Reputation: 11255
I have been doing this for quite some time:
SELECT COUNT(*) AS 'Rank' FROM Table
WHERE Condition = 'Condition' AND Score >= 'Score';
SELECT COUNT(*) AS 'Total' FROM Table
WHERE Condition = 'Condition';
Is there a more efficient way of getting both Rank and Total?
Upvotes: 2
Views: 174
Reputation: 453298
You can calculate both at the same time with one pass through the data.
SELECT COUNT(*) AS 'Total',
SUM(CASE WHEN Score >= 'Score' THEN 1 ELSE 0 END) AS `Rank`
FROM Table
WHERE Condition = 'Condition';
Upvotes: 3