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

在子集中具有特定值的父級(jí)的 SQL 查詢

SQL query for parent with specific values in child set(在子集中具有特定值的父級(jí)的 SQL 查詢)
本文介紹了在子集中具有特定值的父級(jí)的 SQL 查詢的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我試圖只返回父級(jí),其中子級(jí)集包含多個(gè)特定記錄.鑒于此表:

I am trying to return just the parent where the set of children contain multiple specific records. Given this table:

Product   State
-------   -----
111       AZ
111       CA
111       UT
222       AZ
222       WA
333       CA

我想找到同時(shí)具有 AZ 子記錄和 CA 子記錄的 Product 列表,即使它還有其他記錄.哪個(gè)會(huì)返回...

I want find the list of Product that have both a AZ child record and a CA child record, even if it also has other records. Which would return ...

Product
-------
111

推薦答案

select product  
  from table 
 where state in ('az','ca')  
 group by product 
having count(distinct(state)) = 2


select distinct product  
  from table 
 where state = 'az'
INTERSECT 
select distinct product  
  from table 
 where state = 'ca'  


select distinct t1.product  
  from table t1 
  join table t2 
    on t1.product = t2.product 
   and t1.state = 'az'
   and t2.state = 'ca'

最后一個(gè)可能是最有效的.

The last is probably going to be the most efficient.

這篇關(guān)于在子集中具有特定值的父級(jí)的 SQL 查詢的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Modify Existing decimal places info(修改現(xiàn)有小數(shù)位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關(guān)名稱“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號(hào)或管道運(yùn)算符字符串中刪除重復(fù)項(xiàng))
Change an iterative query to a relational set-based query(將迭代查詢更改為基于關(guān)系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 欧美一区二区免费 | 亚洲国产精品精华素 | 国产精品免费视频一区 | 一区在线观看 | 伊人看片| 亚洲精久久久 | 亚洲免费人成在线视频观看 | 久久久精品久 | 9191在线播放 | 日韩在线不卡视频 | 久久久久久久久久久久久9999 | 午夜av电影院 | 色播久久久 | 国产探花在线观看视频 | 激情五月婷婷在线 | 日韩一区二区三区在线 | 国产欧美日韩一区 | 国产精品99久久久久久动医院 | 久久久免费毛片 | 欧美成人激情 | 在线观看黄视频 | 久久精品视频网站 | 一区二区在线免费观看 | 亚洲a级| 麻豆视频国产在线观看 | 欧美在线观看一区二区 | 九九久久久 | 国产免费一区二区三区 | www.久久 | 久久久久久999 | 国产一区二区三区免费 | 日日干夜夜操 | 黄色高清视频 | 亚洲成人免费 | 成人免费在线视频 | 欧美日韩高清 | 久久久国产一区二区三区四区小说 | 狠狠干天天干 | 国产精品视频播放 | 男人天堂社区 | 欧美日韩一区二区三区四区五区 |