我有一个代码可以查看我的销售员工。他最近受聘为已灭绝的客户创造增长。因此,在我们在 dbase 中拥有的 1,000 多个客户中,他只会影响 100 个。因此,在他的值所在的位置生成了很多行NULL
。我希望报告排除这些客户行,以便更有效地了解我的管理层。我将如何做到这一点?
select T1.CardCode 'BP Code',
T1.CardName 'BP Name',
COUNT(CASE WHEN T1.SlpCode<>'37' THEN T0.DocNum END) '# of Orders',
SUM(CASE WHEN T1.SlpCode<>'37' THEN T0.DocTotal END) 'Total Orders Amt',
SUM(CASE WHEN T1.SlpCode<>'37' THEN T0.DOCTOTAL END)/
COUNT(CASE WHEN T1.SlpCode<>'37' THEN T0.DocNum END) 'Avg Order Size',
COUNT(CASE WHEN T1.SlpCode='37' THEN T0.DocNum END) '# of Orders',
SUM(CASE WHEN T1.SlpCode='37' THEN T0.DocTotal END) 'Total Orders Amt',
SUM(CASE WHEN T1.SlpCode='37' THEN T0.DOCTOTAL END)/
COUNT(CASE WHEN T1.SlpCode='37' THEN T0.DocNum END) 'Avg Order Size'
from ORDR T0 INNER JOIN OCRD T1 ON T0.CardCode=T1.CardCode
where T0.DocStatus = 'C'
AND T0.CANCELED <> 'Y'
AND T0.DocDate >= '2015-05-26'
GROUP BY T1.CardCode,
T1.CardName
Order By t1.CardName