2017-06-19 62 views
0

我想將此表 enter image description here 的jumlah_pinjaman的總和,這表jumlah_simpanan通過此表的no_anggota enter image description here 組總和enter image description here 我想這個查詢:顯示2總和不加入

SELECT anggota_2,anggota_1,jumlah_pinjaman,jumlah_simpanan從 (SELECT no_anggota如anggota_1,總和(jumlah_pinjaman)從由no_anggota貸款組jumlah_pinjaman)爲A, (SELECT no_anggota如anggota_2,總和(jumlah_simpanan)作爲jumlah_simpanan從data_simpanan組由no_anggot一)爲B組 通過anggota_1

,但它造成的:enter image description here

的jumlah_simpanan欄不是我想要 請幫助:)

+2

你想要什麼結果呢?在這裏分享您的樣本數據和預期的輸出在適當的文本。圖片是在這裏分享信息的非常糟糕的方式。我們無法將圖像中的數據複製到測試查詢。 –

+0

因爲它涉及三個表,你需要加入表。但是既然你沒有提供關於表格關係的任何信息,我就沒有辦法做。 – Eric

+0

爲什麼你不希望使用一個連接? – John

回答

1

請嘗試以下查詢結果:

select a.no_anggota, 
(select sum(p.jumlah_pinjaman) from pinjaman p where p.no_anggota = a.no_anggota) as sum_jumlah_pinjaman, 
(select sum(d.jumlah_simpanan) from data_simpanan d where d.no_anggota = a.no_anggota) as sum_jumlah_simpanan 
from anggota a 
group by a.no_anggota; 
+0

在這種情況下加入這正是我想要的結果。謝謝主席先生 –

+0

@MochamadRamdannyLukman:請你請我的答案是正確的回答你的問題。 –