sql - ORACLE SQL 比较同一表中的两行或多行

标签 sql oracle

我有一个类似于此值的表

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/

相关文章:

sql - 是否可以仅使用 Insert 和 Select 语句在 Redshift 中引发可序列化隔离冲突?

php - SQL - 我如何在另一个表中使用选定的 ID?

sql - 在我的查询中当 RowNum =1 时没有得到空值

oracle - 注销 oracle 更改通知

mysql - 在 MySQL 中,我应该引用数字吗?

PHP。根据下拉框中选择的选项显示 SQL 表的内容

sql - Oracle 数据库 : How to read a BLOB?

java - 使用 Spring Data 时如何确定是否插入重复项?

oracle - 插入期间违反唯一约束:为什么? (甲骨文)

c# - 使用 GetSchemaTable() 仅检索列名