Dataset Viewer
Auto-converted to Parquet Duplicate
inputs
stringlengths
2.31k
4.19k
targets
stringlengths
20
640
_template_idx
int64
0
9
_task_source
stringclasses
1 value
_task_name
stringclasses
1 value
_template_type
stringclasses
2 values
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Q: Step 1: For each row in Manufacturers table, find the corresponding rows in Products table. Step 2: find Headquarter of the results of step 1 whose Products's Name equals James A: SELECT T1.Headquarter FROM Manufacturers AS T1 JOIN Products AS T2 ON T1.Code = T2.Manufacturer WHERE T2.Name = "James" **** Q: Step 1: For each row in appellations table, find the corresponding rows in wine table. Step 2: find the number of rows of each value of appellations's Appelation in the results of step 1. Step 3: find Winery in the results of step 1 whose corresponding value in step 2 is greater than or equals 4 A: SELECT T2.Winery FROM appellations AS T1 JOIN wine AS T2 ON T1.Appelation = T2.Appelation GROUP BY T1.Appelation HAVING Count ( * ) > = 4 **** Q: Step 1: find the minimum date_assigned_to in Staff_Department_Assignments table. Step 2: find the staff_id of Staff_Department_Assignments table whose date_assigned_to greater than the results of step 1 A:
SELECT staff_id FROM Staff_Department_Assignments WHERE date_assigned_to > ( SELECT Min ( date_assigned_to ) FROM Staff_Department_Assignments ) ****
4
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Let me give you an example: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value The answer to this example can be: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Here is why: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. OK. solve this: Step 1: find the Carrier of phone table for which Memory_in_G greater than 32. Step 2: find the Carrier of phone table for which Memory_in_G less than 64. Step 3: show the rows that are in both the results of step 1 and the results of step 2 Answer:
SELECT Carrier FROM phone WHERE Memory_in_G > 32 INTERSECT SELECT Carrier FROM phone WHERE Memory_in_G < 64
8
NIv2
task077_splash_explanation_to_sql
fs_opt
instruction: In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. question: find the average rating and the average resolution in song table answer: SELECT Avg ( rating ) , Avg ( resolution ) FROM song question: find the ClubName of Club table for which ClubName equals AKW answer: SELECT ClubName FROM Club WHERE ClubName = "AKW" question: Step 1: find the rows of jobs table for which MAX_SALARY greater than 40000. Step 2: find the JOB_TITLE of jobs table for which MAX_SALARY greater than 12000. Step 3: show the rows that are in both the results of step 1 and the results of step 2 answer:
SELECT * FROM jobs WHERE MAX_SALARY > 40000 INTERSECT SELECT JOB_TITLE FROM jobs WHERE MAX_SALARY > 12000
9
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Let me give you an example: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value The answer to this example can be: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Here is why: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. OK. solve this: find the title of course table for which dept_name equals Mobile Computing Answer:
SELECT title FROM course WHERE dept_name = "Mobile Computing"
8
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. [EX Q]: Step 1: For each row in bank table, find the corresponding rows in customer table. Step 2: find bname of the results of step 1 whose credit_score less than 100 [EX A]: SELECT T1.bname FROM bank AS T1 JOIN customer AS T2 ON T1.branch_ID = T2.branch_ID WHERE T2.credit_score < 100 [EX Q]: Step 1: For each row in team table, find the corresponding rows in match_season table. Step 2: find without repetition Season, Name, Name of the results of step 1 [EX A]: SELECT DISTINCT T2.Season , T1.Name , T1.Name FROM team AS T1 JOIN match_season AS T2 ON T1.Team_id = T2.Team [EX Q]: find the Name of wine table for which Year greater than 2008 [EX A]:
SELECT Name FROM wine WHERE Year > 2008
6
NIv2
task077_splash_explanation_to_sql
fs_opt
Given the task definition, example input & output, solve the new input case. In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Example: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Output: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. New input case for you: Step 1: find the number of rows of each value of customer_id in customer table. Step 2: find first_name, last_name, customer_id in customer table whose corresponding value in step 1 is greater than or equals 1 Output:
SELECT first_name , last_name , customer_id FROM customer GROUP BY customer_id HAVING Count ( * ) > = 1
1
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Example Input: find the name, Location, Product of enzyme table for which name contains inhibitor Example Output: SELECT name , Location , Product FROM enzyme WHERE name LIKE "inhibitor" Example Input: Step 1: For each row in trip table, find the corresponding rows in weather table. Step 2: find start_date of the results of step 1 whose min_dew_point_f greater than 85 Example Output: SELECT T1.start_date FROM trip AS T1 JOIN weather AS T2 WHERE T2.min_dew_point_f > 85 Example Input: find the Hight_definition_TV, Country of TV_Channel table for which Language not equals English Example Output:
SELECT Hight_definition_TV , Country FROM TV_Channel WHERE Language ! = "English"
3
NIv2
task077_splash_explanation_to_sql
fs_opt
Teacher: In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Teacher: Now, understand the problem? If you are still confused, see the following example: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Solution: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Reason: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. Now, solve this instance: Step 1: For each row in musical table, find the corresponding rows in actor table. Step 2: find Character of the results of step 1 whose Award equals Tony Award or actor's Name equals Cleavant Derricks Student:
SELECT T2.Character FROM musical AS T1 JOIN actor AS T2 WHERE T1.Award = "Tony Award" OR T2.Name = "Cleavant Derricks"
2
NIv2
task077_splash_explanation_to_sql
fs_opt
You will be given a definition of a task first, then an example. Follow the example to solve a new instance of the task. In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Solution: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Why? This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. New input: find the email, phone of customers table for which last_name equals Astrid Solution:
SELECT email , phone FROM customers WHERE last_name = "Astrid"
0
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Example input: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Example output: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Example explanation: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. Q: find the Hight_definition_TV, Country of TV_Channel table for which Language not equals English A:
SELECT Hight_definition_TV , Country FROM TV_Channel WHERE Language ! = "English"
3
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. One example: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Solution is here: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Explanation: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. Now, solve this: Step 1: find the Actor_ID of actor table. Step 2: find the Name of actor table whose Name not one of the results of step 1 Solution:
SELECT Name FROM actor WHERE Name NOT IN ( SELECT Actor_ID FROM actor )
6
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Let me give you an example: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value The answer to this example can be: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Here is why: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. OK. solve this: Step 1: find the number of rows in weather table whose min_humidity greater than 8. Step 2: find the mean_sea_level_pressure_inches of weather table for which max_temperature_f less than 50. Step 3: show the rows that are in both the results of step 1 and the results of step 2 Answer:
SELECT Count ( * ) FROM weather WHERE min_humidity > 8 INTERSECT SELECT mean_sea_level_pressure_inches FROM weather WHERE max_temperature_f < 50
8
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. One example is below. Q: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value A: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Rationale: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. Q: find the Venue of debate table ordered ascending by Venue A:
SELECT Venue FROM debate ORDER BY Venue Asc
9
NIv2
task077_splash_explanation_to_sql
fs_opt
Teacher: In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Teacher: Now, understand the problem? If you are still confused, see the following example: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Solution: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Reason: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. Now, solve this instance: Step 1: find the number of rows of each value of Appelation in wine table. Step 2: find Appelation in wine table whose corresponding value in step 1 is less than or equals 3 Student:
SELECT Appelation FROM wine GROUP BY Appelation HAVING Count ( * ) < = 3
2
NIv2
task077_splash_explanation_to_sql
fs_opt
instruction: In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. question: Step 1: For each row in Student_Course_Enrolment table, find corresponding rows in Students table and in Student_Tests_Taken table. Step 2: find date_of_latest_logon, test_result of the results of step 1 answer: SELECT T1.date_of_latest_logon , T3.test_result FROM Students AS T1 JOIN Student_Course_Enrolment AS T2 ON T1.student_id = T2.student_id JOIN Student_Tests_Taken AS T3 ON T2.registration_id = T3.registration_id question: Step 1: For each row in Person table, find the corresponding rows in PersonFriend table. Step 2: find the summation of age of each value of friend in the results of step 1. Step 3: find PersonFriend's name in the results of step 1 whose corresponding value in step 2 is greater than or equals engineer answer: SELECT T2.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name GROUP BY T2.friend HAVING Sum ( T1.age ) > = "engineer" question: find without repetition the LName of Student table for which Advisor not equals 2192 answer:
SELECT DISTINCT LName FROM Student WHERE Advisor ! = 2192
9
NIv2
task077_splash_explanation_to_sql
fs_opt
Part 1. Definition In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Part 2. Example Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Answer: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Explanation: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. Part 3. Exercise Step 1: find the yCard of Player table. Step 2: find the summation of enr in College table whose state not one of the results of step 1 Answer:
SELECT Sum ( T1.enr ) FROM College AS T1 WHERE T1.state NOT IN ( SELECT T2.yCard FROM Player AS T2 )
7
NIv2
task077_splash_explanation_to_sql
fs_opt
TASK DEFINITION: In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. PROBLEM: find the Name, Event of wrestler table SOLUTION: SELECT Name , Event FROM wrestler PROBLEM: Step 1: For each row in Campuses table, find corresponding rows in csu_fees table and in faculty table. Step 2: find the average CampusFee in the results of step 1 whose csu_fees's Year equals 2005 and Faculty equals 357.1 SOLUTION: SELECT Avg ( T2.CampusFee ) FROM Campuses AS T1 JOIN csu_fees AS T2 ON T2.Campus = T1.Id JOIN faculty AS T3 ON T1.Id = T3.Campus WHERE T2.Year = 2005 AND T3.Faculty = 357.1 PROBLEM: find the name of student table SOLUTION:
SELECT name FROM student
8
NIv2
task077_splash_explanation_to_sql
fs_opt
You will be given a definition of a task first, then an example. Follow the example to solve a new instance of the task. In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Solution: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Why? This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. New input: Step 1: For each row in genre table, find the corresponding rows in song table. Step 2: find song_name of the results of step 1 whose languages equals modern or g_name equals english Solution:
SELECT T2.song_name FROM genre AS T1 JOIN song AS T2 ON T1.g_name = T2.genre_is WHERE T2.languages = "modern" OR T1.g_name = "english"
0
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Example: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Example solution: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Example explanation: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. Problem: Step 1: For each row in list table, find the corresponding rows in teachers table. Step 2: find the number of rows of each value of Classroom in the results of step 1. Step 3: find FirstName, LastName of step 1 results with largest value in the results of step 2
Solution: SELECT T1.FirstName , T2.LastName FROM list AS T1 JOIN teachers AS T2 GROUP BY T1.Classroom ORDER BY Count ( * ) Desc LIMIT 1
5
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. One example: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Solution is here: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Explanation: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. Now, solve this: Step 1: find the cust_name of customer table. Step 2: find the cust_name of customer table for which acc_type equals Mortgages. Step 3: show the rows that are in the results of step 1 but not in the results of step 2 Solution:
SELECT cust_name FROM customer EXCEPT SELECT cust_name FROM customer WHERE acc_type = "Mortgages"
6
NIv2
task077_splash_explanation_to_sql
fs_opt
Given the task definition, example input & output, solve the new input case. In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Example: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Output: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. New input case for you: Step 1: find the number of rows of each value of name in aircraft table. Step 2: find name in aircraft table whose corresponding value in step 1 is greater than or equals 2 Output:
SELECT name FROM aircraft GROUP BY name HAVING Count ( * ) > = 2
1
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. -------- Question: find the distance, distance of flight table with largest value of price Answer: SELECT distance , distance FROM flight ORDER BY price Desc LIMIT 1 Question: Step 1: For each row in Problems table, find the corresponding rows in Problem_Log table. Step 2: find problem_log_id, date_problem_reported of the results of step 1 whose Problem_Log's problem_id equals 10 Answer: SELECT T1.problem_log_id , T2.date_problem_reported FROM Problem_Log AS T1 JOIN Problems AS T2 ON T1.problem_id = T2.problem_id WHERE T1.problem_id = 10 Question: Step 1: find the name of Highschooler table for which grade equals 9. Step 2: find the name of Highschooler table for which grade equals 9. Step 3: show the rows that are in both the results of step 1 and the results of step 2 Answer:
SELECT name FROM Highschooler WHERE grade = 9 INTERSECT SELECT name FROM Highschooler WHERE grade = 9
7
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Example input: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Example output: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Example explanation: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. Q: find FIRST_NAME, LAST_NAME, SALARY, DEPARTMENT_ID of employees table whose FIRST_NAME equals M or LAST_NAME equals King A:
SELECT FIRST_NAME , LAST_NAME , SALARY , DEPARTMENT_ID FROM employees WHERE FIRST_NAME = "M" OR LAST_NAME = "King"
3
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Let me give you an example: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value The answer to this example can be: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Here is why: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. OK. solve this: find the number of rows in sqlite_sequence table whose seq equals Billy Cobham Answer:
SELECT Count ( * ) FROM sqlite_sequence WHERE seq = "Billy Cobham"
8
NIv2
task077_splash_explanation_to_sql
fs_opt
TASK DEFINITION: In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. PROBLEM: Step 1: For each row in Staff table, find the corresponding rows in Engineer_Visits table. Step 2: find each value of contact_staff_id in the results of step 1 along with the number of the corresponding rows to each value SOLUTION: SELECT T1.staff_name , Count ( * ) FROM Staff AS T1 JOIN Engineer_Visits AS T2 ON T1.staff_id = T2.contact_staff_id GROUP BY T2.contact_staff_id PROBLEM: Step 1: find the characteristic_name, other_characteristic_details, characteristic_type_code of Characteristics table for which characteristic_name equals slow. Step 2: For each row in Characteristics table, find the corresponding rows in Product_Characteristics table. Step 3: find the number of rows of each value of Product_Characteristics's characteristic_id in the results of step 2. Step 4: find characteristic_name, other_characteristic_details, characteristic_data_type in the results of step 3 whose corresponding value in step 3 is equals 1. Step 5: show the rows that are in the results of step 1 but not in the results of step 4 SOLUTION: SELECT T1.characteristic_name , T1.other_characteristic_details , T1.characteristic_type_code FROM Characteristics AS T1 WHERE T1.characteristic_name = "slow" EXCEPT SELECT T1.characteristic_name , T1.other_characteristic_details , T1.characteristic_data_type FROM Characteristics AS T1 JOIN Product_Characteristics AS T2 ON T1.characteristic_id = T2.characteristic_id GROUP BY T2.characteristic_id HAVING Count ( * ) = 1 PROBLEM: find each value of employee_id in Circulation_History table along with the number of the corresponding rows to each value SOLUTION:
SELECT employee_id , Count ( * ) FROM Circulation_History GROUP BY employee_id
8
NIv2
task077_splash_explanation_to_sql
fs_opt
Detailed Instructions: In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. See one example below: Problem: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Solution: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Explanation: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. Problem: Step 1: For each row in jobs table, find the corresponding rows in employees table. Step 2: find FIRST_NAME, HIRE_DATE, SALARY of the results of step 1 whose JOB_TITLE not equals M Solution:
SELECT T2.FIRST_NAME , T2.HIRE_DATE , T2.SALARY FROM jobs AS T1 JOIN employees AS T2 ON T1.JOB_ID = T2.JOB_ID WHERE T1.JOB_TITLE ! = "M"
4
NIv2
task077_splash_explanation_to_sql
fs_opt
Teacher: In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Teacher: Now, understand the problem? If you are still confused, see the following example: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Solution: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Reason: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. Now, solve this instance: Step 1: find the rows of employees table for which SALARY greater than 24000. Step 2: find the JOB_TITLE of jobs table for which MIN_SALARY greater than 12000. Step 3: show the rows that are in both the results of step 1 and the results of step 2 Student:
SELECT * FROM employees AS T1 WHERE T1.SALARY > 24000 INTERSECT SELECT T2.JOB_TITLE FROM jobs AS T2 WHERE T2.MIN_SALARY > 12000
2
NIv2
task077_splash_explanation_to_sql
fs_opt
TASK DEFINITION: In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. PROBLEM: find the name, Location, Product of enzyme table for which name contains inhibitor SOLUTION: SELECT name , Location , Product FROM enzyme WHERE name LIKE "inhibitor" PROBLEM: find rows of jobs table whose MIN_SALARY greater than 2500 and MAX_SALARY less than 40000 SOLUTION: SELECT * FROM jobs WHERE MIN_SALARY > 2500 AND MAX_SALARY < 40000 PROBLEM: Step 1: For each row in jobs table, find the corresponding rows in employees table. Step 2: find FIRST_NAME, HIRE_DATE, SALARY of the results of step 1 whose JOB_TITLE not equals M SOLUTION:
SELECT T2.FIRST_NAME , T2.HIRE_DATE , T2.SALARY FROM jobs AS T1 JOIN employees AS T2 ON T1.JOB_ID = T2.JOB_ID WHERE T1.JOB_TITLE ! = "M"
8
NIv2
task077_splash_explanation_to_sql
fs_opt
Given the task definition, example input & output, solve the new input case. In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Example: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Output: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. New input case for you: Step 1: find the AllergyType of Allergy_Type table. Step 2: find the average Age in Student table whose Sex one of the results of step 1 Output:
SELECT Avg ( T1.Age ) FROM Student AS T1 WHERE T1.Sex IN ( SELECT T2.AllergyType FROM Allergy_Type AS T2 )
1
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Ex Input: find the number of rows in faculty table whose Year equals 2004 and Year equals San Francisco State University Ex Output: SELECT Count ( * ) FROM faculty WHERE Year = "San Francisco State University" AND Year = 2004 Ex Input: find without repetition the Name of mountain table for which Country equals West Germany Ex Output: SELECT DISTINCT Name FROM mountain WHERE Country = "West Germany" Ex Input: Step 1: find the number of rows of each value of Department in Affiliated_With table. Step 2: find Department of Affiliated_With table with largest value in the results of step 1 Ex Output:
SELECT Department FROM Affiliated_With GROUP BY Department ORDER BY Count ( * ) Desc LIMIT 1
1
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Example input: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Example output: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Example explanation: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. Q: Step 1: find the first_name of Staff table. Step 2: find the first_name of Staff table. Step 3: show the rows that are in the results of step 1 but not in the results of step 2 A:
SELECT first_name FROM Staff EXCEPT SELECT first_name FROM Staff
3
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Q: find the Region, Population of country table A: SELECT Region , Population FROM country **** Q: Step 1: find the number of rows of each value of breed_name in Breeds table. Step 2: find breed_name of Breeds table with largest value in the results of step 1 A: SELECT breed_name FROM Breeds GROUP BY breed_name ORDER BY Count ( * ) Desc LIMIT 1 **** Q: Step 1: For each row in Rooms table, find the corresponding rows in Reservations table. Step 2: find roomName of the results of step 1 whose Rate equals 60 A:
SELECT T1.roomName FROM Rooms AS T1 JOIN Reservations AS T2 ON T1.RoomId = T2.Room WHERE T2.Rate = 60 ****
4
NIv2
task077_splash_explanation_to_sql
fs_opt
Part 1. Definition In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Part 2. Example Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Answer: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Explanation: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. Part 3. Exercise Step 1: For each row in Students table, find the corresponding rows in Student_Course_Enrolment table. Step 2: find date_of_enrolment, date_of_latest_logon of the results of step 1 whose family_name equals Zieme and personal_name equals Bernie Answer:
SELECT T2.date_of_enrolment , T1.date_of_latest_logon FROM Students AS T1 JOIN Student_Course_Enrolment AS T2 ON T1.student_id = T2.student_id WHERE T1.family_name = "Zieme" AND T1.personal_name = "Bernie"
7
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Example input: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Example output: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Example explanation: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. Q: Step 1: For each row in Apartments table, find the corresponding rows in Apartment_Bookings table. Step 2: find apt_number of the results of step 1 whose booking_status_code equals 0. Step 3: For each row in Apartments table, find corresponding rows in Apartment_Buildings table and in Apartment_Bookings table. Step 4: find building_manager of the results of step 3 whose booking_status_code equals 1. Step 5: show the rows that are in both the results of step 2 and the results of step 4 A:
SELECT T1.apt_number FROM Apartments AS T1 JOIN Apartment_Bookings AS T2 ON T1.apt_id = T2.apt_id WHERE T2.booking_status_code = 0 INTERSECT SELECT T3.building_manager FROM Apartment_Buildings AS T3 JOIN Apartments AS T1 ON T3.building_id = T1.building_id JOIN Apartment_Bookings AS T2 ON T1.apt_id = T2.apt_id WHERE T2.booking_status_code = 1
3
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. One example is below. Q: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value A: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Rationale: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. Q: Step 1: find the number of rows of each value of skill_id in Skills table. Step 2: find skill_id, skill_description of Skills table with largest value in the results of step 1 A:
SELECT skill_id , skill_description FROM Skills GROUP BY skill_id ORDER BY Count ( * ) Desc LIMIT 1
9
NIv2
task077_splash_explanation_to_sql
fs_opt
TASK DEFINITION: In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. PROBLEM: find the Founded of university table with largest value of Founded SOLUTION: SELECT Founded FROM university ORDER BY Founded Desc LIMIT 1 PROBLEM: find the number of different Currency_Code in Drama_Workshop_Groups table whose Marketing_Region_Code equals FR SOLUTION: SELECT Count ( DISTINCT Currency_Code ) FROM Drama_Workshop_Groups WHERE Marketing_Region_Code = "FR" PROBLEM: Step 1: find the number of rows of each value of skill_id in Skills table. Step 2: find skill_id, skill_description of Skills table with largest value in the results of step 1 SOLUTION:
SELECT skill_id , skill_description FROM Skills GROUP BY skill_id ORDER BY Count ( * ) Desc LIMIT 1
8
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Example Input: Step 1: For each row in jobs table, find the corresponding rows in employees table. Step 2: find rows of the results of step 1 whose SALARY equals 8000 or MAX_SALARY greater than 12000 Example Output: SELECT * FROM jobs AS T1 JOIN employees AS T2 ON T1.JOB_ID = T2.JOB_ID WHERE T2.SALARY = 8000 OR T1.MAX_SALARY > 12000 Example Input: find the characteristic_name, other_characteristic_details, characteristic_type_code of Characteristics table Example Output: SELECT characteristic_name , other_characteristic_details , characteristic_type_code FROM Characteristics Example Input: find without repetition the individual_last_name of Individuals table Example Output:
SELECT DISTINCT individual_last_name FROM Individuals
3
NIv2
task077_splash_explanation_to_sql
fs_opt
Given the task definition, example input & output, solve the new input case. In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Example: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Output: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. New input case for you: Step 1: find the number of rows of each value of Headquarters in company table. Step 2: find Headquarters in company table whose corresponding value in step 1 is greater than or equals 2 Output:
SELECT Headquarters FROM company GROUP BY Headquarters HAVING Count ( * ) > = 2
1
NIv2
task077_splash_explanation_to_sql
fs_opt
Given the task definition, example input & output, solve the new input case. In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Example: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Output: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. New input case for you: Step 1: For each row in station_company table, find corresponding rows in company table and in gas_station table. Step 2: find Location, Representative_Name of the results of step 1 ordered descending by Sales_billion. Step 3: only show the first 3 rows of the results Output:
SELECT T2.Location , T2.Representative_Name FROM company AS T1 JOIN gas_station AS T2 JOIN station_company AS T3 ON T1.Company_ID = T3.Company_ID AND T3.Station_ID = T2.Station_ID ORDER BY T1.Sales_billion Desc LIMIT 3
1
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. One example: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Solution is here: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Explanation: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. Now, solve this: find the maximum Degrees in degrees table Solution:
SELECT Max ( Degrees ) FROM degrees
6
NIv2
task077_splash_explanation_to_sql
fs_opt
Detailed Instructions: In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. See one example below: Problem: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Solution: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Explanation: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. Problem: find the Address of Locations table for which Location_Name equals UK Gallery Solution:
SELECT Address FROM Locations WHERE Location_Name = "UK Gallery"
4
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Example Input: Step 1: For each row in genre table, find the corresponding rows in song table. Step 2: find each value of languages in the results of step 1 along with the average song's rating of the corresponding rows to each value Example Output: SELECT T1.rating , Avg ( T2.rating ) FROM genre AS T1 JOIN song AS T2 ON T1.g_name = T2.genre_is GROUP BY T2.languages Example Input: find the maximum followers and the average followers in user_profiles table Example Output: SELECT Max ( followers ) , Avg ( followers ) FROM user_profiles Example Input: Step 1: find the rows of employees table ordered ascending by SALARY. Step 2: only show the first 2500 rows of the results Example Output:
SELECT * FROM employees ORDER BY SALARY Asc LIMIT 2500
3
NIv2
task077_splash_explanation_to_sql
fs_opt
Part 1. Definition In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Part 2. Example Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Answer: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Explanation: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. Part 3. Exercise Step 1: find the rows of employees table ordered ascending by SALARY. Step 2: only show the first 2500 rows of the results Answer:
SELECT * FROM employees ORDER BY SALARY Asc LIMIT 2500
7
NIv2
task077_splash_explanation_to_sql
fs_opt
Given the task definition, example input & output, solve the new input case. In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Example: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Output: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. New input case for you: find the Name, Score of wine table for which Grape equals White Output:
SELECT Name , Score FROM wine WHERE Grape = "White"
1
NIv2
task077_splash_explanation_to_sql
fs_opt
Given the task definition, example input & output, solve the new input case. In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Example: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Output: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. New input case for you: Step 1: For each row in city table, find the corresponding rows in address table. Step 2: find the number of rows of each value of address's city_id in the results of step 1. Step 3: find district, city, address's city_id of step 1 results with largest value in the results of step 2 Output:
SELECT T1.district , T2.city , T1.city_id FROM address AS T1 JOIN city AS T2 ON T1.city_id = T2.city_id GROUP BY T1.city_id ORDER BY Count ( * ) Desc LIMIT 1
1
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Example: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Example solution: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Example explanation: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. Problem: Step 1: find the number of rows in weather table whose min_humidity greater than 8. Step 2: find the max_sea_level_pressure_inches of weather table for which max_sea_level_pressure_inches less than 50. Step 3: show the rows that are in both the results of step 1 and the results of step 2
Solution: SELECT Count ( * ) FROM weather WHERE min_humidity > 8 INTERSECT SELECT max_sea_level_pressure_inches FROM weather WHERE max_sea_level_pressure_inches < 50
5
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Q: Step 1: find the number of rows of each value of catalog_name in Catalogs table. Step 2: find date_of_publication in Catalogs table whose corresponding value in step 1 is greater than 1 A: SELECT date_of_publication FROM Catalogs GROUP BY catalog_name HAVING Count ( * ) > 1 **** Q: Step 1: For each row in TV_Channel table, find the corresponding rows in Cartoon table. Step 2: find series_name, Country of the results of step 1 whose Written_by equals Ben Jones and Directed_by equals Michael Chang A: SELECT T1.series_name , T1.Country FROM TV_Channel AS T1 JOIN Cartoon AS T2 ON T1.id = T2.Channel WHERE T2.Written_by = "Ben Jones" AND T2.Directed_by = "Michael Chang" **** Q: find the average price_in_euros and the minimum price_in_dollars in Catalog_Contents table A:
SELECT Avg ( price_in_euros ) , Min ( price_in_dollars ) FROM Catalog_Contents ****
4
NIv2
task077_splash_explanation_to_sql
fs_opt
Given the task definition, example input & output, solve the new input case. In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Example: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Output: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. New input case for you: find the name, job, city of Person table ordered ascending by name Output:
SELECT name , job , city FROM Person ORDER BY name Asc
1
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. -------- Question: Step 1: For each row in Detention table, find corresponding rows in Ref_Detention_Type table and in Teachers table. Step 2: find detention_type_description of the results of step 1 whose last_name equals Schuster Answer: SELECT T1.detention_type_description FROM Ref_Detention_Type AS T1 JOIN Teachers AS T2 JOIN Detention AS T3 ON T1.detention_type_code = T3.detention_type_code AND T3.teacher_id = T2.teacher_id WHERE T2.last_name = "Schuster" Question: find the Shop_Details of Shops table Answer: SELECT Shop_Details FROM Shops Question: find the LifeExpectancy, Name, LocalName of country table with largest value of SurfaceArea Answer:
SELECT LifeExpectancy , Name , LocalName FROM country ORDER BY SurfaceArea Desc LIMIT 1
7
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Example: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Example solution: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Example explanation: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. Problem: Step 1: find the average MIN_SALARY in jobs table. Step 2: find the EMPLOYEE_ID of employees table whose SALARY greater than the results of step 1
Solution: SELECT T1.EMPLOYEE_ID FROM employees AS T1 WHERE T1.SALARY > ( SELECT Avg ( T2.MIN_SALARY ) FROM jobs AS T2 )
5
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Input: Consider Input: Step 1: For each row in Student table, find the corresponding rows in Visits_Restaurant table. Step 2: find Fname, LName of the results of step 1 whose Spent equals 600 Output: SELECT T1.Fname , T1.LName FROM Student AS T1 JOIN Visits_Restaurant AS T2 ON T1.StuID = T2.StuID WHERE T2.Spent = 600 Input: Consider Input: find the Unsure_rate, Consider_rate, Oppose_rate of candidate table ordered ascending by Consider_rate Output: SELECT Unsure_rate , Consider_rate , Oppose_rate FROM candidate ORDER BY Consider_rate Asc Input: Consider Input: Step 1: find the minimum department_id in Staff_Department_Assignments table. Step 2: find the staff_id of Staff_Department_Assignments table whose date_assigned_to less than the results of step 1
Output: SELECT staff_id FROM Staff_Department_Assignments WHERE date_assigned_to < ( SELECT Min ( department_id ) FROM Staff_Department_Assignments )
2
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Input: Consider Input: find the number of rows in Faculty table whose Sex equals AsstProf and Rank equals Instructor Output: SELECT Count ( * ) FROM Faculty WHERE Sex = "AsstProf" AND Rank = "Instructor" Input: Consider Input: find the SurfaceArea of country table for which Name equals Caribbean Output: SELECT SurfaceArea FROM country WHERE Name = "Caribbean" Input: Consider Input: Step 1: For each row in volume table, find the corresponding rows in music_festival table. Step 2: find Issue_Date, Date_of_ceremony of the results of step 1
Output: SELECT T1.Issue_Date , T2.Date_of_ceremony FROM volume AS T1 JOIN music_festival AS T2 ON T1.Volume_ID = T2.Volume
2
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Step 1: For each row in Tryout table, find corresponding rows in College table and in Player table. Step 2: find College's cName of the results of step 1 whose pName starts with D SELECT T1.cName FROM College AS T1 JOIN Player AS T2 JOIN Tryout AS T3 ON T1.cName = T3.cName AND T3.pID = T2.pID WHERE T2.pName LIKE "D%" Step 1: For each row in Rating table, find corresponding rows in Movie table and in Reviewer table. Step 2: find title of the results of step 1 whose year less than 1980 or name equals James Cameron SELECT T1.title FROM Movie AS T1 JOIN Reviewer AS T2 JOIN Rating AS T3 ON T1.mID = T3.mID AND T3.rID = T2.rID WHERE T1.year < 1980 OR T2.name = "James Cameron" find the Code of country table for which LocalName equals Spanish
SELECT Code FROM country WHERE LocalName = "Spanish"
0
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Example input: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value Example output: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Example explanation: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. Q: Step 1: find the weight of Dogs table. Step 2: find the name, age, weight of Dogs table whose weight one of the results of step 1 A:
SELECT name , age , weight FROM Dogs WHERE weight IN ( SELECT weight FROM Dogs )
3
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. One example is below. Q: Step 1: For each row in Movie table, find the corresponding rows in Rating table. Step 2: find each value of director in the results of step 1 along with the summation of stars of the corresponding rows to each value A: SELECT T1.title , Sum ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director Rationale: This SQL statement uses a "JOIN" statement to combine the "Movie" and "Rating" table then find the corresponding rows by comparing the movie id, which accomplishes step 1. Finally the SQL statement groups the values by each director and returns the title of each movie and the sum of all the stars, which accomplishes step 2. This is a good example. Q: Step 1: For each row in Ref_Locations table, find the corresponding rows in Document_Locations table. Step 2: find each value of Document_Locations's Location_Code in the results of step 1 along with the number of the corresponding rows to each value A:
SELECT T1.Location_Code , Count ( * ) FROM Ref_Locations AS T1 JOIN Document_Locations AS T2 ON T1.Location_Code = T2.Location_Code GROUP BY T2.Location_Code
9
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. Q: Step 1: For each row in College table, find the corresponding rows in Tryout table. Step 2: only keep the results of step 1 whose enr greater than 18000. Step 3: find the number of rows of each value of Tryout's cName in the results of step 2. Step 4: find College's cName of the results of step 2 ordered descending by the results of step 3 A: SELECT T1.cName FROM College AS T1 JOIN Tryout AS T2 ON T1.cName = T2.cName WHERE T1.enr > 18000 GROUP BY T2.cName ORDER BY Count ( * ) Desc **** Q: find the average amount_paid in Payments table A: SELECT Avg ( amount_paid ) FROM Payments **** Q: find the Player of player table for which Player contains English A:
SELECT Player FROM player WHERE Player LIKE "English" ****
4
NIv2
task077_splash_explanation_to_sql
fs_opt
In this task you are expected to provide an SQL statement from an english description of what that SQL statement does. The description may include multiple steps but you should only ouput one SQL statement that accomplishes every step. An SQL query works by selecting data from a table where certain conditions apply. A table contains columns where every row in that table must have a value for each column. Every table has a primary key that uniquely identifies each row, usually an id. To choose which columns are returned you specify that after the "SELECT" statement. Next, you use a "FROM" statement to specify what tables you want to select the data from. When you specify a table you can rename it with the "AS" statement. You can reference that table by whatever name follows the "AS" statement. If you want to select data from multiple tables you need to use the "JOIN" statement. This will join the tables together by pairing a row in one table with every row in the other table (Cartesian Product). To limit the number of rows returned you should use the "ON" statement. This will only return rows where the condition specified after the statement is true, this is usually an equals operator with primary keys. You can also use the "WHERE" statement to specify that only rows with column values statisfying a certain condition, should be returned. The "GROUP BY" statement will group rows together that have equal column values for whatever columns follows the statement. The "HAVING" statement will return groups that statisfy whatever condition follows the statement. Any column(s) being returned from grouped rows must either be an aggregate function, (AVG, MAX, COUNT, SUM, ...) of a column, or the column(s) that the data was grouped by. To sort the returned data you can use the "ORDER BY" command which will order the data by whatever aggregate function or column follows the statement. The "DESC" statement will sort in descending order and the "ASC" statement will sort in ascending order. Finally, you can use the "LIMIT" statement to return a certain number of rows. When "*" is used in an SQL statement every column is returned. For example, SELECT * FROM table WHERE attribute = 1, will select every column from rows with the attribute column equal to 1. find the donator_name of endowment table for which amount less than 9 SELECT donator_name FROM endowment WHERE amount < 9 Step 1: find the staff_name, staff_id of Staff table. Step 2: find the staff_name, staff_id of Staff table. Step 3: show the rows that are in the results of step 1 but not in the results of step 2 SELECT staff_name , staff_id FROM Staff EXCEPT SELECT staff_name , staff_id FROM Staff find the Name, Seating of track table for which Year_Opened greater than 2000 ordered ascending by Name
SELECT Name , Seating FROM track WHERE Year_Opened > 2000 ORDER BY Name Asc
0
NIv2
task077_splash_explanation_to_sql
fs_opt
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
7