如何为我要在Java中调用的MySQL查询创建存储过程

时间:2018-12-10 08:39:38

标签: java mysql stored-procedures

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代码并提供一些建议吗?

表格

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)

这是表格,因此当您需要帮助时,您可以参考。

0 个答案:

没有答案