sql server 2005中使用with实现递归的方法
程序员文章站
2023-10-31 09:26:22
复制代码 代码如下:with fw_requestion_note_temp(old_apply_id) as ( --取根节点放入临时表 select old_apply...
with fw_requestion_note_temp(old_apply_id) as ( --取根节点放入临时表
select old_apply_id from fw_requestion_note --where old_apply_id = 'e741470e-8b5c-4f91-9b03-c7474d103aef'
--根据已取到的数据递归取其字节点的数据
union all select fw.old_apply_id from fw_requestion_note fw
inner join fw_requestion_note_temp temp on fw.apply_id = temp.old_apply_id ) select old_apply_id from fw_requestion_note_temp