读书@IT·互联网Java开发技术

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

2026-04-09  本文已影响0人  程序员编程助手

行转列 列转行 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

)

;

上一篇 下一篇

猜你喜欢

热点阅读