Database: college_2

create table classroom
	(building		varchar(15),
	 room_number		varchar(7),
	 capacity		numeric(4,0),
	 primary key (building, room_number)
	);
create table department
	(dept_name		varchar(20),
	 building		varchar(15),
	 budget		        numeric(12,2) check (budget > 0),
	 primary key (dept_name)
	);
create table course
	(course_id		varchar(8),
	 title			varchar(50),
	 dept_name		varchar(20) NULL,
	 credits		numeric(2,0) check (credits > 0),
	 primary key (course_id),
    FOREIGN KEY (dept_name)
    REFERENCES `department` (dept_name)
    ON DELETE SET NULL
--    ON UPDATE NO ACTION
--    foreign key (dept_name) references department
-- on delete set null
   );
create table instructor
	(ID			varchar(5),
	 name			varchar(20) not null,
	 dept_name		varchar(20),
	 salary			numeric(8,2) check (salary > 29000),
	 primary key (ID),
	 foreign key (dept_name) references department (dept_name)
		on delete set null
	);
create table section
	(course_id		varchar(8),
         sec_id			varchar(8),
	 semester		varchar(6)
		check (semester in ('Fall', 'Winter', 'Spring', 'Summer')),
	 year			numeric(4,0) check (year > 1701 and year < 2100),
	 building		varchar(15),
	 room_number		varchar(7),
	 time_slot_id		varchar(4),
	 primary key (course_id, sec_id, semester, year),
	 foreign key (course_id) references course (course_id)
		on delete cascade,
	 foreign key (building, room_number) references classroom (building, room_number)
		on delete set null
	);
create table teaches
	(ID			varchar(5),
	 course_id		varchar(8),
	 sec_id			varchar(8),
	 semester		varchar(6),
	 year			numeric(4,0),
	 primary key (ID, course_id, sec_id, semester, year),
	 foreign key (course_id,sec_id, semester, year) references section (course_id, sec_id, semester, year)
		on delete cascade,
	 foreign key (ID) references instructor (ID)
		on delete cascade
	);
create table student
	(ID			varchar(5),
	 name			varchar(20) not null,
	 dept_name		varchar(20),
	 tot_cred		numeric(3,0) check (tot_cred >= 0),
	 primary key (ID),
	 foreign key (dept_name) references department (dept_name)
		on delete set null
	);
create table takes
	(ID			varchar(5),
	 course_id		varchar(8),
	 sec_id			varchar(8),
	 semester		varchar(6),
	 year			numeric(4,0),
	 grade		        varchar(2),
	 primary key (ID, course_id, sec_id, semester, year),
	 foreign key (course_id,sec_id, semester, year) references section (course_id, sec_id, semester, year)
		on delete cascade,
	 foreign key (ID) references student (ID)
		on delete cascade
	);
create table advisor
	(s_ID			varchar(5),
	 i_ID			varchar(5),
	 primary key (s_ID),
	 foreign key (i_ID) references instructor (ID)
		on delete set null,
	 foreign key (s_ID) references student (ID)
		on delete cascade
	);
create table time_slot
	(time_slot_id		varchar(4),
	 day			varchar(1),
	 start_hr		numeric(2) check (start_hr >= 0 and start_hr < 24),
	 start_min		numeric(2) check (start_min >= 0 and start_min < 60),
	 end_hr			numeric(2) check (end_hr >= 0 and end_hr < 24),
	 end_min		numeric(2) check (end_min >= 0 and end_min < 60),
	 primary key (time_slot_id, day, start_hr, start_min)
	);
create table prereq
	(course_id		varchar(8),
	 prereq_id		varchar(8),
	 primary key (course_id, prereq_id),
	 foreign key (course_id) references course (course_id)
		on delete cascade,
	 foreign key (prereq_id) references course (course_id)
	);

Question: Find the buildings which have rooms with capacity more than 50.
SQL: SELECT DISTINCT building FROM classroom WHERE capacity  >  50

Question: What are the distinct buildings with capacities of greater than 50?
SQL: SELECT DISTINCT building FROM classroom WHERE capacity  >  50

Question: Count the number of rooms that are not in the Lamberton building.
SQL: SELECT count(*) FROM classroom WHERE building != 'Lamberton'

Question: How many classrooms are not in Lamberton?
SQL: SELECT count(*) FROM classroom WHERE building != 'Lamberton'

Question: What is the name and building of the departments whose budget is more than the average budget?
SQL: SELECT dept_name ,  building FROM department WHERE budget  >  (SELECT avg(budget) FROM department)

Question: Give the name and building of the departments with greater than average budget.
SQL: SELECT dept_name ,  building FROM department WHERE budget  >  (SELECT avg(budget) FROM department)

Question: Find the room number of the rooms which can sit 50 to 100 students and their buildings.
SQL: SELECT building ,  room_number FROM classroom WHERE capacity BETWEEN 50 AND 100

Question: What are the room numbers and corresponding buildings for classrooms which can seat between 50 to 100 students?
SQL: SELECT building ,  room_number FROM classroom WHERE capacity BETWEEN 50 AND 100

