Question: Show the total number of rooms of the apartments in the building with short name "Columbus Square".

Context: CREATE TABLE Apartment_Buildings (building_id VARCHAR, building_short_name VARCHAR); CREATE TABLE Apartments (room_count INTEGER, building_id VARCHAR)

Answer: [SQL] SELECT SUM(T2.room_count) FROM Apartment_Buildings AS T1 JOIN Apartments AS T2 ON T1.building_id = T2.building_id WHERE T1.building_short_name = "Columbus Square" [/SQL]


Question: Show the addresses of the buildings that have apartments with more than 2 bathrooms.

Context: CREATE TABLE Apartment_Buildings (building_address VARCHAR, building_id VARCHAR); CREATE TABLE Apartments (building_id VARCHAR, bathroom_count INTEGER)

Answer: [SQL] SELECT T1.building_address FROM Apartment_Buildings AS T1 JOIN Apartments AS T2 ON T1.building_id = T2.building_id WHERE T2.bathroom_count > 2 [/SQL]


Question: Show the apartment type codes and apartment numbers in the buildings managed by "Kyle".

Context: CREATE TABLE Apartment_Buildings (building_id VARCHAR, building_manager VARCHAR); CREATE TABLE Apartments (apt_type_code VARCHAR, apt_number VARCHAR, building_id VARCHAR)

Answer: [SQL] SELECT T2.apt_type_code, T2.apt_number FROM Apartment_Buildings AS T1 JOIN Apartments AS T2 ON T1.building_id = T2.building_id WHERE T1.building_manager = "Kyle" [/SQL]


Question: Show the booking status code and the corresponding number of bookings.

Context: CREATE TABLE Apartment_Bookings (booking_status_code VARCHAR)

Answer: [SQL] SELECT booking_status_code, COUNT(*) FROM Apartment_Bookings GROUP BY booking_status_code [/SQL]


Question: Return all the apartment numbers sorted by the room count in ascending order.

Context: CREATE TABLE Apartments (apt_number VARCHAR, room_count VARCHAR)

Answer: [SQL] SELECT apt_number FROM Apartments ORDER BY room_count [/SQL]


Question: Return the apartment number with the largest number of bedrooms.

Context: CREATE TABLE Apartments (apt_number VARCHAR, bedroom_count VARCHAR)

Answer: [SQL] SELECT apt_number FROM Apartments ORDER BY bedroom_count DESC LIMIT 1 [/SQL]


Question: Show the apartment type codes and the corresponding number of apartments sorted by the number of apartments in ascending order.

Context: CREATE TABLE Apartments (apt_type_code VARCHAR)

Answer: [SQL] SELECT apt_type_code, COUNT(*) FROM Apartments GROUP BY apt_type_code ORDER BY COUNT(*) [/SQL]


Question: Show the top 3 apartment type codes sorted by the average number of rooms in descending order.

Context: CREATE TABLE Apartments (apt_type_code VARCHAR, room_count INTEGER)

Answer: [SQL] SELECT apt_type_code FROM Apartments GROUP BY apt_type_code ORDER BY AVG(room_count) DESC LIMIT 3 [/SQL]


Question: Show the apartment type code that has the largest number of total rooms, together with the number of bathrooms and number of bedrooms.

Context: CREATE TABLE Apartments (apt_type_code VARCHAR, bathroom_count VARCHAR, bedroom_count VARCHAR, room_count INTEGER)

Answer: [SQL] SELECT apt_type_code, bathroom_count, bedroom_count FROM Apartments GROUP BY apt_type_code ORDER BY SUM(room_count) DESC LIMIT 1 [/SQL]


Question: Show the most common apartment type code.

Answer: [SQL] SELECT apt_type_code FROM Apartments GROUP BY apt_type_code ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Show the most common apartment type code among apartments with more than 1 bathroom.

Context: CREATE TABLE Apartments (apt_type_code VARCHAR, bathroom_count INTEGER)

Answer: [SQL] SELECT apt_type_code FROM Apartments WHERE bathroom_count > 1 GROUP BY apt_type_code ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Show each apartment type code, and the maximum and minimum number of rooms for each type.

Answer: [SQL] SELECT apt_type_code, MAX(room_count), MIN(room_count) FROM Apartments GROUP BY apt_type_code [/SQL]


Question: Show each gender code and the corresponding count of guests sorted by the count in descending order.

Context: CREATE TABLE Guests (gender_code VARCHAR)

Answer: [SQL] SELECT gender_code, COUNT(*) FROM Guests GROUP BY gender_code ORDER BY COUNT(*) DESC [/SQL]


Question: How many apartments do not have any facility?

