123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- WITH RECURSIVE
- excludeIP(exclude_ip) AS(
- SELECT 'ip20'
- UNION ALL
- SELECT 'ip21'
- ),
- temp_table as (
- SELECT ID , time, from_ip,to_ip, data
- FROM table_01
- left join excludeIP on (table_01.from_ip = excludeIP.exclude_ip or table_01.to_ip = excludeIP.exclude_ip )
- WHERE
- excludeIP.exclude_ip IS null
- ),
- distinct_temp_table as (
- SELECT
- DISTINCT
- from_ip,to_ip
- from temp_table
- ),
- input as (from_ip,to_ip)(
- SELECT 'ip0' ,'ip0'
- UNION ALL
- SELECT 'ip1' ,'ip1'
- ),
- fir_res as(
- SELECT
- DISTINCT
- t.ID, t.time, t.from_ip, t.to_ip
- CASE WHEN
- (t.from_ip = input.from_ip AND t.to_ip = input.to_ip)
- OR (t.to_ip = input.from_ip AND t.from_ip = input.to_ip)
- THEN 0 ELSE 1 END AS addtion_info
- FROM distinct_temp_table t
- JOIN input ON t.from_ip = input.to_ip OR t.to_ip = input.from_ip
- WHERE input.addtion_info = 1 AND
- (SELECT COUNT(*) FROM distinct_temp_table sub WHERE sub.from_ip = t.from_ip OR sub.to_ip = t.from_ip) <= 10
-
- )
-
- SELECT ID, time, from_ip, to_ip, data, from_pos, to_pos, level, addtion_info
- FROM fir_res;
|