склеивались в одну?
SELECT COUNT("Id") AS reached, date_trunc('day', "OccurredOn") AS period
FROM events."Events"
WHERE "Event" = 'RobotCdrReceived' AND "Payload"::JSONB ->> 'BillSec' > '0'
GROUP BY period
UNION ALL
SELECT COUNT("Id") AS cancelled, date_trunc('day', "OccurredOn") AS period
FROM events."Events"
WHERE "Event" = 'RobotCdrReceived' AND "Payload"::JSONB ->> 'BillSec' = '0'
AND (date_trunc('day', "OccurredOn") BETWEEN '2018-01-27' AND '2018-02-07')
GROUP BY period ORDER BY period DESC;
т.е. reached и cancelled должны быть разными колонками
А получиться-то что должно?
Может тебе join нужен?
Не надо union, надо либо join, как уже сказали, либо CASE
SELECT count("Id") FILTER(WHERE "Payload"::JSONB -» 'BillSec' > '0') as reached, count("Id") FILTER(WHERE "Payload"::JSONB -» 'BillSec' = '0') as cancelled, date_trunc('day', "OccurredOn") AS period FROM events."Events" WHERE "Event" = 'RobotCdrReceived' AND (date_trunc('day', "OccurredOn") BETWEEN '2018-01-27' AND '2018-02-07') GROUP BY period ORDER BY period DESC если правильно понял задачу, можно сделать так. подсчитать отдельно count'ы по подусловиям
Обсуждают сегодня