下面的以下 sql 查询产生了这个结果
cust table
CUST_ID AC_NO NAME AREA SALES
---------- ---------- ------------------------- ---
C001 A30045 Smiths Heavy 1 R001
C002 A30145 Heavy jonps 1 R001
C003 A30046 dangote flour 1 R002
C004 A30047 OAU ife 2 R002
Area Table
AREA_NUMBER AREA_NM AREA_Dp
----------- ---------- ----------
1 North Leeds
2 South Newcastle
3 East Surrey
4 West London
Area_geo Table
SALE REPP_ AREAA_ID AREAM AREAMANAGER_NAME
---- ----- ---------- ----- -------------------
SG01 R001 1 R110 mandy Jay
SG02 R002 2 R110 mandy Jay
SG03 R003 3 R111 Kay sole
SG04 R003 3 R111 Kay sole
SG05 R003 3 R111 Kay sole
SG06 R001 4 R110 mandy Jay
select cust.*,
area.AREA_Nm,area.AREA_Dp
from area inner join cust on
area.area_number=customer.area
ORDER BY customer.Cust_ID;
结果
CUST_ID AC_NO NAME ADDRESS AREA SALES AREA_N AREA_Dp
---------- ---------- -------------- ------------------------- ---------- ----- ---
Ac003 A30046 dangote flour court Estate 1 R002 North Leeds
Ac004 A30047 OAU ife 4 Abanishe 2 R002 South Newcastle
我的意图是进一步将 Areamanager_name 包含在下表中的上述结果中。然而,下表对上述结果 (Area) 有一个共同的属性 (Area_ID)
表区_地理
SALE REPP_ AREA_ID AREAM AREAMANAGER_NAME
---- ----- ---------- ----- ----------------
SG01 R001 1 R110 mandy Jay
SG02 R002 2 R110 mandy Jay
SG03 R003 3 R111 Kay sole
SG04 R003 3 R111 Kay sole
SG05 R003 3 R111 Kay sole
SG06 R001 4 R110 mandy Jay
预期结果
CUST_ID AC_NO NAME ADDRESS AREA SALES AREA_N AREA_dp Areamanager
---------- ---------- -------------- ------------------------- ---------- ----- ---
Ac003 A30046 dangote flour court Estate 1 R002 North Leeds mandy Jay
Ac004 A30047 OAU ife 4 Abanishe 2 R002 South Newcastle mandy Jay