instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
What is the average age of language preservation volunteers in Mexico?
|
CREATE TABLE volunteers (id INT,age INT,country TEXT,role TEXT); INSERT INTO volunteers (id,age,country,role) VALUES (1,35,'Mexico','Language Preservation'),(2,45,'USA','Language Preservation'),(3,28,'Mexico','Community Engagement');
|
SELECT AVG(age) FROM volunteers WHERE country = 'Mexico' AND role = 'Language Preservation';
|
Minimum funding for biotech startups in California
|
CREATE SCHEMA if not exists biotech; CREATE TABLE if not exists biotech.startups (id INT,name TEXT,location TEXT,funding FLOAT); INSERT INTO biotech.startups (id,name,location,funding) VALUES (1,'StartupA','Texas',5000000.00); INSERT INTO biotech.startups (id,name,location,funding) VALUES (2,'StartupB','California',7000000.00); INSERT INTO biotech.startups (id,name,location,funding) VALUES (3,'StartupC','Texas',3000000.00); INSERT INTO biotech.startups (id,name,location,funding) VALUES (4,'StartupD','California',4000000.00); INSERT INTO biotech.startups (id,name,location,funding) VALUES (5,'StartupE','California',2000000.00);
|
SELECT MIN(funding) FROM biotech.startups WHERE location = 'California';
|
Find the average water consumption per person in Middle Eastern countries.
|
CREATE TABLE middle_eastern_countries (country VARCHAR(255),population INT,water_consumption INT); INSERT INTO middle_eastern_countries (country,population,water_consumption) VALUES ('Saudi Arabia',34000000,13600000000),('Iran',84000000,33600000000);
|
SELECT country, water_consumption / population AS avg_water_consumption FROM middle_eastern_countries;
|
Determine the number of times each crop type has been planted in Field3, Field5, and Field8 in 2022.
|
CREATE TABLE crop_planting (id INT,location VARCHAR(50),crop VARCHAR(50),planting_date DATE,planting_time TIME); INSERT INTO crop_planting (id,location,crop,planting_date,planting_time) VALUES (1,'Field3','Corn','2022-02-20','14:30:00'),(2,'Field5','Soybeans','2022-03-01','09:45:00');
|
SELECT crop, COUNT(*) AS planting_count FROM crop_planting WHERE location IN ('Field3', 'Field5', 'Field8') AND planting_date >= '2022-01-01' AND planting_date < '2023-01-01' GROUP BY crop;
|
Which programs had the highest volunteer hours in 2021?
|
CREATE TABLE volunteer_hours (volunteer_id INT,program_id INT,hours DECIMAL(10,2),hour_date DATE); INSERT INTO volunteer_hours VALUES (1,101,3.00,'2021-01-01'),(2,101,2.50,'2021-02-01'),(3,102,4.00,'2021-01-10');
|
SELECT program_id, SUM(hours) FROM volunteer_hours GROUP BY program_id ORDER BY SUM(hours) DESC LIMIT 1;
|
What is the total number of maintenance events for trams in the last year?
|
CREATE TABLE TramMaintenance (MaintenanceID INT,MaintenanceDate DATE,VehicleID INT);
|
SELECT COUNT(MaintenanceID) FROM TramMaintenance WHERE MaintenanceDate >= DATEADD(YEAR, -1, GETDATE());
|
What is the suicide rate in each region?
|
CREATE TABLE SuicideRates (Region VARCHAR(50),Population INT,Suicides INT); INSERT INTO SuicideRates (Region,Population,Suicides) VALUES ('North',1000000,1000),('South',1200000,1500),('East',1100000,1200),('West',900000,900);
|
SELECT Region, (SUM(Suicides) / SUM(Population)) * 100000 AS SuicideRate FROM SuicideRates GROUP BY Region;
|
What is the number of cases handled by each restorative justice facilitator, broken down by facilitator name and case type?
|
CREATE TABLE RestorativeJusticeFacilitators (FacilitatorName text,CaseType text,NumCases int); INSERT INTO RestorativeJusticeFacilitators VALUES ('Facilitator1','Assault',15,'2022-01-01'),('Facilitator1','Theft',10,'2022-01-01'),('Facilitator2','Assault',12,'2022-01-01'),('Facilitator2','Theft',8,'2022-01-01');
|
SELECT FacilitatorName, CaseType, SUM(NumCases) FROM RestorativeJusticeFacilitators GROUP BY FacilitatorName, CaseType;
|
What is the minimum, maximum, and average salary by job level?
|
CREATE TABLE job_levels (id INT,level VARCHAR(255)); INSERT INTO job_levels (id,level) VALUES (1,'Entry'),(2,'Mid'),(3,'Senior'); CREATE TABLE salaries (id INT,job_level_id INT,salary INT); INSERT INTO salaries (id,job_level_id,salary) VALUES (1,1,50000),(2,2,70000),(3,3,90000);
|
SELECT job_levels.level, MIN(salaries.salary) as min_salary, MAX(salaries.salary) as max_salary, AVG(salaries.salary) as avg_salary FROM job_levels JOIN salaries ON job_levels.id = salaries.job_level_id GROUP BY job_levels.level;
|
Identify the states with the highest and lowest budget allocation to infrastructure
|
CREATE TABLE states (state_id INT PRIMARY KEY,state_name TEXT,budget_allocation FLOAT);CREATE TABLE infrastructure_budget (state_id INT,budget FLOAT);
|
SELECT s.state_name, AVG(ib.budget) as avg_budget FROM states s INNER JOIN infrastructure_budget ib ON s.state_id = ib.state_id GROUP BY s.state_name ORDER BY avg_budget DESC LIMIT 1;SELECT s.state_name, AVG(ib.budget) as avg_budget FROM states s INNER JOIN infrastructure_budget ib ON s.state_id = ib.state_id GROUP BY s.state_name ORDER BY avg_budget ASC LIMIT 1;
|
What is the maximum account balance for clients in the Asia Pacific region?
|
CREATE TABLE clients (client_id INT,name VARCHAR(50),region VARCHAR(50),account_balance DECIMAL(10,2)); INSERT INTO clients (client_id,name,region,account_balance) VALUES (1,'Lei Wang','Asia Pacific',35000.00),(2,'Hiroshi Tanaka','Asia Pacific',40000.00);
|
SELECT MAX(account_balance) FROM clients WHERE region = 'Asia Pacific';
|
What is the average number of visitors for natural destinations in each country?
|
CREATE TABLE Destinations (id INT PRIMARY KEY,country_id INT,name VARCHAR(255),type VARCHAR(255)); INSERT INTO Destinations (id,country_id,name,type) VALUES (1,1,'Sydney Opera House','Cultural'); INSERT INTO Destinations (id,country_id,name,type) VALUES (2,1,'Great Barrier Reef','Natural'); INSERT INTO Destinations (id,country_id,name,type) VALUES (3,2,'Niagara Falls','Natural'); INSERT INTO Destinations (id,country_id,name,type) VALUES (4,2,'CN Tower','Architectural');
|
SELECT country_id, AVG(visitors) FROM Tourists t JOIN Destinations d ON t.country_id = d.country_id WHERE d.type = 'Natural' GROUP BY country_id;
|
What is the total donation amount per donor, sorted by the highest donors?
|
CREATE TABLE Donors (DonorID INT,DonorName VARCHAR(50),TotalDonation DECIMAL(10,2)); INSERT INTO Donors (DonorID,DonorName,TotalDonation) VALUES (1,'John Doe',15000.00),(2,'Jane Smith',12000.00),(3,'Alice Johnson',10000.00);
|
SELECT DonorName, TotalDonation FROM (SELECT DonorName, TotalDonation, ROW_NUMBER() OVER (ORDER BY TotalDonation DESC) as rnk FROM Donors) sub WHERE rnk = 1 OR rnk = 2 OR rnk = 3;
|
Show the number of threat intelligence reports generated by each agency in the past quarter
|
CREATE TABLE threat_intelligence_reports (report_id INT,report_date DATE,threat_category VARCHAR(255),generating_agency VARCHAR(255));
|
SELECT generating_agency, COUNT(*) as report_count FROM threat_intelligence_reports WHERE report_date >= DATEADD(quarter, -1, CURRENT_DATE) GROUP BY generating_agency;
|
Show the number of active training programs by department
|
training_programs
|
SELECT department, COUNT(*) as active_programs FROM training_programs WHERE CURDATE() BETWEEN start_date AND end_date GROUP BY department;
|
What is the average donation amount for donors from Oceania?
|
CREATE TABLE Donors (DonorID int,DonorName varchar(50),Country varchar(50)); INSERT INTO Donors (DonorID,DonorName,Country) VALUES (1,'John Doe','United States'); INSERT INTO Donors (DonorID,DonorName,Country) VALUES (2,'Jane Smith','Australia'); INSERT INTO Donors (DonorID,DonorName,Country) VALUES (3,'Alice Johnson','Japan'); CREATE TABLE Donations (DonationID int,DonorID int,DonationAmount decimal(10,2)); INSERT INTO Donations (DonationID,DonorID,DonationAmount) VALUES (1,1,5000); INSERT INTO Donations (DonationID,DonorID,DonationAmount) VALUES (2,2,1000); INSERT INTO Donations (DonationID,DonorID,DonationAmount) VALUES (3,2,1500); INSERT INTO Donations (DonationID,DonorID,DonationAmount) VALUES (4,3,2000);
|
SELECT AVG(Donations.DonationAmount) as AverageDonationAmount FROM Donors INNER JOIN Donations ON Donations.DonorID = Donors.DonorID WHERE Donors.Country IN ('Australia');
|
Identify the top 5 most purchased products in the "skincare" category by customers from the United States.
|
CREATE TABLE customer_orders (id INT,customer VARCHAR(100),product VARCHAR(100),category VARCHAR(100),order_date DATE,quantity INT);
|
SELECT product, SUM(quantity) as total_purchases FROM customer_orders WHERE country = 'United States' AND category = 'skincare' GROUP BY product ORDER BY total_purchases DESC LIMIT 5;
|
What is the total revenue generated by each game category in Q2 2022?
|
CREATE SCHEMA if not exists gaming; CREATE TABLE if not exists gaming.games (game_id INT,game_name VARCHAR(255),category VARCHAR(255),release_date DATE,revenue FLOAT); INSERT INTO gaming.games (game_id,game_name,category,release_date,revenue) VALUES (1,'Game A','Action','2021-01-01',5000000),(2,'Game B','Adventure','2021-06-15',7000000),(3,'Game C','Simulation','2022-04-01',3000000),(4,'Game D','Strategy','2022-07-22',8000000);
|
SELECT category, SUM(revenue) as total_revenue FROM gaming.games WHERE release_date BETWEEN '2022-04-01' AND '2022-06-30' GROUP BY category;
|
What is the average number of wins per season for a specific football team?
|
CREATE TABLE team_wins (id INT,team VARCHAR(50),sport VARCHAR(20),season VARCHAR(10),wins INT);
|
SELECT AVG(wins) FROM team_wins WHERE team = 'Manchester United' AND sport = 'Football' GROUP BY season;
|
What is the name and implementation date of each cybersecurity strategy implemented by NATO in the last 5 years?
|
CREATE TABLE NATOCybersecurityStrategies (id INT,strategy VARCHAR(255),implementation_date DATE); INSERT INTO NATOCybersecurityStrategies (id,strategy,implementation_date) VALUES (1,'NATO Cyber Defence Pledge','2016-07-08'); INSERT INTO NATOCybersecurityStrategies (id,strategy,implementation_date) VALUES (2,'NATO Cyber Coalition','2018-11-14');
|
SELECT strategy, implementation_date FROM NATOCybersecurityStrategies WHERE implementation_date >= DATE_SUB(CURDATE(), INTERVAL 5 YEAR);
|
Update the quantity of item_id 100 to 500 in the item_inventory table
|
CREATE TABLE item_inventory (item_id INT,item_name VARCHAR(50),quantity INT,warehouse_id INT);
|
UPDATE item_inventory SET quantity = 500 WHERE item_id = 100;
|
What are the top 2 most viewed cities for virtual tours in 'North America'?
|
CREATE TABLE virtual_tours (tour_id INT,city TEXT,views INT); INSERT INTO virtual_tours (tour_id,city,views) VALUES (1,'CityX',200),(2,'CityY',300),(3,'CityZ',150),(4,'CityX',250),(5,'CityW',400);
|
SELECT city, SUM(views) as total_views FROM virtual_tours WHERE city IN ('CityX', 'CityY', 'CityZ', 'CityW') GROUP BY city ORDER BY total_views DESC LIMIT 2;
|
Show affordable housing units by city and their respective occupancy rates.
|
CREATE TABLE AffordableHousing (UnitID INT,City VARCHAR(50),OccupancyRate DECIMAL(4,2)); INSERT INTO AffordableHousing (UnitID,City,OccupancyRate) VALUES (1,'San Francisco',0.85),(2,'New York',0.92),(3,'Los Angeles',0.76);
|
SELECT City, OccupancyRate FROM AffordableHousing WHERE UnitID IN (SELECT UnitID FROM AffordableHousing WHERE City IN ('San Francisco', 'New York', 'Los Angeles') AND OccupancyRate < 1);
|
Identify the geopolitical risk assessments with high, medium, and low risks for the Middle East in the past 6 months.
|
CREATE TABLE RiskAssessments (assessment_id INT,region VARCHAR(50),risk_level VARCHAR(10),assessment_date DATE);
|
SELECT region, risk_level FROM RiskAssessments WHERE region = 'Middle East' AND assessment_date BETWEEN '2022-01-01' AND CURDATE() GROUP BY region, risk_level;
|
List the top 3 states with the highest wastewater treatment plant efficiency in descending order.
|
CREATE TABLE WastewaterTreatmentPlants (ID INT,State VARCHAR(20),Efficiency FLOAT); INSERT INTO WastewaterTreatmentPlants (ID,State,Efficiency) VALUES (1,'California',0.92),(2,'Texas',0.91),(3,'Florida',0.89),(4,'California',0.93),(5,'Texas',0.90),(6,'Florida',0.88);
|
SELECT State, Efficiency FROM (SELECT State, Efficiency, ROW_NUMBER() OVER (ORDER BY Efficiency DESC) as rn FROM WastewaterTreatmentPlants) tmp WHERE rn <= 3
|
What is the total number of AI models created for finance applications, by month, in the year 2023, for companies based in South America?
|
CREATE TABLE FinanceAIs (ID INT,AI VARCHAR(255),Type VARCHAR(255),Date DATE,Company_Country VARCHAR(255)); INSERT INTO FinanceAIs (ID,AI,Type,Date,Company_Country) VALUES (1,'AI1','Finance','2023-01-01','Brazil'),(2,'AI2','Non-Finance','2023-01-05','Argentina'),(3,'AI3','Finance','2023-02-12','Chile'),(4,'AI4','Finance','2023-03-01','Colombia'),(5,'AI5','Non-Finance','2023-03-05','Peru'),(6,'AI6','Finance','2023-04-01','Uruguay'),(7,'AI7','Finance','2023-05-01','Bolivia');
|
SELECT EXTRACT(MONTH FROM Date) as Month, COUNT(*) as Total_Finance_AIs FROM FinanceAIs WHERE Type = 'Finance' AND Date BETWEEN '2023-01-01' AND '2023-12-31' AND Company_Country IN ('Brazil', 'Argentina', 'Chile', 'Colombia', 'Peru', 'Uruguay', 'Bolivia') GROUP BY Month;
|
Which retailer sold the most 'Tops'?
|
CREATE TABLE RetailerB (item VARCHAR(20),quantity INT); INSERT INTO RetailerB VALUES ('Tops',300);
|
SELECT item, MAX(quantity) FROM RetailerB WHERE item = 'Tops';
|
What is the total number of cybersecurity vulnerabilities found in 'Middle East' and 'Oceania' in 2019 and 2020?
|
CREATE TABLE CybersecurityVulnerabilities (ID INT,Country VARCHAR(50),Year INT,Vulnerabilities INT); INSERT INTO CybersecurityVulnerabilities (ID,Country,Year,Vulnerabilities) VALUES (1,'Country1',2019,100); INSERT INTO CybersecurityVulnerabilities (ID,Country,Year,Vulnerabilities) VALUES (2,'Country2',2020,150); INSERT INTO CybersecurityVulnerabilities (ID,Country,Year,Vulnerabilities) VALUES (3,'Country3',2019,120);
|
SELECT Country, SUM(Vulnerabilities) as TotalVulnerabilities FROM CybersecurityVulnerabilities WHERE Country IN ('Middle East', 'Oceania') AND Year IN (2019, 2020) GROUP BY Country;
|
What is the maximum ocean acidity level in the Atlantic region?
|
CREATE TABLE ocean_acidity (region varchar(255),level decimal(10,2)); INSERT INTO ocean_acidity (region,level) VALUES ('Atlantic',8.10),('Pacific',7.90),('Indian',8.05);
|
SELECT MAX(level) FROM ocean_acidity WHERE region = 'Atlantic';
|
Which astronauts have never flown a mission to Mars?
|
CREATE TABLE Astronauts (ID INT,Name VARCHAR(255),Missions VARCHAR(255)); CREATE TABLE Missions (ID INT,Destination VARCHAR(255)); INSERT INTO Astronauts (ID,Name,Missions) VALUES (1,'Astronaut1','Mars,Moon'),(2,'Astronaut2','Mars'),(3,'Astronaut3','Moon'); INSERT INTO Missions (ID,Destination) VALUES (1,'Mars'),(2,'Mars'),(3,'Moon'),(4,'Mars');
|
SELECT Astronauts.Name FROM Astronauts LEFT JOIN Missions ON Astronauts.Missions = Missions.Destination WHERE Destination IS NULL;
|
What is the total number of fans who attended games in 'New York'?
|
CREATE TABLE teams (team_id INT,team_name VARCHAR(255),city VARCHAR(100)); INSERT INTO teams (team_id,team_name,city) VALUES (1,'Golden State Warriors','San Francisco'),(2,'New York Knicks','New York'); CREATE TABLE game_attendance (game_id INT,team_id INT,num_fans INT); INSERT INTO game_attendance (game_id,team_id,num_fans) VALUES (1,1,15000),(2,1,20000),(3,2,10000),(4,2,25000),(5,2,30000);
|
SELECT SUM(ga.num_fans) as total_fans_attended FROM game_attendance ga WHERE ga.team_id IN (SELECT t.team_id FROM teams t WHERE t.city = 'New York');
|
What was the combined budget for community development programs in India and Brazil in 2018?'
|
CREATE TABLE CommunityDevelopmentPrograms (id INT,country VARCHAR(50),program_name VARCHAR(100),budget FLOAT); INSERT INTO CommunityDevelopmentPrograms (id,country,program_name,budget) VALUES (1,'India','Rural Education',25000.0),(2,'Brazil','Clean Water Initiative',30000.0);
|
SELECT SUM(budget) FROM CommunityDevelopmentPrograms WHERE country IN ('India', 'Brazil') AND YEAR(start_date) = 2018;
|
What is the total donation amount per month in 2022?
|
CREATE TABLE Donations (DonationID INT,DonorID INT,DonationDate DATE,DonationAmount FLOAT); INSERT INTO Donations (DonationID,DonorID,DonationDate,DonationAmount) VALUES (1,1,'2022-01-01',75.00),(2,2,'2022-02-14',125.00);
|
SELECT DATE_FORMAT(DonationDate, '%Y-%m') AS Month, SUM(DonationAmount) AS TotalDonation FROM Donations WHERE YEAR(DonationDate) = 2022 GROUP BY Month;
|
What is the average age of players who have participated in esports events, and the number of VR games they have played?
|
CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10)); INSERT INTO Players VALUES (1,25,'Male'); INSERT INTO Players VALUES (2,22,'Female'); CREATE TABLE EsportsEvents (EventID INT,PlayerID INT,EventName VARCHAR(20)); INSERT INTO EsportsEvents VALUES (1,1,'Dreamhack'); INSERT INTO EsportsEvents VALUES (2,2,'ESL One'); CREATE TABLE VRGameSessions (SessionID INT,PlayerID INT,VRGameCount INT); INSERT INTO VRGameSessions VALUES (1,1,5); INSERT INTO VRGameSessions VALUES (2,2,3);
|
SELECT AVG(Players.Age), AVG(VRGameSessions.VRGameCount) FROM Players INNER JOIN EsportsEvents ON Players.PlayerID = EsportsEvents.PlayerID INNER JOIN VRGameSessions ON Players.PlayerID = VRGameSessions.PlayerID;
|
List the names of healthcare professionals who work in rural areas of Mexico and the facilities they work for.
|
CREATE TABLE professionals (name TEXT,title TEXT,location TEXT); INSERT INTO professionals (name,title,location) VALUES ('Dr. Smith','Doctor','Rural Mexico'),('Nurse Johnson','Nurse','Rural Mexico'); CREATE TABLE facilities (name TEXT,location TEXT); INSERT INTO facilities (name,location) VALUES ('Facility X','Rural Mexico'),('Facility Y','Rural Mexico');
|
SELECT professionals.name, facilities.name FROM professionals INNER JOIN facilities ON professionals.location = facilities.location WHERE professionals.location = 'Rural Mexico';
|
List the top 3 organizations with the highest average expedition depth, along with their average depths.
|
CREATE TABLE expedition (org VARCHAR(20),depth INT); INSERT INTO expedition VALUES ('Ocean Explorer',2500),('Ocean Explorer',3000),('Sea Discoverers',2000),('Marine Investigators',4000),('Marine Investigators',4500),('Deep Sea Divers',7000),('Deep Sea Divers',6500),('Abyssal Pioneers',5000),('Abyssal Pioneers',5500);
|
SELECT org, AVG(depth) AS avg_depth FROM expedition GROUP BY org ORDER BY avg_depth DESC LIMIT 3;
|
What is the total investment value in the European market for clients with a last name starting with 'B'?
|
CREATE TABLE clients (client_id INT,name VARCHAR(50),region VARCHAR(50));CREATE TABLE investments (investment_id INT,client_id INT,market VARCHAR(50),value INT);INSERT INTO clients (client_id,name,region) VALUES (1,'John Doe','North America'),(2,'Barbara Black','Europe');INSERT INTO investments (investment_id,client_id,market,value) VALUES (1,1,'US',50000),(2,2,'Europe',120000);
|
SELECT SUM(i.value) FROM clients c INNER JOIN investments i ON c.client_id = i.client_id WHERE SUBSTRING(c.name, 1, 1) = 'B' AND i.market = 'Europe';
|
Find the total production quantity (in metric tons) of Gadolinium for the years 2015 and 2016.
|
CREATE TABLE production_data (year INT,element TEXT,production_quantity FLOAT); INSERT INTO production_data (year,element,production_quantity) VALUES (2015,'Gadolinium',450); INSERT INTO production_data (year,element,production_quantity) VALUES (2016,'Gadolinium',500); INSERT INTO production_data (year,element,production_quantity) VALUES (2017,'Gadolinium',550);
|
SELECT SUM(production_quantity) FROM production_data WHERE element = 'Gadolinium' AND year IN (2015, 2016);
|
What is the distribution of hotel energy consumption in London by type?
|
CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,city TEXT,type TEXT); INSERT INTO hotels (hotel_id,hotel_name,city,type) VALUES (1,'Hotel A','London','Luxury'),(2,'Hotel B','London','Budget'),(3,'Hotel C','London','Boutique'); CREATE TABLE energy_consumption (hotel_id INT,consumption FLOAT); INSERT INTO energy_consumption (hotel_id,consumption) VALUES (1,1500),(2,1200),(3,1000);
|
SELECT type, AVG(consumption) FROM hotels INNER JOIN energy_consumption ON hotels.hotel_id = energy_consumption.hotel_id WHERE city = 'London' GROUP BY type;
|
What is the total cargo handling time for each fleet?
|
CREATE TABLE fleets (fleet_id INT,fleet_name VARCHAR(50),cargo_handling_time INT); INSERT INTO fleets (fleet_id,fleet_name,cargo_handling_time) VALUES (1,'FleetA',500),(2,'FleetB',750),(3,'FleetC',600);
|
SELECT fleet_name, SUM(cargo_handling_time) FROM fleets GROUP BY fleet_name;
|
How many countries have marine protected areas deeper than 3000 meters?
|
CREATE TABLE marine_protected_areas (name TEXT,depth FLOAT,country TEXT); INSERT INTO marine_protected_areas (name,depth,country) VALUES ('Galapagos Islands',3500.0,'Ecuador'),('Socorro Island',3050.0,'Mexico'),('Mariana Trench',10994.0,'USA');
|
SELECT COUNT(DISTINCT country) FROM marine_protected_areas WHERE depth > 3000;
|
List all volunteers who have participated in programs in Africa?
|
CREATE TABLE Volunteer (VolunteerID int,VolunteerName varchar(50),Country varchar(50)); CREATE TABLE VolunteerProgram (ProgramID int,VolunteerID int,ProgramLocation varchar(50));
|
SELECT VolunteerName FROM Volunteer JOIN VolunteerProgram ON Volunteer.VolunteerID = VolunteerProgram.VolunteerID WHERE Country = 'Africa';
|
Calculate the percentage of algorithms with a complexity score under 4 in the 'AI_Safety' schema.
|
CREATE SCHEMA AI_Safety;CREATE TABLE Algorithms (algo_id INT,complexity_score INT,accuracy_score FLOAT); INSERT INTO AI_Safety.Algorithms (algo_id,complexity_score,accuracy_score) VALUES (1,6,0.95),(2,4,0.9),(3,7,0.8);
|
SELECT (COUNT(*) FILTER (WHERE complexity_score < 4)) * 100.0 / COUNT(*) FROM AI_Safety.Algorithms;
|
What is the distribution of digital assets by type, for companies based in South America?
|
CREATE TABLE AssetAllocation (AssetAllocationID INT,AssetID INT,AssetName VARCHAR(100),AllocationType VARCHAR(50),AllocationValue FLOAT); INSERT INTO AssetAllocation (AssetAllocationID,AssetID,AssetName,AllocationType,AllocationValue) VALUES (1,1,'Asset1','Security',0.7),(2,1,'Asset1','Commodity',0.3),(3,2,'Asset2','Security',0.5),(4,2,'Asset2','Currency',0.5); ALTER TABLE AssetAllocation ADD COLUMN AssetID INT;
|
SELECT AssetType, SUM(AllocationValue) as TotalValue FROM AssetAllocation INNER JOIN DigitalAsset ON AssetAllocation.AssetID = DigitalAsset.AssetID WHERE IssuerLocation = 'South America' GROUP BY AssetType;
|
Delete all climate finance projects that do not have a positive impact on climate adaptation.
|
CREATE TABLE climate_finance (project VARCHAR(50),country VARCHAR(50),amount FLOAT,impact INT,date DATE); INSERT INTO climate_finance (project,country,amount,impact,date) VALUES ('Green City','USA',5000000,1,'2020-01-01'); INSERT INTO climate_finance (project,country,amount,impact,date) VALUES ('Clean Energy','India',3000000,-1,'2020-01-01');
|
DELETE FROM climate_finance WHERE impact < 0;
|
What was the total revenue from ticket sales for the "Comedy Night" event?
|
CREATE TABLE theatre_2 (event VARCHAR(255),date DATE,revenue FLOAT); INSERT INTO theatre_2 (event,date,revenue) VALUES ('Comedy Night','2021-02-01',2500),('Comedy Night','2021-02-02',3000),('Drama Night','2021-02-01',1800);
|
SELECT SUM(revenue) FROM theatre_2 WHERE event = 'Comedy Night';
|
find the number of healthcare facilities and the number of unique ZIP codes in the HealthcareFacilities table, using an INTERSECT operator
|
CREATE TABLE HealthcareFacilities (ID INT,Name TEXT,ZipCode TEXT,City TEXT,State TEXT,Capacity INT); INSERT INTO HealthcareFacilities (ID,Name,ZipCode,City,State,Capacity) VALUES (1,'General Hospital','12345','Anytown','NY',500),(2,'Community Clinic','67890','Othertown','NY',100);
|
SELECT COUNT(*) FROM HealthcareFacilities INTERSECT SELECT COUNT(DISTINCT ZipCode) FROM HealthcareFacilities;
|
List the names, roles, and years of experience of mining engineers with the role 'Mining Engineer'.
|
CREATE TABLE mine_operators (id INT PRIMARY KEY,name VARCHAR(50),role VARCHAR(50),gender VARCHAR(10),years_of_experience INT); INSERT INTO mine_operators (id,name,role,gender,years_of_experience) VALUES (1,'John Doe','Mining Engineer','Male',7),(2,'Maria','Environmental Engineer','Female',5);
|
SELECT name, role, years_of_experience FROM mine_operators WHERE role = 'Mining Engineer';
|
What is the average CO2 emission per site?
|
CREATE TABLE site (site_id INT,site_name TEXT); CREATE TABLE co2_emission (emission_id INT,site_id INT,co2_emission_kg FLOAT); INSERT INTO site (site_id,site_name) VALUES (1,'Site A'),(2,'Site B'); INSERT INTO co2_emission (emission_id,site_id,co2_emission_kg) VALUES (1,1,500),(2,1,600),(3,2,300),(4,2,400);
|
SELECT e.site_id, AVG(e.co2_emission_kg) as avg_co2_emission FROM co2_emission e GROUP BY e.site_id;
|
What is the average length of songs in the jazz genre on the music streaming platform in Japan?
|
CREATE TABLE music_platform (id INT,song_title VARCHAR(100),genre VARCHAR(50),length FLOAT,country VARCHAR(50));
|
SELECT AVG(length) as avg_length FROM music_platform WHERE genre = 'jazz' AND country = 'Japan';
|
Which country had the highest average donation in 2021?
|
CREATE TABLE donations (donation_id INT,donation_amount DECIMAL(10,2),donation_date DATE,donor_country TEXT);
|
SELECT donor_country, AVG(donation_amount) as avg_donation FROM donations WHERE YEAR(donation_date) = 2021 GROUP BY donor_country ORDER BY avg_donation DESC LIMIT 1;
|
Total monthly revenue by region.
|
CREATE TABLE membership (id INT,user_id INT,region VARCHAR(20),monthly_fee INT);
|
SELECT region, TO_CHAR(session_date, 'Month') as month, SUM(monthly_fee) as total_revenue FROM membership GROUP BY region, month ORDER BY total_revenue DESC;
|
Which marine species are found in both the Mediterranean Sea and the Red Sea?
|
CREATE TABLE marine_species (species_id INT,name VARCHAR(50),habitat VARCHAR(50)); INSERT INTO marine_species (species_id,name,habitat) VALUES (1,'Dolphin','Mediterranean Sea'),(2,'Shark','Red Sea'),(3,'Turtle','Atlantic Ocean'),(4,'Clownfish','Pacific Ocean');
|
SELECT name FROM marine_species WHERE habitat = 'Mediterranean Sea' INTERSECT SELECT name FROM marine_species WHERE habitat = 'Red Sea';
|
How many cultural heritage preservation projects were completed in Africa in the last 5 years?
|
CREATE TABLE cultural_preservation_projects (project_id INT,project_name TEXT,country TEXT,completion_date DATE); INSERT INTO cultural_preservation_projects (project_id,project_name,country,completion_date) VALUES (1,'Ancient Ruins Conservation','Egypt','2021-12-31'),(2,'Traditional Craft Revival','Morocco','2020-12-31'),(3,'Historic Building Restoration','Kenya','2019-12-31');
|
SELECT COUNT(*) FROM cultural_preservation_projects WHERE completion_date >= DATEADD(year, -5, GETDATE());
|
What is the average age of all reggae artists?
|
CREATE TABLE Artists (ArtistID INT,Name TEXT,Age INT,Genre TEXT); INSERT INTO Artists (ArtistID,Name,Age,Genre) VALUES (1,'Bob Marley',70,'Reggae'); INSERT INTO Artists (ArtistID,Name,Age,Genre) VALUES (2,'Peter Tosh',65,'Reggae');
|
SELECT AVG(Age) FROM Artists WHERE Genre = 'Reggae';
|
Determine the number of unique inspectors for each chemical's safety inspections.
|
CREATE TABLE inspectors (id INT PRIMARY KEY,inspector VARCHAR(255)); INSERT INTO inspectors (id,inspector) VALUES (1,'Alex Lee'),(2,'Sarah Jones'); CREATE TABLE safety_inspections (id INT PRIMARY KEY,chemical_id INT,inspection_date DATE,inspector_id INT); INSERT INTO safety_inspections (id,chemical_id,inspection_date,inspector_id) VALUES (1,1,'2022-01-01',1),(2,1,'2022-02-01',2);
|
SELECT chemical_id, COUNT(DISTINCT inspector_id) AS num_inspectors, RANK() OVER (ORDER BY COUNT(DISTINCT inspector_id) DESC) AS rank FROM safety_inspections JOIN inspectors ON safety_inspections.inspector_id = inspectors.id GROUP BY chemical_id HAVING rank <= 2;
|
What is the average number of articles published per day by each publication in the last month?
|
CREATE TABLE news_articles (id INT,title VARCHAR(100),publication_date DATE,topic VARCHAR(50),publication_country VARCHAR(50)); INSERT INTO news_articles (id,title,publication_date,topic,publication_country) VALUES (1,'Climate Change: A Growing Crisis','2022-02-12','Climate Change','United States'),(2,'Political Turmoil in Europe','2022-02-13','Politics','United Kingdom');
|
SELECT publication_country, AVG(COUNT(*)) FROM news_articles WHERE publication_date >= DATEADD(month, -1, GETDATE()) GROUP BY publication_country;
|
Update the name of the 'readers' table to 'audience_demographics'
|
CREATE TABLE readers (reader_id INT PRIMARY KEY,age INT,gender VARCHAR(10),location VARCHAR(100));
|
ALTER TABLE readers RENAME TO audience_demographics;
|
What is the total word count for articles in the 'international' category?
|
CREATE TABLE news (title VARCHAR(255),author VARCHAR(255),word_count INT,category VARCHAR(255)); INSERT INTO news (title,author,word_count,category) VALUES ('Sample News','James Brown',800,'International');
|
SELECT SUM(word_count) FROM news WHERE category = 'International';
|
What is the maximum military equipment sale quantity by a defense contractor in 2021?
|
CREATE TABLE max_sales (contractor VARCHAR(20),year INT,sales INT); INSERT INTO max_sales (contractor,year,sales) VALUES ('Boeing',2021,2000),('BAE Systems',2021,1500);
|
SELECT MAX(sales) FROM max_sales WHERE year = 2021;
|
Create a table named 'immunization_coverage'
|
CREATE TABLE immunization_coverage (id INT PRIMARY KEY,country VARCHAR(50),coverage FLOAT);
|
CREATE TABLE immunization_coverage (id INT PRIMARY KEY, country VARCHAR(50), coverage FLOAT);
|
Delete an artwork
|
CREATE TABLE ArtWorks (ArtWorkID INT,Title VARCHAR(100),YearCreated INT,ArtistID INT,Medium VARCHAR(50),MuseumID INT);
|
DELETE FROM ArtWorks WHERE ArtWorkID = 2 AND Title = 'The Two Fridas';
|
What is the total sales for each restaurant in the last week?
|
CREATE TABLE restaurant_sales (restaurant VARCHAR(255),sale_date DATE,sales DECIMAL(10,2)); INSERT INTO restaurant_sales (restaurant,sale_date,sales) VALUES ('Restaurant A','2022-01-01',500.00),('Restaurant A','2022-01-02',600.00),('Restaurant B','2022-01-01',400.00),('Restaurant B','2022-01-02',450.00);
|
SELECT restaurant, SUM(sales) FROM restaurant_sales WHERE sale_date >= DATE_SUB(CURDATE(), INTERVAL 1 WEEK) GROUP BY restaurant;
|
Which public transportation systems were added in Q3 2021?
|
CREATE TABLE schema.public_transportation (system_id INT,system_name VARCHAR(50),system_type VARCHAR(50),implementation_date DATE); INSERT INTO schema.public_transportation (system_id,system_name,system_type,implementation_date) VALUES (1,'Subway','Rail','2021-04-01'),(2,'Light Rail','Rail','2021-07-01'),(3,'Bus Rapid Transit','Bus','2021-10-01');
|
SELECT system_name FROM schema.public_transportation WHERE implementation_date BETWEEN '2021-07-01' AND '2021-09-30';
|
What was the total amount of climate finance provided to African countries for renewable energy projects in 2020?
|
CREATE TABLE climate_finance (year INT,country VARCHAR(50),project_type VARCHAR(50),amount DECIMAL(10,2)); INSERT INTO climate_finance (year,country,project_type,amount) VALUES (2020,'Kenya','Solar',500000.00),(2020,'Nigeria','Wind',750000.00);
|
SELECT SUM(amount) FROM climate_finance WHERE year = 2020 AND country IN ('Kenya', 'Nigeria') AND project_type = 'Renewable Energy';
|
What is the percentage of players who prefer using mobile devices for gaming in each continent?
|
CREATE TABLE PlayerDevices (PlayerID INT,Device VARCHAR(50),Continent VARCHAR(50)); INSERT INTO PlayerDevices (PlayerID,Device,Continent) VALUES (1,'PC','Europe'),(2,'Mobile','Africa'),(3,'PC','Asia'),(4,'Console','North America'),(5,'Mobile','South America'),(6,'PC','Oceania'),(7,'Mobile','Europe'),(8,'Console','Africa'),(9,'PC','Asia'),(10,'Mobile','North America'),(11,'Console','South America'),(12,'PC','Oceania');
|
SELECT Continent, COUNT(*) as TotalPlayers, COUNT(CASE WHEN Device = 'Mobile' THEN 1 END) as MobilePlayers, (COUNT(CASE WHEN Device = 'Mobile' THEN 1 END) * 100.0 / COUNT(*)) as MobilePercentage FROM PlayerDevices GROUP BY Continent
|
Find the number of artworks created in the 'Surrealism' movement during the year 1924.
|
CREATE TABLE Artworks (id INT,creation_year INT,movement VARCHAR(20));
|
SELECT COUNT(*) FROM Artworks WHERE creation_year = 1924 AND movement = 'Surrealism';
|
Update the Department for employee 12 to 'Information Technology' in the Employee table
|
CREATE TABLE Employee (EmployeeID INT PRIMARY KEY,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50),JobTitle VARCHAR(50),LastActivity DATETIME);
|
UPDATE Employee SET Department = 'Information Technology' WHERE EmployeeID = 12;
|
Which crops in the Midwest are part of the Solanaceae family and their scientific names?
|
CREATE TABLE crops (id INT PRIMARY KEY,name VARCHAR(50),scientific_name VARCHAR(50),growth_season VARCHAR(20),family VARCHAR(25),region VARCHAR(25)); INSERT INTO crops (id,name,scientific_name,growth_season,family,region) VALUES (1,'Tomato','Solanum lycopersicum','Warm','Solanaceae','Midwest'); INSERT INTO crops (id,name,scientific_name,growth_season,family,region) VALUES (2,'Potato','Solanum tuberosum','Cool','Solanaceae','Midwest');
|
SELECT name, scientific_name FROM crops WHERE family = 'Solanaceae' AND region = 'Midwest';
|
What's the total amount of donations made by individual donors from the United States, grouped by cause?
|
CREATE TABLE donors (id INT,name VARCHAR(255),country VARCHAR(255));CREATE TABLE donations (id INT,donor_id INT,cause_id INT,amount DECIMAL(10,2));CREATE VIEW us_donors AS SELECT * FROM donors WHERE country = 'United States';
|
SELECT c.name, SUM(d.amount) FROM donations d INNER JOIN us_donors dn ON d.donor_id = dn.id GROUP BY d.cause_id, c.name;
|
Which museums exhibited artworks by artist '103'?
|
CREATE TABLE Exhibitions (exhibition_id INT,museum_name VARCHAR(255),artist_id INT,artwork_id INT); INSERT INTO Exhibitions (exhibition_id,museum_name,artist_id,artwork_id) VALUES (1,'Museum X',101,201),(2,'Museum Y',102,202),(3,'Museum Z',103,203); CREATE TABLE Artworks (artwork_id INT,artist_id INT,artwork_title VARCHAR(255)); INSERT INTO Artworks (artwork_id,artist_id,artwork_title) VALUES (201,101,'Painting 1'),(202,102,'Sculpture 1'),(203,103,'Drawing 1'),(204,103,'Drawing 2'),(205,103,'Drawing 3');
|
SELECT DISTINCT museum_name FROM Exhibitions WHERE artist_id = 103;
|
What is the total attendance for cultural events in the 'dance' category?
|
CREATE TABLE events (id INT,name VARCHAR(50),category VARCHAR(20),attendance INT); INSERT INTO events (id,name,category,attendance) VALUES (1,'Ballet','dance',200),(2,'Play','theater',150),(3,'Festival','music',300);
|
SELECT SUM(attendance) FROM events WHERE category = 'dance';
|
List the number of new volunteers per month, who have donated in the same month, in Canada during the year 2021?
|
CREATE TABLE volunteers (id INT,volunteer_name VARCHAR(50),volunteer_date DATE); INSERT INTO volunteers (id,volunteer_name,volunteer_date) VALUES (1,'James Smith','2021-02-05'),(2,'Grace Johnson','2021-04-15'),(3,'Ethan Patel','2021-01-20'),(4,'Ava Singh','2021-03-01'),(5,'Oliver White','2021-05-10'); CREATE TABLE donations (id INT,donation_amount DECIMAL(10,2),donation_date DATE,volunteer_id INT); INSERT INTO donations (id,donation_amount,donation_date,volunteer_id) VALUES (1,100.00,'2021-02-05',1),(2,75.00,'2021-04-15',2),(3,150.00,'2021-01-20',3),(4,250.00,'2021-03-01',4),(5,300.00,'2021-05-01',5);
|
SELECT MONTH(v.volunteer_date) AS month, COUNT(DISTINCT v.volunteer_name) AS new_volunteers FROM volunteers v JOIN donations d ON v.id = d.volunteer_id WHERE YEAR(v.volunteer_date) = 2021 AND MONTH(v.volunteer_date) = MONTH(d.donation_date) AND v.volunteer_country = 'Canada' GROUP BY month;
|
How many unique donors are there for each program in the first quarter of 2022?
|
CREATE TABLE programs (program_id INT,program_name VARCHAR(255)); CREATE TABLE donations (donation_id INT,donor_id INT,program_id INT,donation_date DATE); INSERT INTO programs (program_id,program_name) VALUES (1,'Education'),(2,'Health'),(3,'Environment'); INSERT INTO donations (donation_id,donor_id,program_id,donation_date) VALUES (1,101,1,'2022-01-02'),(2,102,2,'2022-02-15'),(3,101,1,'2022-03-10');
|
SELECT program_id, COUNT(DISTINCT donor_id) FROM donations JOIN programs ON donations.program_id = programs.program_id WHERE QUARTER(donation_date) = 1 GROUP BY program_id;
|
What is the average well-being score for athletes in each city?
|
CREATE TABLE teams (team_id INT,team_name VARCHAR(50),city VARCHAR(50));CREATE TABLE athletes (athlete_id INT,athlete_name VARCHAR(50),team_id INT,well_being_score INT); INSERT INTO teams (team_id,team_name,city) VALUES (1,'Atlanta Hawks','Atlanta'),(2,'Boston Celtics','Boston'); INSERT INTO athletes (athlete_id,athlete_name,team_id,well_being_score) VALUES (1,'Player1',1,8),(2,'Player2',1,9),(3,'Player3',2,7),(4,'Player4',2,8);
|
SELECT te.city, AVG(a.well_being_score) FROM teams te JOIN athletes a ON te.team_id = a.team_id GROUP BY te.city;
|
What is the minimum savings balance for clients in Pakistan?
|
CREATE TABLE clients (client_id INT,name VARCHAR(100),age INT,country VARCHAR(50),savings DECIMAL(10,2)); INSERT INTO clients (client_id,name,age,country,savings) VALUES (11,'Ahmed Khan',35,'Pakistan',3000);
|
SELECT MIN(savings) FROM clients WHERE country = 'Pakistan';
|
Calculate the total budget allocated to each department in the "Budget" table, where the department name contains 'Education'.
|
CREATE TABLE Budget (id INT,department VARCHAR(50),allocated_budget FLOAT); INSERT INTO Budget (id,department,allocated_budget) VALUES (1,'Education - Primary',1000000.0),(2,'Education - Secondary',1500000.0),(3,'Healthcare',2000000.0),(4,'Transportation',1200000.0),(5,'Education - Higher',2500000.0);
|
SELECT department, SUM(allocated_budget) as total_budget FROM Budget WHERE department LIKE '%Education%' GROUP BY department;
|
Get the maximum number of people on board a single spacecraft
|
CREATE TABLE Spacecraft (SpacecraftID INT,SpacecraftName VARCHAR(50),Manufacturer VARCHAR(50),LaunchDate DATE,NumberOfPeople INT,FuelType VARCHAR(50)); INSERT INTO Spacecraft (SpacecraftID,SpacecraftName,Manufacturer,LaunchDate,NumberOfPeople,FuelType) VALUES (1,'Soyuz','Roscosmos','2020-01-01',3,'Liquid'); INSERT INTO Spacecraft (SpacecraftID,SpacecraftName,Manufacturer,LaunchDate,NumberOfPeople,FuelType) VALUES (2,'Progress','Roscosmos','2020-02-10',2,'Liquid');
|
SELECT MAX(NumberOfPeople) FROM Spacecraft;
|
How many 'Eco-Friendly' garments were sold in 'Australia' retail stores in Q1 of 2022?
|
CREATE TABLE SalesStore (id INT PRIMARY KEY,store_name VARCHAR(50),location VARCHAR(50),garment_type VARCHAR(50),is_eco_friendly BOOLEAN,quantity INT,sale_date DATE); INSERT INTO SalesStore (id,store_name,location,garment_type,is_eco_friendly,quantity,sale_date) VALUES (1,'Store D','Australia','Eco-Friendly T-Shirt',true,30,'2022-01-15');
|
SELECT SUM(quantity) as total_quantity FROM SalesStore WHERE location = 'Australia' AND is_eco_friendly = true AND sale_date BETWEEN '2022-01-01' AND '2022-03-31';
|
What is the total revenue for each game genre in 2021?
|
CREATE TABLE Games (GameID INT,Genre VARCHAR(20),Revenue INT,ReleaseYear INT); INSERT INTO Games (GameID,Genre,Revenue,ReleaseYear) VALUES (1,'Sports',5000000,2021),(2,'RPG',7000000,2020),(3,'Strategy',6000000,2021);
|
SELECT Genre, SUM(Revenue) as TotalRevenue FROM Games WHERE ReleaseYear = 2021 GROUP BY Genre
|
How many legal precedents were set by female attorneys in the 'New York' region?
|
CREATE TABLE attorneys (id INT,name TEXT,gender TEXT,region TEXT,title TEXT); INSERT INTO attorneys (id,name,gender,region,title) VALUES (1,'Jane Doe','Female','New York','Partner'); CREATE TABLE legal_precedents (id INT,attorney_id INT,year INT); INSERT INTO legal_precedents (id,attorney_id,year) VALUES (1,1,2020);
|
SELECT COUNT(*) FROM legal_precedents JOIN attorneys ON legal_precedents.attorney_id = attorneys.id WHERE attorneys.gender = 'Female' AND attorneys.region = 'New York';
|
What is the total revenue for each menu category in a specific region?
|
CREATE TABLE menus (menu_id INT,category VARCHAR(255)); INSERT INTO menus VALUES (1,'Appetizers'); INSERT INTO menus VALUES (2,'Entrees'); INSERT INTO menus VALUES (3,'Desserts'); CREATE TABLE sales (sale_id INT,menu_id INT,quantity INT,region VARCHAR(255),price DECIMAL(10,2));
|
SELECT m.category, SUM(s.price * s.quantity) as total_revenue FROM menus m INNER JOIN sales s ON m.menu_id = s.menu_id WHERE s.region = 'North' GROUP BY m.category;
|
What is the difference in mental health scores between the first and last measurement for each student?
|
CREATE TABLE student_mental_health (student_id INT,mental_health_score INT,measurement_date DATE); INSERT INTO student_mental_health (student_id,mental_health_score,measurement_date) VALUES (1,70,'2022-01-01'),(1,75,'2022-01-02'),(2,60,'2022-01-01'),(2,65,'2022-01-02'),(3,80,'2022-01-01'),(3,85,'2022-01-02');
|
SELECT student_id, mental_health_score, measurement_date, mental_health_score - LAG(mental_health_score, 1, 0) OVER (PARTITION BY student_id ORDER BY measurement_date) as score_difference FROM student_mental_health;
|
How many visitors attended exhibitions in Paris during the first quarter?
|
CREATE TABLE ExhibitionAttendance (id INT,city VARCHAR(50),exhibition VARCHAR(50),attendance_date DATE);
|
SELECT COUNT(*) FROM ExhibitionAttendance WHERE city = 'Paris' AND attendance_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH) AND attendance_date < DATE_SUB(CURRENT_DATE, INTERVAL 2 MONTH);
|
Delete all records from the 'districts' table that have no associated schools.
|
CREATE TABLE districts (id INT,name VARCHAR(255)); INSERT INTO districts (id,name) VALUES (1,'School District 1'),(2,'School District 2'); CREATE TABLE schools (id INT,name VARCHAR(255),district_id INT); INSERT INTO schools (id,name,district_id) VALUES (1,'School 1',1),(2,'School 2',1),(3,'School 3',2),(4,'School 4',NULL);
|
DELETE FROM districts WHERE id NOT IN (SELECT district_id FROM schools);
|
How many sustainable building permits have been issued in the Northeast this year?
|
CREATE TABLE Northeast_SBP (permit_id INT,location VARCHAR(20),permit_date DATE,is_sustainable INT); INSERT INTO Northeast_SBP VALUES (1001,'ME','2022-02-15',1),(1002,'NH','2022-04-20',1),(1003,'VT','2022-06-05',0);
|
SELECT COUNT(permit_id) FROM Northeast_SBP WHERE is_sustainable = 1 AND YEAR(permit_date) = YEAR(CURRENT_DATE());
|
How many clients received financial education in Indonesia?
|
CREATE TABLE financial_education (id INT,client_id INT,country VARCHAR(50),education_type VARCHAR(50)); INSERT INTO financial_education (id,client_id,country,education_type) VALUES (1,101,'Indonesia','Financial Literacy'),(2,102,'Indonesia','Debt Management');
|
SELECT country, COUNT(*) as num_clients FROM financial_education WHERE country = 'Indonesia' GROUP BY country;
|
What is the total funding for bioprocess engineering projects in Q1 2022?
|
CREATE SCHEMA if not exists bioprocess_engineering;CREATE TABLE if not exists bioprocess_engineering.funding (id INT,period VARCHAR(50),year INT,amount FLOAT); INSERT INTO bioprocess_engineering.funding (id,period,year,amount) VALUES (1,'Q1',2022,750000.0),(2,'Q2',2022,900000.0);
|
SELECT SUM(amount) FROM bioprocess_engineering.funding WHERE period = 'Q1' AND year = 2022;
|
How many space missions has each manufacturer been involved in?
|
CREATE TABLE Astronauts (AstronautId INT,Name VARCHAR(50),Age INT,Gender VARCHAR(10)); CREATE TABLE Spacecraft (SpacecraftId INT,Name VARCHAR(50),Manufacturer VARCHAR(20)); CREATE TABLE SpaceMissions (MissionId INT,Name VARCHAR(50),SpacecraftId INT,AstronautId INT); INSERT INTO Astronauts (AstronautId,Name,Age,Gender) VALUES (1,'Mark Watney',40,'Male'),(2,'Melissa Lewis',45,'Female'),(3,'Rick Martinez',35,'Male'),(4,'Beth Johansen',30,'Female'); INSERT INTO Spacecraft (SpacecraftId,Name,Manufacturer) VALUES (1,'Hermes','NASA'),(2,'Cygnus','Orbital Sciences'),(3,'Dragon','SpaceX'),(4,'Progress','Roscosmos'); INSERT INTO SpaceMissions (MissionId,Name,SpacecraftId,AstronautId) VALUES (1,'Ares 3',1,1),(2,'Ares 3',1,2),(3,'Ares 3',3,3),(4,'Ares 3',3,4),(5,'Expedition 44',2,1),(6,'Expedition 44',2,2),(7,'Expedition 45',4,3),(8,'Expedition 45',4,4);
|
SELECT Spacecraft.Manufacturer, COUNT(DISTINCT SpaceMissions.MissionId) as MissionCount FROM Spacecraft INNER JOIN SpaceMissions ON Spacecraft.SpacecraftId = SpaceMissions.SpacecraftId GROUP BY Spacecraft.Manufacturer;
|
What is the average maintenance cost for military equipment, grouped by equipment type?
|
CREATE TABLE Equipment (id INT,name VARCHAR(100));CREATE TABLE Maintenance (id INT,equipment_id INT,cost DECIMAL(10,2)); INSERT INTO Equipment (id,name) VALUES (1,'Tank'),(2,'Fighter Jet'),(3,'Helicopter'); INSERT INTO Maintenance (id,equipment_id,cost) VALUES (1,1,5000),(2,1,6000),(3,2,8000),(4,2,9000),(5,3,12000),(6,3,11000);
|
SELECT e.name AS equipment_type, AVG(m.cost) AS avg_cost FROM Maintenance m JOIN Equipment e ON m.equipment_id = e.id GROUP BY e.name;
|
Compare military equipment maintenance costs between 'Type A' and 'Type B' aircraft in 2022
|
CREATE TABLE equipment_maintenance (equipment_type VARCHAR(50),maintenance_date DATE,maintenance_cost DECIMAL(10,2));
|
SELECT equipment_type, SUM(maintenance_cost) FROM equipment_maintenance WHERE equipment_type IN ('Type A', 'Type B') AND EXTRACT(YEAR FROM maintenance_date) = 2022 GROUP BY equipment_type;
|
Delete records of viewers from Australia.
|
CREATE TABLE Users (User_ID INT,Age INT,Gender VARCHAR(10),Country VARCHAR(50)); INSERT INTO Users (User_ID,Age,Gender,Country) VALUES (1,25,'Female','Australia');
|
DELETE FROM Users WHERE Country = 'Australia';
|
What is the total number of military equipment maintenance requests in Q1 2022?
|
CREATE TABLE MaintenanceRequests (RequestID INT,RequestDate DATE); INSERT INTO MaintenanceRequests (RequestID,RequestDate) VALUES (1,'2022-01-05'),(2,'2022-02-12'),(3,'2022-03-20'),(4,'2022-04-25'),(5,'2022-05-10');
|
SELECT COUNT(*) FROM MaintenanceRequests WHERE RequestDate BETWEEN '2022-01-01' AND '2022-03-31';
|
Calculate the total claim amount for policies issued in February
|
CREATE TABLE policies (policy_number INT,issue_date DATE); INSERT INTO policies (policy_number,issue_date) VALUES (12345,'2021-02-01'); INSERT INTO policies (policy_number,issue_date) VALUES (67890,'2021-03-01'); CREATE TABLE claims (id INT,policy_number INT,claim_amount DECIMAL(10,2)); INSERT INTO claims (id,policy_number,claim_amount) VALUES (1,12345,500.00); INSERT INTO claims (id,policy_number,claim_amount) VALUES (2,67890,1200.00);
|
SELECT SUM(claim_amount) FROM claims JOIN policies ON claims.policy_number = policies.policy_number WHERE EXTRACT(MONTH FROM issue_date) = 2;
|
What is the average runtime (in minutes) of shows by genre, excluding genres with less than 5 shows?
|
CREATE TABLE shows (id INT,title VARCHAR(100),genre VARCHAR(50),country VARCHAR(50),release_year INT,runtime INT);
|
SELECT genre, AVG(runtime) FROM shows GROUP BY genre HAVING COUNT(genre) > 4;
|
What is the average daily water consumption (in gallons) in the state of New York in July 2021?
|
CREATE TABLE states (id INT,name VARCHAR(255)); INSERT INTO states (id,name) VALUES (1,'New York'),(2,'California'); CREATE TABLE water_consumption (state_id INT,consumption INT,date DATE); INSERT INTO water_consumption (state_id,consumption,date) VALUES (1,1200,'2021-07-01'),(1,1300,'2021-07-02'),(1,1400,'2021-07-03'),(2,800,'2021-07-01'),(2,850,'2021-07-02'),(2,900,'2021-07-03');
|
SELECT AVG(consumption) as avg_daily_consumption FROM water_consumption WHERE state_id = 1 AND date BETWEEN '2021-07-01' AND '2021-07-31';
|
What is the ratio of public transportation usage to personal vehicle usage in each country?
|
CREATE TABLE countries (id INT,name VARCHAR(50)); CREATE TABLE public_transportation (id INT,country_id INT,usage INT); CREATE TABLE personal_vehicles (id INT,country_id INT,usage INT); INSERT INTO countries (id,name) VALUES (1,'United States'),(2,'Germany'),(3,'China'); INSERT INTO public_transportation (id,country_id,usage) VALUES (1,1,10000),(2,2,12000),(3,3,15000); INSERT INTO personal_vehicles (id,country_id,usage) VALUES (4,1,30000),(5,2,25000),(6,3,20000);
|
SELECT c.name, (SUM(pt.usage) / SUM(pv.usage)) AS ratio FROM countries c JOIN public_transportation pt ON c.id = pt.country_id JOIN personal_vehicles pv ON c.id = pv.country_id GROUP BY c.name;
|
What is the maximum mental health score of students in the 'Uptown' district?
|
CREATE TABLE districts (district_id INT,district_name TEXT); INSERT INTO districts (district_id,district_name) VALUES (1,'Downtown'),(2,'Uptown'),(3,'Suburbs'); CREATE TABLE students (student_id INT,student_name TEXT,district_id INT,mental_health_score INT); INSERT INTO students (student_id,student_name,district_id,mental_health_score) VALUES (1,'John Doe',1,75),(2,'Jane Smith',2,80),(3,'Alice Johnson',3,85),(4,'Bob Brown',2,90);
|
SELECT MAX(s.mental_health_score) as max_score FROM students s JOIN districts d ON s.district_id = d.district_id WHERE d.district_name = 'Uptown';
|
What is the average number of fishing vessels in the Mediterranean Sea per month in 2020?
|
CREATE TABLE fishing_vessels (id INT,location VARCHAR(50),num_vessels INT,vessel_date DATE); INSERT INTO fishing_vessels (id,location,num_vessels,vessel_date) VALUES (1,'Mediterranean Sea',15,'2020-01-01'); INSERT INTO fishing_vessels (id,location,num_vessels,vessel_date) VALUES (2,'Mediterranean Sea',12,'2020-02-14');
|
SELECT AVG(num_vessels) FROM fishing_vessels WHERE location = 'Mediterranean Sea' AND YEAR(vessel_date) = 2020 GROUP BY location, YEAR(vessel_date), MONTH(vessel_date);
|
What is the total number of military equipment sold by 'ACME Corp' to the 'Government of XYZ' for the 'M1 Abrams' tank model?
|
CREATE TABLE MilitaryEquipmentSales (seller VARCHAR(255),buyer VARCHAR(255),equipment_model VARCHAR(255),quantity INT,sale_date DATE);
|
SELECT SUM(quantity) FROM MilitaryEquipmentSales WHERE seller = 'ACME Corp' AND buyer = 'Government of XYZ' AND equipment_model = 'M1 Abrams';
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.