instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What were the top 2 countries with the highest average R&D expenditure per year? | CREATE TABLE rd_annual(country varchar(20),year int,expenditure int); INSERT INTO rd_annual(country,year,expenditure) VALUES('US',2019,11000),('US',2020,13000),('Canada',2019,8500),('Canada',2020,9500); | SELECT country, AVG(expenditure) FROM rd_annual GROUP BY country ORDER BY AVG(expenditure) DESC LIMIT 2 |
What is the total duration of all 'Pilates' classes attended by members from the USA? | CREATE TABLE Members (MemberID INT,Age INT,Gender VARCHAR(10),MembershipType VARCHAR(20),Country VARCHAR(50)); INSERT INTO Members (MemberID,Age,Gender,MembershipType,Country) VALUES (1,35,'Female','Premium','USA'),(2,45,'Male','Basic','Canada'),(3,28,'Female','Premium','USA'),(4,32,'Male','Premium','Mexico'),(5,48,'Female','Basic','USA'),(6,38,'Male','Elite','Canada'),(7,25,'Female','Basic','USA'),(8,42,'Male','Premium','Mexico'),(9,50,'Female','Elite','Canada'),(10,22,'Male','Basic','USA'); CREATE TABLE ClassAttendance (MemberID INT,Class VARCHAR(20),Duration INT,Date DATE); INSERT INTO ClassAttendance (MemberID,Class,Duration,Date) VALUES (1,'Cycling',60,'2022-04-01'),(2,'Yoga',45,'2022-04-02'),(3,'Cycling',60,'2022-04-03'),(4,'Yoga',45,'2022-04-04'),(5,'Pilates',90,'2022-04-05'),(6,'Cycling',60,'2022-04-06'),(7,'Yoga',45,'2022-04-07'),(8,'Cycling',60,'2022-04-08'),(9,'Yoga',45,'2022-04-09'),(10,'Pilates',120,'2022-04-10'); | SELECT SUM(Duration) FROM Members JOIN ClassAttendance ON Members.MemberID = ClassAttendance.MemberID WHERE Members.Country = 'USA' AND ClassAttendance.Class = 'Pilates'; |
What is the total number of news articles and opinion pieces published by NewsSourceA and NewsSourceB? | CREATE SCHEMA news;CREATE TABLE NewsSourceA (title varchar(255),type varchar(10));CREATE TABLE NewsSourceB (title varchar(255),type varchar(10));INSERT INTO NewsSourceA (title,type) VALUES ('Article1','news'),('Opinion1','opinion');INSERT INTO NewsSourceB (title,type) VALUES ('Article2','news'),('Opinion2','opinion'); | SELECT COUNT(*) FROM ( (SELECT title, type FROM news.NewsSourceA) UNION (SELECT title, type FROM news.NewsSourceB) ) AS combined |
Show the top 3 players and their total achievements | CREATE TABLE player_achievements (player_id INT,achievement_name VARCHAR(255),achievement_date DATE); CREATE VIEW top_players AS SELECT player_id,COUNT(*) as total_achievements FROM player_achievements GROUP BY player_id ORDER BY total_achievements DESC; | SELECT * FROM top_players; |
What is the average waste generation per day in kilograms for commercial areas in Sydney for the month of August? | CREATE TABLE daily_waste_generation_australia(location VARCHAR(50),date DATE,waste_quantity INT); INSERT INTO daily_waste_generation_australia(location,date,waste_quantity) VALUES ('Sydney','2022-08-01',5000),('Sydney','2022-08-02',5500),('Sydney','2022-08-03',6000),('Melbourne','2022-08-01',4000),('Melbourne','2022-08-02',4500),('Melbourne','2022-08-03',5000); | SELECT AVG(waste_quantity/1000.0) FROM daily_waste_generation_australia WHERE location = 'Sydney' AND date BETWEEN '2022-08-01' AND '2022-08-31'; |
What is the average time to resolution for incidents in the healthcare sector? | CREATE TABLE incidents (id INT,sector VARCHAR(255),time_to_resolution INT); INSERT INTO incidents (id,sector,time_to_resolution) VALUES (1,'healthcare',120),(2,'healthcare',180); | SELECT AVG(time_to_resolution) FROM incidents WHERE sector = 'healthcare'; |
Determine the minimum loading capacity for vessels with a maximum speed greater than 30 knots | CREATE TABLE Vessels (VesselID INT,VesselName VARCHAR(100),MaxSpeed FLOAT,LoadingCapacity FLOAT); INSERT INTO Vessels (VesselID,VesselName,MaxSpeed,LoadingCapacity) VALUES (1,'Ocean Titan',33.5,75000),(2,'Sea Giant',31.3,45000),(3,'Marine Unicorn',34.8,62000),(4,'Sky Wanderer',30.2,80000),(5,'River Princess',28.0,40000),(6,'Lake Explorer',36.0,10000); | SELECT MIN(LoadingCapacity) FROM Vessels WHERE MaxSpeed > 30; |
What is the maximum ocean acidification level recorded in the 'acidification_data' table? | CREATE TABLE acidification_data (sample_id INT,location VARCHAR(255),level FLOAT); | SELECT MAX(level) FROM acidification_data; |
What is the name and location of ongoing disaster response projects in Haiti as of 2022? | CREATE TABLE disaster_response (id INT,location TEXT,year INT,ongoing BOOLEAN); INSERT INTO disaster_response (id,location,year,ongoing) VALUES (1,'Haiti',2022,TRUE),(2,'Philippines',2021,FALSE); | SELECT name, location FROM disaster_response WHERE location = 'Haiti' AND year = 2022 AND ongoing = TRUE; |
Delete the carbon offset program 'Program B' | CREATE TABLE carbon_offset_programs (id INT,name TEXT,region TEXT,participants INT); INSERT INTO carbon_offset_programs (id,name,region,participants) VALUES (1,'Program A','west',500); INSERT INTO carbon_offset_programs (id,name,region,participants) VALUES (2,'Program B','east',350); INSERT INTO carbon_offset_programs (id,name,region,participants) VALUES (3,'Program C','west',600); | DELETE FROM carbon_offset_programs WHERE name = 'Program B'; |
Calculate the total military expenditure for the Asia-Pacific region in 2020. | CREATE TABLE MilitaryExpenditure (expenditure_id INT,country VARCHAR(50),region VARCHAR(50),year INT,expenditure FLOAT); INSERT INTO MilitaryExpenditure (expenditure_id,country,region,year,expenditure) VALUES (1,'China','Asia-Pacific',2020,2500000000),(2,'India','Asia-Pacific',2020,7000000000),(3,'Japan','Asia-Pacific',2020,4500000000),(4,'USA','North America',2020,7250000000); | SELECT SUM(expenditure) FROM MilitaryExpenditure WHERE region = 'Asia-Pacific' AND year = 2020; |
What is the total number of volunteers from Kenya and Uganda who participated in environmental programs? | CREATE TABLE Volunteers (VolunteerID INT,VolunteerName TEXT,Country TEXT); INSERT INTO Volunteers (VolunteerID,VolunteerName,Country) VALUES (1,'Esther Mwangi','Kenya'),(2,'Yusuf Kibira','Uganda'),(3,'Alex Nguyen','Canada'); CREATE TABLE VolunteerPrograms (ProgramID INT,ProgramName TEXT); INSERT INTO VolunteerPrograms (ProgramID,ProgramName) VALUES (1,'Education'),(2,'Environment'); CREATE TABLE VolunteerAssignments (AssignmentID INT,VolunteerID INT,ProgramID INT); INSERT INTO VolunteerAssignments (AssignmentID,VolunteerID,ProgramID) VALUES (1,1,2),(2,2,2); | SELECT COUNT(DISTINCT Volunteers.VolunteerID) AS TotalVolunteers FROM Volunteers INNER JOIN VolunteerAssignments ON Volunteers.VolunteerID = VolunteerAssignments.VolunteerID INNER JOIN VolunteerPrograms ON VolunteerAssignments.ProgramID = VolunteerPrograms.ProgramID WHERE Volunteers.Country IN ('Kenya', 'Uganda') AND VolunteerPrograms.ProgramName = 'Environment'; |
Find the total revenue for all events in the 'theater' category with a capacity greater than 300. | CREATE TABLE events (id INT,name TEXT,category TEXT,price DECIMAL(5,2),capacity INT); INSERT INTO events (id,name,category,price,capacity) VALUES (1,'Play','theater',50.00,600),(2,'Concert','music',20.00,200),(3,'Musical','theater',75.00,800),(4,'Ballet','dance',120.00,350),(5,'Recital','dance',80.00,400); CREATE TABLE event_attendance (event_id INT,attendees INT); INSERT INTO event_attendance (event_id,attendees) VALUES (1,550),(2,180),(3,750),(4,300),(5,420); | SELECT SUM(price * attendees) FROM events JOIN event_attendance ON events.id = event_attendance.event_id WHERE events.category = 'theater' AND capacity > 300; |
What is the average water usage per person in South Africa? | CREATE TABLE water_usage_per_person (country VARCHAR(20),usage FLOAT); INSERT INTO water_usage_per_person (country,usage) VALUES ('South Africa',120); | SELECT AVG(usage) FROM water_usage_per_person WHERE country = 'South Africa'; |
What is the number of animals of each species in the animal population as of 2019? | CREATE TABLE AnimalPopulation(Year INT,Species VARCHAR(20),Animals INT); INSERT INTO AnimalPopulation VALUES (2017,'Tiger',10),(2018,'Tiger',12),(2019,'Tiger',15),(2017,'Lion',20),(2018,'Lion',22),(2019,'Lion',25),(2017,'Elephant',25),(2018,'Elephant',28),(2019,'Elephant',30),(2017,'Giraffe',15),(2018,'Giraffe',18),(2019,'Giraffe',20); | SELECT Species, Animals FROM AnimalPopulation WHERE Year = 2019; |
What is the total revenue generated from memberships in the past year, grouped by membership type? | CREATE TABLE Memberships (ID INT PRIMARY KEY,MembershipType VARCHAR(50),StartDate DATE,EndDate DATE,Revenue DECIMAL(10,2)); | SELECT MembershipType, SUM(Revenue) FROM Memberships WHERE StartDate >= DATEADD(year, -1, GETDATE()) GROUP BY MembershipType; |
How many accidents have occurred for each aircraft model? | CREATE TABLE Accidents (id INT,aircraft_model_id INT,accident_date DATE); CREATE TABLE AircraftModels (id INT,name VARCHAR(50)); CREATE VIEW AccidentsPerModel AS SELECT aircraft_model_id,COUNT(*) as num_accidents FROM Accidents GROUP BY aircraft_model_id; | SELECT AircraftModels.name, AccidentsPerModel.num_accidents FROM AircraftModels JOIN AccidentsPerModel ON AircraftModels.id = AccidentsPerModel.aircraft_model_id; |
How many climate mitigation projects have been implemented in Latin America and the Caribbean? | CREATE TABLE climate_mitigation_projects (id INT,project VARCHAR(50),location VARCHAR(50)); INSERT INTO climate_mitigation_projects (id,project,location) VALUES (1,'Carbon Capture','Latin America'),(2,'Energy Efficiency','Caribbean'),(3,'Public Transportation','Latin America'); | SELECT COUNT(*) FROM climate_mitigation_projects WHERE location IN ('Latin America', 'Caribbean'); |
Which defense diplomacy events involved the most countries in 2018? | CREATE TABLE defense_diplomacy (event_id INT,year INT,country VARCHAR(50)); INSERT INTO defense_diplomacy (event_id,year,country) VALUES (123,2018,'United States'),(123,2018,'Canada'),(456,2018,'Germany'),(456,2018,'France'),(789,2018,'United Kingdom'),(789,2018,'France'),(321,2018,'Brazil'),(321,2018,'Argentina'); | SELECT event_id, COUNT(DISTINCT country) FROM defense_diplomacy WHERE year = 2018 GROUP BY event_id ORDER BY COUNT(DISTINCT country) DESC LIMIT 1; |
Delete all investments with ESG scores less than 70. | CREATE TABLE investments (id INT,sector VARCHAR(20),esg_score FLOAT); INSERT INTO investments (id,sector,esg_score) VALUES (1,'Education',75.00),(2,'Healthcare',70.00),(3,'Renewable Energy',65.00); | DELETE FROM investments WHERE esg_score < 70; |
How many civil cases were handled by attorneys from the 'Downtown' office location? | CREATE TABLE Attorneys (AttorneyID INT,OfficeLocation VARCHAR(255)); INSERT INTO Attorneys (AttorneyID,OfficeLocation) VALUES (1,'Downtown'),(2,'Uptown'),(3,'Downtown'),(4,'Suburbs'); CREATE TABLE Cases (CaseID INT,AttorneyID INT,CaseType VARCHAR(255)); INSERT INTO Cases (CaseID,AttorneyID,CaseType) VALUES (1,1,'Civil'),(2,1,'Criminal'),(3,2,'Civil'),(4,3,'Civil'),(5,4,'Criminal'); | SELECT COUNT(*) FROM Cases JOIN Attorneys ON Cases.AttorneyID = Attorneys.AttorneyID WHERE OfficeLocation = 'Downtown' AND CaseType = 'Civil'; |
What is the total donation amount per donor, for donors who have donated more than once? | CREATE TABLE Donors (DonorID INT,FirstName VARCHAR(20),LastName VARCHAR(20),Email VARCHAR(50),DonationAmount DECIMAL(10,2)); | SELECT DonorID, SUM(DonationAmount) FROM Donors GROUP BY DonorID HAVING COUNT(DonorID) > 1; |
What is the total word count of articles published in Spanish? | CREATE TABLE articles (id INT,title VARCHAR(100),content TEXT,language VARCHAR(10),publish_date DATE); INSERT INTO articles (id,title,content,language,publish_date) VALUES (1,'Artículo 1','Contenido 1','es','2020-01-01'),(2,'Article 2','Content 2','en','2020-01-15'),(3,'Artículo 3','Contenido 3','es','2020-02-01'); | SELECT SUM(word_count) as total_word_count FROM articles WHERE language = 'es'; |
What is the average salary of female professors in the College of Arts and Humanities? | CREATE TABLE professors(id INT,name VARCHAR(50),department VARCHAR(50),salary FLOAT,gender VARCHAR(10)); INSERT INTO professors VALUES (1,'Alice','Arts and Humanities',80000.0,'Female'); INSERT INTO professors VALUES (2,'Bob','Science',85000.0,'Male'); INSERT INTO professors VALUES (3,'Charlie','Arts and Humanities',78000.0,'Female'); | SELECT AVG(salary) FROM professors WHERE department = 'Arts and Humanities' AND gender = 'Female'; |
Identify the top 3 beauty products with the highest sales revenue, excluding products labeled 'organic'. | CREATE TABLE SalesDataOrganic (sale_id INT,product_id INT,sale_revenue FLOAT,is_organic BOOLEAN); INSERT INTO SalesDataOrganic (sale_id,product_id,sale_revenue,is_organic) VALUES (1,1,75,true),(2,2,30,false),(3,3,60,false),(4,4,120,true),(5,5,45,false); | SELECT product_id, sale_revenue FROM SalesDataOrganic WHERE is_organic = false GROUP BY product_id, sale_revenue ORDER BY sale_revenue DESC LIMIT 3; |
What is the total value of transactions for all digital assets in the 'Binance Smart Chain' network? | CREATE TABLE transactions_table (asset_name VARCHAR(20),network VARCHAR(20),transactions_value FLOAT); INSERT INTO transactions_table (asset_name,network,transactions_value) VALUES ('BNB','Binance Smart Chain',100000),('ETH','Binance Smart Chain',200000); | SELECT SUM(transactions_value) FROM transactions_table WHERE network = 'Binance Smart Chain'; |
Get the name and description of all diversity metrics in the "diversity_metrics" table | CREATE TABLE diversity_metrics (metric_id INT PRIMARY KEY,name TEXT,description TEXT); INSERT INTO diversity_metrics (metric_id,name,description) VALUES (1,'Gender diversity','Percentage of employees who identify as female or male'); INSERT INTO diversity_metrics (metric_id,name,description) VALUES (2,'Racial diversity','Percentage of employees who identify as a race other than Caucasian'); | SELECT name, description FROM diversity_metrics; |
Insert a new record into the 'equipment' table for a new shovel from 'Canada' with ID 123 | CREATE TABLE equipment (id INT,type VARCHAR(50),country VARCHAR(50),purchase_date DATE); | INSERT INTO equipment (id, type, country, purchase_date) VALUES (123, 'shovel', 'Canada', CURRENT_DATE); |
What is the maximum salary for data scientists in the "big_data" department of the "data_analytics" company? | CREATE TABLE data_scientists (id INT,name VARCHAR(50),salary FLOAT,department VARCHAR(50)); INSERT INTO data_scientists (id,name,salary,department) VALUES (1,'Fiona',95000,'big_data'),(2,'George',100000,'big_data'),(3,'Hannah',90000,'big_data'),(4,'Iris',85000,'big_data'); | SELECT MAX(salary) FROM data_scientists WHERE department = 'big_data'; |
Show all transactions that were made on a holiday. | CREATE TABLE transactions (id INT,transaction_date DATE); INSERT INTO transactions (id,transaction_date) VALUES (1,'2022-01-01'),(2,'2022-01-08'),(3,'2022-01-15'),(4,'2022-01-22'),(5,'2022-01-29'),(6,'2022-12-25'); | SELECT * FROM transactions WHERE transaction_date IN (DATE('2022-01-01'), DATE('2022-01-17'), DATE('2022-02-21'), DATE('2022-05-30'), DATE('2022-07-04'), DATE('2022-12-25')); |
Delete all records in the 'rural_infrastructure' table where the budget is less than 50000. | CREATE TABLE rural_infrastructure (id INT,project_name VARCHAR(255),budget INT); | DELETE FROM rural_infrastructure WHERE budget < 50000; |
What is the average expenditure per day for tourists visiting Egypt from Europe? | CREATE TABLE daily_expenditures (destination_country VARCHAR(50),visitor_country VARCHAR(50),avg_daily_expenditure FLOAT); INSERT INTO daily_expenditures (destination_country,visitor_country,avg_daily_expenditure) VALUES ('Egypt','Europe',75.0); | SELECT avg_daily_expenditure FROM daily_expenditures WHERE destination_country = 'Egypt' AND visitor_country = 'Europe'; |
Delete records of tourists who visited New Zealand in 2019 from the tourism_stats table. | CREATE TABLE tourism_stats (country VARCHAR(255),year INT,visitors INT,continent VARCHAR(255)); INSERT INTO tourism_stats (country,year,visitors,continent) VALUES ('New Zealand',2019,4000000,'Oceania'); | DELETE FROM tourism_stats WHERE country = 'New Zealand' AND year = 2019; |
What is the total amount of research grants awarded to each college? | CREATE TABLE college (college_name TEXT); INSERT INTO college (college_name) VALUES ('College of Science'),('College of Arts'),('College of Business'); CREATE TABLE research_grants (grant_id INTEGER,college_name TEXT,grant_amount INTEGER); INSERT INTO research_grants (grant_id,college_name,grant_amount) VALUES (1,'College of Science',50000),(2,'College of Business',75000),(3,'College of Arts',30000),(4,'College of Science',100000); | SELECT college_name, SUM(grant_amount) FROM research_grants GROUP BY college_name; |
What is the number of units of each product sold through circular supply chains in the last month? | CREATE TABLE products (product_id int,product_name varchar(50),is_circular boolean);CREATE TABLE sales (sale_id int,product_id int,sale_date date,units_sold int); | SELECT products.product_id, products.product_name, SUM(sales.units_sold) as total_units_sold FROM sales JOIN products ON sales.product_id = products.product_id WHERE products.is_circular = true AND sales.sale_date >= DATEADD(month, -1, GETDATE()) GROUP BY products.product_id, products.product_name; |
How many vessels are there in the 'vessel_performance' table? | CREATE TABLE vessel_performance (id INT,vessel_name VARCHAR(50),speed FLOAT); INSERT INTO vessel_performance (id,vessel_name,speed) VALUES (1,'VesselA',15.5),(2,'VesselB',18.2),(3,'VesselC',17.3); | SELECT COUNT(*) FROM vessel_performance; |
What are the recycling rates for plastic and metal waste types? | CREATE TABLE WasteGenerators (GeneratorID INT,WasteType VARCHAR(20),GeneratedTonnes DECIMAL(5,2),Location VARCHAR(50));CREATE TABLE RecyclingPlants (PlantID INT,WasteType VARCHAR(20),RecycledTonnes DECIMAL(5,2),Location VARCHAR(50));CREATE VIEW RecyclingRates AS SELECT WasteType,AVG(RecycledTonnes/GeneratedTonnes) AS RecyclingRate FROM WasteGenerators WG INNER JOIN RecyclingPlants RP ON WG.WasteType = RP.WasteType GROUP BY WasteType; | SELECT WasteType, RecyclingRate FROM RecyclingRates WHERE WasteType IN ('plastic', 'metal'); |
Insert a new property 'Green Heights' into the 'affordable_housing' table located in 'Portland' with 10 units. | CREATE TABLE affordable_housing (id INT,property_id INT,number_of_units INT,city VARCHAR(50)); INSERT INTO affordable_housing (id,property_id,number_of_units,city) VALUES (1,101,12,'New York'),(2,102,8,'Los Angeles'); | INSERT INTO affordable_housing (property_id, number_of_units, city) VALUES (103, 10, 'Portland'); |
What is the minimum salary for male workers in the technology sector? | CREATE TABLE salaries (id INT,gender TEXT,sector TEXT,salary FLOAT); INSERT INTO salaries (id,gender,sector,salary) VALUES (1,'Male','Technology',60000),(2,'Female','Education',55000),(3,'Male','Technology',65000),(4,'Female','Healthcare',50000); | SELECT MIN(salary) FROM salaries WHERE gender = 'Male' AND sector = 'Technology'; |
What is the total production from oil wells in the 'North Sea'? | CREATE TABLE if not exists oil_production (id INT PRIMARY KEY,well_id INT,year INT,production REAL); INSERT INTO oil_production (id,well_id,year,production) VALUES (1,1,2019,1000),(2,2,2019,2000),(3,3,2018,1500),(4,1,2020,1200); CREATE TABLE if not exists oil_wells (id INT PRIMARY KEY,well_name TEXT,region TEXT); INSERT INTO oil_wells (id,well_name,region) VALUES (1,'Well A','North Sea'),(2,'Well B','North Sea'),(3,'Well C','Barents Sea'); | SELECT SUM(production) FROM oil_production JOIN oil_wells ON oil_production.well_id = oil_wells.id WHERE oil_wells.region = 'North Sea'; |
What is the total water consumption by residential sector in the Missouri river basin, excluding Missouri and Kansas? | CREATE TABLE missouri_river_basin(state VARCHAR(20),sector VARCHAR(20),consumption NUMERIC(10,2)); INSERT INTO missouri_river_basin VALUES ('Nebraska','Residential',2345.67),('Missouri','Residential',3456.78),('Kansas','Residential',4567.89),('Iowa','Residential',5678.90); | SELECT consumption FROM missouri_river_basin WHERE state NOT IN ('Missouri', 'Kansas') AND sector = 'Residential'; |
List all the travel advisories issued for Asian countries in the past 6 months. | CREATE TABLE TravelAdvisories (id INT,country TEXT,issued_date DATE); | SELECT * FROM TravelAdvisories WHERE country IN ('Asia', 'Central Asia', 'Southeast Asia', 'East Asia') AND issued_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH); |
How many exploration projects have been initiated in the 'Africa' region? | CREATE TABLE exploration_projects (project_id INT,project_name VARCHAR(50),region VARCHAR(50)); INSERT INTO exploration_projects (project_id,project_name,region) VALUES (1,'Project X','Africa'),(2,'Project Y','Europe'); | SELECT COUNT(*) FROM exploration_projects WHERE region = 'Africa'; |
What is the average CO2 emission of buildings in the city of Seattle? | CREATE TABLE Buildings (id INT,city VARCHAR(20),co2_emission FLOAT); INSERT INTO Buildings (id,city,co2_emission) VALUES (1,'Seattle',340.5),(2,'Los Angeles',420.6),(3,'Seattle',360.1); | SELECT AVG(co2_emission) FROM Buildings WHERE city = 'Seattle'; |
What is the budget allocated for healthcare services in 'Florida' and 'Georgia'? | CREATE TABLE budget (state VARCHAR(20),service VARCHAR(20),amount INT); INSERT INTO budget (state,service,amount) VALUES ('Florida','Education',40000),('Florida','Healthcare',70000),('Georgia','Healthcare',60000),('Georgia','Education',50000); | SELECT amount FROM budget WHERE state IN ('Florida', 'Georgia') AND service = 'Healthcare'; |
What is the number of farms in the Pacific region using recirculating aquaculture systems and their total biomass? | CREATE TABLE farm_biomass (id INT,farm_id INT,biomass INT,system_type TEXT); INSERT INTO farm_biomass (id,farm_id,biomass,system_type) VALUES (1,1,3000,'Recirculating'),(2,1,3000,'Flow-through'),(3,2,2000,'Recirculating'),(4,2,2000,'Hybrid'),(5,3,4000,'Flow-through'); CREATE TABLE pacific_farms_ras (id INT,farm_id INT,farm_name TEXT,region TEXT,system_type TEXT); INSERT INTO pacific_farms_ras (id,farm_id,farm_name,region,system_type) VALUES (1,1,'FarmA','Pacific','Recirculating'),(2,2,'FarmB','Pacific','Recirculating'),(3,3,'FarmC','Atlantic','Flow-through'),(4,4,'FarmD','Pacific','Hybrid'); | SELECT pacific_farms_ras.region, SUM(farm_biomass.biomass) as total_biomass FROM farm_biomass JOIN pacific_farms_ras ON farm_biomass.farm_id = pacific_farms_ras.farm_id WHERE pacific_farms_ras.region = 'Pacific' AND pacific_farms_ras.system_type = 'Recirculating' GROUP BY pacific_farms_ras.region; |
What is the number of unique donors by month in 2022? | CREATE TABLE donors (id INT,name VARCHAR(50),cause VARCHAR(50),donation_date DATE); INSERT INTO donors (id,name,cause,donation_date) VALUES (1,'John Doe','Education','2022-04-01'),(2,'Jane Smith','Health','2022-04-15'),(3,'Alice Johnson','Environment','2022-05-05'); | SELECT EXTRACT(MONTH FROM donation_date) as month, COUNT(DISTINCT name) as unique_donors FROM donors WHERE donation_date BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY month; |
Which infrastructure types have the highest average maintenance costs in the Midwest? | CREATE TABLE Infrastructure (id INT,type VARCHAR(20),region VARCHAR(20),cost FLOAT); INSERT INTO Infrastructure (id,type,region,cost) VALUES (1,'Bridge','Midwest',25000.0),(2,'Road','Midwest',15000.0),(3,'Bridge','Midwest',30000.0); | SELECT type, AVG(cost) as avg_cost FROM Infrastructure WHERE region = 'Midwest' GROUP BY type ORDER BY avg_cost DESC; |
Show the total revenue for each sport from ticket sales and merchandise for the last financial year. | CREATE TABLE TicketSales (TicketID INT,EventType VARCHAR(10),Revenue DECIMAL(10,2)); CREATE TABLE MerchandiseSales (MerchandiseID INT,ProductType VARCHAR(10),Revenue DECIMAL(10,2)); | SELECT EventType, SUM(Revenue) FROM TicketSales WHERE EventDate >= DATEADD(YEAR, -1, GETDATE()) GROUP BY EventType UNION ALL SELECT ProductType, SUM(Revenue) FROM MerchandiseSales WHERE SaleDate >= DATEADD(YEAR, -1, GETDATE()) GROUP BY ProductType; |
Find the supply chain transparency for Lanthanum and Europium | CREATE TABLE supply_chain_transparency (element VARCHAR(10),supplier VARCHAR(20),transparency INT); INSERT INTO supply_chain_transparency VALUES ('Lanthanum','Supplier A',8),('Lanthanum','Supplier B',7),('Europium','Supplier A',9),('Europium','Supplier C',6); | SELECT element, AVG(transparency) AS avg_transparency FROM supply_chain_transparency GROUP BY element; |
Which creative applications use the AI algorithm named 'Lime'? | CREATE TABLE creative_application (id INT,name VARCHAR(50),description TEXT,algorithm_id INT); INSERT INTO creative_application (id,name,description,algorithm_id) VALUES (1,'AI Drawer','An application that generates...',2); | SELECT creative_application.name FROM creative_application INNER JOIN safe_algorithm ON creative_application.algorithm_id = safe_algorithm.id WHERE safe_algorithm.name = 'Lime'; |
Remove reverse logistics records from last month | CREATE TABLE reverse_logistics(id INT,item VARCHAR(255),date DATE); INSERT INTO reverse_logistics VALUES(1,'ABC','2022-02-15'),(2,'DEF','2022-03-01'); | DELETE FROM reverse_logistics WHERE date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH); |
What is the total number of peacekeeping operations conducted by the 'African Union'? | CREATE TABLE peacekeeping_operations (id INT,organization VARCHAR(255),operation VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO peacekeeping_operations (id,organization,operation,start_date,end_date) VALUES (1,'African Union','Operation Freedom','2002-10-01','2003-04-30'); | SELECT COUNT(*) FROM peacekeeping_operations WHERE organization = 'African Union'; |
Which community health workers did not receive any trainings related to motivational interviewing? | CREATE TABLE CommunityHealthWorkerTrainings (WorkerID INT,Training VARCHAR(50)); INSERT INTO CommunityHealthWorkerTrainings (WorkerID,Training) VALUES (1,'Cultural Competency'),(2,'Mental Health First Aid'),(3,'Crisis Prevention'),(4,'Cultural Competency'),(5,'Motivational Interviewing'),(6,'Cultural Competency'),(7,'Mental Health First Aid'),(8,'Crisis Prevention'),(9,'Motivational Interviewing'),(10,'Cultural Competency'),(11,'Motivational Interviewing'),(12,'Language Access'),(13,'Crisis Prevention'),(14,'Cultural Competency'),(15,'Mental Health First Aid'); | SELECT WorkerID FROM CommunityHealthWorkerTrainings WHERE Training NOT LIKE '%Motivational Interviewing%'; |
Which countries have more than 10 million tourists visiting their natural reserves? | CREATE TABLE natural_reserves (country TEXT,visitors INT); INSERT INTO natural_reserves (country,visitors) VALUES ('Brazil',15000000),('Indonesia',12000000),('China',18000000),('India',11000000); | SELECT country FROM natural_reserves WHERE visitors > 10000000; |
Which restaurants had a daily revenue above $500 on Valentine's Day 2022? | CREATE TABLE revenue (restaurant_name TEXT,daily_revenue NUMERIC,date DATE); INSERT INTO revenue (restaurant_name,daily_revenue,date) VALUES ('ABC Bistro',600,'2022-02-14'),('DEF Diner',400,'2022-02-14'),('GHI Grill',300,'2022-02-14'),('JKL Bistro',550,'2022-02-14'); | SELECT restaurant_name FROM revenue WHERE daily_revenue > 500 AND date = '2022-02-14'; |
What is the percentage of students who passed the open pedagogy exam in each school? | CREATE TABLE school_exam_results (student_id INT,school_id INT,exam_id INT,pass INT); INSERT INTO school_exam_results VALUES (1,1,1,1),(2,1,1,0),(3,2,1,1); | SELECT school_id, COUNT(*) * 100.0 / SUM(COUNT(*)) OVER() as pass_percentage FROM school_exam_results WHERE pass = 1 GROUP BY school_id; |
List the number of hospitals and clinics in each state, sorted by the total number of rural healthcare facilities. | CREATE TABLE facilities (id INT,name VARCHAR,facility_type VARCHAR); INSERT INTO facilities (id,name,facility_type) VALUES (1,'Rural General Hospital','hospital'),(2,'Urban Community Clinic','clinic'); CREATE TABLE state_codes (id INT,state VARCHAR,region VARCHAR); INSERT INTO state_codes (id,state,region) VALUES (1,'Texas','South'),(2,'California','West'); | SELECT state_codes.region, COUNT(facilities.id), SUM(facilities.id) FROM facilities INNER JOIN state_codes ON facilities.id = state_codes.id AND facilities.facility_type IN ('hospital', 'clinic') GROUP BY state_codes.region ORDER BY SUM(facilities.id) DESC; |
How many garments were sold in each store during the month of November 2021? | CREATE TABLE Sales(store VARCHAR(20),sale_date DATE,garment_id INT); INSERT INTO Sales(store,sale_date,garment_id) VALUES ('Eco_Friendly','2021-11-01',1),('Eco_Friendly','2021-11-02',2),('Sustainable_Outlet','2021-11-01',3); | SELECT store, COUNT(*) FROM Sales WHERE MONTH(sale_date) = 11 AND YEAR(sale_date) = 2021 GROUP BY store; |
What's the average environmental impact score for mining operations in each country, in the last 2 years? | CREATE TABLE environmental_impact (id INT PRIMARY KEY,country VARCHAR(50),impact_score INT,operation_date DATE); INSERT INTO environmental_impact (id,country,impact_score,operation_date) VALUES (1,'Canada',75,'2020-01-01'),(2,'Mexico',85,'2019-05-05'),(3,'Canada',65,'2021-03-15'); | SELECT country, AVG(impact_score) as avg_score FROM environmental_impact WHERE operation_date >= DATEADD(year, -2, GETDATE()) GROUP BY country; |
List all VR devices used by players in the 'VRUsers' table. | CREATE TABLE VRUsers (PlayerID INT,VRDevice VARCHAR(20)); INSERT INTO VRUsers (PlayerID,VRDevice) VALUES (1,'Oculus'); INSERT INTO VRUsers (PlayerID,VRDevice) VALUES (2,'HTC Vive'); | SELECT DISTINCT VRDevice FROM VRUsers; |
What is the average number of attendees for dance events in Chicago and San Francisco? | CREATE TABLE Events (event_id INT,event_type VARCHAR(50),location VARCHAR(50)); CREATE TABLE Attendance (attendee_id INT,event_id INT); INSERT INTO Events (event_id,event_type,location) VALUES (1,'Dance','Chicago'),(2,'Theater','Los Angeles'),(3,'Dance','San Francisco'); INSERT INTO Attendance (attendee_id,event_id) VALUES (1,1),(2,1),(3,1),(4,2),(5,3),(6,3); | SELECT AVG(cnt) FROM (SELECT COUNT(DISTINCT A.attendee_id) AS cnt FROM Attendance A INNER JOIN Events E ON A.event_id = E.event_id WHERE E.event_type = 'Dance' AND E.location IN ('Chicago', 'San Francisco')) AS subquery |
What is the total revenue generated from virtual tours in the United States and Canada? | CREATE TABLE VirtualTourRevenue(id INT,country TEXT,revenue FLOAT); INSERT INTO VirtualTourRevenue(id,country,revenue) VALUES (1,'United States',5000.0),(2,'Canada',3000.0); | SELECT SUM(revenue) FROM VirtualTourRevenue WHERE country IN ('United States', 'Canada'); |
What are the names and completion dates of all sustainable building projects in the city of Seattle? | CREATE TABLE Sustainable_Buildings (project_name TEXT,city TEXT,completion_date DATE); INSERT INTO Sustainable_Buildings (project_name,city,completion_date) VALUES ('Solar Panel Installation','Seattle','2022-06-01'),('Green Roof Construction','New York','2021-12-15'); | SELECT project_name, completion_date FROM Sustainable_Buildings WHERE city = 'Seattle'; |
What is the total revenue generated from art sales in the 'Modern Art' category? | CREATE TABLE ArtSales (id INT,category VARCHAR(20),price DECIMAL(5,2)); INSERT INTO ArtSales (id,category,price) VALUES (1,'Modern Art',5000.00),(2,'Contemporary Art',7500.00),(3,'Modern Art',8000.00); | SELECT SUM(price) FROM ArtSales WHERE category = 'Modern Art'; |
List all civic tech issues, their status, and the city they are associated with | CREATE TABLE cities (id INT,name VARCHAR(255)); INSERT INTO cities (id,name) VALUES (1,'New York'),(2,'Los Angeles'),(3,'Chicago'); CREATE TABLE civic_tech_issues (id INT,city_id INT,status VARCHAR(255)); INSERT INTO civic_tech_issues (id,city_id,status) VALUES (1,1,'open'),(2,1,'closed'),(3,2,'open'),(4,3,'closed'),(5,NULL,'open'); | SELECT cti.id, cti.status, cities.name as city_name FROM civic_tech_issues cti LEFT JOIN cities ON cti.city_id = cities.id; |
What is the average flight time for each aircraft model in the Russian and Chinese fleets, grouped by the manufacturer? | CREATE TABLE russian_fleet(model VARCHAR(255),flight_time INT);CREATE TABLE chinese_fleet(model VARCHAR(255),flight_time INT); | SELECT 'Russian' as Manufacturer, AVG(flight_time) as Avg_Flight_Time FROM russian_fleet GROUP BY Manufacturer UNION ALL SELECT 'Chinese' as Manufacturer, AVG(flight_time) as Avg_Flight_Time FROM chinese_fleet GROUP BY Manufacturer; |
Insert a new record in the humanitarian_assistance table for an operation named 'Natural Disaster Relief in Caribbean' in 2021 | CREATE TABLE humanitarian_assistance (assistance_id INT,assistance_name VARCHAR(50),year INT,location VARCHAR(50),description TEXT); | INSERT INTO humanitarian_assistance (assistance_id, assistance_name, year, location, description) VALUES (2, 'Natural Disaster Relief in Caribbean', 2021, 'Caribbean', 'Description of the natural disaster relief operation'); |
What is the average budget for intelligence operations in the Asia-Pacific region? | CREATE TABLE intel_budget (id INT,region VARCHAR(255),operation VARCHAR(255),budget DECIMAL(10,2)); INSERT INTO intel_budget (id,region,operation,budget) VALUES (1,'Asia-Pacific','SIGINT',5000000),(2,'Europe','HUMINT',7000000),(3,'Asia-Pacific','GEOINT',6000000),(4,'Americas','OSINT',8000000); | SELECT AVG(budget) as avg_budget FROM intel_budget WHERE region = 'Asia-Pacific' AND operation = 'SIGINT' OR operation = 'GEOINT'; |
What was the total amount donated by individual donors from the United States in 2021? | CREATE TABLE Donors (id INT,name TEXT,country TEXT,donation_amount DECIMAL(10,2),donation_date DATE); | SELECT SUM(donation_amount) FROM Donors WHERE country = 'United States' AND EXTRACT(YEAR FROM donation_date) = 2021 AND id NOT IN (SELECT DISTINCT donor_id FROM Organization_Donations); |
How many clients have a financial wellbeing score greater than 70? | CREATE TABLE clients(id INT,name TEXT,financial_wellbeing_score INT); | SELECT COUNT(*) FROM clients WHERE financial_wellbeing_score > 70; |
What is the number of animals released back into the wild for each species? | CREATE TABLE release_centers (center_id INT,center_name VARCHAR(50));CREATE TABLE animal_releases (release_id INT,animal_id INT,species_id INT,center_id INT,release_date DATE); INSERT INTO release_centers (center_id,center_name) VALUES (1,'Release Center A'),(2,'Release Center B'); INSERT INTO animal_releases (release_id,animal_id,species_id,center_id,release_date) VALUES (1001,101,1,1,'2021-01-01'),(1002,102,2,1,'2021-03-01'),(1003,103,3,2,'2021-05-01'); | SELECT s.species_name, COUNT(a.animal_id) AS total_released FROM animal_releases a JOIN release_centers rc ON a.center_id = rc.center_id JOIN animal_species s ON a.species_id = s.species_id GROUP BY s.species_name; |
Which hotels in the hotels table offer a spa facility and have a rating greater than 4? | CREATE TABLE hotels (hotel_id INT,name VARCHAR(50),facility VARCHAR(50),rating FLOAT); INSERT INTO hotels (hotel_id,name,facility,rating) VALUES (1,'Hotel X','spa,gym',4.5),(2,'Hotel Y','gym',4.2),(3,'Hotel Z','spa',4.7); | SELECT * FROM hotels WHERE facility LIKE '%spa%' AND rating > 4; |
What is the percentage of students in the "Downtown" school district who participated in lifelong learning programs last year? | CREATE TABLE students (student_id INT,district VARCHAR(20),participated_in_llp BOOLEAN,year INT); INSERT INTO students (student_id,district,participated_in_llp,year) VALUES (1,'Downtown',TRUE,2021),(2,'Downtown',FALSE,2021),(3,'Uptown',TRUE,2021); | SELECT (COUNT(*) FILTER (WHERE participated_in_llp = TRUE)) * 100.0 / COUNT(*) FROM students WHERE district = 'Downtown' AND year = 2021; |
What is the total number of marine species in the Sea of Okhotsk? | CREATE TABLE marine_species (species_name TEXT,region TEXT); INSERT INTO marine_species (species_name,region) VALUES ('Pacific Salmon','Sea of Okhotsk'),('Sea Angel','Sea of Okhotsk'); | SELECT COUNT(*) FROM marine_species WHERE region = 'Sea of Okhotsk'; |
Find the total number of animals in the 'endangered' status | CREATE TABLE animals (id INT,name VARCHAR(50),status VARCHAR(20)); INSERT INTO animals (id,name,status) VALUES (1,'Tiger','Endangered'); INSERT INTO animals (id,name,status) VALUES (2,'Elephant','Vulnerable'); | SELECT COUNT(*) FROM animals WHERE status = 'Endangered'; |
What is the average budget allocated for disability programs per region? | CREATE TABLE Regions (RegionID INT,RegionName VARCHAR(50),Budget DECIMAL(10,2)); INSERT INTO Regions (RegionID,RegionName,Budget) VALUES (1,'Northeast',50000),(2,'Southeast',60000),(3,'Midwest',45000),(4,'Southwest',70000),(5,'West',55000); | SELECT AVG(Budget) as AvgBudget, RegionName FROM Regions GROUP BY RegionName; |
List all creative AI applications and their developers, along with the corresponding AI model names, if available. | CREATE TABLE developer (developer_id INT,developer_name VARCHAR(255)); CREATE TABLE ai_model (model_id INT,model_name VARCHAR(255)); CREATE TABLE creative_ai_application (app_id INT,app_name VARCHAR(255),developer_id INT,model_id INT); INSERT INTO developer (developer_id,developer_name) VALUES (1,'Mr. John Smith'); INSERT INTO ai_model (model_id,model_name) VALUES (1,'GAN Art'); INSERT INTO creative_ai_application (app_id,app_name,developer_id,model_id) VALUES (1,'AI-Generated Music',1,NULL); | SELECT d.developer_name, caa.app_name, am.model_name FROM developer d LEFT JOIN creative_ai_application caa ON d.developer_id = caa.developer_id LEFT JOIN ai_model am ON caa.model_id = am.model_id; |
How many times has each type of event been attended by a unique attendee? | CREATE TABLE EventTypes (id INT,event_type VARCHAR(50)); INSERT INTO EventTypes (id,event_type) VALUES (1,'Art Exhibition'),(2,'Music Concert'),(3,'Theater Play'); CREATE TABLE Events (id INT,event_type INT,attendee INT); INSERT INTO Events (id,event_type,attendee) VALUES (1,1,123),(2,2,234),(3,1,345); | SELECT et.event_type, COUNT(DISTINCT e.attendee) as unique_attendees FROM Events e JOIN EventTypes et ON e.event_type = et.id GROUP BY e.event_type; |
What is the clinic capacity for each province, ranked in descending order? | CREATE TABLE Clinics (ProvinceName VARCHAR(50),ClinicName VARCHAR(50),Capacity INT); INSERT INTO Clinics (ProvinceName,ClinicName,Capacity) VALUES ('Ontario','ClinicA',200),('Ontario','ClinicB',250),('Quebec','ClinicX',150),('British Columbia','ClinicY',200),('British Columbia','ClinicZ',175); | SELECT ProvinceName, SUM(Capacity) AS TotalCapacity FROM Clinics GROUP BY ProvinceName ORDER BY TotalCapacity DESC |
How many carbon offset initiatives were implemented in each district of a smart city? | CREATE TABLE Carbon_Offset_Initiatives (id INT,initiative_name VARCHAR(50),district VARCHAR(50)); INSERT INTO Carbon_Offset_Initiatives (id,initiative_name,district) VALUES (1,'Tree Planting','Downtown'),(2,'Recycling Program','Uptown'),(3,'Solar Panels','Suburbs'); | SELECT district, COUNT(*) FROM Carbon_Offset_Initiatives GROUP BY district; |
What is the average time spent on the court by each basketball player in the NBA? | CREATE TABLE nba_minutes (player_id INT,name VARCHAR(50),team VARCHAR(50),minutes INT); INSERT INTO nba_minutes (player_id,name,team,minutes) VALUES (1,'LeBron James','Los Angeles Lakers',3000); INSERT INTO nba_minutes (player_id,name,team,minutes) VALUES (2,'Stephen Curry','Golden State Warriors',2500); | SELECT name, minutes / 60 AS avg_minutes FROM nba_minutes; |
Delete the 'EndangeredSpecies' table record with the most recent addition date. | CREATE TABLE EndangeredSpecies (Species VARCHAR(50),AdditionDate DATE); INSERT INTO EndangeredSpecies (Species,AdditionDate) VALUES ('Polar Bear','2022-02-15'); | DELETE FROM EndangeredSpecies WHERE AdditionDate = (SELECT MAX(AdditionDate) FROM EndangeredSpecies); |
What is the maximum amount of funding for series B rounds for companies in the "blockchain" sector? | CREATE TABLE funding (company_id INT,round TEXT,amount INT); INSERT INTO funding (company_id,round,amount) VALUES (1,'series A',5000000),(1,'series B',8000000),(2,'series A',3000000),(3,'series A',1000000),(4,'series B',12000000),(5,'series B',6000000),(6,'blockchain',5000000),(6,'series B',15000000); | SELECT MAX(amount) FROM funding JOIN company ON funding.company_id = company.id WHERE company.industry = 'blockchain' AND round = 'series B'; |
Show the top 3 countries with the most brands adopting sustainable materials. | CREATE TABLE Brands (BrandID INT,BrandName VARCHAR(50),Country VARCHAR(50),SustainabilityScore INT); INSERT INTO Brands (BrandID,BrandName,Country,SustainabilityScore) VALUES (1,'Brand1','Country1',85),(2,'Brand2','Country2',70),(3,'Brand3','Country1',90),(4,'Brand4','Country3',60),(5,'Brand5','Country1',80); | SELECT Country, COUNT(BrandID) AS BrandCount FROM Brands WHERE SustainabilityScore > 70 GROUP BY Country ORDER BY BrandCount DESC LIMIT 3; |
What is the maximum number of visitors for an exhibition? | CREATE TABLE Exhibitions (id INT,name TEXT,visitor_count INT); INSERT INTO Exhibitions (id,name,visitor_count) VALUES (1,'Dinosaurs',1000),(2,'Egypt',800); | SELECT MAX(visitor_count) FROM Exhibitions; |
What is the total prize pool for the top 3 games with the highest prize pools in esports events, and their respective ranks? | CREATE TABLE EsportsEvents (EventID INT,EventName VARCHAR(50),GameID INT,EventDate DATE,PrizePool NUMERIC(18,2)); INSERT INTO EsportsEvents (EventID,EventName,GameID,EventDate,PrizePool) VALUES (1,'Fortnite World Cup',1,'2019-07-26',30000000); INSERT INTO EsportsEvents (EventID,EventName,GameID,EventDate,PrizePool) VALUES (2,'Overwatch League Grand Finals',2,'2019-09-29',1500000); INSERT INTO EsportsEvents (EventID,EventName,GameID,EventDate,PrizePool) VALUES (3,'League of Legends World Championship',3,'2019-11-10',24000000); INSERT INTO EsportsEvents (EventID,EventName,GameID,EventDate,PrizePool) VALUES (4,'Dota 2 International',4,'2019-08-20',34500000); | SELECT GameID, SUM(PrizePool) as TotalPrizePool, NTILE(3) OVER (ORDER BY SUM(PrizePool) DESC) as PrizePoolRank FROM EsportsEvents GROUP BY GameID; |
What is the 'total_cost' of 'purchases' from 'vendor1'? | CREATE TABLE purchases (id INT,vendor VARCHAR(50),total_cost FLOAT); INSERT INTO purchases (id,vendor,total_cost) VALUES (1,'vendor1',5000.00),(2,'vendor2',7000.00); | SELECT total_cost FROM purchases WHERE vendor = 'vendor1'; |
Which 'Eye Shadow' products have a sales number greater than 150? | CREATE TABLE Sales (SaleID int,ProductID int,ProductName varchar(50),Category varchar(50),SalesNumber int); INSERT INTO Sales (SaleID,ProductID,ProductName,Category,SalesNumber) VALUES (1,1,'Eye Shadow A','Eye Shadow',100),(2,2,'Eye Shadow B','Eye Shadow',200),(3,3,'Lipstick C','Lipstick',300); | SELECT * FROM Sales WHERE Category = 'Eye Shadow' AND SalesNumber > 150; |
What is the total number of volunteers for each program in the 'volunteers' table, grouped by program name? | CREATE TABLE programs (id INT PRIMARY KEY,name VARCHAR(255)); CREATE TABLE volunteers (id INT PRIMARY KEY,name VARCHAR(255),program_id INT,FOREIGN KEY (program_id) REFERENCES programs(id)); | SELECT program_id, COUNT(*) as total_volunteers FROM volunteers GROUP BY program_id; |
What is the total number of volunteers and staff members in each department? | CREATE TABLE departments (id INT,name VARCHAR(255)); CREATE TABLE volunteers (id INT,department_id INT,joined_date DATE); CREATE TABLE staff (id INT,department_id INT,hired_date DATE); | SELECT departments.name, COUNT(volunteers.id) + COUNT(staff.id) FROM departments LEFT JOIN volunteers ON departments.id = volunteers.department_id LEFT JOIN staff ON departments.id = staff.department_id GROUP BY departments.id; |
What is the maximum number of esports event wins by a team from Europe? | CREATE TABLE EsportsTeams (TeamID INT,TeamName VARCHAR(100),Country VARCHAR(50)); INSERT INTO EsportsTeams (TeamID,TeamName,Country) VALUES (1,'Team Europe','Germany'),(2,'Team Canada','Canada'); CREATE TABLE EsportsEvents (EventID INT,EventName VARCHAR(100),TeamID INT,Wins INT); INSERT INTO EsportsEvents (EventID,EventName,TeamID,Wins) VALUES (1,'EventA',1,3),(2,'EventB',1,2),(3,'EventC',2,1); | SELECT MAX(Wins) FROM EsportsEvents WHERE Country = 'Germany'; |
What is the minimum funding amount received by companies founded in the United States? | CREATE TABLE company (id INT,name VARCHAR(50),country VARCHAR(50)); CREATE TABLE investment_round (id INT,company_id INT,funding_amount INT); INSERT INTO company (id,name,country) VALUES (1,'Acme Corp','USA'); INSERT INTO investment_round (id,company_id,funding_amount) VALUES (1,1,500000); INSERT INTO investment_round (id,company_id,funding_amount) VALUES (2,1,750000); INSERT INTO company (id,name,country) VALUES (2,'Maple Leaf Technologies','Canada'); INSERT INTO investment_round (id,company_id,funding_amount) VALUES (3,2,250000); | SELECT MIN(ir.funding_amount) AS min_funding_amount FROM company c JOIN investment_round ir ON c.id = ir.company_id WHERE c.country = 'USA'; |
What is the difference in the number of cases between the first and last quarter for each case type in the current year? | CREATE TABLE CaseCounts (ID INT,CaseType VARCHAR(20),Year INT,Quarter INT,Count INT); INSERT INTO CaseCounts (ID,CaseType,Year,Quarter,Count) VALUES (1,'Civil',2022,1,100),(2,'Criminal',2022,1,150),(3,'Civil',2022,2,120),(4,'Criminal',2022,2,160),(5,'Civil',2022,3,140),(6,'Criminal',2022,3,170),(7,'Civil',2022,4,150),(8,'Criminal',2022,4,180); | SELECT CaseType, (MAX(Count) OVER (PARTITION BY CaseType) - MIN(Count) OVER (PARTITION BY CaseType)) AS Difference FROM CaseCounts WHERE Year = EXTRACT(YEAR FROM CURRENT_DATE) GROUP BY CaseType, Quarter, Count; |
List the unique neighborhoods in San Francisco with wheelchair-accessible units. | CREATE TABLE sf_units(id INT,address VARCHAR(50),wheelchair_access BOOLEAN); INSERT INTO sf_units VALUES (1,'123 Main St',true),(2,'456 Elm St',false); CREATE TABLE sf_neighborhoods(id INT,name VARCHAR(30),unit_id INT); INSERT INTO sf_neighborhoods VALUES (1,'Downtown',1),(2,'Mission',2); | SELECT DISTINCT sf_neighborhoods.name FROM sf_neighborhoods JOIN sf_units ON sf_neighborhoods.unit_id = sf_units.id WHERE sf_units.wheelchair_access = true; |
What is the average transaction amount per user in France? | CREATE TABLE transactions (user_id INT,transaction_amount DECIMAL(10,2),transaction_date DATE,country VARCHAR(255)); INSERT INTO transactions (user_id,transaction_amount,transaction_date,country) VALUES (1,50.00,'2022-01-01','France'),(2,100.50,'2022-01-02','France'); | SELECT AVG(transaction_amount) as avg_transaction_amount FROM transactions WHERE country = 'France' GROUP BY country; |
What are the names of all the marine species in 'marine_species' table that are found in the Pacific Ocean? | CREATE TABLE marine_species (id INT,species_name VARCHAR(50),ocean VARCHAR(50)); | SELECT species_name FROM marine_species WHERE ocean = 'Pacific Ocean'; |
Find the total expenditure by tourists from Italy in each destination? | CREATE TABLE tourism_stats (visitor_country VARCHAR(20),destination VARCHAR(20),expenditure DECIMAL(10,2)); INSERT INTO tourism_stats (visitor_country,destination,expenditure) VALUES ('Italy','Rome',400.00),('Italy','Rome',350.00),('Italy','Florence',300.00),('Italy','Venice',450.00); | SELECT destination, SUM(expenditure) FROM tourism_stats WHERE visitor_country = 'Italy' GROUP BY destination; |
What is the change in the quantity of each product sold, compared to the previous day, for the last 7 days? | CREATE TABLE daily_sales (sale_date DATE,product_id INT,quantity INT); INSERT INTO daily_sales VALUES ('2022-06-01',1,50),('2022-06-01',2,30),('2022-06-02',1,75),('2022-06-02',2,40),('2022-06-03',1,80),('2022-06-03',2,35),('2022-06-04',1,90),('2022-06-04',2,45); | SELECT sale_date, product_id, quantity, LAG(quantity, 1) OVER (PARTITION BY product_id ORDER BY sale_date) as prev_quantity, quantity - LAG(quantity, 1) OVER (PARTITION BY product_id ORDER BY sale_date) as quantity_change FROM daily_sales WHERE sale_date >= DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY) ORDER BY sale_date, product_id; |
What is the minimum energy efficiency rating of buildings in California that have received energy efficiency upgrades since 2010? | CREATE TABLE buildings (id INT,name VARCHAR(50),state VARCHAR(50),rating FLOAT,upgrade_year INT); | SELECT MIN(rating) FROM buildings WHERE state = 'California' AND upgrade_year >= 2010; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.