列在选择列表中无效,因为它未包含在聚合函数或 GROUP BY 子句中
我下面有 sql 查询,但执行时遇到问题。
SELECT * from (Select row_number() OVER(Order By FloorUserId) as 'row_number', FloorUserId,
max(CASE WHEN AreaId='[G]' or AreaId=N'L01' THEN 'X' ELSE ' ' END) as 'L01',
max(CASE WHEN AreaId='[G]' or AreaId=N'L02' THEN 'X' ELSE ' ' END) as 'L02'
from floor, tbuser where FloorUserId= tbuser.userID
) as derivedTable where row_number BETWEEN 1 AND 20
但我不断收到以下错误:
列“FloorId”在选择中无效 列出,因为它不包含在 聚合函数或 GROUP BY 子句。
I have sql query below but i face a problem when execute it.
SELECT * from (Select row_number() OVER(Order By FloorUserId) as 'row_number', FloorUserId,
max(CASE WHEN AreaId='[G]' or AreaId=N'L01' THEN 'X' ELSE ' ' END) as 'L01',
max(CASE WHEN AreaId='[G]' or AreaId=N'L02' THEN 'X' ELSE ' ' END) as 'L02'
from floor, tbuser where FloorUserId= tbuser.userID
) as derivedTable where row_number BETWEEN 1 AND 20
But I keep getting the following error:
Column 'FloorId' is invalid in the select
list because it is not contained in
either an aggregate function or the
GROUP BY clause.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许这可以帮助您到达您想要的地方:
Perhaps this may help you to get where you want:
当您使用聚合(如 max)时,只能使用属于 group by 子句一部分的字段。
因此,如果您希望其他字段将它们添加到 group by 子句中,请去掉“*”。
You can only use fields that are part of a group by clause when you use aggregrates (like max).
So get rid of the '*' if you want other fields add them into a group by clause.