比较销售账户时出现错误 "Only one expression can be specified in the select list when the subquery is not introduced with EXISTS."

Getting error "Only one expression can be specified in the select list when the subquery is not introduced with EXISTS." for comparing sales accounts

尝试将 2 列与基于销售人员的另外 2 列进行比较时出现以下错误。

Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

我的代码是这样的:

select  T1.CardCode 'BP Code',
        T1.CardName 'BP Name',
        COUNT(T0.DocNum) '# of Orders',
        SUM(T0.DocTotal) 'Total Orders Amt',
        SUM(T0.DOCTOTAL)/COUNT(T0.DOCNUM) 'Avg Order Size',
        (SELECT COUNT(T0.DocNum),
        SUM(T0.DocTotal),
        SUM(T0.DOCTOTAL)/COUNT(T0.DOCNUM)

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'
        AND T1.SlpCode = '37'

GROUP BY    T1.CardCode,
            T1.CardName) 

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'
        AND T1.SlpCode <> '37'

GROUP BY    T1.CardCode,
            T1.CardName

我想比较新员工入职前的客户账户与 post 新销售员工自今年受雇之日起的客户账户。所以我想要 6 列。

当前帐户持有人生成的 [订单数量]、[订单总金额]、[平均订单大小] 3 列对比 [订单数量]、[订单总金额]、[平均订单数量] 3 列size] 由销售人员“37”生成。

关于重新排列此代码以实现我正在寻找的内容的任何建议??

我认为只查询一次表就足够了:

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),
        SUM(CASE WHEN T1.SlpCode='37' THEN T0.DocTotal END),
        SUM(CASE WHEN T1.SlpCode='37' THEN T0.DOCTOTAL END)/
          COUNT(CASE WHEN T1.SlpCode='37' THEN T0.DocNum END),

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

您可能还想删除此处计算平均值的列,并在后面的步骤中执行该处理,例如使用此结果集的代码,这样您就不必处理被零除的问题,如果这是一个风险。