instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
What is the total quantity of items produced in the 'Ethical Clothing' category in 2021 and 2022? | CREATE TABLE production (product_id INT,category VARCHAR(255),year INT,quantity INT); INSERT INTO production (product_id,category,year,quantity) VALUES (1,'Ethical Clothing',2021,100),(2,'Eco-Friendly Toys',2022,200),(3,'Ethical Clothing',2022,150); | SELECT category, SUM(quantity) as total_quantity FROM production WHERE category = 'Ethical Clothing' AND year IN (2021, 2022) GROUP BY category; |
Find the astronauts who have had medical procedures performed in space and the name of the medical procedure. | CREATE TABLE Astronaut_Medical_Data(id INT,astronaut_name VARCHAR(50),medical_procedure VARCHAR(50),procedure_date DATE,location VARCHAR(50)); | SELECT astronaut_name, medical_procedure FROM Astronaut_Medical_Data WHERE location = 'Space'; |
What is the average age of athletes for each sport in the 'athletes' table? | CREATE TABLE athletes (athlete_id INT,name VARCHAR(50),age INT,sport VARCHAR(20)); | SELECT sport, AVG(age) FROM athletes GROUP BY sport; |
Which regions have the most fans who have attended wellbeing programs? | CREATE TABLE wellbeing (fan_id INT,region VARCHAR(20)); INSERT INTO wellbeing (fan_id,region) VALUES (1,'North'),(2,'North'),(3,'South'),(4,'East'),(5,'West'); | SELECT region, COUNT(fan_id) FROM wellbeing JOIN fans ON wellbeing.fan_id = fans.fan_id WHERE fans.game_type IN ('Wellbeing Program 1', 'Wellbeing Program 2') GROUP BY region ORDER BY COUNT(fan_id) DESC; |
Find the top 5 autonomous vehicles with the lowest price increase per mile compared to their first model year | CREATE TABLE autonomous_vehicles_3 (vehicle_id INT,vehicle_name VARCHAR(255),price_per_mile DECIMAL(5,2),model_year INT); | SELECT vehicle_name, price_per_mile, model_year, (price_per_mile - t2.price_per_mile) / t2.price_per_mile * 100 as price_increase_percentage FROM autonomous_vehicles_3 t1 JOIN autonomous_vehicles_3 t2 ON t1.vehicle_name = t2.vehicle_name AND t1.model_year = t2.model_year + 1 WHERE t2.model_year = (SELECT MIN(model_year) FROM autonomous_vehicles_3 WHERE vehicle_name = vehicle_name) ORDER BY price_increase_percentage ASC LIMIT 5; |
Which vessels have a max speed greater than 25 knots and are registered in the USA? | CREATE TABLE Vessels (vessel_id VARCHAR(10),name VARCHAR(20),type VARCHAR(20),max_speed FLOAT,cargo_capacity INT,country VARCHAR(20)); INSERT INTO Vessels (vessel_id,name,type,max_speed,cargo_capacity,country) VALUES ('1','Vessel A','Cargo',20.5,5000,'Indonesia'),('2','Vessel B','Tanker',15.2,0,'Nigeria'),('3','Vessel C','Tanker',28.1,0,'USA'),('4','Vessel D','Cargo',12.6,6000,'Indonesia'),('5','Vessel E','Cargo',16.2,4500,'Canada'),('6','Vessel F','Tanker',26.8,3000,'USA'),('7','Vessel G','Tanker',17.5,5000,'USA'); | SELECT vessel_id, name FROM Vessels WHERE max_speed > 25 AND country = 'USA'; |
What is the average age of visitors who attended family workshops? | CREATE TABLE attendees (id INT,event_id INT,age INT); INSERT INTO attendees (id,event_id,age) VALUES (1,101,45),(2,101,47),(3,101,12),(4,102,52),(5,102,54),(6,103,10),(7,103,11),(8,103,13); CREATE TABLE events (id INT,name VARCHAR(255),type VARCHAR(255)); INSERT INTO events (id,name,type) VALUES (101,'Family Workshop A','Workshop'),(102,'Lecture Series 1','Lecture'),(103,'Family Workshop B','Workshop'); | SELECT AVG(age) FROM attendees WHERE event_id IN (SELECT id FROM events WHERE type = 'Workshop'); |
Add recycling rate data to the 'RecyclingRates' table for facility ID 1 in the years 2018, 2019, 2020 with rates 0.75, 0.78, 0.81 | CREATE TABLE WasteTypes (waste_type_id INT PRIMARY KEY,name VARCHAR,description VARCHAR); CREATE TABLE Facilities (facility_id INT PRIMARY KEY,name VARCHAR,location VARCHAR,capacity INT,waste_type_id INT,FOREIGN KEY (waste_type_id) REFERENCES WasteTypes(waste_type_id)); CREATE TABLE RecyclingRates (rate_id INT PRIMARY KEY,facility_id INT,year INT,rate DECIMAL,FOREIGN KEY (facility_id) REFERENCES Facilities(facility_id)); | INSERT INTO RecyclingRates (rate_id, facility_id, year, rate) VALUES (1, 1, 2018, 0.75), (2, 1, 2019, 0.78), (3, 1, 2020, 0.81); |
What is the maximum recycling rate for any material? | CREATE TABLE Recycling_Rates_All (material VARCHAR(20),region VARCHAR(20),recycling_rate DECIMAL(4,2)); INSERT INTO Recycling_Rates_All (material,region,recycling_rate) VALUES ('Glass','East',0.60),('Paper','East',0.75),('Plastic','West',0.55),('Metal','North',0.80),('Glass','West',0.70),('Paper','West',0.65),('Metal','West',0.85); | SELECT MAX(recycling_rate) FROM Recycling_Rates_All; |
Update the water_usage of the customer with the highest water_usage in the month of May 2022 to 1000 in the residential table. | CREATE TABLE residential (customer_id INT,water_usage FLOAT,usage_date DATE); INSERT INTO residential (customer_id,water_usage,usage_date) VALUES (1,150.5,'2022-05-01'),(2,1200.7,'2022-05-02'),(3,800.4,'2022-05-03'); | UPDATE residential SET water_usage = 1000 WHERE customer_id = (SELECT customer_id FROM residential WHERE usage_date BETWEEN '2022-05-01' AND '2022-05-31' ORDER BY water_usage DESC LIMIT 1); |
What is the average explainability score for models trained on the 'south_american_education' dataset? | CREATE TABLE south_american_education (model_name TEXT,explainability_score FLOAT); INSERT INTO south_american_education (model_name,explainability_score) VALUES ('model1',0.92),('model2',0.89),('model3',0.95); | SELECT AVG(explainability_score) FROM south_american_education; |
What is the distribution of AI models across different countries? | CREATE TABLE ai_models (model_name TEXT,model_country TEXT); INSERT INTO ai_models (model_name,model_country) VALUES ('ModelA','USA'),('ModelB','Germany'),('ModelC','China'),('ModelD','Brazil'); | SELECT model_country, COUNT(*) FROM ai_models GROUP BY model_country; |
What is the average age of all astronauts who have flown missions to the International Space Station? | CREATE TABLE Astronauts (AstronautID INT,Name VARCHAR(100),Age INT,SpaceStation VARCHAR(50)); | SELECT AVG(Age) FROM Astronauts WHERE SpaceStation = 'International Space Station'; |
How many habitats are in the 'animal_habitats' table? | CREATE TABLE animal_habitats (id INT PRIMARY KEY,habitat_name VARCHAR,num_animals INT); | SELECT COUNT(*) FROM animal_habitats; |
What is the total number of community education programs held in Texas and California? | CREATE TABLE community_ed (program_id INT,location VARCHAR(50)); INSERT INTO community_ed (program_id,location) VALUES (1,'California'),(2,'Texas'),(3,'California'),(4,'Florida'); | SELECT COUNT(*) FROM community_ed WHERE location IN ('Texas', 'California'); |
How many farms in Region3 have a harvest yield above the average for that region? | CREATE TABLE FarmsRegion (farm_id INT,region VARCHAR(10),harvest_yield FLOAT); INSERT INTO FarmsRegion (farm_id,region,harvest_yield) VALUES (1,'Region3',900),(2,'Region3',850),(3,'Region3',950),(4,'Region3',700); | SELECT farm_id FROM FarmsRegion WHERE region = 'Region3' GROUP BY farm_id HAVING AVG(harvest_yield) < harvest_yield; |
What is the average biomass of Cuttlefish and Squid in Mediterranean marine farms? | CREATE TABLE mediterranean_marine_farms (farm_id INT,species VARCHAR(20),biomass FLOAT); INSERT INTO mediterranean_marine_farms (farm_id,species,biomass) VALUES (1,'Cuttlefish',300.2),(2,'Squid',400.1),(3,'Cuttlefish',350.3); | SELECT AVG(biomass) average_biomass FROM mediterranean_marine_farms WHERE species IN ('Cuttlefish', 'Squid'); |
What is the total number of visitors from African countries who attended events in 2021? | CREATE TABLE events (event_id INT,event_name VARCHAR(50),event_year INT,location VARCHAR(50)); INSERT INTO events (event_id,event_name,event_year,location) VALUES (1,'Music Festival',2021,'Nigeria'),(2,'Art Exhibition',2022,'Egypt'),(3,'Theater Performance',2021,'South Africa'); CREATE TABLE countries (country_id INT,country_name VARCHAR(50),continent VARCHAR(50)); INSERT INTO countries (country_id,country_name,continent) VALUES (1,'Nigeria','Africa'),(2,'Egypt','Africa'),(3,'South Africa','Africa'),(4,'Brazil','South America'); CREATE TABLE attendees (attendee_id INT,event_id INT,country_id INT); INSERT INTO attendees (attendee_id,event_id,country_id) VALUES (1,1,1),(2,1,2),(3,3,3); | SELECT COUNT(*) FROM attendees JOIN events ON attendees.event_id = events.event_id JOIN countries ON attendees.country_id = countries.country_id WHERE events.event_year = 2021 AND countries.continent = 'Africa'; |
Find TV shows with a higher IMDb rating than the average movie rating. | CREATE TABLE movie (id INT,title VARCHAR(50),rating DECIMAL(3,2)); CREATE TABLE tv_show (id INT,title VARCHAR(50),rating DECIMAL(3,2)); INSERT INTO movie (id,title,rating) VALUES (1,'Movie1',8.5),(2,'Movie2',6.7),(3,'Movie3',9.1); INSERT INTO tv_show (id,title,rating) VALUES (1,'TVShow1',8.8),(2,'TVShow2',7.2),(3,'TVShow3',9.0); | SELECT title FROM tv_show WHERE rating > (SELECT AVG(rating) FROM movie); |
What is the average cost of sustainable building materials used in green projects in the city of Seattle? | CREATE TABLE Green_Projects (Project_ID INT,Building_Material VARCHAR(50),Cost FLOAT,City VARCHAR(50)); INSERT INTO Green_Projects (Project_ID,Building_Material,Cost,City) VALUES (1,'Recycled Steel',800,'Seattle'),(2,'Insulated Concrete Forms',1200,'Seattle'); | SELECT AVG(Cost) FROM Green_Projects WHERE City = 'Seattle' AND Building_Material IN ('Recycled Steel', 'Insulated Concrete Forms'); |
What is the total cost of permits for projects with permit numbers greater than 700? | CREATE TABLE permit_data (id INT,project VARCHAR(50),permit_number INT,start_date DATE,permit_cost DECIMAL(10,2)); INSERT INTO permit_data (id,project,permit_number,start_date,permit_cost) VALUES (1,'Office Building',450,'2019-12-20',850.00),(2,'Residential Apartments',751,'2021-03-01',1200.50),(3,'School',333,'2020-06-15',500.25),(4,'Mall',780,'2020-12-01',1500.75); | SELECT SUM(permit_cost) FROM permit_data WHERE permit_number > 700; |
List all cases where the client is from 'California' and the attorney is 'Smith' | CREATE TABLE cases (case_id INT,client_state VARCHAR(2),attorney_name VARCHAR(20)); | SELECT * FROM cases WHERE client_state = 'CA' AND attorney_name = 'Smith'; |
What is the average age of clients who lost cases in the 'personal injury' category? | CREATE TABLE Cases (CaseID int,ClientID int,Category varchar(50)); INSERT INTO Cases (CaseID,ClientID,Category) VALUES (701,7,'Personal Injury'); CREATE TABLE Clients (ClientID int,Age int,Gender varchar(10)); INSERT INTO Clients (ClientID,Age,Gender) VALUES (7,45,'Male'); CREATE TABLE CaseOutcomes (CaseID int,Outcome varchar(50)); INSERT INTO CaseOutcomes (CaseID,Outcome) VALUES (701,'Lost'); | SELECT AVG(C.Age) as AvgAge FROM Clients C INNER JOIN Cases CA ON C.ClientID = CA.ClientID INNER JOIN CaseOutcomes CO ON CA.CaseID = CO.CaseID WHERE CA.Category = 'Personal Injury' AND CO.Outcome = 'Lost'; |
Calculate the average environmental impact score of production sites in Australia, partitioned by state in ascending order. | CREATE TABLE australian_sites (site_id INT,site_name TEXT,state TEXT,environmental_score FLOAT); INSERT INTO australian_sites (site_id,site_name,state,environmental_score) VALUES (1,'Site Q','New South Wales',87.3),(2,'Site R','Victoria',84.5),(3,'Site S','New South Wales',89.1),(4,'Site T','Queensland',86.2); | SELECT state, AVG(environmental_score) as avg_environmental_score, RANK() OVER (PARTITION BY state ORDER BY AVG(environmental_score)) as rank FROM australian_sites GROUP BY state ORDER BY rank; |
How many new drugs were approved by the EMA in 2020? | CREATE TABLE drug_approval(drug_id INT,agency VARCHAR(255),approval_date DATE); INSERT INTO drug_approval(drug_id,agency,approval_date) VALUES (1,'FDA','2020-01-01'),(2,'EMA','2019-12-15'),(3,'FDA','2021-02-01'); | SELECT COUNT(*) as new_drugs_approved FROM drug_approval WHERE agency = 'EMA' AND YEAR(approval_date) = 2020; |
What is the market access strategy for the drug 'Nexo' in South America? | CREATE TABLE market_access (drug_name TEXT,strategy TEXT,region TEXT); INSERT INTO market_access (drug_name,strategy,region) VALUES ('Vaxo','Direct to consumer','United States'),('Nexo','Limited distribution','Brazil'); | SELECT strategy FROM market_access WHERE drug_name = 'Nexo' AND region = 'South America'; |
What is the total revenue for 'HealthCo' from drug sales in 2018? | CREATE TABLE HealthCo_DrugSales(company VARCHAR(20),year INT,revenue DECIMAL(10,2));INSERT INTO HealthCo_DrugSales VALUES('HealthCo',2018,15000000.00); | SELECT SUM(revenue) FROM HealthCo_DrugSales WHERE company = 'HealthCo' AND year = 2018; |
Which countries have the highest R&D expenditures in the pharmaceuticals industry? | CREATE TABLE country (country_code CHAR(2),country_name VARCHAR(100)); INSERT INTO country (country_code,country_name) VALUES ('US','United States'),('DE','Germany'),('JP','Japan'); CREATE TABLE rd_expenditure (country_code CHAR(2),amount FLOAT); INSERT INTO rd_expenditure (country_code,amount) VALUES ('US',81231.56),('DE',62311.23),('JP',38002.98); | SELECT c.country_name, rd.amount FROM country c INNER JOIN rd_expenditure rd ON c.country_code = rd.country_code ORDER BY rd.amount DESC; |
Which drugs were approved by the FDA in 2020? | CREATE TABLE fda_approval (drug varchar(255),year int); INSERT INTO fda_approval (drug,year) VALUES ('DrugA',2020),('DrugC',2020); | SELECT drug FROM fda_approval WHERE year = 2020; |
What are the policies related to mobility and communication accommodations that were effective on or before January 1, 2022? | CREATE TABLE policies (id INT,policy_type VARCHAR(255),policy_text TEXT,policy_effective_date DATE); INSERT INTO policies (id,policy_type,policy_text,policy_effective_date) VALUES (5,'Mobility accommodations','Provides mobility accommodations for students with disabilities','2021-07-01'),(6,'Communication accommodations','Provides communication accommodations for students with disabilities','2022-01-01'); | SELECT p.policy_type, p.policy_text, YEAR(p.policy_effective_date) as year FROM policies p WHERE p.policy_type IN ('Mobility accommodations', 'Communication accommodations') AND p.policy_effective_date <= '2022-01-01' ORDER BY year DESC; |
How many marine species are affected by ocean acidification? | CREATE TABLE species_impact (id INTEGER,name VARCHAR(255),species VARCHAR(255),affected_by_acidification BOOLEAN); | SELECT COUNT(*) FROM species_impact WHERE affected_by_acidification = TRUE; |
List all the wildlife species that inhabit coniferous forests. | CREATE TABLE wildlife_habitat (species VARCHAR(255),forest_type VARCHAR(255)); | SELECT species FROM wildlife_habitat WHERE forest_type = 'coniferous'; |
Which countries source more than 5 ingredients? | CREATE TABLE ingredients (id INT,product_id INT,name VARCHAR(255),country VARCHAR(255)); INSERT INTO ingredients (id,product_id,name,country) VALUES (1,1,'Aloe Vera','Mexico'),(2,1,'Rosehip Oil','Chile'),(3,2,'Jojoba Oil','Brazil'),(4,2,'Green Tea Extract','Japan'),(5,3,'Cucumber Extract','France'),(6,4,'Shea Butter','Ghana'),(7,4,'Argan Oil','Morocco'),(8,4,'Lavender Essence','France'),(9,5,'Coconut Oil','Philippines'),(10,5,'Tea Tree Oil','Australia'); | SELECT country, COUNT(*) FROM ingredients GROUP BY country HAVING COUNT(*) > 5; |
Find the cosmetics with the lowest sales in each category, for the past 9 months, in Asia. | CREATE TABLE sales_by_month (product_id INT,sale_date DATE,sales INT,product_category VARCHAR(50),region VARCHAR(50)); INSERT INTO sales_by_month (product_id,sale_date,sales,product_category,region) VALUES (1,'2021-04-01',500,'Foundation','Asia'),(2,'2021-04-01',800,'Lipstick','Asia'); | SELECT product_category, product_id, MIN(sales) AS min_sales FROM sales_by_month WHERE sale_date >= DATEADD(month, -9, CURRENT_DATE) AND region = 'Asia' GROUP BY product_category, product_id; |
What is the average number of artworks donated by artists per year, for artists who have donated artworks for at least 5 years? | CREATE TABLE Artists (ArtistID int,ArtistName varchar(50),FirstDonationYear int,NumberOfArtworks int);INSERT INTO Artists (ArtistID,ArtistName,FirstDonationYear,NumberOfArtworks) VALUES (1,'Pablo Picasso',1960,500),(2,'Vincent Van Gogh',1970,450),(3,'Claude Monet',1980,350); | SELECT AVG(NumberOfArtworks) FROM Artists WHERE FirstDonationYear <= YEAR(CURRENT_DATE) - 5 AND NumberOfArtworks > 0; |
What is the veteran employment rate in Texas as of December 2021? | CREATE TABLE veteran_employment (state varchar(255),employment_date date,employment_rate decimal(5,2)); | SELECT employment_rate FROM veteran_employment WHERE state = 'Texas' AND MONTH(employment_date) = 12 AND YEAR(employment_date) = 2021; |
How many peacekeeping operations were conducted by each regional command in the 'peacekeeping_operations' and 'regional_commands' tables? | CREATE TABLE regional_commands (command_id INT,command_name VARCHAR(50)); CREATE TABLE peacekeeping_operations (operation_id INT,operation_name VARCHAR(50),command_id INT); INSERT INTO regional_commands VALUES (1,'AFRICOM'),(2,'CENTCOM'),(3,'EUCOM'); INSERT INTO peacekeeping_operations VALUES (1,'MINUSTAH',1),(2,'UNMIL',1),(3,'MONUSCO',2),(4,'UNMISS',3),(5,'MINUSMA',2); | SELECT r.command_name, COUNT(p.operation_id) as operations_conducted FROM regional_commands r JOIN peacekeeping_operations p ON r.command_id = p.command_id GROUP BY r.command_name; |
Find the top 5 salespeople by total sales | CREATE TABLE salesperson_sales (salesperson_id INT,sales_region VARCHAR(50),amount DECIMAL(10,2)); INSERT INTO salesperson_sales (salesperson_id,sales_region,amount) VALUES (1,'Americas',500.00),(1,'Asia',700.00),(2,'Asia',800.00),(3,'Europe',900.00),(3,'Asia',1000.00); | SELECT salesperson_id, SUM(amount) as total_sales FROM salesperson_sales GROUP BY salesperson_id ORDER BY total_sales DESC LIMIT 5; |
How many transactions were made in each region for the 'Credit Cards' product type? | CREATE TABLE regions (id INT,region_name VARCHAR(50)); INSERT INTO regions (id,region_name) VALUES (1,'Northeast'),(2,'Southeast'); CREATE TABLE transactions (region_id INT,product_type_id INT,transaction_count INT); INSERT INTO transactions (region_id,product_type_id,transaction_count) VALUES (1,1,20),(1,1,30),(2,1,10),(2,1,40); | SELECT r.region_name, p.product_type, SUM(t.transaction_count) as total_transactions FROM regions r JOIN transactions t ON r.id = t.region_id JOIN product_types p ON t.product_type_id = p.id WHERE p.product_type = 'Credit Cards' GROUP BY r.region_name, p.product_type; |
What is the average donation amount for the 'Education' program? | CREATE TABLE Donations (donation_id INT,amount DECIMAL(10,2),program VARCHAR(255)); | SELECT AVG(amount) FROM Donations WHERE program = 'Education'; |
Which programs had the highest volunteer participation rate in the last quarter? | CREATE TABLE Programs (ProgramID INT,ProgramName TEXT,Budget DECIMAL(10,2),NumVolunteers INT); CREATE TABLE VolunteerEvents (EventID INT,ProgramID INT,EventDate DATE,NumVolunteers INT); | SELECT p.ProgramName, COUNT(v.EventID) / (SELECT COUNT(*) FROM VolunteerEvents WHERE EventDate >= DATEADD(quarter, -1, GETDATE())) * 100.0 AS VolunteerParticipationRate FROM Programs p INNER JOIN VolunteerEvents v ON p.ProgramID = v.ProgramID WHERE v.EventDate >= DATEADD(quarter, -1, GETDATE()) GROUP BY p.ProgramName ORDER BY VolunteerParticipationRate DESC; |
How many professional development courses did teachers complete in each institution? | CREATE TABLE teacher_professional_development (teacher_id INT,institution_id INT,course_count INT); | SELECT institution_id, SUM(course_count) as total_courses FROM teacher_professional_development GROUP BY institution_id; |
What is the average number of professional development courses taken by teachers in each school district, grouped by district and ordered by the average number in descending order? | CREATE TABLE school_districts (district_id INT,district_name TEXT); CREATE TABLE teachers (teacher_id INT,district_id INT,num_courses INT); | SELECT sd.district_name, AVG(t.num_courses) as avg_num_courses FROM teachers t JOIN school_districts sd ON t.district_id = sd.district_id GROUP BY sd.district_name ORDER BY avg_num_courses DESC; |
What is the average open pedagogy participation score for students in each grade level? | CREATE TABLE student_open_pedagogy (student_id INT,grade_level INT,participation_score INT); INSERT INTO student_open_pedagogy (student_id,grade_level,participation_score) VALUES (1,6,85),(2,6,90),(3,7,75),(4,7,80),(5,8,95); | SELECT grade_level, AVG(participation_score) as avg_participation_score FROM student_open_pedagogy GROUP BY grade_level; |
List the ethnicity and number of employees in management positions from the "diversity" and "positions" tables | CREATE TABLE diversity (id INT,employee_id INT,ethnicity TEXT); CREATE TABLE positions (id INT,employee_id INT,position_title TEXT,is_management BOOLEAN); | SELECT diversity.ethnicity, positions.position_title, COUNT(*) as count FROM diversity JOIN positions ON diversity.employee_id = positions.employee_id WHERE positions.is_management = TRUE GROUP BY diversity.ethnicity, positions.position_title; |
What is the number of new hires by quarter? | CREATE TABLE Employees (EmployeeID int,FirstName varchar(50),LastName varchar(50),JobRole varchar(50),Ethnicity varchar(50),Salary decimal(10,2),HireDate date); INSERT INTO Employees (EmployeeID,FirstName,LastName,JobRole,Ethnicity,Salary,HireDate) VALUES (1,'Sophia','Gonzales','Software Engineer','Hispanic',85000,'2022-01-01'); INSERT INTO Employees (EmployeeID,FirstName,LastName,JobRole,Ethnicity,Salary,HireDate) VALUES (2,'Liam','Johnson','Data Analyst','Caucasian',70000,'2022-04-01'); | SELECT DATE_PART('quarter', HireDate) as Quarter, COUNT(*) as NewHires FROM Employees GROUP BY Quarter; |
What is the total number of job applications received per month in 2021? | CREATE TABLE job_applications (id INT,application_date DATE,application_status VARCHAR(255)); INSERT INTO job_applications (id,application_date,application_status) VALUES (1,'2021-01-15','Submitted'),(2,'2021-02-03','Submitted'),(3,'2021-12-30','Submitted'),(4,'2022-01-01','Submitted'); | SELECT DATE_FORMAT(application_date, '%Y-%m') as month, COUNT(id) as applications_received FROM job_applications WHERE YEAR(application_date) = 2021 GROUP BY month; |
What is the number of renewable energy patents issued per year for the top 3 countries? | CREATE TABLE Patent (Year INT,Country VARCHAR(50),Type VARCHAR(50)); INSERT INTO Patent (Year,Country,Type) VALUES (2018,'Country1','Renewable'),(2018,'Country2','Renewable'),(2018,'Country3','Renewable'),(2019,'Country1','Renewable'),(2019,'Country2','Renewable'),(2019,'Country3','Renewable'); | SELECT Year, Country, COUNT(*) AS RenewableEnergyPatents FROM Patent WHERE Type = 'Renewable' GROUP BY Year, Country ORDER BY Year, COUNT(*) DESC FETCH FIRST 3 ROWS ONLY; |
Calculate the total gas consumption for Nigeria in 2019 | CREATE TABLE gas_consumption (country VARCHAR(50),consumption_year INT,gas_consumption FLOAT); INSERT INTO gas_consumption (country,consumption_year,gas_consumption) VALUES ('Nigeria',2019,12000),('Nigeria',2018,10000),('Ghana',2019,8000),('Ghana',2018,6000),('Ivory Coast',2019,10000),('Ivory Coast',2018,8000); | SELECT gas_consumption FROM gas_consumption WHERE country = 'Nigeria' AND consumption_year = 2019; |
What is the total production of oil from the North Sea field in 2020? | CREATE TABLE north_sea_fields (field_id INT,field_name VARCHAR(50),oil_production FLOAT); INSERT INTO north_sea_fields (field_id,field_name,oil_production) VALUES (1,'North Sea Field A',1500000),(2,'North Sea Field B',1800000); | SELECT SUM(oil_production) FROM north_sea_fields WHERE field_name = 'North Sea Field A' AND YEAR(datetime) = 2020; |
How many healthcare facilities are there in the 'africa' region? | CREATE TABLE region (region_id INT,name VARCHAR(50)); INSERT INTO region (region_id,name) VALUES (1,'asia'),(2,'africa'); CREATE TABLE sector (sector_id INT,name VARCHAR(50)); INSERT INTO sector (sector_id,name) VALUES (1,'education'),(2,'health'); CREATE TABLE healthcare (healthcare_id INT,name VARCHAR(50),region_id INT); INSERT INTO healthcare (healthcare_id,name,region_id) VALUES (1,'Facility A',2),(2,'Facility B',2),(3,'Facility C',1); | SELECT COUNT(*) FROM healthcare WHERE region_id = 2; |
List all the unique sectors in which projects have been funded in Asia. | CREATE TABLE projects (id INT,sector TEXT,location TEXT,funding_amount DECIMAL); INSERT INTO projects (id,sector,location,funding_amount) VALUES (1,'Health','Asia',10000.00),(2,'Education','Africa',15000.00); | SELECT DISTINCT sector FROM projects WHERE location = 'Asia'; |
Find the number of available parking spots at each station on the Orange Line. | CREATE TABLE Parking (station VARCHAR(20),line VARCHAR(20),spots INTEGER); INSERT INTO Parking (station,line,spots) VALUES ('North Station','Orange Line',50),('Back Bay','Orange Line',30); | SELECT station, spots FROM Parking WHERE line = 'Orange Line'; |
What are the unique vehicle types and their respective total fares collected? | CREATE TABLE Fares (id INT,vehicle_type VARCHAR(10),fare DECIMAL(5,2)); INSERT INTO Fares (id,vehicle_type,fare) VALUES (1,'Bus',2.50),(2,'Tram',3.00),(3,'Train',5.00); | SELECT vehicle_type, SUM(fare) FROM Fares GROUP BY vehicle_type; |
What is the earliest and latest time that a vehicle has operated on each route? | CREATE TABLE routes (route_id INT,route_name TEXT);CREATE TABLE vehicles (vehicle_id INT,route_id INT,operation_time TIME); INSERT INTO routes VALUES (123,'Route 123'); INSERT INTO routes VALUES (456,'Route 456'); INSERT INTO vehicles VALUES (1,123,'06:00:00'); INSERT INTO vehicles VALUES (2,123,'06:30:00'); INSERT INTO vehicles VALUES (3,456,'07:00:00'); INSERT INTO vehicles VALUES (4,456,'07:30:00'); | SELECT routes.route_name, MIN(vehicles.operation_time) as earliest_time, MAX(vehicles.operation_time) as latest_time FROM routes INNER JOIN vehicles ON routes.route_id = vehicles.route_id GROUP BY routes.route_name; |
How many units of each product were sold in the last quarter, by salesperson? | CREATE TABLE sales (sale_date DATE,salesperson VARCHAR(255),product VARCHAR(255),quantity INT); | SELECT salesperson, product, SUM(quantity) AS qty_sold, DATE_TRUNC('quarter', sale_date) AS sale_quarter FROM sales WHERE sale_date >= DATE_TRUNC('quarter', CURRENT_DATE - INTERVAL '1 year') GROUP BY salesperson, product, sale_quarter; |
Which factories in Colombia have a production cost between 100 and 200? | CREATE TABLE producers (id INT,name VARCHAR(255),location VARCHAR(255),cost DECIMAL(10,2)); INSERT INTO producers (id,name,location,cost) VALUES (1,'Fabric Inc','Colombia',150.00),(2,'Stitch Time','USA',120.00),(3,'Sew Good','Colombia',170.00); | SELECT name, cost FROM producers WHERE location = 'Colombia' AND cost BETWEEN 100 AND 200; |
How many users have more than 1000 followers and have posted at least once in the past week? | CREATE TABLE users (id INT,name VARCHAR(50),country VARCHAR(2),followers INT,timestamp DATETIME); INSERT INTO users (id,name,country,followers,timestamp) VALUES (1,'Alice','US',1200,'2022-02-01 10:00:00'),(2,'Bob','JP',800,'2022-01-01 11:00:00'),(3,'Charlie','CA',1600,'2022-02-03 12:00:00'); | SELECT COUNT(*) as user_count FROM users WHERE users.followers > 1000 AND users.timestamp >= DATE_SUB(NOW(), INTERVAL 1 WEEK); |
How many unique donors made donations in the healthcare industry in Q3 2022? | CREATE TABLE donations (id INT,donor_id INT,amount FLOAT,donation_date DATE); INSERT INTO donations (id,donor_id,amount,donation_date) VALUES (1,7,100,'2022-07-01'); INSERT INTO donations (id,donor_id,amount,donation_date) VALUES (2,8,200,'2022-09-15'); INSERT INTO donors (id,name,industry,first_donation_date DATE) VALUES (7,'Charlie Davis','Healthcare','2022-07-01'); INSERT INTO donors (id,name,industry,first_donation_date DATE) VALUES (8,'Dana Wilson','Healthcare','2022-09-15'); | SELECT COUNT(DISTINCT donor_id) FROM donations d JOIN donors don ON d.donor_id = don.id WHERE industry = 'Healthcare' AND donation_date BETWEEN '2022-07-01' AND '2022-09-30'; |
How many biosensors were developed in 2021? | CREATE TABLE biosensor_development (name TEXT,year INT); INSERT INTO biosensor_development (name,year) VALUES ('BioSensor1',2020); INSERT INTO biosensor_development (name,year) VALUES ('BioSensor2',2021); | SELECT COUNT(*) FROM biosensor_development WHERE year = 2021; |
What is the average salary of male and female employees in the 'employees' table, grouped by job title? | CREATE TABLE employees (id INT,name VARCHAR(50),gender VARCHAR(10),salary FLOAT,job_title VARCHAR(50)); INSERT INTO employees (id,name,gender,salary,job_title) VALUES (1,'John Doe','Male',60000,'Manager'),(2,'Jane Smith','Female',65000,'Manager'),(3,'Mike Johnson','Male',50000,'Developer'),(4,'Emily Davis','Female',52000,'Developer'); | SELECT job_title, AVG(salary) as avg_salary FROM employees GROUP BY job_title, gender; |
How many users engaged with virtual tours in 'Europe' during each month of 2022? | CREATE TABLE virtual_tours (tour_id INT,user_id INT,country VARCHAR(255),tour_date DATE); INSERT INTO virtual_tours (tour_id,user_id,country,tour_date) VALUES (1,1001,'France','2022-02-03'),(2,1002,'Germany','2022-04-10'),(3,1003,'Italy','2022-01-15'); | SELECT country, EXTRACT(MONTH FROM tour_date) AS month, COUNT(DISTINCT user_id) FROM virtual_tours WHERE country = 'Europe' AND tour_date BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY country, month; |
What is the minimum and maximum age of patients by condition? | CREATE TABLE PatientAges (PatientID int,ConditionID int,Age int); INSERT INTO PatientAges (PatientID,ConditionID,Age) VALUES (1,1,30),(2,2,35); | SELECT Conditions.Condition, MIN(PatientAges.Age), MAX(PatientAges.Age) FROM PatientAges JOIN Conditions ON PatientAges.ConditionID = Conditions.ConditionID GROUP BY Conditions.Condition; |
How many tunnels are there in New York with a length greater than 5 miles? | CREATE TABLE Tunnels (id INT,name TEXT,location TEXT,state TEXT,length FLOAT); INSERT INTO Tunnels (id,name,location,state,length) VALUES (1,'Tunnel A','Location A','New York',7.5),(2,'Tunnel B','Location B','New Jersey',4.5); | SELECT COUNT(*) FROM Tunnels WHERE state = 'New York' AND length > 5; |
List the dams in California | CREATE TABLE Dams (id INT,name TEXT,height INT,reservoir TEXT,state TEXT); INSERT INTO Dams (id,name,height,reservoir,state) VALUES (1,'Hoover Dam',221,'Lake Mead','Nevada'); INSERT INTO Dams (id,name,height,reservoir,state) VALUES (2,'Oroville Dam',230,'Lake Oroville','California'); | SELECT name FROM Dams WHERE state = 'California'; |
Delete all records in the sustainable_tourism_campaigns table where the campaign_name is 'Green Tourism Initiative' | CREATE TABLE sustainable_tourism_campaigns (campaign_id INT PRIMARY KEY,campaign_name VARCHAR(255),start_date DATE,end_date DATE); | DELETE FROM sustainable_tourism_campaigns WHERE campaign_name = 'Green Tourism Initiative'; |
How many legal tech events have taken place in New York and California? | CREATE TABLE legal_tech_events (event_id INT,location VARCHAR(255)); INSERT INTO legal_tech_events (event_id,location) VALUES (1,'New York'),(2,'California'),(3,'Texas'); | SELECT COUNT(*) FROM legal_tech_events WHERE location IN ('New York', 'California'); |
What is the average media literacy score for users in the 'Young Adult' age group who have completed at least one disinformation detection course? | CREATE TABLE users (id INT,age VARCHAR(20),media_literacy_score INT,courses_completed INT); | SELECT AVG(media_literacy_score) FROM users WHERE age = 'Young Adult' AND courses_completed > 0; |
Increase the price of all vegetarian menu items by 10% | CREATE TABLE menu_items (item_id INT,item_name VARCHAR(50),is_vegetarian BOOLEAN,price DECIMAL(5,2)); INSERT INTO menu_items (item_id,item_name,is_vegetarian,price) VALUES (1,'Steak',false,25.99),(2,'Salad',true,12.49),(3,'Pizza',true,16.99),(4,'Pasta',false,18.99),(5,'Soda',false,2.99); | UPDATE menu_items SET price = price * 1.10 WHERE is_vegetarian = true; |
What is the total CO2 emission of each menu item, considering its ingredients and their origin? | CREATE TABLE menu_items (menu_id INT,name VARCHAR(50),co2_emission FLOAT); CREATE TABLE ingredients (ingredient_id INT,name VARCHAR(50),origin VARCHAR(50),co2_emission_per_kg FLOAT); CREATE TABLE recipe (menu_id INT,ingredient_id INT,quantity FLOAT); | SELECT m.name, SUM(i.co2_emission_per_kg * r.quantity) as total_co2_emission FROM menu_items m JOIN recipe r ON m.menu_id = r.menu_id JOIN ingredients i ON r.ingredient_id = i.ingredient_id GROUP BY m.menu_id; |
Which defense projects had a delay of more than 30 days in their timelines in the last 6 months? | CREATE TABLE Defense_Projects (project_id INT,project_start_date DATE,project_end_date DATE,project_status VARCHAR(50)); | SELECT project_id, project_start_date, project_end_date, DATEDIFF(day, project_start_date, project_end_date) as project_duration FROM Defense_Projects WHERE project_end_date BETWEEN DATEADD(month, -6, GETDATE()) AND GETDATE() AND DATEDIFF(day, project_start_date, project_end_date) > 30; |
Determine the number of mines in Colombia with environmental impact assessments that exceed 80 points. | CREATE TABLE mines (id INT,name TEXT,location TEXT,eia_score INT); INSERT INTO mines (id,name,location,eia_score) VALUES (1,'Emerald Mine','Colombia',85); INSERT INTO mines (id,name,location,eia_score) VALUES (2,'Ruby Mine','Colombia',70); | SELECT COUNT(*) FROM mines WHERE location = 'Colombia' AND eia_score > 80; |
List the labor productivity metrics for each mine, including the total amount of minerals extracted and the number of employees, and calculate the productivity metric for each mine. | CREATE TABLE labor_productivity (mine_id INT,amount_extracted INT,num_employees INT); INSERT INTO labor_productivity (mine_id,amount_extracted,num_employees) VALUES (1,1000,50),(1,1200,60),(2,800,40),(2,900,45); CREATE TABLE mines (mine_id INT,mine_name TEXT); INSERT INTO mines (mine_id,mine_name) VALUES (1,'MineA'),(2,'MineB'); | SELECT m.mine_name, AVG(lp.amount_extracted / lp.num_employees) AS productivity_metric FROM labor_productivity lp JOIN mines m ON lp.mine_id = m.mine_id GROUP BY m.mine_name; |
What is the total amount of mineral extraction by type? | CREATE TABLE extraction (extraction_id INT,mine_id INT,year INT,mineral VARCHAR(255),quantity INT); INSERT INTO extraction (extraction_id,mine_id,year,mineral,quantity) VALUES (1,1,2018,'Gold',1000),(2,1,2019,'Gold',1200),(3,2,2018,'Uranium',2000),(4,2,2019,'Uranium',2500); | SELECT mineral, SUM(quantity) FROM extraction GROUP BY mineral; |
Display the names and total donation amounts for nonprofits that offer programs in both the Education and Health categories, excluding any duplicate records. | CREATE TABLE nonprofits (id INT,name TEXT,state TEXT,program TEXT,category TEXT,donation_amount FLOAT); INSERT INTO nonprofits (id,name,state,program,category,donation_amount) VALUES (1,'Nonprofit A','California','Math Education','Education',25000.00),(2,'Nonprofit B','California','Health Services','Health',50000.00),(3,'Nonprofit C','California','Environmental Conservation','Environment',35000.00),(4,'Nonprofit D','Texas','Arts Education','Education',60000.00),(5,'Nonprofit E','New York','Social Services','Other',15000.00),(6,'Nonprofit F','Florida','Disaster Relief','Other',70000.00),(7,'Nonprofit G','California','Science Education','Education',40000.00),(8,'Nonprofit H','California','Mental Health Services','Health',45000.00); | SELECT name, SUM(donation_amount) as total_donation FROM nonprofits WHERE category IN ('Education', 'Health') GROUP BY name; |
List all eSports tournaments that don't have a winner yet. | CREATE TABLE Tournaments (TournamentID INT PRIMARY KEY,Name VARCHAR(50),GameID INT,Date DATE,Winner VARCHAR(50)); INSERT INTO Tournaments (TournamentID,Name,GameID,Date,Winner) VALUES (1,'Tournament A',1,'2021-04-01','Team USA'); INSERT INTO Tournaments (TournamentID,Name,GameID,Date,Winner) VALUES (2,'Tournament B',2,'2021-05-15',''); INSERT INTO Tournaments (TournamentID,Name,GameID,Date,Winner) VALUES (3,'Tournament C',3,'2021-06-30','Team Europe'); | SELECT * FROM Tournaments WHERE Winner IS NULL; |
What is the average playtime in minutes for players who have achieved a rank of Gold or higher in the game "Galactic Conquest"? | CREATE TABLE GalacticConquestPlayers (PlayerID INT,PlayerName VARCHAR(50),PlaytimeMinutes INT,Rank VARCHAR(10)); INSERT INTO GalacticConquestPlayers VALUES (1,'JohnDoe',500,'Gold'),(2,'JaneDoe',700,'Platinum'),(3,'BobSmith',300,'Silver'),(4,'AliceJohnson',800,'Gold'); | SELECT AVG(PlaytimeMinutes) FROM GalacticConquestPlayers WHERE Rank IN ('Gold', 'Platinum'); |
Update the "city_budget_summary" table to mark the "Education" budget as approved | CREATE TABLE city_budget_summary (budget_category VARCHAR(50),budget_amount DECIMAL(10,2),budget_status VARCHAR(20)); | UPDATE city_budget_summary SET budget_status = 'approved' WHERE budget_category = 'Education'; |
List the co-owners and their shared property addresses in Portland, OR. | CREATE TABLE co_owners (id INT,name VARCHAR(30),property_id INT); CREATE TABLE properties (id INT,address VARCHAR(50),city VARCHAR(20)); INSERT INTO co_owners (id,name,property_id) VALUES (1,'Alex',101),(2,'Bella',101); INSERT INTO properties (id,address,city) VALUES (101,'1234 SE Stark St','Portland'),(102,'5678 NE 20th Ave','Portland'); | SELECT co_owners.name, properties.address FROM co_owners INNER JOIN properties ON co_owners.property_id = properties.id WHERE properties.city = 'Portland'; |
Which cuisine type has the highest average food safety score? | CREATE TABLE inspections (id INT,restaurant VARCHAR(50),cuisine VARCHAR(50),score INT); INSERT INTO inspections (id,restaurant,cuisine,score) VALUES (1,'Restaurant A','Italian',90),(2,'Restaurant B','Mexican',95),(3,'Restaurant C','Chinese',88),(4,'Restaurant D','Indian',97),(5,'Restaurant E','Japanese',92),(6,'Restaurant F','Thai',89); | SELECT cuisine, AVG(score) as avg_score FROM inspections GROUP BY cuisine ORDER BY avg_score DESC LIMIT 1; |
How many satellites have been launched by SpaceX each year? | CREATE TABLE satellites (id INT,name VARCHAR(255),launch_company VARCHAR(255),launch_date DATE); | SELECT EXTRACT(YEAR FROM launch_date) as launch_year, COUNT(*) as num_satellites FROM satellites WHERE launch_company = 'SpaceX' GROUP BY launch_year; |
Insert a new spacecraft with ID 6, name 'Spacecraft F', manufacturing date '2022-03-01', country 'Canada', and duration in space 0. | CREATE TABLE Spacecraft (ID INT,Name VARCHAR(50),ManufacturingDate DATE,Country VARCHAR(50),DurationInSpace INT); INSERT INTO Spacecraft VALUES (1,'Spacecraft A','2010-01-01','USA',2500),(2,'Spacecraft B','2012-05-15','China',3000),(3,'Spacecraft C','2005-09-27','Russia',1800),(4,'Spacecraft D','2015-02-20','USA',1200),(5,'Spacecraft E','2008-07-06','China',1500); | INSERT INTO Spacecraft (ID, Name, ManufacturingDate, Country, DurationInSpace) VALUES (6, 'Spacecraft F', '2022-03-01', 'Canada', 0); |
What is the minimum launch cost for SpaceX missions? | CREATE TABLE SpaceXMissions (id INT,mission_name VARCHAR(255),launch_cost DECIMAL(10,2)); INSERT INTO SpaceXMissions (id,mission_name,launch_cost) VALUES (1,'Falcon 1 Flight 1',6500000.00),(2,'Dragon Flight 1',56000000.00); | SELECT MIN(launch_cost) FROM SpaceXMissions; |
What is the total mass of spacecraft launched by ESA before 2010? | CREATE TABLE SpacecraftManufacturing (manufacturer VARCHAR(255),spacecraft_name VARCHAR(255),mass FLOAT,launch_date DATE); INSERT INTO SpacecraftManufacturing (manufacturer,spacecraft_name,mass,launch_date) VALUES ('ESA','ATV Jules Verne',20000,'2008-03-09'),('ESA','ATV Johannes Kepler',20000,'2011-02-16'),('ESA','ATV Edoardo Amaldi',20000,'2012-03-23'); | SELECT SUM(mass) FROM SpacecraftManufacturing WHERE manufacturer = 'ESA' AND launch_date < '2010-01-01'; |
Which player has the highest batting average? | CREATE TABLE Players (Player VARCHAR(50),GamesPlayed INT,Hits INT); INSERT INTO Players VALUES ('Player1',10,12),('Player2',11,15),('Player3',12,18),('Player4',13,20); | SELECT Player, AVG(Hits / GamesPlayed) AS BattingAverage FROM Players GROUP BY Player ORDER BY BattingAverage DESC; |
Find the total number of vulnerabilities for each asset in the 'vulnerabilities' and 'assets' tables | CREATE TABLE assets (asset_id INT PRIMARY KEY,asset_name VARCHAR(255)); INSERT INTO assets (asset_id,asset_name) VALUES (1,'Server01'),(2,'Workstation01'); CREATE TABLE vulnerabilities (vulnerability_id INT PRIMARY KEY,asset_id INT,vulnerability_title VARCHAR(255)); INSERT INTO vulnerabilities (vulnerability_id,asset_id,vulnerability_title) VALUES (1,1,'Elevation of Privilege'),(2,1,'SQL Injection'),(3,2,'Cross-site Scripting'); | SELECT a.asset_name, COUNT(v.vulnerability_id) as total_vulnerabilities FROM assets a INNER JOIN vulnerabilities v ON a.asset_id = v.asset_id GROUP BY a.asset_name; |
What is the maximum number of passengers for autonomous ferries in New York City? | CREATE TABLE autonomous_ferries (ferry_id INT,passengers INT,city VARCHAR(50)); INSERT INTO autonomous_ferries (ferry_id,passengers,city) VALUES (1,150,'New York City'),(2,180,'New York City'),(3,200,'New York City'); | SELECT MAX(passengers) FROM autonomous_ferries WHERE city = 'New York City'; |
Find the top 3 policy types with the highest number of claims in Canada, ordered by the total claim amount in descending order. | CREATE TABLE Claims (PolicyType VARCHAR(20),ClaimAmount DECIMAL(10,2),PolicyholderCountry VARCHAR(50)); INSERT INTO Claims VALUES ('Auto',5000,'Canada'); INSERT INTO Claims VALUES ('Home',3000,'Canada'); INSERT INTO Claims VALUES ('Auto',4000,'Canada'); | SELECT PolicyType, COUNT(*) AS ClaimCount, SUM(ClaimAmount) AS TotalClaimAmount FROM Claims WHERE PolicyholderCountry = 'Canada' GROUP BY PolicyType ORDER BY TotalClaimAmount DESC, ClaimCount DESC LIMIT 3; |
What is the average number of safety issues in workplaces per city? | CREATE TABLE workplaces (id INT,city VARCHAR(10),safety_issues INT); INSERT INTO workplaces (id,city,safety_issues) VALUES (1,'New York',10),(2,'Los Angeles',5),(3,'Houston',15),(4,'Miami',8); CREATE TABLE cities (id INT,city VARCHAR(10)); INSERT INTO cities (id,city) VALUES (1,'New York'),(2,'Los Angeles'),(3,'Houston'),(4,'Miami'); | SELECT w.city, AVG(w.safety_issues) OVER (PARTITION BY w.city) AS avg_safety_issues FROM workplaces w INNER JOIN cities c ON w.city = c.city; |
What is the number of workers represented by the 'Teamsters' and 'UAW' unions? | CREATE TABLE if not exists union_membership (union_id INT,worker_id INT); CREATE TABLE if not exists unions (union_id INT,union_name TEXT,headquarters_address TEXT); INSERT INTO union_membership (union_id,worker_id) VALUES (1,1001),(1,1002),(1,1003),(2,2001),(2,2002),(3,3001); INSERT INTO unions (union_id,union_name,headquarters_address) VALUES (1,'United Steelworkers','60 Boulevard of the Allies,Pittsburgh,PA 15222'),(2,'Teamsters','25 Louisiana Ave NW,Washington,DC 20001'),(3,'UAW','8000 E Jefferson Ave,Detroit,MI 48214'); | SELECT COUNT(DISTINCT union_membership.worker_id) FROM union_membership INNER JOIN unions ON union_membership.union_id = unions.union_id WHERE unions.union_name IN ('Teamsters', 'UAW'); |
What is the average safety rating for electric vehicles in each country? | CREATE TABLE Vehicles (Id INT,Name VARCHAR(100),Type VARCHAR(50),SafetyRating FLOAT,Country VARCHAR(100)); INSERT INTO Vehicles (Id,Name,Type,SafetyRating,Country) VALUES (1,'Tesla Model 3','Electric',5.0,'USA'); INSERT INTO Vehicles (Id,Name,Type,SafetyRating,Country) VALUES (2,'Nissan Leaf','Electric',4.8,'Japan'); INSERT INTO Vehicles (Id,Name,Type,SafetyRating,Country) VALUES (3,'Audi e-Tron','Electric',5.1,'Germany'); | SELECT Country, AVG(SafetyRating) FROM Vehicles WHERE Type = 'Electric' GROUP BY Country; |
What are the names of the vessels with the highest average speed that arrived in Busan? | CREATE TABLE VesselArrivals (ID INT,VesselName VARCHAR(50),ArrivalPort VARCHAR(50),ArrivalDate DATE,AverageSpeed DECIMAL(5,2)); INSERT INTO VesselArrivals (ID,VesselName,ArrivalPort,ArrivalDate,AverageSpeed) VALUES (1,'Test Vessel 1','Busan','2022-01-01',20.0),(2,'Test Vessel 2','Busan','2022-01-02',18.5),(3,'Test Vessel 3','Busan','2022-01-03',21.0); | SELECT VesselName FROM (SELECT VesselName, ROW_NUMBER() OVER (ORDER BY AverageSpeed DESC) AS rn FROM VesselArrivals WHERE ArrivalPort = 'Busan') t WHERE rn = 1; |
What are the names of vessels that have never had safety incidents in North America? | CREATE TABLE Vessels (VesselID INT,VesselName VARCHAR(50));CREATE TABLE SafetyIncidents (IncidentID INT,VesselID INT,IncidentLocation VARCHAR(50),IncidentDate DATE); INSERT INTO Vessels (VesselID,VesselName) VALUES (1,'VesselA'),(2,'VesselB'),(3,'VesselC'),(4,'VesselD'),(5,'VesselE'); INSERT INTO SafetyIncidents (IncidentID,VesselID,IncidentLocation,IncidentDate) VALUES (1,1,'Canada','2021-01-01'),(2,2,'USA','2021-02-01'),(3,3,'Mexico','2021-03-01'); | SELECT Vessels.VesselName FROM Vessels LEFT JOIN SafetyIncidents ON Vessels.VesselID = SafetyIncidents.VesselID WHERE SafetyIncidents.IncidentLocation IS NULL; |
List all circular economy initiatives from 'initiatives' table | CREATE TABLE initiatives (name VARCHAR(50),type VARCHAR(50),start_date DATE,end_date DATE); | SELECT * FROM initiatives WHERE type = 'circular_economy'; |
What is the total landfill capacity in Europe as of 2021, separated by region? | CREATE TABLE LandfillCapacityEurope (region VARCHAR(50),year INT,capacity INT); INSERT INTO LandfillCapacityEurope (region,year,capacity) VALUES ('Europe/East',2021,1000000),('Europe/West',2021,1200000),('Europe/North',2021,1400000),('Europe/South',2021,1100000); | SELECT region, SUM(capacity) FROM LandfillCapacityEurope WHERE year = 2021 GROUP BY region; |
List the names of all sensors and their respective locations from the 'sensor_data' and 'sensor_location' tables | CREATE TABLE sensor_data (sensor_id INT,water_level FLOAT,timestamp TIMESTAMP); CREATE TABLE sensor_location (sensor_id INT,location VARCHAR(50)); | SELECT sensor_data.sensor_id, sensor_location.location FROM sensor_data INNER JOIN sensor_location ON sensor_data.sensor_id = sensor_location.sensor_id; |
What is the average daily water consumption per capita for the past year? | CREATE TABLE countries (country_name VARCHAR(50),country_abbr VARCHAR(5),population INT); INSERT INTO countries (country_name,country_abbr,population) VALUES ('Canada','CA',38005238),('Australia','AU',25683200),('Russia','RU',145934462); CREATE TABLE water_consumption (country_abbr VARCHAR(5),consumption_gallons INT,consumption_date DATE); INSERT INTO water_consumption (country_abbr,consumption_gallons,consumption_date) VALUES ('CA',3845200,'2022-01-01'),('AU',2957420,'2022-01-02'),('RU',1876542,'2022-01-03'); | SELECT c.country_name, AVG(w.consumption_gallons / c.population) as avg_daily_water_consumption_per_capita FROM water_consumption w JOIN countries c ON w.country_abbr = c.country_abbr WHERE w.consumption_date >= DATEADD(year, -1, GETDATE()) GROUP BY c.country_name; |
What is the maximum water consumption in the agricultural sector in Mexico for the year 2020? | CREATE TABLE water_consumption_m3 (region VARCHAR(20),sector VARCHAR(20),year INT,value FLOAT); INSERT INTO water_consumption_m3 (region,sector,year,value) VALUES ('Mexico','Agricultural',2020,12000000); | SELECT MAX(value) FROM water_consumption_m3 WHERE sector = 'Agricultural' AND region = 'Mexico' AND year = 2020; |
Find the number of new members acquired each month in 2021, excluding the members who canceled their membership. | CREATE SCHEMA fitness; CREATE TABLE membership (member_id INT,member_start_date DATE,member_end_date DATE); INSERT INTO membership (member_id,member_start_date,member_end_date) VALUES (1,'2021-01-01','2021-12-31'),(2,'2021-01-01','2021-02-15'),(3,'2021-03-01','2021-12-31'); | SELECT MONTH(member_start_date) AS month, COUNT(*) - SUM(CASE WHEN MONTH(member_end_date) < MONTH(member_start_date) THEN 1 ELSE 0 END) AS new_members FROM membership WHERE YEAR(member_start_date) = 2021 GROUP BY month; |
Find the algorithm names and their corresponding risk_level in the ai_safety table where the risk_level is 'medium' or 'high' | CREATE TABLE ai_safety (algorithm TEXT,risk_level TEXT,dataset TEXT,last_updated TIMESTAMP); | SELECT algorithm, risk_level FROM ai_safety WHERE risk_level IN ('medium', 'high'); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.