update sqlc gen

This commit is contained in:
Pavel 2024-03-17 22:21:12 +03:00
parent d95d690cbe
commit 5f596d7358
2 changed files with 33 additions and 49 deletions

@ -500,30 +500,22 @@ WITH Funnel AS (
AND a.created_at <= TO_TIMESTAMP($3)
),
Results AS (
SELECT
q.title AS question_title,
COUNT(*) AS total_answers,
CAST(
COUNT(CASE WHEN a.result = TRUE THEN 1 ELSE NULL END) * 100.0 / NULLIF(SUM(COUNT(CASE WHEN a.result = TRUE THEN 1 ELSE NULL END)) OVER (PARTITION BY q.id), 0) AS FLOAT8
) AS percentage
FROM
answer a
JOIN question q ON a.question_id = q.id
WHERE
a.quiz_id = $1
AND a.created_at >= TO_TIMESTAMP($2)
AND a.created_at <= TO_TIMESTAMP($3)
AND q.id IN (
SELECT DISTINCT a.question_id
FROM answer a
WHERE a.quiz_id = $1
AND a.result = TRUE
)
GROUP BY
q.id, q.title
HAVING
COUNT(*) >= 1
),
SELECT
q.title AS question_title,
COUNT(*) AS total_answers,
COUNT(*) * 100.0 / NULLIF(SUM(COUNT(*)) FILTER (WHERE a.result = TRUE) OVER (PARTITION BY a.quiz_id), 0) AS percentage
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.title, a.quiz_id
HAVING
COUNT(*) >= 1
),
Questions AS (
SELECT
q.title AS question_title,

@ -1594,30 +1594,22 @@ WITH Funnel AS (
AND a.created_at <= TO_TIMESTAMP($3)
),
Results AS (
SELECT
q.title AS question_title,
COUNT(*) AS total_answers,
CAST(
COUNT(CASE WHEN a.result = TRUE THEN 1 ELSE NULL END) * 100.0 / NULLIF(SUM(COUNT(CASE WHEN a.result = TRUE THEN 1 ELSE NULL END)) OVER (PARTITION BY q.id), 0) AS FLOAT8
) AS percentage
FROM
answer a
JOIN question q ON a.question_id = q.id
WHERE
a.quiz_id = $1
AND a.created_at >= TO_TIMESTAMP($2)
AND a.created_at <= TO_TIMESTAMP($3)
AND q.id IN (
SELECT DISTINCT a.question_id
FROM answer a
WHERE a.quiz_id = $1
AND a.result = TRUE
)
GROUP BY
q.id, q.title
HAVING
COUNT(*) >= 1
),
SELECT
q.title AS question_title,
COUNT(*) AS total_answers,
COUNT(*) * 100.0 / NULLIF(SUM(COUNT(*)) FILTER (WHERE a.result = TRUE) OVER (PARTITION BY a.quiz_id), 0) AS percentage
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.title, a.quiz_id
HAVING
COUNT(*) >= 1
),
Questions AS (
SELECT
q.title AS question_title,
@ -1667,7 +1659,7 @@ type QuestionsStatisticsRow struct {
CountFResultWithTQuestion int64 `db:"count_f_result_with_t_question" json:"count_f_result_with_t_question"`
CountTResult int64 `db:"count_t_result" json:"count_t_result"`
ResultsTitle string `db:"results_title" json:"results_title"`
ResultsPercentage float64 `db:"results_percentage" json:"results_percentage"`
ResultsPercentage int32 `db:"results_percentage" json:"results_percentage"`
QuestionsTitle string `db:"questions_title" json:"questions_title"`
AnswerContent sql.NullString `db:"answer_content" json:"answer_content"`
QuestionsPercentage float64 `db:"questions_percentage" json:"questions_percentage"`