我有以下查询显示学生的月费状况。
SELECT regd, Name_of_Student, Class, Section, Rollno,
If(Month = 'January', Status, 0) AS Jan,
If(Month = 'September', Status, 0) AS Sept
FROM fee
where Class='XI(Art)' and Rollno='2';
此代码的问题如图所示:
我想输出的内容如下:
在实际应用中,我会显示所有月份。
请参阅小提琴here
答案 0 :(得分:3)
SELECT regd, Name_of_Student, Class, Section, Rollno,
MAX(If(Month = 'January', Status, 0)) AS Jan,
MAX(If(Month = 'September', Status, 0)) AS Sept
FROM fee
where Class='XI(Art)' and Rollno='2'
GROUP BY regd, Name_of_Student, Class, Section, Rollno;