instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Update the pallet count for shipment ID 150 to 750, if the current pallet count is less than 750.
CREATE TABLE shipment (id INT PRIMARY KEY,warehouse_id INT,carrier_id INT,pallet_count INT,shipped_date DATE);
UPDATE shipment SET pallet_count = 750 WHERE id = 150 AND pallet_count < 750;
What is the minimum exit valuation for startups in the FinTech sector founded by underrepresented minority founders?
CREATE TABLE exits (id INT,company_id INT,exit_type TEXT,exit_valuation INT,date DATE); INSERT INTO exits (id,company_id,exit_type,exit_valuation,date) VALUES (1,1,'Acquisition',50000000,'2021-01-01'),(2,2,'IPO',100000000,'2022-01-01'),(3,3,'Acquisition',25000000,'2019-01-01');
SELECT MIN(exits.exit_valuation) FROM exits JOIN companies ON exits.company_id = companies.id WHERE companies.industry = 'FinTech' AND companies.founder_ethnicity IN ('Hispanic', 'African American', 'Native American');
Calculate the total teaching hours for all teachers who teach 'English' and work in 'Florida'
CREATE TABLE Hours (TeacherID INT,State VARCHAR(10),Subject VARCHAR(10),Hours DECIMAL(5,2)); INSERT INTO Hours (TeacherID,State,Subject,Hours) VALUES (1,'FL','English',15.5);
SELECT SUM(Hours) FROM Hours WHERE Subject = 'English' AND State = 'Florida';
How many professional development courses were completed by teachers from each country?
CREATE TABLE teachers (id INT,country TEXT);CREATE TABLE courses (id INT,teacher_id INT);CREATE TABLE course_completions (course_id INT,completion_date DATE);
SELECT teachers.country, COUNT(DISTINCT courses.id) as courses_completed FROM teachers INNER JOIN courses ON teachers.id = courses.teacher_id INNER JOIN course_completions ON courses.id = course_completions.course_id GROUP BY teachers.country;
Delete the record of the teacher with ID 2 from the 'teachers' table
CREATE TABLE teachers (id INT,name VARCHAR(20),age INT,address VARCHAR(30)); INSERT INTO teachers (id,name,age,address) VALUES (1,'Alice',30,'San Francisco'); INSERT INTO teachers (id,name,age,address) VALUES (2,'Brian',35,'Oakland'); INSERT INTO teachers (id,name,age,address) VALUES (3,'Carla',40,'Berkeley');
DELETE FROM teachers WHERE id = 2;
What are the average and standard deviation of the ranges of electric vehicles in the vehicle_test_data table?
CREATE TABLE vehicle_test_data (id INT,make VARCHAR(20),model VARCHAR(20),range DECIMAL(5,2)); INSERT INTO vehicle_test_data (id,make,model,range) VALUES (1,'Tesla','Model 3',322.3),(2,'Ford','Mustang Mach-E',230.8),(3,'Chevrolet','Bolt',259.0);
SELECT AVG(range), STDDEV(range) FROM vehicle_test_data WHERE is_electric = true;
What is the average cost of a sustainable building project in Oregon?
CREATE TABLE Sustainable_Projects_OR (project_id INT,project_name VARCHAR(50),state VARCHAR(2),cost FLOAT,is_sustainable BOOLEAN); INSERT INTO Sustainable_Projects_OR VALUES (1,'Portland Eco-House','OR',500000,true);
SELECT AVG(cost) FROM Sustainable_Projects_OR WHERE state = 'OR' AND is_sustainable = true;
What is the average number of likes on posts containing the hashtag "#sustainability" in the last month?
CREATE TABLE posts (id INT,user_id INT,content TEXT,likes INT,timestamp DATETIME); INSERT INTO posts (id,user_id,content,likes,timestamp) VALUES (1,1,'Sustainable living tips',250,'2022-01-01 10:00:00'),(2,2,'Eco-friendly product review',120,'2022-01-05 15:30:00'); CREATE TABLE hashtags (id INT,post_id INT,hashtag TEXT...
SELECT AVG(likes) FROM posts JOIN hashtags ON posts.id = hashtags.post_id WHERE hashtag = '#sustainability' AND timestamp BETWEEN DATE_SUB(NOW(), INTERVAL 1 MONTH) AND NOW();
What is the average energy storage capacity in megawatt-hours (MWh) for Australia and Canada?
CREATE TABLE energy_storage (country VARCHAR(50),capacity_mwh INT); INSERT INTO energy_storage (country,capacity_mwh) VALUES ('Australia',1342),('Canada',2501);
SELECT AVG(capacity_mwh) FROM energy_storage WHERE country IN ('Australia', 'Canada');
What is the total water consumption by industrial sector in California for the year 2020?
CREATE TABLE industrial_water_use (sector VARCHAR(50),year INT,amount INT); INSERT INTO industrial_water_use (sector,year,amount) VALUES ('Agriculture',2020,12000),('Manufacturing',2020,8000),('Mining',2020,5000);
SELECT i.sector, SUM(i.amount) as total_water_consumption FROM industrial_water_use i WHERE i.year = 2020 AND i.sector = 'Industrial' GROUP BY i.sector;
How many farms are in 'region3'?
CREATE TABLE farm (id INT,region VARCHAR(20),crop VARCHAR(20),yield INT);
SELECT COUNT(*) FROM farm WHERE region = 'region3';
Delete the course with the highest ID.
CREATE TABLE courses (id INT,name VARCHAR(50),start_date DATE,end_date DATE); INSERT INTO courses (id,name,start_date,end_date) VALUES (1,'Introduction to Programming','2022-01-01','2022-04-30'); INSERT INTO courses (id,name,start_date,end_date) VALUES (2,'Data Science','2022-05-01','2022-08-31'); INSERT INTO courses (...
DELETE FROM courses WHERE id = (SELECT MAX(id) FROM courses);
What is the total number of digital assets created by developers from the US and Canada?
CREATE TABLE developers (id INT,name TEXT,country TEXT); INSERT INTO developers (id,name,country) VALUES (1,'Alice','USA'),(2,'Bob','Canada'),(3,'Charlie','USA'); CREATE TABLE digital_assets (id INT,name TEXT,developer_id INT); INSERT INTO digital_assets (id,name,developer_id) VALUES (1,'CoinA',1),(2,'CoinB',2),(3,'Coi...
SELECT COUNT(*) FROM digital_assets d JOIN developers dev ON d.developer_id = dev.id WHERE dev.country IN ('USA', 'Canada');
What is the total biomass of fish in the Mediterranean sea and the Black sea?
CREATE TABLE biomass (location VARCHAR(20),biomass_kg FLOAT); INSERT INTO biomass (location,biomass_kg) VALUES ('Mediterranean sea',1200000),('Black sea',900000);
SELECT SUM(biomass_kg) FROM biomass WHERE location IN ('Mediterranean sea', 'Black sea');
Create a table for artists' biographical data
CREATE TABLE artists (artist_id INT PRIMARY KEY,name VARCHAR(100),birth_date DATE,death_date DATE,nationality VARCHAR(50));
CREATE TABLE artists_biography AS SELECT artist_id, name, birth_date, death_date, nationality FROM artists;
What is the number of hotels that have adopted cloud PMS (Property Management System) in Japan, India, and Brazil?
CREATE TABLE pms_stats (pms_id INT,pms_name TEXT,country TEXT,hotel_count INT); INSERT INTO pms_stats (pms_id,pms_name,country,hotel_count) VALUES (1,'PMS 1','Japan',100),(2,'PMS 2','India',150),(3,'PMS 3','Brazil',75),(4,'PMS 4','Japan',50),(5,'PMS 5','Brazil',125);
SELECT country, SUM(hotel_count) as total_hotels FROM pms_stats WHERE country IN ('Japan', 'India', 'Brazil') GROUP BY country;
What is the next marine research expedition for the vessel 'Kiel Explorer'?
CREATE TABLE Research_Expeditions (id INT PRIMARY KEY,expedition_name VARCHAR(50),lead_scientist VARCHAR(50),vessel VARCHAR(50),start_date DATETIME); INSERT INTO Research_Expeditions (id,expedition_name,lead_scientist,vessel,start_date) VALUES (1,'Mariana Trench Exploration','Dr. Sylvia Earle','Deepsea Challenger','202...
SELECT expedition_name, lead_scientist, vessel, start_date, LEAD(start_date) OVER(PARTITION BY vessel ORDER BY start_date) as next_expedition FROM Research_Expeditions WHERE vessel = 'Kiel Explorer'
What is the average soil moisture in the top 3 driest provinces in China in the past month?
CREATE TABLE soil_moisture_data (province VARCHAR(255),soil_moisture INT,date DATE); INSERT INTO soil_moisture_data (province,soil_moisture,date) VALUES ('Shanxi',10,'2022-06-01'),('Shaanxi',15,'2022-06-01'),('Gansu',20,'2022-06-01'),('Henan',25,'2022-06-01');
SELECT province, AVG(soil_moisture) as avg_soil_moisture FROM (SELECT province, soil_moisture, RANK() OVER (PARTITION BY NULL ORDER BY soil_moisture ASC) as dryness_rank FROM soil_moisture_data WHERE date BETWEEN '2022-05-01' AND '2022-06-01' GROUP BY province) subquery WHERE dryness_rank <= 3 GROUP BY province;
What is the total number of practitioners of traditional arts in Asia, listed alphabetically by country?
CREATE TABLE ArtsPractitioners (Country VARCHAR(255),NumberOfPractitioners INT); INSERT INTO ArtsPractitioners (Country,NumberOfPractitioners) VALUES ('India',25000),('China',20000),('Indonesia',18000),('Japan',15000),('Vietnam',12000);
SELECT Country, SUM(NumberOfPractitioners) FROM ArtsPractitioners WHERE Country = 'Asia' GROUP BY Country ORDER BY Country ASC;
Find the average price of eco-friendly skincare products
CREATE TABLE cosmetics (id INT,name VARCHAR(50),price DECIMAL(5,2),eco_friendly BOOLEAN);
SELECT AVG(price) FROM cosmetics WHERE eco_friendly = TRUE;
What's the average production rate for wells in the Middle East in the last quarter?
CREATE TABLE well_production (well_id INT,measurement_date DATE,production_rate FLOAT,location TEXT); INSERT INTO well_production (well_id,measurement_date,production_rate,location) VALUES (1,'2022-01-01',500,'USA'),(2,'2022-02-01',700,'Saudi Arabia'),(3,'2022-03-01',600,'Canada'),(4,'2022-02-01',800,'Iran'),(5,'2022-0...
SELECT AVG(production_rate) FROM well_production WHERE measurement_date >= DATEADD(quarter, -1, GETDATE()) AND location LIKE 'Middle East%';
Find the city with the highest recycling rate in 2021
CREATE TABLE recycling_rates (city VARCHAR(20),year INT,recycling_rate FLOAT);INSERT INTO recycling_rates (city,year,recycling_rate) VALUES ('San Francisco',2019,0.65),('San Francisco',2020,0.7),('San Francisco',2021,0.75),('Oakland',2019,0.55),('Oakland',2020,0.6),('Oakland',2021,0.65);
SELECT city FROM recycling_rates WHERE year = 2021 AND recycling_rate = (SELECT MAX(recycling_rate) FROM recycling_rates WHERE year = 2021);
Delete records in the food_inspections table where the inspection_date is before '2021-01-01'
CREATE TABLE food_inspections (restaurant_id INT,inspection_date DATE);
DELETE FROM food_inspections WHERE inspection_date < '2021-01-01';
Which students have a higher mental health score than the average mental health score of their school?
CREATE TABLE schools (school_id INT,school_name VARCHAR(255),city VARCHAR(255)); CREATE TABLE student_mental_health (student_id INT,school_id INT,mental_health_score INT); INSERT INTO schools (school_id,school_name,city) VALUES (1,'School A','City X'),(2,'School B','City X'),(3,'School C','City Y'); INSERT INTO student...
SELECT student_id, mental_health_score, school_id, AVG(mental_health_score) OVER (PARTITION BY school_id) as avg_school_score FROM student_mental_health;
Which mining operations have no CO2 emissions data?
CREATE TABLE mining_operations (operation_id INT,operation_name VARCHAR(50),location VARCHAR(50)); CREATE TABLE co2_emissions (operation_id INT,co2_emissions_tonnes INT); INSERT INTO mining_operations (operation_id,operation_name,location) VALUES (1,'Operation A','USA'),(2,'Operation B','Canada'),(3,'Operation C','Mexi...
SELECT mining_operations.operation_name FROM mining_operations LEFT JOIN co2_emissions ON mining_operations.operation_id = co2_emissions.operation_id WHERE co2_emissions.operation_id IS NULL;
What is the total number of animals in each habitat, grouped by habitat size?
CREATE TABLE animals (id INT PRIMARY KEY,name VARCHAR(50),species VARCHAR(50),population INT); CREATE TABLE habitats (id INT PRIMARY KEY,name VARCHAR(50),location VARCHAR(50),size FLOAT,animal_id INT);
SELECT habitats.size, COUNT(DISTINCT animals.id) AS total_animals FROM animals INNER JOIN habitats ON animals.id = habitats.animal_id GROUP BY habitats.size;
List all artists and their respective countries who have had their works displayed in the Guggenheim Museum.
CREATE TABLE Artists (ArtistID int,ArtistName varchar(100),Nationality varchar(50)); INSERT INTO Artists (ArtistID,ArtistName,Nationality) VALUES (1,'Pablo Picasso','Spanish'),(2,'Jackson Pollock','American'),(3,'Francis Bacon','Irish'); CREATE TABLE ExhibitedWorks (WorkID int,ArtistID int,MuseumID int); INSERT INTO Ex...
SELECT Artists.ArtistName, Artists.Nationality FROM Artists INNER JOIN ExhibitedWorks ON Artists.ArtistID = ExhibitedWorks.ArtistID INNER JOIN Museums ON ExhibitedWorks.MuseumID = Museums.MuseumID WHERE Museums.MuseumName = 'Guggenheim Museum';
What are the total number of research grants awarded to domestic and international graduate students?
CREATE TABLE research_grants (id INT,student_type VARCHAR(10),amount DECIMAL(10,2)); INSERT INTO research_grants (id,student_type,amount) VALUES (1,'Domestic',15000.00),(2,'International',20000.00);
SELECT SUM(amount) FROM research_grants WHERE student_type IN ('Domestic', 'International');
Increase the ESG rating by 5 for company with id 1.
CREATE TABLE companies (id INT,sector TEXT,ESG_rating FLOAT); INSERT INTO companies (id,sector,ESG_rating) VALUES (1,'technology',78.2),(2,'finance',82.5),(3,'technology',84.6);
UPDATE companies SET ESG_rating = ESG_rating + 5 WHERE id = 1;
What is the total revenue and quantity sold for each sustainable category, including the total quantity sold, in Washington D.C. during the month of November 2021?
CREATE TABLE Restaurants (RestaurantID int,Name varchar(50),Location varchar(50)); CREATE TABLE Menu (MenuID int,ItemName varchar(50),Category varchar(50)); CREATE TABLE MenuSales (MenuID int,RestaurantID int,QuantitySold int,Revenue decimal(5,2),SaleDate date); INSERT INTO Menu (MenuID,ItemName,Category) VALUES (2001,...
SELECT C.Category, SUM(M.Revenue) as Revenue, SUM(M.QuantitySold) as QuantitySold FROM Menu M JOIN MenuSales MS ON M.MenuID = MS.MenuID JOIN Restaurants R ON MS.RestaurantID = R.RestaurantID JOIN (SELECT * FROM Restaurants WHERE Location LIKE '%Washington D.C.%') C ON R.RestaurantID = C.RestaurantID WHERE MS.SaleDate >...
How many community policing events occurred in each district in the last year?
CREATE TABLE Districts (DistrictID INT,DistrictName VARCHAR(255)); CREATE TABLE Events (EventID INT,EventType VARCHAR(255),DistrictID INT,EventDate DATE);
SELECT DistrictName, COUNT(EventID) as EventsCount FROM Events e JOIN Districts d ON e.DistrictID = d.DistrictID WHERE EventDate >= DATEADD(year, -1, GETDATE()) AND EventType = 'Community Policing' GROUP BY DistrictName;
What was the maximum and minimum price for 'Rice' and 'Wheat' in 'HistoricalCommodityPrices' table?
CREATE TABLE HistoricalCommodityPrices (commodity VARCHAR(20),price FLOAT,date DATE);
SELECT commodity, MAX(price) as max_price, MIN(price) as min_price FROM HistoricalCommodityPrices WHERE commodity IN ('Rice','Wheat') GROUP BY commodity;
What are the SO2 emissions for the 'Tasiast' and 'Katanga' mines?
CREATE TABLE Environmental_Impact(Mine_Name TEXT,SO2_Emissions INT,Water_Consumption INT); INSERT INTO Environmental_Impact(Mine_Name,SO2_Emissions,Water_Consumption) VALUES('Tasiast',700000,1400000); INSERT INTO Environmental_Impact(Mine_Name,SO2_Emissions,Water_Consumption) VALUES('Katanga',900000,1800000);
SELECT SO2_Emissions FROM Environmental_Impact WHERE Mine_Name IN ('Tasiast', 'Katanga');
What is the average production figure for all wells located in the Arctic Ocean?
CREATE TABLE wells (well_id varchar(10),region varchar(20),production_figures int); INSERT INTO wells (well_id,region,production_figures) VALUES ('W009','Arctic Ocean',2800),('W010','Arctic Ocean',3100),('W011','Arctic Ocean',2900);
SELECT AVG(production_figures) FROM wells WHERE region = 'Arctic Ocean';
What is the average cargo handling time for each shipping line?
CREATE TABLE shipping_lines (shipping_line_id INT,shipping_line_name VARCHAR(50),cargo_handling_time INT); INSERT INTO shipping_lines (shipping_line_id,shipping_line_name,cargo_handling_time) VALUES (1,'SL1',120),(2,'SL2',150),(3,'SL3',180);
SELECT shipping_line_name, AVG(cargo_handling_time) FROM shipping_lines GROUP BY shipping_line_name;
What is the total amount of donations received for the 'Habitat Restoration' project in 2020?;
CREATE TABLE donations (id INT,donor_name VARCHAR(50),donation_amount DECIMAL(10,2),project_name VARCHAR(50),donation_date DATE); INSERT INTO donations (id,donor_name,donation_amount,project_name,donation_date) VALUES (1,'John Doe',500,'Habitat Restoration','2020-01-01'); INSERT INTO donations (id,donor_name,donation_a...
SELECT SUM(donation_amount) FROM donations WHERE project_name = 'Habitat Restoration' AND YEAR(donation_date) = 2020;
Insert a new threat actor 'WinterLion' with id 5 into the threat_actors table
CREATE TABLE threat_actors (id INT,name VARCHAR); INSERT INTO threat_actors (id,name) VALUES (1,'APT28'),(2,'APT33'),(3,'Lazarus Group'),(4,'Cozy Bear');
INSERT INTO threat_actors (id, name) VALUES (5, 'WinterLion');
Update the end year of defense project 'Project F' to 2023.
CREATE TABLE Defense_Projects(id INT,project_name VARCHAR(255),start_year INT,end_year INT); INSERT INTO Defense_Projects(id,project_name,start_year,end_year) VALUES (1,'Project A',2015,2018),(2,'Project B',2016,2019),(3,'Project C',2017,2020),(4,'Project D',2018,2021),(5,'Project E',2015,2020),(6,'Project F',2016,2017...
UPDATE Defense_Projects SET end_year = 2023 WHERE project_name = 'Project F';
What is the average quantity of medical supplies for rural hospitals?
CREATE TABLE hospitals (id INT PRIMARY KEY,name VARCHAR(255),rural BOOLEAN,num_beds INT); INSERT INTO hospitals (id,name,rural,num_beds) VALUES (1,'Rural General Hospital',true,50),(2,'Urban Teaching Hospital',false,200); CREATE TABLE medical_supplies (id INT PRIMARY KEY,hospital_id INT,name VARCHAR(255),quantity INT);...
SELECT AVG(m.quantity) FROM medical_supplies m INNER JOIN hospitals h ON m.hospital_id = h.id WHERE h.rural = true;
What is the total R&D expenditure for each drug, ranked by the highest R&D expenditure first, for the year 2021?
CREATE TABLE r_and_d_expenditure_2021 (expenditure_id INT,drug_name VARCHAR(255),expenditure_date DATE,amount DECIMAL(10,2)); INSERT INTO r_and_d_expenditure_2021 (expenditure_id,drug_name,expenditure_date,amount) VALUES (1,'DrugP','2021-01-01',12000),(2,'DrugQ','2021-01-02',15000),(3,'DrugR','2021-01-03',18000),(4,'Dr...
SELECT drug_name, SUM(amount) as total_rd_expenditure FROM r_and_d_expenditure_2021 WHERE YEAR(expenditure_date) = 2021 GROUP BY drug_name ORDER BY total_rd_expenditure DESC;
What is the average transaction value in the retail sector in Q3 2022?
CREATE TABLE transaction (transaction_id INT,sector VARCHAR(255),transaction_value DECIMAL(10,2),transaction_date DATE); INSERT INTO transaction (transaction_id,sector,transaction_value,transaction_date) VALUES (1,'retail',100.00,'2022-07-01'),(2,'retail',150.00,'2022-08-01');
SELECT AVG(transaction_value) FROM transaction WHERE sector = 'retail' AND transaction_date BETWEEN '2022-07-01' AND '2022-09-30';
How many students have passed the exam in each subject area in the last academic year?
CREATE TABLE exam_results (student_id INT,subject_area VARCHAR(50),passed BOOLEAN,exam_date DATE); INSERT INTO exam_results (student_id,subject_area,passed,exam_date) VALUES (1,'Mathematics',true,'2021-12-01'),(2,'Mathematics',false,'2021-11-01'),(3,'Science',true,'2022-02-01'),(4,'Science',false,'2021-09-01');
SELECT subject_area, COUNT(student_id) as num_students_passed FROM exam_results WHERE exam_date >= DATEADD(year, -1, CURRENT_TIMESTAMP) AND passed = true GROUP BY subject_area;
What is the average salary in the 'east' region?
CREATE TABLE if not exists salaries4 (id INT,industry TEXT,region TEXT,salary REAL);INSERT INTO salaries4 (id,industry,region,salary) VALUES (1,'manufacturing','east',50000),(2,'retail','west',60000),(3,'manufacturing','east',55000);
SELECT AVG(salary) FROM salaries4 WHERE region = 'east';
What is the average revenue per salesperson in Q1 2022?
CREATE TABLE sales (sale_date DATE,salesperson VARCHAR(255),revenue FLOAT);
SELECT salesperson, AVG(revenue) AS avg_revenue FROM sales WHERE sale_date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY salesperson;
What is the total revenue generated by brands that use vegan materials?
CREATE TABLE VeganMaterialsBrands (brand_name TEXT,revenue INT); INSERT INTO VeganMaterialsBrands (brand_name,revenue) VALUES ('Brand1',1000),('Brand2',1500),('Brand3',2000),('Brand4',2500),('Brand5',3000);
SELECT SUM(revenue) as total_revenue FROM VeganMaterialsBrands WHERE brand_name IN (SELECT brand_name FROM Materials WHERE material_type = 'vegan');
How many disaster response volunteers were there in each region as of January 1, 2020?
CREATE TABLE volunteers (id INT,region VARCHAR(50),volunteer_type VARCHAR(50),registration_date DATE); INSERT INTO volunteers (id,region,volunteer_type,registration_date) VALUES (1,'North','Disaster Response','2019-12-20'),(2,'South','Disaster Response','2019-11-15'),(3,'East','Disaster Response','2020-01-03');
SELECT region, volunteer_type, COUNT(*) as total_volunteers FROM volunteers WHERE volunteer_type = 'Disaster Response' AND registration_date <= '2020-01-01' GROUP BY region, volunteer_type;
What is the number of employees who have completed training on unconscious bias, by manager?
CREATE TABLE EmployeeTraining2 (EmployeeID INT,Manager VARCHAR(50),TrainingType VARCHAR(50),CompletionDate DATE);
SELECT Manager, COUNT(*) as Num_Employees FROM EmployeeTraining2 WHERE TrainingType = 'Unconscious Bias' GROUP BY Manager;
How many people with disabilities have benefited from technology for social good in Central America in the last 3 years?
CREATE TABLE Beneficiaries (BeneficiaryID INT,BeneficiaryName VARCHAR(50),Disability BOOLEAN,Initiative VARCHAR(50),Year INT,Region VARCHAR(50)); INSERT INTO Beneficiaries VALUES (1,'Benef1',true,'Initiative1',2019,'Central America'),(2,'Benef2',true,'Initiative2',2020,'Central America'),(3,'Benef3',false,'Initiative3'...
SELECT SUM(Disability) FROM Beneficiaries WHERE Region = 'Central America' AND Year BETWEEN 2019 AND 2021;
What was the average market price of Erbium for the second quarter of each year from 2019 to 2021?
CREATE TABLE ErbiumMarketPrices (quarter VARCHAR(10),year INT,price DECIMAL(5,2)); INSERT INTO ErbiumMarketPrices (quarter,year,price) VALUES ('Q2',2019,85.00),('Q2',2019,87.50),('Q2',2020,90.00),('Q2',2020,92.50),('Q2',2021,95.00),('Q2',2021,97.50);
SELECT AVG(price) FROM ErbiumMarketPrices WHERE year IN (2019, 2020, 2021) AND quarter = 'Q2';
Insert a new record into the 'market_trends' table for a new crude oil price of $80 per barrel
CREATE TABLE market_trends (id INT,price DECIMAL(10,2),date DATE);
INSERT INTO market_trends (id, price, date) VALUES (1, 80, CURDATE());
What are the heritage sites that do not have any associated artists?
CREATE TABLE HeritageSites (SiteID int,SiteName text); INSERT INTO HeritageSites (SiteID,SiteName) VALUES (1,'Eiffel Tower'),(2,'Mont Saint-Michel'),(3,'Alhambra'); CREATE TABLE ArtHeritage (ArtID int,HeritageID int); INSERT INTO ArtHeritage (ArtID,HeritageID) VALUES (1,1),(2,2),(3,3);
SELECT HS.SiteName FROM HeritageSites HS LEFT JOIN ArtHeritage AH ON HS.SiteID = AH.HeritageID WHERE AH.HeritageID IS NULL;
What is the minimum fare for buses in the 'city' schema, excluding fares greater than $3?
CREATE SCHEMA city; CREATE TABLE city.buses (id INT,fare DECIMAL); INSERT INTO city.buses (id,fare) VALUES (1,2.50),(2,1.75),(3,3.00);
SELECT MIN(fare) FROM city.buses WHERE fare < 3;
What is the total cargo weight transported by each vessel type in the last month, and what is the average weight per container for those shipments?
CREATE TABLE vessels (vessel_id INT,vessel_type VARCHAR(50)); CREATE TABLE containers (container_id INT,container_weight INT,vessel_id INT,shipped_date DATE); INSERT INTO vessels VALUES (1,'Container Ship'); INSERT INTO vessels VALUES (2,'Bulk Carrier'); INSERT INTO containers VALUES (1,10,1,'2022-03-01'); INSERT INTO ...
SELECT vessels.vessel_type, SUM(containers.container_weight) as total_weight, AVG(containers.container_weight) as avg_weight_per_container FROM vessels INNER JOIN containers ON vessels.vessel_id = containers.vessel_id WHERE containers.shipped_date > DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY vessels.vessel_type;
What is the average investment amount per round for companies founded by underrepresented minorities?
CREATE TABLE diversity (company_id INT,underrepresented_minority BOOLEAN); INSERT INTO diversity (company_id,underrepresented_minority) VALUES (1,true); INSERT INTO diversity (company_id,underrepresented_minority) VALUES (2,false);
SELECT AVG(raised_amount) as avg_investment_per_round FROM investments JOIN diversity ON investments.company_id = diversity.company_id WHERE diversity.underrepresented_minority = true;
Select the average billable hours for attorneys in the 'criminal' department
CREATE TABLE attorneys (id INT,name VARCHAR(50),department VARCHAR(20),billable_hours DECIMAL(5,2)); INSERT INTO attorneys (id,name,department,billable_hours) VALUES (1,'John Doe','criminal',120.50); INSERT INTO attorneys (id,name,department,billable_hours) VALUES (2,'Jane Smith','criminal',150.75);
SELECT AVG(billable_hours) FROM attorneys WHERE department = 'criminal';
What is the total funding received by 'Youth Arts Initiative' in 2022?
CREATE TABLE FundingSources (funding_source VARCHAR(50),amount INT,year INT); INSERT INTO FundingSources (funding_source,amount,year) VALUES ('Government Grant',50000,2022); INSERT INTO FundingSources (funding_source,amount,year) VALUES ('Private Donor',25000,2022); INSERT INTO FundingSources (funding_source,amount,yea...
SELECT SUM(amount) FROM FundingSources WHERE funding_source = 'Youth Arts Initiative' AND year = 2022;
Insert new records into the satellite image table for the past month with no anomalies.
CREATE TABLE satellite_image (id INT,field_id INT,image_url TEXT,anomaly BOOLEAN,timestamp TIMESTAMP);
INSERT INTO satellite_image (field_id, image_url, anomaly, timestamp) SELECT f.id, 'https://example.com/image.jpg', false, s.timestamp FROM field f CROSS JOIN generate_series(NOW() - INTERVAL '1 month', NOW(), INTERVAL '1 day') s(timestamp);
What is the average production cost of cotton t-shirts in the 'spring 2021' collection?
CREATE TABLE production_costs (item_type VARCHAR(20),collection VARCHAR(20),cost NUMERIC(10,2)); INSERT INTO production_costs (item_type,collection,cost) VALUES ('cotton t-shirt','spring 2021',15.99),('cotton t-shirt','spring 2021',17.49),('cotton t-shirt','spring 2021',16.99);
SELECT AVG(cost) FROM production_costs WHERE item_type = 'cotton t-shirt' AND collection = 'spring 2021';
What is the average temperature recorded for each crop type in the past month, grouped by day?
CREATE TABLE WeatherData (temp FLOAT,time DATETIME,crop VARCHAR(255));
SELECT crop, DATE(time) as day, AVG(temp) FROM WeatherData WHERE time > DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 MONTH) GROUP BY crop, day;
How many hotels in the 'hotel_tech_adoption' table are located in the 'Asia' region?
CREATE TABLE hotel_tech_adoption (hotel_id INT,hotel_region TEXT); INSERT INTO hotel_tech_adoption (hotel_id,hotel_region) VALUES (1,'Asia'),(2,'Europe'),(3,'Asia'),(4,'North America');
SELECT COUNT(*) FROM hotel_tech_adoption WHERE hotel_region = 'Asia';
What is the maximum range of electric vehicles in Seoul and Shanghai?
CREATE TABLE electric_vehicles (id INT,city VARCHAR(50),range FLOAT,timestamp TIMESTAMP);
SELECT city, MAX(range) FROM electric_vehicles WHERE city IN ('Seoul', 'Shanghai') GROUP BY city;
What is the total cost of produce sourced from local farms?
CREATE TABLE produce_suppliers (supplier_id INT,name VARCHAR(50),local BOOLEAN); CREATE TABLE produce_purchases (purchase_id INT,supplier_id INT,cost DECIMAL(10,2)); INSERT INTO produce_suppliers (supplier_id,name,local) VALUES (1,'Farm Fresh',true),(2,'Green Fields',false),(3,'Local Harvest',true); INSERT INTO produce...
SELECT SUM(cost) FROM produce_purchases JOIN produce_suppliers ON produce_purchases.supplier_id = produce_suppliers.supplier_id WHERE produce_suppliers.local = true;
Determine the number of space missions launched per year, ranked by the number in descending order.
CREATE TABLE Space_Missions (Mission VARCHAR(50),Duration INT,Launch_Date DATE); INSERT INTO Space_Missions (Mission,Duration,Launch_Date) VALUES ('Mission1',123,'2021-01-01'),('Mission2',456,'2021-02-01'),('Mission3',789,'2021-03-01');
SELECT DATE_PART('year', Launch_Date) as Year, COUNT(*) as Mission_Count FROM Space_Missions GROUP BY Year ORDER BY Mission_Count DESC;
What was the maximum and minimum number of lanes for each type of highway project in Illinois in 2020?
CREATE TABLE HighwayProjectsIL (State TEXT,Year INTEGER,ProjectType TEXT,NumberOfLanes INTEGER); INSERT INTO HighwayProjectsIL (State,Year,ProjectType,NumberOfLanes) VALUES ('Illinois',2020,'Highway',4),('Illinois',2020,'Highway',6),('Illinois',2020,'Highway',8),('Illinois',2020,'Highway',10);
SELECT ProjectType, MIN(NumberOfLanes) as MinLanes, MAX(NumberOfLanes) as MaxLanes FROM HighwayProjectsIL WHERE State = 'Illinois' AND Year = 2020 GROUP BY ProjectType;
What is the most common therapy approach used in the Middle East for patients with anxiety?
CREATE TABLE middle_east_patients (patient_id INT,therapy VARCHAR(20),condition VARCHAR(20)); INSERT INTO middle_east_patients (patient_id,therapy,condition) VALUES (1,'Psychodynamic Therapy','Anxiety'),(2,'CBT','Anxiety'),(3,'DBT','Anxiety'),(4,'NA','Depression'),(5,'Psychodynamic Therapy','Anxiety');
SELECT therapy, COUNT(*) AS count FROM middle_east_patients WHERE condition = 'Anxiety' GROUP BY therapy ORDER BY count DESC LIMIT 1;
What is the average donation amount per region, ordered by the highest amount?
CREATE TABLE Donations (DonationID INT,DonationRegion TEXT,DonationAmount DECIMAL(10,2)); INSERT INTO Donations (DonationID,DonationRegion,DonationAmount) VALUES (1,'Asia',1000.00),(2,'Africa',1500.00),(3,'Europe',2000.00),(4,'Asia',500.00),(5,'Africa',800.00),(6,'Europe',1200.00);
SELECT AVG(DonationAmount) AS AvgDonation, DonationRegion FROM Donations GROUP BY DonationRegion ORDER BY AvgDonation DESC;
Display the average monthly maintenance cost for each equipment type in the 'EquipmentMaintenance' table
CREATE TABLE EquipmentMaintenance (id INT,type VARCHAR(255),cost FLOAT,date DATE);
SELECT type, AVG(cost) as avg_monthly_cost FROM EquipmentMaintenance WHERE date >= '2021-01-01' AND date <= '2021-12-31' GROUP BY type;
What are the intelligence operations with 'communications' in their name in the 'intel_ops' table?
CREATE TABLE intel_ops (op VARCHAR(255)); INSERT INTO intel_ops (op) VALUES ('communications_surveillance'),('communications_jamming'),('decoy'),('interception'),('analysis');
SELECT op FROM intel_ops WHERE op LIKE '%communications%';
Who are the teachers who have not led any professional development workshops?
CREATE TABLE teachers (teacher_id INT,teacher_name TEXT); INSERT INTO teachers (teacher_id,teacher_name) VALUES (1,'Alice Johnson'),(2,'Bob Smith'); CREATE TABLE workshops (workshop_id INT,year INT,hours_spent INT,teacher_id INT); INSERT INTO workshops (workshop_id,year,hours_spent,teacher_id) VALUES (1,2022,3,2),(2,20...
SELECT teacher_name FROM teachers WHERE teacher_id NOT IN (SELECT teacher_id FROM workshops);
What is the sale amount and contractor name for each equipment type with a high geopolitical risk level?
CREATE TABLE GeopoliticalRiskFactors (id INT PRIMARY KEY,equipment VARCHAR(50),risk_level VARCHAR(50)); INSERT INTO GeopoliticalRiskFactors (id,equipment,risk_level) VALUES (4,'Patriot','High'); INSERT INTO EquipmentSales (id,contractor,equipment,sale_date,sale_amount) VALUES (6,'Lockheed Martin','Javelin','2021-02-01'...
SELECT EquipmentSales.equipment, EquipmentSales.sale_amount, EquipmentSales.contractor FROM EquipmentSales INNER JOIN GeopoliticalRiskFactors ON EquipmentSales.equipment = GeopoliticalRiskFactors.equipment WHERE GeopoliticalRiskFactors.risk_level = 'High';
What's the total revenue for concerts in Q1 2022, grouped by city?
CREATE TABLE Concerts (id INT,city VARCHAR(50),concert_date DATE,revenue DECIMAL(10,2));
SELECT city, SUM(revenue) FROM Concerts WHERE concert_date >= '2022-01-01' AND concert_date < '2022-04-01' GROUP BY city;
What is the total number of research grants awarded to faculty members in the Natural Sciences department?
CREATE TABLE grants (id INT,faculty_id INT,title VARCHAR(100),amount DECIMAL(10,2)); INSERT INTO grants (id,faculty_id,title,amount) VALUES (1,1,'Research Grant 1',50000),(2,2,'Research Grant 2',75000),(3,3,'Research Grant 3',80000); CREATE TABLE faculty (id INT,name VARCHAR(50),department VARCHAR(50)); INSERT INTO fac...
SELECT SUM(g.amount) FROM grants g JOIN faculty f ON g.faculty_id = f.id WHERE f.department = 'Natural Sciences';
What is the average safety rating of vehicles by 'Honda' in the Safety_Testing table?
CREATE TABLE Safety_Testing (Vehicle_ID INT,Manufacturer VARCHAR(30),Model VARCHAR(20),Safety_Rating FLOAT);
SELECT AVG(Safety_Rating) FROM Safety_Testing WHERE Manufacturer = 'Honda';
What is the minimum word count for articles in the 'international' category?
CREATE TABLE news (title VARCHAR(255),author VARCHAR(255),word_count INT,category VARCHAR(255)); INSERT INTO news (title,author,word_count,category) VALUES ('Sample News','James Brown',800,'International');
SELECT MIN(word_count) FROM news WHERE category = 'International';
What is the percentage of mobile customers using 5G in the European region?
CREATE TABLE mobile_customers (customer_id INT,network_type VARCHAR(10)); INSERT INTO mobile_customers (customer_id,network_type) VALUES (1,'5G'),(2,'4G'),(3,'5G');
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM mobile_customers)) FROM mobile_customers WHERE network_type = '5G' AND country IN ('Germany', 'France', 'United Kingdom');
What is the total number of marine species observed in the Arctic region?
CREATE TABLE marine_species (name varchar(255),region varchar(255),observations int); INSERT INTO marine_species (name,region,observations) VALUES ('Polar Bear','Arctic',2500),('Walrus','Arctic',1200),('Arctic Fox','Arctic',800);
SELECT SUM(observations) FROM marine_species WHERE region = 'Arctic';
What is the maximum transaction amount in GBP by day for the month of February 2022?
CREATE TABLE transactions (transaction_id INT,transaction_date DATE,transaction_currency VARCHAR(3),transaction_amount DECIMAL(10,2));
SELECT DATE(transaction_date) as transaction_day, MAX(transaction_amount) as maximum_transaction_amount FROM transactions WHERE transaction_date BETWEEN '2022-02-01' AND '2022-02-28' AND transaction_currency = 'GBP' GROUP BY transaction_day;
What is the total amount of waste produced by the mining sector in the state of Michigan?
CREATE TABLE waste_production (id INT,company TEXT,location TEXT,waste_amount FLOAT); INSERT INTO waste_production (id,company,location,waste_amount) VALUES (1,'Michigan Mining Co','Michigan',1500);
SELECT SUM(waste_amount) FROM waste_production WHERE location = 'Michigan';
Which volunteers have contributed the most hours to the 'Environment' program in 2021?
CREATE TABLE Volunteers (VolunteerID int,VolunteerName varchar(50),ProgramID int,Hours decimal(10,2),VolunteerDate date); CREATE TABLE Programs (ProgramID int,ProgramName varchar(50),ProgramCategory varchar(50));
SELECT VolunteerName, SUM(Hours) as TotalHours FROM Volunteers INNER JOIN Programs ON Volunteers.ProgramID = Programs.ProgramID WHERE ProgramName = 'Environment' AND YEAR(VolunteerDate) = 2021 GROUP BY VolunteerName ORDER BY TotalHours DESC;
Which community outreach events in '2020' had more than 100 volunteers?
CREATE TABLE volunteer_events (id INT,event_name TEXT,year INT,num_volunteers INT); INSERT INTO volunteer_events (id,event_name,year,num_volunteers) VALUES (1,'Youth Mentoring Program',2020,120),(2,'Feeding the Homeless',2020,180),(3,'Climate Action Rally',2020,90);
SELECT event_name FROM volunteer_events WHERE year = 2020 AND num_volunteers > 100;
What is the total number of defense projects in Africa and their average duration?
CREATE TABLE defense_projects(id INT,project_name VARCHAR(50),start_date DATE,end_date DATE,status VARCHAR(20));
SELECT 'Africa' AS continent, AVG(DATEDIFF(end_date, start_date)) AS avg_duration, COUNT(*) AS total_projects FROM defense_projects WHERE country IN (SELECT country FROM countries WHERE region = 'Africa');
Delete all records from the habitat table where the status is not 'Protected'
CREATE TABLE habitat (id INT,area FLOAT,status VARCHAR(20));
DELETE FROM habitat WHERE status != 'Protected';
Get all spacecraft engines that are not decommissioned
CREATE TABLE spacecraft (id INT PRIMARY KEY,name VARCHAR(50),engine VARCHAR(50),status VARCHAR(10));
SELECT engine FROM spacecraft WHERE status <> 'decommissioned';
What was the total funding received by programs targeting 'youth'?
CREATE TABLE Programs (program_id INT,target_group VARCHAR(50),funding_amount DECIMAL(10,2),funding_date DATE); INSERT INTO Programs (program_id,target_group,funding_amount,funding_date) VALUES (1,'youth',5000.00,'2021-01-01'),(2,'seniors',7000.00,'2021-02-01'),(3,'adults',3000.00,'2021-03-01');
SELECT SUM(funding_amount) AS total_funding FROM Programs WHERE target_group = 'youth';
What is the average retail price of organic apples sold in the United States?
CREATE TABLE OrganicFruitsPrices (fruit_name TEXT,country TEXT,price NUMERIC); INSERT INTO OrganicFruitsPrices (fruit_name,country,price) VALUES ('Apples','United States',2.95);
SELECT AVG(price) FROM OrganicFruitsPrices WHERE fruit_name = 'Apples' AND country = 'United States';
What is the minimum number of launches required for a successful Mars mission?
CREATE TABLE mars_missions (id INT,name VARCHAR(50),launch_date DATE,number_of_launches INT,success VARCHAR(50));
SELECT MIN(number_of_launches) FROM mars_missions WHERE success = 'Yes';
What is the total amount donated by new donors in the month of May 2021?
CREATE TABLE DonorHistory (DonorID INT,Amount DECIMAL(10,2),FirstDonation DATE); INSERT INTO DonorHistory (DonorID,Amount,FirstDonation) VALUES (1,500.00,'2021-04-15'),(2,300.00,'2021-03-01'),(3,250.00,'2021-05-05');
SELECT SUM(Amount) FROM DonorHistory INNER JOIN (SELECT DonorID FROM DonorHistory GROUP BY DonorID HAVING MIN(FirstDonation) >= '2021-05-01') AS NewDonors ON DonorHistory.DonorID = NewDonors.DonorID;
How many fish are there in each cage at the Canadian fish farm 'Farm Z'?
CREATE TABLE fish_cages (id INT,farm_id INT,cage_number INT,fish_count INT); INSERT INTO fish_cages (id,farm_id,cage_number,fish_count) VALUES (1,5,1,2000); INSERT INTO fish_cages (id,farm_id,cage_number,fish_count) VALUES (2,5,2,3000); INSERT INTO fish_cages (id,farm_id,cage_number,fish_count) VALUES (3,5,3,4000);
SELECT cage_number, fish_count FROM fish_cages WHERE farm_id = (SELECT id FROM fish_farms WHERE name = 'Farm Z' AND country = 'Canada' LIMIT 1);
What is the maximum response time for emergency calls in the "north" region in the last week?
CREATE TABLE EmergencyCalls (id INT,region VARCHAR(20),response_time INT,date DATE);
SELECT MAX(response_time) FROM EmergencyCalls WHERE region = 'north' AND date >= DATE_SUB(CURDATE(), INTERVAL 1 WEEK);
Find the number of new clients per week for the past 3 months
CREATE TABLE clients (client_id INT PRIMARY KEY,created_date DATE);
SELECT DATE_FORMAT(created_date, '%Y-%u') AS week, COUNT(DISTINCT client_id) FROM clients WHERE created_date >= DATE_SUB(NOW(), INTERVAL 3 MONTH) GROUP BY week;
What is the total number of climate adaptation projects in the 'africa' region?
CREATE TABLE adaptation_projects (region VARCHAR(20),num_projects INT); INSERT INTO adaptation_projects (region,num_projects) VALUES ('americas',10),('europe',7),('africa',5);
SELECT region, SUM(num_projects) FROM adaptation_projects WHERE region = 'africa' GROUP BY region;
List all farmers who cultivate 'Cassava' and their corresponding countries.
CREATE TABLE farmer (id INT PRIMARY KEY,name VARCHAR(50),crop_id INT,country_id INT); CREATE TABLE crop (id INT PRIMARY KEY,name VARCHAR(50)); CREATE TABLE country (id INT PRIMARY KEY,name VARCHAR(50)); INSERT INTO crop (id,name) VALUES (1,'Cassava'); INSERT INTO country (id,name) VALUES (1,'Nigeria'),(2,'Ghana'); INSE...
SELECT f.name, c.name AS country_name FROM farmer f INNER JOIN crop c ON f.crop_id = c.id INNER JOIN country co ON f.country_id = co.id WHERE c.name = 'Cassava';
How many product safety incidents were reported for products sourced from France?
CREATE TABLE safety_records (id INT,product_id INT,sourcing_country TEXT,incidents INT); INSERT INTO safety_records (id,product_id,sourcing_country,incidents) VALUES (1,1,'France',2),(2,2,'Canada',0),(3,3,'Germany',1);
SELECT COUNT(*) FROM safety_records WHERE sourcing_country = 'France';
Calculate the percentage of union workers and non-union workers in the 'agriculture' sector.
CREATE TABLE agriculture_workers (id INT,name TEXT,sector TEXT,union_member BOOLEAN);
SELECT CASE WHEN union_member THEN 'Union' ELSE 'Non-Union' END as worker_type, ROUND(COUNT(*) * 100.0 / (SELECT COUNT(*) FROM agriculture_workers), 2) as percentage FROM agriculture_workers WHERE sector = 'agriculture' GROUP BY union_member;
What is the average project timeline in months for contractors, and how many projects did they complete?
CREATE TABLE contractor_timeline (id INT,contractor_name VARCHAR(50),project_id INT,start_date DATE,end_date DATE); INSERT INTO contractor_timeline (id,contractor_name,project_id,start_date,end_date) VALUES (1,'Smith Construction',1,'2022-01-01','2022-06-01');
SELECT contractor_name, AVG(DATEDIFF(end_date, start_date)/30) as avg_timeline, COUNT(*) as num_projects FROM contractor_timeline GROUP BY contractor_name;
What is the total number of articles published by independent authors in the last year?
CREATE TABLE News (news_id INT,title VARCHAR(255),publication_date DATE,author VARCHAR(255),independent_author BOOLEAN); INSERT INTO News (news_id,title,publication_date,author,independent_author) VALUES (1,'News1','2021-01-01','Author1',TRUE),(2,'News2','2021-02-10','Author2',FALSE),(3,'News3','2021-03-20','Author3',T...
SELECT SUM(independent_author) FROM News WHERE independent_author = TRUE AND publication_date >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR);
What is the maximum funding received by a biotech startup?
CREATE TABLE startups (name TEXT,funding FLOAT); INSERT INTO startups (name,funding) VALUES ('StartupA',5000000),('StartupB',7000000),('StartupC',6000000);
SELECT MAX(funding) FROM startups;
What is the average trip duration for each continent?
CREATE TABLE if not exists continent (id INT,continent VARCHAR(20)); INSERT INTO continent (id,continent) VALUES (1,'Africa'),(2,'Asia'),(3,'Europe'),(4,'North America'),(5,'South America'),(6,'Oceania'); CREATE TABLE if not exists trips (id INT,trip_id INT,continent_id INT,duration INT);
SELECT c.continent, AVG(t.duration) FROM trips t JOIN continent c ON t.continent_id = c.id GROUP BY c.continent;
What was the total military innovation funding in 2015?
CREATE TABLE MilitaryInnovation (Year INT,Funding FLOAT); INSERT INTO MilitaryInnovation (Year,Funding) VALUES (2015,12000000);
SELECT Funding FROM MilitaryInnovation WHERE Year = 2015;
Show the average popularity score for each region in 'trends_by_region' table
CREATE TABLE trends_by_region (id INT PRIMARY KEY,region VARCHAR(255),trend_name VARCHAR(255),popularity_score INT);
SELECT region, AVG(popularity_score) FROM trends_by_region GROUP BY region;