instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the total number of items in storage across all warehouses in Mexico?
CREATE TABLE Warehouses(id INT,location VARCHAR(50),capacity INT); INSERT INTO Warehouses(id,location,capacity) VALUES (1,'Mexico',2500); CREATE TABLE Inventory(id INT,warehouse_id INT,quantity INT); INSERT INTO Inventory(id,warehouse_id,quantity) VALUES (1,1,1250);
SELECT SUM(Inventory.quantity) FROM Inventory INNER JOIN Warehouses ON Inventory.warehouse_id = Warehouses.id WHERE Warehouses.location = 'Mexico';
How many autonomous buses are operational in New York and Tokyo?
CREATE TABLE autonomous_buses (id INT,location VARCHAR(50),status VARCHAR(50));
SELECT SUM(CASE WHEN location IN ('New York', 'Tokyo') AND status = 'operational' THEN 1 ELSE 0 END) FROM autonomous_buses;
What is the total number of items delivered by each organization?
CREATE TABLE delivery (delivery_id INT,organization VARCHAR(100),num_items INT); INSERT INTO delivery (delivery_id,organization,num_items) VALUES (1,'Org A',5),(2,'Org B',10),(3,'Org A',15);
SELECT organization, SUM(num_items) FROM delivery GROUP BY organization;
What is the average age of community health workers by race and gender?
CREATE TABLE CommunityHealthWorkersRG (WorkerID INT,Age INT,Race VARCHAR(255),Gender VARCHAR(255)); INSERT INTO CommunityHealthWorkersRG (WorkerID,Age,Race,Gender) VALUES (1,35,'Hispanic','Female'),(2,40,'African American','Male'),(3,50,'Caucasian','Female'),(4,45,'Asian','Male');
SELECT Race, Gender, AVG(Age) as AvgAge FROM CommunityHealthWorkersRG GROUP BY Race, Gender;
Delete all records in the deep_sea_exploration table where the vessel is 'Titanic'
CREATE TABLE deep_sea_exploration (vessel TEXT,year INT); INSERT INTO deep_sea_exploration (vessel,year) VALUES ('Titanic',1912),('Trieste',1960),('Titanic',1985);
DELETE FROM deep_sea_exploration WHERE vessel = 'Titanic';
What is the average confidence score for AI models that focus on algorithmic fairness in South America?
CREATE TABLE algorithmic_fairness (id INT,model_name VARCHAR(255),country VARCHAR(255),confidence_score FLOAT); INSERT INTO algorithmic_fairness (id,model_name,country,confidence_score) VALUES (1,'FairModelA','Brazil',0.80),(2,'FairModelB','Argentina',0.85),(3,'FairModelC','Colombia',0.90);
SELECT AVG(confidence_score) FROM algorithmic_fairness WHERE country IN ('Brazil', 'Argentina', 'Colombia');
Display the total number of workers in each industry who have been employed for more than 5 years, in factories that have a workforce development program.
CREATE TABLE Factories (id INT,factory_name VARCHAR(50),workforce_development BOOLEAN); INSERT INTO Factories (id,factory_name,workforce_development) VALUES (1,'Workforce Factory A',TRUE); INSERT INTO Factories (id,factory_name,workforce_development) VALUES (2,'Non-Workforce Factory B',FALSE); CREATE TABLE Workers (id INT,factory_id INT,name VARCHAR(50),employment_duration INT,industry VARCHAR(50)); INSERT INTO Workers (id,factory_id,name,employment_duration,industry) VALUES (1,1,'John Doe',7,'manufacturing'); INSERT INTO Workers (id,factory_id,name,employment_duration,industry) VALUES (2,1,'Jane Smith',3,'technology'); INSERT INTO Workers (id,factory_id,name,employment_duration,industry) VALUES (3,2,'Mike Johnson',6,'manufacturing'); INSERT INTO Workers (id,factory_id,name,employment_duration,industry) VALUES (4,2,'Emily Brown',4,'technology');
SELECT Workers.industry, COUNT(Workers.id) FROM Workers INNER JOIN Factories ON Workers.factory_id = Factories.id WHERE Workers.employment_duration > 5 AND Factories.workforce_development = TRUE GROUP BY Workers.industry;
What is the average salary of employees in the marketing department, including those on maternity leave?
CREATE TABLE Employees (EmployeeID int,Department varchar(20),Salary int,LeaveStatus varchar(10)); INSERT INTO Employees (EmployeeID,Department,Salary,LeaveStatus) VALUES (1,'Marketing',70000,'Active'); INSERT INTO Employees (EmployeeID,Department,Salary,LeaveStatus) VALUES (2,'Marketing',75000,'Maternity');
SELECT AVG(Salary) FROM Employees WHERE Department = 'Marketing' AND LeaveStatus IN ('Active', 'Maternity');
How many local vendors have participated in sustainable events in Spain?
CREATE TABLE LocalVendors (VendorID INT,Country VARCHAR(50),Events INT); INSERT INTO LocalVendors (VendorID,Country,Events) VALUES (1,'Spain',3),(2,'Spain',2);
SELECT SUM(Events) FROM LocalVendors WHERE Country = 'Spain';
List all the wells in the Permian Basin with their respective production figures for 2020
CREATE TABLE if not exists wells (well_id int,region varchar(50),production_year int,oil_production int,gas_production int);INSERT INTO wells (well_id,region,production_year,oil_production,gas_production) VALUES (1,'Permian Basin',2020,220000,650000),(2,'Permian Basin',2019,175000,550000),(3,'Permian Basin',2018,150000,450000);
SELECT * FROM wells WHERE region = 'Permian Basin' AND production_year = 2020;
What was the minimum ticket price for an exhibition in London before 2020?
CREATE TABLE Exhibitions (id INT,city VARCHAR(50),year INT,ticket_price DECIMAL(5,2));INSERT INTO Exhibitions (id,city,year,ticket_price) VALUES (1,'London',2019,15.00),(2,'London',2018,10.00),(3,'Paris',2017,20.00);
SELECT MIN(ticket_price) FROM Exhibitions WHERE city = 'London' AND year < 2020;
Find labor productivity for Newmont Corp
CREATE TABLE productivity (id INT PRIMARY KEY,company VARCHAR(100),value DECIMAL(5,2));
SELECT value FROM productivity WHERE company = 'Newmont Corp';
Insert rainfall measurements from April 2022
CREATE TABLE rainfall (station_id INT,measurement_date DATE,rainfall_mm FLOAT);
INSERT INTO rainfall (station_id, measurement_date, rainfall_mm) VALUES (1, '2022-04-01', 12.5), (2, '2022-04-02', 15.3), (3, '2022-04-03', 8.9);
What is the total number of virtual tours in Germany and Switzerland?
CREATE TABLE virtual_tours (id INT,country VARCHAR(20),tours INT); INSERT INTO virtual_tours (id,country,tours) VALUES (1,'Germany',300),(2,'Switzerland',200),(3,'Austria',150);
SELECT SUM(tours) FROM virtual_tours WHERE country IN ('Germany', 'Switzerland');
How many vessels were in the US Gulf Coast region in January 2021?
CREATE TABLE vessel_movements (id INT,vessel_id INT,movement_date DATE,longitude FLOAT,latitude FLOAT); INSERT INTO vessel_movements (id,vessel_id,movement_date,longitude,latitude) VALUES (1,1,'2021-01-01',-89.40722,29.45344); INSERT INTO vessel_movements (id,vessel_id,movement_date,longitude,latitude) VALUES (2,2,'2021-01-15',-94.54836,29.21483);
SELECT COUNT(DISTINCT vessel_id) FROM vessel_movements WHERE movement_date BETWEEN '2021-01-01' AND '2021-01-31' AND longitude BETWEEN -104.13611 AND -84.40516;
How many marine mammal species are in the oceanography database?
CREATE TABLE marine_species (name TEXT,category TEXT); INSERT INTO marine_species (name,category) VALUES ('Blue Whale','Mammal'),('Dolphin','Mammal'),('Clownfish','Fish');
SELECT COUNT(*) FROM marine_species WHERE category = 'Mammal';
What is the total number of peacekeeping troops contributed by 'Brazil' to all peacekeeping missions in the last 7 years?
CREATE TABLE peacekeeping_troops (id INT,country TEXT,mission TEXT,contribution_date DATE,troops INT); INSERT INTO peacekeeping_troops (id,country,mission,contribution_date,troops) VALUES (1,'Brazil','Mission 1','2016-01-01',300);
SELECT SUM(troops) FROM peacekeeping_troops WHERE country = 'Brazil' AND contribution_date >= DATE_SUB(CURDATE(), INTERVAL 7 YEAR);
What are the environmental impact scores for each manufacturing site, grouped by quarter?
CREATE TABLE ManufacturingSite(Id INT,Name VARCHAR(50),Location VARCHAR(50)); CREATE TABLE EnvironmentalImpactScore(Id INT,Score INT,ManufacturingSiteId INT,ScoreDate DATE);
SELECT m.Name, DATE_FORMAT(e.ScoreDate, '%Y-%q') AS Quarter, AVG(e.Score) AS AverageScore FROM EnvironmentalImpactScore e JOIN ManufacturingSite m ON e.ManufacturingSiteId = m.Id GROUP BY m.Name, Quarter;
Show the number of safety tests performed in each location, broken down by brand
CREATE TABLE safety_tests (id INT PRIMARY KEY,company VARCHAR(255),brand VARCHAR(255),test_location VARCHAR(255),test_date DATE,safety_rating INT);
SELECT test_location, brand, COUNT(*) as total_tests FROM safety_tests GROUP BY test_location, brand;
Update the district of student 'Sofia' to 'HeartSchool' in the 'Student' table.
CREATE TABLE Student (StudentID INT,Name VARCHAR(20),District VARCHAR(20)); INSERT INTO Student (StudentID,Name,District) VALUES (1,'Sofia','MindSchool'); INSERT INTO Student (StudentID,Name,District) VALUES (2,'Ella','HeartSchool');
UPDATE Student SET District = 'HeartSchool' WHERE Name = 'Sofia';
Create a table named 'athlete_stats' to store athlete's statistics
CREATE TABLE athlete_stats (athlete_id INT,name VARCHAR(100),sport VARCHAR(50),height INT,weight INT);
CREATE TABLE athlete_stats (athlete_id INT, name VARCHAR(100), sport VARCHAR(50), height INT, weight INT);
What's the minimum donation amount made by donors from California in the year 2021?
CREATE TABLE Donors (DonorID INT,DonorName VARCHAR(100),DonationAmount DECIMAL(10,2),DonationDate DATE,DonorState VARCHAR(50));
SELECT MIN(DonationAmount) FROM Donors WHERE DonorState = 'California' AND YEAR(DonationDate) = 2021;
What is the total number of trips taken on public transportation in New York and Chicago?
CREATE TABLE public_transportation (trip_id INT,city VARCHAR(20),trips INT); INSERT INTO public_transportation (trip_id,city,trips) VALUES (1,'New York',500000),(2,'New York',600000),(3,'Chicago',400000),(4,'Chicago',300000);
SELECT city, SUM(trips) FROM public_transportation GROUP BY city;
List the names and locations of healthcare providers who have administered vaccines in underserved areas?
CREATE TABLE healthcare_providers (id INT,name VARCHAR(30),location VARCHAR(20),vaccine_administered INT); CREATE VIEW underserved_areas AS SELECT area_id FROM areas WHERE population_density < 500;
SELECT name, location FROM healthcare_providers JOIN underserved_areas ON healthcare_providers.location = underserved_areas.area_id;
Which platform generated the most revenue in the year 2018?
CREATE TABLE platforms (id INT,name TEXT);CREATE TABLE revenue (platform_id INT,year INT,amount FLOAT); INSERT INTO platforms (id,name) VALUES (1,'Platform A'),(2,'Platform B'),(3,'Platform C'); INSERT INTO revenue (platform_id,year,amount) VALUES (1,2018,50000),(2,2018,70000),(3,2018,60000),(1,2019,55000),(2,2019,60000),(3,2019,80000);
SELECT platforms.name, MAX(revenue.amount) FROM platforms JOIN revenue ON platforms.id = revenue.platform_id WHERE revenue.year = 2018 GROUP BY platforms.name ORDER BY MAX(revenue.amount) DESC LIMIT 1;
What is the minimum donation amount for each month in the year 2019?
CREATE TABLE donations (donation_id INT,donation_amount DECIMAL(10,2),donation_date DATE); INSERT INTO donations (donation_id,donation_amount,donation_date) VALUES (1,500.00,'2019-01-01'),(2,300.00,'2019-04-01'),(3,700.00,'2019-07-01'),(4,800.00,'2019-10-01');
SELECT MIN(donation_amount), DATE_FORMAT(donation_date, '%Y-%m') as month FROM donations GROUP BY month;
Insert a new record into the space_exploration table with the following data: mission_name = 'Mars 2020', launch_date = '2020-07-30', launch_site = 'Cape Canaveral Air Force Station'
CREATE TABLE space_exploration (mission_name VARCHAR(100),launch_date DATE,launch_site VARCHAR(100));
INSERT INTO space_exploration (mission_name, launch_date, launch_site) VALUES ('Mars 2020', '2020-07-30', 'Cape Canaveral Air Force Station');
What is the average number of hours spent on esports events by teams from South America?
CREATE TABLE EsportsTeamsSA (TeamID INT,TeamName VARCHAR(100),Country VARCHAR(50),HoursSpent DECIMAL(10,2)); INSERT INTO EsportsTeamsSA (TeamID,TeamName,Country,HoursSpent) VALUES (1,'Team Brazil','Brazil',120.00),(2,'Team Argentina','Argentina',140.00),(3,'Team Chile','Chile',160.00);
SELECT AVG(HoursSpent) FROM EsportsTeamsSA WHERE Country = 'South America';
What is the average score of players who have achieved more than 5 victories in the game 'Galactic Combat'?
CREATE TABLE Galactic_Combat (player_id INT,player_name VARCHAR(50),score INT,victories INT); INSERT INTO Galactic_Combat (player_id,player_name,score,victories) VALUES (1,'John Doe',1000,7),(2,'Jane Smith',1200,3),(3,'Maria Garcia',800,5);
SELECT AVG(score) FROM Galactic_Combat WHERE victories > 5;
How many properties in sustainable communities also appear in affordable housing schemes?
CREATE TABLE community_housing (community_id INT,property_id INT); INSERT INTO community_housing (community_id,property_id) VALUES (1,101),(1,102),(2,103),(2,104),(3,105); CREATE TABLE affordable_housing (property_id INT,price FLOAT); INSERT INTO affordable_housing (property_id,price) VALUES (101,500000.00),(103,600000.00),(104,700000.00),(105,800000.00);
SELECT COUNT(*) FROM community_housing JOIN affordable_housing ON community_housing.property_id = affordable_housing.property_id;
Which drugs were approved in 2021 and have sales figures below $300 million?
CREATE TABLE drug_approval (id INT,drug_name VARCHAR(255),approval_year INT,cost DECIMAL(10,2)); CREATE TABLE sales_figures (id INT,drug_name VARCHAR(255),sales DECIMAL(10,2)); INSERT INTO drug_approval (id,drug_name,approval_year,cost) VALUES (1,'DrugA',2018,1200.00),(2,'DrugB',2019,1500.00),(3,'DrugC',2020,2000.00),(4,'DrugD',2021,2500.00),(5,'DrugE',2021,3500.00); INSERT INTO sales_figures (id,drug_name,sales) VALUES (1,'DrugA',600000000.00),(2,'DrugB',700000000.00),(3,'DrugC',800000000.00),(4,'DrugF',200000000.00),(5,'DrugG',150000000.00);
SELECT drug_name FROM drug_approval JOIN sales_figures ON drug_approval.drug_name = sales_figures.drug_name WHERE drug_approval.approval_year = 2021 AND sales_figures.sales < 300000000;
What is the total population of indigenous communities in the Arctic region?
CREATE TABLE IndigenousCommunities (id INT PRIMARY KEY,name VARCHAR(100),population INT,region VARCHAR(100),language VARCHAR(100)); INSERT INTO IndigenousCommunities (id,name,population,region,language) VALUES (1,'Saami',80000,'Arctic','Northern Sami');
SELECT SUM(ic.population) FROM IndigenousCommunities ic WHERE ic.region = 'Arctic';
What is the average salary for employees who identify as LGBTQ+ in the HR department?
CREATE TABLE Employees (EmployeeID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50),HireDate DATE,Gender VARCHAR(10),SexualOrientation VARCHAR(20));
SELECT AVG(Salary) as AvgSalary FROM Employees WHERE Department = 'HR' AND SexualOrientation = 'LGBTQ+';
Insert a new excavation site in the 'sites' table
CREATE TABLE sites (id INT PRIMARY KEY,name TEXT,location TEXT,start_date DATE);
INSERT INTO sites (id, name, location, start_date) VALUES (1, 'Pompeii', 'Near Naples, Italy', '79-08-24');
List all marine species impacted by climate change in the Arctic.
CREATE TABLE marine_species (name TEXT,impact_climate TEXT,region TEXT); INSERT INTO marine_species (name,impact_climate,region) VALUES ('Polar Bear','Yes','Arctic'),('Walrus','Yes','Arctic'),('Starfish','No','Atlantic');
SELECT name FROM marine_species WHERE impact_climate = 'Yes' AND region = 'Arctic';
What is the average CO2 emission of buildings in the 'smart_cities' schema, grouped by city?
CREATE TABLE smart_cities.buildings (id INT,city VARCHAR(255),co2_emissions INT); CREATE VIEW smart_cities.buildings_view AS SELECT id,city,co2_emissions FROM smart_cities.buildings;
SELECT city, AVG(co2_emissions) FROM smart_cities.buildings_view GROUP BY city;
Get the names of all cruelty-free hair care products with a rating above 4
CREATE TABLE products (product_id INT,product_name VARCHAR(50),cruelty_free BOOLEAN,rating DECIMAL(2,1)); INSERT INTO products (product_id,product_name,cruelty_free,rating) VALUES (1,'shampoo',true,4.2),(2,'conditioner',false,3.5),(3,'hair serum',true,4.8),(4,'hair spray',false,4.0);
SELECT product_name FROM products WHERE cruelty_free = true AND rating > 4;
What is the average calorie count for vegetarian dishes?
CREATE TABLE meals (id INT,name TEXT,type TEXT,calories INT); INSERT INTO meals (id,name,type,calories) VALUES (1,'Quinoa Salad','vegetarian',350),(2,'Pizza Margherita','non_vegetarian',800),(3,'Veggie Burger','vegetarian',500);
SELECT AVG(calories) FROM meals WHERE type = 'vegetarian';
How many users engaged with AI-powered virtual concierges in 'Oceania'?
CREATE TABLE virtual_concierge_engagement (id INT,user_id INT,region TEXT); INSERT INTO virtual_concierge_engagement (id,user_id,region) VALUES (1,1001,'Oceania'),(2,1002,'Oceania'),(3,1003,'Americas'),(4,1004,'Americas'),(5,1005,'Africa');
SELECT region, COUNT(DISTINCT user_id) AS user_count FROM virtual_concierge_engagement WHERE region = 'Oceania' GROUP BY region;
What is the total revenue generated by each genre in the last 5 years?
CREATE TABLE songs (song_id INT,title TEXT,release_year INT,genre TEXT,revenue FLOAT);
SELECT genre, SUM(revenue) FROM songs WHERE release_year >= 2016 GROUP BY genre;
How many accessible taxi trips were provided in New York City in March 2022?
CREATE TABLE taxi_trips (trip_id INT,vehicle_type VARCHAR(10),is_accessible BOOLEAN,trip_date DATE); INSERT INTO taxi_trips VALUES (1,'Taxi',false,'2022-03-01'),(2,'Taxi',true,'2022-03-02'),(3,'Accessible Taxi',true,'2022-03-03');
SELECT COUNT(*) FROM taxi_trips WHERE vehicle_type = 'Accessible Taxi' AND trip_date BETWEEN '2022-03-01' AND '2022-03-31';
What is the average temperature in field_1 for the month of June?
CREATE TABLE field_1 (temperature FLOAT,date DATE); INSERT INTO field_1 (temperature,date) VALUES (23.5,'2021-06-01'),(25.3,'2021-06-02');
SELECT AVG(temperature) FROM field_1 WHERE EXTRACT(MONTH FROM date) = 6 AND field_1.date BETWEEN '2021-06-01' AND '2021-06-30';
What is the total energy generated by solar farms in Texas and New York?
CREATE TABLE solar_farms (id INT,state VARCHAR(255),energy_generated FLOAT); INSERT INTO solar_farms (id,state,energy_generated) VALUES (1,'Texas',1234.56),(2,'New York',6543.21),(3,'California',7890.12);
SELECT SUM(energy_generated) FROM solar_farms WHERE state IN ('Texas', 'New York');
What is the total number of disaster response drills performed by the police and fire departments in 2020?
CREATE TABLE drills (id SERIAL PRIMARY KEY,department VARCHAR(255),timestamp TIMESTAMP); INSERT INTO drills (department,timestamp) VALUES ('Police','2020-03-01 10:00:00'),('Fire','2020-03-01 14:00:00'),('Police','2020-06-15 16:00:00'),('Fire','2020-06-15 18:00:00');
SELECT COUNT(id) as total_drills FROM drills WHERE (department = 'Police' OR department = 'Fire') AND timestamp >= '2020-01-01 00:00:00' AND timestamp < '2021-01-01 00:00:00';
What was the earliest excavation date per site per year?
CREATE TABLE excavation_sites (site_id INT,site_name VARCHAR(50),country VARCHAR(50)); INSERT INTO excavation_sites (site_id,site_name,country) VALUES (1,'Site A','USA'); CREATE TABLE artifacts (artifact_id INT,site_id INT,excavation_date DATE);
SELECT e.site_name, EXTRACT(YEAR FROM a.excavation_date) as excavation_year, MIN(a.excavation_date) as earliest_date FROM excavation_sites e JOIN artifacts a ON e.site_id = a.site_id GROUP BY e.site_id, e.site_name, excavation_year ORDER BY site_id, excavation_year, earliest_date;
Find the number of hospitals and clinics in urban and rural areas separately
CREATE TABLE hospitals (id INT,name VARCHAR(50),location VARCHAR(10)); INSERT INTO hospitals VALUES (1,'H1','urban'); INSERT INTO hospitals VALUES (2,'H2','rural')
SELECT COUNT(*) FROM hospitals WHERE location = 'urban' UNION ALL SELECT COUNT(*) FROM hospitals WHERE location = 'rural'
What is the total quantity of product 4 in the circular supply chain?
CREATE TABLE circular_supply_chain (product_id INT,supplier_id INT,retailer_id INT,quantity INT); INSERT INTO circular_supply_chain (product_id,supplier_id,retailer_id,quantity) VALUES (4,4,4,120);
SELECT SUM(quantity) AS total_quantity FROM circular_supply_chain WHERE product_id = 4;
Update the historical context to 'Medieval artifact' for 'artifact_4' in the 'artifact_analysis' table.
CREATE TABLE artifact_analysis (id INT PRIMARY KEY,artifact_name VARCHAR(50),historical_context TEXT); INSERT INTO artifact_analysis (id,artifact_name,historical_context) VALUES (1,'artifact_1','Iron Age weapon'),(2,'artifact_2','Roman Empire coin'),(3,'artifact_3','Stone Age tool'),(4,'artifact_4','Ancient artifact');
UPDATE artifact_analysis SET historical_context = 'Medieval artifact' WHERE artifact_name = 'artifact_4';
What is the total number of indigenous food systems that have adopted sustainable practices, and what is the average size of these systems in hectares?
CREATE TABLE sustainable_indigenous_food_systems (id INT,name VARCHAR(255),size FLOAT,uses_sustainable_practices BOOLEAN); INSERT INTO sustainable_indigenous_food_systems (id,name,size,uses_sustainable_practices) VALUES (1,'System A',12.5,TRUE),(2,'System B',20.0,FALSE),(3,'System C',5.5,TRUE);
SELECT COUNT(*) as total_systems, AVG(size) as avg_size FROM sustainable_indigenous_food_systems WHERE uses_sustainable_practices = TRUE;
What is the total attendance at cultural events in New York?
CREATE TABLE events (id INT,name TEXT,location TEXT,attendance INT); INSERT INTO events (id,name,location,attendance) VALUES (1,'Festival A','New York',5000),(2,'Conference B','London',3000),(3,'Exhibition C','New York',7000);
SELECT SUM(attendance) FROM events WHERE location = 'New York';
What traditional art forms are present in Southeast Asian countries?
CREATE TABLE TraditionalArts (id INT,name VARCHAR(255),country VARCHAR(255)); INSERT INTO TraditionalArts (id,name,country) VALUES (1,'Wayang Golek','Indonesia'),(2,'Batik','Indonesia'),(3,'Khon','Thailand');
SELECT TraditionalArts.name FROM TraditionalArts WHERE TraditionalArts.country IN ('Indonesia', 'Thailand', 'Malaysia', 'Philippines', 'Singapore');
List all unique schools in the 'Students' table
SELECT DISTINCT School FROM Students;
SELECT DISTINCT School FROM Students;
What is the total number of students enrolled in each course by subject area?
CREATE TABLE subject_areas (id INT,name VARCHAR(255)); CREATE TABLE courses (id INT,subject_area_id INT,name VARCHAR(255)); CREATE TABLE enrollments (id INT,student_id INT,course_id INT); INSERT INTO subject_areas (id,name) VALUES (1,'Mathematics'),(2,'Science'),(3,'Humanities'); INSERT INTO courses (id,subject_area_id,name) VALUES (1,1,'Algebra'),(2,1,'Geometry'),(3,2,'Biology'),(4,2,'Chemistry'),(5,3,'History'),(6,3,'Literature'); INSERT INTO enrollments (id,student_id,course_id) VALUES (1,1,1),(2,2,1),(3,3,1),(4,1,2),(5,2,3),(6,3,3),(7,1,4),(8,2,4),(9,3,4),(10,1,5),(11,2,5),(12,3,5),(13,1,6),(14,2,6),(15,3,6);
SELECT sa.name AS subject_area, c.name AS course_name, COUNT(e.id) AS num_students FROM subject_areas sa JOIN courses c ON sa.id = c.subject_area_id JOIN enrollments e ON c.id = e.course_id GROUP BY sa.name, c.name;
What is the total runtime (in minutes) of all the movies in the movies table that have a runtime greater than the average runtime?
CREATE TABLE movies (id INT,title TEXT,runtime INT);
SELECT SUM(runtime) FROM movies WHERE runtime > (SELECT AVG(runtime) FROM movies);
Which disability advocacy policies were implemented in each region?
CREATE TABLE Advocacy_Policies (Policy_ID INT,Policy_Name VARCHAR(50),Policy_Description TEXT,Region VARCHAR(50));
SELECT Region, Policy_Name FROM Advocacy_Policies;
What is the total CO2 emission reduction for carbon offset programs in the United States?
CREATE TABLE us_carbon_offset_programs (id INT,country VARCHAR(255),name VARCHAR(255),co2_reduction FLOAT); INSERT INTO us_carbon_offset_programs (id,country,name,co2_reduction) VALUES (1,'United States','Program A',1234.5),(2,'United States','Program B',2345.6);
SELECT SUM(co2_reduction) FROM us_carbon_offset_programs WHERE country = 'United States';
What is the total transaction amount for each customer in the Southeast region?
CREATE TABLE customers (id INT,name VARCHAR(50),region VARCHAR(50)); INSERT INTO customers (id,name,region) VALUES (1,'John Doe','Southeast'),(2,'Jane Smith','Northeast'); CREATE TABLE transactions (customer_id INT,transaction_amount DECIMAL(10,2)); INSERT INTO transactions (customer_id,transaction_amount) VALUES (1,200.00),(1,300.00),(2,100.00);
SELECT c.name, SUM(t.transaction_amount) as total_transaction_amount FROM customers c JOIN transactions t ON c.id = t.customer_id WHERE c.region = 'Southeast' GROUP BY c.name;
Count the number of policies in the 'commercial_policy' table for each unique city
CREATE TABLE commercial_policy (policy_number INT,policy_holder_name VARCHAR(50),city VARCHAR(20)); INSERT INTO commercial_policy (policy_number,policy_holder_name,city) VALUES (1001,'ABC Inc.','New York'),(1002,'XYZ Inc.','Los Angeles'),(1003,'DEF Inc.','Chicago');
SELECT city, COUNT(DISTINCT policy_number) FROM commercial_policy GROUP BY city;
What is the total revenue generated from freight forwarding for North American customers in Q1 2022?
CREATE TABLE FreightForwarding (id INT,customer VARCHAR(255),revenue FLOAT,region VARCHAR(255),quarter INT,year INT); INSERT INTO FreightForwarding (id,customer,revenue,region,quarter,year) VALUES (1,'ABC Corp',5000,'North America',1,2022);
SELECT SUM(revenue) FROM FreightForwarding WHERE region = 'North America' AND quarter = 1 AND year = 2022;
What is the total stock of tilapia in recirculating aquaculture systems in Kenya?
CREATE TABLE fish_stock (id INT,species TEXT,quantity INT,system_type TEXT,country TEXT); INSERT INTO fish_stock (id,species,quantity,system_type,country) VALUES (1,'Tilapia',1500,'Recirculating','Kenya'); INSERT INTO fish_stock (id,species,quantity,system_type,country) VALUES (2,'Tilapia',2000,'Flow-through','Kenya'); INSERT INTO fish_stock (id,species,quantity,system_type,country) VALUES (3,'Tilapia',1000,'Recirculating','Kenya');
SELECT SUM(quantity) FROM fish_stock WHERE species = 'Tilapia' AND country = 'Kenya' AND system_type = 'Recirculating';
What is the latest discovery date and the discovery details for each exoplanet in the exoplanets table?
CREATE TABLE exoplanets (discovery_date DATE,discovery_details VARCHAR(100),planet_name VARCHAR(50),host_star VARCHAR(50)); INSERT INTO exoplanets VALUES ('2004-06-07','Kepler 186f discovered','Kepler 186f','Kepler 186'),('2010-08-26','Gliese 581g discovered','Gliese 581g','Gliese 581'),('2012-04-18','Kepler 22b discovered','Kepler 22b','Kepler 22');
SELECT discovery_date, discovery_details, ROW_NUMBER() OVER (PARTITION BY discovery_date ORDER BY discovery_date DESC) as rank FROM exoplanets WHERE rank = 1;
What is the total revenue for the current year for each telecom region?
CREATE TABLE revenue (region VARCHAR(255),revenue_amount FLOAT,year INT); INSERT INTO revenue (region,revenue_amount,year) VALUES ('Northeast',5000000,2021),('Southeast',6000000,2021);
SELECT region, SUM(revenue_amount) FROM revenue WHERE year = YEAR(CURDATE()) GROUP BY region;
Calculate the average attendance for events with a budget over $100,000 and compare it to the overall average attendance.
CREATE TABLE events (id INT,name VARCHAR(255),type VARCHAR(255),budget INT,attendance INT); INSERT INTO events (id,name,type,budget,attendance) VALUES (1,'Expensive Showcase','dance',150000,500),(2,'Cheap Festival','music',10000,300),(3,'Moderate Exhibition','visual arts',75000,400);
SELECT AVG(attendance) FILTER (WHERE budget > 100000) AS avg_attendance_over_100k, AVG(attendance) AS overall_avg_attendance FROM events
What's the max CO2 offset for green building certification?
CREATE TABLE green_buildings_max_offset (id INT,name VARCHAR(255),certification VARCHAR(255),co2_offset FLOAT);
SELECT MAX(co2_offset) FROM green_buildings_max_offset WHERE certification IS NOT NULL;
Which climate mitigation projects have a budget over '400000'?
CREATE TABLE climate_mitigation (project_id INTEGER,project_name TEXT,budget INTEGER); INSERT INTO climate_mitigation (project_id,project_name,budget) VALUES (1,'Project K',500000),(2,'Project L',300000);
SELECT project_name FROM climate_mitigation WHERE budget > 400000;
How many monitoring stations are there in the 'monitoring_stations' table, and what is their total operational cost?
CREATE TABLE monitoring_stations (station_id INT,station_name VARCHAR(50),country VARCHAR(50),operational_cost FLOAT); INSERT INTO monitoring_stations (station_id,station_name,country,operational_cost) VALUES (1,'Station A','Australia',50000.0),(2,'Station B','New Zealand',60000.0);
SELECT COUNT(station_id), SUM(operational_cost) FROM monitoring_stations;
Which defense diplomacy events involved international organizations in the last 5 years?
CREATE TABLE defense_diplomacy (id INT PRIMARY KEY,event_name VARCHAR(255),event_date DATE); CREATE TABLE international_org (id INT PRIMARY KEY,name VARCHAR(255)); INSERT INTO defense_diplomacy (id,event_name,event_date) VALUES (1,'Summit A','2017-01-01'),(2,'Summit B','2018-01-01'),(3,'Conference C','2019-01-01'),(4,'Forum D','2020-01-01'),(5,'Meeting E','2021-01-01'); INSERT INTO international_org (id,name) VALUES (1,'UN'),(2,'NATO'),(3,'AU'),(4,'ASEAN'),(5,'EU');
SELECT defense_diplomacy.event_name, international_org.name FROM defense_diplomacy JOIN international_org ON YEAR(defense_diplomacy.event_date) - YEAR(international_org.name) >= 5;
What is the maximum depth recorded for any marine species in the Indian Ocean?
CREATE TABLE marine_species (name TEXT,max_depth FLOAT,ocean TEXT); CREATE TABLE ocean_regions (name TEXT,area FLOAT);
SELECT MAX(max_depth) FROM marine_species WHERE ocean = (SELECT name FROM ocean_regions WHERE area = 'Indian Ocean');
List all movies directed by women from Asian countries and their release years.
CREATE TABLE movies (id INT,title TEXT,release_year INT,director TEXT); INSERT INTO movies (id,title,release_year,director) VALUES (1,'MovieA',2010,'Director1'),(2,'MovieB',2015,'Director2'); CREATE TABLE directors (id INT,name TEXT,country TEXT); INSERT INTO directors (id,name,country) VALUES (1,'Director1','Japan'),(2,'Director2','Korea');
SELECT movies.title, release_year, directors.name, directors.country FROM movies INNER JOIN directors ON movies.director = directors.name WHERE directors.country IN ('Japan', 'Korea', 'China', 'India', 'Indonesia');
What is the total quantity of cargo handled by each port?
CREATE TABLE ports (port_id INT,port_name VARCHAR(50),quantity_cargo_handled INT); INSERT INTO ports (port_id,port_name,quantity_cargo_handled) VALUES (1,'PortA',5000),(2,'PortB',7000),(3,'PortC',3000);
SELECT port_name, SUM(quantity_cargo_handled) FROM ports GROUP BY port_name;
What is the total energy efficiency (in %) for the industrial sector, in the energy_efficiency_by_sector table, for the year 2025?
CREATE TABLE energy_efficiency_by_sector (sector VARCHAR(255),year INT,efficiency DECIMAL(4,2)); INSERT INTO energy_efficiency_by_sector (sector,year,efficiency) VALUES ('Residential',2018,45.6),('Commercial',2019,56.7),('Industrial',2020,67.8),('Transportation',2021,78.9),('Residential',2022,89.0),('Commercial',2023,90.1),('Industrial',2024,91.2),('Transportation',2025,92.3);
SELECT SUM(efficiency) as total_efficiency FROM energy_efficiency_by_sector WHERE sector = 'Industrial' AND year = 2025;
How many electronic songs were released in 2020 that have more than 7000 streams?
CREATE TABLE songs (song_id INT,genre VARCHAR(20),release_year INT,streams INT); INSERT INTO songs (song_id,genre,release_year,streams) VALUES (1,'electronic',2020,8000); INSERT INTO songs (song_id,genre,release_year,streams) VALUES (2,'electronic',2020,9000); INSERT INTO songs (song_id,genre,release_year,streams) VALUES (3,'electronic',2020,7500);
SELECT COUNT(*) FROM songs WHERE genre = 'electronic' AND release_year = 2020 AND streams > 7000;
What is the minimum weight of packages shipped from Europe to any Asian country in the last year?
CREATE TABLE package_europe_asia (id INT,package_weight FLOAT,shipped_from VARCHAR(20),shipped_to VARCHAR(20),shipped_date DATE); INSERT INTO package_europe_asia (id,package_weight,shipped_from,shipped_to,shipped_date) VALUES (1,1.2,'Germany','China','2021-12-29');
SELECT MIN(package_weight) FROM package_europe_asia WHERE shipped_from LIKE 'Europe%' AND shipped_to LIKE 'Asia%' AND shipped_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR);
What is the minimum budget for military innovation programs for Southeast Asian countries in 2022?
CREATE TABLE MilitaryInnovation (country VARCHAR(50),year INT,budget FLOAT); INSERT INTO MilitaryInnovation (country,year,budget) VALUES ('Indonesia',2022,400000000),('Thailand',2022,250000000),('Malaysia',2022,300000000),('Singapore',2022,500000000),('Vietnam',2022,380000000);
SELECT MIN(budget) FROM MilitaryInnovation WHERE country IN ('Indonesia', 'Thailand', 'Malaysia', 'Singapore', 'Vietnam') AND year = 2022;
What is the total number of AI models created for creative applications, by month, in the year 2022?
CREATE TABLE CreativeAIs (ID INT,AI VARCHAR(255),Type VARCHAR(255),Date DATE); INSERT INTO CreativeAIs (ID,AI,Type,Date) VALUES (1,'AI1','Creative','2022-01-01'),(2,'AI2','Non-Creative','2022-01-05'),(3,'AI3','Creative','2022-02-12'),(4,'AI4','Creative','2022-03-01'),(5,'AI5','Non-Creative','2022-03-05'),(6,'AI6','Creative','2022-04-01'),(7,'AI7','Creative','2022-05-01'),(8,'AI8','Non-Creative','2022-05-05'),(9,'AI9','Creative','2022-06-01');
SELECT EXTRACT(MONTH FROM Date) as Month, COUNT(*) as Total_AI_Models FROM CreativeAIs WHERE Type = 'Creative' AND Date BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY Month;
Update the name of the heritage site with SiteID 5 to 'Hawaii Volcanoes National Park'.
CREATE TABLE HeritageSites (SiteID INT PRIMARY KEY,SiteName VARCHAR(100),Country VARCHAR(50),Region VARCHAR(50));
UPDATE HeritageSites SET SiteName = 'Hawaii Volcanoes National Park' WHERE SiteID = 5;
What is the maximum bridge length in the transport division?
CREATE TABLE Projects (id INT,division VARCHAR(10)); INSERT INTO Projects (id,division) VALUES (1,'water'),(2,'transport'),(3,'energy'); CREATE TABLE TransportProjects (id INT,project_id INT,length DECIMAL(10,2)); INSERT INTO TransportProjects (id,project_id,length) VALUES (1,2,500),(2,2,550),(3,3,600);
SELECT MAX(t.length) FROM TransportProjects t JOIN Projects p ON t.project_id = p.id WHERE p.division = 'transport';
Find the number of eco-certified accommodations in Asia and Europe
CREATE TABLE accommodations (id INT,region VARCHAR(255),eco_certified INT); INSERT INTO accommodations (id,region,eco_certified) VALUES (1,'Asia',1),(2,'Asia',0),(3,'Europe',1),(4,'Europe',1),(5,'South America',0);
SELECT region, SUM(eco_certified) as eco_certified_count FROM accommodations WHERE region IN ('Asia', 'Europe') GROUP BY region;
List the top 2 cruelty-free brands by sales in the UK.
CREATE TABLE Brands (BrandID INT,BrandName VARCHAR(100),IsCrueltyFree BOOLEAN,TotalSales DECIMAL(10,2)); INSERT INTO Brands (BrandID,BrandName,IsCrueltyFree,TotalSales) VALUES (1,'Brand X',true,5000),(2,'Brand Y',false,6000),(3,'Brand Z',true,4000),(4,'Brand W',false,7000),(5,'Brand V',true,3000);
SELECT BrandName, IsCrueltyFree, TotalSales FROM (SELECT BrandName, IsCrueltyFree, TotalSales, ROW_NUMBER() OVER (PARTITION BY IsCrueltyFree ORDER BY TotalSales DESC) as rn FROM Brands WHERE Country = 'UK') t WHERE rn <= 2;
What is the total renewable energy capacity (in MW) for each country?
CREATE TABLE renewable_energy (country VARCHAR(50),capacity INT); INSERT INTO renewable_energy (country,capacity) VALUES ('US',220000);
SELECT country, SUM(capacity) as total_capacity FROM renewable_energy GROUP BY country;
What is the total financial wellbeing program budget for each organization in North America that launched programs before 2017 and had a budget greater than $750,000?
CREATE TABLE FinancialWellbeingNA (id INT,org_name VARCHAR(50),location VARCHAR(50),launch_date DATE,budget DECIMAL(10,2));
SELECT org_name, SUM(budget) as total_budget FROM FinancialWellbeingNA WHERE location LIKE '%North America%' AND launch_date < '2017-01-01' AND budget > 750000 GROUP BY org_name;
What is the average sustainable material cost for manufacturers in India?
CREATE TABLE Manufacturers (ManufacturerID INT,ManufacturerName VARCHAR(50),Location VARCHAR(50),Cost DECIMAL(5,2)); CREATE TABLE Materials (MaterialID INT,MaterialName VARCHAR(50),Type VARCHAR(50)); INSERT INTO Materials (MaterialID,MaterialName,Type) VALUES (1,'Organic Cotton','Sustainable'); INSERT INTO Manufacturers (ManufacturerID,ManufacturerName,Location,Cost) VALUES (1,'Manufacturer A','India',12.50),(2,'Manufacturer B','China',15.00),(3,'Manufacturer C','India',10.00); CREATE TABLE ManufacturerMaterials (ManufacturerID INT,MaterialID INT,Quantity INT); INSERT INTO ManufacturerMaterials (ManufacturerID,MaterialID,Quantity) VALUES (1,1,500),(2,1,750),(3,1,600);
SELECT AVG(Manufacturers.Cost) FROM Manufacturers JOIN ManufacturerMaterials ON Manufacturers.ManufacturerID = ManufacturerMaterials.ManufacturerID JOIN Materials ON ManufacturerMaterials.MaterialID = Materials.MaterialID WHERE Materials.Type = 'Sustainable' AND Manufacturers.Location = 'India';
Update the 'renewable_energy' department's average salary to $38,000.
CREATE TABLE company_departments (dept_name TEXT,avg_salary NUMERIC); INSERT INTO company_departments (dept_name,avg_salary) VALUES ('renewable_energy',36000.00);
UPDATE company_departments SET avg_salary = 38000.00 WHERE dept_name = 'renewable_energy';
What is the total revenue generated by ticket sales for each month and team?
CREATE TABLE monthly_ticket_sales (ticket_id INT,team_id INT,date DATE,price INT);
SELECT EXTRACT(MONTH FROM date) as month, team_id, SUM(price) as total_revenue FROM monthly_ticket_sales GROUP BY month, team_id;
Find the top 2 tunnels with the highest maintenance costs in the 'Southeast' region, for the year 2021.
CREATE TABLE Tunnels (TunnelID INT,Name VARCHAR(255),Region VARCHAR(255),MaintenanceCost DECIMAL(10,2),Year INT);
SELECT * FROM ( SELECT *, ROW_NUMBER() OVER (PARTITION BY Region ORDER BY MaintenanceCost DESC) as rank FROM Tunnels WHERE Year = 2021 AND Region = 'Southeast') sub WHERE rank <= 2;
Insert data into the 'auto_show' table
CREATE TABLE auto_show (id INT PRIMARY KEY,show_name VARCHAR(255),location VARCHAR(255),start_date DATE,end_date DATE);
INSERT INTO auto_show (id, show_name, location, start_date, end_date) VALUES (1, 'Paris Motor Show', 'Paris, France', '2023-10-01', '2023-10-15');
How many genetic research projects are in France?
CREATE SCHEMA genetics; CREATE TABLE genetics.projects (id INT,name VARCHAR(100),country VARCHAR(50)); INSERT INTO genetics.projects (id,name,country) VALUES (1,'ProjectA','France'); INSERT INTO genetics.projects (id,name,country) VALUES (2,'ProjectB','France'); INSERT INTO genetics.projects (id,name,country) VALUES (3,'ProjectC','France');
SELECT COUNT(*) FROM genetics.projects WHERE country = 'France';
List all wildlife habitats that have experienced a population decrease since 2019
CREATE TABLE wildlife_population (id INT,name VARCHAR(255),population INT,year INT);
SELECT w1.* FROM wildlife_population w1 INNER JOIN (SELECT name, MAX(year) AS latest_year FROM wildlife_population GROUP BY name) w2 ON w1.name = w2.name AND w1.year < w2.latest_year AND w1.population < (SELECT population FROM wildlife_population w3 WHERE w3.name = w1.name AND w3.year = w2.latest_year);
Determine the number of machines in each ethical manufacturing facility that use renewable energy sources and the percentage of machines using renewable energy, sorted by the percentage in descending order.
CREATE TABLE ethical_manufacturing_facilities (id INT PRIMARY KEY,facility_name VARCHAR(255),location VARCHAR(255),total_machines INT,renewable_energy BOOLEAN); INSERT INTO ethical_manufacturing_facilities (id,facility_name,location,total_machines,renewable_energy) VALUES (1,'Facility A','City A',100,true),(2,'Facility B','City B',120,false),(3,'Facility C','City C',80,true),(4,'Facility D','City D',150,false),(5,'Facility E','City E',90,true);
SELECT facility_name, location, total_machines, 100.0 * SUM(renewable_energy) / COUNT(*) as percentage FROM ethical_manufacturing_facilities GROUP BY facility_name, location ORDER BY percentage DESC;
How many marine research projects were conducted in the Southern Ocean in 2020?
CREATE TABLE marine_research (id INT,name VARCHAR(255),ocean VARCHAR(255),year INT); INSERT INTO marine_research (id,name,ocean,year) VALUES (1,'Antarctic Wildlife Study','Southern Ocean',2018),(2,'Marine Life Census','Southern Ocean',2020);
SELECT COUNT(*) FROM marine_research WHERE ocean = 'Southern Ocean' AND year = 2020;
Which fish species have the highest market value?
CREATE TABLE FishSpecies (SpeciesName VARCHAR(50),MarketValue FLOAT); INSERT INTO FishSpecies VALUES ('Bluefin Tuna',3000),('Salmon',250),('Cod',120),('Sardines',25);
SELECT SpeciesName, MarketValue FROM FishSpecies ORDER BY MarketValue DESC LIMIT 1;
What is the total production of wheat by continent?
CREATE TABLE Continent (id INT,name VARCHAR(255)); INSERT INTO Continent (id,name) VALUES (1,'Africa'),(2,'Asia'),(3,'Europe'),(4,'North America'),(5,'South America'); CREATE TABLE Crop (id INT,name VARCHAR(255),continent_id INT,production INT); INSERT INTO Crop (id,name,continent_id,production) VALUES (1,'Wheat',3,800),(2,'Rice',2,1200),(3,'Wheat',5,600);
SELECT SUM(Crop.production) FROM Crop INNER JOIN Continent ON Crop.continent_id = Continent.id WHERE Crop.name = 'Wheat';
What is the percentage of readers who prefer news on technology?
CREATE TABLE readers (id INT,name VARCHAR(50),age INT,topic VARCHAR(50)); INSERT INTO readers (id,name,age,topic) VALUES (1,'John Doe',35,'technology'),(2,'Jane Smith',40,'politics');
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM readers)) AS percentage FROM readers WHERE topic = 'technology';
List the defense projects and their timelines for the Asia-Pacific region, with the earliest start and end dates.
CREATE TABLE DefenseProjects (project_name VARCHAR(50),region VARCHAR(50),start_date DATE,end_date DATE);
SELECT project_name, region, MIN(start_date) AS earliest_start_date, MIN(end_date) AS earliest_end_date FROM DefenseProjects WHERE region = 'Asia-Pacific' GROUP BY project_name, region;
What are the total CO2 emissions for each manufacturing plant in the past quarter?
CREATE TABLE ManufacturingPlants (id INT,plant_name VARCHAR(255),location VARCHAR(255)); CREATE TABLE Emissions (id INT,plant_id INT,CO2_emissions FLOAT,emission_date DATE);
SELECT ManufacturingPlants.plant_name, SUM(Emissions.CO2_emissions) as total_CO2_emissions FROM ManufacturingPlants INNER JOIN Emissions ON ManufacturingPlants.id = Emissions.plant_id WHERE Emissions.emission_date >= DATEADD(quarter, -1, GETDATE()) GROUP BY ManufacturingPlants.plant_name;
What is the total watch time of all educational videos by users in the United States?
CREATE TABLE users (id INT,country VARCHAR(50)); INSERT INTO users (id,country) VALUES (1,'United States'),(2,'Canada'); CREATE TABLE videos (id INT,type VARCHAR(50)); INSERT INTO videos (id,type) VALUES (1,'Educational'),(2,'Entertainment'); CREATE TABLE user_video_view (user_id INT,video_id INT,watch_time INT);
SELECT SUM(uvv.watch_time) as total_watch_time FROM user_video_view uvv JOIN users u ON uvv.user_id = u.id JOIN videos v ON uvv.video_id = v.id WHERE u.country = 'United States' AND v.type = 'Educational';
What is the maximum number of therapy sessions attended by a single patient?
CREATE TABLE patients (id INT,name TEXT,age INT,condition TEXT,therapy_sessions INT);
SELECT MAX(therapy_sessions) FROM patients;
Delete records in the vessel_safety table where the last_inspection_date is older than 3 years from today's date
CREATE TABLE vessel_safety (vessel_name VARCHAR(255),last_inspection_date DATE);
DELETE FROM vessel_safety WHERE last_inspection_date < DATE_SUB(CURRENT_DATE, INTERVAL 3 YEAR);
Find explainable AI articles written by authors from the US.
CREATE TABLE explainable_ai_articles (id INT PRIMARY KEY,title VARCHAR(100),content TEXT,author_name VARCHAR(50),author_country VARCHAR(50)); INSERT INTO explainable_ai_articles (id,title,content,author_name,author_country) VALUES (1,'The Importance of Explainable AI','Explainable AI is crucial for...','Alex Johnson','United States'); INSERT INTO explainable_ai_articles (id,title,content,author_name,author_country) VALUES (2,'A New Approach to Explainable AI','A new approach to Explainable AI...','Sophia Lee','South Korea');
SELECT * FROM explainable_ai_articles WHERE author_country = 'United States';
What is the average number of blocks per game for the Nets?
CREATE TABLE teams (team_id INT,team_name VARCHAR(50)); INSERT INTO teams (team_id,team_name) VALUES (1,'Nets'); CREATE TABLE games (game_id INT,home_team_id INT,away_team_id INT,home_team_score INT,away_team_score INT,home_team_blocks INT,away_team_blocks INT); INSERT INTO games (game_id,home_team_id,away_team_id,home_team_score,away_team_score,home_team_blocks,away_team_blocks) VALUES (1,1,2,100,90,5,4),(2,2,1,80,85,4,5),(3,1,3,110,105,6,5),(4,4,1,70,75,3,5);
SELECT AVG(home_team_blocks + away_team_blocks) as avg_blocks FROM games WHERE home_team_id = (SELECT team_id FROM teams WHERE team_name = 'Nets') OR away_team_id = (SELECT team_id FROM teams WHERE team_name = 'Nets');