Home > Net >  Select sum of multiple columns based on the conditions
Select sum of multiple columns based on the conditions

Time:10-15

I want to find addition of low_cvt,med_cvt and high_cvt based on the unique idCampaign. for example in the screenshot, idcampaign 3870576 is repeating twice and it's addition is 12.

Screenshot: https://imgur.com/a/xES9yp2

I am using following statement in select statement:

  CVT.low_cvt   CVT.med_cvt   CVT.high_cvt   CVT.other_cvt AS 'All CVT', 

however, it is giving duplicate idcampaign.

Thanks, Sameer

CodePudding user response:

try a query like this:

SELECT CVT.idcampaign,
       SUM(CVT.low_cvt CVT.med_cvt CVT.high_cvt CVT.other_cvt) AS 'All CVT'
FROM Your_Table AS CVT
WHERE CVT.idcampaign = 3870576
GROUP BY CVT.idcampaign;
  • Related