| Author |
Topic |
|
invisible777
Starting Member
10 Posts |
Posted - 2007-05-03 : 01:21:21
|
| Row goes ItemOne, ItemTwo, CustIDIf I have a bunch of rows that look like this, how can I group and quantify the CustID get an overall average of how many times it appears? In other words, 003 appears 4 times, 004 appears 2 times, 5 appears 1 time. How could I code it to group and average 4, 2, 1?('ItemOne','ItemTwo',003)('ItemOne','ItemTwo',003)('ItemOne','ItemTwo',004)('ItemOne','ItemTwo',004)('ItemOne','ItemTwo',005)('ItemOne','ItemTwo',003)('ItemOne','ItemTwo',003) |
|
|
dfiala
Posting Yak Master
116 Posts |
Posted - 2007-05-03 : 01:29:02
|
| Select CustID, Count(*) Total FROM SomeTable Group By CustIDDean FialaVery Practical Software, IncNow with Blogging...http://www.vpsw.com/blogbabyMicrosoft MVP |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-05-03 : 01:32:08
|
| [code]-- Prepare sample datadeclare @t table( ItemOne varchar(10), ItemTwo varchar(10), CustID varchar(10))insert @tselect 'ItemOne','ItemTwo','003' union allselect 'ItemOne','ItemTwo','003' union allselect 'ItemOne','ItemTwo','004' union allselect 'ItemOne','ItemTwo','004' union allselect 'ItemOne','ItemTwo','005' union allselect 'ItemOne','ItemTwo','003' union allselect 'ItemOne','ItemTwo','003'-- Countselect CustID, count(*) as cntfrom @tgroup by CustID-- AverageSelect Avg(cnt) as Averagefrom(select CustID, count(*) as cntfrom @tgroup by CustID) t[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
invisible777
Starting Member
10 Posts |
Posted - 2007-05-03 : 01:36:45
|
| wow quick replies... thanks |
 |
|
|
|
|
|