Question: Find the name and building of the department with the highest budget.
SQL: SELECT dept_name ,  building FROM department ORDER BY budget DESC LIMIT 1

Question: What is the department name and corresponding building for the department with the greatest budget?
SQL: SELECT dept_name ,  building FROM department ORDER BY budget DESC LIMIT 1

Question: What is the name of the student who has the highest total credits in the History department.
SQL: SELECT name FROM student WHERE dept_name  =  'History' ORDER BY tot_cred DESC LIMIT 1

Question: Give the name of the student in the History department with the most credits.
SQL: SELECT name FROM student WHERE dept_name  =  'History' ORDER BY tot_cred DESC LIMIT 1

Question: How many rooms does the Lamberton building have?
SQL: SELECT count(*) FROM classroom WHERE building  =  'Lamberton'

Question: Count the number of classrooms in Lamberton.
SQL: SELECT count(*) FROM classroom WHERE building  =  'Lamberton'

Question: How many students have advisors?
SQL: SELECT count(DISTINCT s_id) FROM advisor

Question: Count the number of students who have advisors.
SQL: SELECT count(DISTINCT s_id) FROM advisor

Question: How many departments offer courses?
SQL: SELECT count(DISTINCT dept_name) FROM course

Question: Count the number of departments which offer courses.
SQL: SELECT count(DISTINCT dept_name) FROM course

Question: How many different courses offered by Physics department?
SQL: SELECT count(DISTINCT course_id) FROM course WHERE dept_name  =  'Physics'

Question: Count the number of courses in the Physics department.
SQL: SELECT count(DISTINCT course_id) FROM course WHERE dept_name  =  'Physics'

Question: Find the title of courses that have two prerequisites?
SQL: SELECT T1.title FROM course AS T1 JOIN prereq AS T2 ON T1.course_id  =  T2.course_id GROUP BY T2.course_id HAVING count(*)  =  2

Question: What are the titles for courses with two prerequisites?
SQL: SELECT T1.title FROM course AS T1 JOIN prereq AS T2 ON T1.course_id  =  T2.course_id GROUP BY T2.course_id HAVING count(*)  =  2

Question: Find the title, credit, and department name of courses that have more than one prerequisites?
SQL: SELECT T1.title ,  T1.credits , T1.dept_name FROM course AS T1 JOIN prereq AS T2 ON T1.course_id  =  T2.course_id GROUP BY T2.course_id HAVING count(*)  >  1

Question: What is the title, credit value, and department name for courses with more than one prerequisite?
SQL: SELECT T1.title ,  T1.credits , T1.dept_name FROM course AS T1 JOIN prereq AS T2 ON T1.course_id  =  T2.course_id GROUP BY T2.course_id HAVING count(*)  >  1

Question: How many courses that do not have prerequisite?
SQL: SELECT count(*) FROM course WHERE course_id NOT IN (SELECT course_id FROM prereq)

Question: Count the number of courses without prerequisites.
SQL: SELECT count(*) FROM course WHERE course_id NOT IN (SELECT course_id FROM prereq)

Question: Find the name of the courses that do not have any prerequisite?
SQL: SELECT title FROM course WHERE course_id NOT IN (SELECT course_id FROM prereq)

Question: What are the titles of courses without prerequisites?
SQL: SELECT title FROM course WHERE course_id NOT IN (SELECT course_id FROM prereq)

Question: How many different instructors have taught some course?
SQL: SELECT COUNT (DISTINCT id) FROM teaches

Question: Count the number of distinct instructors who have taught a course.
SQL: SELECT COUNT (DISTINCT id) FROM teaches

Question: Find the total budgets of the Marketing or Finance department.
SQL: SELECT sum(budget) FROM department WHERE dept_name  =  'Marketing' OR dept_name  =  'Finance'

Question: What is the sum of budgets of the Marketing and Finance departments?
SQL: SELECT sum(budget) FROM department WHERE dept_name  =  'Marketing' OR dept_name  =  'Finance'

Question: Find the department name of the instructor whose name contains 'Soisalon'.
SQL: SELECT dept_name FROM instructor WHERE name LIKE '%Soisalon%'

Question: What is the name of the department with an instructure who has a name like 'Soisalon'?
SQL: SELECT dept_name FROM instructor WHERE name LIKE '%Soisalon%'

Question: How many rooms whose capacity is less than 50 does the Lamberton building have?
SQL: SELECT count(*) FROM classroom WHERE building  =  'Lamberton' AND capacity  <  50

Question: Count the number of rooms in Lamberton with capacity lower than 50.
SQL: SELECT count(*) FROM classroom WHERE building  =  'Lamberton' AND capacity  <  50

Question: Find the name and budget of departments whose budgets are more than the average budget.
SQL: SELECT dept_name ,  budget FROM department WHERE budget  >  (SELECT avg(budget) FROM department)

