失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > oracle中union all优化 【讨论】UNION ALL 语句优化

oracle中union all优化 【讨论】UNION ALL 语句优化

时间:2021-03-14 05:42:01

相关推荐

oracle中union all优化 【讨论】UNION ALL 语句优化

SQL> select owner , view_name , text from dba_views where view_name='V_WARM_ASSET';

OWNER VIEW_NAMETEXT

---------- ---------- --------------------------------------------------

ALCM V_WARM_ASS select '500kV' as 类别,

ETsum(case

when status = '运行中' then

1

else

0

end) as 正常,

sum(case

when status = '停止使用' then

1

else

0

end) as 异常,

sum(case

when status = '删除' then

1

else

0

end) as 停运

from sc_asset t

where t.ydtf_dydj = 1

union all

select '220kV' as 类别,

sum(case

when status = '运行中' then

else

1

0

end) as 正常,

sum(case

when status = '停止使用' then

1

else

0

end) as 异常,

sum(case

when status = '删除' then

1

else

0

end) as 停运

from sc_asset t

where t.ydtf_dydj = 2

union all

select '110kV' as 类别,

sum(case

when status = '运行中' then

1

else

0

end) as 正常,

sum(case

when status = '停止使用' then

1

else

0

end) as 异常,

sum(case

when status = '删除' then

1

else

0

end) as 停运

from sc_asset t

where t.ydtf_dydj = 3

union all

select '其它等级' as 类别,

sum(case

when status = '运行中' then

1

else

0

end) as 正常,

sum(case

when status = '停止使用' then

1

else

0

end) as 异常,

sum(case

when status = '删除' then

1

else

0

end) as 停运

from sc_asset t

where t.ydtf_dydj not in (1, 2, 3)

union all

/*设备类型*/

。。。

就是这么一个语句,有十多个union all,运行直接把服务器拖死,大家看看要怎么优化呢?

附件里面是完整的语句

-10-15 14:27 上传

点击文件名下载附件

16.32 KB, 下载次数: 40

如果觉得《oracle中union all优化 【讨论】UNION ALL 语句优化》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。