instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
What is the total volume of timber harvested in forests in each country?
|
CREATE TABLE forests (id INT,country VARCHAR(50),volume FLOAT); INSERT INTO forests (id,country,volume) VALUES (1,'Indonesia',1200.5),(2,'Brazil',1500.3),(3,'Canada',800.2),(4,'Russia',900.1),(5,'United States',1000.0);
|
SELECT country, SUM(volume) FROM forests GROUP BY country;
|
Show unique drilling permits issued to DEF Oil & Gas in the Gulf of Mexico.
|
CREATE TABLE permits (company VARCHAR(255),region VARCHAR(255),permit_number INT);
|
SELECT DISTINCT permit_number FROM permits WHERE company = 'DEF Oil & Gas' AND region = 'Gulf of Mexico';
|
Who are the top 3 donors by average donation amount in the Education category?
|
CREATE TABLE Donations (DonationID INT,DonorID INT,DonationDate DATE,DonationAmount DECIMAL(10,2),DonationCategory VARCHAR(50)); CREATE TABLE Donors (DonorID INT,DonorName VARCHAR(50),DonorType VARCHAR(50));
|
SELECT DonorName, AVG(DonationAmount) FROM Donations d JOIN Donors don ON d.DonorID = don.DonorID WHERE DonationCategory = 'Education' GROUP BY DonorID, DonorName ORDER BY AVG(DonationAmount) DESC FETCH NEXT 3 ROWS ONLY;
|
List the top 3 most purchased beauty products that contain 'aloe vera' as an ingredient and are vegan-friendly.
|
CREATE TABLE Ingredients (product_id INT,ingredient TEXT); INSERT INTO Ingredients (product_id,ingredient) VALUES (1,'aloe vera'),(2,'almond oil'),(3,'coconut oil'),(4,'aloe vera'),(5,'lavender');
|
SELECT product_id, ingredient FROM Ingredients WHERE ingredient = 'aloe vera' INTERSECT SELECT product_id FROM Products WHERE is_vegan = true LIMIT 3;
|
Which electric vehicle models have the highest sales in Cape Town?
|
CREATE TABLE electric_vehicles (vehicle_id INT,vehicle_model VARCHAR(50),total_sold INT,city VARCHAR(50)); INSERT INTO electric_vehicles (vehicle_id,vehicle_model,total_sold,city) VALUES (1,'Zonda Electric',1500,'Cape Town'),(2,'Rimac Nevera',1000,'Cape Town');
|
SELECT vehicle_model, SUM(total_sold) FROM electric_vehicles WHERE city = 'Cape Town' GROUP BY vehicle_model ORDER BY SUM(total_sold) DESC;
|
Identify the co-owners of properties in Denver with a market value above $500,000.
|
CREATE TABLE denver_prop(id INT,owner1 VARCHAR(20),owner2 VARCHAR(20),market_value INT); INSERT INTO denver_prop VALUES (1,'Eve','Frank',550000),(2,'Grace','Hal',450000);
|
SELECT owner1, owner2 FROM denver_prop WHERE market_value > 500000 AND (owner1 <> owner2);
|
Delete records in the 'military_equipment' table where the 'equipment_type' is 'Artillery' and 'manufactured_year' is before 2000
|
CREATE TABLE military_equipment (equipment_id INT PRIMARY KEY,equipment_type VARCHAR(50),manufactured_year INT,quantity INT,country VARCHAR(50));
|
DELETE FROM military_equipment WHERE equipment_type = 'Artillery' AND manufactured_year < 2000;
|
What is the total revenue per day for the 'bookings' table in the month of August 2022?
|
CREATE TABLE bookings (booking_id INT,booking_date DATE,revenue DECIMAL(10,2)); INSERT INTO bookings (booking_id,booking_date,revenue) VALUES (1,'2022-08-01',100),(2,'2022-08-02',200),(3,'2022-08-03',300);
|
SELECT DATE(booking_date) AS booking_day, SUM(revenue) AS total_revenue FROM bookings WHERE EXTRACT(MONTH FROM booking_date) = 8 GROUP BY booking_day;
|
What is the maximum claim amount for policy number 1002?
|
CREATE TABLE claims (claim_id INT,policy_id INT,claim_amount DECIMAL); INSERT INTO claims (claim_id,policy_id,claim_amount) VALUES (1,1001,2500.00),(2,1002,3000.00),(3,1003,1500.00),(4,1002,3500.00);
|
SELECT MAX(claim_amount) FROM claims WHERE policy_id = 1002;
|
How many volunteers engaged in each program in 2021, grouped by program name?
|
CREATE TABLE Volunteers (VolunteerID int,ProgramName varchar(50),VolunteerDate date); INSERT INTO Volunteers (VolunteerID,ProgramName,VolunteerDate) VALUES (1,'Education','2021-01-01'),(2,'Healthcare','2021-02-01'),(3,'Education','2021-12-25');
|
SELECT ProgramName, COUNT(*) as NumberOfVolunteers FROM Volunteers WHERE YEAR(VolunteerDate) = 2021 GROUP BY ProgramName;
|
Which countries have the lowest teacher professional development budgets per student?
|
CREATE TABLE regions (id INT,name VARCHAR(50),budget INT,country VARCHAR(50)); INSERT INTO regions (id,name,budget,country) VALUES (1,'Northeast',50000,'USA'),(2,'Southeast',60000,'USA'),(3,'East Asia',70000,'China'),(4,'South Asia',40000,'India'); CREATE TABLE pd_budgets (id INT,region_id INT,amount INT,students INT); INSERT INTO pd_budgets (id,region_id,amount,students) VALUES (1,1,40000,2000),(2,2,50000,2500),(3,3,60000,3000),(4,4,30000,1500);
|
SELECT r.country, MIN(pd_budgets.amount/pd_budgets.students) as lowest_budget_per_student FROM regions r JOIN pd_budgets ON r.id = pd_budgets.region_id GROUP BY r.country;
|
What are the names and types of minerals extracted by each company?
|
CREATE TABLE Companies (CompanyID INT,CompanyName VARCHAR(50)); INSERT INTO Companies (CompanyID,CompanyName) VALUES (1,'ABC Mining'),(2,'XYZ Excavations'); CREATE TABLE Minerals (MineralID INT,MineralName VARCHAR(50),CompanyID INT); INSERT INTO Minerals (MineralID,MineralName,CompanyID) VALUES (1,'Gold',1),(2,'Silver',1),(3,'Copper',2),(4,'Iron',2);
|
SELECT CompanyName, MineralName FROM Companies JOIN Minerals ON Companies.CompanyID = Minerals.CompanyID;
|
What is the total billing amount for cases in the 'Criminal' practice area that were won by attorneys with a 'LLM' degree?
|
CREATE TABLE cases (id INT,practice_area VARCHAR(255),billing_amount DECIMAL(10,2),case_outcome VARCHAR(255),attorney_id INT); INSERT INTO cases (id,practice_area,billing_amount,case_outcome,attorney_id) VALUES (1,'Civil',5000.00,'Won',1),(2,'Criminal',3000.00,'Won',2),(3,'Civil',7000.00,'Lost',1),(4,'Civil',6000.00,'Won',3),(5,'Criminal',4000.00,'Lost',2); CREATE TABLE attorneys (id INT,degree VARCHAR(255)); INSERT INTO attorneys (id,degree) VALUES (1,'JD'),(2,'LLM'),(3,'JD'),(4,'BA');
|
SELECT SUM(billing_amount) FROM cases INNER JOIN attorneys ON cases.attorney_id = attorneys.id WHERE cases.practice_area = 'Criminal' AND cases.case_outcome = 'Won' AND attorneys.degree = 'LLM';
|
Update player demographics information
|
CREATE TABLE Players (PlayerID INT PRIMARY KEY,Name VARCHAR(50),Age INT,Gender VARCHAR(10),Country VARCHAR(50)); INSERT INTO Players (PlayerID,Name,Age,Gender,Country) VALUES (1,'Jamal Jackson',25,'Male','United States'); INSERT INTO Players (PlayerID,Name,Age,Gender,Country) VALUES (2,'Sofia Rodriguez',22,'Female','Spain');
|
UPDATE Players SET Age = 23, Gender = 'Non-binary', Country = 'Mexico' WHERE PlayerID = 1;
|
Update the budget for the 'Irrigation System Improvement' project in Rural Kenya to 300000 in 2021.
|
CREATE TABLE RuralInfrastructure (id INT,country VARCHAR(50),project VARCHAR(50),budget FLOAT,year INT); INSERT INTO RuralInfrastructure (id,country,project,budget,year) VALUES (1,'Rural Kenya','Irrigation System Improvement',250000,2021);
|
WITH cte AS (UPDATE RuralInfrastructure SET budget = 300000 WHERE country = 'Rural Kenya' AND project = 'Irrigation System Improvement' AND year = 2021) SELECT * FROM RuralInfrastructure WHERE country = 'Rural Kenya' AND project = 'Irrigation System Improvement' AND year = 2021;
|
Insert a new record into the table 'vessels' with the name 'VesselD', port_id 1, and speed 23.5.
|
CREATE TABLE vessels (id INT,name TEXT,port_id INT,speed FLOAT); INSERT INTO vessels (id,name,port_id,speed) VALUES (1,'VesselA',1,20.5),(2,'VesselB',1,21.3),(3,'VesselC',2,25.0);
|
INSERT INTO vessels (name, port_id, speed) VALUES ('VesselD', 1, 23.5);
|
What is the average environmental impact score for chemicals produced in Brazil?
|
CREATE TABLE environmental_impact (chemical_id INT,environmental_impact_score INT,production_country VARCHAR(255)); INSERT INTO environmental_impact (chemical_id,environmental_impact_score,production_country) VALUES (101,78,'Brazil'),(102,82,'USA'),(103,85,'Mexico'),(104,60,'Brazil'),(105,90,'Canada');
|
SELECT AVG(environmental_impact_score) FROM environmental_impact WHERE production_country = 'Brazil'
|
What was the total cost of all infrastructure projects in Kenya in 2020?
|
CREATE TABLE Infrastructure_Projects (id INT,country VARCHAR(50),year INT,cost FLOAT); INSERT INTO Infrastructure_Projects (id,country,year,cost) VALUES (1,'Kenya',2020,150000.0),(2,'Tanzania',2019,120000.0),(3,'Kenya',2018,175000.0);
|
SELECT SUM(cost) FROM Infrastructure_Projects WHERE country = 'Kenya' AND year = 2020;
|
What is the average years of experience for teachers who have not accessed mental health resources?
|
CREATE TABLE teachers (teacher_id INT,years_of_experience INT,mental_health_resource_access DATE); INSERT INTO teachers VALUES (1,5,NULL),(2,3,NULL),(3,8,NULL);
|
SELECT AVG(years_of_experience) AS avg_experience FROM teachers WHERE mental_health_resource_access IS NULL;
|
Identify the top 3 heaviest non-organic products and their suppliers.
|
CREATE TABLE suppliers (id INT,name VARCHAR(255),country VARCHAR(255)); CREATE TABLE products (id INT,name VARCHAR(255),organic BOOLEAN,weight FLOAT,supplier_id INT);
|
SELECT p.name, s.name as supplier, p.weight FROM suppliers s INNER JOIN products p ON s.id = p.supplier_id WHERE p.organic = 'f' ORDER BY p.weight DESC LIMIT 3;
|
What is the minimum labor productivity for a mine site in Q4 2022?
|
CREATE TABLE labor_productivity_q4 (site_id INT,productivity FLOAT,productivity_date DATE); INSERT INTO labor_productivity_q4 (site_id,productivity,productivity_date) VALUES (1,12.0,'2022-10-01'),(1,13.0,'2022-10-02'),(1,14.0,'2022-10-03'); INSERT INTO labor_productivity_q4 (site_id,productivity,productivity_date) VALUES (2,15.0,'2022-10-01'),(2,16.0,'2022-10-02'),(2,17.0,'2022-10-03');
|
SELECT site_id, MIN(productivity) FROM labor_productivity_q4 WHERE productivity_date BETWEEN '2022-10-01' AND '2022-12-31' GROUP BY site_id;
|
How many mining equipment units are there in the 'equipment_inventory' table, broken down by type?
|
CREATE TABLE equipment_inventory (id INT,equipment_type VARCHAR(50),quantity INT); INSERT INTO equipment_inventory (id,equipment_type,quantity) VALUES (1,'Excavator',10),(2,'Drill',15),(3,'Haul Truck',20);
|
SELECT equipment_type, quantity FROM equipment_inventory;
|
What is the average attendance for events in the 'music' category?
|
CREATE TABLE events (id INT,name VARCHAR(255),date DATE,category VARCHAR(255)); INSERT INTO events (id,name,date,category) VALUES (1,'Concert','2022-06-01','music'),(2,'Play','2022-06-02','theater');
|
SELECT AVG(attendance) FROM events WHERE category = 'music';
|
What is the average advertising revenue in Japan for Q2 2022?
|
CREATE TABLE ad_revenue (country VARCHAR(2),date DATE,revenue DECIMAL(10,2)); INSERT INTO ad_revenue (country,date,revenue) VALUES ('US','2022-01-01',100),('JP','2022-04-01',200),('JP','2022-04-15',250);
|
SELECT AVG(revenue) FROM ad_revenue WHERE country = 'JP' AND date BETWEEN '2022-04-01' AND '2022-06-30';
|
Update the revenue of all Classical music streams in the United Kingdom on March 1, 2021 to 2.50.
|
CREATE TABLE streams (song_id INT,stream_date DATE,genre VARCHAR(20),country VARCHAR(20),revenue DECIMAL(10,2)); INSERT INTO streams (song_id,stream_date,genre,country,revenue) VALUES (10,'2021-03-01','Classical','UK',1.50);
|
UPDATE streams SET revenue = 2.50 WHERE genre = 'Classical' AND country = 'UK' AND stream_date = '2021-03-01';
|
What is the total number of visitors to historical museums in the year 2019?
|
CREATE TABLE museums (name VARCHAR(255),location VARCHAR(255),year_established INT,type VARCHAR(255)); INSERT INTO museums (name,location,year_established,type) VALUES ('British Museum','London',1753,'History'),('Louvre Museum','Paris',1793,'Art'),('Metropolitan Museum of Art','New York',1870,'Art'); CREATE TABLE attendance (museum_name VARCHAR(255),year INT,total_visitors INT); INSERT INTO attendance (museum_name,year,total_visitors) VALUES ('British Museum',2019,6267367),('Louvre Museum',2019,10028000),('Metropolitan Museum of Art',2019,6911941);
|
SELECT SUM(total_visitors) FROM attendance WHERE year = 2019 AND type = 'History';
|
What is the total quantity of recycled polyester sourced from Asian countries?
|
CREATE TABLE textile_sources (source_id INT,material VARCHAR(50),country VARCHAR(50)); INSERT INTO textile_sources (source_id,material,country) VALUES (1,'Recycled Polyester','China'),(2,'Recycled Polyester','India'); CREATE TABLE quantities (quantity_id INT,source_id INT,quantity INT); INSERT INTO quantities (quantity_id,source_id,quantity) VALUES (1,1,5000),(2,2,7000);
|
SELECT SUM(q.quantity) FROM quantities q INNER JOIN textile_sources ts ON q.source_id = ts.source_id WHERE ts.material = 'Recycled Polyester' AND ts.country IN ('China', 'India');
|
Find the average number of comments for posts with the hashtag #nature in the "wildlife_appreciation" schema.
|
CREATE TABLE posts (id INT,user_id INT,content TEXT,comments INT,hashtags TEXT);
|
SELECT AVG(comments) FROM posts WHERE hashtags LIKE '%#nature%';
|
How many employees were hired in the last quarter of 2022?
|
CREATE TABLE Hiring (HireID INT,HireDate DATE); INSERT INTO Hiring (HireID,HireDate) VALUES (1,'2022-10-01'),(2,'2022-11-15'),(3,'2022-12-20'),(4,'2023-01-05'),(5,'2023-02-12');
|
SELECT COUNT(*) FROM Hiring WHERE HireDate >= '2022-10-01' AND HireDate < '2023-01-01';
|
Identify users who have posted more than 5 times per day on average in the last 30 days.
|
CREATE TABLE posts (id INT,user_id INT,created_at TIMESTAMP); CREATE TABLE users (id INT,username VARCHAR(255));
|
SELECT users.username FROM users JOIN (SELECT user_id, COUNT(*) / 30 AS avg_posts_per_day FROM posts WHERE created_at >= NOW() - INTERVAL 30 DAY GROUP BY user_id HAVING avg_posts_per_day > 5) AS subquery ON users.id = subquery.user_id;
|
Which programs had the least volunteer hours in Q4 2021?
|
CREATE TABLE program_hours (id INT,program TEXT,hours DECIMAL,hours_date DATE);
|
SELECT program, SUM(hours) as total_hours FROM program_hours WHERE hours_date >= '2021-10-01' AND hours_date < '2022-01-01' GROUP BY program ORDER BY total_hours ASC;
|
List the teams that have a win rate greater than 60%.
|
CREATE TABLE games (game_id INT,team VARCHAR(50),position VARCHAR(50),wins INT);
|
SELECT team FROM (SELECT team, SUM(wins) AS wins, COUNT(*) AS total_games FROM games GROUP BY team) AS subquery WHERE wins / total_games > 0.6;
|
How many soccer games took place in London since 2020?
|
CREATE TABLE if not exists cities (city_id INT,city VARCHAR(255)); INSERT INTO cities (city_id,city) VALUES (1,'London'),(2,'Paris'),(3,'Berlin'); CREATE TABLE if not exists matches (match_id INT,city_id INT,match_date DATE); INSERT INTO matches (match_id,city_id,match_date) VALUES (1,1,'2022-01-01'),(2,2,'2022-01-02'),(3,3,'2022-01-03'),(4,1,'2021-06-01'),(5,1,'2021-12-25');
|
SELECT COUNT(*) FROM matches WHERE city_id = 1 AND match_date >= '2020-01-01';
|
Identify the total production of 'cassava' by small farmers in 'Africa' for the last 3 years.
|
CREATE TABLE crops_2 (id INT,farmer_id INT,name TEXT,yield INT,year INT); INSERT INTO crops_2 (id,farmer_id,name,yield,year) VALUES (1,1,'cassava',400,2010),(2,1,'cassava',500,2011),(3,2,'cassava',600,2010),(4,2,'cassava',700,2011),(5,3,'cassava',800,2010),(6,3,'cassava',900,2011);
|
SELECT SUM(yield) FROM crops_2 WHERE name = 'cassava' AND country = 'Africa' AND year BETWEEN 2010 AND 2012;
|
What is the average speed of vessels that arrived in the US in the last month?
|
CREATE TABLE Vessels (ID INT,Name VARCHAR(255),Speed FLOAT,Arrival DATETIME); INSERT INTO Vessels (ID,Name,Speed,Arrival) VALUES (1,'Vessel1',20.5,'2022-01-01 10:00:00'),(2,'Vessel2',25.3,'2022-01-15 14:30:00');
|
SELECT AVG(Speed) FROM (SELECT Speed, ROW_NUMBER() OVER (ORDER BY Arrival DESC) as RowNum FROM Vessels WHERE Arrival >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH)) AS Sub WHERE RowNum <= 10;
|
What is the average square footage of co-living units in the city of Austin?
|
CREATE TABLE properties (id INT,city VARCHAR(50),square_footage FLOAT); INSERT INTO properties (id,city,square_footage) VALUES (1,'Austin',1200.0),(2,'Austin',1500.0),(3,'Seattle',1800.0);
|
SELECT AVG(square_footage) FROM properties WHERE city = 'Austin' AND square_footage IS NOT NULL AND city IS NOT NULL;
|
What is the average budget allocated for ethical AI initiatives by country?
|
CREATE TABLE Ethical_AI (country VARCHAR(255),budget INT); INSERT INTO Ethical_AI (country,budget) VALUES ('USA',5000000),('Canada',3000000),('Mexico',2000000);
|
SELECT AVG(budget) as avg_budget, country FROM Ethical_AI GROUP BY country;
|
Find the top 3 water-consuming cities in the state of California for August 2020.
|
CREATE TABLE WaterConsumption (ID INT,City VARCHAR(20),State VARCHAR(20),Consumption FLOAT,Date DATE); INSERT INTO WaterConsumption (ID,City,State,Consumption,Date) VALUES (13,'Los Angeles','California',200,'2020-08-01'),(14,'San Francisco','California',180,'2020-08-02'),(15,'San Diego','California',190,'2020-08-03'),(16,'Los Angeles','California',210,'2020-08-04');
|
SELECT City, SUM(Consumption) FROM WaterConsumption WHERE State = 'California' AND Date >= '2020-08-01' AND Date <= '2020-08-31' GROUP BY City ORDER BY SUM(Consumption) DESC LIMIT 3
|
Which policy types have no claims in 2020?
|
CREATE TABLE Policy (PolicyID int,PolicyType varchar(50),EffectiveDate date,RiskScore int); CREATE TABLE Claim (ClaimID int,PolicyID int,ClaimDate date,ClaimAmount int,State varchar(50)); INSERT INTO Policy (PolicyID,PolicyType,EffectiveDate,RiskScore) VALUES (1,'Auto','2020-01-01',700),(2,'Home','2019-05-05',900),(3,'Life','2021-08-01',850); INSERT INTO Claim (ClaimID,PolicyID,ClaimDate,ClaimAmount,State) VALUES (1,1,'2020-03-15',2000,'Texas'),(2,2,'2019-12-27',3000,'California'),(3,3,'2021-01-05',1500,'Texas');
|
SELECT Policy.PolicyType FROM Policy LEFT JOIN Claim ON Policy.PolicyID = Claim.PolicyID WHERE Claim.ClaimDate IS NULL AND Claim.ClaimDate BETWEEN '2020-01-01' AND '2020-12-31';
|
What is the daily waste generation rate for each waste type, ranked by the highest generation rate, for the Northwest region?
|
CREATE TABLE waste_generation (waste_type VARCHAR(255),region VARCHAR(255),generation_rate INT,date DATE); INSERT INTO waste_generation (waste_type,region,generation_rate,date) VALUES ('Plastic','Northwest',120,'2021-01-01'),('Plastic','Northwest',150,'2021-01-02'),('Paper','Northwest',210,'2021-01-01'),('Paper','Northwest',240,'2021-01-02');
|
SELECT waste_type, region, generation_rate, date, RANK() OVER (PARTITION BY waste_type ORDER BY generation_rate DESC) as daily_generation_rank FROM waste_generation WHERE region = 'Northwest';
|
Which network infrastructure investments were made in the last 6 months?
|
CREATE TABLE network_investments (investment_id INT,investment_date DATE,investment_amount DECIMAL(10,2)); INSERT INTO network_investments (investment_id,investment_date,investment_amount) VALUES (1,'2022-01-01',50000),(2,'2022-03-15',75000),(3,'2022-06-30',60000),(4,'2022-09-15',85000),(5,'2022-12-31',90000);
|
SELECT * FROM network_investments WHERE network_investments.investment_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH);
|
Insert records of tourists who visited Canada in 2022.
|
CREATE TABLE tourism_stats (country VARCHAR(255),year INT,visitors INT,continent VARCHAR(255));
|
INSERT INTO tourism_stats (country, year, visitors, continent) VALUES ('Canada', 2022, 3500000, 'North America');
|
What is the average data usage (in GB) for prepaid mobile customers in the 'South' region?
|
CREATE TABLE usage (id INT,subscriber_id INT,data_usage DECIMAL(10,2)); INSERT INTO usage (id,subscriber_id,data_usage) VALUES (1,1,2.5),(2,2,3.0),(3,3,1.5); CREATE TABLE subscribers (id INT,type VARCHAR(10),region VARCHAR(10)); INSERT INTO subscribers (id,type,region) VALUES (1,'postpaid','North'),(2,'prepaid','South'),(3,'postpaid','East');
|
SELECT AVG(usage.data_usage) AS avg_data_usage FROM usage INNER JOIN subscribers ON usage.subscriber_id = subscribers.id WHERE subscribers.type = 'prepaid' AND subscribers.region = 'South';
|
Rank nonprofits based in Washington by the number of donations received
|
CREATE TABLE donations (id INT PRIMARY KEY,donor_id INT,donation_amount DECIMAL(10,2),donation_date DATE,nonprofit_id INT); CREATE TABLE nonprofits (id INT PRIMARY KEY,name VARCHAR(100),city VARCHAR(50),mission VARCHAR(200)); INSERT INTO donations (id,donor_id,donation_amount,donation_date,nonprofit_id) VALUES (1,1,500,'2022-01-01',1); INSERT INTO donations (id,donor_id,donation_amount,donation_date,nonprofit_id) VALUES (2,2,750,'2022-02-15',2); INSERT INTO nonprofits (id,name,city,mission) VALUES (1,'Save the Children','Washington','Improving the lives of children through better education,health care,and economic opportunities.'); INSERT INTO nonprofits (id,name,city,mission) VALUES (2,'Greenpeace','San Francisco','Dedicated to preserving the environment and promoting peace.');
|
SELECT nonprofits.name, ROW_NUMBER() OVER (PARTITION BY nonprofits.city ORDER BY COUNT(donations.id) DESC) as ranking FROM nonprofits INNER JOIN donations ON nonprofits.id = donations.nonprofit_id WHERE nonprofits.city = 'Washington' GROUP BY nonprofits.name;
|
What is the combined mass of all spacecraft that have been to Mars?
|
CREATE TABLE Spacecraft (SpacecraftID INT,Name VARCHAR(50),Manufacturer VARCHAR(50),LaunchDate DATE,Mass FLOAT); INSERT INTO Spacecraft VALUES (1,'Mariner 4','NASA','1964-11-28',260),(2,'Mariner 6','NASA','1969-02-25',419),(3,'Mariner 7','NASA','1969-03-27',419),(4,'Viking 1','NASA','1975-08-20',1200),(5,'Viking 2','NASA','1975-09-09',1200),(6,'Mars Pathfinder','NASA','1996-12-04',1400),(7,'Mars Global Surveyor','NASA','1996-11-07',1060),(8,'Nozomi','ISAS','1998-07-03',540),(9,'Mars Climate Orbiter','NASA',1998-12-11,628),(10,'Mars Polar Lander','NASA',1999-01-03,370);
|
SELECT SUM(Mass) FROM Spacecraft WHERE Destination = 'Mars';
|
Insert new cargo records for a shipment from the Port of Oakland to Japan in 2023
|
CREATE TABLE ports (port_id INT,port_name VARCHAR(255),country VARCHAR(255)); INSERT INTO ports VALUES (1,'Port of Shanghai','China'); CREATE TABLE cargo (cargo_id INT,port_id INT,weight FLOAT,handling_date DATE);
|
INSERT INTO cargo (cargo_id, port_id, weight, handling_date) VALUES (1001, (SELECT port_id FROM ports WHERE port_name = 'Port of Oakland'), 6000, '2023-02-14'), (1002, (SELECT port_id FROM ports WHERE country = 'Japan'), 5500, '2023-02-16');
|
Delete records of peacekeeping operations older than a certain year.
|
CREATE TABLE peacekeeping_operations (id INT,country VARCHAR(255),year INT);
|
DELETE FROM peacekeeping_operations WHERE year < (SELECT EXTRACT(YEAR FROM NOW()) - 10);
|
Which team has the highest number of home wins in the last 10 games?
|
CREATE TABLE games (team TEXT,result TEXT); INSERT INTO games (team,result) VALUES ('Team A','win'),('Team A','loss'),('Team B','win');
|
SELECT team, COUNT(*) FILTER (WHERE result = 'win') OVER (PARTITION BY team ORDER BY team ROWS BETWEEN UNBOUNDED PRECEDING AND 9 PRECEDING) as home_wins FROM games WHERE result = 'win' ORDER BY home_wins DESC LIMIT 1;
|
Find the number of unique products from organic sources.
|
CREATE TABLE sources (id INT,name TEXT,organic BOOLEAN); CREATE TABLE products_sources (product_id INT,source_id INT); INSERT INTO sources VALUES (1,'Source A',TRUE),(2,'Source B',FALSE),(3,'Source C',TRUE); INSERT INTO products_sources VALUES (1,1),(2,1),(3,2),(4,3);
|
SELECT COUNT(DISTINCT products_sources.product_id) FROM products_sources INNER JOIN sources ON products_sources.source_id = sources.id WHERE sources.organic = TRUE;
|
What is the hotel tech adoption rate by country, in Q1 2023?
|
CREATE TABLE hotel_tech_adoption (adoption_id INT,adoption_rate FLOAT,country TEXT,quarter TEXT); INSERT INTO hotel_tech_adoption (adoption_id,adoption_rate,country,quarter) VALUES (1,0.65,'USA','Q1 2023'),(2,0.72,'Canada','Q1 2023');
|
SELECT quarter, country, AVG(adoption_rate) FROM hotel_tech_adoption GROUP BY quarter, country;
|
What is the order ID and delivery time for the slowest delivery made by each courier in the 'courier_performances' view, ordered by the slowest delivery time?
|
CREATE VIEW courier_performances AS SELECT courier_id,order_id,MAX(delivery_time) as slowest_delivery_time FROM orders GROUP BY courier_id,order_id;
|
SELECT courier_id, order_id, MAX(slowest_delivery_time) as slowest_delivery_time FROM courier_performances GROUP BY courier_id, order_id ORDER BY slowest_delivery_time;
|
What is the total number of shelters in Kenya and the number of families they accommodate?
|
CREATE TABLE shelters (id INT,name TEXT,location TEXT,capacity INT); INSERT INTO shelters (id,name,location,capacity) VALUES (1,'Shelter A','Nairobi',50),(2,'Shelter B','Mombasa',75);
|
SELECT SUM(capacity) as total_capacity, (SELECT COUNT(DISTINCT id) FROM shelters WHERE location = 'Kenya') as family_count FROM shelters WHERE location = 'Kenya';
|
What is the total number of models that have been trained and tested for fairness in the 'US' region?
|
CREATE TABLE models (id INT,name VARCHAR(255),region VARCHAR(255),is_fairness_test BOOLEAN); INSERT INTO models (id,name,region,is_fairness_test) VALUES (1,'ModelA','US',true),(2,'ModelB','EU',false),(3,'ModelC','APAC',true),(4,'ModelD','US',false),(5,'ModelE','US',true);
|
SELECT COUNT(*) FROM models WHERE region = 'US' AND is_fairness_test = true;
|
Show the energy efficiency ratings for solar projects in New York, and the average energy efficiency rating for solar projects in New York
|
CREATE TABLE solar_projects (project_id INT,project_name VARCHAR(255),location VARCHAR(255),installed_capacity INT,commissioning_date DATE,energy_efficiency_rating INT); INSERT INTO solar_projects (project_id,project_name,location,installed_capacity,commissioning_date,energy_efficiency_rating) VALUES (1,'Solar Farm A','California',150,'2018-05-01',80); INSERT INTO solar_projects (project_id,project_name,location,installed_capacity,commissioning_date,energy_efficiency_rating) VALUES (2,'Solar Farm B','Texas',200,'2019-11-15',85); INSERT INTO solar_projects (project_id,project_name,location,installed_capacity,commissioning_date,energy_efficiency_rating) VALUES (3,'Solar Farm C','New York',120,'2020-07-20',95);
|
SELECT energy_efficiency_rating FROM solar_projects WHERE location = 'New York'; SELECT AVG(energy_efficiency_rating) FROM solar_projects WHERE location = 'New York';
|
List the names of all tennis players who have won a Grand Slam tournament, along with the tournament name and the year they won it.
|
CREATE TABLE tennis_players (id INT,name VARCHAR(100),country VARCHAR(50)); CREATE TABLE tennis_tournaments (id INT,name VARCHAR(50),year INT,surface VARCHAR(50)); CREATE TABLE tennis_winners (player_id INT,tournament_id INT,year INT,result VARCHAR(50));
|
SELECT p.name, t.name as tournament, w.year FROM tennis_players p JOIN tennis_winners w ON p.id = w.player_id JOIN tennis_tournaments t ON w.tournament_id = t.id WHERE w.result = 'Winner';
|
What is the minimum rating for movies produced in the last 5 years by directors from underrepresented communities?
|
CREATE TABLE movies (id INT,title TEXT,release_year INT,rating FLOAT,director TEXT); INSERT INTO movies (id,title,release_year,rating,director) VALUES (1,'Movie1',2019,7.5,'Director1'); INSERT INTO movies (id,title,release_year,rating,director) VALUES (2,'Movie2',2021,8.2,'Director2');
|
SELECT MIN(rating) FROM movies WHERE release_year >= YEAR(CURRENT_DATE) - 5 AND director IN (SELECT director FROM directors WHERE underrepresented = true);
|
List all smart contracts associated with the digital asset 'BTC'
|
CREATE TABLE smart_contracts (contract_name VARCHAR(20),associated_asset VARCHAR(10)); INSERT INTO smart_contracts (contract_name,associated_asset) VALUES ('Contract1','ETH'),('Contract2','BTC'),('Contract3','LTC');
|
SELECT contract_name FROM smart_contracts WHERE associated_asset = 'BTC';
|
How many total donations did we receive from foundations based in CA?
|
CREATE TABLE donors (id INT,state VARCHAR(50),donor_type VARCHAR(50)); INSERT INTO donors (id,state,donor_type) VALUES (1,'CA','foundation'),(2,'NY','individual'),(3,'CA','individual'); CREATE TABLE donations (id INT,donor_id INT,amount DECIMAL(10,2)); INSERT INTO donations (id,donor_id,amount) VALUES (1,1,5000),(2,1,7000),(3,2,200),(4,3,1000);
|
SELECT SUM(donations.amount) FROM donations JOIN donors ON donations.donor_id = donors.id WHERE donors.state = 'CA' AND donors.donor_type = 'foundation';
|
What is the maximum number of international visitors to New Zealand in a month?
|
CREATE TABLE international_visitors (id INT,country VARCHAR(50),visit_month DATE); INSERT INTO international_visitors (id,country,visit_month) VALUES (1,'New Zealand','2022-01-01'),(2,'New Zealand','2022-02-01'),(3,'New Zealand','2022-02-15');
|
SELECT MAX(MONTH(visit_month)) as max_month, COUNT(*) as max_visitors FROM international_visitors WHERE country = 'New Zealand' GROUP BY max_month;
|
What organizations are dedicated to technology accessibility and have published at least one paper?
|
CREATE TABLE tech_accessibility_orgs (id INT PRIMARY KEY,name VARCHAR(255),website VARCHAR(255),city VARCHAR(255)); INSERT INTO tech_accessibility_orgs (id,name,website,city) VALUES (1,'Open Inclusion','https://openinclusion.com','London'); INSERT INTO tech_accessibility_orgs (id,name,website,city) VALUES (2,'Technability','https://technability.org','Tel Aviv'); INSERT INTO tech_accessibility_orgs (id,name,website,city) VALUES (3,'BarrierBreak','https://barrierbreak.com','Mumbai'); CREATE TABLE papers (id INT PRIMARY KEY,title VARCHAR(255),org_id INT,publication_date DATE); INSERT INTO papers (id,title,org_id,publication_date) VALUES (1,'Designing for Accessibility',1,'2021-04-25'); INSERT INTO papers (id,title,org_id,publication_date) VALUES (2,'Assistive Technology Trends',2,'2021-10-12'); INSERT INTO papers (id,title,org_id,publication_date) VALUES (3,'Accessibility in AI-powered Products',3,'2022-02-15');
|
SELECT DISTINCT name FROM tech_accessibility_orgs WHERE id IN (SELECT org_id FROM papers);
|
What is the highest number of 3-pointers made by each basketball player in the NBA?
|
CREATE TABLE nba_3pointers (player_id INT,name VARCHAR(50),team VARCHAR(50),threes INT); INSERT INTO nba_3pointers (player_id,name,team,threes) VALUES (1,'Stephen Curry','Golden State Warriors',300); INSERT INTO nba_3pointers (player_id,name,team,threes) VALUES (2,'James Harden','Brooklyn Nets',250);
|
SELECT name, MAX(threes) FROM nba_3pointers GROUP BY name;
|
What is the total sales revenue for each category in the last month?
|
CREATE TABLE sales (menu_item VARCHAR(255),category VARCHAR(255),sales_revenue DECIMAL(10,2)); INSERT INTO sales (menu_item,category,sales_revenue) VALUES ('Burger','Main Dishes',15.99); INSERT INTO sales (menu_item,category,sales_revenue) VALUES ('Caesar Salad','Salads',12.50);
|
SELECT category, SUM(sales_revenue) as total_revenue FROM sales WHERE sales_revenue > 0 AND sale_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY category;
|
Which vessels have a max speed greater than 18?
|
CREATE TABLE Vessels (vessel_id VARCHAR(10),name VARCHAR(20),type VARCHAR(20),max_speed FLOAT); INSERT INTO Vessels (vessel_id,name,type,max_speed) VALUES ('1','Vessel A','Cargo',20.5),('2','Vessel B','Tanker',15.2),('3','Vessel C','Tanker',18.1),('4','Vessel D','Cargo',12.6);
|
SELECT vessel_id, name FROM Vessels WHERE max_speed > 18;
|
What is the maximum altitude reached by any satellite deployed by Orbital Inc.?
|
CREATE TABLE SatelliteAltitude (satellite_id INT,company VARCHAR(255),altitude INT);
|
SELECT MAX(altitude) FROM SatelliteAltitude WHERE company = 'Orbital Inc.';
|
What is the average price of products made from sustainable materials in the Asian market?
|
CREATE TABLE products (product_id INT,material VARCHAR(20),price DECIMAL(5,2),market VARCHAR(20)); INSERT INTO products (product_id,material,price,market) VALUES (1,'organic cotton',50.00,'Asia'),(2,'sustainable wood',60.00,'Asia'),(3,'recycled polyester',70.00,'Europe'),(4,'organic linen',80.00,'Asia');
|
SELECT AVG(price) FROM products WHERE market = 'Asia' AND material IN ('organic cotton', 'sustainable wood', 'recycled polyester', 'organic linen');
|
List the top 5 most streamed songs for users aged 18-24.
|
CREATE TABLE artists (id INT PRIMARY KEY,name VARCHAR(255),genre VARCHAR(255),country VARCHAR(255)); CREATE TABLE songs (id INT PRIMARY KEY,title VARCHAR(255),artist_id INT,released DATE); CREATE TABLE streams (id INT PRIMARY KEY,song_id INT,user_id INT,stream_date DATE,FOREIGN KEY (song_id) REFERENCES songs(id)); CREATE TABLE users (id INT PRIMARY KEY,gender VARCHAR(50),age INT);
|
SELECT s.title, COUNT(s.id) AS total_streams FROM streams s JOIN users u ON s.user_id = u.id WHERE u.age BETWEEN 18 AND 24 GROUP BY s.title ORDER BY total_streams DESC LIMIT 5;
|
Find the total number of autonomous driving research papers published
|
CREATE TABLE research_papers (id INT,title VARCHAR(100),publication_year INT,autonomous_driving BOOLEAN); INSERT INTO research_papers (id,title,publication_year,autonomous_driving) VALUES (1,'Autonomous Driving and AI',2020,true),(2,'Hybrid Vehicle Efficiency',2021,false),(3,'EV Charging Infrastructure',2021,false),(4,'Sensors in Autonomous Vehicles',2022,true);
|
SELECT COUNT(*) FROM research_papers WHERE autonomous_driving = true;
|
What is the average program impact score for programs with a budget over $100,000 in the past 2 years?
|
CREATE TABLE Programs (ProgramID INT,ProgramName TEXT,Budget DECIMAL,ProgramDate DATE,ImpactScore INT); INSERT INTO Programs (ProgramID,ProgramName,Budget,ProgramDate,ImpactScore) VALUES (1,'Art Education',125000.00,'2020-01-01',85),(2,'Theater Production',75000.00,'2021-07-15',90),(3,'Music Recording',150000.00,'2019-12-31',88);
|
SELECT AVG(ImpactScore) FROM Programs WHERE Budget > 100000.00 AND ProgramDate >= DATE_SUB(CURRENT_DATE, INTERVAL 2 YEAR);
|
What is the maximum water usage in a single day for the city of Chicago?
|
CREATE TABLE water_usage (usage_id INT,city VARCHAR(20),usage FLOAT,date DATE); INSERT INTO water_usage (usage_id,city,usage,date) VALUES (1,'Chicago',500000.0,'2021-01-01'),(2,'Chicago',600000.0,'2021-02-01'),(3,'New York',700000.0,'2021-03-01');
|
SELECT MAX(usage) FROM water_usage WHERE city = 'Chicago';
|
What is the maximum altitude reached by each spacecraft model?
|
CREATE TABLE spacecraft_telemetry (id INT,spacecraft_model VARCHAR(255),altitude INT);
|
SELECT spacecraft_model, MAX(altitude) as max_altitude FROM spacecraft_telemetry GROUP BY spacecraft_model;
|
What is the difference in biomass between farming sites in the Northern and Southern Hemispheres for each fish type?
|
CREATE TABLE Farming_Sites (Site_ID INT,Site_Name TEXT,Hemisphere TEXT); INSERT INTO Farming_Sites (Site_ID,Site_Name,Hemisphere) VALUES (1,'Site A','Northern'),(2,'Site B','Southern'),(3,'Site C','Southern'); CREATE TABLE Fish_Stock (Site_ID INT,Fish_Type TEXT,Biomass FLOAT); INSERT INTO Fish_Stock (Site_ID,Fish_Type,Biomass) VALUES (1,'Salmon',5000),(1,'Tuna',3000),(2,'Salmon',7000),(2,'Tilapia',4000),(3,'Salmon',6000),(3,'Tuna',2000);
|
SELECT Fish_Type, SUM(CASE WHEN Hemisphere = 'Northern' THEN Biomass ELSE 0 END) - SUM(CASE WHEN Hemisphere = 'Southern' THEN Biomass ELSE 0 END) FROM Fish_Stock INNER JOIN Farming_Sites ON Fish_Stock.Site_ID = Farming_Sites.Site_ID GROUP BY Fish_Type;
|
How many traditional dances are documented for each country in Asia?
|
CREATE TABLE traditional_dances (id INT,name VARCHAR(50),location VARCHAR(50),dance_type VARCHAR(50),PRIMARY KEY(id)); INSERT INTO traditional_dances (id,name,location,dance_type) VALUES (1,'Bharatanatyam','India','Classical'),(2,'Odissi','India','Classical'),(3,'Kathak','India','Classical'),(4,'Jingju','China','Opera'),(5,'Bian Lian','China','Opera');
|
SELECT t.location, COUNT(*) AS dance_count FROM traditional_dances t GROUP BY t.location;
|
What is the average horsepower for electric vehicles in the 'green_cars' table?
|
CREATE TABLE green_cars (make VARCHAR(50),model VARCHAR(50),year INT,horsepower INT);
|
SELECT AVG(horsepower) FROM green_cars WHERE horsepower IS NOT NULL AND make = 'Tesla';
|
What is the total training cost for employees who joined the company in 2019, grouped by their department?
|
CREATE TABLE Employees (EmployeeID INT,HireYear INT,Department VARCHAR(20)); CREATE TABLE Trainings (TrainingID INT,EmployeeID INT,TrainingYear INT,Cost FLOAT); INSERT INTO Employees (EmployeeID,HireYear,Department) VALUES (1,2019,'IT'),(2,2019,'HR'),(3,2018,'IT'),(4,2019,'IT'); INSERT INTO Trainings (TrainingID,EmployeeID,TrainingYear,Cost) VALUES (1,1,2019,500.00),(2,2,2019,600.00),(3,3,2018,700.00),(4,4,2019,800.00);
|
SELECT Department, SUM(Cost) FROM Employees INNER JOIN Trainings ON Employees.EmployeeID = Trainings.EmployeeID WHERE Employees.HireYear = 2019 GROUP BY Department;
|
What is the total number of renewable energy projects in 'India'?
|
CREATE TABLE total_renewable_projects (project_id INT,country VARCHAR(50)); INSERT INTO total_renewable_projects (project_id,country) VALUES (1,'India'),(2,'Brazil');
|
SELECT COUNT(*) FROM total_renewable_projects WHERE country = 'India';
|
What is the maximum transaction value for each customer in the "credit_card" table, grouped by their country?
|
CREATE TABLE customer (customer_id INT,name VARCHAR(50),country VARCHAR(50)); CREATE TABLE credit_card (transaction_id INT,customer_id INT,value DECIMAL(10,2),timestamp TIMESTAMP);
|
SELECT c.country, MAX(cc.value) as max_value FROM customer c JOIN credit_card cc ON c.customer_id = cc.customer_id GROUP BY c.country;
|
How many exhibitions were organized by the museum in the last 5 years, segmented by type?
|
CREATE TABLE Exhibitions (ExhibitionID INT,ExhibitionType VARCHAR(255),ExhibitionDate DATE); INSERT INTO Exhibitions (ExhibitionID,ExhibitionType,ExhibitionDate) VALUES (1,'Art','2017-01-01'); INSERT INTO Exhibitions (ExhibitionID,ExhibitionType,ExhibitionDate) VALUES (2,'Science','2018-07-15'); INSERT INTO Exhibitions (ExhibitionID,ExhibitionType,ExhibitionDate) VALUES (3,'History','2019-03-25');
|
SELECT ExhibitionType, COUNT(ExhibitionID) as Count FROM Exhibitions WHERE ExhibitionDate >= DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR) GROUP BY ExhibitionType;
|
What is the maximum donation amount in each non-social cause category?
|
CREATE TABLE donations (id INT,donor_id INT,amount DECIMAL(10,2),cause_id INT); INSERT INTO donations (id,donor_id,amount,cause_id) VALUES (1,1,500.00,3),(2,1,300.00,3),(3,2,250.00,4),(4,2,400.00,4),(5,3,100.00,3),(6,4,700.00,4),(7,5,1200.00,3);
|
SELECT c.type, MAX(d.amount) FROM donations d JOIN causes c ON d.cause_id = c.id GROUP BY c.type HAVING c.type != 'Social';
|
What is the total amount of waste generated by the chemical manufacturing plants in Argentina in the year 2020?
|
CREATE TABLE waste_generation (id INT,plant_id INT,generation_date DATE,waste_amount FLOAT); CREATE TABLE manufacturing_plants (id INT,plant_name VARCHAR(100),country VARCHAR(50)); INSERT INTO manufacturing_plants (id,plant_name,country) VALUES (1,'Argentina Plant 1','Argentina'),(2,'Argentina Plant 2','Argentina'); INSERT INTO waste_generation (id,plant_id,generation_date,waste_amount) VALUES (1,1,'2020-01-01',120.3),(2,1,'2020-05-15',150.6),(3,2,'2020-12-28',180.9);
|
SELECT SUM(waste_amount) FROM waste_generation JOIN manufacturing_plants ON waste_generation.plant_id = manufacturing_plants.id WHERE manufacturing_plants.country = 'Argentina' AND EXTRACT(YEAR FROM generation_date) = 2020;
|
How many shipments were sent to each country from warehouse 2?
|
CREATE TABLE warehouse (id INT,location VARCHAR(255)); INSERT INTO warehouse (id,location) VALUES (1,'Chicago'),(2,'Houston'); CREATE TABLE shipments (id INT,warehouse_id INT,country VARCHAR(255)); INSERT INTO shipments (id,warehouse_id,country) VALUES (1,1,'USA'),(2,1,'Canada'),(3,2,'Mexico'),(4,2,'USA');
|
SELECT warehouse_id, country, COUNT(*) as num_shipments FROM shipments GROUP BY warehouse_id, country;
|
Which non-GMO breakfast items have more than 400 calories?
|
CREATE TABLE Foods(id INT,name TEXT,type TEXT,calories INT,is_gmo BOOLEAN); INSERT INTO Foods(id,name,type,calories,is_gmo) VALUES (1,'Scrambled Tofu','Breakfast',450,FALSE),(2,'Blueberry Oatmeal','Breakfast',380,FALSE);
|
SELECT name, calories FROM Foods WHERE type = 'Breakfast' AND calories > 400 AND is_gmo = FALSE;
|
What are the green building names and certification ratings in Japan?
|
CREATE TABLE GreenBuildings (id INT,name VARCHAR(50),city VARCHAR(50),state VARCHAR(50),country VARCHAR(50),certification VARCHAR(50),certification_rating INT); INSERT INTO GreenBuildings (id,name,city,state,country,certification,certification_rating) VALUES (4,'SakuraEco','Tokyo','Tokyo','Japan','CASBEE Gold',80);
|
SELECT g.name, g.certification_rating FROM GreenBuildings g WHERE g.country = 'Japan';
|
Identify systems that have not had a policy update in the last 30 days.
|
CREATE TABLE policies (id INT,policy_id TEXT,system TEXT,description TEXT,last_updated DATE);INSERT INTO policies (id,policy_id,system,description,last_updated) VALUES (1,'PS-001','firewall','Block all incoming traffic','2021-01-03');
|
SELECT system, last_updated FROM policies WHERE last_updated < CURRENT_DATE - INTERVAL '30 days' AND system NOT IN (SELECT system FROM policies WHERE last_updated >= CURRENT_DATE - INTERVAL '30 days');
|
Get the number of multimodal mobility users in Mumbai and Istanbul who used both public transportation and shared scooters.
|
CREATE TABLE mumbai_mobility (user_id INT,mode VARCHAR(20)); CREATE TABLE istanbul_mobility (user_id INT,mode VARCHAR(20)); INSERT INTO mumbai_mobility (user_id,mode) VALUES (1,'Train'),(2,'Bus'),(3,'Bike'),(4,'Shared Scooter'); INSERT INTO istanbul_mobility (user_id,mode) VALUES (5,'Train'),(6,'Bus'),(7,'Bike'),(8,'Shared Scooter');
|
SELECT COUNT(*) FROM (SELECT user_id FROM mumbai_mobility WHERE mode = 'Shared Scooter' INTERSECT SELECT user_id FROM mumbai_mobility WHERE mode = 'Train') AS intersection UNION ALL SELECT COUNT(*) FROM (SELECT user_id FROM istanbul_mobility WHERE mode = 'Shared Scooter' INTERSECT SELECT user_id FROM istanbul_mobility WHERE mode = 'Train');
|
How many people were displaced due to natural disasters in Indonesia and Philippines?
|
CREATE TABLE displaced_persons (id INT,country VARCHAR(20),person_id INT,displacement_date DATE);
|
SELECT country, COUNT(DISTINCT person_id) as displaced_people FROM displaced_persons GROUP BY country;
|
What is the most popular tourist destination in Japan for the month of May?
|
CREATE TABLE tourism_data (id INT,destination TEXT,visit_date DATE); INSERT INTO tourism_data (id,destination,visit_date) VALUES (1,'Tokyo','2022-05-01'),(2,'Osaka','2022-05-15'),(3,'Kyoto','2022-05-03'),(4,'Tokyo','2022-05-05');
|
SELECT destination, COUNT(*) AS num_visitors FROM tourism_data WHERE visit_date BETWEEN '2022-05-01' AND '2022-05-31' GROUP BY destination ORDER BY num_visitors DESC LIMIT 1;
|
What is the total weight of all shipments from 'Paris' to any destination?
|
CREATE TABLE Shipments (ID INT,Origin VARCHAR(50),Destination VARCHAR(50),Weight INT); INSERT INTO Shipments (ID,Origin,Destination,Weight) VALUES (1,'Tokyo','New York',100),(2,'Paris','London',200),(3,'Brazil','India',300);
|
SELECT SUM(Shipments.Weight) FROM Shipments WHERE Shipments.Origin = 'Paris';
|
What is the average price of room service in Mexico?
|
CREATE TABLE features (id INT,name TEXT,price FLOAT,location TEXT); INSERT INTO features (id,name,price,location) VALUES (1,'Virtual tours',10,'USA'),(2,'Concierge service',20,'Canada'),(3,'Room service',30,'Mexico');
|
SELECT AVG(price) FROM features WHERE name = 'Room service' AND location = 'Mexico';
|
What is the maximum number of passengers for each aircraft type?
|
CREATE TABLE Aircraft_Types (Id INT,Aircraft_Type VARCHAR(50),Max_Passengers INT); INSERT INTO Aircraft_Types (Id,Aircraft_Type,Max_Passengers) VALUES (1,'B737',215),(2,'A320',186),(3,'B747',416);
|
SELECT Aircraft_Type, MAX(Max_Passengers) FROM Aircraft_Types GROUP BY Aircraft_Type;
|
How many hydroelectric power plants are in Canada?
|
CREATE TABLE hydro_plants (id INT,country VARCHAR(255),name VARCHAR(255)); INSERT INTO hydro_plants (id,country,name) VALUES (1,'Canada','Hydro Plant A'),(2,'Canada','Hydro Plant B'),(3,'United States','Hydro Plant C');
|
SELECT COUNT(*) FROM hydro_plants WHERE country = 'Canada';
|
How many volunteers engaged in each program in 2021?
|
CREATE TABLE Volunteers (volunteer_id INT,program_id INT,volunteer_hours INT,volunteer_date DATE); INSERT INTO Volunteers (volunteer_id,program_id,volunteer_hours,volunteer_date) VALUES (1,1,5,'2021-06-05'),(2,2,8,'2021-04-12'),(3,1,3,'2021-06-05'),(1,3,6,'2021-12-25');
|
SELECT program_id, COUNT(DISTINCT volunteer_id) as unique_volunteers_in_2021 FROM Volunteers WHERE volunteer_date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY program_id;
|
What is the maximum number of military personnel for countries in a specific region?
|
CREATE TABLE Country (Name VARCHAR(50),Region VARCHAR(50),MilitaryPersonnel INT); INSERT INTO Country (Name,Region,MilitaryPersonnel) VALUES ('United States','North America',1400000),('Canada','North America',65000),('Mexico','North America',270000),('Brazil','South America',300000),('Argentina','South America',120000);
|
SELECT Region, MAX(MilitaryPersonnel) AS MaxMilitaryPersonnel FROM Country GROUP BY Region;
|
Insert a new teacher record into the 'Teachers' table
|
CREATE TABLE Teachers (TeacherID int,FirstName varchar(20),LastName varchar(20),Age int,Gender varchar(10),Subject varchar(20));
|
INSERT INTO Teachers (TeacherID, FirstName, LastName, Age, Gender, Subject) VALUES (5678, 'Jane', 'Doe', 35, 'Female', 'English');
|
What is the maximum budget for any education program?
|
CREATE VIEW Education_Programs AS SELECT 'Eco_Warriors' AS program,22000 AS budget UNION SELECT 'Nature_Defenders',25000;
|
SELECT MAX(budget) FROM Education_Programs;
|
List all the defense equipment maintenance companies that operate in Africa?
|
CREATE TABLE Maintenance_Company (id INT,name VARCHAR(50),region VARCHAR(50)); INSERT INTO Maintenance_Company (id,name,region) VALUES (1,'Lockheed Martin Africa','Africa'),(2,'Boeing Europe','Europe');
|
SELECT DISTINCT name FROM Maintenance_Company WHERE region = 'Africa';
|
Average home value for socially responsible loans in Alaska
|
CREATE TABLE socially_responsible_loans (id INT,home_value FLOAT,state VARCHAR(255)); CREATE TABLE states (id INT,state VARCHAR(255),region VARCHAR(255));
|
SELECT AVG(home_value) FROM socially_responsible_loans INNER JOIN states ON socially_responsible_loans.state = states.state WHERE states.state = 'Alaska';
|
Identify the industry with the lowest average funding amount
|
CREATE TABLE industry_funding (company_name VARCHAR(100),industry VARCHAR(50),funding_amount INT);
|
SELECT industry, AVG(funding_amount) as avg_funding FROM industry_funding GROUP BY industry ORDER BY avg_funding ASC LIMIT 1;
|
Show the recycling rate per month for the city of New York in 2019, with the highest rate at the top.
|
CREATE TABLE recycling_rates (id INT,city VARCHAR(50),rate FLOAT,month INT,year INT); INSERT INTO recycling_rates (id,city,rate,month,year) VALUES (1,'New York',25.6,1,2019),(2,'New York',26.2,2,2019),(3,'New York',27.1,3,2019);
|
SELECT city, AVG(rate) as avg_rate FROM recycling_rates WHERE city = 'New York' AND year = 2019 GROUP BY city, month ORDER BY avg_rate DESC;
|
Count the number of students in each 'grade_level' in the 'students' table
|
CREATE TABLE students (student_id INT,name VARCHAR(50),grade_level VARCHAR(10));
|
SELECT grade_level, COUNT(*) FROM students GROUP BY grade_level;
|
What is the total timber production for each country in 2022?
|
CREATE TABLE timber_production (country_code CHAR(3),year INT,volume INT); INSERT INTO timber_production (country_code,year,volume) VALUES ('IDN',2022,12000),('IDN',2021,11000),('JPN',2022,15000),('JPN',2021,13000);
|
SELECT c.country_name, SUM(tp.volume) as total_volume FROM timber_production tp INNER JOIN country c ON tp.country_code = c.country_code WHERE tp.year = 2022 GROUP BY c.country_name;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.