表T(ID ,FID,SXH)
数据(1,0,1
2,0,2
3,1,1
4,1,2
5,1,3
6,2,1
7,2,2)
fid是ID的父ID,SXH是本ID在父ID下的顺序号
我想通过SQL语句得到
ID,SXH和其父ID的sxh(没有父ID的记录可以忽略或返回空,或零)
即 id ,fid,sxh,f_sxh
( 1,0,1,0
2,0,2,0
3,1,1,1
4,1,2,1
5,1,3,1
6,2,1,2
7,2,2,2)
数据(1,0,1
2,0,2
3,1,1
4,1,2
5,1,3
6,2,1
7,2,2)
fid是ID的父ID,SXH是本ID在父ID下的顺序号
我想通过SQL语句得到
ID,SXH和其父ID的sxh(没有父ID的记录可以忽略或返回空,或零)
即 id ,fid,sxh,f_sxh
( 1,0,1,0
2,0,2,0
3,1,1,1
4,1,2,1
5,1,3,1
6,2,1,2
7,2,2,2)
解决方案 »
- 这段PL/SQL为何报错?
- oracle自动保存sql解析文件,导致根目录空间满,服务起不来的情况。
- 求购:oracle书籍
- ORA-04031: unable to allocate 4200 bytes of shared memory
- oracle 可不可以设置某用户只能看某些表的满足特定条件的记录
- 如何给结果返回默认植?
- 如何把一个SQLSERVER的数据库转到ORACLE上,谢谢!
- 急!!数据库启动不了了!!!!
- database configuration assistant在客户端怎样配置才能建立数据库?
- 请问,在oracle中的统计值有什么用?
- 请教如何将朋友的DMP文件导入?
- delphi连接oracle时用system和sys以外的用户名和密码总是报错 怎么弄啊??
另外,f_sxh是什么含义呢?父亲在爷爷中的排位?select t1.id , t1.fid, t1.sxh, t2.sxh
from t t1, t t2
where t1.fid = t2.id这样行不?
比如记录4,1,2 其父ID 是1 ,1的顺序号为1结果应该为
4,1,2,1
我现在就想通过SQL语句得到这样的结果
比如记录4,1,2 其父ID 是1 ,1的顺序号为1结果应该为
4,1,2,1
我现在就想通过SQL语句得到这样的结果
with tmp as
(
select 1 id,0 fid,1 sxh from dual union all
select 2 id,0 fid,2 sxh from dual union all
select 3 id,1 fid,1 sxh from dual union all
select 4 id,1 fid,2 sxh from dual union all
select 5 id,1 fid,3 sxh from dual union all
select 6 id,2 fid,1 sxh from dual union all
select 7 id,2 fid,2 sxh from dual)
select mt.id, mt.fid, mt.sxh, nvl(st.sxh,0) f_sxh
from tmp mt, tmp st
where mt.fid = st.id(+)
order by mt.id; ID FID SXH F_SXH
---------- ---------- ---------- ----------
1 0 1 0
2 0 2 0
3 1 1 1
4 1 2 1
5 1 3 1
6 2 1 2
7 2 2 2