instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the total quantity of sustainable products in the products and inventory tables? | CREATE TABLE products (product_id INT,product_name TEXT,is_sustainable BOOLEAN); INSERT INTO products VALUES (1,'Eco Shirt',TRUE); INSERT INTO products VALUES (2,'Regular Shirt',FALSE); CREATE TABLE inventory (product_id INT,quantity INT); INSERT INTO inventory VALUES (1,100); INSERT INTO inventory VALUES (2,200); | SELECT SUM(quantity) FROM products INNER JOIN inventory ON products.product_id = inventory.product_id WHERE is_sustainable = TRUE; |
Show the names of startups that have had an acquisition exit event | CREATE TABLE startup (id INT,name TEXT,exit_event TEXT); INSERT INTO startup (id,name,exit_event) VALUES (1,'Acme Inc','Acquisition'); INSERT INTO startup (id,name,exit_event) VALUES (2,'Beta Corp',NULL); | SELECT name FROM startup WHERE exit_event = 'Acquisition'; |
What is the average size of co-owned properties in NYC? | CREATE TABLE co_ownership (property_id INT,size FLOAT,city VARCHAR(20)); INSERT INTO co_ownership (property_id,size,city) VALUES (1,1200.0,'Seattle'),(2,1500.0,'NYC'); | SELECT AVG(size) FROM co_ownership WHERE city = 'NYC'; |
What is the average attendance at events, in the past month, broken down by day of the week and genre? | CREATE TABLE Events (id INT,date DATE,genre VARCHAR(50),city VARCHAR(50),attendance INT); INSERT INTO Events (id,date,genre,city,attendance) VALUES (1,'2021-01-01','Classical','New York',100),(2,'2021-01-02','Rock','Los Angeles',200); | SELECT DATE_FORMAT(e.date, '%W') AS day_of_week, e.genre, AVG(e.attendance) AS avg_attendance FROM Events e WHERE e.date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY day_of_week, e.genre; |
What is the average viewership for TV shows by network? | CREATE TABLE TV_Shows_Viewership (id INT,title VARCHAR(100),network VARCHAR(50),avg_viewers DECIMAL(10,2)); INSERT INTO TV_Shows_Viewership (id,title,network,avg_viewers) VALUES (1,'The Simpsons','FOX',5000000.00),(2,'Game of Thrones','HBO',12000000.00),(3,'Friends','NBC',20000000.00); | SELECT network, AVG(avg_viewers) FROM TV_Shows_Viewership GROUP BY network; |
What is the total production volume for all plants? | CREATE TABLE chemical_plants (id INT,name TEXT,region TEXT,production_volume INT); INSERT INTO chemical_plants (id,name,region,production_volume) VALUES (1,'Plant A','Northeast',1200),(2,'Plant B','Midwest',900),(3,'Plant C','West',1300); | SELECT SUM(production_volume) FROM chemical_plants; |
Delete all records from the 'research' table where the 'research_type' is 'Bioinformatics' | CREATE TABLE research (id INT PRIMARY KEY,research_type VARCHAR(50),description TEXT,date DATE); | WITH cte1 AS (DELETE FROM research WHERE research_type = 'Bioinformatics') SELECT * FROM cte1; |
List all astronauts who have not flown after 2015 for SpaceCorp? | CREATE TABLE Astronauts (id INT,name VARCHAR(100),flights INT,last_flight DATE,agency VARCHAR(100)); INSERT INTO Astronauts (id,name,flights,last_flight,agency) VALUES (1,'Astronaut1',5,'2014-01-01','SpaceCorp'); INSERT INTO Astronauts (id,name,flights,last_flight,agency) VALUES (2,'Astronaut2',3,'2016-03-03','SpaceCorp'); | SELECT name, flights, last_flight FROM Astronauts WHERE agency = 'SpaceCorp' AND EXTRACT(YEAR FROM last_flight) < 2016; |
What is the name of the most popular artist in the 'music_streaming' table? | CREATE TABLE music_streaming (song_id INT,song_name TEXT,artist_name TEXT,plays INT); | SELECT artist_name, MAX(plays) FROM music_streaming GROUP BY artist_name; |
Delete garments with a rating below 3. | CREATE TABLE low_rated_garments AS SELECT * FROM garments WHERE rating < 3; | DELETE FROM garments WHERE id IN (SELECT garment_id FROM low_rated_garments); |
Which sport has the most number of fans? | CREATE TABLE sports (sport_id INT,sport_name VARCHAR(50)); CREATE TABLE fans (fan_id INT,fan_name VARCHAR(50),sport_id INT); | SELECT s.sport_name, COUNT(*) as fan_count FROM fans f JOIN sports s ON f.sport_id = s.sport_id GROUP BY s.sport_name ORDER BY fan_count DESC LIMIT 1; |
How many individuals with disabilities attended 'Accessible Arts' events in 2021? | CREATE TABLE EventAccessibility (event_name VARCHAR(50),event_year INT,attendee_disability BOOLEAN); INSERT INTO EventAccessibility (event_name,event_year,attendee_disability) VALUES ('Accessible Arts',2021,TRUE); INSERT INTO EventAccessibility (event_name,event_year,attendee_disability) VALUES ('Accessible Arts',2021,FALSE); INSERT INTO EventAccessibility (event_name,event_year,attendee_disability) VALUES ('Accessible Arts',2020,TRUE); | SELECT COUNT(*) FROM EventAccessibility WHERE event_name = 'Accessible Arts' AND event_year = 2021 AND attendee_disability = TRUE; |
Which investigative journalists in Australia have been involved in more than 10 media ethics violations? | CREATE TABLE ethics (id INT,journalist VARCHAR(100),country VARCHAR(50),violation_type VARCHAR(50),date DATE); INSERT INTO ethics (id,journalist,country,violation_type,date) VALUES (1,'Charlie Davis','Australia','Conflict of Interest','2022-01-01'); INSERT INTO ethics (id,journalist,country,violation_type,date) VALUES (2,'David Thompson','Australia','Plagiarism','2022-01-02'); | SELECT journalist, COUNT(*) FROM ethics WHERE country = 'Australia' GROUP BY journalist HAVING COUNT(*) > 10; |
List all marine species that have been recorded at a depth greater than 5000 meters and have a conservation status of 'Least Concern'. | CREATE TABLE marine_species (species_id INT,species_name VARCHAR(100),max_depth FLOAT,conservation_status VARCHAR(50),order_name VARCHAR(50),family VARCHAR(50)); | SELECT species_name FROM marine_species WHERE max_depth > 5000 AND conservation_status = 'Least Concern'; |
Create a table to archive resolved complaints for the last year | CREATE TABLE resolved_complaints_year (id INT PRIMARY KEY,complaint TEXT,date DATE); | CREATE TABLE resolved_complaints_year AS SELECT id, complaint, date FROM resolved_complaints WHERE date >= (CURRENT_DATE - INTERVAL '1 year'); |
Which companies have a workforce diversity metric greater than 0.6? | CREATE TABLE workforce_diversity (id INT,company_name VARCHAR(50),diversity_metric FLOAT); INSERT INTO workforce_diversity (id,company_name,diversity_metric) VALUES (1,'Company O',0.5),(2,'Company P',0.8); | SELECT * FROM workforce_diversity WHERE diversity_metric > 0.6; |
What is the total quantity of size 14 dresses sold in the last quarter? | CREATE TABLE Sales (order_id INT,product_id INT,product_name VARCHAR(50),size INT,price DECIMAL(5,2),sale_date DATE); INSERT INTO Sales (order_id,product_id,product_name,size,price,sale_date) VALUES (1,1001,'Dress',14,89.99,'2022-01-05'),(2,1002,'Dress',12,99.99,'2022-02-10'),(3,1001,'Dress',14,89.99,'2022-03-20'); | SELECT SUM(price) FROM Sales WHERE size = 14 AND sale_date >= '2022-01-01' AND sale_date <= '2022-03-31'; |
List all the satellites deployed by SpaceX before 2015. | CREATE TABLE SatelliteDeployments (Id INT,Operator VARCHAR(50),Name VARCHAR(50),Year INT); INSERT INTO SatelliteDeployments (Id,Operator,Name,Year) VALUES (1,'SpaceX','FalconSat',2006),(2,'SpaceX','DRAGON',2010); | SELECT Operator, Name FROM SatelliteDeployments WHERE Operator = 'SpaceX' AND Year < 2015; |
What is the average production cost of crops in 'region2' and 'region1'? | CREATE TABLE crop (crop_id INT,crop_name TEXT,region TEXT,cost INT); INSERT INTO crop (crop_id,crop_name,region,cost) VALUES (1,'Corn','region1',200),(2,'Potatoes','region1',100),(3,'Beans','region2',150),(4,'Carrots','region2',120); | SELECT c.region, AVG(c.cost) as avg_production_cost FROM crop c GROUP BY c.region; |
Display the average number of cybersecurity personnel in each country in the North America region. | CREATE TABLE personnel (id INT,country VARCHAR(50),role VARCHAR(50),region VARCHAR(50)); INSERT INTO personnel (id,country,role,region) VALUES (1,'USA','Security Analyst','North America'); INSERT INTO personnel (id,country,role,region) VALUES (2,'Canada','Security Engineer','North America'); | SELECT region, AVG(CASE WHEN role = 'Security Analyst' OR role = 'Security Engineer' THEN 1 ELSE 0 END) FROM personnel WHERE region = 'North America' GROUP BY region; |
What are the names and design standards of all dams in the province of Quebec with a height greater than 50 meters? | CREATE TABLE Dams (id INT,name VARCHAR(100),height FLOAT,province VARCHAR(50),design_standard VARCHAR(50)); INSERT INTO Dams (id,name,height,province,design_standard) VALUES (1,'Manicouagan Dam',162,'Quebec','CSA Z247'); | SELECT name, design_standard FROM Dams WHERE province = 'Quebec' AND height > 50; |
List the peacekeeping operations that have the highest personnel casualties since 2010? | CREATE TABLE PeacekeepingOperations (Operation VARCHAR(50),Year INT,Casualties INT); INSERT INTO PeacekeepingOperations (Operation,Year,Casualties) VALUES ('UNAMID',2010,187),('MONUSCO',2010,184),('MINUSMA',2013,164),('UNMISS',2013,158),('UNSTAMIS',2014,129),('MINUSCA',2014,128),('UNMIK',2000,124),('UNFICYP',1964,101),('ONUC',1961,92),('UNTSO',1948,88); | SELECT Operation, MAX(Casualties) AS HighestCasualties FROM PeacekeepingOperations GROUP BY Operation ORDER BY HighestCasualties DESC; |
How many articles were published on the website per month in 2021? | CREATE TABLE article (id INT,title VARCHAR(255),publish_date DATE); INSERT INTO article (id,title,publish_date) VALUES (1,'Article1','2021-01-01'),(2,'Article2','2021-02-15'),(3,'Article3','2021-12-20'); | SELECT MONTH(publish_date), COUNT(*) FROM article WHERE YEAR(publish_date) = 2021 GROUP BY MONTH(publish_date); |
Insert a new compliance record for the 'Ocean Pollution Act' with vessel_id 3. | CREATE TABLE compliance_new (id INT PRIMARY KEY,vessel_id INT,act TEXT,FOREIGN KEY (vessel_id) REFERENCES vessels(id)); | INSERT INTO compliance_new (vessel_id, act) VALUES ((SELECT id FROM vessels WHERE name = 'Test Vessel 3'), 'Ocean Pollution Act'); |
What is the total value of all digital assets owned by users in the European Union? | CREATE TABLE users (id INT,name TEXT,country TEXT); INSERT INTO users (id,name,country) VALUES (1,'Eve','Germany'),(2,'Frank','France'),(3,'Sophia','UK'); CREATE TABLE digital_assets (id INT,user_id INT,value REAL); INSERT INTO digital_assets (id,user_id,value) VALUES (1,1,100),(2,1,200),(3,2,300),(4,3,400); | SELECT SUM(value) FROM digital_assets da INNER JOIN users u ON da.user_id = u.id WHERE u.country IN ('Germany', 'France', 'UK'); |
Find the number of autonomous buses in the city of 'San Francisco' | CREATE TABLE public.vehicles (id INT,type VARCHAR(20),city VARCHAR(20)); INSERT INTO public.vehicles (id,type,city) VALUES (1,'autonomous_bus','San Francisco'),(2,'conventional_bus','San Francisco'),(3,'autonomous_car','Los Angeles'); | SELECT COUNT(*) FROM public.vehicles WHERE type = 'autonomous_bus' AND city = 'San Francisco'; |
What is the average number of grants awarded to researchers in the Computer Science department? | CREATE TABLE department (id INT,name VARCHAR(255)); CREATE TABLE researcher (id INT,name VARCHAR(255),department_id INT); CREATE TABLE grant (id INT,researcher_id INT,amount DECIMAL(10,2)); | SELECT department.name, AVG(grant.amount) FROM department INNER JOIN researcher ON department.id = researcher.department_id INNER JOIN grant ON researcher.id = grant.researcher_id WHERE department.name = 'Computer Science' GROUP BY department.name; |
What is the progression of professional development workshops attended by a randomly selected teacher? | CREATE TABLE teacher_workshops (teacher_id INT,workshop_id INT,enrollment_date DATE); INSERT INTO teacher_workshops VALUES (1,1001,'2021-01-01'),(1,1002,'2021-02-01'); CREATE TABLE workshops (workshop_id INT,workshop_name VARCHAR(50)); INSERT INTO workshops VALUES (1001,'Tech Tools'),(1002,'Diverse Classrooms'); | SELECT teacher_id, workshop_id, LEAD(enrollment_date, 1) OVER (PARTITION BY teacher_id ORDER BY enrollment_date) as next_workshop_date FROM teacher_workshops JOIN workshops ON teacher_workshops.workshop_id = workshops.workshop_id WHERE teacher_id = 1; |
What is the total crop yield for each crop grown in each province in Argentina? | CREATE TABLE provinces (id INT,name TEXT,country TEXT); INSERT INTO provinces (id,name,country) VALUES (1,'Buenos Aires','Argentina'),(2,'Cordoba','Argentina'); | SELECT crops.name, provinces.name as province_name, SUM(crop_yield.yield) FROM crop_yield JOIN farms ON crop_yield.farm_id = farms.id JOIN crops ON crop_yield.crop_id = crops.id JOIN provinces ON farms.id = provinces.id GROUP BY crops.name, provinces.name; |
What was the total oil production in Texas in 2020? | CREATE TABLE oil_production (year INT,state VARCHAR(255),oil_quantity INT); INSERT INTO oil_production (year,state,oil_quantity) VALUES (2015,'Texas',1230000),(2016,'Texas',1500000),(2017,'Texas',1750000),(2018,'Texas',1900000),(2019,'Texas',2100000); | SELECT SUM(oil_quantity) FROM oil_production WHERE year = 2020 AND state = 'Texas'; |
Who are the top 3 holders of the Solana (SOL) cryptocurrency? | CREATE TABLE SolanaHolders (id INT,address VARCHAR(100),balance DECIMAL(20,2)); INSERT INTO SolanaHolders (id,address,balance) VALUES (1,'sol1...',1000000),(2,'sol2...',500000),(3,'sol3...',300000); | SELECT address, balance FROM SolanaHolders ORDER BY balance DESC LIMIT 3; |
What is the minimum and maximum salary by department? | 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 Department, MIN(Salary) as MinSalary, MAX(Salary) as MaxSalary FROM Employees GROUP BY Department; |
How many clinical trials were conducted by companies located in Germany in 2018? | CREATE TABLE trial (id INT,company TEXT,year INT); INSERT INTO trial (id,company,year) VALUES (1,'Germany Pharma',2018); INSERT INTO trial (id,company,year) VALUES (2,'Germany Pharma',2019); INSERT INTO trial (id,company,year) VALUES (3,'Germany Pharma',2020); INSERT INTO trial (id,company,year) VALUES (4,'USA Pharma',2018); INSERT INTO trial (id,company,year) VALUES (5,'USA Pharma',2019); | SELECT COUNT(*) FROM trial WHERE company LIKE '%Germany%' AND year = 2018; |
What is the total number of games played in the NBA this season? | CREATE TABLE games (id INT,home_team VARCHAR(50),away_team VARCHAR(50),season INT); INSERT INTO games (id,home_team,away_team,season) VALUES (1,'Boston Celtics','Brooklyn Nets',2022); INSERT INTO games (id,home_team,away_team,season) VALUES (2,'Los Angeles Lakers','Golden State Warriors',2022); | SELECT COUNT(*) FROM games WHERE season = 2022; |
Delete all programs that have not had any donations in the last 2 years. | CREATE TABLE donations (id INT,program_id INT,donation_date DATE); CREATE TABLE programs (id INT,program_name TEXT,is_discontinued BOOLEAN); | DELETE FROM programs WHERE programs.id NOT IN (SELECT donations.program_id FROM donations WHERE donations.donation_date >= DATE_SUB(CURDATE(), INTERVAL 2 YEAR)); |
What is the minimum delivery time for shipments to 'Europe' after the 1st of February? | CREATE TABLE shipments (id INT,shipped_date DATE,destination VARCHAR(20),delivery_time INT); INSERT INTO shipments (id,shipped_date,destination,delivery_time) VALUES (1,'2022-02-05','Europe',4),(2,'2022-02-07','Europe',6),(3,'2022-02-16','Europe',5); | SELECT MIN(delivery_time) FROM shipments WHERE shipped_date >= '2022-02-01' AND destination = 'Europe'; |
Get the names of all rangers in the 'asia_pacific' region | CREATE TABLE rangers (id INT,name VARCHAR(255),region VARCHAR(255)); INSERT INTO rangers (id,name,region) VALUES (1,'John','North America'),(2,'Sophia','South America'),(3,'Emma','Europe'),(4,'Ethan','Africa'),(5,'Ava','Asia'),(6,'Ben','Asia Pacific'); | SELECT name FROM rangers WHERE region = 'Asia Pacific'; |
What are the publication statistics for each faculty member? | CREATE TABLE faculty (faculty_id INT,faculty_name VARCHAR(50)); CREATE TABLE publications (pub_id INT,faculty_id INT,pub_type VARCHAR(10)); INSERT INTO faculty (faculty_id,faculty_name) VALUES (1,'John Doe'),(2,'Jane Smith'); INSERT INTO publications (pub_id,faculty_id,pub_type) VALUES (100,1,'Journal'),(101,1,'Conference'),(102,2,'Journal'),(103,2,'Book'); | SELECT f.faculty_name, COUNT(p.pub_id) AS num_publications, SUM(CASE WHEN p.pub_type = 'Journal' THEN 1 ELSE 0 END) AS num_journal_publications, SUM(CASE WHEN p.pub_type = 'Conference' THEN 1 ELSE 0 END) AS num_conference_publications FROM faculty f LEFT JOIN publications p ON f.faculty_id = p.faculty_id GROUP BY f.faculty_name; |
What are the most preferred cosmetic products among male consumers? | CREATE TABLE consumer_preferences (product_id INT,consumer_gender VARCHAR(10),preference_score FLOAT); | SELECT product_id, preference_score FROM consumer_preferences WHERE consumer_gender = 'male' ORDER BY preference_score DESC LIMIT 5; |
What is the trend of mining activity in Canada over the past 5 years, and what is the projected trend for the next 5 years? | CREATE TABLE canada_mining_activity (id INT,year INT,activity_level INT); | SELECT year, activity_level FROM canada_mining_activity WHERE year BETWEEN 2016 AND 2021 OR year BETWEEN 2026 AND 2031; |
Identify the total number of rural infrastructure projects in the 'east' and 'west' regions. | CREATE TABLE infrastructure (region VARCHAR(20),project_type VARCHAR(20),count INT); INSERT INTO infrastructure (region,project_type,count) VALUES ('east','infrastructure',150),('west','infrastructure',200); | SELECT SUM(count) FROM infrastructure WHERE region IN ('east', 'west') AND project_type = 'infrastructure'; |
Update the country of the record with id 4001 in the 'energy_efficiency' table to 'Germany' | CREATE TABLE energy_efficiency (id INT PRIMARY KEY,project_name VARCHAR(100),country VARCHAR(50),kwh_savings INT); | UPDATE energy_efficiency SET country = 'Germany' WHERE id = 4001; |
What is the trend of mental health scores by race/ethnicity? | CREATE TABLE student_mental_health (student_id INT,score INT,race_ethnicity VARCHAR(20)); INSERT INTO student_mental_health (student_id,score,race_ethnicity) VALUES (1,80,'Asian'),(1,85,'Asian'),(2,70,'Hispanic'),(2,75,'Hispanic'),(3,90,'African American'),(3,95,'African American'); | SELECT race_ethnicity, AVG(score) as avg_score FROM student_mental_health GROUP BY race_ethnicity ORDER BY race_ethnicity; |
What is the average energy consumption (in kWh) per smart city technology in the smart_cities table, grouped by technology type? | CREATE TABLE smart_cities (city VARCHAR(50),technology VARCHAR(50),energy_consumption FLOAT); INSERT INTO smart_cities (city,technology,energy_consumption) VALUES ('CityA','SmartLighting',1000),('CityB','SmartLighting',1200),('CityC','SmartTransport',2000); | SELECT technology, AVG(energy_consumption) as avg_energy_consumption FROM smart_cities GROUP BY technology; |
Delete all donation records with an amount less than $50. | CREATE TABLE Donations (id INT,user VARCHAR(255),amount DECIMAL(10,2)); INSERT INTO Donations (id,user,amount) VALUES (1,'John',50.00),(2,'Jane',25.00); | DELETE FROM Donations WHERE amount < 50; |
Show the change in soil moisture levels for each field over the past month. | CREATE TABLE soil_moisture (field TEXT,moisture INTEGER,timestamp TIMESTAMP); | SELECT field, DATEDIFF(day, MIN(timestamp), timestamp) as day_diff, AVG(moisture) as avg_moisture FROM soil_moisture GROUP BY field, DAY(timestamp) ORDER BY field, MIN(timestamp); |
What is the minimum rating for movies and TV shows in Brazil? | CREATE TABLE movies (id INT,title VARCHAR(255),release_year INT,views INT,country VARCHAR(50),rating FLOAT); INSERT INTO movies (id,title,release_year,views,country,rating) VALUES (1,'Movie1',2010,10000,'Brazil',7.5),(2,'Movie2',2015,15000,'Brazil',8.2),(3,'Movie3',2020,20000,'Brazil',8.8); CREATE TABLE tv_shows (id INT,title VARCHAR(255),release_year INT,views INT,country VARCHAR(50),rating FLOAT); INSERT INTO tv_shows (id,title,release_year,views,country,rating) VALUES (1,'TVShow1',2005,20000,'Brazil',8.5),(2,'TVShow2',2018,25000,'Brazil',9.0),(3,'TVShow3',2021,30000,'Brazil',9.5); | SELECT MIN(rating) FROM movies WHERE country = 'Brazil' UNION SELECT MIN(rating) FROM tv_shows WHERE country = 'Brazil'; |
What is the maximum number of working hours per employee in a week for chemical plants in the Great Lakes region, and the corresponding employee and plant? | CREATE TABLE employees (id INT,plant TEXT,employee TEXT,hours_worked FLOAT,work_date DATE); INSERT INTO employees (id,plant,employee,hours_worked,work_date) VALUES (1,'Great Lakes Plant 1','Employee C',45,'2021-07-17'),(2,'Great Lakes Plant 2','Employee D',50,'2021-08-09'); | SELECT MAX(hours_worked) AS max_hours, plant, employee FROM employees WHERE plant LIKE 'Great Lakes%' GROUP BY plant, employee HAVING max_hours = (SELECT MAX(hours_worked) FROM employees WHERE plant LIKE 'Great Lakes%'); |
Calculate average mental health diagnosis per community health worker by district. | CREATE TABLE mental_health_diagnosis (patient_id INT,diagnosis_date DATE,diagnosis VARCHAR(50),prescriber_id INT); INSERT INTO mental_health_diagnosis (patient_id,diagnosis_date,diagnosis,prescriber_id) VALUES (1,'2022-01-01','Depression',101); CREATE TABLE prescriber_details (id INT,prescriber_name VARCHAR(50),language VARCHAR(20),years_of_experience INT); INSERT INTO prescriber_details (id,prescriber_name,language,years_of_experience) VALUES (101,'Dr. Smith','English',15); CREATE TABLE community_health_workers (id INT,worker_name VARCHAR(50),language VARCHAR(20),years_in_service INT,district VARCHAR(30)); INSERT INTO community_health_workers (id,worker_name,language,years_in_service,district) VALUES (201,'Ms. Garcia','Spanish',8,'Downtown'),(202,'Mr. Nguyen','Vietnamese',12,'Uptown'); | SELECT C.district, COUNT(DISTINCT M.patient_id) as AvgDiagnosisPerWorker FROM mental_health_diagnosis M JOIN prescriber_details P ON M.prescriber_id = P.id JOIN community_health_workers C ON P.language = C.language GROUP BY C.district; |
List all cultural heritage sites and their virtual tour availability status. | CREATE TABLE cultural_heritage_sites (site_id INT,site_name TEXT,is_virtual_tour BOOLEAN); INSERT INTO cultural_heritage_sites (site_id,site_name,is_virtual_tour) VALUES (1,'Machu Picchu',false),(2,'Taj Mahal',true),(3,'Colosseum',false); | SELECT site_name, is_virtual_tour FROM cultural_heritage_sites; |
Determine the percentage of accessible technology patents for each organization in the last year, ordered by the highest percentage. | CREATE TABLE accessible_tech_patents (org_name VARCHAR(50),year INT,accessible_patents INT); INSERT INTO accessible_tech_patents (org_name,year,accessible_patents) VALUES ('ABC Corp',2021,120),('XYZ Inc',2020,150),('DEF Org',2021,180),('GHI Ltd',2020,100),('JKL Co',2021,210); CREATE TABLE total_patents (org_name VARCHAR(50),year INT,total_patents INT); INSERT INTO total_patents (org_name,year,total_patents) VALUES ('ABC Corp',2021,200),('XYZ Inc',2020,250),('DEF Org',2021,300),('GHI Ltd',2020,200),('JKL Co',2021,350); | SELECT a.org_name, (a.accessible_patents * 100.0 / b.total_patents) as percentage FROM accessible_tech_patents a JOIN total_patents b ON a.org_name = b.org_name WHERE a.year = 2021 GROUP BY a.org_name ORDER BY percentage DESC; |
Show revenue for restaurants located in 'California' from the 'Revenue' table. | CREATE TABLE Revenue (restaurant VARCHAR(255),state VARCHAR(255),revenue DECIMAL(10,2)); INSERT INTO Revenue (restaurant,state,revenue) VALUES ('Bistro Veggie','California',35000),('Pizza House','New York',50000),('Vegan Delight','California',40000); | SELECT revenue FROM Revenue WHERE state = 'California'; |
What is the number of organizations and total invested amount by each investor for organizations focused on social impact? | CREATE TABLE investments (investment_id INT,investor_id INT,org_id INT,investment_amount INT); INSERT INTO investments (investment_id,investor_id,org_id,investment_amount) VALUES (1,1,2,50000),(2,2,3,75000),(3,1,1,100000),(4,3,2,35000),(5,2,1,80000); CREATE TABLE investors (investor_id INT,investor_name TEXT); INSERT INTO investors (investor_id,investor_name) VALUES (1,'Investor A'),(2,'Investor B'),(3,'Investor C'); CREATE TABLE organizations (org_id INT,org_name TEXT,focus_topic TEXT); INSERT INTO organizations (org_id,org_name,focus_topic) VALUES (1,'Org 1','Social Impact'),(2,'Org 2','Social Impact'),(3,'Org 3','Climate Change'); | SELECT investors.investor_name, COUNT(organizations.org_id) AS orgs_invested, SUM(investments.investment_amount) AS total_invested FROM investments JOIN investors ON investments.investor_id = investors.investor_id JOIN organizations ON investments.org_id = organizations.org_id WHERE organizations.focus_topic = 'Social Impact' GROUP BY investors.investor_name; |
Find the top 2 countries with the highest number of fashion brands, and show only those brands that have been in business for more than 10 years. | CREATE TABLE FashionBrands (brand TEXT,country TEXT,years_in_business INTEGER); INSERT INTO FashionBrands (brand,country,years_in_business) VALUES ('Brand1','Italy',15),('Brand2','France',8),('Brand3','Spain',20),('Brand4','Germany',12); | SELECT country, COUNT(*) as brand_count FROM FashionBrands WHERE years_in_business > 10 GROUP BY country ORDER BY brand_count DESC LIMIT 2; |
What is the total amount of donations made by the top 5 donors for the year 2020? | CREATE TABLE donors (donor_id INT,donor_name VARCHAR(50),donor_country VARCHAR(50),donation_amount DECIMAL(10,2),donation_date DATE); INSERT INTO donors (donor_id,donor_name,donor_country,donation_amount,donation_date) VALUES (1,'John Doe','USA',50.00,'2020-01-01'); | SELECT donor_name, SUM(donation_amount) AS total_donation FROM (SELECT donor_name, donation_amount, ROW_NUMBER() OVER (ORDER BY donation_amount DESC) AS rank FROM donors WHERE YEAR(donation_date) = 2020) donors_ranked WHERE rank <= 5 GROUP BY donor_name; |
What is the number of TB cases reported in each province of Canada, by year? | CREATE TABLE tb_cases (id INT,patient_id INT,report_date DATE,province VARCHAR(255),is_active BOOLEAN); | SELECT YEAR(report_date) AS year, province, COUNT(*) AS num_tb_cases FROM tb_cases WHERE is_active = TRUE GROUP BY year, province; |
How many streams did 'Female Artists' have on their songs released in the last 5 years? | CREATE TABLE artists (artist_id INT,artist_name VARCHAR(100),gender VARCHAR(10)); INSERT INTO artists (artist_id,artist_name,gender) VALUES (1,'Taylor Swift','Female'),(2,'Ed Sheeran','Male'),(3,'Kendrick Lamar','Male'),(4,'Ariana Grande','Female'); CREATE TABLE songs (song_id INT,song_name VARCHAR(100),release_year INT,gender VARCHAR(10)); INSERT INTO songs (song_id,song_name,release_year,gender) VALUES (1,'Shape of You',2017,'Male'),(2,'Thinking Out Loud',2014,'Male'),(3,'Bohemian Rhapsody',1975,'Male'),(4,'Problem',2014,'Female'),(5,'The Way',2013,'Female'); CREATE TABLE streams (stream_id INT,song_id INT,streams INT); INSERT INTO streams (stream_id,song_id,streams) VALUES (1,1,1000000),(2,1,750000),(3,2,800000),(4,2,600000),(5,3,50000),(6,3,40000),(7,4,300000),(8,4,250000),(9,5,100000),(10,5,90000); | SELECT SUM(s.streams) FROM songs so INNER JOIN artists a ON so.gender = a.gender INNER JOIN streams s ON so.song_id = s.song_id WHERE a.gender = 'Female' AND so.release_year BETWEEN 2016 AND 2021; |
Determine the number of electric vehicles (ev) sold in each region in 2019 | CREATE TABLE sales_region (id INT,region VARCHAR(20),vehicle_type VARCHAR(20),year INT,quantity INT); INSERT INTO sales_region (id,region,vehicle_type,year,quantity) VALUES (1,'North','ev',2018,1500),(2,'North','ev',2019,2500),(3,'South','ev',2018,1000),(4,'South','ev',2019,2000),(5,'East','ev',2018,800),(6,'East','ev',2019,3000),(7,'West','ev',2018,2000),(8,'West','ev',2019,4000); | SELECT region, year, SUM(quantity) FROM sales_region WHERE vehicle_type = 'ev' GROUP BY region, year; |
How many volunteers signed up in each state in 2022? | CREATE TABLE Volunteers (VolunteerID int,State varchar(50),VolunteerDate date); INSERT INTO Volunteers (VolunteerID,State,VolunteerDate) VALUES (1,'California','2022-01-01'),(2,'Texas','2022-05-15'); | SELECT State, COUNT(*) as NumVolunteers FROM Volunteers WHERE VolunteerDate BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY State; |
Insert a new record into the "manufacturing_data" table | CREATE TABLE manufacturing_data (id INT PRIMARY KEY,chemical_name VARCHAR(255),quantity_produced INT,date_manufactured DATE); | INSERT INTO manufacturing_data (id, chemical_name, quantity_produced, date_manufactured) VALUES (1, 'Ammonia', 100, '2022-01-01'); |
Find the number of criminal cases that were resolved through diversion programs in each state in 2020. | CREATE TABLE CriminalCases (Id INT,State VARCHAR(50),Program VARCHAR(50),ResolutionDate DATE); INSERT INTO CriminalCases (Id,State,Program,ResolutionDate) VALUES (1,'California','Diversion','2020-03-21'),(2,'Texas','Probation','2019-12-12'),(3,'NewYork','Diversion','2020-06-15'); | SELECT State, COUNT(*) as NumCases FROM CriminalCases WHERE Program = 'Diversion' AND YEAR(ResolutionDate) = 2020 GROUP BY State; |
What is the number of hybrid vehicles sold in Canada each year since 2015? | CREATE TABLE VehicleSales (year INT,country VARCHAR(255),vehicle_type VARCHAR(255),sales INT); INSERT INTO VehicleSales (year,country,vehicle_type,sales) VALUES (2015,'Canada','Hybrid',15000),(2016,'Canada','Hybrid',20000),(2017,'Canada','Hybrid',30000),(2018,'Canada','Hybrid',40000),(2019,'Canada','Hybrid',50000),(2020,'Canada','Hybrid',60000); | SELECT year, SUM(sales) AS hybrid_vehicle_sales FROM VehicleSales WHERE country = 'Canada' AND vehicle_type = 'Hybrid' GROUP BY year; |
List all deliveries made to Syria in 2022 that included medical supplies. | CREATE TABLE Deliveries (delivery_id INT,delivery_date DATE,item_id INT,quantity INT,country TEXT); CREATE TABLE Items (item_id INT,item_name TEXT); | SELECT Deliveries.* FROM Deliveries INNER JOIN Items ON Deliveries.item_id = Items.item_id WHERE Deliveries.country = 'Syria' AND Deliveries.delivery_date BETWEEN '2022-01-01' AND '2022-12-31' AND Items.item_name LIKE '%medical%'; |
Delete the record for well 'C03' in 'North Sea'. | CREATE TABLE wells (well_id VARCHAR(10),well_location VARCHAR(20)); INSERT INTO wells (well_id,well_location) VALUES ('C03','North Sea'); CREATE TABLE production (well_id VARCHAR(10),production_count INT); INSERT INTO production (well_id,production_count) VALUES ('C03',7000); | DELETE FROM production WHERE well_id = 'C03'; |
How many indigenous communities are in the Arctic Research Station 6 and 7? | CREATE TABLE Arctic_Research_Station_6 (id INT,community TEXT); CREATE TABLE Arctic_Research_Station_7 (id INT,community TEXT); | SELECT COUNT(DISTINCT community) FROM Arctic_Research_Station_6; SELECT COUNT(DISTINCT community) FROM Arctic_Research_Station_7; SELECT COUNT(DISTINCT community) FROM (SELECT * FROM Arctic_Research_Station_6 UNION ALL SELECT * FROM Arctic_Research_Station_7) AS Arctic_Communities; |
What is the average age of patients for each condition? | CREATE TABLE patients (patient_id INT,age INT,gender TEXT,condition TEXT,treatment TEXT); INSERT INTO patients (patient_id,age,gender,condition,treatment) VALUES (1,35,'Female','Depression','CBT'),(2,40,'Male','Anxiety','Medication'); | SELECT condition, AVG(age) as avg_age FROM patients GROUP BY condition; |
What is the total number of articles by topic? | CREATE TABLE articles (id INT,title VARCHAR(100),topic VARCHAR(50),date DATE); INSERT INTO articles (id,title,topic,date) VALUES (1,'Article 1','Politics','2021-01-01'); INSERT INTO articles (id,title,topic,date) VALUES (2,'Article 2','Sports','2021-01-02'); INSERT INTO articles (id,title,topic,date) VALUES (3,'Article 3','Politics','2021-01-03'); | SELECT topic, COUNT(*) as total_articles FROM articles GROUP BY topic; |
What is the average temperature recorded by IoT sensors in the past week in the 'FieldA'? | CREATE TABLE FieldA_Sensors (sensor_id INT,temperature FLOAT,reading_time DATETIME); INSERT INTO FieldA_Sensors (sensor_id,temperature,reading_time) VALUES (1,23.5,'2022-01-01 10:00:00'),(1,25.3,'2022-01-02 10:00:00'); | SELECT AVG(temperature) FROM FieldA_Sensors WHERE reading_time BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK) AND CURRENT_DATE; |
Who has the highest number of assists in the 2022 NBA season for each team? | CREATE TABLE nba_assists (player_id INT,player_name TEXT,team_id INT,assists INT); INSERT INTO nba_assists (player_id,player_name,team_id,assists) VALUES (1,'Luka Doncic',18,871),(2,'James Harden',17,798); | SELECT team_id, MAX(assists) OVER (PARTITION BY team_id ORDER BY team_id) AS highest_assists FROM nba_assists; |
List the total capacity (MW) of renewable energy sources in each country | CREATE TABLE renewable_sources (id INT,name TEXT,country TEXT,capacity FLOAT); INSERT INTO renewable_sources (id,name,country,capacity) VALUES (1,'Wind','US',150.1); INSERT INTO renewable_sources (id,name,country,capacity) VALUES (2,'Solar','Spain',50.1); INSERT INTO renewable_sources (id,name,country,capacity) VALUES (3,'Hydro','Germany',1060); | SELECT country, SUM(capacity) FROM renewable_sources GROUP BY country; |
What is the minimum number of games played by players from India? | CREATE TABLE PlayerGameStats (PlayerID INT,GamesPlayed INT); INSERT INTO PlayerGameStats (PlayerID,GamesPlayed) VALUES (1,15),(2,12),(3,10),(4,18),(5,17),(6,11),(7,10),(8,20),(9,15),(10,12),(11,25),(12,18),(13,14),(14,15),(15,11),(16,12),(17,10),(18,20),(19,15),(20,14); CREATE TABLE PlayerLocation (PlayerID INT,Location VARCHAR(20)); INSERT INTO PlayerLocation (PlayerID,Location) VALUES (1,'USA'),(2,'Canada'),(3,'USA'),(4,'Mexico'),(5,'India'),(6,'USA'),(7,'Canada'),(8,'China'),(9,'Brazil'),(10,'India'),(11,'USA'),(12,'Mexico'),(13,'Canada'),(14,'India'),(15,'USA'),(16,'Brazil'),(17,'Canada'),(18,'China'),(19,'India'),(20,'Brazil'); | SELECT MIN(PlayerGameStats.GamesPlayed) FROM PlayerGameStats JOIN PlayerLocation ON PlayerGameStats.PlayerID = PlayerLocation.PlayerID WHERE PlayerLocation.Location = 'India'; |
What is the number of active players in each country, defined as players who have played a game in the last month, grouped by country. | CREATE TABLE players(id INT,name VARCHAR(50),country VARCHAR(50),last_login DATETIME); CREATE TABLE game_sessions(id INT,player_id INT,game_name VARCHAR(50),start_time DATETIME); | SELECT players.country, COUNT(DISTINCT players.id) as active_players FROM players JOIN game_sessions ON players.id = game_sessions.player_id WHERE start_time >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY players.country; |
How many goals has Messi scored in away matches? | CREATE TABLE matches (id INT,home_team VARCHAR(50),away_team VARCHAR(50),goals_home INT,goals_away INT); | SELECT SUM(goals_away) FROM matches WHERE away_team = 'Barcelona' AND player = 'Messi'; |
Delete factories in Indonesia that have a labor cost greater than $5.00 and do not use sustainable materials. | CREATE TABLE factory_indonesia (factory VARCHAR(255),country VARCHAR(255),material VARCHAR(255),labor_cost DECIMAL(5,2)); INSERT INTO factory_indonesia (factory,country,material,labor_cost) VALUES ('Factory1','Indonesia','conventional cotton',5.50),('Factory2','Indonesia','recycled polyester',4.75),('Factory3','Indonesia','conventional cotton',5.25); | DELETE FROM factory_indonesia WHERE country = 'Indonesia' AND labor_cost > 5.00 AND material NOT IN ('organic cotton', 'recycled polyester'); |
What is the minimum salary in the 'finance' sector? | CREATE TABLE company_data (company_name VARCHAR(30),sector VARCHAR(20),min_salary INT); INSERT INTO company_data (company_name,sector,min_salary) VALUES ('CompanyX','Finance',50000),('CompanyY','Finance',60000),('CompanyZ','Retail',40000); | SELECT MIN(min_salary) FROM company_data WHERE sector = 'Finance'; |
What is the average price of ethical fashion products made from recycled materials? | CREATE TABLE ethical_fashion (product_id INT,product_type VARCHAR(50),material_type VARCHAR(50),price DECIMAL(5,2)); INSERT INTO ethical_fashion (product_id,product_type,material_type,price) VALUES (1,'Ethical Fashion','Recycled Polyester',50.00),(2,'Ethical Fashion','Organic Cotton',60.00),(3,'Ethical Fashion','Tencel',70.00); | SELECT AVG(price) FROM ethical_fashion WHERE product_type = 'Ethical Fashion' AND material_type IN ('Recycled Polyester', 'Organic Cotton', 'Tencel'); |
Find the number of climate finance records for each organization, sorted by the number of records in descending order. | CREATE TABLE climate_finance (organization_name TEXT); INSERT INTO climate_finance (organization_name) VALUES ('Organization A'),('Organization B'),('Organization A'),('Organization C'),('Organization B'),('Organization B'); | SELECT organization_name, COUNT(*) as records FROM climate_finance GROUP BY organization_name ORDER BY records DESC; |
What is the average donation to environmental nonprofits in Canada? | CREATE TABLE organization (org_id INT PRIMARY KEY,name VARCHAR(255),industry VARCHAR(255),country VARCHAR(255)); INSERT INTO organization (org_id,name,industry,country) VALUES (2,'Greenpeace Canada','Nonprofit','Canada'); | SELECT AVG(donation_amount) FROM (SELECT donation.amount AS donation_amount FROM donation JOIN organization ON donation.org_id = organization.org_id WHERE organization.country = 'Canada' AND organization.industry = 'Nonprofit' AND organization.name = 'Greenpeace Canada') AS donation_subquery; |
List the total production of oil and gas for each country in the Middle East for 2020. | CREATE TABLE middle_east_oil_production (country VARCHAR(255),year INT,oil_production FLOAT,gas_production FLOAT); | SELECT country, SUM(oil_production) as total_oil_production, SUM(gas_production) as total_gas_production FROM middle_east_oil_production WHERE year = 2020 AND country IN ('Saudi Arabia', 'Iran', 'Iraq', 'UAE', 'Kuwait', 'Qatar') GROUP BY country; |
What is the total revenue from concert ticket sales in 2021? | CREATE TABLE Concerts (ConcertID INT,ArtistID INT,ConcertDate DATE,Venue VARCHAR(100),TicketRevenue DECIMAL(10,2)); INSERT INTO Concerts (ConcertID,ArtistID,ConcertDate,Venue,TicketRevenue) VALUES (1,1,'2021-06-01','Stadium',500000); INSERT INTO Concerts (ConcertID,ArtistID,ConcertDate,Venue,TicketRevenue) VALUES (2,2,'2021-12-31','Theatre',25000); | SELECT SUM(TicketRevenue) FROM Concerts WHERE YEAR(ConcertDate) = 2021; |
Delete records of drivers with no rides in the rides table for the month of January 2022. | rides (id,driver_id,ride_date,distance,cost) | DELETE FROM rides USING drivers WHERE rides.driver_id = drivers.id AND rides.ride_date < '2022-02-01' AND rides.ride_date >= '2022-01-01' AND drivers.name IS NOT NULL AND rides.distance IS NULL; |
What is the total number of certified sustainable tourism businesses in the Caribbean? | CREATE TABLE businesses (id INT,name VARCHAR(30),location VARCHAR(20),certified BOOLEAN); INSERT INTO businesses (id,name,location,certified) VALUES (1,'Caribbean Eco Tours','Bahamas',TRUE),(2,'Green Travel Jamaica','Jamaica',TRUE),(3,'Eco Adventures','Puerto Rico',FALSE); | SELECT COUNT(*) FROM businesses WHERE certified = TRUE AND location IN ('Bahamas', 'Jamaica', 'Puerto Rico', 'Cuba', 'Dominican Republic', 'Barbados', 'Haiti', 'Trinidad and Tobago'); |
Which team had the highest average ticket sales revenue per game? | CREATE TABLE team_ticket_sales (id INT,team VARCHAR(50),revenue INT); INSERT INTO team_ticket_sales (id,team,revenue) VALUES (1,'TeamA',70000),(2,'TeamA',60000),(3,'TeamB',50000),(4,'TeamB',40000); | SELECT team, AVG(revenue) as avg_revenue_per_game FROM team_ticket_sales GROUP BY team; |
What is the total number of visitors at the "music_concerts" table by age group? | CREATE TABLE music_concerts (concert_id INT,age INT,num_visitors INT); INSERT INTO music_concerts (concert_id,age,num_visitors) VALUES (1,18,200),(2,25,250),(3,35,300); | SELECT age, SUM(num_visitors) FROM music_concerts GROUP BY age; |
What is the rank of the most recent comment made by a user from Japan, ordered by created date? | CREATE TABLE comments (id INT,post_id INT,user_id INT,text TEXT,created_date DATE); INSERT INTO comments (id,post_id,user_id,text,created_date) VALUES (1,1,7,'Nice post!','2022-11-05'),(2,2,7,'Thank you.','2022-11-06'); | SELECT c.text, c.user_id, ROW_NUMBER() OVER (ORDER BY created_date DESC) as rank FROM comments c WHERE c.country = 'Japan' AND c.created_date = (SELECT MAX(created_date) FROM comments WHERE country = 'Japan') |
What is the average biomass of fish in saltwater fish farms in the Northern Hemisphere? | CREATE TABLE fish_farms (id INT,name TEXT,type TEXT,location TEXT,biomass FLOAT); INSERT INTO fish_farms (id,name,type,location,biomass) VALUES (1,'Farm M','Fish','Norway',25000.0),(2,'Farm N','Fish','Canada',18000.0); | SELECT AVG(biomass) FROM fish_farms WHERE type = 'Fish' AND location IN (SELECT location FROM fish_farms WHERE biomass IS NOT NULL GROUP BY location HAVING EXTRACT(HOUR FROM AVG(location)) < 12); |
What is the total budget of all campaigns in New York? | CREATE TABLE campaigns (id INT,name TEXT,budget INT,start_date DATE,state TEXT); INSERT INTO campaigns (id,name,budget,start_date,state) VALUES (1,'EndStigma',50000,'2019-03-01','New York'); INSERT INTO campaigns (id,name,budget,start_date,state) VALUES (2,'HealthyMinds',75000,'2018-06-15','California'); INSERT INTO campaigns (id,name,budget,start_date,state) VALUES (3,'MentalHealthMatters',60000,'2017-12-09','New York'); | SELECT SUM(budget) FROM campaigns WHERE state = 'New York'; |
Minimum safety score for AI models developed in Q1 of 2020? | CREATE TABLE ai_safety (model_name TEXT,safety_score INTEGER,quarter TEXT); INSERT INTO ai_safety (model_name,safety_score,quarter) VALUES ('ModelA',88,'Q1 2020'),('ModelB',92,'Q2 2019'),('ModelC',75,'Q1 2020'),('ModelD',95,'Q4 2021'); | SELECT MIN(safety_score) FROM ai_safety WHERE quarter = 'Q1 2020'; |
What is the total amount donated by donors in the healthcare industry in the year 2020? | CREATE TABLE Donors (DonorID INT,DonorName TEXT,Industry TEXT); INSERT INTO Donors (DonorID,DonorName,Industry) VALUES (1,'John Doe','Technology'),(2,'Jane Smith','Finance'),(3,'Leung Li','Technology'),(4,'Kim Jae','Retail'); CREATE TABLE Donations (DonationID INT,DonorID INT,DonationAmount INT,DonationYear INT); INSERT INTO Donations (DonationID,DonorID,DonationAmount,DonationYear) VALUES (1,1,100,2020),(2,1,200,2019),(3,2,30,2020),(4,2,50,2019),(5,3,1000,2018),(6,4,2000,2020); | SELECT SUM(DonationAmount) FROM Donations JOIN Donors ON Donations.DonorID = Donors.DonorID WHERE Donors.Industry = 'Healthcare' AND DonationYear = 2020; |
What is the total number of train delays in Tokyo greater than 10 minutes? | CREATE TABLE train_delays (delay_id INT,train_id INT,delay_length INT,delay_reason VARCHAR); INSERT INTO train_delays VALUES (1,123,15,'Mechanical failure'); | SELECT COUNT(*) FROM train_delays WHERE delay_length > 10; |
What is the maximum production of Dysprosium in 2017? | CREATE TABLE dysprosium_production (country VARCHAR(50),year INT,quantity INT); INSERT INTO dysprosium_production (country,year,quantity) VALUES ('China',2017,3800),('United States',2017,600),('Malaysia',2017,500),('India',2017,400); | SELECT MAX(quantity) FROM dysprosium_production WHERE year = 2017; |
How many professional development courses were completed by teachers in 'Spring 2022'? | CREATE TABLE teacher_professional_development (teacher_id INT,course_id INT,date DATE); INSERT INTO teacher_professional_development (teacher_id,course_id,date) VALUES (1,1,'2022-03-01'),(2,2,'2022-03-02'),(3,3,'2022-03-03'); | SELECT COUNT(DISTINCT course_id) FROM teacher_professional_development WHERE date = '2022-03-01'; |
Retrieve the number of machines of each type | CREATE TABLE machines (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255),status VARCHAR(255)); INSERT INTO machines (id,name,type,status) VALUES (1,'Machine A','CNC','Operational'),(2,'Machine B','Robotic Arm','Under Maintenance'),(3,'Machine C','CNC','Operational'),(4,'Machine D','Robotic Arm','Operational'),(5,'Machine E','Conveyor Belt','Operational'); | SELECT type, COUNT(*) FROM machines GROUP BY type; |
What is the average budget for economic diversification projects in Argentina that started in 2017? | CREATE TABLE economic_diversification (id INT,project_name VARCHAR(255),budget FLOAT,start_date DATE,country VARCHAR(50)); INSERT INTO economic_diversification (id,project_name,budget,start_date,country) VALUES (1,'Technology Hub',350000.00,'2017-05-01','Argentina'),(2,'Sustainable Fashion',250000.00,'2017-11-30','Argentina'),(3,'Biofuel Research',400000.00,'2017-07-14','Argentina'); | SELECT AVG(budget) FROM economic_diversification WHERE country = 'Argentina' AND start_date BETWEEN '2017-01-01' AND '2017-12-31' |
What is the total revenue generated from warehouse management for customers in India in Q2 2022? | CREATE TABLE WarehouseManagement (id INT,customer VARCHAR(255),revenue FLOAT,country VARCHAR(255),quarter INT,year INT); | SELECT SUM(revenue) FROM WarehouseManagement WHERE country = 'India' AND quarter = 2 AND year = 2022; |
Who are the top 5 investors by number of investments in startups in the Bay Area? | CREATE TABLE investments (id INT,startup_id INT,investor_id INT,investment_date DATE,investment_amount FLOAT); INSERT INTO investments (id,startup_id,investor_id,investment_date,investment_amount) VALUES (1,1,101,'2010-01-01',1000000); CREATE TABLE investors (id INT,name TEXT,location TEXT); INSERT INTO investors (id,name,location) VALUES (101,'Capital Ventures','San Francisco'); | SELECT i.name, COUNT(i.id) as num_investments FROM investments AS inv JOIN investors AS i ON inv.investor_id = i.id WHERE i.location = 'San Francisco' GROUP BY i.id ORDER BY num_investments DESC LIMIT 5; |
List the top 2 continents with the highest CO2 emission per capita in 2019, and rank them. | CREATE TABLE EmissionsData (Continent VARCHAR(50),Year INT,CO2Emission DECIMAL(5,2),Population INT); INSERT INTO EmissionsData (Continent,Year,CO2Emission,Population) VALUES ('Asia',2020,5.3,4600000000),('Asia',2019,4.6,4580000000),('Africa',2020,2.1,1300000000),('Africa',2019,1.8,1280000000); | SELECT Continent, AVG(CO2Emission/Population) as AvgCO2PerCapita, RANK() OVER (ORDER BY AVG(CO2Emission/Population) DESC) as Rank FROM EmissionsData WHERE Year = 2019 GROUP BY Continent HAVING COUNT(*) > 1 ORDER BY Rank; |
What is the percentage change in sales of organic products in the US between 2020 and 2021? | CREATE TABLE sales (id INT,year INT,product_type VARCHAR(20),revenue FLOAT); INSERT INTO sales (id,year,product_type,revenue) VALUES (1,2020,'organic',1000),(2,2021,'organic',1200); | SELECT (revenue_2021 - revenue_2020) / revenue_2020 * 100 AS percentage_change FROM (SELECT (SELECT revenue FROM sales WHERE year = 2021 AND product_type = 'organic') AS revenue_2021, (SELECT revenue FROM sales WHERE year = 2020 AND product_type = 'organic') AS revenue_2020) AS organic_sales; |
Update the location of the project with id 2 to 'Texas Panhandle' | CREATE TABLE projects (id INT,name TEXT,capacity INT,location TEXT); INSERT INTO projects (id,name,capacity,location) VALUES (1,'Solar Farm 1.0',1000,'California'); INSERT INTO projects (id,name,capacity,location) VALUES (2,'Wind Farm 1.0',2000,'Texas'); INSERT INTO projects (id,name,capacity,location) VALUES (3,'Hydro Plant 1.0',1500,'Oregon'); | UPDATE projects SET location = 'Texas Panhandle' WHERE id = 2; |
What is the average recycling rate for each material type in California in 2021? | CREATE TABLE recycling_rates (year INT,location VARCHAR(255),material VARCHAR(255),recycling_rate DECIMAL(5,2)); INSERT INTO recycling_rates (year,location,material,recycling_rate) VALUES (2021,'California','Plastic',0.35),(2021,'California','Paper',0.65),(2021,'California','Glass',0.55); | SELECT material, AVG(recycling_rate) as avg_recycling_rate FROM recycling_rates WHERE year = 2021 AND location = 'California' GROUP BY material; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.