先谢谢,我正在使用Mysql数据库。实际上我需要一行数据,当与当前日期和时间进行比较时,其date_date列的datetime数据类型超过24小时。其他名称为"检查"与carts表orderid相比,包含相同的orderid。 所以当比较购物车order_date与当前日期和购物车表时,我需要一个sql查询来获取一行购物车表数据,其中orderid与check表相同,orderid应该被忽略。
carts table:
S.No | username | orderid | exam_name | order_date |
1 | Rakesh |746G797W819d3343493z | PMP | 2016-11-05 11:34:5 |
2 | Rakesh |746G797W819d3343493z | CAPM | 2016-11-05 11:34:5 |
3 | Kulkarni |24890W819d6743493W | CAPM | 2016-11-05 11:34:5 |
4 | Suresh |52890W819d6743493W | PMP | 2016-11-05 11:34:5 |
5 | Gautham |90890W819d6743493W | PMP | 2016-11-05 11:34:5 |
checks table:
S.No | username | orderid | exam_name | checked_date
1 | Rakesh |746G797W819d3343493z | PMP | 2016-11-07 11:20:5
2 | Kulkarni |24890W819d6743493W | CAPM | 2016-11-07 11:20:5
需要以下剩余行
S.No | username | orderid | exam_name | order_date |
1 | Rakesh |746G797W819d3343493z | CAPM | 2016-11-05 11:34:5 |
2 | Suresh |52890W819d6743493W | PMP | 2016-11-05 11:34:5 |
3 | Gautham |90890W819d6743493W | PMP | 2016-11-05 11:34:5 |
答案 0 :(得分:0)
我会做以下事情:
SELECT
*
FROM
carts
LEFT JOIN
checks ON
carts.orderid = checks.orderid AND
carts.exam_name = checks.exam_name
WHERE
checks.orderid is null AND
checks.exam_name is null AND
carts.order_date < NOW() - INTERVAL 1 DAY