instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What are the top 3 cruelty-free certified cosmetic products by sales in the European market?
CREATE TABLE products (product_id INT,product_name VARCHAR(255),region VARCHAR(50),sales FLOAT,certified_cruelty_free BOOLEAN); INSERT INTO products (product_id,product_name,region,sales,certified_cruelty_free) VALUES (1,'Lipstick A','Europe',5000,true),(2,'Foundation B','Asia',7000,false),(3,'Mascara C','Europe',6000,true),(4,'Eye-shadow D','America',8000,false),(5,'Blush E','Europe',4000,true);
SELECT product_name, sales FROM products WHERE region = 'Europe' AND certified_cruelty_free = true ORDER BY sales DESC LIMIT 3;
What was the total military equipment sales revenue for contractor Z in Q2 2022?
CREATE TABLE revenue(id INT,contractor VARCHAR(50),revenue NUMERIC,quarter INT);
SELECT SUM(revenue) FROM revenue WHERE contractor = 'Z' AND quarter = 2;
What is the minimum ocean acidification level in the Indian Ocean?
CREATE TABLE ocean_acidification_indian (location text,level numeric); INSERT INTO ocean_acidification_indian (location,level) VALUES ('Indian Ocean',8.1),('Southern Ocean',8.2);
SELECT MIN(level) FROM ocean_acidification_indian WHERE location = 'Indian Ocean';
What is the total CO2 emission for each research expedition?
CREATE TABLE ResearchExpeditions(expedition VARCHAR(50),co2_emission FLOAT);INSERT INTO ResearchExpeditions(expedition,co2_emission) VALUES('Expedition 1',10000.0),('Expedition 2',15000.0),('Expedition 3',20000.0),('Expedition 4',12000.0);
SELECT expedition, SUM(co2_emission) FROM ResearchExpeditions GROUP BY expedition;
Identify the circular economy initiatives that have a higher budget allocation than 'Waste to Energy' program in the 'South' region.
CREATE TABLE initiatives (initiative_name VARCHAR(50),region VARCHAR(50),budget INT); INSERT INTO initiatives (initiative_name,region,budget) VALUES ('Waste to Energy','South',2000000),('Recycling','South',2500000),('Composting','South',1500000);
SELECT initiative_name, budget FROM initiatives WHERE region = 'South' AND budget > (SELECT budget FROM initiatives WHERE initiative_name = 'Waste to Energy') AND initiative_name != 'Waste to Energy';
What is the average age of players who have played 'Space Conquerors' and are from India?
CREATE TABLE Players (PlayerID INT,PlayerAge INT,GameName VARCHAR(255),Country VARCHAR(255)); INSERT INTO Players (PlayerID,PlayerAge,GameName,Country) VALUES (1,22,'Space Conquerors','India'); INSERT INTO Players (PlayerID,PlayerAge,GameName,Country) VALUES (2,28,'Space Conquerors','United States');
SELECT AVG(PlayerAge) FROM (SELECT PlayerAge FROM Players WHERE GameName = 'Space Conquerors' AND Country = 'India') AS Subquery;
What is the total production budget for movies by director?
CREATE TABLE movie_budget (id INT,movie TEXT,director TEXT,budget INT); INSERT INTO movie_budget (id,movie,director,budget) VALUES (1,'Movie4','Director1',1000000); INSERT INTO movie_budget (id,movie,director,budget) VALUES (2,'Movie5','Director2',1200000); INSERT INTO movie_budget (id,movie,director,budget) VALUES (3,'Movie6','Director1',1500000);
SELECT director, SUM(budget) as total_budget FROM movie_budget GROUP BY director;
How many refugees arrived in each region in 2020?
CREATE TABLE refugees (id INT PRIMARY KEY,name VARCHAR(50),arrival_date DATE,region VARCHAR(50)); INSERT INTO refugees (id,name,arrival_date,region) VALUES (1,'Ahmed','2020-01-01','Middle East'),(2,'Sofia','2020-05-10','Europe'),(3,'Hiroshi','2019-12-31','Asia');
SELECT region, COUNT(*) as num_refugees FROM refugees WHERE YEAR(arrival_date) = 2020 GROUP BY region;
What was the average Yttrium production in Oceania between 2016 and 2018?
CREATE TABLE production (year INT,region VARCHAR(10),element VARCHAR(10),quantity INT); INSERT INTO production (year,region,element,quantity) VALUES (2015,'Oceania','Yttrium',1200),(2016,'Oceania','Yttrium',1400),(2017,'Oceania','Yttrium',1500),(2018,'Oceania','Yttrium',1700),(2019,'Oceania','Yttrium',1800);
SELECT AVG(quantity) FROM production WHERE element = 'Yttrium' AND region = 'Oceania' AND year BETWEEN 2016 AND 2018;
Insert a new record for the 2022 Tesla Model X with a safety rating of 5 and a release date of 2022-02-22.
CREATE TABLE Vehicles (Id INT,Name TEXT,Type TEXT,SafetyRating INT,ReleaseDate DATE);
INSERT INTO Vehicles (Name, Type, SafetyRating, ReleaseDate) VALUES ('2022 Tesla Model X', 'Electric', 5, '2022-02-22');
What is the maximum speed reached by an electric vehicle in a shared fleet in San Francisco?
CREATE TABLE shared_ev (vehicle_id INT,trip_id INT,trip_start_time TIMESTAMP,trip_end_time TIMESTAMP,start_latitude DECIMAL(9,6),start_longitude DECIMAL(9,6),end_latitude DECIMAL(9,6),end_longitude DECIMAL(9,6),distance DECIMAL(10,2),max_speed DECIMAL(5,2));
SELECT MAX(max_speed) FROM shared_ev WHERE start_longitude BETWEEN -122.6 AND -121.9 AND start_latitude BETWEEN 37.6 AND 38.1;
Find the total claim amount for policyholders in 'Michigan' who have policies issued in 2019 and having a claim amount greater than $750.
CREATE TABLE policyholders (id INT,name TEXT,state TEXT); CREATE TABLE policies (id INT,policyholder_id INT,issue_date DATE,claim_amount FLOAT); INSERT INTO policyholders (id,name,state) VALUES (1,'Sophia Thompson','MI'); INSERT INTO policies (id,policyholder_id,issue_date,claim_amount) VALUES (1,1,'2019-11-15',800.00);
SELECT SUM(claim_amount) FROM policies INNER JOIN policyholders ON policies.policyholder_id = policyholders.id WHERE issue_date >= '2019-01-01' AND issue_date < '2020-01-01' AND claim_amount > 750 AND policyholders.state = 'MI';
Add a new record to the "warehouses" table with the following data: warehouse_name = "Mumbai Warehouse", country = "India", capacity = 5000, and current_inventory = 3000
CREATE TABLE warehouses (id INT,warehouse_name VARCHAR(50),country VARCHAR(50),capacity INT,current_inventory INT);
INSERT INTO warehouses (id, warehouse_name, country, capacity, current_inventory) VALUES (1, 'Mumbai Warehouse', 'India', 5000, 3000);
List the financial wellbeing programs in Africa with the lowest average monthly cost.
CREATE TABLE programs (id INT PRIMARY KEY,program_name VARCHAR(255),region_id INT,is_financial_wellbeing BOOLEAN,monthly_cost DECIMAL(5,2)); CREATE TABLE regions (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255)); CREATE VIEW program_views AS SELECT programs.id,programs.program_name,programs.region_id,programs.is_financial_wellbeing,programs.monthly_cost,regions.country FROM programs INNER JOIN regions ON TRUE;
SELECT program_views.program_name, program_views.monthly_cost FROM program_views WHERE program_views.is_financial_wellbeing = TRUE AND regions.country = 'Africa' ORDER BY program_views.monthly_cost ASC LIMIT 1;
How many water resources were distributed in Syria in H1 2021?
CREATE TABLE water_resources (id INT,quantity INT,country TEXT,half INT,year INT); INSERT INTO water_resources (id,quantity,country,half,year) VALUES (1,600,'Syria',1,2021),(2,400,'Syria',2,2021),(3,500,'Syria',1,2021);
SELECT SUM(quantity) FROM water_resources WHERE country = 'Syria' AND half = 1 AND year = 2021;
What is the total funding for startups founded by individuals from each country?
CREATE TABLE startups (id INT,name TEXT,founder TEXT,country TEXT,funding FLOAT); INSERT INTO startups (id,name,founder,country,funding) VALUES (1,'Acme','John Doe','USA',500000.00); INSERT INTO startups (id,name,founder,country,funding) VALUES (2,'Beta Corp','Jane Smith','Canada',750000.00); INSERT INTO startups (id,name,founder,country,funding) VALUES (3,'Gamma Inc','Alice','India',300000.00); INSERT INTO startups (id,name,founder,country,funding) VALUES (4,'Delta','Bob','USA',800000.00);
SELECT country, SUM(funding) FROM startups GROUP BY country;
What is the carbon price in the European Union Emissions Trading System?
CREATE TABLE carbon_prices (region TEXT,price FLOAT); INSERT INTO carbon_prices (region,price) VALUES ('European Union Emissions Trading System',25.0);
SELECT price FROM carbon_prices WHERE region = 'European Union Emissions Trading System';
Add a new marine research project in the Atlantic Ocean
CREATE TABLE marine_research_projects (id INT PRIMARY KEY,project_name VARCHAR(255),region VARCHAR(255));
INSERT INTO marine_research_projects (id, project_name, region) VALUES (1, 'Exploring Atlantic Depths', 'Atlantic Ocean');
What is the number of public libraries in Seattle, Washington that offer free Wi-Fi access?
CREATE TABLE public_libraries (library_id INT,library_name TEXT,city TEXT,state TEXT,wi_fi_access BOOLEAN); INSERT INTO public_libraries (library_id,library_name,city,state,wi_fi_access) VALUES (1,'Seattle Central Library','Seattle','Washington',TRUE); INSERT INTO public_libraries (library_id,library_name,city,state,wi_fi_access) VALUES (2,'The Seattle Public Library - Ballard Branch','Seattle','Washington',TRUE); INSERT INTO public_libraries (library_id,library_name,city,state,wi_fi_access) VALUES (3,'The Seattle Public Library - Green Lake Branch','Seattle','Washington',FALSE);
SELECT COUNT(*) FROM public_libraries WHERE city = 'Seattle' AND state = 'Washington' AND wi_fi_access = TRUE;
What is the number of external threat intelligence sources, by category and country?
CREATE TABLE threat_intelligence (id INT,date DATE,source VARCHAR(20),category VARCHAR(20),country VARCHAR(20)); INSERT INTO threat_intelligence (id,date,source,category,country) VALUES (1,'2021-01-01','internal','malware','Russia'); INSERT INTO threat_intelligence (id,date,source,category,country) VALUES (2,'2021-01-02','external','phishing','China');
SELECT category, country, COUNT(*) as external_count FROM threat_intelligence WHERE source = 'external' GROUP BY category, country;
Calculate the average carbon offset for each green building project category, excluding projects with a budget over 5 million?
CREATE TABLE green_buildings (id INT,name VARCHAR(255),category VARCHAR(255),carbon_offsets FLOAT,budget FLOAT); INSERT INTO green_buildings (id,name,category,carbon_offsets,budget) VALUES (1,'Solar Tower 1','solar',500.0,4000000.0); INSERT INTO green_buildings (id,name,category,carbon_offsets,budget) VALUES (2,'Solar Tower 2','solar',800.0,3000000.0); INSERT INTO green_buildings (id,name,category,carbon_offsets,budget) VALUES (3,'Wind Farm 1','wind',1000.0,6000000.0);
SELECT category, AVG(carbon_offsets) AS avg_carbon_offsets FROM green_buildings WHERE budget <= 5000000 GROUP BY category;
List the destinations that had more visitors than the average number of visitors in 2019
CREATE TABLE tourism_stats (destination VARCHAR(255),year INT,visitors INT); INSERT INTO tourism_stats (destination,year,visitors) VALUES ('Japan',2019,15000000),('Canada',2019,23000000),('France',2019,24000000);
SELECT destination FROM tourism_stats WHERE visitors > (SELECT AVG(visitors) FROM tourism_stats WHERE year = 2019);
How many tickets were sold for the away games of the 'Bears' in the second half of the 2023 season?
CREATE TABLE TicketSales (TicketID INT,GameID INT,Team VARCHAR(20),SaleDate DATE,Quantity INT); INSERT INTO TicketSales (TicketID,GameID,Team,SaleDate,Quantity) VALUES (1,1,'Bears','2023-07-01',600);
SELECT SUM(Quantity) FROM TicketSales WHERE Team = 'Bears' AND SaleDate BETWEEN '2023-07-01' AND '2023-12-31' AND GameID NOT IN (SELECT GameID FROM Game WHERE HomeTeam = 'Bears');
Update all military technology records with a last inspection date within the last month.
CREATE TABLE MilitaryTech (TechID INT,TechName VARCHAR(50),LastInspection DATE); INSERT INTO MilitaryTech (TechID,TechName,LastInspection) VALUES (1,'Fighter Jet','2022-02-01'),(2,'Tank','2022-03-10'),(3,'Submarine','2022-04-15'),(4,'Radar System','2022-05-20'),(5,'Missile System','2022-06-25');
UPDATE MilitaryTech SET LastInspection = GETDATE() WHERE LastInspection >= DATEADD(month, -1, GETDATE());
What is the number of military equipment units manufactured each year by company?
CREATE TABLE military_equipment_manufacturing (equipment_type VARCHAR(255),year INT,unit_count INT,manufacturer VARCHAR(255)); INSERT INTO military_equipment_manufacturing (equipment_type,year,unit_count,manufacturer) VALUES ('Tank',2018,200,'General Dynamics'),('Tank',2019,250,'General Dynamics'),('Tank',2020,300,'General Dynamics'),('Aircraft',2018,500,'Lockheed Martin'),('Aircraft',2019,600,'Lockheed Martin'),('Aircraft',2020,700,'Lockheed Martin'),('Ship',2018,50,'Boeing'),('Ship',2019,60,'Boeing'),('Ship',2020,70,'Boeing'),('Helicopter',2018,150,'Bell Helicopter'),('Helicopter',2019,175,'Bell Helicopter'),('Helicopter',2020,200,'Bell Helicopter');
SELECT manufacturer, year, SUM(unit_count) FROM military_equipment_manufacturing GROUP BY manufacturer, year;
What are the names of the containers with a type of 'reefer' and their respective current location in the cargo table?
CREATE TABLE cargo (id INT PRIMARY KEY,container_id INT,location VARCHAR(255),container_type VARCHAR(255)); INSERT INTO cargo (id,container_id,location,container_type) VALUES (1,101,'Port A','reefer'),(2,102,'Port B','dry'),(3,103,'Port C','reefer');
SELECT c.container_id, c.location, c.container_type FROM cargo c JOIN shipping_container sc ON c.container_id = sc.id WHERE c.container_type = 'reefer';
What is the average ticket price for each event category?
CREATE TABLE Events (event_id INT,category VARCHAR(255),price DECIMAL(5,2)); INSERT INTO Events (event_id,category,price) VALUES (1,'Concert',50.99),(2,'Sports',30.50),(3,'Theater',75.00);
SELECT category, AVG(price) FROM Events GROUP BY category;
What is the total number of police interventions in the borough of Queens in the second half of 2021?
CREATE TABLE police_interventions (id INT,borough VARCHAR(20),year INT,half INT,interventions INT); INSERT INTO police_interventions (id,borough,year,half,interventions) VALUES (1,'Queens',2021,2,80); INSERT INTO police_interventions (id,borough,year,half,interventions) VALUES (2,'Queens',2021,2,85);
SELECT SUM(interventions) FROM police_interventions WHERE borough = 'Queens' AND year = 2021 AND half = 2;
What is the total energy production from renewable energy sources in Canada in 2020?
CREATE TABLE canada_energy_production (year INT,production_quantity INT); INSERT INTO canada_energy_production (year,production_quantity) VALUES (2015,50000),(2016,55000),(2017,60000),(2018,65000),(2019,70000),(2020,75000);
SELECT production_quantity FROM canada_energy_production WHERE year = 2020;
What is the total number of spacecraft launched by the European Space Agency?
CREATE TABLE Space_Agencies (ID INT,Agency VARCHAR(50),Country VARCHAR(50),Total_Spacecraft INT); INSERT INTO Space_Agencies (ID,Agency,Country,Total_Spacecraft) VALUES (1,'European Space Agency','Europe',50),(2,'National Aeronautics and Space Administration','USA',200),(3,'Roscosmos','Russia',150),(4,'China National Space Administration','China',100),(5,'Indian Space Research Organisation','India',75);
SELECT Total_Spacecraft FROM Space_Agencies WHERE Agency = 'European Space Agency';
What was the most popular hashtag in the past week, and how many posts used it?
CREATE TABLE hashtags (id INT,hashtag VARCHAR(255),post_id INT,PRIMARY KEY (id)); INSERT INTO hashtags (id,hashtag,post_id) VALUES (1,'#tech',5001),(2,'#food',3002),(3,'#travel',4003);
SELECT hashtag, COUNT(post_id) AS post_count FROM hashtags WHERE post_id IN (SELECT post_id FROM posts WHERE DATE(post_date) > DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK)) GROUP BY hashtag ORDER BY post_count DESC LIMIT 1;
List all IP addresses and their threat levels from the last month
CREATE TABLE threat_intel (ip_address VARCHAR(20),threat_level VARCHAR(20),last_seen DATE); INSERT INTO threat_intel (ip_address,threat_level,last_seen) VALUES ('192.168.1.1','low','2021-03-01'),('10.0.0.1','high','2021-02-10');
SELECT ip_address, threat_level FROM threat_intel WHERE last_seen >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);
What is the average energy consumption of industrial buildings in New York, grouped by zip code and building age?
CREATE TABLE industrial_buildings (id INT,zip_code VARCHAR(10),state VARCHAR(50),energy_consumption FLOAT,building_age INT); INSERT INTO industrial_buildings (id,zip_code,state,energy_consumption,building_age) VALUES (1,'10001','New York',5000,5); INSERT INTO industrial_buildings (id,zip_code,state,energy_consumption,building_age) VALUES (2,'10002','New York',5500,10);
SELECT zip_code, building_age, AVG(energy_consumption) AS avg_energy_consumption FROM industrial_buildings WHERE state = 'New York' GROUP BY zip_code, building_age;
Show the total number of deep-sea expeditions funded by each organization.
CREATE TABLE deep_sea_expeditions (expedition_name TEXT,funding_org TEXT); INSERT INTO deep_sea_expeditions (expedition_name,funding_org) VALUES ('Atlantis Expedition','National Oceanic and Atmospheric Administration'),('Triton Expedition','National Geographic'),('Poseidon Expedition','Woods Hole Oceanographic Institution');
SELECT funding_org, COUNT(*) FROM deep_sea_expeditions GROUP BY funding_org;
List the top 5 customers by spending on sustainable ingredients?
CREATE TABLE customers (customer_id INT,customer_name VARCHAR(255)); CREATE TABLE menu_items (menu_item_id INT,menu_category VARCHAR(255),item_name VARCHAR(255),is_sustainable BOOLEAN); CREATE TABLE orders (order_id INT,customer_id INT,menu_item_id INT,order_date DATE,order_price INT);
SELECT c.customer_name, SUM(o.order_price) as total_spend FROM customers c JOIN orders o ON c.customer_id = o.customer_id JOIN menu_items mi ON o.menu_item_id = mi.menu_item_id WHERE mi.is_sustainable = TRUE GROUP BY c.customer_name ORDER BY total_spend DESC LIMIT 5;
What is the total number of volunteer hours served in Q2 of 2022?
CREATE TABLE volunteers (id INT,name TEXT,country TEXT,hours_served INT);
SELECT SUM(hours_served) FROM volunteers WHERE QUARTER(volunteer_date) = 2 AND YEAR(volunteer_date) = 2022;
What is the average chemical waste produced per site, partitioned by country and ordered by the highest average?
CREATE TABLE chemical_sites (id INT,site_name VARCHAR(50),country VARCHAR(50),total_waste FLOAT); INSERT INTO chemical_sites (id,site_name,country,total_waste) VALUES (1,'Site A','USA',150.5),(2,'Site B','Canada',125.7),(3,'Site C','USA',200.3),(4,'Site D','Mexico',75.9);
SELECT country, AVG(total_waste) as avg_waste FROM chemical_sites GROUP BY country ORDER BY avg_waste DESC;
Add data to 'community_education' table
CREATE TABLE community_education (id INT,name VARCHAR(50),city VARCHAR(50),state VARCHAR(2),country VARCHAR(50));
INSERT INTO community_education (id, name, city, state, country) VALUES (1, 'GreenLife', 'San Juan', 'PR', 'Puerto Rico');
What is the average number of subway routes per region?
CREATE TABLE subway_routes (region VARCHAR(10),num_routes INT); INSERT INTO subway_routes (region,num_routes) VALUES ('north',12),('south',9),('east',8),('west',10),('central',15);
SELECT AVG(num_routes) FROM subway_routes;
Delete the records of ingredients that were sourced in China in 2021.
CREATE TABLE ingredients (ingredient_id INT,name TEXT,sourcing_country TEXT,source_date DATE); INSERT INTO ingredients (ingredient_id,name,sourcing_country,source_date) VALUES (1,'Water','China','2021-01-01'),(2,'Glycerin','France','2021-02-15'),(3,'Retinol','USA','2020-12-10');
DELETE FROM ingredients WHERE sourcing_country = 'China' AND source_date >= '2021-01-01' AND source_date <= '2021-12-31';
How many data breaches occurred in the retail sector in 2019 and 2020?
CREATE TABLE data_breaches (breach_id INT,sector TEXT,year INT); INSERT INTO data_breaches (breach_id,sector,year) VALUES (1,'Retail',2019),(2,'Retail',2020),(3,'Financial',2019),(4,'Financial',2020),(5,'Healthcare',2019);
SELECT sector, COUNT(*) FROM data_breaches WHERE sector = 'Retail' AND year IN (2019, 2020) GROUP BY sector;
List all the customers who have ordered dishes from multiple cuisines.
CREATE TABLE customers (id INT,name VARCHAR(255)); INSERT INTO customers (id,name) VALUES (1,'John Doe'),(2,'Jane Smith'); CREATE TABLE orders (id INT,customer_id INT,dish_id INT); INSERT INTO orders (id,customer_id,dish_id) VALUES (1,1,1),(2,1,2),(3,2,2),(4,2,3); CREATE TABLE dishes (id INT,name VARCHAR(255),cuisine VARCHAR(255)); INSERT INTO dishes (id,name,cuisine) VALUES (1,'Pizza Margherita','Italian'),(2,'Vegan Tacos','Mexican'),(3,'Chana Masala','Indian');
SELECT DISTINCT o1.customer_id FROM orders o1 INNER JOIN orders o2 ON o1.customer_id = o2.customer_id WHERE o1.dish_id != o2.dish_id;
What is the maximum salary for female employees in the IT department?
CREATE TABLE Employees (EmployeeID INT,Gender VARCHAR(10),Department VARCHAR(20),Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID,Gender,Department,Salary) VALUES (1,'Male','IT',70000.00),(2,'Female','IT',68000.00),(3,'Female','IT',72000.00);
SELECT MAX(Salary) FROM Employees WHERE Gender = 'Female' AND Department = 'IT';
Which policies were implemented in 'Delhi' or 'Mumbai' between 2018 and 2021?
CREATE TABLE City (id INT,name VARCHAR(50)); INSERT INTO City (id,name) VALUES (1,'New York'); INSERT INTO City (id,name) VALUES (2,'Los Angeles'); INSERT INTO City (id,name) VALUES (3,'Delhi'); INSERT INTO City (id,name) VALUES (4,'Mumbai'); INSERT INTO City (id,name) VALUES (5,'Tokyo'); CREATE TABLE Policy (id INT,name VARCHAR(50),city_id INT,category VARCHAR(50),budget DECIMAL(10,2),start_date DATE,end_date DATE); INSERT INTO Policy (id,name,city_id,category,budget,start_date,end_date) VALUES (1,'Education',3,'Education',1200000,'2021-01-01','2023-12-31'); INSERT INTO Policy (id,name,city_id,category,budget,start_date,end_date) VALUES (2,'Healthcare',3,'Healthcare',1500000,'2020-01-01','2022-12-31'); INSERT INTO Policy (id,name,city_id,category,budget,start_date,end_date) VALUES (3,'Transportation',4,'Transportation',2000000,'2019-01-01','2024-12-31'); INSERT INTO Policy (id,name,city_id,category,budget,start_date,end_date) VALUES (4,'Education',4,'Education',1800000,'2020-01-01','2023-12-31');
SELECT name, start_date FROM Policy JOIN City ON Policy.city_id = City.id WHERE City.name IN ('Delhi', 'Mumbai') AND YEAR(start_date) BETWEEN 2018 AND 2021;
What is the average budget allocated for public safety in the cities of Atlanta, Boston, and Denver for the years 2022 and 2023?
CREATE TABLE city_budgets (city varchar(50),year int,service varchar(50),budget int); INSERT INTO city_budgets (city,year,service,budget) VALUES ('Atlanta',2022,'Public Safety',15000000),('Atlanta',2023,'Public Safety',16000000),('Boston',2022,'Public Safety',20000000),('Boston',2023,'Public Safety',21000000),('Denver',2022,'Public Safety',12000000),('Denver',2023,'Public Safety',13000000);
SELECT AVG(budget) FROM city_budgets WHERE (city = 'Atlanta' OR city = 'Boston' OR city = 'Denver') AND service = 'Public Safety' AND (year = 2022 OR year = 2023);
What is the average CO2 emission of textile factories in Turkey, grouped by factory size and sorted in ascending order?
CREATE TABLE turkey_factories (factory_id INT,factory_name VARCHAR(50),factory_size INT,co2_emission INT); INSERT INTO turkey_factories VALUES (1,'Factory X',10,1200); INSERT INTO turkey_factories VALUES (2,'Factory Y',15,1500); INSERT INTO turkey_factories VALUES (3,'Factory Z',20,1800);
SELECT factory_size, AVG(co2_emission) as avg_emission FROM turkey_factories GROUP BY factory_size ORDER BY avg_emission ASC;
What is the total budget allocated for education and healthcare services in the city of Los Angeles?
CREATE TABLE cities (city_name VARCHAR(255),budget INT); INSERT INTO cities (city_name,budget) VALUES ('Los Angeles',1000000),('New York',2000000);
SELECT SUM(budget) FROM cities WHERE city_name IN ('Los Angeles') AND service IN ('education', 'healthcare');
How many disaster response teams are present in each country?
CREATE TABLE DisasterTeams (Country VARCHAR(20),TeamID INT); INSERT INTO DisasterTeams (Country,TeamID) VALUES ('Afghanistan',10),('Syria',15),('Iraq',20),('Jordan',25),('Lebanon',30);
SELECT Country, COUNT(TeamID) as NumTeams FROM DisasterTeams GROUP BY Country;
What is the minimum dissolved oxygen level recorded in the Mediterranean Sea?
CREATE TABLE dissolved_oxygen (location VARCHAR(255),level FLOAT,date DATE);
SELECT MIN(level) FROM dissolved_oxygen WHERE location = 'Mediterranean Sea';
What is the maximum labor cost for commercial construction projects in Miami, Florida in 2019?
CREATE TABLE labor_costs_2 (project_id INT,project_type VARCHAR(20),city VARCHAR(20),year INT,cost FLOAT); INSERT INTO labor_costs_2 (project_id,project_type,city,year,cost) VALUES (13,'Commercial','Miami',2019,250000),(14,'Residential','Miami',2020,180000),(15,'Commercial','Tampa',2018,220000);
SELECT MAX(cost) FROM labor_costs_2 WHERE project_type = 'Commercial' AND city = 'Miami' AND year = 2019;
What is the average age of attendees at events in the 'Theater' category that received funding from 'Corporate Sponsors'?
CREATE TABLE Events (EventID INT,EventName VARCHAR(20),EventCategory VARCHAR(20));CREATE TABLE FundingSources (FundingSourceID INT,FundingSourceName VARCHAR(20));CREATE TABLE EventFunding (EventID INT,FundingSourceID INT,FundingAmount INT);CREATE TABLE Attendees (AttendeeID INT,Age INT,EventID INT);
SELECT AVG(A.Age) AS Avg_Age FROM Events E INNER JOIN EventFunding EF ON E.EventID = EF.EventID INNER JOIN FundingSources FS ON EF.FundingSourceID = FS.FundingSourceID INNER JOIN Attendees A ON E.EventID = A.EventID WHERE E.EventCategory = 'Theater' AND FS.FundingSourceName = 'Corporate Sponsors';
List the top 5 customers by transaction count and total transaction value in H1 2021.
CREATE TABLE customers (customer_id INT,customer_name VARCHAR(255),city VARCHAR(255)); CREATE TABLE transactions (transaction_id INT,customer_id INT,transaction_date DATE,transaction_value DECIMAL(10,2)); INSERT INTO customers (customer_id,customer_name,city) VALUES (1,'John Doe','New York'),(2,'Jane Smith','Los Angeles'),(3,'Bob Johnson','Chicago'); INSERT INTO transactions (transaction_id,customer_id,transaction_date,transaction_value) VALUES (1,1,'2021-01-01',100.00),(2,1,'2021-01-05',200.00),(3,2,'2021-01-03',50.00);
SELECT c.customer_name, COUNT(t.transaction_id) as transaction_count, SUM(t.transaction_value) as total_transaction_value FROM customers c INNER JOIN transactions t ON c.customer_id = t.customer_id WHERE t.transaction_date BETWEEN '2021-01-01' AND '2021-06-30' GROUP BY c.customer_name ORDER BY transaction_count DESC, total_transaction_value DESC LIMIT 5;
List all sports in the sports_teams table along with the number of players in each sport.
CREATE TABLE sports_teams (team_id INT,team_name VARCHAR(50),sport VARCHAR(20),city VARCHAR(20),division VARCHAR(20)); CREATE TABLE athletes (athlete_id INT,name VARCHAR(50),team_id INT,position VARCHAR(20),age INT);
SELECT s.sport, COUNT(a.athlete_id) as num_players FROM sports_teams s JOIN athletes a ON s.team_id = a.team_id GROUP BY s.sport;
Calculate the average CO2 emissions of electric vehicles in California.
CREATE TABLE ev (ev_id INT,make TEXT,model TEXT,year INT,CO2_emissions FLOAT);
SELECT AVG(CO2_emissions) FROM ev WHERE make IS NOT NULL AND model IS NOT NULL AND year IS NOT NULL AND state = 'California';
What is the average daily water consumption per capita in India for the past 6 months?
CREATE TABLE water_consumption (country VARCHAR(255),consumption FLOAT,date DATE); INSERT INTO water_consumption (country,consumption,date) VALUES ('India',15,'2022-01-01'); INSERT INTO water_consumption (country,consumption,date) VALUES ('India',16,'2022-01-02');
SELECT AVG(consumption) FROM (SELECT consumption, DATE_TRUNC('day', date) AS day FROM water_consumption WHERE country = 'India' AND date >= '2021-07-01' AND date < '2022-01-01' GROUP BY day, consumption ORDER BY day) subquery;
What is the average property price for co-owned properties in Seattle?
CREATE TABLE Properties (PropertyID int,Price int,City varchar(20),OwnershipType varchar(20)); INSERT INTO Properties (PropertyID,Price,City,OwnershipType) VALUES (1,500000,'Seattle','Co-Owned'); INSERT INTO Properties (PropertyID,Price,City,OwnershipType) VALUES (2,700000,'Portland','Individual');
SELECT AVG(Price) FROM Properties WHERE City = 'Seattle' AND OwnershipType = 'Co-Owned';
Which cities in NY have donated?
CREATE TABLE donations (id INT PRIMARY KEY,donor_id INT,city VARCHAR(50),state VARCHAR(50),amount DECIMAL(10,2)); INSERT INTO donations (id,donor_id,city,state,amount) VALUES (1,1,'Albany','NY',50.00);
SELECT donations.city, donors.name FROM donors INNER JOIN donations ON donors.id = donations.donor_id WHERE donations.state = 'NY';
What is the minimum rating for movies released in India?
CREATE TABLE movies (id INT,title VARCHAR(100),genre VARCHAR(50),release_year INT,rating DECIMAL(3,2),country VARCHAR(50)); INSERT INTO movies (id,title,genre,release_year,rating,country) VALUES (1,'Movie1','Comedy',2020,8.2,'India'); INSERT INTO movies (id,title,genre,release_year,rating,country) VALUES (2,'Movie2','Drama',2019,7.5,'India'); INSERT INTO movies (id,title,genre,release_year,rating,country) VALUES (3,'Movie3','Action',2021,6.8,'India');
SELECT MIN(rating) FROM movies WHERE country = 'India';
What was the total count of building permits issued for multi-family residential buildings taller than 10 floors in Toronto between 2010 and 2019?
CREATE TABLE Building_Permits (Permit_ID INT,Building_Type VARCHAR(50),Floors INT,Issue_Date DATE,Location VARCHAR(50));
SELECT COUNT(Permit_ID) FROM Building_Permits WHERE Building_Type = 'Residential' AND Floors > 10 AND Location = 'Toronto' AND Issue_Date BETWEEN '2010-01-01' AND '2019-12-31';
Find the earliest and latest creation dates for artworks by each artist.
CREATE TABLE Art (id INT,title VARCHAR(255),artist_id INT,creation_date DATE); CREATE TABLE Artist (id INT,name VARCHAR(255));
SELECT Artist.name, MIN(Art.creation_date) AS earliest_date, MAX(Art.creation_date) AS latest_date FROM Artist JOIN Art ON Artist.id = Art.artist_id GROUP BY Artist.name;
What is the average energy demand and the corresponding energy source for locations with a demand greater than 7000 in the energy_demand and renewable_generation tables?
CREATE TABLE renewable_generation (id INT,source VARCHAR(255),capacity FLOAT,location VARCHAR(255)); CREATE TABLE energy_demand (id INT,location VARCHAR(255),demand FLOAT,timestamp DATETIME); INSERT INTO renewable_generation (id,source,capacity,location) VALUES (1,'Wind',5000.0,'NY'),(2,'Solar',7000.0,'FL'); INSERT INTO energy_demand (id,location,demand,timestamp) VALUES (1,'NY',8000.0,'2022-01-01 10:00:00'),(2,'FL',6000.0,'2022-01-01 10:00:00');
SELECT e.location, r.source, AVG(e.demand) as avg_demand FROM renewable_generation r RIGHT JOIN energy_demand e ON r.location = e.location WHERE e.demand > 7000.0 GROUP BY e.location, r.source;
How many unique attendees have visited each cultural organization, and what is the total amount they have spent?
CREATE TABLE CulturalOrgs (org_id INT,org_name VARCHAR(50)); CREATE TABLE Visits (org_id INT,attendee_id INT,visit_date DATE,amount INT);
SELECT org_name, COUNT(DISTINCT attendee_id) AS unique_attendees, SUM(amount) AS total_spent FROM Visits v JOIN CulturalOrgs o ON v.org_id = o.org_id GROUP BY org_name;
List all spacecraft that have been used in missions to Jupiter's moons.
CREATE TABLE Spacecraft (SpacecraftID INT,Name VARCHAR(50),Manufacturer VARCHAR(50),LaunchDate DATE); CREATE TABLE SpaceMissions (MissionID INT,SpacecraftID INT,Destination VARCHAR(50)); INSERT INTO Spacecraft VALUES (1,'Juno','NASA','2011-08-05'); INSERT INTO SpaceMissions VALUES (1,1,'Jupiter');
SELECT Spacecraft.Name FROM Spacecraft INNER JOIN SpaceMissions ON Spacecraft.SpacecraftID = SpaceMissions.SpacecraftID WHERE SpaceMissions.Destination LIKE '%Jupiter%' AND SpaceMissions.Destination LIKE '%moons%';
Insert new circular economy initiatives in 'Asia' with the given details.
CREATE TABLE asia_initiatives (region VARCHAR(50),initiative_name VARCHAR(50),budget NUMERIC(10,2),start_date DATE); INSERT INTO asia_initiatives (region,initiative_name,budget,start_date) VALUES (NULL,NULL,NULL,NULL);
INSERT INTO asia_initiatives (region, initiative_name, budget, start_date) VALUES ('Asia', 'E-Waste Recycling', 600000, '2021-04-01'), ('Asia', 'Smart Cities', 900000, '2021-10-01');
Identify unique cybersecurity strategies implemented by countries with a high military technology budget
CREATE TABLE CybersecurityStrategies (Id INT PRIMARY KEY,Country VARCHAR(50),Name VARCHAR(50),Budget INT);
SELECT DISTINCT Name FROM CybersecurityStrategies WHERE Country IN (SELECT Country FROM MilitaryBudget WHERE Budget > 1000000) GROUP BY Country;
How many students with mobility impairments are enrolled in each program in the Southeast?
CREATE TABLE Students (ID INT,Name VARCHAR(50),Disability VARCHAR(50),Program VARCHAR(50),Region VARCHAR(50)); INSERT INTO Students (ID,Name,Disability,Program,Region) VALUES (1,'Jane Doe','Mobility Impairment','Wheelchair Tennis','Southeast'),(2,'John Doe','Learning Disability','Wheelchair Tennis','Southeast'),(3,'Jim Smith','Mobility Impairment','Adapted Yoga','Southeast');
SELECT Program, COUNT(*) FROM Students WHERE Disability = 'Mobility Impairment' GROUP BY Program;
Add new records to hotel_reviews_table with random ratings for hotel_id 1004 and 1005
CREATE TABLE hotel_reviews (id INT,hotel_id INT,guest_name VARCHAR(50),rating INT,review_date DATE);
INSERT INTO hotel_reviews (id, hotel_id, guest_name, rating, review_date) VALUES (1, 1004, 'John Doe', FLOOR(1 + RAND() * 5), CURDATE()), (2, 1005, 'Jane Smith', FLOOR(1 + RAND() * 5), CURDATE());
What is the total funding amount for projects in the 'Education' sector?
CREATE TABLE projects (id INT,sector TEXT,total_funding DECIMAL); INSERT INTO projects (id,sector,total_funding) VALUES (1,'Health',10000.00),(2,'Education',15000.00),(3,'Agriculture',20000.00);
SELECT SUM(total_funding) FROM projects WHERE sector = 'Education';
Delete all records from the "articles" table where the "publish_date" is before 2020-01-01
CREATE TABLE articles (id INT,title TEXT,author TEXT,publish_date DATE);
DELETE FROM articles WHERE publish_date < '2020-01-01';
How many students have participated in lifelong learning programs in each country?
CREATE TABLE student (student_id INT,student_name VARCHAR(50),country VARCHAR(50)); CREATE TABLE lifelong_learning (student_id INT,program_name VARCHAR(50)); INSERT INTO student (student_id,student_name,country) VALUES (1,'Alex Johnson','USA'),(2,'Pedro Martinez','Mexico'),(3,'Sophia Lee','Canada'),(4,'Lucas Nguyen','Vietnam'); INSERT INTO lifelong_learning (student_id,program_name) VALUES (1,'Adult Education'),(2,'English as a Second Language'),(3,'Coding Bootcamp'),(4,'Online Degree Program');
SELECT country, COUNT(DISTINCT student_id) as num_students FROM student INNER JOIN lifelong_learning ON student.student_id = lifelong_learning.student_id GROUP BY country;
Find the total number of streams for all hip-hop songs on the platform, excluding any streams from the United States.
CREATE TABLE artists (id INT,name VARCHAR(255),genre VARCHAR(255)); CREATE TABLE streams (id INT,song_id INT,user_id INT,location VARCHAR(255),timestamp TIMESTAMP); INSERT INTO artists (id,name,genre) VALUES (1,'Eminem','Hip-Hop'),(2,'Dr. Dre','Hip-Hop'); INSERT INTO streams (id,song_id,user_id,location,timestamp) VALUES (1,1,1,'USA',NOW()),(2,1,2,'Canada',NOW()); CREATE VIEW hip_hop_songs AS SELECT song_id FROM artists WHERE genre = 'Hip-Hop';
SELECT COUNT(*) FROM streams WHERE song_id IN (SELECT song_id FROM hip_hop_songs) AND location != 'USA';
Find the total water usage in cubic meters for the year 2020
CREATE TABLE water_usage (id INT PRIMARY KEY,year INT,location VARCHAR(50),usage FLOAT); INSERT INTO water_usage (id,year,location,usage) VALUES (1,2018,'New York',1234.56),(2,2019,'New York',1567.89),(3,2020,'New York',1890.12),(4,2018,'Los Angeles',2234.56),(5,2019,'Los Angeles',2567.89),(6,2020,'Los Angeles',2890.12);
SELECT SUM(usage) FROM water_usage WHERE year = 2020;
Which African countries have the highest number of eco-tourists?
CREATE TABLE africa_eco_tourists (country VARCHAR(50),eco_tourists INT); INSERT INTO africa_eco_tourists (country,eco_tourists) VALUES ('South Africa',400000),('Tanzania',350000),('Kenya',450000),('Namibia',250000),('Botswana',300000); CREATE TABLE africa_countries (country VARCHAR(50)); INSERT INTO africa_countries (country) VALUES ('South Africa'),('Tanzania'),('Kenya'),('Namibia'),('Botswana'),('Egypt');
SELECT country FROM africa_eco_tourists WHERE eco_tourists IN (SELECT MAX(eco_tourists) FROM africa_eco_tourists) INTERSECT SELECT country FROM africa_countries;
What is the total transaction amount for each day in March 2022, sorted by transaction date in ascending order?
CREATE TABLE transactions (transaction_id INT,transaction_date DATE,amount DECIMAL(10,2)); INSERT INTO transactions (transaction_id,transaction_date,amount) VALUES (1,'2022-03-01',100.50),(2,'2022-03-02',200.75),(3,'2022-03-03',50.00);
SELECT transaction_date, SUM(amount) as daily_total FROM transactions WHERE transaction_date >= '2022-03-01' AND transaction_date < '2022-04-01' GROUP BY transaction_date ORDER BY transaction_date ASC;
What is the maximum number of crimes reported in 'Hillside' in the last 3 months?
CREATE TABLE crimes (id INT,area VARCHAR(20),reported_crimes INT,month INT);
SELECT MAX(reported_crimes) FROM crimes WHERE area = 'Hillside' AND month BETWEEN MONTH(CURRENT_DATE) - 3 AND MONTH(CURRENT_DATE);
What is the total carbon sequestration for 2021?
CREATE TABLE carbon_sequestration (id INT,year INT,amount FLOAT); INSERT INTO carbon_sequestration (id,year,amount) VALUES (1,2020,500.3),(2,2021,700.5),(3,2022,800.2);
SELECT SUM(amount) FROM carbon_sequestration WHERE year = 2021;
How many 'Action' genre movies were released between 2018 and 2020?
CREATE TABLE movies (id INT,title VARCHAR(100),genre VARCHAR(50),release_year INT); INSERT INTO movies (id,title,genre,release_year) VALUES (1,'Movie1','Action',2018); INSERT INTO movies (id,title,genre,release_year) VALUES (2,'Movie2','Action',2019); INSERT INTO movies (id,title,genre,release_year) VALUES (3,'Movie3','Action',2020);
SELECT COUNT(*) FROM movies WHERE genre = 'Action' AND release_year BETWEEN 2018 AND 2020;
Which artists have released songs in the pop genre since 2010?
CREATE TABLE artists (artist_id INT,artist_name VARCHAR(255),genre VARCHAR(255)); CREATE TABLE songs (song_id INT,song_name VARCHAR(255),release_year INT,artist_id INT); INSERT INTO artists (artist_id,artist_name,genre) VALUES (1,'Taylor Swift','Pop'); INSERT INTO songs (song_id,song_name,release_year,artist_id) VALUES (1,'Shake it Off',2014,1);
SELECT artists.artist_name FROM artists JOIN songs ON artists.artist_id = songs.artist_id WHERE artists.genre = 'Pop' AND songs.release_year >= 2010;
Update the rating of the product 'Shirt' in the 'Eco' category to 4.8.
CREATE TABLE products (product_id INT,name TEXT,rating FLOAT,category TEXT); INSERT INTO products (product_id,name,rating,category) VALUES (1,'Shirt',4.5,'Eco'); INSERT INTO products (product_id,name,rating,category) VALUES (2,'Pants',4.7,'Eco'); INSERT INTO products (product_id,name,rating,category) VALUES (3,'Jacket',4.3,'Eco');
UPDATE products SET rating = 4.8 WHERE name = 'Shirt' AND category = 'Eco';
What is the total amount donated by each donor in 2021, grouped by donor name?
CREATE TABLE Donors (DonorID int,DonorName varchar(50),DonationDate date,DonationAmount int); INSERT INTO Donors (DonorID,DonorName,DonationDate,DonationAmount) VALUES (1,'John Doe','2021-01-01',500),(2,'Jane Smith','2021-02-10',300),(1,'John Doe','2021-12-25',700);
SELECT DonorName, SUM(DonationAmount) as TotalDonation FROM Donors WHERE YEAR(DonationDate) = 2021 GROUP BY DonorName;
What is the total capacity of vessels in a specific country?
CREATE TABLE vessels (id INT,name VARCHAR(255),country VARCHAR(255),capacity INT); INSERT INTO vessels (id,name,country,capacity) VALUES (1,'Vessel A','USA',5000),(2,'Vessel B','USA',6000),(3,'Vessel C','Canada',4000);
SELECT SUM(capacity) as total_capacity FROM vessels WHERE country = 'USA';
What is the average distance between rural health clinics and the nearest pharmacy?
CREATE TABLE clinics (id INT,location VARCHAR(20),latitude FLOAT,longitude FLOAT); CREATE TABLE pharmacies (id INT,location VARCHAR(20),latitude FLOAT,longitude FLOAT);
SELECT AVG(ST_Distance(clinics.geom, pharmacies.geom)) FROM clinics, pharmacies WHERE ST_DWithin(clinics.geom, pharmacies.geom, 50000);
Which movies and TV shows have the same production company?
CREATE TABLE movie (id INT,title VARCHAR(100),production_company VARCHAR(50)); CREATE TABLE tv_show (id INT,title VARCHAR(100),production_company VARCHAR(50)); INSERT INTO movie (id,title,production_company) VALUES (1,'Movie1','ProductionCompany1'); INSERT INTO movie (id,title,production_company) VALUES (2,'Movie2','ProductionCompany2'); INSERT INTO tv_show (id,title,production_company) VALUES (1,'TVShow1','ProductionCompany1');
SELECT movie.title, tv_show.title FROM movie INNER JOIN tv_show ON movie.production_company = tv_show.production_company;
What is the minimum R&D expenditure for trials in 'CountryF' in 2021?
CREATE TABLE rd_expenditure(trial_id TEXT,country TEXT,year INT,amount FLOAT); INSERT INTO rd_expenditure (trial_id,country,year,amount) VALUES ('Trial1','CountryX',2021,2500000),('Trial2','CountryY',2020,3000000),('Trial3','CountryF',2021,2000000),('Trial4','CountryF',2021,2200000);
SELECT MIN(amount) FROM rd_expenditure WHERE country = 'CountryF' AND year = 2021;
What is the average sustainable tourism score for each region?
CREATE TABLE destinations (destination TEXT,region TEXT,sustainability_score FLOAT); INSERT INTO destinations (destination,region,sustainability_score) VALUES ('Bali','Asia Pacific',4.7),('Paris','Europe',4.5),('New York','North America',4.3);
SELECT region, AVG(sustainability_score) OVER (PARTITION BY region) AS avg_sustainability_score FROM destinations;
What is the maximum funding amount for Indian biotech startups?
CREATE TABLE biotech_startups (id INT,name VARCHAR(100),location VARCHAR(100),funding FLOAT); INSERT INTO biotech_startups (id,name,location,funding) VALUES (1,'Startup A','India',12000000); INSERT INTO biotech_startups (id,name,location,funding) VALUES (2,'Startup B','India',18000000); INSERT INTO biotech_startups (id,name,location,funding) VALUES (3,'Startup C','India',20000000);
SELECT MAX(funding) FROM biotech_startups WHERE location = 'India';
List the names of sustainable tour operators in Europe that offer tours in Paris or Rome.
CREATE TABLE tour_operators (operator_id INT,name VARCHAR,location VARCHAR,sustainable_practices BOOLEAN); CREATE VIEW european_tour_operators AS SELECT * FROM tour_operators WHERE location LIKE '%%Europe%%'; CREATE VIEW paris_rome_tours AS SELECT * FROM tours WHERE location IN ('Paris','Rome');
SELECT name FROM european_tour_operators WHERE sustainable_practices = TRUE AND operator_id IN (SELECT operator_id FROM paris_rome_tours);
Which artists have released songs in both the rock and pop genres?
CREATE TABLE song_releases (song_id INT,artist_name VARCHAR(50),genre VARCHAR(20));
SELECT artist_name FROM song_releases WHERE genre IN ('rock', 'pop') GROUP BY artist_name HAVING COUNT(DISTINCT genre) = 2;
What is the total quantity of fish farmed in each country by species in January?
CREATE TABLE CountryFishSpecies (Country varchar(50),SpeciesID int,SpeciesName varchar(50),Quantity int); INSERT INTO CountryFishSpecies (Country,SpeciesID,SpeciesName,Quantity) VALUES ('Canada',1,'Salmon',5000),('Canada',2,'Tuna',6000),('USA',1,'Salmon',7000);
SELECT Country, SpeciesName, SUM(Quantity) as TotalQuantity FROM CountryFishSpecies WHERE MONTH(Date) = 1 GROUP BY Country, SpeciesName;
What was the average ticket price for each team in the eastern conference?
CREATE TABLE teams (team_id INT,team_name VARCHAR(50),conference VARCHAR(50));CREATE TABLE tickets (ticket_id INT,team_id INT,price DECIMAL(5,2)); INSERT INTO teams VALUES (1,'TeamA','Eastern'),(2,'TeamB','Eastern'),(3,'TeamC','Western'); INSERT INTO tickets VALUES (1,1,100.50),(2,1,110.00),(3,2,95.00),(4,2,92.50),(5,3,120.00);
SELECT t.conference, AVG(t.price) as avg_price FROM tickets t JOIN teams te ON t.team_id = te.team_id WHERE te.conference = 'Eastern' GROUP BY t.conference;
What is the average mental health score for community health workers by race, ordered by the highest average score?
CREATE TABLE community_health_workers (worker_id INT,worker_name TEXT,race TEXT,mental_health_score INT); INSERT INTO community_health_workers (worker_id,worker_name,race,mental_health_score) VALUES (1,'John Doe','White',75),(2,'Jane Smith','Black',80),(3,'Alice Johnson','Asian',85),(4,'Bob Brown','Hispanic',70);
SELECT race, AVG(mental_health_score) as avg_score FROM community_health_workers GROUP BY race ORDER BY avg_score DESC;
What is the percentage of students who have not shown any improvement in their mental health scores in the past year?
CREATE TABLE students (student_id INT,mental_health_score INT,improvement_1year INT); INSERT INTO students (student_id,mental_health_score,improvement_1year) VALUES (1,60,0),(2,70,0),(3,50,5),(4,80,-3),(5,40,10);
SELECT (COUNT(student_id) / (SELECT COUNT(student_id) FROM students)) * 100 AS percentage FROM students WHERE improvement_1year = 0;
What are the names of all agricultural innovation projects in the 'rural_projects' table, excluding those with a budget over 50000?
CREATE TABLE rural_projects (id INT,project_name VARCHAR(50),budget INT); INSERT INTO rural_projects (id,project_name,budget) VALUES (1,'Drip Irrigation',40000),(2,'Solar Powered Pumps',70000),(3,'Organic Fertilizers',30000);
SELECT project_name FROM rural_projects WHERE budget <= 50000;
Find the number of wells drilled in Texas and their total cost
CREATE TABLE wells (id INT,state VARCHAR(2),cost FLOAT); INSERT INTO wells (id,state,cost) VALUES (1,'TX',500000.0),(2,'TX',600000.0),(3,'OK',400000.0);
SELECT COUNT(*) as num_wells, SUM(cost) as total_cost FROM wells WHERE state = 'TX';
How many HIV tests were conducted in Kenya in the last year?
CREATE TABLE hiv_tests (id INT,test_date DATE,location TEXT); INSERT INTO hiv_tests (id,test_date,location) VALUES (1,'2021-12-31','Kenya'); INSERT INTO hiv_tests (id,test_date,location) VALUES (2,'2022-02-05','Kenya');
SELECT COUNT(*) FROM hiv_tests WHERE location = 'Kenya' AND test_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR);
What is the total revenue generated by heritage hotels in India and Mexico?
CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,country TEXT); INSERT INTO hotels (hotel_id,hotel_name,country) VALUES (1,'Heritage Hotel Delhi','India'),(2,'Eco Hotel Cancun','Mexico'),(3,'Cultural Hotel Rome','Italy'); CREATE TABLE bookings (booking_id INT,hotel_id INT,revenue INT); INSERT INTO bookings (booking_id,hotel_id,revenue) VALUES (1,1,500),(2,1,600),(3,2,400);
SELECT SUM(bookings.revenue) FROM bookings INNER JOIN hotels ON bookings.hotel_id = hotels.hotel_id WHERE hotels.country IN ('India', 'Mexico') AND hotels.hotel_name LIKE '%heritage%';
What is the average donation amount for individual donors from India?
CREATE TABLE Donors (DonorID INT,DonorName TEXT,DonorType TEXT,Country TEXT); INSERT INTO Donors (DonorID,DonorName,DonorType,Country) VALUES (1,'Ramesh Kumar','Individual','India'),(2,'Kiran Reddy','Individual','India'); CREATE TABLE Donations (DonationID INT,DonorID INT,DonationAmount INT); INSERT INTO Donations (DonationID,DonorID,DonationAmount) VALUES (1,1,500),(2,1,750),(3,2,1000);
SELECT AVG(DonationAmount) FROM Donations JOIN Donors ON Donations.DonorID = Donors.DonorID WHERE Donors.Country = 'India' AND Donors.DonorType = 'Individual';
Delete all records from the 'market_trends' table where the 'price' is less than 30
CREATE TABLE market_trends (id INT,country VARCHAR(50),year INT,price FLOAT); INSERT INTO market_trends (id,country,year,price) VALUES (1,'Mexico',2018,35.56); INSERT INTO market_trends (id,country,year,price) VALUES (2,'Colombia',2017,28.43);
DELETE FROM market_trends WHERE price < 30;
What is the total amount of humanitarian assistance provided by each organization in the last 3 years?
CREATE TABLE HumanitarianAssistance (Organization VARCHAR(50),Year INT,Amount DECIMAL(10,2)); INSERT INTO HumanitarianAssistance (Organization,Year,Amount) VALUES ('UNHCR',2019,500000),('WFP',2020,700000),('Red Cross',2019,600000),('CARE',2020,800000),('Oxfam',2021,900000),('UNHCR',2020,600000),('WFP',2021,800000),('Red Cross',2020,700000),('CARE',2021,900000),('Oxfam',2019,800000);
SELECT Organization, SUM(Amount) AS TotalAssistance FROM HumanitarianAssistance WHERE Year >= 2019 GROUP BY Organization;
What is the total number of organic products sourced from local farms?
CREATE TABLE sourcing (id INT,product TEXT,origin TEXT,organic BOOLEAN,local BOOLEAN); INSERT INTO sourcing (id,product,origin,organic,local) VALUES (1,'Carrots','local',true,true),(2,'Quinoa','imported',true,false),(3,'Chicken','local',false,true),(4,'Olive Oil','imported',true,false);
SELECT COUNT(*) FROM sourcing WHERE organic = true AND local = true;