С условным агрегированием:
select date(created_utc),
count(case when isMnp = 0 and isEsim = 0 then 1 end) SIM,
count(case when isMnp = 1 and isEsim = 0 then 1 end) MNP,
count(case when isMnp = 0 and isEsim = 1 then 1 end) eSIM,
count(case when isMnp = 1 and isEsim = 1 then 1 end) "eSIM-MNP"
from "Order"
where status = 'completed' and date(created_utc) >= '2020-04-25'
group by date(created_utc)
Если столбцы isMnp
и isEsim
равны boolean
, используйте это:
select date(created_utc),
count(case when not isMnp and isEsim then 1 end) SIM,
count(case when isMnp and not isEsim then 1 end) MNP,
count(case when not isMnp and isEsim then 1 end) eSIM,
count(case when isMnp and isEsim then 1 end) "eSIM-MNP"
from "Order"
where status = 'completed' and date(created_utc) >= '2020-04-25'
group by date(created_utc)