instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Identify the financial institutions that offer the most financial wellbeing programs in Africa.
CREATE TABLE programs (id INT,name VARCHAR(50),institution_id INT,category VARCHAR(20)); INSERT INTO programs (id,name,institution_id,category) VALUES (1,'Financial Literacy Workshop',1,'Financial Wellbeing'); CREATE TABLE financial_institutions (id INT,name VARCHAR(50),region VARCHAR(20)); INSERT INTO financial_instit...
SELECT financial_institutions.name, COUNT(programs.id) FROM programs INNER JOIN financial_institutions ON programs.institution_id = financial_institutions.id WHERE programs.category = 'Financial Wellbeing' GROUP BY financial_institutions.name ORDER BY COUNT(programs.id) DESC LIMIT 1;
Which farms have farmed more than one species of fish, excluding fish from the 'Carp' species?
CREATE TABLE Farm (FarmID INT,FarmName TEXT); CREATE TABLE Fish (FishID INT,FarmID INT,SpeciesID INT,BirthDate DATE); INSERT INTO Farm VALUES (1,'Farm M'); INSERT INTO Farm VALUES (2,'Farm N'); INSERT INTO Fish VALUES (1,1,1,'2021-01-01'); INSERT INTO Fish VALUES (2,1,2,'2021-02-01'); INSERT INTO Fish VALUES (3,2,1,'20...
SELECT FarmName FROM Farm INNER JOIN Fish ON Farm.FarmID = Fish.FarmID WHERE SpeciesID != 3 GROUP BY FarmName HAVING COUNT(DISTINCT SpeciesID) > 1;
What is the total biomass of fish in marine farms in the Arctic region that have a water depth of more than 30 meters?
CREATE TABLE marine_farms (id INT,name TEXT,region TEXT,water_depth INT,biomass FLOAT); INSERT INTO marine_farms (id,name,region,water_depth,biomass) VALUES (1,'Farm A','Arctic',40,15000),(2,'Farm B','Arctic',35,12000),(3,'Farm C','Antarctic',50,18000);
SELECT SUM(biomass) FROM marine_farms WHERE region = 'Arctic' AND water_depth > 30;
What are the military technology expenditures for the 'MilitaryTech' schema?
CREATE SCHEMA IF NOT EXISTS MilitaryTech; CREATE TABLE IF NOT EXISTS MilitaryTech.Tech_Expenditures (expenditure_id INT,year INT,amount DECIMAL(10,2),description TEXT); INSERT INTO MilitaryTech.Tech_Expenditures (expenditure_id,year,amount,description) VALUES (1,2021,75000000.00,'Fighter Jet Development'),(2,2022,78000...
SELECT * FROM MilitaryTech.Tech_Expenditures;
What is the total number of hours of content produced by creators in each country, for creators who identify as LGBTQ+?
CREATE TABLE creators (id INT,LGBTQ_identified BOOLEAN,hours_of_content FLOAT,country VARCHAR(20)); INSERT INTO creators (id,LGBTQ_identified,hours_of_content,country) VALUES (1,TRUE,10.5,'Germany'),(2,FALSE,15.2,'France'),(3,TRUE,8.9,'United States');
SELECT country, SUM(hours_of_content) AS total_hours FROM creators WHERE LGBTQ_identified = TRUE GROUP BY country;
What is the maximum dissolved oxygen level for each month in the 'North Atlantic' region?
CREATE TABLE ocean_health (location VARCHAR(255),date DATE,dissolved_oxygen FLOAT); INSERT INTO ocean_health (location,date,dissolved_oxygen) VALUES ('North Atlantic','2021-01-01',6.5),('North Atlantic','2021-01-15',6.3),('North Atlantic','2021-02-01',6.7);
SELECT EXTRACT(MONTH FROM date) AS month, MAX(dissolved_oxygen) AS max_dissolved_oxygen FROM ocean_health WHERE location = 'North Atlantic' GROUP BY month;
What is the average safety rating of autonomous vehicles in the United States?
CREATE TABLE Vehicles (ID INT,Name TEXT,Type TEXT,SafetyRating FLOAT,Country TEXT); INSERT INTO Vehicles (ID,Name,Type,SafetyRating,Country) VALUES (1,'Wayve','Autonomous',4.8,'United States'); INSERT INTO Vehicles (ID,Name,Type,SafetyRating,Country) VALUES (2,'NVIDIA','Autonomous',4.6,'United States');
SELECT AVG(SafetyRating) FROM Vehicles WHERE Type = 'Autonomous' AND Country = 'United States';
Which countries have launched satellites using providers other than SpaceTech Inc. and CosmosLaunch?
CREATE TABLE Satellites (country VARCHAR(255),provider VARCHAR(255)); INSERT INTO Satellites (country,provider) VALUES ('Country1','SpaceTech Inc.'); INSERT INTO Satellites (country,provider) VALUES ('Country2','CosmosLaunch'); INSERT INTO Satellites (country,provider) VALUES ('Country3','OtherLaunch');
SELECT country FROM Satellites WHERE provider NOT IN ('SpaceTech Inc.', 'CosmosLaunch');
What is the total revenue generated from recycled products in Europe?
CREATE TABLE orders (order_id INT,order_date DATE,product_id INT,revenue FLOAT,is_recycled BOOLEAN); CREATE TABLE products (product_id INT,product_name VARCHAR(50),country VARCHAR(50)); INSERT INTO orders (order_id,order_date,product_id,revenue,is_recycled) VALUES (1,'2022-01-01',1,250,TRUE),(2,'2022-01-02',2,80,FALSE)...
SELECT SUM(revenue) FROM orders JOIN products ON orders.product_id = products.product_id WHERE is_recycled = TRUE AND products.country IN ('Germany', 'France', 'Italy', 'Spain', 'Poland');
What is the average quantity of garments sold online per day in the 'Delhi' region?
CREATE TABLE sales (id INT PRIMARY KEY,transaction_date DATE,quantity_sold INT,payment_method VARCHAR(255),region VARCHAR(255));
SELECT AVG(quantity_sold / 365.25) as avg_quantity_sold_online_per_day FROM sales WHERE region = 'Delhi' AND payment_method IS NOT NULL;
What is the average mental health score of students in 'High School' schools?
CREATE TABLE Schools (id INT,name VARCHAR(20)); INSERT INTO Schools (id,name) VALUES (1,'Elementary'),(2,'High School'),(3,'Middle School'); CREATE TABLE StudentMentalHealth (student_id INT,school_id INT,score INT); INSERT INTO StudentMentalHealth (student_id,school_id,score) VALUES (1,1,80),(2,1,90),(3,2,70),(4,3,85),...
SELECT AVG(smh.score) FROM StudentMentalHealth smh JOIN Schools s ON smh.school_id = s.id WHERE s.name = 'High School';
What are the names and symbols of all cryptocurrencies with a market cap greater than $10 billion?
CREATE TABLE public.cryptocurrencies (id SERIAL PRIMARY KEY,name VARCHAR(100),symbol VARCHAR(10),market_cap DECIMAL); INSERT INTO public.cryptocurrencies (name,symbol,market_cap) VALUES ('Bitcoin','BTC',936823233334); INSERT INTO public.cryptocurrencies (name,symbol,market_cap) VALUES ('Ethereum','ETH',416885542744);
SELECT name, symbol FROM public.cryptocurrencies WHERE market_cap > 10000000000;
What is the total revenue for the football team from ticket sales in San Francisco?
CREATE TABLE tickets (ticket_id INT,game_id INT,quantity INT,price DECIMAL(5,2)); INSERT INTO tickets VALUES (1,1,50,25.99); INSERT INTO tickets VALUES (2,2,30,19.99); CREATE TABLE games (game_id INT,team VARCHAR(20),location VARCHAR(20),price DECIMAL(5,2)); INSERT INTO games VALUES (1,'49ers','San Francisco',50.00); I...
SELECT SUM(tickets.quantity * games.price) FROM tickets INNER JOIN games ON tickets.game_id = games.game_id WHERE games.location = 'San Francisco';
What is the minimum amount of funding raised by companies founded by immigrants in the fintech industry?
CREATE TABLE companies (id INT,name TEXT,industry TEXT,founding_year INT,founder_immigrant TEXT); INSERT INTO companies (id,name,industry,founding_year,founder_immigrant) VALUES (1,'FinTechInnovations','Fintech',2015,'Yes'); INSERT INTO companies (id,name,industry,founding_year,founder_immigrant) VALUES (2,'FinanceServ...
SELECT MIN(funding_amount) FROM funding_records INNER JOIN companies ON funding_records.company_id = companies.id WHERE companies.founder_immigrant = 'Yes' AND companies.industry = 'Fintech';
What is the total amount of defense contracts awarded to companies in Texas?
CREATE TABLE defense_contracts (contract_id INT,company_name VARCHAR(100),state VARCHAR(50),contract_value FLOAT);
SELECT SUM(contract_value) FROM defense_contracts WHERE state = 'Texas';
What is the total cost of smart city technology adoptions in the city of Toronto?
CREATE TABLE smart_city_tech (tech_id INT,tech_name VARCHAR(30),city VARCHAR(20),cost DECIMAL(10,2)); INSERT INTO smart_city_tech (tech_id,tech_name,city,cost) VALUES (1,'Smart Grids','Toronto',5000000.00),(2,'Smart Lighting','Montreal',3000000.00),(3,'Smart Traffic Management','Vancouver',4000000.00);
SELECT SUM(cost) FROM smart_city_tech WHERE city = 'Toronto';
List all green buildings in the green_buildings table that have a higher energy efficiency rating than the average rating for buildings in the 'Urban' region.
CREATE TABLE green_buildings (building_id INT,name VARCHAR(100),location VARCHAR(50),energy_efficiency_rating FLOAT); INSERT INTO green_buildings (building_id,name,location,energy_efficiency_rating) VALUES (1,'GreenHQ','Urban',85),(2,'EcoTower','Rural',90),(3,'SolarSpire','Urban',88);
SELECT building_id, name, location, energy_efficiency_rating FROM green_buildings WHERE energy_efficiency_rating > (SELECT AVG(energy_efficiency_rating) FROM green_buildings WHERE location = 'Urban') AND location = 'Urban';
Update the address of donor with ID 5 to '987 Cedar Rd'?
CREATE TABLE donors (donor_id INT,donor_name TEXT,address TEXT); INSERT INTO donors (donor_id,donor_name,address) VALUES (3,'Jim Brown','456 Elm St'),(4,'Pam Smith','789 Oak Rd'),(5,'Quincy Jones',NULL);
UPDATE donors SET address = '987 Cedar Rd' WHERE donor_id = 5;
What is the percentage of users who have opted out of targeted advertising for the year 2022?
CREATE TABLE users (id INT,opted_out_targeted_ads BOOLEAN,created_date DATE);
SELECT ROUND(100.0 * SUM(CASE WHEN opted_out_targeted_ads THEN 1 ELSE 0 END) / COUNT(*) , 2) as percentage FROM users WHERE YEAR(created_date) = 2022;
Delete all albums released before 2010
CREATE TABLE albums (id INT PRIMARY KEY,title VARCHAR(100),artist_id INT,release_year INT);
DELETE FROM albums WHERE release_year < 2010;
What is the total quantity of gluten-free dishes sold in May 2022?
CREATE TABLE Dishes (dish_id INT,dish_name TEXT,dish_type TEXT,quantity_sold INT,sale_date DATE); INSERT INTO Dishes (dish_id,dish_name,dish_type,quantity_sold,sale_date) VALUES (1,'Quinoa Salad','gluten-free',40,'2022-05-01');
SELECT SUM(quantity_sold) FROM Dishes WHERE dish_type = 'gluten-free' AND sale_date >= '2022-05-01' AND sale_date < '2022-06-01';
List the number of articles published in 'Boston Globe' and 'Chicago Tribune' on each day of the week.
CREATE TABLE BG_Articles(id INT,title VARCHAR(50),publication DATE,category VARCHAR(20));CREATE TABLE CT_Articles(id INT,title VARCHAR(50),publication DATE,category VARCHAR(20));
SELECT DATEPART(dw, publication) AS DayOfWeek, COUNT(*) FROM BG_Articles WHERE publication IS NOT NULL GROUP BY DATEPART(dw, publication) UNION ALL SELECT DATEPART(dw, publication) AS DayOfWeek, COUNT(*) FROM CT_Articles WHERE publication IS NOT NULL GROUP BY DATEPART(dw, publication);
Which spacecraft were launched by NASA and what were their maximum altitudes?
CREATE TABLE Spacecraft (SpacecraftID INT PRIMARY KEY,Name VARCHAR(255),Manufacturer VARCHAR(100),LaunchDate DATE,MaxAltitude FLOAT); INSERT INTO Spacecraft (SpacecraftID,Name,Manufacturer,LaunchDate,MaxAltitude) VALUES (5,'Voyager 1','NASA','1977-09-05',13.8); INSERT INTO Spacecraft (SpacecraftID,Name,Manufacturer,Lau...
SELECT Name, MaxAltitude FROM Spacecraft WHERE Manufacturer = 'NASA';
What is the maximum capacity (in MW) of wind power projects in the 'Africa' region that were completed before the year 2015?
CREATE TABLE projects (id INT,name TEXT,region TEXT,completed_year INT,capacity_mw FLOAT); INSERT INTO projects (id,name,region,completed_year,capacity_mw) VALUES (1,'Wind Project 1','Africa',2013,120.5); INSERT INTO projects (id,name,region,completed_year,capacity_mw) VALUES (2,'Wind Project 2','Africa',2017,180.3);
SELECT MAX(capacity_mw) FROM projects WHERE type = 'wind' AND region = 'Africa' AND completed_year < 2015;
What is the total number of grievances filed in the 'technology_database' database?
CREATE TABLE grievances (id INT,employee_id INT,is_union_member BOOLEAN,filed_date DATE); INSERT INTO grievances (id,employee_id,is_union_member,filed_date) VALUES (1,101,true,'2021-01-01'),(2,102,false,'2021-02-01'),(3,103,true,'2021-03-01');
SELECT COUNT(*) FROM grievances;
What is the annual salary of the highest paid employee in each department, and what is the total cost of operations for each department?
CREATE TABLE Departments (DepartmentID INT,DepartmentName VARCHAR(50));CREATE TABLE Employees (EmployeeID INT,DepartmentID INT,FirstName VARCHAR(50),LastName VARCHAR(50),AnnualSalary DECIMAL(10,2));CREATE TABLE Operations (OperationID INT,DepartmentID INT,OperationType VARCHAR(50),ResourcesUsed DECIMAL(10,2),Cost DECIM...
SELECT D.DepartmentName, DE.FirstName, DE.LastName, DE.AnnualSalary AS EmployeeSalary, DO.OperationType, DO.Cost AS DepartmentCost FROM Departments D JOIN DepartmentEmployees DE ON D.DepartmentID = DE.DepartmentID JOIN DepartmentOperations DO ON D.DepartmentID = DO.DepartmentID WHERE DE.SalaryRank = 1 AND DO.CostRank =...
What is the maximum age of users?
CREATE TABLE Users (UserID INT,Age INT); INSERT INTO Users (UserID,Age) VALUES (1,34),(2,45),(3,29);
SELECT MAX(Age) FROM Users;
Create a table named trending_topics with columns topic_id, topic, trend_score, and trend_start_time.
CREATE TABLE posts (post_id INT,user_id INT,content TEXT,post_time TIMESTAMP);
CREATE TABLE trending_topics (topic_id INT, topic VARCHAR(50), trend_score INT, trend_start_time TIMESTAMP);
What is the total healthcare spending in 2021 for male patients in rural Arizona?
CREATE TABLE healthcare_spending (patient_id INT,year INT,amount DECIMAL(10,2)); INSERT INTO healthcare_spending (patient_id,year,amount) VALUES (1,2021,5000.50);
SELECT SUM(amount) FROM healthcare_spending WHERE patient_id = 1 AND year = 2021 AND gender = 'Male' AND location = 'rural Arizona';
What was the total amount donated by returning donors in H2 2021?
CREATE TABLE donations (id INT,donor TEXT,amount DECIMAL,donation_date DATE); CREATE TABLE returning_donors (id INT,name TEXT,is_returning BOOLEAN);
SELECT SUM(amount) as total_donated FROM donations d JOIN returning_donors rd ON d.donor = rd.name WHERE rd.is_returning = TRUE AND d.donation_date >= '2021-07-01' AND d.donation_date < '2022-01-01';
Sum the total energy consumption of factories in the 'electronics' sector that are located in Africa.
CREATE TABLE factories (id INT,sector TEXT,location TEXT,energy_consumption INT); INSERT INTO factories (id,sector,location,energy_consumption) VALUES (1,'electronics','Africa',500),(2,'electronics','Europe',400),(3,'textiles','Africa',600),(4,'chemicals','Africa',700),(5,'electronics','Africa',300);
SELECT SUM(energy_consumption) FROM factories WHERE sector = 'electronics' AND location = 'Africa';
What is the minimum age of patients diagnosed with PTSD in the 'mental_health' schema?
CREATE TABLE patients (patient_id INT,diagnosis VARCHAR(255),age INT); INSERT INTO patients (patient_id,diagnosis,age) VALUES (1,'depression',35),(2,'anxiety',28),(3,'PTSD',42),(4,'anxiety',50),(5,'PTSD',38);
SELECT MIN(age) FROM mental_health.patients WHERE diagnosis = 'PTSD';
What are the total sales for each dispensary in California and Colorado?
CREATE TABLE dispensaries (id INT,name TEXT,state TEXT); INSERT INTO dispensaries (id,name,state) VALUES (1,'3D Cannabis Center','Colorado'); INSERT INTO dispensaries (id,name,state) VALUES (2,'Berkshire Roots','California');
SELECT name, SUM(sales) FROM dispensaries d JOIN sales s ON d.id = s.dispensary_id WHERE state IN ('California', 'Colorado') GROUP BY name;
Find the average age of male patients diagnosed with any disease in the 'Texas' region.
CREATE TABLE Patients (PatientID INT,Age INT,Gender VARCHAR(10),Disease VARCHAR(20),Region VARCHAR(20)); INSERT INTO Patients (PatientID,Age,Gender,Disease,Region) VALUES (1,34,'Male','Influenza','Los Angeles'); INSERT INTO Patients (PatientID,Age,Gender,Disease,Region) VALUES (2,42,'Female','Pneumonia','New York');
SELECT AVG(Age) FROM Patients WHERE Gender = 'Male' AND Region = 'Texas';
What is the minimum fine amount for parking violations in 'justice_traffic' table?
CREATE TABLE justice_traffic (id INT,violation_type TEXT,fine_amount INT); INSERT INTO justice_traffic (id,violation_type,fine_amount) VALUES (1,'Speeding',100),(2,'Running Red Light',200),(3,'Parking Violation',50);
SELECT MIN(fine_amount) FROM justice_traffic WHERE violation_type = 'Parking Violation';
Which programs received the most donations from specific cities?
CREATE TABLE Programs (id INT,program VARCHAR(50),budget DECIMAL(10,2)); INSERT INTO Programs (id,program,budget) VALUES (1,'Feeding America',10000.00); CREATE TABLE Donors (id INT,donor_name VARCHAR(50),donation_amount DECIMAL(10,2),donation_date DATE,city VARCHAR(50),program_id INT); INSERT INTO Donors (id,donor_name...
SELECT program, city, SUM(donation_amount) as total_donation_amount FROM Donors GROUP BY program, city;
What is the minimum response time for each division?
CREATE TABLE incidents (id INT,division VARCHAR(255),response_time INT); INSERT INTO incidents (id,division,response_time) VALUES (1,'LAPD',20),(2,'MPD',25);
SELECT division, MIN(response_time) as min_response_time FROM incidents GROUP BY division;
Delete all records from the table "maritime_safety" where region is 'South Pacific'
CREATE TABLE maritime_safety (id INT,region VARCHAR(50),incidents INT,date DATE);
DELETE FROM maritime_safety WHERE region = 'South Pacific';
Insert a new disaster into the 'disasters' table
CREATE TABLE disasters (id INT PRIMARY KEY,name VARCHAR(50),location VARCHAR(50),type VARCHAR(50),start_date DATE,end_date DATE);
INSERT INTO disasters (id, name, location, type, start_date, end_date) VALUES (1, 'Hurricane Katrina', 'New Orleans', 'Hurricane', '2005-08-29', '2005-09-30');
What is the maximum heart rate recorded for each member during 'cardio' workouts in February 2022?
CREATE TABLE heart_rate (id INT,member_id INT,activity_type VARCHAR(50),heart_rate INT,workout_date DATE); INSERT INTO heart_rate (id,member_id,activity_type,heart_rate,workout_date) VALUES (1,1,'cardio',160,'2022-01-01'),(2,1,'yoga',140,'2022-01-02'),(3,2,'cardio',180,'2022-02-03'),(4,2,'yoga',150,'2022-02-04'),(5,3,'...
SELECT members.member_name, MAX(heart_rate) AS max_heart_rate FROM heart_rate JOIN members ON heart_rate.member_id = members.id WHERE activity_type = 'cardio' AND DATE_FORMAT(workout_date, '%Y-%m') = '2022-02' GROUP BY members.member_name;
What is the average age of athletes who have participated in the most number of games in the 'athlete_stats' table?
CREATE TABLE athlete_stats (athlete_id INT,game_count INT,average_age DECIMAL(3,1));
SELECT AVG(average_age) FROM athlete_stats WHERE game_count = (SELECT MAX(game_count) FROM athlete_stats);
What is the average salary of workers in the 'manufacturing' industry?
CREATE TABLE manufacturers (id INT,name VARCHAR(255),industry VARCHAR(255),salary DECIMAL(10,2)); INSERT INTO manufacturers (id,name,industry,salary) VALUES (1,'John Doe','manufacturing',50000.00),(2,'Jane Smith','retail',35000.00);
SELECT AVG(salary) FROM manufacturers WHERE industry = 'manufacturing';
What is the most recent indigenous knowledge entry for the community with the ID 2?
CREATE TABLE indigenous_knowledge (id INT PRIMARY KEY,name VARCHAR(255),knowledge VARCHAR(255),community_id INT,date DATE); INSERT INTO indigenous_knowledge (id,name,knowledge,community_id,date) VALUES (1,'Knowledge A','Sea ice conditions',1,'2022-02-01'),(2,'Knowledge B','Animal migration patterns',2,'2022-03-15'),(3,...
SELECT i.name, i.knowledge, i.community_id, i.date FROM indigenous_knowledge i WHERE i.community_id = 2 ORDER BY i.date DESC LIMIT 1;
What is the monthly average of CO2 emissions per mining site, and which site has the highest monthly average?
CREATE TABLE MiningSites (SiteID INT,SiteName VARCHAR(50),Location VARCHAR(50),CO2Emissions DECIMAL(10,2),EmissionDate DATE);CREATE VIEW MonthlySiteEmissions AS SELECT SiteID,SiteName,ROW_NUMBER() OVER (PARTITION BY SiteID ORDER BY EmissionDate DESC) AS MonthRank,AVG(CO2Emissions) OVER (PARTITION BY SiteID) AS AvgCO2Em...
SELECT SiteName, AvgCO2Emissions, MonthRank FROM MonthlySiteEmissions WHERE MonthRank = 1 ORDER BY AvgCO2Emissions DESC FETCH FIRST 1 ROW ONLY;
List all clients who received expired dairy products from 'Dairy Dream'?
CREATE TABLE ExpiredDairy (id INT,supplier VARCHAR(20),client VARCHAR(20),product VARCHAR(20),expiry_date DATE); INSERT INTO ExpiredDairy (id,supplier,client,product,expiry_date) VALUES (1,'Dairy Dream','Grocery Store','Milk','2021-04-25'),(2,'Dairy Dream','Convenience Store','Cheese','2021-05-10');
SELECT DISTINCT client FROM ExpiredDairy WHERE supplier = 'Dairy Dream' AND product LIKE '%dairy%' AND expiry_date < CURDATE();
What is the total number of accommodations provided for students with visual impairments in each school?
CREATE TABLE Accommodations (SchoolName VARCHAR(255),Student VARCHAR(255),Accommodation VARCHAR(255)); INSERT INTO Accommodations (SchoolName,Student,Accommodation) VALUES ('SchoolA','Student1','Screen Reader'),('SchoolA','Student2','Large Print'),('SchoolB','Student3','Screen Reader');
SELECT SchoolName, COUNT(*) as TotalAccommodations FROM Accommodations WHERE Accommodation LIKE '%Visual Impairment%' GROUP BY SchoolName;
What is the average project timeline for construction projects in Florida?
CREATE TABLE ProjectTimeline (ProjectId INT,StartDate DATE,EndDate DATE,State VARCHAR(50)); INSERT INTO ProjectTimeline (ProjectId,StartDate,EndDate,State) VALUES (1,'2020-01-01','2020-06-01','Florida');
SELECT AVG(DATEDIFF(EndDate, StartDate)) AS AvgProjectTimeline FROM ProjectTimeline WHERE State = 'Florida';
What are the recycling rates for each material and country in 'waste_stream'?
CREATE TABLE waste_stream (country VARCHAR(50),material VARCHAR(50),recycling_rate DECIMAL(5,2));
SELECT country, material, AVG(recycling_rate) as avg_recycling_rate FROM waste_stream GROUP BY country, material;
How many creative AI applications were developed in the US region between 2018 and 2020?
CREATE TABLE Creative_AI_Apps_History (app_id INT,app_name VARCHAR(50),region VARCHAR(50),app_development_date DATE); INSERT INTO Creative_AI_Apps_History (app_id,app_name,region,app_development_date) VALUES (1,'TextGen','US','2018-01-01'),(2,'ImageGen','US','2019-05-12'),(3,'MusicGen','CA','2020-11-15');
SELECT COUNT(*) FROM Creative_AI_Apps_History WHERE region = 'US' AND app_development_date BETWEEN '2018-01-01' AND '2020-12-31';
What is the total value of military equipment sales to India in Q1 2020, partitioned by week?
CREATE TABLE Military_Equipment_Sales (sale_id INT,sale_date DATE,equipment_type VARCHAR(255),country VARCHAR(255),sale_value FLOAT); INSERT INTO Military_Equipment_Sales (sale_id,sale_date,equipment_type,country,sale_value) VALUES (1,'2020-01-02','Aircraft','India',5000000),(2,'2020-01-10','Armored Vehicles','India',2...
SELECT sale_date, SUM(sale_value) AS total_sales FROM Military_Equipment_Sales WHERE country = 'India' AND sale_date BETWEEN '2020-01-01' AND '2020-03-31' GROUP BY sale_date, WEEK(sale_date);
Update the 'Boston Celtics' ticket price to $120.
CREATE TABLE teams (id INT,name TEXT,city TEXT); INSERT INTO teams (id,name,city) VALUES (1,'Boston Celtics','Boston'),(2,'NY Knicks','NY'),(3,'LA Lakers','LA'),(4,'Atlanta Hawks','Atlanta'),(5,'Chicago Bulls','Chicago'),(6,'Golden State Warriors','San Francisco'); CREATE TABLE tickets (id INT,team TEXT,home_team TEXT,...
UPDATE tickets SET price = 120 WHERE team = 'Boston Celtics';
What is the total revenue generated by tours in the 'virtual' category?
CREATE TABLE tours (tour_id INT,tour_name TEXT,category TEXT,start_date DATE,end_date DATE,revenue INT); INSERT INTO tours (tour_id,tour_name,category,start_date,end_date,revenue) VALUES (501,'Virtual Rome','virtual','2022-01-01','2022-12-31',30000),(502,'Paris 360','virtual','2022-01-01','2022-12-31',40000),(503,'Anci...
SELECT SUM(revenue) as total_revenue FROM tours WHERE category = 'virtual';
What is the number of events and their total revenue by month in 2021?
CREATE TABLE events (id INT,name VARCHAR(255),category VARCHAR(255),date DATE,revenue DECIMAL(10,2));
SELECT DATE_FORMAT(date, '%Y-%m') AS month, COUNT(id) AS events, SUM(revenue) AS revenue FROM events WHERE date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY month;
Find the longest running military innovation project in the Middle East
CREATE TABLE military_innovation_projects (project_id INT,region VARCHAR(255),project_name VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO military_innovation_projects (project_id,region,project_name,start_date,end_date) VALUES (1,'Middle East','Project A','2010-01-01','2015-12-31'),(2,'Middle East','Project B...
SELECT project_name, DATEDIFF(end_date, start_date) AS duration FROM military_innovation_projects WHERE region = 'Middle East' ORDER BY duration DESC LIMIT 1;
What is the total quantity of locally sourced ingredients used in menu items?
CREATE TABLE Dishes (DishID INT,Name VARCHAR(50),Quantity INT); CREATE TABLE Ingredients (IngredientID INT,DishID INT,Quantity INT,LocallySourced BOOLEAN); INSERT INTO Dishes (DishID,Name,Quantity) VALUES (1,'Veggie Burger',250),(2,'Potato Salad',150); INSERT INTO Ingredients (IngredientID,DishID,Quantity,LocallySource...
SELECT SUM(i.Quantity) FROM Dishes d JOIN Ingredients i ON d.DishID = i.DishID WHERE i.LocallySourced = TRUE;
What is the average fare for public transportation in Toronto?
CREATE TABLE public_transportation_fare (fare_id INT,fare FLOAT,city VARCHAR(50)); INSERT INTO public_transportation_fare (fare_id,fare,city) VALUES (1,3.5,'Toronto'),(2,4.2,'Toronto'),(3,2.8,'Toronto');
SELECT AVG(fare) FROM public_transportation_fare WHERE city = 'Toronto';
Which species have the highest average carbon sequestration?
CREATE TABLE Species (SpeciesID INT,SpeciesName TEXT,CarbonSequestration REAL); INSERT INTO Species (SpeciesID,SpeciesName,CarbonSequestration) VALUES (1,'Red Oak',12.3),(2,'White Pine',10.5);
SELECT SpeciesName, AVG(CarbonSequestration) as AverageSequestration FROM Species GROUP BY SpeciesName ORDER BY AverageSequestration DESC LIMIT 1;
List all autonomous bus routes and the number of incidents in Toronto for each route.
CREATE TABLE autonomous_buses (bus_id INT,route_id INT,trip_start_time TIMESTAMP,trip_end_time TIMESTAMP,incidents INT); INSERT INTO autonomous_buses (bus_id,route_id,trip_start_time,trip_end_time,incidents) VALUES (1,101,'2022-01-01 08:00:00','2022-01-01 09:00:00',0),(2,102,'2022-01-01 08:00:00','2022-01-01 09:00:00',...
SELECT route_id, SUM(incidents) FROM autonomous_buses WHERE city = 'Toronto' GROUP BY route_id;
What is the total revenue generated by sustainable tourism in Barcelona?
CREATE TABLE tourism_revenue (city TEXT,tourism_type TEXT,revenue INT); INSERT INTO tourism_revenue (city,tourism_type,revenue) VALUES ('Barcelona','Sustainable',3000000),('Barcelona','Traditional',5000000);
SELECT revenue FROM tourism_revenue WHERE city = 'Barcelona' AND tourism_type = 'Sustainable';
Who are the top 3 customers in Asia based on the total order value?
CREATE TABLE customers (customer_id INT,customer_name TEXT,country TEXT); CREATE TABLE orders (order_id INT,customer_id INT,order_value DECIMAL); INSERT INTO customers (customer_id,customer_name,country) VALUES (1,'Jane Smith','Canada'),(2,'John Doe','Asia'),(3,'Mike Johnson','USA'),(4,'Sara Lee','Asia'); INSERT INTO o...
SELECT customer_id, customer_name, SUM(order_value) AS total_order_value FROM orders JOIN customers ON orders.customer_id = customers.customer_id WHERE country = 'Asia' GROUP BY customer_id, customer_name ORDER BY total_order_value DESC LIMIT 3;
What is the total assets value for each wealth management advisor?
CREATE TABLE wealth_management_advisors (advisor_id INT,name VARCHAR(50)); INSERT INTO wealth_management_advisors (advisor_id,name) VALUES (1,'Dupont'),(2,'Ahmad'),(3,'Patel'); CREATE TABLE assets (asset_id INT,advisor_id INT,value DECIMAL(10,2)); INSERT INTO assets (asset_id,advisor_id,value) VALUES (1,1,500000.00),(2...
SELECT w.name, SUM(a.value) FROM wealth_management_advisors w JOIN assets a ON w.advisor_id = a.advisor_id GROUP BY w.name;
How many crimes were reported in the state of New York in the year 2020?
CREATE TABLE public.crime_statistics (id serial PRIMARY KEY,state varchar(255),year int,num_crimes int); INSERT INTO public.crime_statistics (state,year,num_crimes) VALUES ('New York',2020,50000);
SELECT SUM(num_crimes) FROM public.crime_statistics WHERE state = 'New York' AND year = 2020;
How many labor violations were reported in the USA?
CREATE TABLE manufacturers (manufacturer_id INT,manufacturer_name TEXT,country TEXT); CREATE TABLE labor_reports (report_id INT,manufacturer_id INT,violation_count INT,report_date DATE); INSERT INTO manufacturers (manufacturer_id,manufacturer_name,country) VALUES (1,'EcoFashions','USA'),(2,'FairWear','Canada'); INSERT ...
SELECT SUM(violation_count) FROM labor_reports JOIN manufacturers ON labor_reports.manufacturer_id = manufacturers.manufacturer_id WHERE country = 'USA';
What is the maximum number of courses completed by a teacher in a year?
CREATE TABLE teachers (teacher_id INT,first_name VARCHAR(255),last_name VARCHAR(255)); CREATE TABLE courses (course_id INT,course_name VARCHAR(255),completion_date DATE); CREATE TABLE teacher_courses (teacher_id INT,course_id INT,completion_date DATE);
SELECT t.teacher_id, MAX(YEAR(tc.completion_date)) AS max_year, COUNT(tc.course_id) AS max_courses FROM teachers t JOIN teacher_courses tc ON t.teacher_id = tc.teacher_id JOIN courses c ON tc.course_id = c.course_id GROUP BY t.teacher_id HAVING MAX(YEAR(tc.completion_date)) = (SELECT MAX(YEAR(completion_date)) FROM tea...
What was the total budget for rural infrastructure projects in Peru during 2015?
CREATE TABLE rural_infrastructure_projects (id INT,project_name VARCHAR(50),country VARCHAR(50),budget FLOAT,year INT); INSERT INTO rural_infrastructure_projects (id,project_name,country,budget,year) VALUES (1,'Peruvian Rural Roads Program','Peru',15000000.00,2015),(2,'Peruvian Irrigation Modernization Project','Peru',...
SELECT SUM(budget) FROM rural_infrastructure_projects WHERE country = 'Peru' AND year = 2015;
What is the minimum and maximum depth of all marine protected areas, grouped by their country?
CREATE TABLE marine_protected_areas (area_name VARCHAR(255),country VARCHAR(255),min_depth FLOAT,max_depth FLOAT); INSERT INTO marine_protected_areas (area_name,country,min_depth,max_depth) VALUES ('Galapagos Islands','Ecuador',100.0,4000.0),('Great Barrier Reef','Australia',50.0,200.0),('Palau National Marine Sanctuar...
SELECT country, MIN(min_depth) as min_depth, MAX(max_depth) as max_depth FROM marine_protected_areas GROUP BY country;
What is the maximum investment made by a customer in the western region?
CREATE TABLE customer_data (customer_id INT,name VARCHAR(20),region VARCHAR(10)); INSERT INTO customer_data (customer_id,name,region) VALUES (1,'John Doe','west'),(2,'Jane Smith','south'),(3,'Mary Johnson','west'); CREATE TABLE investment_data (customer_id INT,investment FLOAT); INSERT INTO investment_data (customer_id...
SELECT MAX(investment) FROM investment_data INNER JOIN customer_data ON investment_data.customer_id = customer_data.customer_id WHERE customer_data.region = 'west';
Show the latest drilling report date, well name, and status for wells in the Caspian Sea, partitioned by the report type.
CREATE TABLE caspian_drilling (report_id INT,well_id INT,report_date DATE,report_type VARCHAR(50),status VARCHAR(50)); INSERT INTO caspian_drilling (report_id,well_id,report_date,report_type,status) VALUES (5,7,'2021-05-01','Daily','Completed'),(6,7,'2021-05-02','Daily','Completed'),(7,8,'2021-04-01','Monthly','In Prog...
SELECT caspian_drilling.report_type, caspian_drilling.report_date, wells.well_name, caspian_drilling.status, ROW_NUMBER() OVER (PARTITION BY caspian_drilling.report_type ORDER BY caspian_drilling.report_date DESC) as row_num FROM caspian_drilling JOIN wells ON caspian_drilling.well_id = wells.well_id WHERE wells.locati...
Compare average virtual tour engagement between hotels and vacation rentals
CREATE TABLE virtual_tours (tour_id INT PRIMARY KEY,listing_id INT,listing_type VARCHAR(20),engagement FLOAT);
SELECT AVG(engagement) FROM virtual_tours WHERE listing_type = 'hotel'
What is the total number of inclusion efforts in "Northwest" region?
CREATE TABLE Inclusion_Efforts (effort_id INT,region VARCHAR(20),start_date DATE,end_date DATE); INSERT INTO Inclusion_Efforts (effort_id,region,start_date,end_date) VALUES (1,'Northwest','2019-01-01','2019-12-31'),(2,'Southwest','2018-12-01','2020-01-01'); INSERT INTO Inclusion_Efforts (effort_id,region,start_date,end...
SELECT COUNT(*) FROM Inclusion_Efforts WHERE region = 'Northwest';
What is the average age of policyholders who have a car make of 'Tesla'?
CREATE TABLE Policyholders (PolicyholderID INT,Age INT,CarMake VARCHAR(20)); INSERT INTO Policyholders (PolicyholderID,Age,CarMake) VALUES (1,35,'Tesla'),(2,45,'Honda'),(3,50,'Tesla');
SELECT AVG(Age) FROM Policyholders WHERE CarMake = 'Tesla';
What are the top 3 cities with the most green buildings in the 'green_buildings' table?
CREATE TABLE if not exists green_buildings (building_id INT,building_name VARCHAR(255),city VARCHAR(255),certification_level VARCHAR(50));
SELECT city, COUNT(*) as building_count FROM green_buildings GROUP BY city ORDER BY building_count DESC LIMIT 3;
What was the average donation amount by new donors in Q1 2021?
CREATE TABLE Donors (DonorID INT,DonationDate DATE,DonationAmount DECIMAL); INSERT INTO Donors (DonorID,DonationDate,DonationAmount) VALUES (1,'2021-01-01',50.00),(2,'2021-01-15',100.00),(3,'2021-03-01',75.00);
SELECT AVG(DonationAmount) FROM Donors WHERE DonationDate BETWEEN '2021-01-01' AND '2021-03-31' AND DonorID NOT IN (SELECT DonorID FROM Donors WHERE DonationDate < '2021-01-01');
What is the contact information for suppliers from Colombia who provide renewable energy solutions and have a workforce development program in place?
CREATE TABLE Suppliers (SupplierID INT,SupplierName VARCHAR(50),Country VARCHAR(50),Industry VARCHAR(50),SustainabilityRating DECIMAL(3,2),WorkforceDevelopment BOOLEAN); INSERT INTO Suppliers (SupplierID,SupplierName,Country,Industry,SustainabilityRating,WorkforceDevelopment) VALUES (1,'EcoSupplies Inc.','USA','Renewab...
SELECT SupplierName, Country, Industry FROM Suppliers WHERE Country = 'Colombia' AND Industry = 'Renewable Energy' AND WorkforceDevelopment = TRUE;
Find the maximum score of 'ArcadeGame' in 'AU' region.
CREATE TABLE ArcadeGame (playerID INT,region VARCHAR(5),score INT); INSERT INTO ArcadeGame (playerID,region,score) VALUES (1,'AU',20),(2,'AU',30),(3,'AU',50),(4,'EU',80);
SELECT MAX(score) FROM ArcadeGame WHERE region = 'AU' AND game = 'ArcadeGame';
What is the maximum billing amount for cases handled by attorneys in the 'Miami' region?
CREATE TABLE cases (id INT,attorney_id INT,billing_amount INT); INSERT INTO cases (id,attorney_id,billing_amount) VALUES (1,1,6000); CREATE TABLE attorneys (id INT,name TEXT,region TEXT,title TEXT); INSERT INTO attorneys (id,name,region,title) VALUES (1,'Sofia Sanchez','Miami','Partner');
SELECT MAX(billing_amount) FROM cases JOIN attorneys ON cases.attorney_id = attorneys.id WHERE attorneys.region = 'Miami';
What is the maximum investment made in the education sector?
CREATE TABLE investments (id INT,sector VARCHAR(20),amount DECIMAL(10,2)); INSERT INTO investments (id,sector,amount) VALUES (1,'education',15000.00),(2,'education',20000.00),(3,'education',22000.00);
SELECT MAX(amount) FROM investments WHERE sector = 'education';
Update the names of all libraries in 'City 1' to include 'New' at the beginning of the name.
CREATE TABLE cities (id INT,name VARCHAR(255)); INSERT INTO cities (id,name) VALUES (1,'City 1'),(2,'City 2'); CREATE TABLE libraries (id INT,name VARCHAR(255),city_id INT); INSERT INTO libraries (id,name,city_id) VALUES (1,'Library 1',1),(2,'Library 2',1),(3,'Library 3',2);
UPDATE libraries SET name = CONCAT('New ', name) WHERE city_id = (SELECT id FROM cities WHERE name = 'City 1');
What are the most common mental health campaigns in South Africa?
CREATE TABLE campaigns (id INT PRIMARY KEY,country VARCHAR(50),name VARCHAR(50),reach FLOAT);
SELECT name FROM campaigns WHERE country = 'South Africa' GROUP BY name ORDER BY SUM(reach) DESC;
What is the total number of cases heard in community courts by gender?
CREATE TABLE community_courts (id INT,case_number INT,gender VARCHAR(10));
SELECT gender, COUNT(*) FROM community_courts GROUP BY gender;
What are the top 5 most preferred cosmetic products by consumers, along with their cruelty-free certification status?
CREATE TABLE cosmetic_products (product_id INT,product_name VARCHAR(50),brand_name VARCHAR(50),consumer_preference INT); INSERT INTO cosmetic_products (product_id,product_name,brand_name,consumer_preference) VALUES (1,'Lipstick','Loreal',4),(2,'Mascara','Maybelline',5),(3,'Foundation','Estee Lauder',3),(4,'Eyeshadow','...
SELECT cp.product_name, cp.brand_name, cp.consumer_preference, cfc.certified FROM cosmetic_products cp INNER JOIN cruelty_free_certification cfc ON cp.product_id = cfc.product_id ORDER BY cp.consumer_preference DESC LIMIT 5;
What is the minimum and maximum area (in sq. km) of indigenous food systems in South America?
CREATE TABLE indigenous_food_systems (country VARCHAR(50),area FLOAT); INSERT INTO indigenous_food_systems (country,area) VALUES ('Brazil',50000.0),('Peru',45000.0),('Colombia',60000.0);
SELECT MIN(area), MAX(area) FROM indigenous_food_systems WHERE country IN ('Brazil', 'Peru', 'Colombia');
Find total number of patients treated with CBT and medication combined
CREATE TABLE patients (id INT,name VARCHAR(50),treatment VARCHAR(50)); CREATE TABLE treatments (treatment VARCHAR(50),cost INT);
SELECT COUNT(*) FROM (SELECT p.name FROM patients p JOIN treatments t ON p.treatment = t.treatment WHERE t.treatment IN ('CBT', 'medication') GROUP BY p.name) AS combined_treatments;
Identify the total biomass of fish in farms located in the Black sea?
CREATE TABLE fish_farms (id INT,name TEXT,country TEXT,biomass FLOAT); INSERT INTO fish_farms (id,name,country) VALUES (1,'Farm P','Bulgaria'); INSERT INTO fish_farms (id,name,country) VALUES (2,'Farm Q','Romania'); CREATE TABLE biomass_data (farm_id INT,biomass FLOAT); INSERT INTO biomass_data (farm_id,biomass) VALUES...
SELECT SUM(bd.biomass) FROM fish_farms ff JOIN biomass_data bd ON ff.id = bd.farm_id WHERE ff.country LIKE '%Black%';
How many patients in Canada have been diagnosed with bipolar disorder?
CREATE TABLE patients (id INT,age INT,gender TEXT,country TEXT,condition TEXT); INSERT INTO patients (id,age,gender,country,condition) VALUES (1,30,'Female','Canada','Bipolar Disorder'); INSERT INTO patients (id,age,gender,country,condition) VALUES (2,40,'Male','USA','Depression');
SELECT COUNT(*) FROM patients WHERE country = 'Canada' AND condition = 'Bipolar Disorder';
How many female players have designed a game in the RPG genre and have more than 10,000 players?
CREATE TABLE game_designers (designer_id INT,gender VARCHAR(10),genre VARCHAR(10),players INT);
SELECT COUNT(*) FROM game_designers WHERE gender = 'female' AND genre = 'RPG' AND players > 10000;
What is the maximum number of tickets sold in a day for the bulls in the ticket_sales table?
CREATE TABLE ticket_sales (team_name TEXT,sale_date DATE,quantity_sold INTEGER);
SELECT MAX(quantity_sold) FROM ticket_sales WHERE team_name = 'bulls';
What is the average age of farmers in 'New York'?
CREATE TABLE farmers (id INT PRIMARY KEY,name VARCHAR(50),age INT,gender VARCHAR(10),location VARCHAR(50)); INSERT INTO farmers (id,name,age,gender,location) VALUES (2,'Jane Smith',40,'Female','New York');
SELECT AVG(age) FROM farmers WHERE location = 'New York';
What is the total number of fish in each Ocean?
CREATE TABLE Fish_Farms (Farm_ID INT,Farm_Name TEXT,Ocean TEXT,Number_of_Fish INT); INSERT INTO Fish_Farms (Farm_ID,Farm_Name,Ocean,Number_of_Fish) VALUES (1,'Farm G','Pacific',5000); INSERT INTO Fish_Farms (Farm_ID,Farm_Name,Ocean,Number_of_Fish) VALUES (2,'Farm H','Atlantic',6000); INSERT INTO Fish_Farms (Farm_ID,Far...
SELECT Ocean, SUM(Number_of_Fish) FROM Fish_Farms GROUP BY Ocean;
What is the average mass of Chinese spacecraft?
CREATE TABLE SpacecraftData (id INT,name VARCHAR(50),manufacturer VARCHAR(50),mass FLOAT); INSERT INTO SpacecraftData (id,name,manufacturer,mass) VALUES (1,'Saturn V','NASA',3000),(2,'Space Shuttle','NASA',2000),(3,'Proton-M','Russia',1100),(4,'Long March 5','China',1700),(5,'Shenzhou 10','China',8600);
SELECT AVG(mass) FROM SpacecraftData WHERE manufacturer = 'China';
Delete records of users who have unregistered from a course in the last week from the users table
CREATE TABLE users (id INT,name VARCHAR(50),email VARCHAR(50),registered_for_course BOOLEAN);
DELETE FROM users WHERE registered_for_course = false AND registration_date < DATE_SUB(CURDATE(), INTERVAL 1 WEEK);
What is the total number of cultural competency training sessions conducted in each region?
CREATE TABLE cultural_competency_training (region VARCHAR(255),sessions INT); INSERT INTO cultural_competency_training (region,sessions) VALUES ('Northeast',400),('Southeast',500),('Midwest',350),('West',600);
SELECT region, SUM(sessions) FROM cultural_competency_training GROUP BY region;
What is the average salinity of the ocean in each hemisphere, further grouped by depth?
CREATE TABLE ocean_salinity (id INT,year INT,hemisphere VARCHAR(50),depth INT,avg_salinity FLOAT); INSERT INTO ocean_salinity (id,year,hemisphere,depth,avg_salinity) VALUES (1,2020,'Northern Hemisphere',1000,35); INSERT INTO ocean_salinity (id,year,hemisphere,depth,avg_salinity) VALUES (2,2020,'Southern Hemisphere',200...
SELECT hemisphere, depth, AVG(avg_salinity) FROM ocean_salinity GROUP BY hemisphere, depth;
Who are the top 3 users in terms of ad revenue?
CREATE TABLE users (id INT,ad_revenue DECIMAL(10,2)); INSERT INTO users (id,ad_revenue) VALUES (1,500.00),(2,450.00),(3,600.00),(4,300.00),(5,700.00),(6,250.00);
SELECT id, ad_revenue FROM users ORDER BY ad_revenue DESC LIMIT 3;
How many times have adaptive clothing items been restocked, by size, in the last 12 months?
CREATE TABLE Inventory (inventory_id INT,product_id INT,size VARCHAR(10),restock_date DATE); CREATE TABLE Products (product_id INT,product_category VARCHAR(20)); INSERT INTO Inventory (inventory_id,product_id,size,restock_date) VALUES (1,1,'XL','2022-02-01');
SELECT size, COUNT(DISTINCT inventory_id) as restock_count FROM Inventory JOIN Products ON Inventory.product_id = Products.product_id WHERE product_category = 'Adaptive Clothing' AND restock_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 12 MONTH) AND CURRENT_DATE GROUP BY size;
What are the total prize pools for esports events held in Asia and Europe?
CREATE TABLE Events (EventID INT,Country VARCHAR(20),PrizePool INT); INSERT INTO Events (EventID,Country,PrizePool) VALUES (1,'USA',500000),(2,'South Korea',700000),(3,'Canada',400000),(4,'Germany',400000),(5,'USA',600000),(6,'South Korea',800000),(7,'China',900000);
SELECT Country, SUM(PrizePool) FROM Events WHERE Country IN ('Asia', 'Europe') GROUP BY Country;
What is the total number of doctors in Australia?
CREATE TABLE Doctors (Country VARCHAR(50),Doctors INT); INSERT INTO Doctors (Country,Doctors) VALUES ('Australia',100000);
SELECT SUM(Doctors) FROM Doctors WHERE Country = 'Australia';
Delete records of soldiers who were discharged before 2010-01-01 from the soldiers_discharge_data table
CREATE TABLE soldiers_discharge_data (soldier_id INT,name VARCHAR(50),rank VARCHAR(50),discharge_date DATE);
DELETE FROM soldiers_discharge_data WHERE discharge_date < '2010-01-01';
Find the top 2 brands with the highest average product price for 'upcycled' products.
CREATE TABLE brands(brand_id INT,brand_name TEXT); INSERT INTO brands(brand_id,brand_name) VALUES (1,'BrandA'),(2,'BrandB'),(3,'BrandC'); CREATE TABLE products(product_id INT,product_name TEXT,brand_id INT,price DECIMAL(5,2)); INSERT INTO products(product_id,product_name,brand_id,price) VALUES (1,'Product1',1,50),(2,'P...
SELECT brand_id, AVG(price) as avg_price FROM products WHERE product_name LIKE '%upcycled%' GROUP BY brand_id ORDER BY avg_price DESC LIMIT 2;
What is the average water usage in MWh per month for the industrial sector in 2020?
CREATE TABLE avg_water_usage_per_month (year INT,sector VARCHAR(20),month INT,usage FLOAT); INSERT INTO avg_water_usage_per_month (year,sector,month,usage) VALUES (2020,'industrial',1,7000); INSERT INTO avg_water_usage_per_month (year,sector,month,usage) VALUES (2020,'industrial',2,7500); INSERT INTO avg_water_usage_pe...
SELECT AVG(usage) FROM avg_water_usage_per_month WHERE year = 2020 AND sector = 'industrial';