我正在尝试加入PL-SQL Developer中的表,但是尽管有明显的一对多关系,但输出只有三行,其中字段FED_ST_PRJ_NBR和QP_PROJECTNUMBER匹配。我做了一个正确的连接,以便SURFACING_HISTORY_REPORT中的所有数据都包含在输出中。这是我正在使用的SQL查询,非常简单:
create or replace view PROJECT_NUMBERS_GROUPED as
select t.FED_ST_PRJ_NBR,t.ROUTE_NBR,t.BEG_TERMINI,
t.END_TERMINI,t.LAT,t.LNGTD
from SITE_MANAGER t
group by t.FED_ST_PRJ_NBR,t.ROUTE_NBR,t.BEG_TERMINI,
t.END_TERMINI,t.LAT,t.LNGTD
order by t.FED_ST_PRJ_NBR
;
--create or replace view SITE_MANAGER_COMBINED AS
select distinct t.route_nbr,t.beg_termini,
t.end_termini,t.lat,t.lngtd,t.FED_ST_PRJ_NBR,s.*
from PROJECT_NUMBERS_GROUPED t right join SURFACING_HISTORY_REPORT s
on t.fed_st_prj_nbr = s.QP_PROJECTNUMBER
order by t.route_nbr
可以肯定的是,我通过在另一个表上创建了一个带有t.fed_st_prj_nbr的主键来检查t.fed_st_prj_nbr和s.QP_PROJECTNUMBER之间是否存在一对多的关系,并且它运行正常。以下是我尝试加入的两个数据集的各个部分。第一个是PROJECT_NUMBERS_GROUPED表的一部分。
FED_ST_PRJ_NBR ROUTE_NBR BEG_TERMINI END_TERMINI LAT LNGTD
AR 29148 LOCAL 0.1 472927 1112041
ARRA 0002(874) DIST WIDE 470636 1044251
ARRA 101-1(4)2 N-101 2.34 2.43 473129 1111724
ARRA 1028(4) U-1028 0.12 1.46 454754 1082627
ARRA 1031(11) U-1031 1.938 2.912 454544 1083703
ARRA 1031(9) U-1031 4.762 2.912 474405 1083703
ARRA 11-1(51)53 P-11 53.2 57.9 454005 1103302
ARRA 13-1(45)37 P-13 36.8 451141 1114044
ARRA 15(90) N-5 0.007 1.506 480933 1141816
ARRA 15(91) N-5 1.506 3.046 481033 1141924
ARRA 15(92) N-5 3.046 3.994 481124 1142001
ARRA 15-2(81)125 I-15 125.5 126.2 455930 1123254
ARRA 15-4(89)240 I-15 470514 1115740
ARRA 16(73) LOCAL 454032 1110107
ARRA 1806(8) U-1806 0.0 0.7 455958 1123141
ARRA 1810(4) U-1810 0.1 1.4 455957 1123004
ARRA 235-1(11)2 S-235 1.9 4.5 454346 1110711
ARRA 25(50) LOCAL 0.7 1.5 463616 1115559
ARRA 260-1(5)0 S-260 0.0 3.6 482442 1153432
ARRA 27-1(9)2 P-27 2.3 6.8 455434 1043208
,这是其他数据集的一部分(只是一些列和行):
QP_PROJECTNUMBER QP_PROJECTNAME QMI_NAME QMI_ITEMNUMBER
ARRA 101-1(4)2 SMELTER AVE & 10TH ST N-GREAT FALLS PLANT MIX GR D - COMMERCIAL TESTED 401020022
ARRA 101-1(4)2 SMELTER AVE & 10TH ST N-GREAT FALLS PLANT MIX GR D - COMMERCIAL TESTED 401020022
ARRA 1028(4) LOCKWOOD - SOUTHEAST PLANT MIX GR D - COMMERCIAL TESTED 401020022
ARRA 1028(4) LOCKWOOD - SOUTHEAST PLANT MIX GR D - COMMERCIAL TESTED 401020022
ARRA 1031(11) SHILOH ROAD CORRIDOR-BILLINGS PLANT MIX BIT SURF GR S - 19 MM 401080000
ARRA 1031(11) SHILOH ROAD CORRIDOR-BILLINGS PLANT MIX BIT SURF GR S - 19 MM 401080000
ARRA 1031(11) SHILOH ROAD CORRIDOR-BILLINGS PLANT MIX BIT SURF GR S - 19 MM 401080000
ARRA 11-1(51)53 LIVINGSTON - NE PLANT MIX BIT SURF GR S - 3/4 IN 401020045
ARRA 11-1(51)53 LIVINGSTON - NE PLANT MIX BIT SURF GR S - 3/4 IN 401020045
ARRA 11-1(51)53 LIVINGSTON - NE PLANT MIX BIT SURF GR S - 3/4 IN 401020045
ARRA 15(90) KBP - US 93 TO AIRPORT RD PLANT MIX BIT SURF GR S - 19 MM 401080000
ARRA 15(90) KBP - US 93 TO AIRPORT RD PLANT MIX GR D - COMMERCIAL TESTED 401020507
ARRA 15(90) KBP - US 93 TO AIRPORT RD PLANT MIX BIT SURF GR S - 19 MM 401080000
ARRA 15(90) KBP - US 93 TO AIRPORT RD PLANT MIX GR D - COMMERCIAL TESTED 401020507
ARRA 15(92) KBP - FOYS LAKE RD TO US 2 PLANT MIX GR D - COMMERCIAL TESTED 401020507
ARRA 15(92) KBP - FOYS LAKE RD TO US 2 PLANT MIX GR D - COMMERCIAL TESTED 401020507
ARRA 15(92) KBP - FOYS LAKE RD TO US 2 PLANT MIX BIT SURF GR S - 19 MM 401080000
1600多个行中的不止一行应该正确加入。这是数据类型问题吗?我也尝试过:
on t.fed_st_prj_nbr like s.QP_PROJECTNUMBER
并没有改变任何事情。怎么了?
答案 0 :(得分:1)
好像你可能在t.fed_st_prj_nbr
列中有尾随(和/或前导)空格。
尝试将连接条件更改为:
trim(t.fed_st_prj_nbr) = s.qp_projectnumber