Q:

Sum of non repeated customer values until date

I have a list consisting of date and all customer's statuses for each date (one field for active and another for inactive)
How can I get a count per flag of non repeated customers until a given calendar date?
calendar_date   customer_uid    active_flag     inactive_flag
2016-09-10          500             1               0
2016-09-10          501             0               0
2016-09-10          509             1               0
2016-09-11          509             1               0
2016-09-11          500             1               0
2016-09-11          501             0               0
2016-09-12          500             1               0
2016-09-12          501             1               0
2016-09-12          509             1               0
2016-09-13          500             0               1
2016-09-13          501             1               0
2016-09-13          509             1               0
2016-09-14          500             0               1
2016-09-14          501             1               0
2016-09-14          509             0               1

The result would be like this:
calendar_date   active_flag     inactive_flag
2016-09-10          2               0
2016-09-11          2               0
2016-09-12          3               0
2016-09-13          2               1
2016-09-14          1               2

A:

You need to use SUM function and GROUP BY
SELECT calendar_date,SUM(active_flag) active_flag,SUM(inactive_flag) inactive_flag 
FROM T
GROUP BY calendar_date

If active_flag and inactive_flag state are more than two
you can use case when expression with aggregate function.
SELECT calendar_date,
       COUNT(CASE WHEN active_flag = 1 THEN 1 END) active_flag,
       COUNT(CASE WHEN inactive_flag = 1 THEN 1 END) inactive_flag 
FROM T
GROUP BY calendar_date

