instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
List cybersecurity strategies, their implementing organizations, and types | CREATE TABLE CyberStrategy (id INT PRIMARY KEY,name VARCHAR(255),description TEXT,organization_id INT); CREATE TABLE Organization (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255)); INSERT INTO Organization (id,name,type) VALUES (1,'NSA','Intelligence'); | SELECT s.name, o.name AS organization_name, o.type FROM CyberStrategy s INNER JOIN Organization o ON s.organization_id = o.id WHERE o.type = 'Intelligence'; |
What is the percentage of cases that were resolved through restorative justice, by year? | CREATE TABLE CaseResolutions (CaseID INT,Resolution VARCHAR(20),Year INT); INSERT INTO CaseResolutions (CaseID,Resolution,Year) VALUES (1,'Restorative Justice',2021),(2,'Probation',2021),(3,'Restorative Justice',2022),(4,'Incarceration',2022); | SELECT Year, COUNT(*) FILTER (WHERE Resolution = 'Restorative Justice') * 100.0 / COUNT(*) AS Percentage FROM CaseResolutions GROUP BY Year; |
What is the average report age for products that have a safety rating of 'Excellent'? | CREATE TABLE Product (id INT,productName VARCHAR(50),price DECIMAL(5,2)); INSERT INTO Product (id,productName,price) VALUES (4,'Blush',14.99),(5,'Foundation',29.99),(6,'Lip Liner',16.99); CREATE TABLE SafetyRecord (id INT,productId INT,safetyRating VARCHAR(10),reportDate DATE); INSERT INTO SafetyRecord (id,productId,safetyRating,reportDate) VALUES (5,4,'Excellent','2021-04-01'),(6,5,'Good','2021-05-01'),(7,6,'Excellent','2021-06-01'); | SELECT AVG(DATEDIFF(day, S.reportDate, GETDATE())) as avgReportAge FROM SafetyRecord S WHERE S.safetyRating = 'Excellent'; |
List the names of all startups that have exited through an IPO | CREATE TABLE exit_strategies (company_name VARCHAR(100),exit_type VARCHAR(50),exit_year INT); | SELECT company_name FROM exit_strategies WHERE exit_type = 'IPO'; |
What is the percentage of mobile and broadband subscribers who have made a complaint in the last 6 months? | CREATE TABLE mobile_subscribers(subscriber_id INT,made_complaint BOOLEAN); INSERT INTO mobile_subscribers(subscriber_id,made_complaint) VALUES (1,TRUE),(2,FALSE),(3,TRUE),(4,FALSE); CREATE TABLE broadband_subscribers(subscriber_id INT,made_complaint BOOLEAN); INSERT INTO broadband_subscribers(subscriber_id,made_complaint) VALUES (1,TRUE),(2,FALSE),(3,TRUE),(4,FALSE); | SELECT (SELECT COUNT(*) FROM (SELECT subscriber_id FROM mobile_subscribers WHERE made_complaint = TRUE UNION SELECT subscriber_id FROM broadband_subscribers WHERE made_complaint = TRUE)) * 100.0 / (SELECT COUNT(*) FROM (SELECT subscriber_id FROM mobile_subscribers UNION SELECT subscriber_id FROM broadband_subscribers)); |
Update the recycling rate for Japan to 35.5% in the RecyclingRatesAPAC table. | CREATE TABLE RecyclingRatesAPAC (id INT,country VARCHAR(50),region VARCHAR(50),recycling_rate FLOAT); INSERT INTO RecyclingRatesAPAC (id,country,region,recycling_rate) VALUES (1,'China','APAC',25.6),(2,'Japan','APAC',34.7),(3,'India','APAC',22.3); | UPDATE RecyclingRatesAPAC SET recycling_rate = 0.355 WHERE country = 'Japan'; |
What mental health campaigns were active in the second half of 2021? | CREATE TABLE campaigns (id INT,name VARCHAR(50),start_date DATE,end_date DATE); INSERT INTO campaigns (id,name,start_date,end_date) VALUES (3,'Embrace Yourself','2021-07-01','2021-12-31'); INSERT INTO campaigns (id,name,start_date,end_date) VALUES (4,'Mental Health for All','2021-07-01','2021-12-31'); | SELECT name FROM campaigns WHERE start_date <= '2021-07-01' AND end_date >= '2021-07-01' |
What is the total number of employees for companies founded by underrepresented minorities in the tech sector? | CREATE TABLE companies (id INT,name TEXT,industry TEXT,employees INT,founding_date DATE,founder_minority TEXT); | SELECT SUM(employees) FROM companies WHERE industry = 'Tech' AND founder_minority IN ('African American', 'Hispanic', 'Native American'); |
Add a new menu item 'Veggie Burger' with a price of 13.50 | CREATE TABLE menu_items (item_id INT,item_name VARCHAR(50),price DECIMAL(5,2)); | INSERT INTO menu_items (item_name, price) VALUES ('Veggie Burger', 13.50); |
Calculate the percentage of employees who received a promotion in the last 6 months, and display the result with two decimal places. | CREATE TABLE Employees (EmployeeID INT,PromotionDate DATE); | SELECT ROUND(COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Employees) , 2) AS PromotionPercentage FROM Employees WHERE PromotionDate >= DATEADD(month, -6, GETDATE()); |
How many properties are there in each city, ordered by the number of properties in descending order? | CREATE TABLE cities (id INT,name VARCHAR(255)); INSERT INTO cities (id,name) VALUES (1,'New York'),(2,'Los Angeles'),(3,'London'); CREATE TABLE properties (id INT,city_id INT); INSERT INTO properties (id,city_id) VALUES (1,1),(2,1),(3,2),(4,2),(5,3),(6,3),(7,3); | SELECT city_id, COUNT(*) as num_properties FROM properties GROUP BY city_id ORDER BY num_properties DESC; |
Which neighborhood in Austin has the most affordable housing? | CREATE TABLE housing_units (id INT,neighborhood TEXT,city TEXT,state TEXT,price FLOAT,is_affordable BOOLEAN); | SELECT neighborhood, COUNT(*) as total_affordable FROM housing_units WHERE city = 'Austin' AND is_affordable = TRUE GROUP BY 1 HAVING total_affordable > (SELECT AVG(total_affordable) FROM (SELECT COUNT(*) as total_affordable FROM housing_units WHERE city = 'Austin' AND is_affordable = TRUE GROUP BY neighborhood) as subquery); |
What is the average altitude of spacecrafts launched by 'Blue Origin'? | CREATE TABLE SpacecraftLaunches (id INT,name VARCHAR(50),company VARCHAR(50),launch_date DATE,apogee FLOAT); | SELECT company, AVG(apogee) FROM SpacecraftLaunches WHERE company = 'Blue Origin' GROUP BY company; |
What is the percentage of public transportation trips taken by autonomous vehicles in Tokyo? | CREATE TABLE TransportationTrips(id INT,mode VARCHAR(20),city VARCHAR(20),autonomous BOOLEAN); | SELECT mode, ROUND(COUNT(*)*100.0/SUM(COUNT(*)) OVER (PARTITION BY city) , 2) as percentage FROM TransportationTrips WHERE city = 'Tokyo' AND autonomous = TRUE GROUP BY mode ORDER BY percentage DESC; |
Show the vehicles that passed safety tests and were also tested in autonomous driving research. | CREATE TABLE SafetyTestingVehicle (TestID INT,Vehicle VARCHAR(20),TestResult VARCHAR(10)); CREATE TABLE AutonomousDrivingData (TestID INT,Vehicle VARCHAR(20),MaxSpeed FLOAT,MinSpeed FLOAT); | SELECT Vehicle FROM SafetyTestingVehicle STV JOIN AutonomousDrivingData ADD ON STV.Vehicle = ADD.Vehicle WHERE STV.TestResult = 'Pass'; |
What is the total number of volunteers and total donation amount for each program in Mexico? | CREATE TABLE Donations (id INT,donation_amount DECIMAL(10,2),donation_date DATE,program VARCHAR(50),country VARCHAR(50)); CREATE TABLE Volunteers (id INT,volunteer_name VARCHAR(50),program VARCHAR(50),country VARCHAR(50)); INSERT INTO Donations (id,donation_amount,donation_date,program,country) VALUES (1,150.00,'2021-01-01','Environment','Mexico'); INSERT INTO Donations (id,donation_amount,donation_date,program,country) VALUES (2,250.00,'2021-01-02','Health','Mexico'); INSERT INTO Volunteers (id,volunteer_name,program,country) VALUES (1,'Maria Lopez','Environment','Mexico'); INSERT INTO Volunteers (id,volunteer_name,program,country) VALUES (2,'Pedro Hernandez','Health','Mexico'); | SELECT p.program, COUNT(DISTINCT v.volunteer_name) as num_volunteers, SUM(d.donation_amount) as total_donations FROM Donations d INNER JOIN Volunteers v ON d.program = v.program INNER JOIN Programs p ON d.program = p.program WHERE d.country = 'Mexico' GROUP BY p.program; |
Determine the number of users who have opted in to targeted advertising in 'Russia'. | CREATE TABLE users (id INT,name VARCHAR(255),country VARCHAR(255),opt_in_targeted_ads BOOLEAN); | SELECT COUNT(*) AS num_users |
What are the names and types of assistive technologies that have been distributed in underrepresented communities in the last 5 years? | CREATE TABLE assistive_tech (id INT,name VARCHAR(255),type VARCHAR(255),distribution_date DATE); CREATE TABLE communities (id INT,name VARCHAR(255),region VARCHAR(255)); | SELECT assistive_tech.name, assistive_tech.type FROM assistive_tech INNER JOIN communities ON assistive_tech.distribution_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 5 YEAR) WHERE communities.region = 'Underrepresented'; |
What is the maximum water temperature in the Arctic region? | CREATE TABLE Weather (location VARCHAR(255),temperature DECIMAL(5,2),time DATETIME); INSERT INTO Weather (location,temperature,time) VALUES ('Arctic',5.0,'2022-01-01 12:00:00'),('Arctic',4.5,'2022-01-02 12:00:00'); | SELECT MAX(temperature) FROM Weather WHERE location = 'Arctic' AND time BETWEEN '2022-01-01' AND '2022-01-02'; |
What is the average block size in the Bitcoin network? | CREATE TABLE network_stats (stat_id INT,coin VARCHAR(10),value DECIMAL(20,2)); INSERT INTO network_stats (stat_id,coin,value) VALUES (1,'Bitcoin',834563.45),(2,'Bitcoin',843546.23),(3,'Bitcoin',854364.21); | SELECT AVG(value) FROM network_stats WHERE coin = 'Bitcoin'; |
Which department has the highest veteran employment rate in 2020? | CREATE TABLE veteran_employment (department VARCHAR(100),year INT,num_veterans INT,total_employees INT); | SELECT department, (num_veterans/total_employees)*100 AS veteran_rate FROM veteran_employment WHERE year = 2020 ORDER BY veteran_rate DESC LIMIT 1; |
What is the total revenue of movies released in 2019? | CREATE TABLE movies_revenue (movie_id INT,title VARCHAR(255),release_year INT,revenue INT); INSERT INTO movies_revenue (movie_id,title,release_year,revenue) VALUES (1,'Inception',2010,825),(2,'Avatar',2009,2788),(3,'Parasite',2019,258),(4,'The Lion King',2019,1657); | SELECT SUM(revenue) as total_revenue FROM movies_revenue WHERE release_year = 2019; |
What is the maximum number of evidence-based policy making programs in the Asian region? | CREATE TABLE programs (id INT,region TEXT,program_count INT); INSERT INTO programs (id,region,program_count) VALUES (1,'Asian',10),(2,'African',8),(3,'European',12),(4,'American',15); | SELECT MAX(program_count) FROM programs WHERE region = 'Asian'; |
What is the total weight of recycled materials used in the production of garments? | CREATE TABLE Production(garment_id INT,recycled_material_weight INT); INSERT INTO Production(garment_id,recycled_material_weight) VALUES (1,5),(2,3); | SELECT SUM(recycled_material_weight) FROM Production; |
How many marine species are there in total? | CREATE TABLE marine_species (id INTEGER,name TEXT); INSERT INTO marine_species (id,name) VALUES (1,'Coral'),(2,'Clownfish'),(3,'Sea Star'),(4,'Tuna'),(5,'Polar Bear'),(6,'Narwhal'),(7,'Walrus'),(8,'Beluga Whale'); | SELECT COUNT(*) FROM marine_species; |
What is the average defense diplomacy spending for Western European nations in 2016? | CREATE TABLE DefenseDiplomacy (nation VARCHAR(50),year INT,spending FLOAT); INSERT INTO DefenseDiplomacy (nation,year,spending) VALUES ('France',2016,300000000),('Germany',2016,350000000),('United Kingdom',2016,400000000),('Italy',2016,280000000),('Spain',2016,330000000); | SELECT AVG(spending) FROM DefenseDiplomacy WHERE nation IN ('France', 'Germany', 'United Kingdom', 'Italy', 'Spain') AND year = 2016; |
Who are the top 5 property co-owners in Vancouver with the most properties? | CREATE TABLE vancouver_owners (id INT,name VARCHAR(50),type VARCHAR(50)); INSERT INTO vancouver_owners (id,name,type) VALUES (1,'John Doe','individual'),(2,'Jane Smith','individual'),(3,'ABC Corp','company'); CREATE TABLE property_co_owners (id INT,property_id INT,owner_id INT); INSERT INTO property_co_owners (id,property_id,owner_id) VALUES (1,1,1),(2,1,2),(3,2,3); CREATE TABLE properties (id INT,owner_id INT); INSERT INTO properties (id,owner_id) VALUES (1,1),(2,3); | SELECT vancouver_owners.name, COUNT(properties.id) AS property_count FROM vancouver_owners INNER JOIN property_co_owners ON vancouver_owners.id = property_co_owners.owner_id INNER JOIN properties ON property_co_owners.property_id = properties.id GROUP BY vancouver_owners.name ORDER BY property_count DESC LIMIT 5; |
How many threat intelligence reports were created in the threat_intel table for each month in 2021? | CREATE TABLE threat_intel (report_date DATE); | SELECT EXTRACT(MONTH FROM report_date), COUNT(*) FROM threat_intel WHERE report_date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY EXTRACT(MONTH FROM report_date); |
Find the top 3 socially responsible lending institutions with the highest average loan amounts, and display their names and average loan amounts. | CREATE TABLE socially_responsible_lending (institution_id INT,institution_name VARCHAR(50),loan_amount DECIMAL(10,2)); INSERT INTO socially_responsible_lending (institution_id,institution_name,loan_amount) VALUES (1,'XYZ Foundation',3000.00),(2,'Green Lending Group',4000.00),(3,'Community Development Fund',5000.00),(4,'Fair Finance Society',2500.00),(5,'Sustainable Bank',6000.00); | SELECT institution_name, AVG(loan_amount) AS avg_loan_amount FROM socially_responsible_lending GROUP BY institution_name ORDER BY avg_loan_amount DESC LIMIT 3; |
What is the industry with the most workers? | CREATE TABLE if not exists industry (industry_id INT,industry_name TEXT,total_workers INT); INSERT INTO industry (industry_id,industry_name,total_workers) VALUES (1,'manufacturing',5000),(2,'technology',7000),(3,'healthcare',6000),(4,'finance',4000),(5,'retail',3000); | SELECT industry_name, MAX(total_workers) FROM industry; |
What is the total exploration cost in the 'ArabianSea' for wells drilled after 2010? | CREATE TABLE WellExplorationCosts (well_id INT,drill_year INT,exploration_cost REAL); INSERT INTO WellExplorationCosts (well_id,drill_year,exploration_cost) VALUES (1,2008,2000000),(2,2012,3000000),(3,2015,1500000); | SELECT SUM(exploration_cost) FROM WellExplorationCosts WHERE region = 'ArabianSea' AND drill_year > 2010 |
What is the maximum nitrogen level and corresponding sample location for soil samples with a pH less than 6.5? | CREATE TABLE soil_samples (id INT,sample_location VARCHAR(50),nitrogen FLOAT,phosphorus FLOAT,potassium FLOAT,pH FLOAT,timestamp TIMESTAMP); INSERT INTO soil_samples (id,sample_location,nitrogen,phosphorus,potassium,pH,timestamp) VALUES (1,'Field 1',0.3,0.2,0.5,6.5,'2022-01-01 10:00:00'); | SELECT sample_location, MAX(nitrogen) FROM soil_samples WHERE pH < 6.5 GROUP BY sample_location HAVING MAX(nitrogen); |
What's the total investment in 'renewable_energy' projects by 'ImpactFirst' before 2022? | CREATE TABLE investments (id INT,investor VARCHAR(255),project_type VARCHAR(255),amount INT,date DATE); INSERT INTO investments (id,investor,project_type,amount,date) VALUES (9,'ImpactFirst','renewable_energy',350000,'2021-10-07'); INSERT INTO investments (id,investor,project_type,amount,date) VALUES (10,'ImpactFirst','wind_farm',650000,'2022-07-27'); INSERT INTO investments (id,investor,project_type,amount,date) VALUES (11,'ImpactFirst','solar_farm',500000,'2020-12-20'); | SELECT SUM(amount) FROM investments WHERE investor = 'ImpactFirst' AND project_type = 'renewable_energy' AND date < '2022-01-01'; |
What is the average salary of developers in the IT department, grouped by their employment status? | CREATE TABLE employees (id INT,name VARCHAR(50),department VARCHAR(50),salary FLOAT,employment_status VARCHAR(50)); INSERT INTO employees (id,name,department,salary,employment_status) VALUES (1,'John Doe','IT',75000.0,'Full-time'),(2,'Jane Smith','IT',80000.0,'Part-time'),(3,'Alice Johnson','IT',90000.0,'Full-time'); CREATE TABLE departments (id INT,name VARCHAR(50),manager VARCHAR(50)); INSERT INTO departments (id,name,manager) VALUES (1,'IT','Alex Brown'); CREATE TABLE positions (id INT,name VARCHAR(50),department VARCHAR(50),salary_range FLOAT(50)); INSERT INTO positions (id,name,department,salary_range) VALUES (1,'Developer','IT',60000.0),(2,'Manager','IT',100000.0); | SELECT employment_status, AVG(salary) FROM employees INNER JOIN positions ON employees.department = positions.department AND employees.name = positions.name WHERE positions.name = 'Developer' GROUP BY employment_status; |
Which countries have the most pollution incidents in the ocean? | CREATE TABLE pollution_incidents (id INT,country VARCHAR(255),incidents INT); INSERT INTO pollution_incidents (id,country,incidents) VALUES (1,'USA',50),(2,'China',80),(3,'Japan',30),(4,'India',60),(5,'Indonesia',70); | SELECT country, SUM(incidents) as total_incidents FROM pollution_incidents GROUP BY country ORDER BY total_incidents DESC; |
Calculate total donations by donor | CREATE TABLE Donations (Id INT,DonorName VARCHAR(50),DonationAmount DECIMAL(10,2),DonationDate DATE); INSERT INTO Donations (Id,DonorName,DonationAmount,DonationDate) VALUES (1,'John Doe',50.00,'2021-01-01'),(2,'Jane Smith',100.00,'2021-01-02'),(3,'John Doe',200.00,'2021-01-03'); | SELECT DonorName, SUM(DonationAmount) OVER(PARTITION BY DonorName) AS TotalDonations FROM Donations; |
List the top 3 sustainable brands by sales in the US. | CREATE TABLE Brands (BrandID INT,BrandName VARCHAR(100),SustainabilityScore INT,TotalSales DECIMAL(10,2)); INSERT INTO Brands (BrandID,BrandName,SustainabilityScore,TotalSales) VALUES (1,'Brand X',85,50000),(2,'Brand Y',92,65000),(3,'Brand Z',78,42000); | SELECT BrandName, SustainabilityScore, TotalSales FROM (SELECT BrandName, SustainabilityScore, TotalSales, ROW_NUMBER() OVER (ORDER BY TotalSales DESC) as rn FROM Brands WHERE Country = 'US') t WHERE rn <= 3; |
Which excavation sites have the highest number of artifacts from the 'Stone Tools' category? | CREATE TABLE excavation_sites_stone_tools (site_id INT,artifact_count INT); INSERT INTO excavation_sites_stone_tools (site_id,artifact_count) VALUES (1,35),(2,28),(3,40); | SELECT site_id FROM excavation_sites_stone_tools WHERE artifact_count = (SELECT MAX(artifact_count) FROM excavation_sites_stone_tools); |
What is the percentage of veteran employment in the defense industry, by job category, for each quarter in the past year? | CREATE TABLE veteran_employment (employment_id INT,employment_date DATE,company TEXT,job_category TEXT,is_veteran BOOLEAN); INSERT INTO veteran_employment (employment_id,employment_date,company,job_category,is_veteran) VALUES (1,'2022-04-01','ACME Inc','Engineering',true),(2,'2022-05-15','Beta Corp','Management',false),(3,'2022-06-30','Gamma Industries','Engineering',true); | SELECT DATE_FORMAT(employment_date, '%Y-%m') as quarter, job_category, ROUND(100.0 * SUM(CASE WHEN is_veteran THEN 1 ELSE 0 END) / COUNT(*), 2) as pct_veteran_employment FROM veteran_employment WHERE employment_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) AND CURRENT_DATE GROUP BY quarter, job_category; |
What was the minimum production yield (in pounds) for the strain 'Girl Scout Cookies' in the state of Washington in 2021? | CREATE TABLE production (id INT,strain VARCHAR(50),state VARCHAR(50),year INT,yield FLOAT); INSERT INTO production (id,strain,state,year,yield) VALUES (1,'OG Kush','Washington',2021,3.5),(2,'Girl Scout Cookies','Washington',2021,4.2),(3,'Sour Diesel','California',2021,3.0); | SELECT MIN(yield) FROM production WHERE strain = 'Girl Scout Cookies' AND state = 'Washington' AND year = 2021; |
What is the total fare collected from passengers with disabilities for train route 203? | CREATE TABLE routes (route_id INT,route_name TEXT); INSERT INTO routes (route_id,route_name) VALUES (101,'Bus Route 101'),(201,'Train Route 201'),(203,'Train Route 203'); CREATE TABLE fare_collection (collection_id INT,passenger_type TEXT,route_id INT,fare DECIMAL); INSERT INTO fare_collection (collection_id,passenger_type,route_id) VALUES (1,'Ambulatory',101),(2,'Wheelchair',101),(3,'Able-bodied',101),(4,'Ambulatory',201),(5,'Wheelchair',201),(6,'Able-bodied',201),(7,'Wheelchair',203),(8,'Able-bodied',203); | SELECT SUM(fare) FROM fare_collection JOIN routes ON fare_collection.route_id = routes.route_id WHERE passenger_type = 'Wheelchair' AND routes.route_name = 'Train Route 203'; |
List all the menu items and their categories | CREATE TABLE menu_items (id INT PRIMARY KEY,name VARCHAR(255),category VARCHAR(255)); CREATE TABLE menu_categories (id INT PRIMARY KEY,name VARCHAR(255)); INSERT INTO menu_categories (id,name) VALUES (1,'Appetizers'),(2,'Entrees'),(3,'Desserts'); INSERT INTO menu_items (id,name,category) VALUES (1,'Bruschetta',1),(2,'Spaghetti',2),(3,'Tiramisu',3); | SELECT menu_items.name, menu_categories.name AS category FROM menu_items JOIN menu_categories ON menu_items.category = menu_categories.id; |
What is the 3-month moving average of military equipment sales by region? | CREATE TABLE military_sales (id INT,sale_date DATE,region VARCHAR(20),equipment_type VARCHAR(30),revenue DECIMAL(10,2)); | SELECT region, AVG(revenue) OVER (PARTITION BY region ORDER BY sale_date ROWS BETWEEN 3 PRECEDING AND CURRENT ROW) as moving_avg FROM military_sales; |
What is the total number of cases handled by attorneys with a success rate greater than 75%? | CREATE TABLE attorney_outcomes (attorney_id INT,total_cases INT,successful_cases INT); INSERT INTO attorney_outcomes (attorney_id,total_cases,successful_cases) VALUES (1,15,12),(2,10,8),(3,8,6); | SELECT SUM(total_cases) FROM attorney_outcomes WHERE successful_cases / total_cases > 0.75; |
Which water conservation initiatives were implemented in California during 2022? | CREATE TABLE WastewaterTreatmentFacilities (FacilityID INT,FacilityName VARCHAR(255),Address VARCHAR(255),City VARCHAR(255),State VARCHAR(255),ZipCode VARCHAR(10)); INSERT INTO WastewaterTreatmentFacilities (FacilityID,FacilityName,Address,City,State,ZipCode) VALUES (1,'Blue Ridge Wastewater Treatment Plant','1200 W Main St','Blue Ridge','GA','30513'),(2,'Greenville Wastewater Treatment Plant','450 Powerhouse Rd','Greenville','SC','29605'),(3,'California Water Treatment Plant','1234 Ocean Blvd','Sacramento','CA','94203'); CREATE TABLE WaterConservationInitiatives (InitiativeID INT,FacilityID INT,InitiativeName VARCHAR(255),InitiativeDescription VARCHAR(255),StartDate DATE,EndDate DATE); INSERT INTO WaterConservationInitiatives (InitiativeID,FacilityID,InitiativeName,InitiativeDescription,StartDate,EndDate) VALUES (1,1,'Water recycling program','Recycling of water for irrigation purposes','2022-01-01','2022-12-31'),(2,3,'Drought-tolerant landscaping','Replacing lawns with drought-tolerant plants','2022-03-15','2022-11-30'); | SELECT InitiativeName FROM WaterConservationInitiatives WHERE FacilityID = 3 AND StartDate <= '2022-12-31' AND EndDate >= '2022-01-01'; |
Identify hotels with a high number of negative reviews in Paris. | CREATE TABLE Hotels (id INT,name TEXT,country TEXT,city TEXT,reviews INT); INSERT INTO Hotels (id,name,country,city,reviews) VALUES (1,'Eco Hotel','France','Paris',-75); | SELECT name FROM Hotels WHERE city = 'Paris' AND reviews < 0 GROUP BY name HAVING COUNT(*) > 1; |
Which tools are provided by Stanley or Bosch? | CREATE TABLE Manufacturing_Tools (id INT PRIMARY KEY,tool_name VARCHAR(100),quantity INT,vendor VARCHAR(100)); INSERT INTO Manufacturing_Tools (id,tool_name,quantity,vendor) VALUES (1,'Drill',5,'Stanley'); INSERT INTO Manufacturing_Tools (id,tool_name,quantity,vendor) VALUES (2,'Wrench',3,'Snap-on'); INSERT INTO Manufacturing_Tools (id,tool_name,quantity,vendor) VALUES (3,'Screwdriver',8,'Makita'); INSERT INTO Manufacturing_Tools (id,tool_name,quantity,vendor) VALUES (4,'Jigsaw',6,'Bosch'); | SELECT * FROM Manufacturing_Tools WHERE vendor IN ('Stanley', 'Bosch'); |
How many defense diplomacy events occurred in South America in 2020? | CREATE TABLE DefenseDiplomacy (id INT PRIMARY KEY,event VARCHAR(100),country VARCHAR(50),year INT,participants INT); INSERT INTO DefenseDiplomacy (id,event,country,year,participants) VALUES (4,'Military Training Exchange','Colombia',2020,15); | SELECT COUNT(*) FROM DefenseDiplomacy WHERE country LIKE '%South America%' AND year = 2020; |
Insert a new record for well 'H08' in 'Siberia' with a production count of 12000. | CREATE TABLE wells (well_id VARCHAR(10),well_location VARCHAR(20)); CREATE TABLE production (well_id VARCHAR(10),production_count INT); | INSERT INTO wells (well_id, well_location) VALUES ('H08', 'Siberia'); INSERT INTO production (well_id, production_count) VALUES ('H08', 12000); |
List the top 5 heaviest packages shipped in May 2022 | CREATE TABLE package_types (id INT,name VARCHAR(255),max_weight FLOAT); INSERT INTO package_types (id,name,max_weight) VALUES (1,'Envelope',1.0),(2,'Small Box',50.0),(3,'Medium Box',100.0),(4,'Large Box',200.0),(5,'Pallet',500.0); | SELECT packages.id, packages.weight, package_types.name FROM packages JOIN package_types ON packages.id = package_types.id WHERE packages.weight IN (SELECT weight FROM (SELECT packages.weight FROM packages JOIN warehouse_routes ON packages.id = warehouse_routes.package_id JOIN warehouses ON warehouse_routes.warehouse_id = warehouses.id JOIN countries ON warehouses.country = countries.name WHERE countries.name = 'United States' AND packages.weight IS NOT NULL GROUP BY packages.weight ORDER BY SUM(packages.weight) DESC LIMIT 5) AS subquery) ORDER BY packages.weight DESC; |
What's the total investment in 'waste_management' projects by 'SustainableFund' in 2021? | CREATE TABLE investments (id INT,investor VARCHAR(255),project_type VARCHAR(255),amount INT,date DATE); INSERT INTO investments (id,investor,project_type,amount,date) VALUES (15,'SustainableFund','waste_management',700000,'2021-08-25'); INSERT INTO investments (id,investor,project_type,amount,date) VALUES (16,'SustainableFund','renewable_energy',500000,'2022-02-16'); INSERT INTO investments (id,investor,project_type,amount,date) VALUES (17,'SustainableFund','solar_farm',600000,'2022-09-12'); | SELECT SUM(amount) FROM investments WHERE investor = 'SustainableFund' AND project_type = 'waste_management' AND date BETWEEN '2021-01-01' AND '2021-12-31'; |
What is the number of cases handled by each judge, in the last quarter? | CREATE TABLE cases_by_judge (case_id INT,judge_id INT,open_date DATE); INSERT INTO cases_by_judge (case_id,judge_id,open_date) VALUES (1,1,'2022-01-05'),(2,2,'2022-03-10'),(3,1,'2022-04-01'); | SELECT cases_by_judge.judge_id, COUNT(*) as num_cases FROM cases_by_judge WHERE open_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH) GROUP BY cases_by_judge.judge_id; |
What are the names of all satellites launched by China? | CREATE TABLE Satellites (Id INT,Name VARCHAR(50),LaunchYear INT,Country VARCHAR(50)); INSERT INTO Satellites (Id,Name,LaunchYear,Country) VALUES (1,'Sat1',2018,'USA'),(2,'Sat2',2019,'USA'),(3,'Sat3',2020,'USA'),(4,'Sat4',2020,'China'),(5,'Sat5',2020,'Russia'),(6,'Sat6',2018,'Germany'),(7,'Sat7',2019,'India'),(8,'Sat8',2020,'India'),(9,'Sat9',2020,'China'),(10,'Sat10',2021,'China'); | SELECT Name FROM Satellites WHERE Country = 'China'; |
What is the average number of kills per game for players from the United States and Canada, partitioned by game mode? | CREATE TABLE PlayerKills (PlayerID INT,GameMode VARCHAR(255),Kills INT,Country VARCHAR(255)); INSERT INTO PlayerKills (PlayerID,GameMode,Kills,Country) VALUES (1,'Capture the Flag',15,'United States'),(2,'Deathmatch',28,'Canada'); | SELECT GameMode, AVG(Kills) as AvgKills FROM PlayerKills WHERE Country IN ('United States', 'Canada') GROUP BY GameMode, Country WITH ROLLUP; |
What is the average landfill capacity (in cubic meters) for countries in the Asia-Pacific region? | CREATE TABLE landfill_data (country VARCHAR(50),capacity FLOAT); INSERT INTO landfill_data (country,capacity) VALUES ('India',1200000),('China',2500000),('Indonesia',800000); | SELECT AVG(capacity) FROM landfill_data WHERE country IN ('India', 'China', 'Indonesia'); |
What is the average number of posts, comments, and reactions for users from the USA and India in the social_media database? | CREATE TABLE users (user_id INT,username VARCHAR(20),email VARCHAR(50),country VARCHAR(20)); CREATE TABLE posts (post_id INT,user_id INT,content TEXT,post_time TIMESTAMP); CREATE TABLE comments (comment_id INT,post_id INT,user_id INT,comment TEXT,comment_time TIMESTAMP); CREATE TABLE reactions (reaction_id INT,post_id INT,user_id INT,reaction VARCHAR(10),reaction_time TIMESTAMP); | SELECT AVG(posts), AVG(comments), AVG(reactions) FROM (SELECT u.country, COUNT(p.post_id) AS posts, COUNT(c.comment_id) AS comments, COUNT(r.reaction_id) AS reactions FROM users u LEFT JOIN posts p ON u.user_id = p.user_id LEFT JOIN comments c ON p.post_id = c.post_id LEFT JOIN reactions r ON p.post_id = r.post_id WHERE u.country IN ('USA', 'India') GROUP BY u.country) sub; |
What is the count of claims for policy number 1004? | CREATE TABLE claims (claim_id INT,policy_id INT); INSERT INTO claims (claim_id,policy_id) VALUES (1,1001),(2,1002),(3,1003),(4,1002),(5,1004),(6,1004); | SELECT COUNT(*) FROM claims WHERE policy_id = 1004; |
Identify military equipment manufacturers in Africa with the highest contract values since 2020. | CREATE TABLE military_equipment_contracts (contract_id INT,equipment_id INT,manufacturer VARCHAR(50),contract_value FLOAT,contract_date DATE); INSERT INTO military_equipment_contracts VALUES (1,1,'Rheinmetall AG',10000000,'2021-05-15'); | SELECT manufacturer, MAX(contract_value) FROM military_equipment_contracts WHERE contract_date >= '2020-01-01' AND country IN (SELECT country FROM countries WHERE region = 'Africa') GROUP BY manufacturer; |
What is the maximum monthly production of Europium from all mines in 2021? | CREATE TABLE mine (id INT,name TEXT,location TEXT,Europium_monthly_production FLOAT,timestamp TIMESTAMP); INSERT INTO mine (id,name,location,Europium_monthly_production,timestamp) VALUES (1,'Australian Mine','Australia',120.5,'2021-03-01'),(2,'Californian Mine','USA',150.3,'2021-03-01'),(3,'Brazilian Mine','Brazil',80.0,'2021-03-01'),(4,'Indian Mine','India',200.5,'2021-03-01'); | SELECT MAX(Europium_monthly_production) FROM mine WHERE EXTRACT(YEAR FROM timestamp) = 2021; |
What is the total cost of accommodations provided to students with physical disabilities in the current academic year? | CREATE TABLE Student_Accommodations (student_id INT,accommodation_type TEXT,cost DECIMAL(5,2),academic_year INT); CREATE VIEW Physical_Disability_Accommodations AS SELECT * FROM Student_Accommodations WHERE accommodation_type LIKE '%physical disability%'; CREATE VIEW Total_Physical_Disability_Accommodations_Cost AS SELECT SUM(cost) FROM Physical_Disability_Accommodations WHERE academic_year = YEAR(CURRENT_DATE); | SELECT Total_Physical_Disability_Accommodations_Cost.SUM(cost) FROM Physical_Disability_Accommodations INNER JOIN Total_Physical_Disability_Accommodations_Cost ON Physical_Disability_Accommodations.accommodation_type = Total_Physical_Disability_Accommodations_Cost.accommodation_type WHERE Physical_Disability_Accommodations.academic_year = YEAR(CURRENT_DATE); |
What is the average year of foundation for manufacturers based in the United States? | CREATE TABLE Manufacturer (id INT,name VARCHAR(255),country VARCHAR(255),year_founded INT); INSERT INTO Manufacturer (id,name,country,year_founded) VALUES (1,'Boeing','USA',1916); INSERT INTO Manufacturer (id,name,country,year_founded) VALUES (2,'Airbus','Europe',1970); INSERT INTO Manufacturer (id,name,country,year_founded) VALUES (3,'Lockheed Martin','USA',1995); | SELECT AVG(year_founded) FROM Manufacturer WHERE country = 'USA'; |
What is the total number of dams and levees in the West and their respective average construction costs? | CREATE TABLE DamLevee (id INT,type VARCHAR(10),region VARCHAR(20),cost FLOAT); INSERT INTO DamLevee (id,type,region,cost) VALUES (1,'Dam','West',15000000.0),(2,'Levee','West',8000000.0),(3,'Dam','West',12000000.0); | SELECT type, COUNT(*), AVG(cost) as avg_cost FROM DamLevee WHERE region = 'West' GROUP BY type; |
Create a table named 'product_education' | CREATE TABLE product_education (product_id INT,educational_material VARCHAR(500)); | CREATE TABLE product_education (product_id INT, educational_material VARCHAR(500)); |
How many users are there from Africa who are older than 30? | CREATE TABLE Users (id INT,age INT,gender VARCHAR(10),country VARCHAR(50)); INSERT INTO Users (id,age,gender,country) VALUES (1,25,'Male','USA'); INSERT INTO Users (id,age,gender,country) VALUES (2,35,'Female','Canada'); INSERT INTO Users (id,age,gender,country) VALUES (3,42,'Male','Nigeria'); | SELECT COUNT(*) FROM Users WHERE country LIKE '%%Africa' AND age > 30; |
What was the minimum cost of 'Transportation' projects in 2020, excluding projects with a duration of more than 1 year? | CREATE TABLE Projects (id INT,name VARCHAR(50),category VARCHAR(50),cost FLOAT,start_date DATE,end_date DATE,status VARCHAR(20)); INSERT INTO Projects (id,name,category,cost,start_date,end_date,status) VALUES (1,'Dam Reconstruction','Water Supply',500000,'2017-04-01','2019-04-01','Completed'),(2,'Wastewater Treatment','Waste Management',600000,'2018-05-01','2020-05-01','Completed'),(3,'Road Pavement','Transportation',700000,'2016-06-01','2018-06-01','Completed'),(4,'Bridge Construction','Transportation',800000,'2018-07-01','2019-07-01','Completed'),(5,'Tunnel Construction','Transportation',900000,'2019-08-01','2021-08-01','In Progress'); | SELECT MIN(cost) FROM Projects WHERE category = 'Transportation' AND YEAR(start_date) = 2020 AND DATEDIFF(end_date, start_date) <= 365; |
What is the total number of humanitarian assistance provided by the African Union in 2021, partitioned by country? | CREATE TABLE HumanitarianAssistance (id INT,year INT,country VARCHAR(255),assistance VARCHAR(255)); | SELECT country, SUM(1) as total_assistance FROM HumanitarianAssistance WHERE year = 2021 AND country IN ('African Union member countries') GROUP BY country; |
Find the average price of sustainable fabric types | CREATE TABLE fabric (type VARCHAR(20),price DECIMAL(5,2),is_sustainable BOOLEAN); INSERT INTO fabric (type,price,is_sustainable) VALUES ('cotton',3.50,true),('polyester',2.50,false),('recycled_polyester',3.00,true); | SELECT AVG(price) FROM fabric WHERE is_sustainable = true; |
Insert a new community health worker in Texas with 2 workers for the Hispanic race/ethnicity? | CREATE TABLE community_health_workers (state VARCHAR(50),race_ethnicity VARCHAR(50),workers INT); | INSERT INTO community_health_workers (state, race_ethnicity, workers) VALUES ('Texas', 'Hispanic', 2); |
List the top 5 countries in South America with the highest greenhouse gas emissions reduction due to climate adaptation projects. | CREATE TABLE greenhouse_gas_emissions (id INT PRIMARY KEY,source_type VARCHAR(50),country VARCHAR(50),year INT,amount DECIMAL(10,2));CREATE TABLE climate_adaptation_projects (id INT PRIMARY KEY,project_type VARCHAR(50),country VARCHAR(50),year INT,reduction DECIMAL(10,2));CREATE VIEW v_south_american_adaptation_projects AS SELECT cap.project_type,cap.country,SUM(cap.reduction) AS total_reduction FROM climate_adaptation_projects cap WHERE cap.country LIKE 'South America%' GROUP BY cap.project_type,cap.country;CREATE VIEW v_ghg_reductions AS SELECT ghe.source_type,ghe.country,SUM(ghe.amount) * -1 AS total_reduction FROM greenhouse_gas_emissions ghe JOIN v_south_american_adaptation_projects sap ON ghe.country = sap.country WHERE ghe.source_type = 'Greenhouse Gas' GROUP BY ghe.source_type,ghe.country; | SELECT country, total_reduction FROM v_ghg_reductions WHERE source_type = 'Greenhouse Gas' ORDER BY total_reduction DESC LIMIT 5; |
What is the maximum temperature in field J in the past week? | CREATE TABLE Temperature (field VARCHAR(50),date DATE,temperature FLOAT); INSERT INTO Temperature (field,date,temperature) VALUES ('Field J','2022-06-01',30.1),('Field J','2022-06-02',32.6),('Field J','2022-06-03',28.3); | SELECT MAX(temperature) FROM Temperature WHERE field = 'Field J' AND date >= DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY); |
What is the total number of shelters constructed in "North America" in 2019? | CREATE TABLE shelters (id INT,project_id INT,location VARCHAR(255),construction_date DATE); INSERT INTO shelters (id,project_id,location,construction_date) VALUES (1,10001,'USA','2019-05-01'); INSERT INTO shelters (id,project_id,location,construction_date) VALUES (2,10002,'Canada','2019-02-01'); | SELECT COUNT(*) FROM shelters WHERE location = 'North America' AND YEAR(construction_date) = 2019; |
What is the minimum expression level for gene 'MNO' across all samples? | CREATE SCHEMA if not exists genetics; USE genetics; CREATE TABLE if not exists gene_expression (sample_id INT,gene_name VARCHAR(255),expression DECIMAL(5,2)); INSERT INTO gene_expression (sample_id,gene_name,expression) VALUES (1,'ABC',3.45),(2,'ABC',3.56),(3,'MNO',1.23),(4,'DEF',2.98),(5,'MNO',0.98),(6,'GHI',4.02); | SELECT MIN(expression) FROM genetics.gene_expression WHERE gene_name = 'MNO'; |
What is the total amount of funding received by events in the 'Dance' category from 'Private Donations'? | CREATE TABLE Events (EventID INT,EventName VARCHAR(20),EventCategory VARCHAR(20));CREATE TABLE FundingSources (FundingSourceID INT,FundingSourceName VARCHAR(20));CREATE TABLE EventFunding (EventID INT,FundingSourceID INT,FundingAmount INT); | SELECT SUM(EF.FundingAmount) AS Total_Funding_Received FROM Events E INNER JOIN EventFunding EF ON E.EventID = EF.EventID INNER JOIN FundingSources FS ON EF.FundingSourceID = FS.FundingSourceID WHERE E.EventCategory = 'Dance' AND FS.FundingSourceName = 'Private Donations'; |
Identify the menu item with the highest price from the "menu_items" table. | CREATE TABLE menu_items (id INT,restaurant_id INT,name VARCHAR(255),category VARCHAR(255),price DECIMAL(5,2)); INSERT INTO menu_items (id,restaurant_id,name,category,price) VALUES (1,1,'Quinoa Salad','Salads',15.99),(2,1,'Grilled Chicken Sandwich','Sandwiches',12.49),(3,2,'Cheeseburger','Burgers',8.99),(4,2,'Veggie Wrap','Wraps',9.99),(5,3,'Spaghetti Bolognese','Pastas',16.99); | SELECT name, MAX(price) FROM menu_items; |
What is the average revenue per OTA booking in 'Asia'? | CREATE TABLE ota_bookings (booking_id INT,hotel_name TEXT,region TEXT,revenue FLOAT); INSERT INTO ota_bookings (booking_id,hotel_name,region,revenue) VALUES (1,'Hotel Q','Asia',600),(2,'Hotel R','Asia',800),(3,'Hotel S','Asia',500); | SELECT AVG(revenue) FROM ota_bookings WHERE region = 'Asia'; |
List the bottom 2 countries with the lowest average salary in the 'Finance' job category, including the average salary for that job category in each country? | CREATE TABLE Employees (EmployeeID int,EmployeeName varchar(50),JobCategory varchar(50),Salary decimal(10,2),Gender varchar(10),Country varchar(50)); INSERT INTO Employees (EmployeeID,EmployeeName,JobCategory,Salary,Gender,Country) VALUES (1,'Jasmine White','IT',85000.00,'Female','USA'),(2,'Kai Johnson','IT',90000.00,'Male','USA'),(3,'Leah Lewis','HR',70000.00,'Female','UK'),(4,'Nathan Kim','HR',75000.00,'Male','UK'),(5,'Zara Ahmed','Finance',95000.00,'Female','Canada'),(6,'Hamza Ali','Finance',80000.00,'Male','Pakistan'),(7,'Sophia Patel','Finance',85000.00,'Female','India'); | SELECT Country, AVG(Salary) AS avg_salary FROM Employees WHERE JobCategory = 'Finance' GROUP BY Country ORDER BY avg_salary, Country LIMIT 2; |
What is the total number of power outages in Florida in 2019, categorized by outage cause and power restoration time? | CREATE TABLE Outages (id INT,state VARCHAR(2),year INT,outage_cause VARCHAR(10),power_restoration_time TIME,count INT); INSERT INTO Outages (id,state,year,outage_cause,power_restoration_time,count) VALUES (1,'FL',2019,'Hurricane','2H',20),(2,'FL',2019,'Equipment Failure','30M',30),(3,'FL',2019,'Hurricane','12H',10); | SELECT outage_cause, power_restoration_time, SUM(count) FROM Outages WHERE state = 'FL' AND year = 2019 GROUP BY outage_cause, power_restoration_time; |
What is the latest launch date for each space agency? | CREATE TABLE launches (id INT,agency_id INT,launch_date DATE); CREATE TABLE space_agencies (id INT,name VARCHAR(50)); | SELECT a.name, MAX(l.launch_date) FROM launches l JOIN space_agencies a ON l.agency_id = a.id GROUP BY a.name; |
Who are the top 5 most frequent providers of support programs for students with physical disabilities? | CREATE TABLE SupportProgramProviders (ProgramID INT,ProviderName VARCHAR(50),DisabilityType VARCHAR(50)); | SELECT ProviderName, COUNT(ProgramID) as ProgramCount FROM SupportProgramProviders WHERE DisabilityType = 'physical disability' GROUP BY ProviderName ORDER BY ProgramCount DESC LIMIT 5; |
What is the average rating of movies produced in the US and released between 2015 and 2020? | CREATE TABLE movies (title VARCHAR(255),release_year INT,rating DECIMAL(3,2),production_country VARCHAR(50)); | SELECT AVG(rating) FROM movies WHERE production_country = 'United States' AND release_year BETWEEN 2015 AND 2020; |
What is the total wastewater treated in European Union countries? | CREATE TABLE eu_countries (country VARCHAR(255),wastewater_treated INT); INSERT INTO eu_countries (country,wastewater_treated) VALUES ('Germany',2000000),('France',3000000),('Italy',4000000); | SELECT SUM(wastewater_treated) FROM eu_countries; |
What is the average production quantity of Neodymium in 2020 from the 'mining' and 'recycling' sources? | CREATE TABLE mining (year INT,element VARCHAR(10),quantity INT); INSERT INTO mining VALUES (2020,'Neodymium',1200); CREATE TABLE recycling (year INT,element VARCHAR(10),quantity INT); INSERT INTO recycling VALUES (2020,'Neodymium',800); | SELECT AVG(quantity) FROM (SELECT quantity FROM mining WHERE element = 'Neodymium' AND year = 2020 UNION ALL SELECT quantity FROM recycling WHERE element = 'Neodymium' AND year = 2020) AS total |
What is the total revenue generated by music festivals in Asia in 2023? | CREATE TABLE Festivals (id INT,name VARCHAR(50),country VARCHAR(50),year INT,revenue INT); INSERT INTO Festivals (id,name,country,year,revenue) VALUES (1,'Summer Sonic','Japan',2023,4000000),(2,'ZoukOut','Singapore',2023,3000000),(3,'Ultra','Miami',2023,5000000),(4,'Ultra','Seoul',2023,6000000); | SELECT SUM(revenue) FROM Festivals WHERE country IN ('Japan', 'Singapore', 'Seoul') AND year = 2023; |
What is the total number of products in the 'sustainable_products' table that are certified by the 'certified_products' table? | CREATE TABLE sustainable_products (product_id INT,category VARCHAR(255),price DECIMAL(10,2),recycled BOOLEAN,certified_by INT);CREATE TABLE certified_products (certification_id INT,name VARCHAR(255)); | SELECT COUNT(*) FROM sustainable_products WHERE certified_by IS NOT NULL; |
What is the average severity of vulnerabilities found in the last quarter, grouped by month? | CREATE TABLE vulnerabilities(id INT,timestamp TIMESTAMP,severity FLOAT); | SELECT DATE_FORMAT(timestamp, '%Y-%m') as month, AVG(severity) as avg_severity FROM vulnerabilities WHERE timestamp >= NOW() - INTERVAL 3 MONTH GROUP BY month; |
What is the maximum carbon sequestration rate for each tree species? | CREATE TABLE TreeSpecies (id INT,name VARCHAR(255)); INSERT INTO TreeSpecies (id,name) VALUES (1,'Pine'),(2,'Oak'),(3,'Maple'),(4,'Birch'); CREATE TABLE CarbonSeq (id INT,tree_species_id INT,year INT,rate FLOAT); INSERT INTO CarbonSeq (id,tree_species_id,year,rate) VALUES (1,1,2000,2.5),(2,1,2001,3.0),(3,2,2000,4.0),(4,2,2001,4.5),(5,3,2000,3.5),(6,3,2001,4.0),(7,4,2000,4.5),(8,4,2001,5.0); | SELECT ts.id, ts.name, MAX(cs.rate) AS max_carbon_sequestration_rate FROM TreeSpecies ts JOIN CarbonSeq cs ON ts.id = cs.tree_species_id GROUP BY ts.id; |
List all excavation sites and the number of artifacts associated with each site. | CREATE TABLE excavation_sites (id INT,site_name VARCHAR(50),location VARCHAR(50),num_artifacts INT); INSERT INTO excavation_sites (id,site_name,location,num_artifacts) VALUES (1,'Site A','USA',30),(2,'Site B','Mexico',45),(3,'Site C','Canada',25); | SELECT site_name, num_artifacts FROM excavation_sites; |
Delete all records from table regulatory_compliance with regulation_id 201 | CREATE TABLE regulatory_compliance (id INT PRIMARY KEY,cargo_id INT,regulation_id INT); INSERT INTO regulatory_compliance (id,cargo_id,regulation_id) VALUES (1,101,201); | DELETE FROM regulatory_compliance WHERE regulation_id = 201; |
Delete all records from the 'renewable_energy_projects' table where the 'initiator' is 'SolarPioneers' | CREATE TABLE renewable_energy_projects (id INT,project_type VARCHAR(255),initiator VARCHAR(255),initiated_year INT,capacity FLOAT); | DELETE FROM renewable_energy_projects WHERE initiator = 'SolarPioneers'; |
What is the total claim amount per policy type, quarter, and region? | CREATE TABLE Claims (ClaimID INT,PolicyID INT,ClaimAmount DECIMAL(10,2),ClaimDate DATE,Region VARCHAR(255)); INSERT INTO Claims VALUES (1,1,500,'2021-01-05','East'),(2,2,1000,'2022-02-10','West'),(3,3,750,'2021-03-15','Central'),(4,4,1200,'2022-01-25','East'),(5,5,300,'2021-02-01','West'),(6,6,1500,'2022-03-01','Central'); | SELECT PolicyType, Region, EXTRACT(QUARTER FROM ClaimDate) AS Quarter, SUM(ClaimAmount) AS TotalClaimAmount FROM Claims GROUP BY PolicyType, Region, Quarter; |
How many green-certified buildings are there in each borough? | CREATE TABLE Boroughs (name VARCHAR(50),green_certified INT); INSERT INTO Boroughs (name,green_certified) VALUES ('Manhattan',150),('Brooklyn',200),('Queens',120); | SELECT name, green_certified FROM Boroughs; |
Determine the number of rural clinics that have seen an increase in patient volume in the past year. | CREATE TABLE clinics (id INT,patient_volume INT,location VARCHAR(20),year INT); INSERT INTO clinics (id,patient_volume,location,year) VALUES (1,500,'rural',2021),(2,200,'urban',2021),(3,750,'rural',2020),(4,600,'rural',2019); | SELECT COUNT(*) FROM clinics WHERE location LIKE '%rural%' AND patient_volume > (SELECT patient_volume FROM clinics WHERE location = 'rural' AND year = YEAR(GETDATE()) - 1); |
What is the maximum amount of humanitarian assistance provided by the United States to any country in 2020? | CREATE TABLE humanitarian_assistance (country VARCHAR(50),year INT,amount INT); INSERT INTO humanitarian_assistance (country,year,amount) VALUES ('Syria',2018,1000000),('Yemen',2019,1500000),('Syria',2020,2000000),('Yemen',2020,1200000); | SELECT MAX(amount) FROM humanitarian_assistance WHERE country = 'Syria' AND year = 2020; |
What is the average number of streams for artist 'Dua Lipa' in Canada? | CREATE TABLE Streams (id INT,artist VARCHAR(100),country VARCHAR(100),streams INT); INSERT INTO Streams (id,artist,country,streams) VALUES (1,'Dua Lipa','Canada',700000),(2,'Dua Lipa','Canada',800000); | SELECT AVG(streams) FROM Streams WHERE artist = 'Dua Lipa' AND country = 'Canada' |
What is the total revenue for each salesperson, ordered by total revenue? | CREATE TABLE salesperson (id INT,name VARCHAR(50),revenue DECIMAL(10,2)); INSERT INTO salesperson (id,name,revenue) VALUES (1,'John Doe',5000.00),(2,'Jane Smith',7000.00); | SELECT name, SUM(revenue) as total_revenue FROM salesperson GROUP BY name ORDER BY total_revenue DESC; |
What is the average rating of products manufactured in the USA? | CREATE TABLE products (product_id INT,name VARCHAR(255),manufacturer_country VARCHAR(50)); INSERT INTO products (product_id,name,manufacturer_country) VALUES (1,'T-Shirt','USA'),(2,'Jeans','India'); | SELECT AVG(rating) FROM products JOIN product_reviews ON products.product_id = product_reviews.product_id WHERE manufacturer_country = 'USA'; |
How many vessels from Nigeria have been to the Mediterranean sea in the past month? | CREATE TABLE vessels(id INT,name VARCHAR(50),country VARCHAR(50)); CREATE TABLE vessel_locations(id INT,vessel_id INT,location VARCHAR(50),timestamp TIMESTAMP); | SELECT COUNT(DISTINCT vessels.id) FROM vessels JOIN vessel_locations ON vessels.id = vessel_locations.vessel_id WHERE vessels.country = 'Nigeria' AND location LIKE '%Mediterranean%' AND timestamp > DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) |
What is the maximum cargo weight for each ship? | CREATE TABLE ship (id INT PRIMARY KEY,name VARCHAR(50),type VARCHAR(50),length INT,port_id INT,FOREIGN KEY (port_id) REFERENCES port(id)); INSERT INTO ship VALUES (1,'Sea Giant','Container',300,1); INSERT INTO ship VALUES (2,'Ocean Titan','Tanker',400,2); CREATE TABLE cargo (id INT PRIMARY KEY,ship_id INT,weight INT,FOREIGN KEY (ship_id) REFERENCES ship(id)); INSERT INTO cargo VALUES (1,1,1000); INSERT INTO cargo VALUES (2,2,2000); INSERT INTO cargo VALUES (3,1,1500); | SELECT s.name as ship_name, MAX(c.weight) as max_weight FROM cargo c JOIN ship s ON c.ship_id = s.id GROUP BY s.name; |
List the top 3 most active movie production companies in Asia based on the number of movies released since 2000? | CREATE TABLE movies (id INT,title VARCHAR(255),release_year INT,production_company VARCHAR(100)); INSERT INTO movies (id,title,release_year,production_company) VALUES (1,'Movie1',2005,'CompanyA'),(2,'Movie2',2002,'CompanyB'),(3,'Movie3',2018,'CompanyA'); | SELECT production_company, COUNT(*) as num_movies FROM movies WHERE release_year >= 2000 AND production_company IN (SELECT production_company FROM movies WHERE release_year >= 2000 GROUP BY production_company HAVING COUNT(*) > 2) GROUP BY production_company ORDER BY num_movies DESC LIMIT 3; |
How many drug approvals were granted in the EU in Q3 2018? | CREATE TABLE drug_approvals (region TEXT,quarter TEXT,year INTEGER,num_approvals INTEGER); INSERT INTO drug_approvals (region,quarter,year,num_approvals) VALUES ('EU','Q3',2018,50); | SELECT SUM(num_approvals) FROM drug_approvals WHERE region = 'EU' AND quarter = 'Q3' AND year = 2018; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.