teradata - Transposing and Where Criteria -


i wondering if there more efficient of writing code below (which not work). trying transpose data set, want values dogs , cats greater 1. in group has both cat , dogs.

the code below not work, attempt pull base on above statement. please feel free modify codes below and/or provide better codes. in advance!

    select      ,group_id     ,sum(case when product = '18' 1 else 0 end) "dogs"     ,sum(case when product = '20' 1 else 0 end) "cats"      risk_bl      dogs > 1 , cats > 1      group 1 

try using having clause:

select  ,group_id ,sum(case when product = '18' 1 else 0 end) "dogs" ,sum(case when product = '20' 1 else 0 end) "cats"  risk_bl group 1 having sum(case when product = '18' 1 else 0 end) > 1  , sum(case when product = '20' 1 else 0 end)> 1 

as dnoeth pointed out, teradata allows use aliases in having clause (among other things) having clause read:

 having dogs > 1 , cats > 1 

the having clause applies after grouping , aggregation, think want.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -