instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
What is the total donation amount in the first half of 2022, ranked by amount? | CREATE TABLE Donations (DonationID INT,DonorID INT,DonationDate DATE,DonationAmount FLOAT); | SELECT DonorID, SUM(DonationAmount) as 'Total Donation Amount' FROM Donations WHERE DonationDate BETWEEN '2022-01-01' AND '2022-06-30' GROUP BY DonorID ORDER BY SUM(DonationAmount) DESC; |
How many female players are there? | Player_Demographics | SELECT COUNT(*) FROM Player_Demographics WHERE Gender = 'Female'; |
What is the highest-rated action game? | CREATE TABLE Action_Games (Game_ID INT,Game_Name VARCHAR(20),Rating INT); INSERT INTO Action_Games (Game_ID,Game_Name,Rating) VALUES (1,'Game 1',90),(2,'Game 2',85),(3,'Game 3',95); | SELECT Game_Name, MAX(Rating) FROM Action_Games; |
What is the minimum playtime for players who have played the game 'Simulation' and are from Asia? | CREATE TABLE PlayerGameData (PlayerID INT,Age INT,Game VARCHAR(20),Playtime INT,Country VARCHAR(20)); INSERT INTO PlayerGameData (PlayerID,Age,Game,Playtime,Country) VALUES (5,30,'Simulation',40,'Japan'),(6,35,'Simulation',60,'China'),(7,28,'Racing',70,'USA'); | SELECT MIN(Playtime) FROM PlayerGameData WHERE Game = 'Simulation' AND Country = 'Asia'; |
What is the earliest capture time for each satellite image in the 'satellite_images' table? | CREATE TABLE satellite_images (image_id INT,image_url TEXT,capture_time TIMESTAMP); INSERT INTO satellite_images (image_id,image_url,capture_time) VALUES (1,'image1.jpg','2022-01-01 10:00:00'),(2,'image2.jpg','2021-05-01 10:00:00'); | SELECT image_id, MIN(capture_time) OVER (PARTITION BY image_id) FROM satellite_images; |
What is the total budget allocated for all categories in 2022, in the 'annual_budget' table? | CREATE TABLE annual_budget (year INT,category VARCHAR(255),budget INT); INSERT INTO annual_budget (year,category,budget) VALUES (2022,'Education',1000000),(2023,'Infrastructure',1500000); | SELECT SUM(budget) FROM annual_budget WHERE year = 2022; |
Add a new record of inclusive housing data in the GreenVille area. | CREATE TABLE InclusiveHousing (area TEXT,num_units INT,wheelchair_accessible BOOLEAN,pets_allowed BOOLEAN); INSERT INTO InclusiveHousing (area,num_units,wheelchair_accessible,pets_allowed) VALUES ('Eastside',10,TRUE,FALSE),('Westside',15,TRUE,TRUE); | INSERT INTO InclusiveHousing (area, num_units, wheelchair_accessible, pets_allowed) VALUES ('GreenVille', 20, TRUE, TRUE); |
What is the total installed capacity of wind projects in the 'EcoPower' schema? | CREATE SCHEMA EcoPower; CREATE TABLE WindProjects (project_id INT,name VARCHAR(100),location VARCHAR(100),installed_capacity INT); INSERT INTO WindProjects (project_id,name,location,installed_capacity) VALUES (1,'WindFarm 1','California',50000); | SELECT SUM(installed_capacity) FROM EcoPower.WindProjects; |
What percentage of restaurants in each city have a food safety score above 90? | CREATE TABLE food_safety_inspections(restaurant_id INT,city TEXT,score FLOAT); INSERT INTO food_safety_inspections(restaurant_id,city,score) VALUES (1,'New York',95.0),(2,'New York',90.0),(3,'Los Angeles',85.0),(4,'Los Angeles',92.0); | SELECT city, (COUNT(*) FILTER (WHERE score > 90)) * 100.0 / COUNT(*) as percentage FROM food_safety_inspections GROUP BY city; |
Get the product with the highest price from each supplier. | CREATE TABLE product (product_id INT,name VARCHAR(255),price DECIMAL(5,2),supplier_id INT); INSERT INTO product (product_id,name,price,supplier_id) VALUES (1,'Organic Cotton T-Shirt',20.99,1),(2,'Polyester Hoodie',35.99,2),(3,'Bamboo Socks',9.99,1); | SELECT product_id, name, price, supplier_id FROM (SELECT product_id, name, price, supplier_id, RANK() OVER (PARTITION BY supplier_id ORDER BY price DESC) AS tier FROM product) AS tiered_products WHERE tier = 1; |
What is the total quantity of products sold by each brand? | CREATE TABLE brands (brand_id INT,brand_name VARCHAR(255)); INSERT INTO brands (brand_id,brand_name) VALUES (1,'BrandA'),(2,'BrandB'); CREATE TABLE sales (sale_id INT,brand_id INT,product_quantity INT); | SELECT brands.brand_name, SUM(sales.product_quantity) as total_quantity FROM sales JOIN brands ON sales.brand_id = brands.brand_id GROUP BY brands.brand_name; |
How many manned missions were conducted by NASA before 2000? | CREATE TABLE SpaceMissions (id INT,name VARCHAR(100),agency VARCHAR(100),year INT,manned BOOLEAN); INSERT INTO SpaceMissions (id,name,agency,year,manned) VALUES (1,'Apollo 11','NASA',1969,true); INSERT INTO SpaceMissions (id,name,agency,year,manned) VALUES (2,'Apollo 13','NASA',1970,true); | SELECT COUNT(*) FROM SpaceMissions WHERE agency = 'NASA' AND year < 2000 AND manned = true; |
Find the total number of fans who have attended football and basketball games separately. | CREATE TABLE fans (id INT,name VARCHAR(50)); CREATE TABLE events (id INT,event_type VARCHAR(20),tickets_bought INT); INSERT INTO fans (id,name) VALUES (1,'John Doe'),(2,'Jane Smith'),(3,'Richard Roe'); INSERT INTO events (id,event_type,tickets_bought) VALUES (1,'Football',2),(1,'Basketball',1),(2,'Football',1),(2,'Basketball',3),(3,'Football',1),(3,'Basketball',2); | SELECT SUM(CASE WHEN event_type = 'Basketball' THEN tickets_bought ELSE 0 END) + SUM(CASE WHEN event_type = 'Football' THEN tickets_bought ELSE 0 END) FROM events INNER JOIN fans ON events.id = fans.id; |
What is the average age of female fans who prefer the 'Soccer' team in the 'fan_demographics' table? | CREATE TABLE fan_demographics (id INT PRIMARY KEY,name VARCHAR(100),gender VARCHAR(10),age INT,favorite_team VARCHAR(50)); CREATE TABLE teams (id INT PRIMARY KEY,name VARCHAR(100),sport VARCHAR(50)); | SELECT AVG(fd.age) as avg_age FROM fan_demographics fd JOIN teams t ON fd.favorite_team = t.name WHERE fd.gender = 'Female' AND t.name = 'Soccer'; |
How many autonomous vehicles were manufactured in 'Germany' and 'Italy' by the 'FutureTech' company in the manufacturers table? | CREATE TABLE manufacturers (id INT,company TEXT,country TEXT,vehicle_type TEXT,fuel_type TEXT,total_manufactured INT); INSERT INTO manufacturers (id,company,country,vehicle_type,fuel_type,total_manufactured) VALUES (1,'FutureTech','Germany','Car','Electric',500),(2,'GreenMotors','USA','Truck','Hydrogen',700),(3,'FutureTech','Italy','Car','Autonomous',800); | SELECT company, country, SUM(total_manufactured) as total_autonomous_vehicles_manufactured FROM manufacturers WHERE company = 'FutureTech' AND (country = 'Germany' OR country = 'Italy') AND fuel_type = 'Autonomous' GROUP BY company, country; |
Who are the users who used electric vehicles and their trip details? | CREATE TABLE users (id INT,name VARCHAR(50),age INT,gender VARCHAR(10),city VARCHAR(50));CREATE TABLE vehicles (id INT,vehicle_type VARCHAR(20),is_electric BOOLEAN);CREATE TABLE trips (id INT,user_id INT,vehicle_id INT,trip_distance FLOAT,trip_duration INT,departure_time TIMESTAMP,arrival_time TIMESTAMP);INSERT INTO users (id,name,age,gender,city) VALUES (3,'Alex',30,'Female','New York');INSERT INTO vehicles (id,vehicle_type,is_electric) VALUES (1,'Tesla',true),(2,'Bike',false);INSERT INTO trips (id,user_id,vehicle_id,trip_distance,trip_duration,departure_time,arrival_time) VALUES (3,3,1,15.3,25,'2022-01-03 12:00:00','2022-01-03 12:25:00'); | SELECT u.name, v.vehicle_type, t.trip_distance, t.trip_duration FROM users u JOIN trips t ON u.id = t.user_id JOIN vehicles v ON t.vehicle_id = v.id WHERE v.is_electric = true; |
When did the latest collective bargaining agreements expire for each union? | CREATE TABLE collective_bargaining (id INT,union_id INT,company VARCHAR,agreement_date DATE,expiration_date DATE); INSERT INTO collective_bargaining (id,union_id,company,agreement_date,expiration_date) VALUES (3,1,'DEF Industries','2021-02-01','2023-01-31'); INSERT INTO collective_bargaining (id,union_id,company,agreement_date,expiration_date) VALUES (4,2,'MNO Ltd','2020-10-15','2022-10-14'); | SELECT union_id, MAX(expiration_date) OVER (PARTITION BY union_id) as latest_expiration_date FROM collective_bargaining; |
List the total cargo weight for each cargo type in the 'cargo_tracking' table? | CREATE TABLE cargo_tracking (cargo_id INT,cargo_type VARCHAR(50),weight FLOAT,timestamp TIMESTAMP); | SELECT cargo_type, SUM(weight) FROM cargo_tracking GROUP BY cargo_type; |
What is the total waste generation in Brazil over the past 3 years? | CREATE TABLE WasteGenerationBrazil (year INT,amount INT); INSERT INTO WasteGenerationBrazil (year,amount) VALUES (2019,1200000),(2020,1300000),(2021,1400000); | SELECT SUM(amount) FROM WasteGenerationBrazil; |
List the top 2 states with the lowest wastewater treatment plant efficiency in ascending order. | CREATE TABLE WastewaterTreatmentPlants (ID INT,State VARCHAR(20),Efficiency FLOAT); INSERT INTO WastewaterTreatmentPlants (ID,State,Efficiency) VALUES (7,'New York',0.85),(8,'New York',0.87),(9,'Pennsylvania',0.83),(10,'Pennsylvania',0.84); | SELECT State, Efficiency FROM (SELECT State, Efficiency, ROW_NUMBER() OVER (ORDER BY Efficiency ASC) as rn FROM WastewaterTreatmentPlants) tmp WHERE rn <= 2 |
What is the total volume of water used for irrigation in Colorado? | CREATE TABLE water_use (id INT,location TEXT,use_type TEXT,volume FLOAT); INSERT INTO water_use (id,location,use_type,volume) VALUES (1,'Denver','Irrigation',100000),(2,'Colorado Springs','Irrigation',150000),(3,'Boulder','Industrial',200000); | SELECT SUM(volume) as total_volume FROM water_use WHERE location IN ('Denver', 'Colorado Springs', 'Boulder') AND use_type = 'Irrigation'; |
What is the total water consumption for residential and commercial sectors in 2020? | CREATE TABLE water_usage(sector VARCHAR(20),year INT,consumption INT); INSERT INTO water_usage VALUES ('Residential',2018,5000),('Residential',2019,5500),('Residential',2020,6000),('Commercial',2018,3000),('Commercial',2019,3400),('Commercial',2020,3800); | SELECT sector, SUM(consumption) FROM water_usage WHERE year = 2020 AND sector IN ('Residential', 'Commercial') GROUP BY sector; |
What is the average heart rate for each member in the last week? | CREATE TABLE workout_data(member_id INT,heart_rate INT,workout_date DATE); INSERT INTO workout_data(member_id,heart_rate,workout_date) VALUES (1,120,'2022-02-14'),(2,150,'2022-02-15'),(3,130,'2022-02-16'),(4,160,'2022-02-17'),(5,110,'2022-02-18'),(6,170,'2022-02-19'),(7,140,'2022-02-20'),(8,180,'2022-02-21'),(9,100,'2022-02-22'),(10,190,'2022-02-23'),(11,120,'2022-02-24'),(12,130,'2022-02-25'); | SELECT member_id, AVG(heart_rate) FROM workout_data WHERE workout_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK) GROUP BY member_id; |
How many agricultural innovation projects were completed in Q2 2022, partitioned by completion status? | CREATE TABLE AgriculturalInnovation (ProjectID INT,ProjectName VARCHAR(100),CompletionStatus VARCHAR(20),CompletionDate DATE); INSERT INTO AgriculturalInnovation VALUES (1,'Precision Farming','Completed','2022-04-15'),(2,'Vertical Farming','In Progress','2022-06-30'),(3,'Drip Irrigation','Completed','2022-05-28'),(4,'Genetic Engineering','In Progress','2022-07-20'),(5,'Drone Pollination','Completed','2022-04-22'); | SELECT CompletionStatus, COUNT(*) AS ProjectCount FROM AgriculturalInnovation WHERE CompletionDate BETWEEN '2022-04-01' AND '2022-06-30' GROUP BY CompletionStatus; |
How many art workshops were held in African countries in the last two years? | CREATE TABLE ArtWorkshops (workshopID INT,workshopLocation VARCHAR(50),workshopDate DATE); INSERT INTO ArtWorkshops (workshopID,workshopLocation,workshopDate) VALUES (1,'Nigeria','2020-03-01'),(2,'Kenya','2021-04-10'),(3,'Egypt','2022-01-20'); | SELECT COUNT(*) FROM ArtWorkshops WHERE workshopLocation IN ('Nigeria', 'Kenya', 'Egypt') AND workshopDate >= DATEADD(year, -2, GETDATE()); |
What is the average attendance for arts and culture events in 'Toronto' for events with an attendance of over 1000? | CREATE TABLE Events (event_id INT,city VARCHAR(20),attendee_count INT); INSERT INTO Events (event_id,city,attendee_count) VALUES (1,'Toronto',1200),(2,'Toronto',1500),(3,'Toronto',900); | SELECT AVG(attendee_count) FROM Events WHERE city = 'Toronto' AND attendee_count > 1000; |
How many materials in the sustainable_materials table have a recycled_content_percentage greater than 85%? | CREATE TABLE sustainable_materials (material_name TEXT,recycled_content_percentage FLOAT,embodied_carbon_kg_co2 FLOAT); INSERT INTO sustainable_materials (material_name,recycled_content_percentage,embodied_carbon_kg_co2) VALUES ('Bamboo',90,0.45),('Reclaimed Wood',80,0.75),('Straw Bale',100,1.3); | SELECT COUNT(*) FROM sustainable_materials WHERE recycled_content_percentage > 85; |
What is the average investment in climate finance for each country in South America in 2021? | CREATE TABLE climate_finance (country VARCHAR(50),investment INT,year INT,region VARCHAR(50)); INSERT INTO climate_finance (country,investment,year,region) VALUES ('Brazil',2000000,2021,'South America'),('Argentina',1500000,2021,'South America'); | SELECT country, AVG(investment) as avg_investment FROM climate_finance WHERE year = 2021 AND region = 'South America' GROUP BY country; |
What is the total climate finance allocated for adaptation projects in South America? | CREATE TABLE climate_finance (region VARCHAR(50),amount FLOAT,sector VARCHAR(50)); INSERT INTO climate_finance (region,amount,sector) VALUES ('Asia',6000000,'Mitigation'),('Africa',4000000,'Mitigation'),('South America',5000000,'Adaptation'); | SELECT SUM(amount) FROM climate_finance WHERE region = 'South America' AND sector = 'Adaptation'; |
List the R&D expenditures for the top 5 pharmaceutical companies in Germany. | CREATE TABLE r_and_d_expenditures (company VARCHAR(255),country VARCHAR(255),amount FLOAT); INSERT INTO r_and_d_expenditures (company,country,amount) VALUES ('PharmaA','Germany',5000000); | SELECT company, SUM(amount) FROM r_and_d_expenditures WHERE country = 'Germany' GROUP BY company ORDER BY SUM(amount) DESC LIMIT 5; |
How many hospitals are present in each state? | CREATE TABLE Hospitals (ID INT,State VARCHAR(50),City VARCHAR(50)); INSERT INTO Hospitals (ID,State,City) VALUES (1,'StateA','CityA'),(2,'StateA','CityB'),(3,'StateB','CityC'),(4,'StateB','CityD'); | SELECT State, COUNT(DISTINCT State) as HospitalCount FROM Hospitals GROUP BY State; |
What is the maximum number of hospital visits for patients with cancer in New York? | CREATE TABLE Patients (PatientID INT,Cancer TEXT,HospitalVisits INT,State TEXT); INSERT INTO Patients (PatientID,Cancer,HospitalVisits,State) VALUES (1,'Breast Cancer',3,'New York'); | SELECT MAX(HospitalVisits) FROM Patients WHERE Cancer IS NOT NULL AND State = 'New York'; |
What is the percentage of women in the workforce in Germany? | CREATE TABLE Labor (ID INT,Country VARCHAR(100),Year INT,WomenInWorkforcePercentage FLOAT); INSERT INTO Labor (ID,Country,Year,WomenInWorkforcePercentage) VALUES (1,'Germany',2020,49); | SELECT WomenInWorkforcePercentage FROM Labor WHERE Country = 'Germany' AND Year = 2020; |
What is the maximum funding amount received by a startup in the biotech sector? | CREATE TABLE funding(startup_id INT,funding_amount DECIMAL(10,2)); INSERT INTO funding(startup_id,funding_amount) VALUES (1,1000000.00); CREATE TABLE startups(id INT,name TEXT,industry TEXT); INSERT INTO startups(id,name,industry) VALUES (1,'BiotechMax','Biotech'); | SELECT MAX(funding_amount) FROM funding JOIN startups ON startups.id = funding.startup_id WHERE startups.industry = 'Biotech'; |
What is the minimum funding received by startups founded by individuals from Africa in the e-commerce sector? | CREATE TABLE startups (id INT,name TEXT,industry TEXT,founders TEXT,funding FLOAT); INSERT INTO startups (id,name,industry,founders,funding) VALUES (1,'AfricanEcom','E-commerce','Africa',2000000); | SELECT MIN(funding) FROM startups WHERE industry = 'E-commerce' AND founders = 'Africa'; |
What is the number of startups founded by non-binary individuals in the technology industry? | CREATE TABLE company (id INT,name TEXT,founder_gender TEXT,industry TEXT); INSERT INTO company (id,name,founder_gender,industry) VALUES (1,'CodeForAll','Non-binary','Technology'); INSERT INTO company (id,name,founder_gender,industry) VALUES (2,'TechVillage','Male','Technology'); | SELECT COUNT(*) FROM company WHERE founder_gender = 'Non-binary' AND industry = 'Technology'; |
How many startups were founded by underrepresented minorities in the last 5 years? | CREATE TABLE startups(id INT,name TEXT,founder_minority TEXT); INSERT INTO startups VALUES (1,'Acme Inc','Yes'); INSERT INTO startups VALUES (2,'Beta Corp','No'); CREATE TABLE founding_dates(startup_id INT,founded_year INT); INSERT INTO founding_dates VALUES (1,2018); INSERT INTO founding_dates VALUES (2,2017); | SELECT COUNT(*) FROM startups INNER JOIN founding_dates ON startups.id = founding_dates.startup_id WHERE founder_minority = 'Yes' AND founded_year >= YEAR(CURRENT_DATE) - 5; |
What are the names and founding years of companies founded in Chilean accelerators between 2010 and 2015? | CREATE TABLE accelerator (id INT,accelerator_name VARCHAR(50),location VARCHAR(50),start_year INT,end_year INT); CREATE TABLE company (id INT,name VARCHAR(50),founding_year INT,industry VARCHAR(50),accelerator_id INT); | SELECT a.accelerator_name, c.name, c.founding_year FROM accelerator a INNER JOIN company c ON a.id = c.accelerator_id WHERE a.location = 'Chile' AND c.founding_year >= a.start_year AND c.founding_year <= a.end_year AND a.start_year BETWEEN 2010 AND 2015; |
Show all regulatory frameworks related to blockchain. | CREATE TABLE regulatory_frameworks (framework_id INT,name VARCHAR(64),description VARCHAR(256)); | SELECT * FROM regulatory_frameworks WHERE description LIKE '%blockchain%'; |
What's the average gas limit for smart contracts on the Binance Smart Chain? | CREATE TABLE binance_smart_chain (contract_address VARCHAR(42),gas_limit INTEGER); | SELECT AVG(gas_limit) FROM binance_smart_chain; |
What is the total number of wildlife habitats for each type, grouped by type? | CREATE TABLE wildlife_habitat(type VARCHAR(255),count INT); INSERT INTO wildlife_habitat(type,count) VALUES ('Forest',300),('Wetland',200),('Grassland',150),('Desert',50); | SELECT type, SUM(count) FROM wildlife_habitat GROUP BY type; |
What are the total sales for cruelty-free makeup brands in the United Kingdom? | CREATE TABLE brands (brand_id INT,brand_name TEXT,is_cruelty_free BOOLEAN); INSERT INTO brands (brand_id,brand_name,is_cruelty_free) VALUES (1,'Natural Beauty',true),(2,'Cosmetics Inc.',false),(3,'Vegan Cosmetics',true); CREATE TABLE sales (sale_id INT,brand_id INT,sale_quantity INT,sale_country TEXT); INSERT INTO sales (sale_id,brand_id,sale_quantity,sale_country) VALUES (1,1,700,'UK'),(2,2,800,'US'),(3,3,900,'CA'),(4,1,600,'DE'),(5,2,500,'FR'); | SELECT SUM(s.sale_quantity) as total_sales FROM sales s JOIN brands b ON s.brand_id = b.brand_id WHERE b.is_cruelty_free = true AND s.sale_country = 'UK'; |
What are the total sales for each region in Q3 of 2022? | CREATE TABLE sales (product_id INT,product_name VARCHAR(100),category VARCHAR(50),sale_date DATE,revenue DECIMAL(10,2),region VARCHAR(50)); INSERT INTO sales (product_id,product_name,category,sale_date,revenue,region) VALUES (1,'Lipstick','Cosmetics','2022-07-02',25.99,'North'),(2,'Foundation','Cosmetics','2022-07-15',34.99,'South'); | SELECT region, EXTRACT(QUARTER FROM sale_date) AS quarter, SUM(revenue) AS total_sales FROM sales GROUP BY region, quarter HAVING quarter = 3; |
Display the soldier names and branches from the view | CREATE VIEW soldier_details AS SELECT id,name,branch FROM soldiers; | SELECT name, branch FROM soldier_details; |
Show peacekeeping operations that involved more than one military branch | CREATE TABLE peacekeeping_operations (id INT,operation_name VARCHAR(255),military_branch1 VARCHAR(255),military_branch2 VARCHAR(255),year INT); | SELECT operation_name FROM peacekeeping_operations WHERE military_branch1 <> military_branch2; |
What is the total assets of clients who have invested in mutual funds but not in stocks? | CREATE TABLE clients (client_id INT,name TEXT,age INT,gender TEXT,total_assets DECIMAL(10,2)); INSERT INTO clients VALUES (1,'John Doe',35,'Male',250000.00),(2,'Jane Smith',45,'Female',500000.00); CREATE TABLE investments (client_id INT,investment_type TEXT); INSERT INTO investments VALUES (1,'Stocks'),(1,'Bonds'),(2,'Stocks'),(3,'Mutual Funds'); | SELECT c.total_assets FROM clients c INNER JOIN investments i ON c.client_id = i.client_id WHERE i.investment_type = 'Mutual Funds' AND c.client_id NOT IN (SELECT client_id FROM investments WHERE investment_type = 'Stocks'); |
List the top 3 cities with the most volunteer hours. | CREATE TABLE CityVolunteers (city TEXT,hours FLOAT); INSERT INTO CityVolunteers (city,hours) VALUES ('NYC',450.0),('LA',300.5),('Chicago',350.1),('Houston',200.2); | SELECT city, hours FROM CityVolunteers ORDER BY hours DESC LIMIT 3; |
What percentage of the total budget in 2022 was spent on administrative expenses? | CREATE TABLE Expenses (ExpenseID int,ExpenseType varchar(50),Amount decimal(10,2),ExpenseDate date); INSERT INTO Expenses VALUES (1,'Administrative',25000,'2022-01-01'); | SELECT (SUM(CASE WHEN ExpenseType = 'Administrative' THEN Amount ELSE 0 END) / SUM(Amount)) * 100 FROM Expenses WHERE ExpenseDate BETWEEN '2022-01-01' AND '2022-12-31' |
How many students have improved their mental health score by more than 10 points since enrolling? | CREATE TABLE student_mental_health (student_id INT,mental_health_score INT,date DATE); CREATE TABLE enrollments (student_id INT,enrollment_date DATE); | SELECT COUNT(smh.student_id) as num_improved FROM student_mental_health smh JOIN enrollments e ON smh.student_id = e.student_id WHERE smh.mental_health_score > e.mental_health_score + 10; |
What is the minimum salary for employees who identify as Latinx in the Sales department? | CREATE TABLE Employees (EmployeeID INT,Gender VARCHAR(10),Ethnicity VARCHAR(20),Department VARCHAR(20),Salary INT); INSERT INTO Employees (EmployeeID,Gender,Ethnicity,Department,Salary) VALUES (1,'Female','Latinx','Sales',60000); INSERT INTO Employees (EmployeeID,Gender,Ethnicity,Department,Salary) VALUES (2,'Male','Asian','Marketing',70000); | SELECT MIN(Salary) FROM Employees WHERE Ethnicity = 'Latinx' AND Department = 'Sales'; |
What was the average energy efficiency score for each region in 2021? | CREATE TABLE energy_efficiency (region VARCHAR(255),year INT,score INT); INSERT INTO energy_efficiency (region,year,score) VALUES ('Northeast',2021,85); INSERT INTO energy_efficiency (region,year,score) VALUES ('Midwest',2021,82); | SELECT region, AVG(score) FROM energy_efficiency WHERE year = 2021 GROUP BY region; |
What was the energy efficiency rating of the top 5 most efficient cars in the world, by make and model, in 2020? | CREATE TABLE cars (make text,model text,year integer,efficiency decimal); | SELECT make, model, MAX(efficiency) as top_efficiency FROM cars WHERE year = 2020 GROUP BY make, model ORDER BY top_efficiency DESC LIMIT 5; |
Show the total number of races won by the 'formula1_drivers' table in ascending order. | CREATE TABLE formula1_drivers (driver_id INT,driver_name VARCHAR(50),races_won INT); | SELECT driver_name, SUM(races_won) as total_races_won FROM formula1_drivers GROUP BY driver_name ORDER BY total_races_won ASC; |
What is the average number of rebounds per game by Wilt Chamberlain in the NBA? | CREATE TABLE wilt_stats (game INT,points INT,rebounds INT); INSERT INTO wilt_stats (game,points,rebounds) VALUES (1,50,25),(2,40,30); | SELECT AVG(rebounds) FROM wilt_stats; |
What is the highest scoring game in the history of the UEFA Champions League? | CREATE TABLE games (game_id INT,home_team INT,away_team INT,home_goals INT,away_goals INT); | SELECT home_team, away_team, home_goals, away_goals FROM games WHERE (home_goals + away_goals) = (SELECT MAX(home_goals + away_goals) FROM games); |
Delete all records from the "funding_sources" table where the "region" is "South America" and the "funding_type" is "loan". | CREATE TABLE funding_sources (funding_source_id INT PRIMARY KEY,name VARCHAR(255),region VARCHAR(255),funding_type VARCHAR(255)); | DELETE FROM funding_sources WHERE region = 'South America' AND funding_type = 'loan'; |
What is the percentage of accessible technology projects in each country? | CREATE TABLE accessible_tech (id INT,country VARCHAR(2),project_accessibility VARCHAR(10)); INSERT INTO accessible_tech (id,country,project_accessibility) VALUES (1,'US','yes'),(2,'CA','no'),(3,'MX','yes'),(4,'BR','yes'),(5,'AR','no'); | SELECT country, COUNT(*) * 100.0 / (SELECT COUNT(*) FROM accessible_tech) AS percentage FROM accessible_tech WHERE project_accessibility = 'yes' GROUP BY country; |
List all stations with wheelchair accessibility and elevator availability | CREATE TABLE stations (station_id INT,name VARCHAR(255),latitude DECIMAL(9,6),longitude DECIMAL(9,6)); CREATE TABLE accessibility (station_id INT,wheelchair_accessible BOOLEAN,elevator_availability BOOLEAN); | SELECT s.name FROM stations s JOIN accessibility a ON s.station_id = a.station_id WHERE a.wheelchair_accessible = TRUE AND a.elevator_availability = TRUE; |
List unique user IDs that used the 'Eco Pass' in the first quarter of 2022 | CREATE TABLE users (id INT PRIMARY KEY,user_id INT,pass_type VARCHAR(20)); | SELECT DISTINCT user_id FROM users WHERE pass_type = 'Eco Pass' AND (DATE(NOW()) - DATE(created_at)) >= INTERVAL '3 months'; |
What is the total revenue for each route type, by day? | CREATE TABLE Routes (RouteID int,RouteType varchar(10),StartingLocation varchar(20)); CREATE TABLE Fares (RouteID int,Fare float); CREATE TABLE PassengerCounts (RouteID int,Date date,PassengerCount int); INSERT INTO Routes VALUES (1,'Bus','City Center'),(2,'Tram','City Center'); INSERT INTO Fares VALUES (1,2.5),(2,3.0); INSERT INTO PassengerCounts VALUES (1,'2022-01-01',100),(1,'2022-01-02',110),(2,'2022-01-01',120); | SELECT Routes.RouteType, PassengerCounts.Date, SUM(Fares.Fare * PassengerCounts.PassengerCount) as daily_revenue FROM Routes INNER JOIN Fares ON Routes.RouteID = Fares.RouteID INNER JOIN PassengerCounts ON Routes.RouteID = PassengerCounts.RouteID GROUP BY Routes.RouteType, PassengerCounts.Date; |
What are the top 5 cities with the most user engagement on our platform, in terms of likes, shares, and comments, for the year 2022? | CREATE TABLE cities (city_id INT,city_name VARCHAR(255));CREATE TABLE user_activity (activity_id INT,user_id INT,city_id INT,activity_type VARCHAR(50),activity_date DATE); | SELECT c.city_name, SUM(CASE WHEN activity_type IN ('like', 'share', 'comment') THEN 1 ELSE 0 END) as total_engagement FROM cities c JOIN user_activity ua ON c.city_id = ua.city_id WHERE ua.activity_date >= '2022-01-01' AND ua.activity_date < '2023-01-01' GROUP BY c.city_name ORDER BY total_engagement DESC LIMIT 5; |
What is the total amount of microfinance loans provided by the BRAC Bank last year? | CREATE TABLE microfinance_loans (bank VARCHAR(50),product VARCHAR(50),amount FLOAT,loan_date DATE); INSERT INTO microfinance_loans (bank,product,amount,loan_date) VALUES ('BRAC Bank','Microenterprise Loan',1000.00,'2022-01-01'),('BRAC Bank','Education Loan',2000.00,'2022-02-01'),('BRAC Bank','Housing Loan',3000.00,'2022-03-01'); | SELECT SUM(amount) FROM microfinance_loans WHERE bank = 'BRAC Bank' AND YEAR(loan_date) = YEAR(CURRENT_DATE()) - 1; |
How many hours did volunteers contribute to environmental programs in Australia in H1 2021? | CREATE TABLE Volunteers (id INT,volunteer_name VARCHAR(255),program VARCHAR(255),volunteer_hours INT,volunteer_date DATE); INSERT INTO Volunteers (id,volunteer_name,program,volunteer_hours,volunteer_date) VALUES (1,'David Williams','Environment',20,'2021-02-15'),(2,'Emily Green','Environment',25,'2021-06-05'); | SELECT SUM(volunteer_hours) FROM Volunteers WHERE program = 'Environment' AND volunteer_date BETWEEN '2021-01-01' AND '2021-06-30'; |
Identify all suppliers who provide non-GMO ingredients to restaurants with Michelin stars. | CREATE TABLE Suppliers (id INT,name VARCHAR(50),isNonGMO BOOLEAN); CREATE TABLE Restaurants (id INT,name VARCHAR(50),numStars INT); CREATE TABLE Ingredients (supplierId INT,restaurantId INT,isNonGMO BOOLEAN); | SELECT Suppliers.name FROM Suppliers INNER JOIN Ingredients ON Suppliers.id = Ingredients.supplierId INNER JOIN Restaurants ON Ingredients.restaurantId = Restaurants.id WHERE Restaurants.numStars > 2 AND Ingredients.isNonGMO = TRUE; |
What is the maximum sustainability rating for each supplier type? | CREATE TABLE supplier_types (id INT,type VARCHAR(255),description VARCHAR(255)); INSERT INTO supplier_types (id,type,description) VALUES (1,'Organic','Suppliers that specialize in organic food production.'); INSERT INTO supplier_types (id,type,description) VALUES (2,'Local','Suppliers that are locally owned and operated.'); CREATE TABLE supplier_type_ratings (supplier_id INT,supplier_type_id INT,rating FLOAT); INSERT INTO supplier_type_ratings (supplier_id,supplier_type_id,rating) VALUES (1,1,4.8); INSERT INTO supplier_type_ratings (supplier_id,supplier_type_id,rating) VALUES (2,1,4.2); INSERT INTO supplier_type_ratings (supplier_id,supplier_type_id,rating) VALUES (1,2,4.9); | SELECT st.type, MAX(str.rating) AS max_rating FROM supplier_types st JOIN supplier_type_ratings str ON st.id = str.supplier_type_id GROUP BY st.type; |
What is the total quantity of products shipped to each continent? | CREATE TABLE shipments (shipment_id INT,continent TEXT); INSERT INTO shipments (shipment_id,continent) VALUES (1,'Europe'),(2,'Asia'),(3,'Europe'),(4,'Americas'),(5,'Africa'); CREATE TABLE shipment_items (product TEXT,shipment_id INT,quantity INT); INSERT INTO shipment_items (product,shipment_id,quantity) VALUES ('Product A',1,100),('Product B',2,200),('Product A',3,300),('Product C',4,400),('Product B',5,500); | SELECT s.continent, SUM(si.quantity) as total_quantity FROM shipment_items si JOIN shipments s ON si.shipment_id = s.shipment_id GROUP BY s.continent; |
What is the average funding amount for biotech startups in California? | CREATE TABLE biotech_startups (id INT,name TEXT,location TEXT,funding_amount INT); INSERT INTO biotech_startups (id,name,location,funding_amount) VALUES (1,'GenSolutions','California',12000000); | SELECT AVG(funding_amount) FROM biotech_startups WHERE location = 'California'; |
How many community health workers are there in each state? | CREATE TABLE community_health_workers (state VARCHAR(2),worker_id INT); | SELECT state, COUNT(worker_id) FROM community_health_workers GROUP BY state; |
Find the number of tourists who have experienced virtual tours in Asia. | CREATE TABLE tourists (tourist_id INT,name VARCHAR,country VARCHAR,virtual_tour_experience INT); CREATE VIEW asian_tourists AS SELECT * FROM tourists WHERE country LIKE '%%Asia%%'; | SELECT COUNT(*) FROM asian_tourists WHERE virtual_tour_experience > 0; |
Find the total price of artworks by 'Gustav Klimt' in the 'Art Nouveau' period. | CREATE TABLE Artworks (id INT,artist_name VARCHAR(100),period VARCHAR(50),artwork_name VARCHAR(100),price FLOAT); INSERT INTO Artworks (id,artist_name,period,artwork_name,price) VALUES (1,'Gustav Klimt','Art Nouveau','The Kiss',10000000.0); INSERT INTO Artworks (id,artist_name,period,artwork_name,price) VALUES (2,'Gustav Klimt','Art Nouveau','Portrait of Adele Bloch-Bauer I',135000000.0); | SELECT SUM(price) as total_price FROM Artworks WHERE artist_name = 'Gustav Klimt' AND period = 'Art Nouveau'; |
What was the average visitor count for all exhibitions in 'Cubism' genre in Paris, France? | CREATE TABLE Exhibitions (id INT,name TEXT,genre TEXT,visitor_count INT,city TEXT,country TEXT); | SELECT AVG(visitor_count) FROM Exhibitions WHERE genre = 'Cubism' AND city = 'Paris' AND country = 'France'; |
Create a view to display all therapists with the specialization of 'CBT' | CREATE VIEW cbt_therapists AS SELECT therapist_id,name,specialization,experience FROM therapists WHERE specialization = 'CBT'; | CREATE VIEW cbt_therapists AS SELECT therapist_id, name, specialization, experience FROM therapists WHERE specialization = 'CBT'; |
Delete all records related to destinations that were not marketed in 2022. | CREATE TABLE marketing_campaigns (destination VARCHAR(20),year INT); INSERT INTO marketing_campaigns (destination,year) VALUES ('Japan',2020),('France',2021),('Germany',2022),('Italy',2020); | DELETE FROM marketing_campaigns WHERE year != 2022; |
What is the total number of marine species in the Atlantic Ocean with a conservation status of 'Critically Endangered' or 'Extinct'? | CREATE TABLE AtlanticSpecies (species_name TEXT,location TEXT,conservation_status TEXT); INSERT INTO AtlanticSpecies (species_name,location,conservation_status) VALUES ('North Atlantic Right Whale','Atlantic Ocean','Critically Endangered'),('Staghorn Coral','Atlantic Ocean','Critically Endangered'),('Black Abalone','Atlantic Ocean','Extinct'); | SELECT COUNT(*) FROM AtlanticSpecies WHERE conservation_status IN ('Critically Endangered', 'Extinct'); |
List all TV shows with a runtime greater than 60 minutes? | CREATE TABLE shows (id INT,title TEXT,runtime FLOAT); INSERT INTO shows (id,title,runtime) VALUES (1,'Show1',65),(2,'Show2',45),(3,'Show3',70); | SELECT title FROM shows WHERE runtime > 60; |
What is the total inventory value for each category in the UK? | CREATE TABLE inventory (id INT,item_id INT,category TEXT,quantity INT,price DECIMAL(5,2));INSERT INTO inventory (id,item_id,category,quantity,price) VALUES (1,1,'Pizza',100,5.99),(2,2,'Pasta',75,6.99),(3,3,'Salad',50,4.99); | SELECT c.category, SUM(i.quantity * i.price) AS total_inventory_value FROM inventory i JOIN categories c ON i.category = c.id WHERE c.country = 'UK' GROUP BY c.category; |
Which defense projects have been delayed in the Asia-Pacific region? | CREATE TABLE DefenseProjects (id INT,project_name VARCHAR(255),region VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO DefenseProjects (id,project_name,region,start_date,end_date) VALUES (1,'Aircraft Carrier Construction','Asia-Pacific','2020-01-01','2023-12-31'),(2,'Cybersecurity Training Program','Asia-Pacific','2019-06-01','2021-05-31'); | SELECT project_name FROM DefenseProjects WHERE region = 'Asia-Pacific' AND end_date < CURDATE(); |
Delete a record from the broadband_usage table | CREATE TABLE broadband_usage (usage_id INT,subscriber_id INT,usage_start_time TIMESTAMP,usage_end_time TIMESTAMP,data_used DECIMAL(10,2)); | DELETE FROM broadband_usage WHERE usage_id = 11111; |
Show the top 3 most liked articles and their authors, published in the last month. | CREATE TABLE articles (id INT,title TEXT,category TEXT,likes INT,created_at DATETIME,author_id INT); INSERT INTO articles (id,title,category,likes,created_at,author_id) VALUES (1,'Climate crisis: 12 years to save the planet','climate change',100,'2022-01-01 10:30:00',123); | SELECT title, author_id, likes FROM articles WHERE created_at >= DATE_SUB(NOW(), INTERVAL 1 MONTH) ORDER BY likes DESC LIMIT 3 |
What is the average age of all female news reporters across all news agencies? | CREATE TABLE news_agency (name VARCHAR(255),location VARCHAR(255));CREATE TABLE reporter (id INT,name VARCHAR(255),age INT,gender VARCHAR(10),news_agency_id INT); INSERT INTO news_agency (name,location) VALUES ('ABC News','New York'),('CNN','Atlanta'),('Fox News','New York'); INSERT INTO reporter (id,name,age,gender,news_agency_id) VALUES (1,'Alice',35,'Female',1),(2,'Bella',45,'Female',2),(3,'Carol',30,'Female',3); | SELECT AVG(age) FROM reporter WHERE gender = 'Female'; |
Insert a new entry in the 'divers' table for 'Selma' who is from 'Brazil' and has 'PADI' certification. | CREATE TABLE divers (diver_id INT,name TEXT,country TEXT,certification TEXT); | INSERT INTO divers (diver_id, name, country, certification) VALUES (4, 'Selma', 'Brazil', 'PADI'); |
Find the top 5 players with the highest scores in the 'historical_tournaments' view, including their scores and the names of the tournaments they participated in. | CREATE VIEW historical_tournaments AS SELECT tournaments.tournament_name,players.player_name,players.score FROM tournaments JOIN players_scores ON tournaments.tournament_id = players_scores.tournament_id JOIN players ON players_scores.player_id = players.player_id; CREATE TABLE tournaments (tournament_id INT,tournament_name TEXT); CREATE TABLE players_scores (player_id INT,tournament_id INT,score INT); CREATE TABLE players (player_id INT,player_name TEXT); | SELECT players.player_name, MAX(players_scores.score) as high_score, tournaments.tournament_name FROM historical_tournaments JOIN players ON historical_tournaments.player_id = players.player_id JOIN players_scores ON historical_tournaments.player_id = players_scores.player_id JOIN tournaments ON players_scores.tournament_id = tournaments.tournament_id GROUP BY players.player_id, tournaments.tournament_name ORDER BY high_score DESC LIMIT 5; |
Show the total rainfall (in millimeters) for each field in the 'PrecisionFarm' farm from May to August 2021. | CREATE TABLE RainfallData (id INT,field VARCHAR(255),timestamp TIMESTAMP,rainfall DECIMAL(5,2)); | SELECT field, SUM(rainfall) FROM RainfallData WHERE field IN ('PrecisionFarm1', 'PrecisionFarm2', 'PrecisionFarm3') AND MONTH(timestamp) BETWEEN 5 AND 8 AND YEAR(timestamp) = 2021 GROUP BY field; |
What is the average temperature recorded by weather stations in the 'PrecisionFarm1' field during the growing season of 2021? | CREATE TABLE WeatherStations (id INT,field VARCHAR(255),temperature DECIMAL(5,2),timestamp TIMESTAMP); | SELECT AVG(temperature) FROM WeatherStations WHERE field = 'PrecisionFarm1' AND timestamp BETWEEN '2021-03-01' AND '2021-10-31'; |
Calculate the average daily production of Samarium for each country in the Asia continent from January 1st, 2020 to December 31st, 2020. | CREATE TABLE Country (Code TEXT,Name TEXT,Continent TEXT); INSERT INTO Country (Code,Name,Continent) VALUES ('CN','China','Asia'),('AU','Australia','Australia'),('KR','South Korea','Asia'),('IN','India','Asia'); CREATE TABLE ProductionDaily (Date DATE,Country TEXT,Company TEXT,Element TEXT,Quantity INT); INSERT INTO ProductionDaily (Date,Country,Company,Element,Quantity) VALUES ('2020-01-01','CN','Kappa Inc','Samarium',50),('2020-01-01','IN','Lambda Ltd','Samarium',40),('2020-01-02','CN','Kappa Inc','Samarium',55),('2020-01-02','IN','Lambda Ltd','Samarium',45); | SELECT Country, AVG(Quantity) FROM ProductionDaily WHERE Element = 'Samarium' AND Date BETWEEN '2020-01-01' AND '2020-12-31' AND Country IN (SELECT Name FROM Country WHERE Continent = 'Asia') GROUP BY Country; |
How many instances of 'Dysprosium' production were there in each country after 2015? | CREATE TABLE production (element VARCHAR(10),country VARCHAR(20),quantity INT,year INT); INSERT INTO production (element,country,quantity,year) VALUES ('Dysprosium','Malaysia',8000,2016),('Dysprosium','India',11000,2017),('Dysprosium','Malaysia',9000,2018),('Dysprosium','India',13000,2019),('Dysprosium','Malaysia',10000,2020),('Dysprosium','India',14000,2021); | SELECT country, COUNT(*) FROM production WHERE element = 'Dysprosium' AND year > 2015 GROUP BY country; |
What is the average annual REE production for Vietnam between 2017 and 2021? | CREATE TABLE production (country VARCHAR(255),REE VARCHAR(255),amount INT,year INT); INSERT INTO production (country,REE,amount,year) VALUES ('Vietnam','Neodymium',2000,2017); INSERT INTO production (country,REE,amount,year) VALUES ('Vietnam','Praseodymium',2200,2018); INSERT INTO production (country,REE,amount,year) VALUES ('Vietnam','Dysprosium',2500,2019); INSERT INTO production (country,REE,amount,year) VALUES ('Vietnam','Terbium',2800,2020); INSERT INTO production (country,REE,amount,year) VALUES ('Vietnam',' Europium',3100,2021); | SELECT AVG(amount) as avg_annual_production FROM production WHERE country = 'Vietnam' AND year BETWEEN 2017 AND 2021; |
What is the average production of Gadolinium in 2018 for countries with production > 15,000? | CREATE TABLE production (country VARCHAR(255),year INT,element VARCHAR(10),quantity INT); INSERT INTO production (country,year,element,quantity) VALUES ('China',2018,'Gd',25000),('Australia',2018,'Gd',20000),('China',2018,'Gd',26000),('Russia',2018,'Gd',15000); | SELECT AVG(quantity) FROM production WHERE year = 2018 AND country IN (SELECT country FROM production WHERE element = 'Gd' AND quantity > 15000 GROUP BY country); |
What is the number of properties with inclusive housing features in the 'housing_data' table for each city? | CREATE TABLE housing_data (id INT,address VARCHAR(255),city VARCHAR(255),state VARCHAR(255),square_footage INT,inclusive_features VARCHAR(255)); INSERT INTO housing_data (id,address,city,state,square_footage,inclusive_features) VALUES (1,'123 Maple St','San Francisco','CA',1200,'wheelchair accessible'),(2,'456 Oak St','Austin','TX',1500,'none'),(3,'789 Pine St','Seattle','WA',1800,'affordable housing'); | SELECT city, COUNT(*) FROM housing_data WHERE inclusive_features IS NOT NULL GROUP BY city; |
What is the average CO2 emission reduction in Geothermal Projects? | CREATE TABLE Geothermal_Projects (project_id INT,location VARCHAR(50),co2_emission_reduction FLOAT); INSERT INTO Geothermal_Projects (project_id,location,co2_emission_reduction) VALUES (1,'Iceland',4500.0),(2,'New Zealand',3000.0),(3,'Italy',2500.0); | SELECT AVG(co2_emission_reduction) FROM Geothermal_Projects; |
List all restaurants that serve gluten-free options? | CREATE TABLE restaurants (restaurant_id INT,name VARCHAR(255),serves_gluten_free BOOLEAN); INSERT INTO restaurants (restaurant_id,name,serves_gluten_free) VALUES (1,'Green Garden',TRUE),(2,'Bistro Bella',FALSE),(3,'Asian Fusion',FALSE); CREATE TABLE menu (menu_item VARCHAR(255),gluten_free BOOLEAN); INSERT INTO menu (menu_item,gluten_free) VALUES ('Quinoa Salad',TRUE),('Chicken Alfredo',FALSE); | SELECT r.name FROM restaurants r WHERE r.serves_gluten_free = TRUE; |
What is the average labor cost for factories in African countries? | CREATE TABLE factories (factory_id INT,country VARCHAR(50),labor_cost DECIMAL(10,2)); INSERT INTO factories (factory_id,country,labor_cost) VALUES (1,'Kenya',500),(2,'Nigeria',450),(3,'South Africa',520); | SELECT AVG(factories.labor_cost) FROM factories WHERE factories.country IN ('Kenya', 'Nigeria', 'South Africa'); |
How many astrophysics research projects are there on Neutron Stars and Quasars? | CREATE TABLE AstroResearch (ResearchID INT PRIMARY KEY,Subject VARCHAR(255),Description TEXT,ResearcherID INT); INSERT INTO AstroResearch (ResearchID,Subject,Description,ResearcherID) VALUES (3,'Neutron Stars','Observations and simulations of neutron stars',103); INSERT INTO AstroResearch (ResearchID,Subject,Description,ResearcherID) VALUES (4,'Quasars','Study of quasars in distant galaxies',104); | SELECT COUNT(*) FROM AstroResearch WHERE Subject IN ('Neutron Stars', 'Quasars'); |
What is the minimum distance from Earth recorded by each spacecraft during its mission? | CREATE TABLE spacecraft_missions (id INT,spacecraft_name VARCHAR(255),mission_duration INT,min_distance_from_earth FLOAT); INSERT INTO spacecraft_missions (id,spacecraft_name,mission_duration,min_distance_from_earth) VALUES (1,'Spacecraft1',365,500.0),(2,'Spacecraft2',730,700.0); | SELECT spacecraft_name, MIN(min_distance_from_earth) FROM spacecraft_missions GROUP BY spacecraft_name; |
What is the total number of tickets sold in the "ticket_sales" table for soccer games in the year 2021? | CREATE TABLE ticket_sales (id INT,sport TEXT,date DATE,quantity INT); INSERT INTO ticket_sales (id,sport,date,quantity) VALUES (1,'basketball','2022-01-01',50),(2,'soccer','2021-12-31',75); | SELECT SUM(quantity) FROM ticket_sales WHERE sport = 'soccer' AND YEAR(date) = 2021; |
How many high severity vulnerabilities were found in the transportation department's systems in the last month? | CREATE TABLE dept_vulnerabilities (id INT,department VARCHAR(255),severity FLOAT,discovered_at TIMESTAMP); INSERT INTO dept_vulnerabilities (id,department,severity,discovered_at) VALUES (1,'transportation',8.5,'2021-09-03 09:30:00'),(2,'education',4.0,'2021-10-20 11:00:00'); | SELECT COUNT(*) FROM dept_vulnerabilities WHERE department = 'transportation' AND severity >= 7.0 AND discovered_at >= DATE_SUB(NOW(), INTERVAL 1 MONTH); |
What is the total number of security incidents for each department in the organization? | CREATE TABLE incident (incident_id INT,incident_date DATE,incident_description TEXT,department_id INT);CREATE TABLE department (department_id INT,department_name VARCHAR(255)); | SELECT d.department_name, COUNT(i.incident_id) AS incident_count FROM incident i JOIN department d ON i.department_id = d.department_id GROUP BY d.department_name; |
Update policyholder information for policy type 'Renters'. | CREATE TABLE Policy (PolicyID INT,PolicyType VARCHAR(50),PolicyHolderName VARCHAR(50),PolicyHolderAddress VARCHAR(50)); INSERT INTO Policy VALUES (1,'Renters','John Doe','123 Main St'),(2,'Home','Jane Smith','456 Elm St'),(3,'Life','Bob Johnson','789 Oak Rd'); | UPDATE Policy SET PolicyHolderName = 'Jane Doe', PolicyHolderAddress = '456 Oak Rd' WHERE PolicyType = 'Renters'; |
Find the number of hybrid vehicles sold in the US, Germany, and Japan. | CREATE TABLE vehicle_sales (sale_id INT,vehicle_id INT,country VARCHAR(20),quantity INT); CREATE TABLE vehicles (vehicle_id INT,model VARCHAR(20),manufacture VARCHAR(20),vehicle_type VARCHAR(20)); | SELECT SUM(vs.quantity) FROM vehicle_sales vs JOIN vehicles v ON vs.vehicle_id = v.vehicle_id WHERE v.vehicle_type = 'hybrid' AND vs.country IN ('US', 'Germany', 'Japan'); |
What is the average safety rating of electric vehicles released in the US after 2018? | CREATE TABLE if not exists Vehicles (Id int,Name varchar(100),Type varchar(50),SafetyRating float,ReleaseYear int,Country varchar(50)); INSERT INTO Vehicles (Id,Name,Type,SafetyRating,ReleaseYear,Country) VALUES (1,'Tesla Model 3','Electric',5.3,2017,'USA'),(2,'Tesla Model S','Electric',5.4,2012,'USA'),(3,'Nissan Leaf','Electric',4.8,2010,'Japan'); | SELECT AVG(SafetyRating) FROM (SELECT SafetyRating FROM Vehicles WHERE Type = 'Electric' AND Country = 'USA' AND ReleaseYear > 2018) AS Subquery; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.