树形结构SQL

sweat89 2012-04-10 09:29:00

A表:
org_id org_name p_id


B表:
org_id user_id


C表:
user_id user_name


D表:
user_id user_pic state

分别根据user_name,org_name, state,三个字段查找user_name,user_pic,org_name结果集
...全文
235 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
sweat89 2012-04-11
  • 打赏
  • 举报
回复
自己UP
ICE-word 2012-04-10
  • 打赏
  • 举报
回复
继续求子节点的话!加上子节点的字段不就可以了?
fangkaifang 2012-04-10
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 的回复:]
还是不行额
[/Quote]

310645611 方凯 加我。。
sweat89 2012-04-10
  • 打赏
  • 举报
回复
还是不行额
fangkaifang 2012-04-10
  • 打赏
  • 举报
回复
select c.user_name,d.user_pic,a.org_name from A a ,B b,C c,D d where a.org_id =b.org_id and b.user_id

=c.user_id and c.user_id = d.user_id and and a.org_name like ‘%a%’

fangkaifang 2012-04-10
  • 打赏
  • 举报
回复
select c.user_name,d.user_pic,a.org_name from A a ,B b,C c,D d where a.org_id =b.org_id and b.user_id

=c.user_id and c.user_id = d.user_id and b.user_id = d.user_id
and c.user_name =? and a.org_name = ?
and d.state =?


这个你试试看
sweat89 2012-04-10
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

引用 6 楼 的回复:
引用 5 楼 的回复:

引用 4 楼 的回复:
引用 3 楼 的回复:

引用 2 楼 的回复:
引用 1 楼 的回复:

select c.user_name,d.user_pic,a.org_name from A a ,B b,C c,D d where a.org_id =b.org_id and b.user_id

=c.user_i……
[/Quote]
A表:
org_id org_name p_id
1 a 0
2 a1 1
3 a2 1

这样,查找org_name为a,要把下面子节点(a1,a2)的都展示出来
fangkaifang 2012-04-10
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]
引用 5 楼 的回复:

引用 4 楼 的回复:
引用 3 楼 的回复:

引用 2 楼 的回复:
引用 1 楼 的回复:

select c.user_name,d.user_pic,a.org_name from A a ,B b,C c,D d where a.org_id =b.org_id and b.user_id

=c.user_id and c.user_id……
[/Quote]

子节点是哪张表?
sweat89 2012-04-10
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]

引用 4 楼 的回复:
引用 3 楼 的回复:

引用 2 楼 的回复:
引用 1 楼 的回复:

select c.user_name,d.user_pic,a.org_name from A a ,B b,C c,D d where a.org_id =b.org_id and b.user_id

=c.user_id and c.user_id = d.user_id ……
[/Quote]
哥们,貌似有问题啊。根据org_name,查询不到子节点的值···
fangkaifang 2012-04-10
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]
引用 3 楼 的回复:

引用 2 楼 的回复:
引用 1 楼 的回复:

select c.user_name,d.user_pic,a.org_name from A a ,B b,C c,D d where a.org_id =b.org_id and b.user_id

=c.user_id and c.user_id = d.user_id and c.user_name……
[/Quote]

结贴给分吧
sweat89 2012-04-10
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

引用 2 楼 的回复:
引用 1 楼 的回复:

select c.user_name,d.user_pic,a.org_name from A a ,B b,C c,D d where a.org_id =b.org_id and b.user_id

=c.user_id and c.user_id = d.user_id and c.user_name =? and a.org……
[/Quote]
呵呵,原来这样就行了啊,我一直在考虑start wiht, CONNECT BY PRIOR,原来现在加了个中间表,容易多了,谢谢指导了
fangkaifang 2012-04-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
引用 1 楼 的回复:

select c.user_name,d.user_pic,a.org_name from A a ,B b,C c,D d where a.org_id =b.org_id and b.user_id

=c.user_id and c.user_id = d.user_id and c.user_name =? and a.org_name = ?
and ……
[/Quote]


只要那个关联没错的话 你可以一个一个得到结果集的啊
sweat89 2012-04-10
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

select c.user_name,d.user_pic,a.org_name from A a ,B b,C c,D d where a.org_id =b.org_id and b.user_id

=c.user_id and c.user_id = d.user_id and c.user_name =? and a.org_name = ?
and d.state =?
……
[/Quote]
不好意思,可能是我之前没说明白题意。
分别根据user_name,org_name, state,也就是三个SQL语句

1.根据user_name查询user_name,user_pic,org_name结果集
2.根据org_name查询user_name,user_pic,org_name结果集
3.根据state查询user_name,user_pic,org_name结果集
fangkaifang 2012-04-10
  • 打赏
  • 举报
回复
select c.user_name,d.user_pic,a.org_name from A a ,B b,C c,D d where a.org_id =b.org_id and b.user_id

=c.user_id and c.user_id = d.user_id and c.user_name =? and a.org_name = ?
and d.state =?

试试看。。。
sweat89 2012-04-10
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 的回复:]

oracle树形结构查询可以用
CONNECT BY PRIOR
START WITH语法
[/Quote]
兄弟,有时间帮我写下么
我是睡 2012-04-10
  • 打赏
  • 举报
回复
oracle树形结构查询可以用
CONNECT BY PRIOR
START WITH语法

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