instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
List the top 5 socially responsible lending programs by total amount disbursed in Canada, for the year 2019.
CREATE TABLE socially_responsible_lending (program_id INT,program_name VARCHAR(255),amount_disbursed DECIMAL(10,2),disbursement_date DATE,country VARCHAR(255));
SELECT program_name, SUM(amount_disbursed) as total_amount FROM socially_responsible_lending WHERE country = 'Canada' AND YEAR(disbursement_date) = 2019 GROUP BY program_name ORDER BY total_amount DESC LIMIT 5;
What is the average temperature and humidity for each crop type in the past week?
CREATE TABLE crop (type TEXT,temperature FLOAT,humidity FLOAT,date DATE);
SELECT c.type, AVG(c.temperature) as avg_temp, AVG(c.humidity) as avg_hum FROM crop c WHERE c.date >= DATEADD(day, -7, CURRENT_DATE) GROUP BY c.type;
Insert a new menu item 'Impossible Burger' with a price of $12.99 into the menu_items table
CREATE TABLE menu_items (menu_item_id INT,name VARCHAR(50),category VARCHAR(50),price DECIMAL(5,2)); INSERT INTO menu_items (menu_item_id,name,category,price) VALUES (1,'Cheeseburger','Main',9.99),(2,'Lobster Roll','Main',19.99);
INSERT INTO menu_items (menu_item_id, name, category, price) VALUES (3, 'Impossible Burger', 'Main', 12.99);
Which countries in the Middle East have reported the most climate mitigation efforts in the last 3 years?
CREATE TABLE climate_mitigation (id INT,country VARCHAR(50),year INT,efforts VARCHAR(50)); INSERT INTO climate_mitigation (id,country,year,efforts) VALUES (1,'Saudi Arabia',2020,'renewable energy');
SELECT country, COUNT(*) as num_efforts FROM climate_mitigation WHERE year BETWEEN (YEAR(CURRENT_DATE) - 3) AND YEAR(CURRENT_DATE) GROUP BY country ORDER BY num_efforts DESC;
How many unique hotels are there in the 'Boutique' category with at least one booking?
CREATE TABLE Hotels (hotel_id INT,hotel_name VARCHAR(100),category VARCHAR(50)); CREATE TABLE Bookings (booking_id INT,hotel_id INT,booking_date DATE,revenue FLOAT,channel VARCHAR(50)); INSERT INTO Hotels (hotel_id,hotel_name,category) VALUES (1,'Hotel A','Boutique'),(2,'Hotel B','Boutique'),(3,'Hotel C','Luxury'); INSERT INTO Bookings (booking_id,hotel_id,booking_date,revenue,channel) VALUES (1,1,'2022-01-01',200.0,'Direct'),(2,1,'2022-01-03',150.0,'OTA'),(3,2,'2022-01-05',300.0,'Direct');
SELECT COUNT(DISTINCT Hotels.hotel_id) FROM Hotels INNER JOIN Bookings ON Hotels.hotel_id = Bookings.hotel_id WHERE category = 'Boutique';
How many construction workers were involved in green projects in the city of Chicago in 2021?
CREATE TABLE Green_Projects (Project_ID INT,Building_Type VARCHAR(50),Cost FLOAT,City VARCHAR(50)); CREATE TABLE Labor_Statistics (Permit_ID INT,Worker_Count INT,Year INT); INSERT INTO Green_Projects (Project_ID,Building_Type,Cost,City) VALUES (1,'Green',1000,'Chicago'),(2,'Green',1500,'Chicago'); INSERT INTO Labor_Statistics (Permit_ID,Worker_Count,Year) VALUES (1,25,2021),(2,30,2021);
SELECT SUM(Worker_Count) FROM Green_Projects INNER JOIN Labor_Statistics ON Green_Projects.Project_ID = Labor_Statistics.Permit_ID WHERE City = 'Chicago' AND Year = 2021;
What is the success rate of the support group program?
CREATE TABLE support_groups (id INT,patient_id INT,attendance BOOLEAN,improvement BOOLEAN);
SELECT 100.0 * AVG(CASE WHEN improvement THEN 1 ELSE 0 END) as success_rate FROM support_groups WHERE attendance = TRUE;
What are the details of the smart contract '0x789...', if any, in the 'contracts' table?
CREATE TABLE contracts (id INT,contract_address VARCHAR(50),contract_name VARCHAR(50),creator VARCHAR(50),language VARCHAR(20)); INSERT INTO contracts (id,contract_address,contract_name,creator,language) VALUES (1,'0x789...','DappToken','JDoe','Solidity'),(2,'0xabc...','MyContract','JDoe','Vyper');
SELECT * FROM contracts WHERE contract_address = '0x789...';
Identify all pipelines in Canada and their lengths
CREATE TABLE pipelines (pipeline_name VARCHAR(50),country VARCHAR(50),length INT); INSERT INTO pipelines (pipeline_name,country,length) VALUES ('Keystone XL','Canada',1900),('Energy East','Canada',4600);
SELECT pipeline_name, length FROM pipelines WHERE country = 'Canada';
What is the average speed of autonomous ferries in Norway?
CREATE TABLE if not exists Ferries (id INT,type VARCHAR(20),country VARCHAR(20),speed FLOAT); INSERT INTO Ferries (id,type,country,speed) VALUES (1,'Autonomous','Norway',20.5),(2,'Manual','Norway',18.3),(3,'Autonomous','Norway',22.1);
SELECT AVG(speed) FROM Ferries WHERE type = 'Autonomous' AND country = 'Norway';
Display the names of teachers who teach in 'California' from the 'teachers' table
CREATE TABLE teachers (teacher_id INT,name VARCHAR(50),state VARCHAR(20));
SELECT name FROM teachers WHERE state = 'California';
What is the total carbon pricing revenue in Texas in 2019?
CREATE TABLE carbon_pricing_texas (id INT,year INT,revenue FLOAT); INSERT INTO carbon_pricing_texas (id,year,revenue) VALUES (1,2019,200.0),(2,2018,180.0);
SELECT SUM(revenue) FROM carbon_pricing_texas WHERE year = 2019;
How many fish are there in total in the Tilapia_Harvest table?
CREATE TABLE Tilapia_Harvest (Harvest_ID INT,Farm_ID INT,Harvest_Date DATE,Quantity_Harvested INT); INSERT INTO Tilapia_Harvest (Harvest_ID,Farm_ID,Harvest_Date,Quantity_Harvested) VALUES (1,1,'2021-06-01',5000),(2,2,'2021-06-15',7000),(3,1,'2021-07-01',5500);
SELECT SUM(Quantity_Harvested) FROM Tilapia_Harvest;
Identify the top 3 cities with the highest number of renewable energy projects in the 'RenewableEnergyProjects' table.
CREATE TABLE RenewableEnergyProjects (id INT,project_name VARCHAR(50),city VARCHAR(50),project_type VARCHAR(50));
SELECT city, COUNT(*) as project_count FROM RenewableEnergyProjects GROUP BY city ORDER BY project_count DESC LIMIT 3;
How many students have completed the online_course?
CREATE TABLE online_course (id INT,student_id INT,course_name VARCHAR(50),completed BOOLEAN);
SELECT COUNT(*) FROM online_course WHERE completed = TRUE;
Show the 5 most recent transactions for Shariah-compliant finance, including the transaction amount and date.
CREATE TABLE shariah_transactions (id INT,amount DECIMAL(10,2),date DATE); INSERT INTO shariah_transactions (id,amount,date) VALUES (1,500.00,'2022-01-01'),(2,700.00,'2022-02-01'),(3,300.00,'2022-03-01');
SELECT amount, date FROM shariah_transactions ORDER BY date DESC LIMIT 5;
What is the policy count for each state?
CREATE TABLE policies (id INT,policyholder_id INT,state TEXT); INSERT INTO policies (id,policyholder_id,state) VALUES (1,1,'CA'); INSERT INTO policies (id,policyholder_id,state) VALUES (2,2,'CA'); INSERT INTO policies (id,policyholder_id,state) VALUES (3,3,'NY'); INSERT INTO policies (id,policyholder_id,state) VALUES (4,4,'TX'); INSERT INTO policies (id,policyholder_id,state) VALUES (5,5,'FL'); INSERT INTO policies (id,policyholder_id,state) VALUES (6,6,'CA');
SELECT state, COUNT(*) FROM policies GROUP BY state;
What is the average sustainability rating for brands that use organic cotton?
CREATE TABLE BRAND_SUSTAINABILITY (id INT PRIMARY KEY,brand_id INT,uses_organic_cotton BOOLEAN,sustainability_rating FLOAT); CREATE TABLE SUSTAINABILITY_RATINGS (id INT PRIMARY KEY,brand_id INT,rating FLOAT,rating_date DATE);
SELECT AVG(sustainability_rating) FROM BRAND_SUSTAINABILITY JOIN SUSTAINABILITY_RATINGS ON BRAND_SUSTAINABILITY.brand_id = SUSTAINABILITY_RATINGS.brand_id WHERE uses_organic_cotton = TRUE;
What was the total number of donations made in Q3 2020 and Q4 2020, and the average donation amount in each quarter?
CREATE TABLE donations (id INT,donation_date DATE,donation_amount DECIMAL(10,2)); INSERT INTO donations (id,donation_date,donation_amount) VALUES (1,'2020-10-01',50.00),(2,'2020-12-15',100.00);
SELECT QUARTER(donation_date) AS quarter, COUNT(*) AS num_donations, AVG(donation_amount) AS avg_donation_amount FROM donations WHERE YEAR(donation_date) = 2020 AND QUARTER(donation_date) IN (3, 4) GROUP BY quarter;
How many 'Vegan' and 'Gluten-free' menu items are offered by each vendor?
CREATE TABLE Menu (MenuID INT,Name VARCHAR(50),Type VARCHAR(50),VendorID INT); INSERT INTO Menu (MenuID,Name,Type,VendorID) VALUES (1,'Veggie Burger','Vegan',1),(2,'Falafel Wrap','Vegan',1),(3,'Breadless Sandwich','Gluten-free',2);
SELECT VendorID, COUNT(CASE WHEN Type = 'Vegan' THEN 1 END) AS VeganCount, COUNT(CASE WHEN Type = 'Gluten-free' THEN 1 END) AS GlutenFreeCount FROM Menu GROUP BY VendorID;
Delete all beauty products that contain 'paraben'.
CREATE TABLE Products (product_id INT,name VARCHAR(100),ingredients TEXT); INSERT INTO Products (product_id,name,ingredients) VALUES (1,'Bamboo','water,titanium dioxide,paraben'),(2,'Ivory','water,zinc oxide,mica');
DELETE FROM Products WHERE ingredients LIKE '%paraben%';
What is the maximum number of points scored by a player in a single NBA game?
CREATE TABLE Players (PlayerID INT,PlayerName VARCHAR(100),Points INT); INSERT INTO Players (PlayerID,PlayerName,Points) VALUES (1,'Michael Jordan',69),(2,'Kobe Bryant',81),(3,'LeBron James',61);
SELECT MAX(Points) FROM Players;
What are the average temperatures and precipitation levels for each location in the Arctic Council countries' territories, excluding Svalbard?
CREATE TABLE arctic_council_climate (id INT,location VARCHAR(50),temperature FLOAT,precipitation FLOAT,country VARCHAR(50)); INSERT INTO arctic_council_climate (id,location,temperature,precipitation,country) VALUES (1,'Utqiaġvik',-20.5,0.0,'USA'),(2,'Tuktoyaktuk',-25.0,12.0,'Canada');
SELECT country, location, AVG(temperature), AVG(precipitation) FROM arctic_council_climate WHERE country NOT IN ('Svalbard') GROUP BY country, location;
What is the maximum trip duration for Indian tourists visiting Singapore?
CREATE TABLE tourism_stats (id INT PRIMARY KEY,country VARCHAR(255),destination VARCHAR(255),duration INT); INSERT INTO tourism_stats (id,country,destination,duration) VALUES (1,'India','Singapore',14),(2,'India','Singapore',21),(3,'India','Singapore',10);
SELECT MAX(duration) FROM tourism_stats WHERE country = 'India' AND destination = 'Singapore';
What is the maximum expenditure by a single tourist from South Africa in Cape Town?
CREATE TABLE tourism_stats (visitor_country VARCHAR(20),destination VARCHAR(20),expenditure DECIMAL(10,2)); INSERT INTO tourism_stats (visitor_country,destination,expenditure) VALUES ('South Africa','Cape Town',1200.00),('South Africa','Cape Town',1500.00),('South Africa','Cape Town',1000.00);
SELECT MAX(expenditure) FROM tourism_stats WHERE visitor_country = 'South Africa' AND destination = 'Cape Town';
What is the latest artifact analysis date for each artifact type?
CREATE TABLE Analysis (AnalysisID INT,ArtifactID INT,ArtifactType TEXT,AnalysisDate DATE); INSERT INTO Analysis (AnalysisID,ArtifactID,ArtifactType,AnalysisDate) VALUES (1,1,'Pottery','2011-01-10'); INSERT INTO Analysis (AnalysisID,ArtifactID,ArtifactType,AnalysisDate) VALUES (2,1,'Pottery','2011-02-05'); INSERT INTO Analysis (AnalysisID,ArtifactID,ArtifactType,AnalysisDate) VALUES (3,2,'Bone','2011-03-15');
SELECT ArtifactType, MAX(AnalysisDate) OVER (PARTITION BY ArtifactType) AS LatestAnalysisDate FROM Analysis;
What are the differences in ethical manufacturing practices between factories in the same region?
CREATE TABLE factories (factory_id INT,name TEXT,location TEXT,ethical_manufacturing BOOLEAN); INSERT INTO factories (factory_id,name,location,ethical_manufacturing) VALUES (1,'Factory A','City A',true),(2,'Factory B','City A',true),(3,'Factory C','City B',false);
SELECT f1.name AS factory1, f2.name AS factory2, f1.ethical_manufacturing AS ethical_practice1, f2.ethical_manufacturing AS ethical_practice2 FROM factories f1 JOIN factories f2 ON f1.location = f2.location WHERE f1.factory_id <> f2.factory_id;
Show the number of unique product categories for suppliers in India.
CREATE TABLE suppliers (supplier_id INT,supplier_name TEXT,country TEXT,product_category TEXT); INSERT INTO suppliers (supplier_id,supplier_name,country,product_category) VALUES (101,'Supplier 1','India','Category 1'),(102,'Supplier 2','India','Category 2'),(103,'Supplier 3','USA','Category 1'),(104,'Supplier 4','USA','Category 3');
SELECT COUNT(DISTINCT product_category) FROM suppliers WHERE country = 'India';
What is the total funding received by 'Indigenous Arts Program' in the year 2022?
CREATE TABLE FundingHistory (funding_program VARCHAR(50),funding_amount INT,funding_year INT); INSERT INTO FundingHistory (funding_program,funding_amount,funding_year) VALUES ('Indigenous Arts Program',50000,2022); INSERT INTO FundingHistory (funding_program,funding_amount,funding_year) VALUES ('Indigenous Arts Program',55000,2023);
SELECT SUM(funding_amount) FROM FundingHistory WHERE funding_program = 'Indigenous Arts Program' AND funding_year = 2022;
What is the percentage of the population without health insurance in Texas by race?
CREATE TABLE health_insurance (id INT,state TEXT,race TEXT,no_insurance BOOLEAN); INSERT INTO health_insurance (id,state,race,no_insurance) VALUES (1,'Texas','White',FALSE),(2,'Texas','Hispanic',TRUE),(3,'Texas','Black',FALSE),(4,'California','Asian',FALSE);
SELECT race, COUNT(*) * 100.0 / (SELECT COUNT(*) FROM health_insurance WHERE state = 'Texas') AS percentage FROM health_insurance WHERE state = 'Texas' AND no_insurance = TRUE GROUP BY race;
What is the total CO2 emissions reduction from renewable energy projects in California since 2010?
CREATE TABLE projects (id INT,state VARCHAR(255),name VARCHAR(255),co2_emissions_reduction INT,start_year INT); INSERT INTO projects (id,state,name,co2_emissions_reduction,start_year) VALUES (1,'California','Project1',10000,2010),(2,'California','Project2',15000,2012);
SELECT SUM(co2_emissions_reduction) FROM projects WHERE state = 'California' AND start_year <= 2010;
Find all satellites launched before 2010 and their respective launch site.
CREATE TABLE Satellite_Launches (satellite_id INT,launch_year INT,launch_site VARCHAR(255)); INSERT INTO Satellite_Launches (satellite_id,launch_year,launch_site) VALUES (1,2012,'Kourou'),(2,2008,'Vandenberg'),(3,2015,'Baikonur'),(4,2005,'Plesetsk');
SELECT s.satellite_id, s.launch_site FROM Satellite_Launches s WHERE s.launch_year < 2010;
What is the average salary of male and female employees, partitioned by department?
CREATE TABLE Employees (EmployeeID INT,Gender VARCHAR(10),Department VARCHAR(20),Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID,Gender,Department,Salary) VALUES (1,'Male','IT',80000.00),(2,'Female','IT',75000.00),(3,'Non-binary','HR',70000.00),(4,'Male','HR',78000.00);
SELECT Department, AVG(Salary) OVER (PARTITION BY Department, Gender) AS Avg_Salary FROM Employees;
What is the average budget for technology for social good projects in the LATAM region?
CREATE TABLE tech_social_good_latam (project VARCHAR(255),budget FLOAT,region VARCHAR(255)); INSERT INTO tech_social_good_latam (project,budget,region) VALUES ('Project L',900000,'LATAM'),('Project M',750000,'LATAM'),('Project N',800000,'APAC');
SELECT region, AVG(budget) AS avg_budget FROM tech_social_good_latam WHERE region = 'LATAM';
What is the mortality rate due to COVID-19 in Brazil?
CREATE TABLE countries (id INT PRIMARY KEY,name VARCHAR(255),continent VARCHAR(255)); INSERT INTO countries (id,name,continent) VALUES (1,'Afghanistan','Asia'); CREATE TABLE covid_data (id INT PRIMARY KEY,country_id INT,date DATE,mortality_rate DECIMAL(3,2)); INSERT INTO covid_data (id,country_id,date,mortality_rate) VALUES (1,1,'2020-03-01',0.5),(2,1,'2020-03-02',0.6);
SELECT mortality_rate FROM covid_data WHERE country_id = (SELECT id FROM countries WHERE name = 'Brazil') ORDER BY date DESC LIMIT 1;
Which indigenous community in the Arctic has the largest population?
CREATE TABLE arctic_communities(id INT,name VARCHAR(50),population INT); INSERT INTO arctic_communities(id,name,population) VALUES (1,'Inuit',150000),(2,'Sami',80000),(3,'Yupik',40000),(4,'Chukchi',50000);
SELECT name, population FROM arctic_communities WHERE population = (SELECT MAX(population) FROM arctic_communities);
Delete all food safety violations recorded before 2020.
CREATE TABLE Inspections (id INT,violation_date DATE,description VARCHAR(255));
DELETE FROM Inspections WHERE violation_date < '2020-01-01';
What is the average sale price for non-sustainable garments?
CREATE TABLE sales (item_type VARCHAR(20),sustainable BOOLEAN,price FLOAT); INSERT INTO sales (item_type,sustainable,price) VALUES ('sustainable_jeans',true,35.0),('sustainable_t_shirt',true,20.0),('sustainable_skirt',true,25.0),('jeans',false,40.0);
SELECT AVG(price) as avg_price FROM sales WHERE sustainable = false;
What is the maximum trip duration for Mexican tourists visiting Africa in 2023?
CREATE TABLE tourism_stats (id INT PRIMARY KEY,year INT,country VARCHAR(255),destination VARCHAR(255),duration INT); INSERT INTO tourism_stats (id,year,country,destination,duration) VALUES (1,2023,'Mexico','Kenya',15),(2,2023,'Mexico','South Africa',22),(3,2023,'Mexico','Egypt',17);
SELECT MAX(duration) FROM tourism_stats WHERE country = 'Mexico' AND destination LIKE 'Africa%' AND year = 2023;
What is the wind_speed of the turbine with the lowest id?
CREATE TABLE wind_speed (id INT,turbine_id INT,wind_speed FLOAT);
SELECT MIN(wind_speed) AS min_wind_speed FROM wind_speed WHERE id = (SELECT MIN(id) FROM wind_speed);
Which countries received climate adaptation funding over 1 million in 2018?
CREATE TABLE adaptation_funding (year INT,country VARCHAR(255),amount FLOAT); INSERT INTO adaptation_funding VALUES (2018,'Bangladesh',1500000);
SELECT country FROM adaptation_funding WHERE year = 2018 AND amount > 1000000;
What is the total token supply for all decentralized exchanges on the Polygon network, and how many of them have a trading volume greater than 1 million?
CREATE TABLE polygon_decentralized_exchanges (exchange_id INT,token_supply DECIMAL(30,0),trading_volume DECIMAL(30,0)); INSERT INTO polygon_decentralized_exchanges (exchange_id,token_supply,trading_volume) VALUES (1,500000000,150000000),(2,750000000,200000000),(3,250000000,50000000),(4,100000000,120000000),(5,20000000,20000000);
SELECT SUM(token_supply), COUNT(*) FROM polygon_decentralized_exchanges WHERE trading_volume > 1000000;
What was the revenue for each day in the month of June 2022?
CREATE TABLE daily_revenue_2 (date DATE,revenue FLOAT); INSERT INTO daily_revenue_2 (date,revenue) VALUES ('2022-06-01',5000),('2022-06-02',6000),('2022-06-03',4000);
SELECT date, revenue FROM daily_revenue_2 WHERE date BETWEEN '2022-06-01' AND '2022-06-30';
How many volunteers signed up in each country in 2021?
CREATE TABLE volunteer_signups (volunteer_id INT,country VARCHAR(50),signup_date DATE); INSERT INTO volunteer_signups (volunteer_id,country,signup_date) VALUES (4,'Canada','2021-01-01'),(5,'Mexico','2021-02-01'),(6,'Brazil','2021-03-01'),(7,'USA','2021-04-01');
SELECT country, COUNT(volunteer_id) as total_volunteers FROM volunteer_signups WHERE YEAR(signup_date) = 2021 GROUP BY country;
What is the total number of matches played in "Virtual Reality Chess"?
CREATE TABLE Matches (MatchID INT,PlayerID INT,Game VARCHAR(50),Wins INT); INSERT INTO Matches (MatchID,PlayerID,Game,Wins) VALUES (1,1,'Virtual Reality Chess',10),(2,1,'Virtual Reality Chess',12),(3,2,'Virtual Reality Chess',15),(4,3,'Virtual Reality Chess',18);
SELECT SUM(1) FROM Matches WHERE Game = 'Virtual Reality Chess';
What is the total number of building permits issued in the city of Seattle in 2020?
CREATE TABLE building_permits (permit_id INT,city VARCHAR(20),year INT,permits_issued INT); INSERT INTO building_permits (permit_id,city,year,permits_issued) VALUES (1,'Seattle',2020,5000),(2,'Seattle',2019,4500),(3,'New York',2020,7000),(4,'Los Angeles',2020,6000);
SELECT SUM(permits_issued) FROM building_permits WHERE city = 'Seattle' AND year = 2020;
What is the oldest patient's age in the 'rural_hospital_2' table?
CREATE TABLE rural_hospital_2 (patient_id INT,age INT,gender VARCHAR(10)); INSERT INTO rural_hospital_2 (patient_id,age,gender) VALUES (1,65,'Male'),(2,45,'Female'),(3,70,'Male'),(4,55,'Female');
SELECT MAX(age) FROM rural_hospital_2;
Show the number of factories in each country that have implemented ethical manufacturing practices, along with their respective countries.
CREATE TABLE factories_ethical (id INT,country VARCHAR(20)); CREATE TABLE factories (id INT,name VARCHAR(50),country VARCHAR(20)); INSERT INTO factories_ethical (id,country) VALUES (1,'USA'),(2,'China'),(3,'India'),(4,'Germany'); INSERT INTO factories (id,name,country) VALUES (1,'Factory A','USA'),(2,'Factory B','China'),(3,'Factory C','India'),(4,'Factory D','Germany'),(5,'Factory E','USA'),(6,'Factory F','China'),(7,'Factory G','India'),(8,'Factory H','Germany');
SELECT f.country, COUNT(*) FROM factories f INNER JOIN factories_ethical e ON f.country = e.country GROUP BY f.country;
Count the number of building permits issued in NYC for projects with a timeline over 6 months.
CREATE TABLE building_permits (id INT,city VARCHAR(50),timeline INT); INSERT INTO building_permits (id,city,timeline) VALUES (1,'NYC',7),(2,'LA',5),(3,'NYC',8),(4,'CHI',4);
SELECT COUNT(*) FROM building_permits WHERE city = 'NYC' AND timeline > 6;
Find the difference in costs between the first and last project in 'Road_Infrastructure' table.
CREATE TABLE Road_Infrastructure (id INT,project_name VARCHAR(50),location VARCHAR(50),cost INT);
SELECT (MAX(cost) - MIN(cost)) AS cost_difference FROM (SELECT cost FROM Road_Infrastructure ORDER BY id LIMIT 1 OFFSET 1) AS first_project CROSS JOIN (SELECT cost FROM Road_Infrastructure ORDER BY id DESC LIMIT 1) AS last_project;
Update the age of the patient with ID 1 to 35 in the 'patients' table.
CREATE TABLE patients (patient_id INT PRIMARY KEY AUTO_INCREMENT,first_name VARCHAR(50),last_name VARCHAR(50),age INT,gender VARCHAR(10),ethnicity VARCHAR(50));
UPDATE patients SET age = 35 WHERE patient_id = 1;
How many units of each sustainable fabric type do we have in stock?
CREATE TABLE Stock (StockID INT,FabricID INT,Quantity INT); INSERT INTO Stock (StockID,FabricID,Quantity) VALUES (1,1,50),(2,2,75),(3,3,100);
SELECT Fabrics.FabricName, Stock.Quantity FROM Fabrics INNER JOIN Stock ON Fabrics.FabricID = Stock.FabricID WHERE Fabrics.IsSustainable = TRUE;
How many restaurants serve Indian food and have a revenue greater than $6000?
CREATE TABLE Restaurants (id INT,name TEXT,type TEXT,revenue FLOAT); INSERT INTO Restaurants (id,name,type,revenue) VALUES (1,'Restaurant A','Italian',5000.00),(2,'Restaurant B','Indian',8000.00),(3,'Restaurant C','Indian',6500.00),(4,'Restaurant D','Indian',7000.00);
SELECT COUNT(*) FROM Restaurants WHERE type = 'Indian' AND revenue > 6000;
Update the ethnicity of 'John Doe' to 'Hispanic' in 'clinic_NYC'.
CREATE TABLE clinic_NYC (patient_id INT,name VARCHAR(50),ethnicity VARCHAR(50)); INSERT INTO clinic_NYC (patient_id,name,ethnicity) VALUES (1,'John Doe','Caucasian'),(2,'Jane Smith','African American');
UPDATE clinic_NYC SET ethnicity = 'Hispanic' WHERE patient_id = 1;
Delete the 'Oceanic Whitetip Shark' record from the 'marine_species' table if its maximum depth is greater than 300 meters.
CREATE TABLE marine_species (id INT,species_name VARCHAR(50),habitat_depth FLOAT); INSERT INTO marine_species (id,species_name,habitat_depth) VALUES (1,'Green Sea Turtle',50.0),(2,'Clownfish',20.0),(3,'Oceanic Whitetip Shark',350.0);
DELETE FROM marine_species WHERE species_name = 'Oceanic Whitetip Shark' AND habitat_depth > 300.0;
What's the total budget for programs led by female coordinators?
CREATE TABLE Programs (ProgramID INT PRIMARY KEY,ProgramName VARCHAR(50),CoordinatorGender VARCHAR(10),Budget DECIMAL(10,2)); INSERT INTO Programs (ProgramID,ProgramName,CoordinatorGender,Budget) VALUES (1,'Youth Empowerment','Female',8000.00); INSERT INTO Programs (ProgramID,ProgramName,CoordinatorGender,Budget) VALUES (2,'Environmental Conservation','Male',12000.00);
SELECT SUM(Budget) FROM Programs WHERE CoordinatorGender = 'Female';
What is the average budget per project for renewable energy infrastructure in each country, sorted by the highest average?
CREATE TABLE renewable_energy (id INT,name VARCHAR(255),country VARCHAR(255),technology VARCHAR(255),projects INT,budget FLOAT); INSERT INTO renewable_energy (id,name,country,technology,projects,budget) VALUES (1,'Solar Farm 1','USA','solar',5,5000000.0); INSERT INTO renewable_energy (id,name,country,technology,projects,budget) VALUES (2,'Wind Farm 2','USA','wind',8,12000000.0); INSERT INTO renewable_energy (id,name,country,technology,projects,budget) VALUES (3,'Geothermal Plant 3','Canada','geothermal',3,7500000.0); INSERT INTO renewable_energy (id,name,country,technology,projects,budget) VALUES (4,'Hydroelectric Dam 4','Canada','hydroelectric',6,18000000.0);
SELECT country, AVG(budget/projects) as avg_budget_per_project FROM renewable_energy GROUP BY country ORDER BY avg_budget_per_project DESC;
What were the names and locations of agricultural projects initiated in 2022?
CREATE TABLE AgriculturalProjects (id INT PRIMARY KEY,name VARCHAR(50),location VARCHAR(50),sector VARCHAR(20),start_date DATE,end_date DATE); INSERT INTO AgriculturalProjects (id,name,location,sector,start_date,end_date) VALUES (1,'Solar Irrigation','Rural Kenya','Agricultural Innovation','2020-01-01','2022-12-31'),(2,'Precision Farming','Rural Brazil','Agricultural Innovation','2021-01-01','2023-12-31'),(3,'Organic Farming','Rural India','Agricultural Innovation','2022-01-01','2024-12-31');
SELECT name, location FROM AgriculturalProjects WHERE start_date >= '2022-01-01' AND start_date < '2023-01-01';
Insert a new community development initiative in India, 'Fair Trade Marketing Support', started on '2022-06-01' with a budget of 150000.00 and a duration of 24 months.
CREATE TABLE community_initiatives (id INT,initiative_name VARCHAR(100),location VARCHAR(50),start_date DATE,end_date DATE,budget DECIMAL(10,2),duration INT);
INSERT INTO community_initiatives (id, initiative_name, location, start_date, end_date, budget, duration) VALUES (3, 'Fair Trade Marketing Support', 'India', '2022-06-01', '2024-05-31', 150000.00, 24);
How many farms in the 'agricultural_farms' table have more than 50 animals?
CREATE TABLE agricultural_farms (id INT,name VARCHAR(30),num_employees INT,num_animals INT);
SELECT COUNT(*) FROM agricultural_farms WHERE num_animals > 50;
What's the total number of workers by gender for a specific mining operation?
CREATE TABLE MiningOperations (OperationID INT,MineName VARCHAR(100),OperationType VARCHAR(50),StartDate DATE,EndDate DATE); INSERT INTO MiningOperations (OperationID,MineName,OperationType,StartDate,EndDate) VALUES (1,'Golden Mine','Exploration','2015-01-01','2015-12-31'),(2,'Silver Ridge','Extraction','2016-01-01','2016-12-31'); CREATE TABLE WorkforceDiversity (EmployeeID INT,OperationID INT,Gender VARCHAR(10),Age INT,Position VARCHAR(50)); INSERT INTO WorkforceDiversity (EmployeeID,OperationID,Gender,Age,Position) VALUES (1,1,'Male',35,'Engineer'),(2,1,'Female',40,'Manager'),(3,2,'Male',45,'Engineer'),(4,2,'Female',30,'Manager');
SELECT wf.OperationID, wf.Gender, COUNT(wf.EmployeeID) as TotalWorkers FROM WorkforceDiversity wf WHERE wf.OperationID = 1 GROUP BY wf.Gender;
How many pollution control initiatives have been implemented in the Southern Ocean?
CREATE TABLE southern_ocean (id INT,initiative TEXT,region TEXT); INSERT INTO southern_ocean (id,initiative,region) VALUES (1,'Cleanup Project A','Southern Ocean'),(2,'Waste Management B','Southern Ocean');
SELECT COUNT(*) FROM southern_ocean WHERE region = 'Southern Ocean';
List the names and total points of the top 10 NBA players in the 2021-2022 season, based on their performance in the regular season.
CREATE TABLE nba_players (id INT,name VARCHAR(100),team VARCHAR(50),position VARCHAR(50),points INT,assists INT,rebounds INT,games_played INT);
SELECT name, SUM(points) as total_points FROM nba_players WHERE season = 2021 AND category = 'regular' GROUP BY name ORDER BY total_points DESC LIMIT 10;
What is the total CO2 emissions reduction achieved by climate projects in South America?
CREATE TABLE emissions_reduction (id INT,project VARCHAR(50),location VARCHAR(50),reduction_amount FLOAT); INSERT INTO emissions_reduction (id,project,location,reduction_amount) VALUES (1,'Adaptation Project','South America',1000000.0); INSERT INTO emissions_reduction (id,project,location,reduction_amount) VALUES (2,'Mitigation Project','South America',1500000.0); INSERT INTO emissions_reduction (id,project,location,reduction_amount) VALUES (3,'Communication Project','Africa',500000.0);
SELECT SUM(reduction_amount) FROM emissions_reduction WHERE location = 'South America';
Show the peacekeeping operations that were led by the African Union
CREATE TABLE peacekeeping_operations (id INT,operation_name VARCHAR(255),leading_organization VARCHAR(255),year INT);
SELECT operation_name FROM peacekeeping_operations WHERE leading_organization = 'African Union';
What was the citizen feedback score for public transportation in Sydney in Q1 2022?
CREATE TABLE citizen_feedback (quarter INT,city VARCHAR(20),service VARCHAR(20),score INT); INSERT INTO citizen_feedback VALUES (1,'Sydney','Public Transportation',80);
SELECT score FROM citizen_feedback WHERE city = 'Sydney' AND service = 'Public Transportation' AND quarter = 1;
How many social good technology projects were completed in 2020 and 2021, categorized by project status?
CREATE TABLE Social_Good_Tech (year INT,status VARCHAR(20),projects INT); INSERT INTO Social_Good_Tech (year,status,projects) VALUES (2020,'completed',30),(2020,'in_progress',20),(2021,'completed',40),(2021,'in_progress',50);
SELECT Social_Good_Tech.year, Social_Good_Tech.status, SUM(Social_Good_Tech.projects) FROM Social_Good_Tech WHERE Social_Good_Tech.year IN (2020, 2021) GROUP BY Social_Good_Tech.year, Social_Good_Tech.status;
Add a column "last_maintenance" to the "vehicles" table.
ALTER TABLE vehicles ADD COLUMN last_maintenance DATE;
ALTER TABLE vehicles ADD COLUMN last_maintenance DATE;
List all the unique workout names, their respective total calories burned, and average duration for users aged 30 and below.
CREATE TABLE Users (id INT,user_name TEXT,age INT); CREATE TABLE Workouts (id INT,user_id INT,workout_name TEXT,calories INT,duration INT); INSERT INTO Users (id,user_name,age) VALUES (1,'John Doe',32); INSERT INTO Users (id,user_name,age) VALUES (2,'Jane Smith',25); INSERT INTO Users (id,user_name,age) VALUES (3,'Pablo Garcia',45); INSERT INTO Workouts (id,user_id,workout_name,calories,duration) VALUES (1,1,'Running',300,30); INSERT INTO Workouts (id,user_id,workout_name,calories,duration) VALUES (2,1,'Cycling',400,45); INSERT INTO Workouts (id,user_id,workout_name,calories,duration) VALUES (3,2,'Yoga',200,60); INSERT INTO Workouts (id,user_id,workout_name,calories,duration) VALUES (4,2,'Running',200,25);
SELECT DISTINCT workout_name, SUM(calories) as total_calories, AVG(duration) as avg_duration FROM Workouts JOIN Users ON Workouts.user_id = Users.id WHERE Users.age <= 30 GROUP BY workout_name;
Identify the top 2 cities with the highest housing affordability score in the 'affordable_housing' table, partitioned by country.
CREATE TABLE affordable_housing (id INT,city VARCHAR(255),country VARCHAR(255),region VARCHAR(255),score INT); INSERT INTO affordable_housing (id,city,country,region,score) VALUES (1,'Toronto','Canada','North',80),(2,'Mexico City','Mexico','South',70),(3,'Sao Paulo','Brazil','South',60),(4,'Rio de Janeiro','Brazil','South',85),(5,'Chicago','USA','Midwest',75);
SELECT city, country, score, RANK() OVER (PARTITION BY country ORDER BY score DESC) as housing_affordability_rank FROM affordable_housing WHERE housing_affordability_rank <= 2;
Add a new column 'ethnicity' to the existing 'employee_demographics' table
CREATE TABLE employee_demographics (employee_id INTEGER,department VARCHAR(50),gender VARCHAR(10),ethnicity VARCHAR(30));
ALTER TABLE employee_demographics ADD ethnicity VARCHAR(30);
What is the number of donations made by each donor in 2017?
CREATE TABLE Donors (DonorID INT,DonorName TEXT,DonationYear INT); INSERT INTO Donors (DonorID,DonorName,DonationYear) VALUES (1,'Donor A',2017),(2,'Donor B',2017),(3,'Donor C',2017),(1,'Donor A',2017),(2,'Donor B',2017);
SELECT DonorName, COUNT(*) as NumberOfDonations FROM Donors WHERE DonationYear = 2017 GROUP BY DonorName;
What is the total CO2 emissions (in tonnes) from the energy sector in India, grouped by fuel type?
CREATE TABLE co2_emissions (id INT,country TEXT,fuel_type TEXT,co2_emissions_tonnes FLOAT); INSERT INTO co2_emissions (id,country,fuel_type,co2_emissions_tonnes) VALUES (1,'India','Coal',800.0),(2,'India','Gas',200.0),(3,'India','Oil',300.0);
SELECT fuel_type, SUM(co2_emissions_tonnes) FROM co2_emissions WHERE country = 'India' GROUP BY fuel_type;
What is the total number of autonomous bus trips in Tokyo?
CREATE TABLE autonomous_buses (bus_id INT,trip_duration FLOAT,start_speed FLOAT,end_speed FLOAT,start_time TIMESTAMP,end_time TIMESTAMP,city VARCHAR(50)); INSERT INTO autonomous_buses (bus_id,trip_duration,start_speed,end_speed,start_time,end_time,city) VALUES (1,60.0,0.0,10.0,'2021-01-01 00:00:00','2021-01-01 00:60:00','Tokyo'),(2,75.0,0.0,12.0,'2021-01-02 08:00:00','2021-01-02 08:75:00','Tokyo');
SELECT COUNT(*) FROM autonomous_buses WHERE city = 'Tokyo';
How many vulnerabilities were found in each system category this year?
CREATE TABLE vulnerabilities (id INT,category VARCHAR(20),discovered_date DATE); INSERT INTO vulnerabilities (id,category,discovered_date) VALUES (1,'Network','2021-01-01'),(2,'Software','2021-02-01'),(3,'Hardware','2021-03-01');
SELECT category, COUNT(*) as total_vulnerabilities FROM vulnerabilities WHERE discovered_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY category;
What is the number of cases in each stage of the criminal justice process for Indigenous and non-Indigenous populations in Australia?
CREATE TABLE australia_criminal_justice (id INT,population VARCHAR(255),stage VARCHAR(255),cases INT); INSERT INTO australia_criminal_justice (id,population,stage,cases) VALUES (1,'Indigenous','Arrest',300),(2,'Indigenous','Charge',250),(3,'Indigenous','Trial',200),(4,'Indigenous','Sentencing',150),(5,'Non-Indigenous','Arrest',2000),(6,'Non-Indigenous','Charge',1500),(7,'Non-Indigenous','Trial',1000),(8,'Non-Indigenous','Sentencing',500);
SELECT population, stage, SUM(cases) AS total_cases FROM australia_criminal_justice GROUP BY population, stage;
What is the sum of account balances for socially responsible lending accounts in the Midwest region?
CREATE TABLE midwest_region (region VARCHAR(20),account_type VARCHAR(30),account_balance DECIMAL(10,2)); INSERT INTO midwest_region (region,account_type,account_balance) VALUES ('Midwest','Socially Responsible Lending',5000.00),('Midwest','Socially Responsible Lending',6000.00),('Midwest','Traditional Lending',4000.00);
SELECT SUM(account_balance) FROM midwest_region WHERE account_type = 'Socially Responsible Lending';
Find the policy type and number of policies, along with the average claim amount, for policyholders in California.
CREATE TABLE Claim (ClaimId INT,PolicyId INT,ClaimAmount DECIMAL(10,2)); CREATE TABLE Policy (PolicyId INT,PolicyType VARCHAR(50),IssueDate DATE,Region VARCHAR(50),PolicyholderZip INT);
SELECT Policy.PolicyType, COUNT(Policy.PolicyId), AVG(Claim.ClaimAmount) FROM Policy INNER JOIN Claim ON Policy.PolicyId = Claim.PolicyId WHERE Policy.Region = 'California' GROUP BY Policy.PolicyType;
What are the textile sourcing countries with a sustainability rating greater than 75?
CREATE TABLE sourcing (id INT,country VARCHAR(20),sustainability_rating INT); INSERT INTO sourcing (id,country,sustainability_rating) VALUES (1,'China',70); INSERT INTO sourcing (id,country,sustainability_rating) VALUES (2,'Italy',85);
SELECT country FROM sourcing WHERE sustainability_rating > 75;
What is the average mental health score of non-binary students?
CREATE TABLE students (student_id INT,gender VARCHAR(50),school_id INT,mental_health_score INT); INSERT INTO students (student_id,gender,school_id,mental_health_score) VALUES (1,'Female',1001,75),(2,'Female',1001,80),(3,'Non-binary',1002,65);
SELECT AVG(s.mental_health_score) as avg_mental_health_score FROM students s WHERE s.gender = 'Non-binary';
What is the maximum daily water consumption for each water treatment plant?
CREATE TABLE water_treatment_plants (plant_name VARCHAR(50),plant_id INT,plant_location VARCHAR(50)); INSERT INTO water_treatment_plants (plant_name,plant_id,plant_location) VALUES ('Toronto Water Treatment Plant',1,'Toronto,Canada'),('Sydney Water Treatment Plant',2,'Sydney,Australia'),('Moscow Water Treatment Plant',3,'Moscow,Russia'); CREATE TABLE water_consumption (plant_id INT,consumption_gallons INT,consumption_date DATE); INSERT INTO water_consumption (plant_id,consumption_gallons,consumption_date) VALUES (1,9834520,'2022-01-01'),(2,8734520,'2022-01-02'),(3,7634520,'2022-01-03');
SELECT wtp.plant_name, MAX(w.consumption_gallons) as max_daily_water_consumption FROM water_consumption w JOIN water_treatment_plants wtp ON w.plant_id = wtp.plant_id GROUP BY wtp.plant_name;
How many articles were published by each author in each category from the 'news_articles' table?
CREATE TABLE news_articles (article_id INT,author VARCHAR(50),title VARCHAR(100),publication_date DATE,category VARCHAR(20)); INSERT INTO news_articles (article_id,author,title,publication_date,category) VALUES (1,'John Doe','Article 1','2022-01-01','Politics'),(2,'Jane Smith','Article 2','2022-01-02','Sports');
SELECT author, category, COUNT(*) as article_count FROM news_articles GROUP BY author, category;
What is the name of the disability support program in Florida that has the most number of participants?
CREATE TABLE ProgramParticipants (ParticipantID INT,ProgramID INT,ParticipantName VARCHAR(50)); INSERT INTO ProgramParticipants (ParticipantID,ProgramID,ParticipantName) VALUES (1,1,'Participant 1'),(2,1,'Participant 2'),(3,2,'Participant 3'),(4,2,'Participant 4'),(5,3,'Participant 5'),(6,3,'Participant 6'),(7,4,'Participant 7'),(8,4,'Participant 8'),(9,5,'Participant 9'),(10,6,'Participant 10');
SELECT Programs.ProgramName FROM Programs INNER JOIN (SELECT ProgramID, COUNT(*) as NumParticipants FROM ProgramParticipants GROUP BY ProgramID ORDER BY NumParticipants DESC LIMIT 1) Subquery ON Programs.ProgramID = Subquery.ProgramID WHERE Programs.State = 'Florida';
What is the number of students who received accommodations by accommodation type and graduation year?
CREATE TABLE Accommodations (StudentID INT,AccommodationType VARCHAR(50),AccommodationDate DATE); INSERT INTO Accommodations (StudentID,AccommodationType,AccommodationDate) VALUES (1,'Sign Language Interpreter','2021-01-01'); CREATE TABLE Students (StudentID INT,StudentName VARCHAR(50),GraduationYear INT); INSERT INTO Students (StudentID,StudentName,GraduationYear) VALUES (1,'Jacob Taylor',2023);
SELECT AccommodationType, GraduationYear, COUNT(*) as Total FROM Accommodations JOIN Students ON Accommodations.StudentID = Students.StudentID GROUP BY AccommodationType, GraduationYear;
What is the total energy storage capacity for each type of energy storage in the USA?
CREATE TABLE usa_energy_storage (type VARCHAR(20),capacity INT); INSERT INTO usa_energy_storage (type,capacity) VALUES ('Batteries',15000),('Pumped Hydro',25000),('Thermal',10000),('Flywheels',3000),('CAES',5000);
SELECT type, SUM(capacity) FROM usa_energy_storage GROUP BY type;
Delete all employee records who have not completed any diversity and inclusion training and have a hire_date before 2020.
CREATE TABLE employees (id INT,first_name VARCHAR(50),last_name VARCHAR(50),hire_date DATE,country VARCHAR(50)); CREATE TABLE diversity_training (id INT,employee_id INT,training_name VARCHAR(50),completed_date DATE);
DELETE e FROM employees e WHERE NOT EXISTS (SELECT 1 FROM diversity_training dt WHERE dt.employee_id = e.id) AND e.hire_date < '2020-01-01';
Show policy numbers, claim dates, and claim amounts for claims processed in 'March' of any year
CREATE TABLE claims (claim_id INT,policy_number INT,claim_amount DECIMAL(10,2),claim_date DATE);
SELECT policy_number, claim_amount, claim_date FROM claims WHERE MONTH(claim_date) = 3;
How many times has each artwork been viewed by female visitors over 50?
CREATE TABLE artworks (id INT,name TEXT); INSERT INTO artworks (id,name) VALUES (1,'Mona Lisa'),(2,'Starry Night'); CREATE TABLE views (id INT,visitor_id INT,artwork_id INT,age INT,gender TEXT); INSERT INTO views (id,visitor_id,artwork_id,age,gender) VALUES (1,1,1,55,'Female'),(2,2,1,35,'Male');
SELECT artwork_id, COUNT(*) FROM views WHERE gender = 'Female' AND age > 50 GROUP BY artwork_id;
What's the average salary of employees in the 'mining_ops' table?
CREATE TABLE mining_ops (id INT,name VARCHAR(50),position VARCHAR(50),salary DECIMAL(10,2));
SELECT AVG(salary) FROM mining_ops;
How many employees in the IT department are fluent in more than one programming language?
CREATE TABLE Employees (EmployeeID INT,Department VARCHAR(20),NumberOfProgrammingLanguages INT); INSERT INTO Employees (EmployeeID,Department,NumberOfProgrammingLanguages) VALUES (1,'IT',2),(2,'IT',1),(3,'HR',0);
SELECT COUNT(*) FROM Employees WHERE Department = 'IT' HAVING NumberOfProgrammingLanguages > 1;
What is the total number of impact investments in the 'renewable energy' sector?
CREATE TABLE company_impact_investments (company_id INT,sector VARCHAR(20),investment_amount FLOAT); INSERT INTO company_impact_investments (company_id,sector,investment_amount) VALUES (1,'renewable energy',250000),(2,'finance',120000),(3,'renewable energy',170000); CREATE TABLE companies (id INT,sector VARCHAR(20)); INSERT INTO companies (id,sector) VALUES (1,'renewable energy'),(2,'finance'),(3,'renewable energy');
SELECT COUNT(*) FROM company_impact_investments INNER JOIN companies ON company_impact_investments.company_id = companies.id WHERE companies.sector = 'renewable energy';
What is the maximum number of peacekeeping personnel in a single operation?
CREATE TABLE peacekeeping_ops (operation_id INT,num_personnel INT);
SELECT MAX(num_personnel) FROM peacekeeping_ops;
What is the minimum age of readers who prefer opinion pieces in the 'Latin America' region?
CREATE TABLE readers (id INT,name TEXT,age INT,region TEXT,interest TEXT); INSERT INTO readers (id,name,age,region,interest) VALUES (1,'Juan Garcia',28,'Latin America','opinion');
SELECT MIN(age) FROM readers WHERE interest = 'opinion' AND region = 'Latin America';
List all vulnerabilities with a severity rating of 'High' or 'Critical' for systems in the Asia-Pacific region, excluding Japan and Korea.
CREATE TABLE vulnerabilities (system_name VARCHAR(255),severity VARCHAR(255),region VARCHAR(255));
SELECT system_name, severity FROM vulnerabilities WHERE region IN ('Asia-Pacific', 'APAC') AND severity IN ('High', 'Critical') EXCEPT (SELECT system_name FROM vulnerabilities WHERE region IN ('Japan', 'Korea'));
Number of attendees at events in "events" table, grouped by event type, for events that took place in New York or Los Angeles between 2018 and 2020.
CREATE TABLE events (event_id INT,event_type VARCHAR(50),event_location VARCHAR(50),event_date DATE);
SELECT event_type, COUNT(event_id) as total_attendees FROM events WHERE event_location IN ('New York', 'Los Angeles') AND event_date BETWEEN '2018-01-01' AND '2020-12-31' GROUP BY event_type;
Which athletes have participated in more than 50 events?
CREATE TABLE Participants (id INT PRIMARY KEY,athlete_id INT,event_id INT); CREATE TABLE Events (id INT PRIMARY KEY); INSERT INTO Participants (id,athlete_id,event_id) VALUES (1,1,1),(2,1,2),(3,2,1),(4,3,1),(5,3,2); INSERT INTO Events (id) VALUES (1),(2),(3),(4),(5);
SELECT Athlete_id, COUNT(*) as Event_Count FROM Participants GROUP BY Athlete_id HAVING Event_Count > 50;
What is the average funding amount for startups founded by LGBTQ+ individuals in the tech industry?
CREATE TABLE startups(id INT,name TEXT,industry TEXT,founding_year INT); CREATE TABLE funding_rounds(id INT,startup_id INT,amount INT); CREATE TABLE founders(id INT,startup_id INT,founder_identity TEXT); INSERT INTO startups (id,name,industry,founding_year) VALUES (1,'TechCo','Tech',2010); INSERT INTO funding_rounds (id,startup_id,amount) VALUES (1,1,5000000); INSERT INTO founders (id,startup_id,founder_identity) VALUES (1,1,'LGBTQ+');
SELECT AVG(amount) FROM startups JOIN funding_rounds ON startups.id = funding_rounds.startup_id JOIN founders ON startups.id = founders.startup_id WHERE industry = 'Tech' AND founder_identity = 'LGBTQ+';
How many permits were issued per month in 2020?
CREATE TABLE Month (id INT,name VARCHAR(10)); CREATE TABLE Permit (id INT,issue_date DATE);
SELECT Month.name, COUNT(Permit.id) AS permits_issued FROM Month INNER JOIN Permit ON Month.id = MONTH(Permit.issue_date) WHERE YEAR(Permit.issue_date) = 2020 GROUP BY Month.name;
Find the average mass of spacecraft manufactured by Galactic
CREATE TABLE Spacecraft (id INT,manufacturer VARCHAR(20),mass FLOAT); INSERT INTO Spacecraft (id,manufacturer,mass) VALUES (1,'SpaceCorp',15000.0); INSERT INTO Spacecraft (id,manufacturer,mass) VALUES (2,'Galactic',12000.0); INSERT INTO Spacecraft (id,manufacturer,mass) VALUES (3,'Galactic',13000.0);
SELECT AVG(mass) FROM Spacecraft WHERE manufacturer = 'Galactic';
What is the maximum duration (in days) of any space mission led by a female astronaut?
CREATE TABLE space_missions (id INT,mission_name VARCHAR(50),launch_date DATE,duration INT,commander_gender VARCHAR(50)); INSERT INTO space_missions (id,mission_name,launch_date,duration,commander_gender) VALUES (1,'Artemis I','2022-08-29',26,'Female'); INSERT INTO space_missions (id,mission_name,launch_date,duration,commander_gender) VALUES (2,'Apollo 11','1969-07-16',8,'Male');
SELECT MAX(duration) FROM space_missions WHERE commander_gender = 'Female';