+ 2

Why alias 'NC' is referred as unknow column?

MySql code:- SELECT C.HACKER_ID,COUNT(C.CHALLENGE_ID) AS NC FROM CHALLENGES AS C WHERE C.NC=50 GROUP BY C.HACKER_ID; OUTPUT:- ERROR 1054 (42S22) at line 4: Unknown column 'C.NC' in 'where clause' pls reply me the correct query

23rd Mar 2022, 5:59 PM
Jawahirullah
Jawahirullah - avatar
3 Antworten
0
Jawa this might be a use case for the HAVING clause. Try this: SELECT C.HACKER_ID,COUNT(C.CHALLENGE_ID) AS NC FROM CHALLENGES AS C GROUP BY C.HACKER_ID HAVING COUNT(C.CHALLENGE_ID)=50;
23rd Mar 2022, 8:16 PM
Brian
Brian - avatar
0
-- try this SELECT C.HACKER_ID, COUNT(C.CHALLENGE_ID) AS NC FROM CHALLENGES C WHERE COUNT(C.CHALLENGE_ID)=50 GROUP BY C.HACKER_ID;
23rd Mar 2022, 8:45 PM
SoloProg
SoloProg - avatar