instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Which sustainable material has the highest average price?
CREATE TABLE material_prices (id INT,material VARCHAR(50),price DECIMAL(10,2)); INSERT INTO material_prices (id,material,price) VALUES (1,'organic silk',35.00),(2,'organic linen',18.50);
SELECT material, AVG(price) as avg_price FROM material_prices GROUP BY material ORDER BY avg_price DESC LIMIT 1;
Compare the number of language preservation programs in North America and Europe.
CREATE TABLE language_preservation (id INT,country VARCHAR(50),program VARCHAR(50),region VARCHAR(50)); INSERT INTO language_preservation (id,country,program,region) VALUES (1,'USA','Native American Language Program','North America'),(2,'France','French Language Program','Europe');
SELECT COUNT(*) FROM language_preservation WHERE region = 'North America' INTERSECT SELECT COUNT(*) FROM language_preservation WHERE region = 'Europe';
What is the total installed solar PV capacity (MW) in Germany as of 2022?
CREATE TABLE solar_pv (id INT,country TEXT,year INT,capacity_mw FLOAT); INSERT INTO solar_pv (id,country,year,capacity_mw) VALUES (1,'Japan',2020,60.5),(2,'Japan',2021,65.6),(3,'Germany',2022,70.7);
SELECT SUM(capacity_mw) FROM solar_pv WHERE country = 'Germany' AND year = 2022;
What is the total funding raised for companies with a female founder?
CREATE TABLE companies (id INT,name VARCHAR(50),industry VARCHAR(50),founding_year INT,founder_gender VARCHAR(10)); INSERT INTO companies (id,name,industry,founding_year,founder_gender) VALUES (1,'Delta Inc','Retail',2016,'Female'),(2,'Echo Corp','Tech',2017,'Male'),(3,'Foxtrot LLC','Retail',2018,'Female'),(4,'Gamma In...
SELECT SUM(f.round_amount) FROM companies c JOIN funding_rounds f ON c.id = f.company_id WHERE c.founder_gender = 'Female';
Delete players from the US who haven't made any purchases in the last year?
CREATE TABLE players (id INT,name VARCHAR(100),country VARCHAR(100)); CREATE TABLE purchases (id INT,player_id INT,purchase_date DATE); INSERT INTO players (id,name,country) VALUES (1,'John Doe','USA'),(2,'Jane Smith','USA'),(3,'Alex Brown','Canada'); INSERT INTO purchases (id,player_id,purchase_date) VALUES (1,1,'2022...
DELETE FROM players WHERE id IN (SELECT p.id FROM players p JOIN purchases pu ON p.id = pu.player_id WHERE p.country = 'USA' AND pu.purchase_date < (CURRENT_DATE - INTERVAL '1 year'));
What is the maximum salary of editors in the "staff" table?
CREATE TABLE staff (id INT,name VARCHAR(50),position VARCHAR(50),salary INT); INSERT INTO staff (id,name,position,salary) VALUES (1,'Jane Smith','Editor',70000),(2,'Mike Johnson','Reporter',50000);
SELECT MAX(salary) FROM staff WHERE position = 'Editor';
Which country sources the most organic ingredients for cosmetic products?
CREATE TABLE Ingredient_Sourcing (SupplierID INT,ProductID INT,Organic BOOLEAN,Country VARCHAR(50)); INSERT INTO Ingredient_Sourcing (SupplierID,ProductID,Organic,Country) VALUES (1001,101,TRUE,'Brazil'),(1002,102,FALSE,'Brazil'),(1003,101,TRUE,'Argentina'),(1004,103,FALSE,'Argentina'),(1005,102,TRUE,'Chile');
SELECT Country, SUM(Organic) as TotalOrganic FROM Ingredient_Sourcing GROUP BY Country ORDER BY TotalOrganic DESC;
Delete all cargos from the 'cargos' table that are over 10 years old.
CREATE TABLE cargos (id INT PRIMARY KEY,name VARCHAR(50),date_received DATE);
DELETE FROM cargos WHERE date_received < DATE_SUB(CURDATE(), INTERVAL 10 YEAR);
Find the unique property co-owners in Los Angeles with a lease expiration date in the next 3 months.
CREATE TABLE la_prop(id INT,owner1 VARCHAR(20),owner2 VARCHAR(20),lease_exp DATE); INSERT INTO la_prop VALUES (1,'Ivy','Jack','2023-03-01'),(2,'Karen','Luke','2023-01-15');
SELECT DISTINCT owner1, owner2 FROM la_prop WHERE (owner1 <> owner2) AND (lease_exp BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 3 MONTH));
List all safety incidents recorded in the last 30 days
CREATE TABLE SafetyIncidents(IncidentID INT,VesselID INT,IncidentType TEXT,IncidentDate DATETIME); INSERT INTO SafetyIncidents(IncidentID,VesselID,IncidentType,IncidentDate) VALUES (1,1,'Collision','2022-03-05 11:00:00'),(2,2,'Grounding','2022-03-15 09:00:00'),(3,3,'Mechanical Failure','2022-03-30 16:30:00');
SELECT * FROM SafetyIncidents WHERE IncidentDate BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 30 DAY) AND CURRENT_DATE;
Retrieve the most recent geopolitical risk rating for India.
CREATE TABLE GeopoliticalRiskAssessments (AssessmentID INT,Country VARCHAR(50),RiskRating VARCHAR(10),AssessmentDate DATE); INSERT INTO GeopoliticalRiskAssessments (AssessmentID,Country,RiskRating,AssessmentDate) VALUES (1,'Iran','High','2021-06-01'),(2,'India','Medium','2022-08-12');
SELECT Country, RiskRating FROM GeopoliticalRiskAssessments WHERE AssessmentDate = (SELECT MAX(AssessmentDate) FROM GeopoliticalRiskAssessments WHERE Country = 'India');
What is the name and model of military aircrafts manufactured in the USA?
CREATE TABLE MilitaryAircrafts(id INT PRIMARY KEY,name VARCHAR(50),model VARCHAR(50),country VARCHAR(50));INSERT INTO MilitaryAircrafts(id,name,model,country) VALUES (1,'F-15 Eagle','F-15EX','USA');
SELECT name, model FROM MilitaryAircrafts WHERE country = 'USA';
What is the earliest pollution control initiative date for each site?
CREATE TABLE pollution_initiatives (initiative_id INT,site_id INT,initiative_date DATE,initiative_description TEXT); INSERT INTO pollution_initiatives (initiative_id,site_id,initiative_date,initiative_description) VALUES (1,1,'2022-08-01','Installed new filters'),(2,3,'2022-07-15','Regular cleaning schedule established...
SELECT site_id, MIN(initiative_date) FROM pollution_initiatives GROUP BY site_id;
What is the maximum response time for emergency calls in each district?
CREATE TABLE Districts (DistrictID INT,Name VARCHAR(50)); CREATE TABLE EmergencyCalls (CallID INT,DistrictID INT,ResponseTime FLOAT);
SELECT D.Name, MAX(E.ResponseTime) as MaxResponseTime FROM Districts D INNER JOIN EmergencyCalls E ON D.DistrictID = E.DistrictID GROUP BY D.Name;
Insert new records into the 'ethical_manufacturing' table with the following data: (1, 'Fair Trade Certified', '2021-01-01')
CREATE TABLE ethical_manufacturing (id INT PRIMARY KEY,certification VARCHAR(100),certification_date DATE);
INSERT INTO ethical_manufacturing (id, certification, certification_date) VALUES (1, 'Fair Trade Certified', '2021-01-01');
How many students have enrolled in the open pedagogy program in the past 6 months?
CREATE TABLE enrollments (id INT,enrollment_date DATE,student_id INT,program VARCHAR(50)); INSERT INTO enrollments (id,enrollment_date,student_id,program) VALUES (1,'2021-07-01',1001,'Open Pedagogy'),(2,'2021-08-15',1002,'Open Pedagogy'),(3,'2022-01-10',1003,'Traditional Program'),(4,'2022-02-01',1004,'Open Pedagogy');
SELECT COUNT(DISTINCT student_id) as num_enrolled FROM enrollments WHERE program = 'Open Pedagogy' AND enrollment_date >= DATEADD(month, -6, GETDATE());
Update email of players from 'US' to 'new_email@usa.com'
player (player_id,name,email,age,gender,country,total_games_played)
UPDATE player SET email = 'new_email@usa.com' WHERE country = 'US'
Determine the most common aircraft type involved in accidents and its count.
CREATE TABLE Accidents (AccidentID INT,Date DATE,Location VARCHAR(50),AircraftType VARCHAR(50),Description TEXT,Fatalities INT); INSERT INTO Accidents (AccidentID,Date,Location,AircraftType,Description,Fatalities) VALUES (7,'2018-05-05','Moscow','Boeing 737','Electrical issues',1),(8,'2020-06-06','Tokyo','Boeing 737','...
SELECT AircraftType, COUNT(*) AS Count FROM Accidents GROUP BY AircraftType ORDER BY COUNT(*) DESC FETCH FIRST 1 ROW ONLY;
Identify the legal aid organization with the most cases in California
CREATE TABLE legal_aid_organizations (org_id INT,name VARCHAR(50),cases_handled INT,state VARCHAR(2)); INSERT INTO legal_aid_organizations (org_id,name,cases_handled,state) VALUES (1,'California Legal Aid',200,'CA'),(2,'New York Legal Aid',300,'NY'),(3,'Texas Legal Aid',150,'TX'),(4,'Florida Legal Aid',250,'FL'),(5,'Lo...
SELECT name, MAX(cases_handled) FROM legal_aid_organizations WHERE state = 'CA';
Find the dish with the highest price in the 'Pizza' category
CREATE TABLE menu (dish_name TEXT,category TEXT,price DECIMAL); INSERT INTO menu VALUES ('Margherita Pizza','Pizza',9.99),('Pepperoni Pizza','Pizza',10.99),('Vegetarian Pizza','Pizza',11.99);
SELECT dish_name, MAX(price) FROM menu WHERE category = 'Pizza' GROUP BY category;
Which size has the most customers in the 'South America' region?
CREATE TABLE Customers (CustomerID INT,Size VARCHAR(10),Country VARCHAR(255)); INSERT INTO Customers (CustomerID,Size,Country) VALUES (1,'XS','Brazil'),(2,'S','Argentina'),(3,'M','Chile'),(4,'L','Peru'),(5,'XL','Colombia'),(6,'XS','Argentina'),(7,'L','Brazil');
SELECT Size, COUNT(*) AS Count FROM Customers WHERE Country = 'South America' GROUP BY Size ORDER BY Count DESC LIMIT 1;
What is the total claim amount per risk assessment category?
CREATE TABLE claims (id INT,policyholder_id INT,amount DECIMAL(10,2),risk_category VARCHAR(25));
SELECT risk_category, SUM(amount) as total_claim_amount FROM claims GROUP BY risk_category;
List the suppliers and their respective total revenue for vegan products in Germany.
CREATE TABLE suppliers (supp_id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO suppliers VALUES (1,'Green Earth','Germany'); INSERT INTO suppliers VALUES (2,'EcoVita','Germany'); CREATE TABLE products (product_id INT,name VARCHAR(50),type VARCHAR(20),price DECIMAL(5,2)); INSERT INTO products VALUES (1,'Tofu Ste...
SELECT s.name, SUM(p.price) FROM suppliers s JOIN products p ON s.name = p.name WHERE s.country = 'Germany' AND p.type = 'vegan' GROUP BY s.name;
What is the maximum pressure recorded per device per hour?
create table PressureData (Device varchar(255),Pressure int,Timestamp datetime); insert into PressureData values ('Device1',50,'2022-01-01 01:00:00'),('Device2',70,'2022-01-01 02:00:00'),('Device1',60,'2022-01-01 03:00:00');
select Device, DATE_PART('hour', Timestamp) as Hour, MAX(Pressure) as MaxPressure from PressureData group by Device, Hour;
What is the maximum quantity of products sold by small businesses, pivoted by day?
CREATE TABLE sales (sale_id INT,product_id INT,quantity INT,sale_date DATE,is_small_business BOOLEAN); INSERT INTO sales (sale_id,product_id,quantity,sale_date,is_small_business) VALUES (1,1,5,'2021-01-01',true); CREATE TABLE products (product_id INT,product_name VARCHAR(255)); INSERT INTO products (product_id,product_...
SELECT EXTRACT(DAY FROM sale_date) AS day, is_small_business, MAX(quantity) AS max_quantity FROM sales JOIN products ON sales.product_id = products.product_id WHERE is_small_business = true GROUP BY day, is_small_business;
Which players from the United States and Canada have not participated in any esports events?
CREATE TABLE Players (PlayerID INT,PlayerName VARCHAR(50),Country VARCHAR(50)); INSERT INTO Players (PlayerID,PlayerName,Country) VALUES (1,'John Doe','USA'),(2,'Jane Smith','Canada'); CREATE TABLE EsportsEvents (EventID INT,PlayerID INT,EventName VARCHAR(50)); INSERT INTO EsportsEvents (EventID,PlayerID,EventName) VAL...
(SELECT Players.PlayerName FROM Players WHERE Players.Country IN ('USA', 'Canada') EXCEPT SELECT EsportsEvents.PlayerName FROM EsportsEvents)
What is the distribution of AI safety incidents by type in the last 3 years?
CREATE TABLE time_series_data (incident_id INT,incident_type VARCHAR(50),incident_year INT); INSERT INTO time_series_data (incident_id,incident_type,incident_year) VALUES (1,'Data Privacy',2021),(2,'Model Malfunction',2020),(3,'Data Privacy',2021);
SELECT incident_type, COUNT(*) as num_incidents, incident_year FROM time_series_data WHERE incident_year >= 2019 GROUP BY incident_type, incident_year;
What was the minimum ocean acidification level by year?
CREATE TABLE yearly_acidification (year INT,level FLOAT); INSERT INTO yearly_acidification (year,level) VALUES (2015,7.6),(2016,7.7),(2017,7.8),(2018,7.8),(2019,7.7),(2020,7.6);
SELECT year, MIN(level) FROM yearly_acidification;
What is the total biosensor technology development cost for projects in the UK?
CREATE TABLE projects (id INT,name VARCHAR(50),country VARCHAR(50),techniques VARCHAR(50),costs FLOAT); INSERT INTO projects (id,name,country,techniques,costs) VALUES (1,'ProjectX','UK','Biosensor technology,bioinformatics',20000); INSERT INTO projects (id,name,country,techniques,costs) VALUES (2,'ProjectY','UK','PCR,b...
SELECT SUM(costs) FROM projects WHERE country = 'UK' AND techniques LIKE '%Biosensor technology%';
What is the average number of employees per mining operation in Australia, partitioned by state?
CREATE TABLE mining_operations (id INT,name TEXT,location TEXT,num_employees INT); INSERT INTO mining_operations (id,name,location,num_employees) VALUES (1,'Operation X','Australia-NSW',250),(2,'Operation Y','Australia-QLD',300),(3,'Operation Z','Australia-NSW',200);
SELECT location, AVG(num_employees) FROM mining_operations WHERE location LIKE 'Australia-%' GROUP BY location;
What is the win rate for each player in the 'matches' table?
CREATE TABLE matches (id INT,player_id INT,opponent_id INT,winner_id INT); INSERT INTO matches VALUES (1,1,2,1); INSERT INTO matches VALUES (2,2,1,2); INSERT INTO matches VALUES (3,1,3,1); INSERT INTO matches VALUES (4,3,1,3);
SELECT player_id, COUNT(*) * 100.0 / SUM(CASE WHEN player_id IN (player_id, opponent_id) THEN 1 ELSE 0 END) as win_rate FROM matches GROUP BY player_id;
What is the number of members in unions advocating for labor rights in Texas?
CREATE TABLE union_advocacy_tx (id INT,union_name TEXT,state TEXT,involved_in_advocacy BOOLEAN,members INT); INSERT INTO union_advocacy_tx (id,union_name,state,involved_in_advocacy,members) VALUES (1,'Union A','Texas',true,500),(2,'Union B','Texas',true,600),(3,'Union C','Texas',false,400);
SELECT SUM(members) FROM union_advocacy_tx WHERE state = 'Texas' AND involved_in_advocacy = true;
Display the total revenue for the "jazz" genre from all platforms, excluding any platforms that have a revenue lower than $5,000 for that genre.
CREATE TABLE platformD (genre TEXT,revenue INT); CREATE TABLE platformE (genre TEXT,revenue INT); CREATE TABLE platformF (genre TEXT,revenue INT);
SELECT genre, SUM(revenue) FROM (SELECT genre, revenue FROM platformD WHERE genre = 'jazz' AND revenue >= 5000 UNION ALL SELECT genre, revenue FROM platformE WHERE genre = 'jazz' AND revenue >= 5000 UNION ALL SELECT genre, revenue FROM platformF WHERE genre = 'jazz' AND revenue >= 5000) AS combined_platforms GROUP BY g...
How many whales have been spotted in the Atlantic Ocean in 2020?
CREATE TABLE atlantic_ocean (id INT,year INT,species TEXT,sightings INT); INSERT INTO atlantic_ocean (id,year,species,sightings) VALUES (1,2020,'Blue Whale',250);
SELECT SUM(sightings) FROM atlantic_ocean WHERE year = 2020 AND species = 'Blue Whale';
Update the 'Organic Chicken' dish price to $14.00 in the 'Bistro' restaurant.
CREATE TABLE menu_engineering(dish VARCHAR(255),category VARCHAR(255),price DECIMAL(5,2),restaurant VARCHAR(255));
UPDATE menu_engineering SET price = 14.00 WHERE dish = 'Organic Chicken' AND restaurant = 'Bistro';
Calculate the average amount of waste produced per day for each manufacturing plant, for the past month, and rank them in descending order.
CREATE TABLE Waste_Production (Plant VARCHAR(255),Waste_Amount INT,Waste_Date DATE); INSERT INTO Waste_Production (Plant,Waste_Amount,Waste_Date) VALUES ('Plant1',50,'2022-06-01'),('Plant1',60,'2022-06-02'),('Plant2',30,'2022-06-01'),('Plant2',40,'2022-06-02');
SELECT Plant, AVG(Waste_Amount) AS Avg_Waste_Per_Day, RANK() OVER (ORDER BY AVG(Waste_Amount) DESC) AS Rank FROM Waste_Production WHERE Waste_Date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY Plant;
Find the average fare for each route
CREATE TABLE fare (fare_id INT,amount DECIMAL,collected_date DATE,route_id INT); INSERT INTO fare VALUES (1,2.50,'2022-07-01',1); INSERT INTO fare VALUES (2,3.00,'2022-07-01',1); INSERT INTO fare VALUES (3,2.00,'2022-07-02',2); INSERT INTO fare VALUES (4,4.00,'2022-07-02',2); CREATE TABLE route (route_id INT,name TEXT)...
SELECT r.name, AVG(f.amount) FROM fare f JOIN route r ON f.route_id = r.route_id GROUP BY f.route_id;
Calculate the total number of genetic research projects in the USA.
CREATE TABLE genetic_research (id INT,project_name VARCHAR(50),location VARCHAR(50)); INSERT INTO genetic_research (id,project_name,location) VALUES (1,'Project K','USA'); INSERT INTO genetic_research (id,project_name,location) VALUES (2,'Project L','Canada');
SELECT COUNT(*) FROM genetic_research WHERE location = 'USA';
What are the names of volunteers who have worked on projects in both 'Education' and 'Environment' categories?
CREATE TABLE projects (id INT,category VARCHAR(20),volunteer_id INT); INSERT INTO projects (id,category,volunteer_id) VALUES (1,'Education',100),(2,'Environment',100),(3,'Health',200),(4,'Education',300);
SELECT volunteer_id FROM projects WHERE category = 'Education' INTERSECT SELECT volunteer_id FROM projects WHERE category = 'Environment';
Update the carbon sequestration values for Canada in 2020 by 5%
CREATE TABLE carbon_sequestration (id INT,country VARCHAR(255),year INT,sequestration FLOAT,hectares FLOAT); INSERT INTO carbon_sequestration (id,country,year,sequestration,hectares) VALUES (1,'Canada',2018,1000.2,12000000.5),(2,'Australia',2019,1100.1,15000000.3),(3,'Brazil',2018,1300.0,20000000.7),(4,'Indonesia',2019...
UPDATE carbon_sequestration SET sequestration = sequestration * 1.05 WHERE country = 'Canada' AND year = 2020;
What is the average delivery time for each fair labor practice brand in Asia?
CREATE TABLE Brands (brand_id INT,brand_name VARCHAR(50),ethical BOOLEAN,region VARCHAR(50)); CREATE TABLE Deliveries (delivery_id INT,delivery_date DATE,brand_id INT);
SELECT B.brand_name, AVG(DATEDIFF(delivery_date, order_date)) as avg_delivery_time FROM Deliveries D INNER JOIN Orders O ON D.delivery_id = O.order_id INNER JOIN Brands B ON D.brand_id = B.brand_id WHERE B.ethical = TRUE AND B.region = 'Asia' GROUP BY B.brand_name;
What is the average maintenance cost per month for naval ships in Canada?
CREATE TABLE Naval_Ships (id INT,country VARCHAR(50),type VARCHAR(50),acquisition_date DATE,maintenance_cost FLOAT);
SELECT AVG(maintenance_cost/MONTHS_BETWEEN(acquisition_date, CURRENT_DATE)) FROM Naval_Ships WHERE country = 'Canada';
What is the total investment in genetics research in Q1 2022?
CREATE TABLE genetics_investment(id INT,investment VARCHAR(50),date DATE,amount DECIMAL(10,2)); INSERT INTO genetics_investment VALUES (1,'InvestmentA','2022-03-15',1000000.00),(2,'InvestmentB','2022-01-30',1200000.00),(3,'InvestmentC','2022-02-28',1500000.00);
SELECT SUM(amount) FROM genetics_investment WHERE date BETWEEN '2022-01-01' AND '2022-03-31';
What's the total funding received by environmental NGOs based in Africa since 2015?
CREATE TABLE organizations (id INT,name VARCHAR(50),type VARCHAR(50),country VARCHAR(50)); INSERT INTO organizations (id,name,type,country) VALUES (1,'Greenpeace Africa','NGO','Africa'); INSERT INTO organizations (id,name,type,country) VALUES (2,'Friends of the Earth Africa','NGO','Africa'); INSERT INTO organizations (...
SELECT o.name, o.country, sum(f.funding) as total_funding FROM organizations o INNER JOIN funding_received f ON o.id = f.organization_id WHERE o.type = 'NGO' AND o.country = 'Africa' AND f.year >= 2015 GROUP BY o.name, o.country;
How many ethical AI projects were completed in North America last year?
CREATE TABLE ethical_ai_projects (project_id INT,country VARCHAR(20),completion_year INT); INSERT INTO ethical_ai_projects (project_id,country,completion_year) VALUES (1,'USA',2020),(2,'Canada',2019),(3,'Mexico',2021),(4,'USA',2018);
SELECT COUNT(*) FROM ethical_ai_projects WHERE country IN ('USA', 'Canada') AND completion_year = 2020;
How many international visitors arrived in Paris by month in 2020?
CREATE TABLE visitor_stats (visitor_id INT,city TEXT,visit_date DATE); INSERT INTO visitor_stats (visitor_id,city,visit_date) VALUES (1,'Paris','2020-01-01'),(2,'Paris','2020-02-14'),(3,'London','2020-03-03'),(4,'Paris','2020-04-20');
SELECT city, EXTRACT(MONTH FROM visit_date) AS month, COUNT(DISTINCT visitor_id) AS num_visitors FROM visitor_stats WHERE city = 'Paris' AND EXTRACT(YEAR FROM visit_date) = 2020 GROUP BY city, month ORDER BY month;
What is the average number of security incidents per month for the 'HR' department in 2022?
CREATE TABLE security_incidents (id INT,department VARCHAR(20),incident_date DATE); INSERT INTO security_incidents (id,department,incident_date) VALUES (1,'HR','2022-01-15'),(2,'Finance','2022-02-07'),(3,'HR','2022-03-20'),(4,'HR','2022-01-01');
SELECT AVG(COUNT(*)) FROM security_incidents WHERE department = 'HR' AND YEAR(incident_date) = 2022 GROUP BY MONTH(incident_date);
Calculate the total CO2 emissions for each country in 2020 from the 'emissions' table
CREATE TABLE emissions (country VARCHAR(50),year INT,co2_emissions INT); INSERT INTO emissions (country,year,co2_emissions) VALUES ('USA',2020,5135),('China',2020,10096),('India',2020,2720),('Russia',2020,2653),('Japan',2020,1140),('Germany',2020,736),('Iran',2020,551),('Saudi Arabia',2020,531),('South Korea',2020,601)...
SELECT country, SUM(co2_emissions) as total_emissions FROM emissions WHERE year = 2020 GROUP BY country;
What is the total installed capacity (MW) of renewable energy sources in California?
CREATE TABLE ca_renewable_energy (id INT,source TEXT,capacity_mw FLOAT); INSERT INTO ca_renewable_energy (id,source,capacity_mw) VALUES (1,'Wind',500.0),(2,'Solar',1000.0),(3,'Geothermal',750.0);
SELECT SUM(capacity_mw) FROM ca_renewable_energy WHERE source IN ('Wind', 'Solar', 'Geothermal');
What is the total number of space missions and the percentage of successful missions by country?
CREATE SCHEMA Space;CREATE TABLE Space.SpaceExplorationResearch (country VARCHAR(50),mission_result VARCHAR(10));INSERT INTO Space.SpaceExplorationResearch (country,mission_result) VALUES ('USA','Success'),('USA','Success'),('China','Success'),('Russia','Failure'),('Russia','Success'),('India','Success'),('India','Fail...
SELECT country, COUNT(*) AS total_missions, 100.0 * SUM(CASE WHEN mission_result = 'Success' THEN 1 ELSE 0 END) / COUNT(*) AS success_percentage FROM Space.SpaceExplorationResearch GROUP BY country;
What is the maximum number of union members in the 'healthcare' schema for any given month in '2021'?
CREATE TABLE union_members (id INT,date DATE,industry VARCHAR(255),member_count INT); INSERT INTO union_members (id,date,industry,member_count) VALUES (1,'2021-01-01','healthcare',500),(2,'2021-02-01','healthcare',550),(3,'2021-03-01','healthcare',600);
SELECT MAX(member_count) FROM union_members WHERE industry = 'healthcare' AND date BETWEEN '2021-01-01' AND '2021-12-31';
What is the rank of each cargo by volume category?
CREATE TABLE VolumeCategory (VolumeCategoryID INT,VolumeRange VARCHAR(50),LowerLimit INT,UpperLimit INT); INSERT INTO VolumeCategory (VolumeCategoryID,VolumeRange,LowerLimit,UpperLimit) VALUES (1,'up to 10000',0,10000); INSERT INTO VolumeCategory (VolumeCategoryID,VolumeRange,LowerLimit,UpperLimit) VALUES (2,'10000-500...
SELECT CargoName, Weight, RANK() OVER (PARTITION BY vc.VolumeCategoryID ORDER BY Weight DESC) as Rank FROM Cargo c JOIN VolumeCategory vc ON c.Weight BETWEEN vc.LowerLimit AND vc.UpperLimit;
How many cultural heritage sites are there in Germany, Austria, and Switzerland?
CREATE TABLE heritage_sites (site_id INT,site_name TEXT,country TEXT); INSERT INTO heritage_sites (site_id,site_name,country) VALUES (1,'Brandenburg Gate','Germany'),(2,'Schönbrunn Palace','Austria'),(3,'Jungfrau-Aletsch','Switzerland');
SELECT COUNT(*) FROM heritage_sites WHERE country IN ('Germany', 'Austria', 'Switzerland');
Find the total carbon sequestration in 2020 in the 'carbon' table.
CREATE TABLE carbon (forest_id INT,year INT,sequestration FLOAT);
SELECT SUM(sequestration) FROM carbon WHERE year = 2020;
How many total tickets were sold for each type of event in the 'events' table?
CREATE TABLE events (id INT PRIMARY KEY,event_name VARCHAR(100),event_type VARCHAR(50),num_tickets_sold INT);
SELECT event_type, SUM(num_tickets_sold) AS total_tickets_sold FROM events GROUP BY event_type;
What is the total number of marine species observed in the Coral Triangle?
CREATE TABLE marine_species_observations (id INTEGER,species TEXT,location TEXT); INSERT INTO marine_species_observations (id,species,location) VALUES (1,'Clownfish','Coral Triangle'),(2,'Sea Turtle','Coral Triangle'),(3,'Dolphin','Coral Triangle');
SELECT COUNT(*) FROM marine_species_observations WHERE location = 'Coral Triangle';
Show the total number of employees by ethnicity
diversity_metrics
SELECT ethnicity, COUNT(*) as total_employees FROM diversity_metrics GROUP BY ethnicity;
Who are the top 3 contributors to heritage site conservation efforts in 'Europe'?
CREATE TABLE contributors (id INT,name VARCHAR(50),donation INT,location VARCHAR(50)); INSERT INTO contributors (id,name,donation,location) VALUES (1,'Anne Smith',15000,'Europe'),(2,'Bob Johnson',12000,'Europe'),(3,'Charlotte Lee',10000,'Europe');
SELECT name, donation FROM contributors WHERE location = 'Europe' ORDER BY donation DESC LIMIT 3;
How many circular economy initiatives were launched in 'Africa' since 2015?
CREATE TABLE circular_initiatives(region VARCHAR(10),year INT,initiative VARCHAR(20)); INSERT INTO circular_initiatives VALUES('Africa',2015,'Waste-to-Energy'),('Asia',2016,'Recycling program'),('Africa',2016,'Composting program'),('Europe',2017,'Product reuse'),('Africa',2018,'Plastic reduction campaign');
SELECT COUNT(*) FROM circular_initiatives WHERE region = 'Africa' AND year >= 2015;
What is the minimum speed for each vessel type?
CREATE TABLE vessels (id INT,type VARCHAR(255),imo INT); CREATE TABLE speeds (id INT,vessel_id INT,speed FLOAT);
SELECT v.type, MIN(s.speed) as min_speed FROM speeds s JOIN vessels v ON s.vessel_id = v.id GROUP BY v.type;
How many articles were published by "The New York Times" in 2019 having the word 'climate' in the title?
CREATE TABLE Articles (id INT,title VARCHAR(255),publisher VARCHAR(100),publication_year INT,topic VARCHAR(50)); INSERT INTO Articles (id,title,publisher,publication_year,topic) VALUES (1,'Article1','The New York Times',2019,'climate'),(2,'Article2','The Washington Post',2018,'politics'),(3,'Article3','The New York Tim...
SELECT COUNT(*) FROM Articles WHERE publisher = 'The New York Times' AND publication_year = 2019 AND topic = 'climate';
List all chemical reactions involving 'Sodium Hydroxide' and 'Hydrochloric Acid', along with their reaction types, and the number of times they have been performed.
CREATE TABLE reaction (id INT,chemical_1 VARCHAR(255),chemical_2 VARCHAR(255),reaction_type VARCHAR(255)); INSERT INTO reaction (id,chemical_1,chemical_2,reaction_type) VALUES (1,'Sodium Hydroxide','Hydrochloric Acid','Neutralization'),(2,'Sodium Hydroxide','Acetic Acid','Neutralization'),(3,'Hydrochloric Acid','Sodium...
SELECT r.reaction_type, r.chemical_1, r.chemical_2, COUNT(rr.id) as num_reactions FROM reaction r INNER JOIN reaction_record rr ON r.id = rr.reaction_id WHERE (r.chemical_1 = 'Sodium Hydroxide' AND r.chemical_2 = 'Hydrochloric Acid') OR (r.chemical_1 = 'Hydrochloric Acid' AND r.chemical_2 = 'Sodium Hydroxide') GROUP BY...
What are the names of the programs that have a budget greater than the average program budget?
CREATE TABLE Programs (ProgramName VARCHAR(50),Budget DECIMAL(10,2)); INSERT INTO Programs (ProgramName,Budget) VALUES ('Education',15000.00),('Healthcare',22000.00),('Arts',10000.00);
SELECT ProgramName FROM Programs WHERE Budget > (SELECT AVG(Budget) FROM Programs);
List the names and locations of all marine mammal species in the Arctic.
CREATE TABLE marine_mammals (name VARCHAR(255),species VARCHAR(255),location VARCHAR(255)); INSERT INTO marine_mammals (name,species,location) VALUES ('Beluga Whale','Whale','Arctic'),('Polar Bear','Bear','Arctic');
SELECT name, location FROM marine_mammals WHERE location = 'Arctic';
What is the average price of garments, grouped by category, for those categories that have a total revenue greater than $100,000?
CREATE TABLE garments (id INT PRIMARY KEY,category VARCHAR(255)); CREATE TABLE sales (id INT PRIMARY KEY,garment_id INT,date DATE,quantity INT,price DECIMAL(5,2)); ALTER TABLE sales ADD FOREIGN KEY (garment_id) REFERENCES garments(id);
SELECT garments.category, AVG(sales.price) as avg_price FROM garments INNER JOIN sales ON garments.id = sales.garment_id GROUP BY garments.category HAVING SUM(sales.quantity*sales.price) > 100000;
For the tech_for_social_good table, return the project_name and budget_remaining for the row with the latest start_date, in descending order.
CREATE TABLE tech_for_social_good (project_name VARCHAR(255),budget_remaining FLOAT,start_date DATE);
SELECT project_name, budget_remaining FROM tech_for_social_good WHERE start_date = (SELECT MAX(start_date) FROM tech_for_social_good);
What is the number of hospitals and clinics in each city?
CREATE TABLE cities (city_id INT,city_name VARCHAR(255)); INSERT INTO cities VALUES (1,'CityA'),(2,'CityB'); CREATE TABLE hospitals (hospital_id INT,hospital_name VARCHAR(255),city_id INT); INSERT INTO hospitals VALUES (1,'Hospital1',1),(2,'Hospital2',2); CREATE TABLE clinics (clinic_id INT,clinic_name VARCHAR(255),cit...
SELECT cities.city_name, COUNT(hospitals.hospital_id) AS hospitals, COUNT(clinics.clinic_id) AS clinics FROM cities LEFT JOIN hospitals ON cities.city_id = hospitals.city_id LEFT JOIN clinics ON cities.city_id = clinics.city_id GROUP BY cities.city_name;
List the ports and the number of vessels that visited each port in the last month
CREATE TABLE Ports (PortID INT,PortName VARCHAR(50)); CREATE TABLE Visits (VisitID INT,PortID INT,VisitDate DATE); INSERT INTO Ports (PortID,PortName) VALUES (1,'PortA'),(2,'PortB'),(3,'PortC'); INSERT INTO Visits (VisitID,PortID,VisitDate) VALUES (1,1,'2022-01-05'),(2,1,'2022-01-10'),(3,2,'2022-01-15'),(4,3,'2022-01-2...
SELECT PortName, COUNT(*) FROM Ports INNER JOIN Visits ON Ports.PortID = Visits.PortID WHERE VisitDate >= DATEADD(month, -1, GETDATE()) GROUP BY PortName;
Who are the top 3 farmers in terms of total crop yield?
CREATE TABLE farmers (id INT,name VARCHAR(50),age INT); INSERT INTO farmers (id,name,age) VALUES (1,'James Brown',45); INSERT INTO farmers (id,name,age) VALUES (2,'Sara Johnson',50); INSERT INTO farmers (id,name,age) VALUES (3,'Maria Garcia',55); INSERT INTO farmers (id,name,age) VALUES (4,'David White',60); CREATE TAB...
SELECT farmers.name, SUM(crops.yield) as total_yield FROM farmers INNER JOIN crops ON farmers.id = crops.farmer_id GROUP BY farmers.name ORDER BY total_yield DESC LIMIT 3;
How many users in Tokyo have a heart rate over 120 during their workouts in April 2022?
CREATE TABLE workouts (id INT,user_location VARCHAR(50),workout_date DATE,avg_heart_rate INT); INSERT INTO workouts (id,user_location,workout_date,avg_heart_rate) VALUES (1,'Tokyo','2022-04-01',130),(2,'Tokyo','2022-04-02',110);
SELECT COUNT(*) FROM workouts WHERE user_location = 'Tokyo' AND avg_heart_rate > 120 AND workout_date BETWEEN '2022-04-01' AND '2022-04-30';
What is the total number of government transparency initiatives in the last 2 years?
CREATE TABLE transparency_initiatives (initiative_date DATE,initiative_type VARCHAR(20)); INSERT INTO transparency_initiatives (initiative_date,initiative_type) VALUES ('2021-01-01','Fiscal Transparency'),('2021-02-01','Open Data'),('2021-03-01','Public Participation');
SELECT COUNT(*) FROM transparency_initiatives WHERE initiative_date >= DATEADD(year, -2, GETDATE());
Add a new column 'Age' to the 'Player' table and calculate it based on the 'Date_Joined' column
CREATE TABLE Player (Player_ID INT,Name VARCHAR(50),Date_Joined DATE); INSERT INTO Player (Player_ID,Name,Date_Joined) VALUES (1,'John Doe','2019-06-15'),(2,'Jane Smith','2020-03-08'),(3,'Alice Johnson','2021-02-22');
ALTER TABLE Player ADD Age INT; UPDATE Player SET Age = DATEDIFF(year, Date_Joined, GETDATE()) FROM Player;
Find the average age of athletes participating in the Olympics and Commonwealth Games.
CREATE TABLE athletes (id INT,name VARCHAR(50),age INT,sport VARCHAR(50),event VARCHAR(50)); INSERT INTO athletes (id,name,age,sport,event) VALUES (1,'John Doe',25,'Athletics','Olympics'),(2,'Jane Smith',30,'Swimming','Commonwealth Games'),(3,'Richard Roe',28,'Athletics','Commonwealth Games');
SELECT AVG(age) FROM athletes WHERE event IN ('Olympics', 'Commonwealth Games');
How many refugee children are there in the 'refugee_support' table for 'Syria'?
CREATE TABLE refugee_support(id INT,age INT,location VARCHAR(255)); INSERT INTO refugee_support(id,age,location) VALUES (1,10,'Syria'),(2,25,'Iraq'),(3,12,'Syria');
SELECT COUNT(*) FROM refugee_support WHERE location = 'Syria' AND age < 18;
What is the average number of days it takes to process a return, for each store, in the past month?
CREATE TABLE returns (id INT,date DATE,store VARCHAR(50),days_to_process INT);
SELECT store, AVG(days_to_process) as avg_days_to_process FROM returns WHERE date >= DATEADD(month, -1, GETDATE()) GROUP BY store;
What is the number of unique devices affected by each vulnerability type in the last year?
CREATE TABLE device_vulnerabilities (id INT,device_id INT,device_type VARCHAR(255),vulnerability_type VARCHAR(255),year INT); INSERT INTO device_vulnerabilities (id,device_id,device_type,vulnerability_type,year) VALUES (1,1,'Laptop','SQL Injection',2021),(2,1,'Laptop','Cross-site Scripting',2021),(3,2,'Desktop','SQL In...
SELECT vulnerability_type, COUNT(DISTINCT device_id) as unique_devices FROM device_vulnerabilities WHERE year = 2021 GROUP BY vulnerability_type;
Find the number of wind power projects in India, Brazil, and South Africa with an investment over 200 million dollars.
CREATE TABLE wind_power_projects (id INT,name TEXT,country TEXT,investment_usd FLOAT); INSERT INTO wind_power_projects (id,name,country,investment_usd) VALUES (1,'São Vitor Wind Farm','Brazil',250.0);
SELECT COUNT(*) FROM wind_power_projects WHERE country IN ('India', 'Brazil', 'South Africa') AND investment_usd > 200000000.0;
What are the top 3 cruelty-free cosmetic brands by total sales in the USA?
CREATE TABLE brands (brand_id INT,brand_name TEXT,is_cruelty_free BOOLEAN,country TEXT); INSERT INTO brands (brand_id,brand_name,is_cruelty_free,country) VALUES (1,'Lush',TRUE,'USA'),(2,'The Body Shop',TRUE,'UK'),(3,'Estee Lauder',FALSE,'USA');
SELECT brand_name, SUM(sales) as total_sales FROM brands JOIN sales_data ON brands.brand_id = sales_data.brand_id WHERE country = 'USA' AND is_cruelty_free = TRUE GROUP BY brand_name ORDER BY total_sales DESC LIMIT 3;
What is the total weight of freight forwarded from Canada to Australia?
CREATE TABLE Freight (id INT,item VARCHAR(50),weight FLOAT,country VARCHAR(50)); INSERT INTO Freight (id,item,weight,country) VALUES (1,'Gizmo',15.3,'Canada'),(2,'Gadget',22.8,'Australia');
SELECT SUM(weight) FROM Freight f1 INNER JOIN Freight f2 ON f1.item = f2.item WHERE f1.country = 'Canada' AND f2.country = 'Australia';
List all space missions that failed
CREATE TABLE SpaceMissions (ID INT,MissionName VARCHAR(50),Success BOOLEAN); INSERT INTO SpaceMissions VALUES (1,'Apollo 11',true),(2,'Apollo 13',false);
SELECT * FROM SpaceMissions WHERE Success = false;
Identify the consumer sentiment trend for ethical fashion in the last 3 months.
CREATE TABLE consumer_sentiment (date DATE,sentiment INT); INSERT INTO consumer_sentiment (date,sentiment) VALUES ('2022-01-01',75),('2022-01-02',78),('2022-01-03',82),('2022-02-01',80),('2022-02-02',85),('2022-02-03',88),('2022-03-01',90),('2022-03-02',92),('2022-03-03',95);
SELECT date, sentiment, LAG(sentiment, 2) OVER (ORDER BY date) as lagged_sentiment FROM consumer_sentiment;
What is the average amount of humanitarian assistance provided per quarter in 2020?
CREATE TABLE humanitarian_assistance (id INT,quarter INT,year INT,amount FLOAT); INSERT INTO humanitarian_assistance (id,quarter,year,amount) VALUES (1,1,2018,125000),(2,1,2019,137500),(3,1,2020,150000),(4,2,2020,162500),(5,3,2020,175000),(6,4,2020,187500);
SELECT AVG(amount) FROM humanitarian_assistance WHERE year = 2020;
What is the minimum number of pharmacotherapy sessions attended by patients with depression in France?
CREATE TABLE pharmacotherapy (pharmacotherapy_id INT,patient_id INT,condition VARCHAR(50),country VARCHAR(50),num_sessions INT); INSERT INTO pharmacotherapy (pharmacotherapy_id,patient_id,condition,country,num_sessions) VALUES (1,15,'Depression','France',4),(2,16,'Depression','France',6),(3,17,'Depression','France',5);
SELECT MIN(num_sessions) FROM pharmacotherapy WHERE country = 'France' AND condition = 'Depression';
What is the minimum permit issuance delay in the North region for residential projects?
CREATE TABLE permit_delay_north (delay_id INT,region VARCHAR(50),project_type VARCHAR(50),delay INT); INSERT INTO permit_delay_north (delay_id,region,project_type,delay) VALUES (1,'North','Residential',5);
SELECT MIN(delay) FROM permit_delay_north WHERE region = 'North' AND project_type = 'Residential';
List hospitals in Nairobi with their capacity and the number of patients vaccinated at each.
CREATE TABLE hospitals (id INT,name VARCHAR(50),location VARCHAR(50),capacity INT); INSERT INTO hospitals (id,name,location,capacity) VALUES (7,'Nairobi Hospital','Nairobi',600); CREATE TABLE patient_vaccinations (id INT,hospital_id INT,patient_id INT,date DATE); INSERT INTO patient_vaccinations (id,hospital_id,patient...
SELECT hospitals.name, hospitals.capacity, COUNT(patient_vaccinations.patient_id) FROM hospitals LEFT JOIN patient_vaccinations ON hospitals.id = patient_vaccinations.hospital_id WHERE hospitals.location = 'Nairobi' GROUP BY hospitals.name;
Find the number of electric cars sold, leased, and total for each manufacturer in the 'auto_sales' table.
CREATE TABLE auto_sales (id INT,manufacturer VARCHAR(20),sale_type VARCHAR(10),vehicle_type VARCHAR(10)); INSERT INTO auto_sales (id,manufacturer,sale_type,vehicle_type) VALUES (1,'Tesla','Sold','EV'),(2,'Toyota','Leased','Hybrid'),(3,'Tesla','Sold','EV'),(4,'Nissan','Leased','EV');
SELECT manufacturer, COUNT(*) FILTER (WHERE sale_type = 'Sold' AND vehicle_type = 'EV') AS sold, COUNT(*) FILTER (WHERE sale_type = 'Leased' AND vehicle_type = 'EV') AS leased, COUNT(*) AS total FROM auto_sales GROUP BY manufacturer;
Which male reporters aged 30 or above are assigned to investigative projects?
CREATE TABLE reporters (id INT,name VARCHAR(255),gender VARCHAR(10),age INT,country VARCHAR(100)); CREATE TABLE investigative_projects (id INT,title VARCHAR(255),reporter_id INT,status VARCHAR(20),start_date DATE,end_date DATE); INSERT INTO reporters (id,name,gender,age,country) VALUES (3,'Alex Garcia','Male',32,'Mexic...
SELECT reporters.name, reporters.gender, reporters.age FROM reporters INNER JOIN investigative_projects ON reporters.id = investigative_projects.reporter_id WHERE reporters.gender = 'Male' AND reporters.age >= 30;
What is the maximum budget for all projects in the infrastructure development database?
CREATE TABLE if not exists Projects (id INT,name VARCHAR(50),type VARCHAR(50),budget DECIMAL(10,2)); INSERT INTO Projects (id,name,type,budget) VALUES (1,'Seawall','Resilience',5000000.00),(2,'Floodgate','Resilience',3000000.00),(3,'Bridge','Transportation',8000000.00),(4,'Highway','Transportation',12000000.00);
SELECT MAX(budget) FROM Projects;
What is the maximum value of military equipment sold in a single transaction?
CREATE TABLE MilitaryEquipmentSales (id INT PRIMARY KEY,year INT,country VARCHAR(50),equipment VARCHAR(50),value FLOAT); INSERT INTO MilitaryEquipmentSales (id,year,country,equipment,value) VALUES (1,2022,'USA','Ships',50000000);
SELECT MAX(value) FROM MilitaryEquipmentSales;
What is the number of students and teachers in each school?
CREATE TABLE students (student_id INT,student_name VARCHAR(50),school_id INT); INSERT INTO students (student_id,student_name,school_id) VALUES (1,'John Doe',1001),(2,'Jane Smith',1001),(3,'Mike Johnson',1002); CREATE TABLE teachers (teacher_id INT,teacher_name VARCHAR(50),school_id INT); INSERT INTO teachers (teacher_i...
SELECT school_id, COUNT(DISTINCT s.student_id) as student_count, COUNT(DISTINCT t.teacher_id) as teacher_count FROM students s FULL OUTER JOIN teachers t ON s.school_id = t.school_id GROUP BY school_id;
Rank the top 3 construction labor statistics by frequency in the South?
CREATE TABLE South_LS (statistic VARCHAR(30),frequency INT); INSERT INTO South_LS VALUES ('Hourly wage',5000),('Overtime hours',3000),('Safety incidents',1500);
SELECT statistic, ROW_NUMBER() OVER (ORDER BY frequency DESC) as rank FROM South_LS WHERE rank <= 3;
What is the average water temperature for the Tilapia farm in the last 7 days?
CREATE TABLE FarmTemperature (farm_id INT,date DATE,temperature DECIMAL(5,2)); INSERT INTO FarmTemperature (farm_id,date,temperature) VALUES (1,'2022-03-01',26.2),(1,'2022-03-02',26.3);
SELECT AVG(temperature) avg_temp FROM FarmTemperature WHERE farm_id = 1 AND date >= (SELECT DATEADD(day, -7, GETDATE()));
What is the most common severity of mental health issues reported in the student_mental_health table?
CREATE TABLE student_mental_health (id INT,student_id INT,issue VARCHAR(50),severity VARCHAR(50));
SELECT severity, COUNT(*) FROM student_mental_health GROUP BY severity ORDER BY COUNT(*) DESC LIMIT 1;
How many students are enrolled in each department?
CREATE TABLE enrollment (id INT,student_id INT,department VARCHAR(50)); INSERT INTO enrollment (id,student_id,department) VALUES (1,1,'Computer Science'),(2,2,'Computer Science'),(3,3,'Mathematics'),(4,4,'Physics');
SELECT department, COUNT(DISTINCT student_id) FROM enrollment GROUP BY department;
What is the total number of visitors from the 'United States' and 'Canada'?
CREATE TABLE visitors (id INT,country VARCHAR(255),exhibition_id INT); INSERT INTO visitors (id,country,exhibition_id) VALUES (1,'United States',1),(2,'Canada',1),(3,'Mexico',1),(4,'United States',2),(5,'Canada',2),(6,'Brazil',2),(7,'United States',3),(8,'Canada',3); CREATE TABLE exhibitions (id INT,name VARCHAR(255),t...
SELECT COUNT(*) FROM visitors WHERE country IN ('United States', 'Canada');
Present the earliest and latest arrival times for tanker cargo types in the Port of Rotterdam.
CREATE TABLE ROTTERDAM_PORT_CALLS (ID INT,PORT_CALL_ID INT,CARGO_TYPE VARCHAR(50),ARRIVAL DATETIME); INSERT INTO ROTTERDAM_PORT_CALLS VALUES (1,1,'Crude Oil','2021-12-01 12:00:00'); INSERT INTO ROTTERDAM_PORT_CALLS VALUES (2,2,'Gasoline','2021-12-03 06:00:00');
SELECT CARGO_TYPE, MIN(ARRIVAL) AS EARLIEST_ARRIVAL, MAX(ARRIVAL) AS LATEST_ARRIVAL FROM ROTTERDAM_PORT_CALLS JOIN PORT_CALLS ON ROTTERDAM_PORT_CALLS.PORT_CALL_ID = PORT_CALLS.ID WHERE PORT = 'Port of Rotterdam' AND CARGO_TYPE LIKE 'Tanker%' GROUP BY CARGO_TYPE
How many students are enrolled in the 'AssistiveTechnology' and 'SignLanguageInterpreter' programs in the 'StudentPrograms' table?
CREATE TABLE StudentPrograms (student_id INT,program_name VARCHAR(255)); INSERT INTO StudentPrograms (student_id,program_name) VALUES (1,'AssistiveTechnology'),(2,'SignLanguageInterpreter'),(3,'ExtendedTestingTime'),(4,'AssistiveTechnology'),(5,'ExtendedTestingTime');
SELECT COUNT(*) FROM StudentPrograms WHERE program_name IN ('AssistiveTechnology', 'SignLanguageInterpreter');
Show production rates for machines in the textile manufacturing industry, ordered from highest to lowest.
CREATE TABLE machine_data (machine_type VARCHAR(50),industry VARCHAR(50),production_rate FLOAT); INSERT INTO machine_data (machine_type,industry,production_rate) VALUES ('Automated Cutting Machine','Textile',120),('Sewing Machine','Textile',90),('Knitting Machine','Textile',80),('Automated Folding Machine','Textile',70...
SELECT machine_type, production_rate FROM machine_data WHERE industry = 'Textile' ORDER BY production_rate DESC;
What was the total donation amount by new donors in Q1 2023?
CREATE TABLE donors (donor_id INT,donation_date DATE,donation_amount DECIMAL(10,2)); INSERT INTO donors VALUES (11,'2023-01-02',200.00),(12,'2023-03-10',300.00),(13,'2023-01-15',100.00);
SELECT SUM(donation_amount) FROM donors WHERE donor_id IN (SELECT donor_id FROM donors WHERE donation_date BETWEEN '2023-01-01' AND '2023-03-31' GROUP BY donor_id HAVING COUNT(*) = 1);
What is the total investment in rural infrastructure in Southeast Asia?
CREATE TABLE project (id INT,name TEXT,location TEXT,investment_amount INT,year INT); INSERT INTO project (id,name,location,investment_amount,year) VALUES (1,'Northern Highway','India',2000000,2020),(2,'Southern Railway','Vietnam',1500000,2019),(3,'Central Dam','Indonesia',2500000,2018),(4,'Eastern Irrigation','Nepal',...
SELECT SUM(investment_amount) FROM project WHERE location LIKE 'Southeast%';