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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:40:26+00:00 2026-05-20T10:40:26+00:00

I’m working on a query for SQL Server and I’m wondering if anyone can

  • 0

I’m working on a query for SQL Server and I’m wondering if anyone can give me some tips on selecting individual rows that make up a group (where the group’s based on an aggregate function, COUNT in this case)

So, as a simplified example, if I have a table of billings, as below, I want to select all billings for each client where they have 2 or more billings after a certain date.

ClaimID     ClaimDate             ClientName
101         May 5, 2010           Jim
102         June 19, 2010         Jim
103         August 5, 2008        Jim
104         January 1, 2011       Mary
105         May 8, 2009           Mary
106         November 4, 2010      Mary
107         October 6, 2010       Mary
108         April 4, 2010         Bob
109         April 29, 2009        Bob
110         July 7, 2006          Joe

So if I execute

SELECT ClientName, COUNT(ClaimID) FROM Billings
WHERE ClaimDate > '2010'
Group By ClientName
Having COUNT(ClaimID) > 1

I’d get:

Jim  2
Mary    3

Which is good, it finds all clients who have 2 or more billings in the time frame, but I want to actually list what those billings are.
So I want this:

ClaimID ClientName  Count
101         Jim     2
102         Jim     2
104         Mary    3
106         Mary    3
107         Mary    3

What do you think is the best way to accomplish this?

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-05-20T10:40:27+00:00Added an answer on May 20, 2026 at 10:40 am

    You join that back to the main table.

    SELECT B.ClaimID, B.ClaimDate, B.ClientName, G.ClaimCount
    FROM
    (
        SELECT ClientName, COUNT(ClaimID) ClaimCount
        FROM Billings
        WHERE ClaimDate > '2010'
        Group By ClientName
        Having COUNT(ClaimID) > 1
    ) G
    INNER JOIN Billings B on B.ClientName = G.ClientName
    WHERE B.ClaimDate > '2010'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.