我有 3 个关系表
1. 表权限(从用户名获取用户权限)
select branch_code,username from privilege where username='joko';
结果:
| branch_code | username |
|--------------|----------|
| 'IDJK003MPV' | 'joko' |
| 'IDJK001MAG' | 'joko' |
| 'IDJK002MCL' | 'joko' |
| 'IDBTNCTR' | 'joko' |
2. 表 biodata_karyawan(这个表关于员工的 branch_code)
select branch_code,status_karyawan from biodata_karyawan;
结果:
| branch_code | status_karyawan |
|--------------|-----------------|
| 'IDJB001BEC' | 'Aktif' |
| 'IDJB001BEC' | 'Aktif' |
| 'IDPA001PPA' | 'Aktif' |
| 'IDJK001MAG' | 'Aktif' |
| 'IDJB001BEC' | 'Aktif' |
| 'IDJB001BEC' | 'Tidak Aktif' |
| 'IDBTNCTR' | 'Tidak Aktif' |
3.表分支
select branch_code,branch_name from branch;
结果 :
| branch_code | branch_name |
|--------------|--------------------------|
| 'IDJB001BEC' | 'BEC BANDUNG' |
| 'IDJK001MAG' | 'MALL ARTHA GADING' |
| 'IDJK001HO' | 'HEAD OFFICE' |
| 'IDPA001PPA' | 'MALL MATAHARI JAYAPURA' |
| 'IDBE001BGK' | 'BENCOOLEN INDAH MALL' |
| 'IDJK002MPB' | 'METRO PASAR BARU' |
我希望结果会是这样的家伙:(记录只是样本)
| branch_code | branch_name | count |
|--------------|----------------|-------|
| 'IDJB001BEC' | 'MALL BANDUNG' | '5' |
| 'IDJK001MLP' | 'MALL LIPPO' | '2' |
| 'IDJK002MPI' | 'MALL PURI' | '0' |
| 'IDJB002ZZZ' | 'MALL POSO' | '0' |
谁能帮助我?
谢谢你的时间。