Overclock.net banner

1 - 2 of 2 Posts

·
Registered
Joined
·
740 Posts
Discussion Starter · #1 ·
Cant test anything until I'm back at work. Been trying to use SQL+ for about a day now.

My question is

http://www.w3schools...ql_func_avg.asp

The example they show is

Quote:
SELECT AVG(Price) AS PriceAverage FROM Products;
They did AVG(price) which gets the price but then they have "PriceAverage". Is that a new name?

My example table called "purchase":

Car price purchase Date

smcar £10 01/12/2014

smfar £20 03/12/2014

In my case will this be "SELECT AVG(price) as PriceAverage FROM purchase" ?
 

·
Registered
Joined
·
656 Posts
Quote:
Originally Posted by Said Nobody View Post

Cant test anything until I'm back at work. Been trying to use SQL+ for about a day now.

My question is

http://www.w3schools...ql_func_avg.asp

The example they show is

They did AVG(price) which gets the price but then they have "PriceAverage". Is that a new name?

My example table called "purchase":

Car price purchase Date

smcar £10 01/12/2014

smfar £20 03/12/2014

In my case will this be "SELECT AVG(price) as PriceAverage FROM purchase" ?
Yes, that's how a alias can be assigned (to any column(s).
However, that's not the correct answer, if price is null or zero in any rows the average isn't correct.
SELECT AVG(PRICE) AS PriceAverage
FROM PRODUCTS
WHERE PRICE IS NOT NULL
AND PRICE > 0;
 
1 - 2 of 2 Posts
Top