instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
List the unique industries for startups founded by Latinx individuals that have received Series A funding or higher.
CREATE TABLE startup (id INT,industry TEXT,founder_demographics TEXT); INSERT INTO startup (id,industry,founder_demographics) VALUES (1,'Software','Latinx Female'),(2,'Hardware','Asian Male'),(3,'Healthcare','Latinx Non-binary'),(4,'AI','Black Female');
SELECT DISTINCT industry FROM startup WHERE founder_demographics LIKE '%Latinx%' AND industry IN ('Series A', 'Series B', 'Series C', 'Series D', 'Series E');
What is the average number of assists per basketball player in the 'assists' table?
CREATE TABLE assists (assist_id INT,player_id INT,match_id INT,team_id INT,assists INT); INSERT INTO assists (assist_id,player_id,match_id,team_id,assists) VALUES (1,12,13,107,6);
SELECT AVG(assists) FROM assists;
Delete all records from the 'invoices' table where invoice_date is older than 6 months
CREATE TABLE invoices (invoice_id INT,invoice_date DATE);
DELETE FROM invoices WHERE invoice_date < (CURRENT_DATE - INTERVAL '6 months');
Identify dishes that contribute to the least revenue
CREATE TABLE sales (sale_id INT,dish_id INT,sale_price DECIMAL(5,2),country VARCHAR(255)); INSERT INTO sales (sale_id,dish_id,sale_price,country) VALUES (1,1,9.99,'USA'),(2,3,7.99,'Mexico'),(3,2,12.99,'USA'); CREATE TABLE dishes (dish_id INT,dish_name VARCHAR(255),cuisine VARCHAR(255)); INSERT INTO dishes (dish_id,dish...
SELECT d.dish_id, d.dish_name, SUM(s.sale_price) as revenue FROM dishes d LEFT JOIN sales s ON d.dish_id = s.dish_id GROUP BY d.dish_id, d.dish_name ORDER BY revenue ASC LIMIT 1;
Which mental health conditions were treated most frequently in Germany during 2020?
CREATE TABLE patients (id INT,country VARCHAR(255)); CREATE TABLE treatments (id INT,patient_id INT,treatment_date DATE); CREATE TABLE conditions (id INT,patient_id INT,condition VARCHAR(255)); INSERT INTO patients (id,country) VALUES (1,'Germany'),(2,'Germany'),(3,'Germany'),(4,'Germany'); INSERT INTO treatments (id,p...
SELECT conditions.condition, COUNT(conditions.condition) AS count FROM conditions JOIN patients ON conditions.patient_id = patients.id JOIN treatments ON patients.id = treatments.patient_id WHERE patients.country = 'Germany' AND treatments.treatment_date >= '2020-01-01' AND treatments.treatment_date < '2021-01-01' GROU...
What is the total number of AI models developed in South America with an explainability score above 85?
CREATE TABLE sa_models (model_name TEXT,region TEXT,explainability_score INTEGER); INSERT INTO sa_models (model_name,region,explainability_score) VALUES ('Model1','South America',90),('Model2','South America',80),('Model3','South America',88);
SELECT SUM(incident_count) FROM sa_models WHERE region = 'South America' AND explainability_score > 85;
What is the average CO2 emission of rental cars in each country, ranked by the highest emission?
CREATE TABLE rental_cars (id INT,country VARCHAR(255),co2_emission INT); INSERT INTO rental_cars (id,country,co2_emission) VALUES (1,'USA',150),(2,'USA',180),(3,'Germany',120),(4,'Germany',130),(5,'Brazil',200),(6,'Brazil',220),(7,'India',100),(8,'India',110);
SELECT country, AVG(co2_emission) AS avg_co2_emission, RANK() OVER (ORDER BY AVG(co2_emission) DESC) AS rank FROM rental_cars GROUP BY country ORDER BY rank;
List all trainers who have conducted diversity and inclusion training in the USA or Canada.
CREATE TABLE Training_Programs (Program_Name VARCHAR(50),Trainer VARCHAR(20),Location VARCHAR(20),Start_Date DATE,End_Date DATE); CREATE TABLE Trainers (Trainer_ID INT,Trainer VARCHAR(20),Specialization VARCHAR(20));
SELECT Trainer FROM Training_Programs WHERE Program_Name LIKE '%diversity%' AND (Location = 'USA' OR Location = 'Canada') INTERSECT SELECT Trainer FROM Trainers;
Find the total number of digital museum interactions in New York and Chicago in Q2 of 2020.
CREATE TABLE Digital_Interactions (id INT,location VARCHAR(50),quarter INT,year INT,interaction_count INT);
SELECT SUM(interaction_count) FROM Digital_Interactions WHERE location IN ('New York', 'Chicago') AND quarter = 2 AND year = 2020;
What is the total transaction fee for all gold transactions?
CREATE TABLE transactions (transaction_id INT,transaction_type VARCHAR(20),transaction_fee DECIMAL(10,2)); INSERT INTO transactions (transaction_id,transaction_type,transaction_fee) VALUES (1,'Gold',50.00),(2,'Silver',25.00);
SELECT SUM(transaction_fee) FROM transactions WHERE transaction_type = 'Gold';
Delete all records from the network_investments table where the investment_date is older than 3 years
CREATE TABLE network_investments (investment_id INT,investment_type VARCHAR(50),investment_date DATE,investment_amount DECIMAL(10,2));
DELETE FROM network_investments WHERE investment_date < (CURRENT_DATE - INTERVAL '3' YEAR);
Show the total number of esports events for 'Counter-Strike: Global Offensive' and 'StarCraft II'
CREATE TABLE EsportsEvents (PlayerID INT,Game VARCHAR(20),Event VARCHAR(20)); INSERT INTO EsportsEvents (PlayerID,Game,Event) VALUES (1,'Counter-Strike: Global Offensive','ESL One Cologne'),(2,'StarCraft II','WCS Global Finals'),(3,'Fortnite','World Cup');
SELECT COUNT(DISTINCT Event) FROM EsportsEvents WHERE Game IN ('Counter-Strike: Global Offensive', 'StarCraft II')
Which recycling rates are higher, for municipal solid waste or for industrial waste, in the European Union?
CREATE TABLE RecyclingRates (WasteType VARCHAR(50),Region VARCHAR(50),RecyclingRate DECIMAL(5,2)); INSERT INTO RecyclingRates (WasteType,Region,RecyclingRate) VALUES ('Municipal Solid Waste','European Union',0.35),('Industrial Waste','European Union',0.70),('Municipal Solid Waste','United States',0.30),('Industrial Was...
SELECT WasteType, RecyclingRate FROM RecyclingRates WHERE Region = 'European Union' AND WasteType IN ('Municipal Solid Waste', 'Industrial Waste') ORDER BY RecyclingRate DESC LIMIT 1;
List space missions with duration more than the average, along with their mission names and launch dates.
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 Mission, Duration, Launch_Date FROM Space_Missions WHERE Duration > (SELECT AVG(Duration) FROM Space_Missions);
Increase the transaction amount for the client with the highest transaction by 10%.
CREATE TABLE clients (client_id INT,name TEXT,region TEXT,transaction_amount DECIMAL); INSERT INTO clients (client_id,name,region,transaction_amount) VALUES (1,'John Doe','Asia',500.00); INSERT INTO clients (client_id,name,region,transaction_amount) VALUES (2,'Jane Smith','Europe',600.00); INSERT INTO clients (client_i...
UPDATE clients SET transaction_amount = transaction_amount * 1.10 WHERE client_id = (SELECT client_id FROM clients WHERE transaction_amount = (SELECT MAX(transaction_amount) FROM clients));
List the unique malware types and their affected software for the healthcare sector, sorted by malware type.
CREATE TABLE malware (type VARCHAR(50),affected_software TEXT); INSERT INTO malware (type,affected_software) VALUES ('Ransomware','Windows 7,Windows 10');
SELECT DISTINCT type, affected_software FROM malware WHERE type IN (SELECT type FROM malware_sectors WHERE sector = 'Healthcare') ORDER BY type;
What is the average temperature in the Atlantic and Indian oceans?
CREATE TABLE temperature (temp_id INT,location TEXT,temperature FLOAT); INSERT INTO temperature (temp_id,location,temperature) VALUES (1,'Atlantic',20.5),(2,'Indian',25.7);
SELECT AVG(temperature) FROM temperature WHERE location IN ('Atlantic', 'Indian')
What are the top 5 most common types of malicious activity in the last week?
CREATE TABLE malicious_activity (id INT,type VARCHAR(50),timestamp DATETIME);
SELECT type, COUNT(*) as num_occurrences FROM malicious_activity WHERE timestamp > DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK) GROUP BY type ORDER BY num_occurrences DESC LIMIT 5;
Insert a new record into the 'Expenses' table for 'Travel Expenses'
CREATE TABLE Expenses (expense_id INT,category VARCHAR(50),amount DECIMAL(10,2)); INSERT INTO Expenses (expense_id,category,amount) VALUES (1,'Office Supplies',100.00);
INSERT INTO Expenses (expense_id, category, amount) VALUES (2, 'Travel Expenses', 0);
find the number of vegan skincare products that were sold between 2019 and 2020
CREATE TABLE VeganSkincareSales (sale_id INT,product_name TEXT,is_vegan BOOLEAN,sale_amount FLOAT,sale_date DATE); INSERT INTO VeganSkincareSales (sale_id,product_name,is_vegan,sale_amount,sale_date) VALUES (1,'Vegan Cleanser',TRUE,60.00,'2019-12-25'); INSERT INTO VeganSkincareSales (sale_id,product_name,is_vegan,sale_...
SELECT COUNT(*) FROM VeganSkincareSales WHERE is_vegan = TRUE AND YEAR(sale_date) BETWEEN 2019 AND 2020;
What is the minimum revenue per day for hotels in the UAE that have adopted cloud-based PMS?
CREATE TABLE hotel_revenue_data_2 (hotel_id INT,country TEXT,pms_type TEXT,daily_revenue FLOAT); INSERT INTO hotel_revenue_data_2 (hotel_id,country,pms_type,daily_revenue) VALUES (1,'UAE','cloud-based',5000),(2,'UAE','cloud-based',6000),(3,'UAE','legacy',4000),(4,'Qatar','cloud-based',7000);
SELECT MIN(daily_revenue) FROM hotel_revenue_data_2 WHERE country = 'UAE' AND pms_type = 'cloud-based';
What is the minimum number of hospital beds per 1000 people in low-income countries?
CREATE TABLE hospital_beds (country VARCHAR(20),beds_per_1000 INT); INSERT INTO hospital_beds (country,beds_per_1000) VALUES ('High-Income',50); INSERT INTO hospital_beds (country,beds_per_1000) VALUES ('Low-Income',10);
SELECT MIN(beds_per_1000) FROM hospital_beds WHERE country = 'Low-Income';
What is the percentage of female, male, and non-binary employees in the Sales department?
CREATE TABLE EmployeeDemographics (EmployeeID int,Gender varchar(10),Department varchar(20)); INSERT INTO EmployeeDemographics (EmployeeID,Gender,Department) VALUES (1,'Female','Engineering'),(2,'Male','IT'),(3,'Non-binary','Engineering'),(4,'Female','Sales'),(5,'Male','Sales'),(6,'Female','Sales');
SELECT Department, ROUND(COUNT(CASE WHEN Gender = 'Female' THEN 1 END) * 100.0 / COUNT(*), 1) AS FemalePercentage, ROUND(COUNT(CASE WHEN Gender = 'Male' THEN 1 END) * 100.0 / COUNT(*), 1) AS MalePercentage, ROUND(COUNT(CASE WHEN Gender = 'Non-binary' THEN 1 END) * 100.0 / COUNT(*), 1) AS NonBinaryPercentage FROM Employ...
What is the total number of containers that were transported by cargo ships from Asian countries to the Port of Singapore?
CREATE TABLE containers (container_id INT,container_size INT,ship_id INT); INSERT INTO containers (container_id,container_size,ship_id) VALUES (1,10,1),(2,15,1),(3,12,2); CREATE TABLE ships (ship_id INT,ship_name VARCHAR(100),country VARCHAR(100)); INSERT INTO ships (ship_id,ship_name,country) VALUES (1,'Asian Ship 1',...
SELECT COUNT(*) FROM containers JOIN ships ON containers.ship_id = ships.ship_id WHERE ships.country = 'Asia' AND ports.port_name = 'Port of Singapore';
List all mobile subscribers with their monthly usage and network investment in the 'Africa' region.
CREATE TABLE network_investments (id INT,country VARCHAR(50),region VARCHAR(20),investment FLOAT); INSERT INTO network_investments (id,country,region,investment) VALUES (1,'South Africa','Africa',2000000);
SELECT mobile_subscribers.name, customer_usage.usage, network_investments.investment FROM mobile_subscribers INNER JOIN customer_usage ON mobile_subscribers.id = customer_usage.subscriber_id INNER JOIN network_investments ON mobile_subscribers.country = network_investments.country WHERE network_investments.region = 'Af...
What is the total revenue generated from organic menu items in the Midwest region?
CREATE TABLE menu (menu_id INT,menu_name TEXT,menu_type TEXT,price DECIMAL,daily_sales INT,is_organic BOOLEAN,region TEXT); CREATE VIEW organic_menu AS SELECT * FROM menu WHERE is_organic = TRUE;
SELECT SUM(price * daily_sales) AS total_revenue FROM organic_menu WHERE region = 'Midwest';
Delete all records of bridges with a 'resilience_score' less than 80 in the 'West Coast' region.
CREATE TABLE bridges (id INT,name TEXT,region TEXT,resilience_score FLOAT); INSERT INTO bridges (id,name,region,resilience_score) VALUES (1,'Golden Gate Bridge','West Coast',85.2),(2,'Brooklyn Bridge','East Coast',76.3),(3,'Bay Bridge','West Coast',78.1);
DELETE FROM bridges WHERE region = 'West Coast' AND resilience_score < 80;
How many sizes does our fashion retailer offer in total?
CREATE TABLE sizes (id INT,product_id INT,size VARCHAR(10)); INSERT INTO sizes (id,product_id,size) VALUES (1,1001,'XS'),(2,1001,'S'),(3,1001,'M');
SELECT COUNT(DISTINCT size) FROM sizes;
Update the 'state' column in the 'cities' table for the city 'San Francisco' to 'CA'
CREATE TABLE cities (id INT,name VARCHAR(50),state VARCHAR(2),population INT);
UPDATE cities SET state = 'CA' WHERE name = 'San Francisco';
Insert a new song into the 'songs' table
CREATE TABLE songs (id INT PRIMARY KEY,title VARCHAR(255),artist VARCHAR(255),genre VARCHAR(255),added_date DATE);
INSERT INTO songs (id, title, artist, genre, added_date) VALUES (1, 'La Gorce', 'Jacques Greene', 'Electronic', '2022-05-15');
What is the minimum conservation status score for all marine species affected by ocean acidification?
CREATE TABLE marine_species (species_name TEXT,affected_by_ocean_acidification BOOLEAN,conservation_status_score FLOAT);
SELECT MIN(conservation_status_score) FROM marine_species WHERE affected_by_ocean_acidification = TRUE;
What is the total number of heritage sites for each country in Asia?
CREATE TABLE heritagesites (name VARCHAR(255),country VARCHAR(255),region VARCHAR(255)); INSERT INTO heritagesites (name,country,region) VALUES ('Taj Mahal','India','Asia'); INSERT INTO heritagesites (name,country,region) VALUES ('Angkor Wat','Cambodia','Asia');
SELECT country, COUNT(DISTINCT name) as num_sites FROM heritagesites WHERE region = 'Asia' GROUP BY country;
How many coastal countries have ratified the United Nations Convention on the Law of the Sea?
CREATE TABLE unclos_ratification (id INT,country TEXT,ratified BOOLEAN); INSERT INTO unclos_ratification (id,country,ratified) VALUES (1,'United States',FALSE),(2,'Russia',TRUE);
SELECT COUNT(*) FROM unclos_ratification WHERE ratified = TRUE;
List all unique case types
CREATE TABLE cases (id INT,case_number VARCHAR(20),case_type VARCHAR(10)); INSERT INTO cases (id,case_number,case_type) VALUES (1,'12345','civil'); INSERT INTO cases (id,case_number,case_type) VALUES (2,'54321','criminal'); INSERT INTO cases (id,case_number,case_type) VALUES (3,'98765','civil');
SELECT DISTINCT case_type FROM cases;
What are the total sales and average potency for each strain produced by cultivators in Oregon in 2021?
CREATE TABLE cultivators (id INT,name TEXT,state TEXT); INSERT INTO cultivators (id,name,state) VALUES (1,'Cultivator X','Oregon'); INSERT INTO cultivators (id,name,state) VALUES (2,'Cultivator Y','Oregon'); CREATE TABLE strains (cultivator_id INT,name TEXT,year INT,potency INT,sales INT); INSERT INTO strains (cultivat...
SELECT s.name as strain_name, c.state as cultivator_state, SUM(s.sales) as total_sales, AVG(s.potency) as average_potency FROM strains s INNER JOIN cultivators c ON s.cultivator_id = c.id WHERE c.state = 'Oregon' AND s.year = 2021 GROUP BY s.name, c.state;
What is the total water consumption by each water treatment plant in the state of New York in the month of February in the year 2021?
CREATE TABLE water_treatment_plant (plant_id INT,state VARCHAR(50),year INT,month INT,water_consumption FLOAT); INSERT INTO water_treatment_plant (plant_id,state,year,month,water_consumption) VALUES (10,'New York',2021,2,12345.6),(11,'New York',2021,2,23456.7),(12,'New York',2021,2,34567.8);
SELECT plant_id, SUM(water_consumption) as total_water_consumption FROM water_treatment_plant WHERE state = 'New York' AND year = 2021 AND month = 2 GROUP BY plant_id;
What is the average rating of sustainable hotels in each city in the United States?
CREATE TABLE hotels (id INT,name TEXT,city TEXT,country TEXT,sustainable BOOLEAN,rating FLOAT); INSERT INTO hotels (id,name,city,country,sustainable,rating) VALUES (1,'Eco Hotel New York','New York','USA',true,4.2),(2,'Green Hotel Los Angeles','Los Angeles','USA',true,4.5);
SELECT city, AVG(rating) FROM hotels WHERE country = 'USA' AND sustainable = true GROUP BY city;
How many tourists visited each European country's top tourist attraction in 2020?
CREATE TABLE top_tourist_attractions (country VARCHAR(30),attraction VARCHAR(50),visitors INT,year INT); INSERT INTO top_tourist_attractions (country,attraction,visitors,year) VALUES ('France','Eiffel Tower',7000000,2020),('Spain','Sagrada Familia',4500000,2020),('Italy','Colosseum',5000000,2020);
SELECT country, SUM(visitors) as total_visitors FROM top_tourist_attractions WHERE year = 2020 GROUP BY country;
What is the percentage of accidents for each aircraft model in a specific year?
CREATE SCHEMA if not exists aerospace;CREATE TABLE if not exists aerospace.aircraft (id INT PRIMARY KEY,manufacturer VARCHAR(50),model VARCHAR(50),accidents INT,launch_year INT); INSERT INTO aerospace.aircraft (id,manufacturer,model,accidents,launch_year) VALUES (1,'Boeing','737',3,2000),(2,'Boeing','747',2,2001),(3,'A...
SELECT model, launch_year, (SUM(accidents) OVER (PARTITION BY launch_year) * 100.0 / (SELECT SUM(accidents) FROM aerospace.aircraft WHERE launch_year = 2010)) as accident_percentage FROM aerospace.aircraft WHERE launch_year = 2010;
Insert a new record for a food safety inspection
CREATE TABLE inspections (inspection_id INT,restaurant_id INT,inspection_date DATE,violation_count INT);
INSERT INTO inspections (inspection_id, restaurant_id, inspection_date, violation_count) VALUES (123, 456, '2022-03-01', 3);
How many distinct suppliers provided Terbium to Japan?
CREATE TABLE Terbium_Supply (id INT,year INT,supplier_id INT,supply_volume INT); CREATE VIEW distinct_suppliers AS SELECT DISTINCT supplier_id FROM Terbium_Supply WHERE country = 'Japan';
SELECT COUNT(*) FROM distinct_suppliers;
What is the combined population of animals that are present in both the 'animal_population' table and the 'habitat_preservation' view?
CREATE VIEW habitat_preservation AS SELECT 'lion' AS animal_name,250 AS acres_preserved; CREATE TABLE animal_population (id INT,animal_name VARCHAR(50),population INT); INSERT INTO animal_population (id,animal_name,population) VALUES (1,'tiger',200),(2,'elephant',300),(3,'giraffe',150);
SELECT animal_name, SUM(population) FROM animal_population WHERE animal_name IN (SELECT animal_name FROM habitat_preservation) GROUP BY animal_name;
What is the average CO2 concentration in the atmosphere in Svalbard in 2021?
CREATE TABLE CO2Concentration (location VARCHAR(50),year INT,avg_conc FLOAT); INSERT INTO CO2Concentration (location,year,avg_conc) VALUES ('Svalbard',2021,417.2);
SELECT avg_conc FROM CO2Concentration WHERE location = 'Svalbard' AND year = 2021;
List all suppliers from the United States that provide materials to companies with ethical manufacturing practices.
CREATE TABLE suppliers (id INT,name TEXT,country TEXT,ethical_practices BOOLEAN); INSERT INTO suppliers (id,name,country,ethical_practices) VALUES (1,'XYZ Supplies','USA',TRUE),(2,'LMN Supplies','Canada',FALSE),(3,'OPQ Supplies','USA',TRUE); CREATE TABLE purchases (id INT,supplier_id INT,company_id INT,ethical_manufact...
SELECT s.name FROM suppliers s JOIN purchases p ON s.id = p.supplier_id WHERE s.country = 'USA' AND p.ethical_manufacturing = TRUE;
What is the maximum safety score for each AI model, grouped by model type?
CREATE TABLE model_safety_scores (score_id INT PRIMARY KEY,model_id INT,score_date DATE,model_type VARCHAR(50),safety_score FLOAT); INSERT INTO model_safety_scores (score_id,model_id,score_date,model_type,safety_score) VALUES (1,1,'2021-01-01','Deep Learning',0.95),(2,2,'2021-02-01','Tree Based',0.92),(3,1,'2021-03-01'...
SELECT model_type, MAX(safety_score) FROM model_safety_scores GROUP BY model_type;
Insert records for new fish species that have been added to the aquarium in the past week.
CREATE TABLE new_fish (id INT,species VARCHAR(255),water_temp FLOAT,date DATE); CREATE TABLE new_species (id INT,species VARCHAR(255),added_date DATE);
INSERT INTO fish (id, species, water_temp, date) SELECT new_species.id, new_species.species, NULL, new_species.added_date FROM new_species WHERE new_species.added_date >= DATE_TRUNC('week', CURRENT_DATE) - INTERVAL '1 week';
What is the average budget, in dollars, of economic diversification efforts in South Africa that were completed in 2017?
CREATE TABLE economic_diversification_efforts (id INT,name TEXT,completion_date DATE,budget FLOAT,country TEXT); INSERT INTO economic_diversification_efforts (id,name,completion_date,budget,country) VALUES (1,'Project W','2017-06-30',35000.0,'South Africa'); INSERT INTO economic_diversification_efforts (id,name,complet...
SELECT AVG(budget) FROM economic_diversification_efforts WHERE YEAR(completion_date) = 2017 AND country = 'South Africa';
What is the average monthly data usage for customers in the 18-25 age group with a mobile subscription?
CREATE TABLE customers(id INT,name VARCHAR(50),age INT,has_mobile_subscription BOOLEAN,data_usage FLOAT);
SELECT AVG(data_usage) FROM customers WHERE age BETWEEN 18 AND 25 AND has_mobile_subscription = TRUE;
Which genetic research projects have received funding from investors based in Germany?
CREATE TABLE investments (id INT,project_id INT,investor_id INT,investor_location VARCHAR(255)); INSERT INTO investments (id,project_id,investor_id,investor_location) VALUES (1,101,301,'Germany'); INSERT INTO investments (id,project_id,investor_id,investor_location) VALUES (2,102,302,'France');
SELECT project_id FROM investments WHERE investor_location = 'Germany';
What is the total number of community health workers by region?
CREATE TABLE region (region_id INT,region_name VARCHAR(50)); INSERT INTO region (region_id,region_name) VALUES (1,'Northeast'),(2,'Southeast'),(3,'Midwest'),(4,'Southwest'),(5,'West'); CREATE TABLE community_health_workers (worker_id INT,worker_name VARCHAR(50),region_id INT); INSERT INTO community_health_workers (work...
SELECT r.region_name, COUNT(chw.worker_id) as total_workers FROM community_health_workers chw JOIN region r ON chw.region_id = r.region_id GROUP BY r.region_name;
What is the maximum safety score for models from France?
CREATE TABLE models_france (model_id INT,name VARCHAR(255),country VARCHAR(255),safety_score FLOAT); INSERT INTO models_france (model_id,name,country,safety_score) VALUES (1,'Model1','France',0.85),(2,'Model2','France',0.92),(3,'Model3','France',0.78),(4,'Model4','France',0.88),(5,'Model5','France',0.90);
SELECT MAX(safety_score) FROM models_france WHERE country = 'France';
Find the forests with the tallest trees, but exclude forests with an area smaller than 200,000 hectares?
CREATE TABLE forests (id INT,name VARCHAR(255),hectares FLOAT,country VARCHAR(255)); INSERT INTO forests (id,name,hectares,country) VALUES (1,'Amazon Rainforest',5500000.0,'Brazil'),(2,'Daintree Rainforest',120000.0,'Australia'),(3,'Yellowstone',894000.0,'USA'),(4,'Banff National Park',664000.0,'Canada'); CREATE TABLE ...
SELECT forests.name FROM forests INNER JOIN tallest_trees ON forests.id = tallest_trees.forest_id WHERE forests.hectares > 200000;
List the number of unique donors and total amount donated for each disaster response.
CREATE TABLE donors (id INT,disaster_id INT,amount FLOAT); CREATE TABLE disasters (id INT,name VARCHAR(255));
SELECT d.name, COUNT(DISTINCT donors.id) as donor_count, SUM(donors.amount) as total_donated FROM disasters d LEFT JOIN donors ON d.id = donors.disaster_id GROUP BY d.id;
Insert a new record into the "labor_productivity" table with the following data: 'Diamond Depot', 'East Coast', 93
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 ('Diamond Depot', 'East Coast', 93);
Get the average water footprint for each type of plant-based milk in our database.
CREATE TABLE PlantBasedMilks (id INT,type VARCHAR(50),water_footprint INT); INSERT INTO PlantBasedMilks (id,type,water_footprint) VALUES (1,'Almond Milk',150),(2,'Soy Milk',250),(3,'Oat Milk',130),(4,'Rice Milk',240);
SELECT type, AVG(water_footprint) FROM PlantBasedMilks GROUP BY type;
What is the minimum number of charging stations required for electric vehicles in India?
CREATE TABLE charging_stations (id INT,country VARCHAR(255),charging_standard VARCHAR(255),quantity INT); INSERT INTO charging_stations (id,country,charging_standard,quantity) VALUES (1,'India','CCS',500),(2,'India','CHAdeMO',300);
SELECT MIN(quantity) FROM charging_stations WHERE country = 'India';
What is the total number of companies founded by LGBTQ+ founders in the renewable energy industry?
CREATE TABLE company (id INT,name TEXT,founding_date DATE,industry TEXT,headquarters TEXT,lgbtq_founder BOOLEAN);
SELECT COUNT(*) FROM company WHERE lgbtq_founder = TRUE AND industry = 'renewable energy';
What is the average energy consumption per month for each hotel?
CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,city TEXT,country TEXT,energy_consumption FLOAT); INSERT INTO hotels (hotel_id,hotel_name,city,country,energy_consumption) VALUES (1,'Hotel A','Rome','Italy',12000.0),(2,'Hotel B','Paris','France',15000.0);
SELECT hotel_name, AVG(energy_consumption) as avg_energy_consumption FROM hotels GROUP BY hotel_name, EXTRACT(MONTH FROM timestamp);
What is the population trend in 'population' table for China?
CREATE TABLE population (country VARCHAR(50),year INT,population INT);
SELECT year, AVG(population) as avg_population FROM population WHERE country = 'China' GROUP BY year;
What is the average weekly overtime hours worked by workers in the 'transportation' sector?
CREATE TABLE if not exists overtime (id INT PRIMARY KEY,worker_id INT,sector VARCHAR(255),overtime_hours INT); INSERT INTO overtime (id,worker_id,sector,overtime_hours) VALUES (1,201,'transportation',5),(2,202,'transportation',10),(3,203,'manufacturing',7);
SELECT AVG(overtime_hours) FROM overtime WHERE sector = 'transportation';
What is the average donation amount for each donor in 2020?
CREATE TABLE donations (donation_id INT,donor_id INT,donation_amount FLOAT,donation_date DATE); INSERT INTO donations (donation_id,donor_id,donation_amount,donation_date) VALUES (1,1,50.00,'2020-01-01'); INSERT INTO donations (donation_id,donor_id,donation_amount,donation_date) VALUES (2,2,100.00,'2020-02-03');
SELECT donor_id, AVG(donation_amount) as avg_donation FROM donations WHERE EXTRACT(YEAR FROM donation_date) = 2020 GROUP BY donor_id;
Display the menu items and their CO2 emissions for items with local ingredients.
CREATE TABLE menu (menu_id INT,menu_item VARCHAR(50),ingredients_sourced_locally BOOLEAN,co2_emissions FLOAT); INSERT INTO menu (menu_id,menu_item,ingredients_sourced_locally,co2_emissions) VALUES (1,'Cheese Pizza',FALSE,2.5),(2,'Margherita Pizza',TRUE,1.8),(3,'Veggie Delight',TRUE,1.9);
SELECT menu_item, co2_emissions FROM menu WHERE ingredients_sourced_locally = TRUE;
What is the total funding awarded to female researchers in the Engineering department?
CREATE TABLE researcher (id INT,name VARCHAR(255),gender VARCHAR(10),department_id INT); CREATE TABLE grant_award (id INT,researcher_id INT,amount DECIMAL(10,2));
SELECT SUM(grant_award.amount) FROM grant_award INNER JOIN researcher ON grant_award.researcher_id = researcher.id WHERE researcher.gender = 'Female' AND researcher.department_id = 1;
How many mental health providers are there in each county in California?
CREATE TABLE counties (id INT,name VARCHAR(255),state VARCHAR(255)); INSERT INTO counties (id,name,state) VALUES (1,'Alameda County','California'); CREATE TABLE mental_health_providers (id INT,name VARCHAR(255),county_id INT); INSERT INTO mental_health_providers (id,name,county_id) VALUES (1,'Provider A',1);
SELECT c.name, COUNT(m.id) FROM counties c JOIN mental_health_providers m ON c.id = m.county_id WHERE c.state = 'California' GROUP BY c.name;
What is the maximum price of products in the 'Fair Trade' category sold by vendors in the European Union?
CREATE TABLE vendor_location (vendor_id INT,vendor_region VARCHAR(50)); INSERT INTO vendor_location (vendor_id,vendor_region) VALUES (1,'European Union'),(2,'United States'),(3,'Canada');
SELECT MAX(price) FROM products JOIN sales ON products.product_id = sales.product_id JOIN vendors ON sales.vendor_id = vendors.vendor_id JOIN vendor_location ON vendors.vendor_id = vendor_location.vendor_id WHERE products.product_category = 'Fair Trade' AND vendor_location.vendor_region = 'European Union';
What is the total number of bike trips per month?
CREATE TABLE BikeTrips (TripID INT,TripDate DATE);
SELECT COUNT(TripID), DATEPART(MONTH, TripDate) AS Month FROM BikeTrips GROUP BY DATEPART(MONTH, TripDate);
Show the food items that are part of indigenous food systems but not urban agriculture programs.
CREATE TABLE food_items (id INT,name VARCHAR(50),category VARCHAR(50)); CREATE TABLE indigenous_food_systems (id INT,food_item_id INT); CREATE TABLE urban_agriculture_programs (id INT,food_item_id INT); INSERT INTO food_items (id,name,category) VALUES (1,'Quinoa','Grains'),(2,'Amaranth','Grains'),(3,'Kale','Vegetables'...
SELECT name FROM food_items f WHERE f.category = 'Grains' AND id NOT IN (SELECT food_item_id FROM urban_agriculture_programs);
Which brand has the most products certified as vegan in Australia?
CREATE TABLE cosmetics.product_certifications (product_id INT,brand VARCHAR(50),is_vegan BOOLEAN,country VARCHAR(50)); INSERT INTO cosmetics.product_certifications (product_id,brand,is_vegan,country) VALUES (1,'Australis',true,'Australia'),(2,'Nude by Nature',false,'Australia'),(3,'modelspretty',true,'Australia'),(4,' ...
SELECT brand, SUM(is_vegan) as total_vegan_products FROM cosmetics.product_certifications WHERE country = 'Australia' GROUP BY brand ORDER BY total_vegan_products DESC LIMIT 1;
What is the minimum budget allocated for transportation services?
CREATE TABLE TransportationBudget (Service VARCHAR(25),Budget INT); INSERT INTO TransportationBudget (Service,Budget) VALUES ('Bus',3000000),('Train',5000000),('Subway',4000000);
SELECT MIN(Budget) FROM TransportationBudget;
What is the lifelong learning progression for a randomly selected student?
CREATE TABLE lifelong_learning (student_id INT,course_id INT,completion_date DATE); INSERT INTO lifelong_learning VALUES (1,1001,'2015-01-01'),(1,1002,'2016-01-01');
SELECT student_id, course_id, LAG(completion_date, 1) OVER (PARTITION BY student_id ORDER BY completion_date) as previous_course_date FROM lifelong_learning WHERE student_id = 1;
List AI safety research papers published before 2018 in descending order by the number of citations.
CREATE SCHEMA AI_Research;CREATE TABLE Safety_Papers (paper_id INT,publication_year INT,citations INT); INSERT INTO AI_Research.Safety_Papers (paper_id,publication_year,citations) VALUES (1,2016,20),(2,2018,30),(3,2017,15);
SELECT paper_id, citations FROM AI_Research.Safety_Papers WHERE publication_year < 2018 ORDER BY citations DESC;
Delete all cargo records from port 'New York' in table cargo_handling
CREATE TABLE cargo_handling (id INT PRIMARY KEY,cargo_id INT,port VARCHAR(20)); INSERT INTO cargo_handling (id,cargo_id,port) VALUES (1,101,'New York');
DELETE FROM cargo_handling WHERE port = 'New York';
What is the total installed solar capacity in Germany and Spain?
CREATE TABLE solar_capacity (country VARCHAR(20),capacity FLOAT); INSERT INTO solar_capacity (country,capacity) VALUES ('Germany',53.2),('Germany',54.1),('Spain',42.6),('Spain',43.7);
SELECT SUM(capacity) as total_capacity, country FROM solar_capacity GROUP BY country;
Update the attendance for event_id 5001
CREATE TABLE events (event_id INT PRIMARY KEY,event_name VARCHAR(100),event_location VARCHAR(100),start_time DATETIME,end_time DATETIME,attendance INT);
UPDATE events SET attendance = 350 WHERE event_id = 5001;
What is the average size of co-owned properties in Seattle?
CREATE TABLE co_ownership (property_id INT,size FLOAT,city VARCHAR(20)); INSERT INTO co_ownership (property_id,size,city) VALUES (1,1200.0,'Seattle'),(2,1500.0,'NYC');
SELECT AVG(size) FROM co_ownership WHERE city = 'Seattle';
What are the unique hobbies of users who have clicked on ads about outdoor activities but have not followed any outdoor-related accounts?
CREATE TABLE user_actions (user_id INT,action_type VARCHAR(50),hobby VARCHAR(50)); INSERT INTO user_actions (user_id,action_type,hobby) VALUES (1,'clicked_ad','hiking'),(2,'followed_account','photography'),(3,'clicked_ad','camping'),(4,'followed_account','yoga'),(5,'clicked_ad','running'),(6,'followed_account','gaming'...
SELECT hobby FROM user_actions WHERE action_type = 'clicked_ad' AND user_id NOT IN (SELECT user_id FROM user_actions WHERE action_type = 'followed_account' AND hobby LIKE '%outdoor%');
How many accidents were reported for each mining operation in the past year?
CREATE TABLE operations (id INT,name TEXT); CREATE TABLE accidents (operation_id INT,year INT,reported BOOLEAN); INSERT INTO operations (id,name) VALUES (1,'Operation A'),(2,'Operation B'),(3,'Operation C'); INSERT INTO accidents (operation_id,year,reported) VALUES (1,2021,TRUE),(1,2021,TRUE),(2,2021,FALSE),(3,2021,TRU...
SELECT operations.name, COUNT(accidents.id) FROM operations LEFT JOIN accidents ON operations.id = accidents.operation_id AND accidents.year = 2021 GROUP BY operations.id;
Find the number of cultural heritage sites in Germany and Italy that have a virtual tour available.
CREATE TABLE CulturalHeritageSites (site_id INT,site_name TEXT,country TEXT,has_virtual_tour BOOLEAN); INSERT INTO CulturalHeritageSites (site_id,site_name,country,has_virtual_tour) VALUES (1,'Site A','Germany',TRUE),(2,'Site B','Italy',FALSE);
SELECT country, COUNT(*) FROM CulturalHeritageSites WHERE country IN ('Germany', 'Italy') AND has_virtual_tour = TRUE GROUP BY country;
Count the number of cerium mines in Canada and the United States.
CREATE TABLE cerium_mines (country TEXT,num_mines INT); INSERT INTO cerium_mines (country,num_mines) VALUES ('Canada',12),('United States',15);
SELECT SUM(num_mines) FROM cerium_mines WHERE country IN ('Canada', 'United States');
Delete all records of airmen who were dismissed for misconduct from the air_force_discharge_data table
CREATE TABLE air_force_discharge_data (airman_id INT,name VARCHAR(50),rank VARCHAR(50),discharge_type VARCHAR(50),discharge_date DATE);
DELETE FROM air_force_discharge_data WHERE rank = 'Airman' AND discharge_type = 'misconduct';
What is the average number of home runs hit in a single game in the J-League, excluding games with less than 3 home runs hit?
CREATE TABLE J_League_Matches (MatchID INT,HomeTeam VARCHAR(50),AwayTeam VARCHAR(50),HomeRuns INT,AwayRuns INT); INSERT INTO J_League_Matches (MatchID,HomeTeam,AwayTeam,HomeRuns,AwayRuns) VALUES (1,'Kashima Antlers','Urawa Red Diamonds',2,1);
SELECT AVG(HomeRuns + AwayRuns) FROM J_League_Matches WHERE (HomeRuns + AwayRuns) >= 3 GROUP BY (HomeRuns + AwayRuns);
How many subway rides were there per day in Sydney in Q1 2022?
CREATE TABLE subway_rides_sydney(ride_date DATE,num_rides INTEGER); INSERT INTO subway_rides_sydney (ride_date,num_rides) VALUES ('2022-01-01',1200),('2022-01-02',1300);
SELECT ride_date, AVG(num_rides) AS avg_daily_rides FROM subway_rides_sydney WHERE ride_date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY ride_date;
What is the average amount donated per donation for each donor?
CREATE TABLE Donors (DonorID INT,Name TEXT); CREATE TABLE Donations (DonationID INT,DonorID INT,DonationAmount DECIMAL);
SELECT D.Name as DonorName, AVG(DonationAmount) as AvgDonationAmount FROM Donors D INNER JOIN Donations Don ON D.DonorID = Don.DonorID GROUP BY D.DonorID, D.Name;
What are the top 5 countries with the highest cybersecurity budget in the last 3 years?
CREATE TABLE if not exists cybersecurity_budget (country VARCHAR(50),year INT,budget FLOAT);
SELECT country, AVG(budget) as avg_budget FROM cybersecurity_budget GROUP BY country ORDER BY avg_budget DESC LIMIT 5;
Delete the record of the reader with the ID of 4 if it exists.
CREATE TABLE readers (id INT,name VARCHAR(50),age INT,preference VARCHAR(50)); INSERT INTO readers (id,name,age,preference) VALUES (1,'John Doe',30,'technology'),(2,'Jane Smith',45,'sports'),(3,'Bob Johnson',28,'politics'),(4,'Alice Davis',34,'international');
DELETE FROM readers WHERE id = 4;
List all crime incidents with a severity level of 3 in the Central area.
CREATE TABLE area (id INT,name VARCHAR(20)); INSERT INTO area (id,name) VALUES (1,'North'),(2,'South'),(3,'East'),(4,'West'),(5,'Central'); CREATE TABLE incidents (id INT,area_id INT,incident_type VARCHAR(50),severity INT); INSERT INTO incidents (id,area_id,incident_type,severity) VALUES (1,5,'Theft',3),(2,3,'Assault',...
SELECT * FROM incidents WHERE area_id = (SELECT id FROM area WHERE name = 'Central') AND severity = 3;
What is the average number of wins for players who play "Virtual Reality Chess Extreme" or "Rhythm Game 2023"?
CREATE TABLE Players (PlayerID INT,PlayerName VARCHAR(50),Game VARCHAR(50),Wins INT); INSERT INTO Players (PlayerID,PlayerName,Game,Wins) VALUES (1,'Sophia Garcia','Virtual Reality Chess Extreme',35),(2,'Daniel Kim','Rhythm Game 2023',40),(3,'Lila Hernandez','Racing Simulator 2022',28),(4,'Kenji Nguyen','Rhythm Game 20...
SELECT AVG(Wins) FROM Players WHERE Game IN ('Virtual Reality Chess Extreme', 'Rhythm Game 2023');
What is the change in monthly energy production for each hydroelectric power plant in the renewables table?
CREATE TABLE renewables (id INT,name VARCHAR(50),type VARCHAR(50),production FLOAT,created_at TIMESTAMP);
SELECT name, LAG(production, 1) OVER(PARTITION BY name ORDER BY created_at) as prev_month_production, production, production - LAG(production, 1) OVER(PARTITION BY name ORDER BY created_at) as monthly_change FROM renewables WHERE type = 'hydro' ORDER BY name, created_at;
Who is the top scorer for each team in a tournament?
CREATE TABLE Player (PlayerID int,PlayerName varchar(50),TeamID int); CREATE TABLE Goal (GoalID int,PlayerID int,Goals int,MatchDate date,TournamentID int); INSERT INTO Player (PlayerID,PlayerName,TeamID) VALUES (1,'James Rodriguez',1),(2,'Radamel Falcao',1),(3,'Thomas Muller',2),(4,'Miroslav Klose',2); INSERT INTO Go...
SELECT p.TeamID, p.PlayerName, SUM(g.Goals) AS TotalGoals, ROW_NUMBER() OVER (PARTITION BY p.TeamID ORDER BY SUM(g.Goals) DESC) AS Ranking FROM Player p JOIN Goal g ON p.PlayerID = g.PlayerID WHERE g.TournamentID = 1 GROUP BY p.TeamID, p.PlayerName HAVING Ranking <= 1;
What is the maximum number of items purchased in a single order for each customer?
CREATE TABLE orders(customer_id INT,items INT); INSERT INTO orders(customer_id,items) VALUES(1,3),(2,1),(3,5),(4,2);
SELECT customer_id, MAX(items) FROM orders GROUP BY customer_id;
List Gaelic football teams with their average ticket sales revenue per game in the Connacht province.
CREATE TABLE gaelic_football_teams (team_id INT,team_name VARCHAR(50),province VARCHAR(50)); INSERT INTO gaelic_football_teams (team_id,team_name,province) VALUES (1,'Galway','Connacht'),(2,'Mayo','Connacht'),(3,'Roscommon','Connacht'); CREATE TABLE gaelic_football_ticket_sales (team_id INT,sale_date DATE,quantity INT,...
SELECT gft.team_name, AVG(gfts.revenue/gfts.quantity) as avg_revenue_per_game FROM gaelic_football_ticket_sales gfts JOIN gaelic_football_teams gft ON gfts.team_id = gft.team_id WHERE gft.province = 'Connacht' GROUP BY gft.team_name;
What are the drug approval dates for PharmaB Inc. in Japan?
CREATE TABLE drug_approval (company VARCHAR(255),country VARCHAR(255),approval_date DATE); INSERT INTO drug_approval (company,country,approval_date) VALUES ('PharmaB Inc.','Japan','2021-03-15');
SELECT company, approval_date FROM drug_approval WHERE company = 'PharmaB Inc.' AND country = 'Japan';
Update the 'rural_development' database's 'economic_diversification' table to include a new 'diversification_type' column with values 'Renewable Energy' and 'Tourism' for 'Europe' records
CREATE TABLE economic_diversification (diversification_id INT PRIMARY KEY,diversification_name VARCHAR(100),country VARCHAR(50),region VARCHAR(50),year_introduced INT);
ALTER TABLE economic_diversification ADD diversification_type VARCHAR(50); UPDATE economic_diversification SET diversification_type = 'Renewable Energy' WHERE country = 'Europe'; UPDATE economic_diversification SET diversification_type = 'Tourism' WHERE country = 'Europe';
How many cases were won by the 'jones' law firm?
CREATE TABLE cases (id INT,law_firm TEXT,won BOOLEAN); INSERT INTO cases (id,law_firm,won) VALUES (1,'jones',TRUE),(2,'jones',FALSE),(3,'jones',TRUE);
SELECT COUNT(*) FROM cases WHERE law_firm = 'jones' AND won = TRUE;
Add new record to recycling_rates table with location 'California', recycling_type 'Plastic', rate 0.20, date '2021-01-01'
CREATE TABLE recycling_rates (id INT PRIMARY KEY,location VARCHAR(255),recycling_type VARCHAR(255),rate DECIMAL(5,4),date DATE);
INSERT INTO recycling_rates (location, recycling_type, rate, date) VALUES ('California', 'Plastic', 0.20, '2021-01-01');
Find the difference in average daily streams between weekdays and weekends for the pop genre.
CREATE TABLE daily_streams (date DATE,genre VARCHAR(10),stream_count BIGINT);
SELECT (AVG(CASE WHEN DAYOFWEEK(date) IN (1,7) THEN stream_count ELSE 0 END) - AVG(CASE WHEN DAYOFWEEK(date) IN (2,3,4,5,6) THEN stream_count ELSE 0 END)) * 1000 AS weekend_vs_weekday_diff FROM daily_streams WHERE genre = 'pop' GROUP BY genre;
Identify evidence-based policy making related to climate change
CREATE TABLE Policy (id INT,name VARCHAR(50),category VARCHAR(50),description TEXT); INSERT INTO Policy (id,name,category,description) VALUES (1,'Renewable Energy Standard','Energy','Standard to increase renewable energy production');
SELECT Policy.name, Policy.category, Policy.description FROM Policy WHERE Policy.description LIKE '%climate change%' OR Policy.category = 'Climate Change';
Identify the explainable AI application with the lowest explainability score in Africa.
CREATE TABLE explainable_ai_applications (app_name TEXT,region TEXT,explainability_score FLOAT); INSERT INTO explainable_ai_applications (app_name,region,explainability_score) VALUES ('App13','Africa',0.7),('App14','Africa',0.6),('App15','Europe',0.8);
SELECT app_name, explainability_score FROM explainable_ai_applications WHERE region = 'Africa' ORDER BY explainability_score LIMIT 1;
Find the minimum energy storage capacity for each energy_type installed in Alberta, Canada between 2020-01-01 and 2020-06-30, excluding energy_types with only one installation record.
CREATE TABLE energy_storage_3 (id INT,energy_type VARCHAR(50),location VARCHAR(50),capacity INT,installation_date DATE); INSERT INTO energy_storage_3 (id,energy_type,location,capacity,installation_date) VALUES (3,'Lithium-ion','Alberta',5000,'2020-03-01');
SELECT energy_type, MIN(capacity) as min_capacity FROM energy_storage_3 WHERE installation_date BETWEEN '2020-01-01' AND '2020-06-30' AND location = 'Alberta' GROUP BY energy_type HAVING COUNT(*) > 1;
Insert new records for visitors from Australia and New Zealand.
CREATE TABLE Visitors (id INT,name VARCHAR(100),country VARCHAR(50),visit_date DATE);
INSERT INTO Visitors (id, name, country, visit_date) VALUES (1, 'Emma Watson', 'Australia', '2021-08-01'), (2, 'Sam Smith', 'New Zealand', '2021-09-01');