From 00496d90068ce8028be37ca8bebc10fdf97c2ba8 Mon Sep 17 00:00:00 2001 From: Pavel Date: Sun, 17 Mar 2024 18:35:54 +0300 Subject: [PATCH] update sqlc gen --- dal/db_query/queries.sql | 20 ++++++++++++++++++-- dal/sqlcgen/queries.sql.go | 20 ++++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/dal/db_query/queries.sql b/dal/db_query/queries.sql index d80e17d..76351a2 100644 --- a/dal/db_query/queries.sql +++ b/dal/db_query/queries.sql @@ -500,21 +500,37 @@ WITH Funnel AS ( AND a.created_at >= TO_TIMESTAMP($2) AND a.created_at <= TO_TIMESTAMP($3) ), + TotalAnswers AS ( + SELECT + q.id AS question_id, + COUNT(*) AS total_answers + FROM + question q + JOIN answer a ON q.id = a.question_id + WHERE + a.quiz_id = $1 + AND a.created_at >= TO_TIMESTAMP($2) + AND a.created_at <= TO_TIMESTAMP($3) + GROUP BY + q.id + ), Results AS ( SELECT q.title AS question_title, - COUNT(*)::FLOAT / NULLIF(SUM(COUNT(*)) FILTER (WHERE a.result = TRUE), 0) AS percentage + COUNT(*)::FLOAT / NULLIF(ta.total_answers, 0) AS percentage FROM answer a JOIN question q ON a.question_id = q.id + JOIN + TotalAnswers ta ON q.id = ta.question_id WHERE a.quiz_id = $1 AND a.created_at >= TO_TIMESTAMP($2) AND a.created_at <= TO_TIMESTAMP($3) AND a.result = TRUE GROUP BY - q.id, q.title + q.id, q.title, ta.total_answers HAVING COUNT(*) >= 1 ), diff --git a/dal/sqlcgen/queries.sql.go b/dal/sqlcgen/queries.sql.go index f176a43..5c65a33 100644 --- a/dal/sqlcgen/queries.sql.go +++ b/dal/sqlcgen/queries.sql.go @@ -1594,21 +1594,37 @@ WITH Funnel AS ( AND a.created_at >= TO_TIMESTAMP($2) AND a.created_at <= TO_TIMESTAMP($3) ), + TotalAnswers AS ( + SELECT + q.id AS question_id, + COUNT(*) AS total_answers + FROM + question q + JOIN answer a ON q.id = a.question_id + WHERE + a.quiz_id = $1 + AND a.created_at >= TO_TIMESTAMP($2) + AND a.created_at <= TO_TIMESTAMP($3) + GROUP BY + q.id + ), Results AS ( SELECT q.title AS question_title, - COUNT(*)::FLOAT / NULLIF(SUM(COUNT(*)) FILTER (WHERE a.result = TRUE), 0) AS percentage + COUNT(*)::FLOAT / NULLIF(ta.total_answers, 0) AS percentage FROM answer a JOIN question q ON a.question_id = q.id + JOIN + TotalAnswers ta ON q.id = ta.question_id WHERE a.quiz_id = $1 AND a.created_at >= TO_TIMESTAMP($2) AND a.created_at <= TO_TIMESTAMP($3) AND a.result = TRUE GROUP BY - q.id, q.title + q.id, q.title, ta.total_answers HAVING COUNT(*) >= 1 ),