我有,我想加入4表:外連接多臺
tbl_transaksi_header
--------------------
kode_transaksi
kode_user
nama_penerima
email_penerima
alamat_penerima
bank
telpon
tbl_konfirmasi
--------------------
id
kode
member
namarekening
tbl_user
-------------------
kode_user
username_user
tbl_transaksi_detail
---------------------
kode_transaksi
harga
jumlah
status
我想告訴所有的數據,包括nama_rek NULL。
我嘗試這樣做:
SELECT t.status, t.kode_transaksi kode, u.username_user nama_user, t.nama_penerima penerima, t.telpon, t.bank, sum(d.harga*d.jumlah) total,k.namarekening nama_rek
FROM tbl_transaksi_header t
JOIN tbl_user u
ON t.kode_user=u.kode_user
JOIN tbl_transaksi_detail d
ON t.kode_transaksi=d.kode_transaksi
LEFT OUTER JOIN tbl_konfirmasi k
ON t.kode_transaksi=k.kode
做工精細,但沒有顯示空的結果,只顯示1分的結果。我想是這樣的:
status kode nama_user penerima telpn bank total nama_rek
xxx xxx xxx xxx xxx xxx xxx NULL
xxx xxx xxx xxx xxx xxx xxx NULL
xxx xxx xxx xxx xxx xxx xxx yyy
xxx xxx xxx xxx xxx xxx xxx NULL
的樣本數據:
kode_transaksi kode_user nama_penerima email_penerima alamat_penerima bank telpon
kd1 1 john [email protected] florida Bank A 088833221
kd2 2 elsa [email protected] uk Bank B 088833222
kd3 1 roy [email protected] manhattan Bank C 088833223
id kode member namarekening
1 kd1 paul paul
kode_user username_user
1 paul
2 elena
kode_transaksi harga jumlah status
kd1 10 2 process
kd1 5 2 process
kd1 5 1 process
kd2 4 3 pending
kd2 3 4 pending
kd3 2 3 pending
我想這樣的輸出:
status kode nama_user penerima telpon bank total nama_rek
process kd1 paul john 088833221 Bank A 35 paul
pending kd2 elena elsa 088833222 Bank B 24 NULL
pending kd2 elena roy 088833223 Bank C 6 NULL
你使用的是mysql,mssql,...? – pbaldauf 2014-12-07 14:44:04
如果你會顯示一些示例源數據,這將有所幫助。 – Joe 2014-12-07 14:45:43
@pbaldauf是mysql – john 2014-12-07 14:47:43