sql查询语句

木其工作室 qq:928900200

Students can submit the same assignment multiple times. All of them are recorded, but only the last one for one assignment is graded. The deadline and timestamp are the number of milliseconds since the epoch. There is an if expression in SQL. It has the format if(condition,value1,value2). If the condition is true, then value1 is the value, otherwise value2 is the value.
create table Assignment (
id int primary key,
name varchar(10) not null unique,
description varchar(255),
topic varchar(1023) not null,
deadline long not null
);
create table Role (
id int primary key auto_increment,
name varchar(255) not null unique
);
create table Person (
id int primary key,
email varchar(255) not null unique,
name varchar(255) not null,
encryptedPassword varchar(255),
role int not null,
foreign key(role) references Role(id)
);
create table Submission (
id int primary key auto_increment,
submittedBy int not null,
foreign key(submittedBy) references Person(id) on update cascade on delete no action,
remoteAddress varchar(1023) not null,
timestamp long not null,
submittedFor int not null,
foreign key(submittedFor) references Assignment(id) on update cascade on delete no action,
filename varchar(1023) not null,
content blob not null,
contentType varchar(255)
);
create table Duty (
submittedBy int not null,
foreign key(submittedBy) references Person(id) on update cascade on delete cascade,
gradedBy int not null,
foreign key(gradedBy) references Person(id) on update cascade on delete no action,
submittedFor int not null,
foreign key(submittedFor) references Assignment(id) on update cascade on delete cascade,
primary key(submittedBy, submittedFor)
);
insert into Role(name) values('student');
insert into Role(name) values('TA');
insert into Role(name) values('instructor');
1. In this course, students receive a bonus if they submit their assignment early and no penalty if they are late, 1 point per hour early. List all students. For each student show the student name and for each assignment show the bonus (as a floating point number).
2. List all students by name who have submitted all of the first 5 assignments on time.
3. A new student named Angel Bose has been added to the course. The Person table has already been updated, and there is only one student with this name. Adjust the Duty table for each assignment so that the TA who is grading the smallest number of students in each assignment will given the duty of grading this new student.
4. A TA named Juan Lee has taken a new job. Explain how to update the tables so as to remove this TA from the database, and equitably redistribute the TA duties to the other TAs. You may use a series of commands.
Express your queries using SQL.

 

你可能感兴趣的:(sql)