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
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Midhun TpPosted Nov 10, 2016, 8:40 PM
That is because you are finding rank based on the table communication. But the result is from "A" with some where conditions. So the rows with other ranks are skipped. You just query "select * from A". You can see all ranks.