Home > front end >  SQL - add new column based off of existing column value (1 row)
SQL - add new column based off of existing column value (1 row)

Time:08-10

Data:

enter image description here

Final result I intend to obtain is i.e, a new column 'payOff' has to be added and set to 'Y' when ss_use_TYPE='delta'

enter image description here

Any suggestions please ?

CodePudding user response:

One approach uses aggregation:

SELECT SUM(Sum) AS Sum, ss_source, case_id,
       CASE WHEN COUNT(CASE WHEN ss_use_type = 'delta' THEN 1 END) > 0
            THEN 'Y' ELSE 'N' END AS payoff
FROM yourTable
GROUP BY ss_source, case_id;
  • Related