instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the average budget allocated per service category in the Health department?
CREATE TABLE Health_Dept (ID INT,Service VARCHAR(255),Budget FLOAT); INSERT INTO Health_Dept (ID,Service,Budget) VALUES (1,'Primary Care',500000),(2,'Mental Health',700000),(3,'Public Health',800000);
SELECT AVG(Budget) FROM Health_Dept GROUP BY Service;
What is the average rating of performing arts events, grouped by genre and performer?
CREATE TABLE PerformingArtsEvents (ID INT,EventName VARCHAR(255),EventDate DATE,Genre VARCHAR(255),Performer VARCHAR(255),Rating DECIMAL(3,2));
SELECT Genre, Performer, AVG(Rating) as AverageRating FROM PerformingArtsEvents GROUP BY Genre, Performer;
Add a new artist 'Mickalene Thomas' to the 'Contemporary Art' event.
CREATE TABLE artists (id INT,name VARCHAR(50),event VARCHAR(50),stipend DECIMAL(5,2)); INSERT INTO artists (id,name,event,stipend) VALUES (1,'Pablo Picasso','Art of the Americas',3000),(2,'Frida Kahlo','Art of the Americas',2500),(3,'Yayoi Kusama','Women in Art',4000),(4,'Xu Bing','Asian Art',2000);
INSERT INTO artists (id, name, event, stipend) VALUES (5, 'Mickalene Thomas', 'Contemporary Art', 5000);
How many electric vehicles were adopted in each country in 'EV Adoption Statistics' table?
CREATE TABLE EV_Adoption_Statistics (country VARCHAR(50),vehicle_type VARCHAR(20),num_adopted INT);
SELECT country, COUNT(*) FROM EV_Adoption_Statistics WHERE vehicle_type = 'Electric' GROUP BY country;
What is the percentage of users who liked articles about 'sports' and also liked articles about 'entertainment'?
CREATE TABLE users (id INT,name TEXT,likes INT); CREATE TABLE user_likes (user_id INT,article_id INT); CREATE TABLE articles (id INT,title TEXT,category TEXT);
SELECT (COUNT(*) / (SELECT COUNT(*) FROM users)) * 100.0 AS percentage FROM user_likes JOIN users ON user_likes.user_id = users.id JOIN articles ON user_likes.article_id = articles.id WHERE articles.category = 'sports' INTERSECT SELECT user_likes.user_id FROM user_likes JOIN users ON user_likes.user_id = users.id JOIN articles ON user_likes.article_id = articles.id WHERE articles.category = 'entertainment';
What is the minimum rating of TV shows produced in Japan and released before 2010?
CREATE TABLE tv_shows_jp (id INT,title VARCHAR(100),rating FLOAT,production_year INT,country VARCHAR(50)); INSERT INTO tv_shows_jp (id,title,rating,production_year,country) VALUES (1,'TVShow1',7.5,2005,'Japan'),(2,'TVShow2',8.2,2008,'Japan'),(3,'TVShow3',6.9,2012,'Japan');
SELECT MIN(rating) FROM tv_shows_jp WHERE production_year < 2010 AND country = 'Japan';
What is the total number of traditional arts centers and the number of centers dedicated to music in each province in China?
CREATE TABLE Arts_Centers_China (Center_Name VARCHAR(50),Province VARCHAR(50),Type VARCHAR(50)); INSERT INTO Arts_Centers_China (Center_Name,Province,Type) VALUES ('Shanghai Grand Theatre','Shanghai','Opera'),('National Centre for the Performing Arts','Beijing','Ballet');
SELECT Province, COUNT(*) AS Total_Arts_Centers, SUM(CASE WHEN Type = 'Music' THEN 1 ELSE 0 END) AS Music_Centers FROM Arts_Centers_China GROUP BY Province;
What is the maximum salary of community health workers who identify as African American or Hispanic?
CREATE TABLE CommunityHealthWorkers (Id INT,Race VARCHAR(25),Salary DECIMAL(10,2)); INSERT INTO CommunityHealthWorkers (Id,Race,Salary) VALUES (1,'African American',65000.00),(2,'Hispanic',70000.00),(3,'African American',60000.00),(4,'Hispanic',75000.00),(5,'African American',68000.00);
SELECT MAX(Salary) as MaxSalary FROM CommunityHealthWorkers WHERE Race IN ('African American', 'Hispanic');
Calculate the total claims amount per policy type
CREATE TABLE policy (policy_type VARCHAR(20),total_claims INT); INSERT INTO policy (policy_type,total_claims) VALUES ('Auto',1500),('Home',800),('Life',2000);
SELECT policy_type, SUM(total_claims) AS total_claims FROM policy GROUP BY policy_type;
What is the average temperature recorded in the Arctic Research Station 1 in January?
CREATE TABLE Arctic_Research_Station_1 (date DATE,temperature FLOAT);
SELECT AVG(temperature) FROM Arctic_Research_Station_1 WHERE EXTRACT(MONTH FROM date) = 1;
What is the average budget for genetics research projects in Q1 2022?
CREATE TABLE genetics_research(id INT,project_name TEXT,budget DECIMAL(10,2),quarter INT,year INT);
SELECT AVG(budget) FROM genetics_research WHERE quarter = 1 AND year = 2022;
What is the total production cost of bamboo viscose in China?
CREATE TABLE ProductionCosts (product VARCHAR(255),material VARCHAR(255),cost DECIMAL(10,2)); INSERT INTO ProductionCosts (product,material,cost) VALUES ('Bamboo Viscose','China',8.5);
SELECT SUM(cost) FROM ProductionCosts WHERE product = 'Bamboo Viscose' AND material = 'China';
What is the total waste generation by material type in the state of New York in 2021?'
CREATE TABLE waste_generation (state VARCHAR(20),year INT,material_type VARCHAR(20),quantity INT); INSERT INTO waste_generation VALUES ('New York',2021,'Plastic',1200000),('New York',2021,'Paper',1500000),('New York',2021,'Glass',1000000),('New York',2021,'Metal',800000),('New York',2021,'Organic',2000000);
SELECT material_type, SUM(quantity) AS total_waste FROM waste_generation WHERE state = 'New York' AND year = 2021 GROUP BY material_type;
What is the average accuracy of all models that raised fairness issues in the 'fair_models' table?
CREATE TABLE fair_models (model_name TEXT,accuracy FLOAT,raised_issue INTEGER); INSERT INTO fair_models (model_name,accuracy,raised_issue) VALUES ('model1',0.88,1),('model2',0.92,0),('model3',0.78,1);
SELECT AVG(accuracy) FROM fair_models WHERE raised_issue = 1;
What is the maximum quantity of goods, in metric tons, shipped from China to the United States via the Pacific Ocean?
CREATE TABLE shipping_routes (id INT,departure_country VARCHAR(50),arrival_country VARCHAR(50),departure_region VARCHAR(50),arrival_region VARCHAR(50),transportation_method VARCHAR(50),quantity FLOAT); INSERT INTO shipping_routes (id,departure_country,arrival_country,departure_region,arrival_region,transportation_method,quantity) VALUES (1,'China','United States','Pacific','Pacific','Ship',7000.5),(2,'China','United States','Pacific','Pacific','Ship',8000.2),(3,'China','United States','Pacific','Pacific','Ship',9000.1);
SELECT MAX(quantity) FROM shipping_routes WHERE departure_country = 'China' AND arrival_country = 'United States' AND departure_region = 'Pacific' AND arrival_region = 'Pacific' AND transportation_method = 'Ship';
What is the average calorie count for vegan dishes offered by local restaurants?
CREATE TABLE restaurants (restaurant_id INT,name VARCHAR(50),type VARCHAR(20)); INSERT INTO restaurants (restaurant_id,name,type) VALUES (1,'Green Garden','vegan'); CREATE TABLE dishes (dish_id INT,name VARCHAR(50),calories INT,restaurant_id INT); INSERT INTO dishes (dish_id,name,calories,restaurant_id) VALUES (1,'Veggie Delight',350,1),(2,'Tofu Stir Fry',400,1);
SELECT AVG(calories) FROM dishes JOIN restaurants ON dishes.restaurant_id = restaurants.restaurant_id WHERE restaurants.type = 'vegan';
What is the percentage of accessible technology initiatives in each region worldwide?
CREATE TABLE tech_initiatives_worldwide (id INT,initiative_name VARCHAR(255),location VARCHAR(255),accessibility_score FLOAT);
SELECT location, (SUM(accessibility_score) / (SELECT SUM(accessibility_score) FROM tech_initiatives_worldwide)) * 100 AS percentage FROM tech_initiatives_worldwide GROUP BY location;
Identify mobile subscribers who joined in Q1 2021 and have a monthly data usage greater than the average.
CREATE TABLE mobile_subscribers (subscriber_id INT,join_date DATE,monthly_data_usage DECIMAL(10,2)); INSERT INTO mobile_subscribers (subscriber_id,join_date,monthly_data_usage) VALUES (1,'2021-01-01',3.5),(2,'2021-03-01',4.2),(3,'2021-02-01',3.0),(4,'2021-04-01',4.8),(5,'2021-01-15',5.0),(6,'2021-03-15',4.5),(7,'2021-02-15',3.5),(8,'2021-04-15',5.5);
SELECT subscriber_id, monthly_data_usage FROM mobile_subscribers m WHERE join_date BETWEEN '2021-01-01' AND '2021-03-31' AND monthly_data_usage > (SELECT AVG(monthly_data_usage) FROM mobile_subscribers WHERE join_date BETWEEN '2021-01-01' AND '2021-03-31');
Insert a new record into the "GreenBuildings" table for a new "GreenOffice" building in "Delhi" with a size of 2500
CREATE TABLE GreenBuildings (id INT,building_name VARCHAR(20),material VARCHAR(20),size INT);
INSERT INTO GreenBuildings (building_name, material, size) VALUES ('GreenOffice', 'steel', 2500);
Find the retailer with the highest revenue and the corresponding total quantity of orders.
CREATE TABLE retailers (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),revenue INT); INSERT INTO retailers (id,name,location,revenue) VALUES (1,'Ethical Emporium','London',1000000),(2,'Fair Fashions','Paris',1200000); CREATE TABLE customer_orders (id INT PRIMARY KEY,retailer_id INT,material_id INT,quantity INT); INSERT INTO customer_orders (id,retailer_id,material_id,quantity) VALUES (1,1,1,500),(2,2,2,300);
SELECT r.name, SUM(co.quantity) AS total_quantity FROM retailers r INNER JOIN customer_orders co ON r.id = co.retailer_id GROUP BY r.id ORDER BY r.revenue DESC LIMIT 1;
Update the price of 'Eggplant Parmesan' to $16.99 in the 'Vegetarian' section.
CREATE TABLE Menu (item VARCHAR(20),type VARCHAR(20),price DECIMAL(5,2),quantity INT); INSERT INTO Menu (item,type,price,quantity) VALUES ('Eggplant Parmesan','Vegetarian',15.99,25);
UPDATE Menu SET price = 16.99 WHERE item = 'Eggplant Parmesan' AND type = 'Vegetarian';
What is the total number of military personnel in the 'Air_Force' table?
CREATE TABLE Air_Force (id INT,name VARCHAR(50),rank VARCHAR(20),region VARCHAR(20),num_personnel INT); INSERT INTO Air_Force (id,name,rank,region,num_personnel) VALUES (1,'Alice Johnson','Captain','North America',800);
SELECT SUM(num_personnel) FROM Air_Force;
What is the total revenue from ticket sales for each team's city?
CREATE TABLE teams (team_id INT,team_name VARCHAR(50),city VARCHAR(50));CREATE TABLE tickets (ticket_id INT,team_id INT,price DECIMAL(5,2)); INSERT INTO teams (team_id,team_name,city) VALUES (1,'Atlanta Hawks','Atlanta'),(2,'Boston Celtics','Boston'); INSERT INTO tickets (ticket_id,team_id,price) VALUES (1,1,70.50),(2,1,80.00),(3,2,100.00);
SELECT te.city, SUM(t.price) FROM teams te JOIN tickets t ON te.team_id = t.team_id GROUP BY te.city;
What is the average R&D expenditure per clinical trial in 'CountryG' from 2018 to 2021?
CREATE TABLE rd_expenditure(trial_id TEXT,country TEXT,year INT,amount FLOAT); INSERT INTO rd_expenditure (trial_id,country,year,amount) VALUES ('Trial1','CountryX',2018,2500000),('Trial2','CountryY',2019,3000000),('Trial3','CountryG',2018,4000000),('Trial4','CountryG',2019,4500000),('Trial5','CountryG',2020,5000000),('Trial6','CountryG',2021,5500000); CREATE TABLE clinical_trials(trial_id TEXT,country TEXT,year INT); INSERT INTO clinical_trials (trial_id,country,year) VALUES ('Trial1','CountryX',2018),('Trial2','CountryY',2019),('Trial3','CountryG',2018),('Trial4','CountryG',2019),('Trial5','CountryG',2020),('Trial6','CountryG',2021);
SELECT AVG(rd_expenditure.amount) AS avg_rd_expenditure_per_trial FROM rd_expenditure INNER JOIN clinical_trials ON rd_expenditure.trial_id = clinical_trials.trial_id WHERE rd_expenditure.country = 'CountryG' AND rd_expenditure.year BETWEEN 2018 AND 2021;
Which athletes have participated in the most wellbeing programs in total?
CREATE TABLE athletes (athlete_id INT,athlete_name VARCHAR(50)); INSERT INTO athletes (athlete_id,athlete_name) VALUES (1,'Alex'),(2,'Bella'),(3,'Charles'),(4,'Diana'); CREATE TABLE athlete_program_participation (participation_id INT,athlete_id INT,program_id INT,participation_date DATE); INSERT INTO athlete_program_participation (participation_id,athlete_id,program_id,participation_date) VALUES (1,1,1,'2020-01-01'),(2,1,2,'2020-05-15'),(3,2,3,'2021-03-02'),(4,3,4,'2021-11-28'),(5,1,5,'2021-12-01');
SELECT a.athlete_name, COUNT(*) AS total_participations FROM athletes a INNER JOIN athlete_program_participation app ON a.athlete_id = app.athlete_id GROUP BY a.athlete_name ORDER BY total_participations DESC;
Which regulatory frameworks have been updated in the 'polygon' network since 2020?
CREATE TABLE regulatory_frameworks (framework_id INT,name VARCHAR(255),network VARCHAR(255),last_updated DATE); INSERT INTO regulatory_frameworks (framework_id,name,network,last_updated) VALUES (1,'Framework1','polygon','2022-01-01'),(2,'Framework2','ethereum','2021-12-31');
SELECT * FROM regulatory_frameworks WHERE network = 'polygon' AND last_updated >= '2020-01-01';
Which communities have obesity rates higher than the state average?
CREATE TABLE Community (Name VARCHAR(255),State VARCHAR(255),ObesityRate DECIMAL(5,2)); INSERT INTO Community (Name,State,ObesityRate) VALUES ('Community A','State A',22.5),('Community B','State A',28.0),('Community C','State A',18.5),('Community D','State B',20.0),('Community E','State B',25.0); CREATE TABLE StateHealthData (State VARCHAR(255),AvgObesityRate DECIMAL(5,2)); INSERT INTO StateHealthData (State,AvgObesityRate) VALUES ('State A',23.0),('State B',22.5);
SELECT Name, ObesityRate FROM Community c INNER JOIN StateHealthData shd ON c.State = shd.State WHERE c.ObesityRate > shd.AvgObesityRate;
Which art programs received the most funding in 2020?
CREATE TABLE programs (program_id INT,program_name VARCHAR(50),program_type VARCHAR(50)); CREATE TABLE funding (funding_id INT,program_id INT,amount INT,funding_date DATE); INSERT INTO programs (program_id,program_name,program_type) VALUES (1,'Art Education','Education'),(2,'Symphony Orchestra','Music'); INSERT INTO funding (funding_id,program_id,amount,funding_date) VALUES (1,1,50000,'2020-02-12'),(2,1,75000,'2019-12-01'),(3,2,100000,'2020-05-25');
SELECT programs.program_name, SUM(funding.amount) FROM programs INNER JOIN funding ON programs.program_id = funding.program_id WHERE YEAR(funding_date) = 2020 GROUP BY programs.program_name ORDER BY SUM(funding.amount) DESC;
What is the total number of workplaces in the 'government' sector with a collective bargaining agreement?
CREATE TABLE if NOT EXISTS workplaces (id INT,sector VARCHAR(20),has_cba BOOLEAN); INSERT INTO workplaces (id,sector,has_cba) VALUES (1,'government',true),(2,'government',false),(3,'retail',false);
SELECT COUNT(*) FROM workplaces WHERE sector = 'government' AND has_cba = true;
What are the names and locations of agricultural innovation projects in East Africa that have received funding from the African Development Bank?
CREATE TABLE AgriculturalInnovations (id INT,project_name TEXT,location TEXT,funder TEXT); INSERT INTO AgriculturalInnovations (id,project_name,location,funder) VALUES (1,'AgriTech East Africa','East Africa','African Development Bank'); INSERT INTO AgriculturalInnovations (id,project_name,location,funder) VALUES (2,'Smart Farm East Africa','East Africa','Government of East Africa');
SELECT project_name, location FROM AgriculturalInnovations WHERE funder = 'African Development Bank';
What is the total amount donated by the top 5 donors in the 'donors' table?
CREATE TABLE donors (id INT,name TEXT,amount_donated DECIMAL(10,2)); INSERT INTO donors (id,name,amount_donated) VALUES (1,'John Doe',500.00),(2,'Jane Smith',350.00),(3,'Alice Johnson',400.00),(4,'Bob Brown',600.00),(5,'Charlie Green',700.00);
SELECT SUM(amount_donated) FROM (SELECT amount_donated FROM donors ORDER BY amount_donated DESC LIMIT 5) AS top5_donors;
Update the status of all military equipment items in the Atlantic region to 'Operational'?
CREATE TABLE military_equipment (id INT,name VARCHAR(50),status VARCHAR(50),region VARCHAR(50)); INSERT INTO military_equipment (id,name,status,region) VALUES (1,'Tank A','To be maintained','Pacific'),(2,'Helicopter B','Operational','Atlantic');
UPDATE military_equipment SET status = 'Operational' WHERE region = 'Atlantic';
Add a new union 'Educators Union' with 500 members in the 'midwest' region.
CREATE TABLE unions (id INT,name TEXT,member_count INT,region TEXT); CREATE TABLE members (id INT,union_id INT);
INSERT INTO unions (id, name, member_count, region) VALUES (1, 'Educators Union', 500, 'midwest'); INSERT INTO members (id, union_id) SELECT NULL, id FROM (SELECT 1 + (SELECT MAX(id) FROM unions) AS id) AS seq_table;
What is the average energy efficiency rating in the United States and Canada?
CREATE TABLE energy_efficiency (id INT,country VARCHAR(255),rating INT); INSERT INTO energy_efficiency (id,country,rating) VALUES (1,'United States',80),(2,'Canada',85),(3,'Mexico',75);
SELECT AVG(rating) FROM energy_efficiency WHERE country IN ('United States', 'Canada');
Compare AI models' performance in the finance sector versus the healthcare sector.
CREATE TABLE ai_models (model_name TEXT,performance_score INTEGER,sector TEXT); INSERT INTO ai_models (model_name,performance_score,sector) VALUES ('ModelA',85,'Finance'),('ModelB',90,'Healthcare'),('ModelC',80,'Finance'),('ModelD',92,'Healthcare');
SELECT sector, AVG(performance_score) FROM ai_models GROUP BY sector;
Total carbon credits traded in the EU ETS
CREATE TABLE carbon_credits (id INT,trade_number VARCHAR(255),buyer VARCHAR(255),seller VARCHAR(255),quantity INT,trade_date DATE,market VARCHAR(255));
SELECT SUM(quantity) FROM carbon_credits WHERE market = 'EU ETS';
What is the total number of accidents for each country?
CREATE TABLE country_accidents (id INT,country VARCHAR(50),accident_id INT,accident_type VARCHAR(50)); INSERT INTO country_accidents VALUES (1,'Japan',1,'Collision'),(2,'Japan',2,'Grounding'),(3,'China',3,'Collision');
SELECT country, COUNT(*) FROM country_accidents GROUP BY country;
Insert a new employee into the employees table
CREATE SCHEMA hr; CREATE TABLE employees (id INT,name VARCHAR(50),department VARCHAR(50),salary DECIMAL(10,2));
INSERT INTO employees (id, name, department, salary) VALUES (4, 'Alice Davis', 'IT', 80000.00);
Calculate the average carbon footprint for chemicals with a water usage above 1200.
CREATE TABLE environmental_impact (id INT PRIMARY KEY,chemical_id INT,carbon_footprint INT,water_usage INT); INSERT INTO environmental_impact (id,chemical_id,carbon_footprint,water_usage) VALUES (1,1,500,1500);
SELECT AVG(carbon_footprint) FROM environmental_impact WHERE water_usage > 1200;
Update the production quantity for well 'F' in the 'PermianBasin' to 220 on '2022-01-03'?
CREATE TABLE wells (id VARCHAR(10),name VARCHAR(10),region VARCHAR(20)); INSERT INTO wells (id,name,region) VALUES ('W006','F','PermianBasin'); CREATE TABLE production (well_id VARCHAR(10),date DATE,quantity INT); INSERT INTO production (well_id,date,quantity) VALUES ('W006','2022-01-01',200),('W006','2022-01-02',210);
UPDATE production SET quantity = 220 WHERE well_id = (SELECT id FROM wells WHERE name = 'F' AND region = 'PermianBasin') AND date = '2022-01-03';
What is the total number of intelligence operations in the Latin America and Caribbean region by year?
CREATE TABLE intelligence_operations (id INT,operation_date DATE,region VARCHAR(255)); INSERT INTO intelligence_operations (id,operation_date,region) VALUES (1,'2020-01-01','Latin America'); INSERT INTO intelligence_operations (id,operation_date,region) VALUES (2,'2021-03-15','Europe');
SELECT YEAR(operation_date) AS year, COUNT(*) AS total_operations FROM intelligence_operations WHERE region = 'Latin America' GROUP BY year;
What is the total number of fish in the Salmon farm?
CREATE TABLE FarmStock (farm_id INT,date DATE,action VARCHAR(10),quantity INT); INSERT INTO FarmStock (farm_id,date,action,quantity) VALUES (2,'2020-01-01','added',300),(2,'2020-01-05','added',250);
SELECT SUM(quantity) total_fish FROM FarmStock WHERE farm_id = 2 AND action = 'added';
What is the combined capacity of all renewable energy farms (wind and solar) in the 'North' region?
CREATE TABLE wind_farms (id INT,name VARCHAR(50),region VARCHAR(50),capacity FLOAT,efficiency FLOAT); INSERT INTO wind_farms (id,name,region,capacity,efficiency) VALUES (1,'Windfarm A','North',110.9,0.28); CREATE TABLE solar_farms (id INT,name VARCHAR(50),region VARCHAR(50),capacity FLOAT,efficiency FLOAT); INSERT INTO solar_farms (id,name,region,capacity,efficiency) VALUES (1,'Solarfarm A','North',160.2,0.31);
SELECT SUM(capacity) AS total_capacity FROM wind_farms WHERE region = 'North' UNION SELECT SUM(capacity) AS total_capacity FROM solar_farms WHERE region = 'North';
Insert a new row of Lanthanum production for 'EcoTech' in Brazil on 2023-05-01 with a quantity of 300.0.
CREATE TABLE lanthanum_production (id INT,name VARCHAR(255),element VARCHAR(10),country VARCHAR(100),production_date DATE,quantity FLOAT);
INSERT INTO lanthanum_production (id, name, element, country, production_date, quantity) VALUES (1, 'EcoTech', 'La', 'Brazil', '2023-05-01', 300.0);
List the names of all farms that have been imaged by at least two satellites.
CREATE TABLE SatelliteImages(satellite VARCHAR(255),farm VARCHAR(255)); INSERT INTO SatelliteImages(satellite,farm) VALUES('S1','F1'),('S1','F2'),('S1','F3'),('S2','F1'),('S2','F2'),('S3','F2'),('S3','F3'),('S4','F4'),('S4','F5');
SELECT farm FROM SatelliteImages GROUP BY farm HAVING COUNT(DISTINCT satellite) >= 2;
What is the maximum temperature in the Arctic Ocean?
CREATE TABLE ocean_temperatures (ocean TEXT,temperature FLOAT); INSERT INTO ocean_temperatures (ocean,temperature) VALUES ('Arctic Ocean',-1.8),('Arctic Ocean',-1.9),('Arctic Ocean',-1.7);
SELECT MAX(temperature) FROM ocean_temperatures WHERE ocean = 'Arctic Ocean';
How many hospitals in the 'Inner City' district have a patient satisfaction rating greater than 85?
CREATE TABLE hospitals (hospital_id INT,hospital_name TEXT,district TEXT,patient_satisfaction_rating INT); INSERT INTO hospitals (hospital_id,hospital_name,district,patient_satisfaction_rating) VALUES (1,'City General','Inner City',88),(2,'Metro Hospital','Uptown',75),(3,'Harbor Hospital','Harbor',92);
SELECT COUNT(*) FROM hospitals WHERE district = 'Inner City' AND patient_satisfaction_rating > 85;
List all distinct accommodation_types
CREATE TABLE accommodation_types (accommodation_type VARCHAR(255));
SELECT DISTINCT accommodation_type FROM accommodation_types;
What is the total number of rural healthcare facilities in Australia and New Zealand?
CREATE TABLE healthcare_facilities_anz (name TEXT,location TEXT,country TEXT); INSERT INTO healthcare_facilities_anz (name,location,country) VALUES ('Facility 1','Rural Australia','Australia'),('Facility 2','Rural New Zealand','New Zealand'),('Facility 3','Urban New Zealand','New Zealand');
SELECT COUNT(*) FROM healthcare_facilities_anz WHERE country IN ('Australia', 'New Zealand') AND location LIKE 'Rural%'
Identify the number of fair labor certifications by country.
CREATE TABLE FairLabor(id INT,country VARCHAR(50),certification_count INT); INSERT INTO FairLabor(id,country,certification_count) VALUES (1,'Bangladesh',250),(2,'India',300),(3,'Cambodia',180);
SELECT country, certification_count FROM FairLabor;
How many employees have completed diversity and inclusion training?
CREATE TABLE training_records (id INT,employee_id INT,training_type VARCHAR(255),completion_date DATE); INSERT INTO training_records (id,employee_id,training_type,completion_date) VALUES (1,1,'Diversity and Inclusion','2021-02-01'),(2,2,'Sexual Harassment Prevention','2021-03-15'),(3,3,'Diversity and Inclusion',NULL),(4,4,'Sexual Harassment Prevention','2021-04-30'),(5,5,NULL,NULL);
SELECT COUNT(*) as num_completed FROM training_records WHERE training_type = 'Diversity and Inclusion' AND completion_date IS NOT NULL;
What is the total number of ticket sales for the 'TeamA' vs 'TeamB' match?
CREATE TABLE ticket_sales (match VARCHAR(255),tickets_sold INT); INSERT INTO ticket_sales (match,tickets_sold) VALUES ('TeamA vs TeamB',1500),('TeamC vs TeamD',1200);
SELECT tickets_sold FROM ticket_sales WHERE match = 'TeamA vs TeamB';
What is the total production quantity (in metric tons) of Europium from the mine with the ID 2 for the year 2018?
CREATE TABLE production (id INT,mine_id INT,year INT,element TEXT,production_quantity INT); INSERT INTO production (id,mine_id,year,element,production_quantity) VALUES (1,2,2018,'Europium',120),(2,3,2018,'Europium',180),(3,4,2018,'Europium',240),(4,2,2018,'Gadolinium',300),(5,3,2018,'Gadolinium',420),(6,4,2018,'Gadolinium',540);
SELECT SUM(production_quantity) FROM production WHERE mine_id = 2 AND year = 2018 AND element = 'Europium';
What is the number of unloaded containers for each port in the 'port_operations' table?
CREATE TABLE port_operations (id INT,port VARCHAR(50),operation_type VARCHAR(50),container_count INT); INSERT INTO port_operations (id,port,operation_type,container_count) VALUES (1,'LA','Load',200),(2,'LA','Unload',150),(3,'NY','Load',300),(4,'NY','Unload',250),(5,'MIA','Load',100),(6,'MIA','Unload',200);
SELECT port, SUM(container_count) FROM port_operations WHERE operation_type = 'Unload' GROUP BY port;
What is the average cargo weight for vessels that have had at least one accident?
CREATE TABLE Vessels (ID INT PRIMARY KEY,Name TEXT,CargoWeight FLOAT); INSERT INTO Vessels (ID,Name,CargoWeight) VALUES (1,'Cargo Ship 1',5500),(2,'Cargo Ship 2',7000),(3,'Cargo Ship 3',4800);
SELECT AVG(CargoWeight) FROM Vessels INNER JOIN (SELECT VesselID, COUNT(*) FROM Accidents GROUP BY VesselID HAVING COUNT(*) > 0) AS Accidents ON Vessels.ID = Accidents.VesselID;
What is the total revenue for 'Delicious Diner' in Q3 2019?
CREATE TABLE Revenue (restaurant_id INT,quarter INT,year INT,revenue INT); INSERT INTO Revenue (restaurant_id,quarter,year,revenue) VALUES (7,3,2019,7000);
SELECT SUM(revenue) FROM Revenue WHERE restaurant_id = 7 AND EXTRACT(QUARTER FROM DATE '2019-01-01' + INTERVAL (quarter - 1) * 3 MONTH) = 3 AND EXTRACT(YEAR FROM DATE '2019-01-01' + INTERVAL (quarter - 1) * 3 MONTH) = 2019;
What is the maximum number of courses completed by a teacher in each subject area?
CREATE TABLE subjects (subject_id INT,subject_name TEXT); CREATE TABLE teachers (teacher_id INT,subject_id INT); CREATE TABLE courses (course_id INT,subject_id INT,teacher_id INT); INSERT INTO subjects VALUES (1,'Math'),(2,'Science'),(3,'English'); INSERT INTO teachers VALUES (1,1),(2,2),(3,3); INSERT INTO courses VALUES (1,1,1),(2,1,1),(3,2,2),(4,3,3);
SELECT s.subject_name, MAX(COUNT(c.course_id)) as max_courses_completed FROM subjects s JOIN teachers t ON s.subject_id = t.subject_id LEFT JOIN courses c ON t.teacher_id = c.teacher_id GROUP BY s.subject_id;
What is the average fare for bus routes in the 'Southside' division?
CREATE TABLE division (division_id INT,division_name TEXT); INSERT INTO division (division_id,division_name) VALUES (1,'Northside'),(2,'Southside'),(3,'Eastside'),(4,'Westside'); CREATE TABLE route (route_id INT,division_id INT,route_name TEXT,fare DECIMAL); INSERT INTO route (route_id,division_id,route_name,fare) VALUES (1,2,'R1',2.50),(2,2,'R2',2.50),(3,3,'R3',3.00),(4,4,'R4',3.50);
SELECT AVG(fare) FROM route WHERE division_id = 2;
What is the maximum depth of any ocean feature?
CREATE TABLE ocean_features (name TEXT,depth FLOAT); INSERT INTO ocean_features (name,depth) VALUES ('Mariana Trench',10994.0),('Puerto Rico Trench',8605.0),('Siberian Traps',3000.0);
SELECT MAX(depth) FROM ocean_features;
Update the hotel with ID 456 in the hotels table to be eco-friendly.
CREATE TABLE hotels (hotel_id INT,name VARCHAR(50),country VARCHAR(50),stars INT,is_eco_friendly BOOLEAN);
UPDATE hotels SET is_eco_friendly = TRUE WHERE hotel_id = 456;
Find the average depth of all marine protected areas (MPAs)
CREATE TABLE mpas (id INT,name TEXT,region TEXT,avg_depth REAL);
SELECT AVG(avg_depth) FROM mpas WHERE region = 'Caribbean';
What is the total quantity of products supplied by companies in 'Indonesia' and 'Vietnam'?
CREATE TABLE suppliers (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),sustainability_score INT); INSERT INTO suppliers (id,name,country,sustainability_score) VALUES (1,'Supplier X','Indonesia',75),(2,'Supplier Y','Vietnam',80),(3,'Supplier Z','Indonesia',85); CREATE TABLE products (id INT PRIMARY KEY,name VARCHAR(255),supplier_id INT,quantity INT,FOREIGN KEY (supplier_id) REFERENCES suppliers(id)); INSERT INTO products (id,name,supplier_id,quantity) VALUES (1,'Product A',1,100),(2,'Product B',2,200),(3,'Product C',3,150),(4,'Product D',1,250);
SELECT SUM(quantity) FROM products p INNER JOIN suppliers s ON p.supplier_id = s.id WHERE s.country IN ('Indonesia', 'Vietnam');
Identify the top three countries with the highest recycling rates for glass waste.
CREATE TABLE GlassWaste (Country VARCHAR(50),RecyclingRate DECIMAL(5,2)); INSERT INTO GlassWaste (Country,RecyclingRate) VALUES ('Switzerland',0.96),('Sweden',0.93),('Belgium',0.91),('Germany',0.90),('Finland',0.89);
SELECT Country, RecyclingRate FROM GlassWaste ORDER BY RecyclingRate DESC, Country ASC LIMIT 3;
What is the number of users who have used virtual tours for each hotel in the virtual_tour_usage view?
CREATE VIEW virtual_tour_usage AS SELECT h.hotel_id,h.hotel_name,COUNT(DISTINCT c.customer_id) AS num_users FROM hotels h JOIN customer_support c ON h.hotel_id = c.hotel_id WHERE c.used_virtual_tour = TRUE GROUP BY h.hotel_id;
SELECT hotel_name, AVG(num_users) FROM virtual_tour_usage GROUP BY hotel_name;
Insert a new record into the 'Manufacturers' table for 'Manufacturer C' with an id of 3
CREATE TABLE Manufacturers (id INT,name VARCHAR(255)); INSERT INTO Manufacturers (id,name) VALUES (1,'Manufacturer A'),(2,'Manufacturer B');
INSERT INTO Manufacturers (id, name) VALUES (3, 'Manufacturer C');
What is the total network investment for each region?
CREATE TABLE network_investments (region VARCHAR(20),investment FLOAT); INSERT INTO network_investments (region,investment) VALUES ('North',5000000),('South',7000000),('East',3000000);
SELECT region, SUM(investment) AS total_investment FROM network_investments GROUP BY region;
Display the names and locations of all marine research projects in the 'Research' schema's 'Projects' table
CREATE TABLE Research.Projects (id INT,project_name VARCHAR(255),location VARCHAR(255));
SELECT project_name, location FROM Research.Projects;
What is the average recycling rate of metal by province in 2021?
CREATE TABLE recycling_rates (id INT,year INT,province VARCHAR(255),material VARCHAR(255),recycling_rate DECIMAL(5,2));
SELECT province, AVG(recycling_rate) as avg_recycling_rate FROM recycling_rates WHERE year = 2021 AND material = 'metal' GROUP BY province;
List the number of safe AI algorithms grouped by their evaluation category.
CREATE TABLE safe_ai_algorithms_evaluations (id INT,algorithm VARCHAR(25),evaluation VARCHAR(25),score FLOAT); INSERT INTO safe_ai_algorithms_evaluations (id,algorithm,evaluation,score) VALUES (1,'AlgorithmA','Robustness',0.92),(2,'AlgorithmB','Security',0.95),(3,'AlgorithmC','Reliability',0.88),(4,'AlgorithmD','Robustness',0.98);
SELECT evaluation, COUNT(*) as num_algorithms FROM safe_ai_algorithms_evaluations GROUP BY evaluation;
List the total cargo weight for each cargo type in the 'cargo_tracking' table, grouped by week?
CREATE TABLE cargo_tracking (cargo_id INT,cargo_type VARCHAR(50),weight FLOAT,timestamp TIMESTAMP);
SELECT DATE_FORMAT(timestamp, '%Y-%u') AS week, cargo_type, SUM(weight) FROM cargo_tracking GROUP BY week, cargo_type;
What are the total production quantities for all wells in the North Sea, grouped by the year they were drilled?
CREATE TABLE wells (well_id INT,well_name TEXT,production_qty FLOAT,drill_year INT,region TEXT); INSERT INTO wells (well_id,well_name,production_qty,drill_year,region) VALUES (1,'Well A',1000,2018,'North Sea'),(2,'Well B',1500,2019,'North Sea'),(3,'Well C',800,2020,'North Sea');
SELECT drill_year, SUM(production_qty) as total_production FROM wells WHERE region = 'North Sea' GROUP BY drill_year;
What is the average number of refugees helped per day by aid_organization 2 in the refugee_support table?
CREATE TABLE refugee_support (id INT PRIMARY KEY,aid_organization INT,refugees_helped INT,date DATE); INSERT INTO refugee_support (id,aid_organization,refugees_helped,date) VALUES (1,1,100,'2022-01-01'); INSERT INTO refugee_support (id,aid_organization,refugees_helped,date) VALUES (2,2,200,'2022-01-02'); INSERT INTO refugee_support (id,aid_organization,refugees_helped,date) VALUES (3,2,300,'2022-01-03');
SELECT AVG(refugees_helped) FROM refugee_support WHERE aid_organization = 2;
Who scored the most goals in the 2018 FIFA World Cup?
CREATE TABLE fifa_world_cup_2018 (player VARCHAR(50),goals INT); INSERT INTO fifa_world_cup_2018 (player,goals) VALUES ('Harry Kane',6),('Antoine Griezmann',4),('Romelu Lukaku',4);
SELECT player, MAX(goals) AS top_scorer FROM fifa_world_cup_2018;
What is the total revenue generated by Latin music in the United States since 2015?
CREATE TABLE revenue (id INT,region VARCHAR(255),year INT,amount INT); INSERT INTO revenue (id,region,year,amount) VALUES (1,'United States',2015,5000000);
SELECT SUM(amount) FROM revenue WHERE region = 'United States' AND genre = 'Latin' AND year >= 2015;
What is the total data usage for each region, sorted by usage in descending order?
CREATE TABLE mobile_customers (customer_id INT,plan_type VARCHAR(10),data_usage FLOAT,region VARCHAR(20)); INSERT INTO mobile_customers (customer_id,plan_type,data_usage,region) VALUES (1,'postpaid',3.5,'Chicago'),(2,'prepaid',2.0,'Chicago'),(3,'postpaid',5.0,'New York'); CREATE TABLE regions (region VARCHAR(20)); INSERT INTO regions (region) VALUES ('Chicago'),('New York');
SELECT r.region, SUM(mc.data_usage) AS total_data_usage FROM mobile_customers mc JOIN regions r ON mc.region = r.region GROUP BY r.region ORDER BY total_data_usage DESC;
List all unique donors and their total donation amount for causes related to education.
CREATE TABLE philanthropy.causes (cause_id INT,cause_name TEXT,cause_category TEXT); INSERT INTO philanthropy.causes (cause_id,cause_name,cause_category) VALUES (1,'Education Fund','Education'),(2,'Medical Research','Health');
SELECT d.donor_id, SUM(d.amount) FROM philanthropy.donations d JOIN philanthropy.causes c ON d.cause_id = c.cause_id WHERE c.cause_category = 'Education' GROUP BY d.donor_id;
What are the total donations made by individual donors from 'country_US' who have made donations in the last 6 months?
CREATE TABLE donor (donor_id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO donor (donor_id,name,country) VALUES (1,'John Doe','country_US'); INSERT INTO donor (donor_id,name,country) VALUES (2,'Jane Smith','country_CA'); CREATE TABLE donation (donation_id INT,donor_id INT,amount DECIMAL(10,2),donation_date DATE); INSERT INTO donation (donation_id,donor_id,amount,donation_date) VALUES (1,1,500,'2021-01-01'); INSERT INTO donation (donation_id,donor_id,amount,donation_date) VALUES (2,1,400,'2021-02-15');
SELECT SUM(d.amount) as total_donations FROM donation d INNER JOIN donor don ON d.donor_id = don.donor_id WHERE don.country = 'country_US' AND d.donation_date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH);
Which programs have the same number of male and female attendees?
CREATE TABLE attendee_demographics (attendee_id INT,program_id INT,gender VARCHAR(6)); INSERT INTO attendee_demographics (attendee_id,program_id,gender) VALUES (101,1,'male'),(102,1,'female'),(103,2,'male'),(104,2,'male'),(105,3,'female');
SELECT program_id, COUNT(CASE WHEN gender = 'male' THEN 1 ELSE NULL END) AS num_males, COUNT(CASE WHEN gender = 'female' THEN 1 ELSE NULL END) AS num_females FROM attendee_demographics GROUP BY program_id HAVING num_males = num_females;
Who are the users who have posted in 'Russia' but not in 'China'?
CREATE TABLE user_posts (user_id INT,post_country VARCHAR(50)); INSERT INTO user_posts (user_id,post_country) VALUES (1,'Russia'); INSERT INTO user_posts (user_id,post_country) VALUES (2,'China'); INSERT INTO user_posts (user_id,post_country) VALUES (3,'USA'); CREATE TABLE users (id INT,name VARCHAR(50),post_country VARCHAR(50)); INSERT INTO users (id,name,post_country) VALUES (1,'Eugene','Russia'); INSERT INTO users (id,name,post_country) VALUES (2,'Fiona','China'); INSERT INTO users (id,name,post_country) VALUES (3,'George','USA');
SELECT name FROM users WHERE id IN (SELECT user_id FROM user_posts WHERE post_country = 'Russia') AND id NOT IN (SELECT user_id FROM user_posts WHERE post_country = 'China');
What is the percentage of total donations made by donors from 'California'?
CREATE TABLE donors (donor_id INT,donor_name VARCHAR(255),state VARCHAR(255)); CREATE TABLE donations (donation_id INT,donor_id INT,donation_date DATE,donation_amount DECIMAL(10,2)); INSERT INTO donors (donor_id,donor_name,state) VALUES (1,'John Doe','California'),(2,'Jane Smith','New York'),(3,'Bob Johnson','California'); INSERT INTO donations (donation_id,donor_id,donation_date,donation_amount) VALUES (1,1,'2022-01-02',100),(2,2,'2022-02-15',200),(3,1,'2022-03-10',150);
SELECT (SUM(d.donation_amount) * 100.0 / (SELECT SUM(donation_amount) FROM donations)) as donation_percentage FROM donations d JOIN donors don ON d.donor_id = don.donor_id WHERE don.state = 'California';
Find the average production quantity for wells in the North Sea
CREATE TABLE production (well_id INT,date DATE,quantity FLOAT); INSERT INTO production (well_id,date,quantity) VALUES (1,'2021-01-01',100.0),(1,'2021-01-02',120.0),(2,'2021-01-01',150.0);
SELECT AVG(quantity) FROM production p JOIN wells w ON p.well_id = w.id WHERE w.location = 'North Sea';
What is the total revenue for each restaurant, including their sustainable sourcing efforts?
CREATE TABLE Restaurants (RestaurantID INT,Name VARCHAR(50),TotalRevenue DECIMAL(10,2)); CREATE TABLE SustainableSourcing (SourcingID INT,RestaurantID INT,SustainabilityScore INT);
SELECT R.Name, R.TotalRevenue + SUM(SS.SustainabilityScore) as TotalRevenueAndSustainabilityScore FROM Restaurants R INNER JOIN SustainableSourcing SS ON R.RestaurantID = SS.RestaurantID GROUP BY R.Name;
Insert a new record into the menu_items table for a vegan dish, 'tofu curry', priced at $12.50
CREATE TABLE menu_items (menu_item_id INT,name VARCHAR(50),description TEXT,price DECIMAL(5,2),category VARCHAR(20),is_vegan BOOLEAN);
INSERT INTO menu_items (name, description, price, category, is_vegan) VALUES ('tofu curry', 'Silky tofu in a rich coconut curry sauce', 12.50, 'entree', TRUE);
What is the total number of subscribers to 'NewsPaperA' and 'NewsPaperB' in each country, and what are their names?
CREATE TABLE NewsPaperA (id INT,subscriber_name VARCHAR(30),country VARCHAR(20)); CREATE TABLE NewsPaperB (id INT,subscriber_name VARCHAR(30),country VARCHAR(20));
SELECT COUNT(npa.id) as total_subscribers, npa.country, npb.subscriber_name FROM NewsPaperA npa JOIN NewsPaperB npb ON npa.subscriber_name = npb.subscriber_name GROUP BY npa.country, npb.subscriber_name;
List of autonomous vehicles with safety ratings between 8.5 and 9.0.
CREATE TABLE autonoumous_vehicles_rating (id INT PRIMARY KEY,make VARCHAR(50),model VARCHAR(50),safety_rating FLOAT); INSERT INTO autonoumous_vehicles_rating (id,make,model,safety_rating) VALUES (1,'Tesla','Model 3',8.9),(2,'Waymo','Waymo One',9.5),(3,'NVIDIA','DRIVE AGX',9.1),(4,'Baidu','Apollo',8.8),(5,'Uber','ATG',8.6);
SELECT make, model, safety_rating FROM autonoumous_vehicles_rating WHERE safety_rating BETWEEN 8.5 AND 9.0;
What is the total CO2 emission for each country in 2020 from the Energy sector?
CREATE TABLE EnergyEmissions (country VARCHAR(50),year INT,sector VARCHAR(50),co2_emission INT); INSERT INTO EnergyEmissions (country,year,sector,co2_emission) VALUES ('Canada',2020,'Energy',550000),('Mexico',2020,'Energy',420000),('Brazil',2020,'Energy',480000);
SELECT country, SUM(co2_emission) as 'Total CO2 Emission' FROM EnergyEmissions WHERE year = 2020 AND sector = 'Energy' GROUP BY country;
What is the average CO2 emission of cosmetics products manufactured in the USA?
CREATE TABLE co2_emissions (id INT,product VARCHAR(255),country VARCHAR(255),co2_emission FLOAT); INSERT INTO co2_emissions (id,product,country,co2_emission) VALUES (1,'Lipstick','USA',2.5),(2,'Mascara','France',1.5),(3,'Eyeliner','USA',2.0);
SELECT AVG(co2_emission) FROM co2_emissions WHERE country = 'USA';
Which are the top 5 ports with the most cargo weight handled in 2021?
CREATE TABLE ports (port_id INT,port_name VARCHAR(255),country VARCHAR(255)); INSERT INTO ports VALUES (1,'Port of Shanghai','China'); CREATE TABLE cargo (cargo_id INT,port_id INT,weight FLOAT,handling_date DATE); INSERT INTO cargo VALUES (1,1,5000,'2021-01-01');
SELECT p.port_name, SUM(c.weight) as total_weight FROM ports p JOIN cargo c ON p.port_id = c.port_id WHERE handling_date >= '2021-01-01' AND handling_date < '2022-01-01' GROUP BY p.port_name ORDER BY total_weight DESC LIMIT 5;
What is the average total cost of projects in the 'Energy_Efficiency' table?
CREATE TABLE Energy_Efficiency (project_id INT,project_name VARCHAR(50),location VARCHAR(50),total_cost FLOAT); INSERT INTO Energy_Efficiency (project_id,project_name,location,total_cost) VALUES (1,'Building Insulation','City Hall',100000.00),(2,'LED Lighting Retrofit','Library',50000.00),(3,'Solar Panel Installation','Recreation Center',250000.00);
SELECT AVG(total_cost) FROM Energy_Efficiency;
Which province in Canada has the highest energy storage capacity?
CREATE TABLE energy_storage_Canada (province VARCHAR(255),source_type VARCHAR(255),capacity INT); INSERT INTO energy_storage_Canada (province,source_type,capacity) VALUES ('Ontario','Batteries',3000),('Quebec','Batteries',4000),('Ontario','Pumped Hydro',8000);
SELECT province, MAX(capacity) FROM energy_storage_Canada GROUP BY province;
What is the total prize money for esports events in the 'Action' genre?
CREATE TABLE EsportsEvents (EventID INT PRIMARY KEY,EventName VARCHAR(50),GameName VARCHAR(50),PrizeMoney DECIMAL(10,2),EventDate DATE); INSERT INTO EsportsEvents (EventID,EventName,GameName,PrizeMoney,EventDate) VALUES (5,'EventE','GameD',12000,'2021-06-15'),(6,'EventF','GameE',18000,'2022-06-30'),(7,'EventG','GameA',22000,'2022-12-31'); CREATE TABLE Games (GameID INT PRIMARY KEY,GameName VARCHAR(50),Genre VARCHAR(30),ReleaseDate DATE); INSERT INTO Games (GameID,GameName,Genre,ReleaseDate) VALUES (1,'GameA','Action','2018-01-01'),(4,'GameD','Action','2021-01-01'),(5,'GameE','Adventure','2022-05-15');
SELECT SUM(PrizeMoney) FROM EsportsEvents JOIN Games ON EsportsEvents.GameName = Games.GameName WHERE Games.Genre = 'Action';
What is the total weight of cannabis trim sold in Michigan dispensaries in Q1 2022?
CREATE TABLE dispensaries (dispensary_id INT,state CHAR(2)); INSERT INTO dispensaries (dispensary_id,state) VALUES (1,'MI'),(2,'CA'),(3,'OR'); CREATE TABLE sales (dispensary_id INT,sale_date DATE,product_type VARCHAR(50),weight DECIMAL(5,2)); INSERT INTO sales (dispensary_id,sale_date,product_type,weight) VALUES (1,'2022-01-01','trim',5.5),(1,'2022-02-01','trim',6.2),(2,'2022-01-01','trim',7.1);
SELECT SUM(weight) FROM sales s JOIN dispensaries d ON s.dispensary_id = d.dispensary_id WHERE d.state = 'MI' AND s.product_type = 'trim' AND s.sale_date BETWEEN '2022-01-01' AND '2022-03-31';
What is the difference in salary between the highest and lowest paid employee in each department?
CREATE TABLE employees (id INT,name VARCHAR(50),department VARCHAR(50),salary DECIMAL(5,2)); INSERT INTO employees (id,name,department,salary) VALUES (1,'John Doe','IT',50000.00); INSERT INTO employees (id,name,department,salary) VALUES (2,'Jane Smith','HR',55000.00);
SELECT department, MAX(salary) - MIN(salary) as salary_range FROM employees GROUP BY department;
Present the total package weight for each warehouse in the 'warehouses' table.
CREATE TABLE packages (package_id INT,item_id INT,weight FLOAT,warehouse_id INT); INSERT INTO packages (package_id,item_id,weight,warehouse_id) VALUES (1,1,3.5,1),(2,2,2.8,1),(3,3,1.2,2); CREATE TABLE warehouses (warehouse_id INT,warehouse_name VARCHAR(20)); INSERT INTO warehouses (warehouse_id,warehouse_name) VALUES (1,'warehouse1'),(2,'warehouse2');
SELECT packages.warehouse_id, SUM(packages.weight) FROM packages JOIN warehouses ON packages.warehouse_id = warehouses.warehouse_id GROUP BY packages.warehouse_id;
How many Zika cases were reported in Florida in 2018?
CREATE TABLE Zika_Cases (ID INT,CaseCount INT,ReportDate DATE,State VARCHAR(20)); INSERT INTO Zika_Cases (ID,CaseCount,ReportDate,State) VALUES (1,5,'2018-01-01','Florida'); INSERT INTO Zika_Cases (ID,CaseCount,ReportDate,State) VALUES (2,3,'2018-02-01','Florida');
SELECT SUM(CaseCount) FROM Zika_Cases WHERE YEAR(ReportDate) = 2018 AND State = 'Florida';
What is the total number of workouts for each member?
CREATE TABLE workout_data (member_id INT,workout_date DATE); INSERT INTO workout_data (member_id,workout_date) VALUES (1,'2022-01-01'),(1,'2022-01-02'),(2,'2022-01-01'),(2,'2022-01-03'),(3,'2022-01-02'),(3,'2022-01-03'),(3,'2022-01-04'),(4,'2022-01-04');
SELECT member_id, COUNT(*) AS total_workouts FROM workout_data GROUP BY member_id;
Update user information (address, email) where their membership type is 'premium'
CREATE TABLE users (id INT PRIMARY KEY,name VARCHAR(255),address VARCHAR(255),email VARCHAR(255),membership VARCHAR(50));
UPDATE users SET address = 'new_address', email = 'new_email' WHERE membership = 'premium';
What is the maximum number of workers on a single project in the state of New York?
CREATE TABLE Projects (project_id INT,state VARCHAR(255),num_workers INT); INSERT INTO Projects (project_id,state,num_workers) VALUES (1,'New York',10),(2,'New York',15);
SELECT MAX(num_workers) FROM Projects WHERE state = 'New York';
Find the 'building_name' and 'certification' for all green buildings in the 'Europe' region with a 'certification' of 'BREEAM' or 'LEED'.
CREATE TABLE green_buildings (building_id INT,building_name VARCHAR(255),certification VARCHAR(255),region VARCHAR(255)); INSERT INTO green_buildings (building_id,building_name,certification,region) VALUES (1,'Building A','LEED','Americas'),(2,'Building B','BREEAM','Europe'),(3,'Building C','LEED','Americas'),(4,'Building D','WELL','Asia');
SELECT building_name, certification FROM green_buildings WHERE region = 'Europe' AND (certification = 'BREEAM' OR certification = 'LEED');
Delete records with a population density over 5000 in the 'rural_settlements' table
CREATE TABLE rural_settlements (name VARCHAR(255),population INT,population_density INT,country VARCHAR(255));
DELETE FROM rural_settlements WHERE population_density > 5000;