question
stringlengths
25
117
context
stringlengths
30
206
answer
stringlengths
25
366
How many heads of the departments are older than 56 ?
CREATE TABLE head (age INTEGER)
SELECT COUNT(*) FROM head WHERE age > 56
List the name, born state and age of the heads of departments ordered by age.
CREATE TABLE head (name VARCHAR, born_state VARCHAR, age VARCHAR)
SELECT name, born_state, age FROM head ORDER BY age
List the creation year, name and budget of each department.
CREATE TABLE department (creation VARCHAR, name VARCHAR, budget_in_billions VARCHAR)
SELECT creation, name, budget_in_billions FROM department
What are the maximum and minimum budget of the departments?
CREATE TABLE department (budget_in_billions INTEGER)
SELECT MAX(budget_in_billions), MIN(budget_in_billions) FROM department
What is the average number of employees of the departments whose rank is between 10 and 15?
CREATE TABLE department (num_employees INTEGER, ranking INTEGER)
SELECT AVG(num_employees) FROM department WHERE ranking BETWEEN 10 AND 15
What are the names of the heads who are born outside the California state?
CREATE TABLE head (name VARCHAR, born_state VARCHAR)
SELECT name FROM head WHERE born_state <> 'California'
What are the distinct creation years of the departments managed by a secretary born in state 'Alabama'?
CREATE TABLE department (creation VARCHAR, department_id VARCHAR); CREATE TABLE management (department_id VARCHAR, head_id VARCHAR); CREATE TABLE head (head_id VARCHAR, born_state VARCHAR)
SELECT DISTINCT T1.creation FROM department AS T1 JOIN management AS T2 ON T1.department_id = T2.department_id JOIN head AS T3 ON T2.head_id = T3.head_id WHERE T3.born_state = 'Alabama'
What are the names of the states where at least 3 heads were born?
CREATE TABLE head (born_state VARCHAR)
SELECT born_state FROM head GROUP BY born_state HAVING COUNT(*) >= 3
In which year were most departments established?
CREATE TABLE department (creation VARCHAR)
SELECT creation FROM department GROUP BY creation ORDER BY COUNT(*) DESC LIMIT 1
Show the name and number of employees for the departments managed by heads whose temporary acting value is 'Yes'?
CREATE TABLE management (department_id VARCHAR, temporary_acting VARCHAR); CREATE TABLE department (name VARCHAR, num_employees VARCHAR, department_id VARCHAR)
SELECT T1.name, T1.num_employees FROM department AS T1 JOIN management AS T2 ON T1.department_id = T2.department_id WHERE T2.temporary_acting = 'Yes'
How many acting statuses are there?
CREATE TABLE management (temporary_acting VARCHAR)
SELECT COUNT(DISTINCT temporary_acting) FROM management
How many departments are led by heads who are not mentioned?
CREATE TABLE management (department_id VARCHAR); CREATE TABLE department (department_id VARCHAR)
SELECT COUNT(*) FROM department WHERE NOT department_id IN (SELECT department_id FROM management)
What are the distinct ages of the heads who are acting?
CREATE TABLE head (age VARCHAR, head_id VARCHAR); CREATE TABLE management (head_id VARCHAR, temporary_acting VARCHAR)
SELECT DISTINCT T1.age FROM management AS T2 JOIN head AS T1 ON T1.head_id = T2.head_id WHERE T2.temporary_acting = 'Yes'
List the states where both the secretary of 'Treasury' department and the secretary of 'Homeland Security' were born.
CREATE TABLE management (department_id VARCHAR, head_id VARCHAR); CREATE TABLE head (born_state VARCHAR, head_id VARCHAR); CREATE TABLE department (department_id VARCHAR, name VARCHAR)
SELECT T3.born_state FROM department AS T1 JOIN management AS T2 ON T1.department_id = T2.department_id JOIN head AS T3 ON T2.head_id = T3.head_id WHERE T1.name = 'Treasury' INTERSECT SELECT T3.born_state FROM department AS T1 JOIN management AS T2 ON T1.department_id = T2.department_id JOIN head AS T3 ON T2.head_id = T3.head_id WHERE T1.name = 'Homeland Security'
Which department has more than 1 head at a time? List the id, name and the number of heads.
CREATE TABLE management (department_id VARCHAR); CREATE TABLE department (department_id VARCHAR, name VARCHAR)
SELECT T1.department_id, T1.name, COUNT(*) FROM management AS T2 JOIN department AS T1 ON T1.department_id = T2.department_id GROUP BY T1.department_id HAVING COUNT(*) > 1
Which head's name has the substring 'Ha'? List the id and name.
CREATE TABLE head (head_id VARCHAR, name VARCHAR)
SELECT head_id, name FROM head WHERE name LIKE '%Ha%'
How many farms are there?
CREATE TABLE farm (Id VARCHAR)
SELECT COUNT(*) FROM farm
List the total number of horses on farms in ascending order.
CREATE TABLE farm (Total_Horses VARCHAR)
SELECT Total_Horses FROM farm ORDER BY Total_Horses
What are the hosts of competitions whose theme is not "Aliens"?
CREATE TABLE farm_competition (Hosts VARCHAR, Theme VARCHAR)
SELECT Hosts FROM farm_competition WHERE Theme <> 'Aliens'
What are the themes of farm competitions sorted by year in ascending order?
CREATE TABLE farm_competition (Theme VARCHAR, YEAR VARCHAR)
SELECT Theme FROM farm_competition ORDER BY YEAR
What is the average number of working horses of farms with more than 5000 total number of horses?
CREATE TABLE farm (Working_Horses INTEGER, Total_Horses INTEGER)
SELECT AVG(Working_Horses) FROM farm WHERE Total_Horses > 5000
What are the maximum and minimum number of cows across all farms.
CREATE TABLE farm (Cows INTEGER)
SELECT MAX(Cows), MIN(Cows) FROM farm
How many different statuses do cities have?
CREATE TABLE city (Status VARCHAR)
SELECT COUNT(DISTINCT Status) FROM city
List official names of cities in descending order of population.
CREATE TABLE city (Official_Name VARCHAR, Population VARCHAR)
SELECT Official_Name FROM city ORDER BY Population DESC
List the official name and status of the city with the largest population.
CREATE TABLE city (Official_Name VARCHAR, Status VARCHAR, Population VARCHAR)
SELECT Official_Name, Status FROM city ORDER BY Population DESC LIMIT 1
Show the years and the official names of the host cities of competitions.
CREATE TABLE city (Official_Name VARCHAR, City_ID VARCHAR); CREATE TABLE farm_competition (Year VARCHAR, Host_city_ID VARCHAR)
SELECT T2.Year, T1.Official_Name FROM city AS T1 JOIN farm_competition AS T2 ON T1.City_ID = T2.Host_city_ID
Show the official names of the cities that have hosted more than one competition.
CREATE TABLE farm_competition (Host_city_ID VARCHAR); CREATE TABLE city (Official_Name VARCHAR, City_ID VARCHAR)
SELECT T1.Official_Name FROM city AS T1 JOIN farm_competition AS T2 ON T1.City_ID = T2.Host_city_ID GROUP BY T2.Host_city_ID HAVING COUNT(*) > 1
Show the status of the city that has hosted the greatest number of competitions.
CREATE TABLE city (Status VARCHAR, City_ID VARCHAR); CREATE TABLE farm_competition (Host_city_ID VARCHAR)
SELECT T1.Status FROM city AS T1 JOIN farm_competition AS T2 ON T1.City_ID = T2.Host_city_ID GROUP BY T2.Host_city_ID ORDER BY COUNT(*) DESC LIMIT 1
Please show the themes of competitions with host cities having populations larger than 1000.
CREATE TABLE city (City_ID VARCHAR, Population INTEGER); CREATE TABLE farm_competition (Theme VARCHAR, Host_city_ID VARCHAR)
SELECT T2.Theme FROM city AS T1 JOIN farm_competition AS T2 ON T1.City_ID = T2.Host_city_ID WHERE T1.Population > 1000
Please show the different statuses of cities and the average population of cities with each status.
CREATE TABLE city (Status VARCHAR, Population INTEGER)
SELECT Status, AVG(Population) FROM city GROUP BY Status
Please show the different statuses, ordered by the number of cities that have each.
CREATE TABLE city (Status VARCHAR)
SELECT Status FROM city GROUP BY Status ORDER BY COUNT(*)
List the most common type of Status across cities.
CREATE TABLE city (Status VARCHAR)
SELECT Status FROM city GROUP BY Status ORDER BY COUNT(*) DESC LIMIT 1
List the official names of cities that have not held any competition.
CREATE TABLE farm_competition (Official_Name VARCHAR, City_ID VARCHAR, Host_city_ID VARCHAR); CREATE TABLE city (Official_Name VARCHAR, City_ID VARCHAR, Host_city_ID VARCHAR)
SELECT Official_Name FROM city WHERE NOT City_ID IN (SELECT Host_city_ID FROM farm_competition)
Show the status shared by cities with population bigger than 1500 and smaller than 500.
CREATE TABLE city (Status VARCHAR, Population INTEGER)
SELECT Status FROM city WHERE Population > 1500 INTERSECT SELECT Status FROM city WHERE Population < 500
Find the official names of cities with population bigger than 1500 or smaller than 500.
CREATE TABLE city (Official_Name VARCHAR, Population VARCHAR)
SELECT Official_Name FROM city WHERE Population > 1500 OR Population < 500
Show the census ranking of cities whose status are not "Village".
CREATE TABLE city (Census_Ranking VARCHAR, Status VARCHAR)
SELECT Census_Ranking FROM city WHERE Status <> "Village"
which course has most number of registered students?
CREATE TABLE courses (course_name VARCHAR, course_id VARCHAR); CREATE TABLE student_course_registrations (course_Id VARCHAR)
SELECT T1.course_name FROM courses AS T1 JOIN student_course_registrations AS T2 ON T1.course_id = T2.course_Id GROUP BY T1.course_id ORDER BY COUNT(*) DESC LIMIT 1
what is id of students who registered some courses but the least number of courses in these students?
CREATE TABLE student_course_registrations (student_id VARCHAR)
SELECT student_id FROM student_course_registrations GROUP BY student_id ORDER BY COUNT(*) LIMIT 1
what are the first name and last name of all candidates?
CREATE TABLE candidates (candidate_id VARCHAR); CREATE TABLE people (first_name VARCHAR, last_name VARCHAR, person_id VARCHAR)
SELECT T2.first_name, T2.last_name FROM candidates AS T1 JOIN people AS T2 ON T1.candidate_id = T2.person_id
List the id of students who never attends courses?
CREATE TABLE student_course_attendance (student_id VARCHAR); CREATE TABLE students (student_id VARCHAR)
SELECT student_id FROM students WHERE NOT student_id IN (SELECT student_id FROM student_course_attendance)
List the id of students who attended some courses?
CREATE TABLE student_course_attendance (student_id VARCHAR)
SELECT student_id FROM student_course_attendance
What are the ids of all students for courses and what are the names of those courses?
CREATE TABLE courses (course_name VARCHAR, course_id VARCHAR); CREATE TABLE student_course_registrations (student_id VARCHAR, course_id VARCHAR)
SELECT T1.student_id, T2.course_name FROM student_course_registrations AS T1 JOIN courses AS T2 ON T1.course_id = T2.course_id
What is detail of the student who most recently registered course?
CREATE TABLE student_course_registrations (student_id VARCHAR, registration_date VARCHAR); CREATE TABLE students (student_details VARCHAR, student_id VARCHAR)
SELECT T2.student_details FROM student_course_registrations AS T1 JOIN students AS T2 ON T1.student_id = T2.student_id ORDER BY T1.registration_date DESC LIMIT 1
How many students attend course English?
CREATE TABLE student_course_attendance (course_id VARCHAR); CREATE TABLE courses (course_id VARCHAR, course_name VARCHAR)
SELECT COUNT(*) FROM courses AS T1 JOIN student_course_attendance AS T2 ON T1.course_id = T2.course_id WHERE T1.course_name = "English"
How many courses do the student whose id is 171 attend?
CREATE TABLE courses (course_id VARCHAR); CREATE TABLE student_course_attendance (course_id VARCHAR, student_id VARCHAR)
SELECT COUNT(*) FROM courses AS T1 JOIN student_course_attendance AS T2 ON T1.course_id = T2.course_id WHERE T2.student_id = 171
Find id of the candidate whose email is [email protected]?
CREATE TABLE candidates (candidate_id VARCHAR); CREATE TABLE people (person_id VARCHAR, email_address VARCHAR)
SELECT T2.candidate_id FROM people AS T1 JOIN candidates AS T2 ON T1.person_id = T2.candidate_id WHERE T1.email_address = "[email protected]"
Find id of the candidate who most recently accessed the course?
CREATE TABLE candidate_assessments (candidate_id VARCHAR, assessment_date VARCHAR)
SELECT candidate_id FROM candidate_assessments ORDER BY assessment_date DESC LIMIT 1
What is detail of the student who registered the most number of courses?
CREATE TABLE students (student_details VARCHAR, student_id VARCHAR); CREATE TABLE student_course_registrations (student_id VARCHAR)
SELECT T1.student_details FROM students AS T1 JOIN student_course_registrations AS T2 ON T1.student_id = T2.student_id GROUP BY T1.student_id ORDER BY COUNT(*) DESC LIMIT 1
List the id of students who registered some courses and the number of their registered courses?
CREATE TABLE students (student_id VARCHAR); CREATE TABLE student_course_registrations (student_id VARCHAR)
SELECT T1.student_id, COUNT(*) FROM students AS T1 JOIN student_course_registrations AS T2 ON T1.student_id = T2.student_id GROUP BY T1.student_id
How many registed students do each course have? List course name and the number of their registered students?
CREATE TABLE students (student_id VARCHAR); CREATE TABLE courses (course_name VARCHAR, course_id VARCHAR); CREATE TABLE student_course_registrations (course_id VARCHAR, student_id VARCHAR)
SELECT T3.course_name, COUNT(*) FROM students AS T1 JOIN student_course_registrations AS T2 ON T1.student_id = T2.student_id JOIN courses AS T3 ON T2.course_id = T3.course_id GROUP BY T2.course_id
Find id of candidates whose assessment code is "Pass"?
CREATE TABLE candidate_assessments (candidate_id VARCHAR, asessment_outcome_code VARCHAR)
SELECT candidate_id FROM candidate_assessments WHERE asessment_outcome_code = "Pass"
Find the cell mobile number of the candidates whose assessment code is "Fail"?
CREATE TABLE candidates (candidate_id VARCHAR); CREATE TABLE people (cell_mobile_number VARCHAR, person_id VARCHAR); CREATE TABLE candidate_assessments (candidate_id VARCHAR, asessment_outcome_code VARCHAR)
SELECT T3.cell_mobile_number FROM candidates AS T1 JOIN candidate_assessments AS T2 ON T1.candidate_id = T2.candidate_id JOIN people AS T3 ON T1.candidate_id = T3.person_id WHERE T2.asessment_outcome_code = "Fail"
What are the id of students who registered course 301?
CREATE TABLE student_course_attendance (student_id VARCHAR, course_id VARCHAR)
SELECT student_id FROM student_course_attendance WHERE course_id = 301
What is the id of the student who most recently registered course 301?
CREATE TABLE student_course_attendance (student_id VARCHAR, course_id VARCHAR, date_of_attendance VARCHAR)
SELECT student_id FROM student_course_attendance WHERE course_id = 301 ORDER BY date_of_attendance DESC LIMIT 1
Find distinct cities of addresses of people?
CREATE TABLE addresses (city VARCHAR, address_id VARCHAR); CREATE TABLE people_addresses (address_id VARCHAR)
SELECT DISTINCT T1.city FROM addresses AS T1 JOIN people_addresses AS T2 ON T1.address_id = T2.address_id
Find distinct cities of address of students?
CREATE TABLE students (student_id VARCHAR); CREATE TABLE addresses (city VARCHAR, address_id VARCHAR); CREATE TABLE people_addresses (address_id VARCHAR, person_id VARCHAR)
SELECT DISTINCT T1.city FROM addresses AS T1 JOIN people_addresses AS T2 ON T1.address_id = T2.address_id JOIN students AS T3 ON T2.person_id = T3.student_id
List the names of courses in alphabetical order?
CREATE TABLE courses (course_name VARCHAR)
SELECT course_name FROM courses ORDER BY course_name
List the first names of people in alphabetical order?
CREATE TABLE people (first_name VARCHAR)
SELECT first_name FROM people ORDER BY first_name
What are the id of students who registered courses or attended courses?
CREATE TABLE student_course_attendance (student_id VARCHAR); CREATE TABLE student_course_registrations (student_id VARCHAR)
SELECT student_id FROM student_course_registrations UNION SELECT student_id FROM student_course_attendance
Find the id of courses which are registered or attended by student whose id is 121?
CREATE TABLE student_course_attendance (course_id VARCHAR, student_id VARCHAR); CREATE TABLE student_course_registrations (course_id VARCHAR, student_id VARCHAR)
SELECT course_id FROM student_course_registrations WHERE student_id = 121 UNION SELECT course_id FROM student_course_attendance WHERE student_id = 121

