Search This Blog

Wednesday, December 18, 2013

Average without Zero values SQL Server

SQL Server > Built-in Functions > AVG > Without zerous
 
Example to calculate average without zero

create table #sale(regionid int, amount int)
insert into #sale(regionid , amount ) values (1,100), (2,50) , (3,0)
select
       AVG (CASE WHEN amount <> 0 THEN amount ELSE NULL END)
from
   #sale
drop table #sale

result:
75