instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What are the different types of military satellites operated by the US and China?
CREATE TABLE MilitarySatellites (Country VARCHAR(255),Type VARCHAR(255)); INSERT INTO MilitarySatellites (Country,Type) VALUES ('USA','Communications Satellite'),('USA','Surveillance Satellite'),('China','Communications Satellite'),('China','Reconnaissance Satellite');
SELECT Type FROM MilitarySatellites WHERE Country IN ('USA', 'China');
What was the total construction cost for each infrastructure project in 2020?
CREATE TABLE InfrastructureProjects (Id INT,Name VARCHAR(255),Location VARCHAR(255),ConstructionCost FLOAT,Year INT); INSERT INTO InfrastructureProjects (Id,Name,Location,ConstructionCost,Year) VALUES (1,'Dam','City A',5000000,2020),(2,'Bridge','City B',2000000,2019),(3,'Road','City C',1500000,2020);
SELECT Location, SUM(ConstructionCost) as TotalCost FROM InfrastructureProjects WHERE Year = 2020 GROUP BY Location;
Select all trends with a popularity score greater than 0.85
CREATE TABLE fashion_trends (trend_id INT PRIMARY KEY,trend_name VARCHAR(100),popularity_score FLOAT,season VARCHAR(20)); INSERT INTO fashion_trends (trend_id,trend_name,popularity_score,season) VALUES (1,'Boho Chic',0.85,'Spring'),(2,'Minimalist',0.9,'Winter'),(3,'Vintage',0.8,'Autumn');
SELECT * FROM fashion_trends WHERE popularity_score > 0.85;
What is the total billing amount for cases handled by attorney Johnson?
CREATE TABLE cases (case_id INT,attorney_name VARCHAR(255),billing_amount FLOAT); INSERT INTO cases (case_id,attorney_name,billing_amount) VALUES (1,'Smith',5000),(2,'Jones',3000),(3,'Jones',3500),(4,'Johnson',4000),(5,'Johnson',6000);
SELECT SUM(billing_amount) FROM cases WHERE attorney_name = 'Johnson';
Which biosensors and their associated departments have a price less than 1500?
CREATE TABLE Biosensor (Biosensor_Name VARCHAR(50) PRIMARY KEY,Department VARCHAR(50),Price DECIMAL(10,2)); INSERT INTO Biosensor (Biosensor_Name,Department,Price) VALUES ('Bio1','Genetic Research',1000.00); INSERT INTO Biosensor (Biosensor_Name,Department,Price) VALUES ('Bio2','BioProcess Engineering',1500.00); INSERT INTO Biosensor (Biosensor_Name,Department,Price) VALUES ('Bio3','Genetic Research',1800.00);
SELECT B.Biosensor_Name, B.Department FROM Biosensor B WHERE B.Price < 1500;
What is the total energy consumption of renewable energy projects in the RenewableEnergy schema?
CREATE TABLE RenewableEnergy (ProjectID INT,EnergyConsumption FLOAT);
select sum(EnergyConsumption) as total_cons from RenewableEnergy;
What is the name and ID of the water treatment plant in the 'PublicWorks' table with the highest daily capacity?
CREATE TABLE PublicWorks (ID INT,Name VARCHAR(50),Type VARCHAR(20),Location VARCHAR(50),DailyCapacity INT); INSERT INTO PublicWorks (ID,Name,Type,Location,DailyCapacity) VALUES (1,'Water Treatment Plant A','Water Treatment Plant','Seattle,WA',150000); INSERT INTO PublicWorks (ID,Name,Type,Location,DailyCapacity) VALUES (2,'Wastewater Treatment Plant B','Wastewater Treatment Plant','Denver,CO',125000);
SELECT Name, ID FROM PublicWorks WHERE DailyCapacity = (SELECT MAX(DailyCapacity) FROM PublicWorks WHERE Type = 'Water Treatment Plant');
Insert a new record for a community health worker with ID 3, age 30, and ethnicity Caucasian.
CREATE TABLE community_health_workers (worker_id INT,age INT,race VARCHAR(255)); INSERT INTO community_health_workers (worker_id,age,race) VALUES (1,35,'Hispanic'); INSERT INTO community_health_workers (worker_id,age,race) VALUES (2,40,'African American');
INSERT INTO community_health_workers (worker_id, age, race) VALUES (3, 30, 'Caucasian');
What is the name of the artist with the highest number of artworks?
CREATE TABLE Artists (name VARCHAR(255),art VARCHAR(255),quantity INT); INSERT INTO Artists (name,art,quantity) VALUES ('Picasso','Painting',500),('Van Gogh','Painting',400),('Dali','Painting',300),('Picasso','Sculpture',200);
SELECT name FROM Artists WHERE quantity = (SELECT MAX(quantity) FROM Artists);
Find the difference in data usage between consecutive months for subscriber_id 43 in the 'Asia-Pacific' region.
CREATE TABLE subscriber_data (subscriber_id INT,data_usage FLOAT,month DATE); INSERT INTO subscriber_data (subscriber_id,data_usage,month) VALUES (43,28,'2021-01-01'),(43,33,'2021-02-01'),(43,38,'2021-03-01');
SELECT subscriber_id, LAG(data_usage) OVER (PARTITION BY subscriber_id ORDER BY month) as prev_data_usage, data_usage, month FROM subscriber_data WHERE subscriber_id = 43 AND region = 'Asia-Pacific' ORDER BY month;
What is the lifelong learning enrollment rate for each province?
CREATE TABLE province (province_id INT,province_name VARCHAR(255)); CREATE TABLE lifelong_learning (student_id INT,province_id INT,enrollment_date DATE); INSERT INTO province (province_id,province_name) VALUES (8001,'Province A'),(8002,'Province B'),(8003,'Province C'); INSERT INTO lifelong_learning (student_id,province_id,enrollment_date) VALUES (9001,8001,'2021-01-01'),(9002,8002,'2021-02-01'),(9003,8003,'2021-03-01'); CREATE VIEW enrolled_students AS SELECT province_id,COUNT(DISTINCT student_id) as enrolled_count FROM lifelong_learning GROUP BY province_id;
SELECT province_name, enrolled_students.enrolled_count, (enrolled_students.enrolled_count::FLOAT / (SELECT COUNT(DISTINCT student_id) FROM lifelong_learning) * 100) as enrollment_rate FROM province JOIN enrolled_students ON province.province_id = enrolled_students.province_id;
What is the percentage of female and male employees for each job type across all mines?
CREATE TABLE Mine (MineID int,MineName varchar(50),Location varchar(50)); CREATE TABLE Employee (EmployeeID int,EmployeeName varchar(50),JobType varchar(50),MineID int,Gender varchar(10)); INSERT INTO Mine VALUES (1,'ABC Mine','Colorado'),(2,'DEF Mine','Wyoming'),(3,'GHI Mine','West Virginia'); INSERT INTO Employee VALUES (1,'John Doe','Miner',1,'Male'),(2,'Jane Smith','Engineer',1,'Female'),(3,'Michael Lee','Miner',2,'Male'),(4,'Emily Johnson','Admin',2,'Female'),(5,'Robert Brown','Miner',3,'Male'),(6,'Sophia Davis','Engineer',3,'Female');
SELECT JobType, Gender, COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Employee) as Percentage FROM Employee GROUP BY JobType, Gender;
How many unique pests were reported in the 'Northeast' region organic farms in 2019?
CREATE TABLE Organic_Farms (farm_name VARCHAR(50),region VARCHAR(20),year INT); CREATE TABLE Pest_Report (report_id INT,farm_name VARCHAR(50),pest VARCHAR(30),year INT); INSERT INTO Organic_Farms (farm_name,region,year) VALUES ('Farm1','Northeast',2019),('Farm2','Northeast',2019); INSERT INTO Pest_Report (report_id,farm_name,pest,year) VALUES (1,'Farm1','Aphid',2019),(2,'Farm1','Thrip',2019);
SELECT COUNT(DISTINCT pest) as unique_pests FROM Pest_Report pr JOIN Organic_Farms of ON pr.farm_name = of.farm_name WHERE of.region = 'Northeast' AND of.year = 2019;
Add a new column 'weight' to the 'satellite_deployment' table
CREATE TABLE satellite_deployment (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),launch_date DATE);
ALTER TABLE satellite_deployment ADD COLUMN weight FLOAT;
What is the average monthly data usage for mobile and broadband subscribers in the state of California?
CREATE TABLE subscriber_data (subscriber_id INT,subscriber_type VARCHAR(10),data_usage FLOAT,state VARCHAR(20)); INSERT INTO subscriber_data (subscriber_id,subscriber_type,data_usage,state) VALUES (1,'mobile',3.5,'CA'),(2,'mobile',4.2,'NY'),(3,'broadband',200.5,'CA'),(4,'mobile',3.8,'WA'),(5,'broadband',250.0,'NY');
SELECT subscriber_type, AVG(data_usage) FROM subscriber_data WHERE state = 'CA' GROUP BY subscriber_type;
What is the average word count for articles in 'category1', 'category3', and 'category5'?
CREATE TABLE articles (id INT,title VARCHAR(50),word_count INT,category VARCHAR(20)); INSERT INTO articles (id,title,word_count,category) VALUES (1,'Article1',500,'category1'),(2,'Article2',700,'category3'),(3,'Article3',800,'category5'),(4,'Article4',600,'category2'),(5,'Article5',400,'category1');
SELECT AVG(word_count) FROM articles WHERE category IN ('category1', 'category3', 'category5')
Find the top 5 submarine dives by maximum depth, showing the dive's date and the name of the submarine.
CREATE TABLE SUBMARINE_DIVES (DIVE_ID INT,SUBMARINE_NAME VARCHAR(20),DIVE_DATE DATE,MAX_DEPTH INT); INSERT INTO SUBMARINE_DIVES (DIVE_ID,SUBMARINE_NAME,DIVE_DATE,MAX_DEPTH) VALUES (1,'Alvin','2022-01-01',4000),(2,'Nautile','2022-02-01',6000),(3,'Alvin','2022-03-01',3500),(4,'Nautile','2022-04-01',5000),(5,'Alvin','2022-05-01',4500);
SELECT SUBMARINE_NAME, DIVE_DATE, MAX_DEPTH FROM (SELECT SUBMARINE_NAME, DIVE_DATE, MAX_DEPTH, ROW_NUMBER() OVER (PARTITION BY SUBMARINE_NAME ORDER BY MAX_DEPTH DESC) AS RN FROM SUBMARINE_DIVES) WHERE RN <= 5;
What is the average price of recycled polyester clothing manufactured in size S?
CREATE TABLE textile_sources (source_id INT,material VARCHAR(50)); INSERT INTO textile_sources (source_id,material) VALUES (1,'Recycled Polyester'); CREATE TABLE garment_sizes (size_id INT,size VARCHAR(10)); INSERT INTO garment_sizes (size_id,size) VALUES (1,'S'); CREATE TABLE products (product_id INT,name VARCHAR(50),price DECIMAL(5,2),source_id INT,size_id INT); INSERT INTO products (product_id,name,price,source_id,size_id) VALUES (1,'Recycled Polyester Top',30.99,1,1);
SELECT AVG(p.price) FROM products p INNER JOIN textile_sources ts ON p.source_id = ts.source_id INNER JOIN garment_sizes gs ON p.size_id = gs.size_id WHERE ts.material = 'Recycled Polyester' AND gs.size = 'S';
Determine the percentage change in total production of Dysprosium for each country from 2019 to 2020.
CREATE TABLE Country (Code TEXT,Name TEXT,Continent TEXT); INSERT INTO Country (Code,Name,Continent) VALUES ('CN','China','Asia'),('AU','Australia','Australia'),('KR','South Korea','Asia'),('IN','India','Asia'); CREATE TABLE ProductionYearly (Year INT,Country TEXT,Element TEXT,Quantity INT); INSERT INTO ProductionYearly (Year,Country,Element,Quantity) VALUES (2019,'CN','Dysprosium',1500),(2019,'AU','Dysprosium',1200),(2019,'KR','Dysprosium',1000),(2020,'CN','Dysprosium',1800),(2020,'AU','Dysprosium',1300),(2020,'KR','Dysprosium',1100);
SELECT a.Country, ((b.Quantity - a.Quantity) * 100.0 / a.Quantity) AS PercentageChange FROM ProductionYearly a JOIN ProductionYearly b ON a.Country = b.Country WHERE a.Element = 'Dysprosium' AND b.Element = 'Dysprosium' AND a.Year = 2019 AND b.Year = 2020;
How many defense projects exceeded their budget in the last 3 years?
CREATE TABLE DefenseProjects (id INT,project_name VARCHAR(255),start_date DATE,end_date DATE,budget INT,actual_cost INT); INSERT INTO DefenseProjects (id,project_name,start_date,end_date,budget,actual_cost) VALUES (1,'Project A','2019-01-01','2021-12-31',10000000,11000000),(2,'Project B','2018-01-01','2020-12-31',8000000,7500000);
SELECT COUNT(*) FROM DefenseProjects WHERE actual_cost > budget AND start_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 YEAR);
What is the number of teachers who have attended professional development sessions in each subject area by gender?
CREATE TABLE teacher_development_gender (teacher_id INT,gender VARCHAR(255),subject_area VARCHAR(255),sessions_attended INT); INSERT INTO teacher_development_gender (teacher_id,gender,subject_area,sessions_attended) VALUES (1,'Male','Math',3),(2,'Female','English',2),(3,'Non-binary','Science',5),(4,'Male','Math',4);
SELECT gender, subject_area, SUM(sessions_attended) as total_sessions_attended FROM teacher_development_gender GROUP BY gender, subject_area;
Which menu items were inspected by the Food Safety Agency in 2021?
CREATE TABLE food_safety_inspection(menu_item VARCHAR(255),inspection_date DATE,agency VARCHAR(255)); INSERT INTO food_safety_inspection VALUES ('Chicken Burger','2021-05-15','Food Safety Agency'); INSERT INTO food_safety_inspection VALUES ('Fish Tacos','2021-10-20','Food Safety Agency');
SELECT menu_item FROM food_safety_inspection WHERE agency = 'Food Safety Agency' AND YEAR(inspection_date) = 2021;
What is the release year of the most recent movie in the "movies" table?
CREATE TABLE movies (id INT,title VARCHAR(100),release_year INT);
SELECT MAX(release_year) FROM movies;
What is the total sales revenue for each drug, ranked by total sales revenue?
CREATE TABLE DrugSales (DrugName varchar(50),SalesRepID int,SalesDate date,TotalSalesRev decimal(18,2)); INSERT INTO DrugSales (DrugName,SalesRepID,SalesDate,TotalSalesRev) VALUES ('DrugI',1,'2021-03-15',50000.00),('DrugJ',2,'2021-02-01',75000.00),('DrugK',3,'2021-01-25',62000.00),('DrugL',4,'2021-04-02',85000.00);
SELECT DrugName, TotalSalesRev, ROW_NUMBER() OVER (ORDER BY TotalSalesRev DESC) as SalesRank FROM (SELECT DrugName, SUM(TotalSalesRev) as TotalSalesRev FROM DrugSales GROUP BY DrugName) as TotalSales;
What is the total number of volunteer hours contributed by each program in Q1 2023, including partial hours?
CREATE TABLE Programs (ProgramID INT,Name TEXT);CREATE TABLE VolunteerHours (HourID INT,ProgramID INT,Hours DECIMAL(10,2),HourDate DATE);
SELECT P.Name, SUM(VH.Hours) as TotalHours FROM VolunteerHours VH JOIN Programs P ON VH.ProgramID = P.ProgramID WHERE VH.HourDate BETWEEN '2023-01-01' AND '2023-03-31' GROUP BY P.ProgramID, P.Name;
What is the total quantity of equipment for each manufacturer, grouped by equipment type, in the 'equipment_summary' view?
CREATE TABLE workout_equipment (equipment_id INT,equipment_name VARCHAR(50),quantity INT,manufacturer VARCHAR(50)); CREATE VIEW equipment_summary AS SELECT equipment_name,manufacturer,SUM(quantity) as total_quantity FROM workout_equipment GROUP BY equipment_name,manufacturer;
SELECT manufacturer, equipment_name, SUM(total_quantity) FROM equipment_summary GROUP BY manufacturer, equipment_name;
How many public schools are there in total, and what is the total budget allocated to them?
CREATE TABLE Schools (Name VARCHAR(255),Type VARCHAR(255),Region VARCHAR(255)); INSERT INTO Schools (Name,Type,Region) VALUES ('School A','Public','North'),('School B','Private','North'),('School C','Public','South'),('School D','Private','South'); CREATE TABLE SchoolBudget (Year INT,School VARCHAR(255),Amount DECIMAL(10,2)); INSERT INTO SchoolBudget (Year,School,Amount) VALUES (2020,'School A',500000.00),(2020,'School B',600000.00),(2020,'School C',550000.00),(2020,'School D',700000.00);
SELECT COUNT(s.Name), SUM(sb.Amount) FROM Schools s INNER JOIN SchoolBudget sb ON s.Name = sb.School WHERE s.Type = 'Public';
Find the union of emergency calls and crimes reported in the Downtown and Uptown districts.
CREATE TABLE Districts (district_name TEXT,calls INTEGER,crimes INTEGER); INSERT INTO Districts (district_name,calls,crimes) VALUES ('Downtown',450,300),('Uptown',500,250);
SELECT calls, crimes FROM Districts WHERE district_name = 'Downtown' UNION SELECT calls, crimes FROM Districts WHERE district_name = 'Uptown';
List the total production of oil and gas for all fields in the North Sea in 2019.
CREATE TABLE north_sea_fields (field_id INT,field_name VARCHAR(50),oil_production FLOAT,gas_production FLOAT,datetime DATETIME); INSERT INTO north_sea_fields (field_id,field_name,oil_production,gas_production,datetime) VALUES (1,'North Sea Field A',1500000,2000000,'2019-01-01 00:00:00'),(2,'North Sea Field B',1800000,2500000,'2019-01-01 00:00:00');
SELECT field_name, SUM(oil_production) + SUM(gas_production) FROM north_sea_fields WHERE YEAR(datetime) = 2019 GROUP BY field_name;
Get the list of members who are older than 40 and from a country other than the United States and Canada.
CREATE TABLE members_geo(id INT,name VARCHAR(50),gender VARCHAR(10),age INT,membership_type VARCHAR(20),country VARCHAR(20),city VARCHAR(20)); INSERT INTO members_geo(id,name,gender,age,membership_type,country,city) VALUES (1,'John Doe','Male',30,'Gym','USA','New York'),(2,'Jane Doe','Female',45,'Swimming','Mexico','Mexico City');
SELECT id, name, country FROM members_geo WHERE age > 40 AND country NOT IN ('USA', 'Canada');
What is the maximum claim amount for policyholders living in 'Texas'?
CREATE TABLE policyholders (id INT,name TEXT,age INT,gender TEXT,state TEXT); INSERT INTO policyholders (id,name,age,gender,state) VALUES (1,'John Doe',36,'Male','Texas'); INSERT INTO policyholders (id,name,age,gender,state) VALUES (2,'Jane Smith',42,'Female','Texas'); CREATE TABLE claims (id INT,policyholder_id INT,claim_amount INT); INSERT INTO claims (id,policyholder_id,claim_amount) VALUES (1,1,2500); INSERT INTO claims (id,policyholder_id,claim_amount) VALUES (2,1,3000); INSERT INTO claims (id,policyholder_id,claim_amount) VALUES (3,2,1500); INSERT INTO claims (id,policyholder_id,claim_amount) VALUES (4,2,6000);
SELECT MAX(claim_amount) FROM claims JOIN policyholders ON claims.policyholder_id = policyholders.id WHERE policyholders.state = 'Texas';
How many carbon offset initiatives have been launched by the city government of Tokyo in the last 5 years?
CREATE TABLE carbon_offset_initiatives (initiative_id INT,initiative_name VARCHAR(100),launch_date DATE,city VARCHAR(100)); INSERT INTO carbon_offset_initiatives (initiative_id,initiative_name,launch_date,city) VALUES (1,'Tree Planting','2022-01-01','Tokyo'),(2,'Public Transit Expansion','2021-07-01','Tokyo');
SELECT COUNT(*) FROM carbon_offset_initiatives WHERE city = 'Tokyo' AND launch_date >= DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR);
What is the total donation amount by new donors (first-time donors) in 2022?
CREATE TABLE donors (id INT,name VARCHAR(50),is_new_donor BOOLEAN,donation_amount DECIMAL(10,2),donation_date DATE); INSERT INTO donors (id,name,is_new_donor,donation_amount,donation_date) VALUES (1,'John Doe',true,200.00,'2022-04-15'); INSERT INTO donors (id,name,is_new_donor,donation_amount,donation_date) VALUES (2,'Jane Smith',false,300.00,'2022-01-01'); INSERT INTO donors (id,name,is_new_donor,donation_amount,donation_date) VALUES (3,'Maria Garcia',true,500.00,'2022-11-29');
SELECT SUM(donation_amount) FROM donors WHERE YEAR(donation_date) = 2022 AND is_new_donor = true;
Delete all records from the 'charging_stations' table where the 'city' is 'San Diego'
CREATE TABLE charging_stations (id INT PRIMARY KEY,station_name VARCHAR(255),city VARCHAR(255),num_ports INT);
DELETE FROM charging_stations WHERE city = 'San Diego';
How many polar bears were sighted in total in the past 2 years?
CREATE TABLE PolarBearSightings (id INT,year INT,month INT,polar_bears_sighted INT); INSERT INTO PolarBearSightings (id,year,month,polar_bears_sighted) VALUES (1,2019,1,3),(2,2019,2,5),(3,2019,3,4);
SELECT year, SUM(polar_bears_sighted) FROM PolarBearSightings WHERE year IN (2020, 2021) GROUP BY year;
What is the average billing amount for cases with precedent 'Precedent B'?
CREATE TABLE cases (case_id INT,precedent TEXT,total_billing FLOAT); INSERT INTO cases (case_id,precedent,total_billing) VALUES (1,'Precedent A',2000.00),(2,'Precedent A',3000.00),(3,'Precedent B',1500.00);
SELECT AVG(total_billing) FROM cases WHERE precedent = 'Precedent B';
Rank national security budgets from highest to lowest for the last 3 years.
CREATE TABLE budgets (budget_id INT,year INT,region_id INT,amount INT); INSERT INTO budgets (budget_id,year,region_id,amount) VALUES (1,2019,1,500),(2,2020,1,600),(3,2021,1,700),(4,2019,2,400),(5,2020,2,450),(6,2021,2,500);
SELECT year, region_id, amount, RANK() OVER (PARTITION BY year ORDER BY amount DESC) as ranking FROM budgets ORDER BY year, ranking;
Which support programs have at least one student with a visual impairment?
CREATE TABLE Students(student_id INT,name TEXT,disability TEXT);CREATE TABLE Programs(program_id INT,program_name TEXT);CREATE TABLE Student_Programs(student_id INT,program_id INT);
SELECT p.program_name FROM Programs p INNER JOIN Student_Programs sp ON p.program_id = sp.program_id INNER JOIN Students s ON sp.student_id = s.student_id WHERE s.disability LIKE '%visual%';
Which underrepresented communities have been included in the training data for each AI model?
CREATE TABLE training_data (id INT,model_id INT,community VARCHAR(255)); INSERT INTO training_data (id,model_id,community) VALUES (1,1,'Rural Communities'),(2,1,'Elderly Population'),(3,2,'LGBTQ+ Community'),(4,3,'Minority Languages');
SELECT model_id, community FROM training_data;
What is the average installed capacity of wind projects?
CREATE TABLE renewable_energy_projects (id INT,project_name TEXT,country TEXT,technology TEXT,installed_capacity FLOAT); INSERT INTO renewable_energy_projects (id,project_name,country,technology,installed_capacity) VALUES (1,'Project A','country1','solar',200.0),(2,'Project B','country2','wind',150.0),(3,'Project C','country1','wind',300.0);
SELECT AVG(installed_capacity) FROM renewable_energy_projects WHERE technology = 'wind';
Display the number of users who have not accepted the privacy policy in Senegal as of Q2 2022.
CREATE TABLE if not exists privacy_update (user_id INT,country VARCHAR(50),accepted BOOLEAN,quarter INT,year INT); INSERT INTO privacy_update (user_id,country,accepted) VALUES (1,'Senegal',TRUE,2,2022),(2,'Senegal',FALSE,2,2022);
SELECT COUNT(user_id) FROM privacy_update WHERE country = 'Senegal' AND accepted = FALSE;
Delete the record of the diamond mine in Mpumalanga, South Africa from the "mining_operations" table
CREATE TABLE mining_operations (id INT PRIMARY KEY,mine_name VARCHAR(255),location VARCHAR(255),resource VARCHAR(255),open_date DATE);
DELETE FROM mining_operations WHERE mine_name = 'Diamond Dream' AND location = 'Mpumalanga, South Africa';
What is the minimum price of blushes sourced from Europe?
CREATE TABLE Cosmetics (product_id INT,name VARCHAR(50),price DECIMAL(5,2),sourcing_country VARCHAR(50),type VARCHAR(50));
SELECT MIN(price) FROM Cosmetics WHERE type = 'Blush' AND sourcing_country = 'Europe';
What is the total amount donated by each donor to each organization in 2020?
CREATE TABLE Donors (DonorID INT,DonorName TEXT,DonationAmount INT,DonationYear INT); INSERT INTO Donors (DonorID,DonorName,DonationAmount,DonationYear) VALUES (1,'Donor A',2000,2020),(2,'Donor B',3000,2020),(3,'Donor C',4000,2020); CREATE TABLE Organizations (OrganizationID INT,OrganizationName TEXT); INSERT INTO Organizations (OrganizationID,OrganizationName) VALUES (1,'UNICEF'),(2,'Greenpeace'),(3,'Doctors Without Borders'); CREATE TABLE Donations (DonorID INT,OrganizationID INT,DonationAmount INT,DonationYear INT); INSERT INTO Donations (DonorID,OrganizationID,DonationAmount,DonationYear) VALUES (1,1,2000,2020),(2,2,3000,2020),(3,3,4000,2020);
SELECT DonorName, OrganizationName, SUM(DonationAmount) as TotalDonation FROM Donors INNER JOIN Donations ON Donors.DonorID = Donations.DonorID INNER JOIN Organizations ON Donations.OrganizationID = Organizations.OrganizationID WHERE DonationYear = 2020 GROUP BY DonorName, OrganizationName;
What is the total amount donated and total number of donations for each program, excluding 'Medical Research'?
CREATE TABLE Donors (DonorID INT,DonorName TEXT,TotalDonated DECIMAL(10,2));CREATE TABLE Donations (DonationID INT,DonorID INT,Program TEXT,Amount DECIMAL(10,2),Success BOOLEAN);
SELECT D.Program, SUM(D.Amount) as TotalAmount, COUNT(*) as TotalDonations FROM Donations D WHERE D.Program != 'Medical Research' GROUP BY D.Program;
What is the total number of hours spent on professional development by teachers in each country?
CREATE TABLE professional_development_hours (teacher_id INT,country TEXT,hours_spent INT); INSERT INTO professional_development_hours (teacher_id,country,hours_spent) VALUES (1,'USA',10),(2,'Canada',15),(3,'Mexico',20),(4,'Brazil',25),(5,'Argentina',30);
SELECT country, SUM(hours_spent) as total_hours FROM professional_development_hours GROUP BY country;
What is the total budget allocated for habitat preservation in 'Africa'?
CREATE TABLE Habitat_Preservation (PreservationID INT,Habitat VARCHAR(20),Budget DECIMAL(10,2)); INSERT INTO Habitat_Preservation (PreservationID,Habitat,Budget) VALUES (1,'Africa',50000.00); INSERT INTO Habitat_Preservation (PreservationID,Habitat,Budget) VALUES (2,'Asia',75000.00);
SELECT SUM(Budget) FROM Habitat_Preservation WHERE Habitat = 'Africa';
How many tons of seafood were exported from Canada to the US in 2020?
CREATE TABLE seafood_exports (id INT,export_date DATE,export_country VARCHAR(50),import_country VARCHAR(50),quantity INT,unit_type VARCHAR(10)); INSERT INTO seafood_exports (id,export_date,export_country,import_country,quantity,unit_type) VALUES (1,'2020-01-01','Canada','US',500,'ton'),(2,'2020-01-02','Canada','Mexico',300,'ton'),(3,'2021-01-01','Canada','US',600,'ton');
SELECT SUM(quantity) FROM seafood_exports WHERE export_country = 'Canada' AND import_country = 'US' AND EXTRACT(YEAR FROM export_date) = 2020;
What is the maximum temperature recorded in the 'arctic_weather' table for each month in the year 2020?
CREATE TABLE arctic_weather (id INT,date DATE,temperature FLOAT);
SELECT MONTH(date) AS month, MAX(temperature) AS max_temp FROM arctic_weather WHERE YEAR(date) = 2020 GROUP BY month;
What is the total revenue for each fashion trend that is popular in the UK and has a size diversity score greater than 8?
CREATE TABLE FashionTrends (TrendID INT,TrendName TEXT,Popularity INT,Revenue INT,SizeDiversityScore INT); INSERT INTO FashionTrends (TrendID,TrendName,Popularity,Revenue,SizeDiversityScore) VALUES (1,'Athleisure',8000,50000,9),(2,'Denim',9000,60000,7),(3,'Boho-Chic',7000,40000,8),(4,'Minimalism',6000,30000,10); CREATE TABLE SizeDiversity (TrendID INT,SizeDiversityScore INT); INSERT INTO SizeDiversity (TrendID,SizeDiversityScore) VALUES (1,9),(2,7),(3,8),(4,10);
SELECT FT.TrendName, SUM(FT.Revenue) FROM FashionTrends FT INNER JOIN SizeDiversity SD ON FT.TrendID = SD.TrendID WHERE FT.Popularity > 8000 AND SD.SizeDiversityScore > 8 GROUP BY FT.TrendName HAVING COUNT(DISTINCT FT.Country) > 1;
How many wind farms are there in 'Texas' that have a capacity of at least 250 MW?
CREATE TABLE wind_farms (id INT,name TEXT,location TEXT,capacity FLOAT); INSERT INTO wind_farms (id,name,location,capacity) VALUES (1,'Farm A','Texas',300.2),(2,'Farm B','Texas',200.1);
SELECT COUNT(*) FROM wind_farms WHERE location = 'Texas' AND capacity >= 250;
What is the maximum number of followers for any user, and what is their location?
CREATE TABLE users (id INT,name VARCHAR(50),location VARCHAR(50),followers INT); INSERT INTO users (id,name,location,followers) VALUES (1,'Alice','Canada',100); INSERT INTO users (id,name,location,followers) VALUES (2,'Bob','USA',200); INSERT INTO users (id,name,location,followers) VALUES (3,'Charlie','Mexico',300);
SELECT location, MAX(followers) as max_followers FROM users;
What is the combined height of all Redwood trees?
CREATE TABLE forestry_survey (id INT,species VARCHAR(255),diameter FLOAT,height FLOAT,volume FLOAT); INSERT INTO forestry_survey (id,species,diameter,height,volume) VALUES (1,'Redwood',5.6,120,23.4); INSERT INTO forestry_survey (id,species,diameter,height,volume) VALUES (2,'Oak',2.4,60,4.2); INSERT INTO forestry_survey (id,species,diameter,height,volume) VALUES (3,'Pine',3.8,80,12.3);
SELECT SUM(height) FROM forestry_survey WHERE species = 'Redwood';
Determine the number of users who achieved over 10,000 steps per day on average in 2021.
CREATE TABLE DailySteps (user_id INT,steps INT,activity_date DATE); INSERT INTO DailySteps (user_id,steps,activity_date) VALUES (1,12000,'2021-01-01'),(2,8000,'2021-01-02'),(3,15000,'2021-12-31');
SELECT COUNT(*) FROM (SELECT user_id, AVG(steps) avg_steps FROM DailySteps GROUP BY user_id) subquery WHERE avg_steps > 10000;
What is the recycling rate of plastic in the commercial sector?
CREATE TABLE recycling_rates (sector VARCHAR(20),material VARCHAR(20),recycling_rate DECIMAL(5,2)); INSERT INTO recycling_rates (sector,material,recycling_rate) VALUES ('residential','plastic',0.25),('commercial','plastic',0.30),('residential','paper',0.40),('commercial','paper',0.50);
SELECT recycling_rate FROM recycling_rates WHERE sector = 'commercial' AND material = 'plastic';
Show the number of unique investors who have invested in companies that have an exit strategy.
CREATE TABLE Companies (id INT,name TEXT,has_exit_strategy BOOLEAN); INSERT INTO Companies (id,name,has_exit_strategy) VALUES (1,'Star Startup',TRUE); INSERT INTO Companies (id,name,has_exit_strategy) VALUES (2,'Moonshot Inc',FALSE); CREATE TABLE Investors (id INT,name TEXT); INSERT INTO Investors (id,name) VALUES (1,'Venture Capital 4'); INSERT INTO Investors (id,name) VALUES (2,'Angel Investor 4');
SELECT COUNT(DISTINCT Investors.name) FROM Companies INNER JOIN Investors ON TRUE WHERE Companies.has_exit_strategy = TRUE;
Identify smart city projects with overlapping start and end dates.
CREATE TABLE smart_transportation_projects (id INT,project_name VARCHAR(255),project_type VARCHAR(255),location VARCHAR(255),start_date DATE,end_date DATE,PRIMARY KEY(id)); INSERT INTO smart_transportation_projects (id,project_name,project_type,location,start_date,end_date) VALUES (1,'Bike Sharing','Transportation','Barcelona','2022-06-01','2024-05-31'),(2,'Autonomous Buses','Transportation','Singapore','2023-01-15','2025-01-14'),(3,'Smart Traffic Lights','Transportation','Amsterdam','2023-02-01','2022-01-31');
SELECT project_name, project_type, location, start_date, end_date FROM smart_transportation_projects WHERE start_date <= end_date AND end_date >= start_date;
What is the average age of members in unions that have a focus on healthcare?
CREATE TABLE union_members (member_id INT,name VARCHAR(50),age INT,union_id INT); CREATE TABLE unions (union_id INT,union_name VARCHAR(50),focus VARCHAR(50)); INSERT INTO union_members (member_id,name,age,union_id) VALUES (1,'John Doe',35,1),(2,'Jane Smith',40,1),(3,'Mike Johnson',30,2); INSERT INTO unions (union_id,union_name,focus) VALUES (1,'Healthcare Workers Union','healthcare'),(2,'Teachers Union','education');
SELECT AVG(um.age) FROM union_members um INNER JOIN unions u ON um.union_id = u.union_id WHERE u.focus = 'healthcare';
What are the defense diplomacy activities between France and Germany?
CREATE TABLE defense_diplomacy (activity_id INT,country1 TEXT,country2 TEXT); INSERT INTO defense_diplomacy (activity_id,country1,country2) VALUES (1,'France','Germany'),(2,'Germany','France');
SELECT * FROM defense_diplomacy WHERE (country1 = 'France' AND country2 = 'Germany') OR (country1 = 'Germany' AND country2 = 'France')
Insert new records into the "player_inventory" table with the following data: (1, 'Health Potion', 5), (2, 'Gold Coin', 100)
CREATE TABLE player_inventory (player_id INT,item_name VARCHAR(50),quantity INT);
WITH cte AS (VALUES (1, 'Health Potion', 5), (2, 'Gold Coin', 100)) INSERT INTO player_inventory (player_id, item_name, quantity) SELECT * FROM cte;
Find the total number of male and female employees in the 'hr' and 'operations' departments and exclude employees from the 'management' role.
CREATE TABLE employees (id INT,name VARCHAR(50),gender VARCHAR(50),department VARCHAR(50),role VARCHAR(50)); INSERT INTO employees (id,name,gender,department,role) VALUES (1,'John Doe','male','hr','employee'); INSERT INTO employees (id,name,gender,department,role) VALUES (2,'Jane Smith','female','hr','manager'); INSERT INTO employees (id,name,gender,department,role) VALUES (3,'Bob Johnson','male','operations','employee');
SELECT COUNT(*) FILTER (WHERE gender = 'male') AS male_count, COUNT(*) FILTER (WHERE gender = 'female') AS female_count FROM employees WHERE department IN ('hr', 'operations') AND role != 'manager';
What is the total number of players who play "Battle Royale Adventure" or "Rhythm Game 2023"?
CREATE TABLE Players (PlayerID INT,PlayerName VARCHAR(50),Game VARCHAR(50)); INSERT INTO Players (PlayerID,PlayerName,Game) VALUES (1,'Sophia Garcia','Battle Royale Adventure'),(2,'Daniel Kim','Rhythm Game 2023'),(3,'Lila Hernandez','Virtual Reality Chess'),(4,'Kenji Nguyen','Racing Simulator 2022');
SELECT COUNT(*) FROM Players WHERE Game IN ('Battle Royale Adventure', 'Rhythm Game 2023');
Which departments have taken a diversity and inclusion training course?
CREATE TABLE Employees (EmployeeID INT,Department VARCHAR(50)); INSERT INTO Employees (EmployeeID,Department) VALUES (1,'IT'); INSERT INTO Employees (EmployeeID,Department) VALUES (2,'IT'); INSERT INTO Employees (EmployeeID,Department) VALUES (3,'HR'); INSERT INTO Employees (EmployeeID,Department) VALUES (4,'Finance'); CREATE TABLE Training (TrainingID INT,Course VARCHAR(50),EmployeeID INT); INSERT INTO Training (TrainingID,Course,EmployeeID) VALUES (1,'Diversity and Inclusion',1); INSERT INTO Training (TrainingID,Course,EmployeeID) VALUES (2,'Diversity and Inclusion',3);
SELECT Department FROM Employees INNER JOIN Training ON Employees.EmployeeID = Training.EmployeeID WHERE Course = 'Diversity and Inclusion'
What is the description of the latest cybersecurity strategy in the 'cybersecurity' table?
CREATE TABLE cybersecurity (strategy_id INT,strategy_name VARCHAR(50),description TEXT,last_updated TIMESTAMP);
SELECT description FROM cybersecurity WHERE strategy_id = (SELECT strategy_id FROM cybersecurity WHERE last_updated = (SELECT MAX(last_updated) FROM cybersecurity));
What are the names of all the marine species that are part of any research initiative in the 'marine_species' and 'research_initiatives' tables?
CREATE TABLE marine_species (id INT,species_name VARCHAR(50),ocean VARCHAR(50)); CREATE TABLE research_initiatives (id INT,species_name VARCHAR(50),initiative_id INT);
SELECT species_name FROM marine_species WHERE species_name IN (SELECT species_name FROM research_initiatives);
How many sustainable materials were used in total for project with ID 2?
CREATE TABLE sustainability (id INT,project_id INT,sustainable_material VARCHAR(255),amount_used INT); INSERT INTO sustainability (id,project_id,sustainable_material,amount_used) VALUES (1,1,'Recycled Steel',1000),(2,2,'Reclaimed Wood',500),(3,2,'Eco-Friendly Paint',300);
SELECT SUM(amount_used) FROM sustainability WHERE project_id = 2;
Delete records in waste_generation table where the generation_date is after 2020-01-01
CREATE TABLE waste_generation (id INT,location VARCHAR(50),generation_date DATE,waste_amount INT); INSERT INTO waste_generation (id,location,generation_date,waste_amount) VALUES (1,'New York','2018-01-01',1000),(2,'Los Angeles','2019-01-01',2000),(3,'London','2020-01-01',1200),(4,'Sydney','2019-07-01',1800),(5,'Rio de Janeiro','2018-05-01',2500);
DELETE FROM waste_generation WHERE generation_date > '2020-01-01';
What is the total number of songs produced by artists from the United States?
CREATE TABLE artists (id INT,name TEXT,country TEXT); INSERT INTO artists (id,name,country) VALUES (1,'Taylor Swift','United States'),(2,'Eminem','United States'); CREATE TABLE songs (id INT,title TEXT,artist_id INT); INSERT INTO songs (id,title,artist_id) VALUES (1,'Shake it Off',1),(2,'Lose Yourself',2);
SELECT COUNT(*) FROM songs JOIN artists ON songs.artist_id = artists.id WHERE artists.country = 'United States';
Add a new organization to the database
CREATE TABLE organization (org_id INT,org_name TEXT); INSERT INTO organization (org_id,org_name) VALUES (1,'Volunteers Inc'); INSERT INTO organization (org_id,org_name) VALUES (2,'Helping Hands');
INSERT INTO organization (org_id, org_name) VALUES (3, 'Caring Communities');
List all maritime law violations in the 'maritime_law_violations' table
CREATE TABLE maritime_law_violations (id INT PRIMARY KEY,vessel_name VARCHAR(255),violation_type VARCHAR(255),fine FLOAT,violation_date DATE);
SELECT * FROM maritime_law_violations;
What is the average depth of all marine protected areas in the Pacific region?'
CREATE TABLE marine_protected_areas (id INT,name TEXT,region TEXT,avg_depth FLOAT); INSERT INTO marine_protected_areas (id,name,region,avg_depth) VALUES (1,'Galapagos Marine Reserve','Pacific',200.5); INSERT INTO marine_protected_areas (id,name,region,avg_depth) VALUES (2,'Great Barrier Reef','Pacific',91.4);
SELECT AVG(avg_depth) FROM marine_protected_areas WHERE region = 'Pacific';
Identify the number of wells drilled by each operator in the Gulf of Mexico
CREATE TABLE operators (operator_id INT,operator_name TEXT); INSERT INTO operators (operator_id,operator_name) VALUES (1,'Company A'),(2,'Company B'); CREATE TABLE wells (well_id INT,operator_id INT,location TEXT); INSERT INTO wells (well_id,operator_id,location) VALUES (1,1,'Gulf of Mexico'),(2,1,'Atlantic'),(3,2,'Gulf of Mexico'),(4,2,'Caribbean');
SELECT o.operator_name, COUNT(w.well_id) AS num_wells_drilled FROM wells w JOIN operators o ON w.operator_id = o.operator_id WHERE w.location = 'Gulf of Mexico' GROUP BY o.operator_id;
Present the number of intelligence operations conducted per country in the last 5 years
CREATE TABLE intelligence_operations (operation_name VARCHAR(255),operation_year INT,country VARCHAR(255)); INSERT INTO intelligence_operations (operation_name,operation_year,country) VALUES ('Operation Red Sparrow',2018,'Russia'),('Operation Black Swan',2017,'China');
SELECT country, operation_year FROM intelligence_operations WHERE operation_year BETWEEN (YEAR(CURRENT_DATE) - 5) AND YEAR(CURRENT_DATE) GROUP BY country, operation_year;
How many items are there in the 'NY' warehouse?
CREATE TABLE warehouse (id INT,name VARCHAR(255),location VARCHAR(255)); INSERT INTO warehouse (id,name,location) VALUES (1,'NY','New York'),(2,'LA','Los Angeles'); CREATE TABLE inventory (item_code VARCHAR(255),quantity INT,warehouse_id INT); INSERT INTO inventory (item_code,quantity,warehouse_id) VALUES ('EGG-01',300,1),('APP-01',200,1),('ORG-01',150,2);
SELECT COUNT(DISTINCT item_code) FROM inventory WHERE warehouse_id = (SELECT id FROM warehouse WHERE location = 'New York');
Find the total number of tickets sold for basketball games in the Pacific Northwest in 2020.
CREATE TABLE basketball_games(id INT,team VARCHAR(50),location VARCHAR(50),year INT,tickets_sold INT); INSERT INTO basketball_games(id,team,location,year,tickets_sold) VALUES (1,'Portland Trail Blazers','Moda Center',2020,765000),(2,'Seattle SuperSonics','KeyArena',2020,600000),(3,'Oklahoma City Thunder','Chesapeake Energy Arena',2020,550000);
SELECT SUM(tickets_sold) FROM basketball_games WHERE location IN ('Moda Center', 'KeyArena') AND year = 2020;
Show the number of patients and providers in the rural healthcare system.
CREATE TABLE Patients (ID INT,Name TEXT); CREATE TABLE Providers (ID INT,Name TEXT,Type TEXT);
SELECT (SELECT COUNT(*) FROM Patients) + (SELECT COUNT(*) FROM Providers) AS Total;
What percentage of digital divide initiatives are led by BIPOC individuals?
CREATE TABLE initiatives (id INT,leader VARCHAR(255),initiative_type VARCHAR(255)); INSERT INTO initiatives (id,leader,initiative_type) VALUES (1,'BIPOC Woman','digital_divide'),(2,'White Man','digital_divide'),(3,'BIPOC Man','accessibility');
SELECT (COUNT(*) FILTER (WHERE leader ILIKE '%BIPOC%')) * 100.0 / COUNT(*) FROM initiatives WHERE initiative_type = 'digital_divide';
What is the total duration of all songs in the pop genre?
CREATE TABLE songs (id INT,title VARCHAR(255),duration INT,genre VARCHAR(255)); INSERT INTO songs (id,title,duration,genre) VALUES (1,'Song 1',180,'Pop');
SELECT SUM(duration) FROM songs WHERE genre = 'Pop';
Calculate the average productivity for 'Silver' mineral extractions in all regions.
CREATE TABLE Productivity_Silver (mineral TEXT,region TEXT,productivity REAL); INSERT INTO Productivity_Silver (mineral,region,productivity) VALUES ('Silver','Africa',3.2); INSERT INTO Productivity_Silver (mineral,region,productivity) VALUES ('Silver','Asia',3.6); INSERT INTO Productivity_Silver (mineral,region,productivity) VALUES ('Silver','Europe',3.4);
SELECT AVG(productivity) FROM Productivity_Silver WHERE mineral = 'Silver';
What is the total number of military aircrafts by type, maintained by contractor X in the year 2020?
CREATE TABLE military_aircrafts(id INT,type VARCHAR(255),manufacturer VARCHAR(255),year INT,contractor VARCHAR(255));
SELECT type, COUNT(*) as total FROM military_aircrafts WHERE contractor = 'X' AND year = 2020 GROUP BY type;
What is the percentage of products made by fair trade manufacturers?
CREATE TABLE manufacturers (id INT PRIMARY KEY,name TEXT,location TEXT,is_fair_trade BOOLEAN); CREATE TABLE products (id INT PRIMARY KEY,name TEXT,category TEXT,price DECIMAL,manufacturer_id INT,FOREIGN KEY (manufacturer_id) REFERENCES manufacturers(id));
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM products)) FROM products p JOIN manufacturers m ON p.manufacturer_id = m.id WHERE m.is_fair_trade = TRUE;
What is the maximum fare for public transportation in each region?
CREATE TABLE Region (RegionID INT,RegionName VARCHAR(255)); INSERT INTO Region (RegionID,RegionName) VALUES (1,'RegionX'),(2,'RegionY'),(3,'RegionZ'); CREATE TABLE Fare (FareID INT,RegionID INT,FareAmount DECIMAL(5,2)); INSERT INTO Fare (FareID,RegionID,FareAmount) VALUES (1,1,3.50),(2,1,2.80),(3,2,4.20),(4,2,3.90),(5,3,1.50),(6,3,1.80);
SELECT Region.RegionName, MAX(FareAmount) FROM Region JOIN Fare ON Region.RegionID = Fare.RegionID GROUP BY Region.RegionName;
What is the budget for the Parks and Recreation department after a 10% increase?
CREATE TABLE CityBudget (BudgetID INT PRIMARY KEY,Department VARCHAR(50),BudgetAmount DECIMAL(10,2)); INSERT INTO CityBudget (BudgetID,Department,BudgetAmount) VALUES (1,'Public Works',250000.00),(2,'Education',750000.00),(3,'Parks and Recreation',150000.00);
UPDATE CityBudget SET BudgetAmount = BudgetAmount * 1.1 WHERE Department = 'Parks and Recreation';
How many accidents were reported for vessels in the 'Pacific' region?
CREATE TABLE Accidents (ID INT PRIMARY KEY,VesselID INT,Region TEXT); INSERT INTO Accidents (ID,VesselID,Region) VALUES (1,1,'Atlantic'),(2,2,'Pacific'),(3,3,'Atlantic');
SELECT COUNT(*) FROM Accidents WHERE Region = 'Pacific';
How many students have been served in each accommodation category?
CREATE TABLE Accommodations (student_id INT,accommodation_type TEXT); CREATE VIEW Accommodation_Counts AS SELECT accommodation_type,COUNT(*) FROM Accommodations GROUP BY accommodation_type;
SELECT * FROM Accommodation_Counts;
What is the total revenue for each salesperson in the sales database?
CREATE TABLE sales (salesperson VARCHAR(20),revenue INT); INSERT INTO sales (salesperson,revenue) VALUES ('John',5000),('Jane',7000),('Doe',6000);
SELECT salesperson, SUM(revenue) FROM sales GROUP BY salesperson;
What is the average distance run by users in a specific neighborhood?
CREATE TABLE Runs (id INT,user_id INT,distance FLOAT,neighborhood TEXT); INSERT INTO Runs (id,user_id,distance,neighborhood) VALUES (1,1,5.6,'West Village'),(2,2,7.2,'Silver Lake');
SELECT AVG(distance) FROM Runs WHERE neighborhood = 'West Village';
What is the maximum cargo weight handled by the ACME Shipping Company in a single port call?
CREATE TABLE cargo (id INT,vessel_name VARCHAR(255),port_name VARCHAR(255),weight INT); INSERT INTO cargo (id,vessel_name,port_name,weight) VALUES (1,'Seafarer','Port of Los Angeles',5000),(2,'Oceanus','Port of New York',7000),(3,'Neptune','Port of Singapore',8000),(4,'Seafarer','Port of Los Angeles',6000);
SELECT MAX(weight) FROM cargo WHERE vessel_name IN (SELECT name FROM vessels WHERE company = 'ACME Shipping');
What is the average depth of all marine protected areas in the Indian and Atlantic regions?
CREATE TABLE marine_protected_areas (name VARCHAR(255),location VARCHAR(255),depth FLOAT); INSERT INTO marine_protected_areas (name,location,depth) VALUES ('MPA 1','Indian',150.7); INSERT INTO marine_protected_areas (name,location,depth) VALUES ('MPA 2','Atlantic',200.3);
SELECT AVG(depth) FROM marine_protected_areas WHERE location IN ('Indian', 'Atlantic');
What is the total number of protected areas in each country?
CREATE TABLE countries (country_code CHAR(2),country_name VARCHAR(50)); CREATE TABLE protected_areas (area_id INT,area_name VARCHAR(50),country_code CHAR(2)); INSERT INTO countries (country_code,country_name) VALUES ('CA','Canada'),('US','United States'),('DK','Denmark'); INSERT INTO protected_areas (area_id,area_name,country_code) VALUES (1,'Waterton Lakes National Park','CA'),(2,'Banff National Park','CA'),(3,'Glacier National Park','US'),(4,'Thy National Park','DK');
SELECT country_code, COUNT(*) as total_protected_areas FROM protected_areas GROUP BY country_code;
What is the total amount of research grants awarded to women principal investigators in the last 3 years?
CREATE TABLE research_grants (id INT,pi_gender VARCHAR(10),year INT,amount INT); INSERT INTO research_grants (id,pi_gender,year,amount) VALUES (1,'Female',2020,50000); INSERT INTO research_grants (id,pi_gender,year,amount) VALUES (2,'Male',2019,75000);
SELECT SUM(amount) FROM research_grants WHERE pi_gender = 'Female' AND year BETWEEN 2019 AND 2021;
How many hotels adopted AI in the Americas and Europe?
CREATE TABLE ai_adoption (hotel_id INT,hotel_name VARCHAR(255),region VARCHAR(255),ai_adopted INT);
SELECT SUM(ai_adopted) FROM ai_adoption WHERE region IN ('Americas', 'Europe');
What is the average transaction amount for each product type?
CREATE TABLE product_types (id INT,product_type VARCHAR(50)); INSERT INTO product_types (id,product_type) VALUES (1,'Stocks'),(2,'Bonds'); CREATE TABLE transactions (product_type_id INT,transaction_amount DECIMAL(10,2)); INSERT INTO transactions (product_type_id,transaction_amount) VALUES (1,200.00),(1,300.00),(2,100.00),(2,400.00);
SELECT p.product_type, AVG(t.transaction_amount) as avg_transaction_amount FROM product_types p JOIN transactions t ON p.id = t.product_type_id GROUP BY p.product_type;
What is the total duration of strength training workouts for users aged 25-35?
CREATE TABLE workouts (id INT,user_id INT,workout_type VARCHAR(20),duration INT); INSERT INTO workouts (id,user_id,workout_type,duration) VALUES (1,101,'Strength Training',60),(2,102,'Strength Training',90),(3,103,'Strength Training',45),(4,104,'Yoga',30); CREATE TABLE users (id INT,birthdate DATE); INSERT INTO users (id,birthdate) VALUES (101,'1996-01-01'),(102,'1989-05-20'),(103,'1978-12-15'),(104,'2000-06-03');
SELECT SUM(duration) as total_duration FROM workouts JOIN users ON workouts.user_id = users.id WHERE users.birthdate BETWEEN '1986-01-01' AND '1996-12-31' AND workout_type = 'Strength Training';
Which menu items were inspected by the Food Safety Agency in the last 30 days?
CREATE TABLE menu_items (item_id INT,name VARCHAR(255),category VARCHAR(255)); INSERT INTO menu_items (item_id,name,category) VALUES (1,'Burger','Main Course'),(2,'Salad','Side Dish'); CREATE TABLE inspections (inspection_id INT,item_id INT,date DATE,result VARCHAR(255)); INSERT INTO inspections (inspection_id,item_id,date,result) VALUES (1,1,'2022-02-01','Passed'),(2,1,'2022-02-15','Passed'),(3,2,'2022-02-10','Failed');
SELECT m.name, i.date FROM menu_items m JOIN inspections i ON m.item_id = i.item_id WHERE i.date >= DATE(NOW()) - INTERVAL 30 DAY;
What is the total amount of funding received by public schools in the state of California in 2021 and 2022, using a cross join?
CREATE TABLE school_funding (state VARCHAR(255),year INT,school_name VARCHAR(255),funding_amount FLOAT); INSERT INTO school_funding (state,year,school_name,funding_amount) VALUES ('California',2021,'School A',500000.00),('California',2021,'School B',600000.00),('California',2021,'School C',700000.00),('California',2022,'School A',550000.00),('California',2022,'School B',650000.00),('California',2022,'School C',750000.00); CREATE TABLE schools (school_name VARCHAR(255),school_type VARCHAR(255)); INSERT INTO schools (school_name,school_type) VALUES ('School A','Public'),('School B','Public'),('School C','Public');
SELECT s.school_name, SUM(sf.funding_amount) AS total_funding_amount FROM school_funding sf CROSS JOIN schools s WHERE sf.state = 'California' AND sf.year IN (2021, 2022) AND s.school_type = 'Public' GROUP BY s.school_name;
Calculate the percentage of mobile subscribers using 4G technology in each country.
CREATE TABLE mobile_subscribers_2 (id INT,country VARCHAR(20),technology VARCHAR(10)); INSERT INTO mobile_subscribers_2 (id,country,technology) VALUES (1,'USA','4G'); INSERT INTO mobile_subscribers_2 (id,country,technology) VALUES (2,'Canada','5G');
SELECT country, technology, COUNT(*) as total, (COUNT(*) FILTER (WHERE technology = '4G')::FLOAT / COUNT(*)) * 100 as percentage FROM mobile_subscribers_2 GROUP BY country, technology HAVING technology = '4G';
What is the number of accessible technology initiatives in Asia?
CREATE TABLE accessible_tech (region VARCHAR(20),initiatives INT); INSERT INTO accessible_tech (region,initiatives) VALUES ('Africa',50),('Asia',75),('South America',100);
SELECT initiatives FROM accessible_tech WHERE region = 'Asia';
What is the average carbon price in India and Canada?
CREATE TABLE carbon_pricing (country VARCHAR(20),carbon_price DECIMAL(5,2)); INSERT INTO carbon_pricing (country,carbon_price) VALUES ('Germany',25.00),('France',32.00),('USA',12.00),('UK',28.00),('Italy',22.00),('India',8.00),('Canada',18.00);
SELECT AVG(carbon_price) FROM carbon_pricing WHERE country IN ('India', 'Canada');
List health insurance policy types and their respective average claim amounts.
CREATE TABLE HealthPolicyTypes (PolicyTypeID int,PolicyType varchar(20)); CREATE TABLE HealthClaims (ClaimID int,PolicyTypeID int,ClaimAmount decimal); INSERT INTO HealthPolicyTypes (PolicyTypeID,PolicyType) VALUES (1,'Health Maintenance Organization'); INSERT INTO HealthPolicyTypes (PolicyTypeID,PolicyType) VALUES (2,'Preferred Provider Organization'); INSERT INTO HealthClaims (ClaimID,PolicyTypeID,ClaimAmount) VALUES (1,1,1200); INSERT INTO HealthClaims (ClaimID,PolicyTypeID,ClaimAmount) VALUES (2,2,1800);
SELECT HealthPolicyTypes.PolicyType, AVG(HealthClaims.ClaimAmount) FROM HealthPolicyTypes INNER JOIN HealthClaims ON HealthPolicyTypes.PolicyTypeID = HealthClaims.PolicyTypeID GROUP BY HealthPolicyTypes.PolicyType;