如果我在phpmyadmin中运行以下查询,则会将我误解为
>查询错误(1054):未知列' QTY'在' where子句'
SELECT User_Name,
COUNT(User_Name) AS QTY
FROM preusage
WHERE QTY > 1
GROUP BY User_Name
请有人帮助我
答案 0 :(得分:3)
不允许在WHERE子句中引用列别名,因为在执行WHERE子句时可能尚未确定列值。
但在你的情况下,我想你想要使用having
(可以使用先前定义的别名)
SELECT User_Name, COUNT(User_Name) as QTY
FROM preusage
GROUP BY User_Name
HAVING QTY > 1
答案 1 :(得分:0)
使用having而不是where子句,因为你正在使用group by
SELECT User_Name,
COUNT(User_Name) AS QTY
FROM preusage
GROUP BY User_Name HAVING User_Name > 1