Home > Blockchain >  Div0 with case when in sql
Div0 with case when in sql

Time:03-12

I would like to transform this row code sql :

div0(COL1,COL2) * 100 AS NEW_COL,

by integrating a case when with a condition on date:

div0(CASE WHEN COL1='2022-03-11' THEN (COL1,COL2) ELSE 0 END) AS NEW_COL

Thanks in advance for you help

CodePudding user response:

Because div0 is a function you can try to use div0 function in CASE WHEN expression.

(CASE WHEN COL1='2022-03-11' THEN div0(COL1,COL2) ELSE 0 END) AS NEW_COL

CodePudding user response:

If the goal is to be used as conditional aggregation then:

SELECT SUM(IFF(COLX='2022-03-11', DIV0(COL1, COL2), 0)) 
FROM tab;
  • Related