Overview

This dataset builds from WikiSQL and Spider.

There are 78,577 examples of natural language queries, SQL CREATE TABLE statements, and SQL Query answering the question using the CREATE statement as context. This dataset was built with text-to-sql LLMs in mind, intending to prevent hallucination of column and table names often seen when trained on text-to-sql datasets. The CREATE TABLE statement can often be copy and pasted from different DBMS and provides table names, column names and their data types. By providing just the CREATE TABLE statement as context, we can hopefully provide better grounding for models without having to provide actual rows of data, limiting token usage and exposure to private, sensitive, or proprietary data.

Cleansing and Augmentation

Cleansing and data augmentation has been done on the combined WikiSQL and Spider data. I used SQLGlot on queries from Spider and WikiSQL and parsed them into different tables and columns, I then inferred column data types based on usage of > < operators as well as the use of MIN() MAX() AVG() SUM() on columns. While this isn't perfect, it increases the likelihood of inferring the correct datatype for a column, the columns otherwise default to VARCHAR type. These tables and columns are then used to generate CREATE TABLE statements using the inferred types. SQLGlot is used again to ensure both the SQL queries and CREATE TABLE statements parse without errors.

Some queries that do not have column names, e.g. SELECT * FROM table, have a default Id column added to the CREATE TABLE statement. Some other queries which use the generic table as the FROM table have instead been changed to a variation of table_name_1 or some other number which is also reflected in the CREATE TABLE statement.

