Forum Moderators: open

Message Too Old, No Replies

MySQL - calculate sales in a time period by hour

         

wrightee

3:59 pm on May 27, 2008 (gmt 0)

10+ Year Member



Hi - I can't figure out this one:

tbl_sales
- transaction_timedate
- amount

If I want to know sales on a daily basis in a particular hourly time frame (e.g. only counting sales that happened between 9:00 and 17:00) - how would I write it? My efforts so far have yielded rubbish I'm ashamed to say.

Thanks in advance for your time.

Zipper

7:08 pm on May 27, 2008 (gmt 0)

10+ Year Member



You mean something like this,

SELECT * FROM tbl_sales WHERE TIME(transaction_timedate) BETWEEN '09:00' AND '17:00'

wrightee

9:42 pm on May 27, 2008 (gmt 0)

10+ Year Member



No. I mean the result would be a list of dates with the total sales made for each day between 9 & 5pm for example.

coopster

11:06 pm on May 27, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



That query is almost complete, wrightee. All you need to do is SELECT the DATE portion of the DATETIME column, perform your SUM() and GROUP BY on the DATE portion of the DATETIME column.