は、私は、テーブル内の各アプリの統計情報を集約したい戻る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