我在oralce 11g中有这个查询:
SELECT (case when APIPueFun='A' then Auditor.UNombre else null end) audi,
(case when APIPueFun='S' then Supervisor.UNombre else null end) supe
FROM SATAPersInte,
SATUsuario Auditor,
SATUsuario Supervisor
WHERE APINCIUsu = Auditor.UNCIUsua
AND APINCIUsu = Supervisor.UNCIUsua
AND APIPueFun in ('A','S')
AND APINCIAud =134440;
我有这个结果:
NOMBREAU NOMBRESU
------------------------------------------- -----------------------------------
Lic. Marcela Espinosa Muciño (null)
P.L.A.E. Alejandro Antonio (null)
(null) L.C. Claudia Serrano Cobos
(null) Lic. Rosalba Montero Gómez
(null) Lic. Víctor Antonio Lemus
(null) Lic. Yatzaret Velarde
但我想要这个结果:
NOMBREAU NOMBRESU
------------------------------------------- -----------------------------------
Lic. Marcela Espinosa Muciño L.C. Claudia Serrano Cobos
P.L.A.E. Alejandro Antonio Lic. Rosalba Montero Gómez
(null) Lic. Víctor Antonio Lemus
(null) Lic. Yatzaret Velarde
(null) (null)
(null) (null)
我该怎么做?
答案 0 :(得分:0)
SELECT (case when APIPueFun='A' then Auditor.UNombre else null end) audi,
(case when APIPueFun='S' then Supervisor.UNombre else null end) supe
FROM SATAPersInte,
SATUsuario Auditor,
SATUsuario Supervisor
WHERE APINCIUsu = Auditor.UNCIUsua
AND APINCIUsu = Supervisor.UNCIUsua
AND APIPueFun in ('A','S')
AND APINCIAud =134440
ORDER BY NOMBREAU DESC NULLS LAST
, NOMBRESU DESC NULLS FIRST;
答案 1 :(得分:0)
您似乎希望两个不相关的数据列彼此相邻。这很不寻常。要做到这一点,你需要分配每个音频和supe一个数字,然后将它们连接在一起。您可以使用ROW_NUMBER执行此操作
With data as (
SELECT (case when APIPueFun='A' then Auditor.UNombre else null end) audi,
(case when APIPueFun='S' then Supervisor.UNombre else null end) supe
FROM SATAPersInte,
SATUsuario Auditor,
SATUsuario Supervisor
WHERE APINCIUsu = Auditor.UNCIUsua
AND APINCIUsu = Supervisor.UNCIUsua
AND APIPueFun in ('A','S')
AND APINCIAud =134440) ,
rowNumbers as
( Select
audi,
row_number() over (order by audi) aRN,
supe,
row_number() over (order by supe) sRN
FROM
data)
Select
a.audi,
s.supe
FROM
rowNumbers a
FULL OUTER JOIN rowNumbers s
on a.aRN = s.sRN
ORDER BY
a.aRN,
s.sRN