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

Case When Distinct 值然后求和另一個(gè)值?

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

問題描述

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

Piggy backing off another question I had yesterday.

我想知道如何計(jì)算 amt > 1500 的不同記錄數(shù).根據(jù)我的數(shù)據(jù)連接方式,我可以多次反映相同的 PKey AcctNo,因?yàn)槲业耐暾獠窟B接到另一個(gè)具有多個(gè)事務(wù)記錄的表.

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

這是我當(dāng)前的代碼,可產(chǎn)生所需的結(jié)果.我

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)

也許我的整個(gè)方法都是錯(cuò)誤的...idk

Or maybe my entire approach is wrong...idk

推薦答案

您可以對 CASE 表達(dá)式的輸出使用 COUNT(DISTINCT ).例如,要計(jì)算具有 [amount] [amount] 的不同 AcctNo_Pkey 的數(shù)量.聚合結(jié)果中某處的 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)

您可以在在這個(gè)最小的 sqlfiddle 示例

這篇關(guān)于Case When Distinct 值然后求和另一個(gè)值?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個(gè)子標(biāo)記轉(zhuǎn)換為具有多個(gè)分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個(gè)表創(chuàng)建視圖?)
Create calculated value based on calculated value inside previous row(根據(jù)前一行內(nèi)的計(jì)算值創(chuàng)建計(jì)算值)
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屋-程序員軟件開發(fā)技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉(zhuǎn)換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 欧美日韩一区二区三区视频 | 在线视频一区二区 | 久久av一区二区三区亚洲 | 欧美日韩精品在线 | 亚洲国产福利 | 色一情一乱一乱一区91av | 中文字幕在线观看免费视频 | 国产日韩一区 | 国产午夜三级 | 日韩在线视频播放 | 美女一级毛片 | 天堂资源在线 | 国产性猛交 | 97免费在线| 伊人国产精品 | 久久久久久网站 | 日韩在线高清 | 亚洲国产网站 | 国产乱码精品一区二区三 | 在线观看日韩欧美 | 国产日韩中文字幕 | 91精品国产日韩91久久久久久 | 日韩精品在线一区二区 | 日韩看片 | 中文字幕在线网站 | 九九色 | 黄色一级大片 | www一级片 | 久久久高清 | 欧美精品系列 | 日本一级大毛片a一 | 黄色在线观看免费 | 一级黄色录像带 | 国产精品福利一区 | 久久草av| 不卡视频在线 | 日本精品网站 | 国产高清一区二区 | 久久精品在线观看 | 一区二区在线视频 | 国产suv一区二区 |