instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the average speed of aircrafts manufactured by 'Airbus'?
CREATE TABLE Aircrafts (id INT,name VARCHAR(50),manufacturer VARCHAR(50),max_speed FLOAT);
SELECT AVG(max_speed) FROM Aircrafts WHERE manufacturer = 'Airbus';
What is the name of the facility with the lowest circular economy score?
CREATE TABLE circular_economy (id INT,facility_name VARCHAR(255),score FLOAT); INSERT INTO circular_economy (id,facility_name,score) VALUES (1,'Green Textiles',8.5),(2,'EcoMetal',9.0),(3,'SolarSteel',7.8);
SELECT facility_name FROM circular_economy ORDER BY score LIMIT 1;
What is the average energy consumption of hotels in Canada per square foot?
CREATE TABLE hotel_data(id INT,hotel_name TEXT,country TEXT,sqft INT,energy_consumption INT); INSERT INTO hotel_data (id,hotel_name,country,sqft,energy_consumption) VALUES (1,'Hotel A','Canada',10000,1200),(2,'Hotel B','Canada',12000,1400),(3,'Hotel C','Canada',15000,1800);
SELECT AVG(energy_consumption / sqft) FROM hotel_data WHERE country = 'Canada';
Which countries did the top 3 heaviest shipments originate from?
CREATE TABLE shipment (id INT,warehouse_from_country VARCHAR(20),warehouse_to_country VARCHAR(20),weight FLOAT); INSERT INTO shipment VALUES (1,'US','CA',75.6),(2,'MX','TX',82.9),(3,'US','NY',90.1);
SELECT DISTINCT warehouse_from_country, weight FROM shipment ORDER BY weight DESC LIMIT 3;
What is the average explainability score for AI models in Africa?
CREATE TABLE ai_models (model_id INT,model_name TEXT,region TEXT,explainability_score FLOAT); INSERT INTO ai_models (model_id,model_name,region,explainability_score) VALUES (1,'Eucalyptus','Africa',0.75),(2,'Fern','Asia',0.85),(3,'Gingko','Africa',0.80);
SELECT region, AVG(explainability_score) FROM ai_models WHERE region = 'Africa' GROUP BY region;
How many new employees were hired in each month of 2022?
CREATE TABLE HiringData (HireID INT,EmployeeID INT,HireDate DATE); INSERT INTO HiringData (HireID,EmployeeID,HireDate) VALUES (1,4,'2022-01-15'),(2,5,'2022-02-20'),(3,6,'2022-03-10'),(4,7,'2022-04-05'),(5,8,'2022-05-02'),(6,9,'2022-06-28'),(7,10,'2022-07-01'),(8,11,'2022-08-15'),(9,12,'2022-09-30'),(10,13,'2022-10-25'),(11,14,'2022-11-18'),(12,15,'2022-12-27');
SELECT EXTRACT(MONTH FROM HireDate) AS Month, COUNT(*) AS NewHires FROM HiringData WHERE HireDate BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY Month;
What is the maximum number of military personnel in the last year?
CREATE TABLE Personnel (id INT,personnel_id INT,personnel_date DATE,personnel_count INT);
SELECT MAX(personnel_count) FROM Personnel WHERE personnel_date >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR) AND personnel_type = 'Military';
Identify the current migration stage and start date for each whale species, partitioned by species, after August 15, 2021.
CREATE TABLE WhaleMigration (Species NVARCHAR(50),MigrationRoute NVARCHAR(50),StartDate DATETIME,EndDate DATETIME); INSERT INTO WhaleMigration (Species,MigrationRoute,StartDate,EndDate) VALUES ('Blue Whale','Pacific Ocean','2021-04-01 00:00:00','2021-10-31 00:00:00'); INSERT INTO WhaleMigration (Species,MigrationRoute,StartDate,EndDate) VALUES ('Humpback Whale','Atlantic Ocean','2021-06-01 00:00:00','2021-11-30 00:00:00');
SELECT Species, StartDate, ROW_NUMBER() OVER (PARTITION BY Species ORDER BY StartDate) as MigrationStage FROM WhaleMigration WHERE EndDate >= '2021-08-15'
What is the difference in delivery time between the earliest and latest deliveries for each supplier in the 'deliveries' table?
CREATE TABLE deliveries (supplier VARCHAR(255),delivery_time INT,delivery_date DATE); INSERT INTO deliveries (supplier,delivery_time,delivery_date) VALUES ('Supplier A',4,'2022-01-01'),('Supplier B',3,'2022-01-02'),('Supplier A',5,'2022-01-03');
SELECT supplier, MAX(delivery_time) - MIN(delivery_time) as delivery_time_difference FROM deliveries GROUP BY supplier;
Summarize mental health parity scores by community health workers in NY and PA.
CREATE TABLE community_health_workers (worker_id INT,name TEXT,state TEXT); INSERT INTO community_health_workers (worker_id,name,state) VALUES (1,'Ms. Fatima Lopez','NY'); CREATE TABLE mental_health_parity (worker_id INT,score INT);
SELECT c.name, SUM(m.score) FROM community_health_workers c INNER JOIN mental_health_parity m ON c.worker_id = m.worker_id WHERE c.state IN ('NY', 'PA') GROUP BY c.name;
Which actors have acted in both Action and Comedy movies?
CREATE TABLE movie (id INT,title VARCHAR(50),genre VARCHAR(20),language VARCHAR(20),viewers INT,rating DECIMAL(3,2),director VARCHAR(50),actor VARCHAR(50)); INSERT INTO movie (id,title,genre,language,viewers,rating,director,actor) VALUES (1,'Movie1','Animation','English',150000,8.5,'Director1','Actor1'),(2,'Movie2','Action','English',250000,7.8,'Director2','Actor2'),(3,'Movie3','Animation','French',200000,9.2,'Director1','Actor3'),(4,'Movie4','Drama','Spanish',100000,6.3,'Director3','Actor4'),(5,'Movie5','Animation','English',220000,9.0,'Director2','Actor1'),(6,'Movie6','Drama','French',180000,8.5,'Director1','Actor3'),(7,'Movie7','Comedy','English',150000,7.5,'Director4','Actor2'),(8,'Movie8','Action','English',200000,9.0,'Director2','Actor1'),(9,'Movie9','Comedy','French',250000,8.0,'Director1','Actor4');
SELECT actor FROM movie WHERE genre = 'Action' INTERSECT SELECT actor FROM movie WHERE genre = 'Comedy';
What is the sum of populations of 'Endangered' species in 'animal_population' table?
CREATE TABLE animal_population (id INT,animal_name VARCHAR(50),population INT,status VARCHAR(50)); INSERT INTO animal_population VALUES (1,'Tiger',500,'Endangered'),(2,'Elephant',800,'Vulnerable');
SELECT SUM(population) FROM animal_population WHERE status = 'Endangered';
What is the maximum production capacity of all silver mines in the 'mine_stats' table?
CREATE TABLE mine_stats (mine_name VARCHAR(255),mine_type VARCHAR(255),production_capacity FLOAT); INSERT INTO mine_stats (mine_name,mine_type,production_capacity) VALUES ('Silver Summit','silver',3000.2),('Quicksilver Quarry','silver',3500.4),('Mercury Mine','silver',2800.1);
SELECT MAX(production_capacity) FROM mine_stats WHERE mine_type = 'silver';
What is the percentage of employees with a STEM degree in each department?
CREATE TABLE department (id INT,name TEXT); INSERT INTO department (id,name) VALUES (1,'Operations'),(2,'Engineering'),(3,'HR'); CREATE TABLE employee (id INT,name TEXT,department_id INT,degree TEXT); INSERT INTO employee (id,name,department_id,degree) VALUES (1,'John Doe',1,'Business'),(2,'Jane Smith',1,'Computer Science'),(3,'Mike Johnson',2,'Mechanical Engineering');
SELECT department_id, degree, COUNT(*) as num_employees, ROUND(COUNT(*) * 100.0 / (SELECT COUNT(*) FROM employee WHERE department_id = department.id), 2) as percentage FROM employee WHERE degree LIKE '%STEM%' GROUP BY department_id, degree;
Get the total calories of all vegetarian dishes in 'Nourish Me'.
CREATE TABLE Restaurants (name text); INSERT INTO Restaurants (name) VALUES ('Nourish Me'); CREATE TABLE Menu (name text,restaurant text,food text,calories integer); INSERT INTO Menu (name,restaurant,food,calories) VALUES ('Nourish Me','Vegetarian Lasagna',600),('Nourish Me','Chickpea Salad',450);
SELECT SUM(calories) FROM Menu WHERE restaurant = 'Nourish Me' AND food LIKE '%vegetarian%';
List all biosensor technology patents filed in Asia.
CREATE TABLE patents (id INT,title VARCHAR(50),technology VARCHAR(50),location VARCHAR(50)); INSERT INTO patents (id,title,technology,location) VALUES (1,'BioSensor 1000','Biosensor','Germany'),(2,'BioSensor Pro','Biosensor','Asia');
SELECT title FROM patents WHERE technology = 'Biosensor' AND location = 'Asia';
List all the founders who have not yet founded a company.
CREATE TABLE founders (id INT,name TEXT,gender TEXT,company_id INT); INSERT INTO founders (id,name,gender,company_id) VALUES (1,'Alice','Female',1),(2,'Bob','Male',NULL),(3,'Charlie','Male',3),(4,'Diana','Female',4); CREATE TABLE companies (id INT,name TEXT); INSERT INTO companies (id,name) VALUES (1,'Acme Inc'),(2,'Beta Corp'),(3,'Gamma LLC'),(4,'Delta Co');
SELECT name FROM founders WHERE company_id IS NULL;
What is the total number of unique users who have streamed music in each genre?
CREATE TABLE genre_streams (stream_id INT,genre VARCHAR(255),user_id INT); CREATE TABLE user (user_id INT,user_name VARCHAR(255));
SELECT genre, COUNT(DISTINCT user_id) FROM genre_streams GROUP BY genre;
What was the total amount of donations received by each country in April 2021?
CREATE TABLE donations (id INT,country VARCHAR(50),donation_amount DECIMAL(10,2),donation_date DATE); INSERT INTO donations (id,country,donation_amount,donation_date) VALUES (1,'USA',500.00,'2021-04-01'),(2,'Canada',350.00,'2021-04-05'),(3,'Mexico',200.00,'2021-04-10');
SELECT country, SUM(donation_amount) as total_donations FROM donations WHERE donation_date BETWEEN '2021-04-01' AND '2021-04-30' GROUP BY country;
What is the total number of threat intelligence incidents by severity level?
CREATE TABLE ThreatIntelligence (IncidentID int,IncidentDate date,IncidentSeverity varchar(50)); INSERT INTO ThreatIntelligence (IncidentID,IncidentDate,IncidentSeverity) VALUES (1,'2022-01-15','High'),(2,'2022-03-01','Medium'),(3,'2022-04-10','High'),(4,'2022-07-05','Low'),(5,'2022-11-28','Medium');
SELECT IncidentSeverity, COUNT(*) as NumIncidents FROM ThreatIntelligence GROUP BY IncidentSeverity;
List all visitors from France or Japan
CREATE TABLE Visitor (id INT,name TEXT,country TEXT); INSERT INTO Visitor (id,name,country) VALUES (1,'Alice','France'),(2,'Bob','Japan'),(3,'Charlie','USA');
SELECT * FROM Visitor WHERE country IN ('France', 'Japan');
What is the average donation amount by US-based non-profit organizations in Q1 2021?
CREATE TABLE non_profit_orgs (id INT,name VARCHAR(100),country VARCHAR(50),avg_donation_amount DECIMAL(10,2)); INSERT INTO non_profit_orgs (id,name,country,avg_donation_amount) VALUES (1,'Hearts for Humanity','USA',250.00); INSERT INTO non_profit_orgs (id,name,country,avg_donation_amount) VALUES (2,'Education Empowerment','USA',150.00);
SELECT AVG(avg_donation_amount) FROM non_profit_orgs WHERE country = 'USA' AND QUARTER(registration_date) = 1;
How many 'Endangered' species are present in 'Habitat 4'?
CREATE TABLE Habitat4(animal_id INT,species VARCHAR(20),conservation_status VARCHAR(10),population INT); INSERT INTO Habitat4 VALUES (1,'Tiger','Endangered',15),(2,'Elephant','Vulnerable',20),(3,'Rhinoceros','Critically Endangered',25);
SELECT COUNT(DISTINCT species) FROM Habitat4 WHERE conservation_status = 'Endangered';
What is the distribution of fans by age for each hockey team?
CREATE TABLE fan_demographics (fan_id INT,age INT,team_id INT); INSERT INTO fan_demographics (fan_id,age,team_id) VALUES (1,22,1),(2,25,2),(3,30,1),(4,35,3),(5,40,2); CREATE TABLE teams (team_id INT,team_name VARCHAR(255),sport VARCHAR(255)); INSERT INTO teams (team_id,team_name,sport) VALUES (1,'Maple Leafs','Hockey'),(2,'Blackhawks','Hockey'),(3,'Cavaliers','Basketball');
SELECT t.team_name, f.age, COUNT(f.fan_id) fan_count FROM fan_demographics f JOIN teams t ON f.team_id = t.team_id WHERE t.sport = 'Hockey' GROUP BY t.team_name, f.age;
What is the total number of traditional and electric buses in the public_transportation table, grouped by fuel_type?
CREATE TABLE public_transportation (id INT,vehicle_type TEXT,fuel_type TEXT,manufacturer TEXT,year INT,total_vehicles INT); INSERT INTO public_transportation (id,vehicle_type,fuel_type,manufacturer,year,total_vehicles) VALUES (1,'Bus','Diesel','ABC Bus Co.',2015,500),(2,'Bus','Electric','XYZ Green Mobility',2020,300),(3,'Train','Electric','National Railways',2018,800);
SELECT fuel_type, COUNT(*) as total FROM public_transportation WHERE vehicle_type = 'Bus' GROUP BY fuel_type;
Which space missions have the highest and lowest cost in the SpaceMissions table?
CREATE TABLE SpaceMissions (mission_id INT,mission_name VARCHAR(50),cost FLOAT); INSERT INTO SpaceMissions (mission_id,mission_name,cost) VALUES (1,'Apollo 11',25500000.0),(2,'Mars Rover',2500000.0),(3,'Artemis 1',340000000.0);
SELECT mission_name, cost FROM (SELECT mission_name, cost, ROW_NUMBER() OVER (ORDER BY cost ASC) AS low_cost_rank, ROW_NUMBER() OVER (ORDER BY cost DESC) AS high_cost_rank FROM SpaceMissions) AS subquery WHERE low_cost_rank = 1 OR high_cost_rank = 1;
What is the total number of AI models in the 'explainable_ai' table that have a fairness score greater than 0.8 and a bias score less than 0.2?
CREATE TABLE explainable_ai (model_id INT,model_name TEXT,fairness_score FLOAT,bias_score FLOAT);
SELECT COUNT(*) FROM explainable_ai WHERE fairness_score > 0.8 AND bias_score < 0.2;
What is the maximum number of humanitarian assistance missions performed by any nation in the Americas in 2015?
CREATE TABLE HumanitarianAssistance (nation VARCHAR(50),year INT,mission_count INT); INSERT INTO HumanitarianAssistance (nation,year,mission_count) VALUES ('Brazil',2015,12),('Canada',2015,15),('Chile',2015,10),('United States',2015,20),('Mexico',2015,8);
SELECT MAX(mission_count) FROM HumanitarianAssistance WHERE nation IN ('Brazil', 'Canada', 'Chile', 'United States', 'Mexico') AND year = 2015;
What is the total number of volunteer hours and unique volunteers for each program in Q1 2023?
CREATE TABLE VolunteerHours (VolunteerHoursID int,VolunteerID int,ProgramID int,Hours decimal,HourDate date); CREATE TABLE Programs (ProgramID int,ProgramName varchar(50)); INSERT INTO VolunteerHours (VolunteerHoursID,VolunteerID,ProgramID,Hours,HourDate) VALUES (1,3,1,7,'2023-01-05'),(2,4,2,10,'2023-01-10'); INSERT INTO Programs (ProgramID,ProgramName) VALUES (1,'Education'),(2,'Health');
SELECT Programs.ProgramName, SUM(VolunteerHours.Hours) as TotalHours, COUNT(DISTINCT VolunteerID) as Volunteers FROM VolunteerHours JOIN Programs ON VolunteerHours.ProgramID = Programs.ProgramID WHERE YEAR(HourDate) = 2023 AND MONTH(HourDate) <= 3 GROUP BY ProgramName;
What is the minimum number of stations for subway routes in the 'west' region?
CREATE TABLE subway_routes (region VARCHAR(10),num_stations INT); INSERT INTO subway_routes (region,num_stations) VALUES ('east',8),('west',10),('north',12),('south',9);
SELECT MIN(num_stations) FROM subway_routes WHERE region = 'west';
What is the total number of members in each union?
CREATE TABLE unions (id INT,name VARCHAR(255),industry VARCHAR(255),member_count INT); INSERT INTO unions (id,name,industry,member_count) VALUES (1,'Union A','retail',500),(2,'Union B','technology',300),(3,'Union C','manufacturing',700);
SELECT name, SUM(member_count) FROM unions GROUP BY name;
Find the number of employees in each department for ManufacturerD
CREATE TABLE Departments (department_id INT,department_name VARCHAR(50),manufacturer_id INT); INSERT INTO Departments (department_id,department_name,manufacturer_id) VALUES (1,'Department1',4),(2,'Department2',4); CREATE TABLE Employees (employee_id INT,employee_name VARCHAR(50),department_id INT); INSERT INTO Employees (employee_id,employee_name,department_id) VALUES (1,'Employee1',1),(2,'Employee2',1),(3,'Employee3',2); CREATE TABLE Manufacturers (manufacturer_id INT,manufacturer_name VARCHAR(50),region VARCHAR(50)); INSERT INTO Manufacturers (manufacturer_id,manufacturer_name,region) VALUES (4,'ManufacturerD','North America');
SELECT d.department_name, COUNT(e.employee_id) AS num_employees FROM Departments d INNER JOIN Employees e ON d.department_id = e.department_id WHERE d.manufacturer_id = (SELECT manufacturer_id FROM Manufacturers WHERE manufacturer_name = 'ManufacturerD') GROUP BY d.department_name;
Determine the total investment in economic diversification projects in the 'econ_diversification' table.
CREATE TABLE econ_diversification (id INT,project_name VARCHAR(255),investment_amount FLOAT); INSERT INTO econ_diversification (id,project_name,investment_amount) VALUES (1,'Renewable Energy',800000),(2,'Tourism Development',600000);
SELECT SUM(investment_amount) FROM econ_diversification;
How many donors made donations in each age group (10-year intervals) in 2022?
CREATE TABLE donors (id INT,age INT,donation_date DATE,amount DECIMAL(10,2)); INSERT INTO donors (id,age,donation_date,amount) VALUES (1,30,'2022-01-05',100); INSERT INTO donors (id,age,donation_date,amount) VALUES (2,45,'2022-02-10',200);
SELECT FLOOR(age/10)*10 as age_group, COUNT(DISTINCT id) as donors_in_age_group FROM donors WHERE donation_date BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY age_group;
What is the ratio of sustainable to non-sustainable materials used in clothing production in Turkey?
CREATE TABLE Materials (id INT,name VARCHAR(255),sustainable BOOLEAN,country VARCHAR(255)); INSERT INTO Materials (id,name,sustainable,country) VALUES (1,'Organic Cotton',TRUE,'Turkey'); INSERT INTO Materials (id,name,sustainable,country) VALUES (2,'Conventional Cotton',FALSE,'Turkey');
SELECT (SUM(sustainable)::INT / COUNT(*)::FLOAT) * 100 FROM Materials WHERE country = 'Turkey'
List the donors who made donations in both the years 2017 and 2020.
CREATE TABLE Donors (DonorID INT,DonorName TEXT); CREATE TABLE Donations (DonationID INT,DonorID INT,DonationDate DATE,DonationAmount DECIMAL);
SELECT D.DonorName FROM Donors D JOIN Donations DON17 ON D.DonorID = DON17.DonorID JOIN Donations DON20 ON D.DonorID = DON20.DonorID WHERE YEAR(DON17.DonationDate) = 2017 AND YEAR(DON20.DonationDate) = 2020 GROUP BY D.DonorName HAVING COUNT(DISTINCT YEAR(DonationDate)) = 2;
What are the total revenue and ticket sales by genre for movies released in 2020?
CREATE TABLE movies (id INT,title VARCHAR(255),release_year INT,genre VARCHAR(255),revenue INT,tickets_sold INT); INSERT INTO movies (id,title,release_year,genre,revenue,tickets_sold) VALUES (1,'Movie1',2020,'Action',50000000,800000),(2,'Movie2',2020,'Comedy',35000000,650000),(3,'Movie3',2020,'Drama',40000000,700000);
SELECT genre, SUM(revenue) AS total_revenue, SUM(tickets_sold) AS total_tickets_sold FROM movies WHERE release_year = 2020 GROUP BY genre;
What is the average renewable energy consumption per green building?
CREATE TABLE GreenBuildings (BuildingID int,RenewableEnergyConsumption int);
SELECT AVG(GreenBuildings.RenewableEnergyConsumption) as AvgREConsumption FROM GreenBuildings;
How many climate finance initiatives were implemented in Small Island Developing States (SIDS) in 2021?
CREATE TABLE climate_finance (id INT,initiative_name VARCHAR(50),country VARCHAR(50),amount FLOAT,date DATE); INSERT INTO climate_finance (id,initiative_name,country,amount,date) VALUES (1,'Green Energy Investment','Fiji',750000,'2021-01-01');
SELECT COUNT(*) FROM climate_finance WHERE country LIKE '%Small Island%' AND date = '2021-01-01';
What is the average disability accommodation cost per student per year, partitioned by program type and ordered from highest to lowest?
CREATE TABLE Disability_Accommodations (Program_Type VARCHAR(20),Student_ID INT,Year INT,Cost DECIMAL(5,2)); INSERT INTO Disability_Accommodations VALUES ('Assistive Technology',1001,2021,500.00),('Assistive Technology',1001,2022,550.00),('ASL Interpretation',1002,2021,1200.00),('ASL Interpretation',1002,2022,1320.00),('Mobility Support',1003,2021,2000.00),('Mobility Support',1003,2022,2200.00);
SELECT Program_Type, AVG(Cost) as Avg_Cost, RANK() OVER (ORDER BY AVG(Cost) DESC) as Rank FROM Disability_Accommodations GROUP BY Program_Type ORDER BY Rank;
What is the average dissolved oxygen level for each species in Tank1?
CREATE TABLE Tank1 (species VARCHAR(50),dissolved_oxygen FLOAT); INSERT INTO Tank1 (species,dissolved_oxygen) VALUES ('Salmon',6.5),('Trout',7.2),('Tilapia',5.8);
SELECT species, AVG(dissolved_oxygen) FROM Tank1 GROUP BY species;
What is the percentage of students with disabilities who have completed a degree program in the last 3 years?
CREATE TABLE Student_Disabilities (student_id INT,disability_type TEXT,degree_status TEXT); CREATE VIEW Degree_Completion_Count AS SELECT disability_type,COUNT(*) FROM Student_Disabilities WHERE degree_status = 'Completed' AND YEAR(submission_date) BETWEEN YEAR(CURRENT_DATE)-3 AND YEAR(CURRENT_DATE) GROUP BY disability_type; CREATE VIEW Total_Students_With_Disabilities AS SELECT disability_type,COUNT(*) FROM Student_Disabilities GROUP BY disability_type;
SELECT Degree_Completion_Count.disability_type, (Degree_Completion_Count.COUNT(*) / Total_Students_With_Disabilities.COUNT(*))*100 AS percentage FROM Degree_Completion_Count INNER JOIN Total_Students_With_Disabilities ON Degree_Completion_Count.disability_type = Total_Students_With_Disabilities.disability_type;
What is the maximum depth in the Atlantic Ocean among all marine research stations?
CREATE TABLE ocean_depths (station_name VARCHAR(50),atlantic_depth FLOAT); INSERT INTO ocean_depths (station_name,atlantic_depth) VALUES ('Woods Hole Oceanographic Institution',2500.0),('Bermuda Institute of Ocean Sciences',5000.0);
SELECT MAX(atlantic_depth) FROM ocean_depths WHERE station_name IN ('Woods Hole Oceanographic Institution', 'Bermuda Institute of Ocean Sciences');
How many vegetarian dishes are offered in each category in the menu?
CREATE TABLE menu (item_id INT,item_name VARCHAR(255),category VARCHAR(255),is_vegetarian BOOLEAN);INSERT INTO menu (item_id,item_name,category,is_vegetarian) VALUES (1,'Quinoa Salad','Starters',true),(2,'Chickpea Curry','Entrees',true),(3,'Cheese Pizza','Entrees',false);
SELECT category, COUNT(*) FROM menu WHERE is_vegetarian = true GROUP BY category;
What is the total number of plays for all songs in the 'music_streaming' table?
CREATE TABLE music_streaming (song_id INT,song_name TEXT,artist_name TEXT,plays INT);
SELECT SUM(plays) FROM music_streaming;
What is the total value of military equipment sales to India in 2020, ordered by the highest sale first?
CREATE TABLE Military_Equipment_Sales(id INT,country VARCHAR(255),year INT,value FLOAT); INSERT INTO Military_Equipment_Sales(id,country,year,value) VALUES (1,'India',2020,50000000),(2,'India',2019,45000000),(3,'US',2020,80000000);
SELECT SUM(value) as Total_Value FROM Military_Equipment_Sales WHERE country = 'India' AND year = 2020 ORDER BY Total_Value DESC;
What is the total number of emergency incidents and crimes reported by community policing centers in region 1?
CREATE TABLE community_policing_centers (id INT,center_name TEXT,region TEXT); INSERT INTO community_policing_centers (id,center_name,region) VALUES (1,'Center A','Region 1'),(2,'Center B','Region 2'); CREATE TABLE emergency_incidents (id INT,center_id INT,incident_type TEXT,incident_count INT); INSERT INTO emergency_incidents (id,center_id,incident_type,incident_count) VALUES (1,1,'Fire',30),(2,1,'Medical',40),(3,2,'Fire',50),(4,2,'Medical',60); CREATE TABLE crimes_reported (id INT,center_id INT,crime_type TEXT,crime_count INT); INSERT INTO crimes_reported (id,center_id,crime_type,crime_count) VALUES (1,1,'Theft',20),(2,1,'Vandalism',10),(3,2,'Theft',30),(4,2,'Vandalism',20);
SELECT SUM(e.incident_count + cr.crime_count) AS total_incidents FROM community_policing_centers c JOIN emergency_incidents e ON c.id = e.center_id JOIN crimes_reported cr ON c.id = cr.center_id WHERE c.region = 'Region 1';
What is the average number of articles published per day by "Al Jazeera" in 2019?
CREATE TABLE articles (id INT,title TEXT,content TEXT,publication_date DATE,newspaper TEXT);
SELECT AVG(articles_per_day) FROM (SELECT COUNT(*)/COUNT(DISTINCT DATE(publication_date)) AS articles_per_day FROM articles WHERE newspaper = 'Al Jazeera' AND YEAR(publication_date) = 2019) t;
What is the maximum quantity of military equipment sold in a single transaction by Harris Corporation to European countries in Q2 2019?
CREATE TABLE Military_Equipment_Sales(equipment_id INT,manufacturer VARCHAR(255),purchaser VARCHAR(255),sale_date DATE,quantity INT);INSERT INTO Military_Equipment_Sales(equipment_id,manufacturer,purchaser,sale_date,quantity) VALUES (1,'Harris Corporation','Germany','2019-04-01',20),(2,'Harris Corporation','France','2019-06-15',30);
SELECT MAX(quantity) FROM Military_Equipment_Sales WHERE manufacturer = 'Harris Corporation' AND purchaser LIKE 'Europe%' AND sale_date BETWEEN '2019-04-01' AND '2019-06-30';
List all employees who have not completed diversity training, along with their hire dates.
CREATE TABLE Employees (EmployeeID INT,HireDate DATETIME,CompletedDiversityTraining BOOLEAN); INSERT INTO Employees (EmployeeID,HireDate,CompletedDiversityTraining) VALUES (1,'2020-01-01',true); INSERT INTO Employees (EmployeeID,HireDate,CompletedDiversityTraining) VALUES (2,'2019-05-15',false);
SELECT EmployeeID, HireDate FROM Employees WHERE CompletedDiversityTraining = false;
Who are the top 5 donors in terms of total donation amounts to environmental projects in South America?
CREATE TABLE donors (id INT,name TEXT,region TEXT); CREATE TABLE donations (id INT,donor_id INT,project_id INT,amount DECIMAL); CREATE TABLE projects (id INT,project_name TEXT,region TEXT); INSERT INTO donors (id,name,region) VALUES (1,'John Doe','North America'),(2,'Jane Smith','Europe'),(3,'Pedro Alvarez','South America'),(4,'Li Wong','Asia'); INSERT INTO donations (id,donor_id,project_id,amount) VALUES (1,1,1,5000.00),(2,1,2,7000.00),(3,2,2,3000.00),(4,3,3,8000.00),(5,4,3,12000.00); INSERT INTO projects (id,project_name,region) VALUES (1,'Tree Planting','South America'),(2,'Recycling Program','South America'),(3,'Ocean Cleanup','Global');
SELECT d.donor_id, d.name, SUM(d.amount) as total_donations FROM donors d INNER JOIN donations don ON d.id = don.donor_id INNER JOIN projects p ON don.project_id = p.id WHERE p.region = 'South America' AND p.project_name LIKE '%environment%' GROUP BY d.donor_id ORDER BY total_donations DESC LIMIT 5;
What is the average engagement rate for posts in each language in the past month?
CREATE TABLE posts (post_id INT,language VARCHAR(50),engagement_rate DECIMAL(5,2)); INSERT INTO posts (post_id,language,engagement_rate) VALUES (1,'English',0.10),(2,'Spanish',0.12),(3,'French',0.15),(4,'German',0.11),(5,'Italian',0.13);
SELECT language, AVG(engagement_rate) AS avg_engagement_rate FROM posts WHERE date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY language;
How many clinical trials were conducted for each drug in the 'ClinicalTrials' table, grouped by drug name?
CREATE TABLE ClinicalTrials (trial_id INT,drug_name VARCHAR(255),trial_status VARCHAR(255)); INSERT INTO ClinicalTrials (trial_id,drug_name,trial_status) VALUES (1,'DrugA','Completed'),(2,'DrugA','Failed'),(3,'DrugB','Completed'),(4,'DrugC','In Progress');
SELECT drug_name, COUNT(*) as total_trials FROM ClinicalTrials GROUP BY drug_name;
What is the market share of autonomous buses in Singapore?
CREATE TABLE buses (id INT,type VARCHAR(255),city VARCHAR(255),country VARCHAR(255),market_share FLOAT); INSERT INTO buses VALUES (1,'Autonomous','Singapore','Singapore',0.2);
SELECT market_share FROM buses WHERE type = 'Autonomous' AND city = 'Singapore';
What is the number of students who prefer open pedagogy and their respective district's average mental health score?
CREATE TABLE student_preference (student_id INT,district_id INT,preference VARCHAR(10)); CREATE TABLE student_mental_health (student_id INT,mental_health_score INT); INSERT INTO student_preference (student_id,district_id,preference) VALUES (1,101,'open'),(2,101,'traditional'),(3,102,'open'),(4,102,'open'),(5,103,'traditional'); INSERT INTO student_mental_health (student_id,mental_health_score) VALUES (1,75),(2,80),(3,65),(4,70),(5,85);
SELECT sp.district_id, COUNT(CASE WHEN sp.preference = 'open' THEN 1 END) AS num_open_students, AVG(smh.mental_health_score) AS avg_mental_health_score FROM student_preference sp JOIN student_mental_health smh ON sp.student_id = smh.student_id GROUP BY sp.district_id;
What is the maximum number of astronauts that have been on a single space mission for each space agency?
CREATE TABLE Space_Missions (id INT,mission_name VARCHAR(50),agency VARCHAR(50),num_astronauts INT); INSERT INTO Space_Missions (id,mission_name,agency,num_astronauts) VALUES (1,'Apollo 13','NASA',3),(2,'Soyuz T-15','Roscosmos',2),(3,'STS-61-A','NASA',8);
SELECT agency, MAX(num_astronauts) as max_num_astronauts FROM Space_Missions GROUP BY agency;
List the regulatory frameworks for the blockchain industry in each region, in alphabetical order by region name.
CREATE TABLE Regions (RegionID int,RegionName varchar(50),IndustryRegulations varchar(50)); INSERT INTO Regions (RegionID,RegionName,IndustryRegulations) VALUES (1,'Region1','RegulationA,RegulationB'),(2,'Region2','RegulationC,RegulationD'),(3,'Region3','RegulationE,RegulationF');
SELECT RegionName, IndustryRegulations FROM Regions ORDER BY RegionName;
What is the average soil moisture level for each crop type in the past year, grouped by quarters?
CREATE TABLE crop_data (id INT,crop_type VARCHAR(255),soil_moisture INT,timestamp TIMESTAMP); INSERT INTO crop_data (id,crop_type,soil_moisture,timestamp) VALUES (1,'Corn',75,'2021-01-01 10:00:00'),(2,'Soybeans',80,'2021-01-01 10:00:00');
SELECT crop_type, QUARTER(timestamp) AS quarter, AVG(soil_moisture) FROM crop_data WHERE timestamp >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 YEAR) GROUP BY crop_type, quarter;
What is the minimum rating of eco-friendly hotels in Australia?
CREATE TABLE eco_hotels_australia (hotel_id INT,hotel_name TEXT,country TEXT,rating FLOAT); INSERT INTO eco_hotels_australia (hotel_id,hotel_name,country,rating) VALUES (1,'Eco-Retreat Australia','Australia',4.2),(2,'Green Hotel Sydney','Australia',4.5);
SELECT MIN(rating) FROM eco_hotels_australia WHERE country = 'Australia';
Show the number of times each crop type was planted in the last 3 months
CREATE TABLE planting_data (planting_date DATE,crop_type VARCHAR(20)); INSERT INTO planting_data (planting_date,crop_type) VALUES ('2022-04-01','Corn'),('2022-04-15','Soybeans'),('2022-05-01','Wheat'),('2022-05-15','Corn'),('2022-06-01','Soybeans');
SELECT crop_type, COUNT(*) FROM planting_data WHERE planting_date >= DATE_SUB(CURDATE(), INTERVAL 3 MONTH) GROUP BY crop_type;
What is the total amount donated by individual donors from Japan and Argentina in 2020?
CREATE TABLE Donors (DonorID INT,DonorName TEXT,Country TEXT); INSERT INTO Donors (DonorID,DonorName,Country) VALUES (1,'Hiroshi Yamada','Japan'),(2,'María González','Argentina'); CREATE TABLE Donations (DonationID INT,DonorID INT,Amount DECIMAL,DonationYear INT); INSERT INTO Donations (DonationID,DonorID,Amount,DonationYear) VALUES (1,1,120,2020),(2,2,180,2020);
SELECT SUM(d.Amount) FROM Donations d JOIN Donors don ON d.DonorID = don.DonorID WHERE don.Country IN ('Japan', 'Argentina') AND d.DonationYear = 2020;
Find the top 3 destinations for tourists from India with the highest average eco-rating.
CREATE TABLE destinations (id INT,destination VARCHAR(50),num_tourists INT,avg_eco_rating FLOAT); INSERT INTO destinations (id,destination,num_tourists,avg_eco_rating) VALUES (1,'Bali',1200,8.5),(2,'Maldives',1500,8.7),(3,'New Zealand',1800,9.2),(4,'Costa Rica',900,9.0),(5,'Nepal',1000,8.8); CREATE TABLE source_countries (id INT,country VARCHAR(50),num_tourists INT); INSERT INTO source_countries (id,country,num_tourists) VALUES (1,'India',2000),(2,'China',1500),(3,'United States',1800),(4,'Australia',1200),(5,'Canada',1000);
SELECT d.destination, d.avg_eco_rating FROM destinations d JOIN source_countries sc ON d.id = sc.id WHERE sc.country = 'India' ORDER BY d.avg_eco_rating DESC LIMIT 3;
How many virtual tours were engaged in the DACH region during the last month?
CREATE TABLE virtual_tours_2 (tour_id INT,country TEXT,engagement_date DATE); INSERT INTO virtual_tours_2 (tour_id,country,engagement_date) VALUES (1,'Germany','2022-02-05'),(2,'Switzerland','2022-03-10'),(3,'Austria','2022-04-15'),(4,'Germany','2022-03-20');
SELECT COUNT(*) FROM virtual_tours_2 WHERE country IN ('Germany', 'Switzerland', 'Austria') AND engagement_date >= DATEADD(month, -1, GETDATE());
What is the sum of fish biomass for each aquafarm in the Salmon_Farming table?
CREATE TABLE Salmon_Farming (Farm_ID INT,Farm_Name TEXT,Location TEXT,Fish_Biomass FLOAT); INSERT INTO Salmon_Farming (Farm_ID,Farm_Name,Location,Fish_Biomass) VALUES (1,'Farm 1','Norway',3500.5),(2,'Farm 2','Norway',4200.3),(3,'Farm 3','Scotland',5000.0);
SELECT Location, SUM(Fish_Biomass) FROM Salmon_Farming GROUP BY Location;
What is the maximum property price for sustainable urbanism properties in Texas?
CREATE TABLE sustainable_urbanism (id INT,price FLOAT,state VARCHAR(20)); INSERT INTO sustainable_urbanism (id,price,state) VALUES (1,700000,'Texas'),(2,800000,'Texas'),(3,900000,'Texas');
SELECT MAX(price) FROM sustainable_urbanism WHERE state = 'Texas';
What is the total number of sustainable tourism certifications awarded per month in the Americas in 2023?
CREATE TABLE CertificationRecords (CertificationID INT,CertificationDate DATE,CertificationType VARCHAR(50),Country VARCHAR(50)); INSERT INTO CertificationRecords (CertificationID,CertificationDate,CertificationType,Country) VALUES (1,'2023-01-01','Sustainable Tourism','Canada'),(2,'2023-02-01','Sustainable Tourism','Brazil'),(3,'2023-03-01','Sustainable Tourism','USA');
SELECT EXTRACT(MONTH FROM CertificationDate), SUM(CASE WHEN Country IN ('Canada', 'USA', 'Brazil') THEN 1 ELSE 0 END) AS TotalCertifications FROM CertificationRecords WHERE CertificationType = 'Sustainable Tourism' AND CertificationDate BETWEEN '2023-01-01' AND '2023-12-31' GROUP BY EXTRACT(MONTH FROM CertificationDate);
List the number of investments by round for companies with female founders.
CREATE TABLE companies (id INT,name TEXT,founded_date DATE,founder_gender TEXT); INSERT INTO companies (id,name,founded_date,founder_gender) VALUES (1,'Acme Inc','2010-01-01','female'); INSERT INTO companies (id,name,founded_date,founder_gender) VALUES (2,'Beta Corp','2015-05-15','male'); CREATE TABLE investments (id INT,company_id INT,round_number INT,funding_amount INT); INSERT INTO investments (id,company_id,round_number,funding_amount) VALUES (1,1,1,500000); INSERT INTO investments (id,company_id,round_number,funding_amount) VALUES (2,2,1,2000000);
SELECT company_id, round_number, COUNT(*) FROM investments JOIN companies ON investments.company_id = companies.id WHERE companies.founder_gender = 'female' GROUP BY company_id, round_number;
Find the average sustainable sourcing score for each menu category in May 2022.
CREATE TABLE sustainable_sourcing_2 (menu_category VARCHAR(255),score INT,sourcing_date DATE); INSERT INTO sustainable_sourcing_2 (menu_category,score,sourcing_date) VALUES ('Appetizers',85,'2022-05-01'),('Entrees',90,'2022-05-01');
SELECT menu_category, AVG(score) FROM sustainable_sourcing_2 WHERE sourcing_date BETWEEN '2022-05-01' AND '2022-05-31' GROUP BY menu_category;
What is the maximum number of total employees in workplaces that have successful collective bargaining?
CREATE TABLE workplaces (id INT,name TEXT,location TEXT,sector TEXT,total_employees INT,union_members INT,successful_cb BOOLEAN,cb_year INT);
SELECT MAX(total_employees) FROM workplaces WHERE successful_cb = TRUE;
What is the average daily transaction amount for clients in the 'International' division for the month of January 2022?
CREATE TABLE Clients (ClientID int,Name varchar(50),Division varchar(50),Country varchar(50)); INSERT INTO Clients (ClientID,Name,Division,Country) VALUES (10,'Alex Thompson','High Net Worth','USA'),(11,'Bella Chen','Retail','China'),(12,'Charlie Lee','High Net Worth','Canada'),(13,'Dana Kim','International','South Korea'); CREATE TABLE Transactions (TransactionID int,ClientID int,Amount decimal(10,2),TransactionDate date); INSERT INTO Transactions (TransactionID,ClientID,Amount,TransactionDate) VALUES (100,10,5000,'2022-01-01'),(101,10,7000,'2022-01-02'),(102,11,3000,'2022-01-03'),(103,12,8000,'2022-01-04'),(104,11,9000,'2022-01-05'),(105,11,10000,'2022-01-06');
SELECT AVG(t.Amount) as AverageDailyTransactionAmount FROM Clients c INNER JOIN Transactions t ON c.ClientID = t.ClientID WHERE c.Division = 'International' AND c.Country = 'South Korea' AND t.TransactionDate BETWEEN '2022-01-01' AND '2022-01-31' GROUP BY t.TransactionDate;
Identify the top 3 most common traditional art forms in Africa and their respective total number of practitioners.
CREATE TABLE africa_art_forms (id INT,art_form TEXT,country TEXT,num_practitioners INT); INSERT INTO africa_art_forms (id,art_form,country,num_practitioners) VALUES (1,'Batik','Nigeria',5000),(2,'Adinkra','Ghana',3000),(3,'Thanga','India',2000),(4,'Ukara','Tanzania',1000),(5,'Mudcloth','Mali',4000);
SELECT art_form, SUM(num_practitioners) as total_num_practitioners FROM africa_art_forms WHERE country IN ('Nigeria', 'Ghana', 'Mali') GROUP BY art_form ORDER BY total_num_practitioners DESC LIMIT 3;
What is the average mental health score for students in each gender, grouped by age?
CREATE TABLE students (id INT,name VARCHAR(50),gender VARCHAR(10),mental_health_score INT,age INT); INSERT INTO students (id,name,gender,mental_health_score,age) VALUES (1,'John Doe','Male',70,18);
SELECT gender, age, AVG(mental_health_score) as avg_score FROM students GROUP BY gender, age;
List all the community policing initiatives in the southern and eastern regions.
CREATE TABLE regions (region_id INT,region_name VARCHAR(255)); INSERT INTO regions (region_id,region_name) VALUES (1,'Northern'),(2,'Southern'),(3,'Eastern'),(4,'Western'); CREATE TABLE community_policing (initiative_id INT,region_id INT,initiative_name VARCHAR(255));
SELECT r.region_name, c.initiative_name FROM community_policing c INNER JOIN regions r ON c.region_id = r.region_id WHERE r.region_name IN ('Southern', 'Eastern');
How many members have a smartwatch as their wearable device?
CREATE TABLE Members (MemberID INT,Age INT,FavoriteExercise VARCHAR(20)); CREATE TABLE Wearables (DeviceID INT,MemberID INT,Type VARCHAR(20)); INSERT INTO Members (MemberID,Age,FavoriteExercise) VALUES (1,35,'Yoga'); INSERT INTO Members (MemberID,Age,FavoriteExercise) VALUES (2,28,'Running'); INSERT INTO Wearables (DeviceID,MemberID,Type) VALUES (1,1,'Smartwatch'); INSERT INTO Wearables (DeviceID,MemberID,Type) VALUES (2,1,'Band');
SELECT COUNT(*) FROM Members JOIN Wearables ON Members.MemberID = Wearables.MemberID WHERE Type = 'Smartwatch';
What is the average number of professional development hours for teachers in 'Fall 2022'?
CREATE TABLE teacher_pd (teacher_id INT,pd_hours INT,date DATE); INSERT INTO teacher_pd (teacher_id,pd_hours,date) VALUES (1,10,'2022-08-01'); CREATE VIEW fall_2022_pd AS SELECT teacher_id,AVG(pd_hours) as avg_pd_hours FROM teacher_pd WHERE date BETWEEN '2022-08-01' AND '2022-12-31' GROUP BY teacher_id;
SELECT AVG(avg_pd_hours) as avg_pd_hours_fall22 FROM fall_2022_pd;
Count the number of community policing events per officer in 2022
CREATE TABLE community_policing_2022 (id INT,officer_id INT,event_date DATE,event_type VARCHAR(20)); INSERT INTO community_policing_2022 (id,officer_id,event_date,event_type) VALUES (1,101,'2022-01-01','Meeting'),(2,102,'2022-01-15','Patrol'),(3,101,'2022-04-01','Meeting'),(4,103,'2022-07-01','Workshop');
SELECT officer_id, COUNT(*) as total_events FROM community_policing_2022 GROUP BY officer_id;
Insert a new building 'WindHaven' built in 2022 with CO2 emission 80.0.
CREATE TABLE Buildings (id INT,name TEXT,year_built INT,co2_emission FLOAT);
INSERT INTO Buildings (name, year_built, co2_emission) VALUES ('WindHaven', 2022, 80.0);
Which artworks were added to the 'Metropolitan Museum of Art' in the last 3 months?
CREATE TABLE artworks (id INT,museum_id INT,name TEXT,date_added DATE); INSERT INTO artworks (id,museum_id,name,date_added) VALUES (1,1,'Mona Lisa','2021-01-01'),(2,1,'Starry Night','2021-02-01'),(3,2,'David','2022-03-15'),(4,3,'Guernica','2022-04-01'),(5,1,'The Persistence of Memory','2022-05-01');
SELECT name FROM artworks WHERE museum_id = 1 AND date_added >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH);
Delete records in the "defense_diplomacy" table for 'Colombia' in 2018 and 'Brazil' in 2020
CREATE TABLE defense_diplomacy (id INT PRIMARY KEY,country VARCHAR(50),year INT,type VARCHAR(20)); INSERT INTO defense_diplomacy (id,country,year,type) VALUES (1,'Colombia',2018,'Bilateral'),(2,'Brazil',2020,'Multilateral');
DELETE FROM defense_diplomacy WHERE (country = 'Colombia' AND year = 2018) OR (country = 'Brazil' AND year = 2020);
Delete all records in the 'accidents' table where the 'vehicle_make' is 'Tesla'
CREATE TABLE accidents (id INT PRIMARY KEY,vehicle_make VARCHAR(255),accident_count INT);
DELETE FROM accidents WHERE vehicle_make = 'Tesla';
What is the number of spacecrafts manufactured by each manufacturer?
CREATE TABLE SpacecraftManufacturerCount (Manufacturer VARCHAR(50),TotalSpacecrafts INT); INSERT INTO SpacecraftManufacturerCount (Manufacturer,TotalSpacecrafts) VALUES ('Galactic Spacecraft Inc.',100),('Nebula Spacecrafts',500),('Cosmic Engineering',350);
SELECT Manufacturer, COUNT(*) FROM SpacecraftManufacturerCount GROUP BY Manufacturer
What are the names of suppliers who have provided chemicals with a hazard level greater than 7 in the last 6 months?
CREATE TABLE chemical_suppliers (id INT PRIMARY KEY,chemical_id INT,supplier_name VARCHAR(255),last_purchase_date DATE); CREATE TABLE chemicals (id INT PRIMARY KEY,hazard_level INT);
SELECT DISTINCT cs.supplier_name FROM chemical_suppliers cs JOIN chemicals c ON cs.chemical_id = c.id WHERE c.hazard_level > 7 AND cs.last_purchase_date > (CURRENT_DATE - INTERVAL '6 months');
Which marine species are affected by plastic pollution in the Indian Ocean?
CREATE TABLE Indian_Ocean_Pollution (pollutant TEXT,location TEXT,affected_species TEXT); INSERT INTO Indian_Ocean_Pollution (pollutant,location,affected_species) VALUES ('Microplastics','Arabian Sea','Omani Sardine,Whale Shark'),('Plastic Waste','Bay of Bengal','Indian Oil Sardine,Bottlenose Dolphin');
SELECT affected_species FROM Indian_Ocean_Pollution WHERE pollutant = 'Microplastics' OR pollutant = 'Plastic Waste';
What is the maximum quantity of organic meat consumed in Australia?
CREATE TABLE consumptions (id INT,product VARCHAR(50),is_organic BOOLEAN,quantity INT); INSERT INTO consumptions (id,product,is_organic,quantity) VALUES (1,'Beef',true,1000),(2,'Chicken',true,800);
SELECT MAX(quantity) FROM consumptions WHERE is_organic = true AND product LIKE '%Meat%' AND country = 'Australia';
Show the number of players who played more than 100 hours of a specific game genre in the last year.
CREATE TABLE GameSessions (PlayerID INT,GameGenre VARCHAR(255),SessionDuration FLOAT,SessionDate DATE); INSERT INTO GameSessions (PlayerID,GameGenre,SessionDuration,SessionDate) VALUES (1,'RPG',50.5,'2021-05-01'),(2,'FPS',130.3,'2021-07-10');
SELECT GameGenre, COUNT(PlayerID) as PlayersCount FROM GameSessions WHERE SessionDate BETWEEN DATEADD(year, -1, CURRENT_DATE) AND CURRENT_DATE AND SessionDuration > 100 GROUP BY GameGenre;
Delete any program records with a budget over $100,000 and a program type of 'Education'.
CREATE TABLE programs (id INT,budget INT,program_type VARCHAR(20)); INSERT INTO programs (id,budget,program_type) VALUES (1,120000,'Education'),(2,50000,'Health'),(3,80000,'Arts');
DELETE FROM programs WHERE budget > 100000 AND program_type = 'Education';
What is the percentage of positive citizen feedback on road maintenance?
CREATE TABLE feedback (id INT,area TEXT,category TEXT,sentiment TEXT); INSERT INTO feedback (id,area,category,sentiment) VALUES (1,'State A','road maintenance','positive'),(2,'City B','road maintenance','negative'),(3,'State A','road maintenance','positive');
SELECT (COUNT(*) FILTER (WHERE sentiment = 'positive')) * 100.0 / COUNT(*) AS percentage FROM feedback WHERE category = 'road maintenance';
What is the total funding for biotech startups in Asia?
CREATE SCHEMA if not exists funding; USE funding; CREATE TABLE if not exists startup_funding (id INT,name VARCHAR(255),region VARCHAR(255),funding DECIMAL(10,2)); INSERT INTO startup_funding (id,name,region,funding) VALUES (1,'Startup A','Asia',18000000.00),(2,'Startup B','USA',25000000.00),(3,'Startup C','Europe',10000000.00);
SELECT SUM(funding) FROM funding.startup_funding WHERE region = 'Asia';
What is the total number of mental health parity violations reported in Japan in 2021?
CREATE TABLE mental_health_parity (id INT,violation_date DATE,location TEXT); INSERT INTO mental_health_parity (id,violation_date,location) VALUES (1,'2021-01-01','Japan'); INSERT INTO mental_health_parity (id,violation_date,location) VALUES (2,'2021-02-01','South Korea'); INSERT INTO mental_health_parity (id,violation_date,location) VALUES (3,'2021-03-01','Japan');
SELECT COUNT(*) FROM mental_health_parity WHERE violation_date >= '2021-01-01' AND violation_date < '2022-01-01' AND location = 'Japan';
What is the total number of seismic retrofits performed on buildings in California?
CREATE TABLE Buildings (id INT,name VARCHAR(100),state VARCHAR(50),seismic_retrofit BOOLEAN); INSERT INTO Buildings (id,name,state,seismic_retrofit) VALUES (1,'City Hall','California',TRUE),(2,'Library','California',FALSE),(3,'Police Station','California',TRUE);
SELECT COUNT(*) FROM Buildings WHERE state = 'California' AND seismic_retrofit = TRUE;
Delete records of products that have never received a safety violation but are not cruelty-free certified.
CREATE TABLE products (product_id INT,product_name TEXT,is_cruelty_free BOOLEAN); CREATE TABLE safety_records (record_id INT,product_id INT,violation_date DATE);
DELETE FROM products USING safety_records WHERE products.product_id = safety_records.product_id AND products.is_cruelty_free = FALSE AND safety_records.record_id IS NULL;
Find all destinations with CO2 emissions below the average in the Sustainable_Tourism table.
CREATE TABLE Sustainable_Tourism (Destination VARCHAR(50),CO2_Emissions INT,Water_Usage INT); INSERT INTO Sustainable_Tourism (Destination,CO2_Emissions,Water_Usage) VALUES ('Bali',120,3500),('Kyoto',80,2000),('Rio de Janeiro',150,4000);
SELECT Destination FROM Sustainable_Tourism WHERE CO2_Emissions < (SELECT AVG(CO2_Emissions) FROM Sustainable_Tourism);
What is the sum of all Shariah-compliant and socially responsible loans issued in the month of June 2021?
CREATE TABLE shariah_loans (id INT,amount DECIMAL,date DATE); INSERT INTO shariah_loans (id,amount,date) VALUES (1,5000,'2021-06-05'),(2,7000,'2021-06-07'); CREATE TABLE socially_responsible_loans (id INT,amount DECIMAL,date DATE); INSERT INTO socially_responsible_loans (id,amount,date) VALUES (1,3000,'2021-06-02'),(2,4000,'2021-06-08');
SELECT SUM(amount) FROM shariah_loans WHERE EXTRACT(MONTH FROM date) = 6 UNION ALL SELECT SUM(amount) FROM socially_responsible_loans WHERE EXTRACT(MONTH FROM date) = 6;
Who is the top donor in terms of total donation amount?
CREATE TABLE Donors (DonorID INT,Name TEXT,DonationAmount DECIMAL);
SELECT Name, SUM(DonationAmount) AS TotalDonation FROM Donors GROUP BY Name ORDER BY TotalDonation DESC LIMIT 1;
Who are the top 3 intelligence agency directors by tenure?
CREATE TABLE intelligence_agencies (agency_id INT PRIMARY KEY,agency_name VARCHAR(255),director_name VARCHAR(255),director_start_date DATE,director_end_date DATE); INSERT INTO intelligence_agencies (agency_id,agency_name,director_name,director_start_date,director_end_date) VALUES (1,'CIA','William Burns','2021-03-19','NULL'),(2,'FBI','Christopher Wray','2017-08-02','NULL'),(3,'NSA','Paul Nakasone','2018-05-04','NULL'),(4,'DHS','Alejandro Mayorkas','2021-02-02','NULL');
SELECT director_name, DATEDIFF(day, director_start_date, director_end_date) AS tenure FROM intelligence_agencies ORDER BY tenure DESC LIMIT 3;
List the top 3 sustainable menu items based on their sales and sustainability scores for a particular restaurant in Q2 2021.
CREATE TABLE menu (menu_id INT,restaurant_id INT,food_category TEXT,price DECIMAL(5,2),sustainability_score INT); CREATE TABLE restaurant (restaurant_id INT,name TEXT); INSERT INTO restaurant (restaurant_id,name) VALUES (1,'Restaurant B'),(2,'Restaurant C'); INSERT INTO menu (menu_id,restaurant_id,food_category,price,sustainability_score) VALUES (1,1,'Appetizers',7.99,80),(2,1,'Entrees',14.99,90),(3,1,'Desserts',6.50,70),(4,2,'Appetizers',9.99,95),(5,2,'Entrees',19.99,85),(6,2,'Desserts',7.99,75);
SELECT m.food_category, m.price, m.sustainability_score, SUM(m.price) AS total_sales FROM menu m JOIN restaurant r ON m.restaurant_id = r.restaurant_id WHERE r.name = 'Restaurant B' AND m.price > 0 AND EXTRACT(MONTH FROM m.order_date) BETWEEN 4 AND 6 AND EXTRACT(YEAR FROM m.order_date) = 2021 GROUP BY m.menu_id, m.food_category, m.price, m.sustainability_score ORDER BY total_sales DESC, m.sustainability_score DESC LIMIT 3;
Retrieve the name, age, and ethnicity of all students with disability accommodations
CREATE TABLE student_demographics (id INT PRIMARY KEY,name VARCHAR(255),age INT,gender VARCHAR(50),ethnicity VARCHAR(50)); CREATE TABLE disability_accommodations (id INT PRIMARY KEY,student_id INT,faculty_id INT,accommodation_type VARCHAR(50),start_date DATE,end_date DATE);
SELECT student_demographics.name, student_demographics.age, student_demographics.ethnicity FROM student_demographics INNER JOIN disability_accommodations ON student_demographics.id = disability_accommodations.student_id;
List the donors who have donated more than once in a single month, and the dates of their donations.
CREATE TABLE Donations (DonationID int,DonorID int,DonationDate date,AmountDonated float); INSERT INTO Donations (DonationID,DonorID,DonationDate,AmountDonated) VALUES (1,1,'2022-01-01',5000.00),(2,2,'2022-02-01',7000.00),(3,1,'2022-03-01',8000.00),(4,1,'2022-03-05',3000.00);
SELECT DonorID, DonationDate FROM Donations D1 WHERE DonorID IN (SELECT DonorID FROM Donations D2 WHERE D1.DonorID = D2.DonorID AND MONTH(D1.DonationDate) = MONTH(D2.DonationDate) AND YEAR(D1.DonationDate) = YEAR(D2.DonationDate) AND D1.DonationID <> D2.DonationID);
What is the next scheduled launch date for Blue Origin missions?
CREATE TABLE BlueOrigin (ID INT,Mission VARCHAR(50),LaunchDate DATE); INSERT INTO BlueOrigin (ID,Mission,LaunchDate) VALUES (1,'New Shepard','2022-08-01'),(2,'New Glenn','2023-02-15'),(3,'Blue Moon','2024-01-01');
SELECT Mission, LEAD(LaunchDate) OVER (ORDER BY LaunchDate) as NextLaunchDate FROM BlueOrigin;
Delete all records from the 'research_projects' table where the 'project_type' is 'genomics'
CREATE TABLE research_projects (project_id INT PRIMARY KEY,project_name VARCHAR(50),project_type VARCHAR(50));
DELETE FROM research_projects WHERE project_type = 'genomics';