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 Apartments table, find the corresponding rows in Apartment_Bookings table.
Step 2: find the average bathroom_count in the results of step 1 whose booking_status_code equals Provisional

SELECT Avg ( T1.bathroom_count ) FROM Apartments AS T1 JOIN Apartment_Bookings AS T2 ON T1.apt_id = T2.apt_id WHERE T2.booking_status_code = "Provisional"


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 faculty's Year equals 1996 and csu_fees's Year equals 1996

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 T3.Year = 1996 AND T2.Year = 1996


find each value of product_name in Products table along with the summation of the corresponding rows to each value

SELECT product_name , Sum ( * ) FROM Products GROUP BY product_name


Step 1: For each row in Addresses table, find the corresponding rows in Student_Addresses table.
Step 2: find the average monthly_rental of each value of student_id in the results of step 1.
Step 3: find student_id, city of step 1 results with largest value in the results of step 2

SELECT T2.student_id , T1.city FROM Addresses AS T1 JOIN Student_Addresses AS T2 ON T1.address_id = T2.address_id GROUP BY T2.student_id ORDER BY Avg ( T2.monthly_rental ) Desc LIMIT 1


Step 1: For each row in Apartment_Buildings table, find the corresponding rows in Apartments table.
Step 2: find the summation of bathroom_count in the results of step 1 whose apt_number equals Columbus Square and building_short_name equals Normandie Court

SELECT Sum ( T2.bathroom_count ) FROM Apartment_Buildings AS T1 JOIN Apartments AS T2 ON T1.building_id = T2.building_id WHERE T2.apt_number = "Columbus Square" AND T1.building_short_name = "Normandie Court"


Step 1: find the number of rows of each value of facility_code in Apartment_Facilities table.
Step 2: find facility_code in Apartment_Facilities table whose corresponding value in step 1 is greater than 4

SELECT facility_code FROM Apartment_Facilities GROUP BY facility_code HAVING Count ( * ) > 4


Step 1: For each row in Campuses table, find the corresponding rows in faculty table.
Step 2: find the number of rows in the results of step 1 whose Campuses's Campus equals Long Beach State University and faculty's Year equals 2002

SELECT Count ( * ) FROM Campuses AS T1 JOIN faculty AS T2 ON T1.Id = T2.Campus WHERE T1.Campus = "Long Beach State University" AND T2.Year = 2002


Step 1: For each row in Campuses table, find corresponding rows in csu_fees table and in discipline_enrollments table.
Step 2: find CampusFee of the results of step 1 whose discipline_enrollments's Year equals 1996 and discipline_enrollments's Year equals San Jose State University

SELECT 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 T3.Year = "San Jose State University" AND T3.Year = 1996


Step 1: find the number of rows of each value of city in Addresses table.
Step 2: find city of Addresses table with largest value in the results of step 1

SELECT city FROM Addresses GROUP BY city ORDER BY Count ( * ) Desc LIMIT 1


Step 1: find the average stars in Rating table.
Step 2: For each row in Movie table, find the corresponding rows in Rating table.
Step 3: find title, director in the results of step 2 whose stars greater than the results of step 1

SELECT T1.title , T1.director FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID WHERE T2.stars > ( SELECT Avg ( T2.stars ) FROM Rating AS T2 )


Step 1: For each row in Orders table, find the corresponding rows in Invoices table.
Step 2: find date_order_placed, Invoices's order_id of the results of step 1

SELECT T1.date_order_placed , T2.order_id FROM Orders AS T1 JOIN Invoices AS T2 ON T1.order_id = T2.order_id


find the summation of amount_outstanding in Customers table whose first_name equals Carole and last_name equals Bernhard

SELECT Sum ( amount_outstanding ) FROM Customers WHERE first_name = "Carole" AND last_name = "Bernhard"


Step 1: find the rows in faculty table whose Year equals 2003.
Step 2: find each value of Faculty in the results of step 1 ordered descending by number of rows that correspond of each value.
Step 3: only show the first row of the results

SELECT Faculty FROM faculty WHERE Year = 2003 GROUP BY Campus ORDER BY Count ( * ) Desc LIMIT 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 average stars of the corresponding rows to each value

SELECT T1.title , Avg ( T2.stars ) FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID GROUP BY T1.director


find the number of rows in faculty table whose Year equals 2002 and Year equals Long Beach State University

SELECT Count ( * ) FROM faculty WHERE Year = "Long Beach State University" AND Year = 2002


Step 1: find the number of rows of each value of product in product table.
Step 2: find product of product table with largest value in the results of step 1

SELECT product FROM product GROUP BY product ORDER BY Count ( * ) Desc LIMIT 1


