SQL 查询未显示预期结果
所以我创建了一个集成脚本,但由于某种原因它没有显示预期的结果。 我的查询是
SELECT xf_user_group_relation.user_id, xf_user_group_relation.user_group_id, MAX( xf_user_group.display_style_priority ) AS display_style_priority
FROM xf_user_group_relation
INNER JOIN xf_user_group ON xf_user_group_relation.user_group_id = xf_user_group.user_group_id
WHERE xf_user_group.display_style_priority >=1000
GROUP BY user_id
结果中意外的行之一是
user_id | user_group_id | display_style_priority
86 | 11 |5200
The group with the id 11 has display_style_priority 2000 and not 5200. 它应该显示带有 display_style_priority 5200 的用户组 id。 该用户所在的排名最高的组是哪个。 有人可以指出我做错了什么吗?
So im creating a integration script, but for some reason its not showing the exprected result.
My query is
SELECT xf_user_group_relation.user_id, xf_user_group_relation.user_group_id, MAX( xf_user_group.display_style_priority ) AS display_style_priority
FROM xf_user_group_relation
INNER JOIN xf_user_group ON xf_user_group_relation.user_group_id = xf_user_group.user_group_id
WHERE xf_user_group.display_style_priority >=1000
GROUP BY user_id
One of the lines in the result which is unexpected is this
user_id | user_group_id | display_style_priority
86 | 11 |5200
The group with the id 11 has display_style_priority 2000 and not 5200. It should show the user group id with display_style_priority 5200.
Which is the highest ranked group this user is in.
Can somebody point out what im doing wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将 GROUP BY 更改为
大多数其他 DBMS 都会对该查询引发错误,因为 SELECT 列表中的每一列都必须聚合或位于 GROUP BY 中。
编辑:这是一个很好的例子,说明了为什么 ANSI-SQL 和其他 RDBMS 不允许这种语法
Try changing the GROUP BY to
Most other DBMS would throw an error for that query because every column in the SELECT list must be either aggregated or in the GROUP BY.
Edit: this is a great example of why ANSI-SQL and other RDBMS do not allow this syntax