-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.js
63 lines (52 loc) · 1.82 KB
/
solution.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const db = require("./database/db.js");
const select_cohorts_in_finsbo = db.prepare(/*sql*/ `
SELECT name FROM cohorts WHERE location = 'Finsbury Park'
`);
function listCohortsInFinsbo() {
return select_cohorts_in_finsbo.all();
}
const select_students_in_finsbo = db.prepare(/*sql*/ `
SELECT username FROM students WHERE cohort_name IN (
SELECT name FROM cohorts WHERE location = 'Finsbury Park'
)
`);
function listStudentsInFinsbo() {
return select_students_in_finsbo.all();
}
const select_students_with_location = db.prepare(/*sql*/ `
SELECT students.username, cohorts.location
FROM students INNER JOIN cohorts
ON students.cohort_name = cohorts.name
`);
function listStudentsWithLocation() {
return select_students_with_location.all();
}
const select_students_with_projects = db.prepare(/*sql*/ `
SELECT projects.name, students.username FROM projects
INNER JOIN students_projects ON projects.id = students_projects.project_id
INNER JOIN students ON students.username = students_projects.student_username
`);
function listStudentsWithProjects() {
return select_students_with_projects.all();
}
const select_students_with_projects_in_finsbo = db.prepare(/*sql*/ `
SELECT projects.name, students.username FROM projects
INNER JOIN students_projects ON projects.id = students_projects.project_id
INNER JOIN students ON students.username = students_projects.student_username
WHERE students.username IN (
SELECT username FROM students
WHERE cohort_name IN (
SELECT name FROM cohorts WHERE location = 'Finsbury Park'
)
)
`);
function listStudentsWithProjectsInFinsbo() {
return select_students_with_projects_in_finsbo.all();
}
module.exports = {
listCohortsInFinsbo,
listStudentsInFinsbo,
listStudentsWithLocation,
listStudentsWithProjects,
listStudentsWithProjectsInFinsbo,
};