instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the total greenhouse gas emissions reduction due to climate finance projects in Central America?
CREATE TABLE greenhouse_gas_emissions (id INT PRIMARY KEY,source_type VARCHAR(50),country VARCHAR(50),year INT,amount DECIMAL(10,2));CREATE TABLE climate_finance_projects (id INT PRIMARY KEY,project_type VARCHAR(50),country VARCHAR(50),year INT,reduction DECIMAL(10,2));CREATE VIEW v_central_american_finance_projects AS SELECT cfp.project_type,cfp.country,SUM(cfp.reduction) AS total_reduction FROM climate_finance_projects cfp WHERE cfp.country LIKE 'Central America%' GROUP BY cfp.project_type,cfp.country;CREATE VIEW v_ghg_reductions AS SELECT ghe.source_type,ghe.country,SUM(ghe.amount) * -1 AS total_reduction FROM greenhouse_gas_emissions ghe JOIN v_central_american_finance_projects cfp ON ghe.country = cfp.country WHERE ghe.source_type = 'Greenhouse Gas' GROUP BY ghe.source_type,ghe.country;
SELECT total_reduction FROM v_ghg_reductions WHERE source_type = 'Greenhouse Gas';
What is the market share of drug 'JKL-012' in India in Q3 2022?
CREATE TABLE market_share (drug_name TEXT,region TEXT,market_share FLOAT,quarter INT,year INT); INSERT INTO market_share (drug_name,region,market_share,quarter,year) VALUES ('JKL-012','India',0.65,3,2022),('MNO-345','China',0.70,3,2022),('GHI-999','India',0.55,3,2022);
SELECT market_share FROM market_share WHERE drug_name = 'JKL-012' AND region = 'India' AND quarter = 3 AND year = 2022;
Which drugs have been approved for pediatric use in the past 5 years?
CREATE TABLE drug_approval (drug_name TEXT,approval_date DATE); INSERT INTO drug_approval (drug_name,approval_date) VALUES ('DrugA','2018-01-01'),('DrugB','2017-05-15'),('DrugC','2020-09-27'),('DrugD','2016-08-04');
SELECT drug_name FROM drug_approval WHERE approval_date >= DATE('now', '-5 year');
List all the public health policies for California and Texas.
CREATE TABLE HealthPolicies (id INT,name VARCHAR(50),state VARCHAR(50),description TEXT); INSERT INTO HealthPolicies VALUES (1,'Policy A','California','Description A'); INSERT INTO HealthPolicies VALUES (2,'Policy B','California','Description B'); INSERT INTO HealthPolicies VALUES (3,'Policy C','Texas','Description C');
SELECT * FROM HealthPolicies WHERE state IN ('California', 'Texas');
List the number of founders for companies in the 'San Francisco' region
CREATE TABLE companies (id INT,region VARCHAR(255),num_founders INT); INSERT INTO companies (id,region,num_founders) VALUES (1,'San Francisco',2),(2,'New York',3),(3,'Los Angeles',1);
SELECT region, COUNT(*) as num_companies FROM companies WHERE region = 'San Francisco';
What is the average total funding for companies founded after 2010?
CREATE TABLE company_founding (id INT PRIMARY KEY,name TEXT,location TEXT,founding_year INT,diversity_metrics TEXT); CREATE TABLE funding_records (id INT PRIMARY KEY,company_id INT,funding_amount INT,funding_date DATE); CREATE VIEW company_funding_summary AS SELECT company_id,SUM(funding_amount) AS total_funding FROM funding_records GROUP BY company_id;
SELECT AVG(f.total_funding) as avg_total_funding FROM company_funding_summary f JOIN company_founding c ON f.company_id = c.id WHERE c.founding_year > 2010;
How many agroecology research projects have been completed in Colombia and Peru?
CREATE TABLE agroecology_research (id INT,project_name VARCHAR(50),country VARCHAR(20)); INSERT INTO agroecology_research (id,project_name,country) VALUES (101,'Proyecto Agroecología para el Desarrollo Rural','CO'),(102,'Investigación Agroecológica en la Amazonía Peruana','PE'),(103,'Agroecología y Soberanía Alimentaria en los Andes','PE'),(104,'Estudio Agroecológico de Cultivos Tropicales en Colombia','CO');
SELECT COUNT(DISTINCT country) FROM agroecology_research WHERE country IN ('CO', 'PE');
Show the number of urban agriculture initiatives in each city and the average budget.
CREATE TABLE urban_agriculture_city (initiative_name VARCHAR(255),city VARCHAR(255),budget FLOAT);
SELECT city, COUNT(initiative_name) as num_initiatives, AVG(budget) as avg_budget FROM urban_agriculture_city GROUP BY city;
What is the total quantity of corn sold by farmers in 'Summerfield'?
CREATE TABLE farmers (id INT,name VARCHAR(50),location VARCHAR(50),crops VARCHAR(50)); CREATE TABLE crops (id INT,name VARCHAR(50),yield INT); CREATE TABLE sales (id INT,farmer_id INT,crop_name VARCHAR(50),quantity INT,price DECIMAL(5,2)); INSERT INTO farmers VALUES (1,'Jane Doe','Summerfield','Corn'); INSERT INTO crops VALUES (1,'Corn',100); INSERT INTO sales VALUES (1,1,'Corn',50,2.50);
SELECT SUM(quantity) FROM sales INNER JOIN farmers ON sales.farmer_id = farmers.id INNER JOIN crops ON sales.crop_name = crops.name WHERE farmers.location = 'Summerfield' AND crops.name = 'Corn';
What is the total number of marine species in the 'Arctic' region that are threatened or endangered?'
CREATE TABLE marine_species (name TEXT,region TEXT,conservation_status TEXT); INSERT INTO marine_species (name,region,conservation_status) VALUES ('Polar Bear','Arctic','Endangered'); INSERT INTO marine_species (name,region,conservation_status) VALUES ('Narwhal','Arctic','Threatened');
SELECT region, COUNT(*) FROM marine_species WHERE region = 'Arctic' AND conservation_status IN ('Endangered', 'Threatened') GROUP BY region;
What is the average total value of transactions for the top 3 digital assets in the 'Binance Smart Chain' network?
CREATE TABLE binance_transactions (asset_name VARCHAR(20),network VARCHAR(20),transactions_value FLOAT); INSERT INTO binance_transactions (asset_name,network,transactions_value) VALUES ('BNB','Binance Smart Chain',200000),('ETH','Binance Smart Chain',300000),('CAKE','Binance Smart Chain',400000);
SELECT asset_name, network, AVG(transactions_value) FROM binance_transactions WHERE network = 'Binance Smart Chain' AND asset_name IN (SELECT asset_name FROM (SELECT asset_name, ROW_NUMBER() OVER (ORDER BY transactions_value DESC) as rn FROM binance_transactions WHERE network = 'Binance Smart Chain') x WHERE rn <= 3) GROUP BY asset_name, network;
What is the total value of transactions for a specific smart contract (e.g. '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D') on the 'Binance Smart Chain'?
CREATE TABLE contract_transactions (transaction_id INT,contract_id INT,block_number INT,value DECIMAL(10,2)); INSERT INTO contract_transactions (transaction_id,contract_id,block_number,value) VALUES (1,1,10,100.50); INSERT INTO contract_transactions (transaction_id,contract_id,block_number,value) VALUES (2,1,20,200.25);
SELECT SUM(value) as total_value FROM contract_transactions WHERE contract_id = (SELECT contract_id FROM smart_contracts WHERE contract_address = '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D' AND network = 'Binance Smart Chain');
What is the total area, in hectares, of wildlife habitats, broken down by habitat type, for habitats that have an area larger than 100000 hectares?
CREATE TABLE wildlife_habitat_4 (id INT,habitat_type VARCHAR(255),area FLOAT); INSERT INTO wildlife_habitat_4 (id,habitat_type,area) VALUES (1,'Tropical Rainforest',150000.0),(2,'Temperate Rainforest',120000.0),(3,'Mangrove',200000.0),(4,'Savanna',80000.0),(5,'Coral Reef',50000.0);
SELECT habitat_type, SUM(area) FROM wildlife_habitat_4 WHERE area > 100000 GROUP BY habitat_type;
What is the total volume of timber sold in each region?
CREATE TABLE Regions (RegionID INT,RegionName TEXT); INSERT INTO Regions (RegionID,RegionName) VALUES (1,'Northeast'),(2,'Southeast'); CREATE TABLE Transactions (TransactionID INT,SupplierID INT,RegionID INT,Volume REAL); INSERT INTO Transactions (TransactionID,SupplierID,RegionID,Volume) VALUES (1,1,1,500.3),(2,1,2,750.1);
SELECT Regions.RegionName, SUM(Transactions.Volume) as TotalVolume FROM Regions INNER JOIN Transactions ON Regions.RegionID = Transactions.RegionID GROUP BY Regions.RegionName;
What is the most popular halal certified lipstick in France?
CREATE TABLE lipstick_sales (sale_id INT,product_id INT,sale_quantity INT,is_halal_certified BOOLEAN,sale_date DATE,country VARCHAR(20)); INSERT INTO lipstick_sales VALUES (1,10,5,true,'2021-08-12','France'); INSERT INTO lipstick_sales VALUES (2,11,2,true,'2021-08-12','France');
SELECT product_id, MAX(sale_quantity) FROM lipstick_sales WHERE is_halal_certified = true AND country = 'France' GROUP BY product_id;
Find the total revenue for events with an attendance over 200 in 2021.
CREATE TABLE events (event_id INT,event_name VARCHAR(50),attendance INT,revenue DECIMAL(10,2),event_date DATE); INSERT INTO events (event_id,event_name,attendance,revenue,event_date) VALUES (1,'Art Exhibition',250,15000,'2021-06-01'); INSERT INTO events (event_id,event_name,attendance,revenue,event_date) VALUES (2,'Theater Performance',180,12000,'2021-07-15');
SELECT SUM(revenue) FROM events WHERE attendance > 200 AND YEAR(event_date) = 2021;
What is the average ticket price for jazz concerts?
CREATE TABLE concerts (id INT,type VARCHAR(10),price DECIMAL(5,2)); INSERT INTO concerts (id,type,price) VALUES (1,'jazz',35.99),(2,'rock',29.99),(3,'jazz',42.50);
SELECT AVG(price) FROM concerts WHERE type = 'jazz';
Create a view to display veterans with more than 5 years of service
CREATE TABLE veteran_employment (id INT PRIMARY KEY,name VARCHAR(255),position VARCHAR(255),years_of_service INT,salary NUMERIC(10,2));
CREATE VIEW veteran_long_service AS SELECT * FROM veteran_employment WHERE years_of_service > 5;
What is the total number of veteran job applications in Texas in the last year?
CREATE TABLE veteran_jobs (id INT,state VARCHAR(50),application_date DATE); INSERT INTO veteran_jobs (id,state,application_date) VALUES (1,'Texas','2021-02-15'),(2,'California','2021-04-10'),(3,'Texas','2022-01-05');
SELECT COUNT(*) FROM veteran_jobs WHERE state = 'Texas' AND application_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR);
Insert new records into the 'humanitarian_assistance' table for assistance starting in 2022
CREATE TABLE humanitarian_assistance (assistance_id INT,assistance_type VARCHAR(255),start_date DATE,end_date DATE);
INSERT INTO humanitarian_assistance (assistance_id, assistance_type, start_date, end_date) VALUES (10, 'food distribution', '2022-01-01', '2022-12-31'), (11, 'water purification', '2022-07-01', NULL);
What is the total number of defense diplomacy events held in Africa in 2021?
CREATE TABLE DefenseDiplomacyEvents (Region VARCHAR(10),Year INT,Events INT); INSERT INTO DefenseDiplomacyEvents (Region,Year,Events) VALUES ('Africa',2021,12),('Europe',2021,15),('Asia',2021,18);
SELECT SUM(Events) FROM DefenseDiplomacyEvents WHERE Region = 'Africa' AND Year = 2021;
Identify salespeople who have made transactions in the last 60 days
CREATE TABLE salesperson_activity (salesperson_id INT,activity_date DATE); INSERT INTO salesperson_activity (salesperson_id,activity_date) VALUES (1,'2022-01-01'),(1,'2022-02-01'),(2,'2022-03-01'),(3,'2022-04-01');
SELECT * FROM salesperson_activity WHERE activity_date >= DATE_SUB(CURRENT_DATE, INTERVAL 60 DAY);
List all the transactions made by clients living in New York with a transaction amount greater than $1000.
CREATE TABLE transactions (id INT,client_id INT,transaction_amount DECIMAL(10,2),transaction_date DATE); INSERT INTO transactions (id,client_id,transaction_amount,transaction_date) VALUES (1,3,1500.00,'2022-01-01'),(2,4,800.00,'2022-01-02'),(3,3,1200.00,'2022-01-03'); CREATE TABLE clients (id INT,name VARCHAR(255),state VARCHAR(255)); INSERT INTO clients (id,name,state) VALUES (3,'Mike Johnson','New York'),(4,'Sara Lee','California');
SELECT transactions.id, transactions.client_id, transactions.transaction_amount, transactions.transaction_date FROM transactions INNER JOIN clients ON transactions.client_id = clients.id WHERE clients.state = 'New York' AND transactions.transaction_amount > 1000.00;
List the ports and their average cargo weight for company "HarborLink" in Q2 2017 and Q3 2017.
CREATE TABLE company (id INT,name VARCHAR(255)); INSERT INTO company (id,name) VALUES (1,'HarborLink'); CREATE TABLE port (id INT,name VARCHAR(255)); CREATE TABLE cargo (id INT,port_id INT,company_id INT,weight INT,quarter INT); INSERT INTO port (id,name) VALUES (1,'PortA'),(2,'PortB'),(3,'PortC'); INSERT INTO cargo (id,port_id,company_id,weight,quarter) VALUES (1,1,1,1000,2),(2,1,1,1200,3),(3,2,1,1500,2),(4,2,1,1600,3),(5,3,1,1400,2);
SELECT port.name, AVG(cargo.weight) FROM port INNER JOIN cargo ON port.id = cargo.port_id AND cargo.quarter IN (2, 3) INNER JOIN company ON cargo.company_id = company.id WHERE company.name = 'HarborLink' GROUP BY port.name;
What is the total number of containers handled by port 'LA'?
CREATE TABLE ports (port_id INT,port_name VARCHAR(20)); INSERT INTO ports (port_id,port_name) VALUES (1,'LA'),(2,'LB'),(3,'HOU'); CREATE TABLE cargo (cargo_id INT,port_id INT,container_count INT); INSERT INTO cargo (cargo_id,port_id,container_count) VALUES (1,1,5000),(2,1,3000),(3,2,4000),(4,3,6000);
SELECT SUM(container_count) FROM cargo WHERE port_id = (SELECT port_id FROM ports WHERE port_name = 'LA');
List materials involved in recycling programs located in Africa.
CREATE TABLE recycling_programs (id INT PRIMARY KEY,name TEXT,location TEXT); CREATE TABLE materials (id INT PRIMARY KEY,name TEXT,recycling_program_id INT,FOREIGN KEY (recycling_program_id) REFERENCES recycling_programs(id));
SELECT materials.name, recycling_programs.name AS program_name FROM materials INNER JOIN recycling_programs ON materials.recycling_program_id = recycling_programs.id WHERE recycling_programs.location LIKE '%Africa%';
List the names of all materials that are not part of the 'recycling' program.
CREATE TABLE materials (material_id INT,name VARCHAR(20),recycling_program BOOLEAN); INSERT INTO materials (material_id,name,recycling_program) VALUES (1,'plastic',true),(2,'glass',false),(3,'metal',true),(4,'wood',false);
SELECT name FROM materials WHERE recycling_program = false;
What is the average production output for each machine in the company's facility in Thailand?
CREATE TABLE production_output (output_id INT,machine_id INT,production_date DATE,output_quantity INT); INSERT INTO production_output (output_id,machine_id,production_date,output_quantity) VALUES (1,1,'2022-04-01',100),(2,1,'2022-04-02',120),(3,2,'2022-04-01',150),(4,2,'2022-04-02',160); CREATE TABLE facilities (facility_id INT,facility_name VARCHAR(255),country VARCHAR(255)); INSERT INTO facilities (facility_id,facility_name,country) VALUES (1,'Bangkok Plant','Thailand'),(2,'Chiang Mai Plant','Thailand');
SELECT machine_id, AVG(output_quantity) as avg_output FROM production_output po JOIN facilities f ON f.facility_name = 'Bangkok Plant' WHERE po.production_date BETWEEN '2022-04-01' AND '2022-12-31' GROUP BY machine_id;
List the top 2 countries with the highest average artifact weight, along with the year and total weight of those artifacts.
CREATE TABLE ExcavationSites (SiteID INT,Country VARCHAR(50),Year INT,ArtifactWeight FLOAT); INSERT INTO ExcavationSites (SiteID,Country,Year,ArtifactWeight) VALUES (1,'USA',2020,23.5),(2,'Mexico',2020,14.2),(3,'USA',2019,34.8),(4,'Canada',2019,45.6),(5,'Canada',2019,56.7);
SELECT Country, Year, SUM(ArtifactWeight) AS TotalWeight, AVG(ArtifactWeight) OVER (PARTITION BY Country) AS AvgWeight FROM (SELECT Country, Year, ArtifactWeight, ROW_NUMBER() OVER (PARTITION BY Country ORDER BY ArtifactWeight DESC) rn FROM ExcavationSites) x WHERE rn <= 2 GROUP BY Country, Year;
What is the average number of hospital beds in rural areas of South Korea?
CREATE TABLE HospitalBeds (HospitalID int,Beds int,Rural bool); INSERT INTO HospitalBeds (HospitalID,Beds,Rural) VALUES (1,50,true);
SELECT AVG(Beds) FROM HospitalBeds WHERE Rural = true;
How many companies does 'Impact Fund 1' have investments in, and what's their average ESG rating?
CREATE TABLE investments (fund_name VARCHAR(20),company_id INT); CREATE TABLE companies (id INT,company_name VARCHAR(20),sector VARCHAR(20),ESG_rating FLOAT); INSERT INTO investments (fund_name,company_id) VALUES ('Impact Fund 1',1),('Impact Fund 1',2),('Impact Fund 2',3); INSERT INTO companies (id,company_name,sector,ESG_rating) VALUES (1,'Tech Innovations','technology',8.1),(2,'Finance Group','finance',6.5),(3,'Green Solutions','renewable_energy',9.0);
SELECT COUNT(DISTINCT companies.id), AVG(companies.ESG_rating) FROM investments INNER JOIN companies ON investments.company_id = companies.id WHERE investments.fund_name = 'Impact Fund 1';
Identify the top 3 countries with the highest number of social impact projects in 2019.
CREATE TABLE countries (id INT,name VARCHAR(255),total_projects INT); INSERT INTO countries (id,name,total_projects) VALUES (1,'Brazil',500),(2,'India',700),(3,'South Africa',350); CREATE TABLE projects_by_country (country VARCHAR(255),project_count INT); INSERT INTO projects_by_country (country,project_count) SELECT country,COUNT(*) FROM projects GROUP BY country;
SELECT c.name, p.project_count FROM countries c JOIN (SELECT country, COUNT(*) AS project_count FROM projects GROUP BY country ORDER BY project_count DESC LIMIT 3) p ON c.name = p.country;
Update the risk score to 7 for investments in the housing sector with an investment amount greater than 1,500,000.
CREATE TABLE investments (investment_id INT,sector VARCHAR(50),risk_score INT,investment_amount INT); INSERT INTO investments (investment_id,sector,risk_score,investment_amount) VALUES (1,'Housing',4,1000000),(2,'Housing',5,1800000),(3,'Housing',3,1200000),(4,'Housing',6,2000000),(5,'Housing',2,900000);
UPDATE investments SET risk_score = 7 WHERE sector = 'Housing' AND investment_amount > 1500000;
What is the maximum ESG score for companies in the education sector in Q3 2020?
CREATE TABLE if not exists companies (company_id INT,sector VARCHAR(50),esg_score DECIMAL(3,2),quarter INT,year INT); INSERT INTO companies (company_id,sector,esg_score,quarter,year) VALUES (4,'Education',8.7,3,2020),(5,'Education',9.0,3,2020),(6,'Education',8.5,3,2020);
SELECT MAX(esg_score) FROM companies WHERE sector = 'Education' AND quarter = 3 AND year = 2020;
What is the average length (in minutes) of songs produced by female artists from Canada in the pop genre?
CREATE TABLE songs (id INT,title VARCHAR(255),length FLOAT,artist_name VARCHAR(255),artist_gender VARCHAR(10),artist_country VARCHAR(50),genre VARCHAR(50));
SELECT AVG(length) FROM songs WHERE artist_gender = 'female' AND artist_country = 'Canada' AND genre = 'pop';
What is the minimum budget for each program in Q4 2026, excluding any updates made to the budgets?
CREATE TABLE Programs (ProgramID INT,Name TEXT,InitialBudget DECIMAL(10,2));CREATE TABLE BudgetUpdates (UpdateID INT,ProgramID INT,NewBudget DECIMAL(10,2),UpdateDate DATE);
SELECT P.Name, MIN(P.InitialBudget) as MinBudget FROM Programs P LEFT JOIN BudgetUpdates BU ON P.ProgramID = BU.ProgramID WHERE BU.UpdateDate IS NULL GROUP BY P.ProgramID, P.Name;
What is the average years of experience for teachers who have accessed mental health resources?
CREATE TABLE teachers (teacher_id INT,years_of_experience INT,mental_health_resource_access DATE); INSERT INTO teachers VALUES (1,5,'2021-02-01'),(2,3,'2021-06-01'),(3,8,'2020-12-01');
SELECT AVG(years_of_experience) AS avg_experience FROM teachers WHERE mental_health_resource_access IS NOT NULL;
List all employees who have changed departments in the 'hr' schema's 'employee_moves' table and the 'hr' schema's 'employee_details' table
CREATE TABLE hr.employee_moves (id INT,employee_id INT,old_dept VARCHAR(50),new_dept VARCHAR(50),move_date DATE); CREATE TABLE hr.employee_details (id INT,employee_id INT,first_name VARCHAR(50),last_name VARCHAR(50),department VARCHAR(50));
SELECT e.first_name, e.last_name FROM hr.employee_details e INNER JOIN hr.employee_moves m ON e.employee_id = m.employee_id WHERE m.old_dept != m.new_dept;
How many renewable energy projects are in Country R?
CREATE TABLE renewable_count (name TEXT,location TEXT,type TEXT); INSERT INTO renewable_count (name,location,type) VALUES ('Project 1','Country R','Wind'),('Project 2','Country S','Solar'),('Project 3','Country R','Geothermal');
SELECT COUNT(*) FROM renewable_count WHERE location = 'Country R';
List the top 3 countries with the highest solar energy production?
CREATE TABLE solar_energy (country VARCHAR(20),production_quantity INT); INSERT INTO solar_energy (country,production_quantity) VALUES ('Germany',40000),('Italy',32000),('Spain',28000),('USA',22000),('India',15000);
SELECT country, production_quantity FROM solar_energy ORDER BY production_quantity DESC LIMIT 3;
What is the average energy consumption (in kWh) for households in Canada?
CREATE TABLE HouseholdEnergyConsumption (HouseholdID INT,Country VARCHAR(255),EnergyConsumption FLOAT);
SELECT AVG(EnergyConsumption) FROM HouseholdEnergyConsumption WHERE Country = 'Canada';
Update the 'oil_market' table to set the crude_oil_price_usd to 70.50 for all records where the market_name is 'European Market'
CREATE TABLE oil_market (market_id INT PRIMARY KEY,market_name VARCHAR(255),crude_oil_price_usd DECIMAL(10,2));
UPDATE oil_market SET crude_oil_price_usd = 70.50 WHERE market_name = 'European Market';
What was the average daily production of oil in Q4 2020 for wells in the North Sea?
CREATE TABLE wells (well_id INT,well_name VARCHAR(50),location VARCHAR(50),production_date DATE,oil_production FLOAT); INSERT INTO wells (well_id,well_name,location,production_date,oil_production) VALUES (1,'A1','North Sea','2020-10-01',150.5),(2,'B2','North Sea','2020-11-03',125.8),(3,'C3','North Sea','2020-12-15',175.6);
SELECT AVG(oil_production) FROM wells WHERE production_date BETWEEN '2020-10-01' AND '2020-12-31' AND location = 'North Sea';
What is the average number of points scored by the 'Atlanta Dream' and 'Minnesota Lynx' in the 'WNBA'?
CREATE TABLE teams (team_id INT,team_name TEXT,league TEXT); INSERT INTO teams (team_id,team_name,league) VALUES (1,'Atlanta Dream','WNBA'),(2,'Minnesota Lynx','WNBA'); CREATE TABLE games (game_id INT,team_id INT,points INT); INSERT INTO games (game_id,team_id,points) VALUES (1,1,70),(2,1,75),(3,2,80),(4,2,85);
SELECT AVG(points) FROM games WHERE team_id IN (SELECT team_id FROM teams WHERE team_name IN ('Atlanta Dream', 'Minnesota Lynx')) AND league = 'WNBA';
What is the average number of spectators in the last 3 home games for each team?
CREATE TABLE games (id INT,team TEXT,spectators INT,home INT); INSERT INTO games (id,team,spectators,home) VALUES (1,'Manchester United',75000,1),(2,'Manchester City',65000,1),(3,'Liverpool',55000,1),(4,'Manchester United',76000,0),(5,'Manchester City',64000,0),(6,'Liverpool',56000,0);
SELECT team, AVG(spectators) FROM games WHERE home = 1 GROUP BY team HAVING season >= 2017;
What are the total funds allocated for ethical AI initiatives in North America?
CREATE TABLE ethical_ai_initiatives (initiative_id INT,region VARCHAR(20),funds DECIMAL(10,2)); INSERT INTO ethical_ai_initiatives (initiative_id,region,funds) VALUES (1,'North America',50000.00),(2,'Europe',100000.00),(3,'South America',25000.00);
SELECT SUM(funds) FROM ethical_ai_initiatives WHERE region = 'North America';
Who is responsible for AI oversight in Canada?
CREATE TABLE ai_oversight (id INT,organization VARCHAR(50),region VARCHAR(50)); INSERT INTO ai_oversight (id,organization,region) VALUES (1,'AI Ethics Board','Canada'),(2,'Data Privacy Commissioner','Canada'),(3,'Innovation Science and Economic Development Canada','Canada');
SELECT organization FROM ai_oversight WHERE region = 'Canada';
What is the maximum fare for train and bus services?
CREATE TABLE fares (fare_id INT,mode_id INT,fare_amount DECIMAL(5,2)); INSERT INTO fares VALUES (1,1,2.50); INSERT INTO fares VALUES (2,1,3.00); INSERT INTO fares VALUES (3,2,1.75);
SELECT MAX(fare_amount) as max_fare FROM fares WHERE mode_id IN (1, 2);
Calculate the average quantity of sustainable materials used by each brand, excluding 'BrandA'?
CREATE TABLE Brands (BrandID INT,BrandName VARCHAR(50),Material VARCHAR(50),Quantity INT);INSERT INTO Brands (BrandID,BrandName,Material,Quantity) VALUES (1,'BrandA','Organic Cotton',3000),(2,'BrandB','Recycled Polyester',2500),(1,'BrandA','Organic Silk',1000),(3,'BrandC','Organic Cotton',2000),(2,'BrandB','Tencel',1800);
SELECT BrandName, AVG(Quantity) as AvgQuantity FROM Brands WHERE BrandName != 'BrandA' GROUP BY BrandName;
Find the daily new user registrations in 'data_privacy' table for the last week?
CREATE TABLE data_privacy (user_id INT,registration_date DATE);
SELECT registration_date, COUNT(*) FROM data_privacy WHERE registration_date >= CURDATE() - INTERVAL 7 DAY GROUP BY registration_date;
Show the number of unique users who engaged with posts about renewable energy in the past month.
CREATE TABLE posts (id INT,post_text TEXT,post_date DATETIME); CREATE TABLE engagements (id INT,user_id INT,post_id INT);
SELECT COUNT(DISTINCT e.user_id) AS unique_users FROM posts p JOIN engagements e ON p.id = e.post_id WHERE p.post_text LIKE '%renewable energy%' AND DATE(p.post_date) > DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);
What is the average fabric cost for t-shirts?
CREATE TABLE Fabrics (id INT,fabric_name VARCHAR(255),cost DECIMAL(5,2)); INSERT INTO Fabrics (id,fabric_name,cost) VALUES (1,'Cotton',2.50),(2,'Polyester',1.80),(3,'Rayon',3.20); CREATE TABLE Products (id INT,product_name VARCHAR(255),fabric_id INT); INSERT INTO Products (id,product_name,fabric_id) VALUES (1,'T-Shirt',1),(2,'Pants',2),(3,'Dress',3);
SELECT AVG(Fabrics.cost) FROM Fabrics INNER JOIN Products ON Fabrics.id = Products.fabric_id WHERE Products.product_name = 'T-Shirt';
What is the average price of cotton textiles sourced from the USA?
CREATE TABLE sourcing (id INT,material VARCHAR(10),country VARCHAR(10),price DECIMAL(5,2)); INSERT INTO sourcing (id,material,country,price) VALUES (1,'cotton','USA',3.50),(2,'polyester','China',2.75);
SELECT AVG(price) FROM sourcing WHERE material = 'cotton' AND country = 'USA';
What is the minimum donation amount for the 'Environmental Conservation' program in '2021'?
CREATE TABLE environmental_donations (id INT,donor_name TEXT,program TEXT,donation_amount DECIMAL); INSERT INTO environmental_donations (id,donor_name,program,donation_amount) VALUES (1,'Mia','Environmental Conservation',25.00); INSERT INTO environmental_donations (id,donor_name,program,donation_amount) VALUES (2,'Noah','Environmental Conservation',50.00);
SELECT MIN(donation_amount) FROM environmental_donations WHERE program = 'Environmental Conservation' AND YEAR(donation_date) = 2021;
List all food recalls in the food_recalls table for the year 2020.
CREATE TABLE food_recalls (recall_id INT,recall_date DATE,food_item VARCHAR(255));
SELECT recall_id, recall_date, food_item FROM food_recalls WHERE EXTRACT(YEAR FROM recall_date) = 2020;
What is the average weight of all shipments that originated from the United Kingdom in January 2022?
CREATE TABLE Shipments (id INT,weight INT,origin_country TEXT,shipment_date DATE); INSERT INTO Shipments (id,weight,origin_country,shipment_date) VALUES (1,8,'UK','2022-01-01'); INSERT INTO Shipments (id,weight,origin_country,shipment_date) VALUES (2,12,'USA','2022-01-02'); INSERT INTO Shipments (id,weight,origin_country,shipment_date) VALUES (3,5,'Canada','2022-01-03');
SELECT AVG(weight) FROM Shipments WHERE origin_country = 'UK' AND shipment_date BETWEEN '2022-01-01' AND '2022-01-31';
How many genetic research projects were conducted in Africa?
CREATE TABLE projects (id INT,title VARCHAR(50),location VARCHAR(50)); INSERT INTO projects (id,title,location) VALUES (1,'Genome Mapping','Canada'),(2,'DNA Sequencing','Africa');
SELECT COUNT(*) FROM projects WHERE location = 'Africa';
What is the total funding for biotech startups in Texas?
CREATE SCHEMA if not exists biotech; CREATE TABLE if not exists biotech.startups (id INT,name TEXT,location TEXT,funding FLOAT); INSERT INTO biotech.startups (id,name,location,funding) VALUES (1,'StartupA','Texas',5000000.00); INSERT INTO biotech.startups (id,name,location,funding) VALUES (2,'StartupB','California',7000000.00); INSERT INTO biotech.startups (id,name,location,funding) VALUES (3,'StartupC','Texas',3000000.00);
SELECT SUM(funding) FROM biotech.startups WHERE location = 'Texas';
What is the total budget and number of departments for each manager?
CREATE TABLE Manager (id INT,Name VARCHAR(50)); INSERT INTO Manager (id,Name) VALUES (101,'Manager1'); INSERT INTO Manager (id,Name) VALUES (102,'Manager2'); CREATE TABLE Department (id INT,Name VARCHAR(50),ManagerID INT,Budget FLOAT); INSERT INTO Department (id,Name,ManagerID,Budget) VALUES (1,'Department1',101,500000); INSERT INTO Department (id,Name,ManagerID,Budget) VALUES (2,'Department2',101,750000); INSERT INTO Department (id,Name,ManagerID,Budget) VALUES (3,'Department3',102,600000);
SELECT m.Name AS ManagerName, SUM(d.Budget) AS TotalBudget, COUNT(d.id) AS NumberOfDepartments FROM Manager m JOIN Department d ON m.id = d.ManagerID GROUP BY m.Name;
How many graduate students are enrolled in the Computer Science program?
CREATE TABLE GraduateStudents (StudentID int,Name varchar(50),Department varchar(50)); CREATE TABLE Enrollment (StudentID int,Course varchar(50),Semester varchar(50)); INSERT INTO GraduateStudents (StudentID,Name,Department) VALUES (1,'Alice Johnson','Computer Science'); INSERT INTO GraduateStudents (StudentID,Name,Department) VALUES (2,'Bob Brown','Computer Science'); INSERT INTO Enrollment (StudentID,Course,Semester) VALUES (1,'Database Systems','Fall'); INSERT INTO Enrollment (StudentID,Course,Semester) VALUES (1,'Artificial Intelligence','Spring'); INSERT INTO Enrollment (StudentID,Course,Semester) VALUES (2,'Database Systems','Fall');
SELECT COUNT(*) FROM GraduateStudents WHERE Department = 'Computer Science' AND StudentID IN (SELECT StudentID FROM Enrollment);
Which community health workers have served the most patients from underrepresented communities in the last year?
CREATE TABLE community_workers (worker_id INT,worker_name VARCHAR(50),community_type VARCHAR(50),patients_served INT,year INT); INSERT INTO community_workers (worker_id,worker_name,community_type,patients_served,year) VALUES (1,'John Doe','African American',50,2021),(2,'Jane Smith','Hispanic',75,2021),(3,'Alice Johnson','LGBTQ+',60,2021),(4,'Bob Brown','Rural',40,2021),(5,'Maria Garcia','Asian',45,2021),(6,'David Kim','Native American',35,2021);
SELECT community_type, worker_name, SUM(patients_served) as total_patients_served FROM community_workers WHERE year = 2021 AND community_type IN ('African American', 'Hispanic', 'LGBTQ+') GROUP BY community_type, worker_name ORDER BY total_patients_served DESC;
How many sustainable tourism initiatives were implemented in South America in 2021?
CREATE TABLE sustainable_tourism_initiatives (country VARCHAR(255),year INT,num_initiatives INT); INSERT INTO sustainable_tourism_initiatives (country,year,num_initiatives) VALUES ('Argentina',2021,20),('Colombia',2021,30),('Peru',2021,40);
SELECT SUM(num_initiatives) FROM sustainable_tourism_initiatives WHERE country IN ('Argentina', 'Colombia', 'Peru') AND year = 2021;
What are the average virtual tour engagement statistics for hotels in the APAC region in Q1 2022?
CREATE TABLE avg_virtual_tour_stats (hotel_id INT,hotel_name TEXT,region TEXT,q1_2022_views INT,q1_2022_clicks INT); INSERT INTO avg_virtual_tour_stats (hotel_id,hotel_name,region,q1_2022_views,q1_2022_clicks) VALUES (10,'Hotel X','APAC',500,300),(11,'Hotel Y','APAC',650,350);
SELECT region, AVG(q1_2022_views) AS avg_views, AVG(q1_2022_clicks) AS avg_clicks FROM avg_virtual_tour_stats WHERE region = 'APAC' GROUP BY region;
Which OTA websites have the highest revenue from hotel bookings in Asia?
CREATE TABLE ota_bookings (booking_id INT,ota_website VARCHAR(255),hotel_name VARCHAR(255),country VARCHAR(255),revenue DECIMAL(10,2)); CREATE TABLE hotels (hotel_id INT,hotel_name VARCHAR(255),country VARCHAR(255));
SELECT ota_website, SUM(revenue) FROM ota_bookings INNER JOIN hotels ON ota_bookings.hotel_name = hotels.hotel_name WHERE country = 'Asia' GROUP BY ota_website ORDER BY SUM(revenue) DESC;
What resources are managed by the Inuit community and in what quantities?
CREATE TABLE Indigenous_Communities (id INT PRIMARY KEY,community_name VARCHAR(50),population INT,region VARCHAR(50)); CREATE TABLE Resource_Management (id INT,year INT,resource_type VARCHAR(50),quantity INT,community_id INT,FOREIGN KEY (community_id) REFERENCES Indigenous_Communities(id)); INSERT INTO Indigenous_Communities (id,community_name,population,region) VALUES (1,'Inuit',15000,'Arctic'); INSERT INTO Resource_Management (id,year,resource_type,quantity,community_id) VALUES (1,2020,'Fish',5000,1),(2,2020,'Seal',2000,1);
SELECT Indigenous_Communities.community_name, Resource_Management.resource_type, Resource_Management.quantity FROM Indigenous_Communities INNER JOIN Resource_Management ON Indigenous_Communities.id = Resource_Management.community_id WHERE Indigenous_Communities.community_name = 'Inuit';
What's the name and category of art performed at community events in Seattle?
CREATE TABLE CommunityEvents (ID INT,City VARCHAR(20),EventName VARCHAR(30),ArtCategory VARCHAR(20)); INSERT INTO CommunityEvents VALUES (1,'Seattle','Festival ofColors','Dance'); CREATE TABLE Arts (ArtID INT,ArtName VARCHAR(30),ArtCategory VARCHAR(20)); INSERT INTO Arts VALUES (1,'Bharatanatyam','Dance');
SELECT e.City, e.EventName, a.ArtName FROM CommunityEvents e JOIN Arts a ON e.ArtCategory = a.ArtCategory;
Total number of therapy sessions in each region?
CREATE TABLE therapy_sessions (session_id INT,region VARCHAR(20)); INSERT INTO therapy_sessions (session_id,region) VALUES (1,'Asia'),(2,'Europe'),(3,'America'),(4,'Asia'),(5,'Asia');
SELECT region, COUNT(*) as total_sessions FROM therapy_sessions GROUP BY region;
What is the most common mental health condition treated in France?
CREATE TABLE patients (patient_id INT,age INT,gender TEXT,country TEXT); INSERT INTO patients (patient_id,age,gender,country) VALUES (1,35,'Male','France'); INSERT INTO patients (patient_id,age,gender,country) VALUES (2,42,'Female','France'); CREATE TABLE treatments (treatment_id INT,patient_id INT,treatment_type TEXT); INSERT INTO treatments (treatment_id,patient_id,treatment_type) VALUES (1,1,'Depression'); INSERT INTO treatments (treatment_id,patient_id,treatment_type) VALUES (2,2,'Anxiety');
SELECT treatment_type, COUNT(*) AS treatment_count FROM treatments JOIN patients ON patients.patient_id = treatments.patient_id WHERE patients.country = 'France' GROUP BY treatment_type ORDER BY treatment_count DESC LIMIT 1;
List all destinations with a travel advisory level of 3 or lower
CREATE TABLE destinations (id INT,name VARCHAR(50),travel_advisory_level INT); INSERT INTO destinations (id,name,travel_advisory_level) VALUES (1,'Paris',2),(2,'Rome',3),(3,'Tokyo',1);
SELECT name FROM destinations WHERE travel_advisory_level <= 3;
What is the total number of luxury hotel rooms in Japan?
CREATE TABLE hotels (id INT,country VARCHAR(20),stars INT,rooms INT); INSERT INTO hotels (id,country,stars,rooms) VALUES (1,'Japan',5,500),(2,'Japan',4,300),(3,'Japan',3,200);
SELECT SUM(rooms) FROM hotels WHERE country = 'Japan' AND stars = 5;
What is the total number of tourists who visited Australia and New Zealand in 2021, grouped by month?
CREATE TABLE tourism_stats (country VARCHAR(255),year INT,month INT,visitors INT); INSERT INTO tourism_stats (country,year,month,visitors) VALUES ('Australia',2021,1,1200000); INSERT INTO tourism_stats (country,year,month,visitors) VALUES ('Australia',2021,2,1500000); INSERT INTO tourism_stats (country,year,month,visitors) VALUES ('New Zealand',2021,1,400000); INSERT INTO tourism_stats (country,year,month,visitors) VALUES ('New Zealand',2021,2,450000);
SELECT country, SUM(visitors) as total_visitors FROM tourism_stats WHERE country IN ('Australia', 'New Zealand') AND year = 2021 GROUP BY country, month;
What are the different types of crimes committed in the urban and rural areas?
CREATE TABLE Crimes (ID INT,Type VARCHAR(30),Area VARCHAR(10)); INSERT INTO Crimes (ID,Type,Area) VALUES (1,'Theft','Urban'),(2,'Assault','Rural'),(3,'Vandalism','Urban'),(4,'DUI','Rural');
SELECT Type FROM Crimes WHERE Area = 'Urban' UNION SELECT Type FROM Crimes WHERE Area = 'Rural';
What is the percentage of legal aid clients in Los Angeles who have been homeless in the past year?
CREATE TABLE legal_aid_clients (client_id INT,has_been_homeless BOOLEAN,city VARCHAR(50),state VARCHAR(20)); INSERT INTO legal_aid_clients (client_id,has_been_homeless,city,state) VALUES (1,true,'Los Angeles','California'),(2,false,'Los Angeles','California');
SELECT (SUM(has_been_homeless) * 100.0 / COUNT(*)) AS percentage FROM legal_aid_clients WHERE city = 'Los Angeles';
What is the total number of cases heard by each judge in the 'criminal_cases' table, grouped by judge name?
CREATE TABLE criminal_cases (case_id INT,judge_name VARCHAR(255),case_type VARCHAR(255),case_status VARCHAR(255)); INSERT INTO criminal_cases (case_id,judge_name,case_type,case_status) VALUES (1,'Smith','Theft','Open'),(2,'Johnson','Murder','Closed'),(3,'Williams','Assault','Open');
SELECT judge_name, COUNT(*) as total_cases FROM criminal_cases GROUP BY judge_name;
Calculate the percentage of vessels in each ocean basin that have outdated engine technology.
CREATE TABLE fleet_information (id INT,vessel_name VARCHAR(255),ocean_basin VARCHAR(255),engine_technology DATE); INSERT INTO fleet_information (id,vessel_name,ocean_basin,engine_technology) VALUES (1,'Ocean Titan','Atlantic','2000-01-01'),(2,'Sea Explorer','Pacific','2010-01-01');
SELECT ocean_basin, PERCENTAGE_RANK() OVER (ORDER BY outdated_engine_count) FROM (SELECT ocean_basin, COUNT(*) FILTER (WHERE engine_technology < '2010-01-01') AS outdated_engine_count FROM fleet_information GROUP BY ocean_basin);
How many marine species are present in each type of marine life zone?
CREATE TABLE species (id INT,type TEXT,name TEXT); INSERT INTO species (id,type,name) VALUES (1,'Trench','Anglerfish'),(2,'Abyssal','Goblin shark'),(3,'Trench','Hatchetfish');
SELECT type, COUNT(DISTINCT name) species_count FROM species GROUP BY type;
How many marine species are recorded in the Indian Ocean according to the species_inventory table?
CREATE TABLE species_inventory (id INT,species TEXT,region TEXT); INSERT INTO species_inventory (id,species,region) VALUES (1,'Species A','Indian Ocean'),(2,'Species B','Atlantic Ocean'),(3,'Species C','Indian Ocean');
SELECT COUNT(*) FROM species_inventory WHERE region = 'Indian Ocean';
Identify the top 3 most preferred dishes among customers by rating?
CREATE TABLE orders (id INT,dish_id INT,customer_id INT,rating INT); INSERT INTO orders (id,dish_id,customer_id,rating) VALUES (1,1,101,8),(2,2,102,9),(3,3,103,7),(4,1,104,10),(5,2,105,6);
SELECT dish_id, AVG(rating) as avg_rating FROM orders GROUP BY dish_id ORDER BY avg_rating DESC LIMIT 3;
Update military equipment sales records in the Pacific with a 10% increase.
CREATE TABLE MilitaryEquipmentSales (id INT,region VARCHAR(50),amount FLOAT,sale_date DATE); INSERT INTO MilitaryEquipmentSales (id,region,amount,sale_date) VALUES (1,'Pacific',20000000,'2021-12-25'); INSERT INTO MilitaryEquipmentSales (id,region,amount,sale_date) VALUES (2,'Pacific',22000000,'2022-01-10'); INSERT INTO MilitaryEquipmentSales (id,region,amount,sale_date) VALUES (3,'Pacific',25000000,'2022-07-01');
UPDATE MilitaryEquipmentSales SET amount = amount * 1.1 WHERE region = 'Pacific';
What is the geopolitical risk assessment score for each country in 2020?
CREATE TABLE GeopoliticalRiskAssessments (assessment_id INT,assessment_name VARCHAR(50),score INT,assessment_date DATE,country VARCHAR(50)); INSERT INTO GeopoliticalRiskAssessments (assessment_id,assessment_name,score,assessment_date,country) VALUES (1,'Assessment A',7,'2020-01-01','USA'),(2,'Assessment B',5,'2020-02-15','Russia'),(3,'Assessment C',8,'2020-03-31','China');
SELECT country, score FROM GeopoliticalRiskAssessments WHERE assessment_date BETWEEN '2020-01-01' AND '2020-12-31';
What is the total value of military equipment sales to Africa in the last 12 months?
CREATE TABLE Military_Equipment_Sales(sale_id INT,sale_date DATE,equipment_type VARCHAR(50),country VARCHAR(50),sale_value DECIMAL(10,2));
SELECT SUM(sale_value) FROM Military_Equipment_Sales WHERE country IN (SELECT country FROM World_Countries WHERE continent = 'Africa') AND sale_date >= DATE_SUB(CURRENT_DATE, INTERVAL 12 MONTH);
Which air defense system contractor had the most contracts?
CREATE TABLE Contractors (id INT PRIMARY KEY,contractor_name VARCHAR(50),system_type VARCHAR(50),total_contracts INT);
SELECT contractor_name, COUNT(*) FROM Contractors WHERE system_type = 'air defense' GROUP BY contractor_name ORDER BY COUNT(*) DESC LIMIT 1;
Delete all records of workers who were employed in the 'survey' department in the year 2019.
CREATE TABLE workers(id INT,name TEXT,department TEXT,year INT);INSERT INTO workers(id,name,department,year) VALUES (1,'John','survey',2019),(2,'Jane','survey',2019),(3,'Mike','mining',2018),(4,'Lucy','geology',2020),(5,'Ella','survey',2018);
DELETE FROM workers WHERE department = 'survey' AND year = 2019;
Identify the mining methods used for each mineral in the "mining_methods" table.
CREATE TABLE mining_methods (mineral VARCHAR(50),method VARCHAR(50)); INSERT INTO mining_methods (mineral,method) VALUES ('Gold','Heap leaching'),('Silver','Flotation'),('Iron Ore','Drilling'),('Copper','Open pit mining'),('Zinc','Underground mining'),('Lead','Quarrying'),('Nickel','Open pit mining'),('Tin','Dredging'),('Aluminum','Open pit mining'),('Uranium','In situ leaching');
SELECT mineral, method FROM mining_methods;
Update the "production_data" table to set the "productivity_score" to 95 for all records where the "mine_name" is 'Golden Hills'
CREATE TABLE production_data (record_id INT PRIMARY KEY,mine_name VARCHAR(20),productivity_score INT); INSERT INTO production_data (record_id,mine_name,productivity_score) VALUES (1,'Golden Hills',90),(2,'Silver Ridge',85),(3,'Golden Hills',92);
UPDATE production_data SET productivity_score = 95 WHERE mine_name = 'Golden Hills';
Count the number of mining incidents per month in 2021.
CREATE TABLE incidents (id INT,date DATE,incident_type TEXT); INSERT INTO incidents (id,date,incident_type) VALUES (1,'2021-01-05','equipment_failure'); INSERT INTO incidents (id,date,incident_type) VALUES (2,'2021-03-12','safety_violation');
SELECT DATE_PART('month', date) AS month, COUNT(*) FROM incidents WHERE date >= '2021-01-01' AND date < '2022-01-01' GROUP BY month;
What is the percentage of women in the Mining department?
CREATE TABLE Employees (EmployeeID INT,Name VARCHAR(50),Department VARCHAR(50),Gender VARCHAR(50)); INSERT INTO Employees (EmployeeID,Name,Department,Gender) VALUES (1,'John Doe','Mining','Male'); INSERT INTO Employees (EmployeeID,Name,Department,Gender) VALUES (2,'Jane Smith','Mining','Female');
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Employees WHERE Department = 'Mining')) AS Percentage FROM Employees WHERE Department = 'Mining' AND Gender = 'Female';
Delete broadband subscribers who have used more than 200GB of data in the last month.
CREATE TABLE excessive_data_users (subscriber_id INT,name VARCHAR(50),data_usage_gb FLOAT); INSERT INTO excessive_data_users (subscriber_id,name,data_usage_gb) VALUES (7,'Eva Wilson',210); INSERT INTO excessive_data_users (subscriber_id,name,data_usage_gb) VALUES (8,'Frank Miller',250);
DELETE FROM broadband_subscribers WHERE subscriber_id IN (SELECT subscriber_id FROM excessive_data_users WHERE data_usage_gb > 200);
Update the investment type for a record in the network_investments table
CREATE TABLE network_investments (investment_id INT,location VARCHAR(50),investment_type VARCHAR(50),investment_amount DECIMAL(10,2),investment_date DATE);
UPDATE network_investments SET investment_type = 'Fiber Expansion' WHERE investment_id = 67890;
Which broadband subscribers have a download speed greater than 300 Mbps?
CREATE TABLE broadband_subscribers (subscriber_id INT,download_speed FLOAT); INSERT INTO broadband_subscribers (subscriber_id,download_speed) VALUES (1,250.6),(2,350.8),(3,120.9);
SELECT subscriber_id FROM broadband_subscribers WHERE download_speed > 300;
Who is the oldest artist from the United States?
CREATE TABLE artists (id INT,name VARCHAR(255),age INT,country VARCHAR(255)); INSERT INTO artists (id,name,age,country) VALUES (1,'Bruce Springsteen',72,'United States'),(2,'Beyoncé',40,'United States');
SELECT name, MAX(age) FROM artists WHERE country = 'United States';
Find the number of articles published by each author in the 'investigative_reports' table.
CREATE TABLE investigative_reports (id INT,author VARCHAR(255),title VARCHAR(255),published_date DATE);
SELECT author, COUNT(*) FROM investigative_reports GROUP BY author;
How many articles were published by each author in the 'reports' table, broken down by topic?
CREATE TABLE reports (id INT,author VARCHAR(255),title VARCHAR(255),published_date DATE,topic VARCHAR(255));
SELECT author, topic, COUNT(*) as articles_count FROM reports GROUP BY author, topic;
How many donations were made in each country, based on the 'donations' and 'countries' tables?
CREATE TABLE countries (id INT,country_code CHAR(2),country_name TEXT);CREATE TABLE donations (id INT,donor_id INT,amount DECIMAL(10,2),donation_date DATE,donor_country_id INT);
SELECT countries.country_name, COUNT(donations.id) FROM countries INNER JOIN donations ON countries.id = donations.donor_country_id GROUP BY countries.country_name;
What is the total number of grants given per city?
CREATE TABLE Nonprofits (NonprofitID INT,Name VARCHAR(50),City VARCHAR(50),State VARCHAR(2),Zip VARCHAR(10),MissionStatement TEXT); CREATE TABLE Grants (GrantID INT,DonorID INT,NonprofitID INT,GrantAmount DECIMAL(10,2),Date DATE); CREATE TABLE Donors (DonorID INT,Name VARCHAR(50),City VARCHAR(50),State VARCHAR(2),Zip VARCHAR(10),DonationAmount DECIMAL(10,2));
SELECT City, COUNT(*) FROM Grants G INNER JOIN Nonprofits N ON G.NonprofitID = N.NonprofitID GROUP BY City;
What was the total donation amount by each organization in the last 30 days?
CREATE TABLE organization_donations (id INT,organization TEXT,donation_date DATE,donation_amount DECIMAL(10,2)); INSERT INTO organization_donations (id,organization,donation_date,donation_amount) VALUES (1,'Organization A','2021-03-15',100.00),(2,'Organization B','2021-03-25',200.00);
SELECT organization, SUM(donation_amount) FROM organization_donations WHERE donation_date >= DATE_SUB(CURRENT_DATE, INTERVAL 30 DAY) GROUP BY organization;
Add a new 'underwater_camera' record to the 'equipment' table for 'GoPro' with 'status' 'inactive'.
CREATE TABLE equipment (equipment_id INT,equipment_name TEXT,manufacturer TEXT,status TEXT);
INSERT INTO equipment (equipment_id, equipment_name, manufacturer, status) VALUES (6, 'underwater_camera', 'GoPro', 'inactive');
Find ship incidents involving oil tankers in the North Sea
CREATE TABLE Ship_Incidents (id INT,ship_name VARCHAR(50),incident_type VARCHAR(50),incident_date DATE,ship_type VARCHAR(50)); INSERT INTO Ship_Incidents (id,ship_name,incident_type,incident_date,ship_type) VALUES (1,'Braer','oil spill','1993-01-05','oil tanker');
SELECT ship_name, incident_type FROM Ship_Incidents WHERE ship_type = 'oil tanker' AND location IN ('North Sea');
How many species are there in each ocean basin?
CREATE TABLE species_count (ocean_basin TEXT,species_number INTEGER); INSERT INTO species_count (ocean_basin,species_number) VALUES ('Atlantic',1200),('Pacific',2000),('Indian',1500);
SELECT ocean_basin, species_number FROM species_count;
What is the maximum year a deep-sea exploration was conducted?
CREATE TABLE deep_sea_exploration (vessel TEXT,year INT); INSERT INTO deep_sea_exploration (vessel,year) VALUES ('Titanic',1912),('Trieste',1960),('Titanic',1985);
SELECT MAX(year) FROM deep_sea_exploration;