instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
How many events had an attendance of over 500 in 2020?
CREATE TABLE Events (EventID int,EventDate date,EventAttendance int);
SELECT COUNT(*) FROM Events WHERE EventAttendance > 500 AND EventDate BETWEEN '2020-01-01' AND '2020-12-31';
What is the most common type of space debris?
CREATE TABLE space_debris (id INT,debris_type TEXT,frequency INT); INSERT INTO space_debris (id,debris_type,frequency) VALUES (1,'Spent rocket stages',2500),(2,'Defunct satellites',2000),(3,'Fuel tanks',500),(4,'Nuts and bolts',1000),(5,' fragments from disintegration and collisions',5000);
SELECT debris_type FROM space_debris ORDER BY frequency DESC LIMIT 1;
Update the 'publication_date' of an article with 'article_id' 1 in the 'articles' table
CREATE TABLE articles (article_id INT PRIMARY KEY,title VARCHAR(255),content TEXT,publication_date DATE);
UPDATE articles SET publication_date = '2022-01-15' WHERE article_id = 1;
What was the total number of volunteer hours for each program in Q3 2020, grouped by city?
CREATE TABLE Volunteers (VolunteerID INT,Name TEXT,City TEXT,Hours DECIMAL(10,2)); CREATE TABLE Programs (ProgramID INT,Name TEXT,VolunteerID INT,StartDate DATE); INSERT INTO Volunteers (VolunteerID,Name,City,Hours) VALUES (1,'James Johnson','New York',20.00),(2,'Natalie Brown','Los Angeles',25.00),(3,'Michael Davis','...
SELECT City, SUM(Hours) as 'Total Volunteer Hours' FROM Volunteers INNER JOIN Programs ON Volunteers.VolunteerID = Programs.VolunteerID WHERE Programs.StartDate BETWEEN '2020-07-01' AND '2020-09-30' GROUP BY City;
How many workers are employed in factories located in the Global South?
CREATE TABLE Factories (factory_id INT,name VARCHAR(100),location VARCHAR(100),num_workers INT); CREATE TABLE Regions (region_id INT,name VARCHAR(100),continent VARCHAR(50)); INSERT INTO Factories VALUES (1,'Factory A','New York',200),(2,'Factory B','Mumbai',350),(3,'Factory C','Dhaka',500),(4,'Factory D','São Paulo',4...
SELECT COUNT(Factories.num_workers) FROM Factories JOIN Regions ON Factories.location = Regions.name WHERE Regions.continent = 'Asia' OR Regions.continent = 'America';
List the accommodation types and their respective costs for students in the StudentAccommodations table.
CREATE TABLE StudentAccommodations (studentID INT,accommodationType VARCHAR(50),cost FLOAT);
SELECT accommodationType, cost FROM StudentAccommodations;
Which countries have above-average carbon sequestration in both 2017 and 2020?
CREATE TABLE carbon_sequestration (country VARCHAR(255),year INT,sequestration FLOAT); INSERT INTO carbon_sequestration (country,year,sequestration) VALUES ('Country A',2017,1200.0),('Country B',2017,1500.0),('Country A',2020,1400.0),('Country C',2020,1600.0);
SELECT country FROM carbon_sequestration WHERE sequestration > (SELECT AVG(sequestration) FROM carbon_sequestration WHERE year = 2017) AND country IN (SELECT country FROM carbon_sequestration WHERE year = 2020 AND sequestration > (SELECT AVG(sequestration) FROM carbon_sequestration WHERE year = 2020)) GROUP BY country ...
Delete all satellites launched by a specific country?
CREATE TABLE satellites (id INT,name VARCHAR(255),country VARCHAR(255),launch_date DATE); INSERT INTO satellites (id,name,country,launch_date) VALUES (1,'Satellite1','USA','2010-01-01'); INSERT INTO satellites (id,name,country,launch_date) VALUES (2,'Satellite2','Russia','2015-05-12');
DELETE FROM satellites WHERE country = 'USA';
What is the total waste generation in gram by each city?
CREATE TABLE Cities (id INT,city_name VARCHAR(255)); INSERT INTO Cities (id,city_name) VALUES (1,'CityA'),(2,'CityB'); CREATE TABLE WasteData (city_id INT,waste_generation INT,date DATE); INSERT INTO WasteData (city_id,waste_generation,date) VALUES (1,1200,'2021-01-01'),(1,1500,'2021-01-02'),(2,800,'2021-01-01'),(2,100...
SELECT Cities.city_name, SUM(WasteData.waste_generation) FROM Cities INNER JOIN WasteData ON Cities.id = WasteData.city_id GROUP BY Cities.city_name;
What is the average production volume of neodymium in 2020 and 2021?
CREATE TABLE production (year INT,element TEXT,volume INT); INSERT INTO production (year,element,volume) VALUES (2020,'neodymium',12000),(2021,'neodymium',15000);
SELECT AVG(volume) FROM production WHERE element = 'neodymium' AND year IN (2020, 2021);
Which cities have multimodal transportation systems with the highest number of electric scooters?
CREATE TABLE cities (city_id INT,has_multimodal BOOLEAN,num_escooters INT); INSERT INTO cities (city_id,has_multimodal,num_escooters) VALUES (1,true,500),(2,false,300),(3,true,700);
SELECT city_id, num_escooters FROM cities WHERE has_multimodal = true ORDER BY num_escooters DESC LIMIT 1;
What is the total number of concert venues in 'New York' and 'Los Angeles'?
CREATE TABLE Venues (VenueID INT,VenueName VARCHAR(100),Location VARCHAR(50)); INSERT INTO Venues (VenueID,VenueName,Location) VALUES (1001,'VenueA','New York'),(1002,'VenueB','Los Angeles'),(1003,'VenueC','Tokyo'),(1004,'VenueD','Paris'),(1005,'VenueE','Sydney');
SELECT COUNT(DISTINCT VenueID) AS TotalVenues FROM Venues WHERE Location IN ('New York', 'Los Angeles');
What is the minimum salary of workers in the renewable energy sector in India?
CREATE TABLE workers (id INT,name VARCHAR(50),country VARCHAR(50),sector VARCHAR(50),salary DECIMAL(10,2));
SELECT MIN(salary) FROM workers WHERE country = 'India' AND sector = 'Renewable Energy';
How many climate adaptation projects were initiated in the Pacific Islands between 2016 and 2018?
CREATE TABLE adaptation_projects (project_id INT,year INT,region VARCHAR(255)); INSERT INTO adaptation_projects VALUES (1,2016,'Pacific Islands'),(2,2018,'Pacific Islands');
SELECT COUNT(*) FROM adaptation_projects WHERE region = 'Pacific Islands' AND year BETWEEN 2016 AND 2018;
Who are the top 3 artists with the highest number of streams in the "Jazz" genre?
CREATE TABLE music_streaming (id INT,artist VARCHAR(50),song VARCHAR(50),genre VARCHAR(20),streamed_on DATE,revenue DECIMAL(10,2),streams INT); CREATE VIEW artist_streams AS SELECT artist,genre,SUM(streams) AS total_streams FROM music_streaming GROUP BY artist,genre;
SELECT artist, total_streams FROM artist_streams WHERE genre = 'Jazz' ORDER BY total_streams DESC LIMIT 3;
Count the number of mental health services provided to patients in 'Toronto' and 'Montreal' in 2022.
CREATE TABLE MentalHealthServices (ID INT PRIMARY KEY,PatientID INT,ProviderID INT,Service VARCHAR(50),City VARCHAR(50),Year INT); INSERT INTO MentalHealthServices (ID,PatientID,ProviderID,Service,City,Year) VALUES (1,101,201,'Therapy','Toronto',2022); INSERT INTO MentalHealthServices (ID,PatientID,ProviderID,Service,C...
SELECT City, COUNT(*) FROM MentalHealthServices WHERE Year = 2022 GROUP BY City HAVING City IN ('Toronto', 'Montreal');
What is the total revenue generated from each state for the year 2022?
CREATE SCHEMA fitness; CREATE TABLE memberships (id INT,member_name VARCHAR(255),city VARCHAR(255),state VARCHAR(255),join_date DATE,membership_type VARCHAR(255),price DECIMAL(10,2));
SELECT state, SUM(price) FROM fitness.memberships WHERE YEAR(join_date) = 2022 GROUP BY state;
What is the average dissolved oxygen level (in mg/L) for fish farms located in the Asia Pacific region, excluding those with a depth of less than 5 meters?
CREATE TABLE fish_farms (id INT,name VARCHAR(255),region VARCHAR(255),depth FLOAT,dissolved_oxygen_level FLOAT); INSERT INTO fish_farms (id,name,region,depth,dissolved_oxygen_level) VALUES (1,'Farm A','Asia Pacific',6.2,7.1),(2,'Farm B','Asia Pacific',4.8,6.5),(3,'Farm C','North America',8.5,6.3);
SELECT AVG(dissolved_oxygen_level) FROM fish_farms WHERE region = 'Asia Pacific' AND depth >= 5;
Find the total number of marine species in the OceanLife database.
CREATE TABLE OceanLife (id INT,species TEXT,status TEXT); INSERT INTO OceanLife (id,species,status) VALUES (1,'Blue Whale','Endangered'); INSERT INTO OceanLife (id,species,status) VALUES (2,'Dolphin','Protected'); INSERT INTO OceanLife (id,species,status) VALUES (3,'Clownfish','Protected'); INSERT INTO OceanLife (id,sp...
SELECT COUNT(*) FROM OceanLife;
What is the average salary of developers in the IT department?
CREATE TABLE employees (id INT,name VARCHAR(50),department VARCHAR(50),position VARCHAR(50),salary FLOAT); INSERT INTO employees (id,name,department,position,salary) VALUES (1,'John Doe','IT','Developer',75000.0),(2,'Jane Smith','IT','Developer',80000.0);
SELECT AVG(salary) FROM employees WHERE department = 'IT' AND position = 'Developer';
List all unique machinery types and their respective manufacturers in the 'mining_machinery' and 'manufacturers' tables.
CREATE TABLE mining_machinery (equipment_type VARCHAR(50),machine_model VARCHAR(50)); INSERT INTO mining_machinery (equipment_type,machine_model) VALUES ('Drilling Rig','DR-500'),('Excavator','EX-300'); CREATE TABLE manufacturers (manufacturer_id INT,manufacturer_name VARCHAR(50),machine_model VARCHAR(50)); INSERT INTO...
SELECT mining_machinery.equipment_type, manufacturers.manufacturer_name FROM mining_machinery INNER JOIN manufacturers ON mining_machinery.machine_model = manufacturers.machine_model;
What is the landfill capacity in Mumbai in 2025?
CREATE TABLE landfill_capacity (city varchar(255),year int,capacity int); INSERT INTO landfill_capacity (city,year,capacity) VALUES ('Mumbai',2020,5000000),('Mumbai',2025,4500000),('Mumbai',2030,4000000);
SELECT capacity FROM landfill_capacity WHERE city = 'Mumbai' AND year = 2025;
What is the minimum depth of marine protected areas in the Arctic Ocean region?
CREATE TABLE arctic_marine_protected_areas (id INT,name TEXT,region TEXT,min_depth FLOAT); INSERT INTO arctic_marine_protected_areas (id,name,region,min_depth) VALUES (1,'Norwegian Trench','Arctic',3000.0),(2,'Fram Strait','Arctic',2500.0);
SELECT MIN(min_depth) FROM arctic_marine_protected_areas WHERE region = 'Arctic';
What is the average energy consumption of buildings constructed after 2015 and located in 'Urban' areas in the 'GreenBuildings' table?
CREATE TABLE GreenBuildings (id INT,name VARCHAR(50),constructionDate DATE,location VARCHAR(50),energyConsumption DECIMAL(5,2));
SELECT AVG(energyConsumption) FROM GreenBuildings WHERE constructionDate > '2015-01-01' AND location = 'Urban';
What is the total production of 'corn' and 'wheat' for each state?
CREATE TABLE states (id INT PRIMARY KEY,name TEXT,region TEXT); INSERT INTO states (id,name,region) VALUES (1,'Alabama','South'); CREATE TABLE crops (id INT PRIMARY KEY,state_id INT,crop TEXT,production INT); INSERT INTO crops (id,state_id,crop,production) VALUES (1,1,'corn',500);
SELECT state_id, SUM(production) FROM crops WHERE crop IN ('corn', 'wheat') GROUP BY state_id;
What is the safety record for product 103?
CREATE TABLE product_safety_records (id INT,product_id INT,incident_date DATE,incident_description VARCHAR(255)); INSERT INTO product_safety_records (id,product_id,incident_date,incident_description) VALUES (1,101,'2020-01-01','Minor irritation'),(2,103,'2019-12-15','Allergy reported'),(3,102,'2019-11-30','No incidents...
SELECT incident_date, incident_description FROM product_safety_records WHERE product_id = 103;
What is the maximum number of military satellites in orbit for each country?
CREATE TABLE satellites (id INT,satellite_name VARCHAR(255),country VARCHAR(255),in_orbit BOOLEAN); INSERT INTO satellites (id,satellite_name,country,in_orbit) VALUES (1,'Satellite A','USA',TRUE),(2,'Satellite B','USA',TRUE),(3,'Satellite C','Russia',TRUE); CREATE VIEW country_satellites AS SELECT country,COUNT(*) as t...
SELECT country, MAX(total_satellites) FROM country_satellites;
What are the total minutes spent in fitness classes by each member?
CREATE TABLE class_minutes(member_id INT,class_type VARCHAR(20),minutes INT); INSERT INTO class_minutes(member_id,class_type,minutes) VALUES (1,'Yoga',60); INSERT INTO class_minutes(member_id,class_type,minutes) VALUES (1,'Pilates',45); INSERT INTO class_minutes(member_id,class_type,minutes) VALUES (2,'Yoga',90); INSER...
SELECT member_id, SUM(minutes) as total_minutes FROM class_minutes GROUP BY member_id;
What is the difference in safety scores between the union with the highest and lowest safety scores?
CREATE TABLE unions (id INT,name TEXT,location TEXT,type TEXT,safety_score INT); INSERT INTO unions (id,name,location,type,safety_score) VALUES (1,'Union A','Germany','Manufacturing',90),(2,'Union B','France','Manufacturing',70);
SELECT MAX(safety_score) - MIN(safety_score) FROM unions WHERE type = 'Manufacturing';
Add a new row to the 'ingredient_sources' table with 'ingredient_name' 'Shea Butter', 'source_country' 'Ghana', and 'sustainable' 'Yes'
CREATE TABLE ingredient_sources (source_id INT PRIMARY KEY,ingredient_name VARCHAR(255),source_country VARCHAR(100),sustainable VARCHAR(10));
INSERT INTO ingredient_sources (ingredient_name, source_country, sustainable) VALUES ('Shea Butter', 'Ghana', 'Yes');
How many socially responsible loans were issued in Q2 2021?
CREATE TABLE loans (loan_number INT,issue_date DATE,is_socially_responsible BOOLEAN); INSERT INTO loans (loan_number,issue_date,is_socially_responsible) VALUES (1,'2021-04-01',true),(2,'2021-05-15',false),(3,'2021-07-03',true);
SELECT COUNT(*) FROM loans WHERE is_socially_responsible = true AND issue_date BETWEEN '2021-04-01' AND '2021-06-30';
What is the average funding received by startups in the food sector founded by a person from a historically underrepresented community?
CREATE TABLE communities (id INT,name TEXT); INSERT INTO communities (id,name) VALUES (1,'NativeAmerican'); INSERT INTO communities (id,name) VALUES (2,'AfricanAmerican'); CREATE TABLE companies (id INT,name TEXT,industry TEXT,founder_community TEXT,funding_received FLOAT); INSERT INTO companies (id,name,industry,found...
SELECT AVG(funding_received) FROM companies INNER JOIN communities ON companies.founder_community = communities.name WHERE industry = 'Food' AND communities.name IN ('NativeAmerican', 'AfricanAmerican');
What is the total number of disability support programs in California and Texas?
CREATE TABLE SupportPrograms (ProgramID INT,ProgramName VARCHAR(50),State VARCHAR(50)); INSERT INTO SupportPrograms (ProgramID,ProgramName,State) VALUES (1,'Program A','California'),(2,'Program B','Texas'),(3,'Program C','California'),(4,'Program D','Texas'),(5,'Program E','New York'),(6,'Program F','Florida');
SELECT SUM(CASE WHEN State IN ('California', 'Texas') THEN 1 ELSE 0 END) FROM SupportPrograms;
Get the names of all spacecraft that have not been launched and the company that manufactured them, in alphabetical order by company name.
CREATE TABLE Spacecraft_Manufacturing(id INT,company VARCHAR(50),model VARCHAR(50),quantity INT); CREATE TABLE Space_Missions(id INT,mission_name VARCHAR(50),launch_date DATE,spacecraft_name VARCHAR(50));
SELECT s.model, m.company FROM Spacecraft_Manufacturing s LEFT JOIN Space_Missions m ON s.model = m.spacecraft_name WHERE m.spacecraft_name IS NULL ORDER BY m.company;
What is the minimum response time for medical emergencies in 'Harlem'?
CREATE TABLE emergencies (id INT,emergency_type VARCHAR(20),neighborhood VARCHAR(20),response_time FLOAT); INSERT INTO emergencies (id,emergency_type,neighborhood,response_time) VALUES (1,'medical','Harlem',15.2),(2,'fire','Harlem',8.3),(3,'fire','Downtown',10.1),(4,'medical','Harlem',13.8),(5,'medical','Harlem',14.9);
SELECT MIN(response_time) FROM emergencies WHERE emergency_type = 'medical' AND neighborhood = 'Harlem';
What is the average donation amount for 'Education'?
CREATE TABLE education_donations (donation_id INT,donation_amount DECIMAL(10,2),cause_id INT); INSERT INTO education_donations (donation_id,donation_amount,cause_id) VALUES (1,5000.00,1),(2,7500.00,1),(3,12000.00,1);
SELECT AVG(donation_amount) AS avg_donation_amount FROM education_donations WHERE cause_id = 1;
Delete all records of containers shipped from the port of 'Tokyo' from the shipment table.
CREATE TABLE port (port_id INT,port_name TEXT,country TEXT);CREATE TABLE shipment (shipment_id INT,container_count INT,ship_date DATE,port_id INT); INSERT INTO port VALUES (1,'Sydney','Australia'),(2,'Tokyo','Japan'),(3,'Los Angeles','USA'); INSERT INTO shipment VALUES (1,500,'2018-01-01',1),(2,300,'2019-02-15',2),(3,4...
DELETE FROM shipment WHERE port_id IN (SELECT port_id FROM port WHERE port_name = 'Tokyo');
What is the average length of songs released by female artists in the Pop genre between 2010 and 2020?
CREATE TABLE Artists (ArtistID INT,Name VARCHAR(100),Gender VARCHAR(10)); INSERT INTO Artists (ArtistID,Name,Gender) VALUES (1,'Taylor Swift','Female'),(2,'Ariana Grande','Female'); CREATE TABLE Songs (SongID INT,Title VARCHAR(100),Length FLOAT,ArtistID INT,Genre VARCHAR(20),ReleaseYear INT); INSERT INTO Songs (SongID,...
SELECT AVG(Length) FROM Songs WHERE Gender = 'Female' AND Genre = 'Pop' AND ReleaseYear BETWEEN 2010 AND 2020;
Update the eSports tournament start dates to be one week earlier
CREATE TABLE esports_tournaments (id INT PRIMARY KEY,name VARCHAR(50),game_name VARCHAR(50),location VARCHAR(50),start_date DATE,end_date DATE); INSERT INTO esports_tournaments (id,name,game_name,location,start_date,end_date) VALUES (1,'Tournament A','Game X','USA','2023-01-01','2023-01-03'),(2,'Tournament B','Game Y',...
UPDATE esports_tournaments SET start_date = DATEADD(day, -7, start_date);
Identify the average budget allocated to public services in Florida in 2022.
CREATE TABLE PublicServices (state VARCHAR(20),year INT,budget INT); INSERT INTO PublicServices (state,year,budget) VALUES ('Florida',2022,1000000),('Florida',2022,1200000),('Florida',2022,800000),('Florida',2022,1100000);
SELECT AVG(budget) FROM PublicServices WHERE state = 'Florida' AND year = 2022;
Get labor productivity for Barrick Gold
CREATE TABLE productivity (id INT PRIMARY KEY,company VARCHAR(100),value DECIMAL(5,2));
SELECT value FROM productivity WHERE company = 'Barrick Gold';
How many autonomous buses are there in Tokyo and Seoul?
CREATE TABLE autonomous_buses (bus_id INT,city VARCHAR(50)); INSERT INTO autonomous_buses (bus_id,city) VALUES (1,'Tokyo'),(2,'Tokyo'),(3,'Seoul'),(4,'Seoul'),(5,'Seoul');
SELECT COUNT(*) FROM autonomous_buses WHERE city IN ('Tokyo', 'Seoul');
What is the total number of animals in each community education program, ranked from highest to lowest?
CREATE TABLE education_programs (id INT,name VARCHAR(255)); CREATE TABLE education_animals (program_id INT,animal_count INT);
SELECT e.name, SUM(ea.animal_count) as total_animal_count FROM education_programs e JOIN education_animals ea ON e.id = ea.program_id GROUP BY e.name ORDER BY total_animal_count DESC;
How many employees were hired in Q3 of 2020?
CREATE TABLE hires (id INT,employee_id INT,hire_date DATE); INSERT INTO hires (id,employee_id,hire_date) VALUES (1,3,'2020-10-01'),(2,4,'2020-07-15'),(3,5,'2020-09-30');
SELECT COUNT(*) FROM hires WHERE hire_date >= '2020-07-01' AND hire_date <= '2020-09-30';
Which hotel in LATAM has the highest virtual tour engagement?
CREATE TABLE latam_virtual_tours (hotel_id INT,hotel_name VARCHAR(255),views INT);
SELECT hotel_id, hotel_name, MAX(views) FROM latam_virtual_tours;
What is the maximum salary of workers in the 'gas' industry in each province in Canada?
CREATE TABLE workers (id INT,name VARCHAR(50),industry VARCHAR(50),salary FLOAT,country VARCHAR(50)); INSERT INTO workers (id,name,industry,salary,country) VALUES (1,'John Doe','oil',60000,'Canada'); INSERT INTO workers (id,name,industry,salary,country) VALUES (2,'Jane Smith','gas',65000,'Canada'); INSERT INTO workers ...
SELECT provinces.name, MAX(workers.salary) FROM workers INNER JOIN provinces ON workers.country = provinces.country WHERE workers.industry = 'gas' GROUP BY provinces.name;
Find the top 3 cities with the highest ticket sales for the Baseball team.
CREATE TABLE tickets (id INT,game_date DATE,city VARCHAR(50),sales INT,sport VARCHAR(50)); INSERT INTO tickets (id,game_date,city,sales,sport) VALUES (1,'2022-05-01','New York',500,'Baseball'); INSERT INTO tickets (id,game_date,city,sales,sport) VALUES (2,'2022-05-02','Chicago',700,'Baseball');
SELECT city, SUM(sales) AS total_sales FROM tickets WHERE sport = 'Baseball' GROUP BY city ORDER BY total_sales DESC LIMIT 3;
What are the names of all employees who work in the 'Assembly' department and earn a salary greater than $50,000?
CREATE TABLE Employees (EmployeeID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50),Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,Salary) VALUES (1,'John','Doe','Assembly',60000.00),(2,'Jane','Doe','Quality',55000.00),(3,'Mike','Smith','Assembly',52000.00);
SELECT FirstName, LastName FROM Employees WHERE Department = 'Assembly' AND Salary > 50000;
What is the average monthly water usage for residential users in the Los Angeles region for the past year?
CREATE TABLE residential_usage (user_id INT,region VARCHAR(20),usage FLOAT,timestamp TIMESTAMP); INSERT INTO residential_usage (user_id,region,usage,timestamp) VALUES (1,'Los Angeles',15.6,'2022-01-01 10:00:00'),(2,'Los Angeles',14.8,'2022-02-01 10:00:00');
SELECT AVG(usage) FROM residential_usage WHERE region = 'Los Angeles' AND timestamp BETWEEN DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 YEAR) AND CURRENT_TIMESTAMP;
What is the total number of electric vehicles sold in Germany and the UK since 2020?
CREATE TABLE ev_sales_eu (country VARCHAR(50),year INT,make VARCHAR(50),model VARCHAR(50),sales INT); INSERT INTO ev_sales_eu (country,year,make,model,sales) VALUES ('Germany',2020,'Audi','e-Tron',15000),('Germany',2021,'Mercedes-Benz','EQC',20000),('UK',2020,'Tesla','Model 3',35000),('UK',2021,'Nissan','Leaf',20000);
SELECT SUM(sales) FROM ev_sales_eu WHERE (country = 'Germany' OR country = 'UK') AND year >= 2020;
What is the total number of electric vehicles produced by Tesla?
CREATE TABLE tesla_vehicles (id INT,model VARCHAR(50),type VARCHAR(20)); INSERT INTO tesla_vehicles (id,model,type) VALUES (1,'Tesla Model S','Electric'),(2,'Tesla Model 3','Electric'),(3,'Tesla Model X','Electric'),(4,'Tesla Model Y','Electric');
SELECT COUNT(*) FROM tesla_vehicles WHERE type = 'Electric';
What is the total number of visitors who attended exhibitions in the month of February?
CREATE TABLE exhibitions (exhibition_id INT,name VARCHAR(255)); INSERT INTO exhibitions (exhibition_id,name) VALUES (1,'Art of the Renaissance'),(2,'Modern Art'),(3,'Impressionist Art'); CREATE TABLE visitors (visitor_id INT,exhibition_id INT,visit_date DATE); INSERT INTO visitors (visitor_id,exhibition_id,visit_date) ...
SELECT COUNT(visitor_id) as num_visitors FROM visitors WHERE visit_date >= '2022-02-01' AND visit_date <= '2022-02-28';
What was the landfill capacity in cubic meters for the 'West' region in 2021?
CREATE TABLE landfill_capacity (region VARCHAR(20),year INT,capacity INT); INSERT INTO landfill_capacity (region,year,capacity) VALUES ('West',2019,450000),('West',2020,475000),('West',2021,500000);
SELECT capacity FROM landfill_capacity WHERE region = 'West' AND year = 2021;
How many articles were published in each region?
CREATE TABLE articles (id INT,title VARCHAR(50),region VARCHAR(20)); INSERT INTO articles (id,title,region) VALUES (1,'Article1','region1'),(2,'Article2','region2');
SELECT region, COUNT(*) FROM articles GROUP BY region;
What is the total revenue and number of games released for each developer in the 'Arcade' genre?
CREATE TABLE arcade_games (arcade_games_id INT,game_id INT,genre VARCHAR(50),developer VARCHAR(50),revenue DECIMAL(10,2)); INSERT INTO arcade_games VALUES (1,1,'Arcade','Dev1',10000.00),(2,2,'Arcade','Dev2',12000.00),(3,3,'Arcade','Dev1',15000.00),(4,4,'Arcade','Dev3',11000.00);
SELECT developer, genre, SUM(revenue) as total_revenue, COUNT(DISTINCT game_id) as num_games FROM arcade_games WHERE genre = 'Arcade' GROUP BY developer, genre;
What is the average monthly balance for all customers who have a Shariah-compliant savings account?
CREATE TABLE savings (customer_id INT,account_type VARCHAR(20),balance DECIMAL(10,2)); INSERT INTO savings (customer_id,account_type,balance) VALUES (1,'Shariah',5000.00),(2,'Savings',7000.00),(3,'Shariah',3000.00);
SELECT AVG(balance) FROM savings WHERE account_type = 'Shariah';
Insert a new record into the 'Volunteers' table
CREATE TABLE Volunteers (VolunteerID INT PRIMARY KEY,FirstName VARCHAR(50),LastName VARCHAR(50),Email VARCHAR(100));
INSERT INTO Volunteers (VolunteerID, FirstName, LastName, Email) VALUES (201, 'Aaliyah', 'Gonzales', 'aaliyah.gonzales@example.com');
What's the total amount donated by each country in the year 2020?
CREATE TABLE Donors (DonorID INT,DonorName VARCHAR(100),DonationAmount DECIMAL(10,2),DonationDate DATE,DonorCountry VARCHAR(50));
SELECT DonorCountry, SUM(DonationAmount) FROM Donors WHERE YEAR(DonationDate) = 2020 GROUP BY DonorCountry;
What is the total sales revenue for a given product in a given region?
CREATE TABLE products (product_id INT,product_name VARCHAR(50)); INSERT INTO products VALUES (1,'Lipstick 101'),(2,'Eye Shadow 202'); CREATE TABLE sales (sale_id INT,product_id INT,sale_date DATE,region VARCHAR(50),sale_price FLOAT); INSERT INTO sales VALUES (1,1,'2022-01-05','Europe',15.99),(2,2,'2022-02-10','Asia',19...
SELECT SUM(sale_price) FROM sales WHERE product_id = 1 AND region = 'Europe';
What is the carbon sequestration capacity (in tons) for each species in the 'carbon_sequestration' table?
CREATE TABLE carbon_sequestration (id INT,species VARCHAR(255),sequestration_rate FLOAT); INSERT INTO carbon_sequestration (id,species,sequestration_rate) VALUES (1,'Oak',2.5),(2,'Maple',2.3),(3,'Pine',2.8);
SELECT species, sequestration_rate * 10 AS carbon_sequestration_capacity FROM carbon_sequestration;
Who are the volunteers with the least number of hours in the 'VolunteerHours' table?
CREATE TABLE VolunteerHours (VolunteerID INT,VolunteerName VARCHAR(50),Hours INT); INSERT INTO VolunteerHours (VolunteerID,VolunteerName,Hours) VALUES (1,'Sophia Garcia',20),(2,'Ali Hassan',15),(3,'Lea Kim',25),(4,'Han Mehta',10);
SELECT VolunteerID, VolunteerName, Hours FROM VolunteerHours WHERE Hours = (SELECT MIN(Hours) FROM VolunteerHours);
Identify auto show locations in the AutoShows table for shows taking place in 'Canada'.
CREATE TABLE AutoShows (Id INT,Name VARCHAR(50),City VARCHAR(50),State VARCHAR(50),Country VARCHAR(50)); INSERT INTO AutoShows (Id,Name,City,State,Country) VALUES (1,'Montreal International Auto Show','Montreal',NULL,'Canada'),(2,'Detroit Auto Show','Detroit','MI','USA');
SELECT DISTINCT City, Country FROM AutoShows WHERE Country = 'Canada';
What is the maximum installed capacity (in MW) of renewable energy projects in the 'renewable_projects' table?
CREATE TABLE if not exists renewable_projects (project_id INT,project_name VARCHAR(255),location VARCHAR(255),installed_capacity FLOAT);
SELECT MAX(installed_capacity) FROM renewable_projects WHERE installed_capacity IS NOT NULL;
What is the latest marine conservation initiative in the Pacific Ocean?
CREATE TABLE marine_conservation_initiatives (id INT,initiative_name TEXT,start_date DATE,location TEXT); INSERT INTO marine_conservation_initiatives (id,initiative_name,start_date,location) VALUES (1,'Coral Triangle Initiative','2009-01-01','Pacific Ocean'); INSERT INTO marine_conservation_initiatives (id,initiative_n...
SELECT initiative_name FROM marine_conservation_initiatives WHERE location = 'Pacific Ocean' ORDER BY start_date DESC LIMIT 1;
Find the total number of products that are both organic and locally sourced.
CREATE TABLE Products (pid INT,name TEXT,organic BOOLEAN,locally_sourced BOOLEAN);INSERT INTO Products VALUES (1,'ProductA',true,true);
SELECT COUNT(*) FROM Products WHERE organic = true AND locally_sourced = true;
What is the name and manufacturer of the satellites launched from the Vandenberg Air Force Base?
CREATE TABLE LaunchSite (SiteId INT,Name VARCHAR(50),Country VARCHAR(50),Active BOOLEAN); INSERT INTO LaunchSite (SiteId,Name,Country,Active) VALUES (1,'Cape Canaveral','USA',TRUE); INSERT INTO LaunchSite (SiteId,Name,Country,Active) VALUES (2,'Vandenberg Air Force Base','USA',TRUE); INSERT INTO LaunchSite (SiteId,Name...
SELECT Name, Manufacturer FROM Satellite JOIN SpaceMission ON Satellite.LaunchSiteId = SpaceMission.LaunchSiteId WHERE SpaceMission.LaunchSiteId = 2;
What is the average number of songs streamed per user for a specific genre in a given year?
CREATE TABLE Artists (id INT,name VARCHAR(100),genre VARCHAR(50)); CREATE TABLE Users (id INT,name VARCHAR(100)); CREATE TABLE Streams (id INT,user_id INT,artist_id INT,songs_streamed INT,year INT);
SELECT genre, AVG(songs_streamed) AS avg_songs_per_user FROM Streams s JOIN Artists a ON s.artist_id = a.id WHERE year = 2021 GROUP BY genre;
What is the total number of successful and failed space missions by country?
CREATE TABLE Space_Missions (mission_id INT,mission_date DATE,result VARCHAR(255),country VARCHAR(255)); INSERT INTO Space_Missions (mission_id,mission_date,result,country) VALUES (1,'2021-01-01','Success','USA'),(2,'2021-02-01','Failed','China'),(3,'2021-03-01','Success','Russia');
SELECT country, SUM(CASE WHEN result = 'Success' THEN 1 ELSE 0 END) + SUM(CASE WHEN result = 'Failed' THEN 1 ELSE 0 END) FROM Space_Missions GROUP BY country;
What's the average telemetry data length for each communication satellite type?
CREATE TABLE Satellite (id INT PRIMARY KEY,name VARCHAR(50),type VARCHAR(50),manufacturer VARCHAR(50),launch_date DATE); CREATE TABLE Telemetry (id INT PRIMARY KEY,satellite_id INT,telemetry_data TEXT,transmission_date DATE,FOREIGN KEY (satellite_id) REFERENCES Satellite(id));
SELECT Satellite.type, AVG(LENGTH(Telemetry.telemetry_data)) as avg_data_length FROM Satellite INNER JOIN Telemetry ON Satellite.id = Telemetry.satellite_id WHERE Satellite.type = 'Communication' GROUP BY Satellite.type;
How many dishes in the database have a nutritional information label for each cuisine type?
CREATE TABLE dishes (id INT,name VARCHAR(255),cuisine VARCHAR(255),has_nutrition_label BOOLEAN); INSERT INTO dishes (id,name,cuisine,has_nutrition_label) VALUES (1,'Chicken Tikka Masala','Indian',true),(2,'Pizza Margherita','Italian',false),(3,'Pad Thai','Thai',true),(4,'Beef Empanadas','Argentinian',true),(5,'Sushi Ro...
SELECT cuisine, COUNT(*) as num_dishes FROM dishes WHERE has_nutrition_label = true GROUP BY cuisine;
What is the average rating of TV shows by genre?
CREATE TABLE tv_shows (title VARCHAR(255),rating FLOAT,genre VARCHAR(255)); INSERT INTO tv_shows (title,rating,genre) VALUES ('The Wire',9.3,'Crime'),('Friends',8.9,'Comedy');
SELECT genre, AVG(rating) FROM tv_shows GROUP BY genre;
What is the total number of virtual tours in Mexico with a rating of at least 4.5?
CREATE TABLE tours (tour_id INT,country VARCHAR(50),rating FLOAT,tour_type VARCHAR(10)); INSERT INTO tours (tour_id,country,rating,tour_type) VALUES (1,'Mexico',4.7,'virtual'),(2,'Mexico',4.2,'in-person'),(3,'Brazil',4.9,'virtual');
SELECT COUNT(*) FROM tours t WHERE t.country = 'Mexico' AND t.rating >= 4.5 AND t.tour_type = 'virtual';
List all garments and their corresponding categories from the garments table
CREATE TABLE garments (id INT,name VARCHAR(100),price DECIMAL(5,2),category VARCHAR(50));
SELECT id, name, category FROM garments;
What is the average water temperature change per hour for each aquafarm in the Indian region?
CREATE TABLE aquafarms (id INT,name TEXT,location TEXT); INSERT INTO aquafarms (id,name,location) VALUES (1,'Farm A','Pacific'),(2,'Farm B','Atlantic'),(7,'Farm G','Indian'); CREATE TABLE temperature_data (aquafarm_id INT,timestamp TIMESTAMP,temperature FLOAT);
SELECT aquafarm_id, AVG(temp_diff) AS avg_temp_change, EXTRACT(HOUR FROM timestamp) AS hour FROM (SELECT aquafarm_id, temperature, LAG(temperature) OVER (PARTITION BY aquafarm_id ORDER BY timestamp) AS prev_temperature, (temperature - COALESCE(prev_temperature, temperature)) AS temp_diff FROM temperature_data) temperat...
Who are the community engagement coordinators in the 'community_engagement' schema?
CREATE TABLE community_engagement (id INT,name VARCHAR(255),role VARCHAR(255)); INSERT INTO community_engagement (id,name,role) VALUES (1,'John Doe','Coordinator'),(2,'Jane Smith','Assistant Coordinator');
SELECT name, role FROM community_engagement.community_engagement WHERE role LIKE 'Coordinator%';
What are the names of the exhibitions where Impressionist artworks were displayed?
CREATE TABLE Exhibitions(id INT,name VARCHAR(255)); CREATE TABLE Artworks(id INT,title VARCHAR(255),exhibition_id INT,art_style VARCHAR(255)); INSERT INTO Exhibitions(id,name) VALUES (1,'Impressionist Exhibition'); INSERT INTO Artworks(id,title,exhibition_id,art_style) VALUES (1,'Impression,Sunrise',1,'Impressionism');...
SELECT Exhibitions.name FROM Exhibitions INNER JOIN Artworks ON Exhibitions.id = Artworks.exhibition_id WHERE Artworks.art_style = 'Impressionism';
What is the total number of electric vehicles in the 'electric_vehicles' table, grouped by their 'year' of manufacture?
CREATE TABLE electric_vehicles (id INT,vehicle_id INT,year INT,manufacturer VARCHAR(255));
SELECT year, COUNT(*) FROM electric_vehicles GROUP BY year;
What is the percentage of electric vehicles in 'EV Adoption Statistics' table by country?
CREATE TABLE EV_Adoption_Statistics (country VARCHAR(50),vehicle_type VARCHAR(20),num_adopted INT,total_vehicles INT);
SELECT country, (COUNT(*) FILTER (WHERE vehicle_type = 'Electric')::DECIMAL/COUNT(*)::DECIMAL) * 100 FROM EV_Adoption_Statistics GROUP BY country;
Insert a new record into the 'shariah_compliant_finance' table for a client in the United Arab Emirates who has invested in a Shariah-compliant fund.
CREATE TABLE shariah_compliant_finance (client_id INT,investment_type VARCHAR(50),country VARCHAR(50));
INSERT INTO shariah_compliant_finance VALUES (5, 'Shariah-compliant Fund', 'United Arab Emirates');
What is the total installed solar capacity in MW for projects in the 'renewable_energy' table?
CREATE TABLE renewable_energy (project_id INT,location TEXT,installed_capacity FLOAT); INSERT INTO renewable_energy (project_id,location,installed_capacity) VALUES (1,'San Francisco',100.5),(2,'New York',200.3);
SELECT SUM(installed_capacity) FROM renewable_energy WHERE technology = 'Solar';
List all the unique genres and countries where artists come from, based on the 'genre' table and 'artist' table joined with the 'country' table.
CREATE TABLE genre (genre_id INT,genre_name VARCHAR(255)); CREATE TABLE artist (artist_id INT,artist_name VARCHAR(255),genre_id INT,country_id INT); CREATE TABLE country (country_id INT,country_name VARCHAR(255));
SELECT DISTINCT g.genre_name, c.country_name FROM genre g INNER JOIN artist a ON g.genre_id = a.genre_id INNER JOIN country c ON a.country_id = c.country_id;
What is the average distance traveled for home health services in Dallas county?
CREATE TABLE home_health_services (id INT,county VARCHAR(20),distance FLOAT); INSERT INTO home_health_services (id,county,distance) VALUES (1,'Dallas',12.3),(2,'Dallas',14.5),(3,'Houston',10.0);
SELECT AVG(distance) FROM home_health_services WHERE county = 'Dallas';
How many greenhouse gas emissions have been reported for each manufacturer in the ethical fashion industry?
CREATE TABLE greenhouse_gas_emissions (manufacturer_id INT,emissions INT); INSERT INTO greenhouse_gas_emissions (manufacturer_id,emissions) VALUES (1,5000),(2,3000),(3,6000),(4,4000),(5,7000);
SELECT manufacturer_id, emissions FROM greenhouse_gas_emissions;
Delete the record for the organization "Greenpeace" from the "organizations" table
CREATE TABLE organizations (id INT PRIMARY KEY,name VARCHAR(50),primary_focus VARCHAR(50));
DELETE FROM organizations WHERE name = 'Greenpeace';
Show the total ad spend and impressions for each campaign in the advertising table that had a spend greater than $5000 in the last week.
CREATE TABLE advertising (campaign_id INT,spend DECIMAL(10,2),impressions INT,start_date DATE,end_date DATE);
SELECT campaign_id, SUM(spend) as total_spend, SUM(impressions) as total_impressions FROM advertising WHERE start_date <= DATE_SUB(CURDATE(), INTERVAL 1 WEEK) AND end_date >= DATE_SUB(CURDATE(), INTERVAL 1 WEEK) AND spend > 5000 GROUP BY campaign_id;
Insert new fish species into the existing fish_species table
CREATE TABLE fish_species (id INT,species VARCHAR(50),scientific_name VARCHAR(50)); INSERT INTO fish_species (id,species,scientific_name) VALUES (1,'Tilapia','Oreochromis niloticus');
INSERT INTO fish_species (species, scientific_name) VALUES ('Tilapia', 'Oreochromis niloticus');
What is the average cargo weight per port for ports in South America?
CREATE TABLE Ports (PortID INT,Name VARCHAR(255),Country VARCHAR(255)); CREATE TABLE Cargo (CargoID INT,PortID INT,Weight INT); INSERT INTO Ports (PortID,Name,Country) VALUES (1,'Rio de Janeiro','Brazil'),(2,'Buenos Aires','Argentina'); INSERT INTO Cargo (CargoID,PortID,Weight) VALUES (1,1,5000),(2,1,3000),(3,2,7000),(...
SELECT Ports.Name, AVG(Cargo.Weight) FROM Ports INNER JOIN Cargo ON Ports.PortID = Cargo.PortID WHERE Ports.Country LIKE 'South%' GROUP BY Ports.Name;
What is the total revenue for each restaurant in a given city?
CREATE TABLE restaurants (restaurant_id INT,city VARCHAR(255),revenue INT); INSERT INTO restaurants (restaurant_id,city,revenue) VALUES (1,'New York',5000),(2,'Los Angeles',7000),(3,'New York',8000);
SELECT city, revenue FROM restaurants GROUP BY city;
How many exhibitions were hosted by the 'Modern Art Museum' in 2015 and 2016 combined?
CREATE TABLE Exhibitions (exhibition_id INT,museum_name VARCHAR(255),exhibition_year INT);
SELECT COUNT(*) FROM Exhibitions WHERE museum_name = 'Modern Art Museum' AND exhibition_year IN (2015, 2016);
What is the maximum funding amount received by a company founded by a person from the LGBTQ+ community?
CREATE TABLE Companies (id INT,name TEXT,industry TEXT,founders TEXT,funding FLOAT,lgbtq_founder BOOLEAN); INSERT INTO Companies (id,name,industry,founders,funding,lgbtq_founder) VALUES (1,'RainbowTech','Technology','LGBTQ+ Founder',3000000.00,TRUE); INSERT INTO Companies (id,name,industry,founders,funding,lgbtq_founde...
SELECT MAX(funding) FROM Companies WHERE lgbtq_founder = TRUE;
What is the total number of cybersecurity incidents detected in the Middle East and North Africa (MENA) region in 2021?
CREATE TABLE security_incidents (id INT,region VARCHAR(50),incident_date DATE,incident_number INT); INSERT INTO security_incidents (id,region,incident_date,incident_number) VALUES (1,'MENA','2021-02-03',100),(2,'MENA','2021-12-20',200);
SELECT SUM(incident_number) FROM security_incidents WHERE region = 'MENA' AND incident_date BETWEEN '2021-01-01' AND '2021-12-31';
What is the success rate of biotech startups founded in the last 5 years, based on their total funding and number of employees?
CREATE TABLE biotech_startups (id INT PRIMARY KEY,name VARCHAR(255),total_funding DECIMAL(10,2),employees INT,founding_year INT,country VARCHAR(255));
SELECT ROUND((SUM(CASE WHEN total_funding > 1000000 AND employees > 50 THEN 1 ELSE 0 END)/COUNT(*))*100,2) AS success_rate FROM biotech_startups WHERE founding_year BETWEEN 2017 AND 2022;
Remove all climate adaptation policies from the 'climate_adaptation' table that have no associated funding in the 'climate_finance' table.
CREATE TABLE climate_adaptation (policy_name TEXT,funding INTEGER); INSERT INTO climate_adaptation (policy_name,funding) VALUES ('Policy X',100000),('Policy Y',NULL); CREATE TABLE climate_finance (funding_year INTEGER,policy_name TEXT); INSERT INTO climate_finance (funding_year,policy_name) VALUES (2020,'Policy X');
DELETE FROM climate_adaptation WHERE policy_name NOT IN (SELECT policy_name FROM climate_finance);
What is the average energy efficiency rating for residential buildings in the city of Toronto, with a COUNT of the buildings?
CREATE TABLE residential_buildings (id INT,building_id VARCHAR(255),city VARCHAR(255),energy_efficiency_rating INT);
SELECT AVG(energy_efficiency_rating) AS avg_rating, COUNT(building_id) AS total_buildings FROM residential_buildings WHERE city = 'Toronto';
Find the total sales of cruelty-free products by region.
CREATE TABLE regions (region_id INT,region_name TEXT); CREATE TABLE sales_regions AS SELECT sales.sale_id,sales.product_id,regions.region_id,regions.region_name FROM sales JOIN regions ON sales.sale_country = regions.region_name; INSERT INTO regions VALUES (1,'North America'),(2,'Europe'),(3,'Asia'),(4,'South Americ...
SELECT regions.region_name, SUM(sales_regions.sale_id) as total_sales FROM sales_regions JOIN regions ON sales_regions.region_id = regions.region_id WHERE sales_regions.product_id IN (SELECT products.product_id FROM products WHERE products.is_cruelty_free = true) GROUP BY regions.region_name
What is the distribution of spacecraft component quantities by country?
CREATE TABLE SpacecraftComponents (id INT,country TEXT,quantity INT);
SELECT country, AVG(quantity) as avg_quantity, STDDEV(quantity) as stddev_quantity FROM SpacecraftComponents GROUP BY country;
Show the number of mobile and broadband subscribers in each country
CREATE TABLE country (subscriber_id INT,subscriber_type VARCHAR(10),country VARCHAR(10));
SELECT subscriber_type, COUNT(*), country FROM country GROUP BY subscriber_type, country;
Identify the number of research expeditions and the number of unique researchers involved in each expedition in the Arctic region for each year.
CREATE TABLE expeditions (expedition_id INT,expedition_date DATE,researcher VARCHAR(50),expedition_location VARCHAR(50));
SELECT YEAR(expedition_date) AS year, COUNT(*) AS total_expeditions, COUNT(DISTINCT researcher) AS unique_researchers FROM expeditions WHERE expedition_location LIKE '%Arctic%' GROUP BY year;
What is the total cost of procedures in the 'rural_clinic_6' table?
CREATE TABLE rural_clinic_6 (procedure_id INT,cost DECIMAL(5,2)); INSERT INTO rural_clinic_6 (procedure_id,cost) VALUES (1,100.50),(2,150.25),(3,75.00),(4,200.00),(5,50.00),(6,300.00),(7,125.00);
SELECT SUM(cost) FROM rural_clinic_6;
How many games were played at home for each team in the 'games' table?
CREATE TABLE games (home_team TEXT,away_team TEXT,played BOOLEAN);
SELECT home_team, COUNT(*) as games_at_home FROM games WHERE played = TRUE AND home_team = away_team GROUP BY home_team;