gpt4 book ai didi

Mysql根据日期查询三张表

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

我正在尝试根据 MYSQL 中的订阅开始日期获取用户信息。

这就是我到目前为止所想出的..

    SELECT a.id, a.user_login, a.user_email, c.cardtype, c.accountnumber, a.user_pass, a.user_registered
FROM users a
INNER JOIN memberships_users b
ON b.user_id = a.id
INNER JOIN memberships_order c
ON c.user_id = a.id
WHERE b.status = 'active' AND
(c.cyckle_period = 6 AND
('2016-06-01 00:00:00' < (SELECT c.startdate ORDER BY c.startdate DESC LIMIT 1))
OR
(c.cyckle_period = 1 AND
('2015-12-01 00:00:00' < (SELECT c.startdate ORDER BY c.startdate DESC LIMIT 1));

此查询向我显示错误消息“您的 SQL 语法有错误;请检查与您的 MySQL 服务器版本相对应的手册,以了解在第 8 行‘LIMIT 0, 30’附近使用的正确语法”。

最佳答案

我在您发布的代码中没有看到任何LIMIT 0, 30。你发布了正确的代码吗?顺便说一句,你下面的部分是完全错误的

'2015-12-01 00:00:00' < (SELECT c.startdate ORDER BY c.startdate DESC LIMIT 1)

应该是

'2015-12-01 00:00:00' < SELECT max(startdate) FROM memberships_order

更改您的 WHERE 部分,如下所示

WHERE b.status = 'active' AND 
c.cyckle_period IN (6, 1) AND
'2015-12-01 00:00:00' < (SELECT max(startdate) FROM memberships_order);

关于Mysql根据日期查询三张表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40947934/

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