从Redshift中的Connect by Prior开始

时间:2019-01-07 11:31:18

标签: sql amazon-redshift recursive-query

任何人都可以在下面帮助您进行转换的过程中,以ORACLE连接查询开始转换为Redshift查询。我相信Redshift无法启动。

SELECT DISTINCT 
   mrcompanyid || locationid location_lkp_id
   , (SELECT 
         t2.locationid
      FROM 
         dwh.dmn_me_location t2 
      START WITH t2.locationid = t1.locationid AND t2.mrcompanyid=t1.mrcompanyid
      CONNECT BY NOCYCLE PRIOR t2.locationparentid=t2.locationid
      GROUP BY T2.MRCOMPANYID,T2.LOCATIONID,T2.LOCATIONTYPE
      HAVING 
         LOCATIONTYPE='COUNTRY' AND 
         T2.MRCOMPANYID=T1.MRCOMPANYID
      ) location_country_id
FROM
   dwh.dmn_me_location t1

0 个答案:

没有答案