我想要聚合表中的每個應用統計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