【问题标题】:How to convert rows into columns in SQL?如何在 SQL 中将行转换为列?
【发布时间】:2021-11-27 11:20:25
【问题描述】:

我想将此表转换为水平表,以便 code_val 的列是水平的

Null Half_day half_day Null Null Null 

如上。

【问题讨论】:

  • MySQL 不支持 Pivot。模拟(条件聚合或动态 SQL)。
  • 如果超过 6 行怎么办? 5个怎么样?

标签: mysql sql database pivot


【解决方案1】:

MySQL 不支持透视和反透视

你能做什么?

select id,attendence_remark_code_val, 'a' col, a value
from attendance
union all
select id,attendence_remark_code_val, 'b' col, b value
from attendance
union all
select id,attendence_remark_code_val, 'c' col, c value
from attendance

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-04
    • 2015-04-17
    相关资源
    最近更新 更多