spider_version
int64
1
2
db_id
stringclasses
204 values
schema
stringclasses
187 values
question
stringlengths
3
328
query
stringlengths
20
3.81k
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
What are the maximum and minimum sales of the companies whose industries are not "Banking".
SELECT max(Sales_billion) , min(Sales_billion) FROM Companies WHERE Industry != "Banking"
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Find the maximum and minimum sales of the companies that are not in the "Banking" industry.
SELECT max(Sales_billion) , min(Sales_billion) FROM Companies WHERE Industry != "Banking"
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
How many different industries are the companies in?
SELECT count(DISTINCT Industry) FROM Companies
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Count the number of distinct company industries.
SELECT count(DISTINCT Industry) FROM Companies
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
List the names of buildings in descending order of building height.
SELECT name FROM buildings ORDER BY Height DESC
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
What are the names of buildings sorted in descending order of building height?
SELECT name FROM buildings ORDER BY Height DESC
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Find the stories of the building with the largest height.
SELECT Stories FROM buildings ORDER BY Height DESC LIMIT 1
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
What is the stories of highest building?
SELECT Stories FROM buildings ORDER BY Height DESC LIMIT 1
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
List the name of a building along with the name of a company whose office is in the building.
SELECT T3.name , T2.name FROM Office_locations AS T1 JOIN buildings AS T2 ON T1.building_id = T2.id JOIN Companies AS T3 ON T1.company_id = T3.id
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
For each company, return the company name and the name of the building its office is located in.
SELECT T3.name , T2.name FROM Office_locations AS T1 JOIN buildings AS T2 ON T1.building_id = T2.id JOIN Companies AS T3 ON T1.company_id = T3.id
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Show the names of the buildings that have more than one company offices.
SELECT T2.name FROM Office_locations AS T1 JOIN buildings AS T2 ON T1.building_id = T2.id JOIN Companies AS T3 ON T1.company_id = T3.id GROUP BY T1.building_id HAVING COUNT(*) > 1
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Which buildings have more than one company offices? Give me the building names.
SELECT T2.name FROM Office_locations AS T1 JOIN buildings AS T2 ON T1.building_id = T2.id JOIN Companies AS T3 ON T1.company_id = T3.id GROUP BY T1.building_id HAVING COUNT(*) > 1
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Show the name of the building that has the most company offices.
SELECT T2.name FROM Office_locations AS T1 JOIN buildings AS T2 ON T1.building_id = T2.id JOIN Companies AS T3 ON T1.company_id = T3.id GROUP BY T1.building_id ORDER BY COUNT(*) DESC LIMIT 1
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Which building has the largest number of company offices? Give me the building name.
SELECT T2.name FROM Office_locations AS T1 JOIN buildings AS T2 ON T1.building_id = T2.id JOIN Companies AS T3 ON T1.company_id = T3.id GROUP BY T1.building_id ORDER BY COUNT(*) DESC LIMIT 1
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Please show the names of the buildings whose status is "on-hold", in ascending order of stories.
SELECT name FROM buildings WHERE Status = "on-hold" ORDER BY Stories ASC
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Find the names of the buildings in "on-hold" status, and sort them in ascending order of building stories.
SELECT name FROM buildings WHERE Status = "on-hold" ORDER BY Stories ASC
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Please show each industry and the corresponding number of companies in that industry.
SELECT Industry , COUNT(*) FROM Companies GROUP BY Industry
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Whah are the name of each industry and the number of companies in that industry?
SELECT Industry , COUNT(*) FROM Companies GROUP BY Industry
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Please show the industries of companies in descending order of the number of companies.
SELECT Industry FROM Companies GROUP BY Industry ORDER BY COUNT(*) DESC
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Sort all the industries in descending order of the count of companies in each industry
SELECT Industry FROM Companies GROUP BY Industry ORDER BY COUNT(*) DESC
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
List the industry shared by the most companies.
SELECT Industry FROM Companies GROUP BY Industry ORDER BY COUNT(*) DESC LIMIT 1
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Which industry has the most companies?
SELECT Industry FROM Companies GROUP BY Industry ORDER BY COUNT(*) DESC LIMIT 1
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
List the names of buildings that have no company office.
SELECT name FROM buildings WHERE id NOT IN (SELECT building_id FROM Office_locations)
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Which buildings do not have any company office? Give me the building names.
SELECT name FROM buildings WHERE id NOT IN (SELECT building_id FROM Office_locations)
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Show the industries shared by companies whose headquarters are "USA" and companies whose headquarters are "China".
SELECT Industry FROM Companies WHERE Headquarters = "USA" INTERSECT SELECT Industry FROM Companies WHERE Headquarters = "China"
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Which industries have both companies with headquarter in "USA" and companies with headquarter in "China"?
SELECT Industry FROM Companies WHERE Headquarters = "USA" INTERSECT SELECT Industry FROM Companies WHERE Headquarters = "China"
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Find the number of companies whose industry is "Banking" or "Conglomerate",
SELECT count(*) FROM Companies WHERE Industry = "Banking" OR Industry = "Conglomerate"
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
How many companies are in either "Banking" industry or "Conglomerate" industry?
SELECT count(*) FROM Companies WHERE Industry = "Banking" OR Industry = "Conglomerate"
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Show the headquarters shared by more than two companies.
SELECT Headquarters FROM Companies GROUP BY Headquarters HAVING COUNT(*) > 2
1
company_office
CREATE TABLE "buildings" ( "id" int, "name" text, "City" text, "Height" int, "Stories" int, "Status" text, PRIMARY KEY("id") ); CREATE TABLE "Companies" ( "id" int, "name" text, "Headquarters" text, "Industry" text, "Sales_billion" real, "Profits_billion" real, "Assets_billion" real, "Market_Value_billion" text, PRIMARY KEY ("id") ); CREATE TABLE "Office_locations" ( "building_id" int, "company_id" int, "move_in_year" int, PRIMARY KEY ("building_id", "company_id"), FOREIGN KEY ("building_id") REFERENCES "buildings"("id"), FOREIGN KEY ("company_id") REFERENCES "Companies"("id") )
Which headquarter locations are used by more than 2 companies?
SELECT Headquarters FROM Companies GROUP BY Headquarters HAVING COUNT(*) > 2
1
solvency_ii
CREATE TABLE Addresses ( Address_ID INTEGER NOT NULL , address_details VARCHAR(255), PRIMARY KEY (Address_ID), UNIQUE (Address_ID) ); CREATE TABLE Locations ( Location_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Location_ID) ); CREATE TABLE Products ( Product_ID INTEGER NOT NULL, Product_Type_Code CHAR(15), Product_Name VARCHAR(255), Product_Price DECIMAL(20,4), PRIMARY KEY (Product_ID), UNIQUE (Product_ID) ); CREATE TABLE Parties ( Party_ID INTEGER NOT NULL, Party_Details VARCHAR(255), PRIMARY KEY (Party_ID) ); CREATE TABLE Assets ( Asset_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Asset_ID) ); CREATE TABLE Channels ( Channel_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Channel_ID) ); CREATE TABLE Finances ( Finance_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Finance_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL , Address_ID INTEGER, Channel_ID INTEGER NOT NULL, Event_Type_Code CHAR(15), Finance_ID INTEGER NOT NULL, Location_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID), UNIQUE (Event_ID), FOREIGN KEY (Location_ID) REFERENCES Locations (Location_ID), FOREIGN KEY (Address_ID) REFERENCES Addresses (Address_ID), FOREIGN KEY (Finance_ID) REFERENCES Finances (Finance_ID) ); CREATE TABLE Products_in_Events ( Product_in_Event_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Product_ID INTEGER NOT NULL, PRIMARY KEY (Product_in_Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Product_ID) REFERENCES Products (Product_ID) ); CREATE TABLE Parties_in_Events ( Party_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Role_Code CHAR(15), PRIMARY KEY (Party_ID, Event_ID), FOREIGN KEY (Party_ID) REFERENCES Parties (Party_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Agreements ( Document_ID INTEGER NOT NULL , Event_ID INTEGER NOT NULL, PRIMARY KEY (Document_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Assets_in_Events ( Asset_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, PRIMARY KEY (Asset_ID, Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
How many products are there?
SELECT count(*) FROM Products
1
solvency_ii
CREATE TABLE Addresses ( Address_ID INTEGER NOT NULL , address_details VARCHAR(255), PRIMARY KEY (Address_ID), UNIQUE (Address_ID) ); CREATE TABLE Locations ( Location_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Location_ID) ); CREATE TABLE Products ( Product_ID INTEGER NOT NULL, Product_Type_Code CHAR(15), Product_Name VARCHAR(255), Product_Price DECIMAL(20,4), PRIMARY KEY (Product_ID), UNIQUE (Product_ID) ); CREATE TABLE Parties ( Party_ID INTEGER NOT NULL, Party_Details VARCHAR(255), PRIMARY KEY (Party_ID) ); CREATE TABLE Assets ( Asset_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Asset_ID) ); CREATE TABLE Channels ( Channel_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Channel_ID) ); CREATE TABLE Finances ( Finance_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Finance_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL , Address_ID INTEGER, Channel_ID INTEGER NOT NULL, Event_Type_Code CHAR(15), Finance_ID INTEGER NOT NULL, Location_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID), UNIQUE (Event_ID), FOREIGN KEY (Location_ID) REFERENCES Locations (Location_ID), FOREIGN KEY (Address_ID) REFERENCES Addresses (Address_ID), FOREIGN KEY (Finance_ID) REFERENCES Finances (Finance_ID) ); CREATE TABLE Products_in_Events ( Product_in_Event_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Product_ID INTEGER NOT NULL, PRIMARY KEY (Product_in_Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Product_ID) REFERENCES Products (Product_ID) ); CREATE TABLE Parties_in_Events ( Party_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Role_Code CHAR(15), PRIMARY KEY (Party_ID, Event_ID), FOREIGN KEY (Party_ID) REFERENCES Parties (Party_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Agreements ( Document_ID INTEGER NOT NULL , Event_ID INTEGER NOT NULL, PRIMARY KEY (Document_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Assets_in_Events ( Asset_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, PRIMARY KEY (Asset_ID, Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
List the name of products in ascending order of price.
SELECT Product_Name FROM Products ORDER BY Product_Price ASC
1
solvency_ii
CREATE TABLE Addresses ( Address_ID INTEGER NOT NULL , address_details VARCHAR(255), PRIMARY KEY (Address_ID), UNIQUE (Address_ID) ); CREATE TABLE Locations ( Location_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Location_ID) ); CREATE TABLE Products ( Product_ID INTEGER NOT NULL, Product_Type_Code CHAR(15), Product_Name VARCHAR(255), Product_Price DECIMAL(20,4), PRIMARY KEY (Product_ID), UNIQUE (Product_ID) ); CREATE TABLE Parties ( Party_ID INTEGER NOT NULL, Party_Details VARCHAR(255), PRIMARY KEY (Party_ID) ); CREATE TABLE Assets ( Asset_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Asset_ID) ); CREATE TABLE Channels ( Channel_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Channel_ID) ); CREATE TABLE Finances ( Finance_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Finance_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL , Address_ID INTEGER, Channel_ID INTEGER NOT NULL, Event_Type_Code CHAR(15), Finance_ID INTEGER NOT NULL, Location_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID), UNIQUE (Event_ID), FOREIGN KEY (Location_ID) REFERENCES Locations (Location_ID), FOREIGN KEY (Address_ID) REFERENCES Addresses (Address_ID), FOREIGN KEY (Finance_ID) REFERENCES Finances (Finance_ID) ); CREATE TABLE Products_in_Events ( Product_in_Event_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Product_ID INTEGER NOT NULL, PRIMARY KEY (Product_in_Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Product_ID) REFERENCES Products (Product_ID) ); CREATE TABLE Parties_in_Events ( Party_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Role_Code CHAR(15), PRIMARY KEY (Party_ID, Event_ID), FOREIGN KEY (Party_ID) REFERENCES Parties (Party_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Agreements ( Document_ID INTEGER NOT NULL , Event_ID INTEGER NOT NULL, PRIMARY KEY (Document_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Assets_in_Events ( Asset_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, PRIMARY KEY (Asset_ID, Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
What are the names and type codes of products?
SELECT Product_Name , Product_Type_Code FROM Products
1
solvency_ii
CREATE TABLE Addresses ( Address_ID INTEGER NOT NULL , address_details VARCHAR(255), PRIMARY KEY (Address_ID), UNIQUE (Address_ID) ); CREATE TABLE Locations ( Location_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Location_ID) ); CREATE TABLE Products ( Product_ID INTEGER NOT NULL, Product_Type_Code CHAR(15), Product_Name VARCHAR(255), Product_Price DECIMAL(20,4), PRIMARY KEY (Product_ID), UNIQUE (Product_ID) ); CREATE TABLE Parties ( Party_ID INTEGER NOT NULL, Party_Details VARCHAR(255), PRIMARY KEY (Party_ID) ); CREATE TABLE Assets ( Asset_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Asset_ID) ); CREATE TABLE Channels ( Channel_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Channel_ID) ); CREATE TABLE Finances ( Finance_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Finance_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL , Address_ID INTEGER, Channel_ID INTEGER NOT NULL, Event_Type_Code CHAR(15), Finance_ID INTEGER NOT NULL, Location_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID), UNIQUE (Event_ID), FOREIGN KEY (Location_ID) REFERENCES Locations (Location_ID), FOREIGN KEY (Address_ID) REFERENCES Addresses (Address_ID), FOREIGN KEY (Finance_ID) REFERENCES Finances (Finance_ID) ); CREATE TABLE Products_in_Events ( Product_in_Event_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Product_ID INTEGER NOT NULL, PRIMARY KEY (Product_in_Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Product_ID) REFERENCES Products (Product_ID) ); CREATE TABLE Parties_in_Events ( Party_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Role_Code CHAR(15), PRIMARY KEY (Party_ID, Event_ID), FOREIGN KEY (Party_ID) REFERENCES Parties (Party_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Agreements ( Document_ID INTEGER NOT NULL , Event_ID INTEGER NOT NULL, PRIMARY KEY (Document_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Assets_in_Events ( Asset_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, PRIMARY KEY (Asset_ID, Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
Show the prices of the products named "Dining" or "Trading Policy".
SELECT Product_Price FROM Products WHERE Product_Name = "Dining" OR Product_Name = "Trading Policy"
1
solvency_ii
CREATE TABLE Addresses ( Address_ID INTEGER NOT NULL , address_details VARCHAR(255), PRIMARY KEY (Address_ID), UNIQUE (Address_ID) ); CREATE TABLE Locations ( Location_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Location_ID) ); CREATE TABLE Products ( Product_ID INTEGER NOT NULL, Product_Type_Code CHAR(15), Product_Name VARCHAR(255), Product_Price DECIMAL(20,4), PRIMARY KEY (Product_ID), UNIQUE (Product_ID) ); CREATE TABLE Parties ( Party_ID INTEGER NOT NULL, Party_Details VARCHAR(255), PRIMARY KEY (Party_ID) ); CREATE TABLE Assets ( Asset_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Asset_ID) ); CREATE TABLE Channels ( Channel_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Channel_ID) ); CREATE TABLE Finances ( Finance_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Finance_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL , Address_ID INTEGER, Channel_ID INTEGER NOT NULL, Event_Type_Code CHAR(15), Finance_ID INTEGER NOT NULL, Location_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID), UNIQUE (Event_ID), FOREIGN KEY (Location_ID) REFERENCES Locations (Location_ID), FOREIGN KEY (Address_ID) REFERENCES Addresses (Address_ID), FOREIGN KEY (Finance_ID) REFERENCES Finances (Finance_ID) ); CREATE TABLE Products_in_Events ( Product_in_Event_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Product_ID INTEGER NOT NULL, PRIMARY KEY (Product_in_Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Product_ID) REFERENCES Products (Product_ID) ); CREATE TABLE Parties_in_Events ( Party_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Role_Code CHAR(15), PRIMARY KEY (Party_ID, Event_ID), FOREIGN KEY (Party_ID) REFERENCES Parties (Party_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Agreements ( Document_ID INTEGER NOT NULL , Event_ID INTEGER NOT NULL, PRIMARY KEY (Document_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Assets_in_Events ( Asset_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, PRIMARY KEY (Asset_ID, Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
What is the average price for products?
SELECT avg(Product_Price) FROM Products
1
solvency_ii
CREATE TABLE Addresses ( Address_ID INTEGER NOT NULL , address_details VARCHAR(255), PRIMARY KEY (Address_ID), UNIQUE (Address_ID) ); CREATE TABLE Locations ( Location_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Location_ID) ); CREATE TABLE Products ( Product_ID INTEGER NOT NULL, Product_Type_Code CHAR(15), Product_Name VARCHAR(255), Product_Price DECIMAL(20,4), PRIMARY KEY (Product_ID), UNIQUE (Product_ID) ); CREATE TABLE Parties ( Party_ID INTEGER NOT NULL, Party_Details VARCHAR(255), PRIMARY KEY (Party_ID) ); CREATE TABLE Assets ( Asset_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Asset_ID) ); CREATE TABLE Channels ( Channel_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Channel_ID) ); CREATE TABLE Finances ( Finance_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Finance_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL , Address_ID INTEGER, Channel_ID INTEGER NOT NULL, Event_Type_Code CHAR(15), Finance_ID INTEGER NOT NULL, Location_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID), UNIQUE (Event_ID), FOREIGN KEY (Location_ID) REFERENCES Locations (Location_ID), FOREIGN KEY (Address_ID) REFERENCES Addresses (Address_ID), FOREIGN KEY (Finance_ID) REFERENCES Finances (Finance_ID) ); CREATE TABLE Products_in_Events ( Product_in_Event_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Product_ID INTEGER NOT NULL, PRIMARY KEY (Product_in_Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Product_ID) REFERENCES Products (Product_ID) ); CREATE TABLE Parties_in_Events ( Party_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Role_Code CHAR(15), PRIMARY KEY (Party_ID, Event_ID), FOREIGN KEY (Party_ID) REFERENCES Parties (Party_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Agreements ( Document_ID INTEGER NOT NULL , Event_ID INTEGER NOT NULL, PRIMARY KEY (Document_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Assets_in_Events ( Asset_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, PRIMARY KEY (Asset_ID, Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
What is the name of the product with the highest price?
SELECT Product_Name FROM Products ORDER BY Product_Price DESC LIMIT 1
1
solvency_ii
CREATE TABLE Addresses ( Address_ID INTEGER NOT NULL , address_details VARCHAR(255), PRIMARY KEY (Address_ID), UNIQUE (Address_ID) ); CREATE TABLE Locations ( Location_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Location_ID) ); CREATE TABLE Products ( Product_ID INTEGER NOT NULL, Product_Type_Code CHAR(15), Product_Name VARCHAR(255), Product_Price DECIMAL(20,4), PRIMARY KEY (Product_ID), UNIQUE (Product_ID) ); CREATE TABLE Parties ( Party_ID INTEGER NOT NULL, Party_Details VARCHAR(255), PRIMARY KEY (Party_ID) ); CREATE TABLE Assets ( Asset_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Asset_ID) ); CREATE TABLE Channels ( Channel_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Channel_ID) ); CREATE TABLE Finances ( Finance_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Finance_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL , Address_ID INTEGER, Channel_ID INTEGER NOT NULL, Event_Type_Code CHAR(15), Finance_ID INTEGER NOT NULL, Location_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID), UNIQUE (Event_ID), FOREIGN KEY (Location_ID) REFERENCES Locations (Location_ID), FOREIGN KEY (Address_ID) REFERENCES Addresses (Address_ID), FOREIGN KEY (Finance_ID) REFERENCES Finances (Finance_ID) ); CREATE TABLE Products_in_Events ( Product_in_Event_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Product_ID INTEGER NOT NULL, PRIMARY KEY (Product_in_Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Product_ID) REFERENCES Products (Product_ID) ); CREATE TABLE Parties_in_Events ( Party_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Role_Code CHAR(15), PRIMARY KEY (Party_ID, Event_ID), FOREIGN KEY (Party_ID) REFERENCES Parties (Party_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Agreements ( Document_ID INTEGER NOT NULL , Event_ID INTEGER NOT NULL, PRIMARY KEY (Document_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Assets_in_Events ( Asset_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, PRIMARY KEY (Asset_ID, Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
Show different type codes of products and the number of products with each type code.
SELECT Product_Type_Code , COUNT(*) FROM Products GROUP BY Product_Type_Code
1
solvency_ii
CREATE TABLE Addresses ( Address_ID INTEGER NOT NULL , address_details VARCHAR(255), PRIMARY KEY (Address_ID), UNIQUE (Address_ID) ); CREATE TABLE Locations ( Location_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Location_ID) ); CREATE TABLE Products ( Product_ID INTEGER NOT NULL, Product_Type_Code CHAR(15), Product_Name VARCHAR(255), Product_Price DECIMAL(20,4), PRIMARY KEY (Product_ID), UNIQUE (Product_ID) ); CREATE TABLE Parties ( Party_ID INTEGER NOT NULL, Party_Details VARCHAR(255), PRIMARY KEY (Party_ID) ); CREATE TABLE Assets ( Asset_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Asset_ID) ); CREATE TABLE Channels ( Channel_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Channel_ID) ); CREATE TABLE Finances ( Finance_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Finance_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL , Address_ID INTEGER, Channel_ID INTEGER NOT NULL, Event_Type_Code CHAR(15), Finance_ID INTEGER NOT NULL, Location_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID), UNIQUE (Event_ID), FOREIGN KEY (Location_ID) REFERENCES Locations (Location_ID), FOREIGN KEY (Address_ID) REFERENCES Addresses (Address_ID), FOREIGN KEY (Finance_ID) REFERENCES Finances (Finance_ID) ); CREATE TABLE Products_in_Events ( Product_in_Event_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Product_ID INTEGER NOT NULL, PRIMARY KEY (Product_in_Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Product_ID) REFERENCES Products (Product_ID) ); CREATE TABLE Parties_in_Events ( Party_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Role_Code CHAR(15), PRIMARY KEY (Party_ID, Event_ID), FOREIGN KEY (Party_ID) REFERENCES Parties (Party_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Agreements ( Document_ID INTEGER NOT NULL , Event_ID INTEGER NOT NULL, PRIMARY KEY (Document_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Assets_in_Events ( Asset_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, PRIMARY KEY (Asset_ID, Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
Show the most common type code across products.
SELECT Product_Type_Code FROM Products GROUP BY Product_Type_Code ORDER BY COUNT(*) DESC LIMIT 1
1
solvency_ii
CREATE TABLE Addresses ( Address_ID INTEGER NOT NULL , address_details VARCHAR(255), PRIMARY KEY (Address_ID), UNIQUE (Address_ID) ); CREATE TABLE Locations ( Location_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Location_ID) ); CREATE TABLE Products ( Product_ID INTEGER NOT NULL, Product_Type_Code CHAR(15), Product_Name VARCHAR(255), Product_Price DECIMAL(20,4), PRIMARY KEY (Product_ID), UNIQUE (Product_ID) ); CREATE TABLE Parties ( Party_ID INTEGER NOT NULL, Party_Details VARCHAR(255), PRIMARY KEY (Party_ID) ); CREATE TABLE Assets ( Asset_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Asset_ID) ); CREATE TABLE Channels ( Channel_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Channel_ID) ); CREATE TABLE Finances ( Finance_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Finance_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL , Address_ID INTEGER, Channel_ID INTEGER NOT NULL, Event_Type_Code CHAR(15), Finance_ID INTEGER NOT NULL, Location_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID), UNIQUE (Event_ID), FOREIGN KEY (Location_ID) REFERENCES Locations (Location_ID), FOREIGN KEY (Address_ID) REFERENCES Addresses (Address_ID), FOREIGN KEY (Finance_ID) REFERENCES Finances (Finance_ID) ); CREATE TABLE Products_in_Events ( Product_in_Event_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Product_ID INTEGER NOT NULL, PRIMARY KEY (Product_in_Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Product_ID) REFERENCES Products (Product_ID) ); CREATE TABLE Parties_in_Events ( Party_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Role_Code CHAR(15), PRIMARY KEY (Party_ID, Event_ID), FOREIGN KEY (Party_ID) REFERENCES Parties (Party_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Agreements ( Document_ID INTEGER NOT NULL , Event_ID INTEGER NOT NULL, PRIMARY KEY (Document_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Assets_in_Events ( Asset_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, PRIMARY KEY (Asset_ID, Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
Show the product type codes that have at least two products.
SELECT Product_Type_Code FROM Products GROUP BY Product_Type_Code HAVING COUNT(*) >= 2
1
solvency_ii
CREATE TABLE Addresses ( Address_ID INTEGER NOT NULL , address_details VARCHAR(255), PRIMARY KEY (Address_ID), UNIQUE (Address_ID) ); CREATE TABLE Locations ( Location_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Location_ID) ); CREATE TABLE Products ( Product_ID INTEGER NOT NULL, Product_Type_Code CHAR(15), Product_Name VARCHAR(255), Product_Price DECIMAL(20,4), PRIMARY KEY (Product_ID), UNIQUE (Product_ID) ); CREATE TABLE Parties ( Party_ID INTEGER NOT NULL, Party_Details VARCHAR(255), PRIMARY KEY (Party_ID) ); CREATE TABLE Assets ( Asset_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Asset_ID) ); CREATE TABLE Channels ( Channel_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Channel_ID) ); CREATE TABLE Finances ( Finance_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Finance_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL , Address_ID INTEGER, Channel_ID INTEGER NOT NULL, Event_Type_Code CHAR(15), Finance_ID INTEGER NOT NULL, Location_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID), UNIQUE (Event_ID), FOREIGN KEY (Location_ID) REFERENCES Locations (Location_ID), FOREIGN KEY (Address_ID) REFERENCES Addresses (Address_ID), FOREIGN KEY (Finance_ID) REFERENCES Finances (Finance_ID) ); CREATE TABLE Products_in_Events ( Product_in_Event_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Product_ID INTEGER NOT NULL, PRIMARY KEY (Product_in_Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Product_ID) REFERENCES Products (Product_ID) ); CREATE TABLE Parties_in_Events ( Party_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Role_Code CHAR(15), PRIMARY KEY (Party_ID, Event_ID), FOREIGN KEY (Party_ID) REFERENCES Parties (Party_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Agreements ( Document_ID INTEGER NOT NULL , Event_ID INTEGER NOT NULL, PRIMARY KEY (Document_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Assets_in_Events ( Asset_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, PRIMARY KEY (Asset_ID, Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
Show the product type codes that have both products with price higher than 4500 and products with price lower than 3000.
SELECT Product_Type_Code FROM Products WHERE Product_Price > 4500 INTERSECT SELECT Product_Type_Code FROM Products WHERE Product_Price < 3000
1
solvency_ii
CREATE TABLE Addresses ( Address_ID INTEGER NOT NULL , address_details VARCHAR(255), PRIMARY KEY (Address_ID), UNIQUE (Address_ID) ); CREATE TABLE Locations ( Location_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Location_ID) ); CREATE TABLE Products ( Product_ID INTEGER NOT NULL, Product_Type_Code CHAR(15), Product_Name VARCHAR(255), Product_Price DECIMAL(20,4), PRIMARY KEY (Product_ID), UNIQUE (Product_ID) ); CREATE TABLE Parties ( Party_ID INTEGER NOT NULL, Party_Details VARCHAR(255), PRIMARY KEY (Party_ID) ); CREATE TABLE Assets ( Asset_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Asset_ID) ); CREATE TABLE Channels ( Channel_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Channel_ID) ); CREATE TABLE Finances ( Finance_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Finance_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL , Address_ID INTEGER, Channel_ID INTEGER NOT NULL, Event_Type_Code CHAR(15), Finance_ID INTEGER NOT NULL, Location_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID), UNIQUE (Event_ID), FOREIGN KEY (Location_ID) REFERENCES Locations (Location_ID), FOREIGN KEY (Address_ID) REFERENCES Addresses (Address_ID), FOREIGN KEY (Finance_ID) REFERENCES Finances (Finance_ID) ); CREATE TABLE Products_in_Events ( Product_in_Event_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Product_ID INTEGER NOT NULL, PRIMARY KEY (Product_in_Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Product_ID) REFERENCES Products (Product_ID) ); CREATE TABLE Parties_in_Events ( Party_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Role_Code CHAR(15), PRIMARY KEY (Party_ID, Event_ID), FOREIGN KEY (Party_ID) REFERENCES Parties (Party_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Agreements ( Document_ID INTEGER NOT NULL , Event_ID INTEGER NOT NULL, PRIMARY KEY (Document_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Assets_in_Events ( Asset_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, PRIMARY KEY (Asset_ID, Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
Show the names of products and the number of events they are in.
SELECT T1.Product_Name , COUNT(*) FROM Products AS T1 JOIN Products_in_Events AS T2 ON T1.Product_ID = T2.Product_ID GROUP BY T1.Product_Name
1
solvency_ii
CREATE TABLE Addresses ( Address_ID INTEGER NOT NULL , address_details VARCHAR(255), PRIMARY KEY (Address_ID), UNIQUE (Address_ID) ); CREATE TABLE Locations ( Location_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Location_ID) ); CREATE TABLE Products ( Product_ID INTEGER NOT NULL, Product_Type_Code CHAR(15), Product_Name VARCHAR(255), Product_Price DECIMAL(20,4), PRIMARY KEY (Product_ID), UNIQUE (Product_ID) ); CREATE TABLE Parties ( Party_ID INTEGER NOT NULL, Party_Details VARCHAR(255), PRIMARY KEY (Party_ID) ); CREATE TABLE Assets ( Asset_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Asset_ID) ); CREATE TABLE Channels ( Channel_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Channel_ID) ); CREATE TABLE Finances ( Finance_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Finance_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL , Address_ID INTEGER, Channel_ID INTEGER NOT NULL, Event_Type_Code CHAR(15), Finance_ID INTEGER NOT NULL, Location_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID), UNIQUE (Event_ID), FOREIGN KEY (Location_ID) REFERENCES Locations (Location_ID), FOREIGN KEY (Address_ID) REFERENCES Addresses (Address_ID), FOREIGN KEY (Finance_ID) REFERENCES Finances (Finance_ID) ); CREATE TABLE Products_in_Events ( Product_in_Event_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Product_ID INTEGER NOT NULL, PRIMARY KEY (Product_in_Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Product_ID) REFERENCES Products (Product_ID) ); CREATE TABLE Parties_in_Events ( Party_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Role_Code CHAR(15), PRIMARY KEY (Party_ID, Event_ID), FOREIGN KEY (Party_ID) REFERENCES Parties (Party_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Agreements ( Document_ID INTEGER NOT NULL , Event_ID INTEGER NOT NULL, PRIMARY KEY (Document_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Assets_in_Events ( Asset_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, PRIMARY KEY (Asset_ID, Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
Show the names of products and the number of events they are in, sorted by the number of events in descending order.
SELECT T1.Product_Name , COUNT(*) FROM Products AS T1 JOIN Products_in_Events AS T2 ON T1.Product_ID = T2.Product_ID GROUP BY T1.Product_Name ORDER BY COUNT(*) DESC
1
solvency_ii
CREATE TABLE Addresses ( Address_ID INTEGER NOT NULL , address_details VARCHAR(255), PRIMARY KEY (Address_ID), UNIQUE (Address_ID) ); CREATE TABLE Locations ( Location_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Location_ID) ); CREATE TABLE Products ( Product_ID INTEGER NOT NULL, Product_Type_Code CHAR(15), Product_Name VARCHAR(255), Product_Price DECIMAL(20,4), PRIMARY KEY (Product_ID), UNIQUE (Product_ID) ); CREATE TABLE Parties ( Party_ID INTEGER NOT NULL, Party_Details VARCHAR(255), PRIMARY KEY (Party_ID) ); CREATE TABLE Assets ( Asset_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Asset_ID) ); CREATE TABLE Channels ( Channel_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Channel_ID) ); CREATE TABLE Finances ( Finance_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Finance_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL , Address_ID INTEGER, Channel_ID INTEGER NOT NULL, Event_Type_Code CHAR(15), Finance_ID INTEGER NOT NULL, Location_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID), UNIQUE (Event_ID), FOREIGN KEY (Location_ID) REFERENCES Locations (Location_ID), FOREIGN KEY (Address_ID) REFERENCES Addresses (Address_ID), FOREIGN KEY (Finance_ID) REFERENCES Finances (Finance_ID) ); CREATE TABLE Products_in_Events ( Product_in_Event_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Product_ID INTEGER NOT NULL, PRIMARY KEY (Product_in_Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Product_ID) REFERENCES Products (Product_ID) ); CREATE TABLE Parties_in_Events ( Party_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Role_Code CHAR(15), PRIMARY KEY (Party_ID, Event_ID), FOREIGN KEY (Party_ID) REFERENCES Parties (Party_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Agreements ( Document_ID INTEGER NOT NULL , Event_ID INTEGER NOT NULL, PRIMARY KEY (Document_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Assets_in_Events ( Asset_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, PRIMARY KEY (Asset_ID, Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
Show the names of products that are in at least two events.
SELECT T1.Product_Name FROM Products AS T1 JOIN Products_in_Events AS T2 ON T1.Product_ID = T2.Product_ID GROUP BY T1.Product_Name HAVING COUNT(*) >= 2
1
solvency_ii
CREATE TABLE Addresses ( Address_ID INTEGER NOT NULL , address_details VARCHAR(255), PRIMARY KEY (Address_ID), UNIQUE (Address_ID) ); CREATE TABLE Locations ( Location_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Location_ID) ); CREATE TABLE Products ( Product_ID INTEGER NOT NULL, Product_Type_Code CHAR(15), Product_Name VARCHAR(255), Product_Price DECIMAL(20,4), PRIMARY KEY (Product_ID), UNIQUE (Product_ID) ); CREATE TABLE Parties ( Party_ID INTEGER NOT NULL, Party_Details VARCHAR(255), PRIMARY KEY (Party_ID) ); CREATE TABLE Assets ( Asset_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Asset_ID) ); CREATE TABLE Channels ( Channel_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Channel_ID) ); CREATE TABLE Finances ( Finance_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Finance_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL , Address_ID INTEGER, Channel_ID INTEGER NOT NULL, Event_Type_Code CHAR(15), Finance_ID INTEGER NOT NULL, Location_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID), UNIQUE (Event_ID), FOREIGN KEY (Location_ID) REFERENCES Locations (Location_ID), FOREIGN KEY (Address_ID) REFERENCES Addresses (Address_ID), FOREIGN KEY (Finance_ID) REFERENCES Finances (Finance_ID) ); CREATE TABLE Products_in_Events ( Product_in_Event_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Product_ID INTEGER NOT NULL, PRIMARY KEY (Product_in_Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Product_ID) REFERENCES Products (Product_ID) ); CREATE TABLE Parties_in_Events ( Party_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Role_Code CHAR(15), PRIMARY KEY (Party_ID, Event_ID), FOREIGN KEY (Party_ID) REFERENCES Parties (Party_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Agreements ( Document_ID INTEGER NOT NULL , Event_ID INTEGER NOT NULL, PRIMARY KEY (Document_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Assets_in_Events ( Asset_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, PRIMARY KEY (Asset_ID, Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
Show the names of products that are in at least two events in ascending alphabetical order of product name.
SELECT T1.Product_Name FROM Products AS T1 JOIN Products_in_Events AS T2 ON T1.Product_ID = T2.Product_ID GROUP BY T1.Product_Name HAVING COUNT(*) >= 2 ORDER BY T1.Product_Name
1
solvency_ii
CREATE TABLE Addresses ( Address_ID INTEGER NOT NULL , address_details VARCHAR(255), PRIMARY KEY (Address_ID), UNIQUE (Address_ID) ); CREATE TABLE Locations ( Location_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Location_ID) ); CREATE TABLE Products ( Product_ID INTEGER NOT NULL, Product_Type_Code CHAR(15), Product_Name VARCHAR(255), Product_Price DECIMAL(20,4), PRIMARY KEY (Product_ID), UNIQUE (Product_ID) ); CREATE TABLE Parties ( Party_ID INTEGER NOT NULL, Party_Details VARCHAR(255), PRIMARY KEY (Party_ID) ); CREATE TABLE Assets ( Asset_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Asset_ID) ); CREATE TABLE Channels ( Channel_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Channel_ID) ); CREATE TABLE Finances ( Finance_ID INTEGER NOT NULL , Other_Details VARCHAR(255), PRIMARY KEY (Finance_ID) ); CREATE TABLE EVENTS ( Event_ID INTEGER NOT NULL , Address_ID INTEGER, Channel_ID INTEGER NOT NULL, Event_Type_Code CHAR(15), Finance_ID INTEGER NOT NULL, Location_ID INTEGER NOT NULL, PRIMARY KEY (Event_ID), UNIQUE (Event_ID), FOREIGN KEY (Location_ID) REFERENCES Locations (Location_ID), FOREIGN KEY (Address_ID) REFERENCES Addresses (Address_ID), FOREIGN KEY (Finance_ID) REFERENCES Finances (Finance_ID) ); CREATE TABLE Products_in_Events ( Product_in_Event_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Product_ID INTEGER NOT NULL, PRIMARY KEY (Product_in_Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Product_ID) REFERENCES Products (Product_ID) ); CREATE TABLE Parties_in_Events ( Party_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, Role_Code CHAR(15), PRIMARY KEY (Party_ID, Event_ID), FOREIGN KEY (Party_ID) REFERENCES Parties (Party_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Agreements ( Document_ID INTEGER NOT NULL , Event_ID INTEGER NOT NULL, PRIMARY KEY (Document_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) ); CREATE TABLE Assets_in_Events ( Asset_ID INTEGER NOT NULL, Event_ID INTEGER NOT NULL, PRIMARY KEY (Asset_ID, Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID), FOREIGN KEY (Event_ID) REFERENCES EVENTS (Event_ID) )
List the names of products that are not in any event.
SELECT Product_Name FROM Products WHERE Product_ID NOT IN (SELECT Product_ID FROM Products_in_Events)
1
entertainment_awards
CREATE TABLE "festival_detail" ( "Festival_ID" int, "Festival_Name" text, "Chair_Name" text, "Location" text, "Year" int, "Num_of_Audience" int, PRIMARY KEY ("Festival_ID") ); CREATE TABLE artwork ( "Artwork_ID" int, "Type" text, "Name" text, PRIMARY KEY ("Artwork_ID") ); CREATE TABLE nomination ( "Artwork_ID" int, "Festival_ID" int, "Result" text, PRIMARY KEY ("Artwork_ID","Festival_ID"), FOREIGN KEY ("Artwork_ID") REFERENCES `artwork`("Artwork_ID"), FOREIGN KEY ("Festival_ID") REFERENCES `festival_detail`("Festival_ID") )
How many artworks are there?
SELECT count(*) FROM artwork
1
entertainment_awards
CREATE TABLE "festival_detail" ( "Festival_ID" int, "Festival_Name" text, "Chair_Name" text, "Location" text, "Year" int, "Num_of_Audience" int, PRIMARY KEY ("Festival_ID") ); CREATE TABLE artwork ( "Artwork_ID" int, "Type" text, "Name" text, PRIMARY KEY ("Artwork_ID") ); CREATE TABLE nomination ( "Artwork_ID" int, "Festival_ID" int, "Result" text, PRIMARY KEY ("Artwork_ID","Festival_ID"), FOREIGN KEY ("Artwork_ID") REFERENCES `artwork`("Artwork_ID"), FOREIGN KEY ("Festival_ID") REFERENCES `festival_detail`("Festival_ID") )
List the name of artworks in ascending alphabetical order.
SELECT Name FROM artwork ORDER BY Name ASC
1
entertainment_awards
CREATE TABLE "festival_detail" ( "Festival_ID" int, "Festival_Name" text, "Chair_Name" text, "Location" text, "Year" int, "Num_of_Audience" int, PRIMARY KEY ("Festival_ID") ); CREATE TABLE artwork ( "Artwork_ID" int, "Type" text, "Name" text, PRIMARY KEY ("Artwork_ID") ); CREATE TABLE nomination ( "Artwork_ID" int, "Festival_ID" int, "Result" text, PRIMARY KEY ("Artwork_ID","Festival_ID"), FOREIGN KEY ("Artwork_ID") REFERENCES `artwork`("Artwork_ID"), FOREIGN KEY ("Festival_ID") REFERENCES `festival_detail`("Festival_ID") )
List the name of artworks whose type is not "Program Talent Show".
SELECT Name FROM artwork WHERE TYPE != "Program Talent Show"
1
entertainment_awards
CREATE TABLE "festival_detail" ( "Festival_ID" int, "Festival_Name" text, "Chair_Name" text, "Location" text, "Year" int, "Num_of_Audience" int, PRIMARY KEY ("Festival_ID") ); CREATE TABLE artwork ( "Artwork_ID" int, "Type" text, "Name" text, PRIMARY KEY ("Artwork_ID") ); CREATE TABLE nomination ( "Artwork_ID" int, "Festival_ID" int, "Result" text, PRIMARY KEY ("Artwork_ID","Festival_ID"), FOREIGN KEY ("Artwork_ID") REFERENCES `artwork`("Artwork_ID"), FOREIGN KEY ("Festival_ID") REFERENCES `festival_detail`("Festival_ID") )
What are the names and locations of festivals?
SELECT Festival_Name , LOCATION FROM festival_detail
1
entertainment_awards
CREATE TABLE "festival_detail" ( "Festival_ID" int, "Festival_Name" text, "Chair_Name" text, "Location" text, "Year" int, "Num_of_Audience" int, PRIMARY KEY ("Festival_ID") ); CREATE TABLE artwork ( "Artwork_ID" int, "Type" text, "Name" text, PRIMARY KEY ("Artwork_ID") ); CREATE TABLE nomination ( "Artwork_ID" int, "Festival_ID" int, "Result" text, PRIMARY KEY ("Artwork_ID","Festival_ID"), FOREIGN KEY ("Artwork_ID") REFERENCES `artwork`("Artwork_ID"), FOREIGN KEY ("Festival_ID") REFERENCES `festival_detail`("Festival_ID") )
What are the names of the chairs of festivals, sorted in ascending order of the year held?
SELECT Chair_Name FROM festival_detail ORDER BY YEAR ASC
1
entertainment_awards
CREATE TABLE "festival_detail" ( "Festival_ID" int, "Festival_Name" text, "Chair_Name" text, "Location" text, "Year" int, "Num_of_Audience" int, PRIMARY KEY ("Festival_ID") ); CREATE TABLE artwork ( "Artwork_ID" int, "Type" text, "Name" text, PRIMARY KEY ("Artwork_ID") ); CREATE TABLE nomination ( "Artwork_ID" int, "Festival_ID" int, "Result" text, PRIMARY KEY ("Artwork_ID","Festival_ID"), FOREIGN KEY ("Artwork_ID") REFERENCES `artwork`("Artwork_ID"), FOREIGN KEY ("Festival_ID") REFERENCES `festival_detail`("Festival_ID") )
What is the location of the festival with the largest number of audience?
SELECT LOCATION FROM festival_detail ORDER BY Num_of_Audience DESC LIMIT 1
1
entertainment_awards
CREATE TABLE "festival_detail" ( "Festival_ID" int, "Festival_Name" text, "Chair_Name" text, "Location" text, "Year" int, "Num_of_Audience" int, PRIMARY KEY ("Festival_ID") ); CREATE TABLE artwork ( "Artwork_ID" int, "Type" text, "Name" text, PRIMARY KEY ("Artwork_ID") ); CREATE TABLE nomination ( "Artwork_ID" int, "Festival_ID" int, "Result" text, PRIMARY KEY ("Artwork_ID","Festival_ID"), FOREIGN KEY ("Artwork_ID") REFERENCES `artwork`("Artwork_ID"), FOREIGN KEY ("Festival_ID") REFERENCES `festival_detail`("Festival_ID") )
What are the names of festivals held in year 2007?
SELECT Festival_Name FROM festival_detail WHERE YEAR = 2007
1
entertainment_awards
CREATE TABLE "festival_detail" ( "Festival_ID" int, "Festival_Name" text, "Chair_Name" text, "Location" text, "Year" int, "Num_of_Audience" int, PRIMARY KEY ("Festival_ID") ); CREATE TABLE artwork ( "Artwork_ID" int, "Type" text, "Name" text, PRIMARY KEY ("Artwork_ID") ); CREATE TABLE nomination ( "Artwork_ID" int, "Festival_ID" int, "Result" text, PRIMARY KEY ("Artwork_ID","Festival_ID"), FOREIGN KEY ("Artwork_ID") REFERENCES `artwork`("Artwork_ID"), FOREIGN KEY ("Festival_ID") REFERENCES `festival_detail`("Festival_ID") )
What is the average number of audience for festivals?
SELECT avg(Num_of_Audience) FROM festival_detail
1
entertainment_awards
CREATE TABLE "festival_detail" ( "Festival_ID" int, "Festival_Name" text, "Chair_Name" text, "Location" text, "Year" int, "Num_of_Audience" int, PRIMARY KEY ("Festival_ID") ); CREATE TABLE artwork ( "Artwork_ID" int, "Type" text, "Name" text, PRIMARY KEY ("Artwork_ID") ); CREATE TABLE nomination ( "Artwork_ID" int, "Festival_ID" int, "Result" text, PRIMARY KEY ("Artwork_ID","Festival_ID"), FOREIGN KEY ("Artwork_ID") REFERENCES `artwork`("Artwork_ID"), FOREIGN KEY ("Festival_ID") REFERENCES `festival_detail`("Festival_ID") )
Show the names of the three most recent festivals.
SELECT Festival_Name FROM festival_detail ORDER BY YEAR DESC LIMIT 3
1
entertainment_awards
CREATE TABLE "festival_detail" ( "Festival_ID" int, "Festival_Name" text, "Chair_Name" text, "Location" text, "Year" int, "Num_of_Audience" int, PRIMARY KEY ("Festival_ID") ); CREATE TABLE artwork ( "Artwork_ID" int, "Type" text, "Name" text, PRIMARY KEY ("Artwork_ID") ); CREATE TABLE nomination ( "Artwork_ID" int, "Festival_ID" int, "Result" text, PRIMARY KEY ("Artwork_ID","Festival_ID"), FOREIGN KEY ("Artwork_ID") REFERENCES `artwork`("Artwork_ID"), FOREIGN KEY ("Festival_ID") REFERENCES `festival_detail`("Festival_ID") )
For each nomination, show the name of the artwork and name of the festival where it is nominated.
SELECT T2.Name , T3.Festival_Name FROM nomination AS T1 JOIN artwork AS T2 ON T1.Artwork_ID = T2.Artwork_ID JOIN festival_detail AS T3 ON T1.Festival_ID = T3.Festival_ID
1
entertainment_awards
CREATE TABLE "festival_detail" ( "Festival_ID" int, "Festival_Name" text, "Chair_Name" text, "Location" text, "Year" int, "Num_of_Audience" int, PRIMARY KEY ("Festival_ID") ); CREATE TABLE artwork ( "Artwork_ID" int, "Type" text, "Name" text, PRIMARY KEY ("Artwork_ID") ); CREATE TABLE nomination ( "Artwork_ID" int, "Festival_ID" int, "Result" text, PRIMARY KEY ("Artwork_ID","Festival_ID"), FOREIGN KEY ("Artwork_ID") REFERENCES `artwork`("Artwork_ID"), FOREIGN KEY ("Festival_ID") REFERENCES `festival_detail`("Festival_ID") )
Show distinct types of artworks that are nominated in festivals in 2007.
SELECT DISTINCT T2.Type FROM nomination AS T1 JOIN artwork AS T2 ON T1.Artwork_ID = T2.Artwork_ID JOIN festival_detail AS T3 ON T1.Festival_ID = T3.Festival_ID WHERE T3.Year = 2007
1
entertainment_awards
CREATE TABLE "festival_detail" ( "Festival_ID" int, "Festival_Name" text, "Chair_Name" text, "Location" text, "Year" int, "Num_of_Audience" int, PRIMARY KEY ("Festival_ID") ); CREATE TABLE artwork ( "Artwork_ID" int, "Type" text, "Name" text, PRIMARY KEY ("Artwork_ID") ); CREATE TABLE nomination ( "Artwork_ID" int, "Festival_ID" int, "Result" text, PRIMARY KEY ("Artwork_ID","Festival_ID"), FOREIGN KEY ("Artwork_ID") REFERENCES `artwork`("Artwork_ID"), FOREIGN KEY ("Festival_ID") REFERENCES `festival_detail`("Festival_ID") )
Show the names of artworks in ascending order of the year they are nominated in.
SELECT T2.Name FROM nomination AS T1 JOIN artwork AS T2 ON T1.Artwork_ID = T2.Artwork_ID JOIN festival_detail AS T3 ON T1.Festival_ID = T3.Festival_ID ORDER BY T3.Year
1
entertainment_awards
CREATE TABLE "festival_detail" ( "Festival_ID" int, "Festival_Name" text, "Chair_Name" text, "Location" text, "Year" int, "Num_of_Audience" int, PRIMARY KEY ("Festival_ID") ); CREATE TABLE artwork ( "Artwork_ID" int, "Type" text, "Name" text, PRIMARY KEY ("Artwork_ID") ); CREATE TABLE nomination ( "Artwork_ID" int, "Festival_ID" int, "Result" text, PRIMARY KEY ("Artwork_ID","Festival_ID"), FOREIGN KEY ("Artwork_ID") REFERENCES `artwork`("Artwork_ID"), FOREIGN KEY ("Festival_ID") REFERENCES `festival_detail`("Festival_ID") )
Show the names of festivals that have nominated artworks of type "Program Talent Show".
SELECT T3.Festival_Name FROM nomination AS T1 JOIN artwork AS T2 ON T1.Artwork_ID = T2.Artwork_ID JOIN festival_detail AS T3 ON T1.Festival_ID = T3.Festival_ID WHERE T2.Type = "Program Talent Show"
1
entertainment_awards
CREATE TABLE "festival_detail" ( "Festival_ID" int, "Festival_Name" text, "Chair_Name" text, "Location" text, "Year" int, "Num_of_Audience" int, PRIMARY KEY ("Festival_ID") ); CREATE TABLE artwork ( "Artwork_ID" int, "Type" text, "Name" text, PRIMARY KEY ("Artwork_ID") ); CREATE TABLE nomination ( "Artwork_ID" int, "Festival_ID" int, "Result" text, PRIMARY KEY ("Artwork_ID","Festival_ID"), FOREIGN KEY ("Artwork_ID") REFERENCES `artwork`("Artwork_ID"), FOREIGN KEY ("Festival_ID") REFERENCES `festival_detail`("Festival_ID") )
Show the ids and names of festivals that have at least two nominations for artworks.
SELECT T1.Festival_ID , T3.Festival_Name FROM nomination AS T1 JOIN artwork AS T2 ON T1.Artwork_ID = T2.Artwork_ID JOIN festival_detail AS T3 ON T1.Festival_ID = T3.Festival_ID GROUP BY T1.Festival_ID HAVING COUNT(*) >= 2
1
entertainment_awards
CREATE TABLE "festival_detail" ( "Festival_ID" int, "Festival_Name" text, "Chair_Name" text, "Location" text, "Year" int, "Num_of_Audience" int, PRIMARY KEY ("Festival_ID") ); CREATE TABLE artwork ( "Artwork_ID" int, "Type" text, "Name" text, PRIMARY KEY ("Artwork_ID") ); CREATE TABLE nomination ( "Artwork_ID" int, "Festival_ID" int, "Result" text, PRIMARY KEY ("Artwork_ID","Festival_ID"), FOREIGN KEY ("Artwork_ID") REFERENCES `artwork`("Artwork_ID"), FOREIGN KEY ("Festival_ID") REFERENCES `festival_detail`("Festival_ID") )
Show the id, name of each festival and the number of artworks it has nominated.
SELECT T1.Festival_ID , T3.Festival_Name , COUNT(*) FROM nomination AS T1 JOIN artwork AS T2 ON T1.Artwork_ID = T2.Artwork_ID JOIN festival_detail AS T3 ON T1.Festival_ID = T3.Festival_ID GROUP BY T1.Festival_ID
1
entertainment_awards
CREATE TABLE "festival_detail" ( "Festival_ID" int, "Festival_Name" text, "Chair_Name" text, "Location" text, "Year" int, "Num_of_Audience" int, PRIMARY KEY ("Festival_ID") ); CREATE TABLE artwork ( "Artwork_ID" int, "Type" text, "Name" text, PRIMARY KEY ("Artwork_ID") ); CREATE TABLE nomination ( "Artwork_ID" int, "Festival_ID" int, "Result" text, PRIMARY KEY ("Artwork_ID","Festival_ID"), FOREIGN KEY ("Artwork_ID") REFERENCES `artwork`("Artwork_ID"), FOREIGN KEY ("Festival_ID") REFERENCES `festival_detail`("Festival_ID") )
Please show different types of artworks with the corresponding number of artworks of each type.
SELECT TYPE , COUNT(*) FROM artwork GROUP BY TYPE
1
entertainment_awards
CREATE TABLE "festival_detail" ( "Festival_ID" int, "Festival_Name" text, "Chair_Name" text, "Location" text, "Year" int, "Num_of_Audience" int, PRIMARY KEY ("Festival_ID") ); CREATE TABLE artwork ( "Artwork_ID" int, "Type" text, "Name" text, PRIMARY KEY ("Artwork_ID") ); CREATE TABLE nomination ( "Artwork_ID" int, "Festival_ID" int, "Result" text, PRIMARY KEY ("Artwork_ID","Festival_ID"), FOREIGN KEY ("Artwork_ID") REFERENCES `artwork`("Artwork_ID"), FOREIGN KEY ("Festival_ID") REFERENCES `festival_detail`("Festival_ID") )
List the most common type of artworks.
SELECT TYPE FROM artwork GROUP BY TYPE ORDER BY COUNT(*) DESC LIMIT 1
1
entertainment_awards
CREATE TABLE "festival_detail" ( "Festival_ID" int, "Festival_Name" text, "Chair_Name" text, "Location" text, "Year" int, "Num_of_Audience" int, PRIMARY KEY ("Festival_ID") ); CREATE TABLE artwork ( "Artwork_ID" int, "Type" text, "Name" text, PRIMARY KEY ("Artwork_ID") ); CREATE TABLE nomination ( "Artwork_ID" int, "Festival_ID" int, "Result" text, PRIMARY KEY ("Artwork_ID","Festival_ID"), FOREIGN KEY ("Artwork_ID") REFERENCES `artwork`("Artwork_ID"), FOREIGN KEY ("Festival_ID") REFERENCES `festival_detail`("Festival_ID") )
List the year in which there are more than one festivals.
SELECT YEAR FROM festival_detail GROUP BY YEAR HAVING COUNT(*) > 1
1
entertainment_awards
CREATE TABLE "festival_detail" ( "Festival_ID" int, "Festival_Name" text, "Chair_Name" text, "Location" text, "Year" int, "Num_of_Audience" int, PRIMARY KEY ("Festival_ID") ); CREATE TABLE artwork ( "Artwork_ID" int, "Type" text, "Name" text, PRIMARY KEY ("Artwork_ID") ); CREATE TABLE nomination ( "Artwork_ID" int, "Festival_ID" int, "Result" text, PRIMARY KEY ("Artwork_ID","Festival_ID"), FOREIGN KEY ("Artwork_ID") REFERENCES `artwork`("Artwork_ID"), FOREIGN KEY ("Festival_ID") REFERENCES `festival_detail`("Festival_ID") )
List the name of artworks that are not nominated.
SELECT Name FROM Artwork WHERE Artwork_ID NOT IN (SELECT Artwork_ID FROM nomination)
1
entertainment_awards
CREATE TABLE "festival_detail" ( "Festival_ID" int, "Festival_Name" text, "Chair_Name" text, "Location" text, "Year" int, "Num_of_Audience" int, PRIMARY KEY ("Festival_ID") ); CREATE TABLE artwork ( "Artwork_ID" int, "Type" text, "Name" text, PRIMARY KEY ("Artwork_ID") ); CREATE TABLE nomination ( "Artwork_ID" int, "Festival_ID" int, "Result" text, PRIMARY KEY ("Artwork_ID","Festival_ID"), FOREIGN KEY ("Artwork_ID") REFERENCES `artwork`("Artwork_ID"), FOREIGN KEY ("Festival_ID") REFERENCES `festival_detail`("Festival_ID") )
Show the number of audience in year 2008 or 2010.
SELECT Num_of_Audience FROM festival_detail WHERE YEAR = 2008 OR YEAR = 2010
1
entertainment_awards
CREATE TABLE "festival_detail" ( "Festival_ID" int, "Festival_Name" text, "Chair_Name" text, "Location" text, "Year" int, "Num_of_Audience" int, PRIMARY KEY ("Festival_ID") ); CREATE TABLE artwork ( "Artwork_ID" int, "Type" text, "Name" text, PRIMARY KEY ("Artwork_ID") ); CREATE TABLE nomination ( "Artwork_ID" int, "Festival_ID" int, "Result" text, PRIMARY KEY ("Artwork_ID","Festival_ID"), FOREIGN KEY ("Artwork_ID") REFERENCES `artwork`("Artwork_ID"), FOREIGN KEY ("Festival_ID") REFERENCES `festival_detail`("Festival_ID") )
What are the total number of the audiences who visited any of the festivals?
SELECT sum(Num_of_Audience) FROM festival_detail
1
entertainment_awards
CREATE TABLE "festival_detail" ( "Festival_ID" int, "Festival_Name" text, "Chair_Name" text, "Location" text, "Year" int, "Num_of_Audience" int, PRIMARY KEY ("Festival_ID") ); CREATE TABLE artwork ( "Artwork_ID" int, "Type" text, "Name" text, PRIMARY KEY ("Artwork_ID") ); CREATE TABLE nomination ( "Artwork_ID" int, "Festival_ID" int, "Result" text, PRIMARY KEY ("Artwork_ID","Festival_ID"), FOREIGN KEY ("Artwork_ID") REFERENCES `artwork`("Artwork_ID"), FOREIGN KEY ("Festival_ID") REFERENCES `festival_detail`("Festival_ID") )
In which year are there festivals both inside the 'United States' and outside the 'United States'?
SELECT YEAR FROM festival_detail WHERE LOCATION = 'United States' INTERSECT SELECT YEAR FROM festival_detail WHERE LOCATION != 'United States'
1
customers_campaigns_ecommerce
CREATE TABLE `Premises` ( `premise_id` INTEGER PRIMARY KEY, `premises_type` VARCHAR(15) NOT NULL, `premise_details` VARCHAR(255) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15) NOT NULL, `product_name` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `customer_address` VARCHAR(255), `customer_login` VARCHAR(80), `customer_password` VARCHAR(10) ); CREATE TABLE `Mailshot_Campaigns` ( `mailshot_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15), `mailshot_name` VARCHAR(80), `mailshot_start_date` DATETIME, `mailshot_end_date` DATETIME ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `premise_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`premise_id` ) REFERENCES `Premises`(`premise_id` ) FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(15) NOT NULL, `shipping_method_code` VARCHAR(15) NOT NULL, `order_placed_datetime` DATETIME NOT NULL, `order_delivered_datetime` DATETIME, `order_shipping_charges` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Mailshot_Customers` ( `mailshot_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `outcome_code` VARCHAR(15) NOT NULL, `mailshot_customer_date` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`mailshot_id` ) REFERENCES `Mailshot_Campaigns`(`mailshot_id` ) ); CREATE TABLE `Order_Items` ( `item_id` INTEGER NOT NULL , `order_item_status_code` VARCHAR(15) NOT NULL, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `item_status_code` VARCHAR(15), `item_delivered_datetime` DATETIME, `item_order_quantity` VARCHAR(80), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) )
How many premises are there?
SELECT count(*) FROM premises
1
customers_campaigns_ecommerce
CREATE TABLE `Premises` ( `premise_id` INTEGER PRIMARY KEY, `premises_type` VARCHAR(15) NOT NULL, `premise_details` VARCHAR(255) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15) NOT NULL, `product_name` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `customer_address` VARCHAR(255), `customer_login` VARCHAR(80), `customer_password` VARCHAR(10) ); CREATE TABLE `Mailshot_Campaigns` ( `mailshot_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15), `mailshot_name` VARCHAR(80), `mailshot_start_date` DATETIME, `mailshot_end_date` DATETIME ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `premise_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`premise_id` ) REFERENCES `Premises`(`premise_id` ) FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(15) NOT NULL, `shipping_method_code` VARCHAR(15) NOT NULL, `order_placed_datetime` DATETIME NOT NULL, `order_delivered_datetime` DATETIME, `order_shipping_charges` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Mailshot_Customers` ( `mailshot_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `outcome_code` VARCHAR(15) NOT NULL, `mailshot_customer_date` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`mailshot_id` ) REFERENCES `Mailshot_Campaigns`(`mailshot_id` ) ); CREATE TABLE `Order_Items` ( `item_id` INTEGER NOT NULL , `order_item_status_code` VARCHAR(15) NOT NULL, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `item_status_code` VARCHAR(15), `item_delivered_datetime` DATETIME, `item_order_quantity` VARCHAR(80), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) )
What are all the distinct premise types?
SELECT DISTINCT premises_type FROM premises
1
customers_campaigns_ecommerce
CREATE TABLE `Premises` ( `premise_id` INTEGER PRIMARY KEY, `premises_type` VARCHAR(15) NOT NULL, `premise_details` VARCHAR(255) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15) NOT NULL, `product_name` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `customer_address` VARCHAR(255), `customer_login` VARCHAR(80), `customer_password` VARCHAR(10) ); CREATE TABLE `Mailshot_Campaigns` ( `mailshot_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15), `mailshot_name` VARCHAR(80), `mailshot_start_date` DATETIME, `mailshot_end_date` DATETIME ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `premise_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`premise_id` ) REFERENCES `Premises`(`premise_id` ) FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(15) NOT NULL, `shipping_method_code` VARCHAR(15) NOT NULL, `order_placed_datetime` DATETIME NOT NULL, `order_delivered_datetime` DATETIME, `order_shipping_charges` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Mailshot_Customers` ( `mailshot_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `outcome_code` VARCHAR(15) NOT NULL, `mailshot_customer_date` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`mailshot_id` ) REFERENCES `Mailshot_Campaigns`(`mailshot_id` ) ); CREATE TABLE `Order_Items` ( `item_id` INTEGER NOT NULL , `order_item_status_code` VARCHAR(15) NOT NULL, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `item_status_code` VARCHAR(15), `item_delivered_datetime` DATETIME, `item_order_quantity` VARCHAR(80), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) )
Find the types and details for all premises and order by the premise type.
SELECT premises_type , premise_details FROM premises ORDER BY premises_type
1
customers_campaigns_ecommerce
CREATE TABLE `Premises` ( `premise_id` INTEGER PRIMARY KEY, `premises_type` VARCHAR(15) NOT NULL, `premise_details` VARCHAR(255) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15) NOT NULL, `product_name` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `customer_address` VARCHAR(255), `customer_login` VARCHAR(80), `customer_password` VARCHAR(10) ); CREATE TABLE `Mailshot_Campaigns` ( `mailshot_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15), `mailshot_name` VARCHAR(80), `mailshot_start_date` DATETIME, `mailshot_end_date` DATETIME ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `premise_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`premise_id` ) REFERENCES `Premises`(`premise_id` ) FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(15) NOT NULL, `shipping_method_code` VARCHAR(15) NOT NULL, `order_placed_datetime` DATETIME NOT NULL, `order_delivered_datetime` DATETIME, `order_shipping_charges` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Mailshot_Customers` ( `mailshot_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `outcome_code` VARCHAR(15) NOT NULL, `mailshot_customer_date` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`mailshot_id` ) REFERENCES `Mailshot_Campaigns`(`mailshot_id` ) ); CREATE TABLE `Order_Items` ( `item_id` INTEGER NOT NULL , `order_item_status_code` VARCHAR(15) NOT NULL, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `item_status_code` VARCHAR(15), `item_delivered_datetime` DATETIME, `item_order_quantity` VARCHAR(80), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) )
Show each premise type and the number of premises in that type.
SELECT premises_type , count(*) FROM premises GROUP BY premises_type
1
customers_campaigns_ecommerce
CREATE TABLE `Premises` ( `premise_id` INTEGER PRIMARY KEY, `premises_type` VARCHAR(15) NOT NULL, `premise_details` VARCHAR(255) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15) NOT NULL, `product_name` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `customer_address` VARCHAR(255), `customer_login` VARCHAR(80), `customer_password` VARCHAR(10) ); CREATE TABLE `Mailshot_Campaigns` ( `mailshot_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15), `mailshot_name` VARCHAR(80), `mailshot_start_date` DATETIME, `mailshot_end_date` DATETIME ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `premise_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`premise_id` ) REFERENCES `Premises`(`premise_id` ) FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(15) NOT NULL, `shipping_method_code` VARCHAR(15) NOT NULL, `order_placed_datetime` DATETIME NOT NULL, `order_delivered_datetime` DATETIME, `order_shipping_charges` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Mailshot_Customers` ( `mailshot_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `outcome_code` VARCHAR(15) NOT NULL, `mailshot_customer_date` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`mailshot_id` ) REFERENCES `Mailshot_Campaigns`(`mailshot_id` ) ); CREATE TABLE `Order_Items` ( `item_id` INTEGER NOT NULL , `order_item_status_code` VARCHAR(15) NOT NULL, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `item_status_code` VARCHAR(15), `item_delivered_datetime` DATETIME, `item_order_quantity` VARCHAR(80), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) )
Show all distinct product categories along with the number of mailshots in each category.
SELECT product_category , count(*) FROM mailshot_campaigns GROUP BY product_category
1
customers_campaigns_ecommerce
CREATE TABLE `Premises` ( `premise_id` INTEGER PRIMARY KEY, `premises_type` VARCHAR(15) NOT NULL, `premise_details` VARCHAR(255) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15) NOT NULL, `product_name` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `customer_address` VARCHAR(255), `customer_login` VARCHAR(80), `customer_password` VARCHAR(10) ); CREATE TABLE `Mailshot_Campaigns` ( `mailshot_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15), `mailshot_name` VARCHAR(80), `mailshot_start_date` DATETIME, `mailshot_end_date` DATETIME ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `premise_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`premise_id` ) REFERENCES `Premises`(`premise_id` ) FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(15) NOT NULL, `shipping_method_code` VARCHAR(15) NOT NULL, `order_placed_datetime` DATETIME NOT NULL, `order_delivered_datetime` DATETIME, `order_shipping_charges` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Mailshot_Customers` ( `mailshot_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `outcome_code` VARCHAR(15) NOT NULL, `mailshot_customer_date` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`mailshot_id` ) REFERENCES `Mailshot_Campaigns`(`mailshot_id` ) ); CREATE TABLE `Order_Items` ( `item_id` INTEGER NOT NULL , `order_item_status_code` VARCHAR(15) NOT NULL, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `item_status_code` VARCHAR(15), `item_delivered_datetime` DATETIME, `item_order_quantity` VARCHAR(80), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) )
Show the name and phone of the customer without any mailshot.
SELECT customer_name , customer_phone FROM customers WHERE customer_id NOT IN (SELECT customer_id FROM mailshot_customers)
1
customers_campaigns_ecommerce
CREATE TABLE `Premises` ( `premise_id` INTEGER PRIMARY KEY, `premises_type` VARCHAR(15) NOT NULL, `premise_details` VARCHAR(255) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15) NOT NULL, `product_name` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `customer_address` VARCHAR(255), `customer_login` VARCHAR(80), `customer_password` VARCHAR(10) ); CREATE TABLE `Mailshot_Campaigns` ( `mailshot_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15), `mailshot_name` VARCHAR(80), `mailshot_start_date` DATETIME, `mailshot_end_date` DATETIME ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `premise_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`premise_id` ) REFERENCES `Premises`(`premise_id` ) FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(15) NOT NULL, `shipping_method_code` VARCHAR(15) NOT NULL, `order_placed_datetime` DATETIME NOT NULL, `order_delivered_datetime` DATETIME, `order_shipping_charges` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Mailshot_Customers` ( `mailshot_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `outcome_code` VARCHAR(15) NOT NULL, `mailshot_customer_date` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`mailshot_id` ) REFERENCES `Mailshot_Campaigns`(`mailshot_id` ) ); CREATE TABLE `Order_Items` ( `item_id` INTEGER NOT NULL , `order_item_status_code` VARCHAR(15) NOT NULL, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `item_status_code` VARCHAR(15), `item_delivered_datetime` DATETIME, `item_order_quantity` VARCHAR(80), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) )
Show the name and phone for customers with a mailshot with outcome code 'No Response'.
SELECT T1.customer_name , T1.customer_phone FROM customers AS T1 JOIN mailshot_customers AS T2 ON T1.customer_id = T2.customer_id WHERE T2.outcome_code = 'No Response'
1
customers_campaigns_ecommerce
CREATE TABLE `Premises` ( `premise_id` INTEGER PRIMARY KEY, `premises_type` VARCHAR(15) NOT NULL, `premise_details` VARCHAR(255) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15) NOT NULL, `product_name` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `customer_address` VARCHAR(255), `customer_login` VARCHAR(80), `customer_password` VARCHAR(10) ); CREATE TABLE `Mailshot_Campaigns` ( `mailshot_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15), `mailshot_name` VARCHAR(80), `mailshot_start_date` DATETIME, `mailshot_end_date` DATETIME ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `premise_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`premise_id` ) REFERENCES `Premises`(`premise_id` ) FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(15) NOT NULL, `shipping_method_code` VARCHAR(15) NOT NULL, `order_placed_datetime` DATETIME NOT NULL, `order_delivered_datetime` DATETIME, `order_shipping_charges` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Mailshot_Customers` ( `mailshot_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `outcome_code` VARCHAR(15) NOT NULL, `mailshot_customer_date` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`mailshot_id` ) REFERENCES `Mailshot_Campaigns`(`mailshot_id` ) ); CREATE TABLE `Order_Items` ( `item_id` INTEGER NOT NULL , `order_item_status_code` VARCHAR(15) NOT NULL, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `item_status_code` VARCHAR(15), `item_delivered_datetime` DATETIME, `item_order_quantity` VARCHAR(80), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) )
Show the outcome code of mailshots along with the number of mailshots in each outcome code.
SELECT outcome_code , count(*) FROM mailshot_customers GROUP BY outcome_code
1
customers_campaigns_ecommerce
CREATE TABLE `Premises` ( `premise_id` INTEGER PRIMARY KEY, `premises_type` VARCHAR(15) NOT NULL, `premise_details` VARCHAR(255) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15) NOT NULL, `product_name` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `customer_address` VARCHAR(255), `customer_login` VARCHAR(80), `customer_password` VARCHAR(10) ); CREATE TABLE `Mailshot_Campaigns` ( `mailshot_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15), `mailshot_name` VARCHAR(80), `mailshot_start_date` DATETIME, `mailshot_end_date` DATETIME ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `premise_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`premise_id` ) REFERENCES `Premises`(`premise_id` ) FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(15) NOT NULL, `shipping_method_code` VARCHAR(15) NOT NULL, `order_placed_datetime` DATETIME NOT NULL, `order_delivered_datetime` DATETIME, `order_shipping_charges` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Mailshot_Customers` ( `mailshot_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `outcome_code` VARCHAR(15) NOT NULL, `mailshot_customer_date` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`mailshot_id` ) REFERENCES `Mailshot_Campaigns`(`mailshot_id` ) ); CREATE TABLE `Order_Items` ( `item_id` INTEGER NOT NULL , `order_item_status_code` VARCHAR(15) NOT NULL, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `item_status_code` VARCHAR(15), `item_delivered_datetime` DATETIME, `item_order_quantity` VARCHAR(80), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) )
Show the names of customers who have at least 2 mailshots with outcome code 'Order'.
SELECT T2.customer_name FROM mailshot_customers AS T1 JOIN customers AS T2 ON T1.customer_id = T2.customer_id WHERE outcome_code = 'Order' GROUP BY T1.customer_id HAVING count(*) >= 2
1
customers_campaigns_ecommerce
CREATE TABLE `Premises` ( `premise_id` INTEGER PRIMARY KEY, `premises_type` VARCHAR(15) NOT NULL, `premise_details` VARCHAR(255) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15) NOT NULL, `product_name` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `customer_address` VARCHAR(255), `customer_login` VARCHAR(80), `customer_password` VARCHAR(10) ); CREATE TABLE `Mailshot_Campaigns` ( `mailshot_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15), `mailshot_name` VARCHAR(80), `mailshot_start_date` DATETIME, `mailshot_end_date` DATETIME ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `premise_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`premise_id` ) REFERENCES `Premises`(`premise_id` ) FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(15) NOT NULL, `shipping_method_code` VARCHAR(15) NOT NULL, `order_placed_datetime` DATETIME NOT NULL, `order_delivered_datetime` DATETIME, `order_shipping_charges` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Mailshot_Customers` ( `mailshot_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `outcome_code` VARCHAR(15) NOT NULL, `mailshot_customer_date` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`mailshot_id` ) REFERENCES `Mailshot_Campaigns`(`mailshot_id` ) ); CREATE TABLE `Order_Items` ( `item_id` INTEGER NOT NULL , `order_item_status_code` VARCHAR(15) NOT NULL, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `item_status_code` VARCHAR(15), `item_delivered_datetime` DATETIME, `item_order_quantity` VARCHAR(80), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) )
Show the names of customers who have the most mailshots.
SELECT T2.customer_name FROM mailshot_customers AS T1 JOIN customers AS T2 ON T1.customer_id = T2.customer_id GROUP BY T1.customer_id ORDER BY count(*) DESC LIMIT 1
1
customers_campaigns_ecommerce
CREATE TABLE `Premises` ( `premise_id` INTEGER PRIMARY KEY, `premises_type` VARCHAR(15) NOT NULL, `premise_details` VARCHAR(255) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15) NOT NULL, `product_name` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `customer_address` VARCHAR(255), `customer_login` VARCHAR(80), `customer_password` VARCHAR(10) ); CREATE TABLE `Mailshot_Campaigns` ( `mailshot_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15), `mailshot_name` VARCHAR(80), `mailshot_start_date` DATETIME, `mailshot_end_date` DATETIME ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `premise_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`premise_id` ) REFERENCES `Premises`(`premise_id` ) FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(15) NOT NULL, `shipping_method_code` VARCHAR(15) NOT NULL, `order_placed_datetime` DATETIME NOT NULL, `order_delivered_datetime` DATETIME, `order_shipping_charges` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Mailshot_Customers` ( `mailshot_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `outcome_code` VARCHAR(15) NOT NULL, `mailshot_customer_date` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`mailshot_id` ) REFERENCES `Mailshot_Campaigns`(`mailshot_id` ) ); CREATE TABLE `Order_Items` ( `item_id` INTEGER NOT NULL , `order_item_status_code` VARCHAR(15) NOT NULL, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `item_status_code` VARCHAR(15), `item_delivered_datetime` DATETIME, `item_order_quantity` VARCHAR(80), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) )
What are the name and payment method of customers who have both mailshots in 'Order' outcome and mailshots in 'No Response' outcome.
SELECT T2.customer_name , T2.payment_method FROM mailshot_customers AS T1 JOIN customers AS T2 ON T1.customer_id = T2.customer_id WHERE T1.outcome_code = 'Order' INTERSECT SELECT T2.customer_name , T2.payment_method FROM mailshot_customers AS T1 JOIN customers AS T2 ON T1.customer_id = T2.customer_id WHERE T1.outcome_code = 'No Response'
1
customers_campaigns_ecommerce
CREATE TABLE `Premises` ( `premise_id` INTEGER PRIMARY KEY, `premises_type` VARCHAR(15) NOT NULL, `premise_details` VARCHAR(255) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15) NOT NULL, `product_name` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `customer_address` VARCHAR(255), `customer_login` VARCHAR(80), `customer_password` VARCHAR(10) ); CREATE TABLE `Mailshot_Campaigns` ( `mailshot_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15), `mailshot_name` VARCHAR(80), `mailshot_start_date` DATETIME, `mailshot_end_date` DATETIME ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `premise_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`premise_id` ) REFERENCES `Premises`(`premise_id` ) FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(15) NOT NULL, `shipping_method_code` VARCHAR(15) NOT NULL, `order_placed_datetime` DATETIME NOT NULL, `order_delivered_datetime` DATETIME, `order_shipping_charges` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Mailshot_Customers` ( `mailshot_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `outcome_code` VARCHAR(15) NOT NULL, `mailshot_customer_date` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`mailshot_id` ) REFERENCES `Mailshot_Campaigns`(`mailshot_id` ) ); CREATE TABLE `Order_Items` ( `item_id` INTEGER NOT NULL , `order_item_status_code` VARCHAR(15) NOT NULL, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `item_status_code` VARCHAR(15), `item_delivered_datetime` DATETIME, `item_order_quantity` VARCHAR(80), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) )
Show the premise type and address type code for all customer addresses.
SELECT T2.premises_type , T1.address_type_code FROM customer_addresses AS T1 JOIN premises AS T2 ON T1.premise_id = T2.premise_id
1
customers_campaigns_ecommerce
CREATE TABLE `Premises` ( `premise_id` INTEGER PRIMARY KEY, `premises_type` VARCHAR(15) NOT NULL, `premise_details` VARCHAR(255) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15) NOT NULL, `product_name` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `customer_address` VARCHAR(255), `customer_login` VARCHAR(80), `customer_password` VARCHAR(10) ); CREATE TABLE `Mailshot_Campaigns` ( `mailshot_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15), `mailshot_name` VARCHAR(80), `mailshot_start_date` DATETIME, `mailshot_end_date` DATETIME ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `premise_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`premise_id` ) REFERENCES `Premises`(`premise_id` ) FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(15) NOT NULL, `shipping_method_code` VARCHAR(15) NOT NULL, `order_placed_datetime` DATETIME NOT NULL, `order_delivered_datetime` DATETIME, `order_shipping_charges` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Mailshot_Customers` ( `mailshot_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `outcome_code` VARCHAR(15) NOT NULL, `mailshot_customer_date` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`mailshot_id` ) REFERENCES `Mailshot_Campaigns`(`mailshot_id` ) ); CREATE TABLE `Order_Items` ( `item_id` INTEGER NOT NULL , `order_item_status_code` VARCHAR(15) NOT NULL, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `item_status_code` VARCHAR(15), `item_delivered_datetime` DATETIME, `item_order_quantity` VARCHAR(80), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) )
What are the distinct address type codes for all customer addresses?
SELECT DISTINCT address_type_code FROM customer_addresses
1
customers_campaigns_ecommerce
CREATE TABLE `Premises` ( `premise_id` INTEGER PRIMARY KEY, `premises_type` VARCHAR(15) NOT NULL, `premise_details` VARCHAR(255) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15) NOT NULL, `product_name` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `customer_address` VARCHAR(255), `customer_login` VARCHAR(80), `customer_password` VARCHAR(10) ); CREATE TABLE `Mailshot_Campaigns` ( `mailshot_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15), `mailshot_name` VARCHAR(80), `mailshot_start_date` DATETIME, `mailshot_end_date` DATETIME ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `premise_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`premise_id` ) REFERENCES `Premises`(`premise_id` ) FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(15) NOT NULL, `shipping_method_code` VARCHAR(15) NOT NULL, `order_placed_datetime` DATETIME NOT NULL, `order_delivered_datetime` DATETIME, `order_shipping_charges` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Mailshot_Customers` ( `mailshot_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `outcome_code` VARCHAR(15) NOT NULL, `mailshot_customer_date` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`mailshot_id` ) REFERENCES `Mailshot_Campaigns`(`mailshot_id` ) ); CREATE TABLE `Order_Items` ( `item_id` INTEGER NOT NULL , `order_item_status_code` VARCHAR(15) NOT NULL, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `item_status_code` VARCHAR(15), `item_delivered_datetime` DATETIME, `item_order_quantity` VARCHAR(80), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) )
Show the shipping charge and customer id for customer orders with order status Cancelled or Paid.
SELECT order_shipping_charges , customer_id FROM customer_orders WHERE order_status_code = 'Cancelled' OR order_status_code = 'Paid'
1
customers_campaigns_ecommerce
CREATE TABLE `Premises` ( `premise_id` INTEGER PRIMARY KEY, `premises_type` VARCHAR(15) NOT NULL, `premise_details` VARCHAR(255) ); CREATE TABLE `Products` ( `product_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15) NOT NULL, `product_name` VARCHAR(80) ); CREATE TABLE `Customers` ( `customer_id` INTEGER PRIMARY KEY, `payment_method` VARCHAR(15) NOT NULL, `customer_name` VARCHAR(80), `customer_phone` VARCHAR(80), `customer_email` VARCHAR(80), `customer_address` VARCHAR(255), `customer_login` VARCHAR(80), `customer_password` VARCHAR(10) ); CREATE TABLE `Mailshot_Campaigns` ( `mailshot_id` INTEGER PRIMARY KEY, `product_category` VARCHAR(15), `mailshot_name` VARCHAR(80), `mailshot_start_date` DATETIME, `mailshot_end_date` DATETIME ); CREATE TABLE `Customer_Addresses` ( `customer_id` INTEGER NOT NULL, `premise_id` INTEGER NOT NULL, `date_address_from` DATETIME NOT NULL, `address_type_code` VARCHAR(15) NOT NULL, `date_address_to` DATETIME, FOREIGN KEY (`premise_id` ) REFERENCES `Premises`(`premise_id` ) FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Customer_Orders` ( `order_id` INTEGER PRIMARY KEY, `customer_id` INTEGER NOT NULL, `order_status_code` VARCHAR(15) NOT NULL, `shipping_method_code` VARCHAR(15) NOT NULL, `order_placed_datetime` DATETIME NOT NULL, `order_delivered_datetime` DATETIME, `order_shipping_charges` VARCHAR(255), FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ) ); CREATE TABLE `Mailshot_Customers` ( `mailshot_id` INTEGER NOT NULL, `customer_id` INTEGER NOT NULL, `outcome_code` VARCHAR(15) NOT NULL, `mailshot_customer_date` DATETIME, FOREIGN KEY (`customer_id` ) REFERENCES `Customers`(`customer_id` ), FOREIGN KEY (`mailshot_id` ) REFERENCES `Mailshot_Campaigns`(`mailshot_id` ) ); CREATE TABLE `Order_Items` ( `item_id` INTEGER NOT NULL , `order_item_status_code` VARCHAR(15) NOT NULL, `order_id` INTEGER NOT NULL, `product_id` INTEGER NOT NULL, `item_status_code` VARCHAR(15), `item_delivered_datetime` DATETIME, `item_order_quantity` VARCHAR(80), FOREIGN KEY (`product_id` ) REFERENCES `Products`(`product_id` ), FOREIGN KEY (`order_id` ) REFERENCES `Customer_Orders`(`order_id` ) )
Show the names of customers having an order with shipping method FedEx and order status Paid.
SELECT T1.customer_name FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id WHERE shipping_method_code = 'FedEx' AND order_status_code = 'Paid'
1
college_3
How many courses are there in total?
SELECT count(*) FROM COURSE
1
college_3
Count the number of courses.
SELECT count(*) FROM COURSE
1
college_3
How many courses have more than 2 credits?
SELECT count(*) FROM COURSE WHERE Credits > 2
1
college_3
Count the number of courses with more than 2 credits.
SELECT count(*) FROM COURSE WHERE Credits > 2
1
college_3
List all names of courses with 1 credit?
SELECT CName FROM COURSE WHERE Credits = 1
1
college_3
What are the names of courses with 1 credit?
SELECT CName FROM COURSE WHERE Credits = 1
1
college_3
Which courses are taught on days MTW?
SELECT CName FROM COURSE WHERE Days = "MTW"
1
college_3
What are the course names for courses taught on MTW?
SELECT CName FROM COURSE WHERE Days = "MTW"
1
college_3
What is the number of departments in Division "AS"?
SELECT count(*) FROM DEPARTMENT WHERE Division = "AS"
1
college_3
How many departments are in the division AS?
SELECT count(*) FROM DEPARTMENT WHERE Division = "AS"
1
college_3
What are the phones of departments in Room 268?
SELECT DPhone FROM DEPARTMENT WHERE Room = 268
1
college_3
Give the phones for departments in room 268.
SELECT DPhone FROM DEPARTMENT WHERE Room = 268
1
college_3
Find the number of students that have at least one grade "B".
SELECT COUNT(DISTINCT StuID) FROM ENROLLED_IN WHERE Grade = "B"
1
college_3
How many students have had at least one "B" grade?
SELECT COUNT(DISTINCT StuID) FROM ENROLLED_IN WHERE Grade = "B"
1
college_3
Find the max and min grade point for all letter grade.
SELECT max(gradepoint) , min(gradepoint) FROM GRADECONVERSION
1
college_3
What are the maximum and minumum grade points?
SELECT max(gradepoint) , min(gradepoint) FROM GRADECONVERSION
1
college_3
Find the first names of students whose first names contain letter "a".
SELECT DISTINCT Fname FROM STUDENT WHERE Fname LIKE '%a%'
1
college_3
What are the first names for students who have an "a" in their first name?
SELECT DISTINCT Fname FROM STUDENT WHERE Fname LIKE '%a%'