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

Case When Distinct 值然后求和另一個值?

Case When Distinct value then sum another value?(Case When Distinct 值然后求和另一個值?)
本文介紹了Case When Distinct 值然后求和另一個值?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

小豬退縮了我昨天提出的另一個問題.

Piggy backing off another question I had yesterday.

我想知道如何計算 amt > 1500 的不同記錄數.根據我的數據連接方式,我可以多次反映相同的 PKey AcctNo,因為我的完整外部連接到另一個具有多個事務記錄的表.

I was wondering how I would go about counting the distinct number of records that have an amt > 1500. The way my data is joined, I could have the same PKey AcctNo reflected more than one time because my full outer joined to another table that has multiple transactional records.

(Case When AcctNo_PKey = distinct then sum(case when amount > 1500 then 1 else 0 end)
 else 0) end as GT1500

這是我當前的代碼,可產生所需的結果.我

this my current code that produces a desired result. I

SELECT sum(case when amount > 1500 then 1 else 0 end) as GT1500
     , sum(case when amount < 1500 then 1 else 0 end) as LT1500
    , DATEPART(Year, amount.Date) Deposit_Year
    , DATEPART(QUARTER, amount.Date) Deposit_Qtr 
From account 
full outer JOIN amount ON account.AcctNo = amount.AcctNo
group by DATEPART(Year, amount.Date)
    , DATEPART(QUARTER, amount.Date)

也許我的整個方法都是錯誤的...idk

Or maybe my entire approach is wrong...idk

推薦答案

您可以對 CASE 表達式的輸出使用 COUNT(DISTINCT ).例如,要計算具有 [amount] [amount] 的不同 AcctNo_Pkey 的數量.聚合結果中某處的 1500 行,您可以使用它:

You can use COUNT(DISTINCT ) on the output of a CASE expression. For example, to count the number of distinct AcctNo_Pkeys that have an [amount] < 1500 row somewhere in the aggregated result, you could use this:

COUNT(DISTINCT CASE WHEN [amount] < 1500 THEN AcctNo_PKey END)

您可以在在這個最小的 sqlfiddle 示例

這篇關于Case When Distinct 值然后求和另一個值?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 国产色在线 | 亚洲精品68久久久一区 | 天天操天天射综合 | 久久久久久中文字幕 | 国产精品a一区二区三区网址 | 黄色av网站免费看 | 亚洲性免费 | 成人三级在线观看 | 在线观看特色大片免费网站 | 欧美影院 | 羞羞的视频免费在线观看 | 亚洲国产精品一区二区三区 | 久久久成人免费一区二区 | 精品综合视频 | 色噜噜狠狠色综合中国 | 久久久www成人免费精品 | 最近中文字幕免费 | 国产日韩欧美一区二区在线播放 | 99久久99热这里只有精品 | 天天拍天天操 | 精品国产黄a∨片高清在线 www.一级片 国产欧美日韩综合精品一区二区 | 国产精品久久久久久久久久免费 | 伊人伊成久久人综合网站 | 手机av在线 | 国产日韩精品视频 | 日本成人福利视频 | 夜夜草天天草 | 国产成人在线一区二区 | 国产一区二区免费 | 在线播放中文字幕 | 中文字幕日韩欧美一区二区三区 | a在线观看免费 | 人人做人人澡人人爽欧美 | 欧美福利影院 | 国产精品欧美一区二区三区不卡 | 亚洲啊v在线 | 激情五月综合 | 欧美日韩一区在线 | 久久久久久久电影 | 国产激情精品一区二区三区 | 国产成人免费 |