spider_version
int64
1
2
db_id
stringclasses
204 values
schema
stringclasses
187 values
question
stringlengths
3
328
query
stringlengths
20
3.81k
1
pilot_record
CREATE TABLE "aircraft" ( "Aircraft_ID" int, "Order_Year" int, "Manufacturer" text, "Model" text, "Fleet_Series" text, "Powertrain" text, "Fuel_Propulsion" text, PRIMARY KEY ("Aircraft_ID") ); CREATE TABLE "pilot" ( "Pilot_ID" int, "Pilot_name" text, "Rank" int, "Age" int, "Nationality" text, "Position" text, "Join_Year" int, "Team" text, PRIMARY KEY ("Pilot_ID") ); CREATE TABLE "pilot_record" ( "Record_ID" int, "Pilot_ID" int, "Aircraft_ID" int, "Date" text, PRIMARY KEY ("Pilot_ID", "Aircraft_ID", "Date"), FOREIGN KEY (`Pilot_ID`) REFERENCES `pilot`(`Pilot_ID`), FOREIGN KEY (`Aircraft_ID`) REFERENCES `aircraft`(`Aircraft_ID`) )
Show the pilot positions that have both pilots joining after year 2005 and pilots joining before 2000.
SELECT POSITION FROM pilot WHERE Join_Year < 2000 INTERSECT SELECT POSITION FROM pilot WHERE Join_Year > 2005
1
pilot_record
CREATE TABLE "aircraft" ( "Aircraft_ID" int, "Order_Year" int, "Manufacturer" text, "Model" text, "Fleet_Series" text, "Powertrain" text, "Fuel_Propulsion" text, PRIMARY KEY ("Aircraft_ID") ); CREATE TABLE "pilot" ( "Pilot_ID" int, "Pilot_name" text, "Rank" int, "Age" int, "Nationality" text, "Position" text, "Join_Year" int, "Team" text, PRIMARY KEY ("Pilot_ID") ); CREATE TABLE "pilot_record" ( "Record_ID" int, "Pilot_ID" int, "Aircraft_ID" int, "Date" text, PRIMARY KEY ("Pilot_ID", "Aircraft_ID", "Date"), FOREIGN KEY (`Pilot_ID`) REFERENCES `pilot`(`Pilot_ID`), FOREIGN KEY (`Aircraft_ID`) REFERENCES `aircraft`(`Aircraft_ID`) )
Show the names of pilots and models of aircrafts they have flied with.
SELECT T3.Pilot_name , T2.Model FROM pilot_record AS T1 JOIN aircraft AS T2 ON T1.Aircraft_ID = T2.Aircraft_ID JOIN pilot AS T3 ON T1.Pilot_ID = T3.Pilot_ID
1
pilot_record
CREATE TABLE "aircraft" ( "Aircraft_ID" int, "Order_Year" int, "Manufacturer" text, "Model" text, "Fleet_Series" text, "Powertrain" text, "Fuel_Propulsion" text, PRIMARY KEY ("Aircraft_ID") ); CREATE TABLE "pilot" ( "Pilot_ID" int, "Pilot_name" text, "Rank" int, "Age" int, "Nationality" text, "Position" text, "Join_Year" int, "Team" text, PRIMARY KEY ("Pilot_ID") ); CREATE TABLE "pilot_record" ( "Record_ID" int, "Pilot_ID" int, "Aircraft_ID" int, "Date" text, PRIMARY KEY ("Pilot_ID", "Aircraft_ID", "Date"), FOREIGN KEY (`Pilot_ID`) REFERENCES `pilot`(`Pilot_ID`), FOREIGN KEY (`Aircraft_ID`) REFERENCES `aircraft`(`Aircraft_ID`) )
Show the names of pilots and fleet series of the aircrafts they have flied with in ascending order of the rank of the pilot.
SELECT T3.Pilot_name , T2.Fleet_Series FROM pilot_record AS T1 JOIN aircraft AS T2 ON T1.Aircraft_ID = T2.Aircraft_ID JOIN pilot AS T3 ON T1.Pilot_ID = T3.Pilot_ID ORDER BY T3.Rank
1
pilot_record
CREATE TABLE "aircraft" ( "Aircraft_ID" int, "Order_Year" int, "Manufacturer" text, "Model" text, "Fleet_Series" text, "Powertrain" text, "Fuel_Propulsion" text, PRIMARY KEY ("Aircraft_ID") ); CREATE TABLE "pilot" ( "Pilot_ID" int, "Pilot_name" text, "Rank" int, "Age" int, "Nationality" text, "Position" text, "Join_Year" int, "Team" text, PRIMARY KEY ("Pilot_ID") ); CREATE TABLE "pilot_record" ( "Record_ID" int, "Pilot_ID" int, "Aircraft_ID" int, "Date" text, PRIMARY KEY ("Pilot_ID", "Aircraft_ID", "Date"), FOREIGN KEY (`Pilot_ID`) REFERENCES `pilot`(`Pilot_ID`), FOREIGN KEY (`Aircraft_ID`) REFERENCES `aircraft`(`Aircraft_ID`) )
Show the fleet series of the aircrafts flied by pilots younger than 34
SELECT T2.Fleet_Series FROM pilot_record AS T1 JOIN aircraft AS T2 ON T1.Aircraft_ID = T2.Aircraft_ID JOIN pilot AS T3 ON T1.Pilot_ID = T3.Pilot_ID WHERE T3.Age < 34
1
pilot_record
CREATE TABLE "aircraft" ( "Aircraft_ID" int, "Order_Year" int, "Manufacturer" text, "Model" text, "Fleet_Series" text, "Powertrain" text, "Fuel_Propulsion" text, PRIMARY KEY ("Aircraft_ID") ); CREATE TABLE "pilot" ( "Pilot_ID" int, "Pilot_name" text, "Rank" int, "Age" int, "Nationality" text, "Position" text, "Join_Year" int, "Team" text, PRIMARY KEY ("Pilot_ID") ); CREATE TABLE "pilot_record" ( "Record_ID" int, "Pilot_ID" int, "Aircraft_ID" int, "Date" text, PRIMARY KEY ("Pilot_ID", "Aircraft_ID", "Date"), FOREIGN KEY (`Pilot_ID`) REFERENCES `pilot`(`Pilot_ID`), FOREIGN KEY (`Aircraft_ID`) REFERENCES `aircraft`(`Aircraft_ID`) )
Show the names of pilots and the number of records they have.
SELECT T2.Pilot_name , COUNT(*) FROM pilot_record AS T1 JOIN pilot AS T2 ON T1.pilot_ID = T2.pilot_ID GROUP BY T2.Pilot_name
1
pilot_record
CREATE TABLE "aircraft" ( "Aircraft_ID" int, "Order_Year" int, "Manufacturer" text, "Model" text, "Fleet_Series" text, "Powertrain" text, "Fuel_Propulsion" text, PRIMARY KEY ("Aircraft_ID") ); CREATE TABLE "pilot" ( "Pilot_ID" int, "Pilot_name" text, "Rank" int, "Age" int, "Nationality" text, "Position" text, "Join_Year" int, "Team" text, PRIMARY KEY ("Pilot_ID") ); CREATE TABLE "pilot_record" ( "Record_ID" int, "Pilot_ID" int, "Aircraft_ID" int, "Date" text, PRIMARY KEY ("Pilot_ID", "Aircraft_ID", "Date"), FOREIGN KEY (`Pilot_ID`) REFERENCES `pilot`(`Pilot_ID`), FOREIGN KEY (`Aircraft_ID`) REFERENCES `aircraft`(`Aircraft_ID`) )
Show names of pilots that have more than one record.
SELECT T2.Pilot_name , COUNT(*) FROM pilot_record AS T1 JOIN pilot AS T2 ON T1.pilot_ID = T2.pilot_ID GROUP BY T2.Pilot_name HAVING COUNT(*) > 1
1
pilot_record
CREATE TABLE "aircraft" ( "Aircraft_ID" int, "Order_Year" int, "Manufacturer" text, "Model" text, "Fleet_Series" text, "Powertrain" text, "Fuel_Propulsion" text, PRIMARY KEY ("Aircraft_ID") ); CREATE TABLE "pilot" ( "Pilot_ID" int, "Pilot_name" text, "Rank" int, "Age" int, "Nationality" text, "Position" text, "Join_Year" int, "Team" text, PRIMARY KEY ("Pilot_ID") ); CREATE TABLE "pilot_record" ( "Record_ID" int, "Pilot_ID" int, "Aircraft_ID" int, "Date" text, PRIMARY KEY ("Pilot_ID", "Aircraft_ID", "Date"), FOREIGN KEY (`Pilot_ID`) REFERENCES `pilot`(`Pilot_ID`), FOREIGN KEY (`Aircraft_ID`) REFERENCES `aircraft`(`Aircraft_ID`) )
List the names of pilots that do not have any record.
SELECT Pilot_name FROM pilot WHERE Pilot_ID NOT IN (SELECT Pilot_ID FROM pilot_record)
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
What document status codes do we have?
SELECT document_status_code FROM Ref_Document_Status;
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
What is the description of document status code 'working'?
SELECT document_status_description FROM Ref_Document_Status WHERE document_status_code = "working";
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
What document type codes do we have?
SELECT document_type_code FROM Ref_Document_Types;
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
What is the description of document type 'Paper'?
SELECT document_type_description FROM Ref_Document_Types WHERE document_type_code = "Paper";
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
What are the shipping agent names?
SELECT shipping_agent_name FROM Ref_Shipping_Agents;
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
What is the shipping agent code of shipping agent UPS?
SELECT shipping_agent_code FROM Ref_Shipping_Agents WHERE shipping_agent_name = "UPS";
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
What are all role codes?
SELECT role_code FROM ROLES;
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
What is the description of role code ED?
SELECT role_description FROM ROLES WHERE role_code = "ED";
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
How many employees do we have?
SELECT count(*) FROM Employees;
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
What is the role of the employee named Koby?
SELECT T1.role_description FROM ROLES AS T1 JOIN Employees AS T2 ON T1.role_code = T2.role_code WHERE T2.employee_name = "Koby";
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
List all document ids and receipt dates of documents.
SELECT document_id , receipt_date FROM Documents;
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
How many employees does each role have? List role description, id and number of employees.
SELECT T1.role_description , T2.role_code , count(*) FROM ROLES AS T1 JOIN Employees AS T2 ON T1.role_code = T2.role_code GROUP BY T2.role_code;
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
List roles that have more than one employee. List the role description and number of employees.
SELECT Roles.role_description , count(Employees.employee_id) FROM ROLES JOIN Employees ON Employees.role_code = Roles.role_code GROUP BY Employees.role_code HAVING count(Employees.employee_id) > 1;
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
What is the document status description of the document with id 1?
SELECT Ref_Document_Status.document_status_description FROM Ref_Document_Status JOIN Documents ON Documents.document_status_code = Ref_Document_Status.document_status_code WHERE Documents.document_id = 1;
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
How many documents have the status code done?
SELECT count(*) FROM Documents WHERE document_status_code = "done";
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
List the document type code for the document with the id 2.
SELECT document_type_code FROM Documents WHERE document_id = 2;
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
List the document ids for any documents with the status code done and the type code paper.
SELECT document_id FROM Documents WHERE document_status_code = "done" AND document_type_code = "Paper";
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
What is the name of the shipping agent of the document with id 2?
SELECT Ref_Shipping_Agents.shipping_agent_name FROM Ref_Shipping_Agents JOIN Documents ON Documents.shipping_agent_code = Ref_Shipping_Agents.shipping_agent_code WHERE Documents.document_id = 2;
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
How many documents were shipped by USPS?
SELECT count(*) FROM Ref_Shipping_Agents JOIN Documents ON Documents.shipping_agent_code = Ref_Shipping_Agents.shipping_agent_code WHERE Ref_Shipping_Agents.shipping_agent_name = "USPS";
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
Which shipping agent shipped the most documents? List the shipping agent name and the number of documents.
SELECT Ref_Shipping_Agents.shipping_agent_name , count(Documents.document_id) FROM Ref_Shipping_Agents JOIN Documents ON Documents.shipping_agent_code = Ref_Shipping_Agents.shipping_agent_code GROUP BY Ref_Shipping_Agents.shipping_agent_code ORDER BY count(Documents.document_id) DESC LIMIT 1;
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
What is the receipt date of the document with id 3?
SELECT receipt_date FROM Documents WHERE document_id = 3;
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
What address was the document with id 4 mailed to?
SELECT Addresses.address_details FROM Addresses JOIN Documents_Mailed ON Documents_Mailed.mailed_to_address_id = Addresses.address_id WHERE document_id = 4;
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
What is the mail date of the document with id 7?
SELECT mailing_date FROM Documents_Mailed WHERE document_id = 7;
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
List the document ids of documents with the status done and type Paper, which not shipped by the shipping agent named USPS.
SELECT document_id FROM Documents WHERE document_status_code = "done" AND document_type_code = "Paper" EXCEPT SELECT document_id FROM Documents JOIN Ref_Shipping_Agents ON Documents.shipping_agent_code = Ref_Shipping_Agents.shipping_agent_code WHERE Ref_Shipping_Agents.shipping_agent_name = "USPS";
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
List document id of documents status is done and document type is Paper and the document is shipped by shipping agent named USPS.
SELECT document_id FROM Documents WHERE document_status_code = "done" AND document_type_code = "Paper" INTERSECT SELECT document_id FROM Documents JOIN Ref_Shipping_Agents ON Documents.shipping_agent_code = Ref_Shipping_Agents.shipping_agent_code WHERE Ref_Shipping_Agents.shipping_agent_name = "USPS";
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
What is draft detail of the document with id 7?
SELECT draft_details FROM Document_Drafts WHERE document_id = 7;
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
How many draft copies does the document with id 2 have?
SELECT count(*) FROM Draft_Copies WHERE document_id = 2;
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
Which document has the most draft copies? List its document id and number of draft copies.
SELECT document_id , count(copy_number) FROM Draft_Copies GROUP BY document_id ORDER BY count(copy_number) DESC LIMIT 1;
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
Which documents have more than 1 draft copies? List document id and number of draft copies.
SELECT document_id , count(*) FROM Draft_Copies GROUP BY document_id HAVING count(*) > 1;
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
List all employees in the circulation history of the document with id 1. List the employee's name.
SELECT Employees.employee_name FROM Employees JOIN Circulation_History ON Circulation_History.employee_id = Employees.employee_id WHERE Circulation_History.document_id = 1;
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
List the employees who have not showed up in any circulation history of documents. List the employee's name.
SELECT employee_name FROM Employees EXCEPT SELECT Employees.employee_name FROM Employees JOIN Circulation_History ON Circulation_History.employee_id = Employees.employee_id
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
Which employee has showed up in most circulation history documents. List the employee's name and the number of drafts and copies.
SELECT Employees.employee_name , count(*) FROM Employees JOIN Circulation_History ON Circulation_History.employee_id = Employees.employee_id GROUP BY Circulation_History.document_id , Circulation_History.draft_number , Circulation_History.copy_number ORDER BY count(*) DESC LIMIT 1;
1
cre_Doc_Control_Systems
CREATE TABLE Ref_Document_Types ( document_type_code CHAR(15) NOT NULL, document_type_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_type_code) ); CREATE TABLE ROLES ( role_code CHAR(15) NOT NULL, role_description VARCHAR(255), PRIMARY KEY (role_code) ); CREATE TABLE Addresses ( address_id INTEGER NOT NULL, address_details VARCHAR(255), PRIMARY KEY (address_id) ); CREATE TABLE Ref_Document_Status ( document_status_code CHAR(15) NOT NULL, document_status_description VARCHAR(255) NOT NULL, PRIMARY KEY (document_status_code) ); CREATE TABLE Ref_Shipping_Agents ( shipping_agent_code CHAR(15) NOT NULL, shipping_agent_name VARCHAR(255) NOT NULL, shipping_agent_description VARCHAR(255) NOT NULL, PRIMARY KEY (shipping_agent_code) ); CREATE TABLE Documents ( document_id INTEGER NOT NULL, document_status_code CHAR(15) NOT NULL, document_type_code CHAR(15) NOT NULL, shipping_agent_code CHAR(15), receipt_date DATETIME, receipt_number VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (document_id), FOREIGN KEY (document_type_code) REFERENCES Ref_Document_Types (document_type_code), FOREIGN KEY (document_status_code) REFERENCES Ref_Document_Status (document_status_code), FOREIGN KEY (shipping_agent_code) REFERENCES Ref_Shipping_Agents (shipping_agent_code) ); CREATE TABLE Employees ( employee_id INTEGER NOT NULL, role_code CHAR(15) NOT NULL, employee_name VARCHAR(255), other_details VARCHAR(255), PRIMARY KEY (employee_id), FOREIGN KEY (role_code) REFERENCES ROLES (role_code) ); CREATE TABLE Document_Drafts ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, draft_details VARCHAR(255), PRIMARY KEY (document_id, draft_number), FOREIGN KEY (document_id) REFERENCES Documents (document_id) ); CREATE TABLE Draft_Copies ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number), FOREIGN KEY (document_id, draft_number) REFERENCES Document_Drafts (document_id,draft_number) ); CREATE TABLE Circulation_History ( document_id INTEGER NOT NULL, draft_number INTEGER NOT NULL, copy_number INTEGER NOT NULL, employee_id INTEGER NOT NULL, PRIMARY KEY (document_id, draft_number, copy_number, employee_id), FOREIGN KEY (document_id, draft_number, copy_number) REFERENCES Draft_Copies (document_id,draft_number,copy_number), FOREIGN KEY (employee_id) REFERENCES Employees (employee_id) ); CREATE TABLE Documents_Mailed ( document_id INTEGER NOT NULL, mailed_to_address_id INTEGER NOT NULL, mailing_date DATETIME, PRIMARY KEY (document_id, mailed_to_address_id), FOREIGN KEY (document_id) REFERENCES Documents (document_id), FOREIGN KEY (mailed_to_address_id) REFERENCES Addresses (address_id) )
For each document, list the number of employees who have showed up in the circulation history of that document. List the document ids and number of employees.
SELECT document_id , count(DISTINCT employee_id) FROM Circulation_History GROUP BY document_id;
1
local_govt_in_alabama
CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_Type_Code CHAR(15) NOT NULL, PRIMARY KEY (Service_ID) ); CREATE TABLE Participants ( Participant_ID INTEGER NOT NULL, Participant_Type_Code CHAR(15) NOT NULL, Participant_Details VARCHAR(255), PRIMARY KEY (Participant_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, Event_Details VARCHAR(255), PRIMARY KEY (Event_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID) ); CREATE TABLE Participants_in_Events ( Event_ID INTEGER NOT NULL, Participant_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID, Participant_ID), FOREIGN KEY (Participant_ID) REFERENCES Participants (Participant_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
what are the event details of the services that have the type code 'Marriage'?
SELECT T1.event_details FROM EVENTS AS T1 JOIN Services AS T2 ON T1.Service_ID = T2.Service_ID WHERE T2.Service_Type_Code = 'Marriage'
1
local_govt_in_alabama
CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_Type_Code CHAR(15) NOT NULL, PRIMARY KEY (Service_ID) ); CREATE TABLE Participants ( Participant_ID INTEGER NOT NULL, Participant_Type_Code CHAR(15) NOT NULL, Participant_Details VARCHAR(255), PRIMARY KEY (Participant_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, Event_Details VARCHAR(255), PRIMARY KEY (Event_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID) ); CREATE TABLE Participants_in_Events ( Event_ID INTEGER NOT NULL, Participant_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID, Participant_ID), FOREIGN KEY (Participant_ID) REFERENCES Participants (Participant_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
What are the ids and details of events that have more than one participants?
SELECT T1.event_id , T1.event_details FROM EVENTS AS T1 JOIN Participants_in_Events AS T2 ON T1.Event_ID = T2.Event_ID GROUP BY T1.Event_ID HAVING count(*) > 1
1
local_govt_in_alabama
CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_Type_Code CHAR(15) NOT NULL, PRIMARY KEY (Service_ID) ); CREATE TABLE Participants ( Participant_ID INTEGER NOT NULL, Participant_Type_Code CHAR(15) NOT NULL, Participant_Details VARCHAR(255), PRIMARY KEY (Participant_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, Event_Details VARCHAR(255), PRIMARY KEY (Event_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID) ); CREATE TABLE Participants_in_Events ( Event_ID INTEGER NOT NULL, Participant_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID, Participant_ID), FOREIGN KEY (Participant_ID) REFERENCES Participants (Participant_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
How many events have each participants attended? List the participant id, type and the number.
SELECT T1.Participant_ID , T1.Participant_Type_Code , count(*) FROM Participants AS T1 JOIN Participants_in_Events AS T2 ON T1.Participant_ID = T2.Participant_ID GROUP BY T1.Participant_ID
1
local_govt_in_alabama
CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_Type_Code CHAR(15) NOT NULL, PRIMARY KEY (Service_ID) ); CREATE TABLE Participants ( Participant_ID INTEGER NOT NULL, Participant_Type_Code CHAR(15) NOT NULL, Participant_Details VARCHAR(255), PRIMARY KEY (Participant_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, Event_Details VARCHAR(255), PRIMARY KEY (Event_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID) ); CREATE TABLE Participants_in_Events ( Event_ID INTEGER NOT NULL, Participant_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID, Participant_ID), FOREIGN KEY (Participant_ID) REFERENCES Participants (Participant_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
What are all the the participant ids, type code and details?
SELECT Participant_ID , Participant_Type_Code , Participant_Details FROM Participants
1
local_govt_in_alabama
CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_Type_Code CHAR(15) NOT NULL, PRIMARY KEY (Service_ID) ); CREATE TABLE Participants ( Participant_ID INTEGER NOT NULL, Participant_Type_Code CHAR(15) NOT NULL, Participant_Details VARCHAR(255), PRIMARY KEY (Participant_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, Event_Details VARCHAR(255), PRIMARY KEY (Event_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID) ); CREATE TABLE Participants_in_Events ( Event_ID INTEGER NOT NULL, Participant_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID, Participant_ID), FOREIGN KEY (Participant_ID) REFERENCES Participants (Participant_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
How many participants belong to the type 'Organizer'?
SELECT count(*) FROM participants WHERE participant_type_code = 'Organizer'
1
local_govt_in_alabama
CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_Type_Code CHAR(15) NOT NULL, PRIMARY KEY (Service_ID) ); CREATE TABLE Participants ( Participant_ID INTEGER NOT NULL, Participant_Type_Code CHAR(15) NOT NULL, Participant_Details VARCHAR(255), PRIMARY KEY (Participant_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, Event_Details VARCHAR(255), PRIMARY KEY (Event_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID) ); CREATE TABLE Participants_in_Events ( Event_ID INTEGER NOT NULL, Participant_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID, Participant_ID), FOREIGN KEY (Participant_ID) REFERENCES Participants (Participant_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
List the type of the services in alphabetical order.
SELECT service_type_code FROM services ORDER BY service_type_code
1
local_govt_in_alabama
CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_Type_Code CHAR(15) NOT NULL, PRIMARY KEY (Service_ID) ); CREATE TABLE Participants ( Participant_ID INTEGER NOT NULL, Participant_Type_Code CHAR(15) NOT NULL, Participant_Details VARCHAR(255), PRIMARY KEY (Participant_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, Event_Details VARCHAR(255), PRIMARY KEY (Event_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID) ); CREATE TABLE Participants_in_Events ( Event_ID INTEGER NOT NULL, Participant_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID, Participant_ID), FOREIGN KEY (Participant_ID) REFERENCES Participants (Participant_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
List the service id and details for the events.
SELECT service_id , event_details FROM EVENTS
1
local_govt_in_alabama
CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_Type_Code CHAR(15) NOT NULL, PRIMARY KEY (Service_ID) ); CREATE TABLE Participants ( Participant_ID INTEGER NOT NULL, Participant_Type_Code CHAR(15) NOT NULL, Participant_Details VARCHAR(255), PRIMARY KEY (Participant_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, Event_Details VARCHAR(255), PRIMARY KEY (Event_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID) ); CREATE TABLE Participants_in_Events ( Event_ID INTEGER NOT NULL, Participant_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID, Participant_ID), FOREIGN KEY (Participant_ID) REFERENCES Participants (Participant_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
How many events had participants whose details had the substring 'Dr.'
SELECT count(*) FROM participants AS T1 JOIN Participants_in_Events AS T2 ON T1.Participant_ID = T2.Participant_ID WHERE T1.participant_details LIKE '%Dr.%'
1
local_govt_in_alabama
CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_Type_Code CHAR(15) NOT NULL, PRIMARY KEY (Service_ID) ); CREATE TABLE Participants ( Participant_ID INTEGER NOT NULL, Participant_Type_Code CHAR(15) NOT NULL, Participant_Details VARCHAR(255), PRIMARY KEY (Participant_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, Event_Details VARCHAR(255), PRIMARY KEY (Event_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID) ); CREATE TABLE Participants_in_Events ( Event_ID INTEGER NOT NULL, Participant_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID, Participant_ID), FOREIGN KEY (Participant_ID) REFERENCES Participants (Participant_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
What is the most common participant type?
SELECT participant_type_code FROM participants GROUP BY participant_type_code ORDER BY count(*) DESC LIMIT 1
1
local_govt_in_alabama
CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_Type_Code CHAR(15) NOT NULL, PRIMARY KEY (Service_ID) ); CREATE TABLE Participants ( Participant_ID INTEGER NOT NULL, Participant_Type_Code CHAR(15) NOT NULL, Participant_Details VARCHAR(255), PRIMARY KEY (Participant_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, Event_Details VARCHAR(255), PRIMARY KEY (Event_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID) ); CREATE TABLE Participants_in_Events ( Event_ID INTEGER NOT NULL, Participant_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID, Participant_ID), FOREIGN KEY (Participant_ID) REFERENCES Participants (Participant_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
Which service id and type has the least number of participants?
SELECT T3.service_id , T4.Service_Type_Code FROM participants AS T1 JOIN Participants_in_Events AS T2 ON T1.Participant_ID = T2.Participant_ID JOIN EVENTS AS T3 ON T2.Event_ID = T3.Event_ID JOIN services AS T4 ON T3.service_id = T4.service_id GROUP BY T3.service_id ORDER BY count(*) ASC LIMIT 1
1
local_govt_in_alabama
CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_Type_Code CHAR(15) NOT NULL, PRIMARY KEY (Service_ID) ); CREATE TABLE Participants ( Participant_ID INTEGER NOT NULL, Participant_Type_Code CHAR(15) NOT NULL, Participant_Details VARCHAR(255), PRIMARY KEY (Participant_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, Event_Details VARCHAR(255), PRIMARY KEY (Event_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID) ); CREATE TABLE Participants_in_Events ( Event_ID INTEGER NOT NULL, Participant_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID, Participant_ID), FOREIGN KEY (Participant_ID) REFERENCES Participants (Participant_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
What is the id of the event with the most participants?
SELECT Event_ID FROM Participants_in_Events GROUP BY Event_ID ORDER BY count(*) DESC LIMIT 1
1
local_govt_in_alabama
CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_Type_Code CHAR(15) NOT NULL, PRIMARY KEY (Service_ID) ); CREATE TABLE Participants ( Participant_ID INTEGER NOT NULL, Participant_Type_Code CHAR(15) NOT NULL, Participant_Details VARCHAR(255), PRIMARY KEY (Participant_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, Event_Details VARCHAR(255), PRIMARY KEY (Event_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID) ); CREATE TABLE Participants_in_Events ( Event_ID INTEGER NOT NULL, Participant_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID, Participant_ID), FOREIGN KEY (Participant_ID) REFERENCES Participants (Participant_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
Which events id does not have any participant with detail 'Kenyatta Kuhn'?
SELECT event_id FROM EVENTS EXCEPT SELECT T1.event_id FROM Participants_in_Events AS T1 JOIN Participants AS T2 ON T1.Participant_ID = T2.Participant_ID WHERE Participant_Details = 'Kenyatta Kuhn'
1
local_govt_in_alabama
CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_Type_Code CHAR(15) NOT NULL, PRIMARY KEY (Service_ID) ); CREATE TABLE Participants ( Participant_ID INTEGER NOT NULL, Participant_Type_Code CHAR(15) NOT NULL, Participant_Details VARCHAR(255), PRIMARY KEY (Participant_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, Event_Details VARCHAR(255), PRIMARY KEY (Event_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID) ); CREATE TABLE Participants_in_Events ( Event_ID INTEGER NOT NULL, Participant_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID, Participant_ID), FOREIGN KEY (Participant_ID) REFERENCES Participants (Participant_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
Which services type had both successful and failure event details?
SELECT T1.service_type_code FROM services AS T1 JOIN EVENTS AS T2 ON T1.service_id = T2.service_id WHERE T2.event_details = 'Success' INTERSECT SELECT T1.service_type_code FROM services AS T1 JOIN EVENTS AS T2 ON T1.service_id = T2.service_id WHERE T2.event_details = 'Fail'
1
local_govt_in_alabama
CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_Type_Code CHAR(15) NOT NULL, PRIMARY KEY (Service_ID) ); CREATE TABLE Participants ( Participant_ID INTEGER NOT NULL, Participant_Type_Code CHAR(15) NOT NULL, Participant_Details VARCHAR(255), PRIMARY KEY (Participant_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, Event_Details VARCHAR(255), PRIMARY KEY (Event_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID) ); CREATE TABLE Participants_in_Events ( Event_ID INTEGER NOT NULL, Participant_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID, Participant_ID), FOREIGN KEY (Participant_ID) REFERENCES Participants (Participant_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
How many events did not have any participants?
SELECT count(*) FROM EVENTS WHERE event_id NOT IN (SELECT event_id FROM Participants_in_Events)
1
local_govt_in_alabama
CREATE TABLE Services ( Service_ID INTEGER NOT NULL, Service_Type_Code CHAR(15) NOT NULL, PRIMARY KEY (Service_ID) ); CREATE TABLE Participants ( Participant_ID INTEGER NOT NULL, Participant_Type_Code CHAR(15) NOT NULL, Participant_Details VARCHAR(255), PRIMARY KEY (Participant_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL, Service_ID INTEGER NOT NULL, Event_Details VARCHAR(255), PRIMARY KEY (Event_ID), FOREIGN KEY (Service_ID) REFERENCES Services (Service_ID) ); CREATE TABLE Participants_in_Events ( Event_ID INTEGER NOT NULL, Participant_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID, Participant_ID), FOREIGN KEY (Participant_ID) REFERENCES Participants (Participant_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
What are all the distinct participant ids who attended any events?
SELECT count(DISTINCT participant_id) FROM participants_in_Events
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
How many technicians are there?
SELECT count(*) FROM technician
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
What is the number of technicians?
SELECT count(*) FROM technician
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
List the names of technicians in ascending order of age.
SELECT Name FROM technician ORDER BY Age ASC
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
What are the names of the technicians by ascending order of age?
SELECT Name FROM technician ORDER BY Age ASC
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
What are the team and starting year of technicians?
SELECT Team , Starting_Year FROM technician
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
What is the team and starting year for each technician?
SELECT Team , Starting_Year FROM technician
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
List the name of technicians whose team is not "NYY".
SELECT Name FROM technician WHERE Team != "NYY"
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
What is the name of the technician whose team is not 'NYY'?
SELECT Name FROM technician WHERE Team != "NYY"
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
Show the name of technicians aged either 36 or 37
SELECT Name FROM technician WHERE Age = 36 OR Age = 37
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
What are the names of the technicians aged either 36 or 37?
SELECT Name FROM technician WHERE Age = 36 OR Age = 37
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
What is the starting year of the oldest technicians?
SELECT Starting_Year FROM technician ORDER BY Age DESC LIMIT 1
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
What is the starting year for the oldest technician?
SELECT Starting_Year FROM technician ORDER BY Age DESC LIMIT 1
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
Show different teams of technicians and the number of technicians in each team.
SELECT Team , COUNT(*) FROM technician GROUP BY Team
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
For each team, how many technicians are there?
SELECT Team , COUNT(*) FROM technician GROUP BY Team
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
Please show the team that has the most number of technicians.
SELECT Team FROM technician GROUP BY Team ORDER BY COUNT(*) DESC LIMIT 1
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
What are the teams with the most technicians?
SELECT Team FROM technician GROUP BY Team ORDER BY COUNT(*) DESC LIMIT 1
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
Show the team that have at least two technicians.
SELECT Team FROM technician GROUP BY Team HAVING COUNT(*) >= 2
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
What is the team with at least 2 technicians?
SELECT Team FROM technician GROUP BY Team HAVING COUNT(*) >= 2
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
Show names of technicians and series of machines they are assigned to repair.
SELECT T3.Name , T2.Machine_series FROM repair_assignment AS T1 JOIN machine AS T2 ON T1.machine_id = T2.machine_id JOIN technician AS T3 ON T1.technician_ID = T3.technician_ID
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
What are the names of technicians and the machine series that they repair?
SELECT T3.Name , T2.Machine_series FROM repair_assignment AS T1 JOIN machine AS T2 ON T1.machine_id = T2.machine_id JOIN technician AS T3 ON T1.technician_ID = T3.technician_ID
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
Show names of technicians in ascending order of quality rank of the machine they are assigned.
SELECT T3.Name FROM repair_assignment AS T1 JOIN machine AS T2 ON T1.machine_id = T2.machine_id JOIN technician AS T3 ON T1.technician_ID = T3.technician_ID ORDER BY T2.quality_rank
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
What are the names of the technicians by ascending order of quality rank for the machine they are assigned?
SELECT T3.Name FROM repair_assignment AS T1 JOIN machine AS T2 ON T1.machine_id = T2.machine_id JOIN technician AS T3 ON T1.technician_ID = T3.technician_ID ORDER BY T2.quality_rank
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
Show names of technicians who are assigned to repair machines with value point more than 70.
SELECT T3.Name FROM repair_assignment AS T1 JOIN machine AS T2 ON T1.machine_id = T2.machine_id JOIN technician AS T3 ON T1.technician_ID = T3.technician_ID WHERE T2.value_points > 70
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
What are the names of the technicians that are assigned to repair machines with more point values than 70?
SELECT T3.Name FROM repair_assignment AS T1 JOIN machine AS T2 ON T1.machine_id = T2.machine_id JOIN technician AS T3 ON T1.technician_ID = T3.technician_ID WHERE T2.value_points > 70
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
Show names of technicians and the number of machines they are assigned to repair.
SELECT T2.Name , COUNT(*) FROM repair_assignment AS T1 JOIN technician AS T2 ON T1.technician_ID = T2.technician_ID GROUP BY T2.Name
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
What are the names of the technicians and how many machines are they assigned to repair?
SELECT T2.Name , COUNT(*) FROM repair_assignment AS T1 JOIN technician AS T2 ON T1.technician_ID = T2.technician_ID GROUP BY T2.Name
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
List the names of technicians who have not been assigned to repair machines.
SELECT Name FROM technician WHERE technician_id NOT IN (SELECT technician_id FROM repair_assignment)
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
What are the names of the technicians that have not been assigned to repair machines?
SELECT Name FROM technician WHERE technician_id NOT IN (SELECT technician_id FROM repair_assignment)
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
Show the starting years shared by technicians from team "CLE" and "CWS".
SELECT Starting_Year FROM technician WHERE Team = "CLE" INTERSECT SELECT Starting_Year FROM technician WHERE Team = "CWS"
1
machine_repair
CREATE TABLE "repair" ( "repair_ID" int, "name" text, "Launch_Date" text, "Notes" text, PRIMARY KEY ("repair_ID") ); CREATE TABLE "machine" ( "Machine_ID" int, "Making_Year" int, "Class" text, "Team" text, "Machine_series" text, "value_points" real, "quality_rank" int, PRIMARY KEY ("Machine_ID") ); CREATE TABLE "technician" ( "technician_id" real, "Name" text, "Team" text, "Starting_Year" real, "Age" int, PRIMARY KEY ("technician_id") ); CREATE TABLE "repair_assignment" ( "technician_id" int, "repair_ID" int, "Machine_ID" int, PRIMARY KEY ("technician_id","repair_ID","Machine_ID"), FOREIGN KEY (`technician_id`) REFERENCES `technician`(`technician_id`), FOREIGN KEY (`repair_ID`) REFERENCES `repair`(`repair_ID`), FOREIGN KEY (`Machine_ID`) REFERENCES `machine`(`Machine_ID`) )
What are the starting years shared by the technicians from the team "CLE" or "CWS"?
SELECT Starting_Year FROM technician WHERE Team = "CLE" INTERSECT SELECT Starting_Year FROM technician WHERE Team = "CWS"
1
entrepreneur
CREATE TABLE "entrepreneur" ( "Entrepreneur_ID" int, "People_ID" int, "Company" text, "Money_Requested" real, "Investor" text, PRIMARY KEY ("Entrepreneur_ID"), FOREIGN KEY ("People_ID") REFERENCES "people"("People_ID") ); CREATE TABLE "people" ( "People_ID" int, "Name" text, "Height" real, "Weight" real, "Date_of_Birth" text, PRIMARY KEY ("People_ID") )
How many entrepreneurs are there?
SELECT count(*) FROM entrepreneur
1
entrepreneur
CREATE TABLE "entrepreneur" ( "Entrepreneur_ID" int, "People_ID" int, "Company" text, "Money_Requested" real, "Investor" text, PRIMARY KEY ("Entrepreneur_ID"), FOREIGN KEY ("People_ID") REFERENCES "people"("People_ID") ); CREATE TABLE "people" ( "People_ID" int, "Name" text, "Height" real, "Weight" real, "Date_of_Birth" text, PRIMARY KEY ("People_ID") )
Count the number of entrepreneurs.
SELECT count(*) FROM entrepreneur
1
entrepreneur
CREATE TABLE "entrepreneur" ( "Entrepreneur_ID" int, "People_ID" int, "Company" text, "Money_Requested" real, "Investor" text, PRIMARY KEY ("Entrepreneur_ID"), FOREIGN KEY ("People_ID") REFERENCES "people"("People_ID") ); CREATE TABLE "people" ( "People_ID" int, "Name" text, "Height" real, "Weight" real, "Date_of_Birth" text, PRIMARY KEY ("People_ID") )
List the companies of entrepreneurs in descending order of money requested.
SELECT Company FROM entrepreneur ORDER BY Money_Requested DESC
1
entrepreneur
CREATE TABLE "entrepreneur" ( "Entrepreneur_ID" int, "People_ID" int, "Company" text, "Money_Requested" real, "Investor" text, PRIMARY KEY ("Entrepreneur_ID"), FOREIGN KEY ("People_ID") REFERENCES "people"("People_ID") ); CREATE TABLE "people" ( "People_ID" int, "Name" text, "Height" real, "Weight" real, "Date_of_Birth" text, PRIMARY KEY ("People_ID") )
What are the companies of entrepreneurs, ordered descending by amount of money requested?
SELECT Company FROM entrepreneur ORDER BY Money_Requested DESC
1
entrepreneur
CREATE TABLE "entrepreneur" ( "Entrepreneur_ID" int, "People_ID" int, "Company" text, "Money_Requested" real, "Investor" text, PRIMARY KEY ("Entrepreneur_ID"), FOREIGN KEY ("People_ID") REFERENCES "people"("People_ID") ); CREATE TABLE "people" ( "People_ID" int, "Name" text, "Height" real, "Weight" real, "Date_of_Birth" text, PRIMARY KEY ("People_ID") )
List the companies and the investors of entrepreneurs.
SELECT Company , Investor FROM entrepreneur
1
entrepreneur
CREATE TABLE "entrepreneur" ( "Entrepreneur_ID" int, "People_ID" int, "Company" text, "Money_Requested" real, "Investor" text, PRIMARY KEY ("Entrepreneur_ID"), FOREIGN KEY ("People_ID") REFERENCES "people"("People_ID") ); CREATE TABLE "people" ( "People_ID" int, "Name" text, "Height" real, "Weight" real, "Date_of_Birth" text, PRIMARY KEY ("People_ID") )
What are the companies and investors that correspond to each entrepreneur?
SELECT Company , Investor FROM entrepreneur
1
entrepreneur
CREATE TABLE "entrepreneur" ( "Entrepreneur_ID" int, "People_ID" int, "Company" text, "Money_Requested" real, "Investor" text, PRIMARY KEY ("Entrepreneur_ID"), FOREIGN KEY ("People_ID") REFERENCES "people"("People_ID") ); CREATE TABLE "people" ( "People_ID" int, "Name" text, "Height" real, "Weight" real, "Date_of_Birth" text, PRIMARY KEY ("People_ID") )
What is the average money requested by all entrepreneurs?
SELECT avg(Money_Requested) FROM entrepreneur
1
entrepreneur
CREATE TABLE "entrepreneur" ( "Entrepreneur_ID" int, "People_ID" int, "Company" text, "Money_Requested" real, "Investor" text, PRIMARY KEY ("Entrepreneur_ID"), FOREIGN KEY ("People_ID") REFERENCES "people"("People_ID") ); CREATE TABLE "people" ( "People_ID" int, "Name" text, "Height" real, "Weight" real, "Date_of_Birth" text, PRIMARY KEY ("People_ID") )
Return the average money requested across all entrepreneurs.
SELECT avg(Money_Requested) FROM entrepreneur
1
entrepreneur
CREATE TABLE "entrepreneur" ( "Entrepreneur_ID" int, "People_ID" int, "Company" text, "Money_Requested" real, "Investor" text, PRIMARY KEY ("Entrepreneur_ID"), FOREIGN KEY ("People_ID") REFERENCES "people"("People_ID") ); CREATE TABLE "people" ( "People_ID" int, "Name" text, "Height" real, "Weight" real, "Date_of_Birth" text, PRIMARY KEY ("People_ID") )
What are the names of people in ascending order of weight?
SELECT Name FROM People ORDER BY Weight ASC
1
entrepreneur
CREATE TABLE "entrepreneur" ( "Entrepreneur_ID" int, "People_ID" int, "Company" text, "Money_Requested" real, "Investor" text, PRIMARY KEY ("Entrepreneur_ID"), FOREIGN KEY ("People_ID") REFERENCES "people"("People_ID") ); CREATE TABLE "people" ( "People_ID" int, "Name" text, "Height" real, "Weight" real, "Date_of_Birth" text, PRIMARY KEY ("People_ID") )
Return the names of people, ordered by weight ascending.
SELECT Name FROM People ORDER BY Weight ASC
1
entrepreneur
CREATE TABLE "entrepreneur" ( "Entrepreneur_ID" int, "People_ID" int, "Company" text, "Money_Requested" real, "Investor" text, PRIMARY KEY ("Entrepreneur_ID"), FOREIGN KEY ("People_ID") REFERENCES "people"("People_ID") ); CREATE TABLE "people" ( "People_ID" int, "Name" text, "Height" real, "Weight" real, "Date_of_Birth" text, PRIMARY KEY ("People_ID") )
What are the names of entrepreneurs?
SELECT T2.Name FROM entrepreneur AS T1 JOIN people AS T2 ON T1.People_ID = T2.People_ID
1
entrepreneur
CREATE TABLE "entrepreneur" ( "Entrepreneur_ID" int, "People_ID" int, "Company" text, "Money_Requested" real, "Investor" text, PRIMARY KEY ("Entrepreneur_ID"), FOREIGN KEY ("People_ID") REFERENCES "people"("People_ID") ); CREATE TABLE "people" ( "People_ID" int, "Name" text, "Height" real, "Weight" real, "Date_of_Birth" text, PRIMARY KEY ("People_ID") )
Return the names of entrepreneurs.
SELECT T2.Name FROM entrepreneur AS T1 JOIN people AS T2 ON T1.People_ID = T2.People_ID
1
entrepreneur
CREATE TABLE "entrepreneur" ( "Entrepreneur_ID" int, "People_ID" int, "Company" text, "Money_Requested" real, "Investor" text, PRIMARY KEY ("Entrepreneur_ID"), FOREIGN KEY ("People_ID") REFERENCES "people"("People_ID") ); CREATE TABLE "people" ( "People_ID" int, "Name" text, "Height" real, "Weight" real, "Date_of_Birth" text, PRIMARY KEY ("People_ID") )
What are the names of entrepreneurs whose investor is not "Rachel Elnaugh"?
SELECT T2.Name FROM entrepreneur AS T1 JOIN people AS T2 ON T1.People_ID = T2.People_ID WHERE T1.Investor != "Rachel Elnaugh"
1
entrepreneur
CREATE TABLE "entrepreneur" ( "Entrepreneur_ID" int, "People_ID" int, "Company" text, "Money_Requested" real, "Investor" text, PRIMARY KEY ("Entrepreneur_ID"), FOREIGN KEY ("People_ID") REFERENCES "people"("People_ID") ); CREATE TABLE "people" ( "People_ID" int, "Name" text, "Height" real, "Weight" real, "Date_of_Birth" text, PRIMARY KEY ("People_ID") )
Return the names of entrepreneurs do no not have the investor Rachel Elnaugh.
SELECT T2.Name FROM entrepreneur AS T1 JOIN people AS T2 ON T1.People_ID = T2.People_ID WHERE T1.Investor != "Rachel Elnaugh"
1
entrepreneur
CREATE TABLE "entrepreneur" ( "Entrepreneur_ID" int, "People_ID" int, "Company" text, "Money_Requested" real, "Investor" text, PRIMARY KEY ("Entrepreneur_ID"), FOREIGN KEY ("People_ID") REFERENCES "people"("People_ID") ); CREATE TABLE "people" ( "People_ID" int, "Name" text, "Height" real, "Weight" real, "Date_of_Birth" text, PRIMARY KEY ("People_ID") )
What is the weight of the shortest person?
SELECT Weight FROM people ORDER BY Height ASC LIMIT 1