instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
Which community health workers have served the most patients with limited English proficiency in the last two years? | CREATE TABLE community_health_workers_patients (worker_id INT,limited_english BOOLEAN,last_two_years BOOLEAN); INSERT INTO community_health_workers_patients (worker_id,limited_english,last_two_years) VALUES (1,TRUE,TRUE),(2,FALSE,TRUE),(3,TRUE,FALSE); | SELECT c.worker_id, c.limited_english FROM community_health_workers_patients c WHERE c.last_two_years = TRUE AND c.limited_english = TRUE; |
Which regions grow 'Wheat' in the 'crop_farmers' table? | CREATE TABLE crop_farmers (farmer_id INT,crop VARCHAR(50),region VARCHAR(50)); INSERT INTO crop_farmers (farmer_id,crop,region) VALUES (1,'Wheat','Great Plains'),(2,'Corn','Midwest'),(3,'Soybean','Midwest'); | SELECT region FROM crop_farmers WHERE crop = 'Wheat'; |
What is the average water temperature in tropical aquaculture farms in the past 6 months, grouped by month and region, and only showing records with a temperature above 28 degrees Celsius? | CREATE TABLE if not exists farms (id int,name varchar(50),region varchar(50),type varchar(50)); INSERT INTO farms (id,name,region,type) VALUES (1,'Farm A','Asia','Tropical'); INSERT INTO farms (id,name,region,type) VALUES (2,'Farm B','South America','Tropical'); CREATE TABLE if not exists water_temperature (id int,farm_id int,date date,temperature float); INSERT INTO water_temperature (id,farm_id,date,temperature) VALUES (1,1,'2022-01-01',29.5); INSERT INTO water_temperature (id,farm_id,date,temperature) VALUES (2,1,'2022-02-01',28.8); INSERT INTO water_temperature (id,farm_id,date,temperature) VALUES (3,2,'2022-01-01',27.9); | SELECT AVG(temperature) as avg_temperature, DATE_FORMAT(date, '%Y-%m') as month, region FROM farms f JOIN water_temperature w ON f.id = w.farm_id WHERE temperature > 28 AND type = 'Tropical' AND date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH) GROUP BY month, region; |
Which auto show has the most electric vehicle models on display? | CREATE TABLE AutoShow (id INT,name VARCHAR(255),location VARCHAR(255),country VARCHAR(255),num_electric_vehicles INT); INSERT INTO AutoShow (id,name,location,country,num_electric_vehicles) VALUES (1,'Detroit Auto Show','Detroit','USA',50); | SELECT name, location, MAX(num_electric_vehicles) FROM AutoShow; |
Show all agricultural projects in 'Rural Kenya' | CREATE TABLE agricultural_projects (id INT PRIMARY KEY,name VARCHAR(100),location VARCHAR(50),funding_source VARCHAR(50),start_date DATE,end_date DATE); INSERT INTO agricultural_projects (id,name,location,funding_source,start_date,end_date) VALUES (1,'Solar Powered Irrigation','Rural Kenya','World Bank','2022-01-01','2023-12-31'),(2,'Crop Diversification','Rural Peru','USAID','2022-06-15','2024-06-14'); | SELECT * FROM agricultural_projects WHERE location = 'Rural Kenya'; |
Insert a new record for a soldier with Name 'Mary Johnson', Rank 'Lieutenant', and EntryYear 2020. | CREATE TABLE Soldiers (SoldierID INT,Name VARCHAR(50),Rank VARCHAR(20),EntryYear INT); INSERT INTO Soldiers (SoldierID,Name,Rank,EntryYear) VALUES (1,'John Doe','Captain',1995),(2,'Jane Smith','Lieutenant',2002); | INSERT INTO Soldiers (Name, Rank, EntryYear) VALUES ('Mary Johnson', 'Lieutenant', 2020); |
Find the number of animals per species in the "animal_population" table | CREATE TABLE animal_population (species VARCHAR(255),animal_count INT); | SELECT species, SUM(animal_count) FROM animal_population GROUP BY species; |
What is the total carbon sequestration for each species? | CREATE TABLE species (id INT,name VARCHAR(255),carbon_sequestration FLOAT); INSERT INTO species (id,name,carbon_sequestration) VALUES (1,'Species1',123.45); INSERT INTO species (id,name,carbon_sequestration) VALUES (2,'Species2',234.56); CREATE TABLE region (id INT,name VARCHAR(255)); INSERT INTO region (id,name) VALUES (1,'Region1'); INSERT INTO region (id,name) VALUES (2,'Region2'); | SELECT s.name, SUM(s.carbon_sequestration) as total_carbon FROM species s GROUP BY s.name; |
List the names of Esports events that have had more than 1000 participants. | CREATE TABLE Events (EventID INT,EventName VARCHAR(20),Game VARCHAR(10),Participants INT); INSERT INTO Events (EventID,EventName,Game,Participants) VALUES (1,'Event1','Esports',1200); INSERT INTO Events (EventID,EventName,Game,Participants) VALUES (2,'Event2','Esports',800); | SELECT EventName FROM Events WHERE Game = 'Esports' AND Participants > 1000; |
What is the average recycling rate in percentage for the bottom 2 material types in 2019? | CREATE TABLE recycling_rates (material VARCHAR(255),year INT,rate FLOAT); INSERT INTO recycling_rates (material,year,rate) VALUES ('Plastic',2019,12.0),('Glass',2019,22.0),('Paper',2019,35.0),('Metal',2019,45.0); | SELECT r.material, AVG(r.rate) as avg_rate FROM recycling_rates r WHERE r.year = 2019 AND r.material IN (SELECT material FROM recycling_rates WHERE year = 2019 ORDER BY rate LIMIT 2 OFFSET 2) GROUP BY r.material; |
What is the average value of artworks in the 'artworks' table? | CREATE TABLE artworks (artwork_id INT,title VARCHAR(50),year INT,artist_id INT,value INT,country VARCHAR(50)); INSERT INTO artworks (artwork_id,title,year,artist_id,value,country) VALUES (1,'Guernica',1937,1,20000000,'Spain'); INSERT INTO artworks (artwork_id,title,year,artist_id,value,country) VALUES (2,'Study for Portrait of Lucian Freud',1969,2,15000000,'UK'); | SELECT AVG(value) FROM artworks; |
Which underwater volcanoes are within the African plate? | CREATE TABLE AfricanPlate (volcano_name TEXT,location TEXT); INSERT INTO AfricanPlate (volcano_name,location) VALUES ('Tagoro','Atlantic Ocean'),('Nazca','Atlantic Ocean'); | SELECT * FROM AfricanPlate WHERE location LIKE '%Atlantic Ocean%'; |
How many unique countries are represented in the music_streaming table? | CREATE TABLE music_streaming (id INT,user_id INT,song_id INT,country VARCHAR(255),timestamp TIMESTAMP); | SELECT COUNT(DISTINCT country) FROM music_streaming; |
Increase prevalence by 10 for disease 'Flu' in 'disease_data' | CREATE TABLE if not exists 'disease_data' (id INT,state TEXT,disease TEXT,prevalence INT,PRIMARY KEY(id)); | UPDATE 'disease_data' SET prevalence = prevalence + 10 WHERE disease = 'Flu'; |
What is the count of community health workers serving mental health patients in Florida? | CREATE TABLE community_health_workers (worker_id INT,worker_name TEXT,state TEXT); INSERT INTO community_health_workers (worker_id,worker_name,state) VALUES (1,'Jamila','Florida'),(2,'Keith','California'); CREATE TABLE mental_health_patients (patient_id INT,worker_id INT,diagnosis TEXT); INSERT INTO mental_health_patients (patient_id,worker_id,diagnosis) VALUES (101,1,'Anxiety'),(102,1,'Depression'),(201,NULL,'Bipolar'); | SELECT COUNT(DISTINCT c.worker_id) FROM community_health_workers c JOIN mental_health_patients m ON c.worker_id = m.worker_id WHERE c.state = 'Florida' AND m.diagnosis IS NOT NULL; |
What is the total billing amount for cases won by attorneys who joined the firm in 2018 or later? | CREATE TABLE Attorneys (AttorneyID INT,JoinYear INT,BillingAmount DECIMAL); INSERT INTO Attorneys (AttorneyID,JoinYear,BillingAmount) VALUES (1,2016,5000.00),(2,2018,3000.00),(3,2015,4000.00); CREATE TABLE Cases (CaseID INT,AttorneyID INT,CaseOutcome VARCHAR(10)); INSERT INTO Cases (CaseID,AttorneyID,CaseOutcome) VALUES (101,1,'Lost'),(102,2,'Won'),(103,3,'Won'); | SELECT SUM(BillingAmount) FROM Attorneys JOIN Cases ON Attorneys.AttorneyID = Cases.AttorneyID WHERE CaseOutcome = 'Won' AND JoinYear >= 2018; |
What was the total investment in agricultural innovation projects in Latin America in the past 5 years? | CREATE TABLE investment (id INT,project TEXT,location TEXT,investment_amount INT,year INT); INSERT INTO investment (id,project,location,investment_amount,year) VALUES (1,'Potato Seed Project','Peru',200000,2018),(2,'Corn Seed Project','Brazil',300000,2019),(3,'Rice Seed Project','Colombia',150000,2017),(4,'Wheat Seed Project','Argentina',250000,2020); | SELECT SUM(investment_amount) FROM investment WHERE location LIKE 'Latin%' AND year BETWEEN 2017 AND 2022; |
What is the historical context of artifacts analyzed by French researchers? | CREATE TABLE ArtifactContext (ArtifactID INT,ArtifactName TEXT,HistoricalContext TEXT); INSERT INTO ArtifactContext (ArtifactID,ArtifactName,HistoricalContext) VALUES (1,'Pompeii Amphora','Ancient Roman trade'); | SELECT ArtifactName, HistoricalContext FROM ArtifactContext INNER JOIN Artifacts ON ArtifactContext.ArtifactID = Artifacts.ArtifactID WHERE Artifacts.AnalyzedBy = 'France'; |
What is the total number of users in Japan and South Korea who have interacted with a specific ad, and what was the total engagement time for these users? | CREATE TABLE ad_interactions (user_id INT,ad_id INT,country VARCHAR(2),interaction_time FLOAT); INSERT INTO ad_interactions (user_id,ad_id,country,interaction_time) VALUES (1,1001,'JP',25.3),(2,1001,'KR',30.5); | SELECT SUM(CASE WHEN country IN ('JP', 'KR') THEN 1 ELSE 0 END) as total_users, SUM(interaction_time) as total_engagement_time FROM ad_interactions WHERE ad_id = 1001; |
What is the total number of underwater volcanoes in the Pacific Ocean? | CREATE TABLE pacific_volcanoes (name VARCHAR(255),location VARCHAR(255)); | SELECT COUNT(*) FROM pacific_volcanoes WHERE location = 'Pacific Ocean'; |
List the TV shows with the highest marketing expenses for each country and their corresponding production companies. | CREATE TABLE TVShows (ShowID INT,Title VARCHAR(255),Country VARCHAR(50),MarketingExpenses DECIMAL(10,2),ProductionCompany VARCHAR(255)); CREATE TABLE ProductionCompanies (CompanyID INT,CompanyName VARCHAR(255)); | SELECT T1.Title, T1.Country, T1.MarketingExpenses, T2.CompanyName FROM TVShows T1 INNER JOIN (SELECT Country, MAX(MarketingExpenses) AS Max_Expenses FROM TVShows GROUP BY Country) T2 ON T1.Country = T2.Country AND T1.MarketingExpenses = T2.Max_Expenses INNER JOIN ProductionCompanies T3 ON T1.ProductionCompany = T3.CompanyName; |
Who is the youngest astronaut to have participated in a space mission? | CREATE TABLE Astronauts (name VARCHAR(30),age INT,mission_name VARCHAR(30)); INSERT INTO Astronauts (name,age,mission_name) VALUES ('Gus Grissom',36,'Mercury-Redstone 4'),('John Glenn',40,'Friendship 7'); | SELECT name, age FROM Astronauts ORDER BY age LIMIT 1; |
How many community health workers identify as Two-Spirit or Native Hawaiian? | CREATE TABLE community_health_workers (worker_id INT,name TEXT,identity TEXT); INSERT INTO community_health_workers (worker_id,name,identity) VALUES (1,'John Doe','Straight'),(2,'Jane Smith','Two-Spirit'),(3,'Maria Garcia','Native Hawaiian'); | SELECT COUNT(*) FROM community_health_workers WHERE identity IN ('Two-Spirit', 'Native Hawaiian'); |
Delete all records of fans from a specific country. | CREATE TABLE fans (fan_id INT,name VARCHAR(100),country VARCHAR(100)); INSERT INTO fans (fan_id,name,country) VALUES (1,'John Doe','USA'); INSERT INTO fans (fan_id,name,country) VALUES (2,'Jane Smith','Canada'); INSERT INTO fans (fan_id,name,country) VALUES (3,'Jose Garcia','Mexico'); | DELETE FROM fans WHERE country = 'USA'; |
Find the yttrium production difference between 2018 and 2017 for each refiner. | CREATE TABLE YttriumProduction (Refiner VARCHAR(50),Year INT,Production FLOAT); INSERT INTO YttriumProduction(Refiner,Year,Production) VALUES ('RefinerX',2017,123.5),('RefinerX',2018,127.8),('RefinerX',2019,134.5),('RefinerY',2017,109.1),('RefinerY',2018,113.5),('RefinerY',2019,119.8); | SELECT Refiner, Production - LAG(Production) OVER (PARTITION BY Refiner ORDER BY Year) as Difference FROM YttriumProduction WHERE Refiner IN ('RefinerX', 'RefinerY'); |
What is the annual change in water usage for agricultural users in Colorado? | CREATE TABLE annual_water_usage (year INT,user_type VARCHAR(10),water_usage INT); | SELECT EXTRACT(YEAR FROM date_trunc('year', date)) as year, AVG(water_usage) - LAG(AVG(water_usage)) OVER (ORDER BY year) as annual_change FROM annual_water_usage JOIN (SELECT date_trunc('year', date) as date, user_type FROM water_consumption_by_day) tmp ON annual_water_usage.year = EXTRACT(YEAR FROM tmp.date) WHERE user_type = 'agricultural' AND state = 'Colorado' GROUP BY year; |
What is the average number of tweets per day for users who have opted in to location sharing? | CREATE TABLE tweets (tweet_id INT,user_id INT,tweet_date DATE);CREATE TABLE user_settings (user_id INT,location_sharing BOOLEAN); | SELECT AVG(num_tweets_per_day) as avg_num_tweets FROM (SELECT u.user_id, COUNT(t.tweet_id) as num_tweets_per_day FROM user_settings u JOIN tweets t ON u.user_id = t.user_id WHERE u.location_sharing = TRUE GROUP BY u.user_id) subquery; |
Find the total quantity of each strain sold in California and Washington. | CREATE TABLE sales (sale_id INT,dispensary_id INT,strain VARCHAR(255),quantity INT);CREATE TABLE dispensaries (dispensary_id INT,name VARCHAR(255),state VARCHAR(255)); | SELECT strain, SUM(quantity) as total_quantity FROM sales JOIN dispensaries ON sales.dispensary_id = dispensaries.dispensary_id WHERE state IN ('California', 'Washington') GROUP BY strain; |
List all products that contain an ingredient sourced from a country with a high safety record, and the associated safety score of that country. | CREATE TABLE ingredient_safety (ingredient_id INT,country_safety_score INT); INSERT INTO ingredient_safety (ingredient_id,country_safety_score) VALUES (1,95),(2,90),(3,85),(4,92),(5,88),(6,97),(7,80),(8,96),(9,85),(10,93),(11,95),(12,98); CREATE TABLE product_ingredients (product_id INT,ingredient_id INT); INSERT INTO product_ingredients (product_id,ingredient_id) VALUES (1,1),(1,2),(2,3),(2,4),(3,5),(3,6),(4,7),(4,8),(5,9),(5,10),(6,11),(6,12); | SELECT p.product_name, p.brand_name, i.country_name, i.country_safety_score FROM product_ingredients pi INNER JOIN cosmetic_products p ON pi.product_id = p.product_id INNER JOIN ingredient_sourcing i ON pi.ingredient_id = i.ingredient_id INNER JOIN ingredient_safety s ON i.country_name = s.country_name WHERE s.country_safety_score >= 90; |
What is the average age of patients diagnosed with diabetes in the rural county of "Bumpkinsville"? | CREATE TABLE Patients (PatientID INT,Age INT,Gender VARCHAR(10),RuralHealthFacility VARCHAR(20),Disease VARCHAR(20)); INSERT INTO Patients (PatientID,Age,Gender,RuralHealthFacility,Disease) VALUES (1,55,'Male','Bumpkinsville RHF','Diabetes'); | SELECT AVG(Age) FROM Patients WHERE RuralHealthFacility = 'Bumpkinsville RHF' AND Disease = 'Diabetes'; |
Delete fan records from the "fans" table for fans who are over 60 | CREATE TABLE fans (id INT PRIMARY KEY,name VARCHAR(50),age INT,gender VARCHAR(10),state VARCHAR(50)); | DELETE FROM fans WHERE age > 60; |
What is the average water usage in Texas over the last 5 years? | CREATE TABLE water_usage (state VARCHAR(20),year INT,volume_m3 INT); INSERT INTO water_usage (state,year,volume_m3) VALUES ('Texas',2017,25000000),('Texas',2018,26000000),('Texas',2019,27000000),('Texas',2020,28000000),('Texas',2021,29000000); | SELECT AVG(volume_m3) FROM water_usage WHERE state = 'Texas' AND year BETWEEN 2017 AND 2021; |
Increase the price of all products made from recycled materials by 10%. | CREATE TABLE PRODUCT (id INT PRIMARY KEY,name TEXT,material TEXT,quantity INT,price INT,country TEXT,certifications TEXT,is_recycled BOOLEAN); INSERT INTO PRODUCT (id,name,material,quantity,price,country,certifications,is_recycled) VALUES (1,'Organic Cotton Shirt','Organic Cotton',30,50,'USA','GOTS,Fair Trade',FALSE); INSERT INTO PRODUCT (id,name,material,quantity,price,country,certifications,is_recycled) VALUES (2,'Recycled Poly Shoes','Recycled Polyester',25,75,'Germany','BlueSign',TRUE); INSERT INTO PRODUCT (id,name,material,quantity,price,country) VALUES (3,'Bamboo T-Shirt','Bamboo',15,30,'China'); INSERT INTO PRODUCT (id,name,material,quantity,price,country,certifications,is_recycled) VALUES (4,'GOTS Certified Organic Shoes','Organic Cotton',20,60,'Italy','GOTS',TRUE); | UPDATE PRODUCT SET price = price * 1.1 WHERE is_recycled = TRUE; |
Who has spent the most time in space? | CREATE TABLE astronauts(name TEXT,missions INTEGER,days_in_space REAL); INSERT INTO astronauts(name,missions,days_in_space) VALUES('Neil Armstrong',1,265.5),('Buzz Aldrin',1,216.4); | SELECT name, MAX(days_in_space) FROM astronauts; |
What is the total number of autonomous driving research papers published by Asian authors in 2020? | CREATE TABLE ResearchPapers(Id INT,Title VARCHAR(50),Author VARCHAR(50),Year INT,Domain VARCHAR(50)); INSERT INTO ResearchPapers(Id,Title,Author,Year,Domain) VALUES (1,'Autonomous Driving Algorithms','Li,X.',2020,'Asia'); INSERT INTO ResearchPapers(Id,Title,Author,Year,Domain) VALUES (2,'Deep Learning for Self-Driving Cars','Kim,Y.',2020,'Asia'); | SELECT COUNT(*) FROM ResearchPapers WHERE Year = 2020 AND Domain = 'Asia'; |
Add a new "DiveSite" record with a name of Blue Hole and a depth of 120 meters | CREATE TABLE DiveSite (Name VARCHAR(50) PRIMARY KEY,Depth INT); | INSERT INTO DiveSite (Name, Depth) VALUES ('Blue Hole', 120); |
What is the average carbon footprint of tourists visiting the Maldives? | CREATE TABLE carbon_footprint (name VARCHAR(255),location VARCHAR(255),year INT,footprint DECIMAL(5,2)); INSERT INTO carbon_footprint (name,location,year,footprint) VALUES ('Resort Stay','Maldives',2015,21.34),('Liveaboard','Maldives',2015,12.15); | SELECT AVG(footprint) FROM carbon_footprint WHERE location = 'Maldives'; |
Which community health workers have the most experience? | CREATE TABLE community_health_workers (id INT,name VARCHAR(50),race VARCHAR(50),ethnicity VARCHAR(50),years_of_experience INT); INSERT INTO community_health_workers (id,name,race,ethnicity,years_of_experience) VALUES (1,'John Doe','White','Not Hispanic or Latino',5),(2,'Jane Smith','Black or African American','Not Hispanic or Latino',10); | SELECT name, years_of_experience, RANK() OVER (ORDER BY years_of_experience DESC) as rank FROM community_health_workers; |
Which countries have researchers in the database? | CREATE TABLE researchers (id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO researchers (id,name,country) VALUES (1,'Sanna Simula','Finland'),(2,'Kristian Olsen','Greenland'),(3,'Agnes Sorensen','Greenland'),(4,'Joseph Okpik','Canada'); | SELECT DISTINCT country FROM researchers; |
Find the unique legal precedents that have been cited in cases from both the 'civil' and 'criminal' case type tables. | CREATE TABLE legal_precedents (precedent_id INT,precedent_name VARCHAR(100)); CREATE TABLE civil_cases (case_id INT,case_type VARCHAR(20),precedent_id INT); CREATE TABLE criminal_cases (case_id INT,case_type VARCHAR(20),precedent_id INT); | SELECT precedent_name FROM legal_precedents WHERE precedent_id IN (SELECT precedent_id FROM civil_cases) INTERSECT SELECT precedent_name FROM legal_precedents WHERE precedent_id IN (SELECT precedent_id FROM criminal_cases); |
How many players play sports games and are younger than 25? | CREATE TABLE PlayerDemographics (PlayerID INT,Age INT,GamePreference VARCHAR(20)); INSERT INTO PlayerDemographics (PlayerID,Age,GamePreference) VALUES (1,24,'sports'); | SELECT COUNT(*) FROM PlayerDemographics WHERE Age < 25 AND GamePreference = 'sports'; |
What is the total quantity of minerals extracted by small-scale mines in Zambia in 2022? | CREATE TABLE MineTypes (MineID int,MineType varchar(50)); INSERT INTO MineTypes VALUES (1,'Small-scale Mine'),(2,'Medium-scale Mine'),(3,'Large-scale Mine'); CREATE TABLE ExtractionData (MineID int,ExtractionDate date,Material varchar(10),Quantity int); INSERT INTO ExtractionData VALUES (1,'2022-01-01','Gold',1000),(1,'2022-01-15','Gold',1500),(2,'2022-01-30','Gold',800),(1,'2022-02-05','Gold',1200),(3,'2022-03-01','Gold',1000); | SELECT mt.MineType, SUM(ed.Quantity) as TotalExtraction FROM ExtractionData ed JOIN MineTypes mt ON ed.MineID = mt.MineID WHERE ed.ExtractionDate BETWEEN '2022-01-01' AND '2022-12-31' AND mt.MineType = 'Small-scale Mine' AND ed.Material = 'Gold' GROUP BY mt.MineType; |
What is the minimum depth of all deep-sea trenches in the Indian Ocean? | CREATE TABLE deep_sea_trenches (name VARCHAR(255),region VARCHAR(255),depth FLOAT);INSERT INTO deep_sea_trenches (name,region,depth) VALUES ('Trench 1','Indian Ocean',6000),('Trench 2','Atlantic Ocean',7000),('Trench 3','Indian Ocean',5000); | SELECT MIN(depth) FROM deep_sea_trenches WHERE region = 'Indian Ocean'; |
What is the maximum number of kills achieved by a player in a single match? | CREATE TABLE MatchStats (MatchID int,PlayerID int,Kills int,Deaths int); INSERT INTO MatchStats VALUES (1,1,15,5),(2,2,10,8),(3,1,20,10),(4,3,12,7); | SELECT PlayerID, MAX(Kills) as MaxKills FROM MatchStats GROUP BY PlayerID; |
What is the maximum network investment for the telecom provider in the Western region? | CREATE TABLE network_investments (investment FLOAT,region VARCHAR(20)); INSERT INTO network_investments (investment,region) VALUES (120000,'Western'),(150000,'Northern'),(180000,'Western'); | SELECT MAX(investment) FROM network_investments WHERE region = 'Western'; |
What is the total revenue generated from ticket sales for exhibitions in Tokyo, Japan in 2019?' | CREATE TABLE Exhibitions (ID INT,Title VARCHAR(50),City VARCHAR(20),Country VARCHAR(20),Date DATE,TicketPrice INT); INSERT INTO Exhibitions (ID,Title,City,Country,Date,TicketPrice) VALUES (1,'Traditional Japanese Art','Tokyo','Japan','2019-03-01',15); CREATE TABLE TicketSales (ID INT,ExhibitionID INT,Quantity INT,Date DATE); INSERT INTO TicketSales (ID,ExhibitionID,Quantity,Date) VALUES (1,1,500,'2019-03-01'); | SELECT SUM(TicketSales.Quantity * Exhibitions.TicketPrice) FROM TicketSales INNER JOIN Exhibitions ON TicketSales.ExhibitionID = Exhibitions.ID WHERE Exhibitions.City = 'Tokyo' AND Exhibitions.Country = 'Japan' AND Exhibitions.Date BETWEEN '2019-01-01' AND '2019-12-31'; |
Display the average mass of space debris in the space_debris table for the debris items from the USA | CREATE TABLE space_debris (id INT,name VARCHAR(50),type VARCHAR(50),country VARCHAR(50),launch_date DATE,mass FLOAT); | SELECT AVG(mass) as average_mass FROM space_debris WHERE country = 'USA'; |
Update the salary of all employees in the accounting department | CREATE TABLE Employees (EmployeeID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50),Salary DECIMAL(10,2),LeftCompany BOOLEAN); | UPDATE Employees SET Salary = 65000 WHERE Department = 'Accounting'; |
List restaurants that have had a food safety violation in the last 3 months | CREATE TABLE inspections (inspection_id INT PRIMARY KEY,restaurant_id INT,inspection_date DATE,violation_code INT,description VARCHAR(255)); | SELECT r.restaurant_id, r.restaurant_name FROM restaurants r JOIN inspections i ON r.restaurant_id = i.restaurant_id WHERE i.inspection_date >= DATEADD(month, -3, GETDATE()) AND i.violation_code IS NOT NULL; |
What is the total revenue generated by each mobile network in Italy for the year 2020? | CREATE TABLE italy_data (year INT,network VARCHAR(15),revenue FLOAT); INSERT INTO italy_data (year,network,revenue) VALUES (2020,'Vodafone',15000000),(2020,'TIM',12000000),(2020,'Wind Tre',13000000); | SELECT network, SUM(revenue) as total_revenue FROM italy_data WHERE year = 2020 GROUP BY network; |
Identify the total quantity of fruits and vegetables that were supplied by local farmers in the last month? | CREATE TABLE Farmers(FarmerID INT,Name VARCHAR(50),Local BOOLEAN);CREATE TABLE FruitsVeggies(FruitVeggieID INT,FarmerID INT,Product VARCHAR(50),Quantity INT,DeliveryDate DATE);INSERT INTO Farmers VALUES (1,'Amy Johnson',TRUE),(2,'Bob Smith',FALSE);INSERT INTO FruitsVeggies VALUES (1,1,'Apples',300,'2022-05-15'),(2,1,'Carrots',400,'2022-05-01'),(3,2,'Bananas',500,'2022-04-20'); | SELECT SUM(Quantity) FROM FruitsVeggies WHERE DeliveryDate >= DATEADD(month, -1, GETDATE()) AND Local = TRUE; |
Find the number of veterans employed by age group and gender, in each state? | CREATE TABLE VeteranEmployment (VEID INT,Age INT,Gender VARCHAR(10),State VARCHAR(20),NumVeterans INT); INSERT INTO VeteranEmployment (VEID,Age,Gender,State,NumVeterans) VALUES (1,25,'Male','California',100),(2,35,'Female','Texas',200),(3,45,'Male','Florida',150); | SELECT State, Gender, Age, COUNT(NumVeterans) as NumVeterans FROM VeteranEmployment GROUP BY State, Gender, Age; |
What was the total quantity of 'Dress' items sold in 'Paris' in 2021? | CREATE TABLE sales(item VARCHAR(20),location VARCHAR(20),quantity INT,sale_date DATE); INSERT INTO sales (item,location,quantity,sale_date) VALUES ('Dress','Paris',15,'2021-01-01'); INSERT INTO sales (item,location,quantity,sale_date) VALUES ('Top','Paris',20,'2021-01-02'); | SELECT SUM(quantity) FROM sales WHERE item = 'Dress' AND location = 'Paris' AND sale_date BETWEEN '2021-01-01' AND '2021-12-31'; |
What is the maximum number of public transportation trips taken in a single day for each mode of transportation? | CREATE TABLE PublicTransportation (TripID INT,TripDate DATE,Mode VARCHAR(255),Trips INT); INSERT INTO PublicTransportation (TripID,TripDate,Mode,Trips) VALUES (1,'2022-01-01','Bus',50000),(2,'2022-01-02','Subway',70000),(3,'2022-01-03','Bus',55000); | SELECT MAX(Trips), Mode FROM PublicTransportation GROUP BY Mode; |
How many female and male artists released albums in 2021? | CREATE TABLE artists (id INT,name VARCHAR(255),gender VARCHAR(6)); CREATE TABLE albums (id INT,artist_id INT,year INT); | SELECT artists.gender, COUNT(*) FROM albums JOIN artists ON albums.artist_id = artists.id WHERE albums.year = 2021 GROUP BY artists.gender; |
Which neighborhood in Boston has the highest property tax? | CREATE TABLE tax_rates_3 (id INT,neighborhood TEXT,city TEXT,state TEXT,property_type TEXT,rate FLOAT); | SELECT MAX(rate) FROM tax_rates_3 WHERE city = 'Boston' AND property_type = 'Residential' GROUP BY neighborhood; |
What is the average revenue for each game type? | CREATE TABLE RevenueData (GameID INT,GameType VARCHAR(20),Revenue INT); INSERT INTO RevenueData (GameID,GameType,Revenue) VALUES (1,'Action',5000),(2,'Adventure',6000),(3,'Simulation',8000),(4,'Action',7000),(5,'Simulation',9000),(6,'Adventure',10000); | SELECT GameType, AVG(Revenue) FROM RevenueData GROUP BY GameType; |
Find the daily water usage for the top 5 water consuming cities in Texas. | CREATE TABLE daily_usage (city VARCHAR(50),date DATE,water_usage FLOAT); INSERT INTO daily_usage VALUES ('Dallas','2022-01-01',500000),('Dallas','2022-01-02',600000),('Dallas','2022-01-03',550000),('Houston','2022-01-01',450000),('Houston','2022-01-02',500000),('Houston','2022-01-03',480000),('Austin','2022-01-01',350000),('Austin','2022-01-02',370000),('Austin','2022-01-03',360000),('San Antonio','2022-01-01',400000),('San Antonio','2022-01-02',420000),('San Antonio','2022-01-03',390000); | SELECT city, SUM(water_usage) as total_usage FROM daily_usage WHERE date >= '2022-01-01' AND date <= '2022-01-03' AND city IN ('Dallas', 'Houston', 'Austin', 'San Antonio', 'Fort Worth') GROUP BY city ORDER BY total_usage DESC LIMIT 5; |
What was the total quantity of shrimp exported from Thailand to Singapore in 2022? | CREATE TABLE seafood_exports (id INT,export_date DATE,export_country TEXT,import_country TEXT,quantity INT); INSERT INTO seafood_exports (id,export_date,export_country,import_country,quantity) VALUES (1,'2022-01-01','Thailand','Singapore',500); INSERT INTO seafood_exports (id,export_date,export_country,import_country,quantity) VALUES (2,'2022-02-15','Thailand','Singapore',600); | SELECT SUM(quantity) FROM seafood_exports WHERE export_country = 'Thailand' AND import_country = 'Singapore' AND EXTRACT(YEAR FROM export_date) = 2022 AND species = 'Shrimp'; |
What was the average donation amount for each donor type? | CREATE TABLE donors (donor_id INT,donor_type TEXT,donation_amount DECIMAL(10,2)); INSERT INTO donors VALUES (1,'Individual',50.00); INSERT INTO donors VALUES (2,'Corporation',5000.00); | SELECT donor_type, AVG(donation_amount) as avg_donation FROM donors GROUP BY donor_type; |
What is the count of satellite images taken for agricultural purposes in Brazil in January 2021? | CREATE TABLE if NOT EXISTS satellite_images (id int,location varchar(50),image_date datetime,purpose varchar(50)); INSERT INTO satellite_images (id,location,image_date,purpose) VALUES (1,'Brazil','2021-01-01 10:00:00','agriculture'),(2,'Brazil','2021-01-02 10:00:00','agriculture'); | SELECT COUNT(*) FROM satellite_images WHERE location = 'Brazil' AND purpose = 'agriculture' AND image_date >= '2021-01-01' AND image_date < '2021-02-01'; |
Who are the female jazz artists with the highest ticket sales? | CREATE TABLE Artists (ArtistID INT PRIMARY KEY,ArtistName VARCHAR(100),Gender VARCHAR(10),Genre VARCHAR(50),TicketsSold INT); INSERT INTO Artists (ArtistID,ArtistName,Gender,Genre,TicketsSold) VALUES (1,'Artist A','Female','Jazz',3000),(2,'Artist B','Male','Jazz',4000),(3,'Artist C','Female','Jazz',5000),(4,'Artist D','Male','Jazz',2000),(5,'Artist E','Female','Rock',6000); | SELECT ArtistName FROM Artists WHERE Gender = 'Female' AND Genre = 'Jazz' ORDER BY TicketsSold DESC LIMIT 1; |
Calculate the percentage of endangered species for each habitat type, considering the total number of species in the "endangered_species", "habitat_preservation", and "habitats" tables | CREATE TABLE endangered_species (species VARCHAR(255),habitat_type VARCHAR(255),endangered BOOLEAN); CREATE TABLE habitat_preservation (habitat_type VARCHAR(255),location VARCHAR(255)); CREATE TABLE habitats (habitat_type VARCHAR(255),area_size FLOAT); | SELECT h1.habitat_type, (COUNT(e1.species) * 100.0 / (SELECT COUNT(DISTINCT e2.species) FROM endangered_species e2 WHERE e2.habitat_type = h1.habitat_type)) as endangered_percentage FROM endangered_species e1 INNER JOIN habitat_preservation h1 ON e1.habitat_type = h1.habitat_type INNER JOIN habitats h2 ON h1.habitat_type = h2.habitat_type GROUP BY h1.habitat_type; |
What is the maximum salary by company and job role? | CREATE TABLE MaxSalaries (id INT,company_id INT,job_role VARCHAR(50),salary INT); INSERT INTO MaxSalaries (id,company_id,job_role,salary) VALUES (1,1,'Engineer',90000),(2,1,'Manager',120000),(3,2,'Engineer',95000),(4,2,'Engineer',100000); | SELECT company_id, job_role, MAX(salary) as max_salary FROM MaxSalaries GROUP BY company_id, job_role; |
What is the number of volunteers who have not made a donation? | CREATE TABLE donor (id INT,name VARCHAR(50)); CREATE TABLE donation (id INT,donor_id INT,amount DECIMAL(10,2),donation_date DATE); CREATE TABLE volunteer (id INT,donor_id INT,volunteer_date DATE); | SELECT COUNT(DISTINCT v.id) as total_volunteers FROM volunteer v LEFT JOIN donation d ON v.donor_id = d.donor_id WHERE d.id IS NULL; |
What is the total number of visitors who have attended multiple exhibitions? | CREATE TABLE Exhibitions (ExhibitionID INT,ExhibitionName VARCHAR(255)); INSERT INTO Exhibitions (ExhibitionID,ExhibitionName) VALUES (1,'Modern Art'); INSERT INTO Exhibitions (ExhibitionID,ExhibitionName) VALUES (2,'Natural History'); CREATE TABLE Visitors (VisitorID INT,VisitorName VARCHAR(255),HasVisitedMultipleExhibitions BOOLEAN); INSERT INTO Visitors (VisitorID,VisitorName,HasVisitedMultipleExhibitions) VALUES (1,'John Doe',true); INSERT INTO Visitors (VisitorID,VisitorName,HasVisitedMultipleExhibitions) VALUES (2,'Jane Doe',false); INSERT INTO Visitors (VisitorID,VisitorName,HasVisitedMultipleExhibitions) VALUES (3,'Jim Smith',true); CREATE TABLE VisitorExhibitions (VisitorID INT,ExhibitionID INT); INSERT INTO VisitorExhibitions (VisitorID,ExhibitionID) VALUES (1,1); INSERT INTO VisitorExhibitions (VisitorID,ExhibitionID) VALUES (1,2); INSERT INTO VisitorExhibitions (VisitorID,ExhibitionID) VALUES (3,1); INSERT INTO VisitorExhibitions (VisitorID,ExhibitionID) VALUES (3,2); | SELECT COUNT(V.VisitorID) as TotalVisitors FROM Visitors V INNER JOIN VisitorExhibitionsVE ON V.VisitorID = VE.VisitorID GROUP BY V.VisitorID HAVING COUNT(VE.ExhibitionID) > 1; |
List stores that meet or exceed the specified sustainability thresholds for waste reduction and water conservation. | CREATE TABLE SUSTAINABILITY (store_id INT,waste_reduction FLOAT,water_conservation FLOAT); INSERT INTO SUSTAINABILITY VALUES (1,0.15,0.20),(2,0.10,0.15),(3,0.20,0.25),(4,0.12,0.18); | SELECT store_id, waste_reduction, water_conservation FROM SUSTAINABILITY WHERE waste_reduction >= 0.15 AND water_conservation >= 0.20; |
What is the distribution of military technology types by country? | CREATE TABLE military_tech (country VARCHAR(50),tech_type VARCHAR(50),quantity INT); INSERT INTO military_tech (country,tech_type,quantity) VALUES ('USA','Aircraft',13000),('USA','Vessels',500),('China','Aircraft',5000),('China','Vessels',700),('Russia','Aircraft',4000),('Russia','Vessels',600); | SELECT country, tech_type, quantity FROM military_tech; |
What is the total amount of climate finance invested in sustainable agriculture projects in the Middle East in 2023? | CREATE TABLE climate_finance (country VARCHAR(255),sector VARCHAR(255),investment_amount NUMERIC,region VARCHAR(255),year INT); | SELECT SUM(investment_amount) FROM climate_finance WHERE sector = 'sustainable agriculture' AND region = 'Middle East' AND year = 2023; |
What is the maximum cargo weight and corresponding port for cargo handled by the vessel 'Sea Serpent'? | CREATE TABLE ports (id INT,name VARCHAR(50),location VARCHAR(50),un_code VARCHAR(10)); CREATE TABLE vessels (id INT,name VARCHAR(50),type VARCHAR(50),year_built INT,port_id INT); CREATE TABLE captains (id INT,name VARCHAR(50),age INT,license_number VARCHAR(20),vessel_id INT); CREATE TABLE cargo (id INT,description VARCHAR(50),weight FLOAT,port_id INT,vessel_id INT); CREATE VIEW captain_vessel AS SELECT captains.name AS captain_name,vessels.name AS vessel_name FROM captains INNER JOIN vessels ON captains.vessel_id = vessels.id; | SELECT ports.name, MAX(cargo.weight) AS max_cargo_weight FROM ports INNER JOIN (vessels INNER JOIN cargo ON vessels.id = cargo.vessel_id) ON ports.id = vessels.port_id WHERE vessels.name = 'Sea Serpent' GROUP BY ports.name; |
What is the maximum score achieved by player 'Mia' in the game 'Fortnite'? | CREATE TABLE fortnite_scores (id INT,player TEXT,score INT,game TEXT); INSERT INTO fortnite_scores (id,player,score,game) VALUES (1,'Mia',120,'Fortnite'),(2,'Mia',115,'Fortnite'),(3,'Max',130,'Fortnite'); | SELECT MAX(score) FROM fortnite_scores WHERE player = 'Mia' AND game = 'Fortnite'; |
Find the number of employees and total salary costs for mining companies in the top 2 countries with the highest total salary costs. | CREATE TABLE company (id INT,name VARCHAR(255),country VARCHAR(255),num_employees INT,avg_salary DECIMAL(10,2));CREATE VIEW mining_companies AS SELECT * FROM company WHERE industry = 'Mining'; | SELECT c.country, SUM(c.num_employees) as total_employees, SUM(c.num_employees * c.avg_salary) as total_salary_costs FROM mining_companies c JOIN (SELECT country, SUM(num_employees * avg_salary) as total_salary_costs FROM mining_companies GROUP BY country ORDER BY total_salary_costs DESC LIMIT 2) mc ON c.country = mc.country GROUP BY c.country; |
List all the dental clinics in rural areas of Australia with their budget. | CREATE TABLE clinics (id INT,name VARCHAR(50),location VARCHAR(50),type VARCHAR(20),budget INT); | SELECT name, budget FROM clinics WHERE location LIKE '%Australia%' AND location LIKE '%rural%' AND type = 'dental'; |
How many veterans have been employed by each company? | CREATE TABLE companies (id INT,name VARCHAR(255));CREATE TABLE veteran_employment (company_id INT,num_veterans INT);INSERT INTO companies (id,name) VALUES (1,'Lockheed Martin'),(2,'Boeing'),(3,'Raytheon Technologies'),(4,'Northrop Grumman');INSERT INTO veteran_employment (company_id,num_veterans) VALUES (1,25000),(2,30000),(3,15000),(4,20000); | SELECT c.name, SUM(ve.num_veterans) as total_veterans FROM companies c JOIN veteran_employment ve ON c.id = ve.company_id GROUP BY c.name; |
What is the maximum energy efficiency score? | CREATE TABLE energy_efficiency_scores (score INT); INSERT INTO energy_efficiency_scores (score) VALUES (90),(85),(88); | SELECT MAX(score) FROM energy_efficiency_scores; |
What is the total amount of research grants awarded to female faculty members in the College of Engineering for each year since 2017? | CREATE TABLE College_of_Engineering_Grants (faculty_gender VARCHAR(10),grant_year INT,grant_amount INT); INSERT INTO College_of_Engineering_Grants (faculty_gender,grant_year,grant_amount) VALUES ('Female',2017,50000),('Male',2017,70000),('Female',2018,60000),('Male',2018,80000),('Female',2019,75000),('Male',2019,65000); | SELECT grant_year, SUM(grant_amount) as total_grant_amount FROM College_of_Engineering_Grants WHERE faculty_gender = 'Female' GROUP BY grant_year; |
How many hectares of forest are dedicated to carbon sequestration in each region? | CREATE TABLE Carbon_Sequestration (ID INT,Region VARCHAR(50),Area FLOAT); INSERT INTO Carbon_Sequestration (ID,Region,Area) VALUES (1,'Region1',30.2),(2,'Region2',45.6),(3,'Region3',60.8); | SELECT Region, Area FROM Carbon_Sequestration; |
Show the top 3 cities with the highest number of ticket purchases for baseball games. | CREATE TABLE baseball_tickets (id INT,city VARCHAR(20),ticket_sales INT); | SELECT city, SUM(ticket_sales) AS total_sales FROM baseball_tickets GROUP BY city ORDER BY total_sales DESC LIMIT 3; |
Which supplier provided the most Holmium in 2017? | CREATE TABLE supplier_holmium (year INT,supplier VARCHAR(20),holmium_supply INT); INSERT INTO supplier_holmium VALUES (2015,'Supplier A',20),(2016,'Supplier B',25),(2017,'Supplier C',30),(2018,'Supplier D',35),(2019,'Supplier E',40); | SELECT supplier, MAX(holmium_supply) FROM supplier_holmium WHERE year = 2017 GROUP BY supplier; |
What is the maximum altitude reached by any spacecraft? | CREATE TABLE Spacecraft (name VARCHAR(30),max_altitude FLOAT); INSERT INTO Spacecraft (name,max_altitude) VALUES ('Apollo 13',400040),('Apollo 11',363390); | SELECT MAX(max_altitude) FROM Spacecraft; |
What are the unique depths of the ocean habitats for marine species in the Arctic Ocean? | CREATE TABLE marine_species (id INT,name VARCHAR(50),region VARCHAR(50),ocean_depth DECIMAL(5,2)); INSERT INTO marine_species (id,name,region,ocean_depth) VALUES (1,'Polar Bear','Arctic Ocean',100.00); CREATE TABLE ocean_depth_scale (id INT,name VARCHAR(50),value DECIMAL(5,2)); | SELECT DISTINCT marine_species.ocean_depth FROM marine_species INNER JOIN ocean_depth_scale ON marine_species.ocean_depth = ocean_depth_scale.value WHERE ocean_depth_scale.name = 'Meters'; |
Delete the investment with the given id. | CREATE TABLE investments (id INT,sector VARCHAR(20),amount FLOAT); INSERT INTO investments (id,sector,amount) VALUES (1,'Education',150000.00),(2,'Healthcare',120000.00); | DELETE FROM investments WHERE id = 2; |
What is the earliest issued permit date for projects in 'LA'? | CREATE TABLE project (id INT,name VARCHAR(50),location VARCHAR(50),start_date DATE); INSERT INTO project (id,name,location,start_date) VALUES (1,'Green Build','NYC','2020-01-01'),(2,'Solar Tower','LA','2019-12-15'),(3,'Eco House','Austin','2020-03-01'); CREATE TABLE permit (id INT,project_id INT,type VARCHAR(50),issued_date DATE); INSERT INTO permit (id,project_id,type,issued_date) VALUES (1,1,'Building','2019-12-01'),(2,1,'Electrical','2020-01-05'),(3,2,'Building','2019-11-30'),(4,2,'Plumbing','2019-12-10'),(5,3,'Building','2020-02-15'); | SELECT MIN(issued_date) AS earliest_date FROM permit WHERE project_id IN (SELECT id FROM project WHERE location = 'LA'); |
Display the number of times each dish has been ordered, sorted by the most ordered dish | CREATE TABLE orders (order_id INT,dish_id INT,order_date DATE); INSERT INTO orders (order_id,dish_id,order_date) VALUES (1,1,'2022-01-01'),(2,2,'2022-01-01'),(3,3,'2022-01-01'),(4,1,'2022-01-02'),(5,3,'2022-01-02'),(6,1,'2022-01-03'); | SELECT dish_id, COUNT(*) as order_count FROM orders GROUP BY dish_id ORDER BY order_count DESC; |
What is the average age of blues artists who have sold more than 2000 tickets? | CREATE TABLE Artists (ArtistID INT PRIMARY KEY,ArtistName VARCHAR(100),Age INT,Genre VARCHAR(50),TicketsSold INT); INSERT INTO Artists (ArtistID,ArtistName,Age,Genre,TicketsSold) VALUES (1,'Artist A',35,'Blues',3000),(2,'Artist B',45,'Jazz',4000),(3,'Artist C',28,'Pop',5000),(4,'Artist D',50,'Blues',2500),(5,'Artist E',42,'Blues',1500),(6,'Artist F',48,'Jazz',6000); | SELECT AVG(Age) FROM Artists WHERE Genre = 'Blues' AND TicketsSold > 2000; |
What is the average duration of unsuccessful defense projects in Europe? | CREATE TABLE ProjectTimelines (id INT,project_name VARCHAR(255),region VARCHAR(255),start_date DATE,end_date DATE,status VARCHAR(255)); INSERT INTO ProjectTimelines (id,project_name,region,start_date,end_date,status) VALUES (1,'Project A','Europe','2017-01-01','2019-12-31','Completed'),(2,'Project B','Europe','2018-01-01','2020-12-31','Cancelled'),(3,'Project C','Africa','2019-01-01','2021-06-30','In Progress'); | SELECT AVG(DATEDIFF(end_date, start_date)) as avg_duration FROM ProjectTimelines WHERE region = 'Europe' AND status != 'Completed'; |
What is the minimum number of therapy sessions attended by patients with a primary diagnosis of bipolar disorder? | CREATE TABLE patients (id INT,name TEXT,age INT,condition TEXT,therapy_sessions INT); | SELECT MIN(therapy_sessions) FROM patients WHERE condition = 'bipolar_disorder'; |
Update the capacities of all warehouses in the USA to 5000 | CREATE TABLE warehouse (id INT,city VARCHAR(20),capacity INT); CREATE TABLE country (id INT,name VARCHAR(20)); INSERT INTO country (id,name) VALUES (1,'India'),(2,'USA'),(3,'Germany'); CREATE VIEW warehouse_country AS SELECT * FROM warehouse INNER JOIN country ON warehouse.id = country.id; INSERT INTO warehouse (id,city,capacity) VALUES (13,'New York',1500),(14,'Los Angeles',2000),(15,'Chicago',2500); INSERT INTO country (id,name) VALUES (5,'USA'); INSERT INTO warehouse_country (id,city,capacity,name) VALUES (13,'New York',1500,'USA'),(14,'Los Angeles',2000,'USA'),(15,'Chicago',2500,'USA'); | UPDATE warehouse_country SET capacity = 5000 WHERE name = 'USA'; |
What is the average investment amount for each investor? | CREATE TABLE Investments (InvestmentID INT,InvestorID INT,Amount INT); INSERT INTO Investments (InvestmentID,InvestorID,Amount) VALUES (1,1,5000),(2,1,7000),(3,2,6000),(4,2,8000),(5,3,4000),(6,3,6000); CREATE TABLE Investors (InvestorID INT,Name VARCHAR(20),Gender VARCHAR(10)); INSERT INTO Investors (InvestorID,Name,Gender) VALUES (1,'John Doe','Male'),(2,'Jane Smith','Female'),(3,'Jim Brown','Male'); | SELECT Investors.Name, AVG(Investments.Amount) as AverageInvestment FROM Investments JOIN Investors ON Investments.InvestorID = Investors.InvestorID GROUP BY Investors.Name; |
Select all data from the view for health equity metrics | CREATE OR REPLACE VIEW health_equity_view AS SELECT * FROM health_equity; | SELECT * FROM health_equity_view; |
What is the total cost of infrastructure projects for each community in 2022, sorted by the highest total cost? | CREATE TABLE communities (id INT,name TEXT,location TEXT); INSERT INTO communities (id,name,location) VALUES (1,'Community A','Rural Area 1'),(2,'Community B','Rural Area 2'); CREATE TABLE infrastructure_projects (id INT,community_id INT,name TEXT,cost INT,year INT,PRIMARY KEY (id,year)); INSERT INTO infrastructure_projects (id,community_id,name,cost,year) VALUES (1,1,'Project 1',5000,2022),(2,1,'Project 2',3000,2022),(3,2,'Project 3',4000,2022); | SELECT community_id, SUM(cost) as total_cost FROM infrastructure_projects WHERE year = 2022 GROUP BY community_id ORDER BY total_cost DESC; |
Insert a new record into the "labor_productivity" table with the following data: 'Ruby Ranch', 'South Coast', 91 | CREATE TABLE labor_productivity (record_id INT PRIMARY KEY,mine_name VARCHAR(20),region VARCHAR(20),productivity_score INT); | INSERT INTO labor_productivity (mine_name, region, productivity_score) VALUES ('Ruby Ranch', 'South Coast', 91); |
Find the number of employees and unions in the 'labor_unions' and 'employees' tables | CREATE TABLE labor_unions (id INT,union_name VARCHAR(50),members INT); CREATE TABLE employees (id INT,union_id INT,name VARCHAR(50),position VARCHAR(50)); | SELECT COUNT(DISTINCT e.id) AS employee_count, COUNT(DISTINCT l.id) AS union_count FROM employees e JOIN labor_unions l ON e.union_id = l.id; |
List all unique mental health programs offered by schools in the 'programs' table, without sorting the results. | CREATE TABLE programs (school_id INT,program_name VARCHAR(50),program_type VARCHAR(20)); | SELECT DISTINCT program_name FROM programs WHERE program_type = 'mental_health'; |
What is the cultural competency training completion rate for community health workers in each region? | CREATE TABLE training_sessions (session_id INT,session_name VARCHAR(50),completed_by_worker INT); INSERT INTO training_sessions (session_id,session_name,completed_by_worker) VALUES (1,'Cultural Competency 101',120),(2,'Advanced Cultural Competency',80); | SELECT r.region_name, COUNT(chw.worker_id) as total_workers, COUNT(ts.completed_by_worker) as completed_trainings, 100.0 * COUNT(ts.completed_by_worker) / COUNT(chw.worker_id) as completion_rate FROM regions r INNER JOIN community_health_workers chw ON r.region_id = chw.region_id LEFT JOIN (training_sessions ts INNER JOIN (SELECT worker_id, MAX(session_id) as max_session_id FROM training_sessions GROUP BY worker_id) ts_max ON ts.session_id = ts_max.max_session_id AND ts.completed_by_worker = ts_max.worker_id) ON chw.worker_id = ts_max.worker_id GROUP BY r.region_name; |
What is the total number of languages preserved in each country? | CREATE TABLE language_count (id INT,country VARCHAR(50),language VARCHAR(50)); INSERT INTO language_count (id,country,language) VALUES (1,'Canada','Navajo'); INSERT INTO language_count (id,country,language) VALUES (2,'New Zealand','Quechua'); | SELECT country, COUNT(language) FROM language_count GROUP BY country; |
What is the percentage of total visitors that went to Colombia from each continent? | CREATE TABLE destinations (id INT,country TEXT,continent TEXT); INSERT INTO destinations (id,country,continent) VALUES (1,'Colombia','South America'),(2,'Argentina','South America'),(3,'Canada','North America'); CREATE TABLE visits (id INT,visitor_origin TEXT,destination_id INT); INSERT INTO visits (id,visitor_origin,destination_id) VALUES (1,'Mexico',3),(2,'Brazil',3),(3,'Colombia',1); | SELECT d.continent, 100.0 * COUNT(v.id) / (SELECT COUNT(*) FROM visits) AS percentage FROM visits v JOIN destinations d ON v.destination_id = d.id WHERE d.country = 'Colombia' GROUP BY d.continent; |
List all products supplied by Fair Trade certified suppliers in Kenya. | CREATE TABLE suppliers (supplier_id INT,name VARCHAR(50),certification VARCHAR(50),country VARCHAR(50),sustainable_practices BOOLEAN); CREATE TABLE products (product_id INT,supplier_id INT,name VARCHAR(50)); CREATE VIEW product_supplier_view AS SELECT products.product_id,products.name,suppliers.supplier_id,suppliers.name as supplier_name,suppliers.certification,suppliers.country FROM products INNER JOIN suppliers ON products.supplier_id = suppliers.supplier_id; | SELECT product_id, name FROM product_supplier_view WHERE certification = 'Fair Trade' AND country = 'Kenya'; |
Update the email address for student with ID 10 in the students table | CREATE TABLE students (id INT,name VARCHAR(50),email VARCHAR(50)); INSERT INTO students (id,name,email) VALUES (10,'John Doe','[email protected]'); | UPDATE students SET email = '[email protected]' WHERE id = 10; |
What are the average ticket prices for each artist's concert in the United Kingdom? | CREATE TABLE concert_tickets (ticket_id int,artist_id int,venue_id int,ticket_price decimal,timestamp datetime); INSERT INTO concert_tickets (ticket_id,artist_id,venue_id,ticket_price,timestamp) VALUES (1,456,789,50.00,'2022-06-01 12:00:00'); | SELECT artist_id, AVG(ticket_price) as avg_ticket_price FROM concert_tickets WHERE timestamp BETWEEN '2022-01-01' AND '2022-12-31' AND venue_id IN (SELECT venue_id FROM venues WHERE country = 'United Kingdom') GROUP BY artist_id; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.