COUNT计数不正确

时间:2014-03-07 22:36:03

标签: sql count

我想知道客户通过电话或互联网订购产品的次数。 adduser字段指示订单的放置方式。我正在使用下面的脚本,但它没有返回正确的值。如果我在桌面上选择日期和来自下方的custno,则总共有30个结果,但没有一个属于“互联网”类别。伯爵说互联网有19项结果。

SELECT custno, company, COUNT(internet) AS VPI
FROM   (SELECT a.custno, company, COUNT(c.adduser) AS internet
        FROM   arcust a
         LEFT  JOIN armast b ON a.custno = b.custno
         LEFT  JOIN somast c ON a.custno = c.custno
        WHERE  invdte BETWEEN '02-03-2014' AND '03-03-2014'
          AND  indust = 'S'
          AND  c.adduser = 'VPI'
          AND  b.custno = '12827'
        GROUP  BY a.custno, company, b.invdte) a
GROUP   BY custno, company
ORDER   BY custno

0 个答案:

没有答案