oraclel列變行(多列變成多行)

2021-07-08 17:38:42 字數 582 閱讀 3161

和mysql的一起對照著看:

這篇是oracle10g的環境

資料庫結構如圖:

這裡將相同名字的不同分數(不同列)顯示在多個行中,形如:

sql如下:

(select name ,'數學' as type ,math as score from student )

union

(select name ,'語文' as type ,chinese as score from student )

union

(select name ,'英語' as type ,english as score from student )

呵呵,原來 union和union all 是標準sql中的規範,所以和mysql的用法一樣,sql server估計也一樣,不過沒測試過

mysql drop 多列 MySQL多列分割槽

drop table if exists partition test create table partition test t id int 11 not null auto increment,test date datetime not null,t key varchar 16 test ...

用sql語句要求行變列,列變行

create table tb 姓名 varchar 10 課程 varchar 10 分數 int insert into tb values 張三 語文 74 insert into tb values 張三 數學 83 insert into tb values 張三 物理 93 insert...

SQL事件名行變成列,次數列變行

select imsi callinsms setup sum case when event name callinsms setup then 1 else 0 end idle lup sum case when event name idle lup then 1 else 0 end id...