Hi guys:
I have a problem on date time and count function.
I have a table which contains the following field:
IndexID: autoincrement;
users: varchar;
ordertime: 0000-00-00 00:00:00
messages: varchar;
What I want to do is to count the number of orders per day from now to 10 or 15 days back and display them in a table. The real difficulty is that the ordertime is precise up to seconds instead of days. The nearest approach I made so far is:
select count(*)
from tablename
where to_days(now()) - to_days(datetime) <= 15
and datetime like '2003-09-01%'
However, it has two drawbacks, firstly, one execution can only get number of orders for one day, so there should be a loop to execute them for 10 to 15 times.
Secondly, overhere, I manually set the parameter as "2003-09-01%", in real program such as PHP script, it could be diffult to pass in the parameter like this.
Can someone help me to find a better solution for this simple problem? Thanks a lot.
I have a problem on date time and count function.
I have a table which contains the following field:
IndexID: autoincrement;
users: varchar;
ordertime: 0000-00-00 00:00:00
messages: varchar;
What I want to do is to count the number of orders per day from now to 10 or 15 days back and display them in a table. The real difficulty is that the ordertime is precise up to seconds instead of days. The nearest approach I made so far is:
select count(*)
from tablename
where to_days(now()) - to_days(datetime) <= 15
and datetime like '2003-09-01%'
However, it has two drawbacks, firstly, one execution can only get number of orders for one day, so there should be a loop to execute them for 10 to 15 times.
Secondly, overhere, I manually set the parameter as "2003-09-01%", in real program such as PHP script, it could be diffult to pass in the parameter like this.
Can someone help me to find a better solution for this simple problem? Thanks a lot.