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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:18:42+00:00 2026-05-10T23:18:42+00:00

I have a table with the following columns: A B C ——— 1 10

  • 0

I have a table with the following columns:

  A   B   C --------- 1   10  X 1   11  X 2   15  X 3   20  Y 4   15  Y 4   20  Y  

I want to group the data based on the B and C columns and count the distinct values of the A column. But if there are two ore more rows where the value on the A column is the same I want to get the maximum value from the B column.

If I do a simple group by the result would be:

  B   C    Count -------------- 10  X    1 11  X    1 15  X    1 20  Y    2 15  Y    1  

What I want is this result:

  B   C    Count -------------- 11  X    1 15  X    1 20  Y    2  

Is there any query that can return this result. Server is SQL Server 2005.

  • 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. 2026-05-10T23:18:42+00:00Added an answer on May 10, 2026 at 11:18 pm

    I like to work in steps: first get rid of duplicate A records, then group. Not the most efficient, but it works on your example.

    with t1 as (     select A, max(B) as B, C          from YourTable         group by A, C ) select count(A) as CountA, B, C     from t1     group by B, C 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with the following columns: EntityId, EntityName, EntityProfile, ................. I want
I have a table data with following columns: |-a-|-b-|-text-| |-1-|-1-|-text-| |-1-|-2-|-text-| |-1-|-3-|-text-| |-2-|-1-|-text-| |-2-|-2-|-text-|
I have a table with the following columns and data Category Item Price Tax
I have a table with following columns and data FldID | Rev | Words
I have a table with the following columns and data: activity_dt | activity_amt 2009-01-01
I have a table which contains the following columns: UniqueID remote_ip_addr platform I want
I have the following table with the following columns: Person(id, name, surname) I want
I have a table with the following columns (of urls): [id,url,visited,timestamp] Types:[int,string,int,long] I want
In SQL Server 2008, I have a table with following columns and data Date
I have a table with the following columns: a|b|c|d|e and I want to 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.