MySQL Group Results by day using timestamp
Posted
by Webnet
on Stack Overflow
See other posts from Stack Overflow
or by Webnet
Published on 2010-04-19T21:03:27Z
Indexed on
2010/04/19
21:13 UTC
Read the original article
Hit count: 136
I need to take the following query and pull the total order counts and sum of the orders grouped by day. I'm storing everything using timestamps.
SELECT
COUNT(id) as order_count,
SUM(price + shipping_price) as order_sum,
DAY(FROM_UNIXTIME(created)) as day
FROM `order`
WHERE '.implode(' AND ', $where).'
I need to group by DAY but when I do for this past weekend's sales it takes my order_count and makes it 1 instead of 3. How can I pull the above values grouped by day?
NOTE: The implode is used ONLY to define the time period (WHERE created >= TIMESTAMP AND <= TIMESTAMP)
© Stack Overflow or respective owner