SQL account how to sum and subtract

Asked

Viewed 1,962 times

1

I’m starting to learn SQL I need to do an account, I have a select for a report where I need to do an account to show another value in the fields in that report and the formula cannot appear in that report.

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 must be:

 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 help me, please?

1 answer

2


Do it like this

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)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.