instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
What is the total cost of ingredients for each supplier, grouped by country? | CREATE TABLE Suppliers (SupplierID INT,Name VARCHAR(50),Country VARCHAR(50)); CREATE TABLE Ingredients (IngredientID INT,Name VARCHAR(50),SupplierID INT,Cost DECIMAL(5,2)); | SELECT Suppliers.Country, SUM(Ingredients.Cost) as TotalCost FROM Suppliers JOIN Ingredients ON Suppliers.SupplierID = Ingredients.SupplierID GROUP BY Suppliers.Country; |
What is the average rating of songs from female artists? | CREATE TABLE artists (id INT PRIMARY KEY,name VARCHAR(255),gender VARCHAR(10)); INSERT INTO artists (id,name,gender) VALUES (1,'Taylor Swift','Female'); INSERT INTO artists (id,name,gender) VALUES (2,'Ed Sheeran','Male'); | SELECT AVG(r.rating) as average_rating FROM ratings r INNER JOIN songs s ON r.song_id = s.id INNER JOIN artists a ON s.artist_id = a.id WHERE a.gender = 'Female'; |
What was the total number of journeys for each vessel? | CREATE TABLE journeys (vessel VARCHAR(20),speed INT,distance INT); INSERT INTO journeys (vessel,speed,distance) VALUES ('Aurelia',20,100),('Aurelia',22,120),('Belfast',25,150),('Belfast',24,140),('Belfast',26,160),('Caledonia',21,110),('Caledonia',23,130); | SELECT vessel, COUNT(*) FROM journeys GROUP BY vessel; |
What is the average age of employees working in the 'Mining Operations' department across all sites? | CREATE TABLE Employees (EmployeeID INT,Name VARCHAR(50),Department VARCHAR(50),Age INT,Site VARCHAR(50)); INSERT INTO Employees (EmployeeID,Name,Department,Age,Site) VALUES (1,'John Doe','Mining Operations',35,'Site A'); INSERT INTO Employees (EmployeeID,Name,Department,Age,Site) VALUES (2,'Jane Smith','Mining Operations',32,'Site B'); CREATE TABLE Sites (Site VARCHAR(50),Location VARCHAR(50)); INSERT INTO Sites (Site,Location) VALUES ('Site A','USA'); INSERT INTO Sites (Site,Location) VALUES ('Site B','Canada'); | SELECT AVG(Employees.Age) FROM Employees INNER JOIN Sites ON Employees.Site = Sites.Site WHERE Employees.Department = 'Mining Operations'; |
What is the total funding received by dance programs for underrepresented communities? | CREATE TABLE Funding (program TEXT,amount INT); INSERT INTO Funding (program,amount) VALUES ('Dance for Underrepresented Youth',50000),('Dance for Minorities',75000); | SELECT SUM(amount) FROM Funding WHERE program LIKE '%Underrepresented%' OR program LIKE '%Minorities%'; |
What is the total quantity of dishes with the 'vegan' tag? | CREATE TABLE dishes (id INT,name TEXT,tags TEXT); CREATE TABLE orders (id INT,dish_id INT,quantity INT); INSERT INTO dishes (id,name,tags) VALUES (1,'Quinoa Salad','vegan'),(2,'Chickpea Curry','vegan'),(3,'Beef Burger','none'),(4,'Spicy Chicken Sandwich','none'); INSERT INTO orders (id,dish_id,quantity) VALUES (1,1,10),(2,2,8),(3,3,5),(4,1,7),(5,2,9),(6,4,12); | SELECT SUM(quantity) FROM orders JOIN dishes ON dishes.id = orders.dish_id WHERE tags LIKE '%vegan%'; |
How many refugees were served by 'Community Outreach Program' in '2019'? | CREATE TABLE Refugees (refugee_id INT,refugee_name VARCHAR(255),service_start_date DATE,service_end_date DATE); CREATE TABLE Programs (program_id INT,program_name VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO Refugees (refugee_id,refugee_name,service_start_date,service_end_date) VALUES (1,'Ahmed','2019-01-01','2019-12-31'); INSERT INTO Programs (program_id,program_name,start_date,end_date) VALUES (1,'Community Outreach Program','2019-01-01','2019-12-31'); | SELECT COUNT(Refugees.refugee_id) FROM Refugees INNER JOIN Programs ON Refugees.service_start_date <= Programs.end_date AND Refugees.service_end_date >= Programs.start_date WHERE Programs.program_name = 'Community Outreach Program' AND YEAR(Programs.start_date) = 2019; |
What art historians specialized in Baroque art? | CREATE TABLE ArtHistorians (HistorianID int,Name varchar(50),Specialization varchar(50)); INSERT INTO ArtHistorians (HistorianID,Name,Specialization) VALUES (1,'Giorgio Vasari','Renaissance Art'); INSERT INTO ArtHistorians (HistorianID,Name,Specialization) VALUES (2,'Jacob Burckhardt','Italian Renaissance'); INSERT INTO ArtHistorians (HistorianID,Name,Specialization) VALUES (3,'Johann Joachim Winckelmann','Baroque Art'); | SELECT Name FROM ArtHistorians WHERE Specialization = 'Baroque Art'; |
What is the total revenue for each supplier, by week? | CREATE TABLE purchases (purchase_date DATE,supplier VARCHAR(255),revenue DECIMAL(10,2)); | SELECT supplier, DATE_TRUNC('week', purchase_date) AS purchase_week, SUM(revenue) AS total_revenue FROM purchases GROUP BY supplier, purchase_week; |
What is the total amount donated by each donor's postal code, summed up quarterly? | CREATE TABLE donors (id INT,name TEXT,postal_code TEXT,donation_amount DECIMAL(10,2),donation_date DATE); INSERT INTO donors (id,name,postal_code,donation_amount,donation_date) VALUES (1,'John Doe','90210',500.00,'2022-01-01'),(2,'Jane Smith','B7P 1A1',350.00,'2022-02-15'); | SELECT postal_code, DATE_TRUNC('quarter', donation_date) AS donation_quarter, SUM(donation_amount) AS total_donation FROM donors GROUP BY postal_code, donation_quarter; |
What is the average quantity of ethically sourced products sold per day? | CREATE TABLE sales (sale_id INT,sale_date DATE,product_id INT,quantity INT,is_ethically_sourced BOOLEAN); INSERT INTO sales (sale_id,sale_date,product_id,quantity,is_ethically_sourced) VALUES (1,'2022-01-01',1,50,true); INSERT INTO sales (sale_id,sale_date,product_id,quantity,is_ethically_sourced) VALUES (2,'2022-01-02',2,25,false); | SELECT AVG(quantity) FROM sales WHERE is_ethically_sourced = true; |
How many climate adaptation projects were initiated in Asia in 2019? | CREATE TABLE climate_adaptation_projects (project_id INT,project_name TEXT,location TEXT,start_year INT); INSERT INTO climate_adaptation_projects (project_id,project_name,location,start_year) VALUES (1,'Asian Coastal Protection','Asia',2019),(2,'Monsoon Resilience','Asia',2018),(3,'Asian Drought Response','Asia',2020); | SELECT COUNT(*) FROM climate_adaptation_projects WHERE start_year = 2019 AND location = 'Asia'; |
Create a view named "species_at_farms" with columns "farm_id", "species_id", and "species_common_name". Join "fish_farms" with "fish_species" to get the species common name. | CREATE TABLE fish_species (species_id INT PRIMARY KEY,scientific_name VARCHAR(255),common_name VARCHAR(255),conservation_status VARCHAR(50)); INSERT INTO fish_species (species_id,scientific_name,common_name,conservation_status) VALUES (1,'Oncorhynchus tshawytscha','Chinook salmon','Vulnerable'),(2,'Salmo salar','Atlantic salmon','Endangered'),(3,'Thunnus thynnus','Bluefin tuna','Critically Endangered'),(4,'Scomber japonicus','Mackerel','Least Concern'),(5,'Pagrus major','Red seabream','Vulnerable'); CREATE TABLE fish_farms (farm_id INT PRIMARY KEY,location VARCHAR(255),species_id INT,acreage FLOAT); INSERT INTO fish_farms (farm_id,location,species_id,acreage) VALUES (1,'Farm A',1,50.0),(2,'Farm B',4,75.0),(3,'Farm C',5,100.0); | CREATE VIEW species_at_farms AS SELECT ff.farm_id, ff.species_id, fs.common_name AS species_common_name FROM fish_farms ff JOIN fish_species fs ON ff.species_id = fs.species_id; |
Which virtual reality headsets are most popular by gender? | CREATE TABLE vr_headsets (id INT,headset VARCHAR(255),gender VARCHAR(10)); INSERT INTO vr_headsets (id,headset,gender) VALUES (1,'Oculus','Male'),(2,'HTC Vive','Female'),(3,'Oculus','Male'); | SELECT headset, gender, PERCENT_RANK() OVER (PARTITION BY gender ORDER BY COUNT(*) DESC) AS popularity_percentile FROM vr_headsets GROUP BY headset, gender ORDER BY gender, popularity_percentile; |
What is the maximum number of assists for each player in the players table, grouped by their position, and only for players who have more than 20 assists in total? | CREATE TABLE players_stats (player_id INT PRIMARY KEY,player_name VARCHAR(255),position VARCHAR(50),assists INT,FOREIGN KEY (player_id) REFERENCES players(player_id)); | SELECT position, MAX(assists) as max_assists FROM players_stats GROUP BY position HAVING SUM(assists) > 20; |
Display the names of unions with more than 5000 members that are not located in the United States. | CREATE TABLE union_size(id INT,union_name VARCHAR(50),members INT,location VARCHAR(14));INSERT INTO union_size(id,union_name,members,location) VALUES (1,'Union E',6000,'Canada'),(2,'Union F',4000,'United States'),(3,'Union G',8000,'Mexico'); | SELECT union_name FROM union_size WHERE members > 5000 AND location != 'United States'; |
Find the total value of agricultural machinery imported in the 'import_transactions' table for the years 2018 and 2019, separated by country? | CREATE TABLE import_transactions (id INT,date DATE,item_description VARCHAR(100),quantity INT,unit_price DECIMAL(10,2),country VARCHAR(50)); | SELECT country, SUM(quantity * unit_price) as total_value FROM import_transactions WHERE item_description LIKE '%agricultural machinery%' AND YEAR(date) IN (2018, 2019) GROUP BY country; |
How many open pedagogy courses are offered by institution? | CREATE TABLE courses (institution VARCHAR(50),course_name VARCHAR(50),course_type VARCHAR(20)); INSERT INTO courses (institution,course_name,course_type) VALUES ('University A','Introduction to Programming','Open Pedagogy'),('University B','Data Science Fundamentals','Traditional'),('University A','Machine Learning Basics','Open Pedagogy'); | SELECT institution, COUNT(*) as num_courses FROM courses WHERE course_type = 'Open Pedagogy' GROUP BY institution; |
Who won the Stanley Cup in 2012? | CREATE TABLE team_achievements (team VARCHAR(255),year INT,title VARCHAR(255)); INSERT INTO team_achievements (team,year,title) VALUES ('Los Angeles Kings',2012,'Stanley Cup'); | SELECT team FROM team_achievements WHERE title = 'Stanley Cup' AND year = 2012; |
What is the average revenue per day for each restaurant in the last month? | CREATE TABLE restaurants (id INT,name VARCHAR(50),location VARCHAR(50)); INSERT INTO restaurants VALUES (1,'Restaurant A','City A'); INSERT INTO restaurants VALUES (2,'Restaurant B','City B'); CREATE TABLE revenue (restaurant_id INT,date DATE,revenue INT); INSERT INTO revenue VALUES (1,'2021-06-01',2000); INSERT INTO revenue VALUES (1,'2021-06-02',2500); INSERT INTO revenue VALUES (2,'2021-06-01',3000); | SELECT r.name, AVG(revenue/DATEDIFF(LAST_DAY(date), date)) as avg_revenue_per_day FROM revenue JOIN restaurants r ON revenue.restaurant_id = r.id WHERE date BETWEEN DATE_SUB(LAST_DAY(CURRENT_DATE), INTERVAL 1 MONTH) AND LAST_DAY(CURRENT_DATE) GROUP BY r.name; |
Which beauty products have been sold the most in Germany in the past year? | CREATE TABLE ProductQuantity (product VARCHAR(255),country VARCHAR(255),date DATE,quantity INT); | SELECT product, SUM(quantity) AS total_quantity FROM ProductQuantity WHERE country = 'Germany' AND date >= DATEADD(year, -1, GETDATE()) GROUP BY product ORDER BY total_quantity DESC; |
Which workout type is most popular among female members? | CREATE TABLE Members (MemberID INT,Gender VARCHAR(10),WorkoutType VARCHAR(20)); INSERT INTO Members (MemberID,Gender,WorkoutType) VALUES (1,'Female','Yoga'),(2,'Male','Weightlifting'),(3,'Female','Yoga'),(4,'Male','Running'); | SELECT WorkoutType, COUNT(*) AS Count FROM Members WHERE Gender = 'Female' GROUP BY WorkoutType ORDER BY Count DESC LIMIT 1; |
Identify the top 3 donor countries by total monetary aid to South American countries affected by natural disasters? | CREATE TABLE donors (id INT,name TEXT); INSERT INTO donors (id,name) VALUES (1,'USA'),(2,'Canada'),(3,'Brazil'),(4,'Argentina'); CREATE TABLE donations (id INT,donor INT,country INT,amount FLOAT); INSERT INTO donations (id,donor,country,amount) VALUES (1,1,2,1000),(2,2,3,1500),(3,1,2,750); CREATE TABLE countries (id INT,name TEXT,region TEXT); INSERT INTO countries (id,name,region) VALUES (2,'Colombia','South America'),(3,'Peru','South America'); | SELECT d.name, SUM(donation.amount) as total_aid FROM donations donation JOIN donors d ON donation.donor = d.id JOIN countries c ON donation.country = c.id WHERE c.region = 'South America' GROUP BY d.name ORDER BY total_aid DESC LIMIT 3; |
What's the avg. donation amount for each org in '2022'? | CREATE TABLE OrganizationDonations (OrgID INT,DonationAmount INT,DonationDate DATE); | SELECT o.OrgName, AVG(od.DonationAmount) FROM OrganizationDonations od INNER JOIN Organizations o ON od.OrgID = o.OrgID WHERE YEAR(od.DonationDate) = 2022 GROUP BY o.OrgName; |
What is the average salary for each employee position, grouped by gender? | CREATE TABLE Employees (EmployeeID INT,Name VARCHAR(50),Position VARCHAR(50),HireDate DATETIME); CREATE TABLE Salaries (SalaryID INT,EmployeeID INT,Amount DECIMAL(5,2),StartDate DATETIME,EndDate DATETIME); | SELECT Employees.Position, Employees.Gender, AVG(Salaries.Amount) as AverageSalary FROM Employees JOIN Salaries ON Employees.EmployeeID = Salaries.EmployeeID GROUP BY Employees.Position, Employees.Gender; |
Identify the unique workout types for members who are younger than 30 and reside in European countries. | CREATE TABLE workout_data_europe(id INT,member_id INT,workout_type VARCHAR(20),workout_duration INT,country VARCHAR(20)); INSERT INTO workout_data_europe(id,member_id,workout_type,workout_duration,country) VALUES (1,1,'Running',60,'UK'),(2,2,'Cycling',45,'Germany'); | SELECT DISTINCT workout_type FROM workout_data_europe WHERE country IN ('UK', 'Germany', 'France', 'Italy') AND age < 30; |
Who is the community health worker with the least mental health parity consultations in Florida? | CREATE TABLE community_health_workers (id INT,name TEXT,zip TEXT,consultations INT); INSERT INTO community_health_workers (id,name,zip,consultations) VALUES (1,'Sophia Rodriguez','32001',5),(2,'Daniel Nguyen','33101',12); CREATE VIEW fl_workers AS SELECT * FROM community_health_workers WHERE zip BETWEEN '32001' AND '34999'; | SELECT name FROM fl_workers WHERE consultations = (SELECT MIN(consultations) FROM fl_workers); |
What was the total revenue for the top 3 California cultivators in Q1 2022? | CREATE TABLE cultivators (id INT,name TEXT,state TEXT); INSERT INTO cultivators (id,name,state) VALUES (1,'Cultivator A','California'); INSERT INTO cultivators (id,name,state) VALUES (2,'Cultivator B','California'); CREATE TABLE sales (cultivator_id INT,quantity INT,price DECIMAL(10,2),sale_date DATE); INSERT INTO sales (cultivator_id,quantity,price,sale_date) VALUES (1,10,50,'2022-01-01'); INSERT INTO sales (cultivator_id,quantity,price,sale_date) VALUES (1,15,60,'2022-01-05'); INSERT INTO sales (cultivator_id,quantity,price,sale_date) VALUES (2,20,40,'2022-01-03'); | SELECT c.name, SUM(s.quantity * s.price) as total_revenue FROM cultivators c JOIN sales s ON c.id = s.cultivator_id WHERE s.sale_date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY c.name ORDER BY total_revenue DESC LIMIT 3; |
What is the maximum number of vehicles in a car-sharing program in Madrid, Spain? | CREATE TABLE car_sharing (id INT,city VARCHAR(255),country VARCHAR(255),car_type VARCHAR(255),quantity INT); INSERT INTO car_sharing (id,city,country,car_type,quantity) VALUES (1,'Madrid','Spain','Electric Car',500),(2,'Madrid','Spain','Hybrid Car',300); | SELECT MAX(quantity) FROM car_sharing WHERE city = 'Madrid' AND country = 'Spain'; |
What is the total revenue per month for the Paris metro system? | CREATE TABLE paris_metro (fare DECIMAL(5,2),fare_date DATE); INSERT INTO paris_metro (fare,fare_date) VALUES (4.50,'2022-01-01'),(4.50,'2022-01-02'),(4.50,'2022-02-01'); | SELECT EXTRACT(MONTH FROM fare_date), SUM(fare) FROM paris_metro GROUP BY EXTRACT(MONTH FROM fare_date); |
What is the total number of tourists from Brazil visiting Asia in 2021? | CREATE TABLE tourism_stats (id INT PRIMARY KEY,year INT,country VARCHAR(255),destination VARCHAR(255)); INSERT INTO tourism_stats (id,year,country,destination) VALUES (1,2021,'Brazil','Japan'),(2,2021,'Brazil','Thailand'),(3,2021,'Brazil','China'); | SELECT SUM(1) FROM tourism_stats WHERE country = 'Brazil' AND destination LIKE 'Asia%' AND year = 2021; |
What is the average number of community service hours per offender in Texas? | CREATE TABLE offenders (id INT,name TEXT,state TEXT,community_service_hours INT); INSERT INTO offenders (id,name,state,community_service_hours) VALUES (1,'John Doe','Texas',50); INSERT INTO offenders (id,name,state,community_service_hours) VALUES (2,'Jane Smith','Texas',75); INSERT INTO offenders (id,name,state,community_service_hours) VALUES (3,'Mike Brown','Texas',100); | SELECT AVG(community_service_hours) FROM offenders WHERE state = 'Texas' |
Create a new table for storing information about aquatic feed manufacturers. | CREATE TABLE feed_manufacturers (id INT,name VARCHAR(255),country VARCHAR(255),establishment_date DATE); | INSERT INTO feed_manufacturers (id, name, country, establishment_date) VALUES (1, 'Skretting', 'Netherlands', '1956-04-01'), (2, 'Cargill Aqua Nutrition', 'USA', '1989-12-12'), (3, 'BioMar', 'Denmark', '1962-09-15'); |
Which virtual reality devices are used by at least 40,000 players? | CREATE TABLE VirtualReality (VRID INT PRIMARY KEY,VRName VARCHAR(50),PlayersUsing INT); INSERT INTO VirtualReality (VRID,VRName,PlayersUsing) VALUES (8,'Samsung Gear VR',45000); INSERT INTO VirtualReality (VRID,VRName,PlayersUsing) VALUES (9,'Google Daydream',30000); | SELECT VRName FROM VirtualReality WHERE PlayersUsing >= 40000; |
What is the total capacity of all vessels in the fleet? | CREATE TABLE vessels (id INT,name VARCHAR(50),type VARCHAR(50),capacity INT); INSERT INTO vessels (id,name,type,capacity) VALUES (1,'VesselA','Container',5000),(2,'VesselB','Tanker',7000); | SELECT SUM(capacity) FROM vessels; |
What is the total number of Green_Infrastructure projects in 'City O' and 'City P'? | CREATE TABLE Green_Infrastructure (id INT,project_name VARCHAR(50),location VARCHAR(50),cost FLOAT); INSERT INTO Green_Infrastructure (id,project_name,location,cost) VALUES (1,'Urban Farming','City O',2000000); INSERT INTO Green_Infrastructure (id,project_name,location,cost) VALUES (2,'Community Gardens','City P',3000000); | SELECT COUNT(*) FROM Green_Infrastructure WHERE location IN ('City O', 'City P'); |
List all the unique warehouse locations and their corresponding capacities? | CREATE TABLE warehouses (warehouse_id INT,location TEXT,capacity INT); INSERT INTO warehouses (warehouse_id,location,capacity) VALUES (1,'NYC',5000),(2,'LAX',6000),(3,'ORD',7000),(4,'DFW',4000),(5,'SFO',8000); | SELECT DISTINCT location, capacity FROM warehouses; |
What is the average price of samarium in Japan in 2017? | CREATE TABLE japan_samarium (id INT,year INT,price DECIMAL); INSERT INTO japan_samarium (id,year,price) VALUES (1,2015,250),(2,2016,260),(3,2017,270); | SELECT AVG(price) FROM japan_samarium WHERE year = 2017; |
What is the total number of marine protected areas in the Atlantic region? | CREATE TABLE marine_protected_areas (name TEXT,region TEXT,num_areas INT); INSERT INTO marine_protected_areas (name,region,num_areas) VALUES ('MPA1','Atlantic',1); INSERT INTO marine_protected_areas (name,region,num_areas) VALUES ('MPA2','Pacific',2); | SELECT SUM(num_areas) FROM marine_protected_areas WHERE region = 'Atlantic'; |
What is the average recycling rate for glass in the city of London for the years 2018 and 2019? | CREATE TABLE recycling_rates (city VARCHAR(255),year INT,material_type VARCHAR(255),recycling_rate DECIMAL(5,2)); INSERT INTO recycling_rates (city,year,material_type,recycling_rate) VALUES ('London',2018,'Glass',0.25),('London',2018,'Plastic',0.35),('London',2019,'Glass',0.30),('London',2019,'Plastic',0.40); | SELECT AVG(recycling_rate) FROM recycling_rates WHERE city = 'London' AND material_type = 'Glass' AND year IN (2018, 2019); |
List the number of mental health parity violations per state in the past year. | CREATE TABLE mental_health_parity (violation_id INT,state VARCHAR(20),date DATE); INSERT INTO mental_health_parity (violation_id,state,date) VALUES (1,'California','2021-01-01'); INSERT INTO mental_health_parity (violation_id,state,date) VALUES (2,'Texas','2021-03-05'); | SELECT state, COUNT(*) as num_violations FROM mental_health_parity WHERE date >= '2021-01-01' AND date < '2022-01-01' GROUP BY state; |
What is the total health equity metric for each country in 2021? | CREATE TABLE HealthEquityMetrics (MetricID INT,Country VARCHAR(255),MetricValue INT,ReportDate DATE); INSERT INTO HealthEquityMetrics (MetricID,Country,MetricValue,ReportDate) VALUES (1,'United States',85,'2021-01-01'); INSERT INTO HealthEquityMetrics (MetricID,Country,MetricValue,ReportDate) VALUES (2,'Brazil',78,'2021-02-15'); INSERT INTO HealthEquityMetrics (MetricID,Country,MetricValue,ReportDate) VALUES (3,'Germany',92,'2021-03-05'); INSERT INTO HealthEquityMetrics (MetricID,Country,MetricValue,ReportDate) VALUES (4,'China',64,'2021-04-10'); | SELECT Country, SUM(MetricValue) FROM HealthEquityMetrics WHERE YEAR(ReportDate) = 2021 GROUP BY Country; |
What is the average age of players who use VR technology in Japan? | CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),Country VARCHAR(20)); INSERT INTO Players (PlayerID,Age,Gender,Country) VALUES (1,25,'Male','Japan'); | SELECT AVG(Age) FROM Players WHERE Country = 'Japan' AND Gender = 'Male' AND VR_User = TRUE; |
What is the minimum number of hours of community service required for traffic violations in Illinois? | CREATE TABLE community_service_hours (id INT,state VARCHAR(50),violation_type VARCHAR(50),hours INT); INSERT INTO community_service_hours (id,state,violation_type,hours) VALUES (1,'Illinois','Speeding',10),(2,'Illinois','Running Red Light',15),(3,'Illinois','Reckless Driving',20); | SELECT MIN(hours) FROM community_service_hours WHERE state = 'Illinois' AND violation_type = 'Traffic Violation'; |
How many renewable energy projects are there in 'CityY' in the 'RenewableEnergyProjects' table? | CREATE TABLE RenewableEnergyProjects (id INT,project_name VARCHAR(50),city VARCHAR(50),project_type VARCHAR(50)); | SELECT COUNT(*) FROM RenewableEnergyProjects WHERE city = 'CityY'; |
Insert a new genre named 'Afrobeat' into the Genres table | CREATE TABLE Genres (GenreID INT PRIMARY KEY AUTO_INCREMENT,Name VARCHAR(50)); | INSERT INTO Genres (Name) VALUES ('Afrobeat'); |
What is the local economic impact (revenue) of the top 3 most visited museums in Spain? | CREATE TABLE museums(museum_id INT,museum_name TEXT,country TEXT,revenue FLOAT); INSERT INTO museums(museum_id,museum_name,country,revenue) VALUES (1,'Museo del Prado','Spain',12000000),(2,'Reina Sofia Museum','Spain',8000000),(3,'Guggenheim Bilbao','Spain',9000000),(4,'Picasso Museum','Spain',7000000); | SELECT SUM(revenue) FROM (SELECT museum_name, revenue FROM museums WHERE country = 'Spain' ORDER BY revenue DESC LIMIT 3) subquery; |
What is the geopolitical risk level for 'Country Z' in 2022 and 2023? | CREATE TABLE geopolitical_risks_3 (country varchar(255),year int,risk_level int); INSERT INTO geopolitical_risks_3 (country,year,risk_level) VALUES ('Country Z',2022,4),('Country Z',2023,5); | SELECT year, risk_level FROM geopolitical_risks_3 WHERE country = 'Country Z'; |
What is the maximum number of visitors to New Zealand from Australia in any given year? | CREATE TABLE visitor_stats (id INT PRIMARY KEY,visitor_country VARCHAR(50),year INT,num_visitors INT); INSERT INTO visitor_stats (id,visitor_country,year,num_visitors) VALUES (1,'Australia',2015,45000); INSERT INTO visitor_stats (id,visitor_country,year,num_visitors) VALUES (2,'Australia',2018,50000); | SELECT MAX(num_visitors) FROM visitor_stats WHERE visitor_country = 'Australia'; |
What is the total volume of timber harvested in the 'North American Forests' region in 2020? | CREATE TABLE NorthAmericanForests (region VARCHAR(20),year INT,timber_volume FLOAT); INSERT INTO NorthAmericanForests (region,year,timber_volume) VALUES ('North American Forests',2020,56789.12); | SELECT SUM(timber_volume) FROM NorthAmericanForests WHERE region = 'North American Forests' AND year = 2020; |
What is the total number of containers handled by each port in January 2022? | CREATE TABLE ports (port_id INT,port_name VARCHAR(50),handling_date DATE,total_containers INT); INSERT INTO ports VALUES (1,'PortA','2022-01-01',500),(2,'PortB','2022-01-01',700),(3,'PortC','2022-01-01',800),(1,'PortA','2022-01-02',600),(2,'PortB','2022-01-02',800),(3,'PortC','2022-01-02',900); | SELECT port_name, EXTRACT(MONTH FROM handling_date) AS month, EXTRACT(YEAR FROM handling_date) AS year, SUM(total_containers) FROM ports GROUP BY port_name, month, year HAVING month = 1 AND year = 2022; |
What is the average salary of full-time workers in the 'manufacturing' industry who are union members, and how many such members are there? | CREATE TABLE fulltime_workers (id INT,industry VARCHAR(20),salary FLOAT,union_member BOOLEAN); INSERT INTO fulltime_workers (id,industry,salary,union_member) VALUES (1,'manufacturing',50000.0,true),(2,'technology',70000.0,false),(3,'manufacturing',55000.0,true); | SELECT AVG(salary), COUNT(*) FROM fulltime_workers WHERE industry = 'manufacturing' AND union_member = true; |
Insert a new record with is_electric=true, is_autonomous=false, and city='Los Angeles' into the vehicles table. | CREATE TABLE vehicles (vehicle_id INT,city VARCHAR(20),is_electric BOOLEAN,is_autonomous BOOLEAN); INSERT INTO vehicles (vehicle_id,city,is_electric,is_autonomous) VALUES (1,'San Francisco',false,false),(2,'New York',true,false); | INSERT INTO vehicles (city, is_electric, is_autonomous) VALUES ('Los Angeles', true, false); |
What is the total number of posts related to technology? | CREATE TABLE posts (id INT,user_id INT,content TEXT,category VARCHAR(50)); INSERT INTO posts (id,user_id,content,category) VALUES (1,1,'I love coding','technology'),(2,1,'Data science is fascinating','technology'),(3,2,'Painting is my hobby','art'); | SELECT COUNT(*) FROM posts WHERE category = 'technology'; |
Identify the total biomass of fish in farms located in the Mediterranean sea? | CREATE TABLE fish_farms (id INT,name TEXT,country TEXT,biomass FLOAT); INSERT INTO fish_farms (id,name,country) VALUES (1,'Farm C','Italy'); INSERT INTO fish_farms (id,name,country) VALUES (2,'Farm D','Spain'); CREATE TABLE biomass_data (farm_id INT,biomass FLOAT); INSERT INTO biomass_data (farm_id,biomass) VALUES (1,500.3); INSERT INTO biomass_data (farm_id,biomass) VALUES (2,600.5); | SELECT SUM(bd.biomass) FROM fish_farms ff JOIN biomass_data bd ON ff.id = bd.farm_id WHERE ff.country LIKE '%Mediterranean%'; |
How many customers prefer size XS in our fashion retailer? | CREATE TABLE customer_sizes (id INT,customer_id INT,size VARCHAR(10)); INSERT INTO customer_sizes (id,customer_id,size) VALUES (1,10001,'XS'); | SELECT COUNT(*) FROM customer_sizes WHERE size = 'XS'; |
Find the total fare collected from each station on the Silver Line | CREATE TABLE stations (station_id INT,station_name VARCHAR(255),line VARCHAR(255));CREATE TABLE trips (trip_id INT,station_id INT,fare FLOAT); INSERT INTO stations (station_id,station_name,line) VALUES (1,'Boston','Silver Line'),(2,'Chelsea','Silver Line'); INSERT INTO trips (trip_id,station_id,fare) VALUES (1,1,2.5),(2,1,3.0),(3,2,1.5); | SELECT s.station_name, SUM(t.fare) as total_fare FROM trips t JOIN stations s ON t.station_id = s.station_id WHERE s.line = 'Silver Line' GROUP BY s.station_name; |
List all freight forwarding transactions for 'CustomerA' with their corresponding statuses and dates. | CREATE TABLE Customers (CustomerID VARCHAR(20),CustomerName VARCHAR(20)); INSERT INTO Customers (CustomerID,CustomerName) VALUES ('A','CustomerA'),('B','CustomerB'); CREATE TABLE FreightForwardingTransactions (TransactionID INT,CustomerID VARCHAR(20),TransactionStatus VARCHAR(20),TransactionDate DATE); INSERT INTO FreightForwardingTransactions (TransactionID,CustomerID,TransactionStatus,TransactionDate) VALUES (1,'A','Created','2022-01-01'),(2,'A','InProgress','2022-01-02'); | SELECT FreightForwardingTransactions.TransactionID, FreightForwardingTransactions.TransactionStatus, FreightForwardingTransactions.TransactionDate FROM Customers JOIN FreightForwardingTransactions ON Customers.CustomerID = FreightForwardingTransactions.CustomerID WHERE Customers.CustomerName = 'CustomerA'; |
What is the average number of refugees supported per refugee support project in the Middle East? | CREATE TABLE refugee_support_projects (id INT,name VARCHAR(100),region VARCHAR(50),num_refugees INT); INSERT INTO refugee_support_projects (id,name,region,num_refugees) VALUES (1,'Project A','Middle East',50),(2,'Project B','Middle East',100),(3,'Project C','Middle East',75),(4,'Project D','Asia',25); | SELECT AVG(num_refugees) FROM refugee_support_projects WHERE region = 'Middle East'; |
What is the maximum temperature (°C) recorded in wheat farms in Pakistan in the past week? | CREATE TABLE temperature_data (temperature DECIMAL(3,2),reading_date DATE,location TEXT); INSERT INTO temperature_data (temperature,reading_date,location) VALUES (32.5,'2021-07-01','Pakistan'),(33.1,'2021-07-02','Pakistan'),(30.9,'2021-04-01','Pakistan'); | SELECT MAX(temperature) FROM temperature_data WHERE location = 'Pakistan' AND reading_date > DATE_SUB(CURDATE(), INTERVAL 1 WEEK) AND location LIKE '%wheat%'; |
What is the total number of safety incidents recorded in the past quarter for the chemical manufacturing plant in New Delhi? | CREATE TABLE safety_incidents (id INT,plant_location VARCHAR(50),incident_date DATE,incident_type VARCHAR(50)); | SELECT COUNT(*) FROM safety_incidents WHERE plant_location = 'New Delhi' AND incident_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH) GROUP BY incident_type HAVING COUNT(*) > 10; |
What is the average rating of hotels in 'New York'? | CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,city TEXT,rating FLOAT); INSERT INTO hotels (hotel_id,hotel_name,city,rating) VALUES (1,'The Plaza','New York',4.5),(2,'The Bowery Hotel','New York',4.2); | SELECT AVG(rating) FROM hotels WHERE city = 'New York'; |
What is the correlation between temperature change and greenhouse gas emissions in North America from 2010 to 2020? | CREATE TABLE temperature_data (region VARCHAR(255),year INT,avg_temp FLOAT);CREATE TABLE greenhouse_gas_emissions (region VARCHAR(255),year INT,emissions FLOAT); | SELECT CORR(t.avg_temp, g.emissions) AS correlation FROM temperature_data t INNER JOIN greenhouse_gas_emissions g ON t.region = g.region AND t.year = g.year WHERE t.region = 'North America' AND t.year BETWEEN 2010 AND 2020; |
List the names of performing arts events with more than 50 attendees, excluding workshops. | CREATE TABLE events (id INT,name VARCHAR(50),type VARCHAR(20)); INSERT INTO events (id,name,type) VALUES (1,'Play 1','Theater'),(2,'Dance Show','Dance'),(3,'Workshop 1','Workshop'),(4,'Play 2','Theater'); CREATE TABLE attendance (event_id INT,attendee_count INT); INSERT INTO attendance (event_id,attendee_count) VALUES (1,60),(2,45),(3,20),(4,55); | SELECT e.name FROM events e JOIN attendance a ON e.id = a.event_id WHERE e.type NOT IN ('Workshop') AND a.attendee_count > 50; |
What is the percentage of accessible technology scholarships for underrepresented communities in Europe? | CREATE TABLE tech_scholarships (scholarship_location VARCHAR(255),is_accessible BOOLEAN,community VARCHAR(255)); INSERT INTO tech_scholarships (scholarship_location,is_accessible,community) VALUES ('Germany',true,'Minority Women'),('France',false,'Persons with Disabilities'),('UK',true,'Refugees'); | SELECT scholarship_location, COUNT(*) * 100.0 / SUM(COUNT(*)) OVER () as percentage_accessible FROM tech_scholarships WHERE scholarship_location LIKE 'Europe%' AND is_accessible = true AND community IN ('Minority Women', 'Persons with Disabilities', 'Refugees') GROUP BY scholarship_location; |
What is the sum of construction costs for highways in California? | CREATE TABLE Highways (id INT,name TEXT,location TEXT,state TEXT,cost FLOAT); INSERT INTO Highways (id,name,location,state,cost) VALUES (1,'Highway A','Location A','California',10000000),(2,'Highway B','Location B','New York',12000000); | SELECT SUM(cost) FROM Highways WHERE state = 'California'; |
Get the total watch time of educational videos for users from Africa. | CREATE TABLE user_sessions (user_id INT,video_id INT,watch_time INT,video_type VARCHAR(50)); CREATE VIEW educational_videos AS SELECT DISTINCT video_id FROM videos WHERE video_type = 'educational'; CREATE VIEW users_from_africa AS SELECT DISTINCT user_id FROM users WHERE country IN ('Nigeria','South Africa','Egypt','Algeria','Morocco'); | SELECT SUM(watch_time) FROM user_sessions JOIN educational_videos ON user_sessions.video_id = educational_videos.video_id JOIN users_from_africa ON user_sessions.user_id = users_from_africa.user_id; |
What is the maximum pro-bono work hours for attorneys who identify as male? | CREATE TABLE Attorneys (AttorneyID INT,Gender VARCHAR(10),ProBonoHours INT); INSERT INTO Attorneys (AttorneyID,Gender,ProBonoHours) VALUES (1,'Male',100),(2,'Female',120),(3,'Non-binary',80); | SELECT MAX(ProBonoHours) FROM Attorneys WHERE Gender = 'Male'; |
Identify the number of projects with a focus on diversity and inclusion that were funded in the last year. | CREATE TABLE projects_funding (id INT,name TEXT,focus TEXT,funding_date DATE); INSERT INTO projects_funding (id,name,focus,funding_date) VALUES (1,'Diverse Leadership Program','Diversity and Inclusion','2022-03-15'),(2,'Accessibility Initiative','Diversity and Inclusion','2021-12-28'); | SELECT COUNT(*) FROM projects_funding WHERE focus = 'Diversity and Inclusion' AND funding_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR); |
Who are the suppliers for Product Z and their ethical ratings? | CREATE TABLE suppliers (id INT,name VARCHAR(50),location VARCHAR(50),ethical_rating FLOAT); CREATE TABLE products (id INT,name VARCHAR(50),supplier_id INT,quantity_sold INT); INSERT INTO suppliers (id,name,location,ethical_rating) VALUES (1,'Supplier A','USA',4.2); INSERT INTO suppliers (id,name,location,ethical_rating) VALUES (2,'Supplier B','Mexico',3.8); INSERT INTO products (id,name,supplier_id,quantity_sold) VALUES (1,'Product X',1,500); INSERT INTO products (id,name,supplier_id,quantity_sold) VALUES (2,'Product Y',2,350); INSERT INTO products (id,name,supplier_id,quantity_sold) VALUES (3,'Product Z',1,700); | SELECT s.name, s.ethical_rating FROM suppliers s JOIN products p ON s.id = p.supplier_id WHERE p.name = 'Product Z'; |
What is the most popular sustainable material used in clothing? | CREATE TABLE clothing_materials (material_id INTEGER,material TEXT,sustainable BOOLEAN,popularity INTEGER); INSERT INTO clothing_materials (material_id,material,sustainable,popularity) VALUES (1,'cotton',TRUE,250),(2,'silk',FALSE,150),(3,'polyester',TRUE,200),(4,'wool',FALSE,100); | SELECT material, MAX(popularity) AS max_popularity FROM clothing_materials WHERE sustainable = TRUE GROUP BY material ORDER BY max_popularity DESC LIMIT 1; |
What is the total sales of all menu items that contain 'cheese' in their name? | CREATE TABLE sales (id INT,menu_item_id INT,sales DECIMAL(5,2)); INSERT INTO sales (id,menu_item_id,sales) VALUES (1,1,100.00),(2,1,200.00),(3,2,50.00),(4,3,150.00),(5,3,250.00); CREATE TABLE menus (id INT,menu_item_name TEXT); INSERT INTO menus (id,menu_item_name) VALUES (1,'Cheese Burger'),(2,'Fries'),(3,'Cheese Salad'); | SELECT SUM(sales) FROM sales JOIN menus ON sales.menu_item_id = menus.id WHERE menu_item_name LIKE '%cheese%'; |
What is the average water demand and recycled water usage by sector? | CREATE TABLE if not exists irrigation_data (id INT PRIMARY KEY,farm_id INT,water_usage FLOAT,usage_date DATE); INSERT INTO irrigation_data (id,farm_id,water_usage,usage_date) VALUES (1,1,50.3,'2022-09-01'),(2,2,45.8,'2022-09-01'),(3,3,40.2,'2022-09-01'); CREATE TABLE if not exists recycled_water_usage (id INT PRIMARY KEY,sector VARCHAR(50),water_volume FLOAT); | SELECT rwu.sector, AVG(id.water_usage) as avg_water_demand, rwu.water_volume as recycled_water_volume FROM irrigation_data id JOIN recycled_water_usage rwu ON 1=1 GROUP BY rwu.sector; |
Which city generated the most waste in the year 2019? | CREATE TABLE waste_generation (city VARCHAR(20),year INT,total_waste_gen FLOAT); INSERT INTO waste_generation (city,year,total_waste_gen) VALUES ('Seattle',2019,240000),('Portland',2019,260000),('San Francisco',2019,270000); | SELECT city, MAX(total_waste_gen) FROM waste_generation GROUP BY year HAVING year = 2019; |
What was the average number of containers carried by vessels that arrived at the port of Oakland in July 2021? | CREATE TABLE ports (id INT,name VARCHAR(50)); INSERT INTO ports (id,name) VALUES (1,'Oakland'),(2,'Los Angeles'); CREATE TABLE vessels (id INT,name VARCHAR(50),port_id INT,arrival_date DATE,num_containers INT); INSERT INTO vessels (id,name,port_id,arrival_date,num_containers) VALUES (1,'Vessel1',1,'2021-07-01',1000),(2,'Vessel2',2,'2021-07-03',1200),(3,'Vessel3',1,'2021-07-05',1500); | SELECT AVG(num_containers) as avg_containers FROM vessels WHERE port_id = 1 AND MONTH(arrival_date) = 7; |
Insert a new record into the food_safety table with the following data: restaurant_id = 102, inspection_date = '2022-09-15', score = 88 | CREATE TABLE food_safety (id INT PRIMARY KEY,restaurant_id INT,inspection_date DATE,score INT); | INSERT INTO food_safety (restaurant_id, inspection_date, score) VALUES (102, '2022-09-15', 88); |
What is the average number of attendees for poetry events in New York in 2021? | CREATE TABLE PoetryEvents (eventID INT,attendeeCount INT,eventLocation VARCHAR(50),eventDate DATE); INSERT INTO PoetryEvents (eventID,attendeeCount,eventLocation,eventDate) VALUES (1,30,'New York','2021-02-03'),(2,45,'Chicago','2021-04-10'),(3,25,'New York','2021-07-15'); | SELECT AVG(attendeeCount) FROM PoetryEvents WHERE eventLocation = 'New York' AND YEAR(eventDate) = 2021; |
Find the average funding amount for companies founded by women in the technology sector | CREATE TABLE companies (id INT,name VARCHAR(50),industry VARCHAR(50),founder_gender VARCHAR(10)); INSERT INTO companies VALUES (1,'Acme Corp','Technology','Female'); INSERT INTO companies VALUES (2,'Beta Inc','Retail','Male'); | SELECT AVG(funding_amount) FROM funds INNER JOIN companies ON funds.company_id = companies.id WHERE companies.founder_gender = 'Female' AND companies.industry = 'Technology'; |
What is the distribution of security incidents by type in the past month? | CREATE TABLE incident_types (id INT,incident_type VARCHAR(50),incidents INT,timestamp TIMESTAMP); INSERT INTO incident_types (id,incident_type,incidents,timestamp) VALUES (1,'Phishing',50,'2022-01-01 10:00:00'),(2,'Malware',75,'2022-01-02 12:00:00'); | SELECT incident_type, SUM(incidents) as total_incidents FROM incident_types WHERE timestamp >= '2022-02-01' GROUP BY incident_type; |
Delete all records from the esports_teams table where the organization is not 'Genesis' or 'Titan' | CREATE TABLE esports_teams (id INT PRIMARY KEY,name TEXT,organization TEXT); | DELETE FROM esports_teams WHERE organization NOT IN ('Genesis', 'Titan'); |
What is the change in water consumption between consecutive months for each district in Cape Town? | CREATE TABLE cape_town_water_consumption (id INT,date DATE,district VARCHAR(20),water_consumption FLOAT); INSERT INTO cape_town_water_consumption (id,date,district,water_consumption) VALUES (1,'2021-01-01','Atlantis',1200.0),(2,'2021-01-02','Bishop Lavis',1500.0); | SELECT district, LAG(water_consumption) OVER (PARTITION BY district ORDER BY date) - water_consumption FROM cape_town_water_consumption; |
What is the total amount donated by each donor in the last 6 months? | CREATE TABLE Donors (DonorID INT,Name TEXT); CREATE TABLE Donations (DonationID INT,DonorID INT,DonationDate DATE,DonationAmount DECIMAL); | SELECT D.Name as DonorName, SUM(DonationAmount) as TotalDonationLast6Months FROM Donors D INNER JOIN Donations Don ON D.DonorID = Don.DonorID WHERE DonationDate >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH) GROUP BY D.DonorID, D.Name; |
What is the average duration of yoga workouts for members with a heart rate monitor? | CREATE TABLE Members (MemberID INT,HasHeartRateMonitor BOOLEAN); CREATE TABLE Workouts (WorkoutID INT,MemberID INT,WorkoutDate DATE,Duration INT,WorkoutType VARCHAR(10)); | SELECT AVG(Duration) FROM (SELECT MemberID, Duration FROM Workouts INNER JOIN Members ON Workouts.MemberID = Members.MemberID WHERE Members.HasHeartRateMonitor = TRUE AND WorkoutType = 'yoga') AS Subquery; |
How many individuals have been impacted by access to justice initiatives in Asia since 2018? | CREATE TABLE initiatives (initiative_id INT,year INT,individuals_impacted INT); INSERT INTO initiatives (initiative_id,year,individuals_impacted) VALUES (1,2018,4000),(2,2019,5000); CREATE TABLE locations (initiative_id INT,region VARCHAR(20)); INSERT INTO locations (initiative_id,region) VALUES (1,'Asia'),(2,'Africa'); | SELECT SUM(initiatives.individuals_impacted) FROM initiatives INNER JOIN locations ON initiatives.initiative_id = locations.initiative_id WHERE locations.region = 'Asia' AND initiatives.year >= 2018; |
Show the names of graduate students who have received research grants. | CREATE TABLE Students (StudentID int,Name varchar(50)); INSERT INTO Students (StudentID,Name) VALUES (1,'John Smith'); INSERT INTO Students (StudentID,Name) VALUES (2,'Jane Doe'); CREATE TABLE Grants (GrantID int,StudentID int); INSERT INTO Grants (GrantID,StudentID) VALUES (1,1); INSERT INTO Grants (GrantID,StudentID) VALUES (2,2); | SELECT Students.Name FROM Students INNER JOIN Grants ON Students.StudentID = Grants.StudentID; |
Create a table for storing public transportation usage data | CREATE TABLE public_transportation (id INT PRIMARY KEY,location VARCHAR(100),type VARCHAR(100),passengers INT,year INT); | CREATE TABLE public_transportation (id INT PRIMARY KEY, location VARCHAR(100), type VARCHAR(100), passengers INT, year INT); |
Insert a new investment with organization ID 4 in the renewable energy sector with an ESG rating of 9.0 | CREATE TABLE organizations (id INT,sector VARCHAR(20),ESG_rating FLOAT); INSERT INTO organizations (id,sector,ESG_rating) VALUES (1,'Healthcare',7.5),(2,'Technology',8.2),(3,'Healthcare',8.0); CREATE TABLE investments (id INT,organization_id INT); INSERT INTO investments (id,organization_id) VALUES (1,1),(2,2),(3,3); | INSERT INTO investments (id, organization_id) VALUES (4, (SELECT id FROM organizations WHERE sector = 'Renewable Energy' AND ESG_rating = 9.0)); -- Note: There are currently no organizations in the 'Renewable Energy' sector with an ESG rating of 9.0. This command will fail if such an organization doesn't exist. |
What is the total number of intelligence operations conducted in 'Asia' in the 'Operations' table? | CREATE TABLE Operations (id INT,name VARCHAR(50),year INT,continent VARCHAR(50)); INSERT INTO Operations (id,name,year,continent) VALUES (1,'Operation Red',2005,'Asia'); INSERT INTO Operations (id,name,year,continent) VALUES (2,'Operation Blue',2008,'Europe'); | SELECT COUNT(*) FROM Operations WHERE continent = 'Asia'; |
Who are the top 5 content creators in Asia in terms of video views? | CREATE TABLE content_creators (id INT,name VARCHAR(50),country VARCHAR(50),views BIGINT); INSERT INTO content_creators (id,name,country,views) VALUES (1,'Creator1','China',10000000),(2,'Creator2','Japan',15000000),(3,'Creator3','South Korea',20000000),(4,'Creator4','India',8000000),(5,'Creator5','Indonesia',12000000); | SELECT name, country, views FROM content_creators WHERE country = 'Asia' ORDER BY views DESC LIMIT 5; |
What is the total number of articles on 'freedom of speech' and 'interviews', and the average age of readers who prefer news on those categories? | CREATE TABLE articles (id INT,title VARCHAR(50),category VARCHAR(20)); INSERT INTO articles (id,title,category) VALUES (1,'Article One','freedom of speech'),(2,'Article Two','interviews'); CREATE TABLE readers (id INT,name VARCHAR(20),age INT,favorite_category VARCHAR(20)); INSERT INTO readers (id,name,age,favorite_category) VALUES (1,'Sanaa Ali',27,'freedom of speech'),(2,'Pedro Gutierrez',32,'interviews'); | SELECT SUM(total_articles) AS total_articles, AVG(average_age) AS average_age FROM (SELECT COUNT(*) AS total_articles FROM articles WHERE category IN ('freedom of speech', 'interviews') GROUP BY category) AS subquery1 CROSS JOIN (SELECT AVG(age) AS average_age FROM readers WHERE favorite_category IN ('freedom of speech', 'interviews') GROUP BY favorite_category) AS subquery2; |
How many mining accidents were reported in the African continent in the last 3 years? | CREATE TABLE mining_accidents (id INT,location TEXT,timestamp TIMESTAMP); INSERT INTO mining_accidents (id,location,timestamp) VALUES (1,'Witwatersrand Gold Fields','2019-01-01 12:00:00'); | SELECT COUNT(*) FROM mining_accidents WHERE EXTRACT(YEAR FROM timestamp) >= EXTRACT(YEAR FROM CURRENT_DATE) - 3 AND location LIKE 'Africa%'; |
What is the average production cost of garments in the 'ethical_materials' table? | CREATE TABLE ethical_materials (id INT,garment_type VARCHAR(255),production_cost DECIMAL(10,2)); | SELECT AVG(production_cost) FROM ethical_materials; |
What is the average precipitation in India's Western Ghats in September? | CREATE TABLE weather (country VARCHAR(255),region VARCHAR(255),month INT,precipitation FLOAT); INSERT INTO weather (country,region,month,precipitation) VALUES ('India','Western Ghats',9,350.5),('India','Western Ghats',9,360.2),('India','Western Ghats',9,340.8),('India','Western Ghats',9,355.9); | SELECT AVG(precipitation) FROM weather WHERE country = 'India' AND region = 'Western Ghats' AND month = 9; |
What is the average revenue per night for sustainable accommodations? | CREATE TABLE accommodations (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255),nightly_rate FLOAT,num_nights INT); | SELECT AVG(nightly_rate * num_nights) FROM accommodations WHERE type = 'Sustainable'; |
Calculate the total production volume for each country, for the 'Gas' production type. | CREATE TABLE production (production_id INT,well_id INT,production_date DATE,production_type TEXT,production_volume INT); INSERT INTO production (production_id,well_id,production_date,production_type,production_volume) VALUES (1,1,'2018-01-01','Oil',100),(2,1,'2018-01-02','Gas',50),(3,2,'2019-05-03','Oil',150); CREATE TABLE wells (well_id INT,well_name TEXT,drill_date DATE,country TEXT); INSERT INTO wells (well_id,well_name,drill_date,country) VALUES (1,'Well A','2018-01-01','USA'),(2,'Well B','2019-05-03','Canada'); | SELECT wells.country, SUM(production.production_volume) as total_gas_production FROM production INNER JOIN wells ON production.well_id = wells.well_id WHERE production.production_type = 'Gas' GROUP BY wells.country; |
How many accommodations were made for students with visual impairments in the past year across all universities? | CREATE TABLE accommodations (id INT PRIMARY KEY,student_id INT,accommodation_type VARCHAR(255),university VARCHAR(255),date DATE); CREATE VIEW student_visual_impairment AS SELECT student_id FROM students WHERE disability = 'visual impairment'; | SELECT COUNT(*) FROM accommodations JOIN student_visual_impairment ON accommodations.student_id = student_visual_impairment.student_id WHERE date >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR); |
How many endangered species are there in 'africa'? | CREATE TABLE species (name VARCHAR(255),region VARCHAR(255),endangered BOOLEAN); INSERT INTO species (name,region,endangered) VALUES ('lion','africa',TRUE); INSERT INTO species (name,region,endangered) VALUES ('giraffe','africa',FALSE); | SELECT COUNT(*) FROM species WHERE region = 'africa' AND endangered = TRUE; |
List the number of unique autonomous vehicle models and their average price in the vehicle_sales table. | CREATE TABLE autonomous_vehicles (id INT,vehicle_model VARCHAR(50),price FLOAT); INSERT INTO autonomous_vehicles (id,vehicle_model,price) VALUES (1,'Wayve Pod',150000),(2,'Nuro R2',120000),(3,'Zoox',180000),(4,'Aptiv',160000),(5,'Baidu Apollo',140000); | SELECT COUNT(DISTINCT vehicle_model) AS unique_models, AVG(price) AS average_price FROM autonomous_vehicles; |
How many collective bargaining agreements were signed in the year 2020? | CREATE TABLE cb_agreements (id INT,union_id INT,employer_id INT,sign_date DATE); INSERT INTO cb_agreements (id,union_id,employer_id,sign_date) VALUES (1,1,1,'2019-12-31'); INSERT INTO cb_agreements (id,union_id,employer_id,sign_date) VALUES (2,2,2,'2020-03-15'); INSERT INTO cb_agreements (id,union_id,employer_id,sign_date) VALUES (3,3,3,'2021-01-01'); | SELECT COUNT(*) FROM cb_agreements WHERE EXTRACT(YEAR FROM sign_date) = 2020; |
Count the number of incidents for each vessel type | CREATE TABLE VesselTypes (id INT,vessel_type VARCHAR(50)); CREATE TABLE IncidentLog (id INT,vessel_id INT,incident_type VARCHAR(50),time TIMESTAMP); | SELECT vt.vessel_type, COUNT(il.id) FROM VesselTypes vt JOIN IncidentLog il ON vt.id = il.vessel_id GROUP BY vt.vessel_type; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.