I have this query
SELECT
patientid,
practiceid,
visitcount
FROM
(
SELECT
patientid,
practiceid ,
visitcount,
RANK() OVER (PARTITION BY patientid ORDER BY visitcount DESC) as Rank
FROM
aco.patients_practices
WHERE practiceid in (select id from aco.practices where parentaco = 30982) and isprimary = 0
) AS A
WHERE
Rank = 1
Here are some results
patientid practiceid visitcount 157053 30976 6 158463 30974 2 187772 30973 15 187797 30971 1 187797 30975 1
Notice the last 2 patientid’s are the same and have the same visitcount hence the same rank. How can I omit these records with equal ranks completely from the output?
Thanks!
You can eliminate them by counting them and including them in the
whereclause. The following query counts them using logic similar to the rank — the number of times the patient has the same visitcount:I do notice that the practiceid is different in the last two records. It seems that you still want to eliminate both, though.