我想要聚合表中的每个应用统计apps
汇总列返回零
我有以下查询,但由于某些原因,所有的结果返回0
select
a.id,
'support' as domain,
'summary' as type,
90 as interval,
json_build_object(
'new', count(new),
'closed', count(closed_c),
'reply_rate', count(reply_rate),
'median_response', max(median_response.response_time)
) as data
from apps a
full join (
SELECT * from conversations c
WHERE c.started_at::date > (current_date - (90 || ' days')::interval)::date
) as new on new.app_id = a.id
full join (
SELECT * from conversations c
WHERE c.closed_at::date > (current_date - (90 || ' days')::interval)::date
) as closed_c on closed_c.app_id = a.id
full join (
SELECT * from conversations c
WHERE c.started_at::date > (current_date - (90 || ' days')::interval)::date AND c.first_response_at is not null
) as reply_rate on reply_rate.app_id = a.id
full join (
SELECT c.app_id, extract(epoch from (c.first_response_at - c.started_at)) as response_time, ntile(2) OVER (ORDER BY (c.first_response_at - c.started_at)) AS bucket FROM conversations c
WHERE c.started_at::date > (current_date - (90 || ' days')::interval)::date AND c.first_response_at is not null
) as median_response on median_response.app_id = a.id
where a.test = false
group by a.id
'max(median_response.response_time)'也返回0吗?你是否获得了'a.id'的值?你会得到子查询记录吗?他们是否正确加入?这些聚合是否在'json_build_object()'之外工作?如果你改变为'Count(new。*)'而不是'Count(new)'? – JNevill
那个返回'null'。我正在获取'a.id'的值。子查询应该返回记录?他们在外面工作。不改变任何东西 – Tarlen
聚合公式在'json_build_object()'之外工作吗?这真的让事情变窄了! – JNevill