我有以下查询以显示学生的月度费用状态。

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

最佳答案

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;

关于mysql - 如何在mysql中实现这样的数据透视表?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18783151/

10-13 22:08