如何用SQL查詢一張表中的某列在行上顯示如下格式

時間 2022-05-24 09:40:09

1樓:匿名使用者

首先,轉換後的列名必須固定,因為只能進行列舉才能進行行列轉換。

select name,

xuehao,

sum(decode(kemu,'yuwen',fenshu,0) yuwen,

sum(decode(kemu,'shuxue',fenshu,0) shuxue,

sum(decode(kemu,'gaoshu',fenshu,0) gaoshu

from table

group by name,xuehao

order by name

2樓:匿名使用者

select name,xuehao,

sum(case when kemu ='yuwen' then fenshu end) as yuwen,

sum(case when kemu ='shuxue' then fenshu end) as shuxue,

sum(case when kemu ='gaoshu' then fenshu end) as gaoshu

from 表名

group by name,xuehao

3樓:匿名使用者

select distinct(xuehao),name,(select fenshu from core where kemu='shuxue' and xuehao=c.xuehao) as shuxue ,

(select fenshu from core where kemu='yuwen' and xuehao=c.xuehao) as yuwen,

(select fenshu from core where kemu='gaoshu' and xuehao=c.xuehao) as gaoshu

from core as c

sql查詢中如何將某列分成兩列,SQL中如何將兩列拼接

阿嘎灑 declare str varchar 50 set str 100.1203,200.1234 select substring str,1,patindex str 1 as 經度 reverse substring reverse str 1,patindex str 1 as 緯度 ...

sql資料庫中建立檢視怎樣把一張表的列值轉換成另一張表的

首初珍餘啟 獲取檢視名稱樹懶已經實現了,下面就是獲取檢視中所有列的名稱了,其實也是用一句sql語句就可以實現了,有興趣也來試試吧 declare objid int,objname char 40 set objname 你的檢視名稱 建個函式把 create function getyqstrin...

sql怎麼將一張表的欄位賦值給另一張表

插入資料insert into tbytz userid select userid from tbuser更新資料則在tbuser和tbytz兩個表要有一個關係。如tbuser.a1 tbytz.a2update tbytz set tbytz.userid select userid from ...