答案 0 :(得分:7)
使用窗口功能:
SELECT col1, col2, col3, COUNT(*) OVER () AS total_rows
FROM mytable
答案 1 :(得分:2)
如果你的意思是总到目前为止那么:
select c1, c2, c3,
count(*) over (order by c1 range unbounded preceding) as total_rows
from mytable
order by c1
这将得到如下结果:
C1 C2 C3 TOTAL_ROWS
A B C 1
A B D 2
B D E 3
...