• sqlit中使用到的查询语句


    近期使用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');



  • 相关阅读:
    JavaWeb学习笔记(9)
    JavaWeb学习笔记(8)
    JavaWeb学习笔记(7)
    JavaWeb学习笔记(6)
    JavaWeb学习笔记(5)
    JavaWeb学习笔记(4)
    Plans(Real-Time Update)
    CSP-J2 2020 题解(Updating)
    Lcez#111 yist
    洛谷P1104 生日
  • 原文地址:https://www.cnblogs.com/cynchanpin/p/6893293.html
Copyright © 2020-2023  润新知