🐛 fix cohort-bug
when all questions are answered at least 3 times, it didn't fill the last cohort with random questions Co-authored-by: haraldnilsen <harald_998@hotmail.com> Signed-off-by: Sindre Kjelsrud <kjelsrudsindre@gmail.com>
This commit is contained in:
parent
b249705cd8
commit
03a3d3f2d6
1 changed files with 24 additions and 23 deletions
|
@ -57,17 +57,18 @@ func GetUserQuestions(respondentID int) ([]UserQuestions, error) {
|
||||||
) AS subquery ON s.spørsmålID = subquery.spørsmålID
|
) AS subquery ON s.spørsmålID = subquery.spørsmålID
|
||||||
WHERE subquery.spørsmålID IS NOT NULL
|
WHERE subquery.spørsmålID IS NOT NULL
|
||||||
LIMIT 5
|
LIMIT 5
|
||||||
)
|
),
|
||||||
|
RandomQuestions AS (
|
||||||
SELECT * FROM FilteredQuestions
|
|
||||||
UNION ALL
|
|
||||||
SELECT * FROM (
|
|
||||||
SELECT s.SpørsmålID, s.tekst
|
SELECT s.SpørsmålID, s.tekst
|
||||||
FROM Spørsmål s
|
FROM Spørsmål s
|
||||||
|
WHERE s.SpørsmålID NOT IN (SELECT SpørsmålID FROM FilteredQuestions)
|
||||||
ORDER BY RANDOM()
|
ORDER BY RANDOM()
|
||||||
LIMIT 5
|
LIMIT 5
|
||||||
) RandomQuestions
|
)
|
||||||
WHERE NOT EXISTS (SELECT 1 FROM FilteredQuestions)
|
SELECT * FROM FilteredQuestions
|
||||||
|
UNION ALL
|
||||||
|
SELECT * FROM RandomQuestions
|
||||||
|
LIMIT 5
|
||||||
`
|
`
|
||||||
|
|
||||||
stmt, err := db.Prepare(getQuestionsStatement)
|
stmt, err := db.Prepare(getQuestionsStatement)
|
||||||
|
|
Reference in a new issue