简体   繁体   中英

SQL - add new column based off of existing column value (1 row)

Data:

在此处输入图像描述

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

在此处输入图像描述

Any suggestions please?

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM