db_id stringclasses 146 values | question stringlengths 3 224 | sql stringlengths 18 577 | database_schema stringclasses 146 values |
|---|---|---|---|
soccer_1 | List the names of all left-footed players who have overall rating between 85 and 90. | SELECT DISTINCT T1.player_name FROM Player AS T1 JOIN Player_Attributes AS T2 ON T1.player_api_id = T2.player_api_id WHERE T2.preferred_foot = "left" AND T2.overall_rating >= 85 AND T2.overall_rating <= 90 | CREATE TABLE "Player_Attributes" (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`player_fifa_api_id` INTEGER,
`player_api_id` INTEGER,
`date` TEXT,
`overall_rating` INTEGER,
`potential` INTEGER,
`preferred_foot` TEXT,
`attacking_work_rate` TEXT,
`defensive_work_rate` TEXT,
`crossing` INTEGER,
`finishing` INTEGER,
`heading_accuracy` INTEGER,
`short_passing` INTEGER,
`volleys` INTEGER,
`dribbling` INTEGER,
`curve` INTEGER,
`free_kick_accuracy` INTEGER,
`long_passing` INTEGER,
`ball_control` INTEGER,
`acceleration` INTEGER,
`sprint_speed` INTEGER,
`agility` INTEGER,
`reactions` INTEGER,
`balance` INTEGER,
`shot_power` INTEGER,
`jumping` INTEGER,
`stamina` INTEGER,
`strength` INTEGER,
`long_shots` INTEGER,
`aggression` INTEGER,
`interceptions` INTEGER,
`positioning` INTEGER,
`vision` INTEGER,
`penalties` INTEGER,
`marking` INTEGER,
`standing_tackle` INTEGER,
`sliding_tackle` INTEGER,
`gk_diving` INTEGER,
`gk_handling` INTEGER,
`gk_kicking` INTEGER,
`gk_positioning` INTEGER,
`gk_reflexes` INTEGER,
FOREIGN KEY(`player_fifa_api_id`) REFERENCES `Player`(`player_fifa_api_id`),
FOREIGN KEY(`player_api_id`) REFERENCES `Player`(`player_api_id`)
)
3 rows from Player_Attributes table:
id player_fifa_api_id player_api_id date overall_rating potential preferred_foot attacking_work_rate defensive_work_rate crossing finishing heading_accuracy short_passing volleys dribbling curve free_kick_accuracy long_passing ball_control acceleration sprint_speed agility reactions balance shot_power jumping stamina strength long_shots aggression interceptions positioning vision penalties marking standing_tackle sliding_tackle gk_diving gk_handling gk_kicking gk_positioning gk_reflexes
1 218353 505942 2016-02-18 00:00:00 67 71 right medium medium 49 44 71 61 44 51 45 39 64 49 60 64 59 47 65 55 58 54 76 35 71 70 45 54 48 65 69 69 6 11 10 8 8
2 218353 505942 2015-11-19 00:00:00 67 71 right medium medium 49 44 71 61 44 51 45 39 64 49 60 64 59 47 65 55 58 54 76 35 71 70 45 54 48 65 69 69 6 11 10 8 8
3 218353 505942 2015-09-21 00:00:00 62 66 right medium medium 49 44 71 61 44 51 45 39 64 49 60 64 59 47 65 55 58 54 76 35 63 41 45 54 48 65 66 69 6 11 10 8 8
CREATE TABLE sqlite_sequence(name,seq)
3 rows from sqlite_sequence table:
name seq
Team 103916
Country 51958
League 51958
CREATE TABLE `Player` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`player_api_id` INTEGER UNIQUE,
`player_name` TEXT,
`player_fifa_api_id` INTEGER UNIQUE,
`birthday` TEXT,
`height` INTEGER,
`weight` INTEGER
)
3 rows from Player table:
id player_api_id player_name player_fifa_api_id birthday height weight
1 505942 Aaron Appindangoye 218353 1992-02-29 00:00:00 182.88 187
2 155782 Aaron Cresswell 189615 1989-12-15 00:00:00 170.18 146
3 162549 Aaron Doran 186170 1991-05-13 00:00:00 170.18 163
CREATE TABLE `League` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`country_id` INTEGER,
`name` TEXT UNIQUE,
FOREIGN KEY(`country_id`) REFERENCES `Country`(`id`)
)
3 rows from League table:
id country_id name
1 1 Belgium Jupiler League
1729 1729 England Premier League
4769 4769 France Ligue 1
CREATE TABLE `Country` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`name` TEXT UNIQUE
)
3 rows from Country table:
id name
1 Belgium
1729 England
4769 France
CREATE TABLE "Team" (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`team_api_id` INTEGER UNIQUE,
`team_fifa_api_id` INTEGER,
`team_long_name` TEXT,
`team_short_name` TEXT
)
3 rows from Team table:
id team_api_id team_fifa_api_id team_long_name team_short_name
1 9987 673 KRC Genk GEN
2 9993 675 Beerschot AC BAC
3 10000 15005 SV Zulte-Waregem ZUL
CREATE TABLE `Team_Attributes` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`team_fifa_api_id` INTEGER,
`team_api_id` INTEGER,
`date` TEXT,
`buildUpPlaySpeed` INTEGER,
`buildUpPlaySpeedClass` TEXT,
`buildUpPlayDribbling` INTEGER,
`buildUpPlayDribblingClass` TEXT,
`buildUpPlayPassing` INTEGER,
`buildUpPlayPassingClass` TEXT,
`buildUpPlayPositioningClass` TEXT,
`chanceCreationPassing` INTEGER,
`chanceCreationPassingClass` TEXT,
`chanceCreationCrossing` INTEGER,
`chanceCreationCrossingClass` TEXT,
`chanceCreationShooting` INTEGER,
`chanceCreationShootingClass` TEXT,
`chanceCreationPositioningClass` TEXT,
`defencePressure` INTEGER,
`defencePressureClass` TEXT,
`defenceAggression` INTEGER,
`defenceAggressionClass` TEXT,
`defenceTeamWidth` INTEGER,
`defenceTeamWidthClass` TEXT,
`defenceDefenderLineClass` TEXT,
FOREIGN KEY(`team_fifa_api_id`) REFERENCES `Team`(`team_fifa_api_id`),
FOREIGN KEY(`team_api_id`) REFERENCES `Team`(`team_api_id`)
)
3 rows from Team_Attributes table:
id team_fifa_api_id team_api_id date buildUpPlaySpeed buildUpPlaySpeedClass buildUpPlayDribbling buildUpPlayDribblingClass buildUpPlayPassing buildUpPlayPassingClass buildUpPlayPositioningClass chanceCreationPassing chanceCreationPassingClass chanceCreationCrossing chanceCreationCrossingClass chanceCreationShooting chanceCreationShootingClass chanceCreationPositioningClass defencePressure defencePressureClass defenceAggression defenceAggressionClass defenceTeamWidth defenceTeamWidthClass defenceDefenderLineClass
1 434 9930 2010-02-22 00:00:00 60 Balanced NaN Little 50 Mixed Organised 60 Normal 65 Normal 55 Normal Organised 50 Medium 55 Press 45 Normal Cover
2 434 9930 2014-09-19 00:00:00 52 Balanced 48.0 Normal 56 Mixed Organised 54 Normal 63 Normal 64 Normal Organised 47 Medium 44 Press 54 Normal Cover
3 434 9930 2015-09-10 00:00:00 47 Balanced 41.0 Normal 54 Mixed Organised 54 Normal 63 Normal 64 Normal Organised 47 Medium 44 Press 54 Normal Cover
|
soccer_1 | What is the average rating for right-footed players and left-footed players? | SELECT preferred_foot , avg(overall_rating) FROM Player_Attributes GROUP BY preferred_foot | CREATE TABLE "Player_Attributes" (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`player_fifa_api_id` INTEGER,
`player_api_id` INTEGER,
`date` TEXT,
`overall_rating` INTEGER,
`potential` INTEGER,
`preferred_foot` TEXT,
`attacking_work_rate` TEXT,
`defensive_work_rate` TEXT,
`crossing` INTEGER,
`finishing` INTEGER,
`heading_accuracy` INTEGER,
`short_passing` INTEGER,
`volleys` INTEGER,
`dribbling` INTEGER,
`curve` INTEGER,
`free_kick_accuracy` INTEGER,
`long_passing` INTEGER,
`ball_control` INTEGER,
`acceleration` INTEGER,
`sprint_speed` INTEGER,
`agility` INTEGER,
`reactions` INTEGER,
`balance` INTEGER,
`shot_power` INTEGER,
`jumping` INTEGER,
`stamina` INTEGER,
`strength` INTEGER,
`long_shots` INTEGER,
`aggression` INTEGER,
`interceptions` INTEGER,
`positioning` INTEGER,
`vision` INTEGER,
`penalties` INTEGER,
`marking` INTEGER,
`standing_tackle` INTEGER,
`sliding_tackle` INTEGER,
`gk_diving` INTEGER,
`gk_handling` INTEGER,
`gk_kicking` INTEGER,
`gk_positioning` INTEGER,
`gk_reflexes` INTEGER,
FOREIGN KEY(`player_fifa_api_id`) REFERENCES `Player`(`player_fifa_api_id`),
FOREIGN KEY(`player_api_id`) REFERENCES `Player`(`player_api_id`)
)
3 rows from Player_Attributes table:
id player_fifa_api_id player_api_id date overall_rating potential preferred_foot attacking_work_rate defensive_work_rate crossing finishing heading_accuracy short_passing volleys dribbling curve free_kick_accuracy long_passing ball_control acceleration sprint_speed agility reactions balance shot_power jumping stamina strength long_shots aggression interceptions positioning vision penalties marking standing_tackle sliding_tackle gk_diving gk_handling gk_kicking gk_positioning gk_reflexes
1 218353 505942 2016-02-18 00:00:00 67 71 right medium medium 49 44 71 61 44 51 45 39 64 49 60 64 59 47 65 55 58 54 76 35 71 70 45 54 48 65 69 69 6 11 10 8 8
2 218353 505942 2015-11-19 00:00:00 67 71 right medium medium 49 44 71 61 44 51 45 39 64 49 60 64 59 47 65 55 58 54 76 35 71 70 45 54 48 65 69 69 6 11 10 8 8
3 218353 505942 2015-09-21 00:00:00 62 66 right medium medium 49 44 71 61 44 51 45 39 64 49 60 64 59 47 65 55 58 54 76 35 63 41 45 54 48 65 66 69 6 11 10 8 8
CREATE TABLE sqlite_sequence(name,seq)
3 rows from sqlite_sequence table:
name seq
Team 103916
Country 51958
League 51958
CREATE TABLE `Player` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`player_api_id` INTEGER UNIQUE,
`player_name` TEXT,
`player_fifa_api_id` INTEGER UNIQUE,
`birthday` TEXT,
`height` INTEGER,
`weight` INTEGER
)
3 rows from Player table:
id player_api_id player_name player_fifa_api_id birthday height weight
1 505942 Aaron Appindangoye 218353 1992-02-29 00:00:00 182.88 187
2 155782 Aaron Cresswell 189615 1989-12-15 00:00:00 170.18 146
3 162549 Aaron Doran 186170 1991-05-13 00:00:00 170.18 163
CREATE TABLE `League` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`country_id` INTEGER,
`name` TEXT UNIQUE,
FOREIGN KEY(`country_id`) REFERENCES `Country`(`id`)
)
3 rows from League table:
id country_id name
1 1 Belgium Jupiler League
1729 1729 England Premier League
4769 4769 France Ligue 1
CREATE TABLE `Country` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`name` TEXT UNIQUE
)
3 rows from Country table:
id name
1 Belgium
1729 England
4769 France
CREATE TABLE "Team" (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`team_api_id` INTEGER UNIQUE,
`team_fifa_api_id` INTEGER,
`team_long_name` TEXT,
`team_short_name` TEXT
)
3 rows from Team table:
id team_api_id team_fifa_api_id team_long_name team_short_name
1 9987 673 KRC Genk GEN
2 9993 675 Beerschot AC BAC
3 10000 15005 SV Zulte-Waregem ZUL
CREATE TABLE `Team_Attributes` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`team_fifa_api_id` INTEGER,
`team_api_id` INTEGER,
`date` TEXT,
`buildUpPlaySpeed` INTEGER,
`buildUpPlaySpeedClass` TEXT,
`buildUpPlayDribbling` INTEGER,
`buildUpPlayDribblingClass` TEXT,
`buildUpPlayPassing` INTEGER,
`buildUpPlayPassingClass` TEXT,
`buildUpPlayPositioningClass` TEXT,
`chanceCreationPassing` INTEGER,
`chanceCreationPassingClass` TEXT,
`chanceCreationCrossing` INTEGER,
`chanceCreationCrossingClass` TEXT,
`chanceCreationShooting` INTEGER,
`chanceCreationShootingClass` TEXT,
`chanceCreationPositioningClass` TEXT,
`defencePressure` INTEGER,
`defencePressureClass` TEXT,
`defenceAggression` INTEGER,
`defenceAggressionClass` TEXT,
`defenceTeamWidth` INTEGER,
`defenceTeamWidthClass` TEXT,
`defenceDefenderLineClass` TEXT,
FOREIGN KEY(`team_fifa_api_id`) REFERENCES `Team`(`team_fifa_api_id`),
FOREIGN KEY(`team_api_id`) REFERENCES `Team`(`team_api_id`)
)
3 rows from Team_Attributes table:
id team_fifa_api_id team_api_id date buildUpPlaySpeed buildUpPlaySpeedClass buildUpPlayDribbling buildUpPlayDribblingClass buildUpPlayPassing buildUpPlayPassingClass buildUpPlayPositioningClass chanceCreationPassing chanceCreationPassingClass chanceCreationCrossing chanceCreationCrossingClass chanceCreationShooting chanceCreationShootingClass chanceCreationPositioningClass defencePressure defencePressureClass defenceAggression defenceAggressionClass defenceTeamWidth defenceTeamWidthClass defenceDefenderLineClass
1 434 9930 2010-02-22 00:00:00 60 Balanced NaN Little 50 Mixed Organised 60 Normal 65 Normal 55 Normal Organised 50 Medium 55 Press 45 Normal Cover
2 434 9930 2014-09-19 00:00:00 52 Balanced 48.0 Normal 56 Mixed Organised 54 Normal 63 Normal 64 Normal Organised 47 Medium 44 Press 54 Normal Cover
3 434 9930 2015-09-10 00:00:00 47 Balanced 41.0 Normal 54 Mixed Organised 54 Normal 63 Normal 64 Normal Organised 47 Medium 44 Press 54 Normal Cover
|
soccer_1 | Of all players with an overall rating greater than 80, how many are right-footed and left-footed? | SELECT preferred_foot , count(*) FROM Player_Attributes WHERE overall_rating > 80 GROUP BY preferred_foot | CREATE TABLE "Player_Attributes" (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`player_fifa_api_id` INTEGER,
`player_api_id` INTEGER,
`date` TEXT,
`overall_rating` INTEGER,
`potential` INTEGER,
`preferred_foot` TEXT,
`attacking_work_rate` TEXT,
`defensive_work_rate` TEXT,
`crossing` INTEGER,
`finishing` INTEGER,
`heading_accuracy` INTEGER,
`short_passing` INTEGER,
`volleys` INTEGER,
`dribbling` INTEGER,
`curve` INTEGER,
`free_kick_accuracy` INTEGER,
`long_passing` INTEGER,
`ball_control` INTEGER,
`acceleration` INTEGER,
`sprint_speed` INTEGER,
`agility` INTEGER,
`reactions` INTEGER,
`balance` INTEGER,
`shot_power` INTEGER,
`jumping` INTEGER,
`stamina` INTEGER,
`strength` INTEGER,
`long_shots` INTEGER,
`aggression` INTEGER,
`interceptions` INTEGER,
`positioning` INTEGER,
`vision` INTEGER,
`penalties` INTEGER,
`marking` INTEGER,
`standing_tackle` INTEGER,
`sliding_tackle` INTEGER,
`gk_diving` INTEGER,
`gk_handling` INTEGER,
`gk_kicking` INTEGER,
`gk_positioning` INTEGER,
`gk_reflexes` INTEGER,
FOREIGN KEY(`player_fifa_api_id`) REFERENCES `Player`(`player_fifa_api_id`),
FOREIGN KEY(`player_api_id`) REFERENCES `Player`(`player_api_id`)
)
3 rows from Player_Attributes table:
id player_fifa_api_id player_api_id date overall_rating potential preferred_foot attacking_work_rate defensive_work_rate crossing finishing heading_accuracy short_passing volleys dribbling curve free_kick_accuracy long_passing ball_control acceleration sprint_speed agility reactions balance shot_power jumping stamina strength long_shots aggression interceptions positioning vision penalties marking standing_tackle sliding_tackle gk_diving gk_handling gk_kicking gk_positioning gk_reflexes
1 218353 505942 2016-02-18 00:00:00 67 71 right medium medium 49 44 71 61 44 51 45 39 64 49 60 64 59 47 65 55 58 54 76 35 71 70 45 54 48 65 69 69 6 11 10 8 8
2 218353 505942 2015-11-19 00:00:00 67 71 right medium medium 49 44 71 61 44 51 45 39 64 49 60 64 59 47 65 55 58 54 76 35 71 70 45 54 48 65 69 69 6 11 10 8 8
3 218353 505942 2015-09-21 00:00:00 62 66 right medium medium 49 44 71 61 44 51 45 39 64 49 60 64 59 47 65 55 58 54 76 35 63 41 45 54 48 65 66 69 6 11 10 8 8
CREATE TABLE sqlite_sequence(name,seq)
3 rows from sqlite_sequence table:
name seq
Team 103916
Country 51958
League 51958
CREATE TABLE `Player` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`player_api_id` INTEGER UNIQUE,
`player_name` TEXT,
`player_fifa_api_id` INTEGER UNIQUE,
`birthday` TEXT,
`height` INTEGER,
`weight` INTEGER
)
3 rows from Player table:
id player_api_id player_name player_fifa_api_id birthday height weight
1 505942 Aaron Appindangoye 218353 1992-02-29 00:00:00 182.88 187
2 155782 Aaron Cresswell 189615 1989-12-15 00:00:00 170.18 146
3 162549 Aaron Doran 186170 1991-05-13 00:00:00 170.18 163
CREATE TABLE `League` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`country_id` INTEGER,
`name` TEXT UNIQUE,
FOREIGN KEY(`country_id`) REFERENCES `Country`(`id`)
)
3 rows from League table:
id country_id name
1 1 Belgium Jupiler League
1729 1729 England Premier League
4769 4769 France Ligue 1
CREATE TABLE `Country` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`name` TEXT UNIQUE
)
3 rows from Country table:
id name
1 Belgium
1729 England
4769 France
CREATE TABLE "Team" (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`team_api_id` INTEGER UNIQUE,
`team_fifa_api_id` INTEGER,
`team_long_name` TEXT,
`team_short_name` TEXT
)
3 rows from Team table:
id team_api_id team_fifa_api_id team_long_name team_short_name
1 9987 673 KRC Genk GEN
2 9993 675 Beerschot AC BAC
3 10000 15005 SV Zulte-Waregem ZUL
CREATE TABLE `Team_Attributes` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`team_fifa_api_id` INTEGER,
`team_api_id` INTEGER,
`date` TEXT,
`buildUpPlaySpeed` INTEGER,
`buildUpPlaySpeedClass` TEXT,
`buildUpPlayDribbling` INTEGER,
`buildUpPlayDribblingClass` TEXT,
`buildUpPlayPassing` INTEGER,
`buildUpPlayPassingClass` TEXT,
`buildUpPlayPositioningClass` TEXT,
`chanceCreationPassing` INTEGER,
`chanceCreationPassingClass` TEXT,
`chanceCreationCrossing` INTEGER,
`chanceCreationCrossingClass` TEXT,
`chanceCreationShooting` INTEGER,
`chanceCreationShootingClass` TEXT,
`chanceCreationPositioningClass` TEXT,
`defencePressure` INTEGER,
`defencePressureClass` TEXT,
`defenceAggression` INTEGER,
`defenceAggressionClass` TEXT,
`defenceTeamWidth` INTEGER,
`defenceTeamWidthClass` TEXT,
`defenceDefenderLineClass` TEXT,
FOREIGN KEY(`team_fifa_api_id`) REFERENCES `Team`(`team_fifa_api_id`),
FOREIGN KEY(`team_api_id`) REFERENCES `Team`(`team_api_id`)
)
3 rows from Team_Attributes table:
id team_fifa_api_id team_api_id date buildUpPlaySpeed buildUpPlaySpeedClass buildUpPlayDribbling buildUpPlayDribblingClass buildUpPlayPassing buildUpPlayPassingClass buildUpPlayPositioningClass chanceCreationPassing chanceCreationPassingClass chanceCreationCrossing chanceCreationCrossingClass chanceCreationShooting chanceCreationShootingClass chanceCreationPositioningClass defencePressure defencePressureClass defenceAggression defenceAggressionClass defenceTeamWidth defenceTeamWidthClass defenceDefenderLineClass
1 434 9930 2010-02-22 00:00:00 60 Balanced NaN Little 50 Mixed Organised 60 Normal 65 Normal 55 Normal Organised 50 Medium 55 Press 45 Normal Cover
2 434 9930 2014-09-19 00:00:00 52 Balanced 48.0 Normal 56 Mixed Organised 54 Normal 63 Normal 64 Normal Organised 47 Medium 44 Press 54 Normal Cover
3 434 9930 2015-09-10 00:00:00 47 Balanced 41.0 Normal 54 Mixed Organised 54 Normal 63 Normal 64 Normal Organised 47 Medium 44 Press 54 Normal Cover
|
soccer_1 | List all of the player ids with a height of at least 180cm and an overall rating higher than 85. | SELECT player_api_id FROM Player WHERE height >= 180 INTERSECT SELECT player_api_id FROM Player_Attributes WHERE overall_rating > 85 | CREATE TABLE "Player_Attributes" (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`player_fifa_api_id` INTEGER,
`player_api_id` INTEGER,
`date` TEXT,
`overall_rating` INTEGER,
`potential` INTEGER,
`preferred_foot` TEXT,
`attacking_work_rate` TEXT,
`defensive_work_rate` TEXT,
`crossing` INTEGER,
`finishing` INTEGER,
`heading_accuracy` INTEGER,
`short_passing` INTEGER,
`volleys` INTEGER,
`dribbling` INTEGER,
`curve` INTEGER,
`free_kick_accuracy` INTEGER,
`long_passing` INTEGER,
`ball_control` INTEGER,
`acceleration` INTEGER,
`sprint_speed` INTEGER,
`agility` INTEGER,
`reactions` INTEGER,
`balance` INTEGER,
`shot_power` INTEGER,
`jumping` INTEGER,
`stamina` INTEGER,
`strength` INTEGER,
`long_shots` INTEGER,
`aggression` INTEGER,
`interceptions` INTEGER,
`positioning` INTEGER,
`vision` INTEGER,
`penalties` INTEGER,
`marking` INTEGER,
`standing_tackle` INTEGER,
`sliding_tackle` INTEGER,
`gk_diving` INTEGER,
`gk_handling` INTEGER,
`gk_kicking` INTEGER,
`gk_positioning` INTEGER,
`gk_reflexes` INTEGER,
FOREIGN KEY(`player_fifa_api_id`) REFERENCES `Player`(`player_fifa_api_id`),
FOREIGN KEY(`player_api_id`) REFERENCES `Player`(`player_api_id`)
)
3 rows from Player_Attributes table:
id player_fifa_api_id player_api_id date overall_rating potential preferred_foot attacking_work_rate defensive_work_rate crossing finishing heading_accuracy short_passing volleys dribbling curve free_kick_accuracy long_passing ball_control acceleration sprint_speed agility reactions balance shot_power jumping stamina strength long_shots aggression interceptions positioning vision penalties marking standing_tackle sliding_tackle gk_diving gk_handling gk_kicking gk_positioning gk_reflexes
1 218353 505942 2016-02-18 00:00:00 67 71 right medium medium 49 44 71 61 44 51 45 39 64 49 60 64 59 47 65 55 58 54 76 35 71 70 45 54 48 65 69 69 6 11 10 8 8
2 218353 505942 2015-11-19 00:00:00 67 71 right medium medium 49 44 71 61 44 51 45 39 64 49 60 64 59 47 65 55 58 54 76 35 71 70 45 54 48 65 69 69 6 11 10 8 8
3 218353 505942 2015-09-21 00:00:00 62 66 right medium medium 49 44 71 61 44 51 45 39 64 49 60 64 59 47 65 55 58 54 76 35 63 41 45 54 48 65 66 69 6 11 10 8 8
CREATE TABLE sqlite_sequence(name,seq)
3 rows from sqlite_sequence table:
name seq
Team 103916
Country 51958
League 51958
CREATE TABLE `Player` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`player_api_id` INTEGER UNIQUE,
`player_name` TEXT,
`player_fifa_api_id` INTEGER UNIQUE,
`birthday` TEXT,
`height` INTEGER,
`weight` INTEGER
)
3 rows from Player table:
id player_api_id player_name player_fifa_api_id birthday height weight
1 505942 Aaron Appindangoye 218353 1992-02-29 00:00:00 182.88 187
2 155782 Aaron Cresswell 189615 1989-12-15 00:00:00 170.18 146
3 162549 Aaron Doran 186170 1991-05-13 00:00:00 170.18 163
CREATE TABLE `League` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`country_id` INTEGER,
`name` TEXT UNIQUE,
FOREIGN KEY(`country_id`) REFERENCES `Country`(`id`)
)
3 rows from League table:
id country_id name
1 1 Belgium Jupiler League
1729 1729 England Premier League
4769 4769 France Ligue 1
CREATE TABLE `Country` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`name` TEXT UNIQUE
)
3 rows from Country table:
id name
1 Belgium
1729 England
4769 France
CREATE TABLE "Team" (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`team_api_id` INTEGER UNIQUE,
`team_fifa_api_id` INTEGER,
`team_long_name` TEXT,
`team_short_name` TEXT
)
3 rows from Team table:
id team_api_id team_fifa_api_id team_long_name team_short_name
1 9987 673 KRC Genk GEN
2 9993 675 Beerschot AC BAC
3 10000 15005 SV Zulte-Waregem ZUL
CREATE TABLE `Team_Attributes` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`team_fifa_api_id` INTEGER,
`team_api_id` INTEGER,
`date` TEXT,
`buildUpPlaySpeed` INTEGER,
`buildUpPlaySpeedClass` TEXT,
`buildUpPlayDribbling` INTEGER,
`buildUpPlayDribblingClass` TEXT,
`buildUpPlayPassing` INTEGER,
`buildUpPlayPassingClass` TEXT,
`buildUpPlayPositioningClass` TEXT,
`chanceCreationPassing` INTEGER,
`chanceCreationPassingClass` TEXT,
`chanceCreationCrossing` INTEGER,
`chanceCreationCrossingClass` TEXT,
`chanceCreationShooting` INTEGER,
`chanceCreationShootingClass` TEXT,
`chanceCreationPositioningClass` TEXT,
`defencePressure` INTEGER,
`defencePressureClass` TEXT,
`defenceAggression` INTEGER,
`defenceAggressionClass` TEXT,
`defenceTeamWidth` INTEGER,
`defenceTeamWidthClass` TEXT,
`defenceDefenderLineClass` TEXT,
FOREIGN KEY(`team_fifa_api_id`) REFERENCES `Team`(`team_fifa_api_id`),
FOREIGN KEY(`team_api_id`) REFERENCES `Team`(`team_api_id`)
)
3 rows from Team_Attributes table:
id team_fifa_api_id team_api_id date buildUpPlaySpeed buildUpPlaySpeedClass buildUpPlayDribbling buildUpPlayDribblingClass buildUpPlayPassing buildUpPlayPassingClass buildUpPlayPositioningClass chanceCreationPassing chanceCreationPassingClass chanceCreationCrossing chanceCreationCrossingClass chanceCreationShooting chanceCreationShootingClass chanceCreationPositioningClass defencePressure defencePressureClass defenceAggression defenceAggressionClass defenceTeamWidth defenceTeamWidthClass defenceDefenderLineClass
1 434 9930 2010-02-22 00:00:00 60 Balanced NaN Little 50 Mixed Organised 60 Normal 65 Normal 55 Normal Organised 50 Medium 55 Press 45 Normal Cover
2 434 9930 2014-09-19 00:00:00 52 Balanced 48.0 Normal 56 Mixed Organised 54 Normal 63 Normal 64 Normal Organised 47 Medium 44 Press 54 Normal Cover
3 434 9930 2015-09-10 00:00:00 47 Balanced 41.0 Normal 54 Mixed Organised 54 Normal 63 Normal 64 Normal Organised 47 Medium 44 Press 54 Normal Cover
|
soccer_1 | List all of the ids for left-footed players with a height between 180cm and 190cm. | SELECT player_api_id FROM Player WHERE height >= 180 AND height <= 190 INTERSECT SELECT player_api_id FROM Player_Attributes WHERE preferred_foot = "left" | CREATE TABLE "Player_Attributes" (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`player_fifa_api_id` INTEGER,
`player_api_id` INTEGER,
`date` TEXT,
`overall_rating` INTEGER,
`potential` INTEGER,
`preferred_foot` TEXT,
`attacking_work_rate` TEXT,
`defensive_work_rate` TEXT,
`crossing` INTEGER,
`finishing` INTEGER,
`heading_accuracy` INTEGER,
`short_passing` INTEGER,
`volleys` INTEGER,
`dribbling` INTEGER,
`curve` INTEGER,
`free_kick_accuracy` INTEGER,
`long_passing` INTEGER,
`ball_control` INTEGER,
`acceleration` INTEGER,
`sprint_speed` INTEGER,
`agility` INTEGER,
`reactions` INTEGER,
`balance` INTEGER,
`shot_power` INTEGER,
`jumping` INTEGER,
`stamina` INTEGER,
`strength` INTEGER,
`long_shots` INTEGER,
`aggression` INTEGER,
`interceptions` INTEGER,
`positioning` INTEGER,
`vision` INTEGER,
`penalties` INTEGER,
`marking` INTEGER,
`standing_tackle` INTEGER,
`sliding_tackle` INTEGER,
`gk_diving` INTEGER,
`gk_handling` INTEGER,
`gk_kicking` INTEGER,
`gk_positioning` INTEGER,
`gk_reflexes` INTEGER,
FOREIGN KEY(`player_fifa_api_id`) REFERENCES `Player`(`player_fifa_api_id`),
FOREIGN KEY(`player_api_id`) REFERENCES `Player`(`player_api_id`)
)
3 rows from Player_Attributes table:
id player_fifa_api_id player_api_id date overall_rating potential preferred_foot attacking_work_rate defensive_work_rate crossing finishing heading_accuracy short_passing volleys dribbling curve free_kick_accuracy long_passing ball_control acceleration sprint_speed agility reactions balance shot_power jumping stamina strength long_shots aggression interceptions positioning vision penalties marking standing_tackle sliding_tackle gk_diving gk_handling gk_kicking gk_positioning gk_reflexes
1 218353 505942 2016-02-18 00:00:00 67 71 right medium medium 49 44 71 61 44 51 45 39 64 49 60 64 59 47 65 55 58 54 76 35 71 70 45 54 48 65 69 69 6 11 10 8 8
2 218353 505942 2015-11-19 00:00:00 67 71 right medium medium 49 44 71 61 44 51 45 39 64 49 60 64 59 47 65 55 58 54 76 35 71 70 45 54 48 65 69 69 6 11 10 8 8
3 218353 505942 2015-09-21 00:00:00 62 66 right medium medium 49 44 71 61 44 51 45 39 64 49 60 64 59 47 65 55 58 54 76 35 63 41 45 54 48 65 66 69 6 11 10 8 8
CREATE TABLE sqlite_sequence(name,seq)
3 rows from sqlite_sequence table:
name seq
Team 103916
Country 51958
League 51958
CREATE TABLE `Player` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`player_api_id` INTEGER UNIQUE,
`player_name` TEXT,
`player_fifa_api_id` INTEGER UNIQUE,
`birthday` TEXT,
`height` INTEGER,
`weight` INTEGER
)
3 rows from Player table:
id player_api_id player_name player_fifa_api_id birthday height weight
1 505942 Aaron Appindangoye 218353 1992-02-29 00:00:00 182.88 187
2 155782 Aaron Cresswell 189615 1989-12-15 00:00:00 170.18 146
3 162549 Aaron Doran 186170 1991-05-13 00:00:00 170.18 163
CREATE TABLE `League` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`country_id` INTEGER,
`name` TEXT UNIQUE,
FOREIGN KEY(`country_id`) REFERENCES `Country`(`id`)
)
3 rows from League table:
id country_id name
1 1 Belgium Jupiler League
1729 1729 England Premier League
4769 4769 France Ligue 1
CREATE TABLE `Country` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`name` TEXT UNIQUE
)
3 rows from Country table:
id name
1 Belgium
1729 England
4769 France
CREATE TABLE "Team" (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`team_api_id` INTEGER UNIQUE,
`team_fifa_api_id` INTEGER,
`team_long_name` TEXT,
`team_short_name` TEXT
)
3 rows from Team table:
id team_api_id team_fifa_api_id team_long_name team_short_name
1 9987 673 KRC Genk GEN
2 9993 675 Beerschot AC BAC
3 10000 15005 SV Zulte-Waregem ZUL
CREATE TABLE `Team_Attributes` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`team_fifa_api_id` INTEGER,
`team_api_id` INTEGER,
`date` TEXT,
`buildUpPlaySpeed` INTEGER,
`buildUpPlaySpeedClass` TEXT,
`buildUpPlayDribbling` INTEGER,
`buildUpPlayDribblingClass` TEXT,
`buildUpPlayPassing` INTEGER,
`buildUpPlayPassingClass` TEXT,
`buildUpPlayPositioningClass` TEXT,
`chanceCreationPassing` INTEGER,
`chanceCreationPassingClass` TEXT,
`chanceCreationCrossing` INTEGER,
`chanceCreationCrossingClass` TEXT,
`chanceCreationShooting` INTEGER,
`chanceCreationShootingClass` TEXT,
`chanceCreationPositioningClass` TEXT,
`defencePressure` INTEGER,
`defencePressureClass` TEXT,
`defenceAggression` INTEGER,
`defenceAggressionClass` TEXT,
`defenceTeamWidth` INTEGER,
`defenceTeamWidthClass` TEXT,
`defenceDefenderLineClass` TEXT,
FOREIGN KEY(`team_fifa_api_id`) REFERENCES `Team`(`team_fifa_api_id`),
FOREIGN KEY(`team_api_id`) REFERENCES `Team`(`team_api_id`)
)
3 rows from Team_Attributes table:
id team_fifa_api_id team_api_id date buildUpPlaySpeed buildUpPlaySpeedClass buildUpPlayDribbling buildUpPlayDribblingClass buildUpPlayPassing buildUpPlayPassingClass buildUpPlayPositioningClass chanceCreationPassing chanceCreationPassingClass chanceCreationCrossing chanceCreationCrossingClass chanceCreationShooting chanceCreationShootingClass chanceCreationPositioningClass defencePressure defencePressureClass defenceAggression defenceAggressionClass defenceTeamWidth defenceTeamWidthClass defenceDefenderLineClass
1 434 9930 2010-02-22 00:00:00 60 Balanced NaN Little 50 Mixed Organised 60 Normal 65 Normal 55 Normal Organised 50 Medium 55 Press 45 Normal Cover
2 434 9930 2014-09-19 00:00:00 52 Balanced 48.0 Normal 56 Mixed Organised 54 Normal 63 Normal 64 Normal Organised 47 Medium 44 Press 54 Normal Cover
3 434 9930 2015-09-10 00:00:00 47 Balanced 41.0 Normal 54 Mixed Organised 54 Normal 63 Normal 64 Normal Organised 47 Medium 44 Press 54 Normal Cover
|
soccer_1 | Who are the top 3 players in terms of overall rating? | SELECT DISTINCT T1.player_name FROM Player AS T1 JOIN Player_Attributes AS T2 ON T1.player_api_id = T2.player_api_id ORDER BY overall_rating DESC LIMIT 3 | CREATE TABLE "Player_Attributes" (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`player_fifa_api_id` INTEGER,
`player_api_id` INTEGER,
`date` TEXT,
`overall_rating` INTEGER,
`potential` INTEGER,
`preferred_foot` TEXT,
`attacking_work_rate` TEXT,
`defensive_work_rate` TEXT,
`crossing` INTEGER,
`finishing` INTEGER,
`heading_accuracy` INTEGER,
`short_passing` INTEGER,
`volleys` INTEGER,
`dribbling` INTEGER,
`curve` INTEGER,
`free_kick_accuracy` INTEGER,
`long_passing` INTEGER,
`ball_control` INTEGER,
`acceleration` INTEGER,
`sprint_speed` INTEGER,
`agility` INTEGER,
`reactions` INTEGER,
`balance` INTEGER,
`shot_power` INTEGER,
`jumping` INTEGER,
`stamina` INTEGER,
`strength` INTEGER,
`long_shots` INTEGER,
`aggression` INTEGER,
`interceptions` INTEGER,
`positioning` INTEGER,
`vision` INTEGER,
`penalties` INTEGER,
`marking` INTEGER,
`standing_tackle` INTEGER,
`sliding_tackle` INTEGER,
`gk_diving` INTEGER,
`gk_handling` INTEGER,
`gk_kicking` INTEGER,
`gk_positioning` INTEGER,
`gk_reflexes` INTEGER,
FOREIGN KEY(`player_fifa_api_id`) REFERENCES `Player`(`player_fifa_api_id`),
FOREIGN KEY(`player_api_id`) REFERENCES `Player`(`player_api_id`)
)
3 rows from Player_Attributes table:
id player_fifa_api_id player_api_id date overall_rating potential preferred_foot attacking_work_rate defensive_work_rate crossing finishing heading_accuracy short_passing volleys dribbling curve free_kick_accuracy long_passing ball_control acceleration sprint_speed agility reactions balance shot_power jumping stamina strength long_shots aggression interceptions positioning vision penalties marking standing_tackle sliding_tackle gk_diving gk_handling gk_kicking gk_positioning gk_reflexes
1 218353 505942 2016-02-18 00:00:00 67 71 right medium medium 49 44 71 61 44 51 45 39 64 49 60 64 59 47 65 55 58 54 76 35 71 70 45 54 48 65 69 69 6 11 10 8 8
2 218353 505942 2015-11-19 00:00:00 67 71 right medium medium 49 44 71 61 44 51 45 39 64 49 60 64 59 47 65 55 58 54 76 35 71 70 45 54 48 65 69 69 6 11 10 8 8
3 218353 505942 2015-09-21 00:00:00 62 66 right medium medium 49 44 71 61 44 51 45 39 64 49 60 64 59 47 65 55 58 54 76 35 63 41 45 54 48 65 66 69 6 11 10 8 8
CREATE TABLE sqlite_sequence(name,seq)
3 rows from sqlite_sequence table:
name seq
Team 103916
Country 51958
League 51958
CREATE TABLE `Player` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`player_api_id` INTEGER UNIQUE,
`player_name` TEXT,
`player_fifa_api_id` INTEGER UNIQUE,
`birthday` TEXT,
`height` INTEGER,
`weight` INTEGER
)
3 rows from Player table:
id player_api_id player_name player_fifa_api_id birthday height weight
1 505942 Aaron Appindangoye 218353 1992-02-29 00:00:00 182.88 187
2 155782 Aaron Cresswell 189615 1989-12-15 00:00:00 170.18 146
3 162549 Aaron Doran 186170 1991-05-13 00:00:00 170.18 163
CREATE TABLE `League` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`country_id` INTEGER,
`name` TEXT UNIQUE,
FOREIGN KEY(`country_id`) REFERENCES `Country`(`id`)
)
3 rows from League table:
id country_id name
1 1 Belgium Jupiler League
1729 1729 England Premier League
4769 4769 France Ligue 1
CREATE TABLE `Country` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`name` TEXT UNIQUE
)
3 rows from Country table:
id name
1 Belgium
1729 England
4769 France
CREATE TABLE "Team" (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`team_api_id` INTEGER UNIQUE,
`team_fifa_api_id` INTEGER,
`team_long_name` TEXT,
`team_short_name` TEXT
)
3 rows from Team table:
id team_api_id team_fifa_api_id team_long_name team_short_name
1 9987 673 KRC Genk GEN
2 9993 675 Beerschot AC BAC
3 10000 15005 SV Zulte-Waregem ZUL
CREATE TABLE `Team_Attributes` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`team_fifa_api_id` INTEGER,
`team_api_id` INTEGER,
`date` TEXT,
`buildUpPlaySpeed` INTEGER,
`buildUpPlaySpeedClass` TEXT,
`buildUpPlayDribbling` INTEGER,
`buildUpPlayDribblingClass` TEXT,
`buildUpPlayPassing` INTEGER,
`buildUpPlayPassingClass` TEXT,
`buildUpPlayPositioningClass` TEXT,
`chanceCreationPassing` INTEGER,
`chanceCreationPassingClass` TEXT,
`chanceCreationCrossing` INTEGER,
`chanceCreationCrossingClass` TEXT,
`chanceCreationShooting` INTEGER,
`chanceCreationShootingClass` TEXT,
`chanceCreationPositioningClass` TEXT,
`defencePressure` INTEGER,
`defencePressureClass` TEXT,
`defenceAggression` INTEGER,
`defenceAggressionClass` TEXT,
`defenceTeamWidth` INTEGER,
`defenceTeamWidthClass` TEXT,
`defenceDefenderLineClass` TEXT,
FOREIGN KEY(`team_fifa_api_id`) REFERENCES `Team`(`team_fifa_api_id`),
FOREIGN KEY(`team_api_id`) REFERENCES `Team`(`team_api_id`)
)
3 rows from Team_Attributes table:
id team_fifa_api_id team_api_id date buildUpPlaySpeed buildUpPlaySpeedClass buildUpPlayDribbling buildUpPlayDribblingClass buildUpPlayPassing buildUpPlayPassingClass buildUpPlayPositioningClass chanceCreationPassing chanceCreationPassingClass chanceCreationCrossing chanceCreationCrossingClass chanceCreationShooting chanceCreationShootingClass chanceCreationPositioningClass defencePressure defencePressureClass defenceAggression defenceAggressionClass defenceTeamWidth defenceTeamWidthClass defenceDefenderLineClass
1 434 9930 2010-02-22 00:00:00 60 Balanced NaN Little 50 Mixed Organised 60 Normal 65 Normal 55 Normal Organised 50 Medium 55 Press 45 Normal Cover
2 434 9930 2014-09-19 00:00:00 52 Balanced 48.0 Normal 56 Mixed Organised 54 Normal 63 Normal 64 Normal Organised 47 Medium 44 Press 54 Normal Cover
3 434 9930 2015-09-10 00:00:00 47 Balanced 41.0 Normal 54 Mixed Organised 54 Normal 63 Normal 64 Normal Organised 47 Medium 44 Press 54 Normal Cover
|
soccer_1 | List the names and birthdays of the top five players in terms of potential. | SELECT DISTINCT T1.player_name , T1.birthday FROM Player AS T1 JOIN Player_Attributes AS T2 ON T1.player_api_id = T2.player_api_id ORDER BY potential DESC LIMIT 5 | CREATE TABLE "Player_Attributes" (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`player_fifa_api_id` INTEGER,
`player_api_id` INTEGER,
`date` TEXT,
`overall_rating` INTEGER,
`potential` INTEGER,
`preferred_foot` TEXT,
`attacking_work_rate` TEXT,
`defensive_work_rate` TEXT,
`crossing` INTEGER,
`finishing` INTEGER,
`heading_accuracy` INTEGER,
`short_passing` INTEGER,
`volleys` INTEGER,
`dribbling` INTEGER,
`curve` INTEGER,
`free_kick_accuracy` INTEGER,
`long_passing` INTEGER,
`ball_control` INTEGER,
`acceleration` INTEGER,
`sprint_speed` INTEGER,
`agility` INTEGER,
`reactions` INTEGER,
`balance` INTEGER,
`shot_power` INTEGER,
`jumping` INTEGER,
`stamina` INTEGER,
`strength` INTEGER,
`long_shots` INTEGER,
`aggression` INTEGER,
`interceptions` INTEGER,
`positioning` INTEGER,
`vision` INTEGER,
`penalties` INTEGER,
`marking` INTEGER,
`standing_tackle` INTEGER,
`sliding_tackle` INTEGER,
`gk_diving` INTEGER,
`gk_handling` INTEGER,
`gk_kicking` INTEGER,
`gk_positioning` INTEGER,
`gk_reflexes` INTEGER,
FOREIGN KEY(`player_fifa_api_id`) REFERENCES `Player`(`player_fifa_api_id`),
FOREIGN KEY(`player_api_id`) REFERENCES `Player`(`player_api_id`)
)
3 rows from Player_Attributes table:
id player_fifa_api_id player_api_id date overall_rating potential preferred_foot attacking_work_rate defensive_work_rate crossing finishing heading_accuracy short_passing volleys dribbling curve free_kick_accuracy long_passing ball_control acceleration sprint_speed agility reactions balance shot_power jumping stamina strength long_shots aggression interceptions positioning vision penalties marking standing_tackle sliding_tackle gk_diving gk_handling gk_kicking gk_positioning gk_reflexes
1 218353 505942 2016-02-18 00:00:00 67 71 right medium medium 49 44 71 61 44 51 45 39 64 49 60 64 59 47 65 55 58 54 76 35 71 70 45 54 48 65 69 69 6 11 10 8 8
2 218353 505942 2015-11-19 00:00:00 67 71 right medium medium 49 44 71 61 44 51 45 39 64 49 60 64 59 47 65 55 58 54 76 35 71 70 45 54 48 65 69 69 6 11 10 8 8
3 218353 505942 2015-09-21 00:00:00 62 66 right medium medium 49 44 71 61 44 51 45 39 64 49 60 64 59 47 65 55 58 54 76 35 63 41 45 54 48 65 66 69 6 11 10 8 8
CREATE TABLE sqlite_sequence(name,seq)
3 rows from sqlite_sequence table:
name seq
Team 103916
Country 51958
League 51958
CREATE TABLE `Player` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`player_api_id` INTEGER UNIQUE,
`player_name` TEXT,
`player_fifa_api_id` INTEGER UNIQUE,
`birthday` TEXT,
`height` INTEGER,
`weight` INTEGER
)
3 rows from Player table:
id player_api_id player_name player_fifa_api_id birthday height weight
1 505942 Aaron Appindangoye 218353 1992-02-29 00:00:00 182.88 187
2 155782 Aaron Cresswell 189615 1989-12-15 00:00:00 170.18 146
3 162549 Aaron Doran 186170 1991-05-13 00:00:00 170.18 163
CREATE TABLE `League` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`country_id` INTEGER,
`name` TEXT UNIQUE,
FOREIGN KEY(`country_id`) REFERENCES `Country`(`id`)
)
3 rows from League table:
id country_id name
1 1 Belgium Jupiler League
1729 1729 England Premier League
4769 4769 France Ligue 1
CREATE TABLE `Country` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`name` TEXT UNIQUE
)
3 rows from Country table:
id name
1 Belgium
1729 England
4769 France
CREATE TABLE "Team" (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`team_api_id` INTEGER UNIQUE,
`team_fifa_api_id` INTEGER,
`team_long_name` TEXT,
`team_short_name` TEXT
)
3 rows from Team table:
id team_api_id team_fifa_api_id team_long_name team_short_name
1 9987 673 KRC Genk GEN
2 9993 675 Beerschot AC BAC
3 10000 15005 SV Zulte-Waregem ZUL
CREATE TABLE `Team_Attributes` (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`team_fifa_api_id` INTEGER,
`team_api_id` INTEGER,
`date` TEXT,
`buildUpPlaySpeed` INTEGER,
`buildUpPlaySpeedClass` TEXT,
`buildUpPlayDribbling` INTEGER,
`buildUpPlayDribblingClass` TEXT,
`buildUpPlayPassing` INTEGER,
`buildUpPlayPassingClass` TEXT,
`buildUpPlayPositioningClass` TEXT,
`chanceCreationPassing` INTEGER,
`chanceCreationPassingClass` TEXT,
`chanceCreationCrossing` INTEGER,
`chanceCreationCrossingClass` TEXT,
`chanceCreationShooting` INTEGER,
`chanceCreationShootingClass` TEXT,
`chanceCreationPositioningClass` TEXT,
`defencePressure` INTEGER,
`defencePressureClass` TEXT,
`defenceAggression` INTEGER,
`defenceAggressionClass` TEXT,
`defenceTeamWidth` INTEGER,
`defenceTeamWidthClass` TEXT,
`defenceDefenderLineClass` TEXT,
FOREIGN KEY(`team_fifa_api_id`) REFERENCES `Team`(`team_fifa_api_id`),
FOREIGN KEY(`team_api_id`) REFERENCES `Team`(`team_api_id`)
)
3 rows from Team_Attributes table:
id team_fifa_api_id team_api_id date buildUpPlaySpeed buildUpPlaySpeedClass buildUpPlayDribbling buildUpPlayDribblingClass buildUpPlayPassing buildUpPlayPassingClass buildUpPlayPositioningClass chanceCreationPassing chanceCreationPassingClass chanceCreationCrossing chanceCreationCrossingClass chanceCreationShooting chanceCreationShootingClass chanceCreationPositioningClass defencePressure defencePressureClass defenceAggression defenceAggressionClass defenceTeamWidth defenceTeamWidthClass defenceDefenderLineClass
1 434 9930 2010-02-22 00:00:00 60 Balanced NaN Little 50 Mixed Organised 60 Normal 65 Normal 55 Normal Organised 50 Medium 55 Press 45 Normal Cover
2 434 9930 2014-09-19 00:00:00 52 Balanced 48.0 Normal 56 Mixed Organised 54 Normal 63 Normal 64 Normal Organised 47 Medium 44 Press 54 Normal Cover
3 434 9930 2015-09-10 00:00:00 47 Balanced 41.0 Normal 54 Mixed Organised 54 Normal 63 Normal 64 Normal Organised 47 Medium 44 Press 54 Normal Cover
|
performance_attendance | How many performances are there? | SELECT count(*) FROM performance | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
)
3 rows from member table:
Member_ID Name Nationality Role
1 Wilfredo Ruiz Uruguay Prime Violin
2 Luis González Argentina Violin
3 Héctor Campana Argentina Violin
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
)
3 rows from performance table:
Performance_ID Date Host Location Attendance
1.0 February 2 Boston Bruins TD Garden 165
2.0 February 4 New York Rangers Madison Square Garden 1820
3.0 February 5 Atlanta Thrashers Verizon Center 1878
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
)
3 rows from member_attendance table:
Member_ID Performance_ID Num_of_Pieces
11 3 2
7 2 3
4 6 4
|
performance_attendance | List the hosts of performances in ascending order of attendance. | SELECT HOST FROM performance ORDER BY Attendance ASC | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
)
3 rows from member table:
Member_ID Name Nationality Role
1 Wilfredo Ruiz Uruguay Prime Violin
2 Luis González Argentina Violin
3 Héctor Campana Argentina Violin
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
)
3 rows from performance table:
Performance_ID Date Host Location Attendance
1.0 February 2 Boston Bruins TD Garden 165
2.0 February 4 New York Rangers Madison Square Garden 1820
3.0 February 5 Atlanta Thrashers Verizon Center 1878
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
)
3 rows from member_attendance table:
Member_ID Performance_ID Num_of_Pieces
11 3 2
7 2 3
4 6 4
|
performance_attendance | What are the dates and locations of performances? | SELECT Date , LOCATION FROM performance | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
)
3 rows from member table:
Member_ID Name Nationality Role
1 Wilfredo Ruiz Uruguay Prime Violin
2 Luis González Argentina Violin
3 Héctor Campana Argentina Violin
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
)
3 rows from performance table:
Performance_ID Date Host Location Attendance
1.0 February 2 Boston Bruins TD Garden 165
2.0 February 4 New York Rangers Madison Square Garden 1820
3.0 February 5 Atlanta Thrashers Verizon Center 1878
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
)
3 rows from member_attendance table:
Member_ID Performance_ID Num_of_Pieces
11 3 2
7 2 3
4 6 4
|
performance_attendance | Show the attendances of the performances at location "TD Garden" or "Bell Centre" | SELECT Attendance FROM performance WHERE LOCATION = "TD Garden" OR LOCATION = "Bell Centre" | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
)
3 rows from member table:
Member_ID Name Nationality Role
1 Wilfredo Ruiz Uruguay Prime Violin
2 Luis González Argentina Violin
3 Héctor Campana Argentina Violin
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
)
3 rows from performance table:
Performance_ID Date Host Location Attendance
1.0 February 2 Boston Bruins TD Garden 165
2.0 February 4 New York Rangers Madison Square Garden 1820
3.0 February 5 Atlanta Thrashers Verizon Center 1878
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
)
3 rows from member_attendance table:
Member_ID Performance_ID Num_of_Pieces
11 3 2
7 2 3
4 6 4
|
performance_attendance | What is the average number of attendees for performances? | SELECT avg(Attendance) FROM performance | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
)
3 rows from member table:
Member_ID Name Nationality Role
1 Wilfredo Ruiz Uruguay Prime Violin
2 Luis González Argentina Violin
3 Héctor Campana Argentina Violin
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
)
3 rows from performance table:
Performance_ID Date Host Location Attendance
1.0 February 2 Boston Bruins TD Garden 165
2.0 February 4 New York Rangers Madison Square Garden 1820
3.0 February 5 Atlanta Thrashers Verizon Center 1878
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
)
3 rows from member_attendance table:
Member_ID Performance_ID Num_of_Pieces
11 3 2
7 2 3
4 6 4
|
performance_attendance | What is the date of the performance with the highest number of attendees? | SELECT Date FROM performance ORDER BY Attendance DESC LIMIT 1 | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
)
3 rows from member table:
Member_ID Name Nationality Role
1 Wilfredo Ruiz Uruguay Prime Violin
2 Luis González Argentina Violin
3 Héctor Campana Argentina Violin
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
)
3 rows from performance table:
Performance_ID Date Host Location Attendance
1.0 February 2 Boston Bruins TD Garden 165
2.0 February 4 New York Rangers Madison Square Garden 1820
3.0 February 5 Atlanta Thrashers Verizon Center 1878
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
)
3 rows from member_attendance table:
Member_ID Performance_ID Num_of_Pieces
11 3 2
7 2 3
4 6 4
|
performance_attendance | Show different locations and the number of performances at each location. | SELECT LOCATION , COUNT(*) FROM performance GROUP BY LOCATION | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
)
3 rows from member table:
Member_ID Name Nationality Role
1 Wilfredo Ruiz Uruguay Prime Violin
2 Luis González Argentina Violin
3 Héctor Campana Argentina Violin
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
)
3 rows from performance table:
Performance_ID Date Host Location Attendance
1.0 February 2 Boston Bruins TD Garden 165
2.0 February 4 New York Rangers Madison Square Garden 1820
3.0 February 5 Atlanta Thrashers Verizon Center 1878
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
)
3 rows from member_attendance table:
Member_ID Performance_ID Num_of_Pieces
11 3 2
7 2 3
4 6 4
|
performance_attendance | Show the most common location of performances. | SELECT LOCATION FROM performance GROUP BY LOCATION ORDER BY COUNT(*) DESC LIMIT 1 | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
)
3 rows from member table:
Member_ID Name Nationality Role
1 Wilfredo Ruiz Uruguay Prime Violin
2 Luis González Argentina Violin
3 Héctor Campana Argentina Violin
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
)
3 rows from performance table:
Performance_ID Date Host Location Attendance
1.0 February 2 Boston Bruins TD Garden 165
2.0 February 4 New York Rangers Madison Square Garden 1820
3.0 February 5 Atlanta Thrashers Verizon Center 1878
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
)
3 rows from member_attendance table:
Member_ID Performance_ID Num_of_Pieces
11 3 2
7 2 3
4 6 4
|
performance_attendance | Show the locations that have at least two performances. | SELECT LOCATION FROM performance GROUP BY LOCATION HAVING COUNT(*) >= 2 | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
)
3 rows from member table:
Member_ID Name Nationality Role
1 Wilfredo Ruiz Uruguay Prime Violin
2 Luis González Argentina Violin
3 Héctor Campana Argentina Violin
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
)
3 rows from performance table:
Performance_ID Date Host Location Attendance
1.0 February 2 Boston Bruins TD Garden 165
2.0 February 4 New York Rangers Madison Square Garden 1820
3.0 February 5 Atlanta Thrashers Verizon Center 1878
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
)
3 rows from member_attendance table:
Member_ID Performance_ID Num_of_Pieces
11 3 2
7 2 3
4 6 4
|
performance_attendance | Show the locations that have both performances with more than 2000 attendees and performances with less than 1000 attendees. | SELECT LOCATION FROM performance WHERE Attendance > 2000 INTERSECT SELECT LOCATION FROM performance WHERE Attendance < 1000 | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
)
3 rows from member table:
Member_ID Name Nationality Role
1 Wilfredo Ruiz Uruguay Prime Violin
2 Luis González Argentina Violin
3 Héctor Campana Argentina Violin
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
)
3 rows from performance table:
Performance_ID Date Host Location Attendance
1.0 February 2 Boston Bruins TD Garden 165
2.0 February 4 New York Rangers Madison Square Garden 1820
3.0 February 5 Atlanta Thrashers Verizon Center 1878
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
)
3 rows from member_attendance table:
Member_ID Performance_ID Num_of_Pieces
11 3 2
7 2 3
4 6 4
|
performance_attendance | Show the names of members and the location of the performances they attended. | SELECT T2.Name , T3.Location FROM member_attendance AS T1 JOIN member AS T2 ON T1.Member_ID = T2.Member_ID JOIN performance AS T3 ON T1.Performance_ID = T3.Performance_ID | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
)
3 rows from member table:
Member_ID Name Nationality Role
1 Wilfredo Ruiz Uruguay Prime Violin
2 Luis González Argentina Violin
3 Héctor Campana Argentina Violin
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
)
3 rows from performance table:
Performance_ID Date Host Location Attendance
1.0 February 2 Boston Bruins TD Garden 165
2.0 February 4 New York Rangers Madison Square Garden 1820
3.0 February 5 Atlanta Thrashers Verizon Center 1878
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
)
3 rows from member_attendance table:
Member_ID Performance_ID Num_of_Pieces
11 3 2
7 2 3
4 6 4
|
performance_attendance | Show the names of members and the location of performances they attended in ascending alphabetical order of their names. | SELECT T2.Name , T3.Location FROM member_attendance AS T1 JOIN member AS T2 ON T1.Member_ID = T2.Member_ID JOIN performance AS T3 ON T1.Performance_ID = T3.Performance_ID ORDER BY T2.Name ASC | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
)
3 rows from member table:
Member_ID Name Nationality Role
1 Wilfredo Ruiz Uruguay Prime Violin
2 Luis González Argentina Violin
3 Héctor Campana Argentina Violin
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
)
3 rows from performance table:
Performance_ID Date Host Location Attendance
1.0 February 2 Boston Bruins TD Garden 165
2.0 February 4 New York Rangers Madison Square Garden 1820
3.0 February 5 Atlanta Thrashers Verizon Center 1878
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
)
3 rows from member_attendance table:
Member_ID Performance_ID Num_of_Pieces
11 3 2
7 2 3
4 6 4
|
performance_attendance | Show the dates of performances with attending members whose roles are "Violin". | SELECT T3.Date FROM member_attendance AS T1 JOIN member AS T2 ON T1.Member_ID = T2.Member_ID JOIN performance AS T3 ON T1.Performance_ID = T3.Performance_ID WHERE T2.Role = "Violin" | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
)
3 rows from member table:
Member_ID Name Nationality Role
1 Wilfredo Ruiz Uruguay Prime Violin
2 Luis González Argentina Violin
3 Héctor Campana Argentina Violin
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
)
3 rows from performance table:
Performance_ID Date Host Location Attendance
1.0 February 2 Boston Bruins TD Garden 165
2.0 February 4 New York Rangers Madison Square Garden 1820
3.0 February 5 Atlanta Thrashers Verizon Center 1878
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
)
3 rows from member_attendance table:
Member_ID Performance_ID Num_of_Pieces
11 3 2
7 2 3
4 6 4
|
performance_attendance | Show the names of members and the dates of performances they attended in descending order of attendance of the performances. | SELECT T2.Name , T3.Date FROM member_attendance AS T1 JOIN member AS T2 ON T1.Member_ID = T2.Member_ID JOIN performance AS T3 ON T1.Performance_ID = T3.Performance_ID ORDER BY T3.Attendance DESC | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
)
3 rows from member table:
Member_ID Name Nationality Role
1 Wilfredo Ruiz Uruguay Prime Violin
2 Luis González Argentina Violin
3 Héctor Campana Argentina Violin
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
)
3 rows from performance table:
Performance_ID Date Host Location Attendance
1.0 February 2 Boston Bruins TD Garden 165
2.0 February 4 New York Rangers Madison Square Garden 1820
3.0 February 5 Atlanta Thrashers Verizon Center 1878
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
)
3 rows from member_attendance table:
Member_ID Performance_ID Num_of_Pieces
11 3 2
7 2 3
4 6 4
|
performance_attendance | List the names of members who did not attend any performance. | SELECT Name FROM member WHERE Member_ID NOT IN (SELECT Member_ID FROM member_attendance) | CREATE TABLE "member" (
"Member_ID" text,
"Name" text,
"Nationality" text,
"Role" text,
PRIMARY KEY ("Member_ID")
)
3 rows from member table:
Member_ID Name Nationality Role
1 Wilfredo Ruiz Uruguay Prime Violin
2 Luis González Argentina Violin
3 Héctor Campana Argentina Violin
CREATE TABLE "performance" (
"Performance_ID" real,
"Date" text,
"Host" text,
"Location" text,
"Attendance" int,
PRIMARY KEY ("Performance_ID")
)
3 rows from performance table:
Performance_ID Date Host Location Attendance
1.0 February 2 Boston Bruins TD Garden 165
2.0 February 4 New York Rangers Madison Square Garden 1820
3.0 February 5 Atlanta Thrashers Verizon Center 1878
CREATE TABLE "member_attendance" (
"Member_ID" int,
"Performance_ID" int,
"Num_of_Pieces" int,
PRIMARY KEY ("Member_ID","Performance_ID"),
FOREIGN KEY ("Member_ID") REFERENCES `member`("Member_ID"),
FOREIGN KEY ("Performance_ID") REFERENCES `performance`("Performance_ID")
)
3 rows from member_attendance table:
Member_ID Performance_ID Num_of_Pieces
11 3 2
7 2 3
4 6 4
|
college_2 | Find the buildings which have rooms with capacity more than 50. | SELECT DISTINCT building FROM classroom WHERE capacity > 50 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | What are the distinct buildings with capacities of greater than 50? | SELECT DISTINCT building FROM classroom WHERE capacity > 50 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Count the number of rooms that are not in the Lamberton building. | SELECT count(*) FROM classroom WHERE building != 'Lamberton' | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | How many classrooms are not in Lamberton? | SELECT count(*) FROM classroom WHERE building != 'Lamberton' | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | What is the name and building of the departments whose budget is more than the average budget? | SELECT dept_name , building FROM department WHERE budget > (SELECT avg(budget) FROM department) | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Give the name and building of the departments with greater than average budget. | SELECT dept_name , building FROM department WHERE budget > (SELECT avg(budget) FROM department) | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Find the room number of the rooms which can sit 50 to 100 students and their buildings. | SELECT building , room_number FROM classroom WHERE capacity BETWEEN 50 AND 100 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | What are the room numbers and corresponding buildings for classrooms which can seat between 50 to 100 students? | SELECT building , room_number FROM classroom WHERE capacity BETWEEN 50 AND 100 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Find the name and building of the department with the highest budget. | SELECT dept_name , building FROM department ORDER BY budget DESC LIMIT 1 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | What is the department name and corresponding building for the department with the greatest budget? | SELECT dept_name , building FROM department ORDER BY budget DESC LIMIT 1 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | What is the name of the student who has the highest total credits in the History department. | SELECT name FROM student WHERE dept_name = 'History' ORDER BY tot_cred DESC LIMIT 1 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Give the name of the student in the History department with the most credits. | SELECT name FROM student WHERE dept_name = 'History' ORDER BY tot_cred DESC LIMIT 1 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | How many rooms does the Lamberton building have? | SELECT count(*) FROM classroom WHERE building = 'Lamberton' | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Count the number of classrooms in Lamberton. | SELECT count(*) FROM classroom WHERE building = 'Lamberton' | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | How many students have advisors? | SELECT count(DISTINCT s_id) FROM advisor | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Count the number of students who have advisors. | SELECT count(DISTINCT s_id) FROM advisor | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | How many departments offer courses? | SELECT count(DISTINCT dept_name) FROM course | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Count the number of departments which offer courses. | SELECT count(DISTINCT dept_name) FROM course | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | How many different courses offered by Physics department? | SELECT count(DISTINCT course_id) FROM course WHERE dept_name = 'Physics' | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Count the number of courses in the Physics department. | SELECT count(DISTINCT course_id) FROM course WHERE dept_name = 'Physics' | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Find the title of courses that have two prerequisites? | 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 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | What are the titles for courses with two prerequisites? | 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 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Find the title, credit, and department name of courses that have more than one prerequisites? | 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 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | What is the title, credit value, and department name for courses with more than one prerequisite? | 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 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | How many courses that do not have prerequisite? | SELECT count(*) FROM course WHERE course_id NOT IN (SELECT course_id FROM prereq) | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Count the number of courses without prerequisites. | SELECT count(*) FROM course WHERE course_id NOT IN (SELECT course_id FROM prereq) | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Find the name of the courses that do not have any prerequisite? | SELECT title FROM course WHERE course_id NOT IN (SELECT course_id FROM prereq) | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | What are the titles of courses without prerequisites? | SELECT title FROM course WHERE course_id NOT IN (SELECT course_id FROM prereq) | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | How many different instructors have taught some course? | SELECT COUNT (DISTINCT id) FROM teaches | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Count the number of distinct instructors who have taught a course. | SELECT COUNT (DISTINCT id) FROM teaches | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Find the total budgets of the Marketing or Finance department. | SELECT sum(budget) FROM department WHERE dept_name = 'Marketing' OR dept_name = 'Finance' | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | What is the sum of budgets of the Marketing and Finance departments? | SELECT sum(budget) FROM department WHERE dept_name = 'Marketing' OR dept_name = 'Finance' | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Find the department name of the instructor whose name contains 'Soisalon'. | SELECT dept_name FROM instructor WHERE name LIKE '%Soisalon%' | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | What is the name of the department with an instructure who has a name like 'Soisalon'? | SELECT dept_name FROM instructor WHERE name LIKE '%Soisalon%' | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | How many rooms whose capacity is less than 50 does the Lamberton building have? | SELECT count(*) FROM classroom WHERE building = 'Lamberton' AND capacity < 50 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Count the number of rooms in Lamberton with capacity lower than 50. | SELECT count(*) FROM classroom WHERE building = 'Lamberton' AND capacity < 50 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Find the name and budget of departments whose budgets are more than the average budget. | SELECT dept_name , budget FROM department WHERE budget > (SELECT avg(budget) FROM department) | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | What are the names and budgets of departments with budgets greater than the average? | SELECT dept_name , budget FROM department WHERE budget > (SELECT avg(budget) FROM department) | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | what is the name of the instructor who is in Statistics department and earns the lowest salary? | SELECT name FROM instructor WHERE dept_name = 'Statistics' ORDER BY salary LIMIT 1 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Give the name of the lowest earning instructor in the Statistics department. | SELECT name FROM instructor WHERE dept_name = 'Statistics' ORDER BY salary LIMIT 1 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Find the title of course that is provided by both Statistics and Psychology departments. | SELECT title FROM course WHERE dept_name = 'Statistics' INTERSECT SELECT title FROM course WHERE dept_name = 'Psychology' | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | What is the title of a course that is listed in both the Statistics and Psychology departments? | SELECT title FROM course WHERE dept_name = 'Statistics' INTERSECT SELECT title FROM course WHERE dept_name = 'Psychology' | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Find the title of course that is provided by Statistics but not Psychology departments. | SELECT title FROM course WHERE dept_name = 'Statistics' EXCEPT SELECT title FROM course WHERE dept_name = 'Psychology' | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | What are the titles of courses that are in the Statistics department but not the Psychology department? | SELECT title FROM course WHERE dept_name = 'Statistics' EXCEPT SELECT title FROM course WHERE dept_name = 'Psychology' | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Find the id of instructors who taught a class in Fall 2009 but not in Spring 2010. | SELECT id FROM teaches WHERE semester = 'Fall' AND YEAR = 2009 EXCEPT SELECT id FROM teaches WHERE semester = 'Spring' AND YEAR = 2010 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | What are the ids of instructors who taught in the Fall of 2009 but not in the Spring of 2010? | SELECT id FROM teaches WHERE semester = 'Fall' AND YEAR = 2009 EXCEPT SELECT id FROM teaches WHERE semester = 'Spring' AND YEAR = 2010 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Find the name of students who took any class in the years of 2009 and 2010. | SELECT DISTINCT T1.name FROM student AS T1 JOIN takes AS T2 ON T1.id = T2.id WHERE YEAR = 2009 OR YEAR = 2010 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | What are the names of the students who took classes in 2009 or 2010? | SELECT DISTINCT T1.name FROM student AS T1 JOIN takes AS T2 ON T1.id = T2.id WHERE YEAR = 2009 OR YEAR = 2010 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Find the names of the top 3 departments that provide the largest amount of courses? | SELECT dept_name FROM course GROUP BY dept_name ORDER BY count(*) DESC LIMIT 3 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | What are the names of the 3 departments with the most courses? | SELECT dept_name FROM course GROUP BY dept_name ORDER BY count(*) DESC LIMIT 3 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Find the name of the department that offers the highest total credits? | SELECT dept_name FROM course GROUP BY dept_name ORDER BY sum(credits) DESC LIMIT 1 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | What is the name of the department with the most credits? | SELECT dept_name FROM course GROUP BY dept_name ORDER BY sum(credits) DESC LIMIT 1 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | List the names of all courses ordered by their titles and credits. | SELECT title FROM course ORDER BY title , credits | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Given the titles of all courses, in order of titles and credits. | SELECT title FROM course ORDER BY title , credits | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Which department has the lowest budget? | SELECT dept_name FROM department ORDER BY budget LIMIT 1 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Give the name of the department with the lowest budget. | SELECT dept_name FROM department ORDER BY budget LIMIT 1 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | List the names and buildings of all departments sorted by the budget from large to small. | SELECT dept_name , building FROM department ORDER BY budget DESC | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | What are the names and buildings of the deparments, sorted by budget descending? | SELECT dept_name , building FROM department ORDER BY budget DESC | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Who is the instructor with the highest salary? | SELECT name FROM instructor ORDER BY salary DESC LIMIT 1 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Give the name of the highest paid instructor. | SELECT name FROM instructor ORDER BY salary DESC LIMIT 1 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | List the information of all instructors ordered by their salary in ascending order. | SELECT * FROM instructor ORDER BY salary | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Give all information regarding instructors, in order of salary from least to greatest. | SELECT * FROM instructor ORDER BY salary | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Find the name of the students and their department names sorted by their total credits in ascending order. | SELECT name , dept_name FROM student ORDER BY tot_cred | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | What are the names of students and their respective departments, ordered by number of credits from least to greatest? | SELECT name , dept_name FROM student ORDER BY tot_cred | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | list in alphabetic order all course names and their instructors' names in year 2008. | 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 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Show all titles and their instructors' names for courses in 2008, in alphabetical order by title. | 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 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Find the name of instructors who are advising more than one student. | 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 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | What are the names of instructors who advise more than one student? | 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 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Find the name of the students who have more than one advisor? | 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 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | What are the names of students who have more than one advisor? | 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 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Find the number of rooms with more than 50 capacity for each building. | SELECT count(*) , building FROM classroom WHERE capacity > 50 GROUP BY building | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | How many rooms in each building have a capacity of over 50? | SELECT count(*) , building FROM classroom WHERE capacity > 50 GROUP BY building | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Find the maximum and average capacity among rooms in each building. | SELECT max(capacity) , avg(capacity) , building FROM classroom GROUP BY building | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | What are the greatest and average capacity for rooms in each building? | SELECT max(capacity) , avg(capacity) , building FROM classroom GROUP BY building | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Find the title of the course that is offered by more than one department. | SELECT title FROM course GROUP BY title HAVING count(*) > 1 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | What are the titles of courses that are offered in more than one department? | SELECT title FROM course GROUP BY title HAVING count(*) > 1 | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | Find the total credits of courses provided by different department. | SELECT sum(credits) , dept_name FROM course GROUP BY dept_name | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
college_2 | How many total credits are offered by each department? | SELECT sum(credits) , dept_name FROM course GROUP BY dept_name | CREATE TABLE classroom
(building varchar(15),
room_number varchar(7),
capacity numeric(4,0),
primary key (building, room_number)
)
3 rows from classroom table:
building room_number capacity
Lamberton 134 10
Chandler 375 10
Fairchild 145 27
CREATE TABLE department
(dept_name varchar(20),
building varchar(15),
budget numeric(12,2) check (budget > 0),
primary key (dept_name)
)
3 rows from department table:
dept_name building budget
Civil Eng. Chandler 255041.46
Biology Candlestick 647610.55
History Taylor 699140.86
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
)
3 rows from course table:
course_id title dept_name credits
787 C Programming Mech. Eng. 4
238 The Music of Donovan Mech. Eng. 3
608 Electron Microscopy Mech. Eng. 3
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
)
3 rows from instructor table:
ID name dept_name salary
63395 McKinnon Cybernetics 94333.99
78699 Pingr Statistics 59303.62
96895 Mird Marketing 119921.41
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
)
3 rows from section table:
course_id sec_id semester year building room_number time_slot_id
313 1 Fall 2010 Chandler 804 N
747 1 Spring 2004 Gates 314 K
443 1 Spring 2010 Whitman 434 O
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
)
3 rows from teaches table:
ID course_id sec_id semester year
34175 747 1 Spring 2004
3199 169 1 Spring 2007
6569 445 1 Spring 2001
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
)
3 rows from student table:
ID name dept_name tot_cred
24746 Schrefl History 4
79352 Rumat Finance 100
76672 Miliko Statistics 116
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
)
3 rows from takes table:
ID course_id sec_id semester year grade
65901 401 1 Fall 2003 C-
24932 802 1 Spring 2003 B-
61332 200 1 Spring 2007 A-
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
)
3 rows from advisor table:
s_ID i_ID
24746 19368
79352 95030
76672 22591
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)
)
3 rows from time_slot table:
time_slot_id day start_hr start_min end_hr end_min
A M 8 0 8 50
A W 8 0 8 50
A F 8 0 8 50
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)
)
3 rows from prereq table:
course_id prereq_id
376 130
760 169
403 345
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.