惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tenable Blog
H
Heimdal Security Blog
K
Kaspersky official blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
S
Schneier on Security
G
GRAHAM CLULEY
U
Unit 42
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
C
CERT Recently Published Vulnerability Notes
Google DeepMind News
Google DeepMind News
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
阮一峰的网络日志
阮一峰的网络日志
Simon Willison's Weblog
Simon Willison's Weblog
C
Cisco Blogs
Cyberwarzone
Cyberwarzone
T
The Exploit Database - CXSecurity.com
Project Zero
Project Zero
Security Archives - TechRepublic
Security Archives - TechRepublic
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 司徒正美
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
V
Visual Studio Blog
博客园 - Franky
Engineering at Meta
Engineering at Meta
WordPress大学
WordPress大学
Jina AI
Jina AI
P
Proofpoint News Feed
P
Proofpoint News Feed
有赞技术团队
有赞技术团队
L
LINUX DO - 最新话题
宝玉的分享
宝玉的分享
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 聂微东
T
The Blog of Author Tim Ferriss
Spread Privacy
Spread Privacy
Application and Cybersecurity Blog
Application and Cybersecurity Blog
IT之家
IT之家
S
Security Affairs
博客园 - 叶小钗
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
小众软件
小众软件
N
News | PayPal Newsroom
Cloudbric
Cloudbric
AWS News Blog
AWS News Blog
W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
NISL@THU
NISL@THU

博客园 - stefanie

PowerShell-将CSV导入SQL Server [Powershell] 检查IIS设置 VBS 操作注册表 十六进制 无法在People Picker中选择用户 Microsoft Certification List WINDOWS 2012忘记密码之后。。。 Auto Install Workflow Manager 1.0 批量删除Kindle Personal Documents 导入Excel表格到SharePoint站点 用户中心 - 博客园 [Powershell] FTP Download File [PowerShell] Backup Folder and Files Across Network SSRS 请求并显示SharePoint人员和组字段 VS 2010 安装 .net framework2.0/3.0/3.5 How to Setup AssociatedOwnerGroup / AssociatedMemberGroup / AssociatedVisitorGroup RPC服务不可用 [转]SharePoint Versions 安装 64 位版本的 Office 2010 后,无法查看数据表视图中的列表 [MOSS]关闭弹出窗口
SQL - 获取多机构最近相同节点
stefanie · 2018-10-16 · via 博客园 - stefanie
-- Create Branches Table
create table Branches
(
    BranchCode varchar(16)
    ,BranchName nvarchar(32)
    ,L0BCode varchar(16)
    ,L1BCode varchar(16)
    ,L2BCode varchar(16)
    ,L3BCode varchar(16)
    ,L4BCode varchar(16)
    ,L5BCode varchar(16)
    ,L6BCode varchar(16)
    ,L7BCode varchar(16)
)
go


-------------------------------------------------------------------------------------------

declare @branches varchar(512) = '02078,31696,90100'
        ,@count int
        ,@branchcode varchar(16)

select @count = COUNT(*) from string_split(@branches,',') 

;with t1
as
(
select b.L0BCode,b.L1BCode,b.L2BCode,b.L3BCode,b.L4BCode,b.L5BCode,b.L6BCode,b.L7BCode
,iif(isnull(b.L0BCode,'') = '',@count,dense_rank()over(order by b.L0BCode ))  as L0Rank
,iif(isnull(b.L1BCode,'') = '',@count,dense_rank()over(order by b.L1BCode ))  as L1Rank
,iif(isnull(b.L2BCode,'') = '',@count,dense_rank()over(order by b.L2BCode ))  as L2Rank
,iif(isnull(b.L3BCode,'') = '',@count,dense_rank()over(order by b.L3BCode ))  as L3Rank
,iif(isnull(b.L4BCode,'') = '',@count,dense_rank()over(order by b.L4BCode ))  as L4Rank
,iif(isnull(b.L5BCode,'') = '',@count,dense_rank()over(order by b.L5BCode ))  as L5Rank
,iif(isnull(b.L6BCode,'') = '',@count,dense_rank()over(order by b.L6BCode ))  as L6Rank
,iif(isnull(b.L7BCode,'') = '',@count,dense_rank()over(order by b.L7BCode ))  as L7Rank
from 
    Branches b
        inner join
            string_split(@branches,',')  b2
                on
                    b.BranchCode = b2.value
)

,t2
as
(
select 
    top 1 * 
from
(
    select 
        b.L0BCode,b.L1BCode,b.L2BCode,b.L3BCode,b.L4BCode,b.L5BCode,b.L6BCode,b.L7BCode
        ,sum(L0Rank)over(partition by 1) as L0Sum
        ,sum(L1Rank)over(partition by 1) as L1Sum
        ,sum(L2Rank)over(partition by 1) as L2Sum
        ,sum(L3Rank)over(partition by 1) as L3Sum
        ,sum(L4Rank)over(partition by 1) as L4Sum
        ,sum(L5Rank)over(partition by 1) as L5Sum
        ,sum(L6Rank)over(partition by 1) as L6Sum
        ,sum(L7Rank)over(partition by 1) as L7Sum
    from t1 as b
) as b
order by b.L7BCode desc,b.L6BCode desc,b.L5BCode desc,b.L4BCode desc,b.L3BCode desc,b.L2BCode desc,b.L1BCode desc
)

select 
    @branchcode = 
    (
        case 
            when L7Sum = @count then L7BCode
            when L6Sum = @count then L6BCode
            when L5Sum = @count then L5BCode
            when L4Sum = @count then L4BCode
            when L3Sum = @count then L3BCode
            when L2Sum = @count then L2BCode
            when L1Sum = @count then L1BCode
            when L0Sum = @count then L0BCode
        else
            L0BCode
        end
    )
    
from t2


select @branchcode