instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
How many animals in 'Habitat A' have been educated about conservation?
CREATE TABLE Habitats (id INT,name VARCHAR(20)); INSERT INTO Habitats (id,name) VALUES (1,'Habitat A'),(2,'Habitat B'); CREATE TABLE Animals (id INT,name VARCHAR(20),habitat_id INT); INSERT INTO Animals (id,name,habitat_id) VALUES (1,'Lion',1),(2,'Elephant',1),(3,'Giraffe',2); CREATE TABLE Education (animal_id INT,date DATE); INSERT INTO Education (animal_id,date) VALUES (1,'2022-01-01'),(2,'2022-01-02'),(3,'2022-01-03');
SELECT COUNT(*) FROM Animals INNER JOIN Education ON Animals.id = Education.animal_id WHERE Animals.habitat_id = 1
What is the average number of security incidents reported per day in the education sector in the past year?
CREATE TABLE security_incidents (id INT,sector VARCHAR(255),date DATE);
SELECT AVG(number_of_incidents_per_day) FROM (SELECT DATE(date) as date, COUNT(*) as number_of_incidents_per_day FROM security_incidents WHERE sector = 'education' AND date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY date) as subquery;
What was the average broadband usage for each plan in the last month?
CREATE TABLE customers (id INT,name VARCHAR(255),broadband_plan_id INT,usage DECIMAL(10,2),created_at TIMESTAMP); CREATE TABLE broadband_plans (id INT,name VARCHAR(255),price DECIMAL(10,2));
SELECT bp.name, AVG(c.usage) as avg_usage FROM customers c JOIN broadband_plans bp ON c.broadband_plan_id = bp.id WHERE c.created_at >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 MONTH) GROUP BY bp.name;
How many clinical trials were conducted for 'DrugB' in the European region between 2018 and 2020?
CREATE TABLE clinical_trials (drug_name TEXT,region TEXT,year INT,trials INT); INSERT INTO clinical_trials (drug_name,region,year,trials) VALUES ('DrugB','Europe',2018,300); INSERT INTO clinical_trials (drug_name,region,year,trials) VALUES ('DrugB','Europe',2019,350); INSERT INTO clinical_trials (drug_name,region,year,trials) VALUES ('DrugB','Europe',2020,400);
SELECT SUM(trials) FROM clinical_trials WHERE drug_name = 'DrugB' AND region = 'Europe' AND year BETWEEN 2018 AND 2020;
What are the humanitarian aid projects in India and their costs?
CREATE TABLE if not exists humanitarian_aid (id INT,project_name VARCHAR(100),location VARCHAR(100),amount FLOAT,date DATE); INSERT INTO humanitarian_aid (id,project_name,location,amount,date) VALUES (1,'Flood Relief','Pakistan',5000000,'2010-07-01'); INSERT INTO humanitarian_aid (id,project_name,location,amount,date) VALUES (2,'Earthquake Relief','Haiti',7000000,'2010-01-12');
SELECT project_name, location, amount FROM humanitarian_aid WHERE location = 'India';
What is the average daily waste generation for the chemical production in the past week?
CREATE TABLE waste_generation (id INT PRIMARY KEY,chemical_name VARCHAR(255),date DATE,waste_generated INT); INSERT INTO waste_generation (id,chemical_name,date,waste_generated) VALUES (1,'Hydrochloric Acid','2022-06-01',20); INSERT INTO waste_generation (id,chemical_name,date,waste_generated) VALUES (2,'Sulfuric Acid','2022-06-02',30);
SELECT AVG(waste_generated) as avg_daily_waste, DATEADD(day, -7, GETDATE()) as start_date FROM waste_generation WHERE date >= DATEADD(day, -7, GETDATE());
Which countries have launched the most satellites, in descending order?
CREATE TABLE satellite_launches (year INT,satellite_name VARCHAR(50),country VARCHAR(50)); INSERT INTO satellite_launches (year,satellite_name,country) VALUES (2015,'Kalamsat','India'),(2017,'PSLV-C37','India'),(2018,'PSLV-C42','India'),(2018,'PSLV-C43','India'),(2019,'PSLV-C45','India'),(2020,'PSLV-C46','India'),(2021,'PSLV-C51','India'),(2019,'Starlink 1','USA'),(2019,'Starlink 2','USA'),(2020,'Starlink 11','USA'),(2020,'Starlink 12','USA'),(2021,'Starlink 23','USA');
SELECT country, COUNT(*) OVER (PARTITION BY country) AS num_satellites FROM satellite_launches GROUP BY country ORDER BY num_satellites DESC;
Show the total revenue of sustainable haircare products sold in France and Germany.
CREATE TABLE SustainableSales (product_id INT,product_name VARCHAR(100),revenue DECIMAL(5,2),country VARCHAR(50)); INSERT INTO SustainableSales VALUES (201,'Shampoo Bar',15.99,'France'),(202,'Conditioner Bar',17.99,'Germany'),(203,'Hair Gel',9.99,'France'),(204,'Hair Serum',24.99,'Germany'); CREATE TABLE Sustainability (product_id INT,sustainability_rating INT); INSERT INTO Sustainability VALUES (201,5),(202,5),(203,3),(204,5);
SELECT SUM(revenue) FROM SustainableSales INNER JOIN Sustainability ON SustainableSales.product_id = Sustainability.product_id WHERE country IN ('France', 'Germany') AND sustainability_rating >= 4;
How many total items were delivered to 'region' South America in January 2022?
CREATE TABLE delivery (delivery_id INT,region VARCHAR(50),delivery_date DATE); INSERT INTO delivery (delivery_id,region,delivery_date) VALUES (1,'South America','2022-01-05'),(2,'North America','2022-01-10'),(3,'South America','2022-01-15'); CREATE TABLE item (item_id INT,delivery_id INT); INSERT INTO item (item_id,delivery_id) VALUES (1,1),(2,1),(3,2),(4,3);
SELECT COUNT(i.item_id) FROM item i JOIN delivery d ON i.delivery_id = d.delivery_id WHERE d.region = 'South America' AND d.delivery_date >= '2022-01-01' AND d.delivery_date < '2022-02-01';
Return the user_id and username of users who have created playlists with the 'Rock' genre.
CREATE VIEW playlists_rock AS SELECT * FROM playlists WHERE genre = 'Rock'; CREATE TABLE user_profiles (user_id INT,username VARCHAR(50),bio VARCHAR(255)); INSERT INTO user_profiles (user_id,username,bio) VALUES (1,'jane123','I love rock music.'),(2,'musicfan01','Enjoy all kinds of music.');
SELECT user_id, username FROM user_profiles JOIN playlists_rock ON user_profiles.user_id = playlists_rock.user_id;
What is the average age of farmers in each country?
CREATE TABLE farmer (farmer_id INT,name VARCHAR(50),age INT,gender VARCHAR(10),location VARCHAR(50)); CREATE TABLE country (country_id INT,name VARCHAR(50),description TEXT); CREATE TABLE location (location_id INT,name VARCHAR(50),country_id INT);
SELECT l.name, AVG(f.age) FROM farmer f JOIN location l ON f.location = l.name JOIN country c ON l.country_id = c.country_id GROUP BY l.name;
What is the maximum acres of a habitat in the 'habitat_preservation' table?
CREATE TABLE habitat_preservation (id INT,habitat_name VARCHAR(50),acres FLOAT); INSERT INTO habitat_preservation (id,habitat_name,acres) VALUES (1,'Forest',500.5),(2,'Wetlands',300.2),(3,'Grasslands',700.1);
SELECT MAX(acres) FROM habitat_preservation;
Which landfills have reached 75% of their capacity or more?
CREATE TABLE Landfills (LandfillID INT,Capacity INT,Location VARCHAR(50));CREATE TABLE WasteGenerators (GeneratorID INT,WasteType VARCHAR(20),GeneratedTonnes DECIMAL(5,2),LandfillID INT);CREATE VIEW FilledLandfills AS SELECT L.Location,SUM(WG.GeneratedTonnes) AS TotalTonnes FROM Landfills L INNER JOIN WasteGenerators WG ON L.LandfillID = WG.LandfillID GROUP BY L.Location;
SELECT L.Location, (SUM(WG.GeneratedTonnes) / L.Capacity) * 100 AS PercentageFilled FROM FilledLandfills F INNER JOIN Landfills L ON F.Location = L.Location GROUP BY F.Location HAVING PercentageFilled >= 75;
What is the total quantity of garments sold by suppliers from India in the 'Accessories' category?
CREATE TABLE suppliers (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),industry VARCHAR(255)); INSERT INTO suppliers (id,name,country,industry) VALUES (1,'Supplier A','Bangladesh','Textile'); CREATE TABLE garments (id INT PRIMARY KEY,supplier_id INT,name VARCHAR(255),category VARCHAR(255),price DECIMAL(10,2)); CREATE TABLE sales (id INT PRIMARY KEY,garment_id INT,date DATE,quantity INT); CREATE VIEW category_sales AS SELECT category,SUM(quantity) as total_sales FROM sales JOIN garments ON sales.garment_id = garments.id GROUP BY category; CREATE VIEW indian_suppliers AS SELECT * FROM suppliers WHERE country = 'India';
SELECT SUM(total_sales) FROM category_sales JOIN indian_suppliers ON garments.supplier_id = indian_suppliers.id WHERE category = 'Accessories';
What is the total assets value for all customers from the United States?
CREATE TABLE customers (id INT,name VARCHAR(255),country VARCHAR(255)); INSERT INTO customers (id,name,country) VALUES (1,'John Doe','USA'),(2,'Jane Smith','Canada'); CREATE TABLE accounts (id INT,customer_id INT,assets DECIMAL(10,2)); INSERT INTO accounts (id,customer_id,assets) VALUES (1,1,10000.00),(2,1,15000.00),(3,2,5000.00);
SELECT SUM(accounts.assets) FROM accounts INNER JOIN customers ON accounts.customer_id = customers.id WHERE customers.country = 'USA';
Who are the manufacturers that produce chemical products with a safety protocol number greater than 600?
CREATE TABLE chemical_products (id INT,product TEXT,manufacturer INT,safety_protocol INT); INSERT INTO chemical_products (id,product,manufacturer,safety_protocol) VALUES (1,'Product1',1001,650),(2,'Product2',1002,300),(3,'Product3',1003,700);
SELECT manufacturer FROM chemical_products WHERE safety_protocol > 600;
What is the distribution of threat intelligence sources by type for the last 6 months?
CREATE TABLE threat_intelligence (id INT,source TEXT,type TEXT,date_added DATE); INSERT INTO threat_intelligence (id,source,type,date_added) VALUES (1,'IBM X-Force','Commercial','2021-08-02'),(2,'AlienVault OTX','Commercial','2021-08-05'),(3,'CERT Coordination Center','Open Source','2021-08-10'),(4,'National Vulnerability Database','Open Source','2021-08-15'),(5,'Shadowserver Foundation','Open Source','2021-08-20'),(6,'Honeynet Project','Open Source','2021-08-25'),(7,'FireEye iSIGHT','Commercial','2021-09-01'),(8,'Proofpoint ET','Commercial','2021-09-05');
SELECT type, COUNT(*) as count FROM threat_intelligence WHERE date_added >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH) GROUP BY type;
What is the number of OTA bookings in the USA and Canada in Q1 2022?
CREATE TABLE ota_bookings (booking_id INT,country VARCHAR(255),booking_date DATE); INSERT INTO ota_bookings (booking_id,country,booking_date) VALUES (1,'USA','2022-01-01'),(2,'Canada','2022-02-01'),(3,'USA','2022-03-01');
SELECT COUNT(*) FROM ota_bookings WHERE country IN ('USA', 'Canada') AND booking_date BETWEEN '2022-01-01' AND '2022-03-31';
What is the total biomass (in kg) of each species in the Arctic?
CREATE TABLE Biomass (species TEXT,biomass FLOAT); INSERT INTO Biomass (species,biomass) VALUES ('Polar Bear',450),('Arctic Fox',5.5),('Beluga Whale',1500),('Reindeer',120),('Walrus',1300);
SELECT species, SUM(biomass) FROM Biomass GROUP BY species;
What is the average cost of gene sequencing for unique clients who have spent more than $5000?
CREATE TABLE GeneSequencing (client_id INT,sequencing_cost FLOAT); INSERT INTO GeneSequencing (client_id,sequencing_cost) VALUES (1,4500.50),(2,6200.75),(3,3000.20),(4,5800.00),(5,7000.00);
SELECT AVG(sequencing_cost) FROM GeneSequencing WHERE sequencing_cost > 5000 GROUP BY client_id;
Update the regulatory_compliance table to add a new record for a new regulation "Data Privacy Act" with compliance date 2023-03-15
CREATE TABLE regulatory_compliance (compliance_id INT,regulation_name VARCHAR(50),compliance_date DATE);
INSERT INTO regulatory_compliance (compliance_id, regulation_name, compliance_date) VALUES ((SELECT MAX(compliance_id) FROM regulatory_compliance) + 1, 'Data Privacy Act', '2023-03-15');
What is the latest military innovation for each country in the Middle East?
CREATE TABLE MiddleEastMilitaryInnovations (id INT,innovation VARCHAR(255),country VARCHAR(255),innovation_date DATE);
SELECT country, MAX(innovation_date) as max_innovation_date FROM MiddleEastMilitaryInnovations WHERE country IN ('Middle Eastern countries') GROUP BY country;
Find the number of unique mental health treatment centers in Canada and Australia.
CREATE TABLE treatment_centers (id INT,name VARCHAR(255),country VARCHAR(255)); INSERT INTO treatment_centers (id,name,country) VALUES (1,'Sunshine Mental Health','Canada'); INSERT INTO treatment_centers (id,name,country) VALUES (2,'Oceanic Mental Health','Australia'); INSERT INTO treatment_centers (id,name,country) VALUES (3,'Peak Mental Health','Canada');
SELECT COUNT(DISTINCT country) FROM treatment_centers WHERE country IN ('Canada', 'Australia');
What is the minimum monthly salary in the 'Retail Workers Union'?
CREATE TABLE union_members (member_id INT,member_name VARCHAR(255),union_id INT,monthly_salary DECIMAL(10,2)); CREATE TABLE unions (union_id INT,union_name VARCHAR(255)); INSERT INTO unions (union_id,union_name) VALUES (123,'Retail Workers Union'); INSERT INTO unions (union_id,union_name) VALUES (456,'Teachers Union'); INSERT INTO union_members (member_id,member_name,union_id,monthly_salary) VALUES (1,'John Doe',123,2000.50); INSERT INTO union_members (member_id,member_name,union_id,monthly_salary) VALUES (2,'Jane Doe',123,2200.25);
SELECT MIN(monthly_salary) FROM union_members WHERE union_id = (SELECT union_id FROM unions WHERE union_name = 'Retail Workers Union');
How many projects were completed in the energy sector last year?
CREATE TABLE projects (id INT,name VARCHAR(255),category VARCHAR(255),year INT,status VARCHAR(255)); INSERT INTO projects (id,name,category,year,status) VALUES (3,'Solar Farm Construction','Energy',2021,'Completed');
SELECT COUNT(*) FROM projects WHERE category = 'Energy' AND status = 'Completed' AND year = 2021;
What is the total number of policies and their types for policyholders in California who are under 30 years of age?
CREATE TABLE policies (policy_id INT,policy_holder_id INT,policy_type VARCHAR(50),issue_date DATE,policy_holder_dob DATE,policy_holder_state VARCHAR(50));
SELECT policy_type, COUNT(policy_id) FROM policies WHERE policy_holder_state = 'California' AND DATEDIFF(YEAR, policy_holder_dob, GETDATE()) < 30 GROUP BY policy_type;
Show the daily production rate for Well001
CREATE TABLE wells (id INT,well_name VARCHAR(255),location VARCHAR(255),drill_year INT,company VARCHAR(255),daily_production_rate DECIMAL(5,2)); INSERT INTO wells (id,well_name,location,drill_year,company,daily_production_rate) VALUES (1,'Well001','Texas',2020,'CompanyA',100.50); INSERT INTO wells (id,well_name,location,drill_year,company,daily_production_rate) VALUES (2,'Well002','Colorado',2019,'CompanyB',150.25); INSERT INTO wells (id,well_name,location,drill_year,company,daily_production_rate) VALUES (3,'Well003','California',2019,'CompanyC',200.00);
SELECT daily_production_rate FROM wells WHERE well_name = 'Well001';
Show the total weight of packages in the 'packages' table.
CREATE TABLE packages (package_id INT,item_id INT,weight FLOAT); INSERT INTO packages (package_id,item_id,weight) VALUES (1,1,3.5),(2,2,2.8),(3,3,1.2);
SELECT SUM(weight) FROM packages;
What is the total amount donated by individuals in the United States and Canada?
CREATE TABLE donors (donor_id INT,donor_name TEXT,country TEXT); INSERT INTO donors (donor_id,donor_name,country) VALUES (1,'John Doe','USA'),(2,'Jane Smith','Canada'); CREATE TABLE donations (donation_id INT,donor_id INT,donation_amount DECIMAL); INSERT INTO donations (donation_id,donor_id,donation_amount) VALUES (1,1,100.00),(2,1,200.00),(3,2,300.00);
SELECT SUM(donations.donation_amount) FROM donations INNER JOIN donors ON donations.donor_id = donors.donor_id WHERE donors.country IN ('USA', 'Canada');
What are the defense diplomacy activities between India and China?
CREATE TABLE defense_diplomacy (activity_id INT,country1 TEXT,country2 TEXT); INSERT INTO defense_diplomacy (activity_id,country1,country2) VALUES (1,'India','China'),(2,'China','India');
SELECT * FROM defense_diplomacy WHERE (country1 = 'India' AND country2 = 'China') OR (country1 = 'China' AND country2 = 'India')
How many public hospitals are there in each region?
CREATE TABLE regions (region_id INT,region_name VARCHAR(255)); INSERT INTO regions (region_id,region_name) VALUES (1,'North'),(2,'South'),(3,'East'),(4,'West'); CREATE TABLE hospitals (hospital_id INT,hospital_name VARCHAR(255),region_id INT); INSERT INTO hospitals (hospital_id,hospital_name,region_id) VALUES (1,'North General',1),(2,'South City',2),(3,'East End',3),(4,'Westview',4);
SELECT region_name, COUNT(*) FROM hospitals JOIN regions ON hospitals.region_id = regions.region_id GROUP BY region_name;
What is the trend in funding amounts over time, partitioned by company?
CREATE TABLE funding_time (funding_time_id INT,company_id INT,funding_amount INT,funding_date DATE);
SELECT company_id, funding_date, funding_amount, LAG(funding_amount, 1) OVER (PARTITION BY company_id ORDER BY funding_date) AS previous_funding_amount FROM funding_time ORDER BY company_id, funding_date;
What is the total revenue of military equipment sales for each country in Q3 2021, ordered by the highest revenue first?
CREATE TABLE sales (sale_id int,product varchar(255),country varchar(255),amount decimal(10,2),sale_date date); INSERT INTO sales (sale_id,product,country,amount,sale_date) VALUES (1,'Tank','USA',5000000,'2021-07-01'); INSERT INTO sales (sale_id,product,country,amount,sale_date) VALUES (2,'Fighter Jet','Canada',8000000,'2021-09-15');
SELECT country, SUM(amount) as total_revenue FROM sales WHERE sale_date BETWEEN '2021-07-01' AND '2021-09-30' GROUP BY country ORDER BY total_revenue DESC;
What is the average number of likes on posts by users from the United States, for posts containing the hashtag #nature, in the last month?
CREATE TABLE users (id INT,country VARCHAR(255)); CREATE TABLE posts (id INT,user_id INT,likes INT,hashtags TEXT,post_date DATE);
SELECT AVG(likes) FROM posts INNER JOIN users ON posts.user_id = users.id WHERE users.country = 'United States' AND hashtags LIKE '%#nature%' AND post_date >= DATE(NOW()) - INTERVAL 1 MONTH;
What is the average number of articles published per journalist?
CREATE TABLE journalists (journalist_id INT,name VARCHAR(255)); CREATE TABLE articles (article_id INT,journalist_id INT,publication_date DATE); INSERT INTO journalists (journalist_id,name) VALUES (1,'John Doe'),(2,'Jane Smith'); INSERT INTO articles (article_id,journalist_id,publication_date) VALUES (1,1,'2022-01-01'),(2,1,'2022-01-02'),(3,2,'2022-01-03');
SELECT AVG(article_count) FROM (SELECT journalist_id, COUNT(article_id) AS article_count FROM articles GROUP BY journalist_id) AS subquery;
What is the average volunteer hour contribution by volunteers in each country in Q4 of 2021?
CREATE TABLE Volunteers (id INT,name TEXT,country TEXT,hours FLOAT,quarter TEXT,year INT); INSERT INTO Volunteers (id,name,country,hours,quarter,year) VALUES (1,'Alice','USA',5.0,'Q4',2021),(2,'Bob','Canada',7.5,'Q4',2021),(3,'Eve','Canada',3.0,'Q4',2021),(4,'Frank','USA',6.0,'Q4',2021),(5,'Grace','Mexico',8.0,'Q4',2021);
SELECT country, AVG(hours) FROM Volunteers WHERE quarter = 'Q4' AND year = 2021 GROUP BY country;
What is the average price of vegan products, grouped by category?
CREATE TABLE products (product_id INT,category VARCHAR(255),price DECIMAL(5,2),is_vegan BOOLEAN); INSERT INTO products (product_id,category,price,is_vegan) VALUES (1,'Groceries',4.50,true);
SELECT category, AVG(price) AS avg_price FROM products WHERE is_vegan = true GROUP BY category;
List all artifacts from 'South American' countries with their corresponding site IDs.
CREATE TABLE Artifacts (ArtifactID int,Name text,SiteID int); INSERT INTO Artifacts (ArtifactID,Name,SiteID) VALUES (1,'Artifact1',2);
SELECT Artifacts.Name, Sites.SiteID FROM Artifacts INNER JOIN Sites ON Artifacts.SiteID = Sites.SiteID WHERE Sites.Country = 'South America';
Identify the top 3 countries with the highest number of new players in the last 3 months.
CREATE TABLE NewPlayers (PlayerID INT,RegistrationDate DATE); INSERT INTO NewPlayers (PlayerID,RegistrationDate) VALUES (1,'2021-09-01'),(2,'2021-10-10'),(3,'2021-11-05'),(4,'2021-01-15');
SELECT Country, COUNT(PlayerID) as PlayerCount, RANK() OVER (ORDER BY COUNT(PlayerID) DESC) as Rank FROM Players JOIN (SELECT PlayerID, Country FROM PlayerInfo WHERE RegistrationDate BETWEEN DATEADD(month, -3, CURRENT_DATE) AND CURRENT_DATE) as NewPlayers ON Players.PlayerID = NewPlayers.PlayerID GROUP BY Country HAVING Rank <= 3;
List all unique content topics discussed in Germany and France.
CREATE TABLE topics (id INT,content_topic VARCHAR(255),country VARCHAR(255)); INSERT INTO topics (id,content_topic,country) VALUES (1,'AI','Germany'),(2,'Data Science','France'),(3,'Machine Learning','Germany');
SELECT DISTINCT content_topic FROM topics WHERE country IN ('Germany', 'France');
What is the most expensive item in the "Entrees" category?
CREATE TABLE Menu (menu_id INT PRIMARY KEY,item_name VARCHAR(255),category VARCHAR(255),price DECIMAL(5,2));
SELECT item_name, price FROM Menu WHERE category = 'Entrees' ORDER BY price DESC LIMIT 1;
Delete records in the 'damages' table where the reported cost is less than or equal to $10,000
CREATE TABLE damages (id INT,incident_date DATE,reported_cost INT);
DELETE FROM damages WHERE reported_cost <= 10000;
What is the total number of cases heard in the justice_data schema's court_hearings table where the defendant is of African American origin, and the maximum sentence length for those cases?
CREATE TABLE justice_data.court_hearings (id INT,case_number INT,hearing_date DATE,defendant_race VARCHAR(50)); CREATE TABLE justice_data.sentencing (id INT,case_number INT,offender_id INT,sentence_length INT,conviction VARCHAR(50));
SELECT CH.defendant_race, COUNT(*), MAX(S.sentence_length) FROM justice_data.court_hearings CH JOIN justice_data.sentencing S ON CH.case_number = S.case_number WHERE CH.defendant_race LIKE '%African American%' GROUP BY CH.defendant_race;
List all clients who have completed any financial program and their account balances.
CREATE TABLE financial_programs (client_id INT,program_name VARCHAR(30),program_status VARCHAR(20)); INSERT INTO financial_programs (client_id,program_name,program_status) VALUES (301,'Islamic Financial Capability','Completed'),(302,'Financial Wellbeing','Enrolled'),(303,'Islamic Financial Capability','Completed'),(304,'Financial Capability','Dropped Out'); CREATE TABLE account_balances (client_id INT,account_balance DECIMAL(10,2)); INSERT INTO account_balances (client_id,account_balance) VALUES (301,1000.00),(302,2000.00),(303,3000.00),(304,4000.00);
SELECT * FROM financial_programs INNER JOIN account_balances ON financial_programs.client_id = account_balances.client_id WHERE program_status = 'Completed';
Insert a new record for a sustainable seafood dish in the restaurants table.
CREATE TABLE restaurants (id INT,dish VARCHAR(255),category VARCHAR(255),calories INT,sustainability_score INT);
INSERT INTO restaurants (id, dish, category, calories, sustainability_score) VALUES (1, 'Grilled Sustainable Tuna', 'sustainable seafood', 500, 90);
What is the success rate of startups founded by people from each state in the US?
CREATE TABLE companies (id INT,name TEXT,founder_state TEXT,is_active BOOLEAN);
SELECT founder_state, 100.0 * AVG(CASE WHEN is_active THEN 1.0 ELSE 0.0 END) as success_rate FROM companies WHERE founder_state IS NOT NULL GROUP BY founder_state;
What is the average player score for each game in South Asia?
CREATE TABLE AvgPlayerScores (player_id INT,game_id INT,player_score INT); INSERT INTO AvgPlayerScores (player_id,game_id,player_score) VALUES (11,6,1600),(12,6,1700),(13,7,2100),(14,7,2000),(15,8,1400),(16,8,1300);
SELECT G.game_name, AVG(APS.player_score) as avg_score FROM AvgPlayerScores APS JOIN Games G ON APS.game_id = G.game_id WHERE APS.region = 'South Asia' GROUP BY G.game_name;
What is the total number of mobile and broadband subscribers in each age group?
CREATE TABLE age_groups (age_group_id INT,age_group_name VARCHAR(50)); CREATE TABLE subscriber_age (subscriber_id INT,age INT,age_group_id INT);
SELECT ag.age_group_name, COUNT(sa.subscriber_id) AS total_subscribers FROM age_groups ag INNER JOIN subscriber_age sa ON ag.age_group_id = sa.age_group_id GROUP BY ag.age_group_name;
List all the donation transactions that were made in January 2021, along with the program name they were associated with.
CREATE TABLE Donations (id INT,amount DECIMAL(10,2),donation_date DATE,program_id INT); CREATE TABLE Programs (id INT,name VARCHAR(100)); INSERT INTO Donations (id,amount,donation_date,program_id) VALUES (1,50.00,'2021-01-05',1); INSERT INTO Programs (id,name) VALUES (1,'Education'); INSERT INTO Programs (id,name) VALUES (2,'Health');
SELECT Donations.donation_date, Programs.name FROM Donations JOIN Programs ON Donations.program_id = Programs.id WHERE Donations.donation_date >= '2021-01-01' AND Donations.donation_date < '2021-02-01';
What is the total number of posts mentioning the brand "Samsung" in the electronics industry, in South Korea, in the past week?
CREATE TABLE posts (id INT,user_id INT,brand_mentioned VARCHAR(255),post_time DATETIME);
SELECT COUNT(*) FROM posts WHERE brand_mentioned = 'Samsung' AND industry = 'electronics' AND country = 'South Korea' AND post_time > DATE_SUB(NOW(), INTERVAL 1 WEEK);
List the top 3 destinations in South America with the highest sustainable tourism ratings.
CREATE TABLE sustainability_ratings (destination VARCHAR(20),rating DECIMAL(3,2)); INSERT INTO sustainability_ratings (destination,rating) VALUES ('Galapagos Islands',9.5),('Torres del Paine NP',9.3),('Machu Picchu',9.1),('Iguazu Falls',8.9);
SELECT destination, rating FROM sustainability_ratings WHERE destination IN ('Galapagos Islands', 'Torres del Paine NP', 'Machu Picchu') ORDER BY rating DESC LIMIT 3;
What is the maximum number of levels completed by players who have achieved more than 5 victories in the game "MysticJourney"?
CREATE TABLE MysticJourney (PlayerID INT,LevelsCompleted INT,Victories INT); INSERT INTO MysticJourney (PlayerID,LevelsCompleted,Victories) VALUES (1,25,8),(2,30,12),(3,20,6),(4,35,15),(5,28,7);
SELECT MAX(LevelsCompleted) FROM MysticJourney WHERE Victories > 5;
What is the total quantity of chemical 'ChemA' stored in warehouses located in Texas?
CREATE TABLE warehouses (id INT,name TEXT,location TEXT,total_quantity INT); INSERT INTO warehouses (id,name,location,total_quantity) VALUES (1,'WH1','Texas',100),(2,'WH2','New York',50),(3,'WH3','California',75); CREATE TABLE chemicals (id INT,name TEXT); INSERT INTO chemicals (id,name) VALUES (1,'ChemA'),(2,'ChemB'),(3,'ChemC'); CREATE TABLE inventory (warehouse_id INT,chemical_id INT,quantity INT); INSERT INTO inventory (warehouse_id,chemical_id,quantity) VALUES (1,1,50),(1,3,30),(2,2,40),(3,1,25);
SELECT SUM(i.quantity) FROM inventory i INNER JOIN warehouses w ON i.warehouse_id = w.id INNER JOIN chemicals c ON i.chemical_id = c.id WHERE w.location = 'Texas' AND c.name = 'ChemA';
Update the quantity of the product with product_id 1002 to 250 in the 'dispensary_sales' table
CREATE TABLE dispensary_sales (dispensary_id INT,product_id INT,sale_date DATE,quantity INT);
UPDATE dispensary_sales SET quantity = 250 WHERE product_id = 1002;
What was the total revenue from Music Streaming in Germany?
CREATE TABLE MusicStreaming (id INT,country VARCHAR(20),revenue FLOAT); INSERT INTO MusicStreaming (id,country,revenue) VALUES (1,'USA',1000000.0),(2,'Germany',700000.0);
SELECT SUM(revenue) FROM MusicStreaming WHERE country = 'Germany';
Remove the 'Gluten-free' category from the menu_categories table
CREATE TABLE menu_categories (category_id INT,category_name TEXT);
DELETE FROM menu_categories WHERE category_name = 'Gluten-free';
What is the number of employees in each sector in the 'workplace_safety' schema, grouped by sector?
CREATE SCHEMA workplace_safety; CREATE TABLE employees (id INT,name VARCHAR,sector VARCHAR); INSERT INTO employees VALUES (1,'Jane Smith','Tech');
SELECT sector, COUNT(*) AS num_employees FROM workplace_safety.employees GROUP BY sector;
List all the dams in Texas and their construction dates
CREATE TABLE dams (id INT,name TEXT,construction_date DATE,location TEXT); INSERT INTO dams (id,name,construction_date,location) VALUES (1,'Dam A','1950-05-15','Texas'),(2,'Dam B','1965-08-27','Florida');
SELECT * FROM dams WHERE location = 'Texas';
What is the average carbon footprint of factories in North America?
CREATE TABLE FactoryCarbonFootprints (factory_id INT,carbon_footprint INT); INSERT INTO FactoryCarbonFootprints (factory_id,carbon_footprint) VALUES (1,100),(2,120),(3,150); CREATE TABLE Factories (factory_id INT,region VARCHAR(50)); INSERT INTO Factories (factory_id,region) VALUES (1,'North America'),(2,'South America'),(3,'Europe');
SELECT AVG(carbon_footprint) FROM FactoryCarbonFootprints INNER JOIN Factories ON FactoryCarbonFootprints.factory_id = Factories.factory_id WHERE Factories.region = 'North America';
Find the top 2 content creators with the most followers from Mexico, ordered by the number of followers in descending order.
CREATE TABLE content_creators (id INT,name VARCHAR(255),country VARCHAR(255)); INSERT INTO content_creators (id,name,country) VALUES (1,'Creator K','Mexico'),(2,'Creator L','Mexico'),(3,'Creator M','Mexico'),(4,'Creator N','Colombia'),(5,'Creator O','Chile');
SELECT name, COUNT(*) AS followers FROM content_creators WHERE country = 'Mexico' GROUP BY name ORDER BY followers DESC LIMIT 2;
Find the count of distinct case types where the case outcome is 'Settled' and the attorney's experience level is 'Senior'.
CREATE TABLE Cases (CaseID INT,CaseType VARCHAR(20),Outcome VARCHAR(20),AttorneyExperience VARCHAR(10)); INSERT INTO Cases (CaseID,CaseType,Outcome,AttorneyExperience) VALUES (1,'Civil','Settled','Senior'),(2,'Criminal','Lost','Junior'),(3,'Civil','Won','Senior'),(4,'Civil','Settled','Junior');
SELECT COUNT(DISTINCT CaseType) FROM Cases WHERE Outcome = 'Settled' AND AttorneyExperience = 'Senior';
What is the total number of workplace incidents reported for the 'Service' industry?
CREATE TABLE WorkplaceSafety (union_id INT,year INT,incidents INT); CREATE TABLE Unions (union_id INT,industry TEXT);
SELECT SUM(WorkplaceSafety.incidents) FROM WorkplaceSafety INNER JOIN Unions ON WorkplaceSafety.union_id = Unions.union_id WHERE Unions.industry = 'Service';
What is the average distance from rural hospitals to the nearest clinic in each state?
CREATE TABLE hospitals (id INT,name TEXT,location TEXT,state TEXT); INSERT INTO hospitals (id,name,location,state) VALUES (1,'Hospital A','Rural Texas','Texas'),(2,'Hospital B','Rural California','California'); CREATE TABLE clinics (id INT,name TEXT,location TEXT,state TEXT); INSERT INTO clinics (id,name,location,state) VALUES (1,'Clinic A','Rural Texas','Texas'),(2,'Clinic B','Rural California','California'); CREATE TABLE distance (hospital_id INT,clinic_id INT,distance FLOAT); INSERT INTO distance (hospital_id,clinic_id,distance) VALUES (1,1,15.0),(1,2,20.0),(2,1,25.0),(2,2,30.0);
SELECT h.state, AVG(d.distance) AS avg_distance FROM hospitals h INNER JOIN distance d ON h.id = d.hospital_id INNER JOIN (SELECT hospital_id, MIN(distance) AS min_distance FROM distance GROUP BY hospital_id) m ON d.hospital_id = m.hospital_id AND d.distance = m.min_distance GROUP BY h.state;
Which artifacts have a weight between 10 and 20?
CREATE TABLE Artifact (ArtifactID VARCHAR(10),SiteID VARCHAR(10),Weight FLOAT); INSERT INTO Artifact (ArtifactID,SiteID,Weight) VALUES ('1','A',12.3),('2','A',15.6),('3','A',8.9),('4','A',9.7),('5','A',25.6),('6','B',18.9),('7','B',12.1),('8','B',19.8),('9','B',30.2);
SELECT ArtifactID, Weight FROM Artifact WHERE Weight BETWEEN 10 AND 20;
What is the total number of union members in each occupation category?
CREATE TABLE union_members (id INT,member_id INT,occupation VARCHAR(20)); INSERT INTO union_members (id,member_id,occupation) VALUES (1,1001,'Engineer'),(2,1002,'Teacher'),(3,1003,'Engineer'),(4,1004,'Doctor');
SELECT occupation, SUM(1) OVER (PARTITION BY occupation) AS total_union_members FROM union_members;
What was the total donation amount by city in the year 2020?
CREATE TABLE Donations (id INT,donor VARCHAR(50),city VARCHAR(50),amount FLOAT,donation_date DATE); INSERT INTO Donations (id,donor,city,amount,donation_date) VALUES (1,'John Doe','New York',500,'2020-01-01'); INSERT INTO Donations (id,donor,city,amount,donation_date) VALUES (2,'Jane Smith','Los Angeles',300,'2020-02-01');
SELECT city, SUM(amount) as total_donation FROM Donations WHERE YEAR(donation_date) = 2020 GROUP BY city;
Update the 'initiative' column to 'Digital Access' for 'CodeForAmerica' in the 'social_good' table
CREATE TABLE social_good (organization VARCHAR(255),initiative VARCHAR(255)); INSERT INTO social_good (organization,initiative) VALUES ('CodeForAmerica','Civic Technology'),('BlackGirlsCode','Digital Literacy'),('CodeForAmerica','Data Science');
UPDATE social_good SET initiative = 'Digital Access' WHERE organization = 'CodeForAmerica';
What is the total funding received by biotech startups located in the US?
CREATE TABLE startups (id INT,name VARCHAR(50),location VARCHAR(50),funding FLOAT); INSERT INTO startups (id,name,location,funding) VALUES (1,'Genomic Solutions','USA',5000000);
SELECT SUM(funding) FROM startups WHERE location = 'USA';
List the number of male and female patients diagnosed with any infectious disease in Seattle.
CREATE TABLE Genders (GenderID INT,Age INT,Gender VARCHAR(10),City VARCHAR(20),Disease VARCHAR(20)); INSERT INTO Genders (GenderID,Age,Gender,City,Disease) VALUES (1,50,'Female','Seattle','Measles');
SELECT Gender, COUNT(*) as PatientCount FROM Genders WHERE City = 'Seattle' GROUP BY Gender;
List all electric vehicles in Los Angeles with their speed and usage status.
CREATE TABLE public.evs (id SERIAL PRIMARY KEY,name TEXT,speed FLOAT,in_use BOOLEAN,city TEXT); INSERT INTO public.evs (name,speed,in_use,city) VALUES ('Electric Vehicle 1',60.5,TRUE,'Los Angeles'),('Electric Vehicle 2',65.3,FALSE,'Los Angeles');
SELECT * FROM public.evs WHERE city = 'Los Angeles';
What is the sum of satisfaction scores for creative AI applications in South America?
CREATE TABLE creative_ai_satisfaction (model_name TEXT,satisfaction_score INTEGER,application TEXT,country TEXT); CREATE TABLE south_american_countries (country TEXT); INSERT INTO south_american_countries VALUES ('Brazil'),('Argentina'),('Colombia'),('Peru'),('Chile');
SELECT SUM(satisfaction_score) FROM creative_ai_satisfaction WHERE country IN (SELECT * FROM south_american_countries);
How many Shariah-compliant finance transactions were made in Q1 2022 by gender?
CREATE TABLE shariah_compliant_finance(id INT,transaction_id INT,gender VARCHAR(10),quarter INT,year INT); INSERT INTO shariah_compliant_finance VALUES (1,301,'Male',1,2022); INSERT INTO shariah_compliant_finance VALUES (2,302,'Female',1,2022); INSERT INTO shariah_compliant_finance VALUES (3,303,'Male',2,2022); INSERT INTO shariah_compliant_finance VALUES (4,304,'Female',2,2022); INSERT INTO shariah_compliant_finance VALUES (5,305,'Non-binary',1,2022);
SELECT gender, COUNT(transaction_id) FROM shariah_compliant_finance WHERE quarter = 1 AND year = 2022 GROUP BY gender;
What is the life expectancy in Asian countries in 2020?
CREATE TABLE LifeExpectancy (Country VARCHAR(50),Continent VARCHAR(50),Year INT,LifeExpectancy FLOAT); INSERT INTO LifeExpectancy (Country,Continent,Year,LifeExpectancy) VALUES ('China','Asia',2020,76.4),('India','Asia',2020,69.7),('Japan','Asia',2020,85.0);
SELECT Country, Continent, LifeExpectancy FROM LifeExpectancy WHERE Continent = 'Asia' AND Year = 2020;
What is the total length of songs in the reggae genre released in the 2010s?
CREATE TABLE songs (song_id INT,genre VARCHAR(20),album VARCHAR(30),artist VARCHAR(30),length FLOAT,release_year INT); CREATE TABLE genres (genre VARCHAR(20)); INSERT INTO genres (genre) VALUES ('pop'),('rock'),('jazz'),('hip-hop'),('reggae'); ALTER TABLE songs ADD CONSTRAINT fk_genre FOREIGN KEY (genre) REFERENCES genres(genre);
SELECT SUM(length) as total_length FROM songs WHERE genre = (SELECT genre FROM genres WHERE genre = 'reggae') AND release_year BETWEEN 2010 AND 2019;
Insert a new record into the 'instructors' table: 'Bob Brown', 'Australia', 'Cybersecurity'
CREATE TABLE instructors (id INT,name VARCHAR(50),country VARCHAR(50),expertise VARCHAR(50));
INSERT INTO instructors (id, name, country, expertise) VALUES (4, 'Bob Brown', 'Australia', 'Cybersecurity');
Find the number of mines in Australia that mined zinc in 2018
CREATE TABLE mining_operations (id INT,mine_name TEXT,location TEXT,material TEXT,quantity INT,date DATE); INSERT INTO mining_operations (id,mine_name,location,material,quantity,date) VALUES (4,'Zinc Fortress','Australia','zinc',3000,'2018-01-01');
SELECT COUNT(DISTINCT mine_name) FROM mining_operations WHERE material = 'zinc' AND location = 'Australia' AND date = '2018-01-01';
Delete all records of eco-friendly hotels in South America.
CREATE TABLE hotels (id INT,name TEXT,country TEXT,type TEXT); INSERT INTO hotels (id,name,country,type) VALUES (1,'Eco Hotel Buenos Aires','Argentina','eco'),(2,'Eco Hotel Lima','Peru','eco');
DELETE FROM hotels WHERE type = 'eco' AND country IN ('South America');
List the destinations in Brazil with the greatest increase in visitors from 2019 to 2022 interested in cultural tourism.
CREATE TABLE brazil_tourism (destination VARCHAR(50),year INT,cultural_visitors INT); INSERT INTO brazil_tourism (destination,year,cultural_visitors) VALUES ('Rio de Janeiro',2019,1000000),('Rio de Janeiro',2022,1200000),('Sao Paulo',2019,800000),('Sao Paulo',2022,1000000),('Iguazu Falls',2019,600000),('Iguazu Falls',2022,800000);
SELECT destination, MAX(cultural_visitors) - MIN(cultural_visitors) AS increase FROM brazil_tourism WHERE year IN (2019, 2022) AND cultural_visitors > 0 GROUP BY destination ORDER BY increase DESC LIMIT 1;
Who are the top 3 contributors to ethical AI projects by funding?
CREATE TABLE contributor (contributor_id INT,contributor_name VARCHAR(255),amount DECIMAL(10,2)); INSERT INTO contributor (contributor_id,contributor_name,amount) VALUES (1,'Tech for Good Foundation',600000),(2,'AI Ethics Alliance',450000),(3,'Digital Responsibility Fund',500000),(4,'Inclusive AI Coalition',300000); CREATE TABLE contributor_project (contributor_id INT,project_id INT); INSERT INTO contributor_project (contributor_id,project_id) VALUES (1,1),(2,1),(3,1),(4,2);
SELECT contributor_name, SUM(amount) as total_contribution FROM contributor JOIN contributor_project ON contributor.contributor_id = contributor_project.contributor_id JOIN (SELECT project_id FROM project_budget WHERE project_name LIKE '%AI ethics%' GROUP BY project_id) AS project_filter ON contributor_project.project_id = project_filter.project_id GROUP BY contributor_name ORDER BY total_contribution DESC LIMIT 3;
What is the total environmental impact of each mine?
CREATE TABLE mines (mine_id INT,name TEXT,location TEXT,environmental_impact FLOAT); INSERT INTO mines (mine_id,name,location,environmental_impact) VALUES (1,'ABC Mine','USA',200),(2,'DEF Mine','Canada',250);
SELECT name, SUM(environmental_impact) FROM mines GROUP BY name;
Delete all records of beauty products that contain microplastics from the database.
CREATE TABLE products (product_id INT,product_name VARCHAR(255),contains_microplastics BOOLEAN,country VARCHAR(255));
DELETE FROM products WHERE contains_microplastics = TRUE;
Find the minimum and maximum production quantity of Praseodymium in 2018.
CREATE TABLE Praseodymium_Production (Year INT,Quarter INT,Quantity INT); INSERT INTO Praseodymium_Production (Year,Quarter,Quantity) VALUES (2018,1,250),(2018,2,275),(2018,3,300),(2018,4,325);
SELECT MIN(Quantity), MAX(Quantity) FROM Praseodymium_Production WHERE Year = 2018;
What are the most common types of cybersecurity incidents for each country and their total number of occurrences?
CREATE TABLE country_incidents (id INT,country VARCHAR(255),incident_type VARCHAR(255),incident_date DATE,affected_assets INT); INSERT INTO country_incidents (id,country,incident_type,incident_date,affected_assets) VALUES (1,'USA','Data breach','2021-01-01',50);
SELECT country, incident_type, COUNT(*) as total_occurrences FROM country_incidents GROUP BY country, incident_type ORDER BY total_occurrences DESC;
Delete records of crops not present in 2022
CREATE TABLE crops (id INT,year INT,crop TEXT,quantity INT); INSERT INTO crops (id,year,crop,quantity) VALUES (1,2022,'quinoa',120),(2,2021,'teff',80),(3,2020,'millet',90);
DELETE FROM crops WHERE year != 2022;
What was the percentage of attendees over 65 years old at the 'Senior Arts Festival' in Miami?
CREATE TABLE age_distribution_2 (event_name VARCHAR(50),city VARCHAR(50),age_group VARCHAR(10),attendees INT); INSERT INTO age_distribution_2 (event_name,city,age_group,attendees) VALUES ('Senior Arts Festival','Miami','Over 65',150);
SELECT (attendees * 100.0 / (SELECT SUM(attendees) FROM age_distribution_2 WHERE event_name = 'Senior Arts Festival' AND city = 'Miami')) AS percentage FROM age_distribution_2 WHERE event_name = 'Senior Arts Festival' AND city = 'Miami' AND age_group = 'Over 65';
What is the total revenue from sustainable fashion sales in the last month?
CREATE TABLE sales (id INT,garment_id INT,size INT,sale_date DATE,sustainable BOOLEAN,price DECIMAL(5,2)); INSERT INTO sales (id,garment_id,size,sale_date,sustainable,price) VALUES (1,401,16,'2022-02-01',TRUE,70.00),(2,402,10,'2022-01-15',FALSE,80.00),(3,403,12,'2022-03-20',TRUE,90.00);
SELECT SUM(price) FROM sales WHERE sustainable = TRUE AND sale_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 1 MONTH) AND CURDATE();
Identify the top 3 countries with the highest total revenue from art exhibits, including ticket sales and additional expenses.
CREATE TABLE Exhibits (exhibit_id INT,country VARCHAR(50),city VARCHAR(50),tickets_sold INT,price DECIMAL(5,2),additional_expenses DECIMAL(5,2)); INSERT INTO Exhibits (exhibit_id,country,city,tickets_sold,price,additional_expenses) VALUES (1,'USA','New York',500,25.99,5000),(2,'Canada','Toronto',700,22.49,3000),(3,'Mexico','Mexico City',350,30.00,2000);
SELECT country, SUM(tickets_sold * price + additional_expenses) as total_revenue FROM Exhibits GROUP BY country ORDER BY total_revenue DESC LIMIT 3;
What is the maximum duration of a bioprocess engineering project in the 'pharmaceutical' industry?
CREATE TABLE bioprocess_engineering (id INT,project_name VARCHAR(100),industry VARCHAR(100),duration INT);
SELECT MAX(duration) FROM bioprocess_engineering WHERE industry = 'pharmaceutical';
What is the average age of all archaeologists who have participated in excavations?
CREATE TABLE Archaeologists (ArchaeologistID INT,Age INT,Name VARCHAR(50)); INSERT INTO Archaeologists (ArchaeologistID,Age,Name) VALUES (1,35,'John Doe'); INSERT INTO Archaeologists (ArchaeologistID,Age,Name) VALUES (2,42,'Jane Smith'); CREATE TABLE Excavations (ExcavationID INT,ArchaeologistID INT); INSERT INTO Excavations (ExcavationID,ArchaeologistID) VALUES (1,1); INSERT INTO Excavations (ExcavationID,ArchaeologistID) VALUES (2,2);
SELECT AVG(A.Age) FROM Archaeologists A INNER JOIN Excavations E ON A.ArchaeologistID = E.ArchaeologistID;
What was the total revenue for the 2022 Lollapalooza festival?
CREATE TABLE lollapalooza (year INT,revenue FLOAT); INSERT INTO lollapalooza (year,revenue) VALUES (2017,105.0),(2018,125.0),(2019,140.0),(2022,175.0);
SELECT revenue FROM lollapalooza WHERE year = 2022;
What is the total volume of timber production for the entire dataset?
CREATE TABLE timber_production(year INT,volume INT); INSERT INTO timber_production(year,volume) VALUES (2018,5000),(2019,5500),(2020,6000);
SELECT SUM(volume) FROM timber_production;
What is the total cost of road projects in the Asia-Pacific region that were completed after 2016?
CREATE TABLE InfrastructureProjects (id INT,name VARCHAR(100),region VARCHAR(50),project_type VARCHAR(50),cost FLOAT,completion_date DATE); INSERT INTO InfrastructureProjects (id,name,region,project_type,cost,completion_date) VALUES (1,'Sydney Road','Asia-Pacific','road',5000000,'2017-01-01');
SELECT SUM(cost) FROM InfrastructureProjects WHERE region = 'Asia-Pacific' AND project_type = 'road' AND completion_date > '2016-01-01';
What is the total number of nonprofits offering programs in the categories of Education, Health, and Environment, excluding any duplicate records?
CREATE TABLE nonprofits (id INT,name TEXT,state TEXT,program TEXT,category TEXT); INSERT INTO nonprofits (id,name,state,program,category) VALUES (1,'Nonprofit A','California','Math Education','Education'),(2,'Nonprofit B','California','Health Services','Health'),(3,'Nonprofit C','California','Environmental Conservation','Environment'),(4,'Nonprofit D','Texas','Arts Education','Education'),(5,'Nonprofit E','New York','Social Services','Other'),(6,'Nonprofit F','Florida','Disaster Relief','Other');
SELECT COUNT(DISTINCT name) as total_nonprofits FROM nonprofits WHERE category IN ('Education', 'Health', 'Environment');
What is the average distance traveled per bus in the London transit system on a given day?
CREATE TABLE london_buses (bus_id INT,daily_distance FLOAT,date DATE);
SELECT AVG(daily_distance) FROM london_buses WHERE date = '2022-03-01';
Calculate the total distance covered by users during the entire year of 2021.
CREATE TABLE Distance (user_id INT,distance DECIMAL(5,2),activity_date DATE); INSERT INTO Distance (user_id,distance,activity_date) VALUES (1,5.5,'2021-01-01'),(2,6.2,'2021-01-02'),(3,7.3,'2021-12-31');
SELECT SUM(distance) FROM Distance WHERE activity_date BETWEEN '2021-01-01' AND '2021-12-31';
What is the total CO2 emission of flights from Canada to Australia?
CREATE TABLE flights (flight_id INT,airline TEXT,origin TEXT,destination TEXT,distance INT,co2_emission INT); INSERT INTO flights (flight_id,airline,origin,destination,distance,co2_emission) VALUES (1,'Air Canada','Canada','Australia',15000,1200),(2,'Qantas','Australia','Canada',15000,1200);
SELECT SUM(co2_emission) FROM flights WHERE origin = 'Canada' AND destination = 'Australia';
Display all veteran employment opportunities with a salary over $75,000
CREATE TABLE veteran_employment (opportunity_id INT,opportunity_name VARCHAR(100),location VARCHAR(100),salary INT);
SELECT * FROM veteran_employment WHERE salary > 75000;
List all music festivals and the average number of streams per user for artists performing at the festival, sorted by the number of artists in descending order.
CREATE TABLE festival_artist_streams (festival_id INT,artist_id INT,stream_id INT); INSERT INTO festival_artist_streams (festival_id,artist_id,stream_id) VALUES (1,1,1),(1,1,2),(2,2,3);
SELECT f.festival_name, AVG(s.stream_id / u.user_count) AS avg_streams_per_user FROM festivals f INNER JOIN festival_artist_streams s ON f.festival_id = s.festival_id INNER JOIN artists a ON s.artist_id = a.artist_id INNER JOIN streams stream ON s.stream_id = stream.stream_id INNER JOIN users u ON stream.user_id = u.user_id GROUP BY f.festival_name ORDER BY COUNT(DISTINCT a.artist_id) DESC;
Identify the military equipment used by NATO countries, and the quantity of each type.
CREATE TABLE nato_military_equipment (id INT,country TEXT,equipment_type TEXT,quantity INT); INSERT INTO nato_military_equipment (id,country,equipment_type,quantity) VALUES (1,'USA','Tanks',3000),(2,'France','Tanks',1500),(3,'Germany','Aircraft',2000);
SELECT n.country, n.equipment_type, n.quantity FROM nato_military_equipment n WHERE n.country IN (SELECT m.country FROM military_countries m WHERE m.alliance = 'NATO') GROUP BY n.equipment_type;
List all records from the 'Parks' table sorted by park area
CREATE TABLE Parks(park_id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),area FLOAT,created_date DATE); INSERT INTO Parks (park_id,name,location,area,created_date) VALUES (1,'Central Park','NYC',843.00,'2000-01-01'),(2,'Prospect Park','NYC',585.00,'2000-01-02'),(3,'Golden Gate Park','San Francisco',1017.00,'2000-01-03');
SELECT * FROM Parks ORDER BY area;