Tuesday, 4 September 2018
Subscribe to:
Post Comments (Atom)
SELECT School.NAME,
Payment.year,
Payment.amount,
Count(Student.id_stud) AS 'nb stud'
FROM School
LEFT JOIN Student
ON school.id_school = Student.id_school
LEFT JOIN Payment
ON School.id_school = Payment.id_School
WHERE Year(Student.date_in) <= Payment.year
GROUP BY School.NAME,
Payment.amount,
Payment.year
Year(Student.date_in) filter to ON conditionSELECT School.NAME,
Payment.year,
Payment.amount,
Count(Student.id_stud) AS 'nb stud'
FROM School
LEFT JOIN Student
ON school.id_school = Student.id_school
LEFT JOIN Payment
ON School.id_school = Payment.id_School
AND Year(Student.date_in) <= Payment.year
GROUP BY School.NAME,
Payment.amount,
Payment.year
Year(Student.date_in) in Where clause, for the non matching Student.date_in will have NULL values. Those NULL values will be filtered by the where condition. So Move the filter to ON clause it tells what are records to be joined instead of filtering the result. Same logic will be applied to Payment.year as well.
Hello Friends! I am Ramana a part time blogger from Hyderabad.
0 comments:
Post a Comment