1,账单表结构
id money create_date 1 10 2016-11-11 2 20 2016-11-12
2,需求是按日期排序,查询总金额<=1000元的账单列表数据
光阴似箭催人老,日月如移越少年。
select t.sum_money,t.date from (select sum(money) as sum_money,create_date as date from tablename group by create_date) t order by t.date;
若money为总金额,则SELECT id, money, create_date FROM TABLE WHERE money <= 1000ORDER BY create_date DESC
select sum(money) sums,create_date from talbe group by create_date having sums<=1000 order by create_date;
select t.sum_money,t.date from (select sum(money) as sum_money,create_date as date from tablename group by create_date) t order by t.date;
若money为总金额,则
SELECT id, money, create_date
FROM TABLE
WHERE money <= 1000
ORDER BY create_date DESC
select sum(money) sums,create_date from talbe group by create_date having sums<=1000 order by create_date;