instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the distribution of case outcomes by court location, ordered by the number of cases? | CREATE TABLE outcomes (id INT,location VARCHAR(255),result VARCHAR(255)); INSERT INTO outcomes (id,location,result) VALUES (1,'Denver','Guilty'); INSERT INTO outcomes (id,location,result) VALUES (2,'Boulder','Not Guilty'); | SELECT location, result, COUNT(*) as case_count, ROW_NUMBER() OVER(PARTITION BY location ORDER BY COUNT(*) DESC) as sequence FROM outcomes GROUP BY location, result; |
Which military technologies have been discontinued since 2015? | CREATE TABLE MilitaryTechnologies (Tech VARCHAR(50),YearDiscontinued INT); INSERT INTO MilitaryTechnologies (Tech,YearDiscontinued) VALUES ('Landmines',2015),('Chemical Weapons',2016),('Biological Weapons',2017),('Cluster Bombs',2018),('Tactical Nuclear Weapons',2019); | SELECT Tech FROM MilitaryTechnologies WHERE YearDiscontinued IS NOT NULL; |
What is the average amount of climate finance spent by organizations of each size? | CREATE TABLE org_climate_finance (org_size VARCHAR(20),amount FLOAT); INSERT INTO org_climate_finance (org_size,amount) VALUES ('small',20000),('medium',50000),('large',75000),('extra_large',100000); | SELECT org_size, AVG(amount) FROM org_climate_finance GROUP BY org_size; |
Which exhibition categories had the most and least visitors? | CREATE TABLE visitors_exhibitions (visitor_id INT,exhibition_id INT,exhibition_category VARCHAR(10)); INSERT INTO visitors_exhibitions (visitor_id,exhibition_id,exhibition_category) VALUES (1,1,'Art'),(2,2,'Science'); | SELECT exhibition_category, COUNT(visitor_id) AS num_visitors FROM visitors_exhibitions GROUP BY exhibition_category ORDER BY num_visitors DESC, exhibition_category; |
What is the average length of time a painting is on display, per artist, at the 'Artistic Wonders' gallery, ordered from longest to shortest display time? | CREATE TABLE Artists (ArtistID INT,ArtistName VARCHAR(50),Nationality VARCHAR(50),ActiveYears INT);CREATE TABLE Paintings (PaintingID INT,PaintingName VARCHAR(50),ArtistID INT,DisplayStart DATE,DisplayEnd DATE);CREATE TABLE Gallery (GalleryID INT,GalleryName VARCHAR(50),City VARCHAR(50));INSERT INTO Artists VALUES (1,'... | SELECT ArtistName, AVG(DATEDIFF(DisplayEnd, DisplayStart)) AS AvgDisplayDays FROM Paintings JOIN Artists ON Paintings.ArtistID = Artists.ArtistID WHERE GalleryName = 'Artistic Wonders' GROUP BY ArtistName ORDER BY AvgDisplayDays DESC; |
What's the total number of relief supplies received by urban areas in 2020? | CREATE TABLE relief_supplies (id INT PRIMARY KEY,area VARCHAR(20),year INT,quantity INT); INSERT INTO relief_supplies (id,area,year,quantity) VALUES (1,'urban',2018,200),(2,'rural',2018,300),(3,'urban',2019,150),(4,'urban',2020,500),(5,'rural',2020,450); | SELECT SUM(quantity) FROM relief_supplies WHERE area = 'urban' AND year = 2020; |
What is the minimum number of accidents for commercial airlines in Australia since 2000? | CREATE TABLE flight_safety_records (airline VARCHAR(50),country VARCHAR(50),accidents INT,year INT); INSERT INTO flight_safety_records (airline,country,accidents,year) VALUES ('Qantas','Australia',0,2000),('Virgin Australia','Australia',1,2001); | SELECT MIN(accidents) FROM flight_safety_records WHERE country = 'Australia' AND year >= 2000; |
What is the total number of hotels with sustainable practices in Oceania? | CREATE TABLE hotels (hotel_id INT,name TEXT,country TEXT,has_sustainable_practices BOOLEAN); INSERT INTO hotels (hotel_id,name,country,has_sustainable_practices) VALUES (1,'Eco Resort','Australia',true),(2,'Green Hotel','New Zealand',true); CREATE TABLE countries (country TEXT,continent TEXT); INSERT INTO countries (co... | SELECT COUNT(*) FROM hotels h JOIN countries c ON h.country = c.country WHERE has_sustainable_practices = true AND c.continent = 'Oceania'; |
Provide the average biosensor output for each biosensor type, grouped by the country of origin. | CREATE TABLE biosensors (id INT,type TEXT,output FLOAT,country TEXT); INSERT INTO biosensors (id,type,output,country) VALUES (1,'Glucose',120,'USA'); INSERT INTO biosensors (id,type,output,country) VALUES (2,'Cholesterol',200,'Canada'); | SELECT country, type, AVG(output) FROM biosensors GROUP BY country, type; |
How many polar bears were sighted in the 'polar_bear_sightings' table during the summer months (June, July, August) in the year 2019? | CREATE TABLE polar_bear_sightings (id INT,date DATE,sighted BOOLEAN); | SELECT COUNT(*) FROM polar_bear_sightings WHERE MONTH(date) IN (6, 7, 8) AND sighted = TRUE AND YEAR(date) = 2019; |
How many players won more than 50 matches in "Shooter Game 2022"? | CREATE TABLE Matches (MatchID INT,PlayerID INT,Game VARCHAR(50),Wins INT); INSERT INTO Matches (MatchID,PlayerID,Game,Wins) VALUES (1,1,'Shooter Game 2022',45),(2,1,'Shooter Game 2022',52),(3,2,'Shooter Game 2022',60),(4,3,'Racing Simulator 2022',30); | SELECT COUNT(*) FROM Matches WHERE Game = 'Shooter Game 2022' AND Wins > 50; |
What is the total number of employees who have changed departments in the last year? | CREATE TABLE Employees (Employee_ID INT,First_Name VARCHAR(20),Last_Name VARCHAR(20),Department VARCHAR(20),Country VARCHAR(20),Join_Date DATE,Previous_Department VARCHAR(20),Change_Date DATE); | SELECT COUNT(*) FROM Employees WHERE Change_Date >= DATEADD(year, -1, GETDATE()); |
Get the number of products with a specific label | CREATE TABLE products (id INT,name VARCHAR(255),labels TEXT); | SELECT COUNT(*) FROM products WHERE labels LIKE '%label%'; |
Identify the average budget and total number of completed rural infrastructure projects in the 'rural_development' database, for projects located in the 'North' region, sorted by average budget in descending order. | CREATE TABLE infrastructure_projects (id INT PRIMARY KEY,name TEXT,region TEXT,status TEXT,budget INT); INSERT INTO infrastructure_projects (id,name,region,status,budget) VALUES (1,'Highway Construction','North','Completed',2000000); INSERT INTO infrastructure_projects (id,name,region,status,budget) VALUES (2,'Bridge R... | SELECT region, AVG(budget) as avg_budget, COUNT(id) as total_completed_projects FROM infrastructure_projects WHERE region = 'North' AND status = 'Completed' GROUP BY region ORDER BY avg_budget DESC; |
What is the maximum number of streams for any artist from Australia? | CREATE TABLE Streaming (id INT,artist VARCHAR(50),streams INT,country VARCHAR(50)); INSERT INTO Streaming (id,artist,streams,country) VALUES (1,'Sia',1000000,'Australia'),(2,'Taylor Swift',2000000,'USA'),(3,'Kylie Minogue',1800000,'Australia'); | SELECT MAX(streams) FROM Streaming WHERE country = 'Australia'; |
What is the total salary paid by job role? | CREATE TABLE Employees (EmployeeID int,FirstName varchar(50),LastName varchar(50),JobRole varchar(50),Ethnicity varchar(50),Salary decimal(10,2)); INSERT INTO Employees (EmployeeID,FirstName,LastName,JobRole,Ethnicity,Salary) VALUES (1,'Sophia','Gonzales','Software Engineer','Hispanic',85000); INSERT INTO Employees (Em... | SELECT JobRole, SUM(Salary) as TotalSalary FROM Employees GROUP BY JobRole; |
Show waste generation metrics for the 'Southeast' region's cities, excluding 'Atlanta'. | CREATE TABLE Cities (id INT,city VARCHAR(255),region VARCHAR(255)); INSERT INTO Cities (id,city,region) VALUES (1,'Atlanta','Southeast'),(2,'Miami','Southeast'),(3,'Tampa','Southeast'); CREATE TABLE WasteMetrics (id INT,city VARCHAR(255),generation_tons INT); INSERT INTO WasteMetrics (id,city,generation_tons) VALUES (1... | SELECT WasteMetrics.city, WasteMetrics.generation_tons FROM Cities JOIN WasteMetrics ON Cities.city = WasteMetrics.city WHERE Cities.region = 'Southeast' AND Cities.city != 'Atlanta'; |
What is the market share of each OTA in terms of total bookings for all hotels? | CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,country TEXT);CREATE TABLE ota_bookings (booking_id INT,hotel_id INT,ota_name TEXT,revenue FLOAT); INSERT INTO hotels (hotel_id,hotel_name,country) VALUES (1,'Hotel X','USA'),(2,'Hotel Y','Canada'); INSERT INTO ota_bookings (booking_id,hotel_id,ota_name,revenue) VALUES ... | SELECT ota.ota_name, SUM(ob.revenue) as total_revenue, (SUM(ob.revenue) / (SELECT SUM(ob2.revenue) FROM ota_bookings ob2)) as market_share FROM hotels h INNER JOIN ota_bookings ob ON h.hotel_id = ob.hotel_id INNER JOIN (SELECT DISTINCT hotel_id, ota_name FROM ota_bookings) ota ON h.hotel_id = ota.hotel_id GROUP BY ota.... |
What is the average range of military aircrafts owned by each country in the 'military_tech' table? | CREATE TABLE military_tech (country VARCHAR(50),aircraft_name VARCHAR(50),range INT); INSERT INTO military_tech (country,aircraft_name,range) VALUES ('USA','F-15',3000),('USA','F-22',2960),('Russia','Su-27',3500),('Russia','MiG-35',2000),('China','J-20',2400); | SELECT AVG(range) as avg_range, country FROM military_tech GROUP BY country; |
What is the total healthcare spending in 2021 for rural communities in Australia? | CREATE TABLE healthcare_spending (community_id INT,year INT,amount DECIMAL(10,2)); INSERT INTO healthcare_spending (community_id,year,amount) VALUES (1,2021,50000.50); | SELECT SUM(amount) FROM healthcare_spending WHERE community_id = 1 AND year = 2021 AND location = 'rural Australia'; |
What is the adoption rate of electric vehicles in urban areas? | CREATE TABLE VehicleSales (id INT,vehicle_type VARCHAR(50),location VARCHAR(50),sales INT); INSERT INTO VehicleSales (id,vehicle_type,location,sales) VALUES (1,'Electric','City A',1000); | SELECT (SUM(CASE WHEN vehicle_type = 'Electric' THEN sales ELSE 0 END) / SUM(sales)) * 100 AS adoption_rate FROM VehicleSales WHERE location LIKE 'City%'; |
Identify the most common types of security incidents that have occurred in the last week and display the top 5. | CREATE TABLE incident_types (id INT,incident_type VARCHAR(255)); INSERT INTO incident_types (id,incident_type) VALUES (1,'Malware'); INSERT INTO incident_types (id,incident_type) VALUES (2,'Phishing'); INSERT INTO incident_types (id,incident_type) VALUES (3,'Unauthorized Access'); | SELECT incident_type, COUNT(*) as total_incidents FROM security_incidents WHERE incident_date >= DATEADD(week, -1, GETDATE()) GROUP BY incident_type ORDER BY total_incidents DESC LIMIT 5; |
What is the total funding received by biotech startups in the USA? | CREATE TABLE biotech_startups (id INT,name VARCHAR(50),budget DECIMAL(10,2),region VARCHAR(50)); INSERT INTO biotech_startups (id,name,budget,region) VALUES (1,'BioGenBrazil',3000000.00,'Brazil'); INSERT INTO biotech_startups (id,name,budget,region) VALUES (2,'InnoLife',8000000.00,'USA'); INSERT INTO biotech_startups (... | SELECT SUM(budget) FROM biotech_startups WHERE region = 'USA'; |
What is the average age of astronauts at their first space mission? | CREATE TABLE astronauts(id INT,name VARCHAR(50),age INT,first_mission_year INT); INSERT INTO astronauts VALUES(1,'Yang Liwei',38,2003),(2,'Valentina Tereshkova',26,1963); | SELECT AVG(age - first_mission_year) FROM astronauts; |
What is the total CO2 emission reduction achieved by hotels in Australia? | CREATE TABLE co2_emissions (hotel_name TEXT,country TEXT,co2_reduction INT); INSERT INTO co2_emissions (hotel_name,country,co2_reduction) VALUES ('Sydney Eco Hotel','Australia',1000),('Melbourne Green Hotel','Australia',1200); | SELECT SUM(co2_reduction) FROM co2_emissions WHERE country = 'Australia'; |
Delete records of drugs with sales less than $10,000 in Q1 2022 | CREATE TABLE sales (drug_id INT,sales_amount DECIMAL(10,2),quarter INT,year INT); INSERT INTO sales (drug_id,sales_amount,quarter,year) VALUES (1,12000,1,2022),(2,8000,1,2022),(3,15000,1,2022) | DELETE FROM sales WHERE sales_amount < 10000 AND quarter = 1 AND year = 2022 |
What is the average property size in urban areas with green building certifications? | CREATE TABLE properties (id INT,size FLOAT,location VARCHAR(20),green_building_certified BOOLEAN); INSERT INTO properties (id,size,location,green_building_certified) VALUES (1,1500,'urban',true),(2,1200,'rural',false); | SELECT AVG(size) FROM properties WHERE location = 'urban' AND green_building_certified = true; |
What is the average claim amount for policyholders living in 'Los Angeles'? | CREATE TABLE policyholders (id INT,name TEXT,city TEXT,state TEXT,claim_amount FLOAT); INSERT INTO policyholders (id,name,city,state,claim_amount) VALUES (1,'John Doe','Los Angeles','CA',2500.00); INSERT INTO policyholders (id,name,city,state,claim_amount) VALUES (2,'Jane Doe','Los Angeles','CA',3000.00); | SELECT AVG(claim_amount) FROM policyholders WHERE city = 'Los Angeles'; |
Delete all records for Tank9 that have a dissolved oxygen level of less than 6.0. | CREATE TABLE Tank9 (species VARCHAR(20),dissolved_oxygen FLOAT); INSERT INTO Tank9 (species,dissolved_oxygen) VALUES ('Tilapia',6.5),('Salmon',7.0),('Trout',7.5),('Tilapia',5.5),('Salmon',6.0); | DELETE FROM Tank9 WHERE dissolved_oxygen < 6.0; |
Which crop has the lowest yield in 'crop_comparison' table? | CREATE TABLE crop_comparison (farmer VARCHAR(50),crop VARCHAR(50),yield INT); INSERT INTO crop_comparison (farmer,crop,yield) VALUES ('FarmerA','corn',100),('FarmerA','wheat',80),('FarmerB','corn',110),('FarmerB','wheat',90),('FarmerC','corn',95),('FarmerC','wheat',75); | SELECT crop, MIN(yield) as lowest_yield FROM crop_comparison GROUP BY crop; |
Find the number of registered users from each country who signed up in the last month, and order by the count in descending order. | CREATE TABLE users (id INT,name VARCHAR(100),country VARCHAR(50),signup_date DATE); INSERT INTO users (id,name,country,signup_date) VALUES (1,'John Doe','USA','2022-01-01'); INSERT INTO users (id,name,country,signup_date) VALUES (2,'Jane Smith','Canada','2022-02-10'); INSERT INTO users (id,name,country,signup_date) VAL... | SELECT country, COUNT(*) as num_users FROM users WHERE signup_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY country ORDER BY num_users DESC; |
List the water conservation initiatives implemented in regions affected by severe droughts between 2017 and 2020, ordered by initiative. | CREATE TABLE conservation_initiatives(region VARCHAR(20),year INT,initiative VARCHAR(50)); INSERT INTO conservation_initiatives VALUES ('California',2017,'Water rationing'),('California',2018,'Mandatory water restrictions'),('Nevada',2019,'Smart irrigation systems'),('Nevada',2020,'Water-saving appliances'),('Arizona',... | SELECT * FROM conservation_initiatives WHERE year BETWEEN 2017 AND 2020 AND region IN ('California', 'Nevada', 'Arizona') ORDER BY initiative; |
How many articles were published per month in the past year? | CREATE TABLE articles (article_id INT,publication_date DATE); INSERT INTO articles (article_id,publication_date) VALUES (1,'2022-01-01'),(2,'2022-02-15'),(3,'2021-12-31'); | SELECT DATE_FORMAT(publication_date, '%Y-%m') as month, COUNT(*) as articles_per_month FROM articles WHERE publication_date >= DATE_SUB(NOW(), INTERVAL 1 YEAR) GROUP BY month; |
What was the average revenue per song for R&B and Hip Hop genres in 2020? | CREATE TABLE genre_songs_2020 (genre VARCHAR(255),year INT,num_songs INT,revenue FLOAT); INSERT INTO genre_songs_2020 (genre,year,num_songs,revenue) VALUES ('Pop',2020,12,3000000),('Rock',2020,15,4000000),('Electronic',2020,18,5000000),('R&B',2020,20,6000000),('Hip Hop',2020,25,7000000); | SELECT genre, AVG(revenue/num_songs) FROM genre_songs_2020 WHERE genre IN ('R&B', 'Hip Hop') GROUP BY genre; |
What is the total mineral extraction quantity for each mine, by mineral type, in 2020? | CREATE TABLE MineExtraction (mine_name VARCHAR(50),country VARCHAR(50),year INT,mineral VARCHAR(50),quantity INT); INSERT INTO MineExtraction (mine_name,country,year,mineral,quantity) VALUES ('Golden Mine','Canada',2020,'Gold',60),('Silver Mine','Mexico',2020,'Silver',75),('Iron Mine','Brazil',2020,'Iron',90); | SELECT context.mine_name, context.mineral, SUM(context.quantity) as total_quantity FROM context WHERE context.year = 2020 GROUP BY context.mine_name, context.mineral; |
Insert a new faculty member with a unique faculty_id, name, and research_interest. | CREATE TABLE faculty (faculty_id INT,name VARCHAR(50),research_interest VARCHAR(50)); | INSERT INTO faculty VALUES (3, 'Charlie Brown', 'Robotics'); |
What is the maximum salary of unionized workers in the 'Finance' industry? | CREATE TABLE Workers (EmployeeID INT,Industry VARCHAR(20),UnionMember BOOLEAN,Salary FLOAT); INSERT INTO Workers (EmployeeID,Industry,UnionMember,Salary) VALUES (1,'Finance',true,90000.0),(2,'Finance',true,95000.0),(3,'Finance',false,85000.0); | SELECT MAX(Salary) FROM Workers WHERE Industry = 'Finance' AND UnionMember = true; |
What is the maximum number of bytes transferred in a single day? | CREATE TABLE network_traffic (id INT,date DATE,bytes INT); INSERT INTO network_traffic (id,date,bytes) VALUES (1,'2022-01-01',1000),(2,'2022-01-02',2000),(3,'2022-01-03',1500),(4,'2022-01-04',500),(5,'2022-01-05',2500),(6,'2022-01-06',3000); | SELECT date, MAX(bytes) as max_bytes FROM network_traffic GROUP BY date; |
What was the total revenue generated from ticket sales in Q2 2022? | CREATE TABLE quarters (id INT,name VARCHAR(255)); INSERT INTO quarters (id,name) VALUES (1,'Q1'),(2,'Q2'),(3,'Q3'),(4,'Q4'); CREATE TABLE tickets (id INT,quarter_id INT,sale_date DATE,revenue INT); INSERT INTO tickets (id,quarter_id,sale_date,revenue) VALUES (1,2,'2022-04-01',5000),(2,2,'2022-05-01',7000),(3,2,'2022-06... | SELECT SUM(t.revenue) as total_revenue FROM tickets t JOIN quarters q ON t.quarter_id = q.id WHERE q.name = 'Q2'; |
What is the percentage of volunteers from 'France' who signed up for 'Health' programs? | CREATE TABLE volunteers (volunteer_id INT,volunteer_name TEXT,program_name TEXT,volunteer_start_date DATE); INSERT INTO volunteers (volunteer_id,volunteer_name,program_name,volunteer_start_date) VALUES (1,'Jacques Leclerc','Health Check','2022-04-01'); | SELECT 100.0 * COUNT(*) / (SELECT COUNT(*) FROM volunteers WHERE volunteer_country = 'France') AS percentage FROM volunteers WHERE program_name = 'Health' AND volunteer_country = 'France'; |
What is the name and email address of the accessibility consultant for 'GHI Foundation'? | CREATE TABLE staff (staff_id INT,staff_name TEXT,position TEXT,email TEXT,org_id INT); INSERT INTO staff (staff_id,staff_name,position,email,org_id) VALUES (1,'John Doe','Manager','johndoe@example.com',1); INSERT INTO staff (staff_id,staff_name,position,email,org_id) VALUES (2,'Jane Smith','Accessibility Consultant','j... | SELECT S.staff_name, S.email FROM staff S INNER JOIN organization O ON S.org_id = O.org_id WHERE O.org_name = 'GHI Foundation' AND S.position = 'Accessibility Consultant'; |
What is the minimum number of days required to complete a large commercial construction project in Tokyo? | CREATE TABLE Project_Timelines (Project_ID INT,City VARCHAR(50),Project_Type VARCHAR(50),Days_To_Complete INT); | SELECT MIN(Days_To_Complete) FROM Project_Timelines WHERE City = 'Tokyo' AND Project_Type = 'Commercial' AND Days_To_Complete > 30; |
What is the total number of cases in access to justice programs by program category? | CREATE TABLE access_to_justice_programs (id INT,case_number INT,program_category VARCHAR(20)); | SELECT program_category, COUNT(*) FROM access_to_justice_programs GROUP BY program_category; |
Which astronauts have completed more than 5 spacewalks and their total duration in minutes? | CREATE TABLE Astronauts (id INT,name VARCHAR(255),missions INT,spacewalks INT,total_spacewalk_minutes INT); INSERT INTO Astronauts (id,name,missions,spacewalks,total_spacewalk_minutes) VALUES (1,'Mark Kelly',5,4,245); INSERT INTO Astronauts (id,name,missions,spacewalks,total_spacewalk_minutes) VALUES (2,'Scott Kelly',5... | SELECT name, spacewalks, SUM(total_spacewalk_minutes) FROM Astronauts WHERE spacewalks > 5 GROUP BY name; |
What is the total budget allocated for programs in the Education department that start with the letter 'E'? | CREATE TABLE Education_Dept (ID INT,Program VARCHAR(255),Budget FLOAT); INSERT INTO Education_Dept (ID,Program,Budget) VALUES (1,'Elementary Education',900000),(2,'English Language Learning',800000),(3,'Extracurricular Activities',700000); | SELECT SUM(Budget) FROM Education_Dept WHERE Program LIKE 'E%'; |
What is the number of hospitals and their respective regions with more than 500 employees? | CREATE TABLE hospitals (id INT,name TEXT,region TEXT,num_employees INT); INSERT INTO hospitals VALUES (1,'Hospital A','Region A',600),(2,'Hospital B','Region B',400),(3,'Hospital C','Region A',700); | SELECT region, COUNT(*) as num_hospitals FROM hospitals WHERE num_employees > 500 GROUP BY region; |
Update the quantity of 'Organic Milk' sold to 650 for March 15th. | CREATE TABLE produce (id INT,name VARCHAR(255),qty_sold INT); INSERT INTO produce (id,name,qty_sold) VALUES (1,'Organic Milk',600),(2,'Seasonal Vegetables',700),(3,'Whole Grain Bread',800); CREATE TABLE date (id INT,date DATE); INSERT INTO date (id,date) VALUES (1,'2022-03-14'),(2,'2022-03-15'),(3,'2022-03-16'); | UPDATE produce SET qty_sold = 650 WHERE name = 'Organic Milk' AND date IN (SELECT date FROM date WHERE date = '2022-03-15'); |
Add a new department 'Marketing' and insert 2 new employees 'Alice Johnson', 'Marketing', '2020-05-15' and 'Bob Davis', 'Marketing', '2020-05-18' | CREATE SCHEMA IF NOT EXISTS hr;CREATE TABLE IF NOT EXISTS employees (id INT,name VARCHAR(50),department VARCHAR(50),hire_date DATE);CREATE TABLE IF NOT EXISTS departments (id INT,name VARCHAR(50));INSERT INTO departments (id,name) VALUES (1,'IT');INSERT INTO departments (id,name) VALUES (2,'HR');INSERT INTO employees (... | ALTER TABLE hr.departments ADD id INT;INSERT INTO hr.departments (id, name) VALUES (3, 'Marketing');INSERT INTO hr.employees (id, name, department, hire_date) VALUES (4, 'Alice Johnson', 'Marketing', '2020-05-15');INSERT INTO hr.employees (id, name, department, hire_date) VALUES (5, 'Bob Davis', 'Marketing', '2020-05-1... |
Find the maximum and minimum depths of the ocean floor mapped by project Arctic Expedition? | CREATE TABLE ocean_floor_mapping (id INT,project TEXT,location TEXT,depth FLOAT); INSERT INTO ocean_floor_mapping (id,project,location,depth) VALUES (1,'Arctic Expedition','North Pole',4000.1); INSERT INTO ocean_floor_mapping (id,project,location,depth) VALUES (2,'Atlantic Expedition','South Atlantic',7000.3); | SELECT MAX(depth), MIN(depth) FROM ocean_floor_mapping WHERE project = 'Arctic Expedition'; |
Delete the station with station_id 3 from the monorail_stations table | CREATE TABLE monorail_stations (station_id INT,station_name VARCHAR(255)); INSERT INTO monorail_stations (station_id,station_name) VALUES (1,'Downtown'),(2,'Uptown'),(3,'Suburbia'),(4,'Airport'); | DELETE FROM monorail_stations WHERE station_id = 3; |
What is the total quantity of minerals extracted by each company in each country, and the total number of employees and contractors for each company in each country? | CREATE TABLE countries (id INT,name VARCHAR(50)); CREATE TABLE companies (id INT,name VARCHAR(50)); CREATE TABLE company_sites (id INT,company_id INT,site_id INT); CREATE TABLE mining_sites (id INT,name VARCHAR(50),location VARCHAR(50),country_id INT,company_id INT); CREATE TABLE employees (id INT,site_id INT,role VARC... | SELECT co.name AS country, c.name AS company, SUM(me.quantity) AS total_minerals_extracted, SUM(e.quantity + c.quantity) AS total_workforce FROM countries co INNER JOIN mining_sites ms ON co.id = ms.country_id INNER JOIN companies c ON ms.company_id = c.id INNER JOIN company_sites cs ON c.id = cs.company_id INNER JOIN ... |
Which clinical trials were conducted by 'PharmaA' in 'RegionN' in 2022? | CREATE TABLE clinical_trials(company varchar(20),region varchar(20),year int,trial varchar(20)); INSERT INTO clinical_trials VALUES ('PharmaA','RegionN',2022,'TrialX'); | SELECT DISTINCT trial FROM clinical_trials WHERE company = 'PharmaA' AND region = 'RegionN' AND year = 2022; |
What is the total number of low-risk vulnerabilities in the healthcare sector that have not been addressed in the last 90 days, with severity 5 or lower? | CREATE TABLE vulnerabilities (id INT,sector TEXT,severity INT,last_updated DATE); INSERT INTO vulnerabilities (id,sector,severity,last_updated) VALUES (1,'Healthcare',4,'2022-11-01'); INSERT INTO vulnerabilities (id,sector,severity,last_updated) VALUES (2,'Healthcare',7,'2023-01-10'); | SELECT COUNT(*) FROM vulnerabilities WHERE sector = 'Healthcare' AND severity <= 5 AND last_updated < CURRENT_DATE - INTERVAL 90 DAY; |
List all the transactions from socially responsible lending with a transaction amount greater than $5000. | CREATE TABLE socially_responsible_lending (transaction_id INT,client_id INT,transaction_amount DECIMAL(10,2)); INSERT INTO socially_responsible_lending (transaction_id,client_id,transaction_amount) VALUES (1,4,7000.00),(2,5,6000.00),(3,6,5500.00),(4,7,8000.00); | SELECT * FROM socially_responsible_lending WHERE transaction_amount > 5000; |
What is the average duration of games played by each player in the last month? | CREATE TABLE Players (PlayerID INT,PlayerName TEXT); INSERT INTO Players (PlayerID,PlayerName) VALUES (1,'John Doe'),(2,'Jane Smith'),(3,'Alex Rodriguez'); CREATE TABLE Games (GameID INT,PlayerID INT,GameDateTime TIMESTAMP,Duration INT); INSERT INTO Games (GameID,PlayerID,GameDateTime,Duration) VALUES (1,1,'2021-01-25 ... | SELECT Players.PlayerName, AVG(Games.Duration) as AverageDuration FROM Players JOIN Games ON Players.PlayerID = Games.PlayerID WHERE Games.GameDateTime > DATE_SUB(NOW(), INTERVAL 1 MONTH) GROUP BY Players.PlayerName; |
What is the average donation per month for each donor? | CREATE TABLE donations (donor_id INT,donation_date DATE,amount DECIMAL(10,2)); INSERT INTO donations (donor_id,donation_date,amount) VALUES (1,'2021-01-01',50.00),(2,'2021-01-15',100.00),(1,'2021-03-05',200.00); | SELECT donor_id, DATE_FORMAT(donation_date, '%Y-%m') AS month, AVG(amount) AS avg_donation FROM donations GROUP BY donor_id, month; |
What is the total number of users who have engaged with content related to social justice issues in the first half of 2021? | CREATE TABLE user_interactions (id INT,user_id INT,content_type VARCHAR(50),interaction_date DATE); CREATE TABLE content (id INT,content_type VARCHAR(50),tags VARCHAR(500)); | SELECT COUNT(DISTINCT ui.user_id) as total_users FROM user_interactions ui JOIN content c ON ui.content_type = c.content_type WHERE c.tags LIKE '%social justice%' AND interaction_date >= '2021-01-01' AND interaction_date <= '2021-06-30'; |
What is the number of unique animals in the 'habitat_preservation' view that have a population of over 1000, grouped by continent? | CREATE TABLE animal_population (animal VARCHAR(50),continent VARCHAR(50),population INT); INSERT INTO animal_population (animal,continent,population) VALUES ('Amur Leopard','Asia',90),('Black Rhino','Africa',5600),('Giant Panda','Asia',1864),('Koala','Oceania',50000); CREATE VIEW habitat_preservation AS SELECT animal,C... | SELECT continent, COUNT(DISTINCT animal) FROM habitat_preservation WHERE population > 1000 GROUP BY continent; |
What are the top 3 states with the highest life expectancy, and what is the average healthcare spending in those states? | CREATE TABLE StateHealthData (State VARCHAR(255),LifeExpectancy DECIMAL(3,1),HealthcareSpending DECIMAL(10,2)); INSERT INTO StateHealthData (State,LifeExpectancy,HealthcareSpending) VALUES ('State A',80.5,7500.00),('State B',78.0,8200.00),('State C',82.0,9000.00),('State D',76.0,7000.00); | SELECT State, LifeExpectancy FROM StateHealthData ORDER BY LifeExpectancy DESC LIMIT 3; SELECT State, AVG(HealthcareSpending) FROM StateHealthData WHERE State IN ('State A', 'State C', 'State B') GROUP BY State; |
What is the maximum number of tickets sold for a single basketball game? | CREATE TABLE tickets (id INT,game_id INT,quantity INT,sport VARCHAR(50)); INSERT INTO tickets (id,game_id,quantity,sport) VALUES (1,101,500,'Basketball'); INSERT INTO tickets (id,game_id,quantity,sport) VALUES (2,102,600,'Basketball'); | SELECT MAX(quantity) FROM tickets WHERE sport = 'Basketball'; |
How many wastewater treatment plants are in Texas and New York? | CREATE TABLE states (id INT,name VARCHAR(255)); INSERT INTO states (id,name) VALUES (1,'Texas'),(2,'New York'); CREATE TABLE wastewater_treatment_plants (id INT,state_id INT,name VARCHAR(255)); INSERT INTO wastewater_treatment_plants (id,state_id,name) VALUES (1,1,'PlantA'),(2,1,'PlantB'),(3,2,'PlantC'),(4,2,'PlantD'); | SELECT state_id, COUNT(*) as num_plants FROM wastewater_treatment_plants GROUP BY state_id; |
What is the scientific name for the species "Bluehead wrasse"? | CREATE TABLE marine_species (scientific_name TEXT,common_name TEXT); INSERT INTO marine_species (scientific_name,common_name) VALUES ('Thalassoma bifasciatum','Bluehead wrasse'); | SELECT scientific_name FROM marine_species WHERE common_name = 'Bluehead wrasse'; |
Identify the most popular streaming platforms for TV shows by total number of episodes, grouped by genre. | CREATE TABLE show_episodes (id INT,title VARCHAR(255),genre VARCHAR(255),platform VARCHAR(255),episodes INT); INSERT INTO show_episodes (id,title,genre,platform,episodes) VALUES (1,'Show1','Comedy','Netflix',20),(2,'Show2','Drama','Amazon',30),(3,'Show3','Action','Netflix',15),(4,'Show4','Comedy','Hulu',12),(5,'Show5',... | SELECT platform, genre, SUM(episodes) AS total_episodes FROM show_episodes GROUP BY platform, genre ORDER BY total_episodes DESC; |
What is the total revenue generated by hotels in the 'Americas' region for the year 2022? | CREATE TABLE hotels (id INT,name TEXT,region TEXT,revenue FLOAT); INSERT INTO hotels (id,name,region,revenue) VALUES (1,'Hotel1','Americas',500000),(2,'Hotel2','Asia',600000); | SELECT SUM(revenue) FROM hotels WHERE region = 'Americas' AND YEAR(calendar) = 2022; |
List all network towers in the state of New York that have experienced outages in the past month. | CREATE TABLE network_towers (tower_id INT,location VARCHAR(50),last_outage DATE); INSERT INTO network_towers (tower_id,location,last_outage) VALUES (1,'New York City','2022-01-15'); INSERT INTO network_towers (tower_id,location,last_outage) VALUES (2,'Buffalo','2022-02-03'); | SELECT * FROM network_towers WHERE last_outage >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) AND state = 'New York'; |
What is the average playtime in minutes for players who have achieved a rank of Silver or higher in the game "Virtual Arena"? | CREATE TABLE VirtualArenaPlayers (PlayerID INT,PlayerName VARCHAR(50),PlaytimeMinutes INT,Rank VARCHAR(10)); INSERT INTO VirtualArenaPlayers VALUES (1,'AvaGarcia',550,'Silver'),(2,'MasonThomas',650,'Gold'),(3,'IsabellaMartinez',450,'Silver'),(4,'BenjaminHarris',750,'Platinum'); | SELECT AVG(PlaytimeMinutes) FROM VirtualArenaPlayers WHERE Rank IN ('Silver', 'Gold', 'Platinum'); |
Find the number of traffic accidents in each ward of the city of Chicago from the 'chicago_traffic_database' | CREATE TABLE chicago_wards (id INT PRIMARY KEY,name VARCHAR(255));CREATE TABLE traffic_accidents (id INT PRIMARY KEY,ward_id INT,FOREIGN KEY (ward_id) REFERENCES chicago_wards(id)); INSERT INTO chicago_wards (id,name) VALUES (1,'Ward 1'); INSERT INTO chicago_wards (id,name) VALUES (2,'Ward 2'); | SELECT chicago_wards.name as ward_name, COUNT(traffic_accidents.id) as accident_count FROM chicago_wards INNER JOIN traffic_accidents ON chicago_wards.id = traffic_accidents.ward_id GROUP BY chicago_wards.name; |
What are the types and unit costs of equipment that have been shipped to the Middle East? | CREATE TABLE Equipment (id INT,equipment_type VARCHAR(255),manufacturer VARCHAR(255),production_year INT,unit_cost DECIMAL(10,2)); CREATE TABLE Shipments (id INT,equipment_type VARCHAR(255),quantity INT,destination VARCHAR(255),delivery_date DATE,equipment_id INT); INSERT INTO Equipment (id,equipment_type,manufacturer,... | SELECT Equipment.equipment_type, Equipment.unit_cost FROM Equipment INNER JOIN Shipments ON Equipment.id = Shipments.equipment_id WHERE Shipments.destination = 'Middle East'; |
Show the name and size of all marine protected areas in the Southern Ocean. | CREATE TABLE marine_protected_areas (id INT,name VARCHAR(50),size FLOAT,ocean VARCHAR(20)); INSERT INTO marine_protected_areas (id,name,size,ocean) VALUES (1,'Ross Sea',1590000,'Southern'); INSERT INTO marine_protected_areas (id,name,size,ocean) VALUES (2,'Weddell Sea',1930000,'Southern'); | SELECT name, size FROM marine_protected_areas WHERE ocean = 'Southern'; |
Update the claims table to change the claim amount for policy number 9 to 3500 for claim date of '2020-03-15' | CREATE TABLE claims (claim_number INT,policy_number INT,claim_amount INT,claim_date DATE); INSERT INTO claims (claim_number,policy_number,claim_amount,claim_date) VALUES (1,9,3000,'2020-03-15'); | UPDATE claims SET claim_amount = 3500 WHERE policy_number = 9 AND claim_date = '2020-03-15'; |
What is the total number of unique IP addresses associated with each threat category for the last week? | CREATE TABLE threats (id INT,category VARCHAR(50),ip_address VARCHAR(50),threat_date DATE); INSERT INTO threats (id,category,ip_address,threat_date) VALUES (1,'Malware','192.168.1.1','2022-01-01'),(2,'Phishing','192.168.1.2','2022-01-02'); | SELECT category, COUNT(DISTINCT ip_address) as unique_ips FROM threats WHERE threat_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK) GROUP BY category; |
What was the average R&D expenditure for 'CompanyX' between 2015 and 2017? | CREATE TABLE r_and_d(company varchar(20),year int,expenditure int);INSERT INTO r_and_d VALUES ('CompanyX',2015,5000000);INSERT INTO r_and_d VALUES ('CompanyX',2016,5500000);INSERT INTO r_and_d VALUES ('CompanyX',2017,6000000); | SELECT AVG(expenditure) FROM r_and_d WHERE company = 'CompanyX' AND year BETWEEN 2015 AND 2017; |
What is the total number of attendees at events in the 'theater' category, grouped by the attendee's country of origin? | CREATE TABLE attendance (id INT,event_name TEXT,attendee_country TEXT,attendee_count INT); INSERT INTO attendance (id,event_name,attendee_country,attendee_count) VALUES (1,'Play','USA',100),(2,'Musical','UK',75); | SELECT attendee_country, SUM(attendee_count) FROM attendance WHERE event_name IN (SELECT event_name FROM events WHERE event_category = 'theater') GROUP BY attendee_country; |
What was the total revenue for each dispensary in Washington in Q3 2022? | 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 (id INT,dispensary_id INT,revenue INT,sale_date DATE); INSERT INTO Sales (id,dispensary_id,revenue,sale_date) VALUES (1,1,500,'2022... | SELECT d.name, SUM(s.revenue) AS total_revenue FROM Dispensaries d INNER JOIN Sales s ON d.id = s.dispensary_id WHERE s.sale_date BETWEEN '2022-07-01' AND '2022-09-30' GROUP BY d.name; |
How many fish are being raised in farms located in the Pacific Ocean? | CREATE TABLE salmon_farms (id INT,name TEXT,location TEXT,size INT);CREATE VIEW ocean_farms AS SELECT * FROM salmon_farms WHERE location LIKE '%Pacific%'; | SELECT SUM(size) FROM ocean_farms; |
What is the average production cost for items made of organic cotton? | CREATE TABLE products (id INT,name TEXT,material TEXT,production_cost FLOAT); INSERT INTO products (id,name,material,production_cost) VALUES (1,'T-Shirt','Organic Cotton',15.0),(2,'Pants','Organic Cotton',30.0); | SELECT AVG(production_cost) FROM products WHERE material = 'Organic Cotton'; |
Which smart city initiatives were implemented in Tokyo in 2020? | CREATE TABLE smart_city_initiatives (initiative_id INT,initiative_name VARCHAR(255),city VARCHAR(255),country VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO smart_city_initiatives (initiative_id,initiative_name,city,country,start_date,end_date) VALUES (1,'Tokyo Solar','Tokyo','JP','2020-01-01','2020-12-31'); ... | SELECT initiative_name FROM smart_city_initiatives WHERE city = 'Tokyo' AND YEAR(start_date) = 2020; |
What is the average carbon sequestration for each species? | CREATE TABLE Species (SpeciesID INT,SpeciesName TEXT,CarbonSequestration REAL); INSERT INTO Species (SpeciesID,SpeciesName,CarbonSequestration) VALUES (1,'Red Oak',12.3),(2,'White Pine',10.5),(3,'Yellow Birch',11.2); | SELECT SpeciesName, AVG(CarbonSequestration) as AverageSequestration FROM Species GROUP BY SpeciesName; |
What is the average age of astronauts from Japan during their first space mission in 2025? | CREATE TABLE AstronautsT (astronaut_name VARCHAR(30),age INT,first_mission_date DATE,nationality VARCHAR(20)); INSERT INTO AstronautsT (astronaut_name,age,first_mission_date,nationality) VALUES ('Astronaut5',50,'2025-01-01','Japan'); | SELECT AVG(age) FROM AstronautsT WHERE nationality = 'Japan' AND first_mission_date = (SELECT MIN(first_mission_date) FROM AstronautsT WHERE nationality = 'Japan' AND YEAR(first_mission_date) = 2025); |
Update the hours_served column in the volunteers table to set the value to 35.00 for the record with id = 4. | CREATE TABLE volunteers (id INT,name VARCHAR(50),hours_served FLOAT); INSERT INTO volunteers (id,name,hours_served) VALUES (4,'Olivia Thompson',25.00); | UPDATE volunteers SET hours_served = 35.00 WHERE id = 4; |
What is the total revenue for each retail store by month for the year 2022? | CREATE TABLE retail_stores (store_id INT,store_name VARCHAR(255)); INSERT INTO retail_stores (store_id,store_name) VALUES (1,'Store A'),(2,'Store B'),(3,'Store C'); CREATE TABLE sales (sale_id INT,store_id INT,sale_date DATE,revenue DECIMAL(10,2)); INSERT INTO sales (sale_id,store_id,sale_date,revenue) VALUES (1,1,'202... | SELECT s.store_id, EXTRACT(MONTH FROM s.sale_date) AS month, SUM(s.revenue) AS total_revenue FROM sales s GROUP BY s.store_id, EXTRACT(MONTH FROM s.sale_date); |
What is the average billing amount for cases in the 'criminal' schema, grouped by case type? | CREATE SCHEMA criminal; CREATE TABLE case_types (case_number INT,case_type VARCHAR(255)); CREATE TABLE billing (bill_id INT,case_number INT,amount DECIMAL(10,2)); | SELECT ct.case_type, AVG(b.amount) FROM criminal.case_types ct INNER JOIN criminal.billing b ON ct.case_number = b.case_number GROUP BY ct.case_type; |
What is the total amount donated by the donor with the id 2? | CREATE TABLE donations (id INT,donor_id INT,amount DECIMAL(10,2)); INSERT INTO donations (id,donor_id,amount) VALUES (1,2,50.00),(2,2,30.00),(3,2,100.00); | SELECT SUM(amount) FROM donations WHERE donor_id = 2; |
How many clinical trials have been conducted in 'CountryA' but not in 'CountryB'? | CREATE TABLE clinical_trials (trial_name TEXT,country TEXT); INSERT INTO clinical_trials (trial_name,country) VALUES ('Trial1','CountryA'),('Trial2','CountryB'),('Trial3','CountryA'),('Trial4','CountryC'); | SELECT COUNT(*) FROM clinical_trials WHERE country = 'CountryA' AND trial_name NOT IN (SELECT trial_name FROM clinical_trials WHERE country = 'CountryB'); |
What is the total number of sewage spills in New York in 2020, categorized by spill location and spill volume? | CREATE TABLE Spills (id INT,state VARCHAR(2),year INT,spill_location VARCHAR(10),spill_volume INT,count INT); INSERT INTO Spills (id,state,year,spill_location,spill_volume,count) VALUES (1,'NY',2020,'Street',100,20),(2,'NY',2020,'River',500,30),(3,'NY',2020,'Beach',200,10); | SELECT spill_location, spill_volume, SUM(count) FROM Spills WHERE state = 'NY' AND year = 2020 GROUP BY spill_location, spill_volume; |
List the names of all mental health campaigns in the European region. | CREATE TABLE campaigns (id INT,name VARCHAR(100),region VARCHAR(50)); INSERT INTO campaigns (id,name,region) VALUES (1,'Mind Strong','Europe'),(2,'Mental Health Matters','Europe'),(3,'Harmony','Asia'); | SELECT name FROM campaigns WHERE region = 'Europe'; |
What are the names and case IDs of all cases that have been dismissed in the state of California? | CREATE TABLE court_cases (case_id INT,case_status TEXT,case_state TEXT); INSERT INTO court_cases (case_id,case_status,case_state) VALUES (33333,'Dismissed','California'); | SELECT case_id, case_status FROM court_cases WHERE case_state = 'California' AND case_status = 'Dismissed'; |
What is the total number of polar bears in the Arctic? | CREATE TABLE PolarBearCount (id INT,region VARCHAR(20),year INT,bear_count INT); INSERT INTO PolarBearCount (id,region,year,bear_count) VALUES (1,'Arctic Archipelago',2020,125); INSERT INTO PolarBearCount (id,region,year,bear_count) VALUES (2,'Norwegian Bay',2020,87); | SELECT SUM(bear_count) FROM PolarBearCount WHERE region LIKE 'Arctic%'; |
What is the total number of properties and the total area of sustainable urban projects in the city of "Chicago"? | CREATE TABLE properties (property_id INT,area FLOAT,city_id INT,PRIMARY KEY (property_id),FOREIGN KEY (city_id) REFERENCES cities(city_id)); INSERT INTO properties (property_id,area,city_id) VALUES (1,1000.0,2),(2,1200.0,2),(3,800.0,2); CREATE TABLE sustainable_projects (project_id INT,area FLOAT,city_id INT,PRIMARY KE... | SELECT COUNT(*), SUM(sustainable_projects.area) FROM properties, sustainable_projects JOIN cities ON properties.city_id = cities.city_id AND sustainable_projects.city_id = cities.city_id WHERE cities.city_name = 'Chicago'; |
What is the total water usage by all residential users in the city of San Francisco? | CREATE TABLE residential_users (id INT,city VARCHAR(20),water_usage FLOAT); INSERT INTO residential_users (id,city,water_usage) VALUES (1,'San Francisco',15.5),(2,'San Francisco',12.3),(3,'Oakland',18.7); | SELECT SUM(water_usage) FROM residential_users WHERE city = 'San Francisco'; |
What's the highest ESG score for companies in the 'finance' sector? | CREATE TABLE companies (id INT,sector VARCHAR(20),ESG_score FLOAT); INSERT INTO companies (id,sector,ESG_score) VALUES (1,'technology',72.5),(2,'finance',85.3),(3,'technology',75.1); | SELECT MAX(ESG_score) FROM companies WHERE sector = 'finance'; |
What is the maximum water usage by any user in the state of Florida? | CREATE TABLE all_users (id INT,state VARCHAR(20),water_usage FLOAT); INSERT INTO all_users (id,state,water_usage) VALUES (1,'Florida',20.5),(2,'Florida',25.6),(3,'California',30.2); | SELECT MAX(water_usage) FROM all_users WHERE state = 'Florida'; |
Find the top 3 chemical products with the highest total sales in Canada, ordered by total sales in descending order. | CREATE TABLE products (product_id INT,product_name TEXT,country TEXT,total_sales FLOAT); INSERT INTO products (product_id,product_name,country,total_sales) VALUES (1,'Product A','Canada',50000),(2,'Product B','Canada',75000),(3,'Product C','Canada',40000),(4,'Product D','Canada',60000); | SELECT product_name, total_sales, RANK() OVER (ORDER BY total_sales DESC) as rank FROM products WHERE country = 'Canada' GROUP BY product_name HAVING rank <= 3; |
How many defense contracts were awarded to companies in California in 2020? | CREATE TABLE Contracts (ID INT,Company TEXT,State TEXT,Year INT,Value INT); INSERT INTO Contracts (ID,Company,State,Year,Value) VALUES (1,'Lockheed Martin','California',2020,1000000); INSERT INTO Contracts (ID,Company,State,Year,Value) VALUES (2,'Northrop Grumman','California',2020,1500000); | SELECT COUNT(*) FROM Contracts WHERE State = 'California' AND Year = 2020; |
What is the minimum publication date for graduate students in the English department? | CREATE TABLE graduate_students (id INT,name VARCHAR(50),department VARCHAR(50),enrollment_date DATE); CREATE TABLE publications (id INT,student_id INT,title VARCHAR(100),publication_date DATE); | SELECT MIN(publication_date) FROM publications p JOIN graduate_students gs ON p.student_id = gs.id WHERE gs.department = 'English'; |
Find the average age of members who have done a 'Cycling' workout. | CREATE TABLE Members (id INT,name VARCHAR(50),age INT); INSERT INTO Members (id,name,age) VALUES (1,'Surae',28),(2,'Javier',35),(3,'Minh',32),(4,'Elena',45); CREATE TABLE Workouts (member_id INT,workout VARCHAR(50)); INSERT INTO Workouts (member_id,workout) VALUES (1,'Cycling'),(2,'Cycling'),(3,'Yoga'),(4,'Pilates'); | SELECT AVG(age) FROM Members m JOIN Workouts w ON m.id = w.member_id WHERE w.workout = 'Cycling'; |
What is the maximum budget allocated to any public service in the city of Sydney? | CREATE TABLE public_services (name VARCHAR(255),city VARCHAR(255),budget DECIMAL(10,2)); INSERT INTO public_services (name,city,budget) VALUES ('Sydney Public Transport',10000000.00),('Sydney Parks and Gardens',9000000.00),('Sydney Opera House',8000000.00); | SELECT MAX(budget) FROM public_services WHERE city = 'Sydney'; |
What is the maximum number of animals in any single habitat? | CREATE TABLE Habitats (HabitatID INT,Habitat VARCHAR(20),AnimalCount INT); INSERT INTO Habitats (HabitatID,Habitat,AnimalCount) VALUES (1,'North America',50); INSERT INTO Habitats (HabitatID,Habitat,AnimalCount) VALUES (2,'Asia',75); INSERT INTO Habitats (HabitatID,Habitat,AnimalCount) VALUES (3,'Africa',100); | SELECT MAX(AnimalCount) FROM Habitats; |
Delete all citizen complaints related to the 'Parks and Recreation' department from the 'complaints' table. | CREATE TABLE complaints (id INT PRIMARY KEY,department_id INT,title VARCHAR(255)); | DELETE FROM complaints WHERE department_id IN (SELECT id FROM departments WHERE name = 'Parks and Recreation'); |
Delete funding records for startups not in the 'technology' sector. | CREATE TABLE funding_records (id INT,company_id INT,funding_amount INT,funding_date DATE); INSERT INTO funding_records (id,company_id,funding_amount,funding_date) VALUES (1,1,500000,'2021-03-01'),(2,2,700000,'2020-08-15'),(3,3,300000,'2019-12-20'); | DELETE FROM funding_records WHERE company_id NOT IN (SELECT id FROM companies WHERE industry = 'Technology'); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.