Question: What are the names and budgets of departments with budgets greater than the average?
SQL: SELECT dept_name ,  budget FROM department WHERE budget  >  (SELECT avg(budget) FROM department)

Question: what is the name of the instructor who is in Statistics department and earns the lowest salary?
SQL: SELECT name FROM instructor WHERE dept_name  =  'Statistics' ORDER BY salary LIMIT 1

Question: Give the name of the lowest earning instructor in the Statistics department.
SQL: SELECT name FROM instructor WHERE dept_name  =  'Statistics' ORDER BY salary LIMIT 1

Question: Find the title of course that is provided by both Statistics and Psychology departments.
SQL: SELECT title FROM course WHERE dept_name  =  'Statistics' INTERSECT SELECT title FROM course WHERE dept_name  =  'Psychology'

Question: What is the title of a course that is listed in both the Statistics and Psychology departments?
SQL: SELECT title FROM course WHERE dept_name  =  'Statistics' INTERSECT SELECT title FROM course WHERE dept_name  =  'Psychology'

Question: Find the title of course that is provided by Statistics but not Psychology departments.
SQL: SELECT title FROM course WHERE dept_name  =  'Statistics' EXCEPT SELECT title FROM course WHERE dept_name  =  'Psychology'

Question: What are the titles of courses that are in the Statistics department but not the Psychology department?
SQL: SELECT title FROM course WHERE dept_name  =  'Statistics' EXCEPT SELECT title FROM course WHERE dept_name  =  'Psychology'

Question: Find the id of instructors who taught a class in Fall 2009 but not in Spring 2010.
SQL: SELECT id FROM teaches WHERE semester  =  'Fall' AND YEAR  =  2009 EXCEPT SELECT id FROM teaches WHERE semester  =  'Spring' AND YEAR  =  2010

Question: What are the ids of instructors who taught in the Fall of 2009 but not in the Spring of 2010?
SQL: SELECT id FROM teaches WHERE semester  =  'Fall' AND YEAR  =  2009 EXCEPT SELECT id FROM teaches WHERE semester  =  'Spring' AND YEAR  =  2010

Question: Find the name of students who took any class in the years of 2009 and 2010.
SQL: SELECT DISTINCT T1.name FROM student AS T1 JOIN takes AS T2 ON T1.id  =  T2.id WHERE YEAR  =  2009 OR YEAR  =  2010

Question: What are the names of the students who took classes in 2009 or 2010?
SQL: SELECT DISTINCT T1.name FROM student AS T1 JOIN takes AS T2 ON T1.id  =  T2.id WHERE YEAR  =  2009 OR YEAR  =  2010

Question: Find the names of the top 3 departments that provide the largest amount of courses?
SQL: SELECT dept_name FROM course GROUP BY dept_name ORDER BY count(*) DESC LIMIT 3

Question: What are the names of the 3 departments with the most courses?
SQL: SELECT dept_name FROM course GROUP BY dept_name ORDER BY count(*) DESC LIMIT 3

Question: Find the name of the department that offers the highest total credits?
SQL: SELECT dept_name FROM course GROUP BY dept_name ORDER BY sum(credits) DESC LIMIT 1

Question: What is the name of the department with the most credits?
SQL: SELECT dept_name FROM course GROUP BY dept_name ORDER BY sum(credits) DESC LIMIT 1

Question: List the names of all courses ordered by their titles and credits.
SQL: SELECT title FROM course ORDER BY title ,  credits

Question: Given the titles of all courses, in order of titles and credits.
SQL: SELECT title FROM course ORDER BY title ,  credits

Question: Which department has the lowest budget?
SQL: SELECT dept_name FROM department ORDER BY budget LIMIT 1

Question: Give the name of the department with the lowest budget.
SQL: SELECT dept_name FROM department ORDER BY budget LIMIT 1

Question: List the names and buildings of all departments sorted by the budget from large to small.
SQL: SELECT dept_name ,  building FROM department ORDER BY budget DESC

Question: What are the names and buildings of the deparments, sorted by budget descending?
SQL: SELECT dept_name ,  building FROM department ORDER BY budget DESC

Question: Who is the instructor with the highest salary?
SQL: SELECT name FROM instructor ORDER BY salary DESC LIMIT 1

Question: Give the name of the highest paid instructor.
SQL: SELECT name FROM instructor ORDER BY salary DESC LIMIT 1

Question: List the information of all instructors ordered by their salary in ascending order.
SQL: SELECT * FROM instructor ORDER BY salary

Question: Give all information regarding instructors, in order of salary from least to greatest.
SQL: SELECT * FROM instructor ORDER BY salary

Question: Find the name of the students and their department names sorted by their total credits in ascending order.
SQL: SELECT name ,  dept_name FROM student ORDER BY tot_cred

Question: What are the names of students and their respective departments, ordered by number of credits from least to greatest?
SQL: SELECT name ,  dept_name FROM student ORDER BY tot_cred

