我有一个类似于此值的表
Uname | Grp_ID | Role_ID
---------------------
usr1 | 10 | 1032
usr1 | 10 | 1034
usr1 | 20 | 1032
usr1 | 20 | 1034
usr1 | 30 | 1032
usr1 | 40 | 1032
usr1 | 50 | 1034
usr1 | 50 | 1034
usr1 | 60 | 1018
usr1 | 70 | 1057
我想要具有 1032 和 1034(两者)作为 Role_ID 的输出 Grp_ID
例如,
Grp_ID 10 has 1032 and 1034 as ROle_IDs
Grp_ID 20 has 1032 and 1034 as ROle_IDs
Grp_ID 30, 40, 50, 60 ,70 没有 1032 和 1034 作为 Role_ID
我尝试过使用内部连接和“拥有”,但似乎没有得到我想要的。
最佳答案
Select t1.uname, t2.grp_id, t1.role_id from table_name t1
left join table_name t2 on t1.grp_is = t2.grp_id
Where t1.role_id = 1032 and t2.role_id = 1034
关于sql - ORACLE SQL 比较同一表中的两行或多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39206337/