表格 ARMASTER =客户信息 ORDERHEAD =销售订单信息(送货到,开帐单)
嘿大家好!我对SQL仍然很陌生,我相信我很快就会把它拿起来。我现在已经绞尽脑汁待了几个小时,并在办公室周围询问,似乎没有人有解决方案。我正在尝试确定客户帐户被用作SHIP TO位置的次数。比尔到位。
SELECT ARMASTER.CUSTOMER,
ARMASTER.DIVISION,
ARMASTER.STATUS,
ARMASTER.CUHEAD AS "MASTER",
COUNT (ORDERHEAD.BILLTO) AS "COUNT_BILL",
COUNT (ORDERHEAD.SHIPTO) AS "COUNT_SHIP"
FROM ARMASTER
LEFT OUTER JOIN ORDERHEAD
ON ARMASTER.CUSTOMER = ORDERHEAD.BILLTO
LEFT OUTER JOIN ORDERHEAD
ON ARMASTER.CUSTOMER = ORDERHEAD.SHIPTO
GROUP BY ARMASTER.CUSTOMER,
ARMASTER.DIVISION,
ARMASTER.STATUS,
ARMASTER.CUHEAD
而且我甚至都没有遥控器得到我应该得到的东西。但是,当我删除其中一个连接时,计数正是它应该是1或者其他的连接。
任何指导都将非常感谢!谢谢!
答案 0 :(得分:0)
我认为它也可以起作用
SELECT CUSTOMER,
DIVISION,
STATUS,
CUHEAD AS "MASTER",
(SELECT COUNT(1) FROM ORDERHEAD WHERE SHIPTO = ARMASTER.CUSTOMER ) AS "COUNT_BILL",
(SELECT COUNT(1) FROM ORDERHEAD WHERE BILLTO = ARMASTER.CUSTOMER ) AS "COUNT_SHIP"
FROM ARMASTER