Sql- Count distinct values from date-30days to current register's date -


i have 1 table named "transactions" following columns: date, clientid, amount.

i have active clients in last 30 days.

something this:

date        |    active_clients 2017/08/10  |      697 2017/08/11  |      710 2017/08/12  |      689 

etc

meaning: 2017/08/10 minus 30 days 2017/08/10 had 697 active users.

i tryed many ways , didnt make it.

one method looks this:

select d.dte, count(distinct t.clientid) (select '2017-08-10' dte union       select '2017-08-11' dte union       select '2017-08-12' dte       ) d left join      transactions t      on t.date <= d.dte , t.date > d.dte - interval '30' day group d.dte order d.dte; 

the exact syntax date constants, date arithmetic, , subqueries constant values differs database.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -