久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

兩個 select 語句的求和結果

Sum results from two select statements(兩個 select 語句的求和結果)
本文介紹了兩個 select 語句的求和結果的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我們的員工每周都會收到傭金,由于獎金結構,我必須計算兩個單獨的周薪,然后將兩者相加.

Our employees are paid commission on a weekly basis and because of a bonus structure i have to calculate two separate weeks of pay and then add the two together.

我有以下 SQL 語句來獲取兩個單獨的星期結果

I have the following SQL statement which gets the two separate weeks results

    SELECT  PerceptionistID, SSNLastFour, CommissionPay,
        PTOPay, HolidayPay, Overtime, TotalPay
    FROM [dbo].fnCalculateCommissionForWeekOf(@MondayOfCurrentWeek)

    UNION

    -- Need to get the following week's data and sum the two together
    SELECT  PerceptionistID, SSNLastFour, CommissionPay,
        PTOPay, HolidayPay, Overtime, TotalPay
    FROM [dbo].fnCalculateCommissionForWeekOf(@MondayOfFollowingWeek)

這為我提供了我需要的數據,但我想將兩個結果合并到一個具有相同列的表中,但將一些列添加在一起(CommissionPay、PTOPay、HolidayPay、Overtime、TotalPay).做這個的最好方式是什么?我使用的是 SQL Server 2008 R2.

This gets me the data I need but I would like to combine the two results into one table with the same columns but having some of the columns added together (CommissionPay, PTOPay, HolidayPay, Overtime, TotalPay). What is the best way to do this? I am using SQL Server 2008 R2.

推薦答案

試試這個

SELECT PerceptionistID, SSNLastFour, SUM(CommissionPay) CommissionPay,
        SUM(PTOPay) PTOPay, SUM(HolidayPay) HolidayPay, SUM(Overtime) Overtime, SUM(TotalPay) TotalPay
FROM
(
    SELECT  PerceptionistID, SSNLastFour, CommissionPay,
        PTOPay, HolidayPay, Overtime, TotalPay
    FROM [dbo].fnCalculateCommissionForWeekOf(@MondayOfCurrentWeek)

    UNION ALL

    -- Need to get the following week's data and sum the two together
    SELECT  PerceptionistID, SSNLastFour, CommissionPay,
        PTOPay, HolidayPay, Overtime, TotalPay
    FROM [dbo].fnCalculateCommissionForWeekOf(@MondayOfFollowingWeek)
) t
GROUP BY PerceptionistID, SSNLastFour

這篇關于兩個 select 語句的求和結果的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 99精品视频免费观看 | 玖玖玖av| 日本精品久久久久 | 久日精品 | 亚洲 欧美 另类 日韩 | 欧美理伦片在线播放 | 欧美电影免费观看 | 久久久久99 | 亚洲精品福利视频 | 中文字幕高清av | 国产成人福利 | 狠狠影院| 亚洲欧美精品在线 | 久久久久久亚洲 | 久久不射网 | 麻豆av网| 蜜桃视频一区二区三区 | 在线观看国产www | 欧美狠狠操 | 久久久久久久97 | 精品一区二区三区免费视频 | 黄色网址在线免费观看 | 日韩中文字幕在线播放 | 激情网五月天 | 国产高清免费视频 | 成人免费日韩 | 欧美一区二区三区视频在线播放 | av中文在线播放 | 天天草av | 久久久久91 | 可以在线观看av的网站 | 国产精品99久久久久久久vr | 人操人人干人 | 国产精品日韩欧美 | 国产精品久久久久久 | 欧美一区二区三区一在线观看 | 日韩一区二区在线视频 | 黄色网址免费看 | 精品在线免费看 | 亚洲中国字幕 | 台湾佬伊人 |