Skip to content

Commit

Permalink
Added left join in to include all students without notes
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebrownlee committed Feb 19, 2024
1 parent ddcc411 commit 59a4a48
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
40 changes: 32 additions & 8 deletions LearningAPI.session.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
select *
from pg_catalog.pg_tables;

-- View all tables
select * from pg_catalog.pg_tables;


-- Drop all tables
DO $$ DECLARE
r RECORD;
BEGIN
FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = current_schema()) LOOP
EXECUTE 'DROP TABLE IF EXISTS ' || quote_ident(r.tablename) || ' CASCADE';
END LOOP;
END $$;
DROP FUNCTION IF EXISTS get_cohort_student_data(INT);
DROP FUNCTION IF EXISTS get_student_details(INT);
DROP FUNCTION IF EXISTS get_project_average_start_delay(INT);
ALTER TABLE auth_user ALTER COLUMN last_login DROP NOT NULL;
















DROP FUNCTION IF EXISTS get_cohort_student_data(INT);
select * from get_cohort_student_data(11);
select * from get_cohort_student_data(29);



Expand Down Expand Up @@ -93,7 +119,7 @@ FROM "LearningAPI_nssuser" nu
JOIN "auth_user" au ON au."id" = nu."user_id"
LEFT JOIN "LearningAPI_nssusercohort" nc ON nc."nss_user_id" = nu."id"
LEFT JOIN "LearningAPI_cohort" c ON c."id" = nc."cohort_id"
JOIN "LearningAPI_studentnote" sn ON sn."student_id" = nu."id"
LEFT JOIN "LearningAPI_studentnote" sn ON sn."student_id" = nu."id"
LEFT JOIN "socialaccount_socialaccount" social ON social.user_id = nu.id
LEFT JOIN "LearningAPI_capstone" sc ON sc.student_id = nu."id"
LEFT JOIN "LearningAPI_studentproject" sp
Expand Down Expand Up @@ -219,13 +245,11 @@ SELECT
EXTRACT(YEAR FROM AGE(NOW(), sp.date_created)) * 365 +
EXTRACT(MONTH FROM AGE(NOW(), sp.date_created)) * 30 +
EXTRACT(DAY FROM AGE(NOW(), sp.date_created))::double precision AS project_duration


FROM "LearningAPI_nssuser" nu
JOIN "auth_user" au ON au."id" = nu."user_id"
LEFT JOIN "LearningAPI_nssusercohort" nc ON nc."nss_user_id" = nu."id"
LEFT JOIN "LearningAPI_cohort" c ON c."id" = nc."cohort_id"
JOIN "LearningAPI_studentnote" sn ON sn."student_id" = nu."id"
LEFT JOIN "LearningAPI_studentnote" sn ON sn."student_id" = nu."id"
LEFT JOIN "socialaccount_socialaccount" social ON social.user_id = nu.id
LEFT JOIN "LearningAPI_capstone" sc ON sc.student_id = nu."id"
LEFT JOIN "LearningAPI_studentproject" sp
Expand Down Expand Up @@ -257,7 +281,7 @@ LEFT JOIN (
WHERE lr."achieved" = true
GROUP BY lr."student_id"
) lr ON lr."student_id" = nu."id"
WHERE nc."cohort_id" = 11
WHERE nc."cohort_id" = 29
AND au.is_active = TRUE
AND au.is_staff = FALSE
GROUP BY nu.user_id, nu.github_handle, social.extra_data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Migration(migrations.Migration):
JOIN "auth_user" au ON au."id" = nu."user_id"
LEFT JOIN "LearningAPI_nssusercohort" nc ON nc."nss_user_id" = nu."id"
LEFT JOIN "LearningAPI_cohort" c ON c."id" = nc."cohort_id"
JOIN "LearningAPI_studentnote" sn ON sn."student_id" = nu."id"
LEFT JOIN "LearningAPI_studentnote" sn ON sn."student_id" = nu."id"
LEFT JOIN "socialaccount_socialaccount" social ON social.user_id = nu.id
LEFT JOIN "LearningAPI_capstone" sc ON sc.student_id = nu."id"
LEFT JOIN "LearningAPI_studentproject" sp
Expand Down

0 comments on commit 59a4a48

Please sign in to comment.