instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
List all astronauts who have been on the ISS and their total number of days in space.
CREATE TABLE Astronauts (astronaut_name TEXT,mission_name TEXT,days_in_space INT); INSERT INTO Astronauts (astronaut_name,mission_name,days_in_space) VALUES ('Serena Auñón-Chancellor','ISS Expedition 56/57',197),('Alexander Gerst','ISS Expedition 40/41',165),('Reid Wiseman','ISS Expedition 40/41',165),('Max Surayev','ISS Expedition 21/22',169),('Jeff Williams','ISS Expedition 13/14,21/22,47/48,51/52',534);
SELECT astronaut_name, SUM(days_in_space) as total_days_in_space FROM Astronauts WHERE mission_name LIKE '%ISS%' GROUP BY astronaut_name;
Find the number of TV shows produced in each country and the percentage of total shows.
CREATE TABLE tv_show (id INT,title VARCHAR(100),production_country VARCHAR(50)); INSERT INTO tv_show (id,title,production_country) VALUES (1,'Breaking Bad','United States');
SELECT production_country, COUNT(*), 100.0 * COUNT(*) / (SELECT COUNT(*) FROM tv_show) AS percentage FROM tv_show GROUP BY production_country;
List all smart city initiatives in the state of California, along with their start dates.
CREATE TABLE smart_city_initiatives (id INT,initiative_name VARCHAR(50),state VARCHAR(50),start_date DATE); INSERT INTO smart_city_initiatives (id,initiative_name,state,start_date) VALUES (1,'California Smart Grid','California','2015-01-01');
SELECT initiative_name, start_date FROM smart_city_initiatives WHERE state = 'California';
Find the number of users who have rated movies or watched shows in each month of 2019.
CREATE TABLE user_ratings (user_id INT,movie_title VARCHAR(50),rating INT,rating_date DATE); CREATE TABLE show_views (user_id INT,show_name VARCHAR(50),views_date DATE);
SELECT MONTH(rating_date) AS month, COUNT(DISTINCT user_id) FROM user_ratings WHERE YEAR(rating_date) = 2019 GROUP BY month UNION SELECT MONTH(views_date) AS month, COUNT(DISTINCT user_id) FROM show_views WHERE YEAR(views_date) = 2019 GROUP BY month ORDER BY month;
What is the minimum price of natural cosmetics sold in Germany?
CREATE TABLE products (product_id INT,name TEXT,is_natural BOOLEAN,price DECIMAL,country TEXT); INSERT INTO products (product_id,name,is_natural,price,country) VALUES (1,'Lipstick',TRUE,10.99,'Germany'); INSERT INTO products (product_id,name,is_natural,price,country) VALUES (2,'Eye Shadow',TRUE,8.49,'Germany');
SELECT MIN(price) FROM products WHERE is_natural = TRUE AND country = 'Germany';
Calculate the percentage of total carbon emissions by each mine.
CREATE TABLE mine_carbon_emissions (mine_id INT,total_carbon_emissions FLOAT); INSERT INTO mine_carbon_emissions (mine_id,total_carbon_emissions) VALUES (1,5000),(2,4500),(3,4000),(4,3500),(5,3000);
SELECT mine_id, total_carbon_emissions, total_carbon_emissions * 100.0 / SUM(total_carbon_emissions) OVER () as carbon_emissions_percentage FROM mine_carbon_emissions;
Who are the top 3 countries with the highest number of military innovation projects in the last decade?
CREATE TABLE military_innovation (innovation_id INT,innovation_name TEXT,innovation_description TEXT,country TEXT,start_date DATE,end_date DATE); INSERT INTO military_innovation (innovation_id,innovation_name,innovation_description,country,start_date,end_date) VALUES (1,'Stealth Technology','Invisible aircraft technology','USA','2010-01-01','2015-12-31'),(2,'Artificial Intelligence','AI-driven drones','China','2016-01-01','2021-12-31'),(3,'Cyber Warfare','Offensive and defensive cyber operations','Russia','2012-01-01','2021-12-31');
SELECT military_innovation.country, COUNT(military_innovation.innovation_id) as innovation_count FROM military_innovation WHERE military_innovation.start_date >= DATE_SUB(CURDATE(), INTERVAL 10 YEAR) GROUP BY military_innovation.country ORDER BY innovation_count DESC LIMIT 3;
What is the average number of online travel agency bookings per day for hotels in Tokyo, Japan?
CREATE TABLE online_travel_agencies (id INT,hotel_id INT,revenue INT,booking_date DATE); CREATE TABLE hotels (id INT,name TEXT,city TEXT,country TEXT);
SELECT AVG(1.0 * COUNT(*)) FROM online_travel_agencies ota INNER JOIN hotels h ON ota.hotel_id = h.id WHERE h.city = 'Tokyo' AND h.country = 'Japan' GROUP BY booking_date;
How many unique strains were sold in total in the state of Nevada in 2022?
CREATE TABLE sales (id INT,state VARCHAR(50),year INT,strain VARCHAR(50));
SELECT COUNT(DISTINCT strain) FROM sales WHERE state = 'Nevada' AND year = 2022;
What is the average fare per trip segment for the bottom 5 least frequently traveled segments?
CREATE TABLE trip_segments (segment_id INT,route_id INT,fare DECIMAL(5,2),passenger_count INT); INSERT INTO trip_segments (segment_id,route_id,fare,passenger_count) VALUES (1,101,2.50,1000),(2,101,2.00,1200),(3,102,3.00,800),(4,103,1.50,1500),(5,104,4.00,600),(6,105,1.75,500),(7,106,2.25,700);
SELECT AVG(fare) FROM (SELECT fare, ROW_NUMBER() OVER (ORDER BY passenger_count ASC) rn FROM trip_segments) t WHERE rn <= 5;
What is the number of community development initiatives in Peru that were not completed in 2018?
CREATE TABLE community_development (id INT,country VARCHAR(50),year INT,initiative VARCHAR(50),completed BOOLEAN); INSERT INTO community_development (id,country,year,initiative,completed) VALUES (1,'Peru',2018,'Education',FALSE);
SELECT COUNT(*) FROM community_development WHERE country = 'Peru' AND year = 2018 AND completed = FALSE;
What is the average price of sustainable textiles sourced from India?
CREATE TABLE TextileSources (source_id INT,source_country VARCHAR(20),sustainability_rating INT,price DECIMAL(5,2)); INSERT INTO TextileSources VALUES (1,'India',5,12.50),(2,'Bangladesh',3,8.00),(3,'China',2,6.25);
SELECT AVG(price) FROM TextileSources WHERE source_country = 'India' AND sustainability_rating >= 4;
What is the average rating of hotels in Canada that have not adopted AI technology?
CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,city TEXT,rating FLOAT,ai_adoption BOOLEAN); INSERT INTO hotels (hotel_id,hotel_name,city,rating,ai_adoption) VALUES (1,'Hotel A','Toronto',4.5,false),(2,'Hotel B','Montreal',4.2,true);
SELECT AVG(rating) FROM hotels WHERE city = 'Toronto' AND ai_adoption = false;
What is the average value of military equipment sales by region in 2020?
CREATE TABLE military_sales (id INT,year INT,region VARCHAR(50),value FLOAT); INSERT INTO military_sales (id,year,region,value) VALUES (1,2020,'North America',5000000),(2,2020,'Europe',6000000),(3,2020,'Asia',7000000),(4,2020,'Africa',4000000),(5,2020,'South America',3000000);
SELECT region, AVG(value) FROM military_sales WHERE year = 2020 GROUP BY region;
How many Shariah-compliant finance accounts were opened in each quarter of 2021?
CREATE TABLE shariah_compliant_finance (account_number INT,open_date DATE); INSERT INTO shariah_compliant_finance (account_number,open_date) VALUES (1,'2021-01-01'),(2,'2021-04-01'),(3,'2021-07-01'),(4,'2021-10-01');
SELECT DATE_FORMAT(open_date, '%Y-%m') AS quarter, COUNT(*) FROM shariah_compliant_finance WHERE YEAR(open_date) = 2021 GROUP BY quarter;
Which cybersecurity strategies were implemented right after the ones introduced by the European Union?
CREATE TABLE cybersecurity_strategies (id INT,title VARCHAR(255),description TEXT,agency VARCHAR(255),date DATE); INSERT INTO cybersecurity_strategies (id,title,description,agency,date) VALUES (1,'Active Cyber Defense Certainty Act','Creates a legal safe harbor for businesses to defend themselves against cyber threats','Congress','2017-10-02'); INSERT INTO cybersecurity_strategies (id,title,description,agency,date) VALUES (2,'Department of Defense Cyber Strategy','Guides the Department of Defense efforts to counter adversary activities in cyberspace','DoD','2018-04-16'); INSERT INTO cybersecurity_strategies (id,title,description,agency,date) VALUES (3,'EU Cybersecurity Act','Enhances cybersecurity in the EU','European Union','2019-04-08');
SELECT title, description, agency, date, LEAD(date) OVER (ORDER BY date) as next_date FROM cybersecurity_strategies WHERE agency = 'European Union';
What is the total number of workers earning more than the average wage in the 'service' sector?
CREATE TABLE worker_salary (id INT,sector VARCHAR(20),wage FLOAT); INSERT INTO worker_salary (id,sector,wage) VALUES (1,'service',15.25),(2,'service',17.50),(3,'service',13.00),(4,'service',18.00);
SELECT COUNT(*) FROM worker_salary WHERE sector = 'service' AND wage > (SELECT AVG(wage) FROM worker_salary WHERE sector = 'service');
What is the average price of organic products in the Skincare category?
CREATE TABLE Products (ProductID INT,ProductName VARCHAR(50),Category VARCHAR(50),Price DECIMAL(5,2),Organic BOOLEAN); INSERT INTO Products (ProductID,ProductName,Category,Price,Organic) VALUES (1,'Aloe Vera Gel','Skincare',12.99,TRUE),(2,'Vitamin C Serum','Skincare',29.99,FALSE),(3,'Argan Oil','Skincare',18.99,TRUE);
SELECT Category, AVG(Price) FROM Products WHERE Category = 'Skincare' AND Organic = TRUE GROUP BY Category;
How many esports events were held in Japan in 2022?
CREATE TABLE EsportsEvents (EventID INT,Country VARCHAR(20),Year INT); INSERT INTO EsportsEvents (EventID,Country,Year) VALUES (1,'Japan',2022);
SELECT COUNT(*) FROM EsportsEvents WHERE Country = 'Japan' AND Year = 2022;
Insert a new inclusive housing policy into the inclusive_housing_policies table
CREATE TABLE public.inclusive_housing_policies (id SERIAL PRIMARY KEY,policy_name VARCHAR(255),policy_description TEXT,city_name VARCHAR(255),state_name VARCHAR(255));
INSERT INTO public.inclusive_housing_policies (policy_name, policy_description, city_name, state_name) VALUES ('Affordable Housing Act', 'Provides tax incentives for developers building affordable housing units', 'Denver', 'Colorado');
Add a new record to the species table for 'Black Spruce' in 'Canada'
CREATE TABLE species (id INT PRIMARY KEY,common_name TEXT,scientific_name TEXT,region TEXT);
INSERT INTO species (id, common_name, scientific_name, region) VALUES (1, 'Black Spruce', 'Picea mariana', 'Canada');
What is the average revenue for restaurants in the 'Italian' category that have a rating of at least 4?
CREATE TABLE restaurants (id INT,name VARCHAR(255),type VARCHAR(255),revenue FLOAT,rating INT); INSERT INTO restaurants (id,name,type,revenue,rating) VALUES (1,'Restaurant A','Italian',5000.00,3),(2,'Restaurant B','Asian',8000.00,5),(3,'Restaurant C','Mexican',3000.00,4),(4,'Restaurant D','Italian',6000.00,5);
SELECT AVG(revenue) FROM restaurants WHERE type = 'Italian' AND rating >= 4;
What is the total distance of packages delivered by DHL?
CREATE TABLE Routes (RouteId INT,OriginWarehouseId INT,DestinationWarehouseId INT,CarrierId INT,Distance INT,DeliveryTime INT); INSERT INTO Routes (RouteId,OriginWarehouseId,DestinationWarehouseId,CarrierId,Distance,DeliveryTime) VALUES (1,1,2,1,500,240); INSERT INTO Routes (RouteId,OriginWarehouseId,DestinationWarehouseId,CarrierId,Distance,DeliveryTime) VALUES (2,2,1,2,500,240); INSERT INTO Routes (RouteId,OriginWarehouseId,DestinationWarehouseId,CarrierId,Distance,DeliveryTime) VALUES (3,2,3,3,1000,480);
SELECT SUM(Distance) AS TotalDistance FROM Routes WHERE CarrierId = 3;
How can I delete the landfill data for the year 2020 from the co2_emissions table?
CREATE TABLE waste_treatment_methods (id INT,name VARCHAR(255),year INT); INSERT INTO waste_treatment_methods (id,name,year) VALUES (1,'Landfill',2019),(2,'Incineration',2020),(3,'Recycling',2020),(4,'Composting',2018); CREATE TABLE co2_emissions (treatment_method_id INT,emissions INT,year INT); INSERT INTO co2_emissions (treatment_method_id,emissions,year) VALUES (1,100,2019),(1,120,2019),(2,80,2020),(2,100,2020),(3,60,2020),(3,70,2020);
DELETE FROM co2_emissions WHERE treatment_method_id = 1 AND year = 2020;
What is the average price of green-certified buildings in the city of Seattle?
CREATE TABLE green_buildings (id INT,price FLOAT,city VARCHAR(20)); INSERT INTO green_buildings (id,price,city) VALUES (1,500000,'Seattle'),(2,700000,'Portland');
SELECT AVG(price) FROM green_buildings WHERE city = 'Seattle';
How many consumers have made purchases from both ethical and unethical suppliers?
CREATE TABLE consumers (consumer_id INT); CREATE TABLE purchases (purchase_id INT,consumer_id INT,supplier_id INT,is_ethical BOOLEAN); INSERT INTO consumers (consumer_id) VALUES (1),(2),(3),(4),(5); INSERT INTO purchases (purchase_id,consumer_id,supplier_id,is_ethical) VALUES (1,1,1,TRUE),(2,1,2,FALSE),(3,2,3,TRUE),(4,3,4,FALSE),(5,4,5,TRUE);
SELECT consumers.consumer_id FROM consumers INNER JOIN purchases purch1 ON consumers.consumer_id = purch1.consumer_id INNER JOIN purchases purch2 ON consumers.consumer_id = purch2.consumer_id WHERE purch1.is_ethical = TRUE AND purch2.is_ethical = FALSE GROUP BY consumers.consumer_id HAVING COUNT(DISTINCT purch1.supplier_id) > 1 AND COUNT(DISTINCT purch2.supplier_id) > 1;
What is the maximum water temperature recorded in brackish water farms in the year 2021?
CREATE TABLE water_temperature (farm_id INT,water_type VARCHAR(10),year INT,temperature FLOAT); INSERT INTO water_temperature VALUES (1,'Marine',2021,25.5),(2,'Marine',2022,26.0),(3,'Brackish',2021,24.5),(4,'Freshwater',2022,23.0);
SELECT MAX(temperature) FROM water_temperature WHERE water_type = 'Brackish' AND year = 2021;
What is the average loan amount for socially responsible lending in the United Kingdom?
CREATE TABLE socially_responsible_lending (id INT,country VARCHAR(255),loan_amount DECIMAL(10,2));
SELECT AVG(loan_amount) FROM socially_responsible_lending WHERE country = 'United Kingdom';
What is the total revenue generated by eco-friendly hotels in the United Kingdom and the United States?
CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,country TEXT); INSERT INTO hotels (hotel_id,hotel_name,country) VALUES (1,'Eco Hotel London','United Kingdom'),(2,'Green Hotel New York','United States'),(3,'Sustainable Hotel Tokyo','Japan'); CREATE TABLE bookings (booking_id INT,hotel_id INT,revenue INT); INSERT INTO bookings (booking_id,hotel_id,revenue) VALUES (1,1,200),(2,1,300),(3,2,400);
SELECT SUM(bookings.revenue) FROM bookings INNER JOIN hotels ON bookings.hotel_id = hotels.hotel_id WHERE hotels.country IN ('United Kingdom', 'United States') AND hotels.hotel_name LIKE '%eco%' OR hotels.hotel_name LIKE '%green%';
What are the total sales and average sales per transaction for beauty products with a palm oil-free label in Germany?
CREATE TABLE beauty_products_germany (palm_oil_free BOOLEAN,sale_date DATE,sales_quantity INT,unit_price DECIMAL(5,2)); INSERT INTO beauty_products_germany (palm_oil_free,sale_date,sales_quantity,unit_price) VALUES (TRUE,'2022-01-01',120,22.99),(FALSE,'2022-01-01',180,18.99);
SELECT SUM(sales_quantity * unit_price) AS total_sales, AVG(sales_quantity) AS avg_sales_per_transaction FROM beauty_products_germany WHERE palm_oil_free = TRUE AND sale_date BETWEEN '2022-01-01' AND '2022-12-31';
Identify the top 3 most frequent types of threats and their frequency for the organization 'Org789' for the current year?
CREATE TABLE threats (threat_type VARCHAR(255),organization VARCHAR(255),threat_date DATE); INSERT INTO threats (threat_type,organization,threat_date) VALUES ('Phishing','Org789','2022-01-01'),('Malware','Org789','2022-01-05'),('Ransomware','Org789','2022-01-10'),('Phishing','Org789','2022-02-01'),('Phishing','Org789','2022-02-15'),('Malware','Org789','2022-03-01'),('Phishing','Org789','2022-03-15'),('Ransomware','Org789','2022-04-01'),('Phishing','Org789','2022-04-15'),('Malware','Org789','2022-05-01'),('Phishing','Org789','2022-05-15');
SELECT threat_type, COUNT(threat_type) as frequency FROM threats WHERE organization = 'Org789' AND threat_date >= DATEADD(year, -1, GETDATE()) GROUP BY threat_type ORDER BY frequency DESC LIMIT 3;
Compute the average construction cost per mile for highways in the Midwest, and the total cost for highways constructed since 2015.
CREATE TABLE highways (id INT,highway_name VARCHAR(255),location VARCHAR(255),length FLOAT,construction_cost INT); INSERT INTO highways (id,highway_name,location,length,construction_cost) VALUES (1,'I-70 Expansion','Midwest',32.1,120000000),(2,'I-80 Reconstruction','Midwest',45.9,200000000),(3,'I-35 Interchange','Midwest',14.5,70000000);
SELECT location, AVG(construction_cost / length) AS avg_cost_per_mile, SUM(construction_cost) AS total_cost FROM highways WHERE location = 'Midwest' AND construction_cost > 0 AND length > 0 GROUP BY location;
Determine the distribution of user interests based on their ethnicity.
CREATE TABLE user_demographics (user_id INT,ethnicity VARCHAR(255),interest VARCHAR(255)); INSERT INTO user_demographics (user_id,ethnicity,interest) VALUES (1,'Hispanic','Politics'),(2,'African American','Sports'),(3,'Asian','Tech');
SELECT ethnicity, interest, COUNT(*) as count FROM user_demographics GROUP BY ethnicity, interest;
What is the total budget allocated for education and transportation services in the year 2021?
CREATE TABLE ServiceBudget (Year INT,Service VARCHAR(255),Budget FLOAT); INSERT INTO ServiceBudget (Year,Service,Budget) VALUES (2021,'Education',200000),(2021,'Transportation',150000),(2021,'Healthcare',180000),(2021,'Public Safety',250000),(2021,'Housing',120000);
SELECT SUM(Budget) FROM ServiceBudget WHERE Year = 2021 AND (Service = 'Education' OR Service = 'Transportation');
Which sustainable fashion brands have a lower energy efficiency score than the industry average (0.75)?
CREATE TABLE BrandSustainability (brand VARCHAR(30),water_usage DECIMAL(4,2),energy_efficiency DECIMAL(4,2),customer_satisfaction INT); INSERT INTO BrandSustainability VALUES ('EcoFashions',1.25,0.80,4),('GreenThreads',1.10,0.90,5),('SustainaClothes',1.05,0.70,3);
SELECT brand FROM BrandSustainability WHERE energy_efficiency < 0.75;
What is the most recent cybersecurity incident reported?
CREATE TABLE cybersecurity_incidents (id INT,incident_date DATE,incident_type VARCHAR(255)); INSERT INTO cybersecurity_incidents (id,incident_date,incident_type) VALUES (3,'2021-04-12','Ransomware Attack');
SELECT * FROM cybersecurity_incidents ORDER BY incident_date DESC LIMIT 1;
What is the total number of minutes of content produced by indigenous creators in Canada?
CREATE TABLE content_providers (id INT,name VARCHAR(255),location VARCHAR(64),is_indigenous BOOLEAN); CREATE TABLE content (id INT,title VARCHAR(255),duration INT,provider_id INT,PRIMARY KEY (id),FOREIGN KEY (provider_id) REFERENCES content_providers(id)); INSERT INTO content_providers (id,name,location,is_indigenous) VALUES (1,'Provider1','Canada',true),(2,'Provider2','USA',false),(3,'Provider3','Canada',true); INSERT INTO content (id,title,duration,provider_id) VALUES (1,'Content1',60,1),(2,'Content2',90,2),(3,'Content3',75,3),(4,'Content4',120,1);
SELECT SUM(content.duration) FROM content INNER JOIN content_providers ON content.provider_id = content_providers.id WHERE content_providers.location = 'Canada' AND content_providers.is_indigenous = true;
Who are the top 3 employees with the highest salaries in the 'metalwork' department?
CREATE TABLE employees (id INT,name TEXT,department TEXT,salary FLOAT); INSERT INTO employees (id,name,department,salary) VALUES (1,'John Doe','metalwork',50000.0),(2,'Jane Smith','textiles',40000.0),(3,'Mike Johnson','metalwork',55000.0);
SELECT name, salary FROM employees WHERE department = 'metalwork' ORDER BY salary DESC LIMIT 3;
List all deep-sea exploration missions and their start dates.
CREATE TABLE deep_sea_missions (id INT,mission_name TEXT,start_date DATE); INSERT INTO deep_sea_missions (id,mission_name,start_date) VALUES (1,'Project Nereus','2008-03-01'); INSERT INTO deep_sea_missions (id,mission_name,start_date) VALUES (2,'Challenger Deep Expedition','2012-03-25');
SELECT mission_name, start_date FROM deep_sea_missions;
Find the number of visitors who attended events in different cities.
CREATE TABLE different_cities_visitors (id INT,name TEXT,city TEXT); INSERT INTO different_cities_visitors VALUES (1,'Mike','LA');
SELECT COUNT(DISTINCT different_cities_visitors.name) FROM different_cities_visitors WHERE different_cities_visitors.city IN ('NY', 'LA', 'Chicago');
What is the total weight of cannabis flowers produced by each cultivation site in Colorado in the last 6 months?
CREATE TABLE cultivation_sites (id INT,state TEXT,site_name TEXT);CREATE TABLE cultivation (id INT,site_id INT,plant_weight DECIMAL,plant_type TEXT,cultivation_date DATE);
SELECT cs.site_name, SUM(c.plant_weight) as total_weight FROM cultivation_sites cs INNER JOIN cultivation c ON cs.id = c.site_id WHERE cs.state = 'Colorado' AND c.plant_type = 'flowers' AND c.cultivation_date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH) GROUP BY cs.site_name;
What is the minimum fairness score for AI models in the Europe region?
CREATE TABLE ai_fairness (model_name TEXT,region TEXT,fairness_score INTEGER); INSERT INTO ai_fairness (model_name,region,fairness_score) VALUES ('ModelX','Europe',75),('ModelY','Europe',80),('ModelZ','Asia',70);
SELECT MIN(fairness_score) FROM ai_fairness WHERE region = 'Europe';
What is the maximum budget allocated for sign language interpreters in each state?
CREATE TABLE interpreter_budget (state VARCHAR(20),budget INT); INSERT INTO interpreter_budget (state,budget) VALUES ('California',5000); INSERT INTO interpreter_budget (state,budget) VALUES ('Texas',7000); INSERT INTO interpreter_budget (state,budget) VALUES ('Florida',8000);
SELECT state, MAX(budget) FROM interpreter_budget GROUP BY state;
What is the average revenue generated by hotels in Southeast Asia?
CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,country TEXT,revenue FLOAT); INSERT INTO hotels (hotel_id,hotel_name,country,revenue) VALUES (1,'Hotel A','Indonesia',1000000),(2,'Hotel B','Malaysia',1200000),(3,'Hotel C','Thailand',1400000),(4,'Hotel D','Singapore',1600000);
SELECT country, AVG(revenue) as avg_revenue FROM hotels WHERE country IN ('Indonesia', 'Malaysia', 'Thailand', 'Singapore') GROUP BY country;
Insert a new record of a vegan lip balm product in the 'natural' category with a price of $4.99.
CREATE TABLE products (id INT,name VARCHAR(255),category VARCHAR(255),price DECIMAL(5,2),vegan BOOLEAN);
INSERT INTO products (name, category, price, vegan) VALUES ('Lip Balm', 'natural', 4.99, true);
Update the "guidelines" for the "IBM" record in the "ai_ethics" table to "AI ethical guidelines for AI integration"
CREATE TABLE ai_ethics (company TEXT,region TEXT,guidelines TEXT); INSERT INTO ai_ethics (company,region,guidelines) VALUES ('Microsoft','North America','Ethical AI guidelines for AI development'); INSERT INTO ai_ethics (company,region,guidelines) VALUES ('Google','Europe','AI ethical guidelines for AI usage'); INSERT INTO ai_ethics (company,region,guidelines) VALUES ('IBM','Asia','AI ethical guidelines for AI deployment');
UPDATE ai_ethics SET guidelines = 'AI ethical guidelines for AI integration' WHERE company = 'IBM';
What is the average risk assessment for policies in 'New Mexico' and 'Oklahoma' by 'Global' teams?
CREATE TABLE UnderwritingData (PolicyID INT,Team VARCHAR(20),RiskAssessment DECIMAL(5,2),State VARCHAR(20)); INSERT INTO UnderwritingData VALUES (1,'Global Team',0.35,'California'),(2,'Diverse Team',0.20,'California'),(3,'Global Team',0.15,'Texas'),(4,'Global Team',0.45,'New Mexico'),(5,'Global Team',0.55,'Oklahoma');
SELECT Team, AVG(RiskAssessment) FROM UnderwritingData WHERE State IN ('New Mexico', 'Oklahoma') AND Team LIKE 'Global%' GROUP BY Team;
What is the average number of annual visitors to museums in Senegal?
CREATE TABLE museums (museum_id INT,country VARCHAR(50),annual_visitors INT); INSERT INTO museums (museum_id,country,annual_visitors) VALUES (1,'Senegal',30000),(2,'Senegal',40000),(3,'Nigeria',50000);
SELECT AVG(m.annual_visitors) FROM museums m WHERE m.country = 'Senegal';
What is the total number of unique species in 'rehabilitated_animals' table?
CREATE TABLE rehabilitated_animals (id INT,species VARCHAR(255),population INT);
SELECT species FROM rehabilitated_animals GROUP BY species;
How many volunteers engaged in environmental programs in 2021?
CREATE TABLE Volunteers (id INT,user_id INT,program_id INT,volunteer_date DATE); INSERT INTO Volunteers (id,user_id,program_id,volunteer_date) VALUES (1,1001,101,'2021-04-10'); INSERT INTO Volunteers (id,user_id,program_id,volunteer_date) VALUES (2,1002,102,'2021-06-15'); INSERT INTO Volunteers (id,user_id,program_id,volunteer_date) VALUES (3,1003,101,'2022-03-15');
SELECT COUNT(*) FROM Volunteers WHERE program_id BETWEEN 101 AND 110 AND volunteer_date >= '2021-01-01' AND volunteer_date < '2022-01-01';
Update the "size" of the "EcoHouse" building in the "GreenBuildings" table to 2000
CREATE TABLE GreenBuildings (id INT,building_name VARCHAR(20),material VARCHAR(20),size INT); INSERT INTO GreenBuildings (id,building_name,material,size) VALUES (1,'EcoHouse','wood',1500),(2,'GreenOffice','steel',2000),(3,'SolarTower','concrete',3000);
UPDATE GreenBuildings SET size = 2000 WHERE building_name = 'EcoHouse';
What is the total number of animals in the African habitat preservation initiative?
CREATE TABLE animal_population (animal_id INT,animal_region VARCHAR(255)); INSERT INTO animal_population (animal_id,animal_region) VALUES (1,'Africa'),(2,'Asia'),(3,'South America');
SELECT COUNT(*) FROM animal_population WHERE animal_region = 'Africa';
How many countries have ratified the Paris Agreement by region?
CREATE TABLE paris_agreement (country TEXT,region TEXT); INSERT INTO paris_agreement (country,region) VALUES ('USA','North America'),('Canada','North America'),('Mexico','North America'),('Brazil','South America'),('Argentina','South America'),('Australia','Oceania'),('New Zealand','Oceania'),('India','Asia'),('China','Asia'),('Russia','Europe'),('Germany','Europe'),('France','Europe');
SELECT region, COUNT(DISTINCT country) FROM paris_agreement GROUP BY region;
How many rare earth elements were produced in each year since 2015?
CREATE TABLE production (year INT,element TEXT,volume INT); INSERT INTO production (year,element,volume) VALUES (2015,'neodymium',10000),(2016,'neodymium',12000),(2017,'neodymium',14000),(2018,'neodymium',15000),(2015,'dysprosium',5000),(2016,'dysprosium',6000),(2017,'dysprosium',7000),(2018,'dysprosium',8000),(2019,'dysprosium',9000); CREATE TABLE elements (element TEXT); INSERT INTO elements (element) VALUES ('neodymium'),('dysprosium');
SELECT p.year, COUNT(DISTINCT e.element) AS element_count FROM production p JOIN elements e ON e.element = p.element GROUP BY p.year;
What is the total quantity of Lanthanum (La) and Cerium (Ce) produced by each country in the last three years, ordered by year and country?
CREATE TABLE production_data (element VARCHAR(2),country VARCHAR(15),quantity INT,year INT); INSERT INTO production_data VALUES ('La','India',8000,2020),('Ce','Brazil',7000,2020),('La','India',9000,2021),('Ce','Brazil',8000,2021),('La','India',10000,2022),('Ce','Brazil',9000,2022);
SELECT country, YEAR(production_data.year) AS year, SUM(quantity) AS total_quantity FROM production_data WHERE element IN ('La', 'Ce') AND production_data.year BETWEEN YEAR(CURRENT_DATE) - 3 AND YEAR(CURRENT_DATE) GROUP BY country, year ORDER BY year, country;
Find the total number of garments manufactured using recycled materials in Africa.
CREATE TABLE garments (garment_id INT,recycled BOOLEAN,manufacture_location VARCHAR(255)); INSERT INTO garments (garment_id,recycled,manufacture_location) VALUES (1,TRUE,'Nigeria'); INSERT INTO garments (garment_id,recycled,manufacture_location) VALUES (2,FALSE,'Egypt'); INSERT INTO garments (garment_id,recycled,manufacture_location) VALUES (3,TRUE,'South Africa');
SELECT COUNT(*) FROM garments WHERE recycled = TRUE AND manufacture_location LIKE 'Africa%';
What is the percentage of employees who are from underrepresented racial or ethnic groups?
CREATE TABLE EmployeeData (EmployeeID int,Race varchar(50)); INSERT INTO EmployeeData (EmployeeID,Race) VALUES (1,'White'),(2,'Asian'),(3,'Hispanic'),(4,'Black');
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM EmployeeData)) AS Percentage FROM EmployeeData WHERE Race IN ('Hispanic', 'Black');
What is the total number of tourists who visited Japan in 2020 and 2021, grouped by continent?
CREATE TABLE tourism_stats (country VARCHAR(255),year INT,visitors INT,continent VARCHAR(255)); INSERT INTO tourism_stats (country,year,visitors,continent) VALUES ('Japan',2020,12000000,'Asia'); INSERT INTO tourism_stats (country,year,visitors,continent) VALUES ('Japan',2021,15000000,'Asia');
SELECT continent, SUM(visitors) as total_visitors FROM tourism_stats WHERE country = 'Japan' AND year IN (2020, 2021) GROUP BY continent;
What is the average length of songs in the 'Rock' genre?
CREATE TABLE songs (id INT,title VARCHAR(255),length DECIMAL(5,2),genre_id INT); CREATE TABLE genres (id INT,genre VARCHAR(255)); INSERT INTO genres VALUES (1,'Rock'); INSERT INTO songs VALUES (1,'Bohemian Rhapsody',545,1);
SELECT AVG(s.length) as avg_length FROM songs s JOIN genres g ON s.genre_id = g.id WHERE g.genre = 'Rock';
How many space debris objects are currently being tracked by the Space Surveillance Network (SSN)?
CREATE TABLE SpaceDebris (DebrisID INT,ObjectType VARCHAR(50),IsTrackedBySSN BOOLEAN,LastObservationDate DATETIME);
SELECT COUNT(*) FROM SpaceDebris WHERE IsTrackedBySSN = TRUE;
Insert a new pop song released in 2022 into the Songs table
CREATE TABLE Songs (song_id INT,title TEXT,genre TEXT,release_date DATE,price DECIMAL(5,2));
INSERT INTO Songs (song_id, title, genre, release_date, price) VALUES (1001, 'New Pop Song', 'pop', '2022-10-15', 0.99);
Count the number of schools constructed in "Asia" before 2021.
CREATE TABLE schools (id INT,project_id INT,location VARCHAR(255),construction_date DATE); INSERT INTO schools (id,project_id,location,construction_date) VALUES (1,3001,'India','2019-05-01'); INSERT INTO schools (id,project_id,location,construction_date) VALUES (2,3002,'Nepal','2018-02-01');
SELECT COUNT(*) FROM schools WHERE location = 'Asia' AND YEAR(construction_date) < 2021;
What is the total revenue generated from 'Suburbs'?
CREATE TABLE suburbs_revenue (revenue int); INSERT INTO suburbs_revenue (revenue) VALUES (5000),(6000),(7000);
SELECT SUM(revenue) FROM suburbs_revenue;
Find the number of farmers who grow crops in the same country as the farmer with the id of 1.
CREATE TABLE Farmers (id INT PRIMARY KEY,name VARCHAR(50),age INT,country VARCHAR(50)); INSERT INTO Farmers (id,name,age,country) VALUES (1,'John Doe',35,'USA'); INSERT INTO Farmers (id,name,age,country) VALUES (2,'Jane Smith',40,'Canada'); CREATE TABLE Crops (id INT PRIMARY KEY,name VARCHAR(50),growth_stage VARCHAR(50),farmer_id INT,FOREIGN KEY (farmer_id) REFERENCES Farmers(id)); INSERT INTO Crops (id,name,growth_stage,farmer_id) VALUES (1,'Corn','Germination',1); INSERT INTO Crops (id,name,growth_stage,farmer_id) VALUES (2,'Soybeans','Vegetative',2);
SELECT COUNT(*) FROM Farmers INNER JOIN Crops ON Farmers.id = Crops.farmer_id WHERE Farmers.country = (SELECT country FROM Farmers WHERE id = 1);
How many ethical concerns were raised for each AI safety principle?
CREATE TABLE ai_safety_principles (principle_name TEXT,ethical_concerns INT); INSERT INTO ai_safety_principles (principle_name,ethical_concerns) VALUES ('Beneficence',12),('Nonmaleficence',8),('Autonomy',15),('Justice',10);
SELECT principle_name, ethical_concerns FROM ai_safety_principles;
Update the 'area_sq_miles' column in the 'state_facts' table for the state of 'NY' to 54_556
CREATE TABLE state_facts (state VARCHAR(2),capital VARCHAR(50),population INT,area_sq_miles INT);
UPDATE state_facts SET area_sq_miles = 54556 WHERE state = 'NY';
Which ethical AI tools have a higher rating than the average rating of AI tools in their respective regions?
CREATE TABLE ethical_ai (tool_id INT,tool_name VARCHAR(50),region VARCHAR(50),rating FLOAT); INSERT INTO ethical_ai (tool_id,tool_name,region,rating) VALUES (1,'EAITool1','APAC',4.4),(2,'EAITool2','EMEA',4.7),(3,'EAITool3','AMER',4.6);
SELECT tool_name, region, rating FROM (SELECT tool_name, region, rating, AVG(rating) OVER (PARTITION BY region) as avg_rating FROM ethical_ai) subquery WHERE rating > avg_rating;
What is the minimum membership fee in each country?
CREATE TABLE memberships (id INT,member_country VARCHAR(50),membership_start_date DATE,membership_fee FLOAT); INSERT INTO memberships (id,member_country,membership_start_date,membership_fee) VALUES (1,'United States','2022-01-05',50.0),(2,'Canada','2022-01-10',75.0);
SELECT member_country, MIN(membership_fee) FROM memberships GROUP BY member_country;
Identify the most popular color for each product category in the last year.
CREATE TABLE Product_Sales (product_id INT,sale_date DATE,product_category VARCHAR(255),product_color VARCHAR(255)); INSERT INTO Product_Sales (product_id,sale_date,product_category,product_color) VALUES (1,'2021-01-01','Tops','Red'),(2,'2021-01-15','Trousers','Blue'),(3,'2021-02-01','Tops','Black'),(4,'2021-02-10','Dresses','White'),(5,'2021-03-01','Trousers','Black'),(6,'2021-03-15','Tops','White'),(7,'2021-04-01','Trousers','Red'),(8,'2021-04-10','Dresses','Yellow'),(9,'2021-05-01','Trousers','Green'),(10,'2021-05-15','Tops','Pink');
SELECT product_category, product_color, COUNT(*) as count FROM Product_Sales WHERE sale_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) AND CURRENT_DATE GROUP BY product_category, product_color ORDER BY count DESC;
What is the maximum number of workforce development programs offered by companies in the 'europe' region?
CREATE TABLE companies (id INT,name TEXT,region TEXT,num_workforce_programs INT); INSERT INTO companies (id,name,region,num_workforce_programs) VALUES (1,'Empowerment Enterprises','Europe',3); INSERT INTO companies (id,name,region,num_workforce_programs) VALUES (2,'Skillset Solutions','Europe',2); INSERT INTO companies (id,name,region,num_workforce_programs) VALUES (3,'Proficiency Partners','Europe',4); INSERT INTO companies (id,name,region,num_workforce_programs) VALUES (4,'Abilities Associates','Europe',5); INSERT INTO companies (id,name,region,num_workforce_programs) VALUES (5,'Capability Creations','Europe',1);
SELECT MAX(num_workforce_programs) AS max_programs FROM companies WHERE region = 'Europe';
What are the spacecraft manufacturing countries and the number of satellites in their networks?
CREATE TABLE Spacecraft_Manufacturers (Manufacturer_ID INT,Name VARCHAR(50),Country VARCHAR(50)); CREATE TABLE Satellite_Networks (Network_ID INT,Name VARCHAR(50),Satellite_Count INT,Agency_ID INT);
SELECT Spacecraft_Manufacturers.Country, SUM(Satellite_Networks.Satellite_Count) FROM Spacecraft_Manufacturers INNER JOIN Satellite_Networks ON Spacecraft_Manufacturers.Country = Satellite_Networks.Location GROUP BY Spacecraft_Manufacturers.Country;
List the top 2 green building projects by total budget in Africa in descending order.
CREATE TABLE green_building_projects (project_id INT,project_name VARCHAR(100),country VARCHAR(50),total_budget FLOAT); INSERT INTO green_building_projects (project_id,project_name,country,total_budget) VALUES (1,'EcoTower','Kenya',20000000),(2,'SustainableVillage','South Africa',30000000),(3,'GreenCity','Egypt',25000000);
SELECT project_name, total_budget FROM (SELECT project_name, total_budget, ROW_NUMBER() OVER (ORDER BY total_budget DESC) rn FROM green_building_projects WHERE country IN ('Kenya', 'South Africa', 'Egypt')) WHERE rn <= 2
What is the total rare earth element production for the year 2020?
CREATE TABLE production_yearly (year INT,country VARCHAR(50),production INT); INSERT INTO production_yearly (year,country,production) VALUES (2018,'China',60000),(2018,'USA',25000),(2018,'Australia',15000),(2019,'China',70000),(2019,'USA',30000),(2019,'Australia',18000),(2020,'China',105000),(2020,'USA',38000),(2020,'Australia',20000);
SELECT SUM(production) FROM production_yearly WHERE year = 2020;
Show production rates for machines in the electronics manufacturing industry, ordered from highest to lowest.
CREATE TABLE machine_data (machine_type VARCHAR(50),industry VARCHAR(50),production_rate FLOAT); INSERT INTO machine_data (machine_type,industry,production_rate) VALUES ('Surface Mount Technology Machine','Electronics',150),('Automated Optical Inspection Machine','Electronics',130),('Selective Soldering Machine','Electronics',120),('Automated Guided Vehicle','Electronics',50),('Robotic Arm','Electronics',80);
SELECT machine_type, production_rate FROM machine_data WHERE industry = 'Electronics' ORDER BY production_rate DESC;
Who are the top 5 creators by number of followers, and what is their total number of followers?
CREATE TABLE creators (id INT,followers INT); INSERT INTO creators (id,followers) VALUES (1,10000),(2,25000),(3,15000),(4,30000),(5,5000); CREATE TABLE content (creator_id INT,followers INT); INSERT INTO content (creator_id,followers) VALUES (1,12000),(2,28000),(3,16000),(4,32000),(5,5500);
SELECT c.id, c.followers + COALESCE(content.followers, 0) AS total_followers FROM creators c LEFT JOIN (SELECT creator_id, SUM(followers) AS followers FROM content GROUP BY creator_id) content ON c.id = content.creator_id ORDER BY total_followers DESC LIMIT 5;
What is the total number of patients diagnosed with Dengue Fever in India in 2021?
CREATE TABLE Patients (ID INT,Gender VARCHAR(10),Disease VARCHAR(20),Country VARCHAR(30),Diagnosis_Date DATE); INSERT INTO Patients (ID,Gender,Disease,Country,Diagnosis_Date) VALUES (1,'Male','Dengue Fever','India','2021-01-01');
SELECT COUNT(*) FROM Patients WHERE Disease = 'Dengue Fever' AND Country = 'India' AND YEAR(Diagnosis_Date) = 2021;
Insert a new hydroelectric project 'Rocky Dam' with 350 MW capacity in Washington state
CREATE TABLE hydro_energy_projects (id INT PRIMARY KEY,project_name VARCHAR(255),state VARCHAR(2),capacity FLOAT,status VARCHAR(50));
INSERT INTO hydro_energy_projects (project_name, state, capacity, status) VALUES ('Rocky Dam', 'Washington', 350.0, 'Planning');
What was the total cost of manufacturing the Boeing 787 Dreamliner?
CREATE TABLE Manufacturing_Costs (manufacturer VARCHAR(50),model VARCHAR(50),cost FLOAT); INSERT INTO Manufacturing_Costs (manufacturer,model,cost) VALUES ('Boeing','787 Dreamliner',2500000000);
SELECT cost FROM Manufacturing_Costs WHERE manufacturer = 'Boeing' AND model = '787 Dreamliner';
What are the names and locations of all agricultural innovation projects in the 'rural_innovation' table?
CREATE TABLE rural_innovation (id INT,name VARCHAR(50),location VARCHAR(50));
SELECT name, location FROM rural_innovation;
What is the earliest launch date of campaigns by 'org_z'?
CREATE TABLE org_z (campaign_id INT,organization VARCHAR(10),launch_date DATE); INSERT INTO org_z (campaign_id,organization,launch_date) VALUES (5,'org_z','2021-01-01'),(6,'org_z','2022-01-01');
SELECT MIN(launch_date) FROM org_z WHERE organization = 'org_z';
What was the average water usage in Mumbai per month in 2019?
CREATE TABLE WaterUsage (Id INT,Location VARCHAR(100),Usage INT,Month INT,Year INT); INSERT INTO WaterUsage (Id,Location,Usage,Month,Year) VALUES (1,'Mumbai',1500,1,2019); INSERT INTO WaterUsage (Id,Location,Usage,Month,Year) VALUES (2,'Mumbai',1700,2,2019); INSERT INTO WaterUsage (Id,Location,Usage,Month,Year) VALUES (3,'Delhi',1300,1,2019); INSERT INTO WaterUsage (Id,Location,Usage,Month,Year) VALUES (4,'Delhi',1400,2,2019);
SELECT Location, AVG(Usage) FROM WaterUsage WHERE Location = 'Mumbai' AND Year = 2019 GROUP BY Location, Month;
What is the minimum lifelong learning participation rate for students in each gender category that has more than 10 students?
CREATE TABLE student_demographics (student_id INT,gender VARCHAR(10),participation_rate DECIMAL(5,2)); INSERT INTO student_demographics (student_id,gender,participation_rate) VALUES (1,'Male',0.85),(2,'Female',0.90),(3,'Non-binary',0.75),(4,'Genderqueer',0.80),(5,'Female',0.95);
SELECT gender, MIN(participation_rate) as min_participation_rate FROM student_demographics GROUP BY gender HAVING COUNT(student_id) > 10;
What is the average budget allocation per program for community development initiatives in the state of New York?
CREATE TABLE CommunityDevelopmentInitiatives (InitiativeID INT,ProgramName VARCHAR(255),State VARCHAR(255),Budget DECIMAL(10,2)); INSERT INTO CommunityDevelopmentInitiatives (InitiativeID,ProgramName,State,Budget) VALUES (1,'Parks Improvement','New York',500000.00),(2,'Education Grants','New York',800000.00);
SELECT AVG(Budget) FROM CommunityDevelopmentInitiatives WHERE State = 'New York' AND ProgramName LIKE '%community development%';
What is the minimum and maximum property price in the city of Portland?
CREATE TABLE Properties (id INT,price INT,city TEXT); INSERT INTO Properties (id,price,city) VALUES (1,600000,'Portland'),(2,500000,'Seattle'),(3,800000,'Portland'),(4,700000,'Denver');
SELECT MIN(price) AS min_price, MAX(price) AS max_price FROM Properties WHERE city = 'Portland';
What are the total sales figures for each drug in the 'SalesData' table, grouped by drug name?
CREATE TABLE SalesData (drug_name VARCHAR(255),sales_quantity INT,sales_amount DECIMAL(10,2)); INSERT INTO SalesData (drug_name,sales_quantity,sales_amount) VALUES ('DrugA',150,25000.00),('DrugB',200,30000.00),('DrugC',100,12000.00);
SELECT drug_name, SUM(sales_quantity) as total_sales_quantity, SUM(sales_amount) as total_sales_amount FROM SalesData GROUP BY drug_name;
Calculate the total biomass of fish for each species, categorized by the farm's continent.
CREATE TABLE Continent (id INT,name VARCHAR(50)); CREATE TABLE Farm (id INT,name VARCHAR(50),country VARCHAR(50),continent_id INT); CREATE TABLE Species (id INT,name VARCHAR(50),scientific_name VARCHAR(50)); CREATE TABLE FarmSpecies (farm_id INT,species_id INT,biomass INT);
SELECT c.name, s.name, SUM(fs.biomass) FROM Species s JOIN FarmSpecies fs ON s.id = fs.species_id JOIN Farm f ON fs.farm_id = f.id JOIN Continent c ON f.continent_id = c.id GROUP BY c.name, s.name;
What is the trend of health equity metrics over time?
CREATE TABLE health_equity_metrics (metric_id INT,measurement_date DATE,value INT); INSERT INTO health_equity_metrics (metric_id,measurement_date,value) VALUES (1,'2022-01-01',70),(2,'2022-02-01',75),(3,'2022-03-01',80),(4,'2022-04-01',85),(5,'2022-05-01',90);
SELECT measurement_date, AVG(value) as avg_value FROM health_equity_metrics GROUP BY measurement_date;
Delete all public schools from the table that have a missing average teacher age.
CREATE TABLE public_schools (id INT,name TEXT,location TEXT,num_students INT,avg_teacher_age FLOAT); INSERT INTO public_schools (id,name,location,num_students,avg_teacher_age) VALUES (1,'School 1','MI',500,45.3),(2,'School 2','MI',600,NULL),(3,'School 3','MI',700,47.1);
DELETE FROM public_schools WHERE avg_teacher_age IS NULL;
What is the lowest-rated news article in the 'technology' section?
CREATE TABLE news_articles (id INT,title VARCHAR(100),section VARCHAR(50),rating INT); INSERT INTO news_articles (id,title,section,rating) VALUES (1,'Article 1','technology',3),(2,'Article 2','politics',5),(3,'Article 3','sports',4); CREATE TABLE news_ratings (article_id INT,rating INT); INSERT INTO news_ratings (article_id,rating) VALUES (1,3),(2,5),(3,4);
SELECT title FROM news_articles WHERE id = (SELECT article_id FROM news_ratings WHERE rating = (SELECT MIN(rating) FROM news_ratings));
What is the total funding received by startups in the renewable energy sector that were founded before 2010?
CREATE TABLE company (id INT,name TEXT,industry TEXT,founding_year INT); INSERT INTO company (id,name,industry,founding_year) VALUES (1,'GreenTech','Renewable Energy',2005),(2,'EcoInnovations','Renewable Energy',2012); CREATE TABLE funding (id INT,company_id INT,amount INT); INSERT INTO funding (id,company_id,amount) VALUES (1,1,2000000),(2,2,500000);
SELECT SUM(funding.amount) FROM funding INNER JOIN company ON funding.company_id = company.id WHERE company.industry = 'Renewable Energy' AND company.founding_year < 2010;
What is the average monthly data usage for customers in the 'Rural' region?
CREATE TABLE customers (id INT,name VARCHAR(50),data_usage FLOAT,region VARCHAR(20)); INSERT INTO customers (id,name,data_usage,region) VALUES (1,'John Doe',15.0,'Rural');
SELECT AVG(data_usage) FROM customers WHERE region = 'Rural';
Who are the players that have played more than 1000 matches in 'GameA'?
CREATE TABLE PlayerMatches (PlayerID int,GameID int,MatchesPlayed int); INSERT INTO PlayerMatches (PlayerID,GameID,MatchesPlayed) VALUES (1,1,1200),(2,1,800),(3,1,500),(4,1,700),(5,1,1500),(6,2,900),(7,2,1100),(8,3,1300),(9,3,1700),(10,4,1900);
SELECT PlayerID FROM PlayerMatches WHERE GameID = 1 AND MatchesPlayed > 1000;
What is the average speed of all vessels near the coast of Australia?
CREATE TABLE vessels(id INT,name TEXT,speed FLOAT,longitude FLOAT,latitude FLOAT); INSERT INTO vessels VALUES (1,'VesselA',20.5,139.6917,35.6895),(5,'VesselE',15.3,131.0414,-33.8568);
SELECT AVG(speed) FROM vessels WHERE longitude BETWEEN 112.9093 AND 153.6381 AND latitude BETWEEN -43.8337 AND -9.1552;
What is the total number of food assistance projects completed in the last 18 months in Latin America?
CREATE TABLE Projects (ProjectID int,ProjectName varchar(50),ProjectType varchar(50),StartDate date,EndDate date); INSERT INTO Projects (ProjectID,ProjectName,ProjectType,StartDate,EndDate) VALUES (1,'Food Distribution','Food Assistance','2021-01-01','2022-06-30'),(2,'School Meals','Food Assistance','2020-01-01','2021-12-31');
SELECT COUNT(ProjectID) as CompletedProjects FROM Projects WHERE ProjectType = 'Food Assistance' AND EndDate >= DATE_SUB(CURRENT_DATE, INTERVAL 18 MONTH) AND EndDate IS NOT NULL;
What is the total salary expense for each department, grouped by the manager of each department?
CREATE TABLE Employees (EmployeeID int,Department varchar(50),Manager varchar(50),Salary decimal(10,2)); INSERT INTO Employees (EmployeeID,Department,Manager,Salary) VALUES (1,'Engineering','John Doe',80000.00),(2,'Marketing','Jane Smith',70000.00),(3,'Sales','Bob Johnson',75000.00);
SELECT e.Manager, e.Department, SUM(e.Salary) as SalaryExpense FROM Employees e GROUP BY e.Manager, e.Department;
Identify the top 5 ocean basins with the most marine protected areas.
CREATE TABLE marine_protected_areas (area_id INTEGER,area_name TEXT,ocean_basin TEXT);
SELECT ocean_basin, COUNT(area_id) FROM marine_protected_areas GROUP BY ocean_basin ORDER BY COUNT(area_id) DESC LIMIT 5;
Show the number of community health workers who speak each language by city.
CREATE TABLE CommunityHealthWorkers (CHWId INT,City VARCHAR(255),Language VARCHAR(255)); INSERT INTO CommunityHealthWorkers (CHWId,City,Language) VALUES (1,'Los Angeles','Spanish'); INSERT INTO CommunityHealthWorkers (CHWId,City,Language) VALUES (2,'New York','English'); INSERT INTO CommunityHealthWorkers (CHWId,City,Language) VALUES (3,'Chicago','Polish'); INSERT INTO CommunityHealthWorkers (CHWId,City,Language) VALUES (4,'Miami','Spanish');
SELECT City, Language, COUNT(*) FROM CommunityHealthWorkers GROUP BY City, Language;
Insert a new record into the Inventory table for the 'OG Kush' strain with an added date of 2021-07-01.
CREATE TABLE Inventory (id INT,strain VARCHAR(255),added_date DATE);
INSERT INTO Inventory (strain, added_date) VALUES ('OG Kush', '2021-07-01');
What are the average dimensions of each artifact category in the 'Mexico' excavation sites?
CREATE TABLE artifact_categories (category_id INT,category_name TEXT); INSERT INTO artifact_categories (category_id,category_name) VALUES (1,'Pottery'),(2,'Stone Tools'),(3,'Jewelry'); CREATE TABLE artifacts (artifact_id INT,site_id INT,category_id INT,length FLOAT,width FLOAT,height FLOAT); INSERT INTO artifacts (artifact_id,site_id,category_id,length,width,height) VALUES (1,1,1,15.2,12.1,3.8),(2,1,2,18.5,5.6,2.1),(3,1,3,3.2,2.5,1.2); INSERT INTO artifacts (artifact_id,site_id,category_id,length,width,height) VALUES (4,2,1,10.9,9.3,2.7),(5,2,2,14.6,4.8,1.9),(6,2,3,4.1,3.3,1.5);
SELECT category_name, AVG(length) as avg_length, AVG(width) as avg_width, AVG(height) as avg_height FROM artifacts a JOIN excavation_sites s ON a.site_id = s.site_id WHERE s.country = 'Mexico' GROUP BY category_name;
List the number of IoT sensors in the 'PrecisionFarming' schema that have a 'moisture' measurement.
CREATE SCHEMA PrecisionFarming; CREATE TABLE IoT_Sensors (sensor_id INT,sensor_name VARCHAR(50),measurement VARCHAR(50)); INSERT INTO PrecisionFarming.IoT_Sensors (sensor_id,sensor_name,measurement) VALUES (1,'Sensor1','temperature'),(2,'Sensor2','humidity'),(4,'Sensor4','moisture');
SELECT COUNT(*) FROM PrecisionFarming.IoT_Sensors WHERE measurement = 'moisture';