Oracle到Netezza Migration - Connect Prior ...在Netezza中以等效方式开始

时间:2015-04-20 03:40:09

标签: oracle netezza

有人可以帮助我获得Oracle 11g CONNECT PRIOR ... START WITH equivalent

Netezza中的SQL

以下SQL无法在Netezza中使用

CREATE TABLE Employees

(

  empid   int         NOT NULL,

  mgrid   int         NULL,

  empname varchar(25) NOT NULL,

  salary  DECIMAL(12,2)       NOT NULL

);


INSERT INTO Employees VALUES(1 , NULL, 'Nancy'   , 10000.00);

INSERT INTO Employees VALUES(2 , 1   , 'Andrew'  , 5000.00);

INSERT INTO Employees VALUES(3 , 1   , 'Janet'   , 5000.00);

INSERT INTO Employees VALUES(4 , 1   , 'Margaret', 5000.00) ;

INSERT INTO Employees VALUES(5 , 2   , 'Steven'  , 2500.00);

INSERT INTO Employees VALUES(6 , 2   , 'Michael' , 2500.00);

INSERT INTO Employees VALUES(7 , 3   , 'Robert'  , 2500.00);

INSERT INTO Employees VALUES(8 , 3   , 'Laura'   , 2500.00);

INSERT INTO Employees VALUES(9 , 3   , 'Ann'     , 2500.00);

INSERT INTO Employees VALUES(10, 4   , 'Ina'     , 2500.00);

INSERT INTO Employees VALUES(11, 7   , 'David'   , 2000.00);

INSERT INTO Employees VALUES(12, 7   , 'Ron'     , 2000.00);

INSERT INTO Employees VALUES(13, 7   , 'Dan'     , 2000.00);

INSERT INTO Employees VALUES(14, 11  , 'James'   , 1500.00);


  insert into employees values (17, 12, 'Sai11', 4500.00);

   insert into employees values (18, 12, 'SSV11', 4500.00);


  insert into employees values (19, 13, 'SB11', 4500.00);
  insert into employees values (20, 13, 'SB11', 4500.00);


WITH EmpCTE(empid, empname, mgrid, lvl)
AS
( 

  -- Anchor Member (AM)
  SELECT empid, empname, mgrid, 0
  FROM Employees
  WHERE empid = 7
  UNION ALL

  -- Recursive Member (RM)
  SELECT E.empid, E.empname, E.mgrid, M.lvl+1
  FROM Employees AS E
    JOIN EmpCTE AS M
      ON E.mgrid = M.empid
)
SELECT * FROM EmpCTE e order by e.empid  

1 个答案:

答案 0 :(得分:0)

我认为您要做的就是删除字段定义,而不是引用已建立的字段定义。

WITH EmpCTE AS ( 
  -- Anchor Member (AM)
  SELECT empid, empname, mgrid, 0
  FROM Employees
  WHERE empid = 7
), EmpCTERecursive as (
  select *
  from EmpCTE
  union all
  -- Recursive Member (RM)
  SELECT E.empid, E.empname, E.mgrid, M.lvl+1
  FROM Employees AS E
  JOIN EmpCTE AS M
  ON E.mgrid = M.empid
)
SELECT * FROM EmpCTERecursive e order by e.empid