instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
What is the total number of security incidents in the last year that involved a user from a department that has more than 50 users? | CREATE TABLE security_incidents (incident_id INT,incident_date DATE,user_id INT);CREATE TABLE users (user_id INT,user_name VARCHAR(255),department VARCHAR(255),department_size INT); | SELECT COUNT(*) FROM security_incidents si JOIN users u ON si.user_id = u.user_id WHERE incident_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) AND u.department_size > 50; |
What was the daily average speed of autonomous taxis in New York for the last week? | CREATE TABLE taxi_speeds (id INT,taxi_id INT,taxi_type VARCHAR(20),speed FLOAT,date DATE,city VARCHAR(20)); INSERT INTO taxi_speeds (id,taxi_id,taxi_type,speed,date,city) VALUES (1,101,'Autonomous',70.5,'2022-05-01','New York'); INSERT INTO taxi_speeds (id,taxi_id,taxi_type,speed,date,city) VALUES (2,102,'Autonomous',72.1,'2022-05-01','New York'); INSERT INTO taxi_speeds (id,taxi_id,taxi_type,speed,date,city) VALUES (3,103,'Conventional',68.7,'2022-05-01','New York'); | SELECT DATE(date) as trip_date, AVG(speed) as avg_speed FROM taxi_speeds WHERE taxi_type = 'Autonomous' AND city = 'New York' AND date BETWEEN DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND CURDATE() GROUP BY trip_date ORDER BY trip_date; |
What is the sum of claim amounts paid to policyholders in 'Utah' and 'Idaho'? | CREATE TABLE claims (policyholder_id INT,claim_amount DECIMAL(10,2),policyholder_state VARCHAR(20)); INSERT INTO claims (policyholder_id,claim_amount,policyholder_state) VALUES (1,500.00,'Utah'),(2,300.00,'Idaho'),(3,700.00,'Utah'); | SELECT SUM(claim_amount) FROM claims WHERE policyholder_state IN ('Utah', 'Idaho'); |
Who are the top 3 underwriters with the highest claim amount in the Midwest region? | CREATE TABLE Claims (ClaimID INT,UnderwriterID INT,Amount DECIMAL(10,2)); CREATE TABLE Underwriters (UnderwriterID INT,Region VARCHAR(20)); INSERT INTO Claims (ClaimID,UnderwriterID,Amount) VALUES (1,1,500),(2,2,300),(3,4,1000),(4,1,700); INSERT INTO Underwriters (UnderwriterID,Region) VALUES (1,'Midwest'),(2,'Northeast'),(3,'South'),(4,'Midwest'); | SELECT Underwriters.UnderwriterID, Underwriters.Region, SUM(Claims.Amount) AS TotalClaimAmount FROM Claims INNER JOIN Underwriters ON Claims.UnderwriterID = Underwriters.UnderwriterID WHERE Underwriters.Region = 'Midwest' GROUP BY Underwriters.UnderwriterID, Underwriters.Region ORDER BY TotalClaimAmount DESC LIMIT 3; |
What is the percentage of workplaces with no reported injuries in each region? | CREATE TABLE workplaces (id INT,workplace_name VARCHAR(255),region VARCHAR(255)); INSERT INTO workplaces (id,workplace_name,region) VALUES (1,'Workplace A','Western'),(2,'Workplace B','Western'),(3,'Workplace C','Eastern'); CREATE TABLE injuries (id INT,workplace_id INT,injury_count INT); INSERT INTO injuries (id,workplace_id,injury_count) VALUES (1,1,0),(2,1,0),(3,2,1),(4,3,5); | SELECT w.region, 100.0 * AVG(CASE WHEN i.injury_count = 0 THEN 1 ELSE 0 END) as pct_no_injuries FROM workplaces w LEFT JOIN injuries i ON w.id = i.workplace_id GROUP BY w.region; |
Delete all vehicle safety testing records for vehicles released before 2010. | CREATE TABLE VehicleSafetyTesting (id INT,vehicle_name VARCHAR(50),release_year INT); INSERT INTO VehicleSafetyTesting (id,vehicle_name,release_year) VALUES (1,'Car A',2005); INSERT INTO VehicleSafetyTesting (id,vehicle_name,release_year) VALUES (2,'Car B',2012); | DELETE FROM VehicleSafetyTesting WHERE release_year < 2010; |
What is the average speed of vessels that arrived in the US East Coast ports in July 2021? | CREATE TABLE ports (id INT,name TEXT,country TEXT); INSERT INTO ports (id,name,country) VALUES (1,'New York','USA'),(2,'Savannah','USA'),(3,'Norfolk','USA'); CREATE TABLE vessels (id INT,name TEXT,type TEXT,speed FLOAT,port_id INT); INSERT INTO vessels (id,name,type,speed,port_id) VALUES (1,'MSC Georgia','Container',22.5,1),(2,'Ever Given','Container',20.0,2),(3,'Maersk Mc-Kinney Moller','Container',23.0,3); | SELECT AVG(speed) FROM vessels WHERE port_id IN (SELECT id FROM ports WHERE country = 'USA' AND name IN ('New York', 'Savannah', 'Norfolk')) AND EXTRACT(MONTH FROM arrival_date) = 7; |
What is the total fine amount for each vessel in the 'regulatory_compliance' table? | CREATE TABLE regulatory_compliance (vessel_id INT,fine_type VARCHAR(50),amount FLOAT,timestamp TIMESTAMP); | SELECT vessel_id, SUM(amount) FROM regulatory_compliance GROUP BY vessel_id; |
What are the recycling rates in Oceania for the year 2021, grouped by country? | CREATE TABLE RecyclingRatesOceania (country VARCHAR(50),year INT,recycling_rate DECIMAL(5,2)); INSERT INTO RecyclingRatesOceania (country,year,recycling_rate) VALUES ('Australia',2021,0.58),('New Zealand',2021,0.52); | SELECT country, AVG(recycling_rate) FROM RecyclingRatesOceania WHERE year = 2021 GROUP BY country; |
Who are the top 3 contributors to AI safety research? | CREATE TABLE safety_research (researcher_name TEXT,contributions INTEGER); INSERT INTO safety_research (researcher_name,contributions) VALUES ('Researcher A',15),('Researcher B',20),('Researcher C',25),('Researcher D',10); | SELECT researcher_name FROM safety_research ORDER BY contributions DESC LIMIT 3; |
Calculate the total cost of rural infrastructure projects in India that were completed in 2021 and 2022. | CREATE TABLE infrastructure_projects (id INT,name TEXT,country TEXT,completion_year INT,cost INT); INSERT INTO infrastructure_projects (id,name,country,completion_year,cost) VALUES (1,'Road Construction','India',2021,1000000),(2,'Bridge Building','India',2022,1500000); | SELECT SUM(cost) FROM infrastructure_projects WHERE country = 'India' AND completion_year BETWEEN 2021 AND 2022; |
List the names and total investments in rural infrastructure projects for Latinx communities in the United States. | CREATE TABLE rural_infrastructure_projects (id INT,community_type VARCHAR(30),country VARCHAR(20),investment DECIMAL(10,2)); INSERT INTO rural_infrastructure_projects (id,community_type,country,investment) VALUES (1,'Latinx','United States',35000.00),(2,'African American','United States',40000.00); | SELECT country, SUM(investment) FROM rural_infrastructure_projects WHERE community_type = 'Latinx' GROUP BY country; |
Who are the top 5 agricultural innovation projects in Indonesia by budget allocated? | CREATE TABLE innovation_projects (id INT,project_id INT,country VARCHAR(50),project VARCHAR(50),budget DECIMAL(10,2),start_date DATE,end_date DATE); INSERT INTO innovation_projects (id,project_id,country,project,budget,start_date,end_date) VALUES (1,7001,'Indonesia','Precision Agriculture',50000.00,'2021-01-01','2023-12-31'),(2,7002,'Indonesia','Vertical Farming',75000.00,'2022-06-01','2024-05-31'); | SELECT project_id, budget FROM innovation_projects WHERE country = 'Indonesia' GROUP BY project_id ORDER BY budget DESC LIMIT 5; |
Calculate the biomass of fish in the Salmon farm by weight and date | CREATE TABLE FishBiomass (fish_id INT,farm_id INT,weight DECIMAL(5,2),date DATE); INSERT INTO FishBiomass (fish_id,farm_id,weight,date) VALUES (201,2,0.6,'2022-01-01'),(202,2,0.7,'2022-01-02'); | SELECT farm_id, SUM(weight) over (partition by farm_id order by date) biomass FROM FishBiomass WHERE farm_id = 2; |
What is the maximum donation amount in the "dance_sponsors" table? | CREATE TABLE dance_sponsors (sponsor_id INT,donation_amount FLOAT,donation_date DATE); INSERT INTO dance_sponsors (sponsor_id,donation_amount,donation_date) VALUES (1,1000.00,'2021-01-01'),(2,1200.00,'2021-02-01'),(3,800.00,'2021-03-01'); | SELECT MAX(donation_amount) FROM dance_sponsors; |
What was the average donation amount by new donors in Q2 2021? | CREATE TABLE Donors (DonorID int,DonationDate date,DonationAmount numeric); | SELECT AVG(DonationAmount) FROM (SELECT DonationAmount FROM Donors WHERE DonationDate BETWEEN '2021-04-01' AND '2021-06-30' AND DonorID NOT IN (SELECT DonorID FROM Donors WHERE DonationDate < '2021-04-01')) AS NewDonors; |
What is the total construction cost for sustainable building projects in Texas in Q2 2022? | CREATE TABLE Projects (project_id INT,state VARCHAR(255),is_sustainable BOOLEAN,cost FLOAT); INSERT INTO Projects (project_id,state,is_sustainable,cost) VALUES (1,'Texas',true,500000),(2,'Texas',false,700000); | SELECT SUM(cost) FROM Projects WHERE state = 'Texas' AND is_sustainable = true AND QUARTER(start_date) = 2 AND YEAR(start_date) = 2022 GROUP BY state; |
How many cases did attorney Rodriguez win in Texas in 2020? | CREATE TABLE cases (id INT,attorney VARCHAR(255),state VARCHAR(255),outcome VARCHAR(255),date DATE); INSERT INTO cases (id,attorney,state,outcome,date) VALUES (1,'Rodriguez','Texas','won','2020-01-01'),(2,'Rodriguez','Texas','lost','2020-02-01'),(3,'Rodriguez','California','won','2020-03-01'); | SELECT COUNT(*) FROM cases WHERE attorney = 'Rodriguez' AND state = 'Texas' AND outcome = 'won' AND date BETWEEN '2020-01-01' AND '2020-12-31'; |
Delete the records of waste production for the 'Antarctica' region in January 2022. | CREATE TABLE waste_production (region varchar(20),waste_amount int,date date); | DELETE FROM waste_production WHERE region = 'Antarctica' AND date = '2022-01-01'; |
What are the average emission levels of factories in California? | CREATE TABLE factories (factory_id INT,name TEXT,location TEXT,emissions INT); INSERT INTO factories (factory_id,name,location,emissions) VALUES (1,'Factory A','California',100),(2,'Factory B','Texas',200),(3,'Factory C','California',150); | SELECT AVG(f.emissions) FROM factories f WHERE f.location = 'California'; |
What safety protocols are unique to 'Plant A', 'Plant B', and 'Plant C'? | CREATE TABLE Plant_A_Safety_Protocols (Protocol VARCHAR(255)); INSERT INTO Plant_A_Safety_Protocols (Protocol) VALUES ('PPE'),('Emergency Drills'),('Chemical Spill Response'); CREATE TABLE Plant_B_Safety_Protocols (Protocol VARCHAR(255)); INSERT INTO Plant_B_Safety_Protocols (Protocol) VALUES ('PPE'),('Fire Safety'),('Hazard Communication'); CREATE TABLE Plant_C_Safety_Protocols (Protocol VARCHAR(255)); INSERT INTO Plant_C_Safety_Protocols (Protocol) VALUES ('Radiation Protection'),('Biohazard Protection'),('Chemical Spill Response'); | (SELECT Protocol FROM Plant_A_Safety_Protocols EXCEPT SELECT Protocol FROM Plant_B_Safety_Protocols) UNION (SELECT Protocol FROM Plant_B_Safety_Protocols EXCEPT SELECT Protocol FROM Plant_C_Safety_Protocols) UNION (SELECT Protocol FROM Plant_C_Safety_Protocols EXCEPT SELECT Protocol FROM Plant_A_Safety_Protocols); |
What is the total amount of climate finance provided to projects in Africa between 2015 and 2020, grouped by the type of finance? | CREATE TABLE climate_finance (id INT,project_location VARCHAR(20),finance_type VARCHAR(20),amount INT,finance_year INT); INSERT INTO climate_finance (id,project_location,finance_type,amount,finance_year) VALUES (1,'Africa','Government Grants',500000,2015),(2,'Africa','Private Investments',750000,2015),(3,'Africa','Government Grants',600000,2016),(4,'Africa','Private Investments',800000,2016); | SELECT finance_type, SUM(amount) FROM climate_finance WHERE project_location = 'Africa' AND finance_year BETWEEN 2015 AND 2020 GROUP BY finance_type; |
Which cities have a higher average temperature in the "Finance" scheme than in the "Mitigation" scheme? | CREATE TABLE Mitigation (city VARCHAR(255),avg_temp FLOAT); INSERT INTO Mitigation VALUES ('CityA',20.5),('CityB',22.3); CREATE TABLE Finance (city VARCHAR(255),avg_temp FLOAT); INSERT INTO Finance VALUES ('CityA',23.0),('CityX',23.5); | SELECT Finance.city FROM Finance, Mitigation WHERE Finance.city = Mitigation.city AND Finance.avg_temp > Mitigation.avg_temp |
What is the average life expectancy in Africa? | CREATE TABLE Countries (CountryName TEXT,Continent TEXT,LifeExpectancy FLOAT); INSERT INTO Countries (CountryName,Continent,LifeExpectancy) VALUES ('Afghanistan','Asia',65.0),('Albania','Europe',78.7),('Algeria','Africa',76.3); | SELECT AVG(LifeExpectancy) FROM Countries WHERE Continent = 'Africa'; |
Insert data into 'student_disability' table | CREATE TABLE student_disability (id INT PRIMARY KEY,student_name VARCHAR(100),disability_type VARCHAR(50),accommodation_provided VARCHAR(50)); INSERT INTO student_disability (id,student_name,disability_type,accommodation_provided) VALUES (1,'John Doe','Visual Impairment','Screen Reader'),(2,'Jane Smith','Hearing Impairment','Sign Language Interpreter'); | INSERT INTO student_disability (id, student_name, disability_type, accommodation_provided) VALUES (3, 'Jim Brown', 'Mobility Impairment', 'Wheelchair Access'), (4, 'Jake White', 'Learning Disability', 'Extra Time for Exams'); |
Update the climate_change table to reflect a decrease in ocean temperatures for the Arctic Ocean | CREATE TABLE climate_change (id INT PRIMARY KEY,region VARCHAR(255),avg_temp_celsius DECIMAL(5,2),avg_temp_fahrenheit DECIMAL(5,2),year INT); | UPDATE climate_change SET avg_temp_celsius = avg_temp_celsius - 0.2, avg_temp_fahrenheit = avg_temp_fahrenheit - 0.36 WHERE region = 'Arctic Ocean'; |
Show the transaction history for a specific user '0x456...'. | CREATE TABLE transactions (hash VARCHAR(64),value INT,timestamp TIMESTAMP,user_address VARCHAR(64)); | SELECT hash, value, timestamp FROM transactions WHERE user_address = '0x456...'; |
Which regulatory frameworks have been implemented in 'Country1'? | CREATE TABLE countries (id INT,name VARCHAR(255)); INSERT INTO countries (id,name) VALUES (1,'Country1'); CREATE TABLE regulatory_frameworks (id INT,country_id INT,name VARCHAR(255)); INSERT INTO regulatory_frameworks (id,country_id,name) VALUES (1,1,'Framework1'); INSERT INTO regulatory_frameworks (id,country_id,name) VALUES (2,1,'Framework2'); INSERT INTO regulatory_frameworks (id,country_id,name) VALUES (3,1,'Framework3'); | SELECT name FROM regulatory_frameworks WHERE country_id = (SELECT id FROM countries WHERE name = 'Country1'); |
What is the total number of organic and non-organic products? | CREATE TABLE products_organic (id INT,product_name TEXT,organic BOOLEAN); INSERT INTO products_organic (id,product_name,organic) VALUES (1,'Lotion',true),(2,'Shampoo',false),(3,'Soap',true); | SELECT organic, COUNT(*) FROM products_organic GROUP BY organic; |
What is the average price of vegan cosmetics in the US? | CREATE TABLE cosmetics (product_id INT,product_name VARCHAR(50),is_vegan BOOLEAN,price FLOAT,country VARCHAR(50)); | SELECT AVG(price) FROM cosmetics WHERE is_vegan = TRUE AND country = 'USA'; |
What is the percentage of lipsticks that are vegan and gluten-free? | CREATE TABLE lipsticks (lipstick_id INT,name VARCHAR(255),is_vegan BOOLEAN,is_gluten_free BOOLEAN); | SELECT (COUNT(*) FILTER (WHERE is_vegan = TRUE AND is_gluten_free = TRUE)) * 100.0 / COUNT(*) FROM lipsticks; |
What is the percentage of sustainable haircare products sold in France in Q3 2021? | CREATE TABLE haircare_sales (sale_id INT,product_id INT,sale_quantity INT,is_sustainable BOOLEAN,sale_date DATE,country VARCHAR(20)); INSERT INTO haircare_sales VALUES (1,45,6,true,'2021-07-29','France'); INSERT INTO haircare_sales VALUES (2,46,3,false,'2021-07-29','France'); | SELECT ROUND((SUM(CASE WHEN is_sustainable = true THEN sale_quantity ELSE 0 END) / SUM(sale_quantity)) * 100, 2) FROM haircare_sales WHERE sale_date BETWEEN '2021-07-01' AND '2021-09-30' AND country = 'France'; |
Which brands have the most highly-rated cruelty-free makeup products? | CREATE TABLE brands (brand_id INT,brand_name VARCHAR(255)); CREATE TABLE products (product_id INT,product_name VARCHAR(255),brand_id INT,rating INT,is_cruelty_free BOOLEAN); | SELECT b.brand_name, AVG(p.rating) as avg_rating FROM brands b INNER JOIN products p ON b.brand_id = p.brand_id WHERE p.is_cruelty_free = TRUE GROUP BY b.brand_name ORDER BY avg_rating DESC; |
What is the average crime rate per capita in each neighborhood? | CREATE TABLE neighborhoods (name VARCHAR(255),population INT,crime_count INT); INSERT INTO neighborhoods (name,population,crime_count) VALUES ('Central Park',1000,25),('Harlem',2500,75),('Brooklyn',5000,120); | SELECT name, AVG(crime_count/population) OVER (PARTITION BY name) FROM neighborhoods; |
What was the response time for the top 5 most common crime types in each community district in the past month? | CREATE TABLE community_districts (cd_number INT,community_name VARCHAR(255)); INSERT INTO community_districts (cd_number,community_name) VALUES (1,'Manhattan 1'),(2,'Manhattan 2'),(3,'Manhattan 3'); CREATE TABLE crime_data (crime_date DATE,cd_number INT,crime_type VARCHAR(255),response_time INT); | SELECT cd.community_name, ct.crime_type, AVG(cd.response_time) as avg_response_time FROM community_districts cd JOIN crime_data cd ON cd.cd_number = cd.cd_number JOIN (SELECT crime_type, cd_number, COUNT(*) as count FROM crime_data WHERE crime_date >= CURDATE() - INTERVAL 1 MONTH GROUP BY crime_type, cd_number ORDER BY count DESC LIMIT 5) ct ON cd.cd_number = ct.cd_number WHERE cd.crime_date >= CURDATE() - INTERVAL 1 MONTH GROUP BY cd.community_name, ct.crime_type; |
Show the difference in military equipment maintenance costs between 'Type A' and 'Type B' aircraft in 2022 | CREATE TABLE equipment_maintenance (equipment_type VARCHAR(50),maintenance_date DATE,maintenance_cost DECIMAL(10,2)); | SELECT (SUM(CASE WHEN equipment_type = 'Type A' THEN maintenance_cost ELSE 0 END) - SUM(CASE WHEN equipment_type = 'Type B' THEN maintenance_cost ELSE 0 END))/10000 FROM equipment_maintenance WHERE EXTRACT(YEAR FROM maintenance_date) = 2022; |
List all defense diplomacy events involving 'China' and 'India' between 2005 and 2010. | CREATE TABLE defense_diplomacy (id INT,country1 VARCHAR(255),country2 VARCHAR(255),year INT,event VARCHAR(255)); INSERT INTO defense_diplomacy (id,country1,country2,year,event) VALUES (1,'China','India',2005,'Military Exercise'); | SELECT * FROM defense_diplomacy WHERE (country1 = 'China' AND country2 = 'India') OR (country1 = 'India' AND country2 = 'China') AND year BETWEEN 2005 AND 2010; |
What is the total cargo capacity for all vessels in the 'vessels' table registered in the 'Hong Kong' registry? | CREATE TABLE vessels (vessel_id INT,vessel_name VARCHAR(50),registry VARCHAR(50),capacity INT); INSERT INTO vessels (vessel_id,vessel_name,registry,capacity) VALUES (1,'CSCL Globe','China',197500),(2,'OOCL Hong Kong','Hong Kong',210000),(3,'MSC Maya','Panama',192240); | SELECT SUM(capacity) FROM vessels WHERE registry = 'Hong Kong'; |
What are the names of all suppliers from 'Germany'? | CREATE TABLE suppliers (id INT,name VARCHAR(50),country VARCHAR(20)); INSERT INTO suppliers (id,name,country) VALUES (1,'Supplier 1','Germany'),(2,'Supplier 2','USA'); | SELECT name FROM suppliers WHERE country = 'Germany'; |
What are the names and capabilities of military technologies developed in 'North America'? | CREATE TABLE military_tech (id INT,tech_name TEXT,region TEXT,capabilities TEXT); INSERT INTO military_tech (id,tech_name,region,capabilities) VALUES (1,'F-35 Lightning II','North America','Stealth,multi-role'),(2,'THAAD','North America','Anti-ballistic missile defense'),(3,'Sea Hunter','North America','Autonomous naval vessel'); | SELECT tech_name, capabilities FROM military_tech WHERE region = 'North America'; |
Delete all records for the Hip-Hop genre from the year 2019 | CREATE TABLE music_genres (genre VARCHAR(255),country VARCHAR(255),revenue FLOAT,event_date DATE); INSERT INTO music_genres (genre,country,revenue,event_date) VALUES ('Pop','USA',10000.0,'2020-01-01'),('Rock','USA',8000.0,'2020-01-01'),('Jazz','USA',6000.0,'2020-01-01'); | DELETE FROM music_genres WHERE genre = 'Hip-Hop' AND YEAR(event_date) = 2019; |
What is the average length of songs by artists from the United States? | CREATE TABLE artists (artist_id INT,artist_name TEXT,country TEXT); CREATE TABLE songs (song_id INT,song_length FLOAT,artist_id INT); INSERT INTO artists VALUES (1,'Taylor Swift','United States'),(2,'Adele','United Kingdom'); INSERT INTO songs VALUES (1,205.3,1),(2,180.2,2); | SELECT AVG(song_length) FROM songs INNER JOIN artists ON songs.artist_id = artists.artist_id WHERE artists.country = 'United States'; |
How many donors have donated more than $100 in the 'Donations' table? | CREATE TABLE Donations (DonorID INT,DonationDate DATE,Amount DECIMAL(10,2)); INSERT INTO Donations (DonorID,DonationDate,Amount) VALUES (1,'2022-02-01',120.00),(2,'2022-01-15',75.00),(3,'2022-03-05',150.00); | SELECT COUNT(*) FROM Donations WHERE Amount > 100; |
What is the average donation amount for donors with the last name starting with 'S'? | CREATE TABLE Donations (DonationID INT,DonorName TEXT,DonationAmount DECIMAL); INSERT INTO Donations (DonationID,DonorName,DonationAmount) VALUES (1,'Sarah Lee',50.00),(2,'Peter Smith',100.00); | SELECT AVG(DonationAmount) FROM Donations WHERE DonorName LIKE 'S%'; |
What was the average donation amount for new donors to health programs in Q2 2022? | CREATE TABLE Donors (donor_id INT,donor_name VARCHAR(50),total_donation_amount DECIMAL(10,2),last_donation_date DATE,first_donation_date DATE); CREATE TABLE Donations (donation_id INT,donor_id INT,donation_amount DECIMAL(10,2),donation_date DATE,program_id INT); | SELECT AVG(donation_amount) FROM Donations d JOIN Donors don ON d.donor_id = don.donor_id WHERE program_id IN (SELECT program_id FROM Programs WHERE category = 'health') AND donor_id IN (SELECT donor_id FROM Donors WHERE YEAR(first_donation_date) = 2022 AND first_donation_date BETWEEN '2022-04-01' AND '2022-06-30' GROUP BY donor_id HAVING COUNT(*) = 1); |
How many lifelong learning courses has a student with ID '2' completed, in chronological order? | CREATE TABLE lifelong_learning (student_id INT,course_id INT,completion_date DATE); INSERT INTO lifelong_learning VALUES (2,1001,'2015-01-01'),(2,1002,'2016-01-01'); | SELECT student_id, course_id, COUNT(course_id) OVER (PARTITION BY student_id ORDER BY completion_date) as completed_courses FROM lifelong_learning WHERE student_id = 2; |
Select 'Name' from 'TopTeachers' view | CREATE TABLE Teachers (TeacherID INT,Name VARCHAR(100),Subject VARCHAR(50)); CREATE VIEW TopTeachers AS SELECT Name,Subject FROM Teachers WHERE Subject = 'Science'; | SELECT Name FROM TopTeachers; |
What is the average mental health score of students for each district, ordered by the average score? | CREATE TABLE districts (district_id INT,district_name VARCHAR(50)); INSERT INTO districts VALUES (1,'District A'),(2,'District B'),(3,'District C'); CREATE TABLE student_mental_health (student_id INT,district_id INT,mental_health_score INT); INSERT INTO student_mental_health VALUES (1,1,80),(2,1,90),(3,2,70),(4,2,60),(5,3,95),(6,3,85); | SELECT district_id, AVG(mental_health_score) as avg_score FROM student_mental_health GROUP BY district_id ORDER BY avg_score DESC; |
What is the total salary expense for the company? | CREATE TABLE Employees (EmployeeID INT,Department VARCHAR(20),Salary FLOAT); INSERT INTO Employees (EmployeeID,Department,Salary) VALUES (1,'Marketing',75000.0),(2,'Marketing',80000.0),(3,'IT',85000.0); | SELECT SUM(Salary) FROM Employees; |
Add a new energy storage capacity record for Sao Paulo in 2027 with 9000 MWh | CREATE TABLE energy_storage (id INT,region VARCHAR(50),year INT,capacity FLOAT); | INSERT INTO energy_storage (id, region, year, capacity) VALUES (3, 'Sao Paulo', 2027, 9000); |
What is the total energy generated from renewable energy sources in Kenya, Nigeria, and South Africa for Q1 2021? | CREATE TABLE energy_generation (country VARCHAR(20),source_type VARCHAR(20),generation FLOAT,generation_date DATETIME); INSERT INTO energy_generation (country,source_type,generation,generation_date) VALUES ('Kenya','Solar',1200.0,'2021-01-01'),('Kenya','Wind',1500.0,'2021-01-01'),('Nigeria','Solar',1800.0,'2021-01-01'),('Nigeria','Wind',2000.0,'2021-01-01'),('South Africa','Solar',2100.0,'2021-01-01'),('South Africa','Wind',2400.0,'2021-01-01'); | SELECT country, SUM(generation) as total_generation FROM energy_generation WHERE country IN ('Kenya', 'Nigeria', 'South Africa') AND generation_date >= '2021-01-01' AND generation_date < '2021-04-01' AND source_type IN ('Solar', 'Wind') GROUP BY country; |
How many producing gas wells are there in the Permian Basin and Marcellus Shale? | CREATE TABLE wells (id INT,region VARCHAR(255),well_type VARCHAR(255),status VARCHAR(255)); INSERT INTO wells (id,region,well_type,status) VALUES (1,'Permian Basin','Gas','Producing'),(2,'Permian Basin','Oil','Producing'),(3,'Marcellus Shale','Gas','Producing'),(4,'Marcellus Shale','Oil','Shut-in'); | SELECT SUM(CASE WHEN region IN ('Permian Basin', 'Marcellus Shale') AND well_type = 'Gas' AND status = 'Producing' THEN 1 ELSE 0 END) as producing_gas_wells FROM wells; |
Find the team with the highest winning percentage in the current MLB season. | CREATE TABLE teams (team_id INT,team_name VARCHAR(50),season_id INT); CREATE TABLE games (game_id INT,team_id INT,won INT,season_id INT); | SELECT team_id, AVG(won) * 100.0 / (SELECT COUNT(*) FROM games WHERE team_id = teams.team_id) AS win_percentage FROM games JOIN teams ON games.team_id = teams.team_id WHERE season_id = (SELECT MAX(season_id) FROM teams) GROUP BY team_id ORDER BY win_percentage DESC LIMIT 1; |
Who has the highest number of home runs in the 'baseball_stats' table? | CREATE TABLE baseball_stats (player_id INT,name VARCHAR(50),team VARCHAR(50),home_runs INT); INSERT INTO baseball_stats (player_id,name,team,home_runs) VALUES (1,'Aaron Judge','New York Yankees',52); INSERT INTO baseball_stats (player_id,name,team,home_runs) VALUES (2,'Mike Trout','Los Angeles Angels',45); | SELECT name, MAX(home_runs) FROM baseball_stats; |
What's the total funding amount for organizations located in 'India'? | CREATE TABLE Organization (id INT PRIMARY KEY,name VARCHAR(50),type VARCHAR(20),country VARCHAR(20)); INSERT INTO Organization (id,name,type,country) VALUES (1,'Akshaya Patra','Food Support','India'); INSERT INTO Organization (id,name,type,country) VALUES (2,'Goonj','Relief','India'); CREATE TABLE Funding (id INT PRIMARY KEY,donor_id INT,organization_id INT,amount DECIMAL(10,2)); INSERT INTO Funding (id,donor_id,organization_id,amount) VALUES (1,1,1,50000.00); INSERT INTO Funding (id,donor_id,organization_id,amount) VALUES (2,2,2,100000.00); | SELECT SUM(Funding.amount) FROM Funding INNER JOIN Organization ON Funding.organization_id = Organization.id WHERE Organization.country = 'India'; |
What is the maximum fare for trams in the 'urban' schema, excluding fares less than $2? | CREATE SCHEMA urban; CREATE TABLE urban.trams (id INT,fare DECIMAL); INSERT INTO urban.trams (id,fare) VALUES (1,3.50),(2,1.75),(3,2.25); | SELECT MAX(fare) FROM urban.trams WHERE fare > 2; |
What is the total revenue for the 'Red Line' route? | CREATE TABLE routes (route_id varchar(255),route_name varchar(255),revenue decimal(10,2)); INSERT INTO routes (route_id,route_name,revenue) VALUES ('R1','Red Line',500000.00); | SELECT revenue FROM routes WHERE route_name = 'Red Line'; |
What is the average delivery time for orders shipped to Italy that contain eco-friendly materials? | CREATE TABLE orders (id INT,delivery_time INT,eco_friendly BOOLEAN,country VARCHAR(50)); INSERT INTO orders (id,delivery_time,eco_friendly,country) VALUES (1,5,TRUE,'Italy'),(2,3,FALSE,'Canada'),(3,7,TRUE,'Italy'); | SELECT AVG(delivery_time) FROM orders WHERE eco_friendly = TRUE AND country = 'Italy'; |
What is the total income and expenses for financial wellbeing programs in Australia? | CREATE TABLE FinancialWellbeingPrograms (id INT,program_name VARCHAR(50),country VARCHAR(50),income FLOAT,expenses FLOAT); INSERT INTO FinancialWellbeingPrograms (id,program_name,country,income,expenses) VALUES (1,'Financial Literacy Program','Australia',25000,15000),(2,'Debt Management Program','Australia',30000,20000),(3,'Retirement Planning Program','Australia',35000,25000); | SELECT country, SUM(income) as total_income, SUM(expenses) as total_expenses FROM FinancialWellbeingPrograms WHERE country = 'Australia' GROUP BY country; |
What was the total donation amount by age group in 2021? | CREATE TABLE donors (donor_id INT,donor_age INT,donation_amount DECIMAL(10,2),donation_date DATE); | SELECT donor_age, SUM(donation_amount) as total_donation FROM donors WHERE YEAR(donation_date) = 2021 GROUP BY donor_age; |
What is the average weight of packages shipped to Africa in the last year? | CREATE TABLE packages (id INT,weight FLOAT,shipped_date DATE); INSERT INTO packages (id,weight,shipped_date) VALUES (1,15.3,'2022-01-01'),(2,22.1,'2022-01-15'); | SELECT AVG(weight) FROM packages WHERE shipped_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) AND destination = 'Africa'; |
What is the total weight of parcels shipped from 'FRA' to 'ICN' in March 2022? | CREATE TABLE parcels (id INT,shipment_id INT,weight FLOAT); INSERT INTO parcels (id,shipment_id,weight) VALUES (1,1,5.2),(2,1,4.8),(3,2,6.0),(4,2,5.5),(5,3,4.5); CREATE TABLE shipments (id INT,source_airport VARCHAR(5),destination_airport VARCHAR(5),shipped_date DATE); INSERT INTO shipments (id,source_airport,destination_airport,shipped_date) VALUES (1,'FRA','ICN','2022-03-02'),(2,'FRA','ICN','2022-03-05'),(3,'ICN','FRA','2022-03-10'); | SELECT SUM(weight) FROM parcels JOIN shipments ON parcels.shipment_id = shipments.id WHERE source_airport = 'FRA' AND destination_airport = 'ICN' AND shipped_date BETWEEN '2022-03-01' AND '2022-03-31'; |
Delete genetic research experiments conducted before 2010 | CREATE TABLE genetic_research_experiments (experiment_id INT,experiment_name VARCHAR(255),experiment_date DATE); | DELETE FROM genetic_research_experiments WHERE experiment_date < '2010-01-01'; |
Which genetic research projects used biosensor technologies in Spain? | CREATE TABLE projects(name VARCHAR(50),location VARCHAR(20),biosensor_used BOOLEAN);INSERT INTO projects(name,location,biosensor_used) VALUES('ProjectX','Spain',true),('ProjectY','Germany',false),('ProjectZ','France',true); | SELECT name FROM projects WHERE location = 'Spain' AND biosensor_used = true; |
Update the budget of the government program in the state of Florida with the ID of 1 to $3M. | CREATE TABLE programs (id INT,name VARCHAR(255),budget FLOAT,state VARCHAR(255)); INSERT INTO programs (id,name,budget,state) VALUES (1,'Program A',2.5,'Florida'),(2,'Program B',1.2,'Florida'),(3,'Program C',1.8,'California'); | UPDATE programs SET budget = 3000000.0 WHERE id = 1 AND state = 'Florida'; |
Which committees have less than 5 members, displayed in ascending order of the number of members? | CREATE TABLE committees (committee_name TEXT,members INT); INSERT INTO committees (committee_name,members) VALUES ('Committee1',6),('Committee2',3),('Committee3',7),('Committee4',2),('Committee5',8); | SELECT committee_name FROM committees WHERE members < 5 ORDER BY members ASC; |
What is the maximum salary of a professor in the Physics department? | CREATE TABLE if NOT EXISTS faculty (id INT,name VARCHAR(50),department VARCHAR(20),rank VARCHAR(20),salary INT); | SELECT MAX(salary) FROM faculty WHERE department='Physics' AND rank='Professor'; |
Find the ratio of community health workers to mental health professionals in each region. | CREATE TABLE HealthWorkers (Region VARCHAR(20),WorkerType VARCHAR(20),Count INT); INSERT INTO HealthWorkers (Region,WorkerType,Count) VALUES ('Northeast','MentalHealthProfessional',900),('Northeast','CommunityHealthWorker',500),('Southeast','MentalHealthProfessional',600),('Southeast','CommunityHealthWorker',400),('Midwest','MentalHealthProfessional',850),('Midwest','CommunityHealthWorker',600),('West','MentalHealthProfessional',750),('West','CommunityHealthWorker',700); | SELECT Region, AVG(CommunityHealthWorkerCount / MentalHealthProfessionalCount) AS Ratio FROM (SELECT Region, SUM(CASE WHEN WorkerType = 'MentalHealthProfessional' THEN Count ELSE 0 END) AS MentalHealthProfessionalCount, SUM(CASE WHEN WorkerType = 'CommunityHealthWorker' THEN Count ELSE 0 END) AS CommunityHealthWorkerCount FROM HealthWorkers GROUP BY Region) AS HealthWorkerCounts GROUP BY Region; |
How many mental health parity cases were reported in the Southwest region in 2020? | CREATE TABLE MentalHealthParity (Id INT,Region VARCHAR(20),ReportDate DATE); INSERT INTO MentalHealthParity (Id,Region,ReportDate) VALUES (1,'Southwest','2020-01-01'),(2,'Northeast','2019-12-31'),(3,'Southwest','2020-06-15'); | SELECT COUNT(*) as CountOfCases FROM MentalHealthParity WHERE Region = 'Southwest' AND YEAR(ReportDate) = 2020; |
What is the total number of bookings for eco-friendly accommodations in Barcelona? | CREATE TABLE accommodations (id INT,name TEXT,city TEXT,bookings INT,is_eco_friendly BOOLEAN); INSERT INTO accommodations (id,name,city,bookings,is_eco_friendly) VALUES (1,'Eco Hotel Barcelona','Barcelona',350,true),(2,'Green Lodge Barcelona','Barcelona',220,true),(3,'Sustainable Suites Barcelona','Barcelona',410,true); | SELECT SUM(bookings) FROM accommodations WHERE city = 'Barcelona' AND is_eco_friendly = true; |
What is the average number of AI-powered bookings per hotel in North America in Q2 2022? | CREATE TABLE ai_bookings (id INT,quarter TEXT,region TEXT,hotel_id INT,bookings INT); INSERT INTO ai_bookings (id,quarter,region,hotel_id,bookings) VALUES (1,'Q2 2022','North America',101,50),(2,'Q2 2022','North America',102,75),(3,'Q2 2022','North America',103,60); | SELECT region, AVG(bookings/NULLIF(hotel_id,0)) FROM ai_bookings WHERE quarter = 'Q2 2022' AND region = 'North America' GROUP BY region; |
Which species were studied by Agnes Sorensen? | CREATE TABLE species_research (id INT,species_id INT,year INT,location VARCHAR(50),observations INT); INSERT INTO species_research (id,species_id,year,location,observations) VALUES (1,1,2015,'Arctic',350),(2,1,2016,'Antarctic',400),(3,2,2016,'Arctic',500); CREATE TABLE researchers (id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO researchers (id,name,country) VALUES (1,'Sanna Simula','Finland'),(2,'Kristian Olsen','Greenland'),(3,'Agnes Sorensen','Greenland'); CREATE TABLE researcher_species (researcher_id INT,species_id INT); INSERT INTO researcher_species (researcher_id,species_id) VALUES (1,1),(2,1),(3,2); | SELECT s.name FROM researcher_species rs JOIN researchers r ON r.id = rs.researcher_id JOIN species s ON s.id = rs.species_id WHERE r.name = 'Agnes Sorensen'; |
How many projects are in the 'Green_Infrastructure' table located in 'Park'? | CREATE TABLE Green_Infrastructure (project_id INT,project_name VARCHAR(50),location VARCHAR(50)); INSERT INTO Green_Infrastructure (project_id,project_name,location) VALUES (1,'Rain Garden Installation','Park'),(2,'Tree Planting','Park'),(3,'Bioswale Construction','Street'),(4,'Permeable Pavement Installation','Parking Lot'); | SELECT COUNT(*) FROM Green_Infrastructure WHERE location = 'Park'; |
What is the average hotel price in each city in Europe? | CREATE TABLE Hotels_Europe (id INT,name VARCHAR(50),price DECIMAL(5,2),city VARCHAR(50)); INSERT INTO Hotels_Europe (id,name,price,city) VALUES (1,'Grand Hotel',200.00,'Paris'),(2,'Hotel Colosseo',350.00,'Rome'),(3,'Park Royal',120.00,'London'),(4,'Hotel Versailles',420.00,'Paris'); | SELECT city, AVG(price) as avg_price FROM Hotels_Europe GROUP BY city; |
List the marine life research projects in the 'Marine Research Projects' table. | CREATE TABLE marine_research_projects (id INT,project_name VARCHAR(255),objective TEXT,start_date DATE,end_date DATE); | SELECT project_name FROM marine_research_projects; |
What is the minimum depth at which any coral species can be found in the Caribbean region? | CREATE TABLE coral_species (species_name VARCHAR(255),region VARCHAR(255),min_depth FLOAT); INSERT INTO coral_species (species_name,region,min_depth) VALUES ('Staghorn Coral','Caribbean',1.0),('Elkhorn Coral','Caribbean',2.0); | SELECT MIN(min_depth) FROM coral_species WHERE region = 'Caribbean'; |
What is the percentage of videos about disinformation detection, published by independent creators? | CREATE TABLE videos (id INT,title VARCHAR(255),views INT,publish_date DATE,topic VARCHAR(255),creator_type VARCHAR(255)); | SELECT (COUNT(*) FILTER (WHERE topic = 'disinformation detection' AND creator_type = 'independent')) * 100.0 / COUNT(*) FROM videos; |
What is the percentage of female managers in the company? | CREATE TABLE Employees (EmployeeID INT,Department VARCHAR(20),Position VARCHAR(20),Age INT,Gender VARCHAR(10)); INSERT INTO Employees (EmployeeID,Department,Position,Age,Gender) VALUES (1,'Mining','Manager',50,'Female'),(2,'Mining','Engineer',40,'Male'),(3,'HR','Manager',45,'Female'); | SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Employees)) AS PercentageFemaleManagers FROM Employees WHERE Gender = 'Female' AND Position = 'Manager'; |
List all network towers in the city of Los Angeles that have a latitude value between -118.4 and -118.3. | CREATE TABLE network_towers (tower_id INT,city VARCHAR(20),latitude FLOAT); INSERT INTO network_towers (tower_id,city,latitude) VALUES (1,'Los Angeles',-118.2),(2,'Los Angeles',-118.5),(3,'New York',-118.4); | SELECT tower_id, city, latitude FROM network_towers WHERE city = 'Los Angeles' AND latitude BETWEEN -118.4 AND -118.3; |
What is the average word count of articles published in "The Wall Street Journal" in the "Business" news category? | CREATE TABLE articles (id INT,title TEXT,content TEXT,publication_date DATE,newspaper TEXT,category TEXT); CREATE TABLE words (id INT,article_id INT,word TEXT); | SELECT AVG(word_count) FROM (SELECT a.id, COUNT(w.word) AS word_count FROM articles a INNER JOIN words w ON a.id = w.article_id WHERE a.newspaper = 'The Wall Street Journal' AND a.category = 'Business' GROUP BY a.id) t; |
What is the minimum marine conservation score for areas in the Mediterranean? | CREATE TABLE marine_protected_areas (area_name TEXT,region TEXT,conservation_score FLOAT); INSERT INTO marine_protected_areas (area_name,region,conservation_score) VALUES ('MPA 1','Mediterranean',82.0),('MPA 2','Mediterranean',85.6),('MPA 3','Mediterranean',79.8); | SELECT MIN(conservation_score) FROM marine_protected_areas WHERE region = 'Mediterranean'; |
What is the total number of deep-sea exploration projects in the Southern Ocean? | CREATE TABLE deep_sea_exploration (name VARCHAR,ocean VARCHAR); INSERT INTO deep_sea_exploration (name,ocean) VALUES ('Argentina','Southern Ocean'); | SELECT COUNT(*) FROM deep_sea_exploration WHERE ocean = 'Southern Ocean'; |
What is the total number of marine species in each region? | CREATE TABLE marine_species (name VARCHAR,region VARCHAR); INSERT INTO marine_species (name,region) VALUES ('Dolphin','Atlantic'),('Shark','Pacific'),('Clownfish','Indian'); | SELECT region, COUNT(*) FROM marine_species GROUP BY region; |
Delete records in the 'esports_teams' table where the team is from the 'Asia' region | CREATE TABLE esports_teams (team_id INT,name VARCHAR(100),is_active BOOLEAN,region VARCHAR(50)); | DELETE FROM esports_teams WHERE region = 'Asia'; |
What is the minimum level of a player for CS:GO? | CREATE TABLE Players (PlayerID INT,PlayerName VARCHAR(20),Game VARCHAR(20),PlayerLevel INT); INSERT INTO Players (PlayerID,PlayerName,Game,PlayerLevel) VALUES (1,'Player1','CS:GO',23),(2,'Player2','CS:GO',30); | SELECT MIN(PlayerLevel) FROM Players WHERE Game = 'CS:GO'; |
What is the total amount of fines issued by the police department of Houston in the year 2019? | CREATE TABLE fines (fine_id INT,fine_date DATE,fine_city TEXT,fine_amount FLOAT); INSERT INTO fines (fine_id,fine_date,fine_city,fine_amount) VALUES (1,'2019-01-01','Houston',100),(2,'2019-06-15','Houston',200),(3,'2020-12-31','Houston',50); | SELECT SUM(fine_amount) FROM fines WHERE fine_city = 'Houston' AND YEAR(fine_date) = 2019; |
List all the distinct producers of Gadolinium from the 'production' table, ordered alphabetically. | CREATE TABLE production (element VARCHAR(10),year INT,month INT,producer VARCHAR(20),quantity INT); | SELECT DISTINCT producer FROM production WHERE element = 'Gadolinium' ORDER BY producer ASC; |
Which cities have affordable housing units with occupancy rates below 80%? | CREATE TABLE AffordableHousing (UnitID INT,City VARCHAR(50),OccupancyRate DECIMAL(4,2)); INSERT INTO AffordableHousing (UnitID,City,OccupancyRate) VALUES (1,'San Francisco',0.85),(2,'New York',0.92),(3,'Los Angeles',0.76); | SELECT City FROM AffordableHousing WHERE OccupancyRate < 0.80; |
Who are the owners of properties with a price above the average? | CREATE TABLE property (id INT,price FLOAT,owner_id INT); CREATE TABLE person (id INT,name VARCHAR(50)); | SELECT person.name FROM person INNER JOIN property ON person.id = property.owner_id WHERE price > (SELECT AVG(price) FROM property); |
Compute the percentage of renewable energy consumption in Southeast Asia, for each country, in the last 5 years. | CREATE TABLE SEA_Renewable_Energy (country VARCHAR(255),year INT,consumption INT); INSERT INTO SEA_Renewable_Energy (country,year,consumption) VALUES ('Indonesia',2018,15),('Malaysia',2018,20),('Thailand',2018,25),('Vietnam',2018,30),('Indonesia',2019,17),('Malaysia',2019,22),('Thailand',2019,28),('Vietnam',2019,33); | SELECT country, (SUM(consumption) FILTER (WHERE year BETWEEN 2018 AND 2022) OVER (PARTITION BY country)::DECIMAL / SUM(consumption) OVER (PARTITION BY country)) * 100 AS pct_renewable FROM SEA_Renewable_Energy; |
Which countries have the highest and lowest sales of ethical clothing brands? | CREATE TABLE ethical_brands (brand_id INT,brand_name TEXT,product_category TEXT); INSERT INTO ethical_brands (brand_id,brand_name,product_category) VALUES (1,'BrandA','Clothing'),(2,'BrandB','Electronics'),(3,'BrandC','Clothing'); CREATE TABLE sales (sale_id INT,brand_id INT,product_quantity INT,country TEXT); INSERT INTO sales (sale_id,brand_id,product_quantity,country) VALUES (1,1,50,'Germany'),(2,2,75,'France'),(3,3,30,'Germany'),(4,1,100,'France'); | SELECT country, SUM(product_quantity) AS total_sales FROM sales JOIN ethical_brands ON sales.brand_id = ethical_brands.brand_id WHERE ethical_brands.product_category = 'Clothing' GROUP BY country ORDER BY total_sales DESC, country; |
What is the maximum distance traveled by any astrophysics research? | CREATE TABLE astrophysics_research (research_id INT,location VARCHAR(50),distance FLOAT); INSERT INTO astrophysics_research (research_id,location,distance) VALUES (1,'Mars',50.3),(2,'Venus',10.2),(3,'Mars',40.1),(4,'Jupiter',70.5),(5,'Mars',60.0); | SELECT MAX(distance) FROM astrophysics_research; |
What is the minimum age of athletes in the "Athletes" table who are members of the LGBTQ+ community? | CREATE TABLE athletes (id INT,name VARCHAR(50),age INT,community VARCHAR(50)); | SELECT MIN(age) FROM athletes WHERE community = 'LGBTQ+'; |
What are the top 5 most common vulnerabilities based on their CVE IDs in the last month, ranked by severity? | CREATE TABLE Vulnerabilities (cve_id VARCHAR(20),severity INT,timestamp TIMESTAMP); INSERT INTO Vulnerabilities (cve_id,severity,timestamp) VALUES ('CVE-2022-1234',7,'2022-01-01 10:00:00'); | SELECT cve_id, COUNT(*) as vulnerability_count, RANK() OVER (ORDER BY vulnerability_count DESC) as vulnerability_rank FROM Vulnerabilities WHERE timestamp BETWEEN DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 MONTH) AND CURRENT_TIMESTAMP GROUP BY cve_id ORDER BY vulnerability_count DESC, severity DESC LIMIT 5; |
What is the average time to remediate high severity vulnerabilities for each organization? | CREATE TABLE vulnerabilities (vuln_id INT,org_id INT,vuln_severity VARCHAR(50),vuln_report_date DATE,vuln_remediation_date DATE); INSERT INTO vulnerabilities (vuln_id,org_id,vuln_severity,vuln_report_date,vuln_remediation_date) VALUES (1,1,'high','2022-01-01','2022-01-05'),(2,1,'medium','2022-01-02','2022-01-07'),(3,2,'high','2022-01-03','2022-01-10'); | SELECT org_id, AVG(DATEDIFF(day, vuln_report_date, vuln_remediation_date)) as avg_remediation_time FROM vulnerabilities WHERE vuln_severity = 'high' GROUP BY org_id; |
Which user accounts were created in the 'Europe' region in the last week? | CREATE TABLE user_accounts (id INT,username VARCHAR(255),region VARCHAR(255),account_created DATETIME); INSERT INTO user_accounts (id,username,region,account_created) VALUES (1,'jdoe','Asia-Pacific','2022-01-05'),(2,'jsmith','Europe','2022-01-06'); | SELECT username FROM user_accounts WHERE region = 'Europe' AND account_created >= DATE_SUB(NOW(), INTERVAL 1 WEEK); |
How many autonomous vehicles were manufactured in 2021 or 2022 with an average speed greater than 40 mph? | CREATE TABLE Autonomous_Vehicles (id INT,make VARCHAR(50),model VARCHAR(50),year INT,total_miles FLOAT,average_speed FLOAT); INSERT INTO Autonomous_Vehicles (id,make,model,year,total_miles,average_speed) VALUES (1,'Zoox','Alfred',2022,7000.0,38.0),(2,'Wayve','Ivy',2021,8000.0,45.0); | SELECT COUNT(*) FROM Autonomous_Vehicles WHERE year IN (2021, 2022) AND average_speed > 40.0; |
What is the average occupancy rate of public transportation vehicles in Seoul? | CREATE TABLE public_transportation_occupancy (vehicle_id INT,occupancy_rate FLOAT,city VARCHAR(50)); | SELECT AVG(occupancy_rate) FROM public_transportation_occupancy WHERE city = 'Seoul'; |
What is the daily usage of bike-sharing systems in London? | CREATE TABLE london_bikes (id INT,ride_id VARCHAR(20),start_time TIMESTAMP,end_time TIMESTAMP,bike_id INT); | SELECT DATE(start_time) AS ride_date, COUNT(DISTINCT bike_id) FROM london_bikes GROUP BY ride_date; |
Delete policies with no claims for policy type 'Renters' in the past 24 months. | CREATE TABLE Policy (PolicyID INT,PolicyType VARCHAR(50)); INSERT INTO Policy VALUES (1,'Auto'),(2,'Home'),(3,'Life'),(4,'Travel'),(5,'Renters'); CREATE TABLE Claims (ClaimID INT,PolicyID INT,ClaimDate DATE); INSERT INTO Claims VALUES (1,1,'2021-01-01'),(2,1,'2021-02-01'),(3,2,'2021-03-01'),(4,3,'2020-01-01'),(5,1,'2021-04-01'),(6,2,'2020-01-01'); | DELETE FROM Policy WHERE PolicyID NOT IN (SELECT PolicyID FROM Claims WHERE PolicyID = Policy.PolicyID AND ClaimDate > DATE_SUB(CURDATE(), INTERVAL 24 MONTH) AND PolicyType = 'Renters'); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.