Reputation: 3937
i have a table and i have little issue with groupby month
CREATE TABLE BabyData (BabyId INT, BabyName TEXT, _id INT PRIMARY KEY, Date DATE, Height TEXT, Weight TEXT);
from this table i want the average of weight in each month in a year
when i am providing a date as '2011-2-2' then i want the average of weight in each month from '2011-2-2' to '2012-2-2'
i gave like this
SELECT strftime('%Y',Date) AS year,
strftime('%m',Date) AS month,
Avg(Weight) As Amount
FROM BabyData
Group By strftime('%Y',Date),strftime('%m',Date)
But i getting only 1 average
Upvotes: 2
Views: 4278
Reputation: 263843
SELECT strftime('%m',`Date`) AS `month`,
Avg(Weight) As `Amount `
FROM BabyData
WHERE `DATE` BETWEEN DATE('2011-2-2')
AND
date('2011-2-2','+12 month')
GROUP BY `Month`
Upvotes: 5