久久久久久久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)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 伊人操| 羞视频在线观看 | 亚洲精品久久久久久国产精华液 | 久久91av| 在线看片福利 | 国产成人精品区一区二区不卡 | 操网站| 国产网站在线免费观看 | 日韩在线精品视频 | 亚洲一区二区精品视频在线观看 | 婷婷福利视频导航 | 午夜在线视频 | 成人一区二区三区 | 大象一区 | 91国内精品 | 久久久亚洲精品视频 | 国产乱码精品一区二区三区五月婷 | 日韩精品一区二区三区在线观看 | 2021狠狠干 | 在线观看免费av片 | 九九久久精品 | 久草热视频 | 色吧综合网 | 欧美福利一区 | 99精品欧美一区二区蜜桃免费 | 免费av毛片| 午夜私人影院在线观看 | 国产精品日产欧美久久久久 | 爱爱视频在线观看 | 久久精品欧美一区二区三区不卡 | 亚洲精品黄 | 精品国产99 | 国产色爽 | 91在线电影| 精品国产99 | 在线成人av | 亚洲 欧美 激情 另类 校园 | 成人黄页在线观看 | 日韩一区不卡 | 色综合天天天天做夜夜夜夜做 | 人妖videosex高潮另类 |