Java SQL查询 分组显示问题:

数据库中有如下表单:
Java SQL查询 分组显示问题

采用两种分组查询方式,效果分别显示如下:

(1)采用group_concat()

select name,group_concat(subject,score) from stu group by name;

代码运行结果如下:
Java SQL查询 分组显示问题

(2)采用max(case …when…then…else…end)

执行如下代码,结果如下:

select name,max(case subject when '数学' then score else 0 end) 数学, 
					max(case subject when '语文' then score else 0 end) 语文,
					max(case subject when '英语' then score else 0 end) 英语,
					max(case subject when '体育' then score else 0 end) 体育  from stu group by name;
					

Java SQL查询 分组显示问题

相关文章:

  • 2021-11-04
  • 2021-09-13
  • 2021-06-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-28
  • 2022-01-30
猜你喜欢
  • 2021-10-01
  • 2021-06-07
  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
相关资源
相似解决方案