Group by month in SQLite

前端 未结 6 715
礼貌的吻别
礼貌的吻别 2020-12-16 14:17

I have an SQLite database which contains transactions, each of them having a price and a transDate.

I want to retrieve the sum of the transactions

6条回答
  •  北海茫月
    2020-12-16 14:25

    it is always good while you group by MONTH it should check YEAR also

    select SUM(transaction) as Price, 
           DATE_FORMAT(transDate, "%m-%Y") as 'month-year' 
           from transaction group by DATE_FORMAT(transDate, "%m-%Y");
    

    FOR SQLITE

    select SUM(transaction) as Price, 
           strftime("%m-%Y", transDate) as 'month-year' 
           from transaction group by strftime("%m-%Y", transDate);
    

提交回复
热议问题