0

我有两张桌子:

表 GL

TRANS_NBR     BASE_AMOUNT    CTRL GRP
 120211282    -7200          77
 120211282    -300           77
 120211282    -10000         76

表 AP

TRANS_NBR   BASE_AMOUNT    CODE
 120211282  7500           Wire
 120211282  10000          ACH

我需要能够将代码列添加到 GL 表中,但需要先汇总金额。有谁知道如何做到这一点?谢谢

我从汤姆英格拉姆的回答中试过这个,

SELECT GLTRANS.REFERENCE, SUM(GLTRANS.BASE_AMOUNT) AS SUM_BASE_AMOUNT, CBCHECK.CODE 
FROM (      
SELECT GLTRANS.REFERENCE, GLTRANS.BASE_AMOUNT, CBCHECK.CODE         
FROM  LAWSON_PRODST.LAWSON.GLTRANS      
LEFT JOIN LAWSON_PRODTST.LAWSON.CBCHECK on CBCHECK.TRANS_NBR = GLTRANS.REFERENCE    
UNION       
SELECT GLTRANS.REFERENCE, GLTRANS.BASE_AMOUNT, CBCHECK.CODE         
FROM LAWSON_PRODTST.LAWSON.CBCHECK      
)       
GROUP BY GLTRANS.REFERENCE      

但是我得到一个“关键字“组附近的语法不正确”。任何人都可以发现这个问题吗?谢谢

4

2 回答 2

0
SELECT  TRANS_NBR,
        Base_Amount = SUM(Base_Amount),
        Code        = /*Your Logic Here */
  FROM  TABLE_GL
 GROUP BY TRANS_NBR
于 2012-07-03T19:29:57.507 回答
0

尝试这样的事情

select DTABLE.TRANS_MBR, DTABLE.SUM(BASE_AMOUNT) as DTABLE.SUM_BASE_AMOUNT, CODE
from (
    select TABLE_GL.TRANS_NBR, TABLE_GL.BASE_AMOUNT, TABLE_AP.CODE
    from TABLE_GL
    left join TABLE_AP on TABLE_AP.TRANS_NBR = TABLE_GL.TRANS_NBR
    union
    select TABLE_AP.TRANS_NBR, TABLE_AP.BASE_AMOUNT, TABLE_AP.CODE
    from TABLE_AP
) as DTABLE
group by TRANS_NBR
于 2012-07-03T19:47:33.403 回答