Question: If a user win Puzzle Game Level than I make a Toast "You Win Play Next Level" and then I want to show rewarded video ads.

What code will be there to show Admob Rewarded Video Ads after Toast in android studio?

```
    if (isSolved())
        Toast.makeText(context, "You Win ! Play Next Level", Toast.LENGTH_LONG).show();

```

Answer: 
You can use aggregation and a cumulative sum -- after unpivoting the data:

```
with d as (
      select validfrom as dte, 1 as inc
      from t
      union all
      select validto, -1
      from t
     )
select dte, sum(sum(inc)) over (order by dte)
from d
group by dte
order by dte;

```

Note: This assumes that the `validto` date is not included. If you want it included, then add "1" to it.

EDIT:

If you only need the results for those two dates, then use:

```
select v.dte,
       (select count(*) 
        from t
        where t.validfrom <= v.dte and t.validto >= t.validto
       ) as cnt
from (values ('2020-01-01'), ('2020-01-02')) v(dte);

```
An easy ways is to build a date table and then count how many employee (or customer) were in that particular date.

```
;with t as (   -- this is your table/Dimension
    select pk,EmployeeNo,Building,ValidFrom,ValidTo 
    from (values (1, 1, 'a', '2000-01-01', '2008-06-01'),
                 (2, 1, 'b', '2008-06-01', '2010-06-01'),
                 (3, 1, 'c', '2010-06-01', '2011-08-01'),
                 (4, 2, 'a', '2000-01-01', '2008-06-01'),
                 (5, 2, 'b', '2008-06-01', '2010-06-01'),
                 (6, 2, 'c', '2010-06-01', '2011-08-01')
        )t (pk,EmployeeNo,Building,ValidFrom,ValidTo)
)
, dates as ( -- this is a recursive query, building a date table from 2000-01-01 up to today
    select convert(date, '2000-01-01') as d
    union all
    select DATEADD(d,1,d) 
    from dates 
    where d < getdate()-1
)
select d.d, count(1) as [Employe count]  
from dates d
inner join t on d.d between t.ValidFrom and t.ValidTo -- will join only valid employee
group by d.d 
option (maxrecursion 0)  -- since our dates table recurse over more than 100 times and the dataset is fairly small, you need this option

```