查詢問題!在線!
在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.
多謝!