我有一张桌子:
CREATE TABLE [dbo].[TargettingReport](
[MLISNPI] [varchar](50) NULL,
[CLIENT_ID1] [varchar](50) NULL,
[Sum of count] [int] NULL
) ON [PRIMARY]
我正在尝试根据以下标准选择第二和第三高SUM OF COUNT
的MLISNPI, CLIENT_ID1
这就是我如何为每个独特的事件获得最大值MLISNPI, CLIENT_ID1
:
select [MLISNPI],[CLIENT_ID1],MAX([Sum of count])
from [TargettingReport]
group by
[MLISNPI],[CLIENT_ID1]
问题是我如何获得第二和第三高?
这是一些示例数据:
+---------+------------+--------------+
| MLISNPI | CLIENT_ID1 | sum of count |
+---------+------------+--------------+
| 567890 | 214060 | 18 |
| 678901 | 214060 | 58 |
| 789012 | 214060 | 27 |
| 891012 | 214060 | 1 |
| 101112 | 214060 | 23 |
| 003001 | 101596 | 0 |
| 003001 | 101522 | 436 |
| 003001 | 101597 | 0 |
| 003002 | 102165 | 66 |
| 003002 | 100062 | 1 |
| 003002 | 211074 | 1229 |
| 003006 | 102235 | 21 |
| 003014 | 213926 | 5 |
| 003016 | 213143 | 3 |
| 003023 | 213801 | 55 |
| 003023 | 212876 | 44 |
| 003023 | 100218 | 0 |
| 003028 | 211144 | 133 |
| 003041 | 100236 | 346 |
| 003041 | 103164 | 65 |
| 003051 | 213402 | 157 |
| 003058 | 100572 | 28 |
| 003065 | 101632 | 29 |
| 003071 | 213632 | 6 |
| 003072 | 101506 | 4 |
| 003081 | 100087 | 398 |
| 003083 | 214311 | 7 |
| 003117 | 210178 | 203 |
| 003121 | 214008 | 9 |
| 003139 | 102179 | 1635 |
| 003147 | 216022 | 21 |
| 003149 | 211425 | 1 |
| 003186 | 215748 | 1 |
+---------+------------+--------------+