Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8931919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:13:13+00:00 2026-06-15T09:13:13+00:00

I have this query SELECT patientid, practiceid, visitcount FROM ( SELECT patientid, practiceid ,

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:13:14+00:00Added an answer on June 15, 2026 at 9:13 am

    You can eliminate them by counting them and including them in the where clause. The following query counts them using logic similar to the rank — the number of times the patient has the same visitcount:

    SELECT patientid, practiceid, visitcount
    FROM (SELECT patientid, practiceid, visitcount,
                 RANK() OVER (PARTITION BY patientid ORDER BY visitcount DESC) as Rank,
                 COUNT(*) over (PARTITION by patientid, visitcount) as RankCount
          FROM aco.patients_practices
          WHERE practiceid in (select id from aco.practices where parentaco = 30982) and isprimary = 0
         ) A
    WHERE Rank = 1 and RankCount = 1
    

    I do notice that the practiceid is different in the last two records. It seems that you still want to eliminate both, though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query: SELECT * From checkfinale where AssociateID = 51 AND `CompletedDate`
I have this query: select BUnit, value from myTable where BUnit in (555,556,557,558) and
I have this query: SELECT * FROM sample INNER JOIN test ON sample.sample_number =
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
i have this query: SELECT `completed`.`ID` AS `ID`,`completed`.`level` AS `level`,`completed`.`completed_in` AS `completed_in`, COUNT(1) AS
I have this query SELECT zip, ( 3959 * acos( cos( radians(34.12520) ) *
I have this query: Select (Country.Name + ', ' + City.Name) as Location ...
I have this query: SELECT COUNT(*) AS invoice_count, IFNULL(SUM(qa_invoices.invoice_total), 0) AS invoice_total, IFNULL(SUM(qa_invoices.invoice_discount) ,0)
I have this query: select qa_returns_items.item_code, (CASE status_code WHEN 11 THEN (qa_returns_items.item_quantity - qa_returns_residues.item_quantity)
I have this query: (SELECT e.IdEvent,e.EventName,e.EventSubtitle,e.EventDescription,l.LocationName,e.EventVenue,EventStartDate,e.EventEndDate,e.EventHost,c.CategoryName,l.LocationCity,l.LocationState,e.isTBA, (SELECT s.status FROM jos_rsevents_subscriptions s WHERE s.IdUser =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.