HI i was solving a question in LeetCODE and I wrote the following query
WITH TotalCount AS (
SELECT COUNT(*) AS TotalCountOf FROM Register
)
SELECT
R.contest_id,
ROUND((CAST(COUNT(R.contest_id) AS FLOAT) * 100) / Tc.TotalCountOf, 2) AS [percentage]
FROM
Register R
CROSS JOIN TotalCount Tc
GROUP BY
R.contest_id,
ORDER BY
[percentage] DESC,
R.contest_id ASC;
I got the below error.
I am not sure what I am doing wrong in my code. Can anyone help?
Runtime Error
[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Common table expression defined but not used. (422) (SQLExecDirectW)
I was expecting to get the total count of records in register table in the cte to join with the original select query
Sarika Ramachandran Nair is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.