instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
List all fields that had a maximum temperature above the minimum temperature for field A in December 2021.
CREATE TABLE field_temperatures (field_id VARCHAR(10),temperature INT,reading_date DATE); INSERT INTO field_temperatures (field_id,temperature,reading_date) VALUES ('A',10,'2021-12-01'),('B',15,'2021-12-02'),('C',12,'2021-12-03');
SELECT field_id FROM field_temperatures WHERE temperature > (SELECT MIN(temperature) FROM field_temperatures WHERE field_id = 'A') AND reading_date BETWEEN '2021-12-01' AND '2021-12-31';
What is the maximum installed capacity of a single wind turbine in the wind farm with the highest installed capacity?
CREATE TABLE wind_turbines (id INT,farm_id INT,name VARCHAR(255),installed_capacity INT); INSERT INTO wind_turbines (id,farm_id,name,installed_capacity) VALUES (1,1,'Turbine A',50),(2,2,'Turbine B',60);
SELECT MAX(installed_capacity) FROM wind_turbines WHERE farm_id IN (SELECT id FROM (SELECT MAX(id) AS id FROM wind_farms) AS max_farm_id);
What are the production figures for wells in the Permian Basin, sorted by production?
CREATE TABLE wells (well_id INT,location VARCHAR(255),production_figures FLOAT); INSERT INTO wells (well_id,location,production_figures) VALUES (1,'Permian Basin',15000); INSERT INTO wells (well_id,location,production_figures) VALUES (2,'Eagle Ford',12000);
SELECT location, production_figures FROM wells WHERE location = 'Permian Basin' ORDER BY production_figures DESC;
What is the total number of visitors for the modern art and photography exhibitions?
CREATE TABLE Exhibitions (id INT,name VARCHAR(20)); INSERT INTO Exhibitions (id,name) VALUES (1,'Modern Art'),(2,'Photography');
SELECT COUNT(*) FROM Visitors JOIN Exhibitions ON Visitors.exhibition_id = Exhibitions.id WHERE Exhibitions.name IN ('Modern Art', 'Photography');
Update the safety score of the vessel 'Indian Titan' to 93 if its last safety check was more than a month ago.
CREATE TABLE Vessels (ID INT,Name VARCHAR(255),SafetyScore INT,LastSafetyCheck DATETIME); INSERT INTO Vessels (ID,Name,SafetyScore,LastSafetyCheck) VALUES (7,'Indian Titan',88,'2022-01-05'),(8,'Asian Ace',96,'2022-02-23');
UPDATE Vessels SET SafetyScore = 93 WHERE Name = 'Indian Titan' AND LastSafetyCheck < DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);
What is the percentage of uninsured individuals in Florida?
CREATE TABLE health_insurance (id INT,insured BOOLEAN,state TEXT); INSERT INTO health_insurance (id,insured,state) VALUES (1,true,'California'); INSERT INTO health_insurance (id,insured,state) VALUES (2,false,'Florida');
SELECT (SUM(NOT insured) * 100.0 / COUNT(*)) FROM health_insurance WHERE state = 'Florida';
What is the total number of naval vessels owned by African countries?
CREATE TABLE naval_vessels (id INT,country TEXT,vessel_type TEXT,in_service DATE); INSERT INTO naval_vessels (id,country,vessel_type,in_service) VALUES (1,'Algeria','Frigate','2016-05-12'),(2,'Nigeria','Corvette','2018-06-20'),(3,'South Africa','Submarine','2020-04-05');
SELECT COUNT(*) FROM naval_vessels WHERE country IN (SELECT DISTINCT country FROM naval_vessels WHERE country LIKE 'Africa%');
Delete all player records from the 'Players to Delete' list.
CREATE TABLE players (id INT,name VARCHAR(255),age INT,country VARCHAR(255)); CREATE TABLE players_to_delete (id INT); INSERT INTO players (id,name,age,country) VALUES (1,'John Doe',25,'USA'),(2,'Jane Doe',30,'Canada'); INSERT INTO players_to_delete (id) VALUES (1),(3);
DELETE FROM players WHERE id IN (SELECT id FROM players_to_delete);
How many games did each team play in the last season?
CREATE TABLE team_game_data (id INT,team VARCHAR(50),season INT,games INT); INSERT INTO team_game_data (id,team,season,games) VALUES (1,'Celtics',2022,82),(2,'Bruins',2022,82);
SELECT team, SUM(games) as total_games FROM team_game_data WHERE season = 2022 GROUP BY team;
Find the element with the highest production quantity for each country.
CREATE TABLE production (id INT,country VARCHAR(255),element VARCHAR(255),quantity INT); INSERT INTO production (id,country,element,quantity) VALUES (1,'China','Neodymium',12000),(2,'China','Dysprosium',1000),(3,'USA','Neodymium',4000),(4,'USA','Dysprosium',800),(5,'Australia','Neodymium',3000),(6,'Australia','Dysprosium',500);
SELECT country, element, quantity FROM (SELECT country, element, quantity, RANK() OVER (PARTITION BY country ORDER BY quantity DESC) as rnk FROM production) as ranked WHERE rnk = 1;
What is the average speed of electric vehicles in New York and California?
CREATE TABLE if not exists EvSpeed(state CHAR(2),avg_speed FLOAT); INSERT INTO EvSpeed(state,avg_speed) VALUES ('NY',65.3),('NY',63.8),('CA',68.9),('CA',70.1);
SELECT AVG(avg_speed) FROM EvSpeed WHERE state IN ('NY', 'CA') GROUP BY state;
What is the recycling rate for plastic and metal combined in 2020 for countries with a population over 100 million?
CREATE TABLE recycling_rates_population (country VARCHAR(255),year INT,plastic_rate FLOAT,metal_rate FLOAT); INSERT INTO recycling_rates_population (country,year,plastic_rate,metal_rate) VALUES ('India',2020,0.5,0.4),('China',2020,0.6,0.5),('Indonesia',2020,0.4,0.3);
SELECT r.country, (r.plastic_rate + r.metal_rate) as recycling_rate FROM recycling_rates_population r WHERE r.year = 2020 AND r.population > 100000000;
What is the total sales revenue for a given region in a given year?
CREATE TABLE sales (sale_id INT,product_id INT,sale_date DATE,region VARCHAR(50),sale_price FLOAT); INSERT INTO sales VALUES (1,1,'2022-01-05','Europe',15.99),(2,2,'2022-02-10','Asia',19.99),(3,1,'2022-03-20','Europe',15.99),(4,3,'2022-03-25','Europe',12.99);
SELECT SUM(sale_price) FROM sales WHERE sale_date BETWEEN '2022-01-01' AND '2022-12-31' AND region = 'Europe';
Find the number of public schools in the state of New Jersey and Georgia, excluding any schools with a rating below 7.
CREATE TABLE Schools (name VARCHAR(50),state VARCHAR(20),rating INT); INSERT INTO Schools (name,state,rating) VALUES ('SchoolA','New Jersey',8),('SchoolB','New Jersey',7),('SchoolC','Georgia',6);
SELECT COUNT(*) FROM Schools WHERE state IN ('New Jersey', 'Georgia') AND rating >= 7;
What is the total number of incidents and vulnerabilities, by attack vector and country?
CREATE TABLE incidents (id INT,date DATE,severity VARCHAR(10),attack_vector VARCHAR(20),country VARCHAR(20)); INSERT INTO incidents (id,date,severity,attack_vector,country) VALUES (1,'2021-01-01','medium','web','USA'); INSERT INTO incidents (id,date,severity,attack_vector,country) VALUES (2,'2021-01-02','high','email','Canada'); CREATE TABLE vulnerabilities (id INT,date DATE,severity VARCHAR(10),system VARCHAR(20),country VARCHAR(20)); INSERT INTO vulnerabilities (id,date,severity,system,country) VALUES (1,'2021-01-01','medium','database','Mexico'); INSERT INTO vulnerabilities (id,date,severity,system,country) VALUES (2,'2021-01-02','high','network','Brazil');
SELECT 'incidents' as type, attack_vector, country, COUNT(*) as total FROM incidents GROUP BY attack_vector, country UNION ALL SELECT 'vulnerabilities' as type, system as attack_vector, country, COUNT(*) as total FROM vulnerabilities GROUP BY system, country;
What is the total labor productivity in terms of extracted minerals per hour for each company?
CREATE TABLE companies (id INT,name VARCHAR(255)); INSERT INTO companies (id,name) VALUES (1,'ACME Minerals'),(2,'BIG Extraction'); CREATE TABLE production (id INT,company_id INT,extracted_minerals INT,extraction_hours DECIMAL(10,2)); INSERT INTO production (id,company_id,extracted_minerals,extraction_hours) VALUES (1,1,500,10.0),(2,1,600,12.0),(3,2,700,15.0);
SELECT c.name, SUM(p.extracted_minerals) / SUM(p.extraction_hours) as labor_productivity FROM companies c INNER JOIN production p ON c.id = p.company_id GROUP BY c.name;
Which volunteers have not donated to a program?
CREATE TABLE Volunteers (VolunteerID int,Name varchar(50)); INSERT INTO Volunteers (VolunteerID,Name) VALUES (1,'John Doe'),(2,'Jane Smith'),(3,'Mike Johnson'); CREATE TABLE VolunteerPrograms (VolunteerID int,ProgramID int); INSERT INTO VolunteerPrograms (VolunteerID,ProgramID) VALUES (1,1),(2,1),(3,2);
SELECT V.Name FROM Volunteers V LEFT JOIN VolunteerPrograms VP ON V.VolunteerID = VP.VolunteerID WHERE VP.ProgramID IS NULL
Show the total nutrient content for each feed type
CREATE TABLE feed_inventory (feed_id INT PRIMARY KEY,feed_type VARCHAR(50),nutrients INT,quantity INT); INSERT INTO feed_inventory (feed_id,feed_type,nutrients,quantity) VALUES (1,'Pellets',350,1000),(2,'Flakes',280,750),(3,'Gel',400,1200);
SELECT feed_type, SUM(nutrients * quantity) as total_nutrients FROM feed_inventory GROUP BY feed_type;
What is the average package weight shipped from each warehouse, excluding shipments under 20 kg?
CREATE TABLE warehouse (id INT,location VARCHAR(255)); INSERT INTO warehouse (id,location) VALUES (1,'Chicago'),(2,'Houston'); CREATE TABLE packages (id INT,warehouse_id INT,weight FLOAT); INSERT INTO packages (id,warehouse_id,weight) VALUES (1,1,50.3),(2,1,30.1),(3,2,70.0),(4,2,10.0);
SELECT warehouse_id, AVG(weight) as avg_weight FROM packages WHERE weight >= 20 GROUP BY warehouse_id;
Find the number of energy storage projects in South Korea and Brazil for each energy type.
CREATE TABLE energy_storage (country VARCHAR(255),energy_type VARCHAR(255),project_count INT); INSERT INTO energy_storage (country,energy_type,project_count) VALUES ('South Korea','Batteries',200),('Brazil','Batteries',350),('South Korea','Pumped Hydro',50),('Brazil','Pumped Hydro',600);
SELECT country, energy_type, SUM(project_count) FROM energy_storage WHERE country IN ('South Korea', 'Brazil') GROUP BY country, energy_type;
What was the total fare collected from the 'Blue Line' on February 14, 2021?
CREATE TABLE routes (route_name VARCHAR(20),fare FLOAT); INSERT INTO routes (route_name,fare) VALUES ('Red Line',2.50),('Blue Line',3.25),('Green Line',1.75);
SELECT SUM(fare) FROM routes WHERE route_name = 'Blue Line' AND fare_date = '2021-02-14';
List the materials with the highest labor cost in the 'construction_labor' table.
CREATE TABLE construction_labor (laborer_id INT,laborer_name VARCHAR(50),project_id INT,material VARCHAR(50),cost DECIMAL(10,2));
SELECT material, MAX(cost) AS max_cost FROM construction_labor GROUP BY material ORDER BY max_cost DESC LIMIT 1;
How many products have been sold by vendors with ethical labor practices?
CREATE TABLE vendors(vendor_id INT,vendor_name TEXT,ethical_practices BOOLEAN); INSERT INTO vendors(vendor_id,vendor_name,ethical_practices) VALUES (1,'VendorA',TRUE),(2,'VendorB',FALSE),(3,'VendorC',TRUE);
SELECT COUNT(DISTINCT product_id) FROM transactions JOIN vendors ON transactions.vendor_id = vendors.vendor_id WHERE vendors.ethical_practices = TRUE;
What is the number of mental health parity violations per language?
CREATE TABLE Languages (language_id INT,language_name TEXT);CREATE TABLE ParityViolations (violation_id INT,violation_language INT);
SELECT l.language_name, COUNT(*) as num_violations FROM ParityViolations pv JOIN Languages l ON pv.violation_language = l.language_id GROUP BY l.language_name;
What is the total number of mobile customers who have made international calls from the state of California in the first quarter of 2021?
CREATE TABLE mobile_customers (customer_id INT,international_calls BOOLEAN,state VARCHAR(20),call_date DATE); INSERT INTO mobile_customers (customer_id,international_calls,state,call_date) VALUES (1,true,'California','2021-01-05'),(2,false,'California','2021-02-10'),(3,true,'California','2021-03-15');
SELECT COUNT(*) FROM mobile_customers WHERE international_calls = true AND state = 'California' AND call_date >= '2021-01-01' AND call_date <= '2021-03-31';
What is the maximum landfill capacity in cubic meters for each region?
CREATE TABLE LandfillCapacity (region VARCHAR(255),landfill_capacity FLOAT); INSERT INTO LandfillCapacity (region,landfill_capacity) VALUES ('North',1000000),('South',800000),('East',1200000),('West',900000);
SELECT region, MAX(landfill_capacity) FROM LandfillCapacity GROUP BY region;
How many patients started therapy in Sydney each quarter of 2020?
CREATE TABLE therapy (therapy_id INT,patient_id INT,therapist_id INT,therapy_date DATE,city TEXT); INSERT INTO therapy (therapy_id,patient_id,therapist_id,therapy_date,city) VALUES (1,1,101,'2018-01-02','Sydney');
SELECT DATE_TRUNC('quarter', therapy_date) as quarter, COUNT(DISTINCT patient_id) as num_patients FROM therapy WHERE city = 'Sydney' AND EXTRACT(YEAR FROM therapy_date) = 2020 GROUP BY quarter ORDER BY quarter;
What is the total amount donated by individual donors from Canada in the year 2020?
CREATE TABLE Donors (DonorID INT,DonorName TEXT,Country TEXT); INSERT INTO Donors (DonorID,DonorName,Country) VALUES (1,'John Doe','Canada'); INSERT INTO Donors (DonorID,DonorName,Country) VALUES (2,'Jane Smith','USA'); CREATE TABLE Donations (DonationID INT,DonorID INT,DonationAmount DECIMAL,DonationDate DATE); INSERT INTO Donations (DonationID,DonorID,DonationAmount,DonationDate) VALUES (1,1,50.00,'2020-01-01'); INSERT INTO Donations (DonationID,DonorID,DonationAmount,DonationDate) VALUES (2,1,75.00,'2020-12-31');
SELECT SUM(Donations.DonationAmount) FROM Donors INNER JOIN Donations ON Donors.DonorID = Donations.DonorID WHERE Donors.Country = 'Canada' AND YEAR(Donations.DonationDate) = 2020;
How many female and male faculty members are there in the College of Engineering, and what is their average salary?
CREATE TABLE faculty (faculty_id INT,faculty_name VARCHAR(50),dept_name VARCHAR(50),salary INT,gender VARCHAR(10));
SELECT dept_name, SUM(CASE WHEN gender = 'Female' THEN 1 ELSE 0 END) as num_female, SUM(CASE WHEN gender = 'Male' THEN 1 ELSE 0 END) as num_male, AVG(salary) as avg_salary FROM faculty WHERE dept_name = 'College of Engineering' GROUP BY dept_name;
What is the preferred size of customers from Spain?
CREATE TABLE CUSTOMER_SIZE (customer_id INT PRIMARY KEY,customer_name VARCHAR(50),preferred_size VARCHAR(10),country VARCHAR(50)); INSERT INTO CUSTOMER_SIZE (customer_id,customer_name,preferred_size,country) VALUES (1,'Alice','M','USA'),(2,'Bob','L','USA'),(3,'Carol','XL','Spain');
SELECT preferred_size FROM CUSTOMER_SIZE WHERE country = 'Spain';
What is the total cost of permits issued for residential projects in Austin?
CREATE TABLE permit (id INT,city VARCHAR(20),project_type VARCHAR(20),cost INT); INSERT INTO permit (id,city,project_type,cost) VALUES (1,'Austin','Residential',5000); INSERT INTO permit (id,city,project_type,cost) VALUES (2,'Austin','Commercial',15000); INSERT INTO permit (id,city,project_type,cost) VALUES (3,'Dallas','Residential',6000);
SELECT SUM(cost) FROM permit WHERE city = 'Austin' AND project_type = 'Residential';
What was the total donation amount by individuals in Russia in Q3 2021?
CREATE TABLE Donations (id INT,donor_name VARCHAR(255),donation_amount DECIMAL(10,2),donation_date DATE); INSERT INTO Donations (id,donor_name,donation_amount,donation_date) VALUES (1,'Ivan Petrov',20.00,'2021-07-22'),(2,'Natalia Ivanova',30.00,'2021-10-07');
SELECT SUM(donation_amount) FROM Donations WHERE donor_name NOT LIKE '%org%' AND donation_date BETWEEN '2021-07-01' AND '2021-09-30';
Who are the top 5 donors to education initiatives in Haiti, and how much have they donated in total?
CREATE TABLE Donors (id INT,donor_name VARCHAR(50),donation_amount INT,initiative_type VARCHAR(50)); INSERT INTO Donors (id,donor_name,donation_amount,initiative_type) VALUES (1,'Donor1',5000,'education'),(2,'Donor2',10000,'education'); CREATE TABLE Initiatives (initiative_id INT,initiative_type VARCHAR(50)); INSERT INTO Initiatives (initiative_id,initiative_type) VALUES (1,'education'),(2,'health');
SELECT Donors.donor_name, SUM(Donors.donation_amount) AS total_donated FROM Donors JOIN Initiatives ON Donors.initiative_type = Initiatives.initiative_type WHERE Initiatives.initiative_type = 'education' AND Donors.donor_name IN (SELECT Donors.donor_name FROM Donors WHERE Donors.initiative_type = 'education' GROUP BY Donors.donor_name ORDER BY SUM(Donors.donation_amount) DESC LIMIT 5);
List all adaptation projects that started after January 2023
CREATE TABLE adaptation_projects (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),budget FLOAT,start_date DATE,end_date DATE); INSERT INTO adaptation_projects (id,name,location,budget,start_date,end_date) VALUES (1,'Seawall Construction','New York City,USA',2000000,'2022-01-01','2023-12-31'),(2,'Drought Resistant Crops','Cape Town,South Africa',800000,'2023-05-15','2024-04-30'),(3,'Flood Early Warning System','Dhaka,Bangladesh',1000000,'2023-07-01','2025-06-30');
SELECT * FROM adaptation_projects WHERE start_date > '2023-01-01';
What is the average number of professional development courses completed by teachers in the past year, broken down by their years of experience?
CREATE TABLE teachers (teacher_id INT,years_of_experience INT,professional_development_course_completion_date DATE); INSERT INTO teachers (teacher_id,years_of_experience,professional_development_course_completion_date) VALUES (1,5,'2022-01-01'),(2,10,'2021-12-15'),(3,2,'2022-03-05');
SELECT years_of_experience, AVG(COUNT(*)) as avg_courses FROM teachers WHERE professional_development_course_completion_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY years_of_experience;
What is the average age of female patients diagnosed with tuberculosis, grouped by ethnicity, in California during 2020?
CREATE TABLE patients (id INT,name VARCHAR(50),age INT,gender VARCHAR(10),ethnicity VARCHAR(30),diagnosis VARCHAR(50),state VARCHAR(20),date DATE); INSERT INTO patients (id,name,age,gender,ethnicity,diagnosis,state,date) VALUES (1,'Jessica',34,'Female','Hispanic','Tuberculosis','California','2020-03-15'); INSERT INTO patients (id,name,age,gender,ethnicity,diagnosis,state,date) VALUES (2,'John',45,'Male','Caucasian','Tuberculosis','California','2020-06-27'); INSERT INTO patients (id,name,age,gender,ethnicity,diagnosis,state,date) VALUES (3,'Clara',28,'Female','African American','Tuberculosis','California','2020-11-09');
SELECT AVG(age) as avg_age, ethnicity FROM patients WHERE diagnosis = 'Tuberculosis' AND gender = 'Female' AND state = 'California' AND YEAR(date) = 2020 GROUP BY ethnicity;
What is the total number of military technology patents filed by 'Government Entity A' and 'Government Entity B'?
CREATE TABLE MilitaryPatents (ID INT,Entity VARCHAR(50),Patent VARCHAR(50),Year INT); INSERT INTO MilitaryPatents (ID,Entity,Patent,Year) VALUES (1,'Government Entity A','Patent1',2020); INSERT INTO MilitaryPatents (ID,Entity,Patent,Year) VALUES (2,'Government Entity B','Patent2',2021);
SELECT COUNT(*) FROM MilitaryPatents WHERE Entity IN ('Government Entity A', 'Government Entity B');
List the programs that had the highest and lowest impact in terms of funds raised in 2020?
CREATE TABLE programs (program_id INT,program_name VARCHAR(50),funds_raised DECIMAL(10,2),program_start_date DATE);
SELECT program_name, funds_raised FROM programs WHERE program_start_date <= '2020-12-31' AND program_start_date >= '2020-01-01' ORDER BY funds_raised DESC LIMIT 1; SELECT program_name, funds_raised FROM programs WHERE program_start_date <= '2020-12-31' AND program_start_date >= '2020-01-01' ORDER BY funds_raised ASC LIMIT 1;
What is the carbon pricing for country 'FR' in the 'carbon_pricing' schema?
CREATE TABLE carbon_pricing.carbon_prices (country varchar(2),year int,price decimal(5,2)); INSERT INTO carbon_pricing.carbon_prices (country,year,price) VALUES ('FR',2020,30.5),('FR',2021,32.0),('DE',2020,28.0),('DE',2021,30.2);
SELECT price FROM carbon_pricing.carbon_prices WHERE country = 'FR' AND year = (SELECT MAX(year) FROM carbon_pricing.carbon_prices);
Show the number of doctors, nurses, and patients in the rural healthcare system.
CREATE TABLE Doctors (ID INT,Name TEXT,Specialty TEXT); CREATE TABLE Nurses (ID INT,Name TEXT,Specialty TEXT); CREATE TABLE Patients (ID INT,Name TEXT,Condition TEXT);
SELECT (SELECT COUNT(*) FROM Doctors) + (SELECT COUNT(*) FROM Nurses) + (SELECT COUNT(*) FROM Patients) AS Total;
Insert new records into the RiskModels table for policyholders with a low risk score.
CREATE TABLE Policyholders (ID INT,Name VARCHAR(50),Age INT,Gender VARCHAR(10),City VARCHAR(50),State VARCHAR(20),ZipCode VARCHAR(10)); CREATE TABLE RiskModels (ID INT,PolicyholderID INT,ModelName VARCHAR(50),ModelScore DECIMAL(5,2));
INSERT INTO RiskModels (ID, PolicyholderID, ModelName, ModelScore) SELECT Policyholders.ID, Policyholders.ID AS PolicyholderID, 'Risk Model A' AS ModelName, 0.5 AS ModelScore FROM Policyholders WHERE Age < 30;
How many education resources were distributed in India in Q2 and Q3 2022?
CREATE TABLE education_resources (id INT,quantity INT,country TEXT,quarter INT,year INT); INSERT INTO education_resources (id,quantity,country,quarter,year) VALUES (1,200,'India',2,2022),(2,300,'India',3,2022),(3,400,'India',4,2022);
SELECT SUM(quantity) FROM education_resources WHERE country = 'India' AND (quarter = 2 OR quarter = 3) AND year = 2022;
Which infrastructure projects in Texas have experienced cost overruns of over 20%?
CREATE TABLE projects (project_id INT,project_name VARCHAR(100),state CHAR(2),planned_cost FLOAT,actual_cost FLOAT); INSERT INTO projects VALUES (1,'TX Bullet Train','TX',12000000000,14000000000),(2,'Dallas-Fort Worth Connector','TX',800000000,900000000),(3,'Houston Ship Channel Expansion','TX',1000000000,1100000000);
SELECT * FROM projects WHERE state = 'TX' AND actual_cost > planned_cost * 1.2;
Get the names of all AI models that were created before 2020-01-01 and are part of the Explainable AI category.
CREATE TABLE ai_models (model_id INT,name VARCHAR(50),category VARCHAR(50),creation_date DATE); INSERT INTO ai_models (model_id,name,category,creation_date) VALUES (1,'LIME','Explainable AI','2019-06-15'); INSERT INTO ai_models (model_id,name,category,creation_date) VALUES (2,'SHAP','Explainable AI','2018-03-22'); INSERT INTO ai_models (model_id,name,category,creation_date) VALUES (3,'Gazer','Computer Vision','2020-12-25');
SELECT name FROM ai_models WHERE creation_date < '2020-01-01' AND category = 'Explainable AI';
What is the daily production trend for a specific well?
CREATE TABLE production (prod_id INT,well_id INT,prod_date DATE,production_rate FLOAT); INSERT INTO production (prod_id,well_id,prod_date,production_rate) VALUES (1,1,'2020-01-01',1000),(2,1,'2020-01-02',1100),(3,1,'2020-01-03',1200),(4,1,'2020-01-04',1300),(5,1,'2020-01-05',1400);
SELECT prod_date, production_rate, LAG(production_rate, 1) OVER (ORDER BY prod_date) AS previous_day_rate FROM production WHERE well_id = 1;
What is the total amount donated and number of donations for each quarter in the 'donations' table?
CREATE TABLE donations (donation_id INT,donation_date DATE,donation_amount FLOAT); INSERT INTO donations (donation_id,donation_date,donation_amount) VALUES (1,'2022-01-01',50.00),(2,'2022-02-01',100.00),(3,'2022-03-01',150.00);
SELECT DATE_TRUNC('quarter', donation_date) as quarter, SUM(donation_amount) as total_donation, COUNT(donation_id) as num_donations FROM donations GROUP BY quarter ORDER BY quarter;
What is the average funding received by companies founded by women in the renewable energy sector?
CREATE TABLE companies (id INT,name TEXT,industry TEXT,founders_gender TEXT,funding FLOAT);
SELECT AVG(funding) FROM companies WHERE founders_gender = 'female' AND industry = 'renewable energy';
What is the average area size of aquaculture farms in Africa?
CREATE TABLE AquacultureFarms (region VARCHAR(50),area_size INT); INSERT INTO AquacultureFarms (region,area_size) VALUES ('Africa',10000),('Asia',15000),('Europe',12000),('North America',18000),('South America',14000);
SELECT AVG(area_size) as avg_area_size FROM AquacultureFarms WHERE region = 'Africa';
List the vessel names, their types, and safety inspection status for all vessels with an engine capacity greater than 3000, ordered by safety inspection status and engine capacity in descending order?
CREATE TABLE Vessels (ID INT,Name VARCHAR(50),Type VARCHAR(50),Safety_Inspections INT,Engine_Capacity INT); INSERT INTO Vessels (ID,Name,Type,Safety_Inspections,Engine_Capacity) VALUES (1,'MV Andromeda','Cargo Ship',1,3500),(2,'MV Antares','Cargo Ship',0,6000);
SELECT Name, Type, Safety_Inspections, Engine_Capacity FROM Vessels WHERE Engine_Capacity > 3000 ORDER BY Safety_Inspections DESC, Engine_Capacity DESC;
What is the total number of inclusive housing units in Portland and San Francisco?
CREATE TABLE housing (id INT,units INT,city VARCHAR(20),inclusive BOOLEAN); INSERT INTO housing (id,units,city,inclusive) VALUES (1,50,'Portland',TRUE),(2,75,'San Francisco',TRUE),(3,100,'NYC',FALSE);
SELECT SUM(units) FROM housing WHERE inclusive = TRUE AND city IN ('Portland', 'San Francisco');
What is the difference in average permit cost between high-rise and low-rise buildings in British Columbia in 2021?
CREATE TABLE permit_cost_comparison (cost_id INT,province VARCHAR(50),building_type VARCHAR(50),permit_cost FLOAT,structure_height INT,issue_date DATE); INSERT INTO permit_cost_comparison (cost_id,province,building_type,permit_cost,structure_height,issue_date) VALUES (7,'British Columbia','High-rise',1000000.00,50,'2021-01-01'); INSERT INTO permit_cost_comparison (cost_id,province,building_type,permit_cost,structure_height,issue_date) VALUES (8,'British Columbia','Low-rise',500000.00,10,'2021-01-10');
SELECT AVG(permit_cost) - LAG(AVG(permit_cost)) OVER (PARTITION BY province ORDER BY EXTRACT(YEAR FROM issue_date)) FROM permit_cost_comparison WHERE province = 'British Columbia' AND building_type IN ('High-rise', 'Low-rise') AND issue_date BETWEEN '2021-01-01' AND '2021-12-31';
What is the maximum and minimum carbon offset per green building in each country?
CREATE TABLE green_buildings (id INT,country VARCHAR(50),offset INT); INSERT INTO green_buildings (id,country,offset) VALUES (1,'CountryA',50),(2,'CountryB',100),(3,'CountryA',75),(4,'CountryA',125),(5,'CountryB',150);
SELECT g.country, MAX(g.offset) as max_offset, MIN(g.offset) as min_offset FROM green_buildings g GROUP BY g.country;
Find the maximum energy efficiency rating of projects in the 'solar' technology type.
CREATE TABLE projects (id INT,technology VARCHAR(20),energy_efficiency_rating INT); INSERT INTO projects (id,technology,energy_efficiency_rating) VALUES (1,'wind',80),(2,'solar',90),(3,'wind',75),(4,'hydro',95);
SELECT MAX(energy_efficiency_rating) AS max_rating FROM projects WHERE technology = 'solar';
What is the name and description of the oldest accommodation provided?
CREATE TABLE Accommodations (Id INT,StudentId INT,AccommodationType VARCHAR(50),Description TEXT,DateProvided DATETIME); INSERT INTO Accommodations (Id,StudentId,AccommodationType,Description,DateProvided) VALUES (1,1,'Sign Language Interpreter','Interpreted lectures for a student with hearing impairment','2021-01-01');
SELECT AccommodationType, Description FROM Accommodations ORDER BY DateProvided ASC LIMIT 1;
What is the total waste generation in grams for the bottom 3 countries in 2021, ordered by the least total amount?
CREATE TABLE waste_generation (country VARCHAR(50),year INT,waste_generation_grams INT); INSERT INTO waste_generation (country,year,waste_generation_grams) VALUES ('India',2021,5000000),('China',2021,4000000),('Indonesia',2021,3000000),('Vietnam',2021,2000000);
SELECT country, SUM(waste_generation_grams) as total_waste_generation_2021 FROM waste_generation WHERE year = 2021 GROUP BY country ORDER BY total_waste_generation_2021 ASC LIMIT 3;
How many network technologies has the company invested in?
CREATE TABLE tech_investments (id INT,network_tech VARCHAR(30)); INSERT INTO tech_investments (id,network_tech) VALUES (1,'5G');
SELECT COUNT(*) FROM tech_investments;
What is the total transaction value for each hour of the day for the month of April 2022?
CREATE TABLE transactions (transaction_id INT,transaction_date DATE,transaction_category VARCHAR(255),transaction_value DECIMAL(10,2)); INSERT INTO transactions (transaction_id,transaction_date,transaction_category,transaction_value) VALUES (1,'2022-04-02','Food',75.00),(2,'2022-04-05','Electronics',350.00),(3,'2022-04-10','Clothing',200.00);
SELECT HOUR(transaction_date) as hour_of_day, SUM(transaction_value) as total_value FROM transactions WHERE transaction_date BETWEEN '2022-04-01' AND '2022-04-30' GROUP BY hour_of_day;
What are the top 2 cybersecurity strategies by budget allocated for the current fiscal year, and which departments have been assigned to implement them?
CREATE TABLE cybersecurity_strategies (id INT,strategy VARCHAR(50),department VARCHAR(50),budget INT,fiscal_year INT); INSERT INTO cybersecurity_strategies (id,strategy,department,budget,fiscal_year) VALUES (1,'Endpoint Protection','IT',500000,2022),(2,'Network Security','IT',600000,2022),(3,'Incident Response','Security',400000,2022),(4,'Risk Management','Risk',300000,2022),(5,'Vulnerability Management','Security',450000,2022),(6,'Identity and Access Management','IT',550000,2022);
SELECT strategy, department, SUM(budget) as total_budget FROM cybersecurity_strategies WHERE fiscal_year = 2022 GROUP BY strategy, department HAVING COUNT(*) >= 2 ORDER BY total_budget DESC;
Identify the top 3 countries with the most community education programs, based on the "education_programs", "countries", and "habitat_preservation" tables
CREATE TABLE education_programs (program_name VARCHAR(255),country VARCHAR(255),habitat_type VARCHAR(255)); CREATE TABLE countries (country VARCHAR(255),region VARCHAR(255)); CREATE TABLE habitat_preservation (habitat_type VARCHAR(255),location VARCHAR(255));
SELECT e1.country, COUNT(e1.program_name) as num_programs FROM education_programs e1 INNER JOIN countries c1 ON e1.country = c1.country INNER JOIN habitat_preservation h1 ON e1.habitat_type = h1.habitat_type GROUP BY e1.country ORDER BY num_programs DESC LIMIT 3;
What is the most expensive product from company 'XYZ'?
CREATE TABLE products (id INT,company VARCHAR(255),price DECIMAL(5,2)); INSERT INTO products (id,company,price) VALUES (1,'ABC',50.99),(2,'DEF',35.49),(3,'XYZ',75.99),(4,'ABC',60.99);
SELECT MAX(price) FROM products WHERE company = 'XYZ';
List the top 5 cities with the highest broadband subscription rates.
CREATE TABLE broadband_subscribers(id INT,name VARCHAR(50),city VARCHAR(50)); CREATE TABLE broadband_usage(subscriber_id INT,usage FLOAT);
SELECT broadband_subscribers.city, COUNT(*) as num_subscribers, AVG(broadband_usage.usage) as avg_usage FROM broadband_subscribers JOIN broadband_usage ON broadband_subscribers.id = broadband_usage.subscriber_id GROUP BY broadband_subscribers.city ORDER BY num_subscribers DESC, avg_usage DESC LIMIT 5;
Update the "CommunityProjects" table to reflect that the project status for the 'IrrigationInfrastructure' project changed to 'completed'
CREATE TABLE CommunityProjects (id INT PRIMARY KEY,project_name VARCHAR(255),location VARCHAR(255),status VARCHAR(255));
UPDATE CommunityProjects SET status = 'completed' WHERE project_name = 'IrrigationInfrastructure';
What is the total R&D expenditure for drugs in 'Europe'?
CREATE TABLE rd_expenditure (drug_name TEXT,region TEXT,amount INTEGER);
SELECT SUM(amount) FROM rd_expenditure WHERE region = 'Europe';
What is the local economic impact of tourism in Barcelona per quarter?
CREATE TABLE local_economy (city TEXT,year INT,quarter INT,impact INT); INSERT INTO local_economy (city,year,quarter,impact) VALUES ('Barcelona',2022,1,5000),('Barcelona',2022,2,5500),('Barcelona',2022,3,6000),('Barcelona',2022,4,6500);
SELECT quarter, SUM(impact) FROM local_economy WHERE city = 'Barcelona' GROUP BY quarter;
How many community education programs are there for each habitat type?
CREATE TABLE education (id INT,type VARCHAR(50),programs INT); INSERT INTO education (id,type,programs) VALUES (1,'Forest',5),(2,'Savannah',3),(3,'Wetlands',7);
SELECT type, SUM(programs) FROM education GROUP BY type;
Delete the 'MarineLife' table records for species with a population less than 500
CREATE TABLE MarineLife (id INT,species VARCHAR(50),population INT,last_sighting DATE); INSERT INTO MarineLife (id,species,population,last_sighting) VALUES (1,'Shark',500,'2019-01-01'),(2,'Starfish',3000,'2020-05-15'),(3,'Jellyfish',1500,'2018-12-27'),(4,'Lionfish',800,'2020-07-08');
DELETE FROM MarineLife WHERE population < 500;
What is the total budget for all government departments in Canada?
CREATE TABLE GovernmentDepartments (DepartmentID int,DepartmentName varchar(255),Country varchar(255),Budget decimal(10,2)); INSERT INTO GovernmentDepartments (DepartmentID,DepartmentName,Country,Budget) VALUES (1,'Canadian Department of Defense','Canada',25000000.00),(2,'Canadian Department of Health','Canada',30000000.00);
SELECT SUM(Budget) FROM GovernmentDepartments WHERE Country = 'Canada';
What is the average dissolved oxygen level for marine fish farms in the Pacific region?
CREATE TABLE marine_fish_farms (id INT,name TEXT,region TEXT,dissolved_oxygen FLOAT); INSERT INTO marine_fish_farms (id,name,region,dissolved_oxygen) VALUES (1,'Farm A','Pacific',6.5),(2,'Farm B','Pacific',6.3),(3,'Farm C','Atlantic',7.0);
SELECT AVG(dissolved_oxygen) FROM marine_fish_farms WHERE region = 'Pacific' AND species = 'marine';
How many marine protected areas are there in each ocean basin?
CREATE TABLE marine_protected_areas (area_name TEXT,ocean_basin TEXT); INSERT INTO marine_protected_areas (area_name,ocean_basin) VALUES ('Galapagos Islands','Pacific'),('Great Barrier Reef','Pacific'),('Palau National Marine Sanctuary','Pacific'),('Northwest Atlantic Marine National Monument','Atlantic');
SELECT ocean_basin, COUNT(*) FROM marine_protected_areas GROUP BY ocean_basin;
What is the minimum quantity of recycled materials used by retailers in the 'Toys' category?
CREATE TABLE retailers (retailer_id INT,retailer_name VARCHAR(255),category VARCHAR(255),recycled_materials_quantity INT); INSERT INTO retailers (retailer_id,retailer_name,category,recycled_materials_quantity) VALUES (1,'Green Toys','Toys',300); INSERT INTO retailers (retailer_id,retailer_name,category,recycled_materials_quantity) VALUES (2,'Eco Kids','Toys',550);
SELECT MIN(recycled_materials_quantity) FROM retailers WHERE category = 'Toys';
What's the number of movies released per year by a specific studio?
CREATE TABLE studio (studio_id INT,studio_name VARCHAR(50),country VARCHAR(50)); INSERT INTO studio (studio_id,studio_name,country) VALUES (1,'Studio A','USA'),(2,'Studio B','Canada'); CREATE TABLE movie (movie_id INT,title VARCHAR(50),release_year INT,studio_id INT); INSERT INTO movie (movie_id,title,release_year,studio_id) VALUES (1,'Movie 1',2019,1),(2,'Movie 2',2020,1),(3,'Movie 3',2018,2);
SELECT release_year, COUNT(title) FROM movie JOIN studio ON movie.studio_id = studio.studio_id WHERE studio.studio_name = 'Studio A' GROUP BY release_year;
Find the total number of fans who engaged with each social media platform for a specific team?
CREATE TABLE fans (fan_id INT,team_name VARCHAR(50),platform VARCHAR(50),followers INT); INSERT INTO fans (fan_id,team_name,platform,followers) VALUES (1,'Red Sox','Twitter',500000),(2,'Yankees','Instagram',700000);
SELECT team_name, SUM(followers) as total_followers FROM fans GROUP BY team_name;
List all the animal species in the 'animal_population' table along with their conservation status from the 'conservation_status' table.
CREATE TABLE animal_population (id INT,animal_name VARCHAR(50),population INT); CREATE TABLE conservation_status (id INT,animal_name VARCHAR(50),status VARCHAR(20));
SELECT ap.animal_name, cs.status FROM animal_population ap INNER JOIN conservation_status cs ON ap.animal_name = cs.animal_name;
What is the total investment amount for each customer in the North region?
CREATE TABLE investments (investment_id INT,customer_id INT,region VARCHAR(20),investment_amount DECIMAL(10,2)); INSERT INTO investments (investment_id,customer_id,region,investment_amount) VALUES (1,3,'North',10000.00),(2,4,'South',15000.00);
SELECT customer_id, SUM(investment_amount) FROM investments WHERE region = 'North' GROUP BY customer_id;
What is the total waste generation in kg for all cities in the year 2020?
CREATE TABLE waste_generation (city VARCHAR(255),year INT,amount FLOAT); INSERT INTO waste_generation (city,year,amount) VALUES ('CityA',2020,1200.5),('CityA',2019,1100.3),('CityB',2020,1500.6),('CityB',2019,1400.2);
SELECT SUM(amount) FROM waste_generation WHERE year = 2020;
Update the "experience" field in the "researchers" table for the researcher with "researcher_id" 405 to 9.
CREATE TABLE researchers (researcher_id INT PRIMARY KEY,name VARCHAR(255),region VARCHAR(255),experience INT);
UPDATE researchers SET experience = 9 WHERE researcher_id = 405;
What is the total coral reef area for countries in the Pacific Ocean?
CREATE TABLE countries (country_name TEXT,ocean_basin TEXT,coral_reef_area FLOAT); INSERT INTO countries (country_name,ocean_basin,coral_reef_area) VALUES ('Japan','Pacific',15000.0),('Australia','Pacific',60000.0),('Philippines','Pacific',27000.0);
SELECT SUM(coral_reef_area) FROM countries WHERE ocean_basin = 'Pacific';
What is the average size of protected habitats in square kilometers?
CREATE TABLE habitats (id INT,name TEXT,size_km2 FLOAT); INSERT INTO habitats (id,name,size_km2) VALUES (1,'Forest',50.3),(2,'Wetlands',32.1),(3,'Grasslands',87.6);
SELECT AVG(size_km2) FROM habitats;
List all food safety inspections with a passing grade, their corresponding restaurant, and the date of inspection.
CREATE TABLE Restaurants (RestaurantID int,RestaurantName varchar(255)); CREATE TABLE Inspections (InspectionID int,RestaurantID int,InspectionGrade varchar(10),InspectionDate date);
SELECT R.RestaurantName, I.InspectionGrade, I.InspectionDate FROM Restaurants R INNER JOIN Inspections I ON R.RestaurantID = I.RestaurantID WHERE I.InspectionGrade = 'Pass';
What is the daily ridership of public transportation in London over the past week?
CREATE TABLE public_transportation_ridership (id INT,trip_date DATE,mode TEXT,ridership INT);
SELECT trip_date, mode, AVG(ridership) AS daily_ridership FROM public_transportation_ridership WHERE trip_date >= CURRENT_DATE - INTERVAL '7 days' GROUP BY trip_date, mode;
What is the total value of contracts negotiated with the US government by defense contractors in the last 2 years?
CREATE TABLE ContractNegotiations (id INT,contractor VARCHAR(255),government VARCHAR(255),contract_value INT,negotiation_date DATE); INSERT INTO ContractNegotiations (id,contractor,government,contract_value,negotiation_date) VALUES (1,'Contractor A','US Government',20000000,'2020-01-01'),(2,'Contractor B','US Government',15000000,'2019-06-15'),(3,'Contractor A','US Government',25000000,'2021-03-30');
SELECT SUM(contract_value) as total_value FROM ContractNegotiations WHERE government = 'US Government' AND negotiation_date >= DATE_SUB(CURRENT_DATE, INTERVAL 2 YEAR);
List the recycling rates for the top 3 cities with the highest waste generation in 2021.
CREATE TABLE recycling_rates (city VARCHAR(255),year INT,rate DECIMAL(5,4)); CREATE TABLE waste_generation (city VARCHAR(255),year INT,amount INT); INSERT INTO recycling_rates (city,year,rate) VALUES ('San Francisco',2021,0.35),('New York',2021,0.40),('Los Angeles',2021,0.25); INSERT INTO waste_generation (city,year,amount) VALUES ('San Francisco',2021,700000),('New York',2021,800000),('Los Angeles',2021,600000);
SELECT wg.city, r.rate FROM (SELECT city, year, SUM(amount) AS total_waste FROM waste_generation GROUP BY city, year ORDER BY total_waste DESC LIMIT 3) wg INNER JOIN recycling_rates r ON wg.city = r.city AND wg.year = r.year;
How many donations were made in the year 2020?
CREATE TABLE donations (id INT,donor_id INT,amount DECIMAL(10,2),donation_date DATE);
SELECT COUNT(*) FROM donations WHERE YEAR(donation_date) = 2020;
Identify policyholders with more than one claim in California
CREATE TABLE claims (policyholder_id INT,claim_number INT,state VARCHAR(2)); INSERT INTO claims (policyholder_id,claim_number,state) VALUES (1,1,'CA'),(1,2,'CA'),(2,1,'CA');
SELECT policyholder_id FROM claims WHERE state = 'CA' GROUP BY policyholder_id HAVING COUNT(*) > 1;
Add a column named "sustainability_rating" to the existing "hotels" table.
CREATE TABLE hotels (hotel_id INT,name VARCHAR(50),location VARCHAR(50),stars INT,sustainability_rating INT);
ALTER TABLE hotels ADD sustainability_rating INT;
What is the percentage of graduate students in the Engineering department who are international students?
CREATE TABLE students (student_id INT,name VARCHAR(50),department VARCHAR(50),is_international BOOLEAN);
SELECT (COUNT(s.student_id) * 100.0 / (SELECT COUNT(*) FROM students)) AS percentage FROM students s WHERE s.department = 'Engineering' AND s.is_international = TRUE;
How many high severity vulnerabilities were detected in the Finance department in the last quarter?
CREATE TABLE vulnerabilities (id INT,department VARCHAR(255),severity VARCHAR(255),date DATE); INSERT INTO vulnerabilities (id,department,severity,date) VALUES (1,'Finance','high','2022-01-01'),(2,'HR','medium','2022-05-15'),(3,'IT','low','2022-06-20'),(4,'Finance','high','2022-04-01'),(5,'Finance','medium','2022-03-10');
SELECT COUNT(*) FROM vulnerabilities WHERE department = 'Finance' AND severity = 'high' AND date >= DATEADD(quarter, -1, GETDATE());
Delete all garments with a carbon footprint greater than 10
CREATE TABLE CarbonFootprint (id INT,garment_id INT,material VARCHAR(255),carbon_footprint INT); INSERT INTO CarbonFootprint (id,garment_id,material,carbon_footprint) VALUES (1,1000,'Recycled Polyester',5),(2,1001,'Organic Cotton',7),(3,1002,'Recycled Polyester',6);
DELETE FROM CarbonFootprint WHERE carbon_footprint > 10;
What was the total sales revenue of a specific drug in a given year?
CREATE TABLE drugs (drug_id INT,drug_name VARCHAR(50)); INSERT INTO drugs (drug_id,drug_name) VALUES (1,'DrugA'),(2,'DrugB'); CREATE TABLE sales (sale_id INT,drug_id INT,year INT,revenue INT); INSERT INTO sales (sale_id,drug_id,year,revenue) VALUES (1,1,2020,50000),(2,1,2021,60000),(3,2,2020,45000),(4,2,2021,55000);
SELECT s.revenue FROM sales s JOIN drugs d ON s.drug_id = d.drug_id WHERE d.drug_name = 'DrugA' AND s.year = 2021;
What is the total funding received by universities in South America for ethical AI research?
CREATE TABLE Ethical_AI_Funding (University VARCHAR(50),Funding INT);
SELECT SUM(Funding) FROM Ethical_AI_Funding WHERE University IN (SELECT University FROM Ethical_AI_Funding WHERE Country IN ('Argentina', 'Brazil', 'Colombia') GROUP BY University HAVING COUNT(*) >= 2);
Determine the percentage of drought-impacted areas in Arizona?
CREATE TABLE drought_areas (area_name VARCHAR(30),state VARCHAR(20),drought_status VARCHAR(10)); CREATE TABLE drought_categories (drought_status VARCHAR(10),description VARCHAR(20));
SELECT 100.0 * COUNT(CASE WHEN da.drought_status = 'D4' THEN 1 END) / COUNT(*) as pct_drought FROM drought_areas da JOIN drought_categories dc ON da.drought_status = dc.drought_status WHERE da.state = 'Arizona';
Count the number of employees who identify as female in the "hr" schema
CREATE TABLE hr.employees (id INT,name VARCHAR(50),gender VARCHAR(10),department VARCHAR(50)); INSERT INTO hr.employees (id,name,gender,department) VALUES (1,'Jane Doe','Female','HR'); INSERT INTO hr.employees (id,name,gender,department) VALUES (2,'John Smith','Male','IT'); INSERT INTO hr.employees (id,name,gender,department) VALUES (3,'Bob Brown','Non-binary','IT');
SELECT COUNT(*) FROM hr.employees WHERE gender = 'Female';
Show the number of cultural heritage sites in each world heritage list.
CREATE TABLE heritage_sites (site_id INT,name VARCHAR(255),list VARCHAR(255)); CREATE VIEW list_summary AS SELECT list,COUNT(site_id) as site_count FROM heritage_sites GROUP BY list;
SELECT list, site_count FROM list_summary;
What is the total number of trips taken on the Moscow metro during the weekend?
CREATE TABLE metro_trips (entry_time TIME,day VARCHAR(10)); INSERT INTO metro_trips (entry_time,day) VALUES ('10:00:00','Saturday'),('12:30:00','Sunday'),('16:45:00','Saturday');
SELECT COUNT(*) FROM metro_trips WHERE day IN ('Saturday', 'Sunday');
What is the number of disaster preparedness trainings held in Boston and their respective attendance?"
CREATE TABLE boston_disaster_preparedness (id INT,training_name VARCHAR(255),city VARCHAR(255),attendance INT); INSERT INTO boston_disaster_preparedness (id,training_name,city,attendance) VALUES (1,'Earthquake Preparedness','Boston',25);
SELECT training_name, SUM(attendance) as total_attendance FROM boston_disaster_preparedness WHERE city = 'Boston' GROUP BY training_name;
What is the number of union members that are also teachers in Canada?
CREATE TABLE union_members (id INT,name VARCHAR(50),occupation VARCHAR(50),state VARCHAR(2),joined_date DATE); INSERT INTO union_members (id,name,occupation,state,joined_date) VALUES (1,'Alice Brown','Teacher','CA','2019-09-01'); INSERT INTO union_members (id,name,occupation,state,joined_date) VALUES (2,'Bob Johnson','Engineer','ON','2020-01-01'); INSERT INTO union_members (id,name,occupation,state,joined_date) VALUES (3,'Charlie Lee','Teacher','QC','2018-12-21'); INSERT INTO union_members (id,name,occupation,state,joined_date) VALUES (4,'David Kim','Nurse','BC','2019-04-10');
SELECT COUNT(*) FROM union_members WHERE occupation = 'Teacher' AND state = 'CA';
Identify the total number of VR games that support cross-platform play, and list the game names.
CREATE TABLE GameDesign (GameID INT,GameName VARCHAR(20),Platform VARCHAR(10),VR BIT,CrossPlatform BIT);
SELECT GameName FROM GameDesign WHERE VR = 1 AND CrossPlatform = 1;
How many unique genetic research patents have been filed in each country, in the past 5 years?
CREATE SCHEMA if not exists biotech; CREATE TABLE if not exists biotech.patents (id INT,name VARCHAR(50),location VARCHAR(50),filed_date DATE,industry VARCHAR(50)); INSERT INTO biotech.patents (id,name,location,filed_date,industry) VALUES (1,'PatentA','USA','2019-05-15','Genetic Research'),(2,'PatentB','Canada','2018-02-23','Bioprocess Engineering'),(3,'PatentC','USA','2017-09-01','Synthetic Biology'),(4,'PatentD','USA','2020-03-12','Genetic Research'),(5,'PatentE','Germany','2019-11-28','Genetic Research');
SELECT location, COUNT(DISTINCT id) as num_patents FROM biotech.patents WHERE industry = 'Genetic Research' AND filed_date >= DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR) GROUP BY location;
Calculate the average health score for each restaurant category in the 'fast_food' schema.
CREATE TABLE fast_food.health_inspections (restaurant_id INT,category TEXT,health_score INT); INSERT INTO fast_food.health_inspections (restaurant_id,category,health_score) VALUES (1,'Burger',90),(2,'Pizza',85),(3,'Fried Chicken',80);
SELECT category, AVG(health_score) FROM fast_food.health_inspections GROUP BY category;
What is the number of students who received accommodations for exams for each disability type?
CREATE TABLE Disability_Accommodations (Student_ID INT,Student_Name TEXT,Disability_Type TEXT,Accommodation_Type TEXT); INSERT INTO Disability_Accommodations (Student_ID,Student_Name,Disability_Type,Accommodation_Type) VALUES (1,'John Doe','Visual Impairment','Extended Time'),(2,'Jane Smith','Hearing Impairment','Sign Language Interpreting'),(3,'Michael Brown','ADHD','Extended Time');
SELECT Disability_Type, Accommodation_Type, COUNT(*) FROM Disability_Accommodations GROUP BY Disability_Type, Accommodation_Type;