

# TODO   students enrolled in fall 2020 


## Fall 2020 students with how many classes theyre taking

SELECT u.canvasid, u.name, u.sortablename, COUNT(e.id) AS num FROM enrollment AS e
JOIN users AS u ON e.user_id=u.id
JOIN courses AS c ON e.course_id=c.id
WHERE c.sis LIKE "202070-%" 
AND e.workflow="active"
AND e."type"="StudentEnrollment"
GROUP BY u.canvasid



## All sections offered in Fall 2020

SELECT c.id, c.canvasid, c.name, c.code  FROM courses AS c
WHERE c.sis LIKE "202070-%"
AND NOT c.state="deleted"
ORDER BY c.code ASC



## All Teachers teaching in Fall 2020

SELECT c.id, c.canvasid AS course_cid, c.name, c.code, u.name, u.sortablename, u.canvasid AS user_cid  FROM courses AS c
JOIN enrollment AS e ON e.course_id=c.id
JOIN users AS u ON u.id=e.user_id
WHERE c.sis LIKE "202070-%"
AND NOT c.state="deleted"
AND e."type"="TeacherEnrollment"
ORDER BY u.sortablename 
--- ORDER BY c.code ASC




## All Teachers teaching in Fall 2020 -> how many classes each has

SELECT u.name, u.sortablename, COUNT(c.id) AS num, GROUP_CONCAT(c.code, ", ") AS courses, u.canvasid AS user_cid  FROM courses AS c
JOIN enrollment AS e ON e.course_id=c.id
JOIN users AS u ON u.id=e.user_id
WHERE c.sis LIKE "202070-%"
AND NOT c.state="deleted"
AND e."type"="TeacherEnrollment"
GROUP BY user_cid
ORDER BY courses
--- ORDER BY u.sortablename 
--- ORDER BY c.code ASC



-- ## Fall 2020 teachers with NO ACTIVITY
SELECT c.id AS courseid, u.id AS userid, c.code, u.name  FROM courses AS c
JOIN enrollment AS e ON e.course_id=c.id
JOIN users AS u ON u.id=e.user_id
WHERE c.sis LIKE "202070-%"
AND NOT c.state="deleted"
AND e."type"="TeacherEnrollment"
AND u.id NOT IN (
	SELECT r.userid FROM requests_sum1 AS r
)
ORDER BY u.sortablename 



-- ## Activity of Fall 2020 teachers

SELECT t.code, t.name, SUM(r.viewcount) FROM requests_sum1 AS r 
JOIN (
	SELECT c.id AS courseid, u.id AS userid, c.code, u.name  FROM courses AS c
	JOIN enrollment AS e ON e.course_id=c.id
	JOIN users AS u ON u.id=e.user_id
	WHERE c.sis LIKE "202070-%"
	AND NOT c.state="deleted"
	AND e."type"="TeacherEnrollment"
	--GROUP BY u.id
	ORDER BY u.sortablename 
) AS t ON r.userid=t.userid AND r.courseid=t.courseid
GROUP BY r.userid, r.courseid




######   Students who are new in FALL 2020

SELECT u.canvasid, u.name, u.sortablename, GROUP_CONCAT(c.code), COUNT(e.id) AS num FROM enrollment AS e
JOIN users AS u ON e.user_id=u.id
JOIN courses AS c ON e.course_id=c.id
WHERE c.sis LIKE "202070-%" 
AND e.workflow="active"
AND e."type"="StudentEnrollment"
AND u.canvasid NOT IN (
	SELECT u.canvasid FROM enrollment AS e
	JOIN users AS u ON e.user_id=u.id
	JOIN courses AS c ON e.course_id=c.id
	WHERE c.sis NOT LIKE "202070-%" 
	AND e.workflow="active"
	AND e."type"="StudentEnrollment"
	GROUP BY u.canvasid
)
GROUP BY u.canvasid
ORDER BY num DESC, u.sortablename




######   Students who are new in 2020

SELECT u.canvasid, u.name, u.sortablename, GROUP_CONCAT(c.code), COUNT(e.id) AS num FROM enrollment AS e
JOIN users AS u ON e.user_id=u.id
JOIN courses AS c ON e.course_id=c.id
WHERE c.sis LIKE "202070-%" 
AND e.workflow="active"
AND e."type"="StudentEnrollment"
AND u.canvasid NOT IN (
	SELECT u.canvasid FROM enrollment AS e
	JOIN users AS u ON e.user_id=u.id
	JOIN courses AS c ON e.course_id=c.id
	WHERE c.sis NOT LIKE "202070-%" 
	AND  c.sis NOT LIKE "202050-%" 
	AND  c.sis NOT LIKE "202030-%" 
	AND e.workflow="active"
	AND e."type"="StudentEnrollment"
	GROUP BY u.canvasid
)
GROUP BY u.canvasid
ORDER BY num DESC, u.sortablename





######   Students who are new in FALL 2020  -> how many students are taking how many classes

SELECT num, COUNT(num) AS class_count FROM (
	SELECT e.id, COUNT(e.id) AS num FROM enrollment AS e
	JOIN users AS u ON e.user_id=u.id
	JOIN courses AS c ON e.course_id=c.id
	WHERE c.sis LIKE "202070-%" 
	AND e.workflow="active"
	AND e."type"="StudentEnrollment"
	AND u.canvasid NOT IN (
		SELECT u.canvasid FROM enrollment AS e
		JOIN users AS u ON e.user_id=u.id
		JOIN courses AS c ON e.course_id=c.id
		WHERE c.sis NOT LIKE "202070-%" 
		AND e.workflow="active"
		AND e."type"="StudentEnrollment"
		GROUP BY u.canvasid
	)
	GROUP BY u.id
)
GROUP BY num
ORDER BY num DESC



######   All FALL 2020 students  -> how many students are taking how many classes

SELECT num, COUNT(num) AS class_count FROM (
	SELECT e.id, COUNT(e.id) AS num FROM enrollment AS e
	JOIN users AS u ON e.user_id=u.id
	JOIN courses AS c ON e.course_id=c.id
	WHERE c.sis LIKE "202070-%" 
	AND e.workflow="active"
	AND e."type"="StudentEnrollment"
	GROUP BY u.id
)
GROUP BY num
ORDER BY num DESC




#####   Students who are NOT enrolled in Fall 2020

SELECT u.canvasid, u.name, u.sortablename FROM enrollment AS e
JOIN users AS u ON e.user_id=u.id
JOIN courses AS c ON e.course_id=c.id
WHERE c.sis NOT LIKE "202070-%" 
AND e.workflow="active"
AND e."type"="StudentEnrollment"
GROUP BY u.canvasid

