Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Rich75
Starting Member
8 Posts |
Posted - 2013-03-27 : 11:49:18
|
I have the following data:Main_Number Sub_Number13965015 1396501613965015 1396501713965028 1396502913965028 1396502913965033 1396503413965033 13965034I want to display a count of distinct Sub Numbers for each Main Number. So my results would look like this:Main_Number Count_of_Distinct_Sub_Numbers 13965015 2 13965028 113965033 1I'm not sure where to begin in writing this query. Could you offer some advice.Thanks |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-03-27 : 11:54:05
|
[code]SELECT Main_Number, COUNT(DISTINCT Sub_Number) as Count_of_Distinct_Sub_Numbers FROM YourTableNameHereGROUP BY Main_Number;[/code] |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2013-03-27 : 11:55:49
|
This?select Main_number, count(distinct sub_number) as cnt from table group by Main_number Too old to Rock'n'Roll too young to die. |
|
|
Rich75
Starting Member
8 Posts |
Posted - 2013-03-27 : 11:57:32
|
quote: Originally posted by James K
SELECT Main_Number, COUNT(DISTINCT Sub_Number) as Count_of_Distinct_Sub_Numbers FROM YourTableNameHereGROUP BY Main_Number;
Thank You ! |
|
|
|
|
|