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 8707791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:57:22+00:00 2026-06-13T03:57:22+00:00

My query: with cte as ( select client_id,COUNT(patient_id) PatientCount from ( select client_id,patient_id from

  • 0

My query:

with cte as (
        select client_id,COUNT(patient_id) PatientCount from
        (
            select client_id,patient_id
            from F_ACCESSION_DAILY
            group by CLIENT_ID,PATIENT_ID
            having COUNT(ACCESSION_ID)=2
        ) a
        group by CLIENT_ID
)

works, but is not so useful to me. because although i can JOIN easily on this query, I will actually need to repeat this WITH statement many times because i need to be able to differentiate between:

having count(Accession_id)=2

and

having count(Accession_id)=3

and

having count(accession_id)=4

and so on until around 100

i was thinking to do something more like this:

select distinct client_id, patient_id, count(*) over (partition by client_id, patient_id,accession_id) patientcount
    from f_accession_daily

but i am stuck!

i was wondering if you can point me into the right direction on how to convert the initial query into something more useable when having count(Accession)=many different values?

thanks so much for your guidance.

  • 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-13T03:57:23+00:00Added an answer on June 13, 2026 at 3:57 am

    Something like…?

       select client_id,accessioncount,COUNT(patient_id) PatientCount from 
        ( 
            select client_id,patient_id, count(accession_id) as accessioncount
            from F_ACCESSION_DAILY 
            group by CLIENT_ID,PATIENT_ID 
        ) a 
        group by CLIENT_ID,accessioncount
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query as follows: WITH CTE AS ( SELECT MIN(att.Date) [minDate] FROM
Query 1: SELECT * FROM user_d1 WHERE EXISTS (SELECT 1 FROM `user_d1` WHERE birthdate
Query: SELECT u.user_id,r.totalVotes votes,r.totalPoints rating,@row:=@row+1 rank FROM mismatch_user u LEFT JOIN ratingItems r ON
Query: SELECT DISTINCT ([Equipment List].ID) AS Expr1, [Job Assignments].Job FROM [Equipment List] LEFT JOIN
I have the following query: WITH cte AS ( SELECT windowId, frameIndx, elemIndx, comment,
I want to optimize this query WITH CTE AS ( SELECT KladrItemName _KladrItemName ,
This query is taking 5 seconds: With cte as ( Select ROW_NUMBER() OVER (Order
I have a query that looks like this WITH CTE AS ( SELECT ROW_NUMBER()
I have the following query: ;WITH valRules AS ( SELECT vr.valRuleID, Count(*) AS totalRows,
I have a SQL Server query as: SELECT top 1 vConsentInfo FROM ( SELECT

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.