 
--   目标 递归几次
-- WITH RECURSIVE excludeAdd (exclude_add) as (
--        values
--             ('add21')
--             ,('add20')
-- ),
-- input_add(_add)as
-- (
--     values
--             ('add0')
--             ,('add1')
-- )
WITH RECURSIVE excludeAdd (exclude_add) as (
       select 
            ('add21')
  union all
            select ('add20')
),
input_add(_add)as
(
      select 
            ('add0')
    union all
           select ('add1')

),

 cte AS (
    SELECT
  
     ID
    , time
    , from_add
    , to_add
    , data
    ,    1 AS level
   -- ,            CASE WHEN from_add IN (SELECT exclude_add FROM excludeAdd) 
--    OR    to_add IN (SELECT exclude_add FROM excludeAdd) THEN 0 ELSE 1 END AS addtion_info
    FROM table_01
    WHERE from_add IN (select _add from   input_add ) OR to_add IN (select _add from   input_add ) 
    UNION ALL
    SELECT 
      
   t.ID
    , t.time
    , t.from_add
    , t.to_add
    , t.data
    ,   cte.level + 1
    -- , CASE WHEN t.from_add IN (SELECT exclude_add FROM excludeAdd)
    --         OR t.to_add IN (SELECT exclude_add FROM excludeAdd) 
    --         OR (t.from_add = cte.from_add AND t.to_add = cte.to_add)
    --             OR (t.to_add = cte.from_add AND t.from_add = cte.to_add) THEN 0 ELSE 1 END AS addtion_info
    FROM table_01 t
    JOIN cte ON t.from_add = cte.to_add OR t.to_add = cte.from_add
    WHERE 
    -- cte.addtion_info = 1 
    -- AND         
      (SELECT COUNT(*) FROM table_01 sub WHERE sub.from_add = t.from_add OR sub.to_add = t.from_add) <= 10
          AND t.from_add NOT IN (SELECT exclude_add FROM excludeAdd) 
   AND t.to_add NOT IN (SELECT exclude_add FROM excludeAdd)
   -- 递归次数小于5
   AND level <=4 
) 

SELECT DISTINCT  ID, time, from_add, to_add, data,    level
-- , addtion_info
FROM cte;

-- select * from excludeAdd
 