SQL 连接多行
是否可以为表中的许多行生成“连接方式”并对它们进行求和。 我有一张桌子
person boss
---------------
person1 NULL
person2 person1
person3 person2
,我想要得到一张桌子,
boss is_boss_of
---------------
person1 person2
person1 person3
person2 person3
我想通过表达式为桌子上的每个人建立连接? 有什么办法可以做到吗?
说到总和,我想到了这样的事情
SELECT CONNECT_BY_ROOT person as boss, person as is_boss_of
FROM table1
START WITH boss = person1
CONNECT BY PRIOR Empno = Mgr;
Union
SELECT CONNECT_BY_ROOT person as boss, person as is_boss_of
FROM table1
START WITH boss = person2
CONNECT BY PRIOR Empno = Mgr;
Union
...
and so on
Is it possible to generate "connect by" for many rows in table and sum them all.
I have a table
person boss
---------------
person1 NULL
person2 person1
person3 person2
And i want to get table
boss is_boss_of
---------------
person1 person2
person1 person3
person2 person3
I would like to make connect by expression for everyone in table person-boss?
Is there any way to make it?
Saying about sum i thought about something like this
SELECT CONNECT_BY_ROOT person as boss, person as is_boss_of
FROM table1
START WITH boss = person1
CONNECT BY PRIOR Empno = Mgr;
Union
SELECT CONNECT_BY_ROOT person as boss, person as is_boss_of
FROM table1
START WITH boss = person2
CONNECT BY PRIOR Empno = Mgr;
Union
...
and so on
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新
看到更新后,您只需删除“开始”即可。
结束更新
CONNECT_BY_ROOT< /a> 是您要查找的内容
此语句
输出
添加 SUMS 和 GROUPS 非常简单
Update
After seeing your update, you just need to drop the START WITH.
End update
CONNECT_BY_ROOT is what you're looking for
This statement
Outputs
Adding SUMS and GROUPS is pretty easy