update sqlc gen
This commit is contained in:
parent
cb6dafbc2b
commit
00496d9006
@ -500,21 +500,37 @@ WITH Funnel AS (
|
|||||||
AND a.created_at >= TO_TIMESTAMP($2)
|
AND a.created_at >= TO_TIMESTAMP($2)
|
||||||
AND a.created_at <= TO_TIMESTAMP($3)
|
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 (
|
Results AS (
|
||||||
SELECT
|
SELECT
|
||||||
q.title AS question_title,
|
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
|
FROM
|
||||||
answer a
|
answer a
|
||||||
JOIN
|
JOIN
|
||||||
question q ON a.question_id = q.id
|
question q ON a.question_id = q.id
|
||||||
|
JOIN
|
||||||
|
TotalAnswers ta ON q.id = ta.question_id
|
||||||
WHERE
|
WHERE
|
||||||
a.quiz_id = $1
|
a.quiz_id = $1
|
||||||
AND a.created_at >= TO_TIMESTAMP($2)
|
AND a.created_at >= TO_TIMESTAMP($2)
|
||||||
AND a.created_at <= TO_TIMESTAMP($3)
|
AND a.created_at <= TO_TIMESTAMP($3)
|
||||||
AND a.result = TRUE
|
AND a.result = TRUE
|
||||||
GROUP BY
|
GROUP BY
|
||||||
q.id, q.title
|
q.id, q.title, ta.total_answers
|
||||||
HAVING
|
HAVING
|
||||||
COUNT(*) >= 1
|
COUNT(*) >= 1
|
||||||
),
|
),
|
||||||
|
@ -1594,21 +1594,37 @@ WITH Funnel AS (
|
|||||||
AND a.created_at >= TO_TIMESTAMP($2)
|
AND a.created_at >= TO_TIMESTAMP($2)
|
||||||
AND a.created_at <= TO_TIMESTAMP($3)
|
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 (
|
Results AS (
|
||||||
SELECT
|
SELECT
|
||||||
q.title AS question_title,
|
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
|
FROM
|
||||||
answer a
|
answer a
|
||||||
JOIN
|
JOIN
|
||||||
question q ON a.question_id = q.id
|
question q ON a.question_id = q.id
|
||||||
|
JOIN
|
||||||
|
TotalAnswers ta ON q.id = ta.question_id
|
||||||
WHERE
|
WHERE
|
||||||
a.quiz_id = $1
|
a.quiz_id = $1
|
||||||
AND a.created_at >= TO_TIMESTAMP($2)
|
AND a.created_at >= TO_TIMESTAMP($2)
|
||||||
AND a.created_at <= TO_TIMESTAMP($3)
|
AND a.created_at <= TO_TIMESTAMP($3)
|
||||||
AND a.result = TRUE
|
AND a.result = TRUE
|
||||||
GROUP BY
|
GROUP BY
|
||||||
q.id, q.title
|
q.id, q.title, ta.total_answers
|
||||||
HAVING
|
HAVING
|
||||||
COUNT(*) >= 1
|
COUNT(*) >= 1
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user