instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
Delete all records of species from the 'species' table which have a population less than 1000 and are from the 'Atlantic Ocean' region. | CREATE TABLE species (species_name TEXT,population INTEGER,region TEXT); INSERT INTO species (species_name,population,region) VALUES ('Blue Whale',1200,'Atlantic Ocean'),('Tuna',15000,'Pacific Ocean'); | DELETE FROM species WHERE population < 1000 AND region = 'Atlantic Ocean'; |
What is the total number of cases for each justice category in a given year and their resolution status? | CREATE TABLE CasesByJusticeCategory (Year INT,Category TEXT,Resolution TEXT,TotalCases INT); INSERT INTO CasesByJusticeCategory (Year,Category,Resolution,TotalCases) VALUES (2020,'Civil','Resolved',500),(2020,'Civil','Unresolved',250),(2020,'Criminal','Resolved',1000),(2020,'Criminal','Unresolved',500),(2021,'Civil','Resolved',600),(2021,'Civil','Unresolved',300),(2021,'Criminal','Resolved',1200),(2021,'Criminal','Unresolved',600); | SELECT Category, Resolution, SUM(TotalCases) FROM CasesByJusticeCategory GROUP BY Category, Resolution; |
What is the average playtime of the top 3 players in the VR game 'Beat Saber'? | CREATE TABLE vr_games_3 (id INT,player TEXT,game TEXT,playtime INT,rank INT); INSERT INTO vr_games_3 (id,player,game,playtime,rank) VALUES (1,'Alice','Beat Saber',120,1),(2,'Bob','Beat Saber',100,2),(3,'Eva','Beat Saber',150,3),(4,'Fred','Beat Saber',80,4); | SELECT AVG(playtime) FROM vr_games_3 WHERE game = 'Beat Saber' AND rank <= 3; |
What is the total number of employees who identify as female or non-binary? | CREATE TABLE Employees (EmployeeID INT,Gender VARCHAR(10)); INSERT INTO Employees (EmployeeID,Gender) VALUES (1,'Female'),(2,'Male'),(3,'Non-binary'),(4,'Female'),(5,'Non-binary'),(6,'Male'); | SELECT COUNT(*) FROM Employees WHERE Gender IN ('Female', 'Non-binary'); |
Update the soil moisture reading for a specific record of crop type 'Rice'. | CREATE TABLE crop_data (id INT,crop_type VARCHAR(255),soil_moisture INT,measurement_date DATE); INSERT INTO crop_data (id,crop_type,soil_moisture,measurement_date) VALUES (1,'Corn',60,'2021-05-01'); INSERT INTO crop_data (id,crop_type,soil_moisture,measurement_date) VALUES (2,'Rice',70,'2021-05-03'); | UPDATE crop_data SET soil_moisture = 75 WHERE id = 2; |
How many cargo theft incidents occurred in the state of Texas in 2020? | CREATE TABLE incidents(id INT,location VARCHAR(100),year INT,value INT); INSERT INTO incidents(id,location,year,value) VALUES (1,'Texas',2019,1200); INSERT INTO incidents(id,location,year,value) VALUES (2,'Texas',2020,1500); INSERT INTO incidents(id,location,year,value) VALUES (3,'California',2019,1800); INSERT INTO incidents(id,location,year,value) VALUES (4,'California',2020,2000); | SELECT SUM(value) FROM incidents WHERE location = 'Texas' AND year = 2020; |
Delete all records from the 'artworks' table where the 'price' is greater than the average 'price' for all artworks. | CREATE TABLE artworks (artwork_id INT,title VARCHAR(255),style VARCHAR(64),year INT,price DECIMAL(10,2)); | DELETE FROM artworks WHERE price > (SELECT AVG(price) FROM artworks); |
What is the total number of military equipment donations by country in the last 5 years? | CREATE TABLE donations (donor VARCHAR(255),recipient VARCHAR(255),equipment VARCHAR(255),quantity INT,donation_date DATE); | SELECT donor, SUM(quantity) as total_donations FROM donations WHERE donation_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 5 YEAR) AND CURDATE() GROUP BY donor; |
What is the average rating for accommodations in the Americas? | CREATE TABLE regions (id INT PRIMARY KEY,name VARCHAR(255)); CREATE TABLE accommodations (id INT PRIMARY KEY,name VARCHAR(255),rating FLOAT,region_id INT,FOREIGN KEY (region_id) REFERENCES regions(id)); INSERT INTO regions (id,name) VALUES (1,'Americas'); | SELECT AVG(rating) FROM accommodations WHERE region_id = 1; |
What is the minimum wage in the 'technology' industry for non-unionized workplaces? | CREATE TABLE if NOT EXISTS workplaces (id INT,industry VARCHAR(20),wage DECIMAL(5,2),is_unionized BOOLEAN); INSERT INTO workplaces (id,industry,wage,is_unionized) VALUES (1,'technology',70000.00,false),(2,'technology',75000.00,true),(3,'retail',30000.00,false); | SELECT MIN(wage) FROM workplaces WHERE industry = 'technology' AND is_unionized = false; |
What is the average price of ethically sourced cotton products? | CREATE TABLE cotton_products (product_id INT,is_ethically_sourced BOOLEAN,price DECIMAL(5,2)); INSERT INTO cotton_products (product_id,is_ethically_sourced,price) VALUES (1,true,20.99),(2,false,15.99),(3,true,25.99); | SELECT AVG(price) FROM cotton_products WHERE is_ethically_sourced = true; |
What are the names and categories of all eco-friendly clothing items? | CREATE TABLE clothing_items (id INT PRIMARY KEY,name VARCHAR(50),category VARCHAR(20),eco_friendly BOOLEAN); CREATE TABLE inventory (id INT PRIMARY KEY,clothing_item_id INT,size VARCHAR(10),quantity INT); CREATE TABLE sales (id INT PRIMARY KEY,inventory_id INT,sale_date DATE,quantity INT); | SELECT name, category FROM clothing_items WHERE eco_friendly = TRUE; |
What is the total donation and investment amount for each cause, separated by donations and investments, in the 'cause_donations' and 'cause_investments' tables, respectively, ordered by the total amount in descending order? | CREATE TABLE cause_donations (cause_id INT,cause_name TEXT,total_donations DECIMAL(10,2)); CREATE TABLE cause_investments (cause_id INT,cause_name TEXT,total_investments DECIMAL(10,2)); | SELECT cause_name, SUM(total_donations) as total_donation_amount FROM cause_donations GROUP BY cause_name UNION ALL SELECT cause_name, SUM(total_investments) as total_investment_amount FROM cause_investments GROUP BY cause_name ORDER BY total_donation_amount DESC; |
How many professional development courses did each teacher complete in the last two years? | CREATE TABLE teacher_professional_development (teacher_id INT,course_id INT,date DATE); INSERT INTO teacher_professional_development (teacher_id,course_id,date) VALUES (1,1001,'2020-01-01'); INSERT INTO teacher_professional_development (teacher_id,course_id,date) VALUES (1,1002,'2020-02-01'); | SELECT teacher_id, COUNT(course_id) as courses_completed FROM teacher_professional_development WHERE date >= DATEADD(year, -2, GETDATE()) GROUP BY teacher_id; |
Which defense projects have had the longest delays compared to their original timelines? | CREATE TABLE defense_projects (id INT,project VARCHAR(50),start_date DATE,end_date DATE,original_duration INT); INSERT INTO defense_projects (id,project,start_date,end_date,original_duration) VALUES (1,'Project A','2015-01-01','2018-12-31',12),(2,'Project B','2016-01-01','2017-12-31',12),(3,'Project C','2017-01-01','2019-12-31',12),(4,'Project D','2018-01-01','2020-01-01',12); | SELECT project, DATEDIFF(end_date, start_date) as actual_duration, original_duration, DATEDIFF(end_date, start_date) - original_duration as delay FROM defense_projects ORDER BY delay DESC; |
List all unique accommodation types from the 'StaffAccommodations' table. | CREATE TABLE StaffAccommodations (staff_id INT,accommodation_type VARCHAR(255)); INSERT INTO StaffAccommodations (staff_id,accommodation_type) VALUES (101,'Wheelchair Accessible Workspace'),(102,'Speech-to-Text Software'),(103,'Adaptive Keyboard'); | SELECT DISTINCT accommodation_type FROM StaffAccommodations; |
Identify the number of farms in each country practicing agroecology and the average farm size. | CREATE TABLE farms (id INT,name TEXT,country TEXT,size INT,practice TEXT); INSERT INTO farms (id,name,country,size,practice) VALUES (1,'Smith Farm','Brazil',10,'Agroecology'); INSERT INTO farms (id,name,country,size,practice) VALUES (2,'Jones Farm','Canada',15,'Conventional'); INSERT INTO farms (id,name,country,size,practice) VALUES (3,'Brown Farm','Brazil',20,'Agroecology'); | SELECT f.country, COUNT(f.id), AVG(f.size) FROM farms f WHERE f.practice = 'Agroecology' GROUP BY f.country; |
Find the number of unique species in each community education program | CREATE TABLE education_programs (id INT,name VARCHAR(50));CREATE TABLE animals (id INT,species VARCHAR(50),program_id INT);INSERT INTO education_programs (id,name) VALUES (1,'Adopt an Animal'),(2,'Wildlife Warriors');INSERT INTO animals (id,species,program_id) VALUES (1,'Lion',1),(2,'Elephant',2),(3,'Zebra',1),(4,'Lion',2); | SELECT e.name, COUNT(DISTINCT a.species) as unique_species FROM education_programs e INNER JOIN animals a ON e.id = a.program_id GROUP BY e.name; |
Decrease the average salary for the 'human_resources' department by 3%. | CREATE TABLE company_departments (dept_name TEXT,avg_salary NUMERIC); INSERT INTO company_departments (dept_name,avg_salary) VALUES ('human_resources',45000.00); | UPDATE company_departments SET avg_salary = avg_salary * 0.97 WHERE dept_name = 'human_resources'; |
What was the percentage change in rural poverty rates in Central America from 2018-2020? | CREATE TABLE poverty_rates (region VARCHAR(255),year INT,poverty_rate DECIMAL(5,2)); INSERT INTO poverty_rates (region,year,poverty_rate) VALUES ('Central America',2018,25.5),('Central America',2020,23.2); | SELECT ((poverty_rate_2020 - poverty_rate_2018) * 100.0 / poverty_rate_2018) AS percentage_change FROM (SELECT (SELECT poverty_rate FROM poverty_rates p2 WHERE p1.region = p2.region AND p2.year = 2018) AS poverty_rate_2018, (SELECT poverty_rate FROM poverty_rates p3 WHERE p1.region = p3.region AND p3.year = 2020) AS poverty_rate_2020 FROM poverty_rates p1 WHERE p1.region = 'Central America') AS subquery; |
What is the maximum depth in the ocean_floor_mapping table? | CREATE TABLE ocean_floor_mapping (location TEXT,depth INTEGER); INSERT INTO ocean_floor_mapping (location,depth) VALUES ('Challenger Deep',10994),('Mariana Trench',10972),('Tonga Trench',10823); | SELECT MAX(depth) FROM ocean_floor_mapping; |
List the unique treatment_approaches for patients diagnosed with bipolar disorder or schizophrenia in the 'treatment' schema. | CREATE TABLE treatment (treatment_id INT,patient_id INT,treatment_approach VARCHAR(255)); INSERT INTO treatment (treatment_id,patient_id,treatment_approach) VALUES (1,1,'CBT'),(2,2,'DBT'),(3,3,'EMDR'),(4,1,'Medication'),(5,6,'Lithium'),(6,7,'Antipsychotics'); | SELECT DISTINCT treatment_approach FROM treatment INNER JOIN (SELECT patient_id FROM patients WHERE diagnosis IN ('bipolar disorder', 'schizophrenia')) AS subquery ON treatment.patient_id = subquery.patient_id; |
What is the average price of vegan menu items in 'Sushi House'? | CREATE TABLE vegan_menu_engineering (menu_item VARCHAR(255),price DECIMAL(10,2),restaurant_name VARCHAR(255)); INSERT INTO vegan_menu_engineering (menu_item,price,restaurant_name) VALUES ('Veggie Roll',7.99,'Sushi House'),('Tofu Stir Fry',13.99,'Sushi House'),('Edamame',4.99,'Sushi House'); | SELECT AVG(price) FROM vegan_menu_engineering WHERE restaurant_name = 'Sushi House'; |
List all green-certified buildings in the 'downtown' area with their co-owners. | CREATE TABLE building (id INT,green_certified BOOLEAN,owner_id INT); CREATE TABLE person (id INT,name VARCHAR(50)); | SELECT building.id, person.name FROM building INNER JOIN person ON building.owner_id = person.id WHERE green_certified = TRUE AND neighborhood = 'downtown'; |
What is the maximum fine for traffic violations in the "TrafficViolations" table, per type of violation, for violations that occurred in business districts? | CREATE TABLE TrafficViolations (id INT,violation_type VARCHAR(50),location VARCHAR(50),fine DECIMAL(5,2)); INSERT INTO TrafficViolations (id,violation_type,location,fine) VALUES (1,'Speeding','School Zone',100),(2,'Illegal Parking','Business District',500),(3,'Speeding','Residential Area',80),(4,'Running Red Light','School Zone',150); | SELECT violation_type, MAX(fine) as max_fine FROM TrafficViolations WHERE location LIKE '%Business%' GROUP BY violation_type; |
List the total timber volume and carbon sequestration rate for each country with wildlife sanctuaries, sorted by the total timber volume in descending order. | CREATE TABLE country (country_id INT,country_name TEXT,PRIMARY KEY (country_id)); CREATE TABLE timber (timber_id INT,country_id INT,year INT,volume INT,PRIMARY KEY (timber_id),FOREIGN KEY (country_id) REFERENCES country(country_id)); CREATE TABLE wildlife (wildlife_id INT,country_id INT,species_count INT,PRIMARY KEY (wildlife_id),FOREIGN KEY (country_id) REFERENCES country(country_id)); CREATE TABLE carbon_sequestration (carbon_sequestration_id INT,country_id INT,rate REAL,PRIMARY KEY (carbon_sequestration_id),FOREIGN KEY (country_id) REFERENCES country(country_id)); | SELECT c.country_name, SUM(t.volume) AS total_timber_volume, AVG(cs.rate) AS avg_carbon_sequestration_rate FROM country c INNER JOIN timber t ON c.country_id = t.country_id INNER JOIN wildlife w ON c.country_id = w.country_id INNER JOIN carbon_sequestration cs ON c.country_id = cs.country_id GROUP BY c.country_name HAVING SUM(w.species_count) > 0 ORDER BY total_timber_volume DESC; |
Identify the total number of satellites in the Satellites table, grouped by their country of origin. | CREATE TABLE Satellites (ID INT,Satellite_Name VARCHAR(255),Country_Of_Origin VARCHAR(255)); INSERT INTO Satellites (ID,Satellite_Name,Country_Of_Origin) VALUES (1,'Starlink-1','USA'),(2,'Galileo-1','Europe'); | SELECT Country_Of_Origin, COUNT(*) FROM Satellites GROUP BY Country_Of_Origin; |
Identify the supplier with the largest organic vegetable shipments in H1 2021? | CREATE TABLE shipments (id INT,supplier_id INT,product VARCHAR(50),organic BOOLEAN,year INT,quarter INT,total_shipped INT); INSERT INTO shipments (id,supplier_id,product,organic,year,quarter,total_shipped) VALUES (1,1,'Carrots',true,2021,1,500),(2,2,'Broccoli',false,2022,2,600),(3,3,'Spinach',true,2021,1,400); | SELECT supplier_id, SUM(total_shipped) as total_organic_vegetable_shipments FROM shipments WHERE organic = true AND product LIKE '%vegetable%' AND year = 2021 AND quarter <= 2 GROUP BY supplier_id ORDER BY total_organic_vegetable_shipments DESC FETCH FIRST 1 ROW ONLY; |
What is the daily waste quantity for each type, ranked by the highest quantity, for the Southeast region? | CREATE TABLE waste_types (waste_type VARCHAR(255),region VARCHAR(255),waste_quantity INT,date DATE); INSERT INTO waste_types (waste_type,region,waste_quantity,date) VALUES ('Plastic','Southeast',100,'2021-01-01'),('Plastic','Southeast',150,'2021-01-02'),('Paper','Southeast',200,'2021-01-01'),('Paper','Southeast',250,'2021-01-02'); | SELECT waste_type, region, waste_quantity, date, RANK() OVER (PARTITION BY waste_type ORDER BY waste_quantity DESC) as daily_waste_rank FROM waste_types WHERE region = 'Southeast'; |
Delete all workouts with an average heart rate below 70 for users from Mumbai. | CREATE TABLE workouts (id INT,user_location VARCHAR(50),workout_date DATE,avg_heart_rate INT); INSERT INTO workouts (id,user_location,workout_date,avg_heart_rate) VALUES (1,'Mumbai','2022-01-01',80),(2,'Mumbai','2022-01-02',65); | DELETE FROM workouts WHERE user_location = 'Mumbai' AND avg_heart_rate < 70; |
Determine the change in the number of community health workers by race over time? | CREATE TABLE community_health_workers (id INT,name VARCHAR(50),age INT,race VARCHAR(50),hire_date DATE); INSERT INTO community_health_workers (id,name,age,race,hire_date) VALUES (1,'John Doe',35,'White','2020-01-01'),(2,'Jane Smith',40,'Black','2019-01-01'),(3,'Jose Rodriguez',30,'Hispanic','2021-01-01'); | SELECT race, COUNT(*) as current_count, LAG(COUNT(*)) OVER (PARTITION BY race ORDER BY hire_date) as previous_count FROM community_health_workers GROUP BY race, hire_date; |
List the virtual reality (VR) game design elements, including their unique IDs, names, genres, and the number of levels, for games that support multiplayer mode. | CREATE TABLE GameDesign (GameID INT,Name VARCHAR(50),Genre VARCHAR(20),Multiplayer BOOLEAN,NumLevels INT); INSERT INTO GameDesign (GameID,Name,Genre,Multiplayer,NumLevels) VALUES (1,'VR Racer','Racing',TRUE,10),(2,'Solar System','Simulation',FALSE,1),(3,'VR Puzzler','Puzzle',TRUE,15); | SELECT GameID, Name, Genre, NumLevels FROM GameDesign WHERE Multiplayer = TRUE; |
How many infectious disease cases were reported in each country in the past year? | CREATE TABLE infectious_diseases (id INT,country TEXT,date TEXT,cases INT); INSERT INTO infectious_diseases (id,country,date,cases) VALUES (1,'USA','2022-01-01',100),(2,'Canada','2022-01-02',50),(3,'Mexico','2022-01-03',75),(4,'USA','2022-01-04',120),(5,'Canada','2022-01-05',60),(6,'Mexico','2022-01-06',80); | SELECT country, COUNT(*) FROM infectious_diseases WHERE date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY country; |
What is the maximum oil production rate for wells in the Middle East? | CREATE TABLE wells (id INT,region VARCHAR(255),well_type VARCHAR(255),oil_production DECIMAL(5,2)); INSERT INTO wells (id,region,well_type,oil_production) VALUES (1,'Middle East','Oil',200.0),(2,'Middle East','Gas',250.0),(3,'North America','Oil',300.0),(4,'North America','Gas',350.0); | SELECT MAX(oil_production) as max_oil_production FROM wells WHERE region = 'Middle East'; |
What is the total amount of funding received by each project in Haiti in 2019? | CREATE TABLE projects (id INT,name VARCHAR(255),location VARCHAR(255)); CREATE TABLE funding (id INT,project_id INT,amount DECIMAL(10,2),funding_date DATE); | SELECT projects.name, SUM(funding.amount) FROM funding JOIN projects ON funding.project_id = projects.id WHERE projects.location = 'Haiti' AND funding.funding_date BETWEEN '2019-01-01' AND '2019-12-31' GROUP BY projects.id; |
What is the production rate for Well Z in the Marcellus Shale? | CREATE TABLE production_rates (well_name VARCHAR(50),location VARCHAR(50),rate FLOAT); INSERT INTO production_rates (well_name,location,rate) VALUES ('Well Z','Marcellus Shale',1500); | SELECT rate FROM production_rates WHERE well_name = 'Well Z' AND location = 'Marcellus Shale'; |
Update the sourcing country of ingredient 1 to 'France'. | CREATE TABLE ingredients (ingredient_id INT,name TEXT,sourcing_country TEXT,source_date DATE); INSERT INTO ingredients (ingredient_id,name,sourcing_country,source_date) VALUES (1,'Water','China','2021-01-01'),(2,'Glycerin','France','2021-02-15'); | UPDATE ingredients SET sourcing_country = 'France' WHERE ingredient_id = 1; |
Identify if there are any food recalls in the last month? | CREATE TABLE recall (id INT,product VARCHAR(50),date DATE); INSERT INTO recall (id,product,date) VALUES (1,'Chicken nuggets','2022-05-01'),(2,'Almond milk','2022-03-15'),(3,'Frozen berries','2022-01-20'); | SELECT * FROM recall WHERE date >= DATEADD(month, -1, GETDATE()); |
What is the minimum production rate of a single chemical in the African region? | CREATE TABLE regional_chemical_production (id INT,chemical_name VARCHAR(255),region VARCHAR(255),production_rate FLOAT); INSERT INTO regional_chemical_production (id,chemical_name,region,production_rate) VALUES (1,'Ethanol','Africa',650.0); | SELECT MIN(production_rate) FROM regional_chemical_production WHERE region = 'Africa'; |
How many cases were won by the top 2 attorneys with the highest win rate? | CREATE TABLE cases (case_id INT,attorney_id INT,case_won BOOLEAN); INSERT INTO cases (case_id,attorney_id,case_won) VALUES (1,4,TRUE),(2,4,FALSE),(3,5,TRUE),(4,5,TRUE),(5,6,FALSE),(6,6,TRUE); CREATE TABLE attorneys (attorney_id INT,name VARCHAR(50)); INSERT INTO attorneys (attorney_id,name) VALUES (4,'Maya Patel'),(5,'Carlos Alvarez'),(6,'Sophia Kim'); | SELECT COUNT(*) FROM (SELECT attorney_id, COUNT(*) as wins, COUNT(*) FILTER (WHERE case_won) as case_won_count, COUNT(*) - COUNT(*) FILTER (WHERE case_won) as losses FROM cases JOIN attorneys ON cases.attorney_id = attorneys.attorney_id GROUP BY attorney_id ORDER BY (COUNT(*) FILTER (WHERE case_won)) * 100.0 / COUNT(*) DESC LIMIT 2); |
What is the average safety score for AI models developed in Q1 2022, by companies located in Asia? | CREATE TABLE AI_Safety (ID INT,Model VARCHAR(255),Safety_Score FLOAT,Date DATE,Company_Location VARCHAR(255)); INSERT INTO AI_Safety (ID,Model,Safety_Score,Date,Company_Location) VALUES (1,'ModelA',0.85,'2022-01-15','Japan'),(2,'ModelB',0.91,'2022-02-12','China'),(3,'ModelC',0.75,'2022-03-01','India'); | SELECT AVG(Safety_Score) as Average_Score FROM AI_Safety WHERE Date BETWEEN '2022-01-01' AND '2022-03-31' AND Company_Location IN ('Japan', 'China', 'India'); |
What is the total billing amount for cases in the 'Family' category? | CREATE TABLE Cases (CaseID INT,Category VARCHAR(50),BillingAmount DECIMAL(10,2)); INSERT INTO Cases (CaseID,Category,BillingAmount) VALUES (1,'Family',2000.00),(2,'Civil',3000.00); | SELECT SUM(BillingAmount) FROM Cases WHERE Category = 'Family'; |
Show the number of athletes who have participated in each sport. | CREATE TABLE athletes_3 (name TEXT,sport TEXT); INSERT INTO athletes_3 (name,sport) VALUES ('Jane Doe','Soccer'),('Jim Brown','Football'),('Michael Jordan','Basketball'),('Babe Ruth','Baseball'),('Serena Williams','Tennis'); | SELECT sport, COUNT(*) FROM athletes_3 GROUP BY sport; |
Which menu category has the highest average price? | CREATE TABLE menus (menu_category VARCHAR(50),avg_price DECIMAL(5,2)); INSERT INTO menus (menu_category,avg_price) VALUES ('Appetizers',8.50),('Entrees',15.00),('Desserts',7.50); | SELECT menu_category, AVG(avg_price) FROM menus GROUP BY menu_category ORDER BY AVG(avg_price) DESC LIMIT 1; |
What is the number of cultural competency trainings conducted in California and New York? | CREATE TABLE cultural_competency_trainings (training_id INT,location VARCHAR(50),date DATE); INSERT INTO cultural_competency_trainings (training_id,location,date) VALUES (1,'Los Angeles,CA','2022-01-01'),(2,'San Diego,CA','2022-02-01'),(3,'San Francisco,CA','2022-03-01'),(4,'New York,NY','2022-02-15'); | SELECT COUNT(*) FROM cultural_competency_trainings WHERE location IN ('CA', 'NY'); |
How many species have been observed in each Arctic habitat type? | CREATE TABLE habitats (habitat_id INT,habitat_name VARCHAR(50)); CREATE TABLE species (species_id INT,species_name VARCHAR(50)); CREATE TABLE species_observations (observation_id INT,species_id INT,habitat_id INT); INSERT INTO habitats (habitat_id,habitat_name) VALUES (1,'Tundra'),(2,'Freshwater'),(3,'Marine'); INSERT INTO species (species_id,species_name) VALUES (1,'Polar Bear'),(2,'Arctic Fox'),(3,'Arctic Char'); INSERT INTO species_observations (observation_id,species_id,habitat_id) VALUES (1,1,1),(2,1,3),(3,2,2),(4,3,3); | SELECT h.habitat_name, COUNT(DISTINCT so.species_id) as species_count FROM habitats h JOIN species_observations so ON h.habitat_id = so.habitat_id GROUP BY h.habitat_name; |
What is the average number of research grants awarded per year to each country? | CREATE TABLE country_grants_by_year (id INT,country VARCHAR(255),year INT,grant_amount INT); INSERT INTO country_grants_by_year (id,country,year,grant_amount) VALUES (1,'USA',2018,100000),(2,'Canada',2018,75000),(3,'Mexico',2018,50000),(4,'USA',2019,125000),(5,'Brazil',2019,80000); | SELECT country, AVG(grant_amount) as avg_grants FROM country_grants_by_year GROUP BY country; |
What was the total weight of cannabis sold by each dispensary in Washington in Q3 2021? | CREATE TABLE Dispensaries (id INT,name TEXT,state TEXT); INSERT INTO Dispensaries (id,name,state) VALUES (1,'Dispensary A','Washington'),(2,'Dispensary B','Washington'); CREATE TABLE Sales (dispensary_id INT,date DATE,weight_sold INT); INSERT INTO Sales (dispensary_id,date,weight_sold) VALUES (1,'2021-07-01',50),(1,'2021-07-02',60),(1,'2021-08-01',55),(2,'2021-07-01',40),(2,'2021-07-03',45),(2,'2021-08-01',42); | SELECT d.name, SUM(s.weight_sold) as total_weight_sold FROM Dispensaries d INNER JOIN Sales s ON d.id = s.dispensary_id WHERE s.date BETWEEN '2021-07-01' AND '2021-09-30' GROUP BY d.name; |
What is the total number of players who play "Virtual Reality Chess" or "Racing Simulator 2022"? | CREATE TABLE Players (PlayerID INT,PlayerName VARCHAR(50),Game VARCHAR(50)); INSERT INTO Players (PlayerID,PlayerName,Game) VALUES (1,'John Doe','Virtual Reality Chess'),(2,'Jane Smith','Virtual Reality Chess'),(3,'Alice Johnson','Shooter Game 2022'),(4,'Bob Brown','Racing Simulator 2022'); | SELECT COUNT(*) FROM Players WHERE Game IN ('Virtual Reality Chess', 'Racing Simulator 2022'); |
What is the percentage of players who have achieved level 50 in 'GameK'? | CREATE TABLE player_levels (player_id INT,game_name VARCHAR(100),level INT); INSERT INTO player_levels (player_id,game_name,level) VALUES (1,'GameK',50),(2,'GameL',45),(3,'GameK',40),(4,'GameK',50),(5,'GameM',35); CREATE TABLE player_profiles (player_id INT,player_country VARCHAR(50)); INSERT INTO player_profiles (player_id,player_country) VALUES (1,'USA'),(2,'Canada'),(3,'Mexico'),(4,'Brazil'),(5,'USA'); | SELECT COUNT(player_id) * 100.0 / (SELECT COUNT(DISTINCT player_id) FROM player_profiles) AS percentage_of_players FROM player_levels WHERE game_name = 'GameK' AND level = 50; |
Add a new record to the 'Volunteers' table with the name 'Jane Doe', skill level 'Advanced', and last volunteered date '2022-01-01' | CREATE TABLE Volunteers (id INT PRIMARY KEY,volunteer_name VARCHAR(255),skill_level VARCHAR(255),last_volunteered DATE); | INSERT INTO Volunteers (volunteer_name, skill_level, last_volunteered) VALUES ('Jane Doe', 'Advanced', '2022-01-01'); |
Which public works projects were completed in '2022-03'? | CREATE TABLE PublicWorksProjects (id INT,name TEXT,start_date DATE,completion_date DATE); INSERT INTO PublicWorksProjects (id,name,start_date,completion_date) VALUES (1,'Street Paving','2021-03-01','2021-03-31'); INSERT INTO PublicWorksProjects (id,name,start_date,completion_date) VALUES (2,'Sidewalk Construction','2021-07-01','2021-09-30'); INSERT INTO PublicWorksProjects (id,name,start_date,completion_date) VALUES (3,'Traffic Light Installation','2022-01-01','2022-02-28'); INSERT INTO PublicWorksProjects (id,name,start_date,completion_date) VALUES (4,'Bridge Inspection','2022-03-15','2022-03-30'); | SELECT name FROM PublicWorksProjects WHERE completion_date BETWEEN '2022-03-01' AND '2022-03-31'; |
What is the average depth of underwater sites in Fiji? | CREATE TABLE underwater_sites (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),depth INT); | SELECT AVG(depth) FROM underwater_sites WHERE country = 'Fiji'; |
What is the average age of patients who improved after therapy? | CREATE TABLE patients (patient_id INT,age INT,improvement CHAR(1)); INSERT INTO patients (patient_id,age,improvement) VALUES (1,30,'Y'),(2,25,'N'),(3,45,'Y'); | SELECT AVG(age) FROM patients WHERE improvement = 'Y'; |
Show the local economic impact of tourism in the city of Kyoto. | CREATE TABLE tourism_impact (city TEXT,economic_impact INT); INSERT INTO tourism_impact (city,economic_impact) VALUES ('Kyoto',25000000),('Osaka',30000000),('Tokyo',40000000); | SELECT economic_impact FROM tourism_impact WHERE city = 'Kyoto'; |
Which regions have the greatest digital divide in terms of access to technology? | CREATE TABLE digital_divide (region VARCHAR(50),access_gap FLOAT); INSERT INTO digital_divide (region,access_gap) VALUES ('Asia-Pacific',0.32),('Latin America',0.47),('Sub-Saharan Africa',0.56); | SELECT region, access_gap FROM digital_divide WHERE access_gap > (SELECT AVG(access_gap) FROM digital_divide) ORDER BY access_gap DESC; |
What is the minimum marketing budget for sustainable tourism initiatives in Europe? | CREATE TABLE SustainableTourism (initiative VARCHAR(50),location VARCHAR(50),budget INT); INSERT INTO SustainableTourism (initiative,location,budget) VALUES ('Green Villages','Europe',50000); | SELECT MIN(budget) FROM SustainableTourism WHERE location = 'Europe'; |
What is the moving average of claim amounts for the last 3 months? | CREATE TABLE Claims (ClaimID int,ClaimDate date,ClaimAmount decimal(10,2)); INSERT INTO Claims (ClaimID,ClaimDate,ClaimAmount) VALUES (1,'2022-01-15',4500.00),(2,'2022-02-03',3200.00),(3,'2022-03-17',5700.00),(4,'2022-04-01',6100.00),(5,'2022-05-12',4200.00),(6,'2022-06-20',3800.00); | SELECT ClaimDate, AVG(ClaimAmount) OVER (ORDER BY ClaimDate ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS MovingAverage FROM Claims |
What is the minimum water usage per day in the wastewater treatment plant located in Atlanta? | CREATE TABLE WastewaterTreatmentData (plant_location VARCHAR(20),water_consumption_per_day FLOAT); INSERT INTO WastewaterTreatmentData (plant_location,water_consumption_per_day) VALUES ('Atlanta',2200000),('Miami',2800000); | SELECT MIN(water_consumption_per_day) FROM WastewaterTreatmentData WHERE plant_location = 'Atlanta'; |
Show the total waste generation for each type | CREATE TABLE waste_generation (id INT PRIMARY KEY,waste_type_id INT,generation_rate FLOAT); INSERT INTO waste_generation (id,waste_type_id,generation_rate) VALUES (1,1,50.5),(2,2,40.3); CREATE TABLE waste_types (id INT PRIMARY KEY,waste_type VARCHAR(255)); INSERT INTO waste_types (id,waste_type) VALUES (1,'Plastic'),(2,'Paper'); | SELECT waste_types.waste_type, SUM(waste_generation.generation_rate) FROM waste_types INNER JOIN waste_generation ON waste_types.id = waste_generation.waste_type_id GROUP BY waste_types.waste_type; |
What is the total amount of aid given to Rohingya refugees by international organizations since 2017? | CREATE TABLE refugee_aid (id INT,recipient VARCHAR(50),aid_type VARCHAR(50),amount FLOAT,date DATE); INSERT INTO refugee_aid (id,recipient,aid_type,amount,date) VALUES (1,'Rohingya refugees','food',200000,'2017-01-01'); | SELECT recipient, SUM(amount) as total_aid_given FROM refugee_aid WHERE recipient = 'Rohingya refugees' AND date >= '2017-01-01' GROUP BY recipient; |
What is the total biomass of all marine life in the Atlantic Ocean below 2000 meters depth? | CREATE TABLE atlantic_ocean_biomass (id INT,depth FLOAT,biomass FLOAT); | SELECT SUM(biomass) FROM atlantic_ocean_biomass WHERE depth < 2000; |
Identify the number of investments made in each sector in the year 2018. | CREATE TABLE investments (id INT,sector VARCHAR(20),date DATE,value FLOAT); INSERT INTO investments (id,sector,date,value) VALUES (1,'Technology','2018-01-01',100000.0),(2,'Finance','2016-01-01',75000.0),(3,'Renewable Energy','2018-01-01',125000.0); | SELECT sector, COUNT(*) FROM investments WHERE date >= '2018-01-01' AND date < '2019-01-01' GROUP BY sector; |
Who is the top scorer for the Warriors in the current season? | CREATE TABLE teams (team_id INT,team_name VARCHAR(255)); INSERT INTO teams (team_id,team_name) VALUES (1,'Warriors'); CREATE TABLE players (player_id INT,player_name VARCHAR(255),team_id INT); INSERT INTO players (player_id,player_name,team_id) VALUES (1,'Stephen Curry',1); CREATE TABLE games (game_id INT,team_id INT,player_id INT,points INT); INSERT INTO games (game_id,team_id,player_id,points) VALUES (1,1,1,30); | SELECT players.player_name, MAX(games.points) FROM players INNER JOIN games ON players.player_id = games.player_id WHERE players.team_id = 1 GROUP BY players.player_name; |
Insert a new bus route from 'Downtown' to 'Harbor' | CREATE TABLE bus_routes (route_id INT PRIMARY KEY,start_location TEXT,end_location TEXT); | INSERT INTO bus_routes (route_id, start_location, end_location) VALUES (1, 'Downtown', 'Harbor'); |
What is the average time to resolve security incidents for each vulnerability type in the last month? | CREATE TABLE incident_vulnerability_resolution (id INT,incident_id INT,vulnerability_type VARCHAR(255),resolution_time INT,incident_date DATE); INSERT INTO incident_vulnerability_resolution (id,incident_id,vulnerability_type,resolution_time,incident_date) VALUES (1,1,'SQL Injection',120,'2021-12-01'),(2,1,'Cross-site Scripting',150,'2021-12-01'),(3,2,'SQL Injection',100,'2021-12-02'),(4,3,'Cross-site Scripting',180,'2021-12-03'),(5,3,'Phishing',110,'2021-12-03'),(6,4,'Phishing',140,'2021-12-04'),(7,4,'SQL Injection',120,'2021-12-04'),(8,5,'Cross-site Scripting',150,'2021-12-05'); | SELECT vulnerability_type, AVG(resolution_time) as avg_resolution_time FROM incident_vulnerability_resolution WHERE incident_date >= DATEADD(day, -30, GETDATE()) GROUP BY vulnerability_type; |
What is the production trend for Terbium between 2015 and 2020? | CREATE TABLE Terbium_Production (Year INT,Quantity INT); INSERT INTO Terbium_Production (Year,Quantity) VALUES (2015,900),(2016,1000),(2017,1100),(2018,1200),(2019,1300),(2020,1400); | SELECT Year, Quantity FROM Terbium_Production; |
What is the minimum water consumption per day for the uranium mines? | CREATE TABLE WaterConsumption (MineID INT,MineType VARCHAR(15),ConsumptionDate DATE,WaterAmount INT); | SELECT MIN(WaterAmount) FROM WaterConsumption WHERE MineType = 'Uranium'; |
List the defense contractors in California with contracts worth over 1 million | CREATE TABLE defense_contracts (contract_id INT,company_name TEXT,state TEXT,value FLOAT); INSERT INTO defense_contracts (contract_id,company_name,state,value) VALUES (1,'XYZ Corp','California',1500000),(2,'ABC Inc','Texas',500000),(3,'DEF Ltd','California',800000); | SELECT company_name FROM defense_contracts WHERE state = 'California' AND value > 1000000; |
List the number of unique international graduate students in each department of the university? | CREATE TABLE graduate_students (student_id INT,student_name TEXT,program_name TEXT,department_name TEXT,international_student BOOLEAN); INSERT INTO graduate_students VALUES (4001,'Sophia Lee','MS CS','Computer Science',true),(4002,'Daniel Kim','MA Math','Mathematics',true),(4003,'Emily Wong','MS Stats','Statistics',false),(4004,'Oliver Chen','PhD CS','Computer Science',true); | SELECT department_name, COUNT(DISTINCT CASE WHEN international_student THEN program_name END) FROM graduate_students GROUP BY department_name; |
Delete all classical music songs from the Songs table | CREATE TABLE Songs (song_id INT,title TEXT,genre TEXT,release_date DATE,price DECIMAL(5,2)); | DELETE FROM Songs WHERE genre = 'classical'; |
List the names and positions of all healthcare professionals who have served in South Sudan and Somalia, sorted alphabetically by name. | CREATE TABLE healthcare_personnel (id INT,name VARCHAR(255),position VARCHAR(255),country VARCHAR(255)); INSERT INTO healthcare_personnel (id,name,position,country) VALUES ('1','Eliud','Doctor','South Sudan'),('2','Fatima','Nurse','Somalia'),('3','Hamza','Pharmacist','South Sudan'),('4','Ibtisam','Doctor','Somalia'),('5','Joseph','Nurse','South Sudan'),('6','Khadija','Pharmacist','Somalia'); | SELECT name, position FROM healthcare_personnel WHERE country IN ('South Sudan', 'Somalia') ORDER BY name ASC; |
What is the total program impact in the city of Chicago? | CREATE TABLE programs (id INT,city TEXT,impact INT); INSERT INTO programs (id,city,impact) VALUES (1,'Chicago',50),(2,'Chicago',75),(3,'Los Angeles',100); | SELECT SUM(impact) FROM programs WHERE city = 'Chicago'; |
Show the trend of approved socially responsible lending applications in the last 12 months. | CREATE TABLE lending_trend (application_date DATE,approved BOOLEAN); INSERT INTO lending_trend (application_date,approved) VALUES ('2021-01-02',TRUE),('2021-03-15',FALSE),('2021-04-01',TRUE),('2021-05-01',TRUE),('2021-06-15',FALSE),('2021-07-01',TRUE),('2021-08-01',TRUE),('2021-09-15',FALSE),('2021-10-01',TRUE),('2021-11-01',TRUE),('2021-12-15',FALSE); | SELECT MONTH(application_date) as month, YEAR(application_date) as year, SUM(approved) as num_approved FROM lending_trend WHERE application_date >= DATE_SUB(CURRENT_DATE, INTERVAL 12 MONTH) GROUP BY YEAR(application_date), MONTH(application_date); |
Delete all records related to 'arson' in 'Chicago' | CREATE TABLE crime_statistics(id INT,crime_type VARCHAR(20),location VARCHAR(20),time DATE); | DELETE FROM crime_statistics WHERE crime_type = 'arson' AND location = 'Chicago'; |
What is the minimum salary of employees who joined in Q3 2022? | CREATE TABLE EmployeeHiring (EmployeeID INT,HireDate DATE,Salary REAL); INSERT INTO EmployeeHiring (EmployeeID,HireDate,Salary) VALUES (1,'2022-07-01',62000); | SELECT MIN(Salary) FROM EmployeeHiring WHERE HireDate BETWEEN '2022-07-01' AND '2022-09-30'; |
What is the total number of visitors from the United States and Canada for each exhibition? | CREATE TABLE Exhibitions (ExhibitionID INT,ExhibitionName VARCHAR(255)); INSERT INTO Exhibitions (ExhibitionID,ExhibitionName) VALUES (1,'Modern Art'); INSERT INTO Exhibitions (ExhibitionID,ExhibitionName) VALUES (2,'Natural History'); CREATE TABLE Visitors (VisitorID INT,Country VARCHAR(255),ExhibitionID INT); INSERT INTO Visitors (VisitorID,Country,ExhibitionID) VALUES (1,'USA',1); INSERT INTO Visitors (VisitorID,Country,ExhibitionID) VALUES (2,'Canada',1); INSERT INTO Visitors (VisitorID,Country,ExhibitionID) VALUES (3,'Mexico',2); | SELECT E.ExhibitionName, COUNT(V.VisitorID) as TotalVisitors FROM Exhibitions E INNER JOIN Visitors V ON E.ExhibitionID = V.ExhibitionID WHERE V.Country IN ('USA', 'Canada') GROUP BY E.ExhibitionName; |
What is the total number of climate adaptation projects in Oceania? | CREATE TABLE climate_adaptation_projects (project_id INT,project_name VARCHAR(255),location VARCHAR(255)); INSERT INTO climate_adaptation_projects (project_id,project_name,location) VALUES (1,'Coastal Protection in Australia','Australia'),(2,'Water Management in New Zealand','New Zealand'),(3,'Disaster Resilience in Pacific Islands','Pacific Islands'); | SELECT COUNT(*) FROM climate_adaptation_projects WHERE location = 'Oceania'; |
Show the total number of posts and comments by users in the 'LGBTQ+' community on Twitter and Instagram in the past week, broken down by gender. | CREATE TABLE posts (post_id INT,user_id INT,platform VARCHAR(20),post_text VARCHAR(100),post_date DATE); CREATE TABLE comments (comment_id INT,post_id INT,user_id INT,comment_text VARCHAR(100),comment_date DATE); CREATE TABLE user_profile (user_id INT,community VARCHAR(20),gender VARCHAR(10)); INSERT INTO posts VALUES (1,1,'Twitter','Hello World!','2022-01-01'); INSERT INTO comments VALUES (1,1,2,'Nice post!','2022-01-02'); INSERT INTO user_profile VALUES (1,'LGBTQ+','Female'); | SELECT p.platform, u.gender, COUNT(DISTINCT p.post_id) as num_posts, COUNT(DISTINCT c.comment_id) as num_comments FROM posts p JOIN comments c ON p.post_id = c.post_id JOIN user_profile u ON p.user_id = u.user_id WHERE p.platform IN ('Twitter', 'Instagram') AND u.community = 'LGBTQ+' AND p.post_date >= DATEADD(week, -1, GETDATE()) GROUP BY p.platform, u.gender; |
Find the difference between the highest and lowest daily trading volume for each stock? | CREATE TABLE daily_volume (stock_symbol VARCHAR(10),trading_date DATE,volume INT); INSERT INTO daily_volume (stock_symbol,trading_date,volume) VALUES ('AAPL','2022-01-01',1000000); INSERT INTO daily_volume (stock_symbol,trading_date,volume) VALUES ('AAPL','2022-01-02',1200000); INSERT INTO daily_volume (stock_symbol,trading_date,volume) VALUES ('GOOG','2022-01-01',800000); INSERT INTO daily_volume (stock_symbol,trading_date,volume) VALUES ('GOOG','2022-01-02',750000); | SELECT stock_symbol, MAX(volume) - MIN(volume) as volume_range FROM daily_volume GROUP BY stock_symbol; |
What is the maximum travel advisory level for Southeast Asia? | CREATE TABLE advisory (id INT,country TEXT,level INT); INSERT INTO advisory (id,country,level) VALUES (1,'Thailand',2),(2,'Vietnam',1),(3,'Indonesia',3); | SELECT MAX(level) FROM advisory WHERE country IN ('Thailand', 'Vietnam', 'Indonesia'); |
List the top 3 most expensive property co-ownerships in the sustainable urbanism category. | CREATE TABLE co_ownership (id INT,property_id INT,coowner_id INT,category VARCHAR(255),price DECIMAL(10,2)); INSERT INTO co_ownership (id,property_id,coowner_id,category,price) VALUES (1,1,1001,'sustainable urbanism',500000),(2,2,1002,'sustainable urbanism',600000),(3,3,1003,'inclusive housing',450000); | SELECT c.property_id, c.coowner_id, c.category, c.price FROM co_ownership c WHERE c.category = 'sustainable urbanism' ORDER BY c.price DESC LIMIT 3; |
What is the number of mental health facilities in New York and California? | CREATE TABLE mental_health_facilities (state VARCHAR(20),num_facilities INT); INSERT INTO mental_health_facilities (state,num_facilities) VALUES ('New York',500),('California',800); | SELECT SUM(num_facilities) FROM mental_health_facilities WHERE state IN ('New York', 'California'); |
What was the average donation amount by first-time donors in 2021? | CREATE TABLE Donors (DonorID int,DonationDate date,DonationAmount numeric); INSERT INTO Donors VALUES (1,'2021-01-01',50),(2,'2021-02-01',100),(3,'2021-03-01',200),(4,'2021-01-01',150),(5,'2021-02-01',200); | SELECT AVG(DonationAmount) FROM (SELECT DonationAmount FROM Donors WHERE DonorID NOT IN (SELECT DonorID FROM Donors GROUP BY DonorID HAVING COUNT(*) > 1) AND EXTRACT(YEAR FROM DonationDate) = 2021) |
Which vineyards have a temperature above 30°C on any day in the 'vineyard_temperature' table? | CREATE TABLE vineyard_temperature (id INT,vineyard_id INT,temperature DECIMAL(5,2),record_date DATE); | SELECT DISTINCT vineyard_id FROM vineyard_temperature WHERE temperature > 30; |
Who are the top 3 cities in Texas with the highest average income? | CREATE TABLE cities (name TEXT,state TEXT,avg_income INTEGER); INSERT INTO cities (name,state,avg_income) VALUES ('City1','Texas',60000),('City2','Texas',70000),('City3','Texas',50000),('City4','Texas',80000),('City5','Texas',55000); | SELECT name, avg_income FROM (SELECT name, avg_income, ROW_NUMBER() OVER (ORDER BY avg_income DESC) as rank FROM cities WHERE state = 'Texas') as subquery WHERE rank <= 3; |
List all military personnel who have been promoted in the last 5 years | CREATE TABLE military_personnel (id INT,name VARCHAR(50),rank VARCHAR(20),promotion_date DATE); INSERT INTO military_personnel (id,name,rank,promotion_date) VALUES (1,'John Doe','Private','2015-01-01'),(2,'Jane Smith','Captain','2016-01-01'),(3,'Alice Johnson','Sergeant','2017-01-01'),(4,'Bob Brown','Lieutenant','2018-01-01'),(5,'Charlie Davis','Colonel','2019-01-01'); | SELECT * FROM military_personnel WHERE promotion_date >= DATEADD(year, -5, GETDATE()); |
What is the percentage of workplaces with documented sexual harassment cases in the manufacturing industry in India and Argentina? | CREATE TABLE workplace_harassment(id INT,industry VARCHAR(50),country VARCHAR(14),harassment_cases INT);INSERT INTO workplace_harassment(id,industry,country,harassment_cases) VALUES (1,'Manufacturing','India',250),(2,'Manufacturing','Argentina',120),(3,'Manufacturing','United States',600),(4,'Manufacturing','Brazil',300); | SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM workplace_harassment WHERE industry = 'Manufacturing' AND country IN ('India', 'Argentina'))) FROM workplace_harassment WHERE industry = 'Manufacturing' AND country IN ('India', 'Argentina') AND harassment_cases > 0 |
Determine the dishes that are low in inventory | CREATE TABLE inventory (dish_id INT,quantity INT); INSERT INTO inventory (dish_id,quantity) VALUES (1,10),(2,5),(3,15); CREATE TABLE dishes (dish_id INT,dish_name VARCHAR(255),cuisine VARCHAR(255)); INSERT INTO dishes (dish_id,dish_name,cuisine) VALUES (1,'Quinoa Salad','Mediterranean'),(2,'Chicken Caesar Wrap','Mediterranean'),(3,'Tacos','Mexican'); | SELECT d.dish_id, d.dish_name, i.quantity FROM inventory i INNER JOIN dishes d ON i.dish_id = d.dish_id WHERE i.quantity < 10; |
How many international tourists visited Japan in the last 3 years? | CREATE TABLE tourists (tourist_id INT,visited_date DATE,country TEXT); INSERT INTO tourists (tourist_id,visited_date,country) VALUES (1,'2020-01-01','Japan'),(2,'2019-05-05','USA'),(3,'2018-12-31','Japan'); | SELECT COUNT(*) FROM tourists WHERE country = 'Japan' AND visited_date >= DATE_SUB(CURDATE(), INTERVAL 3 YEAR); |
Show cross-domain AI fairness issues by model. | CREATE TABLE ai_fairness_issues (model TEXT,domain TEXT); CREATE TABLE creative_ai (model TEXT,application TEXT); | SELECT ai_fairness_issues.model, COUNT(DISTINCT ai_fairness_issues.domain) + COUNT(DISTINCT creative_ai.application) AS cross_domain_issues FROM ai_fairness_issues INNER JOIN creative_ai ON ai_fairness_issues.model = creative_ai.model GROUP BY ai_fairness_issues.model HAVING cross_domain_issues > 1; |
Which vehicle safety test scores are above the overall average score in the 'safety_tests' table? | CREATE TABLE safety_tests (test_id INT,vehicle_model VARCHAR(30),score FLOAT); INSERT INTO safety_tests (test_id,vehicle_model,score) VALUES (1,'Model S',92.5),(2,'Model S',94.7),(3,'Model X',91.2),(4,'Model 3',93.6); | SELECT vehicle_model, score FROM (SELECT vehicle_model, score, AVG(score) OVER () avg_score FROM safety_tests) sq WHERE score > avg_score; |
Insert a new record into the 'carrier' table with ID 5, name 'Sea Freight Inc.', and phone number '123-456-7890'. | CREATE TABLE carrier (id INT PRIMARY KEY,name VARCHAR(50),phone VARCHAR(15)); | INSERT INTO carrier (id, name, phone) VALUES (5, 'Sea Freight Inc.', '123-456-7890'); |
How many attendees identified as male, female, or non-binary for each program in 2022? | CREATE TABLE attendee_demographics (attendee_id INT,attendee_age INT,attendee_gender VARCHAR(50),program_id INT,event_date DATE); INSERT INTO attendee_demographics (attendee_id,attendee_age,attendee_gender,program_id,event_date) VALUES (1,34,'male',101,'2022-05-12'); INSERT INTO attendee_demographics (attendee_id,attendee_age,attendee_gender,program_id,event_date) VALUES (2,45,'non-binary',102,'2022-06-20'); | SELECT program_id, attendee_gender, COUNT(*) as attendee_count FROM attendee_demographics WHERE YEAR(event_date) = 2022 GROUP BY program_id, attendee_gender; |
Find the average number of days between vulnerability discoveries for each software product. | CREATE TABLE software (id INT,name VARCHAR(255)); INSERT INTO software (id,name) VALUES (1,'Product A'),(2,'Product B'); CREATE TABLE vulnerabilities (id INT,software_id INT,discovered_on DATE,severity VARCHAR(255)); INSERT INTO vulnerabilities (id,software_id,discovered_on,severity) VALUES (1,1,'2022-01-01','High'),(2,1,'2022-02-01','Medium'),(3,2,'2022-03-01','Low'); | SELECT software.name, AVG(DATEDIFF(day, vulnerabilities.discovered_on, LEAD(vulnerabilities.discovered_on) OVER (PARTITION BY software.id ORDER BY vulnerabilities.discovered_on))) as average_days_between_vulnerabilities FROM software LEFT JOIN vulnerabilities ON software.id = vulnerabilities.software_id GROUP BY software.name; |
Delete records in 'sports_team_d_ticket_sales' table where 'sale_date' is after '2022-02-01' | CREATE TABLE sports_team_d_ticket_sales (sale_id INT,sale_date DATE,quantity INT,price DECIMAL(5,2)); INSERT INTO sports_team_d_ticket_sales (sale_id,sale_date,quantity,price) VALUES (1,'2022-01-01',100,50.00),(2,'2022-01-02',120,55.00),(3,'2022-02-03',150,60.00); | DELETE FROM sports_team_d_ticket_sales WHERE sale_date > '2022-02-01'; |
Identify the waste generation metrics for countries in the top 3 recycling rate categories, and rank them by total waste generated. | CREATE TABLE CountryWasteMetrics (Country TEXT,TotalWasteGenerated FLOAT,RecyclingRate FLOAT); INSERT INTO CountryWasteMetrics (CountryName,TotalWasteGenerated,RecyclingRate) VALUES ('USA',250,0.35),('China',300,0.2),('Germany',100,0.65),('Canada',120,0.45),('India',180,0.15),('Brazil',150,0.55),('SouthAfrica',80,0.6),('Indonesia',200,0.1),('Japan',70,0.7),('Mexico',130,0.3); | SELECT Country, TotalWasteGenerated, RecyclingRate FROM (SELECT Country, TotalWasteGenerated, RecyclingRate, NTILE(3) OVER (ORDER BY RecyclingRate DESC) as tier FROM CountryWasteMetrics) t WHERE tier <= 3 ORDER BY TotalWasteGenerated DESC; |
Create a new table 'risk_models' with columns 'model_id', 'model_name', 'model_description', 'model_date' | CREATE TABLE policyholders (policyholder_id INT PRIMARY KEY,name VARCHAR(100),age INT,gender VARCHAR(10),city VARCHAR(50),state VARCHAR(50),zip_code VARCHAR(10)); | CREATE TABLE risk_models (model_id INT PRIMARY KEY, model_name VARCHAR(100), model_description TEXT, model_date DATE); |
List all ports that have had cargo handled on a Sunday. | CREATE TABLE ports (port_id INT,port_name VARCHAR(50),city VARCHAR(50),country VARCHAR(50)); CREATE TABLE cargo (cargo_id INT,port_id INT,weight FLOAT,handling_date DATE); | SELECT DISTINCT port_name FROM cargo c JOIN ports p ON c.port_id = p.port_id WHERE DAYOFWEEK(handling_date) = 1; |
Find the name and age of the youngest individual in the 'ancient_burials' table. | CREATE TABLE ancient_burials (id INT,name VARCHAR(50),age INT,gender VARCHAR(10),grave_contents VARCHAR(255)); INSERT INTO ancient_burials (id,name,age,gender,grave_contents) VALUES (1,'John Doe',45,'Male','Pottery,coins'),(2,'Jane Doe',30,'Female','Beads,pottery'),(3,'Ahmed',25,'Male','Bronze tools'),(4,'Siti',22,'Female','Pottery'); | SELECT name, age FROM ancient_burials WHERE age = (SELECT MIN(age) FROM ancient_burials); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.