context
stringlengths 27
489
| answer
stringlengths 18
557
| question
stringlengths 12
244
|
---|---|---|
CREATE TABLE Student (StuID VARCHAR, age INTEGER)
|
SELECT StuID FROM Student WHERE age = (SELECT MAX(age) FROM Student)
|
Show the student id of the oldest student.
|
CREATE TABLE Student (major VARCHAR)
|
SELECT major, COUNT(*) FROM Student GROUP BY major
|
Show all majors and corresponding number of students.
|
CREATE TABLE Student (major VARCHAR)
|
SELECT major FROM Student GROUP BY major ORDER BY COUNT(*) DESC LIMIT 1
|
Which major has most number of students?
|
CREATE TABLE Student (age VARCHAR)
|
SELECT age, COUNT(*) FROM Student GROUP BY age
|
Show all ages and corresponding number of students.
|
CREATE TABLE Student (sex VARCHAR, age INTEGER)
|
SELECT AVG(age), sex FROM Student GROUP BY sex
|
Show the average age for male and female students.
|
CREATE TABLE Student (city_code VARCHAR)
|
SELECT city_code, COUNT(*) FROM Student GROUP BY city_code
|
Show all cities and corresponding number of students.
|
CREATE TABLE Student (advisor VARCHAR)
|
SELECT advisor, COUNT(*) FROM Student GROUP BY advisor
|
Show all advisors and corresponding number of students.
|
CREATE TABLE Student (advisor VARCHAR)
|
SELECT advisor FROM Student GROUP BY advisor ORDER BY COUNT(*) DESC LIMIT 1
|
Which advisor has most number of students?
|
CREATE TABLE Has_allergy (Allergy VARCHAR)
|
SELECT COUNT(*) FROM Has_allergy WHERE Allergy = "Cat"
|
How many students have cat allergies?
|
CREATE TABLE Has_allergy (StuID VARCHAR)
|
SELECT StuID FROM Has_allergy GROUP BY StuID HAVING COUNT(*) >= 2
|
Show all student IDs who have at least two allergies.
|
CREATE TABLE Has_allergy (StuID VARCHAR); CREATE TABLE Student (StuID VARCHAR)
|
SELECT StuID FROM Student EXCEPT SELECT StuID FROM Has_allergy
|
What are the student ids of students who don't have any allergies?
|
CREATE TABLE Student (StuID VARCHAR, sex VARCHAR); CREATE TABLE has_allergy (StuID VARCHAR, allergy VARCHAR)
|
SELECT COUNT(*) FROM has_allergy AS T1 JOIN Student AS T2 ON T1.StuID = T2.StuID WHERE T2.sex = "F" AND T1.allergy = "Milk" OR T1.allergy = "Eggs"
|
How many female students have milk or egg allergies?
|
CREATE TABLE Has_allergy (allergy VARCHAR); CREATE TABLE Allergy_type (allergy VARCHAR, allergytype VARCHAR)
|
SELECT COUNT(*) FROM Has_allergy AS T1 JOIN Allergy_type AS T2 ON T1.allergy = T2.allergy WHERE T2.allergytype = "food"
|
How many students have a food allergy?
|
CREATE TABLE Has_allergy (Allergy VARCHAR)
|
SELECT Allergy FROM Has_allergy GROUP BY Allergy ORDER BY COUNT(*) DESC LIMIT 1
|
Which allergy has most number of students affected?
|
CREATE TABLE Has_allergy (Allergy VARCHAR)
|
SELECT Allergy, COUNT(*) FROM Has_allergy GROUP BY Allergy
|
Show all allergies with number of students affected.
|
CREATE TABLE Has_allergy (allergy VARCHAR); CREATE TABLE Allergy_type (allergytype VARCHAR, allergy VARCHAR)
|
SELECT T2.allergytype, COUNT(*) FROM Has_allergy AS T1 JOIN Allergy_type AS T2 ON T1.allergy = T2.allergy GROUP BY T2.allergytype
|
Show all allergy type with number of students affected.
|
CREATE TABLE Has_allergy (lname VARCHAR, age VARCHAR, StuID VARCHAR, Allergy VARCHAR); CREATE TABLE Student (lname VARCHAR, age VARCHAR, StuID VARCHAR, Allergy VARCHAR)
|
SELECT lname, age FROM Student WHERE StuID IN (SELECT StuID FROM Has_allergy WHERE Allergy = "Milk" INTERSECT SELECT StuID FROM Has_allergy WHERE Allergy = "Cat")
|
Find the last name and age of the student who has allergy to both milk and cat.
|
CREATE TABLE Has_allergy (Allergy VARCHAR, StuID VARCHAR); CREATE TABLE Student (StuID VARCHAR, Fname VARCHAR); CREATE TABLE Allergy_type (Allergy VARCHAR, AllergyType VARCHAR)
|
SELECT T1.Allergy, T1.AllergyType FROM Allergy_type AS T1 JOIN Has_allergy AS T2 ON T1.Allergy = T2.Allergy JOIN Student AS T3 ON T3.StuID = T2.StuID WHERE T3.Fname = "Lisa" ORDER BY T1.Allergy
|
What are the allergies and their types that the student with first name Lisa has? And order the result by name of allergies.
|
CREATE TABLE Student (fname VARCHAR, sex VARCHAR, StuID VARCHAR, Allergy VARCHAR); CREATE TABLE Has_allergy (fname VARCHAR, sex VARCHAR, StuID VARCHAR, Allergy VARCHAR)
|
SELECT fname, sex FROM Student WHERE StuID IN (SELECT StuID FROM Has_allergy WHERE Allergy = "Milk" EXCEPT SELECT StuID FROM Has_allergy WHERE Allergy = "Cat")
|
Find the first name and gender of the student who has allergy to milk but not cat.
|
CREATE TABLE Student (age INTEGER, StuID VARCHAR); CREATE TABLE Allergy_Type (Allergy VARCHAR, allergytype VARCHAR); CREATE TABLE Has_allergy (StuID VARCHAR, Allergy VARCHAR)
|
SELECT AVG(age) FROM Student WHERE StuID IN (SELECT T1.StuID FROM Has_allergy AS T1 JOIN Allergy_Type AS T2 ON T1.Allergy = T2.Allergy WHERE T2.allergytype = "food" INTERSECT SELECT T1.StuID FROM Has_allergy AS T1 JOIN Allergy_Type AS T2 ON T1.Allergy = T2.Allergy WHERE T2.allergytype = "animal")
|
Find the average age of the students who have allergies with food and animal types.
|
CREATE TABLE Student (fname VARCHAR, lname VARCHAR, StuID VARCHAR); CREATE TABLE Allergy_Type (Allergy VARCHAR, allergytype VARCHAR); CREATE TABLE Has_allergy (StuID VARCHAR, Allergy VARCHAR)
|
SELECT fname, lname FROM Student WHERE NOT StuID IN (SELECT T1.StuID FROM Has_allergy AS T1 JOIN Allergy_Type AS T2 ON T1.Allergy = T2.Allergy WHERE T2.allergytype = "food")
|
List the first and last name of the students who do not have any food type allergy.
|
CREATE TABLE Has_allergy (Allergy VARCHAR); CREATE TABLE Allergy_Type (Allergy VARCHAR, allergytype VARCHAR); CREATE TABLE Student (sex VARCHAR, StuID VARCHAR)
|
SELECT COUNT(*) FROM Student WHERE sex = "M" AND StuID IN (SELECT StuID FROM Has_allergy AS T1 JOIN Allergy_Type AS T2 ON T1.Allergy = T2.Allergy WHERE T2.allergytype = "food")
|
Find the number of male (sex is 'M') students who have some food type allery.
|
CREATE TABLE Has_Allergy (stuid VARCHAR, Allergy VARCHAR); CREATE TABLE Student (fname VARCHAR, city_code VARCHAR, stuid VARCHAR)
|
SELECT DISTINCT T1.fname, T1.city_code FROM Student AS T1 JOIN Has_Allergy AS T2 ON T1.stuid = T2.stuid WHERE T2.Allergy = "Milk" OR T2.Allergy = "Cat"
|
Find the different first names and cities of the students who have allergy to milk or cat.
|
CREATE TABLE Allergy_Type (Allergy VARCHAR, allergytype VARCHAR); CREATE TABLE Has_allergy (Allergy VARCHAR); CREATE TABLE Student (age VARCHAR, StuID VARCHAR)
|
SELECT COUNT(*) FROM Student WHERE age > 18 AND NOT StuID IN (SELECT StuID FROM Has_allergy AS T1 JOIN Allergy_Type AS T2 ON T1.Allergy = T2.Allergy WHERE T2.allergytype = "food" OR T2.allergytype = "animal")
|
Find the number of students who are older than 18 and do not have allergy to either food or animal.
|
CREATE TABLE Has_allergy (fname VARCHAR, major VARCHAR, StuID VARCHAR, Allergy VARCHAR); CREATE TABLE Student (fname VARCHAR, major VARCHAR, StuID VARCHAR, Allergy VARCHAR)
|
SELECT fname, major FROM Student WHERE NOT StuID IN (SELECT StuID FROM Has_allergy WHERE Allergy = "Soy")
|
Find the first name and major of the students who are not allegry to soy.
|
CREATE TABLE invoices (billing_country VARCHAR)
|
SELECT billing_country, COUNT(*) FROM invoices GROUP BY billing_country ORDER BY COUNT(*) DESC LIMIT 5
|
A list of the top 5 countries by number of invoices. List country name and number of invoices.
|
CREATE TABLE invoices (billing_country VARCHAR, total INTEGER)
|
SELECT billing_country, SUM(total) FROM invoices GROUP BY billing_country ORDER BY SUM(total) DESC LIMIT 8
|
A list of the top 8 countries by gross/total invoice size. List country name and gross invoice size.
|
CREATE TABLE invoices (billing_country VARCHAR, total INTEGER)
|
SELECT billing_country, AVG(total) FROM invoices GROUP BY billing_country ORDER BY AVG(total) DESC LIMIT 10
|
A list of the top 10 countries by average invoice size. List country name and average invoice size.
|
CREATE TABLE customers (first_name VARCHAR, last_name VARCHAR, id VARCHAR); CREATE TABLE invoices (customer_id VARCHAR, invoice_date VARCHAR)
|
SELECT T1.first_name, T1.last_name FROM customers AS T1 JOIN invoices AS T2 ON T2.customer_id = T1.id ORDER BY T2.invoice_date DESC LIMIT 5
|
Find out 5 customers who most recently purchased something. List customers' first and last name.
|
CREATE TABLE customers (first_name VARCHAR, last_name VARCHAR, id VARCHAR); CREATE TABLE invoices (customer_id VARCHAR)
|
SELECT T1.first_name, T1.last_name, COUNT(*) FROM customers AS T1 JOIN invoices AS T2 ON T2.customer_id = T1.id GROUP BY T1.id ORDER BY COUNT(*) DESC LIMIT 10
|
Find out the top 10 customers by total number of orders. List customers' first and last name and the number of total orders.
|
CREATE TABLE invoices (total INTEGER, customer_id VARCHAR); CREATE TABLE customers (first_name VARCHAR, last_name VARCHAR, id VARCHAR)
|
SELECT T1.first_name, T1.last_name, SUM(T2.total) FROM customers AS T1 JOIN invoices AS T2 ON T2.customer_id = T1.id GROUP BY T1.id ORDER BY SUM(T2.total) DESC LIMIT 10
|
List the top 10 customers by total gross sales. List customers' first and last name and total gross sales.
|
CREATE TABLE tracks (genre_id VARCHAR); CREATE TABLE genres (name VARCHAR, id VARCHAR)
|
SELECT T1.name, COUNT(*) FROM genres AS T1 JOIN tracks AS T2 ON T2.genre_id = T1.id GROUP BY T1.id ORDER BY COUNT(*) DESC LIMIT 5
|
List the top 5 genres by number of tracks. List genres name and total tracks.
|
CREATE TABLE albums (title VARCHAR)
|
SELECT title FROM albums
|
List every album's title.
|
CREATE TABLE albums (title VARCHAR)
|
SELECT title FROM albums ORDER BY title
|
List every album ordered by album title in ascending order.
|
CREATE TABLE albums (title VARCHAR)
|
SELECT title FROM albums WHERE title LIKE 'A%' ORDER BY title
|
List every album whose title starts with A in alphabetical order.
|
CREATE TABLE customers (first_name VARCHAR, last_name VARCHAR, id VARCHAR); CREATE TABLE invoices (customer_id VARCHAR)
|
SELECT T1.first_name, T1.last_name FROM customers AS T1 JOIN invoices AS T2 ON T2.customer_id = T1.id ORDER BY total LIMIT 10
|
List the customers first and last name of 10 least expensive invoices.
|
CREATE TABLE invoices (total INTEGER, billing_city VARCHAR, billing_state VARCHAR)
|
SELECT SUM(total) FROM invoices WHERE billing_city = "Chicago" AND billing_state = "IL"
|
List total amount of invoice from Chicago, IL.
|
CREATE TABLE invoices (billing_city VARCHAR, billing_state VARCHAR)
|
SELECT COUNT(*) FROM invoices WHERE billing_city = "Chicago" AND billing_state = "IL"
|
List the number of invoices from Chicago, IL.
|
CREATE TABLE invoices (billing_state VARCHAR, billing_country VARCHAR)
|
SELECT billing_state, COUNT(*) FROM invoices WHERE billing_country = "USA" GROUP BY billing_state
|
List the number of invoices from the US, grouped by state.
|
CREATE TABLE invoices (billing_state VARCHAR, billing_country VARCHAR)
|
SELECT billing_state, COUNT(*) FROM invoices WHERE billing_country = "USA" GROUP BY billing_state ORDER BY COUNT(*) DESC LIMIT 1
|
List the state in the US with the most invoices.
|
CREATE TABLE invoices (billing_state VARCHAR, total INTEGER)
|
SELECT billing_state, COUNT(*), SUM(total) FROM invoices WHERE billing_state = "CA"
|
List the number of invoices and the invoice total from California.
|
CREATE TABLE artists (id VARCHAR, name VARCHAR); CREATE TABLE albums (title VARCHAR, artist_id VARCHAR)
|
SELECT T1.title FROM albums AS T1 JOIN artists AS T2 ON T1.artist_id = T2.id WHERE T2.name = "Aerosmith"
|
List Aerosmith's albums.
|
CREATE TABLE artists (id VARCHAR, name VARCHAR); CREATE TABLE albums (artist_id VARCHAR)
|
SELECT COUNT(*) FROM albums AS T1 JOIN artists AS T2 ON T1.artist_id = T2.id WHERE T2.name = "Billy Cobham"
|
How many albums does Billy Cobham has?
|
CREATE TABLE customers (company VARCHAR, first_name VARCHAR, last_name VARCHAR)
|
SELECT company FROM customers WHERE first_name = "Eduardo" AND last_name = "Martins"
|
Eduardo Martins is a customer at which company?
|
CREATE TABLE customers (email VARCHAR, phone VARCHAR, first_name VARCHAR, last_name VARCHAR)
|
SELECT email, phone FROM customers WHERE first_name = "Astrid" AND last_name = "Gruber"
|
What is Astrid Gruber's email and phone number?
|
CREATE TABLE customers (city VARCHAR)
|
SELECT COUNT(*) FROM customers WHERE city = "Prague"
|
How many customers live in Prague city?
|
CREATE TABLE customers (state VARCHAR)
|
SELECT COUNT(*) FROM customers WHERE state = "CA"
|
How many customers in state of CA?
|
CREATE TABLE customers (country VARCHAR, first_name VARCHAR, last_name VARCHAR)
|
SELECT country FROM customers WHERE first_name = "Roberto" AND last_name = "Almeida"
|
What country does Roberto Almeida live?
|
CREATE TABLE artists (id VARCHAR, name VARCHAR); CREATE TABLE albums (title VARCHAR, artist_id VARCHAR)
|
SELECT T2.title FROM artists AS T1 JOIN albums AS T2 ON T1.id = T2.artist_id WHERE T1.name LIKE '%Led%'
|
List the name of albums that are released by aritist whose name has 'Led'
|
CREATE TABLE employees (id VARCHAR, first_name VARCHAR, last_name VARCHAR); CREATE TABLE customers (support_rep_id VARCHAR)
|
SELECT COUNT(*) FROM employees AS T1 JOIN customers AS T2 ON T2.support_rep_id = T1.id WHERE T1.first_name = "Steve" AND T1.last_name = "Johnson"
|
How many customers does Steve Johnson support?
|
CREATE TABLE employees (title VARCHAR, phone VARCHAR, hire_date VARCHAR, first_name VARCHAR, last_name VARCHAR)
|
SELECT title, phone, hire_date FROM employees WHERE first_name = "Nancy" AND last_name = "Edwards"
|
What is the title, phone and hire date of Nancy Edwards?
|
CREATE TABLE employees (id VARCHAR, first_name VARCHAR, last_name VARCHAR); CREATE TABLE employees (first_name VARCHAR, last_name VARCHAR, reports_to VARCHAR)
|
SELECT T2.first_name, T2.last_name FROM employees AS T1 JOIN employees AS T2 ON T1.id = T2.reports_to WHERE T1.first_name = "Nancy" AND T1.last_name = "Edwards"
|
find the full name of employees who report to Nancy Edwards?
|
CREATE TABLE employees (address VARCHAR, first_name VARCHAR, last_name VARCHAR)
|
SELECT address FROM employees WHERE first_name = "Nancy" AND last_name = "Edwards"
|
What is the address of employee Nancy Edwards?
|
CREATE TABLE employees (first_name VARCHAR, last_name VARCHAR, id VARCHAR); CREATE TABLE customers (support_rep_id VARCHAR)
|
SELECT T1.first_name, T1.last_name FROM employees AS T1 JOIN customers AS T2 ON T1.id = T2.support_rep_id GROUP BY T1.id ORDER BY COUNT(*) DESC LIMIT 1
|
Find the full name of employee who supported the most number of customers.
|
CREATE TABLE employees (country VARCHAR)
|
SELECT COUNT(*) FROM employees WHERE country = "Canada"
|
How many employees are living in Canada?
|
CREATE TABLE employees (phone VARCHAR, first_name VARCHAR, last_name VARCHAR)
|
SELECT phone FROM employees WHERE first_name = "Nancy" AND last_name = "Edwards"
|
What is employee Nancy Edwards's phone number?
|
CREATE TABLE employees (first_name VARCHAR, last_name VARCHAR, birth_date VARCHAR)
|
SELECT first_name, last_name FROM employees ORDER BY birth_date DESC LIMIT 1
|
Who is the youngest employee in the company? List employee's first and last name.
|
CREATE TABLE employees (first_name VARCHAR, last_name VARCHAR, hire_date VARCHAR)
|
SELECT first_name, last_name FROM employees ORDER BY hire_date LIMIT 10
|
List top 10 employee work longest in the company. List employee's first and last name.
|
CREATE TABLE employees (city VARCHAR, title VARCHAR)
|
SELECT COUNT(*), city FROM employees WHERE title = 'IT Staff' GROUP BY city
|
Find the number of employees whose title is IT Staff from each city?
|
CREATE TABLE employees (first_name VARCHAR, last_name VARCHAR, id VARCHAR); CREATE TABLE employees (reports_to VARCHAR)
|
SELECT T2.first_name, T2.last_name, COUNT(T1.reports_to) FROM employees AS T1 JOIN employees AS T2 ON T1.reports_to = T2.id GROUP BY T1.reports_to ORDER BY COUNT(T1.reports_to) DESC LIMIT 1
|
Which employee manage most number of peoples? List employee's first and last name, and number of people report to that employee.
|
CREATE TABLE invoices (customer_id VARCHAR); CREATE TABLE customers (id VARCHAR, first_name VARCHAR, last_name VARCHAR)
|
SELECT COUNT(*) FROM customers AS T1 JOIN invoices AS T2 ON T1.id = T2.customer_id WHERE T1.first_name = "Lucas" AND T1.last_name = "Mancini"
|
How many orders does Lucas Mancini has?
|
CREATE TABLE invoices (total INTEGER, customer_id VARCHAR); CREATE TABLE customers (id VARCHAR, first_name VARCHAR, last_name VARCHAR)
|
SELECT SUM(T2.total) FROM customers AS T1 JOIN invoices AS T2 ON T1.id = T2.customer_id WHERE T1.first_name = "Lucas" AND T1.last_name = "Mancini"
|
What is the total amount of money spent by Lucas Mancini?
|
CREATE TABLE media_types (name VARCHAR)
|
SELECT name FROM media_types
|
List all media types.
|
CREATE TABLE genres (name VARCHAR)
|
SELECT DISTINCT name FROM genres
|
List all different genre types.
|
CREATE TABLE playlists (name VARCHAR)
|
SELECT name FROM playlists
|
List the name of all playlist.
|
CREATE TABLE tracks (composer VARCHAR, name VARCHAR)
|
SELECT composer FROM tracks WHERE name = "Fast As a Shark"
|
Who is the composer of track Fast As a Shark?
|
CREATE TABLE tracks (milliseconds VARCHAR, name VARCHAR)
|
SELECT milliseconds FROM tracks WHERE name = "Fast As a Shark"
|
How long does track Fast As a Shark has?
|
CREATE TABLE genres (id VARCHAR, name VARCHAR); CREATE TABLE tracks (name VARCHAR, genre_id VARCHAR)
|
SELECT T2.name FROM genres AS T1 JOIN tracks AS T2 ON T1.id = T2.genre_id WHERE T1.name = "Rock"
|
What is the name of tracks whose genre is Rock?
|
CREATE TABLE tracks (genre_id VARCHAR, name VARCHAR); CREATE TABLE albums (title VARCHAR, id VARCHAR)
|
SELECT T1.title FROM albums AS T1 JOIN tracks AS T2 ON T1.id = T2.genre_id WHERE T2.name = "Balls to the Wall"
|
What is title of album which track Balls to the Wall belongs to?
|
CREATE TABLE tracks (name VARCHAR, genre_id VARCHAR); CREATE TABLE albums (id VARCHAR, title VARCHAR)
|
SELECT T2.name FROM albums AS T1 JOIN tracks AS T2 ON T1.id = T2.genre_id WHERE T1.title = "Balls to the Wall"
|
List name of all tracks in Balls to the Wall.
|
CREATE TABLE tracks (album_id VARCHAR); CREATE TABLE albums (title VARCHAR, id VARCHAR)
|
SELECT T1.title FROM albums AS T1 JOIN tracks AS T2 ON T1.id = T2.album_id GROUP BY T1.id HAVING COUNT(T1.id) > 10
|
List title of albums have the number of tracks greater than 10.
|
CREATE TABLE genres (id VARCHAR, name VARCHAR); CREATE TABLE tracks (name VARCHAR, genre_id VARCHAR, media_type_id VARCHAR); CREATE TABLE media_types (id VARCHAR, name VARCHAR)
|
SELECT T2.name FROM genres AS T1 JOIN tracks AS T2 ON T1.id = T2.genre_id JOIN media_types AS T3 ON T3.id = T2.media_type_id WHERE T1.name = "Rock" AND T3.name = "MPEG audio file"
|
List the name of tracks belongs to genre Rock and whose media type is MPEG audio file.
|
CREATE TABLE genres (id VARCHAR, name VARCHAR); CREATE TABLE tracks (name VARCHAR, genre_id VARCHAR, media_type_id VARCHAR); CREATE TABLE media_types (id VARCHAR, name VARCHAR)
|
SELECT T2.name FROM genres AS T1 JOIN tracks AS T2 ON T1.id = T2.genre_id JOIN media_types AS T3 ON T3.id = T2.media_type_id WHERE T1.name = "Rock" OR T3.name = "MPEG audio file"
|
List the name of tracks belongs to genre Rock or media type is MPEG audio file.
|
CREATE TABLE genres (id VARCHAR, name VARCHAR); CREATE TABLE tracks (name VARCHAR, genre_id VARCHAR)
|
SELECT T2.name FROM genres AS T1 JOIN tracks AS T2 ON T1.id = T2.genre_id WHERE T1.name = "Rock" OR T1.name = "Jazz"
|
List the name of tracks belongs to genre Rock or genre Jazz.
|
CREATE TABLE playlists (id VARCHAR, name VARCHAR); CREATE TABLE playlist_tracks (track_id VARCHAR, playlist_id VARCHAR); CREATE TABLE tracks (name VARCHAR, id VARCHAR)
|
SELECT T1.name FROM tracks AS T1 JOIN playlist_tracks AS T2 ON T1.id = T2.track_id JOIN playlists AS T3 ON T3.id = T2.playlist_id WHERE T3.name = "Movies"
|
List the name of all tracks in the playlists of Movies.
|
CREATE TABLE playlist_tracks (playlist_id VARCHAR, track_id VARCHAR); CREATE TABLE playlists (name VARCHAR, id VARCHAR)
|
SELECT T2.name FROM playlist_tracks AS T1 JOIN playlists AS T2 ON T2.id = T1.playlist_id GROUP BY T1.playlist_id HAVING COUNT(T1.track_id) > 100
|
List the name of playlist which has number of tracks greater than 100.
|
CREATE TABLE invoices (id VARCHAR, customer_id VARCHAR); CREATE TABLE invoice_lines (track_id VARCHAR, invoice_id VARCHAR); CREATE TABLE tracks (name VARCHAR, id VARCHAR); CREATE TABLE customers (id VARCHAR, first_name VARCHAR, last_name VARCHAR)
|
SELECT T1.name FROM tracks AS T1 JOIN invoice_lines AS T2 ON T1.id = T2.track_id JOIN invoices AS T3 ON T3.id = T2.invoice_id JOIN customers AS T4 ON T4.id = T3.customer_id WHERE T4.first_name = "Daan" AND T4.last_name = "Peeters"
|
List all tracks bought by customer Daan Peeters.
|
CREATE TABLE tracks (unit_price VARCHAR, name VARCHAR)
|
SELECT unit_price FROM tracks WHERE name = "Fast As a Shark"
|
How much is the track Fast As a Shark?
|
CREATE TABLE playlists (id VARCHAR, name VARCHAR); CREATE TABLE playlist_tracks (track_id VARCHAR, playlist_id VARCHAR); CREATE TABLE tracks (name VARCHAR, id VARCHAR)
|
SELECT T1.name FROM tracks AS T1 JOIN playlist_tracks AS T2 ON T1.id = T2.track_id JOIN playlists AS T3 ON T2.playlist_id = T3.id WHERE T3.name = 'Movies' EXCEPT SELECT T1.name FROM tracks AS T1 JOIN playlist_tracks AS T2 ON T1.id = T2.track_id JOIN playlists AS T3 ON T2.playlist_id = T3.id WHERE T3.name = 'Music'
|
Find the name of tracks which are in Movies playlist but not in music playlist.
|
CREATE TABLE playlists (id VARCHAR, name VARCHAR); CREATE TABLE playlist_tracks (track_id VARCHAR, playlist_id VARCHAR); CREATE TABLE tracks (name VARCHAR, id VARCHAR)
|
SELECT T1.name FROM tracks AS T1 JOIN playlist_tracks AS T2 ON T1.id = T2.track_id JOIN playlists AS T3 ON T2.playlist_id = T3.id WHERE T3.name = 'Movies' INTERSECT SELECT T1.name FROM tracks AS T1 JOIN playlist_tracks AS T2 ON T1.id = T2.track_id JOIN playlists AS T3 ON T2.playlist_id = T3.id WHERE T3.name = 'Music'
|
Find the name of tracks which are in both Movies and music playlists.
|
CREATE TABLE tracks (genre_id VARCHAR); CREATE TABLE genres (name VARCHAR, id VARCHAR)
|
SELECT COUNT(*), T1.name FROM genres AS T1 JOIN tracks AS T2 ON T1.id = T2.genre_id GROUP BY T1.name
|
Find number of tracks in each genre?
|
CREATE TABLE editor (Id VARCHAR)
|
SELECT COUNT(*) FROM editor
|
How many editors are there?
|
CREATE TABLE editor (Name VARCHAR, Age VARCHAR)
|
SELECT Name FROM editor ORDER BY Age
|
List the names of editors in ascending order of age.
|
CREATE TABLE editor (Name VARCHAR, Age VARCHAR)
|
SELECT Name, Age FROM editor
|
What are the names and ages of editors?
|
CREATE TABLE editor (Name VARCHAR, Age INTEGER)
|
SELECT Name FROM editor WHERE Age > 25
|
List the names of editors who are older than 25.
|
CREATE TABLE editor (Name VARCHAR, Age VARCHAR)
|
SELECT Name FROM editor WHERE Age = 24 OR Age = 25
|
Show the names of editors of age either 24 or 25.
|
CREATE TABLE editor (Name VARCHAR, Age VARCHAR)
|
SELECT Name FROM editor ORDER BY Age LIMIT 1
|
What is the name of the youngest editor?
|
CREATE TABLE editor (Age VARCHAR)
|
SELECT Age, COUNT(*) FROM editor GROUP BY Age
|
What are the different ages of editors? Show each age along with the number of editors of that age.
|
CREATE TABLE editor (Age VARCHAR)
|
SELECT Age FROM editor GROUP BY Age ORDER BY COUNT(*) DESC LIMIT 1
|
Please show the most common age of editors.
|
CREATE TABLE journal (Theme VARCHAR)
|
SELECT DISTINCT Theme FROM journal
|
Show the distinct themes of journals.
|
CREATE TABLE journal_committee (Editor_ID VARCHAR, Journal_ID VARCHAR); CREATE TABLE editor (Name VARCHAR, Editor_ID VARCHAR); CREATE TABLE journal (Theme VARCHAR, Journal_ID VARCHAR)
|
SELECT T2.Name, T3.Theme FROM journal_committee AS T1 JOIN editor AS T2 ON T1.Editor_ID = T2.Editor_ID JOIN journal AS T3 ON T1.Journal_ID = T3.Journal_ID
|
Show the names of editors and the theme of journals for which they serve on committees.
|
CREATE TABLE journal_committee (Editor_ID VARCHAR, Journal_ID VARCHAR); CREATE TABLE editor (Name VARCHAR, age VARCHAR, Editor_ID VARCHAR); CREATE TABLE journal (Theme VARCHAR, Journal_ID VARCHAR)
|
SELECT T2.Name, T2.age, T3.Theme FROM journal_committee AS T1 JOIN editor AS T2 ON T1.Editor_ID = T2.Editor_ID JOIN journal AS T3 ON T1.Journal_ID = T3.Journal_ID ORDER BY T3.Theme
|
Show the names and ages of editors and the theme of journals for which they serve on committees, in ascending alphabetical order of theme.
|
CREATE TABLE journal_committee (Editor_ID VARCHAR, Journal_ID VARCHAR); CREATE TABLE editor (Name VARCHAR, Editor_ID VARCHAR); CREATE TABLE journal (Journal_ID VARCHAR, Sales INTEGER)
|
SELECT T2.Name FROM journal_committee AS T1 JOIN editor AS T2 ON T1.Editor_ID = T2.Editor_ID JOIN journal AS T3 ON T1.Journal_ID = T3.Journal_ID WHERE T3.Sales > 3000
|
Show the names of editors that are on the committee of journals with sales bigger than 3000.
|
CREATE TABLE editor (editor_id VARCHAR, Name VARCHAR, Editor_ID VARCHAR); CREATE TABLE journal_committee (Editor_ID VARCHAR)
|
SELECT T1.editor_id, T1.Name, COUNT(*) FROM editor AS T1 JOIN journal_committee AS T2 ON T1.Editor_ID = T2.Editor_ID GROUP BY T1.editor_id
|
Show the id, name of each editor and the number of journal committees they are on.
|
CREATE TABLE editor (Name VARCHAR, Editor_ID VARCHAR); CREATE TABLE journal_committee (Editor_ID VARCHAR)
|
SELECT T1.Name FROM editor AS T1 JOIN journal_committee AS T2 ON T1.Editor_ID = T2.Editor_ID GROUP BY T1.Name HAVING COUNT(*) >= 2
|
Show the names of editors that are on at least two journal committees.
|
CREATE TABLE editor (Name VARCHAR, editor_id VARCHAR); CREATE TABLE journal_committee (Name VARCHAR, editor_id VARCHAR)
|
SELECT Name FROM editor WHERE NOT editor_id IN (SELECT editor_id FROM journal_committee)
|
List the names of editors that are not on any journal committee.
|
CREATE TABLE journal_committee (journal_ID VARCHAR); CREATE TABLE journal (date VARCHAR, theme VARCHAR, sales VARCHAR); CREATE TABLE journal (date VARCHAR, theme VARCHAR, sales VARCHAR, journal_ID VARCHAR)
|
SELECT date, theme, sales FROM journal EXCEPT SELECT T1.date, T1.theme, T1.sales FROM journal AS T1 JOIN journal_committee AS T2 ON T1.journal_ID = T2.journal_ID
|
List the date, theme and sales of the journal which did not have any of the listed editors serving on committee.
|
CREATE TABLE journal_committee (journal_ID VARCHAR, work_type VARCHAR); CREATE TABLE journal (sales INTEGER, journal_ID VARCHAR)
|
SELECT AVG(T1.sales) FROM journal AS T1 JOIN journal_committee AS T2 ON T1.journal_ID = T2.journal_ID WHERE T2.work_type = 'Photo'
|
What is the average sales of the journals that have an editor whose work type is 'Photo'?
|
CREATE TABLE Accounts (Id VARCHAR)
|
SELECT COUNT(*) FROM Accounts
|
How many accounts do we have?
|
CREATE TABLE Accounts (account_id VARCHAR, customer_id VARCHAR, account_name VARCHAR)
|
SELECT account_id, customer_id, account_name FROM Accounts
|
Show ids, customer ids, names for all accounts.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.