I'm new to SQL. I'm studying SQL statements to create a database schema to hold information in a DBSM of my choice. I'm using SQLite and SQLite manager to set primary keys, foreign keys, not null, and other relevant constraints on the tables. Also I need to populate the database with the data included. But the thing is when I imported the needed CSVs into SQLite manager and there was a SQL operational feature which can directly be used to write DMLs for my results. All my DMLs are executable. So I think I need the entire DDL and SQL statements for each of the questions listed below. Here are some of my requirements from a tutorial I need to determine from an enrollment CSV.
- How many fully online classes (DEO) were offered each year? List the year and count for all 10 years.
- Find the top 10 classes, in terms of enrollment, offered in Fall 2015. List titles and enrollments only.
- Find the enrollment trend in COSC 111 (all classes) during the 10 years. List year and total enrollment.
- Find the total credit hour production for each department in the College of Arts and Sciences in Fall 2015.
- What was the net income, from tuition, for the College of Business during Fall 2015? The resident tuition per credit hour is $296.65 for “UG” classes and $597.00 for “GR” classes for the academic year.
- A query of your choice which produces meaningful data. Specify what you are trying to retrieve with your query.
Here are my DMLs for the first requirement from above:
SELECT COUNT(*)
FROM enrollment
WHERE TERM_CODE_KEY = "200610" AND SCHD_CODE_MEET1 = "DEO"
+
SELECT COUNT(*)
FROM enrollment
WHERE TERM_CODE_KEY = "200620" AND SCHD_CODE_MEET1 = "DEO";
Output:332
There are several similar DMLs to count the DEOs offered from year 2007 to year 2015.
...
SELECT COUNT(*)
FROM enrollment
WHERE TERM_CODE_KEY = "201610" AND SCHD_CODE_MEET1 = "DEO"
+
SELECT COUNT(*)
FROM enrollment
WHERE TERM_CODE_KEY = "201620" AND SCHD_CODE_MEET1 = "DEO";
Output:327
Note that A class refers to one section of a course. A year includes fall and winter semesters. Summer classes are not included in this dataset. The term code includes the year that the academic year ends in. So the term code for Fall 2013 is 201410 and Winter 2014 is 201420. Credit hour production for a class is the product of credit hours and enrollment.
My question for the first question are how to combine them together in one query and the output should be the year and the DEO classes offered and how to add the standard DDL statement in front of the DML for this question to meet the requirement?
Here are my DMLs for the last five questions:
CREATE TITLE, COUNT(*) AS count
FROM enrollment
WHERE TERM_CODE_KEY = "200610"
GROUP BY count DESC
LIMIT 10;
SELECT TERM_CODE_KEY COUNT(*) AS count
FROM enrollment
WHERE DEPT_CODE = "COSC" AND CRSE_NUMBER = "111"
GROUP BY TERM_CODE_KEY;
SELECT SUBJ_CODE, COUNT(CREDIT_HOUR) AS production
FROM enrollment
WHERE TERM_CODE_KEY = "200610" AND COLL_CODE = "AS"
GROUP BY SUBJ_CODE
ORDER BY production DESC;
SELECT
(SELECT SUM(CREDIT_HOURS*296.65) AS total
FROM enrollment
WHERE COLL_CODE = "BU" AND LEVL_CODE1 = "UG" AND TERM_CODE_KEY = "201610")
+
SELECT
(SELECT SUM(CREDIT_HOURS*597) AS total
FROM enrollment
WHERE COLL_CODE = "BU" AND LEVL_CODE1 = "GR" AND TERM_CODE_KEY = "201610");
/List CRN TITLE START and END time for the classes registered in FAll 2015 from Computer Science and Math./
SELECT CRN_KEY, TITLE, BEGIN_TIME1, END_TIME1
FROM enrollment
WHERE TERM_CODE_KEY = "201610" AND DEPT_CODE ="COSC"
UNION ALL
SELECT CRN_KEY, TITLE, BEGIN_TIME1, END_TIME1
FROM enrollment
WHERE TERM_CODE_KEY = "201610" AND DEPT_CODE ="MATH"
GROUP BY CRN_KEY;
So I really appreciate someone who can help me with the DDL for all DMLs which can acquire the conditions and requirements. And if I need to modify some of DMLs please let me know. Thank you!
Aucun commentaire:
Enregistrer un commentaire