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 |
|
osullivj
Starting Member
4 Posts |
Posted - 2011-05-30 : 16:49:14
|
Ok Guys..I am struggling with this but you guys should be able to helpI have a table like thisID, AREA, SUB_AREA1, x, s2, x, s3, x, t 4, y, yand would like to get the following answer, the number of sub areas per areaAREA, COUNTSUBAREASx, 2y, 1You help is appreciatedThanks,J As our society gets more complex and our people get more complacent, the role of the jester is more vital than ever before. Please stop sitting around. We need you to make a ruckus. Seth Godin - Linchpin |
|
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2011-05-30 : 17:32:57
|
try this:select area, count(area) as count_subareafrom table_like_thisgroup by area and result will be:AREA, COUNTSUBAREASx, 3y, 1best |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-05-30 : 17:47:09
|
| Or this, a slight tweak to slimtselect area, count(distinct area) as count_subareafrom table_like_thisgroup by areaJimEveryday I learn something that somebody else already knew |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-05-30 : 19:57:28
|
should it be counting distinct sub_area ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-05-30 : 20:02:14
|
| Oops! Yes, it should be sub_area.JimEveryday I learn something that somebody else already knew |
 |
|
|
osullivj
Starting Member
4 Posts |
Posted - 2011-05-31 : 09:30:42
|
Great Thanks very much As our society gets more complex and our people get more complacent, the role of the jester is more vital than ever before. Please stop sitting around. We need you to make a ruckus. Seth Godin - Linchpin |
 |
|
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2011-05-31 : 12:33:18
|
| jimf, thank you.distinct (count sub_area) is the right count :)i overlooked it :) |
 |
|
|
|
|
|
|
|