由手机通讯记录界面想到的问题
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