instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
What is the total transaction amount for each customer in the Southeast region in January 2022? | CREATE TABLE transactions (transaction_id INT,customer_id INT,transaction_date DATE,transaction_amount DECIMAL(10,2)); INSERT INTO transactions (transaction_id,customer_id,transaction_date,transaction_amount) VALUES (1,2,'2022-01-05',350.00),(2,1,'2022-01-10',500.00),(3,3,'2022-02-15',700.00),(4,4,'2022-01-15',600.00),(5,3,'2022-01-20',800.00); CREATE TABLE customers (customer_id INT,name VARCHAR(100),region VARCHAR(50)); INSERT INTO customers (customer_id,name,region) VALUES (1,'John Doe','Southeast'),(2,'Jane Smith','Northeast'),(3,'Alice Johnson','Midwest'),(4,'Bob Brown','West'); | SELECT customers.name, SUM(transactions.transaction_amount) FROM transactions INNER JOIN customers ON transactions.customer_id = customers.customer_id WHERE customers.region = 'Southeast' AND transactions.transaction_date BETWEEN '2022-01-01' AND '2022-01-31' GROUP BY customers.name; |
What is the total budget for peacekeeping operations in the Americas in 2020? | CREATE TABLE peacekeeping_operations (id INT PRIMARY KEY,operation_name VARCHAR(100),budget DECIMAL(10,2),start_date DATE,region VARCHAR(50)); INSERT INTO peacekeeping_operations (id,operation_name,budget,start_date,region) VALUES (1,'Operation 1',80000,'2019-01-01','Americas'),(2,'Operation 2',120000,'2018-05-15','Asia-Pacific'),(3,'Operation 3',90000,'2020-12-31','Americas'); | SELECT SUM(budget) FROM peacekeeping_operations WHERE start_date LIKE '2020-%' AND region = 'Americas'; |
How many exhibitions were held in the museum for the last 6 months? | CREATE TABLE Exhibitions_History (id INT,exhibition_date DATE); INSERT INTO Exhibitions_History (id,exhibition_date) VALUES (1,'2022-02-01'),(2,'2022-03-15'),(3,'2022-04-01'),(4,'2022-05-10'),(5,'2022-06-15'); | SELECT COUNT(*) FROM Exhibitions_History WHERE exhibition_date >= DATEADD(month, -6, CURRENT_DATE); |
What was the average revenue per user in the Middle East in Q3 2022? | CREATE SCHEMA socialmedia;CREATE TABLE users (id INT,country VARCHAR(255),revenue DECIMAL(10,2));INSERT INTO users (id,country,revenue) VALUES (1,'Middle East',100.00),(2,'Middle East',150.00); | SELECT AVG(revenue) FROM socialmedia.users WHERE country = 'Middle East' AND EXTRACT(MONTH FROM timestamp) BETWEEN 7 AND 9; |
Display all flight safety records with a severity level of 'High'. | CREATE TABLE FlightSafetyRecords (id INT,incident_date DATE,severity VARCHAR(50),description VARCHAR(255)); INSERT INTO FlightSafetyRecords (id,incident_date,severity,description) VALUES (1,'2021-02-10','High','Engine failure during takeoff'); INSERT INTO FlightSafetyRecords (id,incident_date,severity,description) VALUES (2,'2022-03-15','Medium','Landing gear malfunction'); | SELECT * FROM FlightSafetyRecords WHERE severity = 'High'; |
What is the total revenue for each station in the 'subway' system? | CREATE TABLE station (station_id INT,name TEXT,line TEXT);CREATE TABLE trip (trip_id INT,start_station_id INT,end_station_id INT,revenue FLOAT); | SELECT s.name, SUM(t.revenue) FROM station s INNER JOIN trip t ON s.station_id = t.start_station_id GROUP BY s.name; |
What are the safety measures for hydrochloric acid? | CREATE TABLE chemical_safety_protocols (protocol_id INT PRIMARY KEY,chemical_name VARCHAR(255),safety_measure TEXT); | SELECT safety_measure FROM chemical_safety_protocols WHERE chemical_name = 'hydrochloric acid'; |
What are the top 5 most popular game modes in VR games played by female players over the age of 30? | CREATE TABLE users (user_id INT,age INT,gender VARCHAR(10)); INSERT INTO users (user_id,age,gender) VALUES (1,35,'Female'),(2,25,'Male'),(3,45,'Female'); CREATE TABLE vr_games (game_id INT,game_mode VARCHAR(20)); INSERT INTO vr_games (game_id,game_mode) VALUES (1,'Adventure'),(2,'Shooter'),(3,'Strategy'),(4,'Puzzle'); CREATE TABLE user_games (user_id INT,game_id INT,playtime INT); INSERT INTO user_games (user_id,game_id,playtime) VALUES (1,1,50),(1,2,20),(1,3,0),(2,2,100),(2,3,80),(3,1,60),(3,4,100); | SELECT game_mode, SUM(playtime) AS total_playtime FROM user_games JOIN users ON user_games.user_id = users.user_id JOIN vr_games ON user_games.game_id = vr_games.game_id WHERE users.age > 30 AND users.gender = 'Female' GROUP BY game_mode ORDER BY total_playtime DESC LIMIT 5; |
Identify the unique genres in the books table, excluding the children genre. | CREATE TABLE books (id INT,title TEXT,genre TEXT); | SELECT DISTINCT genre FROM books WHERE genre != 'children'; |
What is the average daily water consumption in the city of Miami for the month of September 2020? | CREATE TABLE WaterConsumption (ID INT,City VARCHAR(20),Consumption FLOAT,Date DATE); INSERT INTO WaterConsumption (ID,City,Consumption,Date) VALUES (9,'Miami',150,'2020-09-01'),(10,'Miami',145,'2020-09-02'),(11,'Miami',160,'2020-09-03'),(12,'Miami',140,'2020-09-04'); | SELECT AVG(Consumption) FROM WaterConsumption WHERE City = 'Miami' AND Date >= '2020-09-01' AND Date <= '2020-09-30' GROUP BY Date |
What is the average quantity of garments sold by the top 10 stores, per transaction, for each country? | CREATE TABLE Stores (StoreID INT,StoreName VARCHAR(50),Country VARCHAR(50)); INSERT INTO Stores VALUES (1,'StoreA','USA'),(2,'StoreB','USA'),(3,'StoreC','Canada'); CREATE TABLE Transactions (TransactionID INT,StoreID INT,Quantity INT); INSERT INTO Transactions VALUES (1,1,50),(2,1,75),(3,2,30),(4,3,60); | SELECT AVG(Quantity) AS Avg_Quantity, Country FROM (SELECT StoreName, Country, Quantity, ROW_NUMBER() OVER (PARTITION BY Country ORDER BY SUM(Quantity) DESC) AS StoreRank FROM Stores JOIN Transactions ON Stores.StoreID = Transactions.StoreID GROUP BY StoreName, Country) AS Subquery WHERE StoreRank <= 10 GROUP BY Country; |
Compare the number of agricultural innovation projects in Latin America and the Caribbean, showing the project type and the number of projects in each region. | CREATE TABLE agricultural_innovation (region VARCHAR(50),project_type VARCHAR(50),project_start_date DATE); | SELECT 'Latin America' as region, project_type, COUNT(*) as project_count FROM agricultural_innovation WHERE region = 'Latin America' UNION ALL SELECT 'Caribbean' as region, project_type, COUNT(*) as project_count FROM agricultural_innovation WHERE region = 'Caribbean'; |
Delete records in the equipment_maintenance table that have not been updated in the last 6 months | CREATE TABLE equipment_maintenance (id INT,equipment_name VARCHAR(50),last_update TIMESTAMP); | DELETE FROM equipment_maintenance WHERE last_update < NOW() - INTERVAL 6 MONTH; |
Update the 'community_policing' table to reflect the current number of community meetings held this year | CREATE TABLE community_policing (cp_id INT,did INT,meetings_this_year INT); INSERT INTO community_policing (cp_id,did,meetings_this_year) VALUES (1,1,5),(2,2,3),(3,3,7); | UPDATE community_policing SET meetings_this_year = meetings_this_year + 2 WHERE did = 1; |
What is the total number of job applications by month for the last year? | CREATE TABLE JobApplications (ApplicationID INT,Year INT,Month VARCHAR(10)); INSERT INTO JobApplications (ApplicationID,Year,Month) VALUES (1,2021,'January'),(2,2021,'February'),(3,2022,'January'); | SELECT Year, SUM(MonthNum) as TotalApplications FROM (SELECT YEAR(STR_TO_DATE(Month, '%M')) AS Year, MONTH(STR_TO_DATE(Month, '%M')) AS MonthNum FROM JobApplications WHERE STR_TO_DATE(Month, '%M') >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR) GROUP BY Year, MonthNum) AS SubQuery GROUP BY Year; |
List all the legal clinics in 'South Peak' justice district that have provided more than 250 hours of service in a year. | CREATE TABLE LegalClinics (ID INT,ClinicID VARCHAR(20),District VARCHAR(20),Hours INT,Year INT); INSERT INTO LegalClinics (ID,ClinicID,District,Hours,Year) VALUES (1,'LC2017','South Peak',300,2017),(2,'LC2018','North Valley',200,2018),(3,'LC2019','South Peak',250,2019); | SELECT ClinicID FROM LegalClinics WHERE District = 'South Peak' AND Hours > 250; |
How many players have reached level 10 in a given game, broken down by country? | CREATE TABLE GameLevels (PlayerID INT,PlayerName TEXT,Country TEXT,Game TEXT,Level INT); INSERT INTO GameLevels (PlayerID,PlayerName,Country,Game,Level) VALUES (1,'John Doe','USA','Game A',10),(2,'Jane Smith','Canada','Game A',12),(3,'Bob Johnson','USA','Game A',8),(4,'Alice Williams','Canada','Game A',10),(5,'Charlie Brown','Mexico','Game A',9); | SELECT Country, COUNT(*) AS NumPlayers FROM GameLevels WHERE Game = 'Game A' AND Level = 10 GROUP BY Country; |
Which suppliers are associated with ingredient 2? | CREATE TABLE ingredient_sourcing (id INT,product_id INT,ingredient_id INT,supplier_id INT,country VARCHAR(50)); INSERT INTO ingredient_sourcing (id,product_id,ingredient_id,supplier_id,country) VALUES (1,101,1,201,'France'),(2,101,2,202,'Italy'),(3,101,3,203,'Spain'),(4,102,2,204,'Germany'),(5,103,1,201,'France'); | SELECT DISTINCT supplier_id FROM ingredient_sourcing WHERE ingredient_id = 2; |
List all players who have not participated in any esports events and the number of VR games they have not played. | CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),Country VARCHAR(20)); INSERT INTO Players VALUES (1,25,'Male','USA'); INSERT INTO Players VALUES (2,22,'Female','Canada'); CREATE TABLE EsportsEvents (EventID INT,PlayerID INT,EventName VARCHAR(20),PrizeMoney INT); INSERT INTO EsportsEvents VALUES (1,1,'Dreamhack',10000); CREATE TABLE VRGameSessions (SessionID INT,PlayerID INT,VRGameCount INT); INSERT INTO VRGameSessions VALUES (1,1,5); | SELECT Players.*, COALESCE(EsportsEvents.PlayerID, 0) AS EventParticipation, COALESCE(VRGameSessions.PlayerID, 0) AS VRGamePlayed FROM Players LEFT JOIN EsportsEvents ON Players.PlayerID = EsportsEvents.PlayerID LEFT JOIN VRGameSessions ON Players.PlayerID = VRGameSessions.PlayerID WHERE EsportsEvents.PlayerID IS NULL AND VRGameSessions.PlayerID IS NULL; |
What is the obesity rate among children in each state? | CREATE TABLE ObesityData (State VARCHAR(50),AgeGroup VARCHAR(20),Population INT,ObesePopulation INT); INSERT INTO ObesityData (State,AgeGroup,Population,ObesePopulation) VALUES ('California','Children',6000000,850000),('Texas','Children',5500000,1000000); | SELECT State, (SUM(ObesePopulation) / SUM(Population)) * 100 AS ObesityRate FROM ObesityData WHERE AgeGroup = 'Children' GROUP BY State; |
List the top 2 CO2 reducing states from the transportation sector? | CREATE TABLE co2_reduction (state VARCHAR(20),sector VARCHAR(20),co2_reduction FLOAT); INSERT INTO co2_reduction (state,sector,co2_reduction) VALUES ('California','Transportation',34.56),('Texas','Transportation',29.45),('New York','Transportation',25.13); | SELECT state, SUM(co2_reduction) as total_reduction FROM co2_reduction WHERE sector = 'Transportation' GROUP BY state ORDER BY total_reduction DESC LIMIT 2; |
What is the average military spending by countries in the European region? | CREATE TABLE military_spending (country VARCHAR(50),region VARCHAR(50),spending NUMERIC(10,2)); INSERT INTO military_spending (country,region,spending) VALUES ('USA','North America',7319340000),('China','Asia',252000000000),('Germany','Europe',4960600000),('France','Europe',4125000000),('UK','Europe',5043000000); | SELECT AVG(spending) FROM military_spending WHERE region = 'Europe'; |
How many community engagement events were held in North America in 2021? | CREATE TABLE CommunityEngagementEvents (id INT,location VARCHAR(20),year INT,events INT); | SELECT SUM(events) FROM CommunityEngagementEvents WHERE location LIKE 'North America%' AND year = 2021; |
What is the number of cybersecurity incidents reported by region per month in 2021? | CREATE TABLE cybersecurity_incidents (region VARCHAR(255),date DATE,incident_id INT); INSERT INTO cybersecurity_incidents (region,date,incident_id) VALUES ('Northeast','2021-01-01',123),('Midwest','2021-01-02',234),('South','2021-01-03',345),('West','2021-01-04',456),('Northeast','2021-02-01',567),('Midwest','2021-02-02',678),('South','2021-02-03',789),('West','2021-02-04',890); | SELECT region, DATE_TRUNC('month', date) as month, COUNT(incident_id) as num_incidents FROM cybersecurity_incidents WHERE date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY region, month; |
How many patients have received both CBT and medication management in NY? | CREATE TABLE patients (patient_id INT,age INT,gender TEXT,treatment TEXT,state TEXT); INSERT INTO patients (patient_id,age,gender,treatment,state) VALUES (1,35,'Female','CBT','New York'); INSERT INTO patients (patient_id,age,gender,treatment,state) VALUES (2,45,'Male','Medication Management','New York'); INSERT INTO patients (patient_id,age,gender,treatment,state) VALUES (3,28,'Female','CBT','New York'); INSERT INTO patients (patient_id,age,gender,treatment,state) VALUES (4,50,'Male','Medication Management','New York'); INSERT INTO patients (patient_id,age,gender,treatment,state) VALUES (5,42,'Non-binary','CBT','New York'); INSERT INTO patients (patient_id,age,gender,treatment,state) VALUES (6,34,'Male','Medication Management','New York'); | SELECT COUNT(DISTINCT patient_id) FROM patients WHERE state = 'New York' AND treatment IN ('CBT', 'Medication Management') GROUP BY patient_id HAVING COUNT(DISTINCT treatment) = 2; |
Get carbon offset programs in a specific region | CREATE TABLE carbon_offset_programs (id INT,name TEXT,region TEXT); INSERT INTO carbon_offset_programs (id,name,region) VALUES (1,'Tree Planting','North America'),(2,'Wind Power','Europe'),(3,'Solar Power','Asia'); | SELECT * FROM carbon_offset_programs WHERE region = 'North America'; |
Display the total number of hotels and tourist attractions in the "hotel_sustainability" and "tourist_attractions" tables | CREATE TABLE hotel_sustainability (hotel_id integer,name text,location text,sustainable_practices text); CREATE TABLE tourist_attractions (attraction_id integer,name text,type text,location text,cultural_significance text); | SELECT COUNT(*) FROM hotel_sustainability; SELECT COUNT(*) FROM tourist_attractions; |
Find the difference in budget allocation between social services and environment protection from 2022 to 2023. | CREATE TABLE budget_2022 (service TEXT,budget INTEGER); INSERT INTO budget_2022 (service,budget) VALUES ('Social Services',1400000),('Environment Protection',1300000); CREATE TABLE budget_2023 (service TEXT,budget INTEGER); INSERT INTO budget_2023 (service,budget) VALUES ('Social Services',1600000),('Environment Protection',1500000); | SELECT (COALESCE(SUM(budget_2023.budget), 0) - COALESCE(SUM(budget_2022.budget), 0)) FROM budget_2022 FULL OUTER JOIN budget_2023 ON budget_2022.service = budget_2023.service WHERE service IN ('Social Services', 'Environment Protection'); |
Show all teachers with a professional development score above 90 | CREATE TABLE teacher_professional_development (teacher_id INT,professional_development_score INT); | SELECT * FROM teacher_professional_development WHERE professional_development_score > 90; |
List the names of athletes who participated in both football and basketball games. | CREATE TABLE athletes (athlete_id INT,game_id INT); | SELECT athlete_id FROM athletes WHERE game_id IN (SELECT game_id FROM games WHERE game_type = 'Football') INTERSECT SELECT athlete_id FROM athletes WHERE game_id IN (SELECT game_id FROM games WHERE game_type = 'Basketball'); |
Find the total waste produced by each chemical in the Chemical_Waste table | CREATE TABLE Chemical_Waste (chemical_id INT,chemical_name VARCHAR(50),waste_amount DECIMAL(5,2)); | SELECT chemical_name, SUM(waste_amount) as total_waste FROM Chemical_Waste GROUP BY chemical_name; |
Identify the total annual production of Europium and Gadolinium, excluding data from 2016 | CREATE TABLE production (element VARCHAR(10),year INT,month INT,quantity INT); INSERT INTO production (element,year,month,quantity) VALUES ('Europium',2015,1,70),('Europium',2015,2,75),('Europium',2016,1,80),('Europium',2016,2,85),('Gadolinium',2015,1,90),('Gadolinium',2015,2,95),('Gadolinium',2016,1,100),('Gadolinium',2016,2,105); | SELECT SUM(quantity) FROM production WHERE element IN ('Europium', 'Gadolinium') AND year <> 2016 GROUP BY element; |
What is the total billing amount for cases handled by the attorney with the ID 3? | CREATE TABLE Attorneys (AttorneyID INT,Name VARCHAR(50)); INSERT INTO Attorneys (AttorneyID,Name) VALUES (1,'Smith,John'),(2,'Garcia,Maria'),(3,'Li,Wei'); CREATE TABLE Cases (CaseID INT,AttorneyID INT,BillingAmount DECIMAL(10,2)); INSERT INTO Cases (CaseID,AttorneyID,BillingAmount) VALUES (1,1,5000.00),(2,2,3500.00),(3,3,4000.00),(4,3,6000.00); | SELECT SUM(BillingAmount) FROM Cases WHERE AttorneyID = 3; |
How many defense contracts were awarded to companies in the United States in the last 3 years? | CREATE TABLE DefenseContracts (id INT,company VARCHAR(50),country VARCHAR(50),award_date DATE); INSERT INTO DefenseContracts (id,company,country,award_date) VALUES (1,'Lockheed Martin','USA','2019-05-15'),(2,'Raytheon','USA','2020-08-22'),(3,'Boeing','USA','2021-03-09'); | SELECT COUNT(*) FROM DefenseContracts WHERE country = 'USA' AND award_date >= DATE_SUB(CURDATE(), INTERVAL 3 YEAR); |
What is the total number of co-owned properties in the city of Las Vegas with a listing price above the average listing price? | CREATE TABLE properties (id INT,city VARCHAR(20),listing_price FLOAT,co_owned BOOLEAN); INSERT INTO properties (id,city,listing_price,co_owned) VALUES (1,'Las Vegas',150000,true),(2,'Las Vegas',200000,false),(3,'Las Vegas',250000,true); | SELECT COUNT(*) FROM properties WHERE city = 'Las Vegas' AND co_owned = true AND listing_price > (SELECT AVG(listing_price) FROM properties WHERE city = 'Las Vegas'); |
What is the total number of security incidents recorded per country? | CREATE TABLE security_incidents (id INT,country VARCHAR(20),incident_type VARCHAR(20),timestamp TIMESTAMP); INSERT INTO security_incidents (id,country,incident_type,timestamp) VALUES (1,'USA','Malware','2022-01-01 10:00:00'),(2,'Canada','Phishing','2022-01-02 11:00:00'); | SELECT country, COUNT(*) as total_incidents FROM security_incidents GROUP BY country; |
Delete all records from the 'machinery' table where the 'manufacturer' is 'Heavy Mach' | CREATE TABLE machinery (id INT PRIMARY KEY,manufacturer VARCHAR(255),model VARCHAR(255),year INT); | DELETE FROM machinery WHERE manufacturer = 'Heavy Mach'; |
What is the average sustainability rating for each garment category? | CREATE TABLE GarmentCategories (CategoryID INT,CategoryName VARCHAR(50));CREATE TABLE SustainabilityRatings (GarmentID INT,CategoryID INT,SustainabilityRating INT); | SELECT GC.CategoryName, AVG(SR.SustainabilityRating) AS AverageRating FROM GarmentCategories GC JOIN SustainabilityRatings SR ON GC.CategoryID = SR.CategoryID GROUP BY GC.CategoryName; |
What is the average plastic recycling rate by location? | CREATE TABLE recycling_rates (location VARCHAR(50),material VARCHAR(50),rate DECIMAL(5,2)); INSERT INTO recycling_rates (location,material,rate) VALUES ('Nairobi','Plastic',0.65); | SELECT location, AVG(rate) as avg_plastic_recycling_rate FROM recycling_rates WHERE material = 'Plastic' GROUP BY location; |
What is the defense spending trend for the Navy from 2018 to 2023? | CREATE TABLE navy_spending_trend (year INT,spending NUMERIC(10,2)); INSERT INTO navy_spending_trend (year,spending) VALUES (2018,3000000000),(2019,3200000000),(2020,3400000000),(2021,3600000000),(2022,3800000000),(2023,4000000000); | SELECT year, spending FROM navy_spending_trend; |
List all product_ids and quantities for products in the 'electronics' category | CREATE TABLE products (product_id INT,category VARCHAR(20),quantity INT); INSERT INTO products (product_id,category,quantity) VALUES (1,'electronics',100),(2,'electronics',200),(3,'electronics',300); | SELECT product_id, quantity FROM products WHERE category = 'electronics'; |
Display the AI safety research papers with the lowest number of citations in the 'AI_Research' schema. | CREATE SCHEMA AI_Research;CREATE TABLE Safety_Papers (paper_id INT,publication_year INT,citations INT); INSERT INTO AI_Research.Safety_Papers (paper_id,publication_year,citations) VALUES (1,2016,20),(2,2018,30),(3,2017,15); | SELECT paper_id, citations FROM AI_Research.Safety_Papers ORDER BY citations LIMIT 1; |
What is the average sustainability score for cosmetic products, partitioned by brand and ordered by average score in descending order? | CREATE TABLE products (product_id INT,brand_id INT,sustainability_score FLOAT); INSERT INTO products (product_id,brand_id,sustainability_score) VALUES (1,1,80),(2,1,85),(3,2,70),(4,2,75); CREATE TABLE brands (brand_id INT,name VARCHAR(255)); INSERT INTO brands (brand_id,name) VALUES (1,'BrandA'),(2,'BrandB'); | SELECT brands.name, AVG(products.sustainability_score) as avg_score FROM products JOIN brands ON products.brand_id = brands.brand_id GROUP BY brands.name ORDER BY avg_score DESC; |
What is the total calorie content of dishes that contain ingredients from a supplier in the West? | CREATE TABLE Suppliers (sid INT,name TEXT,location TEXT);CREATE TABLE Dishes (did INT,name TEXT,calorie_content INT);CREATE TABLE Ingredients (iid INT,dish_id INT,supplier_id INT);INSERT INTO Suppliers VALUES (1,'SupplierA','West'),(2,'SupplierB','East'),(3,'SupplierC','West');INSERT INTO Dishes VALUES (1,'DishA',500),(2,'DishB',1500),(3,'DishC',800);INSERT INTO Ingredients VALUES (1,1,1),(2,2,1),(3,2,2),(4,3,3); | SELECT SUM(Dishes.calorie_content) FROM Dishes INNER JOIN Ingredients ON Dishes.did = Ingredients.dish_id INNER JOIN Suppliers ON Ingredients.supplier_id = Suppliers.sid WHERE Suppliers.location = 'West'; |
Who are the top 3 artists by total revenue? | CREATE TABLE Artists (artist_id INT,artist_name VARCHAR(255)); CREATE TABLE ArtSales (sale_id INT,artist_id INT,sale_price DECIMAL(10,2)); INSERT INTO Artists (artist_id,artist_name) VALUES (1,'Alice'),(2,'Bob'),(3,'Charlie'); INSERT INTO ArtSales (sale_id,artist_id,sale_price) VALUES (1,1,5000.00),(2,2,7000.00),(3,1,6000.00),(4,3,8000.00); | SELECT artist_name, SUM(sale_price) as Total_Revenue FROM Artists JOIN ArtSales ON Artists.artist_id = ArtSales.artist_id GROUP BY 1 ORDER BY Total_Revenue DESC LIMIT 3; |
Calculate the total revenue for all movies and TV shows released in 2020. | CREATE TABLE movie_sales (id INT,movie_name VARCHAR(50),revenue FLOAT,release_date DATE); CREATE TABLE show_sales (id INT,show_name VARCHAR(50),revenue FLOAT,air_date DATE); | SELECT SUM(revenue) FROM movie_sales WHERE YEAR(release_date) = 2020 UNION SELECT SUM(revenue) FROM show_sales WHERE YEAR(air_date) = 2020; |
Which countries have the highest percentage of circular supply chains in the apparel industry? | CREATE TABLE Companies (company_id INT,country TEXT); INSERT INTO Companies (company_id,country) VALUES (1,'USA'),(2,'China'),(3,'Bangladesh'),(4,'Italy'),(5,'India'); CREATE TABLE SupplyChains (company_id INT,type TEXT); INSERT INTO SupplyChains (company_id,type) VALUES (1,'circular'),(1,'linear'),(2,'linear'),(3,'circular'),(4,'circular'),(5,'linear'); CREATE TABLE Apparel (company_id INT); INSERT INTO Apparel (company_id) VALUES (1),(2),(3),(4),(5); | SELECT C.country, (COUNT(S.company_id) * 100.0 / (SELECT COUNT(*) FROM Companies C2 JOIN Apparel A2 ON C2.country = A2.country)) AS percentage FROM Companies C JOIN SupplyChains S ON C.company_id = S.company_id JOIN Apparel A ON C.company_id = A.company_id WHERE S.type = 'circular' GROUP BY C.country ORDER BY percentage DESC; |
Find the number of social factors rated 9 or 10 and the corresponding projects in the healthcare sector. | CREATE TABLE esg_factors (id INT,investment_id INT,environmental_factor DECIMAL(5,2),social_factor DECIMAL(5,2),governance_factor DECIMAL(5,2)); INSERT INTO esg_factors (id,investment_id,environmental_factor,social_factor,governance_factor) VALUES (1,1,0.90,9.0,0.95); | SELECT i.project, e.social_factor FROM impact_investments i JOIN esg_factors e ON i.id = e.investment_id WHERE i.primary_sector = 'Healthcare' AND e.social_factor IN (9, 10); |
What is the total cost of ingredients for the 'Veggie Sushi Roll' for the month of October 2022? | CREATE TABLE Ingredients (ingredient_id INT,ingredient_name TEXT,dish_id INT,cost FLOAT); INSERT INTO Ingredients (ingredient_id,ingredient_name,dish_id,cost) VALUES (1,'Sushi Rice',8,1.5); | SELECT SUM(cost) FROM Ingredients WHERE dish_id IN (SELECT dish_id FROM Dishes WHERE dish_name = 'Veggie Sushi Roll') AND ingredient_name NOT IN ('Seaweed', 'Cucumber', 'Avocado'); |
Find the mine that had the lowest daily production of Thulium in 2012. | CREATE TABLE mines (id INT,name TEXT,daily_production FLOAT,year INT,primary_key INT); | SELECT name FROM mines WHERE element = 'Thulium' AND year = 2012 AND daily_production = (SELECT MIN(daily_production) FROM mines WHERE element = 'Thulium' AND year = 2012); |
How many movies have been produced in each country? | CREATE TABLE movies (id INT,title VARCHAR(100),production_country VARCHAR(50)); INSERT INTO movies (id,title,production_country) VALUES (1,'MovieA','France'); INSERT INTO movies (id,title,production_country) VALUES (2,'MovieB','Germany'); | SELECT production_country, COUNT(*) FROM movies GROUP BY production_country; |
Find stores with sales below the overall average for stores in the 'East' and 'West' regions. | CREATE TABLE REGIONAL_STORES (store_id INT,region VARCHAR(20),sales FLOAT); INSERT INTO REGIONAL_STORES VALUES (1,'East',5000),(2,'East',7000),(3,'East',8000),(4,'West',6000),(5,'West',9000),(6,'West',4000); | SELECT store_id FROM REGIONAL_STORES WHERE region IN ('East', 'West') AND sales < (SELECT AVG(sales) FROM REGIONAL_STORES); |
How many cases of COVID-19 have been reported in New York City? | CREATE TABLE covid_cases (id INT,location TEXT,confirmed INT); INSERT INTO covid_cases (id,location,confirmed) VALUES (1,'New York City',500); INSERT INTO covid_cases (id,location,confirmed) VALUES (2,'Los Angeles',300); | SELECT SUM(confirmed) FROM covid_cases WHERE location = 'New York City'; |
Delete records from the cargo_tracking table where voyage_id = 'V006' | cargo_tracking(tracking_id,voyage_id,cargo_type,cargo_weight) | DELETE FROM cargo_tracking WHERE voyage_id = 'V006'; |
How many military equipment maintenance requests were submitted by each agency in the last month? | CREATE TABLE equipment_maintenance (maintenance_id INT,maintenance_date DATE,maintenance_type TEXT,agency_id INT,equipment_model TEXT); INSERT INTO equipment_maintenance (maintenance_id,maintenance_date,maintenance_type,agency_id,equipment_model) VALUES (1,'2022-01-15','Preventive maintenance',101,'M1 Abrams'); INSERT INTO equipment_maintenance (maintenance_id,maintenance_date,maintenance_type,agency_id,equipment_model) VALUES (2,'2022-01-20','Corrective maintenance',102,'UH-60 Black Hawk'); | SELECT agency_id, COUNT(*) as maintenance_requests FROM equipment_maintenance WHERE maintenance_date >= DATEADD(month, -1, GETDATE()) GROUP BY agency_id; |
What are the names and adoption rates of agricultural innovations in rural communities in Bangladesh? | CREATE TABLE names (id INT,innovation TEXT,community TEXT,adoption_rate FLOAT); INSERT INTO names (id,innovation,community,adoption_rate) VALUES (1,'SRI','Rural Community A',0.9),(2,'Hybrid Seeds','Rural Community B',0.7); | SELECT innovation, adoption_rate FROM names WHERE community LIKE 'Rural Community%' AND country = 'Bangladesh'; |
What are the names and locations of hydrothermal vents in the Southern Ocean? | CREATE TABLE Southern_Ocean_Vents (vent_name TEXT,location TEXT); INSERT INTO Southern_Ocean_Vents (vent_name,location) VALUES ('E end vent field','Southwest Indian Ridge'),('Lucky Strike','Mid-Atlantic Ridge'); | SELECT vent_name, location FROM Southern_Ocean_Vents; |
Show the number of electric vehicle charging stations in each state in the US. | CREATE TABLE states (state_name TEXT,num_cities INT);CREATE TABLE charging_stations (station_id INT,station_name TEXT,city_name TEXT,state_name TEXT,num_charging_points INT); | SELECT s.state_name, COUNT(cs.station_id) AS num_charging_stations FROM states s JOIN charging_stations cs ON s.state_name = cs.state_name GROUP BY s.state_name; |
What is the total fine amount collected per month in 2020? | CREATE TABLE payments (payment_id INT,payment_date DATE,fine_amount INT); INSERT INTO payments (payment_id,payment_date,fine_amount) VALUES (1,'2020-02-15',200),(2,'2020-03-10',500),(3,'2020-04-05',800),(4,'2020-05-12',1200); | SELECT EXTRACT(MONTH FROM payment_date) as month, SUM(fine_amount) as total_fine_amount FROM payments WHERE payment_date BETWEEN '2020-01-01' AND '2020-12-31' GROUP BY month; |
What's the maximum number of tokens in circulation for TokenC? | CREATE TABLE token_circulation (id INT PRIMARY KEY,name VARCHAR(255),circulating_supply BIGINT); INSERT INTO token_circulation (id,name,circulating_supply) VALUES (1,'TokenC',50000000),(2,'TokenD',25000000); | SELECT circulating_supply FROM token_circulation WHERE name = 'TokenC'; |
What is the average number of military personnel in the Army and Navy? | CREATE TABLE MilitaryPersonnel (branch TEXT,num_personnel INTEGER); INSERT INTO MilitaryPersonnel (branch,num_personnel) VALUES ('Army',500000),('Navy',350000),('AirForce',300000),('Marines',200000); | SELECT AVG(num_personnel) FROM MilitaryPersonnel WHERE branch IN ('Army', 'Navy'); |
Which members have attended yoga or pilates classes in LA? | CREATE TABLE gym_class_attendance (member_id INT,class_name VARCHAR(255)); | SELECT DISTINCT m.member_id FROM member_profiles m INNER JOIN gym_class_attendance gca ON m.member_id = gca.member_id WHERE m.member_city = 'LA' AND gca.class_name IN ('yoga', 'pilates'); |
Find the top 5 water consuming neighborhoods in Seattle? | CREATE TABLE Neighborhood_Water_Usage (ID INT,Neighborhood VARCHAR(20),Usage FLOAT); | SELECT Neighborhood, Usage FROM (SELECT Neighborhood, Usage, ROW_NUMBER() OVER(ORDER BY Usage DESC) as rn FROM Neighborhood_Water_Usage WHERE City = 'Seattle') t WHERE rn <= 5; |
List all volunteers who have participated in programs in the last month? | CREATE TABLE Volunteer (VolunteerID int,VolunteerName varchar(50),Country varchar(50)); CREATE TABLE VolunteerProgram (ProgramID int,VolunteerID int,ProgramDate date); | SELECT VolunteerName FROM Volunteer JOIN VolunteerProgram ON Volunteer.VolunteerID = VolunteerProgram.VolunteerID WHERE ProgramDate >= DATEADD(month, -1, GETDATE()); |
What is the maximum fare for 'Tram' mode of transport for journeys on the first day of each month? | CREATE TABLE Fares(fare INT,journey_date DATE,mode_of_transport VARCHAR(20)); INSERT INTO Fares(fare,journey_date,mode_of_transport) VALUES (3,'2022-01-01','Tram'),(4,'2022-01-02','Tram'),(5,'2022-02-01','Tram'); | SELECT MAX(fare) FROM Fares WHERE mode_of_transport = 'Tram' AND EXTRACT(DAY FROM journey_date) = 1; |
Update the aircraft_plants table to include the number of employees at each plant. | CREATE TABLE plant_employees (plant_id INT,num_employees INT); INSERT INTO plant_employees (plant_id,num_employees) VALUES (1,30000),(2,25000),(3,15000),(4,8000),(5,12000),(6,5000); | UPDATE aircraft_plants SET num_employees = (SELECT num_employees FROM plant_employees WHERE aircraft_plants.plant_id = plant_employees.plant_id); |
What is the total weight of packages shipped to Canada, and how many were shipped? | CREATE TABLE warehouse (id INT,location VARCHAR(255)); INSERT INTO warehouse (id,location) VALUES (1,'Chicago'),(2,'Houston'); CREATE TABLE packages (id INT,warehouse_id INT,weight FLOAT,country VARCHAR(255)); INSERT INTO packages (id,warehouse_id,weight,country) VALUES (1,1,50.3,'Canada'),(2,1,30.1,'Canada'),(3,2,70.0,'Mexico'),(4,2,40.0,'Canada'); | SELECT country, SUM(weight) as total_weight, COUNT(*) as num_shipments FROM packages GROUP BY country HAVING country = 'Canada'; |
How many patients have received treatment in each quarter of 2022? | CREATE TABLE treatments (treatment_id INT,year INT,quarter INT,condition VARCHAR(30)); INSERT INTO treatments (treatment_id,year,quarter,condition) VALUES (1,2022,1,'Anxiety'),(2,2022,2,'Depression'),(3,2022,3,'Anxiety'),(4,2022,4,'PTSD'); | SELECT year, quarter, COUNT(*) as count FROM treatments GROUP BY year, quarter; |
What is the market share of OTAs offering virtual tours in the APAC region? | CREATE TABLE otas (ota_id INT,ota_name TEXT,country TEXT); CREATE TABLE virtual_tours (tour_id INT,ota_id INT,views INT); INSERT INTO otas VALUES (1,'OTA A','Japan'); INSERT INTO virtual_tours VALUES (1,1),(2,1); | SELECT 100.0 * COUNT(DISTINCT otas.ota_id) / (SELECT COUNT(DISTINCT ota_id) FROM otas) AS market_share FROM virtual_tours INNER JOIN otas ON virtual_tours.ota_id = otas.ota_id WHERE otas.country LIKE 'APAC%'; |
Delete the records of students who have not published any articles | CREATE TABLE students (id INT,name TEXT,publications INT); INSERT INTO students (id,name,publications) VALUES (1,'John',3),(2,'Jane',0),(3,'Doe',2); | DELETE FROM students WHERE publications = 0; |
What is the average rating for the 'Transportation' service? | CREATE TABLE feedback (id INT,service VARCHAR(20),rating INT,comment TEXT); INSERT INTO feedback (id,service,rating,comment) VALUES (1,'Parks and Recreation',5,'Great job!'),(2,'Parks and Recreation',3,'Could improve'),(3,'Waste Management',4,'Good but room for improvement'),(4,'Libraries',5,'Awesome!'),(5,'Libraries',4,'Very helpful'),(6,'Transportation',2,'Needs work'); | SELECT AVG(f.rating) FROM feedback f WHERE f.service = 'Transportation'; |
Find species affected by pollution incidents in the Mediterranean Sea. | CREATE TABLE pollution_impacts (species VARCHAR(255),ocean VARCHAR(255),pollution_incident BOOLEAN); INSERT INTO pollution_impacts (species,ocean,pollution_incident) VALUES ('Species3','Mediterranean Sea',TRUE); | SELECT species FROM pollution_impacts WHERE ocean = 'Mediterranean Sea' AND pollution_incident = TRUE |
Determine the average R&D expenditure per drug, ranked from the highest to the lowest, in the year 2019? | CREATE TABLE r_and_d_expenditure (expenditure_id INT,drug_name VARCHAR(255),expenditure_date DATE,amount DECIMAL(10,2)); INSERT INTO r_and_d_expenditure (expenditure_id,drug_name,expenditure_date,amount) VALUES (1,'DrugA','2019-01-01',10000),(2,'DrugB','2019-01-02',12000),(3,'DrugC','2019-01-03',15000),(4,'DrugA','2019-01-04',11000),(5,'DrugB','2019-01-05',13000),(6,'DrugC','2019-01-06',16000); | SELECT drug_name, AVG(amount) as avg_expenditure FROM r_and_d_expenditure WHERE YEAR(expenditure_date) = 2019 GROUP BY drug_name ORDER BY avg_expenditure DESC; |
What is the total funding allocated for climate communication initiatives in Asia? | CREATE TABLE climate_mitigation (region VARCHAR(255),funding INT); INSERT INTO climate_mitigation VALUES ('Asia',5000000); | SELECT SUM(funding) FROM climate_mitigation WHERE region = 'Asia' AND initiative_type = 'climate communication'; |
Display the total number of workers in each union in the 'union_memberships' table, excluding duplicate worker_id's | CREATE TABLE union_memberships (union_id INT,worker_id INT,union_name VARCHAR(50),join_date DATE); INSERT INTO union_memberships (union_id,worker_id,union_name,join_date) VALUES (1,1,'United Steelworkers','2021-01-10'),(1,2,'United Steelworkers','2022-01-05'),(2,3,'Teamsters','2021-08-10'),(2,4,'Teamsters','2022-02-15'),(3,5,'Service Employees International Union','2021-04-01'),(3,6,'Service Employees International Union','2022-04-12'),(4,7,'United Auto Workers','2021-09-15'),(4,8,'United Auto Workers','2022-09-10'),(1,9,'United Steelworkers','2022-09-20'); | SELECT union_id, COUNT(DISTINCT worker_id) AS total_workers FROM union_memberships GROUP BY union_id; |
Calculate the average price of clothing items that are both ethically sourced and made from organic materials. | CREATE TABLE Clothing_Items (item_id INT,is_ethically_sourced BOOLEAN,is_organic BOOLEAN,price DECIMAL(5,2)); INSERT INTO Clothing_Items (item_id,is_ethically_sourced,is_organic,price) VALUES (100,true,true,50.00),(101,false,true,40.00),(102,true,false,60.00),(103,false,false,30.00),(104,true,true,55.00); | SELECT AVG(price) as avg_price FROM Clothing_Items WHERE is_ethically_sourced = true AND is_organic = true; |
Which cultural heritage sites in Athens have virtual tours available? | CREATE TABLE cultural_sites (site_id INT,city TEXT,virtual_tour BOOLEAN); INSERT INTO cultural_sites (site_id,city,virtual_tour) VALUES (1,'Athens',true),(2,'Athens',false); | SELECT name FROM cultural_sites WHERE city = 'Athens' AND virtual_tour = true; |
How many marine research stations are in the Indian Ocean? | CREATE TABLE research_stations (station_name VARCHAR(50),ocean VARCHAR(20)); INSERT INTO research_stations (station_name,ocean) VALUES ('Indian Ocean Observatory','Indian'),('National Institute of Ocean Technology','Indian'); | SELECT COUNT(*) FROM research_stations WHERE ocean = 'Indian'; |
Calculate the average preservation year for artifacts with more than 2 preservation records. | CREATE TABLE Preservation (PreservationID INT,ArtifactID INT,PreservationMethod VARCHAR(255),PreservationDate DATE); INSERT INTO Preservation (PreservationID,ArtifactID,PreservationMethod,PreservationDate) VALUES (1,2,'Freezing','2020-02-01'); | SELECT ArtifactID, AVG(YEAR(PreservationDate)) as AvgPreservationYear FROM Preservation GROUP BY ArtifactID HAVING COUNT(*) > 2; |
Calculate the percentage of accidents involving each aircraft type. | CREATE TABLE Accidents (AccidentID INT,Date DATE,Location VARCHAR(50),AircraftType VARCHAR(50),Description TEXT,Fatalities INT); INSERT INTO Accidents (AccidentID,Date,Location,AircraftType,Description,Fatalities) VALUES (13,'2019-08-18','Rio de Janeiro','Boeing 737','Flight control issues',0),(14,'2021-02-20','New Delhi','Airbus A320','Engine failure',1),(15,'2022-07-25','Cape Town','Boeing 747','Landing gear malfunction',2),(16,'2023-01-01','Sydney','Airbus A380','Hydraulic failure',0),(17,'2024-03-14','Toronto','Boeing 777','Fuel leak',1); | SELECT AircraftType, 100.0 * COUNT(*) / (SELECT COUNT(*) FROM Accidents) AS AccidentPercentage FROM Accidents GROUP BY AircraftType; |
What is the maximum speed of vessels with 'YANG' prefix that carried dangerous goods in the Pacific Ocean in 2017? | CREATE TABLE Vessels (ID INT,Name TEXT,Speed FLOAT,Dangerous_Goods BOOLEAN,Prefix TEXT,Year INT);CREATE VIEW Pacific_Ocean_Vessels AS SELECT * FROM Vessels WHERE Region = 'Pacific Ocean'; | SELECT MAX(Speed) FROM Pacific_Ocean_Vessels WHERE Prefix = 'YANG' AND Dangerous_Goods = 1 AND Year = 2017; |
What is the average safety rating of organic skincare products sold in Canada in 2022? | CREATE TABLE cosmetics_ingredients (product VARCHAR(255),ingredient VARCHAR(255),safety_rating INTEGER); CREATE TABLE cosmetics (product VARCHAR(255),product_category VARCHAR(255),organic BOOLEAN); CREATE TABLE countries (country VARCHAR(255),continent VARCHAR(255)); CREATE TABLE sale_records (product VARCHAR(255),country VARCHAR(255),sale_date DATE); INSERT INTO countries (country,continent) VALUES ('Canada','North America'); CREATE VIEW organic_skincare AS SELECT * FROM cosmetics WHERE product_category = 'Skincare' AND organic = true; CREATE VIEW sale_records_2022 AS SELECT * FROM sale_records WHERE YEAR(sale_date) = 2022; CREATE VIEW canada_sales AS SELECT * FROM sale_records_2022 WHERE country = 'Canada'; CREATE VIEW organic_canada_sales AS SELECT * FROM canada_sales JOIN organic_skincare ON cosmetics.product = sale_records.product; | SELECT AVG(safety_rating) FROM cosmetics_ingredients JOIN organic_canada_sales ON cosmetics_ingredients.product = organic_canada_sales.product; |
How many claims were filed per policy type in 'Michigan'? | CREATE TABLE Claims (ClaimID INT,PolicyID INT,PolicyType VARCHAR(20),ClaimState VARCHAR(20)); INSERT INTO Claims (ClaimID,PolicyID,PolicyType,ClaimState) VALUES (4,4,'Auto','Michigan'),(5,5,'Home','Michigan'),(6,6,'Life','Michigan'); | SELECT PolicyType, COUNT(*) as ClaimCount FROM Claims WHERE ClaimState = 'Michigan' GROUP BY PolicyType; |
How many animals are there in total across all habitats? | CREATE TABLE Habitat_Summary AS SELECT 'Habitat_G' AS name,52 AS animal_count UNION SELECT 'Habitat_H',57; | SELECT SUM(animal_count) FROM Habitat_Summary; |
List all network investments made in the African region in the past year, including the investment amount and location. | CREATE TABLE network_investments (investment_id INT,investment_amount FLOAT,investment_date DATE,location TEXT); INSERT INTO network_investments (investment_id,investment_amount,investment_date,location) VALUES (1,500000,'2021-02-14','Nairobi'); INSERT INTO network_investments (investment_id,investment_amount,investment_date,location) VALUES (2,750000,'2021-05-27','Cape Town'); | SELECT * FROM network_investments WHERE investment_date >= DATEADD(year, -1, CURRENT_DATE) AND location LIKE 'Africa%'; |
List all donors who have donated in the last 6 months? | CREATE TABLE donors (id INT,name VARCHAR(255)); INSERT INTO donors (id,name) VALUES (1,'John'),(2,'Jane'),(3,'Mike'),(4,'Lucy'); CREATE TABLE donations (id INT,donor_id INT,amount DECIMAL(10,2),donation_date DATE); INSERT INTO donations (id,donor_id,amount,donation_date) VALUES (1,1,500,'2021-01-01'),(2,2,1500,'2021-02-01'),(3,3,750,'2021-03-01'),(4,4,250,'2021-04-01'),(5,1,250,'2021-05-01'),(6,2,500,'2021-06-01'); | SELECT d.name FROM donors d JOIN donations don ON d.id = don.donor_id WHERE don.donation_date >= DATE_SUB(NOW(), INTERVAL 6 MONTH); |
Show the number of unique strains available in each dispensary in states with legal recreational cannabis. | CREATE TABLE Dispensaries (DispensaryID INT,DispensaryName TEXT,State TEXT); INSERT INTO Dispensaries (DispensaryID,DispensaryName,State) VALUES (1,'Green Earth','Colorado'); CREATE TABLE Inventory (InventoryID INT,DispensaryID INT,Strain TEXT); INSERT INTO Inventory (InventoryID,DispensaryID,Strain) VALUES (1,1,'Blue Dream'); CREATE TABLE States (State TEXT,Legalization TEXT); INSERT INTO States (State,Legalization) VALUES ('Colorado','Recreational'); | SELECT d.DispensaryName, COUNT(DISTINCT i.Strain) as UniqueStrains FROM Dispensaries d INNER JOIN Inventory i ON d.DispensaryID = i.DispensaryID INNER JOIN States s ON d.State = s.State WHERE s.Legalization = 'Recreational' GROUP BY d.DispensaryName; |
What is the minimum weight lifted in the deadlift exercise by members who joined in 2021? | CREATE TABLE members(id INT,join_date DATE); INSERT INTO members (id,join_date) VALUES (1,'2021-01-01'),(2,'2022-03-15'); CREATE TABLE weights(id INT,member_id INT,exercise VARCHAR(15),weight INT); INSERT INTO weights (id,member_id,exercise,weight) VALUES (1,1,'deadlift',200),(2,2,'squat',150); | SELECT MIN(weight) FROM weights w JOIN members m ON w.member_id = m.id WHERE YEAR(m.join_date) = 2021 AND w.exercise = 'deadlift'; |
What is the change in mental health score between consecutive school years for students with a mental health score above 80? | CREATE TABLE mental_health_changes (student_id INT,year INT,score INT); INSERT INTO mental_health_changes (student_id,year,score) VALUES (1,2018,80),(1,2019,85),(2,2018,70),(2,2019,75),(3,2018,90),(3,2019,95); | SELECT year, score, LAG(score, 1) OVER (PARTITION BY student_id ORDER BY year) AS previous_score, score - LAG(score, 1) OVER (PARTITION BY student_id ORDER BY year) AS score_change FROM mental_health_changes WHERE score > 80; |
What is the total billing amount for civil cases? | CREATE TABLE CivilCases (CaseID INT,CaseType VARCHAR(20),BillingAmount DECIMAL(10,2)); INSERT INTO CivilCases (CaseID,CaseType,BillingAmount) VALUES (1,'Civil',5000.00),(2,'Civil',3000.50); | SELECT SUM(BillingAmount) FROM CivilCases WHERE CaseType = 'Civil'; |
List the unique cultural competency training programs offered by providers in Illinois and Michigan. | CREATE TABLE cultural_competency_training (id INT,provider_id INT,program_name VARCHAR(100),program_date DATE); INSERT INTO cultural_competency_training (id,provider_id,program_name,program_date) VALUES (3,111,'Cultural Competency 101','2021-03-01'),(4,111,'Cultural Diversity Workshop','2021-04-15'); CREATE TABLE healthcare_providers (id INT,name VARCHAR(50),region VARCHAR(50)); INSERT INTO healthcare_providers (id,name,region) VALUES (111,'Clara Garcia','Illinois'),(222,'Daniel Lee','Michigan'); | SELECT DISTINCT program_name FROM cultural_competency_training INNER JOIN healthcare_providers ON cultural_competency_training.provider_id = healthcare_providers.id WHERE healthcare_providers.region IN ('Illinois', 'Michigan'); |
What is the total population of indigenous communities in each country? | CREATE TABLE indigenous_communities (id INT,country VARCHAR,community_name VARCHAR,population INT); INSERT INTO indigenous_communities VALUES (1,'Canada','First Nations',637000); | SELECT country, SUM(population) FROM indigenous_communities GROUP BY country; |
What's the sum of all donations made by the top 10 donors, categorized by cause area? | CREATE TABLE donors (id INT,name TEXT,total_donated_amount FLOAT); CREATE TABLE donations (id INT,donor_id INT,organization_id INT,donation_amount FLOAT); CREATE TABLE organizations (id INT,name TEXT,cause_area TEXT); | SELECT o.cause_area, SUM(donations.donation_amount) as total_donations FROM donations INNER JOIN organizations o ON donations.organization_id = o.id INNER JOIN (SELECT id, total_donated_amount FROM donors ORDER BY total_donated_amount DESC LIMIT 10) d ON donations.donor_id = d.id GROUP BY o.cause_area; |
Who are the top 3 most prolific male authors from Europe? | CREATE TABLE authors (id INT,name TEXT,gender TEXT,region TEXT); CREATE TABLE articles (id INT,title TEXT,author_id INT); INSERT INTO authors (id,name,gender,region) VALUES (1,'Author1','Male','Europe'),(2,'Author2','Female','Asia'),(3,'Author3','Male','Europe'),(4,'Author4','Female','Africa'); INSERT INTO articles (id,title,author_id) VALUES (1,'Article1',1),(2,'Article2',2),(3,'Article3',3),(4,'Article4',3),(5,'Article5',4); | SELECT authors.name, COUNT(articles.id) as article_count FROM authors INNER JOIN articles ON authors.id = articles.author_id WHERE authors.gender = 'Male' AND authors.region = 'Europe' GROUP BY authors.name ORDER BY article_count DESC LIMIT 3; |
What is the maximum transaction amount for clients with a primary language of Spanish in Q2 2023? | CREATE TABLE clients (client_id INT,name VARCHAR(50),primary_language VARCHAR(50),max_transaction_amount DECIMAL(10,2));CREATE TABLE transactions (transaction_id INT,client_id INT,transaction_date DATE,total_amount DECIMAL(10,2)); | SELECT MAX(max_transaction_amount) FROM clients c INNER JOIN transactions t ON c.client_id = t.client_id WHERE c.primary_language = 'Spanish' AND t.transaction_date BETWEEN '2023-04-01' AND '2023-06-30' |
Update the investment amount for the record with id 1 in the investment_data table to 300000.00. | CREATE TABLE investment_data (id INT,investment_amount FLOAT,strategy VARCHAR(50),region VARCHAR(50)); INSERT INTO investment_data (id,investment_amount,strategy,region) VALUES (1,250000.00,'Renewable energy','Americas'); INSERT INTO investment_data (id,investment_amount,strategy,region) VALUES (2,500000.00,'Green energy','Asia-Pacific'); INSERT INTO investment_data (id,investment_amount,strategy,region) VALUES (3,300000.00,'Sustainable agriculture','Europe'); | UPDATE investment_data SET investment_amount = 300000.00 WHERE id = 1; |
Get the total 'amount' invested by 'EthicalVentures' in 'WasteManagement'. | CREATE TABLE InvestmentsAmount (id INT,investor VARCHAR(255),sector VARCHAR(255),amount DECIMAL(10,2)); | SELECT SUM(amount) FROM InvestmentsAmount WHERE investor = 'EthicalVentures' AND sector = 'WasteManagement'; |
What is the total number of words in all articles published by "The Washington Post" in the last 3 months, excluding articles with less than 500 words? | CREATE TABLE articles (id INT,title TEXT,publication DATE,newspaper TEXT,word_count INT); INSERT INTO articles (id,title,publication,newspaper,word_count) VALUES (1,'Article 1','2022-01-01','The Washington Post',1000); INSERT INTO articles (id,title,publication,newspaper,word_count) VALUES (2,'Article 2','2022-02-14','The Washington Post',700); INSERT INTO articles (id,title,publication,newspaper,word_count) VALUES (3,'Article 3','2022-03-20','The Washington Post',1500); | SELECT SUM(word_count) FROM articles WHERE newspaper = 'The Washington Post' AND publication >= DATE_SUB(CURDATE(), INTERVAL 3 MONTH) AND word_count >= 500; |
What was the average exhibition duration for sculptures, partitioned by gallery? | CREATE TABLE GalleryC (gallery_name VARCHAR(20),artwork_type VARCHAR(20),exhibition_duration INT); INSERT INTO GalleryC (gallery_name,artwork_type,exhibition_duration) VALUES ('GalleryC','Sculpture',120),('GalleryC','Sculpture',90),('GalleryC','Painting',60); | SELECT gallery_name, AVG(exhibition_duration) as avg_duration FROM (SELECT gallery_name, artwork_type, exhibition_duration, ROW_NUMBER() OVER (PARTITION BY gallery_name, artwork_type ORDER BY exhibition_duration) as rn FROM GalleryC) tmp WHERE rn = 1 GROUP BY gallery_name; |
What is the total revenue generated from concerts in Mexico? | CREATE TABLE concert_revenue (venue VARCHAR(255),date DATE,location VARCHAR(255),tickets_sold INT,revenue INT); INSERT INTO concert_revenue (venue,date,location,tickets_sold,revenue) VALUES ('Auditorio Nacional','2022-09-01','Mexico',12000,250000),('Forum Mundo Imperial','2022-10-15','Mexico',8000,180000); | SELECT SUM(revenue) as total_revenue FROM concert_revenue WHERE location = 'Mexico'; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.