将外连接从Sybase转换为My Sql

时间:2015-06-18 16:46:00

标签: mysql sql sybase

有人可以帮我把这个连接转换成我的sql ..

SELECT DISTINCT 
    b.gl_acct_type + '0', 
    b.gl_id, 
    b.fd_id, 
    b.gl_sub, 
    b.gl_tran,
    b.gl_entry_type,
    IsNull(b1.gl_amount,0),
    IsNull(b2.gl_amount,0),
    IsNull(b3.gl_amount,0),
    IsNull(b4.gl_amount,0), 
    IsNull(b1.gl_debit,0),
    IsNull(b2.gl_debit,0),
    IsNull(b3.gl_debit,0),
    IsNull(b4.gl_debit,0), 
    IsNull(b1.gl_credit,0),
    IsNull(b2.gl_credit,0),
    isNull(b3.gl_credit,0),
    IsNull(b4.gl_credit,0),
    b.detail_yn  
FROM 
    zz_cfs_bal_1 b, 
    zz_cfs_bal_2 b1, 
    zz_cfs_bal_2 b2, 
    zz_cfs_bal_2 b3, 
    zz_cfs_bal_2 b4
WHERE 
    b.gl_acct_type IN ('1', '2', '3') AND
    b.gl_id *= b1.gl_id AND 
    b.fd_id *= b1.fd_id AND 
    b.gl_entry_type *= b1.gl_entry_type AND 
    b1.line_type=1 AND
    b.gl_sub *= b1.gl_sub AND
    b.gl_id *= b2.gl_id AND
    b.fd_id *= b2.fd_id AND
    b.gl_entry_type *= b2.gl_entry_type AND
    b2.line_type=2 AND 
    b.gl_sub *= b2.gl_sub AND  
    b.gl_id *= b3.gl_id AND 
    b.fd_id *= b3.fd_id AND 
    b.gl_entry_type *= b3.gl_entry_type AND 
    b3.line_type=3 AND 
    b.gl_sub *= b3.gl_sub AND  
    b.gl_id *= b4.gl_id AND
    b.fd_id *= b4.fd_id AND
    b.gl_entry_type *= b4.gl_entry_type AND
    b4.line_type=4 AND 
    b.gl_sub *= b4.gl_sub 

提前致谢

2 个答案:

答案 0 :(得分:0)

SELECT DISTINCT b.gl_acct_type + '0',
                b.gl_id,
                b.fd_id,
                b.gl_sub,
                b.gl_tran,
                b.gl_entry_type,
                IFNULL(b1.gl_amount,0),
                IFNULL(b2.gl_amount,0),
                IFNULL(b3.gl_amount,0),
                IFNULL(b4.gl_amount,0),
                IFNULL(b1.gl_debit,0),
                IFNULL(b2.gl_debit,0),
                IFNULL(b3.gl_debit,0),
                IFNULL(b4.gl_debit,0),
                IFNULL(b1.gl_credit,0),
                IFNULL(b2.gl_credit,0),
                IFNULL(b3.gl_credit,0),
                IFNULL(b4.gl_credit,0),
                b.detail_yn
FROM zz_cfs_bal_1 b,
     zz_cfs_bal_2 b1,
     zz_cfs_bal_2 b2,
     zz_cfs_bal_2 b3,
     zz_cfs_bal_2 b4
WHERE b.gl_acct_type IN ('1',
                         '2',
                         '3')
  AND b.gl_id *= b1.gl_id
  AND b.fd_id *= b1.fd_id
  AND b.gl_entry_type *= b1.gl_entry_type
  AND b1.line_type=1
  AND b.gl_sub *= b1.gl_sub
  AND b.gl_id *= b2.gl_id
  AND b.fd_id *= b2.fd_id
  AND b.gl_entry_type *= b2.gl_entry_type
  AND b2.line_type=2
  AND b.gl_sub *= b2.gl_sub
  AND b.gl_id *= b3.gl_id
  AND b.fd_id *= b3.fd_id
  AND b.gl_entry_type *= b3.gl_entry_type
  AND b3.line_type=3
  AND b.gl_sub *= b3.gl_sub
  AND b.gl_id *= b4.gl_id
  AND b.fd_id *= b4.fd_id
  AND b.gl_entry_type *= b4.gl_entry_type
  AND b4.line_type=4
  AND b.gl_sub *= b4.gl_sub

答案 1 :(得分:0)

在这里,你应该摆脱旧的ansii风格连接。

SELECT DISTINCT 
    b.gl_acct_type + '0', 
    b.gl_id, 
    b.fd_id, 
    b.gl_sub, 
    b.gl_tran,
    b.gl_entry_type,
    IsNull(b1.gl_amount,0),
    IsNull(b2.gl_amount,0),
    IsNull(b3.gl_amount,0),
    IsNull(b4.gl_amount,0), 
    IsNull(b1.gl_debit,0),
    IsNull(b2.gl_debit,0),
    IsNull(b3.gl_debit,0),
    IsNull(b4.gl_debit,0), 
    IsNull(b1.gl_credit,0),
    IsNull(b2.gl_credit,0),
    isNull(b3.gl_credit,0),
    IsNull(b4.gl_credit,0),
    b.detail_yn  
FROM 
    zz_cfs_bal_1 b
    left join zz_cfs_bal_2 b1 on b.gl_id = b1.gl_id and b.fd_id = b1.fd_id and b.gl_entry_type = b1.gl_entry_type and b.gl_sub = b1.gl_sub
    left join zz_cfs_bal_2 b2 on b.gl_id = b2.gl_id and b.fd_id = b2.fd_id and b.gl_entry_type = b2.gl_entry_type and b.gl_sub = b2.gl_sub
    left join zz_cfs_bal_2 b3 on b.gl_id = b3.gl_id and b.fd_id = b3.fd_id AND b.gl_entry_type = b3.gl_entry_type and b.gl_sub = b3.gl_sub
    left join zz_cfs_bal_2 b4 on b.gl_id = b4.gl_id and b.fd_id = b4.fd_id and b.gl_entry_type = b4.gl_entry_type and b.gl_sub = b4.gl_sub
WHERE 
    b.gl_acct_type IN ('1', '2', '3') AND
    b1.line_type=1 AND
    b2.line_type=2 AND 
    b3.line_type=3 AND
    b4.line_type=4