instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the total weight of all space debris?
CREATE TABLE Space_Debris (object_name TEXT,weight FLOAT); INSERT INTO Space_Debris (object_name,weight) VALUES ('FENGYUN 1C',1000),('COSMOS 1402',6000),('Meteor 1-21',2000),('COSMOS 954',1500),('TIROS-M',130);
SELECT SUM(weight) as total_debris_weight FROM Space_Debris;
How many female and male faculty members were hired in the last 5 years?
CREATE TABLE faculty (id INT,faculty_name TEXT,faculty_gender TEXT,hire_date DATE); INSERT INTO faculty (id,faculty_name,faculty_gender,hire_date) VALUES (1,'Eliot','M','2018-02-15'); INSERT INTO faculty (id,faculty_name,faculty_gender,hire_date) VALUES (2,'Fiona','F','2021-03-20');
SELECT faculty_gender, COUNT(*) FROM faculty WHERE hire_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR) AND CURRENT_DATE GROUP BY faculty_gender
Delete all records from crop_health table where field_id is not in (3, 5, 7)
CREATE TABLE crop_health (field_id INT,health_score INT,measurement_timestamp DATETIME);
DELETE FROM crop_health WHERE field_id NOT IN (3, 5, 7);
What is the release date of the shortest Rap song?
CREATE TABLE songs (song_id INT,release_date DATE,song_length FLOAT,genre TEXT); INSERT INTO songs VALUES (1,'2005-07-12',125.3,'Rap'),(2,'2010-02-14',200.2,'R&B'),(3,'2008-05-23',100.5,'Rap'),(4,'2012-12-31',180.1,'Hip Hop'),(5,'2011-06-20',150.0,'Rap');
SELECT release_date FROM songs WHERE genre = 'Rap' AND song_length = (SELECT MIN(song_length) FROM songs WHERE genre = 'Rap');
What is the average number of riders per day for each bus route in Rome?
CREATE TABLE rome_bus (route_id INT,num_riders INT,ride_date DATE);
SELECT route_id, AVG(num_riders) FROM rome_bus GROUP BY route_id;
What is the total quantity of garments produced using sustainable materials in the last 6 months?
CREATE TABLE Sustainable_Material_Garments (id INT,production_date DATE,quantity INT);
SELECT SUM(quantity) FROM Sustainable_Material_Garments WHERE production_date >= DATEADD(month, -6, GETDATE());
Find the company with the most electric vehicles in the ElectricVehicles table.
CREATE TABLE ElectricVehicles (id INT,company VARCHAR(20),vehicle_type VARCHAR(20),num_vehicles INT); INSERT INTO ElectricVehicles (id,company,vehicle_type,num_vehicles) VALUES (1,'Tesla','EV',1500000),(2,'Nissan','Leaf',500000),(3,'Chevrolet','Bolt',300000),(6,'Rivian','EV',2000),(7,'Lucid','EV',5000);
SELECT company FROM ElectricVehicles WHERE num_vehicles = (SELECT MAX(num_vehicles) FROM ElectricVehicles);
What was the total amount donated by each organization type in 2022?
CREATE TABLE Donations (DonationID INT,DonorID INT,DonationAmount FLOAT,DonationDate DATE,OrganizationType TEXT); INSERT INTO Donations (DonationID,DonorID,DonationAmount,DonationDate,OrganizationType) VALUES (1,1,500.00,'2022-01-01','Non-profit'),(2,2,350.00,'2022-02-14','Corporation'),(3,3,1000.00,'2022-12-31','Individual');
SELECT OrganizationType, SUM(DonationAmount) as TotalDonation FROM Donations WHERE YEAR(DonationDate) = 2022 GROUP BY OrganizationType;
List all the organizations in 'org_info' table located in 'New York'?
CREATE TABLE org_info (org_name VARCHAR(50),location VARCHAR(50)); INSERT INTO org_info (org_name,location) VALUES ('XYZ Foundation','New York');
SELECT org_name FROM org_info WHERE location = 'New York';
What is the total number of cybersecurity incidents reported in Q1 of 2021?
CREATE TABLE cybersecurity_incidents (id INT,incident_date DATE,incident_type VARCHAR(255)); INSERT INTO cybersecurity_incidents (id,incident_date,incident_type) VALUES (1,'2021-01-05','Data Breach'),(2,'2021-03-18','Phishing');
SELECT COUNT(*) FROM cybersecurity_incidents WHERE incident_date BETWEEN '2021-01-01' AND '2021-03-31';
Get the total revenue of menu items in the 'side_dishes' category
CREATE TABLE menu_items (item_id INT,item_name TEXT,category TEXT,price DECIMAL(5,2)); INSERT INTO menu_items (item_id,item_name,category,price) VALUES (1,'Burger','entrees',9.99),(2,'Fries','side_dishes',2.50),(3,'Salad','appetizers',4.50),(4,'Fries','side_dishes',3.50);
SELECT SUM(price) FROM menu_items WHERE category = 'side_dishes';
What is the total amount of research grants awarded by country?
CREATE TABLE research_grants (id INT,student_id INT,year INT,amount DECIMAL(10,2),country VARCHAR(50)); INSERT INTO research_grants VALUES (1,1,2021,10000,'USA'); INSERT INTO research_grants VALUES (2,2,2020,12000,'Canada'); INSERT INTO research_grants VALUES (3,3,2021,15000,'Mexico');
SELECT r.country, SUM(r.amount) FROM research_grants r GROUP BY r.country;
Which animal species have never been admitted to the rehabilitation center?
CREATE TABLE animal_species (species_id INT,species_name VARCHAR(255)); INSERT INTO animal_species (species_id,species_name) VALUES (1,'Tiger'),(2,'Lion'),(3,'Elephant');
SELECT species_name FROM animal_species WHERE species_id NOT IN (SELECT animal_id FROM rehabilitation_center);
What is the total revenue generated by mobile games in 2022?
CREATE TABLE game_sales (id INT,year INT,platform VARCHAR(20),revenue INT); INSERT INTO game_sales (id,year,platform,revenue) VALUES (1,2022,'mobile',5000000),(2,2021,'pc',4000000),(3,2022,'console',3000000),(4,2021,'mobile',6000000),(5,2022,'pc',7000000),(6,2021,'console',2000000);
SELECT SUM(revenue) FROM game_sales WHERE year = 2022 AND platform = 'mobile';
How many bioprocess engineering jobs are available in Germany?
CREATE SCHEMA if not exists engineering; CREATE TABLE if not exists engineering.jobs(job_id INT PRIMARY KEY,title VARCHAR(100),location VARCHAR(50),salary DECIMAL(10,2)); INSERT INTO engineering.jobs (job_id,title,location,salary) VALUES (1,'Bioprocess Engineer','Germany',80000); INSERT INTO engineering.jobs (job_id,title,location,salary) VALUES (2,'Mechanical Engineer','Germany',70000);
SELECT COUNT(*) FROM engineering.jobs WHERE title = 'Bioprocess Engineer' AND location = 'Germany';
Show the total carbon offsets in each sector, excluding sectors with no carbon offsets
CREATE TABLE carbon_offsets (id INT PRIMARY KEY,sector VARCHAR(255),amount_offset INT); INSERT INTO carbon_offsets (id,sector,amount_offset) VALUES (1,'Transportation',350000); INSERT INTO carbon_offsets (id,sector,amount_offset) VALUES (2,'Energy',200000);
SELECT sector, SUM(amount_offset) FROM carbon_offsets WHERE amount_offset IS NOT NULL GROUP BY sector;
Find the number of unique visitors who attended events in 'New York' and 'London'.
CREATE TABLE Events (id INT,name TEXT,location TEXT); CREATE TABLE Visitors_Events (visitor_id INT,event_id INT); INSERT INTO Events (id,name,location) VALUES (1,'Dance Performance','New York'),(2,'Film Festival','London'); INSERT INTO Visitors_Events (visitor_id,event_id) VALUES (1,1),(1,2),(3,1);
SELECT COUNT(DISTINCT Visitors_Events.visitor_id) FROM Visitors_Events INNER JOIN Events ON Visitors_Events.event_id = Events.id WHERE Events.location IN ('New York', 'London');
Which countries had the highest and lowest museum attendance in the last 3 years?
CREATE TABLE Museums (MuseumID INT,MuseumName VARCHAR(50),Country VARCHAR(50)); CREATE TABLE Attendance (AttendanceID INT,MuseumID INT,Year INT,Visitors INT); INSERT INTO Museums VALUES (1,'Louvre','France'),(2,'Met','USA'),(3,'British Museum','UK'); INSERT INTO Attendance VALUES (1,1,2019,1000000),(2,1,2020,800000),(3,1,2021,900000),(4,2,2019,7000000),(5,2,2020,4000000),(6,2,2021,5000000),(7,3,2019,6000000),(8,3,2020,5000000),(9,3,2021,6500000);
SELECT M.Country, MAX(A.Visitors) AS MaxAttendance, MIN(A.Visitors) AS MinAttendance FROM Museums M INNER JOIN Attendance A ON M.MuseumID = A.MuseumID WHERE A.Year BETWEEN 2019 AND 2021 GROUP BY M.Country;
What is the total assets under management (AUM) for clients in the Asia-Pacific region?
CREATE TABLE clients (client_id INT,region VARCHAR(20)); INSERT INTO clients (client_id,region) VALUES (1,'North America'),(2,'Asia-Pacific'),(3,'Europe'); CREATE TABLE assets (asset_id INT,client_id INT,value DECIMAL(10,2)); INSERT INTO assets (asset_id,client_id,value) VALUES (1,1,500000.00),(2,1,750000.00),(3,2,250000.00),(4,3,1000000.00);
SELECT SUM(value) AS AUM FROM assets JOIN clients ON assets.client_id = clients.client_id WHERE clients.region = 'Asia-Pacific';
Unpivot the data to show the total number of programs by type
CREATE TABLE programs (id INT,name VARCHAR(50),location VARCHAR(50),type VARCHAR(50),start_date DATE,end_date DATE);
SELECT type, SUM(value) AS Total_Programs FROM (SELECT location, type, 1 AS value FROM programs WHERE start_date <= CURDATE() AND end_date >= CURDATE()) AS subquery GROUP BY type;
What is the trend of satellite deployment projects over the last decade?
CREATE TABLE satellite_projects (id INT,country VARCHAR(255),manufacturer VARCHAR(255),project_start_date DATE,project_end_date DATE);
SELECT YEAR(project_start_date) as year, COUNT(*) as num_projects FROM satellite_projects GROUP BY year ORDER BY year;
Insert new records for a new healthcare facility 'Facility D' in 'City Y' that offers mental health services.
CREATE TABLE HealthcareFacilities (Name VARCHAR(255),City VARCHAR(255),Specialized BOOLEAN); INSERT INTO HealthcareFacilities (Name,City,Specialized) VALUES ('Facility A','City X',TRUE),('Facility B','City X',FALSE),('Facility C','City Y',TRUE);
INSERT INTO HealthcareFacilities (Name, City, Specialized) VALUES ('Facility D', 'City Y', TRUE);
List union names, their membership statistics, and collective bargaining agreements that will expire before 2023?
CREATE TABLE union_names (union_name TEXT); INSERT INTO union_names (union_name) VALUES ('Union A'),('Union B'),('Union C'),('Union D'); CREATE TABLE membership_stats (union_name TEXT,members INTEGER); INSERT INTO membership_stats (union_name,members) VALUES ('Union A',4000),('Union B',2000),('Union C',6000),('Union D',500); CREATE TABLE cb_agreements (union_name TEXT,expiration_year INTEGER); INSERT INTO cb_agreements (union_name,expiration_year) VALUES ('Union A',2023),('Union B',2025),('Union C',2024),('Union D',2025),('Union H',2022);
SELECT union_names.union_name, membership_stats.members, cb_agreements.expiration_year FROM union_names FULL OUTER JOIN membership_stats ON union_names.union_name = membership_stats.union_name FULL OUTER JOIN cb_agreements ON union_names.union_name = cb_agreements.union_name WHERE cb_agreements.expiration_year < 2023;
What is the maximum salary for workers in the 'construction_database' database who are members of a union?
CREATE TABLE builders (id INT,name VARCHAR(50),salary DECIMAL(10,2),is_union_member BOOLEAN); INSERT INTO builders (id,name,salary,is_union_member) VALUES (1,'Mia',80000.00,true),(2,'Max',85000.00,true),(3,'Mel',90000.00,true);
SELECT MAX(salary) FROM builders WHERE is_union_member = true;
Find the average weight of fish, grouped by farm name and species.
CREATE TABLE Farm (id INT,farm_name TEXT,species TEXT,weight FLOAT,age INT); INSERT INTO Farm (id,farm_name,species,weight,age) VALUES (1,'OceanPacific','Tilapia',500.3,2),(2,'SeaBreeze','Salmon',300.1,1),(3,'OceanPacific','Tilapia',600.5,3),(4,'FarmX','Salmon',700.2,4),(5,'OceanPacific','Salmon',800.1,5);
SELECT farm_name, species, AVG(weight) as avg_weight FROM Farm GROUP BY farm_name, species;
What is the average distance run by the top 10 fastest sprinters in the 100m dash event?
CREATE TABLE athletes (id INT,name VARCHAR(50),sport VARCHAR(50),event VARCHAR(50),personal_best FLOAT); INSERT INTO athletes (id,name,sport,event,personal_best) VALUES (1,'John Doe','Athletics','100m',9.87),(2,'Jane Smith','Athletics','100m',10.12);
SELECT AVG(personal_best) FROM (SELECT personal_best FROM athletes WHERE sport = 'Athletics' AND event = '100m' ORDER BY personal_best DESC FETCH NEXT 10 ROWS ONLY) AS subquery;
Which are the top 3 countries with the most fair trade chocolate farms?
CREATE TABLE chocolate_farms (id INT,farm_name TEXT,country TEXT,fair_trade BOOLEAN); INSERT INTO chocolate_farms (id,farm_name,country,fair_trade) VALUES (1,'Cocoa Paradise','Ecuador',true),(2,'Choco Haven','Ghana',true),(3,'Sweet Earth','Peru',false);
SELECT country, COUNT(*) FROM chocolate_farms WHERE fair_trade = true GROUP BY country ORDER BY COUNT(*) DESC LIMIT 3;
What is the minimum temperature ever recorded in the Arctic Ocean?
CREATE TABLE ocean_temperatures (id INT,ocean TEXT,min_temp FLOAT); INSERT INTO ocean_temperatures (id,ocean,min_temp) VALUES (1,'Arctic Ocean',-50.0),(2,'Atlantic Ocean',0.0);
SELECT MIN(min_temp) FROM ocean_temperatures WHERE ocean = 'Arctic Ocean';
What is the total quantity of sustainable textiles sourced from Africa?
CREATE TABLE sourcing (sourcing_id INT,textile_type VARCHAR(30),quantity INT,region VARCHAR(20)); INSERT INTO sourcing (sourcing_id,textile_type,quantity,region) VALUES (1,'Organic Cotton',5000,'Africa'),(2,'Tencel',3000,'Europe'),(3,'Bamboo',4000,'Asia');
SELECT SUM(quantity) FROM sourcing WHERE textile_type = 'Organic Cotton' AND region = 'Africa';
delete all records from the carbon_sequestration table where the tree_type is 'Spruce'
CREATE TABLE carbon_sequestration (year INT,tree_type VARCHAR(255),region VARCHAR(255),sequestration_rate FLOAT);
DELETE FROM carbon_sequestration WHERE tree_type = 'Spruce';
What is the most common treatment approach for patients with depression in Florida?
CREATE TABLE patients (patient_id INT,age INT,gender TEXT,treatment TEXT,state TEXT,condition TEXT); INSERT INTO patients (patient_id,age,gender,treatment,state,condition) VALUES (1,30,'Female','CBT','Texas','Anxiety'); INSERT INTO patients (patient_id,age,gender,treatment,state,condition) VALUES (2,45,'Male','DBT','California','Depression'); INSERT INTO patients (patient_id,age,gender,treatment,state,condition) VALUES (3,25,'Non-binary','Therapy','Washington','Depression');
SELECT treatment, COUNT(*) AS count FROM patients WHERE condition = 'Depression' AND state = 'Florida' GROUP BY treatment ORDER BY count DESC LIMIT 1;
What is the total quantity of sustainable fabric sourced from Indian suppliers?
CREATE TABLE SustainableFabric (Brand VARCHAR(255),Supplier VARCHAR(255),Quantity INT); INSERT INTO SustainableFabric (Brand,Supplier,Quantity) VALUES ('BrandG','SupplierD',2000),('BrandH','SupplierE',2500),('BrandI','SupplierF',3000),('BrandJ','SupplierD',1500);
SELECT SUM(Quantity) FROM SustainableFabric WHERE Supplier IN ('SupplierD', 'SupplierE', 'SupplierF');
Find the top 5 countries with the highest average sustainability score for their manufacturers, along with the total number of manufacturers.
CREATE TABLE manufacturers (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),sustainability_score INT);
SELECT m.country, AVG(m.sustainability_score) as avg_score, COUNT(*) as total_manufacturers, RANK() OVER (ORDER BY avg_score DESC) as rank FROM manufacturers m GROUP BY m.country HAVING rank <= 5;
Find the total waste produced by each manufacturing plant in the first quarter of 2022, ordered from greatest to least.
CREATE TABLE Waste (Plant VARCHAR(255),Waste_Amount INT,Waste_Date DATE); INSERT INTO Waste (Plant,Waste_Amount,Waste_Date) VALUES ('PlantA',500,'2022-01-01'),('PlantB',300,'2022-01-02'),('PlantC',700,'2022-01-03');
SELECT Plant, SUM(Waste_Amount) AS Total_Waste FROM Waste WHERE Waste_Date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY Plant ORDER BY Total_Waste DESC;
What is the lowest-rated eco-friendly hotel in the United Kingdom?
CREATE TABLE Hotels (id INT,name TEXT,country TEXT,rating FLOAT,eco_friendly BOOLEAN); INSERT INTO Hotels (id,name,country,rating,eco_friendly) VALUES (1,'Eco Hotel','United Kingdom',3.8,true),(2,'Green Lodge','United Kingdom',4.2,true),(3,'Classic Hotel','United Kingdom',4.6,false);
SELECT name, rating FROM Hotels WHERE country = 'United Kingdom' AND eco_friendly = true ORDER BY rating ASC LIMIT 1;
Delete all marine species in the 'marine_species' table that belong to the 'Cnidaria' phylum.
CREATE TABLE marine_species (id INT,name VARCHAR(255),phylum VARCHAR(255)); INSERT INTO marine_species (id,name,phylum) VALUES (1,'Pacific salmon','Chordata'),(2,'Hawaiian monk seal','Chordata'),(3,'Sea anemone','Cnidaria');
DELETE FROM marine_species WHERE phylum = 'Cnidaria';
What is the average age of policyholders with life insurance in the state of New York?
CREATE TABLE Policyholder_Info (ID INT,Age INT,State VARCHAR(20),Insurance_Type VARCHAR(20)); INSERT INTO Policyholder_Info (ID,Age,State,Insurance_Type) VALUES (1,45,'New York','Life'),(2,35,'California','Health'),(3,60,'New York','Life'),(4,25,'Texas','Auto'),(5,50,'New York','Life'),(6,40,'California','Life');
SELECT AVG(Age) FROM Policyholder_Info WHERE State = 'New York' AND Insurance_Type = 'Life';
What is the average speed of electric buses in the city of Austin?
CREATE TABLE if not exists Buses (id INT,type VARCHAR(20),city VARCHAR(20),speed FLOAT); INSERT INTO Buses (id,type,city,speed) VALUES (1,'Electric','Austin',35.6),(2,'Diesel','Austin',32.8),(3,'Electric','Austin',37.2);
SELECT AVG(speed) FROM Buses WHERE type = 'Electric' AND city = 'Austin';
What is the average wind speed for Sydney in the month of February 2022?
CREATE TABLE weather (id INT,city VARCHAR(50),temperature FLOAT,wind_speed FLOAT,timestamp TIMESTAMP); INSERT INTO weather (id,city,temperature,wind_speed,timestamp) VALUES (1,'Sydney',70.2,12.5,'2022-02-01 10:00:00'); INSERT INTO weather (id,city,temperature,wind_speed,timestamp) VALUES (2,'Sydney',72.1,14.3,'2022-02-02 10:00:00');
SELECT AVG(wind_speed) as avg_wind_speed FROM weather WHERE city = 'Sydney' AND timestamp BETWEEN '2022-02-01 00:00:00' AND '2022-02-28 23:59:59';
What is the average years of experience for male geologists in the 'geologists' table?
CREATE TABLE geologists (id INT,name VARCHAR(50),age INT,gender VARCHAR(10),years_of_experience INT);
SELECT AVG(years_of_experience) FROM geologists WHERE gender = 'male';
Determine the total value of all transactions for a specific customer in the last year.
CREATE TABLE customer_transactions (transaction_id INT,customer_id INT,transaction_date DATE,transaction_value DECIMAL(10,2)); INSERT INTO customer_transactions (transaction_id,customer_id,transaction_date,transaction_value) VALUES (1,1,'2022-01-01',100.00),(2,1,'2022-02-01',200.00),(3,2,'2022-03-01',150.00),(4,1,'2022-04-01',300.00);
SELECT SUM(transaction_value) FROM customer_transactions WHERE customer_id = 1 AND transaction_date >= DATE_SUB(NOW(), INTERVAL 1 YEAR);
What is the maximum capacity of a single energy storage system in South Korea?
CREATE TABLE EnergyStorageSystems (id INT,country VARCHAR(20),system_capacity INT); INSERT INTO EnergyStorageSystems (id,country,system_capacity) VALUES (1,'South Korea',5000),(2,'South Korea',7000),(3,'Japan',6000);
SELECT MAX(system_capacity) FROM EnergyStorageSystems WHERE country = 'South Korea';
What is the average credit score for customers in each state?
CREATE TABLE customers (id INT,state VARCHAR(50),credit_score INT); INSERT INTO customers (id,state,credit_score) VALUES (1,'California',700),(2,'New York',750),(3,'Texas',650);
SELECT state, AVG(credit_score) FROM customers GROUP BY state;
What is the average water consumption of hemp clothing production compared to cotton?
CREATE TABLE production (id INT,material VARCHAR(255),water_consumption INT); INSERT INTO production (id,material,water_consumption) VALUES (1,'Hemp',300),(2,'Cotton',2500);
SELECT AVG(CASE WHEN material = 'Hemp' THEN water_consumption ELSE NULL END) as avg_hemp, AVG(CASE WHEN material = 'Cotton' THEN water_consumption ELSE NULL END) as avg_cotton FROM production;
How many marine species are found in the Arctic region?
CREATE TABLE marine_species (name VARCHAR(255),region VARCHAR(255),population INT); INSERT INTO marine_species (name,region,population) VALUES ('Polar Bear','Arctic',25000),('Narwhal','Arctic',10000);
SELECT SUM(population) FROM marine_species WHERE region = 'Arctic';
Insert a new record for a customer 'Mohamed Ahmed' from 'Middle East' region with assets value $900,000.00.
CREATE TABLE customers (id INT,name VARCHAR(100),region VARCHAR(50),assets_value FLOAT);
INSERT INTO customers (name, region, assets_value) VALUES ('Mohamed Ahmed', 'Middle East', 900000.00);
Find the number of digital assets created by developers in each country in April 2022.
CREATE TABLE developers (developer_id INT,developer_name VARCHAR(100),developer_country VARCHAR(50),date_of_birth DATE); INSERT INTO developers VALUES (1,'Alice','USA','1990-05-01'); INSERT INTO developers VALUES (2,'Bob','Canada','1985-08-12');
SELECT developer_country, COUNT(*) as num_assets FROM developers WHERE date_of_birth BETWEEN '1980-01-01' AND '2000-12-31' AND developer_country IN ('USA', 'Canada', 'Mexico', 'Brazil', 'UK') GROUP BY developer_country;
List all rovers that have landed on Mars and their launching countries.
CREATE TABLE MarsRovers (RoverName TEXT,LaunchCountry TEXT);CREATE VIEW MarsLandings (RoverName) AS SELECT RoverName FROM MarsRovers WHERE MarsRovers.RoverName IN ('Spirit','Opportunity','Curiosity','Perseverance');
SELECT MarsRovers.RoverName, MarsRovers.LaunchCountry FROM MarsRovers INNER JOIN MarsLandings ON MarsRovers.RoverName = MarsLandings.RoverName;
Determine the total waste generation by city for the year 2021 in the province of British Columbia, Canada, separated by waste type.
CREATE TABLE canada_waste_generation (city VARCHAR(20),province VARCHAR(20),year INT,waste_type VARCHAR(20),quantity FLOAT); INSERT INTO canada_waste_generation (city,province,year,waste_type,quantity) VALUES ('Vancouver','British Columbia',2021,'Organic',100000); INSERT INTO canada_waste_generation (city,province,year,waste_type,quantity) VALUES ('Vancouver','British Columbia',2021,'Recyclable',150000);
SELECT city, waste_type, SUM(quantity) as total_quantity FROM canada_waste_generation WHERE province = 'British Columbia' AND year = 2021 GROUP BY city, waste_type;
What is the total revenue for restaurants that serve sustainable menu items?
CREATE TABLE restaurant_revenue(location VARCHAR(255),revenue INT); INSERT INTO restaurant_revenue(location,revenue) VALUES ('Location1',5000),('Location2',7000),('Location3',3000),('Restaurant4',6000),('Restaurant5',4000),('Restaurant9',9000),('Restaurant10',8000);
SELECT SUM(revenue) FROM restaurant_revenue INNER JOIN sustainable_sourcing ON restaurant_revenue.location = sustainable_sourcing.menu_item WHERE sustainable = TRUE;
Increase the duration of all workouts in August by 15% for members aged 30 or older.
CREATE TABLE Members (Id INT,Age INT,Gender VARCHAR(10)); CREATE TABLE Workouts (Id INT,MemberId INT,Duration INT,Date DATE); INSERT INTO Members (Id,Age,Gender) VALUES (1,25,'Female'),(2,32,'Male'),(3,45,'Female'),(4,28,'Non-binary'); INSERT INTO Workouts (Id,MemberId,Duration,Date) VALUES (1,1,60,'2022-08-01'),(2,1,45,'2022-08-02'),(3,2,90,'2022-08-01'),(4,2,75,'2022-08-03'),(5,3,120,'2022-08-01');
UPDATE Workouts SET Duration = Duration * 1.15 WHERE DATE_FORMAT(Date, '%Y-%m') = '2022-08' AND MemberId IN (SELECT Id FROM Members WHERE Age >= 30);
What is the average distance for routes starting from a warehouse in CA?
CREATE TABLE Routes (RouteID INT,OriginWarehouse INT,DestinationWarehouse INT,Distance FLOAT); INSERT INTO Routes (RouteID,OriginWarehouse,DestinationWarehouse,Distance) VALUES (1,10,20,150.3),(2,11,21,180.5),(3,12,22,120.7); CREATE TABLE Warehouses (WarehouseID INT,State VARCHAR(2)); INSERT INTO Warehouses (WarehouseID,State) VALUES (10,'CA'),(11,'CA'),(12,'CA'),(20,'NY'),(21,'NY'),(22,'NY');
SELECT AVG(Distance) FROM Routes r JOIN Warehouses w ON r.OriginWarehouse = w.WarehouseID WHERE w.State = 'CA';
List all the Shariah-compliant financial products offered in the Asia region.
CREATE TABLE shariah_compliant_finance (product_id INT,product_name VARCHAR(50),region VARCHAR(50)); INSERT INTO shariah_compliant_finance (product_id,product_name,region) VALUES (1,'Murabaha','Asia'),(2,'Ijara','Europe'),(3,'Musharakah','Asia');
SELECT product_name FROM shariah_compliant_finance WHERE region = 'Asia';
Identify the number of employees hired in each quarter for the Engineering division.
CREATE TABLE Employee (Employee_ID INT,First_Name VARCHAR(50),Last_Name VARCHAR(50),Position VARCHAR(50),Department VARCHAR(50),Division VARCHAR(50),Hire_Date DATE); CREATE TABLE Department_Organization (Department_ID INT,Department VARCHAR(50),Division VARCHAR(50));
SELECT DATEPART(QUARTER, Hire_Date) AS Quarter, Department, Division, COUNT(*) AS Employees_Hired FROM Employee WHERE Division = 'Engineering' GROUP BY DATEPART(QUARTER, Hire_Date), Department, Division;
What is the total production volume for each region, and what is the percentage of the total production volume accounted for by the top 2 regions?
CREATE TABLE production_volume (volume_id INT,well_id INT,production_year INT,production_volume FLOAT,region VARCHAR(50)); INSERT INTO production_volume (volume_id,well_id,production_year,production_volume,region) VALUES (11,7,2022,300.0,'South America'); INSERT INTO production_volume (volume_id,well_id,production_year,production_volume,region) VALUES (12,8,2023,280.5,'Europe');
SELECT region, SUM(production_volume) as total_volume, PERCENTAGE_RANK() OVER (ORDER BY SUM(production_volume) DESC) as percentage_of_total FROM production_volume GROUP BY region ORDER BY percentage_of_total DESC FETCH FIRST 2 ROWS ONLY;
What is the total resource depletion cost for each mine by year?
CREATE TABLE mine (id INT,name VARCHAR(50),location VARCHAR(50)); CREATE TABLE cost (mine_id INT,year INT,cost INT);
SELECT mine.name, cost.year, SUM(cost.cost) FROM cost JOIN mine ON cost.mine_id = mine.id GROUP BY mine.name, cost.year;
Which garment has the highest CO2 emission and how much is it?
CREATE TABLE garment (garment_id INT,type VARCHAR(50),co2_emission INT);
SELECT type AS highest_emission_garment, MAX(co2_emission) AS co2_emission FROM garment;
Which strains have been sold in more than 5 dispensaries in Oregon?
CREATE TABLE sales (sale_id INT,dispensary_id INT,strain VARCHAR(255),quantity INT);CREATE TABLE dispensaries (dispensary_id INT,name VARCHAR(255),state VARCHAR(255));
SELECT strain FROM sales JOIN dispensaries ON sales.dispensary_id = dispensaries.dispensary_id WHERE state = 'Oregon' GROUP BY strain HAVING COUNT(DISTINCT dispensary_id) > 5;
What is the maximum heart rate recorded during any workout for users in Australia in the last year?
CREATE TABLE Users (UserID INT,UserName VARCHAR(50),Country VARCHAR(50),HeartRate INT,WorkoutDate DATE);
SELECT MAX(HeartRate) FROM Users WHERE Country = 'Australia' AND WorkoutDate >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR);
What is the maximum monthly data usage for mobile customers in the city of San Francisco?
CREATE TABLE mobile_data (id INT,city VARCHAR(50),data_usage FLOAT); INSERT INTO mobile_data (id,city,data_usage) VALUES (1,'San Francisco',4.5),(2,'San Francisco',6.7),(3,'New York',3.4),(4,'San Francisco',8.9);
SELECT MAX(data_usage) FROM mobile_data WHERE city = 'San Francisco';
List all suppliers that have provided both organic and non-organic ingredients to restaurants, along with the total number of ingredients supplied by each.
CREATE TABLE suppliers (supplier_id INT,organic_supplier BOOLEAN); CREATE TABLE ingredients (ingredient_id INT,supplier_id INT,is_organic BOOLEAN); INSERT INTO suppliers VALUES (1,true); INSERT INTO suppliers VALUES (2,false); INSERT INTO ingredients VALUES (1,1,true); INSERT INTO ingredients VALUES (2,1,false); INSERT INTO ingredients VALUES (3,2,false);
SELECT s.supplier_id, COUNT(i.ingredient_id) as total_ingredients FROM suppliers s INNER JOIN ingredients i ON s.supplier_id = i.supplier_id WHERE s.organic_supplier = true OR i.is_organic = false GROUP BY s.supplier_id;
What is the minimum salary of workers in the 'electronics' department, grouped by country?
CREATE TABLE department (id INT,name TEXT); INSERT INTO department (id,name) VALUES (1,'textile'),(2,'metalworking'),(3,'electronics'); CREATE TABLE worker (id INT,salary REAL,department_id INT,country TEXT); INSERT INTO worker (id,salary,department_id,country) VALUES (1,3000,1,'France'),(2,3500,1,'France'),(3,4000,2,'Germany'),(4,4500,2,'Germany'),(5,5000,3,'USA'),(6,5200,3,'USA'),(7,5500,3,'USA');
SELECT country, MIN(worker.salary) FROM worker INNER JOIN department ON worker.department_id = department.id WHERE department.name = 'electronics' GROUP BY country;
Update the menu_item table to change the price of item_id 203 to 12.99
CREATE TABLE menu_item (item_id INT,item_name VARCHAR(50),category VARCHAR(20),price DECIMAL(5,2));
UPDATE menu_item SET price = 12.99 WHERE item_id = 203;
What is the average number of mental health parity violations for each community health worker in California?
CREATE TABLE mental_health_parity (id INT,community_health_worker_id INT,violation_count INT,state VARCHAR(50)); INSERT INTO mental_health_parity (id,community_health_worker_id,violation_count,state) VALUES (1,101,3,'California'),(2,101,2,'California'),(3,102,5,'California');
SELECT state, AVG(violation_count) OVER (PARTITION BY community_health_worker_id) as avg_violations FROM mental_health_parity WHERE state = 'California';
What is the average CO2 emission reduction achieved by renewable energy projects in Africa?
CREATE TABLE emission_reductions (project VARCHAR(255),region VARCHAR(255),reduction FLOAT);
SELECT AVG(reduction) FROM emission_reductions WHERE project = 'renewable energy' AND region = 'Africa';
What is the total number of participants in all language preservation programs?
CREATE TABLE LanguagePreservation (ProgramID int,ParticipantCount int); INSERT INTO LanguagePreservation (ProgramID,ParticipantCount) VALUES (101,45),(102,62),(103,38),(104,71),(105,54);
SELECT SUM(ParticipantCount) FROM LanguagePreservation;
What is the most expensive vegetarian menu item?
CREATE TABLE menu (id INT PRIMARY KEY,name VARCHAR(100),category VARCHAR(50),price DECIMAL(5,2)); INSERT INTO menu (id,name,category,price) VALUES (1,'Margherita Pizza','Pizza',9.99),(2,'Spaghetti Bolognese','Pasta',8.99),(3,'Caesar Salad','Salad',7.99),(4,'Vegetable Lasagna','Pasta',11.99);
SELECT name, price FROM menu WHERE category = 'Salad' OR category = 'Pasta' AND price = (SELECT MAX(price) FROM menu WHERE category = 'Salad' OR category = 'Pasta');
What is the average number of disinformation cases detected per month in South America since 2018?
CREATE TABLE disinformation (id INT,case_name VARCHAR(50),date DATE,location VARCHAR(50)); INSERT INTO disinformation (id,case_name,date,location) VALUES (1,'Case1','2018-01-01','South America'),(2,'Case2','2019-03-15','North America'),(3,'Case3','2020-12-31','Europe');
SELECT AVG(COUNT(*)) FROM disinformation WHERE location LIKE '%South America%' AND date BETWEEN '2018-01-01' AND '2022-12-31' GROUP BY MONTH(date);
Update the 'Ancient Coin' artifact description to 'An extremely rare coin from the EuropeExcavation site.'.
CREATE TABLE ExcavationSite (SiteID INT PRIMARY KEY,SiteName VARCHAR(100),Location VARCHAR(100),StartDate DATE,EndDate DATE);CREATE TABLE Artifact (ArtifactID INT PRIMARY KEY,SiteID INT,ArtifactName VARCHAR(100),Description TEXT,FOREIGN KEY (SiteID) REFERENCES ExcavationSite(SiteID));CREATE TABLE ArtifactType (ArtifactTypeID INT PRIMARY KEY,TypeName VARCHAR(100));CREATE TABLE ArtifactDetail (ArtifactID INT,ArtifactTypeID INT,Quantity INT,PRIMARY KEY (ArtifactID,ArtifactTypeID),FOREIGN KEY (ArtifactID) REFERENCES Artifact(ArtifactID),FOREIGN KEY (ArtifactTypeID) REFERENCES ArtifactType(ArtifactTypeID));
UPDATE Artifact SET Description = 'An extremely rare coin from the EuropeExcavation site.' WHERE ArtifactName = 'Ancient Coin';
Which events had the highest attendance from the 'Latinx' demographic in the 'Theatre' category?
CREATE SCHEMA if not exists arts_culture; CREATE TABLE if not exists arts_culture.events(event_id INT,event_name VARCHAR(50),event_date DATE,category VARCHAR(20)); CREATE TABLE if not exists arts_culture.attendance(attendance_id INT,event_id INT,demographic VARCHAR(10),attendee_count INT);
SELECT events.event_name, MAX(attendance.attendee_count) FROM arts_culture.events JOIN arts_culture.attendance ON events.event_id = attendance.event_id WHERE attendance.demographic = 'Latinx' AND events.category = 'Theatre' GROUP BY events.event_name;
Which city has the highest number of electric taxi rides in a month?
CREATE TABLE electric_taxis (taxi_id INT,ride_id INT,start_time TIMESTAMP,end_time TIMESTAMP,city VARCHAR(255));
SELECT city, COUNT(*) as num_rides FROM electric_taxis WHERE ride_id BETWEEN 1 AND 100000 GROUP BY city ORDER BY num_rides DESC LIMIT 1;
What is the total number of travel advisories issued for 'asia_pacific' region?
CREATE TABLE travel_advisories (region VARCHAR(50),advisory_count INT); INSERT INTO travel_advisories (region,advisory_count) VALUES ('Asia Pacific',120),('Europe',80),('Americas',150);
SELECT SUM(advisory_count) FROM travel_advisories WHERE region = 'Asia Pacific';
What is the average ESG rating for companies in the technology sector?
CREATE TABLE companies (id INT,name TEXT,sector TEXT,ESG_rating FLOAT); INSERT INTO companies (id,name,sector,ESG_rating) VALUES (1,'Apple','Technology',8.2),(2,'Microsoft','Technology',8.5),(3,'Tesla','Automative',7.8);
SELECT AVG(ESG_rating) FROM companies WHERE sector = 'Technology';
How many accessible technology events were held in Africa in the past year?
CREATE TABLE accessible_tech_events (event_location VARCHAR(255),event_date DATE); INSERT INTO accessible_tech_events (event_location,event_date) VALUES ('Kenya','2021-10-01'),('Egypt','2022-02-01'),('Nigeria','2021-06-01');
SELECT COUNT(*) OVER (PARTITION BY CASE WHEN event_date >= '2021-01-01' AND event_date < '2022-01-01' THEN 1 ELSE 0 END) as african_events FROM accessible_tech_events WHERE event_location LIKE 'Africa%';
What is the maximum budget spent on military innovation by each department?
CREATE TABLE DepartmentMilitaryInnovation (id INT,department VARCHAR(50),budget INT);
SELECT department, MAX(budget) FROM DepartmentMilitaryInnovation GROUP BY department;
What is the obesity rate in Oceania by country?
CREATE TABLE oceania (country VARCHAR(50),obesity_rate DECIMAL(3,1)); INSERT INTO oceania (country,obesity_rate) VALUES ('Australia',27.9),('New Zealand',30.8);
SELECT country, AVG(obesity_rate) as avg_obesity_rate FROM oceania GROUP BY country;
What is the average attendance for events in Texas in the 'Events' table?
CREATE TABLE Events (id INT,name VARCHAR(50),location VARCHAR(50),date DATE,attendance INT); INSERT INTO Events (id,name,location,date,attendance) VALUES (1,'Art Show','Texas','2020-01-01',50);
SELECT AVG(attendance) FROM Events WHERE location = 'Texas';
Calculate the total carbon offset for each smart city in the 'smart_cities' table
CREATE TABLE smart_cities (id INT,name VARCHAR(50),location VARCHAR(50),carbon_offset INT);
SELECT name, (SELECT SUM(carbon_offset) FROM smart_cities WHERE smart_cities.name = cities.name) AS total_carbon_offset FROM smart_cities AS cities;
Delete all records of clients who have a financial wellbeing score below 5, regardless of their country.
CREATE TABLE financial_wellbeing (client_id INT,financial_wellbeing_score INT); INSERT INTO financial_wellbeing (client_id,financial_wellbeing_score) VALUES (1,7),(2,3),(3,6),(4,5);
DELETE FROM financial_wellbeing WHERE financial_wellbeing_score < 5;
Count the number of unique esports events where at least one player from Asia participated, and the number of unique FPS games played in these events.
CREATE TABLE EsportsEvents (EventID INT,EventName VARCHAR(50)); CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),Region VARCHAR(20)); CREATE TABLE PlayerEvent (PlayerID INT,EventID INT); CREATE TABLE Games (GameID INT,GameName VARCHAR(50),Genre VARCHAR(20)); CREATE TABLE GameEvent (GameID INT,EventID INT,GameType VARCHAR(10)); CREATE TABLE VR_Games (GameID INT,IsVR INT);
SELECT COUNT(DISTINCT EsportsEvents.EventID), COUNT(DISTINCT Games.GameID) FROM EsportsEvents INNER JOIN PlayerEvent ON EsportsEvents.EventID = PlayerEvent.EventID INNER JOIN Players ON PlayerEvent.PlayerID = Players.PlayerID INNER JOIN Games ON GameEvent.GameID = Games.GameID INNER JOIN GameEvent ON EsportsEvents.EventID = GameEvent.EventID INNER JOIN VR_Games ON Games.GameID = VR_Games.GameID WHERE Players.Region = 'Asia' AND Games.Genre = 'FPS';
Delete peacekeeping operations that were terminated before 2010.
CREATE TABLE Peacekeeping_Operations (id INT,operation_name VARCHAR(255),region VARCHAR(255),start_date DATE,end_date DATE,status VARCHAR(255));
DELETE FROM Peacekeeping_Operations WHERE status = 'Terminated' AND start_date < '2010-01-01';
What is the number of intelligence personnel in each department in the US government?
CREATE TABLE intelligence_personnel (id INT,department TEXT,position TEXT,country TEXT); INSERT INTO intelligence_personnel (id,department,position,country) VALUES (1,'CIA','Analyst','USA'),(2,'FBI','Agent','USA'),(3,'NSA','Engineer','USA');
SELECT i.department, COUNT(i.id) as total_personnel FROM intelligence_personnel i WHERE i.country = 'USA' GROUP BY i.department;
How many crime incidents were reported in the last month, categorized by day of the week and hour?
CREATE TABLE incidents (iid INT,incident_time TIMESTAMP,incident_type VARCHAR(255));
SELECT DATE_FORMAT(i.incident_time, '%W') AS day_of_week, HOUR(i.incident_time) AS hour, COUNT(i.iid) FROM incidents i WHERE i.incident_time >= DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 MONTH) GROUP BY day_of_week, hour;
What is the average transaction value for sustainable investments in the United States?
CREATE TABLE sustainable_investments (id INT,value DECIMAL(10,2),location VARCHAR(50)); INSERT INTO sustainable_investments (id,value,location) VALUES (1,5000,'United States'),(2,3000,'Canada'),(3,7000,'United States');
SELECT AVG(value) FROM sustainable_investments WHERE location = 'United States';
What are the top 3 countries with the most user activity on social media platform sm_platform in the year 2022, and what is the total activity for each?
CREATE TABLE sm_platform (country VARCHAR(50),activity INT); INSERT INTO sm_platform (country,activity) VALUES ('USA',15000),('Canada',10000),('Mexico',12000),('Brazil',18000),('Argentina',14000);
SELECT s.country, SUM(s.activity) as total_activity FROM sm_platform s WHERE s.activity >= 10000 AND YEAR(s.activity_date) = 2022 GROUP BY s.country ORDER BY total_activity DESC LIMIT 3;
What is the total number of job applicants per source, by department, for the year 2021?
CREATE TABLE job_applications (id INT,applicant_name VARCHAR(50),department VARCHAR(50),application_source VARCHAR(50),application_date DATE); INSERT INTO job_applications (id,applicant_name,department,application_source,application_date) VALUES (1,'Jane Doe','IT','LinkedIn','2021-02-12'); INSERT INTO job_applications (id,applicant_name,department,application_source,application_date) VALUES (2,'Bob Smith','HR','Indeed','2021-05-04');
SELECT department, application_source, COUNT(*) as total_applicants FROM job_applications WHERE YEAR(application_date) = 2021 GROUP BY department, application_source;
What is the average virtual tour engagement duration in New York City?
CREATE TABLE virtual_tours (tour_id INT,tour_name VARCHAR(255),city VARCHAR(255),engagement_duration INT); INSERT INTO virtual_tours (tour_id,tour_name,city,engagement_duration) VALUES (1,'Tour A','New York',60),(2,'Tour B','New York',90),(3,'Tour C','Los Angeles',45);
SELECT AVG(engagement_duration) FROM virtual_tours WHERE city = 'New York';
What is the average number of patents for companies founded by LGBTQ+ individuals in the software industry?
CREATE TABLE companies (id INT,name TEXT,industry TEXT,founding_year INT,founder_identity TEXT); INSERT INTO companies (id,name,industry,founding_year,founder_identity) VALUES (1,'SoftwareSolutions','Software',2016,'LGBTQ+'); INSERT INTO companies (id,name,industry,founding_year,founder_identity) VALUES (2,'TechInnovations','Technology',2017,'Straight');
SELECT AVG(num_patents) FROM company_details INNER JOIN companies ON company_details.company_id = companies.id WHERE companies.founder_identity = 'LGBTQ+' AND companies.industry = 'Software';
What is the minimum number of players for eSports events in the 'Sports' category?
CREATE TABLE EventPlayerCounts (event VARCHAR(100),category VARCHAR(50),players INT);
SELECT MIN(players) FROM EventPlayerCounts WHERE category = 'Sports';
What are the total quantities of materials delivered by suppliers located in CityB in the last month?
CREATE TABLE Suppliers (id INT,name TEXT,location TEXT);CREATE TABLE Materials (id INT,supplier_id INT,factory_id INT,material TEXT,quantity INT,date DATE);INSERT INTO Suppliers VALUES (1,'SupplierA','CityA'),(2,'SupplierB','CityB'),(3,'SupplierC','CityC');INSERT INTO Materials VALUES (1,1,5,'MaterialX',100,'2021-06-01'),(2,1,5,'MaterialY',200,'2021-07-15'),(3,2,5,'MaterialX',150,'2021-08-01'),(4,3,6,'MaterialZ',50,'2021-09-10'),(5,2,5,'MaterialY',120,'2021-10-05'),(6,1,5,'MaterialZ',80,'2021-11-12');
SELECT SUM(m.quantity) FROM Suppliers s INNER JOIN Materials m ON s.id = m.supplier_id WHERE s.location = 'CityB' AND m.date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) AND CURRENT_DATE;
What is the total investment in social impact bonds in Southeast Asia in 2019?
CREATE TABLE if not exists investments (investment_id INT,region VARCHAR(50),sector VARCHAR(50),amount DECIMAL(10,2),investment_year INT); INSERT INTO investments (investment_id,region,sector,amount,investment_year) VALUES (1,'Southeast Asia','Social Impact Bonds',700000,2019);
SELECT SUM(amount) FROM investments WHERE region = 'Southeast Asia' AND sector = 'Social Impact Bonds' AND investment_year = 2019;
Delete all records from the 'charging_stations' table where the 'city' is 'Seattle'
CREATE TABLE charging_stations (id INT,city VARCHAR(20),operator VARCHAR(20),num_chargers INT,open_date DATE);
DELETE FROM charging_stations WHERE city = 'Seattle';
Find the number of police officers hired per quarter, for the last 2 years, from 'CommunityPolicing' table.
CREATE TABLE CommunityPolicing (id INT,quarter INT,year INT,numOfficers INT);
SELECT year, quarter, SUM(numOfficers) FROM CommunityPolicing WHERE year BETWEEN (YEAR(CURRENT_DATE) - 2) AND YEAR(CURRENT_DATE) GROUP BY year, quarter;
Find the average temperature for each month in 2022 in the 'temperature' table.
CREATE TABLE temperature (year INT,month INT,avg_temp FLOAT); INSERT INTO temperature (year,month,avg_temp) VALUES (2022,1,-20.5),(2022,2,-25.0);
SELECT month, AVG(avg_temp) as avg_temp FROM temperature WHERE year = 2022 GROUP BY month;
What is the total revenue for Jazz concerts in the United States?
CREATE TABLE concerts (id INT,artist VARCHAR(50),genre VARCHAR(50),tickets_sold INT,revenue DECIMAL(10,2),country VARCHAR(50)); INSERT INTO concerts (id,artist,genre,tickets_sold,revenue,country) VALUES (1,'Louis Armstrong','Jazz',10000,1500000,'USA'); INSERT INTO concerts (id,artist,genre,tickets_sold,revenue,country) VALUES (2,'Miles Davis','Jazz',8000,1200000,'USA'); INSERT INTO concerts (id,artist,genre,tickets_sold,revenue,country) VALUES (3,'Duke Ellington','Jazz',9000,1350000,'USA');
SELECT SUM(revenue) FROM concerts WHERE genre = 'Jazz' AND country = 'USA';
Identify customers who made transactions in both Tokyo and Sydney.
CREATE TABLE customer_transactions (customer_id INT,transaction_city VARCHAR(20)); INSERT INTO customer_transactions (customer_id,transaction_city) VALUES (1,'Tokyo'),(2,'Sydney'),(3,'Tokyo'),(4,'Paris'),(5,'Sydney');
SELECT customer_id FROM customer_transactions WHERE transaction_city IN ('Tokyo', 'Sydney') GROUP BY customer_id HAVING COUNT(DISTINCT transaction_city) = 2;
Which menu items are offered by suppliers from the USA?
CREATE TABLE Suppliers (SupplierID INT,SupplierName VARCHAR(255),Country VARCHAR(255)); INSERT INTO Suppliers (SupplierID,SupplierName,Country) VALUES (6,'Supplier3','USA'); INSERT INTO Suppliers (SupplierID,SupplierName,Country) VALUES (7,'Supplier4','Mexico');
SELECT MenuItems.MenuItemName, Suppliers.SupplierName FROM MenuItems JOIN Suppliers ON MenuItems.SupplierID = Suppliers.SupplierID WHERE Suppliers.Country = 'USA'
What is the average age of astronauts from India?
CREATE TABLE Astronauts (id INT,name VARCHAR(255),country VARCHAR(255),age INT); INSERT INTO Astronauts (id,name,country,age) VALUES (1,'Rakesh Sharma','India',67); INSERT INTO Astronauts (id,name,country,age) VALUES (2,'Kalpana Chawla','India',N/A); INSERT INTO Astronauts (id,name,country,age) VALUES (3,'Sunita Williams','India',57);
SELECT AVG(age) FROM Astronauts WHERE country = 'India';
How many startups were founded in each country?
CREATE TABLE startups(id INT,name TEXT,country TEXT); INSERT INTO startups(id,name,country) VALUES (1,'StartupA','USA'),(2,'StartupB','Canada'),(3,'StartupC','USA'),(4,'StartupD','Mexico'),(5,'StartupE','Brazil');
SELECT country, COUNT(*) as num_startups FROM startups GROUP BY country;
Which regions have sales of products that contain allergens?
CREATE TABLE allergens (product_id INT,allergen_id INT,allergen_name TEXT); CREATE TABLE sales_regions_with_allergens AS SELECT sales_regions.*,allergens.allergen_id,allergens.allergen_name FROM sales_regions JOIN allergens ON sales_regions.product_id = allergens.product_id; INSERT INTO allergens VALUES (1,1,'AllergenA'),(1,2,'AllergenB'),(2,3,'AllergenC'),(3,1,'AllergenA'),(4,4,'AllergenD'),(5,2,'AllergenB'),(6,5,'AllergenE'),(7,1,'AllergenA');
SELECT regions.region_name FROM sales_regions_with_allergens JOIN regions ON sales_regions_with_allergens.region_id = regions.region_id GROUP BY regions.region_name HAVING COUNT(DISTINCT allergens.allergen_id) > 1