instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Identify the top 2 infectious diseases in the European region by case count.
CREATE TABLE europe_infections (region VARCHAR(255),disease VARCHAR(255),cases INT); INSERT INTO europe_infections (region,disease,cases) VALUES ('Europe','Tuberculosis',6000); INSERT INTO europe_infections (region,disease,cases) VALUES ('Europe','Measles',4000); INSERT INTO europe_infections (region,disease,cases) VALUES ('Europe','Meningitis',3000);
SELECT disease, SUM(cases) AS total_cases FROM europe_infections GROUP BY disease ORDER BY total_cases DESC LIMIT 2;
What is the total cargo weight handled by the ACME Shipping Company in the last 30 days?
CREATE TABLE cargo (id INT,vessel_name VARCHAR(255),port_name VARCHAR(255),weight INT,handling_date DATE); INSERT INTO cargo (id,vessel_name,port_name,weight,handling_date) VALUES (1,'Seafarer','Port of Los Angeles',5000,'2022-04-15'),(2,'Oceanus','Port of New York',7000,'2022-04-20'),(3,'Neptune','Port of Singapore',6000,'2022-04-25'),(4,'Seafarer','Port of Los Angeles',5500,'2022-04-17');
SELECT SUM(weight) FROM cargo WHERE handling_date >= DATE_SUB(CURRENT_DATE, INTERVAL 30 DAY) AND vessel_name IN (SELECT name FROM vessels WHERE company = 'ACME Shipping');
What is the average number of streams for all songs by Latin artists?
CREATE TABLE Streaming (SongID INT,Song TEXT,Genre TEXT,Streams INT); INSERT INTO Streaming (SongID,Song,Genre,Streams) VALUES (1,'Despacito','Latin',30000000); INSERT INTO Streaming (SongID,Song,Genre,Streams) VALUES (2,'Havana','Latin',25000000);
SELECT AVG(Streams) FROM Streaming WHERE Genre = 'Latin';
Display the number of visitors to each sustainable tourism event in 2019
CREATE TABLE events (id INT,name VARCHAR(50),is_sustainable BOOLEAN); INSERT INTO events (id,name,is_sustainable) VALUES (1,'Sustainable Event 1',TRUE),(2,'Non-Sustainable Event 1',FALSE),(3,'Sustainable Event 2',TRUE); CREATE TABLE visitors (id INT,event_id INT,year INT); INSERT INTO visitors (id,event_id,year) VALUES (1,1,2019),(2,1,2019),(3,2,2018),(4,3,2019),(5,3,2019),(6,3,2019);
SELECT e.name, COUNT(*) FROM events e INNER JOIN visitors v ON e.id = v.event_id WHERE v.year = 2019 AND e.is_sustainable = TRUE GROUP BY e.name;
What is the minimum CO2 emission reduction (in metric tons) achieved by carbon offset programs in 'NorthAmerica' in '2020'?
CREATE TABLE carbon_offsets (id INT,program_name VARCHAR(50),location VARCHAR(50),year INT,co2_reduction INT); INSERT INTO carbon_offsets (id,program_name,location,year,co2_reduction) VALUES (1,'ProgramA','NorthAmerica',2020,800),(2,'ProgramB','NorthAmerica',2020,1000);
SELECT MIN(co2_reduction) FROM carbon_offsets WHERE location = 'NorthAmerica' AND year = 2020;
What is the maximum number of likes on a post in the "posts_table"?
CREATE TABLE posts_table (post_id INT,likes_count INT); INSERT INTO posts_table (post_id,likes_count) VALUES (1,200),(2,350),(3,120),(4,400),(5,300),(6,500);
SELECT MAX(likes_count) FROM posts_table;
What was the drug approval rate for a specific therapeutic area, 'Neurology', between 2015 and 2020?
CREATE TABLE drug_approval (approval_id INT,therapeutic_area VARCHAR(50),approval_year INT,approval_status VARCHAR(50)); INSERT INTO drug_approval (approval_id,therapeutic_area,approval_year,approval_status) VALUES (1,'Neurology',2015,'Approved'),(2,'Oncology',2016,'Approved'),(3,'Neurology',2017,'Denied'),(4,'Neurology',2018,'Approved'),(5,'Oncology',2019,'Denied'),(6,'Neurology',2020,'Approved');
SELECT COUNT(*) as approval_count FROM drug_approval WHERE therapeutic_area = 'Neurology' AND approval_year BETWEEN 2015 AND 2020 AND approval_status = 'Approved';
What is the total yield of crops by country in 'crop_distribution' table?
CREATE TABLE crop_distribution (country VARCHAR(50),crop VARCHAR(50),yield INT); INSERT INTO crop_distribution (country,crop,yield) VALUES ('Canada','corn',1000),('Canada','wheat',2000),('USA','corn',3000),('USA','wheat',4000),('Mexico','corn',2500),('Mexico','wheat',1500); CREATE TABLE country_total (country VARCHAR(50),total INT); INSERT INTO country_total (country,total) SELECT country,SUM(yield) FROM crop_distribution GROUP BY country;
SELECT ct.country, ct.total FROM country_total ct;
What are the projects in the digital divide domain with the highest funding that have not yet started?
CREATE TABLE digital_divide_future (id INT PRIMARY KEY,project VARCHAR(100),organization VARCHAR(100),funding FLOAT,start_date DATE,end_date DATE);INSERT INTO digital_divide_future (id,project,organization,funding,start_date,end_date) VALUES (1,'Bridging the Digital Divide v3','Connect Global',900000,'2023-01-01','2024-12-31');
SELECT project FROM digital_divide_future WHERE start_date > CURDATE() ORDER BY funding DESC LIMIT 1;
What is the average price for meals sourced from local farmers?
CREATE TABLE Prices (id INT,is_local BOOLEAN,category VARCHAR(20),price INT); INSERT INTO Prices (id,is_local,category,price) VALUES (1,true,'breakfast',10),(2,false,'breakfast',15),(3,true,'lunch',12);
SELECT AVG(price) FROM Prices WHERE is_local = true;
Update the 'troops' value for 'Somalia' in the year 1993 to 750 in the 'peacekeeping_operations' table
CREATE TABLE peacekeeping_operations (id INT PRIMARY KEY,country VARCHAR(50),year INT,troops INT,cost FLOAT);
WITH cte AS (UPDATE peacekeeping_operations SET troops = 750 WHERE country = 'Somalia' AND year = 1993 RETURNING *) INSERT INTO peacekeeping_operations SELECT * FROM cte;
What is the average amount of time it takes for the Department of Homeland Security to process a visa application?
CREATE TABLE visa_applications(application_id INT,application_date DATE,processing_time FLOAT,agency VARCHAR(255)); INSERT INTO visa_applications(application_id,application_date,processing_time,agency) VALUES (1,'2022-01-01',30.0,'Department of Homeland Security');
SELECT AVG(processing_time) FROM visa_applications WHERE agency = 'Department of Homeland Security';
What is the total quantity of wildlife sightings in 2022, separated by species, for indigenous communities in the Arctic?
CREATE TABLE WildlifeSightings (Location VARCHAR(255),Date DATE,Species VARCHAR(255),Community VARCHAR(255),Quantity INT); INSERT INTO WildlifeSightings (Location,Date,Species,Community,Quantity) VALUES ('Tundra National Park','2022-01-01','Polar Bear','Inuit Community',1),('Arctic Circle','2022-01-01','Arctic Fox','Saami Community',2);
SELECT Species, Community, SUM(Quantity) FROM WildlifeSightings WHERE YEAR(Date) = 2022 GROUP BY Species, Community;
Get the number of workplaces with safety issues
CREATE TABLE workplaces (id INT,name TEXT,location TEXT,safety_issues INT);
SELECT COUNT(*) FROM workplaces WHERE safety_issues > 0;
What is the minimum salary in the 'education_union' table?
CREATE TABLE education_union (employee_id INT,department VARCHAR(20),salary DECIMAL(10,2)); INSERT INTO education_union (employee_id,department,salary) VALUES (1,'Education',50000.00),(2,'Education',51000.00),(3,'Education',52000.00);
SELECT MIN(salary) FROM education_union;
What is the name of the latest intelligence operation in the 'intelligence_ops' table?
CREATE TABLE intelligence_ops (operation_id INT,name VARCHAR(50),description TEXT,start_date DATE,end_date DATE,last_updated TIMESTAMP);
SELECT name FROM intelligence_ops WHERE last_updated = (SELECT MAX(last_updated) FROM intelligence_ops);
List the waste generation figures for each area, excluding districts with a population under 100,000.
CREATE TABLE WasteGeneration (id INT,area VARCHAR(10),amount INT); INSERT INTO WasteGeneration (id,area,amount) VALUES (1,'urban',3500),(2,'rural',2000),(3,'DistrictA',1500),(4,'DistrictB',1000); CREATE TABLE Population (id INT,district VARCHAR(20),population INT); INSERT INTO Population (id,district,population) VALUES (1,'DistrictA',120000),(2,'DistrictB',90000);
SELECT WasteGeneration.area, WasteGeneration.amount FROM WasteGeneration LEFT JOIN Population ON WasteGeneration.area = Population.district WHERE Population.population >= 100000 OR Population.district IS NULL;
Which players in the MLB have the same last name as managers?
CREATE TABLE mlb_players (player_id INT,player_name VARCHAR(100),team_id INT); CREATE TABLE mlb_managers (manager_id INT,manager_name VARCHAR(100),team_id INT);
SELECT p.player_name FROM mlb_players p JOIN mlb_managers m ON p.player_name = m.manager_name;
What is the total number of medical supplies delivered to each region?
CREATE TABLE MedicalSupplies (Region VARCHAR(20),SupplyID INT,Quantity INT); INSERT INTO MedicalSupplies (Region,SupplyID,Quantity) VALUES ('North',1,50),('South',2,75),('East',3,100),('West',4,125),('Central',5,150);
SELECT Region, SUM(Quantity) as TotalMedicalSupplies FROM MedicalSupplies GROUP BY Region;
What is the average age of employees in the 'employees' table, for each unique job_title?
CREATE TABLE employees (id INT,first_name VARCHAR(50),last_name VARCHAR(50),job_title VARCHAR(50),department VARCHAR(50),age INT,PRIMARY KEY (id)); INSERT INTO employees (id,first_name,last_name,job_title,department,age) VALUES (1,'John','Doe','Engineer','Mining',35),(2,'Jane','Doe','Operator','Mining',28),(3,'Mike','Johnson','Manager','Environment',45),(4,'Sara','Smith','Technician','Environment',30),(5,'David','Williams','Engineer','Mining',40);
SELECT job_title, AVG(age) FROM employees GROUP BY job_title;
What is the average salary of government employees in Ottawa, and how many of them are there?
CREATE TABLE employees (name VARCHAR(255),city VARCHAR(255),salary DECIMAL(10,2),government BOOLEAN); INSERT INTO employees (name,city,salary,government) VALUES ('Jane Doe','Ottawa',80000.00,TRUE),('John Smith','Ottawa',90000.00,TRUE);
SELECT AVG(salary) FROM employees WHERE city = 'Ottawa' AND government = TRUE; SELECT COUNT(*) FROM employees WHERE city = 'Ottawa' AND government = TRUE;
What is the total revenue generated by the 'Direct' channel in Q1 2022?
CREATE TABLE Bookings (booking_id INT,hotel_id INT,booking_date DATE,revenue FLOAT,channel VARCHAR(50)); INSERT INTO Bookings (booking_id,hotel_id,booking_date,revenue,channel) VALUES (1,1,'2022-01-01',200.0,'Direct'),(2,1,'2022-01-03',150.0,'OTA'),(3,2,'2022-01-05',300.0,'Direct');
SELECT SUM(revenue) FROM Bookings WHERE channel = 'Direct' AND booking_date >= '2022-01-01' AND booking_date < '2022-04-01';
What is the average rating of vegan dishes, excluding dishes with less than 5 ratings?
CREATE TABLE dish_ratings (id INT,dish_name TEXT,rating INT);
SELECT AVG(rating) FROM dish_ratings WHERE dish_name IN (SELECT dish_name FROM dish_ratings GROUP BY dish_name HAVING COUNT(*) >= 5) AND dish_name IN (SELECT dish_name FROM menu_items WHERE is_vegan = TRUE);
Retrieve information about the 'Juno' spacecraft.
CREATE TABLE Spacecrafts (craft_id INT PRIMARY KEY,name VARCHAR(100),type VARCHAR(50),country VARCHAR(50),launch_date DATE); INSERT INTO Spacecrafts (craft_id,name,type,country,launch_date) VALUES (1,'Juno','Spacecraft','USA','2011-08-05');
SELECT * FROM Spacecrafts WHERE name = 'Juno';
Which regions have the least number of digital divide issues?
CREATE TABLE digital_divide (id INT,region VARCHAR(20),issues INT); INSERT INTO digital_divide (id,region,issues) VALUES (1,'Africa',30),(2,'Asia',40),(3,'Europe',10),(4,'Americas',20);
SELECT region FROM digital_divide ORDER BY issues LIMIT 1;
What are the materials and their quantities, ranked by quantity for building 1003?
CREATE TABLE green_building_materials (id INT,building_id INT,material VARCHAR(255),quantity INT); INSERT INTO green_building_materials (id,building_id,material,quantity) VALUES (1,1001,'Recycled Steel',5000); INSERT INTO green_building_materials (id,building_id,material,quantity) VALUES (2,1002,'Bamboo Flooring',3000); INSERT INTO green_building_materials (id,building_id,material,quantity) VALUES (3,1003,'Reclaimed Wood',4000); INSERT INTO green_building_materials (id,building_id,material,quantity) VALUES (4,1003,'Eco-friendly Paint',2000);
SELECT building_id, material, quantity, RANK() OVER(PARTITION BY building_id ORDER BY quantity DESC) as high_quantity_material FROM green_building_materials WHERE building_id = 1003;
What is the average satisfaction rating of public parks in Tokyo, Japan, weighted by the number of user reviews?
CREATE TABLE parks (name varchar(30),city varchar(20),country varchar(20),rating int,reviews int); INSERT INTO parks (name,city,country,rating,reviews) VALUES ('Shinjuku Gyoen','Tokyo','Japan',8,1000),('Yoyogi Park','Tokyo','Japan',7,800);
SELECT AVG(rating * reviews) / SUM(reviews) FROM parks WHERE city = 'Tokyo' AND country = 'Japan';
What was the total duration of all exhibitions in the 'Post-Impressionism' movement?
CREATE TABLE Exhibitions (id INT,title VARCHAR(50),movement VARCHAR(20),exhibition_duration INT);
SELECT SUM(exhibition_duration) FROM Exhibitions WHERE movement = 'Post-Impressionism';
What is the total square footage of properties with sustainable features in the 'housing_data' table?
CREATE TABLE housing_data (id INT,address VARCHAR(255),city VARCHAR(255),state VARCHAR(255),square_footage INT,sustainable_features VARCHAR(255)); INSERT INTO housing_data (id,address,city,state,square_footage,sustainable_features) VALUES (1,'123 Maple St','San Francisco','CA',1200,'solar panels'),(2,'456 Oak St','Austin','TX',1500,'none'),(3,'789 Pine St','Seattle','WA',1800,'green roof');
SELECT SUM(square_footage) FROM housing_data WHERE sustainable_features IS NOT NULL;
How many containers were handled by each stevedoring company in the third quarter of 2019, grouped by company and container type?
CREATE TABLE stevedoring (stevedoring_id INT,company VARCHAR(255),quarter INT,container_type VARCHAR(255),containers_handled INT);INSERT INTO stevedoring (stevedoring_id,company,quarter,container_type,containers_handled) VALUES (1,'ABC',3,'dry',5000),(2,'ABC',3,'refrigerated',3000),(3,'XYZ',3,'dry',4000),(4,'XYZ',3,'refrigerated',6000);
SELECT company, container_type, SUM(containers_handled) FROM stevedoring WHERE quarter = 3 GROUP BY company, container_type;
Delete all records of farmed salmon in Scotland in 2022.
CREATE TABLE Farming(country VARCHAR(255),year INT,species VARCHAR(255),production FLOAT);
DELETE FROM Farming WHERE country = 'Scotland' AND species = 'Salmon' AND year = 2022;
Present the inclusion efforts in the Psychology faculty that are not available in the English faculty.
CREATE TABLE PsychologyInclusion (EffortID INT,Effort VARCHAR(50)); CREATE TABLE EnglishInclusion (EffortID INT,Effort VARCHAR(50)); INSERT INTO PsychologyInclusion VALUES (1,'Mental Health Resources'),(2,'Accessible Counseling'),(3,'Diverse Research Opportunities'); INSERT INTO EnglishInclusion VALUES (2,'Accessible Counseling'),(4,'Writing Workshops');
SELECT Effort FROM PsychologyInclusion WHERE Effort NOT IN (SELECT Effort FROM EnglishInclusion);
What is the average biomass of dolphins in the Southern Ocean?
CREATE TABLE SpeciesBiomass (species_name VARCHAR(50),species_id INT,biomass_mt NUMERIC(12,2),region VARCHAR(50),PRIMARY KEY(species_name,species_id)); INSERT INTO SpeciesBiomass (species_name,species_id,biomass_mt,region) VALUES ('Dolphin',1,456.25,'Southern Ocean'),('Whale',2,897.56,'Southern Ocean');
SELECT AVG(SpeciesBiomass.biomass_mt) FROM SpeciesBiomass WHERE SpeciesBiomass.species_name = 'Dolphin' AND SpeciesBiomass.region = 'Southern Ocean';
What is the average transaction amount per user in the 'creative_ai' application?
CREATE TABLE users (user_id INT,app VARCHAR(20)); INSERT INTO users (user_id,app) VALUES (1,'creative_ai'),(2,'algorithmic_fairness'),(3,'explainable_ai'); CREATE TABLE transactions (transaction_id INT,user_id INT,amount DECIMAL(10,2)); INSERT INTO transactions (transaction_id,user_id,amount) VALUES (1,1,50.00),(2,1,75.00),(3,2,30.00),(4,3,100.00),(5,1,60.00);
SELECT AVG(amount) as avg_amount FROM transactions INNER JOIN users ON transactions.user_id = users.user_id WHERE users.app = 'creative_ai';
Show total balances for customers in the 'High Value' segment
CREATE TABLE customer_segments (customer_id INT,segment VARCHAR(20)); INSERT INTO customer_segments VALUES (1,'High Value'); INSERT INTO customer_segments VALUES (2,'Low Value'); INSERT INTO customer_segments VALUES (3,'High Value'); CREATE VIEW customer_accounts AS SELECT c.customer_id,a.balance FROM accounts a JOIN customers c ON a.customer_id = c.customer_id;
SELECT SUM(ca.balance) as total_balance FROM customer_accounts ca JOIN customer_segments cs ON ca.customer_id = cs.customer_id WHERE cs.segment = 'High Value';
Determine the three-month moving average of production at each manufacturing site.
CREATE TABLE production (site_id INT,production_date DATE,quantity INT);
SELECT site_id, AVG(quantity) OVER (PARTITION BY site_id ORDER BY production_date ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) as moving_avg FROM production;
What is the total number of animals in all sanctuaries?
CREATE TABLE sanctuary_d (animal_id INT,animal_name VARCHAR(50),population INT); INSERT INTO sanctuary_d VALUES (1,'tiger',25); INSERT INTO sanctuary_d VALUES (2,'elephant',30); INSERT INTO sanctuary_d VALUES (3,'monkey',35); INSERT INTO sanctuary_d VALUES (4,'lion',40);
SELECT SUM(population) FROM sanctuary_d;
What is the total distance traveled by electric vehicles in Los Angeles in the last month?
CREATE TABLE electric_vehicles (vehicle_id INT,license_plate TEXT,registration_date DATE,last_maintenance_date DATE,vehicle_type TEXT,distance_traveled_km FLOAT);
SELECT SUM(distance_traveled_km) FROM electric_vehicles WHERE vehicle_type = 'electric' AND registration_date < DATE_SUB(CURDATE(), INTERVAL 1 MONTH) AND license_plate LIKE 'CA-%';
What was the total revenue for each gallery in 2021?
CREATE TABLE GallerySales (Gallery VARCHAR(255),ArtWork VARCHAR(255),Year INT,Revenue DECIMAL(10,2)); INSERT INTO GallerySales (Gallery,ArtWork,Year,Revenue) VALUES ('Gallery 1','Artwork 1',2021,500.00),('Gallery 1','Artwork 2',2021,400.00),('Gallery 2','Artwork 3',2021,750.00),('Gallery 2','Artwork 4',2021,1000.00);
SELECT Gallery, SUM(Revenue) as TotalRevenue FROM GallerySales WHERE Year = 2021 GROUP BY Gallery;
How many depression awareness campaigns were launched in the United States between 2015 and 2020?
CREATE TABLE campaigns (campaign_id INT,launch_year INT,condition VARCHAR(50),country VARCHAR(50)); INSERT INTO campaigns (campaign_id,launch_year,condition,country) VALUES (1,2015,'Depression','USA'),(2,2018,'Anxiety','USA'),(3,2020,'Depression','USA');
SELECT COUNT(*) FROM campaigns WHERE country = 'USA' AND condition = 'Depression' AND launch_year BETWEEN 2015 AND 2020;
What is the average age of the audience members who attended the "Theater" event?
CREATE TABLE Audience (AudienceID INT,Age INT,Event TEXT); INSERT INTO Audience (AudienceID,Age,Event) VALUES (1,30,'Theater'),(2,25,'Theater'),(3,40,'Movie');
SELECT AVG(Age) FROM Audience WHERE Event = 'Theater';
What is the minimum playtime for any VR game in Africa?
CREATE TABLE Games (GameID INT,GameType VARCHAR(255),ReleaseCountry VARCHAR(255),Playtime INT); INSERT INTO Games (GameID,GameType,ReleaseCountry,Playtime) VALUES (1,'RPG','Egypt',120); INSERT INTO Games (GameID,GameType,ReleaseCountry,Playtime) VALUES (2,'Shooter','South Africa',180); INSERT INTO Games (GameID,GameType,ReleaseCountry,Playtime) VALUES (3,'Adventure','Morocco',90);
SELECT MIN(Playtime) FROM Games WHERE ReleaseCountry LIKE '%Africa%';
Update the 'financial_capability' table to reflect an increase in the financial literacy score of a client in Indonesia.
CREATE TABLE financial_capability (client_id INT,financial_literacy_score INT,country VARCHAR(50)); INSERT INTO financial_capability VALUES (4,65,'Indonesia');
UPDATE financial_capability SET financial_literacy_score = 70 WHERE client_id = 4 AND country = 'Indonesia';
Which vessels have visited ports in more than one country in Europe?
CREATE TABLE Vessels (VesselID INT,Name VARCHAR(255),Type VARCHAR(255),Flag VARCHAR(255)); CREATE TABLE PortVisits (VisitID INT,VesselID INT,Port VARCHAR(255),VisitDate DATE,Country VARCHAR(255)); INSERT INTO Vessels (VesselID,Name,Type,Flag) VALUES (1,'European Trader','Cargo','EU'),(2,'Atlantic Navigator','Cargo','EU'); INSERT INTO PortVisits (VisitID,VesselID,Port,VisitDate,Country) VALUES (1,1,'Amsterdam','2022-01-02','Netherlands'),(2,1,'Paris','2022-02-14','France'),(3,2,'Madrid','2022-03-01','Spain'),(4,2,'Berlin','2022-04-10','Germany');
SELECT Vessels.Name FROM Vessels INNER JOIN PortVisits ON Vessels.VesselID = PortVisits.VesselID WHERE PortVisits.Country IN ('Netherlands', 'France', 'Spain', 'Germany') GROUP BY Vessels.Name HAVING COUNT(DISTINCT PortVisits.Country) > 1;
Find the top 5 donors for the 'Arts' program?
CREATE TABLE Donors (DonorID INT,DonorName VARCHAR(50),DonationAmount DECIMAL(10,2)); INSERT INTO Donors (DonorID,DonorName,DonationAmount) VALUES (1,'John Smith',500),(2,'Jane Doe',750),(3,'Bob Johnson',1000),(4,'Alice Williams',1200),(5,'Charlie Brown',1500); CREATE TABLE DonationPrograms (DonationID INT,ProgramID INT); INSERT INTO DonationPrograms (DonationID,ProgramID) VALUES (1,1),(2,1),(1,2),(3,2),(4,3),(5,3),(5,4);
SELECT D.DonorID, D.DonorName, SUM(D.DonationAmount) AS TotalDonated FROM Donors D JOIN DonationPrograms DP ON D.DonationID = DP.DonationID WHERE DP.ProgramID = (SELECT ProgramID FROM Programs WHERE ProgramName = 'Arts') GROUP BY D.DonorID, D.DonorName ORDER BY TotalDonated DESC LIMIT 5;
What is the total budget for AI projects in the 'east_africa' region in the 'tech_for_good' table?
CREATE TABLE tech_for_good (region TEXT,project TEXT,budget INTEGER); INSERT INTO tech_for_good (region,project,budget) VALUES ('East Africa','AI for Healthcare',150000); INSERT INTO tech_for_good (region,project,budget) VALUES ('East Africa','AI for Education',200000);
SELECT SUM(budget) FROM tech_for_good WHERE region = 'East Africa';
What is the average financial wellbeing score for clients in the Middle East?
CREATE TABLE clients (client_id INT,client_name TEXT,region TEXT,financial_wellbeing_score DECIMAL);
SELECT AVG(financial_wellbeing_score) FROM clients WHERE region = 'Middle East';
What is the average caloric content of dishes in each cuisine type, excluding dishes with no caloric information?
CREATE TABLE CuisineTypes (CuisineTypeID INT,CuisineType VARCHAR(50));CREATE TABLE Dishes (DishID INT,DishName VARCHAR(50),CuisineTypeID INT,CaloricContent INT,HasCaloricInfo BOOLEAN); INSERT INTO CuisineTypes VALUES (1,'Italian'),(2,'Chinese'),(3,'Indian'); INSERT INTO Dishes VALUES (1,'Pizza Margherita',1,500,true),(2,'Spaghetti Bolognese',1,700,true),(3,'Kung Pao Chicken',2,600,true),(4,'Spring Rolls',2,NULL,false),(5,'Butter Chicken',3,800,true),(6,'Palak Paneer',3,600,true);
SELECT ct.CuisineType, AVG(d.CaloricContent) as AvgCaloricContent FROM CuisineTypes ct JOIN Dishes d ON ct.CuisineTypeID = d.CuisineTypeID WHERE d.HasCaloricInfo = true GROUP BY ct.CuisineType;
What is the total investment in agricultural innovation in 'Africa' up to 2021?
CREATE TABLE agricultural_innovation (innovation_id INT,innovation_name TEXT,region TEXT,investment_amount INT,year INT); INSERT INTO agricultural_innovation (innovation_id,innovation_name,region,investment_amount,year) VALUES (1,'Drought-Resistant Crops','Africa',2000000,2020); INSERT INTO agricultural_innovation (innovation_id,innovation_name,region,investment_amount,year) VALUES (2,'Precision Farming','Asia',3000000,2021);
SELECT SUM(investment_amount) FROM agricultural_innovation WHERE year <= 2021 AND region = 'Africa';
Insert new records of products sold to a retailer
CREATE TABLE sales(sale_id INT,product_id INT,retailer_id INT,quantity INT,sale_date DATE); INSERT INTO sales(sale_id,product_id,retailer_id,quantity,sale_date) VALUES (1,1,101,10,'2022-01-01'),(2,2,101,15,'2022-01-02'),(3,3,102,5,'2022-01-03');
INSERT INTO sales(sale_id, product_id, retailer_id, quantity, sale_date) VALUES (4, 4, 101, 8, '2022-01-04'), (5, 5, 102, 12, '2022-01-05'), (6, 6, 103, 7, '2022-01-06');
What is the maximum amount of coal extracted in a single day in the 'production_data' table?
CREATE TABLE production_data (id INT,date DATE,coal_production INT,gold_production INT); INSERT INTO production_data (id,date,coal_production,gold_production) VALUES (1,'2022-01-01',200,10); INSERT INTO production_data (id,date,coal_production,gold_production) VALUES (2,'2022-01-02',250,15);
SELECT MAX(coal_production) as max_coal_production FROM production_data;
Calculate the average flight hours for each aircraft model, partitioned by manufacturer.
CREATE TABLE AircraftFlightHours (AircraftID INT,Model VARCHAR(50),Manufacturer VARCHAR(50),FlightHours INT); INSERT INTO AircraftFlightHours (AircraftID,Model,Manufacturer,FlightHours) VALUES (1,'747','Boeing',55000); INSERT INTO AircraftFlightHours (AircraftID,Model,Manufacturer,FlightHours) VALUES (2,'A320','Airbus',35000); INSERT INTO AircraftFlightHours (AircraftID,Model,Manufacturer,FlightHours) VALUES (3,'CRJ','Bombardier',20000);
SELECT Model, Manufacturer, AVG(FlightHours) OVER (PARTITION BY Manufacturer) AS Avg_Flight_Hours_By_Manufacturer FROM AircraftFlightHours;
Who are the attorneys with a win rate greater than 70% in criminal cases?
CREATE TABLE Attorneys (AttorneyID INT,Name VARCHAR(50),Wins INT,Losses INT); INSERT INTO Attorneys (AttorneyID,Name,Wins,Losses) VALUES (1,'John Doe',10,2),(2,'Jane Smith',15,5); CREATE TABLE Cases (CaseID INT,AttorneyID INT,CaseType VARCHAR(50)); INSERT INTO Cases (CaseID,AttorneyID,CaseType) VALUES (1,1,'Criminal'),(2,2,'Criminal');
SELECT Name FROM Attorneys WHERE (Wins / (Wins + Losses)) * 100 > 70 AND AttorneyID IN (SELECT AttorneyID FROM Cases WHERE CaseType = 'Criminal');
What is the maximum number of games won by any team in a single season?
CREATE TABLE games (id INT,team TEXT,season INT,home_or_away TEXT,wins INT,losses INT); INSERT INTO games (id,team,season,home_or_away,wins,losses) VALUES (1,'Team A',2020,'Home',35,10); INSERT INTO games (id,team,season,home_or_away,wins,losses) VALUES (2,'Team B',2020,'Away',28,17);
SELECT team, MAX(wins) FROM games GROUP BY team;
What's the avg. donation amount for each org in '2019'?
CREATE TABLE OrganizationDonations (OrgID INT,DonationAmount INT,DonationYear INT); CREATE TABLE Organizations (OrgID INT,OrgName TEXT);
SELECT o.OrgName, AVG(od.DonationAmount) FROM OrganizationDonations od INNER JOIN Organizations o ON od.OrgID = o.OrgID WHERE od.DonationYear = 2019 GROUP BY o.OrgName;
Which menu items in the vegan category have a revenue greater than $1000 in 2022?
CREATE TABLE menu_engineering(menu_item VARCHAR(255),category VARCHAR(255),revenue DECIMAL(10,2),sustainable_source BOOLEAN); INSERT INTO menu_engineering VALUES ('Vegan Pizza','Vegan',1200,TRUE); INSERT INTO menu_engineering VALUES ('Tofu Stir Fry','Vegan',800,TRUE);
SELECT menu_item FROM menu_engineering WHERE category = 'Vegan' AND revenue > 1000 AND YEAR(date) = 2022;
List all the 'protected areas' in 'North America'
CREATE TABLE protected_areas (id INT,name VARCHAR(50),location VARCHAR(50)); INSERT INTO protected_areas (id,name,location) VALUES (1,'Yosemite National Park','North America');
SELECT name FROM protected_areas WHERE location = 'North America' AND status = 'protected';
Which marine protected areas have a depth greater than 1000 meters?
CREATE TABLE marine_protected_areas (name text,depth integer); INSERT INTO marine_protected_areas (name,depth) VALUES ('Galapagos Islands',2000),('Great Barrier Reef',1000);
SELECT name FROM marine_protected_areas WHERE depth > 1000;
What is the total amount of research grants received by each faculty member in the 'Computer Science' department?
CREATE TABLE faculty (faculty_id INT,name TEXT,department TEXT);CREATE TABLE grants (grant_id INT,faculty_id INT,funding_source TEXT,grant_date DATE,grant_amount INT); INSERT INTO faculty (faculty_id,name,department) VALUES (1,'Alice','Computer Science'),(2,'Bob','Computer Science'); INSERT INTO grants (grant_id,faculty_id,funding_source,grant_date,grant_amount) VALUES (1,1,'Google','2022-01-01',50000),(2,2,'Microsoft','2021-01-01',75000);
SELECT faculty.name, SUM(grants.grant_amount) AS total_grant_amount FROM faculty INNER JOIN grants ON faculty.faculty_id = grants.faculty_id WHERE faculty.department = 'Computer Science' GROUP BY faculty.name;
How many workers were involved in projects that have solar panels?
CREATE TABLE project (id INT,name VARCHAR(50),location VARCHAR(50),start_date DATE); INSERT INTO project (id,name,location,start_date) VALUES (1,'Green Build','NYC','2020-01-01'),(2,'Solar Tower','LA','2019-12-15'),(3,'Eco House','Austin','2020-03-01'); CREATE TABLE labor (id INT,project_id INT,worker VARCHAR(50),hours FLOAT); INSERT INTO labor (id,project_id,worker,hours) VALUES (1,1,'John',40),(2,1,'Jane',35),(3,2,'Bob',45),(4,2,'Alice',50),(5,3,'Alex',48),(6,3,'Nia',42),(7,3,'Jamal',55); CREATE TABLE sustainable (project_id INT,solar_panels BOOLEAN,wind_turbines BOOLEAN,green_roof BOOLEAN); INSERT INTO sustainable (project_id,solar_panels,wind_turbines,green_roof) VALUES (1,TRUE,FALSE,TRUE),(2,TRUE,TRUE,FALSE),(3,FALSE,FALSE,TRUE);
SELECT COUNT(DISTINCT l.project_id) AS num_workers FROM labor l JOIN sustainable s ON l.project_id = s.project_id WHERE s.solar_panels = TRUE;
Create a table named 'victims'
CREATE TABLE victims (id INT PRIMARY KEY,name VARCHAR(50),age INT,ethnicity VARCHAR(20),incident_date DATE);
CREATE TABLE victims (id INT PRIMARY KEY, name VARCHAR(50), age INT, ethnicity VARCHAR(20), incident_date DATE);
Show average total fare from "recent_trips" view.
CREATE TABLE stations (station_id INT,name VARCHAR(255),latitude FLOAT,longitude FLOAT,region VARCHAR(5)); CREATE TABLE routes (route_id INT,name VARCHAR(255),start_station_id INT,end_station_id INT); CREATE VIEW stations_view AS SELECT station_id,name,latitude,longitude,'North' AS region FROM stations WHERE latitude > 40 AND longitude < -70; SELECT * FROM stations WHERE latitude < 40 OR longitude > -70; CREATE TABLE trips (trip_id INT,route_id INT,start_time TIMESTAMP,end_time TIMESTAMP,total_fare FLOAT); CREATE VIEW recent_trips AS SELECT trip_id,route_id,start_time,total_fare FROM trips WHERE start_time > NOW() - INTERVAL '24 hour';
SELECT AVG(total_fare) FROM recent_trips;
Identify the number of autonomous taxis in Singapore by hour.
CREATE TABLE singapore_taxis (id INT,taxi_id VARCHAR(20),start_time TIMESTAMP,end_time TIMESTAMP,autonomous BOOLEAN);
SELECT DATE_FORMAT(start_time, '%Y-%m-%d %H') AS hour, COUNT(*) FROM singapore_taxis WHERE autonomous = TRUE GROUP BY hour;
Add a new fair trade certified product 'Socks' to 'Products' table
CREATE TABLE Products(id INT,name TEXT,material TEXT,is_sustainable BOOLEAN,is_fair_trade_certified BOOLEAN); INSERT INTO Products(id,name,material,is_sustainable,is_fair_trade_certified) VALUES (1,'Shirt','Hemp',true,false),(2,'Pants','Tencel',true,true),(3,'Jacket','Recycled Polyester',true,true); CREATE TABLE Materials(id INT,name TEXT,is_sustainable BOOLEAN); INSERT INTO Materials(id,name,is_sustainable) VALUES (1,'Hemp',true),(2,'Tencel',true),(3,'Recycled Polyester',true);
INSERT INTO Products(id, name, material, is_sustainable, is_fair_trade_certified) VALUES (4, 'Socks', 'Organic Cotton', true, true);
Update player records to set the name 'Siti Rosli' if the Player_ID is 2 in the 'Player' table
CREATE TABLE Player (Player_ID INT,Name VARCHAR(50),Date_Joined DATE); INSERT INTO Player (Player_ID,Name,Date_Joined) VALUES (1,'John Doe','2019-06-15'),(2,'Jane Smith','2020-03-08'),(3,'Alice Johnson','2021-02-22'),(4,'Bob Brown','2020-08-10');
UPDATE Player SET Name = 'Siti Rosli' WHERE Player_ID = 2;
What is the average number of hours of pro bono work performed by lawyers in the Southern region in the past year?
CREATE TABLE pro_bono_work (id INT,lawyer_name TEXT,hours_worked INT,region TEXT,work_year INT); INSERT INTO pro_bono_work (id,lawyer_name,hours_worked,region,work_year) VALUES (1,'Mohammed Ahmed',30,'Southern',2022); INSERT INTO pro_bono_work (id,lawyer_name,hours_worked,region,work_year) VALUES (2,'Karen Nguyen',25,'Southern',2022);
SELECT AVG(hours_worked) FROM pro_bono_work WHERE region = 'Southern' AND work_year = 2022;
What is the total maintenance cost for military equipment in the African region in the second half of 2021?
CREATE TABLE military_equipment (equipment_id INT,region VARCHAR(10),maintenance_cost DECIMAL(10,2),maintenance_date DATE); INSERT INTO military_equipment VALUES (1,'Africa',3000.00,'2021-07-01'),(2,'Europe',2500.00,'2021-08-01'),(3,'Africa',4500.00,'2021-10-01');
SELECT SUM(maintenance_cost) FROM military_equipment WHERE region = 'Africa' AND maintenance_date >= DATE '2021-07-01' AND maintenance_date < DATE '2022-01-01';
What is the total cost of accommodations for students with hearing impairments in the engineering department in 2021?
CREATE TABLE students (id INT,hearing_impairment BOOLEAN,department VARCHAR(255)); INSERT INTO students (id,hearing_impairment,department) VALUES (1,true,'engineering'),(2,false,'engineering'),(3,true,'engineering'),(4,false,'engineering'); CREATE TABLE accommodations (id INT,student_id INT,year INT,cost DECIMAL(10,2)); INSERT INTO accommodations (id,student_id,year,cost) VALUES (1,1,2018,500.00),(2,1,2019,200.00),(3,3,2018,300.00),(4,3,2019,100.00),(5,3,2021,400.00),(6,4,2020,700.00);
SELECT SUM(cost) as total_cost FROM accommodations a INNER JOIN students s ON a.student_id = s.id WHERE s.hearing_impairment = true AND s.department = 'engineering' AND a.year = 2021;
Who is the oldest author in the 'opinion' category?
CREATE TABLE news (title VARCHAR(255),author VARCHAR(255),age INT,category VARCHAR(255)); INSERT INTO news (title,author,age,category) VALUES ('Sample News','Mary Johnson',45,'Opinion');
SELECT author FROM news WHERE category = 'Opinion' ORDER BY age DESC LIMIT 1;
List the number of wells drilled per drilling company in 2021
CREATE TABLE company_drilling_figures (company_id INT,drilling_date DATE);
SELECT company_id, COUNT(*) as num_wells_drilled FROM company_drilling_figures WHERE drilling_date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY company_id;
What is the average number of virtual tour engagements per city in 'APAC' region?
CREATE TABLE virtual_tours (tour_id INT,city TEXT,region TEXT,engagement FLOAT); INSERT INTO virtual_tours (tour_id,city,region,engagement) VALUES (1,'Tokyo','APAC',250.5),(2,'Seoul','APAC',300.7),(3,'Osaka','APAC',220.1),(4,'Paris','EMEA',350.2);
SELECT city, AVG(engagement) FROM virtual_tours WHERE region = 'APAC' GROUP BY city;
What is the name of the city with the highest population growth rate in the last 3 years?
CREATE TABLE historical_cities (name VARCHAR(50),year INT,population INT); INSERT INTO historical_cities (name,year,population) VALUES ('CityA',2018,750000),('CityA',2019,760000),('CityA',2020,770000),('CityB',2018,600000),('CityB',2019,605000),('CityB',2020,610000),('CityC',2018,550000),('CityC',2019,555000),('CityC',2020,560000);
SELECT name FROM (SELECT name, (population-LAG(population) OVER (PARTITION BY name ORDER BY year))/(year-LAG(year) OVER (PARTITION BY name ORDER BY year)) as growth_rate FROM historical_cities WHERE year BETWEEN 2018 AND 2020) WHERE growth_rate = (SELECT MAX(growth_rate) FROM (SELECT name, (population-LAG(population) OVER (PARTITION BY name ORDER BY year))/(year-LAG(year) OVER (PARTITION BY name ORDER BY year)) as growth_rate FROM historical_cities WHERE year BETWEEN 2018 AND 2020));
What is the minimum time to complete a project in the Southwest?
CREATE TABLE Projects (id INT,region VARCHAR(255),completion_time INT); INSERT INTO Projects (id,region,completion_time) VALUES (1,'Southwest',120),(2,'Northeast',150),(3,'Southwest',100);
SELECT MIN(completion_time) FROM Projects WHERE region = 'Southwest';
Insert a new record into the "media_ethics" table with the following details: id 8, topic "Freedom of the press", description "Importance of a free press in a democracy", created_at "2022-03-20"
CREATE TABLE media_ethics (id INT,topic TEXT,description TEXT,created_at DATE);
INSERT INTO media_ethics (id, topic, description, created_at) VALUES (8, 'Freedom of the press', 'Importance of a free press in a democracy', '2022-03-20');
What is the minimum size (in hectares) of a plot in the 'plots' table, where the plot is used for indigenous food systems and is located in the 'Africa' region?
CREATE TABLE plots (id INT,size_ha FLOAT,location TEXT,type TEXT); INSERT INTO plots (id,size_ha,location,type) VALUES (1,2.5,'Africa','Urban'); INSERT INTO plots (id,size_ha,location,type) VALUES (2,1.8,'Africa','Indigenous');
SELECT MIN(size_ha) FROM plots WHERE type = 'Indigenous' AND location = 'Africa';
Show the number of new garment designs released per month in 2022.
CREATE TABLE Designs(id INT,design_name VARCHAR(100),release_date DATE); INSERT INTO Designs(id,design_name,release_date) VALUES (1,'Spring Dress','2022-03-01'); INSERT INTO Designs(id,design_name,release_date) VALUES (2,'Summer Shirt','2022-05-15');
SELECT DATEPART(month, release_date) AS Month, COUNT(*) AS DesignsReleased FROM Designs WHERE YEAR(release_date) = 2022 GROUP BY DATEPART(month, release_date);
What is the average energy consumption per machine per shift?
create table MachineEnergy (Machine varchar(255),Energy int,Shift int,Timestamp datetime); insert into MachineEnergy values ('Machine1',50,1,'2022-01-01 00:00:00'),('Machine2',70,1,'2022-01-01 00:00:00'),('Machine1',60,2,'2022-01-02 00:00:00');
select Machine, Shift, AVG(Energy) as AvgEnergy from MachineEnergy group by Machine, Shift;
Update the number of members for the 'United Auto Workers' to 400,000.
CREATE TABLE unions (id INT,name TEXT,domain TEXT,members INT); INSERT INTO unions (id,name,domain,members) VALUES (1,'United Auto Workers','Automobiles,Aerospace',350000); INSERT INTO unions (id,name,domain,members) VALUES (2,'United Steelworkers','Metals,Mining,Energy,Construction',850000);
UPDATE unions SET members = 400000 WHERE name = 'United Auto Workers';
Which countries have the most factories with fair labor practices?
CREATE TABLE factories (factory_id INT,country VARCHAR(20),has_fair_labor BOOLEAN); INSERT INTO factories (factory_id,country,has_fair_labor) VALUES (1,'Bangladesh',TRUE),(2,'Cambodia',FALSE),(3,'India',TRUE),(4,'Vietnam',FALSE);
SELECT country, SUM(has_fair_labor) AS total_fair_labor FROM factories GROUP BY country;
What are the restorative practices unique to a specific offense type in the 'practice_by_offense' table?
CREATE TABLE practice_by_offense (offense_id INT,practice_id INT); CREATE TABLE restorative_practices (practice_id INT,practice VARCHAR(255));
SELECT practice FROM restorative_practices WHERE practice_id IN (SELECT practice_id FROM practice_by_offense GROUP BY practice_id HAVING COUNT(DISTINCT offense_id) = 1);
What is the total revenue generated from sales in the 'sales' table, partitioned by month?
CREATE TABLE sales (sale_id INT,sale_date DATE,sale_price DECIMAL(5,2));
SELECT EXTRACT(MONTH FROM sale_date) as month, SUM(sale_price) FROM sales GROUP BY month;
What is the average delivery time for each transportation mode?
CREATE TABLE deliveries (id INT,order_id INT,delivery_time INT,transportation_mode VARCHAR(50)); INSERT INTO deliveries (id,order_id,delivery_time,transportation_mode) VALUES (1,1001,3,'Air'),(2,1002,7,'Road'),(3,1003,5,'Rail'),(4,1004,2,'Sea');
SELECT transportation_mode, AVG(delivery_time) as avg_delivery_time FROM deliveries GROUP BY transportation_mode;
Insert new records for 'Artillery' sales to 'South America' in the year '2026' with the quantity of 20 and value of 18000000
CREATE TABLE military_sales (id INT PRIMARY KEY,region VARCHAR(20),year INT,equipment_name VARCHAR(30),quantity INT,value FLOAT);
INSERT INTO military_sales (id, region, year, equipment_name, quantity, value) VALUES (4, 'South America', 2026, 'Artillery', 20, 18000000);
What is the average age of visitors who attended exhibitions on 'Friday'?
CREATE TABLE Exhibitions (exhibition_id INT,name VARCHAR(50),start_date DATE,end_date DATE,day VARCHAR(10)); CREATE TABLE Visitors (visitor_id INT,exhibition_id INT,age INT,gender VARCHAR(50));
SELECT AVG(age) FROM Visitors v JOIN Exhibitions e ON v.exhibition_id = e.exhibition_id WHERE e.day = 'Friday';
What is the minimum energy storage capacity (MWh) in the Australian energy market, and how many storage facilities have a capacity greater than 100 MWh?
CREATE TABLE energy_storage (id INT,location TEXT,country TEXT,capacity FLOAT); INSERT INTO energy_storage (id,location,country,capacity) VALUES (1,'Hornsdale','Australia',129.0),(2,'Tesla Big Battery','Australia',100.0),(3,'Bald Hills','Australia',105.0);
SELECT MIN(capacity), COUNT(*) FROM energy_storage WHERE country = 'Australia' AND capacity > 100;
What is the total population of countries involved in climate adaptation projects in Oceania?
CREATE TABLE climate_adaptation (country VARCHAR(255),population INT); INSERT INTO climate_adaptation VALUES ('Australia',25000000); INSERT INTO climate_adaptation VALUES ('New Zealand',4900000);
SELECT SUM(population) FROM climate_adaptation WHERE continent = 'Oceania';
Calculate the average score for each game
CREATE TABLE game_scores (id INT PRIMARY KEY,player_id INT,game_name VARCHAR(100),score INT); INSERT INTO game_scores VALUES (1,1001,'GameA',5000),(2,1002,'GameB',7000),(3,1003,'GameA',3000),(4,1004,'GameB',7500),(5,1001,'GameA',5500),(6,1005,'GameC',8000);
SELECT game_name, AVG(score) AS avg_score FROM game_scores GROUP BY game_name;
Design a new table named 'student_mental_health'
CREATE TABLE student_mental_health (id INT PRIMARY KEY,student_id INT,mental_health_score INT,assessment_date DATE);
CREATE TABLE student_mental_health (id INT PRIMARY KEY, student_id INT, mental_health_score INT, assessment_date DATE);
What is the total distance traveled by shared electric bicycles in Paris in the past month?
CREATE TABLE shared_bicycles (bicycle_id INT,ride_start_time TIMESTAMP,ride_end_time TIMESTAMP,start_location TEXT,end_location TEXT,distance FLOAT);
SELECT SUM(distance) FROM shared_bicycles WHERE start_location LIKE 'Paris%' AND vehicle_type = 'Electric Bicycle' AND ride_start_time >= NOW() - INTERVAL '1 month';
Insert new records of community health workers who specialize in both mental health and physical health.
CREATE TABLE CommunityHealthWorkers (WorkerID INT,Name VARCHAR(50),Specialty VARCHAR(50));
INSERT INTO CommunityHealthWorkers (WorkerID, Name, Specialty) VALUES (3, 'Jim Brown', 'Mental Health, Physical Health'); INSERT INTO CommunityHealthWorkers (WorkerID, Name, Specialty) VALUES (4, 'Sara Johnson', 'Mental Health, Physical Health');
What is the number of job offers extended to female candidates in the last 6 months?
CREATE TABLE JobOffers (OfferID INT,JobCategory VARCHAR(20),Gender VARCHAR(10),OfferDate DATE); INSERT INTO JobOffers (OfferID,JobCategory,Gender,OfferDate) VALUES (1,'Marketing','Female','2022-01-10'),(2,'IT','Male','2022-03-15');
SELECT JobCategory, COUNT(*) FROM JobOffers WHERE Gender = 'Female' AND OfferDate BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH) AND CURRENT_DATE GROUP BY JobCategory;
What is the maximum number of peacekeeping personnel trained by the European Union in cybersecurity between 2017 and 2022, inclusive?
CREATE TABLE peacekeeping_training(id INT,personnel_id INT,trained_by VARCHAR(255),trained_in VARCHAR(255),training_year INT); INSERT INTO peacekeeping_training(id,personnel_id,trained_by,trained_in,training_year) VALUES (1,111,'EU','Cybersecurity',2017),(2,222,'EU','Peacekeeping Tactics',2018),(3,333,'EU','Cybersecurity',2019),(4,444,'EU','Cybersecurity',2020),(5,555,'EU','Cybersecurity',2021),(6,666,'EU','Cybersecurity',2022);
SELECT MAX(personnel_id) FROM peacekeeping_training WHERE trained_by = 'EU' AND trained_in = 'Cybersecurity' AND training_year BETWEEN 2017 AND 2022;
Which country had the highest total number of shipments in the month of 'February 2022'?
CREATE TABLE Shipments (country varchar(20),shipment_date date); INSERT INTO Shipments (country,shipment_date) VALUES ('Country X','2022-01-05'),('Country Y','2022-02-10');
SELECT country, SUM(CASE WHEN EXTRACT(MONTH FROM shipment_date) = 2 AND EXTRACT(YEAR FROM shipment_date) = 2022 THEN 1 ELSE 0 END) AS total_shipments, SUM(total_shipments) OVER () AS total_shipments_all_countries FROM (SELECT country, COUNT(*) AS total_shipments FROM Shipments GROUP BY country, EXTRACT(MONTH FROM shipment_date), EXTRACT(YEAR FROM shipment_date)) subquery ORDER BY total_shipments DESC LIMIT 1;
How many mental health policies were implemented in California in 2021?
CREATE TABLE MentalHealthPolicies (PolicyID INT,State VARCHAR(20),Year INT,Policy VARCHAR(100)); INSERT INTO MentalHealthPolicies (PolicyID,State,Year,Policy) VALUES (1,'California',2021,'Mental Health Teletherapy Expansion'); INSERT INTO MentalHealthPolicies (PolicyID,State,Year,Policy) VALUES (2,'California',2020,'Suicide Prevention Program');
SELECT COUNT(*) FROM MentalHealthPolicies WHERE State = 'California' AND Year = 2021;
Find the number of juvenile cases that were resolved through community supervision, broken down by race/ethnicity, for the past year.
CREATE TABLE JuvenileCases (Id INT,Race VARCHAR(50),Program VARCHAR(50),ResolutionDate DATE); INSERT INTO JuvenileCases (Id,Race,Program,ResolutionDate) VALUES (1,'Hispanic','Community Supervision','2021-03-21'),(2,'Black','Probation','2020-12-12'),(3,'Asian','Community Supervision','2021-06-15');
SELECT Race, COUNT(*) as NumCases FROM JuvenileCases WHERE Program = 'Community Supervision' AND YEAR(ResolutionDate) = 2021 GROUP BY Race;
Determine the policy with the highest claim amount for each policyholder.
CREATE TABLE policies (policy_id INT,policyholder_id INT); CREATE TABLE claims (claim_id INT,policy_id INT,amount DECIMAL(10,2));
SELECT policies.policyholder_id, MAX(claims.amount) AS highest_claim_amount FROM policies INNER JOIN claims ON policies.policy_id = claims.policy_id GROUP BY policies.policyholder_id;
Delete the water usage data for the 'Agricultural' category in the water_usage table for the date '2022-07-03'
CREATE TABLE water_usage (date DATE,usage_category VARCHAR(20),region VARCHAR(20),usage_amount INT); INSERT INTO water_usage (date,usage_category,region,usage_amount) VALUES ('2022-07-01','Residential','Northeast',15000),('2022-07-02','Industrial','Midwest',200000),('2022-07-03','Agricultural','West',800000);
DELETE FROM water_usage WHERE usage_category = 'Agricultural' AND date = '2022-07-03';
What is the maximum food cost percentage for menu items that have been ordered more than 100 times?
CREATE TABLE MenuItems(menu_item_id INT,item_name VARCHAR(255),order_count INT,food_cost_percentage DECIMAL(5,2));
SELECT MAX(food_cost_percentage) FROM MenuItems WHERE order_count > 100;
What is the virtual tour engagement rate for each hotel, sorted by engagement rate in ascending order?
CREATE TABLE virtual_tours (tour_id INT,hotel_name TEXT,engagement_rate FLOAT); INSERT INTO virtual_tours (tour_id,hotel_name,engagement_rate) VALUES (1,'Hotel A',0.05),(2,'Hotel B',0.07),(3,'Hotel C',0.06);
SELECT hotel_name, engagement_rate FROM virtual_tours ORDER BY engagement_rate ASC;
What is the clearance rate for violent crimes in the city of Dallas?
CREATE TABLE violent_crimes (id INT,city VARCHAR(20),clearance_rate FLOAT); INSERT INTO violent_crimes (id,city,clearance_rate) VALUES (1,'Dallas',0.55);
SELECT clearance_rate FROM violent_crimes WHERE city = 'Dallas';