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

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 avg problem

Author  Topic 

Gili
Starting Member

42 Posts

Posted - 2008-01-16 : 06:49:25
Hi,

i have table with this structure :

customer | sale1 | sale2 | sale3 |
arik | 5 | 6 | 0
i want to make avg of sale1,sale2,sale3 per row and where the value is 0 not take in the avg. like this 5+6 = 11/2 and not 5+6+0=11/3


any ideas plz?

thanks.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-16 : 07:34:40
Try this

Select customer,avg(sale1) as average from
(
select customer,sale1 from table
union all
select customer,sale2 from table
union all
select customer,sale3 from table
) as t
where sale1>0
group by customer

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -