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 |
|
emyk
Yak Posting Veteran
57 Posts |
Posted - 2011-12-26 : 12:57:13
|
| I have a query that returns multiple rows and What I am trying to do here is that using the returned rows to create a new table and insert a raw (1). My approach is that to get the duplicate count by col3 (col3 & col1 are always same value)and then divide the sum of col3 by the count, but I am still struggling to implement my approach. Any suggestions on how to better address this?Table1 col1 col2 col3 car 22 345 car 34 345 car 234 345Desired Table col1 col2 car 345edit: moved to proper forum |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-12-26 : 13:10:06
|
You can use the DISTINCT keyword to remove the duplicatesinsert into NewTable(col1, col2)select distinct col1, col3 from Table1 |
 |
|
|
emyk
Yak Posting Veteran
57 Posts |
Posted - 2011-12-26 : 13:22:46
|
| Thank You Sunitabeck. Distinct did all the trick. |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-12-26 : 17:14:32
|
| YVW; |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-12-27 : 08:00:34
|
| Why do you want to have a new table? You could create a view for thisMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|