instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the average age of all artifacts in the 'ancient_artifacts' table? | CREATE TABLE ancient_artifacts (id INT,artifact_name VARCHAR(50),age INT,excavation_site VARCHAR(50)); | SELECT AVG(age) FROM ancient_artifacts; |
What is the total amount of donations for wildlife conservation in Canada? | CREATE TABLE Donation (Id INT,Donation_Date DATE,Amount DECIMAL(10,2),Country VARCHAR(50)); INSERT INTO Donation (Id,Donation_Date,Amount,Country) VALUES (1,'2022-01-01',100,'Canada'); INSERT INTO Donation (Id,Donation_Date,Amount,Country) VALUES (2,'2022-01-02',200,'Canada'); | SELECT SUM(Amount) FROM Donation WHERE Country = 'Canada' AND Purpose = 'Wildlife Conservation'; |
What is the total number of volunteers and staff members in each office location? | CREATE TABLE offices (id INT,name VARCHAR(255)); CREATE TABLE volunteers (id INT,office_id INT,joined_date DATE); CREATE TABLE staff (id INT,office_id INT,hired_date DATE); | SELECT offices.name, COUNT(volunteers.id) + COUNT(staff.id) FROM offices LEFT JOIN volunteers ON offices.id = volunteers.office_id LEFT JOIN staff ON offices.id = staff.office_id GROUP BY offices.id; |
What is the total fare collected for the 'Green Line' metro route? | CREATE TABLE MetroRoutes (route_id INT,route_name VARCHAR(20),fare DECIMAL(5,2)); INSERT INTO MetroRoutes (route_id,route_name,fare) VALUES (1,'Green Line',2.00),(2,'Blue Line',2.50),(3,'Green Line',2.50); | SELECT SUM(fare) FROM MetroRoutes WHERE route_name = 'Green Line'; |
How many users of each platform have played a specific game, 'Age of Dragons', in the last week? | CREATE TABLE GameSessions (SessionID INT,PlayerID INT,Game VARCHAR(20),Platform VARCHAR(10),StartDate DATETIME); INSERT INTO GameSessions (SessionID,PlayerID,Game,Platform,StartDate) VALUES (1,1,'Age of Dragons','PC','2022-01-01 12:00:00'); | SELECT Platform, COUNT(PlayerID) as UsersPlayed FROM GameSessions WHERE Game = 'Age of Dragons' AND StartDate >= CURRENT_DATE - INTERVAL 1 WEEK GROUP BY Platform; |
How many public libraries are in the city of Seattle? | CREATE TABLE cities (id INT,name VARCHAR(50)); INSERT INTO cities (id,name) VALUES (1,'Seattle'),(2,'Portland'); CREATE TABLE libraries (id INT,name VARCHAR(50),city_id INT); INSERT INTO libraries (id,name,city_id) VALUES (1,'Library A',1),(2,'Library B',1),(3,'Library C',2); | SELECT COUNT(*) FROM libraries WHERE city_id = (SELECT id FROM cities WHERE name = 'Seattle'); |
Delete records of mobile subscribers who have not made international calls in the Southeast region. | CREATE TABLE mobile_subscribers (subscriber_id INT,international_calls BOOLEAN,region VARCHAR(20)); INSERT INTO mobile_subscribers (subscriber_id,international_calls,region) VALUES (1,TRUE,'Southeast'),(2,FALSE,'Northeast'),(3,FALSE,'Southeast'),(4,TRUE,'Northern'),(5,TRUE,'Eastern'); | DELETE FROM mobile_subscribers WHERE international_calls = FALSE AND region = 'Southeast'; |
What was the total cost of economic diversification efforts in Mexico in 2017 and 2018 combined?' | CREATE TABLE economic_diversification_efforts (id INT,country VARCHAR(255),year INT,cost FLOAT); INSERT INTO economic_diversification_efforts (id,country,year,cost) VALUES (1,'Mexico',2017,30000.00),(2,'Mexico',2018,40000.00); | SELECT SUM(cost) FROM economic_diversification_efforts WHERE country = 'Mexico' AND (year = 2017 OR year = 2018); |
What is the average price of artworks in the 'Artworks' table, where the art_category is 'Painting' or 'Sculpture'? | CREATE TABLE Artworks (id INT,art_category VARCHAR(255),artist_name VARCHAR(255),year INT,art_medium VARCHAR(255),price DECIMAL(10,2)); | SELECT AVG(price) as avg_price FROM Artworks WHERE art_category IN ('Painting', 'Sculpture'); |
What was the average maintenance time for each vehicle type in the second quarter of 2021? | CREATE TABLE vehicle_maintenance (id INT,vehicle_type VARCHAR(20),maintenance_date DATE,maintenance_time INT); INSERT INTO vehicle_maintenance (id,vehicle_type,maintenance_date,maintenance_time) VALUES (1,'Bus','2021-04-01',60),(2,'Tram','2021-04-03',90),(3,'Train','2021-04-05',120),(4,'Bus','2021-07-01',70),(5,'Tram','2021-07-03',100),(6,'Train','2021-07-05',130); | SELECT vehicle_type, AVG(maintenance_time) as avg_maintenance_time FROM vehicle_maintenance WHERE maintenance_date BETWEEN '2021-04-01' AND '2021-06-30' GROUP BY vehicle_type; |
Add a new cruelty-free certification awarded by the 'CCIC' organization to the cosmetics."certifications" table | CREATE TABLE cosmetics.certifications (certification_id INT,certification_name VARCHAR(255),awarded_by VARCHAR(255)); INSERT INTO cosmetics.certifications (certification_id,certification_name,awarded_by) VALUES (1,'Leaping Bunny','CCIC'),(2,'Cruelty Free','PETA'); | INSERT INTO cosmetics.certifications (certification_id, certification_name, awarded_by) VALUES (3, 'Choose Cruelty Free', 'CCF'); |
What is the total water usage in California? | CREATE TABLE water_usage(state VARCHAR(20),volume_used INT); INSERT INTO water_usage VALUES('California',12000); | SELECT volume_used FROM water_usage WHERE state = 'California'; |
How many hospitals are there in New York and California? | CREATE TABLE hospitals (id INT,name VARCHAR(100),state VARCHAR(2)); INSERT INTO hospitals (id,name,state) VALUES (1,'Mount Sinai Hospital','NY'),(2,'NewYork-Presbyterian Hospital','NY'),(3,'UCLA Medical Center','CA'),(4,'Cedars-Sinai Medical Center','CA'); | SELECT state, COUNT(*) as hospital_count FROM hospitals GROUP BY state HAVING state IN ('NY', 'CA'); |
What is the average flight time for each aircraft model in the Boeing and Airbus fleets, grouped by the manufacturer? | CREATE TABLE boeing_fleet(model VARCHAR(255),flight_time INT);CREATE TABLE airbus_fleet(model VARCHAR(255),flight_time INT); | SELECT 'Boeing' as Manufacturer, AVG(flight_time) as Avg_Flight_Time FROM boeing_fleet GROUP BY Manufacturer UNION ALL SELECT 'Airbus' as Manufacturer, AVG(flight_time) as Avg_Flight_Time FROM airbus_fleet GROUP BY Manufacturer; |
What is the maximum depth of all mining shafts in the 'mining_shafts' table? | CREATE TABLE mining_shafts (id INT,mine_name VARCHAR,shaft_number INT,depth DECIMAL); INSERT INTO mining_shafts (id,mine_name,shaft_number,depth) VALUES (1,'Deep Dig',1,1200.00),(2,'Deep Dig',2,1500.00),(3,'Underground Oasis',1,1800.00),(4,'Underground Oasis',2,2000.00); | SELECT MAX(depth) FROM mining_shafts; |
What are the unique occupations of the non-union members? | CREATE TABLE non_union_members (id INT,name VARCHAR(50),occupation VARCHAR(50),state VARCHAR(2),joined_date DATE); INSERT INTO non_union_members (id,name,occupation,state,joined_date) VALUES (1,'Bob Johnson','Software Engineer','TX','2021-03-12'); INSERT INTO non_union_members (id,name,occupation,state,joined_date) VALUES (2,'Alice Williams','Teacher','FL','2020-08-02'); INSERT INTO non_union_members (id,name,occupation,state,joined_date) VALUES (3,'Charlie Lee','Software Engineer','TX','2020-11-15'); | SELECT DISTINCT occupation FROM non_union_members; |
What is the maximum age of players who have played VR games? | CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),HasPlayedVR BOOLEAN); INSERT INTO Players (PlayerID,Age,Gender,HasPlayedVR) VALUES (1,25,'Male',true),(2,30,'Female',false),(3,22,'Male',true); | SELECT MAX(Age) FROM Players WHERE HasPlayedVR = true; |
How many crimes were reported in each category in 2020? | CREATE TABLE Crime (cid INT,year INT,category VARCHAR(255),location VARCHAR(255)); | SELECT category, COUNT(*) FROM Crime WHERE year = 2020 GROUP BY category; |
Find the total number of electric and hybrid vehicles sold in each region in the 'sales_data' table. | CREATE TABLE sales_data (vehicle_type VARCHAR(10),sale_region VARCHAR(10),quantity_sold INT); | SELECT sale_region, SUM(CASE WHEN vehicle_type LIKE '%Electric%' THEN quantity_sold ELSE 0 END) + SUM(CASE WHEN vehicle_type LIKE '%Hybrid%' THEN quantity_sold ELSE 0 END) AS total_ev_hybrid_sold FROM sales_data GROUP BY sale_region; |
What is the sum of all grants received by the organization in 2021? | CREATE TABLE grants (grant_id INT,grant_amount DECIMAL(10,2),grant_date DATE,organization_id INT); | SELECT SUM(grant_amount) FROM grants WHERE grant_date >= '2021-01-01' AND grant_date < '2022-01-01'; |
How many vehicles of each model and year are due for maintenance, i.e., have not been maintained in the last 90 days? | CREATE TABLE vehicle (vehicle_id INT,model VARCHAR(255),year INT,route_id INT,last_maintenance DATE); INSERT INTO vehicle (vehicle_id,model,year,route_id,last_maintenance) VALUES (5,'Tram C',2020,5,'2021-12-01'); INSERT INTO vehicle (vehicle_id,model,year,route_id,last_maintenance) VALUES (6,'Trolleybus D',2018,6,'2022-01-10'); | SELECT model, year, COUNT(*) as vehicles_due_for_maintenance FROM vehicle WHERE DATEDIFF(CURDATE(), last_maintenance) > 90 GROUP BY model, year; |
What is the total number of eco-friendly accommodations in South Africa? | CREATE TABLE south_africa_tourism (name VARCHAR(255),location VARCHAR(255),type VARCHAR(255),certification DATE); INSERT INTO south_africa_tourism (name,location,type,certification) VALUES ('Eco Lodge','Cape Town,South Africa','Hotel','2020-05-15'); | SELECT COUNT(*) FROM south_africa_tourism WHERE type = 'Hotel' AND certification IS NOT NULL; |
List the product codes, product names, and quantities of garments made from linen, sorted alphabetically by product name. | CREATE TABLE Products (ProductCode TEXT,ProductName TEXT,Fabric TEXT);INSERT INTO Products (ProductCode,ProductName,Fabric) VALUES ('P101','EcoBlouse','Linen'),('P102','GreenPants','Cotton'),('P103','SustainableShirt','Hemp'),('P104','OrganicSkirt','Linen'),('P105','RecycledJacket','Polyester'); | SELECT ProductCode, ProductName, Fabric FROM Products WHERE Fabric = 'Linen' ORDER BY ProductName ASC; |
Find the average protein content per dish for Mexican cuisine restaurants in Los Angeles, for the month of July 2022. | CREATE TABLE dishes (restaurant_name TEXT,cuisine TEXT,dish TEXT,protein INTEGER,dish_date DATE); INSERT INTO dishes (restaurant_name,cuisine,dish,protein,dish_date) VALUES ('Tacos El Pastor','Mexican','Carnitas Tacos',30,'2022-07-01'); | SELECT cuisine, AVG(protein) as avg_protein FROM (SELECT restaurant_name, cuisine, dish, protein, dish_date, ROW_NUMBER() OVER (PARTITION BY cuisine, dish_date ORDER BY protein) as rn FROM dishes WHERE restaurant_name LIKE 'Los%' AND cuisine = 'Mexican' AND dish_date >= '2022-07-01' AND dish_date < '2022-08-01') t WHERE rn = 1 GROUP BY cuisine; |
Identify galleries that have held exhibitions featuring artists from both France and Spain. | CREATE TABLE Gallery (id INT,name VARCHAR(255)); CREATE TABLE Exhibition (id INT,title VARCHAR(255),gallery_id INT,country VARCHAR(50)); | SELECT Gallery.name FROM Gallery JOIN Exhibition ON Gallery.id = Exhibition.gallery_id WHERE Exhibition.country IN ('France', 'Spain') GROUP BY Gallery.name HAVING COUNT(DISTINCT Exhibition.country) = 2; |
What is the maximum response time for emergency incidents by type in San Francisco? | CREATE TABLE san_francisco_boroughs (id INT,name TEXT); INSERT INTO san_francisco_boroughs (id,name) VALUES (1,'Downtown'),(2,'North Beach'),(3,'Chinatown'); CREATE TABLE emergency_response (id INT,borough_id INT,incident_id INT,response_time INT); INSERT INTO emergency_response (id,borough_id,incident_id,response_time) VALUES (1,1,1,300),(2,1,2,450),(3,3,3,600); CREATE TABLE emergency_incidents (id INT,type TEXT,date DATE); INSERT INTO emergency_incidents (id,type,date) VALUES (1,'Fire','2021-01-01'),(2,'Theft','2021-01-02'),(3,'Assault','2021-01-03'); | SELECT e.type, MAX(er.response_time) as max_response_time FROM emergency_response er JOIN emergency_incidents e ON er.incident_id = e.id JOIN san_francisco_boroughs b ON er.borough_id = b.id GROUP BY e.type; |
What is the total budget for transportation in each city? | CREATE TABLE City_Budget(City VARCHAR(20),Department VARCHAR(20),Budget INT); INSERT INTO City_Budget(City,Department,Budget) VALUES('Toronto','Parks',25000000); INSERT INTO City_Budget(City,Department,Budget) VALUES('Toronto','Transportation',50000000); INSERT INTO City_Budget(City,Department,Budget) VALUES('Montreal','Parks',18000000); INSERT INTO City_Budget(City,Department,Budget) VALUES('Montreal','Transportation',42000000); | SELECT City, SUM(Budget) FROM City_Budget WHERE Department = 'Transportation' GROUP BY City; |
Which marine species were found in the 'South Pacific' region in 2020? | CREATE TABLE Species (id INT,name VARCHAR(255),region VARCHAR(255),year INT); INSERT INTO Species (id,name,region,year) VALUES (1,'Tuna','South Pacific',2020); INSERT INTO Species (id,name,region,year) VALUES (2,'Dolphin','South Pacific',2020); | SELECT name FROM Species WHERE region = 'South Pacific' AND year = 2020; |
What is the total number of diversity and inclusion training sessions conducted, by department, for the year 2021? | CREATE TABLE training_sessions (id INT,session_date DATE,department VARCHAR(50),training_type VARCHAR(50)); INSERT INTO training_sessions (id,session_date,department,training_type) VALUES (1,'2021-02-10','IT','Diversity and Inclusion'); INSERT INTO training_sessions (id,session_date,department,training_type) VALUES (2,'2021-06-15','HR','Diversity and Inclusion'); | SELECT department, training_type, COUNT(*) as total_sessions FROM training_sessions WHERE YEAR(session_date) = 2021 AND training_type = 'Diversity and Inclusion' GROUP BY department, training_type; |
Insert a new record into the 'inventory' table with the following data: '101', 'Hemp Hoodie', 'M', 120 | CREATE TABLE inventory (item_id INT,item_name VARCHAR(50),item_size VARCHAR(5),quantity INT); | INSERT INTO inventory (item_id, item_name, item_size, quantity) VALUES (101, 'Hemp Hoodie', 'M', 120); |
Show companies with risk levels equal to 'high'. | CREATE TABLE companies_risk (company_id INT,company_name VARCHAR(50),risk_level VARCHAR(10)); INSERT INTO companies_risk (company_id,company_name,risk_level) VALUES (1,'Initech','high'),(2,'Global Enterprises','medium'),(3,'Eco-Friendly Solutions','low'); | SELECT * FROM companies_risk WHERE risk_level = 'high'; |
What is the average age of attendees for events by artist 'Picasso'? | CREATE TABLE Artists (ArtistID INT PRIMARY KEY,ArtistName VARCHAR(255)); INSERT INTO Artists (ArtistID,ArtistName) VALUES (1,'Picasso'); CREATE TABLE Events (EventID INT PRIMARY KEY,EventName VARCHAR(255),Attendance INT,ArtistID INT,FOREIGN KEY (ArtistID) REFERENCES Artists(ArtistID)); INSERT INTO Events (EventID,EventName,Attendance,ArtistID) VALUES (1,'Cubism Exhibit',700,1); | SELECT AVG(Audience.Age) FROM Audience INNER JOIN Events ON Audience.EventID = Events.EventID INNER JOIN Artists ON Events.ArtistID = Artists.ArtistID WHERE Artists.ArtistName = 'Picasso'; |
What is the percentage of the budget allocated for waste management services in each state of India, for the fiscal year 2021-2022? | CREATE TABLE BudgetIndia (State VARCHAR(50),Service VARCHAR(50),Year INT,Amount DECIMAL(10,2)); INSERT INTO BudgetIndia (State,Service,Year,Amount) VALUES ('Andhra Pradesh','Waste Management',2021,2500.00),('Andhra Pradesh','Other Services',2021,7500.00),('Bihar','Waste Management',2021,3000.00),('Bihar','Other Services',2021,6000.00); | SELECT State, (SUM(CASE WHEN Service = 'Waste Management' THEN Amount ELSE 0 END) / SUM(Amount)) * 100 as WasteManagementPercentage FROM BudgetIndia WHERE Year = 2021 GROUP BY State; |
Update the description for ethic with id 1 to 'Minimize harm to subjects' | CREATE TABLE ethics (id INT,description VARCHAR(100)); INSERT INTO ethics (id,description) VALUES (1,'Avoid bias in reporting'); | UPDATE ethics SET description = 'Minimize harm to subjects' WHERE id = 1; |
What is the total CO2 emissions for mines with a 'vein' geological structure? | CREATE TABLE environmental_impact (mine_name TEXT,co2_emissions INTEGER,water_usage INTEGER,waste_generation INTEGER,geological_structure TEXT); INSERT INTO environmental_impact (mine_name,co2_emissions,water_usage,waste_generation,geological_structure) VALUES ('Golden Ridge Mine',120,500,30,'stratified'),('Silver Peak Mine',150,400,25,'tabular'),('Emerald Paradise Mine',180,600,35,'vein'),('Topaz Canyon Mine',100,700,20,'vein'); | SELECT SUM(co2_emissions) as total_co2 FROM environmental_impact WHERE geological_structure = 'vein'; |
What is the average defense spending by the top 10 countries with the highest military expenditure over the last 5 years? | CREATE TABLE DefenseSpending (CountryName VARCHAR(50),Year INT,Spending DECIMAL(18,2)); INSERT INTO DefenseSpending (CountryName,Year,Spending) VALUES ('USA',2017,610000000000),('China',2017,228000000000),('Russia',2017,66000000000),('Saudi Arabia',2017,64000000000),('India',2017,53000000000),('France',2017,50000000000),('Germany',2017,45000000000),('UK',2017,45000000000),('Japan',2017,45000000000),('Brazil',2017,27000000000); | SELECT AVG(Spending) FROM (SELECT CountryName, Spending FROM DefenseSpending WHERE Year BETWEEN 2017 AND 2021 QUALIFY ROW_NUMBER() OVER (PARTITION BY CountryName ORDER BY Spending DESC) <= 10) AS Top10Countries; |
What is the total budget allocated for defense diplomacy by countries in North America in 2019? | CREATE TABLE DefenseDiplomacy (id INT,country VARCHAR(50),budget DECIMAL(10,2),year INT); INSERT INTO DefenseDiplomacy (id,country,budget,year) VALUES (1,'USA',10000000,2019),(2,'Canada',5000000,2019),(3,'Mexico',2000000,2019); | SELECT SUM(budget) FROM DefenseDiplomacy WHERE country IN ('USA', 'Canada', 'Mexico') AND year = 2019; |
Find the mining sites that have the highest and lowest water consumption compared to the other sites. | CREATE TABLE mining_sites (id INT,name VARCHAR(50)); CREATE TABLE water_consumption (site_id INT,consumption FLOAT,consumption_date DATE); INSERT INTO mining_sites (id,name) VALUES (1,'Site A'),(2,'Site B'),(3,'Site C'); INSERT INTO water_consumption (site_id,consumption,consumption_date) VALUES (1,200,'2022-01-01'),(1,300,'2022-02-01'),(2,150,'2022-01-01'),(2,250,'2022-02-01'),(3,100,'2022-01-01'),(3,200,'2022-02-01'); | SELECT ms.name, AVG(wc.consumption) as avg_consumption FROM mining_sites ms INNER JOIN water_consumption wc ON ms.id = wc.site_id GROUP BY ms.name ORDER BY avg_consumption DESC, ms.name ASC; |
Find the average number of hospital beds per state in California and Texas. | CREATE TABLE state_hospitals (state VARCHAR(50),hospital_beds INT); INSERT INTO state_hospitals (state,hospital_beds) VALUES ('California',75000),('Texas',85000); | SELECT state, AVG(hospital_beds) AS avg_hospital_beds FROM state_hospitals WHERE state IN ('California', 'Texas') GROUP BY state; |
Find the average temperature and humidity for all vineyards in Sonoma County. | CREATE TABLE vineyards (id INT,name TEXT,location TEXT,temperature DECIMAL(5,2),humidity DECIMAL(5,2)); INSERT INTO vineyards (id,name,location,temperature,humidity) VALUES (1,'Vineyard A','Sonoma County',75.6,65.2),(2,'Vineyard B','Sonoma County',76.3,68.1),(3,'Vineyard C','Napa County',78.9,72.3); | SELECT AVG(temperature), AVG(humidity) FROM vineyards WHERE location = 'Sonoma County'; |
Find the number of cases with a verdict of 'Guilty' or 'Dismissed', grouped by the attorney's last name. | CREATE TABLE cases (id INT,attorney_id INT,verdict VARCHAR(20)); INSERT INTO cases (id,attorney_id,verdict) VALUES (1,1,'Guilty'),(2,1,'Dismissed'),(3,2,'Guilty'),(4,3,'Guilty'),(5,4,'Dismissed'),(6,4,'Guilty'),(7,5,'Dismissed'),(8,5,'Guilty'); CREATE TABLE attorneys (id INT,last_name VARCHAR(20)); INSERT INTO attorneys (id,last_name) VALUES (1,'Patel'),(2,'Lee'),(3,'Johnson'),(4,'Singh'),(5,'Kim'); | SELECT last_name, COUNT(*) FROM cases INNER JOIN attorneys ON cases.attorney_id = attorneys.id WHERE verdict IN ('Guilty', 'Dismissed') GROUP BY last_name; |
What is the average number of participants per defense diplomacy event, ordered from highest to lowest? | CREATE TABLE defense_diplomacy_2 (id INT,event VARCHAR(255),participants INT); INSERT INTO defense_diplomacy_2 (id,event,participants) VALUES (1,'Defense Innovation Summit',500),(2,'International Peacekeeping Conference',350),(3,'Defense and Security Forum',400),(4,'Military Diplomacy Workshop',200),(5,'Defense Cooperation Meeting',250),(6,'Global Security Forum',600),(7,'Defense Technology Conference',700),(8,'International Defense Expo',800),(9,'Peace and Security Summit',900),(10,'World Defense Conference',1000); | SELECT AVG(participants) AS avg_participants FROM defense_diplomacy_2 GROUP BY event ORDER BY avg_participants DESC; |
What is the minimum ph level for each aquaculture zone in 2022, ordered by the minimum value? | CREATE TABLE aquaculture_zones (zone_id INT,year INT,min_ph FLOAT); INSERT INTO aquaculture_zones (zone_id,year,min_ph) VALUES (1,2022,7.5),(2,2022,7.3),(3,2022,7.8),(4,2022,7.6),(5,2022,7.1); | SELECT zone_id, MIN(min_ph) as min_ph_value FROM aquaculture_zones WHERE year = 2022 GROUP BY zone_id ORDER BY MIN(min_ph) ASC; |
What is the success rate of therapy sessions for different age groups? | CREATE TABLE therapy_sessions_age (session_id INT,therapy_success CHAR(1),age INT); INSERT INTO therapy_sessions_age (session_id,therapy_success,age) VALUES (1,'Y',30),(2,'N',25),(3,'Y',45),(4,'N',35); | SELECT age, AVG(CASE WHEN therapy_success = 'Y' THEN 1.0 ELSE 0.0 END) as success_rate FROM therapy_sessions_age GROUP BY age; |
What are the models and their types that have been trained on the 'creative_ai' dataset? | CREATE TABLE model_dataset_creative_ai (model_id INT,model_name VARCHAR(50),model_type VARCHAR(20),dataset_name VARCHAR(50)); INSERT INTO model_dataset_creative_ai (model_id,model_name,model_type,dataset_name) VALUES (1,'DCGAN','generative','creative_ai'),(2,'VAE','generative','creative_ai'),(3,'CNN','convolutional','creative_ai'); | SELECT model_name, model_type FROM model_dataset_creative_ai WHERE dataset_name = 'creative_ai'; |
What is the total revenue for each menu category in January 2020, ordered by the highest revenue first? | CREATE TABLE restaurant_revenue (menu_category VARCHAR(50),transaction_date DATE,revenue NUMERIC(10,2)); INSERT INTO restaurant_revenue (menu_category,transaction_date,revenue) VALUES ('Appetizers','2020-01-01',1500.00),('Entrees','2020-01-03',2500.00),('Desserts','2020-01-02',1200.00); | SELECT menu_category, SUM(revenue) AS total_revenue FROM restaurant_revenue WHERE transaction_date BETWEEN '2020-01-01' AND '2020-01-31' GROUP BY menu_category ORDER BY total_revenue DESC; |
Show the top 3 sustainable cosmetic brands by sales. | CREATE TABLE brand_sales (brand VARCHAR(20),product_category VARCHAR(20),revenue DECIMAL(10,2)); INSERT INTO brand_sales (brand,product_category,revenue) VALUES ('BrandA','Makeup',12000),('BrandA','Skincare',15000),('BrandB','Makeup',9000),('BrandB','Skincare',11000),('BrandC','Makeup',10000),('BrandC','Skincare',16000); | SELECT brand, SUM(revenue) FROM brand_sales GROUP BY brand ORDER BY SUM(revenue) DESC LIMIT 3; |
Delete the record for 'Brazil' from the landfill_capacity table for the oldest date. | CREATE TABLE latam_landfill_capacity (country_name VARCHAR(50),capacity NUMERIC(10,2),date DATE); INSERT INTO latam_landfill_capacity (country_name,capacity,date) VALUES ('Brazil',32345.67,'2021-01-01'),('Brazil',32342.34,'2022-01-01'); | DELETE FROM latam_landfill_capacity WHERE country_name = 'Brazil' AND date = (SELECT MIN(date) FROM latam_landfill_capacity WHERE country_name = 'Brazil'); |
What was the total REE production for each mine in 2020? | CREATE TABLE mines (id INT,name TEXT,location TEXT,quarter INT,annual_production INT); INSERT INTO mines (id,name,location,quarter,annual_production) VALUES (1,'Mine A','Country X',1,400),(2,'Mine B','Country Y',1,500),(3,'Mine C','Country Z',1,450),(1,'Mine A','Country X',2,425),(2,'Mine B','Country Y',2,450),(3,'Mine C','Country Z',2,500),(1,'Mine A','Country X',3,475),(2,'Mine B','Country Y',3,550),(3,'Mine C','Country Z',3,425),(1,'Mine A','Country X',4,350),(2,'Mine B','Country Y',4,450),(3,'Mine C','Country Z',4,475); | SELECT name, SUM(annual_production) as total_production FROM mines WHERE YEAR(timestamp) = 2020 GROUP BY name; |
What is the average calorie count for items in the Organic_Produce table? | CREATE TABLE Organic_Produce (id INT,name VARCHAR(50),calories INT); INSERT INTO Organic_Produce (id,name,calories) VALUES (1,'Apples',95),(2,'Broccoli',55); | SELECT AVG(calories) FROM Organic_Produce; |
Who are the top 3 consumers of cosmetic products in Japan? | CREATE TABLE ConsumerPreference (ConsumerID INT,ProductID INT,ProductName VARCHAR(50),Country VARCHAR(50)); INSERT INTO ConsumerPreference (ConsumerID,ProductID,ProductName,Country) VALUES (1,101,'Lipstick','Japan'),(2,102,'Mascara','Japan'),(3,103,'Foundation','Japan'),(4,104,'Eyeshadow','Japan'),(5,105,'Blush','Japan'); | SELECT ConsumerName, COUNT(*) AS ProductCount FROM ConsumerPreference CP INNER JOIN Consumers C ON CP.ConsumerID = C.ConsumerID WHERE CP.Country = 'Japan' GROUP BY ConsumerName ORDER BY ProductCount DESC LIMIT 3; |
What is the total biomass for each fish species by month in 2022? | CREATE TABLE fish_species (id INT,name VARCHAR(50),average_length DECIMAL(5,2)); CREATE TABLE fish_weights (id INT,fish_species_id INT,date DATE,weight DECIMAL(10,2)); INSERT INTO fish_species (id,name,average_length) VALUES (1,'Salmon',70.0),(2,'Tilapia',25.0); INSERT INTO fish_weights (id,fish_species_id,date,weight) VALUES (1,1,'2022-01-01',50.0),(2,1,'2022-01-02',52.0); | SELECT EXTRACT(MONTH FROM fw.date) AS month, fs.name, SUM(fw.weight) AS total_biomass FROM fish_species fs JOIN fish_weights fw ON fs.id = fw.fish_species_id WHERE YEAR(fw.date) = 2022 GROUP BY month, fs.name; |
List countries and their corresponding populations for companies in the 'finance' sector. | CREATE TABLE companies (id INT,sector VARCHAR(20),country VARCHAR(30)); INSERT INTO companies (id,sector,country) VALUES (1,'technology','USA'),(2,'finance','UK'),(3,'technology','Canada'),(4,'healthcare','Germany'); | SELECT DISTINCT country FROM companies WHERE sector = 'finance'; |
What's the total number of military personnel in the 'military_personnel' table by rank? | CREATE TABLE military_personnel (rank VARCHAR(20),personnel_count INT); INSERT INTO military_personnel (rank,personnel_count) VALUES ('General',500),('Colonel',1000),('Major',1500),('Captain',2000),('Lieutenant',2500); | SELECT rank, SUM(personnel_count) FROM military_personnel GROUP BY rank; |
Which ingredients are commonly used in 'Lip' products, and where are they sourced from? | CREATE TABLE products (product_id INT,product VARCHAR(255),brand_id INT); CREATE TABLE product_ingredients (ingredient_id INT,product_id INT,ingredient VARCHAR(255),source_country VARCHAR(255)); INSERT INTO products (product_id,product,brand_id) VALUES (1,'Lip Balm',1),(2,'Lipstick',2); INSERT INTO product_ingredients (ingredient_id,product_id,ingredient,source_country) VALUES (1,1,'Beeswax','China'),(2,1,'Coconut Oil','Philippines'),(3,2,'Beeswax','Canada'),(4,2,'Castor Oil','India'); | SELECT pi.ingredient, COUNT(pi.ingredient) as count, p.source_country FROM product_ingredients pi JOIN products p ON pi.product_id = p.product_id WHERE p.product LIKE 'Lip%' GROUP BY pi.ingredient, p.source_country; |
Get all unique regions from the 'audience' table | CREATE TABLE audience (audience_id INT PRIMARY KEY,name VARCHAR(255),region VARCHAR(255),gender VARCHAR(255)); | SELECT DISTINCT region FROM audience; |
Number of eco-friendly hotels in specific cities? | CREATE TABLE eco_hotels_extended_2 (hotel_id INT,name TEXT,city TEXT,country TEXT); INSERT INTO eco_hotels_extended_2 (hotel_id,name,city,country) VALUES (1,'Le Hameau de la Vallée','Paris','France'),(2,'Hotel Eco Vie','Marseille','France'),(3,'Eco Resort','Rome','Italy'),(4,'Green Hotel','Barcelona','Spain'); | SELECT city, COUNT(*) FROM eco_hotels_extended_2 GROUP BY city; |
Update the price of all garments in the 'Tops' category to $25.00 | CREATE TABLE Garments (id INT,name VARCHAR(255),category VARCHAR(255),color VARCHAR(255),size VARCHAR(10),price DECIMAL(5,2)); | UPDATE Garments SET price = 25.00 WHERE category = 'Tops'; |
What was the life expectancy in India in 2020? | CREATE TABLE life_expectancy (id INT,country VARCHAR(50),year INT,expectancy DECIMAL(5,2)); INSERT INTO life_expectancy (id,country,year,expectancy) VALUES (1,'India',2020,70.85),(2,'India',2019,70.76); | SELECT expectancy FROM life_expectancy WHERE country = 'India' AND year = 2020; |
What is the total amount donated by individual donors who are residents of 'CityX', for events held in the past six months? | CREATE TABLE Donors (donor_id INT,donor_name VARCHAR(50),donor_city VARCHAR(50),donation_amount INT,donation_date DATE); CREATE TABLE Events (event_id INT,event_name VARCHAR(50),event_date DATE); | SELECT SUM(d.donation_amount) FROM Donors d JOIN Events e ON d.donation_date >= e.event_date AND d.donation_date <= DATEADD(month, 6, e.event_date) WHERE d.donor_city = 'CityX'; |
Delete records for fish species that are not salmonids. | CREATE TABLE fish_species (id INT,name VARCHAR(255),species_family VARCHAR(255)); INSERT INTO fish_species (id,name,species_family) VALUES (1,'Salmon','Salmonidae'),(2,'Tuna','Scombridae'),(3,'Cod','Gadidae'); CREATE TABLE fish_data (id INT,species_id INT,weight DECIMAL(5,2),length DECIMAL(5,2)); INSERT INTO fish_data (id,species_id,weight,length) VALUES (1,1,3.5,0.6),(2,1,4.2,0.7),(3,2,22.3,1.3),(4,3,1.2,0.3); | DELETE FROM fish_data WHERE species_id NOT IN (SELECT id FROM fish_species WHERE species_family = 'Salmonidae'); |
What was the total cost of all projects in 'Water Supply' category in 2020? | CREATE TABLE Projects (id INT,name VARCHAR(50),category VARCHAR(50),cost FLOAT,year INT); INSERT INTO Projects (id,name,category,cost,year) VALUES (1,'Dam Reconstruction','Water Supply',500000,2020),(2,'Wastewater Treatment','Waste Management',600000,2020),(3,'Road Pavement','Transportation',700000,2020); | SELECT SUM(cost) FROM Projects WHERE category = 'Water Supply' AND year = 2020; |
Find the total marketing spend for TV shows in the Comedy and Romance genres for the year 2015. | CREATE TABLE tv_shows (id INT,title VARCHAR(100),genre VARCHAR(50),release_year INT,marketing_spend INT); INSERT INTO tv_shows (id,title,genre,release_year,marketing_spend) VALUES (1,'ShowA','Comedy',2015,5000000); INSERT INTO tv_shows (id,title,genre,release_year,marketing_spend) VALUES (2,'ShowB','Romance',2015,6000000); | SELECT SUM(marketing_spend) FROM tv_shows WHERE genre IN ('Comedy', 'Romance') AND release_year = 2015; |
Identify the top 3 wells with the highest production in H1 2019, excluding well 'W005'? | CREATE TABLE wells (well_id VARCHAR(10),production INT,timestamp TIMESTAMP); INSERT INTO wells (well_id,production,timestamp) VALUES ('W001',250,'2019-01-01 00:00:00'),('W002',300,'2019-01-02 00:00:00'),('W003',200,'2019-01-03 00:00:00'),('W004',350,'2019-01-04 00:00:00'),('W005',275,'2019-01-05 00:00:00'),('W006',400,'2019-01-06 00:00:00'),('W007',500,'2019-01-07 00:00:00'); | SELECT well_id, SUM(production) as total_production FROM wells WHERE well_id != 'W005' AND EXTRACT(QUARTER FROM timestamp) <= 2 AND EXTRACT(YEAR FROM timestamp) = 2019 GROUP BY well_id ORDER BY total_production DESC LIMIT 3; |
What are the names of all power plants and their total energy production in the energy division? | CREATE TABLE power_plants (id INT,name VARCHAR(50),division VARCHAR(50),energy_production FLOAT); INSERT INTO power_plants (id,name,division,energy_production) VALUES (1,'Power Plant A','Energy',5000),(2,'Power Plant B','Energy',6000),(3,'Power Plant C','Energy',4500); | SELECT name, SUM(energy_production) FROM power_plants WHERE division = 'Energy' GROUP BY name; |
What are the AI safety research papers published in 2021, ranked by the number of citations? | CREATE TABLE research_papers (title VARCHAR(255),year INT,citations INT,domain VARCHAR(255)); INSERT INTO research_papers (title,year,citations,domain) VALUES ('Paper3',2018,40,'AI Safety'); INSERT INTO research_papers (title,year,citations,domain) VALUES ('Paper4',2019,60,'AI Safety'); INSERT INTO research_papers (title,year,citations,domain) VALUES ('Paper5',2021,80,'AI Safety'); INSERT INTO research_papers (title,year,citations,domain) VALUES ('Paper6',2020,90,'AI Safety'); | SELECT title, year, citations FROM research_papers WHERE year = 2021 AND domain = 'AI Safety' ORDER BY citations DESC; |
What is the total amount of funding received by events in the 'visual arts' category from 'private' funding sources? | CREATE TABLE funding (id INT,event_name TEXT,funding_source TEXT,amount_funded INT); INSERT INTO funding (id,event_name,funding_source,amount_funded) VALUES (1,'Art Exhibit','Private Donor',5000),(2,'Photography Show','Corporate Sponsor',10000); | SELECT SUM(amount_funded) FROM funding WHERE event_name IN (SELECT event_name FROM events WHERE event_category = 'visual arts') AND funding_source = 'private'; |
Count the number of public works projects in each state | CREATE TABLE Project (id INT,name VARCHAR(255),state VARCHAR(255)); INSERT INTO Project (id,name,state) VALUES (1,'Project X','California'),(2,'Project Y','Texas'),(3,'Project Z','California'); | SELECT state, COUNT(*) FROM Project GROUP BY state; |
List all social impact investments in the Renewable Energy sector with ESG scores between 60 and 80, ordered by investment date and ESGScore, including only investments made by Mexican investors. | CREATE TABLE SocialImpactInvestments (InvestmentID INT,InvestmentDate DATE,Sector VARCHAR(20),ESGScore INT,InvestorCountry VARCHAR(20)); INSERT INTO SocialImpactInvestments VALUES (1,'2021-01-01','Renewable Energy',75,'Mexico'),(2,'2021-02-01','Healthcare',75,'Germany'),(3,'2021-03-01','Renewable Energy',68,'Mexico'); | SELECT * FROM SocialImpactInvestments WHERE Sector = 'Renewable Energy' AND ESGScore BETWEEN 60 AND 80 AND InvestorCountry = 'Mexico' ORDER BY InvestmentDate, ESGScore; |
List the number of investments made by each investor in healthcare startups, sorted by the number of investments in descending order. | CREATE TABLE investors (id INT,name TEXT); CREATE TABLE investments (id INT,investor_id INT,startup_id INT,investment_amount INT); CREATE TABLE startups (id INT,name TEXT,industry TEXT); INSERT INTO investors (id,name) VALUES (1,'InvestorA'),(2,'InvestorB'); INSERT INTO startups (id,name,industry) VALUES (1,'HealthcareStartupA','Healthcare'),(2,'TechStartupB','Technology'); INSERT INTO investments (id,investor_id,startup_id,investment_amount) VALUES (1,1,1,100000),(2,1,2,200000),(3,2,1,150000); | SELECT i.name, COUNT(*) as num_investments FROM investors i INNER JOIN investments inv ON i.id = inv.investor_id INNER JOIN startups s ON inv.startup_id = s.id WHERE s.industry = 'Healthcare' GROUP BY i.name ORDER BY num_investments DESC; |
What is the historical period with the most excavated artifacts? | CREATE TABLE artifacts (artifact_id INT,artifact_type VARCHAR(255),historical_period VARCHAR(255)); INSERT INTO artifacts (artifact_id,artifact_type,historical_period) VALUES (1,'Pottery','Iron Age'),(2,'Bone Fragments','Stone Age'),(3,'Coins','Medieval'),(4,'Bronze Tools','Bronze Age'); | SELECT historical_period, COUNT(*) FROM artifacts GROUP BY historical_period ORDER BY COUNT(*) DESC; |
Identify the top 2 countries with the highest number of sustainable materials providers? | CREATE TABLE countries (country_id INT,country_name VARCHAR(255),sustainable_materials BOOLEAN); INSERT INTO countries (country_id,country_name,sustainable_materials) VALUES (1,'Brazil',TRUE),(2,'India',FALSE),(3,'China',TRUE),(4,'Italy',TRUE),(5,'USA',FALSE),(6,'India',TRUE),(7,'Vietnam',TRUE),(8,'Cambodia',FALSE),(9,'Bangladesh',TRUE),(10,'Spain',TRUE); | SELECT country_name, COUNT(*) as num_sustainable_materials_providers FROM countries WHERE sustainable_materials = TRUE GROUP BY country_name ORDER BY num_sustainable_materials_providers DESC LIMIT 2; |
What is the average temperature for each crop type in the past month? | CREATE TABLE crop_temperature_historical (crop_type TEXT,date DATE,temperature INTEGER); INSERT INTO crop_temperature_historical VALUES ('cassava','2022-06-01',25),('yam','2022-06-01',28); | SELECT crop_type, AVG(temperature) as avg_temperature FROM crop_temperature_historical WHERE date >= CURDATE() - INTERVAL 1 MONTH GROUP BY crop_type; |
What is the average budget allocated for accessible technology initiatives in African countries? | CREATE TABLE AccessibleTechBudget (Country VARCHAR(50),Budget DECIMAL(10,2)); INSERT INTO AccessibleTechBudget (Country,Budget) VALUES ('Rwanda',500000.00),('Kenya',750000.00),('Nigeria',900000.00); CREATE TABLE Countries (Country VARCHAR(50),Continent VARCHAR(50)); INSERT INTO Countries (Country,Continent) VALUES ('Rwanda','Africa'),('Kenya','Africa'),('Nigeria','Africa'); | SELECT AVG(AccessibleTechBudget.Budget) AS AvgBudget FROM AccessibleTechBudget INNER JOIN Countries ON AccessibleTechBudget.Country = Countries.Country WHERE Countries.Continent = 'Africa'; |
Which country produced the most Dysprosium in 2020? | CREATE TABLE yearly_production (country VARCHAR(255),element VARCHAR(255),year INT,production INT); INSERT INTO yearly_production (country,element,year,production) VALUES ('China','Dysprosium',2020,1200),('Australia','Dysprosium',2020,800),('United States','Dysprosium',2020,500); | SELECT country, MAX(production) as max_production FROM yearly_production WHERE element = 'Dysprosium' AND year = 2020 GROUP BY country; |
Sum of home values for socially responsible loans in Texas | CREATE TABLE socially_responsible_loans (id INT,home_value FLOAT,state VARCHAR(255)); CREATE TABLE states (id INT,state VARCHAR(255),region VARCHAR(255)); | SELECT SUM(home_value) FROM socially_responsible_loans INNER JOIN states ON socially_responsible_loans.state = states.state WHERE states.state = 'Texas'; |
What is the maximum number of doctor visits in a year for patients in Ontario? | CREATE TABLE doctor_visit (patient_id INT,visit_year INT,number_of_visits INT); INSERT INTO doctor_visit (patient_id,visit_year,number_of_visits) VALUES (1,2022,5); | SELECT MAX(number_of_visits) FROM doctor_visit WHERE patient_id = 1 AND visit_year = 2022; |
What is the average unloading time (in hours) in Argentina? | CREATE TABLE ports (port_id INT,port_name VARCHAR(50),country VARCHAR(50)); INSERT INTO ports VALUES (1,'Buenos Aires','Argentina'); CREATE TABLE cargo_handling (handling_id INT,port_id INT,operation_type VARCHAR(50),operation_date DATE,unloading_time_hours FLOAT); INSERT INTO cargo_handling VALUES (1,1,'unloading','2021-01-01',10); INSERT INTO cargo_handling VALUES (2,1,'unloading','2021-01-02',12); INSERT INTO cargo_handling VALUES (3,1,'loading','2021-01-03',8); INSERT INTO cargo_handling VALUES (4,1,'loading','2021-01-04',9); | SELECT AVG(unloading_time_hours) FROM cargo_handling JOIN ports ON cargo_handling.port_id = ports.port_id WHERE ports.country = 'Argentina' AND cargo_handling.operation_type = 'unloading'; |
What is the total number of streams for K-pop songs released since 2018? | CREATE TABLE songs (song_id INT,genre VARCHAR(20),release_year INT,streams INT); INSERT INTO songs (song_id,genre,release_year,streams) VALUES (1,'K-pop',2018,1000); INSERT INTO songs (song_id,genre,release_year,streams) VALUES (2,'K-pop',2019,2000); INSERT INTO songs (song_id,genre,release_year,streams) VALUES (3,'K-pop',2020,3000); | SELECT SUM(streams) FROM songs WHERE genre = 'K-pop' AND release_year >= 2018; |
How many graduate students in the Biology department have published at least one paper? | CREATE SCHEMA if not exists higher_ed;CREATE TABLE if not exists higher_ed.students(id INT,name VARCHAR(255),department VARCHAR(255));CREATE TABLE if not exists higher_ed.publications(id INT,title VARCHAR(255),author_id INT); | SELECT COUNT(DISTINCT s.id) FROM higher_ed.students s JOIN higher_ed.publications p ON s.id = p.author_id WHERE s.department = 'Biology'; |
How many volunteers have participated in the 'Environment' program in total? | CREATE TABLE Volunteers (VolunteerID INT,VolunteerName TEXT,Country TEXT); INSERT INTO Volunteers (VolunteerID,VolunteerName,Country) VALUES (1,'Amina','Nigeria'); INSERT INTO Volunteers (VolunteerID,VolunteerName,Country) VALUES (2,'Boris','Russia'); CREATE TABLE VolunteerPrograms (ProgramID INT,ProgramName TEXT); INSERT INTO VolunteerPrograms (ProgramID,ProgramName) VALUES (1,'Environment'); INSERT INTO VolunteerPrograms (ProgramID,ProgramName) VALUES (2,'Culture'); CREATE TABLE VolunteerEvents (EventID INT,ProgramID INT,VolunteerID INT,EventDate DATE); INSERT INTO VolunteerEvents (EventID,ProgramID,VolunteerID,EventDate) VALUES (1,1,1,'2021-01-01'); INSERT INTO VolunteerEvents (EventID,ProgramID,VolunteerID,EventDate) VALUES (2,2,2,'2021-02-01'); INSERT INTO VolunteerEvents (EventID,ProgramID,VolunteerID,EventDate) VALUES (3,1,2,'2021-05-01'); | SELECT COUNT(DISTINCT Volunteers.VolunteerID) AS TotalVolunteers FROM Volunteers INNER JOIN VolunteerEvents ON Volunteers.VolunteerID = VolunteerEvents.VolunteerID INNER JOIN VolunteerPrograms ON VolunteerEvents.ProgramID = VolunteerPrograms.ProgramID WHERE VolunteerPrograms.ProgramName = 'Environment'; |
Insert a new record of Gadolinium production in 2021 with a production value of 15000 | CREATE TABLE gadolinium_production (year INT,production FLOAT); INSERT INTO gadolinium_production (year,production) VALUES (2015,4000),(2016,5000),(2017,6000),(2018,7000),(2019,8000),(2020,9000); | INSERT INTO gadolinium_production (year, production) VALUES (2021, 15000); |
List the fashion trends that intersect between brands A and B. | CREATE TABLE Fashion_Trends (trend_id INT,trend_name TEXT); CREATE TABLE Brand_Trends (brand_id INT,trend_id INT); | SELECT ft.trend_name FROM Fashion_Trends ft JOIN Brand_Trends bt1 ON ft.trend_id = bt1.trend_id JOIN Brand_Trends bt2 ON ft.trend_id = bt2.trend_id WHERE bt1.brand_id = 1 AND bt2.brand_id = 2; |
How many patients started a new treatment approach in India during 2021? | CREATE TABLE patients (id INT,country VARCHAR(255),start_date DATE); CREATE TABLE treatments (id INT,patient_id INT,start_date DATE); INSERT INTO patients (id,country) VALUES (1,'India'),(2,'Pakistan'); INSERT INTO treatments (id,patient_id,start_date) VALUES (1,1,'2021-01-01'),(2,1,'2021-05-15'),(3,2,'2020-12-31'); | SELECT COUNT(DISTINCT patients.id) FROM patients JOIN treatments ON patients.id = treatments.patient_id WHERE patients.country = 'India' AND treatments.start_date >= '2021-01-01' AND treatments.start_date < '2022-01-01'; |
How many spacecrafts were manufactured by AstroCorp in 2017? | CREATE TABLE spacecrafts (manufacturer VARCHAR(255),mass FLOAT,manufacture_date DATE); INSERT INTO spacecrafts (manufacturer,mass,manufacture_date) VALUES ('SpaceCorp',10000,'2010-01-01'); INSERT INTO spacecrafts (manufacturer,mass,manufacture_date) VALUES ('AstroCorp',18000,'2017-09-21'); INSERT INTO spacecrafts (manufacturer,mass,manufacture_date) VALUES ('Galactic Inc',15000,'2015-06-28'); | SELECT COUNT(*) FROM spacecrafts WHERE manufacturer = 'AstroCorp' AND manufacture_date LIKE '2017%'; |
What is the total funding raised by startups founded by women? | CREATE TABLE startup_founders (id INT PRIMARY KEY,name VARCHAR(255),gender VARCHAR(10),industry VARCHAR(255),total_funding FLOAT); | SELECT SUM(total_funding) FROM startup_founders WHERE gender = 'female'; |
What are the names of the vessels that docked in the Port of Miami in May 2022 and have also docked in the Port of Key West in June 2022? | CREATE TABLE port_of_miami (vessel_name VARCHAR(255),dock_month INT); CREATE TABLE port_of_key_west (vessel_name VARCHAR(255),dock_month INT); INSERT INTO port_of_miami (vessel_name,dock_month) VALUES ('Vessel LL',5),('Vessel MM',5),('Vessel NN',6); INSERT INTO port_of_key_west (vessel_name,dock_month) VALUES ('Vessel MM',6),('Vessel NN',6),('Vessel OO',7); | SELECT m.vessel_name FROM port_of_miami m WHERE m.dock_month = 5 INTERSECT SELECT k.vessel_name FROM port_of_key_west k WHERE k.dock_month = 6; |
Which sport event had the highest fan attendance? | CREATE TABLE events (event_type VARCHAR(50),fan_count INT); INSERT INTO events (event_type,fan_count) VALUES ('Football',2000),('Basketball',1500),('Hockey',1200); | SELECT event_type, MAX(fan_count) FROM events; |
What is the average hotel star rating for eco-friendly hotels in Costa Rica? | CREATE TABLE hotels(hotel_id INT,name TEXT,star_rating INT,is_eco_friendly BOOLEAN);CREATE TABLE countries(country_id INT,name TEXT);INSERT INTO countries (country_id,name) VALUES (1,'Costa Rica'); INSERT INTO hotels (hotel_id,name,star_rating,is_eco_friendly) VALUES (1,'Hotel A',4,true),(2,'Hotel B',3,false),(3,'Hotel C',5,true); | SELECT AVG(star_rating) FROM hotels INNER JOIN countries ON hotels.country_id = countries.country_id WHERE is_eco_friendly = true AND countries.name = 'Costa Rica'; |
What was the average donation amount and number of donations per month in 2021? | CREATE TABLE Donations (DonationID INT,DonorID INT,DonationAmount DECIMAL(10,2),DonationDate DATE); INSERT INTO Donations (DonationID,DonorID,DonationAmount,DonationDate) VALUES (1,1,500.00,'2021-01-05'); INSERT INTO Donations (DonationID,DonorID,DonationAmount,DonationDate) VALUES (2,2,300.00,'2021-02-10'); | SELECT EXTRACT(MONTH FROM DonationDate) as Month, AVG(DonationAmount) as AverageDonation, COUNT(*) as NumberOfDonations FROM Donations WHERE DonationDate BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY Month; |
What is the maximum monthly data usage by a customer in the EMEA region? | CREATE TABLE customers (customer_id INT,name VARCHAR(100),region VARCHAR(50),monthly_data_usage DECIMAL(10,2)); INSERT INTO customers (customer_id,name,region,monthly_data_usage) VALUES (1,'John Doe','EMEA',10),(2,'Jane Smith','Europe',15),(3,'Alice Johnson','Asia-Pacific',8),(4,'Bob Brown','EMEA',20),(5,'Charlie Davis','Europe',18); | SELECT MAX(customers.monthly_data_usage) FROM customers WHERE customers.region = 'EMEA'; |
Delete the community health worker with worker_id 3. | CREATE TABLE community_health_workers (worker_id INT,name VARCHAR(50),ethnicity VARCHAR(20)); INSERT INTO community_health_workers (worker_id,name,ethnicity) VALUES (1,'Ana Garcia','Hispanic'),(2,'Juan Hernandez','Hispanic'),(3,'Mark Johnson','Non-Hispanic'); | DELETE FROM community_health_workers WHERE worker_id = 3; |
How many marine mammals are there in the 'species' table, and what is their average conservation status ranking? | CREATE TABLE species (species_id INT,common_name VARCHAR(50),latin_name VARCHAR(50),conservation_status VARCHAR(50),class VARCHAR(50)); INSERT INTO species (species_id,common_name,latin_name,conservation_status,class) VALUES (1,'Green Sea Turtle','Chelonia mydas','Vulnerable','Reptilia'),(2,'Bottlenose Dolphin','Tursiops truncatus','Least Concern','Mammalia'); | SELECT class, COUNT(*), AVG(CASE WHEN conservation_status = 'Critically Endangered' THEN 5 WHEN conservation_status = 'Endangered' THEN 4 WHEN conservation_status = 'Vulnerable' THEN 3 WHEN conservation_status = 'Near Threatened' THEN 2 WHEN conservation_status = 'Least Concern' THEN 1 ELSE 0 END) as conservation_rank FROM species WHERE class = 'Mammalia' GROUP BY class; |
What is the percentage of patients who have been diagnosed with a mental health condition, grouped by their gender? | CREATE TABLE Patients (PatientID INT,Gender VARCHAR(255),Diagnosis VARCHAR(255)); INSERT INTO Patients (PatientID,Gender,Diagnosis) VALUES (1,'Female','Depression'); | SELECT Gender, (SUM(Cases) / SUM(TotalPatients)) * 100.0 FROM (SELECT Gender, COUNT(*) AS TotalPatients, SUM(CASE WHEN Diagnosis IN ('Depression', 'Anxiety', 'Bipolar Disorder') THEN 1 ELSE 0 END) AS Cases FROM Patients GROUP BY Gender) AS Subquery GROUP BY Gender; |
Which donors have made donations in both the education and health sectors? | CREATE TABLE donor_data (donor_id INT,donation DECIMAL(10,2),sector TEXT); INSERT INTO donor_data (donor_id,donation,sector) VALUES (1,250.00,'education'),(2,300.00,'health'),(3,150.00,'education'),(1,100.00,'health'); | SELECT donor_id FROM donor_data WHERE sector = 'education' INTERSECT SELECT donor_id FROM donor_data WHERE sector = 'health'; |
What is the number of hospitals and clinics in each region, and the total number of hospital and clinic beds? | CREATE TABLE hospitals (hospital_id INT,region VARCHAR(20),beds INT); INSERT INTO hospitals (hospital_id,region,beds) VALUES (1,'Rural',50),(2,'Urban',100); CREATE TABLE clinics (clinic_id INT,region VARCHAR(20),beds INT); INSERT INTO clinics (clinic_id,region,beds) VALUES (1,'Rural',10),(2,'Urban',20); | SELECT s.region, COUNT(h.hospital_id) as hospital_count, COUNT(c.clinic_id) as clinic_count, SUM(h.beds) + SUM(c.beds) as total_beds FROM hospitals h JOIN clinics c ON h.region = c.region JOIN states s ON h.region = s.region GROUP BY s.region; |
List all wastewater treatment plants in California that had drought-related issues since 2015. | CREATE TABLE Wastewater_Treatment_Plants (Plant_ID INT,State VARCHAR(20),Year INT,Drought_Issues BOOLEAN); INSERT INTO Wastewater_Treatment_Plants (Plant_ID,State,Year,Drought_Issues) VALUES (1,'California',2015,true),(2,'California',2016,false); | SELECT * FROM Wastewater_Treatment_Plants WHERE State = 'California' AND Drought_Issues = true AND Year >= 2015; |
What is the average labor cost for construction projects in 'British Columbia' in the 'construction_labor_stats' table? | CREATE TABLE construction_labor_stats (province TEXT,project_id INT,labor_cost FLOAT); INSERT INTO construction_labor_stats (province,project_id,labor_cost) VALUES ('British Columbia',1,18000),('British Columbia',2,20000),('British Columbia',3,22000); | SELECT AVG(labor_cost) FROM construction_labor_stats WHERE province = 'British Columbia'; |
What is the minimum military equipment sale price by General Dynamics in 2019? | CREATE TABLE MilitaryEquipmentSales (EquipmentID INT,Manufacturer VARCHAR(50),DestinationCountry VARCHAR(50),SaleDate DATE,Quantity INT,UnitPrice FLOAT); INSERT INTO MilitaryEquipmentSales (EquipmentID,Manufacturer,DestinationCountry,SaleDate,Quantity,UnitPrice) VALUES (1,'General Dynamics','Brazil','2019-01-10',5,1200000.00),(2,'Boeing','France','2019-02-15',3,1800000.00),(3,'General Dynamics','Chile','2019-03-20',7,900000.00); | SELECT MIN(UnitPrice) FROM MilitaryEquipmentSales WHERE Manufacturer = 'General Dynamics' AND YEAR(SaleDate) = 2019; |
Who are the top 3 customers based on their purchases of sustainable cosmetics from the UK? | CREATE TABLE Customer_History (customer_id INT,customer_name VARCHAR(50),purchase_year INT,country VARCHAR(50),sustainable_purchase_value DECIMAL(10,2)); INSERT INTO Customer_History (customer_id,customer_name,purchase_year,country,sustainable_purchase_value) VALUES (1,'Sara',2018,'UK',500.50),(2,'Aisha',2019,'US',400.00),(3,'John',2020,'UK',600.00),(4,'Fatima',2021,'UK',800.00),(5,'David',2018,'CA',350.00),(6,'Maryam',2019,'UK',700.00),(7,'Ahmed',2020,'FR',900.00),(8,'Michael',2021,'DE',1000.00),(9,'Noura',2018,'UK',450.00),(10,'Robert',2019,'AU',550.00); | SELECT customer_name FROM Customer_History WHERE country = 'UK' AND sustainable_purchase_value IS NOT NULL GROUP BY customer_id ORDER BY SUM(sustainable_purchase_value) DESC LIMIT 3; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.