instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the average age of players who play 'Racing' games? | CREATE TABLE Players (player_id INT,name VARCHAR(255),age INT,game_genre VARCHAR(255)); INSERT INTO Players (player_id,name,age,game_genre) VALUES (1,'John',27,'FPS'),(2,'Sarah',30,'RPG'),(3,'Alex',22,'FPS'),(4,'Max',25,'Strategy'),(5,'Zoe',28,'Racing'),(6,'Ella',24,'Racing'); | SELECT AVG(age) FROM Players WHERE game_genre = 'Racing'; |
What is the total number of games designed by women? | CREATE TABLE GameDesigners (DesignerID INT,DesignerName VARCHAR(50),Gender VARCHAR(10),NumberOfGames INT); INSERT INTO GameDesigners (DesignerID,DesignerName,Gender,NumberOfGames) VALUES (1,'Alice','Female',3),(2,'Bob','Male',2),(3,'Charlie','Non-binary',1); | SELECT SUM(NumberOfGames) FROM GameDesigners WHERE Gender = 'Female'; |
Who funded the excavation of 'Herculaneum' and what was the date? | CREATE TABLE Funding (SiteID INT,FundingAgency TEXT,FundingDate DATE); INSERT INTO Funding (SiteID,FundingAgency,FundingDate) VALUES (2,'Italian Government','1927-04-01'),(3,'French Government','1952-05-01'),(4,'German Government','1985-06-01'); | SELECT FundingAgency, FundingDate FROM Funding f JOIN ExcavationSites e ON f.SiteID = e.SiteID WHERE e.SiteName = 'Herculaneum'; |
What is the total fare collected in each city? | CREATE TABLE FareCollection (CollectionID INT,CollectionDate DATE,City VARCHAR(50),Fare DECIMAL(10,2)); INSERT INTO FareCollection (CollectionID,CollectionDate,City,Fare) VALUES (1,'2023-01-01','CityA',10.0),(2,'2023-01-05','CityB',15.0),(3,'2023-02-10','CityA',20.0); | SELECT City, SUM(Fare) as TotalFare FROM FareCollection GROUP BY City; |
List the top 3 clothing categories with the most size-inclusive items. | CREATE TABLE Clothing_Categories (category_id INT,category_name TEXT); CREATE TABLE Items (item_id INT,category_id INT,size_id INT,is_size_inclusive BOOLEAN); CREATE TABLE Sizes (size_id INT,size_name TEXT); | SELECT c.category_name, COUNT(i.item_id) as size_inclusive_item_count FROM Clothing_Categories c JOIN Items i ON c.category_id = i.category_id JOIN Sizes s ON i.size_id = s.size_id WHERE i.is_size_inclusive = TRUE GROUP BY c.category_name ORDER BY size_inclusive_item_count DESC LIMIT 3; |
What is the total cost of all projects in the 'Water_Distribution' table? | CREATE TABLE Water_Distribution (project_id INT,project_name VARCHAR(50),location VARCHAR(50),total_cost FLOAT); INSERT INTO Water_Distribution (project_id,project_name,location,total_cost) VALUES (1,'Water Treatment Plant','New York',5000000); INSERT INTO Water_Distribution (project_id,project_name,location,total_cost) VALUES (2,'Pipe Replacement','California',2500000); | SELECT SUM(total_cost) FROM Water_Distribution; |
How many public works projects were completed in New York in 2020? | CREATE TABLE PublicWorks (ProjectID INT,Location VARCHAR(20),Year INT,Completed BOOLEAN); INSERT INTO PublicWorks (ProjectID,Location,Year,Completed) VALUES (1,'New York',2020,TRUE); | SELECT COUNT(*) FROM PublicWorks WHERE Location = 'New York' AND Year = 2020 AND Completed = TRUE; |
Calculate the average CO2 emission level for vessels in the 'Atlantic' fleet, per month. | CREATE TABLE vessels (vessel_id INT,fleet VARCHAR(50),CO2_emission_level FLOAT); CREATE TABLE handling (handling_id INT,vessel_id INT,handling_date DATE); | SELECT AVG(v.CO2_emission_level) AS avg_CO2_emission, YEAR(h.handling_date) AS handling_year, MONTH(h.handling_date) AS handling_month FROM vessels v JOIN handling h ON v.vessel_id = h.vessel_id WHERE v.fleet = 'Atlantic' GROUP BY YEAR(h.handling_date), MONTH(h.handling_date); |
What is the total number of public transportation trips in 'trips_data' table? | CREATE TABLE trips_data (id INT,trip_type VARCHAR(20),trip_count INT); | SELECT SUM(trip_count) FROM trips_data WHERE trip_type = 'Public Transportation'; |
What is the average weight of all pottery artifacts from the 'Italian Digs' site? | CREATE TABLE If Not Exists excavation_sites (site_id INT,site_name TEXT); INSERT INTO excavation_sites (site_id,site_name) VALUES (1,'Italian Digs'),(2,'Greek Site'),(3,'Egyptian Digs'); CREATE TABLE If Not Exists artifacts (artifact_id INT,artifact_name TEXT,artifact_weight FLOAT,site_id INT); INSERT INTO artifacts (artifact_id,artifact_name,artifact_weight,site_id) VALUES (1,'Amphora',12.3,1),(2,'Pithos',34.5,1),(3,'Oinochoe',2.5,2),(4,'Kylix',1.2,2),(5,'Scarab',0.3,3); | SELECT AVG(artifact_weight) FROM artifacts WHERE site_id = 1; |
What is the distribution of media types in the database? | CREATE TABLE media (id INT,title VARCHAR(255),type VARCHAR(255)); INSERT INTO media (id,title,type) VALUES (1,'Movie1','Movie'),(2,'Documentary1','Documentary'),(3,'Series1','Series'),(4,'Podcast1','Podcast'); | SELECT type, COUNT(*) as count FROM media GROUP BY type; |
Top 5 rated movies by budget? | CREATE TABLE MovieRatings (MovieID INT,Title VARCHAR(100),Budget DECIMAL(10,2),Rating DECIMAL(3,2)); | SELECT Title, Budget, Rating FROM (SELECT Title, Budget, Rating, ROW_NUMBER() OVER (ORDER BY Rating DESC, Budget DESC) as rn FROM MovieRatings) t WHERE rn <= 5; |
How many athletes are in the hockey_players table, and what is their total salary? | CREATE TABLE hockey_players (player_id INT,name VARCHAR(50),position VARCHAR(50),salary DECIMAL(5,2)); INSERT INTO hockey_players (player_id,name,position,salary) VALUES (1,'James Lee','Goalie',50000.00),(2,'Jasmine White','Forward',75000.00); | SELECT COUNT(*), SUM(salary) FROM hockey_players; |
What is the percentage of total aid delivered by each organization? | CREATE TABLE aid_deliveries (delivery_id INT,organization VARCHAR(50),delivery_status VARCHAR(10),amount_delivered INT); INSERT INTO aid_deliveries (delivery_id,organization,delivery_status,amount_delivered) VALUES (1,'Org A','successful',5000),(2,'Org B','failed',2000),(3,'Org A','successful',6000),(4,'Org C','successful',7000),(5,'Org B','failed',3000),(6,'Org A','successful',8000); CREATE TABLE organizations (org_id INT,name VARCHAR(50)); INSERT INTO organizations (org_id,name) VALUES (1,'Org A'),(2,'Org B'),(3,'Org C'); | SELECT organization, ROUND(100.0*SUM(CASE WHEN delivery_status = 'successful' THEN amount_delivered ELSE 0 END)/SUM(amount_delivered) OVER(PARTITION BY 1), 2) AS pct_of_total FROM aid_deliveries JOIN organizations ON aid_deliveries.organization = organizations.name ORDER BY pct_of_total DESC |
Display the dishes with the lowest calorie count for each dish type. | CREATE TABLE dishes (dish_id INT,dish_name VARCHAR(50),dish_type VARCHAR(20),calorie_count INT); INSERT INTO dishes (dish_id,dish_name,dish_type,calorie_count) VALUES (1,'Veggie Delight','vegan',300),(2,'Tofu Stir Fry','vegan',450),(3,'Chickpea Curry','vegan',500),(4,'Lamb Korma','non-veg',900),(5,'Chicken Tikka','non-veg',600); | SELECT dish_name, dish_type, calorie_count FROM (SELECT dish_name, dish_type, calorie_count, RANK() OVER (PARTITION BY dish_type ORDER BY calorie_count ASC) rnk FROM dishes) t WHERE rnk = 1; |
What is the total prize money won by teams from the United States in esports events? | CREATE TABLE teams (id INT,name VARCHAR(50),country VARCHAR(50),prize_money_won DECIMAL(10,2)); INSERT INTO teams (id,name,country,prize_money_won) VALUES (1,'Team1','USA',50000.00),(2,'Team2','China',35000.00),(3,'Team3','USA',60000.00); | SELECT SUM(prize_money_won) FROM teams WHERE country = 'USA'; |
What is the total training cost for the Sales department? | CREATE TABLE Trainings (TrainingID INT,Department VARCHAR(20),Cost FLOAT); INSERT INTO Trainings (TrainingID,Department,Cost) VALUES (1,'Sales',5000),(2,'IT',7000),(3,'Sales',6000),(4,'HR',4000); | SELECT SUM(Cost) FROM Trainings WHERE Department = 'Sales'; |
What is the average funding amount for companies founded in the last 3 years that have a female co-founder? | CREATE TABLE companies (id INT,name TEXT,founding_date DATE,co_founder_gender TEXT); INSERT INTO companies (id,name,founding_date,co_founder_gender) VALUES (1,'GreenTechHub','2020-01-01','Female'); | SELECT AVG(funding_amount) FROM funding_records JOIN companies ON funding_records.company_id = companies.id WHERE companies.founding_date >= DATEADD(year, -3, CURRENT_DATE) AND companies.co_founder_gender = 'Female'; |
Show the total investment amount for each investment type in the "investment_rounds" table | CREATE TABLE investment_rounds (round_name VARCHAR(50),investment_year INT,investment_amount INT,investment_type VARCHAR(50)); | SELECT investment_type, SUM(investment_amount) FROM investment_rounds GROUP BY investment_type; |
What is the average age of employees who have completed diversity and inclusion training? | CREATE TABLE employees (id INT,age INT,gender VARCHAR(10),diversity_training BOOLEAN); | SELECT AVG(age) FROM employees WHERE diversity_training = TRUE; |
What is the name of the faculty member with the least number of publications in the Computer Science department? | CREATE TABLE Faculty (FacultyID int,Name varchar(50),Department varchar(50),NumPublications int); INSERT INTO Faculty (FacultyID,Name,Department,NumPublications) VALUES (1,'John Doe','Mathematics',15); INSERT INTO Faculty (FacultyID,Name,Department,NumPublications) VALUES (2,'Jane Smith','Mathematics',20); INSERT INTO Faculty (FacultyID,Name,Department,NumPublications) VALUES (3,'Mary Johnson','Physics',25); INSERT INTO Faculty (FacultyID,Name,Department,NumPublications) VALUES (4,'Bob Brown','Physics',10); INSERT INTO Faculty (FacultyID,Name,Department,NumPublications) VALUES (5,'Alice Davis','Computer Science',5); INSERT INTO Faculty (FacultyID,Name,Department,NumPublications) VALUES (6,'Charlie Brown','Computer Science',10); | SELECT Name FROM Faculty WHERE Department = 'Computer Science' AND NumPublications = (SELECT MIN(NumPublications) FROM Faculty WHERE Department = 'Computer Science'); |
What are the names and prices of the menu items that are offered at all restaurants? | CREATE TABLE menu_items (menu_item_id INT,name VARCHAR(255),price DECIMAL(5,2),restaurant_id INT); INSERT INTO menu_items (menu_item_id,name,price,restaurant_id) VALUES (1,'Big Burger',12.99,1); INSERT INTO menu_items (menu_item_id,name,price,restaurant_id) VALUES (2,'Chicken Teriyaki',15.99,2); INSERT INTO menu_items (menu_item_id,name,price,restaurant_id) VALUES (3,'Garden Salad',7.99,1); INSERT INTO menu_items (menu_item_id,name,price,restaurant_id) VALUES (4,'Big Burger',11.99,2); | SELECT name, price FROM menu_items WHERE menu_item_id IN (SELECT restaurant_id FROM restaurants) GROUP BY name, price HAVING COUNT(DISTINCT restaurant_id) = (SELECT COUNT(DISTINCT restaurant_id) FROM restaurants); |
Show the number of tourists from India who visited Singapore in 2022 and 2023. | CREATE TABLE tourism_data (id INT,name VARCHAR(50),country VARCHAR(50),destination VARCHAR(50),visit_year INT); INSERT INTO tourism_data (id,name,country,destination,visit_year) VALUES (1,'Ravi Patel','India','Singapore',2022),(2,'Priya Gupta','India','Singapore',2023),(3,'Rajesh Singh','India','Bali',2022); | SELECT COUNT(*) FROM tourism_data WHERE country = 'India' AND destination = 'Singapore' AND visit_year IN (2022, 2023); |
What are the top 3 countries with the most impact investments in renewable energy? | CREATE TABLE impact_investments (investment_id INT,investment_amount DECIMAL(10,2),investment_date DATE,country VARCHAR(50)); INSERT INTO impact_investments VALUES (1,5000000,'2020-01-01','India'),(2,7500000,'2020-02-01','Brazil'),(3,3500000,'2020-03-01','Nigeria'); | SELECT country, SUM(investment_amount) as total_investment FROM impact_investments GROUP BY country ORDER BY total_investment DESC LIMIT 3; |
List the number of users who have used the "Advanced Yoga" class more than once, in the past month, for each day of the week. | CREATE TABLE user_profile (user_id INT,PRIMARY KEY (user_id)); CREATE TABLE class_attendance (class_date DATE,user_id INT,class_name VARCHAR(20),PRIMARY KEY (class_date,user_id)); INSERT INTO user_profile (user_id) VALUES (1),(2),(3); INSERT INTO class_attendance (class_date,user_id,class_name) VALUES ('2022-02-01',1,'Advanced Yoga'),('2022-02-02',2,'Beginner Yoga'),('2022-02-03',1,'Advanced Yoga'),('2022-02-03',3,'Advanced Yoga'),('2022-02-04',1,'Advanced Yoga'); | SELECT DATE_FORMAT(class_date, '%Y-%u') as weekday, COUNT(*) as users_with_multiple_advanced_yoga_classes FROM class_attendance WHERE class_name = 'Advanced Yoga' AND class_date >= DATE(NOW()) - INTERVAL 30 DAY GROUP BY weekday; |
What is the total amount donated by individual donors in the United States? | CREATE TABLE Donors (DonorID int,DonorName varchar(50),Country varchar(50)); INSERT INTO Donors (DonorID,DonorName,Country) VALUES (1,'John Smith','USA'); INSERT INTO Donors (DonorID,DonorName,Country) VALUES (2,'Sara Ahmed','Canada'); | SELECT SUM(DonationAmount) FROM Donations JOIN Donors ON Donations.DonorID = Donors.DonorID WHERE Donors.Country = 'USA'; |
What is the average explainability score for AI models in the Europe region? | CREATE TABLE eu_models (model_name TEXT,region TEXT,explainability_score INTEGER); INSERT INTO eu_models (model_name,region,explainability_score) VALUES ('ModelD','Europe',85),('ModelE','Europe',90),('ModelF','Europe',88); | SELECT AVG(explainability_score) FROM eu_models WHERE region = 'Europe'; |
Which artists have participated in more than 5 cultural events in Paris? | CREATE TABLE artists (id INT,name TEXT,country TEXT);CREATE TABLE cultural_events (id INT,artist_id INT,city TEXT); INSERT INTO artists (id,name,country) VALUES (1,'Picasso','Spain'),(2,'Matisse','France'); INSERT INTO cultural_events (id,artist_id,city) VALUES (1,1,'Paris'),(2,1,'Paris'),(3,1,'Madrid'),(4,2,'Paris'),(5,2,'Paris'),(6,2,'Paris'),(7,2,'Paris'); | SELECT artists.name FROM artists INNER JOIN cultural_events ON artists.id = cultural_events.artist_id WHERE cultural_events.city = 'Paris' GROUP BY artists.name HAVING COUNT(cultural_events.id) > 5; |
What is the total weight of items shipped by sea to 'New York' in the month of 'January'? | CREATE TABLE shipments (shipment_id INT,warehouse_id INT,shipped_date DATE,shipped_weight INT); INSERT INTO shipments (shipment_id,warehouse_id,shipped_date,shipped_weight) VALUES (1,1,'2021-01-03',500),(2,1,'2021-01-10',800),(3,2,'2021-02-15',1000); | SELECT SUM(shipped_weight) FROM shipments WHERE shipped_date BETWEEN '2021-01-01' AND '2021-01-31' AND warehouse_id IN (SELECT warehouse_id FROM warehouses WHERE city = 'New York'); |
What are the total sales and average product price for each product subcategory in Washington for the year 2018? | CREATE TABLE products (id INT,name TEXT,subcategory TEXT,category TEXT); INSERT INTO products (id,name,subcategory,category) VALUES (1,'Product A','Subcategory X','Category A'); INSERT INTO products (id,name,subcategory,category) VALUES (2,'Product B','Subcategory Y','Category B'); CREATE TABLE sales (product_id INT,year INT,sales INT,price INT); INSERT INTO sales (product_id,year,sales,price) VALUES (1,2018,150,55); INSERT INTO sales (product_id,year,sales,price) VALUES (2,2018,200,60); | SELECT p.subcategory, p.category, SUM(s.sales) as total_sales, AVG(s.price) as average_price FROM products p INNER JOIN sales s ON p.id = s.product_id WHERE p.name = 'Washington' AND s.year = 2018 GROUP BY p.subcategory, p.category; |
What is the maximum fare for routes that have more than 100,000 annual passengers? | CREATE TABLE RouteMaxFares (RouteID int,MaxFare decimal(5,2)); INSERT INTO RouteMaxFares (RouteID,MaxFare) VALUES (1,5.00),(2,4.25),(3,3.75); CREATE TABLE RouteRidership (RouteID int,AnnualPassengers int); INSERT INTO RouteRidership (RouteID,AnnualPassengers) VALUES (1,120000),(2,80000),(3,150000); | SELECT MAX(MaxFare) FROM RouteMaxFares INNER JOIN RouteRidership ON RouteMaxFares.RouteID = RouteRidership.RouteID WHERE RouteRidership.AnnualPassengers > 100000; |
List the top 2 dates with the highest humidity in fieldE in 2022. | CREATE TABLE fieldE (humidity FLOAT,date DATE); INSERT INTO fieldE (humidity,date) VALUES (78.5,'2022-01-01'),(81.3,'2022-01-02'); | SELECT date FROM (SELECT date, RANK() OVER (ORDER BY humidity DESC) as rnk FROM fieldE WHERE EXTRACT(YEAR FROM date) = 2022) WHERE rnk <= 2; |
Who is the support staff for the 'Assistive Technology' program in the 'New York' office? | CREATE TABLE office (office_id INT,office_state VARCHAR(50),program_name VARCHAR(50)); CREATE TABLE staff (staff_id INT,staff_name VARCHAR(50),role VARCHAR(50)); INSERT INTO office (office_id,office_state,program_name) VALUES (1,'New York','Assistive Technology'); INSERT INTO staff (staff_id,staff_name,role) VALUES (101,'John Doe','Policy Advocate'),(102,'Jane Smith','Support Staff'); | SELECT staff_name FROM office o JOIN staff s ON o.office_state = s.staff_name WHERE o.program_name = 'Assistive Technology' AND s.role = 'Support Staff'; |
What AI safety conferences were held in Europe? | CREATE TABLE Conferences (conference_name TEXT,location TEXT,domain TEXT); INSERT INTO Conferences VALUES ('NeurIPS','USA','Safety'),('ICML','Canada','Safety'),('AAAI','Spain','AI'); | SELECT conference_name FROM Conferences WHERE domain = 'Safety' AND location = 'Spain'; |
Find the total number of startups founded by women | CREATE TABLE startups(id INT,name TEXT,founding_year INT,founder_gender TEXT); INSERT INTO startups (id,name,founding_year,founder_gender) VALUES (1,'Acme Inc',2010,'Female'); INSERT INTO startups (id,name,founding_year,founder_gender) VALUES (2,'Beta Corp',2015,'Male'); INSERT INTO startups (id,name,founding_year,founder_gender) VALUES (3,'Gamma LLC',2020,'Female'); | SELECT COUNT(*) FROM startups WHERE founder_gender = 'Female'; |
Which airline has the most flights to a specific destination? | CREATE TABLE airline (airline_code CHAR(2),airline_name VARCHAR(50)); INSERT INTO airline VALUES ('UA','United Airlines'),('DL','Delta Air Lines'); CREATE TABLE flight (airline_code CHAR(2),flight_number INT,destination VARCHAR(50)); INSERT INTO flight VALUES ('UA',123,'New York'),('UA',456,'Chicago'),('DL',789,'New York'),('DL',321,'Los Angeles'); | SELECT airline_code, ROW_NUMBER() OVER (PARTITION BY destination ORDER BY COUNT(*) DESC) AS rank FROM flight GROUP BY airline_code, destination; |
What is the total quantity of traditional art pieces by region? | CREATE TABLE Art (ArtID INT,Type VARCHAR(255),Region VARCHAR(255),Quantity INT); INSERT INTO Art (ArtID,Type,Region,Quantity) VALUES (1,'Painting','Asia',25),(2,'Sculpture','Africa',18),(3,'Textile','South America',30),(4,'Pottery','Europe',20),(5,'Jewelry','North America',12); | SELECT Region, SUM(Quantity) as Total_Quantity FROM Art GROUP BY Region; |
What is the total production of all tin mines in 'Country T'? | CREATE TABLE tin_mines (id INT,name TEXT,location TEXT,production INT); INSERT INTO tin_mines (id,name,location,production) VALUES (1,'Tin Mine A','Country T',1200); INSERT INTO tin_mines (id,name,location,production) VALUES (2,'Tin Mine B','Country T',1500); INSERT INTO tin_mines (id,name,location,production) VALUES (3,'Tin Mine C','Country T',800); INSERT INTO tin_mines (id,name,location,production) VALUES (4,'Tin Mine D','Country Y',1000); | SELECT SUM(production) FROM tin_mines WHERE location = 'Country T'; |
For each program, find the number of volunteers, total volunteer hours, and the average volunteer hours per volunteer. | CREATE TABLE Programs (ProgramID INT,ProgramName TEXT); CREATE TABLE Volunteers (VolunteerID INT,VolunteerName TEXT,ProgramID INT,Hours INT); | SELECT ProgramName, COUNT(*) AS NumVolunteers, SUM(Hours) AS TotalHours, AVG(Hours) AS AvgHoursPerVolunteer FROM Programs JOIN Volunteers ON Programs.ProgramID = Volunteers.ProgramID GROUP BY ProgramName; |
What is the total funding per biotech startup and their corresponding rank, ordered by total funding? | CREATE SCHEMA if not exists funding_data;CREATE TABLE if not exists funding_data.startups (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),year INT,funding DECIMAL(10,2)); INSERT INTO funding_data.startups (id,name,country,year,funding) VALUES (1,'StartupA','USA',2018,5000000.00),(2,'StartupB','Canada',2020,3000000.00),(3,'StartupC','USA',2019,7000000.00),(4,'StartupD','Germany',2021,4000000.00); | SELECT name, funding, ROW_NUMBER() OVER (ORDER BY funding DESC) AS rank FROM funding_data.startups; |
List the names of communities that have participated in community development initiatives in the "Visayas" region from the "community_development" table | CREATE TABLE community_development (id INT,community_name VARCHAR(255),region VARCHAR(255),year INT); | SELECT DISTINCT community_name FROM community_development WHERE region = 'Visayas'; |
Delete records of clients who have not participated in any financial literacy programs in the past year from the 'financial_capability' table. | CREATE TABLE financial_capability (client_id INT,financial_literacy_score INT,last_program_date DATE); INSERT INTO financial_capability VALUES (11,80,'2021-08-01'); INSERT INTO financial_capability VALUES (12,70,'2022-01-10'); | DELETE FROM financial_capability WHERE last_program_date < DATE_SUB(CURDATE(), INTERVAL 1 YEAR); |
How many public works projects were completed in each quarter of 2021? | CREATE TABLE public_works_projects (id INT,name VARCHAR(255),completion_date DATE); INSERT INTO public_works_projects (id,name,completion_date) VALUES (1,'Road Reconstruction','2021-03-15'),(2,'Bridge Construction','2021-07-30'),(3,'Traffic Signal Installation','2021-12-18'); | SELECT DATE_FORMAT(completion_date, '%Y-%m') AS quarter, COUNT(*) AS projects_completed FROM public_works_projects WHERE completion_date >= '2021-01-01' AND completion_date < '2022-01-01' GROUP BY quarter; |
What is the earliest artwork on display at 'Museum_X'? | CREATE TABLE Artworks_6 (ArtworkID INT,Title VARCHAR(50),Museum VARCHAR(50),Creation_Date DATE); INSERT INTO Artworks_6 (ArtworkID,Title,Museum,Creation_Date) VALUES (1,'Guernica','Museum_X','1937-04-18'),(2,'The Persistence of Memory','Museum_Y','1937-08-26'),(3,'Memory of a Journey','Museum_X','1912-03-10'),(4,'Water Lilies','Museum_Y','1897-08-13'); | SELECT Title FROM (SELECT Title, ROW_NUMBER() OVER (ORDER BY Creation_Date ASC) as row_num FROM Artworks_6 WHERE Museum = 'Museum_X') as earliest_artwork WHERE row_num = 1; |
What are the names of the freight forwarders who have handled shipments from 'Tokyo' to any destination? | CREATE TABLE FreightForwarders (ID INT,Name VARCHAR(50),Country VARCHAR(50)); INSERT INTO FreightForwarders (ID,Name,Country) VALUES (1,'ABC Logistics','USA'),(2,'XYZ Shipping','Canada'); CREATE TABLE Shipments (ID INT,FreightForwarderID INT,Origin VARCHAR(50),Destination VARCHAR(50)); INSERT INTO Shipments (ID,FreightForwarderID,Origin,Destination) VALUES (1,1,'Tokyo','New York'),(2,2,'Paris','London'); | SELECT FreightForwarders.Name FROM FreightForwarders INNER JOIN Shipments ON FreightForwarders.ID = Shipments.FreightForwarderID WHERE Shipments.Origin = 'Tokyo'; |
What is the percentage of employees of color in the HR department? | CREATE TABLE Employees (EmployeeID INT,Ethnicity VARCHAR(20),Department VARCHAR(20)); INSERT INTO Employees (EmployeeID,Ethnicity,Department) VALUES (1,'Asian','IT'),(2,'White','IT'),(3,'Black','HR'),(4,'Latino','HR'),(5,'Asian','IT'),(6,'White','IT'),(7,'Black','HR'); | SELECT (COUNT(*) FILTER (WHERE Ethnicity IN ('Asian', 'Black', 'Latino')) * 100.0 / COUNT(*)) AS Percentage FROM Employees WHERE Department = 'HR'; |
Insert new records into the garment table for restockings that happened on 2022-01-10 for 4 different garment types. | CREATE TABLE garment (garment_id INT,garment_type VARCHAR(255),restocked_date DATE); | INSERT INTO garment (garment_id, garment_type, restocked_date) VALUES (4, 'Dresses', '2022-01-10'), (5, 'Skirts', '2022-01-10'), (6, 'Hoodies', '2022-01-10'), (7, 'Pants', '2022-01-10'); |
Show the total number of ad clicks and the click-through rate (CTR) for each advertising campaign in the last quarter. | CREATE TABLE campaigns (campaign_id INT,campaign_name VARCHAR(255),start_date DATE,end_date DATE); CREATE TABLE ad_impressions (ad_id INT,campaign_id INT,impressions INT,click_date DATE); | SELECT c.campaign_name, SUM(ai.impressions) as total_impressions, SUM(ai.clicks) as total_clicks, SUM(ai.clicks) / SUM(ai.impressions) as ctr FROM campaigns c INNER JOIN ad_impressions ai ON c.campaign_id = ai.campaign_id WHERE ai.click_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 3 MONTH) AND CURDATE() GROUP BY c.campaign_name; |
Update the destination of tourists visiting Italy from Spain in 2023. | CREATE TABLE tourism_data (id INT,country VARCHAR(50),destination VARCHAR(50),arrival_date DATE,age INT); INSERT INTO tourism_data (id,country,destination,arrival_date,age) VALUES (13,'Spain','Italy','2023-01-23',34),(14,'Spain','Italy','2023-05-16',27); | UPDATE tourism_data SET destination = 'France' WHERE country = 'Spain' AND destination = 'Italy' AND YEAR(arrival_date) = 2023; |
Find the top 5 most frequently used pick-up locations in ride_data. | CREATE TABLE ride_data (ride_id INT,ride_start_time TIMESTAMP,ride_end_time TIMESTAMP,pickup_location VARCHAR(100)); | SELECT pickup_location, COUNT(*) AS trips_count FROM ride_data GROUP BY pickup_location ORDER BY trips_count DESC LIMIT 5; |
Find the top 3 menu items with the highest revenue in each restaurant. | CREATE TABLE menu_items (menu_item_id INT,restaurant_id INT,name VARCHAR(255),revenue DECIMAL(10,2)); | SELECT restaurant_id, name, revenue, RANK() OVER (PARTITION BY restaurant_id ORDER BY revenue DESC) as rank FROM menu_items WHERE rank <= 3; |
What is the total sales amount for each region? | CREATE TABLE sales (item_id INT,sales_quantity INT,sales_amount DECIMAL,region TEXT); INSERT INTO sales (item_id,sales_quantity,sales_amount,region) VALUES (1,10,50.00,'Midwest'),(2,5,37.50,'Northeast'),(3,15,45.00,'South'); | SELECT region, SUM(sales_amount) as total_sales_amount FROM sales GROUP BY region; |
What are the total mineral extractions for each country in 2020, sorted by the highest amount? | CREATE TABLE MineralExtraction (year INT,country TEXT,mineral TEXT,quantity INT); INSERT INTO MineralExtraction (year,country,mineral,quantity) VALUES (2020,'Canada','Gold',15000),(2020,'USA','Silver',20000),(2020,'Mexico','Gold',12000),(2020,'Canada','Silver',18000),(2020,'USA','Gold',25000),(2020,'Mexico','Silver',14000); | SELECT context.country, SUM(context.quantity) as total_mineral_extraction FROM MineralExtraction context WHERE context.year = 2020 GROUP BY context.country ORDER BY total_mineral_extraction DESC; |
What is the percentage of items produced in each country? | CREATE TABLE CountryBreakdown (item_id INT,country VARCHAR(255)); INSERT INTO CountryBreakdown (item_id,country) VALUES (1,'Spain'),(2,'Italy'),(3,'Spain'),(4,'France'),(5,'Spain'); | SELECT country, 100.0 * COUNT(*) / (SELECT COUNT(*) FROM CountryBreakdown) AS percentage FROM CountryBreakdown GROUP BY country; |
Create a view that displays the name and budget of mitigation projects in California | CREATE VIEW cali_mitigation_projects AS SELECT name,budget FROM mitigation_projects WHERE location = 'California'; | CREATE VIEW cali_mitigation_projects AS SELECT name, budget FROM mitigation_projects WHERE location = 'California'; |
What is the average temperature in region 1 and region 2? | CREATE TABLE WeatherData (region INT,temperature FLOAT); INSERT INTO WeatherData (region,temperature) VALUES (1,22.5),(1,23.2),(2,20.8),(2,21.3); | SELECT AVG(temperature) FROM WeatherData WHERE region IN (1, 2) |
What is the total number of legal tech patents filed in the European Union and Japan between 2010 and 2020? | CREATE TABLE legal_tech_patents (id INT,patent_name VARCHAR(255),country VARCHAR(255),filing_year INT); INSERT INTO legal_tech_patents (id,patent_name,country,filing_year) VALUES (1,'AI Document Review System','United States',2018),(2,'Smart Contract Platform','China',2019),(3,'Legal Chatbot','United States',2017),(4,'Blockchain-based E-Discovery','China',2016),(5,'Automated Contract Analysis','Japan',2015),(6,'Legal Expert System','Germany',2016),(7,'AI Intellectual Property Management','France',2017),(8,'Legal Data Analytics','Italy',2018),(9,'Blockchain-based Legal Document Management','England',2019),(10,'AI Legal Research','Spain',2020); | SELECT COUNT(*) AS total_patents FROM legal_tech_patents WHERE country IN ('European Union', 'Japan') AND filing_year BETWEEN 2010 AND 2020; |
Show the number of climate communication projects per year in Africa. | CREATE TABLE comm_projects (project_name TEXT,year INTEGER);INSERT INTO comm_projects (project_name,year) VALUES ('Climate Awareness',2017),('Climate Action',2018); | SELECT year, COUNT(project_name) as num_projects FROM comm_projects WHERE region = 'Africa' GROUP BY year; |
What is the average time to exit for startups in the renewable energy sector? | CREATE TABLE startup (id INT,name TEXT,industry TEXT,founded_at DATE); INSERT INTO startup VALUES (1,'StartupA','Renewable Energy','2010-01-01'); INSERT INTO startup VALUES (2,'StartupB','Tech','2015-01-01'); | SELECT AVG(DATEDIFF('day', founded_at, exit_at)) as avg_exit_time FROM startup WHERE industry = 'Renewable Energy'; |
What is the total length of the underwater cables in the Arctic Ocean? | CREATE TABLE underwater_cables (cable_name TEXT,location TEXT,length FLOAT); INSERT INTO underwater_cables VALUES ('Northern Lights Cable','Arctic Ocean',1200),('Arctic Link','Arctic Ocean',1500); | SELECT SUM(length) FROM underwater_cables WHERE location = 'Arctic Ocean'; |
List the names and number of safety incidents of vessels that had safety incidents in 2018 and 2019. | CREATE TABLE Vessels (id INT,name TEXT,safety_record TEXT,incident_year INT); INSERT INTO Vessels (id,name,safety_record,incident_year) VALUES (1,'Vessel1','Safe',2017); INSERT INTO Vessels (id,name,safety_record,incident_year) VALUES (2,'Vessel2','Incident',2018); | SELECT name, COUNT(*) FROM Vessels WHERE incident_year IN (2018, 2019) GROUP BY name HAVING COUNT(*) > 0; |
List open data initiatives in Oregon | CREATE TABLE open_data_initiatives (name VARCHAR(255),state VARCHAR(255),category VARCHAR(255),description VARCHAR(255),url VARCHAR(255)); INSERT INTO open_data_initiatives (name,state,category,description,url) VALUES ('Oregon Open Data Portal','Oregon','Transportation','Portal for Oregon open data','https://data.oregon.gov/'); INSERT INTO open_data_initiatives (name,state,category,description,url) VALUES ('Portland Open Data','Oregon','Education','Portal for Portland open data','https://opendata.portlandoregon.gov/'); | SELECT * FROM open_data_initiatives WHERE state = 'Oregon'; |
What are the top 2 sustainable food items ordered in dinner menus? | CREATE TABLE food_items (id INT,name VARCHAR(255),is_sustainable BOOLEAN,menu_id INT); INSERT INTO food_items (id,name,is_sustainable,menu_id) VALUES (1,'Quinoa Salad',true,3),(2,'Grilled Chicken',false,3),(3,'Sushi',true,3),(4,'Cheeseburger',false,3); CREATE TABLE menus (id INT,name VARCHAR(255)); INSERT INTO menus (id,name) VALUES (1,'Breakfast'),(2,'Lunch'),(3,'Dinner'); | SELECT fi.name FROM food_items fi JOIN menus m ON fi.menu_id = m.id WHERE m.name = 'Dinner' AND fi.is_sustainable = true GROUP BY fi.name ORDER BY COUNT(*) DESC LIMIT 2; |
What is the total number of employees in each department who are female and of Asian descent? | CREATE TABLE Employees (EmployeeID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Gender VARCHAR(50),Ethnicity VARCHAR(50),Department VARCHAR(50)); INSERT INTO Employees (EmployeeID,FirstName,LastName,Gender,Ethnicity,Department) VALUES (1,'John','Doe','Male','Asian','Mining Operations'),(2,'Jane','Smith','Female','Asian','Human Resources'); | SELECT Department, COUNT(*) FROM Employees WHERE Gender = 'Female' AND Ethnicity = 'Asian' GROUP BY Department; |
Create a view to display products from suppliers with a sustainability score greater than 80 | CREATE VIEW sustainable_products AS SELECT p.* FROM products p JOIN suppliers s ON p.supplier_id = s.supplier_id WHERE s.sustainability_score > 80; | CREATE VIEW sustainable_products AS SELECT p.* FROM products p JOIN suppliers s ON p.supplier_id = s.supplier_id WHERE s.sustainability_score > 80; |
List all wells that were drilled in the 'Haynesville' shale play and had production greater than 2000 in any quarter. | CREATE TABLE wells (well_id INT,well_name VARCHAR(50),shale_play VARCHAR(50),production_q1 FLOAT,production_q2 FLOAT,production_q3 FLOAT,production_q4 FLOAT); INSERT INTO wells (well_id,well_name,shale_play,production_q1,production_q2,production_q3,production_q4) VALUES (1,'Well M','Haynesville',2200,2400,2600,2800),(2,'Well N','Barnett',1900,2150,2400,2650); | SELECT well_name FROM wells WHERE shale_play = 'Haynesville' AND (production_q1 > 2000 OR production_q2 > 2000 OR production_q3 > 2000 OR production_q4 > 2000); |
How many agricultural innovation initiatives were implemented in rural communities of India in 2019?' | CREATE TABLE agricultural_innovation (id INT,location VARCHAR(255),year INT,initiative_count INT); INSERT INTO agricultural_innovation (id,location,year,initiative_count) VALUES (1,'Rural India',2019,30); | SELECT SUM(initiative_count) FROM agricultural_innovation WHERE location = 'Rural India' AND year = 2019; |
How many items are made from sustainable materials in South America? | CREATE TABLE sustainable_materials (id INT,region VARCHAR(20),material VARCHAR(20)); INSERT INTO sustainable_materials (id,region,material) VALUES (1,'South America','organic cotton'),(2,'North America','organic cotton'),(3,'South America','recycled polyester'); | SELECT COUNT(*) FROM sustainable_materials WHERE region = 'South America' AND material IN ('organic cotton', 'recycled polyester'); |
What is the average immunization rate for children under 5 in African countries? | CREATE TABLE countries (country_name VARCHAR(50),continent VARCHAR(50),immunization_rate FLOAT); INSERT INTO countries (country_name,continent,immunization_rate) VALUES ('Nigeria','Africa',45.6),('Egypt','Africa',85.3); | SELECT continent, AVG(immunization_rate) as avg_immunization_rate FROM countries WHERE continent = 'Africa' GROUP BY continent; |
What is the maximum salary of workers in the 'Testing' department for each factory? | CREATE TABLE factories (factory_id INT,department VARCHAR(255)); INSERT INTO factories VALUES (1,'Assembly'),(1,'Quality Control'),(2,'Design'),(2,'Testing'); CREATE TABLE workers (worker_id INT,factory_id INT,department VARCHAR(255),role VARCHAR(255),salary INT); INSERT INTO workers VALUES (1,1,'Assembly','Engineer',50000),(2,1,'Assembly','Technician',40000),(3,1,'Quality Control','Inspector',45000),(4,2,'Design','Architect',60000),(5,2,'Testing','Tester',55000); | SELECT f.factory_id, MAX(w.salary) as max_salary FROM factories f JOIN workers w ON f.factory_id = w.factory_id WHERE f.department = 'Testing' GROUP BY f.factory_id; |
Find mining equipment that has not been serviced in the last 6 months | CREATE TABLE service_records (equipment_id INT,service_date DATE); | SELECT * FROM Mining_Equipment WHERE equipment_id NOT IN (SELECT equipment_id FROM service_records WHERE service_date > DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH)); |
List all sustainable material types and their average production cost across all brands. | CREATE TABLE SustainableMaterials(material_type VARCHAR(255),brand VARCHAR(255),production_cost DECIMAL(5,2)); | SELECT material_type, AVG(production_cost) FROM SustainableMaterials GROUP BY material_type; |
What is the policy impact on waste management in metropolitan regions? | CREATE TABLE waste_management (waste_id INT,region VARCHAR(20),waste_level INT); INSERT INTO waste_management (waste_id,region,waste_level) VALUES (1,'Capital',10),(2,'Capital',12),(3,'City',8),(4,'City',9),(5,'Town',5),(6,'Town',7); CREATE TABLE policies (policy_id INT,region VARCHAR(20),policy_type VARCHAR(20),start_date DATE); INSERT INTO policies (policy_id,region,policy_type,start_date) VALUES (1,'Capital','Metropolitan','2015-01-01'),(2,'City','Urban','2016-01-01'),(3,'Town','Rural','2017-01-01'); | SELECT wm.region, AVG(wm.waste_level) AS avg_waste, p.policy_type FROM waste_management wm INNER JOIN policies p ON wm.region = p.region WHERE p.policy_type IN ('Metropolitan', 'Urban') GROUP BY wm.region, p.policy_type; |
What is the total number of posts in German? | CREATE TABLE posts (id INT,language VARCHAR(255)); INSERT INTO posts (id,language) VALUES (1,'English'),(2,'German'),(3,'French'),(4,'German'); | SELECT COUNT(*) FROM posts WHERE language = 'German'; |
Create a view to display all treatments and their corresponding conditions | CREATE VIEW treatments_and_conditions AS SELECT treatments.treatment_id,name,description,conditions.name AS condition_name FROM treatments JOIN conditions ON treatments.condition_id = conditions.condition_id; | CREATE VIEW treatments_and_conditions AS SELECT treatments.treatment_id, name, description, conditions.name AS condition_name FROM treatments JOIN conditions ON treatments.condition_id = conditions.condition_id; |
What is the total funding allocated for climate finance initiatives in Antarctica between 2020 and 2022? | CREATE TABLE Funding (Year INT,Region VARCHAR(20),Initiative VARCHAR(30),Funding DECIMAL(10,2)); INSERT INTO Funding (Year,Region,Initiative,Funding) VALUES (2020,'Antarctica','Climate Finance',75000.00); INSERT INTO Funding (Year,Region,Initiative,Funding) VALUES (2021,'Antarctica','Climate Finance',85000.00); INSERT INTO Funding (Year,Region,Initiative,Funding) VALUES (2022,'Antarctica','Climate Finance',95000.00); | SELECT SUM(Funding) FROM Funding WHERE Year BETWEEN 2020 AND 2022 AND Region = 'Antarctica' AND Initiative = 'Climate Finance'; |
What is the maximum depth of any marine life research station in the Arctic region? | CREATE TABLE marine_life (id INT,name TEXT,region TEXT,depth FLOAT); INSERT INTO marine_life (id,name,region,depth) VALUES (1,'Station A','Arctic',1500.2); INSERT INTO marine_life (id,name,region,depth) VALUES (2,'Station B','Antarctic',4000.0); | SELECT MAX(depth) FROM marine_life WHERE region = 'Arctic'; |
Show species and their observation counts in 2021. | CREATE TABLE species (id INT PRIMARY KEY,name VARCHAR(255)); INSERT INTO species (id,name) VALUES (1,'polar_bear'),(2,'arctic_fox'); CREATE TABLE observations (id INT PRIMARY KEY,species_id INT,observation_date DATE,FOREIGN KEY (species_id) REFERENCES species(id)); INSERT INTO observations (id,species_id,observation_date) VALUES (1,1,'2021-01-01'),(2,1,'2021-01-02'),(3,2,'2021-02-03'),(4,1,'2021-03-04'); | SELECT s.name, COUNT(o.id) AS observation_count FROM species s JOIN observations o ON s.id = o.species_id WHERE o.observation_date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY s.name; |
Determine the average financial capability score for each continent, ordered by the average score in descending order. | CREATE TABLE financial_capability (individual_id INT,country VARCHAR(50),continent VARCHAR(50),financial_capability_score DECIMAL(5,2)); INSERT INTO financial_capability (individual_id,country,continent,financial_capability_score) VALUES (1,'India','Asia',75.50),(2,'Brazil','South America',80.25),(3,'China','Asia',68.75),(4,'USA','North America',90.00),(5,'Canada','North America',85.00); | SELECT continent, AVG(financial_capability_score) AS avg_score FROM financial_capability GROUP BY continent ORDER BY avg_score DESC; |
What is the total number of posts made by users from the 'americas' region after 2021-06-01? | CREATE TABLE user (id INT,name VARCHAR(50),age INT,gender VARCHAR(10),region VARCHAR(20),created_at TIMESTAMP); CREATE TABLE post (id INT,user_id INT,content TEXT,posted_at TIMESTAMP); INSERT INTO user (id,name,age,gender,region,created_at) VALUES (1,'Juan Garcia',30,'Male','americas','2021-01-01 10:00:00'); INSERT INTO post (id,user_id,content,posted_at) VALUES (1,1,'Hola mundo!','2021-06-02 10:10:00'); | SELECT COUNT(*) FROM post JOIN user ON post.user_id = user.id WHERE user.region = 'americas' AND post.posted_at > '2021-06-01'; |
Find the top 3 countries with the most organizations. | CREATE TABLE organization_country (org_id INT,country TEXT); INSERT INTO organization_country (org_id,country) VALUES (1,'United States'),(2,'Canada'),(3,'Mexico'),(4,'United States'),(5,'Canada'),(6,'Brazil'),(7,'United States'); | SELECT country, COUNT(*) as total_orgs FROM organization_country GROUP BY country ORDER BY total_orgs DESC LIMIT 3; |
What is the total distance of the longest route in the transportation system? | CREATE TABLE ROUTES (route_id TEXT,route_distance REAL); INSERT INTO ROUTES (route_id,route_distance) VALUES ('1',25.0),('2',30.0),('3',22.5),('4',35.0); | SELECT MAX(route_distance) FROM ROUTES; |
What is the total investment in the financial services sector for customers in all regions? | CREATE TABLE investment_data (customer_id INT,sector VARCHAR(20),investment FLOAT); INSERT INTO investment_data (customer_id,sector,investment) VALUES (1,'technology',5000),(2,'financial services',8000),(3,'financial services',3000); CREATE TABLE customer_data (customer_id INT,name VARCHAR(20),region VARCHAR(10)); INSERT INTO customer_data (customer_id,name,region) VALUES (1,'John Doe','west'),(2,'Jane Smith','south'),(3,'Mary Johnson','east'); | SELECT SUM(investment) FROM investment_data INNER JOIN customer_data ON investment_data.customer_id = customer_data.customer_id WHERE sector = 'financial services'; |
Show production figures for wells in the North Sea. | CREATE TABLE wells (well_id INT,country VARCHAR(50),production FLOAT); INSERT INTO wells (well_id,country,production) VALUES (1,'UK - North Sea',1200),(2,'Norway - North Sea',1800),(3,'Netherlands - North Sea',900); | SELECT production FROM wells WHERE country LIKE '%North Sea%'; |
What was the total number of events and total attendees for each event type in 2023? | CREATE TABLE events (id INT,event_type VARCHAR(20),event_date DATE,num_attendees INT); INSERT INTO events (id,event_type,event_date,num_attendees) VALUES (1,'Fundraising','2023-02-01',50); INSERT INTO events (id,event_type,event_date,num_attendees) VALUES (2,'Awareness','2023-03-15',75); | SELECT event_type, COUNT(DISTINCT id) as total_events, SUM(num_attendees) as total_attendees FROM events WHERE event_date BETWEEN '2023-01-01' AND '2023-12-31' GROUP BY event_type; |
Insert data into the 'flight_safety_records' table | CREATE TABLE flight_safety_records (id INT PRIMARY KEY,airline VARCHAR(255),aircraft_model VARCHAR(255),incident_date DATE,incident_description TEXT); | INSERT INTO flight_safety_records (id, airline, aircraft_model, incident_date, incident_description) VALUES (1, 'Aer Lingus', 'Airbus A320', '2022-05-15', 'Engine failure on ascent'); |
How many mental health providers in each state have a rating of 4.5 or higher? | CREATE TABLE mental_health_providers (id INT,name VARCHAR(50),state VARCHAR(50),rating DECIMAL(3,2)); INSERT INTO mental_health_providers (id,name,state,rating) VALUES (1,'Dr. Sarah Johnson','California',4.75),(2,'Dr. Michael Davis','Texas',4.50),(3,'Dr. Emily Garcia','Florida',4.25); | SELECT state, COUNT(*) FROM mental_health_providers WHERE rating >= 4.5 GROUP BY state; |
How many projects are there in total for each category? | CREATE TABLE InfrastructureProjects (id INT,category VARCHAR(20),cost FLOAT); INSERT INTO InfrastructureProjects (id,category,cost) VALUES (1,'Roads',500000),(2,'Bridges',750000),(3,'Buildings',900000),(4,'Roads',600000); | SELECT category, COUNT(*) FROM InfrastructureProjects GROUP BY category; |
What is the percentage of households in the city of Los Angeles that consume less than 1000 liters of water per day? | CREATE TABLE water_consumption_la (id INT,city VARCHAR(50),daily_water_consumption FLOAT); INSERT INTO water_consumption_la (id,city,daily_water_consumption) VALUES (1,'Los Angeles',800),(2,'Los Angeles',1200),(3,'Los Angeles',900); | SELECT (COUNT(*) FILTER (WHERE daily_water_consumption < 1000)) * 100.0 / COUNT(*) FROM water_consumption_la WHERE city = 'Los Angeles' |
What is the total transaction amount for each customer in the last quarter? | CREATE TABLE customers (customer_id INT,name VARCHAR(50)); CREATE TABLE transactions (transaction_id INT,customer_id INT,transaction_amount DECIMAL(10,2)); INSERT INTO customers (customer_id,name) VALUES (1,'John Doe'); INSERT INTO customers (customer_id,name) VALUES (2,'Jane Smith'); INSERT INTO transactions (transaction_id,customer_id,transaction_amount) VALUES (1,1,100.00); INSERT INTO transactions (transaction_id,customer_id,transaction_amount) VALUES (2,2,200.00); | SELECT customer_id, SUM(transaction_amount) as total_transaction_amount FROM transactions WHERE transaction_date BETWEEN DATEADD(day, -90, GETDATE()) AND GETDATE() GROUP BY customer_id; |
What is the total production cost of GOTS Organic certified garments? | CREATE TABLE certifications (certification_id INT,certification_name TEXT); INSERT INTO certifications (certification_id,certification_name) VALUES (1,'Fair Trade'),(2,'GOTS Organic'),(3,'B Corp'); CREATE TABLE garments (garment_id INT,garment_name TEXT,production_cost FLOAT,certification_id INT); INSERT INTO garments (garment_id,garment_name,production_cost,certification_id) VALUES (1,'Organic Cotton Tee',15.50,2),(2,'Cotton Tote Bag',8.25,NULL),(3,'Recycled Polyester Hoodie',28.99,NULL),(4,'Organic Cotton Dress',22.00,2),(5,'Hemp Trousers',35.00,NULL),(6,'Bamboo Shirt',27.50,NULL); | SELECT SUM(g.production_cost) FROM garments g WHERE g.certification_id = 2; |
Calculate the average age of developers in each country | CREATE TABLE Developers (name VARCHAR(255),country VARCHAR(255),age INT); INSERT INTO Developers (name,country,age) VALUES ('Dev1','USA',30),('Dev2','USA',35),('Dev3','China',25); | SELECT country, AVG(age) as avg_age FROM Developers GROUP BY country; |
What is the maximum research grant amount received by a faculty member in the Engineering department? | CREATE TABLE Faculty(Id INT,Name VARCHAR(100),Department VARCHAR(50),Gender VARCHAR(10),GrantAmount DECIMAL(10,2)); INSERT INTO Faculty(Id,Name,Department,Gender,GrantAmount) VALUES (1,'Eve','Engineering','Female',100000.00),(2,'Frank','Engineering','Male',80000.00); | SELECT MAX(GrantAmount) FROM Faculty WHERE Department = 'Engineering'; |
Delete all employees who have been inactive for over a year from the Employee table | CREATE TABLE Employee (EmployeeID INT PRIMARY KEY,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50),LastActivity DATETIME); | DELETE FROM Employee WHERE LastActivity < DATE_SUB(NOW(), INTERVAL 1 YEAR); |
What is the change in biomass of fish for each species between two consecutive months? | CREATE TABLE Stock (StockID INT,FarmID INT,FishSpecies VARCHAR(255),Weight DECIMAL(10,2),StockDate DATE); INSERT INTO Stock (StockID,FarmID,FishSpecies,Weight,StockDate) VALUES (1,1,'Tilapia',5.5,'2022-01-01'),(2,1,'Salmon',12.3,'2022-01-02'),(3,1,'Tilapia',6.0,'2022-02-03'),(4,1,'Catfish',8.2,'2022-02-04'),(5,1,'Tilapia',7.0,'2022-03-01'); | SELECT FishSpecies, DATE_TRUNC('month', StockDate) as Month, SUM(Weight) OVER (PARTITION BY FishSpecies, DATE_TRUNC('month', StockDate)) as Biomass, LAG(SUM(Weight)) OVER (PARTITION BY FishSpecies ORDER BY DATE_TRUNC('month', StockDate)) as PreviousBiomass, SUM(Weight) OVER (PARTITION BY FishSpecies, DATE_TRUNC('month', StockDate)) - LAG(SUM(Weight)) OVER (PARTITION BY FishSpecies ORDER BY DATE_TRUNC('month', StockDate)) as BiomassChange FROM Stock WHERE FarmID = 1; |
Find the number of unique visitors from each country. | CREATE TABLE unique_visitors_country (id INT,name TEXT,country TEXT); INSERT INTO unique_visitors_country VALUES (1,'Kate','Canada'); | SELECT unique_visitors_country.country, COUNT(DISTINCT unique_visitors_country.name) FROM unique_visitors_country GROUP BY unique_visitors_country.country; |
What is the total length of all tunnels in the state of Texas? | CREATE TABLE Tunnels (id INT,name TEXT,state TEXT,length FLOAT); INSERT INTO Tunnels (id,name,state,length) VALUES (1,'Houston Tunnel System','Texas',8000.0); INSERT INTO Tunnels (id,name,state,length) VALUES (2,'Dallas North Tunnel','Texas',3500.0); | SELECT SUM(length) FROM Tunnels WHERE state = 'Texas' |
What is the total waste generation rate in the city of Denver? | CREATE TABLE waste_generation (city VARCHAR(20),waste_rate FLOAT); INSERT INTO waste_generation VALUES ('Denver',1.2); | SELECT waste_rate FROM waste_generation WHERE city = 'Denver'; |
Determine the total number of hybrid buses in the fleet | CREATE TABLE Fleet (VehicleID INT,VehicleType VARCHAR(50),Hybrid BOOLEAN); INSERT INTO Fleet (VehicleID,VehicleType,Hybrid) VALUES (1,'Bus',true),(2,'Bus',false),(3,'Trolley',false),(4,'Hybrid Bus',true),(5,'Van',false),(6,'Hybrid Trolley',true); | SELECT COUNT(*) as TotalHybridBuses FROM Fleet WHERE VehicleType LIKE '%Bus%' AND Hybrid = true; |
What was the total sales revenue for DrugA in Q2 2020? | CREATE TABLE sales(drug_name TEXT,quarter INT,year INT,revenue FLOAT); INSERT INTO sales(drug_name,quarter,year,revenue) VALUES('DrugA',1,2020,150000),('DrugA',2,2020,200000),('DrugA',3,2020,180000),('DrugA',4,2020,220000); | SELECT SUM(revenue) FROM sales WHERE drug_name = 'DrugA' AND quarter = 2 AND year = 2020; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.