instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
List the names of biotech startups that received funding in India or Mexico. | CREATE TABLE funding(startup_name VARCHAR(50),country VARCHAR(20),amount DECIMAL(10,2));INSERT INTO funding(startup_name,country,amount) VALUES('Startup1','India',3000000.00),('Startup2','Mexico',4000000.00),('Startup3','India',5000000.00); | SELECT startup_name FROM funding WHERE country IN ('India', 'Mexico'); |
What is the total oil and gas reserves for Saudi Arabia? | CREATE TABLE reserves (country text,resource text,quantity real); INSERT INTO reserves (country,resource,quantity) VALUES ('Saudi Arabia','oil',266.5),('Saudi Arabia','gas',7.9),('Russia','oil',109.2),('Russia','gas',32.9),('Iran','oil',155.6),('Iran','gas',33.1); | SELECT SUM(quantity) FROM reserves WHERE country = 'Saudi Arabia'; |
What is the total quantity of items in warehouse 1 and 5? | CREATE TABLE warehouses (id INT,location VARCHAR(10),item VARCHAR(10),quantity INT); INSERT INTO warehouses (id,location,item,quantity) VALUES (1,'NY','A101',200),(2,'NJ','A101',300),(3,'CA','B203',150),(4,'NY','C304',50); | SELECT SUM(quantity) FROM warehouses WHERE id IN (1, 5); |
Find the total number of vessels with a maximum speed greater than 35 knots | CREATE TABLE Vessels (VesselID INT,VesselName VARCHAR(100),MaxSpeed FLOAT); INSERT INTO Vessels (VesselID,VesselName,MaxSpeed) VALUES (1,'Ocean Titan',36.5),(2,'Sea Giant',33.3),(3,'Marine Unicorn',37.8),(4,'Sky Wanderer',35.2),(5,'River Princess',29.0),(6,'Lake Explorer',39.0); | SELECT COUNT(*) FROM Vessels WHERE MaxSpeed > 35; |
Update the location of 'Impressionist Visions' to 'London'. | CREATE TABLE Exhibitions (id INT,curator VARCHAR(50),title VARCHAR(100),location VARCHAR(100),start_date DATE,end_date DATE); INSERT INTO Exhibitions (id,curator,title,location,start_date,end_date) VALUES (1,'Theodora J. Roethke','Impressionist Visions','New York','2022-05-01','2022-08-31'); | UPDATE Exhibitions SET location = 'London' WHERE curator = 'Theodora J. Roethke' AND title = 'Impressionist Visions'; |
Which countries have the most clinical trials in 2020? | CREATE TABLE clinical_trials (country TEXT,year INTEGER,trials INTEGER); INSERT INTO clinical_trials (country,year,trials) VALUES ('United States',2020,1200); INSERT INTO clinical_trials (country,year,trials) VALUES ('Germany',2020,300); | SELECT country, SUM(trials) FROM clinical_trials WHERE year = 2020 GROUP BY country ORDER BY SUM(trials) DESC; |
Which rovers were launched by China or Russia? | CREATE TABLE rovers (id INT,name VARCHAR(255),country VARCHAR(255),landing_date DATE,launch_date DATE); INSERT INTO rovers (id,name,country,landing_date,launch_date) VALUES (1,'Spirit','USA','2004-01-04','2003-06-10'); INSERT INTO rovers (id,name,country,landing_date,launch_date) VALUES (2,'Curiosity','USA','2012-08-06','2011-11-26'); INSERT INTO rovers (id,name,country,landing_date,launch_date) VALUES (3,'Yutu','China','2013-12-14','2013-11-29'); | SELECT name, country FROM rovers WHERE country = 'China' OR country = 'Russia'; |
What is the total quantity of steel and concrete used in Project 3? | CREATE TABLE materials (material_id INT,material_name VARCHAR(100),unit_cost DECIMAL(5,2)); INSERT INTO materials VALUES (1,'Concrete',120.50),(2,'Steel',850.00); CREATE TABLE project_materials (project_id INT,material_id INT,quantity INT); INSERT INTO project_materials VALUES (3,1,600),(3,2,300); | SELECT m.material_name, SUM(pm.quantity) FROM project_materials pm JOIN materials m ON pm.material_id = m.material_id WHERE pm.project_id = 3 GROUP BY m.material_name; |
List all suppliers for organic fruits and vegetables, along with their contact information and product details. | CREATE TABLE Suppliers (SupplierID int,Name varchar(50),Contact varchar(50),Industry varchar(50)); INSERT INTO Suppliers (SupplierID,Name,Contact,Industry) VALUES (1,'Green Valley','[email protected]','Organic Fruits'); CREATE TABLE Products (ProductID int,Name varchar(50),SupplierID int,Details varchar(50)); INSERT INTO Products (ProductID,Name,SupplierID,Details) VALUES (1,'Apples',1,'Organic'); | SELECT Suppliers.Name, Suppliers.Contact, Products.Name, Products.Details FROM Suppliers INNER JOIN Products ON Suppliers.SupplierID = Products.SupplierID WHERE Suppliers.Industry = 'Organic Fruits' AND Products.Details = 'Organic'; |
How many consumer complaints were there for each cosmetic product in 2021? | CREATE TABLE Consumer_Complaints (ComplaintID INT,ProductID INT,ComplaintDate DATE); INSERT INTO Consumer_Complaints (ComplaintID,ProductID,ComplaintDate) VALUES (1,101,'2021-01-01'),(2,102,'2021-02-01'),(3,101,'2021-03-01'),(4,103,'2021-04-01'),(5,102,'2021-05-01'),(6,101,'2021-06-01'); | SELECT ProductID, COUNT(*) as Complaints FROM Consumer_Complaints WHERE EXTRACT(YEAR FROM ComplaintDate) = 2021 GROUP BY ProductID; |
Calculate the average level of players for each region | CREATE TABLE players (id INT,name TEXT,level INT,region TEXT); | SELECT region, AVG(level) AS avg_level FROM players GROUP BY region; |
What is the average annual temperature change in India and Australia since 2000, ranked by the greatest change? | CREATE TABLE weather_data (country VARCHAR(20),year INT,avg_temp FLOAT); INSERT INTO weather_data (country,year,avg_temp) VALUES ('India',2000,25.6),('India',2001,25.8),('Australia',2000,21.3),('Australia',2001,21.5); | SELECT country, AVG(avg_temp) as avg_temp_change, ROW_NUMBER() OVER (ORDER BY AVG(avg_temp) DESC) as rank FROM weather_data WHERE country IN ('India', 'Australia') AND year >= 2000 GROUP BY country; |
What are the total assets of the customers who have a savings account? | CREATE TABLE Accounts (CustomerID INT,AccountType VARCHAR(50),Balance DECIMAL(10,2)); INSERT INTO Accounts (CustomerID,AccountType,Balance) VALUES (1,'Savings',10000); INSERT INTO Accounts (CustomerID,AccountType,Balance) VALUES (2,'Checking',5000); | SELECT SUM(Balance) FROM Accounts WHERE AccountType = 'Savings' |
Show the names and number of artworks for all artists who have created works in both the 'Paintings' and 'Sculptures' tables. | CREATE TABLE Artists (ArtistID INT,Name TEXT); INSERT INTO Artists (ArtistID,Name) VALUES (1,'Pablo Picasso'),(2,'Vincent van Gogh'); CREATE TABLE Paintings (PaintingID INT,Title TEXT,ArtistID INT); INSERT INTO Paintings (PaintingID,Title,ArtistID) VALUES (1,'Guernica',1),(2,'The Starry Night',2); CREATE TABLE Sculptures (SculptureID INT,Title TEXT,ArtistID INT); INSERT INTO Sculptures (SculptureID,Title,ArtistID) VALUES (1,'David',1),(2,'The Thinker',2); | SELECT Artists.Name, COUNT(*) as ArtworkCount FROM Artists INNER JOIN Paintings ON Artists.ArtistID = Paintings.ArtistID INNER JOIN Sculptures ON Artists.ArtistID = Sculptures.ArtistID GROUP BY Artists.Name; |
List the number of circular supply chain initiatives in the electronics industry. | CREATE TABLE supply_chain (supply_chain_id INT,industry VARCHAR(255),num_initiatives INT); | SELECT COUNT(*) FROM supply_chain WHERE industry = 'Electronics'; |
What is the total quantity of products sold in the last 30 days, grouped by day? | CREATE TABLE sales (id INT PRIMARY KEY,transaction_id INT,customer_id INT,sale_date DATE,FOREIGN KEY (transaction_id) REFERENCES transactions(id),FOREIGN KEY (customer_id) REFERENCES customers(id)); | SELECT DATE(sale_date) AS sale_day, SUM(transactions.quantity) AS total_quantity FROM sales INNER JOIN transactions ON sales.transaction_id = transactions.id WHERE sales.sale_date >= CURDATE() - INTERVAL 30 DAY GROUP BY sale_day; |
Find the number of employees who joined in each month of the year | CREATE TABLE employee_history (id INT,hire_date DATE,employee_id INT); INSERT INTO employee_history (id,hire_date,employee_id) VALUES (1,'2021-01-01',1001),(2,'2021-02-01',2001),(3,'2020-12-01',3001); | SELECT MONTH(hire_date) as hire_month, COUNT(*) as num_employees FROM employee_history GROUP BY hire_month; |
What is the total number of visitors who attended exhibitions related to indigenous cultures in 2020? | CREATE TABLE Exhibitions (id INT,theme VARCHAR(255),year INT); INSERT INTO Exhibitions (id,theme,year) VALUES (1,'Indigenous Cultures',2020); CREATE TABLE Visitors (id INT,exhibition_id INT); | SELECT COUNT(*) FROM Visitors INNER JOIN Exhibitions ON Visitors.exhibition_id = Exhibitions.id WHERE Exhibitions.theme = 'Indigenous Cultures' AND Exhibitions.year = 2020; |
What is the total number of sustainable building projects in the state of California that were completed in 2021? | CREATE TABLE sustainable_building_projects (project_id INT,project_name VARCHAR(50),state VARCHAR(50),completion_date DATE,is_sustainable BOOLEAN); INSERT INTO sustainable_building_projects (project_id,project_name,state,completion_date,is_sustainable) VALUES (1,'Green Building','California','2021-01-01',TRUE); INSERT INTO sustainable_building_projects (project_id,project_name,state,completion_date,is_sustainable) VALUES (2,'Solar Powered Apartments','California','2021-02-01',TRUE); | SELECT COUNT(*) FROM sustainable_building_projects WHERE state = 'California' AND completion_date BETWEEN '2021-01-01' AND '2021-12-31' AND is_sustainable = TRUE; |
What is the average calorie intake for organic meals served in restaurants located in the US? | CREATE TABLE Restaurants (id INT,name TEXT,country TEXT); CREATE TABLE Meals (id INT,name TEXT,type TEXT,calories INT,RestaurantId INT,FOREIGN KEY (RestaurantId) REFERENCES Restaurants(id)); INSERT INTO Restaurants (id,name,country) VALUES (1,'Restaurant A','USA'),(2,'Restaurant B','USA'),(3,'Restaurant C','Canada'); INSERT INTO Meals (id,name,type,calories,RestaurantId) VALUES (1,'Meal 1','Organic',500,1),(2,'Meal 2','Conventional',600,1),(3,'Meal 3','Organic',400,2),(4,'Meal 4','Conventional',550,2),(5,'Meal 5','Organic',450,3); | SELECT AVG(Meals.calories) FROM Meals JOIN Restaurants ON Meals.RestaurantId = Restaurants.id WHERE Meals.type = 'Organic' AND Restaurants.country = 'USA'; |
What is the number of professional development programs attended by teachers in each district? | CREATE TABLE districts (district_id INT,district_name TEXT); INSERT INTO districts (district_id,district_name) VALUES (1,'Downtown'),(2,'Uptown'),(3,'Suburbs'); CREATE TABLE teachers (teacher_id INT,teacher_name TEXT,district_id INT); INSERT INTO teachers (teacher_id,teacher_name,district_id) VALUES (1,'Mrs. Doe',1),(2,'Mr. Smith',2),(3,'Ms. Johnson',3),(4,'Mr. Williams',1); CREATE TABLE professional_development (program_id INT,program_name TEXT,teacher_id INT); INSERT INTO professional_development (program_id,program_name,teacher_id) VALUES (1,'Python for Educators',1),(2,'Data Science for Teachers',2),(3,'Inclusive Teaching',3),(4,'Open Pedagogy',4),(5,'Diversity and Inclusion',1),(6,'Curriculum Design',2); | SELECT d.district_name, COUNT(pd.program_id) as num_programs FROM districts d JOIN teachers t ON d.district_id = t.district_id JOIN professional_development pd ON t.teacher_id = pd.teacher_id GROUP BY d.district_name; |
Add a new column 'age' to 'athletes' table | CREATE TABLE athletes (name VARCHAR(100),sport VARCHAR(50),country VARCHAR(50)); | ALTER TABLE athletes ADD COLUMN age INT; |
What is the average trip duration for senior tourists in Africa? | CREATE TABLE trip_duration (id INT,country VARCHAR(50),tourist_type VARCHAR(50),trip_duration FLOAT); INSERT INTO trip_duration (id,country,tourist_type,trip_duration) VALUES (1,'South Africa','senior',10.0),(2,'Egypt','senior',12.0),(3,'Morocco','senior',14.0),(4,'Tunisia','senior',16.0),(5,'Kenya','senior',18.0); | SELECT AVG(trip_duration) FROM trip_duration WHERE country IN ('South Africa', 'Egypt', 'Morocco', 'Tunisia', 'Kenya') AND tourist_type = 'senior'; |
Create a table named 'suppliers' | CREATE TABLE suppliers(supplier_id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),sustainability_score DECIMAL(3,2)); | CREATE TABLE suppliers( supplier_id INT PRIMARY KEY, name VARCHAR(255), location VARCHAR(255), sustainability_score DECIMAL(3,2)); |
Insert new records for students who joined an open pedagogy course in the last month | CREATE TABLE students (id INT,name VARCHAR(20),course VARCHAR(20),joined_date DATE); INSERT INTO students (id,name,course,joined_date) VALUES (1,'Alex','Math','2022-01-01'); INSERT INTO students (id,name,course,joined_date) VALUES (2,'Bella','English','2022-02-01'); INSERT INTO students (id,name,course,joined_date) VALUES (3,'Charlie','Science','2022-04-10'); INSERT INTO students (id,name,course,joined_date) VALUES (4,'Daniel','History','2022-01-10'); | INSERT INTO students (id, name, course, joined_date) VALUES (5, 'Eli', 'Open Pedagogy', CURRENT_DATE - INTERVAL 15 DAY), (6, 'Fiona', 'Open Pedagogy', CURRENT_DATE - INTERVAL 25 DAY), (7, 'Gabriel', 'Open Pedagogy', CURRENT_DATE - INTERVAL 5 DAY); |
Find the total revenue generated from sustainable tourism in Tokyo in the last 6 months. | CREATE TABLE bookings (id INT,hotel_id INT,date DATE,revenue INT); INSERT INTO bookings (id,hotel_id,date,revenue) VALUES (1,1,'2021-01-01',100),(2,1,'2021-02-01',200); CREATE TABLE hotels (id INT,city VARCHAR(20),sustainable BOOLEAN); INSERT INTO hotels (id,city,sustainable) VALUES (1,'Tokyo',true),(2,'Tokyo',false); | SELECT SUM(b.revenue) FROM bookings b JOIN hotels h ON b.hotel_id = h.id WHERE h.city = 'Tokyo' AND b.date BETWEEN DATE_SUB(NOW(), INTERVAL 6 MONTH) AND NOW() AND h.sustainable = true; |
What is the average number of saves made by goalkeepers in the 'Ligue 1' league? | CREATE TABLE players (player_id INT,name VARCHAR(50),position VARCHAR(50),height FLOAT,weight INT,team_id INT,league VARCHAR(50),saves INT); INSERT INTO players (player_id,name,position,height,weight,team_id,league,saves) VALUES (8,'Ella','Goalkeeper',1.78,70,801,'Ligue 1',10); | SELECT AVG(saves) FROM players WHERE position = 'Goalkeeper' AND league = 'Ligue 1'; |
Which countries have had at least 10 papers published in AI safety in the last 5 years? | CREATE TABLE Papers (id INT,title VARCHAR(255),year INT,country VARCHAR(255)); INSERT INTO Papers (id,title,year,country) VALUES (1,'Ethical considerations in AI safety',2021,'USA'),(2,'Safe and fair AI algorithms',2022,'Canada'),(3,'Towards explainable AI systems',2022,'Australia'),(4,'AI creativity and human values',2021,'UK'),(5,'AI for social good',2022,'India'),(6,'AI for environmental sustainability',2021,'Brazil'); CREATE TABLE Countries (id INT,name VARCHAR(255)); INSERT INTO Countries (id,name) VALUES (1,'USA'),(2,'Canada'),(3,'Australia'),(4,'UK'),(5,'India'),(6,'Brazil'); | SELECT country, COUNT(*) as num_papers FROM Papers JOIN Countries ON Papers.country = Countries.name WHERE year BETWEEN 2017 AND 2022 GROUP BY country HAVING num_papers >= 10; |
What are the countries with the highest average playtime in the "VirtualRealityGaming"? | CREATE TABLE Players (PlayerID INT PRIMARY KEY,Name VARCHAR(50),GamingCommunity VARCHAR(50),Country VARCHAR(50)); CREATE TABLE GameSessions (SessionID INT PRIMARY KEY,PlayerID INT,Playtime MINUTE,FOREIGN KEY (PlayerID) REFERENCES Players(PlayerID)); INSERT INTO Players (PlayerID,Name,GamingCommunity,Country) VALUES (1,'James Lee','VirtualRealityGaming','USA'),(2,'Alicia Thompson','VirtualRealityGaming','Canada'),(3,'Javier Garcia','VirtualRealityGaming','Mexico'); INSERT INTO GameSessions (SessionID,PlayerID,Playtime) VALUES (1,1,120),(2,1,150),(3,2,200),(4,3,250); | SELECT Country, AVG(Playtime) FROM Players JOIN GameSessions ON Players.PlayerID = GameSessions.PlayerID WHERE Players.GamingCommunity = 'VirtualRealityGaming' GROUP BY Country ORDER BY AVG(Playtime) DESC; |
Insert a new row into the 'products' table for a new eyeshadow palette with the name 'Ethereal', a vegan label, and a rating of 4.5. | CREATE TABLE products (product_id INT,name VARCHAR(255),category VARCHAR(255),rating FLOAT,vegan BOOLEAN); | INSERT INTO products (name, category, rating, vegan) VALUES ('Ethereal', 'eyeshadow', 4.5, TRUE); |
What is the average number of virtual tours conducted per month in Tokyo, Japan, for the year 2022, if the total duration of the tour was at least 45 minutes? | CREATE TABLE VirtualTours (location VARCHAR(20),year INT,month INT,duration INT); | SELECT AVG(duration) FROM VirtualTours WHERE location = 'Tokyo' AND year = 2022 AND month BETWEEN 1 AND 12 HAVING AVG(duration) >= 45; |
What is the total quantity of products manufactured by each supplier in the past year? | CREATE TABLE suppliers(id INT,name TEXT,location TEXT);CREATE TABLE products(id INT,supplier_id INT,product_name TEXT,quantity INT,manufacture_date DATE);INSERT INTO suppliers(id,name,location) VALUES (1,'Supplier A','City A'),(2,'Supplier B','City B'); INSERT INTO products(id,supplier_id,product_name,quantity,manufacture_date) VALUES (1,1,'Product 1',100,'2021-02-01'),(2,1,'Product 2',200,'2021-03-01'),(3,2,'Product 3',150,'2021-01-10'); | SELECT supplier_id, SUM(quantity) as total_quantity FROM products WHERE manufacture_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY supplier_id; |
What is the total number of restorative justice programs in the 'justice_programs' table? | CREATE TABLE justice_programs (id INT,name VARCHAR(50),type VARCHAR(30),location VARCHAR(30)); INSERT INTO justice_programs (id,name,type,location) VALUES (1,'Mediation Center','Restorative Justice','San Francisco'); INSERT INTO justice_programs (id,name,type,location) VALUES (2,'Victim-Offender Reconciliation Program','Restorative Justice','Oakland'); | SELECT COUNT(*) FROM justice_programs WHERE type = 'Restorative Justice'; |
What is the average number of security incidents per day in the last week? | CREATE TABLE security_incidents (id INT,incident_date DATE); | SELECT AVG(COUNT(*)) FROM security_incidents WHERE incident_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK) GROUP BY DATE(incident_date); |
What is the combined water consumption by commercial and industrial sectors in 2019 and 2020? | CREATE TABLE sector_consumption (year INT,sector TEXT,consumption FLOAT); INSERT INTO sector_consumption (year,sector,consumption) VALUES (2015,'residential',123.5),(2015,'commercial',234.6),(2016,'residential',130.2),(2016,'commercial',240.1),(2019,'commercial',270.9),(2019,'industrial',385.1),(2020,'commercial',255.9),(2020,'industrial',402.6); | SELECT consumption FROM sector_consumption WHERE sector IN ('commercial', 'industrial') AND year IN (2019, 2020) |
What is the total revenue generated by classical music concerts in Europe in 2018? | CREATE TABLE concerts (concert_id INT,genre VARCHAR(10),region VARCHAR(10),year INT,revenue INT); INSERT INTO concerts (concert_id,genre,region,year,revenue) VALUES (1,'Classical','Europe',2018,50000),(2,'Jazz','US',2019,30000),(3,'Classical','Europe',2018,60000); | SELECT SUM(revenue) FROM concerts WHERE genre = 'Classical' AND region = 'Europe' AND year = 2018; |
Create a table named 'VolunteerSkills' with columns 'volunteer_id', 'skill', and 'experience'. | CREATE TABLE VolunteerSkills (volunteer_id INT,skill VARCHAR(255),experience INT); | CREATE TABLE VolunteerSkills (volunteer_id INT, skill VARCHAR(255), experience INT); |
Identify the unique vegetarian dishes served at restaurants located in 'City A'. | CREATE TABLE restaurants (id INT,name VARCHAR(255),city VARCHAR(255)); INSERT INTO restaurants (id,name,city) VALUES (1,'Restaurant A','City A'),(2,'Restaurant B','City B'),(3,'Organic Garden','City A'); CREATE TABLE dishes (id INT,name VARCHAR(255),type VARCHAR(255),restaurant_id INT); INSERT INTO dishes (id,name,type,restaurant_id) VALUES (1,'Quinoa Salad','vegetarian',1),(2,'Chickpea Curry','vegetarian',1),(3,'Cheeseburger','non-vegetarian',1),(4,'Pizza Margherita','vegetarian',2),(5,'Fish and Chips','non-vegetarian',2),(6,'Vegan Pizza','vegetarian',3); | SELECT d.name FROM dishes d JOIN restaurants r ON d.restaurant_id = r.id WHERE d.type = 'vegetarian' AND r.city = 'City A' GROUP BY d.name; |
List all public service requests related to road repair in the 'service_requests' table. | CREATE TABLE service_requests (id INT,request_type VARCHAR(255),request_date DATE); INSERT INTO service_requests (id,request_type,request_date) VALUES (1,'Road Repair','2022-01-01'),(2,'Waste Collection','2022-02-01'),(3,'Street Lighting','2022-01-15'); | SELECT * FROM service_requests WHERE request_type = 'Road Repair'; |
What is the average age of all female reporters in the "reporters" table? | CREATE TABLE reporters (id INT,name VARCHAR(50),gender VARCHAR(10),age INT); INSERT INTO reporters (id,name,gender,age) VALUES (1,'Anna Smith','Female',35),(2,'John Doe','Male',40); | SELECT AVG(age) FROM reporters WHERE gender = 'Female'; |
What is the average renewable energy investment for South America in the first half of 2022? | CREATE TABLE renewable_energy_investments (id INT,country VARCHAR(50),investment_amount FLOAT,currency VARCHAR(10),recorded_date DATE); INSERT INTO renewable_energy_investments (id,country,investment_amount,currency,recorded_date) VALUES (1,'Argentina',500000,'USD','2022-01-01'),(2,'Brazil',750000,'USD','2022-01-01'),(3,'Colombia',300000,'USD','2022-01-01'); | SELECT AVG(investment_amount) FROM renewable_energy_investments WHERE country LIKE 'South%' AND recorded_date BETWEEN '2022-01-01' AND '2022-06-30'; |
List all mining projects in Mexico and their respective environmental impact assessments, if available. | CREATE TABLE mining_projects (project_id INT,project_name TEXT,location TEXT); CREATE TABLE environmental_impact_assessments (assessment_id INT,project_id INT,assessment_text TEXT); INSERT INTO mining_projects (project_id,project_name,location) VALUES (1,'El Tesoro','Mexico'),(2,'La Fortuna','Peru'); INSERT INTO environmental_impact_assessments (assessment_id,project_id,assessment_text) VALUES (1,1,'Low impact'),(2,2,'Medium impact'); | SELECT mining_projects.project_name, environmental_impact_assessments.assessment_text FROM mining_projects LEFT JOIN environmental_impact_assessments ON mining_projects.project_id = environmental_impact_assessments.project_id WHERE location = 'Mexico'; |
What are the regulatory frameworks in place for smart contracts in the APAC region? | CREATE TABLE RegulatoryFramework (FrameworkID INT,FrameworkName VARCHAR(100),FrameworkDescription VARCHAR(255),FrameworkRegion VARCHAR(50)); INSERT INTO RegulatoryFramework (FrameworkID,FrameworkName,FrameworkDescription,FrameworkRegion) VALUES (1,'FrameworkA','DescriptionA','APAC'),(2,'FrameworkB','DescriptionB','APAC'),(3,'FrameworkC','DescriptionC','Europe'); | SELECT FrameworkName, FrameworkDescription FROM RegulatoryFramework WHERE FrameworkRegion = 'APAC'; |
What is the highest and lowest assets value for customers from the UK? | CREATE TABLE customers (id INT,name TEXT,age INT,country TEXT,assets FLOAT); INSERT INTO customers (id,name,age,country,assets) VALUES (1,'John Doe',45,'USA',250000.00); INSERT INTO customers (id,name,age,country,assets) VALUES (2,'Jane Smith',34,'Canada',320000.00); INSERT INTO customers (id,name,age,country,assets) VALUES (3,'Alice Johnson',29,'UK',450000.00); INSERT INTO customers (id,name,age,country,assets) VALUES (4,'Bob Brown',51,'UK',150000.00); | SELECT MAX(assets), MIN(assets) FROM customers WHERE country = 'UK'; |
What is the average distance to the nearest hospital in rural areas? | CREATE TABLE hospitals (id INT,name TEXT,location TEXT,is_rural BOOLEAN); INSERT INTO hospitals (id,name,location,is_rural) VALUES (1,'Hospital A','123 Main St,Rural Town A',true),(2,'Hospital B','456 Elm St,Urban City A',false); CREATE TABLE healthcare_facilities (id INT,name TEXT,location TEXT,is_rural BOOLEAN); INSERT INTO healthcare_facilities (id,name,location,is_rural) VALUES (1,'Clinic A','789 Oak St,Rural Town A',true),(2,'Clinic B','321 Maple St,Urban City B',false); CREATE TABLE distances (facility_id INT,hospital_id INT,distance REAL); INSERT INTO distances (facility_id,hospital_id,distance) VALUES (1,1,10),(2,2,25); | SELECT AVG(distance) FROM distances d INNER JOIN healthcare_facilities hf ON d.facility_id = hf.id INNER JOIN hospitals h ON d.hospital_id = h.id WHERE hf.is_rural = true AND h.is_rural = true; |
What is the average water temperature and dissolved oxygen levels for fish farms in the Asia-Pacific region? | CREATE TABLE fish_farms (id INT,name TEXT,location TEXT,water_type TEXT); INSERT INTO fish_farms (id,name,location,water_type) VALUES (1,'Farm I','Tokyo','Saltwater'); INSERT INTO fish_farms (id,name,location,water_type) VALUES (2,'Farm J','Sydney','Seawater'); CREATE TABLE water_quality (id INT,fish_farm_id INT,temperature FLOAT,pH FLOAT,dissolved_oxygen FLOAT); INSERT INTO water_quality (id,fish_farm_id,temperature,pH,dissolved_oxygen) VALUES (1,1,26.5,7.8,7.1); INSERT INTO water_quality (id,fish_farm_id,temperature,pH,dissolved_oxygen) VALUES (2,1,27.0,7.9,7.2); INSERT INTO water_quality (id,fish_farm_id,temperature,pH,dissolved_oxygen) VALUES (3,2,23.0,7.7,6.9); INSERT INTO water_quality (id,fish_farm_id,temperature,pH,dissolved_oxygen) VALUES (4,2,22.5,7.6,7.0); | SELECT ff.location, AVG(wq.temperature) AS avg_temp, AVG(wq.dissolved_oxygen) AS avg_dissolved_oxygen FROM fish_farms ff JOIN water_quality wq ON ff.id = wq.fish_farm_id WHERE ff.location LIKE 'Asia%' OR ff.location LIKE 'Pacific%' GROUP BY ff.location; |
Find the number of employees in each department, ordered from most to least | CREATE TABLE Departments (id INT,name VARCHAR(255),department VARCHAR(255)); INSERT INTO Departments (id,name,department) VALUES (1,'John Doe','Mining Operations'),(2,'Jane Smith','Mining Operations'),(3,'Mike Johnson','IT'),(4,'Sara Clark','HR'),(5,'Alex Rodriguez','Mining Operations'),(6,'Taylor Swift','HR'),(7,'Emma Watson','IT'); | SELECT department, COUNT(*) as num_employees FROM Departments GROUP BY department ORDER BY num_employees DESC; |
How many consumers in the 'Midwest' region have a preference for products in the 'Lipstick' category? | CREATE TABLE consumers (id INT PRIMARY KEY,name VARCHAR(255),age INT,gender VARCHAR(10),region VARCHAR(50)); CREATE TABLE preferences (id INT PRIMARY KEY,consumer_id INT,product_id INT,preference VARCHAR(50),FOREIGN KEY (consumer_id) REFERENCES consumers(id)); CREATE TABLE products (id INT PRIMARY KEY,name VARCHAR(255),category VARCHAR(50),price FLOAT,cruelty_free BOOLEAN); | SELECT COUNT(DISTINCT consumers.id) FROM consumers INNER JOIN preferences ON consumers.id = preferences.consumer_id INNER JOIN products ON preferences.product_id = products.id WHERE consumers.region = 'Midwest' AND products.category = 'Lipstick'; |
What is the distribution of security incidents by department in the last month? | CREATE TABLE security_incidents (id INT,department VARCHAR(50),timestamp DATETIME); | SELECT department, COUNT(*) as num_incidents FROM security_incidents WHERE timestamp > DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY department; |
What is the average budget allocation for education in urban areas? | CREATE TABLE budget (service varchar(20),location varchar(20),allocation int); INSERT INTO budget (service,location,allocation) VALUES ('Education','Urban',5000000),('Healthcare','Urban',7000000),('Education','Rural',3000000),('Healthcare','Rural',4000000); | SELECT AVG(allocation) FROM budget WHERE service = 'Education' AND location = 'Urban'; |
Find the artist with the most works in a specific movement. | CREATE TABLE Artists (ArtistID INT,Name VARCHAR(50),Nationality VARCHAR(50)); INSERT INTO Artists (ArtistID,Name,Nationality) VALUES (1,'Vincent van Gogh','Dutch'); INSERT INTO Artists (ArtistID,Name,Nationality) VALUES (2,'Pablo Picasso','Spanish'); CREATE TABLE Paintings (PaintingID INT,Title VARCHAR(50),ArtistID INT,YearCreated INT,Movement VARCHAR(50)); INSERT INTO Paintings (PaintingID,Title,ArtistID,YearCreated,Movement) VALUES (1,'Starry Night',1,1889,'Post-Impressionism'); INSERT INTO Paintings (PaintingID,Title,ArtistID,YearCreated,Movement) VALUES (2,'Guernica',2,1937,'Cubism'); CREATE TABLE Movements (MovementID INT,Name VARCHAR(50)); INSERT INTO Movements (MovementID,Name) VALUES (1,'Impressionism'); INSERT INTO Movements (MovementID,Name) VALUES (2,'Post-Impressionism'); | SELECT ArtistID, Name, COUNT(*) as TotalPaintings FROM Paintings JOIN Artists ON Paintings.ArtistID = Artists.ArtistID WHERE Movement = 'Post-Impressionism' GROUP BY ArtistID, Name ORDER BY TotalPaintings DESC FETCH FIRST 1 ROW ONLY; |
What is the total budget allocation for education services in CityA for the current fiscal year? | CREATE TABLE fiscal_year (fiscal_year INT,start_date DATE,end_date DATE); INSERT INTO fiscal_year VALUES (2022,'2022-01-01','2022-12-31'),(2023,'2023-01-01','2023-12-31'); CREATE TABLE budget_allocation (service VARCHAR(20),fiscal_year INT,amount INT); INSERT INTO budget_allocation VALUES ('Education',2022,500000),('Healthcare',2022,800000),('Education',2023,600000),('Healthcare',2023,900000); CREATE TABLE cities (id INT,name VARCHAR(20)); INSERT INTO cities VALUES (1,'CityA'),(2,'CityB'),(3,'CityC'); | SELECT SUM(amount) FROM budget_allocation WHERE service = 'Education' AND fiscal_year = (SELECT fiscal_year FROM fiscal_year WHERE start_date <= CURRENT_DATE AND end_date >= CURRENT_DATE) AND city_id = (SELECT id FROM cities WHERE name = 'CityA'); |
What is the total budget for all humanitarian assistance projects by 'uk' in 'humanitarian_table'? | CREATE TABLE humanitarian_table (id INT,project_name VARCHAR(100),country VARCHAR(50),budget INT,status VARCHAR(20)); INSERT INTO humanitarian_table (id,project_name,country,budget,status) VALUES (1,'Project Hope','UK',5000000,'completed'); | SELECT SUM(budget) FROM humanitarian_table WHERE country = 'UK' AND status = 'completed'; |
What are the names of genetic research data tables with the 'research' keyword? | CREATE TABLE research_data_1 (id INT,data TEXT); INSERT INTO research_data_1 (id,data) VALUES (1,'ATGC'),(2,'CGTA'),(3,'TGAC'); CREATE TABLE genetic_data_2 (id INT,data TEXT); INSERT INTO genetic_data_2 (id,data) VALUES (1,'ATGC'),(2,'CGTA'),(3,'TGAC'); | SELECT name FROM (SELECT 'research_data_1' as name UNION ALL SELECT 'genetic_data_2' as name) as subquery WHERE name LIKE '%research%'; |
List all the tables related to ethical AI. | CREATE TABLE ethics_data (name TEXT,description TEXT); INSERT INTO ethics_data (name,description) VALUES ('EthicsAI','Ethical AI framework'),('AIpolicy','AI policy guidelines'); | SELECT * FROM ethics_data; |
What is the total number of public records requests submitted to the city of Houston in 2019 and 2020? | CREATE TABLE public_records_requests (id INT,city VARCHAR,year INT,submitted BOOLEAN); INSERT INTO public_records_requests (id,city,year,submitted) VALUES (1,'Houston',2019,TRUE),(2,'Houston',2020,TRUE); | SELECT COUNT(*) FROM public_records_requests WHERE city = 'Houston' AND (year = 2019 OR year = 2020) AND submitted = TRUE; |
Identify the number of open positions by department for the last 30 days. | CREATE TABLE job_postings (id INT,department VARCHAR(255),posted_date DATE,open_positions INT); INSERT INTO job_postings (id,department,posted_date,open_positions) VALUES (1,'HR','2022-03-18',3),(2,'IT','2022-03-25',5),(3,'Finance','2022-03-10',2); | SELECT department, COUNT(*) as open_positions FROM job_postings WHERE posted_date >= DATE(NOW()) - INTERVAL 30 DAY GROUP BY department; |
What is the average age of patients diagnosed with influenza in California? | CREATE TABLE Patients (PatientID INT,Age INT,Gender VARCHAR(10),Diagnosis VARCHAR(20),State VARCHAR(20)); INSERT INTO Patients (PatientID,Age,Gender,Diagnosis,State) VALUES (1,30,'Female','Influenza','California'); INSERT INTO Patients (PatientID,Age,Gender,Diagnosis,State) VALUES (2,45,'Male','Pneumonia','California'); | SELECT AVG(Age) FROM Patients WHERE Diagnosis = 'Influenza' AND State = 'California'; |
How many genetic research projects are there at 'DNA Solutions'? | CREATE TABLE dna_solutions (id INT,project TEXT,category TEXT); INSERT INTO dna_solutions (id,project,category) VALUES (1,'Gene Mapping','Genetic Research'); INSERT INTO dna_solutions (id,project,category) VALUES (2,'Genome Analysis','Genetic Research'); | SELECT COUNT(*) FROM dna_solutions WHERE category = 'Genetic Research'; |
List the number of Smart City projects by their primary focus area, per continent | CREATE TABLE smart_city_projects (id INT,project_name VARCHAR(100),location VARCHAR(50),continent VARCHAR(50),focus_area VARCHAR(50)); | SELECT continent, focus_area, COUNT(*) as project_count FROM smart_city_projects GROUP BY continent, focus_area; |
What is the number of professional development courses taken by teachers in each department? | CREATE TABLE teachers (teacher_id INT,teacher_name VARCHAR(50),department VARCHAR(20),course_id INT); INSERT INTO teachers (teacher_id,teacher_name,department,course_id) VALUES (1,'John Doe','Math',101),(2,'Jane Smith','English',102),(3,'Alice Johnson','Science',103),(4,'Bob Williams','Math',101),(5,'Charlie Brown','English',102); CREATE TABLE courses (course_id INT,course_name VARCHAR(50),category VARCHAR(20)); INSERT INTO courses (course_id,course_name,category) VALUES (101,'Algebra I','Professional Development'),(102,'Literature Review','Professional Development'),(103,'Physics Lab','Regular Course'),(104,'Calculus I','Professional Development'); | SELECT department, COUNT(DISTINCT course_id) FROM teachers t JOIN courses c ON t.course_id = c.course_id WHERE c.category = 'Professional Development' GROUP BY department; |
How many agricultural innovation projects are funded per year in the 'funding_allocation' table? | CREATE TABLE funding_allocation (project_name VARCHAR(255),funding_year INT,amount INT); INSERT INTO funding_allocation (project_name,funding_year,amount) VALUES ('Precision Agriculture',2020,500000),('Smart Irrigation',2019,400000); | SELECT funding_year, COUNT(*) FROM funding_allocation GROUP BY funding_year; |
What is the percentage of the population fully vaccinated against COVID-19 in each state of Mexico? | CREATE TABLE MexicanVaccinations (State VARCHAR(50),Population INT,Vaccinated INT); INSERT INTO MexicanVaccinations (State,Population,Vaccinated) VALUES ('Jalisco',8000000,6000000),('Mexico City',9000000,7500000),('Veracruz',7000000,5500000),('Puebla',6000000,4500000); | SELECT State, (SUM(Vaccinated) / SUM(Population)) * 100 AS VaccinationPercentage FROM MexicanVaccinations GROUP BY State; |
What was the average value of military equipment sales to the Middle Eastern governments in 2018? | CREATE TABLE military_sales (id INT,year INT,customer VARCHAR(20),equipment_type VARCHAR(20),value FLOAT); INSERT INTO military_sales (id,year,customer,equipment_type,value) VALUES (1,2018,'Middle Eastern Government 1','Armored Vehicles',2000000); INSERT INTO military_sales (id,year,customer,equipment_type,value) VALUES (2,2018,'Middle Eastern Government 2','Artillery',3000000); | SELECT AVG(value) FROM military_sales WHERE year = 2018 AND customer LIKE 'Middle Eastern%'; |
What is the number of cases in each court, broken down by case type, case status, and year, for courts located in the state of New York? | CREATE TABLE CourtCases (CourtName text,State text,CaseType text,CaseStatus text,Year int,NumCases int); INSERT INTO CourtCases VALUES ('Court1','NY','Assault','Open',2022,30,'2022-01-01'),('Court1','NY','Theft','Closed',2022,25,'2022-01-01'),('Court2','CA','Assault','Open',2022,28,'2022-01-01'),('Court2','CA','Theft','Closed',2022,22,'2022-01-01'); | SELECT CourtName, CaseType, CaseStatus, Year, SUM(NumCases) FROM CourtCases WHERE State = 'NY' GROUP BY CourtName, CaseType, CaseStatus, Year; |
What is the total number of hours spent on strength training workouts in the month of June 2022? | CREATE TABLE WorkoutDurations (UserID INT,WorkoutType VARCHAR(20),Duration INT,WorkoutDate DATE); INSERT INTO WorkoutDurations (UserID,WorkoutType,Duration,WorkoutDate) VALUES (1,'Strength Training',60,'2022-06-01'),(1,'Cardio',45,'2022-06-01'),(2,'Strength Training',90,'2022-06-01'),(2,'Yoga',60,'2022-06-01'); | SELECT SUM(Duration) FROM WorkoutDurations WHERE WorkoutType = 'Strength Training' AND WorkoutDate BETWEEN '2022-06-01' AND '2022-06-30'; |
How many mining accidents were reported in the African continent per year, in the last 3 years? | CREATE TABLE accidents (id INT,site_name VARCHAR(50),date DATE,accident_type VARCHAR(50)); INSERT INTO accidents (id,site_name,date,accident_type) VALUES (1,'Site X','2020-03-15','Fire'); | SELECT YEAR(date) AS year, COUNT(*) AS accidents_count FROM accidents WHERE site_name LIKE 'Africa' AND date >= DATE_SUB(CURDATE(), INTERVAL 3 YEAR) GROUP BY year; |
Identify the total number of defense projects initiated by the top 3 defense contractors in 2019. | CREATE TABLE DefenseContractors (contractor_id INT,contractor_name VARCHAR(50),country VARCHAR(50)); CREATE TABLE DefenseProjects (project_id INT,contractor_id INT,project_name VARCHAR(50),start_date DATE,end_date DATE); INSERT INTO DefenseContractors (contractor_id,contractor_name,country) VALUES (1,'Lockheed Martin','USA'),(2,'BAE Systems','UK'),(3,'Airbus','France'); INSERT INTO DefenseProjects (project_id,contractor_id,project_name,start_date,end_date) VALUES (1,1,'F-35 Fighter Jet Program','2019-01-01','2025-12-31'),(2,2,'Type 26 Frigate Program','2019-01-01','2026-12-31'),(3,3,'A400M Program','2019-01-01','2024-12-31'),(4,1,'Hellfire Missile Program','2018-01-01','2022-12-31'); | SELECT COUNT(DISTINCT DefenseProjects.project_id) FROM DefenseProjects INNER JOIN DefenseContractors ON DefenseProjects.contractor_id = DefenseContractors.contractor_id WHERE DefenseContractors.contractor_name IN ('Lockheed Martin', 'BAE Systems', 'Airbus') AND YEAR(DefenseProjects.start_date) = 2019 ORDER BY DefenseProjects.project_id; |
How many graduate students in the Physics department are from underrepresented racial or ethnic backgrounds and have a GPA of at least 3.5? | CREATE SCHEMA if not exists higher_ed;CREATE TABLE if not exists higher_ed.students(id INT,name VARCHAR(255),department VARCHAR(255),gpa DECIMAL(3,2),race VARCHAR(50)); | SELECT COUNT(*) FROM higher_ed.students WHERE department = 'Physics' AND gpa >= 3.5 AND race IN ('Black or African American', 'Hispanic or Latinx', 'Native American or Alaska Native', 'Native Hawaiian or Pacific Islander'); |
What is the total number of space missions by ESA and NASA? | CREATE TABLE space_agency (agency VARCHAR(50),missions INT);INSERT INTO space_agency (agency,missions) VALUES ('ESA',130),('NASA',230); | SELECT SUM(missions) FROM space_agency WHERE agency IN ('ESA', 'NASA'); |
List all the construction labor statistics for the state of California in the year 2019, including the number of workers and the total hours worked. | CREATE TABLE labor_statistics (state TEXT,year INTEGER,workers INTEGER,hours_worked INTEGER);INSERT INTO labor_statistics (state,year,workers,hours_worked) VALUES ('California',2019,1000,500000),('California',2019,1500,750000); | SELECT state, year, workers, SUM(hours_worked) FROM labor_statistics WHERE state = 'California' AND year = 2019 GROUP BY state, year; |
List the names and total costs of all projects that started before 2015 and were completed after 2017. | CREATE TABLE Projects (ProjectID INT,Name VARCHAR(255),StartDate DATE,EndDate DATE,TotalCost DECIMAL(10,2)); | SELECT Name, SUM(TotalCost) as TotalCost FROM Projects WHERE StartDate < '2015-01-01' AND EndDate > '2017-12-31' GROUP BY Name; |
List all cultural heritage sites and their virtual tour availability in Tokyo | CREATE TABLE heritage_sites (id INT,name TEXT,city TEXT,has_virtual_tour BOOLEAN); INSERT INTO heritage_sites (id,name,city,has_virtual_tour) VALUES (1,'Temple','Tokyo',true),(2,'Shrine','Tokyo',false); | SELECT name, has_virtual_tour FROM heritage_sites WHERE city = 'Tokyo'; |
What is the minimum budget allocated for environmental services in urban areas? | CREATE TABLE environmental_services (es_id INT,area_id INT,department VARCHAR(20),amount INT); INSERT INTO environmental_services (es_id,area_id,department,amount) VALUES (1,1,'environmental_services',3000),(2,1,'waste_management',4000),(3,2,'environmental_services',2000),(4,2,'waste_management',5000); | SELECT MIN(e.amount) FROM environmental_services e JOIN urban_areas a ON e.area_id = a.area_id WHERE e.department = 'environmental_services' AND a.area_type = 'urban'; |
What percentage of skincare products in Canada contain natural ingredients? | CREATE TABLE product_ingredients(product_id INT,product_type VARCHAR(255),contains_natural_ingredients BOOLEAN); CREATE TABLE cosmetics_sales(product_id INT,country VARCHAR(255),sales_quantity INT,sales_revenue DECIMAL(10,2)); | SELECT 100.0 * COUNT(product_id) / (SELECT COUNT(*) FROM cosmetics_sales WHERE country = 'Canada' AND product_type = 'skincare') AS pct_natural_ingredients FROM product_ingredients WHERE product_type = 'skincare' AND contains_natural_ingredients = TRUE AND product_id IN (SELECT product_id FROM cosmetics_sales WHERE country = 'Canada' AND product_type = 'skincare'); |
Delete all records from the 'machinery' table where the 'manufacture_date' is earlier than '2000-01-01' | CREATE TABLE machinery (id INT PRIMARY KEY,name VARCHAR(50),type VARCHAR(50),manufacture_date DATE); INSERT INTO machinery (id,name,type,manufacture_date) VALUES (1,'Bulldozer','Heavy','2002-05-15'); INSERT INTO machinery (id,name,type,manufacture_date) VALUES (2,'Excavator','Heavy','2005-08-08'); INSERT INTO machinery (id,name,type,manufacture_date) VALUES (3,'Drill','Light','1999-12-31'); | DELETE FROM machinery WHERE manufacture_date < '2000-01-01'; |
What is the average speed of vehicles on each route? | CREATE TABLE routes (route_id INT,route_name TEXT);CREATE TABLE vehicles (vehicle_id INT,route_id INT,speed INT); INSERT INTO routes VALUES (123,'Route 123'); INSERT INTO routes VALUES (456,'Route 456'); INSERT INTO vehicles VALUES (1,123,50); INSERT INTO vehicles VALUES (2,123,55); INSERT INTO vehicles VALUES (3,456,45); INSERT INTO vehicles VALUES (4,456,40); | SELECT routes.route_name, AVG(vehicles.speed) FROM routes INNER JOIN vehicles ON routes.route_id = vehicles.route_id GROUP BY routes.route_name; |
Number of patients who did not show improvement after dialectical behavior therapy (DBT) treatment in the USA. | CREATE TABLE patients (patient_id INT,country VARCHAR(50)); INSERT INTO patients (patient_id,country) VALUES (1,'USA'),(2,'Canada'),(3,'USA'); CREATE TABLE treatments (patient_id INT,treatment VARCHAR(10),improvement BOOLEAN); INSERT INTO treatments (patient_id,treatment,improvement) VALUES (1,'DBT',FALSE),(2,'DBT',TRUE),(3,'CBT',TRUE); | SELECT COUNT(patients.patient_id) FROM patients INNER JOIN treatments ON patients.patient_id = treatments.patient_id WHERE treatments.treatment = 'DBT' AND patients.country = 'USA' AND treatments.improvement = FALSE; |
Delete records in the cargo_tracking table for the cargo with cargo_id 'MSCU9982' | CREATE TABLE cargo_tracking (id INT PRIMARY KEY,cargo_id TEXT,vessel_name TEXT,departure_port TEXT,arrival_port TEXT,eta DATE); | DELETE FROM cargo_tracking WHERE cargo_id = 'MSCU9982'; |
What is the minimum tenure for members in the 'manufacturing' department? | CREATE TABLE union_membership (id INT,name VARCHAR(50),department VARCHAR(50),tenure INT); INSERT INTO union_membership (id,name,department,tenure) VALUES (1,'Alice','technology',5); INSERT INTO union_membership (id,name,department,tenure) VALUES (2,'Bob','technology',3); INSERT INTO union_membership (id,name,department,tenure) VALUES (3,'Charlie','manufacturing',4); | SELECT MIN(tenure) FROM union_membership WHERE department = 'manufacturing'; |
Identify the AI safety scores for models used in the healthcare sector in South America. | CREATE TABLE ai_safety_scores_2 (id INT,model_name VARCHAR(50),sector VARCHAR(50),region VARCHAR(50),score FLOAT); INSERT INTO ai_safety_scores_2 VALUES (1,'HealthAI1','Healthcare','South America',0.89),(2,'HealthAI2','Healthcare','South America',0.75),(3,'HealthAI3','Healthcare','Europe',0.92); | SELECT model_name, score FROM ai_safety_scores_2 WHERE sector = 'Healthcare' AND region = 'South America'; |
What is the average age of attendees who have participated in visual arts programs in the past year, grouped by their country of origin? | CREATE TABLE Attendees (Id INT,Age INT,Country VARCHAR(50));CREATE TABLE VisualArtsPrograms (Id INT,AttendeeId INT,ProgramDate DATE); | SELECT A.Country, AVG(A.Age) FROM Attendees A INNER JOIN VisualArtsPrograms VAP ON A.Id = VAP.AttendeeId WHERE VAP.ProgramDate >= DATEADD(year, -1, GETDATE()) GROUP BY A.Country; |
Delete records of vessels arriving at the Port of Long Beach before 2020-01-01. | CREATE TABLE Vessels (Id INT,Name VARCHAR(50),Type VARCHAR(50),MaxSpeed DECIMAL(5,2)); INSERT INTO Vessels VALUES (1,'VesselA','Cargo',25.5),(2,'VesselB','Tanker',18.3); CREATE TABLE PortArrivals (Id INT,VesselId INT,Port VARCHAR(50),ArrivalDate DATE); INSERT INTO PortArrivals VALUES (1,1,'Oakland','2022-02-15'),(2,2,'Oakland','2022-02-17'),(3,1,'Long Beach','2019-12-31'),(4,1,'Long Beach','2019-12-15'); | DELETE FROM PortArrivals WHERE Port = 'Long Beach' AND ArrivalDate < '2020-01-01'; |
find the total carbon sequestration by country for 2020 | CREATE TABLE country (country_id INT,country_name VARCHAR(255)); INSERT INTO country (country_id,country_name) VALUES (1,'Canada'),(2,'USA'); CREATE TABLE forest (forest_id INT,country_id INT,carbon_sequestration INT); INSERT INTO forest (forest_id,country_id,carbon_sequestration) VALUES (1,1,1000),(2,1,1500),(3,2,2000),(4,2,2500); | SELECT c.country_name, SUM(f.carbon_sequestration) as total_carbon_sequestration FROM forest f JOIN country c ON f.country_id = c.country_id WHERE f.year = 2020 GROUP BY c.country_name; |
List all routes with more than 50 shipments in the last 30 days. | CREATE TABLE Routes (route_id INT,origin VARCHAR(50),destination VARCHAR(50)); CREATE TABLE Shipments (shipment_id INT,route_id INT,shipment_date DATE); INSERT INTO Routes (route_id,origin,destination) VALUES (1,'Seattle','Chicago'); INSERT INTO Shipments (shipment_id,route_id,shipment_date) VALUES (1,1,'2021-04-15'); INSERT INTO Shipments (shipment_id,route_id,shipment_date) VALUES (2,1,'2021-04-16'); | SELECT Routes.* FROM Routes INNER JOIN (SELECT route_id, COUNT(*) as shipment_count FROM Shipments WHERE shipment_date BETWEEN DATEADD(day, -30, GETDATE()) AND GETDATE() GROUP BY route_id) as ShipmentCounts ON Routes.route_id = ShipmentCounts.route_id WHERE ShipmentCounts.shipment_count > 50; |
Find the total number of ad impressions and their cost for ads with the keyword 'greenenergy' in the 'advertising' table. | CREATE TABLE advertising(id INT,ad_text TEXT,impressions INT,cost DECIMAL(10,2),keyword TEXT); | SELECT SUM(impressions) AS total_impressions, SUM(cost) AS total_cost FROM advertising WHERE keyword = 'greenenergy'; |
What is the average virtual tour rating of cultural heritage sites in Vienna? | CREATE TABLE cultural_sites (site_id INT,city TEXT,virtual_tour_rating FLOAT); INSERT INTO cultural_sites (site_id,city,virtual_tour_rating) VALUES (1,'Vienna',4.6),(2,'Vienna',4.9); | SELECT AVG(virtual_tour_rating) FROM cultural_sites WHERE city = 'Vienna'; |
What are the total sales for each country? | CREATE TABLE Suppliers (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),establishment_date DATE); INSERT INTO Suppliers (id,name,country,establishment_date) VALUES (1,'Supplier A','USA','2000-01-01'); INSERT INTO Suppliers (id,name,country,establishment_date) VALUES (2,'Supplier B','Canada','2005-01-01'); INSERT INTO Suppliers (id,name,country,establishment_date) VALUES (3,'Supplier C','India','1998-04-03'); CREATE TABLE Sales (id INT PRIMARY KEY,product_id INT,quantity INT,sale_date DATE,supplier_id INT,FOREIGN KEY (product_id) REFERENCES Products(id),FOREIGN KEY (supplier_id) REFERENCES Suppliers(id)); INSERT INTO Sales (id,product_id,quantity,sale_date,supplier_id) VALUES (1,1,10,'2021-01-01',1); INSERT INTO Sales (id,product_id,quantity,sale_date,supplier_id) VALUES (2,2,15,'2021-02-01',2); INSERT INTO Sales (id,product_id,quantity,sale_date,supplier_id) VALUES (3,3,8,'2021-03-01',3); | SELECT Suppliers.country, SUM(Sales.quantity) as total_sales FROM Sales INNER JOIN Suppliers ON Sales.supplier_id = Suppliers.id GROUP BY Suppliers.country |
What is the average maintenance cost for each vehicle type? | CREATE TABLE vehicle_maintenance (vehicle_type VARCHAR(50),maintenance_cost DECIMAL(10,2)); INSERT INTO vehicle_maintenance (vehicle_type,maintenance_cost) VALUES ('Bus',500.00),('Tram',800.00),('Subway',1000.00); | SELECT vehicle_type, AVG(maintenance_cost) FROM vehicle_maintenance GROUP BY vehicle_type; |
What is the rank of Canada in terms of the number of tourists visiting from North America? | CREATE TABLE tourism (visitor_continent VARCHAR(50),host_country VARCHAR(50),number_of_tourists INT); INSERT INTO tourism (visitor_continent,host_country,number_of_tourists) VALUES ('North America','Canada',600000),('North America','United States',800000),('North America','Mexico',700000); | SELECT host_country, RANK() OVER (ORDER BY number_of_tourists DESC) as rank FROM tourism WHERE visitor_continent = 'North America'; |
What is the maximum age of patients who received the AstraZeneca vaccine in California? | CREATE TABLE vaccine_administered (patient_id INT,vaccine_name VARCHAR(255),state VARCHAR(255)); CREATE TABLE patients (patient_id INT,age INT); INSERT INTO vaccine_administered (patient_id,vaccine_name,state) VALUES (1,'AstraZeneca','California'); INSERT INTO patients (patient_id,age) VALUES (1,60); | SELECT MAX(y.age) FROM patients y INNER JOIN vaccine_administered a ON y.patient_id = a.patient_id WHERE a.vaccine_name = 'AstraZeneca' AND a.state = 'California'; |
What is the average depth of all the seas in the 'oceanographic_data' table?" | CREATE TABLE oceanographic_data (sea_name VARCHAR(50),avg_depth DECIMAL(5,2)); | SELECT AVG(avg_depth) FROM oceanographic_data; |
What is the average transaction amount per customer in the Southeast region? | CREATE TABLE customers (customer_id INT,customer_name VARCHAR(50),region VARCHAR(50)); INSERT INTO customers (customer_id,customer_name,region) VALUES (1,'John Smith','Southeast'),(2,'Jane Doe','Northeast'); CREATE TABLE transactions (transaction_id INT,customer_id INT,amount DECIMAL(10,2)); INSERT INTO transactions (transaction_id,customer_id,amount) VALUES (1,1,100.50),(2,1,200.75),(3,2,50.00); | SELECT AVG(amount) FROM transactions t JOIN customers c ON t.customer_id = c.customer_id WHERE c.region = 'Southeast'; |
What is the average listing price for co-owned properties in Seattle? | CREATE TABLE co_owned_properties (id INT,city VARCHAR(20),listing_price DECIMAL(10,2)); INSERT INTO co_owned_properties (id,city,listing_price) VALUES (1,'Seattle',750000.00),(2,'New York',1200000.00); | SELECT AVG(listing_price) FROM co_owned_properties WHERE city = 'Seattle'; |
What is the total cost of humanitarian assistance provided by France and Germany combined in the Middle East since 2010? | CREATE TABLE humanitarian_assistance (donor VARCHAR(255),region VARCHAR(255),cost DECIMAL(10,2),assistance_date DATE); | SELECT SUM(cost) FROM humanitarian_assistance WHERE (donor = 'France' OR donor = 'Germany') AND region = 'Middle East' AND assistance_date >= '2010-01-01'; |
Update the waste generation for the 'North' region in 2022 to 65000. | CREATE TABLE waste_generation(region VARCHAR(20),year INT,waste_gram INT); INSERT INTO waste_generation(region,year,waste_gram) VALUES('North',2021,50000),('North',2022,60000),('South',2021,40000),('South',2022,70000); | UPDATE waste_generation SET waste_gram = 65000 WHERE region = 'North' AND year = 2022; |
Insert a new policy record for policyholder_id 500 and policyholder_state 'CA' in the 'Policy' table. | CREATE TABLE Policy (policy_id INT,policyholder_id INT,policyholder_state VARCHAR(20)); | INSERT INTO Policy (policy_id, policyholder_id, policyholder_state) VALUES (1, 500, 'CA'); |
What is the average sale quantity of military equipment for the 'Africa' region by 'Yellow Defense Inc.'? | CREATE TABLE YellowDefenseIncSales(id INT,company VARCHAR(255),region VARCHAR(255),equipment VARCHAR(255),quantity INT);INSERT INTO YellowDefenseIncSales(id,company,region,equipment,quantity) VALUES (1,'Yellow Defense Inc.','Africa','Armored Vehicles',120); | SELECT AVG(quantity) FROM YellowDefenseIncSales WHERE company = 'Yellow Defense Inc.' AND region = 'Africa'; |
List astronauts who have flown on missions with crew larger than 4? | CREATE TABLE Astronauts (ID INT,Name VARCHAR(255),Missions INT); CREATE TABLE Missions (ID INT,Name VARCHAR(255),CrewSize INT); INSERT INTO Astronauts (ID,Name,Missions) VALUES (1,'Astronaut1',3),(2,'Astronaut2',5); INSERT INTO Missions (ID,Name,CrewSize) VALUES (1,'Mission1',4),(2,'Mission2',6); | SELECT Astronauts.Name FROM Astronauts INNER JOIN Missions ON Astronauts.Missions = Missions.ID WHERE Missions.CrewSize > 4; |
How many customers have a specific combination of top and bottom sizes? | CREATE TABLE CustomerSizes (CustomerID INT,TopSize VARCHAR(10),BottomSize VARCHAR(10)); INSERT INTO CustomerSizes (CustomerID,TopSize,BottomSize) VALUES (1,'M','L'),(2,'S','M'),(3,'L','XL'); | SELECT TopSize, BottomSize, COUNT(*) AS CustomerCount FROM CustomerSizes GROUP BY TopSize, BottomSize HAVING TopSize = 'L' AND BottomSize = 'XL'; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.