Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

help with sql class

Report the names of the professors who work on the most number of projects 

Insert Into Professors Values (2005, "Charlie", 'CIS', "201-234-3291",
"Charlie@calstatela.edu",
"www.calstatela.edu/faculty/Charlie/");
Insert Into Professors Values (2006, "Jennifer", 'CIS', "201-234-3621",
"Jennifer@calstatela.edu", "www.calstatela.edu/faculty/Jennifer/");
Insert Into Professors Values (2007, "Jason", 'CIS', "201-234-3921",
"www.calstatela.edu/faculty/Jason/");
"Jason@calstatela.edu",
Insert Into Supervise Values (2001, 0001, "project01", "2002-02-01");
Insert Into Supervise Values (2001, 0002, "project01", "2002-03-01");
Insert Into Supervise Values (2001, 0003, "project02", "2002-03-01");
Insert Into Supervise Values (2002, 0005, "project03", "2002-09-01");
Insert Into Supervise Values (2002, 0006, "project04", "2005-11-01");
Insert Into Supervise Values (2003, 0004, "project05","2003-10-01");
Insert Into Supervise Values (2003, 0004, "project06", "2004-10-01");
expand button
Transcribed Image Text:Insert Into Professors Values (2005, "Charlie", 'CIS', "201-234-3291", "Charlie@calstatela.edu", "www.calstatela.edu/faculty/Charlie/"); Insert Into Professors Values (2006, "Jennifer", 'CIS', "201-234-3621", "Jennifer@calstatela.edu", "www.calstatela.edu/faculty/Jennifer/"); Insert Into Professors Values (2007, "Jason", 'CIS', "201-234-3921", "www.calstatela.edu/faculty/Jason/"); "Jason@calstatela.edu", Insert Into Supervise Values (2001, 0001, "project01", "2002-02-01"); Insert Into Supervise Values (2001, 0002, "project01", "2002-03-01"); Insert Into Supervise Values (2001, 0003, "project02", "2002-03-01"); Insert Into Supervise Values (2002, 0005, "project03", "2002-09-01"); Insert Into Supervise Values (2002, 0006, "project04", "2005-11-01"); Insert Into Supervise Values (2003, 0004, "project05","2003-10-01"); Insert Into Supervise Values (2003, 0004, "project06", "2004-10-01");
CREATE TABLE Students (
student_id int,
);
student_name varchar (50) NOT NULL,
gender char(1)
NULL,
age float NULL,
EMail varchar(40) NULL,
EntryDate date NULL
CREATE TABLE Professors (
prof_id int,
);
prof_name varchar (50) NOT NULL,
dept varchar(5) NULL,
officephone varchar(16) NULL,
EMail varchar(40) NULL,
webAddress varchar(40) NULL
);
CREATE TABLE Supervise (
prof_id int,
student_id int,
project varchar(10) NULL,
startdate date NULL
Insert Into Students Values (0001,
Insert Into Students Values (0002,
01");
Insert Into Students Values (0003,
Insert Into Students Values (0004,
03-01");
Insert Into Students Values (0005,
Insert Into Students Values (0006,
"2004-01-01");
"Tom", 'M', 19, "tom@yahoo.com", "2001-01-01");
"John", 'M', 20, "John@hotmail.com", "2001-06-
"Anmy", 'F', 15, "Anmy@gmail.com", "2003-01-01");
"Dustin", 'M', 24, "Dustin@hotmail.com", "2002-
"Mary", 'F', 22, "Mary@sbc.net", "2004-01-030");
"Jessica", 'F', 21, "Jessica@calstatela.edu",
"Rainy", 'M', 19, "rainy@calstatela.edu", "2004-
Insert Into Students Values (0007,
01-12");
Insert Into Students Values (0008, "Kelvin", 'M', 19, "Kelvin@calstatela.edu",
"2004-01-12");
Insert Into Professors Values(2001, "Scott", 'CS', "201-234-3213",
"scott@calstatela.edu", "www.calstatela.edu/faculty/scott/");
Insert Into Professors Values (2002, "David", 'CE', "201-234-3112",
"david@calstatela.edu", "www.calstatela.edu/faculty/david/");
Insert Into Professors Values (2003, "Judy", 'CE', "201-234-3002",
"Judy@calstatela.edu", "www.calstatela.edu/faculty/Judy/");
Insert Into Professors Values (2004, "Gerald", 'CS', "201-234-3102",
"Gerald@calstatela.edu", "www.calstatela.edu/faculty/Gerald/");
expand button
Transcribed Image Text:CREATE TABLE Students ( student_id int, ); student_name varchar (50) NOT NULL, gender char(1) NULL, age float NULL, EMail varchar(40) NULL, EntryDate date NULL CREATE TABLE Professors ( prof_id int, ); prof_name varchar (50) NOT NULL, dept varchar(5) NULL, officephone varchar(16) NULL, EMail varchar(40) NULL, webAddress varchar(40) NULL ); CREATE TABLE Supervise ( prof_id int, student_id int, project varchar(10) NULL, startdate date NULL Insert Into Students Values (0001, Insert Into Students Values (0002, 01"); Insert Into Students Values (0003, Insert Into Students Values (0004, 03-01"); Insert Into Students Values (0005, Insert Into Students Values (0006, "2004-01-01"); "Tom", 'M', 19, "tom@yahoo.com", "2001-01-01"); "John", 'M', 20, "John@hotmail.com", "2001-06- "Anmy", 'F', 15, "Anmy@gmail.com", "2003-01-01"); "Dustin", 'M', 24, "Dustin@hotmail.com", "2002- "Mary", 'F', 22, "Mary@sbc.net", "2004-01-030"); "Jessica", 'F', 21, "Jessica@calstatela.edu", "Rainy", 'M', 19, "rainy@calstatela.edu", "2004- Insert Into Students Values (0007, 01-12"); Insert Into Students Values (0008, "Kelvin", 'M', 19, "Kelvin@calstatela.edu", "2004-01-12"); Insert Into Professors Values(2001, "Scott", 'CS', "201-234-3213", "scott@calstatela.edu", "www.calstatela.edu/faculty/scott/"); Insert Into Professors Values (2002, "David", 'CE', "201-234-3112", "david@calstatela.edu", "www.calstatela.edu/faculty/david/"); Insert Into Professors Values (2003, "Judy", 'CE', "201-234-3002", "Judy@calstatela.edu", "www.calstatela.edu/faculty/Judy/"); Insert Into Professors Values (2004, "Gerald", 'CS', "201-234-3102", "Gerald@calstatela.edu", "www.calstatela.edu/faculty/Gerald/");
Expert Solution
Check Mark
Step 1⁷

The  SQL code is as following 

 

-- select columns p.prof_name, s.student_name with distinct keyword to get unique values

 

select distinct p.prof_name, s.student_name

 

from Supervise as sp -- from Supervise table with an alias name sp

 

inner join Professors as p -- inner join Professors to Supervise with an alias name p

 

on sp.prof_id = p.prof_id -- on condition to join both the tables

 

inner join Students as s -- inner join Students to Professors with an alias name s

 

on sp.student_id = s.student_id -- on condition to join both the tables

 

union -- union operator to combine left and right queries

 

select p.prof_name, concat('Total ', COUNT(distinct sp.student_id)) -- select columns p.prof_name, concat('Total ', COUNT(distinct sp.student_id))

 

from Supervise as sp -- from Supervise table with an alias name sp

 

inner join Professors as p -- inner join Professors to Supervise with an alias name p

 

on sp.prof_id = p.prof_id -- on condition to join both the tables

 

group by p.prof_id, p.prof_name -- group by to aggregate per professor

 

order by prof_name; -- order by to sort the results by professor name

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education