gpt4 book ai didi

mysql - 我如何从我的表中获取超过 2 天的记录

转载 作者:行者123 更新时间:2023-11-29 02:00:34 25 4
gpt4 key购买 nike

为什么我的间隔日不能在 mysql 语句中工作。

我想要那些超过 2 天大的。这就是我尝试的方式。

SELECT t.*, ct.*,cd.*, max(t.transactiontime) as maxtime
FROM exp_channel_titles as ct
LEFT JOIN transactions as t on (ct.entry_id = t.restaurant_id)
LEFT JOIN exp_channel_data as cd on (ct.entry_id = cd.entry_id)
WHERE t.cardid > 0
and maxtime < ( CURDATE() - INTERVAL 2 DAY )
and t.restaurant_id > 0
and ct.status= 'open'
Group by ct.entry_id
order by maxtime desc

这是我当前的输出

TransactionID          Title           TransactionTime
23132 Locaton 2013-05-17 10:02:04
23131 Novuel 2013-05-16 16:26:45
23128 Mama Rosa 2013-05-15 14:42:44
23126 Rohan 2013-05-14 12:46:56

这是我想要的输出

TransactionID          Title           Date
23128 Mama Rosa 2013-05-15 14:42:44
23126 Rohan 2013-05-14 12:46:56

但是我收到了这个错误

Error Number: 1054

Unknown column 'maxtime' in 'where clause'

SELECT t.*, ct.*,cd.*, max(t.transactiontime) as maxtime FROM exp_channel_titles as ct LEFT JOIN transactions as t on (ct.entry_id = t.restaurant_id) LEFT JOIN exp_channel_data as cd on (ct.entry_id = cd.entry_id) WHERE t.cardid > 0 and maxtime < ( CURDATE() - INTERVAL 2 DAY ) and t.restaurant_id > 0 and ct.status= 'open' Group by ct.entry_id order by maxtime desc

Filename: libraries/Functions.php(656) : eval()'d code

Line Number: 46

最佳答案

尝试:

maxtime < DATE_FORMAT( NOW() - INTERVAL 2 DAY ,'%Y-%m-%d 23:59:59')

CURDATE() 返回 DATE 类型,你需要 DATETIME 类型,所以你应该使用 NOW()

关于mysql - 我如何从我的表中获取超过 2 天的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16057275/

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