我想写一个查询,返回学校的名称,付款年份,付款的成本和学生人数有付款的一年。 我遇到的问题是,某一年有0名学生,所以查询不会返回任何行,虽然有付款。SQL查询不返回行时计数(*)= 0与WHERE子句
这里是我的尝试:
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
我想显示每一行即使COUNT(Student.id_stud)为0 我认为问题出在WHERE子句。
Jatin C和Pரதீப்的两个答案都是有意义的,并且似乎对我有用。也许考虑分享一些'DECLARE TABLE'和'INSERT INTO',这样我们所有人都可以一起复制这些问题。 – KtX2SkD