zundarz
zundarz

Reputation: 1594

How do I get total count of result set to appear in every record of output?

Using Oracle 11g

How can I write query to include a 4th column which displays the total rows returned?

I'm having technical difficulties posting a question as noted here. As soon as this posts, I'll continue with my edit.

Upvotes: 2

Views: 265

Answers (2)

Tony Andrews
Tony Andrews

Reputation: 132630

If you had meant the total so far then:

select  c1, c2, c3, 
        count(*) over (order by c1 range unbounded preceding) as total_rows
from    mytable
order by c1

This will get a result like:

C1 C2 C3 TOTAL_ROWS
A  B  C  1
A  B  D  2
B  D  E  3
...

Upvotes: 2

Quassnoi
Quassnoi

Reputation: 425613

Use the window function:

SELECT  col1, col2, col3, COUNT(*) OVER () AS total_rows
FROM    mytable

Upvotes: 7

Related Questions