Как совместить несколько условий - PullRequest
0 голосов
/ 29 апреля 2020

Уважаемые

я пытаюсь изменить приведенные ниже запросы, чтобы этот результат был прикреплен к таблице, если кто-то может мне помочь

  • Мне нужно использовать утверждение случая или если я думаю, что утверждение

query

enter image description here

заранее спасибо,

1 Ответ

0 голосов
/ 29 апреля 2020

С условным агрегированием:

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)
...