zoukankan      html  css  js  c++  java
  • with递归

    适用于树状结构,关键在于ParentGuid和Guid

    --方案一
    with A as (
    select Guid,ParentGuid,Name_CN,IsProduceBizEntity,1 as xh from dbo.BAS_OrgFrame where Guid='000000020129' and SealUser is null--5e2eb9f1-7e30-4245-a698-c1df88e5c274
    union all
    select b.Guid,b.ParentGuid,b.Name_CN,b.IsProduceBizEntity,a.xh+1 xh from A a inner join dbo.BAS_OrgFrame b on a.ParentGuid=b.Guid and b.SealUser is null
    )
    --select * from A
    select top 1 A.Guid from A where IsProduceBizEntity=1 order by xh



    --方案二
    with A as (
    select Guid,ParentGuid,Name_CN,IsProduceBizEntity, 1 as xh from dbo.BAS_OrgFrame where Guid='000000020129' and SealUser is null--5e2eb9f1-7e30-4245-a698-c1df88e5c274
    union all
    select b.Guid,b.ParentGuid,b.Name_CN,b.IsProduceBizEntity, a.xh+1 as xh from A a inner join dbo.BAS_OrgFrame b on a.ParentGuid=b.Guid and b.SealUser is null and b.IsProduceBizEntity = 1
    )
    select A.ParentGuid, * from A

  • 相关阅读:
    sqlilabs 5
    sqlilabs 1-4
    ipset
    kill命令的使用
    docker 札记
    批量删除数据库表中数据行
    正则表达式调试
    TimescaleDB安装学习
    记一次 Centos7 postgresql v11 安装时序数据库 TimescaleDB
    "知识库"
  • 原文地址:https://www.cnblogs.com/jonsnow/p/7422948.html
Copyright © 2011-2022 走看看