instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the second highest depth ever reached by any expedition?
CREATE TABLE expedition (org VARCHAR(20),depth INT); INSERT INTO expedition VALUES ('Ocean Explorer',2500),('Ocean Explorer',3000),('Sea Discoverers',2000),('Marine Investigators',4000),('Marine Investigators',4500),('Deep Sea Divers',7000),('Deep Sea Divers',6500);
SELECT MAX(depth) FROM expedition WHERE depth < (SELECT MAX(depth) FROM expedition);
What is the total length of bus and train routes?
CREATE TABLE routes (id INT,name VARCHAR(255),type VARCHAR(255),length INT); INSERT INTO routes (id,name,type,length) VALUES (1,'10','Bus',25000),(2,'20','Train',50000);
SELECT type, SUM(length) as Total_Length FROM routes GROUP BY type;
How many space missions have been successful and unsuccessful by country?
CREATE SCHEMA Space;CREATE TABLE Space.SpaceExplorationResearch (country VARCHAR(50),mission_result VARCHAR(10));INSERT INTO Space.SpaceExplorationResearch (country,mission_result) VALUES ('USA','Success'),('USA','Success'),('China','Success'),('Russia','Failure'),('India','Success');
SELECT country, SUM(CASE WHEN mission_result = 'Success' THEN 1 ELSE 0 END) AS successes, SUM(CASE WHEN mission_result = 'Failure' THEN 1 ELSE 0 END) AS failures FROM Space.SpaceExplorationResearch GROUP BY country;
What is the number of employees by age group (under 30, 30-40, 40-50, over 50) in the Mining department?
CREATE TABLE Employees (EmployeeID INT,Department VARCHAR(20),Position VARCHAR(20),Salary INT,Age INT,IsFullTime BOOLEAN);
SELECT Department, CASE WHEN Age < 30 THEN 'under 30' WHEN Age BETWEEN 30 AND 40 THEN '30-40' WHEN Age BETWEEN 40 AND 50 THEN '40-50' ELSE 'over 50' END AS AgeGroup, COUNT(*) FROM Employees WHERE Department = 'Mining' GROUP BY Department, AgeGroup;
List all cities with public transportation systems and their respective fleet sizes
CREATE TABLE cities (id INT,city_name VARCHAR(30),population INT); CREATE TABLE public_transportation (id INT,city_id INT,system_type VARCHAR(20),fleet_size INT); INSERT INTO cities (id,city_name,population) VALUES (1,'CityA',500000),(2,'CityB',750000),(3,'CityC',1000000); INSERT INTO public_transportation (id,city_id,...
SELECT cities.city_name, public_transportation.fleet_size FROM cities INNER JOIN public_transportation ON cities.id = public_transportation.city_id;
What is the total revenue for each menu category for the current week?
CREATE TABLE menu_engineering (menu_category VARCHAR(255),date DATE,revenue DECIMAL(10,2)); INSERT INTO menu_engineering (menu_category,date,revenue) VALUES ('Appetizers','2022-01-01',500.00),('Entrees','2022-01-01',1000.00),('Desserts','2022-01-01',600.00),('Appetizers','2022-01-02',550.00),('Entrees','2022-01-02',110...
SELECT menu_category, SUM(revenue) as total_revenue FROM menu_engineering WHERE date BETWEEN DATEADD(day, -DATEPART(dw, GETDATE()), GETDATE()) AND GETDATE() GROUP BY menu_category;
What is the maximum number of passengers for each aircraft model in the aircraft_models table?
CREATE TABLE aircraft_models (model_id INT,model_name VARCHAR(255),manufacturer VARCHAR(255),max_passengers INT);
SELECT model_id, MAX(max_passengers) as max_passengers FROM aircraft_models GROUP BY model_id;
Show the number of polar bear sightings for each year in the Arctic region.
CREATE TABLE sightings (id INT PRIMARY KEY,animal VARCHAR(255),sighting_date DATE,region VARCHAR(255)); INSERT INTO sightings (id,animal,sighting_date,region) VALUES (1,'polar bear','2015-01-01','Arctic'),(2,'polar bear','2016-02-02','Arctic'),(3,'walrus','2016-03-03','Arctic');
SELECT EXTRACT(YEAR FROM sighting_date) AS year, COUNT(*) AS polar_bear_sightings FROM sightings WHERE animal = 'polar bear' AND region = 'Arctic' GROUP BY year;
Compare average step count by age group.
CREATE TABLE user_profile (id INT,user_id INT,age INT); CREATE TABLE step_count (id INT,user_id INT,step_count INT);
SELECT u.age_group, AVG(s.step_count) as avg_step_count FROM (SELECT user_id, CASE WHEN age < 20 THEN '10-19' WHEN age < 30 THEN '20-29' WHEN age < 40 THEN '30-39' ELSE '40+' END as age_group FROM user_profile) u JOIN step_count s ON u.user_id = s.user_id GROUP BY u.age_group;
Find total pollution fines issued by the European Union in the last 5 years.
CREATE TABLE pollution_fines (fine_id INT,issuing_authority VARCHAR(255),amount DECIMAL(10,2),fine_date DATE,PRIMARY KEY(fine_id)); INSERT INTO pollution_fines (fine_id,issuing_authority,amount,fine_date) VALUES (1,'European Union',150000,'2017-06-21');
SELECT SUM(amount) FROM pollution_fines WHERE issuing_authority = 'European Union' AND fine_date >= DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR);
What is the total number of emergency medical services (EMS) calls in the city of Phoenix in the year 2021?
CREATE TABLE ems_calls (id INT,city VARCHAR(20),year INT,num_calls INT); INSERT INTO ems_calls (id,city,year,num_calls) VALUES (1,'Phoenix',2021,20000);
SELECT SUM(num_calls) FROM ems_calls WHERE city = 'Phoenix' AND year = 2021;
List all customers who have a food allergy?
CREATE TABLE customers (customer_id INT,first_name VARCHAR(50),last_name VARCHAR(50),food_allergy VARCHAR(50)); INSERT INTO customers (customer_id,first_name,last_name,food_allergy) VALUES (1,'John','Doe','Nuts'),(2,'Jane','Doe','Seafood'),(3,'Bob','Smith','Eggs');
SELECT customer_id, first_name, last_name, food_allergy FROM customers WHERE food_allergy IS NOT NULL;
Insert a new risk assessment for policyholder 'Emily Chen' with a risk score of 600 into the risk_assessment_table
CREATE TABLE risk_assessment_table (assessment_id INT,policy_holder TEXT,risk_score INT);
INSERT INTO risk_assessment_table (assessment_id, policy_holder, risk_score) VALUES (1, 'Emily Chen', 600);
How many accessible technology initiatives are there in Africa?
CREATE TABLE accessible_tech (region VARCHAR(20),initiatives INT); INSERT INTO accessible_tech (region,initiatives) VALUES ('Africa',50),('Asia',75),('South America',100);
SELECT initiatives FROM accessible_tech WHERE region = 'Africa';
What is the total number of vulnerabilities in the manufacturing sector?
CREATE TABLE vulnerabilities (id INT,sector VARCHAR(20),vulnerability VARCHAR(50)); INSERT INTO vulnerabilities (id,sector,vulnerability) VALUES (1,'Manufacturing','Privilege Escalation');
SELECT COUNT(*) FROM vulnerabilities WHERE sector = 'Manufacturing';
What are the names of all restaurants that serve vegetarian options?
CREATE TABLE Restaurants (name VARCHAR(255),vegetarian BOOLEAN); INSERT INTO Restaurants (name,vegetarian) VALUES ('Bistro Veggie',TRUE),('Pizza House',FALSE),('Vegan Delight',TRUE);
SELECT name FROM Restaurants WHERE vegetarian = TRUE;
What is the average age of ceramic artifacts from the 'Jomon' culture, rounded to the nearest integer?
CREATE TABLE artifact_analysis (id INT,artifact_name VARCHAR(50),material VARCHAR(50),age INT,culture VARCHAR(50)); INSERT INTO artifact_analysis (id,artifact_name,material,age,culture) VALUES (1,'ceramic_pot','ceramic',1000,'Jomon');
SELECT ROUND(AVG(age)) FROM artifact_analysis WHERE material = 'ceramic' AND culture = 'Jomon';
List all transactions that occurred after a customer's first transaction?
CREATE TABLE Customers (CustomerID int,Name varchar(50),Age int); INSERT INTO Customers (CustomerID,Name,Age) VALUES (1,'John Smith',35),(2,'Jane Doe',42); CREATE TABLE Transactions (TransactionID int,CustomerID int,Amount decimal(10,2),TransactionDate date); INSERT INTO Transactions (TransactionID,CustomerID,Amount,Tr...
SELECT Transactions.TransactionID, Transactions.CustomerID, Transactions.Amount, Transactions.TransactionDate FROM (SELECT TransactionID, CustomerID, ROW_NUMBER() OVER (PARTITION BY CustomerID ORDER BY TransactionDate) as RowNum FROM Transactions) as TransactionsRanked JOIN Transactions ON TransactionsRanked.Transactio...
How many players from each country have played exactly 100 games?
CREATE TABLE Players (PlayerID INT,PlayerName VARCHAR(50),Age INT,Country VARCHAR(50),GamesPlayed INT); INSERT INTO Players (PlayerID,PlayerName,Age,Country,GamesPlayed) VALUES (1,'John Doe',25,'USA',100); INSERT INTO Players (PlayerID,PlayerName,Age,Country,GamesPlayed) VALUES (2,'Jane Smith',30,'Canada',200); INSERT ...
SELECT Country, COUNT(*) FROM Players WHERE GamesPlayed = 100 GROUP BY Country;
How many visitors attended 'Comedy Night' events at 'Comedy Club' in 2021?
CREATE TABLE if not exists venue (id INT,name VARCHAR(50)); CREATE TABLE if not exists event_calendar (id INT,venue_id INT,event_date DATE,event_name VARCHAR(50)); INSERT INTO venue (id,name) VALUES (1,'Comedy Club'); INSERT INTO event_calendar (id,venue_id,event_date,event_name) VALUES (1,1,'2021-01-01','Comedy Night'...
SELECT COUNT(DISTINCT ec.id) FROM event_calendar ec JOIN venue v ON ec.venue_id = v.id WHERE v.name = 'Comedy Club' AND ec.event_name = 'Comedy Night' AND ec.event_date BETWEEN '2021-01-01' AND '2021-12-31';
How many pollution control initiatives have been conducted in the Atlantic Ocean, and what is the total number of vessels involved in these initiatives?
CREATE TABLE pollution_initiatives (id INT,region VARCHAR(50),vessel_id INT,year INT); CREATE TABLE vessels (id INT,name VARCHAR(100),type VARCHAR(50));
SELECT pi.region, COUNT(DISTINCT pi.vessel_id) as num_vessels, COUNT(pi.id) as num_initiatives FROM pollution_initiatives pi INNER JOIN vessels v ON pi.vessel_id = v.id WHERE pi.region = 'Atlantic Ocean' GROUP BY pi.region;
Identify the stores with sales below the average for their state
CREATE TABLE stores (store_id INT,city VARCHAR(255),state VARCHAR(255),sales FLOAT); INSERT INTO stores (store_id,city,state,sales) VALUES (1,'Seattle','WA',400000),(2,'New York','NY',700000),(3,'Los Angeles','CA',600000);
SELECT s1.store_id, s1.city, s1.state, s1.sales FROM stores s1 INNER JOIN (SELECT state, AVG(sales) AS avg_sales FROM stores GROUP BY state) s2 ON s1.state = s2.state WHERE s1.sales < s2.avg_sales;
Update the 'grade' for a record in the 'students' table
CREATE TABLE students (student_id INT PRIMARY KEY,name VARCHAR(50),grade INT,mental_health_score INT);
UPDATE students SET grade = 12 WHERE student_id = 103;
How many visitors returned to a specific exhibition?
CREATE TABLE exhibition_visits (visitor_id INT,exhibition_id INT,visit_date DATE); INSERT INTO exhibition_visits (visitor_id,exhibition_id,visit_date) VALUES (1,1,'2021-01-01'),(1,1,'2021-02-01');
SELECT exhibition_id, COUNT(DISTINCT visitor_id) - COUNT(DISTINCT CASE WHEN visit_date = MIN(visit_date) THEN visitor_id END) AS num_returning_visitors FROM exhibition_visits GROUP BY exhibition_id;
List all companies founded by a person named "John"
CREATE TABLE company (id INT,name VARCHAR(255),founder VARCHAR(255));
SELECT name FROM company WHERE founder LIKE 'John%';
List the top 10 most active volunteers by total hours in Q2 2022, ordered by their location?
CREATE TABLE volunteer_hours (hour_id INT,volunteer_id INT,hours_spent FLOAT,hour_date DATE); INSERT INTO volunteer_hours (hour_id,volunteer_id,hours_spent,hour_date) VALUES (1,1,3,'2022-04-01'); INSERT INTO volunteer_hours (hour_id,volunteer_id,hours_spent,hour_date) VALUES (2,2,5,'2022-05-03');
SELECT v.signup_location, vh.volunteer_id, SUM(vh.hours_spent) AS total_hours FROM volunteer_hours vh INNER JOIN volunteers v ON vh.volunteer_id = v.volunteer_id WHERE EXTRACT(MONTH FROM vh.hour_date) BETWEEN 4 AND 6 GROUP BY v.signup_location, vh.volunteer_id ORDER BY total_hours DESC, v.signup_location;
What is the total number of followers for users in the 'politician' category who have posted more than 20 times?
CREATE TABLE users (user_id INT,username VARCHAR(255),category VARCHAR(255),follower_count INT,post_count INT); INSERT INTO users (user_id,username,category,follower_count,post_count) VALUES (1,'user1','politician',60000,25),(2,'user2','content_creator',20000,30),(3,'user3','politician',70000,15);
SELECT SUM(follower_count) FROM users WHERE category = 'politician' AND post_count > 20;
Increase the number of tickets sold by 10% for the most popular sports game event type in the last month.
CREATE TABLE TicketSales (id INT,event_type VARCHAR(255),location VARCHAR(255),tickets_sold INT,price DECIMAL(5,2),ticket_type VARCHAR(50),date DATE); INSERT INTO TicketSales (id,event_type,location,tickets_sold,price,ticket_type,date) VALUES (1,'Concert','Indoor Arena',1500,150,'VIP','2021-11-01'),(2,'Sports Game','Ou...
UPDATE TicketSales SET tickets_sold = tickets_sold * 1.10 WHERE event_type = (SELECT event_type FROM TicketSales WHERE date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY event_type ORDER BY SUM(tickets_sold) DESC LIMIT 1);
What are the top 5 countries with the most security incidents in the past month, according to our ThreatIntel table?
CREATE TABLE ThreatIntel (id INT,country VARCHAR(50),incidents INT,last_seen DATETIME);
SELECT country, SUM(incidents) as total_incidents FROM ThreatIntel WHERE last_seen >= DATEADD(month, -1, GETDATE()) GROUP BY country ORDER BY total_incidents DESC LIMIT 5;
List the names of vessels and their manufacturers, along with the number of regulatory compliance failures in the last 3 months.
CREATE TABLE Vessels (VesselID INT,VesselName VARCHAR(50),Manufacturer VARCHAR(50)); INSERT INTO Vessels (VesselID,VesselName,Manufacturer) VALUES (1,'Ocean Titan','ABC Shipyard'),(2,'Maritime Queen','Indian Ocean Shipbuilders'); CREATE TABLE RegulatoryCompliance (RegulationID INT,VesselID INT,ComplianceDate DATE,Compl...
SELECT Vessels.VesselName, Vessels.Manufacturer, COUNT(*) AS Failures FROM Vessels INNER JOIN RegulatoryCompliance ON Vessels.VesselID = RegulatoryCompliance.VesselID WHERE RegulatoryCompliance.ComplianceDate > DATE_SUB(CURDATE(), INTERVAL 3 MONTH) AND RegulatoryCompliance.Compliance = 'Non-Compliant' GROUP BY Vessels....
What is the total sales revenue for each region in Q3 2021?
CREATE TABLE sales_region (sale_id INT,region VARCHAR(50),sale_date DATE,total_sales DECIMAL(10,2));
SELECT region, SUM(total_sales) FROM sales_region WHERE sale_date BETWEEN '2021-07-01' AND '2021-09-30' GROUP BY region;
What is the total number of hectares farmed in all urban agriculture projects in the 'urban_agriculture' schema?
CREATE SCHEMA if not exists urban_agriculture; use urban_agriculture; CREATE TABLE urban_agriculture_projects (id INT,name TEXT,size_ha FLOAT,location TEXT); INSERT INTO urban_agriculture_projects (id,name,size_ha,location) VALUES (1,'Project 5',20.0,'City I'),(2,'Project 6',25.0,'City J');
SELECT SUM(size_ha) FROM urban_agriculture.urban_agriculture_projects;
Find the number of climate finance records for each organization, sorted by the number of records in ascending order.
CREATE TABLE climate_finance (organization_name TEXT); INSERT INTO climate_finance (organization_name) VALUES ('Organization D'),('Organization C'),('Organization D'),('Organization A'),('Organization C'),('Organization C');
SELECT organization_name, COUNT(*) as records FROM climate_finance GROUP BY organization_name ORDER BY records ASC;
Create a view with all adaptation projects' names and budgets
CREATE TABLE adaptation_projects (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),budget FLOAT,start_date DATE,end_date DATE); INSERT INTO adaptation_projects (id,name,location,budget,start_date,end_date) VALUES (1,'Seawall Construction','New York City,USA',2000000,'2022-01-01','2023-12-31'),(2,'Drought Resi...
CREATE VIEW adaptation_projects_view AS SELECT name, budget FROM adaptation_projects;
How many employees are there in each department in the 'workforce_diversity' table?
CREATE TABLE workforce_diversity (employee_id INT,name VARCHAR(50),department VARCHAR(50),gender VARCHAR(10),age INT); INSERT INTO workforce_diversity (employee_id,name,department,gender,age) VALUES (1,'John Doe','Engineering','Male',35); INSERT INTO workforce_diversity (employee_id,name,department,gender,age) VALUES (...
SELECT department, COUNT(*) FROM workforce_diversity GROUP BY department;
List the names of ingredients and their sourcing countries, sorted by the sourcing date in descending order.
CREATE TABLE ingredients (ingredient_id INT,name TEXT,sourcing_country TEXT,source_date DATE); INSERT INTO ingredients (ingredient_id,name,sourcing_country,source_date) VALUES (1,'Water','China','2021-01-01'),(2,'Glycerin','France','2021-02-15'),(3,'Retinol','USA','2020-12-10');
SELECT name, sourcing_country, source_date FROM ingredients ORDER BY source_date DESC;
What is the average mental health parity score for patients by health equity metric score quartile?
CREATE TABLE patients (patient_id INT,mental_health_parity_score INT,health_equity_metric_score INT); INSERT INTO patients (patient_id,mental_health_parity_score,health_equity_metric_score) VALUES (1,75,70),(2,80,80),(3,60,90),(4,90,60),(5,70,75);
SELECT AVG(mental_health_parity_score), NTILE(4) OVER (ORDER BY health_equity_metric_score) AS quartile FROM patients GROUP BY quartile;
What is the average word count of articles about climate change?
CREATE TABLE article_topics (article_id INT,topic VARCHAR(50)); CREATE TABLE articles (article_id INT,word_count INT,creation_date DATE);
SELECT AVG(word_count) FROM articles JOIN article_topics ON articles.article_id = article_topics.article_id WHERE topic = 'climate change';
What is the total research grant funding received by the Chemistry department?
CREATE TABLE Grants(GrantID INT,Department VARCHAR(50),Amount FLOAT); INSERT INTO Grants(GrantID,Department,Amount) VALUES (1,'Chemistry',200000.00),(2,'Physics',150000.00),(3,'Chemistry',300000.00);
SELECT SUM(Amount) FROM Grants WHERE Department = 'Chemistry'
Create a table named "tourist_attractions" with columns "attraction_id", "name", "type", "location", "cultural_significance" of types integer, text, text, text, and text respectively
CREATE TABLE tourist_attractions (attraction_id integer,name text,type text,location text,cultural_significance text);
CREATE TABLE tourist_attractions (attraction_id integer, name text, type text, location text, cultural_significance text);
What is the total fare collected for each station in the 'stations' table?
CREATE TABLE stations (station_id INT,station_name VARCHAR(255),num_platforms INT,daily_passengers INT,fare FLOAT);
SELECT station_name, SUM(fare) as total_fare FROM stations GROUP BY station_name;
Delete all records from the 'Volunteers' table where the volunteer name is 'Brian Chen'
CREATE TABLE Volunteers (id INT PRIMARY KEY,volunteer_name VARCHAR(255),hours_volunteered DECIMAL(10,2)); INSERT INTO Volunteers (id,volunteer_name,hours_volunteered) VALUES (1,'Alice Lee',3.00),(2,'Brian Chen',5.00);
DELETE FROM Volunteers WHERE volunteer_name = 'Brian Chen';
How many co-ownership properties are there in the 'sustainable' and 'affordable' areas?
CREATE TABLE properties (property_id INT,area VARCHAR(20),co_ownership BOOLEAN);
SELECT COUNT(*) FROM properties WHERE area IN ('sustainable', 'affordable') AND co_ownership = TRUE;
List all genetic research projects, their corresponding principal investigators, and their associated labs, if any.
CREATE TABLE research_projects (id INT,name TEXT,principal_investigator TEXT); CREATE TABLE labs (id INT,name TEXT,research_project_id INT); INSERT INTO research_projects (id,name,principal_investigator) VALUES (1,'Project X','Dr. Smith'); INSERT INTO labs (id,name,research_project_id) VALUES (1,'Lab 1',1);
SELECT r.name, r.principal_investigator, l.name FROM research_projects r LEFT JOIN labs l ON r.id = l.research_project_id;
Query the DiversityByGender view
SELECT * FROM DiversityByGender;
SELECT * FROM DiversityByGender;
Count the number of co-owned properties in Portland with a listing price above $300,000.
CREATE TABLE properties (id INT,city VARCHAR(20),listing_price INT,co_owned BOOLEAN); INSERT INTO properties (id,city,listing_price,co_owned) VALUES (1,'Portland',400000,true); INSERT INTO properties (id,city,listing_price,co_owned) VALUES (2,'Portland',250000,false);
SELECT COUNT(*) FROM properties WHERE city = 'Portland' AND listing_price > 300000 AND co_owned = true;
Calculate the maximum and minimum distance of asteroids from the Sun, and the average distance of these asteroids from the Sun.
CREATE TABLE Asteroids (id INT,name VARCHAR(255),distance FLOAT);
SELECT MAX(distance) as max_distance, MIN(distance) as min_distance, AVG(distance) as avg_distance FROM Asteroids;
Find the number of factories in each region that use renewable energy.
CREATE TABLE factories (id INT,region VARCHAR(255),uses_renewable_energy BOOLEAN);
SELECT region, COUNT(*) FROM factories WHERE uses_renewable_energy = TRUE GROUP BY region;
What is the maximum donation amount in the 'emergency_response' table?
CREATE TABLE emergency_response (donation_id INT,donor VARCHAR(50),amount DECIMAL(10,2),donation_date DATE); INSERT INTO emergency_response (donation_id,donor,amount,donation_date) VALUES (1,'Karen Green',350.00,'2021-01-01'),(2,'Larry Black',500.00,'2021-02-01');
SELECT MAX(amount) FROM emergency_response;
List the names and average depths of the oceanic trenches in the Pacific Ocean deeper than 8000 meters.
CREATE TABLE pacific_trenches (id INT,name VARCHAR(255),avg_depth FLOAT); INSERT INTO pacific_trenches (id,name,avg_depth) VALUES (1,'Mariana Trench',10994),(2,'Tonga Trench',10882),(3,'Kuril-Kamchatka Trench',10542);
SELECT name, avg_depth FROM pacific_trenches WHERE avg_depth > 8000;
What is the total spending on inclusion efforts by each department?
CREATE TABLE InclusionEfforts (EffortID INT,EffortName VARCHAR(50),Department VARCHAR(50),Cost DECIMAL(5,2)); INSERT INTO InclusionEfforts VALUES (1,'Accessible Workspaces','HR',15000.00),(2,'Diversity Training','Training',20000.00),(3,'Inclusive Hiring Campaign','HR',10000.00),(4,'Disability Awareness Campaign','Marke...
SELECT Department, SUM(Cost) FROM InclusionEfforts GROUP BY Department;
Delete all hotels in New York.
CREATE TABLE hotels (id INT,city VARCHAR(20)); INSERT INTO hotels (id,city) VALUES (1,'Tokyo'),(2,'Osaka'),(3,'New York');
DELETE FROM hotels WHERE city = 'New York';
Show the number of working hours for each agricultural machine in the past week.
CREATE TABLE machine_usage (machine TEXT,usage INTEGER,start_time TIMESTAMP,end_time TIMESTAMP);
SELECT machine, SUM(DATEDIFF(minute, start_time, end_time)) as working_hours FROM machine_usage WHERE end_time BETWEEN DATEADD(day, -7, CURRENT_TIMESTAMP) AND CURRENT_TIMESTAMP GROUP BY machine;
What is the most expensive halal certified skincare product?
CREATE TABLE products (id INT,name VARCHAR(255),category VARCHAR(255),price DECIMAL(5,2),halal_certified BOOLEAN); INSERT INTO products (id,name,category,price,halal_certified) VALUES (1,'Cleanser','skincare',19.99,true),(2,'Toner','skincare',24.99,false),(3,'Moisturizer','skincare',34.99,true);
SELECT name, price FROM products WHERE halal_certified = true ORDER BY price DESC LIMIT 1;
What is the latest launch date of a satellite by NASA?
CREATE TABLE nasa_satellites (id INT,satellite_name VARCHAR(255),launch_date DATE,organization VARCHAR(255)); INSERT INTO nasa_satellites (id,satellite_name,launch_date,organization) VALUES (1,'Juno','2011-08-05','NASA');
SELECT MAX(launch_date) FROM nasa_satellites WHERE organization = 'NASA';
Insert a new well with well_id 4, well_type 'onshore', location 'Alberta', and production_rate 900.
CREATE TABLE wells (well_id INT,well_type VARCHAR(10),location VARCHAR(20),production_rate FLOAT);
INSERT INTO wells (well_id, well_type, location, production_rate) VALUES (4, 'onshore', 'Alberta', 900);
What is the total revenue for the Pop genre in 2021?
CREATE TABLE music_sales (sale_id INT,genre VARCHAR(10),year INT,revenue FLOAT); INSERT INTO music_sales (sale_id,genre,year,revenue) VALUES (1,'Pop',2021,50000.00),(2,'Rock',2021,45000.00),(3,'Pop',2020,40000.00); CREATE VIEW genre_sales AS SELECT genre,SUM(revenue) as total_revenue FROM music_sales GROUP BY genre;
SELECT total_revenue FROM genre_sales WHERE genre = 'Pop';
What is the total quantity of grain transported by vessels from the USA to Africa?
CREATE TABLE vessel_cargo (id INT,vessel_id INT,departure_country VARCHAR(255),arrival_country VARCHAR(255),cargo_type VARCHAR(255),quantity INT); INSERT INTO vessel_cargo (id,vessel_id,departure_country,arrival_country,cargo_type,quantity) VALUES (3,16,'USA','Africa','Grain',12000); INSERT INTO vessel_cargo (id,vessel...
SELECT SUM(quantity) as total_grain_transported FROM vessel_cargo WHERE departure_country = 'USA' AND arrival_country = 'Africa' AND cargo_type = 'Grain';
List the average rating and number of reviews of each hotel and restaurant in Tokyo
CREATE TABLE hotels (hotel_id INT,hotel_name VARCHAR(50),city VARCHAR(50),review_count INT,rating DECIMAL(2,1)); CREATE TABLE restaurants (restaurant_id INT,restaurant_name VARCHAR(50),city VARCHAR(50),review_count INT,rating DECIMAL(2,1));
SELECT 'hotel' as location, hotel_name, AVG(rating) as avg_rating, SUM(review_count) as total_reviews FROM hotels WHERE city = 'Tokyo' GROUP BY hotel_name UNION SELECT 'restaurant' as location, restaurant_name, AVG(rating) as avg_rating, SUM(review_count) as total_reviews FROM restaurants WHERE city = 'Tokyo' GROUP BY ...
What is the total number of satellites in orbit for each country?
CREATE SCHEMA space; USE space; CREATE TABLE country (name VARCHAR(50),population INT); CREATE TABLE satellite (id INT,name VARCHAR(50),country VARCHAR(50),orbit_status VARCHAR(50)); INSERT INTO country (name,population) VALUES ('USA',330000000),('Russia',145000000); INSERT INTO satellite (id,name,country,orbit_status)...
SELECT s.country, COUNT(s.id) FROM space.satellite s JOIN space.country c ON s.country = c.name WHERE s.orbit_status = 'In orbit' GROUP BY s.country;
What is the maximum balance for customers in the North region?
CREATE TABLE customers (id INT,name VARCHAR(50),region VARCHAR(50),balance DECIMAL(10,2)); INSERT INTO customers (id,name,region,balance) VALUES (1,'John Doe','North',5000.00),(2,'Jane Smith','North',7000.00),(3,'Alice Johnson','South',6000.00);
SELECT MAX(balance) FROM customers WHERE region = 'North';
What is the total waste generation in the city of Accra in 2020?
CREATE TABLE waste_generation(city VARCHAR(20),year INT,amount INT); INSERT INTO waste_generation VALUES('Accra',2020,150000);
SELECT amount FROM waste_generation WHERE city = 'Accra' AND year = 2020;
Calculate the average production of oil and gas (in BOE) for each well in the Bakken formation
CREATE TABLE if not exists well_production (well_id INT,well_name TEXT,location TEXT,production_year INT,oil_production FLOAT,gas_production FLOAT); INSERT INTO well_production (well_id,well_name,location,production_year,oil_production,gas_production) VALUES (1,'Well A','Bakken',2020,1234.56,987.65),(2,'Well B','Bakken...
SELECT well_name, (AVG(oil_production) + (AVG(gas_production) / 6)) AS avg_total_production FROM well_production WHERE location = 'Bakken' GROUP BY well_name;
What is the total biomass of all marine species in the Indian Ocean, categorized by their feeding habits?
CREATE TABLE marine_species (id INT,species VARCHAR(50),ocean VARCHAR(50),feeding_habits VARCHAR(50),biomass FLOAT);
SELECT ocean, feeding_habits, SUM(biomass) FROM marine_species WHERE ocean = 'Indian Ocean' GROUP BY ocean, feeding_habits;
Who are the policyholders with the highest risk assessment in California?
CREATE TABLE Policyholders (PolicyID INT,Name VARCHAR(50)); CREATE TABLE UnderwritingData (PolicyID INT,Team VARCHAR(20),RiskAssessment DECIMAL(5,2),State VARCHAR(20)); INSERT INTO Policyholders VALUES (1,'John Smith'),(2,'Jane Doe'),(3,'Mike Brown'); INSERT INTO UnderwritingData VALUES (1,'Team A',0.35,'California'),(...
SELECT p.Name, u.RiskAssessment FROM Policyholders p INNER JOIN UnderwritingData u ON p.PolicyID = u.PolicyID WHERE State = 'California' ORDER BY RiskAssessment DESC;
What is the difference in marine protected area size per region?
CREATE TABLE marine_protected_areas (region VARCHAR(255),area_size FLOAT); INSERT INTO marine_protected_areas (region,area_size) VALUES ('Atlantic',15000),('Pacific',20000),('Indian',12000),('Arctic',10000),('Southern',18000),('Mediterranean',14000);
SELECT region, area_size - LAG(area_size) OVER(ORDER BY region) as area_size_difference FROM marine_protected_areas;
Find the number of unique suppliers in the "SupplyChain_2022" table who provide both vegan and non-vegan ingredients
CREATE TABLE SupplyChain_2022 (id INT,supplier_name VARCHAR(50),ingredient VARCHAR(50),vegan BOOLEAN); INSERT INTO SupplyChain_2022 (id,supplier_name,ingredient,vegan) VALUES (1,'Supplier5','Tofu',true),(2,'Supplier6','Chicken',false),(3,'Supplier7','Soy Milk',true),(4,'Supplier8','Beef',false);
SELECT DISTINCT supplier_name FROM SupplyChain_2022 WHERE vegan = true INTERSECT SELECT DISTINCT supplier_name FROM SupplyChain_2022 WHERE vegan = false;
Which countries source organic ingredients for cosmetics the most?
CREATE TABLE sourcing (country VARCHAR(50),organic_ingredients_percentage DECIMAL(5,2)); INSERT INTO sourcing (country,organic_ingredients_percentage) VALUES ('France',65),('Italy',55),('Germany',70),('USA',80),('Brazil',45),('China',30),('India',50),('Spain',60),('Argentina',40),('Australia',75);
SELECT country, organic_ingredients_percentage FROM sourcing ORDER BY organic_ingredients_percentage DESC;
What is the total amount of climate finance provided to African countries in 2020?
CREATE TABLE climate_finance (year INT,region VARCHAR(255),amount FLOAT); INSERT INTO climate_finance VALUES (2020,'Africa',5000000);
SELECT SUM(amount) FROM climate_finance WHERE year = 2020 AND region = 'Africa';
What is the maximum salary for workers in the 'metalwork' department?
CREATE TABLE factories (factory_id INT,department VARCHAR(20)); INSERT INTO factories VALUES (1,'textiles'),(2,'metalwork'),(3,'textiles'),(4,'electronics'),(5,'textiles'); CREATE TABLE workers (worker_id INT,factory_id INT,salary DECIMAL(5,2)); INSERT INTO workers VALUES (1,1,45000.00),(2,1,46000.00),(3,2,50000.00),(4...
SELECT MAX(salary) FROM workers INNER JOIN factories ON workers.factory_id = factories.factory_id WHERE factories.department = 'metalwork';
List all space missions launched by NASA before 2010
CREATE TABLE SpaceMissions(ID INT,MissionName VARCHAR(50),LaunchDate DATE,Agency VARCHAR(50));
SELECT MissionName FROM SpaceMissions WHERE Agency = 'NASA' AND LaunchDate < '2010-01-01';
Calculate the number of animals in each program
CREATE TABLE animal_population (animal_id INT,animal_name VARCHAR(50),program VARCHAR(50)); INSERT INTO animal_population (animal_id,animal_name,program) VALUES (1,'Grizzly Bear','habitat_preservation'),(2,'Gray Wolf','community_education'),(3,'Bald Eagle','habitat_preservation'),(4,'Red Fox','community_education');
SELECT program, COUNT(*) FROM animal_population GROUP BY program;
What was the total quantity of cargo unloaded at the port of Oakland in June 2021, grouped by cargo type?
CREATE TABLE ports (id INT,name VARCHAR(50)); INSERT INTO ports (id,name) VALUES (1,'Oakland'),(2,'Los Angeles'); CREATE TABLE cargo (id INT,port_id INT,cargo_type VARCHAR(50),quantity INT); INSERT INTO cargo (id,port_id,cargo_type,quantity) VALUES (1,1,'Furniture',500),(2,1,'Electronics',800),(3,2,'Furniture',700),(4,...
SELECT cargo_type, SUM(quantity) as total_quantity FROM cargo WHERE port_id = 1 AND MONTH(date) = 6 GROUP BY cargo_type;
What is the maximum total cost of water treatment projects?
CREATE TABLE Projects (id INT,division VARCHAR(20),total_cost FLOAT); INSERT INTO Projects (id,division,total_cost) VALUES (1,'transportation',300000),(2,'water treatment',750000),(3,'transportation',500000),(4,'water treatment',900000);
SELECT MAX(total_cost) FROM Projects WHERE division = 'water treatment';
What is the total sales for each drug in the Canadian market that has an approved clinical trial?
CREATE TABLE drug_sales (drug_name TEXT,year INTEGER,sales INTEGER,market TEXT); INSERT INTO drug_sales (drug_name,year,sales,market) VALUES ('DrugA',2018,1000000,'Canada'); INSERT INTO drug_sales (drug_name,year,sales,market) VALUES ('DrugB',2018,2000000,'Canada'); INSERT INTO drug_sales (drug_name,year,sales,market) ...
SELECT drug_sales.drug_name, SUM(drug_sales.sales) FROM drug_sales JOIN clinical_trials ON drug_sales.drug_name = clinical_trials.drug_name WHERE clinical_trials.market = 'Canada' AND clinical_trials.trial_status = 'Approved' GROUP BY drug_sales.drug_name;
Update the "donors" table to reflect a new donation from a foundation based in Canada
CREATE TABLE donors (id INT PRIMARY KEY,name VARCHAR(100),donation_date DATE,amount DECIMAL(10,2),country VARCHAR(50));
UPDATE donors SET name = 'Canadian Art Foundation', donation_date = '2022-03-15', amount = 5000.00, country = 'Canada' WHERE id = 1;
How many regulatory compliance failures did vessel 'Poseidon' have?
CREATE TABLE Vessels (VesselID INT,VesselName VARCHAR(255)); CREATE TABLE Compliance (ComplianceID INT,VesselID INT,ComplianceDate DATETIME,ComplianceStatus VARCHAR(10)); INSERT INTO Vessels (VesselID,VesselName) VALUES (1,'Oceanus'),(2,'Neptune'),(3,'Poseidon'); INSERT INTO Compliance (ComplianceID,VesselID,Compliance...
SELECT COUNT(*) AS FailureCount FROM Compliance WHERE VesselID = (SELECT VesselID FROM Vessels WHERE VesselName = 'Poseidon') AND ComplianceStatus = 'Fail';
What is the maximum fare for train lines that have at least 10 stations?
CREATE TABLE train_lines (line_id INT,line_name TEXT,fare FLOAT,num_stations INT); INSERT INTO train_lines (line_id,line_name,fare,num_stations) VALUES (1,'Line 1',2.0,12),(2,'Line 2',2.5,8),(3,'Line 3',3.0,15);
SELECT MAX(fare) FROM train_lines WHERE num_stations >= 10;
How many individuals with disabilities have received accommodations in each region for the past 12 months, including the total budget allocated for those accommodations?
CREATE TABLE Disability_Accommodations (id INT,region VARCHAR(50),individual_count INT,budget DECIMAL(10,2),accommodation_date DATE);
SELECT region, COUNT(individual_count) as individual_count, SUM(budget) as total_budget FROM Disability_Accommodations WHERE accommodation_date >= DATEADD(month, -12, GETDATE()) GROUP BY region;
What is the average depth of all marine protected areas (MPAs) in the Pacific Ocean region?
CREATE TABLE marine_protected_areas (id INT,name VARCHAR(255),depth FLOAT,region VARCHAR(255)); INSERT INTO marine_protected_areas (id,name,depth,region) VALUES (1,'Great Barrier Reef',344,'Pacific'); INSERT INTO marine_protected_areas (id,name,depth,region) VALUES (2,'Monterey Bay National Marine Sanctuary',150,'Pacif...
SELECT AVG(depth) FROM marine_protected_areas WHERE region = 'Pacific';
What is the total number of hours worked by public defenders in a year?
CREATE TABLE public_defenders (defender_id INT,hours_worked INT,year INT);
SELECT SUM(hours_worked) FROM public_defenders WHERE year = (SELECT MAX(year) FROM public_defenders);
Percentage of cultural competency training completed by community health workers by race?
CREATE TABLE CulturalCompetencyTraining (ID INT,CommunityHealthWorkerID INT,Race VARCHAR(50),TrainingPercentage DECIMAL(5,2)); INSERT INTO CulturalCompetencyTraining (ID,CommunityHealthWorkerID,Race,TrainingPercentage) VALUES (1,1,'Native American',0.65),(2,2,'Asian',0.85),(3,3,'African American',0.92);
SELECT Race, AVG(TrainingPercentage) as AvgTrainingPercentage FROM CulturalCompetencyTraining GROUP BY Race;
What is the total amount donated by each agency for flood disasters?
CREATE TABLE Disasters (id INT,name TEXT,location TEXT,type TEXT,date DATE,fatalities INT); INSERT INTO Disasters (id,name,location,type,date,fatalities) VALUES (5,'Flood','Country5','Natural','2021-05-01',12); INSERT INTO Disasters (id,name,location,type,date,fatalities) VALUES (6,'Tornado','Country6','Natural','2021-...
SELECT agency, SUM(donation_amount) FROM Donations WHERE disaster_id IN (SELECT id FROM Disasters WHERE type = 'Flood') GROUP BY agency;
What is the maximum fare for a trip on the Blue Line?
CREATE TABLE if not exists metro_lines (line_id serial primary key,name varchar(255));CREATE TABLE if not exists metro_stations (station_id serial primary key,name varchar(255),line_id int);CREATE TABLE if not exists routes (route_id serial primary key,line_id int,start_station_id int,end_station_id int);CREATE TABLE i...
SELECT MAX(f.price) FROM fares f JOIN routes r ON f.route_id = r.route_id JOIN metro_stations s ON r.start_station_id = s.station_id WHERE s.line_id = 3;
What are the production figures for well 'W001' in the North Sea?
CREATE TABLE wells (well_id varchar(10),region varchar(20),production_figures int); INSERT INTO wells (well_id,region,production_figures) VALUES ('W001','North Sea',5000);
SELECT production_figures FROM wells WHERE well_id = 'W001' AND region = 'North Sea';
What is the percentage of wastewater treated in each country?
CREATE TABLE wastewater_volume (country VARCHAR(50),treated_volume INT,total_volume INT); INSERT INTO wastewater_volume (country,treated_volume,total_volume) VALUES ('USA',1200,1500),('Canada',800,1000),('Mexico',600,900),('Brazil',1000,1300);
SELECT wv.country, (wv.treated_volume*100.0/wv.total_volume) as percentage_treated FROM wastewater_volume wv;
What is the number of property co-ownership agreements by type in cities with inclusive housing policies and affordability scores below 60?
CREATE TABLE City (id INT PRIMARY KEY,name VARCHAR(50),affordability_score INT,inclusive_housing BOOLEAN); CREATE TABLE Property (id INT PRIMARY KEY,city_id INT,type VARCHAR(50),co_ownership BOOLEAN); CREATE VIEW Co_Ownership_Properties AS SELECT * FROM Property WHERE co_ownership = true;
SELECT Property.type, COUNT(Property.id) as num_agreements FROM Property INNER JOIN Co_Ownership_Properties ON Property.id = Co_Ownership_Properties.id INNER JOIN City ON Co_Ownership_Properties.city_id = City.id WHERE City.inclusive_housing = true AND City.affordability_score < 60 GROUP BY Property.type;
What is the number of unique users who streamed music during each month in the year 2020?
CREATE TABLE music_streaming (id INT,user_id INT,artist VARCHAR(50),song VARCHAR(50),genre VARCHAR(20),streamed_on DATE,streams INT); CREATE VIEW monthly_user_streams AS SELECT DATE_TRUNC('month',streamed_on) AS month,user_id FROM music_streaming GROUP BY month,user_id;
SELECT month, COUNT(DISTINCT user_id) FROM monthly_user_streams WHERE streamed_on BETWEEN '2020-01-01' AND '2020-12-31' GROUP BY month ORDER BY month;
What is the highest rated eco-friendly hotel in Kyoto?
CREATE TABLE eco_hotels (hotel_id INT,hotel_name VARCHAR(100),city VARCHAR(100),rating FLOAT); INSERT INTO eco_hotels (hotel_id,hotel_name,city,rating) VALUES (1,'Eco Hotel Tokyo','Tokyo',4.7); INSERT INTO eco_hotels (hotel_id,hotel_name,city,rating) VALUES (2,'Green Hotel Tokyo','Tokyo',4.6); INSERT INTO eco_hotels (h...
SELECT hotel_name, MAX(rating) FROM eco_hotels WHERE city = 'Kyoto';
What is the total number of unique users who played multiplayer games in each country?
CREATE TABLE users (id INT,country VARCHAR(255),last_login DATE); CREATE TABLE games (id INT,genre VARCHAR(255),multiplayer BOOLEAN,launched DATE); CREATE TABLE game_sessions (id INT,user_id INT,game_id INT,session_start DATE);
SELECT u.country, COUNT(DISTINCT user_id) as num_users FROM users u JOIN game_sessions gs ON u.id = gs.user_id JOIN games g ON gs.game_id = g.id WHERE g.multiplayer = TRUE GROUP BY u.country;
Display the names and total labor hours for workers who have worked on sustainable projects, sorted alphabetically by worker name.
CREATE TABLE construction_workers (worker_id INT,name TEXT); CREATE TABLE project_types (project_id INT,project_type TEXT); CREATE TABLE worker_projects (worker_id INT,project_id INT,total_labor_hours INT); INSERT INTO construction_workers (worker_id,name) VALUES (1,'John Doe'),(2,'Jane Smith'),(3,'Maria Garcia'),(4,'A...
SELECT construction_workers.name, SUM(worker_projects.total_labor_hours) FROM construction_workers INNER JOIN worker_projects ON construction_workers.worker_id = worker_projects.worker_id INNER JOIN project_types ON worker_projects.project_id = project_types.project_id WHERE project_types.project_type = 'Sustainable' G...
What is the total number of hours of training completed by employees in the IT department?
CREATE TABLE training_completed (id INT,employee_id INT,department VARCHAR(50),hours_trained INT);
SELECT SUM(hours_trained) FROM training_completed WHERE department = 'IT';
How many paintings were created per year by female artists?
CREATE TABLE artists (id INT,name VARCHAR(50),gender VARCHAR(10)); INSERT INTO artists (id,name,gender) VALUES (1,'Frida Kahlo','Female'); INSERT INTO artists (id,name,gender) VALUES (2,'Pablo Picasso','Male'); CREATE TABLE paintings (id INT,artist_id INT,year INT); INSERT INTO paintings (id,artist_id,year) VALUES (1,1...
SELECT p.year, COUNT(p.id) as paintings_per_year FROM paintings p JOIN artists a ON p.artist_id = a.id WHERE a.gender = 'Female' GROUP BY p.year;
Insert new records for Foreign Military Aid to 'Somalia' with an Amount of 4000000 for the year 2012 and to 'Syria' with an Amount of 5000000 for the year 2014.
CREATE TABLE ForeignMilitaryAid (Year INT,Country VARCHAR(50),Amount DECIMAL(10,2)); INSERT INTO ForeignMilitaryAid (Year,Country,Amount) VALUES (2005,'Afghanistan',5000000),(2006,'Iraq',7000000),(2010,'Pakistan',6000000);
INSERT INTO ForeignMilitaryAid (Year, Country, Amount) VALUES (2012, 'Somalia', 4000000), (2014, 'Syria', 5000000);
What is the number of unique vendors in the Vendors table?
CREATE TABLE Vendors (vendor_id INT,vendor_name TEXT,vendor_location TEXT); INSERT INTO Vendors (vendor_id,vendor_name,vendor_location) VALUES (301,'Green Farms','CA'); INSERT INTO Vendors (vendor_id,vendor_name,vendor_location) VALUES (302,'Eco Goods','NY'); INSERT INTO Vendors (vendor_id,vendor_name,vendor_location) ...
SELECT COUNT(DISTINCT vendor_name) FROM Vendors;
What are the average flight hours and total costs for each aircraft model used in space launch missions?
CREATE TABLE AircraftModels (ModelID INT,ModelName VARCHAR(50),Manufacturer VARCHAR(50),AvgFlightHours DECIMAL(5,2),TotalCost DECIMAL(10,2));
SELECT AircraftModels.ModelName, AircraftModels.Manufacturer, AVG(AircraftModels.AvgFlightHours) as AvgFlightHours, SUM(AircraftModels.TotalCost) as TotalCosts FROM AircraftModels GROUP BY AircraftModels.ModelName, AircraftModels.Manufacturer;
What is the minimum funding round size for startups founded by immigrants?
CREATE TABLE startup (id INT,name TEXT,founder_citizenship TEXT,funding_round_size INT); INSERT INTO startup (id,name,founder_citizenship,funding_round_size) VALUES (1,'ImmigrantStart','Immigrant',3000000); INSERT INTO startup (id,name,founder_citizenship,funding_round_size) VALUES (2,'TechStart','Citizen',10000000);
SELECT MIN(funding_round_size) FROM startup WHERE founder_citizenship = 'Immigrant';
What is the average financial wellbeing score of customers who have a financial capability score between 70 and 85?
CREATE TABLE customers (id INT,financial_capability_score INT,financial_wellbeing_score INT); INSERT INTO customers (id,financial_capability_score,financial_wellbeing_score) VALUES (1,90,75),(2,80,70),(3,85,80),(4,95,85),(5,75,78),(6,82,83);
SELECT AVG(financial_wellbeing_score) as avg_score FROM customers WHERE financial_capability_score BETWEEN 70 AND 85;
List all unique passengers who have used the 'Night' bus service.
CREATE TABLE PassengerTransit (PassengerID int,TransitMode varchar(50),TransitTime varchar(50)); INSERT INTO PassengerTransit VALUES (1,'Bus (Night)','23:00-01:00'); INSERT INTO PassengerTransit VALUES (2,'Bus (Day)','07:00-09:00'); INSERT INTO PassengerTransit VALUES (3,'Bus (Night)','01:00-03:00'); INSERT INTO Passen...
SELECT DISTINCT PassengerID FROM PassengerTransit WHERE TransitMode LIKE 'Bus (Night)';
Which countries supply ingredients for organic makeup products?
CREATE TABLE products (product_id INT,name VARCHAR(50),organic BOOLEAN); INSERT INTO products (product_id,name,organic) VALUES (1,'Lipstick A',true),(2,'Lipstick B',false),(3,'Eyeshadow C',false); CREATE TABLE ingredient_suppliers (ingredient_id INT,supplier_country VARCHAR(50),product_id INT,organic_source BOOLEAN); I...
SELECT DISTINCT supplier_country FROM ingredient_suppliers WHERE organic_source = true AND product_id IN (SELECT product_id FROM products WHERE products.organic = true);