instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Add a new eco-friendly factory with employee details.
CREATE TABLE factories (id INT,name VARCHAR(50),country VARCHAR(50),eco_friendly BOOLEAN,workers INT); INSERT INTO factories (id,name,country,eco_friendly,workers) VALUES (1,'Factory A','India',true,200),(2,'Factory B','Bangladesh',false,150);
INSERT INTO factories (id, name, country, eco_friendly, workers) VALUES (3, 'Green Mill', 'Vietnam', true, 300);
What is the minimum wage in factories in Africa?
CREATE TABLE FactoryWages (factory_id INT,wage DECIMAL); INSERT INTO FactoryWages (factory_id,wage) VALUES (1,5.00),(2,7.00),(3,4.00); CREATE TABLE Factories (factory_id INT,region VARCHAR(50)); INSERT INTO Factories (factory_id,region) VALUES (1,'Africa'),(2,'Europe'),(3,'Asia');
SELECT MIN(wage) FROM FactoryWages INNER JOIN Factories ON FactoryWages.factory_id = Factories.factory_id WHERE Factories.region = 'Africa';
What is the minimum wage in factories, by country, for the last 3 years?
CREATE SCHEMA ethical_fashion; CREATE TABLE factories (factory_id INT,country VARCHAR(255),wage FLOAT,year INT); INSERT INTO factories VALUES (1,'USA',9.0,2020),(2,'USA',9.5,2019),(3,'USA',8.5,2018),(4,'Canada',12.0,2020),(5,'Canada',11.5,2019),(6,'Canada',10.5,2018);
SELECT country, year, MIN(wage) OVER (PARTITION BY country) FROM ethical_fashion.factories WHERE year BETWEEN 2018 AND 2020 ORDER BY country, year;
How many textile factories are present in each region and their respective waste generation?
CREATE TABLE textile_factories (factory_name VARCHAR(255),region VARCHAR(255),waste_generation INT);
SELECT region, COUNT(*) as factory_count, SUM(waste_generation) as total_waste FROM textile_factories GROUP BY region;
Which Shariah-compliant financial institutions offer socially responsible loans in Southeast Asia?
CREATE TABLE financial_institutions (name TEXT,location TEXT,shariah_compliant BOOLEAN); CREATE TABLE loans (institution_name TEXT,loan_type TEXT,socially_responsible BOOLEAN); INSERT INTO financial_institutions (name,location,shariah_compliant) VALUES ('ABC Bank','Singapore',TRUE),('Islamic Finance Corporation','Malaysia',TRUE); INSERT INTO loans (institution_name,loan_type,socially_responsible) VALUES ('ABC Bank','Microfinance Loan',TRUE),('Islamic Finance Corporation','Green Loan',TRUE);
SELECT f.name FROM financial_institutions f INNER JOIN loans l ON f.name = l.institution_name WHERE f.shariah_compliant = TRUE AND l.socially_responsible = TRUE AND f.location LIKE 'Southeast%';
How many dairy-free desserts are available in France?
CREATE TABLE Desserts(id INT,name TEXT,is_dairy_free BOOLEAN,country TEXT); INSERT INTO Desserts(id,name,is_dairy_free,country) VALUES (1,'Fruit Salad',TRUE,'France'),(2,'Chocolate Mousse',FALSE,'France');
SELECT COUNT(*) FROM Desserts WHERE is_dairy_free = TRUE AND country = 'France';
Delete all shipments with item XYZ
CREATE TABLE shipments(id INT,item VARCHAR(255),load_date DATE); INSERT INTO shipments VALUES(1,'XYZ','2022-01-01'),(2,'ABC','2022-02-01');
DELETE FROM shipments WHERE item = 'XYZ';
List the top 2 countries with the most bioprocess engineering patents in 2021.
CREATE SCHEMA if not exists bioprocess;CREATE TABLE if not exists bioprocess.patents (id INT,year INT,country VARCHAR(255),patent_count INT); INSERT INTO bioprocess.patents (id,year,country,patent_count) VALUES (1,2020,'USA',1200),(2,2021,'Germany',900),(3,2021,'China',1500),(4,2020,'India',700),(5,2021,'Brazil',800);
SELECT country, SUM(patent_count) as total_patent_count FROM bioprocess.patents WHERE year = 2021 GROUP BY country ORDER BY total_patent_count DESC LIMIT 2;
Count the number of public hearings held in each district in the last 6 months
CREATE TABLE PublicHearings (HearingID INT,District TEXT,HearingDate DATE); INSERT INTO PublicHearings (HearingID,District,HearingDate) VALUES (1,'District1','2023-01-01'),(2,'District2','2023-02-15'),(3,'District1','2023-03-01');
SELECT District, COUNT(*) FROM PublicHearings WHERE HearingDate >= DATEADD(month, -6, GETDATE()) GROUP BY District;
What was the average funding for 'Climate Change' initiatives provided by the US in 2021?
CREATE TABLE USFunding (Funder VARCHAR(50),Sector VARCHAR(50),FundingAmount NUMERIC(15,2),Year INT); INSERT INTO USFunding (Funder,Sector,FundingAmount,Year) VALUES ('US','Climate Change',450000,2021),('US','Climate Change',500000,2021),('US','Climate Change',350000,2021);
SELECT AVG(FundingAmount) FROM USFunding WHERE Sector = 'Climate Change' AND Year = 2021 AND Funder = 'US';
How many solar power projects were completed in California since 2015 with a budget over $5 million?
CREATE TABLE projects (id INT,state VARCHAR(20),year_completed INT,budget FLOAT,project_type VARCHAR(20)); INSERT INTO projects (id,state,year_completed,budget,project_type) VALUES (1,'California',2014,4000000,'Wind'),(2,'California',2016,6000000,'Solar'),(3,'California',2017,3000000,'Solar'),(4,'California',2018,7000000,'Wind');
SELECT COUNT(*) FROM projects WHERE state = 'California' AND year_completed >= 2015 AND project_type = 'Solar' AND budget > 5000000;
Calculate the total revenue of virtual tourism events in the United States.
CREATE TABLE events (id INT,name TEXT,country TEXT,type TEXT,revenue INT); INSERT INTO events (id,name,country,type,revenue) VALUES (1,'Virtual Tourism New York','USA','virtual',30000),(2,'Virtual Tourism Los Angeles','USA','virtual',40000);
SELECT SUM(revenue) FROM events WHERE country = 'USA' AND type = 'virtual';
Count the number of indigenous communities in each Arctic country.
CREATE TABLE indigenous_communities (id INT,community_name VARCHAR,country VARCHAR);
SELECT country, COUNT(DISTINCT community_name) as community_count FROM indigenous_communities GROUP BY country;
What is the minimum age of patients who received therapy in Colorado?
CREATE TABLE patients (patient_id INT,age INT,gender TEXT,treatment TEXT,state TEXT); INSERT INTO patients (patient_id,age,gender,treatment,state) VALUES (1,30,'Female','CBT','Texas'); INSERT INTO patients (patient_id,age,gender,treatment,state) VALUES (2,45,'Male','DBT','California'); INSERT INTO patients (patient_id,age,gender,treatment,state) VALUES (3,25,'Non-binary','Therapy','Washington'); INSERT INTO patients (patient_id,age,gender,treatment,state) VALUES (4,18,'Male','Therapy','Colorado');
SELECT MIN(age) FROM patients WHERE treatment = 'Therapy' AND state = 'Colorado';
What is the total budget of mental health campaigns launched in 'Northeast' region in 2022?
CREATE TABLE campaigns_2022 (campaign_id INT,name VARCHAR(50),budget INT,region VARCHAR(50)); INSERT INTO campaigns_2022 (campaign_id,name,budget,region) VALUES (1,'Hope Rises',10000,'Northeast'),(2,'Mindful Living',12000,'Northeast'),(3,'Emotional Wellbeing',15000,'Midwest');
SELECT SUM(budget) FROM campaigns_2022 WHERE region = 'Northeast';
What is the youngest age of a patient diagnosed with depression in 2021?
CREATE TABLE diagnoses (patient_id INT,age INT,diagnosis_name VARCHAR(50),diagnosis_date DATE); INSERT INTO diagnoses (patient_id,age,diagnosis_name,diagnosis_date) VALUES (6,22,'Depression','2021-08-18'); INSERT INTO diagnoses (patient_id,age,diagnosis_name,diagnosis_date) VALUES (7,35,'Depression','2021-12-11'); INSERT INTO diagnoses (patient_id,age,diagnosis_name,diagnosis_date) VALUES (8,42,'Depression','2021-05-03');
SELECT MIN(age) FROM diagnoses WHERE diagnosis_name = 'Depression' AND YEAR(diagnosis_date) = 2021;
What is the minimum cost of tunnel projects in the Central region?
CREATE TABLE InfrastructureProjects (id INT,name VARCHAR(100),region VARCHAR(50),project_type VARCHAR(50),cost FLOAT); INSERT INTO InfrastructureProjects (id,name,region,project_type,cost) VALUES (1,'Denver Tunnel','Central','tunnel',20000000);
SELECT MIN(cost) FROM InfrastructureProjects WHERE region = 'Central' AND project_type = 'tunnel';
Summarize the total number of eco-tourists who visited Japan, Thailand, and Indonesia in Q1 and Q2 of 2021
CREATE TABLE EcoTouristsQ1Q2 (country VARCHAR(255),quarter INT,eco_tourists INT); INSERT INTO EcoTouristsQ1Q2 (country,quarter,eco_tourists) VALUES ('Japan',1,1100000),('Japan',2,1300000),('Thailand',1,1500000),('Thailand',2,1700000),('Indonesia',1,1900000),('Indonesia',2,2100000);
SELECT country, SUM(eco_tourists) AS total_eco_tourists FROM EcoTouristsQ1Q2 WHERE country IN ('Japan', 'Thailand', 'Indonesia') AND quarter IN (1, 2) GROUP BY country;
Insert a new marine species record for the Mariana Trench with ID 4, species 'Angler Fish', location 'Mariana Trench', year 2019, and population 100.
CREATE TABLE marine_species_research (id INT,species TEXT,location TEXT,year INT,population INT);
INSERT INTO marine_species_research (id, species, location, year, population) VALUES (4, 'Angler Fish', 'Mariana Trench', 2019, 100);
List the top 3 most represented ethnicities in movies produced in the USA.
CREATE TABLE movies (title VARCHAR(255),production_country VARCHAR(64),lead_actor_ethnicity VARCHAR(64));
SELECT lead_actor_ethnicity, COUNT(*) AS count FROM movies WHERE production_country = 'USA' GROUP BY lead_actor_ethnicity ORDER BY count DESC LIMIT 3;
What is the average quantity of 'Local Greens' sold per day in the Southeast region?
CREATE TABLE Daily_Region_Sales(Date DATE,Region VARCHAR(20),Menu_Item VARCHAR(30),Quantity INT); INSERT INTO Daily_Region_Sales(Date,Region,Menu_Item,Quantity) VALUES('2022-01-01','Southeast','Local Greens',10),('2022-01-02','Southeast','Local Greens',15);
SELECT AVG(Quantity) as Average_Quantity FROM Daily_Region_Sales WHERE Menu_Item = 'Local Greens' AND Region = 'Southeast';
What are the total copper exports and CO2 emissions from Chile between 2016 and 2018?
CREATE TABLE chile_copper_export (year INT,export_amount FLOAT); INSERT INTO chile_copper_export (year,export_amount) VALUES (2016,15000.0),(2017,16000.0),(2018,17000.0); CREATE TABLE chile_co2_emission (year INT,emission FLOAT); INSERT INTO chile_co2_emission (year,emission) VALUES (2016,100.0),(2017,105.0),(2018,110.0);
SELECT SUM(chile_copper_export.export_amount), SUM(chile_co2_emission.emission) FROM chile_copper_export INNER JOIN chile_co2_emission ON chile_copper_export.year = chile_co2_emission.year WHERE chile_copper_export.year BETWEEN 2016 AND 2018;
What is the average productivity of miners in Australia, and what is the total production volume of the mining companies they work for?
CREATE TABLE miners (miner_id INT,miner_name TEXT,company_id INT,productivity INT); CREATE TABLE mining_companies (company_id INT,company_name TEXT,production_volume INT); INSERT INTO miners (miner_id,miner_name,company_id,productivity) VALUES (1,'Mike Brown',1,10),(2,'Sarah Lee',1,12),(3,'Tom White',2,15); INSERT INTO mining_companies (company_id,company_name,production_volume) VALUES (1,'XYZ Mining',500),(2,'ABC Mining',700);
SELECT AVG(miners.productivity), SUM(mining_companies.production_volume) FROM miners INNER JOIN mining_companies ON miners.company_id = mining_companies.company_id WHERE miners.miner_name LIKE '%Australia%';
Which mining operations have a higher than average environmental impact?
CREATE TABLE mining_operations (operation_id INT,operation_name VARCHAR(50),environmental_impact DECIMAL(5,2)); INSERT INTO mining_operations (operation_id,operation_name,environmental_impact) VALUES (1,'Operation A',3.2),(2,'Operation B',4.5),(3,'Operation C',2.9);
SELECT operation_name FROM mining_operations WHERE environmental_impact > (SELECT AVG(environmental_impact) FROM mining_operations);
What is the total number of broadband customers and the total connection speed in Mbps for each region in 2021?
CREATE TABLE subscribers (id INT,service VARCHAR(10),region VARCHAR(10)); INSERT INTO subscribers (id,service,region) VALUES (1,'broadband','Northwest'),(2,'mobile','Northwest'),(3,'broadband','Southwest'),(4,'mobile','Southwest'); CREATE TABLE speeds (subscriber_id INT,connection_speed INT,year INT); INSERT INTO speeds (subscriber_id,connection_speed,year) VALUES (1,550,2021),(1,555,2022),(2,450,2021),(2,460,2022),(3,650,2021),(3,660,2022),(4,400,2021),(4,410,2022);
SELECT subscribers.region, COUNT(subscribers.id) AS total_customers, SUM(speeds.connection_speed) AS total_speed FROM subscribers JOIN speeds ON subscribers.id = speeds.subscriber_id WHERE subscribers.service = 'broadband' AND speeds.year = 2021 GROUP BY subscribers.region;
What is the total number of subscribers in each product category?
CREATE TABLE product_subscribers (subscriber_id INT,name VARCHAR(255),region VARCHAR(255),mobile_number VARCHAR(20),broadband_speed DECIMAL(10,2),product_category VARCHAR(255));
SELECT product_category, COUNT(*) AS num_subscribers FROM product_subscribers GROUP BY product_category;
What is the minimum streaming revenue for users in Japan?
CREATE TABLE japan_streaming (user_id INT,revenue DECIMAL(10,2)); INSERT INTO japan_streaming (user_id,revenue) VALUES (1,12.99),(2,9.99),(3,15.99);
SELECT MIN(revenue) AS min_revenue FROM japan_streaming;
Who are the top 3 donors in 2022?
CREATE TABLE donations (donor_id INT,donation_amount DECIMAL(10,2),donation_date DATE); INSERT INTO donations (donor_id,donation_amount,donation_date) VALUES (1,50.00,'2021-01-01'),(2,100.00,'2021-02-14'),(3,550.00,'2022-01-01'),(4,300.00,'2022-02-12'),(5,800.00,'2022-12-31');
SELECT donor_id, SUM(donation_amount) as total_donated FROM donations WHERE YEAR(donation_date) = 2022 GROUP BY donor_id ORDER BY total_donated DESC LIMIT 3;
Show esports events with a prize pool between the maximum and minimum prize pools in the 'Esports_Events_NA' table.
CREATE TABLE Esports_Events (EventID INT,EventName VARCHAR(100),Location VARCHAR(100),PrizePool DECIMAL(10,2)); INSERT INTO Esports_Events (EventID,EventName,Location,PrizePool) VALUES (1,'EventA','USA',100000),(2,'EventB','Canada',150000),(3,'EventC','Mexico',75000); CREATE TABLE Esports_Events_NA (EventID INT,EventName VARCHAR(100),Location VARCHAR(100),PrizePool DECIMAL(10,2)); INSERT INTO Esports_Events_NA (EventID,EventName,Location,PrizePool) VALUES (1,'EventX','USA',20000),(2,'EventY','Canada',25000),(3,'EventZ','Mexico',18000);
SELECT * FROM Esports_Events WHERE PrizePool BETWEEN (SELECT MAX(PrizePool) FROM Esports_Events_NA) AND (SELECT MIN(PrizePool) FROM Esports_Events_NA);
What is the minimum age of players who play multiplayer games?
CREATE TABLE Players (PlayerID INT,Age INT,MaxPlayers INT); INSERT INTO Players (PlayerID,Age,MaxPlayers) VALUES (1,20,5);
SELECT MIN(Age) FROM Players WHERE MaxPlayers > 1;
Find the number of co-owned properties sold in each neighborhood in the last year.
CREATE TABLE Neighborhoods (NeighborhoodID INT,NeighborhoodName VARCHAR(255)); CREATE TABLE Properties (PropertyID INT,NeighborhoodID INT,Sold DATE,CoOwned BOOLEAN);
SELECT NeighborhoodName, COUNT(*) AS CoOwnedPropertiesSoldCount FROM Properties JOIN Neighborhoods ON Properties.NeighborhoodID = Neighborhoods.NeighborhoodID WHERE CoOwned = 1 AND Sold >= DATEADD(year, -1, CURRENT_TIMESTAMP) GROUP BY NeighborhoodName;
What is the total CO2 emissions (in metric tons) of the carbon offset program 'Plant a Tree'?
CREATE TABLE carbon_offset (id INT,name TEXT,co2_emissions FLOAT); INSERT INTO carbon_offset (id,name,co2_emissions) VALUES (1,'Plant a Tree',1000.0),(2,'Recycle Electronics',1500.0);
SELECT SUM(co2_emissions) FROM carbon_offset WHERE name = 'Plant a Tree';
Display the number of sustainable menu items for each restaurant and the percentage of the menu that is sustainable.
CREATE TABLE Restaurants (RestaurantID int,RestaurantName varchar(255)); CREATE TABLE MenuItems (MenuID int,MenuName varchar(255),RestaurantID int,IsSustainable bit);
SELECT R.RestaurantName, COUNT(MI.IsSustainable) as SustainableCount, (COUNT(MI.IsSustainable) * 100.0 / (SELECT COUNT(*) FROM MenuItems WHERE RestaurantID = R.RestaurantID)) as SustainablePercentage FROM Restaurants R INNER JOIN MenuItems MI ON R.RestaurantID = MI.RestaurantID GROUP BY R.RestaurantID;
Add a new product sourced from a circular supply chain
CREATE TABLE products (product_id INT,product_name VARCHAR(50),sourcing_type VARCHAR(50));
INSERT INTO products (product_id, product_name, sourcing_type) VALUES (4, 'Product D', 'Circular');
Create a table named 'products'
CREATE TABLE products(product_id INT PRIMARY KEY,name VARCHAR(255),supplier_id INT,quantity_sold INT,price DECIMAL(5,2));
CREATE TABLE products( product_id INT PRIMARY KEY, name VARCHAR(255), supplier_id INT, quantity_sold INT, price DECIMAL(5,2));
What is the average price of products in the 'Electronics' category that are produced using circular supply chains?
CREATE TABLE products (product_id INT,product_name TEXT,category TEXT,is_circular_supply_chain BOOLEAN,price DECIMAL); INSERT INTO products (product_id,product_name,category,is_circular_supply_chain,price) VALUES (1,'Refurbished Smartphone','Electronics',TRUE,299.99),(2,'Reconditioned Laptop','Electronics',TRUE,599.99),(3,'New Headphones','Electronics',FALSE,99.99);
SELECT AVG(price) FROM products WHERE category = 'Electronics' AND is_circular_supply_chain = TRUE;
What is the total number of space missions launched by Japan and the USA?
CREATE TABLE space_missions (id INT,mission_name VARCHAR(255),launch_country VARCHAR(255),launch_date DATE); INSERT INTO space_missions (id,mission_name,launch_country,launch_date) VALUES (1,'Sputnik 1','Russia','1957-10-04'); INSERT INTO space_missions (id,mission_name,launch_country,launch_date) VALUES (2,'Explorer 1','USA','1958-01-31'); INSERT INTO space_missions (id,mission_name,launch_country,launch_date) VALUES (3,'Hayabusa','Japan','2003-05-09');
SELECT SUM(cnt) FROM (SELECT launch_country, COUNT(*) AS cnt FROM space_missions WHERE launch_country IN ('Japan', 'USA') GROUP BY launch_country) AS subquery;
What is the maximum number of fans that attended a single game in the MLB?
CREATE TABLE attendance (id INT,team VARCHAR(50),location VARCHAR(50),fans INT); INSERT INTO attendance (id,team,location,fans) VALUES (1,'TeamA','Home',1000),(2,'TeamA','Away',800),(3,'TeamB','Home',1200),(4,'TeamB','Away',1500),(5,'TeamC','Home',2000),(6,'TeamC','Away',1800);
SELECT MAX(fans) FROM attendance;
Find the number of unique IP addresses associated with malware activity in the 'Asia-Pacific' region in the past week.
CREATE TABLE malware_activity_v2 (id INT,ip_address VARCHAR(15),malware_type VARCHAR(255),region VARCHAR(100),last_seen DATE); INSERT INTO malware_activity_v2 (id,ip_address,malware_type,region,last_seen) VALUES (4,'10.0.0.2','wannacry','Asia-Pacific','2022-01-12'),(5,'10.0.0.3','ransomware','Asia-Pacific','2022-01-15'),(6,'10.0.0.4','virut','Asia-Pacific','2022-01-18');
SELECT COUNT(DISTINCT ip_address) FROM malware_activity_v2 WHERE region = 'Asia-Pacific' AND last_seen >= DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK);
What is the average severity of vulnerabilities found in the 'Network' section for the last month?
CREATE TABLE vulnerabilities (id INT,section VARCHAR(50),severity INT,vulnerability_date DATE); INSERT INTO vulnerabilities (id,section,severity,vulnerability_date) VALUES (1,'Network',7,'2022-01-01'),(2,'Application',5,'2022-01-02');
SELECT AVG(severity) as avg_severity FROM vulnerabilities WHERE section = 'Network' AND vulnerability_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);
How many electric vehicles does each manufacturer have in the 'vehicle_data' table?
CREATE TABLE vehicle_data (id INT PRIMARY KEY,make VARCHAR(50),model VARCHAR(50),vehicle_type VARCHAR(50),is_ev BOOLEAN,registration_date DATE); INSERT INTO vehicle_data (id,make,model,vehicle_type,is_ev,registration_date) VALUES (1,'Tesla','Model 3','Sedan',true,'2020-01-01'); INSERT INTO vehicle_data (id,make,model,vehicle_type,is_ev,registration_date) VALUES (2,'Nissan','Leaf','Hatchback',true,'2019-05-15');
SELECT make, COUNT(*) FROM vehicle_data WHERE is_ev = true GROUP BY make;
What is the total revenue for each retail store in the Northern region?
CREATE TABLE sales (store_id INT,region TEXT,revenue INT); INSERT INTO sales (store_id,region,revenue) VALUES (1,'Northern',25000),(2,'Northern',30000),(3,'Northern',20000);
SELECT store_id, SUM(revenue) as total_revenue FROM sales WHERE region = 'Northern' GROUP BY store_id;
List the policy numbers, claim amounts, and claim dates for policies that have more than two claims and the total claim amount exceeds $5000
CREATE TABLE policies (policy_number INT);CREATE TABLE claims (claim_id INT,policy_number INT,claim_amount DECIMAL(10,2),claim_date DATE);
SELECT p.policy_number, c.claim_amount, c.claim_date FROM policies p INNER JOIN claims c ON p.policy_number = c.policy_number GROUP BY p.policy_number, c.claim_amount, c.claim_date HAVING COUNT(c.claim_id) > 2 AND SUM(c.claim_amount) > 5000;
List all unique cargo types and their respective total weights for vessels 'X' and 'Y' from the 'cargo_tracking' and 'vessels' tables
CREATE TABLE cargo_tracking (cargo_id INT,cargo_type TEXT,weight FLOAT,vessel_id INT); CREATE TABLE vessels (vessel_id INT,vessel_name TEXT);
SELECT c.cargo_type, SUM(c.weight) as total_weight FROM cargo_tracking c INNER JOIN vessels v ON c.vessel_id = v.vessel_id WHERE v.vessel_name IN ('X', 'Y') GROUP BY c.cargo_type;
Identify the recycling rates for all plastic waste in the year 2020 across different regions.
CREATE TABLE waste_type (waste_type VARCHAR(50)); INSERT INTO waste_type (waste_type) VALUES ('Plastic'),('Paper'),('Glass'); CREATE TABLE recycling_rates (waste_type VARCHAR(50),region VARCHAR(50),recycling_rate DECIMAL(5,2)); INSERT INTO recycling_rates (waste_type,region,recycling_rate) VALUES ('Plastic','North',0.35),('Plastic','South',0.40),('Plastic','East',0.45),('Plastic','West',0.50);
SELECT wt.waste_type, r.region, r.recycling_rate FROM recycling_rates r JOIN waste_type wt ON r.waste_type = wt.waste_type WHERE wt.waste_type = 'Plastic' AND r.year = 2020;
What is the correlation between rainfall and water consumption in Phoenix?
CREATE TABLE Rainfall (Year INT,Rainfall FLOAT); INSERT INTO Rainfall (Year,Rainfall) VALUES (2017,200.5),(2018,190.2); CREATE TABLE Household_Water_Usage (Household_ID INT,City VARCHAR(20),Year INT,Water_Consumption FLOAT); INSERT INTO Household_Water_Usage (Household_ID,City,Year,Water_Consumption) VALUES (1,'Phoenix',2017,130.5),(2,'Phoenix',2018,120.2);
SELECT CORR(Rainfall, Water_Consumption) FROM Rainfall, Household_Water_Usage WHERE Rainfall.Year = Household_Water_Usage.Year AND City = 'Phoenix';
What is the average salary of employees in the Manufacturing department?
CREATE TABLE Employees (EmployeeID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50),Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,Salary) VALUES (3,'Mike','Smith','Manufacturing',78000.00),(4,'Lucy','Johnson','Testing',82000.00);
SELECT AVG(Salary) AS AvgSalary FROM Employees WHERE Department = 'Manufacturing';
What is the ratio of community education programs to animals in each habitat type?
CREATE TABLE education (id INT,type VARCHAR(50),programs INT); INSERT INTO education (id,type,programs) VALUES (1,'Forest',10),(2,'Savannah',5),(3,'Wetlands',15); CREATE TABLE animal_population (id INT,type VARCHAR(50),animals INT); INSERT INTO animal_population (id,type,animals) VALUES (1,'Forest',200),(2,'Savannah',300),(3,'Wetlands',400);
SELECT a.type, programs/animals as ratio FROM education a JOIN animal_population b ON a.type = b.type;
What is the total funding received by the 'Theater' program in the 'Funding' table?
CREATE TABLE Funding (id INT,program VARCHAR(50),location VARCHAR(50),date DATE,amount DECIMAL(10,2)); INSERT INTO Funding (id,program,location,date,amount) VALUES (1,'Theater','California','2022-01-01',10000);
SELECT SUM(amount) FROM Funding WHERE program = 'Theater';
What was the total revenue from art classes by age group in Q3 2022?
CREATE TABLE ArtClasses (ClassID INT,AgeGroup VARCHAR(50),StartDate DATE,EndDate DATE,Price DECIMAL(10,2)); INSERT INTO ArtClasses (ClassID,AgeGroup,StartDate,EndDate,Price) VALUES (1,'5-10','2022-07-01','2022-07-31',100.00),(2,'11-15','2022-07-01','2022-07-31',150.00);
SELECT SUM(Price) AS TotalRevenue, AgeGroup FROM ArtClasses WHERE MONTH(StartDate) BETWEEN 7 AND 9 GROUP BY AgeGroup;
How many TV shows were released by network per year?
CREATE TABLE tv_shows (id INT,title VARCHAR(100),network VARCHAR(100),release_year INT); INSERT INTO tv_shows (id,title,network,release_year) VALUES (1,'Show1','Network1',2021),(2,'Show2','Network2',2021),(3,'Show3','Network1',2020);
SELECT network, release_year, COUNT(*) as shows_released FROM tv_shows GROUP BY network, release_year;
How many cultivation licenses have been revoked in Massachusetts in the last month?
CREATE TABLE Licenses (id INT,type TEXT,issue_date DATE,revoke_date DATE);
SELECT COUNT(*) FROM Licenses WHERE type = 'cultivation' AND revoke_date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH);
How many new raw materials were added in the 'Plastic Production' department in the last week?
CREATE TABLE Raw_Materials (raw_material_id INT,department VARCHAR(20),raw_material_description VARCHAR(100),supply_date DATE);
SELECT COUNT(*) FROM Raw_Materials WHERE department = 'Plastic Production' AND supply_date >= DATE_SUB(CURDATE(), INTERVAL 1 WEEK);
What is the total cost for each project per month?
create table CostData (Project varchar(255),Cost int,Timestamp datetime); insert into CostData values ('Project1',1000,'2022-01-01 00:00:00'),('Project2',1500,'2022-01-02 00:00:00'),('Project1',1200,'2022-01-03 00:00:00');
select Project, DATE_PART('month', Timestamp) as Month, SUM(Cost) as TotalCost from CostData group by Project, Month;
List all climate mitigation projects in Oceania and their respective end dates.
CREATE TABLE climate_mitigation (project_name VARCHAR(255),region VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO climate_mitigation (project_name,region,start_date,end_date) VALUES ('Coral Reef Restoration','Oceania','2020-01-01','2022-12-31'); INSERT INTO climate_mitigation (project_name,region,start_date,end_date) VALUES ('Mangrove Planting','Oceania','2019-06-15','2021-05-31');
SELECT project_name, end_date FROM climate_mitigation WHERE region = 'Oceania';
What is the average investment in climate finance projects in East Asia in the last 5 years?
CREATE TABLE climate_finance_projects (project_id INT,project_type VARCHAR(50),region VARCHAR(50),investment_amount FLOAT,investment_year INT); INSERT INTO climate_finance_projects (project_id,project_type,region,investment_amount,investment_year) VALUES (1,'climate finance','East Asia',3000000,2017),(2,'climate finance','East Asia',3500000,2018),(3,'climate finance','East Asia',4000000,2019),(4,'climate finance','East Asia',4500000,2020),(5,'climate finance','East Asia',5000000,2021),(6,'climate finance','South East Asia',2000000,2018),(7,'climate finance','East Asia',5500000,2017),(8,'climate finance','East Asia',6000000,2016);
SELECT AVG(investment_amount) FROM climate_finance_projects WHERE region = 'East Asia' AND investment_year BETWEEN 2017 AND 2021;
What is the minimum temperature increase in Europe in any year since 2000, and what is the year in which it occurred?
CREATE TABLE temperature_data (id INT,region VARCHAR(255),year INT,temperature FLOAT); INSERT INTO temperature_data (id,region,year,temperature) VALUES (1,'Europe',2000,12.3);
SELECT region, MIN(temperature) AS min_temp, year FROM temperature_data WHERE region = 'Europe' GROUP BY region, year HAVING min_temp = (SELECT MIN(temperature) FROM temperature_data WHERE region = 'Europe');
What is the total number of electric vehicles sold in Africa per year since 2015?
CREATE TABLE VehicleSales (year INT,continent VARCHAR(255),vehicle_type VARCHAR(255),sales INT); INSERT INTO VehicleSales (year,continent,vehicle_type,sales) VALUES (2015,'Africa','Electric',100),(2016,'Africa','Electric',200),(2017,'Africa','Electric',300),(2018,'Africa','Electric',400),(2019,'Africa','Electric',500),(2020,'Africa','Electric',600);
SELECT year, SUM(sales) AS electric_vehicle_sales FROM VehicleSales WHERE continent = 'Africa' AND vehicle_type = 'Electric' GROUP BY year;
Find the maximum Series B funding amount in the E-Learning sector.
CREATE TABLE funding (id INT,startup_id INT,round TEXT,amount FLOAT);
SELECT MAX(amount) FROM funding WHERE round = 'Series B' AND industry = 'E-Learning';
Find the number of companies founded by women in each country.
CREATE TABLE Companies (id INT,name TEXT,industry TEXT,country TEXT,founder_gender TEXT); INSERT INTO Companies (id,name,industry,country,founder_gender) VALUES (1,'Acme Inc','Tech','USA','Female'); INSERT INTO Companies (id,name,industry,country,founder_gender) VALUES (2,'Beta Corp','Biotech','Canada','Male'); INSERT INTO Companies (id,name,industry,country,founder_gender) VALUES (3,'Delta LLC','Fintech','USA','Female'); INSERT INTO Companies (id,name,industry,country,founder_gender) VALUES (4,'Epsilon Ltd','Renewable Energy','UK','Male');
SELECT country, COUNT(*) as num_female_founded FROM Companies WHERE founder_gender = 'Female' GROUP BY country;
What is the average funding amount for companies founded by women?
CREATE TABLE companies (id INT,name TEXT,founded_date DATE,founder_gender TEXT); INSERT INTO companies (id,name,founded_date,founder_gender) VALUES (1,'Acme Inc','2010-01-01','female'); INSERT INTO companies (id,name,founded_date,founder_gender) VALUES (2,'Beta Corp','2015-05-15','male');
SELECT AVG(funding_amount) FROM investments JOIN companies ON investments.company_id = companies.id WHERE companies.founder_gender = 'female';
What is the total funding for startups in the 'Software' industry founded before 2015?
CREATE TABLE startups(id INT,name TEXT,founded_year INT,industry TEXT,total_funding DECIMAL(10,2)); INSERT INTO startups (id,name,founded_year,industry,total_funding) VALUES (1,'Acme Inc',2010,'Tech',1500000.00); INSERT INTO startups (id,name,founded_year,industry,total_funding) VALUES (2,'Beta Corp',2015,'Biotech',2000000.00); INSERT INTO startups (id,name,founded_year,industry,total_funding) VALUES (3,'Gamma Startup',2018,'Software',500000.00);
SELECT SUM(total_funding) FROM startups WHERE industry = 'Software' AND founded_year < 2015;
List all accommodation requests with their approval status and date approved, if applicable, for students with visual impairments?
CREATE TABLE Students (StudentID int,StudentName varchar(50),DisabilityType varchar(50)); INSERT INTO Students (StudentID,StudentName,DisabilityType) VALUES (1,'John Doe','Visual Impairment'),(2,'Jane Smith','Mobility Impairment'),(3,'Michael Johnson','Learning Disability'); CREATE TABLE AccommodationRequests (RequestID int,StudentID int,RequestDate date,ApprovalStatus varchar(50)); INSERT INTO AccommodationRequests (RequestID,StudentID,RequestDate,ApprovalStatus) VALUES (1,1,'2021-01-01','Approved'),(2,1,'2021-02-01','Pending'),(3,2,'2021-03-01','Approved'),(4,3,'2021-04-01','Denied');
SELECT StudentName, DisabilityType, ApprovalStatus, RequestDate as DateApproved FROM AccommodationRequests AR JOIN Students S ON AR.StudentID = S.StudentID WHERE DisabilityType = 'Visual Impairment' AND ApprovalStatus <> 'Pending';
What is the total budget allocated for disability support programs in the year 2025, ordered by the amount of budget allocated?
CREATE TABLE DisabilitySupportPrograms (ProgramID INT,ProgramName VARCHAR(255),Budget DECIMAL(10,2),Year INT); INSERT INTO DisabilitySupportPrograms (ProgramID,ProgramName,Budget,Year) VALUES (1,'Sign Language Interpretation',50000,2023),(2,'Assistive Technology',75000,2023),(3,'Accessible Transportation',120000,2023),(4,'Adaptive Equipment',60000,2024),(5,'Disability Awareness Training',80000,2024); INSERT INTO DisabilitySupportPrograms (ProgramID,ProgramName,Budget,Year) VALUES (6,'Inclusive Curriculum Development',90000,2025),(7,'Disability Advocacy',100000,2025),(8,'Accessible Housing',110000,2025);
SELECT ProgramName, Budget FROM DisabilitySupportPrograms WHERE Year = 2025 ORDER BY Budget DESC;
What is the maximum depth of marine species in the 'marine_species' table, grouped by their phylum?
CREATE TABLE marine_species (id INT,name VARCHAR(255),phylum VARCHAR(255),depth FLOAT); INSERT INTO marine_species (id,name,phylum,depth) VALUES (1,'Pacific salmon','Chordata',50.0),(2,'Hawaiian monk seal','Chordata',500.0),(3,'Sea anemone','Cnidaria',0.01);
SELECT phylum, MAX(depth) AS max_depth FROM marine_species GROUP BY phylum;
What is the total number of marine protected areas in each ocean basin?
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;
What is the average number of smart contracts developed per developer in Africa?
CREATE TABLE developers (id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO developers (id,name,country) VALUES (1,'Eve','Nigeria'),(2,'Frank','South Africa'),(3,'Grace','Egypt'); CREATE TABLE smart_contracts (id INT,name VARCHAR(50),developer_id INT); INSERT INTO smart_contracts (id,name,developer_id) VALUES (1,'SC1',1),(2,'SC2',1),(3,'SC3',2),(4,'SC4',3);
SELECT AVG(sc_per_dev) FROM (SELECT COUNT(*) as sc_per_dev FROM smart_contracts sc INNER JOIN developers d ON sc.developer_id = d.id GROUP BY d.id) as subquery;
What is the change in crime rate for each category, between this year and last year, for the same time period?
CREATE TABLE CrimeStatistics (ID INT,CrimeType VARCHAR(50),Date TIMESTAMP,Count INT); INSERT INTO CrimeStatistics (ID,CrimeType,Date,Count) VALUES (1,'Theft','2022-01-01 00:00:00',100),(2,'Vandalism','2022-01-01 00:00:00',50),(3,'Theft','2022-01-02 00:00:00',120),(4,'Vandalism','2022-01-02 00:00:00',60),(5,'Theft','2021-01-01 00:00:00',80),(6,'Vandalism','2021-01-01 00:00:00',40),(7,'Theft','2021-01-02 00:00:00',90),(8,'Vandalism','2021-01-02 00:00:00',45);
SELECT CrimeType, (SUM(Count) OVER (PARTITION BY CrimeType ORDER BY EXTRACT(YEAR FROM Date) ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING)) - SUM(Count) OVER (PARTITION BY CrimeType ORDER BY EXTRACT(YEAR FROM Date)) AS CrimeRateChange FROM CrimeStatistics WHERE Date BETWEEN DATE_TRUNC('year', CURRENT_DATE - INTERVAL '1 year') AND CURRENT_DATE;
Identify artists who created art pieces between 1850 and 1900.
CREATE TABLE art_timeline (id INT,artist_name VARCHAR(255),title VARCHAR(255),year INT); INSERT INTO art_timeline (id,artist_name,title,year) VALUES (1,'Gustav Klimt','The Kiss',1907),(2,'Claude Monet','Water Lilies',1899),(3,'Paul Cézanne','The Card Players',1892);
SELECT artist_name FROM art_timeline WHERE year BETWEEN 1850 AND 1900 GROUP BY artist_name HAVING COUNT(DISTINCT year) > 1;
Calculate the average unemployment rate for veterans in H1 2022
CREATE TABLE veteran_employment (quarter VARCHAR(10),total_veterans INT,unemployed_veterans INT);
SELECT AVG(unemployed_veterans/total_veterans) FROM veteran_employment WHERE quarter IN ('Q1 2022', 'Q2 2022');
What is the average account balance for clients in Asia in Q2 2022?
CREATE TABLE accounts (client_id INT,balance DECIMAL(10,2),country VARCHAR(50),account_date DATE); INSERT INTO accounts (client_id,balance,country,account_date) VALUES (1,12000.00,'India','2022-04-01'),(2,25000.00,'China','2022-05-15'),(3,18000.00,'Japan','2022-06-01');
SELECT AVG(balance) as avg_balance FROM accounts WHERE country IN ('India', 'China', 'Japan') AND account_date BETWEEN '2022-04-01' AND '2022-06-30';
List the top 3 ports with the highest total gross tonnage of container vessels.
CREATE TABLE Port (PortID INT,PortName VARCHAR(50),City VARCHAR(50),Country VARCHAR(50)); INSERT INTO Port (PortID,PortName,City,Country) VALUES (1,'Port of Los Angeles','Los Angeles','USA'); INSERT INTO Port (PortID,PortName,City,Country) VALUES (2,'Port of Rotterdam','Rotterdam','Netherlands'); CREATE TABLE Vessel (VesselID INT,VesselName VARCHAR(50),GrossTonnage INT,VesselType VARCHAR(50),PortID INT); INSERT INTO Vessel (VesselID,VesselName,GrossTonnage,VesselType,PortID) VALUES (1,'Ever Ace',235000,'Container',1); INSERT INTO Vessel (VesselID,VesselName,GrossTonnage,VesselType,PortID) VALUES (2,'Algeciras',128000,'Ro-Ro',2);
SELECT p.PortName, SUM(v.GrossTonnage) AS TotalGrossTonnage FROM Vessel v JOIN Port p ON v.PortID = p.PortID WHERE VesselType = 'Container' GROUP BY p.PortName ORDER BY TotalGrossTonnage DESC LIMIT 3;
Identify the total number of military personnel and their corresponding rank for each branch and country in the 'military_personnel' table, sorted by the total number of personnel in descending order.
CREATE TABLE military_personnel (id INT,branch VARCHAR(255),rank VARCHAR(255),country VARCHAR(255),personnel INT);
SELECT branch, country, SUM(personnel) as total_personnel FROM military_personnel GROUP BY branch, country ORDER BY total_personnel DESC;
What is the total number of cybersecurity incidents for each country?
CREATE TABLE cybersecurity_incidents (country TEXT,year INT,num_incidents INT); INSERT INTO cybersecurity_incidents (country,year,num_incidents) VALUES ('USA',2019,50000),('UK',2019,7000),('China',2019,12000),('USA',2020,55000),('UK',2020,8000),('China',2020,15000);
SELECT country, SUM(num_incidents) as total_incidents FROM cybersecurity_incidents GROUP BY country;
List the total number of unique users who have streamed music in each country?
CREATE TABLE music_streams (user_id INT,genre VARCHAR(255),listening_time FLOAT,country_code CHAR(2)); CREATE TABLE countries (country_code CHAR(2),country_name VARCHAR(255));
SELECT cs.country_name, COUNT(DISTINCT ms.user_id) as num_users FROM music_streams ms JOIN country_summary cs ON ms.country_code = cs.country_code GROUP BY cs.country_name;
Find the average amount donated by donors from the USA.
CREATE TABLE Donors (DonorID INT,Name TEXT,Address TEXT,Country TEXT); INSERT INTO Donors (DonorID,Name,Address,Country) VALUES (1,'John Doe','123 Main St','USA'); INSERT INTO Donors (DonorID,Name,Address,Country) VALUES (2,'Jane Smith','456 Elm St','Canada'); CREATE TABLE Donations (DonationID INT,DonorID INT,Amount DECIMAL,DonationDate DATE); INSERT INTO Donations (DonationID,DonorID,Amount,DonationDate) VALUES (1,1,50.00,'2021-01-01'); INSERT INTO Donations (DonationID,DonorID,Amount,DonationDate) VALUES (2,1,75.00,'2021-03-15'); INSERT INTO Donations (DonationID,DonorID,Amount,DonationDate) VALUES (3,2,100.00,'2021-12-31');
SELECT AVG(Amount) as AverageDonation FROM Donors JOIN Donations ON Donors.DonorID = Donations.DonorID WHERE Donors.Country = 'USA';
What is the average donation amount for donors from the USA?
CREATE TABLE Donors (id INT,name TEXT,country TEXT,donation FLOAT,quarter TEXT,year INT); INSERT INTO Donors (id,name,country,donation,quarter,year) VALUES (1,'Charlie','USA',100.0,'Q2',2021),(2,'David','Mexico',150.0,'Q2',2021),(3,'Eve','Canada',75.0,'Q2',2021),(4,'Frank','USA',200.0,'Q3',2021);
SELECT AVG(donation) FROM Donors WHERE country = 'USA';
What is the maximum number of professional development courses completed by a teacher in '2021'?
CREATE TABLE teacher_professional_development (teacher_name VARCHAR(20),course_name VARCHAR(30),completion_date DATE); INSERT INTO teacher_professional_development (teacher_name,course_name,completion_date) VALUES ('Teacher A','Course 1','2021-01-05'),('Teacher A','Course 2','2021-03-20'),('Teacher B','Course 3','2021-06-15'),('Teacher B','Course 4','2021-08-02'),('Teacher C','Course 5','2021-10-10'),('Teacher C','Course 6','2021-12-18');
SELECT teacher_name, MAX(cnt) as max_courses FROM (SELECT teacher_name, COUNT(course_name) as cnt FROM teacher_professional_development WHERE EXTRACT(YEAR FROM completion_date) = 2021 GROUP BY teacher_name) as subquery;
How many energy storage projects were installed in China between 2010 and 2020?
CREATE TABLE storage_projects (name TEXT,country TEXT,technology TEXT,year_built INTEGER); INSERT INTO storage_projects (name,country,technology,year_built) VALUES ('Talcher Thermal','India','Pumped Hydro',1985); INSERT INTO storage_projects (name,country,technology,year_built) VALUES ('Kameng','India','Pumped Hydro',2015);
SELECT COUNT(*) FROM storage_projects WHERE country = 'China' AND year_built BETWEEN 2010 AND 2020;
What was the total gas production in 'Alaska' for the first 6 months of 2020?
CREATE TABLE wells (well_id INT,field VARCHAR(50),region VARCHAR(50),production_oil FLOAT,production_gas FLOAT,production_date DATE); INSERT INTO wells (well_id,field,region,production_oil,production_gas,production_date) VALUES (1,'Prudhoe Bay','Alaska',12000.0,8000.0,'2020-01-01'),(2,'Kuparuk River','Alaska',8000.0,6000.0,'2020-03-01');
SELECT SUM(production_gas) FROM wells WHERE region = 'Alaska' AND MONTH(production_date) <= 6 AND YEAR(production_date) = 2020;
What is the average attendance at NFL games?
CREATE TABLE nfl_games (game_date DATE,home_team VARCHAR(100),away_team VARCHAR(100),attendance INT); INSERT INTO nfl_games VALUES ('2022-01-09','Los Angeles Rams','Arizona Cardinals',74200),('2022-01-09','Tampa Bay Buccaneers','Philadelphia Eagles',65890),('2022-01-09','Dallas Cowboys','San Francisco 49ers',93753);
SELECT AVG(attendance) FROM nfl_games;
What is the total quantity of organic cotton sourced from India and Pakistan?
CREATE TABLE textile_sources (source_id INT,country VARCHAR(50),material VARCHAR(50)); INSERT INTO textile_sources (source_id,country,material) VALUES (1,'India','Organic Cotton'),(2,'Pakistan','Organic Cotton'); CREATE TABLE quantities (quantity_id INT,source_id INT,quantity INT); INSERT INTO quantities (quantity_id,source_id,quantity) VALUES (1,1,1000),(2,2,1500);
SELECT SUM(q.quantity) FROM quantities q INNER JOIN textile_sources ts ON q.source_id = ts.source_id WHERE ts.country IN ('India', 'Pakistan') AND ts.material = 'Organic Cotton';
What is the total revenue earned from size-diverse garments, per country, for countries in South America?
CREATE TABLE Orders (order_id INT,customer_id INT,garment_id INT,revenue INT); INSERT INTO Orders (order_id,customer_id,garment_id,revenue) VALUES (1,1,1,100),(2,2,3,200); CREATE TABLE Garments (garment_id INT,garment_name TEXT,size_diverse BOOLEAN,country_of_origin TEXT); INSERT INTO Garments (garment_id,garment_name,size_diverse,country_of_origin) VALUES (1,'EcoDress',TRUE,'Brazil'),(2,'GreenShirt',FALSE,'Colombia'),(3,'FairTrousers',TRUE,'Argentina');
SELECT g.country_of_origin, SUM(o.revenue) FROM Orders o JOIN Garments g ON o.garment_id = g.garment_id WHERE g.country_of_origin LIKE 'South% America%' AND g.size_diverse = TRUE GROUP BY g.country_of_origin;
What is the average loan amount for clients in Turkey and Iran?
CREATE TABLE loans (id INT,client_name VARCHAR(50),country VARCHAR(50),amount DECIMAL(10,2),date DATE); INSERT INTO loans (id,client_name,country,amount,date) VALUES (1,'Ali','Turkey',6000,'2022-01-01'); INSERT INTO loans (id,client_name,country,amount,date) VALUES (2,'Fatima','Iran',7000,'2022-01-02');
SELECT AVG(amount) FROM loans WHERE country IN ('Turkey', 'Iran');
What is the average transaction value for Shariah-compliant investments in the United States?
CREATE TABLE shariah_investments (id INT,investment_type VARCHAR(255),value DECIMAL(10,2),country VARCHAR(255));
SELECT AVG(value) FROM shariah_investments WHERE country = 'United States';
How many food safety incidents were reported in 2020?
CREATE TABLE incidents (id INT,date TEXT,location TEXT,type TEXT); INSERT INTO incidents (id,date,location,type) VALUES (1,'2020-01-01','China','Contamination'),(2,'2019-12-31','US','Allergens');
SELECT COUNT(*) FROM incidents WHERE date LIKE '2020%';
What is the minimum salary for faculty members in the College of Arts and Humanities?
CREATE TABLE if not exists FACULTY(id INT,name TEXT,department TEXT,position TEXT,salary INT);
SELECT MIN(salary) FROM FACULTY WHERE department = 'College of Arts and Humanities';
What is the total carbon offset of initiatives in the 'CarbonOffsetInitiatives' table?
CREATE TABLE CarbonOffsetInitiatives (id INT,initiative_name VARCHAR(50),location VARCHAR(50),carbon_offset_tons INT);
SELECT SUM(carbon_offset_tons) FROM CarbonOffsetInitiatives;
Who are the top 3 artists with the longest artist statements in the database?
CREATE TABLE artist_statements (artist_name TEXT,statement_length INTEGER); INSERT INTO artist_statements (artist_name,statement_length) VALUES ('Yayoi Kusama',200),('Marina Abramovic',250),('Jeff Koons',300);
SELECT artist_name, statement_length FROM artist_statements ORDER BY statement_length DESC LIMIT 3;
What is the average annual precipitation in the past 10 years for each weather station?
CREATE TABLE WeatherStation (ID INT,Name VARCHAR(100),Location VARCHAR(100),Elevation FLOAT,AnnualPrecipitation FLOAT); INSERT INTO WeatherStation (ID,Name,Location,Elevation,AnnualPrecipitation) VALUES (1,'Station A','Arctic Circle',100,450); INSERT INTO WeatherStation (ID,Name,Location,Elevation,AnnualPrecipitation) VALUES (2,'Station B','North Pole',200,300);
SELECT Name, AVG(AnnualPrecipitation) OVER (PARTITION BY Name ORDER BY Name ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS AvgAnnualPrecipitation FROM WeatherStation WHERE YEAR(CurrentDate) - YEAR(DateInstalled) BETWEEN 1 AND 10;
How many traditional art forms were added to the database in the last month?
CREATE TABLE TraditionalArts (ArtForm varchar(50),AddedDate date); INSERT INTO TraditionalArts (ArtForm,AddedDate) VALUES ('Batik','2022-01-01'),('Ukara Stitching','2022-01-15'),('Tingatinga Painting','2022-02-10');
SELECT COUNT(*) FROM (SELECT * FROM TraditionalArts WHERE AddedDate >= DATEADD(MONTH, -1, GETDATE())) t;
What is the total number of legal aid services provided to individuals in rural areas in the state of California in 2021?
CREATE TABLE legal_aid_services (id INT,location VARCHAR(255),state VARCHAR(255),year INT,services_provided INT); INSERT INTO legal_aid_services (id,location,state,year,services_provided) VALUES (1,'Rural Area','California',2021,1000),(2,'Urban Area','California',2021,2000),(3,'Suburban Area','California',2021,1500);
SELECT SUM(services_provided) FROM legal_aid_services WHERE state = 'California' AND location = 'Rural Area' AND year = 2021;
What is the average depth of all marine life research sites?
CREATE TABLE marine_sites (site_id INT,site_name TEXT,max_depth FLOAT); INSERT INTO marine_sites (site_id,site_name,max_depth) VALUES (1,'Research Site A',3000.5),(2,'Research Site B',5500.2),(3,'Research Site C',2000.0);
SELECT AVG(max_depth) FROM marine_sites;
Who are the top content creators in terms of representation?
CREATE TABLE content_creators (id INT,name VARCHAR,country VARCHAR,views INT,represents_group BOOLEAN); INSERT INTO content_creators (id,name,country,views,represents_group) VALUES (1,'CreatorA','USA',100000,true); INSERT INTO content_creators (id,name,country,views,represents_group) VALUES (2,'CreatorB','Canada',150000,false);
SELECT name, views FROM content_creators WHERE represents_group = true ORDER BY views DESC LIMIT 5;
List all mining sites located in 'California' from the 'mining_sites' table.
CREATE TABLE mining_sites (site_id INT,site_name VARCHAR(100),state VARCHAR(50));
SELECT site_name FROM mining_sites WHERE state = 'California';
List all mobile subscribers who have not made any network infrastructure investments in the last 6 months.
CREATE TABLE subscribers (id INT,subscriber_type VARCHAR(10)); CREATE TABLE investments (id INT,subscriber_id INT,investment_date DATE); INSERT INTO subscribers (id,subscriber_type) VALUES (1,'Mobile'),(2,'Broadband'); INSERT INTO investments (id,subscriber_id,investment_date) VALUES (1,1,'2022-02-01'),(2,2,'2022-03-15');
SELECT s.id, s.subscriber_type FROM subscribers s LEFT JOIN investments i ON s.id = i.subscriber_id WHERE i.subscriber_id IS NULL OR i.investment_date < DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH);
List all mobile subscribers who have not used any data in the last month.
CREATE TABLE subscribers(id INT,last_data_usage_date DATE,monthly_data_usage DECIMAL(5,2)); INSERT INTO subscribers(id,last_data_usage_date,monthly_data_usage) VALUES (1,'2022-01-15',3.5),(2,'2022-02-10',4.2),(3,'2022-03-05',0.0);
SELECT id, last_data_usage_date, monthly_data_usage FROM subscribers WHERE monthly_data_usage = 0 AND last_data_usage_date < DATE_SUB(CURDATE(), INTERVAL 1 MONTH);
List all artists who have performed in a music festival in both the US and Canada.
CREATE TABLE Artists (id INT,name VARCHAR(255),country VARCHAR(255)); CREATE TABLE Festivals (id INT,artist_id INT,country VARCHAR(255));
SELECT Artists.name FROM Artists INNER JOIN Festivals ON Artists.id = Festivals.artist_id WHERE Artists.country = 'US' AND Festivals.country = 'Canada' GROUP BY Artists.name HAVING COUNT(DISTINCT Festivals.country) = 2;
What is the average time spent by users on a news article, grouped by their geographical regions and article categories?
CREATE TABLE user_sessions (session_id INT,user_region VARCHAR(255),article_category VARCHAR(255),time_spent INT); INSERT INTO user_sessions (session_id,user_region,article_category,time_spent) VALUES (1,'North America','Politics',600),(2,'Europe','Sports',300),(3,'Asia','Entertainment',450);
SELECT user_region, article_category, AVG(time_spent) AS avg_time_spent FROM user_sessions GROUP BY user_region, article_category;
What is the total word count of articles published by 'John Doe' in the 'media' schema?
CREATE TABLE media.articles (article_id INT,title VARCHAR(100),author VARCHAR(100),word_count INT); INSERT INTO media.articles (article_id,title,author,word_count) VALUES (1,'Article 1','John Doe',500),(2,'Article 2','Jane Doe',600);
SELECT SUM(word_count) FROM media.articles WHERE author = 'John Doe';