postgres 遞歸查詢 示例

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'



主要是紅色部分,查詢一個節點下的所有子節點

發佈了61 篇原創文章 · 獲贊 8 · 訪問量 15萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章