Question: list in alphabetic order all course names and their instructors' names in year 2008.
SQL: SELECT T1.title ,  T3.name FROM course AS T1 JOIN teaches AS T2 ON T1.course_id  =  T2.course_id JOIN instructor AS T3 ON T2.id  =  T3.id WHERE YEAR  =  2008 ORDER BY T1.title

Question: Show all titles and their instructors' names for courses in 2008, in alphabetical order by title.
SQL: SELECT T1.title ,  T3.name FROM course AS T1 JOIN teaches AS T2 ON T1.course_id  =  T2.course_id JOIN instructor AS T3 ON T2.id  =  T3.id WHERE YEAR  =  2008 ORDER BY T1.title

Question: Find the name of instructors who are advising more than one student.
SQL: SELECT T1.name FROM instructor AS T1 JOIN advisor AS T2 ON T1.id  =  T2.i_id GROUP BY T2.i_id HAVING count(*)  >  1

Question: What are the names of instructors who advise more than one student?
SQL: SELECT T1.name FROM instructor AS T1 JOIN advisor AS T2 ON T1.id  =  T2.i_id GROUP BY T2.i_id HAVING count(*)  >  1

Question: Find the name of the students who have more than one advisor?
SQL: SELECT T1.name FROM student AS T1 JOIN advisor AS T2 ON T1.id  =  T2.s_id GROUP BY T2.s_id HAVING count(*)  >  1

Question: What are the names of students who have more than one advisor?
SQL: SELECT T1.name FROM student AS T1 JOIN advisor AS T2 ON T1.id  =  T2.s_id GROUP BY T2.s_id HAVING count(*)  >  1

Question: Find the number of rooms with more than 50 capacity for each building.
SQL: SELECT count(*) ,  building FROM classroom WHERE capacity  >  50 GROUP BY building

Question: How many rooms in each building have a capacity of over 50?
SQL: SELECT count(*) ,  building FROM classroom WHERE capacity  >  50 GROUP BY building

Question: Find the maximum and average capacity among rooms in each building.
SQL: SELECT max(capacity) ,  avg(capacity) ,  building FROM classroom GROUP BY building

Question: What are the greatest and average capacity for rooms in each building?
SQL: SELECT max(capacity) ,  avg(capacity) ,  building FROM classroom GROUP BY building

Question: Find the title of the course that is offered by more than one department.
SQL: SELECT title FROM course GROUP BY title HAVING count(*)  >  1

Question: What are the titles of courses that are offered in more than one department?
SQL: SELECT title FROM course GROUP BY title HAVING count(*)  >  1

Question: Find the total credits of courses provided by different department.
SQL: SELECT sum(credits) ,  dept_name FROM course GROUP BY dept_name

Question: How many total credits are offered by each department?
SQL: SELECT sum(credits) ,  dept_name FROM course GROUP BY dept_name

Question: Find the minimum salary for the departments whose average salary is above the average payment of all instructors.
SQL: SELECT min(salary) ,  dept_name FROM instructor GROUP BY dept_name HAVING avg(salary)  >  (SELECT avg(salary) FROM instructor)

Question: What is the lowest salary in departments with average salary greater than the overall average.
SQL: SELECT min(salary) ,  dept_name FROM instructor GROUP BY dept_name HAVING avg(salary)  >  (SELECT avg(salary) FROM instructor)

Question: Find the number of courses provided in each semester and year.
SQL: SELECT count(*) ,  semester ,  YEAR FROM SECTION GROUP BY semester ,  YEAR

Question: How many courses are provided in each semester and year?
SQL: SELECT count(*) ,  semester ,  YEAR FROM SECTION GROUP BY semester ,  YEAR

Question: Find the year which offers the largest number of courses.
SQL: SELECT YEAR FROM SECTION GROUP BY YEAR ORDER BY count(*) DESC LIMIT 1

Question: Which year had the greatest number of courses?
SQL: SELECT YEAR FROM SECTION GROUP BY YEAR ORDER BY count(*) DESC LIMIT 1

Question: Find the year and semester when offers the largest number of courses.
SQL: SELECT semester ,  YEAR FROM SECTION GROUP BY semester ,  YEAR ORDER BY count(*) DESC LIMIT 1

Question: What is the year and semester with the most courses?
SQL: SELECT semester ,  YEAR FROM SECTION GROUP BY semester ,  YEAR ORDER BY count(*) DESC LIMIT 1

Question: Find the name of department has the highest amount of students?
SQL: SELECT dept_name FROM student GROUP BY dept_name ORDER BY count(*) DESC LIMIT 1

Question: What is the name of the deparment with the highest enrollment?
SQL: SELECT dept_name FROM student GROUP BY dept_name ORDER BY count(*) DESC LIMIT 1

Question: Find the total number of students in each department.
SQL: SELECT count(*) ,  dept_name FROM student GROUP BY dept_name

Question: How many students are in each department?
SQL: SELECT count(*) ,  dept_name FROM student GROUP BY dept_name

Question: Find the semester and year which has the least number of student taking any class.
SQL: SELECT semester ,  YEAR FROM takes GROUP BY semester ,  YEAR ORDER BY count(*) LIMIT 1

