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等等