instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Update the salary of all employees in the 'employees' table with the job title 'Engineer' to $83,000.
CREATE TABLE employees (id INT,first_name VARCHAR(50),last_name VARCHAR(50),job_title VARCHAR(50),department VARCHAR(50),age INT,salary DECIMAL(10,2),PRIMARY KEY (id)); INSERT INTO employees (id,first_name,last_name,job_title,department,age,salary) VALUES (1,'John','Doe','Engineer','Mining',35,80000.00),(2,'Jane','Doe','Operator','Mining',28,60000.00),(3,'Mike','Johnson','Manager','Environment',45,90000.00),(4,'Sara','Smith','Technician','Environment',30,75000.00),(5,'David','Williams','Engineer','Mining',40,80000.00);
UPDATE employees SET salary = 83000.00 WHERE job_title = 'Engineer';
Which services in CityA have a frequency greater than 7?
CREATE TABLE City (id INT,name VARCHAR(50),population INT); INSERT INTO City (id,name,population) VALUES (1,'CityA',60000); INSERT INTO City (id,name,population) VALUES (2,'CityB',80000); CREATE TABLE Department (id INT,city_id INT,name VARCHAR(50)); INSERT INTO Department (id,city_id,name) VALUES (1,1,'Department1'); INSERT INTO Department (id,city_id,name) VALUES (2,1,'Department2'); CREATE TABLE Service (id INT,department_id INT,name VARCHAR(50),frequency INT); INSERT INTO Service (id,department_id,name,frequency) VALUES (1,1,'Service1',10); INSERT INTO Service (id,department_id,name,frequency) VALUES (2,1,'Service2',5); INSERT INTO Service (id,department_id,name,frequency) VALUES (3,2,'Service3',8);
SELECT s.name FROM Service s JOIN Department d ON s.department_id = d.id JOIN City c ON d.city_id = c.id WHERE c.name = 'CityA' AND s.frequency > 7;
List the top 5 recipients of donations in H1 2021, along with the total amount donated to each?
CREATE TABLE recipients (recipient_id INT,recipient_name TEXT,donation_amount DECIMAL); INSERT INTO recipients (recipient_id,recipient_name,donation_amount) VALUES (1,'Recipient X',800.00),(2,'Recipient Y',300.00),(3,'Recipient Z',600.00);
SELECT recipient_name, SUM(donation_amount) as total_donation FROM donations WHERE donation_date BETWEEN '2021-01-01' AND '2021-06-30' GROUP BY recipient_name ORDER BY total_donation DESC LIMIT 5;
What is the maximum number of hours spent on training AI models by organizations in the education sector?
CREATE TABLE ai_training_hours (org_id INT,sector VARCHAR(20),hours INT); INSERT INTO ai_training_hours (org_id,sector,hours) VALUES (1,'education',40),(2,'healthcare',35),(3,'education',45);
SELECT MAX(hours) FROM ai_training_hours WHERE sector = 'education';
What is the percentage of community health workers who identify as non-binary, by state?
CREATE TABLE CommunityHealthWorkers (WorkerID INT,Age INT,Gender VARCHAR(10),State VARCHAR(20)); INSERT INTO CommunityHealthWorkers (WorkerID,Age,Gender,State) VALUES (1,34,'Female','California'),(2,42,'Male','Texas'),(3,50,'Female','California'),(4,48,'Non-binary','New York');
SELECT State, 100.0 * COUNT(CASE WHEN Gender = 'Non-binary' THEN 1 END) / COUNT(*) as Percentage FROM CommunityHealthWorkers GROUP BY State;
What is the total number of articles published in "The Washington Post" that mention "climate change" in the title or content?
CREATE TABLE articles (id INT,title TEXT,content TEXT,publication_date DATE,newspaper TEXT);
SELECT COUNT(*) FROM articles WHERE (title LIKE '%climate change%' OR content LIKE '%climate change%') AND newspaper = 'The Washington Post';
Update the profession for farmers with id 1 and 2 in the 'farmers' table
CREATE TABLE farmers (id INT PRIMARY KEY,name VARCHAR(50),age INT,gender VARCHAR(10),location VARCHAR(50),profession VARCHAR(50)); INSERT INTO farmers (id,name,age,gender,location) VALUES (1,'John Doe',35,'Male','USA'),(2,'Jane Smith',40,'Female','Canada');
UPDATE farmers SET profession = 'Farmer' WHERE id IN (1, 2);
What is the average sale price of artworks by African artists?
CREATE TABLE Artists (ArtistID INT PRIMARY KEY,Name VARCHAR(255),Nationality VARCHAR(255)); CREATE TABLE Artworks (ArtworkID INT PRIMARY KEY,Title VARCHAR(255),ArtistID INT,Year INT,SalePrice DECIMAL(10,2)); CREATE TABLE Sales (SaleID INT PRIMARY KEY,SaleDate DATE);
SELECT AVG(Artworks.SalePrice) AS AverageSalePrice FROM Artists INNER JOIN Artworks ON Artists.ArtistID = Artworks.ArtistID INNER JOIN Sales ON Artworks.ArtworkID = Sales.ArtworkID WHERE Artists.Nationality = 'African';
Which countries have the highest number of cross-border transactions in stablecoins?
CREATE TABLE transactions (id INT,country VARCHAR(50),asset_type VARCHAR(50),value DECIMAL(10,2)); INSERT INTO transactions (id,country,asset_type,value) VALUES (1,'USA','Stablecoin',1000),(2,'China','Stablecoin',2000),(3,'India','Crypto',3000);
SELECT country, SUM(value) as total_value FROM transactions WHERE asset_type = 'Stablecoin' GROUP BY country ORDER BY total_value DESC;
What is the total number of community education programs held in each continent in the year 2022?
CREATE TABLE education_programs (id INT,location TEXT,year INT,programs INT);
SELECT location, COUNT(programs) FROM education_programs WHERE year = 2022 GROUP BY location;
What is the average age of female farmers in Kenya who have participated in agricultural innovation programs?
CREATE TABLE farmers(id INT,name TEXT,age INT,gender TEXT,country TEXT); INSERT INTO farmers(id,name,age,gender,country) VALUES (1,'Jane',45,'female','Kenya'); INSERT INTO farmers(id,name,age,gender,country) VALUES (2,'Mary',30,'female','Kenya'); CREATE TABLE programs(id INT,farmer_id INT,program TEXT); INSERT INTO programs(id,farmer_id,program) VALUES (1,1,'Innovative Irrigation'); INSERT INTO programs(id,farmer_id,program) VALUES (2,2,'Modern Farming Techniques');
SELECT AVG(age) FROM farmers f INNER JOIN programs p ON f.id = p.farmer_id WHERE f.gender = 'female' AND f.country = 'Kenya';
Insert a new supplier that is woman-owned from a low-risk country
CREATE TABLE suppliers (supplier_id INT,supplier_name VARCHAR(50),owner_gender VARCHAR(50),country_risk VARCHAR(50));
INSERT INTO suppliers (supplier_id, supplier_name, owner_gender, country_risk) VALUES (105, 'Supplier V', 'Female', 'Low');
What is the recycling rate in percentage for each material type in the year 2020?
CREATE TABLE material_recycling(material_type VARCHAR(255),year INT,recycling_rate FLOAT); INSERT INTO material_recycling(material_type,year,recycling_rate) VALUES('MaterialA',2020,12.3),('MaterialB',2020,45.6);
SELECT material_type, AVG(recycling_rate) FROM material_recycling WHERE year = 2020 GROUP BY material_type;
Update the preservation status of the habitat with id 2 to 'Critical'
CREATE TABLE habitats (id INT PRIMARY KEY,location VARCHAR(50),area FLOAT,preservation_status VARCHAR(50));
UPDATE habitats SET preservation_status = 'Critical' WHERE id = 2;
What is the total amount of aid provided by all organizations in South America in 2019?
CREATE TABLE aid (id INT,organization VARCHAR(255),location VARCHAR(255),amount DECIMAL(10,2),provide_date DATE); INSERT INTO aid (id,organization,location,amount,provide_date) VALUES (1,'World Vision','South America',500.00,'2019-02-12'),(2,'CARE','South America',800.25,'2019-04-01'),(3,'UNHCR','South America',300.00,'2019-05-20');
SELECT SUM(amount) as total_amount FROM aid WHERE location = 'South America' AND YEAR(provide_date) = 2019;
Update the ocean_acidification table to reflect a decrease in acidity by 0.1 units in all records
CREATE TABLE ocean_acidification (location TEXT,acidity FLOAT); INSERT INTO ocean_acidification (location,acidity) VALUES ('Caribbean Sea',8.2),('Pacific Ocean',8.1),('Atlantic Ocean',8.0);
UPDATE ocean_acidification SET acidity = acidity - 0.1;
What is the total number of restorative justice programs by location, and the number of programs facilitated by 'Sarah Lee'?
CREATE TABLE restorative_justice_programs (id INT,program_name TEXT,location TEXT,facilitator TEXT,participants INT); INSERT INTO restorative_justice_programs (id,program_name,location,facilitator,participants) VALUES (1,'Victim Offender Mediation','Chicago','John Smith',15),(2,'Restorative Circles','Los Angeles','Ahmed Rami',20),(3,'Victim Empathy Workshop','Chicago','Sarah Lee',12);
SELECT location, COUNT(*) AS total_programs, SUM(CASE WHEN facilitator = 'Sarah Lee' THEN 1 ELSE 0 END) AS sarah_lee_programs FROM restorative_justice_programs GROUP BY location;
What is the total property value in co-owned properties in Sydney?
CREATE TABLE Sydney_Neighborhoods (Neighborhood_Name TEXT,Co_Ownership BOOLEAN); INSERT INTO Sydney_Neighborhoods (Neighborhood_Name,Co_Ownership) VALUES ('Sydney CBD',true),('Surry Hills',false),('Darlinghurst',true),('Potts Point',false); CREATE TABLE Sydney_Properties (Neighborhood_Name TEXT,Property_Price INTEGER); INSERT INTO Sydney_Properties (Neighborhood_Name,Property_Price) VALUES ('Sydney CBD',1000000),('Surry Hills',800000),('Darlinghurst',900000),('Potts Point',700000);
SELECT SUM(Sydney_Properties.Property_Price) FROM Sydney_Properties INNER JOIN Sydney_Neighborhoods ON Sydney_Properties.Neighborhood_Name = Sydney_Neighborhoods.Neighborhood_Name WHERE Sydney_Neighborhoods.Co_Ownership = true;
What is the total waste generation by material type in 2022 for New York?
CREATE TABLE waste_generation (year INT,location VARCHAR(255),material VARCHAR(255),weight_tons INT); INSERT INTO waste_generation (year,location,material,weight_tons) VALUES (2022,'New York','Plastic',15000),(2022,'New York','Paper',20000),(2022,'New York','Glass',10000);
SELECT material, SUM(weight_tons) as total_weight FROM waste_generation WHERE year = 2022 AND location = 'New York' GROUP BY material;
Add a new carbon offset project called 'Tropical Forest Conservation' to the 'carbon_offset_projects' table
CREATE TABLE carbon_offset_projects (id INT PRIMARY KEY,project_name VARCHAR(100),location VARCHAR(50));
INSERT INTO carbon_offset_projects (project_name, location) VALUES ('Tropical Forest Conservation', 'Amazon Rainforest');
Which cargo ships have visited the Port of New York in the last 30 days?
CREATE TABLE port_visits (id INT,ship_id INT,port_id INT,visit_date DATE); INSERT INTO port_visits (id,ship_id,port_id,visit_date) VALUES (1,1,1,'2022-01-01'),(2,2,2,'2022-01-15'),(3,3,1,'2022-02-05'); CREATE TABLE ports (id INT,name VARCHAR(50)); INSERT INTO ports (id,name) VALUES (1,'Port of New York'),(2,'Port of Los Angeles'),(3,'Port of Miami');
SELECT port_visits.ship_id, cargo_ships.name, port_visits.visit_date FROM port_visits JOIN ports ON port_visits.port_id = ports.id JOIN cargo_ships ON port_visits.ship_id = cargo_ships.id WHERE ports.name = 'Port of New York' AND port_visits.visit_date >= DATEADD(day, -30, GETDATE());
What is the minimum number of days to patch critical vulnerabilities in the 'server' subsystem?
CREATE TABLE vulnerabilities (subsystem VARCHAR(255),risk_level VARCHAR(255),days_to_patch INT); INSERT INTO vulnerabilities (subsystem,risk_level,days_to_patch) VALUES ('applications','high',10),('server','critical',5),('network','medium',7);
SELECT MIN(days_to_patch) FROM vulnerabilities WHERE subsystem = 'server' AND risk_level = 'critical';
Calculate the average height of all dams in the United States
CREATE TABLE Infrastructure (id INT,name VARCHAR(100),type VARCHAR(50),state VARCHAR(50),height FLOAT); INSERT INTO Infrastructure (id,name,type,state,height) VALUES (1,'Golden Gate Bridge','Bridge','California',227.0); INSERT INTO Infrastructure (id,name,type,state,height) VALUES (2,'Hoover Dam','Dam','Nevada',221.0);
SELECT AVG(height) FROM Infrastructure WHERE type = 'Dam';
Find the top 5 organizations with the highest average donation amount in the Asia-Pacific region.
CREATE TABLE organizations (id INT,name TEXT,region TEXT,avg_donation_amount DECIMAL(10,2)); INSERT INTO organizations (id,name,region,avg_donation_amount) VALUES (1,'Organization A','Asia-Pacific',50.00),(2,'Organization B','Europe',75.00);
SELECT name, avg_donation_amount FROM organizations WHERE region = 'Asia-Pacific' ORDER BY avg_donation_amount DESC LIMIT 5;
Find the average transaction amount for each customer's transactions?
CREATE TABLE Customers (CustomerID int,Name varchar(50),Age int); INSERT INTO Customers (CustomerID,Name,Age) VALUES (1,'John Smith',35),(2,'Jane Doe',42); CREATE TABLE Transactions (TransactionID int,CustomerID int,Amount decimal(10,2)); INSERT INTO Transactions (TransactionID,CustomerID,Amount) VALUES (1,1,500.00),(2,1,750.00),(3,2,250.00),(4,2,1000.00);
SELECT Contexts.CustomerID, AVG(Transactions.Amount) as AvgTransactionAmount FROM Contexts JOIN Transactions ON Contexts.CustomerID = Transactions.CustomerID GROUP BY Contexts.CustomerID;
What is the difference in average age between male and female healthcare workers in 'rural_clinics' table?
CREATE TABLE rural_clinics (id INT,name TEXT,location TEXT,num_workers INT,avg_age FLOAT,gender TEXT); INSERT INTO rural_clinics (id,name,location,num_workers,avg_age,gender) VALUES (1,'Rural Clinic A','Rural Area 1',10,45.3,'Male'),(2,'Rural Clinic B','Rural Area 2',15,42.8,'Female'),(3,'Rural Clinic C','Rural Area 1',8,50.1,'Male'),(4,'Rural Clinic D','Rural Area 2',12,48.5,'Female');
SELECT (SELECT AVG(avg_age) FROM rural_clinics WHERE gender = 'Male') - (SELECT AVG(avg_age) FROM rural_clinics WHERE gender = 'Female') AS difference;
Find the average capacity (MW) of renewable energy sources for each country
CREATE TABLE renewable_sources (id INT,name TEXT,country TEXT,capacity FLOAT); INSERT INTO renewable_sources (id,name,country,capacity) VALUES (1,'Wind','China',300); INSERT INTO renewable_sources (id,name,country,capacity) VALUES (2,'Solar','US',250); INSERT INTO renewable_sources (id,name,country,capacity) VALUES (3,'Hydro','Germany',200); INSERT INTO renewable_sources (id,name,country,capacity) VALUES (4,'Geothermal','Spain',150);
SELECT country, AVG(capacity) FROM renewable_sources GROUP BY country;
How many accidents have occurred in the last month in the Mining department?
CREATE TABLE Accidents(id INT,department VARCHAR(20),date DATE);
SELECT COUNT(*) FROM Accidents WHERE department = 'Mining' AND date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);
Update the gender of employee with ID 4 to Non-binary.
CREATE TABLE Employees (EmployeeID INT,Department VARCHAR(20),Gender VARCHAR(20),Salary FLOAT); INSERT INTO Employees (EmployeeID,Department,Gender,Salary) VALUES (1,'IT','Male',70000),(2,'HR','Female',60000),(3,'IT','Female',75000),(4,'IT','Male',78000),(5,'Finance','Male',85000);
UPDATE Employees SET Gender = 'Non-binary' WHERE EmployeeID = 4;
What was the market access strategy for 'DrugB' in Japan?
CREATE TABLE market_access(drug_name TEXT,market_country TEXT,strategy_description TEXT); INSERT INTO market_access(drug_name,market_country,strategy_description) VALUES('DrugB','Japan','Direct to consumer');
SELECT strategy_description FROM market_access WHERE drug_name = 'DrugB' AND market_country = 'Japan';
What are the marine species and their conservation statuses in the Southern Ocean?
CREATE TABLE marine_species (id INT,name VARCHAR(50),region VARCHAR(50),conservation_status VARCHAR(50)); INSERT INTO marine_species (id,name,region,conservation_status) VALUES (1,'Krill','Southern Ocean','Least Concern'),(2,'Blue Whale','Southern Ocean','Endangered'); CREATE TABLE conservation_status (id INT,name VARCHAR(50));
SELECT marine_species.name, marine_species.conservation_status FROM marine_species INNER JOIN conservation_status ON marine_species.conservation_status = conservation_status.name WHERE marine_species.region = 'Southern Ocean';
What is the total number of emergency calls in each state?
CREATE TABLE States (StateID INT,Name VARCHAR(50)); CREATE TABLE EmergencyCalls (CallID INT,StateID INT);
SELECT S.Name, COUNT(EC.CallID) as NumCalls FROM States S INNER JOIN EmergencyCalls EC ON S.StateID = EC.StateID GROUP BY S.Name;
What is the total donation amount per cause category in Q2 of 2022?
CREATE TABLE Donations (DonationID INT,DonationDate DATE,CauseCategory VARCHAR(50),DonationAmount NUMERIC(15,2));
SELECT CauseCategory, SUM(DonationAmount) as TotalDonations FROM Donations WHERE DonationDate >= '2022-04-01' AND DonationDate < '2022-07-01' GROUP BY CauseCategory;
How many geopolitical risk assessments were conducted for Brazil in 2019 and 2020?
CREATE TABLE Geopolitical_Risk_Assessments (assessment_id INT,assessment_date DATE,country VARCHAR(50)); INSERT INTO Geopolitical_Risk_Assessments (assessment_id,assessment_date,country) VALUES (1,'2019-05-12','Brazil'),(2,'2020-07-03','Brazil'),(3,'2021-11-28','Brazil');
SELECT COUNT(assessment_id) FROM Geopolitical_Risk_Assessments WHERE country = 'Brazil' AND YEAR(assessment_date) IN (2019, 2020);
Which programs had the highest total donations in H1 2022?
CREATE TABLE Donations (DonationID int,DonorID int,Amount decimal,DonationDate date); CREATE TABLE ProgramDonations (DonationID int,ProgramID int); CREATE TABLE Programs (ProgramID int,ProgramName varchar(50)); INSERT INTO Donations (DonationID,DonorID,Amount,DonationDate) VALUES (1,1,1000,'2022-01-01'); INSERT INTO ProgramDonations (DonationID,ProgramID) VALUES (1,1); INSERT INTO Programs (ProgramID,ProgramName) VALUES (1,'Health');
SELECT ProgramName, SUM(Donations.Amount) as TotalDonations FROM Donations JOIN ProgramDonations ON Donations.DonationID = ProgramDonations.DonationID JOIN Programs ON ProgramDonations.ProgramID = Programs.ProgramID WHERE YEAR(DonationDate) = 2022 AND MONTH(DonationDate) <= 6 GROUP BY ProgramName ORDER BY TotalDonations DESC;
How many riders used each vehicle type in the last week of August 2021?
CREATE TABLE route_planning (id INT,vehicle_type VARCHAR(20),route_date DATE,num_riders INT); INSERT INTO route_planning (id,vehicle_type,route_date,num_riders) VALUES (1,'Bus','2021-08-22',150),(2,'Tram','2021-08-24',200),(3,'Train','2021-08-26',250);
SELECT vehicle_type, SUM(num_riders) as total_riders FROM route_planning WHERE route_date BETWEEN '2021-08-22' AND '2021-08-28' GROUP BY vehicle_type;
Delete the workout type "Pilates" from the "WorkoutTypes" table
CREATE TABLE WorkoutTypes (Id INT PRIMARY KEY,WorkoutType VARCHAR(50));
DELETE FROM WorkoutTypes WHERE WorkoutType = 'Pilates';
What is the total number of mental health parity violations for each community?
CREATE TABLE mental_health_parity (violation_id INT,violation_date DATE,community_id INT); INSERT INTO mental_health_parity (violation_id,violation_date,community_id) VALUES (1,'2021-01-01',1),(2,'2021-02-01',2),(3,'2021-03-01',1);
SELECT community_id, COUNT(violation_id) FROM mental_health_parity GROUP BY community_id;
List the names of attorneys who have not won a case in Washington D.C.
CREATE TABLE attorneys (id INT,name TEXT,city TEXT); INSERT INTO attorneys (id,name,city) VALUES (1,'Catherine Piper','Washington D.C.'); CREATE TABLE cases (id INT,attorney_id INT,result TEXT,city TEXT); INSERT INTO cases (id,attorney_id,result,city) VALUES (1,1,'lost','Washington D.C.');
SELECT attorneys.name FROM attorneys LEFT JOIN cases ON attorneys.id = cases.attorney_id AND cases.result = 'won' WHERE attorneys.city = 'Washington D.C' AND cases.id IS NULL;
Update the budget for the 'Accessible Transportation' program in the year 2023 to 130,000.
CREATE TABLE DisabilitySupportPrograms (ProgramID INT,ProgramName VARCHAR(255),Budget DECIMAL(10,2),Year INT); INSERT INTO DisabilitySupportPrograms (ProgramID,ProgramName,Budget,Year) VALUES (1,'Sign Language Interpretation',50000,2023),(2,'Assistive Technology',75000,2023),(3,'Accessible Transportation',120000,2023);
UPDATE DisabilitySupportPrograms SET Budget = 130000 WHERE ProgramName = 'Accessible Transportation' AND Year = 2023;
Which students with disabilities have attended more than 4 workshops in the last 6 months?
CREATE TABLE Workshops (WorkshopID INT,Name VARCHAR(50),Date DATE,Description TEXT); CREATE TABLE StudentWorkshops (StudentID INT,WorkshopID INT); CREATE TABLE Students (StudentID INT,Disability VARCHAR(50),Name VARCHAR(50));
SELECT s.StudentID, s.Name, s.Disability FROM Students s JOIN StudentWorkshops sw ON s.StudentID = sw.StudentID JOIN Workshops w ON sw.WorkshopID = w.WorkshopID WHERE w.Date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH) AND CURRENT_DATE GROUP BY s.StudentID HAVING COUNT(sw.WorkshopID) > 4;
What was the total military spending by African countries in 2020?
CREATE TABLE military_spending (id INT,country VARCHAR(255),year INT,spending FLOAT); INSERT INTO military_spending (id,country,year,spending) VALUES (1,'Algeria',2020,12.34),(2,'Angola',2020,14.56),(3,'Egypt',2020,17.68),(4,'Nigeria',2020,20.34); CREATE VIEW africa_countries AS SELECT * FROM military_spending WHERE country IN ('Algeria','Angola','Egypt','Nigeria','South Africa','Morocco','Sudan','Libya','Tunisia','Kenya');
SELECT SUM(spending) FROM africa_countries WHERE year = 2020;
What was the sales of 'DrugF' in 'Japan' in Q2 2021?
CREATE TABLE sales_data (drug_name TEXT,country TEXT,sales INTEGER,sale_date DATE);
SELECT SUM(sales) FROM sales_data WHERE drug_name = 'DrugF' AND country = 'Japan' AND EXTRACT(MONTH FROM sale_date) BETWEEN 4 AND 6 AND EXTRACT(YEAR FROM sale_date) = 2021;
Which products are sold to customers from Argentina and have a sustainability_rating greater than 80?
CREATE TABLE sales_arg (id INT,customer_id INT,product VARCHAR(20),price DECIMAL(5,2)); CREATE TABLE suppliers_ar (id INT,product VARCHAR(20),country VARCHAR(20),sustainability_rating INT); INSERT INTO sales_arg (id,customer_id,product,price) VALUES (1,1,'Scarf',29.99); INSERT INTO sales_arg (id,customer_id,product,price) VALUES (2,2,'Cardigan',79.99); INSERT INTO suppliers_ar (id,product,country,sustainability_rating) VALUES (1,'Scarf','Argentina',83); INSERT INTO suppliers_ar (id,product,country,sustainability_rating) VALUES (2,'Dress','Argentina',77);
SELECT sales_arg.product FROM sales_arg JOIN suppliers_ar ON sales_arg.product = suppliers_ar.product WHERE suppliers_ar.country = 'Argentina' AND suppliers_ar.sustainability_rating > 80;
What's the average age of visitors who attended the 'Modern Art' exhibition?
CREATE TABLE Exhibitions (ExhibitionName VARCHAR(50),VisitorID INT);
SELECT AVG(v.Age) FROM Visitors v JOIN Exhibitions e ON v.VisitorID = e.VisitorID WHERE e.ExhibitionName = 'Modern Art';
What is the percentage of patients who received CBT treatment in each state?
CREATE TABLE patient (patient_id INT,age INT,gender VARCHAR(50),state VARCHAR(50)); INSERT INTO patient (patient_id,age,gender,state) VALUES (1,35,'Female','New York'); INSERT INTO patient (patient_id,age,gender,state) VALUES (2,42,'Male','California'); CREATE TABLE treatment (treatment_id INT,patient_id INT,treatment_name VARCHAR(50),duration INT); INSERT INTO treatment (treatment_id,patient_id,treatment_name,duration) VALUES (1,1,'CBT',12); INSERT INTO treatment (treatment_id,patient_id,treatment_name,duration) VALUES (2,2,'DBT',16); CREATE TABLE state_data (state VARCHAR(50),population INT); INSERT INTO state_data (state,population) VALUES ('New York',20000000); INSERT INTO state_data (state,population) VALUES ('California',40000000);
SELECT state, COUNT(*) * 100.0 / (SELECT SUM(population) FROM state_data) AS percentage FROM (SELECT patient.state FROM patient INNER JOIN treatment ON patient.patient_id = treatment.patient_id WHERE treatment.treatment_name = 'CBT' GROUP BY patient.state) AS cbt_states INNER JOIN state_data ON cbt_states.state = state_data.state;
What is the total CO2 emissions of each mining operation in the past year, ordered by the most emitting operation?
CREATE TABLE mining_operations (id INT,name TEXT,co2_emissions INT,year INT); INSERT INTO mining_operations (id,name,co2_emissions,year) VALUES (1,'Operation A',12000,2021),(2,'Operation B',15000,2021),(3,'Operation C',18000,2021);
SELECT name, SUM(co2_emissions) FROM mining_operations WHERE year = 2021 GROUP BY name ORDER BY SUM(co2_emissions) DESC;
What is the total energy consumption of the Solar Plant in California in the last month?
CREATE TABLE EnergyConsumption (EnergyID INT,Plant VARCHAR(255),EnergyQuantity DECIMAL(5,2),Timestamp DATETIME);
SELECT SUM(EnergyQuantity) FROM EnergyConsumption WHERE Plant = 'Solar Plant' AND Region = 'California' AND Timestamp BETWEEN DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH) AND CURRENT_DATE();
What is the total number of medals won by each country in the Winter Olympics?
CREATE TABLE winter_olympics (id INT,country VARCHAR(50),year INT,gold INT,silver INT,bronze INT); INSERT INTO winter_olympics (id,country,year,gold,silver,bronze) VALUES (1,'United States',2022,25,13,10),(2,'Canada',2022,4,8,10);
SELECT country, GOLD + SILVER + BRONZE AS total_medals FROM winter_olympics GROUP BY country ORDER BY total_medals DESC;
Who are the top 5 countries with the highest ethical fashion consumption by quantity of recycled materials?
CREATE TABLE ethical_fashion_consumption (country VARCHAR(50),recycled_materials_quantity INT,total_quantity INT); INSERT INTO ethical_fashion_consumption (country,recycled_materials_quantity,total_quantity) VALUES ('USA',2000,5000),('China',3000,7000),('India',1000,3000),('Brazil',4000,10000),('Germany',500,6000),('France',800,8000);
SELECT country, recycled_materials_quantity FROM ethical_fashion_consumption ORDER BY recycled_materials_quantity DESC LIMIT 5;
Find the total transaction amount and number of transactions for each customer in Japan.
CREATE TABLE transactions (customer_id INT,transaction_amount DECIMAL(10,2),country VARCHAR(50)); INSERT INTO transactions (customer_id,transaction_amount,country) VALUES (1,120.50,'Japan'),(2,75.30,'Japan'),(3,150.00,'Japan'),(4,50.00,'Japan');
SELECT customer_id, SUM(transaction_amount) AS total_amount, COUNT(*) AS num_transactions FROM transactions WHERE country = 'Japan' GROUP BY customer_id;
How many articles were published in 2021?
CREATE TABLE articles (id INT,title TEXT,publish_date DATE); INSERT INTO articles (id,title,publish_date) VALUES (1,'Article 1','2021-01-01'),(2,'Article 2','2022-03-15'),(3,'Article 3','2020-12-25');
SELECT COUNT(*) FROM articles WHERE YEAR(publish_date) = 2021;
Add a new column 'ethnicity' to the 'fan_demographics' table
CREATE TABLE fan_demographics (fan_id INT PRIMARY KEY,name VARCHAR(100),age INT,gender VARCHAR(10),location VARCHAR(100));
ALTER TABLE fan_demographics ADD COLUMN ethnicity VARCHAR(50);
What is the total number of military bases located in 'middle_east' schema
CREATE SCHEMA if not exists middle_east; USE middle_east; CREATE TABLE if not exists military_bases (id INT,name VARCHAR(255),type VARCHAR(255),location VARCHAR(255)); INSERT INTO military_bases (id,name,type,location) VALUES (1,'Al Udeid Air Base','Air Force Base','Qatar'),(2,'Camp Arifjan','Army Base','Kuwait'),(3,'INJ C Camp Buehring','Army Base','Kuwait');
SELECT COUNT(*) FROM middle_east.military_bases;
What is the total number of volunteer hours per program?
CREATE TABLE volunteer_hours (id INT,program_id INT,hours INT); CREATE TABLE programs (id INT,name VARCHAR(20));
SELECT p.name, SUM(vh.hours) as total_hours FROM volunteer_hours vh JOIN programs p ON vh.program_id = p.id GROUP BY p.id;
What is the average duration of open pedagogy courses completed by students in the same school?
CREATE TABLE schools (id INT,name VARCHAR(255)); INSERT INTO schools VALUES (1,'SchoolA'),(2,'SchoolB'); CREATE TABLE course_completions (id INT,student_id INT,course_id INT,completion_date DATE,duration INT,school_id INT);
SELECT school_id, AVG(duration) as avg_duration FROM (SELECT school_id, duration, completion_date, ROW_NUMBER() OVER(PARTITION BY school_id, student_id ORDER BY completion_date DESC) as rn FROM course_completions) t WHERE rn = 1 GROUP BY school_id;
Identify all military technology that has not been inspected in the last 6 months.
CREATE TABLE MilitaryTechInspection (TechID INT,TechName VARCHAR(50),LastInspection DATE); INSERT INTO MilitaryTechInspection (TechID,TechName,LastInspection) VALUES (1,'Fighter Jet','2022-02-01'),(2,'Tank','2022-03-10'),(3,'Submarine','2022-04-15'),(4,'Radar System','2022-05-20'),(5,'Missile System','2022-06-25'),(6,'Drones','2022-01-01'),(7,'Satellite','2022-02-15'),(8,'Cyber Weapon','2022-03-31');
SELECT * FROM MilitaryTechInspection WHERE LastInspection < DATEADD(month, -6, GETDATE());
What is the revenue generated by vegan dishes?
CREATE TABLE dishes (dish VARCHAR(255),category VARCHAR(255),is_vegan BOOLEAN); INSERT INTO dishes VALUES ('Quinoa Salad','Entrees',TRUE); INSERT INTO dishes VALUES ('Cheese Pizza','Entrees',FALSE); CREATE TABLE orders (order_id INT,dish VARCHAR(255),quantity INT,price DECIMAL(10,2)); INSERT INTO orders VALUES (1,'Quinoa Salad',2,15.99); INSERT INTO orders VALUES (2,'Cheese Pizza',1,12.99);
SELECT SUM(quantity * price) AS vegan_revenue FROM orders O JOIN dishes D ON O.dish = D.dish WHERE D.is_vegan = TRUE;
What is the average founding year for companies that have received at least one round of funding over $20 million?
CREATE TABLE companies (id INT,name TEXT,industry TEXT,founding_date DATE,founder_race TEXT);CREATE TABLE funds (id INT,company_id INT,amount INT,funding_round TEXT);
SELECT AVG(EXTRACT(YEAR FROM companies.founding_date)) FROM companies INNER JOIN funds ON companies.id = funds.company_id WHERE funds.amount > 20000000;
What is the average cost of clinical trials for oncology drugs?
CREATE TABLE clinical_trials (drug_name TEXT,trial_type TEXT,cost INTEGER,disease_area TEXT); INSERT INTO clinical_trials (drug_name,trial_type,cost,disease_area) VALUES ('DrugA','Phase I',5000000,'Oncology'),('DrugB','Phase II',15000000,'Oncology'),('DrugC','Phase III',30000000,'Cardiovascular');
SELECT AVG(cost) FROM clinical_trials WHERE disease_area = 'Oncology';
Find the number of research publications for each graduate student in the Mathematics department, and order the results by the number of publications in descending order.
CREATE TABLE StudentPublications (id INT,name VARCHAR(255),department VARCHAR(255),publications INT);
SELECT name, publications FROM StudentPublications WHERE department = 'Mathematics' ORDER BY publications DESC;
What is the total weight of sustainable materials used by each manufacturer?
CREATE TABLE ManufacturerSustainableMaterials (manufacturer_id INT,manufacturer_name VARCHAR(255),material_type VARCHAR(255),weight INT); INSERT INTO ManufacturerSustainableMaterials (manufacturer_id,manufacturer_name,material_type,weight) VALUES (1,'ABC Manufacturing','Organic Cotton',10000),(2,'XYZ Manufacturing','Recycled Polyester',12000),(3,'Green Manufacturing','Hemp',8000),(4,'Eco Manufacturing','Bamboo',15000),(5,'Sustainable Manufacturing','Tencel',9000);
SELECT manufacturer_name, SUM(weight) as total_weight FROM ManufacturerSustainableMaterials GROUP BY manufacturer_name;
What is the minimum funding received by startups in the fintech sector that were founded after 2015?
CREATE TABLE company (id INT,name TEXT,industry TEXT,founding_year INT); INSERT INTO company (id,name,industry,founding_year) VALUES (1,'FinTechInnovations','Fintech',2016),(2,'PayEasy','Fintech',2017); CREATE TABLE funding (id INT,company_id INT,amount INT); INSERT INTO funding (id,company_id,amount) VALUES (1,1,1000000),(2,2,500000);
SELECT MIN(funding.amount) FROM funding INNER JOIN company ON funding.company_id = company.id WHERE company.industry = 'Fintech' AND company.founding_year > 2015;
List all heritage sites with their respective preservation statuses and the dates when the statuses were last updated.
CREATE TABLE HeritageSites (site_id INT,site_name VARCHAR(20),site_type VARCHAR(20)); CREATE TABLE PreservationStatus (site_id INT,status_name VARCHAR(20),status_date DATE);
SELECT hs.site_name, ps.status_name, ps.status_date FROM HeritageSites hs INNER JOIN PreservationStatus ps ON hs.site_id = ps.site_id WHERE ps.status_date = (SELECT MAX(status_date) FROM PreservationStatus WHERE site_id = ps.site_id);
Get the average maintenance cost for military equipment in the Air Force branch
CREATE TABLE military_equipment (equipment_id INT,branch VARCHAR(10),maintenance_cost DECIMAL(10,2));
SELECT AVG(maintenance_cost) FROM military_equipment WHERE branch = 'Air Force';
Update the jersey numbers of athletes who have changed their jersey numbers in the last month in the Athletes table.
CREATE TABLE JerseyChanges (ChangeID INT,AthleteID INT,OldJerseyNumber INT,NewJerseyNumber INT,ChangeDate DATE);
UPDATE Athletes SET JerseyNumber = jc.NewJerseyNumber FROM Athletes a JOIN JerseyChanges jc ON a.AthleteID = jc.AthleteID WHERE jc.ChangeDate > DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);
What is the average CO2 emission for each manufacturing process by region?
CREATE TABLE ManufacturingProcesses (ProcessID INT,ProcessName VARCHAR(50),Region VARCHAR(50)); INSERT INTO ManufacturingProcesses (ProcessID,ProcessName,Region) VALUES (1,'ProcessA','Asia'),(2,'ProcessB','Africa'),(3,'ProcessC','Europe'); CREATE TABLE CO2Emissions (EmissionID INT,CO2Emission DECIMAL(5,2),ProcessID INT); INSERT INTO CO2Emissions (EmissionID,CO2Emission,ProcessID) VALUES (1,50.50,1),(2,60.60,1),(3,70.70,2),(4,80.80,2),(5,90.90,3),(6,100.00,3);
SELECT Region, AVG(CO2Emission) as AverageCO2Emission FROM ManufacturingProcesses mp JOIN CO2Emissions ce ON mp.ProcessID = ce.ProcessID GROUP BY Region;
What is the average amount of waste produced by the mining industry in the state of New York?
CREATE TABLE waste_production (id INT,company TEXT,location TEXT,waste_amount FLOAT); INSERT INTO waste_production (id,company,location,waste_amount) VALUES (1,'New York Mining Inc','New York',15000);
SELECT AVG(waste_amount) FROM waste_production WHERE location = 'New York';
List all clinical trials that have been approved by the FDA and the EMA, and have not been terminated.
CREATE TABLE clinical_trials (trial_id TEXT,fda_approval BOOLEAN,ema_approval BOOLEAN,terminated BOOLEAN); INSERT INTO clinical_trials (trial_id,fda_approval,ema_approval,terminated) VALUES ('CT001',TRUE,TRUE,FALSE),('CT002',TRUE,FALSE,TRUE);
SELECT * FROM clinical_trials WHERE fda_approval = TRUE AND ema_approval = TRUE AND terminated = FALSE;
What is the percentage of vegan dishes sold in all branches last month?
CREATE TABLE Branches (branch_id INT,branch_name VARCHAR(255));CREATE TABLE Menu (dish_name VARCHAR(255),branch_id INT,dish_type VARCHAR(255),price DECIMAL(5,2));CREATE TABLE Sales (sale_date DATE,dish_name VARCHAR(255),quantity INT);
SELECT ROUND(SUM(CASE WHEN dish_type = 'vegan' THEN quantity ELSE 0 END) / SUM(quantity) * 100, 2) as vegan_pct FROM Sales JOIN Menu ON Sales.dish_name = Menu.dish_name WHERE sale_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 2 MONTH) AND DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);
What is the maximum ice thickness observed in Greenland in 2021?
CREATE TABLE ice_thickness_data (location VARCHAR(50),year INT,ice_thickness FLOAT);
SELECT MAX(ice_thickness) FROM ice_thickness_data WHERE location = 'Greenland' AND year = 2021;
List all climate mitigation projects in Latin America and their respective start dates.
CREATE TABLE climate_mitigation (project_name VARCHAR(255),region VARCHAR(255),start_date DATE); INSERT INTO climate_mitigation (project_name,region,start_date) VALUES ('Tree Planting Initiative','Latin America','2020-01-01'); INSERT INTO climate_mitigation (project_name,region,start_date) VALUES ('Carbon Capture Project','Latin America','2019-06-15');
SELECT project_name, start_date FROM climate_mitigation WHERE region = 'Latin America';
How many restorative justice programs were implemented in the United States, Canada, and the United Kingdom between 2015 and 2020?
CREATE TABLE restorative_justice_programs (id INT,program_name VARCHAR(255),country VARCHAR(255),start_year INT,end_year INT); INSERT INTO restorative_justice_programs (id,program_name,country,start_year,end_year) VALUES (1,'Victim Offender Mediation Program','United States',2016,2020),(2,'Restorative Circles','Canada',2017,2020),(3,'Family Group Conferencing','United Kingdom',2015,2018);
SELECT COUNT(*) AS total_programs FROM restorative_justice_programs WHERE country IN ('United States', 'Canada', 'United Kingdom') AND start_year BETWEEN 2015 AND 2020;
Who are the top 3 countries receiving climate finance from the Global Environment Facility for climate adaptation?
CREATE TABLE global_environment_facility (fund_id INT,project_name VARCHAR(100),country VARCHAR(50),sector VARCHAR(50),amount FLOAT,adaptation_flag BOOLEAN); INSERT INTO global_environment_facility (fund_id,project_name,country,sector,amount,adaptation_flag) VALUES (1,'Mangrove Restoration','Indonesia','Coastal',2000000,TRUE);
SELECT country, SUM(amount) as total_amount FROM global_environment_facility WHERE adaptation_flag = TRUE GROUP BY country ORDER BY total_amount DESC LIMIT 3;
What is the distribution of energy sources in rural areas?
CREATE TABLE energy_sources (location VARCHAR(50),source VARCHAR(50),percentage FLOAT);
SELECT source, SUM(percentage) AS percentage FROM energy_sources WHERE location = 'rural' GROUP BY source;
Insert a new record into the 'Craft Workshops' table for the participant 'Lila' who attended the 'Pottery' event.
CREATE TABLE craft_workshops (workshop_id INT,participant_name VARCHAR(50),event_type VARCHAR(50)); INSERT INTO craft_workshops (workshop_id,participant_name,event_type) VALUES (1,'Ada','Jewelry'),(2,'Beatrice','Knitting'),(3,'Charlotte','Sculpture');
INSERT INTO craft_workshops (workshop_id, participant_name, event_type) VALUES (4, 'Lila', 'Pottery');
What is the average donation amount for donors who identify as female and have donated to organizations working on gender equality?
CREATE TABLE donors (id INT,gender VARCHAR(50),name VARCHAR(255)); INSERT INTO donors (id,gender,name) VALUES (1,'Female','Gender Equality Donor'); CREATE TABLE donations (id INT,donor_id INT,organization_id INT,amount DECIMAL(10,2),donation_date DATE); CREATE TABLE organizations (id INT,name VARCHAR(255),focus VARCHAR(255)); INSERT INTO organizations (id,name,focus) VALUES (5,'Gender Equality Network','Gender Equality');
SELECT AVG(amount) FROM donations JOIN donors ON donations.donor_id = donors.id JOIN organizations ON donations.organization_id = organizations.id WHERE donors.gender = 'Female' AND organizations.focus = 'Gender Equality';
What is the average listing price for condos in Denver with a price above 500000?
CREATE TABLE denver_properties (type VARCHAR(10),price INT); INSERT INTO denver_properties (type,price) VALUES ('Condo',600000); INSERT INTO denver_properties (type,price) VALUES ('Condo',700000);
SELECT AVG(price) FROM denver_properties WHERE type = 'Condo' AND price > 500000;
Find the maximum daily water usage for 'residential' purposes in 'November 2021' from the 'water_usage' table
CREATE TABLE water_usage (id INT,usage FLOAT,purpose VARCHAR(20),date DATE); INSERT INTO water_usage (id,usage,purpose,date) VALUES (1,200,'residential','2021-11-01'); INSERT INTO water_usage (id,usage,purpose,date) VALUES (2,150,'residential','2021-11-02');
SELECT MAX(usage) FROM (SELECT usage FROM water_usage WHERE purpose = 'residential' AND date BETWEEN '2021-11-01' AND '2021-11-30' GROUP BY date) as daily_usage;
Insert a new record of cargo with a weight of 6000 tons and cargo name 'chemicals' into the CARGO table
CREATE TABLE CARGO (ID INT,VESSEL_ID INT,CARGO_NAME VARCHAR(50),WEIGHT INT);
INSERT INTO CARGO (ID, VESSEL_ID, CARGO_NAME, WEIGHT) VALUES (1, 123, 'chemicals', 6000);
What was the total number of defense projects in the 'Research' phase with a completion date in H1 2022?
CREATE TABLE defense_projects (id INT,project_name VARCHAR,project_phase VARCHAR,completion_date DATE); INSERT INTO defense_projects (id,project_name,project_phase,completion_date) VALUES (1,'Project J','Research','2022-05-27'); INSERT INTO defense_projects (id,project_name,project_phase,completion_date) VALUES (2,'Project K','Development','2022-02-21'); INSERT INTO defense_projects (id,project_name,project_phase,completion_date) VALUES (3,'Project L','Research','2022-06-12');
SELECT COUNT(*) FROM defense_projects WHERE project_phase = 'Research' AND completion_date BETWEEN '2022-01-01' AND '2022-06-30';
Find the top 2 warehouse locations with the highest average management cost per item in Q2 2021.
CREATE TABLE warehouse_stats (item_id INT,warehouse_location TEXT,management_cost FLOAT,order_date DATE);
SELECT warehouse_location, AVG(management_cost) as avg_cost FROM warehouse_stats WHERE EXTRACT(MONTH FROM order_date) BETWEEN 4 AND 6 GROUP BY warehouse_location ORDER BY avg_cost DESC LIMIT 2;
How many marine protected areas are in the Indian Ocean?
CREATE TABLE marine_protected_areas (region VARCHAR(20),name VARCHAR(50),size FLOAT); INSERT INTO marine_protected_areas (region,name,size) VALUES ('Indian Ocean','Maldives Exclusive Economic Zone',90000); INSERT INTO marine_protected_areas (region,name,size) VALUES ('Indian Ocean','Chagos Marine Protected Area',640000); INSERT INTO marine_protected_areas (region,name,size) VALUES ('Atlantic Ocean','Sargasso Sea',3500000);
SELECT COUNT(*) FROM marine_protected_areas WHERE region = 'Indian Ocean';
What is the combined budget for language preservation programs in Oceania?
CREATE TABLE Preservation_Programs (Program_ID INT PRIMARY KEY,Name VARCHAR(100),Country VARCHAR(50),Budget DECIMAL(10,2)); INSERT INTO Preservation_Programs (Program_ID,Name,Country,Budget) VALUES (1,'Swahili Language Program','Tanzania',50000.00); INSERT INTO Preservation_Programs (Program_ID,Name,Country,Budget) VALUES (2,'Berber Language Program','Morocco',75000.00); INSERT INTO Preservation_Programs (Program_ID,Name,Country,Budget) VALUES (3,'Maori Language Program','New Zealand',30000.00);
SELECT SUM(Budget) FROM Preservation_Programs WHERE Country IN ('New Zealand');
What are the total expenses for astrophysics research on Pulsars and Blazars?
CREATE TABLE ResearchExpenses (ResearchID INT PRIMARY KEY,Subject VARCHAR(255),Expenses FLOAT); INSERT INTO ResearchExpenses (ResearchID,Subject,Expenses) VALUES (5,'Pulsars',500000); INSERT INTO ResearchExpenses (ResearchID,Subject,Expenses) VALUES (6,'Blazars',700000);
SELECT SUM(Expenses) FROM ResearchExpenses WHERE Subject IN ('Pulsars', 'Blazars');
How many soil moisture sensors have a temperature above 20 degrees in 'Field011'?
CREATE TABLE soil_moisture_sensors (id INT,field_id VARCHAR(10),sensor_id VARCHAR(10),temperature FLOAT); INSERT INTO soil_moisture_sensors (id,field_id,sensor_id,temperature) VALUES (1,'Field011','SM011',22.1),(2,'Field011','SM012',19.9);
SELECT COUNT(*) FROM soil_moisture_sensors WHERE field_id = 'Field011' AND temperature > 20;
What is the industry with the highest total assets value?
CREATE TABLE customers (id INT,name VARCHAR(255),industry VARCHAR(255),assets DECIMAL(10,2)); INSERT INTO customers (id,name,industry,assets) VALUES (1,'John Doe','Financial Services',150000.00),(2,'Jane Smith','Financial Services',200000.00),(3,'Alice Johnson','Banking',250000.00),(4,'Bob Brown','Banking',300000.00),(5,'Charlie Davis','Retail',50000.00),(6,'Diana Green','Healthcare',75000.00);
SELECT industry, SUM(assets) AS total_assets FROM customers GROUP BY industry ORDER BY total_assets DESC LIMIT 1;
Update the email addresses for teachers living in 'California'
CREATE TABLE teachers (id INT,name VARCHAR(20),state VARCHAR(20),email VARCHAR(30)); INSERT INTO teachers (id,name,state,email) VALUES (1,'Ms. Garcia','California','ms.garcia@example.com'); INSERT INTO teachers (id,name,state,email) VALUES (2,'Mr. Nguyen','Texas','mr.nguyen@example.com'); INSERT INTO teachers (id,name,state,email) VALUES (3,'Mx. Patel','California','mx.patel@example.com'); INSERT INTO teachers (id,name,state,email) VALUES (4,'Mrs. Chen','New York','mrs.chen@example.com');
UPDATE teachers SET email = CASE WHEN state = 'California' THEN CONCAT(name, '@californiateachers.org') ELSE email END WHERE state = 'California';
What is the total number of animals in the animal_rehabilitation table that have been released back into the wild, grouped by region?
CREATE TABLE animal_rehabilitation (id INT,animal_name VARCHAR(255),region VARCHAR(255),admission_date DATE,release_date DATE);
SELECT region, COUNT(id) FROM animal_rehabilitation WHERE release_date IS NOT NULL GROUP BY region;
What is the maximum ocean floor depth in the Pacific region?
CREATE TABLE ocean_floor (id INT,region VARCHAR(255),depth FLOAT); INSERT INTO ocean_floor (id,region,depth) VALUES (1,'Atlantic',8605.0),(2,'Pacific',10994.0),(3,'Indian',7455.0),(4,'Arctic',5381.0),(5,'Southern',7235.0);
SELECT MAX(depth) FROM ocean_floor WHERE region = 'Pacific';
What is the total CO2 emission in the Arctic regions for each year?
CREATE TABLE CO2Emissions (region VARCHAR(255),year INT,CO2_emission FLOAT); INSERT INTO CO2Emissions (region,year,CO2_emission) VALUES ('Arctic Ocean',2019,120000),('Arctic Ocean',2020,125000),('Greenland',2019,150000),('Greenland',2020,160000);
SELECT region, year, SUM(CO2_emission) as total_emission FROM CO2Emissions GROUP BY year, region;
Show the most recent incident date for each category in the SecurityIncidents table.
CREATE TABLE SecurityIncidents (id INT,incident_category VARCHAR(255),incident_date DATE); INSERT INTO SecurityIncidents (id,incident_category,incident_date) VALUES (1,'Malware','2022-03-01'),(2,'Phishing','2022-03-05'),(3,'Network Intrusion','2022-03-10'),(4,'Unauthorized Access','2022-03-15'),(5,'Data Exfiltration','2022-03-20');
SELECT incident_category, incident_date, ROW_NUMBER() OVER (PARTITION BY incident_category ORDER BY incident_date DESC) AS rank FROM SecurityIncidents WHERE rank = 1;
What defense projects were completed before their scheduled end date in Africa?
CREATE TABLE DefenseProjects (id INT,project_name VARCHAR(100),region VARCHAR(50),start_date DATE,end_date DATE); INSERT INTO DefenseProjects (id,project_name,region,start_date,end_date) VALUES (1,'Project D','Africa','2021-01-01','2021-12-31'); INSERT INTO DefenseProjects (id,project_name,region,start_date,end_date) VALUES (2,'Project E','Africa','2020-01-01','2020-12-31'); INSERT INTO DefenseProjects (id,project_name,region,start_date,end_date) VALUES (3,'Project F','Africa','2019-01-01','2020-06-30');
SELECT * FROM DefenseProjects WHERE region = 'Africa' AND end_date >= start_date;
How many people from 'California' attended the 'Art Exhibition' event?
CREATE TABLE Attendees_Location (event_name VARCHAR(255),attendee_location VARCHAR(255),attendees INT); INSERT INTO Attendees_Location (event_name,attendee_location,attendees) VALUES ('Dance Performance','California',50,'California',60,'New York',40),('Art Exhibition','California',70,'New York',30),('Theater Play','California',45,'California',35,'New York',50);
SELECT attendees FROM Attendees_Location WHERE event_name = 'Art Exhibition' AND attendee_location = 'California';
What is the reactor temperature trend for the last 10 production runs?
CREATE TABLE production_runs (id INT,reactor_temp FLOAT,run_date DATE); INSERT INTO production_runs (id,reactor_temp,run_date) VALUES (1,120.5,'2023-03-01'),(2,125.3,'2023-03-02'),(3,118.9,'2023-03-03');
SELECT reactor_temp, LAG(reactor_temp, 1) OVER (ORDER BY run_date) AS prev_reactor_temp FROM production_runs WHERE id >= 11;
What is the total number of employees and the average environmental impact score of mining operations in each country, excluding those with an environmental impact score below 70?
CREATE TABLE mining_operations (id INT,country VARCHAR(255),num_employees INT,environmental_impact_score INT); INSERT INTO mining_operations (id,country,num_employees,environmental_impact_score) VALUES (1,'Canada',300,85),(2,'USA',500,70),(3,'Mexico',400,88),(4,'Australia',200,60);
SELECT country, SUM(num_employees) AS total_employees, AVG(environmental_impact_score) AS avg_impact_score FROM mining_operations WHERE environmental_impact_score >= 70 GROUP BY country;
What is the average budget allocated for policies?
CREATE TABLE Policy_Budget (Policy_ID INT PRIMARY KEY,Policy_Area VARCHAR(30),Budget INT); INSERT INTO Policy_Budget (Policy_ID,Policy_Area,Budget) VALUES (1,'Transportation',8000000),(2,'Education',7000000),(3,'Environment',5000000),(4,'Housing',9000000);
SELECT AVG(Budget) FROM Policy_Budget;
What is the minimum age of patients who received therapy in South Africa?
CREATE TABLE patients (id INT,age INT,country VARCHAR(20)); INSERT INTO patients (id,age,country) VALUES (1,22,'South Africa'),(2,33,'Namibia'); CREATE TABLE therapies (id INT,patient_id INT); INSERT INTO therapies (id,patient_id) VALUES (1,1),(2,2);
SELECT MIN(patients.age) FROM patients INNER JOIN therapies ON patients.id = therapies.patient_id WHERE patients.country = 'South Africa';
What is the total area of marine protected areas in the Indian Ocean?
CREATE TABLE marine_protected_areas (ocean VARCHAR(255),area INT); INSERT INTO marine_protected_areas (ocean,area) VALUES ('Indian Ocean',250000),('Atlantic Ocean',120000);
SELECT SUM(area) FROM marine_protected_areas WHERE ocean = 'Indian Ocean';
List the power plants in India
CREATE TABLE Infrastructure (id INT,name VARCHAR(100),type VARCHAR(50),country VARCHAR(50)); INSERT INTO Infrastructure (id,name,type,country) VALUES (11,'NTPC Dadri','Power Plant','India'),(12,'Tata Power Mumbai','Power Plant','India');
SELECT name FROM Infrastructure WHERE type = 'Power Plant' AND country = 'India';