1

我只是试图通过数据网格显示详细信息利用此查询

select 
P.Sitename as Site
,P.Vendorname as Vendor
,P.POno,PS.Itemcode as ItemCode
,sum(PS.Quantity) as Qty
,sum(PS.Basic) as Basic
,Sum(PS.DiscountAmt) as [Disc Amt]
,sum(PS.PFAmt) as [PF Amt]
,sum(PS.EDAmt) as [ED Amt]
,sum(PS.VATCSTAmt) as [VATCST Amt]
,sum(PS.Netamt) as Total
,I.Itemname as Itemname
,I.UOM as UOM  
from tbl_Itemmaster I, tbl_Purchaseorder_sub PS,tbl_Purchaseorder P 
where P.POdate between '8/30/2012' and '8/31/2012' 
and PS.status in (4,5) 
and I.Itemidentify=Ps.ITemcode 
and PS.pono=p.POno 
group by PS.Itemcode,P.Sitename,P.Vendorname,I.Itemname,I.UOM   
order by Site,Vendor,ItemCode

但是,我在执行此操作时遇到错误,即

"Column 'tbl_Purchaseorder.POno' is invalid in the select list because 
it is not contained in either an aggregate function or the GROUP BY clause."

请谁能告诉我我该如何纠正它

4

1 回答 1

1

您需要将 POno 添加到 GROUP BY Cluase

就像是

select  P.Sitename as Site,
        P.Vendorname as Vendor,
        P.POno,
        PS.Itemcode as ItemCode,
        sum(PS.Quantity) as Qty,
        sum(PS.Basic) as Basic,
        Sum(PS.DiscountAmt) as [Disc Amt],
        sum(PS.PFAmt) as [PF Amt],
        sum(PS.EDAmt) as [ED Amt],
        sum(PS.VATCSTAmt) as [VATCST Amt],
        sum(PS.Netamt) as Total ,
        I.Itemname as Itemname,
        I.UOM as UOM  
from    tbl_Itemmaster I, 
        tbl_Purchaseorder_sub PS,
        tbl_Purchaseorder P 
where   P.POdate between '8/30/2012' 
and     '8/31/2012' 
and     PS.status in (4,5) 
and     I.Itemidentify=Ps.ITemcode 
and     PS.pono=p.POno 
group by    PS.Itemcode,
            P.Sitename,
            P.Vendorname,
            I.Itemname,
            I.UOM,
            P.POno <-- You need to add this to your query
order by    Site,
            Vendor,
            ItemCode 
于 2012-08-31T06:50:42.410 回答