我有一张表,当我对它运行此查询时
SELECT m.Id, m.DateOne, m.DateTwo, (SELECT IIF
(c.ClubId = 1095 , x.CaptainOne , x.CaptainTwo)
FROM Match x
JOIN Player c on c.Id = x.CaptainOne
JOIN Player d on d.Id = x.CaptainTwo
WHERE x.Id = m.Id ) AS Captain
FROM Match m
order by DateOne
给我一个看起来像这样的输出..
ID | DateOne | DateTwo | Captain
1 | 01/12/2015 | | 1658
2 | 08/12/2015 | | 1658
3 | 15/12/2015 | 22/12/2015 | 1658
4 | 02/01/2016 | | 1703
5 | 09/01/2016 | | 1703
6 | 16/01/2016 | 23/01/2016 | 1658
7 | 30/01/2016 | | 1658
8 | 06/02/2016 | | 1658
9 | 13/02/2016 | | 1658
10 | 20/02/2016 | | 1703
然后我想使用这些结果来进一步缩小输出,使其看起来像这样
Captain | Date(Min) | Date(Max) | Count
1658 | 01/12/2015 | 22/12/2015 | 3
1703 | 02/01/2016 | 09/01/2016 | 2
1658 | 16/01/2016 | 13/02/2016 | 4
1703 | 20/02/2016 | 20/02/2016 | 1
在获取第一次出现的DateOne时创建连续队长的计数,如果DateTwo为最后一次出现的null,则为DateTwo或DateOne。
我希望这是有道理的.. 感谢