Author |
Topic |
morleyz
Starting Member
17 Posts |
Posted - 2008-09-22 : 16:04:44
|
I'm not even sure if this is possible, so it's OK to tell me I'm screwed, but I was wondering if there's a way to aggregate data for some fields and just duplicate that data for others (such as text fields).Example Data:Row1, Row2, Row3, Row41, 15, 12, Bob's a man1, 12, 3, Mary's a woman1, 3, 5, Joe's a dog2, 3, 7, Jack's a man2, 9, 18, Melissa's a catSo I'd like to do something like:SELECT avg(row2), avg(row3), Row4 FROM TABLE GROUP BY Row1and get results like:10, 6.67, Bob's a man10, 6.67, Mary's a woman10, 6.67, Joe's a dog6, 12.5, Jack's a man6, 12.5, Melissa's a catIs there a way to do something like this with a single query? The GROUP BY Clause generates an error and I agree that the SQL isn't correct, but I didn't know if there was a correct way to do this.Thanks |
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-09-22 : 16:14:50
|
You would have to do something like this to get those results. BYW, I think you are confusing Rows with Columns  select d.row1 ,d.avgRow2 ,d.avgRow3 ,t.row4from ( SELECT row1, avg(row2) avgrow2, avg(row3) avgrow3 FROM [TABLE] GROUP BY Row1 ) djoin [Table] t on t.row1 = d.row1 Be One with the OptimizerTG |
 |
|
morleyz
Starting Member
17 Posts |
Posted - 2008-09-22 : 16:22:55
|
Yes...I should have used Col1, Col2, etc...I had them right in my head, just chose the wording poorly. Let me try that query in the real world and I'll see if that's what I needed.Thanks! |
 |
|
morleyz
Starting Member
17 Posts |
Posted - 2008-09-23 : 10:37:44
|
This works as I need. Thanks!! |
 |
|
|
|
|