TODO

  • Further augment the data by converting queries and CREATE TABLE statements into different SQL dialects, this can be done with SQLGlot. Reference to the dialect might also be added to the question.
  • Support other informative contexts beyond CREATE TABLE
  • Better parse datatypes to clean up things like numbers for column names and other numbers as strings

If you have any edits you'd like to see in a version 2 of this dataset, let me know.

Random sample:

  {
    "question": "Please show the themes of competitions with host cities having populations larger than 1000.",
    "context": "CREATE TABLE city (City_ID VARCHAR, Population INTEGER); CREATE TABLE farm_competition (Theme VARCHAR, Host_city_ID VARCHAR)",
    "answer": "SELECT T2.Theme FROM city AS T1 JOIN farm_competition AS T2 ON T1.City_ID = T2.Host_city_ID WHERE T1.Population > 1000"
  },
  {
    "question": "Please show the different statuses of cities and the average population of cities with each status.",
    "context": "CREATE TABLE city (Status VARCHAR, Population INTEGER)",
    "answer": "SELECT Status, AVG(Population) FROM city GROUP BY Status"
  },

Citing this work

@misc{b-mc2_2023_sql-create-context,
  title   = {sql-create-context Dataset},
  author  = {b-mc2}, 
  year    = {2023},
  url     = {https://huggingface.co/datasets/b-mc2/sql-create-context},
  note    = {This dataset was created by modifying data from the following sources: \cite{zhongSeq2SQL2017, yu2018spider}.},
}

Datasets used to create this dataset

@article{zhongSeq2SQL2017,
  author  = {Victor Zhong and Caiming Xiong and Richard Socher},
  title   = {Seq2SQL: Generating Structured Queries from Natural Language using Reinforcement Learning},
  journal = {CoRR},
  volume  = {abs/1709.00103},
  year    = {2017}
}

@article{yu2018spider,
  title   = {Spider: A large-scale human-labeled dataset for complex and cross-domain semantic parsing and text-to-sql task},
  author  = {Yu, Tao and Zhang, Rui and Yang, Kai and Yasunaga, Michihiro and Wang, Dongxu and Li, Zifan and Ma, James and Li, Irene and Yao, Qingning and Roman, Shanelle and others},
  journal = {arXiv preprint arXiv:1809.08887},
  year    = {2018}
}
Downloads last month
19