如何为我想在java中调用的mysql查询创建存储过程

djmepvbi  于 2021-06-18  发布在  Mysql
关注(0)|答案(0)|浏览(277)

mysql数据库

WITH RECURSIVE CTE AS
(SELECT ssn, superssn, 0 as depth from 
EMPLOYEE where ssn='888665555' 
UNION ALL 
SELECT A.SSN, A.SUPERSSN, depth + 1 FROM 
EMPLOYEE A INNER JOIN CTE WHERE 
A.SUPERSSN = CTE.SSN ) 
SELECT * FROM CTE;

我试了很多方法,但都错了,所以我请求一些帮助。查看我的sql代码并给出一些建议?
table

mysql> select ssn,superssn from EMPLOYEE;
+-----------+-----------+
| ssn       | superssn  |
+-----------+-----------+
| 888665555 | NULL      |
| 000000002 | 000000001 |
| 000000003 | 000000002 |
| 000000004 | 000000003 |
| 000000005 | 000000004 |
| 000000006 | 000000005 |
| 123456789 | 333445555 |
| 453453453 | 333445555 |
| 666884444 | 333445555 |
| 333445555 | 888665555 |
| 987654321 | 888665555 |
| 987987987 | 987654321 |
| 999887777 | 987654321 |
| 000000001 | 999887777 |
+-----------+-----------+
14 rows in set (0.00 sec)

这是table,你帮我的时候可以参考一下。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题