Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Avg every set of records
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Nowy
Yak Posting Veteran

57 Posts

Posted - 06/13/2007 :  08:48:57  Show Profile  Reply with Quote
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"

Edited by - Nowy on 06/13/2007 08:52:31

harsh_athalye
Flowing Fount of Yak Knowledge

India
5581 Posts

Posted - 06/13/2007 :  08:58:32  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
Insert into Test (co1l, col2)
Select c.Package, AVG(p.Price) as AvgPrice
From Category c Join Product p on c.CatID = p.CatID
group by c.Package


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17689 Posts

Posted - 06/13/2007 :  09:00:52  Show Profile  Reply with Quote
select Package, avg(price)
from   Category c inner join Product p
on     c.CatID = p.CatID
group by Package



KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17689 Posts

Posted - 06/13/2007 :  09:02:42  Show Profile  Reply with Quote



KH

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000