instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Determine the average attendance for each NHL team's home games.
CREATE TABLE teams (team_id INT,team_name VARCHAR(50)); CREATE TABLE games (game_id INT,home_team_id INT,attendance INT);
SELECT home_team_id, AVG(attendance) AS avg_attendance FROM games WHERE home_team_id = teams.team_id GROUP BY home_team_id;
What is the average amount of money spent on rural infrastructure projects in the 'rural_infrastructure' table, partitioned by the region and ordered by the average amount spent in ascending order?;
CREATE TABLE rural_infrastructure (id INT,project_name VARCHAR(50),region VARCHAR(50),amount_spent DECIMAL(10,2)); INSERT INTO rural_infrastructure VALUES (1,'Road Construction','North',50000.00),(2,'Bridge Building','South',75000.00),(3,'Water Supply','Central',60000.00),(4,'Electricity Distribution','East',80000.00),(5,'School Building','West',45000.00);
SELECT region, AVG(amount_spent) as avg_amount_spent FROM rural_infrastructure GROUP BY region ORDER BY avg_amount_spent ASC;
What is the total number of mental health parity violations in the Northeast and Midwest regions?
CREATE TABLE mental_health_parity_region (region VARCHAR(10),violations INT); INSERT INTO mental_health_parity_region (region,violations) VALUES ('Northeast',35),('Midwest',40),('South',25);
SELECT region, SUM(violations) FROM mental_health_parity_region WHERE region IN ('Northeast', 'Midwest') GROUP BY region;
What is the total number of union members in the 'education' and 'mining' sectors?
CREATE TABLE union_membership (id INT,name VARCHAR(50),sector VARCHAR(50),is_member BOOLEAN); INSERT INTO union_membership (id,name,sector,is_member) VALUES (1,'Alice','education',TRUE); INSERT INTO union_membership (id,name,sector,is_member) VALUES (2,'Bob','technology',FALSE); INSERT INTO union_membership (id,name,sector,is_member) VALUES (3,'Charlie','mining',TRUE);
SELECT SUM(is_member) FROM union_membership WHERE sector IN ('education', 'mining');
Find the number of financial institutions offering financial capability programs in the African region.
CREATE TABLE financial_institutions (institution_id INT,institution_name TEXT,region TEXT,offers_financial_capability BOOLEAN);
SELECT COUNT(institution_id) FROM financial_institutions WHERE region = 'African' AND offers_financial_capability = TRUE;
What is the percentage of workers in the automotive industry who have received industry 4.0 training in North America?
CREATE TABLE workers (id INT,industry VARCHAR(50),region VARCHAR(50),industry_4_0_training BOOLEAN);
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM workers w WHERE industry = 'automotive' AND region = 'North America')) AS percentage FROM workers w WHERE industry = 'automotive' AND region = 'North America' AND industry_4_0_training = TRUE;
What is the average response time for fire emergencies in each community?
CREATE TABLE communities (community_id INT,community_name VARCHAR(50)); CREATE TABLE emergencies (emergency_id INT,community_id INT,emergency_type VARCHAR(50),responded_date DATE,response_time INT); INSERT INTO communities (community_id,community_name) VALUES (1,'Community A'),(2,'Community B'),(3,'Community C'); INSERT INTO emergencies (emergency_id,community_id,emergency_type,responded_date,response_time) VALUES (1,1,'Fire','2021-01-01',15),(2,2,'Medical','2021-02-01',20),(3,3,'Police','2021-03-01',12),(4,1,'Fire','2021-04-01',18),(5,2,'Medical','2021-05-01',10);
SELECT e.community_id, c.community_name, AVG(e.response_time) AS avg_response_time FROM emergencies e JOIN communities c ON e.community_id = c.community_id WHERE e.emergency_type = 'Fire' GROUP BY e.community_id, c.community_name;
How many volunteers are registered in the 'volunteers' table?
CREATE TABLE volunteers (id INT,name TEXT,email TEXT,city TEXT);
SELECT COUNT(*) FROM volunteers;
What is the percentage of cosmetics sold in Canada in 2021 that were vegan?
CREATE TABLE sales (id INT,brand VARCHAR(255),contains_parabens BOOLEAN,is_vegan BOOLEAN,country VARCHAR(255),sales_amount DECIMAL(10,2),sale_date DATE);
SELECT 100.0 * SUM(CASE WHEN is_vegan THEN 1 ELSE 0 END) / COUNT(*) as percentage FROM sales WHERE country = 'Canada' AND sale_date BETWEEN '2021-01-01' AND '2021-12-31';
What is the average humidity in field L during the last 3 days?
CREATE TABLE Humidity_L (field VARCHAR(50),date DATE,humidity FLOAT); INSERT INTO Humidity_L (field,date,humidity) VALUES ('Field L','2022-06-01',65.2),('Field L','2022-06-02',62.1),('Field L','2022-06-03',68.6);
SELECT AVG(humidity) FROM Humidity_L WHERE field = 'Field L' AND date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 DAY);
List all menu items that have a rating of 5 and are vegan-friendly.
CREATE TABLE menu_items(id INT,name VARCHAR(255),rating INT,is_vegan BOOLEAN); INSERT INTO menu_items (id,name,rating,is_vegan) VALUES (1,'Veggie Burger',5,true),(2,'Chicken Sandwich',4,false),(3,'Tofu Stir Fry',5,true);
SELECT name FROM menu_items WHERE rating = 5 AND is_vegan = true;
What is the standard deviation of transaction amounts for clients living in South America?
CREATE TABLE clients (client_id INT,name TEXT,region TEXT,transaction_amount DECIMAL); INSERT INTO clients (client_id,name,region,transaction_amount) VALUES (1,'John Doe','South America',500.00); INSERT INTO clients (client_id,name,region,transaction_amount) VALUES (2,'Jane Smith','Europe',350.00); INSERT INTO clients (client_id,name,region,transaction_amount) VALUES (3,'Mike Johnson','South America',400.00); INSERT INTO clients (client_id,name,region,transaction_amount) VALUES (4,'Sara Doe','South America',600.00);
SELECT STDDEV(transaction_amount) FROM clients WHERE region = 'South America';
What is the average program impact score for each program category?
CREATE TABLE Programs (ProgramID int,ProgramName varchar(50),ProgramCategory varchar(50),ProgramImpactScore numeric(3,1)); INSERT INTO Programs (ProgramID,ProgramName,ProgramCategory,ProgramImpactScore) VALUES (1,'Education','Children',8.5),(2,'Healthcare','Children',7.8),(3,'Nutrition','Elderly',9.2);
SELECT ProgramCategory, AVG(ProgramImpactScore) as AverageScore FROM Programs GROUP BY ProgramCategory;
What is the average CO2 emission per garment by material type in 2021?
CREATE TABLE co2_emissions (date DATE,garment_id INT,material VARCHAR(50),co2_emissions DECIMAL(10,2));
SELECT AVG(co2_emissions) AS avg_co2_emission, material FROM co2_emissions WHERE date >= '2021-01-01' AND date < '2022-01-01' GROUP BY material;
What is the percentage of customers using 4G and 5G networks in each customer region?
CREATE TABLE customer_network_data (customer_region VARCHAR(20),network_type VARCHAR(20),customer_count INT); INSERT INTO customer_network_data (customer_region,network_type,customer_count) VALUES ('Northeast','4G',2500),('Southwest','4G',2000),('Midwest','4G',2200),('Northeast','5G',3000),('Southwest','5G',2500),('Midwest','5G',3300);
SELECT customer_region, ((SUM(CASE WHEN network_type = '5G' THEN customer_count ELSE 0 END) / SUM(customer_count)) * 100) AS pct_5g_customers, ((SUM(CASE WHEN network_type = '4G' THEN customer_count ELSE 0 END) / SUM(customer_count)) * 100) AS pct_4g_customers FROM customer_network_data GROUP BY customer_region;
What is the count of female players from Africa who have adopted VR technology?
CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),Country VARCHAR(50)); INSERT INTO Players (PlayerID,Age,Gender,Country) VALUES (1,25,'Male','South Africa'); INSERT INTO Players (PlayerID,Age,Gender,Country) VALUES (2,30,'Female','Egypt'); CREATE TABLE VRAdoption (PlayerID INT,VRPurchaseDate DATE);
SELECT COUNT(Players.PlayerID) FROM Players INNER JOIN VRAdoption ON Players.PlayerID = VRAdoption.PlayerID WHERE Players.Gender = 'Female' AND Players.Country LIKE 'Africa%';
What is the total transaction amount and average transaction value for each customer in the past month?
CREATE TABLE customers (customer_id INT,name VARCHAR(50),registration_date DATE); INSERT INTO customers VALUES (1,'John Doe','2020-01-01'); INSERT INTO customers VALUES (2,'Jane Smith','2020-02-01'); CREATE TABLE transactions (transaction_id INT,customer_id INT,amount DECIMAL(10,2),transaction_date DATE); INSERT INTO transactions VALUES (1,1,100.00,'2021-03-15'); INSERT INTO transactions VALUES (2,1,200.00,'2021-03-20'); INSERT INTO transactions VALUES (3,2,50.00,'2021-03-18');
SELECT c.customer_id, c.name, SUM(t.amount) AS total_amount, AVG(t.amount) AS avg_amount FROM customers c INNER JOIN transactions t ON c.customer_id = t.customer_ID WHERE t.transaction_date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH) GROUP BY c.customer_id;
What is the total number of court cases in New York City in 2020?
CREATE TABLE court_cases (case_id INT,defendant_id INT,court_date DATE); INSERT INTO court_cases (case_id,defendant_id,court_date) VALUES (1,1001,'2020-02-01'),(2,1002,'2019-03-15');
SELECT COUNT(*) FROM court_cases WHERE YEAR(court_date) = 2020 AND city(court_date) = 'New York';
Which forests have more than one employee and have species data?
CREATE TABLE Forests (id INT,name VARCHAR(50),country VARCHAR(50),hectares INT,year_established INT); CREATE TABLE Species (id INT,name VARCHAR(50),forest_id INT,population INT); CREATE TABLE Employees (id INT,name VARCHAR(50),forest_id INT,role VARCHAR(50),year_hired INT); INSERT INTO Forests (id,name,country,hectares,year_established) VALUES (1,'Bialowieza','Poland',141000,1921),(2,'Amazon','Brazil',340000,1968),(3,'Daintree','Australia',12000,1770); INSERT INTO Species (id,name,forest_id,population) VALUES (1,'Bison',1,500),(2,'Jaguar',2,150),(3,'Cassowary',3,1000); INSERT INTO Employees (id,name,forest_id,role,year_hired) VALUES (1,'John',1,'Forester',2015),(2,'Aisha',2,'Forester',2000),(3,'Pedro',3,'Forester',2010),(4,'Jane',2,'Biologist',2018),(5,'Raul',3,'Forester',2012);
SELECT Forests.name FROM Forests WHERE id IN (SELECT forest_id FROM Employees GROUP BY forest_id HAVING COUNT(DISTINCT Employees.id) > 1) AND id IN (SELECT forest_id FROM Species);
What was the total investment in hydroelectric projects in Southeast Asia in 2019?
CREATE TABLE hydroelectric_projects (id INT,name TEXT,year INT,investment FLOAT); CREATE VIEW southeast_asia AS SELECT * FROM regions WHERE name = 'Southeast Asia';
SELECT SUM(investment) FROM hydroelectric_projects JOIN southeast_asia ON hydroelectric_projects.location = southeast_asia.id WHERE year = 2019;
List the top 3 job categories with the highest number of candidates interviewed in the past month, including their respective locations and the number of candidates interviewed?
CREATE TABLE Interviews (InterviewID int,InterviewDate date,CandidateName varchar(50),CandidateGender varchar(10),JobCategory varchar(50),Location varchar(50)); INSERT INTO Interviews (InterviewID,InterviewDate,CandidateName,CandidateGender,JobCategory,Location) VALUES (1,'2023-02-01','David Kim','Male','Software Engineer','Seattle'),(2,'2023-02-02','Sophia Lee','Female','Data Analyst','San Francisco'),(3,'2023-02-03','Daniel Park','Male','Software Engineer','Los Angeles'),(4,'2023-02-04','Olivia Choi','Female','Data Scientist','New York'),(5,'2023-02-05','William Han','Male','Software Engineer','Chicago'),(6,'2023-02-06','Ava Kim','Female','Data Analyst','Denver'),(7,'2023-02-07','Mohamed Ahmed','Male','Data Scientist','Cairo');
SELECT JobCategory, Location, COUNT(*) AS num_candidates FROM Interviews WHERE InterviewDate >= DATEADD(month, -1, GETDATE()) GROUP BY JobCategory, Location ORDER BY num_candidates DESC, JobCategory DESC, Location DESC LIMIT 3;
Which explainable AI techniques are used in the creative AI application 'Shelley'?
CREATE TABLE if not exists eai_techniques (technique_id INT PRIMARY KEY,name TEXT); INSERT INTO eai_techniques (technique_id,name) VALUES (1,'Feature Attribution'),(2,'Model Simplification'),(3,'Rule Extraction'); CREATE TABLE if not exists ai_applications (app_id INT PRIMARY KEY,name TEXT,technique_id INT); INSERT INTO ai_applications (app_id,name,technique_id) VALUES (1,'DeepArt',1),(2,'DeepDream',NULL),(3,'Shelley',3);
SELECT eai_techniques.name FROM eai_techniques JOIN ai_applications ON eai_techniques.technique_id = ai_applications.technique_id WHERE ai_applications.name = 'Shelley';
List all the unique crop types in 'FieldB' and their total area?
CREATE TABLE FieldB_Info (crop_type VARCHAR(50),area FLOAT); INSERT INTO FieldB_Info (crop_type,area) VALUES ('Corn',500.5),('Soybeans',700.2);
SELECT DISTINCT crop_type, SUM(area) FROM FieldB_Info;
What is the percentage of donations made by each donor compared to the total donations made by all donors?
CREATE TABLE Donations (DonationID INT,DonorID INT,DonationDate DATE,DonationAmount DECIMAL(10,2)); INSERT INTO Donations (DonationID,DonorID,DonationDate,DonationAmount) VALUES (15,1,'2022-06-01',700.00),(16,2,'2022-06-15',800.00),(17,3,'2022-07-01',900.00),(18,4,'2022-07-15',1000.00),(19,5,'2022-07-01',1100.00);
SELECT DonorID, SUM(DonationAmount) OVER (PARTITION BY DonorID ORDER BY DonorID) * 100.0 / SUM(DonationAmount) OVER (ORDER BY DonorID ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS DonationPercentage FROM Donations;
Create a view named 'funding_summary' that displays the total funding for each funding source
CREATE TABLE funding (source VARCHAR(255),amount INT); INSERT INTO funding (source,amount) SELECT * FROM csv_file('funding.csv') AS t(source VARCHAR(255),amount INT);
CREATE VIEW funding_summary AS SELECT source, SUM(amount) AS total_funding FROM funding GROUP BY source;
What is the maximum duration of space missions led by Captain Aliyah Johnson?
CREATE TABLE SpaceMissions (id INT,name VARCHAR(100),leader VARCHAR(100),duration INT); INSERT INTO SpaceMissions (id,name,leader,duration) VALUES (1,'Mission1','Aliyah Johnson',300),(2,'Mission2','Aliyah Johnson',400);
SELECT MAX(duration) FROM SpaceMissions WHERE leader = 'Aliyah Johnson';
Get the total sales for each product category for the month of February 2022?
CREATE TABLE sales_by_category (product_category VARCHAR(255),revenue FLOAT); INSERT INTO sales_by_category (product_category,revenue) VALUES ('Tops',8000),('Bottoms',9000),('Dresses',10000),('Shoes',7000);
SELECT product_category, SUM(revenue) FROM sales_by_category WHERE revenue IS NOT NULL AND product_category IS NOT NULL AND STR_TO_DATE(CONCAT('02-', MONTH(NOW())), '%d-%m-%Y') = STR_TO_DATE('02-2022', '%d-%m-%Y') GROUP BY product_category;
List all projects and their completion dates from organizations located in 'TX'?
CREATE TABLE Organizations (OrgID INT,OrgName TEXT,OrgState TEXT,ProjectID INT,ProjectCompletionDate DATE);
SELECT p.ProjectID, p.ProjectCompletionDate FROM Projects p INNER JOIN Organizations o ON p.OrgID = o.OrgID WHERE o.OrgState = 'TX';
Calculate the percentage of Shariah-compliant loans issued by each bank out of the total loans issued?
CREATE TABLE bank (id INT,name VARCHAR(50),type VARCHAR(50)); INSERT INTO bank (id,name,type) VALUES (1,'Green Bank','Shariah-compliant'),(2,'Fair Lending Bank','Socially Responsible'); CREATE TABLE loans (bank_id INT,amount DECIMAL(10,2),type VARCHAR(50)); INSERT INTO loans (bank_id,amount,type) VALUES (1,5000.00,'Shariah-compliant'),(1,6000.00,'Shariah-compliant'),(2,8000.00,'Socially Responsible'),(2,9000.00,'Socially Responsible');
SELECT bank_id, 100.0 * SUM(CASE WHEN type = 'Shariah-compliant' THEN amount ELSE 0 END) / SUM(amount) as shariah_loan_percentage FROM loans GROUP BY bank_id;
What is the average production cost of cotton t-shirts in Bangladesh?
CREATE TABLE production_costs (country VARCHAR(255),material VARCHAR(255),product VARCHAR(255),cost DECIMAL(10,2)); INSERT INTO production_costs (country,material,product,cost) VALUES ('Bangladesh','cotton','t-shirt',5.50);
SELECT AVG(cost) FROM production_costs WHERE country = 'Bangladesh' AND material = 'cotton' AND product = 't-shirt';
What is the total area of organic farms in the 'organic_farms' table?
CREATE TABLE organic_farms (id INT,name VARCHAR(30),location VARCHAR(30),area DECIMAL(5,2),is_organic BOOLEAN);
SELECT SUM(area) FROM organic_farms WHERE is_organic = TRUE;
What is the minimum size of marine protected areas in the Atlantic Ocean?
CREATE TABLE marine_protected_areas (name VARCHAR(255),area_id INT,depth FLOAT,size INT,country VARCHAR(255)); INSERT INTO marine_protected_areas (name,area_id,depth,size,country) VALUES ('Bermuda Park',21,50,24000,'Bermuda'),('Saba Bank National Park',22,20,270000,'Netherlands');
SELECT MIN(size) FROM marine_protected_areas WHERE country = 'Atlantic Ocean';
Insert a new record for a worker with ID 6 in the 'electronics' department at factory 3 with a salary of 60000.
CREATE TABLE factories (factory_id INT,department VARCHAR(20));CREATE TABLE workers (worker_id INT,factory_id INT,salary DECIMAL(5,2),department VARCHAR(20)); INSERT INTO factories (factory_id,department) VALUES (1,'textile'),(2,'metal'),(3,'electronics'); INSERT INTO workers (worker_id,factory_id,salary,department) VALUES (1,1,35000,'textile'),(2,1,36000,'textile'),(3,2,45000,'metal'),(4,2,46000,'metal'),(5,3,55000,'electronics');
INSERT INTO workers (worker_id, factory_id, salary, department) VALUES (6, 3, 60000, 'electronics');
What is the most visited museum in each city?
CREATE TABLE museum_operations (id INT,museum_name VARCHAR(50),location VARCHAR(50),annual_visitors INT); INSERT INTO museum_operations (id,museum_name,location,annual_visitors) VALUES (1,'Metropolitan Museum of Art','New York',7000000); INSERT INTO museum_operations (id,museum_name,location,annual_visitors) VALUES (2,'British Museum','London',6200000); INSERT INTO museum_operations (id,museum_name,location,annual_visitors) VALUES (3,'Louvre Museum','Paris',9000000);
SELECT museum_name, location, annual_visitors, ROW_NUMBER() OVER(PARTITION BY location ORDER BY annual_visitors DESC) as ranking FROM museum_operations;
What is the average age of readers who prefer sports news in the city of Los Angeles?
CREATE TABLE readers (id INT,name TEXT,age INT,city TEXT,interest TEXT); INSERT INTO readers (id,name,age,city,interest) VALUES (1,'John Doe',35,'Los Angeles','sports');
SELECT AVG(age) FROM readers WHERE city = 'Los Angeles' AND interest = 'sports';
What is the average water usage per household in Canada for the year 2018?
CREATE TABLE water_usage (id INT,country VARCHAR(50),year INT,usage FLOAT); INSERT INTO water_usage (id,country,year,usage) VALUES (1,'Canada',2018,150.3),(2,'Canada',2019,155.1),(3,'Mexico',2018,200.5),(4,'Mexico',2019,210.0);
SELECT AVG(usage) FROM water_usage WHERE country = 'Canada' AND year = 2018;
How many labor hours were spent on non-sustainable building practices in the city of Los Angeles in 2022?
CREATE TABLE labor_hours (labor_id INT,hours FLOAT,city VARCHAR(50),year INT,sustainable BOOLEAN); INSERT INTO labor_hours (labor_id,hours,city,year,sustainable) VALUES (7,150,'Los Angeles',2022,FALSE); INSERT INTO labor_hours (labor_id,hours,city,year,sustainable) VALUES (8,180,'Los Angeles',2022,FALSE);
SELECT SUM(hours) FROM labor_hours WHERE city = 'Los Angeles' AND year = 2022 AND sustainable = FALSE;
What is the total number of volunteers for each program in the year 2020?
CREATE TABLE programs (id INT,name VARCHAR(255)); INSERT INTO programs (id,name) VALUES (1,'Education'),(2,'Health'),(3,'Environment'); CREATE TABLE volunteers (id INT,program_id INT,volunteer_date DATE); INSERT INTO volunteers (id,program_id,volunteer_date) VALUES (1,1,'2020-01-01'),(2,1,'2020-02-01'),(3,2,'2020-03-01');
SELECT v.program_id, COUNT(*) as total_volunteers FROM volunteers v WHERE YEAR(v.volunteer_date) = 2020 GROUP BY v.program_id;
Update the financial wellbeing score of clients in the Philippines to 1 point higher than their current score, if their score is currently above 6.
CREATE TABLE financial_wellbeing_ph (client_id INT,financial_wellbeing_score INT,country VARCHAR(50)); INSERT INTO financial_wellbeing_ph (client_id,financial_wellbeing_score,country) VALUES (1,7,'Philippines'),(2,3,'Philippines'),(3,6,'Philippines');
WITH updated_scores AS (UPDATE financial_wellbeing_ph SET financial_wellbeing_score = financial_wellbeing_score + 1 WHERE country = 'Philippines' AND financial_wellbeing_score > 6) SELECT * FROM updated_scores;
How many international tourists visited Japan in 2020 and spent more than $1000 per day on average?
CREATE TABLE IF NOT EXISTS tourists (id INT PRIMARY KEY,name TEXT,country TEXT,daily_spending FLOAT,visit_date DATE); INSERT INTO tourists (id,name,country,daily_spending,visit_date) VALUES (1,'John Doe','USA',1200,'2020-07-01'),(2,'Jane Smith','Canada',800,'2020-10-15'),(3,'Mike Johnson','Japan',2000,'2020-02-20');
SELECT COUNT(*) FROM tourists WHERE country = 'Japan' AND EXTRACT(YEAR FROM visit_date) = 2020 AND daily_spending > 1000;
Calculate the inventory turnover for a specific item
CREATE TABLE inventory (item_id INT,inventory_amount INT); INSERT INTO inventory VALUES (1,500),(2,300),(3,700);
SELECT inventory.item_id, sales.sales_amount / inventory.inventory_amount AS inventory_turnover FROM inventory JOIN sales ON inventory.item_id = sales.item_id WHERE inventory.item_id = 1;
Update an employee's department in the 'employees' table
CREATE TABLE employees (id INT PRIMARY KEY,first_name VARCHAR(50),last_name VARCHAR(50),department VARCHAR(50),hire_date DATE);
UPDATE employees SET department = 'Human Resources' WHERE id = 101;
What is the total unloaded cargo weight in the port of Hong Kong for each flag?
CREATE TABLE ports (port_id INT,port_name TEXT,country TEXT,unloaded_weight FLOAT,vessel_flag TEXT); INSERT INTO ports (port_id,port_name,country,unloaded_weight,vessel_flag) VALUES (1,'Hong Kong','China',123456.78,'Panama'),(2,'Hong Kong','China',987654.32,'Liberia'),(3,'Hong Kong','China',321897.54,'Marshall Islands');
SELECT vessel_flag, SUM(unloaded_weight) AS total_weight FROM ports WHERE port_name = 'Hong Kong' GROUP BY vessel_flag;
What is the total capacity of each landfill in 2020?
CREATE TABLE landfill_capacity(year INT,landfill VARCHAR(255),capacity INT); INSERT INTO landfill_capacity VALUES (2018,'Landfill A',100000),(2018,'Landfill B',150000),(2018,'Landfill C',200000),(2019,'Landfill A',110000),(2019,'Landfill B',155000),(2019,'Landfill C',210000),(2020,'Landfill A',120000),(2020,'Landfill B',160000),(2020,'Landfill C',220000);
SELECT landfill, SUM(capacity) FROM landfill_capacity WHERE year = 2020 GROUP BY landfill;
Which excavation sites have at least 3 instances of artifacts from the pre-Columbian era?
CREATE TABLE Sites (SiteID INT,SiteName TEXT); INSERT INTO Sites (SiteID,SiteName) VALUES (1,'Site-A'),(2,'Site-B'),(3,'Site-C'); CREATE TABLE Artifacts (ArtifactID INT,ArtifactName TEXT,SiteID INT,Age INT,Era TEXT); INSERT INTO Artifacts (ArtifactID,ArtifactName,SiteID,Age,Era) VALUES (1,'Pottery Shard',1,1000,'Post-Columbian'),(2,'Bronze Arrowhead',2,800,'Iron Age'),(3,'Flint Tool',3,2000,'Stone Age'),(4,'Ancient Coin',1,1500,'Pre-Columbian'),(5,'Stone Hammer',2,3000,'Pre-Columbian');
SELECT Sites.SiteName, COUNT(Artifacts.ArtifactID) AS Quantity FROM Artifacts INNER JOIN Sites ON Artifacts.SiteID = Sites.SiteID WHERE Artifacts.Era = 'Pre-Columbian' GROUP BY Sites.SiteName HAVING Quantity >= 3;
List all vessels that operate in marine protected areas?
CREATE TABLE vessels (id INT,name TEXT,type TEXT); CREATE TABLE vessel_operations (id INT,vessel_id INT,protected_area_id INT); CREATE TABLE marine_protected_areas (id INT,name TEXT); INSERT INTO vessels (id,name,type) VALUES (1,'Fishing Vessel 1','Fishing'),(2,'Research Vessel 1','Research'),(3,'Tourist Vessel 1','Tourism'); INSERT INTO vessel_operations (id,vessel_id,protected_area_id) VALUES (1,1,1),(2,2,2),(3,3,1); INSERT INTO marine_protected_areas (id,name) VALUES (1,'Galapagos Marine Reserve'),(2,'Great Barrier Reef Marine Park');
SELECT vessels.name FROM vessels INNER JOIN vessel_operations ON vessels.id = vessel_operations.vessel_id INNER JOIN marine_protected_areas ON vessel_operations.protected_area_id = marine_protected_areas.id;
What is the average age of attendees who identify as 'Female' and have attended 'Music' programs, and how many unique programs have they attended?
CREATE TABLE Attendees (AttendeeID INT,Age INT,Gender VARCHAR(10));CREATE TABLE Programs (ProgramID INT,ProgramName VARCHAR(20),ProgramCategory VARCHAR(20));CREATE TABLE Attendance (AttendeeID INT,ProgramID INT);
SELECT AVG(A.Age) AS Avg_Age, COUNT(DISTINCT A.ProgramID) AS Num_Unique_Programs FROM Attendees A INNER JOIN Attendance AT ON A.AttendeeID = AT.AttendeeID INNER JOIN Programs P ON AT.ProgramID = P.ProgramID WHERE A.Gender = 'Female' AND P.ProgramCategory = 'Music';
Display the average number of hours billed for cases with outcome 'Won'
CREATE TABLE case_outcomes (case_id INT,outcome TEXT,precedent TEXT); CREATE TABLE case_assignments (case_id INT,attorney_id INT,PRIMARY KEY (case_id,attorney_id)); CREATE TABLE attorney_billing (attorney_id INT,hours_billed INT,PRIMARY KEY (attorney_id));
SELECT AVG(hours_billed) as avg_hours_billed FROM attorney_billing JOIN case_assignments ON attorney_billing.attorney_id = case_assignments.attorney_id JOIN case_outcomes ON case_assignments.case_id = case_outcomes.case_id WHERE outcome = 'Won';
What is the average production budget for action movies released between 2000 and 2010?
CREATE TABLE movies (id INT,title VARCHAR(100),genre VARCHAR(50),release_year INT,production_budget INT); INSERT INTO movies (id,title,genre,release_year,production_budget) VALUES (1,'MovieA','Action',2005,15000000); INSERT INTO movies (id,title,genre,release_year,production_budget) VALUES (2,'MovieB','Action',2002,20000000);
SELECT AVG(production_budget) FROM movies WHERE genre = 'Action' AND release_year BETWEEN 2000 AND 2010;
What was the maximum delivery frequency of a sustainable supplier?
CREATE TABLE supplier_deliveries (supplier VARCHAR(50),deliveries INT,is_sustainable BOOLEAN); INSERT INTO supplier_deliveries (supplier,deliveries,is_sustainable) VALUES ('GreenGrowers',15,true),('OrganicOrigins',20,true); CREATE VIEW sustainable_supplier_deliveries AS SELECT supplier,deliveries FROM supplier_deliveries WHERE is_sustainable = true;
SELECT MAX(deliveries) FROM sustainable_supplier_deliveries;
What is the total number of articles published in "The Hindu" in the "Politics" news category in 2021?
CREATE TABLE articles (id INT,title TEXT,content TEXT,publication_date DATE,newspaper TEXT,category TEXT);
SELECT COUNT(*) FROM articles WHERE newspaper = 'The Hindu' AND category = 'Politics' AND YEAR(publication_date) = 2021;
Add a new player 'Mateo' from 'Argentina' with level 15 to the 'players' table
CREATE TABLE players (id INT,name VARCHAR(50),country VARCHAR(50),level INT);
INSERT INTO players (name, country, level) VALUES ('Mateo', 'Argentina', 15);
List the number of hospitals in each state that have less than 100 beds.
CREATE TABLE Hospitals (HospitalID INT,HospitalName VARCHAR(50),State VARCHAR(20),NumberOfBeds INT); INSERT INTO Hospitals (HospitalID,HospitalName,State,NumberOfBeds) VALUES (1,'Rural General Hospital','California',75); INSERT INTO Hospitals (HospitalID,HospitalName,State,NumberOfBeds) VALUES (2,'Mountain View Medical Center','Colorado',95);
SELECT State, COUNT(*) FROM Hospitals WHERE NumberOfBeds < 100 GROUP BY State;
What is the total revenue generated from members in the age range of 25-34 for the year 2021?
CREATE TABLE Members (MemberID INT,Age INT,JoinDate DATE,MembershipType VARCHAR(20),PaymentAmount DECIMAL(5,2)); INSERT INTO Members (MemberID,Age,JoinDate,MembershipType,PaymentAmount) VALUES (1,27,'2021-01-05','Premium',59.99),(2,31,'2021-03-18','Basic',29.99),(3,26,'2021-08-14','Premium',59.99);
SELECT SUM(PaymentAmount) FROM Members WHERE YEAR(JoinDate) = 2021 AND Age BETWEEN 25 AND 34;
What are the total CO2 emissions for garment production in each region?
CREATE TABLE sustainability_metrics (id INT,region VARCHAR(255),co2_emissions INT); INSERT INTO sustainability_metrics (id,region,co2_emissions) VALUES (1,'South America',130),(2,'Europe',100),(3,'Asia',150);
SELECT region, SUM(co2_emissions) as total_co2_emissions FROM sustainability_metrics GROUP BY region;
Find the average annual rainfall for 'indigenous food systems' in 'South America'.
CREATE TABLE regions (id INT,name TEXT,climate TEXT); INSERT INTO regions (id,name,climate) VALUES (1,'Amazon','Tropical rainforest'),(2,'Andes','Alpine tundra'),(3,'Pampas','Humid subtropical'); CREATE TABLE climate_data (id INT,region_id INT,rainfall INT,year INT); INSERT INTO climate_data (id,region_id,rainfall,year) VALUES (1,1,1500,2010),(2,1,1600,2011),(3,2,300,2010),(4,2,350,2011),(5,3,800,2010),(6,3,900,2011);
SELECT AVG(rainfall) FROM climate_data JOIN regions ON climate_data.region_id = regions.id WHERE regions.name = 'indigenous food systems' AND climate_data.year BETWEEN 2010 AND 2011;
Show the number of cases that were dismissed due to lack of evidence in each court location, for the past year.
CREATE TABLE CourtCases (Id INT,CourtLocation VARCHAR(50),CaseNumber INT,Disposition VARCHAR(50),DismissalDate DATE); INSERT INTO CourtCases (Id,CourtLocation,CaseNumber,Disposition,DismissalDate) VALUES (1,'NY Supreme Court',12345,'Dismissed','2021-02-15'),(2,'TX District Court',67890,'Proceeding','2020-12-21'),(3,'CA Superior Court',23456,'Dismissed','2021-08-01');
SELECT CourtLocation, COUNT(*) as NumCases FROM CourtCases WHERE Disposition = 'Dismissed' AND DismissalDate >= DATEADD(year, -1, GETDATE()) AND Disposition = 'Dismissed' GROUP BY CourtLocation;
What is the minimum cargo handling time for 'Port of New York'?
CREATE TABLE ports (id INT,name TEXT,handling_time INT); INSERT INTO ports (id,name,handling_time) VALUES (5,'Port of New York',120),(6,'Port of Los Angeles',180),(7,'Port of Hong Kong',130);
SELECT MIN(handling_time) FROM ports WHERE name = 'Port of New York';
How many disaster response teams are there in Asia?
CREATE TABLE disaster_response_teams (id INT,name VARCHAR(100),region VARCHAR(50)); INSERT INTO disaster_response_teams (id,name,region) VALUES (1,'Team A','Asia'),(2,'Team B','Africa'),(3,'Team C','Asia');
SELECT COUNT(*) FROM disaster_response_teams WHERE region = 'Asia';
List all policies with a coverage type of 'Basic' and their corresponding policyholders' ages.
CREATE TABLE Policyholders (PolicyholderID INT,Age INT,Region VARCHAR(10)); CREATE TABLE Policies (PolicyID INT,PolicyholderID INT,Coverage VARCHAR(20),Region VARCHAR(10)); INSERT INTO Policyholders (PolicyholderID,Age,Region) VALUES (1,35,'West'); INSERT INTO Policyholders (PolicyholderID,Age,Region) VALUES (2,45,'East'); INSERT INTO Policies (PolicyID,PolicyholderID,Coverage,Region) VALUES (101,1,'Basic','North'); INSERT INTO Policies (PolicyID,PolicyholderID,Coverage,Region) VALUES (102,2,'Premium','South');
SELECT Policies.Coverage, Policyholders.Age FROM Policies INNER JOIN Policyholders ON Policies.PolicyholderID = Policyholders.PolicyholderID WHERE Policies.Coverage = 'Basic';
How many artists in the database are from Africa or South America?
CREATE TABLE ArtistData (id INT,artist_name VARCHAR(50),country VARCHAR(50)); INSERT INTO ArtistData (id,artist_name,country) VALUES (1,'Adele','England'),(2,'Santana','Mexico'),(3,'Hendrix','USA'),(4,'Fela','Nigeria'),(5,'Gilberto','Brazil');
SELECT COUNT(*) FROM ArtistData WHERE country IN ('Africa', 'South America');
What are the top 5 threat actor categories with the most incidents in the last 6 months?
CREATE TABLE threat_actors (id INT,category VARCHAR(50),incident_date DATE); INSERT INTO threat_actors (id,category,incident_date) VALUES (1,'Nation State','2022-01-01'),(2,'Cyber Crime','2022-02-05'),(3,'Hacktivist','2022-03-10');
SELECT category, COUNT(*) as incident_count FROM threat_actors WHERE incident_date >= DATEADD(month, -6, GETDATE()) GROUP BY category ORDER BY incident_count DESC LIMIT 5;
List all garments in the 'Tops' category with a price greater than 25.00 from the garments table
CREATE TABLE garments (id INT,name VARCHAR(100),price DECIMAL(5,2),category VARCHAR(50));
SELECT * FROM garments WHERE category = 'Tops' AND price > 25.00;
What is the total number of volunteer hours contributed by volunteers from Nigeria?
CREATE TABLE Volunteers (VolunteerID INT,VolunteerName TEXT,Hours INT,Country TEXT); INSERT INTO Volunteers (VolunteerID,VolunteerName,Hours,Country) VALUES (3,'Adebayo Adewale',60,'Nigeria'),(4,'Bukola Adewale',90,'Nigeria');
SELECT Country, SUM(Hours) FROM Volunteers WHERE Country = 'Nigeria' GROUP BY Country;
Who are the top 3 donors supporting education projects in Jordan and Lebanon?
CREATE TABLE jordan_donors (donor_id INT,donor_name VARCHAR(50),donation_amount INT,project_type VARCHAR(30)); INSERT INTO jordan_donors (donor_id,donor_name,donation_amount,project_type) VALUES (1,'USAID',100000,'education'),(2,'EU',120000,'health'),(3,'UNESCO',80000,'education'); CREATE TABLE lebanon_donors (donor_id INT,donor_name VARCHAR(50),donation_amount INT,project_type VARCHAR(30)); INSERT INTO lebanon_donors (donor_id,donor_name,donation_amount,project_type) VALUES (1,'USAID',150000,'education'),(2,'EU',180000,'infrastructure'),(3,'UNICEF',90000,'education');
SELECT d1.donor_name, SUM(d1.donation_amount) AS total_donation FROM jordan_donors d1 INNER JOIN lebanon_donors d2 ON d1.donor_name = d2.donor_name WHERE d1.project_type = 'education' GROUP BY d1.donor_name ORDER BY total_donation DESC LIMIT 3;
What is the total revenue generated from broadband subscribers in the city of Chicago?
CREATE TABLE broadband_subscribers (subscriber_id INT,monthly_bill FLOAT,city VARCHAR(20)); INSERT INTO broadband_subscribers (subscriber_id,monthly_bill,city) VALUES (1,60.5,'Chicago'),(2,70.3,'Houston'),(3,55.7,'Chicago');
SELECT SUM(monthly_bill) FROM broadband_subscribers WHERE city = 'Chicago';
List the names and countries of all female news reporters who are over the age of 40.
CREATE TABLE reporters (id INT,name VARCHAR(50),gender VARCHAR(10),age INT,country VARCHAR(50));
SELECT name, country FROM reporters WHERE gender = 'female' AND age > 40;
What is the average number of accommodations per month for students with mobility impairments?
CREATE TABLE accommodation (student_id INT,accommodation_type TEXT,accommodation_date DATE); INSERT INTO accommodation (student_id,accommodation_type,accommodation_date) VALUES (1,'Wheelchair Access','2022-01-05'),(2,'Assistive Technology','2022-02-10'),(3,'Note Taker','2022-03-15'),(4,'Wheelchair Access','2022-04-20'); CREATE TABLE student (student_id INT,disability TEXT); INSERT INTO student (student_id,disability) VALUES (1,'Mobility Impairment'),(2,'Learning Disability'),(3,'Mobility Impairment'),(4,'Mobility Impairment');
SELECT AVG(COUNT(*)) as avg_accommodations FROM accommodation WHERE student_id IN (SELECT student_id FROM student WHERE disability = 'Mobility Impairment') GROUP BY DATE_TRUNC('month', accommodation_date);
What is the total duration of space missions led by female astronauts?
CREATE TABLE space_missions (id INT,mission_name VARCHAR(255),astronaut_name VARCHAR(255),duration INT); INSERT INTO space_missions (id,mission_name,astronaut_name,duration) VALUES (1,'Apollo 11','Neil Armstrong',195),(2,'Apollo 12','Jane Foster',244),(3,'Ares 3','Mark Watney',568),(4,'Apollo 18','Anna Mitchell',205);
SELECT SUM(duration) FROM space_missions WHERE astronaut_name IN ('Jane Foster', 'Anna Mitchell');
Calculate the total number of community education programs in each region
CREATE TABLE community_education (id INT PRIMARY KEY,program_name VARCHAR(255),location VARCHAR(255),region VARCHAR(255));
SELECT location as region, COUNT(*) as total_programs FROM community_education GROUP BY region;
Which drug was approved by the FDA in 2019 with the highest sales?
CREATE TABLE Drug_Approvals(drug VARCHAR(20),approval_year INT,company VARCHAR(20));CREATE TABLE Drug_Sales(drug VARCHAR(20),year INT,sales DECIMAL(10,2));INSERT INTO Drug_Approvals VALUES('DrugA',2019,'PharmaCorp');INSERT INTO Drug_Sales VALUES('DrugA',2019,2000000.00);
SELECT a.drug, MAX(s.sales) FROM Drug_Approvals a INNER JOIN Drug_Sales s ON a.drug = s.drug WHERE a.approval_year = 2019 GROUP BY a.drug;
What is the total revenue for each entree in the current month?
CREATE TABLE entree_orders (order_id INT,entree VARCHAR(255),entree_quantity INT,entree_price DECIMAL(10,2),order_date DATE); INSERT INTO entree_orders VALUES (1,'Spaghetti',2,20.00,'2022-01-01'),(2,'Pizza',1,15.00,'2022-01-03'),(3,'Pizza',2,15.00,'2022-01-02');
SELECT entree, SUM(entree_quantity * entree_price) FROM entree_orders WHERE order_date >= DATEADD(month, 0, GETDATE()) GROUP BY entree;
Show the environmental impact of 'Ethyl Acetate' and 'Methyl Ethyl Ketone' in the environmental_impact_table
CREATE TABLE environmental_impact_table (record_id INT,chemical_id INT,environmental_impact_float);
SELECT chemical_id, environmental_impact_float FROM environmental_impact_table WHERE chemical_id IN (1, 2);
What is the average duration of space missions led by astronauts from the USA?
CREATE TABLE space_missions(id INT,mission_name VARCHAR(50),leader_name VARCHAR(50),leader_country VARCHAR(50),duration INT); INSERT INTO space_missions VALUES(1,'Apollo 11','Neil Armstrong','USA',195.),(2,'Gemini 12','James Lovell','USA',94.);
SELECT AVG(duration) FROM space_missions WHERE leader_country = 'USA';
Which students have not submitted any assignments in any course?
CREATE TABLE students (id INT,name VARCHAR(255)); CREATE TABLE assignments (id INT,student_id INT,course_id INT,submitted_date DATE); INSERT INTO students (id,name) VALUES (1,'Student A'),(2,'Student B'),(3,'Student C'); INSERT INTO assignments (id,student_id,course_id,submitted_date) VALUES (1,1,1,'2021-09-01'),(2,2,1,NULL);
SELECT s.name FROM students s LEFT JOIN assignments a ON s.id = a.student_id WHERE a.submitted_date IS NULL;
How many vessels are there in total?
CREATE TABLE Vessels (ID VARCHAR(20),Name VARCHAR(20),Type VARCHAR(20),MaxSpeed FLOAT); INSERT INTO Vessels VALUES ('V006','Vessel F','Cargo',18.2),('V007','Vessel G','Cargo',16.3),('V008','Vessel H','Passenger',28.0);
SELECT COUNT(*) FROM Vessels;
What is the minimum capacity of hospitals in the 'global_health' schema?
CREATE SCHEMA global_health; CREATE TABLE hospitals (id INT,name TEXT,location TEXT,capacity INT); INSERT INTO global_health.hospitals (id,name,location,capacity) VALUES (1,'Hospital A','City A',200),(2,'Hospital B','City B',300),(3,'Hospital C','City C',150),(4,'Hospital D','City D',250),(5,'Hospital E','City E',400);
SELECT MIN(capacity) FROM global_health.hospitals;
How many job applications were received from underrepresented candidates in the past year?
CREATE TABLE job_applications (id INT,applicant_name VARCHAR(50),date_applied DATE,underrepresented BOOLEAN);
SELECT COUNT(*) FROM job_applications WHERE underrepresented = TRUE AND date_applied >= DATEADD(year, -1, GETDATE());
What is the average size of fish farms in 'canals' schema located in 'europe'?
CREATE SCHEMA canals; CREATE TABLE fish_farms (id INT,size FLOAT,location VARCHAR(25)); INSERT INTO fish_farms (id,size,location) VALUES (1,15.2,'europe'),(2,28.5,'europe'),(3,42.3,'europe');
SELECT AVG(size) FROM canals.fish_farms WHERE location = 'europe';
Update the threat level for all cybersecurity incidents related to a specific type of malware.
CREATE TABLE IncidentThreatLevel (IncidentID INT,IncidentType VARCHAR(50),ThreatLevel INT); INSERT INTO IncidentThreatLevel (IncidentID,IncidentType,ThreatLevel) VALUES (1,'Phishing',3),(2,'Malware',5),(3,'Ransomware',4),(4,'SQL Injection',2),(5,'Insider Threat',3),(6,'Advanced Persistent Threat',5),(7,'Zero Day Exploit',5),(8,'Denial of Service',4);
UPDATE IncidentThreatLevel SET ThreatLevel = 6 WHERE IncidentType = 'Malware';
List the total premiums and number of policies for each policy type, along with the percentage of total premiums for each policy type.
CREATE TABLE Policy (PolicyId INT,PolicyType VARCHAR(50),Premium DECIMAL(10,2),Region VARCHAR(50));
SELECT PolicyType, COUNT(PolicyId) as PolicyCount, SUM(Premium) as TotalPremiums, (SUM(Premium) / (SELECT SUM(Premium) FROM Policy)) * 100 as PercentageOfTotalPremiums FROM Policy GROUP BY PolicyType;
What is the average income for microfinance clients in India by city?
CREATE TABLE microfinance_clients (id INT,name VARCHAR(50),income FLOAT,city VARCHAR(50),country VARCHAR(50)); INSERT INTO microfinance_clients (id,name,income,city,country) VALUES (1,'Ravi Kumar',7000.00,'Mumbai','India'),(2,'Swati Singh',8000.00,'Delhi','India');
SELECT city, AVG(income) as avg_income FROM microfinance_clients WHERE country = 'India' GROUP BY city;
What is the percentage of Holmium production that comes from 'Asia' in 2020?
CREATE TABLE production(year INT,region VARCHAR(20),element VARCHAR(10),quantity INT); INSERT INTO production VALUES(2020,'Asia','Holmium',1200),(2020,'Europe','Holmium',800),(2020,'Africa','Holmium',400);
SELECT (SUM(CASE WHEN region = 'Asia' THEN quantity ELSE 0 END) / SUM(quantity)) * 100.0 FROM production WHERE element = 'Holmium' AND year = 2020
Drop the 'machines' table
CREATE TABLE machines (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255),status VARCHAR(255));
DROP TABLE machines;
List all products and their suppliers
CREATE TABLE products (product_id INT,product_name VARCHAR(50));CREATE TABLE supplier_products (supplier_id INT,product_id INT);CREATE TABLE suppliers (supplier_id INT,supplier_name VARCHAR(50));
SELECT products.product_name, suppliers.supplier_name FROM products JOIN supplier_products ON products.product_id = supplier_products.product_id JOIN suppliers ON supplier_products.supplier_id = suppliers.supplier_id;
Show the names and ages of patients who have been diagnosed with hypertension and are over 50 in rural Arizona.
CREATE TABLE patients (patient_id INT,patient_name TEXT,age INT,diagnosis TEXT,state TEXT); INSERT INTO patients (patient_id,patient_name,age,diagnosis,state) VALUES (2,'Jane Doe',55,'Hypertension','Arizona');
SELECT patient_name, age FROM patients WHERE diagnosis = 'Hypertension' AND age > 50 AND state = 'Arizona';
What is the PH level for fish species in the Indian ocean?
CREATE TABLE indian_ocean_fish (id INT,name VARCHAR(50),ph_level FLOAT); INSERT INTO indian_ocean_fish (id,name,ph_level) VALUES (1,'Tuna',8.1),(2,'Marlin',7.9),(3,'Swordfish',7.8),(4,'Shark',7.5);
SELECT name, ph_level FROM indian_ocean_fish;
What is the total donation amount made by donors with the first name starting with 'A'?
CREATE TABLE Donations (DonationID INT,DonorFirstName TEXT,DonorLastName TEXT,DonationAmount DECIMAL); INSERT INTO Donations (DonationID,DonorFirstName,DonorLastName,DonationAmount) VALUES (1,'Alex','Johnson',75.00),(2,'Anna','Williams',100.00);
SELECT SUM(DonationAmount) FROM Donations WHERE DonorFirstName LIKE 'A%';
Update the attendance for a specific art exhibition where the exhibition type is modern and the attendee age is 25
CREATE TABLE art_exhibitions (id INT,exhibition_type VARCHAR(20),attendance INT,attendee_age INT);
UPDATE art_exhibitions SET attendance = 550 WHERE exhibition_type = 'modern' AND attendee_age = 25;
What was the maximum value of the agricultural innovation metrics for the last quarter, by metric name?
CREATE TABLE agricultural_innovation_metrics (id INT PRIMARY KEY,metric_name VARCHAR(50),value DECIMAL(10,2),measurement_date DATE);
SELECT metric_name, MAX(value) as max_value FROM agricultural_innovation_metrics WHERE measurement_date >= DATE_SUB(CURDATE(), INTERVAL 3 MONTH) GROUP BY metric_name;
Add a new open pedagogy resource
CREATE TABLE if not exists open_pedagogy_resources (id INT,course_id INT,type VARCHAR(50),link VARCHAR(100)); INSERT INTO open_pedagogy_resources (id,course_id,type,link) VALUES (2,2,'Blog Post','https://opensource.com/education/17/6/open-pedagogy-examples');
INSERT INTO open_pedagogy_resources (id, course_id, type, link) VALUES (3, 3, 'Podcast', 'https://edunova.podbean.com/e/episode-1-open-pedagogy-and-the-future-of-education/');
What is the average incident response time for each type of emergency in San Francisco?
CREATE TABLE EmergencyTypes (Type VARCHAR(255)); INSERT INTO EmergencyTypes (Type) VALUES ('Fire'),('Medical'),('Police'); CREATE TABLE EmergencyResponses (ID INT,Type VARCHAR(255),Time FLOAT,Location VARCHAR(255)); INSERT INTO EmergencyResponses (ID,Type,Time,Location) VALUES (1,'Fire',6.5,'San Francisco'),(2,'Medical',7.2,'San Francisco'),(3,'Police',4.9,'San Francisco');
SELECT E.Type, AVG(E.Time) as AvgResponseTime FROM EmergencyResponses E WHERE E.Location = 'San Francisco' GROUP BY E.Type;
Create a table named 'events' with columns 'name', 'date', and 'attendance'
CREATE TABLE events (name VARCHAR(255),date DATE,attendance INT);
CREATE TABLE events (name VARCHAR(255), date DATE, attendance INT);
Calculate the average 'Revenue' for 'Tops' sold in 'Canada'.
CREATE TABLE avg_revenue(product VARCHAR(20),location VARCHAR(20),revenue INT); INSERT INTO avg_revenue VALUES('Tops','Canada',100);
SELECT AVG(revenue) FROM avg_revenue WHERE product = 'Tops' AND location = 'Canada';
What is the total mass of all satellites in the "satellite_mass" table, grouped by manufacturer?
CREATE TABLE satellite_mass (id INT,satellite_name VARCHAR(50),manufacturer VARCHAR(50),mass FLOAT); INSERT INTO satellite_mass (id,satellite_name,manufacturer,mass) VALUES (1,'Sat1','Manufacturer1',1000); INSERT INTO satellite_mass (id,satellite_name,manufacturer,mass) VALUES (2,'Sat2','Manufacturer2',2000);
SELECT manufacturer, SUM(mass) AS total_mass FROM satellite_mass GROUP BY manufacturer;
What is the total cost of ingredients for each menu item, excluding those from a specific supplier?
CREATE TABLE menu_items (menu_id INT,name VARCHAR(50),total_cost FLOAT); CREATE TABLE recipe (menu_id INT,ingredient_id INT,quantity FLOAT); CREATE TABLE ingredients (ingredient_id INT,name VARCHAR(50),supplier VARCHAR(50),cost FLOAT);
SELECT m.menu_id, m.name, SUM(i.cost * r.quantity) as total_cost FROM menu_items m JOIN recipe r ON m.menu_id = r.menu_id JOIN ingredients i ON r.ingredient_id = i.ingredient_id WHERE i.supplier != 'Excluded Supplier' GROUP BY m.menu_id;
What is the contact information and language preservation status for organizations in Africa?
CREATE TABLE organizations (id INT,name VARCHAR,contact VARCHAR,region VARCHAR); INSERT INTO organizations (id,name,contact,region) VALUES (1,'Organization A','[email protected]','Africa'),(2,'Organization B','[email protected]','Europe'); CREATE TABLE preservation_status (id INT,status VARCHAR); INSERT INTO preservation_status (id,status) VALUES (1,'Active'),(2,'Inactive');
SELECT organizations.name, organizations.contact, preservation_status.status FROM organizations INNER JOIN preservation_status ON organizations.region = preservation_status.status WHERE organizations.region = 'Africa';
What is the total number of eco-friendly accommodations in France and Italy?
CREATE TABLE Accommodations (id INT,country VARCHAR(50),type VARCHAR(50),capacity INT); INSERT INTO Accommodations (id,country,type,capacity) VALUES (1,'France','Eco-Friendly Hotel',100),(2,'France','Eco-Friendly Hostel',50),(3,'Italy','Eco-Friendly Resort',150),(4,'Italy','Eco-Friendly B&B',80);
SELECT SUM(capacity) FROM Accommodations WHERE country IN ('France', 'Italy') AND type LIKE '%Eco-Friendly%';
Count the number of restorative justice programs implemented in Indigenous communities
CREATE TABLE restorative_justice_programs (program_id INT,community_type VARCHAR(255)); INSERT INTO restorative_justice_programs (program_id,community_type) VALUES (1,'Indigenous'),(2,'Urban'),(3,'Rural'),(4,'Suburban'),(5,'Indigenous'),(6,'Urban');
SELECT COUNT(*) FROM restorative_justice_programs WHERE community_type = 'Indigenous';
Rank drugs based on the average number of clinical trials per year.
CREATE TABLE clinical_trials (drug_name TEXT,year INTEGER,trial_count INTEGER);
SELECT drug_name, AVG(trial_count) AS avg_trials, RANK() OVER (ORDER BY AVG(trial_count) DESC) AS rank FROM clinical_trials GROUP BY drug_name ORDER BY rank;