0

我有这个查询,我想将它放入“现代连接语法”中

SELECT  
    t.acct_order, 
    c1.acct_desc, 
    c1.position, 
    c1.end_pos,
    Budget = sum(((g.data_set-1)/2)*(g.debits - g.credits)),
    Actual = sum(((g.data_set-3)/-2)*(g.debits - g.credits)) 

FROM    
    glm_chart c1, 
    glm_chart c2, 
    glh_deptsum g, 
    #TEMPTABLE t

WHERE   
        g.acct_uno=c2.acct_uno  
    and c1.acct_code = t.acct_code  
    and c2.position between c1.position and c1.end_pos  
    and g.debits-g.credits<>0 
    and c1.book=1  
    and g.data_set in (1, 3)  
    and (g.period between 201201 and 201212) 

GROUP   by  t.acct_order, 
            c1.acct_desc, 
            c1.position,
            c1.end_pos 

ORDER   by  t.acct_order 

这就是我要做的,但正如你所看到的,我似乎无法识别表 glh_deptsum (g) 到 C1 或 T 的连接

SELECT  
    t.acct_order, 
    c1.acct_desc, 
    c1.position, 
    c1.end_pos,
    sum(((g.data_set-1)/2)*(g.debits - g.credits))  AS Budget,
    sum(((g.data_set-3)/-2)*(g.debits - g.credits)) AS Actual, 


FROM         #TEMPTABLE T
INNER JOIN  glm_chart c1 ON c1.acct_code = t.acct_code
INNER JOIN  glh_deptsum g <---- HELP WHAT GOES HERE ---------
INNER JOIN  glm_chart c2 ON c2.position between c1.position and c1.end_pos AND g.acct_uno=c2.acct_uno


WHERE   
    g.debits - g.credits <> 0 
    AND c1.book=1  
    AND g.data_set in (1, 3) 
    AND (g.period between 201201 and 201212) 

GROUP BY t.acct_order, 
            c1.acct_desc, c1.position,c1.end_pos 

ORDER BY t.acct_order 

谁能让我知道我做错了什么?

4

1 回答 1

2

看起来应该是这样的:

SELECT t.acct_order, 
    c1.acct_desc, 
    c1.position, 
    c1.end_pos,
    Budget = sum(((g.data_set-1)/2)*(g.debits - g.credits)),
    Actual = sum(((g.data_set-3)/-2)*(g.debits - g.credits)) 
FROM #TEMPTABLE t
INNER JOIN glm_chart c1
  ON t.acct_code = c1.acct_code
INNER JOIN glm_chart c2
  ON c2.position between c1.position and c1.end_pos  
INNER JOIN glh_deptsum g
  ON c2.acct_uno = g.acct_uno
WHERE g.debits-g.credits<>0 
    and c1.book=1  
    and g.data_set in (1, 3)  
    and (g.period between 201201 and 201212) 
GROUP by  t.acct_order, 
            c1.acct_desc, 
            c1.position,
            c1.end_pos 
ORDER   by  t.acct_order 
于 2012-10-02T23:56:59.613 回答