Mysql 将我的sql行透视到列中

Mysql 将我的sql行透视到列中,mysql,mysql-workbench,Mysql,Mysql Workbench,我有以下结构。 |id |值| |a | v1| |b | v2| |c | v3| |d | v4| 所需的产出 |a | b | c | d| |v1 | v2 | v3 | v4| 我尝试了很多,但都能成功 select case when t1.id = 'a' then t1.value end as a , case when t1.id = 'b' then t1.value end as b , case when t1.id

我有以下结构。 |id |值|

|a | v1|

|b | v2|

|c | v3|

|d | v4|

所需的产出

|a | b | c | d|

|v1 | v2 | v3 | v4|

我尝试了很多,但都能成功

select case  when t1.id  = 'a' then t1.value end as a ,
         case    when t1.id  = 'b' then t1.value end as b ,
          case   when t1.id  = 'c' then t1.value end as b ,
          case   when t1.id  = 'd' then t1.value end as d 


           from
t1 
请告知


感谢您对所需的结果集使用聚合函数

select max(case  when t1.id  = 'a' then t1.value end) as a ,
       max(case  when t1.id  = 'b' then t1.value end) as b ,
       max(case  when t1.id  = 'c' then t1.value end) as b ,
       max(case  when t1.id  = 'd' then t1.value end) as d 
from t1 

注:使用没有分组的聚合函数将整个表视为单个组