怎么样在mysql5.7上实现递归查询

下面是sqlserver上的语句,我的mysql版本是5.7 不支持这种写法
--递归取当前部门及所有下级部门
    WITH DEPT AS
        (
            select cost_name,department_id,cost_code,parent_cost_code
            from2
            where cost_code  in ('T')
            
            UNION ALL
            
            SELECT c.cost_name,c.department_id,c.cost_code,c.parent_cost_code
            FROM DEPT d,表2 C 
            WHERE d.cost_code = c.parent_cost_code
        )
        SELECT * FROM DEPT ;
怎么样在mysql上实现这个递归查询

可以在https://blog.csdn.net/xubenxismile/article/details/107662209
查看

试一试临时表可以吗
当你断开与数据库的连接后,临时表就会自动被销毁。 临时表只在当前连接中有效,查询临时表数据和查询正常表数据一样;
CREATE TEMPORARY TABLE 临时表名 AS
( SELECT * FROM tables );
删除临时表:
DROP TABLE 临时表名;