注册 登录
编程论坛 SQLite论坛

初学SQLite,遇到一个解决不了的问题,特求教各路高手

wmr19871105 发布于 2013-01-05 10:24, 5049 次点击
将原有的Oracle语句转化成普通的SQL来执行。sqlite中没有connect by prior   start with语句,请问我该怎么改?
select u.user_id, u.truename, u.name from user u,
(select t.group_id, t.group_name, t.group_parent from user_group t
connect by prior t.group_id=t.group_parent start with t.group_parent=(select group_id
from user where user_id=2 and rownum<=1)) t
where t.group_id=u.group_id and u.state<>3

求高手指教!
2 回复
#2
zb4275052013-01-28 09:06
。。。。。。
#3
3037709572013-08-29 16:08
利用mssql中的CTE可以这样来做:
;with cte as
(
   select ug.group_id, ug.group_name, ug.group_parent from user_group ug
   where ug.group_parent=
   (
      select group_id from user where user_id=2 and rownum<=1
   )
   union all
   select c.group_id, c.group_name, c.group_parent from cte c inner join user_group g
   on c.group_id=g.group_parent
)
select u.user_id, u.truename, u.name
from user u,(select * from cte) as t
where t.group_id=u.group_id and u.state<>3
1