最近使用sqlite查询比较多,包括连表查询等。记录一下,以免忘记!
1.先根据时间排序后选择前十条:
select * from MyBill order by createTime desc limit 10;
2.求price的和:
select sum(price) as sum from MyBill;
3.这个是有个分类表,有个账单表,根据分类中的主分类分类统计再排序:
select sum(mysum),tb.pid from"
+ "(select sum(price) as mysum,consumetype.title as tt,consumetype.parentid as pid from mybill "
+ "left join consumetype on mybill.typeid =consumetype.id "
+ "group by mybill.typeid) as tb group by tb.pid order by sum(mysum) desc";
4.这个是有个分类表,有个账单表,根据分类中的子分类分类统计再排序:
select sum(price),consumetype.title from mybill "
+ "left join consumetype on mybill.typeid =consumetype.id "
+ "group by mybill.typeid order by sum(price) desc";
5.根据时间来比较选择:
select * from MyBill where createTime < datetime('2015-05-19')
相应的其他时间函数方式如下:
* select datetime('now'); * select datetime('2006-10-17 00:20:00','+1 hour','-12 minute'); * select date('2006-10-17','+1 day','+1 year'); * select datetime('now','start of year'); * select datetime('now','start of month'); * select datetime('now','start of day'); * select datetime('now','+10 hour','start of day','+10 hour'); * select datetime('now','localtime'); * select datetime('now','+8 hour');
原文链接:https://www.f2er.com/sqlite/199520.html