table:
id int not null primary key,
f_id int default 0,
name varchar2(30) not null
怎么用一条Sql语句,顺序按f_id分组查出,语句:如: 1 0 科技
2 0 市场
3 2 市场一
4 1 科技一
5 1 科技二
我要的效果是:
1 0 科技
4 1 科技一
5 1 科技二
2 0 市场
3 2 市场一
id int not null primary key,
f_id int default 0,
name varchar2(30) not null
怎么用一条Sql语句,顺序按f_id分组查出,语句:如: 1 0 科技
2 0 市场
3 2 市场一
4 1 科技一
5 1 科技二
我要的效果是:
1 0 科技
4 1 科技一
5 1 科技二
2 0 市场
3 2 市场一
你的效果不是分组。也没有按f_id。
自相矛盾的问题。
0
1
1
0
2
这不是没有规律吗?
用order by name排序不知道符合不符合要求?
select id,prior id f_id
from table
connect by prior id = f_id
start with f_id = 0;暂时给出以上查询,回去查资料,明天给你一个答复
select * from table order by name,f_id;
一试便知!
from table
connect by prior id = f_id
start with f_id = 0;
order siblings by f_id,id