I have a table filled with data on cars sold.
I would like to get daily averages so im am using aggregation and the below function.
SELECT
DAYOFMONTH(TIMESTAMP) AS DAY,
MONTH(TIMESTAMP) AS MONTH,
AVG(number_sold) AS sold,
AVG(amount_earned) AS earned,
AVG(wages_spent) AS wages
FROM cardata
GROUP BY DAYOFMONTH(TIMESTAMP)
ORDER BY TIMESTAMP DESC
LIMIT 0, 12;
I should get 12 rows with 1 row for each day. The 12 rows returns but problem getting a row for each day I.e. for February I only get the 5th and the 8th day.
Is there something wrong with my statement?
Help please?
I believe the GROUPBY is not right here.
Try:
This should group the data how you need it.
Alternatively you could do something like:
But fixing the GROUPBY is the main thing that should fix it.