List:General Discussion« Previous MessageNext Message »
From:Graeme B. Davis Date:March 15 1999 2:26pm
Subject:Sql Query question
View as plain text  
Basically I am trying to accomplish an if statement in my sql query.  I want to
do one query Tuesday-Friday and then another query Monday.

Here are two separate queries:

Tuesday-Friday:
---------------
select assignedto, count(assignedto) as count from openedstats where modified <=
DATE_SUB(now(),INTERVAL 2 DAY) group by assignedto order by count desc;

Monday query:
-------------
select assignedto, count(assignedto) as count from openedstats where modified <=
DATE_SUB(now(),INTERVAL 4 DAY) group by assignedto order by count desc;

This is all I have come up with so far, but I don't know how to integrate this
into the select:

mysql> select if(strcmp(dayname(now()),"Monday"),"2","4");
+---------------------------------------------+
| if(strcmp(dayname(now()),"Monday"),"2","4") |
+---------------------------------------------+
|
4                                          
|
+---------------------------------------------+

(I did this query on Monday, so it returned "4", which corresponds to the above
queries "INTERVAL X DAY"

Any hints, ideas?

Thanks!

Thread
Sql Query questionGraeme B. Davis15 Mar
  • Sql Query questionMichael Widenius15 Mar