Rabu, 29 Agustus 2012

average in sql

AVG() on SQL Server Function use to get average value of a numeric column.

select (1)Num,('Product One')ItemName,(2500000)ItemPrice Union
select (2),('Product Two'),(3500000) Union
select (3),('Product Three'),(4500000) Union
select (4),('Product Four'),(6500000) Union
select (5),('Product Five'),(7500000)

#Results:
Num  ItemName       ItemPrice
1    Product One    2500000
2    Product Two    3500000
3    Product Three  4500000
4    Product Four   6500000
5    Product Five   7500000

select AVG(ItemPrice)AvgItemPrice from (
   select (1)Num,('Product One')ItemName,(2500000)ItemPrice Union
   select (2),('Product Two'),(3500000) Union
   select (3),('Product Three'),(4500000) Union
   select (4),('Product Four'),(6500000) Union
   select (5),('Product Five'),(7500000)
)v0

#Results:
AvgItemPrice
4900000

Tidak ada komentar:

Posting Komentar