From 4e6de66f906de89b05617a1c06c9428aeec5fe94 Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Thu, 27 Oct 2022 10:01:30 +1300 Subject: [PATCH] Fix query for start plan If the WHERE IN query is in the first select, then we will have no results unless the person has already worked out today. --- set.service.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/set.service.ts b/set.service.ts index f76c50b4..ead20e1f 100644 --- a/set.service.ts +++ b/set.service.ts @@ -168,13 +168,16 @@ export const countToday = async (name: string): Promise => { export const countMany = async (names: string[]): Promise => { const questions = names.map(_ => '?').join(','); + console.log({questions, names}); const select = ` SELECT workouts.name, COUNT(sets.id) as total, sets.sets - FROM (SELECT distinct name FROM sets) workouts + FROM ( + SELECT distinct name FROM sets + WHERE name IN (${questions}) + ) workouts LEFT JOIN sets ON sets.name = workouts.name AND sets.created LIKE STRFTIME('%Y-%m-%d%%', 'now', 'localtime') - AND NOT hidden - WHERE sets.name IN (${questions}) + AND NOT hidden GROUP BY workouts.name; `; const [result] = await db.executeSql(select, names);