instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
List the top 5 players with the highest points per game, including their team name and average points per game.
CREATE TABLE players (id INT,name TEXT,team TEXT,points_per_game DECIMAL(5,2)); INSERT INTO players (id,name,team,points_per_game) VALUES (1,'John Doe','Team A',15.6),(2,'Jane Smith','Team B',18.2),(3,'Maria Garcia','Team A',20.1),(4,'James Johnson','Team C',14.5),(5,'Emily Davis','Team B',16.8);
SELECT p.name, p.team, AVG(p.points_per_game) as avg_points_per_game FROM players p GROUP BY p.name, p.team ORDER BY avg_points_per_game DESC LIMIT 5;
Which team has the highest number of wins in the 'basketball_games' table?
CREATE TABLE basketball_teams (team_id INT,name VARCHAR(50)); CREATE TABLE basketball_games (game_id INT,home_team INT,away_team INT,home_team_score INT,away_team_score INT); INSERT INTO basketball_teams (team_id,name) VALUES (1,'Boston Celtics'),(2,'Los Angeles Lakers'),(3,'Chicago Bulls'); INSERT INTO basketball_games (game_id,home_team,away_team,home_team_score,away_team_score) VALUES (1,1,2,85,80),(2,2,3,95,90),(3,3,1,75,85);
SELECT name AS team, MAX(home_team_wins + away_team_wins) AS highest_wins FROM (SELECT name, CASE WHEN home_team = team_id AND home_team_score > away_team_score THEN 1 ELSE 0 END + CASE WHEN away_team = team_id AND away_team_score > home_team_score THEN 1 ELSE 0 END AS home_team_wins, CASE WHEN home_team = team_id AND home_team_score < away_team_score THEN 1 ELSE 0 END + CASE WHEN away_team = team_id AND away_team_score < home_team_score THEN 1 ELSE 0 END AS away_team_wins FROM basketball_teams JOIN basketball_games ON basketball_teams.team_id = basketball_games.home_team OR basketball_teams.team_id = basketball_games.away_team) AS subquery GROUP BY name;
How many volunteers with 'Medical' skills were assigned before a volunteer with 'Engineering' skills?
CREATE TABLE volunteers_ext (id INT,name VARCHAR(50),age INT,gender VARCHAR(10),skill VARCHAR(50),assignment_date DATE,end_date DATE); INSERT INTO volunteers_ext (id,name,age,gender,skill,assignment_date,end_date) VALUES (1,'David',25,'Male','Medical','2022-06-01','2022-09-30'),(2,'Emma',30,'Female','Engineering','2022-07-15','2023-06-30');
SELECT COUNT(*) FROM (SELECT skill, assignment_date, LAG(skill) OVER (ORDER BY assignment_date) AS prev_skill FROM volunteers_ext WHERE skill = 'Medical') t WHERE prev_skill = 'Engineering';
Which communities in Africa have received the most humanitarian aid, and what is the total amount of aid received?
CREATE TABLE communities (id INT,name TEXT,country TEXT); INSERT INTO communities (id,name,country) VALUES (1,'Community A','Kenya'),(2,'Community B','Somalia'),(3,'Community C','South Africa'); CREATE TABLE aid (id INT,community INT,amount FLOAT); INSERT INTO aid (id,community,amount) VALUES (1,1,500),(2,2,750),(3,1,250);
SELECT c.name, SUM(a.amount) as total_aid FROM communities c JOIN aid a ON c.id = a.community WHERE c.country = 'Africa' GROUP BY c.name ORDER BY total_aid DESC LIMIT 1;
What is the total fare collected for each train line?
CREATE TABLE train_lines (line_id INT,line_name TEXT); CREATE TABLE fares (fare_id INT,line_id INT,fare DECIMAL); INSERT INTO train_lines VALUES (1,'Line 1'),(2,'Line 2'),(3,'Line 3'); INSERT INTO fares VALUES (1,1,3.50),(2,1,3.50),(3,2,4.25),(4,3,5.00),(5,3,5.00);
SELECT train_lines.line_name, SUM(fares.fare) AS total_fare FROM train_lines INNER JOIN fares ON train_lines.line_id = fares.line_id GROUP BY train_lines.line_id;
What was the total fare collected on the 'Green Line' on March 15th, 2021?
CREATE SCHEMA trans schemas.trans; CREATE TABLE green_line (route_id INT,fare FLOAT,date DATE); INSERT INTO green_line (route_id,fare,date) VALUES (101,2.50,'2021-03-15'),(101,2.50,'2021-03-15'),(101,2.50,'2021-03-15'),(101,2.50,'2021-03-15');
SELECT SUM(fare) FROM green_line WHERE route_id = 101 AND date = '2021-03-15';
Which station on the 'Red' line has the lowest fare collection?
CREATE TABLE routes (line VARCHAR(10),station VARCHAR(20)); INSERT INTO routes (line,station) VALUES ('Red','Station X'),('Red','Station Y'),('Red','Station Z'); CREATE TABLE fares (station VARCHAR(20),revenue DECIMAL(10,2)); INSERT INTO fares (station,revenue) VALUES ('Station X',3000),('Station X',3500),('Station Y',2000),('Station Z',1500),('Station Z',1800);
SELECT station, MIN(revenue) FROM fares WHERE station IN (SELECT station FROM routes WHERE line = 'Red') GROUP BY station;
Delete the product with the highest price in the 'Sustainable' category.
CREATE TABLE products (product_id INT,name TEXT,category TEXT,price FLOAT); INSERT INTO products (product_id,name,category,price) VALUES (1,'Dress','Fair Trade',80.0); INSERT INTO products (product_id,name,category,price) VALUES (2,'Shirt','Fair Trade',60.0);
DELETE FROM products WHERE price = (SELECT MAX(price) FROM products WHERE category = 'Sustainable');
Show the percentage of sustainable material used by each brand as compared to the total quantity of sustainable material used by all brands.
CREATE TABLE Total_Sustainable_Material(Total_Quantity INT); INSERT INTO Total_Sustainable_Material(Total_Quantity) VALUES (2200);
SELECT Brand_Name, (SUM(Quantity) * 100.0 / (SELECT Total_Quantity FROM Total_Sustainable_Material)) as Percentage FROM Brands GROUP BY Brand_Name;
What is the total CO2 emission from transportation for each country in the ethical fashion supply chain?
CREATE TABLE transportation (id INT,country VARCHAR(255),co2_emission_kg INT,orders INT); INSERT INTO transportation VALUES (1,'Italy',150,2000),(2,'Germany',120,1500),(3,'Italy',180,3000),(4,'Brazil',80,1000);
SELECT country, SUM(co2_emission_kg) FROM transportation GROUP BY country;
Show me the total ad revenue generated per month for a specific advertiser (AdvertiserID = 1001)
CREATE TABLE advertiser (advertiser_id INT,name VARCHAR(50)); CREATE TABLE ad_revenue (advertiser_id INT,revenue DECIMAL(10,2),month_year DATE); INSERT INTO advertiser (advertiser_id,name) VALUES (1001,'ABC Company'),(1002,'XYZ Inc'); INSERT INTO ad_revenue (advertiser_id,revenue,month_year) VALUES (1001,5000.50,'2022-01-01'),(1001,6000.25,'2022-02-01'),(1002,4000.00,'2022-01-01');
SELECT DATE_FORMAT(month_year, '%Y-%m') AS month, SUM(revenue) AS total_revenue FROM ad_revenue WHERE advertiser_id = 1001 GROUP BY month;
What is the minimum Shariah-compliant loan amount issued in the last quarter of 2021?
CREATE TABLE loans (id INT,amount DECIMAL,date DATE,loan_type VARCHAR); INSERT INTO loans (id,amount,date,loan_type) VALUES (1,5000,'2021-09-05','Shariah-compliant'),(2,7000,'2021-10-07','socially responsible'),(3,9000,'2021-11-03','Shariah-compliant'),(4,11000,'2021-12-31','Shariah-compliant');
SELECT MIN(amount) FROM loans WHERE EXTRACT(YEAR FROM date) = 2021 AND EXTRACT(QUARTER FROM date) = 4 AND loan_type = 'Shariah-compliant';
What is the average donation amount and number of donations for each program in the 'programs' and 'donations' tables?
CREATE TABLE programs (program_id INT,program_name TEXT); CREATE TABLE donations (donation_id INT,donor_id INT,program_id INT,donation_amount FLOAT); INSERT INTO programs (program_id,program_name) VALUES (1,'Education'),(2,'Health'),(3,'Environment'); INSERT INTO donations (donation_id,donor_id,program_id,donation_amount) VALUES (1,1,1,50.00),(2,2,1,100.00),(3,3,2,150.00);
SELECT p.program_name, AVG(d.donation_amount) as avg_donation, COUNT(d.donation_id) as num_donations FROM programs p JOIN donations d ON p.program_id = d.program_id GROUP BY p.program_name;
How many shipments were made from each country?
CREATE TABLE shipments (shipment_id INT,country TEXT); INSERT INTO shipments (shipment_id,country) VALUES (1,'Germany'),(2,'France'),(3,'Germany'),(4,'Spain'),(5,'France');
SELECT country, COUNT(*) as total_shipments FROM shipments GROUP BY country;
What is the total quantity of items with type 'E' or type 'F' in warehouse O and warehouse P?
CREATE TABLE warehouse_o(item_id INT,item_type VARCHAR(10),quantity INT);CREATE TABLE warehouse_p(item_id INT,item_type VARCHAR(10),quantity INT);INSERT INTO warehouse_o(item_id,item_type,quantity) VALUES (1,'E',200),(2,'F',300),(3,'E',50),(4,'F',400);INSERT INTO warehouse_p(item_id,item_type,quantity) VALUES (1,'E',150),(2,'F',250),(3,'E',40),(4,'F',350);
SELECT quantity FROM warehouse_o WHERE item_type IN ('E', 'F') UNION ALL SELECT quantity FROM warehouse_p WHERE item_type IN ('E', 'F');
Which parcel_delivery routes have a distance greater than 1000 kilometers?
CREATE TABLE parcel_delivery (route_id INT,start_location VARCHAR(255),end_location VARCHAR(255),distance INT); INSERT INTO parcel_delivery (route_id,start_location,end_location,distance) VALUES (1,'New York','Los Angeles',4000),(2,'Chicago','Miami',2500),(3,'Toronto','Vancouver',3500),(4,'London','Glasgow',800),(5,'Paris','Berlin',1200);
SELECT route_id, start_location, end_location, distance FROM parcel_delivery WHERE distance > 1000;
Show the total budget allocated to healthcare programs in each department from the 'government_budget' database.
CREATE TABLE departments (id INT PRIMARY KEY,name VARCHAR(255));CREATE TABLE programs (id INT PRIMARY KEY,name VARCHAR(255),department_id INT,FOREIGN KEY (department_id) REFERENCES departments(id),budget INT); INSERT INTO departments (id,name) VALUES (1,'Health and Human Services'); INSERT INTO departments (id,name) VALUES (2,'Education');
SELECT departments.name, SUM(programs.budget) as total_budget FROM departments INNER JOIN programs ON departments.id = programs.department_id WHERE programs.name LIKE '%healthcare%' GROUP BY departments.name;
What is the total revenue generated from eco-friendly tours in France?
CREATE TABLE tours (id INT,country VARCHAR(20),type VARCHAR(20),revenue FLOAT); INSERT INTO tours (id,country,type,revenue) VALUES (1,'France','Eco-friendly',5000.0),(2,'Italy','Regular',4000.0);
SELECT SUM(revenue) FROM tours WHERE country = 'France' AND type = 'Eco-friendly';
Who are the top 3 artists with the most artworks in the 'Cubism' category, excluding artists who have less than 5 artworks in total?
CREATE TABLE Artists (ArtistID INT PRIMARY KEY,Name TEXT); CREATE TABLE Artworks (ArtworkID INT PRIMARY KEY,Title TEXT,ArtistID INT,Category TEXT,Quantity INT);
SELECT Artists.Name FROM Artists INNER JOIN Artworks ON Artists.ArtistID = Artworks.ArtistID WHERE Artworks.Category = 'Cubism' GROUP BY Artists.Name HAVING SUM(Artworks.Quantity) > 5 ORDER BY SUM(Artworks.Quantity) DESC LIMIT 3;
Which indigenous communities share a region with the snow leopard?
CREATE TABLE IndigenousCommunities (id INT PRIMARY KEY,name VARCHAR(100),population INT,region VARCHAR(50)); INSERT INTO IndigenousCommunities (id,name,population,region) VALUES (2,'Nenets',45000,'Arctic'),(3,'Sami',80000,'Arctic');
SELECT IndigenousCommunities.name FROM IndigenousCommunities INNER JOIN Species ON IndigenousCommunities.region = Species.region WHERE Species.name = 'Snow Leopard';
What is the number of patients who identified as Indigenous and received therapy in H2 2021?
CREATE TABLE patients (id INT,race VARCHAR(25),therapy_date DATE); INSERT INTO patients (id,race,therapy_date) VALUES (1,'Indigenous','2021-07-15'),(2,'White','2021-08-20'),(3,'Hispanic or Latino','2021-07-03'),(4,'Asian','2021-09-10'),(5,'Indigenous','2021-08-08'),(6,'White','2021-09-25'),(7,'Hispanic or Latino','2021-07-12'),(8,'Asian','2021-08-02');
SELECT COUNT(*) FROM patients WHERE race = 'Indigenous' AND therapy_date >= '2021-07-01' AND therapy_date < '2022-01-01';
Get the number of bridges built in each decade since 1950
CREATE TABLE Bridges (bridge_id int,bridge_name varchar(255),year int,location varchar(255));
SELECT (year - 1900) / 10 AS decade, COUNT(*) FROM Bridges WHERE year >= 1950 GROUP BY decade;
What is the minimum, maximum, and average age of victims who have participated in restorative justice programs, by location?
CREATE TABLE victims (id INT,age INT,gender TEXT,ethnicity TEXT,location TEXT); INSERT INTO victims (id,age,gender,ethnicity,location) VALUES (1,45,'Female','Hispanic','Texas'),(2,67,'Male','Asian','California'),(3,34,'Female','African American','New York'); CREATE TABLE restorative_justice_participants (id INT,victim_id INT,program_id INT); INSERT INTO restorative_justice_participants (id,victim_id,program_id) VALUES (1,1,1),(2,2,2),(3,3,3);
SELECT location, MIN(v.age) AS min_age, MAX(v.age) AS max_age, AVG(v.age) AS avg_age FROM victims v JOIN restorative_justice_participants rjp ON v.id = rjp.victim_id GROUP BY location;
Show the total number of marine protected areas in the Pacific Ocean
CREATE TABLE marine_protected_areas (area_name TEXT,location TEXT,size_km INTEGER); INSERT INTO marine_protected_areas (area_name,location,size_km) VALUES ('Mariana Trench Marine National Monument','Pacific Ocean',95804),('Papahānaumokuākea Marine National Monument','Pacific Ocean',1397970),('Rose Atoll Marine National Monument','Pacific Ocean',11628);
SELECT COUNT(*) FROM marine_protected_areas WHERE location = 'Pacific Ocean';
List the names and publication years of Middle Eastern authors who have published books in the 'Non-fiction' genre.
CREATE TABLE authors (id INT PRIMARY KEY,name VARCHAR(255),ethnicity VARCHAR(255)); INSERT INTO authors (id,name,ethnicity) VALUES (1,'Rania Abouzeid','Middle Eastern'); INSERT INTO authors (id,name,ethnicity) VALUES (2,'Khaled Hosseini','Middle Eastern'); CREATE TABLE books (id INT PRIMARY KEY,title VARCHAR(255),author_id INT,publication_year INT,genre VARCHAR(255)); INSERT INTO books (id,title,author_id,publication_year,genre) VALUES (1,'No Turning Back',1,2018,'Non-fiction'); INSERT INTO books (id,title,author_id,publication_year,genre) VALUES (2,'The Kite Runner',2,2003,'Fiction'); INSERT INTO books (id,title,author_id,publication_year,genre) VALUES (3,'A Thousand Splendid Suns',2,2007,'Fiction'); CREATE TABLE genres (id INT PRIMARY KEY,genre VARCHAR(255)); INSERT INTO genres (id,genre) VALUES (1,'Fiction'); INSERT INTO genres (id,genre) VALUES (2,'Non-fiction');
SELECT a.name, b.publication_year FROM authors a INNER JOIN books b ON a.id = b.author_id INNER JOIN genres g ON b.genre = g.genre WHERE a.ethnicity = 'Middle Eastern' AND g.genre = 'Non-fiction';
Determine the percentage of women in the workforce by department.
CREATE TABLE departments (id INT,name TEXT,workforce FLOAT,female_workforce FLOAT);
SELECT name, (female_workforce/workforce)*100 as percentage_of_women FROM departments ORDER BY percentage_of_women DESC;
What is the number of employees in each department, ordered from the highest to the lowest?
CREATE TABLE mining_operations (id INT,name VARCHAR(50),department VARCHAR(50),age INT);
SELECT department, COUNT(*) AS count FROM mining_operations GROUP BY department ORDER BY count DESC;
What is the percentage of mobile customers who are using 4G networks in each city?
CREATE TABLE mobile_networks (id INT,customer_id INT,network_type VARCHAR(50));
SELECT city, 100.0 * SUM(CASE WHEN network_type = '4G' THEN 1 ELSE 0 END) / COUNT(*) AS pct FROM mobile_networks JOIN mobile_subscribers ON mobile_networks.customer_id = mobile_subscribers.id GROUP BY city;
What is the total data usage for each mobile plan in a given month?
CREATE TABLE subscriber_data (subscriber_id INT,plan_id INT,data_usage DECIMAL(10,2),usage_month VARCHAR(7)); INSERT INTO subscriber_data (subscriber_id,plan_id,data_usage,usage_month) VALUES (1,1,2.00,'Jan-2022'),(2,2,8.00,'Jan-2022'),(3,3,25.00,'Jan-2022'),(4,1,3.00,'Jan-2022'),(5,2,10.00,'Jan-2022'),(6,3,30.00,'Jan-2022');
SELECT plan_id, SUM(data_usage) AS total_data_usage FROM subscriber_data WHERE usage_month = 'Jan-2022' GROUP BY plan_id;
How many concert tickets were sold in Europe in 2020?
CREATE TABLE tickets (ticket_id INT,concert_id INT,location VARCHAR(255),year INT,quantity INT); INSERT INTO tickets (ticket_id,concert_id,location,year,quantity) VALUES (1,1,'London',2020,500);
SELECT SUM(quantity) FROM tickets WHERE location LIKE 'Europe%' AND year = 2020;
How many streams did each song by an artist get in a given month?
CREATE TABLE Songs (id INT,artist_id INT,title VARCHAR(50)); CREATE TABLE Streams (id INT,song_id INT,date DATE,streams INT); INSERT INTO Songs (id,artist_id,title) VALUES (1,1,'Shake it Off'),(2,1,'Blank Space'),(3,2,'Humble'),(4,2,'DNA'); INSERT INTO Streams (id,song_id,date,streams) VALUES (1,1,'2022-01-01',1000),(2,1,'2022-01-02',1500),(3,2,'2022-01-01',2000),(4,2,'2022-01-02',2500),(5,3,'2022-01-01',3000),(6,3,'2022-01-02',3500),(7,4,'2022-01-01',4000),(8,4,'2022-01-02',4500);
SELECT s.title, SUM(s.streams) as total_streams FROM Songs s JOIN Streams st ON s.id = st.song_id WHERE st.date BETWEEN '2022-01-01' AND '2022-01-31' GROUP BY s.title;
Insert a new artist 'SZA' with the genre 'R&B' and 5 million monthly listeners in the 'artists' table.
CREATE TABLE artists (id INT,name VARCHAR(255),genre VARCHAR(255),monthly_listeners BIGINT);
INSERT INTO artists (name, genre, monthly_listeners) VALUES ('SZA', 'R&B', 5000000);
Calculate the average temperature of the ocean floor in the Indian Ocean.
CREATE TABLE ocean_floor_temperatures (location TEXT,temperature REAL); INSERT INTO ocean_floor_temperatures (location,temperature) VALUES ('Indian Ocean','4.5'),('Atlantic Ocean','5.2');
SELECT AVG(temperature) FROM ocean_floor_temperatures WHERE location = 'Indian Ocean';
What is the average age of players who play VR games and their total spending on games?
CREATE TABLE players (id INT,name VARCHAR(50),age INT,country VARCHAR(50)); INSERT INTO players (id,name,age,country) VALUES (1,'John Doe',25,'USA'),(2,'Jane Smith',30,'Canada'); CREATE TABLE games (id INT,name VARCHAR(50),type VARCHAR(50),price DECIMAL(5,2)); INSERT INTO games (id,name,type,price) VALUES (1,'Game1','VR',40.00),(2,'Game2','Non-VR',20.00); CREATE TABLE player_games (player_id INT,game_id INT); INSERT INTO player_games (player_id,game_id) VALUES (1,1),(2,1),(1,2);
SELECT AVG(players.age), SUM(games.price) FROM players INNER JOIN player_games ON players.id = player_games.player_id INNER JOIN games ON player_games.game_id = games.id WHERE games.type = 'VR';
Delete records from the "sensor_data" table where the "sensor_id" is 3
CREATE TABLE sensor_data (sensor_id INT,temp FLOAT,humidity FLOAT,light_level INT,timestamp TIMESTAMP);
DELETE FROM sensor_data WHERE sensor_id = 3;
How many public service delivery requests were received from each age group of citizens in 2022?
CREATE TABLE Requests (Age_Group TEXT,Year INTEGER,Num_Requests INTEGER); INSERT INTO Requests (Age_Group,Year,Num_Requests) VALUES ('18-30',2022,200),('31-50',2022,300),('51-65',2022,250),('66+',2022,150);
SELECT Age_Group, SUM(Num_Requests) FROM Requests WHERE Year = 2022 GROUP BY Age_Group;
What is the sum of lanthanum imports to Norway and Sweden for the years 2018 and 2019?
CREATE TABLE lanthanum_imports (year INT,country TEXT,quantity INT); INSERT INTO lanthanum_imports (year,country,quantity) VALUES (2018,'Norway',150),(2019,'Norway',160),(2018,'Sweden',140),(2019,'Sweden',150);
SELECT SUM(quantity) FROM lanthanum_imports WHERE country IN ('Norway', 'Sweden') AND year IN (2018, 2019);
How many properties are there in total for each co-ownership model?
CREATE TABLE coownership_model (model_id INT,property_id INT); INSERT INTO coownership_model (model_id,property_id) VALUES (1,1),(2,1),(1,2),(2,2),(1,3);
SELECT cm.model_id, COUNT(*) as total_properties FROM coownership_model cm GROUP BY cm.model_id;
What is the minimum property tax for properties in the table 'co_ownership' that are located in the city of New York?
CREATE TABLE co_ownership (id INT,property_tax FLOAT,city VARCHAR(20)); INSERT INTO co_ownership (id,property_tax,city) VALUES (1,5000,'Chicago'),(2,7000,'New York'),(3,3000,'Los Angeles');
SELECT MIN(property_tax) FROM co_ownership WHERE city = 'New York';
What is the average energy efficiency score for buildings in each country, ordered by the highest average score?
CREATE TABLE Buildings (id INT,country VARCHAR(50),city VARCHAR(50),efficiency_score INT); INSERT INTO Buildings VALUES (1,'USA','NYC',75),(2,'USA','LA',60),(3,'Canada','Toronto',80),(4,'Canada','Vancouver',85),(5,'Mexico','Mexico City',65);
SELECT country, AVG(efficiency_score) AS avg_efficiency_score FROM Buildings GROUP BY country ORDER BY avg_efficiency_score DESC;
Which menu categories have a daily revenue greater than the average daily revenue?
CREATE TABLE menu_engineering (menu_category VARCHAR(255),daily_revenue DECIMAL(10,2)); INSERT INTO menu_engineering (menu_category,daily_revenue) VALUES ('Appetizers',500.00),('Entrees',2500.00),('Desserts',1000.00);
SELECT menu_category, daily_revenue FROM menu_engineering WHERE daily_revenue > (SELECT AVG(daily_revenue) FROM menu_engineering);
Show the names of suppliers that provide materials for at least 3 products.
CREATE TABLE products (product_id INT,product_name TEXT); CREATE TABLE materials (material_id INT,material_name TEXT,product_id INT,supplier_id INT); INSERT INTO products (product_id,product_name) VALUES (1,'Product A'),(2,'Product B'),(3,'Product C'),(4,'Product D'),(5,'Product E'); INSERT INTO materials (material_id,material_name,product_id,supplier_id) VALUES (1,'Material 1',1,101),(2,'Material 2',1,102),(3,'Material 3',2,103),(4,'Material 4',3,101),(5,'Material 5',3,102),(6,'Material 6',4,103),(7,'Material 7',5,101),(8,'Material 8',5,102),(9,'Material 9',5,103);
SELECT supplier_id FROM materials GROUP BY supplier_id HAVING COUNT(DISTINCT product_id) >= 3;
What are the names and launch dates of all astronauts who have participated in space missions?
CREATE TABLE Astronaut (Id INT,FirstName VARCHAR(50),LastName VARCHAR(50),BirthDate DATETIME,Gender VARCHAR(10),Nationality VARCHAR(50),MissionId INT); INSERT INTO Astronaut (Id,FirstName,LastName,BirthDate,Gender,Nationality,MissionId) VALUES (5,'Neil','Armstrong','1930-08-05','Male','United States',1);
SELECT FirstName, LastName, LaunchDate FROM Astronaut a JOIN SpaceMission sm ON a.MissionId = sm.Id;
What is the total cost of Mars rover missions that have successfully landed?
CREATE TABLE mars_rovers (id INT PRIMARY KEY,name VARCHAR(255),mission_type VARCHAR(255),agency VARCHAR(255),cost FLOAT,launched_date DATE,landed_date DATE);
SELECT SUM(cost) FROM mars_rovers WHERE mission_type = 'Lander' AND landed_date IS NOT NULL;
How many fans from the "Fans" table live in the state of New York and have never attended a game?
CREATE TABLE fans (id INT,name VARCHAR(50),state VARCHAR(50),games_attended INT);
SELECT COUNT(*) FROM fans WHERE state = 'New York' AND games_attended = 0;
How many unique user accounts have been accessing the system in the past month?
CREATE TABLE user_activity (id INT,user_id INT,activity_time TIMESTAMP);
SELECT COUNT(DISTINCT user_id) as unique_users FROM user_activity WHERE activity_time >= NOW() - INTERVAL '1 month';
List all autonomous bus routes and their operating companies in Tokyo, Japan.
CREATE TABLE autonomous_buses (bus_id INT,route VARCHAR(100),company VARCHAR(100),city VARCHAR(50));
SELECT route, company FROM autonomous_buses WHERE city = 'Tokyo';
What is the distribution of trips by mode of transport?
CREATE TABLE trips (user_id INT,trip_date DATE,mode VARCHAR(50),trip_count INT);
SELECT mode, SUM(trip_count) as total_trips FROM trips GROUP BY mode;
Get the count of 'Vegan Leather Shoes' orders in France with a quantity greater than 3.
CREATE TABLE garments (id INT,name VARCHAR(255),category VARCHAR(255),country VARCHAR(255)); INSERT INTO garments (id,name,category,country) VALUES (1,'Vegan Leather Shoes','Footwear','France'); CREATE TABLE orders (id INT,garment_id INT,quantity INT,order_date DATE);
SELECT COUNT(*) FROM orders INNER JOIN garments ON orders.garment_id = garments.id WHERE garments.name = 'Vegan Leather Shoes' AND garments.country = 'France' AND orders.quantity > 3;
What is the average CO2 emissions for the garment manufacturing process for each collection?
CREATE TABLE emissions (collection VARCHAR(20),co2_emissions INT); INSERT INTO emissions (collection,co2_emissions) VALUES ('Spring 2021',10000),('Fall 2021',12000),('Winter 2021',15000),('Spring 2022',18000);
SELECT collection, AVG(co2_emissions) FROM emissions GROUP BY collection;
How many workplace safety incidents were reported in the Construction industry in 2021?
CREATE TABLE WorkplaceSafety (id INT,year INT,industry VARCHAR(255),incidents INT); INSERT INTO WorkplaceSafety (id,year,industry,incidents) VALUES (1,2021,'Construction',12);
SELECT incidents FROM WorkplaceSafety WHERE industry = 'Construction' AND year = 2021;
List the collective bargaining agreements and their expiration dates for the 'agriculture' sector
CREATE TABLE agriculture_cb_expirations (id INT,sector VARCHAR(20),expiration_date DATE); INSERT INTO agriculture_cb_expirations (id,sector,expiration_date) VALUES (1,'agriculture','2023-01-01'),(2,'agriculture','2022-12-31');
SELECT * FROM agriculture_cb_expirations WHERE sector = 'agriculture';
What is the average age of members in unions advocating for 'CivilRights'?
CREATE TABLE UnionMembership (member_id INT,union_id INT); CREATE TABLE Unions (union_id INT,cause TEXT,member_count INT,member_age INT);
SELECT AVG(Unions.member_age) FROM UnionMembership INNER JOIN Unions ON UnionMembership.union_id = Unions.union_id WHERE Unions.cause = 'CivilRights';
What is the union with the fewest members in the education sector?
CREATE TABLE unions (id INT,name TEXT,industry TEXT,members INT); INSERT INTO unions (id,name,industry,members) VALUES (1,'AFT','Education',1600000),(2,'NEA','Education',3000000),(3,'UFT','Education',200000),(4,'AFT Local 1','Education',15000),(5,'AFT Local 2','Education',10000);
SELECT name FROM unions WHERE industry = 'Education' ORDER BY members LIMIT 1;
Find the top 2 car makes with the highest safety ratings, considering the average rating for each make across all models.
CREATE TABLE SafetyRatings (id INT,make VARCHAR(20),model VARCHAR(20),rating FLOAT); INSERT INTO SafetyRatings (id,make,model,rating) VALUES (1,'Tesla','Model S',5.3),(2,'Tesla','Model 3',5.1),(3,'Volvo','XC60',5.2),(4,'Volvo','XC90',5.0),(5,'Honda','Civic',4.8),(6,'Honda','Accord',4.9);
SELECT make, AVG(rating) AS avg_rating FROM SafetyRatings GROUP BY make ORDER BY avg_rating DESC LIMIT 2;
How many safety tests have been conducted for each type of vehicle in 2022?
CREATE TABLE TestTypes (Id INT,TestType VARCHAR(20)); CREATE TABLE SafetyTests (Id INT,VehicleId INT,TestTypeId INT,TestDate DATE); INSERT INTO TestTypes (Id,TestType) VALUES (1,'Crash Test'),(2,'Emission Test'),(3,'Safety Feature Test'); INSERT INTO SafetyTests (Id,VehicleId,TestTypeId,TestDate) VALUES (1,1,1,'2022-01-01'),(2,1,2,'2022-01-02'),(3,2,1,'2022-01-03'),(4,2,2,'2022-01-04'),(5,3,1,'2022-01-05');
SELECT TestTypes.TestType, COUNT(*) FROM TestTypes INNER JOIN SafetyTests ON TestTypes.Id = SafetyTests.TestTypeId WHERE YEAR(TestDate) = 2022 GROUP BY TestTypes.TestType;
Update the 'safety_score' for the 'vehicle_make' 'Polestar' in the 'safety_ratings' table to 95
CREATE TABLE safety_ratings (vehicle_make VARCHAR(255),safety_score INT);
UPDATE safety_ratings SET safety_score = 95 WHERE vehicle_make = 'Polestar';
Identify the states with the highest wastewater treatment plant construction rates between 2005 and 2015, excluding Texas.
CREATE TABLE wastewater_plants(state VARCHAR(20),year INT,num_plants INT); INSERT INTO wastewater_plants VALUES ('Texas',2005,10),('Texas',2006,12),('Texas',2007,14),('New York',2005,5),('New York',2006,6),('New York',2007,7),('California',2005,15),('California',2006,17),('California',2007,19);
SELECT state, AVG(num_plants) AS avg_construction_rate FROM wastewater_plants WHERE state != 'Texas' AND year BETWEEN 2005 AND 2007 GROUP BY state ORDER BY avg_construction_rate DESC LIMIT 2;
Insert records into the 'drought_impact' table for the 'West' region with a 'severity' rating of 'low' and a 'year' of 2021
CREATE TABLE drought_impact (region VARCHAR(20),severity VARCHAR(10),year INT);
INSERT INTO drought_impact (region, severity, year) VALUES ('West', 'low', 2021);
List members who did more than 10 yoga workouts and their total yoga workouts.
CREATE TABLE membership_data (member_id INT,join_date DATE); CREATE TABLE workout_data (workout_id INT,member_id INT,workout_type VARCHAR(20),workout_date DATE);
SELECT m.member_id, m.join_date, COUNT(w.workout_id) as total_yoga_workouts FROM membership_data m JOIN workout_data w ON m.member_id = w.member_id WHERE w.workout_type = 'yoga' GROUP BY m.member_id HAVING COUNT(w.workout_id) > 10;
Display economic diversification efforts and their respective program managers from the 'rural_development' database
CREATE TABLE economic_diversification (id INT,effort VARCHAR(50),description TEXT,program_manager VARCHAR(50)); INSERT INTO economic_diversification (id,effort,description,program_manager) VALUES (1,'Renewable Energy','Promoting clean energy alternatives','John Doe'); INSERT INTO economic_diversification (id,effort,description,program_manager) VALUES (2,'Artisanal Crafts','Supporting local artisans and their crafts','Jane Smith');
SELECT effort, program_manager FROM economic_diversification;
Show the types of economic diversification initiatives and the number of community members involved in each from the 'economic_diversification' and 'community_development' tables
CREATE TABLE economic_diversification (initiative_id INT,initiative_name VARCHAR(50),member_id INT); CREATE TABLE community_development (member_id INT,member_name VARCHAR(50),age INT);
SELECT e.initiative_name, COUNT(c.member_id) FROM economic_diversification e INNER JOIN community_development c ON e.member_id = c.member_id GROUP BY e.initiative_name;
What is the total number of animals in the 'animal_population' table, grouped by species?
CREATE TABLE animal_population (species VARCHAR(50),animal_count INT);
SELECT species, SUM(animal_count) FROM animal_population GROUP BY species;
Which species of fish has the highest average daily growth rate in the Americas?
CREATE TABLE FishGrowth (SiteID INT,Species VARCHAR(255),DailyGrowthRate FLOAT,Region VARCHAR(255)); INSERT INTO FishGrowth (SiteID,Species,DailyGrowthRate,Region) VALUES (1,'Tilapia',0.02,'Americas'),(2,'Salmon',0.03,'Americas'),(3,'Tilapia',0.015,'Asia-Pacific'),(4,'Salmon',0.025,'Europe');
SELECT Species, AVG(DailyGrowthRate) as AvgDailyGrowthRate FROM FishGrowth WHERE Region = 'Americas' GROUP BY Species ORDER BY AvgDailyGrowthRate DESC LIMIT 1;
What is the total funding_amount for art_exhibit events in Q4 2020?
CREATE TABLE art_exhibit_funding_q4_2020 (id INT,funding_amount INT,event_date DATE); INSERT INTO art_exhibit_funding_q4_2020 (id,funding_amount,event_date) VALUES (1,10000,'2020-10-01'),(2,15000,'2020-11-01'),(3,12000,'2020-12-01');
SELECT SUM(funding_amount) FROM art_exhibit_funding_q4_2020 WHERE MONTH(event_date) BETWEEN 10 AND 12;
How many building permits were issued per month in 2020?
CREATE TABLE building_permits (id INT,permit_number INT,issue_date DATE,permit_type VARCHAR(255));
SELECT DATE_FORMAT(issue_date, '%Y-%m') as month, COUNT(*) as permits_issued FROM building_permits WHERE YEAR(issue_date) = 2020 GROUP BY month;
What is the total salary paid to construction workers who worked on sustainable building projects in Washington?
CREATE TABLE ConstructionLaborStatistics (id INT,name VARCHAR(50),job VARCHAR(50),salary INT); INSERT INTO ConstructionLaborStatistics VALUES (1,'Charles Doe','Carpenter',50000); INSERT INTO ConstructionLaborStatistics VALUES (2,'Diana Smith','Electrician',60000); CREATE TABLE BuildingTypes (id INT,building_type VARCHAR(50)); INSERT INTO BuildingTypes VALUES (1,'Sustainable'); INSERT INTO BuildingTypes VALUES (2,'Non-Sustainable'); CREATE TABLE WorkerBuildings (worker_id INT,building_id INT); INSERT INTO WorkerBuildings VALUES (1,1); INSERT INTO WorkerBuildings VALUES (2,2);
SELECT SUM(cls.salary) FROM ConstructionLaborStatistics cls JOIN WorkerBuildings wb ON cls.id = wb.worker_id JOIN BuildingTypes bt ON wb.building_id = bt.id WHERE bt.building_type = 'Sustainable' AND state = 'Washington';
Calculate the total billing amount for cases with a precedent set in the last 3 years for French law.
CREATE TABLE Cases (CaseID INT,PrecedentYear INT,PrecedentType VARCHAR(255)); INSERT INTO Cases (CaseID,PrecedentYear,PrecedentType) VALUES (1,2018,'French'); INSERT INTO Cases (CaseID,PrecedentYear,PrecedentType) VALUES (2,2019,'French'); INSERT INTO Cases (CaseID,PrecedentYear,PrecedentType) VALUES (3,2020,'French'); CREATE TABLE Precedents (CaseID INT,BillingAmount INT); INSERT INTO Precedents (CaseID,BillingAmount) VALUES (1,2000); INSERT INTO Precedents (CaseID,BillingAmount) VALUES (2,3000); INSERT INTO Precedents (CaseID,BillingAmount) VALUES (3,1000);
SELECT SUM(BillingAmount) FROM Precedents JOIN Cases ON Precedents.CaseID = Cases.CaseID WHERE PrecedentYear >= YEAR(CURRENT_DATE) - 3 AND PrecedentType = 'French';
Select the total number of cases won by attorneys in the 'Boston' office.
CREATE TABLE offices (office_id INT,office_name VARCHAR(20)); INSERT INTO offices (office_id,office_name) VALUES (1,'Boston'),(2,'New York'),(3,'Chicago'); CREATE TABLE cases (case_id INT,attorney_id INT,office_id INT,case_outcome VARCHAR(10)); INSERT INTO cases (case_id,attorney_id,office_id,case_outcome) VALUES (1,101,1,'Won'),(2,102,1,'Lost'),(3,103,2,'Won');
SELECT COUNT(*) FROM cases c JOIN offices o ON c.office_id = o.office_id WHERE o.office_name = 'Boston' AND c.case_outcome = 'Won';
Update the 'crops' table to set the 'irrigation' column to 'Drip' for all entries where the crop_name is 'Tomato'.
CREATE TABLE crops (id INT,crop_name VARCHAR(255),irrigation VARCHAR(255)); INSERT INTO crops (id,crop_name,irrigation) VALUES (1,'Tomato','Sprinkler'),(2,'Potato','Furrow'),(3,'Corn','None');
UPDATE crops SET irrigation = 'Drip' WHERE crop_name = 'Tomato';
How many policy advocacy initiatives were implemented in each state in the last 5 years?
CREATE TABLE Policy_Advocacy_Initiatives (state VARCHAR(255),initiation_date DATE); INSERT INTO Policy_Advocacy_Initiatives (state,initiation_date) VALUES ('California','2017-01-01'),('Texas','2018-01-01'),('New York','2016-01-01'),('Florida','2019-01-01'),('Illinois','2015-01-01');
SELECT state, COUNT(*) as num_initiatives FROM Policy_Advocacy_Initiatives WHERE initiation_date >= DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR) GROUP BY state;
What is the total number of students with and without disabilities in each academic year?
CREATE TABLE students (student_id INT,student_name TEXT,disability BOOLEAN,year INT); INSERT INTO students (student_id,student_name,disability,year) VALUES (1,'Alice',true,2018),(2,'Bob',false,2018),(3,'Carol',true,2019),(4,'Dave',false,2019);
SELECT year, SUM(CASE WHEN disability THEN 1 ELSE 0 END) AS students_with_disabilities, SUM(CASE WHEN NOT disability THEN 1 ELSE 0 END) AS students_without_disabilities FROM students GROUP BY year;
List the regulatory frameworks in the 'United States' that have enacted blockchain-related legislation.
CREATE TABLE us_regulatory_frameworks (framework_name TEXT,country TEXT);
SELECT framework_name FROM us_regulatory_frameworks WHERE country = 'United States' AND framework_name LIKE '%blockchain%';
What is the total number of digital assets issued by companies based in the United States?
CREATE TABLE digital_assets (id INT,name TEXT,company TEXT,country TEXT); INSERT INTO digital_assets (id,name,company,country) VALUES (1,'ExampleAsset1','ExampleCompany1','United States');
SELECT COUNT(*) FROM digital_assets WHERE country = 'United States' AND company IS NOT NULL;
What is the minimum investment of clients in the "Commodity" 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 MIN(clients.investment) FROM clients INNER JOIN fund_investments ON clients.client_id = fund_investments.client_id WHERE fund_investments.fund_name = 'Commodity';
What is the total transaction amount by month for the US?
CREATE TABLE transactions (user_id INT,transaction_amount DECIMAL(10,2),transaction_date DATE,country VARCHAR(255)); INSERT INTO transactions (user_id,transaction_amount,transaction_date,country) VALUES (1,50.00,'2022-01-01','US'),(2,100.50,'2022-02-02','US'),(3,200.00,'2022-03-03','US');
SELECT DATE_FORMAT(transaction_date, '%Y-%m') as month, SUM(transaction_amount) as total_transaction_amount FROM transactions WHERE country = 'US' GROUP BY month;
Calculate the average downtime for each manufacturing process
CREATE TABLE manufacturing_processes (process_id INT,process_name VARCHAR(255),downtime INT); INSERT INTO manufacturing_processes (process_id,process_name,downtime) VALUES (1,'Process A',10),(2,'Process B',15),(3,'Process C',20),(4,'Process D',25);
SELECT process_name, AVG(downtime) as avg_downtime FROM manufacturing_processes GROUP BY process_name;
What is the minimum salary of employees working in factories that are located in a specific city and have a production output above a certain threshold?
CREATE TABLE factories (factory_id INT,name VARCHAR(100),location VARCHAR(100),production_output INT); CREATE TABLE employees (employee_id INT,factory_id INT,name VARCHAR(100),position VARCHAR(100),salary INT); INSERT INTO factories (factory_id,name,location,production_output) VALUES (1,'ABC Factory','New York',5500),(2,'XYZ Factory','Los Angeles',4000),(3,'LMN Factory','Houston',6000),(4,'PQR Factory','Toronto',7000); INSERT INTO employees (employee_id,factory_id,name,position,salary) VALUES (1,1,'John Doe','Engineer',70000),(2,1,'Jane Smith','Manager',80000),(3,2,'Mike Johnson','Operator',60000),(4,3,'Sara Brown','Engineer',75000),(5,3,'David Williams','Manager',85000),(6,4,'Emily Davis','Engineer',90000);
SELECT MIN(employees.salary) FROM factories INNER JOIN employees ON factories.factory_id = employees.factory_id WHERE factories.location = 'Los Angeles' AND factories.production_output > 5000;
Calculate the average distance to the nearest rural healthcare facility in Argentina and Colombia.
CREATE TABLE healthcare_facilities (facility_id INT,country VARCHAR(20),distance_km FLOAT); INSERT INTO healthcare_facilities (facility_id,country,distance_km) VALUES (1,'Argentina',10.5),(2,'Colombia',12.3);
SELECT AVG(distance_km) FROM healthcare_facilities WHERE country IN ('Argentina', 'Colombia');
Update track duration based on album release year
CREATE TABLE tracks (id INT PRIMARY KEY,title VARCHAR(255),duration FLOAT,album_id INT,FOREIGN KEY (album_id) REFERENCES albums(id)); CREATE TABLE albums (id INT PRIMARY KEY,title VARCHAR(255),release_year INT);
UPDATE tracks SET duration = duration * (release_year / 2020.0) WHERE album_id IN (SELECT id FROM albums WHERE release_year > 2000);
What was the total donation amount for each program's first-time donors in 2022?
CREATE TABLE Programs (program_id INT,program_name VARCHAR(50)); CREATE TABLE Donations (donor_id INT,donation_amount DECIMAL(10,2),donation_date DATE,program_id INT);
SELECT p.program_name, SUM(d.donation_amount) FROM Programs p JOIN Donations d ON p.program_id = d.program_id WHERE d.donor_id IN (SELECT donor_id FROM Donations WHERE YEAR(donation_date) = 2022 GROUP BY donor_id HAVING COUNT(*) = 1) GROUP BY p.program_name;
Create a view combining student mental health and demographic data
CREATE TABLE student_demographics (student_id INT,age INT,gender TEXT);
CREATE VIEW student_info AS SELECT smh.student_id, smh.mental_health_score, sd.age, sd.gender FROM student_mental_health smh INNER JOIN student_demographics sd ON smh.student_id = sd.student_id;
Find the top 3 employees with the highest salaries in the "employee" and "salary" tables
CREATE TABLE employee (id INT,name TEXT); CREATE TABLE salary (id INT,employee_id INT,salary DECIMAL);
SELECT e.name, s.salary FROM employee e JOIN salary s ON e.id = s.employee_id WHERE (SELECT COUNT(*) FROM salary s2 WHERE s2.salary > s.salary) < 3 ORDER BY s.salary DESC;
Find the top 2 countries with the highest total installed capacity for wind energy.
CREATE TABLE Country (CountryName VARCHAR(50),InstalledCapacity INT); INSERT INTO Country (CountryName,InstalledCapacity) VALUES ('Country1',1000),('Country2',1500),('Country3',1200),('Country4',800);
SELECT CountryName, SUM(InstalledCapacity) AS TotalCapacity FROM Country GROUP BY CountryName ORDER BY TotalCapacity DESC FETCH FIRST 2 ROWS ONLY;
Find the number of wells drilled in Texas in 2020
CREATE TABLE wells (id INT,state VARCHAR(255),date DATE); INSERT INTO wells (id,state,date) VALUES (1,'Texas','2020-01-01'); INSERT INTO wells (id,state,date) VALUES (2,'Texas','2020-02-01');
SELECT COUNT(*) FROM wells WHERE state = 'Texas' AND YEAR(date) = 2020;
What is the production rate for the well with the highest production rate?
CREATE TABLE wells (well_id INT,well_type VARCHAR(10),location VARCHAR(20),production_rate FLOAT); INSERT INTO wells (well_id,well_type,location,production_rate) VALUES (1,'offshore','Gulf of Mexico',1000),(2,'onshore','Texas',800),(3,'offshore','North Sea',1200);
SELECT production_rate FROM (SELECT well_id, well_type, location, production_rate, ROW_NUMBER() OVER (ORDER BY production_rate DESC) rn FROM wells) t WHERE rn = 1;
Who has the highest number of rebounds for the Raptors?
CREATE TABLE teams (team_id INT,team_name VARCHAR(50)); INSERT INTO teams (team_id,team_name) VALUES (1,'Raptors'); CREATE TABLE games (game_id INT,home_team_id INT,away_team_id INT,home_team_score INT,away_team_score INT,home_team_rebounds INT,away_team_rebounds INT); INSERT INTO games (game_id,home_team_id,away_team_id,home_team_score,away_team_score,home_team_rebounds,away_team_rebounds) VALUES (1,1,2,100,90,50,40),(2,2,1,80,85,45,55),(3,1,3,110,105,60,50),(4,4,1,70,75,30,40);
SELECT home_team_rebounds, away_team_rebounds, (home_team_rebounds + away_team_rebounds) as total_rebounds FROM games WHERE home_team_id = (SELECT team_id FROM teams WHERE team_name = 'Raptors') OR away_team_id = (SELECT team_id FROM teams WHERE team_name = 'Raptors') ORDER BY total_rebounds DESC LIMIT 1;
For the AI_ethics_guidelines table, return the organization_name, guideline_text, and review_date for the row with the minimum review_date, in ascending order.
CREATE TABLE AI_ethics_guidelines (organization_name VARCHAR(255),guideline_text TEXT,review_date DATE);
SELECT organization_name, guideline_text, review_date FROM AI_ethics_guidelines WHERE review_date = (SELECT MIN(review_date) FROM AI_ethics_guidelines);
Which users have posted ads and have more than 10 followers?
CREATE TABLE users (id INT PRIMARY KEY,name VARCHAR(50),age INT,gender VARCHAR(10),followers INT); CREATE TABLE ads (id INT PRIMARY KEY,post_id INT,clicks INT,views INT,user_id INT); INSERT INTO users (id,name,age,gender,followers) VALUES (1,'Kai',22,'Non-binary',15); INSERT INTO users (id,name,age,gender,followers) VALUES (2,'Lea',25,'Female',20); INSERT INTO ads (id,post_id,clicks,views,user_id) VALUES (1,1,10,50,1); INSERT INTO ads (id,post_id,clicks,views,user_id) VALUES (2,2,5,25,2);
SELECT users.name FROM users INNER JOIN ads ON users.id = ads.user_id WHERE users.followers > 10;
Show fabric and country of origin
CREATE TABLE sustainable_fabric (id INT PRIMARY KEY,fabric VARCHAR(25),country_of_origin VARCHAR(20)); INSERT INTO sustainable_fabric (id,fabric,country_of_origin) VALUES (1,'Organic Cotton','India'),(2,'Tencel','Austria'),(3,'Hemp','China'),(4,'Recycled Polyester','Japan');
SELECT fabric, country_of_origin FROM sustainable_fabric;
What is the total quantity of size 8 and size 9 women's shoes sold in the United Kingdom?
CREATE TABLE sales_2 (id INT,product VARCHAR(20),size INT,quantity INT,country VARCHAR(20)); INSERT INTO sales_2 VALUES (1,'shoes',8,200,'UK'),(2,'shoes',9,150,'UK'),(3,'shoes',7,100,'UK');
SELECT SUM(s.quantity) FROM sales_2 s WHERE s.product = 'shoes' AND s.size IN (8, 9) AND s.country = 'UK';
Update the 'financial_wellbeing' table to reflect a decrease in the stress level of a client in Mexico.
CREATE TABLE financial_wellbeing (client_id INT,stress_level INT,country VARCHAR(50)); INSERT INTO financial_wellbeing VALUES (8,45,'Mexico');
UPDATE financial_wellbeing SET stress_level = 40 WHERE client_id = 8 AND country = 'Mexico';
How many non-gluten-free items are available in the bakery category?
CREATE TABLE inventory (id INT,category TEXT,item TEXT,gluten_free BOOLEAN); INSERT INTO inventory (id,category,item,gluten_free) VALUES (1,'bakery','Baguette',false),(2,'bakery','Gluten-Free Brownies',true),(3,'produce','Apples',null),(4,'bakery','Croissants',false);
SELECT COUNT(*) FROM inventory WHERE category = 'bakery' AND gluten_free = false;
What is the name and address of the public library with the highest circulation in the city of Chicago?
CREATE TABLE public_libraries (name VARCHAR(255),city VARCHAR(255),address VARCHAR(255),circulation INT); INSERT INTO public_libraries (name,city,address,circulation) VALUES ('Chicago Public Library','Chicago','400 S State St',3000000); INSERT INTO public_libraries (name,city,address,circulation) VALUES ('Harold Washington Library Center','Chicago','400 S State St',5000000);
SELECT name, address FROM public_libraries WHERE city = 'Chicago' AND circulation = (SELECT MAX(circulation) FROM public_libraries WHERE city = 'Chicago');
What is the total amount of research grants awarded to the Physics department in 2021 and 2022?
CREATE TABLE departments (id INT,department_name VARCHAR(255)); CREATE TABLE research_grants (id INT,grant_name VARCHAR(255),grant_amount INT,department_id INT,grant_year INT,PRIMARY KEY (id),FOREIGN KEY (department_id) REFERENCES departments(id)); INSERT INTO departments (id,department_name) VALUES (1,'Physics'),(2,'Mathematics'),(3,'Computer Science'); INSERT INTO research_grants (id,grant_name,grant_amount,department_id,grant_year) VALUES (1,'Grant1',50000,1,2021),(2,'Grant2',75000,2,2022),(3,'Grant3',100000,3,2021),(4,'Grant4',125000,1,2022);
SELECT SUM(grant_amount) as total_grant_amount FROM research_grants WHERE department_id = (SELECT id FROM departments WHERE department_name = 'Physics') AND grant_year IN (2021, 2022);
Delete all green buildings in Japan with a silver rating.
CREATE TABLE green_buildings (building_id INT,building_name VARCHAR(255),country VARCHAR(255),rating VARCHAR(255));
DELETE FROM green_buildings WHERE country = 'Japan' AND rating = 'silver';
What is the total installed capacity of renewable energy projects in each country in the European Union?
CREATE TABLE renewable_energy_projects (project_id INT,project_name VARCHAR(255),country VARCHAR(255),installed_capacity FLOAT); CREATE TABLE eu_countries (country_code VARCHAR(255),country_name VARCHAR(255));
SELECT e.country_name, SUM(r.installed_capacity) FROM renewable_energy_projects r INNER JOIN eu_countries e ON r.country = e.country_code GROUP BY e.country_name;
How many mental health parity violations were reported by gender?
CREATE TABLE MentalHealthParityGender (ViolationID INT,Gender VARCHAR(255),ViolationDate DATE); INSERT INTO MentalHealthParityGender (ViolationID,Gender,ViolationDate) VALUES (1,'Female','2022-01-01'),(2,'Male','2022-02-01'),(3,'Female','2022-03-01');
SELECT Gender, COUNT(*) as ViolationCount FROM MentalHealthParityGender GROUP BY Gender;
Identify the number of UNESCO World Heritage sites in Asia with virtual tourism offerings.
CREATE TABLE world_heritage_sites (site_id INT,site_name TEXT,country TEXT,has_virtual_tour BOOLEAN); INSERT INTO world_heritage_sites (site_id,site_name,country,has_virtual_tour) VALUES (1,'Angkor Wat','Cambodia',true),(2,'Forbidden City','China',false),(3,'Taj Mahal','India',true);
SELECT COUNT(*) FROM world_heritage_sites WHERE has_virtual_tour = true AND country IN (SELECT name FROM countries WHERE continent = 'Asia');
Show the number of hotels that have adopted AI technology in the city of San Francisco
CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,city TEXT,has_adopted_ai BOOLEAN);
SELECT COUNT(*) FROM hotels WHERE city = 'San Francisco' AND has_adopted_ai = TRUE;