查詢問題!在線!

wuzongjie 2002-11-18 05:01:05
在sql server 2000中有一個表table1,它有四個字段,分別為:name,spec,unit,count
在這個表中有兩條記錄,
第一條為:釘,10*30,條,50
第二條為:釘,10*30,條,40
如何寫SQL語句,使查詢結果為:
隻有一條記錄如下:釘,10*30,條,90,即把第四個定段求和。
我用語句為:
select table1.name,table1.spec,table1.unit,sum(table.count) as total
from table1
group by table1.name
但總是出錯,得不到結果。錯誤提示:table1.spec is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

table1.unit is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

多謝!
...全文
34 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuzongjie 2002-11-18
  • 打赏
  • 举报
回复
感謝LIURI(璇璣)的回復!
liuri璇玑 2002-11-18
  • 打赏
  • 举报
回复
or:
select table1.name,max(table1.spec),max(table1.unit),sum(table.count) as total
from table1
group by table1.name
liuri璇玑 2002-11-18
  • 打赏
  • 举报
回复
select table1.name,table1.spec,table1.unit,sum(table.count) as total
from table1
group by table1.name,table1.spec,table1.unit

22,299

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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