Created
April 14, 2014 07:36
-
-
Save zelark/10624657 to your computer and use it in GitHub Desktop.
Calculate the avarage without non-zero values and given zero values in the next column.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with data as ( | |
select 50 as col1, 0 as col2 from dual union all | |
select 0 as col1, 20 as col2 from dual union all | |
select 20 as col1, 10 as col2 from dual union all | |
select 20 as col1, 10 as col2 from dual | |
) | |
select avg(nullif(col1, 0)) as col1_avg_no_zero, | |
avg(nullif(case when col2 = 0 then 0 else col1 end, 0)) as col1_avg_no_zero_with_col2 | |
from data; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment