select A.productID,B.title,A.OuterNo,A.CustomerID,ShopID,ISdel,sum(D.Amount),sum(D.Count),Session
from V5ESB_Customer_CustomerItem A
inner join V5ESB_Customer_CustomerChannel B
on A.CustomerID =B.CustomerID
inner join V5ESB_Order_Order C
on A.CustomerID =C.CustomerID
inner join V5ESB_Order_Product D
on C.Code=D.OrderCode where D.productID=1266 GROUP BY a.customerID,A.productID,B.title,A.OuterNo,ShopID,ISdel,Session
group by 後面的分組字段要有一一對應關係,才能分成一個分組,不能有一一對應關係的可以使用where過濾之後進行分組;
要select 的字段需要放在group by 中,如果不放的,要使用聚合函數sum, avg,count等等