instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
How many job applications were received for each open position?
CREATE TABLE job_openings (id INT,position_id INT,department_id INT,open_date DATE); CREATE TABLE applications (id INT,application_date DATE,position_id INT,applicant_id INT); INSERT INTO job_openings (id,position_id,department_id,open_date) VALUES (1,101,1,'2022-01-05'),(2,102,2,'2022-01-07'),(3,103,3,'2022-01-10'); I...
SELECT positions.position_id, departments.name as department_name, COUNT(applications.id) as applications_count FROM applications JOIN job_openings as positions ON applications.position_id = positions.position_id JOIN departments ON positions.department_id = departments.id GROUP BY positions.position_id, departments.na...
What is the total number of cybersecurity incidents in Asia in the year 2020?
CREATE TABLE CybersecurityIncidents (IncidentID INT,Incident TEXT,Location TEXT,Year INT,Type TEXT); INSERT INTO CybersecurityIncidents (IncidentID,Incident,Location,Year,Type) VALUES (1,'Data Breach','Asia',2020,'Malware'); INSERT INTO CybersecurityIncidents (IncidentID,Incident,Location,Year,Type) VALUES (2,'Phishing...
SELECT SUM(IncidentID) as TotalIncidents FROM CybersecurityIncidents WHERE Location = 'Asia' AND Year = 2020;
How many streams does each song by artists from Canada have on average?
CREATE TABLE Songs (song_id INT,artist_id INT,title VARCHAR(255),streams INT); INSERT INTO Songs (song_id,artist_id,title,streams) VALUES (1,3,'Shape of You',20000000); INSERT INTO Songs (song_id,artist_id,title,streams) VALUES (2,3,'Castle on the Hill',15000000); INSERT INTO Songs (song_id,artist_id,title,streams) VAL...
SELECT AVG(Songs.streams) FROM Artists INNER JOIN Songs ON Artists.artist_id = Songs.artist_id WHERE Artists.country = 'Canada';
Find the number of projects and their total cost for each scheme, excluding the "Adaptation" scheme.
CREATE TABLE Projects (scheme VARCHAR(255),cost FLOAT); INSERT INTO Projects VALUES ('Mitigation',1000.0),('Adaptation',1500.0),('Finance',2000.0),('Communication',2500.0);
SELECT scheme, COUNT(*), SUM(cost) FROM Projects WHERE scheme != 'Adaptation' GROUP BY scheme
What is the maximum ticket price for events in the 'dance' category?
CREATE TABLE events (id INT,name TEXT,category TEXT,price DECIMAL); INSERT INTO events (id,name,category,price) VALUES (1,'Ballet','dance',100.00);
SELECT MAX(price) FROM events WHERE category = 'dance';
List all unique account numbers with a balance greater than 1000
CREATE TABLE accounts (account_number INT,customer_id INT,balance DECIMAL(10,2)); INSERT INTO accounts VALUES (1001,1,1500.00); INSERT INTO accounts VALUES (1002,1,500.00); INSERT INTO accounts VALUES (1003,2,1200.00);
SELECT DISTINCT account_number FROM accounts WHERE balance > 1000;
What is the maximum and minimum sugar content in organic products supplied by 'Green Earth'?
CREATE TABLE organic_prods (product_id INT,name VARCHAR(50),sugar_content DECIMAL(3,2),supplier VARCHAR(50)); INSERT INTO organic_prods VALUES (1,'Organic Granola',8.5,'Green Earth'); INSERT INTO organic_prods VALUES (2,'Organic Almond Milk',3.5,'Green Earth');
SELECT MAX(op.sugar_content), MIN(op.sugar_content) FROM organic_prods op WHERE op.supplier = 'Green Earth';
List the number of vulnerabilities in the technology sector for each year.
CREATE TABLE vulnerabilities (id INT,sector VARCHAR(20),year INT); INSERT INTO vulnerabilities (id,sector,year) VALUES (1,'Technology',2018),(2,'Healthcare',2019);
SELECT sector, year, COUNT(*) FROM vulnerabilities WHERE sector = 'Technology' GROUP BY year;
Find the total number of food safety violations in the 'Produce' category.
CREATE TABLE violations (id INT,category TEXT,violation_count INT); INSERT INTO violations (id,category,violation_count) VALUES (1,'Produce',12),(2,'Dairy',7),(3,'Meat',15);
SELECT SUM(violation_count) FROM violations WHERE category = 'Produce';
Find the number of vessels with a loading capacity between 30000 and 50000 tons
CREATE TABLE Vessels (VesselID INT,VesselName VARCHAR(100),LoadingCapacity FLOAT); INSERT INTO Vessels (VesselID,VesselName,LoadingCapacity) VALUES (1,'Ocean Titan',65000),(2,'Sea Giant',35000),(3,'Marine Unicorn',42000),(4,'Sky Wanderer',28000),(5,'River Princess',38000),(6,'Lake Explorer',15000);
SELECT COUNT(*) FROM Vessels WHERE LoadingCapacity BETWEEN 30000 AND 50000;
How many physicians work in the rural areas of "California" and "Oregon"?
CREATE TABLE Physicians (PhysicianID INT,Name VARCHAR(50),Specialty VARCHAR(30),Area VARCHAR(20)); INSERT INTO Physicians (PhysicianID,Name,Specialty,Area) VALUES (1,'Dr. Smith','Cardiology','Rural California'); INSERT INTO Physicians (PhysicianID,Name,Specialty,Area) VALUES (2,'Dr. Johnson','Pediatrics','Rural Oregon'...
SELECT COUNT(*) FROM Physicians WHERE Area IN ('Rural California', 'Rural Oregon');
Determine the difference in weight of each chemical produced by the same manufacturer, between the first and last quarter of the year
CREATE TABLE chemicals_quarterly (manufacturer_id INT,chemical_id INT,chemical_type VARCHAR(50),quarter INT,weight FLOAT); INSERT INTO chemicals_quarterly (manufacturer_id,chemical_id,chemical_type,quarter,weight) VALUES (1,1,'Acid',1,150.5),(1,1,'Acid',2,155.6),(1,1,'Acid',3,160.3),(1,1,'Acid',4,165.4),(2,2,'Alkali',1...
SELECT a.manufacturer_id, a.chemical_id, a.chemical_type, a.quarter, a.weight, b.weight, a.weight - b.weight as weight_difference FROM chemicals_quarterly a JOIN chemicals_quarterly b ON a.manufacturer_id = b.manufacturer_id AND a.chemical_id = b.chemical_id WHERE a.quarter = 4 AND b.quarter = 1;
How many vulnerabilities were found in each country during the last week in the 'vulnerability_assessments' table?
CREATE TABLE vulnerability_assessments (country VARCHAR(50),assessment_date DATE,num_vulnerabilities INT); INSERT INTO vulnerability_assessments (country,assessment_date,num_vulnerabilities) VALUES ('US','2022-01-01',10),('Canada','2022-01-03',5),('Mexico','2022-01-02',8);
SELECT country, COUNT(*) OVER (PARTITION BY country) AS num_vulnerabilities_last_week FROM vulnerability_assessments WHERE assessment_date >= DATEADD(day, -7, CURRENT_DATE);
What is the trend of space exploration missions over the last 15 years?
CREATE TABLE space_missions (id INT,mission_type VARCHAR(255),mission_start_date DATE,mission_end_date DATE);
SELECT YEAR(mission_start_date) as year, COUNT(*) as num_missions FROM space_missions GROUP BY year ORDER BY year;
How many clean energy policy trends were implemented in 2020?
CREATE TABLE policies (id INT,name TEXT,year INT,type TEXT);
SELECT COUNT(*) FROM policies WHERE year = 2020 AND type = 'clean energy';
What is the average number of streams and the average sales for each album?
CREATE TABLE Albums (AlbumID INT,AlbumName VARCHAR(50),ReleaseYear INT,Streams INT,Sales INT);
SELECT AlbumName, AVG(Streams) as AverageStreams, AVG(Sales) as AverageSales FROM Albums GROUP BY AlbumName;
Show all policy records for policy type 'Renters' as separate columns for policy ID, effective date, and a column for each policy type value
CREATE TABLE policy (policy_id INT,policy_type VARCHAR(20),effective_date DATE); INSERT INTO policy VALUES (1,'Renters','2018-01-01'); INSERT INTO policy VALUES (2,'Personal Auto','2020-01-01');
SELECT policy_id, effective_date, MAX(CASE WHEN policy_type = 'Renters' THEN policy_type END) AS Renters, MAX(CASE WHEN policy_type = 'Personal Auto' THEN policy_type END) AS Personal_Auto FROM policy GROUP BY policy_id, effective_date;
How many clients in the database are from Shariah-compliant financial institutions?
CREATE TABLE client (client_id INT,name TEXT,financial_institution_type TEXT); INSERT INTO client (client_id,name,financial_institution_type) VALUES (1,'John Doe','Shariah-compliant'); INSERT INTO client (client_id,name,financial_institution_type) VALUES (2,'Jane Smith','Conventional');
SELECT COUNT(*) FROM client WHERE financial_institution_type = 'Shariah-compliant';
Calculate the average dissolved oxygen levels in the Mediterranean Sea for October.
CREATE TABLE Mediterranean_Sea (dissolved_oxygen FLOAT,month DATE); INSERT INTO Mediterranean_Sea (dissolved_oxygen,month) VALUES (6.2,'2022-10-01'); INSERT INTO Mediterranean_Sea (dissolved_oxygen,month) VALUES (5.9,'2022-10-15');
SELECT AVG(dissolved_oxygen) FROM Mediterranean_Sea WHERE month = '2022-10-01';
Who are the top 3 mobile data users in the East region?
CREATE TABLE subscribers (subscriber_id INT,name VARCHAR(255),region_id INT); CREATE TABLE mobile (mobile_id INT,subscriber_id INT,data_usage INT); INSERT INTO subscribers (subscriber_id,name,region_id) VALUES (1,'John Doe',3),(2,'Jane Smith',3),(3,'Mike Johnson',3),(4,'Sara Jones',3); INSERT INTO mobile (mobile_id,sub...
SELECT s.name, SUM(m.data_usage) as total_data_usage FROM subscribers AS s JOIN mobile AS m ON s.subscriber_id = m.subscriber_id WHERE s.region_id = 3 GROUP BY s.name ORDER BY total_data_usage DESC LIMIT 3;
What is the total number of preservation efforts for each type of habitat?
CREATE TABLE PreservationEfforts(Year INT,Habitat VARCHAR(20),Efforts INT); INSERT INTO PreservationEfforts VALUES (2017,'Forest',120),(2018,'Forest',150),(2019,'Forest',170),(2017,'Wetland',80),(2018,'Wetland',90),(2019,'Wetland',110);
SELECT Habitat, SUM(Efforts) FROM PreservationEfforts GROUP BY Habitat;
What is the average area (in hectares) of agroecological farms in the 'urban_agriculture' schema, broken down by state?
CREATE SCHEMA urban_agriculture;CREATE TABLE agro_farms (id INT,state VARCHAR(50),area_ha FLOAT);
SELECT state, AVG(area_ha) FROM urban_agriculture.agro_farms GROUP BY state;
Find all transactions greater than $1000 in the East coast region.
CREATE TABLE transactions (transaction_id INT,customer_id INT,region VARCHAR(20),transaction_amount DECIMAL(10,2)); INSERT INTO transactions (transaction_id,customer_id,region,transaction_amount) VALUES (1,3,'East Coast',1500.00),(2,4,'West Coast',800.00);
SELECT * FROM transactions WHERE region = 'East Coast' AND transaction_amount > 1000.00;
Show defense contract data for the year 2019
CREATE TABLE defense_contracts (contract_id INT,agency VARCHAR(255),vendor VARCHAR(255),amount DECIMAL(10,2),year INT);
SELECT * FROM defense_contracts WHERE year = 2019;
What is the wastewater capacity in Cairo and Istanbul?
CREATE TABLE WasteWaterFacilities (Location VARCHAR(100),Capacity FLOAT); INSERT INTO WasteWaterFacilities (Location,Capacity) VALUES ('Cairo',200),('Istanbul',250);
SELECT Location, Capacity FROM WasteWaterFacilities;
Show the number of articles published per day in the last month, ordered by day with the most articles first.
CREATE TABLE articles (id INT,title TEXT,category TEXT,likes INT,created_at DATETIME); INSERT INTO articles (id,title,category,likes,created_at) VALUES (1,'Climate crisis: 12 years to save the planet','climate change',100,'2022-01-01 10:30:00');
SELECT DATE(created_at) as article_day, COUNT(*) as articles_per_day FROM articles WHERE created_at >= DATE_SUB(NOW(), INTERVAL 1 MONTH) GROUP BY article_day ORDER BY articles_per_day DESC
What is the distribution of patients by age and gender, for those who received teletherapy services?
CREATE TABLE patients (patient_id INT,age INT,gender TEXT,state TEXT); INSERT INTO patients (patient_id,age,gender,state) VALUES (1,35,'Female','California'); INSERT INTO patients (patient_id,age,gender,state) VALUES (2,45,'Male','Texas'); CREATE TABLE treatments (treatment_id INT,patient_id INT,treatment TEXT,date DAT...
SELECT patients.age, patients.gender, COUNT(patients.patient_id) FROM patients INNER JOIN treatments ON patients.patient_id = treatments.patient_id WHERE treatments.teletherapy = true GROUP BY patients.age, patients.gender;
What is the total volume of timber production for each region in the timber_production and regions tables?
CREATE TABLE timber_production (production_id INT,region_id INT,volume FLOAT); CREATE TABLE regions (region_id INT,region_name VARCHAR(50));
SELECT r.region_name, SUM(tp.volume) FROM timber_production tp JOIN regions r ON tp.region_id = r.region_id GROUP BY r.region_name;
How many movies were released by year in the Media database?
CREATE TABLE ReleaseYears (MovieTitle VARCHAR(50),ReleaseYear INT); INSERT INTO ReleaseYears (MovieTitle,ReleaseYear) VALUES ('The Godfather',1972),('The Shawshank Redemption',1994),('Pulp Fiction',1994),('The Dark Knight',2008),('Star Wars: Episode IV - A New Hope',1977);
SELECT ReleaseYear, COUNT(*) as MoviesByYear FROM ReleaseYears GROUP BY ReleaseYear;
What is the distribution of visitor ages for a specific exhibition in a given year?
CREATE TABLE ExhibitionVisitors (id INT,exhibition_name VARCHAR(30),city VARCHAR(20),year INT,visitor_age INT); INSERT INTO ExhibitionVisitors (id,exhibition_name,city,year,visitor_age) VALUES (1,'Starry Night Over the Rhone','Paris',2021,32),(2,'Starry Night Over the Rhone','Paris',2021,41),(3,'Mona Lisa','Paris',2021...
SELECT visitor_age, COUNT(*) FROM ExhibitionVisitors WHERE exhibition_name = 'Starry Night Over the Rhone' AND year = 2021 GROUP BY visitor_age;
Update the funding amount of the record with id 3 in the 'funding_records' table
CREATE TABLE funding_records (id INT,company_name VARCHAR(50),funding_amount INT);
UPDATE funding_records SET funding_amount = 2000000 WHERE id = 3;
What is the recycling rate of plastic waste in Asia in 2019?
CREATE TABLE recycling_rates (year INT,region TEXT,plastic_rate FLOAT,paper_rate FLOAT); INSERT INTO recycling_rates (year,region,plastic_rate,paper_rate) VALUES (2018,'Asia',0.35,0.60),(2018,'Europe',0.55,0.75),(2019,'Asia',NULL,NULL),(2019,'Europe',0.60,0.80);
SELECT AVG(plastic_rate) FROM recycling_rates WHERE region = 'Asia' AND year = 2019;
How many funding rounds have startups founded by immigrants gone through?
CREATE TABLE startups(id INT,name TEXT,founders TEXT,founding_year INT); INSERT INTO startups VALUES (1,'StartupA','Ahmed,Bob',2010); INSERT INTO startups VALUES (2,'StartupB','Eve',2015); INSERT INTO startups VALUES (3,'StartupC','Charlie',2018); CREATE TABLE investments(startup_id INT,round INT,funding INT); INSERT I...
SELECT startup_id, COUNT(*) as num_rounds FROM investments GROUP BY startup_id HAVING startup_id IN (SELECT id FROM startups WHERE founders LIKE '%Ahmed%' OR founders LIKE '%Charlie%');
What is the total fare collected for the route with route_id 3 on January 1, 2022?
CREATE TABLE route (route_id INT,route_name VARCHAR(255)); INSERT INTO route (route_id,route_name) VALUES (1,'Route 1'),(2,'Route 2'),(3,'Route 3'),(4,'Route 4'); CREATE TABLE fares (fare_id INT,route_id INT,fare_amount DECIMAL,fare_date DATE); INSERT INTO fares (fare_id,route_id,fare_amount,fare_date) VALUES (1,1,2.50...
SELECT SUM(fare_amount) FROM fares WHERE route_id = 3 AND fare_date = '2022-01-01';
Insert a new voyage for 'VesselC' from Port of Oakland to Port of Los Angeles on 2022-03-20.
CREATE TABLE Vessels (Id INT,Name VARCHAR(50),Type VARCHAR(50),MaxSpeed DECIMAL(5,2)); CREATE TABLE PortVoyages (Id INT,VesselId INT,DeparturePort VARCHAR(50),ArrivalPort VARCHAR(50),DepartureDate DATE);
INSERT INTO PortVoyages (VesselId, DeparturePort, ArrivalPort, DepartureDate) VALUES ((SELECT Id FROM Vessels WHERE Name = 'VesselC'), 'Oakland', 'Los Angeles', '2022-03-20');
What is the total number of natural ingredients sourced from South America?
CREATE TABLE Ingredient_Sourcing (SupplierID INT,ProductID INT,Natural BOOLEAN,Region VARCHAR(50)); INSERT INTO Ingredient_Sourcing (SupplierID,ProductID,Natural,Region) VALUES (3001,101,TRUE,'South America'),(3002,102,FALSE,'South America'),(3003,101,TRUE,'South America'),(3004,103,FALSE,'South America'),(3005,102,TRU...
SELECT SUM(Natural) as TotalNatural FROM Ingredient_Sourcing WHERE Region = 'South America';
Get the number of renewable energy projects in the RenewableEnergy schema
CREATE SCHEMA RenewableEnergy; USE RenewableEnergy; CREATE TABLE RenewableEnergyProjects (id INT,project_name VARCHAR(100),type VARCHAR(50)); INSERT INTO RenewableEnergyProjects (id,project_name,type) VALUES (1,'Hydroelectric Plant','Hydro'),(2,'Wind Farm','Wind'),(3,'Solar Farm','Solar');
SELECT COUNT(*) FROM RenewableEnergy.RenewableEnergyProjects WHERE type IN ('Hydro', 'Wind', 'Solar');
Which countries have the most circular economy initiatives in the textile industry?
CREATE TABLE circular_economy (country VARCHAR(255),initiatives INT); INSERT INTO circular_economy (country,initiatives) VALUES ('Italy',30),('Spain',25),('Germany',40),('France',35),('Sweden',20);
SELECT country, initiatives FROM circular_economy ORDER BY initiatives DESC;
What is the name and age of the oldest patient who received a COVID-19 vaccine in New York?
CREATE TABLE covid_vaccine (patient_id INT,vaccine_name VARCHAR(10),administered_date DATE,patient_age INT); INSERT INTO covid_vaccine (patient_id,vaccine_name,administered_date,patient_age) VALUES (1,'Moderna','2021-01-01',80);
SELECT vaccine_name, patient_age FROM covid_vaccine WHERE patient_age = (SELECT MAX(patient_age) FROM covid_vaccine WHERE state = 'NY');
What is the number of marine protected areas in the Atlantic Ocean?
CREATE TABLE marine_protected_areas (name TEXT,avg_depth REAL,ocean TEXT); INSERT INTO marine_protected_areas (name,avg_depth,ocean) VALUES ('Bermuda Atlantic National Marine Sanctuary',182.9,'Atlantic'),('Saba National Marine Park',20.0,'Atlantic'),('St. Eustatius National Marine Park',30.0,'Atlantic');
SELECT COUNT(*) FROM marine_protected_areas WHERE ocean = 'Atlantic';
What is the number of mental health parity violations by region in the past year?
CREATE TABLE mental_health_parity (violation_id INT,violation_date DATE,region VARCHAR(255)); INSERT INTO mental_health_parity (violation_id,violation_date,region) VALUES (1,'2021-01-01','Northeast'),(2,'2021-02-01','Southeast'),(3,'2021-03-01','Northeast');
SELECT region, COUNT(violation_id) FROM mental_health_parity WHERE violation_date >= DATEADD(year, -1, GETDATE()) GROUP BY region;
How many community policing events were held in the Jackson Heights neighborhood in 2020?
CREATE TABLE neighborhoods (id INT,name TEXT); INSERT INTO neighborhoods (id,name) VALUES (1,'Jackson Heights'),(2,'Queensbridge'),(3,'Flushing'); CREATE TABLE community_policing (id INT,neighborhood_id INT,events INT); INSERT INTO community_policing (id,neighborhood_id,events) VALUES (1,1,12),(2,1,15),(3,1,10),(4,2,8)...
SELECT COUNT(*) FROM community_policing WHERE neighborhood_id = 1 AND YEAR(event_date) = 2020;
How many cybersecurity incidents were reported in 2018 and 2019?
CREATE TABLE cybersecurity_incidents(year INT,incidents INT); INSERT INTO cybersecurity_incidents(year,incidents) VALUES(2017,5000),(2018,7000),(2019,8000);
SELECT SUM(incidents) FROM cybersecurity_incidents WHERE year IN (2018, 2019);
What is the average cost of construction materials for each type of public works project?
CREATE TABLE public_works_projects (id INT,project_type VARCHAR(255),construction_material VARCHAR(255),cost FLOAT); INSERT INTO public_works_projects (id,project_type,construction_material,cost) VALUES (1,'Bridge','Steel',150000.00),(2,'Road','Asphalt',50000.00),(3,'Building','Concrete',200000.00);
SELECT project_type, AVG(cost) as avg_cost FROM public_works_projects GROUP BY project_type;
How many social impact investments were made in 'Africa' in 2020?
CREATE TABLE investments (id INT,location VARCHAR(50),investment_year INT,investment_type VARCHAR(20)); INSERT INTO investments (id,location,investment_year,investment_type) VALUES (1,'Africa',2020,'social impact'),(2,'Europe',2019,'social impact'),(3,'Africa',2020,'traditional'),(4,'North America',2021,'social impact'...
SELECT COUNT(*) FROM investments WHERE location = 'Africa' AND investment_year = 2020 AND investment_type = 'social impact';
How many public transportation trips were taken in each city in the last week?
CREATE TABLE city_transport (trip_id INT,city_name VARCHAR(50),trip_date DATE); INSERT INTO city_transport VALUES (1,'CityA','2022-03-01'),(2,'CityB','2022-03-03'),(3,'CityA','2022-03-05'),(4,'CityC','2022-03-07'),(5,'CityB','2022-03-09');
SELECT city_name, COUNT(*) as num_trips FROM city_transport WHERE trip_date >= DATEADD(day, -7, GETDATE()) GROUP BY city_name;
What is the average number of streams for jazz songs released before 2010?
CREATE TABLE songs (song_id INT,genre VARCHAR(20),release_year INT,streams INT); INSERT INTO songs (song_id,genre,release_year,streams) VALUES (1,'jazz',2000,1100); INSERT INTO songs (song_id,genre,release_year,streams) VALUES (2,'jazz',2005,1200); INSERT INTO songs (song_id,genre,release_year,streams) VALUES (3,'jazz'...
SELECT AVG(streams) FROM songs WHERE genre = 'jazz' AND release_year < 2010;
Update the value of art pieces by artist 'Ojo' by 10%
CREATE TABLE ArtPieces (id INT,title VARCHAR(50),galleryId INT,year INT,value INT,artistId INT); INSERT INTO ArtPieces (id,title,galleryId,year,value,artistId) VALUES (1,'Piece 1',1,2000,10000,1),(2,'Piece 2',1,2010,15000,1),(3,'Piece 3',2,2020,20000,2),(4,'Piece 4',3,1990,5000,1),(5,'Piece 5',NULL,1874,25000,3);
UPDATE ArtPieces SET value = value * 1.1 WHERE artistId = 1;
What is the average severity score of vulnerabilities detected in the last month in the financial sector?
CREATE TABLE vulnerabilities (id INT,sector VARCHAR(255),severity FLOAT,detection_date DATE); INSERT INTO vulnerabilities (id,sector,severity,detection_date) VALUES (1,'financial',7.5,'2022-01-01'); INSERT INTO vulnerabilities (id,sector,severity,detection_date) VALUES (2,'financial',8.2,'2022-01-15');
SELECT AVG(severity) as avg_severity FROM vulnerabilities WHERE detection_date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH) AND sector = 'financial';
What is the average impact score for investments made by Canadian investors in education?
CREATE TABLE investor (investor_id INT,name VARCHAR(255),country VARCHAR(255)); INSERT INTO investor (investor_id,name,country) VALUES (1,'Acme Corp','Canada'); CREATE TABLE investment (investment_id INT,investor_id INT,strategy VARCHAR(255),impact_score FLOAT);
SELECT AVG(impact_score) FROM investment JOIN investor ON investment.investor_id = investor.investor_id WHERE investor.country = 'Canada' AND strategy LIKE '%Education%';
What is the total number of military personnel in the AirForce and Marines?
CREATE TABLE MilitaryPersonnel (branch TEXT,num_personnel INTEGER); INSERT INTO MilitaryPersonnel (branch,num_personnel) VALUES ('Army',500000),('Navy',350000),('AirForce',300000),('Marines',200000);
SELECT SUM(num_personnel) FROM MilitaryPersonnel WHERE branch IN ('AirForce', 'Marines');
Identify the number of certified green accommodations in Spain.
CREATE TABLE Accommodations (accommodation_id INT,accommodation_name VARCHAR(50),country VARCHAR(50),is_certified_green BOOLEAN); INSERT INTO Accommodations (accommodation_id,accommodation_name,country,is_certified_green) VALUES (1,'GreenVilla Barcelona','Spain',true),(2,'BlueResort Madrid','Spain',false);
SELECT COUNT(*) FROM Accommodations WHERE country = 'Spain' AND is_certified_green = true;
Update the attendance of a museum by name in 2019
CREATE TABLE Museums (Name VARCHAR(50),Attendance INT,Year INT); INSERT INTO Museums (Name,Attendance,Year)
UPDATE Museums SET Attendance = 9000 WHERE Name = 'Metropolitan Museum' AND Year = 2019
Which organizations in the technology for social good domain have a Twitter presence?
CREATE TABLE organizations (id INT,name TEXT,domain TEXT,twitter TEXT); INSERT INTO organizations (id,name,domain,twitter) VALUES (1,'GreenTech','technology for social good','greentech_org');
SELECT name FROM organizations WHERE domain = 'technology for social good' AND twitter IS NOT NULL;
How many autonomous driving research studies have been conducted in Japan since 2020?
CREATE TABLE AutonomousDrivingResearch (StudyID INT,StudyName TEXT,Location TEXT,Year INT);
SELECT COUNT(*) FROM AutonomousDrivingResearch WHERE Location = 'Japan' AND Year >= 2020;
Display reverse logistics metrics for returns to the state of Texas.
CREATE TABLE Returns (return_id INT,shipment_id INT,return_state VARCHAR(50)); INSERT INTO Returns (return_id,shipment_id,return_state) VALUES (1,1,'Texas'),(2,2,'California'),(3,3,'Texas');
SELECT r.shipment_id, r.return_state, f.item_name FROM Returns r JOIN FreightForwarding f ON r.shipment_id = f.shipment_id WHERE r.return_state = 'Texas';
Update the production cost of 'Tencel' material in Asia to $3.25 per unit.
CREATE TABLE material_costs (material_id INT,material_name VARCHAR(50),region VARCHAR(50),production_cost DECIMAL(10,2)); INSERT INTO material_costs (material_id,material_name,region,production_cost) VALUES (1,'Bamboo','Asia',2.50),(2,'Tencel','Asia',0.00),(3,'Linen','Asia',3.50);
UPDATE material_costs SET production_cost = 3.25 WHERE material_name = 'Tencel' AND region = 'Asia';
Delete all artists who are not associated with any artwork.
CREATE TABLE Artists (id INT,name VARCHAR(255),gender VARCHAR(255),period VARCHAR(255)); CREATE TABLE Artworks (id INT,title VARCHAR(255),artist INT,period VARCHAR(255),price FLOAT); INSERT INTO Artists (id,name,gender,period) VALUES (5,'Edvard Munch','Male','Expressionism'); INSERT INTO Artworks (id,title,artist,perio...
DELETE FROM Artists WHERE id NOT IN (SELECT artist FROM Artworks);
What is the average water consumption per household in the city of Oakland?
CREATE TABLE households (id INT,city VARCHAR(20),water_consumption FLOAT);
SELECT AVG(water_consumption) FROM households WHERE city = 'Oakland';
Delete a client's case information
CREATE TABLE cases (id INT,client_id INT,case_type VARCHAR(50),opened_date DATE,closed_date DATE); INSERT INTO cases (id,client_id,case_type,opened_date,closed_date) VALUES (1,1,'Civil','2020-01-01','2020-03-01'); INSERT INTO cases (id,client_id,case_type,opened_date,closed_date) VALUES (2,2,'Criminal','2021-02-12','20...
DELETE FROM cases WHERE id = 1;
What is the maximum number of criminal cases handled by a judge in a year?
CREATE TABLE judge (name VARCHAR(255),court_id INT,cases_handled INT); CREATE TABLE court (id INT,location VARCHAR(255)); INSERT INTO judge (name,court_id,cases_handled) VALUES ('Judge A',1,500),('Judge B',1,600),('Judge C',2,700),('Judge D',2,800),('Judge E',3,900); INSERT INTO court (id,location) VALUES (1,'New York'...
SELECT court_id, MAX(cases_handled) FROM judge GROUP BY court_id;
What is the percentage of students who have participated in open pedagogy activities?
CREATE TABLE students (student_id INT,participated_in_open_pedagogy BOOLEAN); INSERT INTO students (student_id,participated_in_open_pedagogy) VALUES (1,TRUE),(2,FALSE),(3,TRUE),(4,TRUE),(5,FALSE);
SELECT (COUNT(student_id) * 100.0 / (SELECT COUNT(*) FROM students)) AS percentage FROM students WHERE participated_in_open_pedagogy = TRUE;
What are the distinct resources for mines with reserves greater than 15000?
CREATE TABLE geological_survey (id INT,mine_id INT,resource VARCHAR(50),reserves FLOAT); INSERT INTO geological_survey (id,mine_id,resource,reserves) VALUES (7,3,'Gold',16000); INSERT INTO geological_survey (id,mine_id,resource,reserves) VALUES (8,4,'Copper',20000);
SELECT DISTINCT g.resource FROM geological_survey g WHERE g.reserves > 15000;
How many sustainable material types does each brand use?
CREATE TABLE brands (brand_id INT,name TEXT,sustainable_material TEXT); INSERT INTO brands (brand_id,name,sustainable_material) VALUES (1,'SustainaCloth','organic cotton'); INSERT INTO brands (brand_id,name,sustainable_material) VALUES (2,'EcoFabrics','recycled polyester,organic cotton');
SELECT name, COUNT(sustainable_material) OVER (PARTITION BY name) FROM brands;
How many organizations work on social good in each continent?
CREATE TABLE social_good (organization_name VARCHAR(100),continent VARCHAR(50)); INSERT INTO social_good (organization_name,continent) VALUES ('Code for Africa','Africa'),('DataKind UK','Europe'),('Data 4 Democracy','Americas');
SELECT continent, COUNT(organization_name) FROM social_good GROUP BY continent;
What is the maximum ocean acidity value in the last 5 years?
CREATE TABLE ocean_acidity (year INT,acidity FLOAT); INSERT INTO ocean_acidity (year,acidity) VALUES (2016,8.2),(2017,8.3),(2018,8.4),(2019,8.3),(2020,8.4),(2021,8.5),(2022,8.6);
SELECT MAX(acidity) FROM ocean_acidity WHERE year BETWEEN (YEAR(CURRENT_DATE) - 5) AND YEAR(CURRENT_DATE);
How many marine protected areas are located in the Atlantic Ocean?
CREATE TABLE marine_protected_areas (area_name TEXT,ocean_location TEXT); INSERT INTO marine_protected_areas (area_name,ocean_location) VALUES ('Bermuda Park','Atlantic Ocean'),('Azores Nature Reserve','Atlantic Ocean'),('Saba National Marine Park','Atlantic Ocean');
SELECT COUNT(*) FROM marine_protected_areas WHERE ocean_location = 'Atlantic Ocean';
List the number of unique research grants awarded to each researcher in the Business division, ordered by the number of grants, pivoted by researcher gender.
CREATE TABLE grant (id INT,researcher VARCHAR(50),gender VARCHAR(10),division VARCHAR(30),amount FLOAT,date DATE); INSERT INTO grant (id,researcher,gender,division,amount,date) VALUES (1,'Xavier','Male','Business',50000.00,'2020-03-01'),(2,'Yara','Female','Business',50000.00,'2019-06-15');
SELECT gender, researcher, COUNT(DISTINCT id) as num_grants FROM grant WHERE division = 'Business' GROUP BY gender, researcher ORDER BY num_grants DESC;
What is the number of tourists visiting Italy and Spain, respectively, in the top 5 most visited countries in Europe?
CREATE TABLE tourism_stats (visitor_country VARCHAR(255),visit_count INT,continent VARCHAR(255)); INSERT INTO tourism_stats (visitor_country,visit_count,continent) VALUES ('Italy',1500,'Europe'),('Spain',1800,'Europe');
SELECT visitor_country, visit_count FROM (SELECT visitor_country, visit_count, ROW_NUMBER() OVER (PARTITION BY continent ORDER BY visit_count DESC) as rn FROM tourism_stats WHERE continent = 'Europe') t WHERE rn <= 5;
How many total attendees were there for outdoor events?
CREATE TABLE attendees (id INT,event_id INT,no_attendees INT); CREATE TABLE events (id INT,name VARCHAR(255),category VARCHAR(255),location VARCHAR(255),date DATE);
SELECT SUM(a.no_attendees) FROM attendees a INNER JOIN events e ON a.event_id = e.id WHERE e.location LIKE '%outdoor%';
List the top 3 wells with highest oil production in the Bakken Formation.
CREATE TABLE bakken_formation_oil_production (well VARCHAR(255),year INT,production FLOAT);
SELECT well, production FROM bakken_formation_oil_production WHERE year = 2021 ORDER BY production DESC LIMIT 3;
What is the total quantity of 'Organic Linen' textile sourced from 'Europe'?
CREATE TABLE europe_textile (id INT,material VARCHAR(30),quantity INT);INSERT INTO europe_textile (id,material,quantity) VALUES (1,'Organic Linen',2000),(2,'Tencel',3000),(3,'Organic Linen',1500);
SELECT SUM(quantity) FROM europe_textile WHERE material = 'Organic Linen';
How many articles were published by 'InvestigativeReports' team members in the last month, and what are their names?
CREATE TABLE TeamMembers (id INT,name VARCHAR(30),role VARCHAR(20)); CREATE TABLE InvestigativeReports (id INT,article_title VARCHAR(50),pub_date DATE,author_id INT);
SELECT COUNT(ir.id) as articles, tm.name as author FROM InvestigativeReports ir JOIN TeamMembers tm ON ir.author_id = tm.id WHERE ir.pub_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) AND tm.role = 'InvestigativeReporter' GROUP BY tm.name;
How many policies of each type and coverage level does the company offer?
CREATE TABLE policies (id INT,policy_type VARCHAR(20),coverage_level INT,price FLOAT); INSERT INTO policies (id,policy_type,coverage_level,price) VALUES (1,'Comprehensive',1,900.00),(2,'Third-Party',1,600.00),(3,'Comprehensive',2,1100.00),(4,'Third-Party',2,700.00),(5,'Comprehensive',3,1200.00),(6,'Third-Party',3,1000....
SELECT policy_type, coverage_level, COUNT(*) FROM policies GROUP BY policy_type, coverage_level;
How many aircraft models were produced per month for the last two years?
CREATE TABLE AircraftProduction (id INT,model VARCHAR(255),production_date DATE); INSERT INTO AircraftProduction (id,model,production_date) VALUES (1,'F-15','2019-12-12'),(2,'F-16','2020-04-05'),(3,'F-35','2021-02-20'),(4,'F-22','2021-04-15'),(5,'F-18','2021-01-27');
SELECT DATEPART(YEAR, production_date) AS year, DATEPART(MONTH, production_date) AS month, COUNT(DISTINCT model) AS aircraft_models_produced FROM AircraftProduction WHERE production_date >= DATEADD(YEAR, -2, GETDATE()) GROUP BY DATEPART(YEAR, production_date), DATEPART(MONTH, production_date);
Show revenue for restaurants located in 'California' and 'New York' from the 'Revenue' table.
CREATE TABLE Revenue (restaurant VARCHAR(255),state VARCHAR(255),revenue DECIMAL(10,2)); INSERT INTO Revenue (restaurant,state,revenue) VALUES ('Bistro Veggie','California',35000),('Pizza House','New York',50000),('Vegan Delight','California',40000);
SELECT revenue FROM Revenue WHERE state IN ('California', 'New York');
What is the average time taken for each type of construction permit to be approved in each region?
CREATE TABLE permit_approval_times (approval_time_id INT,permit_id INT,region_name VARCHAR(50),approval_duration INT); INSERT INTO permit_approval_times (approval_time_id,permit_id,region_name,approval_duration) VALUES (1,1,'Northeast',30);
SELECT par.region_name, par.permit_id, AVG(par.approval_duration) as avg_approval_duration FROM permit_approval_times par GROUP BY par.region_name, par.permit_id;
How many animals in the 'endangered' category had their habitats expanded in '2021' and '2022'?
CREATE TABLE animal_population(animal_id INT,animal_name VARCHAR(50),category VARCHAR(20),year INT,habitat_size INT);INSERT INTO animal_population VALUES (1,'Giant Panda','Endangered',2021,5),(2,'Polar Bear','Endangered',2022,7);CREATE TABLE habitat_preservation(animal_id INT,expansion_year INT,expansion_size INT);INSE...
SELECT COUNT(*) FROM (SELECT ap.animal_id FROM animal_population ap JOIN habitat_preservation hp ON ap.animal_id = hp.animal_id WHERE ap.category = 'Endangered' AND hp.expansion_year BETWEEN 2021 AND 2022 GROUP BY ap.animal_id HAVING SUM(hp.expansion_size) > 0);
List the names, roles, and years of experience of all male mining engineers.
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','Mining Engineer','Female',5);
SELECT name, role, years_of_experience FROM mine_operators WHERE gender = 'Male';
What is the total revenue generated from ticket sales for each team?
CREATE TABLE teams (team_id INT,team_name VARCHAR(50)); INSERT INTO teams (team_id,team_name) VALUES (1,'TeamA'),(2,'TeamB'); CREATE TABLE ticket_sales (team_id INT,sale_date DATE,revenue INT); INSERT INTO ticket_sales (team_id,sale_date,revenue) VALUES (1,'2021-01-01',5000),(1,'2021-01-02',6000),(2,'2021-01-01',7000),...
SELECT t.team_name, SUM(ts.revenue) as total_revenue FROM teams t JOIN ticket_sales ts ON t.team_id = ts.team_id GROUP BY t.team_name;
List the number of vessels in each table
CREATE TABLE IF NOT EXISTS cargo (id INT PRIMARY KEY,vessel_name VARCHAR(255),average_speed DECIMAL(5,2)); CREATE TABLE IF NOT EXISTS vessel_safety (id INT PRIMARY KEY,vessel_name VARCHAR(255),safety_inspection_date DATE);
SELECT 'cargo', COUNT(*) FROM cargo UNION ALL SELECT 'vessel_safety', COUNT(*) FROM vessel_safety;
What are the top 3 most preferred cosmetic products among consumers in Japan that are not certified as cruelty-free?
CREATE TABLE japan_cosmetics_preferences (id INT,consumer_id INT,product_id INT,preference_score INT); INSERT INTO japan_cosmetics_preferences (id,consumer_id,product_id,preference_score) VALUES (1,1,1,5);
SELECT p.name, cp.preference_score FROM japan_cosmetics_preferences cp RIGHT JOIN products p ON cp.product_id = p.id WHERE p.is_cruelty_free = false GROUP BY cp.product_id ORDER BY cp.preference_score DESC LIMIT 3;
What is the minimum 'shared_cost' in the 'co_ownership_diversity' table?
CREATE TABLE co_ownership_diversity (id INT,owner VARCHAR(20),shared_cost INT); INSERT INTO co_ownership_diversity (id,owner,shared_cost) VALUES (1,'Jamal',55000),(2,'Leila',48000),(3,'Steve',62000);
SELECT MIN(shared_cost) FROM co_ownership_diversity;
Delete records in the "energy_storage" table where the "country" is 'US'
CREATE TABLE energy_storage (id INT PRIMARY KEY,technology VARCHAR(50),capacity_mwh INT,country VARCHAR(50)); INSERT INTO energy_storage (id,technology,capacity_mwh,country) VALUES (1,'Lithium Ion',500,'US'),(2,'Flow',400,'UK'),(3,'Flywheel',300,'CA');
DELETE FROM energy_storage WHERE country = 'US';
What is the minimum defense diplomacy meeting duration for India?
CREATE TABLE diplomacy_meetings (country VARCHAR(50),duration INTEGER); INSERT INTO diplomacy_meetings (country,duration) VALUES ('India',120),('China',90),('Russia',180),('Brazil',150),('South Africa',135);
SELECT MIN(duration) FROM diplomacy_meetings WHERE country = 'India';
How many farmers are growing each crop type in the past month?
CREATE TABLE farmer (id INTEGER,name TEXT);CREATE TABLE farmland (id INTEGER,farmer_id INTEGER,type TEXT,start_date DATE,end_date DATE);
SELECT f.name as farmer, fl.type as crop, COUNT(*) as num_farmers FROM farmer f INNER JOIN farmland fl ON f.id = fl.farmer_id WHERE fl.start_date <= DATEADD(month, -1, CURRENT_DATE) AND fl.end_date >= DATEADD(month, -1, CURRENT_DATE) GROUP BY f.name, fl.type;
What are the names and artists of all artworks created before 1800?
CREATE TABLE Artworks (ArtworkID INT,Name VARCHAR(100),Artist VARCHAR(100),Year INT);
SELECT Artworks.Name, Artworks.Artist FROM Artworks WHERE Artworks.Year < 1800;
How many articles were published in each month of the year 2020 in the news table?
CREATE TABLE news (id INT PRIMARY KEY,title VARCHAR(100),publish_date DATE); INSERT INTO news (id,title,publish_date) VALUES (1,'Article 1','2020-01-01'),(2,'Article 2','2020-02-14'),(3,'Article 3','2020-03-20');
SELECT EXTRACT(MONTH FROM publish_date) AS month, COUNT(*) AS articles FROM news WHERE YEAR(publish_date) = 2020 GROUP BY month;
What is the distribution of customer complaints by issue type and region?
CREATE TABLE customer_complaints (complaint_id INT,complaint_type VARCHAR(20),region VARCHAR(20)); INSERT INTO customer_complaints (complaint_id,complaint_type,region) VALUES (1,'Billing','North'),(2,'Service','South'),(3,'Billing','East');
SELECT complaint_type, region, COUNT(*) AS complaint_count FROM customer_complaints GROUP BY complaint_type, region;
What is the total production of indigenous food systems in each continent?
CREATE TABLE indigenous_production (continent VARCHAR(255),production INT); INSERT INTO indigenous_production (continent,production) VALUES ('Continent1',2500),('Continent2',3200),('Continent3',1800); CREATE VIEW indigenous_systems_view AS SELECT * FROM indigenous_production WHERE production > 1500;
SELECT continent FROM indigenous_systems_view
Delete records of artisans without a country specified
CREATE TABLE Artisans (Id INT,Name TEXT,Country TEXT); INSERT INTO Artisans (Id,Name,Country) VALUES (1,'John','USA'),(2,'Ana',NULL);
DELETE FROM Artisans WHERE Country IS NULL;
What is the total number of hours played for the game 'League of Legends'?
CREATE TABLE PlayerActivity (PlayerID INT,Game VARCHAR(100),HoursPlayed INT); INSERT INTO PlayerActivity (PlayerID,Game,HoursPlayed) VALUES (1,'Overwatch',500); INSERT INTO PlayerActivity (PlayerID,Game,HoursPlayed) VALUES (2,'League of Legends',1000); INSERT INTO PlayerActivity (PlayerID,Game,HoursPlayed) VALUES (3,'F...
SELECT SUM(HoursPlayed) FROM PlayerActivity WHERE Game = 'League of Legends';
What is the average amount of foreign aid donated by country for the 'Agriculture' sector in the year 2020?
CREATE TABLE CountryAid (CountryName VARCHAR(50),Sector VARCHAR(50),AidAmount NUMERIC(15,2),DonationYear INT); INSERT INTO CountryAid (CountryName,Sector,AidAmount,DonationYear) VALUES ('USA','Agriculture',500000,2020),('Canada','Agriculture',350000,2020),('Australia','Agriculture',200000,2020);
SELECT AVG(AidAmount) FROM CountryAid WHERE Sector = 'Agriculture' AND DonationYear = 2020;
Find the number of gold mines in 'Country A' with production over 1500 units.
CREATE TABLE gold_mines (id INT,name TEXT,location TEXT,production INT); INSERT INTO gold_mines (id,name,location,production) VALUES (1,'Gold Mine A','Country A',1800); INSERT INTO gold_mines (id,name,location,production) VALUES (2,'Gold Mine B','Country A',1200); INSERT INTO gold_mines (id,name,location,production) VA...
SELECT COUNT(*) FROM gold_mines WHERE location = 'Country A' AND production > 1500;
What is the minimum risk rating for organizations in the Renewable Energy sector?
CREATE TABLE organizations (id INT,name TEXT,sector TEXT,risk_rating FLOAT); INSERT INTO organizations (id,name,sector,risk_rating) VALUES (1,'Org A','Renewable Energy',3.2),(2,'Org B','Finance',4.5),(3,'Org C','Renewable Energy',2.9),(4,'Org D','Healthcare',4.1),(5,'Org E','Finance',3.8);
SELECT MIN(risk_rating) FROM organizations WHERE sector = 'Renewable Energy';
How many lawyers are in the 'lawyers' table?
CREATE TABLE lawyers (id INT,name VARCHAR(50),is_pro_bono BOOLEAN); INSERT INTO lawyers (id,name,is_pro_bono) VALUES (1,'John Smith',FALSE),(2,'Jane Doe',TRUE),(3,'Michael Lee',FALSE);
SELECT COUNT(*) FROM lawyers;
What is the total transaction value per week for the past year?
CREATE TABLE transactions (transaction_date DATE,transaction_value DECIMAL(10,2)); INSERT INTO transactions (transaction_date,transaction_value) VALUES ('2022-01-01',500.00),('2022-01-02',750.00),('2022-01-03',3000.00),('2022-01-04',15000.00),('2022-01-05',200.00),('2022-01-06',1200.00),('2022-01-07',800.00);
SELECT WEEK(transaction_date) as week, YEAR(transaction_date) as year, SUM(transaction_value) as total_transaction_value FROM transactions WHERE transaction_date >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR) GROUP BY week, year;
What is the minimum number of community education programs conducted per year for each type of program?
CREATE TABLE Education_Programs (id INT,year INT,program_type VARCHAR(50),number_of_programs INT);
SELECT program_type, MIN(number_of_programs) FROM Education_Programs GROUP BY program_type;
How many home games did each soccer team play in the 2022 MLS season?
CREATE TABLE mls_teams (team_id INT,team_name TEXT,league TEXT,games_played INT,home_games INT); INSERT INTO mls_teams (team_id,team_name,league,games_played,home_games) VALUES (1,'Los Angeles FC','MLS',34,17),(2,'New York City FC','MLS',34,16);
SELECT team_name, home_games FROM mls_teams;
What is the total waste generated by the top 3 countries in the circular economy?
CREATE TABLE CircularEconomy (country TEXT,waste INT); INSERT INTO CircularEconomy (country,waste) VALUES ('Country1',200),('Country2',300),('Country3',150),('Country4',250),('Country5',400),('Country6',100),('Country7',350),('Country8',180),('Country9',450),('Country10',280);
SELECT country, SUM(waste) as total_waste FROM CircularEconomy GROUP BY country ORDER BY total_waste DESC LIMIT 3;