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 |
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 battle table, find the corresponding rows in ship table.
Step 2: find battle's name, date of the results of step 1 whose ship's name equals HMS Atalanta and ship's name equals Lettice
| Solution: SELECT T1.name , T1.date FROM battle AS T1 JOIN ship AS T2 ON T1.id = T2.lost_in_battle WHERE T2.name = "Lettice" AND T2.name = "HMS Atalanta" | 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: find the Enrollment, School of university table with largest value of Enrollment
Output: SELECT Enrollment , School FROM university ORDER BY Enrollment Desc LIMIT 1
Input: Consider Input: 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
Output: SELECT Name FROM actor WHERE Name NOT IN ( SELECT Actor_ID FROM actor )
Input: Consider Input: find the Name of channel table
| Output: SELECT Name FROM channel
| 2 | 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 address_content of Addresses table whose address_content equals Gleasonmouth and state_province_county equals Arizona
Output: | SELECT address_content FROM Addresses WHERE address_content = "Gleasonmouth" AND state_province_county = "Arizona" | 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 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 Denomination in school table.
Step 2: find Denomination of school table with largest value in the results of step 1
A: | SELECT Denomination FROM school GROUP BY Denomination ORDER BY Count ( * ) Desc LIMIT 1 | 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.
--------
Question: Step 1: For each row in station table, find the corresponding rows in trip table.
Step 2: find the average duration in the results of step 1 whose city not equals Palo Alto
Answer: SELECT Avg ( T2.duration ) FROM station AS T1 JOIN trip AS T2 WHERE T1.city ! = "Palo Alto"
Question: find the summation of rows in Apartments table whose apt_number contains Columbus Square
Answer: SELECT Sum ( * ) FROM Apartments WHERE apt_number LIKE "Columbus Square"
Question: Step 1: For each row in departments table, find the corresponding rows in employees table.
Step 2: find FIRST_NAME, DEPARTMENT_NAME of the results of step 1 whose LAST_NAME equals McEwen
Answer: | SELECT T2.FIRST_NAME , T1.DEPARTMENT_NAME FROM departments AS T1 JOIN employees AS T2 ON T1.DEPARTMENT_ID = T2.DEPARTMENT_ID WHERE T2.LAST_NAME = "McEwen"
| 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.
--------
Question: find the charge_amount of Charges table with largest value of charge_amount
Answer: SELECT charge_amount FROM Charges ORDER BY charge_amount Desc LIMIT 1
Question: find the number of rows in Physician table whose Name equals John Dorian
Answer: SELECT Count ( * ) FROM Physician WHERE Name = "John Dorian"
Question: find the staff_id of Staff_Department_Assignments table for which date_assigned_to greater than or equals Clerical Staff
Answer: | SELECT staff_id FROM Staff_Department_Assignments WHERE date_assigned_to > = "Clerical Staff"
| 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.
Input: Consider Input: find the number of rows in country table whose LocalName equals Spanish
Output: SELECT Count ( * ) FROM country WHERE LocalName = "Spanish"
Input: Consider Input: Step 1: find the Template_Type_Code of Ref_Template_Types table.
Step 2: find the Template_Type_Code of Templates table.
Step 3: show the rows that are in the results of step 1 but not in the results of step 2
Output: SELECT T1.Template_Type_Code FROM Ref_Template_Types AS T1 EXCEPT SELECT T2.Template_Type_Code FROM Templates AS T2
Input: Consider Input: Step 1: find the number of rows of each value of name in buildings table.
Step 2: find name in buildings table whose corresponding value in step 1 is greater than 1
| Output: SELECT name FROM buildings GROUP BY name HAVING Count ( * ) > 1
| 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.
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 state_province_county of Addresses table for which town_city equals 6862 Kaitlyn Knolls
A: | SELECT state_province_county FROM Addresses WHERE town_city = "6862 Kaitlyn Knolls" | 3 | 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 Country of manager table whose Age greater than 50 or Manager_ID equals 46
answer:
SELECT Country FROM manager WHERE Age > 50 OR Manager_ID = 46
question:
Step 1: For each row in employees table, find the corresponding rows in job_history table.
Step 2: find employees's EMPLOYEE_ID, END_DATE of the results of step 1 whose SALARY equals 24000
answer:
SELECT T1.EMPLOYEE_ID , T2.END_DATE FROM employees AS T1 JOIN job_history AS T2 ON T1.EMPLOYEE_ID = T2.EMPLOYEE_ID WHERE T1.SALARY = 24000
question:
find the average price_in_pounds and the minimum price_in_euros in Catalog_Contents table
answer:
| SELECT Avg ( price_in_pounds ) , Min ( price_in_euros ) FROM Catalog_Contents
| 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.
find the name of stadium table for which Country equals Australia
SELECT name FROM stadium WHERE Country = "Australia"
find the treatment_type_description, treatment_type_code of Treatment_Types table
SELECT treatment_type_description , treatment_type_code FROM Treatment_Types
find each value of Company_ID in company table along with the number of the corresponding rows to each value
| SELECT Company , Count ( * ) FROM company GROUP BY Company_ID
| 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: find the number of rows in Activity table
| Solution: SELECT Count ( * ) FROM Activity | 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.
--------
Question: find the name of bridge table ordered descending by length_feet
Answer: SELECT name FROM bridge ORDER BY length_feet Desc
Question: Step 1: For each row in station table, find the corresponding rows in weather table.
Step 2: find zip_code of the results of step 1 whose long greater than 80 or precipitation_inches greater than 0
Answer: SELECT T2.zip_code FROM station AS T1 JOIN weather AS T2 WHERE T1.long > 80 OR T2.precipitation_inches > 0
Question: Step 1: find the Template_Type_Code of Ref_Template_Types table.
Step 2: find the Template_Type_Code of Templates table.
Step 3: show the rows that are in the results of step 1 but not in the results of step 2
Answer: | SELECT T1.Template_Type_Code FROM Ref_Template_Types AS T1 EXCEPT SELECT T2.Template_Type_Code FROM Templates AS T2
| 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.
Input: Consider Input: 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 Person's name in the results of step 1 whose corresponding value in step 2 is greater than engineer
Output: SELECT T1.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.name GROUP BY T2.friend HAVING Sum ( T1.age ) > "engineer"
Input: Consider Input: Step 1: find the number of rows of each value of LastName in teachers table.
Step 2: find FirstName, LastName of teachers table with largest value in the results of step 1
Output: SELECT FirstName , LastName FROM teachers GROUP BY LastName ORDER BY Count ( * ) Desc LIMIT 1
Input: Consider Input: find the number of rows in Activity table
| Output: SELECT Count ( * ) FROM Activity
| 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: find the Hardware_colours of screen_mode table.
Step 2: find the number of rows in screen_mode table whose Hardware_colours not one of the results of step 1
answer:
SELECT Count ( * ) FROM screen_mode WHERE Hardware_colours NOT IN ( SELECT Hardware_colours FROM screen_mode )
question:
find the number of rows in faculty table whose Year equals 2004 and Year equals San Francisco State University
answer:
SELECT Count ( * ) FROM faculty WHERE Year = "San Francisco State University" AND Year = 2004
question:
find rows of Discount_Coupons table whose coupon_amount greater than 500 or coupon_amount less than 500
answer:
| SELECT * FROM Discount_Coupons WHERE coupon_amount > 500 OR coupon_amount < 500
| 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.
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 each value of Founder in Manufacturers table along with the number of the corresponding rows to each value
A: | SELECT Count ( * ) , Founder FROM Manufacturers GROUP BY Founder | 9 | 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 each value of building in department table along with the number of the corresponding rows to each value
Solution: | SELECT Count ( * ) , budget FROM department GROUP BY building | 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 genre table, find the corresponding rows in song table.
Step 2: find song_name of the results of step 1 whose g_name equals modern or languages equals english
| Solution: SELECT T2.song_name FROM genre AS T1 JOIN song AS T2 ON T1.g_name = T2.genre_is WHERE T1.g_name = "modern" OR T2.languages = "english" | 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.
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 different EMPLOYEE_ID of each value of DEPARTMENT_ID in job_history table.
Step 2: find without repetition DEPARTMENT_ID in job_history table whose corresponding value in step 1 is greater than or equals 4
| Solution: SELECT DISTINCT DEPARTMENT_ID FROM job_history GROUP BY DEPARTMENT_ID HAVING Count ( DISTINCT EMPLOYEE_ID ) > = 4 | 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.
Ex Input:
Step 1: For each row in ACCOUNTS table, find the corresponding rows in SAVINGS table.
Step 2: find name, balance of the results of step 1 whose balance less than 200000
Ex Output:
SELECT T1.name , T2.balance FROM ACCOUNTS AS T1 JOIN SAVINGS AS T2 ON T1.custid = T2.custid WHERE T2.balance < 200000
Ex Input:
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
Ex Output:
SELECT staff_id FROM Staff_Department_Assignments WHERE date_assigned_to > ( SELECT Min ( date_assigned_to ) FROM Staff_Department_Assignments )
Ex Input:
Step 1: find the number of different EMPLOYEE_ID of each value of DEPARTMENT_ID in job_history table.
Step 2: find without repetition DEPARTMENT_ID in job_history table whose corresponding value in step 1 is greater than or equals 4
Ex Output:
| SELECT DISTINCT DEPARTMENT_ID FROM job_history GROUP BY DEPARTMENT_ID HAVING Count ( DISTINCT EMPLOYEE_ID ) > = 4
| 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: find the average Age in Student table whose Sex equals F
Output: | SELECT Avg ( Age ) FROM Student WHERE Sex = "F" | 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 Q]: Step 1: find the number of rows of each value of FirstName in teachers table.
Step 2: find FirstName, LastName of teachers table with largest value in the results of step 1
[EX A]: SELECT FirstName , LastName FROM teachers GROUP BY FirstName ORDER BY Count ( * ) Desc LIMIT 1
[EX Q]: find the MANAGER_ID of employees table
[EX A]: SELECT MANAGER_ID FROM employees
[EX Q]: find the town_city, state_province_county of Addresses table
[EX A]: | SELECT town_city , state_province_county FROM Addresses
| 6 | 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 number of rows in car_makers table whose Maker equals American Motor Company
answer:
SELECT Count ( * ) FROM car_makers WHERE Maker = "American Motor Company"
question:
Step 1: For each row in Campuses table, find corresponding rows in csu_fees table and in discipline_enrollments table.
Step 2: find the average CampusFee in the results of step 1 whose csu_fees's Year equals 2005 and discipline_enrollments's Campus equals 1
answer:
SELECT Avg ( T2.CampusFee ) FROM Campuses AS T1 JOIN csu_fees AS T2 ON T2.Campus = T1.Id JOIN discipline_enrollments AS T3 ON T1.Id = T3.Campus WHERE T2.Year = 2005 AND T3.Campus = 1
question:
Step 1: find the Unsure_rate of candidate table ordered descending by Consider_rate.
Step 2: only show the first 3 rows of the results
answer:
| SELECT Unsure_rate FROM candidate ORDER BY Consider_rate Desc LIMIT 3
| 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.
Ex Input:
Step 1: For each row in Courses table, find the corresponding rows in Student_Course_Enrolment table.
Step 2: find each value of Student_Course_Enrolment's course_id in the results of step 1 along with the number of the corresponding rows to each value
Ex Output:
SELECT T1.course_name , Count ( * ) FROM Courses AS T1 JOIN Student_Course_Enrolment AS T2 ON T1.course_id = T2.course_id GROUP BY T2.course_id
Ex Input:
Step 1: find the Content of TV_Channel table.
Step 2: For each row in TV_Channel table, find the corresponding rows in Cartoon table.
Step 3: find Content of the results of step 2 whose Written_by equals Ben Jones.
Step 4: show the rows that are in the results of step 1 but not in the results of step 3
Ex Output:
SELECT T1.Content FROM TV_Channel AS T1 EXCEPT SELECT T1.Content FROM TV_Channel AS T1 JOIN Cartoon AS T2 ON T1.id = T2.Channel WHERE T2.Written_by = "Ben Jones"
Ex Input:
find the name of bridge table ordered descending by length_feet
Ex Output:
| SELECT name FROM bridge ORDER BY length_feet Desc
| 1 | 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 Consider_rate, Unsure_rate, Oppose_rate of candidate table ordered ascending by Unsure_rate
SOLUTION: SELECT Consider_rate , Unsure_rate , Oppose_rate FROM candidate ORDER BY Unsure_rate Asc
PROBLEM: find without repetition the id, name of ship table for which ship_type equals Brig
SOLUTION: SELECT DISTINCT id , name FROM ship WHERE ship_type = "Brig"
PROBLEM: find the number of rows in Student table
SOLUTION: | SELECT Count ( * ) FROM Student
| 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.
Input: Consider Input: Step 1: find the LastName of list table for which FirstName equals JEROME.
Step 2: find the LastName of list table for which FirstName equals COVIN.
Step 3: show the rows that are in the results of step 1 but not in the results of step 2
Output: SELECT LastName FROM list WHERE FirstName = "JEROME" EXCEPT SELECT LastName FROM list WHERE FirstName = "COVIN"
Input: Consider Input: Step 1: For each row in TV_Channel table, find corresponding rows in TV_series table and in Cartoon table.
Step 2: find Episode of the results of step 1 whose Title equals A Love of a Lifetime
Output: SELECT T2.Episode FROM TV_Channel AS T1 JOIN TV_series AS T2 ON T2.Channel = T1.id JOIN Cartoon AS T3 ON T1.id = T3.Channel WHERE T3.Title = "A Love of a Lifetime"
Input: Consider Input: find the Major of Student table for which Sex equals M
| Output: SELECT Major FROM Student WHERE Sex = "M"
| 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.
Ex Input:
find the Store_Name of Stores table
Ex Output:
SELECT Store_Name FROM Stores
Ex Input:
find the average price_range in Hotels table
Ex Output:
SELECT Avg ( price_range ) FROM Hotels
Ex Input:
find the average Age in Student table whose Sex equals F
Ex Output:
| SELECT Avg ( Age ) FROM Student WHERE Sex = "F"
| 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.
Step 1: find the AirportName of airports table.
Step 2: find the AirportName of airports table.
Step 3: show the rows that are in the results of step 1 but not in the results of step 2
SELECT AirportName FROM airports EXCEPT SELECT AirportName FROM airports
find start_station_id of trip table whose duration greater than 60 and start_date equals 8/21/2015 17:03
SELECT start_station_id FROM trip WHERE duration > 60 AND start_date = "8/21/2015 17:03"
Step 1: find the number of rows of each value of customer_id in Customers table.
Step 2: find first_name, last_name in Customers table whose corresponding value in step 1 is greater than 2
| SELECT first_name , last_name FROM Customers GROUP BY customer_id HAVING Count ( * ) > 2
| 0 | 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 Invoices table, find the corresponding rows in Invoice_Items table.
Step 2: find the average Invoice_Items's Order_Quantity in the results of step 1 whose payment_method_code equals MasterCard
Student: | SELECT Avg ( T2.Order_Quantity ) FROM Invoices AS T1 JOIN Invoice_Items AS T2 ON T1.Invoice_ID = T2.Invoice_ID WHERE T1.payment_method_code = "MasterCard" | 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:
find the other_asset_details of Assets table ordered ascending by other_asset_details
answer:
SELECT other_asset_details FROM Assets ORDER BY other_asset_details Asc
question:
Step 1: For each row in employees table, find the corresponding rows in customers table.
Step 2: find employees's first_name of the results of step 1 whose customers's first_name equals Nancy and customers's last_name equals Edwards
answer:
SELECT T1.first_name FROM employees AS T1 JOIN customers AS T2 ON T1.id = T2.support_rep_id WHERE T2.first_name = "Nancy" AND T2.last_name = "Edwards"
question:
Step 1: For each row in Appointment table, find corresponding rows in Physician table and in Nurse table.
Step 2: find the number of rows of each value of Nurse's Position in the results of step 1.
Step 3: find Physician's Name of the results of step 1 with largest value in the results of step 2
answer:
| SELECT T1.Name FROM Physician AS T1 JOIN Nurse AS T2 JOIN Appointment AS T3 ON T1.EmployeeID = T3.Physician AND T3.PrepNurse = T2.EmployeeID GROUP BY T2.Position ORDER BY Count ( * ) Desc LIMIT 1
| 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.
[EX Q]: find the College of match_season table for which Player contains English
[EX A]: SELECT College FROM match_season WHERE Player LIKE "English"
[EX Q]: Step 1: For each row in user_profiles table, find the corresponding rows in tweets table.
Step 2: find the number of rows of each value of tweets's uid in the results of step 1.
Step 3: find name, partitionid in the results of step 1 whose corresponding value in step 2 is greater than 2
[EX A]: SELECT T2.name , T2.partitionid FROM tweets AS T1 JOIN user_profiles AS T2 ON T1.uid = T2.uid GROUP BY T1.uid HAVING Count ( * ) > 2
[EX Q]: find the date of weather table for which precipitation_inches greater than 85
[EX A]: | SELECT date FROM weather WHERE precipitation_inches > 85
| 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.
Q: Step 1: find the Name of member table.
Step 2: find the Name of member table.
Step 3: show the rows that are in the results of step 1 but not in the results of step 2
A: SELECT Name FROM member EXCEPT SELECT Name FROM member
****
Q: Step 1: find the number of rows of each value of city in airports table.
Step 2: find city of airports table ordered ascending by the results of step 1
A: SELECT city FROM airports GROUP BY city ORDER BY Count ( * ) Asc
****
Q: Step 1: find the number of rows of each value of course_id in Courses table.
Step 2: find course_name, course_id in Courses table whose corresponding value in step 1 is less than or equals 2
A: | SELECT course_name , course_id FROM Courses GROUP BY course_id HAVING Count ( * ) < = 2
****
| 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.
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 Nationality of host table for which Age less than 45.
Step 2: find the Nationality of host table for which Age greater than 35.
Step 3: show the rows that are in both the results of step 1 and the results of step 2
Solution: | SELECT Nationality FROM host WHERE Age < 45 INTERSECT SELECT Nationality FROM host WHERE Age > 35 | 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 Fname, LName of Student table for which Major equals 140
Solution: | SELECT Fname , LName FROM Student WHERE Major = 140 | 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: 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: find the rows of regions table
| Solution: SELECT * FROM regions | 5 | 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: find the number of rows of each value of document_name in Documents table.
Step 2: find document_name of Documents table ordered descending by the results of step 1.
Step 3: only show the first 3 rows of the results
Solution: | SELECT document_name FROM Documents GROUP BY document_name ORDER BY Count ( * ) Desc LIMIT 3 | 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.
--------
Question: find the number of rows in Highschooler table
Answer: SELECT Count ( * ) FROM Highschooler
Question: Step 1: find rows in university table whose Founded less than 1850.
Step 2: find each value of Affiliation the results of step 1 along with the number of the corresponding rows to each value
Answer: SELECT Count ( * ) , Affiliation FROM university WHERE Founded < 1850 GROUP BY Affiliation
Question: Step 1: find the average bathroom_count of each value of apt_type_code in Apartments table.
Step 2: find apt_type_code of Apartments table ordered descending by the results of step 1
Answer: | SELECT apt_type_code FROM Apartments GROUP BY apt_type_code ORDER BY Avg ( bathroom_count ) Desc
| 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.
Ex Input:
find the Name of Patient table
Ex Output:
SELECT Name FROM Patient
Ex Input:
find dorm_name, dorm_name of Dorm table whose student_capacity greater than 300 or student_capacity less than 100
Ex Output:
SELECT dorm_name , dorm_name FROM Dorm WHERE student_capacity > 100 OR student_capacity < 300
Ex Input:
Step 1: find cName of College table whose enr greater than 13000 and state equals AZ.
Step 2: find cName of College table whose enr greater than 15000 and state equals LA.
Step 3: show the rows that are in any of the results of step 1 or the results of step 2
Ex Output:
| SELECT cName FROM College WHERE enr > 13000 AND state = "AZ" UNION SELECT cName FROM College WHERE enr > 15000 AND state = "LA"
| 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.
Step 1: For each row in Institution table, find the corresponding rows in protein table.
Step 2: find common_name, Type of the results of step 1
SELECT T2.common_name , T1.Type FROM Institution AS T1 JOIN protein AS T2 ON T1.Institution_id = T2.Institution_id
Step 1: find the company_id of flight table.
Step 2: find the name, Type of operate_company table whose operate_company's id one of the results of step 1
SELECT T1.name , T1.Type FROM operate_company AS T1 WHERE T1.id IN ( SELECT T2.company_id FROM flight AS T2 )
find the City, Hanyu_Pinyin of city table with smallest value of GDP
| SELECT City , Hanyu_Pinyin FROM city ORDER BY GDP Asc LIMIT 1
| 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.
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 Student table whose Sex equals HKG or city_code equals CHI
Answer: | SELECT Count ( * ) FROM Student WHERE Sex = "HKG" OR city_code = "CHI" | 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 Member_of table, find corresponding rows in Faculty table and in Department table.
Step 2: find DName, Lname of the results of step 1 whose Sex equals M and Faculty's Building equals NEB.
Step 3: find DName, Lname of the results of step 1 whose Department's Building equals M and Faculty's Building equals NEB.
Step 4: show the rows that are in both the results of step 2 and the results of step 3
SOLUTION: SELECT T2.DName , T1.Lname FROM Faculty AS T1 JOIN Department AS T2 JOIN Member_of AS T3 ON T1.FacID = T3.FacID AND T3.DNO = T2.DNO WHERE T1.Sex = "M" AND T1.Building = "NEB" INTERSECT SELECT T2.DName , T1.Lname FROM Faculty AS T1 JOIN Department AS T2 JOIN Member_of AS T3 ON T1.FacID = T3.FacID AND T3.DNO = T2.DNO WHERE T2.Building = "M" AND T1.Building = "NEB"
PROBLEM: Step 1: For each row in Services table, find corresponding rows in Ref_Service_Types table and in Drama_Workshop_Groups table.
Step 2: find the number of different Currency_Code in the results of step 1 whose Service_Type_Description equals provide photo service
SOLUTION: SELECT Count ( DISTINCT T2.Currency_Code ) FROM Ref_Service_Types AS T1 JOIN Drama_Workshop_Groups AS T2 JOIN Services AS T3 ON T1.Service_Type_Code = T3.Service_Type_Code AND T3.Workshop_Group_ID = T2.Workshop_Group_ID WHERE T1.Service_Type_Description = "provide photo service"
PROBLEM: find the number of rows in Student table whose Sex equals HKG or city_code equals CHI
SOLUTION: | SELECT Count ( * ) FROM Student WHERE Sex = "HKG" OR city_code = "CHI"
| 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.
Q: find the minimum duration and the minimum duration in trip table whose start_station_name equals Howard at 2nd
A: SELECT Min ( duration ) , Min ( duration ) FROM trip WHERE start_station_name = "Howard at 2nd"
****
Q: find course_id of takes table whose year equals 2010 and semester equals Spring
A: SELECT course_id FROM takes WHERE year = 2010 AND semester = "Spring"
****
Q: Step 1: For each row in station table, find the corresponding rows in weather table.
Step 2: find zip_code of the results of step 1 whose long greater than 80 or min_sea_level_pressure_inches greater than 29.97
A: | SELECT T2.zip_code FROM station AS T1 JOIN weather AS T2 WHERE T1.long > 80 OR T2.min_sea_level_pressure_inches > 29.97
****
| 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.
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 product_description of Products_for_Hire table for which product_name equals 102.76
Solution: | SELECT product_description FROM Products_for_Hire WHERE product_name = 102.76 | 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: For each row in station table, find the corresponding rows in weather table.
Step 2: find zip_code of the results of step 1 whose long greater than 80 or min_sea_level_pressure_inches greater than 29.97
Answer: | SELECT T2.zip_code FROM station AS T1 JOIN weather AS T2 WHERE T1.long > 80 OR T2.min_sea_level_pressure_inches > 29.97 | 8 | NIv2 | task077_splash_explanation_to_sql | fs_opt |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.