instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the maximum heart rate for each member, sorted by membership type? | CREATE TABLE member_demographics (member_id INT,age INT,gender VARCHAR(10)); INSERT INTO member_demographics (member_id,age,gender) VALUES (1,27,'Female'),(2,32,'Male'),(3,26,'Female'); CREATE TABLE wearable_data (member_id INT,heart_rate INT,timestamp TIMESTAMP,membership_type VARCHAR(20)); INSERT INTO wearable_data (member_id,heart_rate,timestamp,membership_type) VALUES (1,120,'2022-01-01 10:00:00','Platinum'),(1,150,'2022-01-01 11:00:00','Platinum'),(2,130,'2022-01-01 10:00:00','Gold'),(2,140,'2022-01-01 11:00:00','Gold'),(3,105,'2022-01-01 10:00:00','Platinum'),(3,110,'2022-01-01 11:00:00','Platinum'); | SELECT member_id, membership_type, MAX(heart_rate) as max_heart_rate FROM wearable_data w JOIN member_demographics m ON w.member_id = m.member_id GROUP BY member_id, membership_type ORDER BY membership_type; |
Count the number of fair trade certified manufacturers in Asia. | CREATE TABLE manufacturers (id INT,certification VARCHAR(20),region VARCHAR(20)); INSERT INTO manufacturers (id,certification,region) VALUES (1,'Fair Trade','Asia'),(2,'GOTS','Europe'),(3,'Fair Trade','Asia'); | SELECT COUNT(*) FROM manufacturers WHERE certification = 'Fair Trade' AND region = 'Asia'; |
How many players have reached 'Ultra' status in 'Cosmic Racers' per region? | CREATE TABLE Regions (RegionID INT,Region VARCHAR(255)); INSERT INTO Regions (RegionID,Region) VALUES (1,'North America'); INSERT INTO Regions (RegionID,Region) VALUES (2,'South America'); INSERT INTO Players (PlayerID,PlayerStatus,GameName,RegionID) VALUES (1,'Ultra','Cosmic Racers',1); INSERT INTO Players (PlayerID,PlayerStatus,GameName,RegionID) VALUES (2,'Beginner','Cosmic Racers',2); | SELECT Region, COUNT(*) as PlayerCount FROM Players JOIN Regions ON Players.RegionID = Regions.RegionID WHERE PlayerStatus = 'Ultra' AND GameName = 'Cosmic Racers' GROUP BY Region; |
How many autonomous buses are there in District 5 of CityB? | CREATE TABLE public_transport (vehicle_id INT,vehicle_type VARCHAR(20),district INT,city VARCHAR(20)); INSERT INTO public_transport (vehicle_id,vehicle_type,district,city) VALUES (101,'autonomous bus',5,'CityB'),(102,'manual bus',5,'CityB'),(103,'tram',4,'CityB'); | SELECT COUNT(*) FROM public_transport WHERE vehicle_type = 'autonomous bus' AND district = 5; |
What is the maximum temperature recorded for each location in the environmental_sensors table? | CREATE TABLE environmental_sensors (id INT,location VARCHAR(50),temperature DECIMAL(5,2)); INSERT INTO environmental_sensors (id,location,temperature) VALUES (1,'Chicago',32.5),(2,'Detroit',25.3),(3,'Cleveland',30.1),(4,'Buffalo',28.6),(5,'Atlanta',35.2); | SELECT location, MAX(temperature) as max_temperature FROM environmental_sensors GROUP BY location; |
Find the top 3 causes that received the most funding from foundations in Canada in 2020? | CREATE TABLE Causes (id INT,cause_name TEXT,total_funding DECIMAL(10,2),cause_category TEXT); CREATE TABLE Foundation_Donations (foundation_id INT,cause_id INT,donation_amount DECIMAL(10,2),donation_date DATE); CREATE TABLE Foundations (id INT,foundation_name TEXT,country TEXT); | SELECT c.cause_name, SUM(fd.donation_amount) AS total_funding FROM Causes c JOIN Foundation_Donations fd ON c.id = fd.cause_id JOIN Foundations f ON fd.foundation_id = f.id WHERE f.country = 'Canada' GROUP BY c.cause_name ORDER BY total_funding DESC LIMIT 3; |
Which public service had the highest citizen satisfaction score in H1 2022 and H2 2022? | CREATE TABLE HalfYearSatisfaction2 (Half TEXT,Year INTEGER,Service TEXT,Score INTEGER); INSERT INTO HalfYearSatisfaction2 (Half,Year,Service,Score) VALUES ('H1 2022',2022,'Education',90),('H1 2022',2022,'Healthcare',85),('H1 2022',2022,'Transportation',92),('H2 2022',2022,'Education',93),('H2 2022',2022,'Healthcare',88),('H2 2022',2022,'Transportation',95); | SELECT Service, MAX(Score) FROM HalfYearSatisfaction2 WHERE Year = 2022 GROUP BY Service; |
What was the total funding amount for startups founded by individuals with disabilities in Germany? | CREATE TABLE company (id INT,name TEXT,country TEXT,founding_date DATE,founder_disability TEXT); INSERT INTO company (id,name,country,founding_date,founder_disability) VALUES (1,'Theta Corp','Germany','2017-01-01','Yes'); INSERT INTO company (id,name,country,founding_date,founder_disability) VALUES (2,'Iota Inc','Germany','2016-01-01','No'); | SELECT SUM(funding_amount) FROM funding INNER JOIN company ON funding.company_id = company.id WHERE company.country = 'Germany' AND company.founder_disability = 'Yes'; |
What is the change in water levels for each reservoir over the past year, and which have experienced the greatest increase and decrease? | CREATE TABLE reservoirs (id INT,reservoir_name VARCHAR(50),country VARCHAR(50),water_level_meters INT,last_measurement_date DATE); INSERT INTO reservoirs (id,reservoir_name,country,water_level_meters,last_measurement_date) VALUES (1,'Lake Superior','Canada',405.5,'2021-12-01'); INSERT INTO reservoirs (id,reservoir_name,country,water_level_meters,last_measurement_date) VALUES (2,'Lake Victoria','Tanzania',11.2,'2021-12-15'); | SELECT id, reservoir_name, country, DATEDIFF(day, last_measurement_date, CURRENT_DATE) as days_since_last_measurement, water_level_meters, (water_level_meters - LAG(water_level_meters) OVER (PARTITION BY reservoir_name ORDER BY last_measurement_date)) as change FROM reservoirs WHERE DATEDIFF(day, last_measurement_date, CURRENT_DATE) <= 365; |
What is the total quantity of items starting with 'A' in warehouse 'W03'? | CREATE TABLE warehouses (id VARCHAR(5),name VARCHAR(10)); INSERT INTO warehouses (id,name) VALUES ('W01','Warehouse One'),('W02','Warehouse Two'),('W03','Warehouse Three'),('W04','Warehouse Four'); CREATE TABLE inventory (item_code VARCHAR(5),warehouse_id VARCHAR(5),quantity INT); INSERT INTO inventory (item_code,warehouse_id,quantity) VALUES ('A101','W01',300),('A202','W02',200),('A303','W03',450),('B404','W04',500); | SELECT SUM(quantity) FROM inventory WHERE item_code LIKE 'A%' AND warehouse_id = 'W03'; |
What is the average review score for hotel_id 123? | CREATE TABLE hotel_reviews (hotel_id INT,review_date DATE,review_score INT); | SELECT AVG(review_score) FROM hotel_reviews WHERE hotel_id = 123; |
List the names and publication years of graduate students who have published in both ACM Transactions on Graphics and IEEE Transactions on Visualization and Computer Graphics. | CREATE TABLE graduate_students (student_id INT,name VARCHAR(50),publication VARCHAR(50),publication_year INT); INSERT INTO graduate_students VALUES (1,'Fatima Patel','ACM Transactions on Graphics',2020),(2,'Gabriel Brown','IEEE Transactions on Visualization and Computer Graphics',2019),(3,'Hana Davis','ACM Transactions on Graphics',2021),(4,'Iman Green','IEEE Transactions on Visualization and Computer Graphics',2020); | SELECT DISTINCT gs1.name, gs1.publication_year FROM graduate_students gs1 JOIN graduate_students gs2 ON gs1.name = gs2.name WHERE gs1.publication = 'ACM Transactions on Graphics' AND gs2.publication = 'IEEE Transactions on Visualization and Computer Graphics'; |
What are the top 5 most mentioned brands in influencer posts, in the last month? | CREATE TABLE influencers (influencer_id INT,influencer_name TEXT);CREATE TABLE posts (post_id INT,post_text TEXT,influencer_id INT,post_date DATE);CREATE TABLE brands (brand_id INT,brand_name TEXT);CREATE TABLE mentions (mention_id INT,post_id INT,brand_id INT); | SELECT b.brand_name, COUNT(m.mention_id) as mention_count FROM mentions m JOIN posts p ON m.post_id = p.post_id JOIN brands b ON m.brand_id = b.brand_id JOIN influencers i ON p.influencer_id = i.influencer_id WHERE p.post_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY b.brand_name ORDER BY mention_count DESC LIMIT 5; |
What is the total billing amount for cases in Texas handled by attorneys who have passed the bar exam in that state? | CREATE TABLE attorneys (attorney_id INT,name TEXT,state TEXT,passed_bar_exam_tx BOOLEAN); INSERT INTO attorneys (attorney_id,name,state,passed_bar_exam_tx) VALUES (1,'Jane Doe','Texas',TRUE),(2,'John Smith','California',FALSE),(3,'Sara Connor','Texas',TRUE),(4,'Tom Williams','New York',FALSE); CREATE TABLE cases (case_id INT,attorney_id INT,billing_amount INT,state TEXT); INSERT INTO cases (case_id,attorney_id,billing_amount,state) VALUES (1,1,10000,'Texas'),(2,2,8000,'California'),(3,3,15000,'Texas'),(4,4,6000,'New York'); | SELECT SUM(cases.billing_amount) FROM cases INNER JOIN attorneys ON cases.attorney_id = attorneys.attorney_id WHERE attorneys.passed_bar_exam_tx = TRUE AND cases.state = attorneys.state; |
What is the total number of digital assets launched by company 'ABC'? | CREATE TABLE digital_assets (id INT,name TEXT,company TEXT); INSERT INTO digital_assets (id,name,company) VALUES (1,'Coin1','ABC'),(2,'Coin2','DEF'); | SELECT COUNT(*) FROM digital_assets WHERE company = 'ABC'; |
How many events were attended by each demographic group last year? | CREATE TABLE Events (id INT,name VARCHAR(255),date DATE); CREATE TABLE Attendees (id INT,event_id INT,age INT,gender VARCHAR(255),race VARCHAR(255)); | SELECT a.age, a.gender, a.race, COUNT(*) FROM Attendees a JOIN Events e ON a.event_id = e.id WHERE e.date >= '2021-01-01' AND e.date < '2022-01-01' GROUP BY a.age, a.gender, a.race; |
How many artifacts were found in the 'Burial Grounds' excavation site? | CREATE TABLE ExcavationSites (id INT,name VARCHAR(255)); INSERT INTO ExcavationSites (id,name) VALUES (1,'Burial Grounds'); CREATE TABLE Artifacts (id INT,excavationSiteId INT,name VARCHAR(255)); INSERT INTO Artifacts (id,excavationSiteId) VALUES (1,1),(2,1),(3,1); | SELECT COUNT(*) FROM Artifacts WHERE excavationSiteId = (SELECT id FROM ExcavationSites WHERE name = 'Burial Grounds'); |
List all female founders in the Consumer Electronics industry. | CREATE TABLE companies (id INT,name TEXT,gender TEXT,industry TEXT); INSERT INTO companies (id,name,gender,industry) VALUES (1,'Charlie Inc','Female','Consumer Electronics'); INSERT INTO companies (id,name,gender,industry) VALUES (2,'David Corp','Male','Software'); INSERT INTO companies (id,name,gender,industry) VALUES (3,'Eva LLP','Female','Finance'); | SELECT companies.name FROM companies WHERE companies.gender = 'Female' AND companies.industry = 'Consumer Electronics'; |
Insert funding records for company_id 104 | CREATE TABLE companies (id INT PRIMARY KEY,name VARCHAR(255)); CREATE TABLE funding_rounds (id INT PRIMARY KEY,company_id INT,round_type VARCHAR(255),raised_amount DECIMAL(10,2)); | INSERT INTO funding_rounds (id, company_id, round_type, raised_amount) VALUES (4, 104, 'Seed', 500000), (5, 104, 'Series A', 2000000); |
What is the maximum depth reached during deep-sea expeditions in the Indian Ocean? | CREATE TABLE deep_sea_expeditions (expedition_name TEXT,location TEXT,max_depth REAL); INSERT INTO deep_sea_expeditions (expedition_name,location,max_depth) VALUES ('Indian Ocean Expedition','Indian Ocean',8000.0); | SELECT max_depth FROM deep_sea_expeditions WHERE location = 'Indian Ocean'; |
What is the total number of cases in the justice system that involved a victim? | CREATE TABLE cases (id INT,victim_involved VARCHAR(5)); INSERT INTO cases (id,victim_involved) VALUES (1,'Yes'),(2,'No'),(3,'Yes'); | SELECT COUNT(*) FROM cases WHERE victim_involved = 'Yes'; |
What is the total mass (in kg) of all space debris larger than 10 cm in size, removed from orbit since 2000? | CREATE TABLE removed_space_debris (id INT,debris_id VARCHAR(50),mass FLOAT,size FLOAT,removal_year INT); | SELECT SUM(mass) FROM removed_space_debris WHERE size > 10 AND removal_year >= 2000; |
What traditional arts have more than 100 artists participating? | CREATE TABLE TraditionalArt (name VARCHAR(255),artists_count INT); INSERT INTO TraditionalArt (name,artists_count) VALUES ('Dance of the Maasai',120),('Papel Talo',150),('Batik',135); | SELECT name FROM TraditionalArt WHERE artists_count > 100; |
What are the total oil reserves for the world, broken down by country, as of 2020? | CREATE TABLE world_oil_reserves (country VARCHAR(255),oil_reserves DECIMAL(10,2),year INT); | SELECT wor.country, SUM(wor.oil_reserves) FROM world_oil_reserves wor WHERE wor.year = 2020 GROUP BY wor.country; |
What is the total number of subway trips in Sydney on a public holiday? | CREATE TABLE subway_trips (trip_id INT,day_of_week VARCHAR(10),city VARCHAR(50),is_holiday BOOLEAN); INSERT INTO subway_trips (trip_id,day_of_week,city,is_holiday) VALUES (1,'Monday','Sydney',false),(2,'Tuesday','Sydney',false),(3,'Friday','Sydney',true); | SELECT COUNT(*) FROM subway_trips WHERE is_holiday = true AND city = 'Sydney'; |
Identify the top 5 countries with the most unique volunteers in the last 6 months. | CREATE TABLE volunteers (id INT,volunteer_country TEXT,volunteer_name TEXT,volunteer_date DATE); INSERT INTO volunteers (id,volunteer_country,volunteer_name,volunteer_date) VALUES (1,'USA','Alice Johnson','2022-01-01'),(2,'Canada','Bob Brown','2022-03-05'); | SELECT volunteer_country, COUNT(DISTINCT volunteer_name) as unique_volunteers FROM volunteers WHERE volunteer_date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH) GROUP BY volunteer_country ORDER BY unique_volunteers DESC LIMIT 5; |
Insert new records of military equipment for a specific country in the military_equipment table. | CREATE TABLE military_equipment (id INT PRIMARY KEY,equipment_name VARCHAR(50),country VARCHAR(50),quantity INT); | INSERT INTO military_equipment (id, equipment_name, country, quantity) VALUES (3, 'Helicopter', 'Germany', 300), (4, 'Submarine', 'Germany', 200); |
What is the total oil production in the Gulf of Mexico in 2019? | CREATE TABLE production_figures (well_id INT,year INT,oil_production INT,gas_production INT); INSERT INTO production_figures (well_id,year,oil_production,gas_production) VALUES (1,2019,120000,50000); INSERT INTO production_figures (well_id,year,oil_production,gas_production) VALUES (2,2018,130000,60000); INSERT INTO production_figures (well_id,year,oil_production,gas_production) VALUES (3,2019,110000,45000); | SELECT SUM(oil_production) FROM production_figures WHERE year = 2019 AND region = 'Gulf of Mexico'; |
What was the total number of visitors to the 'Classic' exhibitions? | CREATE TABLE exhibitions (id INT,name VARCHAR(255),type VARCHAR(255),visits INT); INSERT INTO exhibitions (id,name,type,visits) VALUES (1,'Cubism','Modern',3000),(2,'Abstract','Modern',4500),(3,'Impressionism','Classic',5000),(4,'Surrealism','Modern',2500),(5,'Renaissance','Classic',6000); | SELECT SUM(visits) FROM exhibitions WHERE type = 'Classic'; |
Show the total revenue generated by products that are made of recycled materials in the 'Product' table | CREATE TABLE Product (product_id INT PRIMARY KEY,product_name VARCHAR(50),price DECIMAL(5,2),material_recycled BOOLEAN); | SELECT SUM(price) FROM Product WHERE material_recycled = TRUE; |
What is the total contract value awarded to the 'Logistics Company' in the South region in the past year? | CREATE TABLE contracts (contract_id INT,contract_value FLOAT,vendor VARCHAR(255),region VARCHAR(255)); INSERT INTO contracts (contract_id,contract_value,vendor,region) VALUES (1,500000,'ABC Company','Northeast'); INSERT INTO contracts (contract_id,contract_value,vendor,region) VALUES (2,750000,'Logistics Company','South'); | SELECT vendor, SUM(contract_value) as total_contract_value FROM contracts WHERE vendor = 'Logistics Company' AND region = 'South' AND contract_date >= DATEADD(year, -1, GETDATE()) GROUP BY vendor; |
Calculate the number of community engagement events in the last 6 months, grouped by the day of the week and ordered by the day of the week in ascending order. | CREATE TABLE Events (EventID INT,EventName TEXT,EventDate DATE); INSERT INTO Events (EventID,EventName,EventDate) VALUES (1001,'Community Pottery Workshop','2022-01-01'),(1002,'Weaving Techniques Demonstration','2022-02-15'),(1003,'Traditional Dance Festival','2022-03-31'); | SELECT DATENAME(dw, EventDate) AS Day_Of_Week, COUNT(EventID) AS Number_Of_Events FROM Events WHERE EventDate >= DATEADD(month, -6, GETDATE()) GROUP BY DATENAME(dw, EventDate) ORDER BY DATENAME(dw, EventDate) ASC; |
Which vessels have a type of 'Tanker'? | CREATE TABLE Vessels (ID VARCHAR(20),Name VARCHAR(20),Type VARCHAR(20),AverageSpeed FLOAT); INSERT INTO Vessels VALUES ('V002','Vessel B','Tanker',12.3),('V003','Vessel C','Tanker',14.8); | SELECT Name FROM Vessels WHERE Type = 'Tanker'; |
Show the average salary of employees in each location, ordered by location. | CREATE TABLE Employees (EmployeeID INT,Salary DECIMAL(10,2),Location VARCHAR(50)); INSERT INTO Employees (EmployeeID,Salary,Location) VALUES (1,50000,'NYC'),(2,55000,'LA'),(3,60000,'NYC'),(4,45000,'LA'); | SELECT Location, AVG(Salary) FROM Employees GROUP BY Location ORDER BY Location; |
What is the total number of military equipment sold to each country and the total quantity sold, ordered by the total quantity sold in descending order? | CREATE TABLE military_sales (id INT PRIMARY KEY,seller VARCHAR(255),buyer VARCHAR(255),equipment_type VARCHAR(255),quantity INT); | SELECT buyer, SUM(quantity) FROM military_sales GROUP BY buyer ORDER BY SUM(quantity) DESC; |
What is the average salary by gender? | CREATE TABLE Employees (EmployeeID int,FirstName varchar(50),LastName varchar(50),Department varchar(50),Gender varchar(50),Salary decimal(10,2)); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,Gender,Salary) VALUES (1,'John','Doe','IT','Male',75000); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,Gender,Salary) VALUES (2,'Jane','Doe','HR','Female',80000); | SELECT Gender, AVG(Salary) as AvgSalary FROM Employees GROUP BY Gender; |
What is the average donation amount for each age group in 2021? | CREATE TABLE Donors (DonorID INT,DonorName TEXT,DonorAge INT,TotalDonation FLOAT); | SELECT AVG(TotalDonation) as 'Average Donation Amount' FROM Donors WHERE YEAR(DonationDate) = 2021 GROUP BY FLOOR(DonorAge / 10) * 10; |
What is the maximum revenue for a restaurant in the 'Vegan' category? | CREATE TABLE restaurants (id INT,name VARCHAR(255),type VARCHAR(255),revenue FLOAT); INSERT INTO restaurants (id,name,type,revenue) VALUES (1,'Restaurant A','Vegan',5000.00),(2,'Restaurant B','Asian Vegan',6000.00),(3,'Restaurant C','Italian Vegan',7000.00); | SELECT MAX(revenue) FROM restaurants WHERE type LIKE '%Vegan%'; |
How many unique streaming platforms have songs been played on? | CREATE TABLE songs (id INT,title VARCHAR,platform VARCHAR); INSERT INTO songs (id,title,platform) VALUES (1,'Song1','Spotify'),(2,'Song2','Apple Music'),(3,'Song3','YouTube'),(4,'Song4','Spotify'),(5,'Song5','Apple Music'),(6,'Song6','YouTube'),(7,'Song7','Pandora'),(8,'Song8','Spotify'),(9,'Song9','Tidal'),(10,'Song10','Apple Music'); | SELECT DISTINCT platform FROM songs; |
Delete a specific genetic research project | CREATE SCHEMA if not exists biotech; CREATE TABLE if not exists biotech.research (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),type VARCHAR(255)); INSERT INTO biotech.research (id,name,country,type) VALUES (1,'ProjectA','India','Genetics'),(2,'ProjectB','China','Bioprocess'),(3,'ProjectC','India','Genetics'); | DELETE FROM biotech.research WHERE name = 'ProjectA'; |
What are the names of the spacecraft manufactured by NASA and their manufacturing dates? | CREATE TABLE Spacecraft_Manufacturing (id INT,manufacturer VARCHAR(20),cost INT,manufacturing_date DATE); INSERT INTO Spacecraft_Manufacturing (id,manufacturer,cost,manufacturing_date) VALUES (1,'NASA',6000000,'2021-10-01'); | SELECT manufacturer, manufacturing_date FROM Spacecraft_Manufacturing WHERE manufacturer = 'NASA'; |
What is the average revenue per hotel for hotels in Europe that have adopted cloud PMS? | CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,country TEXT,revenue FLOAT,cloud_pms BOOLEAN); INSERT INTO hotels (hotel_id,hotel_name,country,revenue,cloud_pms) VALUES (1,'Hotel A','France',1000000,true),(2,'Hotel B','Germany',800000,false),(3,'Hotel C','France',1200000,true); INSERT INTO hotels (hotel_id,hotel_name,country,revenue,cloud_pms) VALUES (4,'Hotel D','UK',900000,true),(5,'Hotel E','Spain',700000,false); | SELECT AVG(revenue) FROM hotels WHERE cloud_pms = true AND country LIKE 'Europe%'; |
How many bridges in the database have a span greater than 1000 feet? | CREATE TABLE Bridges (id INT,name VARCHAR(100),span FLOAT); INSERT INTO Bridges (id,name,span) VALUES (1,'Golden Gate Bridge',4200),(2,'Bay Bridge',2300),(3,'Chesapeake Bay Bridge',4800); | SELECT COUNT(*) FROM Bridges WHERE span > 1000; |
Update the email addresses of players living in the UK. | CREATE TABLE players (id INT,name VARCHAR(255),country VARCHAR(255),email VARCHAR(255)); INSERT INTO players (id,name,country,email) VALUES (1,'John Doe','UK','johndoe@example.com'),(2,'Jane Doe','USA','janedoe@example.com'); | UPDATE players SET email = CONCAT(SUBSTRING_INDEX(email, '@', 1), '_uk', '@example.com') WHERE country = 'UK'; |
What is the total quantity of items shipped from the USA to Canada between January 1, 2021 and January 15, 2021? | CREATE TABLE shipments (id INT,item_name VARCHAR(50),quantity INT,ship_date DATE,origin_country VARCHAR(50),destination_country VARCHAR(50)); INSERT INTO shipments (id,item_name,quantity,ship_date,origin_country,destination_country) VALUES (1,'Apples',100,'2021-01-02','USA','Canada'); INSERT INTO shipments (id,item_name,quantity,ship_date,origin_country,destination_country) VALUES (2,'Bananas',200,'2021-01-05','USA','Canada'); | SELECT SUM(quantity) FROM shipments WHERE origin_country = 'USA' AND destination_country = 'Canada' AND ship_date BETWEEN '2021-01-01' AND '2021-01-15'; |
Show non-profit organizations with ongoing circular economy initiatives in Africa. | CREATE TABLE Organisations (OrganisationID INT,Organisation VARCHAR(50),Type VARCHAR(20),Location VARCHAR(50));CREATE TABLE CircularEconomyInitiatives (InitiativeID INT,Organisation VARCHAR(50),InitiativeType VARCHAR(20),StartDate DATE,EndDate DATE);CREATE VIEW OngoingInitiatives AS SELECT Organisation,InitiativeType FROM CircularEconomyInitiatives CI WHERE CI.EndDate IS NULL; | SELECT Organisation FROM OngoingInitiatives OI INNER JOIN Organisations O ON OI.Organisation = O.Organisation WHERE O.Type = 'Non-Profit' AND O.Location = 'Africa'; |
Who are the top 3 highest paid employees by department? | CREATE TABLE Employees (EmployeeID INT,Name VARCHAR(50),Department VARCHAR(50),Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID,Name,Department,Salary) VALUES (1,'John Doe','HR',60000.00),(2,'Jane Smith','IT',70000.00),(3,'Mike Johnson','HR',80000.00),(4,'Emma White','Finance',90000.00); CREATE TABLE Departments (Department VARCHAR(50),Manager VARCHAR(50)); INSERT INTO Departments (Department,Manager) VALUES ('HR','Peter'),('IT','Sarah'),('Finance','David'); | SELECT e.Department, e.Name, e.Salary FROM Employees e JOIN (SELECT Department, MAX(Salary) as MaxSalary FROM Employees GROUP BY Department) m ON e.Department = m.Department AND e.Salary = m.MaxSalary ORDER BY e.Salary DESC LIMIT 3; |
How many autonomous vehicles were sold by region in the year 2020? | CREATE TABLE av_sales (id INT,make VARCHAR,model VARCHAR,year INT,region VARCHAR,sold INT); | SELECT region, SUM(sold) as total_sold FROM av_sales WHERE year = 2020 AND model LIKE '%autonomous%' GROUP BY region; |
What was the total 'cost' of 'mining_operations' in the 'OperationsData' table for '2021'? | CREATE TABLE OperationsData (id INT,operation VARCHAR(255),year INT,cost INT); INSERT INTO OperationsData (id,operation,year,cost) VALUES (1,'drilling',2021,1000),(2,'mining',2021,2000),(3,'excavation',2022,1500); | SELECT SUM(cost) FROM OperationsData WHERE operation = 'mining_operations' AND year = 2021; |
Show the number of restorative justice programs by location and year | CREATE TABLE programs (id INT,name VARCHAR(50),location VARCHAR(50),type VARCHAR(50),start_date DATE,end_date DATE); | SELECT location, YEAR(start_date) AS Year, COUNT(*) AS Programs FROM programs WHERE type = 'Restorative Justice' GROUP BY location, YEAR(start_date); |
What is the total claim amount for each risk assessment model? | CREATE TABLE Policies (ID INT,RiskAssessmentModel VARCHAR(50),ClaimAmount DECIMAL(10,2)); INSERT INTO Policies (ID,RiskAssessmentModel,ClaimAmount) VALUES (1,'Standard',1000.00),(2,'Premium',500.00),(3,'Standard',1500.00),(4,'Basic',2000.00); CREATE TABLE RiskAssessmentModels (ID INT,ModelName VARCHAR(50)); INSERT INTO RiskAssessmentModels (ID,ModelName) VALUES (1,'Standard'),(2,'Premium'),(3,'Basic'); | SELECT RiskAssessmentModel, SUM(ClaimAmount) FROM Policies GROUP BY RiskAssessmentModel; |
What is the distribution of readers by age and gender for articles about politics, categorized by the political ideology of the author? | CREATE TABLE readers (id INT,age INT,gender VARCHAR(10),article_id INT,author_id INT);CREATE TABLE articles (id INT,title VARCHAR(100),date DATE,topic VARCHAR(50),political_ideology VARCHAR(50)); INSERT INTO readers VALUES (1,45,'Female',1,1); INSERT INTO articles VALUES (1,'Politics','2022-01-01','Politics','Liberal'); | SELECT articles.political_ideology, readers.gender, readers.age, COUNT(readers.id) FROM readers INNER JOIN articles ON readers.article_id = articles.id GROUP BY articles.political_ideology, readers.gender, readers.age; |
What are the total costs of all railway projects in the northeast that started after 2020? | CREATE TABLE railway_projects (project_id INT,project_name VARCHAR(100),state CHAR(2),start_date DATE,cost FLOAT); INSERT INTO railway_projects VALUES (1,'Northeast Corridor Upgrade','NY','2021-01-01',500000000),(2,'Keystone Corridor Improvement','PA','2020-06-15',250000000),(3,'Ethan Allen Express Extension','VT','2022-01-01',300000000); | SELECT SUM(cost) FROM railway_projects WHERE state IN ('CT', 'ME', 'MD', 'MA', 'MI', 'NH', 'NJ', 'NY', 'OH', 'PA', 'RI', 'VT', 'VA', 'WI') AND start_date > '2020-01-01'; |
Delete all records of employees who identify as non-binary and work in the finance department. | SAME AS ABOVE | DELETE FROM Employees WHERE Gender = 'Non-binary' AND Department = 'Finance'; |
What is the maximum energy efficiency (in %) of wind farms in 'Europe' that were built after '2015'? | CREATE TABLE wind_farms (id INT,name VARCHAR(50),region VARCHAR(50),built_year INT,efficiency FLOAT); INSERT INTO wind_farms (id,name,region,built_year,efficiency) VALUES (1,'WindFarm1','Europe',2016,0.45),(2,'WindFarm2','Europe',2017,0.50); | SELECT MAX(efficiency) FROM wind_farms WHERE region = 'Europe' AND built_year > 2015; |
What is the maximum budget allocated for utilities in urban areas? | CREATE TABLE areas (id INT,name VARCHAR(20)); INSERT INTO areas (id,name) VALUES (1,'Urban'),(2,'Rural'); CREATE TABLE budget (item VARCHAR(20),area_id INT,amount INT); INSERT INTO budget (item,area_id,amount) VALUES ('Utilities',1,6000000),('Utilities',2,3500000); | SELECT MAX(amount) FROM budget WHERE item = 'Utilities' AND area_id = (SELECT id FROM areas WHERE name = 'Urban'); |
What is the average salary of male employees in the IT department? | CREATE TABLE Employees (EmployeeID INT,Gender VARCHAR(10),Department VARCHAR(20),Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID,Gender,Department,Salary) VALUES (1,'Male','IT',70000.00),(2,'Female','IT',68000.00); | SELECT AVG(Salary) FROM Employees WHERE Gender = 'Male' AND Department = 'IT'; |
What is the average income of households with 3 members in the state of Texas? | CREATE TABLE Households (HouseholdID INTEGER,HouseholdMembers INTEGER,HouseholdIncome INTEGER,HouseholdState TEXT); | SELECT AVG(HouseholdIncome) FROM Households H WHERE H.HouseholdMembers = 3 AND H.HouseholdState = 'Texas'; |
What is the total production of wells in the 'South China Sea'? | CREATE TABLE wells (well_id INT,well_name VARCHAR(50),region VARCHAR(50),production_rate FLOAT); INSERT INTO wells (well_id,well_name,region,production_rate) VALUES (5,'Well E','South China Sea',4000),(6,'Well F','South China Sea',9000); | SELECT SUM(production_rate) FROM wells WHERE region = 'South China Sea'; |
Show the names and genres of all artists who have never performed in the United States. | CREATE TABLE artists (id INT,name VARCHAR(255),genre VARCHAR(255),home_country VARCHAR(255)); CREATE TABLE artist_concerts (artist_id INT,country VARCHAR(255),city VARCHAR(255)); INSERT INTO artists (id,name,genre,home_country) VALUES (1,'Taylor Swift','Country Pop','United States'); INSERT INTO artist_concerts (artist_id,country,city) VALUES (1,'Canada','Toronto'); | SELECT a.name, a.genre FROM artists a WHERE a.id NOT IN (SELECT ac.artist_id FROM artist_concerts ac WHERE ac.country = 'United States'); |
What is the total number of cases heard in the justice_data schema's court_hearings table where the defendant is of Indigenous origin, and the average sentence length for those cases? | CREATE TABLE justice_data.court_hearings (id INT,case_number INT,hearing_date DATE,defendant_race VARCHAR(50)); CREATE TABLE justice_data.sentencing (id INT,case_number INT,offender_id INT,sentence_length INT,conviction VARCHAR(50)); | SELECT CH.defendant_race, COUNT(*), AVG(S.sentence_length) FROM justice_data.court_hearings CH JOIN justice_data.sentencing S ON CH.case_number = S.case_number WHERE CH.defendant_race LIKE '%Indigenous%' GROUP BY CH.defendant_race; |
Delete the records of the languages 'Tigrinya' and 'Amharic' from the Languages table. | CREATE TABLE Languages (Language VARCHAR(50),Status VARCHAR(50)); INSERT INTO Languages (Language,Status) VALUES ('Tigrinya','Vulnerable'),('Amharic','Vulnerable'); | DELETE FROM Languages WHERE Language IN ('Tigrinya', 'Amharic'); |
What is the total number of network infrastructure investments in each region, grouped by year? | CREATE TABLE network_investments (investment_id INT,investment FLOAT,region VARCHAR(50),year INT); INSERT INTO network_investments (investment_id,investment,region,year) VALUES (1,1000000,'North America',2020),(2,2000000,'South America',2019),(3,1500000,'Europe',2020); | SELECT year, region, SUM(investment) AS total_investment FROM network_investments GROUP BY year, region; |
Identify forests with the largest wildlife habitat in India and China? | CREATE TABLE forests (id INT,name VARCHAR(255),hectares FLOAT,country VARCHAR(255)); INSERT INTO forests (id,name,hectares,country) VALUES (1,'Sundarbans',133000.0,'India'),(2,'Great Himalayan National Park',90500.0,'India'),(3,'Xishuangbanna',242000.0,'China'),(4,'Wuyishan',56000.0,'China'); | SELECT forests.name FROM forests WHERE forests.country IN ('India', 'China') AND forests.hectares = (SELECT MAX(hectares) FROM forests WHERE forests.country IN ('India', 'China')); |
What is the maximum daily revenue for each line in the 'mumbai' schema? | CREATE TABLE mumbai.lines (id INT,line_name VARCHAR); CREATE TABLE mumbai.revenue (id INT,line_id INT,daily_revenue DECIMAL); | SELECT mumbai.lines.line_name, MAX(mumbai.revenue.daily_revenue) FROM mumbai.lines INNER JOIN mumbai.revenue ON mumbai.lines.id = mumbai.revenue.line_id GROUP BY mumbai.lines.line_name; |
List the names of all biotech startups that have received more funding than the average funding amount per country. | CREATE SCHEMA if not exists biotech;CREATE TABLE if not exists biotech.startups(id INT,name VARCHAR(50),country VARCHAR(50),funding DECIMAL(10,2));INSERT INTO biotech.startups(id,name,country,funding) VALUES (1,'StartupA','US',1500000.00),(2,'StartupB','Canada',2000000.00),(3,'StartupC','Mexico',500000.00),(4,'StartupD','US',1000000.00),(5,'StartupE','Brazil',750000.00); | SELECT name FROM biotech.startups s1 WHERE s1.funding > (SELECT AVG(funding) FROM biotech.startups s2 WHERE s2.country = s1.country); |
What are the names and prices of all items in the "Desserts" category? | CREATE TABLE Menu (menu_id INT PRIMARY KEY,item_name VARCHAR(255),category VARCHAR(255),price DECIMAL(5,2)); | SELECT item_name, price FROM Menu WHERE category = 'Desserts'; |
What is the minimum number of trips taken by autonomous taxis in San Francisco in a week? | CREATE TABLE public.trips_by_week (id SERIAL PRIMARY KEY,vehicle_type TEXT,city TEXT,week_start DATE,week_trips INTEGER); INSERT INTO public.trips_by_week (vehicle_type,city,week_start,week_trips) VALUES ('autonomous_taxi','San Francisco','2022-01-01',7000),('autonomous_taxi','San Francisco','2022-01-08',6500),('autonomous_taxi','San Francisco','2022-01-15',6000); | SELECT MIN(week_trips) FROM public.trips_by_week WHERE vehicle_type = 'autonomous_taxi' AND city = 'San Francisco'; |
Compare fish health metrics across multiple countries | CREATE TABLE health_metrics (id INT,farm_id INT,country VARCHAR(50),health_score INT); INSERT INTO health_metrics | SELECT health_score FROM health_metrics WHERE country IN ('Norway', 'Chile', 'Scotland') GROUP BY country ORDER BY health_score; |
What is the maximum donation amount from Australia? | CREATE TABLE Donors (DonorID INT,DonorName TEXT,DonationAmount DECIMAL(10,2),Country TEXT); | SELECT MAX(DonationAmount) FROM Donors WHERE Country = 'Australia'; |
What is the total amount donated by new donors in Q2 2022? | CREATE TABLE donors (id INT,name TEXT,program TEXT,amount INT,donation_date DATE); INSERT INTO donors (id,name,program,amount,donation_date) VALUES (1,'John Doe','Arts',500,'2022-04-15'),(2,'Jane Smith','Education',1000,'2022-02-28'),(3,'Alice Johnson','Arts',750,'2021-12-31'),(4,'Grace Wilson','Arts',1000,'2022-05-12'),(5,'Harry Moore','Education',250,'2022-03-14'); | SELECT SUM(amount) FROM (SELECT amount FROM donors WHERE donation_date >= '2022-04-01' AND donation_date < '2022-07-01' GROUP BY id HAVING COUNT(*) = 1) AS new_donors; |
Calculate the average AI safety incident cost in Oceania. | CREATE TABLE ai_safety_incident_costs (incident_id INTEGER,incident_cost FLOAT,region TEXT); INSERT INTO ai_safety_incident_costs (incident_id,incident_cost,region) VALUES (8,5000,'Oceania'),(9,7000,'Oceania'),(10,6000,'Africa'); | SELECT region, AVG(incident_cost) FROM ai_safety_incident_costs WHERE region = 'Oceania' GROUP BY region; |
What was the total revenue from the 'Theater Performance' event? | CREATE TABLE Events (event_id INT,event_name VARCHAR(50),revenue INT); INSERT INTO Events (event_id,event_name,revenue) VALUES (6,'Theater Performance',15000); | SELECT revenue FROM Events WHERE event_name = 'Theater Performance'; |
What is the total number of criminal cases heard in district courts in New York in 2019? | CREATE TABLE criminal_cases (case_id INT,court_type VARCHAR(20),year INT); | SELECT COUNT(*) FROM criminal_cases WHERE court_type = 'district' AND year = 2019; |
What is the total investment for genetic research companies in New York? | CREATE TABLE companies (id INT,name VARCHAR(50),type VARCHAR(50),location VARCHAR(50),investment FLOAT); INSERT INTO companies (id,name,type,location,investment) VALUES (3,'GenoSolutions','Genetic Research','New York',8000000); INSERT INTO companies (id,name,type,location,investment) VALUES (4,'BioNexus','Bioprocess','New York',6000000); | SELECT SUM(investment) FROM companies WHERE type = 'Genetic Research' AND location = 'New York'; |
Which customer demographic groups have the highest total waste? | CREATE TABLE inventory (item VARCHAR(255),daily_waste NUMERIC,customer_group VARCHAR(50),date DATE); INSERT INTO inventory (item,daily_waste,customer_group,date) VALUES ('Chicken Burger',20,'Millennials','2021-10-01'),('Fish and Chips',15,'Gen X','2021-10-01'),('BBQ Ribs',10,'Baby Boomers','2021-10-01'); | SELECT customer_group, SUM(daily_waste) FROM inventory WHERE date >= DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY) GROUP BY customer_group ORDER BY SUM(daily_waste) DESC; |
What is the total donation amount given by individual donors from the USA in the year 2021? | CREATE TABLE donors (donor_id INT,donor_name TEXT,country TEXT,donation_amount FLOAT); INSERT INTO donors (donor_id,donor_name,country,donation_amount) VALUES (1,'John Doe','USA',200.00),(2,'Jane Smith','Canada',300.00); | SELECT SUM(donation_amount) FROM donors WHERE country = 'USA' AND YEAR(donation_date) = 2021 AND donor_type = 'individual'; |
Find the names and quantities of chemical substances that are both produced in the South America region and have an impact score greater than 65. | CREATE TABLE chemical_production (region VARCHAR(20),chemical VARCHAR(30),quantity INT); INSERT INTO chemical_production (region,chemical,quantity) VALUES ('South America','Isobutanol',4000),('South America','Methanol',7000); CREATE TABLE environmental_impact (chemical VARCHAR(30),impact_score INT); INSERT INTO environmental_impact (chemical,impact_score) VALUES ('Isobutanol',70),('Methanol',60),('Ethylene',67); | SELECT cp.chemical, cp.quantity FROM chemical_production cp JOIN environmental_impact ei ON cp.chemical = ei.chemical WHERE cp.region = 'South America' AND ei.impact_score > 65; |
How many sedans were sold in India in Q2 2021? | CREATE TABLE IndianSales (id INT,vehicle_type VARCHAR(50),quantity INT,country VARCHAR(50),quarter INT,year INT); INSERT INTO IndianSales (id,vehicle_type,quantity,country,quarter,year) VALUES (1,'Sedan',1000,'India',2,2021),(2,'Sedan',1200,'India',3,2021),(3,'Hatchback',1500,'India',2,2021),(4,'Hatchback',1700,'India',3,2021); | SELECT SUM(quantity) FROM IndianSales WHERE vehicle_type = 'Sedan' AND country = 'India' AND quarter = 2 AND year = 2021; |
Show the monthly change in waste production for each mining site | CREATE TABLE MiningSites (SiteID INT,SiteName VARCHAR(50),Location VARCHAR(50)); INSERT INTO MiningSites (SiteID,SiteName,Location) VALUES (1,'Site A','New York'),(2,'Site B','Ohio'),(3,'Site C','Alberta'); CREATE TABLE WasteProduction (SiteID INT,ProductionDate DATE,WasteAmount INT); INSERT INTO WasteProduction (SiteID,ProductionDate,WasteAmount) VALUES (1,'2021-01-01',1000),(1,'2021-02-01',1200),(2,'2021-01-01',1500),(2,'2021-02-01',1800),(3,'2021-01-01',2000),(3,'2021-02-01',2200); | SELECT s.SiteName, s.Location, DATE_FORMAT(w.ProductionDate, '%Y-%m') as Month, (SUM(w.WasteAmount) - LAG(SUM(w.WasteAmount)) OVER (PARTITION BY s.SiteID ORDER BY w.ProductionDate)) as MonthlyChangeInWasteProduction FROM WasteProduction w INNER JOIN MiningSites s ON w.SiteID = s.SiteID GROUP BY w.SiteID, Month; |
Find the number of unique patients served by hospitals and clinics in 'suburban' areas. | CREATE TABLE patients (id INT,hospital_id INT,clinic_id INT,name TEXT,location TEXT); INSERT INTO patients (id,hospital_id,clinic_id,name,location) VALUES (1,1,NULL,'Patient A','suburban'); INSERT INTO patients (id,hospital_id,clinic_id,name,location) VALUES (2,2,NULL,'Patient B','suburban'); INSERT INTO patients (id,hospital_id,clinic_id,name,location) VALUES (3,NULL,1,'Patient C','suburban'); | SELECT COUNT(DISTINCT name) FROM patients WHERE location = 'suburban'; |
What is the total cargo quantity for each cargo type and vessel flag? | CREATE TABLE Vessels (Id INT,Name VARCHAR(50),Type VARCHAR(50),Flag VARCHAR(50)); INSERT INTO Vessels (Id,Name,Type,Flag) VALUES (1,'Aurelia','Tanker','Panama'); INSERT INTO Vessels (Id,Name,Type,Flag) VALUES (2,'Barracuda','Bulk Carrier','Marshall Islands'); CREATE TABLE Cargo (Id INT,VesselId INT,CargoType VARCHAR(50),Quantity INT); INSERT INTO Cargo (Id,VesselId,CargoType,Quantity) VALUES (1,1,'Oil',5000); INSERT INTO Cargo (Id,VesselId,CargoType,Quantity) VALUES (2,2,'Coal',8000); | SELECT Vessels.Flag, Cargo.CargoType, SUM(Cargo.Quantity) as TotalQuantity FROM Cargo JOIN Vessels ON Cargo.VesselId = Vessels.Id GROUP BY Vessels.Flag, Cargo.CargoType; |
Count the number of policyholders in Ohio | CREATE TABLE policyholders (policyholder_id INT,state VARCHAR(2)); INSERT INTO policyholders (policyholder_id,state) VALUES (1,'OH'),(2,'OH'),(3,'NY'); | SELECT COUNT(*) FROM policyholders WHERE state = 'OH'; |
Find the cosmetics with the highest sales in each category for the past 12 months. | CREATE TABLE sales_by_month (product_id INT,sale_date DATE,sales INT,product_category VARCHAR(50)); INSERT INTO sales_by_month (product_id,sale_date,sales,product_category) VALUES (1,'2021-01-01',500,'Foundation'),(2,'2021-01-01',800,'Lipstick'); | SELECT product_category, product_id, MAX(sales) AS max_sales FROM sales_by_month WHERE sale_date >= DATEADD(month, -12, CURRENT_DATE) GROUP BY product_category, product_id; |
List policy numbers and claim amounts for policyholders living in 'Tokyo' or 'Delhi' who have filed a claim. | CREATE TABLE Policies (PolicyNumber INT,PolicyholderID INT,PolicyState VARCHAR(20)); CREATE TABLE Claims (PolicyholderID INT,ClaimAmount DECIMAL(10,2),PolicyState VARCHAR(20)); INSERT INTO Policies (PolicyNumber,PolicyholderID,PolicyState) VALUES (3001,13,'Tokyo'),(3002,14,'Tokyo'),(3003,15,'Delhi'); INSERT INTO Claims (PolicyholderID,ClaimAmount,PolicyState) VALUES (13,1200,'Tokyo'),(14,1300,'Tokyo'),(15,1400,'Delhi'); | SELECT Policies.PolicyNumber, Claims.ClaimAmount FROM Policies JOIN Claims ON Policies.PolicyholderID = Claims.PolicyholderID WHERE Policies.PolicyState IN ('Tokyo', 'Delhi'); |
What is the minimum response time for emergency calls in the 'Central' district? | CREATE TABLE districts (district_id INT,district_name TEXT); INSERT INTO districts VALUES (1,'Downtown'),(2,'Uptown'),(3,'Central'); CREATE TABLE calls (call_id INT,district_id INT,response_time INT); | SELECT MIN(c.response_time) FROM calls c WHERE c.district_id = (SELECT district_id FROM districts WHERE district_name = 'Central'); |
How many policies does the 'Diverse Team' have in 'New York' and 'Illinois'? | CREATE TABLE Policies (PolicyID INT,Team VARCHAR(20),State VARCHAR(20)); INSERT INTO Policies VALUES (1,'Diverse Team','New York'),(2,'United Team','Illinois'),(3,'Diverse Team','Texas'),(4,'Global Team','New York'),(5,'Diverse Team','Illinois'); | SELECT Team, COUNT(*) FROM Policies WHERE State IN ('New York', 'Illinois') AND Team = 'Diverse Team' GROUP BY Team; |
What is the maximum number of lanes for highways in Arizona? | CREATE TABLE highways (id INT,name TEXT,state TEXT,num_lanes INT); INSERT INTO highways (id,name,state,num_lanes) VALUES (1,'AZ-1 Interstate','AZ',8); | SELECT MAX(num_lanes) FROM highways WHERE state = 'AZ'; |
Delete the cargo record with ID 33344 from the "cargo" table | CREATE TABLE cargo (id INT PRIMARY KEY,description VARCHAR(255)); | WITH deleted_cargo AS (DELETE FROM cargo WHERE id = 33344 RETURNING id, description) SELECT * FROM deleted_cargo; |
What is the maximum number of goals scored by a single player in a hockey match in the 'hockey_matches' table? | CREATE TABLE hockey_matches (id INT,home_team VARCHAR(50),away_team VARCHAR(50),location VARCHAR(50),date DATE,goals_home INT,goals_away INT); INSERT INTO hockey_matches (id,home_team,away_team,location,date,goals_home,goals_away) VALUES (1,'Toronto Maple Leafs','Montreal Canadiens','Toronto','2022-03-10',4,2); INSERT INTO hockey_matches (id,home_team,away_team,location,date,goals_home,goals_away) VALUES (2,'Boston Bruins','New York Rangers','Boston','2022-03-15',3,5); | SELECT MAX(goals_home), MAX(goals_away) FROM hockey_matches; |
Show the energy efficiency statistics of the top 5 countries in the world | CREATE TABLE energy_efficiency_stats (country VARCHAR(255),year INT,energy_efficiency_index FLOAT); | SELECT country, energy_efficiency_index FROM energy_efficiency_stats WHERE country IN (SELECT country FROM (SELECT country, AVG(energy_efficiency_index) as avg_efficiency FROM energy_efficiency_stats GROUP BY country ORDER BY avg_efficiency DESC LIMIT 5) as temp) ORDER BY energy_efficiency_index DESC; |
What is the ratio of male to female collaborations in the Pop genre? | CREATE TABLE CollaborationData (CollaborationID INT,Artist1 VARCHAR(100),Artist2 VARCHAR(100),Genre VARCHAR(50)); INSERT INTO CollaborationData (CollaborationID,Artist1,Artist2,Genre) VALUES (1,'Taylor Swift','Ed Sheeran','Pop'),(2,'Ariana Grande','Justin Bieber','Pop'); | SELECT (SELECT COUNT(*) FROM CollaborationData WHERE (Artist1 = 'Male' OR Artist2 = 'Male') AND Genre = 'Pop') / (SELECT COUNT(*) FROM CollaborationData WHERE (Artist1 = 'Female' OR Artist2 = 'Female') AND Genre = 'Pop') AS Ratio; |
What is the number of non-binary employees in each department? | CREATE TABLE Employees (EmployeeID INT,Gender VARCHAR(10),Department VARCHAR(20)); INSERT INTO Employees (EmployeeID,Gender,Department) VALUES (1,'Male','IT'),(2,'Female','IT'),(3,'Non-binary','HR'),(4,'Male','HR'),(5,'Non-binary','IT'); | SELECT Department, COUNT(*) FROM Employees WHERE Gender = 'Non-binary' GROUP BY Department; |
Determine the total response time for emergency calls in each district in 2021. | CREATE TABLE district (did INT,name VARCHAR(255)); INSERT INTO district VALUES (1,'Downtown'),(2,'Uptown'); CREATE TABLE calls (call_id INT,district_id INT,response_time INT,year INT); | SELECT d.name, SUM(c.response_time) FROM district d JOIN calls c ON d.did = c.district_id WHERE c.year = 2021 AND c.response_time < 60 GROUP BY d.did; |
Find the number of policyholders who have had at least one claim in the past year. | CREATE TABLE policyholders (policyholder_id INT,first_name VARCHAR(50),last_name VARCHAR(50)); CREATE TABLE claims (claim_id INT,policyholder_id INT,claim_date DATE); | SELECT COUNT(DISTINCT policyholders.policyholder_id) FROM policyholders INNER JOIN claims ON policyholders.policyholder_id = claims.policyholder_id WHERE claims.claim_date >= DATE_SUB(NOW(), INTERVAL 1 YEAR); |
What is the total number of strikes in 'labor_unions'? | CREATE TABLE labor_unions.strikes (id INT,union TEXT,year INT,duration INT); | SELECT SUM(duration) FROM labor_unions.strikes; |
Find the top 3 tree species with the highest carbon sequestration rate. | CREATE TABLE carbon_sequestration (species VARCHAR(255),sequestration_rate DECIMAL(5,2)); | SELECT species, sequestration_rate FROM carbon_sequestration ORDER BY sequestration_rate DESC LIMIT 3; |
List the unique types of healthcare facilities in the 'north' region, excluding dental clinics. | CREATE TABLE healthcare_facilities (id INT,name TEXT,region TEXT,type TEXT); INSERT INTO healthcare_facilities (id,name,region,type) VALUES (1,'Hospital A','north','hospital'); INSERT INTO healthcare_facilities (id,name,region,type) VALUES (2,'Clinic A','north','clinic'); INSERT INTO healthcare_facilities (id,name,region,type) VALUES (3,'Dental Clinic A','north','dental_clinic'); | SELECT DISTINCT type FROM healthcare_facilities WHERE region = 'north' AND type != 'dental_clinic'; |
What is the total revenue generated by all gift shops in Asia? | CREATE TABLE Museums (MuseumID INT,Name TEXT,Country TEXT);CREATE TABLE GiftShops (GiftShopID INT,MuseumID INT,Revenue INT); | SELECT SUM(GiftShops.Revenue) FROM Museums INNER JOIN GiftShops ON Museums.MuseumID = GiftShops.MuseumID WHERE Museums.Country = 'Asia'; |
What is the total number of articles written by local authors about local events in 2021? | CREATE TABLE local_articles (id INT,title VARCHAR(100),publication_year INT,author_local BOOLEAN,event_local BOOLEAN); INSERT INTO local_articles (id,title,publication_year,author_local,event_local) VALUES (1,'Article1',2021,TRUE,TRUE),(2,'Article2',2020,FALSE,TRUE),(3,'Article3',2021,TRUE,FALSE); | SELECT COUNT(*) FROM local_articles WHERE publication_year = 2021 AND author_local = TRUE AND event_local = TRUE; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.