SQL account how to do sum and subtraction

1

I'm starting to learn SQL need to make an account, I have a select for a report where I need to make an account to show another value in the fields of that report and formula can not appear on it.

Query:

SELECT  
    application_name, 
    sum(cancellation_total) as cancellation,
    sum(active_base_total) as active_base, 
    sum(new_subscriber_total)as new_subscriber,
    inserted_date
from report.dashboard_daily_igpm 
where carrier_id IN (122)
   and inserted_date >= DateAdd(mm, DateDiff(mm,0,GetDate()-1) - 0, 0)
  '''

The account should be this:

 Base (Dia 1) = Base (Dia -1) + Altas (Dia 1) - Bajas (Dia 1)

sum(active_base_total)=sum(active_base_total)+sum(new_subscriber_total)- sum(cancellation_total)

Could someone please help me?

    
asked by anonymous 23.03.2018 / 12:31

1 answer

1

Do so

SELECT  
    application_name, 
    sum(cancellation_total) as cancellation,
    sum(active_base_total) as active_base, 
    sum(new_subscriber_total)as new_subscriber,
    sum(active_base_total)+sum(new_subscriber_total)- sum(cancellation_total) as nome_da_formula
    inserted_date
from report.dashboard_daily_igpm 
where carrier_id IN (122)
   and inserted_date >= DateAdd(mm, DateDiff(mm,0,GetDate()-1) - 0, 0)
    
23.03.2018 / 12:51