我在下面有以下sql。
select col1, col2 from table1
union
select col1, col2 from table2
现在我想能够从上面计算联合集中的总行数,并按col2排序。我该怎么做?
答案 0 :(得分:2)
with a as (
select col1, col2 from table1
union
select col1, col2 from table2
)
select *,count(1) over()
from a
order by col2
;