加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在sqlite中怎么统计本周本月数据

发布时间:2020-12-12 20:42:56 所属栏目:百科 来源:网络整理
导读:sqlite中有个表UserConsume,其中有一列rowTime,该列类型是datetime,怎么统计该表本月和本周的数据?sql如下: --本月select *from UserConsumewhere rowTime between datetime('now','start of month','+1 second') and datetime('now','+1 month','-1 se

sqlite中有个表UserConsume,其中有一列rowTime,该列类型是datetime,怎么统计该表本月和本周的数据?sql如下:

--本月
select *
from UserConsume
where rowTime between datetime('now','start of month','+1 second') and 
datetime('now','+1 month','-1 second') 


--本周
select *
from UserConsume
where rowTime between datetime(date(datetime('now',strftime('-%w day','now'))),'+1 second') 
and datetime(date(datetime('now',(6 - strftime('%w day','now'))||' day','1 day')),'-1 second') 

主要用的函数有datetime和strftime,具体用法,请参阅官网:http://www.sqlite.org/lang_datefunc.html

sql,请参阅:http://sqlite.org/lang.html

数据类型,请参阅:http://sqlite.org/datatype3.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读