gpt4 book ai didi

mysql - 我不明白我做错了什么

转载 作者:太空宇宙 更新时间:2023-11-03 12:06:06 25 4
gpt4 key购买 nike

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

有人帮帮我

最佳答案

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.

但在你的情况下,我猜你想使用 having 无论如何(它可以使用以前定义的别名)

SELECT User_Name, COUNT(User_Name) as QTY 
FROM preusage
GROUP BY User_Name
HAVING QTY > 1

关于mysql - 我不明白我做错了什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26572988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com