instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What was the minimum temperature (in Celsius) recorded in each region in 2020? | CREATE TABLE weather (id INT,region_id INT,temperature_c FLOAT,date DATE); | SELECT region_id, MIN(temperature_c) FROM weather WHERE YEAR(date) = 2020 GROUP BY region_id; |
What were the names and locations of agricultural projects that started in 2021? | CREATE TABLE AgriculturalProjects (id INT PRIMARY KEY,name VARCHAR(50),location VARCHAR(50),sector VARCHAR(20),start_date DATE,end_date DATE); INSERT INTO AgriculturalProjects (id,name,location,sector,start_date,end_date) VALUES (1,'Solar Irrigation','Rural Kenya','Agricultural Innovation','2020-01-01','2022-12-31'),(2,'Precision Farming','Rural Brazil','Agricultural Innovation','2021-01-01','2023-12-31'); | SELECT name, location FROM AgriculturalProjects WHERE start_date >= '2021-01-01' AND start_date < '2022-01-01'; |
List the number of unique organizations and total amount donated for each disaster response. | CREATE TABLE organizations (id INT,disaster_id INT,amount FLOAT); CREATE TABLE disasters (id INT,name VARCHAR(255)); | SELECT d.name, COUNT(DISTINCT organizations.id) as organization_count, SUM(organizations.amount) as total_donated FROM disasters d LEFT JOIN organizations ON d.id = organizations.disaster_id GROUP BY d.id; |
What are the details of intelligence operations in Africa? | CREATE TABLE intelligence_operations (id INT,operation_name VARCHAR(50),location VARCHAR(50)); INSERT INTO intelligence_operations (id,operation_name,location) VALUES (1,'Operation Horn of Africa','Africa'),(2,'Operation Juniper Shield','Middle East'),(3,'Operation Okra','Middle East'); | SELECT * FROM intelligence_operations WHERE location = 'Africa'; |
How many crop types were grown in each region in 2019? | CREATE TABLE Crop (id INT,type TEXT,region TEXT,planting_date DATE); | SELECT region, COUNT(DISTINCT type) as num_crop_types FROM Crop WHERE EXTRACT(YEAR FROM planting_date) = 2019 GROUP BY region; |
What is the average carbon footprint of a garment in the EcoFriendlyGarments table? | CREATE TABLE EcoFriendlyGarments (id INT,garment_type VARCHAR(255),carbon_footprint INT); INSERT INTO EcoFriendlyGarments (id,garment_type,carbon_footprint) VALUES (1,'Dress',4),(2,'Skirt',2),(3,'Jacket',6); | SELECT AVG(carbon_footprint) FROM EcoFriendlyGarments; |
What was the total circular economy initiative spending in the 'West' region in 2021? | CREATE TABLE circular_economy_initiatives (region VARCHAR(20),year INT,spending INT); INSERT INTO circular_economy_initiatives (region,year,spending) VALUES ('West',2020,900000),('West',2021,950000),('East',2020,800000),('East',2021,850000); | SELECT SUM(spending) FROM circular_economy_initiatives WHERE region = 'West' AND year = 2021; |
List the names of investors who have invested in companies that have a female founder. | CREATE TABLE Companies (id INT,name TEXT,founder_gender TEXT); INSERT INTO Companies (id,name,founder_gender) VALUES (1,'Daisy Enterprise','Female'); INSERT INTO Companies (id,name,founder_gender) VALUES (2,'Bright Star Corp','Male'); CREATE TABLE Investors (id INT,name TEXT); INSERT INTO Investors (id,name) VALUES (1,'Venture Capital 3'); INSERT INTO Investors (id,name) VALUES (2,'Angel Investor 3'); | SELECT Investors.name FROM Companies INNER JOIN Investors ON TRUE WHERE Companies.founder_gender = 'Female'; |
Display the names and sentences of all inmates who have been incarcerated for less than 3 years | CREATE TABLE inmates (inmate_id INT,inmate_name VARCHAR(255),sentence_length INT,PRIMARY KEY (inmate_id)); INSERT INTO inmates (inmate_id,inmate_name,sentence_length) VALUES (1,'Inmate 1',60),(2,'Inmate 2',36),(3,'Inmate 3',72); | SELECT inmate_name, sentence_length FROM inmates WHERE sentence_length < 36; |
Find the number of female astronauts in the US space program | CREATE TABLE astronauts (id INT,name VARCHAR(50),gender VARCHAR(10),nationality VARCHAR(50),spacecraft VARCHAR(50)); | SELECT COUNT(*) FROM astronauts WHERE gender = 'female' AND nationality = 'United States'; |
Calculate the percentage of sustainable materials used in production for each product category | CREATE TABLE sustainable_materials (sustainable_material_id INT,sustainable_material_name VARCHAR(255),product_category VARCHAR(255)); INSERT INTO sustainable_materials (sustainable_material_id,sustainable_material_name,product_category) VALUES (1,'Material X','Category X'),(2,'Material Y','Category X'),(3,'Material Z','Category Y'),(4,'Material W','Category Y'); CREATE TABLE production (production_id INT,product_id INT,sustainable_material_id INT,production_quantity INT); INSERT INTO production (production_id,product_id,sustainable_material_id,production_quantity) VALUES (1,1,1,100),(2,1,2,200),(3,2,1,250),(4,2,2,300),(5,3,3,350),(6,3,4,400),(7,4,3,450),(8,4,4,500); | SELECT product_category, SUM(production_quantity) as total_production_quantity, SUM(CASE WHEN sustainable_material_id IS NOT NULL THEN production_quantity ELSE 0 END) as sustainable_production_quantity, (SUM(CASE WHEN sustainable_material_id IS NOT NULL THEN production_quantity ELSE 0 END) / SUM(production_quantity)) * 100 as sustainable_percentage FROM production JOIN sustainable_materials ON production.sustainable_material_id = sustainable_materials.sustainable_material_id GROUP BY product_category; |
How many wheelchair-accessible stations are there in London? | CREATE TABLE Stations (StationID int,WheelchairAccessible bit); INSERT INTO Stations (StationID,WheelchairAccessible) VALUES (1,1),(2,0),(3,1); | SELECT COUNT(*) FROM Stations WHERE WheelchairAccessible = 1; |
Find the total revenue generated from sales in the 'Surrealism' genre and the number of artworks sold in Europe. | CREATE TABLE Sales (SaleID INT,ArtworkID INT,Genre VARCHAR(20),Revenue FLOAT,Location VARCHAR(20)); INSERT INTO Sales (SaleID,ArtworkID,Genre,Revenue,Location) VALUES (1,1,'Surrealism',4000.00,'France'); CREATE TABLE Artworks (ArtworkID INT,ArtworkName VARCHAR(50)); INSERT INTO Artworks (ArtworkID,ArtworkName) VALUES (1,'The Persistence of Memory'); | SELECT SUM(Sales.Revenue), COUNT(Sales.SaleID) FROM Sales INNER JOIN Artworks ON Sales.ArtworkID = Artworks.ArtworkID WHERE Sales.Genre = 'Surrealism' AND Sales.Location = 'Europe'; |
What is the average data usage per month for each mobile subscriber in the 'urban' regions, sorted alphabetically by subscriber name? | CREATE TABLE mobile_subscribers (id INT,name VARCHAR(255),state_id INT,monthly_data_usage DECIMAL(10,2));CREATE TABLE states (id INT,name VARCHAR(255),region VARCHAR(255)); | SELECT ms.name, AVG(ms.monthly_data_usage) as avg_data_usage FROM mobile_subscribers ms INNER JOIN states st ON ms.state_id = st.id WHERE st.region = 'urban' GROUP BY ms.name ORDER BY ms.name; |
Insert a new graduate student record | CREATE TABLE GraduateStudents (StudentID INT,Name VARCHAR(50),Department VARCHAR(50),AdvisorID INT); | INSERT INTO GraduateStudents (StudentID, Name, Department, AdvisorID) VALUES (1001, 'Sara Smith', 'Computer Science', 2001); |
How many impact investments were made in 'Asia' in the year 2020? | CREATE TABLE impact_investments (id INT,region VARCHAR(20),investment_year INT,investment_amount FLOAT); INSERT INTO impact_investments (id,region,investment_year,investment_amount) VALUES (1,'Asia',2020,150000),(2,'Africa',2019,120000),(3,'Asia',2020,180000); | SELECT COUNT(*) FROM impact_investments WHERE region = 'Asia' AND investment_year = 2020; |
What is the total quantity of item 'Laptop' in warehouse 'SEA-WH-01'? | CREATE TABLE warehouses (id VARCHAR(10),name VARCHAR(20),city VARCHAR(10),country VARCHAR(10)); INSERT INTO warehouses (id,name,city,country) VALUES ('SEA-WH-01','Seattle Warehouse','Seattle','USA'); CREATE TABLE inventory (item VARCHAR(10),warehouse_id VARCHAR(10),quantity INT); INSERT INTO inventory (item,warehouse_id,quantity) VALUES ('Laptop','SEA-WH-01',300); | SELECT SUM(quantity) FROM inventory WHERE item = 'Laptop' AND warehouse_id = 'SEA-WH-01'; |
Find the number of vessels that have had an incident in the Mediterranean sea | CREATE TABLE VesselIncidents (id INT,vessel_id INT,incident_type VARCHAR(50),latitude DECIMAL(9,6),longitude DECIMAL(9,6),time TIMESTAMP); | SELECT COUNT(vessel_id) FROM VesselIncidents vi WHERE ST_Intersects(ST_SetSRID(ST_MakePoint(longitude, latitude), 4326), ST_GeomFromText('POLYGON((19.45 37.00, 19.45 34.00, 29.55 34.00, 29.55 37.00, 19.45 37.00))', 4326)); |
Insert new R&D expenditure records for Q1 2024 into the r_d_expenditure table. | CREATE TABLE r_d_expenditure (drug VARCHAR(20),division VARCHAR(20),date DATE,expenditure NUMERIC(12,2)); | INSERT INTO r_d_expenditure (drug, division, date, expenditure) VALUES ('DrugD', 'Oncology', '2024-01-01', 120000.00), ('DrugE', 'Cardiology', '2024-01-01', 150000.00), ('DrugD', 'Neurology', '2024-01-01', 180000.00), ('DrugE', 'Oncology', '2024-01-01', 200000.00), ('DrugD', 'Cardiology', '2024-01-01', 130000.00), ('DrugE', 'Neurology', '2024-01-01', 90000.00); |
How many suspicious activities have been detected for each client? | CREATE TABLE fraud_detection (client_id INT,suspicious_activity VARCHAR(50),detection_date DATE); INSERT INTO fraud_detection (client_id,suspicious_activity,detection_date) VALUES (3,'Phishing attempt','2022-02-05'); INSERT INTO fraud_detection (client_id,suspicious_activity,detection_date) VALUES (4,'Account takeover','2022-02-10'); | SELECT client_id, COUNT(*) as number_of_suspicious_activities FROM fraud_detection GROUP BY client_id; |
What is the average age of healthcare workers in rural areas? | CREATE TABLE rural_healthcare_workers (id INT,name TEXT,age INT,is_rural BOOLEAN); INSERT INTO rural_healthcare_workers (id,name,age,is_rural) VALUES (1,'John Doe',35,true),(2,'Jane Smith',40,false); | SELECT AVG(age) FROM rural_healthcare_workers WHERE is_rural = true; |
What is the total number of accessible technology projects, and how many of those are in Africa? | CREATE TABLE accessible_tech_projects (id INT,country VARCHAR(2),project_accessibility VARCHAR(10)); INSERT INTO accessible_tech_projects (id,country,project_accessibility) VALUES (1,'US','yes'),(2,'CA','no'),(3,'MX','yes'),(4,'BR','yes'),(5,'AR','no'),(6,'NG','yes'),(7,'EG','no'),(8,'ZA','yes'),(9,'ET','no'),(10,'GH','yes'); | SELECT COUNT(*) FROM accessible_tech_projects WHERE project_accessibility = 'yes' AND country IN ('NG', 'EG', 'ZA', 'ET', 'GH'); |
What is the current landfill capacity in Mumbai and the projected capacity in 2035? | CREATE TABLE landfill_capacity (location VARCHAR(50),current_capacity INT,projected_capacity INT,year INT); INSERT INTO landfill_capacity (location,current_capacity,projected_capacity,year) VALUES ('Mumbai',45000,55000,2035); | SELECT location, current_capacity, projected_capacity FROM landfill_capacity WHERE location = 'Mumbai' AND year = 2035; |
Which fish species have had a decline in population in the last 6 months? | CREATE TABLE fish_population (id INT,species TEXT,population INT,date DATE); | SELECT species, (fp1.population - fp2.population) AS population_change FROM fish_population fp1 JOIN fish_population fp2 ON fp1.species = fp2.species WHERE fp1.date = (SELECT MAX(date) FROM fish_population) AND fp2.date = (SELECT MAX(date) - INTERVAL '6 months' FROM fish_population) AND population_change < 0; |
What is the total price of artworks in the 'Baroque' period and in the 'Rococo' period in the 'Berlin' museum? | CREATE TABLE Artworks (ArtworkID INT,Title VARCHAR(255),Period VARCHAR(255),MuseumID INT,Price INT); INSERT INTO Artworks VALUES (1,'The Resurrection of Christ','Baroque',5,3000000); CREATE TABLE Museums (MuseumID INT,Name VARCHAR(255),Location VARCHAR(255)); INSERT INTO Museums VALUES (5,'Gemäldegalerie','Berlin'); | SELECT SUM(Artworks.Price) FROM Artworks INNER JOIN Museums ON Artworks.MuseumID = Museums.MuseumID WHERE (Artworks.Period = 'Baroque' OR Artworks.Period = 'Rococo') AND Museums.Location = 'Berlin'; |
What is the average monthly mobile data usage for customers in California? | CREATE TABLE mobile_subscribers (subscriber_id INT,data_usage FLOAT,state VARCHAR(20)); INSERT INTO mobile_subscribers (subscriber_id,data_usage,state) VALUES (1,3.5,'NY'),(2,4.2,'NY'),(3,3.8,'NJ'),(4,5.0,'CA'),(5,4.5,'CA'); | SELECT AVG(data_usage) FROM mobile_subscribers WHERE state = 'CA'; |
What was the total investment in clean energy policy trends in China and the United Kingdom in 2018 and 2019? | CREATE TABLE clean_energy_investments (id INT,country VARCHAR(255),year INT,investment_amount INT); INSERT INTO clean_energy_investments (id,country,year,investment_amount) VALUES (1,'China',2018,4000000),(2,'United Kingdom',2019,5000000); | SELECT SUM(investment_amount) FROM clean_energy_investments WHERE country IN ('China', 'United Kingdom') AND year IN (2018, 2019); |
Identify the number of unique volunteers who participated in events in NYC in 2020 and the average number of hours they contributed. | CREATE TABLE Volunteers (VolunteerID int,EventID int,Hours decimal(5,2)); INSERT INTO Volunteers (VolunteerID,EventID,Hours) VALUES (1,100,5.5),(2,101,7.2),(3,100,3.8),(4,102,6.5),(5,101,8.0); | SELECT COUNT(DISTINCT VolunteerID), AVG(Hours) FROM Volunteers INNER JOIN (SELECT EventID FROM Events WHERE City = 'NYC') AS EventLocations ON Volunteers.EventID = EventLocations.EventID WHERE EXTRACT(YEAR FROM EventDate) = 2020; |
What is the average wildlife habitat size for each species, ranked by size? | CREATE TABLE wildlife (species VARCHAR(255),habitat_size FLOAT); INSERT INTO wildlife (species,habitat_size) VALUES ('Deer',123.4),('Bear',145.6),('Elk',167.8),('Wolf',234.6),('Fox',256.7),('Lynx',345.2); | SELECT species, AVG(habitat_size) AS avg_habitat_size FROM wildlife GROUP BY species ORDER BY AVG(habitat_size) DESC; |
What is the count of members by country, grouped by gender and city, in the 'demographics_summary' view? | CREATE TABLE member_demographics (member_id INT,age INT,gender VARCHAR(10),city VARCHAR(50),state VARCHAR(20),country VARCHAR(50)); CREATE VIEW demographics_summary AS SELECT country,gender,city,COUNT(*) as member_count FROM member_demographics GROUP BY country,gender,city; | SELECT country, gender, city, SUM(member_count) FROM demographics_summary GROUP BY country, gender, city; |
What is the minimum medical condition duration for each unique medical condition? | CREATE TABLE Astronaut_Medical_4 (Astronaut_ID INT,Medical_Condition VARCHAR(50),Medical_Condition_Duration INT); INSERT INTO Astronaut_Medical_4 (Astronaut_ID,Medical_Condition,Medical_Condition_Duration) VALUES (1,'Fatigue',14); INSERT INTO Astronaut_Medical_4 (Astronaut_ID,Medical_Condition,Medical_Condition_Duration) VALUES (2,'Nausea',5); INSERT INTO Astronaut_Medical_4 (Astronaut_ID,Medical_Condition,Medical_Condition_Duration) VALUES (3,'Headache',2); | SELECT Medical_Condition, MIN(Medical_Condition_Duration) as Minimum_Medical_Condition_Duration FROM Astronaut_Medical_4 GROUP BY Medical_Condition; |
List the names and ages of all artists who have created at least one work in the 'painting' category. | CREATE TABLE artists (id INT,name TEXT,age INT,num_works INT); INSERT INTO artists (id,name,age,num_works) VALUES (1,'Picasso',56,550),(2,'Van Gogh',37,210),(3,'Monet',86,690); CREATE TABLE works (id INT,artist_id INT,category TEXT); INSERT INTO works (id,artist_id,category) VALUES (1,1,'painting'),(2,1,'sculpture'),(3,2,'painting'),(4,2,'drawing'),(5,3,'painting'); | SELECT a.name, a.age FROM artists a JOIN works w ON a.id = w.artist_id WHERE w.category = 'painting'; |
How many wins did Team C have in the second half of the 2020 season? | CREATE TABLE games (id INT,team_a TEXT,team_b TEXT,location TEXT,score_team_a INT,score_team_b INT,wins_team_a INT,wins_team_b INT); INSERT INTO games (id,team_a,team_b,location,score_team_a,score_team_b,wins_team_a,wins_team_b) VALUES (1,'Team A','Team B','Away',120,130,0,1); | SELECT SUM(wins_team_a) FROM games WHERE team_a = 'Team C' AND location = 'Home' AND id > 26; |
What is the average score of players from the United States who play 'Racing Games'? | CREATE TABLE Players (PlayerID INT,PlayerName VARCHAR(100),Country VARCHAR(50),Game VARCHAR(50),Score INT); INSERT INTO Players (PlayerID,PlayerName,Country,Game,Score) VALUES (1,'John Doe','United States','Racing Games',90); INSERT INTO Players (PlayerID,PlayerName,Country,Game,Score) VALUES (2,'Jane Smith','Canada','Racing Games',80); | SELECT AVG(Score) FROM Players WHERE Country = 'United States' AND Game = 'Racing Games'; |
What is the maximum Terbium production in 2021 from mines in Australia? | CREATE TABLE mines (id INT,name TEXT,location TEXT,terbium_production FLOAT,timestamp DATE); INSERT INTO mines (id,name,location,terbium_production,timestamp) VALUES (1,'Mine A','Australia',120.5,'2021-01-01'),(2,'Mine B','Australia',150.7,'2021-02-01'),(3,'Mine C','USA',200.3,'2021-03-01'); | SELECT MAX(terbium_production) FROM mines WHERE location = 'Australia' AND YEAR(mines.timestamp) = 2021; |
How many students are enrolled in each course? | CREATE TABLE enrollments (student_id INT,course_name TEXT); INSERT INTO enrollments (student_id,course_name) VALUES (123,'Intro to Psychology'),(123,'English Composition'),(456,'English Composition'),(789,'Intro to Psychology'); | SELECT course_name, COUNT(*) FROM enrollments GROUP BY course_name; |
What is the total labor cost for each supplier by month? | CREATE TABLE labor_cost_by_month (supplier_id INT,labor_cost_month DATE,labor_cost DECIMAL(10,2)); INSERT INTO labor_cost_by_month (supplier_id,labor_cost_month,labor_cost) VALUES (1,'2021-01-01',500.00),(1,'2021-02-01',700.00),(2,'2021-01-01',800.00),(3,'2021-03-01',300.00); | SELECT EXTRACT(MONTH FROM labor_cost_month) AS month, supplier_id, SUM(labor_cost) AS total_labor_cost FROM labor_cost_by_month GROUP BY month, supplier_id; |
List all destinations with travel advisories issued by the US government. | CREATE TABLE destinations (destination_id INT,name TEXT,country TEXT); CREATE TABLE travel_advisories (advisory_id INT,destination_id INT,government TEXT,issued_date DATE); INSERT INTO destinations (destination_id,name,country) VALUES (1,'Paris','France'),(2,'Rio de Janeiro','Brazil'); INSERT INTO travel_advisories (advisory_id,destination_id,government,issued_date) VALUES (1,1,'USA','2022-01-01'),(2,2,'USA','2022-02-01'); | SELECT d.name FROM destinations d INNER JOIN travel_advisories ta ON d.destination_id = ta.destination_id WHERE ta.government = 'USA'; |
What is the maximum sale price for paintings from the 18th century? | CREATE TABLE Artworks (ArtworkID INT,Type TEXT,SalePrice INT,CreationYear INT); INSERT INTO Artworks (ArtworkID,Type,SalePrice,CreationYear) VALUES (1,'Painting',150000,1780); | SELECT MAX(SalePrice) FROM Artworks WHERE Type = 'Painting' AND CreationYear BETWEEN 1701 AND 1800; |
What is the average number of community engagement events per year in South America? | CREATE TABLE events_per_year (id INT,country VARCHAR(255),year INT,events INT); INSERT INTO events_per_year (id,country,year,events) VALUES (1,'Argentina',2015,10),(2,'Brazil',2016,15); | SELECT AVG(events) FROM events_per_year WHERE country LIKE 'South%'; |
List the unique game genres for games designed for VR platforms. | CREATE TABLE Games (GameID INT,Name VARCHAR(100),Genre VARCHAR(50),VRPossible BOOLEAN); INSERT INTO Games (GameID,Name,Genre,VRPossible) VALUES (1,'Game1','Action',true),(2,'Game2','Adventure',true),(3,'Game3','Simulation',false),(4,'Game4','Strategy',false),(5,'Game5','Puzzle',true); | SELECT DISTINCT Genre FROM Games WHERE VRPossible = true; |
What is the average speed of autonomous buses in Tokyo? | CREATE TABLE autonomous_buses (bus_id INT,trip_duration INT,start_speed INT,end_speed INT,trip_date DATE); INSERT INTO autonomous_buses (bus_id,trip_duration,start_speed,end_speed,trip_date) VALUES (1,1800,5,15,'2022-01-01'),(2,1500,10,20,'2022-01-02'); CREATE TABLE city_coordinates (city VARCHAR(50),latitude DECIMAL(9,6),longitude DECIMAL(9,6)); INSERT INTO city_coordinates (city,latitude,longitude) VALUES ('Tokyo',35.6895,139.6917); | SELECT AVG(end_speed - start_speed) as avg_speed FROM autonomous_buses, city_coordinates WHERE city_coordinates.city = 'Tokyo'; |
Insert a new record for a socially responsible loan with a balance of $1000. | CREATE TABLE loans (id INT,loan_type VARCHAR(255),balance DECIMAL(10,2)); INSERT INTO loans (id,loan_type,balance) VALUES (1,'Socially Responsible',1000.00); | INSERT INTO loans (loan_type, balance) VALUES ('Socially Responsible', 1000.00); |
Find the difference in unique job titles between the 'Sales' and 'IT' departments. | CREATE TABLE Employees (Employee_ID INT,First_Name VARCHAR(50),Last_Name VARCHAR(50),Department VARCHAR(50),Job_Title VARCHAR(50)); INSERT INTO Employees (Employee_ID,First_Name,Last_Name,Department,Job_Title) VALUES (1,'John','Doe','Sales','Manager'),(2,'Jane','Smith','Sales','Associate'),(3,'Mike','Jameson','IT','Engineer'),(4,'Lucy','Brown','IT','Analyst'); | SELECT Job_Title FROM Employees WHERE Department = 'Sales' INTERSECT SELECT Job_Title FROM Employees WHERE Department = 'IT' |
How many unique species of mammals are present in the 'arctic_mammals' table, with a population greater than 1000? | CREATE TABLE arctic_mammals (species VARCHAR(50),population INT); | SELECT COUNT(DISTINCT species) FROM arctic_mammals WHERE population > 1000; |
Count the number of members in the 'Healthcare_Union' having a salary below 50000. | CREATE TABLE Healthcare_Union (union_member_id INT,member_id INT,salary FLOAT); INSERT INTO Healthcare_Union (union_member_id,member_id,salary) VALUES (1,101,55000.00),(1,102,48000.00),(1,103,52000.00),(2,201,60000.00),(2,202,56000.00); | SELECT COUNT(union_member_id) FROM Healthcare_Union WHERE salary < 50000; |
What is the minimum depth of any marine life research station in the Pacific region? | CREATE TABLE marine_life_research_stations (id INT,name VARCHAR(255),region VARCHAR(255),depth FLOAT); | SELECT MIN(depth) FROM marine_life_research_stations WHERE region = 'Pacific'; |
Update the biomass value of the 'polar_bear' species to 900 in the 'species_data' table. | CREATE TABLE species_data (species_id INT,species_name VARCHAR(255),biomass FLOAT); INSERT INTO species_data (species_id,species_name,biomass) VALUES (1,'polar_bear',800.0),(2,'arctic_fox',15.0),(3,'caribou',220.0); | UPDATE species_data SET biomass = 900 WHERE species_name = 'polar_bear'; |
What is the distribution of food safety inspection scores across all restaurants? | CREATE TABLE Restaurants (id INT,name VARCHAR(50),region VARCHAR(50),inspection_score INT); INSERT INTO Restaurants (id,name,region,inspection_score) VALUES (1,'Asian Fusion','North',95),(2,'Bistro Bella','South',88),(3,'Tacos & More','East',92); | SELECT inspection_score, COUNT(*) as restaurant_count FROM Restaurants GROUP BY inspection_score; |
What is the total size of solar panels in Germany? | CREATE TABLE Building (id INT,name VARCHAR(50),city VARCHAR(50),country VARCHAR(50),sqft INT,PRIMARY KEY (id)); INSERT INTO Building (id,name,city,country,sqft) VALUES (7,'Brandenburg Gate','Berlin','Germany',88200); INSERT INTO Building (id,name,city,country,sqft) VALUES (8,'Cologne Cathedral','Cologne','Germany',157400); CREATE TABLE SolarPanel (id INT,building_id INT,installed_date DATE,size INT,PRIMARY KEY (id),FOREIGN KEY (building_id) REFERENCES Building (id)); INSERT INTO SolarPanel (id,building_id,installed_date,size) VALUES (7,7,'2011-03-01',12000); INSERT INTO SolarPanel (id,building_id,installed_date,size) VALUES (8,8,'2014-09-01',18000); | SELECT SUM(sp.size) FROM SolarPanel sp JOIN Building b ON sp.building_id = b.id WHERE b.country = 'Germany'; |
What are the sales figures for a specific drug in 2020? | CREATE TABLE drug_sales(drug_id INT,sale_date DATE,amount DECIMAL(10,2)); INSERT INTO drug_sales(drug_id,sale_date,amount) VALUES (1,'2020-01-01',1000),(1,'2020-02-01',1500),(2,'2020-01-01',2000),(2,'2020-02-01',2500); | SELECT drug_id, SUM(amount) as total_sales FROM drug_sales WHERE YEAR(sale_date) = 2020 GROUP BY drug_id; |
What is the total fine amount ordered for each ethnicity of defendants? | CREATE TABLE public.defendants (id SERIAL PRIMARY KEY,name VARCHAR(255),age INT,ethnicity VARCHAR(255),case_number VARCHAR(255)); CREATE TABLE public.cases (id SERIAL PRIMARY KEY,plaintiff_id INT,defendant_id INT,case_date DATE,case_type VARCHAR(255),court_location VARCHAR(255)); CREATE TABLE public.verdicts (id SERIAL PRIMARY KEY,case_number VARCHAR(255),verdict_date DATE,verdict_type VARCHAR(255)); CREATE TABLE public.fines (id SERIAL PRIMARY KEY,case_number VARCHAR(255),fine_amount NUMERIC); | SELECT d.ethnicity, sum(f.fine_amount) as total_fine_amount FROM public.defendants d JOIN public.cases c ON d.id = c.defendant_id JOIN public.verdicts v ON c.case_number = v.case_number JOIN public.fines f ON v.case_number = f.case_number GROUP BY d.ethnicity; |
Delete the 'outdated_standards' view | CREATE VIEW outdated_standards AS SELECT * FROM design_standards WHERE standard_version < 3; | DROP VIEW outdated_standards; |
What is the total cost and average climate finance for projects in Africa with climate finance from the Green Climate Fund? | CREATE TABLE projects (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),start_date DATE,end_date DATE,budget DECIMAL(10,2)); CREATE TABLE climate_finance (id INT PRIMARY KEY,project_id INT,source VARCHAR(255),amount DECIMAL(10,2)); CREATE TABLE mitigation_activities (id INT PRIMARY KEY,project_id INT,activity VARCHAR(255),cost DECIMAL(10,2)); CREATE TABLE countries (id INT PRIMARY KEY,country VARCHAR(255),population INT); | SELECT projects.country, SUM(mitigation_activities.cost) as total_cost, AVG(climate_finance.amount) as avg_climate_finance FROM projects JOIN mitigation_activities ON projects.id = mitigation_activities.project_id JOIN climate_finance ON projects.id = climate_finance.project_id WHERE projects.country = 'Africa' AND climate_finance.source = 'Green Climate Fund' GROUP BY projects.country; |
Add a new virtual tourism attraction to 'attractions' table | CREATE TABLE attractions (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255),country VARCHAR(255)); | INSERT INTO attractions (id, name, type, country) VALUES (1, 'Amazon Rainforest Virtual Tour', 'Virtual', 'Brazil'); |
List all records from the 'carbon_offset_projects' table with a 'type' of 'reforestation' and a 'status' of 'completed'. | CREATE TABLE carbon_offset_projects (id INT,project_name VARCHAR(50),location VARCHAR(50),type VARCHAR(50),status VARCHAR(50)); INSERT INTO carbon_offset_projects (id,project_name,location,type,status) VALUES (1,'Amazon Rainforest Reforestation','Brazil','Reforestation','Completed'),(2,'Boreal Forest Conservation','Canada','Afforestation','In Progress'); | SELECT * FROM carbon_offset_projects WHERE type = 'Reforestation' AND status = 'Completed'; |
Display the total water usage in 'RegionC' for the year 2022 | CREATE TABLE Annual_Water_Usage (id INT,region VARCHAR(20),year INT,usage FLOAT); INSERT INTO Annual_Water_Usage (id,region,year,usage) VALUES (1,'RegionA',2020,12000),(2,'RegionB',2021,15000),(3,'RegionC',2022,NULL); | SELECT region, SUM(usage) FROM Annual_Water_Usage WHERE region = 'RegionC' AND year = 2022 GROUP BY region; |
Which artifacts were found in more than one excavation site? | CREATE TABLE Artifacts (id INT,excavation_site VARCHAR(20),artifact_name VARCHAR(30),pieces INT); INSERT INTO Artifacts (id,excavation_site,artifact_name,pieces) VALUES (1,'BronzeAge','Sword',3000,),(2,'AncientRome','Sword',2500,); | SELECT artifact_name FROM Artifacts GROUP BY artifact_name HAVING COUNT(DISTINCT excavation_site) > 1; |
What is the average time between equipment maintenance requests for each equipment type? | CREATE TABLE maintenance (request_id INT,request_date DATE,equipment_type VARCHAR(255)); INSERT INTO maintenance (request_id,request_date,equipment_type) VALUES (1,'2020-02-12','tank'),(2,'2020-04-15','plane'),(3,'2019-10-27','ship'); | SELECT equipment_type, AVG(DATEDIFF(day, LAG(request_date) OVER (PARTITION BY equipment_type ORDER BY request_date), request_date)) AS avg_days_between_requests FROM maintenance GROUP BY equipment_type; |
What is the ratio of male to female employees in the HR department? | CREATE TABLE Employees (EmployeeID INT,Gender VARCHAR(10),Department VARCHAR(20)); INSERT INTO Employees (EmployeeID,Gender,Department) VALUES (1,'Female','HR'),(2,'Male','IT'),(3,'Female','HR'),(4,'Male','IT'); | SELECT COUNT(*) * 1.0 / SUM(CASE WHEN Gender = 'Female' THEN 1 ELSE 0 END) FROM Employees WHERE Department = 'HR'; |
Which activities have the highest and lowest calories burned? | CREATE TABLE activity_data (member_id INT,activity VARCHAR(20),calories INT); INSERT INTO activity_data (member_id,activity,calories) VALUES (1,'Running',300),(2,'Cycling',400),(3,'Yoga',100),(4,'Swimming',250),(5,'Pilates',150); | SELECT activity, MAX(calories) AS max_calories, MIN(calories) AS min_calories FROM activity_data GROUP BY activity; |
What is the maximum severity of vulnerabilities found in the European region? | CREATE TABLE vulnerabilities (id INT,severity FLOAT,region VARCHAR(50)); INSERT INTO vulnerabilities (id,severity,region) VALUES (1,7.5,'Europe'); | SELECT MAX(severity) FROM vulnerabilities WHERE region = 'Europe'; |
What is the minimum donation amount per volunteer? | CREATE TABLE volunteers (id INT,name TEXT,donation FLOAT); INSERT INTO volunteers (id,name,donation) VALUES (1,'John Doe',50.00),(2,'Jane Smith',100.00),(3,'Alice Johnson',25.00); | SELECT name, MIN(donation) FROM volunteers GROUP BY name; |
Show the total revenue for each music genre on the 'web' platform. | CREATE TABLE artists (id INT,name TEXT,genre TEXT); CREATE TABLE albums (id INT,title TEXT,artist_id INT,platform TEXT); CREATE TABLE sales (id INT,album_id INT,quantity INT,revenue DECIMAL); CREATE VIEW genre_sales AS SELECT ar.genre,SUM(s.revenue) as total_revenue FROM albums a JOIN sales s ON a.id = s.album_id JOIN artists ar ON a.artist_id = ar.id GROUP BY ar.genre; CREATE VIEW genre_sales_web AS SELECT * FROM genre_sales WHERE platform = 'web'; | SELECT genre, total_revenue FROM genre_sales_web; |
List the top 10 hashtags used in the past month, along with the number of times they were used. | CREATE TABLE hashtags (hashtag_id INT,hashtag VARCHAR(255),post_date DATE); | SELECT hashtag, COUNT(*) as usage_count FROM hashtags WHERE post_date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH) GROUP BY hashtag ORDER BY usage_count DESC LIMIT 10; |
List the top 5 graduate students with the highest number of research publications in the past year, sorted by the number of publications in descending order. | CREATE TABLE grad_students (student_id INT,student_name VARCHAR(50),publications INT); INSERT INTO grad_students (student_id,student_name,publications) VALUES (1,'John Doe',3),(2,'Jane Smith',5),(3,'Mike Johnson',2),(4,'Alice Davis',4),(5,'Bob Brown',1); | SELECT student_id, student_name, publications FROM (SELECT student_id, student_name, publications, ROW_NUMBER() OVER (ORDER BY publications DESC) as rank FROM grad_students WHERE publication_date >= DATEADD(year, -1, GETDATE())) as top5 WHERE rank <= 5; |
What is the average size of fish farms in 'oceans' schema? | CREATE SCHEMA oceans; CREATE TABLE fish_farms (id INT,size FLOAT,location VARCHAR(20)); INSERT INTO fish_farms (id,size,location) VALUES (1,50.2,'ocean'),(2,30.5,'ocean'),(3,80.3,'sea'); | SELECT AVG(size) FROM oceans.fish_farms WHERE location = 'ocean'; |
List the names of astronauts who have never flown in space. | CREATE TABLE astronauts (astronaut_id INT,name TEXT,age INT,flown_in_space BOOLEAN); INSERT INTO astronauts (astronaut_id,name,age,flown_in_space) VALUES (1,'Mark Watney',40,true),(2,'Melissa Lewis',45,true),(3,'Jessica Stevens',35,false); | SELECT name FROM astronauts WHERE flown_in_space = false; |
Identify the patient with the most therapy sessions in 2023? | CREATE TABLE therapy_sessions_2023 (patient_id INT,session_date DATE); INSERT INTO therapy_sessions_2023 (patient_id,session_date) VALUES (5,'2023-02-03'),(6,'2023-03-17'),(7,'2023-06-28'),(8,'2023-04-01'),(5,'2023-05-10'),(6,'2023-07-01'),(5,'2023-09-01'),(8,'2023-10-01'),(7,'2023-11-01'),(6,'2023-12-01'); | SELECT patient_id, COUNT(*) AS num_sessions FROM therapy_sessions_2023 WHERE YEAR(session_date) = 2023 GROUP BY patient_id ORDER BY num_sessions DESC LIMIT 1; |
How many garments are produced by each producer in the 'ethical_production' table? | CREATE TABLE ethical_production (id INT,producer VARCHAR(20),garment VARCHAR(20)); INSERT INTO ethical_production (id,producer,garment) VALUES (1,'EcoFabrics','tshirt'),(2,'GreenYarn','pants'),(3,'SustainaFiber','dress'),(4,'EcoFabrics','jacket'),(5,'GreenYarn','shirt'),(6,'SustainaFiber','blouse'); | SELECT producer, COUNT(garment) AS total_garments FROM ethical_production GROUP BY producer; |
Insert new users from Mexico and their posts about local culture. | CREATE TABLE users (id INT,name VARCHAR(255),country VARCHAR(255)); CREATE TABLE posts (id INT,user_id INT,content TEXT,created_at TIMESTAMP); CREATE VIEW latest_post AS SELECT posts.user_id,MAX(posts.created_at) AS latest_post FROM posts GROUP BY posts.user_id; | INSERT INTO users (id, name, country) VALUES (5, 'Edith', 'Mexico'), (6, 'Fernando', 'Mexico'); INSERT INTO posts (id, user_id, content, created_at) SELECT NULL, users.id, 'Discovering the richness of Mexican culture! #localculture', NOW() FROM users WHERE users.id NOT IN (SELECT latest_post.user_id FROM latest_post) AND users.country = 'Mexico'; |
What is the difference between the total assets of male and female customers? | CREATE TABLE Customers (CustomerID INT,Gender VARCHAR(50),Balance DECIMAL(10,2)); INSERT INTO Customers (CustomerID,Gender,Balance) VALUES (1,'Male',10000); INSERT INTO Customers (CustomerID,Gender,Balance) VALUES (2,'Female',5000); | SELECT SUM(CASE WHEN Gender = 'Male' THEN Balance ELSE -Balance END) FROM Customers |
What is the maximum number of education events in a single month for 'Habitat C'? | CREATE TABLE Habitats (id INT,name VARCHAR(20)); INSERT INTO Habitats (id,name) VALUES (1,'Habitat A'),(2,'Habitat B'),(3,'Habitat C'); CREATE TABLE Animals (id INT,name VARCHAR(20),habitat_id INT); INSERT INTO Animals (id,name,habitat_id) VALUES (1,'Tiger',3),(2,'Elephant',3),(3,'Giraffe',1); CREATE TABLE Education (animal_id INT,date DATE); INSERT INTO Education (animal_id,date) VALUES (1,'2022-01-01'),(1,'2022-02-01'),(2,'2022-01-01'),(3,'2022-01-01'),(3,'2022-02-01'); | SELECT MAX(num_education_events) FROM (SELECT habitat_id, MONTH(date) as month, COUNT(*) as num_education_events FROM Education WHERE habitat_id = 3 GROUP BY habitat_id, month) AS subquery |
What is the number of games designed for players with different education levels, and what are their names? | CREATE TABLE GameDesign (GameID INT,GameName VARCHAR(50),VR BIT); INSERT INTO GameDesign (GameID,GameName,VR) VALUES (1,'Space Explorer',1),(2,'Racing Fever',0),(3,'VR Puzzle',1); CREATE TABLE PlayerDemographics (PlayerID INT,Gender VARCHAR(10),EducationLevel VARCHAR(20)); INSERT INTO PlayerDemographics (PlayerID,Gender,EducationLevel) VALUES (1,'Male','High School'),(2,'Female','College'),(3,'Non-binary','Graduate School'); | SELECT PlayerDemographics.EducationLevel, COUNT(GameDesign.GameID) AS Games_Designed, MIN(GameDesign.GameName) AS First_Game, MAX(GameDesign.GameName) AS Last_Game FROM GameDesign INNER JOIN PlayerDemographics ON GameDesign.VR = 1 GROUP BY PlayerDemographics.EducationLevel; |
Calculate the moving average of precipitation over a 7-day period, for 'Field_2' from the 'rainfall_data' table. | CREATE TABLE rainfall_data (field VARCHAR(255),precipitation FLOAT,timestamp TIMESTAMP); | SELECT field, AVG(precipitation) OVER (PARTITION BY field ORDER BY timestamp RANGE BETWEEN INTERVAL '7 day' PRECEDING AND CURRENT ROW) as moving_avg FROM rainfall_data WHERE field = 'Field_2'; |
Insert new records for 3 chemical compounds, 'Acetone', 'Isopropyl Alcohol', 'Toluene', with safety_ratings 7, 8, 6 respectively | CREATE TABLE chemical_compounds (id INT PRIMARY KEY,name VARCHAR(255),safety_rating INT); | INSERT INTO chemical_compounds (name, safety_rating) VALUES ('Acetone', 7), ('Isopropyl Alcohol', 8), ('Toluene', 6); |
What is the minimum budget for projects in Africa? | CREATE TABLE project_budget (id INT,project_id INT,location VARCHAR(50),budget FLOAT); INSERT INTO project_budget (id,project_id,location,budget) VALUES (1,1,'Africa',350000.00),(2,2,'Asia',450000.00),(3,3,'Africa',300000.00); | SELECT MIN(budget) FROM project_budget WHERE location = 'Africa'; |
What are the total quantities of items shipped by land to 'City of Industry' between 2021-06-01 and 2021-06-15? | CREATE TABLE warehouses (warehouse_id INT,warehouse_name VARCHAR(255),city VARCHAR(255)); INSERT INTO warehouses (warehouse_id,warehouse_name,city) VALUES (1,'Warehouse A','City of Industry'),(2,'Warehouse B','Los Angeles'); CREATE TABLE shipments (shipment_id INT,warehouse_id INT,shipped_date DATE,shipped_quantity INT); INSERT INTO shipments (shipment_id,warehouse_id,shipped_date,shipped_quantity) VALUES (1,1,'2021-06-03',500),(2,1,'2021-06-10',800); | SELECT SUM(shipped_quantity) FROM shipments INNER JOIN warehouses ON shipments.warehouse_id = warehouses.warehouse_id WHERE shipped_date BETWEEN '2021-06-01' AND '2021-06-15' AND city = 'City of Industry'; |
What is the total number of cases heard in community courts for each state? | CREATE TABLE community_courts (court_id INT,court_state VARCHAR(2)); INSERT INTO community_courts VALUES (1,'NY'),(2,'CA'),(3,'IL'); | SELECT SUM(1) FROM community_courts cc INNER JOIN court_cases cc ON cc.court_id = cc.court_id GROUP BY cc.court_state; |
Delete size records for customers not fitting standard sizes | CREATE TABLE CustomerSizes (CustomerID INT,Size TEXT); INSERT INTO CustomerSizes (CustomerID,Size) VALUES (1,'XS'),(2,'S'),(3,'M'); | DELETE FROM CustomerSizes WHERE Size NOT IN ('XS', 'S', 'M'); |
Delete renewable energy projects that have an efficiency rating below 1.5. | CREATE TABLE projects (project_id INT,name TEXT,rating FLOAT); INSERT INTO projects (project_id,name,rating) VALUES (1,'Solar Farm',1.8),(2,'Wind Turbine',1.1),(3,'Geothermal Plant',2.0),(4,'Hydro Plant',1.9); | DELETE FROM projects WHERE rating < 1.5; |
Calculate the year-over-year production change for each oil field | CREATE TABLE production (id INT,field_name VARCHAR(50),year INT,qty FLOAT); INSERT INTO production (id,field_name,year,qty) VALUES (1,'Galkynysh',2018,100000); INSERT INTO production (id,field_name,year,qty) VALUES (2,'Galkynysh',2019,120000); INSERT INTO production (id,field_name,year,qty) VALUES (3,'Samotlor',2018,110000); INSERT INTO production (id,field_name,year,qty) VALUES (4,'Samotlor',2019,105000); | SELECT a.field_name, (b.qty - a.qty) / a.qty as yoy_change FROM production a JOIN production b ON a.field_name = b.field_name WHERE a.year = (YEAR(CURRENT_DATE) - 1) AND b.year = YEAR(CURRENT_DATE); |
How many mental health parity cases were reported in 2022? | CREATE TABLE MentalHealthParity (CaseID INT,ReportYear INT); INSERT INTO MentalHealthParity (CaseID,ReportYear) VALUES (1,2020),(2,2021),(3,2020),(4,2020),(5,2021),(6,2022),(7,2022),(8,2022); | SELECT SUM(CASE WHEN ReportYear = 2022 THEN 1 ELSE 0 END) as TotalCases FROM MentalHealthParity; |
Update the 'funding_round' column in the 'startups' table to 'Series A' for the startup with 'name' = 'BioVita' | CREATE TABLE startups (id INT PRIMARY KEY,name VARCHAR(100),industry VARCHAR(50),funding_round VARCHAR(50),funding_amount INT); | UPDATE startups SET funding_round = 'Series A' WHERE name = 'BioVita'; |
What is the total number of transactions for AI safety and AI explainability algorithms? | CREATE TABLE transactions (id INT,algorithm_type VARCHAR(20)); INSERT INTO transactions (id,algorithm_type) VALUES (1,'AI Safety'); INSERT INTO transactions (id,algorithm_type) VALUES (2,'Explainable AI'); | SELECT SUM(id) FROM transactions WHERE algorithm_type IN ('AI Safety', 'Explainable AI'); |
List all menu items that have a rating of 4 or higher and are not vegetarian. | CREATE TABLE menu_items(id INT,name VARCHAR(255),rating INT,is_vegetarian BOOLEAN); INSERT INTO menu_items (id,name,rating,is_vegetarian) VALUES (1,'Steak',5,false),(2,'Grilled Chicken',4,false),(3,'Veggie Burger',3,true); | SELECT name FROM menu_items WHERE rating >= 4 AND is_vegetarian = false; |
What is the total number of donations received by the arts and culture program? | CREATE TABLE Donations (id INT,program VARCHAR(255),amount DECIMAL(10,2)); INSERT INTO Donations (id,program,amount) VALUES (1,'Arts and Culture',500.00),(2,'Education',300.00); | SELECT SUM(amount) FROM Donations WHERE program = 'Arts and Culture'; |
What is the total number of volunteers and total volunteer hours for each month in the year 2021, ordered by the total number of volunteers in descending order? | CREATE TABLE Volunteers (VolunteerID INT,VolunteerName TEXT,VolunteerDate DATE); CREATE TABLE VolunteerHours (VolunteerID INT,Hours INT); | SELECT DATE_FORMAT(V.VolunteerDate, '%Y-%m') as Month, COUNT(V.VolunteerID) as NumVolunteers, SUM(VH.Hours) as TotalHours FROM Volunteers V JOIN VolunteerHours VH ON V.VolunteerID = VH.VolunteerID WHERE YEAR(V.VolunteerDate) = 2021 GROUP BY Month ORDER BY NumVolunteers DESC; |
How many units of makeup products are sold in each country in the last quarter? | CREATE TABLE sales (sale_id INT,product_id INT,sale_date DATE,quantity INT,price DECIMAL(5,2)); CREATE TABLE products (product_id INT,product_name VARCHAR(100),category VARCHAR(50),country VARCHAR(50)); | SELECT sales.country, SUM(sales.quantity) FROM sales JOIN products ON sales.product_id = products.product_id WHERE products.category = 'Makeup' AND sales.sale_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 3 MONTH) GROUP BY sales.country; |
Delete all records with the ocean_name 'Arctic Ocean' and return the number of deleted records. | CREATE TABLE marine_species (species_id INT,species_name VARCHAR(50),ocean_name VARCHAR(50)); | WITH deleted_species AS (DELETE FROM marine_species WHERE ocean_name = 'Arctic Ocean' RETURNING species_id) SELECT COUNT(*) FROM deleted_species; |
What is the total number of transactions on the Algorand network, and what is the distribution of these transactions by the day of the week? | CREATE TABLE algorand_transactions (transaction_id INT,transaction_time DATETIME); | SELECT DATE_FORMAT(transaction_time, '%W') as day_of_week, COUNT(transaction_id) as total_transactions FROM algorand_transactions GROUP BY day_of_week; |
What is the maximum number of satellites launched by any country in a single year? | CREATE TABLE satellites (id INT,country VARCHAR(255),name VARCHAR(255),launch_date DATE); | SELECT MAX(satellites_per_year.count) FROM (SELECT COUNT(*) as count, YEAR(launch_date) as launch_year FROM satellites GROUP BY launch_year) as satellites_per_year; |
What is the total water usage in the residential sector? | CREATE TABLE water_usage (sector VARCHAR(20),usage INT); INSERT INTO water_usage (sector,usage) VALUES ('residential',12000),('commercial',15000),('industrial',20000); | SELECT usage FROM water_usage WHERE sector = 'residential'; |
Insert a new record into the 'auto_show' table with the following details: 'Detroit', '2023-01-09', '2023-01-23' | CREATE TABLE auto_show (id INT PRIMARY KEY,city VARCHAR(255),start_date DATE,end_date DATE); | INSERT INTO auto_show (city, start_date, end_date) VALUES ('Detroit', '2023-01-09', '2023-01-23'); |
Insert a new record into the "RenewableEnergy" table for a new "WindFarm2" project in "Beijing" with a capacity of 7000 | CREATE TABLE RenewableEnergy (id INT,project_name VARCHAR(20),energy_source VARCHAR(20),capacity INT); | INSERT INTO RenewableEnergy (project_name, energy_source, capacity) VALUES ('WindFarm2', 'wind', 7000); |
What is the maximum capacity of a cargo ship in the 'cargo_fleet' table? | CREATE TABLE cargo_fleet (id INT,ship_name VARCHAR(50),type VARCHAR(50),capacity INT); INSERT INTO cargo_fleet (id,ship_name,type,capacity) VALUES (1,'Aquamarine','Container',5000),(2,'Bluewhale','Bulk',8000),(3,'Starfish','Tanker',3000),(4,'Seahorse','Container',6000),(5,'Jellyfish','Container',7000); | SELECT MAX(capacity) FROM cargo_fleet WHERE type = 'Cargo Ship'; |
Count the number of high-intensity interval training (HIIT) workouts completed by users in the last month. | CREATE TABLE workouts (id INT,user_id INT,type VARCHAR(50),duration INT,date DATE); INSERT INTO workouts (id,user_id,type,duration,date) VALUES (1,1,'HIIT',30,'2022-03-01'),(2,2,'Yoga',60,'2022-02-15'),(3,1,'HIIT',45,'2022-03-10'); | SELECT COUNT(*) FROM workouts WHERE type = 'HIIT' AND date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH); |
What is the distribution of support program participants by age and gender? | CREATE TABLE Support_Programs (id INT,participant_id INT,age INT,gender VARCHAR(10)); INSERT INTO Support_Programs (id,participant_id,age,gender) VALUES (1,1001,25,'Female'),(2,1002,30,'Male'); | SELECT Support_Programs.age, Support_Programs.gender, COUNT(*) as total FROM Support_Programs GROUP BY Support_Programs.age, Support_Programs.gender; |
What is the total built-up area (in square meters) for Green Buildings with a Platinum LEED certification in the 'sustainable_buildings' schema? | CREATE SCHEMA IF NOT EXISTS sustainable_buildings;CREATE TABLE IF NOT EXISTS sustainable_buildings.green_buildings (id INT,name VARCHAR(50),certification VARCHAR(20),built_up_area INT);INSERT INTO sustainable_buildings.green_buildings (id,name,certification,built_up_area) VALUES (1,'Green Building A','Platinum',25000),(2,'Green Building B','Gold',20000),(3,'Green Building C','Silver',15000); | SELECT SUM(built_up_area) FROM sustainable_buildings.green_buildings WHERE certification = 'Platinum'; |
Which countries in the 'production' table have a total usage of all materials greater than 1500? | CREATE TABLE production(id INT,country VARCHAR(255),material VARCHAR(255),usage INT); INSERT INTO production(id,country,material,usage) VALUES (1,'China','recycled polyester',800),(2,'India','recycled polyester',600),(3,'Bangladesh','viscose',400),(4,'Vietnam','recycled polyester',700); | SELECT country FROM production GROUP BY country HAVING SUM(usage) > 1500; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.