码迷,mamicode.com
首页 > 数据库 > 详细

sqlit中使用到的查询语句

时间:2015-06-29 00:38:00      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:连表查询   sqlite时间函数   sqlite时间比较   left join   

最近使用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中使用到的查询语句

标签:连表查询   sqlite时间函数   sqlite时间比较   left join   

原文地址:http://blog.csdn.net/xiaoyi_tdcq/article/details/46675099

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!