久久久久久久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)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 黄色毛片免费看 | 超级黄色一级片 | 久久免费精品 | www亚洲精品 | 国产欧美一区二区三区久久人妖 | 黄色在线免费观看视频 | 成年人免费看 | 国产精品伦理一区二区三区 | 一区二区免费看 | 一区二区三区日韩精品 | 久久伊人在 | 成人在线免费视频观看 | 亚洲国产精品久久久 | 黑人巨大精品 | 成人三级网址 | 一区二区三区四区五区在线视频 | 天天久久 | 日韩国产中文字幕 | 黄色国产在线播放 | 国产亚洲精品久久yy50 | 欧美精品1区2区3区 精品国产欧美一区二区 | 国产精品视频一区二区三区四蜜臂 | 国产做爰 | 欧美日韩最新 | 国产精品日本一区二区不卡视频 | 国产精品美女在线观看 | 欧美国产日韩在线观看 | 欧美黄在线观看 | 久久久久国产一区二区三区 | 久久久精品高清 | 永久av | 久草免费在线视频 | 国产伦精品一区二区三区照片91 | 奇米av | 亚洲精品久久嫩草网站秘色 | 欧美精品久久久久久久久久 | 一区二区三区在线看 | 亚洲精品一区二区三区蜜桃久 | 成年人网站在线观看视频 | av播播| 午夜精|