如何显示" name"的结果在两个不同的列i,e。它有2个不同的值?从第一个查询我在名称字段中得到Admin,而从第二个查询我在名称字段中得到Mobile_user,我想要的结果将在两个不同的字段中显示admin和mobile_user
SELECT T1.autgro_id id,
T1.name,
T2.use_id
FROM adm_auth_groups_wv T1
INNER JOIN adm_user_auth_groups_wv T2
ON T1.autgro_id=T2.autgro_id
INNER JOIN ym_customers_wv T3
ON T1.cus_id=T3.cus_id
WHERE T3.cus_id_parent = 4
AND T2.use_id =24
UNION All
SELECT T1.autgro_id id,
T1.name,
T2.use_id
FROM adm_auth_groups_wv T1
INNER JOIN adm_user_auth_groups_wv T2
ON T1.autgro_id = T2.autgro_id
WHERE yard_functions_pkg.get_parent_from_cus_id(T1.cus_id) = 4 AND
T1.autgro_id
NOT IN
(SELECT
T2.autgro_id
FROM
adm_user_auth_groups_wv T2
WHERE
T2.use_id=24)
答案 0 :(得分:0)
在两个查询中使用虚拟列,在第一个查询中填充一列,在第二个查询中填充另一列。
SELECT T1.autgro_id id,
T1.name admin_user,
null mobile_user,
T2.use_id
FROM adm_auth_groups_wv T1
INNER JOIN adm_user_auth_groups_wv T2
ON T1.autgro_id=T2.autgro_id
INNER JOIN ym_customers_wv T3
ON T1.cus_id=T3.cus_id
WHERE T3.cus_id_parent = 4
AND T2.use_id =24
UNION All
SELECT T1.autgro_id id,
null admin_user,
T1.name mobile_user,
T2.use_id
FROM adm_auth_groups_wv T1
INNER JOIN adm_user_auth_groups_wv T2
ON T1.autgro_id = T2.autgro_id
WHERE yard_functions_pkg.get_parent_from_cus_id(T1.cus_id) = 4 AND
T1.autgro_id
NOT IN
(SELECT
T2.autgro_id
FROM
adm_user_auth_groups_wv T2
WHERE
T2.use_id=24)