Amruta Raut Amruta Raut - 5 months ago 48
SQL Question

How to get duplicate substring and add remaining attach integer value of substring in DB2 sql

My scenario is that i have duplicate substring with string in column like


|QWERT-1 |

|QWERT-3 |


I want to get outout column as like


| 16 |

i.e addition of 1+3+12 of duplicate substring(QWERT)and QWERT set as column name

How can I do it using DB2 SQL

Answer Source

Try this:

SELECT SUM(CAST(SUBSTR(t.YourColumn, LOCATE('-',t.YourColumn)+1) as INT)) as sum_total
FROM YourTable t
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download