Question: Which semeseter and year had the fewest students?
SQL: SELECT semester ,  YEAR FROM takes GROUP BY semester ,  YEAR ORDER BY count(*) LIMIT 1

Question: What is the id of the instructor who advises of all students from History department?
SQL: SELECT i_id FROM advisor AS T1 JOIN student AS T2 ON T1.s_id  =  T2.id WHERE T2.dept_name  =  'History'

Question: Give id of the instructor who advises students in the History department.
SQL: SELECT i_id FROM advisor AS T1 JOIN student AS T2 ON T1.s_id  =  T2.id WHERE T2.dept_name  =  'History'

Question: Find the name and salary of the instructors who are advisors of any student from History department?
SQL: SELECT T2.name ,  T2.salary FROM advisor AS T1 JOIN instructor AS T2 ON T1.i_id  =  T2.id JOIN student AS T3 ON T1.s_id  =  T3.id WHERE T3.dept_name  =  'History'

Question: What are the names and salaries of instructors who advises students in the History department?
SQL: SELECT T2.name ,  T2.salary FROM advisor AS T1 JOIN instructor AS T2 ON T1.i_id  =  T2.id JOIN student AS T3 ON T1.s_id  =  T3.id WHERE T3.dept_name  =  'History'

Question: Find the id of the courses that do not have any prerequisite?
SQL: SELECT course_id FROM course EXCEPT SELECT course_id FROM prereq

Question: What are the ids of courses without prerequisites?
SQL: SELECT course_id FROM course EXCEPT SELECT course_id FROM prereq

Question: Find the name of the courses that do not have any prerequisite?
SQL: SELECT title FROM course WHERE course_id NOT IN (SELECT course_id FROM prereq)

Question: What are the names of courses without prerequisites?
SQL: SELECT title FROM course WHERE course_id NOT IN (SELECT course_id FROM prereq)

Question: What is the title of the prerequisite class of International Finance course?
SQL: SELECT title FROM course WHERE course_id IN (SELECT T1.prereq_id FROM prereq AS T1 JOIN course AS T2 ON T1.course_id  =  T2.course_id WHERE T2.title  =  'International Finance')

Question: Give the title of the prerequisite to the course International Finance.
SQL: SELECT title FROM course WHERE course_id IN (SELECT T1.prereq_id FROM prereq AS T1 JOIN course AS T2 ON T1.course_id  =  T2.course_id WHERE T2.title  =  'International Finance')

Question: Find the title of course whose prerequisite is course Differential Geometry.
SQL: SELECT title FROM course WHERE course_id IN (SELECT T1.course_id FROM prereq AS T1 JOIN course AS T2 ON T1.prereq_id  =  T2.course_id WHERE T2.title  =  'Differential Geometry')

Question: What is the title of the course with Differential Geometry as a prerequisite?
SQL: SELECT title FROM course WHERE course_id IN (SELECT T1.course_id FROM prereq AS T1 JOIN course AS T2 ON T1.prereq_id  =  T2.course_id WHERE T2.title  =  'Differential Geometry')

Question: Find the names of students who have taken any course in the fall semester of year 2003.
SQL: SELECT name FROM student WHERE id IN (SELECT id FROM takes WHERE semester  =  'Fall' AND YEAR  =  2003)

Question: What are the names of students who took a course in the Fall of 2003?
SQL: SELECT name FROM student WHERE id IN (SELECT id FROM takes WHERE semester  =  'Fall' AND YEAR  =  2003)

Question: What is the title of the course that was offered at building Chandler during the fall semester in the year of 2010?
SQL: SELECT T1.title FROM course AS T1 JOIN SECTION AS T2 ON T1.course_id  =  T2.course_id WHERE building  =  'Chandler' AND semester  =  'Fall' AND YEAR  =  2010

Question: Give the title of the course offered in Chandler during the Fall of 2010.
SQL: SELECT T1.title FROM course AS T1 JOIN SECTION AS T2 ON T1.course_id  =  T2.course_id WHERE building  =  'Chandler' AND semester  =  'Fall' AND YEAR  =  2010

Question: Find the name of the instructors who taught C Programming course before.
SQL: SELECT T1.name FROM instructor AS T1 JOIN teaches AS T2 ON T1.id  =  T2.id JOIN course AS T3 ON T2.course_id  =  T3.course_id WHERE T3.title  =  'C Programming'

Question: What are the names of instructors who have taught C Programming courses?
SQL: SELECT T1.name FROM instructor AS T1 JOIN teaches AS T2 ON T1.id  =  T2.id JOIN course AS T3 ON T2.course_id  =  T3.course_id WHERE T3.title  =  'C Programming'

Question: Find the name and salary of instructors who are advisors of the students from the Math department.
SQL: SELECT T2.name ,  T2.salary FROM advisor AS T1 JOIN instructor AS T2 ON T1.i_id  =  T2.id JOIN student AS T3 ON T1.s_id  =  T3.id WHERE T3.dept_name  =  'Math'

