我正在尝试提取过去 7 天的记录。这是我一直试图开始工作的选择语句:
select from_unixtime(time,'%m/%d/%y') as fdate, from_unixtime(time,'%h:%m:%s') as ftime
from mdl_log
where from_unixtime(time,'%y-%m-%d') between curdate() and curdate() - INTERVAL 7 DAY
我尝试过 where 子句的各种形式,例如
where time between curdate() and curdate() - INTERVAL 7 DAY
和
where from_unixtime(time,'%yyyy-%mm-%dd') between curdate() and curdate() - INTERVAL 7 DAY
和
where date(time) between curdate() and curdate() - INTERVAL 7 DAY
select curdate() - 结果以 2012-11-08 格式显示日期
最佳答案
你的最后一个化身几乎就在那里。但是,您需要将苹果与苹果进行比较。由于 time
是一个整数,您需要将其转换为 MySQL date/time functions使用。
WHERE DATE(FROM_UNIXTIME(time)) between CURDATE() and CURDATE() - INTERVAL 7 DAY
鉴于您的用例,您实际上只需要 FROM_UNIXTIME() :
WHERE FROM_UNIXTIME(time) between CURDATE() and CURDATE() - INTERVAL 7 DAY
关于mysql - 如何在 where 子句中针对 unixtimestamp (bigint) 列使用 curdate(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13293570/