gpt4 book ai didi

mysql - 如何在 where 子句中针对 unixtimestamp (bigint) 列使用 curdate()

转载 作者:行者123 更新时间:2023-11-29 06:55:00 26 4
gpt4 key购买 nike

我正在尝试提取过去 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com