SQL SELECT:发生的值> 1
我试图从此表中选择重复项:
snr zip
01 83
02 82
03 43
04 28
预期结果只是空表。因为它没有重复项。
我尝试过这个查询:
SELECT snr, zip
FROM student
GRUOP BY snr
HAVING (COUNT(zip) > 1)
但它说语法错误,并且我正在尝试查询聚合函数等。
I'm trying to select duplicates from this table:
snr zip
01 83
02 82
03 43
04 28
Expected result is just empty table. Cuz it got no duplicates.
I've tried with this query:
SELECT snr, zip
FROM student
GRUOP BY snr
HAVING (COUNT(zip) > 1)
But it says that syntax is error, and that I'm trying to query an aggregate functions, etc..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您需要从
SELECT
列中删除zip
,或者将其包装在聚合函数中,例如COUNT(zip)
:另请查看 @OMG Ponies 的回答以获取进一步的建议。
It looks like you need to either remove
zip
from theSELECT
columns, or else wrap it in an aggregate function, such asCOUNT(zip)
:Also check out @OMG Ponies's answer for further suggestions.
用途:
标准 SQL 要求 SELECT 子句中未包装在聚合函数(COUNT、MIN、MAX 等)中的列需要在 GROUP BY 中定义。然而,MySQL 和 SQLite 允许列省略。
此外,请使用 COUNT(DISTINCT ,否则您将面临误报的风险。
Use:
Standard SQL requires that columns in the SELECT clause that are not wrapped in aggregate functions (COUNT, MIN, MAX, etc) need to be defined in the GROUP BY. However, MySQL and SQLite allow for columns to be omitted.
Additionally, use COUNT(DISTINCT or you'll risk false positives.