instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
How many mobile subscribers have upgraded to 5G since its launch? | CREATE TABLE network_upgrades (subscriber_id INT,service VARCHAR(10),upgrade_date DATE); INSERT INTO network_upgrades (subscriber_id,service,upgrade_date) VALUES (1,'mobile','2021-04-15'),(2,'mobile','2021-07-20'); | SELECT COUNT(*) FROM network_upgrades WHERE service = 'mobile' AND upgrade_date >= (SELECT MIN(upgrade_date) FROM network_upgrades WHERE service = 'mobile' AND upgrade_date >= '2020-04-01'); |
What is the average word count for articles in 'category2'? | CREATE TABLE articles (id INT,title VARCHAR(50),word_count INT,category VARCHAR(20)); INSERT INTO articles (id,title,word_count,category) VALUES (1,'Article1',400,'category1'),(2,'Article2',600,'category2'),(3,'Article3',450,'category3'); | SELECT AVG(word_count) FROM articles WHERE category = 'category2' |
Delete all employee records with a hire date before 2019-01-01. | CREATE TABLE departments (dept_id INT,dept_name TEXT); CREATE TABLE employees (emp_id INT,dept_id INT,hire_date DATE); INSERT INTO departments (dept_id,dept_name) VALUES (1,'HR'),(2,'IT'),(3,'Marketing'); INSERT INTO employees (emp_id,dept_id,hire_date) VALUES (1,1,'2018-01-01'),(2,2,'2019-05-05'),(3,3,'2020-07-01'),(4,1,'2018-12-30'); | DELETE FROM employees WHERE hire_date < '2019-01-01'; |
Identify the daily sales trend for the past year, including the current day, by calculating the moving average of units sold per day. | CREATE TABLE daily_sales (sale_date DATE,units_sold INT); INSERT INTO daily_sales (sale_date,units_sold) VALUES ('2021-04-01',500),('2021-04-02',600),('2021-04-03',700),('2021-04-04',800),('2021-04-05',900),('2022-04-01',1000); | SELECT sale_date, AVG(units_sold) OVER (ORDER BY sale_date ROWS BETWEEN 29 PRECEDING AND CURRENT ROW) AS moving_average FROM daily_sales WHERE sale_date >= DATE_TRUNC('day', CURRENT_DATE - INTERVAL '365 day') ORDER BY sale_date; |
What is the average visitor engagement score in Berlin? | CREATE TABLE VisitorEngagementScores (id INT,city VARCHAR(50),visitor_id INT,engagement_score INT); | SELECT AVG(engagement_score) FROM VisitorEngagementScores WHERE city = 'Berlin'; |
What's the average soil moisture for organic farms? | CREATE TABLE farm (id INT,name VARCHAR(50),size FLOAT,organic BOOLEAN,irrigation_system BOOLEAN,PRIMARY KEY(id)); INSERT INTO farm (id,name,size,organic,irrigation_system) VALUES (1,'Farm A',50.3,true,true); INSERT INTO farm (id,name,size,organic,irrigation_system) VALUES (2,'Farm B',75.8,true,false); INSERT INTO farm (id,name,size,organic,irrigation_system) VALUES (3,'Farm C',35.1,false,true); CREATE TABLE soil_moisture (id INT,farm_id INT,moisture FLOAT,PRIMARY KEY(id)); INSERT INTO soil_moisture (id,farm_id,moisture) VALUES (1,1,45.6); INSERT INTO soil_moisture (id,farm_id,moisture) VALUES (2,2,55.1); INSERT INTO soil_moisture (id,farm_id,moisture) VALUES (3,3,35.8); | SELECT f.name, AVG(sm.moisture) FROM farm f INNER JOIN soil_moisture sm ON f.id = sm.farm_id WHERE f.organic = true GROUP BY f.name; |
What is the total claim amount for policyholders who are older than 40? | CREATE TABLE policyholders (id INT,age INT,policy_id INT); INSERT INTO policyholders (id,age,policy_id) VALUES (1,35,1),(2,45,2),(3,50,3); CREATE TABLE claims (id INT,policy_id INT,claim_amount INT); INSERT INTO claims (id,policy_id,claim_amount) VALUES (1,1,5000),(2,2,3000),(3,3,10000); | SELECT SUM(claim_amount) FROM claims JOIN policyholders ON claims.policy_id = policyholders.policy_id WHERE policyholders.age > 40; |
What is the difference between the maximum and minimum open price for each stock? | CREATE TABLE stocks (stock_symbol TEXT,date DATE,open_price FLOAT,close_price FLOAT); INSERT INTO stocks (stock_symbol,date,open_price,close_price) VALUES ('GOOGL','2022-01-01',1500.00,1550.00),('GOOGL','2022-01-02',1550.00,1600.00),('MSFT','2022-01-01',200.00,210.00),('MSFT','2022-01-02',210.00,220.00); | SELECT stock_symbol, MAX(open_price) OVER (PARTITION BY stock_symbol ORDER BY stock_symbol) - MIN(open_price) OVER (PARTITION BY stock_symbol ORDER BY stock_symbol) as price_difference FROM stocks; |
Calculate total revenue from size inclusive sustainable sales | CREATE TABLE sales (id SERIAL PRIMARY KEY,product_id INTEGER,size INTEGER,price DECIMAL(5,2)); INSERT INTO sales (product_id,size,price) VALUES (1,10,50.00),(2,8,30.00),(3,14,75.00),(4,20,40.00),(5,14,60.00),(6,10,55.00); CREATE TABLE products (id INTEGER PRIMARY KEY,name VARCHAR(50),size INTEGER,is_sustainable BOOLEAN); INSERT INTO products (id,name,size,is_sustainable) VALUES (1,'Dress',10,true),(2,'Shirt',8,false),(3,'Blouse',14,true),(4,'Skirt',20,true),(5,'Pants',14,true),(6,'Jacket',10,false); | SELECT SUM(sales.price) FROM sales JOIN products ON sales.product_id = products.id WHERE products.size BETWEEN 8 AND 22 AND products.is_sustainable = true; |
What is the average production for wells in the Gulf of Mexico, partitioned by the well's status? | CREATE TABLE gulf_wells (well_id INT,well_name VARCHAR(255),location VARCHAR(255),production FLOAT,well_status VARCHAR(50)); INSERT INTO gulf_wells (well_id,well_name,location,production,well_status) VALUES (3,'Well C','Gulf of Mexico',600.0,'Active'),(4,'Well D','Gulf of Mexico',450.0,'Inactive'); | SELECT well_status, AVG(production) OVER (PARTITION BY well_status) as avg_production FROM gulf_wells WHERE location = 'Gulf of Mexico'; |
What is the maximum salary for each position in the HR department? | CREATE TABLE positions (id INT,position VARCHAR(50),department VARCHAR(50),salary FLOAT); INSERT INTO positions (id,position,department,salary) VALUES (1,'HR Manager','HR',90000.0),(2,'HR Specialist','HR',70000.0),(3,'HR Coordinator','HR',60000.0); | SELECT position, MAX(salary) FROM positions WHERE department = 'HR' GROUP BY position; |
What is the average water consumption per capita in the agriculture sector in Canada for the year 2021? | CREATE TABLE population (region VARCHAR(20),people INT); INSERT INTO population (region,people) VALUES ('Canada',38000000); CREATE TABLE agriculture_water_usage (region VARCHAR(20),water_consumption FLOAT,usage_date DATE); INSERT INTO agriculture_water_usage (region,water_consumption,usage_date) VALUES ('Canada',12000000000,'2021-01-01'); | SELECT water_consumption / people FROM agriculture_water_usage, population WHERE agriculture_water_usage.region = population.region AND EXTRACT(YEAR FROM usage_date) = 2021; |
What is the maximum duration of virtual tours in New Zealand? | CREATE TABLE virtual_tours_nz (tour_id INT,tour_name VARCHAR(255),country VARCHAR(255),duration INT); INSERT INTO virtual_tours_nz (tour_id,tour_name,country,duration) VALUES (1,'Virtual Tour Queenstown','New Zealand',120); INSERT INTO virtual_tours_nz (tour_id,tour_name,country,duration) VALUES (2,'Virtual Tour Wellington','New Zealand',90); INSERT INTO virtual_tours_nz (tour_id,tour_name,country,duration) VALUES (3,'Virtual Tour Auckland','New Zealand',105); | SELECT country, MAX(duration) FROM virtual_tours_nz WHERE country = 'New Zealand'; |
What is the total weight of containers that were delayed in the last 30 days? | CREATE TABLE Shipment (shipment_id INT,container_id INT,port_id INT,shipping_date DATE); CREATE TABLE Container (container_id INT,weight FLOAT,last_known_location TEXT); | SELECT SUM(c.weight) as total_weight FROM Container c JOIN Shipment s ON c.container_id = s.container_id WHERE s.shipping_date >= NOW() - INTERVAL '30 days' AND c.last_known_location = 'delayed'; |
What is the average attendance for baseball games in the Western region? | CREATE TABLE attendance (attendance_id INT,game_id INT,region VARCHAR(50),attendees INT); INSERT INTO attendance (attendance_id,game_id,region,attendees) VALUES (1,1,'Western',3000); INSERT INTO attendance (attendance_id,game_id,region,attendees) VALUES (2,2,'Central',4000); CREATE TABLE games (game_id INT,sport VARCHAR(50)); INSERT INTO games (game_id,sport) VALUES (1,'Baseball'); INSERT INTO games (game_id,sport) VALUES (2,'Softball'); | SELECT AVG(attendees) FROM attendance INNER JOIN games ON attendance.game_id = games.game_id WHERE region = 'Western' AND sport = 'Baseball'; |
List the hotels in the hotels table that offer either a gym or a spa facility, but not both. | CREATE TABLE hotels (hotel_id INT,name VARCHAR(50),facility VARCHAR(50)); INSERT INTO hotels (hotel_id,name,facility) VALUES (1,'Hotel X','spa,gym'),(2,'Hotel Y','gym'),(3,'Hotel Z','spa'); | SELECT * FROM hotels WHERE (facility LIKE '%gym%' AND facility NOT LIKE '%spa%') OR (facility LIKE '%spa%' AND facility NOT LIKE '%gym%'); |
Which mental health parity laws were enacted in California after 2015? | CREATE TABLE mental_health_parity (law_id INT,state_id INT,law_name VARCHAR(100),enactment_date DATE); INSERT INTO mental_health_parity (law_id,state_id,law_name,enactment_date) VALUES (1,1,'MHP Law 1','2013-01-01'),(2,1,'MHP Law 2','2016-01-01'),(3,2,'MHP Law 3','2014-01-01'),(4,3,'MHP Law 4','2017-01-01'); | SELECT law_name FROM mental_health_parity WHERE state_id = 1 AND enactment_date > '2015-01-01' ORDER BY enactment_date; |
Who are the artists who have created works in both 'Cubism' and 'Fauvism' categories? | CREATE TABLE Artists (ArtistID INT PRIMARY KEY,Name TEXT); CREATE TABLE Artworks (ArtworkID INT PRIMARY KEY,Title TEXT,ArtistID INT,Category TEXT); | SELECT Artists.Name FROM Artists INNER JOIN Artworks ON Artists.ArtistID = Artworks.ArtistID WHERE Artworks.Category IN ('Cubism', 'Fauvism') GROUP BY Artists.Name HAVING COUNT(DISTINCT Artworks.Category) = 2; |
Which indigenous communities have experienced relocation due to coastal erosion? | CREATE TABLE Relocations (community TEXT,year INT,reason TEXT); INSERT INTO Relocations (community,year,reason) VALUES ('Inuit',1995,'Erosion'),('Inuit',2005,'Flooding'),('Sami',2010,'Thawing Permafrost'),('Gwich’in',2015,'Thawing Permafrost'),('Yupik',2020,'Coastal Erosion'),('Aleut',2018,'Coastal Erosion'); | SELECT community FROM Relocations WHERE reason = 'Coastal Erosion' GROUP BY community; |
What is the total number of emergency calls in each community policing sector in the last month? | CREATE TABLE sectors (sid INT,sector_name TEXT); CREATE TABLE emergencies (eid INT,sector_id INT,emergency_date TEXT); INSERT INTO sectors VALUES (1,'Sector A'); INSERT INTO sectors VALUES (2,'Sector B'); INSERT INTO emergencies VALUES (1,1,'2022-01-05'); INSERT INTO emergencies VALUES (2,1,'2022-02-10'); INSERT INTO emergencies VALUES (3,2,'2022-03-01'); INSERT INTO emergencies VALUES (4,2,'2022-03-15'); | SELECT s.sector_name, COUNT(e.eid) FROM sectors s JOIN emergencies e ON s.sid = e.sector_id AND e.emergency_date >= DATEADD(month, -1, GETDATE()) GROUP BY s.sector_name; |
List all the habitats and the number of animals of each species in 'protected_habitats' table that require conservation efforts? | CREATE TABLE protected_habitats (habitat_id INT,habitat_name VARCHAR(50),species VARCHAR(50),conservation_needed BOOLEAN); | SELECT p.habitat_name, a.species, COUNT(*) as num_animals FROM protected_habitats p INNER JOIN animal_population a ON p.species = a.species WHERE p.conservation_needed = TRUE GROUP BY p.habitat_name, a.species; |
What was the total amount donated by the top 5 donors in the 'q1_2022' donation period? | CREATE TABLE donors (id INT,name TEXT,total_donation FLOAT); INSERT INTO donors (id,name,total_donation) VALUES (1,'John Doe',500.00),(2,'Jane Smith',400.00),(3,'Mike Johnson',300.00),(4,'Alice Davis',200.00),(5,'Bob Williams',150.00); | SELECT SUM(total_donation) FROM (SELECT total_donation FROM donors WHERE donors.id IN (SELECT id FROM donors WHERE donation_period = 'q1_2022' ORDER BY total_donation DESC LIMIT 5)) subquery; |
Which financial institution in Asia has the highest average loan amount? | CREATE SCHEMA if not exists finance;CREATE TABLE if not exists loans (id INT PRIMARY KEY,institution_name TEXT,region TEXT,amount DECIMAL(10,2)); INSERT INTO loans (id,institution_name,region,amount) VALUES (1,'ABC Microfinance','Asia',5000.00),(2,'DEF Microfinance','Asia',8000.00),(3,'GHI Microfinance','Asia',6000.00); | SELECT institution_name, AVG(amount) as avg_amount FROM finance.loans WHERE region = 'Asia' GROUP BY institution_name ORDER BY avg_amount DESC LIMIT 1; |
What is the maximum score for each player in the "Sports" genre? | CREATE TABLE PlayerScores (PlayerID int,PlayerName varchar(50),Game varchar(50),Score int); | SELECT PlayerName, MAX(Score) OVER(PARTITION BY PlayerID) as MaxScore FROM PlayerScores WHERE Game = 'Sports'; |
Get the top 5 oldest policyholders | CREATE TABLE policyholders (id INT,name TEXT,dob DATE,gender TEXT,state TEXT); INSERT INTO policyholders (id,name,dob,gender,state) VALUES (1,'John Doe','1960-01-01','Male','NY'),(2,'Jane Smith','1970-05-10','Female','CA'),(3,'Mike Johnson','1985-08-15','Male','TX'); | SELECT * FROM policyholders ORDER BY dob LIMIT 5; |
What is the total capacity (in MW) of geothermal power plants in the 'RenewableEnergyProjects' table? | CREATE TABLE RenewableEnergyProjects (id INT,projectName VARCHAR(50),capacity INT,technology VARCHAR(50)); INSERT INTO RenewableEnergyProjects (id,projectName,capacity,technology) VALUES (1,'GeoPower One',30,'Geothermal'),(2,'GeoPower Two',50,'Geothermal'),(3,'SolarFarm One',50,'Solar'),(4,'WindFarm East',100,'Wind'); | SELECT SUM(capacity) FROM RenewableEnergyProjects WHERE technology = 'Geothermal'; |
What is the average cost of devices for users in rural areas? | CREATE TABLE devices (device_id INT,device_cost FLOAT,user_location VARCHAR(10)); INSERT INTO devices VALUES (1,300,'rural'),(2,500,'urban'),(3,400,'rural'); | SELECT AVG(device_cost) FROM devices WHERE user_location = 'rural'; |
What is the average number of cybersecurity incidents per country? | CREATE TABLE cybersecurity_incidents (country TEXT,year INT,num_incidents INT); INSERT INTO cybersecurity_incidents (country,year,num_incidents) VALUES ('USA',2019,50000),('UK',2019,7000),('China',2019,12000),('USA',2020,55000),('UK',2020,8000),('China',2020,15000); | SELECT AVG(num_incidents) as avg_incidents_per_country FROM cybersecurity_incidents; |
What was the average attendance at the 'Birds Nest' during the 2008 Olympics? | CREATE TABLE olympic_stadiums (name VARCHAR(255),avg_attendance FLOAT); INSERT INTO olympic_stadiums (name,avg_attendance) VALUES ('Birds Nest',91000); | SELECT avg_attendance FROM olympic_stadiums WHERE name = 'Birds Nest'; |
Identify the countries that increased their recycling rate by more than 10% between 2019 and 2020. | CREATE TABLE recycling_rates_history (id INT,country VARCHAR(255),year INT,recycling_rate DECIMAL(5,4)); INSERT INTO recycling_rates_history (id,country,year,recycling_rate) VALUES (1,'China',2019,0.40),(2,'China',2020,0.45),(3,'India',2019,0.30),(4,'India',2020,0.33),(5,'Brazil',2019,0.25),(6,'Brazil',2020,0.24); | SELECT country FROM (SELECT country, recycling_rate, year, LAG(recycling_rate) OVER (PARTITION BY country ORDER BY year) AS prev_rate FROM recycling_rates_history) t WHERE country IN (SELECT country FROM t WHERE year = 2020) GROUP BY country HAVING MAX(year) = 2020 AND MIN(year) = 2019 AND AVG((recycling_rate - prev_rate) / prev_rate * 100) > 10; |
What is the average media literacy score of high school students in Asia? | CREATE TABLE media_literacy_scores (id INT,student_id INT,score INT,school VARCHAR(255),region VARCHAR(255)); INSERT INTO media_literacy_scores (id,student_id,score,school,region) VALUES (1,123,80,'School A','Asia'),(2,456,85,'School B','Asia'),(3,789,70,'School C','Asia'); | SELECT AVG(score) FROM media_literacy_scores WHERE region = 'Asia'; |
What is the average temperature in the Pacific Ocean? | CREATE TABLE ocean_temperatures (ocean TEXT,temperature FLOAT); | SELECT AVG(temperature) FROM ocean_temperatures WHERE ocean = 'Pacific Ocean'; |
What is the maximum number of vulnerabilities found in a single system in the financial sector in 2022? | CREATE TABLE vulnerabilities (system_id INT,sector VARCHAR(255),year INT,count INT); INSERT INTO vulnerabilities (system_id,sector,year,count) VALUES (1,'Financial',2022,20),(2,'Financial',2022,15),(3,'Financial',2022,25),(4,'Financial',2022,30),(5,'Financial',2022,35); | SELECT MAX(count) FROM vulnerabilities WHERE sector = 'Financial' AND year = 2022; |
What is the minimum price of size 8 jeans in the current season? | CREATE TABLE Products (product_id INT,product_name VARCHAR(50),size INT,category VARCHAR(50),price DECIMAL(5,2),season VARCHAR(50)); INSERT INTO Products (product_id,product_name,size,category,price,season) VALUES (1001,'Jeans',8,'Bottoms',59.99,'Spring'),(1002,'Jeans',10,'Bottoms',69.99,'Spring'),(1003,'Jeans',8,'Bottoms',54.99,'Spring'); | SELECT MIN(price) FROM Products WHERE size = 8 AND category = 'Bottoms' AND season = 'Spring'; |
Update 'crime_stats' table to set all 'arson' records for '2018' to 'vandalism' | CREATE TABLE crime_stats (id INT,year INT,month INT,type VARCHAR(255),PRIMARY KEY(id)); | UPDATE crime_stats SET type = 'vandalism' WHERE year = 2018 AND type = 'arson'; |
What is the average time to resolve security incidents for each severity level in the last quarter? | CREATE TABLE incident_resolution (id INT,severity VARCHAR(50),resolution_time INT,incident_date DATE); INSERT INTO incident_resolution (id,severity,resolution_time,incident_date) VALUES (1,'Low',2,'2022-01-01'),(2,'Medium',5,'2022-01-02'),(3,'High',10,'2022-01-03'); | SELECT severity, AVG(resolution_time) as avg_resolution_time FROM incident_resolution WHERE incident_date >= DATE_SUB(CURDATE(), INTERVAL 3 MONTH) GROUP BY severity; |
What is the total number of crimes committed in each district in the last month? | CREATE TABLE districts (district_id INT,district_name TEXT);CREATE TABLE crimes (crime_id INT,district_id INT,crime_date DATE); | SELECT d.district_name, COUNT(c.crime_id) FROM districts d INNER JOIN crimes c ON d.district_id = c.district_id WHERE c.crime_date >= DATEADD(month, -1, GETDATE()) GROUP BY d.district_name; |
What is the infection rate of Tuberculosis in each region? | CREATE TABLE tb_cases(id INT,patient_id INT,region TEXT,date DATE); CREATE TABLE tb_patients(id INT,age INT,gender TEXT); | SELECT region, COUNT(*)/SUM(population) as infection_rate FROM tb_cases JOIN (SELECT region, SUM(population) as population FROM census GROUP BY region) USING(region) GROUP BY region; |
List all movies directed by Asian directors with a rating over 8.5. | CREATE TABLE movies (id INT,title TEXT,director_id INT,rating DECIMAL(3,2)); INSERT INTO movies (id,title,director_id,rating) VALUES (1,'Movie 1',1,8.7); CREATE TABLE directors (id INT,name TEXT,ethnicity TEXT); INSERT INTO directors (id,name,ethnicity) VALUES (1,'Director 1','Asian'); | SELECT m.title FROM movies m INNER JOIN directors d ON m.director_id = d.id WHERE d.ethnicity = 'Asian' AND m.rating > 8.5; |
Identify the job titles and corresponding salaries of employees earning more than the average salary. | CREATE TABLE Employees (EmployeeID INT,JobTitle VARCHAR(50),Department VARCHAR(50),Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID,JobTitle,Department,Salary) VALUES (1,'Software Engineer','IT',80000.00); INSERT INTO Employees (EmployeeID,JobTitle,Department,Salary) VALUES (2,'HR Manager','HR',60000.00); | SELECT JobTitle, Salary FROM Employees WHERE Salary > (SELECT AVG(Salary) FROM Employees); |
Which sustainable sourcing practices were implemented in Ontario in Q2 2022? | CREATE TABLE sustainable_sourcing (practice VARCHAR(255),location VARCHAR(255),quarter INT,year INT); INSERT INTO sustainable_sourcing (practice,location,quarter,year) VALUES ('Free-range eggs','Ontario',2,2022),('Solar power','Ontario',2,2022); | SELECT DISTINCT practice FROM sustainable_sourcing WHERE location = 'Ontario' AND quarter = 2 AND year = 2022; |
What is the average age of readers who prefer reading articles about technology in the "TechNews" newspaper? | CREATE TABLE Readers (id INT,age INT,preference VARCHAR(20)); INSERT INTO Readers (id,age,preference) VALUES (1,25,'technology'),(2,32,'politics'),(3,45,'technology'); | SELECT AVG(age) FROM Readers WHERE preference = 'technology'; |
Which athletes have a higher salary than the average salary in their sport? | CREATE TABLE athlete_salaries (id INT,name VARCHAR(50),sport VARCHAR(50),salary INT); INSERT INTO athlete_salaries (id,name,sport,salary) VALUES (1,'LeBron James','Basketball',4000000),(2,'Messi','Soccer',5000000); | SELECT name, sport, salary FROM (SELECT name, sport, salary, AVG(salary) OVER (PARTITION BY sport) as avg_salary FROM athlete_salaries) subquery WHERE salary > avg_salary; |
What are the top 3 chemicals produced in 'Illinois' based on quantity? | CREATE TABLE Chemical_Plant (plant_name VARCHAR(255),location VARCHAR(255),chemical VARCHAR(255),quantity INT);INSERT INTO Chemical_Plant (plant_name,location,chemical,quantity) VALUES ('Chemical Plant A','Illinois','Ammonia',1200),('Chemical Plant B','Illinois','Chlorine',1500),('Chemical Plant C','Illinois','Sodium Hydroxide',1800); | SELECT chemical, SUM(quantity) AS total_quantity FROM Chemical_Plant WHERE location = 'Illinois' GROUP BY chemical ORDER BY total_quantity DESC LIMIT 3; |
What is the total network investment in New York for the past 3 years? | CREATE TABLE network_investments (investment_id INT,investment_amount FLOAT,investment_date DATE); INSERT INTO network_investments (investment_id,investment_amount,investment_date) VALUES (1,1000000,'2020-01-01'),(2,1500000,'2019-01-01'),(3,1200000,'2018-01-01'); | SELECT SUM(investment_amount) FROM network_investments WHERE investment_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 YEAR) AND state = 'New York'; |
What is the total quantity of ingredients used in each dish category? | CREATE TABLE Dishes (DishID INT,DishName VARCHAR(50),Category VARCHAR(50),IngredientQTY INT); INSERT INTO Dishes (DishID,DishName,Category,IngredientQTY) VALUES (1,'Veggie Pizza','Pizza',500),(2,'Margherita Pizza','Pizza',300),(3,'Chicken Caesar Salad','Salad',250),(4,'Garden Salad','Salad',400); | SELECT Category, SUM(IngredientQTY) as TotalIngredientQTY FROM Dishes GROUP BY Category; |
Who are the top 3 customers by sales in Asia? | CREATE TABLE Customers (id INT,customer_name VARCHAR(255),country VARCHAR(255)); INSERT INTO Customers (id,customer_name,country) VALUES (1,'John Smith','USA'),(2,'Jane Doe','Canada'),(3,'Li Xiang','China'),(4,'Park Soo-Jin','South Korea'); CREATE TABLE Orders (id INT,customer_id INT,order_value DECIMAL(5,2)); INSERT INTO Orders (id,customer_id,order_value) VALUES (1,1,50.00),(2,2,75.00),(3,3,100.00),(4,4,120.00); | SELECT Customers.customer_name, SUM(Orders.order_value) AS total_sales FROM Customers INNER JOIN Orders ON Customers.id = Orders.customer_id WHERE Customers.country LIKE 'Asia%' GROUP BY Customers.customer_name ORDER BY total_sales DESC LIMIT 3; |
Which game design features were updated the most in the past month? | CREATE TABLE Updates (UpdateID INT,GameID INT,UpdateDate DATE,Feature VARCHAR(20)); INSERT INTO Updates (UpdateID,GameID,UpdateDate,Feature) VALUES (1,1,'2022-01-01','Graphics'); INSERT INTO Updates (UpdateID,GameID,UpdateDate,Feature) VALUES (2,2,'2022-01-15','Gameplay'); | SELECT GameID, Feature, COUNT(*) as Count FROM Updates WHERE UpdateDate >= '2022-02-01' GROUP BY GameID, Feature |
Find the athlete with the highest number of assists in each season, for basketball players. | CREATE TABLE athletes (athlete_id INT,name VARCHAR(100),sport VARCHAR(50),position VARCHAR(50),assists INT); INSERT INTO athletes (athlete_id,name,sport,position,assists) VALUES (1,'John Doe','Basketball','Guard',700); INSERT INTO athletes (athlete_id,name,sport,position,assists) VALUES (2,'Jane Smith','Basketball','Forward',500); | SELECT athlete_id, name, sport, position, assists, ROW_NUMBER() OVER (PARTITION BY sport ORDER BY assists DESC) as rank FROM athletes WHERE sport = 'Basketball' |
What is the average recycling rate in California for the last 6 months? | CREATE TABLE recycling_rates (state VARCHAR(50),recycling_rate DECIMAL(5,2),date DATE); INSERT INTO recycling_rates (state,recycling_rate,date) VALUES ('California',0.65,'2022-01-01'),('California',0.67,'2022-02-01'),('California',0.68,'2022-03-01'),('California',0.70,'2022-04-01'),('California',0.72,'2022-05-01'),('California',0.75,'2022-06-01'); | SELECT AVG(recycling_rate) FROM recycling_rates WHERE state = 'California' AND date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH); |
Update the carbon sequestration value for a specific forest. | CREATE TABLE carbon_sequestration (id INT,name VARCHAR(50),sequestration_tons FLOAT); | UPDATE carbon_sequestration SET sequestration_tons = 120.5 WHERE name = 'Amazon Rainforest'; |
What is the number of properties available in each neighborhood with inclusive housing policies? | CREATE TABLE properties (id INT,neighborhood VARCHAR(20),meets_policy BOOLEAN); INSERT INTO properties (id,neighborhood,meets_policy) VALUES (1,'Neighborhood A',true),(2,'Neighborhood B',false),(3,'Neighborhood C',true),(4,'Neighborhood A',false); | SELECT neighborhood, COUNT(*) FROM properties WHERE meets_policy = true GROUP BY neighborhood; |
Update the 'space_exploration' table to mark the 'Apollo 11' mission as 'successful' | CREATE TABLE space_exploration (id INT PRIMARY KEY,mission_name VARCHAR(50),mission_status VARCHAR(20)); | UPDATE space_exploration SET mission_status = 'successful' WHERE mission_name = 'Apollo 11'; |
What is the maximum number of crimes committed by a single offender in a year? | CREATE TABLE offender_crimes (cid INT,oid INT,year INT,PRIMARY KEY(cid),FOREIGN KEY(oid) REFERENCES offenders(oid)); | SELECT oid, MAX(COUNT(*)) FROM offender_crimes GROUP BY oid; |
What is the total funding for biosensor technology development, per year, for the past 3 years? | CREATE SCHEMA if not exists biotech; CREATE TABLE if not exists biotech.funding (id INT,name VARCHAR(50),location VARCHAR(50),industry VARCHAR(50),funding DECIMAL(10,2),funded_date DATE); INSERT INTO biotech.funding (id,name,location,industry,funding,funded_date) VALUES (1,'FundingA','USA','Biosensor Technology',1500000,'2020-01-10'),(2,'FundingB','Canada','Bioprocess Engineering',4500000,'2019-02-23'),(3,'FundingC','USA','Synthetic Biology',5000000,'2018-09-01'),(4,'FundingD','USA','Biosensor Technology',8000000,'2019-03-12'),(5,'FundingE','Germany','Biosensor Technology',7000000,'2018-11-28'),(6,'FundingF','USA','Biosensor Technology',9000000,'2017-05-15'); | SELECT YEAR(funded_date) as year, SUM(funding) as total_funding FROM biotech.funding WHERE industry = 'Biosensor Technology' AND funded_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 YEAR) GROUP BY YEAR(funded_date); |
What is the maximum salary for each position in the Finance department? | CREATE TABLE finance_positions (id INT,position VARCHAR(50),department VARCHAR(50),salary FLOAT); INSERT INTO finance_positions (id,position,department,salary) VALUES (1,'Finance Manager','Finance',100000.0),(2,'Finance Specialist','Finance',80000.0),(3,'Finance Coordinator','Finance',70000.0); | SELECT position, MAX(salary) FROM finance_positions WHERE department = 'Finance' GROUP BY position; |
What is the average number of crops grown per farm in urban agriculture? | CREATE TABLE urban_farms (id INT,farm_id INT,crop_type VARCHAR(255)); | SELECT farm_id, AVG(COUNT(crop_type)) AS average_crops_per_farm FROM urban_farms GROUP BY farm_id; |
What is the total quantity of 'Missiles' sold to Japan in both the AirForce_Equipment and Navy_Equipment tables? | CREATE TABLE AirForce_Equipment (country VARCHAR(50),equipment VARCHAR(50),quantity INT,date DATE); CREATE TABLE Navy_Equipment (country VARCHAR(50),equipment VARCHAR(50),quantity INT,date DATE); | SELECT SUM(quantity) FROM (SELECT quantity FROM AirForce_Equipment WHERE country = 'Japan' AND equipment = 'Missiles' UNION SELECT quantity FROM Navy_Equipment WHERE country = 'Japan' AND equipment = 'Missiles') AS total; |
List sustainable building projects and their permit numbers in Los Angeles County from 2019-2020 | CREATE TABLE sustainable_projects (project_number INT,county VARCHAR(20),start_date DATE); CREATE TABLE building_permits (project_number INT,permit_number INT); | SELECT sp.project_number, sp.county, bp.permit_number FROM sustainable_projects sp INNER JOIN building_permits bp ON sp.project_number = bp.project_number WHERE sp.county = 'Los Angeles County' AND sp.start_date BETWEEN '2019-01-01' AND '2020-12-31'; |
Delete all records from the 'endangered_species' table | CREATE TABLE endangered_species (species_id INT,species_name VARCHAR(20),population INT); INSERT INTO endangered_species (species_id,species_name,population) VALUES (1,'tiger',2000),(2,'elephant',1000),(3,'rhino',500); | DELETE FROM endangered_species; |
What is the average number of building permits issued per month in California in 2022? | CREATE TABLE building_permits (permit_id INT,state VARCHAR(2),year INT,month INT,type VARCHAR(20)); INSERT INTO building_permits (permit_id,state,year,month,type) VALUES (1,'CA',2022,1,'Residential'); | SELECT AVG(COUNT(permit_id)) FROM building_permits WHERE state = 'CA' AND year = 2022 GROUP BY month; |
Find the top 3 countries with the highest military expenditure in the last 5 years? | CREATE TABLE military_expenditure (country VARCHAR(50),year INT,amount FLOAT); INSERT INTO military_expenditure (country,year,amount) VALUES ('USA',2017,61000000000),('China',2017,228000000000),('Russia',2017,69000000000),('USA',2018,64900000000),('China',2018,250000000000),('Russia',2018,65000000000); | SELECT country, SUM(amount) as total_expenditure FROM military_expenditure WHERE year BETWEEN 2017 AND 2021 GROUP BY country ORDER BY total_expenditure DESC LIMIT 3; |
How many resources does each mine deplete on average per day? | CREATE TABLE mine (mine_id INT,mine_name TEXT,location TEXT,daily_depletion_percentage DECIMAL(4,2)); INSERT INTO mine VALUES (1,'ABC Mine','Wyoming,USA',0.25),(2,'DEF Mine','West Virginia,USA',0.33),(3,'GHI Mine','Kentucky,USA',0.20); | SELECT mine_name, daily_depletion_percentage*100 as daily_depletion_percentage_avg, (365*24) as days_in_year_hours FROM mine; |
What is the total humanitarian assistance provided by organizations in the Asia-Pacific region? | CREATE TABLE humanitarian_assistance (organization VARCHAR(255),amount NUMERIC,region VARCHAR(255)); INSERT INTO humanitarian_assistance (organization,amount,region) VALUES ('UNICEF',500000,'Asia-Pacific'),('WFP',600000,'Asia-Pacific'),('Red Cross',400000,'Asia-Pacific'); | SELECT region, SUM(amount) FROM humanitarian_assistance WHERE region = 'Asia-Pacific' GROUP BY region; |
What is the total value of investments in the 'Technology' sector as of the last day of 2021? | CREATE TABLE investments (investment_id INT,sector VARCHAR(20),value DECIMAL(10,2),investment_date DATE); INSERT INTO investments (investment_id,sector,value,investment_date) VALUES (1,'Technology',5000.00,'2021-12-31'),(2,'Healthcare',3000.00,'2022-01-03'),(3,'Finance',7000.00,'2021-12-28'); | SELECT SUM(value) FROM investments WHERE sector = 'Technology' AND investment_date = '2021-12-31'; |
What is the total population in Southeast Asia? | CREATE TABLE Country (Code CHAR(3),Name TEXT,Continent TEXT,Region TEXT,Population INT,LifeExpectancy FLOAT); INSERT INTO Country (Code,Name,Continent,Region,Population,LifeExpectancy) VALUES ('ATA','Antarctica','Antarctica','Antarctica',1000,70.0); INSERT INTO Country (Code,Name,Continent,Region,Population,LifeExpectancy) VALUES ('AFG','Afghanistan','Asia','Southern Asia',37172386,62.0); | SELECT SUM(Population) FROM Country WHERE Region = 'Southeast Asia'; |
What are the unique types of agricultural innovation projects in the 'rural_infrastructure' table? | CREATE TABLE rural_infrastructure (id INT,name VARCHAR(50),type VARCHAR(50),budget FLOAT); INSERT INTO rural_infrastructure (id,name,type,budget) VALUES (1,'Solar Irrigation','Agricultural Innovation',150000.00),(2,'Wind Turbines','Rural Infrastructure',200000.00),(3,'Drip Irrigation','Agricultural Innovation',110000.00); | SELECT DISTINCT type FROM rural_infrastructure WHERE type = 'Agricultural Innovation'; |
What are the average fairness scores for AI algorithms in Africa? | CREATE TABLE ai_algorithms_africa (id INT,algo_name VARCHAR(255),location VARCHAR(255),score DECIMAL(5,4)); | SELECT location, AVG(score) as avg_score FROM ai_algorithms_africa WHERE location = 'Africa' GROUP BY location; |
What is the average donation amount for users with the last name 'Smith'? | CREATE TABLE Donations (id INT,user VARCHAR(255),amount DECIMAL(10,2)); INSERT INTO Donations (id,user,amount) VALUES (1,'John Smith',50.00),(2,'Jane Smith',75.00); | SELECT AVG(amount) FROM Donations WHERE user LIKE '%Smith'; |
What are the names and locations of traditional arts schools in Southeast Asia? | CREATE TABLE traditional_arts_schools (id INT,name TEXT,location TEXT); INSERT INTO traditional_arts_schools (id,name,location) VALUES (1,'Southeast Asian Music Conservatory','Indonesia'),(2,'Philippine Traditional Arts Academy','Philippines'); | SELECT name, location FROM traditional_arts_schools WHERE location LIKE '%%Southeast Asia%%'; |
How many users in the "user_profiles" table are from countries in the "countries" table? | CREATE TABLE user_profiles (id INT,country VARCHAR(255)); INSERT INTO user_profiles (id,country) VALUES (1,'USA'),(2,'Canada'),(3,'Mexico'); CREATE TABLE countries (country VARCHAR(255)); INSERT INTO countries (country) VALUES ('USA'),('Canada'),('Brazil'),('Argentina'); | SELECT COUNT(DISTINCT up.id) FROM user_profiles up WHERE up.country IN (SELECT c.country FROM countries c); |
Find the number of stations with no trips in the last 24 hours | CREATE TABLE station_trips (station_id INTEGER,trip_id INTEGER,start_time TEXT); | SELECT COUNT(s.station_id) as no_trips_stations FROM stations s LEFT JOIN station_trips st ON s.station_id = st.station_id WHERE st.start_time < (CURRENT_TIMESTAMP - INTERVAL '24 hours'); |
What is the total quantity of sustainable materials used by each brand? | CREATE TABLE Brands (BrandID INT,BrandName VARCHAR(50)); INSERT INTO Brands (BrandID,BrandName) VALUES (1,'H&M'),(2,'Zara'),(3,'Patagonia'); CREATE TABLE Materials (MaterialID INT,MaterialType VARCHAR(50),Sustainable BIT,BrandID INT); INSERT INTO Materials (MaterialID,MaterialType,Sustainable,BrandID) VALUES (1,'Organic Cotton',1,1),(2,'Recycled Polyester',1,1),(3,'Conventional Cotton',0,2),(4,'Down',0,2),(5,'Recycled Polyester',1,3) | SELECT b.BrandName, SUM(m.Sustainable) as TotalSustainableMaterials FROM Brands b JOIN Materials m ON b.BrandID = m.BrandID WHERE m.Sustainable = 1 GROUP BY b.BrandName |
How many solar power plants are there in Spain and Italy? | CREATE TABLE solar_power_plants (id INT,country VARCHAR(255),name VARCHAR(255)); INSERT INTO solar_power_plants (id,country,name) VALUES (1,'Spain','Solar Plant A'),(2,'Italy','Solar Plant B'),(3,'France','Solar Plant C'); | SELECT COUNT(*) FROM solar_power_plants WHERE country IN ('Spain', 'Italy'); |
What are the names and flag countries of vessels that loaded containers in the Port of New York in the last week? | CREATE TABLE ports (id INT,name TEXT); INSERT INTO ports (id,name) VALUES (1,'Port of New York'); CREATE TABLE vessel_arrivals (id INT,port_id INT,vessel_id INT,arrival_date DATE); INSERT INTO vessel_arrivals (id,port_id,vessel_id,arrival_date) VALUES (1,1,1,'2022-01-01'),(2,1,2,'2022-01-05'); CREATE TABLE vessels (id INT,name TEXT,flag_country TEXT); INSERT INTO vessels (id,name,flag_country) VALUES (1,'Vessel A','USA'),(2,'Vessel B','Canada'); CREATE TABLE container_events (id INT,port_id INT,vessel_id INT,event_date DATE,event_type TEXT,quantity INT); INSERT INTO container_events (id,port_id,vessel_id,event_date,event_type,quantity) VALUES (1,1,1,'2022-01-01','load',500),(2,1,1,'2022-01-03','unload',300); | SELECT v.name, v.flag_country FROM vessels v JOIN vessel_arrivals va ON v.id = va.vessel_id JOIN container_events ce ON v.id = ce.vessel_id WHERE va.port_id = (SELECT id FROM ports WHERE name = 'Port of New York') AND ce.event_date BETWEEN DATEADD(day, -7, CURRENT_DATE) AND CURRENT_DATE AND ce.event_type = 'load'; |
What is the maximum duration of defense project delays in the Middle East in 2022? | CREATE TABLE defense_projects (id INT PRIMARY KEY,region VARCHAR(50),start_date DATE,end_date DATE,delay_duration INT); INSERT INTO defense_projects (id,region,start_date,end_date,delay_duration) VALUES (1,'Middle East','2022-01-01','2022-06-30',30),(2,'Middle East','2022-04-01','2022-12-31',180),(3,'Middle East','2022-07-01','2023-01-31',120); | SELECT MAX(delay_duration) FROM defense_projects WHERE region = 'Middle East' AND year = 2022; |
List regions with restaurants that have failed an inspection. | CREATE TABLE Restaurants (restaurant_id INT,name VARCHAR(255),region VARCHAR(255)); INSERT INTO Restaurants (restaurant_id,name,region) VALUES (1,'Pizzeria 123','North'),(2,'Sushi Bar','South'),(3,'Mexican Grill','East'),(4,'Sushi Pizza','North'); CREATE TABLE Inspections (inspection_id INT,restaurant_id INT,region VARCHAR(255),passed BOOLEAN); INSERT INTO Inspections (inspection_id,restaurant_id,region,passed) VALUES (1,1,'North',FALSE),(2,2,'South',TRUE),(3,3,'East',TRUE),(4,1,'North',FALSE),(5,2,'South',TRUE); | SELECT r.region FROM Restaurants r JOIN Inspections i ON r.restaurant_id = i.restaurant_id WHERE i.passed = FALSE GROUP BY r.region HAVING COUNT(DISTINCT r.restaurant_id) > 1; |
What is the minimum energy efficiency rating for hydroelectric projects in Europe? | CREATE TABLE hydroelectric_projects (id INT,name VARCHAR(255),location VARCHAR(255),rating FLOAT); | SELECT MIN(rating) FROM hydroelectric_projects WHERE location LIKE '%Europe%'; |
Change the price_per_kg to 75.00 for the year 2022 in the market_trends table | CREATE TABLE market_trends (id INT PRIMARY KEY,year INT,price_per_kg DECIMAL(10,2),total_kg INT); INSERT INTO market_trends (id,year,price_per_kg,total_kg) VALUES (1,2019,50.65,23000),(2,2019,45.32,25000),(3,2021,60.23,18000),(4,2021,65.11,19000),(5,2022,70.00,22000); | UPDATE market_trends SET price_per_kg = 75.00 WHERE year = 2022; |
What is the latest launch date for space missions? | CREATE TABLE missions(name TEXT,agency TEXT,launch_date TEXT); INSERT INTO missions(name,agency,launch_date) VALUES('Apollo 11','NASA','1969-07-16'),('Apollo 13','NASA','1970-04-11'); | SELECT MAX(launch_date) FROM missions; |
Delete all products with sodium content greater than 30% | CREATE TABLE Products (id INT,name TEXT,sodium_percentage DECIMAL); INSERT INTO Products (id,name,sodium_percentage) VALUES (1,'Product1',0.25),(2,'Product2',0.35),(3,'Product3',0.15); | DELETE FROM Products WHERE sodium_percentage > 0.3; |
List the number of dams constructed in each 'South American' country per year, in reverse chronological order. | CREATE TABLE Dams (id INT,country VARCHAR(20),continent VARCHAR(20),year INT,count INT); INSERT INTO Dams (id,country,continent,year,count) VALUES (1,'Brazil','South America',2005,10); INSERT INTO Dams (id,country,continent,year,count) VALUES (2,'Argentina','South America',2008,12); INSERT INTO Dams (id,country,continent,year,count) VALUES (3,'Brazil','South America',2010,15); | SELECT country, year, COUNT(*) as dam_count FROM Dams WHERE continent = 'South America' GROUP BY country, year ORDER BY country, year DESC; |
Calculate the total number of animals in each habitat type | CREATE TABLE habitats (id INT,type VARCHAR(50)); INSERT INTO habitats (id,type) VALUES (1,'Forest'),(2,'Savannah'),(3,'Wetlands'); CREATE TABLE animals (id INT,species VARCHAR(50),habitat_id INT); INSERT INTO animals (id,species,habitat_id) VALUES (1,'Lion',2),(2,'Elephant',1),(3,'Hippo',3),(4,'Tiger',2),(5,'Crane',3); | SELECT h.type, COUNT(a.id) as animal_count FROM animals a INNER JOIN habitats h ON a.habitat_id = h.id GROUP BY h.type; |
What is the average number of virtual tours booked per month for heritage sites in France? | CREATE TABLE heritage_sites (id INT,country VARCHAR(20)); INSERT INTO heritage_sites (id,country) VALUES (1,'France'),(2,'Italy'); CREATE TABLE virtual_tours (id INT,site_id INT,bookings INT,month VARCHAR(10)); | SELECT AVG(virtual_tours.bookings) FROM virtual_tours JOIN heritage_sites ON virtual_tours.site_id = heritage_sites.id WHERE heritage_sites.country = 'France' GROUP BY virtual_tours.month; |
How many cultural competency trainings have been conducted in each region? | CREATE TABLE cultural_competency_trainings(region VARCHAR(50),trainings INT); INSERT INTO cultural_competency_trainings(region,trainings) VALUES ('Northeast',200),('Southeast',150),('Midwest',250),('West',300); | SELECT region, trainings FROM cultural_competency_trainings; |
What is the average heart rate of users aged 25-30 who have a premium membership? | CREATE TABLE users (id INT,age INT,membership VARCHAR(20)); INSERT INTO users (id,age,membership) VALUES (1,27,'premium'),(2,31,'basic'); CREATE TABLE workouts (id INT,user_id INT,heart_rate INT); INSERT INTO workouts (id,user_id,heart_rate) VALUES (1,1,120),(2,1,125),(3,2,90),(4,2,95); | SELECT AVG(heart_rate) FROM users JOIN workouts ON users.id = workouts.user_id WHERE users.age BETWEEN 25 AND 30 AND users.membership = 'premium'; |
Display explainable AI models with a complexity score lower than 5 and their corresponding accuracy scores. | CREATE SCHEMA XAI;CREATE TABLE Models (model_id INT,complexity_score INT,accuracy_score FLOAT); INSERT INTO XAI.Models (model_id,complexity_score,accuracy_score) VALUES (1,6,0.95),(2,4,0.9),(3,7,0.8); | SELECT model_id, accuracy_score FROM XAI.Models WHERE complexity_score < 5; |
How many peacekeeping operations were conducted in total by each country in 2017? | CREATE TABLE peacekeeping_operations (operation_id INT,country_id INT,quarter INT,year INT,FOREIGN KEY (country_id) REFERENCES country(id)); | SELECT c.name, SUM(p.quarter) as total_quarters FROM country c INNER JOIN peacekeeping_operations p ON c.id = p.country_id WHERE p.year = 2017 GROUP BY c.name; |
What is the total number of aircraft manufactured by Boeing? | CREATE TABLE aircraft_manufacturers (manufacturer_id INT,manufacturer_name VARCHAR(100),num_aircraft INT); | SELECT SUM(num_aircraft) FROM aircraft_manufacturers WHERE manufacturer_name = 'Boeing'; |
What is the average temperature and humidity for each smart city by month? | CREATE TABLE sensors (id INT,city VARCHAR(255),type VARCHAR(255),value FLOAT,timestamp TIMESTAMP); INSERT INTO sensors (id,city,type,value,timestamp) VALUES (1,'EcoCity','Temperature',25.3,'2022-03-01 12:00:00'),(2,'EcoCity','Humidity',60.5,'2022-03-01 12:00:00'); | SELECT city, type, AVG(value) as avg_value, DATE_FORMAT(timestamp, '%Y-%m') as month FROM sensors GROUP BY city, type, month; |
Insert a new record into the 'intelligence_officers' table with the name 'Luke', rank 'Sergeant' | CREATE TABLE intelligence_officers (id INT,name VARCHAR(20),rank VARCHAR(10)); | INSERT INTO intelligence_officers (name, rank) VALUES ('Luke', 'Sergeant'); |
What is the total number of tickets sold for each sport, grouped by quarter? | CREATE TABLE sales (sale_id INT,team_id INT,sale_quarter INT,sale_year INT,quantity INT); CREATE TABLE teams (team_id INT,team_name VARCHAR(255),sport_id INT); CREATE TABLE sports (sport_id INT,sport_name VARCHAR(255)); INSERT INTO sales VALUES (1,101,1,2020,500),(2,102,2,2020,750),(3,101,3,2020,800),(4,103,4,2020,600); INSERT INTO teams VALUES (101,'TeamA',1),(102,'TeamB',2),(103,'TeamC',1); INSERT INTO sports VALUES (1,'Basketball'),(2,'Football'),(3,'Soccer'); | SELECT s.sport_name, sale_quarter, SUM(quantity) as total_tickets_sold FROM sales s JOIN teams t ON s.team_id = t.team_id JOIN sports sp ON t.sport_id = sp.sport_id GROUP BY s.sport_name, sale_quarter; |
What is the total number of employees in each mining company, broken down by gender? | CREATE TABLE company_gender_demographics (company_id INT,company_name TEXT,gender TEXT,num_employees INT); | SELECT company_name, gender, SUM(num_employees) AS total_employees FROM company_gender_demographics GROUP BY company_name, gender; |
What is the total number of military personnel in each rank? | CREATE TABLE military_ranks (id INT,name TEXT,rank TEXT,number INT);INSERT INTO military_ranks (id,name,rank,number) VALUES (1,'John Doe','Captain',10);INSERT INTO military_ranks (id,name,rank,number) VALUES (2,'Jane Smith','Lieutenant',20); | SELECT rank, SUM(number) FROM military_ranks GROUP BY rank; |
Identify the top 3 countries with the highest average player spending on mobile games in the Asian market | CREATE TABLE country_codes (country_code CHAR(2),country VARCHAR(50),PRIMARY KEY (country_code)); INSERT INTO country_codes VALUES ('US','United States'),('CN','China'),('JP','Japan'),('IN','India'),('KR','South Korea'); CREATE TABLE player_spending (player_id INT,country_code CHAR(2),amount DECIMAL(10,2),PRIMARY KEY (player_id,country_code)); INSERT INTO player_spending VALUES (1,'CN',500.00),(2,'CN',600.00),(3,'JP',400.00),(4,'JP',700.00),(5,'KR',800.00),(6,'KR',900.00); | SELECT c.country, AVG(ps.amount) as avg_spending FROM country_codes c INNER JOIN player_spending ps ON c.country_code = ps.country_code WHERE c.country IN ('China', 'Japan', 'South Korea') GROUP BY c.country ORDER BY avg_spending DESC LIMIT 3; |
What is the average yield of rice in Japan, in kg per hectare? | CREATE TABLE crops (id INT PRIMARY KEY,name VARCHAR(255),yield_kg_per_hectare FLOAT,country VARCHAR(255)); INSERT INTO crops (id,name,yield_kg_per_hectare,country) VALUES (1,'Rice',750,'Japan'),(2,'Wheat',300,'Japan'),(3,'Barley',250,'Japan'); | SELECT AVG(yield_kg_per_hectare) FROM crops WHERE name = 'Rice' AND country = 'Japan'; |
What is the maximum number of transactions performed by a single decentralized application in a day? | CREATE TABLE transactions (id INT,app_id INT,timestamp TIMESTAMP); INSERT INTO transactions (id,app_id,timestamp) VALUES (1,1,'2022-01-01 10:00:00'),(2,1,'2022-01-01 12:00:00'),(3,2,'2022-01-01 14:00:00'); | SELECT app_id, COUNT(*) as num_transactions FROM transactions GROUP BY app_id ORDER BY num_transactions DESC LIMIT 1; |
List all clinical trials conducted for oncology drugs in Mexico, along with their approval status and completion date. | CREATE TABLE clinical_trials (id INT,drug_name VARCHAR(255),trial_location VARCHAR(255),trial_status VARCHAR(255),completion_date DATE); INSERT INTO clinical_trials (id,drug_name,trial_location,trial_status,completion_date) VALUES (1,'DrugB','Mexico','Approved','2018-12-31'); INSERT INTO clinical_trials (id,drug_name,trial_location,trial_status,completion_date) VALUES (2,'DrugC','Mexico','Pending','2021-03-01'); | SELECT * FROM clinical_trials WHERE trial_location = 'Mexico' AND drug_name LIKE '%oncology%' AND (trial_status = 'Approved' OR trial_status = 'Pending'); |
What is the total fuel consumption of each ship type in the fleet? | CREATE TABLE fleet (id INT,name VARCHAR(50),type VARCHAR(50),fuel_capacity INT); CREATE TABLE fuel_consumption (id INT,ship_id INT,fuel_consumption INT,consumption_date DATE); INSERT INTO fleet VALUES (1,'Ship 1','Cargo',10000); INSERT INTO fleet VALUES (2,'Ship 2','Passenger',12000); INSERT INTO fuel_consumption VALUES (1,1,500,'2022-01-01'); INSERT INTO fuel_consumption VALUES (2,2,600,'2022-01-15'); INSERT INTO fuel_consumption VALUES (3,1,550,'2022-02-01'); | SELECT fleet.type, SUM(fuel_consumption.fuel_consumption) FROM fleet INNER JOIN fuel_consumption ON fleet.id = fuel_consumption.ship_id GROUP BY fleet.type; |
Identify the top 2 countries with the highest number of military innovation patents, excluding those with a rank higher than 5 in defense diplomacy. | CREATE TABLE military_innovation (id INT,patent VARCHAR(50),country VARCHAR(50)); CREATE TABLE defense_diplomacy (id INT,country VARCHAR(50),rank INT); INSERT INTO military_innovation (id,patent,country) VALUES (1,'Stealth technology','United States'),(2,'Artificial Intelligence','China'),(3,'Cybersecurity','Russia'),(4,'Drones','France'),(5,'Robotics','United Kingdom'),(6,'Missile defense','Israel'),(7,'Biometrics','Singapore'); INSERT INTO defense_diplomacy (id,country,rank) VALUES (1,'United States',1),(2,'China',2),(3,'Russia',3),(4,'France',4),(5,'United Kingdom',5),(6,'Israel',6),(7,'Singapore',7); | SELECT military_innovation.country, COUNT(military_innovation.patent) as patent_count FROM military_innovation LEFT JOIN defense_diplomacy ON military_innovation.country = defense_diplomacy.country WHERE defense_diplomacy.rank IS NULL OR defense_diplomacy.rank <= 5 GROUP BY military_innovation.country ORDER BY patent_count DESC LIMIT 2; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.