instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
How many military bases are located in each state in the 'military_bases' and 'states' tables? | CREATE TABLE states (state_id INT,state_name VARCHAR(50)); CREATE TABLE military_bases (base_id INT,base_name VARCHAR(50),state_id INT); INSERT INTO states VALUES (1,'Alabama'),(2,'Alaska'),(3,'Arizona'); INSERT INTO military_bases VALUES (1,'Fort Rucker',1),(2,'Fort Wainwright',2),(3,'Fort Huachuca',3); | SELECT s.state_name, COUNT(m.base_id) as bases_in_state FROM states s JOIN military_bases m ON s.state_id = m.state_id GROUP BY s.state_name; |
List the marine protected areas in descending order of area size. | CREATE TABLE marine_protected_areas (name VARCHAR(255),location VARCHAR(255),area_size FLOAT); INSERT INTO marine_protected_areas (name,location,area_size) VALUES ('Ross Sea Marine Protected Area','Antarctica',1599800.0),('Papahānaumokuākea Marine National Monument','USA',1397970.0),('Great Barrier Reef Marine Park','Australia',344400.0); | SELECT name, location, area_size FROM (SELECT name, location, area_size, ROW_NUMBER() OVER (ORDER BY area_size DESC) as rn FROM marine_protected_areas) t WHERE rn <= 3; |
What is the average project timeline for sustainable commercial building projects in New York? | CREATE TABLE project_timelines (project_id INT,state VARCHAR(2),building_type VARCHAR(20),project_timeline INT); INSERT INTO project_timelines (project_id,state,building_type,project_timeline) VALUES (1,'NY','Residential',180),(2,'NY','Commercial',240),(3,'NY','Residential',200); | SELECT AVG(project_timeline) FROM project_timelines WHERE state = 'NY' AND building_type = 'Commercial'; |
What is the total billing amount for cases in the criminal category? | CREATE TABLE cases (case_id INT,category VARCHAR(255),billing_amount FLOAT); INSERT INTO cases (case_id,category,billing_amount) VALUES (1,'Civil',5000),(2,'Criminal',3000),(3,'Civil',7000),(4,'Criminal',4000),(5,'Civil',8000); | SELECT SUM(billing_amount) FROM cases WHERE category = 'Criminal'; |
What is the total capacity for solar projects in 'SolarProjects' table, by city? | CREATE TABLE SolarProjects (id INT,project_name TEXT,location TEXT,capacity INT); | SELECT location, SUM(capacity) FROM SolarProjects WHERE project_type = 'Solar' GROUP BY location; |
Who are the developers of AI models that have an accuracy greater than 0.95 and are from India? | CREATE TABLE ai_models (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255),accuracy DECIMAL(5,4),developer_id INT); INSERT INTO ai_models (id,name,type,accuracy,developer_id) VALUES (1,'Deep Learning Model','Classification',0.96,1),(2,'Random Forest Model','Regression',0.88,2),(3,'Naive Bayes Model','Classification',0.91,3); CREATE TABLE developers (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255)); INSERT INTO developers (id,name,country) VALUES (1,'Rajesh Patel','India'),(2,'Marie Curie','France'),(3,'Alice Thompson','Canada'); | SELECT developers.name FROM ai_models INNER JOIN developers ON ai_models.developer_id = developers.id WHERE accuracy > 0.95 AND developers.country = 'India'; |
Delete peacekeeping operations that lasted longer than 3 years. | CREATE TABLE peacekeeping_operations (operation_id INT,operation_name VARCHAR(255),start_year INT,end_year INT); INSERT INTO peacekeeping_operations (operation_id,operation_name,start_year,end_year) VALUES (1,'MINUSTAH',2004,2017),(2,'MONUSCO',2010,2021),(3,'UNMISS',2011,2021); | DELETE FROM peacekeeping_operations WHERE end_year - start_year > 3; |
What is the maximum funding received by a biotech startup in Q1 2022? | CREATE TABLE biotech_startups (name TEXT,funding FLOAT,date DATE); INSERT INTO biotech_startups (name,funding,date) VALUES ('StartupA',5000000,'2022-01-05'); INSERT INTO biotech_startups (name,funding,date) VALUES ('StartupB',7000000,'2022-03-10'); | SELECT MAX(funding) FROM biotech_startups WHERE date BETWEEN '2022-01-01' AND '2022-03-31'; |
Update the account type of clients who have recently upgraded their services. | CREATE TABLE clients (client_id INT,name VARCHAR(50),account_type VARCHAR(50)); | UPDATE clients SET account_type = 'Premium' WHERE client_id IN (SELECT client_id FROM (SELECT client_id, ROW_NUMBER() OVER(ORDER BY client_id) AS rn FROM clients WHERE account_type = 'Basic') AS sq WHERE rn <= 10); |
What is the average calorie count per dish for vegan dishes? | 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); | SELECT AVG(calorie_count) FROM dishes WHERE dish_type = 'vegan'; |
What is the average size of cannabis cultivation facilities in Oregon with a license issued in 2021? | CREATE TABLE facility_sizes (id INT,facility VARCHAR(20),size INT,state VARCHAR(2),license_date DATE); INSERT INTO facility_sizes (id,facility,size,state,license_date) VALUES (1,'Emerald Garden',12000,'OR','2021-02-15'),(2,'Sunny Meadows',8000,'OR','2021-12-20'),(3,'Green Valley',15000,'OR','2021-03-05'); | SELECT AVG(size) FROM facility_sizes WHERE state = 'OR' AND license_date >= '2021-01-01' AND license_date < '2022-01-01'; |
What is the average donation amount from Latin America? | CREATE TABLE Donors (DonorID int,DonorName varchar(100),Country varchar(50),DonationDate date,AmountDonated decimal(10,2)); INSERT INTO Donors (DonorID,DonorName,Country,DonationDate,AmountDonated) VALUES (1,'Juan Pérez','Mexico','2022-01-01',500.00),(2,'María Rodríguez','Brazil','2022-02-01',750.00); | SELECT AVG(AmountDonated) as AverageDonation FROM Donors WHERE Country IN ('Argentina', 'Bolivia', 'Brazil', 'Chile', 'Colombia', 'Costa Rica', 'Cuba', 'Ecuador', 'El Salvador', 'Guatemala', 'Honduras', 'Mexico', 'Nicaragua', 'Panama', 'Paraguay', 'Peru', 'Uruguay', 'Venezuela'); |
Update the 'rate' of the recycling in 'Sydney', 'New South Wales', 'Australia' to 0.55 | CREATE TABLE recycling_rates (id INT,city VARCHAR(255),state VARCHAR(255),country VARCHAR(255),rate DECIMAL(5,2)); | UPDATE recycling_rates SET rate = 0.55 WHERE city = 'Sydney' AND state = 'New South Wales' AND country = 'Australia'; |
List all cities with their total attendance and average attendance per event | CREATE TABLE events (event_id INT,event_name VARCHAR(50),city VARCHAR(30),attendance INT); INSERT INTO events (event_id,event_name,city,attendance) VALUES (1,'Theater Play','New York',200),(2,'Art Exhibit','Los Angeles',300); | SELECT city, SUM(attendance) as total_attendance, AVG(attendance) as avg_attendance_per_event FROM events GROUP BY city; |
What is the maximum number of followers for users from India? | CREATE TABLE users (id INT,name VARCHAR(50),country VARCHAR(2),followers INT); INSERT INTO users (id,name,country,followers) VALUES (1,'Alice','US',1000),(2,'Bob','IN',2000),(3,'Charlie','CA',1500); | SELECT MAX(users.followers) as max_followers FROM users WHERE users.country = 'IN'; |
What is the average growth rate of salmon in the Norwegian aquaculture industry? | CREATE TABLE salmon_farm (id INT,location VARCHAR(20),avg_growth_rate DECIMAL(5,2)); INSERT INTO salmon_farm (id,location,avg_growth_rate) VALUES (1,'Norway',2.3); | SELECT avg(avg_growth_rate) FROM salmon_farm WHERE location = 'Norway'; |
How many teachers in each department have completed professional development courses? | CREATE TABLE departments (id INT PRIMARY KEY,name VARCHAR(255)); CREATE TABLE teachers (id INT PRIMARY KEY,department_id INT,has_completed_pd_course BOOLEAN); | SELECT d.name, COUNT(t.id) FROM teachers t JOIN departments d ON t.department_id = d.id WHERE t.has_completed_pd_course = TRUE GROUP BY t.department_id; |
What is the most popular cruelty-free lipstick in the US in 2021? | CREATE TABLE lipstick_sales (sale_id INT,product_id INT,sale_quantity INT,is_cruelty_free BOOLEAN,sale_date DATE,country VARCHAR(20)); INSERT INTO lipstick_sales VALUES (1,25,7,true,'2021-06-12','US'); INSERT INTO lipstick_sales VALUES (2,26,3,true,'2021-06-12','US'); | SELECT product_id, MAX(sale_quantity) FROM lipstick_sales WHERE is_cruelty_free = true AND country = 'US' AND sale_date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY product_id; |
Identify the top 3 countries with the highest budget for community development initiatives in 2021. | CREATE TABLE initiative_budgets (country VARCHAR(50),year INT,budget INT); INSERT INTO initiative_budgets (country,year,budget) VALUES ('India',2021,1200000),('Bangladesh',2021,900000),('Pakistan',2021,750000); | SELECT country, SUM(budget) as total_budget FROM initiative_budgets WHERE year = 2021 GROUP BY country ORDER BY total_budget DESC LIMIT 3; |
List all security incidents with their status and the number of unique assets impacted, ordered by the number of assets impacted in descending order? | CREATE TABLE SecurityIncidents (incident_id INT,status VARCHAR(10),assets_impacted INT,timestamp TIMESTAMP); INSERT INTO SecurityIncidents (incident_id,status,assets_impacted,timestamp) VALUES (1,'Open',2,'2022-01-01 10:00:00'); | SELECT incident_id, status, COUNT(DISTINCT assets_impacted) as unique_assets_impacted FROM SecurityIncidents GROUP BY incident_id, status ORDER BY unique_assets_impacted DESC; |
How many goals has each team scored in the current season? | CREATE TABLE team_stats (id INT,team TEXT,goals INT,season INT); INSERT INTO team_stats (id,team,goals,season) VALUES (1,'Real Madrid',60,2022),(2,'Barcelona',55,2022),(3,'Atletico Madrid',50,2022); | SELECT team, SUM(goals) FROM team_stats GROUP BY team HAVING season = 2022; |
Find the total quantity of materials used at each manufacturing site, ordered from the most to the least used. | CREATE TABLE materials (material_id INT,site_id INT,quantity INT); | SELECT s.site_name, SUM(quantity) as total_quantity FROM materials m JOIN sites s ON m.site_id = s.site_id GROUP BY site_id ORDER BY total_quantity DESC; |
Insert a new record of a patient from India who received electroconvulsive therapy (ECT)? | CREATE TABLE mental_health.patients (patient_id INT,first_name VARCHAR(50),last_name VARCHAR(50),age INT,gender VARCHAR(50),country VARCHAR(50)); INSERT INTO mental_health.patients (patient_id,first_name,last_name,age,gender,country) VALUES (4,'Ravi','Kumar',35,'Male','India'); CREATE TABLE mental_health.treatments (treatment_id INT,patient_id INT,therapist_id INT,treatment_type VARCHAR(50),country VARCHAR(50)); INSERT INTO mental_health.treatments (treatment_id,patient_id,therapist_id,treatment_type,country) VALUES (5,4,401,'ECT','India'); | INSERT INTO mental_health.treatments (treatment_id, patient_id, therapist_id, treatment_type, country) VALUES (5, (SELECT patient_id FROM mental_health.patients WHERE first_name = 'Ravi' AND last_name = 'Kumar' AND country = 'India'), 401, 'ECT', 'India'); |
What is the total number of exoplanets discovered by the Kepler Space Telescope? | CREATE TABLE exoplanet_discoveries (id INT,discovery_method VARCHAR(50),discovery_tool VARCHAR(50),exoplanet_count INT); | SELECT SUM(exoplanet_count) FROM exoplanet_discoveries WHERE discovery_tool = 'Kepler Space Telescope'; |
Find the most popular destination for US visitors in 2021, excluding New York. | CREATE TABLE TravelStats (VisitorID INT,Destination VARCHAR(20),VisitYear INT); INSERT INTO TravelStats (VisitorID,Destination,VisitYear) VALUES (1,'New York',2021),(2,'London',2021),(3,'Paris',2021),(4,'New York',2021); | SELECT Destination, COUNT(*) AS Popularity FROM TravelStats WHERE VisitYear = 2021 AND Destination != 'New York' GROUP BY Destination ORDER BY Popularity DESC LIMIT 1; |
Compute the percentage of customers who improved their financial wellbeing score from the previous quarter. | CREATE TABLE financial_wellbeing(customer_id INT,score DECIMAL(3,1),measure_date DATE); INSERT INTO financial_wellbeing VALUES (1,75,'2022-01-15'),(2,80,'2022-04-01'),(3,70,'2022-03-05'),(4,85,'2022-05-12'); | SELECT COUNT(*) * 100.0 / SUM(COUNT(*)) OVER () AS pct FROM (SELECT customer_id, score, measure_date, LAG(score) OVER (PARTITION BY customer_id ORDER BY measure_date) AS prev_score FROM financial_wellbeing) t WHERE prev_score IS NOT NULL AND score > prev_score; |
What is the average funding for biotech startups in Argentina? | CREATE TABLE startups (id INT,name VARCHAR(100),location VARCHAR(100),funding FLOAT); INSERT INTO startups (id,name,location,funding) VALUES (1,'StartupD','Argentina',3000000); INSERT INTO startups (id,name,location,funding) VALUES (2,'StartupE','Argentina',4000000); | SELECT AVG(funding) FROM startups WHERE location = 'Argentina'; |
What is the average number of practitioners for each traditional art? | CREATE TABLE avg_practitioners (id INT,art VARCHAR(50),practitioners INT); INSERT INTO avg_practitioners (id,art,practitioners) VALUES (1,'Inuit carving',700); INSERT INTO avg_practitioners (id,art,practitioners) VALUES (2,'Māori tattooing',300); | SELECT art, AVG(practitioners) FROM avg_practitioners; |
What is the total number of employees who identify as women in the engineering department? | CREATE TABLE EmployeeDiversity (EmployeeID INT,Identity VARCHAR(50),Department VARCHAR(50)); INSERT INTO EmployeeDiversity (EmployeeID,Identity,Department) VALUES (1,'Woman','Engineering'),(2,'Man','Marketing'); | SELECT COUNT(*) FROM EmployeeDiversity WHERE Identity = 'Woman' AND Department = 'Engineering'; |
How many volunteers contributed more than 5 hours in each quarter of 2021? | CREATE TABLE Volunteers (id INT,name TEXT,country TEXT,hours FLOAT,quarter TEXT,year INT); INSERT INTO Volunteers (id,name,country,hours,quarter,year) VALUES (1,'Alice','USA',5.0,'Q3',2021),(2,'Bob','Canada',7.5,'Q3',2021),(3,'Eve','Canada',3.0,'Q3',2021),(4,'Frank','USA',6.0,'Q2',2021),(5,'Grace','USA',8.0,'Q2',2021); | SELECT quarter, COUNT(*) FROM Volunteers WHERE hours > 5 GROUP BY quarter; |
What is the energy storage capacity (in MWh) for each renewable energy source in Germany as of 2022-01-01? | CREATE TABLE energy_storage (id INT,source VARCHAR(20),country VARCHAR(20),capacity FLOAT,timestamp DATE); INSERT INTO energy_storage (id,source,country,capacity,timestamp) VALUES (1,'Solar','Germany',55000,'2022-01-01'),(2,'Wind','Germany',72000,'2022-01-01'),(3,'Hydro','Germany',38000,'2022-01-01'); | SELECT source, capacity FROM energy_storage WHERE country = 'Germany' AND timestamp = '2022-01-01'; |
What is the average speed of vessels that departed from Port A in January 2022? | CREATE TABLE Vessels (VesselID INT,VesselName TEXT,AverageSpeed DECIMAL(5,2)); CREATE TABLE Voyages (VoyageID INT,VesselID INT,DepartureDate DATE); INSERT INTO Vessels (VesselID,VesselName,AverageSpeed) VALUES (1,'Vessel1',15.5),(2,'Vessel2',18.2); INSERT INTO Voyages (VoyageID,VesselID,DepartureDate) VALUES (1,1,'2022-01-01'),(2,2,'2022-01-05'); | SELECT AVG(Vessels.AverageSpeed) FROM Vessels INNER JOIN Voyages ON Vessels.VesselID = Voyages.VesselID WHERE YEAR(Voyages.DepartureDate) = 2022 AND MONTH(Voyages.DepartureDate) = 1 AND Voyages.DeparturePort = 'Port A'; |
List all the teams in the 'Soccer' sport, along with the number of players in each team. | CREATE TABLE teams (id INT PRIMARY KEY,name VARCHAR(50),sport VARCHAR(20),city VARCHAR(30)); CREATE TABLE players (id INT PRIMARY KEY,name VARCHAR(50),age INT,sport VARCHAR(20),team VARCHAR(30)); INSERT INTO teams (id,name,sport,city) VALUES (1,'Manchester United','Soccer','Manchester'),(2,'Real Madrid','Soccer','Madrid'); INSERT INTO players (id,name,age,sport,team) VALUES (1,'David De Gea',31,'Soccer','Manchester United'),(2,'Casemiro',30,'Soccer','Real Madrid'); | SELECT teams.name, COUNT(players.id) FROM teams INNER JOIN players ON teams.name = players.team WHERE teams.sport = 'Soccer' GROUP BY teams.name; |
What is the maximum balance for premium customers? | CREATE TABLE customer_accounts (id INT,customer_type VARCHAR(20),account_balance DECIMAL(10,2)); INSERT INTO customer_accounts (id,customer_type,account_balance) VALUES (1,'Premium',25000.00),(2,'Standard',15000.00),(3,'Premium',30000.00); | SELECT MAX(account_balance) FROM customer_accounts WHERE customer_type = 'Premium'; |
What is the percentage of sustainable urbanism initiatives in Rome? | CREATE TABLE initiatives (id INT,sustainable BOOLEAN,city VARCHAR(20)); INSERT INTO initiatives (id,sustainable,city) VALUES (1,TRUE,'Rome'),(2,TRUE,'Rome'),(3,FALSE,'Rome'); | SELECT 100.0 * COUNT(*) FILTER (WHERE sustainable = TRUE) / COUNT(*) FROM initiatives WHERE city = 'Rome'; |
Insert data into 'Teachers' table with values (1, 'Jamila Thompson', 'Math'), (2, 'Carlos Lee', 'Science') | CREATE TABLE Teachers (TeacherID INT,Name VARCHAR(100),Subject VARCHAR(50)); | INSERT INTO Teachers (TeacherID, Name, Subject) VALUES (1, 'Jamila Thompson', 'Math'), (2, 'Carlos Lee', 'Science'); |
What are the total CVE counts for each system in the 'vulnerabilities' table? | CREATE TABLE vulnerabilities (system_id INT,system_name VARCHAR(100),cve_count INT); INSERT INTO vulnerabilities (system_id,system_name,cve_count) VALUES (1,'Server01',20),(2,'Workstation01',15),(3,'Firewall01',5),(4,'Router01',12),(5,'Switch01',8),(6,'Printer01',3); | SELECT system_name, SUM(cve_count) as total_cve_count FROM vulnerabilities GROUP BY system_name; |
Determine the monthly sales growth of eco-friendly makeup products in the last year. | CREATE TABLE MakeupSales (ProductID INT,ProductType VARCHAR(20),IsEcoFriendly BOOLEAN,Revenue DECIMAL(10,2),SaleDate DATE); INSERT INTO MakeupSales (ProductID,ProductType,IsEcoFriendly,Revenue,SaleDate) VALUES (1,'Lipstick',TRUE,50.00,'2022-01-15'); INSERT INTO MakeupSales (ProductID,ProductType,IsEcoFriendly,Revenue,SaleDate) VALUES (2,'Eyeshadow',TRUE,75.00,'2022-02-20'); INSERT INTO MakeupSales (ProductID,ProductType,IsEcoFriendly,Revenue,SaleDate) VALUES (3,'Foundation',TRUE,60.00,'2022-03-05'); INSERT INTO MakeupSales (ProductID,ProductType,IsEcoFriendly,Revenue,SaleDate) VALUES (4,'Blush',TRUE,80.00,'2022-04-10'); | SELECT EXTRACT(MONTH FROM SaleDate) AS Month, AVG(Revenue) AS AverageRevenue, LAG(AVG(Revenue)) OVER (ORDER BY EXTRACT(MONTH FROM SaleDate)) AS PreviousMonthAverage FROM MakeupSales WHERE ProductType = 'Makeup' AND IsEcoFriendly = TRUE GROUP BY EXTRACT(MONTH FROM SaleDate) ORDER BY EXTRACT(MONTH FROM SaleDate); |
What is the average revenue per sustainable tourism activity in Southeast Asia? | CREATE TABLE tourism_activities(activity_id INT,name TEXT,location TEXT,revenue FLOAT); INSERT INTO tourism_activities (activity_id,name,location,revenue) VALUES (1,'Eco-Trekking','Indonesia',15000),(2,'Coral Reef Snorkeling','Philippines',20000),(3,'Cultural Cooking Class','Thailand',10000); | SELECT AVG(revenue) FROM tourism_activities WHERE location LIKE 'Southeast%' AND sustainable = TRUE; |
What is the total quantity of vegan ingredients in our inventory? | CREATE TABLE VeganIngredients (id INT,name VARCHAR(50),quantity INT); INSERT INTO VeganIngredients (id,name,quantity) VALUES (1,'Tofu',1000),(2,'Cashews',1500),(3,'Nutritional Yeast',800); | SELECT SUM(quantity) FROM VeganIngredients; |
Display the names of all garments that are made from sustainable materials and cost less than $50. | CREATE TABLE garment_materials (id INT,garment_name VARCHAR(255),material_name VARCHAR(255),production_cost DECIMAL(10,2)); | SELECT garment_name FROM garment_materials WHERE material_name IN (SELECT material_name FROM sustainable_materials) AND production_cost < 50; |
What are the unique job titles of users who have engaged with posts about social justice but have not applied to any jobs in the non-profit sector. | CREATE TABLE user_engagements (user_id INT,engagement_topic VARCHAR(50),job_title VARCHAR(50)); INSERT INTO user_engagements (user_id,engagement_topic,job_title) VALUES (1,'social justice','Human Rights Lawyer'),(2,'technology','Software Engineer'),(3,'social justice','Social Worker'),(4,'education','Teacher'),(5,'social justice','Community Organizer'),(6,'healthcare','Doctor'); | SELECT job_title FROM user_engagements WHERE engagement_topic = 'social justice' AND user_id NOT IN (SELECT user_id FROM user_engagements WHERE job_title LIKE '%non-profit%'); |
How many products in each category are not cruelty-free? | CREATE TABLE product_cruelty (product_id INTEGER,product_category VARCHAR(20),is_cruelty_free BOOLEAN); INSERT INTO product_cruelty (product_id,product_category,is_cruelty_free) VALUES (1,'Makeup',true),(2,'Makeup',false),(3,'Skincare',true),(4,'Skincare',false); | SELECT product_category, COUNT(*) FROM product_cruelty WHERE is_cruelty_free = false GROUP BY product_category; |
What is the total transaction amount for each day in January 2022, for transactions that occurred in the United States? | CREATE TABLE transactions (id INT,transaction_date DATE,country VARCHAR(255),amount DECIMAL(10,2)); INSERT INTO transactions (id,transaction_date,country,amount) VALUES (1,'2022-01-01','USA',100.00),(2,'2022-01-02','Canada',200.00),(3,'2022-01-03','USA',300.00); | SELECT transaction_date, SUM(amount) FROM transactions WHERE transaction_date BETWEEN '2022-01-01' AND '2022-01-31' AND country = 'USA' GROUP BY transaction_date; |
What is the maximum depth of all deep-sea expeditions in the Southern Ocean? | CREATE TABLE deep_sea_expeditions (expedition_name VARCHAR(255),depth FLOAT,ocean VARCHAR(255)); | SELECT MAX(depth) FROM deep_sea_expeditions WHERE ocean = 'Southern'; |
Which organizations have received grants for social impact assessment in the current year? | CREATE TABLE organizations (id INT,name VARCHAR(50),type VARCHAR(30)); CREATE TABLE grants (id INT,org_id INT,amount INT,date DATE,purpose VARCHAR(30)); INSERT INTO organizations (id,name,type) VALUES (1,'ABC Nonprofit','social impact assessment'),(2,'DEF Nonprofit','capacity building'),(3,'GHI Nonprofit','fundraising'); INSERT INTO grants (id,org_id,amount,date,purpose) VALUES (1,1,10000,'2023-03-01','social impact assessment'),(2,2,5000,'2022-12-15','program delivery'),(3,3,7500,'2023-02-05','fundraising'); INSERT INTO grants (id,org_id,amount,date,purpose) VALUES (4,1,15000,'2023-06-15','social impact assessment'); | SELECT organizations.name FROM organizations INNER JOIN grants ON organizations.id = grants.org_id WHERE YEAR(grants.date) = YEAR(GETDATE()) AND organizations.type = 'social impact assessment'; |
Add a new autonomous bus to the public transportation fleet in Rio de Janeiro. | CREATE TABLE public_transportation (transport_id INT,type VARCHAR(20),city VARCHAR(20)); INSERT INTO public_transportation (transport_id,type,city) VALUES (1,'Bus','Rio de Janeiro'),(2,'Tram','Rio de Janeiro'),(3,'Train','Rio de Janeiro'); | INSERT INTO public_transportation (transport_id, type, city) VALUES (4, 'Autonomous Bus', 'Rio de Janeiro'); |
What is the minimum number of workshops attended by a teacher in 'Summer 2023'? | CREATE TABLE teacher_pd (teacher_id INT,workshop_name VARCHAR(255),date DATE); INSERT INTO teacher_pd (teacher_id,workshop_name,date) VALUES (1,'Open Pedagogy','2023-06-01'); CREATE VIEW summer_2023_pd AS SELECT teacher_id,COUNT(*) as num_workshops FROM teacher_pd WHERE date BETWEEN '2023-06-01' AND '2023-08-31' GROUP BY teacher_id; | SELECT MIN(num_workshops) as min_workshops FROM summer_2023_pd; |
What is the number of art pieces created by male and female artists in each medium? | CREATE SCHEMA art; CREATE TABLE art_pieces (art_id INT,art_name VARCHAR(255),artist_name VARCHAR(255),artist_gender VARCHAR(10),medium VARCHAR(50),creation_date DATE); INSERT INTO art.art_pieces (art_id,art_name,artist_name,artist_gender,medium,creation_date) VALUES (1,'Painting','Sarah Johnson','Female','Oil','2018-01-01'),(2,'Sculpture','Mia Kim','Female','Bronze','2019-05-15'),(3,'Print','Jamie Lee','Female','Woodcut','2020-12-31'),(4,'Installation','David Park','Male','Mixed Media','2020-06-01'),(5,'Painting','David Park','Male','Watercolor','2019-12-31'); | SELECT medium, artist_gender, COUNT(*) as count FROM art.art_pieces GROUP BY medium, artist_gender; |
Delete artists who have never held a concert. | CREATE TABLE artists (artist_id INT,name VARCHAR(100),genre VARCHAR(50)); CREATE TABLE concert_artists (concert_id INT,artist_id INT); INSERT INTO artists (artist_id,name,genre) VALUES (101,'Taylor Swift','Pop'),(102,'Billie Eilish','Pop'),(103,'The Weeknd','R&B'); INSERT INTO concert_artists (concert_id,artist_id) VALUES (1,101),(2,102),(3,101); | DELETE FROM artists WHERE artist_id NOT IN (SELECT artist_id FROM concert_artists); |
What was the maximum production of Praseodymium in 2018? | CREATE TABLE production (year INT,element VARCHAR(10),quantity INT); INSERT INTO production (year,element,quantity) VALUES (2015,'Praseodymium',1200),(2016,'Praseodymium',1400),(2017,'Praseodymium',1500),(2018,'Praseodymium',1700),(2019,'Praseodymium',1800),(2020,'Praseodymium',2000),(2021,'Praseodymium',2200); | SELECT MAX(quantity) FROM production WHERE element = 'Praseodymium' AND year = 2018; |
What is the percentage of total orders for each category in the past month? | CREATE TABLE menu (menu_id INT,item_name VARCHAR(255),category VARCHAR(255),price DECIMAL(5,2),inventory_count INT,last_updated TIMESTAMP);CREATE TABLE orders (order_id INT,menu_id INT,order_date TIMESTAMP,quantity INT,PRIMARY KEY (order_id),FOREIGN KEY (menu_id) REFERENCES menu(menu_id)); | SELECT category, SUM(quantity) as total_orders, 100.0 * SUM(quantity) / (SELECT SUM(quantity) FROM orders WHERE order_date >= CURRENT_DATE - INTERVAL '1 month') as percentage_of_total FROM orders JOIN menu ON orders.menu_id = menu.menu_id WHERE order_date >= CURRENT_DATE - INTERVAL '1 month' GROUP BY category; |
What is the economic diversification impact of community development initiatives in Africa in 2020? | CREATE TABLE initiative (id INT,name TEXT,location TEXT,economic_diversification_impact INT,year INT); INSERT INTO initiative (id,name,location,economic_diversification_impact,year) VALUES (1,'Handicraft Training','Egypt',50,2017),(2,'Agricultural Training','Nigeria',70,2018),(3,'IT Training','Kenya',90,2019),(4,'Fishery Training','South Africa',60,2020); | SELECT economic_diversification_impact FROM initiative WHERE location LIKE 'Africa%' AND year = 2020; |
Find the number of vegetarian and non-vegetarian dishes in the menu | CREATE TABLE Menu (dish_id INT,dish_name VARCHAR(100),dish_type VARCHAR(20)); INSERT INTO Menu (dish_id,dish_name,dish_type) VALUES (1,'Quinoa Salad','Vegetarian'); INSERT INTO Menu (dish_id,dish_name,dish_type) VALUES (2,'Grilled Chicken','Non-Vegetarian'); | SELECT SUM(CASE WHEN dish_type = 'Vegetarian' THEN 1 ELSE 0 END) AS vegetarian_dishes, SUM(CASE WHEN dish_type = 'Non-Vegetarian' THEN 1 ELSE 0 END) AS non_vegetarian_dishes FROM Menu; |
Show all military technology and their respective development costs from the 'MilitaryTech' table | CREATE TABLE MilitaryTech (Tech_Name VARCHAR(255),Tech_Type VARCHAR(255),Development_Cost INT,Fiscal_Year INT); INSERT INTO MilitaryTech (Tech_Name,Tech_Type,Development_Cost,Fiscal_Year) VALUES ('F-35 Fighter Jet','Aircraft',100000000,2020); INSERT INTO MilitaryTech (Tech_Name,Tech_Type,Development_Cost,Fiscal_Year) VALUES ('Zumwalt-Class Destroyer','Ship',7000000000,2015); | SELECT * FROM MilitaryTech; |
What percentage of each fabric type is used in textile sourcing? | CREATE TABLE Fabric_Types (fabric_type VARCHAR(255),usage_percentage DECIMAL(5,2)); INSERT INTO Fabric_Types (fabric_type,usage_percentage) VALUES ('Cotton',50.00),('Polyester',30.00),('Wool',10.00),('Silk',5.00),('Linen',5.00); | SELECT fabric_type, usage_percentage FROM Fabric_Types; |
Find the maximum explainability score for AI models in the 'ai_models' table. | CREATE TABLE ai_models (model_id INT,model_name TEXT,explainability_score FLOAT); | SELECT MAX(explainability_score) FROM ai_models; |
How many public bike-sharing users are there in Seoul? | CREATE TABLE bike_sharing (id INT,city VARCHAR(50),users INT); INSERT INTO bike_sharing (id,city,users) VALUES (1,'Seoul',500000),(2,'NYC',300000),(3,'Barcelona',200000); | SELECT users FROM bike_sharing WHERE city = 'Seoul'; |
How many unique donors are there for each category? | CREATE TABLE donations (id INT,donor_id INT,category VARCHAR(255),amount DECIMAL(10,2)); INSERT INTO donations (id,donor_id,category,amount) VALUES (1,1,'healthcare',1000),(2,1,'education',2000),(3,2,'healthcare',500),(4,2,'healthcare',1500),(5,3,'education',3000); | SELECT category, COUNT(DISTINCT donor_id) AS unique_donors FROM donations GROUP BY category; |
Find properties that have been co-owned for more than 5 years, and their respective average sizes. | CREATE TABLE Properties(id INT,size FLOAT,city VARCHAR(20),coown INT);INSERT INTO Properties(id,size,city,coown) VALUES (1,1200,'Seattle',2003),(2,1500,'Seattle',2010),(3,1000,'Portland',2015),(4,2000,'SanFrancisco',2005),(5,1000,'Austin',2020),(6,1200,'Seattle',2008); | SELECT a.coown, AVG(a.size) FROM Properties a WHERE a.coown < 2021 GROUP BY a.coown; |
Which organizations have researchers specialized in both climate change and biodiversity with at least 15 publications? | CREATE TABLE Researchers (id INT,name VARCHAR(100),organization VARCHAR(100),expertise VARCHAR(100),publications INT); INSERT INTO Researchers (id,name,organization,expertise,publications) VALUES (1,'Jane Doe','Polar Research Institute','Climate Change',20); INSERT INTO Researchers (id,name,organization,expertise,publications) VALUES (2,'Jim Brown','Polar Research Institute','Biodiversity',18); INSERT INTO Researchers (id,name,organization,expertise,publications) VALUES (3,'Alex Smith','Arctic Biodiversity Center','Climate Change',16); INSERT INTO Researchers (id,name,organization,expertise,publications) VALUES (4,'Jessica Johnson','Arctic Biodiversity Center','Biodiversity',22); | SELECT DISTINCT organization FROM Researchers WHERE (expertise = 'Climate Change' AND expertise = 'Biodiversity' AND publications >= 15) |
List the top 3 industries in the UK with the highest workplace safety incident rates in the past year, in descending order. | CREATE TABLE incident_rates (id INT,industry TEXT,country TEXT,incident_count INT,total_workplaces INT); INSERT INTO incident_rates (id,industry,country,incident_count,total_workplaces) VALUES (1,'Technology','UK',100,1000),(2,'Manufacturing','UK',200,2000),(3,'Retail','UK',150,1500); | SELECT industry, SUM(incident_count) as total_incidents FROM incident_rates WHERE country = 'UK' GROUP BY industry ORDER BY total_incidents DESC LIMIT 3; |
Determine the hospital with the highest number of beds per state, and display the hospital name and the difference between the highest and second highest number of beds. | CREATE TABLE hospitals (state varchar(2),hospital_name varchar(25),num_beds int); INSERT INTO hospitals (state,hospital_name,num_beds) VALUES ('NY','NY Presbyterian',2001),('CA','UCLA Medical',3012),('TX','MD Anderson',1543),('FL','Mayo Clinic FL',2209); | SELECT hospital_name as highest_bed_hospital, MAX(num_beds) - LEAD(MAX(num_beds)) OVER (ORDER BY MAX(num_beds) DESC) as bed_difference FROM hospitals GROUP BY state HAVING MAX(num_beds) > LEAD(MAX(num_beds)) OVER (ORDER BY MAX(num_beds) DESC); |
What is the total amount of grants awarded by gender? | CREATE TABLE grant (id INT,year INT,amount DECIMAL(10,2)); CREATE TABLE student (id INT,gender VARCHAR(10)); INSERT INTO grant (id,year,amount) VALUES (1,2019,50000),(2,2020,75000),(3,2019,30000); INSERT INTO student (id,gender) VALUES (1,'Female'),(2,'Male'),(3,'Female'); | SELECT student.gender, SUM(grant.amount) as total_grant_amount FROM grant CROSS JOIN student GROUP BY student.gender; |
What is the average length of hospital stays for patients with eating disorders? | CREATE TABLE stays (id INT,patient_id INT,length INT,condition TEXT); CREATE TABLE conditions (id INT,name TEXT); INSERT INTO conditions (id,name) VALUES (1,'Eating Disorder'); | SELECT AVG(length) FROM stays WHERE condition = 'Eating Disorder'; |
List all heritage sites along with their community engagement scores. | CREATE TABLE heritage_sites(id INT,site_name TEXT,community_engagement FLOAT); INSERT INTO heritage_sites VALUES (1,'Mesa Verde National Park',4.2),(2,'Yosemite National Park',3.8); | SELECT site_name, community_engagement FROM heritage_sites; |
What is the percentage of articles about media representation, published by news outlets based in the USA? | CREATE TABLE articles (id INT,title VARCHAR(255),content TEXT,topic VARCHAR(255),publisher_country VARCHAR(255)); | SELECT (COUNT(*) FILTER (WHERE topic = 'media representation' AND publisher_country = 'USA')) * 100.0 / COUNT(*) FROM articles; |
List all Solar Projects in the United States with a capacity over 50 MW | CREATE TABLE solar_projects (id INT,name VARCHAR(100),country VARCHAR(50),capacity_mw FLOAT); INSERT INTO solar_projects (id,name,country,capacity_mw) VALUES (1,'Solar Project 1','USA',75.6),(2,'Solar Project 2','USA',40.2); | SELECT * FROM solar_projects WHERE country = 'USA' AND capacity_mw > 50; |
Find the species names and their respective populations, ordered alphabetically, in the 'Research' schema's 'Species' table | CREATE TABLE Research.Species (id INT,species_name VARCHAR(255),population INT); | SELECT species_name, population FROM Research.Species ORDER BY species_name ASC; |
List all members who joined the 'fair_labor_practices' union in 2021. | CREATE TABLE fair_labor_practices (member_id INT,name VARCHAR(50),union_joined_date DATE); INSERT INTO fair_labor_practices (member_id,name,union_joined_date) VALUES (32,'Mason Green','2021-03-01'),(33,'Olivia Baker','2021-06-15'),(34,'Nathan Robinson','2021-08-28'); | SELECT * FROM fair_labor_practices WHERE YEAR(union_joined_date) = 2021; |
List all menu items with a sustainability_rating of 5 | CREATE TABLE menu_items (menu_item_id INT,name VARCHAR(255),description TEXT,price DECIMAL(5,2),category VARCHAR(255),sustainability_rating INT); | SELECT * FROM menu_items WHERE sustainability_rating = 5; |
What is the total cargo weight transported by vessels with a compliance score above 80 in the Atlantic Ocean in Q1 2021? | CREATE TABLE vessels (id INT,name TEXT,type TEXT,compliance_score INT);CREATE TABLE cargos (id INT,vessel_id INT,weight FLOAT,destination TEXT,date DATE); INSERT INTO vessels (id,name,type,compliance_score) VALUES (1,'VesselD','Container',85); INSERT INTO cargos (id,vessel_id,weight,destination,date) VALUES (1,1,10000,'Atlantic','2021-01-01'); | SELECT SUM(c.weight) FROM vessels v JOIN cargos c ON v.id = c.vessel_id WHERE v.compliance_score > 80 AND c.destination LIKE 'Atlantic%' AND c.date BETWEEN '2021-01-01' AND '2021-03-31'; |
What is the progression of professional development workshops attended by a randomly selected teacher, in the last 6 months? | CREATE TABLE teacher_workshops (teacher_id INT,workshop_id INT,enrollment_date DATE); INSERT INTO teacher_workshops VALUES (1,1001,'2022-03-01'),(1,1002,'2022-04-01'); CREATE TABLE workshops (workshop_id INT,workshop_name VARCHAR(50)); INSERT INTO workshops VALUES (1001,'Tech Tools'),(1002,'Diverse Classrooms'); | SELECT teacher_id, workshop_id, LEAD(enrollment_date, 1) OVER (PARTITION BY teacher_id ORDER BY enrollment_date) as next_workshop_date FROM teacher_workshops JOIN workshops ON teacher_workshops.workshop_id = workshops.workshop_id WHERE teacher_id = 1 AND enrollment_date >= DATEADD(month, -6, GETDATE()); |
What is the distribution of food safety inspection scores for restaurants in Canada? | CREATE TABLE RestaurantInspections (restaurant_id INT,inspection_score INT,country VARCHAR(50)); INSERT INTO RestaurantInspections (restaurant_id,inspection_score,country) VALUES (1,95,'Canada'),(2,85,'Canada'),(3,90,'Canada'),(4,80,'Canada'),(5,92,'Canada'); | SELECT inspection_score, COUNT(*) AS count FROM RestaurantInspections WHERE country = 'Canada' GROUP BY inspection_score; |
List the biosensors developed for a specific disease category. | CREATE SCHEMA if not exists biosensor;CREATE TABLE if not exists biosensor.sensors(id INT,name TEXT,disease_category TEXT);INSERT INTO biosensor.sensors (id,name,disease_category) VALUES (1,'BiosensorA','Cancer'),(2,'BiosensorB','Heart Disease'),(3,'BiosensorC','Cancer'),(4,'BiosensorD','Neurological Disorders'); | SELECT * FROM biosensor.sensors WHERE disease_category = 'Cancer'; |
How many virtual tours were conducted in 'South America'? | CREATE TABLE virtual_tour_count (tour_id INT,city TEXT,region TEXT,tour_date DATE); INSERT INTO virtual_tour_count (tour_id,city,region,tour_date) VALUES (1,'CityN','South America','2022-01-01'),(2,'CityO','South America','2022-01-02'),(3,'CityP','South America','2022-01-03'); | SELECT COUNT(*) FROM virtual_tour_count WHERE region = 'South America'; |
Find the client's first and last name, state, and the difference between the case closing date and the case opening date, for cases with an outcome of 'won', partitioned by state and ordered by the difference in ascending order. | CREATE TABLE Cases (CaseID INT,ClientFirstName VARCHAR(50),ClientLastName VARCHAR(50),State VARCHAR(2),CaseOutcome VARCHAR(20),OpenDate DATE,CloseDate DATE); INSERT INTO Cases (CaseID,ClientFirstName,ClientLastName,State,CaseOutcome,OpenDate,CloseDate) VALUES (1,'John','Doe','NY','won','2020-01-01','2020-06-01'),(2,'Jane','Smith','CA','won','2019-01-01','2019-12-31'),(3,'Mike','Johnson','NY','lost','2021-01-01','2021-06-01'); | SELECT State, ClientFirstName, ClientLastName, DATEDIFF(CloseDate, OpenDate) AS DaysOpen FROM Cases WHERE CaseOutcome = 'won' ORDER BY State, DaysOpen; |
Insert a new record into the marine_life table for the 'Shark' species with a population of 1000 in the indian_ocean region. | CREATE TABLE marine_life (id INT,species VARCHAR(255),population INT,region VARCHAR(255)); | INSERT INTO marine_life (id, species, population, region) VALUES ((SELECT COALESCE(MAX(id), 0) + 1 FROM marine_life), 'Shark', 1000, 'indian_ocean'); |
How many students in the mental health program have had more than 3 absences in the past month? | CREATE TABLE students (id INT,name VARCHAR(50),program VARCHAR(50),absences INT,last_visit DATE); | SELECT COUNT(*) FROM students WHERE program = 'mental health' AND absences > 3 AND last_visit >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH); |
What is the total number of veteran hires in the defense industry in the last quarter? | CREATE TABLE veteran_hires (id INT,hire_number VARCHAR(255),industry VARCHAR(255),date DATE); | SELECT SUM(*) FROM veteran_hires WHERE industry = 'defense' AND date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH); |
What is the total annual production of Praseodymium for companies in the APAC region, for each year? | CREATE TABLE companies (id INT,name TEXT,region TEXT); INSERT INTO companies (id,name,region) VALUES (1,'CompanyI','APAC'),(2,'CompanyJ','EMEA'); CREATE TABLE production (year INT,element TEXT,company_id INT,quantity INT); INSERT INTO production (year,element,company_id,quantity) VALUES (2018,'Praseodymium',1,200),(2018,'Praseodymium',2,300),(2019,'Praseodymium',1,400),(2019,'Praseodymium',2,500),(2020,'Praseodymium',1,600),(2020,'Praseodymium',2,700); | SELECT production.year, SUM(quantity) as total_quantity FROM production JOIN companies ON production.company_id = companies.id WHERE production.element = 'Praseodymium' AND companies.region = 'APAC' GROUP BY production.year; |
What are the total sales of digital albums for each artist in the Pop genre? | CREATE TABLE genres (genre_id INT,genre VARCHAR(50)); CREATE TABLE albums (album_id INT,genre_id INT,title VARCHAR(100),price DECIMAL(5,2),sales INT); | SELECT a.artist, SUM(a.sales) AS total_sales FROM albums al JOIN (SELECT artist_id, artist FROM artists WHERE artists.genre = 'Pop') a ON al.album_id = a.artist_id GROUP BY a.artist; |
Find the total production of Cerium in 2019 and 2020 from the Mineral_Production_4 table? | CREATE TABLE Mineral_Production_4 (year INT,cerium_production FLOAT); | SELECT SUM(cerium_production) FROM Mineral_Production_4 WHERE year IN (2019, 2020); |
What is the average life expectancy in Africa by country? | CREATE TABLE Countries (Country VARCHAR(50),Continent VARCHAR(50),Life_Expectancy FLOAT); INSERT INTO Countries (Country,Continent,Life_Expectancy) VALUES ('Algeria','Africa',76.29),('Angola','Africa',60.79); | SELECT Continent, AVG(Life_Expectancy) FROM Countries WHERE Continent = 'Africa' GROUP BY Continent; |
What is the minimum biomass of any whale species in the Arctic Ocean? | CREATE TABLE whale_biomass (species TEXT,location TEXT,biomass INTEGER); INSERT INTO whale_biomass (species,location,biomass) VALUES ('Blue Whale','Arctic',200000),('Humpback Whale','Arctic',70000),('Sperm Whale','Arctic',300000),('Beluga Whale','Arctic',60000); | SELECT MIN(biomass) FROM whale_biomass WHERE location = 'Arctic'; |
How many unique genres are there in the database? | CREATE TABLE movies (title VARCHAR(255),genre VARCHAR(50)); INSERT INTO movies (title,genre) VALUES ('Movie1','Action'),('Movie2','Drama'),('Movie3','Comedy'),('Movie4','Action'),('Movie5','Drama'),('Movie6','Sci-Fi'); | SELECT COUNT(DISTINCT genre) FROM movies; |
Update the 'game_reviews' table to set the 'rating' column as 5 for the game 'Game1' in the 'Europe' region | CREATE TABLE game_reviews (review_id INT,player_id INT,game_name VARCHAR(100),rating INT,region VARCHAR(50),date DATE); | UPDATE game_reviews SET rating = 5 WHERE game_name = 'Game1' AND region = 'Europe'; |
Which artist has the most songs in the songs table? | CREATE TABLE songs (id INT,title VARCHAR(255),artist VARCHAR(255)); INSERT INTO songs (id,title,artist) VALUES (1,'Song 1','Artist A'); | SELECT artist, COUNT(*) as song_count FROM songs GROUP BY artist ORDER BY song_count DESC LIMIT 1; |
Identify the recycling rates for 'Asia-Pacific' in 2019, for each material type, and show the overall recycling rate. | CREATE TABLE recycling_rates (region VARCHAR(10),year INT,material_type VARCHAR(20),recycling_rate DECIMAL(5,2)); INSERT INTO recycling_rates (region,year,material_type,recycling_rate) VALUES ('Asia-Pacific',2019,'Plastic',0.35),('Asia-Pacific',2019,'Paper',0.60),('Asia-Pacific',2019,'Glass',0.45); | SELECT material_type, AVG(recycling_rate) AS avg_recycling_rate FROM recycling_rates WHERE region = 'Asia-Pacific' AND year = 2019 GROUP BY material_type; |
What is the total donation amount per program in the last year? | CREATE TABLE donations (id INT,program TEXT,donation_amount DECIMAL(10,2),donation_date DATE); INSERT INTO donations VALUES (1,'Education',200.00,'2021-01-01'),(2,'Healthcare',300.00,'2021-02-01'),(3,'Environment',400.00,'2020-12-01'); | SELECT program, SUM(donation_amount) FROM donations WHERE donation_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY program; |
What are the top 5 zip codes with the most construction labor hours in Texas in 2019? | CREATE TABLE labor_hours (zip VARCHAR(5),state VARCHAR(2),year INT,hours INT); INSERT INTO labor_hours (zip,state,year,hours) VALUES ('75201','TX',2019,5000); | SELECT zip, SUM(hours) FROM labor_hours WHERE state = 'TX' AND year = 2019 GROUP BY zip ORDER BY SUM(hours) DESC LIMIT 5; |
What is the total playtime of all players who have played the game "Galactic Guardians" for more than 3 hours in the past week? | CREATE TABLE playtime (id INT,player_id INT,game VARCHAR(50),playtime FLOAT); INSERT INTO playtime VALUES (1,1,'Galactic Guardians',180.5); INSERT INTO playtime VALUES (2,2,'Galactic Guardians',240.75); | SELECT SUM(playtime) FROM playtime WHERE game = 'Galactic Guardians' AND playtime > 3 * 60; |
What is the average daily energy production (in MWh) for each wind farm in the month of January 2021? | CREATE TABLE wind_farms (name VARCHAR(50),location VARCHAR(50),capacity FLOAT,primary key (name)); INSERT INTO wind_farms (name,location,capacity) VALUES ('Farm A','California',100),('Farm B','Texas',150),('Farm C','Oregon',200); CREATE TABLE production (wind_farm VARCHAR(50),date DATE,energy_production FLOAT,primary key (wind_farm,date),foreign key (wind_farm) references wind_farms(name)); INSERT INTO production (wind_farm,date,energy_production) VALUES ('Farm A','2021-01-01',2500),('Farm A','2021-01-02',2400),('Farm B','2021-01-01',3500),('Farm B','2021-01-02',3700),('Farm C','2021-01-01',4500),('Farm C','2021-01-02',4300); | SELECT wind_farm, AVG(energy_production) as avg_daily_production FROM production WHERE date BETWEEN '2021-01-01' AND '2021-01-31' GROUP BY wind_farm, EXTRACT(MONTH FROM date), EXTRACT(YEAR FROM date) |
What is the average size of customers who purchased jackets in India? | CREATE TABLE CustomerData2 (id INT,customer_id INT,product VARCHAR(20),size INT,country VARCHAR(10)); INSERT INTO CustomerData2 (id,customer_id,product,size,country) VALUES (1,2001,'jacket',14,'India'),(2,2002,'shirt',12,'Australia'); | SELECT AVG(size) FROM CustomerData2 WHERE product = 'jacket' AND country = 'India'; |
Find the total sales revenue for each dish type in the last 30 days | CREATE TABLE sales_data (sale_id INT,dish_id INT,sale_date DATE,revenue DECIMAL(10,2)); INSERT INTO sales_data (sale_id,dish_id,sale_date,revenue) VALUES (1,1,'2022-01-01',15.99),(2,2,'2022-01-01',7.99),(3,1,'2022-01-02',12.99),(4,3,'2022-01-02',6.99),(5,1,'2022-01-16',10.99),(6,4,'2022-01-17',9.99); CREATE TABLE menu (dish_id INT,dish_name VARCHAR(255),dish_type VARCHAR(255)); INSERT INTO menu (dish_id,dish_name,dish_type) VALUES (1,'Quinoa Salad','Vegetarian'),(2,'Chicken Sandwich','Non-Vegetarian'),(3,'Pumpkin Soup','Vegetarian'),(4,'Beef Stew','Non-Vegetarian'); | SELECT m.dish_type, SUM(s.revenue) AS total_revenue FROM sales_data s JOIN menu m ON s.dish_id = m.dish_id WHERE s.sale_date >= DATE_SUB(CURDATE(), INTERVAL 30 DAY) GROUP BY m.dish_type; |
Find the top 3 chemical compounds with the highest innovation scores in South Korea. | CREATE TABLE chemical_compounds (compound_id INT,compound_name VARCHAR(50),country VARCHAR(50),innovation_score DECIMAL(5,2)); INSERT INTO chemical_compounds (compound_id,compound_name,country,innovation_score) VALUES (1,'Compound A','South Korea',92.3),(2,'Compound B','South Korea',87.6),(3,'Compound C','USA',78.9); | SELECT * FROM (SELECT compound_id, compound_name, innovation_score, ROW_NUMBER() OVER (ORDER BY innovation_score DESC) as rn FROM chemical_compounds WHERE country = 'South Korea') tmp WHERE rn <= 3; |
Which vessels have traveled to the port of Santos, Brazil in the last year? | CREATE TABLE vessels (id INT,name TEXT,last_port TEXT,last_port_date DATE); INSERT INTO vessels (id,name,last_port,last_port_date) VALUES (1,'VesselX','Santos','2022-02-12'); INSERT INTO vessels (id,name,last_port,last_port_date) VALUES (2,'VesselY','Rio de Janeiro','2022-01-28'); INSERT INTO vessels (id,name,last_port,last_port_date) VALUES (3,'VesselZ','Santos','2021-12-30'); | SELECT DISTINCT name FROM vessels WHERE last_port = 'Santos' AND last_port_date >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR); |
What is the minimum price of properties in the table 'inclusive_housing' that have wheelchair accessibility? | CREATE TABLE inclusive_housing (id INT,price FLOAT,wheelchair_accessible BOOLEAN); INSERT INTO inclusive_housing (id,price,wheelchair_accessible) VALUES (1,400000,true),(2,500000,false),(3,600000,true); | SELECT MIN(price) FROM inclusive_housing WHERE wheelchair_accessible = true; |
How many songs were added to Deezer's Latin music library in the last month? | CREATE TABLE DeezerSongs (SongID INT,AddedDate DATE,Genre VARCHAR(50)); INSERT INTO DeezerSongs (SongID,AddedDate,Genre) VALUES (1,'2022-02-15','Latin'),(2,'2022-02-16','Pop'); | SELECT COUNT(*) FROM DeezerSongs WHERE AddedDate >= DATEADD(MONTH, -1, GETDATE()) AND Genre = 'Latin'; |
Delete the animal record for the Komodo Dragon in the 'animals' table | CREATE TABLE animals (id INT PRIMARY KEY,name VARCHAR(50),species VARCHAR(50),population INT,habitat_status VARCHAR(50)); | DELETE FROM animals WHERE name = 'Komodo Dragon'; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.