instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
How many volunteers are needed for each program in the second half of 2021? | CREATE TABLE Programs (ProgramID int,ProgramName varchar(50)); CREATE TABLE VolunteerRequirements (RequirementID int,ProgramID int,RequiredVolunteers numeric,RequirementDate date); | SELECT ProgramName, SUM(RequiredVolunteers) as TotalVolunteers FROM Programs P JOIN VolunteerRequirements VR ON P.ProgramID = VR.ProgramID WHERE MONTH(RequirementDate) > 6 AND YEAR(RequirementDate) = 2021 GROUP BY ProgramName; |
Find countries with no sustainable seafood certifications. | CREATE TABLE seafood_certifications (id INT,country VARCHAR(50),certification VARCHAR(50)); INSERT INTO seafood_certifications (id,country,certification) VALUES (1,'Norway','MSC'),(2,'Norway','ASC'),(3,'Canada','MSC'); | SELECT country FROM seafood_certifications GROUP BY country HAVING COUNT(DISTINCT certification) = 0; |
What is the average salary of engineers in 'asia_mines'? | CREATE SCHEMA if not exists asia_schema;CREATE TABLE asia_schema.asia_mines (id INT,name VARCHAR,role VARCHAR,salary DECIMAL);INSERT INTO asia_schema.asia_mines (id,name,role,salary) VALUES (1,'A worker','Engineer',65000.00),(2,'B engineer','Engineer',72000.00); | SELECT AVG(salary) FROM asia_schema.asia_mines WHERE role = 'Engineer'; |
What is the average CO2 emission per MWh for each country, sorted by the highest average emission? | CREATE TABLE country (name VARCHAR(50),co2_emission_mwh DECIMAL(5,2)); INSERT INTO country (name,co2_emission_mwh) VALUES ('Canada',230.5),('United States',470.1),('Germany',320.9); | SELECT name, AVG(co2_emission_mwh) OVER (PARTITION BY name) AS avg_emission FROM country ORDER BY avg_emission DESC; |
What is the total revenue generated from VIP ticket sales for basketball games in the Southeast region? | CREATE TABLE tickets (ticket_id INT,game_id INT,region VARCHAR(50),quantity INT,price DECIMAL(5,2)); INSERT INTO tickets (ticket_id,game_id,region,quantity,price) VALUES (1,1,'Southeast',100,100.00); INSERT INTO tickets (ticket_id,game_id,region,quantity,price) VALUES (2,2,'Northeast',150,75.00); CREATE TABLE games (game_id INT,sport VARCHAR(50),vip BOOLEAN); INSERT INTO games (game_id,sport,vip) VALUES (1,'Basketball',TRUE); INSERT INTO games (game_id,sport,vip) VALUES (2,'Football',FALSE); | SELECT SUM(quantity * price) FROM tickets INNER JOIN games ON tickets.game_id = games.game_id WHERE region = 'Southeast' AND sport = 'Basketball' AND vip = TRUE; |
List all countries and the number of satellites they have in orbit, ordered by the number of satellites in descending order. | CREATE TABLE countries (id INT,name VARCHAR(50)); CREATE TABLE satellites (id INT,country_id INT,name VARCHAR(50)); | SELECT c.name, COUNT(s.id) as num_satellites FROM countries c JOIN satellites s ON c.id = s.country_id GROUP BY c.name ORDER BY num_satellites DESC; |
Show dishes added to the menu in the last month | CREATE TABLE dishes (dish_id INT,dish_name VARCHAR(255),added_date DATE); INSERT INTO dishes (dish_id,dish_name,added_date) VALUES (1,'Margherita Pizza','2022-01-01'),(2,'Chicken Alfredo','2022-01-01'),(3,'Caesar Salad','2021-12-25'),(4,'Garden Burger','2022-01-15'),(5,'Spaghetti Bolognese','2021-11-01'); | SELECT dish_id, dish_name, added_date FROM dishes WHERE added_date BETWEEN DATE_SUB(NOW(), INTERVAL 1 MONTH) AND NOW(); |
What is the maximum water leak volume by city, location, and month? | CREATE TABLE water_leak_2 (id INT,city VARCHAR(255),location VARCHAR(255),leak_volume FLOAT,leak_date DATE); INSERT INTO water_leak_2 (id,city,location,leak_volume,leak_date) VALUES (1,'Miami','North',800,'2022-03-01'); INSERT INTO water_leak_2 (id,city,location,leak_volume,leak_date) VALUES (2,'Chicago','South',1000,'2022-04-01'); | SELECT city, location, MAX(leak_volume) FROM water_leak_2 GROUP BY city, location, DATE_FORMAT(leak_date, '%Y-%m'); |
List all clients who have paid exactly $4000 in total billing amount? | CREATE TABLE clients (client_id INT,name VARCHAR(50)); CREATE TABLE cases (case_id INT,client_id INT,billing_amount DECIMAL(10,2)); INSERT INTO clients (client_id,name) VALUES (1,'Smith'),(2,'Johnson'),(3,'Williams'),(4,'Brown'); INSERT INTO cases (case_id,client_id,billing_amount) VALUES (1,1,3000.00),(2,2,6000.00),(3,3,7000.00),(4,4,4000.00); | SELECT clients.name FROM clients INNER JOIN cases ON clients.client_id = cases.client_id GROUP BY clients.name HAVING SUM(billing_amount) = 4000; |
What is the total word count of articles written by each author? | CREATE TABLE authors (id INT,name TEXT); CREATE TABLE articles (id INT,title TEXT,content TEXT,author_id INT); INSERT INTO authors (id,name) VALUES (1,'John Doe'),(2,'Jane Smith'); INSERT INTO articles (id,title,content,author_id) VALUES (1,'Article 1','Content 1',1),(2,'Article 2','Content 2',2); | SELECT authors.name, SUM(LENGTH(articles.content) - LENGTH(REPLACE(articles.content, ' ', '')) + 1) as total_word_count FROM authors INNER JOIN articles ON authors.id = articles.author_id GROUP BY authors.name; |
Update the price of 'Blue Dream' strain in 'inventory' table by $100. | CREATE TABLE inventory (id INT,strain VARCHAR(255),price FLOAT,quantity INT); | UPDATE inventory SET price = price + 100 WHERE strain = 'Blue Dream'; |
Delete the record for 'Ammonia' in the "chemicals" table | CREATE TABLE chemicals (id INT PRIMARY KEY,chemical_name VARCHAR(255),formula VARCHAR(255),hazard_level INT); INSERT INTO chemicals (id,chemical_name,formula,hazard_level) VALUES (1,'Ammonia','NH3',2); | DELETE FROM chemicals WHERE chemical_name = 'Ammonia'; |
Delete an artist | CREATE TABLE Artists (ArtistID INT,Name VARCHAR(100),Nationality VARCHAR(50),BirthYear INT,DeathYear INT); | DELETE FROM Artists WHERE ArtistID = 1 AND Name = 'Leonardo da Vinci'; |
What are the total CO2 emissions for each mining method? | CREATE TABLE mining_methods (method_id INT,method_name VARCHAR(50),CO2_emissions FLOAT); INSERT INTO mining_methods (method_id,method_name,CO2_emissions) VALUES (1,'Open Pit',1.25),(2,'Underground',0.75),(3,'Placer',0.5); | SELECT method_name, SUM(CO2_emissions) FROM mining_methods GROUP BY method_name; |
What is the health equity metric trend for the past year? | CREATE TABLE health_equity_metrics (date DATE,metric FLOAT); INSERT INTO health_equity_metrics (date,metric) VALUES ('2021-01-01',78.5),('2021-02-01',79.2),('2021-03-01',80.1),('2021-04-01',81.0),('2021-05-01',81.5),('2021-06-01',82.0),('2021-07-01',82.5),('2021-08-01',82.8),('2021-09-01',83.1),('2021-10-01',83.4),('2021-11-01',83.7),('2021-12-01',84.0); | SELECT date, metric FROM health_equity_metrics ORDER BY date; |
What is the total energy consumption per machine per day? | create table EnergyData (Machine varchar(255),Energy int,Timestamp datetime); insert into EnergyData values ('Machine1',50,'2022-01-01 00:00:00'),('Machine2',70,'2022-01-01 00:00:00'),('Machine1',60,'2022-01-02 00:00:00'); | select Machine, DATE(Timestamp) as Date, SUM(Energy) as TotalEnergy from EnergyData group by Machine, Date; |
Provide labor productivity metrics for the past 3 years for mines in Brazil. | CREATE TABLE labor_productivity (id INT,mine_id INT,year INT,productivity INT);CREATE TABLE mine (id INT,name VARCHAR(255),location VARCHAR(255)); INSERT INTO mine (id,name,location) VALUES (1,'Brazilian Gold','Brazil'); INSERT INTO labor_productivity (id,mine_id,year,productivity) VALUES (1,1,2020,100); | SELECT year, productivity FROM labor_productivity JOIN mine ON labor_productivity.mine_id = mine.id WHERE mine.location = 'Brazil' AND year >= (SELECT MAX(year) - 3 FROM labor_productivity); |
How many total donations were made to the 'Education' program? | CREATE TABLE program (id INT,name VARCHAR(50)); INSERT INTO program (id,name) VALUES (1,'Education'),(2,'Health'),(3,'Environment'); CREATE TABLE donation (id INT,amount DECIMAL(10,2),program_id INT); | SELECT SUM(d.amount) as total_donations FROM donation d WHERE d.program_id = 1; |
What is the total biomass of each fish species in farming sites located in the Asia-Pacific region? | CREATE TABLE FarmSite (SiteID INT,Species VARCHAR(255),Biomass FLOAT,Region VARCHAR(255)); INSERT INTO FarmSite (SiteID,Species,Biomass,Region) VALUES (1,'Tilapia',500,'Asia-Pacific'),(2,'Salmon',300,'Asia-Pacific'),(3,'Tilapia',600,'Asia-Pacific'),(4,'Salmon',400,'Europe'); | SELECT Species, SUM(Biomass) as TotalBiomass FROM FarmSite WHERE Region = 'Asia-Pacific' GROUP BY Species; |
List all climate finance initiatives and their corresponding categories in Africa from 2018 to 2022, ordered by category and year. | CREATE TABLE climate_finance (id INT,initiative_name VARCHAR(50),category VARCHAR(50),location VARCHAR(50),funding_amount FLOAT,start_year INT,end_year INT); INSERT INTO climate_finance (id,initiative_name,category,location,funding_amount,start_year,end_year) VALUES (1,'Solar Power Expansion','Renewable Energy','Africa',1000000,2018,2022); | SELECT initiative_name, category, start_year, end_year, funding_amount FROM climate_finance WHERE location = 'Africa' AND start_year BETWEEN 2018 AND 2022 ORDER BY category, start_year; |
How many community development projects were completed in the 'southern_region' in 2019? | CREATE TABLE community_projects (project_id INT,project_name TEXT,location TEXT,completion_year INT); INSERT INTO community_projects (project_id,project_name,location,completion_year) VALUES (1,'Community Center','Southern Region',2019); INSERT INTO community_projects (project_id,project_name,location,completion_year) VALUES (2,'Park Renovation','Northern Region',2018); | SELECT COUNT(*) FROM community_projects WHERE completion_year = 2019 AND location = 'southern_region'; |
What is the distribution of post types (text, image, video) for users in a specific country, for the past month? | CREATE TABLE user_info (user_id INT,username VARCHAR(50),country VARCHAR(50),followers INT); CREATE TABLE user_activity (user_id INT,post_date DATE,post_type VARCHAR(10),activity INT); INSERT INTO user_info (user_id,username,country,followers) VALUES (1,'johndoe','USA',1000),(2,'janedoe','Canada',2000),(3,'samantha','Mexico',500); INSERT INTO user_activity (user_id,post_date,post_type,activity) VALUES (1,'2022-02-01','text',10),(1,'2022-02-05','image',5),(2,'2022-02-03','video',1); | SELECT ui.country, post_type, COUNT(*) as post_count FROM user_info ui JOIN user_activity ua ON ui.user_id = ua.user_id WHERE ui.country = 'Mexico' AND ua.post_date BETWEEN DATE_SUB(NOW(), INTERVAL 1 MONTH) AND NOW() GROUP BY ui.country, post_type; |
What is the average survival rate for marine shrimp farms in Indonesia in Q2 2022? | CREATE TABLE marine_shrimp_farms (farm_id INT,country VARCHAR(50),date DATE,survival_rate FLOAT); | SELECT AVG(survival_rate) FROM marine_shrimp_farms WHERE country = 'Indonesia' AND date BETWEEN '2022-04-01' AND '2022-06-30' GROUP BY country; |
What is the distribution of fairness scores for AI algorithms in different regions? | CREATE TABLE algorithmic_fairness (id INT,region VARCHAR,algorithm VARCHAR,fairness FLOAT); | SELECT region, algorithm, PERCENT_RANK() OVER (PARTITION BY region ORDER BY fairness) FROM algorithmic_fairness; |
What is the total revenue generated from memberships in the San Francisco region? | CREATE TABLE Memberships (id INT,member_name TEXT,region TEXT,price DECIMAL(5,2)); INSERT INTO Memberships (id,member_name,region,price) VALUES (1,'John Doe','San Francisco',50.00); INSERT INTO Memberships (id,member_name,region,price) VALUES (2,'Jane Smith','New York',75.00); | SELECT SUM(price) FROM Memberships WHERE region = 'San Francisco'; |
What is the minimum financial capability score for customers? | CREATE TABLE customers (customer_id INT,name VARCHAR(50),financial_capability_score INT); INSERT INTO customers (customer_id,name,financial_capability_score) VALUES (101,'John Doe',75),(102,'Jane Smith',80),(103,'Alice Johnson',82); | SELECT MIN(financial_capability_score) FROM customers; |
Show the ethics principles with descriptions longer than 50 characters. | CREATE TABLE media_ethics (id INT,principle VARCHAR(255),description TEXT); INSERT INTO media_ethics (id,principle,description) VALUES (1,'Accuracy','Always strive for truth and accuracy.'); INSERT INTO media_ethics (id,principle,description) VALUES (3,'Independence','Maintain independence and avoid bias.'); | SELECT * FROM media_ethics WHERE LENGTH(description) > 50; |
Find the number of employees who changed their department more than once in 2020 | CREATE TABLE department_changes (id INT,employee_id INT,change_date DATE,new_department VARCHAR(255)); INSERT INTO department_changes (id,employee_id,change_date,new_department) VALUES (1,701,'2020-03-01','IT'); INSERT INTO department_changes (id,employee_id,change_date,new_department) VALUES (2,702,'2020-12-20','HR'); | SELECT COUNT(DISTINCT employee_id) FROM department_changes WHERE YEAR(change_date) = 2020 GROUP BY employee_id HAVING COUNT(DISTINCT employee_id) > 1; |
What is the name of the cultural site with ID 4 in the cultural_sites table? | CREATE TABLE cultural_sites (site_id INT,name TEXT,city TEXT); INSERT INTO cultural_sites (site_id,name,city) VALUES (1,'Tsukiji Fish Market','Tokyo'),(2,'Sensoji Temple','Tokyo'),(3,'Osaka Castle','Osaka'),(4,'Petronas Twin Towers','Kuala Lumpur'); | SELECT name FROM cultural_sites WHERE site_id = 4; |
What is the total number of maintenance requests for buses in the city of Chicago? | CREATE TABLE bus_lines (line_id INT,line_name VARCHAR(255),city VARCHAR(255)); INSERT INTO bus_lines (line_id,line_name,city) VALUES (1,'Line 10','Chicago'),(2,'Line 40','Chicago'); CREATE TABLE bus_maintenance (maintenance_id INT,bus_id INT,line_id INT,maintenance_date DATE); INSERT INTO bus_maintenance (maintenance_id,bus_id,line_id) VALUES (1,1,1),(2,2,1),(3,3,2),(4,4,2); | SELECT COUNT(*) FROM bus_maintenance bm JOIN bus_lines bl ON bm.line_id = bl.line_id WHERE bl.city = 'Chicago'; |
What is the average age of patients who received therapy in the mental_health_facilities table, grouped by the type of therapy? | CREATE TABLE mental_health_facilities (facility_id INT,therapy_type VARCHAR(255),patient_age INT); | SELECT therapy_type, AVG(patient_age) FROM mental_health_facilities GROUP BY therapy_type; |
What is the total duration of spacewalks by 'NASA' astronauts? | CREATE TABLE Spacewalks (id INT,astronaut VARCHAR(50),space_agency VARCHAR(50),start_time TIME,end_time TIME); | SELECT space_agency, SUM(DATEDIFF(minute, start_time, end_time))/60.0 FROM Spacewalks WHERE space_agency = 'NASA' GROUP BY space_agency; |
Which item type was shipped the most via each transportation mode? | CREATE TABLE shipments (id INT,order_id INT,item_type VARCHAR(50),transportation_mode VARCHAR(50),quantity INT); INSERT INTO shipments (id,order_id,item_type,transportation_mode,quantity) VALUES (1,1001,'Item1','Air',50),(2,1002,'Item2','Road',80),(3,1003,'Item1','Rail',75),(4,1004,'Item3','Sea',30); | SELECT transportation_mode, item_type, SUM(quantity) as total_quantity FROM shipments GROUP BY transportation_mode, item_type ORDER BY total_quantity DESC; |
List the unique security incidents and their types that have been resolved in the last month, excluding any incidents that were resolved using a specific mitigation strategy (e.g. patching)? | CREATE TABLE incident_resolutions (incident_id INT,incident_type TEXT,resolved BOOLEAN,resolved_date DATETIME,resolution_strategy TEXT);INSERT INTO incident_resolutions (incident_id,incident_type,resolved,resolved_date,resolution_strategy) VALUES (1,'Malware',TRUE,'2022-02-01','Patching'),(2,'Phishing',TRUE,'2022-02-02','User Training'),(3,'Ransomware',TRUE,'2022-02-03','Incident Response'),(4,'DDoS',TRUE,'2022-02-04','Network Hardening'),(5,'Intrusion',TRUE,'2022-02-05','Patching'); | SELECT DISTINCT incident_type FROM incident_resolutions WHERE resolved = TRUE AND resolved_date >= DATEADD(month, -1, GETDATE()) AND resolution_strategy != 'Patching'; |
Update the population of the 'Penguin' species in the 'animals' table | CREATE TABLE animals (id INT PRIMARY KEY,name VARCHAR(50),species VARCHAR(50),population INT); | UPDATE animals SET population = 2000 WHERE species = 'Penguin'; |
What are the total assets of all customers who have invested in both the US and Canadian equities markets? | CREATE TABLE Customers (CustomerID INT,Name VARCHAR(50),TotalAssets DECIMAL(18,2));CREATE TABLE Investments (CustomerID INT,InvestmentType VARCHAR(10),Market VARCHAR(10));INSERT INTO Customers VALUES (1,'John Doe',50000.00),(2,'Jane Smith',75000.00);INSERT INTO Investments VALUES (1,'Stocks','US'),(1,'Stocks','Canada'),(2,'Stocks','US'); | SELECT SUM(c.TotalAssets) FROM Customers c INNER JOIN Investments i ON c.CustomerID = i.CustomerID WHERE i.Market IN ('US', 'Canada') GROUP BY i.CustomerID HAVING COUNT(DISTINCT i.Market) = 2; |
What is the average fare for adult passengers in 'lightrail'? | CREATE TABLE public.route_type (route_type_id SERIAL PRIMARY KEY,route_type VARCHAR(20)); INSERT INTO public.route_type (route_type) VALUES ('bus'),('lightrail'),('subway'); CREATE TABLE public.fares (fare_id SERIAL PRIMARY KEY,passenger_type VARCHAR(20),fare DECIMAL(5,2)),route_type_id INTEGER,FOREIGN KEY (route_type_id) REFERENCES public.route_type(route_type_id)); INSERT INTO public.fares (passenger_type,fare,route_type_id) VALUES ('adult',2.50,2),('child',1.25,2); | SELECT fare FROM public.fares WHERE passenger_type = 'adult' AND route_type_id = (SELECT route_type_id FROM public.route_type WHERE route_type = 'lightrail') |
Find the total number of penalty kicks scored by each team in the UEFA Europa League | CREATE TABLE teams (id INT PRIMARY KEY,name TEXT,league TEXT,penalty_kicks_scored INT,penalty_kicks_missed INT); INSERT INTO teams (id,name,league,penalty_kicks_scored,penalty_kicks_missed) VALUES (1,'Barcelona','La Liga',4,1),(2,'Paris Saint-Germain','Ligue 1',2,1),(3,'Manchester United','English Premier League',5,2),(4,'Arsenal','English Premier League',3,0),(5,'Roma','Serie A',2,0),(6,'Lazio','Serie A',1,0); | SELECT name, penalty_kicks_scored FROM teams; |
What is the total number of military vehicles sold by Lockheed Martin to the United States government in the year 2020? | CREATE TABLE military_sales (seller VARCHAR(255),buyer VARCHAR(255),equipment VARCHAR(255),quantity INT,sale_date DATE); INSERT INTO military_sales (seller,buyer,equipment,quantity,sale_date) VALUES ('Lockheed Martin','United States','tank',50,'2020-01-02'),('Lockheed Martin','United States','vehicle',120,'2020-05-15'); | SELECT SUM(quantity) FROM military_sales WHERE seller = 'Lockheed Martin' AND buyer = 'United States' AND YEAR(sale_date) = 2020 AND equipment = 'vehicle'; |
What is the 'maintenance_cost' for 'Plant E' in 'water_treatment_plants'? | CREATE TABLE water_treatment_plants (id INT,plant_name VARCHAR(50),maintenance_cost INT); INSERT INTO water_treatment_plants (id,plant_name,maintenance_cost) VALUES (1,'Plant A',30000),(2,'Plant B',50000),(3,'Plant C',40000),(4,'Plant D',35000),(5,'Plant E',45000); | SELECT maintenance_cost FROM water_treatment_plants WHERE plant_name = 'Plant E'; |
Which marine species are part of the same initiatives as the 'dolphin' species in the 'marine_species' and 'pollution_control' tables? | CREATE TABLE marine_species (id INT,species_name VARCHAR(50),ocean VARCHAR(50)); CREATE TABLE pollution_control (id INT,species_name VARCHAR(50),initiative_id INT); | SELECT ms.species_name FROM marine_species ms JOIN pollution_control pc ON ms.species_name = pc.species_name WHERE pc.species_name = 'dolphin'; |
What is the total humanitarian assistance provided (in USD) by each country in the 'humanitarian_assistance' table, for operations in 'Asia'? | CREATE TABLE humanitarian_assistance (id INT,country VARCHAR(50),region VARCHAR(50),amount INT); | SELECT country, SUM(amount) as total_assistance FROM humanitarian_assistance WHERE region = 'Asia' GROUP BY country; |
What is the total number of virtual tour views for hotels in Miami? | CREATE TABLE cultural_heritage (site_id INT,hotel_id INT,attendance INT); INSERT INTO cultural_heritage (site_id,hotel_id,attendance) VALUES (1,1,500),(2,2,300); | SELECT SUM(vt.num_views) FROM virtual_tours vt INNER JOIN hotel_info hi ON vt.hotel_id = hi.hotel_id WHERE hi.city = 'Miami'; |
What is the maximum number of volunteers for a program, and the name of the program with the maximum number of volunteers? | CREATE TABLE Programs (ProgramID INT,ProgramName TEXT,VolunteerCount INT); INSERT INTO Programs (ProgramID,ProgramName,VolunteerCount) VALUES (1,'Feeding America',75); INSERT INTO Programs (ProgramID,ProgramName,VolunteerCount) VALUES (2,'Red Cross',30); INSERT INTO Programs (ProgramID,ProgramName,VolunteerCount) VALUES (3,'Habitat for Humanity',60); | SELECT ProgramName, MAX(VolunteerCount) FROM Programs; |
What are the sites with the most artifacts analyzed by experts from the same country as experts specialized in metalwork? | CREATE TABLE Artifacts (id INT,site VARCHAR(50),artifact_name VARCHAR(50),date_found DATE,description TEXT); INSERT INTO Artifacts (id,site,artifact_name,date_found,description) VALUES (1,'Site1','Pottery','2020-01-01','Fine pottery with unique symbols'); CREATE TABLE Sites (id INT,site_name VARCHAR(50),location VARCHAR(50),period VARCHAR(50),type VARCHAR(50)); INSERT INTO Sites (id,site_name,location,period,type) VALUES (1,'Site1','Location1','Period1','Settlement'); CREATE TABLE Experts (id INT,name VARCHAR(50),expertise VARCHAR(50),country VARCHAR(50)); INSERT INTO Experts (id,name,expertise,country) VALUES (1,'Expert1','Pottery','Country1'),(2,'Expert2','Metalwork','Country1'); | SELECT site, COUNT(*) as artifact_count FROM Artifacts GROUP BY site HAVING artifact_count = (SELECT MAX(artifact_count) FROM (SELECT site, COUNT(*) as artifact_count FROM Artifacts GROUP BY site) as subquery) AND site IN (SELECT site_name FROM (SELECT site_name FROM Sites WHERE type = 'Settlement' AND location IN (SELECT location FROM Sites WHERE period = 'Period2')) as subquery2 WHERE site_name IN (SELECT site_name FROM Experts WHERE country IN (SELECT country FROM Experts WHERE expertise = 'Metalwork'))) GROUP BY site; |
What is the average admission price for historical sites in Edinburgh? | CREATE TABLE historical_sites (site_id INT,name TEXT,city TEXT,admission_price FLOAT); INSERT INTO historical_sites (site_id,name,city,admission_price) VALUES (1,'Edinburgh Castle','Edinburgh',19.5),(2,'Palace of Holyroodhouse','Edinburgh',15.0); | SELECT AVG(admission_price) FROM historical_sites WHERE city = 'Edinburgh'; |
Determine the average water savings in liters achieved by the implemented water conservation initiatives in 'Tokyo' for the year 2018 | CREATE TABLE savings_data (region VARCHAR(50),date DATE,savings FLOAT); INSERT INTO savings_data (region,date,savings) VALUES ('Tokyo','2018-01-01',100),('Tokyo','2018-01-02',110),('Tokyo','2018-01-03',120); | SELECT AVG(savings) FROM savings_data WHERE region = 'Tokyo' AND date BETWEEN '2018-01-01' AND '2018-12-31'; |
What is the total funding amount for genetic research in India? | CREATE SCHEMA if not exists genetics;CREATE TABLE if not exists genetics.research_funding (id INT,name TEXT,location TEXT,type TEXT,funding DECIMAL(10,2)); INSERT INTO genetics.research_funding (id,name,location,type,funding) VALUES (1,'ProjectX','IN','Genetic',2500000.00),(2,'ProjectY','US','Genomic',5000000.00),(3,'ProjectZ','CA','Genetic',3500000.00); | SELECT SUM(funding) FROM genetics.research_funding WHERE location = 'IN' AND type = 'Genetic'; |
What is the success rate of cases in 'California'? | CREATE TABLE cases (case_id INT,state VARCHAR(50),is_success BOOLEAN); INSERT INTO cases (case_id,state,is_success) VALUES (1,'California',TRUE),(2,'New York',FALSE),(3,'California',TRUE),(4,'Texas',TRUE); | SELECT COUNT(*) / (SELECT COUNT(*) FROM cases WHERE cases.state = 'California' AND is_success = TRUE) AS success_rate FROM cases WHERE cases.state = 'California'; |
How many startups have successfully exited via IPO in the last 5 years? | CREATE TABLE startup (id INT,name TEXT,exit_strategy TEXT,exit_date DATE); INSERT INTO startup (id,name,exit_strategy,exit_date) VALUES (1,'IPOedStartup','IPO','2021-01-01'); INSERT INTO startup (id,name,exit_strategy,exit_date) VALUES (2,'AcquiredStartup','Acquisition','2020-01-01'); | SELECT COUNT(*) FROM startup WHERE exit_strategy = 'IPO' AND exit_date BETWEEN DATE('2016-01-01') AND DATE('2021-01-01'); |
Delete military equipment sale records older than 5 years from sales_data | CREATE TABLE sales_data (id INT,equipment_name TEXT,sale_date DATE,quantity INT,total_cost FLOAT); | DELETE FROM sales_data WHERE sale_date < DATE_SUB(CURDATE(), INTERVAL 5 YEAR); |
What is the average number of songs per album for K-pop albums released in the last 3 years? | CREATE TABLE kpop_albums (id INT,name TEXT,genre TEXT,release_date DATE,songs INT); INSERT INTO kpop_albums (id,name,genre,release_date,songs) VALUES (1,'Album1','K-pop','2020-01-01',12),(2,'Album2','Pop','2019-06-15',10),(3,'Album3','K-pop','2021-09-09',9); | SELECT AVG(songs) FROM kpop_albums WHERE genre = 'K-pop' AND release_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 YEAR); |
Delete records in the "bookings" table where the check-in date is before 2021-01-01 | CREATE TABLE bookings (id INT,guest_name VARCHAR(50),check_in DATE,check_out DATE); | WITH cte AS (DELETE FROM bookings WHERE check_in < '2021-01-01') SELECT * FROM cte; |
What is the minimum unemployment rate of countries in Asia? | CREATE TABLE unemployment (country VARCHAR(50),region VARCHAR(50),unemployment_rate FLOAT); INSERT INTO unemployment (country,region,unemployment_rate) VALUES ('Japan','Asia',2.4),('Malaysia','Asia',3.3),('China','Asia',3.8),('Indonesia','Asia',5.3),('Philippines','Asia',5.4),('Thailand','Asia',1.2),('Vietnam','Asia',2.2),('South Korea','Asia',3.8); | SELECT MIN(unemployment_rate) FROM unemployment WHERE region = 'Asia'; |
What was the total investment in renewable energy projects in 'Region 1' in 2021? | CREATE TABLE renewable_energy_investment (project_id INT,region VARCHAR(255),investment_year INT,investment FLOAT); INSERT INTO renewable_energy_investment (project_id,region,investment_year,investment) VALUES (1,'Region 1',2020,1000000),(2,'Region 1',2021,1500000),(3,'Region 2',2020,1200000),(4,'Region 2',2021,1800000); | SELECT SUM(investment) as total_investment FROM renewable_energy_investment WHERE region = 'Region 1' AND investment_year = 2021; |
Delete records from the "diversity_metrics" table for the company 'Mike Ltd.' | CREATE TABLE diversity_metrics (id INT,company_name VARCHAR(100),region VARCHAR(50),employees_of_color INT,women_in_tech INT); INSERT INTO diversity_metrics (id,company_name,region,employees_of_color,women_in_tech) VALUES (1,'Acme Inc.','Europe',15,22),(2,'Bravo Corp.','North America',35,18),(3,'Mike Ltd.','Africa',20,10); | DELETE FROM diversity_metrics WHERE company_name = 'Mike Ltd.'; |
Show the 'Union_Type' and number of unions in the 'Labor_Unions' table in the 'Asia' region. | CREATE TABLE Labor_Unions (id INT,union_type VARCHAR(20),region VARCHAR(20)); INSERT INTO Labor_Unions (id,union_type,region) VALUES (1,'Trade','Asia'),(2,'Industrial','Europe'),(3,'Trade','Asia'),(4,'Professional','Americas'); | SELECT union_type, COUNT(*) FROM Labor_Unions WHERE region = 'Asia' GROUP BY union_type; |
What is the average budget for public schools in the Northeast and West regions? | CREATE TABLE Schools (Region VARCHAR(20),School VARCHAR(20),Budget DECIMAL(10,2)); INSERT INTO Schools (Region,School,Budget) VALUES ('Northeast','SchoolA',15000.00),('West','SchoolB',20000.00),('Southeast','SchoolC',18000.00); | SELECT AVG(Budget) FROM Schools WHERE Region IN ('Northeast', 'West'); |
Which users have participated in 'Zumba' workouts in the 'workout_data' table? | CREATE TABLE workout_data (user_id INT,workout_type VARCHAR(20),duration INT); INSERT INTO workout_data (user_id,workout_type,duration) VALUES (1,'Running',30),(1,'Cycling',60),(2,'Yoga',45),(3,'Pilates',50),(6,'Zumba',75),(7,'Zumba',90); | SELECT DISTINCT user_id FROM workout_data WHERE workout_type = 'Zumba'; |
Identify the communication channels used for each climate finance project in Europe. | CREATE TABLE climate_finance (project_name TEXT,channel TEXT);INSERT INTO climate_finance (project_name,channel) VALUES ('Renewable Energy','Grants'),('Energy Efficiency','Loans'),('Clean Transport','Equity Investments'); | SELECT project_name, GROUP_CONCAT(channel) as channels FROM climate_finance WHERE region = 'Europe' GROUP BY project_name; |
What is the maximum investment amount in the Technology sector? | CREATE TABLE investments (id INT,company_id INT,sector TEXT,amount FLOAT); INSERT INTO investments (id,company_id,sector,amount) VALUES (1,1,'Technology',50000),(2,2,'Finance',70000),(3,3,'Technology',80000),(4,4,'Healthcare',60000),(5,5,'Finance',90000); | SELECT MAX(amount) FROM investments WHERE sector = 'Technology'; |
What are the names and locations of all renewable energy projects with installed capacities greater than 100000 in the 'EcoPower' schema? | CREATE SCHEMA EcoPower; CREATE TABLE RenewableProjects (project_id INT,name VARCHAR(100),location VARCHAR(100),installed_capacity INT); INSERT INTO RenewableProjects (project_id,name,location,installed_capacity) VALUES (1,'SolarFarm 1','California',150000),(2,'WindFarm 2','Texas',120000),(3,'HydroProject 1','Oregon',180000),(4,'Geothermal 1','Nevada',90000); | SELECT name, location FROM EcoPower.RenewableProjects WHERE installed_capacity > 100000; |
Find the top 3 destinations with the highest total delivery time? | CREATE TABLE Warehouse (id INT,location VARCHAR(255),capacity INT); INSERT INTO Warehouse (id,location,capacity) VALUES (1,'New York',500),(2,'Toronto',700),(3,'Montreal',600); CREATE TABLE Shipment (id INT,warehouse_id INT,delivery_time INT,destination VARCHAR(255)); INSERT INTO Shipment (id,warehouse_id,delivery_time,destination) VALUES (1,1,5,'Mexico'),(2,2,12,'Canada'),(3,3,4,'Canada'),(4,1,6,'Russia'),(5,2,3,'Australia'),(6,3,15,'Brazil'); | SELECT destination, SUM(delivery_time) as total_delivery_time, RANK() OVER (ORDER BY SUM(delivery_time) DESC) as rank FROM Shipment GROUP BY destination HAVING rank <= 3; |
How many pediatric healthcare facilities are available in total? | CREATE TABLE hospitals (id INT,name TEXT,location TEXT,type TEXT); INSERT INTO hospitals (id,name,location,type) VALUES (1,'Hospital A','City A','General'); INSERT INTO hospitals (id,name,location,type) VALUES (2,'Hospital B','City B','Pediatric'); CREATE TABLE clinics (id INT,name TEXT,location TEXT,type TEXT); INSERT INTO clinics (id,name,location,type) VALUES (1,'Clinic C','City C','Dental'); INSERT INTO clinics (id,name,location,type) VALUES (2,'Clinic D','City D','General'); INSERT INTO clinics (id,name,location,type) VALUES (3,'Clinic E','City A','Pediatric'); | SELECT type FROM hospitals WHERE type = 'Pediatric' UNION SELECT type FROM clinics WHERE type = 'Pediatric'; |
List the total number of patients with diabetes in rural hospitals, grouped by hospital location state. | CREATE TABLE patients (patient_id INT,age INT,gender TEXT,rural BOOLEAN,disease TEXT,hospital_id INT); INSERT INTO patients (patient_id,age,gender,rural,disease,hospital_id) VALUES (1,50,'Female',true,'Diabetes',1); CREATE TABLE hospitals (hospital_id INT,hospital_name TEXT,beds INT,rural BOOLEAN,state_id INT); INSERT INTO hospitals (hospital_id,hospital_name,beds,rural,state_id) VALUES (1,'Hospital A',100,true,1); CREATE TABLE states (state_id INT,state TEXT); INSERT INTO states (state_id,state) VALUES (1,'Alabama'),(2,'Alaska'); | SELECT states.state, SUM(CASE WHEN patients.disease = 'Diabetes' THEN 1 ELSE 0 END) patient_count FROM patients JOIN hospitals ON patients.hospital_id = hospitals.hospital_id JOIN states ON hospitals.state_id = states.state_id WHERE hospitals.rural = true GROUP BY states.state; |
Update donation amounts for 2021 with a 5% increase. | CREATE TABLE Donations (DonorID int,DonationDate date,Amount decimal(10,2)); INSERT INTO Donations (DonorID,DonationDate,Amount) VALUES (1,'2021-01-01',500.00),(2,'2021-02-15',300.00); | UPDATE Donations SET Amount = Amount * 1.05 WHERE YEAR(DonationDate) = 2021; |
Delete records of health centers in Northern Mariana Islands. | CREATE TABLE health_centers (id INT,name TEXT,location TEXT); INSERT INTO health_centers (id,name,location) VALUES (1,'Health Center A','Rural Alaska'); INSERT INTO health_centers (id,name,location) VALUES (5,'Health Center E','Northern Mariana Islands'); | DELETE FROM health_centers WHERE location = 'Northern Mariana Islands'; |
What is the distribution of medical risks for astronauts by country? | CREATE TABLE Astronauts (id INT,country TEXT);CREATE TABLE AstronautMedicalData (id INT,astronaut_id INT,medical_risk FLOAT); | SELECT Astronauts.country, AVG(medical_risk) as avg_medical_risk, STDDEV(medical_risk) as stddev_medical_risk FROM Astronauts INNER JOIN AstronautMedicalData ON Astronauts.id = AstronautMedicalData.astronaut_id GROUP BY Astronauts.country; |
What is the minimum number of crew members on any space mission? | CREATE TABLE Missions (name VARCHAR(30),crew_size INT); INSERT INTO Missions (name,crew_size) VALUES ('Apollo 1',3),('Mercury-Redstone 3',1); | SELECT MIN(crew_size) FROM Missions; |
Delete concert records with low attendance | CREATE TABLE concerts (id INT PRIMARY KEY,artist_id INT,venue_name VARCHAR(255),city VARCHAR(255),date DATE,num_attendees INT); CREATE VIEW low_attendance_concerts AS SELECT id,artist_id,venue_name,city,date FROM concerts WHERE num_attendees < 100; CREATE TABLE artists (id INT PRIMARY KEY,name VARCHAR(255),genre VARCHAR(255),origin_country VARCHAR(255)); | DELETE FROM concerts WHERE id IN (SELECT id FROM low_attendance_concerts); |
What was the average citizen feedback score for public transportation in Q1 and Q2 of 2023? | CREATE TABLE CitizenFeedback (Quarter INT,Service TEXT,Score INT); INSERT INTO CitizenFeedback (Quarter,Service,Score) VALUES (1,'PublicTransportation',8),(1,'PublicTransportation',7),(2,'PublicTransportation',9),(2,'PublicTransportation',8); | SELECT AVG(Score) FROM CitizenFeedback WHERE Service = 'PublicTransportation' AND Quarter IN (1, 2); |
Which satellite images have a resolution of 0.4 or better, taken after 2021-09-01? | CREATE TABLE satellite_imagery (id INT,image_url VARCHAR(255),resolution DECIMAL(3,2),date DATE,PRIMARY KEY (id)); INSERT INTO satellite_imagery (id,image_url,resolution,date) VALUES (1,'https://example.com/image1.jpg',0.5,'2021-09-01'),(2,'https://example.com/image2.jpg',0.45,'2021-10-15'),(3,'https://example.com/image3.jpg',0.6,'2021-07-01'); | SELECT * FROM satellite_imagery WHERE resolution <= 0.4 AND date > '2021-09-01'; |
What is the average temperature per city and month in the 'crop_weather' table? | CREATE TABLE crop_weather (city VARCHAR(50),temperature INT,month INT); INSERT INTO crop_weather (city,temperature,month) VALUES ('CityA',15,4),('CityA',18,4),('CityB',20,4),('CityB',22,4),('CityA',25,5),('CityA',28,5),('CityB',26,5),('CityB',30,5); | SELECT city, month, AVG(temperature) as avg_temp FROM crop_weather GROUP BY city, month; |
How many sightings of each Arctic animal species are recorded per year? | CREATE TABLE animal_sightings (sighting_date DATE,animal_species VARCHAR(50)); INSERT INTO animal_sightings (sighting_date,animal_species) VALUES ('2010-01-01','Polar Bear'),('2010-01-05','Walrus'); | SELECT s.animal_species, EXTRACT(YEAR FROM s.sighting_date) as year, COUNT(s.sighting_date) as sighting_count FROM animal_sightings s GROUP BY s.animal_species, s.sighting_date; |
What is the average age of patients who received CBT treatment in Texas? | CREATE TABLE patients (patient_id INT,age INT,gender TEXT,treatment TEXT,state TEXT); INSERT INTO patients (patient_id,age,gender,treatment,state) VALUES (1,30,'Female','CBT','Texas'); INSERT INTO patients (patient_id,age,gender,treatment,state) VALUES (2,45,'Male','DBT','California'); | SELECT AVG(age) FROM patients WHERE treatment = 'CBT' AND state = 'Texas'; |
What is the maximum lifespan of a satellite in geostationary orbit? | CREATE TABLE satellites (id INT,satellite_name VARCHAR(50),orbit VARCHAR(50),launch_date DATE,lifespan INT); | SELECT MAX(lifespan) FROM satellites WHERE orbit = 'Geostationary Orbit'; |
Identify the total labor hours spent on construction projects in 'Northeast' region for the year 2019, excluding permit processing hours. | CREATE TABLE Labor_Hours (project_id INT,region VARCHAR(255),labor_hours INT,permit_hours INT); INSERT INTO Labor_Hours (project_id,region,labor_hours,permit_hours) VALUES (1,'Northeast',500,50); INSERT INTO Labor_Hours (project_id,region,labor_hours,permit_hours) VALUES (2,'Northeast',700,70); | SELECT SUM(labor_hours) FROM Labor_Hours WHERE region = 'Northeast' AND permit_hours = 0 AND YEAR(date) = 2019; |
What is the total number of cases heard in community courts and traditional courts? | CREATE TABLE community_court (case_id INT,court_type VARCHAR(20),case_date DATE,case_status VARCHAR(20)); INSERT INTO community_court VALUES (1,'Community','2021-01-01','Heard'),(2,'Community','2021-01-05','Not Heard'); CREATE TABLE traditional_court (case_id INT,court_type VARCHAR(20),case_date DATE,case_status VARCHAR(20)); INSERT INTO traditional_court VALUES (3,'Traditional','2021-01-02','Heard'),(4,'Traditional','2021-01-06','Heard'); | SELECT SUM(CASE WHEN court_type = 'Community' THEN 1 ELSE 0 END) AS community_court_cases, SUM(CASE WHEN court_type = 'Traditional' THEN 1 ELSE 0 END) AS traditional_court_cases FROM (SELECT * FROM community_court UNION ALL SELECT * FROM traditional_court) AS court_cases; |
What is the total number of workers from historically underrepresented communities in the Operations department? | CREATE TABLE departments (id INT,name VARCHAR(255),diversity_stats VARCHAR(255)); INSERT INTO departments (id,name,diversity_stats) VALUES (1,'HR','{"total_employees":50,"underrepresented":20}'),(2,'Operations','{"total_employees":75,"underrepresented":15}'),(3,'Finance','{"total_employees":60,"underrepresented":10}'); | SELECT d.name AS department, JSON_EXTRACT(d.diversity_stats, '$.underrepresented') AS underrepresented_count FROM departments d WHERE d.name = 'Operations'; |
Update the platform name of the platform with id 3 to 'New Platform Name' in the 'platforms' table | CREATE TABLE platforms (id INT,platform TEXT); | UPDATE platforms SET platform = 'New Platform Name' WHERE id = 3; |
What is the earliest launch date for each agency? | CREATE TABLE Rocket_Launch_Sites (Site_ID INTEGER,Site_Name TEXT,Agency TEXT,Location TEXT,First_Launch DATE); INSERT INTO Rocket_Launch_Sites (Site_ID,Site_Name,Agency,Location,First_Launch) VALUES (3,'Plesetsk Cosmodrome','Roscosmos','Russia','1963-10-16'); INSERT INTO Rocket_Launch_Sites (Site_ID,Site_Name,Agency,Location,First_Launch) VALUES (4,'Vandenberg Air Force Base','USAF','United States','1958-12-18'); | SELECT Agency, MIN(First_Launch) as Earliest_Launch FROM Rocket_Launch_Sites GROUP BY Agency; |
What is the total CO2 emissions for each mining operation in the past year, ordered by the most emitting operation? | CREATE TABLE mining_operations (id INT,name TEXT,co2_emissions INT,operation_date DATE); INSERT INTO mining_operations (id,name,co2_emissions,operation_date) VALUES (1,'Operation X',12000,'2021-01-01'),(2,'Operation Y',15000,'2021-01-02'),(3,'Operation Z',18000,'2021-01-03'); | SELECT name, SUM(co2_emissions) FROM mining_operations WHERE operation_date >= DATEADD(year, -1, GETDATE()) GROUP BY name ORDER BY SUM(co2_emissions) DESC; |
What are the top 3 legal precedents cited in cases handled by attorneys from New York? | CREATE TABLE Cases (CaseID INT,AttorneyID INT,Precedent VARCHAR(255)); CREATE TABLE Attorneys (AttorneyID INT,City VARCHAR(255)); | SELECT Precedent, COUNT(*) FROM Cases JOIN Attorneys ON Cases.AttorneyID = Attorneys.AttorneyID WHERE Attorneys.City = 'New York' GROUP BY Precedent ORDER BY COUNT(*) DESC LIMIT 3; |
What is the total number of news articles published in the "news_articles" table by authors from the USA and Canada? | CREATE TABLE news_articles (id INT,title VARCHAR(100),author_id INT,published_date DATE,country VARCHAR(50)); INSERT INTO news_articles (id,title,author_id,published_date,country) VALUES (1,'News Article 1',1,'2022-01-01','Canada'),(2,'News Article 2',2,'2022-01-02','USA'); | SELECT COUNT(*) FROM news_articles WHERE country IN ('Canada', 'USA'); |
What is the minimum carbon sequestration rate for each region? | CREATE TABLE regions (region_id INT,region_name TEXT);CREATE TABLE carbon_sequestration (sequestration_id INT,region_id INT,sequestration_rate FLOAT); INSERT INTO regions (region_id,region_name) VALUES (1,'Region A'),(2,'Region B'),(3,'Region C'); INSERT INTO carbon_sequestration (sequestration_id,region_id,sequestration_rate) VALUES (1,1,12.5),(2,1,13.2),(3,2,15.3),(4,3,9.6),(5,3,10.1); | SELECT region_id, region_name, MIN(sequestration_rate) FROM regions JOIN carbon_sequestration ON regions.region_id = carbon_sequestration.region_id GROUP BY region_id, region_name; |
What is the percentage of mental health parity coverage that is above the national average, by state? | CREATE TABLE MentalHealthParity (State VARCHAR(20),Coverage DECIMAL(5,2)); INSERT INTO MentalHealthParity (State,Coverage) VALUES ('California',0.75),('Texas',0.82),('New York',0.91),('Florida',0.68),('Illinois',0.77),('NationalAverage',0.78); | SELECT State, 100.0 * Coverage / (SELECT Coverage FROM MentalHealthParity WHERE State = 'NationalAverage') as Percentage FROM MentalHealthParity WHERE Coverage > (SELECT Coverage FROM MentalHealthParity WHERE State = 'NationalAverage') GROUP BY State; |
How many landfill capacity updates were made in Lagos in the last 2 years? | CREATE TABLE landfill_capacity (city VARCHAR(50),capacity_quantity INT,capacity_date DATE,update_date DATE); INSERT INTO landfill_capacity (city,capacity_quantity,capacity_date,update_date) VALUES ('Lagos',1200000,'2021-01-01','2022-01-01'),('Lagos',1500000,'2023-01-01','2022-01-01'); | SELECT COUNT(*) FROM landfill_capacity WHERE city = 'Lagos' AND update_date >= '2020-01-01' AND update_date <= '2022-12-31'; |
How many tuberculosis cases were reported in New York City in the past year? | CREATE TABLE tb_tracking (id INT,case_number INT,city TEXT,state TEXT,date TEXT); INSERT INTO tb_tracking (id,case_number,city,state,date) VALUES (1,123,'New York City','New York','2021-01-01'); INSERT INTO tb_tracking (id,case_number,city,state,date) VALUES (2,456,'New York City','New York','2021-02-01'); | SELECT COUNT(*) FROM tb_tracking WHERE city = 'New York City' AND date BETWEEN (CURRENT_DATE - INTERVAL '1 year') AND CURRENT_DATE; |
Show the total revenue from football ticket sales in 2021 and 2022 | CREATE TABLE ticket_sales (ticket_id INT,sale_date DATE,event_type VARCHAR(10),revenue DECIMAL(10,2)); INSERT INTO ticket_sales (ticket_id,sale_date,event_type,revenue) VALUES (1,'2021-08-01','Football',50.00),(2,'2022-04-10','Football',75.00); | SELECT SUM(revenue) as total_revenue FROM ticket_sales WHERE event_type = 'Football' AND YEAR(sale_date) IN (2021, 2022); |
Which country has the most number of active drilling rigs? | CREATE TABLE Rigs (RigID VARCHAR(10),Location VARCHAR(50),Status VARCHAR(10)); CREATE TABLE Countries (CountryID VARCHAR(10),CountryName VARCHAR(50)); | SELECT CountryName FROM Rigs r JOIN Countries c ON r.Location = c.CountryName WHERE Status = 'Active' GROUP BY CountryName ORDER BY COUNT(*) DESC LIMIT 1; |
Find the total number of articles written by each author and the average word count of those articles. | CREATE TABLE news_articles (id INT,title VARCHAR(100),content TEXT,word_count INT,author_id INT); CREATE TABLE authors (id INT,name VARCHAR(50)); | SELECT a.name, AVG(word_count) AS avg_word_count, COUNT(*) AS articles_count FROM news_articles na JOIN authors a ON na.author_id = a.id GROUP BY a.name; |
What is the distribution of financial wellbeing scores across different income levels? | CREATE TABLE financial_wellbeing_by_income (id INT,income VARCHAR(50),score FLOAT); INSERT INTO financial_wellbeing_by_income (id,income,score) VALUES (1,'<$25,000',6.0),(2,'$25,000-$49,999',7.1),(3,'$50,000-$74,999',8.0),(4,'$75,000-$99,999',8.5),(5,'>$100,000',9.0); | SELECT income, AVG(score) as avg_score, STDDEV(score) as std_dev FROM financial_wellbeing_by_income GROUP BY income; |
What is the average workout duration for members in the 'Gold' category? | CREATE TABLE workout_durations (member_category VARCHAR(20),member_id INT,workout_duration INT); INSERT INTO workout_durations (member_category,member_id,workout_duration) VALUES ('Gold',1,60),('Gold',2,75),('Silver',3,45),('Bronze',4,65),('Bronze',5,55); | SELECT AVG(workout_duration) as avg_workout_duration FROM workout_durations WHERE member_category = 'Gold'; |
What is the total balance for customers who have made a transaction in the last month? | CREATE TABLE transactions (id INT,customer_id INT,transaction_date DATE,amount DECIMAL(10,2)); INSERT INTO transactions (id,customer_id,transaction_date,amount) VALUES (1,1,'2023-02-14',100.00),(2,2,'2023-02-15',200.00),(3,3,'2023-01-10',300.00); CREATE TABLE customers (id INT,name VARCHAR(50),region VARCHAR(50),balance DECIMAL(10,2)); INSERT INTO customers (id,name,region,balance) VALUES (1,'John Doe','West',5000.00),(2,'Jane Smith','West',7000.00),(3,'Alice Johnson','East',6000.00); | SELECT SUM(c.balance) FROM customers c JOIN transactions t ON c.id = t.customer_id WHERE t.transaction_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH); |
What is the average mass of Mars rovers? | CREATE TABLE mars_rovers (rover_name TEXT,rover_mass REAL); INSERT INTO mars_rovers (rover_name,rover_mass) VALUES ('Sojourner',10.6),('Spirit',174),('Opportunity',174); | SELECT AVG(rover_mass) FROM mars_rovers; |
Delete all records in the travel_advisory table where the status is 'Caution' | CREATE TABLE travel_advisory (location VARCHAR(255),status VARCHAR(255),last_updated DATE); | DELETE FROM travel_advisory WHERE status = 'Caution'; |
Insert a new record into the 'public_works_projects' table with the following data: 'City Hall Renovation', 'City of Oakland', '2023-05-01', 'In Progress' | CREATE TABLE public_works_projects (project_id INT,project_name TEXT,project_location TEXT,project_start_date DATE,project_status TEXT); | INSERT INTO public_works_projects (project_name, project_location, project_start_date, project_status) VALUES ('City Hall Renovation', 'City of Oakland', '2023-05-01', 'In Progress'); |
Which vessels had more than 5 safety inspections in the South China Sea? | CREATE TABLE inspections (id INT,vessel_name VARCHAR(255),inspection_date DATE,latitude DECIMAL(9,6),longitude DECIMAL(9,6)); INSERT INTO inspections (id,vessel_name,inspection_date,latitude,longitude) VALUES (1,'VesselA','2022-01-01',22.346654,113.567445); | SELECT vessel_name FROM inspections WHERE latitude BETWEEN 0.0 AND 25.0 AND longitude BETWEEN 95.0 AND 125.0 GROUP BY vessel_name HAVING COUNT(*) > 5; |
Find the total cost of all ocean floor mapping projects | CREATE TABLE ocean_floor_mapping (project_name VARCHAR(255),cost DECIMAL(10,2)); INSERT INTO ocean_floor_mapping (project_name,cost) VALUES ('Project A',50000.0),('Project B',60000.0),('Project C',70000.0); | SELECT SUM(cost) FROM ocean_floor_mapping; |
What was the average price per gram of cannabis flower sold by each dispensary in the city of Toronto in the month of February 2022? | CREATE TABLE Dispensaries (id INT,name VARCHAR(255),city VARCHAR(255),state VARCHAR(255));CREATE TABLE Inventory (id INT,dispensary_id INT,price DECIMAL(10,2),product_type VARCHAR(255),grams INT,month INT,year INT);INSERT INTO Dispensaries (id,name,city,state) VALUES (1,'CannaCorp','Toronto','ON');INSERT INTO Inventory (id,dispensary_id,price,product_type,grams,month,year) VALUES (1,1,20,'flower',3.5,2,2022); | SELECT d.name, AVG(i.price/i.grams) as avg_price_per_gram FROM Dispensaries d JOIN Inventory i ON d.id = i.dispensary_id WHERE d.city = 'Toronto' AND i.product_type = 'flower' AND i.month = 2 AND i.year = 2022 GROUP BY d.name; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.