>>>>> "Graeme" == Graeme B Davis <GraemeD@stripped> writes:
Graeme> Basically I am trying to accomplish an if statement in my sql query. I
> want to
Graeme> do one query Tuesday-Friday and then another query Monday.
Graeme> Here are two separate queries:
Graeme> Tuesday-Friday:
Graeme> ---------------
Graeme> select assignedto, count(assignedto) as count from openedstats where modified
> <=
Graeme> DATE_SUB(now(),INTERVAL 2 DAY) group by assignedto order by count desc;
Graeme> Monday query:
Graeme> -------------
Graeme> select assignedto, count(assignedto) as count from openedstats where modified
> <=
Graeme> DATE_SUB(now(),INTERVAL 4 DAY) group by assignedto order by count desc;
Graeme> This is all I have come up with so far, but I don't know how to integrate this
Graeme> into the select:
mysql> select if(strcmp(dayname(now()),"Monday"),"2","4");
Graeme> +---------------------------------------------+
Graeme> | if(strcmp(dayname(now()),"Monday"),"2","4") |
Graeme> +---------------------------------------------+
Graeme> |
> 4
> |
Graeme> +---------------------------------------------+
Graeme> (I did this query on Monday, so it returned "4", which corresponds to the
> above
Graeme> queries "INTERVAL X DAY"
Graeme> Any hints, ideas?
Hi!
select assignedto, count(assignedto) as count from openedstats where
modified <= DATE_SUB(now(),INTERVAL if (weekday(now())=0,4,2) days)
group by assignedto order by count desc;
Regards,
Monty
| Thread |
|---|
| • Sql Query question | Graeme B. Davis | 15 Mar |
| • Sql Query question | Michael Widenius | 15 Mar |