使用内连接在php查询上连接sql

时间:2013-11-25 21:19:56

标签: php mysql join

我想将表连接为和值,因此我可以通过每个nip_ar获得总和值

我有这个查询,我认为这是对的,但我的结果错误

SELECT nip_ar,nama_ar,sum(JUMLAH) as JUMELAH
from assign
inner join (
    select concat(npwp,kpp,cab) as ident,npwp,sum(jumlah_bayar) as JUMLAH
    from mpnruteng
    WHERE substr(tgl_bayar,1,4)='2013'
    group by ident
 ) as mpn ON concat(assign.npwp,assign.kpp,assign.cab)=mpn.ident
 group by nip_ar;

我会像这样分割查询

SELECT nip_ar,nama_ar,sum(JUMLAH) as JUMELAH from assign inner join

(select concat(npwp,kpp,cab) as ident,npwp,sum(jumlah_bayar) as JUMLAH from mpnruteng WHERE substr(tgl_bayar,1,4)='2013' group by ident) as mpn `

ON concat(assign.npwp,assign.kpp,assign.cab)=mpn.ident group by nip_ar;

任何人都可以看到问题吗?请帮我解决。

这是数据库结构

表格分配

 id | npwp | kpp | cab | nip_ar | nama_ar

table mpn

no | npwp | kpp | cab | nama | kode_map | kode_bayar | masa_pajak |
sk_ssp | tgl_bayar | jumlah_bayar | ntpn | bank | no_spm | idbilling |
jenis |

0 个答案:

没有答案