SQL Select only rows where exact multiple relationships exist

后端 未结 10 1269
温柔的废话
温柔的废话 2020-12-06 02:06

This is closely related to this question, but adds another requirement.

Given a parent table \'parent\'

╔════════════╦════════╗
║ PARENT_ID  ║ NAME           


        
10条回答
  •  离开以前
    2020-12-06 02:55

    SELECT PARENT_ID
    FROM rel
    GROUP BY PARENT_ID
    HAVING SUM(PROP_ID NOT IN (5,1)) = 0
    AND SUM(PROP_ID = 1) = 1 
    AND SUM(PROP_ID = 5) = 1
    

提交回复
热议问题