以下方法是使用了 Recursive CTE (Common Table Expressions). 而MySQL version 是 8.0, 如果 version < 8.0 是不能使用 WITH clause的. What is CTE? 由於每條 statement 都會產生一個暫時的result set, 如果想賦予它一個名字給另外的 statement 使用, 就會用 CTE. 它是以WITH為開頭. WITH
cte_name [(col1, col2, ...)]
AS ( subquery )
Select col1, col2, .. from cte_name; What is Recursive CTE? 是不斷…