×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Need help with this sql grouping/aggregate query

Need help with this sql grouping/aggregate query

Need help with this sql grouping/aggregate query

(OP)
Hi,

I have a query that gives this table


----------------|
count   |  user |
----------------|
     1  |  sam  |
----------------|
     13 |  sam  |
----------------|
     1  |  pat  |
----------------|
     7  |  gus  |
----------------|
     1  |  art  |
----------------|

For this discussion, let's say that it lists the count of some units that each user has.

The query for this is simple enuff.

select count(count), user
from <table>
group by user;

Now what I want now is a display that shows the number of users that have the same unit count value.  So the table would look like this.

--------------|
count | u_count |
--------------|
   1  |   3   |
--------------|
   13 |   1   |
--------------|
   7  |   1   |
--------------|


Is there a way to use sql only to accomplish this?

TIA,
george

RE: Need help with this sql grouping/aggregate query

Create a view based on the first SQL and then query the view with the second one. You can use temporary table also, if the SQL engine has this feature.

RE: Need help with this sql grouping/aggregate query

Try this:

Select Count As Count1, Count(User)
From Table
Group by Count1

Hope this helps!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources