2019-07-06 sql 连续出现次数

由手机通讯记录界面想到的问题

2019-07-06 sql 连续出现次数

2019-07-06 sql 连续出现次数

 

SELECT CASE WHEN AA.num=1 THEN AA.Tel
ELSE AA.Tel+'('+CASt(AA.num AS VARCHAR(4))+')' END AS 通讯记录,AA.Times

FROM (
SELECT a.Tel ,COUNT(*) AS num,MAX(a.Times) AS Times FROM
(SELECT ROW_NUMBER() OVER (PARTITION BY Tel ORDER BY times,Tel) AS num1,ROW_NUMBER() OVER (ORDER BY times,Tel) AS num2,*
FROM #temp ) a
GROUP BY a.num2-a.num1,a.Tel,CONVERT(VARCHAR(10),a.Times,120)
) AS AA ORDER BY AA.Times

 

上一篇:Redis数据库笔记10——命令补充


下一篇:简单的输出个人信息