Select * From ( Select FBillNo, FDeptID, FQty, FTaxRate, FAmount From TableName Union All Select FBillNo&'小计' ,'','','',sum(FAmount) As FAmount from TableName group by FBillNo union all Select '总计' ,'','','',sum(FAmount) As FAmount from TableName ) order by( FBillNo='总计') desc, FBillNo追问
select b.*, SumFDeptID,SumFItemID,SumFQty,SumFTaxRate,SumFAmount,(SumFDeptID + SumFItemID + SumFQty + SumFTaxRate + SumFAmount) as SumCount from (select FBillNo,sum(FDeptID) as SumFDeptID,sum(FItemID) as SumFItemID,sum(FQty) as SumFQty,sum(FTaxRate) as SumFTaxRate,sum(FAmount) as SumFAmount from 表 group by FBillNo) as a,表 as b where a.FBillNo=b.FBillNo追问