instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the total revenue generated from broadband customers in the state of California?
CREATE TABLE broadband_customers (customer_id INT,speed FLOAT,revenue FLOAT,state VARCHAR(20)); INSERT INTO broadband_customers (customer_id,speed,revenue,state) VALUES (1,150,50,'California'),(2,120,40,'New York'),(3,200,60,'California');
SELECT SUM(revenue) FROM broadband_customers WHERE state = 'California';
What is the average R&D expenditure per country for vaccines?
CREATE TABLE rd_expenditure (country VARCHAR(50),drug_type VARCHAR(50),amount NUMERIC(10,2)); INSERT INTO rd_expenditure (country,drug_type,amount) VALUES ('USA','Vaccine',12000000),('Canada','Vaccine',8000000),('Mexico','Vaccine',6000000);
SELECT AVG(amount) FROM rd_expenditure WHERE drug_type = 'Vaccine' GROUP BY country;
What is the percentage of hotels in India that offer virtual tours?
CREATE TABLE hotel_features (hotel_id INT,country TEXT,virtual_tours INT,ai_guest_comm INT); INSERT INTO hotel_features (hotel_id,country,virtual_tours,ai_guest_comm) VALUES (1,'India',1,0),(2,'India',0,1),(3,'Canada',1,1);
SELECT 100.0 * COUNT(*) / (SELECT COUNT(*) FROM hotel_features WHERE country = 'India') FROM hotel_features WHERE country = 'India' AND virtual_tours = 1;
What is the total number of cannabis plants grown in each state, sorted by the total number of plants in descending order?
CREATE TABLE Plants (state VARCHAR(255),plants INT); INSERT INTO Plants (state,plants) VALUES ('OR',5000),('WA',6000),('CA',8000),('CO',7000),('MI',4000);
SELECT state, SUM(plants) as total_plants FROM Plants GROUP BY state ORDER BY total_plants DESC;
What is the total quantity of minerals extracted by medium-scale mines in Australia in 2022?
CREATE TABLE MineTypes (MineID int,MineType varchar(50)); INSERT INTO MineTypes VALUES (1,'Small-scale Mine'),(2,'Medium-scale Mine'),(3,'Large-scale Mine'); CREATE TABLE ExtractionData (MineID int,ExtractionDate date,Material varchar(10),Quantity int); INSERT INTO ExtractionData VALUES (1,'2022-01-01','Gold',1000),(1,'2022-01-15','Gold',1500),(2,'2022-01-30','Gold',800),(1,'2022-02-05','Gold',1200),(3,'2022-03-01','Gold',1000);
SELECT mt.MineType, SUM(ed.Quantity) as TotalExtraction FROM ExtractionData ed JOIN MineTypes mt ON ed.MineID = mt.MineID WHERE ed.ExtractionDate BETWEEN '2022-01-01' AND '2022-12-31' AND mt.MineType = 'Medium-scale Mine' AND ed.Material = 'Gold' GROUP BY mt.MineType;
Find the top 3 countries with the most heritage sites, ordered by the number of sites in descending order.
CREATE TABLE Sites (SiteID INT,SiteName TEXT,Country TEXT); INSERT INTO Sites (SiteID,SiteName,Country) VALUES (1001,'Museum of World Cultures','USA'),(1002,'Global Arts Gallery','Canada'),(1003,'Heritage House','Mexico'),(1004,'Ancient Pyramids','Egypt'),(1005,'Temple of Time','India');
SELECT Country, COUNT(SiteID) AS Number_Of_Sites FROM Sites GROUP BY Country ORDER BY Number_Of_Sites DESC LIMIT 3;
Identify the top 2 countries generating revenue from sustainable accommodations.
CREATE TABLE accommodations (accom_id INT,name VARCHAR(50),country VARCHAR(50),sustainability_rating INT,revenue FLOAT);
SELECT country, SUM(revenue) AS total_revenue FROM accommodations WHERE sustainability_rating >= 4 GROUP BY country ORDER BY total_revenue DESC LIMIT 2;
Update the vessel "Mediterranean Mermaid" with id 108 to have a gross tonnage of 3000
CREATE TABLE vessels (id INT,name TEXT,gross_tonnage INT);
UPDATE vessels SET gross_tonnage = 3000 WHERE id = 108 AND name = 'Mediterranean Mermaid';
Display the average wait time (in hours) at each port for cargo to be loaded, excluding ports with no cargo loaded, and show the results for the top 3 ports with the longest average wait times.
CREATE TABLE ports(port_id INT,port_name TEXT);CREATE TABLE cargo(cargo_id INT,line_id INT,port_id INT,wait_time_hours INT);INSERT INTO ports VALUES (1,'Port A'),(2,'Port B'),(3,'Port C');INSERT INTO cargo VALUES (1,1,1,12),(2,1,2,8),(3,2,1,10),(4,3,3,5);
SELECT p.port_name, AVG(c.wait_time_hours) as avg_wait_time FROM ports p JOIN cargo c ON p.port_id = c.port_id GROUP BY p.port_name HAVING avg_wait_time > 0 ORDER BY avg_wait_time DESC LIMIT 3;
What is the total installed capacity of renewable energy projects in the 'RenewableEnergyProjects' table, grouped by project_status?
CREATE TABLE RenewableEnergyProjects (id INT,project_status VARCHAR(50),installed_capacity FLOAT); INSERT INTO RenewableEnergyProjects (id,project_status,installed_capacity) VALUES (1,'Completed',1000.0),(2,'In Progress',1500.0),(3,'Completed',1200.0);
SELECT project_status, SUM(installed_capacity) FROM RenewableEnergyProjects GROUP BY project_status;
Update the workout 'Yoga' to have a duration of 60 minutes.
CREATE TABLE Workouts (id INT,workout_name TEXT,duration INT); INSERT INTO Workouts (id,workout_name,duration) VALUES (1,'Running',30); INSERT INTO Workouts (id,workout_name,duration) VALUES (2,'Cycling',45); INSERT INTO Workouts (id,workout_name,duration) VALUES (3,'Yoga',40);
UPDATE Workouts SET duration = 60 WHERE workout_name = 'Yoga';
What is the average donation per donor in the 'Donors' table?
CREATE TABLE Donors (DonorID int,DonorName varchar(50),Donation decimal(10,2)); INSERT INTO Donors (DonorID,DonorName,Donation) VALUES (1,'John Doe',500.00),(2,'Jane Smith',700.00),(3,'Mary Johnson',600.00);
SELECT AVG(Donation) as AverageDonationPerDonor FROM Donors;
What is the maximum age of employees who have not completed diversity and inclusion training?
CREATE TABLE Employees (EmployeeID INT,Age INT,DiversityTraining BOOLEAN); INSERT INTO Employees (EmployeeID,Age,DiversityTraining) VALUES (1,30,true),(2,35,false),(3,40,true),(4,45,false),(5,50,false);
SELECT MAX(Age) FROM Employees WHERE DiversityTraining = false;
What is the difference in labor cost between factories in Thailand that use organic cotton and those that use conventional cotton?
CREATE TABLE factory_thailand (factory VARCHAR(255),country VARCHAR(255),material VARCHAR(255),labor_cost DECIMAL(5,2)); INSERT INTO factory_thailand (factory,country,material,labor_cost) VALUES ('Factory1','Thailand','organic cotton',5.00),('Factory2','Thailand','conventional cotton',4.75),('Factory3','Thailand','organic cotton',5.25),('Factory4','Thailand','conventional cotton',4.50);
SELECT material, AVG(labor_cost) AS avg_labor_cost, MIN(labor_cost) AS min_labor_cost, MAX(labor_cost) AS max_labor_cost FROM factory_thailand WHERE country = 'Thailand' GROUP BY material;
How many eco-friendly hotels are in Australia?
CREATE TABLE hotels (id INT,name TEXT,country TEXT,eco_friendly BOOLEAN); INSERT INTO hotels (id,name,country,eco_friendly) VALUES (1,'Eco-Hotel Sydney','Australia',true),(2,'In-City Hotel Melbourne','Australia',false),(3,'Eco-Retreat Byron Bay','Australia',true);
SELECT COUNT(*) FROM hotels WHERE country = 'Australia' AND eco_friendly = true;
What is the average number of streams per artist in 2019?
CREATE TABLE Streams (artist_name VARCHAR(50),year INT,streams INT); INSERT INTO Streams (artist_name,year,streams) VALUES ('Taylor Swift',2019,10000000),('Drake',2019,12000000),('BTS',2019,15000000),('Billie Eilish',2019,8000000);
SELECT AVG(streams) FROM Streams WHERE year = 2019;
Who is the director with the most number of movies produced in the African continent?
CREATE TABLE directors (id INT,name VARCHAR(255),gender VARCHAR(8)); CREATE TABLE movies_directors (movie_id INT,director_id INT,PRIMARY KEY (movie_id,director_id),FOREIGN KEY (movie_id) REFERENCES movies(id),FOREIGN KEY (director_id) REFERENCES directors(id)); CREATE TABLE movies (id INT,title VARCHAR(255),production_country VARCHAR(64),PRIMARY KEY (id)); INSERT INTO directors (id,name,gender) VALUES (1,'Director1','Male'),(2,'Director2','Female'),(3,'Director3','Male'); INSERT INTO movies_directors (movie_id,director_id) VALUES (1,1),(1,2),(2,1),(3,3); INSERT INTO movies (id,title,production_country) VALUES (1,'Movie1','Nigeria'),(2,'Movie2','Egypt'),(3,'Movie3','South Africa');
SELECT d.name, COUNT(md.movie_id) AS num_movies FROM directors d INNER JOIN movies_directors md ON d.id = md.director_id INNER JOIN movies m ON md.movie_id = m.id WHERE m.production_country IN ('Nigeria', 'Egypt', 'South Africa', 'Kenya', 'Tunisia') GROUP BY d.name ORDER BY num_movies DESC LIMIT 1;
Update the 'amount' for 'Project A' to '600000'
CREATE TABLE climate_finance (project_name TEXT,location TEXT,amount INTEGER); INSERT INTO climate_finance (project_name,location,amount) VALUES ('Project A','Asia',500000),('Project B','Europe',300000);
UPDATE climate_finance SET amount = 600000 WHERE project_name = 'Project A';
What was the average number of streams per day for each song?
CREATE TABLE Songs (id INT,artist_id INT,title VARCHAR(50)); CREATE TABLE Streams (id INT,song_id INT,date DATE,streams INT); INSERT INTO Songs (id,artist_id,title) VALUES (1,1,'Shake it Off'),(2,1,'Blank Space'),(3,2,'Humble'),(4,2,'DNA'); INSERT INTO Streams (id,song_id,date,streams) VALUES (1,1,'2022-01-01',1000),(2,1,'2022-01-02',1500),(3,2,'2022-01-01',2000),(4,2,'2022-01-02',2500),(5,3,'2022-01-01',3000),(6,3,'2022-01-02',3500),(7,4,'2022-01-01',4000),(8,4,'2022-01-02',4500);
SELECT s.title, AVG(s.streams/2) as avg_streams_per_day FROM Songs s JOIN Streams st ON s.id = st.song_id WHERE st.date BETWEEN '2022-01-01' AND '2022-01-31' GROUP BY s.title;
Which categories have an average sustainability score below 80?
CREATE TABLE category_scores (id INT PRIMARY KEY,category VARCHAR(255),sustainability_score INT); INSERT INTO category_scores (id,category,sustainability_score) VALUES (1,'Trousers',75); INSERT INTO category_scores (id,category,sustainability_score) VALUES (2,'Jackets',85);
SELECT category, AVG(sustainability_score) as avg_sustainability_score FROM category_scores GROUP BY category HAVING AVG(sustainability_score) < 80;
What is the minimum depth of any trench in the Arctic Ocean?
CREATE TABLE oceanography (id INT,location VARCHAR(255),depth INT); INSERT INTO oceanography (id,location,depth) VALUES (1,'Eurasian Basin',4600);
SELECT MIN(depth) FROM oceanography WHERE location = 'Eurasian Basin';
List the total marine life research data records for each researcher in descending order.
CREATE TABLE MarineLifeData (id INT,researcher VARCHAR(30),species VARCHAR(50)); INSERT INTO MarineLifeData (id,researcher,species) VALUES (1,'Alice','Coral'),(2,'Bob','Whale Shark'),(3,'Alice','Starfish'),(4,'Bob','Dolphin');
SELECT researcher, COUNT(*) as total_records FROM MarineLifeData GROUP BY researcher ORDER BY total_records DESC;
Delete all comments with a score less than 0.
CREATE TABLE posts (id INT PRIMARY KEY,title TEXT,content TEXT); CREATE TABLE comments (id INT PRIMARY KEY,post_id INT,content TEXT,score INT); INSERT INTO posts (id,title,content) VALUES (1,'Post 1','Content 1'),(2,'Post 2','Content 2'); INSERT INTO comments (id,post_id,content,score) VALUES (1,1,'Comment 1',5),(2,1,'Comment 2',-3),(3,2,'Comment 3',0);
DELETE FROM comments WHERE score < 0;
What is the name and ID of the most resilient bridge in the 'West Coast' region, based on the 'resilience_score'?
CREATE TABLE bridges (id INT,name TEXT,region TEXT,resilience_score FLOAT); INSERT INTO bridges (id,name,region,resilience_score) VALUES (1,'Golden Gate Bridge','West Coast',85.2),(2,'Brooklyn Bridge','East Coast',76.3),(3,'Bay Bridge','West Coast',90.1);
SELECT name, id FROM bridges WHERE region = 'West Coast' AND resilience_score = (SELECT MAX(resilience_score) FROM bridges WHERE region = 'West Coast')
List all military innovation projects conducted by the UK
CREATE TABLE military_innovation (country VARCHAR(255),project_name VARCHAR(255)); INSERT INTO military_innovation (country,project_name) VALUES ('UK','Project A'),('USA','Project B'),('UK','Project C'),('Germany','Project D');
SELECT project_name FROM military_innovation WHERE country = 'UK';
What is the cultural competency training completion rate for community health workers?
CREATE TABLE CulturalCompetencyTraining (WorkerID INT,Completion BIT); INSERT INTO CulturalCompetencyTraining (WorkerID,Completion) VALUES (1,1),(2,0),(3,1),(4,1);
SELECT COUNT(CASE WHEN Completion = 1 THEN 1 END) * 100.0 / COUNT(*) as CompletionRate FROM CulturalCompetencyTraining;
Find the number of articles on 'climate_change' in 'recent_news' that do not cite 'scientific_sources'.
CREATE TABLE recent_news (title VARCHAR(255),topic VARCHAR(255),has_scientific_sources BOOLEAN);
SELECT COUNT(*) FROM recent_news WHERE topic = 'climate_change' AND has_scientific_sources = FALSE;
What is the maximum speed for vessels in the last 30 days?
CREATE TABLE Vessels (VesselID varchar(10),Speed int); CREATE TABLE VesselInspections (InspectionID int,VesselID varchar(10),InspectionDate date); INSERT INTO Vessels (VesselID,Speed) VALUES ('VesselI',25),('VesselJ',30); INSERT INTO VesselInspections (InspectionID,VesselID,InspectionDate) VALUES (1,'VesselI','2021-07-01'),(2,'VesselJ','2021-06-15');
SELECT MAX(Speed) FROM Vessels JOIN VesselInspections ON Vessels.VesselID = VesselInspections.VesselID WHERE VesselInspections.InspectionDate > DATEADD(day, -30, GETDATE());
Who are the top 5 players with the highest level in the 'MMORPG' category?
CREATE TABLE PlayerLevel (PlayerID int,PlayerName varchar(50),Game varchar(50),Level int); INSERT INTO PlayerLevel (PlayerID,PlayerName,Game,Level) VALUES (1,'Player1','GameA',60),(2,'Player2','GameB',75),(3,'Player3','GameA',85),(4,'Player4','GameC',65),(5,'Player5','GameA',90),(6,'Player1','GameB',80),(7,'Player2','GameA',70);
SELECT PlayerName, AVG(Level) as AvgLevel FROM PlayerLevel WHERE Game = 'GameA' GROUP BY PlayerName ORDER BY AvgLevel DESC LIMIT 5;
Calculate the average speed of electric cars in 'Oslo'
CREATE TABLE public.vehicles (id INT,type VARCHAR(20),city VARCHAR(20),speed FLOAT); INSERT INTO public.vehicles (id,type,city,speed) VALUES (1,'electric_car','Oslo',65.0),(2,'conventional_car','Oslo',55.0),(3,'autonomous_bus','Oslo',45.0);
SELECT AVG(speed) FROM public.vehicles WHERE type = 'electric_car' AND city = 'Oslo';
What is the average number of followers for users who posted at least 3 times with the hashtag "#travel" in the "user_posts" table?
CREATE TABLE user_profiles (id INT,followers INT); INSERT INTO user_profiles (id,followers) VALUES (1,1000),(2,2000),(3,3000); CREATE TABLE user_posts (user_id INT,post_id INT,hashtags VARCHAR(255)); INSERT INTO user_posts (user_id,post_id,hashtags) VALUES (1,1,'#travel'),(1,2,'#nature'),(2,3,'#travel'),(2,4,'#travel'),(3,5,'#nature');
SELECT AVG(fp.followers) FROM user_profiles fp JOIN user_posts up ON fp.id = up.user_id WHERE up.hashtags LIKE '%#travel%' GROUP BY up.user_id HAVING COUNT(up.post_id) >= 3;
List the programs that have both online and offline volunteer opportunities.
CREATE TABLE Programs (ProgramID INT,ProgramName TEXT,Online BOOLEAN,Offline BOOLEAN); INSERT INTO Programs (ProgramID,ProgramName,Online,Offline) VALUES (1,'Education',TRUE,TRUE),(2,'Health',FALSE,TRUE);
SELECT ProgramName FROM Programs WHERE Online = TRUE AND Offline = TRUE;
How many auto shows took place in the USA in 2021 and 2022?
CREATE TABLE shows_by_year (id INT,name VARCHAR(50),location VARCHAR(50),year INT); INSERT INTO shows_by_year VALUES (1,'Chicago Auto Show','USA',2021); INSERT INTO shows_by_year VALUES (2,'Detroit Auto Show','USA',2022);
SELECT location, COUNT(*) FROM shows_by_year WHERE location = 'USA' AND year IN (2021, 2022) GROUP BY location;
What is the number of marine species in the top 3 deepest marine protected areas?
CREATE TABLE marine_protected_areas (area_name TEXT,max_depth INTEGER,num_species INTEGER); INSERT INTO marine_protected_areas (area_name,max_depth,num_species) VALUES ('Sargasso Sea',7000,2000),('Java Trench',8000,3000),('Mariana Trench',10000,4000),('Tonga Trench',10600,5000),('Molucca Deep',9100,6000);
SELECT SUM(num_species) FROM (SELECT num_species FROM marine_protected_areas ORDER BY max_depth DESC LIMIT 3) AS top_3_deepest;
What are the maximum and minimum production volumes for each product manufactured in India, and what is the average production volume?
CREATE TABLE product (id INT,name VARCHAR(255),manufacturer_country VARCHAR(255),production_volume INT); INSERT INTO product (id,name,manufacturer_country,production_volume) VALUES (1,'Product A','India',100),(2,'Product B','India',150),(3,'Product C','Mexico',75);
SELECT id, name, MAX(production_volume) as max_volume, MIN(production_volume) as min_volume, AVG(production_volume) as avg_volume FROM product WHERE manufacturer_country = 'India' GROUP BY id;
What is the maximum size of marine protected areas in the Pacific Ocean?
CREATE TABLE marine_protected_areas (name VARCHAR(255),area_id INT,depth FLOAT,size INT,country VARCHAR(255)); INSERT INTO marine_protected_areas (name,area_id,depth,size,country) VALUES ('Great Barrier Reef Marine Park',17,50,3444000,'Australia'),('Papahānaumokuākea Marine National Monument',18,0,36000000,'USA');
SELECT MAX(size) FROM marine_protected_areas WHERE country = 'Pacific Ocean';
List the causes that received donations from donors with the email domain 'yahoo.com', and show the total donation amounts for each cause. Join the donors, donations, and causes tables.
CREATE TABLE donors (id INT,name VARCHAR(255),email VARCHAR(255)); INSERT INTO donors (id,name,email) VALUES (1,'John Doe','john.doe@gmail.com'),(2,'Jane Smith','jane.smith@yahoo.com'),(3,'Alice Johnson','alice.johnson@hotmail.com'); CREATE TABLE donations (id INT,donor_id INT,cause_id INT,amount DECIMAL(10,2)); INSERT INTO donations (id,donor_id,cause_id,amount) VALUES (1,1,1,500),(2,1,2,250),(3,2,2,750),(4,3,1,1000); CREATE TABLE causes (id INT,name VARCHAR(255)); INSERT INTO causes (id,name) VALUES (1,'Climate Change'),(2,'Human Rights'),(3,'Poverty Reduction');
SELECT c.name, SUM(donations.amount) as total_donation FROM donors d JOIN donations ON d.id = donations.donor_id JOIN causes ON donations.cause_id = causes.id WHERE d.email LIKE '%@yahoo.com' GROUP BY c.name;
What is the average number of research grants awarded to faculty members in the School of Computer Science?
CREATE TABLE research_grants (id INT,year INT,faculty_name VARCHAR(50),faculty_department VARCHAR(50)); INSERT INTO research_grants (id,year,faculty_name,faculty_department) VALUES (1,2019,'Jose Hernandez','School of Computer Science'),(2,2020,'Fatima Lopez','School of Computer Science'),(3,2018,'Hong Kim','School of Engineering');
SELECT AVG(cnt) FROM (SELECT COUNT(*) AS cnt FROM research_grants WHERE faculty_department LIKE '%Computer Science%' GROUP BY year) AS subquery;
Find hotels that have a higher average rating than the average booking price
CREATE TABLE hotel_bookings (hotel_id INT,user_id INT,booking_date DATE,price DECIMAL(5,2)); INSERT INTO hotel_bookings (hotel_id,user_id,booking_date,price) VALUES (1,23,'2022-01-01',120.00),(2,45,'2022-01-05',250.00); CREATE TABLE hotel_reviews (review_id INT,hotel_id INT,user_id INT,rating INT,review_date DATE); INSERT INTO hotel_reviews (review_id,hotel_id,user_id,rating,review_date) VALUES (1,1,23,4,'2022-01-03'),(2,2,45,5,'2022-01-06');
SELECT hotel_id FROM hotel_reviews WHERE rating > (SELECT AVG(price) FROM hotel_bookings);
How many bicycles were repaired in 'subway' stations in October 2021?
CREATE TABLE public.station (station_id SERIAL PRIMARY KEY,station_name VARCHAR(50),route_type VARCHAR(20)); INSERT INTO public.station (station_name,route_type) VALUES ('Station A','subway'),('Station B','subway'); CREATE TABLE public.maintenance (maintenance_id SERIAL PRIMARY KEY,maintenance_type VARCHAR(20),maintenance_date DATE,station_id INTEGER,FOREIGN KEY (station_id) REFERENCES public.station(station_id)); INSERT INTO public.maintenance (maintenance_type,maintenance_date,station_id) VALUES ('bicycle repair','2021-10-03',1),('bicycle repair','2021-10-15',2);
SELECT COUNT(*) FROM public.maintenance WHERE maintenance_type = 'bicycle repair' AND maintenance_date >= '2021-10-01' AND maintenance_date <= '2021-10-31' AND station_id IN (SELECT station_id FROM public.station WHERE route_type = 'subway')
Determine the average depth of marine life research stations in each ocean and their total number
CREATE TABLE marine_life_research_stations (station_id INT,station_name TEXT,depth FLOAT,ocean TEXT); INSERT INTO marine_life_research_stations (station_id,station_name,depth,ocean) VALUES (1,'Station G',2000.1,'Arctic'),(2,'Station H',3500.5,'Atlantic'),(3,'Station I',1200.7,'Pacific'),(4,'Station J',2800.3,'Indian');
SELECT ocean, AVG(depth) AS avg_depth, COUNT(*) AS total_stations FROM marine_life_research_stations GROUP BY ocean;
What is the most common mode of transportation for electric vehicles?
CREATE TABLE ElectricVehicleTransportation (EVID INT,Mode VARCHAR(50),Distance DECIMAL(5,2));
SELECT Mode, COUNT(*) AS Frequency FROM ElectricVehicleTransportation GROUP BY Mode ORDER BY Frequency DESC LIMIT 1;
Find the total revenue of Italian restaurants
CREATE TABLE restaurant_sales (id INT,restaurant_name VARCHAR(255),cuisine VARCHAR(255),revenue INT); INSERT INTO restaurant_sales (id,restaurant_name,cuisine,revenue) VALUES (1,'Pizzeria La Rosa','Italian',35000); INSERT INTO restaurant_sales (id,restaurant_name,cuisine,revenue) VALUES (2,'Sushi House','Japanese',40000);
SELECT cuisine, SUM(revenue) FROM restaurant_sales WHERE cuisine = 'Italian';
What is the name and city of all students who received accommodations in the past year?
CREATE TABLE Students (StudentID INT,FirstName VARCHAR(50),LastName VARCHAR(50),City VARCHAR(50)); INSERT INTO Students (StudentID,FirstName,LastName,City) VALUES (1,'John','Doe','New York'); INSERT INTO Students (StudentID,FirstName,LastName,City) VALUES (2,'Jane','Doe','Los Angeles'); CREATE TABLE Accommodations (AccommodationID INT,StudentID INT,Date DATE); INSERT INTO Accommodations (AccommodationID,StudentID,Date) VALUES (1,1,'2021-09-01'); INSERT INTO Accommodations (AccommodationID,StudentID,Date) VALUES (2,2,'2021-10-15');
SELECT Students.FirstName, Students.LastName, Students.City FROM Students INNER JOIN Accommodations ON Students.StudentID = Accommodations.StudentID WHERE Accommodations.Date BETWEEN DATEADD(year, -1, GETDATE()) AND GETDATE();
What is the total number of emergency calls by category in Dallas?
CREATE TABLE emergency_calls (id INT,category VARCHAR(255),city VARCHAR(255)); INSERT INTO emergency_calls (id,category,city) VALUES (1,'Medical','Dallas'),(2,'Fire','Dallas'),(3,'Police','Dallas');
SELECT SUM(id) as total, category FROM emergency_calls WHERE city = 'Dallas' GROUP BY category;
Find the attorney with the highest billing rate in the 'billing' table?
CREATE TABLE billing (attorney_id INT,client_id INT,hours FLOAT,rate FLOAT); INSERT INTO billing (attorney_id,client_id,hours,rate) VALUES (1,101,10,300),(2,102,8,350),(3,103,12,250);
SELECT attorney_id, MAX(rate) FROM billing;
Which model has the lowest explainability score in the 'explainable_ai' table?
CREATE TABLE explainable_ai (model_name TEXT,explainability_score INTEGER); INSERT INTO explainable_ai (model_name,explainability_score) VALUES ('modelA',65),('modelB',72),('modelC',68);
SELECT model_name, explainability_score FROM explainable_ai WHERE explainability_score = (SELECT MIN(explainability_score) FROM explainable_ai);
Insert a new subscriber for the 'Broadband' service in the 'Urban' region with a revenue of 75.00 in Q1 of 2022.
CREATE TABLE Subscribers (subscriber_id INT,service VARCHAR(20),region VARCHAR(20),revenue FLOAT,payment_date DATE);
INSERT INTO Subscribers (subscriber_id, service, region, revenue, payment_date) VALUES (5, 'Broadband', 'Urban', 75.00, '2022-01-01');
What are the top 5 African countries with the most investment in ethical AI in the past 3 years?
CREATE TABLE AIInvestments (InvestmentID INT,Country TEXT,Amount FLOAT,InvestmentDate DATE); INSERT INTO AIInvestments (InvestmentID,Country,Amount,InvestmentDate) VALUES (1,'Nigeria',500000,'2020-01-01'); INSERT INTO AIInvestments (InvestmentID,Country,Amount,InvestmentDate) VALUES (2,'South Africa',700000,'2019-01-01'); INSERT INTO AIInvestments (InvestmentID,Country,Amount,InvestmentDate) VALUES (3,'Egypt',600000,'2018-01-01');
SELECT Country, SUM(Amount) as TotalInvestment FROM AIInvestments WHERE InvestmentDate >= (SELECT DATEADD(year, -3, GETDATE())) AND Country IN ('Nigeria', 'South Africa', 'Egypt', 'Kenya', 'Morocco') GROUP BY Country ORDER BY TotalInvestment DESC LIMIT 5;
What are the sales figures for cruelty-free cosmetic products in Germany?
CREATE TABLE products (product_id INT,product_name TEXT,sales FLOAT,country TEXT); INSERT INTO products (product_id,product_name,sales,country) VALUES (1,'Lipstick A',5000,'USA'),(2,'Eye Shadow B',3500,'Canada'),(3,'Mascara C',4200,'Germany'),(4,'Foundation D',6000,'USA'),(5,'Blush E',2800,'Mexico'),(6,'Moisturizer F',7000,'Germany'); CREATE TABLE certification (product_id INT,certified TEXT); INSERT INTO certification (product_id,certified) VALUES (1,'cruelty-free'),(2,'vegan'),(3,'cruelty-free'),(4,'cruelty-free'),(5,'organic'),(6,'cruelty-free');
SELECT p.sales FROM products p JOIN certification c ON p.product_id = c.product_id WHERE c.certified = 'cruelty-free' AND p.country = 'Germany';
What is the minimum salary of any tenured professor in the College of Science?
CREATE TABLE professors(id INT,name VARCHAR(50),department VARCHAR(50),salary FLOAT,tenure VARCHAR(10)); INSERT INTO professors VALUES (1,'Alice','Science',90000.0,'Yes'); INSERT INTO professors VALUES (2,'Bob','Science',95000.0,'No'); INSERT INTO professors VALUES (3,'Charlie','Science',85000.0,'Yes');
SELECT MIN(salary) FROM professors WHERE department = 'Science' AND tenure = 'Yes';
Determine the number of circular supply chain partners for each product in the inventory
CREATE TABLE product_inventory (product_id INT,partner_id INT,partner_type TEXT);
SELECT product_id, COUNT(DISTINCT partner_id) as circular_supply_chain_partners FROM product_inventory WHERE partner_type = 'Circular' GROUP BY product_id;
find the average retail price of all garments that have been sold in the 'Fall' season
CREATE TABLE Seasons (season VARCHAR(10)); INSERT INTO Seasons (season) VALUES ('Spring'),('Summer'),('Fall'),('Winter'); CREATE TABLE Garments (garment_id INT,price DECIMAL(5,2),season VARCHAR(10)); INSERT INTO Garments (garment_id,price,season) VALUES (1,50.00,'Fall'),(2,75.00,'Fall'),(3,30.00,'Spring');
SELECT AVG(price) FROM Garments WHERE season IN (SELECT season FROM Seasons WHERE season = 'Fall');
Count the number of virtual tours conducted in Asia in the last month, grouped by week.
CREATE TABLE virtual_tours (id INT,location TEXT,tour_date DATE); INSERT INTO virtual_tours (id,location,tour_date) VALUES (1,'Tokyo','2022-01-01'),(2,'Seoul','2022-01-10'),(3,'Singapore','2022-01-15');
SELECT WEEK(tour_date) AS week, COUNT(*) FROM virtual_tours WHERE location LIKE 'Asia%' AND tour_date >= DATE_SUB(NOW(), INTERVAL 1 MONTH) GROUP BY week;
Which agricultural innovation initiatives were implemented in a specific country and their budgets in the 'agricultural_innovation' table?
CREATE TABLE agricultural_innovation (id INT,initiative_name VARCHAR(50),country VARCHAR(50),year INT); INSERT INTO agricultural_innovation (id,initiative_name,country,year) VALUES (1,'Precision Agriculture','Canada',2018),(2,'Drip Irrigation','Mexico',2019),(3,'Vertical Farming','US',2020);
SELECT initiative_name, budget FROM agricultural_innovation WHERE country = 'Mexico';
Update the vessel "Golden Wave" with id 104 to have a gross tonnage of 2000
CREATE TABLE vessels (id INT,name TEXT,gross_tonnage INT);
UPDATE vessels SET gross_tonnage = 2000 WHERE id = 104 AND name = 'Golden Wave';
Retrieve the previous defense diplomacy event date for each defense diplomacy event in Russia?
CREATE TABLE defense_diplomacy (id INT,event VARCHAR,country VARCHAR,partner VARCHAR,date DATE,PRIMARY KEY (id)); INSERT INTO defense_diplomacy (id,event,country,partner,date) VALUES (1,'Joint Military Exercise','Russia','China','2020-09-01'),(2,'Military Agreement','Russia','India','2021-02-15');
SELECT event, country, partner, date, LAG(date) OVER (PARTITION BY country ORDER BY date) as previous_event_date FROM defense_diplomacy WHERE country = 'Russia';
What is the average length of songs in the 'pop' genre?
CREATE TABLE songs (id INT,title TEXT,length FLOAT,genre TEXT); INSERT INTO songs (id,title,length,genre) VALUES (1,'Song1',180.5,'pop'),(2,'Song2',230.3,'rock'),(3,'Song3',150.2,'pop');
SELECT AVG(length) FROM songs WHERE genre = 'pop';
What is the total water usage in California and New York?
CREATE TABLE water_usage (state VARCHAR(20),usage INT); INSERT INTO water_usage (state,usage) VALUES ('California',12000),('New York',8000);
SELECT SUM(usage) FROM water_usage WHERE state IN ('California', 'New York');
Get products that are not present in 'products_sustainability' table
CREATE TABLE products (id INT,name TEXT,category TEXT);CREATE TABLE products_sustainability (id INT,name TEXT,sustainable_label TEXT);
SELECT * FROM products EXCEPT SELECT * FROM products_sustainability;
Which companies have provided launch services for space missions in the last 10 years?
CREATE TABLE companies (company_id INT,company_name VARCHAR(255),founded_year INT); INSERT INTO companies (company_id,company_name,founded_year) VALUES (1,'SpaceX',2002),(2,'Blue Origin',2000); CREATE TABLE launch_services (service_id INT,mission_id INT,company_id INT,launch_date DATE); INSERT INTO launch_services (service_id,mission_id,company_id,launch_date) VALUES (1,1,1,'2022-01-01'),(2,2,2,'2021-06-20');
SELECT DISTINCT company_name FROM launch_services JOIN companies ON launch_services.company_id = companies.company_id WHERE launch_date >= DATEADD(year, -10, GETDATE());
What is the name and age of offenders from Florida?
CREATE TABLE offenders (id INT,name VARCHAR(50),age INT,state VARCHAR(2));
SELECT name, age FROM offenders WHERE state = 'FL';
Calculate the number of visitors per month for each exhibition
CREATE TABLE visitors (visitor_id INT PRIMARY KEY,exhibition_id INT,visit_date DATE);
SELECT exhibition_id, DATE_FORMAT(visit_date, '%Y-%m') as visit_month, COUNT(visitor_id) as visitor_count FROM visitors GROUP BY exhibition_id, visit_month;
Which organizations have no technology accessibility limitations in Oceania?
CREATE TABLE org_access_limit (org_id INT,region TEXT,accessibility INT); INSERT INTO org_access_limit (org_id,region,accessibility) VALUES (1,'Oceania',5),(2,'Europe',3),(3,'Oceania',5);
SELECT org_id FROM org_access_limit WHERE region = 'Oceania' AND accessibility = 5;
Get the average hourly wage for construction workers in the 10 most populous states for the year 2020
CREATE TABLE labor_statistics (state VARCHAR(2),year INT,total_workers INT,avg_hourly_wage DECIMAL(5,2),total_payroll DECIMAL(10,2)); INSERT INTO labor_statistics (state,year,total_workers,avg_hourly_wage,total_payroll) VALUES ('CA',2020,500000,30.50,762500000),('TX',2020,450000,29.80,654750000),('NY',2020,400000,31.20,624000000),('FL',2020,350000,27.90,531500000),('PA',2020,300000,28.60,498000000),('IL',2020,250000,27.30,432500000),('OH',2020,225000,26.80,403500000),('MI',2020,200000,28.10,382000000),('NJ',2020,175000,30.10,345750000),('NC',2020,150000,25.40,280500000);
SELECT state, AVG(avg_hourly_wage) FROM labor_statistics WHERE year = 2020 GROUP BY state ORDER BY total_workers DESC LIMIT 10;
What is the average value of defense contracts awarded to companies in Germany in H2 2020?
CREATE TABLE Defense_Contracts (contract_id INT,company_name TEXT,country TEXT,award_amount FLOAT,half INT,year INT); INSERT INTO Defense_Contracts (contract_id,company_name,country,award_amount,half,year) VALUES (1,'German Manufacturing Inc','Germany',8000000,2,2020),(2,'Berlin Defense Systems','Germany',9000000,2,2020);
SELECT AVG(award_amount) FROM Defense_Contracts WHERE country = 'Germany' AND half = 2 AND year = 2020;
What is the total number of marine protected areas in the Caribbean region?'
CREATE TABLE marine_protected_areas (name TEXT,region TEXT); INSERT INTO marine_protected_areas (name,region) VALUES ('Bonaire National Marine Park','Caribbean'); INSERT INTO marine_protected_areas (name,region) VALUES ('Montego Bay Marine Park','Caribbean');
SELECT region, COUNT(*) FROM marine_protected_areas WHERE region = 'Caribbean' GROUP BY region;
What is the total production quantity of Scandium and Terbium combined for each year, for companies located in the Europe region?
CREATE TABLE Producers (ProducerID INT PRIMARY KEY,Name TEXT,ProductionYear INT,RareEarth TEXT,Quantity INT,Location TEXT);
SELECT ProductionYear, SUM(Quantity) FROM Producers WHERE (RareEarth = 'Scandium' OR RareEarth = 'Terbium') AND Location LIKE '%Europe%' GROUP BY ProductionYear ORDER BY ProductionYear ASC;
What is the minimum age of members in unions with a 'construction' industry classification?
CREATE TABLE unions (id INT,name VARCHAR(255),industry VARCHAR(255),member_age INT); INSERT INTO unions (id,name,industry,member_age) VALUES (1,'Union A','construction',30),(2,'Union B','construction',35),(3,'Union C','construction',40);
SELECT MIN(member_age) FROM unions WHERE industry = 'construction';
What is the total amount of funding allocated to criminal justice reform initiatives in the last fiscal year?
CREATE TABLE criminal_justice_reform_funding (id INT,initiative_name VARCHAR(50),funding_amount DECIMAL(10,2),fiscal_year INT);
SELECT SUM(funding_amount) FROM criminal_justice_reform_funding WHERE fiscal_year = EXTRACT(YEAR FROM CURRENT_DATE - INTERVAL 1 YEAR) AND initiative_name IS NOT NULL;
How many small-scale farmers in Canada and Mexico are part of food justice initiatives?
CREATE TABLE small_scale_farmers (id INT,country VARCHAR(2),initiative_id INT); CREATE TABLE food_justice_initiatives (id INT,name VARCHAR(50)); INSERT INTO small_scale_farmers (id,country,initiative_id) VALUES (1,'CA',101),(2,'MX',102),(3,'CA',103); INSERT INTO food_justice_initiatives (id,name) VALUES (101,'Just Food'),(102,'Food Secure Canada'),(103,'Growing Power');
SELECT COUNT(DISTINCT small_scale_farmers.id) FROM small_scale_farmers INNER JOIN food_justice_initiatives ON small_scale_farmers.initiative_id = food_justice_initiatives.id WHERE small_scale_farmers.country IN ('CA', 'MX');
Find the average caloric content of "fish" dishes in the "seafood_menu" table that are also included in the "low_sodium" view
CREATE TABLE seafood_menu (menu_id INT,dish_name VARCHAR(50),dish_category VARCHAR(50),caloric_content INT); INSERT INTO seafood_menu (menu_id,dish_name,dish_category,caloric_content) VALUES (1,'Grilled Salmon','Fish',350); INSERT INTO seafood_menu (menu_id,dish_name,dish_category,caloric_content) VALUES (2,'Shrimp Cocktail','Shellfish',150); CREATE VIEW low_sodium AS SELECT menu_id FROM seafood_menu WHERE caloric_content < 400;
SELECT AVG(caloric_content) FROM seafood_menu WHERE dish_category = 'Fish' AND menu_id IN (SELECT menu_id FROM low_sodium);
Which train routes have had delays exceeding 15 minutes?
CREATE TABLE routes (id INT,name TEXT,delayed BOOLEAN); INSERT INTO routes (id,name,delayed) VALUES (1,'Route1',TRUE),(2,'Route2',FALSE),(3,'Route3',TRUE); CREATE TABLE delays (id INT,route_id INT,delay_time TIME); INSERT INTO delays (id,route_id,delay_time) VALUES (1,1,'00:20:00'),(2,2,'00:10:00'),(3,3,'00:18:00');
SELECT r.name FROM routes r JOIN delays d ON r.id = d.route_id WHERE d.delay_time > '00:15:00';
What are the names and launch dates of satellites manufactured by SpaceTech Inc. and launched before 2010?
CREATE TABLE Satellites (manufacturer VARCHAR(255),name VARCHAR(255),launch_date DATE); INSERT INTO Satellites (manufacturer,name,launch_date) VALUES ('SpaceTech Inc.','Sat1','2005-01-01'); INSERT INTO Satellites (manufacturer,name,launch_date) VALUES ('SpaceTech Inc.','Sat2','2008-05-15');
SELECT name, launch_date FROM Satellites WHERE manufacturer = 'SpaceTech Inc.' AND launch_date < '2010-01-01';
What is the average delay for vessels arriving at ports in the United States?
CREATE TABLE vessel_arrivals (vessel_id INT,arrival_date DATE,arrival_delay INT,port VARCHAR(255));
SELECT AVG(arrival_delay) FROM vessel_arrivals WHERE port LIKE '%United States%';
Which cybersecurity vulnerabilities were discovered in 'Software X' in the last 2 years?
CREATE TABLE if not exists cybersecurity_vulnerabilities (software VARCHAR(50),year INT,vulnerability_name VARCHAR(50),description TEXT);
SELECT software, vulnerability_name, description FROM cybersecurity_vulnerabilities WHERE software = 'Software X' AND year >= 2020;
Update records of sites with high visitor impact on cultural heritage values
CREATE TABLE sites (id INT,name VARCHAR(50),country VARCHAR(50),visitor_impact INT); INSERT INTO sites (id,name,country,visitor_impact) VALUES (1,'Machu Picchu','Peru',1000000),(2,'Angkor Wat','Cambodia',2000000),(3,'Petra','Jordan',500000)
UPDATE sites SET visitor_impact = visitor_impact * 1.1 WHERE visitor_impact > 500000
What is the total revenue generated from digital museum trends in Africa in H1 2020?
CREATE TABLE DigitalTrends (id INT,region VARCHAR(255),half INT,year INT,revenue DECIMAL(10,2));
SELECT SUM(DigitalTrends.revenue) FROM DigitalTrends WHERE DigitalTrends.region = 'Africa' AND DigitalTrends.half = 1 AND DigitalTrends.year = 2020;
What is the average transaction amount for each customer in the North region, sorted by average transaction amount in descending order?
CREATE TABLE customers (customer_id INT,customer_name VARCHAR(50),region VARCHAR(50)); INSERT INTO customers (customer_id,customer_name,region) VALUES (1,'John Smith','North'),(2,'Jane Doe','South'),(3,'Mike Johnson','North'); CREATE TABLE transactions (transaction_id INT,customer_id INT,amount DECIMAL(10,2)); INSERT INTO transactions (transaction_id,customer_id,amount) VALUES (1,1,100.50),(2,1,200.75),(3,2,50.00),(4,3,300.00),(5,3,400.00);
SELECT c.customer_id, AVG(t.amount) as avg_amount FROM customers c JOIN transactions t ON c.customer_id = t.customer_id WHERE c.region = 'North' GROUP BY c.customer_id ORDER BY avg_amount DESC;
Delete records in the "workforce" table where the "gender" is "Male" and the "department" is "Geology" and the "country" is "Russia" from the past 12 months
CREATE TABLE workforce (id INT,gender VARCHAR(50),department VARCHAR(50),country VARCHAR(50),hire_date DATE); INSERT INTO workforce (id,gender,department,country,hire_date) VALUES (1,'Male','Geology','Russia','2021-05-01'),(2,'Female','Geology','Russia','2020-01-01');
DELETE FROM workforce WHERE gender = 'Male' AND department = 'Geology' AND country = 'Russia' AND hire_date >= DATE_SUB(CURRENT_DATE, INTERVAL 12 MONTH);
What is the maximum number of experiments conducted by a single spacecraft, grouped by organization in the astrobiology_experiments and mission_data tables?
CREATE TABLE astrobiology_experiments (experiment_id INT,name VARCHAR(100),spacecraft VARCHAR(100),launch_date DATE,experiments_conducted INT); CREATE TABLE mission_data (mission_id INT,name VARCHAR(100),organization VARCHAR(100),launch_date DATE,mission_cost FLOAT);
SELECT organization, MAX(experiments_conducted) FROM astrobiology_experiments, mission_data WHERE astrobiology_experiments.launch_date = mission_data.launch_date GROUP BY organization;
What is the earliest and latest delivery time for shipments to Florida from the 'shipments' table?
CREATE TABLE shipments (shipment_id INT,customer_id INT,shipped_date TIMESTAMP,shipped_time TIME,delivered_date TIMESTAMP,delivered_time TIME,status TEXT,delay DECIMAL(3,2));
SELECT MIN(delivered_time) as earliest_delivery_time, MAX(delivered_time) as latest_delivery_time FROM shipments WHERE destination_state = 'Florida';
What is the maximum amount of gold extracted, for mines that are located in the state of Alaska?
CREATE TABLE mine (id INT,name VARCHAR(255),state VARCHAR(255),gold_tons INT); INSERT INTO mine (id,name,state,gold_tons) VALUES (1,'Alaskan Gold Mine','Alaska',700),(2,'California Gold Mine','California',400),(3,'Nevada Silver Mine','Nevada',500);
SELECT MAX(gold_tons) as max_gold_tons FROM mine WHERE state = 'Alaska';
What is the maximum transaction volume for each category in the 'Transactions' table?
CREATE TABLE Transactions (id INT,DApp_id INT,smart_contract_hash VARCHAR(66),volume DECIMAL(18,2),date DATE);
SELECT category, MAX(volume) FROM Transactions JOIN DApps ON Transactions.DApp_id = DApps.id GROUP BY category;
What is the total spending on humanitarian assistance by each organization, and the average number of humanitarian assistance projects per organization, for organizations that have spent more than $10 million, ordered by the average number of projects in descending order?
CREATE TABLE Organizations(OrganizationID INT,OrganizationName TEXT); CREATE TABLE HumanitarianAssistance(ProjectID INT,ProjectName TEXT,OrganizationID INT,Spending FLOAT);
SELECT OrganizationName, SUM(Spending) as TotalSpending, COUNT(ProjectID) as AvgProjectsPerOrg FROM HumanitarianAssistance JOIN Organizations ON HumanitarianAssistance.OrganizationID = Organizations.OrganizationID GROUP BY OrganizationName HAVING TotalSpending > 10000000 ORDER BY AvgProjectsPerOrg DESC;
What is the total revenue generated from postpaid mobile customers in the region 'North'?
CREATE TABLE subscribers (id INT,type VARCHAR(10),region VARCHAR(10)); INSERT INTO subscribers (id,type,region) VALUES (1,'postpaid','North'),(2,'prepaid','North'); CREATE TABLE revenue (id INT,subscriber_id INT,amount DECIMAL(10,2)); INSERT INTO revenue (id,subscriber_id,amount) VALUES (1,1,50.00),(2,2,30.00);
SELECT SUM(revenue.amount) AS total_revenue FROM revenue INNER JOIN subscribers ON revenue.subscriber_id = subscribers.id WHERE subscribers.type = 'postpaid' AND subscribers.region = 'North';
Obtain smart city projects and costs in the CityOfFuture schema
CREATE SCHEMA CityOfFuture; USE CityOfFuture; CREATE TABLE SmartCityProjects (id INT,project_name VARCHAR(100),cost DECIMAL(10,2)); INSERT INTO SmartCityProjects (id,project_name,cost) VALUES (1,'Smart Traffic Management',200000.00),(2,'Smart Public Transportation',400000.00);
SELECT project_name, cost FROM CityOfFuture.SmartCityProjects;
How many days have passed since the last inspection of each water source, sorted by water source and days since inspection?
CREATE TABLE water_sources (id INT,source_name VARCHAR(50),district_id INT,water_volume_cubic_meters INT,last_inspection_date DATE); INSERT INTO water_sources (id,source_name,district_id,water_volume_cubic_meters,last_inspection_date) VALUES (1,'Lake Michigan',1,500000,'2021-06-01'); INSERT INTO water_sources (id,source_name,district_id,water_volume_cubic_meters,last_inspection_date) VALUES (2,'Ohio River',2,600000,'2021-07-15');
SELECT id, source_name, district_id, DATEDIFF(day, last_inspection_date, CURRENT_DATE) as days_since_last_inspection, ROW_NUMBER() OVER (PARTITION BY source_name ORDER BY DATEDIFF(day, last_inspection_date, CURRENT_DATE) DESC) as rank FROM water_sources;
list the top 3 provinces with the highest carbon sequestration in 2019
CREATE TABLE carbon_sequestration (id INT,province VARCHAR(255),sequestration_tons INT,year INT);
SELECT province, SUM(sequestration_tons) as total_sequestration FROM carbon_sequestration GROUP BY province ORDER BY total_sequestration DESC LIMIT 3;
List all the safety protocol violations in factories located in Texas and New York.
CREATE TABLE factories (id INT,name TEXT,location TEXT); INSERT INTO factories (id,name,location) VALUES (1,'Factory A','California'),(2,'Factory B','Texas'),(3,'Factory C','New York'); CREATE TABLE violations (factory_id INT,violation_type TEXT); INSERT INTO violations (factory_id,violation_type) VALUES (2,'Violation X'),(2,'Violation Y'),(3,'Violation Z');
SELECT factory_id, violation_type FROM violations WHERE factory_id IN (SELECT id FROM factories WHERE location IN ('Texas', 'New York'));
What is the average deep-sea pressure at 5000 meters in the Atlantic Ocean?
CREATE TABLE deep_sea_pressure (depth INT,region VARCHAR(20),pressure INT); INSERT INTO deep_sea_pressure (depth,region,pressure) VALUES (5000,'Atlantic Ocean',550); INSERT INTO deep_sea_pressure (depth,region,pressure) VALUES (5000,'Atlantic Ocean',540); INSERT INTO deep_sea_pressure (depth,region,pressure) VALUES (5000,'Atlantic Ocean',560);
SELECT AVG(pressure) FROM deep_sea_pressure WHERE depth = 5000 AND region = 'Atlantic Ocean';
Show the number of asteroids that have been visited by spacecraft
CREATE TABLE asteroids (asteroid_id INT,asteroid_name VARCHAR(50),visited BOOLEAN); INSERT INTO asteroids VALUES (1,'Ceres',true),(2,'Vesta',true),(3,'Eros',true),(4,'Gaspra',false),(5,'Ida',false);
SELECT COUNT(*) as num_visited_asteroids FROM asteroids WHERE visited = true;
What was the total budget for NASA's Mars exploration program in 2020?
CREATE SCHEMA space; CREATE TABLE mars_exploration (budget INT,year INT); INSERT INTO mars_exploration VALUES (5000000,2018),(6000000,2019),(7000000,2020);
SELECT SUM(budget) FROM space.mars_exploration WHERE year = 2020;
What is the minimum donation amount in the arts sector?
CREATE TABLE Donations (DonationID INT,DonationAmount DECIMAL(5,2),DonorID INT,Sector VARCHAR(50));
SELECT MIN(DonationAmount) FROM Donations WHERE Sector = 'Arts';
What is the revenue generated by cultural heritage tours in Italy in 2021?
CREATE TABLE cultural_tours (tour_id INT,name VARCHAR(255),country VARCHAR(255),price FLOAT,year INT,month INT,day INT); INSERT INTO cultural_tours (tour_id,name,country,price,year,month,day) VALUES (1,'Roman Colosseum Tour','Italy',30.5,2021,5,15),(2,'Florence Uffizi Gallery Tour','Italy',25.2,2021,7,20),(3,'Pompeii Tour','Italy',40.0,2021,9,10);
SELECT SUM(price) FROM cultural_tours WHERE country = 'Italy' AND year = 2021;
Calculate the number of funding rounds for companies in the biotech industry, ordered by founding year.
CREATE TABLE funding_rounds(id INT,company_name VARCHAR(50),funding_round INT,year INT); INSERT INTO funding_rounds(id,company_name,funding_round,year) VALUES (1,'CompanyA',1,2010); INSERT INTO funding_rounds(id,company_name,funding_round,year) VALUES (2,'CompanyA',2,2012); INSERT INTO funding_rounds(id,company_name,funding_round,year) VALUES (3,'CompanyB',1,2015); INSERT INTO funding_rounds(id,company_name,funding_round,year) VALUES (4,'CompanyB',2,2017); INSERT INTO funding_rounds(id,company_name,funding_round,year) VALUES (5,'CompanyC',1,2018);
SELECT company_name, COUNT(funding_round) as num_funding_rounds FROM funding_rounds WHERE industry = 'Biotech' GROUP BY company_name ORDER BY MIN(year);
What is the difference in property prices between the most expensive and least expensive property in each city?
CREATE TABLE cities (city_id INT,city_name VARCHAR(255));CREATE TABLE properties (property_id INT,city_id INT,price DECIMAL(10,2)); INSERT INTO cities (city_id,city_name) VALUES (1,'CityA'),(2,'CityB'); INSERT INTO properties (property_id,city_id,price) VALUES (1,1,500000.00),(2,1,700000.00),(3,2,300000.00),(4,2,400000.00);
SELECT city_id, MAX(price) - MIN(price) as price_difference FROM properties GROUP BY city_id;
How many users are from Germany in the Workout table?
CREATE TABLE Workout (user_id INT,workout_duration INT,country VARCHAR(50)); INSERT INTO Workout (user_id,workout_duration,country) VALUES (1,30,'Germany'),(2,40,'USA'),(3,50,'Germany');
SELECT COUNT(*) FROM Workout WHERE country = 'Germany';
What is the percentage of cases in which plea bargains were offered in restorative justice programs in Australia, and how does it differ between states?
CREATE TABLE aus_rj_cases(id INT,state VARCHAR(255),plea_bargain VARCHAR(255));
SELECT state, 100.0*SUM(CASE WHEN plea_bargain = 'Yes' THEN 1 ELSE 0 END)/COUNT(*) AS percentage FROM aus_rj_cases GROUP BY state;
How many test flights did SpaceX perform in 2019?
CREATE TABLE test_flights (id INT,company VARCHAR(50),launch_year INT,test_flight BOOLEAN);
SELECT COUNT(*) FROM test_flights WHERE company = 'SpaceX' AND launch_year = 2019 AND test_flight = TRUE;