SQL 2008查询3或多列成单列 [英] Sql 2008 query for 3 or columns into single column

查看:68
本文介绍了SQL 2008查询3或多列成单列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个员工最近几个月的薪水在不同的列中.我需要将所有数据记录在单个记录中,作为员工的明智选择.
我在员工"表中的数据是

EmpName月的总天数工资
测试可能30 10000
Test1五月25 8000
Test2 5月28日12000
6月25日测试10000
Test1 6月28日8000
Test2 6月28日12000
7月28日测试10000
Test2 7月15日12000
测试10000年8月25日
Test1八月17日8000
Test2 12000年8月29日


我需要下面的

EmpName 5月6月7月7月薪水
测试30 25 28 25 10000
测试1 25 28 0 17 8000
test2 28 28 15 29 12000

谁能告诉我以上结果的查询

谢谢,
Sampath kumar

Hi,
I Have one employee last few months salary in different columns.i need all data in single record as employee wise.

My Data in Employee table is

EmpName Month TotalDays Salary
Test may 30 10000
Test1 may 25 8000
Test2 may 28 12000
Test june 25 10000
Test1 june 28 8000
Test2 june 28 12000
Test july 28 10000
Test2 july 15 12000
Test August 25 10000
Test1 August 17 8000
Test2 August 29 12000


I need like below

EmpName may june july August salary
test 30 25 28 25 10000
Test1 25 28 0 17 8000
test2 28 28 15 29 12000

can anyone tell me the query for above result

Thanks,
Sampath kumar

推荐答案

尝试使用PIVOT 操作员 [^ ]


您甚至可以将PIVOT和WITH CUBE混合使用 + ROLLUP

示例 [
You can even mix the PIVOT and WITH CUBE + ROLLUP

Example[^]


这篇关于SQL 2008查询3或多列成单列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