anchor stringlengths 10 14.3k | positive stringlengths 10 14.9k |
|---|---|
Find the names of customers who never placed an order. | SELECT customer_name FROM customers EXCEPT SELECT t1.customer_name FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id = t2.customer_id |
Find the first and last name of all the students of age 18 who have vice president votes. | SELECT DISTINCT T1.Fname , T1.LName FROM STUDENT AS T1 JOIN VOTING_RECORD AS T2 ON T1.StuID = T2.VICE_President_VOTE WHERE T1.age = 18 |
What are the names of tracks that contain the the word you in them? | SELECT Name FROM TRACK WHERE Name LIKE '%you%' |
Find the name of bank branch that provided the greatest total amount of loans. | SELECT T1.bname FROM bank AS T1 JOIN loan AS T2 ON T1.branch_id = T2.branch_id GROUP BY T1.bname ORDER BY sum(T2.amount) DESC LIMIT 1 |
Show the investors shared by entrepreneurs that requested more than 140000 and entrepreneurs that requested less than 120000. | SELECT Investor FROM entrepreneur WHERE Money_Requested > 140000 INTERSECT SELECT Investor FROM entrepreneur WHERE Money_Requested < 120000 |
How many games has each stadium held? | SELECT T1.id , count(*) FROM stadium AS T1 JOIN game AS T2 ON T1.id = T2.stadium_id GROUP BY T1.id |
Show the id and name of the aircraft with the maximum distance. | SELECT aid , name FROM Aircraft ORDER BY distance DESC LIMIT 1 |
Which customer made the most orders? Find the customer name. | SELECT T1.customer_name FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY count(*) DESC LIMIT 1 |
What is the total number of airlines? | SELECT count(*) FROM airlines |
What is the address of the restaurant Subway? | SELECT Address FROM Restaurant WHERE ResName = "Subway"; |
How many institutions do not have an associated protein in our record? | SELECT count(*) FROM institution WHERE institution_id NOT IN (SELECT institution_id FROM protein) |
What is the name of tracks whose genre is Rock? | SELECT T2.name FROM genres AS T1 JOIN tracks AS T2 ON T1.id = T2.genre_id WHERE T1.name = "Rock"; |
What are the drivers' first, last names and id who had more than 8 pit stops or participated in more than 5 race results? | SELECT T1.forename , T1.surname , T1.driverid FROM drivers AS T1 JOIN pitstops AS T2 ON T1.driverid = T2.driverid GROUP BY T1.driverid HAVING count(*) > 8 UNION SELECT T1.forename , T1.surname , T1.driverid FROM drivers AS T1 JOIN results AS T2 ON T1.driverid = T2.driverid GROUP BY T1.driverid HAVING count(*)... |
What is the first and last name of the youngest student with a GPA above 3, and what is their GPA? | SELECT stu_fname , stu_lname , stu_gpa FROM student WHERE stu_gpa > 3 ORDER BY stu_dob DESC LIMIT 1 |
Which student's age is older than 18 and is majoring in 600? List each student's first and last name. | SELECT Fname , Lname FROM Student WHERE Age > 18 AND Major = 600; |
What are the forenames and surnames of drivers who participated in the races named Australian Grand Prix but not the races named Chinese Grand Prix? | SELECT T3.forename , T3.surname FROM races AS T1 JOIN results AS T2 ON T1.raceid = T2.raceid JOIN drivers AS T3 ON T2.driverid = T3.driverid WHERE T1.name = "Australian Grand Prix" EXCEPT SELECT T3.forename , T3.surname FROM races AS T1 JOIN results AS T2 ON T1.raceid = T2.raceid JOIN drivers AS T3 ON T2.driverid = T... |
list names of all departments ordered by their names. | SELECT dept_name FROM department ORDER BY dept_name |
Find the name and total checking and savings balance of the accounts whose savings balance is lower than corresponding checking balance. | SELECT T1.name , T3.balance + T2.balance FROM accounts AS T1 JOIN checking AS T2 ON T1.custid = T2.custid JOIN savings AS T3 ON T1.custid = T3.custid WHERE T3.balance < T2.balance |
Which customers have used the service named "Close a policy" or "Upgrade a policy"? Give me the customer names. | SELECT t1.customer_name FROM customers AS t1 JOIN first_notification_of_loss AS t2 ON t1.customer_id = t2.customer_id JOIN services AS t3 ON t2.service_id = t3.service_id WHERE t3.service_name = "Close a policy" OR t3.service_name = "Upgrade a policy" |
How many different users wrote some reviews? | SELECT count(DISTINCT u_id) FROM review |
How many customers don't have an account? | SELECT count(*) FROM Customers WHERE customer_id NOT IN (SELECT customer_id FROM Accounts) |
List all customer status codes and the number of customers having each status code. | SELECT customer_status_code , count(*) FROM Customers GROUP BY customer_status_code; |
List the names of representatives that have not participated in elections listed here. | SELECT Name FROM representative WHERE Representative_ID NOT IN (SELECT Representative_ID FROM election) |
Find the name of the company that has the least number of phone models. List the company name and the number of phone model produced by that company. | SELECT Company_name , count(*) FROM phone GROUP BY Company_name ORDER BY count(*) ASC LIMIT 1; |
List the order id, customer id for orders in Cancelled status, ordered by their order dates. | SELECT order_id , customer_id FROM customer_orders WHERE order_status_code = "Cancelled" ORDER BY order_date |
Find the name of the customer who made the most orders. | SELECT T1.customer_name FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY count(*) DESC LIMIT 1 |
What are the first year and last year of the parties whose theme is "Spring" or "Teqnology"? | SELECT First_year , Last_year FROM party WHERE Party_Theme = "Spring" OR Party_Theme = "Teqnology" |
Show different locations of railways along with the corresponding number of railways at each location. | SELECT LOCATION , COUNT(*) FROM railway GROUP BY LOCATION |
Show different types of ships and the average tonnage of ships of each type. | SELECT TYPE , avg(Tonnage) FROM ship GROUP BY TYPE |
How many stations are in Mountain View? | SELECT COUNT(*) FROM station WHERE city = "Mountain View" |
What is the salaray and name of the employee that is certified to fly the most planes? | SELECT T1.name , T1.salary FROM Employee AS T1 JOIN Certificate AS T2 ON T1.eid = T2.eid GROUP BY T1.eid ORDER BY count(*) DESC LIMIT 1 |
What is the id of the account with the most transactions? | SELECT account_id FROM Financial_transactions GROUP BY account_id ORDER BY count(*) DESC LIMIT 1 |
How many different departments are there? | SELECT count(DISTINCT dept_name) FROM department |
What is the total quantity of products purchased by "Rodrick Heaney"? | SELECT sum(t3.order_quantity) FROM customers AS t1 JOIN customer_orders AS t2 ON t1.customer_id = t2.customer_id JOIN order_items AS t3 ON t2.order_id = t3.order_id WHERE t1.customer_name = "Rodrick Heaney" |
Find the name of physicians who are affiliated with both Surgery and Psychiatry departments. | SELECT T1.name FROM physician AS T1 JOIN affiliated_with AS T2 ON T1.EmployeeID = T2.physician JOIN department AS T3 ON T2.department = T3.DepartmentID WHERE T3.name = 'Surgery' INTERSECT SELECT T1.name FROM physician AS T1 JOIN affiliated_with AS T2 ON T1.EmployeeID = T2.physician JOIN department AS T3 ON T2.d... |
List the names of all distinct nurses ordered by alphabetical order? | SELECT DISTINCT name FROM nurse ORDER BY name |
Find the name and savings balance of the top 3 accounts with the highest saving balance sorted by savings balance in descending order. | SELECT T1.name , T2.balance FROM accounts AS T1 JOIN savings AS T2 ON T1.custid = T2.custid ORDER BY T2.balance DESC LIMIT 3 |
What is the description of the type of the company who concluded its contracts most recently? | SELECT T1.company_name FROM Third_Party_Companies AS T1 JOIN Maintenance_Contracts AS T2 ON T1.company_id = T2.maintenance_contract_company_id JOIN Ref_Company_Types AS T3 ON T1.company_type_code = T3.company_type_code ORDER BY T2.contract_end_date DESC LIMIT 1 |
What is the order id and order details for the order more than two invoices. | 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 |
Which cities have at least one customer but no performer? | SELECT T1.City_Town FROM Addresses AS T1 JOIN Customers AS T2 ON T1.Address_ID = T2.Address_ID EXCEPT SELECT T1.City_Town FROM Addresses AS T1 JOIN Performers AS T2 ON T1.Address_ID = T2.Address_ID |
Find the total budgets of the Marketing or Finance department. | SELECT sum(budget) FROM department WHERE dept_name = 'Marketing' OR dept_name = 'Finance' |
Show the location code, the starting date and ending data in that location for all the documents. | SELECT location_code , date_in_location_from , date_in_locaton_to FROM Document_locations |
What is the total number of students enrolled in schools without any goalies? | SELECT sum(enr) FROM college WHERE cName NOT IN (SELECT cName FROM tryout WHERE pPos = "goalie") |
List the distinct payment method codes with the number of orders made | SELECT payment_method_code , count(*) FROM INVOICES GROUP BY payment_method_code |
What are the ids and first names of customers who do not hold a credit card? | SELECT customer_id , customer_first_name FROM Customers EXCEPT SELECT T1.customer_id , T2.customer_first_name FROM Customers_cards AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id WHERE card_type_code = "Credit" |
Give me the maximum low temperature and average precipitation at the Amersham station. | SELECT max(t1.low_temperature) , avg(t1.precipitation) FROM weekly_weather AS t1 JOIN station AS t2 ON t1.station_id = t2.id WHERE t2.network_name = "Amersham" |
What are the products with the maximum page size A4 that also have a pages per minute color smaller than 5? | SELECT product FROM product WHERE max_page_size = "A4" AND pages_per_minute_color < 5 |
Return the names and ids of customers who have TN in their address. | SELECT customer_name , customer_id FROM customers WHERE customer_address LIKE "%TN%" |
How many services has each resident requested? List the resident id, details, and the count in descending order of the count. | SELECT T1.resident_id , T1.other_details , count(*) FROM Residents AS T1 JOIN Residents_Services AS T2 ON T1.resident_id = T2.resident_id GROUP BY T1.resident_id ORDER BY count(*) DESC |
In which state is the college that Charles attends? | SELECT T1.state FROM college AS T1 JOIN tryout AS T2 ON T1.cName = T2.cName JOIN player AS T3 ON T2.pID = T3.pID WHERE T3.pName = 'Charles' |
Find the checking balance of the accounts whose savings balance is higher than the average savings balance. | SELECT T2.balance FROM accounts AS T1 JOIN checking AS T2 ON T1.custid = T2.custid WHERE T1.name IN (SELECT T1.name FROM accounts AS T1 JOIN savings AS T2 ON T1.custid = T2.custid WHERE T2.balance > (SELECT avg(balance) FROM savings)) |
Show the phone, room, and building for the faculty named Jerry Prince. | SELECT phone , room , building FROM Faculty WHERE Fname = "Jerry" AND Lname = "Prince" |
Return the type code of the document named "David CV". | SELECT document_type_code FROM documents WHERE document_name = "David CV" |
find the rank, company names, market values of the companies in the banking industry order by their sales and profits in billion. | SELECT rank , company , market_value FROM company WHERE main_industry = 'Banking' ORDER BY sales_billion , profits_billion |
Show the name, average attendance, total attendance for stadiums where no accidents happened. | 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 |
Please show the countries and the number of climbers from each country. | SELECT Country , COUNT(*) FROM climber GROUP BY Country |
Show the number of male and female assistant professors. | SELECT sex , count(*) FROM Faculty WHERE rank = "AsstProf" GROUP BY sex |
How many products have their color described as 'white' or have a characteristic with the name 'hot'? | SELECT count(*) FROM products AS t1 JOIN product_characteristics AS t2 ON t1.product_id = t2.product_id JOIN CHARACTERISTICS AS t3 ON t2.characteristic_id = t3.characteristic_id JOIN ref_colors AS t4 ON t1.color_code = t4.color_code WHERE t4.color_description = "white" OR t3.characteristic_name = "hot" |
What is the average number of cities of markets with low film market estimate bigger than 10000? | SELECT avg(T2.Number_cities) FROM film_market_estimation AS T1 JOIN market AS T2 ON T1.Market_ID = T2.Market_ID WHERE T1.Low_Estimate > 10000 |
Show the name for regions and the number of storms for each region. | SELECT T1.region_name , count(*) FROM region AS T1 JOIN affected_region AS T2 ON T1.region_id = T2.region_id GROUP BY T1.region_id |
List all role codes, role names, and role descriptions. | SELECT role_code , role_name , role_description FROM ROLES |
Find the names of all reviewers who have contributed three or more ratings. | SELECT T2.name FROM Rating AS T1 JOIN Reviewer AS T2 ON T1.rID = T2.rID GROUP BY T1.rID HAVING COUNT(*) >= 3 |
display the ID for those employees who did two or more jobs in the past. | SELECT employee_id FROM job_history GROUP BY employee_id HAVING COUNT(*) >= 2 |
For each party, find its location and the name of its host. Sort the result in ascending order of the age of the host. | SELECT T3.Location , T2.Name FROM party_host AS T1 JOIN HOST AS T2 ON T1.Host_ID = T2.Host_ID JOIN party AS T3 ON T1.Party_ID = T3.Party_ID ORDER BY T2.Age |
How many papers are published by the institution "Tokohu University"? | SELECT count(DISTINCT t1.title) FROM papers AS t1 JOIN authorship AS t2 ON t1.paperid = t2.paperid JOIN inst AS t3 ON t2.instid = t3.instid WHERE t3.name = "Tokohu University" |
Which address has both members younger than 30 and members older than 40? | SELECT address FROM member WHERE age < 30 INTERSECT SELECT address FROM member WHERE age > 40 |
What are the distinct name, location and products of the enzymes which has any 'inhibitor' interaction? | SELECT DISTINCT T1.name , T1.location , T1.product FROM enzyme AS T1 JOIN medicine_enzyme_interaction AS T2 ON T2.enzyme_id = T1.id WHERE T2.interaction_type = 'inhibitor' |
What is the average song duration for the songs that are in mp3 format and whose resolution below 800? | SELECT avg(T1.duration) FROM files AS T1 JOIN song AS T2 ON T1.f_id = T2.f_id WHERE T1.formats = "mp3" AND T2.resolution < 800 |
How many times in total did the team Boston Red Stockings participate in postseason games? | SELECT count(*) FROM ( SELECT * FROM postseason AS T1 JOIN team AS T2 ON T1.team_id_winner = T2.team_id_br WHERE T2.name = 'Boston Red Stockings' UNION SELECT * FROM postseason AS T1 JOIN team AS T2 ON T1.team_id_loser = T2.team_id_br WHERE T2.name = 'Boston Red Stockings' ); |
What are the names and urls of images, sorted alphabetically? | SELECT image_name , image_url FROM images ORDER BY image_name |
List the name of the pilots who have flied for both a company that mainly provide 'Cargo' services and a company that runs 'Catering services' activities. | SELECT T2.pilot FROM operate_company AS T1 JOIN flight AS t2 ON T1.id = T2.company_id WHERE T1.principal_activities = 'Cargo' INTERSECT SELECT T2.pilot FROM operate_company AS T1 JOIN flight AS t2 ON T1.id = T2.company_id WHERE T1.principal_activities = 'Catering services' |
What are the song titles on the album "A Kiss Before You Go: Live in Hamburg"? | SELECT T3.title FROM albums AS T1 JOIN tracklists AS T2 ON T1.aid = T2.albumid JOIN songs AS T3 ON T2.songid = T3.songid WHERE T1.title = "A Kiss Before You Go: Live in Hamburg" |
Find the name of the person who has no student friends. | SELECT name FROM person EXCEPT SELECT T2.name FROM Person AS T1 JOIN PersonFriend AS T2 ON T1.name = T2.friend WHERE T1.job = 'student' |
Which vocal type did the musician with first name "Solveig" played in the song with title "A Bar in Amsterdam"? | SELECT TYPE FROM vocals AS T1 JOIN songs AS T2 ON T1.songid = T2.songid JOIN band AS T3 ON T1.bandmate = T3.id WHERE T3.firstname = "Solveig" AND T2.title = "A Bar In Amsterdam" |
What is the total amount of grant money for research? | SELECT sum(grant_amount) FROM Grants AS T1 JOIN Organisations AS T2 ON T1.organisation_id = T2.organisation_id JOIN organisation_Types AS T3 ON T2.organisation_type = T3.organisation_type WHERE T3.organisation_type_description = 'Research' |
Show the prices of publications whose publisher is either "Person" or "Wiley" | SELECT Price FROM publication WHERE Publisher = "Person" OR Publisher = "Wiley" |
Show the denomination of the school that has the most players. | SELECT T2.Denomination FROM player AS T1 JOIN school AS T2 ON T1.School_ID = T2.School_ID GROUP BY T1.School_ID ORDER BY COUNT(*) DESC LIMIT 1 |
What is the description of the club "Pen and Paper Gaming"? | SELECT clubdesc FROM club WHERE clubname = "Pen and Paper Gaming" |
Find the first name of students living in city PHL whose age is between 20 and 25. | SELECT fname FROM student WHERE city_code = 'PHL' AND age BETWEEN 20 AND 25 |
What is the description of document type 'Paper'? | SELECT document_type_description FROM Ref_Document_Types WHERE document_type_code = "Paper"; |
Which bike traveled the most often in zip code 94002? | SELECT bike_id FROM trip WHERE zip_code = 94002 GROUP BY bike_id ORDER BY COUNT(*) DESC LIMIT 1 |
What are the names, color descriptions, and product descriptions for products in the 'Herbs' category? | SELECT T1.product_name , T2.color_description , T1.product_description FROM products AS T1 JOIN Ref_colors AS T2 ON T1.color_code = T2.color_code WHERE product_category_code = "Herbs" |
What is the sum of total pounds of purchase in year 2018 for all branches in London? | SELECT sum(total_pounds) FROM purchase AS T1 JOIN branch AS T2 ON T1.branch_id = T2.branch_id WHERE T2.city = 'London' AND T1.year = 2018 |
Return the hispanic percentage for cities in which the black percentage is greater than 10. | SELECT Hispanic FROM city WHERE Black > 10 |
Find the average age of all students living in the each city. | SELECT avg(age) , city_code FROM student GROUP BY city_code |
Find the country of all appelations who have at most three wines. | SELECT T1.County FROM APPELLATIONS AS T1 JOIN WINE AS T2 ON T1.Appelation = T2.Appelation GROUP BY T2.Appelation HAVING count(*) <= 3 |
What are the highest and lowest prices of products, grouped by and alphabetically ordered by product type? | SELECT max(product_price) , min(product_price) , product_type_code FROM products GROUP BY product_type_code ORDER BY product_type_code |
Sort all the industries in descending order of the count of companies in each industry | SELECT Industry FROM Companies GROUP BY Industry ORDER BY COUNT(*) DESC |
What are the order ids and customer ids for orders that have been Cancelled, sorted by their order dates? | SELECT order_id , customer_id FROM customer_orders WHERE order_status_code = "Cancelled" ORDER BY order_date |
Return the descriptions and names of the courses that have more than two students enrolled in. | SELECT T1.course_description , T1.course_name FROM Courses AS T1 JOIN Student_Course_Enrolment AS T2 ON T1.course_id = T2.course_id GROUP BY T1.course_name HAVING COUNT(*) > 2 |
How many members are not living in Hartford? | SELECT count(*) FROM member WHERE address != 'Hartford' |
Give me a list of id and status of orders which belong to the customer named "Jeramie". | SELECT T2.order_id , T2.order_status FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T1.customer_name = "Jeramie" |
How many problems does the product with the most problems have? List the number of the problems and product name. | SELECT count(*) , T1.product_name FROM product AS T1 JOIN problems AS T2 ON T1.product_id = T2.product_id GROUP BY T1.product_name ORDER BY count(*) DESC LIMIT 1 |
List the forenames of all distinct drivers in alphabetical order? | SELECT DISTINCT forename FROM drivers ORDER BY forename ASC |
What is the code of the school where the accounting department belongs to? | SELECT school_code FROM department WHERE dept_name = "Accounting" |
Return the number of accounts that the customer with the first name Art and last name Turcotte has. | SELECT count(*) FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id WHERE T2.customer_first_name = "Art" AND T2.customer_last_name = "Turcotte" |
What are the ids and details for each project? | SELECT project_id , project_details FROM Projects |
What are the names of body builders whose total score is higher than 300? | SELECT T2.Name FROM body_builder AS T1 JOIN people AS T2 ON T1.People_ID = T2.People_ID WHERE T1.Total > 300 |
List the full name (first and last name), and salary for those employees who earn below 6000. | SELECT first_name , last_name , salary FROM employees WHERE salary < 6000 |
What is the id of the reviewer whose name includes the word "Mike"? | SELECT rID FROM Reviewer WHERE name LIKE "%Mike%" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.