id, student, course, mark 
1,  张三,    语文,  90 
2,  李四,    语文,  80 
3,  张三,    数学,  70 
4,  李四,    数学,  80 

现在想用转置表的方法转成二维表输出,要求格式是: 

student, 语文, 数学 
张三,    90,  70 
李四,    80,  80 



select student, 
    sum(if(course='语文',mark,0)) as 语文, 
    sum(if(course='数学',mark,0)) as 数学
from table1 
group by student

1   a
2   b
1   c
2   d
合并为
1   a,c
2   b,d

 

select group_concat(column_b,separator ',') from table_name group by column_a;

相关文章:

  • 2022-12-23
  • 2021-07-04
  • 2021-11-17
  • 2022-12-23
  • 2022-01-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-01
  • 2022-12-23
  • 2022-12-23
  • 2022-02-15
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案