TSQL数据透视表

时间:2018-02-12 13:00:44

标签: sql-server tsql pivot

我有查询,我用来获取信息。查询基本上获取工人姓名,参考,工资和收入。我希望通过税收周调整薪酬和收入的价值来显示所有信息。我目前使用的代码如下:

SELECT *, 
        SUM(TOTAL_PAY+Holiday_pay) OVER (PARTITION BY personnel_ref, tax_period, tax_year) as [Total_Earning]
        into #tem
FROM(
SELECT  DISTINCT 
        Personnel_ref,
        Tax_period,
        Tax_Year,
        FirstName,
        LastName,
        Contract_Type,
        SUM(TOTAL_PAY) OVER (PARTITION BY PERSONNEL_REF,TAX_PERIOD,TAX_YEAR) AS [Total_Pay],
        (Holiday_Pay)
FROM #worker_totals w
)D

ORDER BY Tax_period ASC

tax_period / week是动态值,不是硬编码值。我希望得到的结果如下:

                                                     |Tax_Period| 45        | 45           |  46        | 46            |  
personnel_ref | Firstname | Lastname | Contract_type | Tax_year | Total_Pay | Total_Earning | Total_Pay | Total_Earning |

0 个答案:

没有答案