If I run below query in my phpmyadmin it throw me below error
> Error in query (1054): Unknown column 'QTY' in 'where clause'
SELECT User_Name,
COUNT(User_Name) AS QTY
FROM preusage
WHERE QTY > 1
GROUP BY User_Name
Please somebody help me
If I run below query in my phpmyadmin it throw me below error
> Error in query (1054): Unknown column 'QTY' in 'where clause'
SELECT User_Name,
COUNT(User_Name) AS QTY
FROM preusage
WHERE QTY > 1
GROUP BY User_Name
Please somebody help me
It is not allowable to refer to a column alias in a WHERE clause, because the column value might not yet be determined when the WHERE clause is executed.
But in your case I guess instead you want to use having anyway (which can use previously defined aliases)
SELECT User_Name, COUNT(User_Name) as QTY
FROM preusage
GROUP BY User_Name
HAVING QTY > 1
use having instead of where clause as you are using group by
SELECT User_Name,
COUNT(User_Name) AS QTY
FROM preusage
GROUP BY User_Name HAVING User_Name > 1