instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the total waste quantity generated and the total number of circular economy initiatives, for each location and material, for the fourth quarter of 2024?
CREATE TABLE WasteGeneration (Date date,Location text,Material text,Quantity integer);CREATE TABLE CircularEconomyInitiatives (Location text,Initiative text,StartDate date);
SELECT wg.Location, wg.Material, SUM(wg.Quantity) as TotalWasteQuantity, COUNT(DISTINCT cei.Initiative) as NumberOfInitiatives FROM WasteGeneration wg LEFT JOIN CircularEconomyInitiatives cei ON wg.Location = cei.Location WHERE wg.Date >= '2024-10-01' AND wg.Date < '2025-01-01' GROUP BY wg.Location, wg.Material;
What is the total number of streams for songs released in the month of June?
CREATE TABLE songs (id INT,title TEXT,release_date DATE);CREATE TABLE streams (song_id INT,count INT); INSERT INTO songs (id,title,release_date) VALUES (1,'Song 4','2015-06-01'),(2,'Song 5','2013-05-15'),(3,'Song 6','2019-06-20'); INSERT INTO streams (song_id,count) VALUES (1,100),(2,200),(3,300);
SELECT SUM(streams.count) FROM songs JOIN streams ON songs.id = streams.song_id WHERE EXTRACT(MONTH FROM songs.release_date) = 6;
Select all players over 30
CREATE TABLE PlayerDemographics (PlayerID INT PRIMARY KEY,Age INT,Gender VARCHAR(10),Location VARCHAR(50)); INSERT INTO PlayerDemographics (PlayerID,Age,Gender,Location) VALUES (1,25,'Female','New York'),(2,35,'Male','Los Angeles');
SELECT * FROM PlayerDemographics WHERE Age > 30;
What is the average CO2 emissions for the production of garments in the 'Conventional_Materials' category?
CREATE TABLE Production(garment_id INT,CO2_emissions INT); INSERT INTO Production(garment_id,CO2_emissions) VALUES (1,5),(2,3); CREATE TABLE Garments(id INT,category VARCHAR(20)); INSERT INTO Garments(id,category) VALUES (1,'Conventional_Materials'),(2,'Organic_Cotton');
SELECT AVG(Production.CO2_emissions) FROM Production JOIN Garments ON Production.garment_id = Garments.id WHERE Garments.category = 'Conventional_Materials';
What is the distribution of community health workers by race and ethnicity?
CREATE TABLE community_health_workers (id INT,name VARCHAR(50),race VARCHAR(20),ethnicity VARCHAR(20)); INSERT INTO community_health_workers (id,name,race,ethnicity) VALUES (1,'John Doe','White','Not Hispanic or Latino'),(2,'Jane Smith','Black or African American','Not Hispanic or Latino');
SELECT race, ethnicity, COUNT(*) as worker_count FROM community_health_workers GROUP BY race, ethnicity;
Update medical conditions of astronauts who are 40 years old or older.
CREATE TABLE Astronauts (id INT,name VARCHAR(50),age INT,gender VARCHAR(10)); INSERT INTO Astronauts (id,name,age,gender) VALUES (1,'Mark Watney',40,'Male'); INSERT INTO Astronauts (id,name,age,gender) VALUES (2,'Melissa Lewis',38,'Female'); INSERT INTO Astronauts (id,name,age,gender) VALUES (3,'Alex Vogel',45,'Male');
UPDATE Astronauts SET medical_condition = 'Routine Check' WHERE age >= 40;
What are the names and ranks of all personnel in the 'Army'?
CREATE TABLE MilitaryPersonnel (id INT,name VARCHAR(100),rank VARCHAR(50),service VARCHAR(50)); INSERT INTO MilitaryPersonnel (id,name,rank,service) VALUES (1,'John Doe','Colonel','Air Force'); INSERT INTO MilitaryPersonnel (id,name,rank,service) VALUES (2,'Jane Smith','Captain','Navy'); INSERT INTO MilitaryPersonnel (id,name,rank,service) VALUES (3,'Robert Johnson','General','Army');
SELECT name, rank FROM MilitaryPersonnel WHERE service = 'Army';
What is the total waste generation by material type in 2020 for New York?
CREATE TABLE waste_generation(year INT,material VARCHAR(255),quantity INT); INSERT INTO waste_generation VALUES (2020,'plastic',1200),(2020,'paper',2000),(2020,'glass',1500);
SELECT SUM(quantity) AS total_waste, material FROM waste_generation WHERE year = 2020 AND location = 'New York' GROUP BY material;
Determine the number of employees by gender and ethnicity in the environmental department
CREATE TABLE employee_demographics(dept VARCHAR(20),gender VARCHAR(10),ethnicity VARCHAR(20),num_employees INT); INSERT INTO employee_demographics VALUES ('environmental','male','hispanic',35),('environmental','male','asian',25),('environmental','male','african_american',20),('environmental','male','caucasian',50),('environmental','female','hispanic',40),('environmental','female','asian',30),('environmental','female','african_american',35),('environmental','female','caucasian',45);
SELECT gender, ethnicity, SUM(num_employees) FROM employee_demographics WHERE dept = 'environmental' GROUP BY gender, ethnicity;
Update the hours contributed by a volunteer with id '123' to '25' in the 'Volunteers' table
CREATE TABLE Volunteers (vol_id INT,hours_contributed INT,org_id INT);
UPDATE Volunteers SET hours_contributed = 25 WHERE vol_id = 123;
What is the distribution of mental health scores for teachers in each country?
CREATE TABLE teacher_mental_health (teacher_id INT,country VARCHAR(50),score INT); INSERT INTO teacher_mental_health (teacher_id,country,score) VALUES (1,'USA',75),(2,'Canada',80),(3,'Mexico',70);
SELECT country, AVG(score) as avg_score, STDDEV(score) as stddev_score FROM teacher_mental_health GROUP BY country;
Which countries have the highest yield for soybean in the 'yields' table?
CREATE TABLE yields (id INT,crop VARCHAR(255),year INT,country VARCHAR(255),yield INT); INSERT INTO yields (id,crop,year,country,yield) VALUES (1,'Corn',2020,'USA',12000),(2,'Soybean',2020,'Brazil',4000),(3,'Wheat',2020,'China',8000);
SELECT country, yield FROM yields WHERE crop = 'Soybean' ORDER BY yield DESC;
What is the total installed capacity of wind energy projects in the city of Austin, Texas, grouped by project type?
CREATE TABLE wind_energy_projects (id INT PRIMARY KEY,project_name VARCHAR(255),project_type VARCHAR(255),city VARCHAR(255),state VARCHAR(255),capacity FLOAT);
SELECT project_type, SUM(capacity) FROM wind_energy_projects WHERE city = 'Austin' AND state = 'Texas' GROUP BY project_type;
Insert a new record for each customer who made a purchase in Q2 2021.
CREATE TABLE purchases (customer_id INT,purchase_date DATE);
INSERT INTO purchases (customer_id, purchase_date) SELECT DISTINCT c.id, c.transaction_date FROM customers c JOIN purchases p ON c.id = p.customer_id WHERE c.transaction_date >= '2021-04-01' AND c.transaction_date < '2021-07-01';
Update the founder_gender for a company in the Companies table.
CREATE TABLE Companies (id INT,name TEXT,industry TEXT,country TEXT,founder_gender TEXT); INSERT INTO Companies (id,name,industry,country,founder_gender) VALUES (1,'Acme Inc','Tech','USA','Female'); INSERT INTO Companies (id,name,industry,country,founder_gender) VALUES (2,'Beta Corp','Biotech','Canada','Male');
UPDATE Companies SET founder_gender = 'Non-binary' WHERE id = 1;
What is the average recycling rate by country in Asia in 2020?
CREATE TABLE recycling_rates (country VARCHAR(20),year INT,recycling_rate FLOAT); INSERT INTO recycling_rates (country,year,recycling_rate) VALUES ('China',2020,50),('India',2020,30),('Japan',2020,70),('Indonesia',2020,25),('South Korea',2020,65);
SELECT AVG(recycling_rate) as avg_recycling_rate FROM recycling_rates WHERE year = 2020 AND country IN ('China', 'India', 'Japan', 'Indonesia', 'South Korea');
Maximum drug approval time for Cardiovascular drugs
CREATE TABLE drug_approval (approval_id INT,drug_name TEXT,disease_area TEXT,approval_date DATE); INSERT INTO drug_approval (approval_id,drug_name,disease_area,approval_date) VALUES (1,'DrugS','Cardiovascular','2015-01-01'),(2,'DrugT','Oncology','2018-01-01');
SELECT MAX(DATEDIFF('2022-01-01', approval_date)) FROM drug_approval WHERE disease_area = 'Cardiovascular';
What is the total number of members in unions that have 'Bricklayers' in their name?
CREATE TABLE union_details_2 (id INT,union_name VARCHAR(255),member_count INT); INSERT INTO union_details_2 (id,union_name,member_count) VALUES (1,'Bricklayers Local 1',7000),(2,'Bricklayers Local 2',8000),(3,'United Auto Workers',12000);
SELECT SUM(member_count) FROM union_details_2 WHERE union_name LIKE '%Bricklayers%';
Create a new view that shows the total funding and number of employees for tech companies by city
CREATE TABLE tech_company_info (id INT PRIMARY KEY,company_name VARCHAR(50),city VARCHAR(50),total_funding FLOAT,num_employees INT);
CREATE VIEW city_tech_stats AS SELECT city, SUM(total_funding) as total_funding, SUM(num_employees) as num_employees FROM tech_company_info GROUP BY city;
How many animals were adopted from the rescue center in the 'North American Wildlife' region in the last 12 months?
CREATE TABLE rescue_center_adoptions (adoption_id INT,animal_id INT,adoption_date DATE,region VARCHAR(50)); INSERT INTO rescue_center_adoptions (adoption_id,animal_id,adoption_date,region) VALUES (1,1,'2021-03-15','North American Wildlife'); INSERT INTO rescue_center_adoptions (adoption_id,animal_id,adoption_date,region) VALUES (2,2,'2021-08-20','North American Wildlife'); INSERT INTO rescue_center_adoptions (adoption_id,animal_id,adoption_date,region) VALUES (3,3,'2020-07-15','North American Wildlife');
SELECT COUNT(animal_id) FROM rescue_center_adoptions WHERE adoption_date >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH) AND region = 'North American Wildlife';
Which genetic research companies have at least two patents?
CREATE TABLE company (id INT,name VARCHAR(50),industry VARCHAR(50),location VARCHAR(50)); INSERT INTO company (id,name,industry,location) VALUES (1,'GenTech','Genetic Research','San Francisco'); INSERT INTO company (id,name,industry,location) VALUES (2,'BioEngineer','Bioprocess Engineering','Boston'); CREATE TABLE patent (id INT,title VARCHAR(100),company_id INT,filing_date DATE); INSERT INTO patent (id,title,company_id,filing_date) VALUES (1,'GenTech Patent A',1,'2020-01-01'); INSERT INTO patent (id,title,company_id,filing_date) VALUES (2,'GenTech Patent B',1,'2019-06-15'); INSERT INTO patent (id,title,company_id,filing_date) VALUES (3,'BioEngineer Patent C',2,'2018-03-20'); INSERT INTO patent (id,title,company_id,filing_date) VALUES (4,'GenTech Patent D',1,'2017-12-31');
SELECT c.name FROM company c JOIN patent p ON c.id = p.company_id GROUP BY c.name HAVING COUNT(p.id) >= 2
What is the average carbon offset by smart city initiative?
CREATE TABLE SmartCities (City VARCHAR(50),Initiative VARCHAR(50),CarbonOffset FLOAT); INSERT INTO SmartCities (City,Initiative,CarbonOffset) VALUES ('SmartCity A','PublicTransport',100.0),('SmartCity B','PublicTransport',120.0);
SELECT AVG(CarbonOffset) AS AvgCarbonOffset FROM SmartCities;
What is the average donation amount for donors from a specific zip code?
CREATE TABLE donors (id INT,name TEXT,zip_code TEXT,total_donated DECIMAL); INSERT INTO donors (id,name,zip_code,total_donated) VALUES (1,'John Doe','12345',200.00); INSERT INTO donors (id,name,zip_code,total_donated) VALUES (2,'Jane Smith','67890',300.00);
SELECT AVG(total_donated) FROM donors WHERE zip_code = '12345';
How many volunteers have registered per month in 2022?
CREATE TABLE Volunteers (VolunteerID INT,VolunteerDate DATE,VolunteerHours DECIMAL);
SELECT DATE_TRUNC('month', VolunteerDate) as Month, COUNT(*) as Volunteers FROM Volunteers WHERE VolunteerDate BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY Month;
Select records from 'creative_ai' table where 'Artist' is 'Dali' and 'Year' is after 1930
CREATE TABLE creative_ai (artwork TEXT,style TEXT,artist TEXT,year INT); INSERT INTO creative_ai (artwork,style,artist,year) VALUES ('The Persistence of Memory','Surrealism','Dali',1931),('Swans Reflecting Elephants','Surrealism','Dali',1937);
SELECT * FROM creative_ai WHERE artist = 'Dali' AND year > 1930;
Delete all records from the 'manufacturing_plants' table where the 'renewable_energy_usage' is less than 50%
CREATE TABLE manufacturing_plants (id INT,name VARCHAR(255),renewable_energy_usage DECIMAL(5,2));
DELETE FROM manufacturing_plants WHERE renewable_energy_usage < 0.50;
What was the total weight of indoor-grown cannabis sold by each dispensary in California in Q1 2022?
CREATE TABLE Dispensaries (DispensaryID INT,DispensaryName VARCHAR(50),State VARCHAR(50)); INSERT INTO Dispensaries (DispensaryID,DispensaryName,State) VALUES (1,'Buds R Us','California'); CREATE TABLE Sales (SaleID INT,DispensaryID INT,Strain VARCHAR(50),GrowType VARCHAR(50),Weight FLOAT,SaleDate DATE); INSERT INTO Sales (SaleID,DispensaryID,Strain,GrowType,Weight,SaleDate) VALUES (1,1,'Purple Haze','Indoor',10.5,'2022-01-01');
SELECT DispensaryName, SUM(Weight) AS TotalWeight FROM Sales JOIN Dispensaries ON Sales.DispensaryID = Dispensaries.DispensaryID WHERE GrowType = 'Indoor' AND SaleDate BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY DispensaryName;
Delete records of spacecraft that were decommissioned before 2000
CREATE TABLE spacecraft (name TEXT,manufacturer TEXT,year_decommission INT);
DELETE FROM spacecraft WHERE year_decommission < 2000;
How many diverse founders have received funding from each investor?
CREATE TABLE Investors (InvestorID INT,InvestorName VARCHAR(50)); CREATE TABLE Founders (FounderID INT,FounderName VARCHAR(50),Ethnicity VARCHAR(20)); CREATE TABLE Investments (InvestmentID INT,InvestorID INT,FounderID INT,InvestmentAmount DECIMAL(10,2));
SELECT I.InvestorName, COUNT(DISTINCT F.FounderID) AS DiverseFoundersFunded FROM Investments I JOIN Founders F ON I.FounderID = Founders.FounderID WHERE F.Ethnicity IN ('African', 'Hispanic', 'Asian', 'Indigenous') GROUP BY I.InvestorName;
List the top 3 countries with the most bioprocess engineering patents.
CREATE SCHEMA if not exists bioprocess;CREATE TABLE if not exists bioprocess.patents (id INT,country VARCHAR(255),patent_count INT); INSERT INTO bioprocess.patents (id,country,patent_count) VALUES (1,'USA',1200),(2,'Germany',900),(3,'China',1500),(4,'India',700),(5,'Brazil',800);
SELECT country, ROW_NUMBER() OVER (ORDER BY patent_count DESC) as rank FROM bioprocess.patents WHERE rank <= 3;
How many auto shows are there in North America and Europe?
CREATE TABLE auto_shows (id INT,name VARCHAR(50),location VARCHAR(50),year INT); INSERT INTO auto_shows VALUES (1,'Detroit Auto Show','USA',2022); INSERT INTO auto_shows VALUES (2,'New York Auto Show','USA',2022); INSERT INTO auto_shows VALUES (3,'Paris Motor Show','France',2022);
SELECT location, COUNT(*) FROM auto_shows WHERE location IN ('USA', 'France') GROUP BY location;
What was the R&D expenditure for 'CompanyX' in 2019?
CREATE TABLE rd_expenditure(company_name TEXT,expenditure INT,expenditure_year INT); INSERT INTO rd_expenditure(company_name,expenditure,expenditure_year) VALUES('CompanyX',2000000,2019);
SELECT expenditure FROM rd_expenditure WHERE company_name = 'CompanyX' AND expenditure_year = 2019;
Insert data into the port table
CREATE TABLE port (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),country VARCHAR(255),area FLOAT);
INSERT INTO port (id, name, location, country, area) VALUES (1, 'Los Angeles', 'California', 'USA', 100.25);
What are the top 5 deepest marine protected areas?
CREATE TABLE marine_protected_areas (area_name TEXT,max_depth INTEGER); INSERT INTO marine_protected_areas (area_name,max_depth) VALUES ('Sargasso Sea',7000),('Java Trench',8000),('Mariana Trench',10000),('Tonga Trench',10600),('Molucca Deep',9100);
SELECT area_name, max_depth FROM marine_protected_areas ORDER BY max_depth DESC LIMIT 5;
How many players have played each game?
CREATE TABLE Player (PlayerID INT,GameID INT,Played DATE); INSERT INTO Player (PlayerID,GameID,Played) VALUES (1,1,'2022-01-01'),(2,2,'2022-01-02'),(3,1,'2022-01-03'),(4,3,'2022-01-04');
SELECT GameID, COUNT(DISTINCT PlayerID) FROM Player GROUP BY GameID;
Update volunteer hours for 'Anna Rodriguez' to 25
CREATE TABLE Volunteers (volunteer_id INT,volunteer_name VARCHAR(50),hours INT); INSERT INTO Volunteers (volunteer_id,volunteer_name,hours) VALUES (1,'Anna Rodriguez',20);
UPDATE Volunteers SET hours = 25 WHERE volunteer_name = 'Anna Rodriguez';
How many cyber threat intelligence reports were generated each quarter in 2021 and 2022?
CREATE TABLE threat_intelligence (report_id INT,report_date DATE,report_type TEXT); INSERT INTO threat_intelligence (report_id,report_date,report_type) VALUES (1,'2021-01-01','Cyber'),(2,'2022-04-01','Terrorism');
SELECT YEAR(report_date) as Year, DATEPART(QUARTER, report_date) as Quarter, COUNT(*) as Number_of_Reports FROM threat_intelligence WHERE report_date BETWEEN '2021-01-01' AND '2022-12-31' AND report_type = 'Cyber' GROUP BY YEAR(report_date), DATEPART(QUARTER, report_date);
What is the total budget for peacekeeping operations in 'South America'?
CREATE TABLE Budget_PK (id INT,location VARCHAR(30),amount INT); INSERT INTO Budget_PK (id,location,amount) VALUES (1,'South America',7000000);
SELECT SUM(amount) FROM Budget_PK WHERE location = 'South America';
List the names and total contributions of donors who have contributed more than $1000 to a political campaign in Texas?
CREATE TABLE donors (id INT PRIMARY KEY,name TEXT,contribution FLOAT,donation_date DATE); INSERT INTO donors VALUES (1,'Alice',1500,'2022-01-01'); INSERT INTO donors VALUES (2,'Bob',750,'2022-01-02'); INSERT INTO donors VALUES (3,'Charlie',1200,'2022-01-03');
SELECT name, SUM(contribution) as total_contributions FROM donors WHERE donation_date BETWEEN '2021-01-01' AND '2022-12-31' AND state = 'Texas' GROUP BY name HAVING total_contributions > 1000;
Delete the record of the species 'Giant Pacific Octopus' from the marine_species table.
CREATE TABLE marine_species (id INT,species_name VARCHAR(255),ocean VARCHAR(255),depth INT); INSERT INTO marine_species (id,species_name,ocean,depth) VALUES (1,'Giant Pacific Octopus','Pacific',300);
DELETE FROM marine_species WHERE species_name = 'Giant Pacific Octopus';
What is the average budget of SIGINT agencies by region?
CREATE SCHEMA if not exists sigint_budget AUTHORIZATION defsec;CREATE TABLE if not exists sigint_budget.info (id INT,name VARCHAR(100),region VARCHAR(50),budget INT);INSERT INTO sigint_budget.info (id,name,region,budget) VALUES (1,'NSA','US - East',15000000000);INSERT INTO sigint_budget.info (id,name,region,budget) VALUES (2,'GCHQ','Europe - West',8000000000);INSERT INTO sigint_budget.info (id,name,region,budget) VALUES (3,'DGSE','Europe - West',5000000000);
SELECT region, AVG(budget) as avg_budget FROM sigint_budget.info WHERE name LIKE '%SIGINT%' GROUP BY region;
Find the number of employees per department in the Mining Operations department
CREATE TABLE Departments (id INT,name VARCHAR(255),department VARCHAR(255)); INSERT INTO Departments (id,name,department) VALUES (1,'John Doe','Mining Operations'),(2,'Jane Smith','Mining Operations'),(3,'Mike Johnson','IT'),(4,'Sara Clark','HR');
SELECT department, COUNT(*) as num_employees FROM Departments WHERE department = 'Mining Operations' GROUP BY department;
List the total production quantities for all chemicals
CREATE TABLE chemical_production (id INT PRIMARY KEY,chemical_id VARCHAR(10),quantity INT,country VARCHAR(50)); INSERT INTO chemical_production (id,chemical_id,quantity,country) VALUES (1,'C123',500,'USA'),(2,'C456',300,'Canada'),(3,'C123',100,'Germany'),(4,'C456',250,'USA'),(5,'C456',350,'Canada'),(6,'C123',400,'Mexico'),(7,'C789',550,'Mexico'),(8,'C123',600,'USA'),(9,'C789',250,'USA');
SELECT chemical_id, SUM(quantity) FROM chemical_production GROUP BY chemical_id;
What are the policy compliance rates for the top 3 most populous countries in the world?
CREATE TABLE policy_compliance (id INT,country VARCHAR(255),policy_name VARCHAR(255),compliance_percentage DECIMAL(5,2)); INSERT INTO policy_compliance (id,country,policy_name,compliance_percentage) VALUES (1,'China','Data Encryption',90.5),(2,'India','Access Control',85.2),(3,'USA','Incident Response',92.7);
SELECT country, AVG(compliance_percentage) AS avg_compliance_rate FROM policy_compliance WHERE country IN ('China', 'India', 'USA') GROUP BY country ORDER BY avg_compliance_rate DESC LIMIT 3;
Analyze emergency response times for different types of incidents in Sydney, comparing the response times for each suburb.
CREATE TABLE incidents (id INT,incident_type VARCHAR(255),suburb VARCHAR(255),response_time INT); INSERT INTO incidents (id,incident_type,suburb,response_time) VALUES (1,'Assault','Central',12); INSERT INTO incidents (id,incident_type,suburb,response_time) VALUES (2,'Traffic Accident','North Sydney',15); CREATE TABLE suburbs (suburb VARCHAR(255),city VARCHAR(255)); INSERT INTO suburbs (suburb,city) VALUES ('Central','Sydney'); INSERT INTO suburbs (suburb,city) VALUES ('North Sydney','Sydney');
SELECT i.incident_type, s.suburb, AVG(i.response_time) AS avg_response_time FROM incidents i INNER JOIN suburbs s ON i.suburb = s.suburb WHERE s.city = 'Sydney' GROUP BY i.incident_type, s.suburb;
Update labor productivity for Goldcorp Inc
CREATE TABLE productivity (id INT PRIMARY KEY,company VARCHAR(100),value DECIMAL(5,2));
UPDATE productivity SET value = 350 WHERE company = 'Goldcorp Inc';
How many female refugees were assisted by each organization in Africa in 2018?
CREATE TABLE refugees (id INT,organization VARCHAR(255),location VARCHAR(255),assist_date DATE,gender VARCHAR(10),age INT); INSERT INTO refugees (id,organization,location,assist_date,gender,age) VALUES (1,'UNHCR','Africa','2018-02-12','Female',34),(2,'Red Cross','Africa','2018-04-01','Male',27),(3,'Save the Children','Africa','2018-03-21','Female',19),(4,'World Vision','Africa','2018-05-05','Female',25);
SELECT organization, COUNT(*) as total_female_refugees FROM refugees WHERE location = 'Africa' AND YEAR(assist_date) = 2018 AND gender = 'Female' GROUP BY organization;
What are the names of warehouses with more than 2 pending shipments?
CREATE TABLE Warehouses (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255)); CREATE TABLE Shipments (id INT PRIMARY KEY,warehouse_id INT,status VARCHAR(255));
SELECT w.name FROM Warehouses w LEFT JOIN Shipments s ON w.id = s.warehouse_id WHERE s.status = 'pending' GROUP BY w.name HAVING COUNT(s.id) > 2;
List the wastewater treatment facilities in Spain and their capacities?
CREATE TABLE treatment_facilities_ES (name VARCHAR(50),country VARCHAR(20),capacity INT); INSERT INTO treatment_facilities_ES (name,country,capacity) VALUES ('Facility1','Spain',5000),('Facility2','Spain',7000);
SELECT name, capacity FROM treatment_facilities_ES WHERE country = 'Spain';
List all genetic research projects in Mexico using Nanopore technology?
CREATE TABLE research_projects (id INT,name TEXT,country TEXT,methods TEXT); INSERT INTO research_projects (id,name,country,methods) VALUES (1,'GenomaPlus','Mexico','Nanopore,Genome Assembly');
SELECT name FROM research_projects WHERE country = 'Mexico' AND methods LIKE '%Nanopore%';
Find the number of publications by graduate students in each department.
CREATE TABLE graduate_students (id INT,name VARCHAR(50),department VARCHAR(50)); INSERT INTO graduate_students (id,name,department) VALUES (1,'Charlie','Computer Science'); INSERT INTO graduate_students (id,name,department) VALUES (2,'Dana','Electrical Engineering'); CREATE TABLE publications (id INT,graduate_student_id INT,title VARCHAR(100),citations INT); INSERT INTO publications (id,graduate_student_id,title,citations) VALUES (1,1,'Paper1',1200); INSERT INTO publications (id,graduate_student_id,title,citations) VALUES (2,2,'Paper2',800);
SELECT gs.department, COUNT(p.id) as total_publications FROM graduate_students gs LEFT JOIN publications p ON gs.id = p.graduate_student_id GROUP BY gs.department;
What is the total number of media contents produced by Asian producers?
CREATE TABLE MediaProducers (ProducerID INT PRIMARY KEY,ProducerName VARCHAR(50),Ethnicity VARCHAR(30),YearsInMedia INT); INSERT INTO MediaProducers (ProducerID,ProducerName,Ethnicity,YearsInMedia) VALUES (1,'Producer 1','Hispanic',12),(2,'Producer 2','Asian',15);
SELECT SUM(Views) FROM MediaRepresentation WHERE ProducerID IN (SELECT ProducerID FROM MediaProducers WHERE Ethnicity = 'Asian');
List all environmental impact assessments for mining operations in the United States.
CREATE TABLE mining_operation (id INT,name VARCHAR(255),location VARCHAR(255));CREATE TABLE environmental_assessment (id INT,mining_operation_id INT,date DATE,impact VARCHAR(255)); INSERT INTO mining_operation (id,name,location) VALUES (1,'American Gold','United States'); INSERT INTO mining_operation (id,name,location) VALUES (2,'American Diamond','United States'); INSERT INTO environmental_assessment (id,mining_operation_id,date,impact) VALUES (1,1,'2020-01-01','Water pollution');
SELECT mining_operation.name, environmental_assessment.date, environmental_assessment.impact FROM mining_operation JOIN environmental_assessment ON mining_operation.id = environmental_assessment.mining_operation_id WHERE mining_operation.location = 'United States';
What is the average funding received by startups founded by individuals from North America in the blockchain sector?
CREATE TABLE startups (id INT,name TEXT,industry TEXT,founders TEXT,funding FLOAT); INSERT INTO startups (id,name,industry,founders,funding) VALUES (1,'NorthBlock','Blockchain','North America',5000000);
SELECT AVG(funding) FROM startups WHERE industry = 'Blockchain' AND founders = 'North America';
What is the total weight of packages with status 'processing' at each warehouse?
CREATE TABLE Warehouse (id INT,name VARCHAR(20),city VARCHAR(20)); INSERT INTO Warehouse (id,name,city) VALUES (1,'Seattle Warehouse','Seattle'),(2,'NYC Warehouse','NYC'),(3,'Chicago Warehouse','Chicago'); CREATE TABLE Packages (id INT,warehouse_id INT,weight FLOAT,status VARCHAR(20)); INSERT INTO Packages (id,warehouse_id,weight,status) VALUES (1,1,5.0,'shipped'),(2,1,3.0,'shipped'),(3,1,4.0,'processing'),(4,2,2.0,'processing'),(5,3,6.0,'processing');
SELECT warehouse_id, SUM(weight) FROM Packages WHERE status = 'processing' GROUP BY warehouse_id;
Delete records of meetings not held in the year 2021 from 'meetings_data' table.
CREATE TABLE meetings_data (meeting_id INT,meeting_date DATE,location VARCHAR(100),state VARCHAR(50),attendees INT);
DELETE FROM meetings_data WHERE meeting_date BETWEEN '2021-01-01' AND '2021-12-31';
What are the names of agricultural innovation projects in the Amazonas state?
CREATE TABLE agricultural_projects (id INT,name TEXT,state TEXT); INSERT INTO agricultural_projects (id,name,state) VALUES (1,'Project A','Amazonas'),(2,'Project B','Pará');
SELECT name FROM agricultural_projects WHERE state = 'Amazonas';
What is the total waste produced by the top 5 manufacturing industries in Europe?
CREATE TABLE waste (factory_id INT,industry VARCHAR(50),region VARCHAR(50),waste_generated INT);
SELECT industry, SUM(waste_generated) FROM waste w JOIN (SELECT factory_id, MIN(row_number) FROM (SELECT factory_id, ROW_NUMBER() OVER (PARTITION BY industry ORDER BY waste_generated DESC) row_number FROM waste) t GROUP BY industry) x ON w.factory_id = x.factory_id GROUP BY industry HAVING COUNT(*) <= 5 AND region = 'Europe';
Insert a new artist 'BTS' with the genre 'K-Pop' and 10000000 monthly listeners in the 'artists' table.
CREATE TABLE artists (id INT,name VARCHAR(255),genre VARCHAR(255),monthly_listeners BIGINT);
INSERT INTO artists (name, genre, monthly_listeners) VALUES ('BTS', 'K-Pop', 10000000);
Add a new military innovation to the military_innovations table.
CREATE TABLE military_innovations (id INT PRIMARY KEY,innovation_name VARCHAR(50),description TEXT,category VARCHAR(50));
INSERT INTO military_innovations (id, innovation_name, description, category) VALUES (1, 'Stealth Drone', 'A drone equipped with advanced stealth technology for covert operations.', 'Aerial Vehicles');
What was the total Shariah-compliant financing provided to small businesses in the Middle East in Q1 2021?
CREATE TABLE shariah_financing (id INT,financing_date DATE,business_type VARCHAR(255),financing_amount FLOAT);
SELECT SUM(financing_amount) FROM shariah_financing WHERE business_type = 'small business' AND financing_date BETWEEN '2021-01-01' AND '2021-03-31';
What is the total number of tickets sold for home games of the NY Knicks in the last 3 years?
CREATE TABLE IF NOT EXISTS games (id INT,team VARCHAR(50),location VARCHAR(50),date DATE); INSERT INTO games (id,team,location,date) VALUES (1,'NY Knicks','Home','2019-01-01'),(2,'NY Knicks','Away','2019-01-05'),(3,'LA Lakers','Home','2019-01-07');
SELECT SUM(tickets_sold) FROM sales JOIN games ON sales.game_id = games.id WHERE games.team = 'NY Knicks' AND games.location = 'Home' AND games.date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 YEAR);
Identify the policy trends in clean energy for countries in the European Union.
CREATE TABLE eu_clean_energy_policy (country VARCHAR(30),policy_date DATE,policy_description TEXT); INSERT INTO eu_clean_energy_policy (country,policy_date,policy_description) VALUES ('Germany','2022-01-01','Implemented a new feed-in tariff for solar energy.'),('France','2021-06-15','Expanded offshore wind energy capacity.'),('Spain','2022-04-20','Increased funding for renewable energy research and development.'),('Italy','2021-12-10','Phased out coal-fired power plants.'),('Poland','2022-02-15','Introduced a carbon tax on heavy industry.');
SELECT country, policy_description FROM eu_clean_energy_policy WHERE country IN ('Germany', 'France', 'Spain', 'Italy', 'Poland') ORDER BY policy_date DESC;
What is the minimum production cost of garments made with eco-friendly dyes?
CREATE TABLE EcoFriendlyDyeGarments (id INT,production_cost DECIMAL(5,2)); INSERT INTO EcoFriendlyDyeGarments (id,production_cost) VALUES (1,35.00),(2,32.50),(3,37.00),(4,33.00);
SELECT MIN(production_cost) FROM EcoFriendlyDyeGarments;
What is the change in water level for each lake over the last 10 years?
CREATE TABLE water_level_data (lake VARCHAR(255),year INT,water_level FLOAT);
SELECT lake, (water_level - LAG(water_level) OVER (PARTITION BY lake ORDER BY year)) AS water_level_change FROM water_level_data WHERE year BETWEEN 2013 AND 2022;
How many accessible technology patents were granted to BIPOC innovators in H2 2021?
CREATE TABLE AccessibleTechPatents (Half INT,Innovator VARCHAR(50),Patent INT); INSERT INTO AccessibleTechPatents (Half,Innovator,Patent) VALUES (1,'Alice',5),(2,'Bob',10),(3,'Charlie',15),(4,'Diana',20);
SELECT SUM(Patent) FROM AccessibleTechPatents WHERE Half = 2 AND Innovator LIKE 'BIPOC%';
What is the total number of public works projects completed in 2019 and 2020 for each district?
CREATE TABLE PublicWorks (id INT,district VARCHAR(20),year INT,completed INT); INSERT INTO PublicWorks (id,district,year,completed) VALUES (1,'Downtown',2019,1),(2,'Uptown',2020,1),(3,'Downtown',2020,1);
SELECT district, COUNT(*) as num_projects FROM PublicWorks WHERE year IN (2019, 2020) GROUP BY district;
What is the average number of days it takes to remediate a vulnerability, broken down by vulnerability type, for the last year?
CREATE TABLE vulnerabilities (id INT,vulnerability_type VARCHAR(255),remediation_date DATE,timestamp TIMESTAMP);CREATE VIEW remediation_time_by_type AS SELECT vulnerability_type,AVG(DATEDIFF('day',timestamp,remediation_date)) as avg_remediation_time FROM vulnerabilities WHERE timestamp >= NOW() - INTERVAL '1 year' GROUP BY vulnerability_type;
SELECT vulnerability_type, avg_remediation_time FROM remediation_time_by_type;
List all creative AI applications that use Python or R.
CREATE TABLE Creative_AI (id INT,application TEXT,language TEXT); INSERT INTO Creative_AI (id,application,language) VALUES (1,'Art Generation','Python'),(2,'Music Composition','R'),(3,'Story Writing','Python'),(4,'Data Visualization','R');
SELECT DISTINCT application FROM Creative_AI WHERE language IN ('Python', 'R');
What is the total amount of water saved by implementing water conservation initiatives in Mexico in 2020 and 2021?
CREATE TABLE mexico_water_savings (id INT,initiative VARCHAR(50),year INT,amount_saved FLOAT); INSERT INTO mexico_water_savings (id,initiative,year,amount_saved) VALUES (1,'Rainwater Harvesting',2020,15000),(2,'Greywater Recycling',2020,10000),(3,'Leak Detection',2020,8000),(4,'Smart Irrigation',2021,12000),(5,'Public Awareness Campaigns',2021,9000);
SELECT SUM(amount_saved) FROM mexico_water_savings WHERE year IN (2020, 2021);
What is the average water salinity for each location, grouped by location, from the 'fish_stock' and 'ocean_health' tables?
CREATE TABLE fish_stock (location VARCHAR(255),salinity FLOAT); CREATE TABLE ocean_health (location VARCHAR(255),salinity FLOAT); INSERT INTO fish_stock (location,salinity) VALUES ('Location A',32.5),('Location B',35.0); INSERT INTO ocean_health (location,salinity) VALUES ('Location A',33.0),('Location B',34.5);
SELECT f.location, AVG(f.salinity + o.salinity)/2 FROM fish_stock f INNER JOIN ocean_health o ON f.location = o.location GROUP BY f.location;
What is the total waste for each menu category?
CREATE TABLE menus (menu_category VARCHAR(50),waste_amount DECIMAL(10,2)); INSERT INTO menus (menu_category,waste_amount) VALUES ('Appetizers',1000.00),('Entrees',2500.00),('Desserts',1500.00);
SELECT menu_category, SUM(waste_amount) FROM menus GROUP BY menu_category;
What is the total number of virtual tourism experiences in India that were added to the database in the last 6 months?
CREATE TABLE virt_exp (experience_id INT,experience_name TEXT,country TEXT,added_date DATE); INSERT INTO virt_exp (experience_id,experience_name,country,added_date) VALUES (1,'Taj Mahal Virtual Tour','India','2022-01-02'); INSERT INTO virt_exp (experience_id,experience_name,country,added_date) VALUES (2,'Mumbai Street Food Virtual Tour','India','2022-03-17'); INSERT INTO virt_exp (experience_id,experience_name,country,added_date) VALUES (3,'Goa Beach Virtual Tour','India','2022-06-08');
SELECT COUNT(*) FROM virt_exp WHERE country = 'India' AND added_date >= '2022-01-01';
How many recycling facilities are there in the United States?
CREATE TABLE RecyclingFacilities (facility_id INT,country VARCHAR(50),type VARCHAR(50));
SELECT COUNT(*) FROM RecyclingFacilities WHERE country = 'United States';
What is the maximum water consumption in a single day for the industrial sector in Brazil for the month of July 2022?
CREATE TABLE daily_industrial_water_usage (region VARCHAR(20),water_consumption FLOAT,usage_date DATE); INSERT INTO daily_industrial_water_usage (region,water_consumption,usage_date) VALUES ('Brazil',8000000,'2022-07-01'),('Brazil',9000000,'2022-07-02'),('Brazil',7000000,'2022-07-03');
SELECT water_consumption FROM daily_industrial_water_usage WHERE region = 'Brazil' AND usage_date = (SELECT MAX(usage_date) FROM daily_industrial_water_usage WHERE EXTRACT(MONTH FROM usage_date) = 7 AND EXTRACT(YEAR FROM usage_date) = 2022);
What is the total number of volunteers and total volunteer hours for each program, sorted by the total number of volunteers in descending order?
CREATE TABLE Programs (ProgramID INT,ProgramName TEXT); CREATE TABLE Volunteers (VolunteerID INT,VolunteerName TEXT,ProgramID INT,VolunteerHours DECIMAL,VolunteerDate DATE); INSERT INTO Programs (ProgramID,ProgramName) VALUES (1,'Feeding the Hungry'); INSERT INTO Programs (ProgramID,ProgramName) VALUES (2,'Tutoring Kids'); INSERT INTO Volunteers (VolunteerID,VolunteerName,ProgramID,VolunteerHours,VolunteerDate) VALUES (1,'Alice',1,10.00,'2021-01-01'); INSERT INTO Volunteers (VolunteerID,VolunteerName,ProgramID,VolunteerHours,VolunteerDate) VALUES (2,'Bob',1,12.00,'2021-01-05');
SELECT Programs.ProgramName, COUNT(Volunteers.VolunteerID) as NumVolunteers, SUM(Volunteers.VolunteerHours) as TotalHours FROM Programs INNER JOIN Volunteers ON Programs.ProgramID = Volunteers.ProgramID GROUP BY Programs.ProgramName ORDER BY NumVolunteers DESC;
How many emergency calls were made in the last month, categorized by incident type?
CREATE TABLE incidents (iid INT,incident_type VARCHAR(255),call_time TIMESTAMP);
SELECT i.incident_type, COUNT(i.iid) FROM incidents i WHERE i.call_time >= DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 MONTH) GROUP BY i.incident_type;
Show the number of unique menu items for each restaurant, along with the total number of items that are sustainably sourced, grouped by city.
CREATE TABLE restaurants (restaurant_id INT,city VARCHAR(255)); CREATE TABLE menus (menu_id INT,restaurant_id INT,menu_item_id INT,is_sustainable BOOLEAN); INSERT INTO restaurants VALUES (1,'New York'); INSERT INTO restaurants VALUES (2,'Los Angeles'); INSERT INTO menus VALUES (1,1,1,true); INSERT INTO menus VALUES (2,1,2,false); INSERT INTO menus VALUES (3,2,3,true); INSERT INTO menus VALUES (4,2,4,true);
SELECT r.city, COUNT(DISTINCT m.menu_item_id) as unique_menu_items, COUNT(m.menu_item_id) as total_sustainable_items FROM restaurants r INNER JOIN menus m ON r.restaurant_id = m.restaurant_id WHERE m.is_sustainable = true GROUP BY r.city;
What is the maximum number of hospital beds in rural communities in Canada?
CREATE TABLE hospital (hospital_id INT,beds INT,location VARCHAR(10)); INSERT INTO hospital (hospital_id,beds,location) VALUES (1,200,'rural Canada');
SELECT MAX(beds) FROM hospital WHERE location = 'rural Canada';
What is the win-loss ratio of athletes in the UFC with more than 10 fights?
CREATE TABLE ufc_fights (athlete TEXT,wins INT,losses INT);
SELECT athlete, wins/(wins+losses) as win_loss_ratio FROM ufc_fights WHERE wins + losses >= 10;
How many suppliers are there in each region that supply components for ethical manufacturing?
CREATE TABLE suppliers (name TEXT,region TEXT,ethical_manufacturing BOOLEAN); INSERT INTO suppliers (name,region,ethical_manufacturing) VALUES ('Kappa Supplies','Asia-Pacific',TRUE),('Lambda Parts','Americas',FALSE);
SELECT region, COUNT(*) FROM suppliers WHERE ethical_manufacturing = TRUE GROUP BY region;
List all users who have viewed a particular advertisement, Ad123, on the social media platform, MySpace, and their corresponding demographic information.
CREATE TABLE users (user_id INT,user_name VARCHAR(255),age INT,gender VARCHAR(10),city_id INT);CREATE TABLE ad_views (view_id INT,user_id INT,ad_id VARCHAR(10)); INSERT INTO users VALUES (1,'Alice',30,'Female',1),(2,'Bob',25,'Male',2),(3,'Charlie',35,'Non-binary',3),(4,'David',40,'Male',1),(5,'Eve',28,'Female',2); INSERT INTO ad_views VALUES (1,1,'Ad123'),(2,2,'Ad123'),(3,3,'Ad123'),(4,4,'Ad123'),(5,5,'Ad123');
SELECT u.user_name, u.age, u.gender, u.city_id FROM users u INNER JOIN ad_views av ON u.user_id = av.user_id WHERE av.ad_id = 'Ad123';
What is the maximum number of community policing events held in the city of Chicago in a single month?
CREATE TABLE CommunityPolicing (id INT,city VARCHAR(20),month INT,event_count INT);
SELECT MAX(event_count) FROM CommunityPolicing WHERE city = 'Chicago';
Update the investment amount for the record with id 3 in the investment_data table to 400000.00.
CREATE TABLE investment_data (id INT,investment_amount FLOAT,strategy VARCHAR(50),region VARCHAR(50)); INSERT INTO investment_data (id,investment_amount,strategy,region) VALUES (1,250000.00,'Renewable energy','Americas'); INSERT INTO investment_data (id,investment_amount,strategy,region) VALUES (2,500000.00,'Green energy','Asia-Pacific'); INSERT INTO investment_data (id,investment_amount,strategy,region) VALUES (3,300000.00,'Sustainable agriculture','Europe');
UPDATE investment_data SET investment_amount = 400000.00 WHERE id = 3;
What is the total amount of coal, iron ore, and gold mined by month in Australia since 2015?
CREATE TABLE Resources (ResourceID INT,ResourceType VARCHAR(10),ExtractionDate DATE,Quantity INT);
SELECT EXTRACT(MONTH FROM ExtractionDate) AS Month, SUM(CASE WHEN ResourceType = 'coal' THEN Quantity ELSE 0 END) AS CoalTotal, SUM(CASE WHEN ResourceType = 'iron_ore' THEN Quantity ELSE 0 END) AS IronOreTotal, SUM(CASE WHEN ResourceType = 'gold' THEN Quantity ELSE 0 END) AS GoldTotal FROM Resources WHERE Country = 'Australia' AND EXTRACT(YEAR FROM ExtractionDate) >= 2015 GROUP BY EXTRACT(MONTH FROM ExtractionDate);
What is the total quantity of coal extracted by each company?
CREATE TABLE Companies (CompanyID INT,CompanyName VARCHAR(50)); INSERT INTO Companies (CompanyID,CompanyName) VALUES (1,'ABC Mining'),(2,'XYZ Excavations'),(3,'MNO Drilling'); CREATE TABLE Extraction (ExtractionID INT,CompanyID INT,Material VARCHAR(50),Quantity INT); INSERT INTO Extraction (ExtractionID,CompanyID,Material,Quantity) VALUES (1,1,'Coal',5000),(2,1,'Iron',3000),(3,2,'Coal',7000),(4,3,'Gold',2000),(5,1,'Coal',4000);
SELECT CompanyName, SUM(Quantity) FROM Extraction JOIN Companies ON Extraction.CompanyID = Companies.CompanyID WHERE Material = 'Coal' GROUP BY CompanyName;
What is the minimum depth at which the Greenland Shark is found?
CREATE TABLE shark_depths (shark VARCHAR(255),min_depth FLOAT); INSERT INTO shark_depths (shark,min_depth) VALUES ('Greenland Shark',2000.0),('Hammerhead Shark',100.0);
SELECT min_depth FROM shark_depths WHERE shark = 'Greenland Shark';
Show the total number of bioprocess engineering projects and their costs in Spain and Italy.
CREATE TABLE bioprocess_engineering (id INT,project_name VARCHAR(50),location VARCHAR(50),cost FLOAT); INSERT INTO bioprocess_engineering (id,project_name,location,cost) VALUES (1,'ProjectA','Spain',1200000); INSERT INTO bioprocess_engineering (id,project_name,location,cost) VALUES (2,'ProjectB','Italy',1500000); INSERT INTO bioprocess_engineering (id,project_name,location,cost) VALUES (3,'ProjectC','Italy',1800000);
SELECT location, SUM(cost) FROM bioprocess_engineering GROUP BY location HAVING location IN ('Spain', 'Italy');
Delete all players who have not participated in any esports events.
CREATE TABLE players (id INT,name VARCHAR(255),age INT,country VARCHAR(255)); CREATE TABLE esports_events (id INT,player_id INT,event_date DATE,game_type VARCHAR(255)); INSERT INTO players (id,name,age,country) VALUES (1,'John Doe',25,'USA'),(2,'Jane Doe',30,'Canada'),(3,'Jim Brown',30,'Canada'),(4,'Jamie Smith',28,'USA'); INSERT INTO esports_events (id,player_id,event_date,game_type) VALUES (1,1,'2022-01-01','FPS'),(2,1,'2022-02-01','RPG'),(3,2,'2021-12-01','FPS'),(4,2,'2022-01-01','FPS');
DELETE FROM players WHERE id NOT IN (SELECT player_id FROM esports_events);
How many policies were issued per month in the last 12 months?
CREATE TABLE Policies (PolicyID int,IssueDate date); INSERT INTO Policies (PolicyID,IssueDate) VALUES (1001,'2021-04-15'),(1002,'2021-05-03'),(1003,'2021-06-17'),(1004,'2021-07-01'),(1005,'2021-08-20'),(1006,'2021-09-05'),(1007,'2021-10-12'),(1008,'2021-11-28'),(1009,'2021-12-14'),(1010,'2022-01-03'),(1011,'2022-02-18'),(1012,'2022-03-07');
SELECT DATE_FORMAT(IssueDate, '%Y-%m') AS Month, COUNT(PolicyID) AS PoliciesIssued FROM Policies WHERE IssueDate >= DATE_SUB(CURRENT_DATE, INTERVAL 12 MONTH) GROUP BY Month
What is the average rating of hotels in the 'city_hotels' view, partitioned by hotel type and ordered by rating?
CREATE VIEW city_hotels AS SELECT * FROM hotels WHERE city = 'New York';
SELECT type, AVG(rating) OVER (PARTITION BY type ORDER BY rating) FROM city_hotels;
How many users have a membership type of 'premium' and have logged at least 20 workouts in the last month?
CREATE TABLE memberships (user_id INT,membership_type VARCHAR(10)); CREATE TABLE workouts (workout_id INT,user_id INT,workout_date DATE);
SELECT COUNT(DISTINCT user_id) FROM memberships JOIN workouts ON memberships.user_id = workouts.user_id WHERE memberships.membership_type = 'premium' AND workouts.workout_date >= DATEADD(month, -1, GETDATE()) GROUP BY memberships.user_id HAVING COUNT(workouts.workout_id) >= 20;
What is the average budget allocated for assistive technology per country, ordered by the highest average budget?
CREATE TABLE Assistive_Technology (Country VARCHAR(50),Budget NUMERIC(10,2)); INSERT INTO Assistive_Technology VALUES ('USA',500000),('Canada',450000),('Mexico',350000),('Brazil',600000),('UK',400000);
SELECT Country, AVG(Budget) as Avg_Budget FROM Assistive_Technology GROUP BY Country ORDER BY Avg_Budget DESC;
Identify the number of unique public services provided in 'CityK' and 'CityL' with a satisfaction rating of 'Satisfied' in 2021.
CREATE TABLE CityK_Satis (ID INT,Year INT,Service VARCHAR(20),Satisfaction VARCHAR(10)); INSERT INTO CityK_Satis (ID,Year,Service,Satisfaction) VALUES (1,2021,'Roads','Satisfied'),(2,2021,'Parks','Satisfied'),(3,2021,'Waste Collection','Satisfied'); CREATE TABLE CityL_Satis (ID INT,Year INT,Service VARCHAR(20),Satisfaction VARCHAR(10)); INSERT INTO CityL_Satis (ID,Year,Service,Satisfaction) VALUES (1,2021,'Transportation','Satisfied'),(2,2021,'Street Lighting','Satisfied');
SELECT COUNT(DISTINCT Service) FROM (SELECT Service FROM CityK_Satis WHERE Satisfaction = 'Satisfied' AND Year = 2021 UNION SELECT Service FROM CityL_Satis WHERE Satisfaction = 'Satisfied' AND Year = 2021);
What was the total amount donated by individual donors from the United States and Canada in Q1 2021?
CREATE TABLE donors (id INT,name TEXT,country TEXT,donation_amount DECIMAL(10,2),donation_date DATE); INSERT INTO donors (id,name,country,donation_amount,donation_date) VALUES (1,'John Doe','USA',100.00,'2021-01-05'); INSERT INTO donors (id,name,country,donation_amount,donation_date) VALUES (2,'Jane Smith','Canada',200.00,'2021-03-12');
SELECT SUM(donation_amount) FROM donors WHERE country IN ('USA', 'Canada') AND donation_date BETWEEN '2021-01-01' AND '2021-03-31';
What is the total number of tech-based social impact projects implemented in Sub-Saharan Africa and Southeast Asia?
CREATE TABLE SocialImpactProjects(region VARCHAR(255),tech_based BOOLEAN);INSERT INTO SocialImpactProjects(region,tech_based) VALUES('Sub-Saharan Africa',TRUE),('Sub-Saharan Africa',FALSE),('Southeast Asia',TRUE),('Southeast Asia',TRUE),('South America',FALSE),('Europe',TRUE);
SELECT SUM(tech_based) FROM SocialImpactProjects WHERE region IN ('Sub-Saharan Africa', 'Southeast Asia');
List all suppliers and their associated sustainable certifications in the supply_chain and sustainable_certifications tables.
CREATE TABLE supply_chain (supplier_id INT,supplier_name TEXT); CREATE TABLE sustainable_certifications (certification_id INT,supplier_id INT,certification_name TEXT);
SELECT supply_chain.supplier_name, sustainable_certifications.certification_name FROM supply_chain INNER JOIN sustainable_certifications ON supply_chain.supplier_id = sustainable_certifications.supplier_id;
List the top 3 donors by total donation amount to a disaster response in the Americas, with detailed information about the disaster and the recipient organizations?
CREATE TABLE disaster (disaster_id INT,name VARCHAR(255),location VARCHAR(255),start_date DATE); INSERT INTO disaster VALUES (1,'Hurricane Katrina','USA','2005-08-29'); INSERT INTO disaster VALUES (2,'Earthquake','Mexico','2017-09-19'); CREATE TABLE donation (donation_id INT,disaster_id INT,donor_id INT,amount DECIMAL(10,2)); INSERT INTO donation VALUES (1,1,1001,500000); INSERT INTO donation VALUES (2,2,1002,750000); CREATE TABLE donor (donor_id INT,name VARCHAR(255),type VARCHAR(255)); INSERT INTO donor VALUES (1001,'Donor1','Individual'); INSERT INTO donor VALUES (1002,'Donor2','Corporation'); CREATE TABLE organization (org_id INT,name VARCHAR(255),type VARCHAR(255)); INSERT INTO organization VALUES (1,'ORG1','NGO'); INSERT INTO organization VALUES (2,'ORG2','Government Agency');
SELECT donor.name, SUM(donation.amount) as total_donation, disaster.name, organization.name as recipient FROM donation JOIN donor ON donation.donor_id = donor.donor_id JOIN disaster ON donation.disaster_id = disaster.disaster_id JOIN organization ON disaster.org_id = organization.org_id WHERE disaster.location = 'Americas' GROUP BY donor.name ORDER BY total_donation DESC LIMIT 3;
Update innovation_trends table to reflect IoT as a trend for company_id 106
CREATE TABLE companies (id INT PRIMARY KEY,name VARCHAR(255)); CREATE TABLE innovation_trends (id INT PRIMARY KEY,company_id INT,trend VARCHAR(255));
UPDATE innovation_trends SET trend = 'IoT' WHERE company_id = 106;
Find investors who have participated in funding rounds of startups based in Africa.
CREATE TABLE investments (investor_id INT,startup_id INT,round_type TEXT,startup_region TEXT); INSERT INTO investments (investor_id,startup_id,round_type,startup_region) VALUES (1,10,'Seed','North America'),(2,10,'Series A','North America'),(3,11,'Seed','Europe'),(4,12,'Series B','Asia'),(5,13,'Seed','Africa'),(6,14,'Series C','South America'),(7,15,'Seed','Europe'),(8,15,'Series A','Europe'),(9,16,'Seed','South America'),(10,16,'Series A','South America');
SELECT DISTINCT investor_id FROM investments WHERE startup_region = 'Africa';