CREATE OR REPLACE VIEW EVW_SSHIPINFO_TEST AS
SELECT distinct S.PKID,
S.RATEID,
S.FCODE,
S.FDESCR,
S.FVAULE,
S.FTYPE,
S.RECK,
S.ZZD,
S.CC,
S.FKDW,
S.FKDWFI,
S.INOUT,
S.PLANSTATU,
S.SHIPCOM,
S.COMPANYID,
S.CODE_COMPANY,
S.CODECREATOR,
S.DATEOFCREATE,
S.ISAUDIT,
S.ISFORBIDDEN,
S.FNT,
S.FNTNAME,
S.ZEROTAX,
--S.REMARK,
nvl(DS.CHI_VESSEL,C.CHI_VESSEL) CHI_VESSEL,
DECODE(DS.ENG_VESSEL,NULL,C.ENG_VESSEL,DS.ENG_VESSEL) ENG_VESSEL,
DECODE(DS.SIGN,NULL,C.SIGN,DS.SIGN) SIGN,
DECODE(DS.GUOJI,NULL,C.GUOJI,DS.GUOJI) GUOJI,
DS.CLX,
DS.TON_GROS,
DS.TON_NET,
DECODE(DS.TON_DEAD,NULL,C.TON_DEAD,DS.TON_DEAD) TON_DEAD,
DECODE(DS.LOA,NULL,C.LOA,DS.LOA) LOA,
nvl(to_char(DS.LBS_ID),c.ship_id) LBS_ID,
DS.V_ID,
DS.VOYAGE_NATURE,
DS.I_VOYAGE,
DS.O_VOYAGE,
decode(DS.ETA_ARRIVER_TIME,null,nvl(c.yjjg,c.yjlg)) ETA_ARRIVER_TIME,
DS.ETA_ARRIVER_TIME AS BERTH_TIME,
DECODE(DS.BERTHNO,NULL,C.DQBW,DS.BERTHNO) BERTHNO,
DS.BERTH_POSITION,
DS.SAILING_TIME,
DS.LAST_PORT,
DS.NEXT_PORT,
DS.SHIP_STATU,
DS.THIS_DRAFT,
DS.CHU_DRAFT,
DS.AGENT AGENTID,
DS.S_DECLARE,
DS.REMARK,
DECODE(DS.PILOTAGE,2,1,3,1,DS.PILOTAGE) PILOTAGE, --引水标志:0需要,1不需要
DS.TRANSIT_ITEM,
--DS.S_TRADE, -- 1内贸' 2外贸' 3 内支线
decode(nvl(I.DATANAME,C.Tradename),'内贸','1','外贸','2','外贸内支线','3') S_TRADE,
DS.QSBZ,
DS.NAME AGENTNAME,
DS.DESCRIPT AGENTFULLNAME,
nvl(I.DATANAME,C.Tradename) TRADENAME,
DECODE(DS.THIS_DRAFT, 0, NULL, DS.THIS_DRAFT) || ' / ' ||
DECODE(DS.CHU_DRAFT, 0, NULL, DS.CHU_DRAFT) THISDRAFT
FROM CVW_SHIPRATE S LEFT JOIN DVW_SHIPVESSEL DS
ON S.LBS_ID = DS.LBS_ID LEFT JOIN IVW_TRADEF I
ON DS.S_TRADE = I.PKID left join T_E_SCHEDULEORDER C
on C.SHIP_ID = S.M_ID
这样一个视图,中间部分其实都不太重要,重点是最后一句:left join T_E_SCHEDULEORDER C
on C.SHIP_ID = S.M_ID
C表中和m_id对应的数据可能有多条,导致出现了重复数据,现在想要选取对应数据的第一条,应该如何改写?
我用left join T_E_SCHEDULEORDER C on C.SHIP_ID = S.M_ID and rownum =1没有作用
2 个解决方案
#1
先对C表进行预处理,然后再关联;
把C表替换为下面这个试试:
把C表替换为下面这个试试:
Select *
From (Select c.*,
(Row_Number() Over(Partition By c.Ship_Id Order By c.Ship_Id)) Rn
From t_e_Scheduleorder c)
Where Rn = 1;
#2
谢谢,亲测这种方法可以!
#1
先对C表进行预处理,然后再关联;
把C表替换为下面这个试试:
把C表替换为下面这个试试:
Select *
From (Select c.*,
(Row_Number() Over(Partition By c.Ship_Id Order By c.Ship_Id)) Rn
From t_e_Scheduleorder c)
Where Rn = 1;
#2
谢谢,亲测这种方法可以!