diff --git a/dal/db_query/queries.sql b/dal/db_query/queries.sql index cb1f07f..4236a0e 100644 --- a/dal/db_query/queries.sql +++ b/dal/db_query/queries.sql @@ -538,14 +538,13 @@ WITH Funnel AS ( SELECT q.title AS question_title, a.content AS answer_content, - CAST(COUNT(*) * 100.0 / NULLIF(q.total_answers, 0) AS INTEGER) AS percentage + CAST(COUNT(*) * 100.0 / NULLIF(SUM(COUNT(*)) OVER (PARTITION BY q.id), 0) AS INTEGER) AS percentage FROM answer a JOIN ( SELECT q.id, - q.title, - COUNT(*) AS total_answers + q.title FROM question q JOIN @@ -562,7 +561,7 @@ WITH Funnel AS ( AND a.created_at >= TO_TIMESTAMP($2) AND a.created_at <= TO_TIMESTAMP($3) GROUP BY - q.title, a.content, q.total_answers + q.title, a.content, q.id HAVING COUNT(*) >= 1 ) diff --git a/dal/sqlcgen/queries.sql.go b/dal/sqlcgen/queries.sql.go index 3363863..fbcd217 100644 --- a/dal/sqlcgen/queries.sql.go +++ b/dal/sqlcgen/queries.sql.go @@ -1632,14 +1632,13 @@ WITH Funnel AS ( SELECT q.title AS question_title, a.content AS answer_content, - CAST(COUNT(*) * 100.0 / NULLIF(q.total_answers, 0) AS INTEGER) AS percentage + CAST(COUNT(*) * 100.0 / NULLIF(SUM(COUNT(*)) OVER (PARTITION BY q.id), 0) AS INTEGER) AS percentage FROM answer a JOIN ( SELECT q.id, - q.title, - COUNT(*) AS total_answers + q.title FROM question q JOIN @@ -1656,7 +1655,7 @@ WITH Funnel AS ( AND a.created_at >= TO_TIMESTAMP($2) AND a.created_at <= TO_TIMESTAMP($3) GROUP BY - q.title, a.content, q.total_answers + q.title, a.content, q.id HAVING COUNT(*) >= 1 )