简体   繁体   English

基于日期从三个表中查询MySQL

[英]Mysql query from three tables based on date

I'm trying to get user information based on their subscription startdate in MYSQL. 我试图基于用户在MYSQL中的订阅开始日期来获取用户信息。

This is what i've come up with this far.. 这是我到目前为止提出的。

    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));

This query gives me error message "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 0, 30' at line 8". 该查询给我错误消息“您的SQL语法有错误;请查看与您的MySQL服务器版本相对应的手册,以在第8行的'LIMIT 0,30'附近使用正确的语法”。

I don't see any LIMIT 0, 30 in your posted code. 我在您发布的代码中看不到任何LIMIT 0, 30 did you post the right code? 您输入正确的代码了吗? BTW, your this below part is totally wrong 顺便说一句,您的下面这部分是完全错误的

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

It should rather be 应该是

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

Change your WHERE part like below 如下更改您的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);

I think you are just missing right parenthesis. 我认为您只是缺少右括号。 According to me it should be, 根据我的看法,

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))); 从用户中选择a.id,a.user_login,a.user_email,c.cardtype,c.accountnumber,a.user_pass,a.user_registered。 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))));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM