postgres 递归查询 示例

时间:2020-12-26 20:48:33
select sum(i_enter_num),sum(i_leave_num) from vss_intelligent_passenger_flow 
where i_area_id in (select region_id from s_region where control_unit_id in

<span style="color:#FF0000;">( with recursive cte(control_unit_id) as( select * from s_control_unit where name='客流1' union all
                         select b.* from s_control_unit b inner join cte c on b.parent_id = c.control_unit_id)

                          select control_unit_id from cte )</span>
) and c_start_time>='2015-07-15 11:00:00' and c_end_time<='2015-07-15 12:04:36'



主要是红色部分,查询一个节点下的所有子节点