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

如果 1 行滿足條件,則排除 ID 的所有行

exclude all rows for an ID if 1 row meets condition(如果 1 行滿足條件,則排除 ID 的所有行)
本文介紹了如果 1 行滿足條件,則排除 ID 的所有行的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

如果某些客戶沒有列出監護人,我正在嘗試從他們的聯系人表中選擇他們.

I am trying to select certain customers from a contacts table if they do not have a guardian listed.

ClientId | ContactId | Guardian
123      | 1         | Y
123      | 2         | N
123      | 3         | N

456      | 4         | N
456      | 5         | N
456      | 6         | N

所需的輸出:

ClientId | ContactId | Guardian 
456      | 4         | N
456      | 5         | N
456      | 6         | N

所以我的目標是客戶端 456 會出現在我的查詢結果中,但 不會 客戶端 123.我寫了以下內容:

So my goal is that Client 456 would show up in my query results, but not Client 123. I have written the following:

select * from Contacts
where Guardian <> (case when Guardian = 'Y' 
    then Guardian 
       else '' 
         end)

我也試過

select * from Contacts c
where not exists (select 1
                  from Contacts c2
                  where c2.ContactId = c.ContactId
                  and c.Guardian = 'Y')                      

但我的結果只是排除了 Guardian = Y 的行,并打印了 Guardian = N 的行,即使有任何行與 Guardian = Y 的 ClientId 相關聯,該 ClientId 也不應該出現在結果中.我一直在尋找如何只選擇其中具有某些值的行,但是如果其中一行匹配,我沒有找到如何完全排除 ClientId 的運氣.

But my results are just excluding the lines where Guardian = Y, and printing the lines where Guardian = N, even though if there is any line associated with a ClientId where Guardian = Y, that ClientId should not show up in the results. I've been looking up how to only select rows with certain values in them, but I'm not having any luck finding how to exclude a ClientId entirely if one of its rows matches.

如果有任何建議,我將不勝感激!

I'd be really grateful for any suggestions!

推薦答案

子查詢獲取沒有任何 Guardian = 'Y'ClientId.如果您需要完整的記錄,也可以使用外部查詢.如果您只需要 ID,則只需使用子查詢

The subquery gets the ClientIds that do not have any Guardian = 'Y'. If you need the complete record use the outer query too. If you need only the ID then use just the subquery

select *
from Contacts
where ClientId in
(
   select ClientId
   from Contacts
   group by ClientId
   having sum(case when Guardian = 'Y' then 1 else 0 end) = 0
)                

這篇關于如果 1 行滿足條件,則排除 ID 的所有行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 国产视频91在线 | 免费观看成人性生生活片 | 亚洲精品日韩一区二区电影 | 亚洲精品福利在线 | 国产目拍亚洲精品99久久精品 | 在线一区二区三区 | 欧美极品在线 | 综合亚洲视频 | 天天欧美 | 91精品一区二区三区久久久久久 | 亚洲69p | 亚洲高清视频在线 | 四色永久| 国产精品久久久久久久久久三级 | 亚洲欧美综合 | 久久av网 | 国产91在线播放精品91 | 粉嫩av久久一区二区三区 | 毛片高清 | 国产免费又黄又爽又刺激蜜月al | 日韩在线精品强乱中文字幕 | 精品日本久久久久久久久久 | 男女精品久久 | 午夜国产羞羞视频免费网站 | 久久网国产 | 久久精品国产一区二区电影 | 久久高清| 欧美日韩久久精品 | 日韩欧美三区 | 欧美黄色片 | 北条麻妃99精品青青久久主播 | 91精品国产777在线观看 | 欧美成人在线影院 | 蜜桃av人人夜夜澡人人爽 | 午夜免费小视频 | av网站在线免费观看 | 亚洲一区二区三区四区五区中文 | 日韩成年人视频在线 | 拍真实国产伦偷精品 | 国产精品久久久久aaaa九色 | 天天天天天操 |