Number Functions: Count (Running Count)

Description: Returns a running count of all records or by partition.

COUNT(<*, [DISTINCT | ALL] <expression>>) OVER (<analytic clause>)
 
SELECT submit_date, num_votes, TRUNC(COUNT(votes)
OVER(ORDER BY submit_date ROWS UNBOUNDED PRECEDING)) AS DAY_COUNT
FROM votes
ORDER BY submit_date;
 
SELECT submit_date, COUNT(*)
OVER(PARTITION BY submit_date ORDER BY submit_date
ROWS UNBOUNDED PRECEDING) NUM_RECS
FROM votes;

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.