帮忙看个SQL语句

wolf00781 2006-09-29 04:15:01
select ToiletryId,count(ToiletryId) as 'cost',ToiletryName,Path from ToiletryLike,Toiletry where Flag=2 and Toiletry.Id=ToiletryLike.ToiletryId and City='北京' group by ToiletryId order by cost desc
有什么语法错误,在查询分析器里我试了,提示说:
Server: Msg 8120, Level 16, State 1, Line 1
Column 'Toiletry.ToiletryName' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Server: Msg 8120, Level 16, State 1, Line 1
Column 'Toiletry.Path' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Toiletry里的两个字段为什么不管用,
...全文
142 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenli20061027 2006-09-29
  • 打赏
  • 举报
回复
ToiletryId and City='北京'
ToiletryId ToiletryName
你有两个定义的数据!在这里能用and表示吗?
liudianhalf 2006-09-29
  • 打赏
  • 举报
回复
分组查询时查询中要显示的列要么在分组列表中,要么在聚合函数中,否则就报你那个错

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