IF EXISTS(SELECT FROM SYS.TABLES WHERE NAME='SPD') DROP TABLE SPD;
WITH CTE1 AS
(
SELECT
IIF(PD_DueDT>=ISNULL(PD_DebitSuccDT,'9999-12-31'),0,1) AS FLAG/逾期FLAG/,
ROW_NUMBER() OVER(PARTITION BY PD_EFH_SN ORDER BY PD_Termth) AS ID/期次序号/,
MAX(PD_Termth) OVER (PARTITION BY PD_EFH_SN)AS CurrID/当前最大期次序号*/,
为武冈等地区用户提供了全套网页设计制作服务,及武冈网站建设行业解决方案。主营业务为成都做网站、网站建设、武冈网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!
FROM PD WHERE PD_DueDT<=GETDATE() AND PD_Termth>0
),
CTE2 AS
(
SELECT
SUM(FLAG) OVER(PARTITION BY PD_EFH_SN ORDER BY PD_Termth ROWS UNBOUNDED PRECEDING) AS AccuFlag/累计逾期期次/,
FROM CTE1
),
CTE3 AS
(
SELECT
ID-AccuFlag AS FlagGrp/逾期分组/,
FROM CTE2
),
CTE4 AS
(
SELECT
SUM(FLAG) OVER (PARTITION BY PD_EFH_SN,FlagGrp) AS CountFlag/分组计数/,
FROM CTE3 WHERE FLAG=1
),
CTE5 AS
(
SELECT
MAX(CountFlag) OVER (PARTITION BY PD_EFH_SN) AS MaxContFlag/最大连续/,
MAX(AccuFlag) OVER (PARTITION BY PD_EFH_SN) AS TotFlag/历史累计/,
IIF(ID=PD_TotTerm,CountFlag,0) AS CurrContFlag/当前累计/,
ROW_NUMBER() OVER (PARTITION BY PD_EFH_SN ORDER BY PD_Termth DESC) AS CurrTermth,
FROM CTE4
)
SELECT DISTINCT PD_EFH_SN,MaxContFlag,TotFlag,CurrContFlag,'XFY' AS DataSource INTO SPD FROM CTE5 WHERE CurrTermth=1
分享名称:连续逾期
URL标题:https://www.cdcxhl.com/article22/pipicc.html
成都网站建设公司_创新互联,为您提供网站设计公司、外贸网站建设、网站导航、网站改版、网站建设、营销型网站建设
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联