update sqlc gen

This commit is contained in:
Pavel 2024-03-17 18:35:54 +03:00
parent cb6dafbc2b
commit 00496d9006
2 changed files with 36 additions and 4 deletions

@ -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
),

@ -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
),