update sqlc gen

This commit is contained in:
Pavel 2024-03-17 20:28:55 +03:00
parent cd4fd47196
commit 469ccf80e2
2 changed files with 71 additions and 59 deletions

@ -536,30 +536,36 @@ WITH Funnel AS (
), ),
Questions AS ( Questions AS (
SELECT SELECT
q.id,
q.title AS question_title, q.title AS question_title,
a.content AS answer_content, NULL AS answer_content,
CAST(COUNT(*) * 100.0 / NULLIF(q.total_answers, 0) AS INTEGER) AS percentage CAST(COUNT(*) * 100.0 / NULLIF(q.total_answers, 0) AS INTEGER) AS percentage
FROM FROM
answer a answer a
JOIN ( JOIN (
SELECT q.id, q.title, COUNT(*) AS total_answers SELECT
FROM question q q.id,
JOIN answer a ON q.id = a.question_id q.title,
WHERE a.quiz_id = $1 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($2)
AND a.created_at <= TO_TIMESTAMP($3) AND a.created_at <= TO_TIMESTAMP($3)
GROUP BY q.id, q.title GROUP BY
q.id, q.title
) q ON a.question_id = q.id ) q ON a.question_id = q.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)
GROUP BY GROUP BY
q.id, q.title, a.content, q.total_answers q.title, q.total_answers
HAVING HAVING
COUNT(*) >= 1 COUNT(*) >= 1
) )
SELECT SELECT
Funnel.count_start_false, Funnel.count_start_false,
Funnel.count_start_true, Funnel.count_start_true,

@ -1630,30 +1630,36 @@ WITH Funnel AS (
), ),
Questions AS ( Questions AS (
SELECT SELECT
q.id,
q.title AS question_title, q.title AS question_title,
a.content AS answer_content, NULL AS answer_content,
CAST(COUNT(*) * 100.0 / NULLIF(q.total_answers, 0) AS INTEGER) AS percentage CAST(COUNT(*) * 100.0 / NULLIF(q.total_answers, 0) AS INTEGER) AS percentage
FROM FROM
answer a answer a
JOIN ( JOIN (
SELECT q.id, q.title, COUNT(*) AS total_answers SELECT
FROM question q q.id,
JOIN answer a ON q.id = a.question_id q.title,
WHERE a.quiz_id = $1 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($2)
AND a.created_at <= TO_TIMESTAMP($3) AND a.created_at <= TO_TIMESTAMP($3)
GROUP BY q.id, q.title GROUP BY
q.id, q.title
) q ON a.question_id = q.id ) q ON a.question_id = q.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)
GROUP BY GROUP BY
q.id, q.title, a.content, q.total_answers q.title, q.total_answers
HAVING HAVING
COUNT(*) >= 1 COUNT(*) >= 1
) )
SELECT SELECT
Funnel.count_start_false, Funnel.count_start_false,
Funnel.count_start_true, Funnel.count_start_true,
@ -1686,7 +1692,7 @@ type QuestionsStatisticsRow struct {
ResultsTitle string `db:"results_title" json:"results_title"` ResultsTitle string `db:"results_title" json:"results_title"`
ResultsPercentage int32 `db:"results_percentage" json:"results_percentage"` ResultsPercentage int32 `db:"results_percentage" json:"results_percentage"`
QuestionsTitle string `db:"questions_title" json:"questions_title"` QuestionsTitle string `db:"questions_title" json:"questions_title"`
AnswerContent sql.NullString `db:"answer_content" json:"answer_content"` AnswerContent interface{} `db:"answer_content" json:"answer_content"`
QuestionsPercentage int32 `db:"questions_percentage" json:"questions_percentage"` QuestionsPercentage int32 `db:"questions_percentage" json:"questions_percentage"`
} }