首页 行业资讯 宠物日常 宠物养护 宠物健康 宠物故事

mysql 行列转换怎么写?

发布网友 发布时间:2022-04-22 08:00

我来回答

2个回答

热心网友 时间:2024-01-06 20:28

set @i =0;
create table 新表
AS
select @i:=@i+1 as NO,NO1,NO2,NO3,MYA1 as MM
from(
select NO1,NO2,'MYA1 ' as NO3,MYA1 from 表
union all
select NO1,NO2,'MYA2 ',MYA2 from 表
union all
select NO1,NO2,'MYA3 ',MYA3 from 表
union all
select NO1,NO2,'MYA4 ',MYA4 from 表
union all
select NO1,NO2,'MYA5 ',MYA5 from 表
union all
select NO1,NO2,'MYA6 ',MYA6 from 表
)a order by NO1,NO2;

select * from 新表;

热心网友 时间:2024-01-06 20:29

set @i =0;
create table 新表
AS
select @i:=@i+1 as NO,NO1,NO2,NO3,MYA1 as MM
from(
select NO1,NO2,'MYA1 ' as NO3,MYA1 from 表
union all
select NO1,NO2,'MYA2 ',MYA2 from 表
union all
select NO1,NO2,'MYA3 ',MYA3 from 表
union all
select NO1,NO2,'MYA4 ',MYA4 from 表
union all
select NO1,NO2,'MYA5 ',MYA5 from 表
union all
select NO1,NO2,'MYA6 ',MYA6 from 表
)a order by NO1,NO2;

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com