instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Populate 'trends_by_region' table with records from Europe and Asia
CREATE TABLE trends_by_region (id INT PRIMARY KEY,region VARCHAR(255),trend_name VARCHAR(255),popularity_score INT);
INSERT INTO trends_by_region (id, region, trend_name, popularity_score) VALUES (1, 'Europe', 'Minimalistic Style', 8), (2, 'Asia', 'K-Pop Fashion', 9);
What is the average mental health score of students by school district, ordered from highest to lowest?
CREATE TABLE student_mental_health (student_id INT,district_id INT,mental_health_score INT); INSERT INTO student_mental_health (student_id,district_id,mental_health_score) VALUES (1,101,75),(2,101,80),(3,102,60),(4,102,65),(5,103,85),(6,103,90);
SELECT district_id, AVG(mental_health_score) as avg_mental_health_score FROM student_mental_health GROUP BY district_id ORDER BY avg_mental_health_score DESC;
Update the founding year of the company PQR to 2015 in the 'company_founding_data' table
CREATE TABLE company_founding_data (company_name VARCHAR(50),founding_year INT);
UPDATE company_founding_data SET founding_year = 2015 WHERE company_name = 'PQR';
List the top 3 states with the highest energy efficiency savings (in GWh) in the first quarter of 2021.
CREATE TABLE state_savings (state VARCHAR(20),quarter INT,year INT,savings_gwh FLOAT); INSERT INTO state_savings (state,quarter,year,savings_gwh) VALUES ('California',1,2021,1200),('California',1,2021,1300),('California',1,2021,1100),('California',2,2021,1400),('California',2,2021,1500),('California',2,2021,1600),('Texas',1,2021,1000),('Texas',1,2021,1100),('Texas',1,2021,1200),('Texas',2,2021,1300),('Texas',2,2021,1400),('Texas',2,2021,1500),('New York',1,2021,1500),('New York',1,2021,1600),('New York',1,2021,1700),('New York',2,2021,1800),('New York',2,2021,1900),('New York',2,2021,2000);
SELECT state, SUM(savings_gwh) AS total_savings_gwh FROM state_savings WHERE quarter = 1 GROUP BY state ORDER BY total_savings_gwh DESC LIMIT 3;
Which indigenous communities are represented in the 'arctic_communities' table, and what is their total population, excluding the 'Inuit' community?
CREATE TABLE arctic_communities (name TEXT,population INTEGER);
SELECT name, SUM(population) FROM arctic_communities WHERE name != 'Inuit' GROUP BY name;
Update the sector of the organization with ID 3 to 'Sustainable Energy'.
CREATE TABLE organizations (id INT,sector VARCHAR(20),ESG_rating FLOAT); INSERT INTO organizations (id,sector,ESG_rating) VALUES (1,'Healthcare',7.5),(2,'Technology',8.2),(3,'Healthcare',8.0),(4,'Renewable Energy',9.0); CREATE TABLE investments (id INT,organization_id INT); INSERT INTO investments (id,organization_id) VALUES (1,1),(2,2),(3,3),(4,4);
UPDATE organizations SET sector = 'Sustainable Energy' WHERE id = 3;
What is the average price of shampoo bottles larger than 500ml?
CREATE TABLE products (product_id INT,product_name VARCHAR(255),category VARCHAR(255),price DECIMAL(10,2),size INT); INSERT INTO products (product_id,product_name,category,price,size) VALUES (1,'Moisturizing Shampoo','Haircare',14.99,750),(2,'Strengthening Conditioner','Haircare',12.99,500),(3,'Volumizing Shampoo','Haircare',15.99,300);
SELECT AVG(price) FROM products WHERE category = 'Haircare' AND size > 500;
List all renewable energy projects and their corresponding technologies in the 'renewables' schema.
CREATE SCHEMA if not exists renewables; CREATE TABLE if not exists renewables.projects (id INT,project_name VARCHAR,location VARCHAR); CREATE TABLE if not exists renewables.technologies (id INT,project_id INT,technology_type VARCHAR); INSERT INTO renewables.projects (id,project_name,location) VALUES (1,'Solar Project 1','USA'),(2,'Wind Farm 1','Canada'),(3,'Hydro Plant 1','Brazil'); INSERT INTO renewables.technologies (id,project_id,technology_type) VALUES (1,1,'Solar'),(2,1,'Battery'),(3,2,'Wind'),(4,3,'Hydro');
SELECT renewables.projects.project_name, renewables.technologies.technology_type FROM renewables.projects INNER JOIN renewables.technologies ON renewables.projects.id = renewables.technologies.project_id;
Which are the galleries that host contemporary art exhibitions in Paris?
CREATE TABLE galleries (id INT,name VARCHAR(50),city VARCHAR(50));CREATE TABLE exhibitions (id INT,title VARCHAR(50),type VARCHAR(50),gallery_id INT); INSERT INTO galleries (id,name,city) VALUES (1,'Galerie Perrotin','Paris'); INSERT INTO exhibitions (id,title,type,gallery_id) VALUES (1,'Contemporary Art Show','Contemporary',1);
SELECT g.name FROM galleries g INNER JOIN exhibitions e ON g.id = e.gallery_id WHERE g.city = 'Paris' AND e.type = 'Contemporary';
List all unique healthcare policies for low-income communities.
CREATE TABLE healthcare_policies (policy VARCHAR(255),income_group VARCHAR(255)); INSERT INTO healthcare_policies (policy,income_group) VALUES ('Medicaid','Low Income'); INSERT INTO healthcare_policies (policy,income_group) VALUES ('CHIP','Low Income'); CREATE TABLE income_groups (group_name VARCHAR(255)); INSERT INTO income_groups (group_name) VALUES ('Low Income'); INSERT INTO income_groups (group_name) VALUES ('Medium Income');
SELECT DISTINCT policy FROM healthcare_policies, income_groups WHERE healthcare_policies.income_group = income_groups.group_name AND income_groups.group_name = 'Low Income';
Find the total amount of rainfall in each region for the last 3 months?
CREATE TABLE Rainfall (id INT,timestamp DATE,region TEXT,rainfall REAL);
SELECT region, SUM(rainfall) as total_rainfall FROM Rainfall WHERE timestamp >= DATEADD(MONTH, -3, CURRENT_DATE) GROUP BY region;
What is the average number of sea turtle nests per year in the Caribbean Sea?
CREATE TABLE sea_turtle_nests (id INT,species VARCHAR(50),location VARCHAR(50),nest_year INT); INSERT INTO sea_turtle_nests (id,species,location,nest_year) VALUES (1,'Leatherback Sea Turtle','Caribbean Sea',2015); INSERT INTO sea_turtle_nests (id,species,location,nest_year) VALUES (2,'Hawksbill Sea Turtle','Caribbean Sea',2016);
SELECT AVG(nest_year) FROM sea_turtle_nests WHERE species IN ('Leatherback Sea Turtle', 'Hawksbill Sea Turtle') AND location = 'Caribbean Sea';
Delete all records of tree species in the tree_species table that are not native to the continent of Africa.
CREATE TABLE tree_species (id INT,species_name VARCHAR(255),native_continent VARCHAR(255));
DELETE FROM tree_species WHERE native_continent != 'Africa';
Which city has the highest average basketball points per game?
CREATE TABLE if not exists teams (team_id INT,city VARCHAR(255)); INSERT INTO teams (team_id,city) VALUES (1,'New York'),(2,'Los Angeles'),(3,'Chicago'); CREATE TABLE if not exists games (game_id INT,team_id INT,points INT,date DATE); INSERT INTO games (game_id,team_id,points,date) VALUES (1,1,110,'2022-01-01'),(2,2,90,'2022-01-02'),(3,3,120,'2022-01-03');
SELECT city, AVG(points) as avg_points FROM teams JOIN games ON teams.team_id = games.team_id GROUP BY city ORDER BY avg_points DESC LIMIT 1;
How many military innovation projects have been initiated by NATO in the last 3 years?
CREATE TABLE Innovation_Project (project VARCHAR(255),sponsor VARCHAR(255),start_date DATE); INSERT INTO Innovation_Project (project,sponsor,start_date) VALUES ('Stealth Technology','NATO','2020-01-01');
SELECT COUNT(project) FROM Innovation_Project WHERE sponsor = 'NATO' AND start_date >= DATE(NOW()) - INTERVAL 3 YEAR;
Who are the goalkeepers from the English Premier League making more than 5 million per year?
CREATE TABLE players (id INT,name VARCHAR(50),position VARCHAR(20),salary DECIMAL(10,2),team VARCHAR(50)); INSERT INTO players (id,name,position,salary,team) VALUES (1,'David de Gea','Goalkeeper',6000000,'Manchester United'); INSERT INTO players (id,name,position,salary,team) VALUES (2,'Hugo Lloris','Goalkeeper',5500000,'Tottenham Hotspur');
SELECT name, salary FROM players WHERE position = 'Goalkeeper' AND salary > 5000000 AND team LIKE 'English Premier League%';
What is the total transaction amount by product category in Q3 2021?
CREATE TABLE products (product_id INT,category VARCHAR(50)); INSERT INTO products VALUES (1,'Electronics'),(2,'Furniture'),(3,'Electronics'),(4,'Furniture'); CREATE TABLE sales (sale_id INT,product_id INT,amount DECIMAL(10,2),transaction_date DATE); INSERT INTO sales VALUES (1,1,150.50,'2021-07-01'),(2,1,200.00,'2021-07-15'),(3,2,75.30,'2021-07-03'),(4,2,50.00,'2021-08-01'),(5,3,300.00,'2021-08-15'),(6,3,400.00,'2021-09-01');
SELECT p.category, SUM(s.amount) FROM products p JOIN sales s ON p.product_id = s.product_id WHERE s.transaction_date BETWEEN '2021-07-01' AND '2021-09-30' GROUP BY p.category;
Find the number of AI-related patents filed in 2021.
CREATE TABLE patents (id INT,inventor_id INT,patent_year INT,ai_related BOOLEAN);
SELECT COUNT(*) FROM patents WHERE patent_year = 2021 AND ai_related = true;
What is the total CO2 emissions by country in the textile industry in 2022?
CREATE TABLE co2_emissions_textile_2022 (country VARCHAR(50),co2_emissions DECIMAL(10,2),date DATE);
SELECT country, SUM(co2_emissions) AS total_co2_emissions FROM co2_emissions_textile_2022 WHERE date >= '2022-01-01' AND date < '2023-01-01' GROUP BY country;
Count the number of distinct animal species in the 'animal_population' table
CREATE TABLE animal_population (id INT,animal_species VARCHAR(50),population INT); INSERT INTO animal_population (id,animal_species,population) VALUES (1,'Tiger',2000),(2,'Elephant',5000),(3,'Giraffe',8000),(4,'Tiger',3000);
SELECT COUNT(DISTINCT animal_species) FROM animal_population;
What was the maximum budget for a climate adaptation project in the 'climate_adaptation' table?
CREATE TABLE climate_adaptation (project_name TEXT,budget INTEGER); INSERT INTO climate_adaptation (project_name,budget) VALUES ('Green Roofs',50000),('Coastal Wetlands Restoration',120000),('Urban Forest Expansion',200000);
SELECT MAX(budget) FROM climate_adaptation;
Which countries are involved in maritime law compliance projects in the Southern Ocean?
CREATE TABLE Country (country_name VARCHAR(50),ocean_name VARCHAR(50)); INSERT INTO Country (country_name,ocean_name) VALUES ('Country A','Southern Ocean');
SELECT DISTINCT country_name FROM Country WHERE ocean_name = 'Southern Ocean';
How many high-risk vulnerabilities are present in the 'network' subsystem?
CREATE TABLE vulnerabilities (id INT,subsystem VARCHAR(255),risk_level VARCHAR(255)); INSERT INTO vulnerabilities (id,subsystem,risk_level) VALUES (1,'network','high'),(2,'applications','medium'),(3,'network','low');
SELECT COUNT(*) FROM vulnerabilities WHERE subsystem = 'network' AND risk_level = 'high';
Who are the top 3 satellite manufacturers with the most satellite deployments?
CREATE TABLE SatelliteManufacturers (ManufacturerID INT,ManufacturerName VARCHAR(50));CREATE TABLE SatelliteDeployment (DeploymentID INT,ManufacturerID INT,DeliveryTime DATE);
SELECT ManufacturerName, COUNT(*) AS DeploymentCount FROM SatelliteManufacturers SM INNER JOIN SatelliteDeployment SD ON SM.ManufacturerID = SD.ManufacturerID GROUP BY ManufacturerName ORDER BY DeploymentCount DESC LIMIT 3;
Who are the top 5 nations with the highest military expenditure in Africa?
CREATE TABLE military_expenditure(expenditure_id INT,country VARCHAR(255),amount FLOAT); INSERT INTO military_expenditure(expenditure_id,country,amount) VALUES (1,'Algeria',10000000),(2,'Egypt',12000000),(3,'South Africa',11000000),(4,'Nigeria',8000000),(5,'Morocco',9000000),(6,'Libya',7000000),(7,'Tunisia',6000000),(8,'Sudan',5000000),(9,'Angola',4000000),(10,'Ethiopia',3000000);
SELECT country, amount FROM military_expenditure WHERE country IN ('Algeria', 'Egypt', 'South Africa', 'Nigeria', 'Morocco') ORDER BY amount DESC;
Delete all records from the 'ai_ethics' table where the 'region' is 'Asia'
CREATE TABLE ai_ethics (id INT PRIMARY KEY,region VARCHAR(50),initiative VARCHAR(100)); INSERT INTO ai_ethics (id,region,initiative) VALUES (1,'Asia','Ethical AI education program');
DELETE FROM ai_ethics WHERE region = 'Asia';
What is the total labor cost for green building projects in New York?
CREATE TABLE LaborCosts (project_id INT,cost FLOAT,building_type VARCHAR(255),state VARCHAR(255)); INSERT INTO LaborCosts (project_id,cost,building_type,state) VALUES (1,30000,'green','New York'),(2,50000,'regular','California');
SELECT SUM(cost) FROM LaborCosts WHERE building_type = 'green' AND state = 'New York';
What is the average confidence score for explainable AI models in the United States?
CREATE TABLE explainable_ai (id INT,model_name VARCHAR(255),country VARCHAR(255),confidence_score FLOAT); INSERT INTO explainable_ai (id,model_name,country,confidence_score) VALUES (1,'ModelA','USA',0.85),(2,'ModelB','USA',0.92),(3,'ModelC','Canada',0.88);
SELECT AVG(confidence_score) FROM explainable_ai WHERE country = 'USA';
What is the minimum age of visitors who attended the exhibition 'Frida Kahlo: Her Life and Art'?
CREATE TABLE exhibitions (id INT,city VARCHAR(20),visitor_age INT,visit_date DATE); INSERT INTO exhibitions (id,city,visitor_age,visit_date) VALUES (1,'New York',15,'2022-01-01'); INSERT INTO exhibitions (id,city,visitor_age,visit_date) VALUES (2,'Los Angeles',18,'2022-02-15');
SELECT MIN(visitor_age) FROM exhibitions WHERE exhibition_name = 'Frida Kahlo: Her Life and Art';
Identify the suppliers that provide both organic and non-organic ingredients.
CREATE TABLE Suppliers (id INT,name VARCHAR(255),type VARCHAR(255)); CREATE TABLE Ingredients (id INT,name VARCHAR(255),supplier_id INT,organic BOOLEAN);
SELECT s.name FROM Suppliers s INNER JOIN Ingredients i ON s.id = i.supplier_id GROUP BY s.name HAVING COUNT(DISTINCT organic) = 2;
What is the total number of steps taken by members with the last name "Garcia"?
CREATE TABLE wearable_data (member_id INT,step_count INT,record_date DATE,last_name VARCHAR(50)); INSERT INTO wearable_data (member_id,step_count,record_date,last_name) VALUES (1,9000,'2021-01-15','Smith'),(2,12000,'2022-03-28','Garcia');
SELECT SUM(step_count) FROM wearable_data WHERE last_name = 'Garcia';
List of countries with the highest average income in 2020.
CREATE TABLE incomes (id INT,country VARCHAR(50),income FLOAT,year INT); INSERT INTO incomes (id,country,income,year) VALUES (1,'Norway',70000,2020),(2,'Switzerland',68000,2020),(3,'Luxembourg',65000,2020),(4,'Ireland',60000,2020),(5,'Denmark',58000,2020);
SELECT country FROM incomes WHERE year = 2020 ORDER BY income DESC LIMIT 5;
How many security incidents were there for each threat type in the last month?
CREATE TABLE security_incidents (id INT,incident_date DATE,threat_type VARCHAR(50)); INSERT INTO security_incidents (id,incident_date,threat_type) VALUES (1,'2022-01-01','Malware'),(2,'2022-01-05','Phishing'),(3,'2022-01-10','Ransomware');
SELECT threat_type, COUNT(*) as incident_count FROM security_incidents WHERE incident_date >= DATEADD(month, -1, GETDATE()) GROUP BY threat_type;
What is the maximum fine amount issued in civil court in the past year, broken down by the type of case?
CREATE TABLE civil_court_records (id INT,case_type TEXT,fine_amount DECIMAL(5,2),court_date DATE);
SELECT case_type, MAX(fine_amount) FROM civil_court_records WHERE court_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY case_type;
Find the average budget of movies produced by Yellow Studios.
CREATE TABLE studio (studio_id INT,name VARCHAR(100)); INSERT INTO studio (studio_id,name) VALUES (1,'Yellow Studios'); CREATE TABLE movie (movie_id INT,title VARCHAR(100),studio_id INT,genre VARCHAR(50),budget INT);
SELECT AVG(movie.budget) FROM movie WHERE movie.studio_id = 1;
Show all cases in the 'civil_cases' table where the case outcome is 'settled' and the attorney's ID is not 912.
CREATE TABLE civil_cases (case_id INT PRIMARY KEY,client_id INT,attorney_id INT,case_outcome VARCHAR(50));
SELECT * FROM civil_cases WHERE case_outcome = 'settled' AND attorney_id <> 912;
What is the total donation amount for each month, across all donors?
CREATE TABLE DonationAmounts (DonationID INT,DonationDate DATE,DonationAmount DECIMAL(10,2)); INSERT INTO DonationAmounts VALUES (1,'2021-04-05',1500.00),(2,'2021-08-20',1500.00),(3,'2021-04-12',1000.00),(4,'2021-08-01',2000.00),(5,'2021-03-15',500.00),(6,'2021-09-01',750.00);
SELECT EXTRACT(MONTH FROM DonationDate) AS Month, SUM(DonationAmount) OVER (PARTITION BY EXTRACT(MONTH FROM DonationDate)) AS TotalDonationAmount FROM DonationAmounts WHERE EXTRACT(YEAR FROM DonationDate) = 2021 GROUP BY Month ORDER BY Month;
How many rural infrastructure projects in the 'Infrastructure' table were completed in 2018 or later, with a cost of 5000000 or more?
CREATE TABLE Infrastructure (id INT,project VARCHAR(255),location VARCHAR(255),year INT,cost INT); INSERT INTO Infrastructure (id,project,location,year,cost) VALUES (1,'Bridge','Rural East',2015,1500000),(2,'Road','Urban North',2017,5000000),(3,'Water Supply','Rural South',2016,3000000),(4,'Electricity','Urban West',2018,7000000);
SELECT COUNT(*) as num_projects FROM Infrastructure WHERE year >= 2018 AND cost >= 5000000;
Show the number of volunteers who joined in each month of the year 2020.
CREATE TABLE Volunteers (VolunteerID INT,VolunteerName TEXT,VolunteerDate DATE);
SELECT EXTRACT(MONTH FROM V.VolunteerDate) as Month, COUNT(*) as Volunteers FROM Volunteers V WHERE YEAR(V.VolunteerDate) = 2020 GROUP BY Month ORDER BY Month;
What are the unique traditional dances and their origins, with the number of related artifacts?
CREATE TABLE Dance (DanceID INT,DanceName VARCHAR(50),Origin VARCHAR(50)); INSERT INTO Dance (DanceID,DanceName,Origin) VALUES (1,'Hula','Hawaii'),(2,'Flamenco','Spain'),(3,'Bharatanatyam','India'); CREATE TABLE Artifact (ArtifactID INT,ArtifactName VARCHAR(50),DanceID INT); INSERT INTO Artifact (ArtifactID,ArtifactName,DanceID) VALUES (1,'Hawaiian Skirt',1),(2,'Flamenco Dress',2),(3,'Bharatanatyam Anklets',3);
SELECT o.Origin, d.DanceName, COUNT(a.ArtifactID) as ArtifactCount FROM Dance d JOIN Artifact a ON d.DanceID = a.DanceID JOIN (SELECT DISTINCT Origin FROM Dance) o ON d.Origin = o.Origin GROUP BY o.Origin, d.DanceName;
Identify the top two job titles with the highest average salaries in the 'gold' industry, for the state of 'California'.
CREATE TABLE workers (id INT,name VARCHAR(50),job_title VARCHAR(50),industry VARCHAR(50),state VARCHAR(50),salary FLOAT); INSERT INTO workers (id,name,job_title,industry,state,salary) VALUES (1,'Jane Doe','Manager','Coal','West Virginia',90000.00);
SELECT job_title, AVG(salary) AS avg_salary FROM workers WHERE industry = 'Gold' AND state = 'California' GROUP BY job_title ORDER BY avg_salary DESC LIMIT 2;
Get the names of publishers who have never published an article on 'Monday' or 'Tuesday'.
CREATE TABLE articles (id INT,title TEXT,publication_day TEXT,publisher TEXT);
SELECT DISTINCT publisher FROM articles WHERE publication_day NOT IN ('Monday', 'Tuesday');
Find the well with the lowest oil production in the Bakken shale
CREATE TABLE if not exists shale_oil_production (well_id INT,well_name TEXT,location TEXT,oil_production FLOAT); INSERT INTO shale_oil_production (well_id,well_name,location,oil_production) VALUES (1,'Well O','Bakken',1234.56),(2,'Well P','Bakken',234.56),(3,'Well Q','Utica',3456.78);
SELECT well_name, oil_production FROM shale_oil_production WHERE location = 'Bakken' ORDER BY oil_production ASC LIMIT 1;
What is the most common infectious disease in each region?
CREATE TABLE DiseaseData (Country VARCHAR(50),Region VARCHAR(20),Disease VARCHAR(20)); INSERT INTO DiseaseData (Country,Region,Disease) VALUES ('Brazil','South America','Malaria'),('Russia','Europe','Tuberculosis'),('India','Asia','Dengue Fever');
SELECT Region, Disease AS MostCommonDisease, COUNT(*) AS Count FROM DiseaseData GROUP BY Region ORDER BY Count DESC;
How many animals are raised by each farmer in 'region2'?
CREATE TABLE farmer (farmer_id INT,farmer_name TEXT,region TEXT); INSERT INTO farmer (farmer_id,farmer_name,region) VALUES (1,'FarmerA','region1'),(2,'FarmerB','region2'),(3,'FarmerC','region2'); CREATE TABLE animal_rearing (rearing_id INT,farmer_id INT,animal_type TEXT,quantity INT); INSERT INTO animal_rearing (rearing_id,farmer_id,animal_type,quantity) VALUES (1,1,'Cattle',10),(2,1,'Chickens',50),(3,2,'Pigs',20),(4,3,'Goats',30);
SELECT f.farmer_name, SUM(ar.quantity) as total_animals FROM farmer f INNER JOIN animal_rearing ar ON f.farmer_id = ar.farmer_id WHERE f.region = 'region2' GROUP BY f.farmer_name;
What is the total timber production in mangrove forests in India?
CREATE TABLE TimberProduction (id INT,name VARCHAR(255),region VARCHAR(255),year INT,production FLOAT); INSERT INTO TimberProduction (id,name,region,year,production) VALUES (1,'Mangrove Forest','India',2015,2000);
SELECT SUM(production) FROM TimberProduction WHERE name = 'Mangrove Forest' AND region = 'India';
Remove expired contracts from the database
CREATE TABLE contracts(id INT,expiration_date DATE);INSERT INTO contracts(id,expiration_date) VALUES (1,'2021-12-31');
DELETE FROM contracts WHERE expiration_date < CURDATE();
What is the total number of smart contracts for each country?
CREATE TABLE smart_contracts (country VARCHAR(255),smart_contract_count INT); INSERT INTO smart_contracts (country,smart_contract_count) VALUES ('US',3000),('Japan',1500),('Germany',2000);
SELECT country, SUM(smart_contract_count) OVER (PARTITION BY country) FROM smart_contracts;
How many tourists visited Australia in 2018 from Asia, Oceania, and Africa?
CREATE TABLE tourism_data (visitor_country VARCHAR(50),destination_country VARCHAR(50),visit_year INT); INSERT INTO tourism_data (visitor_country,destination_country,visit_year) VALUES ('China','Australia',2018),('India','Australia',2018),('New Zealand','Australia',2018),('South Africa','Australia',2018),('Egypt','Australia',2018);
SELECT SUM(*) FROM tourism_data WHERE visitor_country LIKE 'Asia%' OR visitor_country LIKE 'Oceania%' OR visitor_country LIKE 'Africa%' AND visit_year = 2018 AND destination_country = 'Australia';
How many items were produced in each region last year?
CREATE TABLE regions (id INT,name TEXT,country TEXT); INSERT INTO regions (id,name,country) VALUES (1,'Region 1','Country A'),(2,'Region 2','Country B'); CREATE TABLE production (id INT,region_id INT,year INT,quantity INT); INSERT INTO production (id,region_id,year,quantity) VALUES (1,1,2020,100),(2,1,2021,120),(3,2,2020,80),(4,2,2021,90);
SELECT regions.name, YEAR(production.year), SUM(production.quantity) FROM regions INNER JOIN production ON regions.id = production.region_id GROUP BY regions.name, YEAR(production.year);
What is the lowest dissolved oxygen level in the Pacific Ocean for tuna farms?
CREATE TABLE Pacific_Ocean (id INT,dissolved_oxygen DECIMAL(5,2)); INSERT INTO Pacific_Ocean (id,dissolved_oxygen) VALUES (1,6.5),(2,7.2),(3,5.9); CREATE TABLE Tuna_Farms (id INT,ocean VARCHAR(20)); INSERT INTO Tuna_Farms (id,ocean) VALUES (1,'Pacific'),(2,'Indian'),(3,'Pacific');
SELECT MIN(Pacific_Ocean.dissolved_oxygen) FROM Pacific_Ocean INNER JOIN Tuna_Farms ON Pacific_Ocean.id = Tuna_Farms.id WHERE Tuna_Farms.ocean = 'Pacific';
Which heritage centers have the highest and lowest attendance by gender?
CREATE TABLE heritage_centers (id INT,center_name VARCHAR(255),center_date DATE,visitor_gender VARCHAR(255),visitor_count INT);
SELECT center_name, visitor_gender, SUM(visitor_count) as total_visitors FROM heritage_centers GROUP BY center_name, visitor_gender ORDER BY total_visitors DESC, center_name;
What is the most common art movement in the 'Art_Movement' table?
CREATE TABLE Art_Movement (movement_id INT,movement_name VARCHAR(255),popularity INT);
SELECT movement_name FROM Art_Movement ORDER BY popularity DESC LIMIT 1;
What was the average sale value of military equipment sold to African countries in 2020?
CREATE TABLE EquipmentSalesByCountry (id INT PRIMARY KEY,year INT,country VARCHAR(50),equipment_type VARCHAR(50),sale_value FLOAT); INSERT INTO EquipmentSalesByCountry (id,year,country,equipment_type,sale_value) VALUES (1,2020,'Nigeria','Armored Vehicles',500000); INSERT INTO EquipmentSalesByCountry (id,year,country,equipment_type,sale_value) VALUES (2,2020,'Egypt','Artillery',1000000);
SELECT AVG(sale_value) FROM EquipmentSalesByCountry WHERE year = 2020 AND country IN ('Nigeria', 'Egypt', 'South Africa', 'Algeria', 'Morocco');
Which exhibitions were visited by visitors from outside the country?
CREATE TABLE Exhibition1 (visitor_id INT,date DATE,country VARCHAR(255),primary key(visitor_id,date)); INSERT INTO Exhibition1 VALUES (1,'2021-01-01','USA'),(2,'2021-01-01','Canada'); CREATE TABLE Exhibition2 (visitor_id INT,date DATE,country VARCHAR(255),primary key(visitor_id,date)); INSERT INTO Exhibition2 VALUES (3,'2021-01-01','USA'),(4,'2021-01-02','Mexico');
SELECT visitor_id, date FROM Exhibition1 WHERE country != 'USA' INTERSECT SELECT visitor_id, date FROM Exhibition2 WHERE country != 'USA';
Calculate hospitals with over 10 cultural competency trainings.
CREATE TABLE cultural_competency (id INT PRIMARY KEY,hospital_id INT,training_date DATE,trainer_id INT); CREATE VIEW cultural_competency_view AS SELECT hospital_id,COUNT(*) as trainings_count FROM cultural_competency GROUP BY hospital_id;
SELECT hospital_id, AVG(trainings_count) as avg_trainings FROM cultural_competency_view GROUP BY hospital_id HAVING AVG(trainings_count) > 10;
Identify the top 3 cities with the highest CO2 emissions per capita for each continent in 2015, using the 'CityCO2' table.
CREATE TABLE CityCO2 (City VARCHAR(50),Continent VARCHAR(50),CO2_Emissions INT,Population INT); INSERT INTO CityCO2 (City,Continent,CO2_Emissions,Population) VALUES ('Delhi','Asia',42000000,30000000),('Tokyo','Asia',30000000,37400000),('Sydney','Australia',12000000,5400000),('Rio de Janeiro','South America',8000000,6700000),('New York','North America',6000000,8500000);
SELECT City, Continent, CO2_Emissions/Population AS CO2_PerCapita FROM CityCO2 WHERE Year = 2015 GROUP BY City, Continent ORDER BY Continent, CO2_PerCapita DESC LIMIT 3;
How many times has a specific IP address appeared in the 'threat_intel' table?
CREATE TABLE threat_intel (id INT,ip_address VARCHAR(50),threat_date DATE);
SELECT ip_address, COUNT(*) as appearance_count FROM threat_intel WHERE ip_address = 'specific_ip_address' GROUP BY ip_address;
List all arctic research stations in Russia and their respective altitudes.
CREATE TABLE ResearchStations (name TEXT,country TEXT,altitude INTEGER);
SELECT name, altitude FROM ResearchStations WHERE country = 'Russia';
List the top 5 strains sold by total revenue in the state of Colorado in 2022.
CREATE TABLE strain_sales (id INT,strain_name VARCHAR(255),dispensary_name VARCHAR(255),state VARCHAR(255),sales_amount DECIMAL(10,2),sale_date DATE);
SELECT strain_name, SUM(sales_amount) FROM strain_sales WHERE state = 'Colorado' AND sale_date BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY strain_name ORDER BY SUM(sales_amount) DESC LIMIT 5;
Identify the number of vessels in the 'High Risk' category and their corresponding categories.
CREATE TABLE vessel_safety_multi (vessel_name VARCHAR(255),category VARCHAR(255)); INSERT INTO vessel_safety_multi (vessel_name,category) VALUES ('Titanic','High Risk'),('Queen Mary 2','Medium Risk'),('Andrea Gail','High Risk');
SELECT category, COUNT(*) FROM vessel_safety_multi WHERE category = 'High Risk' GROUP BY category;
Update the genre of a song in the database
CREATE TABLE Genre (id INT,genre VARCHAR(255)); CREATE TABLE Song (id INT,genre_id INT,title VARCHAR(255),playtime INT);
UPDATE Song SET genre_id = (SELECT id FROM Genre WHERE genre = 'Pop') WHERE title = 'Bohemian Rhapsody';
What percentage of consumers prefer matte lipsticks by region?
CREATE TABLE consumer_preferences (consumer_id INT,region VARCHAR(20),lipstick_preference VARCHAR(20)); INSERT INTO consumer_preferences (consumer_id,region,lipstick_preference) VALUES (1,'North','Matte'),(2,'South','Shimmer'),(3,'East','Matte'),(4,'West','Gloss'),(5,'North','Shimmer'),(6,'South','Matte'),(7,'East','Gloss'),(8,'West','Shimmer');
SELECT region, 100.0 * AVG(CASE WHEN lipstick_preference = 'Matte' THEN 1.0 ELSE 0.0 END) as matte_percentage FROM consumer_preferences GROUP BY region;
List all intelligence operations and their related military technologies?
CREATE TABLE intelligence_operations (id INT,operation_name VARCHAR(50),country VARCHAR(50)); CREATE TABLE military_technologies (id INT,technology_name VARCHAR(50),operation_id INT); INSERT INTO intelligence_operations (id,operation_name,country) VALUES (1,'Operation Desert Storm','USA'),(2,'Operation Enduring Freedom','USA'),(3,'Operation Slipper','Australia'); INSERT INTO military_technologies (id,technology_name,operation_id) VALUES (1,'M1 Abrams Tank',1),(2,'Predator Drone',2),(3,'Joint Strike Fighter',2),(4,'Collins Class Submarine',3);
SELECT intelligence_operations.operation_name, military_technologies.technology_name FROM intelligence_operations INNER JOIN military_technologies ON intelligence_operations.id = military_technologies.operation_id;
How many military vehicles did 'Raytheon Technologies' sell in '2022'?
CREATE TABLE Military_Equipment_Sales (seller VARCHAR(255),equipment VARCHAR(255),year INT,quantity INT); INSERT INTO Military_Equipment_Sales (seller,equipment,year,quantity) VALUES ('Raytheon Technologies','Fighter Jet',2022,120),('Raytheon Technologies','Missile System',2022,180);
SELECT SUM(quantity) FROM Military_Equipment_Sales WHERE seller = 'Raytheon Technologies' AND year = 2022;
What is the total contract amount for projects managed by licensed contractors from Florida?
CREATE TABLE Contractors (Id INT,Name VARCHAR(50),LicenseNumber VARCHAR(50),City VARCHAR(50),State VARCHAR(2),Specialty VARCHAR(50)); CREATE TABLE ContractorProjects (ContractorId INT,ProjectId INT,ContractStartDate DATE,ContractEndDate DATE,ContractAmount DECIMAL(10,2));
SELECT SUM(cp.ContractAmount) FROM ContractorProjects cp JOIN Contractors c ON cp.ContractorId = c.Id WHERE c.State = 'FL' AND c.LicenseNumber IS NOT NULL;
What is the average donation amount by region?
CREATE TABLE Donations (DonationID INT PRIMARY KEY,DonationAmount DECIMAL(10,2),DonationDate DATE,Region VARCHAR(50));
SELECT AVG(DonationAmount) as AverageDonation, Region FROM Donations GROUP BY Region;
Show the number of unique countries where Europium production occurred between 2010 and 2020, sorted alphabetically.
CREATE TABLE Producers (ProducerID INT PRIMARY KEY,Name TEXT,ProductionYear INT,RareEarth TEXT,Quantity INT,Location TEXT);
SELECT COUNT(DISTINCT Location) FROM Producers WHERE RareEarth = 'Europium' AND ProductionYear BETWEEN 2010 AND 2020 ORDER BY Location ASC;
What is the correlation between the age of attendees and the amount donated to dance programs, if any?
CREATE TABLE Donors (DonorID INT,DonorName VARCHAR(50),Age INT); CREATE TABLE DancePrograms (ProgramID INT,ProgramName VARCHAR(50),Date DATE,TotalDonation DECIMAL(10,2)); CREATE TABLE ProgramDonors (ProgramID INT,DonorID INT,FOREIGN KEY (ProgramID) REFERENCES DancePrograms(ProgramID),FOREIGN KEY (DonorID) REFERENCES Donors(DonorID));
SELECT CORR(Donors.Age, DancePrograms.TotalDonation) FROM Donors INNER JOIN ProgramDonors ON Donors.DonorID = ProgramDonors.DonorID INNER JOIN DancePrograms ON ProgramDonors.ProgramID = DancePrograms.ProgramID;
What is the number of workplace injuries for each union, by union name, in the year 2021, pivoted by month?
CREATE TABLE union_table_2021 (union_name VARCHAR(255),total_injuries INT,incident_date DATE); INSERT INTO union_table_2021 (union_name,total_injuries,incident_date) VALUES ('Union A',350,'2021-01-01'),('Union B',450,'2021-02-01'),('Union C',550,'2021-03-01'),('Union D',600,'2021-04-01');
SELECT union_name, SUM(CASE WHEN MONTH(incident_date) = 1 THEN total_injuries ELSE 0 END) as january, SUM(CASE WHEN MONTH(incident_date) = 2 THEN total_injuries ELSE 0 END) as february, SUM(CASE WHEN MONTH(incident_date) = 3 THEN total_injuries ELSE 0 END) as march, SUM(CASE WHEN MONTH(incident_date) = 4 THEN total_injuries ELSE 0 END) as april FROM union_table_2021 GROUP BY union_name;
How many electric vehicle charging stations are in each state?
CREATE TABLE states (id INT,name VARCHAR(50)); CREATE TABLE charging_stations (id INT,state_id INT,station_count INT); INSERT INTO states (id,name) VALUES (1,'California'),(2,'Texas'),(3,'Florida'); INSERT INTO charging_stations (id,state_id,station_count) VALUES (1,1,500),(2,2,700),(3,3,800);
SELECT s.name, SUM(cs.station_count) FROM states s JOIN charging_stations cs ON s.id = cs.state_id GROUP BY s.name;
What is the average age of individuals with financial capability in South Africa?
CREATE TABLE financial_capability (id INT,individual_id INT,age INT,country VARCHAR(255)); INSERT INTO financial_capability (id,individual_id,age,country) VALUES (1,3001,50,'South Africa'),(2,3002,55,'South Africa'),(3,3003,45,'South Africa');
SELECT AVG(age) FROM financial_capability WHERE country = 'South Africa';
Delete fish health data for a specific fish species
CREATE TABLE species_health (id INT,species VARCHAR(50),health_score INT); INSERT INTO species_health
DELETE FROM species_health WHERE species = 'Tuna';
What was the average energy storage capacity (in MWh) of wind power in Texas for the year 2019?
CREATE TABLE energy_storage (state VARCHAR(20),year INT,energy_source VARCHAR(20),capacity_mwh FLOAT); INSERT INTO energy_storage (state,year,energy_source,capacity_mwh) VALUES ('Texas',2019,'Wind',3000),('Texas',2019,'Wind',3200),('Texas',2019,'Wind',2800),('Texas',2019,'Solar',1500),('Texas',2019,'Solar',1700);
SELECT AVG(capacity_mwh) AS avg_capacity_mwh FROM energy_storage WHERE state = 'Texas' AND year = 2019 AND energy_source = 'Wind';
What are the number of vulnerabilities and the number of high severity vulnerabilities for each country in the past month?
CREATE TABLE vulnerabilities (id INT,title TEXT,description TEXT,country TEXT,severity TEXT,created_at DATETIME); INSERT INTO vulnerabilities (id,title,description,country,severity,created_at) VALUES (1,'Vuln1','Desc1','USA','High','2022-01-01 10:00:00'),(2,'Vuln2','Desc2','Canada','Medium','2022-01-02 11:00:00'); CREATE TABLE systems (id INT,name TEXT,vulnerability_id INT,country TEXT); INSERT INTO systems (id,name,vulnerability_id,country) VALUES (1,'Sys1',1,'USA'),(2,'Sys2',2,'Canada');
SELECT country, COUNT(*) as total_vulnerabilities, SUM(CASE WHEN severity = 'High' THEN 1 ELSE 0 END) as high_severity_vulnerabilities FROM vulnerabilities WHERE created_at >= NOW() - INTERVAL 1 MONTH GROUP BY country;
Calculate the total number of policies and total claim amount for policyholders from Texas with a home insurance policy.
CREATE TABLE Policyholder (PolicyholderID INT,State VARCHAR(255),PolicyType VARCHAR(255),ClaimAmount DECIMAL(10,2)); INSERT INTO Policyholder VALUES (1,'TX','Home',5000),(2,'NY','Home',7000),(3,'NJ','Auto',8000),(4,'CA','Life',6000),(5,'TX','Home',9000);
SELECT COUNT(*) as TotalPolicies, SUM(ClaimAmount) as TotalClaimAmount FROM Policyholder WHERE State = 'TX' AND PolicyType = 'Home';
Count the number of articles published per month in the 'news_articles' table
CREATE TABLE news_articles (article_id INT,author_name VARCHAR(50),title VARCHAR(100),published_date DATE);
SELECT to_char(published_date, 'YYYY-MM') as year_month, COUNT(article_id) as articles_per_month FROM news_articles GROUP BY year_month;
What is the total number of personnel in each type of military base?
CREATE SCHEMA if not exists national_sec AUTHORIZATION defsec;CREATE TABLE if not exists national_sec.bases (id INT,name VARCHAR(100),type VARCHAR(50),personnel INT);INSERT INTO national_sec.bases (id,name,type,personnel) VALUES (1,'Fort Bragg','Army Base',50000);INSERT INTO national_sec.bases (id,name,type,personnel) VALUES (2,'Camp Pendleton','Marine Corps Base',35000);INSERT INTO national_sec.bases (id,name,type,personnel) VALUES (3,'NSA Maryland','SIGINT Base',25000);
SELECT type, SUM(personnel) as total_personnel FROM national_sec.bases GROUP BY type;
What is the sum of sales for each artist's artwork?
CREATE TABLE Artists (ArtistID INT,Name VARCHAR(100),Nationality VARCHAR(50)); INSERT INTO Artists VALUES (1,'Frida Kahlo','Mexican'); CREATE TABLE Artwork (ArtworkID INT,Title VARCHAR(100),Type VARCHAR(50),Price FLOAT,ArtistID INT); INSERT INTO Artwork VALUES (1,'The Two Fridas','Painting',800000,1); INSERT INTO Artwork VALUES (2,'Self-Portrait with Cropped Hair','Painting',600000,1);
SELECT AR.Name, SUM(A.Price) FROM Artwork A JOIN Artists AR ON A.ArtistID = AR.ArtistID GROUP BY AR.Name;
Display the neighborhoods in New York with more than 100 affordable units.
CREATE TABLE ny_units(id INT,address VARCHAR(50),wheelchair_access BOOLEAN,affordable BOOLEAN); INSERT INTO ny_units VALUES (1,'123 Main St',true,true),(2,'456 Elm St',false,true); CREATE TABLE ny_neighborhoods(id INT,name VARCHAR(30),unit_id INT); INSERT INTO ny_neighborhoods VALUES (1,'Manhattan',1),(2,'Brooklyn',2);
SELECT ny_neighborhoods.name FROM ny_neighborhoods JOIN ny_units ON ny_neighborhoods.unit_id = ny_units.id WHERE ny_units.affordable = true GROUP BY name HAVING COUNT(DISTINCT ny_units.id) > 100;
Find the top 5 volunteers by total hours contributed in the last 6 months, including their contact information and number of projects they worked on.
CREATE TABLE volunteers (id INT,name VARCHAR(50),email VARCHAR(50),phone VARCHAR(15),total_hours DECIMAL(10,2),last_project_date DATE); INSERT INTO volunteers (id,name,email,phone,total_hours,last_project_date) VALUES (1,'Alice Johnson','alicej@email.com','555-123-4567',35.5,'2022-03-20'),(2,'Bob Brown','bobb@email.com','555-987-6543',70.0,'2022-02-01'); CREATE TABLE projects (id INT,title VARCHAR(50),volunteer_id INT,project_date DATE); INSERT INTO projects (id,title,volunteer_id,project_date) VALUES (1,'Project A',1,'2022-01-15'),(2,'Project B',2,'2022-02-05');
SELECT v.name, v.email, v.phone, v.total_hours, v.last_project_date, COUNT(p.id) AS projects_worked_on FROM volunteers v INNER JOIN projects p ON v.id = p.volunteer_id WHERE v.total_hours > 0 AND v.last_project_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH) GROUP BY v.id ORDER BY v.total_hours DESC LIMIT 5;
What is the total donation amount per donor, ordered by the total donation amount in descending order, with a running total of donations for each donor?
CREATE TABLE Donors (DonorID int,DonorName varchar(50),DonationAmount decimal(10,2)); INSERT INTO Donors (DonorID,DonorName,DonationAmount) VALUES (1,'John Doe',500.00),(2,'Jane Smith',300.00),(3,'Mike Johnson',700.00);
SELECT DonorName, DonationAmount, SUM(DonationAmount) OVER (PARTITION BY DonorName ORDER BY DonationAmount) AS RunningTotalDonation FROM Donors ORDER BY DonationAmount DESC;
What is the total number of union workers in the 'healthcare' sector and the 'mining' sector?
CREATE TABLE union_workers (id INT,sector VARCHAR(20)); INSERT INTO union_workers (id,sector) VALUES (1,'healthcare'),(2,'mining'),(3,'healthcare');
SELECT sector, COUNT(*) as total_workers FROM union_workers WHERE sector IN ('healthcare', 'mining') GROUP BY sector;
What is the maximum depth of all trenches located in the Atlantic?
CREATE TABLE ocean_trenches (trench_id INT,name TEXT,location TEXT,max_depth INT);
SELECT MAX(max_depth) FROM ocean_trenches WHERE location LIKE '%Atlantic%';
Add a new column power_source in the auto_shows table and update it with the appropriate values.
CREATE TABLE auto_shows (id INT PRIMARY KEY,name VARCHAR(50),location VARCHAR(50),start_date DATE,end_date DATE);
ALTER TABLE auto_shows ADD COLUMN power_source VARCHAR(50); UPDATE auto_shows SET power_source = 'internal combustion engine' WHERE start_date < '2020-01-01'; UPDATE auto_shows SET power_source = 'electric' WHERE start_date >= '2020-01-01';
What is the average installed capacity for wind farms in the clean_energy schema, grouped by country?
CREATE TABLE wind_farms (id INT,name VARCHAR(50),location VARCHAR(50),installed_capacity FLOAT,country VARCHAR(50)); INSERT INTO wind_farms (id,name,location,installed_capacity,country) VALUES (1,'Wind Farm 1','Country A',120.5,'Country A'); INSERT INTO wind_farms (id,name,location,installed_capacity,country) VALUES (2,'Wind Farm 2','Country B',250.8,'Country B');
SELECT country, AVG(installed_capacity) FROM clean_energy.wind_farms GROUP BY country;
What is the total revenue generated from music events, and how many unique artists have participated in these events?
CREATE TABLE MusicEvents (EventID INT,EventName VARCHAR(50),Date DATE,TicketPrice DECIMAL(10,2)); CREATE TABLE EventArtists (EventID INT,ArtistID INT,FOREIGN KEY (EventID) REFERENCES MusicEvents(EventID),FOREIGN KEY (ArtistID) REFERENCES Artists(ArtistID));
SELECT SUM(MusicEvents.TicketPrice), COUNT(DISTINCT EventArtists.ArtistID) FROM MusicEvents INNER JOIN EventArtists ON MusicEvents.EventID = EventArtists.EventID;
How many cases were resolved through alternative_dispute_resolution methods?
CREATE TABLE alternative_dispute_resolution (id INT,case_id INT,method TEXT,outcome TEXT);
SELECT COUNT(*) FROM alternative_dispute_resolution WHERE outcome = 'resolved';
How many military innovation projects were completed by each division in Q3 of 2019?
CREATE TABLE MilitaryInnovation (Quarter VARCHAR(10),Division VARCHAR(50),Projects INT); INSERT INTO MilitaryInnovation (Quarter,Division,Projects) VALUES ('Q3 2019','Engineering',15),('Q3 2019','Research',20),('Q3 2019','Development',18);
SELECT Division, COUNT(Projects) FROM MilitaryInnovation WHERE Quarter = 'Q3 2019' GROUP BY Division;
Create a table named 'product_preferences' to store consumer preference data
CREATE TABLE product_preferences (id INT PRIMARY KEY,consumer_id INT,product_id INT,preference TEXT);
CREATE TABLE product_preferences (id INT PRIMARY KEY, consumer_id INT, product_id INT, preference TEXT);
What is the top genre played by players in country B?
CREATE TABLE player_game_preferences (player_id INT,country VARCHAR(20),genre VARCHAR(20));
SELECT country, MAX(genre) FROM player_game_preferences WHERE country = 'B';
How many products are made with recycled materials in each category?
CREATE TABLE products (product_id INT,category TEXT,is_recycled BOOLEAN); INSERT INTO products (product_id,category,is_recycled) VALUES (1,'Clothing',true),(2,'Electronics',false),(3,'Furniture',true);
SELECT category, COUNT(*) FROM products WHERE is_recycled = true GROUP BY category;
List all the startups founded by Indigenous individuals in the renewable energy sector.
CREATE TABLE startups(id INT,name TEXT,founder_identity TEXT); INSERT INTO startups VALUES (1,'Acme Inc','Indigenous'); INSERT INTO startups VALUES (2,'Beta Corp','Non-Indigenous'); CREATE TABLE industries(id INT,name TEXT); INSERT INTO industries VALUES (1,'Renewable Energy'); INSERT INTO industries VALUES (2,'Non-Renewable Energy'); CREATE TABLE startup_industries(startup_id INT,industry_id INT); INSERT INTO startup_industries VALUES (1,1); INSERT INTO startup_industries VALUES (2,2);
SELECT startups.name FROM startups INNER JOIN startup_industries ON startups.id = startup_industries.startup_id INNER JOIN industries ON startup_industries.industry_id = industries.id WHERE startups.founder_identity = 'Indigenous' AND industries.name = 'Renewable Energy';
What was the total amount donated by the 'Happy Hearts Foundation' in the year 2020?
CREATE TABLE Donors (donor_id INT,donor_name VARCHAR(50),amount DECIMAL(10,2),donation_year INT); INSERT INTO Donors (donor_id,donor_name,amount,donation_year) VALUES (1,'Happy Hearts Foundation',7000.00,2020),(2,'Happy Hearts Foundation',6000.00,2020);
SELECT SUM(amount) FROM Donors WHERE donor_name = 'Happy Hearts Foundation' AND donation_year = 2020;
What is the maximum journey time of autonomous buses in Sydney?
CREATE TABLE autonomous_buses_journey_time (bus_id INT,journey_time INT,city VARCHAR(50));
SELECT MAX(journey_time) FROM autonomous_buses_journey_time WHERE city = 'Sydney';
What was the average gift size in H2 2021 for nonprofits in the Education sector?
CREATE TABLE donations (id INT,donation_date DATE,sector TEXT,amount DECIMAL(10,2)); INSERT INTO donations (id,donation_date,sector,amount) VALUES (13,'2021-07-01','Education',100.00),(14,'2021-08-15','Healthcare',250.50),(15,'2021-09-30','Education',150.25);
SELECT AVG(amount) FROM donations WHERE sector = 'Education' AND donation_date BETWEEN '2021-07-01' AND '2021-12-31';
List all investment strategies with ESG scores above 80.
CREATE TABLE investment_strategies (strategy_id INT,sector VARCHAR(20),ESG_score FLOAT); INSERT INTO investment_strategies (strategy_id,sector,ESG_score) VALUES (101,'renewable_energy',82.5),(102,'sustainable_agriculture',78.3),(103,'green_transportation',85.1);
SELECT * FROM investment_strategies WHERE ESG_score > 80;
Count the number of visitors who viewed the 'Impressionist Art' exhibition but didn't donate?
CREATE TABLE DonationEvents (DonationEventID INT,DonationID INT,ArtworkID INT,VisitorID INT);
SELECT COUNT(DISTINCT v.VisitorID) FROM Visitors v LEFT JOIN DonationEvents de ON v.VisitorID = de.VisitorID JOIN Artworks a ON v.VisitorID = a.VisitorID JOIN Exhibitions e ON a.ExhibitionID = e.ExhibitionID WHERE e.ExhibitionName = 'Impressionist Art' AND de.DonationEventID IS NULL;
Calculate the total number of troops deployed in peacekeeping operations by each country from the 'Troops' and 'Countries' tables
CREATE TABLE Troops (country TEXT,troops INT); CREATE TABLE Countries (country TEXT,peacekeeping_operation TEXT); INSERT INTO Troops (country,troops) VALUES ('United States',500),('China',700),('Russia',600),('Bangladesh',900),('Pakistan',800); INSERT INTO Countries (country,peacekeeping_operation) VALUES ('United States','MINUSMA'),('China','MONUSCO'),('Russia','UNMISS'),('Bangladesh','MINUSTAH'),('Pakistan','MINURSO');
SELECT Countries.country, SUM(Troops.troops) AS total_troops FROM Countries INNER JOIN Troops ON Countries.country = Troops.country GROUP BY Countries.country;
Delete all claims processed by 'John Doe'.
CREATE TABLE claim (claim_id INT,processed_by VARCHAR(50)); INSERT INTO claim VALUES (1,'Laura Smith'); INSERT INTO claim VALUES (2,'John Doe');
DELETE FROM claim WHERE processed_by = 'John Doe';