如何更改我的子选择我可以使用WHERE IN获得多行?

时间:2018-05-22 07:57:25

标签: mysql sql database subquery

SELECT 
  (SELECT TOP 1 obj FROM rel_raci responsible_raci_r WHERE responsible_raci_r.PERSON_ID = organization.id AND responsible_raci_r.RACI ='R') AS responsible_inverted,
  (SELECT TOP 1 obj FROM rel_raci responsible_raci_r WHERE responsible_raci_r.PERSON_ID = organization.id AND responsible_raci_r.RACI ='A') AS accountable_inverted,
  (SELECT TOP 1 obj FROM rel_raci responsible_raci_r WHERE responsible_raci_r.PERSON_ID = organization.id AND responsible_raci_r.RACI ='C') AS consulted_inverted,
  (SELECT TOP 1 obj FROM rel_raci responsible_raci_r WHERE responsible_raci_r.PERSON_ID = organization.id AND responsible_raci_r.RACI ='I') AS informed_inverted 
FROM obj_resource organization
WHERE CONTAINS('2cef8e3d:15992b7f51e:33f', organization.id, -1) AND getOrgtype(organization.id) != 1

1 个答案:

答案 0 :(得分:0)

您要问的一般语法是:

SELECT {columns_list}
  FROM {table_name}
 WHERE {column_name} IN (SELECT {column_name}
                           FROM {table_name}
                          WHERE {condition(s)}
                        ) A ;