最近使用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');
总结以上是内存溢出为你收集整理的sqlit中使用到的查询语句全部内容,希望文章能够帮你解决sqlit中使用到的查询语句所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)