我有一个DATETIME字段.我想选择上周更新的所有记录.现在我正在使用此查询:
SELECT SUM(mins_spent) as time_sum FROM todos WHERE lastUpdate >= '2008-12-22' AND lastUpdate <='2008-12-28'
但是我得到的结果似乎根据一天中的时间而有所不同,例如在晚上7点我可能会得到17个小时而在晚上11点我会得到14个小时,即使它应该增加,而不是减少.我在考虑将查询更改为:
SELECT SUM(mins_spent) as time_sum FROM todos WHERE lastUpdate >= '2008-12-22 00:00:00' AND lastUpdate <='2008-12-28 00:00:00'
它会有所帮助吗?建议请..
'2008-12-22'
应该相等'2008-12-22 00:00:00'
.
你想要"直到第28天结束?" 如果是这样,请添加23:59:59
到第二个日期.
或者,您可以使用lastUpdate < "2008-12-29"
.
您如何跟踪现有ToDo的更改?INSERT
和/或DELETE
?还是UPDATE
?
如果您DELETE
在"完成"时记录,那么您的记录就会减少.
如果您正在使用UPDATE
,您是否允许日期更改为当前周?如果是这样,它们将从您的结果中删除.
要查看正在发生的事情,您可以尝试在表格中抓取一些聚合mins_spent
,并lastUpdate
(标记值并偶尔运行以查看它们如何更改).
SELECT count(*) AS Total FROM todos WHERE lastUpdate >= '2008-12-22' AND lastUpdate <= '2008-12-28 23:59:59' SELECT min(mins_spent) AS Min, max(mins_spent) AS Max, avg(mins_spent) AS Avg FROM todos WHERE lastUpdate >= '2008-12-22' AND lastUpdate <= '2008-12-28 23:59:59' SELECT min(lastUpdate) AS Min, max(lastUpdate) AS Max FROM todos WHERE lastUpdate >= '2008-12-22' AND lastUpdate <= '2008-12-28 23:59:59'