日期:2014-05-18  浏览次数:20458 次

求一sql语句,汇总!谢谢
SELECT  
           
              t3.fname   as   '商品名称 ',
              t3.FModel   AS   '规格型号 ',
              t4.FName   AS   '计量单位 ',
              sum(t2.fqty)   as   '数量 ',
              t2.fprice   as   '单价 ',
              t2.famount   as   '金额 '
FROM   ICStockBill   t1,ICStockBillentry   t2,t_ICItem   t3,t_MeasureUnit   t4,t_item   t5
WHERE   t1.FInterID=t2.FInterID
AND   t2.FItemID=t3.FItemID
AND   t4.FItemID=t3.FUnitID
AND   t1.ftrantype=21
and   t1.fsupplyid=t5.fitemid  
GROUP   BY   t3.fname,t3.fmodel,t4.fname,t2.fprice,t2.famount,t2.fqty
order   by   t3.fname
按商品名称汇总数量和金额    
但是结果显示不能汇总.请教

------解决方案--------------------
SELECT

t3.fname as [商品名称],
sum(t2.fqty) as [数量],
sum(t2.famount) as '金额 '
FROM ICStockBill t1,ICStockBillentry t2,t_ICItem t3,t_MeasureUnit t4,t_item t5
WHERE t1.FInterID=t2.FInterID
AND t2.FItemID=t3.FItemID
AND t4.FItemID=t3.FUnitID
AND t1.ftrantype=21
and t1.fsupplyid=t5.fitemid
GROUP BY t3.fname
order by t3.fname

你要汇总t2.fqty和t2.famount,怎么还能再 group by t2.fqty,t2.famount ?
你是要按 "商品名称 "汇总,其他的 "规格型号 ", "计量单位 ", "单价 "就不该再出现