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

在子集中具有特定值的父級的 SQL 查詢

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

問題描述

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

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

我想找到同時具有 AZ 子記錄和 CA 子記錄的 Product 列表,即使它還有其他記錄.哪個會返回...

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'

最后一個可能是最有效的.

The last is probably going to be the most efficient.

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

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

相關文檔推薦

Modify Existing decimal places info(修改現有小數位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關名稱“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號或管道運算符字符串中刪除重復項)
Change an iterative query to a relational set-based query(將迭代查詢更改為基于關系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 亚洲91 | 天天成人综合网 | 人人澡人人射 | 精品国产一区探花在线观看 | 成人av观看 | 91免费看片 | 国产一区二区三区视频免费观看 | 午夜手机在线 | 精品国产乱码久久久久久果冻传媒 | 免费在线性爱视频 | 毛片电影 | 欧美日韩综合视频 | 91久久国产| 久久99国产精一区二区三区 | 午夜精品久久久久久久99黑人 | 久久久91 | 欧美 日韩 亚洲91麻豆精品 | h片免费在线观看 | 伊人影院99 | 国内精品久久久久久久 | 亚洲国产精品一区二区三区 | 人人做人人澡人人爽欧美 | 伊人伊人伊人 | 中文字幕精品一区 | 狠狠色狠狠色综合日日92 | 国内成人免费视频 | 色视频网站 | 日日做夜夜爽毛片麻豆 | 青春草国产 | 国产在线观看福利 | 国产精品久久久久久妇女6080 | 一区二区影院 | 久久激情网 | 国产视频二区 | 久久国产一区二区三区 | 国产精品久久久久久久久久 | 国色天香成人网 | 亚洲视频观看 | 久久久久av| www.一级毛片| www久久久 |