instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the maximum depth of the deepest marine trench in each ocean? | CREATE TABLE marine_trenches (ocean TEXT,trench TEXT,max_depth INTEGER);INSERT INTO marine_trenches (ocean,trench,max_depth) VALUES ('Pacific','Mariana Trench',10994),('Indian','Java Trench',7725); | SELECT ocean, MAX(max_depth) FROM marine_trenches GROUP BY ocean; |
What is the average time to complete a construction project in Illinois? | CREATE TABLE il_projects (project VARCHAR(20),completion_time FLOAT); INSERT INTO il_projects (project,completion_time) VALUES ('Residential',12.5),('Commercial',18.2),('Industrial',21.7); | SELECT AVG(completion_time) FROM il_projects; |
Find the average financial capability score for clients in each country in Central America. | CREATE TABLE clients (client_id INT,client_name TEXT,country TEXT,financial_capability_score FLOAT); INSERT INTO clients (client_id,client_name,country,financial_capability_score) VALUES (1,'Maria Hernandez','Costa Rica',7),(2,'Pedro Alvarez','Guatemala',8),(3,'Carlos Rodriguez','Panama',6),(4,'Ana Garcia','Nicaragua',9); | SELECT country, AVG(financial_capability_score) FROM clients WHERE country IN ('Costa Rica', 'Guatemala', 'Panama', 'Nicaragua') GROUP BY country; |
What is the maximum number of community policing programs implemented in the city of Houston between 2018 and 2020? | CREATE TABLE community_policing (id INT,city VARCHAR(50),start_year INT,end_year INT,programs INT); INSERT INTO community_policing (id,city,start_year,end_year,programs) VALUES (1,'Houston',2018,2020,5); INSERT INTO community_policing (id,city,start_year,end_year,programs) VALUES (2,'Houston',2019,2021,6); | SELECT MAX(programs) FROM community_policing WHERE city = 'Houston' AND start_year <= 2020 AND end_year >= 2018; |
Identify customers who haven't made any transactions in the last month. | CREATE TABLE customers (customer_id INT,name VARCHAR(50),region VARCHAR(50)); CREATE TABLE transactions (transaction_id INT,customer_id INT,amount DECIMAL(10,2),transaction_date DATE); | SELECT c.customer_id, c.name, c.region FROM customers c LEFT JOIN transactions t ON c.customer_id = t.customer_id AND t.transaction_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) WHERE t.transaction_id IS NULL; |
Identify galleries with the highest and lowest average value of artworks on display. | CREATE TABLE Art (id INT,title VARCHAR(255),artist_id INT,gallery_id INT,value INT); CREATE TABLE Gallery (id INT,name VARCHAR(255)); | SELECT Gallery.name, AVG(Art.value) AS avg_value FROM Gallery JOIN Art ON Gallery.id = Art.gallery_id GROUP BY Gallery.name ORDER BY avg_value DESC LIMIT 1; |
What is the percentage of total rural population in Sub-Saharan Africa that has access to clean water in 2021? | CREATE TABLE RuralPopulation (region TEXT,year INTEGER,clean_water_access BOOLEAN); INSERT INTO RuralPopulation (region,year,clean_water_access) VALUES ('Sub-Saharan Africa',2021,TRUE),('Sub-Saharan Africa',2021,FALSE),('Sub-Saharan Africa',2021,TRUE),('Sub-Saharan Africa',2021,TRUE),('Sub-Saharan Africa',2021,FALSE); | SELECT (COUNT(*) FILTER (WHERE clean_water_access = TRUE) * 100.0 / COUNT(*)) AS percentage FROM RuralPopulation WHERE region = 'Sub-Saharan Africa' AND year = 2021; |
What is the minimum number of points scored by a player in a basketball game in the 'basketball_games' table? | CREATE TABLE basketball_games (id INT,home_team VARCHAR(50),away_team VARCHAR(50),date DATE,points_home INT,points_away INT); INSERT INTO basketball_games (id,home_team,away_team,date,points_home,points_away) VALUES (1,'Los Angeles Lakers','Golden State Warriors','2022-02-01',110,100); INSERT INTO basketball_games (id,home_team,away_team,date,points_home,points_away) VALUES (2,'Brooklyn Nets','Philadelphia 76ers','2022-03-05',120,115); | SELECT MIN(points_home), MIN(points_away) FROM basketball_games; |
Update the health equity metric scores for the South region to 80. | CREATE TABLE HealthEquityMetrics (MetricID INT,Score INT,Region VARCHAR(15)); INSERT INTO HealthEquityMetrics (MetricID,Score,Region) VALUES (1,85,'Northeast'),(2,92,'Midwest'),(3,78,'South'),(4,88,'West'); | UPDATE HealthEquityMetrics SET Score = 80 WHERE Region = 'South'; |
What is the maximum budget of transportation departments that have not yet adopted open data policies? | CREATE TABLE departments (id INT,name VARCHAR(50),budget INT,open_data BOOLEAN); INSERT INTO departments (id,name,budget,open_data) VALUES (1,'Education',15000000,true),(2,'Transportation',20000000,false); | SELECT MAX(budget) as max_budget FROM departments WHERE name = 'Transportation' AND open_data = false; |
List the top 3 most popular workout types in Texas by total duration in minutes. | CREATE TABLE users (id INT,state VARCHAR(20)); CREATE TABLE workout_data (id INT,user_id INT,type VARCHAR(20),duration INT,date DATE); | SELECT type, SUM(duration) as total_duration FROM workout_data w JOIN users u ON w.user_id = u.id WHERE u.state = 'Texas' GROUP BY type ORDER BY total_duration DESC LIMIT 3; |
Find the total number of art pieces owned by museums in California and Texas. | CREATE TABLE Museums (name VARCHAR(255),state VARCHAR(255),num_art_pieces INT); | SELECT SUM(num_art_pieces) FROM Museums WHERE state IN ('California', 'Texas'); |
What is the total inventory value of vegetarian items? | CREATE TABLE suppliers(supplier_id INT,name TEXT,location TEXT);CREATE TABLE menu_items(item_id INT,name TEXT,type TEXT,price DECIMAL,supplier_id INT); INSERT INTO suppliers VALUES (1,'GreenVeggies','California'); INSERT INTO menu_items VALUES (1,'Veggie Burger','Vegetarian',7.50,1); | SELECT SUM(menu_items.price) FROM menu_items JOIN suppliers ON menu_items.supplier_id = suppliers.supplier_id WHERE menu_items.type = 'Vegetarian'; |
Find the average price and quantity of garments in the 'garments' table, for each garment type, and display the results in descending order based on the average price. | CREATE TABLE garments (garment_id INTEGER,garment_type TEXT,garment_color TEXT,price INTEGER,quantity INTEGER); INSERT INTO garments (garment_id,garment_type,garment_color,price,quantity) VALUES (1,'t-shirt','red',20,100),(2,'jeans','blue',50,75),(3,'hoodie','black',30,120),(4,'skirt','green',60,50); | SELECT garment_type, AVG(price) AS avg_price, AVG(quantity) AS avg_quantity FROM garments GROUP BY garment_type ORDER BY avg_price DESC; |
What is the percentage of sustainable investments in the Americas? | CREATE TABLE sustainable_investments (id INT,region VARCHAR(255),sustainable BOOLEAN); INSERT INTO sustainable_investments (id,region,sustainable) VALUES (1,'Americas',TRUE),(2,'Europe',FALSE),(3,'Americas',TRUE); | SELECT region, COUNT(*) * 100.0 / SUM(COUNT(*)) OVER () FROM sustainable_investments WHERE region = 'Americas' GROUP BY region; |
What is the total waste generated in the city of Seattle in 2020? | CREATE TABLE waste_generation (city VARCHAR(20),year INT,total_waste INT); INSERT INTO waste_generation (city,year,total_waste) VALUES ('Seattle',2019,120000),('Seattle',2021,135000); | SELECT SUM(total_waste) FROM waste_generation WHERE city = 'Seattle' AND year = 2020; |
Find the player with the highest number of home runs in each season, for every player. | CREATE TABLE players (player_id INT,player_name VARCHAR(100),position VARCHAR(50),team VARCHAR(50),games_played INT,at_bats INT,hits INT,home_runs INT,rbi INT); INSERT INTO players (player_id,player_name,position,team,games_played,at_bats,hits,home_runs,rbi) VALUES (1,'John Doe','Outfield','Red Sox',120,450,120,25,75); INSERT INTO players (player_id,player_name,position,team,games_played,at_bats,hits,home_runs,rbi) VALUES (2,'Jane Smith','Infield','Yankees',130,500,145,30,80); | SELECT player_name, season, MAX(home_runs) as max_homeruns FROM (SELECT player_name, DATE_PART('year', game_date) as season, home_runs FROM games JOIN players ON games.player_id = players.player_id) subquery GROUP BY player_name, season; |
What is the average billing rate for attorneys in the 'billing' table? | CREATE TABLE billing (attorney_id INT,client_id INT,hours FLOAT,rate FLOAT); INSERT INTO billing (attorney_id,client_id,hours,rate) VALUES (1,101,10,300),(2,102,8,350),(3,103,12,250); | SELECT AVG(rate) FROM billing; |
How many vehicles have been serviced in the NYC subway system in the last 30 days? | CREATE TABLE subway_vehicles (id INT,type VARCHAR(10),last_service DATE); INSERT INTO subway_vehicles (id,type,last_service) VALUES (1,'Car','2022-06-01'),(2,'Bus','2022-06-15'),(3,'Train','2022-07-01'); | SELECT COUNT(*) FROM subway_vehicles WHERE last_service >= DATEADD(day, -30, CURRENT_DATE); |
What are the total defense contract amounts awarded to the top 10 defense contractors? | CREATE TABLE defense_contractors (id INT,contractor_id VARCHAR(50),contractor_name VARCHAR(100),industry VARCHAR(50)); CREATE TABLE defense_contractor_contracts (id INT,contract_id VARCHAR(50),contractor_id VARCHAR(50),contract_amount DECIMAL(10,2)); | SELECT c.contractor_name, SUM(dc.contract_amount) AS total_contracts FROM defense_contractor_contracts dc INNER JOIN defense_contractors c ON dc.contractor_id = c.contractor_id WHERE c.industry = 'Defense' GROUP BY c.contractor_name ORDER BY total_contracts DESC LIMIT 10; |
Insert new records for 3 labor rights advocates who joined AdvocacyGroupB in the year 2022, with their respective advocate IDs, regions, and join dates. | CREATE TABLE AdvocacyGroups (AdvocacyGroupID INT,AdvocacyGroupName VARCHAR(50)); CREATE TABLE AdvocatesData (AdvocateID INT,AdvocacyGroupID INT,RegionID INT,Date DATE); | INSERT INTO AdvocatesData (AdvocateID, AdvocacyGroupID, RegionID, Date) VALUES (1001, (SELECT AdvocacyGroupID FROM AdvocacyGroups WHERE AdvocacyGroupName = 'AdvocacyGroupB'), 1, '2022-01-01'), (1002, (SELECT AdvocacyGroupID FROM AdvocacyGroups WHERE AdvocacyGroupName = 'AdvocacyGroupB'), 2, '2022-01-02'), (1003, (SELECT AdvocacyGroupID FROM AdvocacyGroups WHERE AdvocacyGroupName = 'AdvocacyGroupB'), 3, '2022-01-01'); |
Which education programs are focused on protecting marine animals? | CREATE TABLE education_programs (id INT,name VARCHAR(50),focus VARCHAR(30)); CREATE VIEW marine_programs AS SELECT * FROM education_programs WHERE focus LIKE '%marine%'; | SELECT name FROM marine_programs; |
What is the consumer rating for the top 3 cosmetic products in India? | CREATE TABLE india_cosmetics (product_id INT,product_name VARCHAR(50),consumer_rating FLOAT); INSERT INTO india_cosmetics (product_id,product_name,consumer_rating) VALUES (2001,'Lipstick X',4.7),(2002,'Foundation Y',4.3),(2003,'Mascara Z',4.5),(2004,'Eye Liner W',3.9),(2005,'Blush V',4.1); | SELECT product_name, consumer_rating FROM india_cosmetics WHERE product_id IN (SELECT product_id FROM india_cosmetics ORDER BY consumer_rating DESC LIMIT 3); |
Which community health workers have served the most culturally diverse communities in the last two years? | CREATE TABLE community_health_workers (worker_id INT,cultural_diversity INT,last_two_years BOOLEAN); INSERT INTO community_health_workers (worker_id,cultural_diversity,last_two_years) VALUES (1,50,TRUE),(2,75,TRUE),(3,25,FALSE); | SELECT c.worker_id, c.cultural_diversity FROM community_health_workers c WHERE c.last_two_years = TRUE ORDER BY c.cultural_diversity DESC; |
List all excavation sites located in 'South America' and the number of artifacts associated with each site. | CREATE TABLE excavation_sites (id INT,site_name VARCHAR(50),location VARCHAR(50),num_artifacts INT); INSERT INTO excavation_sites (id,site_name,location,num_artifacts) VALUES (1,'Site A','USA',30),(2,'Site B','Mexico',45),(3,'Site C','Canada',25),(4,'Site D','Brazil',60),(5,'Site E','Argentina',55); | SELECT site_name, num_artifacts FROM excavation_sites WHERE location IN ('Brazil', 'Argentina'); |
List all unique genetic research experiments conducted in Germany. | CREATE SCHEMA if not exists genetics;CREATE TABLE if not exists genetics.experiments (id INT PRIMARY KEY,name VARCHAR(100),location VARCHAR(100)); INSERT INTO genetics.experiments (id,name,location) VALUES (1,'ExpA','Berlin'),(2,'ExpB','Munich'),(3,'ExpC','Hamburg'),(4,'ExpD','Frankfurt'),(5,'ExpE','Berlin'); | SELECT DISTINCT name FROM genetics.experiments WHERE location = 'Germany'; |
What is the total budget for agricultural innovation projects in the 'rural_innovation' table? | CREATE TABLE rural_innovation (id INT,project_name VARCHAR(50),budget FLOAT); INSERT INTO rural_innovation (id,project_name,budget) VALUES (1,'Precision Agriculture',500000.00),(2,'Organic Farming',350000.00); | SELECT SUM(budget) FROM rural_innovation WHERE project_name LIKE 'agricultural%'; |
What is the average transaction value for the month of January 2022? | CREATE TABLE transactions (transaction_id INT,transaction_date DATE,transaction_category VARCHAR(255),transaction_value DECIMAL(10,2)); INSERT INTO transactions (transaction_id,transaction_date,transaction_category,transaction_value) VALUES (1,'2022-01-02','Food',75.00),(2,'2022-01-05','Electronics',350.00),(3,'2022-01-10','Clothing',200.00); | SELECT AVG(transaction_value) as avg_transaction_value FROM transactions WHERE transaction_date BETWEEN '2022-01-01' AND '2022-01-31'; |
Create a table named 'vessel_safety' | CREATE TABLE IF NOT EXISTS vessel_safety (id INT PRIMARY KEY,vessel_name VARCHAR(255),safety_inspection_date DATE); | CREATE TABLE vessel_safety (id INT PRIMARY KEY, vessel_name VARCHAR(255), safety_inspection_date DATE); |
How many members have a heart rate over 100 during cycling? | CREATE TABLE Members (ID INT,HeartRate INT,Activity VARCHAR(20)); INSERT INTO Members (ID,HeartRate,Activity) VALUES (1,110,'Cycling'); | SELECT COUNT(*) FROM Members WHERE HeartRate > 100 AND Activity = 'Cycling'; |
How can I find the total installed capacity of renewable energy projects? | CREATE TABLE projects (id INT,name VARCHAR(50),location VARCHAR(50),capacity INT,primary_fuel VARCHAR(10)); INSERT INTO projects VALUES (1,'Solar Farm A','California',5000,'Solar'),(2,'Wind Farm B','Texas',6000,'Wind'),(3,'Hydro Plant C','Washington',7000,'Hydro'); | SELECT SUM(capacity) FROM projects WHERE primary_fuel IN ('Solar', 'Wind', 'Hydro'); |
What is the total budget for all programs that start in the second quarter? | CREATE TABLE Programs (id INT,program TEXT,budget FLOAT,start_date DATE,end_date DATE); INSERT INTO Programs (id,program,budget,start_date,end_date) VALUES (1,'Education',5000,'2022-04-01','2022-06-30'),(2,'Health',7000,'2022-01-01','2022-12-31'); | SELECT SUM(budget) FROM Programs WHERE EXTRACT(QUARTER FROM start_date) = 2; |
What is the total revenue generated by music albums released in the year 2020? | CREATE TABLE albums (id INT,title TEXT,release_year INT,revenue INT); INSERT INTO albums (id,title,release_year,revenue) VALUES (1,'Album 1',2019,5000000),(2,'Album 2',2020,7000000),(3,'Album 3',2018,6000000),(4,'Album 4',2020,8000000); | SELECT SUM(albums.revenue) FROM albums WHERE albums.release_year = 2020; |
How many sustainable projects are there in each city? | CREATE TABLE city (id INT,name VARCHAR(255),population INT,sustainable_projects INT); INSERT INTO city (id,name,population,sustainable_projects) VALUES (1,'San Francisco',884363,450); INSERT INTO city (id,name,population,sustainable_projects) VALUES (2,'Los Angeles',4000000,650); INSERT INTO city (id,name,population,sustainable_projects) VALUES (3,'New York',8500000,1500); | SELECT name, SUM(sustainable_projects) as total_sustainable_projects FROM city GROUP BY name; |
What is the total capacity of renewable energy projects in the city of Berlin? | CREATE TABLE berlin_renewable_energy (project_id INT,project_name VARCHAR(255),city VARCHAR(255),type VARCHAR(255),capacity FLOAT); INSERT INTO berlin_renewable_energy (project_id,project_name,city,type,capacity) VALUES (1,'Berlin Solar Farm','Berlin','Solar',50.0); INSERT INTO berlin_renewable_energy (project_id,project_name,city,type,capacity) VALUES (2,'Windpark Berlin','Berlin','Wind',75.0); | SELECT SUM(capacity) FROM berlin_renewable_energy WHERE city = 'Berlin'; |
What is the average temperature per year for each Arctic research station? | CREATE TABLE arctic_stations (id INT,name TEXT,location TEXT,temperature DECIMAL(5,2)); INSERT INTO arctic_stations (id,name,location,temperature) VALUES (1,'Station A','Greenland',2.3),(2,'Station B','Canada',-5.2); | SELECT name, AVG(temperature) as avg_temp, YEAR(time) as year FROM arctic_weather JOIN arctic_stations ON arctic_weather.station_id = arctic_stations.id GROUP BY name, YEAR(time) |
How many times did each strain of cannabis concentrate sell at each dispensary in Q2 2022? | CREATE TABLE concentrate_strain_sales (dispensary_id INT,sale_date DATE,strain_id INT,quantity INT); INSERT INTO concentrate_strain_sales (dispensary_id,sale_date,strain_id,quantity) VALUES (1,'2022-04-01',4,25),(1,'2022-04-15',5,15),(1,'2022-05-05',6,10),(2,'2022-04-03',4,30),(2,'2022-04-30',6,15),(2,'2022-05-20',4,20); | SELECT s.name, d.name, SUM(css.quantity) as total_sales FROM concentrate_strain_sales css JOIN strains s ON css.strain_id = s.id JOIN dispensaries d ON css.dispensary_id = d.id WHERE css.sale_date BETWEEN '2022-04-01' AND '2022-06-30' GROUP BY s.name, d.name; |
Total CO2 emissions for flights from Canada to Asia in 2022 | CREATE TABLE flights (origin VARCHAR(255),destination VARCHAR(255),co2_emissions INT); INSERT INTO flights (origin,destination,co2_emissions) VALUES ('Canada','China',30000),('Canada','Japan',35000); | SELECT SUM(co2_emissions) FROM flights WHERE origin = 'Canada' AND destination IN ('China', 'Japan') AND YEAR(flight_date) = 2022; |
How many artifacts were found at each excavation site? | CREATE TABLE artifacts_count (site_id INT,artifact_count INT); INSERT INTO artifacts_count (site_id,artifact_count) VALUES (1,20),(2,15),(3,12); | SELECT site_id, COUNT(*) OVER (PARTITION BY site_id) AS artifact_count FROM artifacts; |
What is the maximum ocean acidity level for each exploration mission? | CREATE TABLE exploration_missions (mission_name VARCHAR(255),location VARCHAR(255),acidity FLOAT); INSERT INTO exploration_missions (mission_name,location,acidity) VALUES ('Mission1','Location1',6.5),('Mission2','Location2',7.2); | SELECT mission_name, MAX(acidity) as max_acidity FROM exploration_missions GROUP BY mission_name; |
What is the oldest art piece in the 'ArtHeritage' table? | CREATE TABLE ArtHeritage (id INT,name VARCHAR(50),type VARCHAR(50),year INT,country VARCHAR(50)); INSERT INTO ArtHeritage (id,name,type,year,country) VALUES (1,'Pottery','Art',2005,'Mexico'); INSERT INTO ArtHeritage (id,name,type,year,country) VALUES (2,'Woven Baskets','Art',1950,'USA'); | SELECT name, type, year, country FROM (SELECT name, type, year, country, MIN(year) OVER () as min_year FROM ArtHeritage) t WHERE year = min_year; |
What are the names and locations of farmers who have diversified their crops in the 'rural_development' database? | CREATE TABLE farmers (farmer_id INT,name TEXT,location TEXT,crops TEXT); INSERT INTO farmers (farmer_id,name,location,crops) VALUES (1,'James Johnson','Villageville','Corn,Wheat'),(2,'Emily Brown','Farmland','Soybean,Rice'); | SELECT name, location FROM farmers WHERE LENGTH(REGEXP_SPLIT_TO_TABLE(crops, ', ')) > 1; |
What is the maximum duration (in days) of missions to Jupiter and which spacecraft was used for each? | CREATE TABLE spacecraft_missions (spacecraft_id INT,mission_id INT,mission_duration INT); INSERT INTO spacecraft_missions (spacecraft_id,mission_id,mission_duration) VALUES (1,1,300),(2,2,500),(3,3,600); CREATE TABLE space_missions (mission_id INT,name TEXT,destination TEXT); INSERT INTO space_missions (mission_id,name,destination) VALUES (1,'Europa One','Jupiter'),(2,'Ganymede Explorer','Jupiter'),(3,'Callisto Discovery','Jupiter'); CREATE TABLE spacecrafts (spacecraft_id INT,name TEXT); INSERT INTO spacecrafts (spacecraft_id,name) VALUES (1,'Galileo'),(2,'Juno'),(3,'JUICE'); | SELECT s.name AS spacecraft_name, sm.mission_duration FROM spacecraft_missions sm JOIN space_missions m ON sm.mission_id = m.mission_id JOIN spacecrafts s ON sm.spacecraft_id = s.spacecraft_id WHERE m.destination = 'Jupiter' ORDER BY sm.mission_duration DESC; |
What is the average budget allocated for military innovation by countries in the Asia-Pacific region? | CREATE TABLE military_innovation (country VARCHAR(50),budget INT); INSERT INTO military_innovation (country,budget) VALUES ('China',5000000),('Japan',3000000),('India',4000000); | SELECT AVG(budget) FROM military_innovation WHERE country IN ('China', 'Japan', 'India', 'Australia', 'South Korea'); |
What is the minimum number of reps completed in the deadlift exercise by members aged 40 or above? | CREATE TABLE members(id INT,age INT); INSERT INTO members (id,age) VALUES (1,45),(2,35); CREATE TABLE reps(id INT,member_id INT,exercise VARCHAR(15),reps INT); INSERT INTO reps (id,member_id,exercise,reps) VALUES (1,1,'deadlift',10),(2,2,'squat',8); | SELECT MIN(reps) FROM reps r JOIN members m ON r.member_id = m.id WHERE m.age >= 40 AND r.exercise = 'deadlift'; |
Update the pollution level of the Gulf of Mexico in 2019 to 5.2. | CREATE TABLE pollution_records (location TEXT,year INTEGER,pollution_level REAL); INSERT INTO pollution_records (location,year,pollution_level) VALUES ('Gulf of Mexico',2018,4.5),('Gulf of Mexico',2019,3.2),('Gulf of Mexico',2020,7.8); | UPDATE pollution_records SET pollution_level = 5.2 WHERE location = 'Gulf of Mexico' AND year = 2019; |
What are the top 2 most preferred desserts among customers in Tokyo? | CREATE TABLE Customers (customer_id INT,customer_name TEXT,favorite_dessert TEXT,city TEXT); INSERT INTO Customers (customer_id,customer_name,favorite_dessert,city) VALUES (1,'Tanaka Sato','Mochi','Tokyo'); | SELECT favorite_dessert, COUNT(*) AS count FROM Customers WHERE city = 'Tokyo' GROUP BY favorite_dessert ORDER BY count DESC LIMIT 2; |
Update the name of the hotel with an id of 1 in the hotels table | CREATE TABLE hotels (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255)); INSERT INTO hotels (id,name,country) VALUES (1,'Eco-Friendly Hotel','Sweden'); INSERT INTO hotels (id,name,country) VALUES (2,'Sustainable Resort','Costa Rica'); | UPDATE hotels SET name = 'Green Hotel' WHERE id = 1; |
List the names and types of all vessels in the 'vessels' table that were involved in an accident in the 'accidents' table. | CREATE TABLE vessels (id INT PRIMARY KEY,name VARCHAR(50),type VARCHAR(50)); CREATE TABLE accidents (id INT PRIMARY KEY,vessel_id INT,date DATE,description TEXT); | SELECT vessels.name, vessels.type FROM vessels INNER JOIN accidents ON vessels.id = accidents.vessel_id; |
Find the maximum and minimum temperature recorded in the arctic. | CREATE TABLE temperature_records (station_id INT,timestamp TIMESTAMP,temperature FLOAT); | SELECT MAX(temperature) AS max_temperature, MIN(temperature) AS min_temperature FROM temperature_records; |
What is the number of songs in the folk genre that have a song_length greater than 250 seconds? | CREATE TABLE genres (genre VARCHAR(10),song_id INT,song_length FLOAT); INSERT INTO genres (genre,song_id,song_length) VALUES ('folk',25,280.3),('folk',26,265.4),('folk',27,245.1); | SELECT COUNT(*) FROM genres WHERE genre = 'folk' AND song_length > 250; |
What are the names and birthdates of policyholders who have a policy in both the 'Auto' and 'Life' categories? | CREATE TABLE Policyholder (PolicyholderID INT,Name TEXT,Birthdate DATE,PolicyType TEXT); INSERT INTO Policyholder (PolicyholderID,Name,Birthdate,PolicyType) VALUES (1,'John Doe','1980-05-01','Auto'),(2,'Jane Smith','1990-10-15','Life'),(3,'Mike Johnson','1975-02-22','Auto'),(4,'Alice Williams','2000-03-27','Life'); | SELECT Name, Birthdate FROM Policyholder WHERE PolicyType = 'Auto' INTERSECT SELECT Name, Birthdate FROM Policyholder WHERE PolicyType = 'Life'; |
Determine the total number of players who have played game X in the 'PlayerGames' table | CREATE TABLE PlayerGames (PlayerID INT,GameID INT,GameWon BOOLEAN); CREATE TABLE Games (GameID INT,GameName VARCHAR(255)); INSERT INTO Games (GameID,GameName) VALUES (1,'GameX'),(2,'GameY'),(3,'GameZ'); | SELECT COUNT(DISTINCT PlayerID) as TotalPlayers FROM PlayerGames JOIN Games ON PlayerGames.GameID = Games.GameID WHERE Games.GameName = 'GameX'; |
List crops affected by pests in the last 60 days | CREATE TABLE pest_data (crop_type TEXT,pest_incident DATE); INSERT INTO pest_data (crop_type,pest_incident) VALUES ('Corn','2022-01-01'),('Soybeans','2022-01-02'),('Corn','2022-01-15'); | SELECT DISTINCT crop_type FROM pest_data WHERE pest_incident >= DATE(NOW()) - INTERVAL 60 DAY; |
What is the difference in Yttrium production between the maximum and minimum producers in 2021? | CREATE TABLE yttrium_production (id INT,year INT,producer VARCHAR(255),yttrium_prod FLOAT); INSERT INTO yttrium_production (id,year,producer,yttrium_prod) VALUES (1,2021,'China',1234.5),(2,2021,'USA',234.5),(3,2021,'Australia',678.9),(4,2021,'Myanmar',345.6),(5,2021,'India',901.2); | SELECT MAX(yttrium_prod) - MIN(yttrium_prod) FROM yttrium_production WHERE year = 2021; |
What are the names of the vessels that have transported goods to or from the ports of Los Angeles and Long Beach? | CREATE TABLE ports (port_id INT,port_name VARCHAR(50)); INSERT INTO ports (port_id,port_name) VALUES (1,'Los Angeles'),(2,'Long Beach'); CREATE TABLE vessel_port (vessel_id INT,port_id INT); INSERT INTO vessel_port (vessel_id,port_id) VALUES (1,1),(2,2),(3,1),(4,2); CREATE TABLE vessels (vessel_id INT,vessel_name VARCHAR(50)); INSERT INTO vessels (vessel_id,vessel_name) VALUES (1,'Vessel A'),(2,'Vessel B'),(3,'Vessel C'),(4,'Vessel D'); | SELECT DISTINCT v.vessel_name FROM vessels v JOIN vessel_port vp ON v.vessel_id = vp.vessel_id JOIN ports p ON vp.port_id = p.port_id WHERE p.port_name IN ('Los Angeles', 'Long Beach'); |
How many public schools and hospitals are there in each state of the United States, as of 2022? | CREATE TABLE Facilities (State VARCHAR(50),Type VARCHAR(50),Count INT,Year INT); INSERT INTO Facilities (State,Type,Count,Year) VALUES ('Alabama','Schools',1500,2022),('Alabama','Hospitals',200,2022),('Alaska','Schools',200,2022),('Alaska','Hospitals',50,2022); | SELECT State, Type, SUM(Count) as TotalFacilities FROM Facilities WHERE Year = 2022 GROUP BY State, Type; |
What is the total biomass of fish for each species at Location A? | CREATE TABLE farm_locations (location VARCHAR,fish_id INT); CREATE TABLE fish_stock (fish_id INT,species VARCHAR,biomass FLOAT); INSERT INTO farm_locations (location,fish_id) VALUES ('Location A',1),('Location B',2),('Location A',3),('Location C',4); INSERT INTO fish_stock (fish_id,species,biomass) VALUES (1,'Tilapia',500.0),(2,'Salmon',800.0),(3,'Trout',300.0),(4,'Bass',700.0); | SELECT fs.species, SUM(fs.biomass) FROM fish_stock fs JOIN farm_locations fl ON fs.fish_id = fl.fish_id WHERE fl.location = 'Location A' GROUP BY fs.species; |
Insert new records into the 'climate_mitigation_targets' table with the following details: (1, 'China', 'Emissions', '2030', 30) | CREATE TABLE climate_mitigation_targets (id INT,country VARCHAR(255),sector VARCHAR(255),year INT,target FLOAT); | INSERT INTO climate_mitigation_targets (id, country, sector, year, target) VALUES (1, 'China', 'Emissions', 2030, 30); |
What is the minimum visitor age for each exhibition? | CREATE TABLE exhibitions (id INT,exhibition_name VARCHAR(50),visitor_age INT); INSERT INTO exhibitions (id,exhibition_name,visitor_age) VALUES (1,'Art Show',15),(2,'Science Fair',8),(3,'History Expo',12); | SELECT exhibition_name, MIN(visitor_age) FROM exhibitions GROUP BY exhibition_name; |
How many broadband subscribers are there in 'suburban' regions? | CREATE TABLE subscribers (id INT,type TEXT,region TEXT); INSERT INTO subscribers (id,type,region) VALUES (1,'mobile','urban'); INSERT INTO subscribers (id,type,region) VALUES (2,'broadband','suburban'); INSERT INTO subscribers (id,type,region) VALUES (3,'mobile','rural'); INSERT INTO subscribers (id,type,region) VALUES (4,'broadband','urban'); | SELECT COUNT(*) FROM subscribers WHERE type = 'broadband' AND region = 'suburban'; |
Which countries have the most accessible technology initiatives? | CREATE TABLE country (name VARCHAR(50),initiatives INT); INSERT INTO country (name,initiatives) VALUES ('USA',15),('Canada',12),('India',18),('Brazil',10); | SELECT name FROM country ORDER BY initiatives DESC; |
Find the number of artworks by each artist in the 'impressionists' table. | CREATE TABLE artist (id INT,name VARCHAR(50)); INSERT INTO artist (id,name) VALUES (1,'Monet'),(2,'Renoir'),(3,'Degas'); CREATE TABLE impressionists (artist_id INT,artwork VARCHAR(50)); INSERT INTO impressionists (artist_id,artwork) VALUES (1,'Water Lilies'),(1,'Impression,Sunrise'),(2,'Dance at Le Moulin de la Galette'),(2,'Luncheon of the Boating Party'),(3,'Dancers at the Barre'),(3,'Ballet Rehearsal'); | SELECT a.name, COUNT(i.artist_id) AS num_artworks FROM artist a JOIN impressionists i ON a.id = i.artist_id GROUP BY a.id, a.name; |
How many wastewater treatment plants are there in the Asian region? | CREATE TABLE regions (id INT,name VARCHAR(50),PRIMARY KEY(id)); INSERT INTO regions (id,name) VALUES (1,'North America'),(2,'South America'),(3,'Asia'),(4,'Europe'),(5,'Africa'); CREATE TABLE wastewater_treatment_plants (id INT,region INT,PRIMARY KEY(id),FOREIGN KEY (region) REFERENCES regions(id)); INSERT INTO wastewater_treatment_plants (id,region) VALUES (1,1),(2,1),(3,3),(4,3),(5,3); | SELECT COUNT(*) as num_plants FROM wastewater_treatment_plants wwtp JOIN regions r ON wwtp.region = r.id WHERE r.name = 'Asia'; |
Identify the total number of telescopes and their types in each location. | CREATE TABLE telescopes (id INT,telescope_name VARCHAR(255),location VARCHAR(255),telescope_type VARCHAR(255),launch_date DATE); INSERT INTO telescopes (id,telescope_name,location,telescope_type,launch_date) VALUES (1,'Hubble Space Telescope','LEO','Optical','1990-04-24'); | SELECT location, telescope_type, COUNT(*) as total_telescopes FROM telescopes GROUP BY location, telescope_type; |
Delete all readings with a temperature below -2.0 degrees Celsius | CREATE TABLE weather_extreme (id INT,date DATE,temperature DECIMAL(5,2)); INSERT INTO weather_extreme | DELETE FROM weather_extreme WHERE temperature < -2.0; |
What is the average recycling rate (in percentage) for countries in the European Union for the year 2020? | CREATE TABLE recycling_rates (country VARCHAR(50),rate FLOAT); INSERT INTO recycling_rates (country,rate) VALUES ('Germany',60),('France',55),('Italy',45); | SELECT AVG(rate) FROM recycling_rates WHERE country IN ('Germany', 'France', 'Italy') AND YEAR(date) = 2020; |
What is the number of clients and total liabilities value for each sector? | CREATE TABLE clients (id INT,name VARCHAR(255),sector VARCHAR(255),liabilities DECIMAL(10,2)); INSERT INTO clients (id,name,sector,liabilities) VALUES (1,'Emma White','Healthcare',120000.00),(2,'Liam Black','Healthcare',180000.00),(3,'Noah Gray','Banking',220000.00),(4,'Olivia Brown','Banking',280000.00),(5,'Ethan Green','Technology',50000.00),(6,'Harper Blue','Retail',90000.00); | SELECT sector, COUNT(*), SUM(liabilities) FROM clients GROUP BY sector; |
What is the average energy consumption and standard deviation for renewable energy projects in a specific country, ordered by the average energy consumption in ascending order? | CREATE TABLE renewable_energy_projects (id INT,name VARCHAR(50),city VARCHAR(50),state VARCHAR(50),country VARCHAR(50),energy_type VARCHAR(50),capacity_mw FLOAT,energy_consumption FLOAT,PRIMARY KEY (id)); | SELECT country, AVG(energy_consumption) as avg_energy_consumption, STDDEV(energy_consumption) as stddev_energy_consumption FROM renewable_energy_projects WHERE country = 'CountryName' GROUP BY country ORDER BY AVG(energy_consumption); |
Create a view to show average mental health score by month | CREATE VIEW AverageMentalHealthByMonth AS SELECT DATE_TRUNC('month',AssessmentDate) AS Month,AVG(MentalHealthScore) AS AverageScore FROM StudentsMentalHealth GROUP BY Month; | CREATE VIEW AverageMentalHealthByMonth AS SELECT DATE_TRUNC('month', AssessmentDate) AS Month, AVG(MentalHealthScore) AS AverageScore FROM StudentsMentalHealth GROUP BY Month; |
What is the average salary for employees of companies that have not received ethical manufacturing certifications? | CREATE TABLE companies (company_id INT,certified TEXT);CREATE TABLE employees (employee_id INT,company_id INT,salary DECIMAL); | SELECT AVG(e.salary) FROM employees e INNER JOIN companies c ON e.company_id = c.company_id WHERE c.certified = 'no'; |
How many cruelty-free makeup products were sold in Canada last year? | CREATE TABLE sales (id INT,product_id INT,quantity INT,sale_date DATE); CREATE TABLE products (id INT,name TEXT,is_cruelty_free BOOLEAN,country TEXT); | SELECT COUNT(*) FROM sales JOIN products ON sales.product_id = products.id WHERE products.is_cruelty_free = true AND YEAR(sale_date) = YEAR(CURRENT_DATE) - 1 AND products.country = 'Canada'; |
List all the virtual reality games and their respective designers | CREATE TABLE VR_Games (id INT,name VARCHAR(50),designer VARCHAR(50)); INSERT INTO VR_Games (id,name,designer) VALUES (1,'Beat Saber','Jan Kozlovsky'),(2,'Job Simulator','Alex Schwartz'),(3,'Superhot VR','Tomasz Kaczmarczyk'); | SELECT name, designer FROM VR_Games; |
What is the average energy consumption of households in Indonesia? | CREATE TABLE households (id INT,country VARCHAR(255),energy_consumption FLOAT); INSERT INTO households (id,country,energy_consumption) VALUES (1,'Indonesia',250.5),(2,'Indonesia',275.6),(3,'Indonesia',210.3); | SELECT AVG(energy_consumption) FROM households WHERE country = 'Indonesia'; |
Find the difference in the number of financial capability programs offered by each bank, before and after a specified date? | CREATE TABLE FINANCIAL_CAPABILITY_PROGRAMS (BANK_NAME VARCHAR(50),PROGRAM_NAME VARCHAR(50),START_DATE DATE); INSERT INTO FINANCIAL_CAPABILITY_PROGRAMS VALUES ('Bank F','Program A','2020-01-01'); INSERT INTO FINANCIAL_CAPABILITY_PROGRAMS VALUES ('Bank F','Program B','2020-02-01'); INSERT INTO FINANCIAL_CAPABILITY_PROGRAMS VALUES ('Bank G','Program C','2020-03-01'); INSERT INTO FINANCIAL_CAPABILITY_PROGRAMS VALUES ('Bank G','Program D','2020-04-01'); | SELECT BANK_NAME, COUNT(*) - LAG(COUNT(*)) OVER (PARTITION BY BANK_NAME ORDER BY START_DATE) DIFFERENCE FROM FINANCIAL_CAPABILITY_PROGRAMS WHERE START_DATE < '2020-05-01' GROUP BY BANK_NAME, START_DATE ORDER BY BANK_NAME, START_DATE; |
What is the total carbon offset by country? | CREATE TABLE project (id INT,name TEXT,country TEXT,carbon_offset INT); INSERT INTO project (id,name,country,carbon_offset) VALUES (1,'Solar Farm','USA',5000); | SELECT country, SUM(carbon_offset) FROM project GROUP BY country; |
Identify the top 3 most popular sustainable brands | CREATE TABLE brands (id INT,brand_name VARCHAR(20),is_sustainable BOOLEAN,revenue DECIMAL(10,2)); INSERT INTO brands (id,brand_name,is_sustainable,revenue) VALUES (1,'Brand A',true,50000.00),(2,'Brand B',false,70000.00),(3,'Brand C',true,60000.00),(4,'Brand D',false,40000.00),(5,'Brand E',true,80000.00); | SELECT brand_name, is_sustainable, SUM(revenue) FROM brands WHERE is_sustainable = true GROUP BY brand_name ORDER BY SUM(revenue) DESC LIMIT 3; |
Find the number of students who have never taken a course with more than 40 students. | CREATE TABLE student_course_stats (student_id INT,course_id INT,num_students INT); INSERT INTO student_course_stats (student_id,course_id,num_students) VALUES (1,1,45),(2,2,35),(3,3,55),(4,1,45); | SELECT COUNT(*) FROM student_course_stats WHERE num_students <= 40; |
List all military aircraft carriers and their respective classes in the 'Aircraft_Carriers' table. | CREATE SCHEMA IF NOT EXISTS defense_security;CREATE TABLE IF NOT EXISTS defense_security.Aircraft_Carriers (id INT PRIMARY KEY,carrier_name VARCHAR(255),class VARCHAR(255));INSERT INTO defense_security.Aircraft_Carriers (id,carrier_name,class) VALUES (1,'USS Gerald R. Ford','Gerald R. Ford'),(2,'USS Nimitz','Nimitz'),(3,'USS John C. Stennis','Nimitz'); | SELECT carrier_name, class FROM defense_security.Aircraft_Carriers; |
What is the average attendance at events in the 'events' table for each event type? | CREATE TABLE events (event_id INT,name VARCHAR(50),type VARCHAR(50),attendance INT); INSERT INTO events (event_id,name,type,attendance) VALUES (1,'Art Exhibit','Painting',1500); INSERT INTO events (event_id,name,type,attendance) VALUES (2,'Theater Performance','Play',850); INSERT INTO events (event_id,name,type,attendance) VALUES (3,'Art Exhibit','Sculpture',1200); | SELECT type, AVG(attendance) as avg_attendance FROM events GROUP BY type; |
What are the names of the animals in the 'endangered_animals' table that are not already included in the 'animal_population' table? | CREATE TABLE animal_population (id INT,animal_name VARCHAR(50)); CREATE TABLE endangered_animals (id INT,animal_name VARCHAR(50)); | SELECT e.animal_name FROM endangered_animals e LEFT JOIN animal_population a ON e.animal_name = a.animal_name WHERE a.animal_name IS NULL; |
What is the total number of heritage sites and language speakers? | CREATE TABLE heritage_sites_4 (id INT,type VARCHAR(50),name VARCHAR(100),region VARCHAR(50)); INSERT INTO heritage_sites_4 (id,type,name,region) VALUES (1,'Historic Site','Angkor Wat','Southeast Asia'),(2,'Museum','British Museum','United Kingdom'); CREATE TABLE languages_3 (id INT,language VARCHAR(50),speakers INT); INSERT INTO languages_3 (id,language,speakers) VALUES (1,'Mandarin',1197000000),(2,'Spanish',460000000),(3,'English',379000000); | SELECT (SELECT COUNT(*) FROM heritage_sites_4) + (SELECT SUM(speakers) FROM languages_3); |
What's the maximum and minimum gas price for smart contracts in Asia in the last week? | CREATE TABLE smart_contracts (id INT,gas_price DECIMAL(10,2),country VARCHAR(255)); INSERT INTO smart_contracts (id,gas_price,country) VALUES (1,20.5,'China'),(2,25.0,'Japan'),(3,18.7,'India'),(4,30.2,'Singapore'),(5,22.9,'Vietnam'); CREATE TABLE smart_contract_transactions (id INT,smart_contract_id INT,transaction_date DATE,gas_price DECIMAL(10,2)); INSERT INTO smart_contract_transactions (id,smart_contract_id,transaction_date,gas_price) VALUES (1,1,'2022-02-01',22.5),(2,2,'2022-02-03',23.0),(3,3,'2022-02-05',19.7),(4,4,'2022-02-07',32.2),(5,5,'2022-02-09',25.9); | SELECT MAX(gas_price), MIN(gas_price) FROM smart_contract_transactions JOIN smart_contracts ON smart_contract_transactions.smart_contract_id = smart_contracts.id WHERE transaction_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK) AND country IN ('China', 'Japan', 'India', 'Singapore', 'Vietnam'); |
What are the top 2 cruelty-free cosmetic products by sales in the African market? | CREATE TABLE cosmetic_products (product_id INT,product_name VARCHAR(50),is_cruelty_free BOOLEAN,sales_volume INT,market VARCHAR(10)); INSERT INTO cosmetic_products (product_id,product_name,is_cruelty_free,sales_volume,market) VALUES (1,'Lip Gloss',true,500,'AF'),(2,'Mascara',false,400,'AF'),(3,'Eyeshadow',true,600,'AF'); | SELECT product_name, SUM(sales_volume) FROM cosmetic_products WHERE is_cruelty_free = true GROUP BY product_name ORDER BY SUM(sales_volume) DESC LIMIT 2; |
What is the average number of patients who visited each clinic per day? | CREATE TABLE clinic_visits (clinic_name TEXT,visit_date DATE); INSERT INTO clinic_visits (clinic_name,visit_date) VALUES ('Clinic A','2021-01-05'),('Clinic A','2021-02-12'),('Clinic B','2021-03-20'),('Clinic B','2021-03-20'),('Clinic C','2021-03-20'); CREATE TABLE clinic_visits_extended (clinic_name TEXT,visit_date DATE,patient_count INTEGER); INSERT INTO clinic_visits_extended (clinic_name,visit_date,patient_count) VALUES ('Clinic A','2021-01-05',2),('Clinic A','2021-02-12',3),('Clinic B','2021-03-20',1),('Clinic B','2021-03-20',1),('Clinic C','2021-03-20',1); | SELECT AVG(patient_count) FROM (SELECT clinic_name, COUNT(*) AS patient_count FROM clinic_visits_extended GROUP BY clinic_name, visit_date) |
What is the total number of accidents for each aircraft manufacturer? | CREATE SCHEMA if not exists aerospace;CREATE TABLE if not exists aerospace.aircraft (id INT PRIMARY KEY,name VARCHAR(50),model VARCHAR(50),manufacturer VARCHAR(50),accidents INT); INSERT INTO aerospace.aircraft (id,name,model,manufacturer,accidents) VALUES (1,'Boeing','737','Boeing',3),(2,'Boeing','747','Boeing',2),(3,'Airbus','A320','Airbus',6); | SELECT manufacturer, SUM(accidents) as total_accidents FROM aerospace.aircraft GROUP BY manufacturer; |
Which recycling plants in the United States process more than 5 types of waste? | CREATE TABLE recycling_plants (name TEXT,country TEXT,waste_types INTEGER); INSERT INTO recycling_plants (name,country,waste_types) VALUES ('Recycling Plant 1','USA',6),('Recycling Plant 2','USA',4),('Recycling Plant 3','Canada',5); | SELECT name FROM recycling_plants WHERE country = 'USA' AND waste_types > 5; |
Which gender has the highest union membership rate in the education sector? | CREATE TABLE genders (id INT,gender VARCHAR(10)); INSERT INTO genders (id,gender) VALUES (1,'Male'),(2,'Female'),(3,'Other'); CREATE TABLE education_sectors (sector_id INT,sector_name VARCHAR(255)); INSERT INTO education_sectors (sector_id,sector_name) VALUES (1,'Primary Education'),(2,'Secondary Education'),(3,'Higher Education'); CREATE TABLE union_membership_by_gender (id INT,gender_id INT,sector_id INT,membership_rate DECIMAL(5,2)); INSERT INTO union_membership_by_gender (id,gender_id,sector_id,membership_rate) VALUES (1,1,1,0.72),(2,2,2,0.81),(3,3,3,0.68); | SELECT gender, MAX(membership_rate) FROM union_membership_by_gender u JOIN genders g ON u.gender_id = g.id JOIN education_sectors e ON u.sector_id = e.sector_id GROUP BY gender; |
Count the number of visitors per country | CREATE TABLE Visitor (id INT,name TEXT,country TEXT); INSERT INTO Visitor (id,name,country) VALUES (1,'Alice','France'),(2,'Bob','Japan'),(3,'Charlie','France'); | SELECT country, COUNT(*) FROM Visitor GROUP BY country; |
Find total funding for AI safety projects in Europe. | CREATE TABLE ai_safety_projects (project_name TEXT,funding INTEGER,country TEXT); | SELECT SUM(funding) FROM ai_safety_projects WHERE country IN ('Germany', 'France', 'UK', 'Italy', 'Spain'); |
What is the total number of crimes reported in 2021? | CREATE TABLE crimes (id INT,report_date DATE,crime_type VARCHAR(20)); INSERT INTO crimes (id,report_date,crime_type) VALUES (1,'2021-01-01','Murder'),(2,'2021-01-02','Theft'),(3,'2021-01-03','Assault'); | SELECT COUNT(*) FROM crimes WHERE report_date BETWEEN '2021-01-01' AND '2021-12-31'; |
What is the minimum salary for employees hired in Q2 of 2021? | CREATE TABLE Hiring (HireID INT,HireDate DATE,Department VARCHAR(20),Salary FLOAT); INSERT INTO Hiring (HireID,HireDate,Department,Salary) VALUES (1,'2021-04-01','IT',60000),(2,'2021-05-15','IT',65000),(3,'2021-06-01','HR',55000); | SELECT MIN(Salary) FROM Hiring WHERE HireDate BETWEEN '2021-04-01' AND '2021-06-30'; |
Insert new record with digital divide data 'DDDataE' in digital_divide table | CREATE TABLE digital_divide (region VARCHAR(255),internet_speed FLOAT,updated_on DATE); | INSERT INTO digital_divide (region, internet_speed, updated_on) VALUES ('Europe', 150.5, CURDATE()); |
How many garments of the 'Dresses' category were sold in the second half of 2020? | CREATE TABLE sales_category (sale_id INT,sale_date DATE,category VARCHAR(20),quantity INT); INSERT INTO sales_category (sale_id,sale_date,category,quantity) VALUES (1,'2020-07-05','Dresses',10),(2,'2020-08-10','Tops',15),(3,'2020-09-20','Dresses',20),(4,'2020-10-15','Jackets',5),(5,'2020-11-25','Dresses',15),(6,'2020-12-05','Tops',12); | SELECT SUM(quantity) FROM sales_category WHERE category = 'Dresses' AND sale_date BETWEEN '2020-07-01' AND '2020-12-31'; |
Which unions were involved in collective bargaining for the 'education' sector? | CREATE TABLE unions (id INT,name TEXT,sector TEXT); INSERT INTO unions (id,name,sector) VALUES (1,'Union A','education'),(2,'Union B','healthcare'); CREATE TABLE bargaining (id INT,union_id INT,sector TEXT); INSERT INTO bargaining (id,union_id,sector) VALUES (1,1,'education'),(2,2,'healthcare'); | SELECT u.name FROM unions u INNER JOIN bargaining b ON u.id = b.union_id WHERE u.sector = 'education'; |
Who are the 'creative_ai' contributors from 'Europe'? | CREATE TABLE creative_ai (id INT PRIMARY KEY,contributor_name TEXT,country TEXT); INSERT INTO creative_ai (id,contributor_name,country) VALUES (1,'John Doe','USA'),(2,'Jane Smith','Canada'),(3,'Pedro Sanchez','Spain'); | SELECT contributor_name FROM creative_ai WHERE country = 'Spain'; |
What is the total water consumption in liters for the month of August 2020 for the city of New York? | CREATE TABLE WaterConsumption (ID INT,City VARCHAR(20),Consumption FLOAT,Date DATE); INSERT INTO WaterConsumption (ID,City,Consumption,Date) VALUES (5,'New York',200,'2020-08-01'),(6,'New York',195,'2020-08-02'),(7,'New York',210,'2020-08-03'),(8,'New York',200,'2020-08-04'); | SELECT SUM(Consumption) FROM WaterConsumption WHERE City = 'New York' AND Date >= '2020-08-01' AND Date <= '2020-08-31' |
What was the total revenue for the 'Vegan' menu category in February 2021? | CREATE TABLE restaurant_revenue(menu_category VARCHAR(20),revenue DECIMAL(10,2),order_date DATE); INSERT INTO restaurant_revenue(menu_category,revenue,order_date) VALUES ('Vegan',1500,'2021-02-01'),('Vegan',1800,'2021-02-03'),('Vegan',2000,'2021-02-12'); | SELECT SUM(revenue) FROM restaurant_revenue WHERE menu_category = 'Vegan' AND order_date >= '2021-02-01' AND order_date <= '2021-02-28'; |
What is the average transaction amount for customers in the West region? | CREATE TABLE customers (customer_id INT,name VARCHAR(50),region VARCHAR(20)); INSERT INTO customers (customer_id,name,region) VALUES (1,'John Doe','West'),(2,'Jane Smith','East'); CREATE TABLE transactions (transaction_id INT,customer_id INT,amount DECIMAL(10,2)); INSERT INTO transactions (transaction_id,customer_id,amount) VALUES (1,1,100.00),(2,1,200.00),(3,2,50.00); | SELECT AVG(t.amount) FROM customers c INNER JOIN transactions t ON c.customer_id = t.customer_id WHERE c.region = 'West'; |
What was the average attendance at music events? | CREATE TABLE event_attendance (id INT,event_category VARCHAR(10),attendee_count INT); INSERT INTO event_attendance (id,event_category,attendee_count) VALUES (1,'Music',200),(2,'Music',300),(3,'Music',250),(4,'Dance',150),(5,'Dance',200); | SELECT AVG(attendee_count) FROM event_attendance WHERE event_category = 'Music'; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.