Question: What are the names and salaries of instructors who advise students in the Math department?
SQL: SELECT T2.name ,  T2.salary FROM advisor AS T1 JOIN instructor AS T2 ON T1.i_id  =  T2.id JOIN student AS T3 ON T1.s_id  =  T3.id WHERE T3.dept_name  =  'Math'

Question: Find the name of instructors who are advisors of the students from the Math department, and sort the results by students' total credit.
SQL: SELECT T2.name FROM advisor AS T1 JOIN instructor AS T2 ON T1.i_id  =  T2.id JOIN student AS T3 ON T1.s_id  =  T3.id WHERE T3.dept_name  =  'Math' ORDER BY T3.tot_cred

Question: What are the names of all instructors who advise students in the math depart sorted by total credits of the student.
SQL: SELECT T2.name FROM advisor AS T1 JOIN instructor AS T2 ON T1.i_id  =  T2.id JOIN student AS T3 ON T1.s_id  =  T3.id WHERE T3.dept_name  =  'Math' ORDER BY T3.tot_cred

Question: What is the course title of the prerequisite of course Mobile Computing?
SQL: SELECT title FROM course WHERE course_id IN (SELECT T1.prereq_id FROM prereq AS T1 JOIN course AS T2 ON T1.course_id  =  T2.course_id WHERE T2.title  =  'Mobile Computing')

Question: What is the title of the course that is a prerequisite for Mobile Computing?
SQL: SELECT title FROM course WHERE course_id IN (SELECT T1.prereq_id FROM prereq AS T1 JOIN course AS T2 ON T1.course_id  =  T2.course_id WHERE T2.title  =  'Mobile Computing')

Question: Find the name of instructor who is the advisor of the student who has the highest number of total credits.
SQL: SELECT T2.name FROM advisor AS T1 JOIN instructor AS T2 ON T1.i_id  =  T2.id JOIN student AS T3 ON T1.s_id  =  T3.id ORDER BY T3.tot_cred DESC LIMIT 1

Question: What is the name of the instructor who advises the student with the greatest number of total credits?
SQL: SELECT T2.name FROM advisor AS T1 JOIN instructor AS T2 ON T1.i_id  =  T2.id JOIN student AS T3 ON T1.s_id  =  T3.id ORDER BY T3.tot_cred DESC LIMIT 1

Question: Find the name of instructors who didn't teach any courses?
SQL: SELECT name FROM instructor WHERE id NOT IN (SELECT id FROM teaches)

Question: What are the names of instructors who didn't teach?
SQL: SELECT name FROM instructor WHERE id NOT IN (SELECT id FROM teaches)

Question: Find the id of instructors who didn't teach any courses?
SQL: SELECT id FROM instructor EXCEPT SELECT id FROM teaches

Question: What are the ids of instructors who didnt' teach?
SQL: SELECT id FROM instructor EXCEPT SELECT id FROM teaches

Question: Find the names of instructors who didn't each any courses in any Spring semester.
SQL: SELECT name FROM instructor WHERE id NOT IN (SELECT id FROM teaches WHERE semester  =  'Spring')

Question: What are the names of instructors who didn't teach courses in the Spring?
SQL: SELECT name FROM instructor WHERE id NOT IN (SELECT id FROM teaches WHERE semester  =  'Spring')

Question: Find the name of the department which has the highest average salary of professors.
SQL: SELECT dept_name FROM instructor GROUP BY dept_name ORDER BY avg(salary) DESC LIMIT 1

Question: Which department has the highest average instructor salary?
SQL: SELECT dept_name FROM instructor GROUP BY dept_name ORDER BY avg(salary) DESC LIMIT 1

Question: Find the number and averaged salary of all instructors who are in the department with the highest budget.
SQL: SELECT avg(T1.salary) ,  count(*) FROM instructor AS T1 JOIN department AS T2 ON T1.dept_name  =  T2.dept_name ORDER BY T2.budget DESC LIMIT 1

Question: How many instructors are in the department with the highest budget, and what is their average salary?
SQL: SELECT avg(T1.salary) ,  count(*) FROM instructor AS T1 JOIN department AS T2 ON T1.dept_name  =  T2.dept_name ORDER BY T2.budget DESC LIMIT 1

Question: What is the title and credits of the course that is taught in the largest classroom (with the highest capacity)?
SQL: SELECT T3.title ,  T3.credits FROM classroom AS T1 JOIN SECTION AS T2 ON T1.building  =  T2.building AND T1.room_number  =  T2.room_number JOIN course AS T3 ON T2.course_id  =  T3.course_id WHERE T1.capacity  =  (SELECT max(capacity) FROM classroom)

Question: Give the title and credits for the course that is taught in the classroom with the greatest capacity.
SQL: SELECT T3.title ,  T3.credits FROM classroom AS T1 JOIN SECTION AS T2 ON T1.building  =  T2.building AND T1.room_number  =  T2.room_number JOIN course AS T3 ON T2.course_id  =  T3.course_id WHERE T1.capacity  =  (SELECT max(capacity) FROM classroom)

