这是我的表的一个示例(为清楚起见已重新格式化)
Subject Percentage Grade
English 40% D
Chemistry 80% A
Physics 50% C
因此,基本上我想获取此数据并以这种方式表示:
English Chemistry Physics
40% 80% 50%
D A C
我该怎么办?
谢谢。
最佳答案
尝试这个 :
select english , chemistry , physics from (
select (select percentage from Table1 where subject = 'English' ) as english,
(select percentage from Table1 where subject = 'Chemistry') as chemistry,
(select percentage from Table1 where subject = 'Physics') as physics
from Table1 group by english
union all
select (select Grade from Table1 where subject = 'English' ) as english,
(select Grade from Table1 where subject = 'Chemistry') as chemistry,
(select Grade from Table1 where subject = 'Physics') as physics
from Table1 group by english
) t
输出:
ENGLISH CHEMISTRY PHYSICS
40% 80% 50%
D A C
DEMO HERE
关于php - 根据主题类型将mysql行提取到表中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15508470/