我使用多个视图使用子查询和联合获取两列,我想减少执行时间。
select a.empid,empname from
(select empid,empname from india_emp where deptno <> 10
union
select empid,empname from us_emp where deptno <> 10
union
select empid,empname from uk_emp where deptno <> 10
union
select empid,empname from uae_emp where deptno <> 10
union
select empid,empname from brazl_emp where deptno <> 10
union
select empid,empname from chine_emp where deptno <> 10
union
select empid,empname from jpn_emp where deptno in (54,256,362,9879,24,46)
)a
where a.empid NOT IN(105,202,11,45,695,646,726,8465,965,56,646,689,446)
order by 2
答案 0 :(得分:0)
将所有Union
更改为Union All
,这样便宜。
像这样:
SELECT a.empid,empname FROM
(SELECT empid,empname FROM india_emp WHERE deptno <> 10
UNION ALL
SELECT empid,empname FROM us_emp WHERE deptno <> 10
UNION ALL
SELECT empid,empname FROM uk_emp WHERE deptno <> 10
UNION ALL
SELECT empid,empname FROM uae_emp WHERE deptno <> 10
UNION ALL
SELECT empid,empname FROM brazl_emp WHERE deptno <> 10
UNION ALL
SELECT empid,empname FROM chine_emp WHERE deptno <> 10
UNION ALL
SELECT empid,empname FROM jpn_emp WHERE deptno in (54,256,362,9879,24,46)
)a
WHERE a.empid NOT IN(105,202,11,45,695,646,726,8465,965,56,646,689,446)
ORDER BY 2
答案 1 :(得分:0)
你可以尝试在派生表中使用empid过滤器吗?
select a.empid,empname from
(select empid,empname from india_emp where deptno <> 10 and empid NOT IN(105,202,11,45,695,646,726,8465,965,56,646,689,446)
union
select empid,empname from us_emp where deptno <> 10 and empid NOT IN(105,202,11,45,695,646,726,8465,965,56,646,689,446)
union
select empid,empname from uk_emp where deptno <> 10 and empid NOT IN(105,202,11,45,695,646,726,8465,965,56,646,689,446)
union
select empid,empname from uae_emp where deptno <> 10 and empid NOT IN(105,202,11,45,695,646,726,8465,965,56,646,689,446)
union
select empid,empname from brazl_emp where deptno <> 10 and empid NOT IN(105,202,11,45,695,646,726,8465,965,56,646,689,446)
union
select empid,empname from chine_emp where deptno <> 10 and empid NOT IN(105,202,11,45,695,646,726,8465,965,56,646,689,446)
union
select empid,empname from jpn_emp where deptno in (54,256,362,9879,24,46)
)a
where
order by 2