1234567891011121314151617181920212223242526272829 |
- WITH RECURSIVE ConnectedIPs AS (
- -- 递归基: 初始化起始 IP 和结束 IP
- -- 这些是递归查询的起点
- SELECT
- 1 AS level, -- 记录当前递归层级(初始为1)
- 'ip0' AS from_ip, -- 起始 IP
- NULL AS to_ip, -- 初始时没有 to ip
- 0 AS addition_info -- 初始时没有标记为连接数过多
- UNION ALL
- SELECT
- 1 AS level, -- 记录当前递归层级(初始为1)
- 'ip1' AS from_ip, -- 起始 IP
- NULL AS to_ip, -- 初始时没有 to ip
- 0 AS addition_info -- 初始时没有标记为连接数过多
- )
- -- 选择最终结果
- SELECT
- ci.level,
- ci.from_ip,
- ci.to_ip,
- NULL AS unique_hash, -- 需要替换为你实际的 unique hash 生成逻辑
- CURRENT_TIMESTAMP AS time, -- 当前时间戳作为时间字段
- NULL AS data, -- 需要替换为你实际的数据
- NULL AS from_pos, -- 需要替换为你实际的位置信息
- NULL AS to_pos, -- 需要替换为你实际的位置信息
- ci.addition_info -- 标记是否连接数过多
- FROM ConnectedIPs ci
- WHERE ci.level <= 5; -- 确保只选择不超过最大递归深度的结果
|