我有这个疑问:移空值从MySQL结果集
SELECT p.status, s.name AS "Senior", j.name AS "Junior", sp.name AS "Sophomore", f.name AS "Freshman"
FROM matrix p
LEFT JOIN senior s ON p.id = s.id
LEFT JOIN junior j ON p.id = j.id
LEFT JOIN sophomore sp ON p.id = sp.id
LEFT JOIN freshman f ON p.id = f.id
ORDER BY f.name, sp.name, j.name, s.name DESC
它返回这样的结果:
| Senior | Junior | Sohpomore | Freshman |
------------------------------------------
| Value | NULL | NULL | NULL |
| Value | NULL | NULL | NULL |
| Value | NULL | NULL | NULL |
| NULL | Value | NULL | NULL |
| NULL | Value | NULL | NULL |
| NULL | Value | NULL | NULL |
| NULL | NULL | Value | NULL |
| NULL | NULL | Value | NULL |
| NULL | NULL | Value | NULL |
| NULL | NULL | NULL | Value |
| NULL | NULL | NULL | Value |
| NULL | NULL | NULL | Value |
我的问题,是有可能转向第二,第三和第四列'的价值观,使他们都排队(和所有的空值显示在底部)?在此先感谢您的帮助。
顺便说一句,我检索的价值与PHP,万一有帮助。
更新:状态不是唯一的。它只能是2个值,我不会向用户显示。此外,只是为了让我的问题更清晰一点,这就是我想要达到的结果:
| Senior | Junior | Sohpomore | Freshman |
------------------------------------------
| Value | Value | Value | Value |
| Value | Value | Value | Value |
| Value | Value | Value | Value |
| NULL | Value | NULL | Value |
| NULL | Null | NULL | Value |
| NULL | Null | NULL | NULL |
更新2下面是所有表的结构:我想你
Matrix: ID, Status, Student Name, Major, Class Standing
Senior: ID, Name
Junior: ID, Name
Sophomore: ID, Name
Freshman: ID, Name
请显示'matrix'和其他表的示例数据。 –
更新了表结构。 – misdreavus79