Rohit

Rohit

  • 1.8k
  • 236
  • 22.4k

Rank() function in sql getting wrong result

Nov 10 2016 1:15 AM
 below is my query
 
with A as (select *
,Rank() over(partition by ClientID order by CommunicationLogID desc ) as RNK from Communication)select * from A
where ContactDirectionID > 0 and dayid >= 1887 and dayid<=1887
and RNK=1
 
 
output
RNK
7
1
2
1
2
13
20
1
1
5
6
1
2
3
2
1
12
1
8
2
2
5
7
1
4
10
3
4
1
5
6
2
1
4
2
1
9
18
11
12
13
1
1
2
8
7
2
1
2
1
1
2
1
1
1
1
1
1
2
1
1
1
7
1
1
1
1
5
3
4
2
2
4
1
2
11
12
13
12
5
2
13
14
2
2
4
7
7
1
3
4
5
1
6
9
10
3
1
8
1
3
1
1
4
1
4
1
13
14
1
2
3
3
1
3
2
14
15
5
3
5
1
6
8
1
5
5
4
1
1
1
2
5
2
5
6
7
9
2
13
14
4
4
6
7
5
6
7
8
1
1
1
1
1
2
3
1
1
9
7
 
please help why i am getting this wrong output
 
after 1,2,3,it should start again 1 but suddenly getting 3,7,20,13 and many more
 
why  i am not getting please help me 
 
 
 

Answers (1)