instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
How many shipments arrived at port 'P03' in January 2022? | CREATE TABLE shipments (id INT,arrival_date DATE,port_id VARCHAR(5)); INSERT INTO shipments (id,arrival_date,port_id) VALUES (1001,'2022-01-03','P01'),(1002,'2022-01-15','P03'),(1003,'2022-02-01','P03'); CREATE TABLE ports (id VARCHAR(5),name VARCHAR(10)); INSERT INTO ports (id,name) VALUES ('P01','Port One'),('P02','P... | SELECT COUNT(*) FROM shipments WHERE MONTH(arrival_date) = 1 AND port_id = 'P03'; |
What is the average number of cases handled per year by attorneys with more than 5 years of experience? | CREATE TABLE Attorneys (AttorneyID INT,YearsOfExperience INT,Specialization VARCHAR(255)); INSERT INTO Attorneys (AttorneyID,YearsOfExperience,Specialization) VALUES (1,12,'Civil Law'),(2,5,'Criminal Law'),(3,8,'Family Law'),(4,15,'Family Law'); CREATE TABLE Cases (CaseID INT,AttorneyID INT,CaseOpenDate DATE,CaseCloseD... | SELECT AVG(DATEDIFF(CaseCloseDate, CaseOpenDate) / YearsOfExperience) FROM Cases JOIN Attorneys ON Cases.AttorneyID = Attorneys.AttorneyID WHERE YearsOfExperience > 5; |
What is the total energy storage capacity for each type of energy storage? | CREATE TABLE energy_storage (type VARCHAR(20),capacity INT); INSERT INTO energy_storage (type,capacity) VALUES ('Batteries',50000),('Pumped Hydro',75000),('Thermal',30000),('Flywheels',10000),('CAES',20000); | SELECT type, SUM(capacity) FROM energy_storage GROUP BY type; |
Find the total production quantity (in metric tons) of Europium for 2018 and 2019. | CREATE TABLE production_data (year INT,element TEXT,production_quantity FLOAT); INSERT INTO production_data (year,element,production_quantity) VALUES (2018,'Europium',120); INSERT INTO production_data (year,element,production_quantity) VALUES (2019,'Europium',150); INSERT INTO production_data (year,element,production_q... | SELECT SUM(production_quantity) FROM production_data WHERE element = 'Europium' AND year IN (2018, 2019); |
What is the total cargo weight for shipments to Canada in February 2021? | CREATE TABLE canada_shipments (id INT,cargo_weight INT,destination VARCHAR(20),shipment_date DATE); INSERT INTO canada_shipments (id,cargo_weight,destination,shipment_date) VALUES (1,12000,'Canada','2021-02-02'); INSERT INTO canada_shipments (id,cargo_weight,destination,shipment_date) VALUES (2,15000,'Canada','2021-02-... | SELECT SUM(cargo_weight) FROM canada_shipments WHERE destination = 'Canada' AND shipment_date >= '2021-02-01' AND shipment_date < '2021-03-01'; |
What is the average rating of artworks in the 'Impressionism' genre, excluding artworks with a rating of 0, and also show the total number of artworks in this genre? | CREATE TABLE Artwork (artwork_id INT,artwork_name VARCHAR(30),genre VARCHAR(20),rating INT); | SELECT AVG(Artwork.rating) AS avg_rating, COUNT(Artwork.artwork_id) AS total_artworks FROM Artwork WHERE Artwork.genre = 'Impressionism' AND Artwork.rating > 0; |
What is the total number of exoplanets discovered by the Kepler mission? | CREATE TABLE exoplanets (mission VARCHAR(255),count INT); INSERT INTO exoplanets (mission,count) VALUES ('Kepler',2326),('CoRoT',32),('Hubble',4),('Spitzer',7),('K2',428); | SELECT SUM(count) FROM exoplanets WHERE mission = 'Kepler'; |
Which users have been locked out of their accounts more than 3 times in the past day? | CREATE TABLE account_lockouts (id INT,user VARCHAR(255),lockout_count INT,lockout_date DATE); | SELECT user FROM account_lockouts WHERE lockout_count > 3 AND lockout_date >= DATEADD(day, -1, GETDATE()) GROUP BY user HAVING COUNT(*) > 1; |
Show the total quantity of sustainable and non-sustainable fabric types used in all clothing items. | CREATE TABLE TextileSourcing (FabricType VARCHAR(255),Quantity INT,IsSustainable BOOLEAN); INSERT INTO TextileSourcing (FabricType,Quantity,IsSustainable) VALUES ('Organic Cotton',1200,TRUE),('Recycled Polyester',800,TRUE),('Tencel',1500,TRUE),('Virgin Polyester',1000,FALSE),('Conventional Cotton',2000,FALSE); | SELECT IsSustainable, SUM(Quantity) FROM TextileSourcing GROUP BY IsSustainable; |
Create a view for the international visitor statistics by month | CREATE TABLE visitor_statistics (id INT PRIMARY KEY,country VARCHAR(50),year INT,month INT,visitors INT); | CREATE VIEW visitor_statistics_by_month AS SELECT country, year, month, SUM(visitors) AS total_visitors FROM visitor_statistics GROUP BY country, year, month; |
What is the average satisfaction score for residents aged 20-40 in each city? | CREATE TABLE Survey_Responses(City VARCHAR(20),Age INT,Satisfaction INT); INSERT INTO Survey_Responses(City,Age,Satisfaction) VALUES('Toronto',30,8); INSERT INTO Survey_Responses(City,Age,Satisfaction) VALUES('Toronto',40,7); INSERT INTO Survey_Responses(City,Age,Satisfaction) VALUES('Montreal',25,9); INSERT INTO Surve... | SELECT City, AVG(Satisfaction) FROM Survey_Responses WHERE Age BETWEEN 20 AND 40 GROUP BY City; |
Delete all records from the 'manufacturers' table where the country is 'China' | CREATE TABLE manufacturers(id INT,name VARCHAR(255),country VARCHAR(255)); INSERT INTO manufacturers(id,name,country) VALUES (1,'ABC Manufacturing','China'),(2,'XYZ Manufacturing','Bangladesh'),(3,'LMN Manufacturing','India'); | DELETE FROM manufacturers WHERE country = 'China'; |
What is the minimum and maximum quantity of ceramic artifacts at Site G? | CREATE TABLE artifact_catalog (artifact_id INT,site_id INT,artifact_type TEXT,artifact_description TEXT,quantity INT); INSERT INTO artifact_catalog (artifact_id,site_id,artifact_type,artifact_description,quantity) VALUES (1,1,'ceramic','small bowl',25),(2,1,'metal','copper pin',10),(3,1,'bone','animal figurine',15),(4,... | SELECT MIN(quantity), MAX(quantity) FROM artifact_catalog WHERE site_id = 7 AND artifact_type = 'ceramic'; |
Add a new record for a staff member into the 'staff' table | CREATE TABLE staff (id INT PRIMARY KEY,first_name VARCHAR(50),last_name VARCHAR(50),role VARCHAR(50),hire_date DATE); | INSERT INTO staff (id, first_name, last_name, role, hire_date) VALUES (1, 'John', 'Doe', 'Wildlife Biologist', '2020-01-01'); |
What is the average adoption rate of electric vehicles in each city? | CREATE TABLE City_EV_Adoption (id INT,city VARCHAR(50),ev_adoption DECIMAL(5,2)); | SELECT city, AVG(ev_adoption) FROM City_EV_Adoption GROUP BY city; |
What is the average data usage, in GB, for customers in each region, in the last 6 months? | CREATE TABLE customers (customer_id INT,name VARCHAR(50),region VARCHAR(50),data_usage FLOAT,usage_date DATE); INSERT INTO customers (customer_id,name,region,data_usage,usage_date) VALUES (1,'John Doe','North',45.6,'2022-01-01'),(2,'Jane Smith','South',30.9,'2022-02-01'),(3,'Mike Johnson','East',60.7,'2022-03-01'); CRE... | SELECT r.region_name, AVG(c.data_usage) as avg_data_usage FROM customers c JOIN regions r ON c.region = r.region_name WHERE c.usage_date >= DATEADD(month, -6, GETDATE()) GROUP BY r.region_name; |
How many cybersecurity incidents were reported by each national security agency in the 'agency_data' table? | CREATE TABLE agencies (agency VARCHAR(255)); INSERT INTO agencies (agency) VALUES ('NSA'),('CIA'),('FBI'),('CSS'); CREATE VIEW agency_data AS SELECT a.agency,d.incident_count INTEGER FROM agencies a CROSS JOIN (SELECT 10 AS incident_count UNION ALL SELECT 15 UNION ALL SELECT 20 UNION ALL SELECT 25) d; | SELECT a.agency, SUM(d.incident_count) FROM agencies a INNER JOIN agency_data d ON 1=1 GROUP BY a.agency; |
Show the names and fairness scores of models, excluding any models with a fairness score less than 0.7. | CREATE TABLE model_fairness (model_id INT,fairness_score DECIMAL(3,2)); INSERT INTO model_fairness (model_id,fairness_score) VALUES (1,0.85),(2,0.70),(3,0.92),(4,0.68),(5,0.55); | SELECT model_id, fairness_score FROM model_fairness WHERE fairness_score >= 0.7; |
What is the maximum budget allocated for waste management in the city of Tokyo? | CREATE TABLE city_services (city VARCHAR(20),service VARCHAR(20),budget INT); INSERT INTO city_services (city,service,budget) VALUES ('Tokyo','Waste Management',3000000); | SELECT MAX(budget) FROM city_services WHERE city = 'Tokyo' AND service = 'Waste Management'; |
Calculate the total production in the Niger Delta for the last 12 months. | CREATE TABLE well_production (well_id INT,measurement_date DATE,production_rate FLOAT,location TEXT); INSERT INTO well_production (well_id,measurement_date,production_rate,location) VALUES (1,'2022-01-01',500,'Niger Delta'),(2,'2022-02-01',700,'Gulf of Mexico'),(3,'2022-03-01',600,'Siberia'); | SELECT SUM(production_rate) FROM well_production WHERE location = 'Niger Delta' AND measurement_date >= DATEADD(year, -1, GETDATE()); |
Update the name of the virtual tourism platform 'VTravel' in the 'platforms' table | CREATE TABLE platforms (id INT PRIMARY KEY,name VARCHAR(255),url VARCHAR(255)); INSERT INTO platforms (id,name,url) VALUES (1,'VTravel','www.vtravel.com'); INSERT INTO platforms (id,name,url) VALUES (2,'Culture360','www.culture360.org'); | UPDATE platforms SET name = 'Virtual VTravel' WHERE name = 'VTravel'; |
What is the percentage of funding by program category in 2022? | CREATE TABLE program_categories (id INT,program_category VARCHAR(255),funding_year INT,amount DECIMAL(10,2)); | SELECT program_category, (amount / SUM(amount) OVER (PARTITION BY funding_year)) * 100 AS funding_percentage FROM program_categories WHERE funding_year = 2022 ORDER BY funding_percentage DESC; |
Find the top 3 species with the highest timber production in 'forestry' DB. | CREATE TABLE forestry.harvested_trees (id INT,species VARCHAR(50),volume FLOAT); | SELECT species, SUM(volume) AS total_volume FROM forestry.harvested_trees GROUP BY species ORDER BY total_volume DESC LIMIT 3; |
What is the total number of posts containing the hashtag #music, by users from the United Kingdom, in the last week? | CREATE TABLE users (id INT,country VARCHAR(255)); CREATE TABLE posts (id INT,user_id INT,hashtags TEXT,post_date DATE); | SELECT COUNT(*) FROM posts INNER JOIN users ON posts.user_id = users.id WHERE users.country = 'United Kingdom' AND hashtags LIKE '%#music%' AND post_date >= DATE(NOW()) - INTERVAL 1 WEEK; |
What is the maximum project cost in each region? | CREATE TABLE Projects (region VARCHAR(20),project_cost INT); INSERT INTO Projects (region,project_cost) VALUES ('Northeast',5000000),('Southeast',7000000),('Midwest',6000000),('Southwest',8000000),('West',9000000); | SELECT region, MAX(project_cost) FROM Projects GROUP BY region; |
Identify cities with only one restaurant. | CREATE TABLE Restaurants (restaurant_id INT,name TEXT,city TEXT,revenue FLOAT); INSERT INTO Restaurants (restaurant_id,name,city,revenue) VALUES (1,'Asian Fusion','New York',50000.00),(2,'Bella Italia','Los Angeles',60000.00),(3,'Sushi House','New York',70000.00),(4,'Pizzeria La Rosa','Chicago',80000.00),(5,'Taqueria E... | SELECT city FROM Restaurants GROUP BY city HAVING COUNT(*) = 1; |
Which solar plants are located in Country W? | CREATE TABLE solar_plants (name TEXT,location TEXT,capacity_MW INTEGER); INSERT INTO solar_plants (name,location,capacity_MW) VALUES ('Plant A','Country W',50),('Plant B','Country V',75),('Plant C','Country W',100); | SELECT * FROM solar_plants WHERE location = 'Country W'; |
Calculate the total quantity of eco-friendly garments produced in Vietnam in 2022. | CREATE TABLE Manufacturing (id INT,garment_type VARCHAR(20),sustainable BOOLEAN,country VARCHAR(20),quantity INT,year INT); INSERT INTO Manufacturing (id,garment_type,sustainable,country,quantity,year) VALUES (1,'Dress',TRUE,'Vietnam',300,2022),(2,'Shirt',FALSE,'Vietnam',450,2022),(3,'Pant',TRUE,'Vietnam',600,2022); | SELECT SUM(quantity) as total_quantity FROM Manufacturing WHERE sustainable = TRUE AND country = 'Vietnam' AND year = 2022; |
update the carbon_sequestration table to reflect a carbon sequestration rate of 5 tons per hectare for pine in the year 2020 | CREATE TABLE carbon_sequestration (year INT,tree_type VARCHAR(255),region VARCHAR(255),sequestration_rate FLOAT); | UPDATE carbon_sequestration SET sequestration_rate = 5 WHERE tree_type = 'Pine' AND year = 2020; |
What is the percentage of 'organic cotton' products out of the total products for each brand? | CREATE TABLE brands(brand_id INT,brand_name TEXT); INSERT INTO brands(brand_id,brand_name) VALUES (1,'BrandA'),(2,'BrandB'),(3,'BrandC'); CREATE TABLE products(product_id INT,brand_id INT,material TEXT); INSERT INTO products(product_id,brand_id,material) VALUES (1,1,'organic cotton'),(2,1,'polyester'),(3,1,'organic cot... | SELECT brand_id, brand_name, (COUNT(CASE WHEN material = 'organic cotton' THEN 1 END) * 100.0 / COUNT(*)) as percentage FROM brands b JOIN products p ON b.brand_id = p.brand_id GROUP BY brand_id, brand_name; |
What is the percentage of wastewater treated by plants in Toronto, Canada for 2019? | CREATE TABLE wastewater_treatment(plant_id INT,city VARCHAR(50),country VARCHAR(50),year INT,treated_water_volume FLOAT,total_water_volume FLOAT); INSERT INTO wastewater_treatment(plant_id,city,country,year,treated_water_volume,total_water_volume) VALUES (1,'Toronto','Canada',2019,5000000,8000000),(2,'Toronto','Canada'... | SELECT city, (SUM(treated_water_volume) / SUM(total_water_volume)) * 100 FROM wastewater_treatment WHERE city = 'Toronto' AND country = 'Canada' AND year = 2019; |
Which marine species are threatened or endangered? | CREATE TABLE conservation_status (name VARCHAR(50),status VARCHAR(50)); INSERT INTO conservation_status (name,status) VALUES ('Blue Whale','Endangered'),('Hawksbill Turtle','Critically Endangered'),('Fin Whale','Endangered'),('Leatherback Turtle','Vulnerable'),('Humpback Whale','Least Concern'); | SELECT name FROM conservation_status WHERE status = 'Endangered' OR status = 'Critically Endangered'; |
Count total mental health conditions treated across all facilities. | CREATE TABLE facilities (facility_id INT,condition VARCHAR(50)); | SELECT COUNT(DISTINCT condition) as total_conditions FROM facilities; |
What is the average energy price for the 'North' region in March 2022? | CREATE TABLE energy_prices (id INT,region VARCHAR(50),price FLOAT,date DATE); INSERT INTO energy_prices (id,region,price,date) VALUES (1,'North',55.7,'2022-03-01'); | SELECT region, AVG(price) AS avg_price FROM energy_prices WHERE date BETWEEN '2022-03-01' AND '2022-03-31' AND region = 'North' GROUP BY region; |
What is the total CO2 emissions reduction from climate adaptation projects in Asia in 2019? | CREATE TABLE adaptation_projects (country VARCHAR(50),year INT,co2_reduction FLOAT); INSERT INTO adaptation_projects (country,year,co2_reduction) VALUES ('China',2019,1200000),('India',2019,1500000); | SELECT SUM(co2_reduction) FROM adaptation_projects WHERE country IN ('China', 'India') AND year = 2019; |
What is the average cultural competency score for mental health providers who work in urban areas, and how many of them have a score above 80? | CREATE TABLE mental_health_providers (id INT,name VARCHAR(50),location VARCHAR(50),cultural_competency_score INT); INSERT INTO mental_health_providers (id,name,location,cultural_competency_score) VALUES (1,'Dr. Jane Doe','Urban',85),(2,'Dr. John Smith','Suburban',70),(3,'Dr. Maria Garcia','Urban',90),(4,'Dr. Pedro Rodr... | SELECT AVG(cultural_competency_score), COUNT(*) FROM mental_health_providers WHERE location = 'Urban' AND cultural_competency_score > 80; |
How many tourists visited New Zealand in each month of 2022? | CREATE TABLE tourism_data (id INT,country TEXT,visit_date DATE); INSERT INTO tourism_data (id,country,visit_date) VALUES (1,'New Zealand','2022-01-01'),(2,'New Zealand','2022-02-15'),(3,'Australia','2022-03-01'); | SELECT visit_date, COUNT(*) AS num_visitors FROM tourism_data WHERE country = 'New Zealand' AND visit_date BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY visit_date; |
What was the total cost of the construction projects in the city of Seattle in 2020? | CREATE TABLE construction_projects (id INT PRIMARY KEY,city VARCHAR(255),state VARCHAR(255),total_cost FLOAT); | SELECT SUM(total_cost) FROM construction_projects WHERE city = 'Seattle' AND YEAR(project_start_date) = 2020; |
What is the average age of readers who prefer technology news in Brazil? | CREATE TABLE reader_demographics (id INT,age INT,country VARCHAR(50),topic VARCHAR(50)); INSERT INTO reader_demographics (id,age,country,topic) VALUES (1,35,'Brazil','Technology'); INSERT INTO reader_demographics (id,age,country,topic) VALUES (2,42,'Canada','Politics'); | SELECT AVG(age) FROM reader_demographics WHERE country = 'Brazil' AND topic = 'Technology'; |
Identify the total number of countries with military equipment purchases from the US in the last 18 months | CREATE TABLE military_equipment_sales (country TEXT,sale_date DATE); INSERT INTO military_equipment_sales (country,sale_date) VALUES ('Canada','2021-07-15'),('Australia','2022-02-03'),('Germany','2021-12-21'),('Japan','2022-03-09'),('Mexico','2022-06-17'),('Brazil','2022-02-28'),('South Korea','2022-04-05'),('India','2... | SELECT COUNT(DISTINCT country) as unique_countries FROM military_equipment_sales WHERE sale_date >= (SELECT CURRENT_DATE - INTERVAL '18 months'); |
What is the total number of unique marine species observed by expeditions for the 'Marine Investigators' organization? | CREATE TABLE expedition (org VARCHAR(20),species VARCHAR(50)); INSERT INTO expedition VALUES ('Ocean Explorer','Dolphin'),('Ocean Explorer','Tuna'),('Sea Discoverers','Shark'),('Sea Discoverers','Whale'),('Marine Investigators','Starfish'),('Marine Investigators','Jellyfish'),('Marine Investigators','Coral'),('Deep Sea... | SELECT COUNT(DISTINCT species) FROM expedition WHERE org = 'Marine Investigators'; |
Which materials in the 'inventory' table have a quantity of at least 100 and are used in the production of at least one product in the 'products' table? | CREATE TABLE inventory(id INT,material VARCHAR(255),quantity INT); CREATE TABLE products(id INT,material VARCHAR(255),quantity INT); INSERT INTO inventory(id,material,quantity) VALUES (1,'organic cotton',75),(2,'conventional cotton',100),(3,'organic cotton',30),(4,'hemp',60); INSERT INTO products(id,material,quantity) ... | SELECT i.material FROM inventory i INNER JOIN products p ON i.material = p.material WHERE i.quantity >= 100; |
Update the country of a supplier in the "suppliers" table | CREATE TABLE suppliers (supplier_id INT,name VARCHAR(255),country VARCHAR(255),ethical_certification VARCHAR(255)); | UPDATE suppliers SET country = 'Colombia' WHERE supplier_id = 2001; |
List all cultural competency policies in California. | CREATE TABLE CulturalCompetency (id INT,policy_name TEXT,state TEXT); INSERT INTO CulturalCompetency (id,policy_name,state) VALUES (1,'Diversity Act 2020','California'); INSERT INTO CulturalCompetency (id,policy_name,state) VALUES (2,'Inclusion Act 2018','California'); | SELECT * FROM CulturalCompetency WHERE state = 'California'; |
Which climate adaptation sectors received the least funding in North America? | CREATE TABLE climate_adaptation_sectors (project_id INT,sector TEXT,region TEXT,amount FLOAT); INSERT INTO climate_adaptation_sectors (project_id,sector,region,amount) VALUES (1,'Coastal Protection','North America',1000000); INSERT INTO climate_adaptation_sectors (project_id,sector,region,amount) VALUES (2,'Water Manag... | SELECT sector, MIN(amount) FROM climate_adaptation_sectors WHERE region = 'North America' GROUP BY sector; |
What is the total donation amount and average donation amount for each cause? | CREATE TABLE Causes (Cause TEXT); CREATE TABLE Donations (DonationID INT,DonationAmount INT,Cause TEXT); INSERT INTO Causes (Cause) VALUES ('Environment'),('Health'),('Education'); INSERT INTO Donations (DonationID,DonationAmount,Cause) VALUES (1,5000,'Environment'),(2,7000,'Health'),(3,3000,'Environment'),(4,8000,'Edu... | SELECT Cause, SUM(DonationAmount) AS TotalDonationAmount, AVG(DonationAmount) AS AverageDonationAmount FROM Donations GROUP BY Cause; |
Calculate the total cost of materials for each aircraft model, including joined data from the 'aircraft_manufacturing' and 'material_costs' tables. | CREATE TABLE aircraft_manufacturing (model VARCHAR(50),quantity INT); INSERT INTO aircraft_manufacturing (model,quantity) VALUES ('F-35',1200),('F-16',800),('F-22',400); CREATE TABLE material_costs (model VARCHAR(50),cost DECIMAL(10,2)); INSERT INTO material_costs (model,cost) VALUES ('F-35',120000.00),('F-16',80000.00... | SELECT am.model, SUM(mc.cost * am.quantity) AS total_cost FROM aircraft_manufacturing am INNER JOIN material_costs mc ON am.model = mc.model GROUP BY am.model; |
What is the average number of tickets sold for soccer matches per season? | CREATE TABLE soccer_matches (match_id INT,season INT,tickets_sold INT); INSERT INTO soccer_matches (match_id,season,tickets_sold) VALUES (1,2018,25000),(2,2018,28000),(3,2019,32000); | SELECT AVG(tickets_sold) FROM soccer_matches GROUP BY season; |
What is the average daily budget for ad sets grouped by campaign title? | CREATE TABLE ad_campaigns (id INT,title VARCHAR(50),objective VARCHAR(50),budget DECIMAL(10,2),start_date DATE,end_date DATE); INSERT INTO ad_campaigns (id,title,objective,budget,start_date,end_date) VALUES (1,'Sample Campaign','Awareness',5000,'2021-07-01','2021-07-31'),(2,'Another Campaign','Consideration',7000,'2021... | SELECT ad_campaigns.title, AVG(ad_sets.daily_budget) as avg_daily_budget FROM ad_campaigns JOIN ad_sets ON ad_campaigns.id = ad_sets.campaign_id GROUP BY ad_campaigns.title; |
What is the minimum and maximum sea ice extent in the Arctic Ocean for each month in 2021? | CREATE TABLE SeaIceExtent (id INT,month INT,extent DECIMAL(5,2),date DATE); INSERT INTO SeaIceExtent (id,month,extent,date) VALUES (1,1,14.5,'2021-01-01'); INSERT INTO SeaIceExtent (id,month,extent,date) VALUES (2,12,11.0,'2021-12-31'); | SELECT month, MIN(extent) AS min_extent, MAX(extent) AS max_extent FROM SeaIceExtent WHERE date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY month; |
Delete records of artists who have not participated in any programs. | CREATE TABLE Artists (artist_id INT,artist_name VARCHAR(255),community_identifier VARCHAR(255)); CREATE TABLE ArtistPrograms (program_id INT,artist_id INT,participant_role VARCHAR(255)); | DELETE FROM Artists WHERE artist_id NOT IN (SELECT artist_id FROM ArtistPrograms); |
What is the total budget for all AI for good projects in Asia in 2021? | CREATE TABLE ai_for_good (id INT,region VARCHAR(255),year INT,budget DECIMAL(10,2)); INSERT INTO ai_for_good (id,region,year,budget) VALUES (1,'Asia',2021,400000.00); INSERT INTO ai_for_good (id,region,year,budget) VALUES (2,'Europe',2021,500000.00); | SELECT SUM(budget) FROM ai_for_good WHERE region = 'Asia' AND year = 2021; |
What are the names of the military branches in the 'Military_Branches' table? | CREATE TABLE Military_Branches (id INT,branch VARCHAR(50)); INSERT INTO Military_Branches (id,branch) VALUES (1,'Army'); INSERT INTO Military_Branches (id,branch) VALUES (2,'Navy'); | SELECT DISTINCT branch FROM Military_Branches; |
Delete all records of materials with CO2 emissions greater than 3000 for brands operating in India. | CREATE TABLE brands (brand_id INT,brand_name TEXT,country TEXT); INSERT INTO brands (brand_id,brand_name,country) VALUES (1,'EcoBrand','India'),(2,'GreenFashion','France'),(3,'SustainableStyle','USA'); CREATE TABLE material_usage (brand_id INT,material_type TEXT,quantity INT,co2_emissions INT); INSERT INTO material_usa... | DELETE mu FROM material_usage mu JOIN brands b ON mu.brand_id = b.brand_id WHERE b.country = 'India' AND mu.co2_emissions > 3000; |
List all visitors who have not attended any exhibition | CREATE TABLE Visitors (id INT,age INT,gender VARCHAR(255)); CREATE TABLE Tickets (id INT,visitor_id INT,exhibition_id INT); | SELECT Visitors.id, Visitors.age, Visitors.gender FROM Visitors LEFT JOIN Tickets ON Visitors.id = Tickets.visitor_id WHERE Tickets.id IS NULL; |
What is the total amount of donations in the last 6 months? | CREATE TABLE Donations (DonationID INT,DonationDate DATE,DonationAmount DECIMAL(10,2)); INSERT INTO Donations (DonationID,DonationDate,DonationAmount) VALUES (1,'2022-01-01',100.00),(2,'2022-02-15',200.00),(3,'2022-03-30',300.00),(4,'2022-04-15',400.00),(5,'2022-05-30',500.00),(6,'2022-06-15',600.00); | SELECT SUM(DonationAmount) FROM Donations WHERE DonationDate >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH); |
Which organizations are part of the 'Environment' category and have more than 1000 hours of volunteer work? | CREATE TABLE organizations (id INT,name VARCHAR(50),category VARCHAR(20)); CREATE TABLE volunteer_events (id INT,organization_id INT,volunteer_hours DECIMAL(10,2)); INSERT INTO organizations (id,name,category) VALUES (1,'Green Earth','Environment'),(2,'Healthy Lives','Health'),(3,'Arts Alive','Arts & Culture'),(4,'Clea... | SELECT name FROM organizations JOIN volunteer_events ON organizations.id = volunteer_events.organization_id WHERE category = 'Environment' AND volunteer_hours > 1000; |
Insert new biosensor data for a specific project | CREATE TABLE biosensors (id INT PRIMARY KEY,project_id INT,name VARCHAR(255),type VARCHAR(255),FOREIGN KEY (project_id) REFERENCES biosensor_projects(id)); INSERT INTO biosensors (id,project_id,name,type) VALUES (1,1,'pH Sensor','Electrochemical'),(2,1,'Dissolved Oxygen Sensor','Optical'); | INSERT INTO biosensors (id, project_id, name, type) VALUES (3, 2, 'Temperature Sensor', 'Thermistor'); |
What is the average temperature and humidity in France and Germany in June? | CREATE TABLE WeatherData (location VARCHAR(255),date DATE,temperature INT,humidity INT); INSERT INTO WeatherData (location,date,temperature,humidity) VALUES ('Paris','2022-06-01',20,60),('Paris','2022-06-02',22,55),('Berlin','2022-06-01',18,70),('Berlin','2022-06-02',20,65); | SELECT AVG(temperature) as Avg_Temperature, AVG(humidity) as Avg_Humidity FROM WeatherData WHERE location IN ('France', 'Germany') AND date BETWEEN '2022-06-01' AND '2022-06-30'; |
What is the total number of 'Language Access' trainings conducted for community health workers? | CREATE TABLE community_health_workers (id INT,name VARCHAR(50),ethnicity VARCHAR(50),certification BOOLEAN); INSERT INTO community_health_workers (id,name,ethnicity,certification) VALUES (1,'Charlene','Hispanic',true),(2,'Derek','Asian',false); CREATE TABLE cultural_competency_trainings (id INT,worker_id INT,type VARCH... | SELECT COUNT(*) FROM cultural_competency_trainings WHERE type = 'Language Access' AND worker_id IN (SELECT id FROM community_health_workers); |
What is the change in production volume per product, per day, for the past month? | CREATE TABLE ProductionVolumes (Product VARCHAR(50),Volume INT,Timestamp DATETIME); INSERT INTO ProductionVolumes (Product,Volume,Timestamp) VALUES ('ProductA',500,'2022-02-01 00:00:00'),('ProductB',600,'2022-02-01 00:00:00'); | SELECT Product, LAG(Volume) OVER (PARTITION BY Product ORDER BY Timestamp) - Volume AS VolumeChange FROM ProductionVolumes WHERE Timestamp >= DATEADD(day, -30, CURRENT_TIMESTAMP) |
Calculate the revenue by dish type. | CREATE TABLE orders (id INT,dish_id INT,dish_type TEXT,price FLOAT); INSERT INTO orders (id,dish_id,dish_type,price) VALUES (1,1,'vegetarian',7.50),(2,3,'non-vegetarian',11.25),(3,2,'vegetarian',8.95),(4,1,'vegetarian',7.50),(5,4,'vegan',9.75),(6,5,'vegan',10.50),(7,2,'vegetarian',8.95),(8,1,'vegetarian',7.50); | SELECT dish_type, SUM(price) FROM orders GROUP BY dish_type; |
Find the average CO2 emissions of the top 5 cities with the highest emissions in the agriculture sector. | CREATE TABLE emissions (city VARCHAR(20),sector VARCHAR(20),co2_emissions INT); INSERT INTO emissions (city,sector,co2_emissions) VALUES ('CityA','agriculture',1200),('CityB','agriculture',1500),('CityC','agriculture',800),('CityD','agriculture',2000),('CityE','agriculture',1700),('CityF','agriculture',900); | SELECT AVG(co2_emissions) FROM (SELECT * FROM emissions WHERE sector = 'agriculture' ORDER BY co2_emissions DESC LIMIT 5); |
What is the total budget allocated for public transportation in the state of New York in the last 3 years, ordered by allocation date in ascending order? | CREATE TABLE PublicTransportation (TransportID INT,State VARCHAR(255),Type VARCHAR(255),AllocationDate DATE,Budget DECIMAL(10,2)); INSERT INTO PublicTransportation (TransportID,State,Type,AllocationDate,Budget) VALUES (1,'New York','Bus','2020-01-01',100000.00),(2,'New York','Train','2018-01-01',200000.00); | SELECT SUM(Budget), AllocationDate FROM PublicTransportation WHERE State = 'New York' AND AllocationDate >= DATEADD(year, -3, GETDATE()) GROUP BY AllocationDate ORDER BY AllocationDate ASC; |
Delete all posts with less than 50 likes and from users not in the 'verified' group. | CREATE TABLE users (user_id INT,group VARCHAR(20)); INSERT INTO users (user_id,group) VALUES (1,'verified'),(2,'unverified'); CREATE TABLE posts (post_id INT,user_id INT,likes INT); INSERT INTO posts (post_id,user_id,likes) VALUES (1,1,100),(2,1,20),(3,2,50); | DELETE FROM posts WHERE likes < 50 AND user_id NOT IN (SELECT user_id FROM users WHERE group = 'verified'); |
How many cases were handled by attorneys who passed the bar in 2010? | CREATE TABLE attorneys (attorney_id INT,bar_year INT); INSERT INTO attorneys (attorney_id,bar_year) VALUES (1,2005),(2,2010),(3,2008); CREATE TABLE cases (case_id INT,attorney_id INT); INSERT INTO cases (case_id,attorney_id) VALUES (1,1),(2,2),(3,3); | SELECT COUNT(*) FROM attorneys INNER JOIN cases ON attorneys.attorney_id = cases.attorney_id WHERE attorneys.bar_year = 2010; |
Which programs received donations from the most zip codes in the US in 2020? | CREATE TABLE DonationsByZip (DonationID int,DonorZip varchar(10),ProgramID int); INSERT INTO DonationsByZip (DonationID,DonorZip,ProgramID) VALUES (1,'10001',1); INSERT INTO DonationsByZip (DonationID,DonorZip,ProgramID) VALUES (2,'90001',2); | SELECT ProgramName, COUNT(DISTINCT DonorZip) as ZipCodes FROM DonationsByZip DBZ JOIN Programs P ON DBZ.ProgramID = P.ProgramID WHERE DonationDate BETWEEN '2020-01-01' AND '2020-12-31' AND DonorZip LIKE '______' GROUP BY ProgramName ORDER BY ZipCodes DESC, ProgramName ASC; |
List the job titles with the highest average salary and the number of employees in that role. | CREATE TABLE roles (role_id INT,role_title VARCHAR(255),salary INT); INSERT INTO roles (role_id,role_title,salary) VALUES (1,'Manager',70000),(2,'Developer',60000),(3,'Tester',50000); CREATE TABLE employees_roles (emp_id INT,role_id INT); INSERT INTO employees_roles (emp_id,role_id) VALUES (1,1),(2,2),(3,2),(4,3); | SELECT r.role_title, AVG(r.salary) as avg_salary, COUNT(e.emp_id) as num_employees FROM roles r JOIN employees_roles er ON r.role_id = er.role_id JOIN employees e ON er.emp_id = e.emp_id GROUP BY r.role_title ORDER BY avg_salary DESC, num_employees DESC LIMIT 1; |
Delete the record for 'Startup A'. | CREATE TABLE biotech_startups (id INT,name VARCHAR(100),location VARCHAR(100),funding FLOAT); INSERT INTO biotech_startups (id,name,location,funding) VALUES (1,'Startup A','India',12000000); INSERT INTO biotech_startups (id,name,location,funding) VALUES (2,'Startup B','India',18000000); INSERT INTO biotech_startups (id... | DELETE FROM biotech_startups WHERE name = 'Startup A'; |
What is the average protein count for all products in the nutrition_facts table? | CREATE TABLE nutrition_facts (product_id VARCHAR(255),calories INT,protein INT,fat INT); | SELECT AVG(protein) FROM nutrition_facts; |
What is the maximum water consumption in Texas for the years 2018 and 2019? | CREATE TABLE water_consumption (id INT,state VARCHAR(20),year INT,consumption FLOAT); INSERT INTO water_consumption (id,state,year,consumption) VALUES (1,'California',2020,120.5),(2,'California',2019,115.3),(3,'Texas',2020,200.0),(4,'Texas',2019,195.5),(5,'Texas',2018,190.0); | SELECT MAX(consumption) FROM water_consumption WHERE state = 'Texas' AND year IN (2018, 2019); |
What are the total sales and average product price for each product subcategory in New York for the year 2019? | CREATE TABLE products (id INT,name TEXT,subcategory TEXT,category TEXT); INSERT INTO products (id,name,subcategory,category) VALUES (1,'Product X','Subcategory A','Category A'); INSERT INTO products (id,name,subcategory,category) VALUES (2,'Product Y','Subcategory B','Category B'); CREATE TABLE sales (product_id INT,ye... | SELECT p.subcategory, p.category, SUM(s.sales) as total_sales, AVG(s.price) as average_price FROM products p INNER JOIN sales s ON p.id = s.product_id WHERE p.name = 'New York' AND s.year = 2019 GROUP BY p.subcategory, p.category; |
What is the average salary of nurses working in rural areas of Texas? | CREATE TABLE salary (salary_id INT,professional VARCHAR(50),salary INT,location VARCHAR(20)); INSERT INTO salary (salary_id,professional,salary,location) VALUES (1,'Nurse',60000,'Rural Texas'); INSERT INTO salary (salary_id,professional,salary,location) VALUES (2,'Doctor',120000,'Rural Texas'); | SELECT AVG(salary) FROM salary WHERE professional = 'Nurse' AND location = 'Rural Texas'; |
How many electric vehicle charging stations are there in the Central region? | CREATE TABLE stations (id INT,region VARCHAR(20),type VARCHAR(20),count INT); INSERT INTO stations (id,region,type,count) VALUES (1,'Central','EV Charging',200); INSERT INTO stations (id,region,type,count) VALUES (2,'Northern','Bike Sharing',300); | SELECT COUNT(*) FROM stations WHERE region = 'Central' AND type = 'EV Charging'; |
What is the average attendance for each program in the 'community_education' table, grouped by the program and sorted by the average attendance in descending order? | CREATE TABLE community_education (id INT,program VARCHAR(255),attendance INT); INSERT INTO community_education (id,program,attendance) VALUES (1,'Biodiversity',30),(2,'Climate Change',40),(3,'Habitat Restoration',60); | SELECT program, AVG(attendance) as avg_attendance FROM community_education GROUP BY program ORDER BY avg_attendance DESC; |
What is the maximum depth of any marine life research station in the Atlantic region? | CREATE TABLE marine_life_research_stations (id INT,name VARCHAR(255),region VARCHAR(255),depth FLOAT); | SELECT MAX(depth) FROM marine_life_research_stations WHERE region = 'Atlantic'; |
How many patients have not received any treatment so far? | CREATE TABLE patients (patient_id INT,treated BOOLEAN); INSERT INTO patients (patient_id,treated) VALUES (1,TRUE),(2,FALSE),(3,FALSE); | SELECT COUNT(*) FROM patients WHERE treated = FALSE; |
What is the total quantity of ingredients used in dishes offered at lunch? | CREATE TABLE Dishes (DishID INT,Name VARCHAR(50),Meal VARCHAR(50),Quantity INT); INSERT INTO Dishes (DishID,Name,Meal,Quantity) VALUES (1,'Spaghetti Bolognese','Lunch',500),(2,'Caesar Salad','Lunch',300); | SELECT SUM(d.Quantity) FROM Dishes d WHERE d.Meal = 'Lunch'; |
Which traditional arts programs in 'Africa' have a budget greater than the average budget for all traditional arts programs in the database? | CREATE TABLE traditional_arts_programs (id INT,name VARCHAR(50),budget INT,location VARCHAR(50)); INSERT INTO traditional_arts_programs (id,name,budget,location) VALUES (1,'Kenyan Tribal Dance',7000,'Africa'),(2,'Nigerian Mask Making',8000,'Africa'),(3,'South African Beadwork',6000,'Africa'),(4,'Egyptian Puppetry',9000... | SELECT name, budget FROM traditional_arts_programs WHERE budget > (SELECT AVG(budget) FROM traditional_arts_programs) AND location = 'Africa'; |
List the team_name and total_points of the top 5 teams with the highest total_points in hockey_games. | CREATE TABLE hockey_teams (team_id INT,team_name VARCHAR(50));CREATE TABLE hockey_games (game_id INT,home_team_id INT,away_team_id INT,home_team_points INT,away_team_points INT); | SELECT hockey_teams.team_name, SUM(home_team_points + away_team_points) AS total_points FROM hockey_games JOIN hockey_teams ON hockey_games.home_team_id = hockey_teams.team_id GROUP BY hockey_teams.team_name ORDER BY total_points DESC LIMIT 5; |
What is the latest cargo handling time in the 'handling_events' table? | CREATE TABLE handling_events (event_id INT,port_id INT,event_time TIME); INSERT INTO handling_events (event_id,port_id,event_time) VALUES (1,1,'12:30:00'),(2,2,'10:00:00'),(3,3,'14:00:00'),(4,1,'16:00:00'),(5,2,'18:00:00'); | SELECT MAX(event_time) FROM handling_events; |
Find the top 2 countries with the lowest algorithmic fairness ratings? | CREATE TABLE fairness_ratings (country VARCHAR(255),rating FLOAT); INSERT INTO fairness_ratings (country,rating) VALUES ('Country4',0.75); INSERT INTO fairness_ratings (country,rating) VALUES ('Country5',0.62); INSERT INTO fairness_ratings (country,rating) VALUES ('Country6',0.88); | SELECT country, rating, ROW_NUMBER() OVER (ORDER BY rating ASC) as rank FROM fairness_ratings WHERE rank <= 2; |
What is the minimum salary of non-binary employees in the engineering department? | CREATE TABLE Employees (EmployeeID INT,Gender VARCHAR(20),Department VARCHAR(30),Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID,Gender,Department,Salary) VALUES (3,'Non-binary','Engineering',80000.00); | SELECT MIN(Salary) FROM Employees WHERE Gender = 'Non-binary' AND Department = 'Engineering'; |
How many users have logged workouts in each state? | CREATE SCHEMA fitness; CREATE TABLE users (id INT,user_name VARCHAR(255),state VARCHAR(255)); CREATE TABLE workouts (id INT,user_id INT,workout_date DATE); | SELECT users.state, COUNT(DISTINCT users.id) FROM fitness.users INNER JOIN fitness.workouts ON users.id = workouts.user_id GROUP BY users.state; |
Update biosensor accuracy if the related biosensor type is 'Optical'. | CREATE TABLE biosensors (id INT,name VARCHAR(50),type VARCHAR(50),accuracy FLOAT); CREATE TABLE biosensor_types (id INT,type VARCHAR(50),accuracy_bonus FLOAT); INSERT INTO biosensors (id,name,type,accuracy) VALUES (1,'BioSen1','Optical',0.96),(2,'BioSen2','Electrochemical',0.94),(3,'BioSen3','Magnetic',0.98); INSERT IN... | UPDATE biosensors b SET b.accuracy = b.accuracy + bt.accuracy_bonus FROM biosensors b INNER JOIN biosensor_types bt ON b.type = bt.type WHERE b.type = 'Optical'; |
Who is the customer with the highest total cost of orders in the month of October 2021? | CREATE TABLE Customers (customer_id INT,first_name VARCHAR(15),last_name VARCHAR(15)); CREATE TABLE Orders (order_id INT,customer_id INT,order_date DATE); CREATE TABLE Order_Items (order_item_id INT,order_id INT,menu_id INT,quantity INT); CREATE TABLE Menu (menu_id INT,menu_name VARCHAR(20),is_vegetarian BOOLEAN); CREA... | SELECT Customers.first_name, Customers.last_name, SUM(Inventory.inventory_cost * Order_Items.quantity) AS total_cost FROM Customers INNER JOIN Orders ON Customers.customer_id = Orders.customer_id INNER JOIN Order_Items ON Orders.order_id = Order_Items.order_id INNER JOIN Menu ON Order_Items.menu_id = Menu.menu_id INNER... |
What is the average number of research grants awarded per year to graduate programs in the 'computer science' discipline? | CREATE TABLE graduate_programs (program_id INT,program_name VARCHAR(50),discipline VARCHAR(50)); INSERT INTO graduate_programs (program_id,program_name,discipline) VALUES (1,'Data Science','computer science'),(2,'Software Engineering','computer science'); CREATE TABLE research_grants (grant_id INT,program_id INT,grant_... | SELECT discipline, AVG(grant_amount / DATEDIFF(year, grant_date, LEAD(grant_date) OVER (PARTITION BY program_id ORDER BY grant_date))) as avg_grants_per_year FROM graduate_programs JOIN research_grants ON graduate_programs.program_id = research_grants.program_id WHERE discipline = 'computer science' GROUP BY discipline... |
Who are the top 3 contract creators with the highest total transaction fees? | CREATE TABLE contract_creators (creator_id INT,creator_name VARCHAR(50),total_contracts INT,total_fees INT); INSERT INTO contract_creators (creator_id,creator_name,total_contracts,total_fees) VALUES (1,'Oceanus',15,5000),(2,'Neptune',10,7000),(3,'Poseidon',20,3000),(4,'Atlas',8,6000); | SELECT creator_name, SUM(total_fees) FROM contract_creators GROUP BY creator_name ORDER BY SUM(total_fees) DESC LIMIT 3; |
What is the total number of green buildings in Asia? | CREATE TABLE Green_Buildings (id INT,region VARCHAR(20),number_of_buildings INT); INSERT INTO Green_Buildings (id,region,number_of_buildings) VALUES (1,'Europe',5000),(2,'Asia',7000),(3,'Africa',3000); | SELECT SUM(number_of_buildings) FROM Green_Buildings WHERE region = 'Asia'; |
What is the maximum amount of funding received by a company founded by a founder from the Middle East? | CREATE TABLE company (id INT,name TEXT,founding_date DATE,industry TEXT,headquarters TEXT,middle_eastern_founder BOOLEAN); CREATE TABLE funding_rounds (id INT,company_id INT,funding_amount INT,round_type TEXT,date DATE); | SELECT MAX(funding_amount) FROM funding_rounds JOIN company ON funding_rounds.company_id = company.id WHERE middle_eastern_founder = TRUE; |
Delete records of products with outdated safety certifications. | CREATE TABLE products (id INT,product_name TEXT,safety_certified BOOLEAN); INSERT INTO products (id,product_name,safety_certified) VALUES (1,'Product A',FALSE),(2,'Product B',TRUE),(3,'Product C',FALSE); | DELETE FROM products WHERE safety_certified = FALSE; |
Find the total rainfall in millimeters for each province in the 'rainfall_data_2022' table. | CREATE TABLE rainfall_data_2022 (id INT,province VARCHAR(20),rainfall DECIMAL(5,2)); INSERT INTO rainfall_data_2022 (id,province,rainfall) VALUES (1,'Alberta',55.2),(2,'British Columbia',72.6),(3,'Alberta',39.8); | SELECT province, SUM(rainfall) FROM rainfall_data_2022 GROUP BY province; |
List all baseball players who are older than 30, along with their team names. | CREATE TABLE players (id INT PRIMARY KEY,name VARCHAR(50),age INT,sport VARCHAR(20),team VARCHAR(30)); INSERT INTO players (id,name,age,sport,team) VALUES (1,'Mike Trout',30,'Baseball','Angels'),(2,'Albert Pujols',42,'Baseball','Cardinals'); | SELECT players.name, players.team FROM players WHERE players.age > 30 AND players.sport = 'Baseball'; |
Find the number of unique donors who have made donations in the effective altruism sector, but not in the impact investing sector. | CREATE TABLE effective_altruism (donor_id INT,donation_amount DECIMAL(10,2),donation_date DATE); INSERT INTO effective_altruism VALUES (1,25000,'2020-01-01'),(2,30000,'2020-02-01'),(3,15000,'2020-03-01'); CREATE TABLE impact_investing (donor_id INT,donation_amount DECIMAL(10,2),donation_date DATE); INSERT INTO impact_i... | SELECT COUNT(DISTINCT effective_altruism.donor_id) FROM effective_altruism LEFT JOIN impact_investing ON effective_altruism.donor_id = impact_investing.donor_id WHERE impact_investing.donor_id IS NULL; |
Summarize production data for a reservoir | CREATE TABLE production_data (reservoir_id INT,year INT,production FLOAT); INSERT INTO production_data (reservoir_id,year,production) VALUES (1,2015,50),(1,2016,55),(2,2015,100),(2,2016,120); | SELECT reservoir_id, SUM(production) FROM production_data GROUP BY reservoir_id HAVING reservoir_id = 1; |
Insert a new safety protocol for 'Ammonia' in the "safety_protocols" table | CREATE TABLE safety_protocols (id INT PRIMARY KEY,chemical_name VARCHAR(255),safety_protocol VARCHAR(255),date_implemented DATE); | INSERT INTO safety_protocols (id, chemical_name, safety_protocol, date_implemented) VALUES (1, 'Ammonia', 'Always wear safety goggles when handling', '2022-01-01'); |
What is the average workplace safety score per region for the year 2021, based on the 'workplace_safety_scores_2021' table? | CREATE TABLE workplace_safety_scores_2021 (id INT,region VARCHAR(255),score FLOAT); INSERT INTO workplace_safety_scores_2021 (id,region,score) VALUES (1,'Northeast',90.5),(2,'Southeast',85.3),(3,'Midwest',88.7); | SELECT region, AVG(score) as avg_score FROM workplace_safety_scores_2021 GROUP BY region; |
Find the distinct AI algorithms used in fairness-related research by UK authors. | CREATE TABLE fairness_research (id INT,author VARCHAR(50),country VARCHAR(50),algorithm VARCHAR(50),description TEXT); INSERT INTO fairness_research (id,author,country,algorithm,description) VALUES (1,'Alice Johnson','UK','Algorithm A','Description A'),(2,'Bob Brown','UK','Algorithm B','Description B'); | SELECT DISTINCT algorithm FROM fairness_research WHERE country = 'UK'; |
What is the policy retention rate for policyholders from Japan, calculated as the percentage of policyholders who renewed their policies after the first year? | CREATE TABLE Policyholders (PolicyholderID INT,Country VARCHAR(50),FirstYear BOOLEAN,Renewed BOOLEAN); INSERT INTO Policyholders VALUES (1,'Japan',TRUE,TRUE); INSERT INTO Policyholders VALUES (2,'Japan',TRUE,FALSE); | SELECT COUNT(*) * 100.0 / SUM(CASE WHEN FirstYear THEN 1 ELSE 0 END) AS PolicyRetentionRate FROM Policyholders WHERE Country = 'Japan'; |
Display the number of menu items for each restaurant and the percentage of menu items that are vegetarian. | CREATE TABLE Restaurants (RestaurantID int,RestaurantName varchar(255)); CREATE TABLE MenuItems (MenuID int,MenuName varchar(255),RestaurantID int,IsVegetarian bit); | SELECT R.RestaurantName, COUNT(MI.MenuID) as MenuItemCount, (COUNT(MI.MenuID) * 100.0 / (SELECT COUNT(*) FROM MenuItems WHERE RestaurantID = R.RestaurantID)) as VegetarianPercentage FROM Restaurants R INNER JOIN MenuItems MI ON R.RestaurantID = MI.RestaurantID GROUP BY R.RestaurantID; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.