看了你的SQL,几段都差不多,考虑合并吧。此外,对于嵌套查询,可以利用with 语句。如:
with t as (
select * from aaaa)select * from t;