关键字遗失

时间:2019-04-09 06:19:32

标签: sql

我正在创建一个新表,但不断遇到错误,提示我缺少关键字。我想在脚本中包含的逻辑就像

如果ncB.out_fno = 13100,则返回ncB.out_fid。否则,与ncC.in_fid = ncB.out_fid上的表gc_nr_connect ncC左连接。如果ncC.out_fno = 1310-返回ncC.out_fid。

这似乎是一个循环,但我不知道该怎么做。

CREATE TABLE SGTEL10.FTP
AS (
select r.g3e_fid as riser_fid, cbl.g3e_fid as riser_cbl_fid, elem2.ownership as cbl_ownership, 
onu.g3e_fid as FTP_FID, 
CASE WHEN ncB.out_fno = 12100 then ncB.out_fid else ncC.in_fid = ncB.out_fid  
END FTP_FID
FROM gc_riser_temp r
JOIN gc_contain_temp cbl on cbl.g3e_ownerfid = r.g3e_fid AND r.ltt_id in (0,888888888)
JOIN gc_netelem_temp elem2 on elem2.g3e_fid = cbl.g3e_fid AND elem2.ltt_id in (0,888888888)
LEFT JOIN gc_nr_connect_temp ncA on ncA.g3e_fid = cbl.g3e_fid AND ncA.ltt_id in (0,888888888)
LEFT JOIN gc_nr_connect_temp ncB on ncB.in_fid = ncA.out_fid AND ncB.ltt_id in (0,888888888)
LEFT JOIN gc_nr_connect_temp ncC on ncC.in_fid = ncB.out_fid and ncC.ltt_id in (0,888888888) 
LEFT join gc_onu_temp onu on onu.g3e_fid = ncB.out_fid AND onu.ltt_id in (0,888888888));

1 个答案:

答案 0 :(得分:0)

您可以将其写为

select * into new_table from table

查询

select r.g3e_fid as riser_fid, cbl.g3e_fid as riser_cbl_fid, elem2.ownership as cbl_ownership, 
onu.g3e_fid as FTP_FID, 
CASE WHEN ncB.out_fno = 12100 then ncB.out_fid else ncC.in_fid = ncB.out_fid  
END FTP_FID
into  SGTEL10.FTP
FROM gc_riser_temp r
JOIN gc_contain_temp cbl on cbl.g3e_ownerfid = r.g3e_fid AND r.ltt_id in (0,888888888)
JOIN gc_netelem_temp elem2 on elem2.g3e_fid = cbl.g3e_fid AND elem2.ltt_id in (0,888888888)
LEFT JOIN gc_nr_connect_temp ncA on ncA.g3e_fid = cbl.g3e_fid AND ncA.ltt_id in (0,888888888)
LEFT JOIN gc_nr_connect_temp ncB on ncB.in_fid = ncA.out_fid AND ncB.ltt_id in (0,888888888)
LEFT JOIN gc_nr_connect_temp ncC on ncC.in_fid = ncB.out_fid and ncC.ltt_id in (0,888888888) 
LEFT join gc_onu_temp onu on onu.g3e_fid = ncB.out_fid AND onu.ltt_id in (0,888888888))