in between commit to save some possibly useful views

This commit is contained in:
BroodjeAap 2020-11-09 20:54:59 +01:00
parent e445b121e3
commit df3e6b8e51

View file

@ -40,6 +40,29 @@ class PracticeDatabase {
FROM PracticeSession
INNER JOIN PracticeAnswer on PracticeSession.id = PracticeAnswer.sessionId;
''');
await database.execute('''
CREATE VIEW AnswersCorrectByTypeView AS
SELECT
type,
SUM(correct = 1)*1.0 AS correct,
SUM(correct = 0)*1.0 AS incorrect,
COUNT(*) AS total
FROM
AnswersView
GROUP BY
type;
''');
await database.execute('''
CREATE VIEW AnswersRatioByTypeView AS
SELECT
type,
correct,
incorrect,
total,
correct / total AS ratio
FROM
AnswersCorrectByTypeView
''');
}
static Future<Database> getDatabase() async {
@ -74,16 +97,12 @@ class PracticeDatabase {
List<Map<String, dynamic>> answers = await db.rawQuery('''
SELECT
type,
SUM(correct = 1) AS correct,
SUM(correct = 0) AS incorrect,
(
(SUM(correct = 1)*1.0) /
(SUM(correct = 0) + SUM(correct = 1))
) as ratio
correct,
incorrect,
total,
ratio
FROM
AnswersView
GROUP BY
type;
AnswersRatioByTypeView
''');
print(answers);
var first = answers.first;