mysql - 我怎样才能从我的表中获取超过 2 天的记录

标签 mysql

为什么我的间隔日在 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/

相关文章:

mysql - 附加查询参数不起作用

mysql - SQL : Select statement order by

mysql - 在同一台机器上安装多个 MySQL 集群 - CentOS 7

mysql - 无法在我的查询中集成 INNER JOIN

php - 显示两个数字之间的值

php - 使用 Ajax JQuery 和 PHP 将 .csv 文件导入 MySQL 的进度条

mysql - 如何填充行中的空值?

mysql - 获取最新的日期行值

mysql - 更改 URL - 隐藏 URL 中的字符串

mysql - 子查询的问题