在SQLite中統(tǒng)計(jì)本周本月數(shù)據(jù)的代碼實(shí)例
假設(shè)SQLite數(shù)據(jù)庫中有個(gè)表UserConsume,其中有一列rowTime,該列類型是datetime,怎么統(tǒng)計(jì)該表本月和本周的數(shù)據(jù)?接下來我們給出了統(tǒng)計(jì)的代碼。
--統(tǒng)計(jì)本月數(shù)據(jù)的代碼 如下:
- select *
- from UserConsume
- where rowTime between datetime('now','start of month','+1 second') and
- datetime('now','start of month','+1 month','-1 second')
--統(tǒng)計(jì)本周數(shù)據(jù)的代碼如下:
- 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')
關(guān)于SQLite數(shù)據(jù)庫統(tǒng)計(jì)數(shù)據(jù)就介紹到這里了,如果您想了解更多數(shù)據(jù)庫的知識(shí),也可以去看看這里的文章:http://database.51cto.com/,您的收獲是我***的快樂!
【編輯推薦】