Я хочу посчитать количество контрактов для каждого типа контракта в начале каждого месяца. Есть ли способ сделать это вместо 12 операторов выбора с объединением?
select count(distinct c.contract_no), c.contract_type, to_date('01.01.2020','dd.mm.yyyy') as
contr_date, to_char(to_date('01.01.2020','dd.mm.yyyy'),'YYMM') as periode
from contracts c
where 1=1
and c.contract_start <= '01.01.2020'
and (c.contract_end >= '01.01.2020' or c.contract_end is null)
group by c.contract_type
union
select count(distinct c.contract_no), c.contract_type, to_date('01.02.2020','dd.mm.yyyy') as
contr_date, to_char(to_date('01.02.2020','dd.mm.yyyy'),'YYMM') as periode
from contracts c
where 1=1
and c.contract_start <= '01.02.2020'
and (c.contract_end >= '01.02.2020' or c.contract_end is null)
group by c.contract_type
et c. ;