问题是这样的,我有多个表联合查询,出现了一下错误,提示,请各位教一下小弟,谢谢SQL 查询:  SELECT a. * , b.supplier_name, c.username, max( d.action_plan_date ) , d.social_total_non_compliance_corrected, d.social_critical_non_compliance_corrected, d.quality_total_non_compliance_corrected, d.quality_critical_non_compliance_corrected
FROM csr a
JOIN supplier b ON a.supplier_id = b.uid
JOIN user c ON b.csr_user_id = c.uid
LEFT JOIN actionplan d ON a.uid = d.csr_id
GROUP BY a.uid
WHERE csr.enable =0
LIMIT 0 , 30 MySQL 返回: #1064 - 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 'where csr.enable = 0 
LIMIT 0, 30' at line 1 

解决方案 »

  1.   

    这样试下:
    SELECT a. * , b.supplier_name, c.username, max( d.action_plan_date ) , d.social_total_non_compliance_corrected, d.social_critical_non_compliance_corrected, d.quality_total_non_compliance_corrected, d.quality_critical_non_compliance_corrected 
    FROM csr a 
    LEFT JOIN actionplan d ON a.uid = d.csr_id,
     supplier b,user c
    WHERE csr.enable =0 and a.supplier_id = b.uid and b.csr_user_id = c.uid
    GROUP BY a.uid 
    LIMIT 0 , 30 
      

  2.   

    错了:SELECT a. * , b.supplier_name, c.username, max( d.action_plan_date ) , d.social_total_non_compliance_corrected, d.social_critical_non_compliance_corrected, d.quality_total_non_compliance_corrected, d.quality_critical_non_compliance_corrected 
    FROM csr a 
    LEFT JOIN actionplan d ON a.uid = d.csr_id,
     supplier b,user c
    WHERE a.enable =0 and a.supplier_id = b.uid and b.csr_user_id = c.uid
    GROUP BY a.uid 
    LIMIT 0 , 30 
      

  3.   

    Group by 语句要放在where语句的后面。
      

  4.   

    而且你的group by 要放where后面
    where csr.enable=0 最好用 where a.enable=0
      

  5.   

    SELECT a. * , 
    b.supplier_name, c.username, 
    max( d.action_plan_date ) , 
    d.social_total_non_compliance_corrected, 
    d.social_critical_non_compliance_corrected, 
    d.quality_total_non_compliance_corrected, 
    d.quality_critical_non_compliance_corrected
    FROM csr a
    JOIN supplier b ON a.supplier_id = b.uid
    JOIN user c ON b.csr_user_id = c.uid
    LEFT JOIN actionplan d ON a.uid = d.csr_id
    WHERE a.enable =0
    GROUP BY a.uid
    LIMIT 0 , 30 
      

  6.   


    SELECT a. * , b.supplier_name, c.username, max( d.action_plan_date ) , d.social_total_non_compliance_corrected, d.social_critical_non_compliance_corrected, d.quality_total_non_compliance_corrected, d.quality_critical_non_compliance_corrected
    FROM csr a
    JOIN supplier b ON a.supplier_id = b.uid
    JOIN user c ON b.csr_user_id = c.uid
    LEFT JOIN actionplan d ON a.uid = d.csr_id
    WHERE a.enable =0
    GROUP BY a.uid
    LIMIT 0 , 30 
      

  7.   

    对,就是group by 语句位置的原因