find the number of rows in Customers table whose first_name equals Rylan and last_name equals Goodwin

SELECT Count ( * ) FROM Customers WHERE first_name = "Rylan" AND last_name = "Goodwin"


Step 1: For each row in Campuses table, find the corresponding rows in faculty table.
Step 2: find Campuses's Campus of the results of step 1 whose County equals Los Angeles and Campuses's Year greater than 1950 and faculty's Year greater than 2002

SELECT T1.Campus FROM Campuses AS T1 JOIN faculty AS T2 ON T1.Id = T2.Campus WHERE T1.County = "Los Angeles" AND T1.Year > 1950 AND T2.Year > 2002


find the city of Addresses table for which line_1_number_building equals Janessa

SELECT city FROM Addresses WHERE line_1_number_building = "Janessa"


Step 1: find the average transaction_amount in Financial_Transactions table.
Step 2: find the account_id of Financial_Transactions table whose transaction_amount greater than the results of step 1

SELECT account_id FROM Financial_Transactions WHERE transaction_amount > ( SELECT Avg ( transaction_amount ) FROM Financial_Transactions )


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


Step 1: For each row in Reviewer table, find the corresponding rows in Rating table.
Step 2: find name of the results of step 1 whose stars equals null

SELECT T1.name FROM Reviewer AS T1 JOIN Rating AS T2 ON T1.rID = T2.rID WHERE T2.stars = "null"


Step 1: For each row in Apartment_Buildings table, find the corresponding rows in Apartments table.
Step 2: find the summation of bathroom_count in the results of step 1 whose building_full_name equals Columbus Square and building_short_name equals Normandie Court

SELECT Sum ( T2.bathroom_count ) FROM Apartment_Buildings AS T1 JOIN Apartments AS T2 ON T1.building_id = T2.building_id WHERE T1.building_full_name = "Columbus Square" AND T1.building_short_name = "Normandie Court"


find the order_id, date_order_placed, order_details of Orders table

SELECT order_id , date_order_placed , order_details FROM Orders


find without repetition the District_name of district table ordered descending by City_Population

SELECT DISTINCT District_name FROM district ORDER BY City_Population Desc


find each value of product_id in Products table along with the number of the corresponding rows to each value

SELECT product_id , Count ( * ) FROM Products GROUP BY product_id


find each value of apt_number in Apartments table along with the number of the corresponding rows to each value

SELECT apt_number , Count ( * ) FROM Apartments GROUP BY apt_number


Step 1: For each row in Guests table, find the corresponding rows in Apartment_Bookings table.
Step 2: find booking_start_date, booking_end_date of the results of step 1 whose gender_code equals Female

SELECT T2.booking_start_date , T2.booking_end_date FROM Guests AS T1 JOIN Apartment_Bookings AS T2 ON T1.guest_id = T2.guest_id WHERE T1.gender_code = "Female"


Step 1: For each row in Teachers table, find the corresponding rows in Assessment_Notes table.
Step 2: find notes_id of the results of step 1 whose last_name equals Schuster

SELECT T2.notes_id FROM Teachers AS T1 JOIN Assessment_Notes AS T2 ON T1.teacher_id = T2.teacher_id WHERE T1.last_name = "Schuster"


Step 1: For each row in Campuses table, find corresponding rows in degrees table and in discipline_enrollments table.
Step 2: find the average Degrees of each value of discipline_enrollments's Year in the results of step 1.
Step 3: find discipline_enrollments's Year of the results of step 1 with largest value in the results of step 2

SELECT T3.Year FROM Campuses AS T1 JOIN degrees AS T2 ON T2.Campus = T1.Id JOIN discipline_enrollments AS T3 ON T1.Id = T3.Campus GROUP BY T3.Year ORDER BY Avg ( T2.Degrees ) Desc LIMIT 1


Step 1: For each row in Campuses table, find corresponding rows in discipline_enrollments table and in faculty table.
Step 2: find faculty's Year of the results of step 1 whose Undergraduate greater than 400.
Step 3: find the discipline_enrollments's Campus of discipline_enrollments table for which Discipline greater than 1956.
Step 4: show the rows that are in both the results of step 2 and the results of step 3

SELECT T3.Year FROM Campuses AS T1 JOIN discipline_enrollments AS T2 ON T2.Campus = T1.Id JOIN faculty AS T3 ON T1.Id = T3.Campus WHERE T2.Undergraduate > 400 INTERSECT SELECT T2.Campus FROM discipline_enrollments AS T2 WHERE T2.Discipline > 1956


find the average bathroom_count in Apartments table

SELECT Avg ( bathroom_count ) FROM Apartments


