instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the average price of products with a cruelty-free certification?
CREATE TABLE products (product_id INT,price DECIMAL(5,2),is_cruelty_free BOOLEAN); INSERT INTO products (product_id,price,is_cruelty_free) VALUES (1,25.99,true),(2,30.99,false),(3,15.99,true);
SELECT AVG(price) FROM products WHERE is_cruelty_free = true;
Update the number of openings for a talent acquisition in the 'talent_acquisition' table
CREATE TABLE talent_acquisition (id INT PRIMARY KEY,job_title VARCHAR(50),job_location VARCHAR(50),number_of_openings INT,source VARCHAR(50));
UPDATE talent_acquisition SET number_of_openings = 5 WHERE id = 2001;
Show the number of military personnel in each military branch, ranked by the highest number of personnel.
CREATE TABLE MilitaryPersonnel (PersonnelID int,PersonnelName varchar(100),Branch varchar(50),NumPersonnel int); INSERT INTO MilitaryPersonnel (PersonnelID,PersonnelName,Branch,NumPersonnel) VALUES (1,'John Doe','Army',500000),(2,'Jane Smith','Navy',450000),(3,'Mike Johnson','Air Force',300000);
SELECT Branch, NumPersonnel, ROW_NUMBER() OVER (ORDER BY NumPersonnel DESC) as Rank FROM MilitaryPersonnel;
What was the daily production rate for Well ID 401 on 2022-01-03?
CREATE TABLE ProductionData (WellID int,ProductionDate date,BarrelsPerDay int); INSERT INTO ProductionData (WellID,ProductionDate,BarrelsPerDay) VALUES (401,'2022-01-01',1200),(401,'2022-01-02',1300),(401,'2022-01-03',1400);
SELECT BarrelsPerDay FROM ProductionData WHERE WellID = 401 AND ProductionDate = '2022-01-03';
Show the number of employees and total salary expense for each department in the organization.
CREATE TABLE employees (employee_id INT,department TEXT,salary DECIMAL(10,2)); INSERT INTO employees VALUES (1,'Engineering',80000),(2,'Marketing',60000),(3,'Engineering',85000),(4,'Human Resources',70000),(5,'Finance',90000),(6,'Marketing',65000);
SELECT department, COUNT(*) AS num_employees, SUM(salary) AS total_salary_expense FROM employees GROUP BY department;
What is the average sea surface temperature in the Southern Ocean during the month of January?
CREATE TABLE Southern_Ocean_Temp (date DATE,location TEXT,temp FLOAT); INSERT INTO Southern_Ocean_Temp (date,location,temp) VALUES ('2022-01-01','Southern Ocean',2.0),('2022-01-15','Southern Ocean',2.5);
SELECT AVG(temp) FROM Southern_Ocean_Temp WHERE location = 'Southern Ocean' AND EXTRACT(MONTH FROM date) = 1;
What is the name of the factory in 'China' with the lowest number of workers?
CREATE TABLE factories_workers_ext (id INT,factory_id INT,name VARCHAR(50),country VARCHAR(50),worker_count INT); INSERT INTO factories_workers_ext (id,factory_id,name,country,worker_count) VALUES (1,1,'Factory One','Germany',100),(2,2,'Factory Two','China',50),(3,3,'Factory Three','China',150);
SELECT name FROM factories_workers_ext WHERE country = 'China' AND worker_count = (SELECT MIN(worker_count) FROM factories_workers_ext WHERE country = 'China');
Delete the 'intelligence_officer' record with the name 'Ivy' from the 'intelligence_officers' table
CREATE TABLE intelligence_officers (id INT,name VARCHAR(20),rank VARCHAR(10)); INSERT INTO intelligence_officers (id,name,rank) VALUES (1,'Ivy','Captain'),(2,'Jack','Lieutenant'),(3,'Kate','Commander');
DELETE FROM intelligence_officers WHERE name = 'Ivy';
What is the total number of wells that were drilled in the North Atlantic Ocean before 2015, and what is the total amount of oil they produced?
CREATE TABLE north_atlantic_ocean (id INT,well_name VARCHAR(255),drill_date DATE,production_oil INT);
SELECT COUNT(*) as total_wells, SUM(production_oil) as total_oil_produced FROM north_atlantic_ocean WHERE drill_date < '2015-01-01';
How many climate finance initiatives were implemented in Europe in 2019?
CREATE TABLE climate_finance (id INT,initiative_name VARCHAR(50),country VARCHAR(50),amount FLOAT,date DATE); INSERT INTO climate_finance (id,initiative_name,country,amount,date) VALUES (1,'Green Energy Investment','France',750000,'2019-01-01');
SELECT COUNT(*) FROM climate_finance WHERE country LIKE '%Europe%' AND date = '2019-01-01';
Identify the total rainfall in millimeters for all regions in "FR" for the month of "June" in the year "2022".
CREATE TABLE Rainfall (id INT,region VARCHAR(255),rainfall DECIMAL(5,2),date DATE); INSERT INTO Rainfall (id,region,rainfall,date) VALUES (1,'FR-Nord',50.3,'2022-06-01');
SELECT SUM(rainfall) FROM Rainfall WHERE region LIKE 'FR%' AND EXTRACT(MONTH FROM date) = 6 AND EXTRACT(YEAR FROM date) = 2022;
How many active rigs are there in the 'Alaska' region?
CREATE TABLE rigs (rig_id INT,rig_name VARCHAR(255),status VARCHAR(255),region VARCHAR(255)); INSERT INTO rigs (rig_id,rig_name,status,region) VALUES (1,'Rig1','active','Alaska'),(2,'Rig2','inactive','Alaska'),(3,'Rig3','active','Gulf of Mexico');
SELECT COUNT(*) FROM rigs WHERE status = 'active' AND region = 'Alaska';
How many volunteers engaged in each program in Q1 2021, grouped by city?
CREATE TABLE Volunteers (VolunteerID INT,Name TEXT,City TEXT); CREATE TABLE Programs (ProgramID INT,Name TEXT,VolunteerID INT,StartDate DATE); INSERT INTO Volunteers (VolunteerID,Name,City) VALUES (1,'James Johnson','New York'),(2,'Natalie Brown','Los Angeles'),(3,'Michael Davis','Chicago'); INSERT INTO Programs (ProgramID,Name,VolunteerID,StartDate) VALUES (1,'Tutoring Kids',1,'2021-01-05'),(2,'Cleaning Beaches',2,'2021-03-20'),(3,'Planting Trees',3,'2021-02-01');
SELECT City, COUNT(DISTINCT Volunteers.VolunteerID) as 'Number of Volunteers' FROM Programs INNER JOIN Volunteers ON Programs.VolunteerID = Volunteers.VolunteerID WHERE Programs.StartDate BETWEEN '2021-01-01' AND '2021-03-31' GROUP BY City;
What is the ratio of female to male solo artists in the Hip Hop genre?
CREATE TABLE artists (id INT,name VARCHAR(50),gender VARCHAR(10),genre VARCHAR(20),is_solo BOOLEAN); INSERT INTO artists (id,name,gender,genre,is_solo) VALUES (1,'Cardi B','Female','Hip Hop',TRUE),(2,'Kendrick Lamar','Male','Hip Hop',TRUE);
SELECT COUNT(*) FILTER (WHERE gender = 'Female' AND is_solo = TRUE) / COUNT(*) FILTER (WHERE gender = 'Male' AND is_solo = TRUE) FROM artists WHERE genre = 'Hip Hop';
Find the total waste generation for commercial and residential sectors in 2020 and 2021.
CREATE TABLE waste_generation (year INT,sector VARCHAR(20),amount INT); INSERT INTO waste_generation (year,sector,amount) VALUES (2020,'commercial',1200),(2020,'residential',800),(2021,'commercial',1500),(2021,'residential',900);
SELECT sector, SUM(amount) FROM waste_generation WHERE year IN (2020, 2021) GROUP BY sector;
Find the total number of visitors from African countries in the last 2 years.
CREATE TABLE Visitors (id INT,country VARCHAR(50),visit_year INT,gender VARCHAR(10)); CREATE VIEW African_Countries AS SELECT 'Egypt' AS country UNION ALL SELECT 'South Africa' UNION ALL SELECT 'Nigeria';
SELECT COUNT(*) FROM Visitors INNER JOIN African_Countries ON Visitors.country = African_Countries.country WHERE visit_year BETWEEN 2020 AND 2021;
What is the average citizen satisfaction score for public transportation services in urban areas?
CREATE TABLE transportation (area VARCHAR(20),service_type VARCHAR(50),satisfaction_score INT); INSERT INTO transportation (area,service_type,satisfaction_score) VALUES ('urban','public_transportation',8),('rural','public_transportation',6),('urban','rail',9),('rural','rail',7),('urban','bus',8),('rural','bus',7);
SELECT AVG(satisfaction_score) FROM transportation WHERE area = 'urban' AND service_type = 'public_transportation';
How many unique donors have there been each month in the last year?
CREATE TABLE donors (id INT,donor_name TEXT,donation_date DATE); INSERT INTO donors (id,donor_name,donation_date) VALUES (1,'Jim White','2022-01-01'),(2,'Jane Smith','2022-02-15');
SELECT EXTRACT(MONTH FROM donation_date) as month, COUNT(DISTINCT donor_name) as unique_donors FROM donors WHERE donation_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY month ORDER BY month;
Update the retail price of all products that use recycled materials by 5%.
CREATE TABLE products (product_id INT,product_name VARCHAR(50),uses_recycled_materials BIT); INSERT INTO products (product_id,product_name,uses_recycled_materials) VALUES (1,'Product A',1),(2,'Product B',0),(3,'Product C',1); CREATE TABLE pricing (product_id INT,retail_price DECIMAL(5,2)); INSERT INTO pricing (product_id,retail_price) VALUES (1,25.99),(2,34.99),(3,19.99);
UPDATE p SET retail_price = retail_price * 1.05 FROM products p JOIN pricing pc ON p.product_id = pc.product_id WHERE p.uses_recycled_materials = 1;
List all heritage preservation projects in Africa and their corresponding budgets.
CREATE TABLE Projects (ProjectID INT,Name TEXT,Budget INT);CREATE TABLE Locations (ProjectID INT,Country TEXT);
SELECT Projects.Name, Projects.Budget FROM Projects INNER JOIN Locations ON Projects.ProjectID = Locations.ProjectID WHERE Locations.Country = 'Africa';
What are the most common types of military technology used by the Australian and Canadian armies in their inventories?
CREATE TABLE military_tech_armies (army VARCHAR(50),tech_type VARCHAR(50),quantity INT); INSERT INTO military_tech_armies (army,tech_type,quantity) VALUES ('Australia','Armored Vehicles',726),('Australia','Artillery',145),('Australia','Aircraft',334),('Canada','Armored Vehicles',873),('Canada','Artillery',189),('Canada','Aircraft',367);
SELECT army, tech_type, quantity FROM military_tech_armies WHERE army IN ('Australia', 'Canada');
What is the average age of female patients diagnosed with diabetes?
CREATE TABLE patient (patient_id INT,gender VARCHAR(10),age INT,diagnosis VARCHAR(20));
SELECT AVG(age) FROM patient WHERE gender = 'female' AND diagnosis = 'diabetes';
Which carriers have handled the most returns from Canada to France, and what is the total weight of those returns?
CREATE TABLE returns (id INT,carrier TEXT,return_weight FLOAT,source_country TEXT,destination_country TEXT);
SELECT carrier, SUM(return_weight) as total_weight FROM returns WHERE source_country = 'Canada' AND destination_country = 'France' GROUP BY carrier ORDER BY total_weight DESC;
What is the maximum response time for emergency calls in the 'Southern' region?
CREATE TABLE emergency_calls (id INT,region VARCHAR(20),response_time INT); INSERT INTO emergency_calls (id,region,response_time) VALUES (1,'Southern',180);
SELECT MAX(response_time) FROM emergency_calls WHERE region = 'Southern';
Which cruelty-free cosmetic products have the lowest sales volume in the South American market?
CREATE TABLE cosmetic_products (product_id INT,product_name VARCHAR(50),is_cruelty_free BOOLEAN,sales_volume INT,market VARCHAR(10)); INSERT INTO cosmetic_products (product_id,product_name,is_cruelty_free,sales_volume,market) VALUES (1,'Lip Gloss',true,500,'SA'),(2,'Mascara',false,400,'SA'),(3,'Eyeshadow',true,100,'SA');
SELECT product_name, sales_volume FROM cosmetic_products WHERE is_cruelty_free = true AND market = 'SA' ORDER BY sales_volume ASC;
Insert records for new heritage sites into "heritage_sites" table
CREATE TABLE IF NOT EXISTS heritage_sites (id INT,name VARCHAR(255),status VARCHAR(255));
INSERT INTO heritage_sites (id, name, status) VALUES (4, 'Taj Mahal', 'World Heritage'), (5, 'Galapagos Islands', 'World Heritage');
What is the total amount of recycled materials used in the production of jeans in the United States?
CREATE TABLE RecycledMaterials (product VARCHAR(50),amount INT); INSERT INTO RecycledMaterials VALUES ('Jeans',500),('Shirts',300),('Jeans',700),('Pants',400);
SELECT SUM(amount) FROM RecycledMaterials WHERE product = 'Jeans';
What is the total number of network infrastructure investments made in the last quarter of 2020?
CREATE TABLE network_investments (investment_id INT,investment_date DATE); INSERT INTO network_investments (investment_id,investment_date) VALUES (1,'2021-01-15'),(2,'2021-03-01'),(3,'2020-12-01');
SELECT COUNT(*) FROM network_investments WHERE investment_date BETWEEN '2020-10-01' AND '2020-12-31';
What is the minimum claim amount for policies in the 'health_insurance' table?
CREATE TABLE health_insurance (policy_id INT,claim_amount DECIMAL(10,2)); INSERT INTO health_insurance (policy_id,claim_amount) VALUES (1,150.00),(2,250.50),(3,50.00),(4,400.75);
SELECT MIN(claim_amount) FROM health_insurance;
How many fraudulent transactions occurred in Q2 of 2021?
CREATE TABLE transactions (transaction_id INT,date DATE,is_fraudulent BOOLEAN); INSERT INTO transactions (transaction_id,date,is_fraudulent) VALUES (1,'2021-04-01',true),(2,'2021-04-02',false),(3,'2021-07-01',true);
SELECT COUNT(*) FROM transactions WHERE date BETWEEN '2021-04-01' AND '2021-06-30' AND is_fraudulent = true;
What are the total number of research grants awarded to female and non-binary faculty in the College of Engineering, sorted alphabetically by faculty last name?
CREATE TABLE faculty (id INT,name TEXT,gender TEXT,department TEXT); INSERT INTO faculty (id,name,gender,department) VALUES (1,'Alice','Female','Engineering'),(2,'Bob','Male','Engineering'),(3,'Carla','Non-binary','Engineering'); CREATE TABLE research_grants (id INT,faculty_id INT,title TEXT,amount FLOAT); INSERT INTO research_grants (id,faculty_id,title,amount) VALUES (1,1,'Project A',50000),(2,1,'Project B',75000),(3,2,'Project C',60000),(4,3,'Project D',80000);
SELECT COUNT(*) FROM research_grants INNER JOIN faculty ON research_grants.faculty_id = faculty.id WHERE faculty.gender IN ('Female', 'Non-binary') AND faculty.department = 'Engineering' ORDER BY faculty.name;
What is the total budget allocated for all language preservation projects in 'Oceania'?
CREATE TABLE LanguagePreservation (ProjectID INT PRIMARY KEY,ProjectName VARCHAR(50),Location VARCHAR(50),Budget DECIMAL(10,2)); INSERT INTO LanguagePreservation (ProjectID,ProjectName,Location,Budget) VALUES (1,'Polynesian Languages','Samoa',350000.00),(2,'Aboriginal Languages','Australia',600000.00);
SELECT SUM(Budget) FROM LanguagePreservation WHERE Location LIKE '%Oceania%';
Which city has the least number of green buildings in the United States?
CREATE TABLE GreenBuildings (id INT,city VARCHAR(50),building_count INT); INSERT INTO GreenBuildings (id,city,building_count) VALUES (1,'New York',300),(2,'Los Angeles',250),(3,'Chicago',220),(4,'Houston',280);
SELECT city, MIN(building_count) FROM GreenBuildings WHERE country = 'United States';
Calculate the percentage of products sold for each brand in the 'ethical_labor2' table, ordered by the percentage in descending order.
CREATE TABLE ethical_labor2 (product_id INT,brand VARCHAR(255),quantity_sold INT); INSERT INTO ethical_labor2 (product_id,brand,quantity_sold) VALUES (4,'BrandV',500),(5,'BrandW',800),(6,'BrandX',700);
SELECT brand, (SUM(quantity_sold) OVER (PARTITION BY brand) * 100.0 / SUM(quantity_sold) OVER ()) AS percentage_sold FROM ethical_labor2 GROUP BY brand ORDER BY percentage_sold DESC;
What are the AI safety concerns raised in the past year for the transportation industry, in the AI Safety database?
CREATE TABLE concerns (id INT,description VARCHAR(255),published_date DATE,industry VARCHAR(255));
SELECT description FROM concerns WHERE published_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 1 YEAR) AND industry = 'Transportation';
Find the top 3 countries with the highest number of security incidents in the last 30 days.
CREATE TABLE security_incidents (country VARCHAR(50),incident_count INT,incident_date DATE); INSERT INTO security_incidents (country,incident_count,incident_date) VALUES ('USA',200,'2023-01-01'),('Canada',150,'2023-01-02'),('UK',120,'2023-01-03'),('Germany',180,'2023-01-04'),('Australia',80,'2023-01-05');
SELECT country, incident_count FROM security_incidents WHERE incident_date >= DATEADD(day, -30, GETDATE()) ORDER BY incident_count DESC LIMIT 3;
What is the total number of satellites launched by countries before 1990?
CREATE TABLE satellites (id INT,country VARCHAR(255),launch_year INT,PRIMARY KEY(id)); INSERT INTO satellites (id,country,launch_year) VALUES (1,'USA',1978),(2,'USSR',1957),(3,'China',1970);
SELECT SUM(satellites.total) FROM (SELECT COUNT(*) AS total FROM satellites WHERE launch_year < 1990 GROUP BY country) AS satellites;
What is the minimum ph level of soils in the West?
CREATE TABLE Soil_Types (id INT PRIMARY KEY,type VARCHAR(50),ph VARCHAR(50),region VARCHAR(50)); INSERT INTO Soil_Types (id,type,ph,region) VALUES (1,'Sandy','6.0-7.5','Northeast'),(2,'Clay','5.5-6.5','Midwest'),(3,'Loam','6.0-7.0','West'),(4,'Silt','6.5-7.5','West');
SELECT MIN(ph) FROM Soil_Types WHERE region = 'West';
What is the average energy consumption (in kWh) of households in Tokyo and Seoul?
CREATE TABLE household_energy (household_id INT,city VARCHAR(50),consumption_kwh FLOAT); INSERT INTO household_energy (household_id,city,consumption_kwh) VALUES (1,'Tokyo',250.3),(2,'Seoul',280.9),(3,'Tokyo',300.1),(4,'Seoul',220.5),(5,'Tokyo',270.4),(6,'Seoul',290.1);
SELECT AVG(consumption_kwh) FROM household_energy WHERE city IN ('Tokyo', 'Seoul');
What is the average ethical AI score for Latin American countries, for each technology sector, in the year 2022?
CREATE TABLE ethical_ai (country VARCHAR(50),sector VARCHAR(50),year INT,score INT); INSERT INTO ethical_ai (country,sector,year,score) VALUES ('Brazil','Healthcare',2022,85),('Brazil','Finance',2022,70),('Mexico','Healthcare',2022,80),('Mexico','Finance',2022,90);
SELECT country, sector, AVG(score) as avg_score FROM ethical_ai WHERE year = 2022 AND region = 'Latin America' GROUP BY country, sector;
Find the number of security incidents and their corresponding categories for the technology sector, excluding incidents related to phishing.
CREATE TABLE incidents (category VARCHAR(50),sector VARCHAR(20)); INSERT INTO incidents (category,sector) VALUES ('Malware','Technology'),('Phishing','Technology');
SELECT category, COUNT(*) as incident_count FROM incidents WHERE sector = 'Technology' AND category != 'Phishing' GROUP BY category;
What is the market share of hotels in Tokyo that have adopted hospitality AI, by total number of hotels?
CREATE TABLE hotels_tokyo (hotel_id INT,hotel_name TEXT,ai_adoption BOOLEAN); INSERT INTO hotels_tokyo (hotel_id,hotel_name,ai_adoption) VALUES (1,'Hotel Splendid',true),(2,'Hotel Excelsior',false),(3,'Hotel Grande',true);
SELECT (COUNT(*) FILTER (WHERE ai_adoption = true)) * 100.0 / COUNT(*) FROM hotels_tokyo;
What was the total revenue for the state of California in the year 2020 from dispensary sales?
CREATE TABLE DispensarySales (id INT,state VARCHAR(50),year INT,revenue FLOAT); INSERT INTO DispensarySales (id,state,year,revenue) VALUES (1,'California',2020,1200000.0),(2,'California',2019,900000.0),(3,'Colorado',2020,800000.0),(4,'Colorado',2019,600000.0);
SELECT SUM(revenue) FROM DispensarySales WHERE state = 'California' AND year = 2020;
Find the average number of visitors per month for all museums in Canada.
CREATE TABLE Museums (name VARCHAR(255),country VARCHAR(255),visitors_per_month DECIMAL(5,2));
SELECT AVG(visitors_per_month) FROM Museums WHERE country = 'Canada';
Update the drought_impact table to reflect the new drought severity
CREATE TABLE drought_impact (location VARCHAR(255),year INT,severity VARCHAR(255));
UPDATE drought_impact SET severity = 'Severe' WHERE location = 'City C' AND year = 2022;
What is the total number of eco-friendly hotels in London?
CREATE TABLE hotel (hotel_id INT,name TEXT,city TEXT,country TEXT,is_eco_friendly BOOLEAN); INSERT INTO hotel (hotel_id,name,city,country,is_eco_friendly) VALUES (1,'Green Hotel London','London','England',true);
SELECT COUNT(*) FROM hotel WHERE city = 'London' AND is_eco_friendly = true;
How many patients were treated by each therapist in New York?
CREATE TABLE therapists (therapist_id INT,state TEXT); INSERT INTO therapists (therapist_id,state) VALUES (1,'New York'),(2,'New York'),(3,'Texas'); CREATE TABLE therapist_patients (therapist_id INT,patient_id INT); INSERT INTO therapist_patients (therapist_id,patient_id) VALUES (1,1),(1,2),(1,3),(2,4),(2,5),(3,6);
SELECT therapists.state, therapists.therapist_id, COUNT(therapist_patients.patient_id) AS patient_count FROM therapists JOIN therapist_patients ON therapists.therapist_id = therapist_patients.therapist_id WHERE therapists.state = 'New York' GROUP BY therapists.therapist_id;
Show the total revenue generated by members from the LGBTQ+ community in the last month and their average spending on wellness products.
CREATE TABLE Members (MemberID INT,Community VARCHAR(20),Region VARCHAR(20)); INSERT INTO Members (MemberID,Community,Region) VALUES (11,'LGBTQ+','Northeast'); CREATE TABLE Transactions (TransactionID INT,MemberID INT,Service VARCHAR(20),Product VARCHAR(20),Amount DECIMAL(5,2)); INSERT INTO Transactions (TransactionID,MemberID,Service,Product,Amount) VALUES (1100,11,'Workout','Yoga Mat',50.00);
SELECT SUM(CASE WHEN Transactions.Product IS NOT NULL THEN Transactions.Amount ELSE 0 END) AS TotalRevenue, AVG(CASE WHEN Transactions.Product = 'Wellness Product' THEN Transactions.Amount ELSE 0 END) AS AverageSpending FROM Members INNER JOIN Transactions ON Members.MemberID = Transactions.MemberID WHERE Members.Community = 'LGBTQ+' AND Transactions.TransactionDate >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);
Which policies have been updated in the last month and are related to password complexity?
CREATE TABLE Policies (policy_id INT,policy_name VARCHAR(50),policy_date DATE,policy_category VARCHAR(50));
SELECT policy_id, policy_name FROM Policies WHERE policy_category = 'password complexity' AND policy_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) AND CURRENT_DATE;
What is the most common author gender in the 'authors' table?
CREATE TABLE authors (id INT,name VARCHAR(50),gender VARCHAR(10)); INSERT INTO authors (id,name,gender) VALUES (1,'Alice','Female'),(2,'Bob','Male'),(3,'Alex','Non-binary');
SELECT gender, COUNT(*) FROM authors GROUP BY gender ORDER BY COUNT(*) DESC LIMIT 1;
What is the average carbon offset (in metric tons) per smart city project?
CREATE TABLE carbon_offsets (project_id INT,project_name TEXT,offset_metric_tons FLOAT); INSERT INTO carbon_offsets (project_id,project_name,offset_metric_tons) VALUES (1,'Smart City A',1500),(2,'Smart City B',2000);
SELECT AVG(offset_metric_tons) FROM carbon_offsets;
What is the most common type of infectious disease in Alaska?
CREATE TABLE infectious_diseases (id INT,case_number INT,disease_type TEXT,state TEXT); INSERT INTO infectious_diseases (id,case_number,disease_type,state) VALUES (1,123,'Flu','Alaska'); INSERT INTO infectious_diseases (id,case_number,disease_type,state) VALUES (2,456,'COVID-19','Alaska');
SELECT disease_type, COUNT(*) FROM infectious_diseases WHERE state = 'Alaska' GROUP BY disease_type ORDER BY COUNT(*) DESC LIMIT 1;
Update the organic_produce to false for record with restaurant_id 123 in the sustainable_sourcing table
CREATE TABLE sustainable_sourcing (restaurant_id INT,organic_produce BOOLEAN);
UPDATE sustainable_sourcing SET organic_produce = false WHERE restaurant_id = 123;
What is the total number of deep-sea expeditions funded by each organization?
CREATE TABLE deep_sea_expeditions (org_name TEXT,expedition_id INTEGER); INSERT INTO deep_sea_expeditions (org_name,expedition_id) VALUES ('National Oceanic and Atmospheric Administration',123),('Woods Hole Oceanographic Institution',456),('National Geographic Society',789);
SELECT org_name, COUNT(expedition_id) as total_expeditions FROM deep_sea_expeditions GROUP BY org_name;
What is the average annual revenue generated by virtual tourism providers in Spain?
CREATE TABLE TourismProviders (provider_id INT,provider_name TEXT,country TEXT); INSERT INTO TourismProviders (provider_id,provider_name,country) VALUES (1,'Spain Virtual Tours','Spain'); INSERT INTO TourismProviders (provider_id,provider_name,country) VALUES (2,'Global Spain Tours','Spain'); CREATE TABLE VirtualTourRevenue (provider_id INT,annual_revenue INT); INSERT INTO VirtualTourRevenue (provider_id,annual_revenue) VALUES (1,800000); INSERT INTO VirtualTourRevenue (provider_id,annual_revenue) VALUES (2,1000000);
SELECT AVG(annual_revenue) FROM TourismProviders JOIN VirtualTourRevenue ON TourismProviders.provider_id = VirtualTourRevenue.provider_id WHERE country = 'Spain';
Which smart city technologies are adopted in 'CityA' in the 'SmartCityTechnologyAdoption' table?
CREATE TABLE SmartCityTechnologyAdoption (id INT,city VARCHAR(50),technology VARCHAR(50));
SELECT technology FROM SmartCityTechnologyAdoption WHERE city = 'CityA';
Show the total quantity of unsold garments by category.
CREATE TABLE Garments(id INT,name VARCHAR(100),quantity INT,category VARCHAR(50)); INSERT INTO Garments(id,name,quantity,category) VALUES (1,'Dress',20,'Women'); INSERT INTO Garments(id,name,quantity,category) VALUES (2,'Shirt',15,'Men');
SELECT category, SUM(quantity) FROM Garments WHERE quantity > 0 GROUP BY category;
What is the average age of farmers?
CREATE TABLE farmers (farmer_id INT PRIMARY KEY,name VARCHAR(255),age INT,location VARCHAR(255));
SELECT AVG(age) FROM farmers;
What is the total waste generation in the state of New Jersey?
CREATE TABLE waste_generation (state VARCHAR(2),generation INT); INSERT INTO waste_generation (state,generation) VALUES ('CA',5000000),('NY',4000000),('NJ',3000000);
SELECT SUM(generation) FROM waste_generation WHERE state = 'NJ';
Update the labor cost for Helicopter maintenance on Feb 15, 2020 to 750.
CREATE TABLE Maintenance (id INT,equipment VARCHAR(255),date DATE,labor INT,parts INT); INSERT INTO Maintenance (id,equipment,date,labor,parts) VALUES (1,'Tank','2020-01-05',500,200),(2,'Humvee','2020-01-10',300,150),(3,'Helicopter','2020-02-15',700,300),(4,'Airplane','2020-03-20',800,400);
UPDATE Maintenance SET labor = 750 WHERE equipment = 'Helicopter' AND date = '2020-02-15';
What is the total wastewater treatment capacity for each city in India?
CREATE TABLE wastewater_treatment_india(id INT,city VARCHAR(50),treatment_type VARCHAR(50),capacity INT,efficiency FLOAT); INSERT INTO wastewater_treatment_india(id,city,treatment_type,capacity,efficiency) VALUES (1,'Mumbai','Screening',1200,0.92);
SELECT city, SUM(capacity) as total_capacity FROM wastewater_treatment_india GROUP BY city;
What is the average annual salary for tech accessibility specialists in North America and Europe?
CREATE TABLE TechAccessibilitySpecs(role VARCHAR(255),region VARCHAR(255),salary DECIMAL(10,2));INSERT INTO TechAccessibilitySpecs(role,region,salary) VALUES('Tech Accessibility Specialist','North America',80000.00),('AI Ethics Expert','Europe',90000.00),('Tech Accessibility Specialist','Europe',95000.00),('AI Ethics Expert','North America',85000.00);
SELECT AVG(salary) FROM TechAccessibilitySpecs WHERE role = 'Tech Accessibility Specialist' AND region IN ('North America', 'Europe');
What was the maximum revenue for the state of California in the first quarter of 2022?
CREATE TABLE sales (id INT,state VARCHAR(50),quarter INT,revenue FLOAT); INSERT INTO sales (id,state,quarter,revenue) VALUES (1,'California',1,25000.0),(2,'California',2,30000.0),(3,'Colorado',1,20000.0),(4,'Colorado',2,22000.0);
SELECT MAX(revenue) FROM sales WHERE state = 'California' AND quarter = 1;
Find the minimum price of a property in a sustainable urbanism project in Boston with at least 2 co-owners.
CREATE TABLE property_prices (property_id INT,city VARCHAR(50),price INT); CREATE TABLE sustainable_urbanism (property_id INT,sustainable_project BOOLEAN); CREATE TABLE co_ownership (property_id INT,co_owner_count INT); INSERT INTO property_prices (property_id,city,price) VALUES (1,'Boston',800000),(2,'Portland',400000),(3,'Boston',1000000),(4,'Seattle',700000); INSERT INTO sustainable_urbanism (property_id) VALUES (1),(3); INSERT INTO co_ownership (property_id,co_owner_count) VALUES (1,2),(3,3);
SELECT MIN(price) FROM property_prices p JOIN sustainable_urbanism s ON p.property_id = s.property_id JOIN co_ownership c ON p.property_id = c.property_id WHERE p.city = 'Boston' AND c.co_owner_count > 1;
Update inventory records for ingredients used in the 'Veggie Delight' menu item to decrease their quantity by 5
CREATE TABLE inventory (inventory_id INT PRIMARY KEY,ingredient_name VARCHAR(255),quantity INT,reorder_threshold INT); CREATE TABLE menu_ingredients (menu_id INT,ingredient_name VARCHAR(255),quantity INT,PRIMARY KEY (menu_id,ingredient_name),FOREIGN KEY (ingredient_name) REFERENCES inventory(ingredient_name));
UPDATE inventory SET quantity = quantity - 5 WHERE inventory.ingredient_name IN (SELECT menu_ingredients.ingredient_name FROM menu_ingredients WHERE menu_ingredients.menu_id = (SELECT menu_id FROM menu_items WHERE item_name = 'Veggie Delight'));
What is the maximum number of publications for faculty members in the College of Education who are not tenured?
CREATE TABLE faculty_education (id INT,name VARCHAR(50),department VARCHAR(50),tenure_status VARCHAR(50),num_publications INT); INSERT INTO faculty_education (id,name,department,tenure_status,num_publications) VALUES (1,'Dana','College of Education','Not Tenured',7),(2,'Ella','College of Education','Tenured',12),(3,'Fiona','College of Education','Not Tenured',9);
SELECT MAX(num_publications) FROM faculty_education WHERE department = 'College of Education' AND tenure_status = 'Not Tenured';
List the total number of volunteers for each program in 2023, ordered by the total number of volunteers in descending order.
CREATE TABLE Programs (id INT,program_name VARCHAR(50),total_volunteers INT); CREATE TABLE VolunteerEvents (id INT,program_id INT,event_date DATE,total_volunteers INT);
SELECT Programs.program_name, SUM(VolunteerEvents.total_volunteers) AS total_volunteers_2023 FROM Programs INNER JOIN VolunteerEvents ON Programs.id = VolunteerEvents.program_id WHERE VolunteerEvents.event_date BETWEEN '2023-01-01' AND '2023-12-31' GROUP BY Programs.program_name ORDER BY total_volunteers_2023 DESC;
What are the names of animals in 'animal_population' table that are not present in 'protected_species' table?
CREATE TABLE animal_population (id INT,animal_name VARCHAR(50),population INT); CREATE TABLE protected_species (id INT,species_name VARCHAR(50)); INSERT INTO animal_population VALUES (1,'Elephant',1000);
SELECT DISTINCT ap.animal_name FROM animal_population ap LEFT JOIN protected_species ps ON ap.animal_name = ps.species_name WHERE ps.species_name IS NULL;
What is the total cost of maintenance for each type of vehicle in the past month?
CREATE TABLE VehicleTypes (VehicleTypeID INT,VehicleType VARCHAR(50)); INSERT INTO VehicleTypes (VehicleTypeID,VehicleType) VALUES (1,'Bus'),(2,'Tram'),(3,'Subway'); CREATE TABLE VehicleMaintenance (MaintenanceID INT,VehicleTypeID INT,Cost DECIMAL(5,2),MaintenanceDate DATE); INSERT INTO VehicleMaintenance (MaintenanceID,VehicleTypeID,Cost,MaintenanceDate) VALUES (1,1,1500.00,'2020-01-01'),(2,2,1200.00,'2019-12-15'),(3,1,1400.00,'2020-02-03');
SELECT VehicleType, SUM(Cost) FROM VehicleMaintenance INNER JOIN VehicleTypes ON VehicleMaintenance.VehicleTypeID = VehicleTypes.VehicleTypeID WHERE MaintenanceDate >= DATEADD(month, -1, GETDATE()) GROUP BY VehicleType;
Which vendors have a recycling program in place and are reducing waste?
CREATE TABLE sustainability (id INT,vendor VARCHAR(50),recycling_program BOOLEAN,waste_reduction BOOLEAN); INSERT INTO sustainability (id,vendor,recycling_program,waste_reduction) VALUES (4,'Local Produce',true,true),(5,'Farm Fresh',false,true),(6,'Organic Harvest',true,false);
SELECT vendor, CASE WHEN recycling_program THEN 'Yes' ELSE 'No' END as recycling_program, CASE WHEN waste_reduction THEN 'Yes' ELSE 'No' END as waste_reduction FROM sustainability WHERE recycling_program = 'True' AND waste_reduction = 'True';
What are the energy efficiency ratings for appliances in the appliances table produced by a specific manufacturer?
CREATE TABLE appliances (id INT,name VARCHAR(50),manufacturer VARCHAR(50),energy_rating FLOAT,created_at TIMESTAMP);
SELECT name, energy_rating FROM appliances WHERE manufacturer = 'XYZ' ORDER BY energy_rating DESC;
What is the minimum budget allocated for disability support programs in the 'Midwest' region?
CREATE TABLE DisabilitySupportPrograms (region VARCHAR(20),budget DECIMAL(5,2)); INSERT INTO DisabilitySupportPrograms (region,budget) VALUES ('East Coast',150000.00),('West Coast',200000.00),('Midwest',120000.00),('South',180000.00);
SELECT MIN(budget) FROM DisabilitySupportPrograms WHERE region = 'Midwest';
What is the maximum number of marine mammals spotted in a single day in the Pacific Ocean?
CREATE TABLE pacific_ocean_mammals (id INT,date DATE,marine_mammals_spotted INT);
SELECT MAX(marine_mammals_spotted) FROM pacific_ocean_mammals;
Show the top 2 states with the most green building certifications.
CREATE TABLE state_certifications (state VARCHAR(20),certifications INT); INSERT INTO state_certifications (state,certifications) VALUES ('California',500),('Texas',300),('Florida',400);
SELECT state, certifications FROM (SELECT state, certifications, RANK() OVER (ORDER BY certifications DESC) as rank FROM state_certifications) AS subquery WHERE rank <= 2;
What is the average speed of high-speed trains in Japan?
CREATE TABLE high_speed_trains (train_id INT,trip_start_time TIMESTAMP,trip_end_time TIMESTAMP,trip_distance FLOAT,country VARCHAR(50));
SELECT AVG(trip_distance / TIMESTAMP_DIFF(trip_end_time, trip_start_time, MINUTE)) as avg_speed FROM high_speed_trains WHERE country = 'Japan';
What is the total research grant amount awarded to each university, ordered from highest to lowest?
CREATE TABLE Universities (UniversityID int,UniversityName varchar(255)); CREATE TABLE ResearchGrants (GrantID int,UniversityID int,Amount int);
SELECT UniversityName, SUM(Amount) as TotalGrantAmount FROM ResearchGrants rg JOIN Universities u ON rg.UniversityID = u.UniversityID GROUP BY UniversityName ORDER BY TotalGrantAmount DESC;
What is the total number of fishing vessels in the 'Indian Ocean' that are over 20 years old?'
CREATE TABLE fishing_vessels (name VARCHAR(50),region VARCHAR(20),age INTEGER); INSERT INTO fishing_vessels (name,region,age) VALUES ('Vessel A','Indian Ocean',15),('Vessel B','Indian Ocean',25),('Vessel C','Atlantic',10);
SELECT COUNT(*) FROM fishing_vessels WHERE region = 'Indian Ocean' AND age > 20;
Find the number of wells drilled in each country and the total.
CREATE TABLE wells (well_id INT,country VARCHAR(50)); INSERT INTO wells (well_id,country) VALUES (1,'Canada'),(2,'USA'),(3,'Norway');
SELECT country, COUNT(*) as num_wells FROM wells GROUP BY country UNION ALL SELECT 'Total', COUNT(*) FROM wells;
Identify the top 5 volunteers with the most volunteer hours in 2022?
CREATE TABLE volunteers (id INT,name VARCHAR(50),volunteer_hours INT,volunteer_date DATE); INSERT INTO volunteers (id,name,volunteer_hours,volunteer_date) VALUES (1,'John Doe',10,'2022-01-05'),(2,'Jane Smith',15,'2022-01-05'),(3,'Bob Johnson',8,'2022-01-05'),(4,'John Doe',12,'2022-02-10'),(5,'Jane Smith',18,'2022-02-10'),(6,'Bob Johnson',20,'2022-02-10');
SELECT name, SUM(volunteer_hours) as total_hours FROM volunteers WHERE volunteer_date >= '2022-01-01' GROUP BY name ORDER BY total_hours DESC LIMIT 5;
What is the average digital divide index for each region?
CREATE TABLE Digital_Divide (region VARCHAR(50),index INT); INSERT INTO Digital_Divide (region,index) VALUES ('Africa',60),('Asia',50),('South America',40),('Europe',30),('North America',20);
SELECT region, AVG(index) as avg_index FROM Digital_Divide GROUP BY region;
How many cases of Measles and Hepatitis A were reported in Asian countries in 2020?
CREATE TABLE public.infectious_diseases (id SERIAL PRIMARY KEY,country TEXT,disease TEXT,year INT,cases INT); INSERT INTO public.infectious_diseases (country,disease,year,cases) VALUES ('India','Measles',2020,3456),('China','Hepatitis A',2020,5678),('Indonesia','Measles',2020,789);
SELECT country, disease, SUM(cases) FILTER (WHERE disease IN ('Measles', 'Hepatitis A') AND year = 2020) AS total_cases FROM public.infectious_diseases GROUP BY country, disease;
Add a new record to the "peacekeeping_operations" table for "Operation Restore Hope" in Somalia during 1993
CREATE TABLE peacekeeping_operations (operation_id INT PRIMARY KEY,operation_name VARCHAR(50),country VARCHAR(50),operation_year INT);
INSERT INTO peacekeeping_operations (operation_id, operation_name, country, operation_year) VALUES (1, 'Operation Restore Hope', 'Somalia', 1993);
Update the solar energy production record for New South Wales in 2025 to 15000 MWh
CREATE TABLE solar_energy (id INT,region VARCHAR(50),year INT,production FLOAT);
UPDATE solar_energy SET production = 15000 WHERE region = 'New South Wales' AND year = 2025;
Calculate the total retail sales for each country, excluding any duplicates based on the 'country' column in the 'RetailSales' table.
CREATE TABLE RetailSales (country VARCHAR(50),TotalSales DECIMAL(10,2)); INSERT INTO RetailSales (country,TotalSales) VALUES ('USA',12500.00),('Canada',7000.00),('USA',3000.00),('Brazil',9000.00);
SELECT country, SUM(TotalSales) FROM (SELECT DISTINCT country, TotalSales FROM RetailSales) AS A GROUP BY country;
How many virtual tours have been engaged with for hotels that have implemented AI-powered solutions?
CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,region TEXT); CREATE TABLE ai_solutions (solution_id INT,hotel_id INT,implemented_date DATE); CREATE TABLE virtual_tours (tour_id INT,hotel_id INT,engagement_score INT); INSERT INTO hotels (hotel_id,hotel_name,region) VALUES (1,'Luxury Resort','APAC'); INSERT INTO ai_solutions (solution_id,hotel_id,implemented_date) VALUES (1,1,'2021-01-01'); INSERT INTO virtual_tours (tour_id,hotel_id,engagement_score) VALUES (1,1,75);
SELECT COUNT(DISTINCT vt.hotel_id) AS total_tours_engaged FROM virtual_tours vt INNER JOIN hotels h ON vt.hotel_id = h.hotel_id INNER JOIN ai_solutions ai ON h.hotel_id = ai.hotel_id;
What was the total amount donated in Mexico in Q3 2021?
CREATE TABLE Donations (id INT,user_id INT,country VARCHAR(50),amount DECIMAL(10,2),donation_date DATE); INSERT INTO Donations (id,user_id,country,amount,donation_date) VALUES (1,101,'United States',50.00,'2022-01-02'); INSERT INTO Donations (id,user_id,country,amount,donation_date) VALUES (2,102,'Canada',75.00,'2022-01-05'); INSERT INTO Donations (id,user_id,country,amount,donation_date) VALUES (3,103,'Mexico',20.00,'2021-07-20');
SELECT SUM(amount) FROM Donations WHERE country = 'Mexico' AND donation_date BETWEEN '2021-07-01' AND '2021-09-30';
Identify the deepest underwater cave in the world.
CREATE TABLE underwater_caves (cave_name TEXT,max_depth_m INT); INSERT INTO underwater_caves (cave_name,max_depth_m) VALUES ('Hranice Abyss',4040),('Wakulla Springs',295),('Nohoch Nah Chich',134);
SELECT cave_name FROM underwater_caves ORDER BY max_depth_m DESC LIMIT 1;
How many mental health facilities are there in urban areas of the US?
CREATE TABLE facilities (id INT,name VARCHAR(50),location VARCHAR(20),type VARCHAR(20));
SELECT COUNT(*) FROM facilities WHERE location LIKE '%US%' AND location LIKE '%urban%' AND type = 'mental health';
What is the number of restaurants in Chicago with a menu price higher than $30?
CREATE TABLE restaurants (id INT,name TEXT,city TEXT,state TEXT,menu_price DECIMAL); INSERT INTO restaurants (id,name,city,state,menu_price) VALUES (1,'Restaurant A','Chicago','IL',40.00),(2,'Restaurant B','Chicago','IL',35.00),(3,'Restaurant C','St. Louis','MO',30.00);
SELECT COUNT(*) FROM restaurants WHERE city = 'Chicago' AND menu_price > 30;
Calculate the percentage of employees who identify as LGBTQ+, by department.
CREATE TABLE Employees (EmployeeID INT,Gender VARCHAR(10),Department VARCHAR(50)); INSERT INTO Employees (EmployeeID,Gender,Department) VALUES (1,'Male','HR'),(2,'Female','IT'),(3,'Non-binary','IT'),(4,'Transgender','HR');
SELECT Department, COUNT(CASE WHEN Gender IN ('Transgender', 'Non-binary') THEN 1 ELSE NULL END) * 100.0 / COUNT(*) AS Percentage_LGBTQ FROM Employees GROUP BY Department;
What is the total number of players who play VR games?
CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),VRGamePlayer BOOLEAN); INSERT INTO Players (PlayerID,Age,Gender,VRGamePlayer) VALUES (1,25,'Male',true),(2,30,'Female',false),(3,22,'Male',true);
SELECT SUM(VRGamePlayer) FROM Players;
How many investigative journalists in the "investigative_journalists" table are from the United States?
CREATE TABLE investigative_journalists (id INT,name VARCHAR(50),country VARCHAR(50),years_of_experience INT); INSERT INTO investigative_journalists (id,name,country,years_of_experience) VALUES (1,'John Doe','USA',10),(2,'Jane Smith','Canada',12),(3,'Pedro Martinez','Mexico',8);
SELECT COUNT(*) FROM investigative_journalists WHERE country = 'USA';
What is the total number of players by gender and how many players have no gender specified?
CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),Location VARCHAR(50),LastLogin DATETIME); INSERT INTO Players (PlayerID,Age,Gender,Location,LastLogin) VALUES (3,28,'Non-binary','Toronto','2021-06-03 13:45:00');
SELECT COALESCE(Gender, 'Not specified') AS Gender, COUNT(*) FROM Players GROUP BY Gender WITH ROLLUP;
Identify artists who performed in the same city multiple times in 'artist_performances' table?
CREATE TABLE artist_performances (performance_id INT,artist_id INT,city_id INT,date DATE);
SELECT artist_id, city_id, COUNT(*) as performances_in_city FROM artist_performances GROUP BY artist_id, city_id HAVING COUNT(*) > 1;
What is the total production of Neodymium in Australia in the past 5 years?
CREATE TABLE production (year INT,element VARCHAR(10),country VARCHAR(10),quantity INT); INSERT INTO production (year,element,country,quantity) VALUES (2016,'Neodymium','Australia',1200),(2017,'Neodymium','Australia',1400),(2018,'Neodymium','Australia',1600),(2019,'Neodymium','Australia',1800),(2020,'Neodymium','Australia',2000),(2021,'Neodymium','Australia',2200);
SELECT SUM(quantity) FROM production WHERE element = 'Neodymium' AND country = 'Australia' AND year BETWEEN (SELECT YEAR(CURDATE()) - 5) AND YEAR(CURDATE());
What is the minimum project timeline for residential building projects in Texas?
CREATE TABLE project_timeline (project_id INT,state VARCHAR(2),type VARCHAR(20),timeline INT); INSERT INTO project_timeline (project_id,state,type,timeline) VALUES (1,'TX','Residential',180);
SELECT MIN(timeline) FROM project_timeline WHERE state = 'TX' AND type = 'Residential';
How many sustainable tourism initiatives were implemented in Africa in 2020?
CREATE TABLE sustainable_tourism_initiatives (country VARCHAR(255),year INT,num_initiatives INT); INSERT INTO sustainable_tourism_initiatives (country,year,num_initiatives) VALUES ('Egypt',2020,50),('Kenya',2020,60),('South Africa',2020,70);
SELECT SUM(num_initiatives) FROM sustainable_tourism_initiatives WHERE country IN ('Egypt', 'Kenya', 'South Africa') AND year = 2020;
Find the top 3 volunteers who have donated the most.
CREATE TABLE volunteer_summary (vol_id INT,total_donations INT); INSERT INTO volunteer_summary (vol_id,total_donations) SELECT volunteer.vol_id,SUM(donation.donation_amount) FROM volunteer INNER JOIN donation ON volunteer.vol_id = donation.donor_id GROUP BY volunteer.vol_id;
SELECT vol_id, total_donations FROM volunteer_summary ORDER BY total_donations DESC LIMIT 3;
Which biosensor types were funded in the last 3 years?
CREATE TABLE biosensor_funding (fund_id INT,sensor_type VARCHAR(50),fund_date DATE); INSERT INTO biosensor_funding (fund_id,sensor_type,fund_date) VALUES (1,'Optical','2018-12-01'),(2,'Electrochemical','2019-05-15'),(3,'Piezoelectric','2020-08-30'),(4,'Thermal','2021-01-20');
SELECT sensor_type FROM biosensor_funding WHERE fund_date >= DATE_SUB(CURDATE(), INTERVAL 3 YEAR);
What is the average score of players who joined after January 2022 from the 'Action' genre?
CREATE TABLE games (id INT,name VARCHAR(255),genre VARCHAR(255),release_date DATE); INSERT INTO games (id,name,genre,release_date) VALUES (1,'GameA','Action','2021-06-01'); INSERT INTO games (id,name,genre,release_date) VALUES (2,'GameB','Simulation','2020-01-15'); INSERT INTO games (id,name,genre,release_date) VALUES (3,'GameC','Action','2022-03-20');
SELECT AVG(score) FROM players JOIN games ON players.game_id = games.id WHERE players.join_date > '2022-01-01' AND games.genre = 'Action';