【问题标题】:pull users ids where the have 2 different roles assigned. Repeat userid in the output提取分配了 2 个不同角色的用户 ID。在输出中重复用户 ID
【发布时间】:2020-11-17 10:16:00
【问题描述】:

我的数据显示分配给同一用户 ID 的 2 个不同角色。我只想提取分配了多个角色的用户,并在输出中获取多个角色的用户 ID 和名称。 输出将是:

user id   role
--------------------
12345     initiator 
12345     approver

【问题讨论】:

  • 用您正在使用的数据库标记您的问题。
  • 你能提供一个小提琴吗? db-fiddle.com
  • 请显示表格 DDL 和示例表格数据,而不仅仅是预期的结果。另请阅读How to Ask

标签: sql multiple-conditions


【解决方案1】:

会是这样的

select user_id as user_id, role from users a
inner join (
  select user_id as user from users
  group by user_id having count(role) > 1
) b on a.user_id=b.user

Fiddle Link

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-08
    • 1970-01-01
    • 1970-01-01
    • 2019-06-16
    • 1970-01-01
    • 2016-08-11
    • 2014-10-22
    相关资源
    最近更新 更多