這是我的查詢使用子查詢加入MySQL的
SELECT CONCAT(`SM_Title`,' ',`SM_Full_Name`) AS NAME,
`RG_Date`,
`RG_Reg_No`,
`RG_Stu_ID`,
`SM_Tell_Mobile`,
`SM_Tel_Residance`,
`RG_Reg_Type`,
Default_Batch,
`RG_Status`,
`RG_Final_Fee`,
`RG_Total_Paid`,
(`RG_Final_Fee`-`RG_Total_Paid`) AS TOTALDUE,
SUM(`SI_Ins_Amount` - `SI_Paid_Amount`) AS AS_AT_APRIAL_END
INNER JOIN
(SELECT `SI_Ins_Amount`,
`SI_Reg_No`
FROM
`student_installments`
GROUP BY MONTHNAME(`SI_Due_Date`)) Z ON
Z.`SI_Reg_No` = `registrations`.`RG_Reg_No`
FROM `registrations`
LEFT JOIN `student_master` ON `student_master`.`SM_ID` = `registrations`.`RG_Stu_ID`
LEFT JOIN `student_installments` ON `student_installments`.`SI_Reg_No` = `registrations`.`RG_Reg_No`
WHERE (`RG_Reg_Type` LIKE '%HND%' OR `RG_Reg_Type` LIKE '%LMU%')
AND `SI_Due_Date` <= '2014-04-30' GROUP BY `SI_Reg_No`
它給了我一個錯誤附近
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 'Z LIMIT 0, 25' at line 1
我猜'從註冊'應該高於選擇列表後第一次加入。 –
除了FROM之前INNER JOIN的問題之外,您的子查詢似乎很可疑。您正在獲取SI_Reg_No和SI_Ins_Amount,但是按SI_Due_Date分組。我假設SI_Reg_No指的是特定的學生,但是由它組成的小組將爲所有學生組成(其中SI_Reg_No帶回的是未定義的)。此外,當您不返回此字段(而您返回RG_Reg_No)時,您的主要查詢有一個由SI_Reg_No組成的組,而在GROUP BY上,您不定義要使用的SI_Reg_No的哪個表值(即,z.SI_Reg_No或student_installments。 SI_Reg_No)。 – Kickstart