Question

In: Computer Science

Using the Class database: Using a union, display the date and student id those students from...

Using the Class database:

  1. Using a union, display the date and student id those students from the absence table with the date and category of any grade event. Place in order by date. Insert your snip here.
  1. List the scores for student 17 for every List the student id, event id, score, and category for student id 17. Insert your snip here.
  1. For every student in the student table, display the student id as ‘ID’, student name as ‘Name’, and the total number of tests and quizzes each student has taken as ‘Number Taken’. Insert your snip here.
  1. Who missed a test or quiz? Display the student id as ‘ID’, student name as ‘Name’, the category of the test or quizzed missed as ‘Category’, and the date as ‘Date’. You will use 3 tables here. Insert your snip here.
  1. Display the average score for each test event. Do not explicitly test for individual event ids. Let MySQL do the work for you. Display the event id as ‘Event’ and the average score for that event as ‘Average Score’. Insert your snip here.

***********************************************************************************************************************************************

***********************************************************************************************************************************************

***********************************************************************************************************************************************
#---Create and open the database

drop database if exists Class;

CREATE DATABASE Class;


#-- Using the database

USE Class;

# create student table


DROP TABLE IF EXISTS student;

CREATE TABLE student

(
  
name VARCHAR(20) NOT NULL,
  
gender ENUM('F','M') NOT NULL,
  
student_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  
PRIMARY KEY (student_id)

);

# create grade event table

DROP TABLE IF EXISTS grade_event;

CREATE TABLE grade_event

(
  
date DATE NOT NULL,
  
category ENUM('T','Q') NOT NULL,
  
event_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  
PRIMARY KEY (event_id)

);

# create score table


# The PRIMARY KEY comprises two columns to prevent any combination
# of event_id/student_id from appearing more than once.


DROP TABLE IF EXISTS score;


CREATE TABLE score

(
  
student_id INT UNSIGNED NOT NULL,
  
event_id INT UNSIGNED NOT NULL,
  
score INT NOT NULL,
  
PRIMARY KEY (event_id, student_id),
  
INDEX (student_id),
  
FOREIGN KEY (event_id) REFERENCES grade_event (event_id),
  
FOREIGN KEY (student_id) REFERENCES student (student_id)

);

# create absence table


DROP TABLE IF EXISTS absence;

CREATE TABLE absence

(
  
student_id INT UNSIGNED NOT NULL,
  
date DATE NOT NULL,
  
PRIMARY KEY (student_id, date),
  
FOREIGN KEY (student_id) REFERENCES student (student_id)

);

#--Populate the student table


INSERT INTO student VALUES ('Megan','F',NULL);

INSERT INTO student VALUES ('Joseph','M',NULL);

INSERT INTO student VALUES ('Kyle','M',NULL);

INSERT INTO student VALUES ('Katie','F',NULL);

INSERT INTO student VALUES ('Abby','F',NULL);

INSERT INTO student VALUES ('Nathan','M',NULL);

INSERT INTO student VALUES ('Liesl','F',NULL);

INSERT INTO student VALUES ('Ian','M',NULL);

INSERT INTO student VALUES ('Colin','M',NULL);

INSERT INTO student VALUES ('Peter','M',NULL);

INSERT INTO student VALUES ('Michael','M',NULL);

INSERT INTO student VALUES ('Thomas','M',NULL);

INSERT INTO student VALUES ('Devri','F',NULL);

INSERT INTO student VALUES ('Ben','M',NULL);

INSERT INTO student VALUES ('Aubrey','F',NULL);

INSERT INTO student VALUES ('Rebecca','F',NULL);

INSERT INTO student VALUES ('Will','M',NULL);

INSERT INTO student VALUES ('Max','M',NULL);

INSERT INTO student VALUES ('Rianne','F',NULL);

INSERT INTO student VALUES ('Avery','F',NULL);

INSERT INTO student VALUES ('Lauren','F',NULL);

