是否可以编写此oracle查询的优化版本,使其不执行10次?
提前谢谢你的帮助。
select async, column1 from
(
select distinct async, COLUMN1 from Table1
where COLUMN1 is not null
union
select distinct async, COLUMN2 as COLUMN1 from Table1 and
where COLUMN1 is null and COLUMN2 is not null
union
select distinct async, COLUMN3 as COLUMN1 from Table1
where COLUMN1 is null and COLUMN2 is null and COLUMN3 is not null
union
select distinct async, COLUMN4 as COLUMN1 from Table1
where COLUMN1 is null and COLUMN2 is null and COLUMN3 is null and
COLUMN4 is not null
union
select distinct async, COLUMN5 as COLUMN1 from Table1
where COLUMN1 is null and COLUMN2 is null and COLUMN3 is null and
COLUMN4 is null and COLUMN5 is not null
union
select distinct async, COLUMN6 as COLUMN1 from Table1
where COLUMN1 is null and COLUMN2 is null and COLUMN3 is null and
COLUMN4 is null and COLUMN5 is null and
COLUMN6 is not null
union
select distinct async, COLUMN7 as COLUMN1 from Table1
where COLUMN1 is null and COLUMN2 is null and COLUMN3 is null and
COLUMN4 is null and COLUMN5 is null and COLUMN6 is null and
COLUMN7 is not null
union
select distinct async, COLUMN8 as COLUMN1 from Table1
where
COLUMN1 is null and COLUMN2 is null and COLUMN3 is null and
COLUMN4 is null and COLUMN5 is null and COLUMN6 is null and
COLUMN7 is null and COLUMN8 is not null
union
select distinct async, COLUMN9 as COLUMN1 from Table1
where
COLUMN1 is null and COLUMN2 is null and COLUMN3 is null and
COLUMN4 is null and COLUMN5 is null and COLUMN6 is null and
COLUMN7 is null and COLUMN8 is null and COLUMN9 is not null
union
select distinct async, COLUMN10 as COLUMN1 from Table1
where COLUMN1 is null and COLUMN2 is null and
COLUMN3 is null and COLUMN4 is null and COLUMN5 is null and
COLUMN6 is null and COLUMN7 is null and COLUMN8 is null and
COLUMN9 is null and COLUMN10 is not null
)
发布于 2015-08-02 18:38:48
聚结做到了这一点,它选择第一个非空值
select DISTINCT async, coalesce(column1,column2,column3,column4,...) from Table1;https://stackoverflow.com/questions/31775126
复制相似问题