postgres 递归查询 示例

来源:互联网 发布:哔哩哔哩for mac 编辑:程序博客网 时间:2024/06/05 09:47
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'



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

0 0
原创粉丝点击