Question: Find the name of students who didn't take any course from Biology department.
SQL: SELECT name FROM student WHERE id NOT IN (SELECT T1.id FROM takes AS T1 JOIN course AS T2 ON T1.course_id  =  T2.course_id WHERE T2.dept_name  =  'Biology')

Question: What are the names of students who haven't taken any Biology courses?
SQL: SELECT name FROM student WHERE id NOT IN (SELECT T1.id FROM takes AS T1 JOIN course AS T2 ON T1.course_id  =  T2.course_id WHERE T2.dept_name  =  'Biology')

Question: Find the total number of students and total number of instructors for each department.
SQL: SELECT count(DISTINCT T2.id) ,  count(DISTINCT T3.id) ,  T3.dept_name FROM department AS T1 JOIN student AS T2 ON T1.dept_name  =  T2.dept_name JOIN instructor AS T3 ON T1.dept_name  =  T3.dept_name GROUP BY T3.dept_name

Question: How many students and instructors are in each department?
SQL: SELECT count(DISTINCT T2.id) ,  count(DISTINCT T3.id) ,  T3.dept_name FROM department AS T1 JOIN student AS T2 ON T1.dept_name  =  T2.dept_name JOIN instructor AS T3 ON T1.dept_name  =  T3.dept_name GROUP BY T3.dept_name

Question: Find the name of students who have taken the prerequisite course of the course with title International Finance.
SQL: SELECT T1.name FROM student AS T1 JOIN takes AS T2 ON T1.id  =  T2.id WHERE T2.course_id IN (SELECT T4.prereq_id FROM course AS T3 JOIN prereq AS T4 ON T3.course_id  =  T4.course_id WHERE T3.title  =  'International Finance')

Question: What are the names of students who have taken the prerequisite for the course International Finance?
SQL: SELECT T1.name FROM student AS T1 JOIN takes AS T2 ON T1.id  =  T2.id WHERE T2.course_id IN (SELECT T4.prereq_id FROM course AS T3 JOIN prereq AS T4 ON T3.course_id  =  T4.course_id WHERE T3.title  =  'International Finance')

Question: Find the name and salary of instructors whose salary is below the average salary of the instructors in the Physics department.
SQL: SELECT name ,  salary FROM instructor WHERE salary  <  (SELECT avg(salary) FROM instructor WHERE dept_name  =  'Physics')

Question: What are the names and salaries for instructors who earn less than the average salary of instructors in the Physics department?
SQL: SELECT name ,  salary FROM instructor WHERE salary  <  (SELECT avg(salary) FROM instructor WHERE dept_name  =  'Physics')

Question: Find the name of students who took some course offered by Statistics department.
SQL: SELECT T3.name FROM course AS T1 JOIN takes AS T2 ON T1.course_id  =  T2.course_id JOIN student AS T3 ON T2.id  =  T3.id WHERE T1.dept_name  =  'Statistics'

Question: What are the names of students who have taken Statistics courses?
SQL: SELECT T3.name FROM course AS T1 JOIN takes AS T2 ON T1.course_id  =  T2.course_id JOIN student AS T3 ON T2.id  =  T3.id WHERE T1.dept_name  =  'Statistics'

Question: Find the building, room number, semester and year of all courses offered by Psychology department sorted by course titles.
SQL: SELECT T2.building ,  T2.room_number ,  T2.semester ,  T2.year FROM course AS T1 JOIN SECTION AS T2 ON T1.course_id  =  T2.course_id WHERE T1.dept_name  =  'Psychology' ORDER BY T1.title

Question: What are the building, room number, semester and year of courses in the Psychology department, sorted using course title?
SQL: SELECT T2.building ,  T2.room_number ,  T2.semester ,  T2.year FROM course AS T1 JOIN SECTION AS T2 ON T1.course_id  =  T2.course_id WHERE T1.dept_name  =  'Psychology' ORDER BY T1.title

Question: Find the names of all instructors in computer science department
SQL: SELECT name FROM instructor WHERE dept_name  =  'Comp. Sci.'

Question: What are the names of all instructors in the Comp. Sci. department?
SQL: SELECT name FROM instructor WHERE dept_name  =  'Comp. Sci.'

Question: Find the names of all instructors in Comp. Sci. department with salary > 80000.
SQL: SELECT name FROM instructor WHERE dept_name  =  'Comp. Sci.'  AND salary  >  80000

Question: What are the names of the instructors in the Comp. Sci. department who earn more than 80000?
SQL: SELECT name FROM instructor WHERE dept_name  =  'Comp. Sci.'  AND salary  >  80000

Question: Find the names of all instructors who have taught some course and the course_id.
SQL: SELECT name ,  course_id FROM instructor AS T1 JOIN teaches AS T2 ON T1.ID  =  T2.ID

Question: What are the names of all instructors who have taught a course, as well as the corresponding course id?
SQL: SELECT name ,  course_id FROM instructor AS T1 JOIN teaches AS T2 ON T1.ID  =  T2.ID

