专栏"名称"具有不同的值,我想在两个不同的列中显示这些值。但怎么样?

时间:2015-10-05 11:00:02

标签: sql oracle

如何显示" 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)

1 个答案:

答案 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)