instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Identify the cultural festivals with attendance greater than 7500 and their virtual experience platforms.
CREATE TABLE CulturalFestivals (festival_id INT,location TEXT,attendance INT); INSERT INTO CulturalFestivals (festival_id,location,attendance) VALUES (1101,'Food Festival',7000),(1102,'Dance Festival',6000); CREATE TABLE VirtualExperiences (experience_id INT,festival_id INT,platform TEXT); INSERT INTO VirtualExperiences (experience_id,festival_id,platform) VALUES (1201,1101,'Website'),(1202,1102,'Mobile app');
SELECT f.festival_id, f.location, f.attendance, v.platform FROM CulturalFestivals f JOIN VirtualExperiences v ON f.festival_id = v.festival_id WHERE f.attendance > 7500;
List defense contract negotiations with their start and end dates, ordered by negotiation_id.
CREATE SCHEMA IF NOT EXISTS contract_negotiations;CREATE TABLE IF NOT EXISTS contract_negotiations (negotiation_id INT,negotiation_start_date DATE,negotiation_end_date DATE);INSERT INTO contract_negotiations (negotiation_id,negotiation_start_date,negotiation_end_date) VALUES (1,'2021-01-01','2021-02-01'),(2,'2021-02-01','2021-03-15'),(3,'2021-03-15','2021-04-30');
SELECT negotiation_id, negotiation_start_date, negotiation_end_date FROM contract_negotiations ORDER BY negotiation_id;
Summarize the total funding by industry and round
CREATE TABLE funding (id INT,industry VARCHAR(255),round VARCHAR(255),funding_amount DECIMAL(10,2)); INSERT INTO funding (id,industry,round,funding_amount) VALUES (1,'Tech','Seed',50000.00),(2,'Biotech','Series A',200000.00),(3,'Tech','Series B',750000.00),(4,'Biotech','Seed',150000.00);
SELECT industry, round, SUM(funding_amount) as total_funding FROM funding GROUP BY industry, round;
What is the total cost of sustainable building projects in WA?
CREATE TABLE SustainableCosts (ProjectID int,State varchar(25),Sustainable bit,Cost decimal(10,2)); INSERT INTO SustainableCosts (ProjectID,State,Sustainable,Cost) VALUES (1,'WA',1,100000.00),(2,'WA',0,200000.00),(3,'WA',1,150000.00);
SELECT State, SUM(Cost) AS TotalCost FROM SustainableCosts WHERE State = 'WA' AND Sustainable = 1 GROUP BY State;
What is the maximum price of a co-owned property in Manhattan with a SustainabilityRating of at least 3?
CREATE TABLE CoOwnedProperties (PropertyID int,Price int,Borough varchar(255),SustainabilityRating int); INSERT INTO CoOwnedProperties (PropertyID,Price,Borough,SustainabilityRating) VALUES (1,600000,'Manhattan',3);
SELECT MAX(Price) as MaxPrice FROM CoOwnedProperties WHERE Borough = 'Manhattan' AND SustainabilityRating >= 3;
Update the "temperature" in the "sensor_data" table where the "sensor_id" is 2 to 25
CREATE TABLE sensor_data (sensor_id INT,temperature FLOAT,humidity FLOAT,light_level INT,timestamp TIMESTAMP);
UPDATE sensor_data SET temperature = 25 WHERE sensor_id = 2;
How many defense projects in the Project_Timelines table have a duration greater than or equal to 365 days?
CREATE TABLE Project_Timelines (project VARCHAR(50),start_date DATE,end_date DATE);
SELECT COUNT(*) FROM Project_Timelines WHERE DATEDIFF(day, start_date, end_date) >= 365;
What is the total number of building permits issued, in each month, for sustainable building projects, for the past year, ordered by year and month?
CREATE TABLE BuildingPermits (PermitIssueDate DATE,SustainableBuilding INT);
SELECT DATEPART(YEAR, PermitIssueDate) as Year, DATEPART(MONTH, PermitIssueDate) as Month, COUNT(*) as PermitCount FROM BuildingPermits WHERE PermitIssueDate >= DATEADD(YEAR, -1, GETDATE()) AND SustainableBuilding = 1 GROUP BY DATEPART(YEAR, PermitIssueDate), DATEPART(MONTH, PermitIssueDate) ORDER BY Year, Month;
How many agricultural innovation projects have been implemented in the 'innovation_data' table for each type?
CREATE TABLE innovation_data (project_id INT,project_type VARCHAR(20)); INSERT INTO innovation_data (project_id,project_type) VALUES (1,'Precision Agriculture'),(2,'Biotechnology'),(3,'Precision Agriculture');
SELECT project_type, COUNT(project_id) FROM innovation_data GROUP BY project_type;
What is the percentage of total agricultural land in North America that has adopted sustainable farming practices since 2015?
CREATE TABLE AgriculturalLand (region TEXT,year INTEGER,practices TEXT,acres INTEGER); INSERT INTO AgriculturalLand (region,year,practices,acres) VALUES ('North America',2015,'conventional',5000000),('North America',2016,'sustainable',1500000),('North America',2017,'sustainable',3000000),('North America',2018,'sustainable',4500000),('North America',2019,'sustainable',5000000);
SELECT (SUM(CASE WHEN practices = 'sustainable' THEN acres ELSE 0 END) * 100.0 / SUM(acres)) AS percentage FROM AgriculturalLand WHERE region = 'North America' AND year >= 2015;
What is the number of legal technology patents filed in the last 5 years by companies in Washington D.C.?
CREATE TABLE legal_tech_patents (patent_id INT,company_id INT,file_date DATE,state VARCHAR(2)); INSERT INTO legal_tech_patents (patent_id,company_id,file_date,state) VALUES (1,1001,'2018-01-01','DC'),(2,1002,'2019-03-15','DC');
SELECT COUNT(*) FROM legal_tech_patents WHERE state = 'DC' AND file_date >= DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR);
What are the names and excavation dates of sites with at least one wooden artifact?
CREATE TABLE excavation_sites (site_id INT,site_name TEXT,excavation_date DATE); CREATE TABLE artifacts (artifact_id INT,site_id INT,artifact_type TEXT); INSERT INTO excavation_sites (site_id,site_name,excavation_date) VALUES (1,'Site A','2010-01-01'),(2,'Site B','2012-05-05'),(3,'Site C','2015-10-10'); INSERT INTO artifacts (artifact_id,site_id,artifact_type) VALUES (1,1,'wooden'),(2,1,'stone'),(3,2,'metal'),(4,3,'wooden');
SELECT site_name, excavation_date FROM excavation_sites e JOIN artifacts a ON e.site_id = a.site_id WHERE a.artifact_type = 'wooden';
What is the maximum number of players and the corresponding game for each platform in the VR category?
CREATE TABLE VRPlatforms (GameID int,Platform varchar(20),MaxPlayers int); INSERT INTO VRPlatforms (GameID,Platform,MaxPlayers) VALUES (11,'Oculus',300); INSERT INTO VRPlatforms (GameID,Platform,MaxPlayers) VALUES (12,'Vive',250);
SELECT Platform, MAX(MaxPlayers) as MaxPlayers, GameName FROM VRPlatforms vp JOIN VRGames vg ON vp.GameID = vg.GameID WHERE vg.Category = 'VR' GROUP BY Platform;
What is the average budget allocation for policies in CityC?
CREATE TABLE Policy (id INT,city_id INT,title VARCHAR(100),start_date DATE,end_date DATE); INSERT INTO Policy (id,city_id,title,start_date,end_date) VALUES (3,3,'Policy3','2022-01-01','2023-12-31'); INSERT INTO Policy (id,city_id,title,start_date,end_date) VALUES (4,3,'Policy4','2021-01-01','2022-12-31'); CREATE TABLE BudgetAllocation (id INT,policy_id INT,service_id INT,allocation FLOAT); INSERT INTO BudgetAllocation (id,policy_id,service_id,allocation) VALUES (4,3,1,0.3); INSERT INTO BudgetAllocation (id,policy_id,service_id,allocation) VALUES (5,3,2,0.7);
SELECT AVG(ba.allocation) FROM BudgetAllocation ba JOIN Policy p ON ba.policy_id = p.id WHERE p.city_id = 3;
Find the number of fans who have attended both hockey and baseball games in the last year.
CREATE TABLE FanEvents (FanID INT,EventType VARCHAR(10),EventDate DATE); CREATE TABLE Fans (FanID INT,FanName VARCHAR(50));
SELECT COUNT(DISTINCT FanID) FROM FanEvents WHERE EventType IN ('Hockey', 'Baseball') GROUP BY FanID HAVING COUNT(DISTINCT EventType) = 2;
What is the average water temperature in the Pacific Northwest salmon farms in July?
CREATE TABLE salmon_farms (id INT,name TEXT,region TEXT,water_temp FLOAT); INSERT INTO salmon_farms (id,name,region,water_temp) VALUES (1,'Farm A','Pacific Northwest',12.5),(2,'Farm B','Pacific Northwest',13.2),(3,'Farm C','Pacific Northwest',11.8);
SELECT AVG(water_temp) FROM salmon_farms WHERE region = 'Pacific Northwest' AND EXTRACT(MONTH FROM datetime) = 7;
List the total number of military aircraft maintenance requests in the Pacific region in Q3 2022
CREATE TABLE maintenance_requests (region TEXT,quarter NUMERIC,aircraft_type TEXT,num_requests NUMERIC); INSERT INTO maintenance_requests (region,quarter,aircraft_type,num_requests) VALUES ('Pacific',3,'F-16',20),('Atlantic',2,'F-15',15),('Pacific',3,'F-35',30),('Atlantic',1,'A-10',10),('Pacific',2,'F-16',25);
SELECT SUM(num_requests) as total_requests FROM maintenance_requests WHERE region = 'Pacific' AND quarter = 3;
How many virtual tours are available in Spain and Italy?
CREATE TABLE virtual_tourism (venue_id INT,name TEXT,country TEXT,available_tours INT); INSERT INTO virtual_tourism (venue_id,name,country,available_tours) VALUES (1,'Virtually Madrid','Spain',12),(2,'Vatican City 360','Italy',8),(3,'Barcelona Online','Spain',15);
SELECT SUM(available_tours) FROM virtual_tourism WHERE country IN ('Spain', 'Italy');
How many patients received treatment at a specific location?
CREATE TABLE patients (id INT,name VARCHAR(50),location VARCHAR(50),treatment VARCHAR(50)); CREATE TABLE treatments (treatment VARCHAR(50),cost INT);
SELECT COUNT(DISTINCT p.name) FROM patients p WHERE p.location = 'specific_location';
What is the number of animals of each type in each country, ordered by the number of animals in descending order?
CREATE TABLE CountryAnimals (Country VARCHAR(255),Type VARCHAR(255),Animals INT); INSERT INTO CountryAnimals (Country,Type,Animals) VALUES ('India','Tiger',20),('India','Elephant',30),('China','Tiger',15),('China','Panda',20),('Brazil','Elephant',10),('Brazil','Rhino',15);
SELECT Country, Type, SUM(Animals) as TotalAnimals FROM CountryAnimals GROUP BY Country, Type ORDER BY TotalAnimals DESC;
How many passengers traveled on each route on a specific date?
CREATE TABLE trips (route_id INT,trip_date DATE); INSERT INTO trips (route_id,trip_date) VALUES (1,'2022-05-01'),(1,'2022-05-01'),(2,'2022-05-01'),(3,'2022-05-01'),(3,'2022-05-01');
SELECT r.route_name, t.trip_date, COUNT(t.route_id) AS passengers FROM trips t JOIN routes r ON t.route_id = r.route_id GROUP BY r.route_name, t.trip_date;
Which cruelty-free certified products were sold in Canada in Q1 2022?
CREATE TABLE products (product_id INT,product_name VARCHAR(50),is_cruelty_free BOOLEAN); INSERT INTO products VALUES (1,'Lipstick 101',true),(2,'Eye Shadow 202',false); CREATE TABLE sales (sale_id INT,product_id INT,sale_date DATE); INSERT INTO sales VALUES (1,1,'2022-01-05'),(2,2,'2022-02-10'),(3,1,'2022-03-20');
SELECT products.product_name FROM products INNER JOIN sales ON products.product_id = sales.product_id WHERE products.is_cruelty_free = true AND sale_date BETWEEN '2022-01-01' AND '2022-03-31';
How many disaster response volunteers are there in 'regions' table and what are their names?
CREATE TABLE regions (region_id INT,volunteer_name VARCHAR(50),is_disaster_response BOOLEAN); INSERT INTO regions (region_id,volunteer_name,is_disaster_response) VALUES (1,'John Doe',true),(2,'Jane Smith',false),(3,'Alice Johnson',true),(4,'Bob Brown',true),(5,'Charlie Davis',false);
SELECT COUNT(*), volunteer_name FROM regions WHERE is_disaster_response = true;
What is the average daily water consumption per household in New York City?
CREATE TABLE Households (id INT,city VARCHAR(20),daily_consumption FLOAT); INSERT INTO Households (id,city,daily_consumption) VALUES (1,'New York City',300.5),(2,'New York City',327.8),(3,'Los Angeles',425.6);
SELECT AVG(daily_consumption) FROM Households WHERE city = 'New York City';
Calculate the total quantity of 'recycled paper' products in the inventory.
CREATE TABLE product (product_id INT,name VARCHAR(255),quantity INT,material VARCHAR(255)); INSERT INTO product (product_id,name,quantity,material) VALUES (1,'Recycled Paper Notebook',75,'recycled paper');
SELECT SUM(quantity) FROM product WHERE material = 'recycled paper';
What is the distribution of content items across different media representation topics?
CREATE TABLE content (id INT,topic VARCHAR(50)); INSERT INTO content (id,topic) VALUES (1,'Racial Diversity'),(2,'Gender Equality'),(3,'LGBTQ+ Representation'),(4,'Disability Representation'),(5,'Religious Diversity'),(6,'Cultural Diversity');
SELECT topic, COUNT(*) AS num_content, ROUND(COUNT(*) * 100.0 / (SELECT COUNT(*) FROM content), 1) AS percentage FROM content GROUP BY topic;
Find healthcare providers with low cultural competency scores serving Latinx in FL.
CREATE TABLE healthcare_providers (provider_id INT,name TEXT,state TEXT); INSERT INTO healthcare_providers (provider_id,name,state) VALUES (1,'Dr. Ana Perez','FL'); CREATE TABLE cultural_competency (provider_id INT,score INT,community TEXT);
SELECT h.name, c.score FROM healthcare_providers h INNER JOIN cultural_competency c ON h.provider_id = c.provider_id WHERE h.state = 'FL' AND c.community = 'Latinx' AND c.score < 50;
What was the total revenue for 'El Bio Vegan' in 2021?
CREATE TABLE restaurants (name VARCHAR(255),type VARCHAR(255),yearly_revenue INT); INSERT INTO restaurants (name,type,yearly_revenue) VALUES ('El Bio Vegan','Restaurant',300000);
SELECT yearly_revenue FROM restaurants WHERE name = 'El Bio Vegan' AND year = 2021;
How many cybersecurity incidents were reported in the Caribbean region in 2020?
CREATE TABLE cybersecurity_incidents(incident_id INT,region VARCHAR(255),year INT); INSERT INTO cybersecurity_incidents(incident_id,region,year) VALUES (1,'Caribbean',2020),(2,'North America',2019),(3,'Caribbean',2021),(4,'Europe',2020),(5,'Caribbean',2020),(6,'Asia',2020);
SELECT COUNT(*) FROM cybersecurity_incidents WHERE region = 'Caribbean' AND year = 2020;
How many products have been restocked in the past month for each brand?
CREATE TABLE brands (id INT,name TEXT); CREATE TABLE products (id INT,name TEXT,brand_id INT,restock_date DATE); INSERT INTO brands (id,name) VALUES (1,'Brand A'),(2,'Brand B'),(3,'Brand C'); INSERT INTO products (id,name,brand_id,restock_date) VALUES (1,'Product 1',1,'2022-01-05'),(2,'Product 2',2,'2022-02-10'),(3,'Product 3',3,'2022-03-01'),(4,'Product 4',1,'2022-01-15'),(5,'Product 5',2,'2022-02-25');
SELECT brands.name, COUNT(products.id) FROM brands INNER JOIN products ON brands.id = products.brand_id WHERE products.restock_date >= DATEADD(month, -1, GETDATE()) GROUP BY brands.name;
Find the number of distinct tree species in mangrove forests
CREATE TABLE forests_species (id INT,type VARCHAR(20),species INT); INSERT INTO forests_species (id,type,species) VALUES (1,'Mangrove',20),(2,'Mangrove',25);
SELECT COUNT(DISTINCT species) FROM forests_species WHERE type = 'Mangrove';
What is the average number of hours of professional development per teacher per district?
CREATE TABLE development_hours (teacher_id INT,district_id INT,hours_developed INT);
SELECT district_id, AVG(hours_developed) as avg_hours FROM development_hours GROUP BY district_id;
List the names and completion status of rural infrastructure projects in the 'infrastructure_data' table for the 'Prairies' region.
CREATE TABLE infrastructure_data (project_id INT,region VARCHAR(20),project_status VARCHAR(20)); INSERT INTO infrastructure_data (project_id,region,project_status) VALUES (1,'Prairies','completed'),(2,'Northern','in_progress'),(3,'Pacific','completed');
SELECT project_name, project_status FROM infrastructure_data WHERE region = 'Prairies';
List all intelligence operations that were initiated in 2015 and are still ongoing?
CREATE TABLE if not exists intelligence_operations (operation_name VARCHAR(50),start_year INT,end_year INT);
SELECT operation_name FROM intelligence_operations WHERE start_year <= 2015 AND (end_year IS NULL OR end_year > 2015);
Insert a new wind energy production record for Texas in the year 2025
CREATE TABLE wind_energy (id INT,region VARCHAR(50),year INT,production FLOAT);
INSERT INTO wind_energy (id, region, year, production) VALUES (1, 'Texas', 2025, 5000);
What is the average number of visits per community event in Sydney?
CREATE TABLE CommunityEventDetailsSydney (event_id INT,city VARCHAR(50),num_visits INT,num_events INT); INSERT INTO CommunityEventDetailsSydney (event_id,city,num_visits,num_events) VALUES (100,'Sydney',50,2),(200,'Sydney',75,3),(300,'Sydney',100,4);
SELECT AVG(num_visits/num_events) FROM CommunityEventDetailsSydney;
What is the average attendance for games played at stadium 'Stadium X'?
CREATE TABLE games (stadium TEXT,attendance INT); INSERT INTO games (stadium,attendance) VALUES ('Stadium X',12000),('Stadium X',15000),('Stadium Y',18000);
SELECT AVG(attendance) FROM games WHERE stadium = 'Stadium X';
What is the total number of vessels involved in maritime safety incidents?
CREATE TABLE maritime_safety_incidents (region text,vessel_id integer); INSERT INTO maritime_safety_incidents (region,vessel_id) VALUES ('North Atlantic',123),('North Pacific',456),('Mediterranean',789);
SELECT COUNT(DISTINCT vessel_id) FROM maritime_safety_incidents;
Calculate the total waste produced by each menu category in the past year.
CREATE TABLE waste (waste_id INT,menu_item_id INT,waste_amount INT,waste_date DATE); INSERT INTO waste VALUES (1,1,50,'2022-01-01'),(2,2,75,'2022-02-01'),(3,3,60,'2022-03-01'),(4,1,100,'2022-04-01'); CREATE TABLE menu_items (menu_item_id INT,category VARCHAR(255)); INSERT INTO menu_items VALUES (1,'Entrees'),(2,'Soups'),(3,'Salads');
SELECT c1.category, SUM(w1.waste_amount) AS total_waste FROM waste w1 INNER JOIN menu_items m1 ON w1.menu_item_id = m1.menu_item_id INNER JOIN (SELECT menu_item_id, category FROM menu_items EXCEPT SELECT menu_item_id, category FROM menu_items WHERE menu_item_id NOT IN (SELECT menu_item_id FROM waste)) c1 ON m1.menu_item_id = c1.menu_item_id WHERE w1.waste_date > DATEADD(year, -1, GETDATE()) GROUP BY c1.category;
What is the total number of public libraries in the state of California and their respective budgets?
CREATE TABLE PublicLibraries (LibraryID INT,LibraryName VARCHAR(100),State VARCHAR(100),Budget DECIMAL(10,2)); INSERT INTO PublicLibraries (LibraryID,LibraryName,State,Budget) VALUES (1,'Los Angeles Public Library','California',120000.00),(2,'San Francisco Public Library','California',85000.00);
SELECT SUM(Budget) as TotalBudget, LibraryName FROM PublicLibraries WHERE State = 'California' GROUP BY LibraryName;
Find suppliers providing more than 1000 units of any organic ingredient
CREATE TABLE ingredients (id INT,name VARCHAR(50),is_organic BOOLEAN,supplier_id INT,quantity INT); INSERT INTO ingredients (id,name,is_organic,supplier_id,quantity) VALUES (1,'Tomatoes',TRUE,101,1200),(2,'Cheese',FALSE,102,800),(3,'Quinoa',TRUE,103,500); CREATE TABLE suppliers (id INT,name VARCHAR(50)); INSERT INTO suppliers (id,name) VALUES (101,'Green Garden'),(102,'Cheese Company'),(103,'Healthy Harvest');
SELECT s.name, i.name, i.quantity FROM ingredients i INNER JOIN suppliers s ON i.supplier_id = s.id WHERE i.is_organic = TRUE GROUP BY s.name, i.name HAVING COUNT(*) > 1000;
What is the name of the countries and the average hectares of forests?
CREATE TABLE Forests (id INT PRIMARY KEY,name VARCHAR(255),hectares DECIMAL(5,2),country VARCHAR(255)); INSERT INTO Forests (id,name,hectares,country) VALUES (1,'Greenwood',520.00,'Canada'); CREATE TABLE Countries (code CHAR(2),name VARCHAR(255),population INT); INSERT INTO Countries (code,name,population) VALUES ('CA','Canada',37410003);
SELECT Countries.name as country_name, AVG(Forests.hectares) as avg_hectares FROM Forests INNER JOIN Countries ON Forests.country = Countries.code GROUP BY Countries.name;
What is the number of network failures for each tower, grouped by month, and joined with the network investments table to show the total investment for each tower?
CREATE TABLE network_failures (id INT PRIMARY KEY,tower_id INT,failure_type VARCHAR(255),failure_date DATE); CREATE TABLE network_investments (id INT PRIMARY KEY,tower_id INT,investment_amount FLOAT,investment_date DATE);
SELECT MONTH(f.failure_date) as month, i.tower_id, COUNT(f.id) as num_failures, SUM(i.investment_amount) as total_investment FROM network_failures f INNER JOIN network_investments i ON f.tower_id = i.tower_id GROUP BY month, i.tower_id;
How many coal mines are there in the Appalachian region?
CREATE TABLE mines (id INT,name TEXT,location TEXT,product TEXT); INSERT INTO mines (id,name,location,product) VALUES (1,'Mammoth','Appalachia','Coal');
SELECT COUNT(*) FROM mines WHERE location = 'Appalachia' AND product = 'Coal';
What was the change in production of 'Potatoes' between 2015 and 2020 in 'AnnualCropProduction' table?
CREATE TABLE AnnualCropProduction (year INT,crop VARCHAR(20),quantity INT,price FLOAT);
SELECT (SUM(CASE WHEN year = 2020 THEN quantity ELSE 0 END) - SUM(CASE WHEN year = 2015 THEN quantity ELSE 0 END)) as potato_production_change FROM AnnualCropProduction WHERE crop = 'Potatoes';
List the names of the mines that have either gold or silver production data, but not both.
CREATE TABLE gold_mine_production (mine_name VARCHAR(255),quantity INT); CREATE TABLE silver_mine_production (mine_name VARCHAR(255),quantity INT);
SELECT mine_name FROM gold_mine_production GROUP BY mine_name HAVING COUNT(*) = 1 INTERSECT SELECT mine_name FROM silver_mine_production GROUP BY mine_name HAVING COUNT(*) = 0 UNION SELECT mine_name FROM gold_mine_production GROUP BY mine_name HAVING COUNT(*) = 0 INTERSECT SELECT mine_name FROM silver_mine_production GROUP BY mine_name HAVING COUNT(*) = 1;
What is the number of autonomous vehicles in the autonomous_driving_research table?
CREATE TABLE autonomous_driving_research (id INT,make VARCHAR(50),model VARCHAR(50),autonomy_level INT);
SELECT COUNT(*) FROM autonomous_driving_research WHERE autonomy_level > 0;
Find the average size of space debris in each location.
CREATE TABLE space_debris (id INT,name VARCHAR(255),source_type VARCHAR(255),location VARCHAR(255),size FLOAT); INSERT INTO space_debris (id,name,source_type,location,size) VALUES (1,'Defunct Satellite','Spacecraft','LEO',5.0);
SELECT location, AVG(size) as avg_size FROM space_debris GROUP BY location;
What is the total revenue from ticket sales in 'Section A' in the 'ticket_sales' table?
CREATE TABLE ticket_sales (ticket_id INT,section VARCHAR(50),price DECIMAL(5,2),quantity INT); INSERT INTO ticket_sales (ticket_id,section,price,quantity) VALUES (1,'Section A',50.00,25); INSERT INTO ticket_sales (ticket_id,section,price,quantity) VALUES (2,'Section B',40.00,30);
SELECT SUM(price * quantity) FROM ticket_sales WHERE section = 'Section A';
How many events were attended by donors from 'CountryX'?
CREATE TABLE Donors (donor_id INT,name VARCHAR(255),country VARCHAR(255)); CREATE TABLE Donations (donation_id INT,donor_id INT,event_id INT); CREATE TABLE Events (event_id INT,name VARCHAR(255),date DATE);
SELECT COUNT(*) FROM Donors D JOIN Donations DN ON D.donor_id = DN.donor_id JOIN Events E ON DN.event_id = E.event_id WHERE D.country = 'CountryX';
What are the names and roles of reporters who have worked on completed investigative projects?
CREATE TABLE reporters (id INT,name VARCHAR(50),age INT,gender VARCHAR(10),role VARCHAR(20)); INSERT INTO reporters (id,name,age,gender,role) VALUES (1,'Sanaa Ahmed',32,'Female','Investigative Reporter'); INSERT INTO reporters (id,name,age,gender,role) VALUES (2,'Hiroshi Tanaka',45,'Male','Senior Editor'); INSERT INTO reporters (id,name,age,gender,role) VALUES (3,'Claudia Mendoza',30,'Female','Reporter'); INSERT INTO reporters (id,name,age,gender,role) VALUES (4,'Mohammed Al-Saadi',40,'Male','Lead Investigator'); CREATE TABLE investigative_projects (id INT,title VARCHAR(100),lead_investigator_id INT,status VARCHAR(20)); INSERT INTO investigative_projects (id,title,lead_investigator_id,status) VALUES (1,'Corruption in City Hall',4,'Completed'); INSERT INTO investigative_projects (id,title,lead_investigator_id,status) VALUES (2,'Misuse of Funds in Non-Profit Organizations',2,'Completed');
SELECT r.name, r.role FROM reporters r JOIN investigative_projects ip ON r.id = ip.lead_investigator_id WHERE ip.status = 'Completed';
Identify mines with labor productivity below the industry average
CREATE TABLE mine (id INT,name TEXT,location TEXT,labor_productivity INT); INSERT INTO mine (id,name,location,labor_productivity) VALUES (1,'Golden Gorge','CA',120),(2,'Silver Ridge','NV',150),(3,'Bronze Basin','CO',180),(4,'Iron Island','MT',100),(5,'Lead Land','SD',90); CREATE TABLE industry_average (year INT,avg_labor_productivity INT); INSERT INTO industry_average (year,avg_labor_productivity) VALUES (2022,130);
SELECT name, labor_productivity FROM mine WHERE labor_productivity < (SELECT avg_labor_productivity FROM industry_average WHERE year = 2022);
What were the water conservation initiatives with an average savings of over 70 m³ on September 1, 2021?
CREATE TABLE WaterConservation (Id INT,Initiative VARCHAR(50),Savings DECIMAL(5,2),Date DATE); INSERT INTO WaterConservation (Id,Initiative,Savings,Date) VALUES (1,'Rain Barrels',75.2,'2021-09-01'); INSERT INTO WaterConservation (Id,Initiative,Savings,Date) VALUES (2,'Smart Irrigation',78.3,'2021-09-01');
SELECT Initiative, AVG(Savings) FROM WaterConservation WHERE Date = '2021-09-01' GROUP BY Initiative HAVING AVG(Savings) > 70;
What is the total water consumption of factories in each country, categorized by those meeting the living wage standard?
CREATE TABLE Factories (id INT,name TEXT,country TEXT,living_wage_standard BOOLEAN,water_consumption DECIMAL(5,2)); INSERT INTO Factories (id,name,country,living_wage_standard,water_consumption) VALUES (1,'Factory A','USA',true,12000.00),(2,'Factory B','Mexico',false,15000.00),(3,'Factory C','India',true,8000.00),(4,'Factory D','Bangladesh',false,10000.00),(5,'Factory E','China',true,13000.00);
SELECT country, SUM(water_consumption) FROM Factories GROUP BY country, living_wage_standard;
List all community policing initiatives in the 'Bronx' borough.
CREATE TABLE initiatives (id INT,name TEXT,location TEXT); INSERT INTO initiatives (id,name,location) VALUES (1,'Safe Streets','Manhattan'),(2,'Youth and Police Dialogues','Brooklyn'),(3,'Cops and Clergy','Queens'),(4,'Community Patrol','Bronx'),(5,'Disaster Preparedness Workshops','Staten Island');
SELECT name FROM initiatives WHERE location = 'Bronx';
Find the number of fans who have attended both basketball and football games in the last year.
CREATE TABLE FanEvents (FanID INT,EventType VARCHAR(10),EventDate DATE); CREATE TABLE Fans (FanID INT,FanName VARCHAR(50));
SELECT COUNT(DISTINCT FanID) FROM FanEvents WHERE EventType IN ('Basketball', 'Football') GROUP BY FanID HAVING COUNT(DISTINCT EventType) = 2;
Count the number of unsuccessful satellite launches by private companies
CREATE TABLE Launches (LaunchID INT,LaunchDate DATE,SatelliteName VARCHAR(50),Company VARCHAR(50),Success VARCHAR(50)); INSERT INTO Launches (LaunchID,LaunchDate,SatelliteName,Company,Success) VALUES (1,'2022-01-01','SatX','SpaceX','Failure'); INSERT INTO Launches (LaunchID,LaunchDate,SatelliteName,Company,Success) VALUES (2,'2022-02-10','SatY','Blue Origin','Success');
SELECT Company, COUNT(*) FROM Launches WHERE Success = 'Failure' AND Company NOT LIKE '%Government%' GROUP BY Company;
Which marine protected areas in the Southern Ocean have shark populations?
CREATE TABLE marine_protected_areas (id INT,name VARCHAR(255),region VARCHAR(255)); CREATE TABLE shark_populations (id INT,marine_protected_area_id INT,shark_species VARCHAR(255)); INSERT INTO marine_protected_areas (id,name,region) VALUES (1,'Kerguelen Islands Marine Reserve','Southern Ocean'),(2,'Heard Island and McDonald Islands Marine Reserve','Southern Ocean'),(3,'Macquarie Island Marine Park','Southern Ocean'); INSERT INTO shark_populations (id,marine_protected_area_id,shark_species) VALUES (1,1,'Great White Shark'),(2,2,'Southern Ocean Sevengill Shark'),(3,3,'Southern Dogfish Shark');
SELECT marine_protected_areas.name FROM marine_protected_areas JOIN shark_populations ON marine_protected_areas.id = shark_populations.marine_protected_area_id WHERE region = 'Southern Ocean';
List the unique mission names and their launch years for each country.
CREATE TABLE space_missions (id INT,mission_name VARCHAR(255),country VARCHAR(255),launch_year INT,mission_status VARCHAR(255)); INSERT INTO space_missions (id,mission_name,country,launch_year,mission_status) VALUES (1,'Artemis I','United States',2022,'Planned');
SELECT launch_year, country, mission_name FROM space_missions GROUP BY launch_year, country, mission_name;
List the names of companies that have received funding in the last 6 months, ordered by the amount of funding received.
CREATE TABLE companies (id INT,name TEXT,industry TEXT,founding_date DATE,founder_gender TEXT); INSERT INTO companies (id,name,industry,founding_date,founder_gender) VALUES (1,'DataMine','Technology','2018-01-01','Male'); INSERT INTO companies (id,name,industry,founding_date,founder_gender) VALUES (2,'BioHealth','Healthcare','2019-01-01','Female'); CREATE TABLE funding_records (id INT,company_id INT,funding_amount INT,funding_date DATE); INSERT INTO funding_records (id,company_id,funding_amount,funding_date) VALUES (1,1,1000000,'2021-06-01'); INSERT INTO funding_records (id,company_id,funding_amount,funding_date) VALUES (2,2,500000,'2021-03-01');
SELECT companies.name FROM companies JOIN funding_records ON companies.id = funding_records.company_id WHERE funding_records.funding_date >= DATEADD(month, -6, GETDATE()) ORDER BY funding_amount DESC
Find the unique number of countries with travel advisories issued in 2020, 2021 and 2022.
CREATE TABLE TravelAdvisories (id INT,country VARCHAR(50),issue_year INT,PRIMARY KEY(id)); INSERT INTO TravelAdvisories (id,country,issue_year) VALUES (1,'CountryA',2020),(2,'CountryB',2021),(3,'CountryA',2022),(4,'CountryC',2021),(5,'CountryB',2022);
SELECT COUNT(DISTINCT country) FROM TravelAdvisories WHERE issue_year IN (2020, 2021, 2022);
List the names of rural clinics in Africa with their staff count.
CREATE TABLE clinics (id INT,name VARCHAR(50),location VARCHAR(50),staff_count INT);
SELECT name, staff_count FROM clinics WHERE location LIKE '%Africa%' AND location LIKE '%rural%';
Calculate the average salary of workers in the "textiles" department who work in factories located in the US.
CREATE TABLE factories (id INT,name TEXT,location TEXT,department TEXT); INSERT INTO factories (id,name,location,department) VALUES (1,'Factory A','US','textiles'),(2,'Factory B','Canada','electronics'); CREATE TABLE workers (id INT,factory_id INT,salary FLOAT); INSERT INTO workers (id,factory_id,salary) VALUES (1,1,60000),(2,1,65000),(3,2,70000),(4,2,75000),(5,1,55000);
SELECT AVG(salary) FROM workers INNER JOIN factories ON workers.factory_id = factories.id WHERE factories.department = 'textiles' AND factories.location = 'US';
What is the number of healthcare providers in each specialty?
CREATE TABLE providers (id INT,name TEXT,specialty TEXT); INSERT INTO providers (id,name,specialty) VALUES (1,'Dr. Smith','General Practice'),(2,'Dr. Johnson','Mental Health'),(3,'Dr. Thompson','Geriatrics');
SELECT specialty, COUNT(*) FROM providers GROUP BY specialty;
What is the total funding received by arts organizations in the Pacific region?
CREATE TABLE funding (funding_id INT,organization_id INT,source VARCHAR(50),amount INT); CREATE TABLE organizations (organization_id INT,region VARCHAR(50));
SELECT SUM(f.amount) as total_funding FROM funding f JOIN organizations o ON f.organization_id = o.organization_id WHERE o.region = 'Pacific';
What is the earliest launch year for each country with at least one satellite launch, based on the SpaceLaunches table?
CREATE TABLE SpaceLaunches (LaunchID INT,Country VARCHAR(50),SatelliteID INT,LaunchYear INT); INSERT INTO SpaceLaunches (LaunchID,Country,SatelliteID,LaunchYear) VALUES (1,'USA',101,2002),(2,'Russia',201,1995),(3,'China',301,2000),(4,'Germany',401,2005),(5,'Canada',501,2010),(6,'Japan',601,1972),(7,'India',701,1980);
SELECT Country, MIN(LaunchYear) AS EarliestLaunchYear FROM SpaceLaunches GROUP BY Country HAVING COUNT(SatelliteID) > 0;
Calculate the average age of policyholders from each state
CREATE TABLE policyholders (id INT,name TEXT,dob DATE,gender TEXT,state TEXT); INSERT INTO policyholders (id,name,dob,gender,state) VALUES (1,'John Doe','1960-01-01','Male','NY'),(2,'Jane Smith','1970-05-10','Female','CA'),(3,'Mike Johnson','1985-08-15','Male','TX');
SELECT state, AVG(YEAR(CURRENT_DATE) - YEAR(dob)) as avg_age FROM policyholders GROUP BY state;
What is the average oxygen level in the water at the Vietnamese fish farm 'Farm E' in July?
CREATE TABLE fish_farms (id INT,name TEXT,country TEXT,latitude DECIMAL(9,6),longitude DECIMAL(9,6)); INSERT INTO fish_farms (id,name,country,latitude,longitude) VALUES (1,'Farm A','Vietnam',10.34567,106.45678); INSERT INTO fish_farms (id,name,country,latitude,longitude) VALUES (2,'Farm B','Vietnam',12.56789,108.67890); CREATE TABLE water_quality (date DATE,farm_id INT,oxygen_level DECIMAL(5,2)); INSERT INTO water_quality (date,farm_id,oxygen_level) VALUES ('2022-07-01',1,6.8); INSERT INTO water_quality (date,farm_id,oxygen_level) VALUES ('2022-07-01',2,7.1);
SELECT AVG(oxygen_level) FROM water_quality wq JOIN fish_farms ff ON wq.farm_id = ff.id WHERE wq.date = '2022-07-01' AND ff.country = 'Vietnam' AND ff.name LIKE 'Farm E%';
How many passengers with visual impairments boarded a train at each station?
CREATE TABLE passenger (passenger_id INT,name VARCHAR(50),age INT,gender VARCHAR(10),disability VARCHAR(20)); INSERT INTO passenger (passenger_id,name,age,gender,disability) VALUES (1001,'Alex Brown',35,'Male','Visual Impairment');
SELECT passenger_id, name, age, gender, disability, station_id, COUNT(*) OVER (PARTITION BY station_id, disability) AS passengers_by_station_disability FROM passenger;
Find the average temperature and humidity for the crops in field ID 12345.
CREATE TABLE field_sensor_data (field_id INT,date DATE,temperature DECIMAL(5,2),humidity DECIMAL(5,2)); INSERT INTO field_sensor_data (field_id,date,temperature,humidity) VALUES (12345,'2022-01-01',20.5,60.0),(12345,'2022-01-02',21.0,62.0),(12345,'2022-01-03',19.5,58.0);
SELECT AVG(temperature) AS avg_temperature, AVG(humidity) AS avg_humidity FROM field_sensor_data WHERE field_id = 12345;
What is the distribution of mental health scores for students in each state?
CREATE TABLE student_mental_health (student_id INT,state VARCHAR(50),score INT); INSERT INTO student_mental_health (student_id,state,score) VALUES (1,'California',75),(2,'Texas',80),(3,'California',70);
SELECT state, AVG(score) as avg_score, STDDEV(score) as stddev_score FROM student_mental_health GROUP BY state;
total number of space missions by astronauts from the USA
CREATE TABLE Astronauts(astronaut_id INT,name VARCHAR(50),country VARCHAR(50),missions INT);
SELECT COUNT(*) FROM Astronauts WHERE country = 'USA';
What is the average ESG rating for companies in the technology sector with more than 5000 employees?
CREATE TABLE companies (id INT,sector VARCHAR(255),employees INT,esg_rating FLOAT); INSERT INTO companies (id,sector,employees,esg_rating) VALUES (1,'technology',7000,8.2),(2,'technology',5500,7.9),(3,'finance',3000,6.5);
SELECT AVG(esg_rating) FROM companies WHERE sector = 'technology' AND employees > 5000;
What is the total revenue generated from mobile and broadband services in the country of Canada for the year 2021?
CREATE TABLE mobile_revenue (subscriber_id INT,revenue FLOAT,year INT,country VARCHAR(20)); INSERT INTO mobile_revenue (subscriber_id,revenue,year,country) VALUES (1,50,2021,'Canada'),(2,60,2022,'Canada'),(3,45,2021,'Canada'); CREATE TABLE broadband_revenue (subscriber_id INT,revenue FLOAT,year INT,country VARCHAR(20)); INSERT INTO broadband_revenue (subscriber_id,revenue,year,country) VALUES (1,75,2021,'Canada'),(2,80,2022,'Canada'),(3,70,2021,'Canada');
SELECT SUM(mobile_revenue.revenue + broadband_revenue.revenue) FROM mobile_revenue INNER JOIN broadband_revenue ON mobile_revenue.subscriber_id = broadband_revenue.subscriber_id WHERE mobile_revenue.year = 2021 AND broadband_revenue.year = 2021 AND mobile_revenue.country = 'Canada' AND broadband_revenue.country = 'Canada';
What was the country with the lowest waste generation tonnes in the year 2014?
CREATE TABLE waste_generation (id INT PRIMARY KEY,country VARCHAR(50),generation_tonnes INT,year INT); INSERT INTO waste_generation (id,country,generation_tonnes,year) VALUES (1,'Nigeria',100,2014);
SELECT country FROM waste_generation WHERE year = 2014 AND generation_tonnes = (SELECT MIN(generation_tonnes) FROM waste_generation WHERE year = 2014);
Identify the number of ethical AI patents filed by women inventors since 2017.
CREATE TABLE inventors (inventor_id INT,inventor_name VARCHAR(100),gender VARCHAR(10)); INSERT INTO inventors VALUES (1,'Grace Hopper','female'),(2,'Alan Turing','male'); CREATE TABLE patents (patent_id INT,patent_name VARCHAR(100),inventor_id INT,filed_year INT); INSERT INTO patents VALUES (1,'Ethical AI Algorithm',1,2017),(2,'Secure AI System',1,2018),(3,'AI Speed Optimization',2,2019); CREATE TABLE patent_categories (patent_id INT,category VARCHAR(50)); INSERT INTO patent_categories VALUES (1,'ethical AI'),(2,'ethical AI'),(3,'AI performance');
SELECT COUNT(*) FROM patents INNER JOIN inventors ON patents.inventor_id = inventors.inventor_id INNER JOIN patent_categories ON patents.patent_id = patent_categories.patent_id WHERE gender = 'female' AND filed_year >= 2017 AND category = 'ethical AI';
Calculate the average production rate for each field, considering only the active fields
CREATE TABLE fields (field_id INT,field_name VARCHAR(255),production_rate FLOAT,active BOOLEAN); INSERT INTO fields (field_id,field_name,production_rate,active) VALUES (1,'Field A',1000.0,true),(2,'Field B',2000.0,false),(3,'Field C',1500.0,true);
SELECT field_name, AVG(production_rate) as avg_production_rate FROM fields WHERE active = true GROUP BY field_name;
What is the total number of policies and total claim amount for policies with a coverage type of 'Auto' or 'Motorcycle'?
CREATE TABLE Policy (PolicyNumber INT,CoverageType VARCHAR(50)); CREATE TABLE Claim (ClaimNumber INT,PolicyNumber INT,ClaimAmount INT); INSERT INTO Policy (PolicyNumber,CoverageType) VALUES (1,'Home'); INSERT INTO Policy (PolicyNumber,CoverageType) VALUES (2,'Auto'); INSERT INTO Policy (PolicyNumber,CoverageType) VALUES (3,'Motorcycle'); INSERT INTO Claim (ClaimNumber,PolicyNumber,ClaimAmount) VALUES (1,1,5000); INSERT INTO Claim (ClaimNumber,PolicyNumber,ClaimAmount) VALUES (2,2,3000); INSERT INTO Claim (ClaimNumber,PolicyNumber,ClaimAmount) VALUES (3,3,8000);
SELECT COUNT(Policy.PolicyNumber), SUM(Claim.ClaimAmount) FROM Policy JOIN Claim ON Policy.PolicyNumber = Claim.PolicyNumber WHERE Policy.CoverageType IN ('Auto', 'Motorcycle');
What is the average number of volunteer hours spent per volunteer in the Los Angeles region in the year 2022?
CREATE TABLE VolunteerHours (HourID INT,VolunteerName TEXT,Region TEXT,HoursSpent DECIMAL,HourDate DATE); INSERT INTO VolunteerHours (HourID,VolunteerName,Region,HoursSpent,HourDate) VALUES (1,'Sophia Gonzalez','Los Angeles',10.00,'2022-01-01'),(2,'Mia Davis','Los Angeles',15.00,'2022-02-01');
SELECT AVG(HoursSpent) FROM VolunteerHours WHERE Region = 'Los Angeles' AND YEAR(HourDate) = 2022;
Update the 'habitat_preservation' table to set the area_protected of the 'Galapagos Islands' to 97500
CREATE TABLE habitat_preservation (id INT,habitat_name VARCHAR(50),threat_level VARCHAR(10),area_protected INT);
UPDATE habitat_preservation SET area_protected = 97500 WHERE habitat_name = 'Galapagos Islands';
What is the percentage of waste generated that was recycled, for each location and material, for the year 2022?
CREATE TABLE WasteGeneration (Date date,Location text,Material text,Quantity integer);CREATE TABLE RecyclingRates (Date date,Location text,Material text,Quantity real);
SELECT wg.Location, wg.Material, 100.0 * AVG(rr.Quantity / wg.Quantity) as PercentageRecycled FROM WasteGeneration wg JOIN RecyclingRates rr ON wg.Location = rr.Location AND wg.Material = rr.Material WHERE wg.Date >= '2022-01-01' AND wg.Date < '2023-01-01' GROUP BY wg.Location, wg.Material;
How many hotels in Antarctica have a virtual tour?
CREATE TABLE hotels (id INT,name TEXT,country TEXT,virtual_tour BOOLEAN); INSERT INTO hotels (id,name,country,virtual_tour) VALUES (1,'Hotel A','Antarctica',true),(2,'Hotel B','Antarctica',false);
SELECT COUNT(*) FROM hotels WHERE country = 'Antarctica' AND virtual_tour = true;
What is the average length of songs in the pop genre on the music streaming platform?
CREATE TABLE music_platform (id INT,song_title VARCHAR(100),genre VARCHAR(50),length FLOAT);
SELECT AVG(length) as avg_length FROM music_platform WHERE genre = 'pop';
What is the minimum length of bridges made of steel?
CREATE TABLE bridges (id INT PRIMARY KEY,name VARCHAR(255),length FLOAT,material VARCHAR(255),built_year INT); INSERT INTO bridges (id,name,length,material,built_year) VALUES (1,'BridgeX',300.5,'steel',2000),(2,'BridgeY',450.7,'concrete',1965),(3,'BridgeZ',120.3,'steel',1990);
SELECT MIN(length) as min_length FROM bridges WHERE material = 'steel';
Update the conservation status of the 'Bottlenose Dolphin' to 'Vulnerable' in the 'conservation_status' table.
CREATE TABLE conservation_status (id INT,species_name VARCHAR(50),status VARCHAR(20)); INSERT INTO conservation_status (id,species_name,status) VALUES (1,'Green Sea Turtle','Least Concern'),(2,'Clownfish','Least Concern'),(3,'Bottlenose Dolphin','Data Deficient');
UPDATE conservation_status SET status = 'Vulnerable' WHERE species_name = 'Bottlenose Dolphin';
What was the total revenue from users in Nigeria and Indonesia for the 'gaming' product category in Q4 2022?
CREATE TABLE products (product_id INT,product_name VARCHAR(255),category VARCHAR(255)); INSERT INTO products (product_id,product_name,category) VALUES (1,'Game 1','gaming'),(2,'Game 2','gaming'); CREATE TABLE users (user_id INT,user_country VARCHAR(255)); INSERT INTO users (user_id,user_country) VALUES (1,'Nigeria'),(2,'Indonesia'); CREATE TABLE orders (order_id INT,user_id INT,product_id INT,order_date DATE,revenue DECIMAL(10,2)); INSERT INTO orders (order_id,user_id,product_id,order_date,revenue) VALUES (1,1,1,'2022-10-01',25),(2,2,1,'2022-10-05',30);
SELECT SUM(revenue) FROM orders o JOIN products p ON o.product_id = p.product_id JOIN users u ON o.user_id = u.user_id WHERE u.user_country IN ('Nigeria', 'Indonesia') AND p.category = 'gaming' AND o.order_date BETWEEN '2022-10-01' AND '2022-12-31';
What is the total area of all marine reserves in the Arctic region?
CREATE TABLE arctic_reserves (reserve_name VARCHAR(255),reserve_area FLOAT); INSERT INTO arctic_reserves (reserve_name,reserve_area) VALUES ('North Pole',10000.0),('Svalbard',2000.0);
SELECT SUM(reserve_area) FROM arctic_reserves;
What is the average delay for the Red Line subway route?
CREATE TABLE routes (id INT PRIMARY KEY,name TEXT,type TEXT,length REAL); CREATE TABLE delays (route_id INT,delay REAL,timestamp TIMESTAMP);
SELECT AVG(delay) FROM delays WHERE route_id = (SELECT id FROM routes WHERE name = 'Red Line' AND type = 'Subway');
Delete all artists from the 'Modern Art' event.
CREATE TABLE artists (id INT,name VARCHAR(50),event VARCHAR(50),stipend DECIMAL(5,2)); INSERT INTO artists (id,name,event,stipend) VALUES (1,'Pablo Picasso','Art of the Americas',3000),(2,'Frida Kahlo','Art of the Americas',2500),(3,'Yayoi Kusama','Women in Art',4000);
DELETE FROM artists WHERE event = 'Modern Art';
What is the total steps count for users from Brazil in the first week of January 2023?'
CREATE SCHEMA user_activity; CREATE TABLE steps_data (user_id INT,country VARCHAR(50),steps INT,activity_date DATE); INSERT INTO steps_data VALUES (1,'Brazil',8000,'2023-01-01'),(2,'Mexico',7000,'2023-01-02'),(3,'Brazil',9000,'2023-01-03');
SELECT SUM(steps) FROM user_activity.steps_data WHERE country = 'Brazil' AND activity_date >= '2023-01-01' AND activity_date <= '2023-01-07';
List the top 3 diseases with the highest infection rate in New York.
CREATE TABLE Rates (RateID INT,Age INT,Gender VARCHAR(10),City VARCHAR(20),Disease VARCHAR(20),Rate DECIMAL(5,2)); INSERT INTO Rates (RateID,Age,Gender,City,Disease,Rate) VALUES (1,35,'Male','New York','Cholera',0.15);
SELECT Disease, Rate FROM (SELECT Disease, COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Rates WHERE City = 'New York') as Rate FROM Rates WHERE City = 'New York' GROUP BY Disease) as Subquery ORDER BY Rate DESC LIMIT 3;
Calculate the total number of marine protected areas in the Pacific region.
CREATE TABLE marine_protected_areas (id INT,name VARCHAR(50),size FLOAT,region VARCHAR(20)); INSERT INTO marine_protected_areas (id,name,size,region) VALUES (1,'Galapagos Marine Reserve',133000,'Pacific'); INSERT INTO marine_protected_areas (id,name,size,region) VALUES (2,'Great Barrier Reef',344400,'Pacific');
SELECT COUNT(*) FROM marine_protected_areas WHERE region = 'Pacific';
How many public swimming pools are there in each city?
CREATE TABLE SwimmingPools (City TEXT,NumPools INTEGER); INSERT INTO SwimmingPools (City,NumPools) VALUES ('CityA',3),('CityB',5),('CityC',4);
SELECT City, NumPools FROM SwimmingPools;
What are the annual CO2 emissions from shipping activities in the Atlantic Ocean?
CREATE TABLE CO2_Emissions (year INT,emissions_mt INT,region VARCHAR(50),PRIMARY KEY(year)); INSERT INTO CO2_Emissions (year,emissions_mt,region) VALUES (2015,125678,'Atlantic Ocean'),(2016,136789,'Atlantic Ocean');
SELECT CO2_Emissions.emissions_mt FROM CO2_Emissions WHERE CO2_Emissions.region = 'Atlantic Ocean';
List all the bridges and their construction material from the 'bridges' and 'construction_materials' tables.
CREATE TABLE bridges (id INT,name VARCHAR(255),location VARCHAR(255)); CREATE TABLE construction_materials (bridge_id INT,material VARCHAR(255));
SELECT b.name, cm.material FROM bridges b LEFT JOIN construction_materials cm ON b.id = cm.bridge_id;
List the top 2 countries with the lowest average ESG scores in the renewable energy sector.
CREATE TABLE country_data_2 (id INT,country VARCHAR(50),sector VARCHAR(50),ESG_score FLOAT); INSERT INTO country_data_2 (id,country,sector,ESG_score) VALUES (1,'Brazil','Renewable Energy',70.0),(2,'South Africa','Renewable Energy',72.5),(3,'Mexico','Renewable Energy',75.0),(4,'Indonesia','Renewable Energy',77.5);
SELECT country, AVG(ESG_score) as avg_ESG_score FROM country_data_2 WHERE sector = 'Renewable Energy' GROUP BY country ORDER BY avg_ESG_score LIMIT 2;
How many energy storage facilities exist in each state of the 'energy_storage_facilities' table, along with their capacities?
CREATE TABLE energy_storage_facilities (id INT,name VARCHAR(255),state VARCHAR(50),capacity FLOAT); INSERT INTO energy_storage_facilities (id,name,state,capacity) VALUES (1,'Facility A','California',1200.5),(2,'Facility B','Texas',800.3),(3,'Facility C','California',1500.2),(4,'Facility D','New York',900.0);
SELECT e.state, COUNT(*), SUM(e.capacity) as total_capacity FROM energy_storage_facilities e GROUP BY e.state;
How many hospitals are there in New York City that have received a rating of 5 stars?
CREATE TABLE hospitals (hospital_id INT,hospital_name TEXT,city TEXT,state TEXT,star_rating INT); INSERT INTO hospitals (hospital_id,hospital_name,city,state,star_rating) VALUES (1,'New York-Presbyterian','New York City','New York',5); INSERT INTO hospitals (hospital_id,hospital_name,city,state,star_rating) VALUES (2,'Mount Sinai Hospital','New York City','New York',4); INSERT INTO hospitals (hospital_id,hospital_name,city,state,star_rating) VALUES (3,'Rockefeller University Hospital','New York City','New York',5);
SELECT COUNT(*) FROM hospitals WHERE city = 'New York City' AND star_rating = 5;
What is the daily revenue for the 'concierge service' feature?
CREATE TABLE bookings (id INT,feature_id INT,date DATE,price FLOAT); CREATE TABLE features (id INT,name TEXT); INSERT INTO bookings (id,feature_id,date,price) VALUES (1,2,'2022-01-01',20),(2,2,'2022-01-02',20),(3,2,'2022-01-03',20),(4,3,'2022-01-01',30),(5,3,'2022-01-02',30),(6,1,'2022-01-01',10),(7,1,'2022-01-02',10),(8,1,'2022-01-03',10); INSERT INTO features (id,name) VALUES (1,'Virtual tours'),(2,'Concierge service'),(3,'Room service');
SELECT SUM(price) FROM bookings INNER JOIN features ON bookings.feature_id = features.id WHERE features.name = 'Concierge service' GROUP BY date;
What is the minimum rating for each booking with more than one rating?
CREATE TABLE Customer_Survey (id INT,booking_id INT,rating INT,feedback VARCHAR(255)); INSERT INTO Customer_Survey (id,booking_id,rating,feedback) VALUES (1,1,5,'Great experience!'); INSERT INTO Customer_Survey (id,booking_id,rating,feedback) VALUES (2,2,4,'Good,but could be better'); INSERT INTO Customer_Survey (id,booking_id,rating,feedback) VALUES (3,2,3,'Average');
SELECT booking_id, MIN(rating) as 'Minimum Rating' FROM Customer_Survey GROUP BY booking_id HAVING COUNT(*) > 1;