instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the maximum environmental impact score for each resource type in the past year? | CREATE TABLE EnvironmentalImpact(id INT,resource_type VARCHAR(50),year INT,score FLOAT); | SELECT resource_type, MAX(score) AS Max_Score FROM EnvironmentalImpact WHERE year = YEAR(CURRENT_DATE) - 1 GROUP BY resource_type; |
What is the average number of professional development hours for teachers in each subject area, only showing subjects with an average above 20 hours? | CREATE TABLE subjects (subject_id INT,subject_name TEXT,num_teachers INT); CREATE TABLE hours (hour_id INT,subject_id INT,teacher_id INT,hours_spent INT); INSERT INTO subjects (subject_id,subject_name,num_teachers) VALUES (1,'Mathematics',30),(2,'Science',20),(3,'English',40); INSERT INTO hours (hour_id,subject_id,teacher_id,hours_spent) VALUES (1,1,1,25),(2,1,2,30),(3,2,1,22),(4,3,1,20),(5,3,2,23),(6,3,3,18); | SELECT subject_name, AVG(hours_spent) as avg_hours FROM subjects JOIN hours ON subjects.subject_id = hours.subject_id GROUP BY subject_name HAVING avg_hours > 20; |
Which community health workers have received health equity metric training more than once? | CREATE TABLE HealthEquityMetricTraining (WorkerID INT,TrainingDate DATE); INSERT INTO HealthEquityMetricTraining (WorkerID,TrainingDate) VALUES (1,'2021-01-01'),(2,'2021-02-15'),(3,'2021-03-05'),(4,'2021-04-10'),(5,'2021-05-01'),(6,'2021-05-01'); | SELECT WorkerID FROM HealthEquityMetricTraining GROUP BY WorkerID HAVING COUNT(DISTINCT TrainingDate) > 1; |
List the top 3 models with the lowest fairness score in the 'AI for climate change' category. | CREATE TABLE model_fairness (model_id INT,fairness_score FLOAT,ai_application_area VARCHAR(50)); | SELECT model_id, fairness_score FROM (SELECT model_id, fairness_score, ai_application_area, ROW_NUMBER() OVER (PARTITION BY ai_application_area ORDER BY fairness_score ASC) rn FROM model_fairness) mf WHERE mf.ai_application_area = 'AI for climate change' AND rn <= 3; |
Delete the research grant with grant_id 1 from the grants table. | CREATE TABLE grants (grant_id INT,student_id INT,year INT,amount INT); INSERT INTO grants (grant_id,student_id,year,amount) VALUES (1,1,2021,5000),(2,2,2022,15000); | DELETE FROM grants WHERE grant_id = 1; |
Get the total waste generation for 'North America' in 2020 from the 'waste_generation' table | CREATE TABLE waste_generation (id INT,country VARCHAR(50),year INT,total_waste_gen FLOAT); | SELECT SUM(total_waste_gen) FROM waste_generation WHERE year = 2020 AND country = 'North America'; |
What is the distribution of mental health scores by gender? | CREATE TABLE student_mental_health (student_id INT,gender VARCHAR(10),mental_health_score INT); INSERT INTO student_mental_health (student_id,gender,mental_health_score) VALUES (1,'Female',75),(2,'Male',80),(3,'Female',85),(4,'Male',70),(5,'Female',70),(6,'Male',85),(7,'Non-binary',80); | SELECT gender, AVG(mental_health_score) as avg_mh, STDDEV(mental_health_score) as std_dev FROM student_mental_health GROUP BY gender; |
Find the average number of days it takes to resolve vulnerabilities in the finance department. | CREATE TABLE vulnerabilities (vulnerability_id INT PRIMARY KEY,department VARCHAR(50),resolution_date DATE,discovery_date DATE); | SELECT AVG(DATEDIFF(day, discovery_date, resolution_date)) FROM vulnerabilities WHERE department = 'Finance'; |
Display the total number of transportation means in the transportation_summary view. | CREATE VIEW transportation_summary AS SELECT 'ebike' AS transportation_type,COUNT(*) AS total FROM micro_mobility UNION ALL SELECT 'autonomous_bus',COUNT(*) FROM public_transportation WHERE vehicle_type = 'autonomous_bus' UNION ALL SELECT ev_type,COUNT(*) FROM fleet_inventory WHERE ev_type IN ('electric_car','hybrid_car','electric_truck','hybrid_truck') GROUP BY ev_type; | SELECT SUM(total) FROM transportation_summary; |
Which spacecraft was the heaviest one launched by USA? | CREATE TABLE spacecrafts (id INT,name VARCHAR(50),launch_country VARCHAR(50),weight FLOAT); INSERT INTO spacecrafts VALUES (1,'Voyager 1','USA',795.5),(2,'Voyager 2','USA',782.5),(3,'Galileo','USA',2325.0),(4,'Cassini','France',2125.0),(5,'Rosetta','Europe',3000.0); | SELECT name, weight FROM spacecrafts WHERE launch_country = 'USA' ORDER BY weight DESC LIMIT 1; |
Which organizations have received the most donations from each country? | CREATE TABLE organizations (org_id INT,org_name VARCHAR(50),org_country VARCHAR(50));CREATE TABLE donations (donation_id INT,donor_country VARCHAR(50),org_id INT,donation_amount DECIMAL(10,2)); INSERT INTO organizations (org_id,org_name,org_country) VALUES (1,'Habitat for Humanity','USA'),(2,'Greenpeace','Canada'),(3,'American Cancer Society','Australia'); INSERT INTO donations (donation_id,donor_country,org_id,donation_amount) VALUES (1,'USA',1,500.00),(2,'Canada',1,750.00),(3,'Canada',2,300.00),(4,'Australia',3,400.00),(5,'Australia',3,600.00),(6,'USA',1,800.00),(7,'Canada',2,500.00); | SELECT o.org_name, d.donor_country, SUM(d.donation_amount) as total_donation_amount FROM organizations o JOIN donations d ON o.org_id = d.org_id GROUP BY o.org_name, d.donor_country ORDER BY total_donation_amount DESC; |
List all broadband subscribers in the Asia-Pacific region, excluding subscribers with no activity in the last 60 days. | CREATE TABLE subscribers (id INT,subscriber_type VARCHAR(10),region VARCHAR(20)); INSERT INTO subscribers (id,subscriber_type,region) VALUES (1,'Mobile','North America'),(2,'Broadband','Asia-Pacific'),(3,'Mobile','Europe'),(4,'Broadband','Asia-Pacific'),(5,'Broadband','Asia-Pacific'); CREATE TABLE activity (id INT,subscriber_id INT,last_activity_date DATE); INSERT INTO activity (id,subscriber_id,last_activity_date) VALUES (1,1001,'2022-01-01'),(2,1002,'2022-03-15'),(3,1003,'2022-04-05'),(4,1004,'2021-09-01'),(5,1005,'2022-02-01'); | SELECT subscriber_id FROM subscribers WHERE subscriber_type = 'Broadband' AND region = 'Asia-Pacific' INTERSECT SELECT subscriber_id FROM activity WHERE last_activity_date >= DATE_SUB(CURRENT_DATE, INTERVAL 60 DAY); |
How many members have a Premium membership in the Running club? | CREATE TABLE Members (MemberID INT,Age INT,Gender VARCHAR(10),MembershipType VARCHAR(20)); INSERT INTO Members (MemberID,Age,Gender,MembershipType) VALUES (1,35,'Female','Premium'),(2,45,'Male','Basic'),(3,28,'Female','Premium'),(4,32,'Male','Premium'),(5,48,'Female','Basic'); CREATE TABLE ClubMembership (MemberID INT,Club VARCHAR(20)); INSERT INTO ClubMembership (MemberID,Club) VALUES (1,'Cycling'),(2,'Yoga'),(3,'Running'),(4,'Pilates'),(5,'Cycling'); | SELECT COUNT(*) FROM Members JOIN ClubMembership ON Members.MemberID = ClubMembership.MemberID WHERE Members.MembershipType = 'Premium' AND ClubMembership.Club = 'Running'; |
List all accommodations and related students with visual impairments | CREATE TABLE accommodations (student_id INT,accommodation_category VARCHAR(20)); INSERT INTO accommodations (student_id,accommodation_category) VALUES (1,'Braille Materials'),(2,'Screen Reader'),(3,'Large Print'); CREATE TABLE students (student_id INT,student_name VARCHAR(30),disability VARCHAR(20)); INSERT INTO students (student_id,student_name,disability) VALUES (1,'Alex','Visual Impairment'),(2,'Beth','Hearing Impairment'),(3,'Charlie','None'); | SELECT accommodations.accommodation_category, students.student_name FROM accommodations INNER JOIN students ON accommodations.student_id = students.student_id WHERE students.disability = 'Visual Impairment'; |
Find the game released in 2020 with the highest rating in 'game_design' table | CREATE TABLE game_design (game_id INT,game_name VARCHAR(50),genre VARCHAR(50),release_year INT,rating FLOAT); | SELECT * FROM game_design WHERE release_year = 2020 ORDER BY rating DESC LIMIT 1; |
What is the total sales of dishes in each category? | CREATE TABLE Orders (OrderID INT,DishID INT,Quantity INT,OrderDate DATE); CREATE TABLE Dishes (DishID INT,DishName VARCHAR(50),Category VARCHAR(50),Price DECIMAL(5,2)); INSERT INTO Dishes (DishID,DishName,Category,Price) VALUES (1,'Veggie Pizza','Pizza',12.99),(2,'Margherita Pizza','Pizza',10.99),(3,'Chicken Caesar Salad','Salad',15.49),(4,'Garden Salad','Salad',11.99); INSERT INTO Orders (OrderID,DishID,Quantity,OrderDate) VALUES (1,1,2,'2022-01-01'),(2,2,1,'2022-01-02'),(3,3,3,'2022-01-03'),(4,1,1,'2022-01-04'),(5,4,2,'2022-01-05'); | SELECT Category, SUM(Quantity * Price) as TotalSales FROM Orders JOIN Dishes ON Orders.DishID = Dishes.DishID GROUP BY Category; |
How many spacecraft were manufactured by each company in 2025? | CREATE TABLE SpacecraftManufacturing (ID INT,Manufacturer VARCHAR(255),Mass INT,Year INT); INSERT INTO SpacecraftManufacturing (ID,Manufacturer,Mass,Year) VALUES (1,'SpaceCorp',5000,2025),(2,'SpaceCorp',6000,2025),(3,'SpaceCorp2',3000,2025),(4,'SpaceCorp2',4000,2025); | SELECT Manufacturer, COUNT(*) FROM SpacecraftManufacturing WHERE Year = 2025 GROUP BY Manufacturer; |
What is the total number of streams and albums sold by artists who have won a Grammy award? | CREATE TABLE Artists (ArtistID INT,ArtistName VARCHAR(100),GrammyWinner BOOLEAN); INSERT INTO Artists (ArtistID,ArtistName,GrammyWinner) VALUES (1,'Taylor Swift',TRUE),(2,'Green Day',FALSE); CREATE TABLE MusicStreams (StreamID INT,SongID INT,ArtistID INT); INSERT INTO MusicStreams (StreamID,SongID,ArtistID) VALUES (1,1,1),(2,2,2); CREATE TABLE Albums (AlbumID INT,AlbumName VARCHAR(100),ArtistID INT); INSERT INTO Albums (AlbumID,AlbumName,ArtistID) VALUES (1,'Fearless',1),(2,'American Idiot',2); | SELECT COUNT(DISTINCT ms.StreamID) + COUNT(DISTINCT a.AlbumID) AS TotalReleases FROM Artists a JOIN MusicStreams ms ON a.ArtistID = ms.ArtistID JOIN Albums al ON a.ArtistID = al.ArtistID WHERE GrammyWinner = TRUE; |
How many space missions have been launched by each space agency? | CREATE TABLE space_missions (id INT,agency VARCHAR(255),mission_year INT); INSERT INTO space_missions (id,agency,mission_year) VALUES (1,'NASA',2010),(2,'ESA',2012),(3,'ISRO',2008),(4,'Roscosmos',2015),(5,'NASA',2017); | SELECT agency, COUNT(*) AS num_missions FROM space_missions GROUP BY agency; |
What is the average duration of yoga workouts for members under 30 years old? | CREATE TABLE Workouts (WorkoutID INT,MemberID INT,WorkoutDate DATE,Duration INT,WorkoutType VARCHAR(20)); INSERT INTO Workouts (WorkoutID,MemberID,WorkoutDate,Duration,WorkoutType) VALUES (1,1,'2023-01-01',60,'Yoga'),(2,2,'2023-01-02',90,'Cycling'),(3,3,'2023-01-03',75,'Yoga'); | SELECT AVG(Duration) FROM Workouts INNER JOIN Members ON Workouts.MemberID = Members.MemberID WHERE Members.Age < 30 AND WorkoutType = 'Yoga'; |
What is the total revenue for each cuisine type, including the vegan cuisine? | CREATE TABLE restaurants (id INT,name TEXT,cuisine TEXT,revenue INT); INSERT INTO restaurants (id,name,cuisine,revenue) VALUES (1,'Restaurant A','Italian',5000),(2,'Restaurant B','Mexican',6000),(3,'Restaurant C','Italian',7000),(4,'Restaurant D','Vegan',8000); | SELECT cuisine, SUM(revenue) FROM restaurants GROUP BY cuisine; |
List all workplaces and their corresponding collective bargaining agreement status from the 'workplace_data' and 'collective_bargaining' tables. | CREATE TABLE workplace_data (workplace_id INT,workplace_name TEXT); CREATE TABLE collective_bargaining (agreement_status TEXT,workplace_id INT); | SELECT workplace_data.workplace_name, collective_bargaining.agreement_status FROM workplace_data INNER JOIN collective_bargaining ON workplace_data.workplace_id = collective_bargaining.workplace_id; |
How many intelligence operations were conducted by the Australian government in 2019 and 2020? | CREATE TABLE aus_intelligence_operations (id INT,year INT,operations_count INT); INSERT INTO aus_intelligence_operations (id,year,operations_count) VALUES (1,2019,700),(2,2020,850); | SELECT SUM(operations_count) FROM aus_intelligence_operations WHERE year IN (2019, 2020); |
Determine the number of cities that have more than one exhibition venue. | CREATE TABLE CityVenues (id INT,city VARCHAR(20),venue VARCHAR(20)); INSERT INTO CityVenues (id,city,venue) VALUES (1,'Paris','Louvre'),(2,'Paris','Pompidou'),(3,'London','British Museum'),(4,'New York','Met'),(5,'New York','MoMA'); | SELECT COUNT(*) FROM (SELECT city, COUNT(DISTINCT venue) AS num_venues FROM CityVenues GROUP BY city) t WHERE num_venues > 1; |
Find posts that are liked by users from the 'music' page but not interacted with by users from the 'tech' page. | CREATE TABLE users (id INT,name VARCHAR(255)); CREATE TABLE posts (id INT,user_id INT,page_name VARCHAR(255),content TEXT); CREATE TABLE likes (id INT,user_id INT,post_id INT); CREATE TABLE hashtags (id INT,post_id INT,tag VARCHAR(255)); | SELECT posts.id, posts.content FROM posts JOIN likes ON posts.id = likes.post_id JOIN (SELECT user_id FROM users WHERE page_name = 'music') AS music_users ON likes.user_id = music_users.user_id LEFT JOIN (SELECT user_id FROM users WHERE page_name = 'tech') AS tech_users ON likes.user_id = tech_users.user_id WHERE tech_users.user_id IS NULL; |
Calculate the total cargo weight for 'VesselH' in Q1 of 2020 | CREATE TABLE vessel_cargo_weight (vessel_name TEXT,weight_tonnes INTEGER,cargo_date DATE); INSERT INTO vessel_cargo_weight (vessel_name,weight_tonnes,cargo_date) VALUES ('VesselH',500,'2020-01-15'); INSERT INTO vessel_cargo_weight (vessel_name,weight_tonnes,cargo_date) VALUES ('VesselH',600,'2020-03-01'); | SELECT SUM(weight_tonnes) FROM vessel_cargo_weight WHERE vessel_name = 'VesselH' AND cargo_date BETWEEN '2020-01-01' AND '2020-03-31'; |
Insert a new company, 'Indigenous Startup', founded in Australia, and update its record to indicate it has received a sustainability award. | CREATE TABLE DiverseCompanies (id INT,name TEXT,country TEXT); CREATE TABLE InnovationAwards (id INT,company_id INT,award_type TEXT); | INSERT INTO DiverseCompanies (id, name, country) VALUES (1, 'Indigenous Startup', 'Australia'); UPDATE DiverseCompanies SET id = 1 WHERE name = 'Indigenous Startup'; INSERT INTO InnovationAwards (id, company_id, award_type) VALUES (1, 1, 'Sustainability'); |
List the causes that received donations from donors with the email domain 'gmail.com', and show the total donation amounts for each cause. Join the donors, donations, and causes tables. | CREATE TABLE donors (id INT,name VARCHAR(255),email VARCHAR(255)); INSERT INTO donors (id,name,email) VALUES (1,'John Doe','john.doe@gmail.com'),(2,'Jane Smith','jane.smith@yahoo.com'),(3,'Alice Johnson','alice.johnson@hotmail.com'); CREATE TABLE donations (id INT,donor_id INT,cause_id INT,amount DECIMAL(10,2)); INSERT INTO donations (id,donor_id,cause_id,amount) VALUES (1,1,1,500),(2,1,2,250),(3,2,2,750),(4,3,1,1000); CREATE TABLE causes (id INT,name VARCHAR(255)); INSERT INTO causes (id,name) VALUES (1,'Climate Change'),(2,'Human Rights'),(3,'Poverty Reduction'); | SELECT c.name, SUM(donations.amount) as total_donation FROM donors d JOIN donations ON d.id = donations.donor_id JOIN causes ON donations.cause_id = causes.id WHERE d.email LIKE '%@gmail.com' GROUP BY c.name; |
What is the distribution of genres for media content produced by creators from Indigenous communities? | CREATE TABLE media_library (id INT,title TEXT,genre TEXT,creator TEXT); INSERT INTO media_library (id,title,genre,creator) VALUES (1,'Media1','Drama','CreatorA'),(2,'Media2','Comedy','CreatorB'); CREATE TABLE creators (id INT,name TEXT,community TEXT); INSERT INTO creators (id,name,community) VALUES (1,'CreatorA','IndigenousCommunityA'),(2,'CreatorB','IndigenousCommunityB'); | SELECT genre, COUNT(*) as count FROM media_library INNER JOIN creators ON media_library.creator = creators.name WHERE creators.community IN ('IndigenousCommunityA', 'IndigenousCommunityB') GROUP BY genre; |
What are the top 5 most frequently ordered dishes in the California region since January 2022? | CREATE TABLE Orders (order_id INT PRIMARY KEY,customer_id INT,menu_id INT,order_date DATETIME,quantity INT); CREATE TABLE Menu (menu_id INT PRIMARY KEY,menu_item VARCHAR(255),category VARCHAR(255),price DECIMAL(5,2),region VARCHAR(255)); | SELECT Menu.menu_item, COUNT(Orders.quantity) as order_count FROM Orders INNER JOIN Menu ON Orders.menu_id = Menu.menu_id WHERE Menu.region = 'California' AND EXTRACT(YEAR FROM Orders.order_date) = 2022 GROUP BY Menu.menu_item ORDER BY order_count DESC LIMIT 5; |
What is the maximum and minimum cargo weight handled in a single voyage for each vessel in the Indian Ocean in Q1 2023? | CREATE TABLE VoyageCargo (voyage_cargo_id INT,voyage_id INT,cargo_weight INT); | SELECT v.vessel_name, MAX(vc.cargo_weight) as max_cargo_weight, MIN(vc.cargo_weight) as min_cargo_weight FROM VoyageCargo vc JOIN Voyages v ON vc.voyage_id = v.voyage_id WHERE v.region = 'Indian Ocean' AND v.voyage_date >= '2023-01-01' AND v.voyage_date < '2023-04-01' GROUP BY v.vessel_id; |
What is the total number of hours of sunlight received by each crop type in the past week? | CREATE TABLE crop_sunlight (crop_type TEXT,date DATE,hours INTEGER); | SELECT crop_type, SUM(hours) as total_hours FROM crop_sunlight WHERE date >= DATEADD(day, -7, GETDATE()) GROUP BY crop_type; |
What is the average price of hemp products? | CREATE TABLE products (id INT,name VARCHAR(255),material VARCHAR(255),price DECIMAL(5,2)); INSERT INTO products (id,name,material,price) VALUES (1,'T-Shirt','Organic Cotton',25.00),(2,'Hoodie','Recycled Polyester',75.00),(3,'Pants','Hemp',50.00); | SELECT AVG(price) FROM products WHERE material = 'Hemp'; |
What is the number of containers with weight greater than 2000 that were handled by port 'Sydney'? | CREATE TABLE ports (id INT,name VARCHAR(20)); INSERT INTO ports (id,name) VALUES (1,'Auckland'),(2,'Sydney'); CREATE TABLE containers (id INT,weight INT,port_id INT); INSERT INTO containers (id,weight,port_id) VALUES (1,1000,1),(2,2500,2),(3,1500,2),(4,3000,2); | SELECT COUNT(*) FROM containers WHERE weight > 2000 AND port_id = (SELECT id FROM ports WHERE name = 'Sydney'); |
What is the average production rate of wells drilled in the Gulf of Mexico and the North Sea? | CREATE TABLE wells (id INT,driller VARCHAR(255),well VARCHAR(255),location VARCHAR(255),production_rate FLOAT); INSERT INTO wells (id,driller,well,location,production_rate) VALUES (1,'DrillerA','WellA','Gulf of Mexico',1000),(2,'DrillerB','WellB','North Sea',1500),(3,'DrillerA','WellC','Gulf of Mexico',1200),(4,'DrillerC','WellD','North Sea',1500); | SELECT location, AVG(production_rate) FROM wells GROUP BY location; |
How many fish farms in India have experienced a disease outbreak in the past 2 years? | CREATE TABLE indiafarms (country VARCHAR(20),disease_outbreak BOOLEAN,year INTEGER); INSERT INTO indiafarms (country,disease_outbreak,year) VALUES ('India',true,2021),('India',false,2020),('India',false,2019),('India',false,2018),('India',false,2017); | SELECT COUNT(*) FROM indiafarms WHERE country = 'India' AND disease_outbreak = true AND year BETWEEN 2020 AND 2021; |
What is the minimum response time for emergency calls in CityP? | CREATE TABLE emergency_calls_3 (id INT,city VARCHAR(50),response_time FLOAT); INSERT INTO emergency_calls_3 (id,city,response_time) VALUES (1,'CityP',6.1),(2,'CityP',7.5),(3,'CityQ',6.8); | SELECT MIN(response_time) FROM emergency_calls_3 WHERE city = 'CityP'; |
Display the percentage change in exhibition attendance from the previous year for each city. | CREATE TABLE Attendance (id INT,city VARCHAR(20),year INT,visitors INT); INSERT INTO Attendance (id,city,year,visitors) VALUES (1,'Paris',2020,600),(2,'Paris',2019,500),(3,'London',2020,700),(4,'London',2019,800); | SELECT city, ((visitors - LAG(visitors) OVER (PARTITION BY city ORDER BY year))*100.0 / LAG(visitors) OVER (PARTITION BY city ORDER BY year)) AS pct_change FROM Attendance ORDER BY city, year; |
What is the average CO2 emission per month for the iron mines? | CREATE TABLE CO2Emissions (MineID INT,MineType VARCHAR(15),EmissionDate DATE,CO2Amount INT); | SELECT AVG(CO2Amount) FROM CO2Emissions WHERE MineType = 'Iron' GROUP BY MONTH(EmissionDate), YEAR(EmissionDate); |
Which attorney handled the most cases for Hispanic clients? | CREATE TABLE attorneys (attorney_id INT,name VARCHAR(50),start_date DATE); INSERT INTO attorneys (attorney_id,name,start_date) VALUES (1,'Amina Ahmed','2018-01-01'); INSERT INTO attorneys (attorney_id,name,start_date) VALUES (2,'Hugo Sánchez','2019-06-15'); CREATE TABLE clients (client_id INT,attorney_id INT,ethnicity VARCHAR(50),gender VARCHAR(10)); INSERT INTO clients (client_id,attorney_id,ethnicity,gender) VALUES (1,1,'Hispanic','Female'); INSERT INTO clients (client_id,attorney_id,ethnicity,gender) VALUES (2,2,'African American','Male'); INSERT INTO clients (client_id,attorney_id,ethnicity,gender) VALUES (3,1,'Hispanic','Female'); CREATE TABLE cases (case_id INT,client_id INT,case_type VARCHAR(50)); INSERT INTO cases (case_id,client_id,case_type) VALUES (1,1,'Civil Rights'); INSERT INTO cases (case_id,client_id,case_type) VALUES (2,2,'Criminal'); INSERT INTO cases (case_id,client_id,case_type) VALUES (3,1,'Immigration'); | SELECT attorney_id, COUNT(client_id) as cases_handled FROM clients JOIN cases ON clients.client_id = cases.client_id WHERE ethnicity = 'Hispanic' GROUP BY attorney_id; |
What is the total number of art pieces donated by female artists in the last 5 years? | CREATE TABLE ArtDonations (donation_date DATE,artist_gender VARCHAR(10),num_pieces INT); INSERT INTO ArtDonations (donation_date,artist_gender,num_pieces) VALUES ('2017-01-01','Female',120),('2017-01-02','Female',150),('2018-01-03','Female',80),('2019-01-04','Female',90),('2020-02-01','Female',120),('2021-02-02','Female',150),('2022-03-03','Female',80); | SELECT SUM(num_pieces) FROM ArtDonations WHERE artist_gender = 'Female' AND donation_date >= DATEADD(YEAR, -5, GETDATE()); |
What is the total number of employees from underrepresented communities in the Mining department? | CREATE TABLE Employees (EmployeeID INT,Name VARCHAR(50),Department VARCHAR(50),Community VARCHAR(50)); INSERT INTO Employees (EmployeeID,Name,Department,Community) VALUES (1,'John Doe','Mining','Underrepresented'); INSERT INTO Employees (EmployeeID,Name,Department,Community) VALUES (2,'Jane Smith','Human Resources','Represented'); | SELECT COUNT(*) FROM Employees WHERE Department = 'Mining' AND Community = 'Underrepresented'; |
Find the average funding amount for companies founded by individuals who identify as LGBTQ+ in the e-commerce sector | CREATE TABLE company (id INT,name TEXT,founding_year INT,founder_identity TEXT,industry TEXT); INSERT INTO company (id,name,founding_year,founder_identity,industry) VALUES (1,'Delta Inc',2019,'LGBTQ+','E-commerce'); INSERT INTO company (id,name,founding_year,founder_identity,industry) VALUES (2,'Epsilon Corp',2018,'Cisgender','Retail'); INSERT INTO company (id,name,founding_year,founder_identity,industry) VALUES (3,'Zeta Inc',2017,'LGBTQ+','E-commerce'); INSERT INTO company (id,name,founding_year,founder_identity,industry) VALUES (4,'Eta Corp',2016,'Non-binary','Healthcare'); | SELECT AVG(funding_amount) FROM investment_rounds ir INNER JOIN company c ON ir.company_id = c.id WHERE c.founder_identity = 'LGBTQ+' AND c.industry = 'E-commerce'; |
Find the average time to remediation for all high severity vulnerabilities. | CREATE TABLE vulnerabilities (id INT,software_id INT,discovered_on DATE,remediated_on DATE,severity VARCHAR(255)); INSERT INTO vulnerabilities (id,software_id,discovered_on,remediated_on,severity) VALUES (1,1,'2022-01-01','2022-01-05','High'),(2,1,'2022-02-01','2022-02-03','Medium'),(3,2,'2022-03-01','2022-03-05','Low'),(4,2,'2022-03-15','2022-03-17','High'),(5,3,'2022-03-30','2022-04-01','Medium'); | SELECT AVG(DATEDIFF(day, vulnerabilities.discovered_on, vulnerabilities.remediated_on)) as average_time_to_remediation FROM vulnerabilities WHERE vulnerabilities.severity = 'High'; |
What is the total quantity of sustainable materials used by each supplier? | CREATE TABLE supplier_materials (supplier_id INT,material VARCHAR(50),quantity INT); INSERT INTO supplier_materials (supplier_id,material,quantity) VALUES (1,'Recycled Polyester',5000),(1,'Organic Cotton',2000),(2,'Recycled Polyester',3000),(2,'Bamboo Viscose',1000),(3,'Cotton',4000),(3,'Hemp',1000),(4,'Recycled Polyester',6000),(5,'Organic Cotton',7000),(5,'Tencel',3000); CREATE TABLE suppliers (supplier_id INT,name VARCHAR(255)); INSERT INTO suppliers (supplier_id,name) VALUES (1,'Green Fabrics'),(2,'Eco Yarns'),(3,'Blue Textiles'),(4,'Sustainable Threads'),(5,'Natural Fibers'); | SELECT s.name, SUM(sm.quantity) FROM supplier_materials sm JOIN suppliers s ON sm.supplier_id = s.supplier_id GROUP BY s.name; |
What is the number of individuals with a financial wellbeing score above 8 in the United States? | CREATE TABLE if not exists us_wellbeing (id INT,individual_id INT,country VARCHAR(50),gender VARCHAR(10),score DECIMAL(3,1)); | SELECT COUNT(*) FROM us_wellbeing WHERE country = 'United States' AND score > 8; |
List all aquaculture farms in South America with water temperatures below 15 degrees Celsius in January. | CREATE TABLE Aquaculture_Farms (id INT,region VARCHAR(255),temperature DECIMAL(5,2),month INT); INSERT INTO Aquaculture_Farms (id,region,temperature,month) VALUES (1,'South America',14.8,1),(2,'South America',16.2,1),(3,'Europe',10.1,1),(4,'South America',12.5,1); | SELECT Aquaculture_Farms.id FROM Aquaculture_Farms WHERE Aquaculture_Farms.region = 'South America' AND Aquaculture_Farms.temperature < 15 AND Aquaculture_Farms.month = 1; |
What is the number of occurrences of each species in the 'species_occurrences' table? | CREATE TABLE species_occurrences (species_id INT,species_name TEXT,occurrence_count INT); | SELECT species_name, SUM(occurrence_count) as total_occurrences FROM species_occurrences GROUP BY species_name; |
What are the top 3 genres by the number of songs in the music streaming service? | CREATE TABLE Genres (GenreID INT,GenreName VARCHAR(255)); INSERT INTO Genres (GenreID,GenreName) VALUES (1,'Pop'),(2,'Rock'),(3,'Jazz'),(4,'Hip Hop'),(5,'Country'); CREATE TABLE Songs (SongID INT,SongName VARCHAR(255),GenreID INT); INSERT INTO Songs (SongID,SongName,GenreID) VALUES (1,'Song1',1),(2,'Song2',2),(3,'Song3',3),(4,'Song4',1),(5,'Song5',4),(6,'Song6',5),(7,'Song7',1),(8,'Song8',2),(9,'Song9',3); | SELECT GenreName, COUNT(*) as SongCount FROM Songs JOIN Genres ON Songs.GenreID = Genres.GenreID GROUP BY GenreName ORDER BY SongCount DESC LIMIT 3; |
List all financial capability programs offered by providers in the UK? | CREATE TABLE financial_capability_programs (provider VARCHAR(50),program VARCHAR(50),country VARCHAR(50)); INSERT INTO financial_capability_programs (provider,program,country) VALUES ('Bank E','Financial Education for Adults','UK'),('Credit Union F','Youth Money Skills','Australia'); | SELECT DISTINCT provider, program FROM financial_capability_programs WHERE country = 'UK'; |
What is the average amount of research grants awarded to graduate students in each department? | CREATE TABLE graduate_students (student_id INT,name VARCHAR(50),department VARCHAR(50)); CREATE TABLE research_grants (grant_id INT,student_id INT,amount DECIMAL(10,2),grant_date DATE); | SELECT gs.department, AVG(rg.amount) AS avg_grant_amount FROM graduate_students gs INNER JOIN research_grants rg ON gs.student_id = rg.student_id GROUP BY gs.department; |
What is the maximum program impact score for program B? | CREATE TABLE program_impact (program TEXT,impact_score DECIMAL); INSERT INTO program_impact (program,impact_score) VALUES ('Program A',4.2),('Program B',3.5),('Program C',5.0); | SELECT MAX(impact_score) FROM program_impact WHERE program = 'Program B'; |
Count the number of records in the creative_ai table where the application column is 'text generation' and the output_quality is 'excellent' | CREATE TABLE creative_ai (id INTEGER,application TEXT,output_quality TEXT,last_updated TIMESTAMP); | SELECT COUNT(*) FROM creative_ai WHERE application = 'text generation' AND output_quality = 'excellent'; |
How many military innovation projects were completed in the 'americas' region in 2020 and 2021? | CREATE TABLE military_innovation (country VARCHAR(50),region VARCHAR(50),year INT,projects INT); INSERT INTO military_innovation (country,region,year,projects) VALUES ('USA','Americas',2020,150),('Brazil','Americas',2020,80),('Canada','Americas',2021,120); | SELECT region, SUM(projects) as total_projects FROM military_innovation WHERE region = 'Americas' AND year IN (2020, 2021) GROUP BY region; |
Find the average calories for ingredients from specific suppliers with a specific certification | CREATE TABLE ingredients (id INT PRIMARY KEY,name VARCHAR(255),supplier_id INT,origin VARCHAR(255)); CREATE TABLE nutrition (ingredient_id INT,calories INT,protein INT,carbohydrates INT,fat INT); CREATE TABLE sustainability (id INT PRIMARY KEY,ingredient_id INT,certification VARCHAR(255)); | SELECT AVG(nutrition.calories) FROM ingredients INNER JOIN nutrition ON ingredients.id = nutrition.ingredient_id INNER JOIN sustainability ON ingredients.id = sustainability.ingredient_id WHERE ingredients.supplier_id IN (1, 2) AND sustainability.certification = 'Organic'; |
What is the total cost of projects in the water division? | CREATE TABLE Projects (id INT,division VARCHAR(20),total_cost FLOAT); INSERT INTO Projects (id,division,total_cost) VALUES (1,'water',500000),(2,'transportation',300000),(3,'water',750000); | SELECT SUM(total_cost) FROM Projects WHERE division = 'water'; |
What is the trend of flu cases over time by age group? | CREATE TABLE flu_cases (case_id INT,date DATE,age_group_id INT,cases_count INT); | SELECT ag.age_group, EXTRACT(YEAR FROM fc.date) AS year, EXTRACT(MONTH FROM fc.date) AS month, AVG(fc.cases_count) AS avg_cases FROM flu_cases fc JOIN age_groups ag ON fc.age_group_id = ag.age_group_id GROUP BY ag.age_group, EXTRACT(YEAR FROM fc.date), EXTRACT(MONTH FROM fc.date) ORDER BY ag.age_group, EXTRACT(YEAR FROM fc.date), EXTRACT(MONTH FROM fc.date); |
What is the cultural competency score for each community health worker? | CREATE TABLE cultural_competency_scores (worker_id INT,score INT); INSERT INTO cultural_competency_scores (worker_id,score) VALUES (1,85),(2,90),(3,80); | SELECT worker_id, AVG(score) as avg_score FROM cultural_competency_scores GROUP BY worker_id; |
What is the maximum capacity of a vessel in the 'fleet_management' table? | CREATE TABLE fleet_management (id INT,name VARCHAR(50),type VARCHAR(50),capacity INT); | SELECT MAX(capacity) FROM fleet_management; |
Which region produced the most Terbium in 2018? | CREATE TABLE production (year INT,element VARCHAR(10),region VARCHAR(10),quantity INT); INSERT INTO production (year,element,region,quantity) VALUES (2018,'Terbium','Asia',7000); | SELECT element, region, SUM(quantity) as total_quantity FROM production WHERE year = 2018 GROUP BY element, region ORDER BY total_quantity DESC LIMIT 1 |
How many players are there in each game from Asia? | CREATE TABLE GamePlayers (PlayerID INT,GameID INT,PlayerCountry VARCHAR(50)); INSERT INTO GamePlayers (PlayerID,GameID,PlayerCountry) VALUES (1,1,'China'),(2,2,'Japan'),(3,1,'Korea'); | SELECT GameID, COUNT(DISTINCT PlayerID) as PlayerCount FROM GamePlayers WHERE PlayerCountry LIKE 'Asia%' GROUP BY GameID; |
What is the most recent online booking for a hotel in the 'Caribbean'? | CREATE TABLE online_bookings (booking_id INT,hotel_id INT,user_id INT,booking_date DATE); INSERT INTO online_bookings (booking_id,hotel_id,user_id,booking_date) VALUES (1,1001,2001,'2022-06-15'),(2,1002,2002,'2022-07-20'),(3,1003,2003,'2022-05-08'); | SELECT * FROM online_bookings WHERE hotel_id IN (SELECT hotel_id FROM hotels WHERE country = 'Caribbean') ORDER BY booking_date DESC LIMIT 1; |
List all the unique education programs in 'community_education' table. | CREATE TABLE community_education (id INT,program VARCHAR(255)); | SELECT program FROM community_education GROUP BY program; |
Identify the top three most commonly exploited vulnerabilities, ranked by the number of occurrences? | CREATE TABLE vulnerabilities (id INT,vulnerability VARCHAR(20),exploit_count INT,timestamp TIMESTAMP); INSERT INTO vulnerabilities (id,vulnerability,exploit_count,timestamp) VALUES (1,'Buffer Overflow',50,'2022-01-01 10:00:00'),(2,'SQL Injection',75,'2022-01-02 11:00:00'); | SELECT vulnerability, SUM(exploit_count) as total_exploits FROM vulnerabilities GROUP BY vulnerability ORDER BY total_exploits DESC LIMIT 3; |
Delete records for volunteers who engaged in the Fundraising program in 2021 | CREATE TABLE volunteers (volunteer_id INT,program_name VARCHAR(50),volunteer_hours INT,volunteer_date DATE); INSERT INTO volunteers (volunteer_id,program_name,volunteer_hours,volunteer_date) VALUES (1,'Fundraising',10,'2021-01-01'),(2,'Fundraising',15,'2021-02-01'); | DELETE FROM volunteers WHERE program_name = 'Fundraising' AND YEAR(volunteer_date) = 2021; |
Insert a new record for a visitor from Egypt who visited an exhibition on 2022-01-03 | CREATE TABLE Visitors (id INT,name VARCHAR(100),country VARCHAR(50),visit_date DATE); CREATE TABLE Exhibitions (id INT,name VARCHAR(100),location VARCHAR(50)); CREATE TABLE Visits (visitor_id INT,exhibition_id INT,visit_date DATE); | INSERT INTO Visitors (id, name, country, visit_date) VALUES (10, 'Nourhan Mohamed', 'Egypt', '2022-01-03'); INSERT INTO Visits (visitor_id, exhibition_id, visit_date) VALUES (10, 1, '2022-01-03'); |
What is the rank of each country based on the total quantity of sustainable fabric sourced in 2021 and 2022? | CREATE TABLE sourcing (year INT,country VARCHAR(20),fabric_type VARCHAR(20),quantity INT); INSERT INTO sourcing (year,country,fabric_type,quantity) VALUES (2022,'India','sustainable',3000),(2022,'India','organic_cotton',5000),(2021,'Brazil','recycled_polyester',4000),(2021,'Brazil','sustainable',6000),(2021,'Nepal','organic_cotton',2000),(2021,'Nepal','sustainable',4000),(2022,'Brazil','sustainable',7000),(2022,'Nepal','sustainable',5000),(2022,'Nepal','organic_cotton',6000),(2021,'India','sustainable',8000); | SELECT country, RANK() OVER (ORDER BY total_quantity DESC) as rank FROM (SELECT country, SUM(quantity) as total_quantity FROM sourcing WHERE year IN (2021, 2022) AND fabric_type LIKE 'sustainable%' GROUP BY country) as subquery; |
What are the most common types of vulnerabilities found in the last quarter? | CREATE TABLE vulnerabilities (vulnerability_id INT,vulnerability_type VARCHAR(255),discovered_date DATE); INSERT INTO vulnerabilities (vulnerability_id,vulnerability_type,discovered_date) VALUES (1,'SQL Injection','2021-04-01'),(2,'Cross-site Scripting','2021-04-05'),(3,'Remote Code Execution','2021-04-12'),(4,'Denial of Service','2021-05-02'),(5,'Buffer Overflow','2021-05-18'),(6,'Path Traversal','2021-06-03'),(7,'Code Injection','2021-06-09'),(8,'Local File Inclusion','2021-07-01'); | SELECT vulnerability_type, COUNT(*) AS count FROM vulnerabilities WHERE discovered_date >= DATE_SUB(NOW(), INTERVAL 3 MONTH) GROUP BY vulnerability_type ORDER BY count DESC; |
What are the unique technology accessibility concerns for people with disabilities in the accessibility table? | CREATE TABLE accessibility (id INT,disability VARCHAR(255),concern VARCHAR(255)); | SELECT DISTINCT concern FROM accessibility WHERE disability = 'people with disabilities'; |
What is the average age of healthcare workers in 'rural_clinics' table? | CREATE TABLE rural_clinics (id INT,name TEXT,location TEXT,num_workers INT,avg_age FLOAT); INSERT INTO rural_clinics (id,name,location,num_workers,avg_age) VALUES (1,'Rural Clinic A','Rural Area 1',10,45.3),(2,'Rural Clinic B','Rural Area 2',15,42.8); | SELECT AVG(avg_age) FROM rural_clinics; |
How many crimes were committed in each borough of New York City in 2021? | CREATE TABLE Boroughs (Borough VARCHAR(255)); INSERT INTO Boroughs (Borough) VALUES ('Manhattan'),('Brooklyn'),('Queens'),('Bronx'),('Staten Island'); CREATE TABLE Crimes (ID INT,Borough VARCHAR(255),Year INT,Crime VARCHAR(255)); INSERT INTO Crimes (ID,Borough,Year,Crime) VALUES (1,'Manhattan',2021,'Theft'),(2,'Brooklyn',2021,'Assault'),(3,'Queens',2021,'Burglary'),(4,'Bronx',2021,'Homicide'),(5,'Staten Island',2021,'Vandalism'); | SELECT B.Borough, COUNT(C.Crime) as NumberOfCrimes FROM Crimes C INNER JOIN Boroughs B ON C.Borough = B.Borough WHERE C.Year = 2021 GROUP BY B.Borough; |
What are the total player scores for each game in a specific region? | CREATE TABLE GameScores (player_id INT,game_id INT,player_score INT,region VARCHAR(255)); INSERT INTO GameScores (player_id,game_id,player_score,region) VALUES (1,1,1500,'North America'),(2,1,1800,'North America'),(3,2,2000,'Asia'),(4,2,1900,'Asia'),(5,3,1200,'Europe'),(6,3,1600,'Europe'); | SELECT G.game_name, PS.region, SUM(PS.player_score) as total_score FROM GameScores PS JOIN Games G ON PS.game_id = G.game_id GROUP BY G.game_name, PS.region; |
List all organic farming practices in the 'food_justice' schema along with their implementation dates and the regions where they are implemented. | CREATE SCHEMA food_justice;CREATE TABLE organic_practices (id INT,practice VARCHAR(50),implementation_date DATE);CREATE TABLE regions (id INT,name VARCHAR(50));INSERT INTO food_justice.organic_practices (id,practice,implementation_date) VALUES (1,'Practice A','2021-05-15'),(2,'Practice B','2021-06-01'),(3,'Practice C','2021-07-10');INSERT INTO regions (id,name) VALUES (1,'Region A'),(2,'Region B'),(3,'Region C'); | SELECT op.practice, op.implementation_date, r.name FROM food_justice.organic_practices op CROSS JOIN regions r; |
Determine the number of months since the last safety incident for each chemical. | CREATE TABLE Chemical_Safety_Incidents_Timeline (Chemical_ID INT,Chemical_Name TEXT,Incident_Date DATE); INSERT INTO Chemical_Safety_Incidents_Timeline (Chemical_ID,Chemical_Name,Incident_Date) VALUES (1,'Chemical A','2022-01-01'),(2,'Chemical B','2022-02-01'),(3,'Chemical C','2022-03-01'); | SELECT Chemical_ID, Chemical_Name, Incident_Date, DATEDIFF('month', Incident_Date, LEAD(Incident_Date) OVER (PARTITION BY Chemical_ID ORDER BY Incident_Date)) as Months_Since_Last_Incident FROM Chemical_Safety_Incidents_Timeline; |
Add a new gym 'Greenwich' in 'London' using INSERT INTO command | CREATE TABLE gyms (gym_id INT,name TEXT,city TEXT); | INSERT INTO gyms (gym_id, name, city) VALUES (3, 'Greenwich', 'London'); |
What are the top 3 countries in South America by total revenue from sales of Yttrium in 2018? | CREATE TABLE sales (id INT,country VARCHAR(50),Yttrium_sold FLOAT,revenue FLOAT,datetime DATETIME); INSERT INTO sales (id,country,Yttrium_sold,revenue,datetime) VALUES (1,'Brazil',250.0,5000.0,'2018-01-01 10:00:00'),(2,'Argentina',180.0,3600.0,'2018-02-15 14:30:00'),(3,'Colombia',300.0,6000.0,'2018-03-05 09:15:00'); | SELECT country, SUM(revenue) AS total_revenue FROM sales WHERE YEAR(datetime) = 2018 AND Yttrium_sold IS NOT NULL AND country LIKE 'South%' GROUP BY country ORDER BY total_revenue DESC LIMIT 3; |
What is the average number of passengers per ride in public transportation systems in New York City? | CREATE TABLE public_transportation_nyc (id INT,transit_type VARCHAR(255),passengers INT); INSERT INTO public_transportation_nyc (id,transit_type,passengers) VALUES (1,'Subway',3000),(2,'Bus',50),(3,'Ferry',200); | SELECT AVG(passengers) FROM public_transportation_nyc; |
What is the average water consumption per household in Jakarta for the months of January and February in 2019 and 2020? | CREATE TABLE Household_Water_Usage (Household_ID INT,City VARCHAR(20),Month INT,Year INT,Water_Consumption FLOAT); INSERT INTO Household_Water_Usage (Household_ID,City,Month,Year,Water_Consumption) VALUES (1,'Jakarta',1,2019,150.5),(2,'Jakarta',2,2019,130.2); | SELECT Year, AVG(Water_Consumption) FROM Household_Water_Usage WHERE City = 'Jakarta' AND Month IN (1, 2) AND Year IN (2019, 2020) GROUP BY Year; |
How many local businesses in Barcelona have benefited from sustainable tourism initiatives? | CREATE TABLE local_businesses (business_id INT,name TEXT,city TEXT,benefited_from_sustainable_tourism BOOLEAN); INSERT INTO local_businesses (business_id,name,city,benefited_from_sustainable_tourism) VALUES (1,'La Boqueria Market Stall','Barcelona',true),(2,'Barcelona Gift Shop','Barcelona',false); | SELECT COUNT(*) FROM local_businesses WHERE city = 'Barcelona' AND benefited_from_sustainable_tourism = true; |
What is the average data usage for broadband subscribers in a specific region? | CREATE TABLE broadband_subscribers (subscriber_id INT,region VARCHAR(50),data_usage INT); | SELECT region, AVG(data_usage) FROM broadband_subscribers GROUP BY region; |
Identify the top 3 continents with the highest visitor count. | CREATE TABLE Continents (Continent_ID INT,Continent_Name VARCHAR(255)); INSERT INTO Continents (Continent_ID,Continent_Name) VALUES (1,'Africa'),(2,'Asia'),(3,'Europe'),(4,'North America'),(5,'South America'),(6,'Australia'); CREATE TABLE Visitor_Origins (Visitor_ID INT,Continent_ID INT); | SELECT c.Continent_Name, COUNT(v.Visitor_ID) AS Visitor_Count FROM Continents c JOIN Visitor_Origins v ON c.Continent_ID = v.Continent_ID GROUP BY c.Continent_Name ORDER BY Visitor_Count DESC LIMIT 3; |
List all deliveries made to 'Haiti' in 2022 that included 'food' or 'water' items. | CREATE TABLE Deliveries (delivery_id INT,delivery_date DATE,item_id INT,quantity INT,country TEXT); CREATE TABLE Items (item_id INT,item_name TEXT); CREATE TABLE DeliveryItems (delivery_id INT,item_id INT,quantity INT); | SELECT Deliveries.*, Items.item_name FROM Deliveries JOIN DeliveryItems ON Deliveries.delivery_id = DeliveryItems.delivery_id JOIN Items ON DeliveryItems.item_id = Items.item_id WHERE Deliveries.country = 'Haiti' AND Deliveries.delivery_date BETWEEN '2022-01-01' AND '2022-12-31' AND Items.item_name IN ('food', 'water'); |
What is the average number of games played by each team in the 'soccer_teams' table? | CREATE TABLE soccer_teams (team_id INT,team_name VARCHAR(100),num_games INT); | SELECT team_id, AVG(num_games) FROM soccer_teams GROUP BY team_id; |
What is the total number of schools in cities with a population between 500,000 and 1,000,000? | CREATE TABLE cities (name VARCHAR(50),population INT,num_schools INT); INSERT INTO cities (name,population,num_schools) VALUES ('CityA',700000,15),('CityB',600000,12),('CityC',550000,10),('CityD',450000,8),('CityE',300000,6),('CityF',800000,18),('CityG',900000,20),('CityH',1100000,25); | SELECT SUM(num_schools) FROM (SELECT num_schools FROM cities WHERE population BETWEEN 500000 AND 1000000); |
What are the top 5 policies with the highest citizen satisfaction ratings? | CREATE TABLE policies (id INT,name TEXT,budget INT,satisfaction INT); | SELECT * FROM policies ORDER BY satisfaction DESC LIMIT 5; |
What is the average account balance for clients in Japan? | CREATE TABLE clients (id INT,country VARCHAR(20),balance FLOAT); INSERT INTO clients (id,country,balance) VALUES (1,'Japan',10000),(2,'USA',15000),(3,'Canada',8000),(4,'Japan',12000),(5,'USA',9000); | SELECT AVG(balance) FROM clients WHERE country = 'Japan'; |
What is the maximum number of police officers in each division? | CREATE TABLE divisions (id INT,name VARCHAR(20),num_officers INT); INSERT INTO divisions (id,name,num_officers) VALUES (1,'downtown',100),(2,'north',120),(3,'south',90),(4,'east',150); | SELECT name, MAX(num_officers) FROM divisions GROUP BY name; |
List all unique health equity metrics for each state. | CREATE TABLE health_equity_metrics(metric VARCHAR(50),state VARCHAR(2)); INSERT INTO health_equity_metrics(metric,state) VALUES ('Access to Care','AL'),('Quality of Care','AK'),('Cost of Care','AZ'); | SELECT DISTINCT state, metric FROM health_equity_metrics; |
List all concerts with more than 10000 tickets sold | CREATE TABLE concerts (id INT,artist_name VARCHAR(255),tickets_sold INT); INSERT INTO concerts (id,artist_name,tickets_sold) VALUES (1,'Taylor Swift',12000),(2,'BTS',15000),(3,'Ariana Grande',9000); | SELECT * FROM concerts WHERE tickets_sold > 10000; |
What is the maximum altitude reached by a Virgin Galactic spacecraft? | CREATE TABLE VGSpacecrafts (id INT,flight_date DATE,max_altitude INT); | SELECT MAX(max_altitude) FROM VGSpacecrafts WHERE max_altitude IS NOT NULL; |
Find the maximum and minimum salaries of employees in the IT department | CREATE TABLE Employees (EmployeeID INT,FirstName TEXT,LastName TEXT,Department TEXT,Salary INT); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,Salary) VALUES (1,'John','Doe','IT',70000),(2,'Jane','Doe','IT',75000),(3,'Bob','Smith','Finance',80000); | SELECT MAX(Salary) AS MaxSalary, MIN(Salary) AS MinSalary FROM Employees WHERE Department = 'IT'; |
Insert new records into the games table and update the corresponding esports_matches table | CREATE TABLE games (id INT PRIMARY KEY,name TEXT); CREATE TABLE esports_matches (id INT PRIMARY KEY,game_id INT,team1_id INT,team2_id INT); | INSERT INTO games (id, name) VALUES (1, 'Dota 2'), (2, 'CS:GO'); UPDATE esports_matches SET game_id = CASE WHEN team1_id = 1 THEN 1 WHEN team2_id = 1 THEN 1 ELSE 2 END WHERE game_id IS NULL; |
What is the total number of electric vehicles in each country? | CREATE TABLE countries (id INT,name VARCHAR(50)); CREATE TABLE electric_vehicles (id INT,country_id INT,vehicle_count INT); INSERT INTO countries (id,name) VALUES (1,'United States'),(2,'Germany'),(3,'China'); INSERT INTO electric_vehicles (id,country_id,vehicle_count) VALUES (1,1,500000),(2,2,600000),(3,3,800000); | SELECT c.name, SUM(ev.vehicle_count) FROM countries c JOIN electric_vehicles ev ON c.id = ev.country_id GROUP BY c.name; |
What is the maximum daily water usage (in million gallons) in the state of New York in the summer months (June, July, August)? | CREATE TABLE ny_water_usage (id INT,daily_usage FLOAT,usage_location VARCHAR(255),usage_date DATE); INSERT INTO ny_water_usage (id,daily_usage,usage_location,usage_date) VALUES (1,5.6,'New York','2022-07-01'),(2,6.2,'New York','2022-08-01'),(3,4.8,'New York','2022-05-01'); | SELECT MAX(daily_usage) FROM ny_water_usage WHERE usage_location = 'New York' AND EXTRACT(MONTH FROM usage_date) IN (6, 7, 8); |
Identify the top 3 most sustainable fabric types used in garment manufacturing based on water usage (L/kg) in descending order. | CREATE TABLE Fabric (fabric_type VARCHAR(20),water_usage FLOAT); INSERT INTO Fabric (fabric_type,water_usage) VALUES ('Organic Cotton',2000),('Tencel',1200),('Hemp',800),('Recycled Polyester',3000),('Bamboo',1500); | SELECT fabric_type, water_usage FROM Fabric ORDER BY water_usage DESC LIMIT 3; |
What is the average installed capacity of wind energy in the top 3 wind energy producing countries? | CREATE TABLE top_wind_energy (country VARCHAR(20),installed_capacity INT); INSERT INTO top_wind_energy (country,installed_capacity) VALUES ('Germany',62442),('China',210000),('USA',102000),('India',40000),('Spain',25000); | SELECT AVG(installed_capacity) FROM top_wind_energy ORDER BY installed_capacity DESC LIMIT 3; |
Count the number of policies issued per month in 2020 | CREATE TABLE policies (policy_id INT,policyholder_id INT,policy_start_date DATE,policy_end_date DATE); INSERT INTO policies VALUES (1,1,'2020-01-01','2021-01-01'); INSERT INTO policies VALUES (2,2,'2019-01-01','2020-01-01'); INSERT INTO policies VALUES (3,3,'2020-03-01','2021-03-01'); INSERT INTO policies VALUES (4,4,'2020-07-01','2022-07-01'); | SELECT DATE_PART('month', policy_start_date) AS month, COUNT(policy_id) AS num_policies FROM policies WHERE policy_start_date >= '2020-01-01' AND policy_start_date < '2021-01-01' GROUP BY month ORDER BY month |
show the total number of articles published in 'Politics' and 'Sports' | CREATE TABLE Articles (id INT,topic VARCHAR(50),published_date DATE); INSERT INTO Articles (id,topic,published_date) VALUES (1,'Politics','2022-01-01'); INSERT INTO Articles (id,topic,published_date) VALUES (2,'Sports','2022-01-02'); INSERT INTO Articles (id,topic,published_date) VALUES (3,'Politics','2022-01-03'); INSERT INTO Articles (id,topic,published_date) VALUES (4,'Sports','2022-01-04'); | SELECT COUNT(*) FROM Articles WHERE topic IN ('Politics', 'Sports'); |
What are the names of all bridges and their construction dates in the city of 'Los Angeles'? | CREATE TABLE Bridges (name TEXT,city TEXT,construction_date DATE); INSERT INTO Bridges (name,city,construction_date) VALUES ('6th Street Viaduct','Los Angeles','1932-01-01'); | SELECT name, construction_date FROM Bridges WHERE city = 'Los Angeles'; |
What is the total number of electric scooter trips taken in Los Angeles? | CREATE TABLE electric_scooters (scooter_id INT,trip_id INT,city VARCHAR(50)); INSERT INTO electric_scooters (scooter_id,trip_id,city) VALUES (1,1,'Los Angeles'),(2,2,'Los Angeles'),(3,3,'Los Angeles'); | SELECT COUNT(*) FROM electric_scooters WHERE city = 'Los Angeles'; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.