Step 1: For each row in Campuses table, find the corresponding rows in faculty table.
Step 2: find County of the results of step 1 whose County equals Los Angeles and Campuses's Year greater than 1950 and faculty's Year greater than 2002

SELECT T1.County FROM Campuses AS T1 JOIN faculty AS T2 ON T1.Id = T2.Campus WHERE T1.County = "Los Angeles" AND T1.Year > 1950 AND T2.Year > 2002


find the rows of Behavior_Incident table ordered ascending by date_incident_start

SELECT * FROM Behavior_Incident ORDER BY date_incident_start Asc


find the Id of Campuses table for which County equals Los Angeles

SELECT Id FROM Campuses WHERE County = "Los Angeles"


Step 1: For each row in Movie table, find the corresponding rows in Rating table.
Step 2: find title of the results of step 1 whose stars contains 4 or stars contains 3

SELECT T1.title FROM Movie AS T1 JOIN Rating AS T2 ON T1.mID = T2.mID WHERE T2.stars LIKE 3 OR T2.stars LIKE 4


Step 1: For each row in Campuses table, find corresponding rows in csu_fees table and in discipline_enrollments table.
Step 2: find CampusFee of the results of step 1 whose csu_fees's Year equals 1996 and discipline_enrollments's Year equals San Jose State University

SELECT 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 = 1996 AND T3.Year = "San Jose State University"


Step 1: For each row in Campuses table, find corresponding rows in csu_fees table and in faculty table.
Step 2: find faculty's Campus of the results of step 1 whose faculty's Year greater than or equals 1935 and csu_fees's Year less than or equals 1939

SELECT T3.Campus FROM Campuses AS T1 JOIN csu_fees AS T2 ON T2.Campus = T1.Id JOIN faculty AS T3 ON T1.Id = T3.Campus WHERE T3.Year > = 1935 AND T2.Year < = 1939


find the average Clean_Jerk in body_builder table

SELECT Avg ( Clean_Jerk ) FROM body_builder


Step 1: find the number of rows of each value of building_description in Apartment_Buildings table.
Step 2: find building_description in Apartment_Buildings table whose corresponding value in step 1 is greater than 2

SELECT building_description FROM Apartment_Buildings GROUP BY building_description HAVING Count ( * ) > 2


Step 1: For each row in people table, find the corresponding rows in body_builder table.
Step 2: find the summation of Total in the results of step 1 whose Name contains January

SELECT Sum ( T1.Total ) FROM body_builder AS T1 JOIN people AS T2 ON T1.People_ID = T2.People_ID WHERE T2.Name LIKE "January"


Step 1: For each row in Campuses table, find corresponding rows in csu_fees table and in discipline_enrollments table.
Step 2: find CampusFee of the results of step 1 whose Undergraduate equals 1996 and csu_fees's Year equals San Jose State University

SELECT 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 T3.Undergraduate = 1996 AND T2.Year = "San Jose State University"


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: find apt_number of the results of step 1 whose booking_status_code equals 1.
Step 4: show the rows that are in both the results of step 2 and the results of step 3

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 T1.apt_number FROM Apartments AS T1 JOIN Apartment_Bookings AS T2 ON T1.apt_id = T2.apt_id WHERE T2.booking_status_code = 1


Step 1: For each row in Campuses table, find corresponding rows in csu_fees table and in faculty table.
Step 2: find CampusFee of the results of step 1 whose faculty's Year equals 1996 and faculty's Year equals San Jose State University

SELECT 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 T3.Year = "San Jose State University" AND T3.Year = 1996


find the Accreditation_type, Company_name of phone table for which Accreditation_type contains Full

SELECT Accreditation_type , Company_name FROM phone WHERE Accreditation_type LIKE "Full"


Step 1: find the number of rows of each value of apt_type_code in Apartments table.
Step 2: find apt_type_code in Apartments table whose corresponding value in step 1 is greater than 1

SELECT apt_type_code FROM Apartments GROUP BY apt_type_code HAVING Count ( * ) > 1


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

SELECT Count ( * ) FROM screen_mode WHERE Hardware_colours NOT IN ( SELECT Hardware_colours FROM screen_mode )


Step 1: For each row in Reviewer table, find the corresponding rows in Rating table.
Step 2: find stars of the results of step 1 whose name contains Mike

SELECT T2.stars FROM Reviewer AS T1 JOIN Rating AS T2 ON T1.rID = T2.rID WHERE T1.name LIKE "Mike"


Step 1: find the director of Movie table for which title equals null.
Step 2: find the name of Reviewer table whose rID not one of the results of step 1

SELECT T1.name FROM Reviewer AS T1 WHERE T1.rID NOT IN ( SELECT T2.director FROM Movie AS T2 WHERE T2.title = "null" )