instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the maximum investment in renewable energy in Africa? | CREATE TABLE investments (id INT,country VARCHAR(50),sector VARCHAR(50),amount FLOAT); INSERT INTO investments (id,country,sector,amount) VALUES (1,'Egypt','Renewable Energy',800000),(2,'Morocco','Renewable Energy',900000),(3,'Tunisia','Renewable Energy',700000); | SELECT MAX(amount) as max_investment FROM investments WHERE sector = 'Renewable Energy' AND country IN ('Egypt', 'Morocco', 'Tunisia'); |
What is the average cost of green infrastructure projects in 'British Columbia' and 'Manitoba'? | CREATE TABLE Infrastructure_Projects (id INT,name VARCHAR(100),province VARCHAR(50),type VARCHAR(50),cost FLOAT); INSERT INTO Infrastructure_Projects (id,name,province,type,cost) VALUES (1,'Green Roof Installation','British Columbia','Green Infrastructure',200000); INSERT INTO Infrastructure_Projects (id,name,province,type,cost) VALUES (2,'Solar Panel Installation','Manitoba','Green Infrastructure',500000); | SELECT AVG(cost) FROM Infrastructure_Projects WHERE province IN ('British Columbia', 'Manitoba') AND type = 'Green Infrastructure'; |
Find the minimum price of 'Fair Trade' products in the 'Products' table | CREATE TABLE Products (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255),price DECIMAL(5,2),fair_trade BOOLEAN); INSERT INTO Products (id,name,type,price,fair_trade) VALUES (1,'Coffee','Organic',8.99,true),(2,'Chocolate','Organic',5.99,false),(3,'Tea','Fair Trade',4.99,true); | SELECT MIN(price) FROM Products WHERE fair_trade = true; |
Which defense projects had the highest average equipment sale price per unit? | CREATE SCHEMA IF NOT EXISTS defense_contractors;CREATE TABLE IF NOT EXISTS defense_projects (project_id INT,project_name VARCHAR(255),equipment_sale_price DECIMAL(10,2),unit_sold INT);INSERT INTO defense_projects (project_id,project_name,equipment_sale_price,unit_sold) VALUES (1,'Project_A',1500000,10),(2,'Project_B',2000000,5),(3,'Project_C',1200000,8); | SELECT project_name, AVG(equipment_sale_price / unit_sold) AS avg_price_per_unit FROM defense_projects GROUP BY project_name ORDER BY avg_price_per_unit DESC; |
Insert a new smart city project called 'EcoCity' into the 'smart_cities' table | CREATE TABLE smart_cities (id INT PRIMARY KEY,city_name VARCHAR(100),initiative VARCHAR(50)); | INSERT INTO smart_cities (city_name, initiative) VALUES ('EcoCity', 'smart city'); |
What is the total number of broadband subscribers in the 'rural' regions for each state? | CREATE TABLE states (id INT,name VARCHAR(255),region VARCHAR(255));CREATE TABLE subscribers (id INT,state_id INT,subscriber_type VARCHAR(255)); | SELECT s.name, COUNT(sub.id) as total_rural_subscribers FROM states s INNER JOIN subscribers sub ON s.id = sub.state_id WHERE subscriber_type = 'broadband' AND s.region = 'rural' GROUP BY s.name; |
What is the minimum investment amount in water infrastructure in Africa in 2018? | CREATE TABLE if not exists investments (investment_id INT,region VARCHAR(50),sector VARCHAR(50),amount DECIMAL(10,2),investment_year INT); INSERT INTO investments (investment_id,region,sector,amount,investment_year) VALUES (1,'Africa','Water Infrastructure',400000,2018); | SELECT MIN(amount) FROM investments WHERE region = 'Africa' AND sector = 'Water Infrastructure' AND investment_year = 2018; |
How many food safety violations occurred in each restaurant in 2021? | CREATE TABLE inspections (restaurant_name TEXT,violation_count INTEGER,inspection_date DATE); INSERT INTO inspections (restaurant_name,violation_count,inspection_date) VALUES ('ABC Bistro',2,'2021-04-01'),('ABC Bistro',1,'2021-07-01'),('XYZ Café',0,'2021-02-01'),('XYZ Café',3,'2021-11-01'); | SELECT restaurant_name, SUM(violation_count) as total_violations FROM inspections WHERE inspection_date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY restaurant_name; |
What is the difference between the maximum and minimum environmental impact scores for production lines in Russia? | CREATE TABLE production_lines (line_id INT,line_name VARCHAR(50),country VARCHAR(50),environmental_impact_score DECIMAL(5,2)); INSERT INTO production_lines (line_id,line_name,country,environmental_impact_score) VALUES (1,'Line A','Russia',65.2),(2,'Line B','Russia',80.5),(3,'Line C','USA',55.0); | SELECT MAX(environmental_impact_score) - MIN(environmental_impact_score) FROM production_lines WHERE country = 'Russia'; |
Which countries have more than 5 digital divide projects, and what are the issues they are addressing? | CREATE TABLE digital_divide_projects (country VARCHAR(2),issue VARCHAR(50),project_count INT); INSERT INTO digital_divide_projects (country,issue,project_count) VALUES ('US','Lack of infrastructure',7),('CA','High cost of internet',6),('MX','Lack of digital literacy',8),('BR','Lack of infrastructure',5),('AR','High cost of internet',9); | SELECT country, issue FROM digital_divide_projects WHERE project_count > 5; |
What is the total balance of all socially responsible loans issued by GreenLend bank? | CREATE TABLE loans (id INT,bank VARCHAR(20),amount DECIMAL(10,2),is_socially_responsible BOOLEAN); INSERT INTO loans (id,bank,amount,is_socially_responsible) VALUES (1,'GreenLend',1000.00,true),(2,'GreenLend',1500.00,false),(3,'BlueBank',2000.00,true); | SELECT SUM(amount) FROM loans WHERE bank = 'GreenLend' AND is_socially_responsible = true; |
Display the average age of male policyholders | CREATE TABLE Policyholders (PolicyholderID INT,Age INT,Gender VARCHAR(10)); INSERT INTO Policyholders (PolicyholderID,Age,Gender) VALUES (1,34,'Female'),(2,45,'Male'),(3,52,'Male'),(4,30,'Male'),(5,40,'Female'); | SELECT AVG(Age) FROM Policyholders WHERE Gender = 'Male'; |
What is the percentage change in average temperature for each region compared to the same week in the previous year? | CREATE TABLE weekly_temp_data (region VARCHAR(255),temperature INT,week INT,year INT); INSERT INTO weekly_temp_data (region,temperature,week,year) VALUES ('North',25,1,2021),('South',30,1,2021),('East',28,1,2021),('West',22,1,2021),('North',27,1,2022),('South',29,1,2022),('East',31,1,2022),('West',24,1,2022); | SELECT region, ((current_temp - prev_temp) * 100.0 / prev_temp) as pct_change FROM (SELECT region, AVG(temperature) as current_temp, LAG(AVG(temperature)) OVER (PARTITION BY region ORDER BY year) as prev_temp FROM weekly_temp_data WHERE week = 1 GROUP BY region, year) subquery; |
Find the total number of games played by each team in the 'conference_games' table. | CREATE TABLE conference_games (team_id INT,home_team TEXT,away_team TEXT,played BOOLEAN); | SELECT home_team, COUNT(*) as total_games FROM conference_games WHERE played = TRUE GROUP BY home_team; SELECT away_team, COUNT(*) as total_games FROM conference_games WHERE played = TRUE GROUP BY away_team; |
What is the total number of pollution violations that have been issued? | CREATE TABLE pollution_violations (violation_id INTEGER,vessel_name TEXT,fine_amount INTEGER,violation_date DATE); | SELECT COUNT(*) FROM pollution_violations; |
What is the average lifelong learning program enrollment for students in each district over the past 3 years? | CREATE TABLE student_lifelong_learning (student_id INT,district_id INT,year INT,enrolled BOOLEAN); INSERT INTO student_lifelong_learning (student_id,district_id,year,enrolled) VALUES (1,1001,2019,true),(2,1001,2020,true),(3,1001,2021,false),(4,1002,2019,false),(5,1002,2020,true),(6,1002,2021,true); | SELECT district_id, AVG(enrolled) as avg_enrolled FROM student_lifelong_learning WHERE year BETWEEN 2019 AND 2021 GROUP BY district_id; |
Calculate the percentage change in energy consumption per month compared to the previous month for each hotel. | CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,city TEXT,country TEXT,energy_consumption FLOAT,month INT); INSERT INTO hotels (hotel_id,hotel_name,city,country,energy_consumption,month) VALUES (1,'Hotel A','Rome','Italy',12000.0,1),(1,'Hotel A','Rome','Italy',13000.0,2); | SELECT hotel_name, ((energy_consumption - LAG(energy_consumption) OVER (PARTITION BY hotel_name ORDER BY month))/LAG(energy_consumption) OVER (PARTITION BY hotel_name ORDER BY month))*100 as percentage_change FROM hotels; |
Delete the records of ingredients that were sourced before 2020. | CREATE TABLE ingredients (ingredient_id INT,name TEXT,sourcing_country TEXT,source_date DATE); INSERT INTO ingredients (ingredient_id,name,sourcing_country,source_date) VALUES (1,'Water','China','2021-01-01'),(2,'Glycerin','France','2021-02-15'),(3,'Retinol','USA','2020-12-10'); | DELETE FROM ingredients WHERE source_date < '2020-01-01'; |
Which Mental Health Specialties are present in MentalHealthParity table? | CREATE TABLE MentalHealthParity (PatientID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Zipcode VARCHAR(10),MentalHealthSpecialty VARCHAR(50)); INSERT INTO MentalHealthParity (PatientID,FirstName,LastName,Zipcode,MentalHealthSpecialty) VALUES (1,'Jane','Doe','12345','Psychiatry'); | SELECT DISTINCT MentalHealthSpecialty FROM MentalHealthParity; |
How many stores are there in each region for the retail chain? | CREATE TABLE Regions (RegionID int,RegionName varchar(50)); INSERT INTO Regions (RegionID,RegionName) VALUES (1,'North'),(2,'South'),(3,'East'),(4,'West'); CREATE TABLE StoreDetails (StoreID int,StoreName varchar(50),RegionID int); INSERT INTO StoreDetails (StoreID,StoreName,RegionID) VALUES (1,'Store A',1),(2,'Store B',1),(3,'Store C',2),(4,'Store D',3),(5,'Store E',4); | SELECT r.RegionName, COUNT(sd.StoreID) AS StoreCount FROM Regions r JOIN StoreDetails sd ON r.RegionID = sd.RegionID GROUP BY r.RegionName; |
What are the ages of the top 5 athletes with the most Olympic gold medals? | CREATE TABLE olympic_medalists (athlete_id INT,athlete_name VARCHAR(50),country VARCHAR(50),age INT,gold_medals INT); INSERT INTO olympic_medalists (athlete_id,athlete_name,country,age,gold_medals) VALUES (1,'Michael Phelps','USA',36,23),(2,'Larisa Latynina','Soviet Union',74,18),(3,'Marit Bjørgen','Norway',40,15); | SELECT athlete_name, age FROM olympic_medalists ORDER BY gold_medals DESC LIMIT 5; |
What is the average quantity of items in the inventory for each warehouse? | CREATE TABLE InventoryDetails (inventory_id INT,warehouse_id INT,item_name VARCHAR(50),quantity INT,delivery_date DATE); INSERT INTO InventoryDetails (inventory_id,warehouse_id,item_name,quantity,delivery_date) VALUES (1,1,'Box',10,'2022-01-01'),(2,2,'Palette',20,'2022-02-01'),(3,3,'Package',30,'2022-03-01'); | SELECT AVG(quantity) as avg_quantity FROM InventoryDetails; |
How many clients have a savings balance greater than $5,000 in Australia? | CREATE TABLE clients (client_id INT,name VARCHAR(100),age INT,country VARCHAR(50),savings DECIMAL(10,2)); INSERT INTO clients (client_id,name,age,country,savings) VALUES (10,'Sarah Johnson',50,'Australia',7000); | SELECT COUNT(*) FROM clients WHERE country = 'Australia' AND savings > 5000; |
Find the names of artists who have had their works exhibited in both New York and London. | CREATE TABLE Exhibitions (exhibit_id INT,artist_name VARCHAR(50),city VARCHAR(20)); INSERT INTO Exhibitions (exhibit_id,artist_name,city) VALUES (1,'Picasso','New York'),(2,'Warhol','London'),(3,'Matisse','New York'),(4,'Banksy','London'); | SELECT artist_name FROM Exhibitions WHERE city IN ('New York', 'London') GROUP BY artist_name HAVING COUNT(DISTINCT city) = 2; |
List the suppliers who have supplied all of the products in the 'Organic Vegetables' category. | CREATE TABLE suppliers (supplier_id INT,supplier_name TEXT);CREATE TABLE inventory (product_id INT,product_name TEXT,category TEXT,is_organic BOOLEAN);INSERT INTO suppliers VALUES (1,'Supplier A'),(2,'Supplier B'),(3,'Supplier C'),(4,'Supplier D');INSERT INTO inventory VALUES (200,'Carrots','Organic Vegetables',TRUE),(201,'Broccoli','Organic Vegetables',TRUE),(202,'Spinach','Organic Vegetables',TRUE),(203,'Beets','Organic Vegetables',TRUE),(204,'Peppers','Organic Vegetables',TRUE); | SELECT supplier_name FROM suppliers WHERE supplier_id IN (SELECT supplier_id FROM inventory WHERE category = 'Organic Vegetables' GROUP BY supplier_id HAVING COUNT(DISTINCT product_id) = (SELECT COUNT(DISTINCT product_id) FROM inventory WHERE category = 'Organic Vegetables')) ORDER BY supplier_name; |
What is the average weight of shipments for the top 2 warehouse_id's with the highest capacity, regardless of region? | CREATE TABLE Warehouse (id INT,city VARCHAR,capacity INT,region VARCHAR); INSERT INTO Warehouse (id,city,capacity,region) VALUES (1,'Los Angeles',5000,'West'); INSERT INTO Warehouse (id,city,capacity,region) VALUES (2,'Chicago',7000,'Midwest'); CREATE TABLE Shipment (id INT,warehouse_id INT,weight FLOAT,status VARCHAR,shipped_date DATE); INSERT INTO Shipment (id,warehouse_id,weight,status,shipped_date) VALUES (1,1,200,'Delivered','2022-01-01'); INSERT INTO Shipment (id,warehouse_id,weight,status,shipped_date) VALUES (2,2,300,'In Transit','2022-01-02'); | SELECT warehouse_id, AVG(weight) as avg_weight FROM Shipment WHERE warehouse_id IN (SELECT id FROM (SELECT id, ROW_NUMBER() OVER(ORDER BY capacity DESC) as rank FROM Warehouse) WHERE rank <= 2) GROUP BY warehouse_id; |
What is the average rating of hotels in the US that have adopted AI chatbots? | CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,country TEXT,rating FLOAT); CREATE TABLE ai_chatbots (hotel_id INT,chatbot_name TEXT); INSERT INTO hotels VALUES (1,'Hotel A','USA',4.5); INSERT INTO ai_chatbots VALUES (1); | SELECT AVG(hotels.rating) FROM hotels INNER JOIN ai_chatbots ON hotels.hotel_id = ai_chatbots.hotel_id WHERE hotels.country = 'USA'; |
List all customers with a credit score below 650 who have made a purchase in the last week in the Latin America (LA) region. | CREATE TABLE customers (id INT,name VARCHAR(255),credit_score INT,last_purchase_date DATE,region VARCHAR(50)); INSERT INTO customers (id,name,credit_score,last_purchase_date,region) VALUES (1,'Maria Rodriguez',600,'2022-04-20','LA'),(2,'Carlos Santos',700,'2022-03-25','LA'); | SELECT * FROM customers WHERE credit_score < 650 AND last_purchase_date BETWEEN DATEADD(week, -1, GETDATE()) AND GETDATE() AND region = 'LA'; |
What is the total number of AI safety incidents reported in each region? | CREATE TABLE Global_AI_Safety_Incidents (incident_id INT,incident_date DATE,region VARCHAR(50),incident_type VARCHAR(50)); INSERT INTO Global_AI_Safety_Incidents (incident_id,incident_date,region,incident_type) VALUES (1,'2021-01-01','US','Bias'),(2,'2021-02-15','Canada','Robot Malfunction'),(3,'2020-12-31','Mexico','Algorithmic Error'),(4,'2021-03-14','Brazil','Bias'); | SELECT region, COUNT(*) FROM Global_AI_Safety_Incidents GROUP BY region; |
What are the average temperatures in the chemical storage facilities in Canada? | CREATE TABLE chemical_storages (id INT,location VARCHAR(255),temperature FLOAT); INSERT INTO chemical_storages (id,location,temperature) VALUES (1,'Toronto,Canada',18.2),(2,'Vancouver,Canada',15.9),(3,'Montreal,Canada',21.0); | SELECT AVG(temperature) FROM chemical_storages WHERE location LIKE '%Canada%'; |
How many employees have been hired in the past 6 months? | CREATE TABLE employee_hires (id INT,hire_date DATE); INSERT INTO employee_hires (id,hire_date) VALUES (1,'2022-01-01'),(2,'2022-02-15'),(3,'2022-07-20'),(4,'2021-12-25'); | SELECT COUNT(*) FROM employee_hires WHERE hire_date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH) |
How many cases have been handled by female lawyers in each court location? | CREATE TABLE public.lawyers (id SERIAL PRIMARY KEY,name VARCHAR(255),age INT,gender VARCHAR(255),license_date DATE); CREATE TABLE public.cases (id SERIAL PRIMARY KEY,lawyer_id INT,case_number VARCHAR(255),case_date DATE,case_type VARCHAR(255),court_location VARCHAR(255)); | SELECT l.gender, c.court_location, COUNT(c.id) as case_count FROM public.lawyers l JOIN public.cases c ON l.id = c.lawyer_id WHERE l.gender = 'Female' GROUP BY l.gender, c.court_location; |
What is the minimum number of collective bargaining agreements signed in the 'technology' industry? | CREATE TABLE collective_bargaining (id INT,industry VARCHAR(50),num_agreements INT); INSERT INTO collective_bargaining (id,industry,num_agreements) VALUES (1,'construction',15); INSERT INTO collective_bargaining (id,industry,num_agreements) VALUES (2,'manufacturing',10); INSERT INTO collective_bargaining (id,industry,num_agreements) VALUES (3,'technology',5); | SELECT MIN(num_agreements) FROM collective_bargaining WHERE industry = 'technology'; |
What is the total number of marine species researched? | CREATE TABLE ResearchSpecies (id INT,researcher VARCHAR(30),species VARCHAR(50)); INSERT INTO ResearchSpecies (id,researcher,species) VALUES (1,'Alice','Coral'),(2,'Bob','Whale Shark'),(3,'Alice','Starfish'),(4,'Bob','Dolphin'); | SELECT COUNT(DISTINCT species) as total_species FROM ResearchSpecies; |
List the species that have been observed in more than one arctic region. | CREATE TABLE species_observations (species_id INT,region TEXT); | SELECT species_id FROM species_observations GROUP BY species_id HAVING COUNT(DISTINCT region) > 1; |
What is the maximum weight of stone artifacts in 'Site F'? | CREATE TABLE Site_F (Artifact_ID INT,Material VARCHAR(255),Weight INT); INSERT INTO Site_F (Artifact_ID,Material,Weight) VALUES (1,'Stone',200),(2,'Stone',400); | SELECT MAX(Weight) FROM Site_F WHERE Material = 'Stone'; |
Insert a new record with permit ID 456, contractor 'Green Construction', and timeline '2022-01-01 - 2022-04-30' in the building_projects table | CREATE TABLE building_projects (permit_id INT,contractor VARCHAR(100),timeline DATE); | INSERT INTO building_projects (permit_id, contractor, timeline) VALUES (456, 'Green Construction', '2022-01-01'::DATE, '2022-04-30'::DATE); |
What is the total carbon sequestration for each country's forests? | CREATE TABLE countries (id INT,name VARCHAR(255)); INSERT INTO countries (id,name) VALUES (1,'USA'),(2,'Canada'); CREATE TABLE forests (id INT,country_id INT,carbon_sequestration FLOAT); INSERT INTO forests (id,country_id,carbon_sequestration) VALUES (1,1,120.5),(2,1,150.2),(3,2,75.9); | SELECT c.name, SUM(f.carbon_sequestration) FROM countries c JOIN forests f ON c.id = f.country_id GROUP BY c.name; |
What is the total amount of research grants awarded by department? | CREATE TABLE department (id INT,name VARCHAR(255)); INSERT INTO department (id,name) VALUES (1,'Engineering'),(2,'Humanities'); CREATE TABLE grant (id INT,department_id INT,amount DECIMAL(10,2)); INSERT INTO grant (id,department_id,amount) VALUES (1,1,50000),(2,1,75000),(3,2,30000); | SELECT department.name, SUM(grant.amount) as total_grant_amount FROM department INNER JOIN grant ON department.id = grant.department_id GROUP BY department.name; |
Create a table named 'customer_size' | CREATE TABLE customer_size (id INT PRIMARY KEY,size VARCHAR(10),customer_count INT); | CREATE TABLE customer_size (id INT PRIMARY KEY, size VARCHAR(10), customer_count INT); |
Find the number of organic produce items with a price above $2.50 per pound. | CREATE TABLE FarmersMarket (item_name TEXT,item_type TEXT,is_organic BOOLEAN,price DECIMAL); | SELECT COUNT(*) FROM FarmersMarket WHERE is_organic = TRUE AND price > 2.50; |
What is the total quantity of garments sold by each salesperson, ordered by the salesperson's name? | CREATE TABLE salesperson (salesperson_id INT,name VARCHAR(50)); INSERT INTO salesperson (salesperson_id,name) VALUES (1,'John Doe'),(2,'Jane Smith'); CREATE TABLE sales (sales_id INT,salesperson_id INT,quantity INT); | SELECT salesperson.name, SUM(sales.quantity) AS total_quantity FROM salesperson INNER JOIN sales ON salesperson.salesperson_id = sales.salesperson_id GROUP BY salesperson.name ORDER BY salesperson.name; |
What is the total playtime of action games for players from the USA? | CREATE TABLE players (player_id int,age int,gender varchar(10),country varchar(20)); INSERT INTO players (player_id,age,gender,country) VALUES (1,25,'Male','USA'),(2,30,'Female','Canada'),(3,22,'Male','Mexico'); CREATE TABLE game_sessions (session_id int,player_id int,game_name varchar(20),game_type varchar(10),duration int); INSERT INTO game_sessions (session_id,player_id,game_name,game_type,duration) VALUES (1,1,'Racing Game','Non-VR',60),(2,1,'Shooter Game','VR',90),(3,2,'Strategy Game','Non-VR',120),(4,3,'Action Game','Non-VR',180); CREATE TABLE game_catalog (game_name varchar(20),game_type varchar(10)); INSERT INTO game_catalog (game_name,game_type) VALUES ('Racing Game','Non-VR'),('Shooter Game','VR'),('Strategy Game','Non-VR'),('Action Game','Non-VR'); | SELECT SUM(game_sessions.duration) FROM players INNER JOIN game_sessions ON players.player_id = game_sessions.player_id INNER JOIN game_catalog ON game_sessions.game_name = game_catalog.game_name WHERE players.country = 'USA' AND game_catalog.game_type = 'Action'; |
Who is the principal investigator for the 'Gene Editing for Cancer Treatment' study? | CREATE SCHEMA if not exists genetics; USE genetics; CREATE TABLE if not exists genetic_research (id INT PRIMARY KEY,study_name VARCHAR(255),principal_investigator VARCHAR(255)); INSERT INTO genetic_research (id,study_name,principal_investigator) VALUES (1,'Gene Editing for Cancer Treatment','Dr. Jane Smith'),(2,'Genome Modification in Plants','Dr. Alex Johnson'),(3,'CRISPR for Disease Prevention','Dr. Maria Rodriguez'); | SELECT principal_investigator FROM genetics.genetic_research WHERE study_name = 'Gene Editing for Cancer Treatment'; |
What is the average price of the 'room service' feature? | CREATE TABLE features (id INT,name TEXT,price FLOAT); INSERT INTO features (id,name,price) VALUES (1,'Virtual tours',10),(2,'Concierge service',20),(3,'Room service',30); | SELECT AVG(price) FROM features WHERE name = 'Room service'; |
Determine the percentage of female founders in each country | CREATE TABLE founders (id INT,name VARCHAR(255),gender VARCHAR(10),country VARCHAR(255)); INSERT INTO founders (id,name,gender,country) VALUES (1,'John Doe','Male','USA'),(2,'Jane Smith','Female','USA'),(3,'Mike Johnson','Male','Canada'),(4,'Alice Williams','Female','Canada'),(5,'Bob Brown','Male','UK'),(6,'Claire Johnson','Female','UK'),(7,'Suresh Patel','Male','India'),(8,'Priya Gupta','Female','India'); | SELECT country, gender, COUNT(*) as head_count, ROUND(COUNT(*)*100.0/SUM(COUNT(*)) OVER (PARTITION BY country), 2) as gender_percentage FROM founders GROUP BY country, gender; |
Find the average monthly financial wellbeing score for customers in the age group of 30-40, in the United Kingdom, for the last 12 months. | CREATE TABLE customers (customer_id INT,customer_name VARCHAR(255),age INT,country VARCHAR(255),financial_wellbeing_score DECIMAL(3,1),financial_wellbeing_date DATE); | SELECT AVG(c.financial_wellbeing_score) as avg_score FROM customers c WHERE c.age BETWEEN 30 AND 40 AND c.country = 'United Kingdom' AND c.financial_wellbeing_date >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH) GROUP BY MONTH(c.financial_wellbeing_date); |
What is the average size of marine protected areas in the Indian Ocean and Mediterranean Sea? | CREATE TABLE marine_protected_areas (id INT,name VARCHAR(255),location VARCHAR(255),size FLOAT); INSERT INTO marine_protected_areas (id,name,location,size) VALUES (1,'Maldives Atoll Marine Park','Indian Ocean',90000); INSERT INTO marine_protected_areas (id,name,location,size) VALUES (2,'Palestine National Marine Park','Mediterranean Sea',3500); | SELECT AVG(size) FROM marine_protected_areas WHERE location IN ('Indian Ocean', 'Mediterranean Sea'); |
List the total revenue for each membership type for the last quarter. | CREATE TABLE memberships (id INT,member_name VARCHAR(50),state VARCHAR(50),join_date DATE,membership_type VARCHAR(50),price DECIMAL(5,2)); INSERT INTO memberships (id,member_name,state,join_date,membership_type,price) VALUES (1,'John Doe','New York','2021-01-01','Premium',59.99),(2,'Jane Smith','California','2021-02-15','Basic',29.99),(3,'Bob Johnson','California','2022-01-01','Premium',59.99); | SELECT m.membership_type, SUM(m.price) AS total_revenue FROM memberships m WHERE m.join_date >= DATE_SUB(CURDATE(), INTERVAL 3 MONTH) GROUP BY m.membership_type; |
What is the total number of marine species in the Arctic Ocean? | CREATE TABLE ArcticSpecies (id INT,species INT); INSERT INTO ArcticSpecies (id,species) VALUES (1,5000); INSERT INTO ArcticSpecies (id,species) VALUES (2,2000); | SELECT SUM(species) FROM ArcticSpecies; |
Insert a new mining site 'Oil Rig' with 2 accidents. | CREATE TABLE mining_sites(id INT,site VARCHAR(50),accidents INT); | INSERT INTO mining_sites (id, site, accidents) VALUES (4, 'Oil Rig', 2); |
What's the number of workplace incidents in the mining industry by ethnicity, in the last 5 years? | CREATE TABLE workplace_safety (id INT PRIMARY KEY,ethnicity VARCHAR(50),incident_date DATE); INSERT INTO workplace_safety (id,ethnicity,incident_date) VALUES (1,'Caucasian','2018-01-01'),(2,'Hispanic','2017-05-05'),(3,'African American','2019-03-15'),(4,'Native American','2020-07-20'),(5,'Asian','2021-02-03'); | SELECT ethnicity, COUNT(*) as incidents FROM workplace_safety WHERE incident_date >= DATEADD(year, -5, GETDATE()) GROUP BY ethnicity; |
Which causes received the most funding from organizations in the Technology sector in 2021? | CREATE TABLE causes (cause_id INT,cause_name TEXT,cause_category TEXT); INSERT INTO causes (cause_id,cause_name,cause_category) VALUES (1,'Education','Social'),(2,'Healthcare','Social'),(3,'Environment','Social'),(4,'Tech for Good','Technology'); CREATE TABLE funding (funding_id INT,cause_id INT,funding_amount DECIMAL,funding_year INT,organization_sector TEXT); INSERT INTO funding (funding_id,cause_id,funding_amount,funding_year,organization_sector) VALUES (1,1,10000,2021,'Finance'),(2,2,15000,2021,'Technology'),(3,3,7000,2021,'Technology'),(4,4,20000,2021,'Technology'); | SELECT c.cause_name, SUM(f.funding_amount) as total_funding FROM funding f JOIN causes c ON f.cause_id = c.cause_id WHERE f.funding_year = 2021 AND f.organization_sector = 'Technology' GROUP BY c.cause_name ORDER BY total_funding DESC; |
What is the minimum retail price of eco-friendly dresses sold in Australia? | CREATE TABLE garment_sales (id INT,garment_type VARCHAR(50),sustainability_rating INT,country VARCHAR(50),price DECIMAL(5,2)); INSERT INTO garment_sales (id,garment_type,sustainability_rating,country,price) VALUES (1,'dress',5,'Australia',159.99),(2,'dress',4,'Australia',129.99); | SELECT MIN(price) FROM garment_sales WHERE garment_type = 'dress' AND country = 'Australia' AND sustainability_rating = 5; |
What is the average age of audience members who attended performing arts events in urban areas of New York and Pennsylvania? | CREATE TABLE Events (id INT,state VARCHAR(2),city VARCHAR(20),category VARCHAR(20),attendees INT,event_date DATE); INSERT INTO Events (id,state,city,category,attendees,event_date) VALUES (1,'NY','New York','Theater',500,'2022-01-01'),(2,'PA','Philadelphia','Dance',300,'2022-02-01'),(3,'NY','Albany','Music',400,'2022-03-01'); CREATE TABLE Audience (id INT,state VARCHAR(2),zip INT,age INT); INSERT INTO Audience (id,state,zip,age) VALUES (1,'NY',10000,30),(2,'PA',19000,40),(3,'NY',12000,35); CREATE TABLE Zipcodes (zip INT,city VARCHAR(20),urban VARCHAR(5)); INSERT INTO Zipcodes (zip,city,urban) VALUES (10000,'New York','yes'),(19000,'Philadelphia','yes'),(12000,'Albany','yes'); | SELECT AVG(Audience.age) FROM Events INNER JOIN Audience ON Events.state = Audience.state INNER JOIN Zipcodes ON Audience.zip = Zipcodes.zip WHERE urban = 'yes' AND Events.category IN ('Theater', 'Dance') AND Events.state IN ('NY', 'PA'); |
Which countries have the most luxury hotels? | CREATE TABLE hotels (hotel_id INT,hotel_name VARCHAR(255),country VARCHAR(255),luxury_rating INT); | SELECT country, COUNT(*) FROM hotels WHERE luxury_rating >= 4 GROUP BY country ORDER BY COUNT(*) DESC; |
Show all shipwrecks deeper than 3000 meters. | CREATE TABLE shipwrecks (name TEXT,depth INT); INSERT INTO shipwrecks (name,depth) VALUES ('Shipwreck 1','3500'),('Shipwreck 2','2500'); | SELECT * FROM shipwrecks WHERE depth > 3000; |
What is the total number of articles published on the website for each month in 2023? | CREATE TABLE article (id INT,title VARCHAR(255),publish_date DATE); INSERT INTO article (id,title,publish_date) VALUES (1,'Article1','2023-01-01'),(2,'Article2','2023-02-15'),(3,'Article3','2023-12-20'); | SELECT MONTH(publish_date), COUNT(*) FROM article WHERE YEAR(publish_date) = 2023 GROUP BY MONTH(publish_date); |
What is the minimum diversity score for content creators who identify as LGBTQ+ in Europe? | CREATE TABLE content_creators (id INT,name VARCHAR(50),diversity_score INT,country VARCHAR(50),gender VARCHAR(10),sexual_orientation VARCHAR(20)); INSERT INTO content_creators (id,name,diversity_score,country,gender,sexual_orientation) VALUES (1,'Creator1',80,'UK','Female','LGBTQ+'),(2,'Creator2',85,'France','Male','Straight'),(3,'Creator3',90,'Germany','Non-binary','LGBTQ+'),(4,'Creator4',75,'Italy','Female','Straight'); | SELECT MIN(diversity_score) FROM content_creators WHERE country IN ('UK', 'France', 'Germany', 'Italy') AND sexual_orientation = 'LGBTQ+'; |
Delete all records from the 'returns' table where return_date is older than 1 year | CREATE TABLE returns (return_id INT,return_date DATE); | DELETE FROM returns WHERE return_date < (CURRENT_DATE - INTERVAL '1 year'); |
Who are the top 2 employees with the lowest salaries, in the 'intelligence' department, for the year 2021? | CREATE TABLE employee_salaries (employee_id INT,employee_name TEXT,department TEXT,salary INT,year INT); INSERT INTO employee_salaries (employee_id,employee_name,department,salary,year) VALUES (1,'Ahmed','intelligence',70000,2021),(2,'Bina','cybersecurity',80000,2021),(3,'Chirag','intelligence',65000,2021),(4,'Delara','intelligence',60000,2021),(5,'Eesha','intelligence',75000,2021); | SELECT employee_name, salary, ROW_NUMBER() OVER (PARTITION BY department ORDER BY salary ASC) as rn FROM employee_salaries WHERE department = 'intelligence' AND year = 2021 AND rn <= 2; |
Delete the menu item 'Hot Wings' with ID 4 from the menu_sales table. | CREATE TABLE menu_sales (menu_item_id INT,menu_item_name TEXT,revenue INT); INSERT INTO menu_sales (menu_item_id,menu_item_name,revenue) VALUES (1,'Cheeseburger',500),(2,'Fries',300),(3,'Salad',250),(4,'Hot Wings',400); | DELETE FROM menu_sales WHERE menu_item_name = 'Hot Wings' AND menu_item_id = 4; |
What was the total attendance for each museum in Q1 2022? | CREATE TABLE museums (id INT,name TEXT,location TEXT,annual_attendance INT); INSERT INTO museums (id,name,location,annual_attendance) VALUES (1,'Metropolitan Museum of Art','New York,USA',7000000),(2,'British Museum','London,UK',5600000),(3,'Louvre Museum','Paris,France',8000000); CREATE TABLE quarterly_attendance (museum_id INT,quarter INT,attendance INT); INSERT INTO quarterly_attendance (museum_id,quarter,attendance) VALUES (1,1,1750000),(2,1,1400000),(3,1,2000000),(1,2,1875000),(2,2,1350000),(3,2,2200000),(1,3,1750000),(2,3,1400000),(3,3,2000000),(1,4,1625000),(2,4,1300000),(3,4,2100000); | SELECT museums.name, SUM(quarterly_attendance.attendance) AS q1_attendance FROM museums JOIN quarterly_attendance ON museums.id = quarterly_attendance.museum_id WHERE quarterly_attendance.quarter BETWEEN 1 AND 3 GROUP BY museums.name; |
What is the launch date and corresponding ID of the three oldest spacecraft? | CREATE TABLE spacecraft (id INT,name VARCHAR(50),country VARCHAR(50),launch_date DATE); INSERT INTO spacecraft (id,name,country,launch_date) VALUES (1,'Vostok 1','Russia','1961-04-12'); INSERT INTO spacecraft (id,name,country,launch_date) VALUES (2,'Friendship 7','USA','1962-02-20'); INSERT INTO spacecraft (id,name,country,launch_date) VALUES (3,'Voskhod 1','Russia','1964-10-12'); INSERT INTO spacecraft (id,name,country,launch_date) VALUES (4,'Apollo 7','USA','1968-10-11'); | SELECT id, launch_date FROM (SELECT id, launch_date, ROW_NUMBER() OVER (ORDER BY launch_date ASC) as row_num FROM spacecraft) AS subquery WHERE row_num <= 3; |
Which organizations have increased their humanitarian assistance budget by more than 10% in the last two years? | CREATE TABLE HumanitarianBudget (Organization VARCHAR(50),Year INT,Budget DECIMAL(10,2)); INSERT INTO HumanitarianBudget (Organization,Year,Budget) VALUES ('UNHCR',2019,1000000),('UNHCR',2020,1100000),('UNHCR',2021,1250000),('WFP',2019,1500000),('WFP',2020,1650000),('WFP',2021,1850000),('RedCross',2019,1000000),('RedCross',2020,1050000),('RedCross',2021,1150000); | SELECT Organization FROM (SELECT Organization, Year, Budget, LAG(Budget, 1, 0) OVER (PARTITION BY Organization ORDER BY Year) AS PreviousYearBudget, (Budget - PreviousYearBudget) * 100.0 / PreviousYearBudget AS BudgetChangePercentage FROM HumanitarianBudget) AS Subquery WHERE Subquery.Organization = Subquery.Organization AND BudgetChangePercentage > 10 GROUP BY Organization; |
Who are the faculty members in the Mathematics department? | CREATE TABLE faculty(id INT,name TEXT,department TEXT); INSERT INTO faculty(id,name,department) VALUES (1,'Fatima','Mathematics'),(2,'Brian','Physics'),(3,'Yuki','Mathematics'); | SELECT name FROM faculty WHERE department = 'Mathematics'; |
Update the "community_policing" table to set the "officer_count" to 3 for the "district_id" 5 | CREATE TABLE community_policing (district_id INT,officer_count INT); INSERT INTO community_policing (district_id,officer_count) VALUES (1,2),(2,4),(5,0); | UPDATE community_policing SET officer_count = 3 WHERE district_id = 5; |
What is the average price of 'Sustainable T-Shirts' sold in the 'Europe' region in Q1 2022? | CREATE TABLE Sales (id INT,product VARCHAR(20),region VARCHAR(20),price DECIMAL(5,2),sale_date DATE); INSERT INTO Sales (id,product,region,price,sale_date) VALUES (1,'Sustainable T-Shirt','Europe',25.99,'2022-01-02'),(2,'Regular T-Shirt','North America',19.99,'2022-02-15'),(3,'Sustainable T-Shirt','Europe',27.49,'2022-03-28'); | SELECT AVG(price) FROM Sales WHERE product = 'Sustainable T-Shirt' AND region = 'Europe' AND sale_date BETWEEN '2022-01-01' AND '2022-03-31'; |
Find the number of hotels and total number of bookings for hotels in the "Tokyo" city with the "budget" category | CREATE TABLE hotels (hotel_id INT,hotel_name VARCHAR(50),city VARCHAR(50),category VARCHAR(50)); CREATE TABLE bookings (booking_id INT,hotel_id INT,guest_name VARCHAR(50),checkin_date DATE,checkout_date DATE,price DECIMAL(10,2)); | SELECT h.city, h.category, COUNT(DISTINCT h.hotel_id) AS hotel_count, SUM(b.booking_id) AS booking_count FROM hotels h INNER JOIN bookings b ON h.hotel_id = b.hotel_id WHERE h.city = 'Tokyo' AND h.category = 'budget' GROUP BY h.city, h.category; |
Delete all records in the 'oil_spills' table where 'spill_year' is before 1990 | CREATE TABLE oil_spills (spill_id INT PRIMARY KEY,spill_name VARCHAR(50),spill_year INT,spilled_volume FLOAT); | DELETE FROM oil_spills WHERE spill_year < 1990; |
What is the average number of safety inspections per year for each vessel type in the South China Sea? | CREATE TABLE inspection_data (id INT,vessel_name VARCHAR(50),type VARCHAR(50),region VARCHAR(50),date DATE); INSERT INTO inspection_data (id,vessel_name,type,region,date) VALUES (1,'Vessel E','Tanker','South China Sea','2018-01-01'),(2,'Vessel F','Bulk Carrier','South China Sea','2019-02-01'); | SELECT type, YEAR(date) AS year, AVG(COUNT(*)) AS avg_inspections_per_year FROM inspection_data WHERE region = 'South China Sea' GROUP BY type, year; |
What is the name of the country that conducted the fewest humanitarian assistance missions in 2020? | CREATE TABLE humanitarian_assistance (mission_id INT,country_id INT,year INT,FOREIGN KEY (country_id) REFERENCES country(id)); | SELECT c.name FROM country c INNER JOIN (SELECT country_id, COUNT(mission_id) as total_missions FROM humanitarian_assistance WHERE year = 2020 GROUP BY country_id ORDER BY total_missions ASC LIMIT 1) h ON c.id = h.country_id; |
Display the average year of construction for the "Cargo" vessel type from the "vessels_summary" view. | CREATE TABLE vessels (vessel_id INT,name VARCHAR(50),type VARCHAR(50),year_built INT); CREATE VIEW vessels_summary AS SELECT type,AVG(year_built) AS avg_year_built FROM vessels GROUP BY type; | SELECT avg_year_built FROM vessels_summary WHERE type = 'Cargo'; |
What are the names and manufacturing dates of aircraft manufactured by Boeing or Airbus between 1980 and 1999? | CREATE TABLE Manufacturer (ManufacturerID INT PRIMARY KEY,ManufacturerName VARCHAR(50)); INSERT INTO Manufacturer (ManufacturerID,ManufacturerName) VALUES (1,'Boeing'); INSERT INTO Manufacturer (ManufacturerID,ManufacturerName) VALUES (2,'Airbus'); | SELECT A.AircraftName, A.ManufacturingDate FROM Aircraft A INNER JOIN Manufacturer M ON A.Manufacturer = M.ManufacturerName WHERE A.ManufacturingDate BETWEEN '1980-01-01' AND '1999-12-31' AND M.ManufacturerName IN ('Boeing', 'Airbus'); |
What is the total number of shared bikes in Madrid? | CREATE TABLE shared_bikes (id INT,city VARCHAR(255),country VARCHAR(255),num_bikes INT); INSERT INTO shared_bikes VALUES (1,'Madrid','Spain',1500); | SELECT num_bikes FROM shared_bikes WHERE city = 'Madrid'; |
What is the average age of offenders in the justice_data schema's adult_offenders table, broken down by gender? | CREATE TABLE justice_data.adult_offenders (id INT,name VARCHAR(50),age INT,gender VARCHAR(10),offense VARCHAR(50)); | SELECT gender, AVG(age) FROM justice_data.adult_offenders GROUP BY gender; |
What is the total quantity of supplies for each location in the disaster preparedness table, and what is the percentage of the total quantity for each location? | CREATE TABLE disaster_preparedness(id INT,location VARCHAR(255),supplies VARCHAR(255),quantity INT); | SELECT location, supplies, SUM(quantity) as total_quantity, total_quantity * 100.0 / SUM(SUM(quantity)) OVER (PARTITION BY supplies) as percentage FROM disaster_preparedness GROUP BY location, supplies; |
Insert a new athlete 'Alex Hunter' into the 'players' table | CREATE TABLE players (id INT PRIMARY KEY,first_name VARCHAR(50),last_name VARCHAR(50),position VARCHAR(50),team VARCHAR(50)); | INSERT INTO players (id, first_name, last_name, position, team) VALUES (123, 'Alex', 'Hunter', 'Forward', 'Los Angeles Blue'); |
Identify the number of workers in factories that practice ethical labor | CREATE TABLE factories (factory_id INT,location VARCHAR(255),has_ethical_labor BOOLEAN); INSERT INTO factories (factory_id,location,has_ethical_labor) VALUES (1,'New York',TRUE),(2,'Los Angeles',FALSE); CREATE TABLE workers (worker_id INT,factory_id INT); INSERT INTO workers (worker_id,factory_id) VALUES (1,1),(2,2),(3,1); | SELECT COUNT(DISTINCT workers.worker_id) FROM workers INNER JOIN factories ON workers.factory_id = factories.factory_id WHERE factories.has_ethical_labor = TRUE; |
Identify the agricultural innovation metrics that have the highest average score in Mexico and Peru. | CREATE TABLE innovation_metrics (id INT,name TEXT,score INT,country TEXT); INSERT INTO innovation_metrics (id,name,score,country) VALUES (1,'Soil Monitoring',8,'Mexico'),(2,'Irrigation',9,'Peru'),(3,'Crop Yield',7,'Mexico'),(4,'Livestock Management',8,'Peru'); | SELECT name, AVG(score) as avg_score FROM innovation_metrics WHERE country IN ('Mexico', 'Peru') GROUP BY name ORDER BY avg_score DESC LIMIT 1; |
What is the combined recycling rate for 'Material 1' and 'Material 2' in 'Facility 1'? | CREATE TABLE facility_recycling (facility VARCHAR(255),material VARCHAR(255),recycling_rate DECIMAL(5,2)); INSERT INTO facility_recycling (facility,material,recycling_rate) VALUES ('Facility 1','Material 1',0.30),('Facility 1','Material 2',0.40); | SELECT SUM(recycling_rate) FROM (SELECT recycling_rate FROM facility_recycling WHERE facility = 'Facility 1' AND material = 'Material 1' UNION ALL SELECT recycling_rate FROM facility_recycling WHERE facility = 'Facility 1' AND material = 'Material 2') AS combined_recycling; |
Find the total biomass of fish species that have been impacted by ocean acidification. | CREATE TABLE fish_species (id INT,species VARCHAR(255),biomass FLOAT); INSERT INTO fish_species (id,species,biomass) VALUES (1,'Tuna',200.0),(2,'Salmon',150.0),(3,'Cod',120.0),(4,'Herring',100.0); | SELECT SUM(biomass) FROM fish_species WHERE species IN ('Tuna', 'Salmon', 'Cod') HAVING COUNT(*) = 3; |
List all manufacturers that have produced garments in the 'Tops' category | CREATE TABLE Manufacturers (id INT,name VARCHAR(255)); INSERT INTO Manufacturers (id,name) VALUES (1,'Manufacturer A'),(2,'Manufacturer B'); CREATE TABLE Production (id INT,manufacturer_id INT,quantity INT,production_date DATE,category VARCHAR(255)); INSERT INTO Production (id,manufacturer_id,quantity,production_date,category) VALUES (1,1,500,'2020-01-01','Tops'),(2,1,700,'2020-02-01','Bottoms'),(3,2,300,'2020-01-15','Tops'),(4,2,400,'2020-03-10','Tops'); | SELECT m.name FROM Manufacturers m JOIN Production p ON m.id = p.manufacturer_id WHERE p.category = 'Tops' GROUP BY m.name; |
What is the number of students who participated in open pedagogy projects in 'Summer 2021' and 'Winter 2021'? | CREATE TABLE student_open_pedagogy (student_id INT,student_name VARCHAR(50),project_title VARCHAR(100),project_date DATE); INSERT INTO student_open_pedagogy (student_id,student_name,project_title,project_date) VALUES (1,'Michael Lee','Open Source Software Development','2021-07-01'),(2,'Sarah Jones','Digital Storytelling','2021-08-01'),(3,'Michael Lee','Data Visualization for Social Change','2021-12-01'),(4,'David Kim','Open Source Software Development','2021-12-15'); | SELECT COUNT(student_id) FROM student_open_pedagogy WHERE project_date BETWEEN '2021-06-01' AND '2021-12-31'; |
What is the total revenue for 'Pizzeria Yum'? | CREATE TABLE restaurants (name TEXT,revenue FLOAT); INSERT INTO restaurants (name,revenue) VALUES ('Pizzeria Spumoni',15000.0),('Pizzeria Yum',18000.0); | SELECT SUM(revenue) FROM restaurants WHERE name = 'Pizzeria Yum'; |
Determine the total number of wells drilled in each field, indicating which fields have more than 5 wells | CREATE TABLE field_wells (field_id INT,well_id INT); INSERT INTO field_wells (field_id,well_id) VALUES (1,1),(1,2),(1,3),(2,4),(3,5),(3,6),(3,7),(4,8),(4,9),(4,10),(4,11); | SELECT f.field_id, f.field_name, COUNT(fw.well_id) as num_wells FROM fields f INNER JOIN field_wells fw ON f.field_id = fw.field_id GROUP BY f.field_id HAVING num_wells > 5; |
What is the average account balance for socially responsible clients? | CREATE TABLE clients (client_id INT,is_socially_responsible BOOLEAN); INSERT INTO clients (client_id,is_socially_responsible) VALUES (1,true),(2,false),(3,true); CREATE TABLE accounts (account_id INT,client_id INT,balance DECIMAL(10,2)); INSERT INTO accounts (account_id,client_id,balance) VALUES (101,1,5000),(102,1,7000),(103,2,3000),(104,3,6000),(105,3,4000); | SELECT AVG(balance) FROM accounts INNER JOIN clients ON accounts.client_id = clients.client_id WHERE clients.is_socially_responsible = true; |
How many players have a score higher than 100? | CREATE TABLE Player (PlayerID INT,Name VARCHAR(50),Country VARCHAR(50),Score INT); | SELECT COUNT(*) FROM Player WHERE Score > 100; |
Find the minimum, average, and maximum annual energy savings for green buildings in each country | CREATE TABLE green_buildings_country (id INT,building_id INT,country TEXT); | SELECT green_buildings_country.country, MIN(green_buildings.annual_energy_savings_kWh) AS min_annual_energy_savings, AVG(green_buildings.annual_energy_savings_kWh) AS avg_annual_energy_savings, MAX(green_buildings.annual_energy_savings_kWh) AS max_annual_energy_savings FROM green_buildings JOIN green_buildings_country ON green_buildings.id = green_buildings_country.building_id GROUP BY green_buildings_country.country; |
What is the average food safety score for restaurants in the city of New York for the month of April 2022? | CREATE TABLE Restaurants (RestaurantID int,Name varchar(50),City varchar(50));CREATE TABLE FoodInspections (InspectionID int,RestaurantID int,InspectionDate date,Score int); | SELECT AVG(FI.Score) as AverageScore, R.City FROM FoodInspections FI INNER JOIN Restaurants R ON FI.RestaurantID = R.RestaurantID WHERE R.City = 'New York' AND MONTH(FI.InspectionDate) = 4 AND YEAR(FI.InspectionDate) = 2022 GROUP BY R.City; |
Which smart city projects were completed in 2020? | CREATE TABLE smart_city_projects (id INT,project_name TEXT,start_date DATE,end_date DATE); INSERT INTO smart_city_projects (id,project_name,start_date,end_date) VALUES (1,'Project A','2019-01-01','2020-06-30'),(2,'Project B','2020-07-01','2021-12-31'); | SELECT project_name FROM smart_city_projects WHERE YEAR(end_date) = 2020; |
How many tickets were sold for each team's home games in Q1 of 2021? | CREATE TABLE teams (id INT,name VARCHAR(255)); INSERT INTO teams (id,name) VALUES (1,'TeamA'),(2,'TeamB'); CREATE TABLE games (id INT,home_team_id INT,away_team_id INT,home_team_score INT,away_team_score INT,price DECIMAL(5,2),game_date DATE); CREATE VIEW home_games AS SELECT id,home_team_id,price,game_date FROM games; | SELECT t.name, COUNT(*) as tickets_sold FROM home_games h JOIN teams t ON h.home_team_id = t.id WHERE h.game_date BETWEEN '2021-01-01' AND '2021-03-31' GROUP BY t.name; |
What is the total number of aircraft sold by Aerospace Corp to the European Union? | CREATE TABLE Aerospace_Sales (id INT,corporation VARCHAR(20),customer VARCHAR(20),quantity INT,equipment VARCHAR(20)); INSERT INTO Aerospace_Sales (id,corporation,customer,quantity,equipment) VALUES (1,'Aerospace Corp','European Union',15,'Aircraft'); | SELECT SUM(quantity) FROM Aerospace_Sales WHERE corporation = 'Aerospace Corp' AND customer = 'European Union' AND equipment = 'Aircraft'; |
What is the average billing amount for cases in the 'Personal Injury' category? | CREATE TABLE Cases (CaseID INT,CaseType VARCHAR(255),BillingAmount DECIMAL); | SELECT AVG(BillingAmount) FROM Cases WHERE CaseType = 'Personal Injury'; |
What is the average price of sustainable clothing items sold in the US? | CREATE TABLE clothing_sales (id INT,item_name VARCHAR(255),price DECIMAL(5,2),country VARCHAR(50),is_sustainable BOOLEAN); | SELECT AVG(price) FROM clothing_sales WHERE country = 'US' AND is_sustainable = TRUE; |
Find the common drug categories between two companies. | CREATE TABLE company1_sales (drug_id INT,category_id INT); INSERT INTO company1_sales (drug_id,category_id) VALUES (101,1),(102,1),(103,2); CREATE TABLE company2_sales (drug_id INT,category_id INT); INSERT INTO company2_sales (drug_id,category_id) VALUES (102,1),(103,2),(104,3); | SELECT s1.category_id FROM company1_sales s1 JOIN company2_sales s2 ON s1.category_id = s2.category_id; |
Add a new port record to the "ports" table | CREATE TABLE ports (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255)); | INSERT INTO ports (id, name, location) VALUES (56, 'New Port', 'New Location'); |
How many investments were made in the 'Asia-Pacific' region in Q1 2021? | CREATE TABLE investments (id INT,region VARCHAR(20),date DATE); INSERT INTO investments (id,region,date) VALUES (1,'Asia-Pacific','2021-01-05'),(2,'Europe','2021-02-10'),(3,'Asia-Pacific','2021-03-25'); | SELECT COUNT(*) FROM investments WHERE region = 'Asia-Pacific' AND date BETWEEN '2021-01-01' AND '2021-03-31'; |
What was the total waste generation in the commercial sector in the first half of the 2010s? | CREATE TABLE waste_generation (id INT,sector VARCHAR(20),year INT,amount INT); INSERT INTO waste_generation (id,sector,year,amount) VALUES (1,'residential',2010,4000),(2,'residential',2011,4500),(3,'residential',2012,4700),(4,'commercial',2010,6000),(5,'commercial',2011,6500),(6,'commercial',2012,7000); | SELECT SUM(amount) FROM waste_generation WHERE sector = 'commercial' AND year BETWEEN 2010 AND 2012; |
Count the number of users who joined in the second quarter of 2021. | CREATE TABLE Users (user_id INT,join_date DATE); INSERT INTO Users (user_id,join_date) VALUES (1,'2021-04-01'),(2,'2021-05-15'),(3,'2021-06-30'),(4,'2021-07-01'); | SELECT COUNT(*) FROM Users WHERE join_date BETWEEN '2021-04-01' AND '2021-06-30'; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.