Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Computing Average

Status
Not open for further replies.

mistektips

Programmer
Apr 4, 2006
20
0
0
US
Hi,

There are 2 tables:
Table A (SecurityID, SecurityName)
Table B (SecurityID, Price, ClDate)

The query is to find the average price with Name=ABC Corp in year 2005

I wanted to know if this query would be right. If not, then why?

select avg(price) from B, A group by securityID having A.SecurityID=B.SecurityID and SecurityName='ABC Corp' and year(ClDate)=2005

 
Code:
select A.*,
       avg(price)
from B
LEFT JOIN A ON A.SecurityID=B.SecurityID
WHERE A.SecurityName='ABC Corp' and year(A.ClDate)=2005
group by securityID

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top