Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Count over table

$
0
0

This is my table schema

CREATE TABLE submittedProblem 
	(
     userID int,  
     contestID int,
     problemID int,
     score int
    );



INSERT INTO submittedProblem
(userID, contestID, problemID, score)
VALUES
(1, 1, 1, 10),
(1, 1, 2, 10),
(2, 1, 1, 5),
(1, 2, 1, 3),
(2, 2, 2, 3),
(2, 2, 2, 2),
(3, 2, 2, 1);

This is my query. This will return Rank of each User on each Contest based on their score.

select
t.contestID,
t.userID,
t.Score,
RANK() over(partition by 
            t.contestID
            order by t.Score desc) as Rank
from
(
select 
csp.contestID,
csp.userID,
sum(csp.score) as Score 
from 
submittedProblem csp
group by
csp.contestID,
csp.userID
) t

Now, I want to count the number participant on each contest on this query.

How can I find it?

Thank You



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>