在ms sql server中查询make列到行 [英] query for make columns into rows in ms sql server
本文介绍了在ms sql server中查询make列到行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
by using tables i am getting output as follows,
EmpName Place Dept income
A Chennai IT 20
B Chennai IT 30
C Chennai IT 40
D Chennai CSE 30
A Chennai CSE 50
B Chennai CSE 40
C Chennai CSE 10
D Chennai CSE 70
A Bangalore IT 20
B Bangalore IT 30
C Bangalore IT 40
D Bangalore IT 80
A Bangalore EEE 20
B Bangalore EEE 30
C Bangalore EEE 40
D Bangalore EEE 80
I need output as follows
Place Dept A B C D
Chennai IT 20 30 40 30
Chennai CSE 50 40 10 70
Bangalore IT 20 30 40 80
Bangalore EEE 20 30 40 80
can you please help me...ASAP...
推荐答案
select place,dept,[A],[B],[C],[D]
from TableName
pivot
(
sum(income)
for empname in ([A],[B],[C],[D])
)as pvttbl
快乐编码!
:)
Happy Coding!
:)
SELECT PLACE, DEPT, A, B, C, D FROM
(
SELECT EMPNAME, PLACE, DEPT, INCOME FROM EMPLOYEE
)X
PIVOT (SUM(INCOME) FOR EMPNAME IN (A, B, C, D)) AS PVT
这是您的问题所在。
THIS IS YOUR QUERY FOR YOUR PROBLEM.
这篇关于在ms sql server中查询make列到行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文