Question: Find the names of all instructors in the Art department who have taught some course and the course_id.
SQL: SELECT name ,  course_id FROM instructor AS T1 JOIN teaches AS T2 ON T1.ID  =  T2.ID WHERE T1.dept_name  =  'Art'

Question: What are the names of Art instructors who have taught a course, and the corresponding course id?
SQL: SELECT name ,  course_id FROM instructor AS T1 JOIN teaches AS T2 ON T1.ID  =  T2.ID WHERE T1.dept_name  =  'Art'

Question: Find the names of all instructors whose name includes the substring “dar”.
SQL: SELECT name FROM instructor WHERE name LIKE '%dar%'

Question: What are the names of all instructors with names that include "dar"?
SQL: SELECT name FROM instructor WHERE name LIKE '%dar%'

Question: List in alphabetic order the names of all distinct instructors.
SQL: SELECT DISTINCT name FROM  instructor ORDER BY name

Question: List the distinct names of the instructors, ordered by name.
SQL: SELECT DISTINCT name FROM  instructor ORDER BY name

Question: Find courses that ran in Fall 2009 or in Spring 2010.
SQL: SELECT course_id FROM SECTION WHERE semester  =  'Fall' AND YEAR  =  2009 UNION SELECT course_id FROM SECTION WHERE semester  =  'Spring' AND YEAR  =  2010

Question: What are the ids for courses in the Fall of 2009 or the Spring of 2010?
SQL: SELECT course_id FROM SECTION WHERE semester  =  'Fall' AND YEAR  =  2009 UNION SELECT course_id FROM SECTION WHERE semester  =  'Spring' AND YEAR  =  2010

Question: Find courses that ran in Fall 2009 and in Spring 2010.
SQL: SELECT course_id FROM SECTION WHERE semester  =  'Fall' AND YEAR  =  2009 INTERSECT SELECT course_id FROM SECTION WHERE semester  =  'Spring' AND YEAR  =  2010

Question: What are the ids for courses that were offered in both Fall of 2009 and Spring of 2010?
SQL: SELECT course_id FROM SECTION WHERE semester  =  'Fall' AND YEAR  =  2009 INTERSECT SELECT course_id FROM SECTION WHERE semester  =  'Spring' AND YEAR  =  2010

Question: Find courses that ran in Fall 2009 but not in Spring 2010.
SQL: SELECT course_id FROM SECTION WHERE semester  =  'Fall' AND YEAR  =  2009 EXCEPT SELECT course_id FROM SECTION WHERE semester  =  'Spring' AND YEAR  =  2010

Question: What are the ids of courses offered in Fall of 2009 but not in Spring of 2010?
SQL: SELECT course_id FROM SECTION WHERE semester  =  'Fall' AND YEAR  =  2009 EXCEPT SELECT course_id FROM SECTION WHERE semester  =  'Spring' AND YEAR  =  2010

Question: Find the salaries of all distinct instructors that are less than the largest salary.
SQL: SELECT DISTINCT salary FROM instructor WHERE salary  <  (SELECT max(salary) FROM instructor)

Question: What are the distinct salaries of all instructors who earned less than the maximum salary?
SQL: SELECT DISTINCT salary FROM instructor WHERE salary  <  (SELECT max(salary) FROM instructor)

Question: Find the total number of instructors who teach a course in the Spring 2010 semester.
SQL: SELECT COUNT (DISTINCT ID) FROM teaches WHERE semester  =  'Spring' AND YEAR  =  2010

Question: How many instructors teach a course in the Spring of 2010?
SQL: SELECT COUNT (DISTINCT ID) FROM teaches WHERE semester  =  'Spring' AND YEAR  =  2010

Question: Find the names and average salaries of all departments whose average salary is greater than 42000.
SQL: SELECT dept_name ,  AVG (salary) FROM instructor GROUP BY dept_name HAVING AVG (salary)  >  42000

Question: What are the names and average salaries for departments with average salary higher than 42000?
SQL: SELECT dept_name ,  AVG (salary) FROM instructor GROUP BY dept_name HAVING AVG (salary)  >  42000

Question: Find names of instructors with salary greater than that of some (at least one) instructor in the Biology department.
SQL: SELECT name FROM instructor WHERE salary  >  (SELECT min(salary) FROM instructor WHERE dept_name  =  'Biology')

Question: What are the names of instructors who earn more than at least one instructor from the Biology department?
SQL: SELECT name FROM instructor WHERE salary  >  (SELECT min(salary) FROM instructor WHERE dept_name  =  'Biology')

Question: Find the names of all instructors whose salary is greater than the salary of all instructors in the Biology department.
SQL: SELECT name FROM instructor WHERE salary  >  (SELECT max(salary) FROM instructor WHERE dept_name  =  'Biology')

Question: What are the names of all instructors with a higher salary than any of the instructors in the Biology department?
SQL: SELECT name FROM instructor WHERE salary  >  (SELECT max(salary) FROM instructor WHERE dept_name  =  'Biology')