Context: CREATE TABLE Apartment_Facilities (apt_id VARCHAR); CREATE TABLE Apartments (apt_id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM Apartments WHERE NOT apt_id IN (SELECT apt_id FROM Apartment_Facilities) [/SQL]


Question: Show the apartment numbers of apartments with bookings that have status code both "Provisional" and "Confirmed"

Context: CREATE TABLE Apartments (apt_number VARCHAR, apt_id VARCHAR); CREATE TABLE Apartment_Bookings (apt_id VARCHAR, booking_status_code VARCHAR)

Answer: [SQL] SELECT T2.apt_number FROM Apartment_Bookings AS T1 JOIN Apartments AS T2 ON T1.apt_id = T2.apt_id WHERE T1.booking_status_code = "Confirmed" INTERSECT SELECT T2.apt_number FROM Apartment_Bookings AS T1 JOIN Apartments AS T2 ON T1.apt_id = T2.apt_id WHERE T1.booking_status_code = "Provisional" [/SQL]


Question: Show the apartment numbers of apartments with unit status availability of both 0 and 1.

Context: CREATE TABLE View_Unit_Status (apt_id VARCHAR, available_yn VARCHAR); CREATE TABLE Apartments (apt_number VARCHAR, apt_id VARCHAR)

Answer: [SQL] SELECT T1.apt_number FROM Apartments AS T1 JOIN View_Unit_Status AS T2 ON T1.apt_id = T2.apt_id WHERE T2.available_yn = 0 INTERSECT SELECT T1.apt_number FROM Apartments AS T1 JOIN View_Unit_Status AS T2 ON T1.apt_id = T2.apt_id WHERE T2.available_yn = 1 [/SQL]


Question: How many games are held after season 2007?

Context: CREATE TABLE game (season INTEGER)

Answer: [SQL] SELECT COUNT(*) FROM game WHERE season > 2007 [/SQL]


Question: List the dates of games by the home team name in descending order.

Context: CREATE TABLE game (Date VARCHAR, home_team VARCHAR)

Answer: [SQL] SELECT Date FROM game ORDER BY home_team DESC [/SQL]


Question: List the season, home team, away team of all the games.

Context: CREATE TABLE game (season VARCHAR, home_team VARCHAR, away_team VARCHAR)

Answer: [SQL] SELECT season, home_team, away_team FROM game [/SQL]


Question: What are the maximum, minimum and average home games each stadium held?

Context: CREATE TABLE stadium (home_games INTEGER)

Answer: [SQL] SELECT MAX(home_games), MIN(home_games), AVG(home_games) FROM stadium [/SQL]


Question: What is the average attendance of stadiums with capacity percentage higher than 100%?

Context: CREATE TABLE stadium (average_attendance VARCHAR, capacity_percentage INTEGER)

Answer: [SQL] SELECT average_attendance FROM stadium WHERE capacity_percentage > 100 [/SQL]


Question: What are the player name, number of matches, and information source for players who do not suffer from injury of 'Knee problem'?

Context: CREATE TABLE injury_accident (player VARCHAR, number_of_matches VARCHAR, SOURCE VARCHAR, injury VARCHAR)

Answer: [SQL] SELECT player, number_of_matches, SOURCE FROM injury_accident WHERE injury <> 'Knee problem' [/SQL]


Question: What is the season of the game which causes the player 'Walter Samuel' to get injured?

Context: CREATE TABLE injury_accident (game_id VARCHAR, player VARCHAR); CREATE TABLE game (season VARCHAR, id VARCHAR)

Answer: [SQL] SELECT T1.season FROM game AS T1 JOIN injury_accident AS T2 ON T1.id = T2.game_id WHERE T2.player = 'Walter Samuel' [/SQL]


Question: What are the ids, scores, and dates of the games which caused at least two injury accidents?

Context: CREATE TABLE game (id VARCHAR, score VARCHAR, date VARCHAR); CREATE TABLE injury_accident (game_id VARCHAR)

Answer: [SQL] SELECT T1.id, T1.score, T1.date FROM game AS T1 JOIN injury_accident AS T2 ON T2.game_id = T1.id GROUP BY T1.id HAVING COUNT(*) >= 2 [/SQL]


Question: What are the id and name of the stadium where the most injury accidents happened?

Context: CREATE TABLE stadium (id VARCHAR, name VARCHAR); CREATE TABLE injury_accident (game_id VARCHAR); CREATE TABLE game (stadium_id VARCHAR, id VARCHAR)

Answer: [SQL] SELECT T1.id, T1.name FROM stadium AS T1 JOIN game AS T2 ON T1.id = T2.stadium_id JOIN injury_accident AS T3 ON T2.id = T3.game_id GROUP BY T1.id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: In which season and which stadium did any player have an injury of 'Foot injury' or 'Knee problem'?

Context: CREATE TABLE stadium (name VARCHAR, id VARCHAR); CREATE TABLE injury_accident (game_id VARCHAR, injury VARCHAR); CREATE TABLE game (season VARCHAR, stadium_id VARCHAR, id VARCHAR)

Answer: [SQL] SELECT T1.season, T2.name FROM game AS T1 JOIN stadium AS T2 ON T1.stadium_id = T2.id JOIN injury_accident AS T3 ON T1.id = T3.game_id WHERE T3.injury = 'Foot injury' OR T3.injury = 'Knee problem' [/SQL]


Question: How many different kinds of information sources are there for injury accidents?

Context: CREATE TABLE injury_accident (SOURCE VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT SOURCE) FROM injury_accident [/SQL]


Question: How many games are free of injury accidents?

Context: CREATE TABLE injury_accident (id VARCHAR, game_id VARCHAR); CREATE TABLE game (id VARCHAR, game_id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM game WHERE NOT id IN (SELECT game_id FROM injury_accident) [/SQL]


Question: How many distinct kinds of injuries happened after season 2010?

Context: CREATE TABLE injury_accident (injury VARCHAR, game_id VARCHAR); CREATE TABLE game (id VARCHAR, season INTEGER)

Answer: [SQL] SELECT COUNT(DISTINCT T1.injury) FROM injury_accident AS T1 JOIN game AS T2 ON T1.game_id = T2.id WHERE T2.season > 2010 [/SQL]


Question: List the name of the stadium where both the player 'Walter Samuel' and the player 'Thiago Motta' got injured.

Context: CREATE TABLE stadium (name VARCHAR, id VARCHAR); CREATE TABLE game (stadium_id VARCHAR, id VARCHAR); CREATE TABLE injury_accident (game_id VARCHAR, player VARCHAR)

Answer: [SQL] SELECT T2.name FROM game AS T1 JOIN stadium AS T2 ON T1.stadium_id = T2.id JOIN injury_accident AS T3 ON T1.id = T3.game_id WHERE T3.player = 'Walter Samuel' INTERSECT SELECT T2.name FROM game AS T1 JOIN stadium AS T2 ON T1.stadium_id = T2.id JOIN injury_accident AS T3 ON T1.id = T3.game_id WHERE T3.player = 'Thiago Motta' [/SQL]


Question: Show the name, average attendance, total attendance for stadiums where no accidents happened.

Context: CREATE TABLE stadium (name VARCHAR, average_attendance VARCHAR, total_attendance VARCHAR, id VARCHAR); CREATE TABLE stadium (name VARCHAR, average_attendance VARCHAR, total_attendance VARCHAR); CREATE TABLE game (stadium_id VARCHAR, id VARCHAR); CREATE TABLE injury_accident (game_id VARCHAR)

Answer: [SQL] SELECT name, average_attendance, total_attendance FROM stadium EXCEPT SELECT T2.name, T2.average_attendance, T2.total_attendance FROM game AS T1 JOIN stadium AS T2 ON T1.stadium_id = T2.id JOIN injury_accident AS T3 ON T1.id = T3.game_id [/SQL]


Question: Which stadium name contains the substring "Bank"?

Context: CREATE TABLE stadium (name VARCHAR)

Answer: [SQL] SELECT name FROM stadium WHERE name LIKE "%Bank%" [/SQL]


Question: How many games has each stadium held?

Context: CREATE TABLE stadium (id VARCHAR); CREATE TABLE game (stadium_id VARCHAR)

Answer: [SQL] SELECT T1.id, COUNT(*) FROM stadium AS T1 JOIN game AS T2 ON T1.id = T2.stadium_id GROUP BY T1.id [/SQL]


Question: For each injury accident, find the date of the game and the name of the injured player in the game, and sort the results in descending order of game season.

Context: CREATE TABLE game (date VARCHAR, id VARCHAR, season VARCHAR); CREATE TABLE injury_accident (player VARCHAR, game_id VARCHAR)

Answer: [SQL] SELECT T1.date, T2.player FROM game AS T1 JOIN injury_accident AS T2 ON T1.id = T2.game_id ORDER BY T1.season DESC [/SQL]


Question: List all country and league names.

Context: CREATE TABLE League (name VARCHAR, country_id VARCHAR); CREATE TABLE Country (name VARCHAR, id VARCHAR)

Answer: [SQL] SELECT T1.name, T2.name FROM Country AS T1 JOIN League AS T2 ON T1.id = T2.country_id [/SQL]


Question: How many leagues are there in England?

Context: CREATE TABLE League (country_id VARCHAR); CREATE TABLE Country (id VARCHAR, name VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM Country AS T1 JOIN League AS T2 ON T1.id = T2.country_id WHERE T1.name = "England" [/SQL]


Question: What is the average weight of all players?

Context: CREATE TABLE Player (weight INTEGER)

Answer: [SQL] SELECT AVG(weight) FROM Player [/SQL]


Question: What is the maximum and minimum height of all players?

Context: CREATE TABLE Player (weight INTEGER)

Answer: [SQL] SELECT MAX(weight), MIN(weight) FROM Player [/SQL]


Question: List all player names who have an overall rating higher than the average.

Context: CREATE TABLE Player (player_name VARCHAR, player_api_id VARCHAR); CREATE TABLE Player_Attributes (overall_rating INTEGER); CREATE TABLE Player_Attributes (player_api_id VARCHAR, overall_rating INTEGER)

Answer: [SQL] SELECT DISTINCT T1.player_name FROM Player AS T1 JOIN Player_Attributes AS T2 ON T1.player_api_id = T2.player_api_id WHERE T2.overall_rating > (SELECT AVG(overall_rating) FROM Player_Attributes) [/SQL]


Question: What are the names of players who have the best dribbling?

Context: CREATE TABLE Player (player_name VARCHAR, player_api_id VARCHAR); CREATE TABLE Player_Attributes (player_api_id VARCHAR, dribbling VARCHAR); CREATE TABLE Player_Attributes (overall_rating INTEGER)

Answer: [SQL] SELECT DISTINCT T1.player_name FROM Player AS T1 JOIN Player_Attributes AS T2 ON T1.player_api_id = T2.player_api_id WHERE T2.dribbling = (SELECT MAX(overall_rating) FROM Player_Attributes) [/SQL]


Question: List the names of all players who have a crossing score higher than 90 and prefer their right foot.

Context: CREATE TABLE Player (player_name VARCHAR, player_api_id VARCHAR); CREATE TABLE Player_Attributes (player_api_id VARCHAR, crossing VARCHAR, preferred_foot VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.player_name FROM Player AS T1 JOIN Player_Attributes AS T2 ON T1.player_api_id = T2.player_api_id WHERE T2.crossing > 90 AND T2.preferred_foot = "right" [/SQL]


Question: List the names of all left-footed players who have overall rating between 85 and 90.

Context: CREATE TABLE Player (player_name VARCHAR, player_api_id VARCHAR); CREATE TABLE Player_Attributes (player_api_id VARCHAR, overall_rating VARCHAR, preferred_foot VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.player_name FROM Player AS T1 JOIN Player_Attributes AS T2 ON T1.player_api_id = T2.player_api_id WHERE T2.preferred_foot = "left" AND T2.overall_rating >= 85 AND T2.overall_rating <= 90 [/SQL]


Question: What is the average rating for right-footed players and left-footed players?

Context: CREATE TABLE Player_Attributes (preferred_foot VARCHAR, overall_rating INTEGER)

Answer: [SQL] SELECT preferred_foot, AVG(overall_rating) FROM Player_Attributes GROUP BY preferred_foot [/SQL]


Question: Of all players with an overall rating greater than 80, how many are right-footed and left-footed?

Answer: [SQL] SELECT preferred_foot, COUNT(*) FROM Player_Attributes WHERE overall_rating > 80 GROUP BY preferred_foot [/SQL]


Question: List all of the player ids with a height of at least 180cm and an overall rating higher than 85.

Context: CREATE TABLE Player_Attributes (player_api_id VARCHAR, height VARCHAR, overall_rating INTEGER); CREATE TABLE Player (player_api_id VARCHAR, height VARCHAR, overall_rating INTEGER)

Answer: [SQL] SELECT player_api_id FROM Player WHERE height >= 180 INTERSECT SELECT player_api_id FROM Player_Attributes WHERE overall_rating > 85 [/SQL]


Question: List all of the ids for left-footed players with a height between 180cm and 190cm.

Context: CREATE TABLE Player_Attributes (player_api_id VARCHAR, preferred_foot VARCHAR, height VARCHAR); CREATE TABLE Player (player_api_id VARCHAR, preferred_foot VARCHAR, height VARCHAR)

Answer: [SQL] SELECT player_api_id FROM Player WHERE height >= 180 AND height <= 190 INTERSECT SELECT player_api_id FROM Player_Attributes WHERE preferred_foot = "left" [/SQL]


Question: Who are the top 3 players in terms of overall rating?

Context: CREATE TABLE Player (player_name VARCHAR, player_api_id VARCHAR); CREATE TABLE Player_Attributes (player_api_id VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.player_name FROM Player AS T1 JOIN Player_Attributes AS T2 ON T1.player_api_id = T2.player_api_id ORDER BY overall_rating DESC LIMIT 3 [/SQL]


Question: List the names and birthdays of the top five players in terms of potential.

Context: CREATE TABLE Player_Attributes (player_api_id VARCHAR); CREATE TABLE Player (player_name VARCHAR, birthday VARCHAR, player_api_id VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.player_name, T1.birthday FROM Player AS T1 JOIN Player_Attributes AS T2 ON T1.player_api_id = T2.player_api_id ORDER BY potential DESC LIMIT 5 [/SQL]


Question: How many performances are there?

Context: CREATE TABLE performance (Id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM performance [/SQL]


Question: List the hosts of performances in ascending order of attendance.

Context: CREATE TABLE performance (HOST VARCHAR, Attendance VARCHAR)

Answer: [SQL] SELECT HOST FROM performance ORDER BY Attendance [/SQL]


Question: What are the dates and locations of performances?

Context: CREATE TABLE performance (Date VARCHAR, LOCATION VARCHAR)

Answer: [SQL] SELECT Date, LOCATION FROM performance [/SQL]


Question: Show the attendances of the performances at location "TD Garden" or "Bell Centre"

Context: CREATE TABLE performance (Attendance VARCHAR, LOCATION VARCHAR)

Answer: [SQL] SELECT Attendance FROM performance WHERE LOCATION = "TD Garden" OR LOCATION = "Bell Centre" [/SQL]


Question: What is the average number of attendees for performances?

Context: CREATE TABLE performance (Attendance INTEGER)

Answer: [SQL] SELECT AVG(Attendance) FROM performance [/SQL]


Question: What is the date of the performance with the highest number of attendees?

Context: CREATE TABLE performance (Date VARCHAR, Attendance VARCHAR)

Answer: [SQL] SELECT Date FROM performance ORDER BY Attendance DESC LIMIT 1 [/SQL]


Question: Show different locations and the number of performances at each location.

Context: CREATE TABLE performance (LOCATION VARCHAR)

Answer: [SQL] SELECT LOCATION, COUNT(*) FROM performance GROUP BY LOCATION [/SQL]


Question: Show the most common location of performances.

Answer: [SQL] SELECT LOCATION FROM performance GROUP BY LOCATION ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Show the locations that have at least two performances.

Answer: [SQL] SELECT LOCATION FROM performance GROUP BY LOCATION HAVING COUNT(*) >= 2 [/SQL]


Question: Show the locations that have both performances with more than 2000 attendees and performances with less than 1000 attendees.

Context: CREATE TABLE performance (LOCATION VARCHAR, Attendance INTEGER)

Answer: [SQL] SELECT LOCATION FROM performance WHERE Attendance > 2000 INTERSECT SELECT LOCATION FROM performance WHERE Attendance < 1000 [/SQL]


Question: Show the names of members and the location of the performances they attended.

Context: CREATE TABLE performance (Location VARCHAR, Performance_ID VARCHAR); CREATE TABLE member (Name VARCHAR, Member_ID VARCHAR); CREATE TABLE member_attendance (Member_ID VARCHAR, Performance_ID VARCHAR)

Answer: [SQL] SELECT T2.Name, T3.Location FROM member_attendance AS T1 JOIN member AS T2 ON T1.Member_ID = T2.Member_ID JOIN performance AS T3 ON T1.Performance_ID = T3.Performance_ID [/SQL]


Question: Show the names of members and the location of performances they attended in ascending alphabetical order of their names.

Answer: [SQL] SELECT T2.Name, T3.Location FROM member_attendance AS T1 JOIN member AS T2 ON T1.Member_ID = T2.Member_ID JOIN performance AS T3 ON T1.Performance_ID = T3.Performance_ID ORDER BY T2.Name [/SQL]


Question: Show the dates of performances with attending members whose roles are "Violin".

Context: CREATE TABLE performance (Date VARCHAR, Performance_ID VARCHAR); CREATE TABLE member (Member_ID VARCHAR, Role VARCHAR); CREATE TABLE member_attendance (Member_ID VARCHAR, Performance_ID VARCHAR)

Answer: [SQL] SELECT T3.Date FROM member_attendance AS T1 JOIN member AS T2 ON T1.Member_ID = T2.Member_ID JOIN performance AS T3 ON T1.Performance_ID = T3.Performance_ID WHERE T2.Role = "Violin" [/SQL]


Question: Show the names of members and the dates of performances they attended in descending order of attendance of the performances.

Context: CREATE TABLE performance (Date VARCHAR, Performance_ID VARCHAR, Attendance VARCHAR); CREATE TABLE member (Name VARCHAR, Member_ID VARCHAR); CREATE TABLE member_attendance (Member_ID VARCHAR, Performance_ID VARCHAR)

Answer: [SQL] SELECT T2.Name, T3.Date FROM member_attendance AS T1 JOIN member AS T2 ON T1.Member_ID = T2.Member_ID JOIN performance AS T3 ON T1.Performance_ID = T3.Performance_ID ORDER BY T3.Attendance DESC [/SQL]


Question: List the names of members who did not attend any performance.

Context: CREATE TABLE member (Name VARCHAR, Member_ID VARCHAR); CREATE TABLE member_attendance (Name VARCHAR, Member_ID VARCHAR)

Answer: [SQL] SELECT Name FROM member WHERE NOT Member_ID IN (SELECT Member_ID FROM member_attendance) [/SQL]


Question: Find the buildings which have rooms with capacity more than 50.

Context: CREATE TABLE classroom (building VARCHAR, capacity INTEGER)

Answer: [SQL] SELECT DISTINCT building FROM classroom WHERE capacity > 50 [/SQL]


Question: Count the number of rooms that are not in the Lamberton building.

Context: CREATE TABLE classroom (building VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM classroom WHERE building <> 'Lamberton' [/SQL]


Question: What is the name and building of the departments whose budget is more than the average budget?

Context: CREATE TABLE department (dept_name VARCHAR, building VARCHAR, budget INTEGER)

Answer: [SQL] SELECT dept_name, building FROM department WHERE budget > (SELECT AVG(budget) FROM department) [/SQL]


Question: Find the room number of the rooms which can sit 50 to 100 students and their buildings.

Context: CREATE TABLE classroom (building VARCHAR, room_number VARCHAR, capacity INTEGER)

Answer: [SQL] SELECT building, room_number FROM classroom WHERE capacity BETWEEN 50 AND 100 [/SQL]


Question: Find the name and building of the department with the highest budget.

Context: CREATE TABLE department (dept_name VARCHAR, building VARCHAR, budget VARCHAR)

Answer: [SQL] SELECT dept_name, building FROM department ORDER BY budget DESC LIMIT 1 [/SQL]


Question: What is the name of the student who has the highest total credits in the History department.

Context: CREATE TABLE student (name VARCHAR, dept_name VARCHAR, tot_cred VARCHAR)

Answer: [SQL] SELECT name FROM student WHERE dept_name = 'History' ORDER BY tot_cred DESC LIMIT 1 [/SQL]


Question: How many rooms does the Lamberton building have?

Answer: [SQL] SELECT COUNT(*) FROM classroom WHERE building = 'Lamberton' [/SQL]


Question: How many students have advisors?

Context: CREATE TABLE advisor (s_id VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT s_id) FROM advisor [/SQL]


Question: How many departments offer courses?

Context: CREATE TABLE course (dept_name VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT dept_name) FROM course [/SQL]


Question: How many different courses offered by Physics department?

Context: CREATE TABLE course (course_id VARCHAR, dept_name VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT course_id) FROM course WHERE dept_name = 'Physics' [/SQL]


Question: Find the title of courses that have two prerequisites?

Context: CREATE TABLE prereq (course_id VARCHAR); CREATE TABLE course (title VARCHAR, course_id VARCHAR)

Answer: [SQL] SELECT T1.title FROM course AS T1 JOIN prereq AS T2 ON T1.course_id = T2.course_id GROUP BY T2.course_id HAVING COUNT(*) = 2 [/SQL]


Question: Find the title, credit, and department name of courses that have more than one prerequisites?

Context: CREATE TABLE prereq (course_id VARCHAR); CREATE TABLE course (title VARCHAR, credits VARCHAR, dept_name VARCHAR, course_id VARCHAR)

Answer: [SQL] SELECT T1.title, T1.credits, T1.dept_name FROM course AS T1 JOIN prereq AS T2 ON T1.course_id = T2.course_id GROUP BY T2.course_id HAVING COUNT(*) > 1 [/SQL]


Question: How many courses that do not have prerequisite?

Context: CREATE TABLE prereq (course_id VARCHAR); CREATE TABLE course (course_id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM course WHERE NOT course_id IN (SELECT course_id FROM prereq) [/SQL]


Question: Find the name of the courses that do not have any prerequisite?

Context: CREATE TABLE prereq (title VARCHAR, course_id VARCHAR); CREATE TABLE course (title VARCHAR, course_id VARCHAR)

Answer: [SQL] SELECT title FROM course WHERE NOT course_id IN (SELECT course_id FROM prereq) [/SQL]


Question: How many different instructors have taught some course?

Context: CREATE TABLE teaches (id VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT id) FROM teaches [/SQL]


Question: Find the total budgets of the Marketing or Finance department.

Context: CREATE TABLE department (budget INTEGER, dept_name VARCHAR)

Answer: [SQL] SELECT SUM(budget) FROM department WHERE dept_name = 'Marketing' OR dept_name = 'Finance' [/SQL]


Question: Find the department name of the instructor whose name contains 'Soisalon'.

Context: CREATE TABLE instructor (dept_name VARCHAR, name VARCHAR)

Answer: [SQL] SELECT dept_name FROM instructor WHERE name LIKE '%Soisalon%' [/SQL]


Question: How many rooms whose capacity is less than 50 does the Lamberton building have?

Context: CREATE TABLE classroom (building VARCHAR, capacity VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM classroom WHERE building = 'Lamberton' AND capacity < 50 [/SQL]


Question: Find the name and budget of departments whose budgets are more than the average budget.

Context: CREATE TABLE department (dept_name VARCHAR, budget INTEGER)

Answer: [SQL] SELECT dept_name, budget FROM department WHERE budget > (SELECT AVG(budget) FROM department) [/SQL]


Question: what is the name of the instructor who is in Statistics department and earns the lowest salary?

Context: CREATE TABLE instructor (name VARCHAR, dept_name VARCHAR, salary VARCHAR)

Answer: [SQL] SELECT name FROM instructor WHERE dept_name = 'Statistics' ORDER BY salary LIMIT 1 [/SQL]


Question: Find the title of course that is provided by both Statistics and Psychology departments.

Context: CREATE TABLE course (title VARCHAR, dept_name VARCHAR)

Answer: [SQL] SELECT title FROM course WHERE dept_name = 'Statistics' INTERSECT SELECT title FROM course WHERE dept_name = 'Psychology' [/SQL]


Question: Find the title of course that is provided by Statistics but not Psychology departments.

Answer: [SQL] SELECT title FROM course WHERE dept_name = 'Statistics' EXCEPT SELECT title FROM course WHERE dept_name = 'Psychology' [/SQL]


Question: Find the id of instructors who taught a class in Fall 2009 but not in Spring 2010.

Context: CREATE TABLE teaches (id VARCHAR, semester VARCHAR, YEAR VARCHAR)

Answer: [SQL] SELECT id FROM teaches WHERE semester = 'Fall' AND YEAR = 2009 EXCEPT SELECT id FROM teaches WHERE semester = 'Spring' AND YEAR = 2010 [/SQL]


Question: Find the name of students who took any class in the years of 2009 and 2010.

Context: CREATE TABLE student (name VARCHAR, id VARCHAR); CREATE TABLE takes (id VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.name FROM student AS T1 JOIN takes AS T2 ON T1.id = T2.id WHERE YEAR = 2009 OR YEAR = 2010 [/SQL]


Question: Find the names of the top 3 departments that provide the largest amount of courses?

Context: CREATE TABLE course (dept_name VARCHAR)

Answer: [SQL] SELECT dept_name FROM course GROUP BY dept_name ORDER BY COUNT(*) DESC LIMIT 3 [/SQL]


Question: Find the name of the department that offers the highest total credits?

Context: CREATE TABLE course (dept_name VARCHAR, credits INTEGER)

Answer: [SQL] SELECT dept_name FROM course GROUP BY dept_name ORDER BY SUM(credits) DESC LIMIT 1 [/SQL]


Question: List the names of all courses ordered by their titles and credits.

Context: CREATE TABLE course (title VARCHAR, credits VARCHAR)

Answer: [SQL] SELECT title FROM course ORDER BY title, credits [/SQL]


Question: Which department has the lowest budget?

Context: CREATE TABLE department (dept_name VARCHAR, budget VARCHAR)

Answer: [SQL] SELECT dept_name FROM department ORDER BY budget LIMIT 1 [/SQL]


Question: List the names and buildings of all departments sorted by the budget from large to small.

Context: CREATE TABLE department (dept_name VARCHAR, building VARCHAR, budget VARCHAR)

Answer: [SQL] SELECT dept_name, building FROM department ORDER BY budget DESC [/SQL]


Question: Who is the instructor with the highest salary?

Context: CREATE TABLE instructor (name VARCHAR, salary VARCHAR)

Answer: [SQL] SELECT name FROM instructor ORDER BY salary DESC LIMIT 1 [/SQL]


Question: List the information of all instructors ordered by their salary in ascending order.

Context: CREATE TABLE instructor (salary VARCHAR)

Answer: [SQL] SELECT * FROM instructor ORDER BY salary [/SQL]


Question: Find the name of the students and their department names sorted by their total credits in ascending order.

Context: CREATE TABLE student (name VARCHAR, dept_name VARCHAR, tot_cred VARCHAR)

Answer: [SQL] SELECT name, dept_name FROM student ORDER BY tot_cred [/SQL]


Question: list in alphabetic order all course names and their instructors' names in year 2008.

Context: CREATE TABLE course (title VARCHAR, course_id VARCHAR); CREATE TABLE teaches (course_id VARCHAR, id VARCHAR); CREATE TABLE instructor (name VARCHAR, id VARCHAR)

Answer: [SQL] SELECT T1.title, T3.name FROM course AS T1 JOIN teaches AS T2 ON T1.course_id = T2.course_id JOIN instructor AS T3 ON T2.id = T3.id WHERE YEAR = 2008 ORDER BY T1.title [/SQL]


Question: Find the name of instructors who are advising more than one student.

Context: CREATE TABLE advisor (i_id VARCHAR); CREATE TABLE instructor (name VARCHAR, id VARCHAR)

Answer: [SQL] SELECT T1.name FROM instructor AS T1 JOIN advisor AS T2 ON T1.id = T2.i_id GROUP BY T2.i_id HAVING COUNT(*) > 1 [/SQL]


Question: Find the name of the students who have more than one advisor?

Context: CREATE TABLE student (name VARCHAR, id VARCHAR); CREATE TABLE advisor (s_id VARCHAR)

Answer: [SQL] SELECT T1.name FROM student AS T1 JOIN advisor AS T2 ON T1.id = T2.s_id GROUP BY T2.s_id HAVING COUNT(*) > 1 [/SQL]


Question: Find the number of rooms with more than 50 capacity for each building.

Context: CREATE TABLE classroom (building VARCHAR, capacity INTEGER)

Answer: [SQL] SELECT COUNT(*), building FROM classroom WHERE capacity > 50 GROUP BY building [/SQL]


Question: Find the maximum and average capacity among rooms in each building.

Answer: [SQL] SELECT MAX(capacity), AVG(capacity), building FROM classroom GROUP BY building [/SQL]


Question: Find the title of the course that is offered by more than one department.

Context: CREATE TABLE course (title VARCHAR)

Answer: [SQL] SELECT title FROM course GROUP BY title HAVING COUNT(*) > 1 [/SQL]


Question: Find the total credits of courses provided by different department.

Answer: [SQL] SELECT SUM(credits), dept_name FROM course GROUP BY dept_name [/SQL]


Question: Find the minimum salary for the departments whose average salary is above the average payment of all instructors.

Context: CREATE TABLE instructor (dept_name VARCHAR, salary INTEGER)

Answer: [SQL] SELECT MIN(salary), dept_name FROM instructor GROUP BY dept_name HAVING AVG(salary) > (SELECT AVG(salary) FROM instructor) [/SQL]


Question: Find the number of courses provided in each semester and year.

Context: CREATE TABLE SECTION (semester VARCHAR, YEAR VARCHAR)

Answer: [SQL] SELECT COUNT(*), semester, YEAR FROM SECTION GROUP BY semester, YEAR [/SQL]


Question: Find the year which offers the largest number of courses.

Context: CREATE TABLE SECTION (YEAR VARCHAR)

Answer: [SQL] SELECT YEAR FROM SECTION GROUP BY YEAR ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Find the year and semester when offers the largest number of courses.

Answer: [SQL] SELECT semester, YEAR FROM SECTION GROUP BY semester, YEAR ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Find the name of department has the highest amount of students?

Context: CREATE TABLE student (dept_name VARCHAR)

Answer: [SQL] SELECT dept_name FROM student GROUP BY dept_name ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Find the total number of students in each department.

Answer: [SQL] SELECT COUNT(*), dept_name FROM student GROUP BY dept_name [/SQL]


Question: Find the semester and year which has the least number of student taking any class.

Context: CREATE TABLE takes (semester VARCHAR, YEAR VARCHAR)

Answer: [SQL] SELECT semester, YEAR FROM takes GROUP BY semester, YEAR ORDER BY COUNT(*) LIMIT 1 [/SQL]


Question: What is the id of the instructor who advises of all students from History department?

Context: CREATE TABLE advisor (s_id VARCHAR); CREATE TABLE student (id VARCHAR, dept_name VARCHAR)

Answer: [SQL] SELECT i_id FROM advisor AS T1 JOIN student AS T2 ON T1.s_id = T2.id WHERE T2.dept_name = 'History' [/SQL]


Question: Find the name and salary of the instructors who are advisors of any student from History department?

Context: CREATE TABLE instructor (name VARCHAR, salary VARCHAR, id VARCHAR); CREATE TABLE advisor (i_id VARCHAR, s_id VARCHAR); CREATE TABLE student (id VARCHAR, dept_name VARCHAR)

Answer: [SQL] SELECT T2.name, T2.salary FROM advisor AS T1 JOIN instructor AS T2 ON T1.i_id = T2.id JOIN student AS T3 ON T1.s_id = T3.id WHERE T3.dept_name = 'History' [/SQL]


Question: Find the id of the courses that do not have any prerequisite?

Context: CREATE TABLE prereq (course_id VARCHAR); CREATE TABLE course (course_id VARCHAR)

Answer: [SQL] SELECT course_id FROM course EXCEPT SELECT course_id FROM prereq [/SQL]


Question: What is the title of the prerequisite class of International Finance course?

Context: CREATE TABLE course (title VARCHAR, course_id VARCHAR); CREATE TABLE prereq (prereq_id VARCHAR, course_id VARCHAR); CREATE TABLE course (course_id VARCHAR, title VARCHAR)

Answer: [SQL] SELECT title FROM course WHERE course_id IN (SELECT T1.prereq_id FROM prereq AS T1 JOIN course AS T2 ON T1.course_id = T2.course_id WHERE T2.title = 'International Finance') [/SQL]


Question: Find the title of course whose prerequisite is course Differential Geometry.

Context: CREATE TABLE prereq (course_id VARCHAR, prereq_id VARCHAR); CREATE TABLE course (title VARCHAR, course_id VARCHAR); CREATE TABLE course (course_id VARCHAR, title VARCHAR)

Answer: [SQL] SELECT title FROM course WHERE course_id IN (SELECT T1.course_id FROM prereq AS T1 JOIN course AS T2 ON T1.prereq_id = T2.course_id WHERE T2.title = 'Differential Geometry') [/SQL]


Question: Find the names of students who have taken any course in the fall semester of year 2003.

Context: CREATE TABLE student (name VARCHAR, id VARCHAR, semester VARCHAR, YEAR VARCHAR); CREATE TABLE takes (name VARCHAR, id VARCHAR, semester VARCHAR, YEAR VARCHAR)

Answer: [SQL] SELECT name FROM student WHERE id IN (SELECT id FROM takes WHERE semester = 'Fall' AND YEAR = 2003) [/SQL]


Question: What is the title of the course that was offered at building Chandler during the fall semester in the year of 2010?

Context: CREATE TABLE course (title VARCHAR, course_id VARCHAR); CREATE TABLE SECTION (course_id VARCHAR)

Answer: [SQL] SELECT T1.title FROM course AS T1 JOIN SECTION AS T2 ON T1.course_id = T2.course_id WHERE building = 'Chandler' AND semester = 'Fall' AND YEAR = 2010 [/SQL]


Question: Find the name of the instructors who taught C Programming course before.

Context: CREATE TABLE teaches (id VARCHAR, course_id VARCHAR); CREATE TABLE course (course_id VARCHAR, title VARCHAR); CREATE TABLE instructor (name VARCHAR, id VARCHAR)

Answer: [SQL] SELECT T1.name FROM instructor AS T1 JOIN teaches AS T2 ON T1.id = T2.id JOIN course AS T3 ON T2.course_id = T3.course_id WHERE T3.title = 'C Programming' [/SQL]


Question: Find the name and salary of instructors who are advisors of the students from the Math department.

Answer: [SQL] SELECT T2.name, T2.salary FROM advisor AS T1 JOIN instructor AS T2 ON T1.i_id = T2.id JOIN student AS T3 ON T1.s_id = T3.id WHERE T3.dept_name = 'Math' [/SQL]


Question: Find the name of instructors who are advisors of the students from the Math department, and sort the results by students' total credit.

Context: CREATE TABLE student (id VARCHAR, dept_name VARCHAR, tot_cred VARCHAR); CREATE TABLE advisor (i_id VARCHAR, s_id VARCHAR); CREATE TABLE instructor (name VARCHAR, id VARCHAR)

Answer: [SQL] SELECT T2.name FROM advisor AS T1 JOIN instructor AS T2 ON T1.i_id = T2.id JOIN student AS T3 ON T1.s_id = T3.id WHERE T3.dept_name = 'Math' ORDER BY T3.tot_cred [/SQL]


Question: What is the course title of the prerequisite of course Mobile Computing?

Answer: [SQL] SELECT title FROM course WHERE course_id IN (SELECT T1.prereq_id FROM prereq AS T1 JOIN course AS T2 ON T1.course_id = T2.course_id WHERE T2.title = 'Mobile Computing') [/SQL]


Question: Find the name of instructor who is the advisor of the student who has the highest number of total credits.

Context: CREATE TABLE student (id VARCHAR, tot_cred VARCHAR); CREATE TABLE advisor (i_id VARCHAR, s_id VARCHAR); CREATE TABLE instructor (name VARCHAR, id VARCHAR)

Answer: [SQL] SELECT T2.name FROM advisor AS T1 JOIN instructor AS T2 ON T1.i_id = T2.id JOIN student AS T3 ON T1.s_id = T3.id ORDER BY T3.tot_cred DESC LIMIT 1 [/SQL]


Question: Find the name of instructors who didn't teach any courses?

Context: CREATE TABLE teaches (name VARCHAR, id VARCHAR); CREATE TABLE instructor (name VARCHAR, id VARCHAR)

Answer: [SQL] SELECT name FROM instructor WHERE NOT id IN (SELECT id FROM teaches) [/SQL]


Question: Find the id of instructors who didn't teach any courses?

Context: CREATE TABLE teaches (id VARCHAR); CREATE TABLE instructor (id VARCHAR)

Answer: [SQL] SELECT id FROM instructor EXCEPT SELECT id FROM teaches [/SQL]


Question: Find the names of instructors who didn't each any courses in any Spring semester.

Context: CREATE TABLE teaches (name VARCHAR, id VARCHAR, semester VARCHAR); CREATE TABLE instructor (name VARCHAR, id VARCHAR, semester VARCHAR)

Answer: [SQL] SELECT name FROM instructor WHERE NOT id IN (SELECT id FROM teaches WHERE semester = 'Spring') [/SQL]


Question: Find the name of the department which has the highest average salary of professors.

Context: CREATE TABLE instructor (dept_name VARCHAR, salary INTEGER)

Answer: [SQL] SELECT dept_name FROM instructor GROUP BY dept_name ORDER BY AVG(salary) DESC LIMIT 1 [/SQL]


Question: Find the number and averaged salary of all instructors who are in the department with the highest budget.

Context: CREATE TABLE department (dept_name VARCHAR, budget VARCHAR); CREATE TABLE instructor (salary INTEGER, dept_name VARCHAR)

Answer: [SQL] SELECT AVG(T1.salary), COUNT(*) FROM instructor AS T1 JOIN department AS T2 ON T1.dept_name = T2.dept_name ORDER BY T2.budget DESC LIMIT 1 [/SQL]


Question: What is the title and credits of the course that is taught in the largest classroom (with the highest capacity)?

Context: CREATE TABLE SECTION (course_id VARCHAR, building VARCHAR, room_number VARCHAR); CREATE TABLE course (title VARCHAR, credits VARCHAR, course_id VARCHAR); CREATE TABLE classroom (capacity INTEGER, building VARCHAR, room_number VARCHAR); CREATE TABLE classroom (capacity INTEGER)

Answer: [SQL] SELECT T3.title, T3.credits FROM classroom AS T1 JOIN SECTION AS T2 ON T1.building = T2.building AND T1.room_number = T2.room_number JOIN course AS T3 ON T2.course_id = T3.course_id WHERE T1.capacity = (SELECT MAX(capacity) FROM classroom) [/SQL]


Question: Find the name of students who didn't take any course from Biology department.

Context: CREATE TABLE student (name VARCHAR, id VARCHAR); CREATE TABLE course (course_id VARCHAR, dept_name VARCHAR); CREATE TABLE takes (id VARCHAR, course_id VARCHAR)

Answer: [SQL] SELECT name FROM student WHERE NOT id IN (SELECT T1.id FROM takes AS T1 JOIN course AS T2 ON T1.course_id = T2.course_id WHERE T2.dept_name = 'Biology') [/SQL]


Question: Find the total number of students and total number of instructors for each department.

Context: CREATE TABLE department (dept_name VARCHAR); CREATE TABLE student (id VARCHAR, dept_name VARCHAR); CREATE TABLE instructor (dept_name VARCHAR, id VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT T2.id), COUNT(DISTINCT T3.id), T3.dept_name FROM department AS T1 JOIN student AS T2 ON T1.dept_name = T2.dept_name JOIN instructor AS T3 ON T1.dept_name = T3.dept_name GROUP BY T3.dept_name [/SQL]


Question: Find the name of students who have taken the prerequisite course of the course with title International Finance.

Context: CREATE TABLE student (name VARCHAR, id VARCHAR); CREATE TABLE course (course_id VARCHAR, title VARCHAR); CREATE TABLE prereq (prereq_id VARCHAR, course_id VARCHAR); CREATE TABLE takes (id VARCHAR, course_id VARCHAR)

Answer: [SQL] SELECT T1.name FROM student AS T1 JOIN takes AS T2 ON T1.id = T2.id WHERE T2.course_id IN (SELECT T4.prereq_id FROM course AS T3 JOIN prereq AS T4 ON T3.course_id = T4.course_id WHERE T3.title = 'International Finance') [/SQL]


Question: Find the name and salary of instructors whose salary is below the average salary of the instructors in the Physics department.

Context: CREATE TABLE instructor (name VARCHAR, salary INTEGER, dept_name VARCHAR)

Answer: [SQL] SELECT name, salary FROM instructor WHERE salary < (SELECT AVG(salary) FROM instructor WHERE dept_name = 'Physics') [/SQL]


Question: Find the name of students who took some course offered by Statistics department.

Context: CREATE TABLE student (name VARCHAR, id VARCHAR); CREATE TABLE takes (course_id VARCHAR, id VARCHAR); CREATE TABLE course (course_id VARCHAR, dept_name VARCHAR)

Answer: [SQL] SELECT T3.name FROM course AS T1 JOIN takes AS T2 ON T1.course_id = T2.course_id JOIN student AS T3 ON T2.id = T3.id WHERE T1.dept_name = 'Statistics' [/SQL]


Question: Find the building, room number, semester and year of all courses offered by Psychology department sorted by course titles.

Context: CREATE TABLE SECTION (building VARCHAR, room_number VARCHAR, semester VARCHAR, year VARCHAR, course_id VARCHAR); CREATE TABLE course (course_id VARCHAR, dept_name VARCHAR, title VARCHAR)

Answer: [SQL] SELECT T2.building, T2.room_number, T2.semester, T2.year FROM course AS T1 JOIN SECTION AS T2 ON T1.course_id = T2.course_id WHERE T1.dept_name = 'Psychology' ORDER BY T1.title [/SQL]


Question: Find the names of all instructors in computer science department

Context: CREATE TABLE instructor (name VARCHAR, dept_name VARCHAR)

Answer: [SQL] SELECT name FROM instructor WHERE dept_name = 'Comp. Sci.' [/SQL]


Question: Find the names of all instructors in Comp. Sci. department with salary > 80000.

Context: CREATE TABLE instructor (name VARCHAR, dept_name VARCHAR, salary VARCHAR)

Answer: [SQL] SELECT name FROM instructor WHERE dept_name = 'Comp. Sci.' AND salary > 80000 [/SQL]


Question: Find the names of all instructors who have taught some course and the course_id.

Context: CREATE TABLE instructor (ID VARCHAR); CREATE TABLE teaches (ID VARCHAR)

Answer: [SQL] SELECT name, course_id FROM instructor AS T1 JOIN teaches AS T2 ON T1.ID = T2.ID [/SQL]


Question: Find the names of all instructors in the Art department who have taught some course and the course_id.

Context: CREATE TABLE instructor (ID VARCHAR, dept_name VARCHAR); CREATE TABLE teaches (ID VARCHAR)

Answer: [SQL] SELECT name, course_id FROM instructor AS T1 JOIN teaches AS T2 ON T1.ID = T2.ID WHERE T1.dept_name = 'Art' [/SQL]


Question: Find the names of all instructors whose name includes the substring “dar”.

Context: CREATE TABLE instructor (name VARCHAR)

Answer: [SQL] SELECT name FROM instructor WHERE name LIKE '%dar%' [/SQL]


Question: List in alphabetic order the names of all distinct instructors.

Context: CREATE TABLE instructor (name VARCHAR)

Answer: [SQL] SELECT DISTINCT name FROM instructor ORDER BY name [/SQL]


Question: Find courses that ran in Fall 2009 or in Spring 2010.

Context: CREATE TABLE SECTION (course_id VARCHAR, semester VARCHAR, YEAR VARCHAR)

Answer: [SQL] SELECT course_id FROM SECTION WHERE semester = 'Fall' AND YEAR = 2009 UNION SELECT course_id FROM SECTION WHERE semester = 'Spring' AND YEAR = 2010 [/SQL]


Question: Find courses that ran in Fall 2009 and in Spring 2010.

Answer: [SQL] SELECT course_id FROM SECTION WHERE semester = 'Fall' AND YEAR = 2009 INTERSECT SELECT course_id FROM SECTION WHERE semester = 'Spring' AND YEAR = 2010 [/SQL]


Question: Find courses that ran in Fall 2009 but not in Spring 2010.

Answer: [SQL] SELECT course_id FROM SECTION WHERE semester = 'Fall' AND YEAR = 2009 EXCEPT SELECT course_id FROM SECTION WHERE semester = 'Spring' AND YEAR = 2010 [/SQL]


Question: Find the salaries of all distinct instructors that are less than the largest salary.

Context: CREATE TABLE instructor (salary INTEGER)

Answer: [SQL] SELECT DISTINCT salary FROM instructor WHERE salary < (SELECT MAX(salary) FROM instructor) [/SQL]


Question: Find the total number of instructors who teach a course in the Spring 2010 semester.

Context: CREATE TABLE teaches (ID VARCHAR, semester VARCHAR, YEAR VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT ID) FROM teaches WHERE semester = 'Spring' AND YEAR = 2010 [/SQL]


Question: Find the names and average salaries of all departments whose average salary is greater than 42000.

Answer: [SQL] SELECT dept_name, AVG(salary) FROM instructor GROUP BY dept_name HAVING AVG(salary) > 42000 [/SQL]


Question: Find names of instructors with salary greater than that of some (at least one) instructor in the Biology department.

Answer: [SQL] SELECT name FROM instructor WHERE salary > (SELECT MIN(salary) FROM instructor WHERE dept_name = 'Biology') [/SQL]


Question: Find the names of all instructors whose salary is greater than the salary of all instructors in the Biology department.

Answer: [SQL] SELECT name FROM instructor WHERE salary > (SELECT MAX(salary) FROM instructor WHERE dept_name = 'Biology') [/SQL]


Question: How many debates are there?

Context: CREATE TABLE debate (Id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM debate [/SQL]


Question: List the venues of debates in ascending order of the number of audience.

Context: CREATE TABLE debate (Venue VARCHAR, Num_of_Audience VARCHAR)

Answer: [SQL] SELECT Venue FROM debate ORDER BY Num_of_Audience [/SQL]


Question: What are the date and venue of each debate?

Context: CREATE TABLE debate (Date VARCHAR, Venue VARCHAR)

Answer: [SQL] SELECT Date, Venue FROM debate [/SQL]


Question: List the dates of debates with number of audience bigger than 150

Context: CREATE TABLE debate (Date VARCHAR, Num_of_Audience INTEGER)

Answer: [SQL] SELECT Date FROM debate WHERE Num_of_Audience > 150 [/SQL]


Question: Show the names of people aged either 35 or 36.

Context: CREATE TABLE people (Name VARCHAR, Age VARCHAR)

Answer: [SQL] SELECT Name FROM people WHERE Age = 35 OR Age = 36 [/SQL]


Question: What is the party of the youngest people?

Context: CREATE TABLE people (Party VARCHAR, Age VARCHAR)

Answer: [SQL] SELECT Party FROM people ORDER BY Age LIMIT 1 [/SQL]


Question: Show different parties of people along with the number of people in each party.

Context: CREATE TABLE people (Party VARCHAR)

Answer: [SQL] SELECT Party, COUNT(*) FROM people GROUP BY Party [/SQL]


Question: Show the party that has the most people.

Context: CREATE TABLE people (Party VARCHAR)

Answer: [SQL] SELECT Party FROM people GROUP BY Party ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Show the distinct venues of debates

Context: CREATE TABLE debate (Venue VARCHAR)

Answer: [SQL] SELECT DISTINCT Venue FROM debate [/SQL]


Question: Show the names of people, and dates and venues of debates they are on the affirmative side.

Context: CREATE TABLE people (Name VARCHAR, People_ID VARCHAR); CREATE TABLE debate (Date VARCHAR, Venue VARCHAR, Debate_ID VARCHAR); CREATE TABLE debate_people (Debate_ID VARCHAR, Affirmative VARCHAR)

Answer: [SQL] SELECT T3.Name, T2.Date, T2.Venue FROM debate_people AS T1 JOIN debate AS T2 ON T1.Debate_ID = T2.Debate_ID JOIN people AS T3 ON T1.Affirmative = T3.People_ID [/SQL]


Question: Show the names of people, and dates and venues of debates they are on the negative side, ordered in ascending alphabetical order of name.

Context: CREATE TABLE people (Name VARCHAR, People_ID VARCHAR); CREATE TABLE debate (Date VARCHAR, Venue VARCHAR, Debate_ID VARCHAR); CREATE TABLE debate_people (Debate_ID VARCHAR, Negative VARCHAR)

Answer: [SQL] SELECT T3.Name, T2.Date, T2.Venue FROM debate_people AS T1 JOIN debate AS T2 ON T1.Debate_ID = T2.Debate_ID JOIN people AS T3 ON T1.Negative = T3.People_ID ORDER BY T3.Name [/SQL]


Question: Show the names of people that are on affirmative side of debates with number of audience bigger than 200.

Context: CREATE TABLE people (Name VARCHAR, People_ID VARCHAR); CREATE TABLE debate (Debate_ID VARCHAR, Num_of_Audience INTEGER); CREATE TABLE debate_people (Debate_ID VARCHAR, Affirmative VARCHAR)

Answer: [SQL] SELECT T3.Name FROM debate_people AS T1 JOIN debate AS T2 ON T1.Debate_ID = T2.Debate_ID JOIN people AS T3 ON T1.Affirmative = T3.People_ID WHERE T2.Num_of_Audience > 200 [/SQL]


Question: Show the names of people and the number of times they have been on the affirmative side of debates.

Context: CREATE TABLE people (Name VARCHAR, People_ID VARCHAR); CREATE TABLE debate_people (Affirmative VARCHAR)

Answer: [SQL] SELECT T2.Name, COUNT(*) FROM debate_people AS T1 JOIN people AS T2 ON T1.Affirmative = T2.People_ID GROUP BY T2.Name [/SQL]


Question: Show the names of people who have been on the negative side of debates at least twice.

Context: CREATE TABLE debate_people (Negative VARCHAR); CREATE TABLE people (Name VARCHAR, People_ID VARCHAR)

Answer: [SQL] SELECT T2.Name FROM debate_people AS T1 JOIN people AS T2 ON T1.Negative = T2.People_ID GROUP BY T2.Name HAVING COUNT(*) >= 2 [/SQL]


Question: List the names of people that have not been on the affirmative side of debates.

Context: CREATE TABLE debate_people (Name VARCHAR, People_id VARCHAR, Affirmative VARCHAR); CREATE TABLE people (Name VARCHAR, People_id VARCHAR, Affirmative VARCHAR)

Answer: [SQL] SELECT Name FROM people WHERE NOT People_id IN (SELECT Affirmative FROM debate_people) [/SQL]


Question: List the names of all the customers in alphabetical order.

Context: CREATE TABLE customers (customer_details VARCHAR)

Answer: [SQL] SELECT customer_details FROM customers ORDER BY customer_details [/SQL]


Question: Find all the policy type codes associated with the customer "Dayana Robel"

Context: CREATE TABLE customers (customer_id VARCHAR, customer_details VARCHAR); CREATE TABLE policies (customer_id VARCHAR)

Answer: [SQL] SELECT policy_type_code FROM policies AS t1 JOIN customers AS t2 ON t1.customer_id = t2.customer_id WHERE t2.customer_details = "Dayana Robel" [/SQL]


Question: Which type of policy is most frequently used? Give me the policy type code.

Context: CREATE TABLE policies (policy_type_code VARCHAR)

Answer: [SQL] SELECT policy_type_code FROM policies GROUP BY policy_type_code ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Find all the policy types that are used by more than 2 customers.

Answer: [SQL] SELECT policy_type_code FROM policies GROUP BY policy_type_code HAVING COUNT(*) > 2 [/SQL]


Question: Find the total and average amount paid in claim headers.

Context: CREATE TABLE claim_headers (amount_piad INTEGER)

Answer: [SQL] SELECT SUM(amount_piad), AVG(amount_piad) FROM claim_headers [/SQL]


Question: Find the total amount claimed in the most recently created document.

Context: CREATE TABLE claim_headers (amount_claimed INTEGER, claim_header_id VARCHAR); CREATE TABLE claims_documents (claim_id VARCHAR, created_date VARCHAR); CREATE TABLE claims_documents (created_date VARCHAR)

Answer: [SQL] SELECT SUM(t1.amount_claimed) FROM claim_headers AS t1 JOIN claims_documents AS t2 ON t1.claim_header_id = t2.claim_id WHERE t2.created_date = (SELECT created_date FROM claims_documents ORDER BY created_date LIMIT 1) [/SQL]


Question: What is the name of the customer who has made the largest amount of claim in a single claim?

Context: CREATE TABLE customers (customer_details VARCHAR, customer_id VARCHAR); CREATE TABLE claim_headers (amount_claimed INTEGER); CREATE TABLE policies (policy_id VARCHAR, customer_id VARCHAR); CREATE TABLE claim_headers (policy_id VARCHAR, amount_claimed INTEGER)

Answer: [SQL] SELECT t3.customer_details FROM claim_headers AS t1 JOIN policies AS t2 ON t1.policy_id = t2.policy_id JOIN customers AS t3 ON t2.customer_id = t3.customer_id WHERE t1.amount_claimed = (SELECT MAX(amount_claimed) FROM claim_headers) [/SQL]


Question: What is the name of the customer who has made the minimum amount of payment in one claim?

Context: CREATE TABLE claim_headers (amount_piad INTEGER); CREATE TABLE customers (customer_details VARCHAR, customer_id VARCHAR); CREATE TABLE policies (policy_id VARCHAR, customer_id VARCHAR); CREATE TABLE claim_headers (policy_id VARCHAR, amount_piad INTEGER)

Answer: [SQL] SELECT t3.customer_details FROM claim_headers AS t1 JOIN policies AS t2 ON t1.policy_id = t2.policy_id JOIN customers AS t3 ON t2.customer_id = t3.customer_id WHERE t1.amount_piad = (SELECT MIN(amount_piad) FROM claim_headers) [/SQL]


Question: Find the names of customers who have no policies associated.

Context: CREATE TABLE customers (customer_details VARCHAR, customer_id VARCHAR); CREATE TABLE customers (customer_details VARCHAR); CREATE TABLE policies (customer_id VARCHAR)

Answer: [SQL] SELECT customer_details FROM customers EXCEPT SELECT t2.customer_details FROM policies AS t1 JOIN customers AS t2 ON t1.customer_id = t2.customer_id [/SQL]


Question: How many claim processing stages are there in total?

Context: CREATE TABLE claims_processing_stages (Id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM claims_processing_stages [/SQL]


Question: What is the name of the claim processing stage that most of the claims are on?

Context: CREATE TABLE claims_processing (claim_stage_id VARCHAR); CREATE TABLE claims_processing_stages (claim_status_name VARCHAR, claim_stage_id VARCHAR)

Answer: [SQL] SELECT t2.claim_status_name FROM claims_processing AS t1 JOIN claims_processing_stages AS t2 ON t1.claim_stage_id = t2.claim_stage_id GROUP BY t1.claim_stage_id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Find the names of customers whose name contains "Diana".

Answer: [SQL] SELECT customer_details FROM customers WHERE customer_details LIKE "%Diana%" [/SQL]


Question: Find the names of the customers who have an deputy policy.

Context: CREATE TABLE policies (customer_id VARCHAR, policy_type_code VARCHAR); CREATE TABLE customers (customer_details VARCHAR, customer_id VARCHAR)

Answer: [SQL] SELECT DISTINCT t2.customer_details FROM policies AS t1 JOIN customers AS t2 ON t1.customer_id = t2.customer_id WHERE t1.policy_type_code = "Deputy" [/SQL]


Question: Find the names of customers who either have an deputy policy or uniformed policy.

Answer: [SQL] SELECT DISTINCT t2.customer_details FROM policies AS t1 JOIN customers AS t2 ON t1.customer_id = t2.customer_id WHERE t1.policy_type_code = "Deputy" OR t1.policy_type_code = "Uniform" [/SQL]


Question: Find the names of all the customers and staff members.

Context: CREATE TABLE staff (customer_details VARCHAR, staff_details VARCHAR); CREATE TABLE customers (customer_details VARCHAR, staff_details VARCHAR)

Answer: [SQL] SELECT customer_details FROM customers UNION SELECT staff_details FROM staff [/SQL]


Question: Find the number of records of each policy type and its type code.

Answer: [SQL] SELECT policy_type_code, COUNT(*) FROM policies GROUP BY policy_type_code [/SQL]


Question: Find the name of the customer that has been involved in the most policies.

Context: CREATE TABLE customers (customer_details VARCHAR, customer_id VARCHAR); CREATE TABLE policies (customer_id VARCHAR)

Answer: [SQL] SELECT t2.customer_details FROM policies AS t1 JOIN customers AS t2 ON t1.customer_id = t2.customer_id GROUP BY t2.customer_details ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: What is the description of the claim status "Open"?

Context: CREATE TABLE claims_processing_stages (claim_status_description VARCHAR, claim_status_name VARCHAR)

Answer: [SQL] SELECT claim_status_description FROM claims_processing_stages WHERE claim_status_name = "Open" [/SQL]


Question: How many distinct claim outcome codes are there?

Context: CREATE TABLE claims_processing (claim_outcome_code VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT claim_outcome_code) FROM claims_processing [/SQL]


Question: Which customer is associated with the latest policy?

Context: CREATE TABLE customers (customer_details VARCHAR, customer_id VARCHAR); CREATE TABLE policies (start_date INTEGER); CREATE TABLE policies (customer_id VARCHAR, start_date INTEGER)

Answer: [SQL] SELECT t2.customer_details FROM policies AS t1 JOIN customers AS t2 ON t1.customer_id = t2.customer_id WHERE t1.start_date = (SELECT MAX(start_date) FROM policies) [/SQL]


Question: Show the id, the date of account opened, the account name, and other account detail for all accounts.

Context: CREATE TABLE Accounts (account_id VARCHAR, date_account_opened VARCHAR, account_name VARCHAR, other_account_details VARCHAR)

Answer: [SQL] SELECT account_id, date_account_opened, account_name, other_account_details FROM Accounts [/SQL]


Question: Show the id, the account name, and other account details for all accounts by the customer with first name 'Meaghan'.

Context: CREATE TABLE Accounts (account_id VARCHAR, date_account_opened VARCHAR, account_name VARCHAR, other_account_details VARCHAR, customer_id VARCHAR); CREATE TABLE Customers (customer_id VARCHAR, customer_first_name VARCHAR)

Answer: [SQL] SELECT T1.account_id, T1.date_account_opened, T1.account_name, T1.other_account_details FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id WHERE T2.customer_first_name = 'Meaghan' [/SQL]


Question: Show the account name and other account detail for all accounts by the customer with first name Meaghan and last name Keeling.

Context: CREATE TABLE Customers (customer_id VARCHAR, customer_first_name VARCHAR, customer_last_name VARCHAR); CREATE TABLE Accounts (account_name VARCHAR, other_account_details VARCHAR, customer_id VARCHAR)

Answer: [SQL] SELECT T1.account_name, T1.other_account_details FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id WHERE T2.customer_first_name = "Meaghan" AND T2.customer_last_name = "Keeling" [/SQL]


Question: Show the first name and last name for the customer with account name 900.

Context: CREATE TABLE Accounts (customer_id VARCHAR, account_name VARCHAR); CREATE TABLE Customers (customer_first_name VARCHAR, customer_last_name VARCHAR, customer_id VARCHAR)

Answer: [SQL] SELECT T2.customer_first_name, T2.customer_last_name FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id WHERE T1.account_name = "900" [/SQL]


Question: Show the unique first names, last names, and phone numbers for all customers with any account.

Context: CREATE TABLE Accounts (customer_id VARCHAR); CREATE TABLE Customers (customer_first_name VARCHAR, customer_last_name VARCHAR, phone_number VARCHAR, customer_id VARCHAR)

Answer: [SQL] SELECT DISTINCT T1.customer_first_name, T1.customer_last_name, T1.phone_number FROM Customers AS T1 JOIN Accounts AS T2 ON T1.customer_id = T2.customer_id [/SQL]


Question: Show customer ids who don't have an account.

Context: CREATE TABLE Customers (customer_id VARCHAR); CREATE TABLE Accounts (customer_id VARCHAR)

Answer: [SQL] SELECT customer_id FROM Customers EXCEPT SELECT customer_id FROM Accounts [/SQL]


Question: How many accounts does each customer have? List the number and customer id.

Context: CREATE TABLE Accounts (customer_id VARCHAR)

Answer: [SQL] SELECT COUNT(*), customer_id FROM Accounts GROUP BY customer_id [/SQL]


Question: What is the customer id, first and last name with most number of accounts.

Context: CREATE TABLE Accounts (customer_id VARCHAR); CREATE TABLE Customers (customer_first_name VARCHAR, customer_last_name VARCHAR, customer_id VARCHAR)

Answer: [SQL] SELECT T1.customer_id, T2.customer_first_name, T2.customer_last_name FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Show id, first name and last name for all customers and the number of accounts.

Answer: [SQL] SELECT T1.customer_id, T2.customer_first_name, T2.customer_last_name, COUNT(*) FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id [/SQL]


Question: Show first name and id for all customers with at least 2 accounts.

Context: CREATE TABLE Customers (customer_first_name VARCHAR, customer_id VARCHAR); CREATE TABLE Accounts (customer_id VARCHAR)

Answer: [SQL] SELECT T2.customer_first_name, T1.customer_id FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id HAVING COUNT(*) >= 2 [/SQL]


Question: Show the number of customers for each gender.

Context: CREATE TABLE Customers (gender VARCHAR)

Answer: [SQL] SELECT gender, COUNT(*) FROM Customers GROUP BY gender [/SQL]


Question: How many transactions do we have?

Context: CREATE TABLE Financial_transactions (Id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM Financial_transactions [/SQL]


Question: How many transaction does each account have? Show the number and account id.

Context: CREATE TABLE Financial_transactions (account_id VARCHAR)

Answer: [SQL] SELECT COUNT(*), account_id FROM Financial_transactions [/SQL]


Question: How many transaction does account with name 337 have?

Context: CREATE TABLE Accounts (account_id VARCHAR, account_name VARCHAR); CREATE TABLE Financial_transactions (account_id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM Financial_transactions AS T1 JOIN Accounts AS T2 ON T1.account_id = T2.account_id WHERE T2.account_name = "337" [/SQL]


Question: What is the average, minimum, maximum, and total transaction amount?

Context: CREATE TABLE Financial_transactions (transaction_amount INTEGER)

Answer: [SQL] SELECT AVG(transaction_amount), MIN(transaction_amount), MAX(transaction_amount), SUM(transaction_amount) FROM Financial_transactions [/SQL]


Question: Show ids for all transactions whose amounts are greater than the average.

Context: CREATE TABLE Financial_transactions (transaction_id VARCHAR, transaction_amount INTEGER)

Answer: [SQL] SELECT transaction_id FROM Financial_transactions WHERE transaction_amount > (SELECT AVG(transaction_amount) FROM Financial_transactions) [/SQL]


Question: Show the transaction types and the total amount of transactions.

Context: CREATE TABLE Financial_transactions (transaction_type VARCHAR, transaction_amount INTEGER)

Answer: [SQL] SELECT transaction_type, SUM(transaction_amount) FROM Financial_transactions GROUP BY transaction_type [/SQL]


Question: Show the account name, id and the number of transactions for each account.

Context: CREATE TABLE Financial_transactions (account_id VARCHAR); CREATE TABLE Accounts (account_name VARCHAR, account_id VARCHAR)

Answer: [SQL] SELECT T2.account_name, T1.account_id, COUNT(*) FROM Financial_transactions AS T1 JOIN Accounts AS T2 ON T1.account_id = T2.account_id GROUP BY T1.account_id [/SQL]


Question: Show the account id with most number of transactions.

Answer: [SQL] SELECT account_id FROM Financial_transactions GROUP BY account_id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Show the account id and name with at least 4 transactions.

Answer: [SQL] SELECT T1.account_id, T2.account_name FROM Financial_transactions AS T1 JOIN Accounts AS T2 ON T1.account_id = T2.account_id GROUP BY T1.account_id HAVING COUNT(*) >= 4 [/SQL]


Question: Show all product sizes.

Context: CREATE TABLE Products (product_size VARCHAR)

Answer: [SQL] SELECT DISTINCT product_size FROM Products [/SQL]


Question: Show all product colors.

Context: CREATE TABLE Products (product_color VARCHAR)

Answer: [SQL] SELECT DISTINCT product_color FROM Products [/SQL]


Question: Show the invoice number and the number of transactions for each invoice.

Context: CREATE TABLE Financial_transactions (invoice_number VARCHAR)

Answer: [SQL] SELECT invoice_number, COUNT(*) FROM Financial_transactions GROUP BY invoice_number [/SQL]


Question: What is the invoice number and invoice date for the invoice with most number of transactions?

Context: CREATE TABLE Invoices (invoice_number VARCHAR, invoice_date VARCHAR); CREATE TABLE Financial_transactions (invoice_number VARCHAR)

Answer: [SQL] SELECT T2.invoice_number, T2.invoice_date FROM Financial_transactions AS T1 JOIN Invoices AS T2 ON T1.invoice_number = T2.invoice_number GROUP BY T1.invoice_number ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: How many invoices do we have?

Context: CREATE TABLE Invoices (Id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM Invoices [/SQL]


Question: Show invoice dates and order id and details for all invoices.

Context: CREATE TABLE Invoices (invoice_date VARCHAR, order_id VARCHAR); CREATE TABLE Orders (order_details VARCHAR, order_id VARCHAR)

Answer: [SQL] SELECT T1.invoice_date, T1.order_id, T2.order_details FROM Invoices AS T1 JOIN Orders AS T2 ON T1.order_id = T2.order_id [/SQL]


Question: Show the order ids and the number of invoices for each order.

Context: CREATE TABLE Invoices (order_id VARCHAR)

Answer: [SQL] SELECT order_id, COUNT(*) FROM Invoices GROUP BY order_id [/SQL]


Question: What is the order id and order details for the order more than two invoices.

Context: CREATE TABLE Orders (order_id VARCHAR, order_details VARCHAR); CREATE TABLE Invoices (order_id VARCHAR)

Answer: [SQL] SELECT T2.order_id, T2.order_details FROM Invoices AS T1 JOIN Orders AS T2 ON T1.order_id = T2.order_id GROUP BY T2.order_id HAVING COUNT(*) > 2 [/SQL]


Question: What is the customer last name, id and phone number with most number of orders?

Context: CREATE TABLE Orders (customer_id VARCHAR); CREATE TABLE Customers (customer_last_name VARCHAR, phone_number VARCHAR, customer_id VARCHAR)

Answer: [SQL] SELECT T2.customer_last_name, T1.customer_id, T2.phone_number FROM Orders AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Show all product names without an order.

Context: CREATE TABLE Products (product_name VARCHAR, product_id VARCHAR); CREATE TABLE Order_items (product_id VARCHAR); CREATE TABLE Products (product_name VARCHAR)

Answer: [SQL] SELECT product_name FROM Products EXCEPT SELECT T1.product_name FROM Products AS T1 JOIN Order_items AS T2 ON T1.product_id = T2.product_id [/SQL]


Question: Show all product names and the total quantity ordered for each product name.

Context: CREATE TABLE Products (product_name VARCHAR, product_id VARCHAR); CREATE TABLE Order_items (product_quantity INTEGER, product_id VARCHAR)

Answer: [SQL] SELECT T2.product_name, SUM(T1.product_quantity) FROM Order_items AS T1 JOIN Products AS T2 ON T1.product_id = T2.product_id GROUP BY T2.product_name [/SQL]


Question: Show the order ids and the number of items in each order.

Context: CREATE TABLE Order_items (order_id VARCHAR)

Answer: [SQL] SELECT order_id, COUNT(*) FROM Order_items GROUP BY order_id [/SQL]


Question: Show the product ids and the number of unique orders containing each product.

Context: CREATE TABLE Order_items (product_id VARCHAR, order_id VARCHAR)

Answer: [SQL] SELECT product_id, COUNT(DISTINCT order_id) FROM Order_items GROUP BY product_id [/SQL]


Question: Show all product names and the number of customers having an order on each product.

Context: CREATE TABLE Order_items (product_id VARCHAR, order_id VARCHAR); CREATE TABLE Orders (order_id VARCHAR); CREATE TABLE Products (product_name VARCHAR, product_id VARCHAR)

Answer: [SQL] SELECT T2.product_name, COUNT(*) FROM Order_items AS T1 JOIN Products AS T2 ON T1.product_id = T2.product_id JOIN Orders AS T3 ON T3.order_id = T1.order_id GROUP BY T2.product_name [/SQL]


Question: Show order ids and the number of products in each order.

Context: CREATE TABLE Order_items (order_id VARCHAR, product_id VARCHAR)

Answer: [SQL] SELECT order_id, COUNT(DISTINCT product_id) FROM Order_items GROUP BY order_id [/SQL]


Question: Show order ids and the total quantity in each order.

Context: CREATE TABLE Order_items (order_id VARCHAR, product_quantity INTEGER)

Answer: [SQL] SELECT order_id, SUM(product_quantity) FROM Order_items GROUP BY order_id [/SQL]


Question: How many products were not included in any order?

Context: CREATE TABLE products (product_id VARCHAR); CREATE TABLE Order_items (product_id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM products WHERE NOT product_id IN (SELECT product_id FROM Order_items) [/SQL]


Question: How many churches opened before 1850 are there?

Context: CREATE TABLE Church (Open_Date INTEGER)

Answer: [SQL] SELECT COUNT(*) FROM Church WHERE Open_Date < 1850 [/SQL]


Question: Show the name, open date, and organizer for all churches.

Context: CREATE TABLE Church (name VARCHAR, open_date VARCHAR, organized_by VARCHAR)

Answer: [SQL] SELECT name, open_date, organized_by FROM Church [/SQL]


Question: List all church names in descending order of opening date.

Context: CREATE TABLE church (name VARCHAR, open_date VARCHAR)

Answer: [SQL] SELECT name FROM church ORDER BY open_date DESC [/SQL]


Question: Show the opening year in whcih at least two churches opened.

Context: CREATE TABLE church (open_date VARCHAR)

Answer: [SQL] SELECT open_date FROM church GROUP BY open_date HAVING COUNT(*) >= 2 [/SQL]


Question: Show the organizer and name for churches that opened between 1830 and 1840.

Context: CREATE TABLE church (organized_by VARCHAR, name VARCHAR, open_date INTEGER)

Answer: [SQL] SELECT organized_by, name FROM church WHERE open_date BETWEEN 1830 AND 1840 [/SQL]


Question: Show all opening years and the number of churches that opened in that year.

Context: CREATE TABLE church (open_date VARCHAR)

Answer: [SQL] SELECT open_date, COUNT(*) FROM church GROUP BY open_date [/SQL]


Question: Show the name and opening year for three churches that opened most recently.

Answer: [SQL] SELECT name, open_date FROM church ORDER BY open_date DESC LIMIT 3 [/SQL]


Question: How many female people are older than 30 in our record?

Context: CREATE TABLE people (is_male VARCHAR, age VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM people WHERE is_male = 'F' AND age > 30 [/SQL]


Question: Show the country where people older than 30 and younger than 25 are from.

Context: CREATE TABLE people (country VARCHAR, age INTEGER)

Answer: [SQL] SELECT country FROM people WHERE age < 25 INTERSECT SELECT country FROM people WHERE age > 30 [/SQL]


Question: Show the minimum, maximum, and average age for all people.

Context: CREATE TABLE people (age INTEGER)

Answer: [SQL] SELECT MIN(age), MAX(age), AVG(age) FROM people [/SQL]


Question: Show the name and country for all people whose age is smaller than the average.

Context: CREATE TABLE people (name VARCHAR, country VARCHAR, age INTEGER)

Answer: [SQL] SELECT name, country FROM people WHERE age < (SELECT AVG(age) FROM people) [/SQL]


Question: Show the pair of male and female names in all weddings after year 2014

Context: CREATE TABLE wedding (male_id VARCHAR, female_id VARCHAR, year INTEGER); CREATE TABLE people (name VARCHAR, people_id VARCHAR)

Answer: [SQL] SELECT T2.name, T3.name FROM wedding AS T1 JOIN people AS T2 ON T1.male_id = T2.people_id JOIN people AS T3 ON T1.female_id = T3.people_id WHERE T1.year > 2014 [/SQL]


Question: Show the name and age for all male people who don't have a wedding.

Context: CREATE TABLE wedding (name VARCHAR, age VARCHAR, is_male VARCHAR, people_id VARCHAR, male_id VARCHAR); CREATE TABLE people (name VARCHAR, age VARCHAR, is_male VARCHAR, people_id VARCHAR, male_id VARCHAR)

Answer: [SQL] SELECT name, age FROM people WHERE is_male = 'T' AND NOT people_id IN (SELECT male_id FROM wedding) [/SQL]


Question: Show all church names except for those that had a wedding in year 2015.

Context: CREATE TABLE church (name VARCHAR); CREATE TABLE wedding (church_id VARCHAR, year VARCHAR); CREATE TABLE church (name VARCHAR, church_id VARCHAR)

Answer: [SQL] SELECT name FROM church EXCEPT SELECT T1.name FROM church AS T1 JOIN wedding AS T2 ON T1.church_id = T2.church_id WHERE T2.year = 2015 [/SQL]


Question: Show all church names that have hosted least two weddings.

Context: CREATE TABLE wedding (church_id VARCHAR); CREATE TABLE church (name VARCHAR, church_id VARCHAR)

Answer: [SQL] SELECT T1.name FROM church AS T1 JOIN wedding AS T2 ON T1.church_id = T2.church_id GROUP BY T1.church_id HAVING COUNT(*) >= 2 [/SQL]


Question: Show the names for all females from Canada having a wedding in year 2016.

Context: CREATE TABLE people (name VARCHAR, people_id VARCHAR, country VARCHAR, is_male VARCHAR); CREATE TABLE wedding (female_id VARCHAR, year VARCHAR)

Answer: [SQL] SELECT T2.name FROM wedding AS T1 JOIN people AS T2 ON T1.female_id = T2.people_id WHERE T1.year = 2016 AND T2.is_male = 'F' AND T2.country = 'Canada' [/SQL]


Question: How many weddings are there in year 2016?

Context: CREATE TABLE wedding (YEAR VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM wedding WHERE YEAR = 2016 [/SQL]


Question: Show the church names for the weddings of all people older than 30.

Context: CREATE TABLE church (name VARCHAR, church_id VARCHAR); CREATE TABLE people (people_id VARCHAR, age VARCHAR); CREATE TABLE wedding (male_id VARCHAR, female_id VARCHAR, church_id VARCHAR)

Answer: [SQL] SELECT T4.name FROM wedding AS T1 JOIN people AS T2 ON T1.male_id = T2.people_id JOIN people AS T3 ON T1.female_id = T3.people_id JOIN church AS T4 ON T4.church_id = T1.church_id WHERE T2.age > 30 OR T3.age > 30 [/SQL]


Question: Show all countries and the number of people from each country.

Context: CREATE TABLE people (country VARCHAR)

Answer: [SQL] SELECT country, COUNT(*) FROM people GROUP BY country [/SQL]


Question: How many churches have a wedding in year 2016?

Context: CREATE TABLE wedding (church_id VARCHAR, YEAR VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT church_id) FROM wedding WHERE YEAR = 2016 [/SQL]


Question: How many artists do we have?

Context: CREATE TABLE artist (Id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM artist [/SQL]


Question: Show all artist name, age, and country ordered by the yeared they joined.

Context: CREATE TABLE artist (name VARCHAR, age VARCHAR, country VARCHAR, Year_Join VARCHAR)

Answer: [SQL] SELECT name, age, country FROM artist ORDER BY Year_Join [/SQL]


Question: What are all distinct country for artists?

Context: CREATE TABLE artist (country VARCHAR)

Answer: [SQL] SELECT DISTINCT country FROM artist [/SQL]


Question: Show all artist names and the year joined who are not from United States.

Context: CREATE TABLE artist (name VARCHAR, year_join VARCHAR, country VARCHAR)

Answer: [SQL] SELECT name, year_join FROM artist WHERE country <> 'United States' [/SQL]


Question: How many artists are above age 46 and joined after 1990?

Context: CREATE TABLE artist (age VARCHAR, year_join VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM artist WHERE age > 46 AND year_join > 1990 [/SQL]


Question: What is the average and minimum age of all artists from United States.

Context: CREATE TABLE artist (age INTEGER, country VARCHAR)

Answer: [SQL] SELECT AVG(age), MIN(age) FROM artist WHERE country = 'United States' [/SQL]


Question: What is the name of the artist who joined latest?

Context: CREATE TABLE artist (name VARCHAR, year_join VARCHAR)

Answer: [SQL] SELECT name FROM artist ORDER BY year_join DESC LIMIT 1 [/SQL]


Question: How many exhibition are there in year 2005 or after?

Context: CREATE TABLE exhibition (YEAR VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM exhibition WHERE YEAR >= 2005 [/SQL]


Question: Show theme and year for all exhibitions with ticket prices lower than 15.

Context: CREATE TABLE exhibition (theme VARCHAR, YEAR VARCHAR, ticket_price INTEGER)

Answer: [SQL] SELECT theme, YEAR FROM exhibition WHERE ticket_price < 15 [/SQL]


Question: Show all artist names and the number of exhibitions for each artist.

Context: CREATE TABLE artist (name VARCHAR, artist_id VARCHAR); CREATE TABLE exhibition (artist_id VARCHAR)

Answer: [SQL] SELECT T2.name, COUNT(*) FROM exhibition AS T1 JOIN artist AS T2 ON T1.artist_id = T2.artist_id GROUP BY T1.artist_id [/SQL]


Question: What is the name and country for the artist with most number of exhibitions?

Context: CREATE TABLE exhibition (artist_id VARCHAR); CREATE TABLE artist (name VARCHAR, country VARCHAR, artist_id VARCHAR)

Answer: [SQL] SELECT T2.name, T2.country FROM exhibition AS T1 JOIN artist AS T2 ON T1.artist_id = T2.artist_id GROUP BY T1.artist_id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Show names for artists without any exhibition.

Context: CREATE TABLE artist (name VARCHAR, artist_id VARCHAR); CREATE TABLE exhibition (name VARCHAR, artist_id VARCHAR)

Answer: [SQL] SELECT name FROM artist WHERE NOT artist_id IN (SELECT artist_id FROM exhibition) [/SQL]


Question: What is the theme and artist name for the exhibition with a ticket price higher than the average?

Context: CREATE TABLE exhibition (ticket_price INTEGER); CREATE TABLE exhibition (theme VARCHAR, artist_id VARCHAR, ticket_price INTEGER); CREATE TABLE artist (name VARCHAR, artist_id VARCHAR)

Answer: [SQL] SELECT T1.theme, T2.name FROM exhibition AS T1 JOIN artist AS T2 ON T1.artist_id = T2.artist_id WHERE T1.ticket_price > (SELECT AVG(ticket_price) FROM exhibition) [/SQL]


Question: Show the average, minimum, and maximum ticket prices for exhibitions for all years before 2009.

Context: CREATE TABLE exhibition (ticket_price INTEGER, YEAR INTEGER)

Answer: [SQL] SELECT AVG(ticket_price), MIN(ticket_price), MAX(ticket_price) FROM exhibition WHERE YEAR < 2009 [/SQL]


Question: Show theme and year for all exhibitions in an descending order of ticket price.

Context: CREATE TABLE exhibition (theme VARCHAR, YEAR VARCHAR, ticket_price VARCHAR)

Answer: [SQL] SELECT theme, YEAR FROM exhibition ORDER BY ticket_price DESC [/SQL]


Question: What is the theme, date, and attendance for the exhibition in year 2004?

Context: CREATE TABLE exhibition_record (date VARCHAR, attendance VARCHAR, exhibition_id VARCHAR); CREATE TABLE exhibition (theme VARCHAR, exhibition_id VARCHAR, year VARCHAR)

Answer: [SQL] SELECT T2.theme, T1.date, T1.attendance FROM exhibition_record AS T1 JOIN exhibition AS T2 ON T1.exhibition_id = T2.exhibition_id WHERE T2.year = 2004 [/SQL]


Question: Show all artist names who didn't have an exhibition in 2004.

Context: CREATE TABLE exhibition (artist_id VARCHAR, year VARCHAR); CREATE TABLE artist (name VARCHAR); CREATE TABLE artist (name VARCHAR, artist_id VARCHAR)

Answer: [SQL] SELECT name FROM artist EXCEPT SELECT T2.name FROM exhibition AS T1 JOIN artist AS T2 ON T1.artist_id = T2.artist_id WHERE T1.year = 2004 [/SQL]


Question: Show the theme for exhibitions with both records of an attendance below 100 and above 500.

Context: CREATE TABLE exhibition (theme VARCHAR, exhibition_id VARCHAR); CREATE TABLE exhibition_record (exhibition_id VARCHAR, attendance INTEGER)

Answer: [SQL] SELECT T2.theme FROM exhibition_record AS T1 JOIN exhibition AS T2 ON T1.exhibition_id = T2.exhibition_id WHERE T1.attendance < 100 INTERSECT SELECT T2.theme FROM exhibition_record AS T1 JOIN exhibition AS T2 ON T1.exhibition_id = T2.exhibition_id WHERE T1.attendance > 500 [/SQL]


Question: How many exhibitions have a attendance more than 100 or have a ticket price below 10?

Context: CREATE TABLE exhibition_record (exhibition_id VARCHAR, attendance VARCHAR); CREATE TABLE exhibition (exhibition_id VARCHAR, ticket_price VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM exhibition_record AS T1 JOIN exhibition AS T2 ON T1.exhibition_id = T2.exhibition_id WHERE T1.attendance > 100 OR T2.ticket_price < 10 [/SQL]


Question: Show all artist names with an average exhibition attendance over 200.

Context: CREATE TABLE artist (name VARCHAR, artist_id VARCHAR); CREATE TABLE exhibition (exhibition_id VARCHAR, artist_id VARCHAR); CREATE TABLE exhibition_record (exhibition_id VARCHAR, attendance INTEGER)

Answer: [SQL] SELECT T3.name FROM exhibition_record AS T1 JOIN exhibition AS T2 ON T1.exhibition_id = T2.exhibition_id JOIN artist AS T3 ON T3.artist_id = T2.artist_id GROUP BY T3.artist_id HAVING AVG(T1.attendance) > 200 [/SQL]


Question: Find the id of the item whose title is "orange".

Context: CREATE TABLE item (i_id VARCHAR, title VARCHAR)

Answer: [SQL] SELECT i_id FROM item WHERE title = "orange" [/SQL]


Question: List all information in the item table.

Context: CREATE TABLE item (Id VARCHAR)

Answer: [SQL] SELECT * FROM item [/SQL]


Question: Find the number of reviews.

Context: CREATE TABLE review (Id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM review [/SQL]


Question: How many users are there?

Context: CREATE TABLE useracct (Id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM useracct [/SQL]


Question: Find the average and maximum rating of all reviews.

Context: CREATE TABLE review (rating INTEGER)

Answer: [SQL] SELECT AVG(rating), MAX(rating) FROM review [/SQL]


Question: Find the highest rank of all reviews.

Context: CREATE TABLE review (rank INTEGER)

Answer: [SQL] SELECT MIN(rank) FROM review [/SQL]


Question: How many different users wrote some reviews?

Context: CREATE TABLE review (u_id VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT u_id) FROM review [/SQL]


Question: How many different items were reviewed by some users?

Context: CREATE TABLE review (i_id VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT i_id) FROM review [/SQL]


Question: Find the number of items that did not receive any review.

Context: CREATE TABLE review (i_id VARCHAR); CREATE TABLE item (i_id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM item WHERE NOT i_id IN (SELECT i_id FROM review) [/SQL]


Question: Find the names of users who did not leave any review.

Context: CREATE TABLE review (name VARCHAR, u_id VARCHAR); CREATE TABLE useracct (name VARCHAR, u_id VARCHAR)

Answer: [SQL] SELECT name FROM useracct WHERE NOT u_id IN (SELECT u_id FROM review) [/SQL]


Question: Find the names of goods that receive a rating of 10.

Context: CREATE TABLE item (title VARCHAR, i_id VARCHAR); CREATE TABLE review (i_id VARCHAR, rating VARCHAR)

Answer: [SQL] SELECT T1.title FROM item AS T1 JOIN review AS T2 ON T1.i_id = T2.i_id WHERE T2.rating = 10 [/SQL]


Question: Find the titles of items whose rating is higher than the average review rating of all items.

Context: CREATE TABLE review (rating INTEGER); CREATE TABLE item (title VARCHAR, i_id VARCHAR); CREATE TABLE review (i_id VARCHAR, rating INTEGER)

Answer: [SQL] SELECT T1.title FROM item AS T1 JOIN review AS T2 ON T1.i_id = T2.i_id WHERE T2.rating > (SELECT AVG(rating) FROM review) [/SQL]


Question: Find the titles of items that received any rating below 5.

Context: CREATE TABLE item (title VARCHAR, i_id VARCHAR); CREATE TABLE review (i_id VARCHAR, rating INTEGER)

Answer: [SQL] SELECT T1.title FROM item AS T1 JOIN review AS T2 ON T1.i_id = T2.i_id WHERE T2.rating < 5 [/SQL]


Question: Find the titles of items that received both a rating higher than 8 and a rating below 5.

Answer: [SQL] SELECT T1.title FROM item AS T1 JOIN review AS T2 ON T1.i_id = T2.i_id WHERE T2.rating > 8 INTERSECT SELECT T1.title FROM item AS T1 JOIN review AS T2 ON T1.i_id = T2.i_id WHERE T2.rating < 5 [/SQL]


Question: Find the names of items whose rank is higher than 3 and whose average rating is above 5.

Context: CREATE TABLE item (title VARCHAR, i_id VARCHAR); CREATE TABLE review (i_id VARCHAR, rank INTEGER, rating INTEGER)

Answer: [SQL] SELECT T1.title FROM item AS T1 JOIN review AS T2 ON T1.i_id = T2.i_id WHERE T2.rank > 3 INTERSECT SELECT T1.title FROM item AS T1 JOIN review AS T2 ON T1.i_id = T2.i_id GROUP BY T2.i_id HAVING AVG(T2.rating) > 5 [/SQL]


Question: Find the name of the item with the lowest average rating.

Answer: [SQL] SELECT T1.title FROM item AS T1 JOIN review AS T2 ON T1.i_id = T2.i_id GROUP BY T2.i_id ORDER BY AVG(T2.rating) LIMIT 1 [/SQL]


Question: List the titles of all items in alphabetic order .

Context: CREATE TABLE item (title VARCHAR)

Answer: [SQL] SELECT title FROM item ORDER BY title [/SQL]


Question: Find the name of the user who gives the most reviews.

Context: CREATE TABLE useracct (name VARCHAR, u_id VARCHAR); CREATE TABLE review (u_id VARCHAR)

Answer: [SQL] SELECT T1.name FROM useracct AS T1 JOIN review AS T2 ON T1.u_id = T2.u_id GROUP BY T2.u_id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Find the name and id of the item with the highest average rating.

Answer: [SQL] SELECT T1.title, T1.i_id FROM item AS T1 JOIN review AS T2 ON T1.i_id = T2.i_id GROUP BY T2.i_id ORDER BY AVG(T2.rating) DESC LIMIT 1 [/SQL]


Question: Find the name and id of the good with the highest average rank.

Context: CREATE TABLE review (i_id VARCHAR, rank INTEGER); CREATE TABLE item (title VARCHAR, i_id VARCHAR)

Answer: [SQL] SELECT T1.title, T1.i_id FROM item AS T1 JOIN review AS T2 ON T1.i_id = T2.i_id GROUP BY T2.i_id ORDER BY AVG(T2.rank) DESC LIMIT 1 [/SQL]


Question: For each user, return the name and the average rating of reviews given by them.

Context: CREATE TABLE review (rating INTEGER, u_id VARCHAR); CREATE TABLE useracct (name VARCHAR, u_id VARCHAR)

Answer: [SQL] SELECT T1.name, AVG(T2.rating) FROM useracct AS T1 JOIN review AS T2 ON T1.u_id = T2.u_id GROUP BY T2.u_id [/SQL]


Question: For each user, find their name and the number of reviews written by them.

Answer: [SQL] SELECT T1.name, COUNT(*) FROM useracct AS T1 JOIN review AS T2 ON T1.u_id = T2.u_id GROUP BY T2.u_id [/SQL]


Question: Find the name of the user who gave the highest rating.

Context: CREATE TABLE review (u_id VARCHAR, rating VARCHAR); CREATE TABLE useracct (name VARCHAR, u_id VARCHAR)

Answer: [SQL] SELECT T1.name FROM useracct AS T1 JOIN review AS T2 ON T1.u_id = T2.u_id ORDER BY T2.rating DESC LIMIT 1 [/SQL]


Question: Find the name of the source user with the highest average trust score.

Context: CREATE TABLE useracct (name VARCHAR, u_id VARCHAR); CREATE TABLE trust (source_u_id VARCHAR)

Answer: [SQL] SELECT T1.name FROM useracct AS T1 JOIN trust AS T2 ON T1.u_id = T2.source_u_id GROUP BY T2.source_u_id ORDER BY AVG(trust) DESC LIMIT 1 [/SQL]


Question: Find each target user's name and average trust score.

Context: CREATE TABLE trust (target_u_id VARCHAR); CREATE TABLE useracct (name VARCHAR, u_id VARCHAR)

Answer: [SQL] SELECT T1.name, AVG(trust) FROM useracct AS T1 JOIN trust AS T2 ON T1.u_id = T2.target_u_id GROUP BY T2.target_u_id [/SQL]


Question: Find the name of the target user with the lowest trust score.

Answer: [SQL] SELECT T1.name FROM useracct AS T1 JOIN trust AS T2 ON T1.u_id = T2.target_u_id ORDER BY trust LIMIT 1 [/SQL]


Question: Find the names of the items that did not receive any review.

Context: CREATE TABLE item (title VARCHAR, i_id VARCHAR); CREATE TABLE review (title VARCHAR, i_id VARCHAR)

Answer: [SQL] SELECT title FROM item WHERE NOT i_id IN (SELECT i_id FROM review) [/SQL]


Question: Find the number of users who did not write any review.

Context: CREATE TABLE review (u_id VARCHAR); CREATE TABLE useracct (u_id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM useracct WHERE NOT u_id IN (SELECT u_id FROM review) [/SQL]


Question: How many players are there?

Context: CREATE TABLE player (Id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM player [/SQL]


Question: List the names of players in ascending order of votes.

Context: CREATE TABLE player (Player_name VARCHAR, Votes VARCHAR)

Answer: [SQL] SELECT Player_name FROM player ORDER BY Votes [/SQL]


Question: What are the gender and occupation of players?

Context: CREATE TABLE player (Gender VARCHAR, Occupation VARCHAR)

Answer: [SQL] SELECT Gender, Occupation FROM player [/SQL]


Question: List the name and residence for players whose occupation is not "Researcher".

Context: CREATE TABLE player (Player_name VARCHAR, residence VARCHAR, Occupation VARCHAR)

Answer: [SQL] SELECT Player_name, residence FROM player WHERE Occupation <> "Researcher" [/SQL]


Question: Show the names of sponsors of players whose residence is either "Brandon" or "Birtle".

Context: CREATE TABLE player (Sponsor_name VARCHAR, Residence VARCHAR)

Answer: [SQL] SELECT Sponsor_name FROM player WHERE Residence = "Brandon" OR Residence = "Birtle" [/SQL]


Question: What is the name of the player with the largest number of votes?

Answer: [SQL] SELECT Player_name FROM player ORDER BY Votes DESC LIMIT 1 [/SQL]


Question: Show different occupations along with the number of players in each occupation.

Context: CREATE TABLE player (Occupation VARCHAR)

Answer: [SQL] SELECT Occupation, COUNT(*) FROM player GROUP BY Occupation [/SQL]


Question: Please show the most common occupation of players.

Answer: [SQL] SELECT Occupation FROM player GROUP BY Occupation ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: Show the residences that have at least two players.

Context: CREATE TABLE player (Residence VARCHAR)

Answer: [SQL] SELECT Residence FROM player GROUP BY Residence HAVING COUNT(*) >= 2 [/SQL]


Question: Show the names of players and names of their coaches.

Context: CREATE TABLE player (Player_name VARCHAR, Player_ID VARCHAR); CREATE TABLE coach (coach_name VARCHAR, Coach_ID VARCHAR); CREATE TABLE player_coach (Coach_ID VARCHAR, Player_ID VARCHAR)

Answer: [SQL] SELECT T3.Player_name, T2.coach_name FROM player_coach AS T1 JOIN coach AS T2 ON T1.Coach_ID = T2.Coach_ID JOIN player AS T3 ON T1.Player_ID = T3.Player_ID [/SQL]


Question: Show the names of players coached by the rank 1 coach.

Context: CREATE TABLE player (Player_name VARCHAR, Player_ID VARCHAR); CREATE TABLE coach (Coach_ID VARCHAR, Rank VARCHAR); CREATE TABLE player_coach (Coach_ID VARCHAR, Player_ID VARCHAR)

Answer: [SQL] SELECT T3.Player_name FROM player_coach AS T1 JOIN coach AS T2 ON T1.Coach_ID = T2.Coach_ID JOIN player AS T3 ON T1.Player_ID = T3.Player_ID WHERE T2.Rank = 1 [/SQL]


Question: Show the names and genders of players with a coach starting after 2011.

Context: CREATE TABLE player (Player_name VARCHAR, gender VARCHAR, Player_ID VARCHAR); CREATE TABLE player_coach (Coach_ID VARCHAR, Player_ID VARCHAR, Starting_year INTEGER); CREATE TABLE coach (Coach_ID VARCHAR)

Answer: [SQL] SELECT T3.Player_name, T3.gender FROM player_coach AS T1 JOIN coach AS T2 ON T1.Coach_ID = T2.Coach_ID JOIN player AS T3 ON T1.Player_ID = T3.Player_ID WHERE T1.Starting_year > 2011 [/SQL]


Question: Show the names of players and names of their coaches in descending order of the votes of players.

Context: CREATE TABLE coach (coach_name VARCHAR, Coach_ID VARCHAR); CREATE TABLE player_coach (Coach_ID VARCHAR, Player_ID VARCHAR); CREATE TABLE player (Player_name VARCHAR, Player_ID VARCHAR, Votes VARCHAR)

Answer: [SQL] SELECT T3.Player_name, T2.coach_name FROM player_coach AS T1 JOIN coach AS T2 ON T1.Coach_ID = T2.Coach_ID JOIN player AS T3 ON T1.Player_ID = T3.Player_ID ORDER BY T3.Votes DESC [/SQL]


Question: List the names of players that do not have coaches.

Context: CREATE TABLE player (Player_name VARCHAR, Player_ID VARCHAR); CREATE TABLE player_coach (Player_name VARCHAR, Player_ID VARCHAR)

Answer: [SQL] SELECT Player_name FROM player WHERE NOT Player_ID IN (SELECT Player_ID FROM player_coach) [/SQL]


Question: Show the residences that have both a player of gender "M" and a player of gender "F".

Context: CREATE TABLE player (Residence VARCHAR, gender VARCHAR)

Answer: [SQL] SELECT Residence FROM player WHERE gender = "M" INTERSECT SELECT Residence FROM player WHERE gender = "F" [/SQL]


Question: How many coaches does each club has? List the club id, name and the number of coaches.

Context: CREATE TABLE club (club_id VARCHAR, club_name VARCHAR); CREATE TABLE coach (club_id VARCHAR)

Answer: [SQL] SELECT T1.club_id, T1.club_name, COUNT(*) FROM club AS T1 JOIN coach AS T2 ON T1.club_id = T2.club_id GROUP BY T1.club_id [/SQL]


Question: How many gold medals has the club with the most coaches won?

Context: CREATE TABLE match_result (club_id VARCHAR, gold VARCHAR); CREATE TABLE coach (club_id VARCHAR)

Answer: [SQL] SELECT T1.club_id, T1.gold FROM match_result AS T1 JOIN coach AS T2 ON T1.club_id = T2.club_id GROUP BY T1.club_id ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: How many gymnasts are there?

Context: CREATE TABLE gymnast (Id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM gymnast [/SQL]


Question: List the total points of gymnasts in descending order.

Context: CREATE TABLE gymnast (Total_Points VARCHAR)

Answer: [SQL] SELECT Total_Points FROM gymnast ORDER BY Total_Points DESC [/SQL]


Question: List the total points of gymnasts in descending order of floor exercise points.

Context: CREATE TABLE gymnast (Total_Points VARCHAR, Floor_Exercise_Points VARCHAR)

Answer: [SQL] SELECT Total_Points FROM gymnast ORDER BY Floor_Exercise_Points DESC [/SQL]


Question: What is the average horizontal bar points for all gymnasts?

Context: CREATE TABLE gymnast (Horizontal_Bar_Points INTEGER)

Answer: [SQL] SELECT AVG(Horizontal_Bar_Points) FROM gymnast [/SQL]


Question: What are the names of people in ascending alphabetical order?

Context: CREATE TABLE People (Name VARCHAR)

Answer: [SQL] SELECT Name FROM People ORDER BY Name [/SQL]


Question: What are the names of gymnasts?

Context: CREATE TABLE gymnast (Gymnast_ID VARCHAR); CREATE TABLE people (Name VARCHAR, People_ID VARCHAR)

Answer: [SQL] SELECT T2.Name FROM gymnast AS T1 JOIN people AS T2 ON T1.Gymnast_ID = T2.People_ID [/SQL]


Question: What are the names of gymnasts whose hometown is not "Santo Domingo"?

Context: CREATE TABLE gymnast (Gymnast_ID VARCHAR); CREATE TABLE people (Name VARCHAR, People_ID VARCHAR, Hometown VARCHAR)

Answer: [SQL] SELECT T2.Name FROM gymnast AS T1 JOIN people AS T2 ON T1.Gymnast_ID = T2.People_ID WHERE T2.Hometown <> "Santo Domingo" [/SQL]


Question: What is the age of the tallest person?

Context: CREATE TABLE people (Age VARCHAR, Height VARCHAR)

Answer: [SQL] SELECT Age FROM people ORDER BY Height DESC LIMIT 1 [/SQL]


Question: List the names of the top 5 oldest people.

Context: CREATE TABLE People (Name VARCHAR, Age VARCHAR)

Answer: [SQL] SELECT Name FROM People ORDER BY Age DESC LIMIT 5 [/SQL]


Question: What is the total point count of the youngest gymnast?

Context: CREATE TABLE people (People_ID VARCHAR, Age VARCHAR); CREATE TABLE gymnast (Total_Points VARCHAR, Gymnast_ID VARCHAR)

Answer: [SQL] SELECT T1.Total_Points FROM gymnast AS T1 JOIN people AS T2 ON T1.Gymnast_ID = T2.People_ID ORDER BY T2.Age LIMIT 1 [/SQL]


Question: What is the average age of all gymnasts?

Context: CREATE TABLE people (Age INTEGER, People_ID VARCHAR); CREATE TABLE gymnast (Gymnast_ID VARCHAR)

Answer: [SQL] SELECT AVG(T2.Age) FROM gymnast AS T1 JOIN people AS T2 ON T1.Gymnast_ID = T2.People_ID [/SQL]


Question: What are the distinct hometowns of gymnasts with total points more than 57.5?

Context: CREATE TABLE gymnast (Gymnast_ID VARCHAR, Total_Points INTEGER); CREATE TABLE people (Hometown VARCHAR, People_ID VARCHAR)

Answer: [SQL] SELECT DISTINCT T2.Hometown FROM gymnast AS T1 JOIN people AS T2 ON T1.Gymnast_ID = T2.People_ID WHERE T1.Total_Points > 57.5 [/SQL]


Question: What are the hometowns of gymnasts and the corresponding number of gymnasts?

Context: CREATE TABLE gymnast (Gymnast_ID VARCHAR); CREATE TABLE people (Hometown VARCHAR, People_ID VARCHAR)

Answer: [SQL] SELECT T2.Hometown, COUNT(*) FROM gymnast AS T1 JOIN people AS T2 ON T1.Gymnast_ID = T2.People_ID GROUP BY T2.Hometown [/SQL]


Question: What is the most common hometown of gymnasts?

Answer: [SQL] SELECT T2.Hometown FROM gymnast AS T1 JOIN people AS T2 ON T1.Gymnast_ID = T2.People_ID GROUP BY T2.Hometown ORDER BY COUNT(*) DESC LIMIT 1 [/SQL]


Question: What are the hometowns that are shared by at least two gymnasts?

Answer: [SQL] SELECT T2.Hometown FROM gymnast AS T1 JOIN people AS T2 ON T1.Gymnast_ID = T2.People_ID GROUP BY T2.Hometown HAVING COUNT(*) >= 2 [/SQL]


Question: List the names of gymnasts in ascending order by their heights.

Context: CREATE TABLE gymnast (Gymnast_ID VARCHAR); CREATE TABLE people (Name VARCHAR, People_ID VARCHAR, Height VARCHAR)

Answer: [SQL] SELECT T2.Name FROM gymnast AS T1 JOIN people AS T2 ON T1.Gymnast_ID = T2.People_ID ORDER BY T2.Height [/SQL]


Question: List the distinct hometowns that are not associated with any gymnast.

Context: CREATE TABLE gymnast (Gymnast_ID VARCHAR); CREATE TABLE people (Hometown VARCHAR, People_ID VARCHAR); CREATE TABLE people (Hometown VARCHAR)

Answer: [SQL] SELECT DISTINCT Hometown FROM people EXCEPT SELECT DISTINCT T2.Hometown FROM gymnast AS T1 JOIN people AS T2 ON T1.Gymnast_ID = T2.People_ID [/SQL]


Question: Show the hometowns shared by people older than 23 and younger than 20.

Context: CREATE TABLE people (Hometown VARCHAR, Age INTEGER)

Answer: [SQL] SELECT Hometown FROM people WHERE Age > 23 INTERSECT SELECT Hometown FROM people WHERE Age < 20 [/SQL]


Question: How many distinct hometowns did these people have?

Context: CREATE TABLE people (Hometown VARCHAR)

Answer: [SQL] SELECT COUNT(DISTINCT Hometown) FROM people [/SQL]


Question: Show the ages of gymnasts in descending order of total points.

Context: CREATE TABLE people (Age VARCHAR, People_ID VARCHAR); CREATE TABLE gymnast (Gymnast_ID VARCHAR, Total_Points VARCHAR)

Answer: [SQL] SELECT T2.Age FROM gymnast AS T1 JOIN people AS T2 ON T1.Gymnast_ID = T2.People_ID ORDER BY T1.Total_Points DESC [/SQL]


Question: Find the total savings balance of all accounts except the account with name ‘Brown’.

Context: CREATE TABLE accounts (custid VARCHAR, name VARCHAR); CREATE TABLE savings (balance INTEGER, custid VARCHAR)

Answer: [SQL] SELECT SUM(T2.balance) FROM accounts AS T1 JOIN savings AS T2 ON T1.custid = T2.custid WHERE T1.name <> 'Brown' [/SQL]


Question: How many accounts are there in total?

Context: CREATE TABLE accounts (Id VARCHAR)

Answer: [SQL] SELECT COUNT(*) FROM accounts [/SQL]


Question: What is the total checking balance in all accounts?

Context: CREATE TABLE checking (balance INTEGER)

Answer: [SQL] SELECT SUM(balance) FROM checking [/SQL]


Question: Find the average checking balance.

Context: CREATE TABLE checking (balance INTEGER)

Answer: [SQL] SELECT AVG(balance) FROM checking [/SQL]


Question: How many accounts have a savings balance above the average savings balance?

Context: CREATE TABLE savings (balance INTEGER)

Answer: [SQL] SELECT COUNT(*) FROM savings WHERE balance > (SELECT AVG(balance) FROM savings) [/SQL]


Question: Find the name and id of accounts whose checking balance is below the maximum checking balance.

Context: CREATE TABLE accounts (custid VARCHAR, name VARCHAR); CREATE TABLE checking (balance INTEGER); CREATE TABLE checking (custid VARCHAR, balance INTEGER)

Answer: [SQL] SELECT T1.custid, T1.name FROM accounts AS T1 JOIN checking AS T2 ON T1.custid = T2.custid WHERE T2.balance < (SELECT MAX(balance) FROM checking) [/SQL]