我试图转换使用connect_by_root并通过之前连接的查询来消除先前的连接。原始查询是
SELECT distinct CONNECT_BY_ROOT user.userid AS userid ,
CONNECT_BY_ROOT user.username USERNAME,
gr.BALANCE,
client.agentid ,
gr.closedt
FROM user
LEFT JOIN GAMEGROUP gr ON (gr.userid= user.userid)
WHERE gr.closedt>= to_date('1/2/2014 0:0','DD/MM/YYYY HH24:MI') and gr.closedt<= to_date('10/2/2014 23:59','DD/MM/YYYY HH24:MI')
START WITH user.agentid IS NULL CONNECT BY PRIOR user.userid=user.agentid ;
我已将查询转换为
WITH r (USERID, USERNAME, BALANCE, AGENTID, PARTITIONDATE) AS
(SELECT distinct CONNECT_BY_ROOT user.userid AS userid,
CONNECT_BY_ROOT user.username USERNAME,
gr.BALANCE,
user.agentid ,
gr.closedt
FROM client
LEFT JOIN GAMEGROUP gr ON (gr.userid= user.userid)
WHERE gr.closedt>= to_date('1/2/2014 0:0','DD/MM/YYYY HH24:MI') and gr.closedt<= to_date('10/2/2014 23:59','DD/MM/YYYY HH24:MI')
UNION ALL
SELECT distinct CONNECT_BY_ROOT cl.userid AS userid,
CONNECT_BY_ROOT cl.username USERNAME,
g.BALANCE,
cl.agentid ,
g.closedt
FROM r, user cl
LEFT JOIN BACKOFFICE.GAMEGROUP g ON (g.userid= cl.userid)
WHERE g.closedt>= to_date('1/2/2014 0:0','DD/MM/YYYY HH24:MI') and g.closedt<= to_date('10/2/2014 23:59','DD/MM/YYYY HH24:MI') AND r.userid=cl.agentId)
SELECT * FROM r;
我收到此查询块中所需的错误ORA-01788 CONNECT BY子句。有人在我的新查询中看到问题吗?