spider_version
int64
1
2
db_id
stringclasses
204 values
schema
stringclasses
187 values
question
stringlengths
3
328
query
stringlengths
20
3.81k
1
school_bus
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") )
Show the home city with the most number of drivers.
SELECT home_city FROM driver GROUP BY home_city ORDER BY count(*) DESC LIMIT 1
1
school_bus
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") )
Show the party with drivers from Hartford and drivers older than 40.
SELECT party FROM driver WHERE home_city = 'Hartford' AND age > 40
1
school_bus
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") )
Show home city where at least two drivers older than 40 are from.
SELECT home_city FROM driver WHERE age > 40 GROUP BY home_city HAVING count(*) >= 2
1
school_bus
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") )
Show all home cities except for those having a driver older than 40.
SELECT home_city FROM driver EXCEPT SELECT home_city FROM driver WHERE age > 40
1
school_bus
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") )
Show the names of the drivers without a school bus.
SELECT name FROM driver WHERE driver_id NOT IN (SELECT driver_id FROM school_bus)
1
school_bus
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") )
Show the types of schools that have two schools.
SELECT TYPE FROM school GROUP BY TYPE HAVING count(*) = 2
1
school_bus
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") )
Show the school name and driver name for all school buses.
SELECT T2.school , T3.name FROM school_bus AS T1 JOIN school AS T2 ON T1.school_id = T2.school_id JOIN driver AS T3 ON T1.driver_id = T3.driver_id
1
school_bus
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") )
What is the maximum, minimum and average years spent working on a school bus?
SELECT max(years_working) , min(years_working) , avg(years_working) FROM school_bus
1
school_bus
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") )
Show the school name and type for schools without a school bus.
SELECT school , TYPE FROM school WHERE school_id NOT IN (SELECT school_id FROM school_bus)
1
school_bus
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") )
Show the type of school and the number of buses for each type.
SELECT T2.type , count(*) FROM school_bus AS T1 JOIN school AS T2 ON T1.school_id = T2.school_id GROUP BY T2.type
1
school_bus
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") )
How many drivers are from Hartford city or younger than 40?
SELECT count(*) FROM driver WHERE home_city = 'Hartford' OR age < 40
1
school_bus
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") )
List names for drivers from Hartford city and younger than 40.
SELECT name FROM driver WHERE home_city = 'Hartford' AND age < 40
1
school_bus
CREATE TABLE "driver" ( "Driver_ID" int, "Name" text, "Party" text, "Home_city" text, "Age" int, PRIMARY KEY ("Driver_ID") ); CREATE TABLE "school" ( "School_ID" int, "Grade" text, "School" text, "Location" text, "Type" text, PRIMARY KEY ("School_ID") ); CREATE TABLE "school_bus" ( "School_ID" int, "Driver_ID" int, "Years_Working" int, "If_full_time" bool, PRIMARY KEY ("School_ID","Driver_ID"), FOREIGN KEY ("School_ID") REFERENCES `school`("School_ID"), FOREIGN KEY ("Driver_ID") REFERENCES `driver`("Driver_ID") )
find the name of driver who is driving the school bus with the longest working history.
SELECT t1.name FROM driver AS t1 JOIN school_bus AS t2 ON t1.driver_id = t2.driver_id ORDER BY years_working DESC LIMIT 1
1
flight_company
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, PRIMARY KEY("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, PRIMARY KEY ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, PRIMARY KEY ("id"), FOREIGN KEY ("airport_id") REFERENCES `airport`("id"), FOREIGN KEY ("company_id") REFERENCES `operate_company`("id") )
How many flights have a velocity larger than 200?
SELECT count(*) FROM flight WHERE velocity > 200
1
flight_company
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, PRIMARY KEY("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, PRIMARY KEY ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, PRIMARY KEY ("id"), FOREIGN KEY ("airport_id") REFERENCES `airport`("id"), FOREIGN KEY ("company_id") REFERENCES `operate_company`("id") )
List the vehicle flight number, date and pilot of all the flights, ordered by altitude.
SELECT vehicle_flight_number , date , pilot FROM flight ORDER BY altitude ASC
1
flight_company
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, PRIMARY KEY("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, PRIMARY KEY ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, PRIMARY KEY ("id"), FOREIGN KEY ("airport_id") REFERENCES `airport`("id"), FOREIGN KEY ("company_id") REFERENCES `operate_company`("id") )
List the id, country, city and name of the airports ordered alphabetically by the name.
SELECT id , country , city , name FROM airport ORDER BY name
1
flight_company
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, PRIMARY KEY("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, PRIMARY KEY ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, PRIMARY KEY ("id"), FOREIGN KEY ("airport_id") REFERENCES `airport`("id"), FOREIGN KEY ("company_id") REFERENCES `operate_company`("id") )
What is maximum group equity shareholding of the companies?
SELECT max(group_equity_shareholding) FROM operate_company
1
flight_company
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, PRIMARY KEY("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, PRIMARY KEY ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, PRIMARY KEY ("id"), FOREIGN KEY ("airport_id") REFERENCES `airport`("id"), FOREIGN KEY ("company_id") REFERENCES `operate_company`("id") )
What is the velocity of the pilot named 'Thompson'?
SELECT avg(velocity) FROM flight WHERE pilot = 'Thompson'
1
flight_company
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, PRIMARY KEY("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, PRIMARY KEY ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, PRIMARY KEY ("id"), FOREIGN KEY ("airport_id") REFERENCES `airport`("id"), FOREIGN KEY ("company_id") REFERENCES `operate_company`("id") )
What are the names and types of the companies that have ever operated a flight?
SELECT T1.name , T1.type FROM operate_company AS T1 JOIN flight AS t2 ON T1.id = T2.company_id
1
flight_company
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, PRIMARY KEY("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, PRIMARY KEY ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, PRIMARY KEY ("id"), FOREIGN KEY ("airport_id") REFERENCES `airport`("id"), FOREIGN KEY ("company_id") REFERENCES `operate_company`("id") )
What are the names of the airports which are not in the country 'Iceland'?
SELECT name FROM airport WHERE country != 'Iceland'
1
flight_company
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, PRIMARY KEY("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, PRIMARY KEY ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, PRIMARY KEY ("id"), FOREIGN KEY ("airport_id") REFERENCES `airport`("id"), FOREIGN KEY ("company_id") REFERENCES `operate_company`("id") )
What are the distinct types of the companies that have operated any flights with velocity less than 200?
SELECT DISTINCT T1.type FROM operate_company AS T1 JOIN flight AS t2 ON T1.id = T2.company_id WHERE T2.velocity < 200
1
flight_company
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, PRIMARY KEY("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, PRIMARY KEY ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, PRIMARY KEY ("id"), FOREIGN KEY ("airport_id") REFERENCES `airport`("id"), FOREIGN KEY ("company_id") REFERENCES `operate_company`("id") )
What are the ids and names of the companies that operated more than one flight?
SELECT T1.id , T1.name FROM operate_company AS T1 JOIN flight AS t2 ON T1.id = T2.company_id GROUP BY T1.id HAVING count(*) > 1
1
flight_company
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, PRIMARY KEY("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, PRIMARY KEY ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, PRIMARY KEY ("id"), FOREIGN KEY ("airport_id") REFERENCES `airport`("id"), FOREIGN KEY ("company_id") REFERENCES `operate_company`("id") )
What is the id, name and IATA code of the airport that had most number of flights?
SELECT T1.id , T1.name , T1.IATA FROM airport AS T1 JOIN flight AS T2 ON T1.id = T2.airport_id GROUP BY T2.id ORDER BY count(*) DESC LIMIT 1
1
flight_company
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, PRIMARY KEY("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, PRIMARY KEY ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, PRIMARY KEY ("id"), FOREIGN KEY ("airport_id") REFERENCES `airport`("id"), FOREIGN KEY ("company_id") REFERENCES `operate_company`("id") )
What are the different pilot names who had piloted a flight in the country 'United States' or in the airport named 'Billund Airport'?
SELECT DISTINCT T2.pilot FROM airport AS T1 JOIN flight AS T2 ON T1.id = T2.airport_id WHERE T1.country = 'United States' OR T1.name = 'Billund Airport'
1
flight_company
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, PRIMARY KEY("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, PRIMARY KEY ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, PRIMARY KEY ("id"), FOREIGN KEY ("airport_id") REFERENCES `airport`("id"), FOREIGN KEY ("company_id") REFERENCES `operate_company`("id") )
What is the most common company type, and how many are there?
SELECT TYPE , count(*) FROM operate_company GROUP BY TYPE ORDER BY count(*) DESC LIMIT 1
1
flight_company
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, PRIMARY KEY("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, PRIMARY KEY ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, PRIMARY KEY ("id"), FOREIGN KEY ("airport_id") REFERENCES `airport`("id"), FOREIGN KEY ("company_id") REFERENCES `operate_company`("id") )
How many airports haven't the pilot 'Thompson' driven an aircraft?
SELECT count(*) FROM airport WHERE id NOT IN ( SELECT airport_id FROM flight WHERE pilot = 'Thompson' );
1
flight_company
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, PRIMARY KEY("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, PRIMARY KEY ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, PRIMARY KEY ("id"), FOREIGN KEY ("airport_id") REFERENCES `airport`("id"), FOREIGN KEY ("company_id") REFERENCES `operate_company`("id") )
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'
1
flight_company
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, PRIMARY KEY("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, PRIMARY KEY ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, PRIMARY KEY ("id"), FOREIGN KEY ("airport_id") REFERENCES `airport`("id"), FOREIGN KEY ("company_id") REFERENCES `operate_company`("id") )
Which of the airport names contains the word 'international'?
SELECT name FROM airport WHERE name LIKE '%international%'
1
flight_company
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, PRIMARY KEY("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, PRIMARY KEY ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, PRIMARY KEY ("id"), FOREIGN KEY ("airport_id") REFERENCES `airport`("id"), FOREIGN KEY ("company_id") REFERENCES `operate_company`("id") )
How many companies operates airlines in each airport?
SELECT T3.id , count(*) FROM operate_company AS T1 JOIN flight AS t2 ON T1.id = T2.company_id JOIN airport AS T3 ON T2.airport_id = T3.id GROUP BY T3.id
1
flight_company
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, PRIMARY KEY("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, PRIMARY KEY ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, PRIMARY KEY ("id"), FOREIGN KEY ("airport_id") REFERENCES `airport`("id"), FOREIGN KEY ("company_id") REFERENCES `operate_company`("id") )
how many airports are there in each country?
SELECT count(*) , country FROM airport GROUP BY country
1
flight_company
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, PRIMARY KEY("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, PRIMARY KEY ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, PRIMARY KEY ("id"), FOREIGN KEY ("airport_id") REFERENCES `airport`("id"), FOREIGN KEY ("company_id") REFERENCES `operate_company`("id") )
which countries have more than 2 airports?
SELECT country FROM airport GROUP BY country HAVING count(*) > 2
1
flight_company
CREATE TABLE "airport" ( "id" int, "City" text, "Country" text, "IATA" text, "ICAO" text, "name" text, PRIMARY KEY("id") ); CREATE TABLE "operate_company" ( "id" int, "name" text, "Type" text, "Principal_activities" text, "Incorporated_in" text, "Group_Equity_Shareholding" real, PRIMARY KEY ("id") ); CREATE TABLE "flight" ( "id" int, "Vehicle_Flight_number" text, "Date" text, "Pilot" text, "Velocity" real, "Altitude" real, "airport_id" int, "company_id" int, PRIMARY KEY ("id"), FOREIGN KEY ("airport_id") REFERENCES `airport`("id"), FOREIGN KEY ("company_id") REFERENCES `operate_company`("id") )
which pilot is in charge of the most number of flights?
SELECT pilot FROM flight GROUP BY pilot ORDER BY count(*) DESC LIMIT 1
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
How many accounts do we have?
SELECT count(*) FROM Accounts
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Count the number of accounts.
SELECT count(*) FROM Accounts
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Show all account ids and account details.
SELECT account_id , account_details FROM Accounts
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
What are the ids and details of all accounts?
SELECT account_id , account_details FROM Accounts
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
How many statements do we have?
SELECT count(*) FROM Statements
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Count the number of statements.
SELECT count(*) FROM Statements
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
List all statement ids and statement details.
SELECT STATEMENT_ID , statement_details FROM Statements
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
What are the ids and details of all statements?
SELECT STATEMENT_ID , statement_details FROM Statements
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Show statement id, statement detail, account detail for accounts.
SELECT T1.statement_id , T2.statement_details , T1.account_details FROM Accounts AS T1 JOIN Statements AS T2 ON T1.statement_id = T2.statement_id
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
What are the statement ids, statement details, and account details, for all accounts?
SELECT T1.statement_id , T2.statement_details , T1.account_details FROM Accounts AS T1 JOIN Statements AS T2 ON T1.statement_id = T2.statement_id
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Show all statement id and the number of accounts for each statement.
SELECT STATEMENT_ID , count(*) FROM Accounts GROUP BY STATEMENT_ID
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
What are the different statement ids on accounts, and the number of accounts for each?
SELECT STATEMENT_ID , count(*) FROM Accounts GROUP BY STATEMENT_ID
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Show the statement id and the statement detail for the statement with most number of accounts.
SELECT T1.statement_id , T2.statement_details FROM Accounts AS T1 JOIN Statements AS T2 ON T1.statement_id = T2.statement_id GROUP BY T1.statement_id ORDER BY count(*) DESC LIMIT 1
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
What are the statement id and statement detail for the statement that has the most corresponding accounts?
SELECT T1.statement_id , T2.statement_details FROM Accounts AS T1 JOIN Statements AS T2 ON T1.statement_id = T2.statement_id GROUP BY T1.statement_id ORDER BY count(*) DESC LIMIT 1
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Show the number of documents.
SELECT count(*) FROM Documents
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Count the number of documents.
SELECT count(*) FROM Documents
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
List the document type code, document name, and document description for the document with name 'Noel CV' or name 'King Book'.
SELECT document_type_code , document_name , document_description FROM Documents WHERE document_name = 'Noel CV' OR document_name = 'King Book'
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
What are the type come, name, and description of the document that has either the name 'Noel CV' or 'King Book'?
SELECT document_type_code , document_name , document_description FROM Documents WHERE document_name = 'Noel CV' OR document_name = 'King Book'
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Show the ids and names of all documents.
SELECT document_id , document_name FROM Documents
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
What are the ids and names for each of the documents?
SELECT document_id , document_name FROM Documents
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Find names and ids of all documents with document type code BK.
SELECT document_name , document_id FROM Documents WHERE document_type_code = "BK"
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
What are the names and ids of documents that have the type code BK?
SELECT document_name , document_id FROM Documents WHERE document_type_code = "BK"
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
How many documents are with document type code BK for each product id?
SELECT count(*) , project_id FROM Documents WHERE document_type_code = "BK" GROUP BY project_id
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Count the number of documents with the type code BK that correspond to each product id.
SELECT count(*) , project_id FROM Documents WHERE document_type_code = "BK" GROUP BY project_id
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Show the document name and the document date for all documents on project with details 'Graph Database project'.
SELECT document_name , document_date FROM Documents AS T1 JOIN projects AS T2 ON T1.project_id = T2.project_id WHERE T2.project_details = 'Graph Database project'
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
What are the names and dates for documents corresponding to project that has the details 'Graph Database project'?
SELECT document_name , document_date FROM Documents AS T1 JOIN projects AS T2 ON T1.project_id = T2.project_id WHERE T2.project_details = 'Graph Database project'
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Show project ids and the number of documents in each project.
SELECT project_id , count(*) FROM Documents GROUP BY project_id
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
How many documents correspond with each project id?
SELECT project_id , count(*) FROM Documents GROUP BY project_id
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
What is the id of the project with least number of documents?
SELECT project_id FROM Documents GROUP BY project_id ORDER BY count(*) ASC LIMIT 1
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Return the id of the project that has the fewest corresponding documents.
SELECT project_id FROM Documents GROUP BY project_id ORDER BY count(*) ASC LIMIT 1
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Show the ids for projects with at least 2 documents.
SELECT project_id FROM Documents GROUP BY project_id HAVING count(*) >= 2
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
What are project ids of projects that have 2 or more corresponding documents?
SELECT project_id FROM Documents GROUP BY project_id HAVING count(*) >= 2
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
List document type codes and the number of documents in each code.
SELECT document_type_code , count(*) FROM Documents GROUP BY document_type_code
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
How many documents are there of each type?
SELECT document_type_code , count(*) FROM Documents GROUP BY document_type_code
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
What is the document type code with most number of documents?
SELECT document_type_code FROM Documents GROUP BY document_type_code ORDER BY count(*) DESC LIMIT 1
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Return the code of the document type that is most common.
SELECT document_type_code FROM Documents GROUP BY document_type_code ORDER BY count(*) DESC LIMIT 1
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Show the document type code with fewer than 3 documents.
SELECT document_type_code FROM Documents GROUP BY document_type_code HAVING count(*) < 3
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
What are the codes corresponding to document types for which there are less than 3 documents?
SELECT document_type_code FROM Documents GROUP BY document_type_code HAVING count(*) < 3
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Show the statement detail and the corresponding document name for the statement with detail 'Private Project'.
SELECT T1.statement_details , T2.document_name FROM Statements AS T1 JOIN Documents AS T2 ON T1.statement_id = T2.document_id WHERE T1.statement_details = 'Private Project'
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
What are the details for statements with the details 'Private Project', and what are the names of the corresponding documents?
SELECT T1.statement_details , T2.document_name FROM Statements AS T1 JOIN Documents AS T2 ON T1.statement_id = T2.document_id WHERE T1.statement_details = 'Private Project'
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Show all document type codes, document type names, document type descriptions.
SELECT document_type_code , document_type_name , document_type_description FROM Ref_document_types
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
What are the codes, names, and descriptions of the different document types?
SELECT document_type_code , document_type_name , document_type_description FROM Ref_document_types
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
What is the document type description for document type named Film?
SELECT document_type_description FROM Ref_document_types WHERE document_type_name = "Film"
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Return the description of the document type name 'Film'.
SELECT document_type_description FROM Ref_document_types WHERE document_type_name = "Film"
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
What is the document type name and the document type description and creation date for all the documents?
SELECT T1.document_type_name , T1.document_type_description , T2.Document_date FROM Ref_document_types AS T1 JOIN Documents AS T2 ON T1.document_type_code = T2.document_type_code
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Return the type name, type description, and date of creation for each document.
SELECT T1.document_type_name , T1.document_type_description , T2.Document_date FROM Ref_document_types AS T1 JOIN Documents AS T2 ON T1.document_type_code = T2.document_type_code
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Show the number of projects.
SELECT count(*) FROM Projects
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
How many projects are there?
SELECT count(*) FROM Projects
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
List ids and details for all projects.
SELECT project_id , project_details FROM Projects
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
What are the ids and details for each project?
SELECT project_id , project_details FROM Projects
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
What is the project id and detail for the project with at least two documents?
SELECT T1.project_id , T1.project_details FROM Projects AS T1 JOIN Documents AS T2 ON T1.project_id = T2.project_id GROUP BY T1.project_id HAVING count(*) > 2
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Return the ids and details corresponding to projects for which there are more than two documents.
SELECT T1.project_id , T1.project_details FROM Projects AS T1 JOIN Documents AS T2 ON T1.project_id = T2.project_id GROUP BY T1.project_id HAVING count(*) > 2
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
What is the project detail for the project with document "King Book"?
SELECT T1.project_details FROM Projects AS T1 JOIN Documents AS T2 ON T1.project_id = T2.project_id WHERE T2.document_name = "King Book"
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Give the details of the project with the document name 'King Book'.
SELECT T1.project_details FROM Projects AS T1 JOIN Documents AS T2 ON T1.project_id = T2.project_id WHERE T2.document_name = "King Book"
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
How many budget types do we have?
SELECT count(*) FROM Ref_budget_codes
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Count the number of budget codes.
SELECT count(*) FROM Ref_budget_codes
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
List all budget type codes and descriptions.
SELECT budget_type_code , budget_type_description FROM Ref_budget_codes
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
What are the type codes and descriptions of each budget type?
SELECT budget_type_code , budget_type_description FROM Ref_budget_codes
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
What is the description for the budget type with code ORG?
SELECT budget_type_description FROM Ref_budget_codes WHERE budget_type_code = "ORG"
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Return the description of the budget type that has the code ORG.
SELECT budget_type_description FROM Ref_budget_codes WHERE budget_type_code = "ORG"
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
How many documents have expenses?
SELECT count(*) FROM Documents_with_expenses
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Count the number of documents with expenses.
SELECT count(*) FROM Documents_with_expenses
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
What are the document ids for the budget type code 'SF'?
SELECT document_id FROM Documents_with_expenses WHERE budget_type_code = 'SF'
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Give the ids of documents with expenses that have the budget code 'SF'.
SELECT document_id FROM Documents_with_expenses WHERE budget_type_code = 'SF'
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Show the budget type code and description and the corresponding document id.
SELECT T2.budget_type_code , T2.budget_type_description , T1.document_id FROM Documents_with_expenses AS T1 JOIN Ref_budget_codes AS T2 ON T1.budget_type_code = T2.budget_type_code
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Return the budget type codes, budget type descriptions and document ids for documents with expenses.
SELECT T2.budget_type_code , T2.budget_type_description , T1.document_id FROM Documents_with_expenses AS T1 JOIN Ref_budget_codes AS T2 ON T1.budget_type_code = T2.budget_type_code
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Show ids for all documents with budget types described as 'Government'.
SELECT T1.document_id FROM Documents_with_expenses AS T1 JOIN Ref_Budget_Codes AS T2 ON T1.Budget_Type_code = T2.Budget_Type_code WHERE T2.budget_type_Description = "Government"
1
cre_Docs_and_Epenses
CREATE TABLE Ref_Document_Types ( Document_Type_Code CHAR(15) NOT NULL, Document_Type_Name VARCHAR(255) NOT NULL, Document_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Document_Type_Code) ); CREATE TABLE Ref_Budget_Codes ( Budget_Type_Code CHAR(15) NOT NULL, Budget_Type_Description VARCHAR(255) NOT NULL, PRIMARY KEY (Budget_Type_Code) ); CREATE TABLE Projects ( Project_ID INTEGER NOT NULL, Project_Details VARCHAR(255), PRIMARY KEY (Project_ID) ); CREATE TABLE Documents ( Document_ID INTEGER NOT NULL, Document_Type_Code CHAR(15) NOT NULL, Project_ID INTEGER NOT NULL, Document_Date DATETIME, Document_Name VARCHAR(255), Document_Description VARCHAR(255), Other_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Document_Type_Code) REFERENCES Ref_Document_Types (Document_Type_Code), FOREIGN KEY (Project_ID) REFERENCES Projects (Project_ID) ); CREATE TABLE Statements ( STATEMENT_ID INTEGER NOT NULL, Statement_Details VARCHAR(255), PRIMARY KEY (STATEMENT_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Documents_with_Expenses ( Document_ID INTEGER NOT NULL, Budget_Type_Code CHAR(15) NOT NULL, Document_Details VARCHAR(255), PRIMARY KEY (Document_ID), FOREIGN KEY (Budget_Type_Code) REFERENCES Ref_Budget_Codes (Budget_Type_Code), FOREIGN KEY (Document_ID) REFERENCES Documents (Document_ID) ); CREATE TABLE Accounts ( Account_ID INTEGER NOT NULL, STATEMENT_ID INTEGER NOT NULL, Account_Details VARCHAR(255), PRIMARY KEY (Account_ID), FOREIGN KEY (STATEMENT_ID) REFERENCES Statements (STATEMENT_ID) )
Give the ids for documents that have the budget description 'Government'.
SELECT T1.document_id FROM Documents_with_expenses AS T1 JOIN Ref_Budget_Codes AS T2 ON T1.Budget_Type_code = T2.Budget_Type_code WHERE T2.budget_type_Description = "Government"