instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the adoption rate of electric vehicles in the United States by city?
CREATE TABLE City_Data (city VARCHAR(50),state VARCHAR(50),population INT,electric_vehicle_adoption_rate FLOAT); INSERT INTO City_Data (city,state,population,electric_vehicle_adoption_rate) VALUES ('Los Angeles','California',4000000,0.12); INSERT INTO City_Data (city,state,population,electric_vehicle_adoption_rate) VALUES ('New York','New York',8500000,0.10);
SELECT city, electric_vehicle_adoption_rate FROM City_Data ORDER BY electric_vehicle_adoption_rate DESC;
What is the average waste generation rate per capita in the EMEA region?
CREATE TABLE WasteGeneration (id INT,country VARCHAR(50),region VARCHAR(50),generation_rate FLOAT); INSERT INTO WasteGeneration (id,country,region,generation_rate) VALUES (1,'Germany','EMEA',5.3),(2,'France','EMEA',4.4),(3,'Spain','EMEA',5.1);
SELECT AVG(generation_rate) FROM WasteGeneration WHERE region = 'EMEA';
What was the landfill capacity in cubic meters for the 'East' region in 2020?
CREATE TABLE landfill_capacity (region VARCHAR(20),year INT,capacity INT); INSERT INTO landfill_capacity (region,year,capacity) VALUES ('East',2019,400000),('East',2020,425000),('East',2021,450000);
SELECT capacity FROM landfill_capacity WHERE region = 'East' AND year = 2020;
What is the percentage change in water consumption in Lima, Peru between 2017 and 2018?
CREATE TABLE WaterConsumptionYearly_Lima (id INT,year INT,consumption FLOAT); INSERT INTO WaterConsumptionYearly_Lima (id,year,consumption) VALUES (1,2017,130.5),(2,2018,134.2),(3,2019,136.1);
SELECT ((consumption_2018 - consumption_2017) / consumption_2017) * 100.0 FROM (SELECT consumption AS consumption_2017 FROM WaterConsumptionYearly_Lima WHERE year = 2017) AS subquery_2017 CROSS JOIN (SELECT consumption AS consumption_2018 FROM WaterConsumptionYearly_Lima WHERE year = 2018) AS subquery_2018;
Delete the wearable device record of user 'Grace Wilson'
CREATE TABLE wearable_device (user_id INT,name VARCHAR(50),device_model VARCHAR(50)); INSERT INTO wearable_device (user_id,name,device_model) VALUES (6,'Grace Wilson','Apple Watch 7');
WITH deleted_device AS (DELETE FROM wearable_device WHERE name = 'Grace Wilson' RETURNING *) SELECT * FROM deleted_device;
How many users joined the gym in Q1 2023?
CREATE TABLE memberships (id INT,user_id INT,join_date DATE); INSERT INTO memberships (id,user_id,join_date) VALUES (1,5,'2023-01-15'),(2,6,'2023-02-03'),(3,7,'2023-03-20'),(4,8,'2022-12-31');
SELECT COUNT(*) FROM memberships WHERE join_date BETWEEN '2023-01-01' AND '2023-03-31';
List all members who joined in the first quarter of 2021
CREATE TABLE members (member_id INT,join_date DATE);
SELECT member_id FROM members WHERE join_date BETWEEN '2021-01-01' AND '2021-03-31';
List all unique member IDs who have a platinum membership and have not attended any class in the entire month of January 2021.
CREATE TABLE Members (MemberID int,MembershipType varchar(10)); INSERT INTO Members (MemberID,MembershipType) VALUES (1,'Platinum'); CREATE TABLE Classes (ClassID int,MemberID int,ClassDate date); INSERT INTO Classes (ClassID,MemberID,ClassDate) VALUES (1,1,'2021-02-01');
SELECT DISTINCT m.MemberID FROM Members m WHERE m.MembershipType = 'Platinum' AND m.MemberID NOT IN (SELECT MemberID FROM Classes WHERE MONTH(ClassDate) = 1 AND YEAR(ClassDate) = 2021);
What is the total distance covered by users who wore shoes of brand 'XYZ'?
CREATE TABLE wearables (id INT,user_id INT,device_brand VARCHAR(10),distance FLOAT); INSERT INTO wearables (id,user_id,device_brand,distance) VALUES (1,5,'XYZ',5.6); INSERT INTO wearables (id,user_id,device_brand,distance) VALUES (2,6,'ABC',3.2);
SELECT SUM(distance) FROM wearables WHERE device_brand = 'XYZ';
List the number of AI safety incidents for each organization, ordered by the number of incidents in descending order.
CREATE TABLE ai_safety (incident_id INT,incident_date DATE,organization_name TEXT,incident_description TEXT); INSERT INTO ai_safety (incident_id,incident_date,organization_name,incident_description) VALUES (1,'2021-01-01','TechCo','AI system caused harm to a user'); INSERT INTO ai_safety (incident_id,incident_date,organization_name,incident_description) VALUES (2,'2021-02-01','AI Lab','AI system made a biased decision');
SELECT organization_name, COUNT(*) as incidents_count FROM ai_safety GROUP BY organization_name ORDER BY incidents_count DESC;
What is the average population of animals in the 'animal_habitat' table?
CREATE TABLE animal_habitat (habitat_id INT,animal_name VARCHAR(50),habitat_size INT); INSERT INTO animal_habitat (habitat_id,animal_name,habitat_size) VALUES (1,'Tiger',500),(2,'Elephant',1000),(3,'Lion',700);
SELECT AVG(habitat_size) FROM animal_habitat;
What is the sum of fish deaths (deaths) for each species in the 'fish_health' table, having a sum greater than the average for all species?
CREATE TABLE fish_health (id INT,species VARCHAR(255),deaths INT); INSERT INTO fish_health (id,species,deaths) VALUES (1,'Salmon',50),(2,'Salmon',75),(3,'Trout',30),(4,'Trout',40),(5,'Cod',60),(6,'Cod',80);
SELECT species, SUM(deaths) FROM fish_health GROUP BY species HAVING SUM(deaths) > (SELECT AVG(deaths) FROM fish_health);
What is the total number of fish for each location, grouped by location, from the 'fish_stock' and 'sustainable_seafood' tables?
CREATE TABLE fish_stock (location VARCHAR(255),num_fish INT); CREATE TABLE sustainable_seafood (location VARCHAR(255),num_fish INT); INSERT INTO fish_stock (location,num_fish) VALUES ('Location A',500),('Location B',600); INSERT INTO sustainable_seafood (location,num_fish) VALUES ('Location A',450),('Location B',650);
SELECT f.location, SUM(f.num_fish + s.num_fish) FROM fish_stock f FULL OUTER JOIN sustainable_seafood s ON f.location = s.location GROUP BY f.location;
List all art exhibitions with their corresponding funding sources and amounts.
CREATE TABLE art_exhibitions (exhibition_id INT,exhibition_name VARCHAR(50)); CREATE TABLE funding_sources (source_id INT,source_name VARCHAR(50)); CREATE TABLE exhibition_funding (exhibition_id INT,source_id INT,amount DECIMAL(5,2)); INSERT INTO art_exhibitions (exhibition_id,exhibition_name) VALUES (1,'Impressionist Art'),(2,'Contemporary Sculpture'); INSERT INTO funding_sources (source_id,source_name) VALUES (1,'National Endowment for the Arts'),(2,'Private Donors'),(3,'Corporate Sponsors'); INSERT INTO exhibition_funding (exhibition_id,source_id,amount) VALUES (1,1,5000),(1,2,10000),(1,3,20000),(2,2,7000),(2,3,15000);
SELECT e.exhibition_name, f.source_name, ef.amount FROM art_exhibitions e INNER JOIN exhibition_funding ef ON e.exhibition_id = ef.exhibition_id INNER JOIN funding_sources f ON ef.source_id = f.source_id;
What's the distribution of Spotify premium users by age group?
CREATE TABLE SPOTIFY_USERS (id INT,age INT,premium BOOLEAN); INSERT INTO SPOTIFY_USERS (id,age,premium) VALUES (1,18,true),(2,23,false),(3,31,true),(4,45,true),(5,50,false);
SELECT FLOOR(age/10)*10 as age_group, COUNT(*) as num_users FROM SPOTIFY_USERS WHERE premium = true GROUP BY age_group;
Which countries have the most number of action and comedy movies?
CREATE TABLE country_movies (id INT,country VARCHAR(50),genre VARCHAR(20),count INT);
SELECT country, genre, SUM(count) FROM country_movies WHERE genre IN ('Action', 'Comedy') GROUP BY country, genre ORDER BY SUM(count) DESC;
How many compliance violations occurred in each quarter of 2021?
CREATE TABLE compliance_violations (id INT,dispensary_id INT,violation_date DATE,description TEXT); INSERT INTO compliance_violations (id,dispensary_id,violation_date,description) VALUES (1,1,'2021-02-15','Inadequate labeling'),(2,2,'2021-03-02','Improper storage'),(3,3,'2021-06-28','Expired products'),(4,4,'2021-07-14','Lack of inventory controls'),(5,1,'2021-08-12','Inadequate labeling'),(6,2,'2021-12-30','Improper storage');
SELECT EXTRACT(QUARTER FROM violation_date) AS quarter, COUNT(*) FROM compliance_violations WHERE violation_date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY quarter;
List the climate mitigation communication campaigns in Asia with a budget greater than $1,000,000.
CREATE TABLE climate_communication_campaigns (campaign_id INT,campaign_name VARCHAR(50),region VARCHAR(50),budget DECIMAL(10,2),focus VARCHAR(20)); INSERT INTO climate_communication_campaigns (campaign_id,campaign_name,region,budget,focus) VALUES (1,'Climate Action','Asia',1200000.00,'Mitigation'),(2,'Green Future','Asia',750000.00,'Adaptation'),(3,'Eco Life','Asia',1500000.00,'Mitigation');
SELECT campaign_name FROM climate_communication_campaigns WHERE region = 'Asia' AND budget > 1000000.00 AND focus = 'Mitigation';
What is the maximum amount of international climate aid provided to indigenous communities in the Amazon?
CREATE TABLE ClimateAid (ID INT,Community VARCHAR(255),Amount DECIMAL(10,2)); INSERT INTO ClimateAid (ID,Community,Amount) VALUES (1,'Ashaninka',20000),(2,'Yawanawá',25000),(3,'Huni Kui',18000),(4,'Matsés',19000),(5,'Kaxinawá',22000);
SELECT MAX(Amount) FROM ClimateAid WHERE Community IN ('Ashaninka', 'Yawanawá', 'Huni Kui', 'Matsés', 'Kaxinawá');
What is the total number of mental health clinics in each territory of Australia?
CREATE TABLE australia_territories (id INT,name VARCHAR(255)); CREATE TABLE mental_health_clinics (id INT,territory_id INT,name VARCHAR(255)); INSERT INTO australia_territories (id,name) VALUES (1,'New South Wales'),(2,'Victoria'),(3,'Queensland'),(4,'Western Australia'),(5,'South Australia');
SELECT t.name, COUNT(mhc.id) FROM mental_health_clinics mhc JOIN australia_territories t ON mhc.territory_id = t.id GROUP BY t.name;
What is the average number of employees for companies in the 'Technology' industry, categorized by founding year?
CREATE TABLE Company_Info (company_name VARCHAR(50),industry VARCHAR(20),employee_count INT); INSERT INTO Company_Info (company_name,industry,employee_count) VALUES ('Waystar Royco','Media',5000); INSERT INTO Company_Info (company_name,industry,employee_count) VALUES ('Pied Piper','Technology',50); INSERT INTO Company_Info (company_name,industry,employee_count) VALUES ('Austin Biotech','Biotechnology',250); INSERT INTO Company_Info (company_name,industry,employee_count) VALUES ('Everest Technologies','Technology',100);
SELECT founding_year, AVG(employee_count) FROM (SELECT company_name, CASE WHEN industry = 'Technology' THEN founding_year END as founding_year, employee_count FROM Company_Info) t GROUP BY founding_year;
What is the total funding received by female founders?
CREATE TABLE founders (id INT,name VARCHAR(50),gender VARCHAR(10),company_id INT); CREATE TABLE funding (id INT,company_id INT,amount INT);
SELECT SUM(funding.amount) FROM funding JOIN founders ON funding.company_id = founders.company_id WHERE founders.gender = 'female';
What is the distribution of farm sizes in Kenya in 2017?
CREATE TABLE kenyan_regions (region_name TEXT,region_code TEXT); INSERT INTO kenyan_regions (region_name,region_code) VALUES ('Central','CT'),('Coast','CS'); CREATE TABLE farm_sizes (farm_id INTEGER,region TEXT,size INTEGER,year INTEGER); INSERT INTO farm_sizes (farm_id,region,size,year) VALUES (1,'CT',50,2017),(2,'CT',100,2017);
SELECT region, AVG(size), MIN(size), MAX(size), STDDEV(size) FROM farm_sizes JOIN kenyan_regions ON farm_sizes.region = kenyan_regions.region_code WHERE year = 2017 GROUP BY region;
How many support programs were implemented in the Northeast region each year?
CREATE TABLE SupportPrograms (ProgramID INT,ProgramName VARCHAR(50),Region VARCHAR(50),ImplementationYear INT); INSERT INTO SupportPrograms (ProgramID,ProgramName,Region,ImplementationYear) VALUES (1,'Assistive Technology','Northeast',2018),(2,'Sign Language Interpretation','Northeast',2019),(3,'Accessible Furniture','Northeast',2020);
SELECT ImplementationYear, COUNT(ProgramID) FROM SupportPrograms WHERE Region = 'Northeast' GROUP BY ImplementationYear;
Which ocean has the highest average temperature and salinity?
CREATE TABLE oceans (id INT,name VARCHAR(255),avg_temperature DECIMAL(5,2),avg_salinity DECIMAL(5,2)); INSERT INTO oceans (id,name,avg_temperature,avg_salinity) VALUES (1,'Pacific',20.0,34.72); INSERT INTO oceans (id,name,avg_temperature,avg_salinity) VALUES (2,'Atlantic',18.0,35.13); INSERT INTO oceans (id,name,avg_temperature,avg_salinity) VALUES (3,'Indian',22.0,34.56);
SELECT name, MAX(avg_temperature) as max_temperature, MAX(avg_salinity) as max_salinity FROM oceans;
What is the total weight of organic ingredients for a specific product category?
CREATE TABLE Categories (Category_ID INT PRIMARY KEY,Category_Name TEXT); CREATE TABLE Products (Product_ID INT PRIMARY KEY,Product_Name TEXT,Category_ID INT,Organic BOOLEAN,Weight FLOAT); INSERT INTO Categories (Category_ID,Category_Name) VALUES (1,'Facial Care'),(2,'Body Care'),(3,'Hair Care'); INSERT INTO Products (Product_ID,Product_Name,Category_ID,Organic,Weight) VALUES (1,'Cleansing Gel',1,TRUE,50.0),(2,'Hydrating Cream',1,TRUE,30.0),(3,'Refreshing Mist',1,FALSE,20.0),(4,'Nourishing Body Lotion',2,TRUE,75.0),(5,'Volumizing Shampoo',3,FALSE,50.0),(6,'Strengthening Conditioner',3,TRUE,60.0);
SELECT c.Category_Name, SUM(p.Weight) FROM Products p JOIN Categories c ON p.Category_ID = c.Category_ID WHERE p.Organic = TRUE GROUP BY c.Category_ID;
What are the community policing metrics and their corresponding ratings?
CREATE TABLE community_policing (metric_id INT,metric_name VARCHAR(255),rating INT); INSERT INTO community_policing (metric_id,metric_name,rating) VALUES (1,'Community Engagement',90),(2,'Crime Prevention Programs',80);
SELECT metric_name, rating FROM community_policing;
What is the most attended cultural event in the past year?
CREATE TABLE CulturalEvents (id INT,city VARCHAR(50),date DATE,attendance INT); INSERT INTO CulturalEvents (id,city,date,attendance) VALUES (1,'New York','2022-01-01',1000),(2,'Los Angeles','2022-01-02',2000),(3,'New York','2022-01-03',3000);
SELECT * FROM CulturalEvents WHERE date >= DATEADD(year, -1, GETDATE()) ORDER BY attendance DESC LIMIT 1;
Insert a new record into the 'weapons' table with the following data: 'Javelin', 'USA', 'in-development'
CREATE TABLE weapons (id INT PRIMARY KEY,name VARCHAR(255),origin VARCHAR(255),status VARCHAR(255)); INSERT INTO weapons (id,name,origin) VALUES (1,'AK-47','Russia'),(2,'RPG-7','Russia');
INSERT INTO weapons (name, origin, status) VALUES ('Javelin', 'USA', 'in-development');
Present the types of military equipment from Canada
CREATE TABLE military_equipment (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255),country VARCHAR(255));
SELECT type FROM military_equipment WHERE country = 'Canada';
What is the name of each military innovation and the year it was developed by countries in the BRICS?
CREATE TABLE military_innovation (name VARCHAR(50),country VARCHAR(50),year INT); INSERT INTO military_innovation (name,country,year) VALUES ('Stealth Fighter','China',2010),('Cyber Warfare Unit','Russia',2012),('Stealth Frigate','India',2014),('Robot Soldier','Brazil',2015),('Smart Rifle','South Africa',2016);
SELECT mi.name, mi.year FROM military_innovation mi INNER JOIN (SELECT DISTINCT country FROM military_innovation) mic ON mi.country = mic.country;
What is the average transaction amount for clients with a net worth over $1,000,000 in Q4 2023?
CREATE TABLE clients (client_id INT,name VARCHAR(50),net_worth DECIMAL(10,2),last_transaction_date DATE);CREATE TABLE transactions (transaction_id INT,client_id INT,transaction_date DATE,total_amount DECIMAL(10,2));
SELECT AVG(total_amount) FROM transactions t INNER JOIN clients c ON t.client_id = c.client_id WHERE c.net_worth > 1000000 AND t.transaction_date BETWEEN '2023-10-01' AND '2023-12-31'
What is the minimum account balance for clients in the Northwest region?
CREATE TABLE clients (client_id INT,name VARCHAR(50),region VARCHAR(20),account_balance DECIMAL(10,2)); INSERT INTO clients (client_id,name,region,account_balance) VALUES (1,'John Smith','Northwest',30000.00),(2,'Jane Doe','Northeast',22000.00),(3,'Mike Johnson','Northwest',15000.00),(4,'Sara Jones','Southeast',12000.00),(5,'William Brown','Northeast',25000.00),(6,'Emily Davis','Southeast',40000.00),(7,'Olivia Thompson','Northwest',5000.00);
SELECT MIN(account_balance) FROM clients WHERE region = 'Northwest';
Delete a port from the system
ports(port_id,port_name,country,region,location)
DELETE FROM ports WHERE port_id = 5002;
Identify the number of vessels that visited 'Port of Mumbai' in June 2022 but did not carry any perishable cargo.
CREATE TABLE vessels (id INT,name TEXT); CREATE TABLE cargo (id INT,perishable BOOLEAN,vessel_id INT,port_id INT,loaded_date DATE); CREATE TABLE ports (id INT,name TEXT); INSERT INTO vessels (id,name) VALUES (1,'Vessel C'),(2,'Vessel D'); INSERT INTO ports (id,name) VALUES (4,'Port of Mumbai'); INSERT INTO cargo (id,perishable,vessel_id,port_id,loaded_date) VALUES (1,true,1,4,'2022-06-20'),(2,false,2,4,'2022-06-25'),(3,false,1,4,'2022-06-01');
SELECT COUNT(DISTINCT vessels.id) FROM vessels LEFT JOIN cargo ON vessels.id = cargo.vessel_id LEFT JOIN ports ON cargo.port_id = ports.id WHERE ports.name = 'Port of Mumbai' AND cargo.loaded_date >= DATE('2022-06-01') AND cargo.loaded_date <= DATE('2022-06-30') AND cargo.perishable = false GROUP BY vessels.id HAVING COUNT(cargo.id) = 0;
What is the average cargo handling time in hours for each port?
CREATE TABLE cargo_handling (id INT,port_id INT,time_in_hours DECIMAL(5,2)); INSERT INTO cargo_handling (id,port_id,time_in_hours) VALUES (1,1,20.5),(2,1,22.3),(3,2,18.7);
SELECT port_id, AVG(time_in_hours) FROM cargo_handling GROUP BY port_id;
Identify materials with waste generation above the industry average
CREATE TABLE WasteData (manufacturer_id INT,material VARCHAR(50),waste_quantity INT); INSERT INTO WasteData (manufacturer_id,material,waste_quantity) VALUES (1,'Material1',120),(1,'Material2',150),(2,'Material1',80),(2,'Material3',100),(3,'Material2',50),(3,'Material3',130); CREATE TABLE IndustryAverages (material VARCHAR(50),avg_waste INT); INSERT INTO IndustryAverages (material,avg_waste) VALUES ('Material1',100),('Material2',100),('Material3',110);
SELECT w.material, w.waste_quantity, i.avg_waste FROM WasteData w INNER JOIN IndustryAverages i ON w.material = i.material WHERE w.waste_quantity > i.avg_waste;
What is the number of rural hospitals and clinics in each state, and the percentage of hospitals with a CT scan machine in each?
CREATE TABLE hospitals (id INT,name TEXT,location TEXT,num_beds INT,state TEXT,has_ct_scan BOOLEAN); INSERT INTO hospitals (id,name,location,num_beds,state,has_ct_scan) VALUES (1,'Hospital A','Rural Texas',50,'Texas',true),(2,'Hospital B','Rural California',75,'California',false); CREATE TABLE clinics (id INT,name TEXT,location TEXT,num_beds INT,state TEXT); INSERT INTO clinics (id,name,location,num_beds,state) VALUES (1,'Clinic A','Rural Texas',25,'Texas'),(2,'Clinic B','Rural California',35,'California');
SELECT s.state, COUNT(h.id) AS num_hospitals, COUNT(c.id) AS num_clinics, COUNT(h2.id) * 100.0 / (COUNT(h.id) + COUNT(c.id)) AS pct_hospitals_with_ct_scan FROM hospitals h INNER JOIN clinics c ON h.state = c.state INNER JOIN hospitals h2 ON h.state = h2.state AND h2.has_ct_scan = true GROUP BY s.state;
How many green energy projects were funded in the last 3 months, grouped by country?
CREATE TABLE green_energy_funding (id INT,project_name VARCHAR(50),funding_date DATE,country VARCHAR(30)); INSERT INTO green_energy_funding (id,project_name,funding_date,country) VALUES (1,'Wind Farm X','2021-09-15','Germany'),(2,'Solar Park Y','2021-10-05','Spain'),(3,'Geothermal Project Z','2021-11-10','Italy');
SELECT country, COUNT(*) FROM green_energy_funding WHERE funding_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH) GROUP BY country;
Delete the EmployeeDemographics table
CREATE TABLE EmployeeDemographics (EmployeeID INT PRIMARY KEY,Age INT,Gender VARCHAR(10),Ethnicity VARCHAR(20));
DROP TABLE EmployeeDemographics;
Delete all records from the fields table where the field name contains 'Field' and the region is the Gulf of Mexico.
CREATE TABLE fields (field_id INT,field_name TEXT,region TEXT); INSERT INTO fields (field_id,field_name,region) VALUES (1,'Field A','Gulf of Mexico'),(2,'Field B','Caspian Sea'),(3,'Non-Field C','Gulf of Mexico');
DELETE FROM fields WHERE field_name LIKE '%Field%' AND region = 'Gulf of Mexico';
Display the number of social media posts related to ethical AI by month and platform in the 'social_media_posts' table
CREATE TABLE social_media_posts (id INT PRIMARY KEY,post_date DATETIME,platform VARCHAR(50),post_text TEXT);
SELECT EXTRACT(MONTH FROM post_date) as month, platform, COUNT(*) as num_posts FROM social_media_posts WHERE post_text LIKE '%ethical AI%' GROUP BY month, platform ORDER BY month;
Delete fare information for rider 'John Smith'
CREATE TABLE riders (rider_id INT,name VARCHAR(255)); INSERT INTO riders (rider_id,name) VALUES (1,'John Smith'); CREATE TABLE fares (fare_id INT,rider_id INT,fare_amount DECIMAL(5,2));
DELETE FROM fares WHERE rider_id = (SELECT rider_id FROM riders WHERE name = 'John Smith');
How many bus trips were there in the NYC boroughs in Q1 2022?
CREATE TABLE bus_trips(trip_date DATE,borough VARCHAR(20)); INSERT INTO bus_trips (trip_date,borough) VALUES ('2022-01-01','Manhattan'),('2022-01-02','Brooklyn');
SELECT COUNT(*) FROM bus_trips WHERE trip_date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY borough;
What is the distribution of products by size in the ethical fashion market?
CREATE TABLE products (product_id INT,size VARCHAR(10));CREATE TABLE size_ranges (size VARCHAR(10),range VARCHAR(20));
SELECT sr.range, COUNT(p.product_id) FROM products p JOIN size_ranges sr ON p.size = sr.size GROUP BY sr.range;
Find the post with the third highest number of likes in the 'sports' category.
CREATE TABLE posts (id INT,category VARCHAR(20),likes INT); INSERT INTO posts (id,category,likes) VALUES (1,'music',10),(2,'music',15),(3,'sports',20),(4,'sports',30),(5,'sports',40);
SELECT * FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY category ORDER BY likes DESC) as rn FROM posts) t WHERE t.rn = 3 AND t.category = 'sports';
What is the average number of comments for posts in the "social_media_posts" table?
CREATE TABLE social_media_posts (post_id INT,comments_count INT); INSERT INTO social_media_posts (post_id,comments_count) VALUES (1,50),(2,75),(3,30),(4,60),(5,45);
SELECT AVG(comments_count) FROM social_media_posts;
What is the average price of cotton textiles sourced from the United States?
CREATE TABLE textile_sourcing (textile_id INTEGER,material TEXT,country TEXT,price FLOAT); INSERT INTO textile_sourcing (textile_id,material,country,price) VALUES (1,'cotton','United States',5.5),(2,'silk','China',12.0),(3,'polyester','India',3.5);
SELECT AVG(price) FROM textile_sourcing WHERE material = 'cotton' AND country = 'United States';
Who is the customer with the most purchases of 'Sustainable Clothing' in the last 6 months?
CREATE TABLE CustomerOrders (id INT,customer_id INT,product VARCHAR(20),order_date DATE); INSERT INTO CustomerOrders (id,customer_id,product,order_date) VALUES (1,1,'Sustainable T-Shirt','2022-05-03'),(2,2,'Regular Denim','2022-05-05'),(3,1,'Sustainable T-Shirt','2022-04-30'),(4,3,'Sustainable T-Shirt','2022-03-28'),(5,1,'Sustainable T-Shirt','2022-02-15'),(6,4,'Sustainable T-Shirt','2022-01-01'),(7,5,'Sustainable Jacket','2022-05-10'),(8,5,'Sustainable Pants','2022-04-25'),(9,5,'Sustainable Shoes','2022-03-20');
SELECT customer_id, COUNT(*) as num_purchases FROM CustomerOrders WHERE product LIKE 'Sustainable%' AND order_date >= DATEADD(month, -6, CURRENT_DATE) GROUP BY customer_id ORDER BY num_purchases DESC;
Calculate the total number of volunteer hours for the current year, grouped by month and program.
CREATE TABLE Programs (ProgramID int,Name varchar(50),Location varchar(50)); CREATE TABLE Volunteers (VolunteerID int,Name varchar(50),ProgramID int,VolunteerDate date,Hours decimal(10,2)); INSERT INTO Programs (ProgramID,Name,Location) VALUES (1,'Reforestation','Indonesia'),(2,'Animal Rescue','Australia'); INSERT INTO Volunteers (VolunteerID,Name,ProgramID,VolunteerDate,Hours) VALUES (1,'Aaron',1,'2021-12-31',5.00),(2,'Sophie',2,'2022-01-01',10.00),(3,'Benjamin',1,'2022-02-01',15.00),(4,'Emily',1,'2022-03-01',20.00);
SELECT P.Name, DATE_FORMAT(V.VolunteerDate, '%Y-%m') AS Month, SUM(V.Hours) AS TotalHours FROM Programs P JOIN Volunteers V ON P.ProgramID = V.ProgramID WHERE YEAR(V.VolunteerDate) = YEAR(CURDATE()) GROUP BY P.ProgramID, Month;
Show the total calories of dishes served in 'HealthyHarvest' that have a price above the average.
CREATE TABLE Dishes (dish_name VARCHAR(50),calories INT,price INT); INSERT INTO Dishes (dish_name,calories,price) VALUES ('Chia Pudding',250,10),('Veggie Wrap',500,15),('Spinach Salad',300,12),('Quinoa Salad',400,13);
SELECT SUM(Dishes.calories) FROM Dishes WHERE Dishes.dish_name LIKE 'HealthyHarvest%' AND Dishes.price > (SELECT AVG(price) FROM Dishes)
List the top 3 busiest warehouses in terms of shipments in the USA.
CREATE TABLE Warehouses (WarehouseID INT,WarehouseName VARCHAR(50),Country VARCHAR(50)); INSERT INTO Warehouses (WarehouseID,WarehouseName,Country) VALUES (1,'NY Warehouse','USA'),(2,'LA Warehouse','USA'); CREATE TABLE Shipments (ShipmentID INT,WarehouseID INT,Quantity INT);
SELECT WarehouseID, WarehouseName, SUM(Quantity) AS TotalQuantity FROM Warehouses W JOIN Shipments S ON W.WarehouseID = S.WarehouseID WHERE W.Country = 'USA' GROUP BY WarehouseID, WarehouseName ORDER BY TotalQuantity DESC LIMIT 3;
Update the item name of the warehouse management record with ID 1
CREATE TABLE warehouse_management (id INT,aisle VARCHAR(255),item_name VARCHAR(255)); INSERT INTO warehouse_management (id,aisle,item_name) VALUES (1,'Aisle 3','Widget'),(2,'Aisle 8','Thingamajig'),(3,'Aisle 8','Gizmo');
UPDATE warehouse_management SET item_name = 'Super Widget' WHERE id = 1;
What are the top 3 reverse logistics return points in Europe in H1 2022?
CREATE TABLE returns (return_id INT,return_point VARCHAR(255),return_half INT,return_year INT); INSERT INTO returns (return_id,return_point,return_half,return_year) VALUES (1,'Paris',1,2022),(2,'Berlin',1,2022),(3,'London',1,2022),(4,'Rome',1,2022),(5,'Madrid',1,2022);
SELECT return_point, SUM(return_id) as total_returns FROM returns WHERE return_half = 1 AND return_year = 2022 GROUP BY return_point ORDER BY total_returns DESC LIMIT 3;
What is the average funding received by startups in the biotechnology sector located in the USA?
CREATE SCHEMA if not exists biotech;CREATE TABLE if not exists biotech.startups (id INT,name TEXT,location TEXT,funding DECIMAL(10,2),industry TEXT);INSERT INTO biotech.startups (id,name,location,funding,industry) VALUES (1,'StartupA','USA',1500000.00,'Biotechnology'),(2,'StartupB','Canada',2000000.00,'Artificial Intelligence');
SELECT AVG(funding) FROM biotech.startups WHERE industry = 'Biotechnology' AND location = 'USA';
List the unique types of public services offered in 'public_services' table, excluding services of type 'type_c' and 'type_d'.
CREATE TABLE public_services (service_type VARCHAR(255));
SELECT DISTINCT service_type FROM public_services WHERE service_type NOT IN ('type_c', 'type_d');
Show the research grants awarded to professors in the Computer Science department.
CREATE TABLE departments (id INT,name VARCHAR(50)); INSERT INTO departments (id,name) VALUES (1,'Computer Science'),(2,'Mathematics'); CREATE TABLE professors (id INT,name VARCHAR(50),department_id INT); INSERT INTO professors (id,name,department_id) VALUES (1,'John Smith',1),(2,'Jane Doe',2); CREATE TABLE grants (id INT,professor_id INT,year INT,amount FLOAT); INSERT INTO grants (id,professor_id,year,amount) VALUES (1,1,2021,5000.0),(2,2,2020,7000.0);
SELECT professors.name, grants.amount FROM professors INNER JOIN grants ON professors.id = grants.professor_id INNER JOIN departments ON professors.department_id = departments.id WHERE departments.name = 'Computer Science';
How many community health workers are there in each region?
CREATE TABLE region_health_workers (region VARCHAR(10),worker_count INT); INSERT INTO region_health_workers (region,worker_count) VALUES ('Northeast',50),('Southeast',75),('Midwest',100);
SELECT region, SUM(worker_count) FROM region_health_workers GROUP BY region;
How many virtual tours were taken in Japan in the past year?
CREATE TABLE virtual_tours (tour_id INT,location TEXT,views INT,date DATE); INSERT INTO virtual_tours (tour_id,location,views,date) VALUES (1,'Mt. Fuji',2000,'2021-10-01'),(2,'Tokyo Tower',1500,'2021-09-01');
SELECT COUNT(*) FROM virtual_tours WHERE location = 'Japan' AND date >= DATEADD(year, -1, GETDATE());
How many virtual tours have been engaged with for hotels that have implemented AI-powered housekeeping solutions in Africa?
CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,region TEXT); CREATE TABLE ai_solutions (solution_id INT,hotel_id INT,implemented_date DATE,solution_type TEXT); CREATE TABLE virtual_tours (tour_id INT,hotel_id INT,engagement_score INT); INSERT INTO hotels (hotel_id,hotel_name,region) VALUES (1,'Savannah Lodge','Africa'),(2,'Mountain Safari Resort','Africa'); INSERT INTO ai_solutions (solution_id,hotel_id,implemented_date,solution_type) VALUES (1,1,'2021-02-01','housekeeping'),(2,1,'2021-03-01','front desk'),(1,2,'2021-01-01','housekeeping'),(2,2,'2021-02-01','housekeeping'); INSERT INTO virtual_tours (tour_id,hotel_id,engagement_score) VALUES (1,1,70),(2,1,75),(1,2,80),(2,2,85);
SELECT COUNT(DISTINCT vt.hotel_id) AS total_tours_engaged FROM virtual_tours vt INNER JOIN hotels h ON vt.hotel_id = h.hotel_id INNER JOIN ai_solutions ai ON h.hotel_id = ai.hotel_id WHERE h.region = 'Africa' AND ai.solution_type = 'housekeeping';
Show all artworks and their prices from the 'Surrealism' period.
CREATE TABLE Artworks (id INT,artist_name VARCHAR(100),period VARCHAR(50),artwork_name VARCHAR(100),price FLOAT); INSERT INTO Artworks (id,artist_name,period,artwork_name,price) VALUES (1,'Salvador Dalí','Surrealism','The Persistence of Memory',500000.0); INSERT INTO Artworks (id,artist_name,period,artwork_name,price) VALUES (2,'René Magritte','Surrealism','The Son of Man',100000.0);
SELECT artwork_name, price FROM Artworks WHERE period = 'Surrealism';
What is the average temperature recorded in the 'arctic_weather' table for each month in the year 2020, broken down by species ('species' column in the 'arctic_weather' table)?
CREATE TABLE arctic_weather (id INT,date DATE,temperature FLOAT,species VARCHAR(50));
SELECT MONTH(date) AS month, species, AVG(temperature) AS avg_temp FROM arctic_weather WHERE YEAR(date) = 2020 GROUP BY month, species;
What's the average age of patients diagnosed with anxiety disorders?
CREATE TABLE patients (patient_id INT,name VARCHAR(50),age INT,gender VARCHAR(10),condition VARCHAR(50)); INSERT INTO patients (patient_id,name,age,gender,condition) VALUES (1,'John Doe',30,'Male','Anxiety Disorder'); INSERT INTO patients (patient_id,name,age,gender,condition) VALUES (3,'Alice Johnson',40,'Female','Depression'); INSERT INTO patients (patient_id,name,age,gender,condition) VALUES (5,'Bob Smith',25,'Male','Anxiety Disorder');
SELECT AVG(age) FROM patients WHERE condition = 'Anxiety Disorder';
What is the difference in construction cost between the most expensive and least expensive road projects in Australia?
CREATE TABLE Road_Australia (Project VARCHAR(50),Country VARCHAR(50),Cost FLOAT); INSERT INTO Road_Australia (Project,Country,Cost) VALUES ('Sydney Road','Australia',4000000),('Melbourne Road','Australia',3000000);
SELECT MAX(Cost) - MIN(Cost) as Cost_Difference FROM Road_Australia WHERE Country = 'Australia';
What is the market spend on sustainable tourism initiatives in Japan between 2017 and 2019?
CREATE TABLE sustainable_tourism_initiatives(initiative_id INT,name TEXT,country TEXT,start_year INT,end_year INT,market_spend INT);INSERT INTO sustainable_tourism_initiatives (initiative_id,name,country,start_year,end_year,market_spend) VALUES (1,'Eco-friendly hotels in Tokyo','Japan',2017,2019,5000000),(2,'Sustainable transport in Kyoto','Japan',2018,2019,7000000),(3,'Carbon offsetting in Osaka','Japan',2017,2018,3000000);
SELECT SUM(market_spend) FROM sustainable_tourism_initiatives WHERE country = 'Japan' AND start_year BETWEEN 2017 AND 2019;
What is the number of international visitors to Brazil in 2022 and their average expenditures?
CREATE TABLE Visitors_Brazil (id INT,year INT,country VARCHAR(50),expenditure FLOAT); INSERT INTO Visitors_Brazil (id,year,country,expenditure) VALUES (1,2022,'Brazil',1200),(2,2022,'Brazil',1300),(3,2022,'Brazil',1400);
SELECT AVG(Visitors_Brazil.expenditure) FROM Visitors_Brazil WHERE Visitors_Brazil.country = 'Brazil' AND Visitors_Brazil.year = 2022;
Which destinations have the least hotel awards?
CREATE TABLE Destinations (destination_id INT,destination_name TEXT,country TEXT,awards INT); INSERT INTO Destinations (destination_id,destination_name,country,awards) VALUES (1,'City A','Germany',3),(2,'City B','Switzerland',5),(3,'City C','Norway',2);
SELECT destination_name, country, awards, RANK() OVER (PARTITION BY country ORDER BY awards ASC) AS rank FROM Destinations;
What is the number of legal aid organizations in each county?
CREATE TABLE legal_aid_organizations (org_id INT,org_name TEXT,county TEXT,cases_handled INT); INSERT INTO legal_aid_organizations VALUES (1,'LegalAid1','San Francisco',250),(2,'LegalAid2','Dallas',300),(3,'LegalAid3','New York',200),(4,'LegalAid4','Los Angeles',200),(5,'LegalAid5','Miami-Dade',150);
SELECT county, COUNT(*) FROM legal_aid_organizations GROUP BY county;
Determine the total biomass of marine species in the 'Coral Reef' ecosystem.
CREATE SCHEMA MarineEcosystems(ecosystem_id INT,ecosystem_name TEXT);CREATE SCHEMA MarineSpecies(species_id INT,species_name TEXT,biomass INT);INSERT INTO MarineEcosystems(ecosystem_id,ecosystem_name) VALUES (1,'Coral Reef'); INSERT INTO MarineSpecies(species_id,species_name,biomass) VALUES (1,'Clownfish',20),(2,'Sea Turtle',150),(3,'Coral',1000);
SELECT s.biomass FROM MarineSpecies s JOIN MarineEcosystems e ON s.species_id IN (1, 2, 3) AND e.ecosystem_name = 'Coral Reef';
How many marine species are affected by pollution in the Arctic Ocean?
CREATE TABLE Arctic_Marine_Species (species_name TEXT,population INT,is_affected_by_pollution BOOLEAN); INSERT INTO Arctic_Marine_Species (species_name,population,is_affected_by_pollution) VALUES ('Polar Bear',26500,true),('Narwhal',174000,true),('Beluga Whale',105000,false);
SELECT COUNT(*) FROM Arctic_Marine_Species WHERE is_affected_by_pollution = true;
What is the average number of views for Korean and Japanese movies?
CREATE TABLE movies (id INT,title VARCHAR(255),release_year INT,views INT,country VARCHAR(50)); INSERT INTO movies (id,title,release_year,views,country) VALUES (1,'Movie1',2010,15000,'South Korea'),(2,'Movie2',2015,20000,'Japan'),(3,'Movie3',2020,25000,'South Korea'),(4,'Movie4',2005,30000,'Japan');
SELECT AVG(views) FROM movies WHERE country = 'South Korea' UNION SELECT AVG(views) FROM movies WHERE country = 'Japan';
List the top 5 mines with the highest environmental impact in the past year?
CREATE TABLE mine_environmental_impact (mine_name VARCHAR(255),impact NUMERIC,measurement_date DATE); INSERT INTO mine_environmental_impact (mine_name,impact,measurement_date) VALUES ('Mine A',1000,'2021-08-01'),('Mine B',2000,'2021-08-01'),('Mine C',1500,'2021-08-01'),('Mine A',1200,'2020-08-01'),('Mine B',1800,'2020-08-01');
SELECT mine_name, impact FROM (SELECT mine_name, impact, measurement_date, RANK() OVER (ORDER BY impact DESC) as rnk FROM mine_environmental_impact WHERE measurement_date >= DATEADD(year, -1, CURRENT_DATE)) t WHERE rnk <= 5;
What was the average labor productivity in the mining industry in Australia, by year, for the last 5 years?
CREATE TABLE LaborProductivity (year INT,country TEXT,industry TEXT,productivity FLOAT); INSERT INTO LaborProductivity (year,country,industry,productivity) VALUES (2017,'Australia','Mining',125000),(2018,'Australia','Mining',130000),(2019,'Australia','Mining',135000),(2020,'Australia','Mining',140000),(2021,'Australia','Mining',145000);
SELECT context.year, AVG(context.productivity) as avg_productivity FROM LaborProductivity context WHERE context.country = 'Australia' AND context.industry = 'Mining' AND context.year BETWEEN 2017 AND 2021 GROUP BY context.year;
List the names and roles of mining engineers whose names start with 'A' or 'B'.
CREATE TABLE mine_operators (id INT PRIMARY KEY,name VARCHAR(50),role VARCHAR(50),gender VARCHAR(10),years_of_experience INT); INSERT INTO mine_operators (id,name,role,gender,years_of_experience) VALUES (1,'John Doe','Mining Engineer','Male',7),(2,'Aisha','Mining Engineer','Female',3);
SELECT name, role FROM mine_operators WHERE name LIKE 'A%' OR name LIKE 'B%';
How many articles were published in each month of the year?
CREATE TABLE articles (id INT,title VARCHAR(50),publish_date DATE); INSERT INTO articles (id,title,publish_date) VALUES (1,'Article One','2022-01-01'),(2,'Article Two','2022-02-01');
SELECT EXTRACT(MONTH FROM publish_date) AS month, COUNT(*) AS count FROM articles GROUP BY month ORDER BY month;
List all organizations that received donations from 'Brazil' in '2023'.
CREATE TABLE donations (donation_id INT,donor_id INT,organization_id INT,donation_year INT,donation_amount FLOAT); INSERT INTO donations (donation_id,donor_id,organization_id,donation_year,donation_amount) VALUES (1,1,101,2023,200.00),(2,2,102,2023,300.00),(3,3,103,2023,100.00); CREATE TABLE organizations (organization_id INT,organization_name TEXT); INSERT INTO organizations (organization_id,organization_name) VALUES (101,'Food Bank'),(102,'Habitat for Humanity'),(103,'Red Cross');
SELECT organization_name FROM organizations JOIN donations ON organizations.organization_id = donations.organization_id WHERE donation_year = 2023 AND EXISTS (SELECT 1 FROM donors WHERE donors.donor_country = 'Brazil' AND donors.donor_id = donations.donor_id);
Add a new marine species 'Blue Whale' with weight 200000 in the 'North Atlantic Ocean' to the marine_species table
CREATE TABLE marine_species (name VARCHAR(255),weight FLOAT,location VARCHAR(255)); INSERT INTO marine_species (name,weight,location) VALUES ('Great White Shark',2000.0,'Pacific Ocean'),('Giant Squid',700.0,'Atlantic Ocean');
INSERT INTO marine_species (name, weight, location) VALUES ('Blue Whale', 200000.0, 'North Atlantic Ocean');
Insert records of new players who have not registered yet
CREATE TABLE players (id INT PRIMARY KEY,name VARCHAR(50),registration_date TIMESTAMP); INSERT INTO players VALUES (1001,'John Doe','2021-01-01 12:00:00'),(1002,'Jane Doe','2021-02-15 14:30:00'),(1003,'Jim Smith','2021-06-20 09:15:00'); CREATE TABLE new_players (id INT,name VARCHAR(50),registration_date TIMESTAMP);
INSERT INTO players SELECT * FROM new_players WHERE NOT EXISTS (SELECT 1 FROM players WHERE players.id = new_players.id);
What is the average age of players who play "Racing Simulator 2022"?
CREATE TABLE Players (PlayerID INT,PlayerName VARCHAR(50),Game VARCHAR(50),Age INT); INSERT INTO Players (PlayerID,PlayerName,Game,Age) VALUES (1,'John Doe','Racing Simulator 2022',25),(2,'Jane Smith','Racing Simulator 2022',30),(3,'Alice Johnson','Shooter Game 2022',22);
SELECT AVG(Age) FROM Players WHERE Game = 'Racing Simulator 2022';
What is the average property price in the city of 'Oakland' from the 'property' table?
CREATE TABLE property (id INT,city VARCHAR(20),price INT); INSERT INTO property (id,city,price) VALUES (1,'Oakland',500000),(2,'San_Francisco',700000);
SELECT AVG(price) FROM property WHERE city = 'Oakland';
What is the number of space missions launched by each country?
CREATE TABLE space_missions (country TEXT,year INT); INSERT INTO space_missions (country,year) VALUES ('USA',2015),('USA',2015),('USA',2016),('Russia',2015),('Russia',2016),('China',2016),('China',2017),('India',2017);
SELECT country, COUNT(*) FROM space_missions GROUP BY country;
How many security incidents were reported in the APAC region last year?
CREATE TABLE incidents (id INT,region TEXT,date_reported DATE); INSERT INTO incidents (id,region,date_reported) VALUES (1,'APAC','2021-05-03'); INSERT INTO incidents (id,region,date_reported) VALUES (2,'Americas','2021-06-17'); INSERT INTO incidents (id,region,date_reported) VALUES (3,'APAC','2021-07-24'); INSERT INTO incidents (id,region,date_reported) VALUES (4,'Europe','2021-08-30'); INSERT INTO incidents (id,region,date_reported) VALUES (5,'APAC','2021-09-13');
SELECT COUNT(*) as count FROM incidents WHERE region = 'APAC' AND date_reported >= '2021-01-01' AND date_reported < '2022-01-01';
Which countries have the most open vulnerabilities in the last quarter?
CREATE TABLE vulnerabilities (id INT,country VARCHAR(50),open_date DATE,close_date DATE);
SELECT country, COUNT(*) as vulnerability_count FROM vulnerabilities WHERE close_date IS NULL AND open_date >= DATEADD(quarter, -1, GETDATE()) GROUP BY country;
Add a new station to the stations table for the city of Oslo, Norway.
stations (id,name,city,country,latitude,longitude)
INSERT INTO stations (name, city, country) VALUES ('Oslo Central', 'Oslo', 'Norway');
What is the average CO2 emission reduction for electric vehicles?
CREATE TABLE co2_emission (id INT,ev_model VARCHAR(50),co2_reduction FLOAT); INSERT INTO co2_emission (id,ev_model,co2_reduction) VALUES (1,'Tesla Model 3',45.0),(2,'Nissan Leaf',40.0),(3,'Chevrolet Bolt',42.0);
SELECT AVG(co2_reduction) FROM co2_emission;
What is the total CO2 emissions by manufacturer in 2022?
CREATE TABLE co2_emissions_manufacturers (manufacturer VARCHAR(50),co2_emissions DECIMAL(10,2),date DATE);
SELECT manufacturer, SUM(co2_emissions) AS total_co2_emissions FROM co2_emissions_manufacturers WHERE date >= '2022-01-01' AND date < '2023-01-01' GROUP BY manufacturer;
What is the total number of workplace safety violations issued to non-union workplaces in New York in Q3 2022?
CREATE TABLE violations (id INT,workplace_id INT,union_status VARCHAR,violation_date DATE); INSERT INTO violations (id,workplace_id,union_status,violation_date) VALUES (1,2,'non-union','2022-07-15');
SELECT union_status, COUNT(*) as total_violations FROM violations WHERE state = 'New York' AND violation_date >= '2022-07-01' AND violation_date < '2022-10-01' AND union_status = 'non-union' GROUP BY union_status;
What is the average budget for agricultural innovation projects in 'region_1' and 'region_2'?
CREATE TABLE agricultural_innovation (id INT,region VARCHAR(50),budget DECIMAL(10,2)); INSERT INTO agricultural_innovation (id,region,budget) VALUES (1,'region_1',100000.00); INSERT INTO agricultural_innovation (id,region,budget) VALUES (2,'region_2',150000.00);
SELECT AVG(budget) FROM agricultural_innovation WHERE region IN ('region_1', 'region_2');
Who are the astronauts that have flown on missions with a total cost greater than $150,000,000?
CREATE TABLE astronauts (astronaut_name VARCHAR(255),mission_name VARCHAR(255),total_cost DECIMAL(10,2)); INSERT INTO astronauts (astronaut_name,mission_name,total_cost) VALUES ('Astronaut1','Mission1',120000000.00),('Astronaut2','Mission2',180000000.00),('Astronaut3','Mission3',100000000.00),('Astronaut1','Mission4',160000000.00),('Astronaut4','Mission5',200000000.00);
SELECT DISTINCT astronaut_name FROM astronauts WHERE total_cost > 150000000.00;
Find the event with the highest attendance and the corresponding date.
CREATE TABLE Events (event_name VARCHAR(255),event_date DATE,attendee_count INT); INSERT INTO Events (event_name,event_date,attendee_count) VALUES ('Art Exhibition','2022-03-15',200),('Dance Performance','2021-12-20',150),('Music Concert','2022-08-30',250);
SELECT event_name, event_date, attendee_count FROM Events WHERE attendee_count = (SELECT MAX(attendee_count) FROM Events);
What is the total amount of funding received by events in the "Music" category?
CREATE TABLE Events (EventID INT,Category VARCHAR(50),FundingReceived DECIMAL(10,2)); INSERT INTO Events (EventID,Category,FundingReceived) VALUES (1,'Music',10000),(2,'Theater',15000); CREATE TABLE Funding (FundingID INT,Amount DECIMAL(10,2),EventID INT); INSERT INTO Funding (FundingID,Amount,EventID) VALUES (1,5000,1),(2,7500,2);
SELECT SUM(Funding.Amount) AS TotalFundingReceived FROM Funding INNER JOIN Events ON Funding.EventID = Events.EventID WHERE Events.Category = 'Music';
What is the average content rating for action movies?
CREATE TABLE Movies (title VARCHAR(255),genre VARCHAR(255),rating DECIMAL(3,2)); INSERT INTO Movies (title,genre,rating) VALUES ('MovieA','Action',7.5),('MovieB','Comedy',8.0),('MovieC','Action',8.2),('MovieD','Drama',7.8),('MovieE','Action',8.5);
SELECT AVG(rating) FROM Movies WHERE genre = 'Action';
What was the total weight of cannabis sold by each distributor in the second quarter of 2021?
CREATE TABLE sales (id INT,distributor VARCHAR(50),weight DECIMAL(10,2),month INT,year INT);
SELECT distributor, SUM(weight) FROM sales WHERE month BETWEEN 4 AND 6 AND year = 2021 GROUP BY distributor;
List all renewable energy projects in Africa with their budgets?
CREATE TABLE projects (region TEXT,name TEXT,budget FLOAT); INSERT INTO projects (region,name,budget) VALUES ('Africa','Project A',1000000);
SELECT name, budget FROM projects WHERE region = 'Africa' AND type = 'renewable';
What is the total amount of international climate finance provided to Small Island Developing States (SIDS) for climate mitigation projects between 2018 and 2020?
CREATE TABLE climate_finance (region VARCHAR(50),year INT,sector VARCHAR(50),is_sids BOOLEAN,amount FLOAT); INSERT INTO climate_finance (region,year,sector,is_sids,amount) VALUES ('Caribbean',2018,'Mitigation',TRUE,1200.5),('Caribbean',2019,'Mitigation',TRUE,1500.3),('Caribbean',2020,'Mitigation',TRUE,1800.2),('Pacific',2018,'Mitigation',TRUE,200.5),('Pacific',2019,'Mitigation',TRUE,250.3),('Pacific',2020,'Mitigation',TRUE,300.2);
SELECT SUM(amount) FROM climate_finance WHERE is_sids = TRUE AND sector = 'Mitigation' AND year BETWEEN 2018 AND 2020;
Insert a new drug with a price 10% higher than the average price
CREATE TABLE drugs (drug_id INT,drug_name VARCHAR(50),price DECIMAL(10,2)); INSERT INTO drugs (drug_id,drug_name,price) VALUES (1,'DrugA',50),(2,'DrugB',75),(3,'DrugC',100)
INSERT INTO drugs (drug_id, drug_name, price) VALUES ((SELECT MAX(drug_id) FROM drugs) + 1, 'DrugD', (SELECT AVG(price) * 1.1 FROM drugs))
What was the average cost of clinical trials for antiviral drugs?
CREATE TABLE clinical_trials (drug_class TEXT,trial_cost INTEGER); INSERT INTO clinical_trials
SELECT AVG(trial_cost) FROM clinical_trials WHERE drug_class = 'antiviral';
Identify the most common causes of death, by age group and gender.
CREATE TABLE deaths (id INT,age_group INT,gender VARCHAR,cause VARCHAR);
SELECT d.age_group, d.gender, d.cause, COUNT(d.id) AS num_deaths FROM deaths d GROUP BY d.age_group, d.gender, d.cause ORDER BY num_deaths DESC;
Which policy has the lowest healthcare access score in California?
CREATE TABLE policy (name TEXT,state TEXT,score INT);
SELECT name FROM policy WHERE state = 'California' AND score = (SELECT MIN(score) FROM policy WHERE state = 'California');
Determine the total production of 'cotton' and 'tobacco' by region and state.
CREATE TABLE crops (id INT PRIMARY KEY,state TEXT,region TEXT,crop TEXT,production INT); INSERT INTO crops (id,state,region,crop,production) VALUES (1,'Texas','South','Cotton',1000);
SELECT region, state, SUM(production) FROM crops WHERE crop IN ('cotton', 'tobacco') GROUP BY region, state;