instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the maximum number of pieces created by an artist who has used oil as a medium?
CREATE TABLE artists_oil (artist_id INT,name VARCHAR(50),medium VARCHAR(50),pieces INT);
SELECT MAX(pieces) FROM artists_oil WHERE medium = 'oil';
What is the earliest year a peacekeeping operation was conducted in 'Asia'?
CREATE TABLE Peacekeeping_Years (id INT,location VARCHAR(30),year INT); INSERT INTO Peacekeeping_Years (id,location,year) VALUES (1,'Asia',1990),(2,'Asia',2000);
SELECT MIN(year) FROM Peacekeeping_Years WHERE location = 'Asia';
What is the total number of peacekeeping operations conducted by each country, ranked from highest to lowest?
CREATE TABLE PeacekeepingOperations (Country VARCHAR(50),Year INT,Operations INT); INSERT INTO PeacekeepingOperations (Country,Year,Operations) VALUES ('USA',2020,15),('China',2020,10),('France',2020,12),('USA',2021,18),('China',2021,14),('France',2021,16);
SELECT Country, SUM(Operations) OVER (PARTITION BY Country ORDER BY Year ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS TotalOperations, RANK() OVER (ORDER BY SUM(Operations) DESC) AS PeacekeepingRank FROM PeacekeepingOperations GROUP BY Country ORDER BY PeacekeepingRank;
Calculate the number of unique clients living in 'Sydney' with transactions during the month of 'February'.
CREATE TABLE clients (id INT,name TEXT,city TEXT); CREATE TABLE transactions (client_id INT,transaction_time TIMESTAMP); INSERT INTO clients (id,name,city) VALUES (1,'Ivan','Sydney'),(2,'Judy','Sydney'),(3,'Ken','Melbourne'); INSERT INTO transactions (client_id,transaction_time) VALUES (1,'2022-02-05 11:00:00'),(1,'2022-03-03 16:30:00'),(2,'2022-02-12 09:45:00');
SELECT COUNT(DISTINCT clients.id) FROM clients JOIN transactions ON clients.id = transactions.client_id WHERE clients.city = 'Sydney' AND DATE_TRUNC('month', transactions.transaction_time) = '2022-02-01';
Get average returns of ETFs with expense ratio < 0.2 in the past year
CREATE TABLE etfs (etf_id INT PRIMARY KEY,symbol VARCHAR(10),expense_ratio DECIMAL(5,4)); CREATE TABLE etf_returns (return_id INT PRIMARY KEY,etf_id INT,year INT,avg_return DECIMAL(5,2));
SELECT e.symbol, AVG(r.avg_return) FROM etfs e JOIN etf_returns r ON e.etf_id = r.etf_id WHERE e.expense_ratio < 0.2 GROUP BY e.symbol;
What is the maximum cargo weight handled by port 'Hong Kong' and 'Shanghai'?
CREATE TABLE ports (port_id INT,port_name VARCHAR(255)); INSERT INTO ports (port_id,port_name) VALUES (1,'Hong Kong'),(2,'Shanghai'),(3,'Shenzhen'); CREATE TABLE cargo (cargo_id INT,port_id INT,weight FLOAT); INSERT INTO cargo (cargo_id,port_id,weight) VALUES (1,1,30000),(2,1,25000),(3,2,20000),(4,3,18000);
SELECT MAX(weight) FROM cargo WHERE port_name IN ('Hong Kong', 'Shanghai');
What is the most common type of cargo for each vessel?
CREATE TABLE vessels (vessel_id INT,vessel_name VARCHAR(50),status VARCHAR(50)); CREATE TABLE cargo (cargo_id INT,vessel_id INT,cargo_type VARCHAR(50),weight INT);
SELECT V.vessel_name, cargo_type, COUNT(cargo_type) AS frequency FROM cargo C JOIN vessels V ON C.vessel_id = V.vessel_id GROUP BY V.vessel_name, cargo_type ORDER BY frequency DESC;
List the top three categories of workforce development programs with the highest budget increases.
CREATE TABLE programs (program_id INT,program_name VARCHAR(50),budget DECIMAL(10,2),category VARCHAR(50),budget_date DATE);
SELECT category, SUM(budget - LAG(budget) OVER (PARTITION BY category ORDER BY budget_date)) as total_budget_increase FROM programs GROUP BY category ORDER BY total_budget_increase DESC LIMIT 3;
What are the names and locations of all factories with a workforce diversity score above 85?
CREATE TABLE factories (factory_id INT,name TEXT,location TEXT,diversity_score FLOAT);
SELECT name, location FROM factories WHERE diversity_score > 85;
Update the number of listens to 200 for artist id 1 in the music_consumption table
CREATE TABLE music_consumption (id INT,platform VARCHAR(50),listens INT,artist_id INT);
UPDATE music_consumption SET listens = 200 WHERE artist_id = 1;
Which artists have released music in multiple decades, but not consecutively?
CREATE TABLE ArtistDecades (ArtistID int,DecadeStartYear int,DecadeEndYear int); INSERT INTO ArtistDecades VALUES (1,1970,1980); INSERT INTO ArtistDecades VALUES (1,2000,2010); INSERT INTO ArtistDecades VALUES (2,1990,2000); INSERT INTO ArtistDecades VALUES (2,2010,2020);
SELECT ArtistID FROM ArtistDecades WHERE DecadeEndYear % 10 = 0 AND DecadeStartYear % 10 != 0 INTERSECT SELECT ArtistID FROM ArtistDecades WHERE DecadeEndYear % 10 != 0 AND DecadeStartYear % 10 = 0;
Which cities have donors but no active programs?
CREATE TABLE Donors (id INT,donor_name VARCHAR(50),email VARCHAR(50),city VARCHAR(50)); INSERT INTO Donors (id,donor_name,email,city) VALUES (3,'Maria Garcia','[email protected]','Miami'),(4,'Hiroshi Tanaka','[email protected]','San Francisco'); CREATE TABLE Programs (id INT,program_name VARCHAR(50),city VARCHAR(50)); INSERT INTO Programs (id,program_name,city) VALUES (3,'Disaster Relief','New York'),(4,'Refugee Support','Seattle');
SELECT city FROM Donors WHERE city NOT IN (SELECT city FROM Programs);
What is the total energy produced by geothermal power in Indonesia in 2019?
CREATE TABLE geothermal_power (id INT,name TEXT,country TEXT,energy_produced FLOAT);
SELECT SUM(energy_produced) FROM geothermal_power WHERE country = 'Indonesia' AND YEAR(production_date) = 2019;
What is the difference in total points scored between the home and away games for each team in the 2020 baseball season?
CREATE TABLE baseball_season (team_id INT,team_name VARCHAR(50),games_played INT,points_home INT,points_away INT); INSERT INTO baseball_season (team_id,team_name,games_played,points_home,points_away) VALUES (1,'TeamA',162,850,720);
SELECT team_name, (points_home - points_away) as diff FROM baseball_season;
What is the total number of schools in rural areas?
CREATE TABLE schools (id INT,name VARCHAR(255),level VARCHAR(255),location VARCHAR(255)); INSERT INTO schools (id,name,level,location) VALUES (1,'School A','Primary','Rural'),(2,'School B','Secondary','Urban');
SELECT COUNT(*) FROM schools WHERE location = 'Rural';
List all customers who have a Shariah-compliant finance product and a high financial wellbeing score
CREATE TABLE customers (customer_id INT,has_shariah_compliant_finance BOOLEAN,financial_wellbeing DECIMAL(10,2)); CREATE TABLE shariah_finance (customer_id INT,product VARCHAR(255));
SELECT customers.customer_id, shariah_finance.product, customers.financial_wellbeing FROM customers INNER JOIN shariah_finance ON customers.customer_id = shariah_finance.customer_id WHERE customers.has_shariah_compliant_finance = TRUE AND customers.financial_wellbeing > 7;
Rank customers by total deposits in Shariah-compliant accounts, with ties given the same rank.
CREATE TABLE deposits (customer_id INT,account_type VARCHAR(20),balance DECIMAL(10,2),deposit_date DATE);
SELECT customer_id, RANK() OVER (ORDER BY SUM(balance) DESC) as deposit_rank FROM deposits WHERE account_type = 'Shariah-compliant' GROUP BY customer_id;
What is the total revenue for each warehouse after a 10% discount?
CREATE TABLE warehouse_revenue (warehouse_id VARCHAR(5),revenue DECIMAL(10,2)); INSERT INTO warehouse_revenue (warehouse_id,revenue) VALUES ('LA',10000.00),('NY',20000.00),('CH',15000.00),('MI',5000.00),('AT',25000.00);
SELECT warehouse_id, revenue * 0.9 FROM warehouse_revenue;
What is the distribution of biotech startup funding sources?
CREATE TABLE funding_sources (funding_source_id INT,funding_source_type VARCHAR(20)); INSERT INTO funding_sources (funding_source_id,funding_source_type) VALUES (1,'Venture capital'),(2,'Angel investors'),(3,'Grants'),(4,'Crowdfunding');
SELECT funding_source_type, COUNT(*) FROM funding_sources GROUP BY funding_source_type
What is the total number of biosensors developed in the Asia-Pacific region?
CREATE SCHEMA if not exists biosensors;CREATE TABLE if not exists biosensors.sensors (id INT,name VARCHAR(100),location VARCHAR(100)); INSERT INTO biosensors.sensors (id,name,location) VALUES (1,'SensorA','Seoul'),(2,'SensorB','Beijing'),(3,'SensorC','Sydney'),(4,'SensorD','Tokyo');
SELECT COUNT(*) FROM biosensors.sensors WHERE location = 'Asia-Pacific';
How many research grants were awarded to the Computer Science department in the year 2020?
CREATE TABLE grant (id INT,department VARCHAR(50),amount INT,grant_date DATE); INSERT INTO grant (id,department,amount,grant_date) VALUES (1,'Computer Science',50000,'2020-01-01'),(2,'Computer Science',75000,'2020-04-15'),(3,'Mechanical Engineering',60000,'2019-12-31');
SELECT COUNT(*) FROM grant WHERE department = 'Computer Science' AND YEAR(grant_date) = 2020;
List faculty diversity metrics including the number of female, male, and non-binary faculty members in the Mathematics department
CREATE TABLE Department (id INT,name VARCHAR(255)); INSERT INTO Department (id,name) VALUES (1,'Computer Science'),(2,'Physics'),(3,'Mathematics'),(4,'English'); CREATE TABLE Faculty (id INT,name VARCHAR(255),gender VARCHAR(10),department_id INT); INSERT INTO Faculty (id,name,gender,department_id) VALUES (1,'John Doe','Male',1),(2,'Jane Smith','Female',3),(3,'Jamie Johnson','Non-binary',2),(4,'Alice Davis','Female',3),(5,'Bob Brown','Male',1);
SELECT f.gender, COUNT(*) as num_faculty FROM Faculty f WHERE f.department_id = (SELECT id FROM Department WHERE name = 'Mathematics') GROUP BY f.gender;
What is the total number of research grants awarded by department?
CREATE TABLE department (dept_name TEXT); INSERT INTO department (dept_name) VALUES ('Engineering'),('Business'),('Liberal Arts'); CREATE TABLE research_grants (grant_id INTEGER,dept_name TEXT,grant_amount INTEGER); INSERT INTO research_grants (grant_id,dept_name,grant_amount) VALUES (1,'Engineering',50000),(2,'Business',75000),(3,'Liberal Arts',30000);
SELECT dept_name, SUM(grant_amount) FROM research_grants GROUP BY dept_name;
What is the maximum energy consumption by a green building project in Asia?
CREATE TABLE green_buildings (id INT,name VARCHAR(50),country VARCHAR(50),energy_consumption INT); INSERT INTO green_buildings (id,name,country,energy_consumption) VALUES (1,'GreenHub','India',1200),(2,'EcoTower','China',1500),(3,'SolarVista','Japan',1800),(4,'WindHaven','India',2000),(5,'SolarCity','China',2500),(6,'EcoRail','Japan',3000);
SELECT MAX(energy_consumption) FROM green_buildings WHERE country = 'India' OR country = 'China' OR country = 'Japan';
What is the distribution of users by age group for each virtual tour?
CREATE TABLE virtual_tour_users (user_id INT,tour_id INT,age_group TEXT); INSERT INTO virtual_tour_users (user_id,tour_id,age_group) VALUES (1,1,'18-24'),(2,1,'25-34'),(3,1,'35-44'),(4,2,'18-24'),(5,2,'35-44'),(6,2,'45-54'),(7,3,'25-34'),(8,3,'45-54'),(9,3,'55-64');
SELECT tour_id, age_group, COUNT(*) as user_count FROM virtual_tour_users GROUP BY tour_id, age_group;
Find the number of unique endangered languages in Oceania and their corresponding traditional art forms.
CREATE TABLE languages (language VARCHAR(255),region VARCHAR(255),arts VARCHAR(255)); INSERT INTO languages (language,region,arts) VALUES ('Language1','Oceania','Art1,Art2'),('Language2','Oceania','Art3'),('Language3','Asia','Art4');
SELECT language, arts FROM languages WHERE region = 'Oceania' INTERSECT SELECT endangered_languages FROM endangered_languages;
What is the total number of traditional art pieces created in each region with a population greater than 500,000?
CREATE TABLE regions (id INT,name TEXT,population INT); INSERT INTO regions (id,name,population) VALUES (1,'West Africa',6000000),(2,'Amazon Basin',500000); CREATE TABLE art_pieces (id INT,region_id INT,type TEXT,year INT); INSERT INTO art_pieces (id,region_id,type,year) VALUES (1,1,'Mask',2000),(2,1,'Statue',1950),(3,2,'Painting',2020);
SELECT r.name, COUNT(ap.id) FROM regions r JOIN art_pieces ap ON r.id = ap.region_id WHERE r.population > 500000 GROUP BY r.id;
What is the total number of traditional art pieces in North American museums?
CREATE TABLE ArtPieces (museum VARCHAR(50),country VARCHAR(50),type VARCHAR(50),quantity INT); INSERT INTO ArtPieces (museum,country,type,quantity) VALUES ('Metropolitan Museum of Art','USA','traditional art',500),('National Gallery of Art','USA','traditional art',400),('Museo Nacional de Antropología','Mexico','traditional art',600);
SELECT SUM(quantity) FROM ArtPieces WHERE type = 'traditional art' AND country IN ('USA', 'Mexico') AND region = 'North America';
Which mental health conditions were treated most frequently in Canada during 2022?
CREATE TABLE patients (id INT,country VARCHAR(255)); CREATE TABLE treatments (id INT,patient_id INT,treatment_date DATE); CREATE TABLE conditions (id INT,patient_id INT,condition VARCHAR(255)); INSERT INTO patients (id,country) VALUES (1,'Canada'),(2,'Canada'); INSERT INTO treatments (id,patient_id,treatment_date) VALUES (1,1,'2022-01-01'),(2,1,'2022-02-15'),(3,2,'2022-06-30'); INSERT INTO conditions (id,patient_id,condition) VALUES (1,1,'depression'),(2,1,'anxiety'),(3,2,'depression');
SELECT conditions.condition, COUNT(conditions.condition) AS count FROM conditions JOIN patients ON conditions.patient_id = patients.id JOIN treatments ON patients.id = treatments.patient_id WHERE patients.country = 'Canada' AND treatments.treatment_date >= '2022-01-01' AND treatments.treatment_date < '2023-01-01' GROUP BY conditions.condition ORDER BY count DESC LIMIT 1;
List all legal aid clinics in the justice_schemas.legal_aid_clinics table that have been operational for more than five years.
CREATE TABLE justice_schemas.legal_aid_clinics (id INT PRIMARY KEY,clinic_name TEXT,years_operational INT);
SELECT clinic_name FROM justice_schemas.legal_aid_clinics WHERE years_operational > 5;
How many marine conservation initiatives were launched in the Indian Ocean in 2015 and 2016?
CREATE TABLE marine_conservation_initiatives (id INT,name TEXT,year INT,region TEXT);
SELECT COUNT(*) FROM marine_conservation_initiatives WHERE region = 'Indian Ocean' AND year IN (2015, 2016);
How many pollution control initiatives are in the South Pacific Ocean?
CREATE TABLE SouthPacificPollution (initiative_name TEXT,location TEXT); INSERT INTO SouthPacificPollution (initiative_name,location) VALUES ('Clean Oceans Project','South Pacific Ocean'),('Sustainable Fishing Initiative','South Pacific Ocean'); CREATE TABLE Oceans (ocean TEXT,initiative_count INTEGER); INSERT INTO Oceans (ocean,initiative_count) VALUES ('South Pacific Ocean',NULL);
SELECT Oceans.ocean, COUNT(SouthPacificPollution.initiative_name) FROM Oceans LEFT JOIN SouthPacificPollution ON Oceans.ocean = SouthPacificPollution.location GROUP BY Oceans.ocean;
How many species of marine life are present in the Southern Ocean?
CREATE TABLE marine_life (species_name TEXT,location TEXT); INSERT INTO marine_life (species_name,location) VALUES ('Crabeater Seal','Southern Ocean'),('Ross Seal','Southern Ocean'),('Southern Elephant Seal','Southern Ocean'),('Leopard Seal','Southern Ocean'),('Weddell Seal','Southern Ocean');
SELECT COUNT(DISTINCT species_name) FROM marine_life WHERE location = 'Southern Ocean';
What are the names and locations of marine research stations in the Atlantic Ocean?
CREATE TABLE Research_Station (station_name VARCHAR(50),latitude NUMERIC(8,2),longitude NUMERIC(8,2),ocean_name VARCHAR(50)); INSERT INTO Research_Station (station_name,latitude,longitude,ocean_name) VALUES ('Station A',40.7128,-74.0060,'Atlantic'),('Station B',34.0522,-118.2437,'Indian');
SELECT Research_Station.station_name, latitude, longitude FROM Research_Station WHERE ocean_name = 'Atlantic';
What is the average depth of ocean floor mapping projects located in the Arctic region?
CREATE TABLE ocean_floor_mapping(id INT,region VARCHAR(20),depth FLOAT); INSERT INTO ocean_floor_mapping(id,region,depth) VALUES (1,'Pacific',5000.5),(2,'Atlantic',4500.3),(3,'Arctic',3800.0),(4,'Indian',4200.0);
SELECT AVG(depth) FROM ocean_floor_mapping WHERE region = 'Arctic';
What is the total frequency of news content for each genre in the media_content table?
CREATE TABLE media_content (id INT,genre VARCHAR(50),frequency INT); INSERT INTO media_content (id,genre,frequency) VALUES (1,'News - Print',50),(2,'News - Online',100),(3,'News - TV',150);
SELECT genre, SUM(frequency) FROM media_content WHERE genre LIKE 'News%' GROUP BY genre;
What is the average quantity of vegan dishes sold per day in the Los Angeles region?
CREATE TABLE orders (item_id INT,quantity INT,order_date DATE); INSERT INTO orders (item_id,quantity,order_date) VALUES (1,20,'2021-01-01'),(2,30,'2021-01-02'),(1,15,'2021-01-03');
SELECT AVG(quantity) FROM orders JOIN menu ON orders.item_id = menu.item_id WHERE menu.dish_type = 'vegan' AND menu.region = 'Los Angeles' GROUP BY order_date;
Find the mobile subscribers with consecutive speed drops greater than 25% for the last 3 months, ordered by subscription IDs.
CREATE TABLE mobile_usage_detailed (subscriber_id INT,month INT,speed FLOAT); INSERT INTO mobile_usage_detailed (subscriber_id,month,speed) VALUES (1,1,100),(1,2,80),(1,3,70),(2,1,200),(2,2,180),(2,3,160),(3,1,150),(3,2,130),(3,3,110);
SELECT subscriber_id, speed, month FROM (SELECT subscriber_id, speed, month, LAG(speed, 1) OVER (PARTITION BY subscriber_id ORDER BY month) as prev_speed, LAG(speed, 2) OVER (PARTITION BY subscriber_id ORDER BY month) as prev_prev_speed FROM mobile_usage_detailed) t WHERE t.speed < 0.75 * t.prev_speed AND t.speed < 0.75 * t.prev_prev_speed ORDER BY subscriber_id;
How many mobile subscribers are there in each region?
CREATE TABLE mobile_subscribers (id INT,region VARCHAR(10),plan VARCHAR(20)); INSERT INTO mobile_subscribers (id,region,plan) VALUES (1,'urban','PlanA'),(2,'rural','PlanB'),(3,'urban','PlanC'),(4,'urban','PlanA'),(5,'rural','PlanD');
SELECT region, COUNT(*) FROM mobile_subscribers GROUP BY region;
What is the total number of broadband subscribers from urban areas?
CREATE TABLE broadband_subscribers (subscriber_id INT,plan_id INT,subscriber_location VARCHAR(50)); INSERT INTO broadband_subscribers (subscriber_id,plan_id,subscriber_location) VALUES (1,1,'Urban'),(2,2,'Rural'),(3,3,'Urban'); CREATE TABLE broadband_plans (plan_id INT,plan_name VARCHAR(50),download_speed INT,upload_speed INT); INSERT INTO broadband_plans (plan_id,plan_name,download_speed,upload_speed) VALUES (1,'Plan X',120,20),(2,'Plan Y',80,15),(3,'Plan Z',150,30);
SELECT COUNT(*) FROM broadband_subscribers WHERE subscriber_location = 'Urban';
Identify the number of unique causes supported by volunteers from different countries.
CREATE TABLE volunteers (id INT,name VARCHAR(100),country VARCHAR(50),cause VARCHAR(50)); INSERT INTO volunteers VALUES (1,'John Doe','USA','Environment'); INSERT INTO volunteers VALUES (2,'Jane Smith','Canada','Animals');
SELECT country, COUNT(DISTINCT cause) as unique_causes FROM volunteers GROUP BY country;
How many players are there in each gender?
CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),Country VARCHAR(20)); INSERT INTO Players (PlayerID,Age,Gender,Country) VALUES (1,25,'Male','USA'),(2,30,'Female','Canada');
SELECT Gender, COUNT(*) as NumPlayers FROM Players GROUP BY Gender;
Update the genre of all games with the name 'Civilization' to 'Simulation'
CREATE TABLE games (id INT PRIMARY KEY,name VARCHAR(50),genre VARCHAR(50)); INSERT INTO games (id,name,genre) VALUES (1,'Starcraft','Strategy'); INSERT INTO games (id,name,genre) VALUES (2,'Civilization','Strategy');
UPDATE games SET genre = 'Simulation' WHERE name = 'Civilization';
List the number of IoT sensors in the 'PrecisionFarming' schema that have a 'moisture' measurement and were installed after 2019-01-01.
CREATE SCHEMA PrecisionFarming; CREATE TABLE IoT_Sensors (sensor_id INT,sensor_name VARCHAR(50),measurement VARCHAR(50),install_date DATE); INSERT INTO PrecisionFarming.IoT_Sensors (sensor_id,sensor_name,measurement,install_date) VALUES (4,'Sensor4','moisture','2020-01-01'),(5,'Sensor5','moisture','2019-06-15'),(6,'Sensor6','temperature','2021-03-02'),(7,'Sensor7','humidity','2018-12-31');
SELECT COUNT(*) FROM PrecisionFarming.IoT_Sensors WHERE measurement = 'moisture' AND install_date > '2019-01-01';
What is the average co-ownership price per square foot in the Bay Area?
CREATE TABLE bay_area_prop (id INT,address TEXT,price FLOAT,size FLOAT,co_ownership BOOLEAN); INSERT INTO bay_area_prop (id,address,price,size,co_ownership) VALUES (1,'123 Main St',800000,1500,TRUE),(2,'456 Oak St',1000000,2000,FALSE);
SELECT AVG(price / size) FROM bay_area_prop WHERE co_ownership = TRUE;
What is the change in co-ownership cost per property between consecutive rows, ordered by the 'co_ownership' table's ID?
CREATE TABLE co_ownership (id INT,city VARCHAR(255),co_ownership_cost INT,property_id INT); INSERT INTO co_ownership (id,city,co_ownership_cost,property_id) VALUES (1,'Seattle',550000,101),(2,'Seattle',560000,102),(3,'Portland',420000,103),(4,'Portland',430000,104),(5,'Portland',440000,105);
SELECT id, city, co_ownership_cost, LAG(co_ownership_cost) OVER (PARTITION BY city ORDER BY id) AS previous_co_ownership_cost, co_ownership_cost - LAG(co_ownership_cost) OVER (PARTITION BY city ORDER BY id) AS cost_change FROM co_ownership ORDER BY id;
What is the total square footage of all properties in urban areas with affordable housing?
CREATE TABLE urban_areas (id INT,area VARCHAR(20),affordable BOOLEAN); INSERT INTO urban_areas (id,area,affordable) VALUES (1,'City A',true),(2,'City B',false),(3,'City C',true); CREATE TABLE properties (id INT,area VARCHAR(20),size INT); INSERT INTO properties (id,area,size) VALUES (1,'City A',1500),(2,'City B',2000),(3,'City C',1000),(4,'City A',1200);
SELECT SUM(size) FROM properties JOIN urban_areas ON properties.area = urban_areas.area WHERE urban_areas.affordable = true;
What is the average capacity of renewable energy projects for each country?
CREATE TABLE projects (name TEXT,type TEXT,capacity INTEGER,country TEXT); INSERT INTO projects (name,type,capacity,country) VALUES ('Project 1','Wind',100,'USA'),('Project 2','Solar',200,'Germany'),('Project 3','Wind',300,'France');
SELECT country, AVG(capacity) FROM projects GROUP BY country
Which menu item in 'Bistro Italiano' has the highest sales?
CREATE TABLE Sales (restaurant_name TEXT,menu_item TEXT,sales INTEGER); INSERT INTO Sales (restaurant_name,menu_item,sales) VALUES ('Bistro Italiano','Lasagna',125),('Bistro Italiano','Pizza Margherita',98),('Bistro Italiano','Tiramisu',83);
SELECT menu_item, MAX(sales) FROM Sales WHERE restaurant_name = 'Bistro Italiano';
How many space objects are there in total?
CREATE TABLE space_objects_count (id INT,name VARCHAR(255)); INSERT INTO space_objects_count (id,name) VALUES (1,'Space Object 1'),(2,'Space Object 2'),(3,'Space Object 3');
SELECT COUNT(*) FROM space_objects_count;
How many astronauts are from 'Brazil'?
CREATE TABLE AstronautData (id INT,name VARCHAR(50),country VARCHAR(50),height FLOAT,weight FLOAT,blood_pressure FLOAT); INSERT INTO AstronautData (id,name,country,height,weight,blood_pressure) VALUES (1,'John','USA',180,80,120),(2,'Jane','Canada',170,70,110),(3,'Alex','Brazil',190,90,130),(4,'Elena','Russia',165,60,115);
SELECT COUNT(*) FROM AstronautData WHERE country = 'Brazil';
Which cybersecurity policies in the 'cybersecurity_policies' table were last updated on a specific date?
CREATE TABLE cybersecurity_policies (id INT PRIMARY KEY,policy_name TEXT,policy_text TEXT,last_updated DATE);
SELECT policy_name, last_updated FROM cybersecurity_policies WHERE last_updated = '2022-01-01';
How many artworks were created by 'Vincent van Gogh'?
CREATE TABLE artworks (id INT PRIMARY KEY,title VARCHAR(255),artist VARCHAR(255),year INT);
SELECT COUNT(*) FROM artworks WHERE artist = 'Vincent van Gogh';
What is the average age of visitors who attended the "Modern Art" exhibition?
CREATE TABLE visitor_attendance (visitor_id INT,visitor_age INT,exhibition_id INT); INSERT INTO visitor_attendance (visitor_id,visitor_age,exhibition_id) VALUES (1,30,2);
SELECT AVG(visitor_age) FROM visitor_attendance JOIN exhibitions ON visitor_attendance.exhibition_id = exhibitions.exhibition_id WHERE exhibitions.exhibition_name = 'Modern Art';
What is the average water consumption per capita in Tokyo and Seoul for the year 2019?
CREATE TABLE asia_population (id INT,city VARCHAR(50),population INT,year INT); INSERT INTO asia_population (id,city,population,year) VALUES (1,'Tokyo',9000000,2019); INSERT INTO asia_population (id,city,population,year) VALUES (2,'Seoul',7000000,2019); CREATE TABLE asia_water_consumption (id INT,city VARCHAR(50),water_consumption FLOAT,year INT); INSERT INTO asia_water_consumption (id,city,water_consumption,year) VALUES (1,'Tokyo',1500000000,2019); INSERT INTO asia_water_consumption (id,city,water_consumption,year) VALUES (2,'Seoul',1200000000,2019);
SELECT AVG(awc.water_consumption / ap.population) FROM asia_water_consumption awc INNER JOIN asia_population ap ON awc.city = ap.city WHERE awc.year = 2019;
What is the total water consumption in liters for residential users in July 2021?
CREATE TABLE water_consumption (user_category VARCHAR(20),consumption FLOAT,usage_date DATE); INSERT INTO water_consumption (user_category,consumption,usage_date) VALUES ('residential',150,'2021-07-01'),('commercial',250,'2021-07-01'),('residential',160,'2021-07-02'),('commercial',240,'2021-07-02');
SELECT SUM(consumption) FROM water_consumption WHERE user_category = 'residential' AND usage_date >= '2021-07-01' AND usage_date <= '2021-07-31';
What is the total distance walked by members in each age group?
CREATE TABLE workouts (workout_id INT,member_id INT,distance FLOAT); INSERT INTO workouts (workout_id,member_id,distance) VALUES (1,1,2.5),(2,2,3.2),(3,3,1.8);
SELECT AVG(distance) as avg_distance, FLOOR(AGE(FROM_DATE(NOW(), '2020-01-01')) / 5) * 5 as age_group FROM workouts JOIN members ON workouts.member_id = members.member_id GROUP BY age_group;
Delete unsafe AI algorithms with incidents greater than 200 in 2022
CREATE TABLE unsafe_ai_algorithms (algorithm_name VARCHAR(255),incidents INT,year INT); INSERT INTO unsafe_ai_algorithms (algorithm_name,incidents,year) VALUES ('ALG1',120,2022),('ALG2',150,2022),('ALG3',80,2022),('ALG4',200,2022),('ALG5',70,2022),('ALG6',190,2022),('ALG7',130,2022),('ALG8',100,2022);
DELETE FROM unsafe_ai_algorithms WHERE incidents > 200 AND year = 2022;
Compare the number of economic diversification projects in two regions, one in Europe and one in Oceania, by showing the project type and the number of projects in each region.
CREATE TABLE economic_diversification (region VARCHAR(50),project_type VARCHAR(50),project_start_date DATE);
SELECT 'Europe' as region, project_type, COUNT(*) as project_count FROM economic_diversification WHERE region = 'Europe' UNION ALL SELECT 'Oceania' as region, project_type, COUNT(*) as project_count FROM economic_diversification WHERE region = 'Oceania';
Delete all aircraft models that were manufactured before 2000 from the aircraft_manufacturing table
CREATE TABLE aircraft_manufacturing (id INT PRIMARY KEY,model VARCHAR(100),manufacturer VARCHAR(100),year_manufactured INT);
DELETE FROM aircraft_manufacturing WHERE year_manufactured < 2000;
What is the maximum number of flights operated by a single astronaut?
CREATE TABLE flights (flight_id INT,astronaut_id INT,num_flights INT); INSERT INTO flights (flight_id,astronaut_id,num_flights) VALUES (1,1,100),(2,2,50),(3,3,150);
SELECT MAX(num_flights) FROM flights;
Insert a new record into the 'habitat_preservation' table with the following details: 'habitat_preservation_id' as 3, 'location_id' as 2, 'preservation_method' as 'Planting new trees', 'start_date' as '2022-01-01', 'end_date' as '2023-12-31', 'area_preserved' as 500
CREATE TABLE habitat_preservation (habitat_preservation_id INT PRIMARY KEY,location_id INT,preservation_method VARCHAR(50),start_date DATE,end_date DATE,area_preserved INT);
INSERT INTO habitat_preservation (habitat_preservation_id, location_id, preservation_method, start_date, end_date, area_preserved) VALUES (3, 2, 'Planting new trees', '2022-01-01', '2023-12-31', 500);
What is the total area of marine protected areas in the Atlantic Ocean that are larger than 100000 square kilometers?
CREATE TABLE MarineProtectedAreas (ocean VARCHAR(50),area_size INT); INSERT INTO MarineProtectedAreas (ocean,area_size) VALUES ('Atlantic Ocean',150000),('Atlantic Ocean',120000),('Atlantic Ocean',90000),('Pacific Ocean',180000),('Pacific Ocean',160000),('Pacific Ocean',130000);
SELECT SUM(area_size) as total_area FROM MarineProtectedAreas WHERE ocean = 'Atlantic Ocean' AND area_size > 100000;
What was the total funding for 'Art' programs in 'Texas' and 'California'?
CREATE TABLE Programs (program_id INT,program_name VARCHAR(50),focus VARCHAR(50),state VARCHAR(50),funding_amount DECIMAL(10,2)); INSERT INTO Programs (program_id,program_name,focus,state,funding_amount) VALUES (1,'Art Troupe','Art','Texas',15000.00),(2,'Theater Classes','Theater','California',12000.00);
SELECT SUM(funding_amount) FROM Programs WHERE (state = 'Texas' OR state = 'California') AND focus = 'Art';
What are the total number of movies released in the 'Comedy' genre and the 'Action' genre, combined, that have a production budget over 100 million dollars?
CREATE TABLE Movies (MovieId INT,Title VARCHAR(100),Genre VARCHAR(50),ReleaseYear INT,ProductionBudget DECIMAL(10,2));
SELECT SUM(CASE WHEN Genre IN ('Comedy', 'Action') THEN 1 ELSE 0 END) AS TotalComedyAndActionMovies, SUM(CASE WHEN Genre IN ('Comedy', 'Action') AND ProductionBudget > 100000000 THEN 1 ELSE 0 END) AS TotalComedyAndActionBlockbusters FROM Movies;
What is the total revenue generated by African-American movies released in 2020?
CREATE TABLE african_american_movies (id INT PRIMARY KEY,name VARCHAR(255),release_year INT,revenue INT); INSERT INTO african_american_movies (id,name,release_year,revenue) VALUES (1,'Black Panther',2020,150000000),(2,'Us',2020,175000000),(3,'Harriet',2020,45000000);
SELECT SUM(revenue) FROM african_american_movies WHERE release_year = 2020;
Insert a new compliance violation for dispensary 1 on 2022-01-05 with the description 'Expired products'.
CREATE TABLE compliance_violations (id INT,dispensary_id INT,violation_date DATE,description TEXT); INSERT INTO compliance_violations (id,dispensary_id,violation_date,description) VALUES (1,1,'2021-02-15','Inadequate labeling'),(2,2,'2021-03-02','Improper storage'),(3,3,'2021-06-28','Expired products');
INSERT INTO compliance_violations (dispensary_id, violation_date, description) VALUES (1, '2022-01-05', 'Expired products');
Who are the top 3 customers by total purchases from the 'Green Earth' dispensary?
CREATE TABLE Customers (CustomerID INT,CustomerName VARCHAR(255)); CREATE TABLE Purchases (PurchaseID INT,CustomerID INT,DispensaryName VARCHAR(255),TotalPaid DECIMAL(10,2)); INSERT INTO Customers (CustomerID,CustomerName) VALUES (1,'John Doe'),(2,'Jane Smith'),(3,'Jim Brown'),(4,'Jake White'); INSERT INTO Purchases (PurchaseID,CustomerID,DispensaryName,TotalPaid) VALUES (1,1,'Green Earth',100.00),(2,1,'Green Earth',200.00),(3,2,'Green Earth',150.00),(4,3,'Green Earth',50.00),(5,4,'Green Earth',300.00);
SELECT CustomerName, SUM(TotalPaid) AS TotalPurchases FROM Customers JOIN Purchases ON Customers.CustomerID = Purchases.CustomerID WHERE DispensaryName = 'Green Earth' GROUP BY CustomerName ORDER BY TotalPurchases DESC LIMIT 3;
How many cases did attorney 'Jane Doe' handle in total?
CREATE TABLE Attorneys (AttorneyID int,Name varchar(50),Specialty varchar(50)); INSERT INTO Attorneys (AttorneyID,Name,Specialty) VALUES (2,'Jane Doe','Civil'); CREATE TABLE Cases (CaseID int,ClientID int,Category varchar(50),AttorneyID int); INSERT INTO Cases (CaseID,ClientID,Category,AttorneyID) VALUES (301,3,'Civil',2);
SELECT COUNT(*) as TotalCases FROM Cases WHERE AttorneyID = (SELECT AttorneyID FROM Attorneys WHERE Name = 'Jane Doe');
Show the chemical name and its production cost for the lowest costing chemical
CREATE TABLE chemical_costs (chemical VARCHAR(20),cost FLOAT); INSERT INTO chemical_costs (chemical,cost) VALUES ('Eco-friendly Polymer',425.50),('Nano Polymer',402.12),('Smart Polymer',450.00),('Carbon Nanotube',600.00),('Graphene',650.00),('Buckyball',680.00);
SELECT chemical, cost FROM chemical_costs ORDER BY cost ASC LIMIT 1;
Which countries received shipments of Chemical E in the last 3 months?
CREATE TABLE shipments (id INT,product VARCHAR(255),shipped_to VARCHAR(255),shipped_date DATE); INSERT INTO shipments (id,product,shipped_to,shipped_date) VALUES (1,'Chemical A','Canada','2022-05-21'),(2,'Chemical B','USA','2022-04-15'),(3,'Chemical A','Canada','2022-07-05'),(4,'Chemical E','Mexico','2022-06-10'),(5,'Chemical E','Brazil','2022-06-25');
SELECT DISTINCT shipped_to FROM shipments WHERE product = 'Chemical E' AND shipped_date >= '2022-04-01'
List the number of community health centers and infectious disease tracking facilities in 'southwest' regions.
CREATE TABLE centers (id INT,name TEXT,region TEXT); INSERT INTO centers (id,name,region) VALUES (1,'Center A','southwest'); INSERT INTO centers (id,name,region) VALUES (2,'Center B','northeast'); INSERT INTO centers (id,name,region) VALUES (3,'Center C','northwest'); CREATE TABLE diseases (id INT,name TEXT,region TEXT); INSERT INTO diseases (id,name,region) VALUES (1,'Disease A','southwest'); INSERT INTO diseases (id,name,region) VALUES (2,'Disease B','southeast');
SELECT COUNT(*) FROM ( (SELECT * FROM centers WHERE region = 'southwest') UNION (SELECT * FROM diseases WHERE region = 'southwest') );
What is the total production (in metric tons) of organic crops in Oceania, broken down by crop type?
CREATE TABLE organic_crops (crop_id INT,crop_name TEXT,country TEXT,production_tons FLOAT); INSERT INTO organic_crops (crop_id,crop_name,country,production_tons) VALUES (1,'Wheat','Australia',1500.0),(2,'Barley','New Zealand',1200.0),(3,'Corn','Papua New Guinea',2000.0);
SELECT crop_name, SUM(production_tons) FROM organic_crops WHERE country = 'Oceania' GROUP BY crop_name;
Update the accommodation type for a student with a StudentID of 2 from 'Assistive Listening Devices' to 'Sign Language Interpretation'.
CREATE TABLE StudentAccommodations (StudentID INT,StudentName VARCHAR(255),DisabilityType VARCHAR(255),AccommodationType VARCHAR(255),GraduationYear INT); INSERT INTO StudentAccommodations (StudentID,StudentName,DisabilityType,AccommodationType,GraduationYear) VALUES (1,'John Doe','Visual Impairment','Sign Language Interpretation',2018),(2,'Jane Smith','Hearing Impairment','Assistive Listening Devices',NULL),(3,'Michael Johnson','Mobility Impairment','Assistive Technology',2019),(4,'Sara Johnson','Physical Disability','Mobility Assistance',2022);
UPDATE StudentAccommodations SET AccommodationType = 'Sign Language Interpretation' WHERE StudentID = 2;
What is the total number of disability support programs offered in urban and rural areas, and the percentage of total programs for each area type?
CREATE TABLE programs (program_id INT,program_name VARCHAR(255),area_type VARCHAR(255));
SELECT area_type, COUNT(*) as total_programs, ROUND(COUNT(*) * 100.0 / (SELECT COUNT(*) FROM programs) , 2) as percentage_of_total FROM programs WHERE area_type IN ('urban', 'rural') GROUP BY area_type;
Who are the top 5 decentralized applications by transaction volume in South America?
CREATE TABLE dapps (id INT,name VARCHAR(50),daily_tx_volume INT); INSERT INTO dapps (id,name,daily_tx_volume) VALUES (1,'App1',1000),(2,'App2',2000),(3,'App3',3000),(4,'App4',4000),(5,'App5',5000),(6,'App6',6000);
SELECT name, SUM(daily_tx_volume) as total_tx_volume, RANK() OVER (ORDER BY SUM(daily_tx_volume) DESC) as rank FROM dapps WHERE region = 'South America' GROUP BY name;
How many wildlife habitats in South Africa have a total area greater than 50000 hectares?
CREATE TABLE wildlife_habitats (id INT,name TEXT,area REAL,country TEXT);
SELECT COUNT(*) FROM wildlife_habitats WHERE country = 'South Africa' GROUP BY country HAVING SUM(area) > 50000;
Provide the number of wildlife species in the 'Amazon' region.
CREATE TABLE wildlife_species (region VARCHAR(255),species INT); INSERT INTO wildlife_species (region,species) VALUES ('Amazon',500),('Congo',400),('Boreal',300),('Temperate',600);
SELECT region, SUM(species) FROM wildlife_species WHERE region = 'Amazon';
What is the total area of wildlife habitats for each country?
CREATE TABLE country_habitat (country VARCHAR(255),habitat_name VARCHAR(255),area_ha INT); INSERT INTO country_habitat (country,habitat_name,area_ha) VALUES ('Canada','Habitat1',5000),('Canada','Habitat2',7000),('USA','Habitat3',8000),('USA','Habitat4',6000),('Mexico','Habitat5',9000);
SELECT country, SUM(area_ha) FROM country_habitat GROUP BY country;
Which country sources the most organic ingredients for cosmetics?
CREATE TABLE cosmetics.ingredient_sourcing (ingredient_id INT,ingredient_name VARCHAR(50),country VARCHAR(50),is_organic BOOLEAN); INSERT INTO cosmetics.ingredient_sourcing (ingredient_id,ingredient_name,country,is_organic) VALUES (1,'Aloe Vera','Mexico',true),(2,'Jojoba Oil','Argentina',true),(3,'Rosehip Oil','Chile',true),(4,'Shea Butter','Ghana',true),(5,'Coconut Oil','Philippines',false);
SELECT country, SUM(is_organic) as total_organic_ingredients FROM cosmetics.ingredient_sourcing GROUP BY country ORDER BY total_organic_ingredients DESC LIMIT 1;
Delete all records in the Makeup table with a Revenue less than 25000.
CREATE TABLE Makeup (Brand VARCHAR(50),Category VARCHAR(50),Revenue DECIMAL(10,2)); INSERT INTO Makeup (Brand,Category,Revenue) VALUES ('BrandA','Cruelty-Free',50000),('BrandB','Cruelty-Free',40000),('BrandC','Cruelty-Free',30000),('BrandD','Not Cruelty-Free',15000),('BrandE','Not Cruelty-Free',20000);
DELETE FROM Makeup WHERE Revenue < 25000;
Identify the most frequently purchased beauty product by customers from the US.
CREATE TABLE customer_purchases (customer_id INT,product_name VARCHAR(50),purchase_date DATE,country VARCHAR(50)); INSERT INTO customer_purchases (customer_id,product_name,purchase_date,country) VALUES (1,'Lipstick','2021-01-01','US'),(2,'Mascara','2021-01-05','US'),(3,'Lipstick','2021-01-10','CA'),(4,'Lipstick','2021-01-15','US'),(5,'Foundation','2021-01-20','US');
SELECT product_name, COUNT(*) as purchase_count FROM customer_purchases WHERE country = 'US' GROUP BY product_name ORDER BY purchase_count DESC LIMIT 1;
What is the total revenue of cruelty-free skincare products in Belgium?
CREATE TABLE CrueltyFreeSkincare (product VARCHAR(255),country VARCHAR(255),revenue DECIMAL(10,2)); INSERT INTO CrueltyFreeSkincare (product,country,revenue) VALUES ('Cleanser','Belgium',600),('Toner','Belgium',700),('Moisturizer','Belgium',800);
SELECT SUM(revenue) FROM CrueltyFreeSkincare WHERE country = 'Belgium';
How many cultural events were held in Canada in 2021?
CREATE TABLE CulturalEvents (id INT,country VARCHAR(20),year INT,events_held INT); INSERT INTO CulturalEvents (id,country,year,events_held) VALUES (1,'Canada',2021,100),(2,'USA',2021,150),(3,'Canada',2020,75);
SELECT SUM(events_held) FROM CulturalEvents WHERE country = 'Canada' AND year = 2021;
What are the names and maintenance costs of all military equipment in the Atlantic region with a maintenance cost less than $5000?
CREATE TABLE MilitaryEquipment (equipment_id INT,name VARCHAR(255),region VARCHAR(255),maintenance_cost FLOAT); INSERT INTO MilitaryEquipment (equipment_id,name,region,maintenance_cost) VALUES (1,'Tank A','Pacific',5000),(2,'Helicopter B','Pacific',7000),(3,'Ship C','Atlantic',4000);
SELECT name, maintenance_cost FROM MilitaryEquipment WHERE region = 'Atlantic' AND maintenance_cost < 5000;
How many military innovation patents were filed by China in 2015?
CREATE TABLE patents (id INT,country VARCHAR(255),year INT,patent_name VARCHAR(255)); INSERT INTO patents (id,country,year,patent_name) VALUES (1,'China',2015,'Directed Energy Weapon');
SELECT COUNT(*) FROM patents WHERE country = 'China' AND year = 2015;
What is the total humanitarian assistance provided (in USD) by each country in the 'humanitarian_assistance' table, for operations in 'Africa'?
CREATE TABLE humanitarian_assistance (id INT,country VARCHAR(50),region VARCHAR(50),amount INT);
SELECT country, SUM(amount) as total_assistance FROM humanitarian_assistance WHERE region = 'Africa' GROUP BY country;
What is the total number of military innovation patents issued to each country in the last 3 years?
CREATE TABLE Military_Innovation_Patents (id INT,country VARCHAR(50),year INT); CREATE TABLE Countries (id INT,name VARCHAR(50),region VARCHAR(50));
SELECT co.name, COUNT(mi.year) FROM Military_Innovation_Patents mi INNER JOIN Countries co ON mi.country = co.name WHERE mi.year BETWEEN (YEAR(CURRENT_DATE) - 3) AND YEAR(CURRENT_DATE) GROUP BY co.name;
What is the total investment of clients with the last name "Patel" in any fund?
CREATE TABLE clients (client_id INT,name VARCHAR(50),investment FLOAT); CREATE TABLE fund_investments (client_id INT,fund_name VARCHAR(50),investment FLOAT);
SELECT SUM(investment) FROM clients INNER JOIN fund_investments ON clients.client_id = fund_investments.client_id WHERE clients.name LIKE '%Patel';
Retrieve all details of vessels that have a capacity greater than 10000 TEUs
CREATE TABLE vessels (vessel_id INT,vessel_name VARCHAR(50),vessel_type VARCHAR(50),capacity INT); INSERT INTO vessels VALUES (1,'Ever Ace','Container Ship',24000); INSERT INTO vessels VALUES (2,'Seaspan Rely','Container Ship',15000); INSERT INTO vessels VALUES (3,'Gas Leader','LNG Carrier',145000); INSERT INTO vessels VALUES (4,'Ocean Titan','Bulk Carrier',120000);
SELECT * FROM vessels WHERE capacity > 10000;
What is the average tonnage of all cargo handled in the 'cargo_handling' table for the month of April?
CREATE TABLE cargo_handling (id INT,cargo_id INT,handling_date DATE,tonnage INT,PRIMARY KEY(id));
SELECT AVG(tonnage) FROM cargo_handling WHERE MONTH(handling_date) = 4;
Show the number of workers employed in ethical manufacturing for each factory.
CREATE TABLE factories(factory_id INT,name TEXT,location TEXT); CREATE TABLE ethical_manufacturing(factory_id INT,worker_count INT);
SELECT f.name, SUM(em.worker_count) as total_workers FROM factories f JOIN ethical_manufacturing em ON f.factory_id = em.factory_id GROUP BY f.name;
What is the total number of hospital beds in hospitals in Texas that specialize in cancer treatment?
CREATE TABLE hospitals (id INT,name VARCHAR(50),state VARCHAR(25),num_beds INT,specialty VARCHAR(50)); INSERT INTO hospitals (id,name,state,num_beds,specialty) VALUES (1,'Hospital A','Texas',60,'cancer'),(2,'Hospital B','Texas',30,'general practice'),(3,'Hospital C','California',75,'cardiology');
SELECT SUM(num_beds) FROM hospitals WHERE state = 'Texas' AND specialty = 'cancer';
Calculate the overall average age of teachers
SELECT AVG(Age) as AverageAge FROM Teachers;
SELECT AVG(Age) as AverageAge FROM Teachers;
What is the average mental health score for students in traditional courses?
CREATE TABLE students (student_id INT,course_id INT,mental_health_score INT); INSERT INTO students (student_id,course_id,mental_health_score) VALUES (6,15,80),(7,16,85),(8,17,70),(9,18,90),(10,19,65); CREATE TABLE courses (course_id INT,course_type VARCHAR(20)); INSERT INTO courses (course_id,course_type) VALUES (15,'Traditional'),(16,'Open Pedagogy'),(17,'Traditional'),(18,'Open Pedagogy'),(19,'Open Pedagogy');
SELECT AVG(students.mental_health_score) FROM students JOIN courses ON students.course_id = courses.course_id WHERE courses.course_type = 'Traditional';
What is the average salary of male and female employees in the 'employees' table?
CREATE TABLE employees (id INT,name VARCHAR(255),gender VARCHAR(255),country VARCHAR(255),salary DECIMAL(10,2)); INSERT INTO employees (id,name,gender,country,salary) VALUES (1,'John Doe','Male','USA',50000); INSERT INTO employees (id,name,gender,country,salary) VALUES (2,'Jane Smith','Female','Canada',60000); INSERT INTO employees (id,name,gender,country,salary) VALUES (3,'Alice Johnson','Female','USA',55000);
SELECT gender, AVG(salary) FROM employees GROUP BY gender;
What is the production count for well 'A01' in the 'Gulf of Mexico'?
CREATE TABLE wells (well_id VARCHAR(10),well_location VARCHAR(20)); INSERT INTO wells (well_id,well_location) VALUES ('A01','Gulf of Mexico'); CREATE TABLE production (well_id VARCHAR(10),production_count INT); INSERT INTO production (well_id,production_count) VALUES ('A01',5000);
SELECT production_count FROM production WHERE well_id = 'A01';
Which athletes have the most gold medals in the Winter Olympics?
CREATE TABLE winter_olympics (athlete TEXT,gold INT,silver INT,bronze INT,year INT);
SELECT athlete, SUM(gold) FROM winter_olympics GROUP BY athlete ORDER BY SUM(gold) DESC LIMIT 1;
Which basketball players have scored the most points in a single season?
CREATE TABLE points (player_id INT,name TEXT,team TEXT,position TEXT,points_per_game FLOAT,season_points INT); INSERT INTO points (player_id,name,team,position,points_per_game,season_points) VALUES (1,'Stephen Curry','Golden State Warriors','Guard',32.0,2454),(2,'LeBron James','Los Angeles Lakers','Forward',25.0,2173);
SELECT p.name, p.season_points FROM points p ORDER BY p.season_points DESC;
How many organizations provide 'food_support' in 'refugee_camps' and 'disaster_zones'?
CREATE TABLE refugee_camps (id INT,num_orgs INT,services VARCHAR(50));CREATE TABLE disaster_zones (id INT,num_orgs INT,services VARCHAR(50));
SELECT SUM(num_orgs) FROM refugee_camps WHERE services LIKE '%food_support%' UNION SELECT SUM(num_orgs) FROM disaster_zones WHERE services LIKE '%food_support%';