如何在sqlite中构造查询? [英] How to structure my query in sqlite?
问题描述
我想检索今天的数据。目前,我有类似 SELECT * FROM myTable WHERE timeStamp> DATETIME('NOW','-1 DAY')
之类的东西,但是从现在到24小时,不仅是今天(即,从00:00开始已经经过了几个小时)。使用相同的逻辑,我只想检索昨天和本周的数据。
I would like to retrieve today's data. At the moment I have something like SELECT * FROM myTable WHERE timeStamp>DATETIME('NOW','-1 DAY')
but this gives me results from now to 24hrs back, not just today (i.e. no matter how many hours have passed since 00:00). Using the same logic I want to retrieve data for just yesterday, and for the this week.
本周,我的意思是..如果今天是星期四,我想显示星期一的结果
By the term this week i mean.. if today is Thursday, i want to show results from monday or Sunday (it doesnt matter) upto now.
推荐答案
而不是 timeStamp>还是星期天(无关紧要)。 DATETIME('now')
使用 timeStamp> = DATE('now')
。
从昨天开始,您可以使用 DATE('now','-1 day')
。
For since yesterday you can use DATE('now', '-1 day')
.
至于本周-这取决于您是否表示7天前:
As for this week - it depends if you mean 7 days ago:
DATE('now', '-7 days')
或者如果您的意思是自本周第一天开始以来:
Or if you mean since the beginning of the first day of this week:
DATE('now', 'weekday 0', '-7 days')
这篇关于如何在sqlite中构造查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!