行转列 列转行 sql 脚本的编写

0 阅读1分钟

行转列 列转行 sql 脚本的编写

1. sql 脚本编写 行转列 列转行

  


表设计

test_table

id varchar(11),

name varchar(255),

table_desc varchar(255)

sql 编写

  


行转列

  


select concatenate("id",""),

concatenate("name",""),

concatenate("desc",""),

concatenate(

""

,(

select *

from test_table a

where 1=1

limit 1

desc

)

)

from test_table b

  


列转行

  


select concatenate("id",""),*

from test_table a

union

(

select b.id

from test_table b

limit 1

desc

)

;