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 に答える