instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What was the citizen feedback score for public service delivery in Indigenous communities in 2021?
CREATE TABLE Feedback (Community TEXT,Year INTEGER,Feedback_Score INTEGER); INSERT INTO Feedback (Community,Year,Feedback_Score) VALUES ('Urban Indigenous',2021,82),('Urban Indigenous',2022,87),('Rural Indigenous',2021,72),('Rural Indigenous',2022,77);
SELECT Community, AVG(Feedback_Score) FROM Feedback WHERE Year = 2021 GROUP BY Community;
Update the salary of an employee in the "employees" table
CREATE TABLE employees (id INT,first_name VARCHAR(50),last_name VARCHAR(50),department VARCHAR(50),salary DECIMAL(10,2));
UPDATE employees SET salary = 60000.00 WHERE first_name = 'Jamal' AND last_name = 'Johnson';
What is the sales trend for natural beauty products in the European region?
CREATE TABLE sales_data (sale_id INT,product_id INT,country VARCHAR(50),is_natural BOOLEAN,sale_date DATE,revenue DECIMAL(10,2));
SELECT country, YEAR(sale_date) as year, MONTH(sale_date) as month, SUM(revenue) as total_revenue, AVG(is_natural) as avg_natural FROM sales_data WHERE sale_date >= '2018-01-01' AND country LIKE 'Europe%' GROUP BY country, year, month;
What is the average carbon footprint, in metric tons, for the transportation of garments, per manufacturer, for the year 2020?
CREATE TABLE GarmentTransportation (manufacturer VARCHAR(255),carbon_footprint DECIMAL(10,2),year INT);
SELECT manufacturer, AVG(carbon_footprint) FROM GarmentTransportation WHERE year = 2020 GROUP BY manufacturer;
Identify the number of eco-friendly hotels in each city in Spain.
CREATE TABLE eco_friendly_hotels (hotel_id INT,name TEXT,city TEXT); INSERT INTO eco_friendly_hotels (hotel_id,name,city) VALUES (1,'EcoHotel Madrid','Madrid'),(2,'EcoHotel Barcelona','Barcelona'),(3,'EcoHotel Valencia','Valencia');
SELECT city, COUNT(*) as hotel_count FROM eco_friendly_hotels WHERE city IN (SELECT city FROM countries WHERE name = 'Spain') GROUP BY city;
What is the total number of humanitarian assistance personnel deployed by organizations from the Middle East?
CREATE TABLE humanitarian_assistance (id INT PRIMARY KEY,organization VARCHAR(100),personnel INT,region VARCHAR(50)); INSERT INTO humanitarian_assistance (id,organization,personnel,region) VALUES (1,'Org 1',1200,'Asia-Pacific'),(2,'Org 2',1500,'Middle East'),(3,'Org 3',1000,'Europe');
SELECT SUM(personnel) FROM humanitarian_assistance WHERE region = 'Middle East';
What is the maximum depth of the Sunda Trench in the Indian Ocean?
CREATE TABLE trenches (name VARCHAR(255),ocean VARCHAR(255),max_depth INT); INSERT INTO trenches (name,ocean,max_depth) VALUES ('Sunda Trench','Indian',36070),('Mariana Trench','Pacific',36098),('Tonga Trench','Pacific',35702),('South Sandwich Trench','Atlantic',35798),('Kermadec Trench','Pacific',10047);
SELECT max_depth FROM trenches WHERE name = 'Sunda Trench';
Which dispensaries in California have a higher number of unique customers than the state average?
CREATE TABLE dispensaries (dispensary_id INT,name VARCHAR(255),state VARCHAR(255));CREATE TABLE orders (order_id INT,dispensary_id INT,customer_id INT);
SELECT d.name FROM dispensaries d JOIN orders o ON d.dispensary_id = o.dispensary_id JOIN (SELECT AVG(cnt) as avg_cnt FROM (SELECT COUNT(DISTINCT customer_id) as cnt FROM orders WHERE state = 'California' GROUP BY dispensary_id) tmp) avg ON (SELECT COUNT(DISTINCT customer_id) FROM orders o2 WHERE o2.dispensary_id = d.d...
What is the total carbon sequestration in the 'carbon_sequestration' table grouped by forest name?
CREATE TABLE carbon_sequestration_forests (sequestration_id INT,forest_name VARCHAR(50),carbon_amount INT); INSERT INTO carbon_sequestration_forests (sequestration_id,forest_name,carbon_amount) VALUES (1,'Green Forest',500),(2,'Blue Forest',600),(3,'Green Forest',700);
SELECT forest_name, SUM(carbon_amount) as total_carbon_per_forest FROM carbon_sequestration_forests GROUP BY forest_name;
What is the average price of eco-friendly clothing by material?
CREATE TABLE EcoFriendlyClothing (ClothingID INT,Material VARCHAR(50),Price DECIMAL(5,2)); INSERT INTO EcoFriendlyClothing (ClothingID,Material,Price) VALUES (1,'Organic Cotton',50.99),(2,'Hemp',75.99),(3,'Recycled Polyester',35.99),(4,'Tencel',45.99);
SELECT Material, AVG(Price) as AvgPrice FROM EcoFriendlyClothing GROUP BY Material;
List the top 5 most attended events in the 'dance' category.
CREATE TABLE events (id INT,name VARCHAR(255),date DATE,category VARCHAR(255),attendance INT); INSERT INTO events (id,name,date,category,attendance) VALUES (1,'Ballet','2022-06-01','dance',500),(2,'Flamenco','2022-06-02','dance',400);
SELECT name, attendance FROM events WHERE category = 'dance' ORDER BY attendance DESC LIMIT 5;
What is the average budget spent on AI projects by organizations located in the Asia-Pacific region?
CREATE TABLE ai_projects (organization_name TEXT,location TEXT,budget INTEGER); INSERT INTO ai_projects (organization_name,location,budget) VALUES ('TechCorp','Asia-Pacific',2000000),('InnoTech','North America',3000000),('GreenAI','Europe',2500000);
SELECT AVG(budget) FROM ai_projects WHERE location = 'Asia-Pacific';
What are the names of the marine species observed in the Arctic Ocean, and what is their total count?
CREATE TABLE arctic_observations (species_name VARCHAR(255)); INSERT INTO arctic_observations (species_name) VALUES ('Polar Bear'); INSERT INTO arctic_observations (species_name) VALUES ('Narwhal'); INSERT INTO arctic_observations (species_name) VALUES ('Walrus');
SELECT species_name, COUNT(*) as total FROM arctic_observations;
What is the total number of electric vehicle charging stations in India and Mexico?
CREATE TABLE Charging_Stations_2 (Country VARCHAR(20),Station_Count INT); INSERT INTO Charging_Stations_2 (Country,Station_Count) VALUES ('India',800),('Mexico',1000),('Brazil',1200),('Russia',900),('Spain',1100);
SELECT SUM(Station_Count) FROM Charging_Stations_2 WHERE Country IN ('India', 'Mexico');
Update the oil production for platform A in Q4 2021 to 1500?
CREATE TABLE platform (platform_id INT,platform_name TEXT,oil_production_q4_2021 FLOAT); INSERT INTO platform (platform_id,platform_name,oil_production_q4_2021) VALUES (1,'A',1200),(2,'B',1800),(3,'C',2500);
UPDATE platform SET oil_production_q4_2021 = 1500 WHERE platform_name = 'A';
What is the number of building permits issued for each type of building in the city of Chicago?
CREATE TABLE permit (id INT,city VARCHAR(20),type VARCHAR(20),permit_number INT); INSERT INTO permit (id,city,type,permit_number) VALUES (1,'Chicago','Residential',100),(2,'Chicago','Commercial',150),(3,'LA','Residential',80);
SELECT type, COUNT(permit_number) FROM permit WHERE city = 'Chicago' GROUP BY type;
What is the total revenue from the top 2 most profitable countries?
CREATE TABLE Revenue (Country VARCHAR(20),Revenue DECIMAL(10,2)); INSERT INTO Revenue VALUES ('USA',500000),('Canada',350000),('Mexico',200000),('Brazil',400000),('Argentina',150000);
SELECT SUM(Revenue) FROM Revenue WHERE Country IN (SELECT Country FROM Revenue ORDER BY Revenue DESC LIMIT 2);
What is the total weight of indica flower sold in Michigan in Q4 2022?
CREATE TABLE Weight (id INT,strain TEXT,state TEXT,weight_sold INT); INSERT INTO Weight (id,strain,state,weight_sold) VALUES (1,'Purple Kush','MI',500),(2,'Northern Lights','MI',700),(3,'Granddaddy Purple','MI',800),(4,'OG Kush','MI',600);
SELECT SUM(weight_sold) as q4_indica_weight_sold FROM Weight WHERE state = 'MI' AND strain LIKE '%indica%' AND quarter(order_date) = 4 AND year(order_date) = 2022;
What countries have launched the most satellites?
CREATE TABLE satellites (country VARCHAR(50),num_satellites INT); INSERT INTO satellites (country,num_satellites) VALUES ('USA',1800),('China',400),('Russia',300);
SELECT country, SUM(num_satellites) as total_satellites FROM satellites GROUP BY country ORDER BY total_satellites DESC;
Calculate the average safety rating of ingredients by supplier in 2022.
CREATE TABLE IngredientSource (ingredient_id INT,supplier_id INT,safety_rating INT,source_date DATE); INSERT INTO IngredientSource (ingredient_id,supplier_id,safety_rating,source_date) VALUES (1,201,3,'2022-01-15'); INSERT INTO IngredientSource (ingredient_id,supplier_id,safety_rating,source_date) VALUES (2,202,5,'2022...
SELECT supplier_id, AVG(safety_rating) as avg_safety_rating FROM IngredientSource WHERE source_date >= '2022-01-01' AND source_date <= '2022-12-31' GROUP BY supplier_id;
Equipment maintenance requests in H1 2021 for the Pacific region?
CREATE TABLE equipment_maintenance (equipment_id INT,maintenance_date DATE,region VARCHAR(255)); INSERT INTO equipment_maintenance (equipment_id,maintenance_date,region) VALUES (1,'2021-01-15','Pacific'),(2,'2021-03-20','Atlantic'),(3,'2021-02-01','Pacific');
SELECT equipment_id, maintenance_date FROM equipment_maintenance WHERE region = 'Pacific' AND maintenance_date BETWEEN '2021-01-01' AND '2021-06-30';
Display the names of users and the assets they own that are subject to any regulation.
CREATE TABLE user_assets (user_id INT,asset_name VARCHAR(255)); INSERT INTO user_assets (user_id,asset_name) VALUES (1,'Asset1'),(2,'Asset2'),(3,'Asset3');
SELECT u.name, d.name FROM users u INNER JOIN user_assets ua ON u.id = ua.user_id INNER JOIN digital_assets d ON ua.asset_name = d.name INNER JOIN regulatory_frameworks r ON d.name = r.asset_name;
Update the transaction amounts for clients living in Africa with a 5% increase if their current transaction amount is above the average transaction amount.
CREATE TABLE clients (client_id INT,name TEXT,country TEXT,transaction_amount DECIMAL); INSERT INTO clients (client_id,name,country,transaction_amount) VALUES (1,'John Doe','Africa',500.00); INSERT INTO clients (client_id,name,country,transaction_amount) VALUES (2,'Jane Smith','Africa',350.00); INSERT INTO clients (cli...
UPDATE clients SET transaction_amount = transaction_amount * 1.05 WHERE country = 'Africa' AND transaction_amount > (SELECT AVG(transaction_amount) FROM clients WHERE country = 'Africa');
What is the total biomass of fish in all aquaculture farms in Asia in 2020?
CREATE TABLE Aquaculture_Farms (id INT,region VARCHAR(255),year INT,biomass INT); INSERT INTO Aquaculture_Farms (id,region,year,biomass) VALUES (1,'Asia',2018,250),(2,'Asia',2019,300),(3,'Europe',2018,150),(4,'Asia',2020,400);
SELECT SUM(Aquaculture_Farms.biomass) FROM Aquaculture_Farms WHERE Aquaculture_Farms.region = 'Asia' AND Aquaculture_Farms.year = 2020;
Calculate the average daily production rate for wells in California
CREATE TABLE wells (id INT,well_name VARCHAR(255),location VARCHAR(255),drill_year INT,company VARCHAR(255),daily_production_rate DECIMAL(5,2)); INSERT INTO wells (id,well_name,location,drill_year,company,daily_production_rate) VALUES (1,'Well001','Texas',2020,'CompanyA',100.50); INSERT INTO wells (id,well_name,locatio...
SELECT AVG(daily_production_rate) FROM wells WHERE location = 'California';
What is the total carbon footprint for each product category in the last year?
CREATE TABLE Product (id INT,name VARCHAR(255),category VARCHAR(255),carbon_footprint FLOAT,sale_date DATE);
SELECT category, SUM(carbon_footprint) as total_carbon_footprint FROM Product WHERE sale_date >= (CURRENT_DATE - INTERVAL '1 year') GROUP BY category;
How many 5-star food safety ratings were given to Asian restaurants?
CREATE TABLE Restaurants (id INT,name VARCHAR(50),type VARCHAR(20),safety_rating INT); INSERT INTO Restaurants (id,name,type,safety_rating) VALUES (1,'Green Garden','Vegan',5); INSERT INTO Restaurants (id,name,type,safety_rating) VALUES (2,'Bistro Bella','Italian',4); INSERT INTO Restaurants (id,name,type,safety_rating...
SELECT COUNT(*) FROM Restaurants WHERE type LIKE '%Asian%' AND safety_rating = 5;
Calculate the total number of food safety incidents for each category in the safety_incidents table.
CREATE TABLE safety_incidents (incident_id INT,incident_category VARCHAR(50),incident_description TEXT); INSERT INTO safety_incidents (incident_id,incident_category,incident_description) VALUES (1,'Contamination','E. coli found in lettuce'),(2,'Mislabeling','Undisclosed allergens in energy bars'),(3,'Contamination','Sa...
SELECT incident_category, COUNT(*) FROM safety_incidents GROUP BY incident_category;
How many farmers are there in each region and what is the average farm size for each region?
CREATE TABLE farmer_data (farmer_id INT,region TEXT,farm_size INT); INSERT INTO farmer_data (farmer_id,region,farm_size) VALUES (1,'North',150),(2,'North',200),(3,'South',100),(4,'South',120),(5,'East',180),(6,'East',220),(7,'West',140),(8,'West',160);
SELECT region, COUNT(*) as num_farmers, AVG(farm_size) as avg_farm_size FROM farmer_data GROUP BY region;
What is the earliest designation date for UNESCO World Heritage sites in Oceania?
CREATE TABLE heritagesites (name VARCHAR(255),location VARCHAR(255),designation_date DATE); INSERT INTO heritagesites (name,location,designation_date) VALUES ('Great Barrier Reef','Australia','1981-12-26'); INSERT INTO heritagesites (name,location,designation_date) VALUES ('Uluru-Kata Tjuta National Park','Australia','...
SELECT MIN(designation_date) FROM heritagesites WHERE location = 'Australia' AND location IN (SELECT location FROM heritagesites WHERE region = 'Oceania');
What is the total cost of materials for projects that started after January 1, 2021?
CREATE TABLE Projects (id INT,start_date DATE,material_cost FLOAT); INSERT INTO Projects (id,start_date,material_cost) VALUES (1,'2021-02-01',12000.0),(2,'2020-12-30',15000.0),(3,'2021-03-01',13000.0);
SELECT SUM(material_cost) FROM Projects WHERE start_date > '2021-01-01';
List all cultural heritage sites in Japan with their visitation counts in 2021.
CREATE TABLE cultural_sites (site_id INT,name VARCHAR(255),country VARCHAR(255),visitation_count INT); INSERT INTO cultural_sites (site_id,name,country,visitation_count) VALUES (1,'Temples of Kyoto','Japan',500000),(2,'Mount Fuji','Japan',800000);
SELECT name, visitation_count FROM cultural_sites WHERE country = 'Japan';
List all defense projects that have experienced delays and their new expected completion dates.
CREATE TABLE defense_projects(id INT,project_name VARCHAR(50),start_date DATE,end_date DATE,status VARCHAR(20));
SELECT project_name, start_date, end_date AS new_expected_completion_date FROM defense_projects WHERE status = 'Delayed';
What is the unsold quantity of the 't-shirt' garment type?
CREATE TABLE unsold_garments (id INT,garment_type VARCHAR(20),color VARCHAR(20),quantity INT);
SELECT SUM(quantity) AS unsold_quantity FROM unsold_garments WHERE garment_type = 't-shirt';
Calculate the average ticket price for each genre.
CREATE TABLE concerts (id INT,artist_id INT,genre TEXT,location TEXT,price DECIMAL);
SELECT genre, AVG(price) FROM concerts GROUP BY genre;
How many units of skincare products are sold per month on average?
CREATE TABLE sales (sale_id INT,product_id INT,sale_date DATE,quantity INT,price DECIMAL(5,2)); CREATE TABLE products (product_id INT,product_name VARCHAR(100),category VARCHAR(50));
SELECT AVG(EXTRACT(MONTH FROM sale_date) * quantity) FROM sales JOIN products ON sales.product_id = products.product_id WHERE products.category = 'Skincare';
Identify the total quantity of products in circulation that are made from recycled materials across all suppliers.
CREATE TABLE Supplier_Products (supplier_id INT,product_id INT,is_recycled BOOLEAN); INSERT INTO Supplier_Products (supplier_id,product_id,is_recycled) VALUES (1,100,true),(2,101,false),(3,102,true),(4,103,false),(5,104,true); CREATE TABLE Products (product_id INT,quantity_in_stock INT); INSERT INTO Products (product_i...
SELECT SUM(quantity_in_stock) as total_recycled_quantity FROM Products INNER JOIN Supplier_Products ON Products.product_id = Supplier_Products.product_id WHERE Supplier_Products.is_recycled = true;
What is the average CO2 emission of products in the Clothing category, grouped by brand?
CREATE TABLE products (product_id INT,category VARCHAR(255),brand VARCHAR(255),co2_emission INT); INSERT INTO products (product_id,category,brand,co2_emission) VALUES (1,'Clothing','BrandA',5);
SELECT brand, AVG(co2_emission) AS avg_co2_emission FROM products WHERE category = 'Clothing' GROUP BY brand;
What is the total waste generation in the residential sector in the state of Texas in 2022?
CREATE TABLE waste_generation_total (state varchar(255),sector varchar(255),year int,total_waste float); INSERT INTO waste_generation_total (state,sector,year,total_waste) VALUES ('Texas','Residential',2022,2500000);
SELECT total_waste FROM waste_generation_total WHERE state = 'Texas' AND sector = 'Residential' AND year = 2022
Find the total oil and gas production for each platform in the Caribbean.
CREATE TABLE platform_production (platform VARCHAR(255),oil_production FLOAT,gas_production FLOAT);
SELECT platform, SUM(oil_production) AS total_oil_production, SUM(gas_production) AS total_gas_production FROM platform_production WHERE region = 'Caribbean' GROUP BY platform;
What is the average production cost of sustainable fabrics with a rating above 4?
CREATE TABLE fabric_costs (id INT,fabric_id INT,production_cost FLOAT); INSERT INTO fabric_costs (id,fabric_id,production_cost) VALUES (1,1,3.2),(2,2,4.1),(3,3,2.8),(4,4,3.9),(5,5,4.5),(6,6,2.5),(7,7,3.7),(8,8,3.6);
SELECT AVG(production_cost) FROM fabric_costs fc JOIN fabrics f ON fc.fabric_id = f.id WHERE f.sustainability_rating > 4;
Update accessibility table record where region is 'Asia' and year is 2018
CREATE TABLE accessibility (region VARCHAR(255),year INT,internet_penetration FLOAT,mobile_penetration FLOAT); INSERT INTO accessibility (region,year,internet_penetration,mobile_penetration) VALUES ('Africa',2016,0.25,0.45),('Asia',2017,0.42,0.78),('Europe',2018,0.78,0.91);
UPDATE accessibility SET internet_penetration = 0.45, mobile_penetration = 0.8 WHERE region = 'Asia' AND year = 2018;
What is the percentage of community development initiatives led by women in the 'rural_development' schema?
CREATE TABLE community_initiatives(id INT,leader_gender VARCHAR(50),completed INT); INSERT INTO community_initiatives VALUES (1,'Female',1),(2,'Male',0),(3,'Female',1);
SELECT (COUNT(*) FILTER (WHERE leader_gender = 'Female')) * 100.0 / COUNT(*) FROM community_initiatives;
List all donors who have donated in the last month
CREATE TABLE donor_dates (id INT,donation_date DATE);
SELECT d.name FROM donors d JOIN donations don ON d.id = don.donor_id JOIN donor_dates dd ON don.donation_date = dd.id WHERE dd.donation_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);
What is the average waste generation per capita in 2020 for each state?
CREATE TABLE waste_generation_per_capita(year INT,state VARCHAR(255),population INT,waste_quantity INT); INSERT INTO waste_generation_per_capita VALUES (2020,'California',40000000,1200000000),(2020,'Texas',30000000,900000000);
SELECT AVG(waste_quantity/population) AS avg_waste_per_capita, state FROM waste_generation_per_capita WHERE year = 2020 GROUP BY state;
Show all records from the sales table where the country is 'USA'
CREATE TABLE sales (id INT,product_id INT,quantity INT,price DECIMAL(5,2),country VARCHAR(50));
SELECT * FROM sales WHERE country = 'USA';
What was the average donation amount for each organization in Q2 2020?
CREATE TABLE DonationTransactions (TransactionID INT,DonorID INT,OrgID INT,DonationAmount DECIMAL,TransactionDate DATE); INSERT INTO DonationTransactions (TransactionID,DonorID,OrgID,DonationAmount,TransactionDate) VALUES (1,1,1,100.00,'2020-04-01'),(2,1,2,200.00,'2020-05-01'),(3,2,1,50.00,'2020-04-01');
SELECT OrgID, AVG(DonationAmount) as AvgDonationAmount FROM DonationTransactions WHERE QUARTER(TransactionDate) = 2 AND YEAR(TransactionDate) = 2020 GROUP BY OrgID;
What was the average production quantity (in metric tons) of Lanthanum in 2016?
CREATE TABLE production (element VARCHAR(10),year INT,quantity FLOAT); INSERT INTO production (element,year,quantity) VALUES ('Lanthanum',2015,5000),('Lanthanum',2016,6000),('Lanthanum',2017,7000),('Lanthanum',2018,8000),('Lanthanum',2019,9000);
SELECT AVG(quantity) FROM production WHERE element = 'Lanthanum' AND year = 2016;
Delete all posts with hashtags '#politics' or '#elections' from the 'news' network.
CREATE TABLE posts (id INT,user_id INT,timestamp DATETIME,content TEXT,hashtags TEXT,network VARCHAR(255)); INSERT INTO posts (id,user_id,timestamp,content,hashtags,network) VALUES (8,5,'2023-01-01 10:00:00','Political news of the day...','#politics','news'),(9,6,'2023-02-05 15:00:00','Election results are in!','#elect...
DELETE FROM posts WHERE hashtags LIKE '%#politics%' OR hashtags LIKE '%#elections%' AND network = 'news';
What is the minimum number of members in a union in Germany?
CREATE TABLE UnionMembers (id INT,union_name VARCHAR(50),country VARCHAR(50),member_count INT); INSERT INTO UnionMembers (id,union_name,country,member_count) VALUES (1,'United Steelworkers','USA',200000),(2,'UNITE HERE','USA',300000),(3,'TUC','UK',6000000),(4,'CUPE','Canada',650000),(5,'USW','Canada',120000),(6,'CGT','...
SELECT MIN(member_count) as min_members FROM UnionMembers WHERE country = 'Germany';
What is the total number of traditional art pieces by type and their average price?
CREATE TABLE TraditionalArts (id INT,type VARCHAR(255),price DECIMAL(10,2)); INSERT INTO TraditionalArts (id,type,price) VALUES (1,'Painting',500),(2,'Sculpture',800),(3,'Pottery',300);
SELECT type, COUNT(*), AVG(price) FROM TraditionalArts GROUP BY type;
Insert new records for a new ocean pollution control initiative into the 'PollutionControl' table
CREATE TABLE PollutionControl (id INT,name VARCHAR(50),location VARCHAR(50),start_date DATE,end_date DATE); INSERT INTO PollutionControl (id,name,location,start_date,end_date) VALUES (1,'Clean Caribbean Sea','Caribbean Sea','2021-01-01','2022-12-31');
INSERT INTO PollutionControl (id, name, location, start_date, end_date) VALUES (2, 'Pure Pacific Ocean', 'Pacific Ocean', '2022-04-01', '2023-03-31');
Which heritage sites had the most visitors in H1 2022, segregated by country?
CREATE TABLE Countries (CountryID INT,CountryName VARCHAR(50)); INSERT INTO Countries (CountryID,CountryName) VALUES (1,'Brazil'),(2,'South Africa'),(3,'India'); CREATE TABLE Sites (SiteID INT,CountryID INT,SiteName VARCHAR(50),Visitors INT); INSERT INTO Sites (SiteID,CountryID,SiteName,Visitors) VALUES (1,1,'Christ th...
SELECT C.CountryName, S.SiteName, SUM(S.Visitors) as TotalVisitors FROM Countries C INNER JOIN Sites S ON C.CountryID = S.CountryID WHERE MONTH(S.VisitDate) BETWEEN 1 AND 6 GROUP BY C.CountryName, S.SiteName ORDER BY TotalVisitors DESC;
List investment strategies with ESG scores between 70 and 85.
CREATE TABLE investment_strategies (strategy_id INT,sector VARCHAR(20),ESG_score FLOAT); INSERT INTO investment_strategies (strategy_id,sector,ESG_score) VALUES (101,'renewable_energy',77.5),(102,'sustainable_agriculture',82.3),(103,'green_transportation',70.1);
SELECT * FROM investment_strategies WHERE ESG_score > 70 AND ESG_score < 85;
What is the average GDP of countries in Africa?
CREATE TABLE gdp (country VARCHAR(50),region VARCHAR(50),gdp_value FLOAT); INSERT INTO gdp (country,region,gdp_value) VALUES ('Algeria','Africa',180.9),('Angola','Africa',124.2),('Benin','Africa',11.5),('Botswana','Africa',17.6),('Burkina Faso','Africa',13.9),('Burundi','Africa',3.4),('Cameroon','Africa',37.3),('Cape V...
SELECT AVG(gdp_value) FROM gdp WHERE region = 'Africa';
What is the total number of green buildings in 'GreenBuilding' table, in each state, and the corresponding percentage of total green buildings?
CREATE TABLE GreenBuilding (building_id INT,state VARCHAR(50),is_green BOOLEAN);
SELECT state, COUNT(building_id) as total_green_buildings, (COUNT(building_id) / (SELECT COUNT(building_id) FROM GreenBuilding)) * 100 as percentage_of_total FROM GreenBuilding WHERE is_green = 1 GROUP BY state;
Show the number of public and private schools in each city from the 'education_database'
CREATE TABLE cities (id INT PRIMARY KEY,name VARCHAR(255));CREATE TABLE schools (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255),city_id INT,FOREIGN KEY (city_id) REFERENCES cities(id)); INSERT INTO cities (id,name) VALUES (1,'Los Angeles'); INSERT INTO cities (id,name) VALUES (2,'San Francisco'); INSERT INTO sc...
SELECT cities.name as city_name, COUNT(CASE WHEN schools.type = 'public' THEN 1 ELSE NULL END) as public_school_count, COUNT(CASE WHEN schools.type = 'private' THEN 1 ELSE NULL END) as private_school_count FROM cities INNER JOIN schools ON cities.id = schools.city_id GROUP BY cities.name;
What is the average water consumption for each fabric type?
CREATE TABLE fabric_water_consumption (id INT PRIMARY KEY,fabric VARCHAR(20),water_consumption DECIMAL(5,2));
SELECT fabric, AVG(water_consumption) FROM fabric_water_consumption GROUP BY fabric;
How many policyholders are above 65 years old in 'rural' regions?
CREATE TABLE policyholders (id INT,age INT,region VARCHAR(10));
SELECT COUNT(*) FROM policyholders WHERE age > 65 AND region = 'rural';
What is the maximum budget for programs in California?
CREATE TABLE Programs (id INT,program TEXT,budget DECIMAL(10,2),state TEXT); INSERT INTO Programs (id,program,budget,state) VALUES (1,'Feeding the Hungry',5000.00,'CA'),(2,'Clothing Drive',3000.00,'CA'),(3,'Education',7000.00,'NY');
SELECT state, MAX(budget) FROM Programs GROUP BY state;
What is the average monthly water usage per household in the city of San Francisco for the past year?
CREATE TABLE household_water_usage (household_id INT,city VARCHAR(20),usage FLOAT,usage_date DATE); INSERT INTO household_water_usage (household_id,city,usage,usage_date) VALUES (1,'San Francisco',15.4,'2021-01-01'),(2,'San Francisco',12.6,'2021-01-02');
SELECT AVG(usage) FROM (SELECT household_id, city, usage, usage_date, ROW_NUMBER() OVER (PARTITION BY household_id, EXTRACT(MONTH FROM usage_date) ORDER BY usage_date DESC) rn FROM household_water_usage WHERE city = 'San Francisco' AND usage_date >= DATEADD(year, -1, CURRENT_DATE)) t WHERE rn = 1;
How many sustainable building projects have been completed in each state in the US, and what was the total cost of each project?
CREATE TABLE sustainable_projects (id INT,state VARCHAR(2),project_name VARCHAR(100),completion_date DATE,cost DECIMAL(10,2)); INSERT INTO sustainable_projects (id,state,project_name,completion_date,cost) VALUES (1,'CA','Green Building','2021-01-01',1000000.00),(2,'TX','Sustainable Construction','2020-12-15',800000.00)...
SELECT sp.state, COUNT(sp.id) as num_projects, SUM(sp.cost) as total_cost FROM sustainable_projects sp GROUP BY sp.state;
What are the names and total production quantities for all wells in the 'PRODUCTION_SUMMARY' view?
CREATE VIEW PRODUCTION_SUMMARY AS SELECT WELL_NAME,SUM(PRODUCTION_QTY) FROM GAS_WELLS GROUP BY WELL_NAME;
SELECT WELL_NAME, SUM(PRODUCTION_QTY) FROM PRODUCTION_SUMMARY;
What is the total revenue for public transportation in New York on weekdays?
CREATE TABLE nyc_bus (ride_id INT,fare DECIMAL(5,2),ride_date DATE); CREATE TABLE nyc_train (ride_id INT,fare DECIMAL(5,2),ride_date DATE); CREATE TABLE nyc_subway (ride_id INT,fare DECIMAL(5,2),ride_date DATE);
SELECT SUM(fare) FROM (SELECT fare FROM nyc_bus WHERE DAYOFWEEK(ride_date) BETWEEN 2 AND 6 UNION ALL SELECT fare FROM nyc_train WHERE DAYOFWEEK(ride_date) BETWEEN 2 AND 6 UNION ALL SELECT fare FROM nyc_subway WHERE DAYOFWEEK(ride_date) BETWEEN 2 AND 6) AS weekday_fares;
What is the total funding amount for companies founded by immigrants in the biotech sector?
CREATE TABLE funding_records (id INT,company_id INT,funding_amount INT,funding_date DATE); CREATE TABLE companies (id INT,name TEXT,industry TEXT,founding_date DATE,founder_immigrant TEXT);
SELECT SUM(funding_amount) FROM funding_records JOIN companies ON funding_records.company_id = companies.id WHERE companies.industry = 'Biotech' AND founder_immigrant = 'Yes';
List the names of all non-profits and the number of volunteers they have lost in the last year.
CREATE TABLE non_profit (id INT,name TEXT); INSERT INTO non_profit (id,name) VALUES (1,'Greenpeace'),(2,'Save the Children'),(3,'International Rescue Committee'); CREATE TABLE volunteers (id INT,name TEXT,non_profit_id INT,start_date DATE,end_date DATE); INSERT INTO volunteers (id,name,non_profit_id,start_date,end_date...
SELECT n.name, COUNT(v.id) as num_lost_volunteers FROM non_profit n INNER JOIN volunteers v ON n.id = v.non_profit_id WHERE v.end_date <= CURRENT_DATE AND v.end_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY n.id;
What is the average price of products in the 'Organic' category?
CREATE TABLE products (id INT,name VARCHAR(255),category VARCHAR(255),price DECIMAL(10,2)); INSERT INTO products (id,name,category,price) VALUES (1,'Nourishing Face Cream','Organic',25.99),(2,'Revitalizing Serum','Natural',34.99),(3,'Soothing Eye Cream','Organic',19.99);
SELECT AVG(price) FROM products WHERE category = 'Organic';
List the number of threat intelligence reports generated per month in 2021.
CREATE TABLE threat_intelligence (report_id INT,report_date DATE);
SELECT EXTRACT(MONTH FROM report_date) AS month, COUNT(*) FROM threat_intelligence WHERE YEAR(report_date) = 2021 GROUP BY month;
What is the average carbon price (USD) in the California carbon market for the years 2018 and 2019?
CREATE TABLE carbon_prices (year INT,price FLOAT); INSERT INTO carbon_prices (year,price) VALUES (2018,15.42),(2019,16.18),(2020,17.14);
SELECT AVG(price) FROM carbon_prices WHERE year IN (2018, 2019) AND year IS NOT NULL;
For each year, calculate the percentage of AI safety research papers published, rounded to two decimal places.
CREATE SCHEMA ai_safety; CREATE TABLE papers (year INT,title VARCHAR(50),abstract TEXT,published BOOLEAN); INSERT INTO papers (year,title,abstract,published) VALUES (2018,'Safe AI Research','This paper discusses the importance of safety in AI research...',true),(2019,'Robust AI Algorithms','This paper presents a new ap...
SELECT year, ROUND(100.0 * COUNT(*) / (SELECT COUNT(*) FROM ai_safety.papers WHERE published = true AND year <= t.year), 2) as paper_percentage FROM ai_safety.papers t WHERE published = true GROUP BY year;
What is the maximum price of vegan dishes in Mexican restaurants?
CREATE TABLE Restaurants (id INT,name VARCHAR(50),type VARCHAR(20)); INSERT INTO Restaurants (id,name,type) VALUES (1,'Green Garden','Vegan'); INSERT INTO Restaurants (id,name,type) VALUES (2,'Bistro Bella','Italian'); INSERT INTO Restaurants (id,name,type) VALUES (3,'Taqueria Tina','Mexican'); INSERT INTO Restaurants ...
SELECT MAX(price) FROM Menu WHERE vegan = true AND restaurant_id IN (SELECT id FROM Restaurants WHERE type LIKE '%Mexican%');
Which textile sourcing regions have the most productions for each fabric?
CREATE TABLE textile_sourcing (id INT PRIMARY KEY,fabric VARCHAR(255),supplier VARCHAR(255),region VARCHAR(255),production_date DATE);
SELECT fabric, region, COUNT(*) as production_count, RANK() OVER (PARTITION BY fabric ORDER BY COUNT(*) DESC) as production_rank FROM textile_sourcing GROUP BY fabric, region;
Who is the policy advocate for the 'Assistive Technology' program in the 'Florida' office?
CREATE TABLE office (office_id INT,office_state VARCHAR(50),program_name VARCHAR(50)); CREATE TABLE staff (staff_id INT,staff_name VARCHAR(50),role VARCHAR(50),program_name VARCHAR(50)); INSERT INTO office (office_id,office_state,program_name) VALUES (1,'Florida','Assistive Technology'); INSERT INTO staff (staff_id,sta...
SELECT staff_name FROM office o JOIN staff s ON o.office_state = s.program_name WHERE o.program_name = 'Assistive Technology' AND s.role = 'Policy Advocate';
What is the percentage change in virtual tour engagement for hotels in the 'Asia' region between Q2 and Q3 2022?
CREATE TABLE virtual_tours (id INT,hotel_id INT,region TEXT,quarter INT,engagement FLOAT);
SELECT region, (SUM(CASE WHEN quarter = 3 THEN engagement ELSE 0 END) - SUM(CASE WHEN quarter = 2 THEN engagement ELSE 0 END)) * 100.0 / SUM(CASE WHEN quarter = 2 THEN engagement ELSE 0 END) as q2_to_q3_change FROM virtual_tours WHERE region = 'Asia' GROUP BY region;
Delete all records in the Accommodations table for students with disability 'Visual Impairment'
CREATE TABLE Accommodations (AccommodationID INT PRIMARY KEY,Description VARCHAR(50),StudentID INT,Disability VARCHAR(20),FOREIGN KEY (StudentID) REFERENCES Students(StudentID));
DELETE FROM Accommodations WHERE Disability = 'Visual Impairment';
What is the total revenue generated from dishes in the 'Appetizer' category?
CREATE TABLE Sales (sale_id INT,menu_id INT,sale_date DATE,quantity INT,price DECIMAL(5,2)); INSERT INTO Sales (sale_id,menu_id,sale_date,quantity,price) VALUES (1,1,'2022-01-01',2,5.99),(2,2,'2022-01-02',1,7.99),(3,3,'2022-01-03',3,4.99),(4,4,'2022-01-04',4,6.99); CREATE TABLE Menus (menu_id INT,category VARCHAR(255),...
SELECT SUM(quantity * price) FROM Sales JOIN Menus ON Sales.menu_id = Menus.menu_id WHERE Menus.category = 'Appetizer';
Which day of the week had the highest number of visitors at the museum?
CREATE TABLE museum_visits (visit_id INT,visit_date DATE,num_visitors INT); INSERT INTO museum_visits (visit_id,visit_date,num_visitors) VALUES (1,'2022-06-01',500),(2,'2022-06-02',600),(3,'2022-06-03',700),(4,'2022-06-04',800),(5,'2022-06-05',550),(6,'2022-06-06',400),(7,'2022-06-07',350);
SELECT visit_date, num_visitors FROM museum_visits WHERE num_visitors = (SELECT MAX(num_visitors) FROM museum_visits);
What is the average number of likes on posts by users from the United States?
CREATE TABLE users (id INT,country VARCHAR(50)); INSERT INTO users (id,country) VALUES (1,'United States'),(2,'Canada'); CREATE TABLE posts (id INT,user_id INT,likes INT); INSERT INTO posts (id,user_id,likes) VALUES (1,1,100),(2,1,200),(3,2,150);
SELECT AVG(posts.likes) as avg_likes FROM posts JOIN users ON posts.user_id = users.id WHERE users.country = 'United States';
How many unique stops are there on each route?
CREATE TABLE RouteStops (RouteID INT,StopID INT); INSERT INTO RouteStops (RouteID,StopID) VALUES (3,9); INSERT INTO RouteStops (RouteID,StopID) VALUES (4,10);
SELECT RouteID, COUNT(DISTINCT StopID) AS StopCount FROM RouteStops GROUP BY RouteID;
What is the total number of defense contracts awarded in each country?
CREATE TABLE defense_contracts_by_country (id INT,contract_id VARCHAR(50),contract_amount DECIMAL(10,2),country VARCHAR(50));
SELECT country, COUNT(DISTINCT contract_id) AS num_contracts FROM defense_contracts_by_country GROUP BY country;
How many podcast episodes were hosted by underrepresented hosts in the last year?
CREATE TABLE Podcasts (episode_id INT,title VARCHAR(255),host_name VARCHAR(50),publication_date DATE); INSERT INTO Podcasts (episode_id,title,host_name,publication_date) VALUES (1,'Podcast1','John Doe','2021-01-01'),(2,'Podcast2','Jane Smith','2021-02-15'),(3,'Podcast3','Alice Johnson','2022-03-01');
SELECT COUNT(*) FROM Podcasts WHERE host_name IN ('Jane Smith', 'Alice Johnson') AND publication_date >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR);
List the network types with their average broadband speed, sorted from the lowest to the highest.
CREATE TABLE network_types (network VARCHAR(255),broadband_speed FLOAT); INSERT INTO network_types (network,broadband_speed) VALUES ('4G',50),('5G',150),('3G',40),('Fiber',300),('Cable',200);
SELECT network, AVG(broadband_speed) as avg_speed FROM network_types GROUP BY network ORDER BY avg_speed ASC;
How many research grants were awarded to the Physics department in 2020?
CREATE TABLE grants (id INT,department VARCHAR(255),year INT,amount DECIMAL(10,2)); INSERT INTO grants (id,department,year,amount) VALUES (1,'Physics',2020,50000),(2,'Physics',2019,75000),(3,'Chemistry',2020,60000);
SELECT COUNT(*) FROM grants WHERE department = 'Physics' AND year = 2020;
What is the total number of vulnerabilities found in the financial sector?
CREATE TABLE vulnerabilities (id INT,sector VARCHAR(255),vulnerability VARCHAR(255)); INSERT INTO vulnerabilities (id,sector,vulnerability) VALUES (1,'financial','SQL injection');
SELECT COUNT(*) FROM vulnerabilities WHERE sector = 'financial';
List the teams that have won more than 50% of their games.
CREATE TABLE games (game_id INT,team VARCHAR(50),position VARCHAR(50),wins INT);
SELECT team FROM (SELECT team, SUM(wins) AS wins, COUNT(*) AS total_games FROM games GROUP BY team) AS subquery WHERE wins / total_games > 0.5;
Insert new media ethics records for the last quarter
CREATE TABLE media_ethics (id INT,ethics_topic VARCHAR(255),published_date DATE);
INSERT INTO media_ethics (id, ethics_topic, published_date) VALUES (1, ' sourcing', '2022-04-01'), (2, 'bias in reporting', '2022-05-15');
Delete all records from the 'artifacts' table that are not marked as fragile
CREATE TABLE artifacts (id INT PRIMARY KEY,name TEXT,site_id INT,is_fragile BOOLEAN);
DELETE FROM artifacts WHERE is_fragile = FALSE;
What is the average height of all wind turbines in Oklahoma?
CREATE TABLE wind_turbines (turbine_id TEXT,turbine_height INT,turbine_state TEXT); INSERT INTO wind_turbines (turbine_id,turbine_height,turbine_state) VALUES ('WT1',300,'Oklahoma'),('WT2',320,'Oklahoma'),('WT3',350,'Oklahoma'),('WT4',280,'Oklahoma');
SELECT AVG(turbine_height) FROM wind_turbines WHERE turbine_state = 'Oklahoma';
What is the total number of animals by region and year?
CREATE TABLE animal_population (region VARCHAR(50),population INT,year INT); INSERT INTO animal_population (region,population,year) VALUES ('Africa',500,2020),('Africa',510,2021),('Asia',800,2020),('Asia',820,2021),('Americas',300,2020),('Americas',310,2021);
SELECT region, year, SUM(population) OVER (PARTITION BY region, year) as total_population FROM animal_population ORDER BY region, year;
Which marine species have been observed in the Arctic and the Antarctic regions?
CREATE TABLE marine_species (id INT,species_name VARCHAR(50),common_name VARCHAR(50),region VARCHAR(20));INSERT INTO marine_species (id,species_name,common_name,region) VALUES (1,'Orcinus_orca','Killer Whale','Arctic');INSERT INTO marine_species (id,species_name,common_name,region) VALUES (2,'Balaenoptera_bonaerensis',...
SELECT species_name FROM marine_species WHERE region IN ('Arctic', 'Antarctic') GROUP BY species_name HAVING COUNT(DISTINCT region) = 2;
What is the maximum revenue generated in a single day for the "Impressionist Art" exhibition?
CREATE TABLE daily_revenue (date DATE,exhibition_id INT,revenue DECIMAL(5,2)); INSERT INTO daily_revenue (date,exhibition_id,revenue) VALUES ('2022-01-01',3,500.00),('2022-01-02',3,600.00),('2022-01-03',4,700.00);
SELECT MAX(revenue) FROM daily_revenue WHERE exhibition_id = 3;
Find the total number of fish farms in the state of Washington that have a stocking density above 30,000 per hectare.
CREATE TABLE fish_farms (id INT,state VARCHAR(255),stocking_density INT); INSERT INTO fish_farms (id,state,stocking_density) VALUES (1,'Washington',40000),(2,'Oregon',35000),(3,'California',32000);
SELECT COUNT(*) FROM fish_farms WHERE state = 'Washington' AND stocking_density > 30000;
What is the maximum number of cases handled by a single judge in the state of Texas in the year 2020?
CREATE TABLE cases (case_id INT,judge_id INT,state VARCHAR(20),year INT); INSERT INTO cases (case_id,judge_id,state,year) VALUES (1,1,'Texas',2020),(2,1,'Texas',2020),(3,2,'Texas',2019);
SELECT MAX(count) FROM (SELECT judge_id, COUNT(*) as count FROM cases WHERE state = 'Texas' AND year = 2020 GROUP BY judge_id) as subquery;
What is the ratio of Promethium to Holmium production in 2020?
CREATE TABLE Promethium_Production (year INT,production FLOAT); INSERT INTO Promethium_Production (year,production) VALUES (2015,300),(2016,330),(2017,360),(2018,390),(2019,420),(2020,450); CREATE TABLE Holmium_Production (year INT,production FLOAT); INSERT INTO Holmium_Production (year,production) VALUES (2015,600),(2...
SELECT production[year=2020]/(SELECT production FROM Holmium_Production WHERE year = 2020) FROM Promethium_Production WHERE year = 2020;
Which countries were involved in the Artemis missions?
CREATE TABLE Artemis_Missions (Mission_ID INT,Mission_Name VARCHAR(50),Country VARCHAR(50),Launch_Year INT,PRIMARY KEY (Mission_ID)); INSERT INTO Artemis_Missions (Mission_ID,Mission_Name,Country,Launch_Year) VALUES (1,'Artemis I','United States',2022),(2,'Artemis II','United States',2024),(3,'Artemis III','Japan',2025...
SELECT DISTINCT Country FROM Artemis_Missions;
How many emergency medical service calls were made in 'bronx' borough in January?
CREATE TABLE ems_calls (id INT,call_date DATE,borough VARCHAR(20)); INSERT INTO ems_calls (id,call_date,borough) VALUES (1,'2022-01-01','bronx'),(2,'2022-02-01','queens'),(3,'2022-01-15','bronx');
SELECT COUNT(*) FROM ems_calls WHERE borough = 'bronx' AND call_date BETWEEN '2022-01-01' AND '2022-01-31';
What is the total number of legal technology patents filed in the US from 2015 to 2020?
CREATE TABLE patents (patent_id INT,filed_date DATE,country VARCHAR(20)); INSERT INTO patents (patent_id,filed_date,country) VALUES (1,'2015-01-01','USA'),(2,'2020-12-31','USA');
SELECT COUNT(*) FROM patents WHERE country = 'USA' AND filed_date BETWEEN '2015-01-01' AND '2020-12-31';
What is the total number of cargo inspections for vessels with the 'Cargo' type?
CREATE TABLE Vessel (vessel_id INT,name VARCHAR(255),type VARCHAR(255),max_speed DECIMAL(5,2)); CREATE TABLE Inspection (inspection_id INT,vessel_id INT,inspection_type VARCHAR(255),inspection_time TIMESTAMP); CREATE TABLE Cargo (cargo_id INT,vessel_id INT,weight INT); INSERT INTO Vessel (vessel_id,name,type,max_speed)...
SELECT COUNT(*) FROM Inspection i INNER JOIN Vessel v ON i.vessel_id = v.vessel_id WHERE v.type = 'Cargo' AND i.inspection_type = 'Cargo';
Insert a new claim record into the claims table for policy number 7 with a claim amount of 2000 and claim date of '2019-05-15'
CREATE TABLE claims (claim_number INT,policy_number INT,claim_amount INT,claim_date DATE);
INSERT INTO claims (claim_number, policy_number, claim_amount, claim_date) VALUES (1, 7, 2000, '2019-05-15');
Update the amount of effective_altruism with id 1 to 2000000
CREATE TABLE effective_altruism (id INT PRIMARY KEY,name VARCHAR(100),amount INT,cause VARCHAR(20));
UPDATE effective_altruism SET amount = 2000000 WHERE id = 1;