update sqlc gen

This commit is contained in:
Pavel 2024-03-17 19:23:42 +03:00
parent e2ae058c47
commit 153d15351a
2 changed files with 71 additions and 55 deletions

@ -518,7 +518,10 @@ WITH Funnel AS (
SELECT SELECT
q.title AS question_title, q.title AS question_title,
ta.total_answers, ta.total_answers,
COUNT(*)::FLOAT / NULLIF(ta.total_answers, 0) AS percentage CASE
WHEN ta.total_answers = 0 THEN NULL
ELSE COUNT(*)::FLOAT / NULLIF(ta.total_answers, 0)
END AS percentage
FROM FROM
answer a answer a
JOIN JOIN
@ -536,31 +539,34 @@ WITH Funnel AS (
COUNT(*) >= 1 COUNT(*) >= 1
), ),
Questions AS ( Questions AS (
SELECT SELECT
q.id, q.id,
q.title AS question_title, q.title AS question_title,
a.content AS answer_content, a.content AS answer_content,
CAST(COUNT(*)::FLOAT / NULLIF(q.total_answers, 0) AS INTEGER) AS percentage CASE
FROM WHEN q.total_answers = 0 THEN NULL
answer a ELSE COUNT(*)::FLOAT / NULLIF(q.total_answers, 0)
JOIN ( END AS percentage
SELECT q.id, q.title, COUNT(*) AS total_answers FROM
FROM question q answer a
JOIN answer a ON q.id = a.question_id JOIN (
WHERE a.quiz_id = $1 SELECT q.id, q.title, COUNT(*) AS total_answers
AND a.created_at >= TO_TIMESTAMP($2) FROM question q
AND a.created_at <= TO_TIMESTAMP($3) JOIN answer a ON q.id = a.question_id
GROUP BY q.id, q.title WHERE a.quiz_id = $1
) q ON a.question_id = q.id AND a.created_at >= TO_TIMESTAMP($2)
WHERE AND a.created_at <= TO_TIMESTAMP($3)
a.quiz_id = $1 GROUP BY q.id, q.title
AND a.created_at >= TO_TIMESTAMP($2) ) q ON a.question_id = q.id
AND a.created_at <= TO_TIMESTAMP($3) WHERE
GROUP BY a.quiz_id = $1
q.id, q.title, a.content, q.total_answers AND a.created_at >= TO_TIMESTAMP($2)
HAVING AND a.created_at <= TO_TIMESTAMP($3)
COUNT(*) >= 1 GROUP BY
) q.id, q.title, a.content, q.total_answers
HAVING
COUNT(*) >= 1
)
SELECT SELECT
Funnel.count_start_false, Funnel.count_start_false,
Funnel.count_start_true, Funnel.count_start_true,
@ -575,4 +581,6 @@ SELECT
FROM FROM
Funnel, Funnel,
Results, Results,
Questions; Questions
WHERE
Questions.percentage >= 1;

@ -1612,7 +1612,10 @@ WITH Funnel AS (
SELECT SELECT
q.title AS question_title, q.title AS question_title,
ta.total_answers, ta.total_answers,
COUNT(*)::FLOAT / NULLIF(ta.total_answers, 0) AS percentage CASE
WHEN ta.total_answers = 0 THEN NULL
ELSE COUNT(*)::FLOAT / NULLIF(ta.total_answers, 0)
END AS percentage
FROM FROM
answer a answer a
JOIN JOIN
@ -1630,31 +1633,34 @@ WITH Funnel AS (
COUNT(*) >= 1 COUNT(*) >= 1
), ),
Questions AS ( Questions AS (
SELECT SELECT
q.id, q.id,
q.title AS question_title, q.title AS question_title,
a.content AS answer_content, a.content AS answer_content,
CAST(COUNT(*)::FLOAT / NULLIF(q.total_answers, 0) AS INTEGER) AS percentage CASE
FROM WHEN q.total_answers = 0 THEN NULL
answer a ELSE COUNT(*)::FLOAT / NULLIF(q.total_answers, 0)
JOIN ( END AS percentage
SELECT q.id, q.title, COUNT(*) AS total_answers FROM
FROM question q answer a
JOIN answer a ON q.id = a.question_id JOIN (
WHERE a.quiz_id = $1 SELECT q.id, q.title, COUNT(*) AS total_answers
AND a.created_at >= TO_TIMESTAMP($2) FROM question q
AND a.created_at <= TO_TIMESTAMP($3) JOIN answer a ON q.id = a.question_id
GROUP BY q.id, q.title WHERE a.quiz_id = $1
) q ON a.question_id = q.id AND a.created_at >= TO_TIMESTAMP($2)
WHERE AND a.created_at <= TO_TIMESTAMP($3)
a.quiz_id = $1 GROUP BY q.id, q.title
AND a.created_at >= TO_TIMESTAMP($2) ) q ON a.question_id = q.id
AND a.created_at <= TO_TIMESTAMP($3) WHERE
GROUP BY a.quiz_id = $1
q.id, q.title, a.content, q.total_answers AND a.created_at >= TO_TIMESTAMP($2)
HAVING AND a.created_at <= TO_TIMESTAMP($3)
COUNT(*) >= 1 GROUP BY
) q.id, q.title, a.content, q.total_answers
HAVING
COUNT(*) >= 1
)
SELECT SELECT
Funnel.count_start_false, Funnel.count_start_false,
Funnel.count_start_true, Funnel.count_start_true,
@ -1670,6 +1676,8 @@ FROM
Funnel, Funnel,
Results, Results,
Questions Questions
WHERE
Questions.percentage >= 1
` `
type QuestionsStatisticsParams struct { type QuestionsStatisticsParams struct {
@ -1685,10 +1693,10 @@ type QuestionsStatisticsRow struct {
CountTStartWithTQuestion int64 `db:"count_t_start_with_t_question" json:"count_t_start_with_t_question"` CountTStartWithTQuestion int64 `db:"count_t_start_with_t_question" json:"count_t_start_with_t_question"`
CountTResult int64 `db:"count_t_result" json:"count_t_result"` CountTResult int64 `db:"count_t_result" json:"count_t_result"`
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 interface{} `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 sql.NullString `db:"answer_content" json:"answer_content"`
QuestionsPercentage int32 `db:"questions_percentage" json:"questions_percentage"` QuestionsPercentage interface{} `db:"questions_percentage" json:"questions_percentage"`
} }
func (q *Queries) QuestionsStatistics(ctx context.Context, arg QuestionsStatisticsParams) ([]QuestionsStatisticsRow, error) { func (q *Queries) QuestionsStatistics(ctx context.Context, arg QuestionsStatisticsParams) ([]QuestionsStatisticsRow, error) {