November 19, 2009 at 11:07 am
Hi, I have a table named test. The table have this records:
Name: Numbers:
pedro 10
pedro 11
paulo 5
ana 7
ana 8
ana 9
What i want is to make a select that will display a count for each equal name:
Pedro 10 2
pedro 11 2
paulo 5 1
Ana 7 3
ana 8 3
ana 9 3
It will count the number of times that a name is equal.
how can i make the select?
Thank you.
November 19, 2009 at 11:09 am
Inline correlated subquery is one way.
Without knowing your table structure, I can't really provide sample code for how to do it.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
November 19, 2009 at 11:10 am
This somewhat looks like homework, so I'll give you some hints here.
I'd build an aggregate query that uses COUNT() to determine how many times each name appears. That it a very simple aggregate. Then make that a subquery and join it back to the original table on names, and join in the count from that subquery to get that value.
November 19, 2009 at 11:11 am
table structure is:
Name, numbers
Only this.
November 19, 2009 at 4:52 pm
slightly different than the correlated subquery is the option of using a CTE. Use the cte to join back to the original table to get the results you are seeking.
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply