instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
What is the average attendance for theater events in LA and NY? | CREATE TABLE Events (event_id INT,event_type VARCHAR(50),location VARCHAR(50)); CREATE TABLE Attendance (attendee_id INT,event_id INT); INSERT INTO Events (event_id,event_type,location) VALUES (1,'Musical','New York'),(2,'Theater','Los Angeles'),(3,'Theater','New York'); INSERT INTO Attendance (attendee_id,event_id) VALUES (1,1),(2,1),(3,1),(4,2),(5,3); | SELECT AVG(cnt) FROM (SELECT COUNT(DISTINCT A.attendee_id) AS cnt FROM Attendance A WHERE EXISTS (SELECT 1 FROM Events E WHERE E.event_type = 'Theater' AND E.location IN ('Los Angeles', 'New York') AND A.event_id = E.event_id)) AS subquery |
What was the total revenue from online donations for the "Visual Arts" program? | CREATE TABLE online_donations_2 (program VARCHAR(255),donation FLOAT); INSERT INTO online_donations_2 (program,donation) VALUES ('Visual Arts',500),('Visual Arts',250),('Dance Education',300); | SELECT SUM(donation) FROM online_donations_2 WHERE program = 'Visual Arts'; |
What is the average safety score of chemical production sites in the United States, partitioned by state and ranked in descending order? | CREATE TABLE production_sites (site_id INT,site_name TEXT,country TEXT,state TEXT,safety_score FLOAT); INSERT INTO production_sites (site_id,site_name,country,state,safety_score) VALUES (1,'Site A','USA','NY',92.5),(2,'Site B','USA','CA',87.4),(3,'Site C','USA','TX',95.3),(4,'Site D','USA','FL',89.2); | SELECT state, AVG(safety_score) as avg_safety_score, ROW_NUMBER() OVER (ORDER BY AVG(safety_score) DESC) as rank FROM production_sites WHERE country = 'USA' GROUP BY state ORDER BY rank; |
What is the production rate rank for each chemical in the past 6 months? | CREATE TABLE production_rates (id INT PRIMARY KEY,chemical_name VARCHAR(255),production_rate INT,date DATE); INSERT INTO production_rates (id,chemical_name,production_rate,date) VALUES (5,'Citric Acid',600,'2022-01-01'); INSERT INTO production_rates (id,chemical_name,production_rate,date) VALUES (6,'Boric Acid',800,'2022-01-02'); | SELECT chemical_name, production_rate, RANK() OVER(ORDER BY production_rate DESC) as production_rank FROM production_rates WHERE date >= DATEADD(month, -6, GETDATE()); |
Which countries have the highest climate finance expenditures in Latin America? | CREATE TABLE climate_finance (id INT,country VARCHAR(50),sector VARCHAR(50),amount FLOAT); INSERT INTO climate_finance (id,country,sector,amount) VALUES (1,'Brazil','Climate Mitigation',2500000); INSERT INTO climate_finance (id,country,sector,amount) VALUES (2,'Argentina','Climate Adaptation',1800000); INSERT INTO climate_finance (id,country,sector,amount) VALUES (3,'Colombia','Climate Mitigation',2200000); | SELECT country, SUM(amount) as total_amount FROM climate_finance WHERE sector = 'Climate Mitigation' OR sector = 'Climate Adaptation' GROUP BY country ORDER BY total_amount DESC; |
What are the total sales for each drug in Q2 2020? | CREATE TABLE drugs (drug_id INT,drug_name TEXT); INSERT INTO drugs (drug_id,drug_name) VALUES (1001,'Ibuprofen'),(1002,'Paracetamol'),(1003,'Aspirin'); CREATE TABLE sales (sale_id INT,drug_id INT,sale_date DATE,revenue FLOAT); INSERT INTO sales (sale_id,drug_id,sale_date,revenue) VALUES (1,1001,'2020-04-05',1800.0),(2,1002,'2020-04-10',2300.0),(3,1003,'2020-04-15',1400.0),(4,1001,'2020-05-20',1900.0),(5,1002,'2020-06-25',2400.0); | SELECT drug_name, SUM(revenue) as total_sales FROM sales JOIN drugs ON sales.drug_id = drugs.drug_id WHERE sale_date BETWEEN '2020-04-01' AND '2020-06-30' GROUP BY drug_name; |
What is the market access strategy for each drug, ranked by market access approval date? | CREATE TABLE MarketAccess (DrugName varchar(50),ApprovalDate date,ApprovalYear int); INSERT INTO MarketAccess (DrugName,ApprovalDate,ApprovalYear) VALUES ('DrugE','2021-02-14',2021),('DrugF','2020-11-22',2020),('DrugG','2019-07-06',2019),('DrugH','2020-10-18',2020); | SELECT DrugName, ApprovalDate, ROW_NUMBER() OVER (ORDER BY ApprovalDate) as ApprovalRank FROM MarketAccess; |
Who are the top 2 sales representatives by total sales for 'DrugT' in the North America region in Q1 2021? | CREATE TABLE sales_data_2 (rep_name TEXT,drug_name TEXT,region TEXT,quarter INT,total_sales FLOAT); INSERT INTO sales_data_2 (rep_name,drug_name,region,quarter,total_sales) VALUES ('RepE','DrugT','North America',1,600000),('RepF','DrugT','North America',1,700000),('RepG','DrugT','North America',1,550000),('RepH','DrugT','North America',1,450000); | SELECT rep_name, SUM(total_sales) AS total_sales FROM sales_data_2 WHERE drug_name = 'DrugT' AND region = 'North America' AND quarter = 1 GROUP BY rep_name ORDER BY total_sales DESC LIMIT 2; |
What is the number of hospital beds per state? | CREATE TABLE beds (state VARCHAR(2),num_beds INT); | SELECT state, AVG(num_beds) FROM beds GROUP BY state; |
Insert a new row into the 'startups' table for 'Health Startup 5', founded in '2022-03-15' by 'Middle Eastern' founder, with a funding amount of $7,500,000 | CREATE TABLE startups (id INT,name TEXT,industry TEXT,founding_date DATE,raised_funding FLOAT,founder_race TEXT); | INSERT INTO startups (name, industry, founding_date, raised_funding, founder_race) VALUES ('Health Startup 5', 'Healthcare', '2022-03-15', 7500000.00, 'Middle Eastern'); |
What is the percentage of diverse individuals in the workforce for companies with headquarters in 'Indonesia' and 'Argentina'? | CREATE TABLE diversity (id INT,company_id INT,gender VARCHAR(50),race VARCHAR(50),role VARCHAR(50)); INSERT INTO diversity (id,company_id,gender,race,role) VALUES (6,5,'Female','Latinx','Data Scientist'); INSERT INTO diversity (id,company_id,gender,race,role) VALUES (7,6,'Male','Indigenous','Software Engineer'); CREATE TABLE company (id INT,name VARCHAR(50),founding_year INT,industry VARCHAR(50),country VARCHAR(50)); INSERT INTO company (id,name,founding_year,industry,country) VALUES (5,'Budi Utama',2017,'E-commerce','Indonesia'); INSERT INTO company (id,name,founding_year,industry,country) VALUES (6,'Garcia Group',2018,'Fintech','Argentina'); | SELECT d.company_id, ROUND(COUNT(*) * 100.0 / (SELECT COUNT(*) FROM diversity WHERE company_id = d.company_id), 2) as percentage FROM diversity d WHERE (SELECT country FROM company WHERE id = d.company_id) IN ('Indonesia', 'Argentina') GROUP BY d.company_id; |
What is the average budget spent on disability support programs per type and month? | CREATE TABLE Disability_Support_Data (Program_ID INT,Program_Name VARCHAR(50),Budget DECIMAL(10,2),Accommodation_Type VARCHAR(50),Request_Date DATE); | SELECT DATE_PART('month', Request_Date) as Month, Accommodation_Type, AVG(Budget) as Avg_Budget FROM Disability_Support_Data GROUP BY Month, Accommodation_Type; |
List the regulatory frameworks for digital assets in Switzerland and their respective statuses. | CREATE TABLE swiss_frameworks (framework_name VARCHAR(50),status VARCHAR(20)); INSERT INTO swiss_frameworks (framework_name,status) VALUES ('Blockchain Act','Passed'),('Swiss FinTech License','Active'),('DLT-Pilot','Active'); | SELECT framework_name, status FROM swiss_frameworks; |
What are the total transaction fees for each miner in the last week? | CREATE TABLE block_rewards (miner TEXT,block_height INTEGER,reward REAL,timestamp TIMESTAMP); INSERT INTO block_rewards (miner,block_height,reward,timestamp) VALUES ('AntPool',1234569,10.56,'2022-01-08 10:01:20'); INSERT INTO block_rewards (miner,block_height,reward,timestamp) VALUES ('SlushPool',1234570,11.34,'2022-01-09 11:02:30'); | SELECT miner, SUM(reward) as total_fees FROM block_rewards WHERE timestamp >= (SELECT timestamp FROM block_rewards ORDER BY timestamp DESC LIMIT 1) - INTERVAL '1 week' GROUP BY miner; |
What is the daily average number of unique active wallets on the Polygon network in the last month? | CREATE TABLE polygon_wallets (wallet_id INT,wallet_address VARCHAR(42),daily_activity DATE); | SELECT AVG(wallet_count) as daily_average_unique_wallets FROM (SELECT wallet_address, COUNT(DISTINCT daily_activity) as wallet_count FROM polygon_wallets WHERE daily_activity >= NOW() - INTERVAL '1 month' GROUP BY wallet_address) subquery; |
What is the average carbon sequestration rate for tropical forests in Brazil? | CREATE TABLE CarbonSequestration (id INT,name VARCHAR(255),region VARCHAR(255),year INT,rate FLOAT); INSERT INTO CarbonSequestration (id,name,region,year,rate) VALUES (1,'Tropical Forest','Brazil',2010,3.5); | SELECT AVG(rate) FROM CarbonSequestration WHERE name = 'Tropical Forest' AND region = 'Brazil'; |
What are the total sales for each quarter by region? | CREATE TABLE sales (product_id INT,product_name VARCHAR(100),category VARCHAR(50),sale_date DATE,revenue DECIMAL(10,2),region VARCHAR(50)); INSERT INTO sales (product_id,product_name,category,sale_date,revenue,region) VALUES (1,'Lipstick','Cosmetics','2022-01-02',25.99,'North'),(2,'Foundation','Cosmetics','2022-01-15',34.99,'South'); | SELECT region, EXTRACT(QUARTER FROM sale_date) AS quarter, SUM(revenue) AS total_sales FROM sales GROUP BY region, quarter; |
What is the total CO2 emissions of cosmetic companies in the EU? | CREATE TABLE company (company_id INT,company_name VARCHAR(50),co2_emissions FLOAT,region VARCHAR(50)); | SELECT SUM(co2_emissions) FROM company WHERE region = 'EU'; |
What is the average ticket price for each artist? | CREATE TABLE Tickets (id INT,event_id INT,artist VARCHAR(255),price FLOAT); | SELECT artist, AVG(price) FROM Tickets GROUP BY artist; |
What is the average ticket price for musicals in New York? | CREATE TABLE musicals (title VARCHAR(255),location VARCHAR(255),price DECIMAL(5,2)); INSERT INTO musicals (title,location,price) VALUES ('Phantom of the Opera','New York',125.99),('Lion King','New York',149.99); | SELECT AVG(price) FROM musicals WHERE location = 'New York'; |
Get the average veteran unemployment rate for the last 3 years by state | CREATE TABLE veteran_unemployment (state TEXT,year INT,rate FLOAT); INSERT INTO veteran_unemployment (state,year,rate) VALUES ('California',2021,5.3),('California',2020,5.7),('California',2019,6.1),('New York',2021,4.9),('New York',2020,5.2),('New York',2019,5.6); | SELECT state, AVG(rate) FROM veteran_unemployment WHERE year BETWEEN YEAR(CURRENT_DATE) - 3 AND YEAR(CURRENT_DATE) GROUP BY state; |
What is the average time between equipment maintenance for each type of military aircraft? | CREATE TABLE equipment (id INT,equipment_type VARCHAR(255),manufacturer VARCHAR(255)); CREATE TABLE maintenance (id INT,equipment_id INT,maintenance_date DATE); INSERT INTO equipment (id,equipment_type,manufacturer) VALUES (1,'F-16','Lockheed Martin'); INSERT INTO equipment (id,equipment_type,manufacturer) VALUES (2,'F-35','Lockheed Martin'); INSERT INTO equipment (id,equipment_type,manufacturer) VALUES (3,'C-130','Lockheed Martin'); INSERT INTO maintenance (id,equipment_id,maintenance_date) VALUES (1,1,'2022-01-01'); INSERT INTO maintenance (id,equipment_id,maintenance_date) VALUES (2,1,'2022-04-01'); INSERT INTO maintenance (id,equipment_id,maintenance_date) VALUES (3,2,'2022-02-01'); INSERT INTO maintenance (id,equipment_id,maintenance_date) VALUES (4,2,'2022-05-01'); INSERT INTO maintenance (id,equipment_id,maintenance_date) VALUES (5,3,'2022-03-01'); | SELECT e.equipment_type, AVG(DATEDIFF(m2.maintenance_date, m1.maintenance_date)) as avg_maintenance_interval FROM equipment e JOIN maintenance m1 ON e.id = m1.equipment_id JOIN maintenance m2 ON e.id = m2.equipment_id AND m2.maintenance_date > m1.maintenance_date GROUP BY e.equipment_type; |
What is the total spent on defense contracts in Q2 2021 by companies with 'Defense' in their name? | CREATE TABLE ContractData (company TEXT,contract_date DATE,contract_value FLOAT); INSERT INTO ContractData (company,contract_date,contract_value) VALUES ('Defense Co A','2021-04-01',1000000),('Defense Co B','2021-05-15',1500000),('NonDefense Co','2021-04-30',500000); | SELECT SUM(contract_value) FROM ContractData WHERE company LIKE '%Defense%' AND contract_date BETWEEN '2021-04-01' AND '2021-06-30'; |
Delete records of soldiers who left the army before 2015-01-01 from the soldiers_personal_data table | CREATE TABLE soldiers_personal_data (soldier_id INT,name VARCHAR(50),rank VARCHAR(50),departure_date DATE); | DELETE FROM soldiers_personal_data WHERE departure_date < '2015-01-01'; |
Insert a new peacekeeping operation named 'Abyei' in South Sudan with operation ID 101, starting from 2022-01-01 | CREATE TABLE peacekeeping_operations (operation_id INT,operation_name VARCHAR(255),start_date DATE,end_date DATE,operation_region VARCHAR(255)); | INSERT INTO peacekeeping_operations (operation_id, operation_name, start_date, end_date, operation_region) VALUES (101, 'Abyei', '2022-01-01', NULL, 'South Sudan'); |
Find the total transaction amount for each customer in the past month, grouped by week? | CREATE TABLE transactions (transaction_date DATE,customer_id INT,amount DECIMAL(10,2)); INSERT INTO transactions (transaction_date,customer_id,amount) VALUES ('2022-01-01',1,100),('2022-01-05',1,200),('2022-01-02',2,150),('2022-01-03',2,50),('2022-01-04',3,300),('2022-01-05',3,250),('2022-01-10',1,50),('2022-01-15',2,350),('2022-01-20',3,400); | SELECT EXTRACT(WEEK FROM transaction_date) AS week, customer_id, SUM(amount) AS total_amount FROM transactions WHERE transaction_date >= CURRENT_DATE - INTERVAL '1 month' GROUP BY week, customer_id ORDER BY week, customer_id; |
How many high-risk transactions occurred in the 'EMEA' region in the last quarter? | CREATE TABLE transactions (id INT,customer_id INT,region VARCHAR(50),transaction_amount DECIMAL(10,2),transaction_date DATE); INSERT INTO transactions (id,customer_id,region,transaction_amount,transaction_date) VALUES (1,1,'EMEA',5000.00,'2021-01-05'); INSERT INTO transactions (id,customer_id,region,transaction_amount,transaction_date) VALUES (2,2,'APAC',3000.00,'2021-02-10'); | SELECT COUNT(*) FROM transactions WHERE region = 'EMEA' AND transaction_date >= '2021-01-01' AND transaction_date <= '2021-03-31'; |
What are the unique circular economy initiatives in factories located in each continent? | CREATE TABLE factories (factory_id INT,name TEXT,location TEXT); CREATE TABLE initiatives (initiative_id INT,factory_id INT,description TEXT,circular_economy BOOLEAN); INSERT INTO factories (factory_id,name,location) VALUES (1,'Factory A','City A,Asia'),(2,'Factory B','City B,Africa'),(3,'Factory C','City C,Europe'),(4,'Factory D','City D,North America'),(5,'Factory E','City E,South America'),(6,'Factory F','City F,Australia'); INSERT INTO initiatives (initiative_id,factory_id,description,circular_economy) VALUES (1,1,'Recycling program',true),(2,2,'Reuse program',true),(3,3,'Waste reduction program',true),(4,4,'Composting program',true),(5,5,'Donation program',true),(6,6,'Upcycling program',true); | SELECT f.location, i.description FROM factories f JOIN initiatives i ON f.factory_id = i.factory_id WHERE i.circular_economy = true GROUP BY f.location, i.description; |
Add a column for 'Era' to the Sites table. | CREATE TABLE Sites (SiteID INT PRIMARY KEY,SiteName TEXT,Location TEXT,StartDate DATE,EndDate DATE); | ALTER TABLE Sites ADD Era TEXT; |
How many artifacts were found in each excavation site? | CREATE TABLE Excavation_Sites (Site_ID INT,Site_Name TEXT,Country TEXT,Number_of_Artifacts INT);INSERT INTO Excavation_Sites (Site_ID,Site_Name,Country,Number_of_Artifacts) VALUES (1,'Pompeii','Italy',10000);INSERT INTO Excavation_Sites (Site_ID,Site_Name,Country,Number_of_Artifacts) VALUES (2,'Tutankhamun','Egypt',5000);INSERT INTO Excavation_Sites (Site_ID,Site_Name,Country,Number_of_Artifacts) VALUES (3,'Machu Picchu','Peru',3000);INSERT INTO Excavation_Sites (Site_ID,Site_Name,Country,Number_of_Artifacts) VALUES (4,'Angkor Wat','Cambodia',2500);INSERT INTO Excavation_Sites (Site_ID,Site_Name,Country,Number_of_Artifacts) VALUES (5,'Teotihuacan','Mexico',2001); | SELECT Site_ID, Site_Name, SUM(Number_of_Artifacts) FROM Excavation_Sites GROUP BY Site_ID, Site_Name; |
How many unique artifact types are present at each excavation site? | CREATE TABLE ExcavationSite (SiteID INT,SiteName VARCHAR(50)); INSERT INTO ExcavationSite (SiteID,SiteName) VALUES (1,'Site A'),(2,'Site B'),(3,'Site C'); CREATE TABLE Artifact (ArtifactID INT,SiteID INT,ObjectType VARCHAR(50)); INSERT INTO Artifact (ArtifactID,SiteID,ObjectType) VALUES (1,1,'Pottery'),(2,1,'Tool'),(3,2,'Statue'),(4,2,'Bead'),(5,3,'Bead'),(6,3,'Jewelry'),(7,3,'Bead'); | SELECT e.SiteName, COUNT(DISTINCT a.ObjectType) AS UniqueArtifactTypes FROM ExcavationSite e JOIN Artifact a ON e.SiteID = a.SiteID GROUP BY e.SiteName; |
How many beds are available in all rural hospitals? | CREATE TABLE rural_hospitals(hospital_id INT PRIMARY KEY,name VARCHAR(255),bed_count INT,rural_population_served INT); | SELECT SUM(bed_count) FROM rural_hospitals; |
How many streams were there for each artist in the first quarter of 2019? | CREATE TABLE artists (artist_id INT,artist_name VARCHAR(30)); INSERT INTO artists (artist_id,artist_name) VALUES (1,'Ariana Grande'),(2,'BTS'),(3,'Drake'),(4,'Ed Sheeran'),(5,'Taylor Swift'); CREATE TABLE streams (stream_id INT,artist_id INT,revenue DECIMAL(10,2),stream_date DATE); INSERT INTO streams (stream_id,artist_id,revenue,stream_date) VALUES (1,1,10.50,'2019-03-15'),(2,1,12.25,'2019-07-27'),(3,2,9.99,'2019-09-01'),(4,3,15.00,'2019-11-29'),(5,1,8.75,'2019-12-31'),(6,2,11.25,'2019-05-14'),(7,3,7.50,'2019-01-02'),(8,4,9.50,'2019-03-05'),(9,5,12.00,'2019-01-10'),(10,1,10.00,'2019-01-15'); | SELECT artists.artist_name, COUNT(streams.stream_id) AS total_streams FROM artists INNER JOIN streams ON artists.artist_id = streams.artist_id WHERE streams.stream_date BETWEEN '2019-01-01' AND '2019-03-31' GROUP BY artists.artist_name; |
What is the total amount donated by each organization in the last six months? | CREATE TABLE Donations (id INT,organization TEXT,donation_amount FLOAT,donation_date DATE); INSERT INTO Donations (id,organization,donation_amount,donation_date) VALUES (1,'Code for Change',2000,'2022-03-22'); | SELECT organization, SUM(donation_amount) as total_donation FROM Donations WHERE donation_date >= DATEADD(month, -6, GETDATE()) GROUP BY organization; |
What is the total number of volunteers who engaged in programs in the first half of 2019, and the total amount donated in that time period? | CREATE TABLE Donors (DonorID INT,Name TEXT,TotalDonation DECIMAL(10,2),DonationDate DATE); CREATE TABLE Volunteers (VolunteerID INT,Name TEXT,ProgramID INT,VolunteerDate DATE); CREATE TABLE Programs (ProgramID INT,ProgramName TEXT); INSERT INTO Donors VALUES (1,'John Doe',5000.00,'2019-01-01'),(2,'Jane Smith',3000.00,'2019-06-01'); INSERT INTO Volunteers VALUES (1,'Alice',1,'2019-01-01'),(2,'Bob',1,'2019-06-01'),(3,'Charlie',2,'2019-06-01'); INSERT INTO Programs VALUES (1,'Education'),(2,'Environment'); | SELECT COUNT(DISTINCT V.VolunteerID) as NumVolunteers, SUM(D.TotalDonation) as TotalDonated FROM Donors D INNER JOIN Volunteers V ON D.DonationDate = V.VolunteerDate WHERE YEAR(V.VolunteerDate) = 2019 AND MONTH(V.VolunteerDate) <= 6; |
Who were the top 3 volunteer programs by total hours in 2023? | CREATE TABLE VolunteerPrograms (ProgramID int,ProgramName varchar(255),VolunteerHours int); INSERT INTO VolunteerPrograms VALUES (1,'Education',1500),(2,'Healthcare',2000),(3,'Environment',1200),(4,'Arts & Culture',1750),(5,'Social Services',2200); | SELECT ProgramName FROM (SELECT ProgramName, ROW_NUMBER() OVER (ORDER BY VolunteerHours DESC) as Rank FROM VolunteerPrograms) as ProgramRanks WHERE Rank <= 3; |
List the names of students who have never taken a lifelong learning course. | CREATE TABLE student_lifelong_learning (student_id INT,course_id INT); INSERT INTO student_lifelong_learning (student_id,course_id) VALUES (1,1),(2,NULL),(3,2),(4,NULL); | SELECT student_id FROM student_lifelong_learning WHERE course_id IS NULL; |
Calculate the percentage of employees who received a promotion in the last 12 months, and display the result with one decimal place. | CREATE TABLE Employees (EmployeeID INT,PromotionDate DATE); | SELECT ROUND(COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Employees) , 1) AS PromotionPercentage FROM Employees WHERE PromotionDate >= DATEADD(year, -1, GETDATE()); |
Delete records in the 'renewable' table where type is not 'wind' or 'solar' | CREATE TABLE renewable (id INT PRIMARY KEY,type VARCHAR(20),capacity FLOAT); INSERT INTO renewable (id,type,capacity) VALUES (1,'wind',300.2),(2,'solar',400.5),(3,'hydro',500.3),(4,'geothermal',600.4); | WITH cte AS (DELETE FROM renewable WHERE type NOT IN ('wind', 'solar')) DELETE FROM cte; |
Calculate the total number of exploration activities for each platform, indicating which platforms have more than 2 activities | CREATE TABLE platform_activities (activity_id INT,platform_id INT,activity_type VARCHAR(255)); INSERT INTO platform_activities (activity_id,platform_id,activity_type) VALUES (1,1,'Drilling'),(2,1,'Maintenance'),(3,2,'Drilling'),(4,3,'Drilling'),(5,3,'Maintenance'),(6,3,'Seismic'); | SELECT p.platform_id, p.platform_name, COUNT(pa.activity_id) as num_activities FROM platforms p INNER JOIN platform_activities pa ON p.platform_id = pa.platform_id GROUP BY p.platform_id HAVING num_activities > 2; |
List the names and production quantities of wells in the Permian Basin, along with the names of the fields they belong to | CREATE TABLE Well (WellID int,WellName varchar(50),FieldID int); CREATE TABLE Field (FieldID int,FieldName varchar(50),Location varchar(50)); | SELECT Well.WellName, Well.FieldID, Field.FieldName, Well.ProductionQuantity FROM Well INNER JOIN Field ON Well.FieldID = Field.FieldID WHERE Field.Location = 'Permian Basin'; |
List the top 3 teams with the highest number of wins in the 2021 season. | CREATE TABLE nba_teams (team_id INT,team_name VARCHAR(255),wins INT); INSERT INTO nba_teams (team_id,team_name,wins) VALUES (1,'Atlanta Hawks',41),(2,'Boston Celtics',36),(3,'Brooklyn Nets',48),(4,'Charlotte Hornets',33); | SELECT team_name, wins FROM nba_teams ORDER BY wins DESC LIMIT 3; |
What is the average time each athlete spent in the swimming pool during the Olympics? | CREATE TABLE olympic_swimming (athlete VARCHAR(50),time_in_pool INT); INSERT INTO olympic_swimming (athlete,time_in_pool) VALUES ('Michael Phelps',1500),('Katie Ledecky',1600),('Sun Yang',1700); | SELECT AVG(time_in_pool) AS avg_time FROM olympic_swimming; |
List the number of community development projects and their total budget for each region. | CREATE TABLE regions (id INT,name VARCHAR(255)); CREATE TABLE projects (id INT,region_id INT,name VARCHAR(255),budget FLOAT); | SELECT r.name as region_name, COUNT(projects.id) as project_count, SUM(projects.budget) as total_budget FROM regions r LEFT JOIN projects ON r.id = projects.region_id GROUP BY r.id; |
List the number of unique donors and total amount donated for each disaster response, including donors who have donated to multiple disasters. | CREATE TABLE donors (id INT,disaster_id INT,amount FLOAT); CREATE TABLE disasters (id INT,name VARCHAR(255)); | SELECT d.name, COUNT(DISTINCT donors.id) as donor_count, SUM(donors.amount) as total_donated FROM disasters d LEFT JOIN donors ON d.id = donors.disaster_id GROUP BY d.id; |
How many wheelchair accessible vehicles are there in the London bus fleet? | CREATE TABLE bus_fleet (vehicle_id INT,type VARCHAR(20),is_wheelchair_accessible BOOLEAN); INSERT INTO bus_fleet (vehicle_id,type,is_wheelchair_accessible) VALUES (1,'Double Decker',true),(2,'Single Decker',false),(3,'Minibus',true); | SELECT COUNT(*) FROM bus_fleet WHERE is_wheelchair_accessible = true; |
Identify the most common pick-up and drop-off times for taxi trips | CREATE TABLE taxi_trip (trip_id INT,pickup_time TIMESTAMP,dropoff_time TIMESTAMP); | SELECT TIME(pickup_time) AS most_common_pickup, TIME(dropoff_time) AS most_common_dropoff, COUNT(*) AS trip_count FROM taxi_trip GROUP BY pickup_time, dropoff_time ORDER BY trip_count DESC LIMIT 1; |
What is the average fare for each route in the 'routes' table? | CREATE TABLE routes (route_id INT,route_name VARCHAR(255),length FLOAT,fare FLOAT); | SELECT route_name, AVG(fare) as avg_fare FROM routes GROUP BY route_name; |
Delete records in the consumer_awareness table where the region is 'South America' and awareness_score is less than 6 | CREATE TABLE consumer_awareness (id INT PRIMARY KEY,consumer_id INT,region VARCHAR(255),awareness_score INT); INSERT INTO consumer_awareness (id,consumer_id,region,awareness_score) VALUES (1,1001,'Asia Pacific',6),(2,1002,'Europe',7),(3,1003,'Asia Pacific',4),(4,1004,'Americas',8),(5,1005,'South America',5),(6,1006,'South America',4); | DELETE FROM consumer_awareness WHERE region = 'South America' AND awareness_score < 6; |
List all suppliers located in France that provide recycled materials. | CREATE TABLE Suppliers (id INT,name TEXT,country TEXT); INSERT INTO Suppliers VALUES (1,'Supplier1','France'),(2,'Supplier2','Germany'),(3,'Supplier3','Italy'); CREATE TABLE RecycledMaterials (id INT,supplier_id INT,material TEXT); INSERT INTO RecycledMaterials VALUES (1,1,'RecycledPolyester'),(2,3,'RecycledPlastic'),(3,1,'RecycledPaper'); | SELECT s.name FROM Suppliers s INNER JOIN RecycledMaterials rm ON s.id = rm.supplier_id WHERE s.country = 'France'; |
What is the name of the factory with the lowest number of fair trade certified products? | CREATE TABLE Factory_Products(id INT,factory_id INT,product_id INT,is_fair_trade_certified BOOLEAN); INSERT INTO Factory_Products(id,factory_id,product_id,is_fair_trade_certified) VALUES (1,1,1,true),(2,1,2,true),(3,2,3,false); CREATE TABLE Factories(id INT,name TEXT); INSERT INTO Factories(id,name) VALUES (1,'Factory A'),(2,'Factory B'); | SELECT Factories.name FROM Factories INNER JOIN (SELECT factory_id, COUNT(*) as product_count FROM Factory_Products WHERE is_fair_trade_certified = true GROUP BY factory_id) AS Subquery ON Factories.id = Subquery.factory_id ORDER BY Subquery.product_count ASC LIMIT 1; |
How many new users joined from each country in the past week? | CREATE TABLE user_registrations (user_id INT,country VARCHAR(50),registration_date DATE); INSERT INTO user_registrations (user_id,country,registration_date) VALUES (1,'USA','2022-01-01'),(2,'Canada','2022-01-02'),(3,'Mexico','2022-01-03'),(4,'Brazil','2022-01-04'),(5,'Argentina','2022-01-05'); | SELECT country, COUNT(DISTINCT user_id) AS new_users FROM user_registrations WHERE registration_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK) GROUP BY country; |
Show the top 3 content categories in Japan with the most posts. | CREATE TABLE content_categories (id INT,content_category VARCHAR(255)); CREATE TABLE posts_extended (id INT,content_category_id INT,content TEXT,country VARCHAR(255)); INSERT INTO content_categories (id,content_category) VALUES (1,'AI'),(2,'Data Science'),(3,'Machine Learning'); INSERT INTO posts_extended (id,content_category_id,content,country) VALUES (1,1,'Hello','Japan'),(2,1,'World','Japan'),(3,2,'AI','Japan'); | SELECT content_categories.content_category, COUNT(posts_extended.id) AS post_count FROM content_categories JOIN posts_extended ON posts_extended.content_category_id = content_categories.id WHERE posts_extended.country = 'Japan' GROUP BY content_categories.content_category ORDER BY post_count DESC LIMIT 3; |
What is the sum of sales revenue from 'Men's' garments in 'Canada'? | CREATE TABLE canada_sales_revenue (id INT,garment_type VARCHAR(20),revenue INT);INSERT INTO canada_sales_revenue (id,garment_type,revenue) VALUES (1,'Men''s',25000),(2,'Men''s',30000),(3,'Women''s',40000); | SELECT SUM(revenue) FROM canada_sales_revenue WHERE garment_type = 'Men''s'; |
List all the clients from the Socially Responsible Microfinance program and their account balances. | CREATE TABLE microfinance_program (client_id INT,program_name VARCHAR(30),account_balance DECIMAL(10,2)); INSERT INTO microfinance_program (client_id,program_name,account_balance) VALUES (101,'Socially Responsible Microfinance',5000.00),(102,'Conventional Microfinance',7000.00),(103,'Socially Responsible Microfinance',3000.00); | SELECT * FROM microfinance_program WHERE program_name = 'Socially Responsible Microfinance'; |
What is the total amount of interest earned from socially responsible lending? | CREATE TABLE socially_responsible_loans(id INT,bank_id INT,amount INT,interest_rate DECIMAL); | SELECT SUM(s.amount * s.interest_rate) FROM socially_responsible_loans s; |
Identify the warehouse in Colombia that handled the maximum number of pallets in a day. | CREATE TABLE warehouse_stats (id INT,warehouse_country VARCHAR(20),warehouse_city VARCHAR(20),pallets INT,handling_date DATE); INSERT INTO warehouse_stats (id,warehouse_country,warehouse_city,pallets,handling_date) VALUES (1,'Colombia','Bogota',42,'2022-07-02'),(2,'Colombia','Medellin',48,'2022-07-05'); | SELECT warehouse_city, MAX(pallets) FROM warehouse_stats WHERE warehouse_country = 'Colombia' GROUP BY warehouse_city; |
How many bioprocess engineering projects are in Eastern Europe? | CREATE SCHEMA if not exists bioprocessing;CREATE TABLE if not exists bioprocessing.projects (id INT PRIMARY KEY,name VARCHAR(100),region VARCHAR(100)); INSERT INTO bioprocessing.projects (id,name,region) VALUES (1,'ProjA','Warsaw'),(2,'ProjB','Moscow'),(3,'ProjC','Prague'),(4,'ProjD','Bucharest'),(5,'ProjE','Kiev'); | SELECT COUNT(*) FROM bioprocessing.projects WHERE region = 'Eastern Europe'; |
How many genetic research projects are being conducted in the UK? | CREATE SCHEMA if not exists genetics;CREATE TABLE if not exists genetics.research_projects (id INT,name TEXT,location TEXT,type TEXT); INSERT INTO genetics.research_projects (id,name,location,type) VALUES (1,'ProjectA','UK','Genetic'),(2,'ProjectB','US','Genomic'),(3,'ProjectC','UK','Genetic'),(4,'ProjectD','DE','Genomic'); | SELECT COUNT(*) FROM genetics.research_projects WHERE location = 'UK' AND type = 'Genetic'; |
What is the total number of female researchers in each department? | CREATE TABLE department (id INT,name VARCHAR(255)); CREATE TABLE researcher (id INT,name VARCHAR(255),gender VARCHAR(10),department_id INT); | SELECT department.name, COUNT(researcher.id) FROM department INNER JOIN researcher ON department.id = researcher.department_id WHERE researcher.gender = 'Female' GROUP BY department.name; |
What is the total installed capacity (in MW) of renewable energy projects in the 'renewable_projects' table? | CREATE TABLE if not exists renewable_projects (project_id INT,project_name VARCHAR(255),location VARCHAR(255),installed_capacity FLOAT); | SELECT SUM(installed_capacity) FROM renewable_projects WHERE installed_capacity IS NOT NULL; |
How many unique patients have been treated for mental health conditions by providers in each region? | CREATE TABLE regions (region_id INT,region_name VARCHAR(50)); INSERT INTO regions (region_id,region_name) VALUES (1,'Northeast'),(2,'Southeast'),(3,'Midwest'),(4,'Southwest'),(5,'West'); CREATE TABLE providers (provider_id INT,provider_name VARCHAR(50),region_id INT); INSERT INTO providers (provider_id,provider_name,region_id) VALUES (1,'Dr. Smith',1),(2,'Dr. Johnson',2); CREATE TABLE provider_patients (provider_id INT,patient_id INT,condition_id INT); | SELECT p.region_id, COUNT(DISTINCT pp.patient_id) as num_patients FROM providers p JOIN provider_patients pp ON p.provider_id = pp.provider_id GROUP BY p.region_id; |
What is the revenue for each online travel agency in Europe, ordered by revenue in descending order? | CREATE TABLE otas (ota_id INT,ota_name TEXT,region TEXT,revenue FLOAT); INSERT INTO otas (ota_id,ota_name,region,revenue) VALUES (1,'OTA A','Europe',850000),(2,'OTA B','Europe',950000),(3,'OTA C','Asia',1200000); | SELECT ota_name, revenue FROM otas WHERE region = 'Europe' ORDER BY revenue DESC; |
What is the total revenue generated by 'OTAs' in '2022'? | CREATE TABLE otas (id INT,ota_name TEXT,revenue INT); INSERT INTO otas (id,ota_name,revenue) VALUES (1,'Expedia',500000),(2,'Booking.com',600000),(3,'Priceline',400000); | SELECT SUM(revenue) FROM otas WHERE EXTRACT(YEAR FROM CURRENT_DATE) = 2022; |
What is the average temperature recorded for the 'polar_bear' species in the 'Arctic_Animals' table compared to the 'penguin' species in the 'Antarctic_Animals' table? | CREATE TABLE Arctic_Animals (species TEXT,avg_temp FLOAT); CREATE TABLE Antarctic_Animals (species TEXT,avg_temp FLOAT); | SELECT AVG(Arctic_Animals.avg_temp) FROM Arctic_Animals WHERE Arctic_Animals.species = 'polar_bear' INTERSECT SELECT AVG(Antarctic_Animals.avg_temp) FROM Antarctic_Animals WHERE Antarctic_Animals.species = 'penguin' |
What is the minimum temperature recorded in each Arctic region in 2020? | CREATE TABLE WeatherData(region VARCHAR(255),year INT,temperature FLOAT); | SELECT region, MIN(temperature) FROM WeatherData WHERE year = 2020 GROUP BY region; |
How many patients have been treated with CBT or DBT? | CREATE TABLE treatments (patient_id INT,treatment VARCHAR(20)); INSERT INTO treatments (patient_id,treatment) VALUES (1,'CBT'),(2,'DBT'),(3,'Medication'),(4,'CBT'),(5,'DBT'); | SELECT COUNT(*) FROM treatments WHERE treatment IN ('CBT', 'DBT'); |
What is the total number of subway stations in the city of Berlin, Germany? | CREATE TABLE stations (id INT,name VARCHAR(255),location VARCHAR(255),type VARCHAR(255)); INSERT INTO stations (id,name,location,type) VALUES (1,'Alexanderplatz','Berlin,Germany','Subway'),(2,'Potsdamer Platz','Berlin,Germany','Subway'); | SELECT COUNT(*) FROM stations WHERE location = 'Berlin, Germany' AND type = 'Subway'; |
Provide the number of tourists visiting New Zealand, Australia, and Japan from 2018 to 2020 | CREATE TABLE TouristArrivals (country VARCHAR(255),year INT,tourists_count INT); INSERT INTO TouristArrivals (country,year,tourists_count) VALUES ('New Zealand',2018,3500000),('New Zealand',2019,3700000),('New Zealand',2020,1200000),('Australia',2018,9000000),('Australia',2019,9500000),('Australia',2020,2500000),('Japan',2018,31000000),('Japan',2019,32000000),('Japan',2020,8000000); | SELECT country, AVG(tourists_count) as avg_tourists FROM TouristArrivals WHERE country IN ('New Zealand', 'Australia', 'Japan') AND year BETWEEN 2018 AND 2020 GROUP BY country; |
What is the number of travel advisories issued for each country in the last 3 months? | CREATE TABLE TravelAdvisories (Country VARCHAR(255),Advisory INT,IssueDate DATE); | SELECT Country, COUNT(Advisory) OVER (PARTITION BY Country) AS NumAdvisories, TO_CHAR(IssueDate, 'YYYY-MM') AS Month FROM TravelAdvisories WHERE IssueDate >= ADD_MONTHS(CURRENT_DATE, -3) GROUP BY Country, Month; |
What is the location of the restorative justice program with the lowest ID in the 'justice_programs' table? | CREATE TABLE justice_programs (id INT,name VARCHAR(50),type VARCHAR(30),location VARCHAR(30)); INSERT INTO justice_programs (id,name,type,location) VALUES (1,'Mediation Center','Restorative Justice','San Francisco'); INSERT INTO justice_programs (id,name,type,location) VALUES (2,'Victim-Offender Reconciliation Program','Restorative Justice','Oakland'); INSERT INTO justice_programs (id,name,type,location) VALUES (3,'Restorative Circle Facilitator Training','Restorative Justice','Los Angeles'); | SELECT location FROM justice_programs WHERE id = (SELECT MIN(id) FROM justice_programs WHERE type = 'Restorative Justice'); |
List all ocean floor mapping projects in the Arctic region. | CREATE SCHEMA oceans;CREATE TABLE oceans.mapping_projects (id INT PRIMARY KEY,project_name VARCHAR(50),region VARCHAR(50)); INSERT INTO oceans.mapping_projects (id,project_name,region) VALUES (1,'Project A','Arctic'),(2,'Project B','Antarctic'); | SELECT context.project_name FROM oceans.mapping_projects AS context WHERE context.region = 'Arctic'; |
Delete customer feedback with ID 2 | CREATE TABLE customer_feedback (id INT PRIMARY KEY,customer_id INT,menu_id INT,feedback VARCHAR(255)); INSERT INTO customer_feedback (id,customer_id,menu_id,feedback) VALUES (1,1,1,'Loved it!'),(2,2,2,'Did not like it.'); | DELETE FROM customer_feedback WHERE id = 2; |
What is the average price of sustainable seafood items? | CREATE TABLE menu (item_id INT,item_name TEXT,type TEXT,price DECIMAL,is_sustainable BOOLEAN); INSERT INTO menu VALUES (1,'Tuna Sandwich','Seafood',8.99,true),(2,'Shrimp Cocktail','Seafood',7.99,false),(3,'Sustainable Salmon','Seafood',12.99,true); | SELECT AVG(price) FROM menu WHERE type = 'Seafood' AND is_sustainable = true; |
What is the average price of vegan breakfast menu items? | CREATE TABLE menus (menu_id INT,menu_name VARCHAR(255),category VARCHAR(255),price DECIMAL(10,2),is_vegan BOOLEAN); INSERT INTO menus (menu_id,menu_name,category,price,is_vegan) VALUES (1,'Quinoa Salad','Lunch',12.99,FALSE),(2,'Vegan Scramble','Breakfast',7.99,TRUE),(3,'Cheeseburger','Dinner',9.99,FALSE); | SELECT AVG(price) FROM menus WHERE category = 'Breakfast' AND is_vegan = TRUE; |
How many environmental impact assessments were conducted per year, for the last 5 years? | CREATE TABLE eia (id INT,year INT,assessment_count INT); INSERT INTO eia (id,year,assessment_count) VALUES (1,2017,300),(2,2018,350),(3,2019,400),(4,2020,450),(5,2021,500); | SELECT year, assessment_count FROM eia WHERE year BETWEEN 2017 AND 2021 ORDER BY year; |
Which country has the lowest total production of nickel, Indonesia or the Philippines? | CREATE TABLE nickel_production (country VARCHAR(20),quantity INT); INSERT INTO nickel_production (country,quantity) VALUES ('Indonesia',700000),('Philippines',650000); | SELECT country, MIN(quantity) FROM nickel_production WHERE country IN ('Indonesia', 'Philippines') GROUP BY country; |
List all players who have played a specific VR game, 'CyberSphere', and their ages. | CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),Country VARCHAR(50)); CREATE TABLE VRPlayers (PlayerID INT,VRGameID INT); CREATE TABLE VRGames (VRGameID INT,Title VARCHAR(50)); INSERT INTO Players (PlayerID,Age,Gender,Country) VALUES (1,25,'Male','USA'); INSERT INTO Players (PlayerID,Age,Gender,Country) VALUES (2,28,'Female','Canada'); INSERT INTO VRPlayers (PlayerID,VRGameID) VALUES (1,1); INSERT INTO VRPlayers (PlayerID,VRGameID) VALUES (2,1); INSERT INTO VRGames (VRGameID,Title) VALUES (1,'CyberSphere'); | SELECT Players.Age, Players.PlayerID FROM Players INNER JOIN VRPlayers ON Players.PlayerID = VRPlayers.PlayerID INNER JOIN VRGames ON VRPlayers.VRGameID = VRGames.VRGameID WHERE VRGames.Title = 'CyberSphere'; |
What is the total number of players who have played the game 'Adventure' or are from the USA? | CREATE TABLE PlayerGameData (PlayerID INT,Age INT,Game VARCHAR(20),Country VARCHAR(20)); INSERT INTO PlayerGameData (PlayerID,Age,Game,Country) VALUES (1,22,'Adventure','Canada'),(2,25,'Shooter','USA'),(3,28,'Adventure','USA'); | SELECT COUNT(DISTINCT PlayerID) FROM PlayerGameData WHERE Game = 'Adventure' OR Country = 'USA'; |
Find the average temperature in field A for the month of June, 2021. | CREATE TABLE field_temperatures (field_id VARCHAR(10),temperature INT,reading_date DATE); INSERT INTO field_temperatures (field_id,temperature,reading_date) VALUES ('A',25,'2021-06-01'),('A',28,'2021-06-02'),('A',22,'2021-06-03'); | SELECT AVG(temperature) FROM field_temperatures WHERE field_id = 'A' AND reading_date BETWEEN '2021-06-01' AND '2021-06-30'; |
What is the total number of police stations and fire stations in each region? | CREATE SCHEMA gov_service;CREATE TABLE gov_service.safety_data (region VARCHAR(20),facility_type VARCHAR(20),facility_count INT); INSERT INTO gov_service.safety_data (region,facility_type,facility_count) VALUES ('North','Police Station',10),('North','Fire Station',5),('South','Police Station',12),('South','Fire Station',6),('East','Police Station',8),('East','Fire Station',4),('West','Police Station',7),('West','Fire Station',3); | SELECT region, SUM(facility_count) AS total_stations FROM gov_service.safety_data GROUP BY region; |
List the number of properties co-owned by women and men in each city in the database. | CREATE TABLE city_properties (city VARCHAR(50),co_owned BOOLEAN,owner_gender VARCHAR(10),property_id INT); | SELECT city, owner_gender, COUNT(*) AS count FROM city_properties WHERE co_owned = TRUE GROUP BY city, owner_gender; |
What is the average area of sustainable urban properties in the state of New York, broken down by property type? | CREATE TABLE sustainable_urban_properties (id INT,state VARCHAR(255),property_type VARCHAR(255),area FLOAT); INSERT INTO sustainable_urban_properties (id,state,property_type,area) VALUES (1,'New York','Apartment',1000.00),(2,'New York','Condo',1200.00); | SELECT property_type, AVG(area) FROM sustainable_urban_properties WHERE state = 'New York' GROUP BY property_type; |
What is the maximum size of a property in the city of Austin? | CREATE TABLE properties (id INT,property_id INT,city TEXT,size INT); INSERT INTO properties (id,property_id,city,size) VALUES (1,101,'Austin',1200),(2,102,'Seattle',900),(3,103,'Austin',1500); | SELECT MAX(size) FROM properties WHERE city = 'Austin'; |
Find the average energy efficiency rating of buildings in the top 3 most populous cities in Canada. | CREATE TABLE buildings (city_name VARCHAR(255),population INT,energy_efficiency_rating FLOAT); INSERT INTO buildings (city_name,population,energy_efficiency_rating) VALUES ('Toronto',2900000,75),('Montreal',1700000,70),('Vancouver',650000,80),('Calgary',1200000,65),('Edmonton',950000,60); | SELECT AVG(energy_efficiency_rating) as avg_rating FROM buildings WHERE population IN (SELECT population FROM (SELECT city_name, population FROM buildings WHERE city_name IN ('Toronto', 'Montreal', 'Vancouver') ORDER BY population DESC LIMIT 3) as subquery); |
What are the names and prices of the menu items that have the same name as a restaurant? | CREATE TABLE restaurants (restaurant_id INT,name VARCHAR(255),cuisine VARCHAR(255)); INSERT INTO restaurants (restaurant_id,name,cuisine) VALUES (1,'Big Burger','American'); INSERT INTO restaurants (restaurant_id,name,cuisine) VALUES (2,'Sushi Hana','Japanese'); CREATE TABLE menu_items (menu_item_id INT,name VARCHAR(255),price DECIMAL(5,2),restaurant_id INT); INSERT INTO menu_items (menu_item_id,name,price,restaurant_id) VALUES (1,'Big Burger',12.99,1); INSERT INTO menu_items (menu_item_id,name,price,restaurant_id) VALUES (2,'Chicken Teriyaki',15.99,2); INSERT INTO menu_items (menu_item_id,name,price,restaurant_id) VALUES (3,'Garden Salad',7.99,1); | SELECT name, price FROM menu_items WHERE name IN (SELECT name FROM restaurants); |
What is the average price of organic products sold by vendors in the US? | CREATE TABLE vendors (vendor_id INT,vendor_name TEXT,country TEXT);CREATE TABLE products (product_id INT,product_name TEXT,price DECIMAL,organic BOOLEAN,vendor_id INT); INSERT INTO vendors (vendor_id,vendor_name,country) VALUES (1,'VendorA','USA'),(2,'VendorB','Canada'); INSERT INTO products (product_id,product_name,price,organic,vendor_id) VALUES (1,'ProductX',15.99,true,1),(2,'ProductY',12.49,false,1),(3,'ProductZ',20.99,true,2); | SELECT AVG(price) FROM products JOIN vendors ON products.vendor_id = vendors.vendor_id WHERE organic = true AND country = 'USA'; |
What is the farthest distance from Earth for any spacecraft? | CREATE TABLE SpacecraftManufacturing (spacecraft_model VARCHAR(255),max_distance_from_earth FLOAT); INSERT INTO SpacecraftManufacturing (spacecraft_model,max_distance_from_earth) VALUES ('Voyager 1',21335000000),('Voyager 2',17950000000),('New Horizons',12350000000); | SELECT MAX(max_distance_from_earth) FROM SpacecraftManufacturing; |
What is the latest medical data point for astronaut 'R. Riley'? | CREATE TABLE AstronautMedicalData (id INT,astronaut VARCHAR(255),data_point FLOAT,timestamp DATETIME); INSERT INTO AstronautMedicalData (id,astronaut,data_point,timestamp) VALUES (1,'R. Riley',92.0,'2022-03-01 12:00:00'),(2,'R. Riley',93.0,'2022-03-01 13:00:00'); | SELECT MAX(data_point) FROM AstronautMedicalData WHERE astronaut = 'R. Riley'; |
How many fans in the "Toronto Raptors" fan club are from Canada? | CREATE TABLE fan_demographics(id INT,name VARCHAR(50),team VARCHAR(50),country VARCHAR(50));INSERT INTO fan_demographics(id,name,team,country) VALUES (1,'John Smith','Toronto Raptors','Canada'),(2,'Jane Doe','Toronto Raptors','Canada'),(3,'Bob Johnson','Toronto Raptors','USA'); | SELECT COUNT(*) FROM fan_demographics WHERE team = 'Toronto Raptors' AND country = 'Canada'; |
How many sports_events took place in '2018'? | CREATE TABLE sports_events (event_id INT,year INT,sport VARCHAR(20)); INSERT INTO sports_events (event_id,year,sport) VALUES (1,2017,'Football'),(2,2018,'Basketball'),(3,2018,'Baseball'); | SELECT COUNT(*) FROM sports_events WHERE year = 2018; |
List the top 10 most frequently exploited vulnerabilities in the past year and the number of times each vulnerability has been exploited. | CREATE TABLE vulnerabilities (id INT,cve_id VARCHAR(255),publish_date DATE,severity VARCHAR(255),exploited_count INT); INSERT INTO vulnerabilities (id,cve_id,publish_date,severity,exploited_count) VALUES (1,'CVE-2021-1234','2021-01-01','CRITICAL',20); | SELECT cve_id, exploited_count FROM vulnerabilities WHERE publish_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY cve_id ORDER BY exploited_count DESC LIMIT 10; |
What is the maximum, minimum, and average severity of vulnerabilities found in the 'Application' section for the last month? | CREATE TABLE vulnerabilities (id INT,section VARCHAR(50),severity INT,vulnerability_date DATE); INSERT INTO vulnerabilities (id,section,severity,vulnerability_date) VALUES (1,'Network',7,'2022-01-01'),(2,'Application',5,'2022-01-02'); | SELECT section, MIN(severity) as min_severity, MAX(severity) as max_severity, AVG(severity) as avg_severity FROM vulnerabilities WHERE section = 'Application' AND vulnerability_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY section; |
Display the total quantity of all transportation means in the total_inventory view. | CREATE VIEW total_inventory AS SELECT 'ebike' AS transportation_type,SUM(quantity) AS total FROM micro_mobility UNION ALL SELECT 'autonomous_bus',SUM(quantity) FROM public_transportation UNION ALL SELECT ev_type,SUM(quantity) FROM fleet_inventory WHERE ev_type IN ('electric_car','hybrid_car','electric_truck','hybrid_truck') GROUP BY ev_type; | SELECT SUM(total) FROM total_inventory; |
What is the average speed of electric buses in Mexico City, Mexico? | CREATE TABLE electric_buses (bus_id INT,speed FLOAT,city VARCHAR(50)); | SELECT AVG(speed) FROM electric_buses WHERE city = 'Mexico City'; |
Update the price to 25 in the products table for all records with category='Dress' | CREATE TABLE products (id INT,product_name VARCHAR(50),category VARCHAR(50),price DECIMAL(5,2)); | UPDATE products SET price = 25 WHERE category = 'Dress'; |
What are the names and production dates of garments made from fabrics with a sustainability score over 70, produced after 2021-01-01? | CREATE TABLE fabrics (id INT,name VARCHAR(50),type VARCHAR(50),sustainability_score INT); INSERT INTO fabrics (id,name,type,sustainability_score) VALUES (1,'Organic Linen','Natural',80); INSERT INTO fabrics (id,name,type,sustainability_score) VALUES (2,'Recycled Nylon','Synthetic',72); | SELECT garments.name, garments.production_date FROM garments JOIN fabrics ON garments.fabric_id = fabrics.id WHERE fabrics.sustainability_score > 70 AND garments.production_date > '2021-01-01'; |
Show the number of workplace safety incidents per month, for the past year, for workplaces with a union. | CREATE TABLE safety_incidents (id INT,workplace INT,incident_date DATE); INSERT INTO safety_incidents (id,workplace,incident_date) VALUES (1,1,'2022-06-15'); INSERT INTO safety_incidents (id,workplace,incident_date) VALUES (2,2,'2022-07-01'); INSERT INTO safety_incidents (id,workplace,incident_date) VALUES (3,1,'2022-08-10'); | SELECT DATE_FORMAT(incident_date, '%Y-%m') as month, COUNT(*) as num_incidents FROM safety_incidents si INNER JOIN workplaces w ON si.workplace = w.id WHERE w.union_affiliation IS NOT NULL GROUP BY month ORDER BY STR_TO_DATE(month, '%Y-%m'); |
Show the union names and their collective bargaining agreements that are located in the 'south_region'? | CREATE TABLE union_names (union_name TEXT); INSERT INTO union_names (union_name) VALUES ('Union A'),('Union B'),('Union C'),('Union D'); CREATE TABLE cb_agreements (union_name TEXT,region TEXT); INSERT INTO cb_agreements (union_name,region) VALUES ('Union A','west_region'),('Union B','south_region'),('Union C','north_region'),('Union D','south_region'); | SELECT union_names.union_name, cb_agreements.region FROM union_names INNER JOIN cb_agreements ON union_names.union_name = cb_agreements.union_name WHERE cb_agreements.region = 'south_region'; |
What is the total number of union membership applications submitted per month in 2021? | CREATE TABLE Applications (Id INT,ApplicationDate DATE); INSERT INTO Applications (Id,ApplicationDate) VALUES (1,'2021-01-01'),(2,'2021-02-15'),(3,'2021-03-05'),(4,'2021-04-20'); | SELECT MONTH(ApplicationDate) as Month, COUNT(*) as TotalApplications FROM Applications WHERE YEAR(ApplicationDate) = 2021 GROUP BY Month; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.