易截截图软件、单文件、免安装、纯绿色、仅160KB

SQL查询问题(oracle) - Oracle / 开发

如下2张表:
table1:
node_id
parent_id
root_id
value

table2:
node_id
status

表1存储了一棵树,表2存储了节点状态,问题如下:

如何用SQL语句获得状态status为1的节点的所有子节点以及其下子树中所有节点的value?

求解。由于客观因素只能用sql实现,不然就递归了。。。多谢大家

select a.node_id,a.value
from table1 a,table2 b
where a.node_id=b.node_id
start with b.status=1
connect by prior a.node_id=a.parent_id

UP,这个需要用到 start...wiht connect by 语法,层次查询。
引用
select a.node_id,a.value
from table1 a,table2 b
where a.node_id=b.node_id
start with b.status=1
connect by prior a.node_id=a.parent_id


引用
select a.node_id,a.value
from table1 a,table2 b
where a.node_id=b.node_id
start with b.status=1
connect by prior a.node_id=a.parent_id


多谢回复!不过报 sql command not properly ended 错误,试了很多顺序还是不行,望解答,谢谢了

SQL code:

create table tb(id int,pid int);
insert into tb select 1,0 from dual;
insert into tb select 2,0 from dual;
insert into tb select 3,1 from dual;
insert into tb select 4,1 from dual;
insert into tb select 5,3 from dual;
create table tc(id int,statu


相关问答:

csv文件转换成sql导入到数据库,没有数据为何?

执行的顺序:
1)文件浏览框(选择文件使用)
选择好文件后
点击一个导入按钮的时候 ,把上面上传框里的csv文件以一个ID为文件名,上传到**/**文件夹下
2)读取这个文件夹下的csv的文件,转换成sql
3 ......

求一SQL - MS-SQL Server / 基础类

表如下
教室ID 座位数 开始时间 结束时间 2009年1月1日 2009年1月2日 2009年1月3日
  101 50 08:00 08:30 30 40 50  
  101 50 09:00 ......

求一sql【谢谢】 - MS-SQL Server / 基础类

需求如下:
a表:
 p_id status  
  1 0
  2 0
b表
rec_id pid purchase_qty receive_qty flag
1 1 10 10 0
2 ......

linux下C语言开发oracle的问题。

两个文件1.PC,1.inc
1.PC有操作oracle数据库的 ,1.inc也有操作oracle数据库 
在其他数据中如informix 中$include 1.inc就可以使用了
在ORACLE数据库重 $include 1.inc不可用 EXEC SQL include 1.inc也不可 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号