instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What was the average citizen feedback score for District C and D in 2022?
CREATE TABLE CitizenFeedback (District VARCHAR(10),Year INT,Score INT); INSERT INTO CitizenFeedback VALUES ('District C',2022,8),('District C',2022,9),('District D',2022,7),('District D',2022,6);
SELECT AVG(Score) FROM CitizenFeedback WHERE District IN ('District C', 'District D') AND Year = 2022;
Increase the price of Promethium in Canada by 15% for 2022 and later.
CREATE TABLE prices (year INT,element VARCHAR(10),country VARCHAR(10),price DECIMAL(5,2)); INSERT INTO prices (year,element,country,price) VALUES (2017,'Promethium','Canada',25.5),(2018,'Promethium','Canada',26.2),(2019,'Promethium','Canada',28.1),(2020,'Promethium','Canada',30.5),(2021,'Promethium','Canada',32.8),(2022,'Promethium','Canada',35.2);
UPDATE prices SET price = price * 1.15 WHERE element = 'Promethium' AND country = 'Canada' AND year >= 2022;
Insert new records for the rare earth elements gadolinium and terbium into the production table
CREATE TABLE production (id INT PRIMARY KEY,element VARCHAR(10),quantity INT,production_date DATE);
INSERT INTO production (element, quantity, production_date) VALUES ('gadolinium', 150, '2015-03-17'), ('terbium', 200, '2016-06-23');
What is the minimum energy production cost of wind farms in Spain?
CREATE TABLE wind_farm_costs (id INT,name TEXT,country TEXT,energy_production_cost FLOAT); INSERT INTO wind_farm_costs (id,name,country,energy_production_cost) VALUES (1,'Las Tiesas','Spain',0.045),(2,'Eolo','Spain',0.050);
SELECT MIN(energy_production_cost) FROM wind_farm_costs WHERE country = 'Spain';
Show the number of workers in factories that have passed the ethical labor audit.
CREATE TABLE factories (id INT,name TEXT,audit_passed BOOLEAN); CREATE TABLE workers (factory_id INT,worker_id INT); INSERT INTO factories VALUES (1,'Factory A',TRUE),(2,'Factory B',FALSE); INSERT INTO workers VALUES (1,1),(1,2),(2,3);
SELECT COUNT(DISTINCT workers.worker_id) FROM workers INNER JOIN factories ON workers.factory_id = factories.id WHERE factories.audit_passed = TRUE;
What is the total quantity of product A sold in all stores?
CREATE TABLE WAREHOUSE (store_id INT,product VARCHAR(255),quantity INT); INSERT INTO WAREHOUSE (store_id,product,quantity) VALUES (1,'Product A',200),(2,'Product A',300),(3,'Product B',150);
SELECT SUM(quantity) FROM WAREHOUSE WHERE product = 'Product A';
What is the average severity of vulnerabilities found in the last quarter for each product?
CREATE TABLE vulnerabilities (id INT,timestamp TIMESTAMP,product VARCHAR(255),vulnerability_severity VARCHAR(255)); INSERT INTO vulnerabilities (id,timestamp,product,vulnerability_severity) VALUES (1,'2020-10-01 12:00:00','Product A','High'),(2,'2020-11-02 10:30:00','Product B','Medium');
SELECT product, AVG(case when vulnerability_severity = 'High' then 3 when vulnerability_severity = 'Medium' then 2 when vulnerability_severity = 'Low' then 1 else 0 end) as avg_severity FROM vulnerabilities WHERE timestamp >= NOW() - INTERVAL 3 MONTH GROUP BY product;
What is the total number of vulnerabilities found in the 'Finance' department?
CREATE TABLE department (id INT,name VARCHAR(255)); INSERT INTO department (id,name) VALUES (1,'Finance'),(2,'IT'); CREATE TABLE vulnerabilities (id INT,department_id INT,severity VARCHAR(255)); INSERT INTO vulnerabilities (id,department_id,severity) VALUES (1,1,'High'),(2,1,'Medium'),(3,2,'Low');
SELECT COUNT(*) FROM vulnerabilities WHERE department_id = (SELECT id FROM department WHERE name = 'Finance');
What is the average number of trips per day on public transportation in Tokyo and Seoul?
CREATE TABLE daily_trips (trip_id INT,city VARCHAR(20),trips INT,day DATE); INSERT INTO daily_trips (trip_id,city,trips,day) VALUES (1,'Tokyo',500000,'2022-01-01'),(2,'Tokyo',600000,'2022-01-02'),(3,'Seoul',400000,'2022-01-01'),(4,'Seoul',300000,'2022-01-02');
SELECT city, AVG(trips) FROM daily_trips GROUP BY city, day ORDER BY day;
What is the total number of electric vehicle sales for each city?
CREATE TABLE electric_vehicles (id INT,city_id INT,model VARCHAR(50),year INT,sales INT); INSERT INTO electric_vehicles (id,city_id,model,year,sales) VALUES (4,3,'Audi e-Tron',2022,40000); INSERT INTO electric_vehicles (id,city_id,model,year,sales) VALUES (5,3,'Hyundai Kona Electric',2021,25000);
SELECT city_id, SUM(sales) FROM electric_vehicles GROUP BY city_id;
How many men's garments were sold in Mexico in Q4 2020?
CREATE TABLE mexico_mens_garments (garment_type VARCHAR(255),sales_quantity INT,quarter INT,year INT); INSERT INTO mexico_mens_garments (garment_type,sales_quantity,quarter,year) VALUES ('Pants',400,4,2020),('Shirt',500,4,2020);
SELECT SUM(sales_quantity) FROM mexico_mens_garments WHERE quarter = 4 AND year = 2020;
What is the total number of workers employed by unions in the 'manufacturing' sector?
CREATE TABLE unions (id INT,sector VARCHAR(20)); INSERT INTO unions (id,sector) VALUES (1,'manufacturing'),(2,'technology');
SELECT COUNT(*) FROM unions WHERE sector = 'manufacturing';
What is the total number of vehicles sold in 'California' and 'Texas' in the 'sales' table?
CREATE TABLE sales (region VARCHAR(10),vehicle_count INT); INSERT INTO sales VALUES ('California',5000),('Texas',6000),('Florida',4000),('California',5500),('Texas',6500);
SELECT SUM(vehicle_count) FROM sales WHERE region IN ('California', 'Texas');
What is the maximum number of daily visitors for digital exhibitions in Mexico in 2022?
CREATE TABLE Digital_Exhibitions_Mexico (id INT,year INT,visitors_per_day INT);
SELECT MAX(visitors_per_day) FROM Digital_Exhibitions_Mexico WHERE year = 2022;
What was the recycling rate for 'Organic' and 'Electronic' waste types in 'UrbanArea' in 2020?
CREATE TABLE recycling_rates(waste_type VARCHAR(50),location VARCHAR(50),year INT,rate FLOAT); INSERT INTO recycling_rates(waste_type,location,year,rate) VALUES('Organic','UrbanArea',2020,0.6),('Organic','UrbanArea',2019,0.55),('Electronic','UrbanArea',2020,0.4),('Electronic','UrbanArea',2019,0.35);
SELECT waste_type, rate FROM recycling_rates WHERE location = 'UrbanArea' AND year = 2020 AND waste_type IN ('Organic', 'Electronic');
What is the total number of algorithms in the 'AI_Safety' schema that have a complexity score lower than 5 and an accuracy score over 0.9?
CREATE SCHEMA AI_Safety;CREATE TABLE Algorithms (algo_id INT,complexity_score INT,accuracy_score FLOAT); INSERT INTO AI_Safety.Algorithms (algo_id,complexity_score,accuracy_score) VALUES (1,6,0.95),(2,4,0.9),(3,7,0.8);
SELECT COUNT(*) FROM AI_Safety.Algorithms WHERE complexity_score < 5 AND accuracy_score > 0.9;
What is the average community development initiative budget per country, ordered by the largest budget?
CREATE TABLE Country (CountryID INT,CountryName VARCHAR(100)); INSERT INTO Country VALUES (1,'Canada'),(2,'Mexico'),(3,'Brazil'); CREATE TABLE CommunityDevelopment (ProjectID INT,CountryID INT,Budget DECIMAL(10,2)); INSERT INTO CommunityDevelopment VALUES (1,1,50000),(2,1,75000),(3,2,100000),(4,3,125000),(5,3,150000);
SELECT CountryName, AVG(Budget) AS AvgBudget FROM Country JOIN CommunityDevelopment ON Country.CountryID = CommunityDevelopment.CountryID GROUP BY CountryName ORDER BY AvgBudget DESC;
What is the percentage of community development projects completed in 'Caribbean' in 2020?
CREATE TABLE community_projects (project_id INT,project_name TEXT,location TEXT,completion_year INT); INSERT INTO community_projects (project_id,project_name,location,completion_year) VALUES (1,'Community Center','Southern Region,Caribbean',2020); INSERT INTO community_projects (project_id,project_name,location,completion_year) VALUES (2,'Park Renovation','Northern Region,Caribbean',2019); INSERT INTO community_projects (project_id,project_name,location,completion_year) VALUES (3,'Library Construction','Caribbean',2020);
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM community_projects WHERE location = 'Caribbean')) FROM community_projects WHERE completion_year = 2020 AND location = 'Caribbean';
What is the success rate of agricultural innovation projects in rural areas of Indonesia?
CREATE TABLE indonesia_projects (project_id INT,project_name VARCHAR(50),location VARCHAR(20),success BOOLEAN); INSERT INTO indonesia_projects (project_id,project_name,location,success) VALUES (1,'Solar Pump Irrigation','rural',true),(2,'Organic Farming Training','urban',true),(3,'Agroforestry Development','rural',false);
SELECT 100.0 * SUM(success) / COUNT(*) FROM indonesia_projects WHERE location = 'rural';
Which community development initiatives in Bangladesh received the most funding in 2020?
CREATE TABLE initiatives (id INT,initiative_name VARCHAR(100),country VARCHAR(50),year INT,funding FLOAT); INSERT INTO initiatives (id,initiative_name,country,year,funding) VALUES (1,'Green Villages','Bangladesh',2018,500000),(2,'Solar Energy for All','Bangladesh',2019,600000),(3,'Water for Life','Bangladesh',2020,700000),(4,'Education for All','Bangladesh',2020,800000);
SELECT initiative_name, MAX(funding) FROM initiatives WHERE country = 'Bangladesh' AND year = 2020 GROUP BY initiative_name;
What is the total number of animals in protected habitats for each region?
CREATE TABLE ProtectedHabitats (id INT,animal_id INT,size FLOAT,region VARCHAR(255)); INSERT INTO ProtectedHabitats (id,animal_id,size,region) VALUES (1,1,5.6,'Africa'),(2,2,3.2,'Asia'),(3,3,7.8,'Africa');
SELECT region, COUNT(animal_id) FROM ProtectedHabitats GROUP BY region;
Which community education programs are associated with habitats that need urgent preservation efforts?
CREATE TABLE habitats (id INT,habitat_name VARCHAR(50),preservation_status VARCHAR(20)); CREATE TABLE education_programs (id INT,habitat_id INT,coordinator_name VARCHAR(50),urgency VARCHAR(10));
SELECT e.coordinator_name FROM education_programs e INNER JOIN habitats h ON e.habitat_id = h.id WHERE h.preservation_status = 'Urgent';
How many arts education programs were funded by 'Montreal Arts Council' in 'Montreal' in 2021, and what was the total funding amount?
CREATE TABLE Education (program_id INT,city VARCHAR(20),funding_source VARCHAR(20),year INT,total_funding DECIMAL(10,2)); INSERT INTO Education (program_id,city,funding_source,year,total_funding) VALUES (1,'Montreal','Montreal Arts Council',2021,12000),(2,'Montreal','Montreal Arts Council',2021,15000);
SELECT COUNT(*), SUM(total_funding) FROM Education WHERE city = 'Montreal' AND funding_source = 'Montreal Arts Council' AND year = 2021;
Insert new records for a community outreach program.
CREATE TABLE Programs (program_id INT,program_name VARCHAR(255),location VARCHAR(255),num_participants INT,impact_assessment DECIMAL(3,2));
INSERT INTO Programs (program_id, program_name, location, num_participants, impact_assessment) VALUES (5, 'Community Outreach', 'Chicago, IL', 35, 8.2);
What is the median hourly wage for construction laborers in Louisiana?
CREATE TABLE la_wages (job VARCHAR(20),hourly_wage FLOAT); INSERT INTO la_wages (job,hourly_wage) VALUES ('Construction laborer',17.4),('Carpenter',21.9),('Electrician',25.6);
SELECT AVG(hourly_wage) FROM la_wages WHERE job = 'Construction laborer';
How many cases were won by attorney Patel in the last 2 years, categorized by practice area?
CREATE TABLE cases (case_id INT,attorney_name VARCHAR(255),win_status BOOLEAN,case_date DATE,practice_area VARCHAR(255)); INSERT INTO cases (case_id,attorney_name,win_status,case_date,practice_area) VALUES (1,'Patel',true,'2019-01-01','Family'),(2,'Thompson',false,'2020-05-15','Civil'),(3,'Garcia',true,'2021-07-20','Criminal'),(4,'Smith',false,'2020-12-31','Family'),(5,'Brown',true,'2020-06-20','Civil');
SELECT practice_area, COUNT(*) FROM cases WHERE attorney_name = 'Patel' AND win_status = true AND case_date >= DATE_SUB(CURRENT_DATE, INTERVAL 2 YEAR) GROUP BY practice_area;
Update the billing rate for an attorney
CREATE TABLE attorneys (id INT,name VARCHAR(50),cases_handled INT,region VARCHAR(50),billable_rate DECIMAL(10,2)); INSERT INTO attorneys (id,name,cases_handled,region,billable_rate) VALUES (1,'John Lee',40,'Northeast',200.00); INSERT INTO attorneys (id,name,cases_handled,region,billable_rate) VALUES (2,'Jane Doe',50,'Southwest',250.00);
UPDATE attorneys SET billable_rate = 225.00 WHERE name = 'John Lee';
Calculate the moving average of chemical waste production for each facility, for the last 6 months.
CREATE TABLE facility_waste (facility_id INT,date DATE,waste_amount FLOAT); INSERT INTO facility_waste (facility_id,date,waste_amount) VALUES (1,'2022-01-01',500),(1,'2022-02-01',550),(1,'2022-03-01',600),(1,'2022-04-01',650),(1,'2022-05-01',700),(1,'2022-06-01',750),(2,'2022-01-01',400),(2,'2022-02-01',450),(2,'2022-03-01',500),(2,'2022-04-01',550),(2,'2022-05-01',600),(2,'2022-06-01',650);
SELECT facility_id, AVG(waste_amount) OVER (PARTITION BY facility_id ORDER BY date ROWS BETWEEN 5 PRECEDING AND CURRENT ROW) as moving_average FROM facility_waste;
Delete all records from the 'equipment' table where the 'equipment_type' is 'tank'
CREATE TABLE equipment (equipment_id INT,equipment_type VARCHAR(20));
DELETE FROM equipment WHERE equipment_type = 'tank';
How much have countries invested in climate communication in Asia?
CREATE TABLE CommInvestment (Country TEXT,Investment_Amount NUMERIC); INSERT INTO CommInvestment (Country,Investment_Amount) VALUES ('China',5000000),('Japan',4000000),('India',3000000);
SELECT SUM(Investment_Amount) FROM CommInvestment WHERE Country IN ('China', 'Japan', 'India') AND Investment_Amount IS NOT NULL;
List the names and funding amounts of the top 3 largest climate finance projects in 2019
CREATE TABLE climate_finance (project_name VARCHAR(100),year INT,funding_amount INT); INSERT INTO climate_finance (project_name,year,funding_amount) VALUES ('Green Energy Transition Fund',2019,5000),('Climate Adaptation for Coastal Communities',2019,3000),('Sustainable Agriculture Investment Program',2019,4000),('Renewable Energy Infrastructure Project',2019,2000),('Clean Transportation Initiative',2019,6000),('Climate Disaster Relief Fund',2019,7000),('Carbon Capture and Storage Project',2019,8000),('Eco-City Development Program',2019,9000),('Climate Research and Innovation Center',2019,10000),('Global Climate Action Alliance',2019,11000);
SELECT project_name, funding_amount FROM climate_finance WHERE year = 2019 ORDER BY funding_amount DESC LIMIT 3;
What is the average budget for climate change mitigation projects in Europe, and which countries have the most mitigation projects?
CREATE TABLE climate_projects_eu (project_name VARCHAR(50),country VARCHAR(50),project_type VARCHAR(50),budget NUMERIC(12,2)); INSERT INTO climate_projects_eu (project_name,country,project_type,budget) VALUES ('Green Cities','Germany','Mitigation',10000.00),('Renewable Energy','France','Mitigation',15000.00),('Carbon Capture','UK','Mitigation',20000.00);
SELECT country, AVG(budget) FROM climate_projects_eu WHERE project_type = 'Mitigation' AND country IN ('Europe') GROUP BY country;
What is the combined attendance of the Climate Summit and the Adaptation Conference?
CREATE TABLE conferences (id INT PRIMARY KEY,name VARCHAR(50),location VARCHAR(50),year INT,attendance INT); INSERT INTO conferences (id,name,location,year,attendance) VALUES (1,'Climate Summit','Paris',2015,40000); INSERT INTO conferences (id,name,location,year,attendance) VALUES (2,'Adaptation Conference','Tokyo',2016,30000);
SELECT SUM(attendance) FROM conferences WHERE name IN ('Climate Summit', 'Adaptation Conference');
What is the average R&D expenditure per clinical trial, ranked by average expenditure?
CREATE TABLE RDExpenses (TrialID int,Department varchar(50),Expenditure decimal(18,2)); INSERT INTO RDExpenses (TrialID,Department,Expenditure) VALUES (1,'Research',1500000.00),(2,'Development',1800000.00),(3,'ClinicalTrials',2500000.00),(4,'Regulatory',1000000.00);
SELECT Department, AVG(Expenditure), ROW_NUMBER() OVER (ORDER BY AVG(Expenditure) DESC) as ExpenseRank FROM RDExpenses GROUP BY Department;
What was the average R&D expenditure for drugs approved in 2019?
CREATE TABLE rd_expenditure (drug_class TEXT,year INTEGER,expenditure INTEGER);
SELECT AVG(expenditure) FROM rd_expenditure WHERE year = 2019 AND status = 'approved';
Find the number of medical research grants, by institution and year.
CREATE TABLE grants (id INT,institution VARCHAR,year INT,amount INT);
SELECT g.institution, g.year, COUNT(g.id) AS num_grants FROM grants g GROUP BY g.institution, g.year;
What is the total number of patients who have had a flu shot in the last 6 months in California?
CREATE TABLE Patients (PatientID INT,FluShot DATE,State TEXT); INSERT INTO Patients (PatientID,FluShot,State) VALUES (1,'2021-08-01','California');
SELECT COUNT(*) FROM Patients WHERE FluShot >= DATEADD(month, -6, GETDATE()) AND State = 'California';
How many startups in each country have a female founder?
CREATE TABLE startup (id INT,name TEXT,country TEXT,founder_gender TEXT); INSERT INTO startup (id,name,country,founder_gender) VALUES (1,'Epsilon Enterprises','USA','Female'); INSERT INTO startup (id,name,country,founder_gender) VALUES (2,'Zeta Ltd','Canada','Male'); INSERT INTO startup (id,name,country,founder_gender) VALUES (3,'Eta Inc','Mexico','Female');
SELECT s.country, COUNT(*) FROM startup s WHERE s.founder_gender = 'Female' GROUP BY s.country;
Identify organic farming research institutions not located in the Midwest.
CREATE TABLE research_institutes (id INT,name VARCHAR(50),type VARCHAR(50),focus VARCHAR(50),location VARCHAR(50)); INSERT INTO research_institutes (id,name,type,focus,location) VALUES (1,'Rodale Institute','Non-profit','Organic farming research','Pennsylvania'); INSERT INTO research_institutes (id,name,type,focus,location) VALUES (2,'Land Institute','Non-profit','Perennial crop research','Kansas'); INSERT INTO research_institutes (id,name,type,focus,location) VALUES (3,'Organic Farming Research Foundation','Non-profit','Organic farming research','California');
SELECT name FROM research_institutes WHERE focus = 'Organic farming research' AND location != 'Midwest';
What are the names and locations of disability services facilities with a rating of 4 or higher?
CREATE TABLE facilities (facility_id INT,facility_name VARCHAR(255),facility_location VARCHAR(255),facility_rating INT);
SELECT facility_name, facility_location FROM facilities WHERE facility_rating >= 4;
What is the number of students who received accommodations by month and accommodation type?
CREATE TABLE Accommodations (StudentID INT,AccommodationType VARCHAR(50),AccommodationDate DATE); INSERT INTO Accommodations (StudentID,AccommodationType,AccommodationDate) VALUES (1,'Sign Language Interpreter','2021-01-01'); CREATE TABLE Students (StudentID INT,StudentName VARCHAR(50),GraduationYear INT); INSERT INTO Students (StudentID,StudentName,GraduationYear) VALUES (1,'Jacob Taylor',2023);
SELECT MONTH(AccommodationDate) as Month, AccommodationType, COUNT(*) as Total FROM Accommodations JOIN Students ON Accommodations.StudentID = Students.StudentID GROUP BY Month, AccommodationType;
Insert a new record into the species table for a fish species found in the Indian Ocean
CREATE TABLE species (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255),population INT,habitat VARCHAR(255));
INSERT INTO species (id, name, type, population, habitat) VALUES (18, 'Parrotfish', 'Fish', 25000, 'Indian Ocean');
What is the average timber volume for each country in tropical rainforests over the last 3 years?
CREATE TABLE country_timber (id INT,country VARCHAR(30),region VARCHAR(20),year INT,volume FLOAT);
SELECT country, region, AVG(volume) as avg_volume FROM country_timber WHERE region = 'Tropical' AND year BETWEEN 2019 AND 2021 GROUP BY country, region;
Insert new data into the 'cosmetic_ingredients' table for a vegan eyeshadow product by brand 'Ara' with ingredients 'Mica', 'Iron Oxide', 'Titanium Dioxide' and 'Zinc Oxide'.
CREATE TABLE cosmetic_ingredients (ingredient_id INT,product_name TEXT,brand_name TEXT,ingredient_type TEXT);
INSERT INTO cosmetic_ingredients (ingredient_id, product_name, brand_name, ingredient_type) VALUES (NULL, 'Vegan Eyeshadow', 'Ara', 'Ingredient'); INSERT INTO cosmetic_ingredients (ingredient_id, product_name, brand_name, ingredient_type, ingredient_name) SELECT ingredient_id, 'Vegan Eyeshadow', 'Ara', 'Ingredient', 'Mica' FROM cosmetic_ingredients WHERE ingredient_name = 'Mica' UNION ALL SELECT NULL, 'Vegan Eyeshadow', 'Ara', 'Ingredient', 'Iron Oxide' UNION ALL SELECT NULL, 'Vegan Eyeshadow', 'Ara', 'Ingredient', 'Titanium Dioxide' UNION ALL SELECT NULL, 'Vegan Eyeshadow', 'Ara', 'Ingredient', 'Zinc Oxide';
Delete all records from the crime_statistics table where the 'crime_type' column is 'Trespassing' and the 'date' column is '2022-05-15'?
CREATE TABLE crime_statistics (crime_type VARCHAR(255),crime_count INT,date DATE); INSERT INTO crime_statistics (crime_type,crime_count,date) VALUES (NULL,NULL,NULL);
DELETE FROM crime_statistics WHERE crime_type = 'Trespassing' AND date = '2022-05-15';
What is the total number of crime incidents reported in each sector, sorted by the number of incidents in descending order?
CREATE TABLE sector (id INT,name TEXT,location TEXT); INSERT INTO sector (id,name,location) VALUES (1,'Sector A','Downtown'),(2,'Sector B','Uptown'); CREATE TABLE incidents (id INT,sector_id INT,type TEXT,timestamp DATETIME); INSERT INTO incidents (id,sector_id,type,timestamp) VALUES (1,1,'Theft','2022-01-01 10:00:00'),(2,2,'Vandalism','2022-01-02 12:00:00');
SELECT sector.name, COUNT(incidents.id) AS incident_count FROM sector LEFT JOIN incidents ON sector.id = incidents.sector_id GROUP BY sector.name ORDER BY incident_count DESC;
What is the 'value' of 'inventory' for item 'DEF456'?
CREATE TABLE inventory (item VARCHAR(50),value FLOAT); INSERT INTO inventory (item,value) VALUES ('ABC123',2000.00),('DEF456',3000.00);
SELECT value FROM inventory WHERE item = 'DEF456';
What is the average investment in sustainable agriculture per country?
CREATE TABLE investments (id INT,country VARCHAR(50),sector VARCHAR(50),amount FLOAT); INSERT INTO investments (id,country,sector,amount) VALUES (1,'Canada','Sustainable Agriculture',500000),(2,'Mexico','Renewable Energy',750000),(3,'Canada','Sustainable Agriculture',600000);
SELECT country, AVG(amount) as avg_investment FROM investments WHERE sector = 'Sustainable Agriculture' GROUP BY country;
What are the names and ranks of all military personnel in country W who were demoted in the year 2019?
CREATE TABLE military_demotions (id INT,name TEXT,country TEXT,rank TEXT,demotion_year INT);INSERT INTO military_demotions (id,name,country,rank,demotion_year) VALUES (1,'John Doe','Country W','Colonel',2019);
SELECT name, rank FROM military_demotions WHERE country = 'Country W' AND demotion_year = 2019;
What is the number of intelligence personnel in each department in the UK government?
CREATE TABLE intelligence_personnel_uk (id INT,department TEXT,position TEXT,country TEXT); INSERT INTO intelligence_personnel_uk (id,department,position,country) VALUES (1,'MI5','Analyst','UK'),(2,'MI6','Agent','UK'),(3,'GCHQ','Engineer','UK');
SELECT i.department, COUNT(i.id) as total_personnel FROM intelligence_personnel_uk i WHERE i.country = 'UK' GROUP BY i.department;
What is the total number of military personnel in the USA and the average salary for each country?
CREATE TABLE military_personnel (id INT,name TEXT,rank TEXT,country TEXT,salary INT); INSERT INTO military_personnel (id,name,rank,country,salary) VALUES (1,'John Doe','Colonel','USA',80000),(2,'Jane Smith','Captain','USA',60000);
SELECT mc.country, AVG(mc.salary) as avg_salary, COUNT(mc.id) as total_personnel FROM military_personnel mc GROUP BY mc.country;
How many programs were held in each month of 2022?
CREATE TABLE programs (program_id INT,program_name VARCHAR(50),program_date DATE);
SELECT EXTRACT(MONTH FROM program_date) AS month, COUNT(*) AS num_programs FROM programs WHERE YEAR(program_date) = 2022 GROUP BY month;
Show the top 5 employees who have been in training the longest, ordered by total training hours in descending order.
CREATE TABLE trainings (training_id INT,emp_id INT,training_hours INT); INSERT INTO trainings (training_id,emp_id,training_hours) VALUES (1,1,10),(2,1,5),(3,2,15),(4,3,20),(5,4,12),(6,2,8);
SELECT emp_id, SUM(training_hours) as total_training_hours FROM trainings GROUP BY emp_id ORDER BY total_training_hours DESC LIMIT 5;
What is the racial and ethnic diversity of the company?
CREATE TABLE employees (id INT,name VARCHAR(255),race VARCHAR(255),ethnicity VARCHAR(255)); INSERT INTO employees (id,name,race,ethnicity) VALUES (1,'John Doe','White','Not Hispanic or Latino'),(2,'Jane Smith','Asian','Not Hispanic or Latino'),(3,'Alice Johnson','Black or African American','Not Hispanic or Latino'),(4,'Bob Brown','Hispanic or Latino','Mexican'),(5,'Charlie Davis','White','Not Hispanic or Latino');
SELECT race, COUNT(*) as num_employees, CONCAT(ROUND(COUNT(*) / (SELECT COUNT(*) FROM employees) * 100, 2), '%') as percent_of_employees FROM employees GROUP BY race;
How many renewable energy projects were completed in Colombia and Peru in 2020 and 2021?
CREATE TABLE latam_renewable_projects (country VARCHAR(20),year INT,num_projects INT); INSERT INTO latam_renewable_projects (country,year,num_projects) VALUES ('Colombia',2020,15),('Colombia',2021,18),('Peru',2020,22),('Peru',2021,25);
SELECT SUM(num_projects) FROM latam_renewable_projects WHERE country IN ('Colombia', 'Peru') AND year BETWEEN 2020 AND 2021;
What is the total energy efficiency savings in USD for the state of Texas in 2020?
CREATE TABLE energy_efficiency (state VARCHAR(20),savings DECIMAL(10,2),year INT); INSERT INTO energy_efficiency (state,savings,year) VALUES ('Texas',500.00,2020),('Texas',750.00,2020),('Texas',600.00,2020);
SELECT SUM(savings) FROM energy_efficiency WHERE state = 'Texas' AND year = 2020;
Identify the total number of offshore drilling platforms in the North Sea and Gulf of Mexico from the 'InfrastructureData' table.
CREATE TABLE InfrastructureData (region VARCHAR(50),country VARCHAR(50),platform_type VARCHAR(50),quantity INT); INSERT INTO InfrastructureData (region,country,platform_type,quantity) VALUES ('North Sea','UK','offshore_drilling',120),('North Sea','Norway','offshore_drilling',150),('Gulf of Mexico','USA','offshore_drilling',200),('Gulf of Mexico','Mexico','offshore_drilling',180),('South China Sea','China','offshore_drilling',130);
SELECT SUM(quantity) FROM InfrastructureData WHERE (region = 'North Sea' AND platform_type = 'offshore_drilling') OR (region = 'Gulf of Mexico' AND platform_type = 'offshore_drilling');
Add a new bus route from 'Chinatown' to 'Airport'
CREATE TABLE bus_routes (route_id INT PRIMARY KEY,start_location TEXT,end_location TEXT);
INSERT INTO bus_routes (route_id, start_location, end_location) VALUES (2, 'Chinatown', 'Airport');
How many labor disputes were there in each factory, by year?
CREATE TABLE labor_disputes (dispute_date DATE,factory VARCHAR(255),dispute_type VARCHAR(255));
SELECT factory, DATE_TRUNC('year', dispute_date) AS dispute_year, COUNT(*) AS num_disputes FROM labor_disputes GROUP BY factory, dispute_year;
What is the average number of posts per user in each region?
CREATE TABLE users (id INT,region VARCHAR(255)); CREATE TABLE posts (id INT,user_id INT,content TEXT); INSERT INTO users (id,region) VALUES (1,'Asia'),(2,'Africa'),(3,'Europe'),(4,'America'); INSERT INTO posts (id,user_id,content) VALUES (1,1,'Hello'),(2,1,'World'),(3,2,'AI'),(4,2,'Data'),(5,3,'Science');
SELECT users.region, AVG(posts.user_id) FROM posts JOIN users ON posts.user_id = users.id GROUP BY users.region;
List the fashion trends of 2021 with sales greater than 1500?
CREATE TABLE trends_2021 (id INT,product VARCHAR(20),sales INT); INSERT INTO trends_2021 (id,product,sales) VALUES (1,'Dress',1200); INSERT INTO trends_2021 (id,product,sales) VALUES (2,'Skirt',1800);
SELECT product FROM trends_2021 WHERE sales > 1500;
What is the percentage of sales by designer?
CREATE TABLE ClothingSales (ItemID INT,ItemName TEXT,Designer TEXT,Quantity INT); INSERT INTO ClothingSales (ItemID,ItemName,Designer,Quantity) VALUES (1,'Top','DesignerA',250),(2,'Pants','DesignerB',300),(3,'Dress','DesignerC',150);
SELECT Designer, 100.0 * SUM(Quantity) / (SELECT SUM(Quantity) FROM ClothingSales) as PercentageOfSales FROM ClothingSales GROUP BY Designer;
Delete records of donors who haven't donated in the last 12 months from the 'donations' table.
CREATE TABLE donations (donation_id INT,donor_id INT,donation_amount DECIMAL(10,2),donation_date DATE); INSERT INTO donations (donation_id,donor_id,donation_amount,donation_date) VALUES (1,2,1000,'2022-02-14');
DELETE FROM donations WHERE donation_date < NOW() - INTERVAL 12 MONTH;
What is the total number of volunteers who have completed more than 25 hours of service in the "Food Security" program?
CREATE TABLE Volunteers (VolunteerID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Email VARCHAR(50),Hours INT,Program VARCHAR(50));
SELECT SUM(Hours) FROM Volunteers WHERE Program = 'Food Security' AND Hours > 25;
How many suppliers provide non-GMO ingredients for Italian dishes?
CREATE TABLE Suppliers (id INT,provides_non_gmo BOOLEAN,serves_cuisine VARCHAR(20)); INSERT INTO Suppliers (id,provides_non_gmo,serves_cuisine) VALUES (1,true,'Italian'),(2,false,'Italian'),(3,true,'Chinese');
SELECT COUNT(*) FROM Suppliers WHERE provides_non_gmo = true AND serves_cuisine = 'Italian';
Show annual energy consumption for our sustainable seafood processing plants, in kWh.
CREATE TABLE plants (id INT,name TEXT,type TEXT,annual_energy_consumption DECIMAL); INSERT INTO plants (id,name,type,annual_energy_consumption) VALUES (1,'Seafood Haven','Sustainable',1230000);
SELECT name, annual_energy_consumption FROM plants WHERE type = 'Sustainable';
List all biotech startup funding events greater than $20M in the USA and their respective dates.
CREATE TABLE startups_funding (id INT,name VARCHAR(50),location VARCHAR(50),funding FLOAT,funding_date DATE); INSERT INTO startups_funding (id,name,location,funding,funding_date) VALUES (1,'StartupC','USA',25000000,'2022-03-15'); INSERT INTO startups_funding (id,name,location,funding,funding_date) VALUES (2,'StartupD','USA',18000000,'2022-02-20');
SELECT name, funding_date FROM startups_funding WHERE location = 'USA' AND funding > 20000000;
Show the total cost of bioprocess engineering projects in Germany and France.
CREATE TABLE bioprocess_engineering (id INT,project_name VARCHAR(50),location VARCHAR(50),cost FLOAT); INSERT INTO bioprocess_engineering (id,project_name,location,cost) VALUES (1,'ProjectA','Germany',3500000); INSERT INTO bioprocess_engineering (id,project_name,location,cost) VALUES (2,'ProjectB','France',4000000);
SELECT SUM(cost) FROM bioprocess_engineering WHERE location IN ('Germany', 'France');
What is the average age of female bioprocess engineers in Germany?
CREATE TABLE bioprocess_engineers (id INT,name TEXT,age INT,gender TEXT,country TEXT); INSERT INTO bioprocess_engineers (id,name,age,gender,country) VALUES (1,'Alice',35,'Female','Germany');
SELECT AVG(age) FROM bioprocess_engineers WHERE gender = 'Female' AND country = 'Germany';
Find the number of graduate students in each department, excluding those enrolled in the 'Physics' department.
CREATE TABLE graduate_students (id INT,department VARCHAR(20),enrollment_status VARCHAR(10)); INSERT INTO graduate_students (id,department,enrollment_status) VALUES (1,'Physics','Enrolled'),(2,'Mathematics','Enrolled'),(3,'Chemistry','Enrolled'),(4,'English','Not Enrolled'),(5,'Physics','Not Enrolled');
SELECT department, COUNT(*) as num_students FROM graduate_students WHERE department NOT IN ('Physics') GROUP BY department;
What is the average number of research grants awarded per department in the 'research_grants' table, excluding departments with less than 3 grants?
CREATE TABLE research_grants (id INT,department VARCHAR(255),amount FLOAT); INSERT INTO research_grants (id,department,amount) VALUES (1,'Physics',100000),(2,'Physics',200000),(3,'Mathematics',150000),(4,'Chemistry',250000),(5,'Chemistry',300000),(6,'Biology',50000);
SELECT AVG(grant_count) FROM (SELECT department, COUNT(*) AS grant_count FROM research_grants GROUP BY department HAVING COUNT(*) >= 3) AS subquery;
What is the maximum amount of research grant received by a faculty member in the Arts and Humanities department?
CREATE TABLE grants_faculty (id INT,department VARCHAR(50),faculty_name VARCHAR(50),amount DECIMAL(10,2),grant_date DATE); INSERT INTO grants_faculty (id,department,faculty_name,amount,grant_date) VALUES (1,'Arts and Humanities','Grace',12000.00,'2018-06-10'),(2,'Arts and Humanities','Harry',18000.00,'2019-12-20'),(3,'Arts and Humanities','Ida',20000.00,'2020-08-05');
SELECT MAX(amount) FROM grants_faculty WHERE department = 'Arts and Humanities';
How many green buildings are there in each zip code?
CREATE TABLE Zip (zip_code INT,zip_name VARCHAR(50)); CREATE TABLE Building (building_id INT,building_name VARCHAR(50),building_type VARCHAR(50),zip_code INT);
SELECT Zip.zip_name, COUNT(*) as num_buildings FROM Zip JOIN Building ON Zip.zip_code = Building.zip_code WHERE Building.building_type = 'green' GROUP BY Zip.zip_name;
What is the total CO2 emission of buildings constructed before 2000, grouped by city?
CREATE TABLE Buildings (id INT,city VARCHAR(50),co2_emission FLOAT,construction_year INT); INSERT INTO Buildings (id,city,co2_emission,construction_year) VALUES (1,'NYC',1200.5,2020),(2,'LA',1500.3,2019),(3,'SF',900.2,2020),(4,'NYC',1800.7,1999),(5,'LA',1300.5,1998);
SELECT city, SUM(co2_emission) FROM Buildings WHERE construction_year < 2000 GROUP BY city;
How has the number of sustainable tourism activities in Indonesia changed over the past year?
CREATE TABLE indonesia_sustainable_tourism (month INT,country TEXT,num_activities INT); INSERT INTO indonesia_sustainable_tourism (month,country,num_activities) VALUES (1,'Indonesia',120),(2,'Indonesia',125),(3,'Indonesia',130),(4,'Indonesia',140),(5,'Indonesia',150),(6,'Indonesia',160),(7,'Indonesia',170),(8,'Indonesia',180),(9,'Indonesia',190),(10,'Indonesia',200),(11,'Indonesia',210),(12,'Indonesia',220);
SELECT month, num_activities FROM indonesia_sustainable_tourism;
What is the average energy savings per hotel in Egypt?
CREATE TABLE HotelEnergy (HotelID INT,Country VARCHAR(50),EnergySavings FLOAT); INSERT INTO HotelEnergy (HotelID,Country,EnergySavings) VALUES (1,'Egypt',200),(2,'Egypt',250);
SELECT AVG(EnergySavings) FROM HotelEnergy WHERE Country = 'Egypt';
Add new records to "traditional_music" table
CREATE TABLE IF NOT EXISTS traditional_music (id INT,name VARCHAR(255),origin VARCHAR(255)); INSERT INTO traditional_music VALUES (1,'Mbira','Zimbabwe');
INSERT INTO traditional_music (id, name, origin) VALUES (2, 'Didgeridoo', 'Australia'), (3, 'Kora', 'West Africa');
List the traditional arts that have been represented in the most heritage sites, ordered by the number of heritage sites in descending order.
CREATE TABLE Arts (ArtID INT,ArtName TEXT,ArtType TEXT); INSERT INTO Arts (ArtID,ArtName,ArtType) VALUES (1001,'Pottery','Ceramics'),(1002,'Weaving','Textiles'),(1003,'Dance','Performing Arts'); CREATE TABLE SiteArts (SiteID INT,ArtID INT); INSERT INTO SiteArts (SiteID,ArtID) VALUES (1001,1001),(1002,1001),(1003,1001),(1004,1002),(1005,1002);
SELECT ArtType, COUNT(SiteID) AS Number_Of_Sites FROM SiteArts JOIN Arts ON SiteArts.ArtID = Arts.ArtID GROUP BY ArtType ORDER BY Number_Of_Sites DESC;
What is the total number of tourists visiting historical sites in Europe?
CREATE TABLE tourism (destination VARCHAR(50),category VARCHAR(50),number_of_tourists INT); INSERT INTO tourism (destination,category,number_of_tourists) VALUES ('Colosseum','Historical',50000),('Louvre','Historical',80000),('Acropolis','Historical',60000);
SELECT SUM(number_of_tourists) FROM tourism WHERE category = 'Historical';
Insert a new record into the 'offenders' table
CREATE TABLE offenders (id INT PRIMARY KEY,name VARCHAR(255),age INT,state VARCHAR(2));
INSERT INTO offenders (id, name, age, state) VALUES (1, 'Jamal Johnson', 34, 'IL');
What is the average time taken to resolve cases for each mediator?
CREATE TABLE mediators (mediator_id INT,name TEXT); INSERT INTO mediators (mediator_id,name) VALUES (1,'John'),(2,'Jane'),(3,'Mike'); CREATE TABLE cases (case_id INT,mediator_id INT,date TEXT,resolved_date TEXT); INSERT INTO cases (case_id,mediator_id,date,resolved_date) VALUES (1,1,'2022-01-01','2022-01-15'),(2,1,'2022-02-01','2022-02-28'),(3,2,'2022-03-01','2022-03-15'),(4,3,'2022-04-01','2022-04-30');
SELECT mediators.name, AVG(DATEDIFF('day', cases.date, cases.resolved_date)) as average_time_to_resolve FROM mediators INNER JOIN cases ON mediators.mediator_id = cases.mediator_id GROUP BY mediators.name;
Count the number of underwater volcanoes in the Pacific Ocean.
CREATE TABLE OceanFloorFeatures (id INT,ocean_id INT,feature VARCHAR(20)); INSERT INTO OceanFloorFeatures (id,ocean_id,feature) VALUES (1,1,'Volcano'),(2,1,'Mountain'),(3,2,'Volcano'),(4,2,'Trench');
SELECT COUNT(*) FROM OceanFloorFeatures JOIN Oceans ON OceanFloorFeatures.ocean_id = Oceans.id WHERE Oceans.name = 'Pacific' AND OceanFloorFeatures.feature = 'Volcano';
How many whale shark sightings were reported in the Indian Ocean in 2020?
CREATE TABLE whale_shark_sightings (year INT,location TEXT,sightings INT); INSERT INTO whale_shark_sightings (year,location,sightings) VALUES (2018,'Indian Ocean',120),(2019,'Indian Ocean',150),(2020,'Indian Ocean',170);
SELECT sightings FROM whale_shark_sightings WHERE year = 2020 AND location = 'Indian Ocean';
Add a new TV show to the 'shows' table with the title 'New TV Show', release year 2022, and id 5
CREATE TABLE shows (id INT,title TEXT,release_year INT);
INSERT INTO shows (id, title, release_year) VALUES (5, 'New TV Show', 2022);
What are the names of the actors who have acted in the same movie as the director?
CREATE TABLE movies (id INT,title TEXT,actor TEXT,director TEXT);
SELECT DISTINCT actor FROM movies WHERE director IN (SELECT actor FROM movies);
What is the average labor productivity by mine type in the past 12 months?
CREATE TABLE mine_labor_productivity (mine_type VARCHAR(255),productivity NUMERIC,measurement_date DATE); INSERT INTO mine_labor_productivity (mine_type,productivity,measurement_date) VALUES ('open_pit',1234,'2021-08-01'),('underground',2345,'2021-08-01'),('open_pit',5432,'2021-07-01'),('underground',6789,'2021-07-01');
SELECT mine_type, AVG(productivity) as avg_productivity FROM (SELECT mine_type, productivity, measurement_date, ROW_NUMBER() OVER (PARTITION BY mine_type ORDER BY measurement_date DESC) as rn FROM mine_labor_productivity WHERE measurement_date >= DATEADD(month, -12, CURRENT_DATE)) t WHERE rn = 1 GROUP BY mine_type;
What is the total number of employees working in the mining industry in each country in the Middle East?
CREATE TABLE mining_companies (id INT,name VARCHAR(50),country VARCHAR(50)); CREATE TABLE employees (company_id INT,num_employees INT,employee_country VARCHAR(50)); INSERT INTO mining_companies (id,name,country) VALUES (1,'Negev Mining','Israel'),(2,'Arabian Drilling','Saudi Arabia'); INSERT INTO employees (company_id,num_employees,employee_country) VALUES (1,500,'Israel'),(1,550,'Israel'),(2,700,'Saudi Arabia');
SELECT mc.country, SUM(e.num_employees) as total_employees FROM mining_companies mc INNER JOIN employees e ON mc.id = e.company_id WHERE e.employee_country = mc.country AND mc.continent = 'Asia' GROUP BY mc.country;
Delete the record of the reader with the ID of 6 if it exists.
CREATE TABLE readers (id INT,name VARCHAR(50),age INT,preference VARCHAR(50)); INSERT INTO readers (id,name,age,preference) VALUES (1,'John Doe',30,'technology'),(2,'Jane Smith',45,'sports'),(3,'Bob Johnson',28,'politics'),(6,'Mateo Garcia',29,'international');
DELETE FROM readers WHERE id = 6;
How many news articles were published in the 'international' section in the last month?
CREATE TABLE news_articles (id INT,title VARCHAR(100),section VARCHAR(50),publication_date DATE); INSERT INTO news_articles (id,title,section,publication_date) VALUES (1,'Article 1','international','2022-01-01'),(2,'Article 2','national','2022-02-01'),(3,'Article 3','international','2022-02-15');
SELECT COUNT(*) FROM news_articles WHERE section = 'international' AND publication_date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH);
What is the total number of articles written by each author in each region?
CREATE TABLE authors (id INT,name TEXT); CREATE TABLE regions (id INT,name TEXT); CREATE TABLE articles (id INT,title TEXT,content TEXT,author_id INT,region_id INT); INSERT INTO authors (id,name) VALUES (1,'John Doe'),(2,'Jane Smith'); INSERT INTO regions (id,name) VALUES (1,'North'),(2,'South'),(3,'East'),(4,'West'); INSERT INTO articles (id,title,content,author_id,region_id) VALUES (1,'Article 1','Content 1',1,1),(2,'Article 2','Content 2',2,2),(3,'Article 3','Content 3',1,3),(4,'Article 4','Content 4',2,4);
SELECT authors.name, regions.name, COUNT(articles.id) FROM authors INNER JOIN articles ON authors.id = articles.author_id INNER JOIN regions ON regions.id = articles.region_id GROUP BY authors.name, regions.name;
What is the total donation amount per region in the 'Donations' table?
CREATE TABLE Regions (RegionID int,RegionName varchar(50)); CREATE TABLE Donations (DonationID int,DonorID int,Amount decimal(10,2),RegionID int); INSERT INTO Regions (RegionID,RegionName) VALUES (1,'North America'),(2,'South America'),(3,'Europe'),(4,'Asia'),(5,'Africa'); INSERT INTO Donations (DonationID,DonorID,Amount,RegionID) VALUES (1,1001,200.00,1),(2,1002,300.00,1),(3,1003,500.00,3),(4,1004,150.00,2),(5,1005,800.00,4);
SELECT r.RegionName, SUM(d.Amount) as TotalDonationPerRegion FROM Donations d JOIN Regions r ON d.RegionID = r.RegionID GROUP BY r.RegionName;
What is the maximum number of marine species ever observed in a single day in the Baltic Sea?
CREATE TABLE marine_species_observations (observation_id INTEGER,observation_date DATE,species_name TEXT,ocean TEXT,number_of_observations INTEGER);
SELECT MAX(number_of_observations) FROM marine_species_observations WHERE ocean = 'Baltic Sea' AND observation_date BETWEEN '2000-01-01' AND '2022-12-31' GROUP BY ocean, DATE_TRUNC('day', observation_date);
What is the number of players who have played more than 100 minutes?
CREATE TABLE player_sessions (id INT,player_name TEXT,playtime INT); INSERT INTO player_sessions (id,player_name,playtime) VALUES (1,'Olivia',120); INSERT INTO player_sessions (id,player_name,playtime) VALUES (2,'Olivia',150); INSERT INTO player_sessions (id,player_name,playtime) VALUES (3,'William',200);
SELECT COUNT(*) FROM player_sessions WHERE playtime > 100;
How many esports events were held in Europe in 2022?
CREATE TABLE esports_events (id INT,year INT,location VARCHAR(20)); INSERT INTO esports_events (id,year,location) VALUES (1,2022,'USA'),(2,2022,'Germany'),(3,2021,'France');
SELECT COUNT(*) FROM esports_events WHERE year = 2022 AND location LIKE 'Europe%';
Show the total prize pool for each game
CREATE TABLE esports_events (event_id INT PRIMARY KEY,name VARCHAR(50),date DATE,game VARCHAR(50),location VARCHAR(50),prize_pool DECIMAL(10,2));
SELECT game, SUM(prize_pool) as total_prize_pool FROM esports_events GROUP BY game;
What is the average age of players who use virtual reality devices in 2021?
CREATE TABLE PlayerDevices (PlayerID INT,Age INT,Device VARCHAR(50),Year INT); INSERT INTO PlayerDevices (PlayerID,Age,Device,Year) VALUES (1,25,'Oculus Rift',2020); INSERT INTO PlayerDevices (PlayerID,Age,Device,Year) VALUES (2,32,'HTC Vive',2021); INSERT INTO PlayerDevices (PlayerID,Age,Device,Year) VALUES (3,19,'Oculus Quest',2021);
SELECT AVG(Age) FROM PlayerDevices WHERE Year = 2021 AND Device IS NOT NULL;
How many public pools in the Recreation department have a budget over $200,000?
CREATE TABLE Recreation_Dept (ID INT,Facility VARCHAR(255),Budget FLOAT); INSERT INTO Recreation_Dept (ID,Facility,Budget) VALUES (1,'Public Pool',300000),(2,'Public Pool',150000),(3,'Community Center',200000);
SELECT COUNT(*) FROM Recreation_Dept WHERE Facility = 'Public Pool' AND Budget > 200000;
What is the total budget allocated for services in the Social Services department that start with the letter 'C'?
CREATE TABLE Social_Services_Dept (ID INT,Service VARCHAR(255),Budget FLOAT); INSERT INTO Social_Services_Dept (ID,Service,Budget) VALUES (1,'Child Care',600000),(2,'Counseling',700000),(3,'Elder Care',800000);
SELECT SUM(Budget) FROM Social_Services_Dept WHERE Service LIKE 'C%';
What is the highest energy rating for properties in the 'green_buildings' table?
CREATE TABLE green_buildings (id INT,square_footage FLOAT,energy_rating INT);
SELECT MAX(energy_rating) FROM green_buildings;
What is the average energy efficiency rating for residential buildings in the "CleanEnergy" schema?
CREATE TABLE ResidentialEfficiency (building_id INT,rating FLOAT,city VARCHAR(50),state VARCHAR(50)); INSERT INTO ResidentialEfficiency (building_id,rating,city,state) VALUES (1,92.5,'SanFrancisco','CA'),(2,88.3,'Austin','TX');
SELECT AVG(rating) FROM CleanEnergy.ResidentialEfficiency;