请教一个简单的sql查询问题

pbtech 2002-11-18 02:45:08
现在要select 出仓库中所有的货物单价(price)和数量(mount),计算出各中货物的总额
price*mount,然后要汇总所有货物的价格sum(price*mount),这条sql语句怎样写?

select price,mount,sum(price*mount) from uprvdmx
我这样写总是提示 、列 'uprvdmx.price''uprvdmx.cost 在选择列表中无效,因为该列未包含在聚合函数中,并且没有 GROUP BY 子句。“
...全文
22 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
CrazyFor 2002-11-18
  • 打赏
  • 举报
回复
select price,mount,sum(price*mount) as totalAmount,'1' as groupbystr into #temp from uprvdmx group by 货物


select price,mount,sum(price*mount) as Pmount from #temp

select sum(totalAmount) from #temp group by groupbystr
CrazyFor 2002-11-18
  • 打赏
  • 举报
回复
select price,mount,sum(price*mount),'1' as groupbystr into #temp from uprvdmx group by 货物


select price,mount,sum(price*mount) as mount from #temp

select sum(mount) from #temp group by groupbystr


lbd8848 2002-11-18
  • 打赏
  • 举报
回复
select price,mount,sum(price*mount) from uprvdmx group by price,mount

34,576

社区成员

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

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