I’m working out a query that I’ve ran successfully in MySQL for a while, but in Postgres it’s not working with the ole –
ERROR: column "orders.created_at" must appear in the GROUP BY clause or be used in an aggregate function
Here’s the query:
SELECT SUM(total) AS total, to_char(created_at, 'YYYY/MM/DD') AS order_date
FROM orders
WHERE created_at >= (NOW() - INTERVAL '2 DAYS')
GROUP BY to_char(created_at, 'DD')
ORDER BY created_at ASC;
It’s just supposed to return something like this:
total | order_date ---------+------------ 1099.90 | 2013/01/15 650.00 | 2013/01/16 4399.00 | 2013/01/17
The main thing is I want the sum grouped by each individual day of the month.
Anyone have ideas?
UPDATE:
The reason I’m grouping by day is because the graph will be labeled with each day of the month, and the total sales for each.
1st - $3400.00 2nd - $2237.00 3rd - $1489.00
etc.
I’m not sure why you’re doing a conversion there. I think the better thing to do would be this:
I would recommend this query and then format the daily labels in your graph through the graph settings to ensure you do not have any weird issues of the same day in different months getting grouped. However, to get what you display in your edit you can do this: