Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CASE
- WHEN col1 > col2 THEN SUM(col3*col4)
- ELSE 0
- END AS some_product
- select ...
- from (select ... , CASE WHEN col1 > col2 THEN SUM(col3*col4) ELSE 0 END AS some_product
- from ...
- group by col1, col2 ... ) T
- group by some_product ...
- with T as (select ... , CASE WHEN col1 > col2 THEN SUM(col3*col4) ELSE 0 END AS some_product
- from ...
- group by col1, col2 ... )
- select ...
- from T
- group by some_product ...
- Select Sum(Case When col1 > col2 Then col3*col4 Else 0 End) as SumSomeProduct
- From ...
- Group By Case When col1 > col2 Then col3*col4 Else 0 End
- Select SumSomeProduct, Count(*), <other aggregate functions>
- From (Select <other columns you are grouping By>,
- Sum(Case When col1 > col2
- Then col3*col4 Else 0 End) as SumSomeProduct
- From Table
- Group By <Other Columns> ) As Z
- Group by SumSomeProduct
Add Comment
Please, Sign In to add comment