instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the average production capacity of all silver mines in the 'mine_stats' table?
CREATE TABLE mine_stats (mine_name VARCHAR(255),mine_type VARCHAR(255),production_capacity FLOAT); INSERT INTO mine_stats (mine_name,mine_type,production_capacity) VALUES ('Silver Summit','silver',3000.2),('Quicksilver Quarry','silver',3500.4),('Mercury Mine','silver',2800.1);
SELECT AVG(production_capacity) FROM mine_stats WHERE mine_type = 'silver';
Update the compliance status of vessel with ID 456 to 'compliant' in the VESSEL_COMPLIANCE table
CREATE TABLE VESSEL_COMPLIANCE (ID INT,VESSEL_ID INT,COMPLIANCE_STATUS VARCHAR(20));
UPDATE VESSEL_COMPLIANCE SET COMPLIANCE_STATUS = 'compliant' WHERE VESSEL_ID = 456;
What is the average CO2 emission of electric vehicles in China?
CREATE TABLE emissions (id INT,country VARCHAR(20),vehicle_type VARCHAR(20),avg_emission FLOAT); INSERT INTO emissions (id,country,vehicle_type,avg_emission) VALUES (1,'China','Electric',0.05),(2,'China','Gasoline',0.15);
SELECT avg_emission FROM emissions WHERE country = 'China' AND vehicle_type = 'Electric';
What is the total biomass and carbon footprint for all aquaculture farms?
CREATE TABLE aquaculture_farms (id INT,farm_name VARCHAR(50),biomass DECIMAL(10,2),carbon_footprint DECIMAL(10,2)); INSERT INTO aquaculture_farms (id,farm_name,biomass,carbon_footprint) VALUES (1,'Farm A',20000,500); INSERT INTO aquaculture_farms (id,farm_name,biomass,carbon_footprint) VALUES (2,'Farm B',15000,350);
SELECT SUM(biomass) as total_biomass, SUM(carbon_footprint) as total_carbon_footprint FROM aquaculture_farms;
How many unique authors had their books displayed at literature festivals in India and Egypt?
CREATE TABLE LiteratureFestivals (id INT,festival_name VARCHAR(50),author_name VARCHAR(50),country VARCHAR(50),festival_date DATE); INSERT INTO LiteratureFestivals (id,festival_name,author_name,country,festival_date) VALUES (1,'Literature Festival','Rabindranath Tagore','India','2022-10-01'),(2,'Book Fair','Naguib Mahfouz','Egypt','2022-10-05'),(3,'Poetry Slam','Sarojini Naidu','India','2022-10-03'),(4,'Writers Conference','Taha Hussein','Egypt','2022-10-07');
SELECT COUNT(DISTINCT author_name) FROM LiteratureFestivals WHERE country IN ('India', 'Egypt');
Delete records from the 'ai_safety' table where 'risk_level' is 'High' and 'mitigation_strategy' is 'Not Implemented'
CREATE TABLE ai_safety (id INT,incident VARCHAR(20),risk_level VARCHAR(20),mitigation_strategy TEXT); INSERT INTO ai_safety (id,incident,risk_level,mitigation_strategy) VALUES (1,'Data Poisoning','High','Mitigation Implemented'),(2,'Adversarial Attack','Medium','Not Implemented');
DELETE FROM ai_safety WHERE risk_level = 'High' AND mitigation_strategy = 'Not Implemented';
What is the average life expectancy in each region?
CREATE TABLE countries (country_name VARCHAR(50),region VARCHAR(50),life_expectancy FLOAT); INSERT INTO countries (country_name,region,life_expectancy) VALUES ('Canada','North America',82.2),('Mexico','North America',75.5);
SELECT region, AVG(life_expectancy) as avg_life_expectancy FROM countries GROUP BY region;
What is the average conservation budget for the Arctic and Atlantic oceans?
CREATE TABLE conservation (conservation_id INT,region TEXT,budget FLOAT); INSERT INTO conservation (conservation_id,region,budget) VALUES (1,'Arctic',1200000),(2,'Atlantic',1500000);
SELECT AVG(budget) FROM conservation WHERE region IN ('Arctic', 'Atlantic')
Update the 'labor_productivity' column for 'Company A' in the 'mining_labor_productivity' table to be the average of all companies.
CREATE TABLE mining_labor_productivity (company VARCHAR(50),labor_productivity DECIMAL(5,2));
UPDATE mining_labor_productivity SET labor_productivity = (SELECT AVG(labor_productivity) FROM mining_labor_productivity) WHERE company = 'Company A';
Summarize the total number of tourists who visited Spain, Germany, and the United Kingdom in Q2 and Q3 of 2020
CREATE TABLE TouristsQ2Q3 (country VARCHAR(255),quarter INT,tourists INT); INSERT INTO TouristsQ2Q3 (country,quarter,tourists) VALUES ('Spain',2,1200000),('Spain',3,1500000),('Germany',2,2000000),('Germany',3,2200000),('United Kingdom',2,1800000),('United Kingdom',3,2000000);
SELECT country, SUM(tourists) AS total_tourists FROM TouristsQ2Q3 WHERE country IN ('Spain', 'Germany', 'United Kingdom') AND quarter IN (2, 3) GROUP BY country;
What are the biosensors and associated departments that cost more than 1200?
CREATE TABLE Biosensor (Biosensor_Name VARCHAR(50) PRIMARY KEY,Department VARCHAR(50),Price DECIMAL(10,2)); INSERT INTO Biosensor (Biosensor_Name,Department,Price) VALUES ('Bio1','Genetic Research',1000.00); INSERT INTO Biosensor (Biosensor_Name,Department,Price) VALUES ('Bio2','BioProcess Engineering',1500.00); INSERT INTO Biosensor (Biosensor_Name,Department,Price) VALUES ('Bio3','Genetic Research',1800.00);
SELECT B.Biosensor_Name, B.Department FROM Biosensor B WHERE B.Price > 1200;
What is the average hotel price in the capital cities of Europe?
CREATE TABLE Hotels_Europe_Capitals (id INT,name VARCHAR(50),price DECIMAL(5,2),city VARCHAR(50),capital BOOLEAN); INSERT INTO Hotels_Europe_Capitals (id,name,price,city,capital) VALUES (1,'Grand Hotel',200.00,'Paris',TRUE),(2,'Hotel Colosseo',350.00,'Rome',FALSE),(3,'Park Royal',120.00,'London',TRUE),(4,'Hotel Versailles',420.00,'Paris',FALSE);
SELECT city, AVG(price) as avg_price FROM Hotels_Europe_Capitals WHERE capital = TRUE GROUP BY city;
Who is the top customer for eco-friendly denim?
CREATE TABLE customers (customer VARCHAR(20),purchases INT); INSERT INTO customers (customer,purchases) VALUES ('Customer A',10),('Customer B',5),('Customer C',15); CREATE TABLE denim_sales (customer VARCHAR(20),denim INT); INSERT INTO denim_sales (customer,denim) VALUES ('Customer A',5),('Customer B',3),('Customer C',8);
SELECT customer, purchases FROM (SELECT customer, SUM(denim) AS denim_purchases FROM denim_sales GROUP BY customer) AS denim_purchases INNER JOIN customers ON denim_purchases.customer = customers.customer ORDER BY denim_purchases DESC LIMIT 1;
Count the number of energy efficiency projects in Canada
CREATE TABLE energy_efficiency_projects (id INT,name VARCHAR(100),country VARCHAR(50)); INSERT INTO energy_efficiency_projects (id,name,country) VALUES (1,'Project 1','Canada'),(2,'Project 2','Canada'),(3,'Project 3','USA');
SELECT COUNT(*) FROM energy_efficiency_projects WHERE country = 'Canada';
What is the total timber volume in tropical dry forests?
CREATE TABLE tropical_forests (id INT,volume FLOAT); INSERT INTO tropical_forests VALUES (1,111.22),(2,222.33),(3,333.44);
SELECT SUM(volume) FROM tropical_forests WHERE region = 'Tropical Dry';
List all clinical trials for the drug 'Axo' in Europe.
CREATE TABLE clinical_trials_2 (drug_name TEXT,trial_id TEXT,region TEXT); INSERT INTO clinical_trials_2 (drug_name,trial_id,region) VALUES ('Drexo','CT003','France'),('Axo','CT004','Germany');
SELECT * FROM clinical_trials_2 WHERE drug_name = 'Axo' AND region = 'Europe';
Which agricultural innovation projects in Bolivia had the highest cost in 2019?
CREATE TABLE agricultural_innovation_bolivia (id INT,country VARCHAR(255),project VARCHAR(255),cost FLOAT,year INT); INSERT INTO agricultural_innovation_bolivia (id,country,project,cost,year) VALUES (1,'Bolivia','New Seed Variety',2500000,2019),(2,'Bolivia','Drip Irrigation',3000000,2019),(3,'Bolivia','Precision Farming',2000000,2019);
SELECT project, MAX(cost) as max_cost FROM agricultural_innovation_bolivia WHERE country = 'Bolivia' AND year = 2019 GROUP BY project;
What is the total production of Terbium in Africa from 2017 to 2020?
CREATE TABLE terbium_production (id INT,country TEXT,year INT,terbium_prod FLOAT); INSERT INTO terbium_production (id,country,year,terbium_prod) VALUES (1,'South Africa',2017,120.0),(2,'South Africa',2018,150.0),(3,'South Africa',2019,180.0),(4,'South Africa',2020,200.0),(5,'Egypt',2017,50.0),(6,'Egypt',2018,55.0),(7,'Egypt',2019,60.0),(8,'Egypt',2020,65.0);
SELECT SUM(terbium_prod) as total_terbium_prod FROM terbium_production WHERE year BETWEEN 2017 AND 2020 AND country = 'South Africa' OR country = 'Egypt';
What was the total number of hybrid vehicles sold in North America and Europe in Q2 2021?
CREATE TABLE Hybrid_Sales (id INT,vehicle_model VARCHAR(255),quantity_sold INT,region VARCHAR(50),sale_quarter INT); INSERT INTO Hybrid_Sales (id,vehicle_model,quantity_sold,region,sale_quarter) VALUES (1,'Prius',800,'North America',2); INSERT INTO Hybrid_Sales (id,vehicle_model,quantity_sold,region,sale_quarter) VALUES (2,'Tesla Model Y',1200,'Europe',2);
SELECT SUM(quantity_sold) FROM Hybrid_Sales WHERE region IN ('North America', 'Europe') AND sale_quarter = 2;
Which chemical categories have manufacturing costs greater than $100,000?
CREATE TABLE chemical_manufacturing (chemical_id INT,category VARCHAR(255),manufacturing_costs INT); INSERT INTO chemical_manufacturing (chemical_id,category,manufacturing_costs) VALUES (1,'Flammable Liquids',120000),(2,'Corrosive Materials',85000),(3,'Flammable Gases',98000);
SELECT category FROM chemical_manufacturing WHERE manufacturing_costs > 100000;
What is the total number of volunteers who identified as part of the LGBTQ+ community and engaged in our programs in the last 12 months, broken down by city?
CREATE TABLE Volunteers (VolunteerID int,VolunteerName varchar(50),City varchar(50),LastEngagementDate date,LGBTQPlus bit);
SELECT City, SUM(LGBTQPlus) FROM Volunteers WHERE LastEngagementDate >= DATEADD(month, -12, GETDATE()) GROUP BY City;
Find the total CO2 emissions for each mining site in the past year
CREATE TABLE MiningSites (SiteID INT,SiteName VARCHAR(50),Location VARCHAR(50)); INSERT INTO MiningSites (SiteID,SiteName,Location) VALUES (1,'Site A','New York'),(2,'Site B','Ohio'); CREATE TABLE Emissions (SiteID INT,EmissionDate DATE,CO2Emissions INT); INSERT INTO Emissions (SiteID,EmissionDate,CO2Emissions) VALUES (1,'2021-01-01',500),(1,'2022-01-15',700),(2,'2021-02-03',600);
SELECT s.SiteName, s.Location, SUM(e.CO2Emissions) as TotalCO2Emissions FROM Emissions e INNER JOIN MiningSites s ON e.SiteID = s.SiteID WHERE e.EmissionDate >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY e.SiteID;
Calculate total assets by investment type and region.
CREATE TABLE investments (id INT,type VARCHAR(255),region VARCHAR(255),amount FLOAT); INSERT INTO investments VALUES (1,'Stocks','Asia',50000),(2,'Bonds','Europe',75000),(3,'Real Estate','Americas',100000);
SELECT type, SUM(amount) as total_assets, region FROM investments GROUP BY type, region;
What is the total number of autonomous driving research projects in Germany and Japan?
CREATE TABLE AutonomousDrivingResearch (id INT,country VARCHAR(50),project_count INT); INSERT INTO AutonomousDrivingResearch (id,country,project_count) VALUES (1,'Germany',120); INSERT INTO AutonomousDrivingResearch (id,country,project_count) VALUES (2,'Japan',85);
SELECT country, SUM(project_count) FROM AutonomousDrivingResearch WHERE country IN ('Germany', 'Japan') GROUP BY country;
What is the average age of all astronauts who have flown to Mars?
CREATE TABLE Astronauts (AstronautID INT,Age INT,Gender VARCHAR(10),HasFlownToMars BOOLEAN);
SELECT AVG(Age) FROM Astronauts WHERE HasFlownToMars = TRUE;
What is the total amount donated by individual donors from 'Canada' in the year 2020?
CREATE TABLE donors (id INT,name TEXT,country TEXT,donation_amount DECIMAL,donation_date DATE); INSERT INTO donors (id,name,country,donation_amount,donation_date) VALUES (1,'John Doe','Canada',50.00,'2020-01-01'); INSERT INTO donors (id,name,country,donation_amount,donation_date) VALUES (2,'Jane Smith','Canada',100.00,'2020-05-15');
SELECT SUM(donation_amount) FROM donors WHERE country = 'Canada' AND YEAR(donation_date) = 2020 AND id NOT IN (SELECT donor_id FROM organizations);
How many circular economy initiatives were launched in Europe between 2010 and 2015?
CREATE TABLE circular_economy_initiatives (country VARCHAR(50),year INT,initiative BOOLEAN); INSERT INTO circular_economy_initiatives (country,year,initiative) VALUES ('Germany',2010,TRUE),('France',2012,TRUE),('UK',2015,TRUE);
SELECT COUNT(*) FROM circular_economy_initiatives WHERE year BETWEEN 2010 AND 2015 AND country IN ('Germany', 'France', 'UK', 'Italy', 'Spain');
What is the average market price of Erbium extracted in Malaysia in 2019?
CREATE TABLE Erbium_Production (id INT,year INT,country VARCHAR(255),quantity FLOAT,market_price FLOAT);
SELECT AVG(market_price) FROM Erbium_Production WHERE year = 2019 AND country = 'Malaysia';
What is the average number of three-point field goals made per game by the Milwaukee Bucks in their playoff games during the 2020-2021 NBA season?
CREATE TABLE matches (team VARCHAR(50),opponent VARCHAR(50),three_pointers INTEGER,points_team INTEGER,points_opponent INTEGER,season VARCHAR(10)); INSERT INTO matches (team,opponent,three_pointers,points_team,points_opponent,season) VALUES ('Milwaukee Bucks','Brooklyn Nets',15,115,107,'2020-2021'),('Milwaukee Bucks','Atlanta Hawks',18,113,112,'2020-2021');
SELECT AVG(three_pointers) FROM matches WHERE team = 'Milwaukee Bucks' AND season = '2020-2021' AND points_team > points_opponent;
Which user accounts have been involved in security incidents in the last quarter, and what types of incidents occurred?
CREATE TABLE security_incidents (id INT,user_account VARCHAR(20),incident_type VARCHAR(20),timestamp TIMESTAMP);
SELECT user_account, incident_type FROM security_incidents WHERE timestamp >= NOW() - INTERVAL 3 MONTH;
List all games that have been played for more than 50 hours
CREATE TABLE Games (GameID INT,HoursPlayed INT); INSERT INTO Games (GameID,HoursPlayed) VALUES (1,100); INSERT INTO Games (GameID,HoursPlayed) VALUES (2,25);
SELECT * FROM Games WHERE HoursPlayed > 50;
What are the top 3 most ordered vegetarian dishes by customers in the Midwest region?
CREATE TABLE restaurants (restaurant_id INT,name TEXT,region TEXT); INSERT INTO restaurants (restaurant_id,name,region) VALUES (1,'Big Burger','East'),(2,'Veggies R Us','Midwest'),(3,'Tasty Bites','West'); CREATE TABLE orders (order_id INT,dish TEXT,customer_id INT,restaurant_id INT); INSERT INTO orders (order_id,dish,customer_id,restaurant_id) VALUES (1,'Veggie Delight',5,2),(2,'Cheeseburger',6,1),(3,'Tofu Stir Fry',7,2),(4,'BBQ Ribs',8,1),(5,'Vegetarian Pizza',9,2);
SELECT dish, COUNT(*) as count FROM orders WHERE restaurant_id IN (SELECT restaurant_id FROM restaurants WHERE region = 'Midwest' AND dish NOT LIKE '%meat%') GROUP BY dish ORDER BY count DESC LIMIT 3;
What is the average block time for the Tezos network in the past month?
CREATE TABLE tezos_blocks (block_id INT,timestamp TIMESTAMP);
SELECT AVG(timestamp_diff) FROM (SELECT TIMESTAMPDIFF(SECOND, LAG(timestamp) OVER (ORDER BY block_id), timestamp) AS timestamp_diff FROM tezos_blocks WHERE timestamp >= NOW() - INTERVAL '1 month') subquery;
Identify the mental health professionals with the most years of experience in each country.
CREATE TABLE mental_health_professionals (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),years_of_experience INT);
SELECT location, MAX(years_of_experience) AS max_experience FROM mental_health_professionals GROUP BY location;
How many emergency medical service calls were made in each census tract last month?
CREATE TABLE census_tracts (tract_id INT,tract_name TEXT,total_population INT); INSERT INTO census_tracts (tract_id,tract_name,total_population) VALUES (1,'Tract 1',5000),(2,'Tract 2',6000),(3,'Tract 3',4000); CREATE TABLE emergency_medical_service (call_id INT,tract_id INT,call_date DATE); INSERT INTO emergency_medical_service (call_id,tract_id,call_date) VALUES (1,1,'2022-03-01'),(2,1,'2022-03-02'),(3,2,'2022-03-03'),(4,2,'2022-03-04'),(5,3,'2022-03-05'),(6,3,'2022-03-06');
SELECT tract_name, COUNT(*) FROM emergency_medical_service JOIN census_tracts ON emergency_medical_service.tract_id = census_tracts.tract_id WHERE call_date >= '2022-03-01' AND call_date < '2022-04-01' GROUP BY tract_name;
How many community development initiatives were completed in Tanzania between 2018 and 2020?
CREATE TABLE CommunityDevelopment (id INT,country VARCHAR(50),initiative VARCHAR(50),completion_date DATE); INSERT INTO CommunityDevelopment (id,country,initiative,completion_date) VALUES (1,'Tanzania','Library Construction','2018-12-15'),(2,'Tanzania','Water Purification Plant','2019-07-22'),(3,'Rwanda','Community Health Center','2020-04-01');
SELECT COUNT(*) FROM CommunityDevelopment WHERE country = 'Tanzania' AND completion_date BETWEEN '2018-01-01' AND '2020-12-31';
How many construction workers were employed in Washington in 2019 and 2020?
CREATE TABLE employment (employee_id INT,state VARCHAR(2),employment_date DATE,num_employees INT); INSERT INTO employment (employee_id,state,employment_date,num_employees) VALUES (1,'WA','2019-12-31',12000),(2,'WA','2020-12-31',14000),(3,'TX','2020-12-31',16000);
SELECT employment_date, SUM(num_employees) FROM employment WHERE state = 'WA' AND employment_date IN ('2019-12-31', '2020-12-31') GROUP BY employment_date;
Update the 'travel_advisories' table to include a new advisory for Japan regarding the cherry blossom festival in April 2023.
CREATE TABLE travel_advisories (id INT,country VARCHAR(50),advisory TEXT,start_date DATE,end_date DATE); INSERT INTO travel_advisories (id,country,advisory,start_date,end_date) VALUES (1,'Italy','Cancel all non-essential travel.','2022-12-01','2023-03-31');
UPDATE travel_advisories SET advisory = 'Avoid the crowded cherry blossom festival.', start_date = '2023-04-01', end_date = '2023-04-30' WHERE country = 'Japan';
What is the average heart rate of users aged 25-34?
CREATE TABLE users (id INT,age INT,gender VARCHAR(10),heart_rate INT); INSERT INTO users VALUES (1,23,'Female',75),(2,32,'Male',82),(3,27,'Male',78);
SELECT AVG(heart_rate) FROM users WHERE age BETWEEN 25 AND 34;
Calculate the average CO2 emissions of vessels using LNG fuel
CREATE TABLE Vessels (Id INT,Name VARCHAR(50),FuelType VARCHAR(20),CO2Emissions FLOAT); INSERT INTO Vessels (Id,Name,FuelType,CO2Emissions) VALUES (1,'Vessel1','LNG',1200),(2,'Vessel2','Diesel',1500),(3,'Vessel3','LNG',1100);
SELECT AVG(CO2Emissions) FROM Vessels WHERE FuelType = 'LNG';
Find dishes with the lowest sales per day and their average water consumption.
CREATE TABLE dishes (dish_name VARCHAR(255),daily_sales INT,water_consumption INT);
SELECT d.dish_name, AVG(d.water_consumption) as avg_water, MIN(d.daily_sales) as min_sales FROM dishes d GROUP BY d.dish_name ORDER BY min_sales ASC LIMIT 10;
Which art categories have the highest average revenue in each region?
CREATE TABLE ArtSales (id INT,region VARCHAR(255),art_category VARCHAR(255),revenue DECIMAL(10,2)); INSERT INTO ArtSales (id,region,art_category,revenue) VALUES (1,'North','Painting',3000),(2,'South','Sculpture',2000),(3,'North','Photography',1000),(4,'East','Painting',4000),(5,'North','Sculpture',5000),(6,'East','Photography',2000);
SELECT region, art_category, AVG(revenue) FROM ArtSales GROUP BY region, art_category ORDER BY region, AVG(revenue) DESC;
List all labor rights violations reported in the 'reports' table, and the corresponding union names from the 'unions' table.
CREATE TABLE reports (id INT PRIMARY KEY,violation VARCHAR(255),union_id INT); CREATE TABLE unions (id INT PRIMARY KEY,name VARCHAR(255)); INSERT INTO reports (id,violation,union_id) VALUES (1,'Violation 1',1),(2,'Violation 2',2); INSERT INTO unions (id,name) VALUES (1,'Union A'),(2,'Union B');
SELECT reports.violation, unions.name FROM reports JOIN unions ON reports.union_id = unions.id;
Add a new cargo handling operation to the "cargo_operations" table
CREATE TABLE cargo_operations (id INT PRIMARY KEY,vessel_id INT,port_id INT,operation_type VARCHAR(255),amount INT,timestamp TIMESTAMP);
INSERT INTO cargo_operations (id, vessel_id, port_id, operation_type, amount, timestamp) VALUES (1, 1, 2, 'Loading', 10000, '2022-01-01 10:00:00');
List the explainable AI techniques used in AI applications related to healthcare, along with their descriptions, sorted alphabetically by the technique name.
CREATE TABLE explainable_ai_tech (tech_id INT,technique_name VARCHAR(50),description TEXT,application_domain VARCHAR(50));
SELECT technique_name, description FROM explainable_ai_tech WHERE application_domain = 'healthcare' ORDER BY technique_name ASC;
List the top 3 cities with the highest landfill capacity in descending order.
CREATE TABLE landfill_capacity (city VARCHAR(50),capacity INT); INSERT INTO landfill_capacity (city,capacity) VALUES ('CityD',50000),('CityE',40000),('CityF',60000),('CityG',30000);
SELECT city, capacity FROM landfill_capacity ORDER BY capacity DESC LIMIT 3;
What is the maximum salary in the Marketing department?
CREATE TABLE EmployeeSalaries (EmployeeID INT,Department TEXT,Salary REAL); INSERT INTO EmployeeSalaries (EmployeeID,Department,Salary) VALUES (1,'Marketing',65000);
SELECT MAX(Salary) FROM EmployeeSalaries WHERE Department = 'Marketing';
What is the average price of Italian paintings sold after 2010?
CREATE TABLE Artworks (id INT,name TEXT,artist TEXT,year INT,price FLOAT); INSERT INTO Artworks (id,name,artist,year,price) VALUES (1,'Painting1','Artist1',2005,5000.00),(2,'Painting2','Artist2',2012,8000.00),(3,'Painting3','Artist3',2018,9000.00);
SELECT AVG(price) FROM Artworks WHERE artist IS NOT NULL AND year > 2010 AND country = 'Italy';
Create a table 'waste_generation' with columns id, region, year, and metric
CREATE TABLE waste_generation (id INT PRIMARY KEY,region VARCHAR(50),year INT,metric DECIMAL(5,2));
CREATE TABLE waste_generation ( id INT PRIMARY KEY, region VARCHAR(50), year INT, metric DECIMAL(5,2));
What is the total number of mental health parity violations in California?
CREATE TABLE mental_health_parity_state (state VARCHAR(2),violations INT); INSERT INTO mental_health_parity_state (state,violations) VALUES ('CA',22),('NY',18),('TX',30);
SELECT state, SUM(violations) FROM mental_health_parity_state WHERE state = 'CA' GROUP BY state;
What is the total number of vehicles in the 'fleet' table that were added in the last 2 years?
CREATE TABLE fleet (id INT,type TEXT,year INT); INSERT INTO fleet (id,type,year) VALUES (1,'bus',2020),(2,'bus',2018),(3,'tram',2019),(4,'train',2017);
SELECT COUNT(*) as count FROM fleet WHERE year >= 2020;
What is the minimum donation amount for each cause?
CREATE TABLE Donors (DonorID INT,DonorName TEXT,DonationAmount DECIMAL(10,2),Cause TEXT);
SELECT Cause, MIN(DonationAmount) as MinDonation FROM Donors GROUP BY Cause;
Maximum fairness score for AI models submitted by Indigenous contributors?
CREATE TABLE ai_fairness (model_name TEXT,fairness_score INTEGER,contributor_ethnicity TEXT); INSERT INTO ai_fairness (model_name,fairness_score,contributor_ethnicity) VALUES ('ModelX',95,'Indigenous'),('ModelY',88,'African American'),('ModelZ',98,'Asian'),('ModelW',76,'Indigenous');
SELECT MAX(fairness_score) FROM ai_fairness WHERE contributor_ethnicity = 'Indigenous';
Show the total budget allocation and average rating for public services in each city.
CREATE TABLE public_services (id INT PRIMARY KEY,service VARCHAR(255),location VARCHAR(255),budget DECIMAL(10,2),provider VARCHAR(255)); CREATE TABLE public_feedback (id INT PRIMARY KEY,city VARCHAR(255),service VARCHAR(255),rating INT,comment TEXT);
SELECT p.location, AVG(pf.rating) as avg_rating, SUM(p.budget) as total_budget FROM public_services p INNER JOIN public_feedback pf ON p.service = pf.service GROUP BY p.location;
What is the average word count for articles in 'category4'?
CREATE TABLE articles (id INT,title VARCHAR(50),word_count INT,category VARCHAR(20)); INSERT INTO articles (id,title,word_count,category) VALUES (1,'Article1',500,'category1'),(2,'Article2',750,'category4'),(3,'Article3',300,'category3');
SELECT AVG(word_count) FROM articles WHERE category = 'category4'
What are the names and types of all containers in the shipping_container table?
CREATE TABLE shipping_container (id INT PRIMARY KEY,name VARCHAR(255),container_type VARCHAR(255));
SELECT name, container_type FROM shipping_container;
What is the maximum number of wins for players in the "Cybernetic Showdown" game who are from the European region?
CREATE TABLE PlayerWins (PlayerID INT,GameName VARCHAR(20),Wins INT,Region VARCHAR(20)); INSERT INTO PlayerWins (PlayerID,GameName,Wins,Region) VALUES (1001,'Cybernetic Showdown',12,'Europe'),(1002,'Cybernetic Showdown',15,'North America'),(1003,'Cybernetic Showdown',8,'Asia');
SELECT MAX(Wins) FROM PlayerWins WHERE GameName = 'Cybernetic Showdown' AND Region = 'Europe';
What is the market capitalization of digital assets per region?
CREATE TABLE region (id INT,name VARCHAR(255)); INSERT INTO region VALUES (1,'North America'),(2,'Asia'),(3,'Europe'); CREATE TABLE digital_asset (id INT,name VARCHAR(255),region_id INT,market_cap DECIMAL(10,2)); INSERT INTO digital_asset VALUES (1,'AssetA',1,1000000),(2,'AssetB',2,2000000),(3,'AssetC',3,3000000);
SELECT region.name AS region, SUM(digital_asset.market_cap) AS market_cap FROM digital_asset JOIN region ON digital_asset.region_id = region.id GROUP BY region.name;
Delete all fish records from the 'FishFarming' table where the 'species' is 'Tilapia'
CREATE TABLE FishFarming (id INT,species VARCHAR(20),weight FLOAT,farm_location VARCHAR(30));
DELETE FROM FishFarming WHERE species = 'Tilapia';
Insert a new renewable energy source (wind) into the renewables table, and assign it a name, production value, and creation timestamp.
CREATE TABLE renewables (id INT,name VARCHAR(50),type VARCHAR(50),production FLOAT,created_at TIMESTAMP);
INSERT INTO renewables (name, type, production, created_at) VALUES ('Wind Farm 1', 'wind', 5000000, '2022-01-01 00:00:00');
Calculate the total water consumption for each unique treatment type in 'WaterTreatmentPlants' table
CREATE TABLE WaterTreatmentPlants (plant_id INT,location VARCHAR(50),treatment_type VARCHAR(20),daily_consumption INT);
SELECT treatment_type, SUM(daily_consumption) FROM WaterTreatmentPlants GROUP BY treatment_type;
What is the total number of green buildings by building type?
CREATE TABLE green_buildings (city VARCHAR(50),building_type VARCHAR(50),num_buildings INT); INSERT INTO green_buildings (city,building_type,num_buildings) VALUES ('NYC','Residential',1000),('NYC','Commercial',2000),('LA','Residential',1500),('LA','Commercial',2500);
SELECT building_type, SUM(num_buildings) FROM green_buildings GROUP BY building_type;
List the top 2 regions with the highest percentage of cultural competency trainings conducted in languages other than English.
CREATE TABLE CulturalCompetencyTrainings (Region VARCHAR(20),Language VARCHAR(20),Count INT); INSERT INTO CulturalCompetencyTrainings (Region,Language,Count) VALUES ('Northeast','Spanish',50),('Northeast','French',25),('Northeast','Mandarin',30),('Southeast','Spanish',75),('Southeast','French',50),('Southeast','Hmong',25),('Midwest','Spanish',100),('Midwest','French',75),('Midwest','Somali',50),('West','Spanish',125),('West','French',100),('West','Tagalog',75);
SELECT Region, MAX(Percentage) FROM (SELECT Region, (SUM(CASE WHEN Language <> 'English' THEN Count ELSE 0 END) / SUM(Count)) * 100 AS Percentage FROM CulturalCompetencyTrainings GROUP BY Region) AS LanguagePercentages GROUP BY Region ORDER BY Percentage DESC LIMIT 2;
What is the average age of players who play games on PC in Japan?
CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),Country VARCHAR(20),PC BOOLEAN); INSERT INTO Players (PlayerID,Age,Gender,Country,PC) VALUES (1,25,'Male','Japan',TRUE),(2,30,'Female','Canada',FALSE),(3,35,'Female','Mexico',FALSE),(4,15,'Male','Japan',TRUE),(5,45,'Male','Japan',TRUE);
SELECT AVG(Age) FROM Players WHERE Players.Country = 'Japan' AND Players.PC = TRUE;
What are the most common military aircraft types in South America?
CREATE TABLE SouthAmericaMilitaryAircraftTypes (Type VARCHAR(50),Quantity INT); INSERT INTO SouthAmericaMilitaryAircraftTypes (Type,Quantity) VALUES ('Fighter',1000),('Transport',800),('Helicopter',700),('Drone',500),('Bomber',300);
SELECT Type, Quantity, RANK() OVER (ORDER BY Quantity DESC) as Rank FROM SouthAmericaMilitaryAircraftTypes;
Find the number of times a specific IoT sensor (SensorID = 5) in 'Field5' had temperature spikes in the last month.
CREATE TABLE SensorData (ID INT,SensorID INT,Timestamp DATETIME,Temperature FLOAT); CREATE VIEW LastMonthSensorData AS SELECT * FROM SensorData WHERE Timestamp BETWEEN DATEADD(month,-1,GETDATE()) AND GETDATE(); CREATE VIEW Field5Sensors AS SELECT * FROM SensorData WHERE FieldID = 5; CREATE VIEW Field5LastMonthSensorData AS SELECT * FROM LastMonthSensorData WHERE SensorData.SensorID = Field5Sensors.SensorID;
SELECT COUNT(*) OVER (PARTITION BY SensorID ORDER BY Timestamp ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) + 1 AS TemperatureSpikeCount FROM Field5LastMonthSensorData WHERE SensorID = 5 AND Temperature > 30.0;
Update the founding year of the company DEF to 2008 in the 'company_founding_data' table
CREATE TABLE company_founding_data (company_name VARCHAR(50),founding_year INT);
UPDATE company_founding_data SET founding_year = 2008 WHERE company_name = 'DEF';
Determine the total production volume for wells in the Gulf of Mexico and the North Sea
CREATE TABLE wells (well_id INT,well_name VARCHAR(50),production_volume FLOAT,location VARCHAR(50)); INSERT INTO wells VALUES (1,'Well A',1000,'Gulf of Mexico'); INSERT INTO wells VALUES (2,'Well B',1500,'Alaska North Slope'); INSERT INTO wells VALUES (3,'Well C',1200,'North Sea'); INSERT INTO wells VALUES (4,'Well D',800,'Gulf of Mexico');
SELECT location, SUM(production_volume) FROM wells WHERE location IN ('Gulf of Mexico', 'North Sea') GROUP BY location;
What are the categories of programs with a budget over $15,000?
CREATE TABLE Programs (ProgramID INT,Category VARCHAR(50),Budget DECIMAL(10,2)); INSERT INTO Programs (ProgramID,Category,Budget) VALUES (1,'Education',18000.00),(2,'Health',12000.00),(3,'Environment',20000.00);
SELECT Category FROM Programs WHERE Budget > 15000.00;
What is the average revenue per user (ARPU) for each game genre?
CREATE TABLE games (id INT,genre VARCHAR(255),revenue INT); INSERT INTO games (id,genre,revenue) VALUES (1,'FPS',100000),(2,'RPG',200000),(3,'FPS',150000);
SELECT genre, AVG(revenue) OVER (PARTITION BY genre) AS ARPU FROM games ORDER BY ARPU DESC;
How many public transportation trips were taken by people with disabilities in London in the last 6 months?
CREATE TABLE transit_trips_uk (id INT,disability TEXT,trip_date DATE,city TEXT,country TEXT); INSERT INTO transit_trips_uk (id,disability,trip_date,city,country) VALUES (1,'yes','2023-02-01','London','UK'),(2,'no','2023-02-02','Manchester','UK'),(3,'yes','2023-01-01','London','UK');
SELECT SUM(trip_count) FROM transit_trips_uk WHERE disability = 'yes' AND city = 'London' AND country = 'UK' AND trip_date >= DATEADD(month, -6, GETDATE());
Which mines have a higher proportion of contractors compared to full-time employees?
CREATE TABLE mines (id INT,name TEXT,location TEXT,total_employees INT,full_time_employees INT,contractors INT); INSERT INTO mines (id,name,location,total_employees,full_time_employees,contractors) VALUES (1,'Golden Mine','Colorado,USA',300,200,100),(2,'Silver Ridge','Nevada,USA',400,300,100),(3,'Bronze Basin','Utah,USA',500,400,100);
SELECT name FROM mines WHERE contractors > (full_time_employees * 1.0) * (SELECT AVG(contractors / full_time_employees) FROM mines)
What is the average budget spent on ethical AI initiatives by companies in the US?
CREATE TABLE Companies (id INT,name TEXT,country TEXT,budget_ethical_ai FLOAT); INSERT INTO Companies (id,name,country,budget_ethical_ai) VALUES (1,'TechCo','USA',500000),(2,'GreenTech','USA',750000),(3,'EthicalLabs','USA',300000);
SELECT AVG(budget_ethical_ai) FROM Companies WHERE country = 'USA';
What's the total donation amount per donor type?
CREATE TABLE DonorType (DonorTypeID INT,DonorType VARCHAR(20)); INSERT INTO DonorType (DonorTypeID,DonorType) VALUES (1,'Individual'),(2,'Corporate'),(3,'Foundation'); CREATE TABLE Donations (DonationID INT,DonorID INT,DonationAmount DECIMAL(10,2),DonorTypeID INT); INSERT INTO Donations (DonationID,DonorID,DonationAmount,DonorTypeID) VALUES (1,1001,50.00,1),(2,1002,200.00,1),(3,2001,300.00,2),(4,3001,5000.00,3);
SELECT dt.DonorType, SUM(d.DonationAmount) AS TotalDonationAmount FROM DonorType dt JOIN Donations d ON dt.DonorTypeID = d.DonorTypeID GROUP BY dt.DonorType;
Summarize the number of regulatory frameworks implemented in China and India.
CREATE TABLE regulatory_frameworks (id INT,name VARCHAR(255),country VARCHAR(255),implementation_date DATE); INSERT INTO regulatory_frameworks (id,name,country,implementation_date) VALUES (1,'Framework 1','China','2020-05-01'),(2,'Framework 2','India','2021-02-15');
SELECT COUNT(*) FROM regulatory_frameworks WHERE country IN ('China', 'India');
Which organizations have the most volunteers?
CREATE TABLE organization (id INT PRIMARY KEY,name VARCHAR(255));CREATE TABLE volunteer (id INT PRIMARY KEY,organization_id INT);
SELECT o.name, COUNT(v.id) AS total_volunteers FROM organization o JOIN volunteer v ON o.id = v.organization_id GROUP BY o.id ORDER BY total_volunteers DESC LIMIT 10;
Update the budget for the 'Deaf and Hard of Hearing' support program in the 'SupportPrograms' table.
CREATE TABLE Regions (RegionID INT,RegionName VARCHAR(50)); CREATE TABLE SupportServices (ServiceID INT,ServiceName VARCHAR(50),ServiceType VARCHAR(50),Budget DECIMAL(10,2)); CREATE TABLE SupportPrograms (ProgramID INT,ProgramName VARCHAR(50),Budget DECIMAL(10,2),RegionID INT,ServiceID INT); INSERT INTO Regions (RegionID,RegionName) VALUES (1,'Northeast'),(2,'Southeast'),(3,'Midwest'),(4,'South'),(5,'West'); INSERT INTO SupportServices (ServiceID,ServiceName,ServiceType,Budget) VALUES (1,'ASL Interpreter','SignLanguage',15000),(2,'Wheelchair Ramp','PhysicalAccess',8000),(3,'Braille Materials','VisualAssistance',12000),(4,'Assistive Listening Devices','AuditoryAssistance',10000); INSERT INTO SupportPrograms (ProgramID,ProgramName,Budget,RegionID,ServiceID) VALUES (1,'Braille Materials',12000,1,3),(2,'Low Vision Aids',15000,1,4),(3,'Color Contrast Software',9000,2,4),(4,'Screen Magnifiers',11000,2,4),(5,'Deaf and Hard of Hearing',13000,3,1);
UPDATE SupportPrograms SET Budget = 14000 WHERE ProgramName = 'Deaf and Hard of Hearing';
List the unique species names for all species with a higher ID than the average species ID.
CREATE TABLE Species(species_id INT,species_name TEXT); INSERT INTO Species (species_id,species_name) VALUES (1,'Eagle'),(2,'Wolf'),(3,'Bear'),(4,'Fox'),(5,'Owl');
SELECT DISTINCT species_name FROM Species WHERE species_id > (SELECT AVG(species_id) FROM Species);
What types of AI data are used in the 'AI Artist' application?
CREATE TABLE ai_data (id INT,name VARCHAR(50),type VARCHAR(50),application_id INT); INSERT INTO ai_data (id,name,type,application_id) VALUES (3,'Audios','Training',3),(4,'Videos','Testing',3);
SELECT ai_data.name, ai_data.type FROM ai_data INNER JOIN creative_application ON ai_data.application_id = creative_application.id WHERE creative_application.name = 'AI Artist';
What is the average time to resolve security incidents for each country?
CREATE TABLE incident_resolution (id INT,country VARCHAR(50),resolution_time INT); INSERT INTO incident_resolution (id,country,resolution_time) VALUES (1,'USA',120),(2,'Canada',150),(3,'Mexico',180);
SELECT country, AVG(resolution_time) as avg_resolution_time FROM incident_resolution GROUP BY country;
What is the total quantity of sustainable materials used by companies in the 'Europe' region?
CREATE TABLE Companies (id INT,name VARCHAR(255),region VARCHAR(255)); INSERT INTO Companies (id,name,region) VALUES (1,'CompanyA','Asia-Pacific'),(2,'CompanyB','Europe'),(3,'CompanyC','Asia-Pacific'); CREATE TABLE Materials (id INT,company_id INT,material VARCHAR(255),quantity INT); INSERT INTO Materials (id,company_id,material,quantity) VALUES (1,1,'Organic cotton',500),(2,1,'Recycled polyester',300),(3,2,'Organic linen',400),(4,3,'Organic cotton',600),(5,3,'Tencel',700);
SELECT SUM(Materials.quantity) FROM Companies JOIN Materials ON Companies.id = Materials.company_id WHERE Companies.region = 'Europe';
Update the last name of member with ID 1 to 'Smith'.
CREATE TABLE Members (MemberID INT,FirstName VARCHAR(50),LastName VARCHAR(50)); INSERT INTO Members (MemberID,FirstName,LastName) VALUES (1,'John','Doe'); INSERT INTO Members (MemberID,FirstName,LastName) VALUES (2,'Jane','Doe');
UPDATE Members SET LastName = 'Smith' WHERE MemberID = 1;
How many cultural competency trainings were conducted in the year 2020?
CREATE TABLE trainings (training_id INT,training_name VARCHAR(50),training_year INT,location VARCHAR(50)); INSERT INTO trainings (training_id,training_name,training_year,location) VALUES (1,'Cultural Competency 101',2019,'New York'),(2,'Cultural Competency for Healthcare',2020,'Chicago'),(3,'Advanced Cultural Competency',2021,'Los Angeles');
SELECT COUNT(training_id) FROM trainings WHERE training_year = 2020 AND training_name LIKE '%Cultural%';
What is the average age of immigrants who have been in the country for less than 5 years, by state?
CREATE TABLE immigrants (id INT PRIMARY KEY,state VARCHAR(2),age INT,years_in_country INT); INSERT INTO immigrants (id,state,age,years_in_country) VALUES (1,'CA',30,3);
SELECT AVG(age) FROM immigrants WHERE years_in_country < 5 GROUP BY state;
What is the maximum electric range for electric vehicles in the 'vehicle_specs' table?
CREATE TABLE vehicle_specs (make VARCHAR(50),model VARCHAR(50),year INT,electric_range INT);
SELECT MAX(electric_range) FROM vehicle_specs WHERE make = 'Tesla' AND electric_range IS NOT NULL;
What is the average budget of all government departments in the city of New York in 2021?
CREATE TABLE department_budgets (id INT,city VARCHAR,department VARCHAR,year INT,budget FLOAT); INSERT INTO department_budgets (id,city,department,year,budget) VALUES (1,'New York','Education',2021,100000.00),(2,'New York','Health',2021,150000.00);
SELECT AVG(budget) FROM department_budgets WHERE city = 'New York' AND year = 2021;
What is the maximum salary of a worker in the 'Automotive' industry in the 'South' region?
CREATE TABLE worker_salaries (id INT,region VARCHAR(255),industry VARCHAR(255),salary DECIMAL(10,2));
SELECT MAX(salary) FROM worker_salaries WHERE region = 'South' AND industry = 'Automotive';
Delete public outreach events for site 987
CREATE TABLE outreach_events (id INT PRIMARY KEY,site_id INT,event_type VARCHAR(50),date DATE,attendance INT);
DELETE FROM outreach_events WHERE site_id = 987;
Who are the top 3 bus drivers with the highest total fares collected?
CREATE TABLE drivers (driver_id varchar(255),driver_name varchar(255),total_fares decimal(10,2)); INSERT INTO drivers (driver_id,driver_name,total_fares) VALUES ('D1','John Doe',5000.00),('D2','Jane Smith',6000.00),('D3','Mike Johnson',7000.00),('D4','Sara Brown',8000.00);
SELECT driver_name, total_fares FROM drivers ORDER BY total_fares DESC LIMIT 3;
What is the average size of sharks in the Atlantic Ocean?
CREATE TABLE shark_sizes (id INT,species TEXT,size FLOAT,region TEXT);
SELECT AVG(size) FROM shark_sizes WHERE region = 'Atlantic Ocean';
What is the average production rate for wells in each location, for locations with more than one well?
CREATE TABLE wells (id INT,driller VARCHAR(255),well VARCHAR(255),location VARCHAR(255),production_rate FLOAT); INSERT INTO wells (id,driller,well,location,production_rate) VALUES (1,'DrillerA','WellA','Gulf of Mexico',1000),(2,'DrillerB','WellB','North Sea',1500),(3,'DrillerA','WellC','Gulf of Mexico',1200),(4,'DrillerC','WellD','North Sea',1500),(5,'DrillerB','WellE','North Sea',1000),(6,'DrillerE','WellF','South China Sea',1800),(7,'DrillerF','WellG','South China Sea',1200),(8,'DrillerE','WellH','South China Sea',1100),(9,'DrillerF','WellI','South China Sea',2700),(10,'DrillerA','WellJ','Gulf of Mexico',1600);
SELECT location, AVG(production_rate) FROM wells GROUP BY location HAVING COUNT(*) > 1;
Display total monthly revenue for each restaurant and the overall company revenue, including all restaurants.
CREATE TABLE Sales (SaleID int,RestaurantID int,SaleDate date,SaleAmount numeric(10,2)); INSERT INTO Sales (SaleID,RestaurantID,SaleDate,SaleAmount) VALUES (1,1,'2021-01-01',5000); INSERT INTO Sales (SaleID,RestaurantID,SaleDate,SaleAmount) VALUES (2,1,'2021-01-02',6000); INSERT INTO Sales (SaleID,RestaurantID,SaleDate,SaleAmount) VALUES (3,2,'2021-01-01',7000); INSERT INTO Sales (SaleID,RestaurantID,SaleDate,SaleAmount) VALUES (4,2,'2021-01-02',8000); CREATE TABLE Restaurants (RestaurantID int,RestaurantName varchar(50),City varchar(50)); INSERT INTO Restaurants (RestaurantID,RestaurantName,City) VALUES (1,'The Green Garden','San Francisco'); INSERT INTO Restaurants (RestaurantID,RestaurantName,City) VALUES (2,'Healthy Bites','Los Angeles');
SELECT R.RestaurantName, DATE_TRUNC('month', S.SaleDate) AS Month, SUM(S.SaleAmount) AS TotalRevenue FROM Sales S JOIN Restaurants R ON S.RestaurantID = R.RestaurantID GROUP BY R.RestaurantName, Month;
Which military equipment was sold in the first quarter of 2021?
CREATE TABLE equipment_sales (id INT,equipment_name VARCHAR(255),sale_date DATE); INSERT INTO equipment_sales (id,equipment_name,sale_date) VALUES (1,'Tank A','2021-01-01'),(2,'Helicopter B','2021-02-01'),(3,'Drone C','2021-03-01'),(4,'Jeep D','2021-04-01'),(5,'Ship E','2021-05-01');
SELECT equipment_name FROM equipment_sales WHERE QUARTER(sale_date) = 1 AND YEAR(sale_date) = 2021;
How many climate finance projects are in 'Asia' that started after 2000?
CREATE TABLE climate_finance (project_id INT,project_name VARCHAR(255),location VARCHAR(255),start_date DATE,end_date DATE,total_cost DECIMAL(10,2));
SELECT COUNT(*) FROM climate_finance WHERE location = 'Asia' AND start_date > '2000-01-01';
What is the average ticket price for each team?
CREATE TABLE teams (team_id INT,team_name VARCHAR(50)); INSERT INTO teams (team_id,team_name) VALUES (1,'TeamA'),(2,'TeamB'); CREATE TABLE ticket_sales (team_id INT,price DECIMAL(5,2)); INSERT INTO ticket_sales (team_id,price) VALUES (1,50.00),(1,60.00),(2,40.00),(2,35.00);
SELECT t.team_name, AVG(ticket_sales.price) as avg_price FROM ticket_sales JOIN teams ON ticket_sales.team_id = teams.team_id GROUP BY t.team_name;
Maximum CO2 emissions from a single industrial process
CREATE TABLE industrial_processes (id INT,process_name VARCHAR(255),sector VARCHAR(255),country VARCHAR(255),year INT,co2_emissions FLOAT);
SELECT MAX(co2_emissions) FROM industrial_processes;
Delete all transactions made by user 'JohnDoe' in the ShariahCompliantTransactions table.
CREATE TABLE ShariahCompliantTransactions (transactionID INT,userID VARCHAR(20),transactionAmount DECIMAL(10,2),transactionDate DATE); INSERT INTO ShariahCompliantTransactions (transactionID,userID,transactionAmount,transactionDate) VALUES (1,'JohnDoe',500.00,'2022-01-01'),(2,'JaneDoe',300.00,'2022-01-02');
DELETE FROM ShariahCompliantTransactions WHERE userID = 'JohnDoe';
What is the average time taken to resolve citizen complaints in Ward 9?
CREATE TABLE CitizenComplaints (Ward INT,ComplaintID INT,ComplaintDate DATE,ResolutionDate DATE); INSERT INTO CitizenComplaints (Ward,ComplaintID,ComplaintDate,ResolutionDate) VALUES (9,100,'2021-01-01','2021-01-10'),(9,200,'2021-02-01','2021-02-15'),(9,300,'2021-03-01','2021-03-20'),(9,400,'2021-04-01',NULL);
SELECT AVG(DATEDIFF(ResolutionDate, ComplaintDate)) FROM CitizenComplaints WHERE Ward = 9 AND ResolutionDate IS NOT NULL;
How many professional development courses were completed by teachers in 2022?
CREATE TABLE regions (region VARCHAR(20)); INSERT INTO regions (region) VALUES ('North'),('South'),('East'),('West'); CREATE TABLE courses (course_id INT,teacher_id INT,course_name VARCHAR(50),completion_date DATE); INSERT INTO courses (course_id,teacher_id,course_name,completion_date) VALUES (6,6,'PD6','2022-01-01'),(7,7,'PD7','2022-03-15'),(8,8,'PD8','2022-12-31');
SELECT COUNT(*) FROM courses JOIN regions ON courses.teacher_id = (SELECT teacher_id FROM teachers WHERE teachers.region = 'West') WHERE YEAR(completion_date) = 2022 AND course_name LIKE 'PD%';
How many donations have been made in each country?
CREATE TABLE Donations (DonationID INT,DonorID INT,DonationDate DATE,DonationAmount DECIMAL(10,2),DonationCountry VARCHAR(50)); CREATE TABLE Donors (DonorID INT,DonorName VARCHAR(50),DonationType VARCHAR(50));
SELECT DonationCountry, COUNT(*) FROM Donations GROUP BY DonationCountry;