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 |
Nowy
Yak Posting Veteran
57 Posts |
Posted - 2007-06-13 : 08:48:57
|
First:- I've an table "Category" with 2 columns, "CatID", "Cat", "Package"- I've an table "Product" with 2 columns, "ProID", "CatID", "price"- About several reasons, it isn't possible to change the db structure. The table names and column names are actual to keep it simple.Table "Category":Sometimes there is 1 record with an "Package" name, but sometimes there are 3 records with the same "Package" name, etc.I want for every record with the same "Package" name the average "price" from table "Product" and put it in an new table "Test" |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-06-13 : 08:58:32
|
[code]Insert into Test (co1l, col2)Select c.Package, AVG(p.Price) as AvgPriceFrom Category c Join Product p on c.CatID = p.CatIDgroup by c.Package[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-13 : 09:00:52
|
[code]select Package, avg(price)from Category c inner join Product pon c.CatID = p.CatIDgroup by Package[/code] KH |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-13 : 09:02:42
|
KH |
|
|
|
|
|
|
|