instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Calculate the total number of workers at mining sites located in 'CO' or 'WY'.
CREATE TABLE sites (site_id INT,state VARCHAR(2),num_workers INT,acres FLOAT);
SELECT state, SUM(num_workers) as total_workers FROM sites WHERE state IN ('CO', 'WY') GROUP BY state;
What is the total revenue generated from postpaid mobile plans in the last quarter?
CREATE TABLE mobile_plans (id INT,plan_type VARCHAR(20),quarter DATE,revenue DECIMAL(10,2)); CREATE TABLE customers (id INT,plan_id INT); INSERT INTO mobile_plans (id,plan_type,quarter,revenue) VALUES (1,'postpaid','2022-01-01',50.00),(2,'postpaid','2022-01-01',60.00),(3,'prepaid','2022-01-01',40.00); INSERT INTO customers (id,plan_id) VALUES (1,1),(2,2),(3,3);
SELECT SUM(revenue) FROM mobile_plans INNER JOIN customers ON mobile_plans.id = customers.plan_id WHERE plan_type = 'postpaid' AND quarter BETWEEN DATE_SUB('2022-04-01', INTERVAL 3 MONTH) AND '2022-04-01';
Identify the top 5 customers with the highest transaction values in the "debit_card" table for the month of January 2022.
CREATE TABLE customer (customer_id INT,name VARCHAR(50),country VARCHAR(50)); CREATE TABLE debit_card (transaction_id INT,customer_id INT,value DECIMAL(10,2),timestamp TIMESTAMP);
SELECT c.name, SUM(dc.value) as total_value FROM customer c JOIN debit_card dc ON c.customer_id = dc.customer_id WHERE MONTH(dc.timestamp) = 1 AND YEAR(dc.timestamp) = 2022 GROUP BY c.customer_id ORDER BY total_value DESC LIMIT 5;
How many players are active in each region per day?
CREATE TABLE daily_activity (player_id INT,activity_date DATE,region VARCHAR(255)); INSERT INTO daily_activity (player_id,activity_date,region) VALUES (1,'2022-05-01','North America'),(2,'2022-05-02','Europe'),(3,'2022-05-03','Asia');
SELECT activity_date, region, COUNT(player_id) as num_players FROM daily_activity GROUP BY activity_date, region;
Update the instrument of the participant 'Mia' in the 'Music Concerts' table to 'Cello'.
CREATE TABLE music_concerts (concert_id INT,participant_name VARCHAR(50),instrument VARCHAR(50)); INSERT INTO music_concerts (concert_id,participant_name,instrument) VALUES (1,'Mia','Violin'),(2,'Nora','Piano'),(3,'Olivia','Flute');
UPDATE music_concerts SET instrument = 'Cello' WHERE participant_name = 'Mia';
What is the total number of posts for users from the "social_media" platform who have more than 100000 followers?
CREATE TABLE user_data (user_id INT,username VARCHAR(50),country VARCHAR(50),followers INT,posts INT); INSERT INTO user_data (user_id,username,country,followers,posts) VALUES (1,'user1','USA',100000,50),(2,'user2','Canada',120000,75),(3,'user3','Mexico',150000,100),(4,'user4','Brazil',200000,125),(5,'user5','Australia',80000,80),(6,'user6','India',250000,150),(7,'user7','China',300000,175),(8,'user8','Germany',180000,110);
SELECT SUM(posts) as total_posts FROM user_data WHERE followers > 100000;
What is the average duration of Indian movies?
CREATE TABLE media_contents (content_id INTEGER,title VARCHAR(255),duration INTEGER,production_country VARCHAR(100)); INSERT INTO media_contents (content_id,title,duration,production_country) VALUES (1,'Content1',120,'USA'),(2,'Content2',90,'Canada'),(3,'BollywoodRocks',180,'India'),(4,'Content4',100,'France');
SELECT AVG(duration) FROM media_contents WHERE production_country = 'India';
What is the maximum transaction amount in Florida?
CREATE TABLE clients (id INT,name TEXT,age INT,state TEXT,transaction_amount DECIMAL(10,2)); INSERT INTO clients (id,name,age,state,transaction_amount) VALUES (1,'John Doe',35,'Florida',700.00); INSERT INTO clients (id,name,age,state,transaction_amount) VALUES (2,'Jane Smith',40,'Florida',650.50);
SELECT MAX(transaction_amount) FROM clients WHERE state = 'Florida';
Which advocacy campaigns were launched in 'advocacy' table, and when, excluding campaigns launched in 2021?
CREATE TABLE advocacy (id INT,campaign VARCHAR(50),launch_date DATE,end_date DATE); INSERT INTO advocacy (id,campaign,launch_date,end_date) VALUES (1,'Child Rights','2021-01-01','2021-12-31'),(2,'Gender Equality','2021-02-01','2021-12-31'),(3,'Human Rights','2020-01-01','2020-12-31');
SELECT campaign, launch_date FROM advocacy WHERE launch_date < '2021-01-01';
What is the total revenue for each inventory category?
CREATE TABLE inventory (inventory_id INT,item_name VARCHAR(50),inventory_category VARCHAR(50),quantity INT,revenue DECIMAL(10,2)); INSERT INTO inventory (inventory_id,item_name,inventory_category,quantity,revenue) VALUES (1,'Tomato','Produce',50,500.00),(2,'Chicken Breast','Meat',100,1200.00),(3,'Vanilla Ice Cream','Dairy',75,750.00);
SELECT inventory_category, SUM(revenue) FROM inventory GROUP BY inventory_category;
Who is the oldest employee with the title 'Mining Engineer' in the 'mining_company' database?
CREATE TABLE employees(id INT,name VARCHAR(255),title VARCHAR(255),age INT); INSERT INTO employees(id,name,title,age) VALUES ('1','Jane Smith','Mining Engineer','50');
SELECT name, age FROM employees WHERE title = 'Mining Engineer' ORDER BY age DESC LIMIT 1;
List all materials with their embodied carbon and recycled content percentage, ordered by recycled content percentage in descending order
CREATE TABLE sustainable_materials (material_name TEXT,recycled_content_percentage FLOAT,embodied_carbon_kg_co2 FLOAT); INSERT INTO sustainable_materials (material_name,recycled_content_percentage,embodied_carbon_kg_co2) VALUES ('Recycled Steel',95,0.65),('Reclaimed Concrete',85,0.95),('New Timber',10,1.5);
SELECT * FROM sustainable_materials ORDER BY recycled_content_percentage DESC;
What is the minimum rating of TV shows produced in the USA and Canada?
CREATE TABLE TVShows (tv_show_id INT,title VARCHAR(255),rating FLOAT,production_country VARCHAR(50)); INSERT INTO TVShows (tv_show_id,title,rating,production_country) VALUES (1,'TVShow1',7.5,'USA'),(2,'TVShow2',8.2,'Canada'),(3,'TVShow3',6.9,'Mexico');
SELECT MIN(rating) FROM TVShows WHERE production_country IN ('USA', 'Canada');
Update the capacity of the record with id 2001 in the 'battery_storage' table to 1500
CREATE TABLE battery_storage (id INT PRIMARY KEY,manufacturer VARCHAR(50),installed_year INT,capacity FLOAT);
UPDATE battery_storage SET capacity = 1500 WHERE id = 2001;
List unique last names of attorneys who handled more than 30 bankruptcy cases and their respective counts.
CREATE TABLE bankruptcy_cases (case_id INT,attorney_id INT,attorney_last_name VARCHAR(50));
SELECT attorney_last_name, COUNT(*) as case_count FROM bankruptcy_cases GROUP BY attorney_last_name HAVING COUNT(*) > 30;
What is the total population of each shark species, excluding the Great White?
CREATE TABLE Sharks (id INT PRIMARY KEY,name VARCHAR(50),species VARCHAR(50),location VARCHAR(50),population INT); INSERT INTO Sharks (id,name,species,location,population) VALUES (1,'James','Great White','Pacific Ocean',3000),(2,'Sam','Hammerhead','Atlantic Ocean',2000);
SELECT species, SUM(population) FROM Sharks WHERE species != 'Great White' GROUP BY species;
What are the names and average salaries of construction workers in California and Texas?
CREATE TABLE Construction_Workers (Worker_ID INT,Name TEXT,Salary FLOAT,State TEXT); INSERT INTO Construction_Workers (Worker_ID,Name,Salary,State) VALUES (1,'John Doe',60000,'California'),(2,'Jane Smith',65000,'California'),(3,'Mike Johnson',70000,'Texas'),(4,'Sara Williams',75000,'Texas');
SELECT cw.Name, AVG(cw.Salary) FROM Construction_Workers cw WHERE cw.State IN ('California', 'Texas') GROUP BY cw.Name;
Insert a new record into the restaurant_info table for a new restaurant with an ID of 78, a name of "Tasty Bites", an address of "123 Main St", a city of "Anytown", a state of "CA", and a has_vegan_options field of false
CREATE TABLE restaurant_info (restaurant_id INT,name VARCHAR(50),address VARCHAR(100),city VARCHAR(50),state VARCHAR(2),has_vegan_options BOOLEAN);
INSERT INTO restaurant_info (restaurant_id, name, address, city, state, has_vegan_options) VALUES (78, 'Tasty Bites', '123 Main St', 'Anytown', 'CA', false);
What is the maximum temperature in field B in the past week?
CREATE TABLE Weather (field VARCHAR(50),date DATE,temperature FLOAT); INSERT INTO Weather (field,date,temperature) VALUES ('Field B','2022-06-01',25.1),('Field B','2022-06-02',28.6),('Field B','2022-06-03',22.3);
SELECT MAX(temperature) FROM Weather WHERE field = 'Field B' AND date >= DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY);
What is the total installed capacity of wind energy in Germany and France?
CREATE TABLE wind_energy (country VARCHAR(20),installed_capacity INT); INSERT INTO wind_energy (country,installed_capacity) VALUES ('Germany',62000),('France',16000);
SELECT SUM(installed_capacity) FROM wind_energy WHERE country IN ('Germany', 'France');
Which chemical safety inspectors have inspected chemicals with a safety stock level above 1000?
CREATE TABLE Inspectors (InspectorID INT,InspectorName TEXT); CREATE TABLE Inspections (InspectionID INT,InspectorID INT,ChemicalID INT); INSERT INTO Inspectors (InspectorID,InspectorName) VALUES (1,'John Doe'),(2,'Jane Smith'),(3,'Bob Johnson'); INSERT INTO Inspections (InspectionID,InspectorID,ChemicalID) VALUES (1001,1,1),(1002,2,2),(1003,3,3);
SELECT InspectorName FROM Inspectors INNER JOIN Inspections ON Inspectors.InspectorID = Inspections.InspectorID INNER JOIN Chemicals ON Inspections.ChemicalID = Chemicals.ChemicalID WHERE Chemicals.SafetyStockLevel > 1000;
How many genetic researchers work in 'Lab1'?
CREATE TABLE Employees (employee_id INT,name TEXT,role TEXT,department TEXT); INSERT INTO Employees (employee_id,name,role,department) VALUES (1,'John','Genetic Researcher','Lab1'),(2,'Jane','Bioprocess Engineer','Lab1'),(3,'Mike','Data Scientist','Lab2');
SELECT COUNT(*) FROM Employees WHERE role = 'Genetic Researcher' AND department = 'Lab1';
What is the average SPF value of foundations?
CREATE TABLE Foundations (product_id INT,product_name VARCHAR(255),category VARCHAR(255),price DECIMAL(10,2),spf DECIMAL(3,1)); INSERT INTO Foundations (product_id,product_name,category,price,spf) VALUES (1,'Foundation 1','Foundations',24.99,15),(2,'Foundation 2','Foundations',29.99,20),(3,'Foundation 3','Foundations',34.99,30),(4,'Foundation 4','Foundations',39.99,35);
SELECT AVG(spf) FROM Foundations;
How many mental health parity violations have occurred in each state, and what is the trend over the past three years?
CREATE TABLE mental_health_parity_trend (state VARCHAR(2),year INT,violations INT); INSERT INTO mental_health_parity_trend (state,year,violations) VALUES ('CA',2020,15),('CA',2021,25),('NY',2020,20),('NY',2021,30),('TX',2020,10),('TX',2021,20);
SELECT m.state, m.year, m.violations, LAG(m.violations) OVER (PARTITION BY m.state ORDER BY m.year) as prev_year_violations FROM mental_health_parity_trend m;
What is the average age of patients who received cognitive behavioral therapy (CBT) in the US?
CREATE TABLE mental_health.patients (patient_id INT,age INT,country VARCHAR(255)); INSERT INTO mental_health.patients (patient_id,age,country) VALUES (1,35,'USA'),(2,40,'Canada'),(3,30,'USA'); CREATE TABLE mental_health.treatments (treatment_id INT,patient_id INT,treatment_name VARCHAR(255)); INSERT INTO mental_health.treatments (treatment_id,patient_id,treatment_name) VALUES (1,1,'CBT'),(2,2,'Medication'),(3,3,'CBT');
SELECT AVG(p.age) FROM mental_health.patients p INNER JOIN mental_health.treatments t ON p.patient_id = t.patient_id WHERE t.treatment_name = 'CBT' AND p.country = 'USA';
Calculate the total budget for completed rural infrastructure projects in Oceania.
CREATE TABLE rural_infra (id INT,name VARCHAR(255),region VARCHAR(255),budget FLOAT,status VARCHAR(255)); INSERT INTO rural_infra (id,name,region,budget,status) VALUES (1,'Road Construction','Oceania',250000.00,'completed');
SELECT SUM(budget) FROM rural_infra WHERE region = 'Oceania' AND status = 'completed';
What is the average points per game scored by players from the players_stats table, grouped by their team?
CREATE TABLE teams (team_id INT,team_name VARCHAR(255)); CREATE TABLE players (player_id INT,player_name VARCHAR(255),team_id INT); CREATE TABLE players_stats (player_id INT,game_id INT,points INT);
SELECT t.team_name, AVG(ps.points) AS avg_points FROM players_stats ps JOIN players p ON ps.player_id = p.player_id JOIN teams t ON p.team_id = t.team_id GROUP BY t.team_name;
Display the number of employees working for each brand.
CREATE TABLE Brands (BrandID INT,BrandName VARCHAR(50),EmployeeCount INT); INSERT INTO Brands (BrandID,BrandName,EmployeeCount) VALUES (1,'Brand1',500),(2,'Brand2',300),(3,'Brand3',700);
SELECT BrandName, EmployeeCount FROM Brands;
Update the carbon_offsets table to set the 'status' column to 'inactive' for all records with an 'emission_date' older than 2020-01-01.
CREATE TABLE carbon_offsets (offset_id INT,project_id INT,emission_date DATE,status VARCHAR(255)); INSERT INTO carbon_offsets (offset_id,project_id,emission_date,status) VALUES (1,1,'2019-01-01','active'),(2,2,'2020-01-01','active'),(3,3,'2018-01-01','active');
UPDATE carbon_offsets SET status = 'inactive' WHERE emission_date < '2020-01-01';
What are the names and discovery dates of the astrophysics research discovered before the 'Dark Matter' discovery?
CREATE TABLE astro_research (id INT,name VARCHAR(50),location VARCHAR(50),discovery_date DATE,research_type VARCHAR(50)); INSERT INTO astro_research (id,name,location,discovery_date,research_type) VALUES (1,'Black Hole','M87','2019-04-10','Imaging'); INSERT INTO astro_research (id,name,location,discovery_date,research_type) VALUES (2,'Pulsar','Vela','1967-11-28','Radio'); INSERT INTO astro_research (id,name,location,discovery_date,research_type) VALUES (3,'Dark Matter','Bullet Cluster','2006-08-22','Collision'); INSERT INTO astro_research (id,name,location,discovery_date,research_type) VALUES (4,'Exoplanet','Kepler-22b','2011-12-05','Habitable Zone');
SELECT name, discovery_date FROM astro_research WHERE discovery_date < (SELECT discovery_date FROM astro_research WHERE name = 'Dark Matter');
What is the number of online course enrollments by institution and course type?
CREATE TABLE institutions (id INT,name VARCHAR(50),type VARCHAR(20)); INSERT INTO institutions (id,name,type) VALUES (1,'University X','Public'),(2,'College Y','Private'),(3,'Institute Z','Private'); CREATE TABLE enrollments (id INT,institution_id INT,course_type VARCHAR(20),student_count INT); INSERT INTO enrollments (id,institution_id,course_type,student_count) VALUES (1,1,'Online',1000),(2,2,'Online',1500),(3,3,'Online',800),(4,1,'In-person',500);
SELECT i.name, e.course_type, SUM(e.student_count) as total_enrolled FROM institutions i JOIN enrollments e ON i.id = e.institution_id GROUP BY i.name, e.course_type;
Show the number of food safety inspections and the percentage of inspections with critical violations for restaurants in Georgia, for the last 12 months.
CREATE TABLE Inspections (InspectionID INT,RestaurantID INT,InspectionDate DATETIME,CriticalViolationCount INT);
SELECT RestaurantID, COUNT(*) OVER (PARTITION BY RestaurantID) as TotalInspections, (COUNT(*) FILTER (WHERE CriticalViolationCount > 0) OVER (PARTITION BY RestaurantID) * 100.0 / COUNT(*) OVER (PARTITION BY RestaurantID)) as CriticalViolationPercentage FROM Inspections WHERE RestaurantID IN (SELECT RestaurantID FROM Restaurants WHERE State = 'Georgia') AND InspectionDate > CURRENT_DATE - INTERVAL '12 months';
List the top 10 most active users in terms of total number of posts, along with the number of followers they have.
CREATE TABLE users (id INT,username VARCHAR(50),followers INT); CREATE TABLE posts (id INT,user_id INT,content VARCHAR(500));
SELECT u.username, u.followers, COUNT(p.id) as total_posts FROM users u JOIN posts p ON u.id = p.user_id GROUP BY u.id ORDER BY total_posts DESC LIMIT 10;
Insert renewable energy investment data for Kenya and Nigeria.
CREATE TABLE renewable_investment (country VARCHAR(50),investment_amount INT);
INSERT INTO renewable_investment (country, investment_amount) VALUES ('Kenya', 1200), ('Nigeria', 1800);
What is the maximum patch delay for the 'database' subsystem?
CREATE TABLE patch_delays (subsystem VARCHAR(255),delay INT); INSERT INTO patch_delays (subsystem,delay) VALUES ('applications',5),('database',7),('network',3);
SELECT MAX(delay) FROM patch_delays WHERE subsystem = 'database';
What is the total number of races won by each athlete in the 'runners' table?
CREATE TABLE runners (athlete_id INT,name VARCHAR(50),races_won INT); INSERT INTO runners (athlete_id,name,races_won) VALUES (1,'Mo Farah',10); INSERT INTO runners (athlete_id,name,races_won) VALUES (2,'Galen Rupp',8);
SELECT name, SUM(races_won) FROM runners GROUP BY name;
List all garments that are not available in size 'S'
CREATE TABLE Garments (id INT,name VARCHAR(255),category VARCHAR(255),color VARCHAR(255),size VARCHAR(10),price DECIMAL(5,2));
SELECT * FROM Garments WHERE size != 'S';
What is the maximum temperature recorded in each chemical plant during the summer season, and the corresponding date?
CREATE TABLE plant_temperature (plant_id INT,temp_date DATE,plant_location TEXT,temperature FLOAT); INSERT INTO plant_temperature (plant_id,temp_date,plant_location,temperature) VALUES (1,'2021-06-15','Plant A',32.5),(2,'2021-07-20','Plant B',36.7),(3,'2021-08-05','Plant C',41.2);
SELECT plant_location, temp_date, MAX(temperature) AS max_temp FROM plant_temperature WHERE temp_date >= DATEADD(month, 5, DATEADD(year, DATEDIFF(year, 0, CURRENT_DATE), 0)) AND temp_date < DATEADD(month, 8, DATEADD(year, DATEDIFF(year, 0, CURRENT_DATE), 0)) GROUP BY plant_location, temp_date;
How many military innovation projects were completed in the last 3 years, with a budget over 200000?
CREATE TABLE military_innovation (id INT PRIMARY KEY,completion_date DATE,budget DECIMAL(10,2),project_name VARCHAR(100)); INSERT INTO military_innovation (id,completion_date,budget,project_name) VALUES (1,'2020-02-28',300000,'Project 1'),(2,'2019-05-15',150000,'Project 2'),(3,'2018-12-31',250000,'Project 3');
SELECT COUNT(*) FROM military_innovation WHERE completion_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 3 YEAR) AND CURRENT_DATE AND budget > 200000;
What is the percentage of employees who have completed diversity and inclusion training?
CREATE TABLE Employees (EmployeeID INT,DiversityTraining BOOLEAN); INSERT INTO Employees (EmployeeID,DiversityTraining) VALUES (1,1),(2,0),(3,1);
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Employees)) AS Percentage FROM Employees WHERE DiversityTraining = 1;
What is the number of patients who identified as female and received therapy in California?
CREATE TABLE patients (patient_id INT,age INT,gender TEXT,treatment TEXT,state TEXT); INSERT INTO patients (patient_id,age,gender,treatment,state) VALUES (1,30,'Female','CBT','Texas'); INSERT INTO patients (patient_id,age,gender,treatment,state) VALUES (2,45,'Male','DBT','California'); INSERT INTO patients (patient_id,age,gender,treatment,state) VALUES (3,25,'Non-binary','Therapy','Washington'); INSERT INTO patients (patient_id,age,gender,treatment,state) VALUES (4,18,'Male','Therapy','Colorado'); INSERT INTO patients (patient_id,age,gender,treatment,state) VALUES (5,50,'Female','Therapy','California');
SELECT COUNT(*) FROM patients WHERE gender = 'Female' AND treatment = 'Therapy' AND state = 'California';
Find the average sustainability rating for all vegan menu items
CREATE TABLE menu_sustainability (id INT PRIMARY KEY,menu_item VARCHAR(255),sustainability_rating DECIMAL(3,2)); CREATE TABLE menu_items (id INT PRIMARY KEY,menu_item VARCHAR(255),is_vegan BOOLEAN);
SELECT AVG(sustainability_rating) FROM menu_sustainability ms JOIN menu_items mi ON ms.menu_item = mi.menu_item WHERE mi.is_vegan = true;
How many species are listed as 'Critically Endangered' and their population?
CREATE TABLE Species (id INT PRIMARY KEY,species_name VARCHAR(100),population INT,conservation_status VARCHAR(50)); INSERT INTO Species (id,species_name,population,conservation_status) VALUES (5,'Vaquita',10,'Critically Endangered'); INSERT INTO Species (id,species_name,population,conservation_status) VALUES (6,'Javan Rhino',67,'Critically Endangered');
SELECT species_name, population FROM Species WHERE conservation_status = 'Critically Endangered';
What is the number of autonomous driving research vehicles produced by each manufacturer?
CREATE TABLE Manufacturers (id INT,name VARCHAR(255)); INSERT INTO Manufacturers (id,name) VALUES (1,'Tesla'); INSERT INTO Manufacturers (id,name) VALUES (2,'Audi'); CREATE TABLE Autonomous_Vehicles (id INT,manufacturer_id INT,make VARCHAR(255),model VARCHAR(255)); INSERT INTO Autonomous_Vehicles (id,manufacturer_id,make,model) VALUES (1,1,'Tesla','Model S'); INSERT INTO Autonomous_Vehicles (id,manufacturer_id,make,model) VALUES (2,1,'Tesla','Model X'); INSERT INTO Autonomous_Vehicles (id,manufacturer_id,make,model) VALUES (3,2,'Audi','e-Tron');
SELECT m.name, COUNT(av.id) FROM Manufacturers m JOIN Autonomous_Vehicles av ON m.id = av.manufacturer_id GROUP BY m.name;
What is the total number of public transportation vehicles in the 'public_transport' schema, grouped by city?
CREATE TABLE public_transport_cities (city VARCHAR(255),system_name VARCHAR(255),num_vehicles INT); INSERT INTO public_transport_cities (city,system_name,num_vehicles) VALUES ('New York','NYC Subway',6000),('New York','NYC Bus',2000),('London','London Tube',4000),('London','London Bus',3000),('Paris','Paris Metro',2500),('Paris','Paris Bus',1500);
SELECT city, SUM(num_vehicles) FROM public_transport_cities GROUP BY city;
List all unique cybersecurity incidents with an impact level of 'high' or 'critical'.
CREATE TABLE CybersecurityIncidents (Incident VARCHAR(50),ImpactLevel VARCHAR(10)); INSERT INTO CybersecurityIncidents (Incident,ImpactLevel) VALUES ('Data Breach','High'),('Phishing Attack','Low'),('Ransomware Attack','Medium'),('Insider Threat','High'),('Botnet Attack','Medium');
SELECT DISTINCT Incident FROM CybersecurityIncidents WHERE ImpactLevel IN ('High', 'Critical');
What is the total revenue generated by eco-friendly hotels in France?
CREATE TABLE hotels (id INT,name TEXT,country TEXT,is_eco_friendly BOOLEAN); INSERT INTO hotels (id,name,country,is_eco_friendly) VALUES (1,'Green Hotel','France',true),(2,'Le Château','France',false); CREATE TABLE bookings (id INT,hotel_id INT,revenue INT); INSERT INTO bookings (id,hotel_id,revenue) VALUES (1,1,1000),(2,1,2000),(3,2,1500);
SELECT SUM(bookings.revenue) FROM bookings JOIN hotels ON bookings.hotel_id = hotels.id WHERE hotels.country = 'France' AND hotels.is_eco_friendly = true;
What was the total revenue for 'DrugG' in 'CountryI' in the first half of 2019, excluding returns?
CREATE TABLE sales(drug_name TEXT,country TEXT,sales_half INT,revenue FLOAT,return_amount FLOAT); INSERT INTO sales (drug_name,country,sales_half,revenue,return_amount) VALUES ('DrugA','CountryY',1,1200000,100000),('DrugB','CountryX',1,1000000,50000),('DrugG','CountryI',1,1500000,0),('DrugC','CountryX',2,1300000,200000);
SELECT SUM(sales.revenue - COALESCE(sales.return_amount, 0)) AS total_revenue FROM sales WHERE drug_name = 'DrugG' AND country = 'CountryI' AND sales_half = 1;
What is the earliest launch date of a geostationary satellite from Russia?
CREATE TABLE Satellites (SatelliteId INT,Name VARCHAR(50),LaunchDate DATE,OrbitType VARCHAR(50),Country VARCHAR(50)); INSERT INTO Satellites (SatelliteId,Name,LaunchDate,OrbitType,Country) VALUES (5,'Ekspress-AM5','2013-12-15','GEO','Russia');
SELECT Country, MIN(LaunchDate) FROM Satellites WHERE OrbitType = 'GEO' AND Country = 'Russia';
What is the maximum length of a dam in the 'dams' table?
CREATE TABLE dams (dam_id INT,dam_name VARCHAR(50),location VARCHAR(50),length DECIMAL(10,2),reservoir_capacity INT);
SELECT MAX(length) FROM dams;
What are the total sales figures for each drug in the 'drugs' table, including drugs with no sales, in the Asia-Pacific region?
CREATE TABLE drugs (drug_id INT,drug_name TEXT,sales_figure INT,region TEXT); INSERT INTO drugs (drug_id,drug_name,sales_figure,region) VALUES (1,'DrugA',500,'Asia-Pacific'),(2,'DrugB',750,'Europe');
SELECT d.drug_name, COALESCE(SUM(s.sales_figure), 0) AS total_sales FROM drugs d LEFT JOIN sales s ON d.drug_id = s.drug_id WHERE d.region = 'Asia-Pacific' GROUP BY d.drug_name;
Update the quantity of 'Plastic Bottles' to 1500 in waste_generation table
CREATE TABLE waste_generation (id INT PRIMARY KEY,location VARCHAR(255),waste_type VARCHAR(255),quantity INT,date DATE);
UPDATE waste_generation SET quantity = 1500 WHERE waste_type = 'Plastic Bottles';
Delete all records from the 'donations' table that are under $50.
CREATE TABLE donations (id INT,volunteer_id INT,donation_amount DECIMAL); INSERT INTO donations (id,volunteer_id,donation_amount) VALUES (1,1,'100.00'),(2,1,'75.00'),(3,2,'25.00'),(4,2,'150.00');
DELETE FROM donations WHERE donation_amount < 50.00;
What is the maximum price of a product in the circular_supply table?
CREATE TABLE circular_supply (product_id INT,product_name TEXT,price DECIMAL); INSERT INTO circular_supply (product_id,product_name,price) VALUES (1,'Reusable Bag',25),(2,'Refillable Bottle',15),(3,'Solar-Powered Lamp',60);
SELECT MAX(price) FROM circular_supply;
List all ports and their corresponding regulatory authority for vessels flying the flag of Panama.
CREATE TABLE ports(id INT,name VARCHAR(255),country VARCHAR(255)); CREATE TABLE vessels(id INT,name VARCHAR(255),flag VARCHAR(255),port_id INT); CREATE TABLE regulatory_authorities(id INT,name VARCHAR(255),country VARCHAR(255));
SELECT ports.name, regulatory_authorities.name FROM ports INNER JOIN vessels ON ports.id = vessels.port_id INNER JOIN regulatory_authorities ON ports.country = regulatory_authorities.country WHERE vessels.flag = 'Panama';
Find the number of tickets sold for each game of the baseball team in Chicago.
CREATE TABLE tickets (ticket_id INT,game_id INT,quantity INT,price DECIMAL(5,2)); INSERT INTO tickets VALUES (1,1,50,25.99); INSERT INTO tickets VALUES (2,2,30,19.99); CREATE TABLE games (game_id INT,team VARCHAR(20),location VARCHAR(20)); INSERT INTO games VALUES (1,'Cubs','Chicago'); INSERT INTO games VALUES (2,'White Sox','Chicago');
SELECT games.team, SUM(tickets.quantity) FROM tickets INNER JOIN games ON tickets.game_id = games.game_id WHERE games.team = 'Cubs' GROUP BY games.team;
Display the number of accessible vehicles in the 'Green Line' fleet
CREATE TABLE accessible_vehicles (vehicle_type VARCHAR(50),fleet_name VARCHAR(50),is_accessible BOOLEAN); INSERT INTO accessible_vehicles (vehicle_type,fleet_name,is_accessible) VALUES ('Green Line','Bus',true),('Green Line','Train',false),('Blue Line','Bus',true);
SELECT COUNT(*) FROM accessible_vehicles WHERE fleet_name = 'Green Line' AND is_accessible = true;
What is the average depth of ocean floor mapping project sites in the Pacific region?
CREATE TABLE ocean_floor_map (id INT,project_name VARCHAR(255),region VARCHAR(255),avg_depth FLOAT);
SELECT avg(avg_depth) FROM ocean_floor_map WHERE region = 'Pacific';
Which countries received climate finance for mitigation projects in 2019?
CREATE TABLE climate_finance (year INT,country VARCHAR(50),purpose VARCHAR(50),amount FLOAT); INSERT INTO climate_finance (year,country,purpose,amount) VALUES (2019,'Brazil','Mitigation',500000),(2019,'India','Mitigation',700000),(2019,'Indonesia','Adaptation',600000),(2019,'South Africa','Mitigation',800000);
SELECT DISTINCT country FROM climate_finance WHERE year = 2019 AND purpose = 'Mitigation';
Delete all records in the "waste_management" table where the "waste_type" is 'Toxic'
CREATE TABLE waste_management (waste_id INT PRIMARY KEY,waste_type VARCHAR(20)); INSERT INTO waste_management (waste_id,waste_type) VALUES (1,'Non-Toxic'),(2,'Toxic'),(3,'Non-Toxic');
DELETE FROM waste_management WHERE waste_type = 'Toxic';
How many visitors attended each exhibition on Saturday?
CREATE TABLE Exhibitions (exhibition_id INT,name VARCHAR(50),start_date DATE,end_date DATE,day VARCHAR(10)); INSERT INTO Exhibitions (exhibition_id,name,start_date,end_date,day) VALUES (1,'Impressionist','2020-05-01','2021-01-01','Saturday'),(2,'Cubism','2019-08-15','2020-03-30','Sunday'),(3,'Surrealism','2018-12-15','2019-09-15','Saturday'); CREATE TABLE Visitors (visitor_id INT,exhibition_id INT,age INT,gender VARCHAR(50));
SELECT exhibition_id, COUNT(*) FROM Visitors INNER JOIN Exhibitions ON Visitors.exhibition_id = Exhibitions.exhibition_id WHERE day = 'Saturday' GROUP BY exhibition_id;
What is the total number of movies produced by studios based in the United States and Canada?
CREATE TABLE movies (id INT,title VARCHAR(100),release_year INT,studio_country VARCHAR(50)); INSERT INTO movies (id,title,release_year,studio_country) VALUES (1,'Movie1',2000,'USA'),(2,'Movie2',2005,'Canada'),(3,'Movie3',2010,'USA');
SELECT COUNT(*) FROM movies WHERE studio_country IN ('USA', 'Canada');
How many publications were made by graduate students from 'Africa' in 2021?
CREATE TABLE students (id INT,region TEXT,start_year INT); CREATE TABLE publications (id INT,student_id INT,year INT); INSERT INTO students (id,region,start_year) VALUES (1,'Nigeria',2019); INSERT INTO publications (id,student_id,year) VALUES (1,1,2021);
SELECT COUNT(*) FROM publications JOIN students ON publications.student_id = students.id WHERE students.region = 'Nigeria' AND publications.year = 2021;
What is the total revenue generated from adult passengers in the 'red' line?
CREATE TABLE routes (line VARCHAR(10),revenue FLOAT); INSERT INTO routes (line,revenue) VALUES ('red',15000.00),('blue',20000.00),('green',12000.00);
SELECT SUM(revenue) FROM routes WHERE line = 'red' AND revenue=(SELECT revenue FROM routes WHERE line = 'red' AND passenger_type = 'adult');
List the top 5 organizations with the highest total donation amounts in the 'Arts & Culture' category.
CREATE TABLE organizations (id INT,name VARCHAR(50),category VARCHAR(20)); CREATE TABLE donations (id INT,organization_id INT,amount DECIMAL(10,2)); INSERT INTO organizations (id,name,category) VALUES (1,'Org1','Arts & Culture'),(2,'Org2','Arts & Culture'),(3,'Org3','Education'),(4,'Org4','Health'); INSERT INTO donations (id,organization_id,amount) VALUES (1,1,500),(2,1,700),(3,2,1000),(4,2,1200),(5,3,800),(6,4,900);
SELECT organizations.name, SUM(donations.amount) as total_donation FROM organizations JOIN donations ON organizations.id = donations.organization_id WHERE organizations.category = 'Arts & Culture' GROUP BY organizations.name ORDER BY total_donation DESC LIMIT 5;
What is the maximum number of attempts before a lockout for failed authentication on network devices?
CREATE TABLE network_devices (id INT,device_name VARCHAR(255),max_attempts INT); INSERT INTO network_devices (id,device_name,max_attempts) VALUES (1,'Switch1',5),(2,'Router1',3),(3,'Firewall1',7);
SELECT MAX(max_attempts) FROM network_devices;
List the names of the cities with co-living properties and their respective co-living property counts.
CREATE TABLE CoLivingProperties(id INT,name VARCHAR(50),city VARCHAR(20));INSERT INTO CoLivingProperties(id,name,city) VALUES (1,'GreenSpaces','Portland'),(2,'EcoVillage','SanFrancisco'),(3,'UrbanNest','Portland'),(4,'EcoHaven','Austin');
SELECT city, COUNT(*) FROM CoLivingProperties GROUP BY city;
What is the average CO2 emissions (tCO2) per capita in Nigeria, Kenya, and South Africa, for the years 2017 and 2022?
CREATE TABLE co2_emissions (country TEXT,year INT,population INT,co2_emissions FLOAT); INSERT INTO co2_emissions (country,year,population,co2_emissions) VALUES ('Nigeria',2017,196.0,510.0),('Nigeria',2022,205.0,550.0),('Kenya',2017,49.0,110.0),('Kenya',2022,52.0,120.0),('South Africa',2017,57.0,490.0),('South Africa',2022,59.0,520.0);
SELECT country, AVG(co2_emissions/population) FROM co2_emissions WHERE country IN ('Nigeria', 'Kenya', 'South Africa') AND year IN (2017, 2022) GROUP BY country;
What is the minimum number of shares for posts about vegan recipes?
CREATE TABLE posts (id INT,topic VARCHAR(255),shares INT); INSERT INTO posts (id,topic,shares) VALUES (1,'Vegan Recipes',50),(2,'Vegan Recipes',75),(3,'Tech News',100),(4,'Movie Reviews',125),(5,'Vegan Recipes',150),(6,'Vegan Recipes',175);
SELECT MIN(posts.shares) AS min_shares FROM posts WHERE posts.topic = 'Vegan Recipes';
Which cities had a population decrease between 2019 and 2020?
CREATE TABLE CityYearPopulation (CityId INT,Year INT,Population INT,PRIMARY KEY (CityId,Year)); INSERT INTO CityYearPopulation (CityId,Year,Population) VALUES (1,2019,8400000); INSERT INTO CityYearPopulation (CityId,Year,Population) VALUES (1,2020,8600000); INSERT INTO CityYearPopulation (CityId,Year,Population) VALUES (2,2019,3900000); INSERT INTO CityYearPopulation (CityId,Year,Population) VALUES (2,2020,3800000);
SELECT CityId, Year, Population, Population - LAG(Population, 1) OVER (PARTITION BY CityId ORDER BY Year) as PopulationChange FROM CityYearPopulation WHERE PopulationChange < 0;
What are the total military equipment sales by Lockheed Martin to European countries in 2020?
CREATE TABLE MilitaryEquipmentSales (EquipmentID INT,Manufacturer VARCHAR(50),DestinationCountry VARCHAR(50),SaleDate DATE,Quantity INT,UnitPrice FLOAT); INSERT INTO MilitaryEquipmentSales (EquipmentID,Manufacturer,DestinationCountry,SaleDate,Quantity,UnitPrice) VALUES (1,'Lockheed Martin','Algeria','2020-01-10',5,1000000.00),(2,'Northrop Grumman','Egypt','2020-02-15',3,1500000.00),(3,'Lockheed Martin','Nigeria','2020-03-20',7,800000.00),(4,'Boeing','France','2020-04-15',4,1100000.00);
SELECT SUM(Quantity * UnitPrice) FROM MilitaryEquipmentSales WHERE Manufacturer = 'Lockheed Martin' AND DestinationCountry LIKE 'Europe%' AND YEAR(SaleDate) = 2020;
What is the daily maximum temperature for the last 30 days, with a running total of the number of days above 30 degrees Celsius?
CREATE TABLE WeatherData (id INT,Temperature INT,Timestamp DATETIME); INSERT INTO WeatherData (id,Temperature,Timestamp) VALUES (1,32,'2022-05-15 12:00:00'),(2,28,'2022-05-16 12:00:00');
SELECT Temperature, Timestamp, SUM(CASE WHEN Temperature > 30 THEN 1 ELSE 0 END) OVER (ORDER BY Timestamp) as RunningTotal FROM WeatherData WHERE Timestamp BETWEEN DATEADD(day, -30, GETDATE()) AND GETDATE();
What is the transaction history between two blockchain addresses?
CREATE TABLE transactions (tx_id INT,sender VARCHAR(42),receiver VARCHAR(42),amount DECIMAL(20,2),timestamp DATETIME);
SELECT * FROM transactions WHERE (sender = '0x1234567890abcdef1234567890abcdef' AND receiver = '0x87654321f0abcdef1234567890abcdef') OR (sender = '0x87654321f0abcdef1234567890abcdef' AND receiver = '0x1234567890abcdef1234567890abcdef') ORDER BY timestamp;
What is the total number of offshore drilling platforms in the North Sea?
CREATE TABLE DrillingPlatforms (PlatformID int,PlatformName varchar(50),Location varchar(50),PlatformType varchar(50),NumberOfWells int); INSERT INTO DrillingPlatforms (PlatformID,PlatformName,Location,PlatformType,NumberOfWells) VALUES (1,'A01','North Sea','Offshore',10),(2,'B02','Gulf of Mexico','Offshore',15);
SELECT COUNT(*) FROM DrillingPlatforms WHERE PlatformType = 'Offshore' AND Location = 'North Sea';
What is the total number of hospital beds in hospitals located in California?
CREATE TABLE hospitals (id INT PRIMARY KEY,name VARCHAR(255),beds INT,location VARCHAR(255)); INSERT INTO hospitals (id,name,beds,location) VALUES (1,'Johns Hopkins Hospital',1138,'Baltimore,MD'); INSERT INTO hospitals (id,name,beds,location) VALUES (2,'Massachusetts General Hospital',999,'Boston,MA'); INSERT INTO hospitals (id,name,beds,location) VALUES (3,'University of California Medical Center',500,'Los Angeles,CA');
SELECT SUM(beds) FROM hospitals WHERE location LIKE '%California%';
List all the loans issued in Q4 2021 that are Shariah-compliant.
CREATE TABLE loans (loan_id INT,is_shariah_compliant BOOLEAN,issue_date DATE); INSERT INTO loans (loan_id,is_shariah_compliant,issue_date) VALUES (1,true,'2021-10-01'),(2,false,'2021-08-15'),(3,true,'2021-12-30'),(4,false,'2021-06-22');
SELECT loan_id FROM loans WHERE is_shariah_compliant = true AND issue_date BETWEEN '2021-10-01' AND '2021-12-31';
Count the number of public transportation trips taken in New York City for the month of January in the year 2022.
CREATE TABLE trips (trip_id INT,trip_date DATE,trip_type VARCHAR(50),city VARCHAR(50)); INSERT INTO trips (trip_id,trip_date,trip_type,city) VALUES (1,'2022-01-01','Public Transportation','New York City'),(2,'2022-01-05','Taxi','New York City'),(3,'2022-01-10','Public Transportation','New York City');
SELECT COUNT(*) FROM trips WHERE trip_type = 'Public Transportation' AND EXTRACT(MONTH FROM trip_date) = 1 AND EXTRACT(YEAR FROM trip_date) = 2022 AND city = 'New York City';
Which teams have played more than 40 games in the last 3 years?
CREATE TABLE teams (team VARCHAR(255),games INT); CREATE TABLE games_played (team VARCHAR(255),year INT,games INT); INSERT INTO teams VALUES ('TeamA',50),('TeamB',45),('TeamC',40),('TeamD',35); INSERT INTO games_played VALUES ('TeamA',2018,20),('TeamA',2019,25),('TeamA',2020,20),('TeamB',2018,15),('TeamB',2019,15),('TeamB',2020,15),('TeamC',2018,15),('TeamC',2019,12),('TeamC',2020,13),('TeamD',2018,12),('TeamD',2019,12),('TeamD',2020,11);
SELECT team, SUM(games) as total_games FROM games_played WHERE year BETWEEN 2018 AND 2020 GROUP BY team HAVING total_games > 40;
What is the total revenue of ethical fashion brands in the Asia-Pacific region?
CREATE TABLE revenue (brand TEXT,region TEXT,amount FLOAT); INSERT INTO revenue (brand,region,amount) VALUES ('BrandA','Asia-Pacific',5000000),('BrandB','Asia-Pacific',7000000),('BrandC','Asia-Pacific',6000000),('BrandD','Asia-Pacific',8000000),('BrandE','Asia-Pacific',9000000);
SELECT SUM(amount) FROM revenue WHERE region = 'Asia-Pacific';
Remove the volunteer with volunteer_id 3 from all programs.
CREATE TABLE Programs (program_id INT,volunteer_id INT); CREATE TABLE Volunteers (volunteer_id INT,name VARCHAR(255)); INSERT INTO Programs (program_id,volunteer_id) VALUES (101,1),(101,3),(102,3),(103,4); INSERT INTO Volunteers (volunteer_id,name) VALUES (1,'John Doe'),(2,'Jane Doe'),(3,'Ahmed Patel'),(4,'Sophia Williams');
DELETE FROM Programs WHERE volunteer_id = 3;
What is the success rate of 'agricultural innovation projects' in 'Asia'?
CREATE TABLE projects (id INT,name TEXT,region TEXT,success BOOLEAN); INSERT INTO projects (id,name,region,success) VALUES (1,'Project 1','Asia',TRUE),(2,'Project 2','Asia',FALSE),(3,'Project 3','Asia',TRUE);
SELECT AVG(projects.success) FROM projects WHERE projects.region = 'Asia' AND projects.name LIKE 'agricultural innovation%';
How many artifacts were analyzed by each lab?
CREATE TABLE LabArtifacts (LabID varchar(5),ArtifactsAnalyzed int); INSERT INTO LabArtifacts (LabID,ArtifactsAnalyzed) VALUES ('L001',400),('L002',500);
SELECT LabID, SUM(ArtifactsAnalyzed) FROM LabArtifacts GROUP BY LabID;
What is the minimum transaction fee for any digital asset?
CREATE TABLE DigitalAssets (asset_id INT,asset_name TEXT,transaction_fee DECIMAL(10,2)); INSERT INTO DigitalAssets (asset_id,asset_name,transaction_fee) VALUES (1,'Asset1',10.50),(2,'Asset2',5.00),(3,'Asset3',20.00);
SELECT MIN(transaction_fee) FROM DigitalAssets;
What is the average design standard height for water towers in Texas?
CREATE TABLE WaterTowers (TowerID int,State varchar(2),Height decimal(10,2)); INSERT INTO WaterTowers (TowerID,State,Height) VALUES (1,'TX',120.5),(2,'TX',130.2),(3,'NY',110.0);
SELECT AVG(Height) FROM WaterTowers WHERE State = 'TX';
How many songs were released by each artist in 2018?
CREATE TABLE artist_songs_2018 (artist VARCHAR(255),num_songs INT); INSERT INTO artist_songs_2018 (artist,num_songs) VALUES ('Taylor Swift',5),('BTS',8),('Ed Sheeran',10);
SELECT artist, num_songs FROM artist_songs_2018;
What is the minimum wage in factories in South America?
CREATE TABLE factory_wages (id INT,factory VARCHAR(100),location VARCHAR(100),min_wage DECIMAL(5,2)); INSERT INTO factory_wages (id,factory,location,min_wage) VALUES (1,'Argentina Factory','Argentina',10),(2,'Brazil Factory','Brazil',12),(3,'Chile Factory','Chile',15);
SELECT MIN(min_wage) FROM factory_wages WHERE location = 'South America';
Who is the top supplier of military equipment to the Pacific Islands in H2 of 2021?
CREATE TABLE Military_Equipment_Sales(sale_id INT,sale_date DATE,equipment_type VARCHAR(50),supplier VARCHAR(50),region VARCHAR(50),sale_value DECIMAL(10,2));
SELECT supplier, SUM(sale_value) FROM Military_Equipment_Sales WHERE region = 'Pacific Islands' AND sale_date BETWEEN '2021-07-01' AND '2021-12-31' GROUP BY supplier ORDER BY SUM(sale_value) DESC LIMIT 1;
How many aircraft were manufactured per year by each manufacturer?
CREATE SCHEMA aircraft_manufacturing; CREATE TABLE aircraft_manufacturing.production (production_id INT,manufacturer VARCHAR(50),production_year INT,quantity INT); INSERT INTO aircraft_manufacturing.production VALUES (1,'Boeing',2000,500); INSERT INTO aircraft_manufacturing.production VALUES (2,'Airbus',2001,600); INSERT INTO aircraft_manufacturing.production VALUES (3,'Bombardier',2002,400);
SELECT manufacturer, production_year, SUM(quantity) OVER (PARTITION BY manufacturer ORDER BY production_year) as total_produced FROM aircraft_manufacturing.production GROUP BY manufacturer, production_year;
How many distinct species are there in the 'marine_species' table?
CREATE TABLE marine_species (species_id INT,species_name VARCHAR(50)); INSERT INTO marine_species (species_id,species_name) VALUES (1,'Spinner Dolphin'),(2,'Clownfish'),(3,'Shark');
SELECT COUNT(DISTINCT species_name) FROM marine_species;
What is the average age of visitors who attended exhibitions in Paris last year?
CREATE TABLE Exhibitions (id INT,city VARCHAR(50),year INT,visitor_age INT);
SELECT AVG(visitor_age) FROM Exhibitions WHERE city = 'Paris' AND year = 2021;
List all stores located in New York that carry products with ethical labor certifications and their respective suppliers.
CREATE TABLE stores (id INT,name VARCHAR(255),city VARCHAR(255),state VARCHAR(255)); CREATE TABLE products (id INT,name VARCHAR(255),price DECIMAL(10,2),is_ethically_sourced BOOLEAN,supplier_id INT); CREATE TABLE supplier_location (supplier_id INT,country VARCHAR(255)); CREATE TABLE certifications (product_id INT,certification_type VARCHAR(255));
SELECT s.name, p.name, sl.country FROM stores s JOIN products p ON s.id = p.store_id JOIN supplier_location sl ON p.supplier_id = sl.supplier_id JOIN certifications c ON p.id = c.product_id WHERE s.state = 'New York' AND p.is_ethically_sourced = TRUE;
What is the number of hospitalizations due to influenza for each age group in the influenza_hospitalizations table?
CREATE TABLE influenza_hospitalizations (age_group TEXT,num_hospitalizations INT); INSERT INTO influenza_hospitalizations (age_group,num_hospitalizations) VALUES ('0-4',1000),('5-17',2000),('18-49',3000),('50-64',4000),('65+',5000);
SELECT age_group, num_hospitalizations FROM influenza_hospitalizations;
Identify employees who have not received diversity and inclusion training in the last two years.
CREATE TABLE EmployeeTrainings (EmployeeID INT,Training VARCHAR(50),TrainingDate DATE); INSERT INTO EmployeeTrainings (EmployeeID,Training,TrainingDate) VALUES (1,'Diversity and Inclusion','2021-01-01'),(2,'Sexual Harassment Prevention','2021-01-01'),(3,'Diversity and Inclusion','2019-01-01');
SELECT EmployeeID FROM EmployeeTrainings WHERE Training = 'Diversity and Inclusion' AND TrainingDate < DATEADD(year, -2, GETDATE()) GROUP BY EmployeeID HAVING COUNT(*) = 1;
What is the total revenue for home games of each team, considering only games with attendance greater than 30000?
CREATE TABLE teams (team_id INT,team_name VARCHAR(50));CREATE TABLE games (game_id INT,team_id INT,home_team BOOLEAN,price DECIMAL(5,2),attendance INT);INSERT INTO teams (team_id,team_name) VALUES (1,'Red Sox'),(2,'Yankees');INSERT INTO games (game_id,team_id,home_team,price,attendance) VALUES (1,1,1,35.50,45000),(2,2,1,42.75,32000),(3,1,0,28.00,22000);
SELECT t.team_name, SUM(g.price * g.attendance) AS revenue FROM teams t INNER JOIN games g ON t.team_id = g.team_id AND g.home_team = t.team_id WHERE g.attendance > 30000 GROUP BY t.team_name;
Update the disaster_preparedness table to mark the 'status' column as 'Available' for records with 'equipment_type' 'Water Purifier' and 'location' 'Warehouse 2'?
CREATE TABLE disaster_preparedness (id INT,equipment_type VARCHAR(255),status VARCHAR(255),location VARCHAR(255)); INSERT INTO disaster_preparedness (id,equipment_type,status,location) VALUES (1,'Water Purifier','Unavailable','Warehouse 2'),(2,'First Aid Kit','Available','Warehouse 1');
UPDATE disaster_preparedness SET status = 'Available' WHERE equipment_type = 'Water Purifier' AND location = 'Warehouse 2';
Display the average age (in years) of all vessels in each fleet, excluding fleets with no vessels, and show the results for the top 2 fleets with the oldest average vessel age.
CREATE TABLE fleets(fleet_id INT,company TEXT,launch_year INT);CREATE TABLE vessels(vessel_id INT,fleet_id INT,name TEXT,launch_year INT);INSERT INTO fleets VALUES (1,'Company A',2000),(2,'Company B',2010),(3,'Company C',2005);INSERT INTO vessels VALUES (1,1,'Vessel 1',2001),(2,1,'Vessel 2',2002),(3,2,'Vessel 3',2012),(4,3,'Vessel 4',2006),(5,3,'Vessel 5',2007);
SELECT f.company, AVG(v.launch_year) as avg_age FROM fleets f JOIN vessels v ON f.fleet_id = v.fleet_id GROUP BY f.fleet_id HAVING avg_age > 0 ORDER BY avg_age DESC LIMIT 2;
How many spacecraft have been manufactured by Boeing and launched before 2020?
CREATE TABLE Spacecraft (SpacecraftID INT,Name VARCHAR(50),Manufacturer VARCHAR(30),LaunchDate DATETIME); INSERT INTO Spacecraft (SpacecraftID,Name,Manufacturer,LaunchDate) VALUES (1,'Starliner','Boeing','2019-08-02'),(2,'New Glenn','Boeing','2020-04-21'),(3,'X-37B','Boeing','2010-04-22');
SELECT COUNT(*) FROM Spacecraft WHERE Manufacturer = 'Boeing' AND YEAR(LaunchDate) < 2020;
What is the average energy efficiency score for each region?
CREATE TABLE regions (region_id INT,region_name VARCHAR(255)); CREATE TABLE energy_efficiency (efficiency_id INT,state VARCHAR(255),energy_efficiency_score INT,region_id INT); INSERT INTO regions (region_id,region_name) VALUES (1,'West'); INSERT INTO energy_efficiency (efficiency_id,state,energy_efficiency_score,region_id) VALUES (1,'California',90,1); INSERT INTO energy_efficiency (efficiency_id,state,energy_efficiency_score,region_id) VALUES (2,'Texas',75,2);
SELECT r.region_name, AVG(ee.energy_efficiency_score) FROM regions r INNER JOIN energy_efficiency ee ON r.region_id = ee.region_id GROUP BY r.region_id;
What is the average salary of employees who identify as female, grouped by their job title?
CREATE TABLE Employees (EmployeeID INT,Gender VARCHAR(10),JobTitle VARCHAR(50),Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID,Gender,JobTitle,Salary) VALUES (1,'Female','Software Engineer',85000.00),(2,'Male','Project Manager',95000.00),(3,'Non-binary','Data Analyst',70000.00),(4,'Female','Software Engineer',80000.00);
SELECT e.JobTitle, AVG(e.Salary) as AvgSalary FROM Employees e WHERE e.Gender = 'Female' GROUP BY e.JobTitle;
Update temperature readings for a specific sensor record of crop type 'Cotton'.
CREATE TABLE sensor_data (id INT,crop_type VARCHAR(255),temperature INT,humidity INT,measurement_date DATE); INSERT INTO sensor_data (id,crop_type,temperature,humidity,measurement_date) VALUES (1,'Corn',22,55,'2021-05-01'); INSERT INTO sensor_data (id,crop_type,temperature,humidity,measurement_date) VALUES (2,'Cotton',28,65,'2021-05-03');
UPDATE sensor_data SET temperature = 30 WHERE id = 2;