gpt4 book ai didi

php - 根据主题类型将 mysql 行提取到表中

转载 作者:行者123 更新时间:2023-11-29 08:34:45 24 4
gpt4 key购买 nike

这是我的表格示例(为了清晰起见,重新格式化)

  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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com