Query to find the "Number of days" a customer has an active card between a specified interval
I think I have found a good solution for this.
Could you tell me if there are better ways other than this one?
select a.customer_num, count(distinct b.datekey) num_of_days
  from (select t.customer_num,
               t.card_number,
               t.card_issue_date,
               t.card_expire_date
          from test_table t
         where t.card_issue_date &lt;= to_date('1/31/2020', 'mm/dd/yyyy')
           and t.card_expire_date &gt;= to_date('1/1/2020', 'mm/dd/yyyy')) a
 inner join dimdate b
    on b.datekey between a.card_issue_date and a.card_expire_date
   and b.datekey between to_date('1/1/2020', 'mm/dd/yyyy') and
       to_date('1/31/2020', 'mm/dd/yyyy')
 group by a.customer_num