INSERT INTO student VALUES ('Becca','F',NULL);

INSERT INTO student VALUES ('Gregory','M',NULL);

INSERT INTO student VALUES ('Sarah','F',NULL);

INSERT INTO student VALUES ('Robbie','M',NULL);

INSERT INTO student VALUES ('Keaton','M',NULL);

INSERT INTO student VALUES ('Carter','M',NULL);

INSERT INTO student VALUES ('Teddy','M',NULL);

INSERT INTO student VALUES ('Gabrielle','F',NULL);

INSERT INTO student VALUES ('Grace','F',NULL);

INSERT INTO student VALUES ('Emily','F',NULL);


#--Populate grade event table

INSERT INTO grade_event VALUES('2015-09-03', 'Q', NULL);
INSERT INTO grade_event VALUES('
2015-09-06', 'Q', NULL);
INSERT INTO grade_event VALUES('
2015-09-09', 'T', NULL);
INSERT INTO grade_event VALUES('
2015-09-16', 'Q', NULL);
INSERT INTO grade_event VALUES(
'2015-09-23', 'Q', NULL);
INSERT INTO grade_event VALUES('
2015-10-01', 'T', NULL);


#--Populate the score table


INSERT INTO score VALUES (1,1,20);

INSERT INTO score VALUES (3,1,20);

INSERT INTO score VALUES (4,1,18);

INSERT INTO score VALUES (5,1,13);

INSERT INTO score VALUES (6,1,18);

INSERT INTO score VALUES (7,1,14);

INSERT INTO score VALUES (8,1,14);

INSERT INTO score VALUES (9,1,11);

INSERT INTO score VALUES (10,1,19);

INSERT INTO score VALUES (11,1,18);

INSERT INTO score VALUES (12,1,19);

INSERT INTO score VALUES (14,1,11);

INSERT INTO score VALUES (15,1,20);

INSERT INTO score VALUES (16,1,18);

INSERT INTO score VALUES (17,1,9);

INSERT INTO score VALUES (18,1,20);

INSERT INTO score VALUES (19,1,9);

INSERT INTO score VALUES (20,1,9);

INSERT INTO score VALUES (21,1,13);

INSERT INTO score VALUES (22,1,13);

INSERT INTO score VALUES (23,1,16);

INSERT INTO score VALUES (24,1,11);

INSERT INTO score VALUES (25,1,19);

INSERT INTO score VALUES (26,1,10);

INSERT INTO score VALUES (27,1,15);

INSERT INTO score VALUES (28,1,15);

INSERT INTO score VALUES (29,1,19);

INSERT INTO score VALUES (30,1,17);

INSERT INTO score VALUES (31,1,11);

INSERT INTO score VALUES (1,2,17);

INSERT INTO score VALUES (2,2,8);

INSERT INTO score VALUES (3,2,13);

INSERT INTO score VALUES (4,2,13);

INSERT INTO score VALUES (5,2,17);

INSERT INTO score VALUES (6,2,13);

INSERT INTO score VALUES (7,2,17);

INSERT INTO score VALUES (8,2,8);

INSERT INTO score VALUES (9,2,19);

INSERT INTO score VALUES (10,2,18);

INSERT INTO score VALUES (11,2,15);

INSERT INTO score VALUES (12,2,19);

INSERT INTO score VALUES (13,2,18);

INSERT INTO score VALUES (14,2,18);

INSERT INTO score VALUES (15,2,16);

INSERT INTO score VALUES (16,2,9);

INSERT INTO score VALUES (17,2,13);

INSERT INTO score VALUES (18,2,9);

INSERT INTO score VALUES (19,2,11);

INSERT INTO score VALUES (21,2,12);

INSERT INTO score VALUES (22,2,10);

INSERT INTO score VALUES (23,2,17);
INSERT INTO score VALUES (24,2,19);

INSERT INTO score VALUES (25,2,10);

INSERT INTO score VALUES (26,2,18);

INSERT INTO score VALUES (27,2,8);

INSERT INTO score VALUES (28,2,13);

INSERT INTO score VALUES (29,2,16);

INSERT INTO score VALUES (30,2,12);

INSERT INTO score VALUES (31,2,19);

INSERT INTO score VALUES (1,3,88);

INSERT INTO score VALUES (2,3,84);

INSERT INTO score VALUES (3,3,69);

INSERT INTO score VALUES (4,3,71);

INSERT INTO score VALUES (5,3,97);

INSERT INTO score VALUES (6,3,83);

INSERT INTO score VALUES (7,3,88);
INSERT INTO score VALUES (8,3,75);

INSERT INTO score VALUES (9,3,83);

INSERT INTO score VALUES (10,3,72);
INSERT INTO score VALUES (11,3,74);

INSERT INTO score VALUES (12,3,77);

INSERT INTO score VALUES (13,3,67);
INSERT INTO score VALUES (14,3,68);

INSERT INTO score VALUES (15,3,75);

INSERT INTO score VALUES (16,3,60);

INSERT INTO score VALUES (17,3,79);

INSERT INTO score VALUES (18,3,96);

INSERT INTO score VALUES (19,3,79);

INSERT INTO score VALUES (20,3,76);

INSERT INTO score VALUES (21,3,91);

INSERT INTO score VALUES (22,3,81);

INSERT INTO score VALUES (23,3,81);

INSERT INTO score VALUES (24,3,62);

INSERT INTO score VALUES (25,3,79);

INSERT INTO score VALUES (26,3,86);

INSERT INTO score VALUES (27,3,90);

INSERT INTO score VALUES (28,3,68);

INSERT INTO score VALUES (29,3,66);

INSERT INTO score VALUES (30,3,79);

INSERT INTO score VALUES (31,3,81);

INSERT INTO score VALUES (2,4,7);

INSERT INTO score VALUES (3,4,17);

INSERT INTO score VALUES (4,4,16);

INSERT INTO score VALUES (5,4,20);

INSERT INTO score VALUES (6,4,9);

INSERT INTO score VALUES (7,4,19);

INSERT INTO score VALUES (8,4,12);

INSERT INTO score VALUES (9,4,17);

INSERT INTO score VALUES (10,4,12);

INSERT INTO score VALUES (11,4,16);

INSERT INTO score VALUES (12,4,13);

INSERT INTO score VALUES (13,4,8);

INSERT INTO score VALUES (14,4,11);

INSERT INTO score VALUES (15,4,9);

INSERT INTO score VALUES (16,4,20);

INSERT INTO score VALUES (18,4,11);

INSERT INTO score VALUES (19,4,15);

INSERT INTO score VALUES (20,4,17);

INSERT INTO score VALUES (21,4,13);

INSERT INTO score VALUES (22,4,20);

INSERT INTO score VALUES (23,4,13);

INSERT INTO score VALUES (24,4,12);
INSERT INTO score VALUES (25,4,10);

INSERT INTO score VALUES (26,4,15);

INSERT INTO score VALUES (28,4,17);

INSERT INTO score VALUES (30,4,11);

INSERT INTO score VALUES (31,4,19);

INSERT INTO score VALUES (1,5,15);

INSERT INTO score VALUES (2,5,12);

INSERT INTO score VALUES (3,5,11);

INSERT INTO score VALUES (5,5,13);

INSERT INTO score VALUES (6,5,18);

INSERT INTO score VALUES (7,5,14);

INSERT INTO score VALUES (8,5,18);

INSERT INTO score VALUES (9,5,13);

INSERT INTO score VALUES (10,5,14);

INSERT INTO score VALUES (11,5,18);

INSERT INTO score VALUES (12,5,8);

INSERT INTO score VALUES (13,5,8);

INSERT INTO score VALUES (14,5,16);

INSERT INTO score VALUES (15,5,13);

INSERT INTO score VALUES (16,5,15);

INSERT INTO score VALUES (17,5,11);

INSERT INTO score VALUES (18,5,18);

INSERT INTO score VALUES (19,5,18);
INSERT INTO score VALUES (20,5,14);

INSERT INTO score VALUES (21,5,17);

INSERT INTO score VALUES (22,5,17);

INSERT INTO score VALUES (23,5,15);

INSERT INTO score VALUES (25,5,14);

INSERT INTO score VALUES (26,5,8);

INSERT INTO score VALUES (28,5,20);

INSERT INTO score VALUES (29,5,16);

INSERT INTO score VALUES (31,5,9);

INSERT INTO score VALUES (1,6,100);

INSERT INTO score VALUES (2,6,91);

INSERT INTO score VALUES (3,6,94);

INSERT INTO score VALUES (4,6,74);

INSERT INTO score VALUES (5,6,97);

INSERT INTO score VALUES (6,6,89);

INSERT INTO score VALUES (7,6,76);

INSERT INTO score VALUES (8,6,65);

INSERT INTO score VALUES (9,6,73);

INSERT INTO score VALUES (10,6,63);

INSERT INTO score VALUES (11,6,98);

INSERT INTO score VALUES (12,6,75);

INSERT INTO score VALUES (14,6,77);

INSERT INTO score VALUES (15,6,62);

INSERT INTO score VALUES (16,6,98);

INSERT INTO score VALUES (17,6,94);

INSERT INTO score VALUES (18,6,94);

INSERT INTO score VALUES (19,6,74);
INSERT INTO score VALUES (20,6,62);

INSERT INTO score VALUES (21,6,73);

INSERT INTO score VALUES (22,6,95);

INSERT INTO score VALUES (24,6,68);

INSERT INTO score VALUES (25,6,85);

INSERT INTO score VALUES (26,6,91);
INSERT INTO score VALUES (27,6,70);

INSERT INTO score VALUES (28,6,77);

INSERT INTO score VALUES (29,6,66);

INSERT INTO score VALUES (30,6,68);

INSERT INTO score VALUES (31,6,76);


#--Populate the absence table

INSERT INTO `absence` VALUES (3,'2015-09-03');

INSERT INTO `absence` VALUES (5,'2015-09-03');

INSERT INTO `absence` VALUES (10,'2015-09-06');

INSERT INTO `absence` VALUES (10,'2015-09-09');

INSERT INTO `absence` VALUES (17,'2015-09-07');

INSERT INTO `absence` VALUES (20,'2015-09-07');

Solutions

Expert Solution

1.
SELECT date, student_id FROM absence UNION SELECT date, category FROM grade_event

2.
SELECT student_id,score.event_id,score,category FROM score,grade_event WHERE score.event_id = grade_event.event_id AND student_id=17

3.
SELECT student.student_id AS `ID`, name AS `Name` , COUNT(*) AS `Number Taken` FROM student, score WHERE student.student_id = score.student_id GROUP BY student.student_id ORDER BY student.student_id

4.
SELECT student.student_id AS `ID`, name AS `Name` , category AS `Category`, grade_event.date as `Date` FROM student,grade_event, absence WHERE student.student_id = absence.student_ID AND grade_event.date = absence.date;

5.
SELECT event_id AS `Event`, AVG(score) AS `Average Score` FROM score GROUP BY event_id;


Related Solutions

Create a view that will display the student id, name, event id, category, and score for...
Create a view that will display the student id, name, event id, category, and score for all events for students who scored a 70 or below on any test. Call this view atriskstudents. a. What code did you write for this view? Insert the snip of the contents of the view SQL code here: b. Using this view, display those students who earned a score of 65 or greater. Insert your snip here *********************************************************************************************************************************************************** *********************************************************************************************************************************************************** CREATE DATABASE Class; #-- Using...
Using SQL create a new database called school_app. Create a student table with fields id (auto...
Using SQL create a new database called school_app. Create a student table with fields id (auto increment), first_name, last_name. Create a course table with fields id (auto increment), course code (such as ITC or MTH), and course number (such as 100 or 295). Note that the relationship between student and course is many-to-many (n:m). Create a join table called student_course that implements the n:m relationship with fields id (auto increment), student_id, course_id, and grade (which has values 0, 1, 2,...
(Using Date Class) The following UML Class Diagram describes the java Date class: java.util.Date +Date() +Date(elapseTime:...
(Using Date Class) The following UML Class Diagram describes the java Date class: java.util.Date +Date() +Date(elapseTime: long) +toString(): String +getTime(): long +setTime(elapseTime: long): void Constructs a Date object for the current time. Constructs a Date object for a given time in milliseconds elapsed since January 1, 1970, GMT. Returns a string representing the date and time. Returns the number of milliseconds since January 1, 1970, GMT. Sets a new elapse time in the object. The + sign indicates public modifer...
DROP DATABASE class;CREATE DATABASE class;Use class;drop table if exists Class;drop table if exists Student;CREATE TABLE Class...
DROP DATABASE class;CREATE DATABASE class;Use class;drop table if exists Class;drop table if exists Student;CREATE TABLE Class (CIN int PRIMARY KEY, FirstName varchar(255), LastName varchar(255), Gender varchar(1), EyeColor varchar(50), HairColor varchar(50), HeightInches int,CurrentGrade varchar(1));CREATE TABLE Student (SSN int PRIMARY KEY,FirstName varchar(255),LastName varchar(255), Age int,BirthMonth varchar(255),HeightInches int,Address varchar(255),City varchar(255),PhoneNumber varchar(12),Email varchar(255),FavColor varchar(255),FavNumber int);INSERT INTO Class VALUES(1, "David", "San", "M", "BRN", "BLK", 72, "-");INSERT INTO Class VALUES(2, "Jeff", "Gonzales", "M", "BRN", "BLK", 68, "B");INSERT INTO Class VALUES(3, "Anna", "Grayson", "F", "BRN", "BRN", 62,...
Using Linux in VirtualBox To display your system date: Type date in the command line, and...
Using Linux in VirtualBox To display your system date: Type date in the command line, and press Enter. What do you see?                                            You might see the abbreviation EDT (Eastern Daylight Time) instead of EST (Eastern Standard Time), or another time zone abbreviation, such as MDT (Mountain Daylight Time) or CST (Central Standard Time). Notice also that UNIX/Linux uses a 24-hour clock. Type Date in the command line, and press Enter. What error do you see?                                    The system error...
Create a class named Student. Student has fields for an ID number, number of credit hours...
Create a class named Student. Student has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. Student also has a field for grade point average. Include a method to compute the grade point average field by dividing...
In a class, there are 13 students. Out of those 13, 5 students are freshman a)...
In a class, there are 13 students. Out of those 13, 5 students are freshman a) If we pick three students, without replacement, what is the chance that at least one of them is a freshman? b) If we pick 2 students, without replacement, what is the chance that one of them is a freshman and one of them is not a freshman? c) If we pick five students, without replacement, what is the chance that two of them are...
Question 1 - Create a class named Student that has fields for an ID number, number...
Question 1 - Create a class named Student that has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point...
Java Beginner a)Create a class named Student that has fields for an ID number, number of...
Java Beginner a)Create a class named Student that has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point average...
The average height for a student in a class with n = 60 students is a...
The average height for a student in a class with n = 60 students is a random variable with an average height of 180 cm and standard deviation σ = 10. The individual heights which make up that average are i.i.d. (1) use Chebyshev’s inequality to find an upper bound for the probability that the average of the class (obtained from the individual student heights) is greater than 200cm. (2) Use Chebyshev’s inequality to upper bound the probability that the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT