初始表:temp_count

MYSQL中列转行的方法

目标表:machine_count

MYSQL中列转行的方法

利用max(case when then)

select temp_count.id,
 MAX(CASE temp_count.`故障部位` WHEN '动力' THEN temp_count.`故障次数` ELSE 0 END ) '动力',
 MAX(CASE temp_count.`故障部位` WHEN '液压系统' THEN temp_count.`故障次数` ELSE 0 END ) '液压系统',
 MAX(CASE temp_count.`故障部位` WHEN '电装品' THEN temp_count.`故障次数` ELSE 0 END ) '电装品'
 from temp_count
GROUP BY temp_count.id;

MYSQL中列转行的方法

 

 

 

 

 

 

相关文章:

  • 2022-01-05
  • 2021-07-08
  • 2021-12-22
  • 2021-08-07
  • 2021-04-15
  • 2021-06-27
猜你喜欢
  • 2021-12-07
  • 2022-01-22
  • 2022-12-23
  • 2021-10-02
  • 2021-09-12
  • 2021-12-22
相关资源
相似解决方案