instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the average age of intelligence operatives in the 'Intelligence' table?
CREATE TABLE Intelligence (id INT,name VARCHAR(50),role VARCHAR(50),age INT,experience INT); INSERT INTO Intelligence (id,name,role,age,experience) VALUES (1,'Charlie Brown','Analyst',30,5); INSERT INTO Intelligence (id,name,role,age,experience) VALUES (2,'Diana Ross','Agent',35,10);
SELECT AVG(age) FROM Intelligence;
List all the unique artists who have released songs in the 'song' table, joined with the 'artist' table.
CREATE TABLE artist (artist_id INT,artist_name VARCHAR(255)); CREATE TABLE song (song_id INT,song_name VARCHAR(255),artist_id INT);
SELECT DISTINCT a.artist_name FROM artist a INNER JOIN song s ON a.artist_id = s.artist_id;
List all wind projects in 'europe'
CREATE TABLE wind_projects (id INT PRIMARY KEY,project_name VARCHAR(255),location VARCHAR(255),capacity_mw FLOAT,completion_date DATE);
SELECT * FROM wind_projects WHERE location = 'europe';
What is the next maintenance date for machines in the Manufacturing department?
CREATE TABLE Machines (MachineID INT PRIMARY KEY,MachineName VARCHAR(50),Department VARCHAR(50),LastMaintenance DATE,NextMaintenance DATE); INSERT INTO Machines (MachineID,MachineName,Department,LastMaintenance,NextMaintenance) VALUES (3,'Furnace','Manufacturing','2022-03-01','2022-09-01'); INSERT INTO Machines (MachineID,MachineName,Department,LastMaintenance,NextMaintenance) VALUES (4,'Cooler','Manufacturing','2022-04-01','2022-10-01');
SELECT Machines.MachineName, Machines.Department, Machines.NextMaintenance FROM Machines WHERE Machines.Department = 'Manufacturing';
What is the 'hotel tech adoption' percentage for 'boutique hotels'?
CREATE TABLE hotel_tech_adoption (id INT,type TEXT,adoption BOOLEAN); INSERT INTO hotel_tech_adoption (id,type,adoption) VALUES (1,'Boutique',true),(2,'Luxury',false),(3,'Boutique',false);
SELECT 100.0 * COUNT(*) / (SELECT COUNT(*) FROM hotel_tech_adoption WHERE type = 'Boutique') FROM hotel_tech_adoption WHERE type = 'Boutique' AND adoption = true;
What is the monthly production volume of sustainable garments in each country?
CREATE TABLE productions (id INT,garment VARCHAR(50),material VARCHAR(50),country VARCHAR(50),production_date DATE); INSERT INTO productions (id,garment,material,country,production_date) VALUES (1,'T-Shirt','Organic Cotton','India','2021-01-15'),(2,'Hoodie','Bamboo Fabric','China','2021-02-20'),(3,'Jacket','Recycled Polyester','Bangladesh','2021-03-10');
SELECT m.country, EXTRACT(MONTH FROM production_date) as month, COUNT(*) as production_volume FROM productions p JOIN materials m ON p.country = m.country WHERE m.type IN ('Organic Cotton', 'Bamboo Fabric', 'Recycled Polyester') GROUP BY m.country, month ORDER BY month;
Which clients have borrowed more than $10000 from socially responsible lending?
CREATE TABLE socially_responsible_lending (loan_id INT,client_id INT,amount_borrowed INT); INSERT INTO socially_responsible_lending (loan_id,client_id,amount_borrowed) VALUES (1,1,12000),(2,2,8000),(3,3,9000),(4,4,7000),(5,5,11000); CREATE TABLE clients (client_id INT,client_name TEXT); INSERT INTO clients (client_id,client_name) VALUES (1,'Khalid'),(2,'Aisha'),(3,'Ali'),(4,'Zainab'),(5,'Jamal');
SELECT clients.client_name FROM clients JOIN socially_responsible_lending ON clients.client_id = socially_responsible_lending.client_id WHERE socially_responsible_lending.amount_borrowed > 10000;
What is the most popular workout by total time spent?
CREATE TABLE workouts (id INT,member_id INT,workout_type VARCHAR(50),duration INT); INSERT INTO workouts (id,member_id,workout_type,duration) VALUES (1,1,'Cycling',60),(2,1,'Yoga',30),(3,2,'Yoga',45),(4,3,'Cycling',90),(5,4,'Zumba',75); CREATE TABLE members (id INT,name VARCHAR(50),age INT); INSERT INTO members (id,name,age) VALUES (1,'John Doe',30),(2,'Jane Smith',40),(3,'Mike Johnson',50),(4,'Nancy Adams',60);
SELECT workout_type, SUM(duration) AS total_time FROM workouts JOIN members ON workouts.member_id = members.id GROUP BY workout_type ORDER BY total_time DESC LIMIT 1;
What is the total number of military personnel in the 'Air Force' branch?
CREATE SCHEMA IF NOT EXISTS military_personnel; CREATE TABLE IF NOT EXISTS personnel (id INT PRIMARY KEY,name TEXT,branch TEXT,rank TEXT,age INT); INSERT INTO personnel (id,name,branch,rank,age) VALUES (1,'John Doe','Navy','Admiral',45),(2,'Jane Smith','Army','Colonel',35),(3,'Mike Johnson','Air Force','Captain',30);
SELECT COUNT(*) FROM military_personnel.personnel WHERE branch = 'Air Force';
How many customer complaints were there in each state last month?
CREATE TABLE customer_complaints (complaint_id INT,complaint_date DATE,complaint_type VARCHAR(255),state VARCHAR(255));
SELECT state, COUNT(complaint_id) as total_complaints FROM customer_complaints WHERE complaint_date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH) GROUP BY state;
What is the average waste generation rate per capita in the industrial sector in the year 2019?
CREATE TABLE waste_generation (id INT,sector VARCHAR(20),year INT,waste_generated FLOAT); INSERT INTO waste_generation (id,sector,year,waste_generated) VALUES (1,'industrial',2019,300.2),(2,'industrial',2018,280.1),(3,'industrial',2019,320.5);
SELECT AVG(waste_generated) FROM waste_generation WHERE sector = 'industrial' AND year = 2019;
Update artifact analysis result for id 987
CREATE TABLE artifact_analysis (id INT PRIMARY KEY,artifact_id INT,analysis_type VARCHAR(50),result TEXT);
UPDATE artifact_analysis SET result = 'Gold plating detected' WHERE artifact_id = 987 AND analysis_type = 'Metallurgical analysis';
What is the average monthly data usage for postpaid mobile customers in New York?
CREATE TABLE mobile_customers (customer_id INT,name VARCHAR(50),data_usage FLOAT,state VARCHAR(20)); INSERT INTO mobile_customers (customer_id,name,data_usage,state) VALUES (1,'John Doe',3.5,'New York');
SELECT AVG(data_usage) FROM mobile_customers WHERE state = 'New York' AND payment_type = 'postpaid';
minimum retail price of garments in the 'Tops' category
CREATE TABLE GarmentCategories (category VARCHAR(25)); INSERT INTO GarmentCategories (category) VALUES ('Tops'),('Bottoms'),('Dresses'); CREATE TABLE Garments (garment_id INT,price DECIMAL(5,2),category VARCHAR(25)); INSERT INTO Garments (garment_id,price,category) VALUES (1,50.00,'Tops'),(2,75.00,'Tops'),(3,30.00,'Bottoms');
SELECT MIN(price) FROM Garments WHERE category = 'Tops';
What are the names and job titles of community health workers who have completed mental health parity training?
CREATE TABLE CommunityHealthWorkers (CHW_ID INT,Name VARCHAR(50),Job_Title VARCHAR(50),Training_Completion_Date DATE); INSERT INTO CommunityHealthWorkers (CHW_ID,Name,Job_Title,Training_Completion_Date) VALUES (1,'Alex','Community Health Worker','2021-10-01'); INSERT INTO CommunityHealthWorkers (CHW_ID,Name,Job_Title,Training_Completion_Date) VALUES (2,'Taylor','Community Health Worker','2021-11-15'); CREATE TABLE Training_Courses (Course_ID INT,Course_Name VARCHAR(50),Course_Type VARCHAR(50)); INSERT INTO Training_Courses (Course_ID,Course_Name,Course_Type) VALUES (1,'Mental Health Parity','Online');
SELECT Name, Job_Title FROM CommunityHealthWorkers INNER JOIN Training_Courses ON CommunityHealthWorkers.CHW_ID = Training_Courses.Course_ID WHERE Course_Type = 'Mental Health Parity' AND Training_Completion_Date IS NOT NULL;
What is the average salary of workers who have completed 'Forklift Safety' training?
CREATE TABLE Training (TrainingID INT,WorkerID INT,TrainingType VARCHAR(100),CompletionDate DATE); INSERT INTO Training (TrainingID,WorkerID,TrainingType,CompletionDate) VALUES (1,1,'First Aid','2019-12-01'),(2,2,'Forklift Safety','2020-02-15'),(3,3,'Scaffolding Safety','2020-03-01');
SELECT AVG(w.Salary) FROM Workers w INNER JOIN Training t ON w.WorkerID = t.WorkerID WHERE t.TrainingType = 'Forklift Safety';
How many military technologies were developed in the last decade by each intelligence agency?
CREATE TABLE intelligence_agency (id INT,name VARCHAR(255)); INSERT INTO intelligence_agency (id,name) VALUES (1,'CIA'),(2,'FBI'),(3,'NSA'); CREATE TABLE military_technology (id INT,agency_id INT,year INT,technology VARCHAR(255)); INSERT INTO military_technology (id,agency_id,year,technology) VALUES (1,1,2015,'Stealth Drone'),(2,2,2017,'Cyber Defense System'),(3,3,2018,'Artificial Intelligence Algorithms');
SELECT i.name, COUNT(m.id) as technology_count FROM intelligence_agency i INNER JOIN military_technology m ON i.id = m.agency_id WHERE m.year BETWEEN 2010 AND 2020 GROUP BY i.name;
How many safety incidents were reported in the chemical manufacturing plant located in Texas in 2019?
CREATE TABLE safety_incidents (plant_location VARCHAR(50),incident_date DATE); INSERT INTO safety_incidents (plant_location,incident_date) VALUES ('Texas chemical plant','2019-01-01'); INSERT INTO safety_incidents (plant_location,incident_date) VALUES ('Texas chemical plant','2019-03-01');
SELECT count(*) as total_incidents FROM safety_incidents WHERE plant_location = 'Texas chemical plant' AND incident_date >= '2019-01-01' AND incident_date < '2020-01-01';
What is the average salary of workers in the 'construction' industry who are part of a union?
CREATE TABLE if NOT EXISTS workers (id INT,industry VARCHAR(20),wage DECIMAL(5,2),is_union_member BOOLEAN); INSERT INTO workers (id,industry,wage,is_union_member) VALUES (1,'construction',50000.00,true),(2,'retail',30000.00,false),(3,'construction',55000.00,true);
SELECT AVG(wage) FROM workers WHERE industry = 'construction' AND is_union_member = true;
What is the total CO2 emission per year for each species in the 'species_emissions' table?
CREATE TABLE species_emissions (species_id INT,year INT,co2_emission FLOAT);
SELECT species_id, year, SUM(co2_emission) FROM species_emissions GROUP BY species_id, year;
What is the average DBH for trees in the boreal forest that belong to the Pinaceae family?
CREATE TABLE biomes (biome_id INT PRIMARY KEY,name VARCHAR(50),area_km2 FLOAT); INSERT INTO biomes (biome_id,name,area_km2) VALUES (1,'Tropical Rainforest',15000000.0),(2,'Temperate Rainforest',250000.0),(3,'Boreal Forest',12000000.0); CREATE TABLE trees (tree_id INT PRIMARY KEY,species VARCHAR(50),biome_id INT,family VARCHAR(50),dbh FLOAT,FOREIGN KEY (biome_id) REFERENCES biomes(biome_id)); INSERT INTO trees (tree_id,species,biome_id,family,dbh) VALUES (1,'Pinus sylvestris',3,'Pinaceae',35.0),(2,'Picea abies',3,'Pinaceae',40.0),(3,'Larix decidua',3,'Pinaceae',25.0);
SELECT AVG(dbh) FROM trees WHERE trees.family = 'Pinaceae' AND biomes.name = 'Boreal Forest';
What is the total number of cases heard by community courts and the corresponding year?
CREATE TABLE community_courts (id INT,court_name VARCHAR(255),year INT,cases_heard INT); INSERT INTO community_courts (id,court_name,year,cases_heard) VALUES (1,'East Los Angeles Community Court',2018,850),(2,'Midtown Community Court',2019,905),(3,'Red Hook Community Justice Center',2017,760);
SELECT community_courts.year, SUM(community_courts.cases_heard) AS total_cases_heard FROM community_courts;
Identify the top 5 volunteers with the most volunteer hours in the last 3 months, by country.
CREATE TABLE volunteers (id INT,volunteer_name TEXT,hours_served DECIMAL,volunteer_country TEXT,volunteer_date DATE); INSERT INTO volunteers (id,volunteer_name,hours_served,volunteer_country,volunteer_date) VALUES (1,'Alice Johnson',25.00,'USA','2022-01-01'),(2,'Bob Brown',50.00,'Canada','2022-03-05');
SELECT volunteer_country, volunteer_name, SUM(hours_served) as total_hours FROM volunteers WHERE volunteer_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH) GROUP BY volunteer_country, volunteer_name ORDER BY total_hours DESC LIMIT 5;
What is the total number of views for news media published in January 2021 in the media_publication table?
CREATE TABLE media_publication (publication_id INT,publication_date DATE,content_type VARCHAR(50),views INT); INSERT INTO media_publication (publication_id,publication_date,content_type,views) VALUES (1,'2021-01-01','News',1000),(2,'2021-01-02','Entertainment',2000),(3,'2021-02-01','Sports',1500);
SELECT SUM(views) as total_views FROM media_publication WHERE publication_date BETWEEN '2021-01-01' AND '2021-01-31' AND content_type = 'News';
What is the average number of streams per user in the Streaming table?
CREATE TABLE Streaming (id INT,user_id INT,artist_name VARCHAR(255),song_name VARCHAR(255),streams INT); INSERT INTO Streaming (id,user_id,artist_name,song_name,streams) VALUES (1,123,'Ariana Grande','Thank U,Next',500),(2,456,'Billie Eilish','Bad Guy',700),(3,789,'Taylor Swift','Love Story',600);
SELECT user_id, AVG(streams) as avg_streams_per_user FROM Streaming GROUP BY user_id;
What is the total claim amount for policyholders in 'Florida' who have a policy issued before '2020-01-01'?
CREATE TABLE policyholders (id INT,name TEXT,state TEXT); CREATE TABLE policies (id INT,policyholder_id INT,issue_date DATE,total_claim_amount FLOAT); INSERT INTO policyholders (id,name,state) VALUES (1,'Sarah Lee','FL'); INSERT INTO policies (id,policyholder_id,issue_date,total_claim_amount) VALUES (1,1,'2019-01-01',2000.00);
SELECT SUM(policies.total_claim_amount) FROM policies INNER JOIN policyholders ON policies.policyholder_id = policyholders.id WHERE policies.issue_date < '2020-01-01' AND policyholders.state = 'FL';
List all energy efficiency stats for California
CREATE TABLE energy_efficiency_stats (state VARCHAR(20),energy_efficiency_score INT); INSERT INTO energy_efficiency_stats (state,energy_efficiency_score) VALUES ('California',90),('Texas',75),('Florida',80);
SELECT * FROM energy_efficiency_stats WHERE state = 'California';
What is the total number of open pedagogy resources accessed by students in each district, grouped by resource type?
CREATE TABLE student_open_pedagogy (student_id INT,district_id INT,resource_id INT,resource_type VARCHAR(255)); CREATE TABLE resources (resource_id INT,resource_name VARCHAR(255),resource_type VARCHAR(255));
SELECT s.district_id, r.resource_type, COUNT(DISTINCT s.student_id, s.resource_id) as num_resources FROM student_open_pedagogy s INNER JOIN resources r ON s.resource_id = r.resource_id GROUP BY s.district_id, r.resource_type;
What is the total number of network infrastructure investments made in 2020?
CREATE TABLE network_investments (investment_id INT,investment_date DATE); INSERT INTO network_investments (investment_id,investment_date) VALUES (1,'2021-01-15'),(2,'2021-03-01'),(3,'2020-12-01');
SELECT COUNT(*) FROM network_investments WHERE investment_date BETWEEN '2020-01-01' AND '2020-12-31';
How many brands from Canada offer vegan makeup products?
CREATE TABLE brands (brand_id INT PRIMARY KEY,brand_name TEXT,brand_country TEXT,is_vegan BOOLEAN); INSERT INTO brands (brand_id,brand_name,brand_country,is_vegan) VALUES (1,'Elate Cosmetics','Canada',true),(2,'Pacifica','US',true),(3,'Zorah Biocosmetics','Canada',true),(4,'Tarte Cosmetics','US',true),(5,'Bite Beauty','Canada',true);
SELECT COUNT(*) FROM brands WHERE brand_country = 'Canada' AND is_vegan = true;
What is the total number of high severity vulnerabilities found in the North America region in the last 30 days?
CREATE TABLE vulnerabilities (id INT,severity TEXT,region TEXT,date DATE); INSERT INTO vulnerabilities (id,severity,region,date) VALUES (1,'high','North America','2022-01-05'),(2,'medium','Europe','2022-01-10'),(3,'high','North America','2022-01-12');
SELECT COUNT(*) FROM vulnerabilities WHERE severity = 'high' AND region = 'North America' AND date >= DATEADD(day, -30, GETDATE());
List all policyholders from 'Texas' with their claim amounts.
CREATE TABLE policyholders (id INT,policyholder_name TEXT,state TEXT,claim_amount INT); INSERT INTO policyholders (id,policyholder_name,state,claim_amount) VALUES (1,'John Doe','California',5000); INSERT INTO policyholders (id,policyholder_name,state,claim_amount) VALUES (2,'Jane Smith','Texas',7000); INSERT INTO policyholders (id,policyholder_name,state,claim_amount) VALUES (3,'Bob Johnson','New York',10000);
SELECT * FROM policyholders WHERE state = 'Texas';
List all podcasts produced in the 'education' category, ordered by title.
CREATE TABLE podcasts (id INT,title VARCHAR(255),category VARCHAR(255),date DATE);
SELECT title FROM podcasts WHERE category='education' ORDER BY title;
Identify the number of Green building certifications in each country, grouped by continent.
CREATE TABLE green_buildings (building_id INT,building_name VARCHAR(100),country VARCHAR(50),certifications VARCHAR(50)); CREATE TABLE countries (country VARCHAR(50),continent VARCHAR(50));
SELECT c.continent, g.certifications, COUNT(g.building_id) FROM green_buildings g INNER JOIN countries c ON g.country = c.country GROUP BY c.continent, g.certifications;
How many unique genres are there in the songs table?
CREATE TABLE songs (id INT,title TEXT,length FLOAT,genre TEXT); INSERT INTO songs (id,title,length,genre) VALUES (1,'Song1',3.2,'pop'),(2,'Song2',4.1,'rock'),(3,'Song3',3.8,'pop'),(4,'Song4',2.1,'classical'),(5,'Song5',5.3,'jazz'),(6,'Song6',6.2,'jazz');
SELECT COUNT(DISTINCT genre) FROM songs;
What are the total freight costs for each mode of transportation in Europe?
CREATE TABLE Freight_Costs (id INT,freight_date DATETIME,freight_country VARCHAR(50),freight_mode VARCHAR(50),freight_cost DECIMAL(10,2)); INSERT INTO Freight_Costs (id,freight_date,freight_country,freight_mode,freight_cost) VALUES (1,'2022-01-01','Germany','Air',1000),(2,'2022-01-02','France','Sea',800),(3,'2022-01-03','Italy','Rail',900);
SELECT freight_mode, SUM(freight_cost) total_cost FROM Freight_Costs WHERE freight_country IN ('Germany', 'France', 'Italy') GROUP BY freight_mode;
What is the average age of members who use the cycling class?
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'); CREATE TABLE ClassAttendance (MemberID INT,Class VARCHAR(20),Date DATE); INSERT INTO ClassAttendance (MemberID,Class,Date) VALUES (1,'Cycling','2022-01-01'),(2,'Yoga','2022-01-02'),(3,'Cycling','2022-01-03');
SELECT AVG(Members.Age) FROM Members JOIN ClassAttendance ON Members.MemberID = ClassAttendance.MemberID WHERE ClassAttendance.Class = 'Cycling';
Show the total number of players who play each game, ordered by the number of players in descending order
CREATE TABLE player_games (player_id INT,game_id INT,hours_played INT);
SELECT game_id, COUNT(*) as total_players FROM player_games GROUP BY game_id ORDER BY total_players DESC;
What is the total revenue generated by lipsticks and mascaras in the first week of 2021?
CREATE TABLE cosmetics_sales (id INT,product VARCHAR(50),units_sold INT,revenue FLOAT,sale_date DATE); INSERT INTO cosmetics_sales (id,product,units_sold,revenue,sale_date) VALUES (1,'Lipstick',45,342.75,'2021-01-01'); INSERT INTO cosmetics_sales (id,product,units_sold,revenue,sale_date) VALUES (2,'Mascara',34,235.65,'2021-01-02');
SELECT product, SUM(revenue) as total_revenue FROM cosmetics_sales WHERE sale_date BETWEEN '2021-01-01' AND '2021-01-07' AND product IN ('Lipstick', 'Mascara') GROUP BY product;
What is the percentage of successful diversion programs for youth offenders in South America and the US?
CREATE TABLE south_america_diversion (id INT,age_group VARCHAR(255),success BOOLEAN); INSERT INTO south_america_diversion (id,age_group,success) VALUES (1,'Youth',TRUE),(2,'Youth',FALSE),(3,'Youth',TRUE);CREATE TABLE us_diversion (id INT,age_group VARCHAR(255),success BOOLEAN); INSERT INTO us_diversion (id,age_group,success) VALUES (1,'Youth',TRUE),(2,'Youth',TRUE),(3,'Youth',FALSE);
SELECT (SUM(CASE WHEN age_group = 'Youth' AND success = TRUE THEN 1 ELSE 0 END) / COUNT(CASE WHEN age_group = 'Youth' THEN 1 ELSE NULL END)) * 100 AS youth_success_percentage FROM south_america_diversion UNION ALL SELECT (SUM(CASE WHEN age_group = 'Youth' AND success = TRUE THEN 1 ELSE 0 END) / COUNT(CASE WHEN age_group = 'Youth' THEN 1 ELSE NULL END)) * 100 AS youth_success_percentage FROM us_diversion;
How many volunteers have participated in capacity building activities in each country?
CREATE TABLE countries (id INT,name TEXT); INSERT INTO countries (id,name) VALUES (1,'USA'),(2,'Canada'),(3,'Mexico'); CREATE TABLE volunteers (id INT,name TEXT,country_id INT); INSERT INTO volunteers (id,name,country_id) VALUES (1,'John Doe',1),(2,'Jane Smith',2),(3,'Alice Johnson',1),(4,'Bob Williams',3); CREATE TABLE capacity_building (volunteer_id INT,activity_date DATE); INSERT INTO capacity_building (volunteer_id,activity_date) VALUES (1,'2021-05-12'),(2,'2022-03-15'),(3,'2021-12-28'),(1,'2020-08-07'),(4,'2021-01-02');
SELECT c.name, COUNT(DISTINCT v.id) as num_volunteers FROM countries c INNER JOIN volunteers v ON c.id = v.country_id INNER JOIN capacity_building cb ON v.id = cb.volunteer_id GROUP BY c.id;
List the community members and their ages who are involved in agricultural innovation and are living in 'rural_area_1' from the 'community_development', 'agriculture_innovation', and 'rural_infrastructure' tables
CREATE TABLE community_development (member_id INT,member_name VARCHAR(50),age INT,area_id INT); CREATE TABLE agriculture_innovation (farmer_id INT,farmer_name VARCHAR(50),member_id INT); CREATE TABLE rural_infrastructure (project_id INT,project_type VARCHAR(50),budget INT,area_id INT);
SELECT c.member_name, c.age FROM community_development c INNER JOIN agriculture_innovation a ON c.member_id = a.member_id INNER JOIN rural_infrastructure r ON c.area_id = r.area_id WHERE c.area_name = 'rural_area_1';
Rank the threat intelligence sources by the number of unique threat indicators they have reported in the last 30 days.
CREATE TABLE source (source_id INT,source_name VARCHAR(50)); INSERT INTO source (source_id,source_name) VALUES (1,'Malwarebytes'),(2,'Symantec'),(3,'Trend Micro'); CREATE TABLE indicator (indicator_id INT,indicator_value VARCHAR(50),source_id INT,report_date DATE); INSERT INTO indicator (indicator_id,indicator_value,source_id,report_date) VALUES (1,'192.168.1.1',1,'2022-05-01'),(2,'example.com',2,'2022-05-02'),(3,'Trojan.Win32.Generic',3,'2022-05-03');
SELECT source_name, COUNT(DISTINCT indicator_value) as num_unique_indicators FROM source INNER JOIN indicator ON source.source_id = indicator.source_id WHERE report_date >= DATEADD(day, -30, GETDATE()) GROUP BY source_name ORDER BY num_unique_indicators DESC;
Find the maximum duration of any space mission
CREATE TABLE SpaceMissions (id INT,mission_name VARCHAR(30),duration INT); INSERT INTO SpaceMissions (id,mission_name,duration) VALUES (1,'Mars Exploration',400); INSERT INTO SpaceMissions (id,mission_name,duration) VALUES (2,'Asteroid Survey',250); INSERT INTO SpaceMissions (id,mission_name,duration) VALUES (3,'Space Station Maintenance',300);
SELECT MAX(duration) FROM SpaceMissions;
How many workers are employed in factories with fair labor practices in Southeast Asia?
CREATE TABLE FairLaborFactories (factory_id INT,region VARCHAR(20)); INSERT INTO FairLaborFactories (factory_id,region) VALUES (1,'Southeast Asia'),(2,'South America'),(3,'Europe'); CREATE TABLE Workers (worker_id INT,factory_id INT,hours_worked INT); INSERT INTO Workers (worker_id,factory_id,hours_worked) VALUES (1,1,40),(2,1,45),(3,2,35),(4,3,42);
SELECT COUNT(*) FROM Workers INNER JOIN FairLaborFactories ON Workers.factory_id = FairLaborFactories.factory_id WHERE FairLaborFactories.region = 'Southeast Asia';
What is the total number of journeys for 'Subway' mode of transport?
CREATE TABLE Journeys(journey_id INT,journey_date DATE,mode_of_transport VARCHAR(20)); INSERT INTO Journeys(journey_id,journey_date,mode_of_transport) VALUES (1,'2022-01-01','Subway'),(2,'2022-01-02','Subway'),(3,'2022-01-03','Subway'),(4,'2022-01-04','Subway');
SELECT COUNT(*) FROM Journeys WHERE mode_of_transport = 'Subway';
How many members have a fitness tracking device?
CREATE TABLE Members (MemberID INT,Name VARCHAR(50),Age INT,FitnessTrackingDevice VARCHAR(10)); INSERT INTO Members (MemberID,Name,Age,FitnessTrackingDevice) VALUES (1,'John Doe',30,'Yes'); INSERT INTO Members (MemberID,Name,Age,FitnessTrackingDevice) VALUES (2,'Jane Smith',40,'No');
SELECT COUNT(*) FROM Members WHERE FitnessTrackingDevice = 'Yes';
Count the number of visitors from historically underrepresented communities who engaged with museums in the last year.
CREATE TABLE Visitor_Engagement (id INT,visitor_id INT,museum VARCHAR(255),date DATE); INSERT INTO Visitor_Engagement (id,visitor_id,museum,date) VALUES (1,1001,'National Museum of African American History and Culture','2022-03-22'),(2,1002,'American Indian Museum','2022-02-15'),(3,1003,'Smithsonian American Art Museum','2021-12-17'),(4,1004,'National Museum of the American Latino','2022-01-03');
SELECT COUNT(*) FROM Visitor_Engagement WHERE museum IN ('National Museum of African American History and Culture', 'American Indian Museum', 'National Museum of the American Latino') AND date >= '2021-01-01';
What is the maximum calorie burn during 'Cardio' workouts for members residing in 'California'?
CREATE TABLE Workouts (MemberID INT,State VARCHAR(20),WorkoutType VARCHAR(20),CaloriesBurned INT); INSERT INTO Workouts (MemberID,State,WorkoutType,CaloriesBurned) VALUES (1,'California','Cardio',300),(2,'New York','Strength',250),(3,'California','Cardio',350);
SELECT MAX(CaloriesBurned) FROM Workouts WHERE State = 'California' AND WorkoutType = 'Cardio';
Create a view that returns the number of climate change projects in each country
CREATE TABLE climate_projects (project_id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),budget FLOAT); CREATE VIEW project_count_by_country AS SELECT country,COUNT(*) FROM climate_projects GROUP BY country;
CREATE VIEW project_count_by_country AS SELECT country, COUNT(*) FROM climate_projects GROUP BY country;
Insert a new record for circular economy initiative in Berlin in 2022.
CREATE TABLE circular_economy (city VARCHAR(255),year INT,initiative VARCHAR(255));
INSERT INTO circular_economy (city, year, initiative) VALUES ('Berlin', 2022, 'Plastic waste reduction campaign');
What is the maximum financial wellbeing score for users in the West?
CREATE TABLE financial_wellbeing(id INT,user_id INT,region VARCHAR(50),score INT); INSERT INTO financial_wellbeing VALUES (1,501,'West',70); INSERT INTO financial_wellbeing VALUES (2,502,'North',80); INSERT INTO financial_wellbeing VALUES (3,503,'East',75); INSERT INTO financial_wellbeing VALUES (4,504,'South',85); INSERT INTO financial_wellbeing VALUES (5,505,'West',90);
SELECT MAX(score) FROM financial_wellbeing WHERE region = 'West';
Find the top 2 countries with the highest budget for language preservation programs.
CREATE TABLE language_preservation(id INT,country TEXT,annual_budget INT); INSERT INTO language_preservation VALUES (1,'India',500000),(2,'Brazil',400000),(3,'Indonesia',600000),(4,'Mexico',300000);
SELECT country, annual_budget FROM language_preservation ORDER BY annual_budget DESC LIMIT 2;
What is the maximum number of medals won by a country in a single Winter Olympics, categorized by the type of medal?
CREATE TABLE winter_olympics (id INT,nation VARCHAR(100),sport VARCHAR(50),medal VARCHAR(10),year INT);
SELECT nation, medal, MAX(COUNT(*)) as max_medals FROM winter_olympics GROUP BY nation, medal;
Calculate the percentage of volunteers who are under 18 years old, and list them along with their total volunteer hours for the current year.
CREATE TABLE Volunteers (VolunteerID INT,VolunteerName VARCHAR(50),DateOfBirth DATE); INSERT INTO Volunteers (VolunteerID,VolunteerName,DateOfBirth) VALUES (1,'James Brown','1993-01-01'),(2,'Jessica White','2003-01-01'); CREATE TABLE VolunteerHours (VolunteerID INT,Hours INT,VolunteerDate DATE); INSERT INTO VolunteerHours (VolunteerID,Hours,VolunteerDate) VALUES (1,5,'2021-01-01'),(1,6,'2021-02-01'),(1,7,'2021-03-01'),(2,4,'2021-01-01'),(2,3,'2021-02-01'),(2,2,'2021-03-01');
SELECT ROUND(COUNT(CASE WHEN TIMESTAMPDIFF(YEAR, Volunteers.DateOfBirth, CURDATE()) < 18 THEN Volunteers.VolunteerID END) / COUNT(*) * 100, 2) AS Under18Percentage, Volunteers.VolunteerName, SUM(VolunteerHours.Hours) AS TotalHoursForYear FROM Volunteers INNER JOIN VolunteerHours ON Volunteers.VolunteerID = VolunteerHours.VolunteerID AND VolunteerHours.VolunteerDate <= CURDATE() AND YEAR(VolunteerHours.VolunteerDate) = YEAR(CURDATE()) GROUP BY Volunteers.VolunteerName;
Insert a record of a new military technology into the "military_tech" table
CREATE TABLE military_tech (id INT,name VARCHAR(255),description TEXT,country VARCHAR(255));
INSERT INTO military_tech (id, name, description, country) VALUES (1, 'Stealth Drone', 'Unmanned aerial vehicle with low observable radar profile', 'US');
What is the average number of traffic accidents per year in the state of Texas?
CREATE TABLE TrafficAccidents (id INT,state VARCHAR(20),year INT,accident_count INT);
SELECT AVG(accident_count/1.0) FROM TrafficAccidents WHERE state = 'Texas' GROUP BY year;
Update the status of all military equipment records in the Atlantic region to 'Operational'?
CREATE TABLE military_equipment (id INT,equipment_name VARCHAR(50),equipment_status VARCHAR(50),region VARCHAR(50)); INSERT INTO military_equipment (id,equipment_name,equipment_status,region) VALUES (1,'Helicopter A','Non-Operational','Atlantic'),(2,'Tank B','Operational','Pacific');
UPDATE military_equipment SET equipment_status = 'Operational' WHERE region = 'Atlantic';
What is the total number of research grants received by female faculty members in the Chemistry department?
CREATE TABLE Faculty(Id INT,Name VARCHAR(100),Department VARCHAR(50),Gender VARCHAR(10),GrantAmount DECIMAL(10,2)); INSERT INTO Faculty(Id,Name,Department,Gender,GrantAmount) VALUES (1,'Quinn','Chemistry','Female',40000.00),(2,'Rory','Chemistry','Female',50000.00);
SELECT SUM(GrantAmount) FROM Faculty WHERE Department = 'Chemistry' AND Gender = 'Female';
Delete all records from the 'pollution_data' table where the 'pollution_level' is greater than 500.
CREATE TABLE pollution_data (id INT,location VARCHAR(50),pollution_level INT);
DELETE FROM pollution_data WHERE pollution_level > 500;
What is the number of students with each type of disability?
CREATE TABLE Disability_Types (Student_ID INT,Student_Name TEXT,Disability_Type TEXT); INSERT INTO Disability_Types (Student_ID,Student_Name,Disability_Type) VALUES (1,'John Doe','Visual Impairment'),(2,'Jane Smith','Hearing Impairment'),(3,'Michael Brown','ADHD');
SELECT Disability_Type, COUNT(*) FROM Disability_Types GROUP BY Disability_Type;
What was the daily average production of gas in 'South East Asia' in 2019?
CREATE TABLE wells (well_id INT,field VARCHAR(50),region VARCHAR(50),production_oil FLOAT,production_gas FLOAT,production_date DATE); INSERT INTO wells (well_id,field,region,production_oil,production_gas,production_date) VALUES (1,'Banyu Urip','South East Asia',8000.0,4000.0,'2019-01-01'),(2,'Corridor','South East Asia',6000.0,2000.0,'2019-02-01');
SELECT AVG(production_gas) FROM wells WHERE region = 'South East Asia' AND YEAR(production_date) = 2019;
What is the average impact of agricultural innovations for projects in urban areas?
CREATE TABLE AgriculturalInnovation (id INT,project_id INT,innovation VARCHAR(255),impact FLOAT); CREATE TABLE AgriculturalProjects (id INT,project_name VARCHAR(255),location VARCHAR(255),start_date DATE,end_date DATE,budget FLOAT); INSERT INTO AgriculturalProjects (id,project_name,location,start_date,end_date,budget) VALUES (1,'Drip Irrigation','City A','2018-01-01','2019-01-01',5000.00); INSERT INTO AgriculturalInnovation (id,project_id,innovation,impact) VALUES (1,1,'Soil Conservation',0.75);
SELECT AgriculturalProjects.location, AgriculturalInnovation.innovation, AVG(AgriculturalInnovation.impact) as average_impact FROM AgriculturalProjects INNER JOIN AgriculturalInnovation ON AgriculturalProjects.id = AgriculturalInnovation.project_id WHERE AgriculturalProjects.location = 'City A' GROUP BY AgriculturalProjects.location, AgriculturalInnovation.innovation;
What is the maximum number of daily login attempts and the corresponding user for each country in the last week?
CREATE TABLE login_attempts (id INT,country VARCHAR(255),user_id INT,login_attempts INT,login_date DATE); INSERT INTO login_attempts (id,country,user_id,login_attempts,login_date) VALUES (1,'India',101,3,'2021-01-01'),(2,'India',102,5,'2021-01-01'),(3,'Brazil',201,2,'2021-01-01'),(4,'Brazil',202,4,'2021-01-01'),(5,'India',101,4,'2021-01-02'),(6,'India',103,6,'2021-01-02'),(7,'Brazil',201,3,'2021-01-02'),(8,'Brazil',203,7,'2021-01-02');
SELECT country, user_id, MAX(login_attempts) as max_attempts, login_date FROM login_attempts WHERE login_date >= DATEADD(day, -7, GETDATE()) GROUP BY country, user_id, login_date;
List all mental health parity violations in California in the past year.
CREATE TABLE MentalHealthParity (ID INT,Violation VARCHAR(255),State VARCHAR(255),Date DATE); INSERT INTO MentalHealthParity VALUES (1,'Non-compliance with mental health coverage','California','2021-06-15'); INSERT INTO MentalHealthParity VALUES (2,'Lack of mental health coverage parity','California','2022-02-28');
SELECT * FROM MentalHealthParity WHERE State = 'California' AND Date >= DATEADD(year, -1, GETDATE());
What is the total number of hospital beds in 'RuralHealthFacilities' table?
CREATE TABLE RuralHealthFacilities (FacilityID INT,Name VARCHAR(50),Address VARCHAR(100),TotalBeds INT); INSERT INTO RuralHealthFacilities (FacilityID,Name,Address,TotalBeds) VALUES (1,'Rural Community Hospital','1234 Rural Rd',50);
SELECT SUM(TotalBeds) FROM RuralHealthFacilities;
What is the total number of animals in the 'animal_population' table?
CREATE TABLE animal_population (id INT,animal_name VARCHAR(50),population INT); INSERT INTO animal_population (id,animal_name,population) VALUES (1,'Tiger',2500),(2,'Elephant',5000),(3,'Lion',3000);
SELECT SUM(population) FROM animal_population;
What is the percentage of patients who visited a hospital vs. rural clinic?
CREATE TABLE visits (id INT,visit_type TEXT,visit_date DATE);
SELECT (SUM(CASE WHEN visit_type = 'Hospital' THEN 1 ELSE 0 END) * 100.0 / COUNT(*)) as hospital_percentage,
List the top three departments with the highest percentage of employees who identify as disabled.
CREATE TABLE EmployeeDemographics (EmployeeID INT,Department VARCHAR(20),Disability VARCHAR(50)); INSERT INTO EmployeeDemographics (EmployeeID,Department,Disability) VALUES (1,'IT','Yes'),(2,'IT','No'),(3,'HR','Yes'),(4,'HR','No'),(5,'Finance','Yes');
SELECT Department, PERCENT_RANK() OVER (ORDER BY COUNT(*) FILTER (WHERE Disability = 'Yes')) AS Percent_Disabled FROM EmployeeDemographics GROUP BY Department ORDER BY Percent_Disabled DESC LIMIT 3;
What are the top 3 ports by the number of vessels arrived in Q1 2022?
CREATE TABLE ports (id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO ports (id,name,country) VALUES (1,'Port of Los Angeles','USA'); INSERT INTO ports (id,name,country) VALUES (2,'Port of Rotterdam','Netherlands'); INSERT INTO ports (id,name,country) VALUES (3,'Port of Singapore','Singapore'); INSERT INTO vessel_port (vessel_id INT,port_id INT,arrival_date DATE); INSERT INTO vessel_port (vessel_id,port_id,arrival_date) VALUES (1,1,'2022-01-02'); INSERT INTO vessel_port (vessel_id,port_id,arrival_date) VALUES (1,2,'2022-02-15'); INSERT INTO vessel_port (vessel_id,port_id,arrival_date) VALUES (2,3,'2022-03-20'); INSERT INTO vessel_port (vessel_id,port_id,arrival_date) VALUES (2,1,'2022-01-10');
SELECT p.name, COUNT(v.vessel_id) as vessel_count FROM ports p JOIN vessel_port vp ON p.id = vp.port_id JOIN vessels v ON vp.vessel_id = v.id WHERE vp.arrival_date >= '2022-01-01' AND vp.arrival_date < '2022-04-01' GROUP BY p.id ORDER BY vessel_count DESC LIMIT 3;
What is the average salary for rural healthcare professionals, broken down by job title?
CREATE TABLE salaries (name VARCHAR(255),job_title VARCHAR(255),salary NUMERIC(10,2)); INSERT INTO salaries (name,job_title,salary) VALUES ('Professional A','Doctor',90000),('Professional B','Nurse',60000);
SELECT job_title, AVG(salary) FROM salaries GROUP BY job_title;
What is the average media literacy score for users in Europe who watched more than 10 hours of video content in the last month?
CREATE TABLE user_video_views (user_id INT,user_name TEXT,country TEXT,watch_time INT,media_literacy_score INT); INSERT INTO user_video_views (user_id,user_name,country,watch_time,media_literacy_score) VALUES (1,'User 1','Germany',15,6); INSERT INTO user_video_views (user_id,user_name,country,watch_time,media_literacy_score) VALUES (2,'User 2','France',8,7);
SELECT AVG(media_literacy_score) FROM user_video_views WHERE country = 'Europe' AND watch_time > 10 AND watch_time <= 10 + 30 AND watch_time >= 10 - 30;
What is the average energy consumption per square foot for each building type, ordered by the average consumption?
CREATE TABLE Buildings (BuildingID INT,BuildingType VARCHAR(255),EnergyConsumption FLOAT,Area FLOAT); INSERT INTO Buildings (BuildingID,BuildingType,EnergyConsumption,Area) VALUES (1,'Residential',12000,2000),(2,'Commercial',20000,5000),(3,'Residential',15000,3000);
SELECT BuildingType, AVG(EnergyConsumption/Area) AS Avg_Consumption_Per_Sqft FROM Buildings GROUP BY BuildingType ORDER BY Avg_Consumption_Per_Sqft DESC;
Generate a list of unique case types, ordered alphabetically, for a given table?
CREATE TABLE cases (case_id INT,case_type VARCHAR(20)); INSERT INTO cases (case_id,case_type) VALUES (1,'Homicide'),(2,'Assault'),(3,'Theft'),(4,'Fraud'),(5,'Theft');
SELECT DISTINCT case_type FROM cases ORDER BY case_type ASC;
Find the number of startups founded by underrepresented racial and ethnic groups in the technology sector.
CREATE TABLE startups (id INT,name TEXT,founder_race TEXT,industry TEXT); INSERT INTO startups (id,name,founder_race,industry) VALUES (1,'Alpha','Latinx','Technology'),(2,'Beta','Asian','Technology'),(3,'Gamma','Black','Technology'),(4,'Delta','White','Technology'),(5,'Epsilon','Latinx','Healthcare'),(6,'Zeta','Asian','Finance'),(7,'Eta','Black','Technology'),(8,'Theta','White','Healthcare');
SELECT COUNT(*) FROM startups WHERE founder_race IN ('Latinx', 'Asian', 'Black') AND industry = 'Technology';
Which rural infrastructure projects have an estimated cost greater than $600,000?
CREATE TABLE RuralInfrastructure (id INT PRIMARY KEY,name VARCHAR(50),location VARCHAR(50),type VARCHAR(20),cost FLOAT,completion_date DATE); INSERT INTO RuralInfrastructure (id,name,location,type,cost,completion_date) VALUES (1,'Water Reservoir','Rural India','Water Resource',500000,'2021-06-30'),(2,'Electric Grid','Rural Indonesia','Power Supply',800000,'2020-12-31'),(3,'Broadband Internet','Rural Colombia','Telecommunications',700000,'2023-05-31');
SELECT name, location, type, cost FROM RuralInfrastructure WHERE cost > 600000;
What is the percentage of drought-affected areas in the state of Texas for each year since 2010?
CREATE TABLE drought_impact(region VARCHAR(50),year INT,percentage FLOAT); INSERT INTO drought_impact(region,year,percentage) VALUES ('Texas',2010,25.3),('Texas',2011,35.6);
SELECT year, percentage FROM drought_impact WHERE region = 'Texas' ORDER BY year;
List all military technologies in the 'military_technologies' table along with their corresponding classification level and year of development, sorted by the classification level in ascending order.
CREATE TABLE military_technologies (id INT,name VARCHAR(255),classification VARCHAR(255),year_of_development INT);
SELECT name, classification, year_of_development FROM military_technologies ORDER BY classification ASC;
What is the total energy consumption of residential buildings in Tokyo in 2020?
CREATE TABLE energy_consumption (id INT,sector TEXT,location TEXT,year INT,consumption FLOAT); INSERT INTO energy_consumption (id,sector,location,year,consumption) VALUES (1,'residential','Tokyo',2020,5000.0),(2,'commercial','Tokyo',2020,7000.0);
SELECT SUM(consumption) FROM energy_consumption WHERE sector = 'residential' AND location = 'Tokyo' AND year = 2020;
Find the maximum network investment made in a single year.
CREATE TABLE network_investments (year INT,investment FLOAT); INSERT INTO network_investments (year,investment) VALUES (2018,1500000.0),(2019,1800000.0),(2020,2000000.0);
SELECT MAX(investment) FROM network_investments;
What is the average occupancy rate of green certified hotels in Paris?
CREATE TABLE green_hotels (hotel_id INT,name VARCHAR(255),city VARCHAR(255),occupancy_rate DECIMAL(5,2)); CREATE TABLE hotels (hotel_id INT,name VARCHAR(255),city VARCHAR(255),certification VARCHAR(255));
SELECT AVG(gh.occupancy_rate) FROM green_hotels gh INNER JOIN hotels h ON gh.hotel_id = h.hotel_id WHERE h.city = 'Paris' AND h.certification = 'green';
Insert a new sustainable sourcing record for 'Fair Trade Coffee' supplier.
CREATE TABLE sustainable_sourcing (supplier_id INT,supplier_name VARCHAR(255),is_approved BOOLEAN);
INSERT INTO sustainable_sourcing (supplier_id, supplier_name, is_approved) VALUES (3, 'Fair Trade Coffee', false);
Delete records of bridges in the 'infrastructure' schema with a 'material' of 'wood' and a 'span_length' less than 500 meters.
CREATE TABLE bridges (id INT,name VARCHAR(50),span_length FLOAT,material VARCHAR(20)); INSERT INTO bridges (id,name,span_length,material) VALUES (1,'Golden Gate',2737.4,'Steel'),(2,'Brooklyn Bridge',486.3,'Wood');
DELETE FROM bridges WHERE material = 'wood' AND span_length < 500;
What are the names of the roads and their lengths in the road network where the average road length is greater than 10 miles?
CREATE TABLE Roads (id INT,name TEXT,length REAL); INSERT INTO Roads (id,name,length) VALUES (1,'I-5',1381.5),(2,'I-80',2899.8),(3,'I-90',3020.5);
SELECT name, length FROM Roads WHERE length > (SELECT AVG(length) FROM Roads)
Find the number of policies issued per agent, for agents with more than 5 policies, in descending order.
CREATE TABLE Agents (AgentID INT,Name VARCHAR(50),NumberOfPolicies INT); INSERT INTO Agents (AgentID,Name,NumberOfPolicies) VALUES (1,'John Doe',7),(2,'Jane Smith',3),(3,'Mike Johnson',6);
SELECT AgentID, Name, NumberOfPolicies FROM Agents WHERE NumberOfPolicies > 5 ORDER BY NumberOfPolicies DESC;
How many players have played Overwatch and are over 18 years old?
CREATE TABLE players (id INT,name VARCHAR(50),age INT,game VARCHAR(50)); INSERT INTO players (id,name,age,game) VALUES (1,'John Doe',25,'Overwatch');
SELECT COUNT(*) AS num_players FROM players WHERE age > 18 AND game = 'Overwatch';
What is the total volume of timber produced for each forest type?
CREATE TABLE timber_production (year INT,forest_type VARCHAR(255),volume INT); INSERT INTO timber_production (year,forest_type,volume) VALUES (2018,'Coniferous',300),(2019,'Coniferous',350),(2020,'Coniferous',400),(2018,'Deciduous',200),(2019,'Deciduous',250),(2020,'Deciduous',300);
SELECT forest_type, SUM(volume) FROM timber_production GROUP BY forest_type;
What is the total budget allocated for waste management and housing services in 2022, by state?
CREATE TABLE BudgetAllocations (State VARCHAR(50),Service VARCHAR(50),Year INT,Amount DECIMAL(10,2)); INSERT INTO BudgetAllocations (State,Service,Year,Amount) VALUES ('Texas','Waste Management',2022,12000.00),('Texas','Housing',2022,18000.00),('Florida','Waste Management',2022,10000.00),('Florida','Housing',2022,16000.00);
SELECT State, SUM(Amount) as TotalBudget FROM BudgetAllocations WHERE Service IN ('Waste Management', 'Housing') AND Year = 2022 GROUP BY State;
What is the latest spacecraft launch for each manufacturer, still in development?
CREATE TABLE Spacecraft_Development (id INT,name VARCHAR(100),manufacturer VARCHAR(100),launch_date DATE,status VARCHAR(20)); INSERT INTO Spacecraft_Development (id,name,manufacturer,launch_date,status) VALUES (3,'Artemis 1','NASA','2022-08-29','Development');
SELECT manufacturer, MAX(launch_date) as latest_launch FROM Spacecraft_Development WHERE status = 'Development' GROUP BY manufacturer
what is the maximum number of animals in a single habitat preservation project?
CREATE TABLE habitat_preservation (project_id INT,animals INT); INSERT INTO habitat_preservation (project_id,animals) VALUES (1,50),(2,75),(3,100);
SELECT MAX(animals) FROM habitat_preservation;
What is the total number of startups founded by women in the healthcare sector?
CREATE TABLE founders (id INT,name TEXT,gender TEXT); INSERT INTO founders (id,name,gender) VALUES (1,'Alice','Female'),(2,'Bob','Male'); CREATE TABLE companies (id INT,name TEXT,sector TEXT); INSERT INTO companies (id,name,sector) VALUES (1,'MedHealth','Healthcare'),(2,'TechBoost','Technology'); CREATE TABLE founders_companies (founder_id INT,company_id INT); INSERT INTO founders_companies (founder_id,company_id) VALUES (1,1);
SELECT COUNT(*) FROM founders f JOIN founders_companies fc ON f.id = fc.founder_id JOIN companies c ON fc.company_id = c.id WHERE f.gender = 'Female' AND c.sector = 'Healthcare';
List the names and launch dates of all projects focused on ethical AI that were launched in 2020 or later.
CREATE TABLE ProjectTimeline (ProjectID INT,ProjectName VARCHAR(50),LaunchDate DATE); INSERT INTO ProjectTimeline (ProjectID,ProjectName,LaunchDate) VALUES (1,'Ethical AI 1.0','2018-01-01'); INSERT INTO ProjectTimeline (ProjectID,ProjectName,LaunchDate) VALUES (2,'Ethical AI 2.0','2020-01-01');
SELECT ProjectName, LaunchDate FROM ProjectTimeline WHERE ProjectName LIKE '%Ethical AI%' AND YEAR(LaunchDate) >= 2020;
What is the total investment in ethical funds in Oceania, excluding New Zealand?
CREATE TABLE ethical_funds (id INT,investment DECIMAL(10,2),location VARCHAR(50)); INSERT INTO ethical_funds (id,investment,location) VALUES (1,8000,'Australia'),(2,5000,'New Zealand'),(3,9000,'Australia');
SELECT SUM(investment) FROM ethical_funds WHERE location <> 'New Zealand' AND location = 'Oceania';
What is the total number of food_aid_amount records for organization_id 3 in the food_aid table?
CREATE TABLE food_aid (id INT PRIMARY KEY,organization_id INT,food_aid_amount INT); INSERT INTO food_aid (id,organization_id,food_aid_amount) VALUES (1,1,100000); INSERT INTO food_aid (id,organization_id,food_aid_amount) VALUES (2,2,200000); INSERT INTO food_aid (id,organization_id,food_aid_amount) VALUES (3,3,300000); INSERT INTO food_aid (id,organization_id,food_aid_amount) VALUES (4,4,400000);
SELECT SUM(food_aid_amount) FROM food_aid WHERE organization_id = 3;
What's the highest heart rate recorded for a user in December 2022?
CREATE TABLE heart_rate_data (id INT,user_id INT,heart_rate FLOAT,record_date DATE); INSERT INTO heart_rate_data (id,user_id,heart_rate,record_date) VALUES (1,5,85.6,'2022-12-02'),(2,6,91.2,'2023-01-15'),(3,7,89.8,'2022-12-18'),(4,8,76.4,'2022-11-11');
SELECT MAX(heart_rate) FROM heart_rate_data WHERE record_date BETWEEN '2022-12-01' AND '2022-12-31';
Insert records into student mental health table
CREATE TABLE student_mental_health (student_id INT,mental_health_score INT);
INSERT INTO student_mental_health (student_id, mental_health_score) VALUES (1, 80), (2, 85), (3, 70);
What is the average number of hours played per day for users in the 'VR_Users' table who have played for at least one hour in a single session?
CREATE TABLE VR_Sessions (session_id INT,user_id INT,session_duration FLOAT); INSERT INTO VR_Sessions (session_id,user_id,session_duration) VALUES (101,1,1.5),(102,1,2.0),(103,2,0.5),(104,3,3.0),(105,4,1.0),(106,5,4.5); INSERT INTO VR_Users (user_id,total_sessions INT) VALUES (1,2),(2,1),(3,1),(4,1),(5,1);
SELECT AVG(session_duration / total_sessions) as avg_hours_per_day FROM VR_Sessions JOIN VR_Users ON VR_Sessions.user_id = VR_Users.user_id WHERE session_duration >= 1.0;
Delete records in the 'users' table where 'last_login' is before '2020-01-01'
CREATE TABLE users (id INT PRIMARY KEY,name VARCHAR(50),last_login DATETIME);
DELETE FROM users WHERE last_login < '2020-01-01';
Which climate mitigation programs received the most funding in 2020, and what was the average funding amount per program?
CREATE TABLE climate_funding (program VARCHAR(255),year INT,funding_amount FLOAT);
SELECT program, AVG(funding_amount) AS avg_funding FROM climate_funding WHERE year = 2020 GROUP BY program ORDER BY avg_funding DESC LIMIT 1;
List the top 3 states with the highest mental health parity scores.
CREATE TABLE states (state_id INT,state_name VARCHAR(50),parity_score DECIMAL(3,2)); INSERT INTO states (state_id,state_name,parity_score) VALUES (1,'California',85.2),(2,'New York',82.7),(3,'Texas',78.3),(4,'Florida',76.8),(5,'Illinois',74.5);
SELECT state_name, parity_score FROM states ORDER BY parity_score DESC LIMIT 3;