instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the maximum number of days between two consecutive security incidents for the government sector?
create table incidents (id int,date date,sector varchar(255)); insert into incidents values (1,'2021-01-01','government'); insert into incidents values (2,'2021-01-05','government'); insert into incidents values (3,'2021-01-10','government'); insert into incidents values (4,'2021-01-20','healthcare');
SELECT DATEDIFF(date, LAG(date) OVER (PARTITION BY sector ORDER BY date)) FROM incidents WHERE sector = 'government' ORDER BY date DESC LIMIT 1;
Which artists from Asia have the most pieces in the modern art category?
CREATE TABLE Artists (ArtistID int,Name varchar(50),Nationality varchar(50)); CREATE TABLE ArtPieces (ArtPieceID int,Title varchar(50),YearCreated int,ArtistID int,MovementID int); CREATE TABLE ArtMovements (MovementID int,Name varchar(50));
SELECT Artists.Name, COUNT(ArtPieces.ArtPieceID) AS ArtPiecesCount FROM Artists INNER JOIN ArtPieces ON Artists.ArtistID = ArtPieces.ArtistID INNER JOIN ArtMovements ON ArtPieces.MovementID = ArtMovements.MovementID WHERE Artists.Nationality LIKE 'Asia%' AND ArtMovements.Name = 'Modern Art' GROUP BY Artists.Name ORDER BY ArtPiecesCount DESC;
How many workers in the 'Manufacturing' industry have a 'Part-time' status?
CREATE TABLE Workers (id INT,industry VARCHAR(20),employment_status VARCHAR(20)); INSERT INTO Workers (id,industry,employment_status) VALUES (1,'Manufacturing','Part-time'),(2,'Retail','Full-time'),(3,'Manufacturing','Full-time');
SELECT COUNT(*) FROM Workers WHERE industry = 'Manufacturing' AND employment_status = 'Part-time';
Who is the garment manufacturer with the highest sustainability rating in 'South America'?
CREATE TABLE manufacturer_ratings(name VARCHAR(50),location VARCHAR(50),sustainability_rating INT); INSERT INTO manufacturer_ratings (name,location,sustainability_rating) VALUES ('EcoClothes','Brazil',93); INSERT INTO manufacturer_ratings (name,location,sustainability_rating) VALUES ('GreenSeams','Argentina',89);
SELECT name, sustainability_rating FROM manufacturer_ratings WHERE location = 'South America' ORDER BY sustainability_rating DESC LIMIT 1;
What is the average number of security incidents per month for each region?
CREATE TABLE monthly_incidents (id INT,incident_month DATE,region VARCHAR(255)); INSERT INTO monthly_incidents (id,incident_month,region) VALUES (1,'2022-01-01','APAC'),(2,'2022-02-01','EMEA'),(3,'2022-03-01','AMER');
SELECT region, AVG(EXTRACT(MONTH FROM incident_month)) FROM monthly_incidents GROUP BY region;
What was the maximum daily water consumption in the 'DailyWaterUsage' table in July 2022?
CREATE TABLE DailyWaterUsage (ID INT,Date DATE,WaterAmount FLOAT); INSERT INTO DailyWaterUsage (ID,Date,WaterAmount) VALUES (1,'2022-07-01',12000); INSERT INTO DailyWaterUsage (ID,Date,WaterAmount) VALUES (2,'2022-07-02',15000);
SELECT Date, WaterAmount, ROW_NUMBER() OVER (PARTITION BY Date ORDER BY WaterAmount DESC) as Rank FROM DailyWaterUsage WHERE Rank = 1 AND Date BETWEEN '2022-07-01' AND '2022-07-31';
What is the average healthcare provider salary in the "rural_clinics" table, partitioned by clinic location and healthcare provider specialty?
CREATE TABLE rural_clinics (clinic_location VARCHAR(255),healthcare_provider_specialty VARCHAR(255),healthcare_provider_salary INT); INSERT INTO rural_clinics (clinic_location,healthcare_provider_specialty,healthcare_provider_salary) VALUES ('Location1','SpecialtyA',100000),('Location1','SpecialtyA',110000),('Location1','SpecialtyB',120000),('Location1','SpecialtyB',130000),('Location2','SpecialtyA',140000),('Location2','SpecialtyA',150000),('Location2','SpecialtyB',160000),('Location2','SpecialtyB',170000);
SELECT clinic_location, healthcare_provider_specialty, AVG(healthcare_provider_salary) OVER (PARTITION BY clinic_location, healthcare_provider_specialty) FROM rural_clinics;
What is the total number of aircraft manufactured by Boeing and Airbus?
CREATE TABLE AircraftManufacturers (ID INT,Name VARCHAR(50),Country VARCHAR(50));INSERT INTO AircraftManufacturers (ID,Name,Country) VALUES (1,'Boeing','USA'),(2,'Airbus','Europe');
SELECT COUNT(*) FROM AircraftManufacturers WHERE Name IN ('Boeing', 'Airbus');
What is the total number of movies, by genre, produced by studios in Canada and Australia?
CREATE TABLE movies (id INT,title VARCHAR(255),genre VARCHAR(255),studio_location VARCHAR(255)); INSERT INTO movies (id,title,genre,studio_location) VALUES (1,'Movie1','Comedy','Canada'),(2,'Movie2','Drama','Australia'); CREATE TABLE studios (id INT,name VARCHAR(255),location VARCHAR(255)); INSERT INTO studios (id,name,location) VALUES (1,'Studio1','Canada'),(2,'Studio2','Australia');
SELECT genre, COUNT(*) as total FROM movies JOIN studios ON movies.studio_location = studios.location WHERE studios.location IN ('Canada', 'Australia') GROUP BY genre;
What is the total revenue generated from memberships in Q1 2022, excluding the members who joined in March 2022 or later?
CREATE SCHEMA fitness; CREATE TABLE membership (member_id INT,member_start_date DATE,membership_fee INT); INSERT INTO membership (member_id,member_start_date,membership_fee) VALUES (1,'2022-01-01',50),(2,'2022-02-01',75),(3,'2022-03-01',100);
SELECT SUM(membership_fee) FROM membership WHERE membership_fee IS NOT NULL AND member_start_date < '2022-03-01' AND member_start_date >= '2022-01-01';
Calculate the percentage of organic farms in each country in the 'farm_data' table.
CREATE TABLE farm_data (farm_id INT,farm_name VARCHAR(255),country VARCHAR(255),is_organic BOOLEAN); INSERT INTO farm_data (farm_id,farm_name,country,is_organic) VALUES (1,'Farm1','CountryA',true),(2,'Farm2','CountryB',false),(3,'Farm3','CountryA',true),(4,'Farm4','CountryC',true),(5,'Farm5','CountryB',true),(6,'Farm6','CountryA',false);
SELECT country, (COUNT(*) FILTER (WHERE is_organic = true)) * 100.0 / COUNT(*) as organic_percentage FROM farm_data GROUP BY country;
Insert a new record for 'Mexico City' with a wind speed of 20 km/h on '2022-10-31'.
CREATE TABLE weather (city VARCHAR(255),wind_speed FLOAT,date DATE);
INSERT INTO weather (city, wind_speed, date) VALUES ('Mexico City', 20, '2022-10-31');
What is the total number of volunteers from the country of Australia?
CREATE TABLE volunteers (id INT,country TEXT); INSERT INTO volunteers (id,country) VALUES (1,'Australia'),(2,'Mexico'),(3,'Australia');
SELECT COUNT(*) FROM volunteers WHERE country = 'Australia';
Show conservation efforts in the South Pacific and their timeframes.
CREATE TABLE conservation_efforts (id INT PRIMARY KEY,species VARCHAR(255),country VARCHAR(255),program VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO conservation_efforts (id,species,country,program,start_date,end_date) VALUES (1,'turtle','New_Zealand','South_Pacific_conservation','2018-01-01','2023-12-31'),(2,'shark','Australia','South_Pacific_protection','2020-01-01','2025-12-31');
SELECT country, program, start_date, end_date FROM conservation_efforts WHERE country IN ('New_Zealand', 'Australia') AND program LIKE '%South_Pacific%';
Identify the number of hospitals in each state that offer mental health services, for hospitals with more than 200 beds.
CREATE TABLE hospitals (hospital_name VARCHAR(50),state VARCHAR(50),num_beds INTEGER,offers_mental_health BOOLEAN); INSERT INTO hospitals (hospital_name,state,num_beds,offers_mental_health) VALUES ('Hospital A','California',250,TRUE),('Hospital B','California',150,FALSE),('Hospital C','Texas',300,TRUE),('Hospital D','Texas',180,TRUE),('Hospital E','New York',220,TRUE),('Hospital F','New York',270,TRUE);
SELECT state, COUNT(*) as num_hospitals FROM hospitals WHERE offers_mental_health = TRUE AND num_beds > 200 GROUP BY state;
What is the total duration of 'Swimming' workouts for each user in the 'workout_data' table?
CREATE TABLE workout_data (user_id INT,workout_type VARCHAR(20),duration INT); INSERT INTO workout_data (user_id,workout_type,duration) VALUES (4,'Swimming',300),(5,'Swimming',420),(4,'Swimming',240),(5,'Swimming',540);
SELECT user_id, SUM(duration) as total_duration FROM workout_data WHERE workout_type = 'Swimming' GROUP BY user_id;
List all countries that have adopted AI in hospitality
CREATE TABLE ai_adoption (country_name VARCHAR(50),adoption_year INT);
SELECT country_name FROM ai_adoption
What is the maximum landfill capacity in gigatons in Europe?
CREATE TABLE landfill_capacity (region TEXT,capacity INT); INSERT INTO landfill_capacity (region,capacity) VALUES ('Asia',500),('Africa',200),('Europe',300),('North America',400);
SELECT MAX(capacity) FROM landfill_capacity WHERE region = 'Europe';
How many genetic research projects were completed each year?
CREATE SCHEMA if not exists genetics; USE genetics; CREATE TABLE if not exists projects (id INT PRIMARY KEY,name VARCHAR(255),completion_date DATE); INSERT INTO projects (id,name,completion_date) VALUES (1,'ProjectX','2017-12-31'),(2,'ProjectY','2018-06-15'),(3,'ProjectZ','2019-04-22'),(4,'ProjectP','2020-02-03'),(5,'ProjectQ','2021-01-01'),(6,'ProjectR','2016-08-08');
SELECT YEAR(completion_date) AS year, COUNT(*) AS completed_projects FROM projects GROUP BY year ORDER BY year;
What is the average 'Population' for animals in the 'AnimalPopulation' table grouped by 'AnimalName'?
CREATE TABLE AnimalPopulation (AnimalID int,AnimalName varchar(50),Population int); INSERT INTO AnimalPopulation (AnimalID,AnimalName,Population) VALUES (1,'Tiger',2500),(2,'Elephant',550),(3,'Giraffe',1100);
SELECT AnimalName, AVG(Population) FROM AnimalPopulation GROUP BY AnimalName;
What is the average fine for each type of violation?
CREATE TABLE Fines (ID INT,Type VARCHAR(30),Fine INT); INSERT INTO Fines (ID,Type,Fine) VALUES (1,'Traffic Violation',50),(2,'Misdemeanor',200),(3,'Felony',1000);
SELECT Type, AVG(Fine) FROM Fines GROUP BY Type;
Identify the top 10% of suppliers with the highest average price of chemicals they supply, ordered by average price in descending order.
CREATE TABLE chemical_inventory (id INT PRIMARY KEY,chemical_name VARCHAR(255),quantity INT,supplier VARCHAR(255),last_updated TIMESTAMP);CREATE TABLE supplier_info (id INT PRIMARY KEY,supplier_name VARCHAR(255),address VARCHAR(255),country VARCHAR(255));CREATE TABLE chemical_prices (id INT PRIMARY KEY,chemical_name VARCHAR(255),price DECIMAL(10,2),price_updated_date DATE);
SELECT s.supplier_name, AVG(cp.price) AS avg_price FROM supplier_info s JOIN chemical_inventory ci ON s.supplier_name = ci.supplier JOIN chemical_prices cp ON ci.chemical_name = cp.chemical_name GROUP BY s.supplier_name ORDER BY avg_price DESC FETCH FIRST 10 PERCENT ROWS ONLY;
Delete all records from 'fair_labor_practices' table where region is 'Asia'.
CREATE TABLE fair_labor_practices (practice_id INT,brand_id INT,region TEXT,workers_benefitted INT);
DELETE FROM fair_labor_practices WHERE region = 'Asia';
What is the total number of animals in each sanctuary, grouped by region?
CREATE TABLE sanctuary_data (sanctuary_id INT,sanctuary_name VARCHAR(255),region VARCHAR(255),animal_type VARCHAR(255),animal_count INT); INSERT INTO sanctuary_data (sanctuary_id,sanctuary_name,region,animal_type,animal_count) VALUES (1,'Sanctuary A','North','Tiger',25),(2,'Sanctuary A','North','Elephant',30),(3,'Sanctuary B','South','Tiger',35),(4,'Sanctuary B','South','Elephant',20),(5,'Sanctuary C','East','Tiger',15),(6,'Sanctuary C','East','Elephant',40),(7,'Sanctuary D','West','Tiger',5),(8,'Sanctuary D','West','Elephant',10),(9,'Sanctuary E','North','Tiger',45),(10,'Sanctuary E','North','Elephant',25);
SELECT region, animal_type, SUM(animal_count) AS total_animals FROM sanctuary_data GROUP BY region, animal_type;
What are the names of attorneys who have handled cases in both the 'North' and 'South' districts?
CREATE TABLE attorney_districts(attorney_id INT,district VARCHAR(20)); INSERT INTO attorney_districts(attorney_id,district) VALUES (1,'North'),(2,'South'),(3,'East'),(4,'West'),(5,'North'),(6,'South'); CREATE TABLE handled_cases(attorney_id INT,case_id INT); INSERT INTO handled_cases(attorney_id,case_id) VALUES (1,101),(2,102),(3,103),(4,104),(5,105),(6,106);
SELECT h.attorney_id FROM attorney_districts h INNER JOIN (SELECT attorney_id FROM attorney_districts WHERE district = 'North' INTERSECT SELECT attorney_id FROM attorney_districts WHERE district = 'South') i ON h.attorney_id = i.attorney_id;
Find the teams that have played more than 50 games in the "nba_games" table
CREATE TABLE nba_games (team VARCHAR(255),games_played INTEGER);
SELECT team FROM nba_games WHERE games_played > 50 GROUP BY team;
How many chemical productions were made per day?
CREATE TABLE ChemicalProduction (date DATE,chemical VARCHAR(10),mass FLOAT); INSERT INTO ChemicalProduction (date,chemical,mass) VALUES ('2021-01-01','A',100),('2021-01-01','B',150),('2021-01-02','A',120),('2021-01-02','B',170);
SELECT date, COUNT(*) as TotalProductions FROM ChemicalProduction GROUP BY date;
What is the difference in average ticket sales between the top performing team and the worst performing team?
CREATE TABLE teams (team_id INT,team_name VARCHAR(255)); INSERT INTO teams (team_id,team_name) VALUES (1,'Knights'),(2,'Lions'),(3,'Titans'); CREATE TABLE events (event_id INT,team_id INT,num_tickets_sold INT,total_seats INT); INSERT INTO events (event_id,team_id,num_tickets_sold,total_seats) VALUES (1,1,500,1000),(2,1,700,1000),(3,2,600,1200),(4,3,800,1500),(5,3,900,1500);
SELECT AVG(e1.num_tickets_sold) - AVG(e2.num_tickets_sold) as difference_in_avg_tickets_sold FROM events e1, events e2 WHERE e1.team_id = (SELECT team_id FROM teams t JOIN events e ON t.team_id = e.team_id GROUP BY e.team_id ORDER BY AVG(e.num_tickets_sold) DESC LIMIT 1) AND e2.team_id = (SELECT team_id FROM teams t JOIN events e ON t.team_id = e.team_id GROUP BY e.team_id ORDER BY AVG(e.num_tickets_sold) ASC LIMIT 1);
What is the total number of students who have utilized assistive technology?
CREATE TABLE Assistive_Technology (student_id INT,accommodation VARCHAR(255)); INSERT INTO Assistive_Technology VALUES (1,'Text-to-Speech');
SELECT COUNT(DISTINCT student_id) FROM Assistive_Technology
What is the average number of hours volunteered by volunteers in the Food Distribution program?
CREATE TABLE volunteers (id INT,name TEXT,program TEXT,hours INT); INSERT INTO volunteers (id,name,program,hours) VALUES (1,'John Doe','Food Distribution',10),(2,'Jane Smith','Food Distribution',20);
SELECT AVG(hours) FROM volunteers WHERE program = 'Food Distribution';
What is the minimum mental health score for patients who identify as African American or Latino?
CREATE TABLE patient (id INT,name TEXT,mental_health_score INT,community TEXT); INSERT INTO patient (id,name,mental_health_score,community) VALUES (1,'John Doe',60,'Straight'),(2,'Jane Smith',70,'LGBTQ+'),(3,'Ana Garcia',50,'Latino'),(4,'Sara Johnson',80,'African American');
SELECT MIN(mental_health_score) FROM patient WHERE community IN ('African American', 'Latino');
What is the landfill capacity in m3 for 'Africa' in the year 2020?
CREATE TABLE landfill_capacity (region VARCHAR(50),year INT,capacity_m3 FLOAT); INSERT INTO landfill_capacity (region,year,capacity_m3) VALUES ('Africa',2020,5000000),('Africa',2021,6000000);
SELECT capacity_m3 FROM landfill_capacity WHERE region = 'Africa' AND year = 2020;
Find the number of unique artifact types per excavation site?
CREATE TABLE Sites (SiteID INT,SiteName TEXT); INSERT INTO Sites (SiteID,SiteName) VALUES (1,'Site-A'),(2,'Site-B'),(3,'Site-C'); CREATE TABLE Artifacts (ArtifactID INT,ArtifactName TEXT,SiteID INT,ArtifactType TEXT); INSERT INTO Artifacts (ArtifactID,ArtifactName,SiteID,ArtifactType) VALUES (1,'Pottery Shard',1,'Ceramic'),(2,'Bronze Arrowhead',2,'Metal'),(3,'Flint Tool',3,'Stone'),(4,'Ancient Coin',1,'Metal'),(5,'Stone Hammer',2,'Stone');
SELECT Sites.SiteName, COUNT(DISTINCT Artifacts.ArtifactType) AS UniqueArtifactTypes FROM Sites INNER JOIN Artifacts ON Sites.SiteID = Artifacts.SiteID GROUP BY Sites.SiteName;
What is the average number of food safety violations per inspection for each location?
CREATE TABLE food_safety_inspections (location VARCHAR(255),inspection_date DATE,violations INT); INSERT INTO food_safety_inspections (location,inspection_date,violations) VALUES ('Location A','2022-01-01',3),('Location B','2022-01-02',5),('Location A','2022-01-03',2),('Location C','2022-01-04',4),('Location A','2022-01-05',1);
SELECT location, AVG(violations) as average_violations FROM food_safety_inspections GROUP BY location;
What was the total defense diplomacy spending for European nations in 2018?
CREATE TABLE DefenseDiplomacy (nation VARCHAR(50),year INT,spending FLOAT); INSERT INTO DefenseDiplomacy (nation,year,spending) VALUES ('France',2018,25000000),('Germany',2018,30000000),('United Kingdom',2018,35000000),('Italy',2018,22000000),('Spain',2018,28000000);
SELECT SUM(spending) FROM DefenseDiplomacy WHERE nation IN ('France', 'Germany', 'United Kingdom', 'Italy', 'Spain') AND year = 2018;
Which decentralized applications in Asia have the highest daily transaction volumes?
CREATE TABLE dapps (id INT,name VARCHAR(50),region VARCHAR(10),daily_tx_volume INT); INSERT INTO dapps (id,name,region,daily_tx_volume) VALUES (1,'App1','Asia',1000),(2,'App2','Asia',2000),(3,'App3','Asia',3000);
SELECT name, daily_tx_volume, RANK() OVER (ORDER BY daily_tx_volume DESC) as rank FROM dapps WHERE region = 'Asia';
List all explorations in the Gulf of Mexico
CREATE TABLE if not exists dim_exploration (exploration_id INT PRIMARY KEY,exploration_name VARCHAR(255),location VARCHAR(255));
SELECT exploration_name FROM dim_exploration WHERE location = 'Gulf of Mexico';
List all airports in the state of New York
CREATE TABLE Infrastructure (id INT,name VARCHAR(100),type VARCHAR(50),state VARCHAR(50)); INSERT INTO Infrastructure (id,name,type,state) VALUES (1,'Golden Gate Bridge','Bridge','California'); INSERT INTO Infrastructure (id,name,type,state) VALUES (2,'Hoover Dam','Dam','Nevada'); INSERT INTO Infrastructure (id,name,type,state) VALUES (3,'Interstate 10','Road','Texas'); INSERT INTO Infrastructure (id,name,type,state) VALUES (4,'John F. Kennedy International Airport','Airport','New York');
SELECT * FROM Infrastructure WHERE state = 'New York' AND type = 'Airport';
What is the total revenue generated from sustainable garments in the last quarter?
CREATE TABLE RevenueData (RevenueID INT,ProductID INT,Revenue FLOAT,Sustainable BOOLEAN); INSERT INTO RevenueData (RevenueID,ProductID,Revenue,Sustainable) VALUES (1,1001,500,true),(2,1002,600,false),(3,1003,400,true);
SELECT SUM(Revenue) FROM RevenueData WHERE Sustainable = true AND RevenueDate >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH);
What was the most expensive spacecraft?
CREATE TABLE Spacecraft (ID INT,Name VARCHAR(50),Cost FLOAT); INSERT INTO Spacecraft VALUES (1,'Ares',5000000),(2,'Orion',7000000),(3,'Artemis',8000000);
SELECT Name, MAX(Cost) FROM Spacecraft;
What is the total CO2 emissions from Arctic shipping per year?
CREATE TABLE ShippingEmissions(year INT,CO2_emissions FLOAT);
SELECT year, SUM(CO2_emissions) FROM ShippingEmissions GROUP BY year;
What is the average response time for emergency calls in each district?
CREATE TABLE emergency_calls (call_id INT,district TEXT,response_time FLOAT); INSERT INTO emergency_calls (call_id,district,response_time) VALUES (1,'Downtown',10.5),(2,'Uptown',12.0),(3,'Harbor',8.0);
SELECT district, AVG(response_time) FROM emergency_calls GROUP BY district;
Find the hotels in the hotels table that have a higher rating than the average rating of all hotels.
CREATE TABLE hotels (hotel_id INT,name VARCHAR(50),rating FLOAT); INSERT INTO hotels (hotel_id,name,rating) VALUES (1,'Hotel X',4.5),(2,'Hotel Y',4.2),(3,'Hotel Z',4.7);
SELECT * FROM hotels WHERE rating > (SELECT AVG(rating) FROM hotels);
Delete records with a 'license' of 'CC-BY-NC' from the 'open_education_resources' table
CREATE TABLE open_education_resources (resource_id INT PRIMARY KEY,title VARCHAR(100),description TEXT,license VARCHAR(50));
DELETE FROM open_education_resources WHERE license = 'CC-BY-NC';
What is the total installed capacity (in MW) of geothermal power projects in the United States?
CREATE TABLE geothermal_projects (project_id INT,project_name TEXT,country TEXT,capacity_mw FLOAT); INSERT INTO geothermal_projects (project_id,project_name,country,capacity_mw) VALUES (1,'Geothermal Project A','United States',50),(2,'Geothermal Project B','United States',75);
SELECT SUM(capacity_mw) FROM geothermal_projects WHERE country = 'United States';
What is the number of unique donors for each cause area, for donors from African countries, categorized by continent?
CREATE TABLE donors (id INT,name TEXT,country TEXT); CREATE TABLE donations (id INT,donor_id INT,donation_amount FLOAT,organization_id INT); CREATE TABLE organizations (id INT,name TEXT,cause_area TEXT,country TEXT); CREATE TABLE countries (id INT,name TEXT,continent TEXT);
SELECT c.continent, o.cause_area, COUNT(DISTINCT d.id) as num_unique_donors FROM donors d INNER JOIN donations ON d.id = donations.donor_id INNER JOIN organizations o ON donations.organization_id = o.id INNER JOIN countries ON d.country = countries.name WHERE countries.continent = 'Africa' GROUP BY c.continent, o.cause_area;
What is the average threat intelligence score for countries in the Asia-Pacific region in the month of June?
CREATE TABLE threat_intelligence (threat_id INT,country VARCHAR(255),score INT,threat_date DATE); INSERT INTO threat_intelligence (threat_id,country,score,threat_date) VALUES (1,'China',75,'2022-06-01'),(2,'Japan',85,'2022-06-02'),(3,'Australia',65,'2022-06-03');
SELECT AVG(score) FROM threat_intelligence WHERE EXTRACT(MONTH FROM threat_date) = 6 AND country IN ('China', 'Japan', 'Australia');
What is the average budget spent on disability support programs per region?
CREATE TABLE Disability_Support_Programs (Program_ID INT,Program_Name VARCHAR(50),Budget DECIMAL(10,2),Region VARCHAR(50));
SELECT AVG(Budget) as Avg_Budget, Region FROM Disability_Support_Programs GROUP BY Region;
Display the number of customers who have both a socially responsible loan and a high financial capability score
CREATE TABLE customers (customer_id INT,financial_capability_score INT,has_socially_responsible_loan BOOLEAN);
SELECT COUNT(*) FROM customers WHERE financial_capability_score > 7 AND has_socially_responsible_loan = TRUE;
What is the average virtual tour rating for eco-friendly hotels in France?
CREATE TABLE eco_hotels (hotel_id INT,country VARCHAR(50),rating FLOAT); INSERT INTO eco_hotels (hotel_id,country,rating) VALUES (1,'France',4.3),(2,'France',4.6),(3,'Germany',4.5); CREATE TABLE virtual_tours (tour_id INT,hotel_id INT,rating FLOAT); INSERT INTO virtual_tours (tour_id,hotel_id,rating) VALUES (1,1,4.8),(2,2,4.9),(3,3,4.7);
SELECT AVG(vt.rating) FROM virtual_tours vt JOIN eco_hotels eh ON vt.hotel_id = eh.hotel_id WHERE eh.country = 'France';
What is the percentage of the budget allocated to infrastructure in 2021 compared to 2022?
CREATE TABLE BudgetAllocations (Year INT,Service TEXT,Amount INT); INSERT INTO BudgetAllocations (Year,Service,Amount) VALUES (2021,'Infrastructure',12000000),(2022,'Infrastructure',14000000);
SELECT (SUM(CASE WHEN Year = 2022 THEN Amount ELSE 0 END) / SUM(Amount)) * 100.0 FROM BudgetAllocations WHERE Service = 'Infrastructure';
What is the maximum age of employees in the Sales department who have been with the company for more than 5 years?
CREATE TABLE Employees (EmployeeID INT,Department VARCHAR(20),Age INT,YearsWithCompany INT); INSERT INTO Employees (EmployeeID,Department,Age,YearsWithCompany) VALUES (1,'Sales',45,6),(2,'Marketing',30,2),(3,'Sales',50,8);
SELECT MAX(Age) FROM Employees WHERE Department = 'Sales' AND YearsWithCompany > 5;
List all peacekeeping operations led by NATO in 2016.
CREATE TABLE peacekeeping_operations (org_name VARCHAR(255),year INT,operation_name VARCHAR(255)); INSERT INTO peacekeeping_operations (org_name,year,operation_name) VALUES ('NATO',2016,'Resolute Support Mission'),('NATO',2016,'Kosovo Force');
SELECT operation_name FROM peacekeeping_operations WHERE org_name = 'NATO' AND year = 2016;
Which missions did astronaut 'J. Johnson' participate in?
CREATE TABLE Astronauts (id INT,name VARCHAR(255)); CREATE TABLE SpaceMissions (id INT,name VARCHAR(255),astronaut_id INT); INSERT INTO Astronauts (id,name) VALUES (1,'J. Johnson'),(2,'R. Riley'); INSERT INTO SpaceMissions (id,name,astronaut_id) VALUES (1,'Mars Rover',1),(2,'ISS',2);
SELECT SpaceMissions.name FROM SpaceMissions JOIN Astronauts ON SpaceMissions.astronaut_id = Astronauts.id WHERE Astronauts.name = 'J. Johnson';
What is the percentage of households in New Orleans that reduced their water consumption by more than 10% from 2018 to 2019?
CREATE TABLE Household_Water_Usage (Household_ID INT,City VARCHAR(20),Year INT,Water_Consumption FLOAT); INSERT INTO Household_Water_Usage (Household_ID,City,Year,Water_Consumption) VALUES (1,'New Orleans',2018,150.5),(2,'New Orleans',2019,130.2);
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Household_Water_Usage WHERE City = 'New Orleans' AND Year = 2018)) AS Percentage FROM Household_Water_Usage WHERE City = 'New Orleans' AND Year = 2019 AND Water_Consumption (SELECT Water_Consumption * 1.1 FROM Household_Water_Usage WHERE City = 'New Orleans' AND Year = 2018);
List the building permits issued in New York in Q1 2021 and their corresponding project timelines.
CREATE TABLE BuildingPermits (id INT,state VARCHAR(50),permit_number INT,issued_date DATE); INSERT INTO BuildingPermits VALUES (1,'New York',1001,'2021-01-01'); INSERT INTO BuildingPermits VALUES (2,'New York',1002,'2021-02-15'); CREATE TABLE ProjectTimelines (id INT,permit_number INT,start_date DATE,end_date DATE); INSERT INTO ProjectTimelines VALUES (1,1001,'2021-01-05','2021-05-15'); INSERT INTO ProjectTimelines VALUES (2,1002,'2021-03-01','2021-06-30');
SELECT bp.permit_number, bp.issued_date, pt.start_date, pt.end_date FROM BuildingPermits bp JOIN ProjectTimelines pt ON bp.permit_number = pt.permit_number WHERE bp.state = 'New York' AND QUARTER(bp.issued_date) = 1;
What are the top 3 countries by sales of sustainable fabric garments?
CREATE TABLE countries (country_id INT,country_name VARCHAR(255));CREATE TABLE garments (garment_id INT,garment_name VARCHAR(255),country_id INT,price DECIMAL(10,2),is_sustainable BOOLEAN);
SELECT c.country_name, SUM(g.price) AS total_sales FROM garments g JOIN countries c ON g.country_id = c.country_id WHERE g.is_sustainable = TRUE GROUP BY c.country_name ORDER BY total_sales DESC LIMIT 3;
List the geopolitical risk assessments for the Middle East and North Africa in Q3 2019.
CREATE TABLE risk_assessments (id INT,region VARCHAR,assessment_date DATE,risk_level INT); INSERT INTO risk_assessments (id,region,assessment_date,risk_level) VALUES (1,'Middle East','2019-07-22',7); INSERT INTO risk_assessments (id,region,assessment_date,risk_level) VALUES (2,'North Africa','2019-09-10',5); INSERT INTO risk_assessments (id,region,assessment_date,risk_level) VALUES (3,'Middle East','2019-08-03',6);
SELECT region, risk_level FROM risk_assessments WHERE region IN ('Middle East', 'North Africa') AND assessment_date BETWEEN '2019-07-01' AND '2019-09-30';
Get the names of workers and the number of products they have produced
CREATE TABLE workers (id INT,name VARCHAR(20),department VARCHAR(20)); CREATE TABLE products (id INT,worker_id INT,name VARCHAR(20),material VARCHAR(20),quantity INT); INSERT INTO workers (id,name,department) VALUES (1,'Alice','textiles'),(2,'Bob','textiles'),(3,'Charlie','metallurgy'),(4,'Dave','metallurgy'); INSERT INTO products (id,worker_id,name,material,quantity) VALUES (1,1,'beam','steel',100),(2,1,'plate','steel',200),(3,2,'rod','aluminum',150),(4,2,'foil','aluminum',50),(5,3,'gear','steel',250),(6,4,'nut','steel',1000),(7,4,'bolt','steel',1000);
SELECT w.name, COUNT(p.id) FROM workers w INNER JOIN products p ON w.id = p.worker_id GROUP BY w.name;
What is the average water temperature in the Indian Ocean?
CREATE TABLE ocean_temperature (id INT,ocean_name VARCHAR(20),avg_temp DECIMAL(5,2)); INSERT INTO ocean_temperature (id,ocean_name,avg_temp) VALUES (1,'Indian',28.2),(2,'Atlantic',26.7);
SELECT AVG(avg_temp) FROM ocean_temperature WHERE ocean_name = 'Indian';
Update the price of the 'Sushi' menu item to $14.99
CREATE TABLE menu_items (item_name VARCHAR(255),price DECIMAL(10,2)); INSERT INTO menu_items (item_name,price) VALUES ('Pizza',12.99),('Burrito',9.99),('Sushi',13.99);
UPDATE menu_items SET price = 14.99 WHERE item_name = 'Sushi';
What is the total number of satellites and space debris objects in orbit, for each country?
CREATE TABLE satellites (satellite_id INT,country VARCHAR(50)); INSERT INTO satellites (satellite_id,country) VALUES (1,'USA'),(2,'Russia'),(3,'China'),(4,'India'),(5,'Japan'); CREATE TABLE space_debris (debris_id INT,country VARCHAR(50)); INSERT INTO space_debris (debris_id,country) VALUES (1,'USA'),(2,'Russia'),(3,'Germany'),(4,'Canada'),(5,'Australia');
SELECT s.country, COUNT(s.satellite_id) + COUNT(d.debris_id) as total_objects FROM satellites s FULL OUTER JOIN space_debris d ON s.country = d.country GROUP BY s.country;
What is the name and age of the oldest person who received medical assistance in Yemen in 2022?
CREATE TABLE medical_assistance (id INT,name TEXT,age INT,country TEXT,year INT); INSERT INTO medical_assistance (id,name,age,country,year) VALUES (1,'Ali',30,'Yemen',2022),(2,'Fatima',40,'Yemen',2022),(3,'Ahmed',50,'Yemen',2022);
SELECT name, age FROM medical_assistance WHERE country = 'Yemen' AND year = 2022 ORDER BY age DESC LIMIT 1;
What is the minimum number of coral species in the Coral Triangle?
CREATE TABLE coral_species (id INT,location VARCHAR(50),species_name VARCHAR(50),num_species INT); INSERT INTO coral_species (id,location,species_name,num_species) VALUES (1,'Coral Triangle','Acropora',150); INSERT INTO coral_species (id,location,species_name,num_species) VALUES (2,'Coral Triangle','Porites',120);
SELECT MIN(num_species) FROM coral_species WHERE location = 'Coral Triangle';
How many wildlife habitats are in South America?
CREATE TABLE wildlife_habitats (id INT,country VARCHAR(255),region VARCHAR(255),habitat_type VARCHAR(255));
SELECT COUNT(DISTINCT habitat_type) FROM wildlife_habitats WHERE region = 'South America';
Which genres have the highest and lowest revenue?
CREATE TABLE Genres (genre_id INT,genre_name TEXT); CREATE TABLE Sales (sale_id INT,genre_id INT,revenue INT);
SELECT genre_name, MAX(revenue) as max_revenue, MIN(revenue) as min_revenue FROM Genres JOIN Sales ON Genres.genre_id = Sales.genre_id GROUP BY genre_name;
Determine the number of vegan skincare products launched in Q1 2022
CREATE TABLE product_launches (launch_date DATE,product_type VARCHAR(20)); INSERT INTO product_launches (launch_date,product_type) VALUES ('2022-01-05','vegan skincare'),('2022-01-10','conventional skincare'),('2022-02-15','vegan skincare'),('2022-03-20','vegan skincare'),('2022-03-30','organic makeup');
SELECT COUNT(*) FROM product_launches WHERE product_type = 'vegan skincare' AND launch_date BETWEEN '2022-01-01' AND '2022-03-31';
List all cybersecurity strategies and their respective costs in descending order.
CREATE TABLE cybersecurity_strategies (strategy TEXT,cost INTEGER); INSERT INTO cybersecurity_strategies (strategy,cost) VALUES ('Firewall Implementation',5000),('Intrusion Detection System',7000),('Penetration Testing',3000);
SELECT strategy, cost FROM cybersecurity_strategies ORDER BY cost DESC
What is the total number of international visitors to each region in Africa in 2019 and 2020?
CREATE TABLE if not exists regions (id INT,name VARCHAR(20)); INSERT INTO regions (id,name) VALUES (1,'North Africa'),(2,'West Africa'),(3,'Central Africa'),(4,'East Africa'),(5,'Southern Africa'); CREATE TABLE if not exists visitors (id INT,region_id INT,year INT,visitors INT);
SELECT r.name, v.year, SUM(v.visitors) FROM visitors v JOIN regions r ON v.region_id = r.id WHERE r.name IN ('North Africa', 'West Africa', 'Central Africa', 'East Africa', 'Southern Africa') AND v.year IN (2019, 2020) GROUP BY r.name, v.year;
Which volunteers have not volunteered in the last 6 months?
CREATE TABLE volunteer_history (id INT,volunteer_id INT,year INT,num_hours INT); INSERT INTO volunteer_history (id,volunteer_id,year,num_hours) VALUES (1,1,2019,100),(2,1,2020,150),(3,2,2019,75),(4,2,2020,200),(5,3,2019,125),(6,3,2020,175),(7,4,2019,50),(8,4,2020,75);
SELECT volunteer_id FROM volunteer_history WHERE YEAR(NOW()) - year > 1;
What is the average temperature anomaly for each ocean basin, segmented by year?
CREATE TABLE temperature_anomalies (year INT,ocean_basin VARCHAR(50),temperature_anomaly FLOAT); INSERT INTO temperature_anomalies (year,ocean_basin,temperature_anomaly) VALUES (2010,'Pacific Ocean',1.2); INSERT INTO temperature_anomalies (year,ocean_basin,temperature_anomaly) VALUES (2010,'Atlantic Ocean',1.4);
SELECT ocean_basin, AVG(temperature_anomaly) FROM temperature_anomalies GROUP BY ocean_basin, year;
How many hotels were adopted by OTAs in the last quarter in the APAC region?
CREATE TABLE ota_adoptions (id INT,quarter TEXT,region TEXT,hotel_adoptions INT); INSERT INTO ota_adoptions (id,quarter,region,hotel_adoptions) VALUES (1,'Q1 2022','APAC',50),(2,'Q2 2022','APAC',75),(3,'Q1 2022','North America',60);
SELECT region, hotel_adoptions FROM ota_adoptions WHERE quarter = 'Q2 2022' AND region = 'APAC';
What is the total investment for each client?
CREATE TABLE clients (client_id INT,name TEXT,investment_type TEXT,investment FLOAT); INSERT INTO clients (client_id,name,investment_type,investment) VALUES (1,'Jamal Johnson','Stocks',3000.00),(1,'Jamal Johnson','Bonds',2000.00),(2,'Priya Patel','Stocks',5000.00);
SELECT client_id, name, SUM(investment) OVER (PARTITION BY client_id ORDER BY client_id) as total_investment FROM clients;
What is the average daily transaction volume for the top 10 most active digital wallets in Africa?
CREATE TABLE digital_wallets (id INT,name VARCHAR(50),daily_tx_volume INT); INSERT INTO digital_wallets (id,name,daily_tx_volume) VALUES (1,'Wallet1',1000),(2,'Wallet2',2000),(3,'Wallet3',3000),(4,'Wallet4',4000),(5,'Wallet5',5000),(6,'Wallet6',6000),(7,'Wallet7',7000),(8,'Wallet8',8000),(9,'Wallet9',9000),(10,'Wallet10',10000),(11,'Wallet11',11000);
SELECT name, AVG(daily_tx_volume) as avg_daily_tx_volume FROM (SELECT name, daily_tx_volume, RANK() OVER (ORDER BY daily_tx_volume DESC) as rank FROM digital_wallets WHERE region = 'Africa') x WHERE rank <= 10 GROUP BY name;
What is the total CO2 emission reduction in the last 6 months for each ethical fashion brand?
CREATE TABLE co2_emissions (brand VARCHAR(50),reduction INT,date DATE); INSERT INTO co2_emissions (brand,reduction,date) VALUES ('Ethical Brand A',1000,'2023-01-01'),('Ethical Brand B',1500,'2023-01-01'),('Ethical Brand C',500,'2023-01-01'),('Ethical Brand A',800,'2023-02-01'),('Ethical Brand D',1200,'2023-01-01');
SELECT brand, SUM(reduction) FROM co2_emissions WHERE date >= DATEADD(month, -6, CURRENT_DATE) GROUP BY brand;
What is the adoption rate of electric vehicles by year?
CREATE TABLE electric_vehicle_stats (country VARCHAR(50),adoption_rate DECIMAL(3,1),year INT);
SELECT year, AVG(adoption_rate) FROM electric_vehicle_stats GROUP BY year;
What is the average area of timber production sites by region?
CREATE TABLE timber (id INT,name VARCHAR(255),area FLOAT,region_id INT); INSERT INTO timber (id,name,area,region_id) VALUES (1,'Timber1',123.45,1); INSERT INTO timber (id,name,area,region_id) VALUES (2,'Timber2',234.56,2); CREATE TABLE region (id INT,name VARCHAR(255)); INSERT INTO region (id,name) VALUES (1,'Region1'); INSERT INTO region (id,name) VALUES (2,'Region2');
SELECT r.name, AVG(t.area) FROM timber t JOIN region r ON t.region_id = r.id GROUP BY r.name;
What is the percentage of cases won by attorneys in the 'Boston' office?
CREATE TABLE attorneys (attorney_id INT,office VARCHAR(50)); INSERT INTO attorneys VALUES (1,'Boston'); CREATE TABLE cases (case_id INT,attorney_id INT,case_outcome VARCHAR(10));
SELECT 100.0 * COUNT(*) / (SELECT COUNT(*) FROM cases INNER JOIN attorneys ON cases.attorney_id = attorneys.attorney_id) AS percentage_won FROM cases INNER JOIN attorneys ON cases.attorney_id = attorneys.attorney_id WHERE attorneys.office = 'Boston' AND case_outcome = 'won';
Create a new table named 'humanitarian_assistance' with columns 'program_name', 'start_date', 'end_date', 'assistance_type', and 'total_funding'
CREATE TABLE humanitarian_assistance (program_name VARCHAR(255),start_date DATE,end_date DATE,assistance_type VARCHAR(255),total_funding FLOAT);
CREATE TABLE humanitarian_assistance (program_name VARCHAR(255), start_date DATE, end_date DATE, assistance_type VARCHAR(255), total_funding FLOAT);
What is the minimum stocking density of Cod in Norwegian farms?
CREATE TABLE norwegian_farms (farmer_id INT,fish_species TEXT,stocking_density FLOAT); INSERT INTO norwegian_farms (farmer_id,fish_species,stocking_density) VALUES (1,'Cod',1.2),(2,'Haddock',1.8),(3,'Cod',1.5);
SELECT MIN(stocking_density) FROM norwegian_farms WHERE fish_species = 'Cod';
Update the production_status of the aircraft model 'A380' in the 'aircraft_models' table to 'Out of Production'
CREATE TABLE aircraft_models (model VARCHAR(50),manufacturer VARCHAR(50),first_flight YEAR,production_status VARCHAR(50)); INSERT INTO aircraft_models (model,manufacturer,first_flight,production_status) VALUES ('A320','Airbus',1988,'In Production'),('A330','Airbus',1994,'In Production'),('A340','Airbus',1993,'Out of Production'),('A350','Airbus',2015,'In Production'),('A380','Airbus',2007,'In Production');
UPDATE aircraft_models SET production_status = 'Out of Production' WHERE model = 'A380';
What's the total revenue generated by movies produced by a specific studio?
CREATE TABLE studio (studio_id INT,studio_name VARCHAR(50),country VARCHAR(50)); INSERT INTO studio (studio_id,studio_name,country) VALUES (1,'Studio A','USA'),(2,'Studio B','Canada'); CREATE TABLE movie (movie_id INT,title VARCHAR(50),release_year INT,revenue INT,studio_id INT); INSERT INTO movie (movie_id,title,release_year,revenue,studio_id) VALUES (1,'Movie 1',2019,100000,1),(2,'Movie 2',2020,200000,1),(3,'Movie 3',2018,150000,2);
SELECT SUM(revenue) FROM movie JOIN studio ON movie.studio_id = studio.studio_id WHERE studio.studio_name = 'Studio A';
What is the total number of users from Brazil who have updated their profile information in the last month, and what is the average number of posts they have made?
CREATE TABLE users (id INT,country VARCHAR(255),last_update DATE,posts_count INT);
SELECT COUNT(*), AVG(users.posts_count) FROM users WHERE country = 'Brazil' AND last_update >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH);
What is the total number of successful intelligence operations in the 'intelligence_operations' table?
CREATE TABLE intelligence_operations (id INT,operation_name TEXT,success BOOLEAN);
SELECT SUM(success) FROM intelligence_operations WHERE success = true;
Find the number of bridges and tunnels in California
CREATE TABLE Bridge (id INT,name VARCHAR(255),state VARCHAR(255)); INSERT INTO Bridge (id,name,state) VALUES (1,'Bridge A','California'),(2,'Bridge B','Texas'); CREATE TABLE Tunnel (id INT,name VARCHAR(255),state VARCHAR(255)); INSERT INTO Tunnel (id,name,state) VALUES (1,'Tunnel A','New York'),(2,'Tunnel B','California');
SELECT COUNT(*) FROM (SELECT * FROM Bridge WHERE state = 'California' UNION ALL SELECT * FROM Tunnel WHERE state = 'California') AS combined;
What is the population growth rate of indigenous communities in the Arctic?
CREATE TABLE population_growth (id INT,community_name VARCHAR,year INT,population INT,growth_rate FLOAT); INSERT INTO population_growth VALUES (1,'First Nations',2010,637000,0.03);
SELECT community_name, AVG(growth_rate) FROM population_growth GROUP BY community_name;
What is the total volume of timber harvested in 2020 for each country?
CREATE TABLE forestry.harvest (year INT,country VARCHAR(50),volume FLOAT); INSERT INTO forestry.harvest (year,country,volume) VALUES (2020,'Canada',1200000),(2020,'USA',1500000);
SELECT country, SUM(volume) FROM forestry.harvest WHERE year = 2020 GROUP BY country;
What is the average rating of K-pop songs released in 2021?
CREATE TABLE songs (id INT,name TEXT,genre TEXT,release_year INT,rating FLOAT); INSERT INTO songs (id,name,genre,release_year,rating) VALUES (1,'Dynamite','K-pop',2020,4.7),(2,'Butter','K-pop',2021,4.9),(3,'Permission to Dance','K-pop',2021,4.6); CREATE VIEW kpop_songs_2021 AS SELECT * FROM songs WHERE genre = 'K-pop' AND release_year = 2021;
SELECT AVG(rating) FROM kpop_songs_2021;
Which vessels have not been inspected in the past 6 months?
CREATE TABLE vessels (id INT,name TEXT,last_inspection DATE); INSERT INTO vessels (id,name,last_inspection) VALUES (1,'Vessel A','2022-01-01'); INSERT INTO vessels (id,name,last_inspection) VALUES (2,'Vessel B','2022-05-15');
SELECT * FROM vessels WHERE last_inspection < DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH);
List unique mental health conditions treated in each facility.
CREATE TABLE facilities (facility_id INT,condition VARCHAR(50));
SELECT facility_id, STRING_AGG(DISTINCT condition, ', ') as conditions FROM facilities GROUP BY facility_id;
What are the production quantities (in kg) for all chemical compounds in the South America region, ordered by production quantity in ascending order?
CREATE TABLE sa_compounds (compound_id INT,compound_name TEXT,region TEXT,production_quantity INT); INSERT INTO sa_compounds (compound_id,compound_name,region,production_quantity) VALUES (1,'Compound L','South America',3000),(2,'Compound M','South America',2000),(3,'Compound N','South America',5000),(4,'Compound O','South America',4000);
SELECT compound_name, production_quantity FROM sa_compounds WHERE region = 'South America' ORDER BY production_quantity ASC;
What is the average age of patients in Texas who have tried alternative therapies like meditation?
CREATE TABLE patients (id INT,age INT,gender TEXT,state TEXT,alternative_therapy TEXT); INSERT INTO patients (id,age,gender,state,alternative_therapy) VALUES (1,35,'Female','California','No'); INSERT INTO patients (id,age,gender,state,alternative_therapy) VALUES (2,42,'Male','Texas','Yes');
SELECT AVG(patients.age) FROM patients WHERE patients.state = 'Texas' AND patients.alternative_therapy = 'Yes';
What is the total number of COVID-19 cases in each country?
CREATE TABLE COVIDCountry (Country VARCHAR(50),Cases INT); INSERT INTO COVIDCountry (Country,Cases) VALUES ('Canada',20000),('USA',30000),('Mexico',15000);
SELECT Country, SUM(Cases) FROM COVIDCountry GROUP BY Country;
Insert a new clinical trial for 'DrugH' by 'GlobalPharm' in '2023'.
CREATE TABLE ClinicalTrials (clinical_trial_id TEXT,drug_name TEXT,laboratory TEXT,year INTEGER);
INSERT INTO ClinicalTrials (clinical_trial_id, drug_name, laboratory, year) VALUES ('Trial003', 'DrugH', 'GlobalPharm', 2023);
List the names and total donations of top 3 donors in the 'education' cause area, excluding any duplicates.
CREATE TABLE donors (id INT,name VARCHAR(30),cause_area VARCHAR(20)); CREATE TABLE donations (id INT,donor_id INT,amount INT); INSERT INTO donors (id,name,cause_area) VALUES (1,'John Doe','education'),(2,'Jane Smith','education'); INSERT INTO donations (id,donor_id,amount) VALUES (1,1,5000),(2,1,5000),(3,2,7000);
SELECT donors.name, SUM(donations.amount) FROM donors INNER JOIN donations ON donors.id = donations.donor_id WHERE donors.cause_area = 'education' GROUP BY donors.name ORDER BY SUM(donations.amount) DESC LIMIT 3;
What is the total revenue generated from ethical labor practices in the 'footwear' category?
CREATE TABLE sales (sale_id INT,product_id INT,category VARCHAR(20),revenue DECIMAL(5,2),is_ethical BOOLEAN); INSERT INTO sales (sale_id,product_id,category,revenue,is_ethical) VALUES (1,1,'footwear',150.00,true),(2,2,'footwear',120.00,false),(3,3,'footwear',175.00,true);
SELECT SUM(revenue) FROM sales WHERE category = 'footwear' AND is_ethical = true;
What is the maximum landfill capacity available in the United States?
CREATE TABLE USLandfillData (landfill VARCHAR(50),capacity_m3 FLOAT); INSERT INTO USLandfillData (landfill,capacity_m3) VALUES ('Freedom Landfill',18400000),('Casella Landfill',14000000),('Puente Hills Landfill',9800000),('BFI Waste Systems Landfill',12500000),('WM Disposal Services Landfill',11000000);
SELECT MAX(capacity_m3) FROM USLandfillData;
Sustainable food items that failed inspection
CREATE TABLE SustainableFood (ItemID INT,FarmID INT,ItemName VARCHAR(50),IsSustainable BOOLEAN); INSERT INTO SustainableFood (ItemID,FarmID,ItemName,IsSustainable) VALUES (1,1,'Carrots',TRUE),(2,2,'Potatoes',FALSE),(3,3,'Cabbages',TRUE);
SELECT f.ItemName FROM SustainableFood f INNER JOIN InspectionResult i ON f.FarmID = i.FarmID WHERE f.IsSustainable = TRUE AND i.Result = 'Fail';
Find artists who have created more than one type of artwork in the Asian Art Museum.
CREATE TABLE AsianArtMuseum(id INT,type VARCHAR(20),artist VARCHAR(30)); INSERT INTO AsianArtMuseum(id,type,artist) VALUES (1,'Painting','Hokusai'),(2,'Sculpture','Hokusai'),(3,'Calligraphy','Xu Bing'),(4,'Print','Xu Bing');
SELECT artist FROM (SELECT artist, COUNT(DISTINCT type) as type_count FROM AsianArtMuseum GROUP BY artist) AS subquery WHERE type_count > 1;
What is the average data usage for customers in 'Ontario'?
CREATE TABLE customer_data_canada (customer_id INT,data_usage FLOAT,province VARCHAR(50)); INSERT INTO customer_data_canada (customer_id,data_usage,province) VALUES (1,3.5,'Ontario'); INSERT INTO customer_data_canada (customer_id,data_usage,province) VALUES (2,4.2,'Ontario'); INSERT INTO customer_data_canada (customer_id,data_usage,province) VALUES (3,2.8,'Ontario'); INSERT INTO customer_data_canada (customer_id,data_usage,province) VALUES (4,3.9,'Quebec');
SELECT AVG(data_usage) FROM customer_data_canada WHERE province = 'Ontario';