instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the average price of artworks created by French artists? | CREATE TABLE Artists (ArtistID INT,Name VARCHAR(100),Nationality VARCHAR(50),BirthDate DATE); INSERT INTO Artists VALUES (1,'Pablo Picasso','Spanish','1881-10-25'); INSERT INTO Artists VALUES (2,'Claude Monet','French','1840-11-14'); CREATE TABLE Artwork (ArtworkID INT,Title VARCHAR(100),Price FLOAT,ArtistID INT); INSERT INTO Artwork VALUES (1,'Guernica',2000000,1); INSERT INTO Artwork VALUES (2,'Water Lilies',1500000,2); | SELECT AVG(A.Price) FROM Artwork A JOIN Artists AR ON A.ArtistID = AR.ArtistID WHERE AR.Nationality = 'French'; |
What is the total number of artworks by Aboriginal artists? | CREATE TABLE Artworks (id INT,artist VARCHAR(20),title VARCHAR(50),year INT,type VARCHAR(20)); INSERT INTO Artworks (id,artist,title,year,type) VALUES (1,'Aboriginal Artist 1','Artwork 1',2000,'Painting'); INSERT INTO Artworks (id,artist,title,year,type) VALUES (2,'Aboriginal Artist 2','Artwork 2',2005,'Sculpture'); | SELECT SUM(CASE WHEN artist LIKE 'Aboriginal Artist%' THEN 1 ELSE 0 END) AS total_aboriginal_artworks FROM Artworks; |
List all investments made by 'ImpactFirst' in 'wind_farm' projects. | CREATE TABLE investments (id INT,investor VARCHAR(255),project_type VARCHAR(255),amount INT,date DATE); INSERT INTO investments (id,investor,project_type,amount,date) VALUES (18,'ImpactFirst','wind_farm',800000,'2022-03-08'); INSERT INTO investments (id,investor,project_type,amount,date) VALUES (19,'ImpactFirst','renewable_energy',300000,'2021-12-14'); INSERT INTO investments (id,investor,project_type,amount,date) VALUES (20,'ImpactFirst','solar_farm',400000,'2022-06-10'); | SELECT * FROM investments WHERE investor = 'ImpactFirst' AND project_type = 'wind_farm'; |
What is the total budget for genetic research projects that started in 2020 or later in the 'GeneticResearch' schema? | CREATE SCHEMA GeneticResearch; CREATE TABLE project_budgets (project_name VARCHAR(50),start_year INT,budget DECIMAL(10,2)); INSERT INTO project_budgets VALUES ('Project1',2018,600000),('Project2',2020,900000); | SELECT SUM(budget) FROM GeneticResearch.project_budgets WHERE start_year >= 2020; |
Which are the top 3 countries with the most solar power projects? | CREATE TABLE solar_projects (project_id INT,project_name TEXT,country TEXT,capacity_mw FLOAT); INSERT INTO solar_projects (project_id,project_name,country,capacity_mw) VALUES (1,'Solarpark A','Germany',50),(2,'Solarpark B','France',75),(3,'Solarpark C','Spain',60); | SELECT country, SUM(capacity_mw) AS total_capacity FROM solar_projects GROUP BY country ORDER BY total_capacity DESC LIMIT 3; |
What is the total duration of each spacecraft's mission? | CREATE TABLE spacecraft_mission_duration (spacecraft_name TEXT,mission_name TEXT,duration INTEGER); INSERT INTO spacecraft_mission_duration (spacecraft_name,mission_name,duration) VALUES ('Voyager 1','Voyager 1 Mission',43733),('Voyager 2','Voyager 2 Mission',43710),('Cassini','Cassini Mission',67441); | SELECT spacecraft_name, SUM(duration) as total_duration FROM spacecraft_mission_duration GROUP BY spacecraft_name; |
What is the minimum number of passengers for Airbus A320 family aircraft? | CREATE TABLE aircraft_specs (id INT,aircraft_model VARCHAR(50),manufacturer VARCHAR(50),min_passengers INT); | SELECT MIN(min_passengers) FROM aircraft_specs WHERE aircraft_model LIKE 'A320%'; |
Which countries have the most critical vulnerabilities in their software systems, based on the NVD database? | CREATE TABLE nvd_vulnerabilities (id INT,cve_id VARCHAR(255),severity VARCHAR(255),publish_date DATE,description TEXT,software_vendor VARCHAR(255),software_product VARCHAR(255),country VARCHAR(255)); INSERT INTO nvd_vulnerabilities (id,cve_id,severity,publish_date,description,software_vendor,software_product,country) VALUES (1,'CVE-2021-1234','CRITICAL','2021-01-01','Description of CVE-2021-1234','Vendor1','Product1','USA'); | SELECT country, COUNT(*) as critical_vulnerabilities_count FROM nvd_vulnerabilities WHERE severity = 'CRITICAL' GROUP BY country ORDER BY critical_vulnerabilities_count DESC; |
What is the total number of orders by region? | CREATE TABLE orders (order_id INT,customer_id INT,menu_id INT,order_date DATE,region TEXT); INSERT INTO orders (order_id,customer_id,menu_id,order_date,region) VALUES (1,1,1,'2022-01-01','North'),(2,2,2,'2022-01-02','South'),(3,3,3,'2022-01-03','West'); | SELECT region, COUNT(*) as total_orders FROM orders GROUP BY region; |
Which public works projects in Europe have been ongoing for more than 5 years? | CREATE TABLE PublicWorksProjects (ProjectID INT,Name VARCHAR(255),Location VARCHAR(255),StartDate DATE,EndDate DATE,Status VARCHAR(255)); INSERT INTO PublicWorksProjects VALUES (1,'Water Treatment Plant','London,England','2016-01-01',NULL,'In Progress'); INSERT INTO PublicWorksProjects VALUES (2,'Sewer System Upgrade','Paris,France','2017-06-01','2023-12-31','In Progress'); | SELECT Name, Location FROM PublicWorksProjects WHERE Location = 'Europe' AND DATEDIFF(day, StartDate, GETDATE()) > 1825 AND Status = 'In Progress'; |
Insert new game records | CREATE TABLE games (id INT PRIMARY KEY,name VARCHAR(50),genre VARCHAR(50),release_date DATE); | INSERT INTO games (id, name, genre, release_date) VALUES (1, 'Game A', 'Action', '2022-01-01'), (2, 'Game B', 'Adventure', '2022-06-01'), (3, 'Game C', 'Strategy', '2022-12-01'); |
List all sustainable building practices with a LEED certification date in the year 2021 | CREATE TABLE sustainable_practices (project_id INT,leed_certification_date DATE); | SELECT * FROM sustainable_practices WHERE EXTRACT(YEAR FROM leed_certification_date) = 2021; |
How many articles were published per day in the month of August 2022? | CREATE TABLE articles (id INT,title VARCHAR(50),publish_date DATE); INSERT INTO articles (id,title,publish_date) VALUES (1,'Article1','2022-08-01'),(2,'Article2','2022-08-15'),(3,'Article3','2022-07-30'); | SELECT DATE_FORMAT(publish_date, '%%Y-%%m-%%d') as publish_date, COUNT(*) as articles_per_day FROM articles WHERE publish_date >= '2022-08-01' AND publish_date < '2022-09-01' GROUP BY publish_date |
How many wheelchair accessible vehicles are in the fleet? | CREATE TABLE Vehicles (id INT,fleet_number VARCHAR(255),type VARCHAR(255),year INT,wheelchair_accessible BOOLEAN); INSERT INTO Vehicles (id,fleet_number,type,year,wheelchair_accessible) VALUES (1,'V001','Bus',2018,true); | SELECT COUNT(Vehicles.id) FROM Vehicles WHERE Vehicles.wheelchair_accessible = true; |
Delete all records of 'multimodal_mobility' with a usage_count less than 50. | CREATE TABLE public.multimodal_mobility(id serial PRIMARY KEY,mode varchar(255),usage_count int); | DELETE FROM public.multimodal_mobility WHERE usage_count < 50; |
What is the total water consumption by residential sector in California and Texas? | CREATE TABLE california(state VARCHAR(20),sector VARCHAR(20),consumption NUMERIC(10,2)); INSERT INTO california VALUES ('California','Residential',2345.67); CREATE TABLE texas(state VARCHAR(20),sector VARCHAR(20),consumption NUMERIC(10,2)); INSERT INTO texas VALUES ('Texas','Residential',3456.78); | SELECT consumption FROM california WHERE state = 'California' AND sector = 'Residential' UNION ALL SELECT consumption FROM texas WHERE state = 'Texas' AND sector = 'Residential'; |
Calculate the average cost of public transportation per mile | CREATE TABLE Routes (RouteID INT,RouteName VARCHAR(50),Mode VARCHAR(50),Length FLOAT); INSERT INTO Routes (RouteID,RouteName,Mode,Length) VALUES (1,'123 Bus Line','Bus',25.0),(2,'Green Line','Light Rail',15.0),(3,'Expo Line','Light Rail',12.5),(4,'Red Line','Subway',10.0); CREATE TABLE Fares (FareID INT,RouteID INT,Fare FLOAT); INSERT INTO Fares (FareID,RouteID,Fare) VALUES (1,1,1.50),(2,1,1.50),(3,2,2.00),(4,3,1.75),(5,3,1.75),(6,4,2.50); | SELECT AVG(Fare / Length) as AverageCostPerMile FROM Routes JOIN Fares ON Routes.RouteID = Fares.RouteID WHERE Mode = 'Bus' OR Mode = 'Light Rail'; |
List the number of public services and schools in each district, ordered by population. | CREATE TABLE districts (district_id INT,district_name VARCHAR(255),population INT); CREATE TABLE public_services (service_id INT,service_name VARCHAR(255),district_id INT,budget INT); CREATE TABLE schools (school_id INT,school_name VARCHAR(255),district_id INT); | SELECT d.district_name, COUNT(DISTINCT ps.service_id) as num_services, COUNT(DISTINCT s.school_id) as num_schools FROM districts d LEFT JOIN public_services ps ON d.district_id = ps.district_id LEFT JOIN schools s ON d.district_id = s.district_id GROUP BY d.district_name ORDER BY population DESC; |
How many items were shipped from the Mumbai warehouse in March 2022? | CREATE TABLE warehouses (id INT,name VARCHAR(255)); INSERT INTO warehouses (id,name) VALUES (1,'Houston'),(2,'New York'),(3,'Mumbai'); CREATE TABLE shipments (id INT,warehouse_id INT,quantity INT,shipped_at DATETIME); INSERT INTO shipments (id,warehouse_id,quantity,shipped_at) VALUES (1,1,100,'2022-01-01 10:00:00'),(2,1,200,'2022-01-05 14:00:00'),(3,3,50,'2022-03-01 09:00:00'); | SELECT SUM(quantity) FROM shipments WHERE warehouse_id = 3 AND shipped_at BETWEEN '2022-03-01' AND '2022-03-31'; |
Which species have the highest carbon sequestration rates? | CREATE TABLE species (species_id INT,species_name TEXT);CREATE TABLE carbon_sequestration (species_id INT,sequestration_rate FLOAT); INSERT INTO species (species_id,species_name) VALUES (1,'Oak'),(2,'Pine'),(3,'Maple'); INSERT INTO carbon_sequestration (species_id,sequestration_rate) VALUES (1,12.5),(2,15.3),(3,10.8); | SELECT species_id, species_name, MAX(sequestration_rate) FROM carbon_sequestration JOIN species ON carbon_sequestration.species_id = species.species_id GROUP BY species_id, species_name; |
Count the number of traffic violations in city 'San Francisco' for the year 2020. | CREATE TABLE traffic_violations (city VARCHAR(20),year INT,violations INT); INSERT INTO traffic_violations (city,year,violations) VALUES ('San Francisco',2020,3000),('San Francisco',2019,3500),('Los Angeles',2020,4000),('Los Angeles',2019,4500); | SELECT COUNT(*) FROM traffic_violations WHERE city = 'San Francisco' AND year = 2020; |
What is the maximum amount of funds raised by the 'Red Cross' organization in the year 2020? | CREATE TABLE funds(id INT,organization TEXT,amount FLOAT,year INT); INSERT INTO funds(id,organization,amount,year) VALUES (1,'Red Cross',750000.00,2020),(2,'UNICEF',800000.00,2020),(3,'World Vision',600000.00,2019); | SELECT MAX(amount) FROM funds WHERE organization = 'Red Cross' AND year = 2020; |
List all ingredients for products certified as cruelty-free. | CREATE TABLE ingredients (id INT,product_id INT,ingredient_name TEXT,sourcing_country TEXT,cruelty_free BOOLEAN); INSERT INTO ingredients (id,product_id,ingredient_name,sourcing_country,cruelty_free) VALUES (1,1,'Beeswax','Australia',false),(2,1,'Coconut Oil','Indonesia',true),(3,2,'Shea Butter','Africa',true); | SELECT ingredient_name FROM ingredients WHERE cruelty_free = true; |
What is the percentage of mobile customers who are using 5G? | CREATE TABLE mobile_customers (customer_id INT,network VARCHAR(20)); INSERT INTO mobile_customers (customer_id,network) VALUES (1,'5G'),(2,'4G'),(3,'5G'),(4,'3G'),(5,'5G'); | SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM mobile_customers)) AS percentage FROM mobile_customers WHERE network = '5G'; |
List the names and locations of all wells that were drilled in 2019. | CREATE TABLE well_drilling (well_name VARCHAR(50),location VARCHAR(50),year INT,drilled BOOLEAN); INSERT INTO well_drilling (well_name,location,year,drilled) VALUES ('Well A','Permian Basin',2019,TRUE),('Well B','Eagle Ford',2018,TRUE); | SELECT well_name, location FROM well_drilling WHERE year = 2019 AND drilled = TRUE; |
How many marine research vessels are registered in the Caribbean, with a maximum speed of over 20 knots? | CREATE TABLE marine_research_vessels (id INT,name TEXT,max_speed FLOAT,registry TEXT); | SELECT COUNT(*) FROM marine_research_vessels WHERE max_speed > 20 AND registry = 'Caribbean'; |
What is the production trend of Samarium and Holmium from 2017 to 2020? | CREATE TABLE production (year INT,element VARCHAR(10),quantity INT); INSERT INTO production (year,element,quantity) VALUES (2017,'Samarium',800),(2018,'Samarium',850),(2019,'Samarium',900),(2020,'Samarium',950),(2017,'Holmium',1200),(2018,'Holmium',1250),(2019,'Holmium',1300),(2020,'Holmium',1350); | SELECT year, element, SUM(quantity) FROM production GROUP BY year, element; |
What is the maximum number of passengers for a commercial flight? | CREATE TABLE commercial_flights (flight_id INT,num_passengers INT); | SELECT MAX(num_passengers) FROM commercial_flights; |
What is the average number of astronauts per space mission in the SpaceMissions table? | CREATE TABLE SpaceMissions (id INT,mission VARCHAR(50),year INT,astronauts INT); INSERT INTO SpaceMissions (id,mission,year,astronauts) VALUES (1,'Apollo 11',1969,3),(2,'Apollo 13',1970,3),(3,'STS-1',1981,5); | SELECT AVG(astronauts) AS avg_astronauts_per_mission FROM SpaceMissions; |
List the top 3 donors from African countries by total donation amount. | CREATE TABLE Donors (DonorID int,DonorName varchar(50),Country varchar(50)); INSERT INTO Donors (DonorID,DonorName,Country) VALUES (1,'John Doe','United States'); INSERT INTO Donors (DonorID,DonorName,Country) VALUES (2,'Jane Smith','Nigeria'); INSERT INTO Donors (DonorID,DonorName,Country) VALUES (3,'Alice Johnson','Egypt'); CREATE TABLE Donations (DonationID int,DonorID int,DonationAmount decimal(10,2)); INSERT INTO Donations (DonationID,DonorID,DonationAmount) VALUES (1,1,5000); INSERT INTO Donations (DonationID,DonorID,DonationAmount) VALUES (2,2,3000); INSERT INTO Donations (DonationID,DonorID,DonationAmount) VALUES (3,2,1500); INSERT INTO Donations (DonationID,DonorID,DonationAmount) VALUES (4,3,2000); INSERT INTO Donations (DonationID,DonorID,DonationAmount) VALUES (5,4,3000); | SELECT Donors.DonorName, SUM(Donations.DonationAmount) as TotalDonatedAmount FROM Donors INNER JOIN Donations ON Donations.DonorID = Donors.DonorID WHERE Donors.Country IN ('Nigeria', 'Egypt') GROUP BY Donors.DonorName ORDER BY TotalDonatedAmount DESC LIMIT 3; |
What is the average severity score for vulnerabilities in the 'vuln_assessments' table that were discovered in the last month? | CREATE TABLE vuln_assessments (id INT PRIMARY KEY,vulnerability_name TEXT,severity FLOAT,date_discovered DATE); | SELECT AVG(severity) FROM vuln_assessments WHERE date_discovered > NOW() - INTERVAL 1 MONTH; |
How many products have been discontinued for each brand? | CREATE TABLE product_status (id INT,brand VARCHAR(255),is_discontinued BOOLEAN); INSERT INTO product_status (id,brand,is_discontinued) VALUES (1,'Lush',false),(2,'The Body Shop',false),(3,'Sephora',true),(4,'Lush',true),(5,'The Body Shop',true); | SELECT brand, COUNT(*) as discontinued_products FROM product_status WHERE is_discontinued = true GROUP BY brand; |
Who are the top 5 refugee support project coordinators in terms of the number of refugees supported? | CREATE TABLE refugee_support_project_coordinators (id INT,name VARCHAR(100),num_refugees INT); INSERT INTO refugee_support_project_coordinators (id,name,num_refugees) VALUES (1,'Coordinator A',500),(2,'Coordinator B',300),(3,'Coordinator C',700),(4,'Coordinator D',1000),(5,'Coordinator E',250); | SELECT name FROM (SELECT name, ROW_NUMBER() OVER (ORDER BY num_refugees DESC) as row FROM refugee_support_project_coordinators) subquery WHERE subquery.row <= 5; |
How many accidents were reported by vessels with the prefix 'CMB' in the North Sea from 2015 to 2018? | CREATE TABLE Vessels (ID INT,Name TEXT,Accidents INT,Prefix TEXT,Year INT);CREATE VIEW North_Sea_Vessels AS SELECT * FROM Vessels WHERE Region = 'North Sea'; | SELECT SUM(Accidents) FROM North_Sea_Vessels WHERE Prefix = 'CMB' AND Year BETWEEN 2015 AND 2018; |
What is the total funding received by startups founded by BIPOC individuals before 2015? | CREATE TABLE startups(id INT,name TEXT,founder_ethnicity TEXT,funding FLOAT,founding_year INT); INSERT INTO startups VALUES (1,'StartupC','BIPOC',8000000,2012); | SELECT SUM(funding) FROM startups WHERE founder_ethnicity = 'BIPOC' AND founding_year < 2015; |
Views per hour for a specific TV show? | CREATE TABLE TV_Show_Views (id INT,show_title VARCHAR(100),view_time TIME,views INT); | SELECT view_time, SUM(views) FROM TV_Show_Views WHERE show_title = 'Stranger Things' GROUP BY view_time; |
Find the average carbon sequestration for forests in each region. | CREATE TABLE regions (id INT,name VARCHAR(255)); INSERT INTO regions (id,name) VALUES (1,'North'),(2,'South'); CREATE TABLE forests (id INT,region_id INT,carbon_sequestration FLOAT); INSERT INTO forests (id,region_id,carbon_sequestration) VALUES (1,1,120.5),(2,1,150.2),(3,2,75.9),(4,2,85.4); | SELECT r.name, AVG(f.carbon_sequestration) FROM regions r JOIN forests f ON r.id = f.region_id GROUP BY r.name; |
What is the total duration of all human spaceflights? | CREATE TABLE human_spaceflights (id INT,flight_name VARCHAR(50),start_date DATE,end_date DATE,duration INT); | SELECT SUM(duration) FROM human_spaceflights; |
Who are the top 2 intelligence agencies by the number of operations conducted in Europe? | CREATE TABLE IntelligenceAgencies(id INT PRIMARY KEY,name VARCHAR(50),location VARCHAR(50),operations INT);INSERT INTO IntelligenceAgencies(id,name,location,operations) VALUES (1,'CIA','Europe',120),(2,'MI6','Europe',150),(3,'Mossad','Middle East',200); | SELECT name, operations FROM IntelligenceAgencies WHERE location = 'Europe' ORDER BY operations DESC LIMIT 2; |
What is the maximum water usage in MWh in a single month for the agricultural sector in 2020? | CREATE TABLE max_water_usage_per_month (year INT,sector VARCHAR(20),month INT,usage FLOAT); INSERT INTO max_water_usage_per_month (year,sector,month,usage) VALUES (2020,'agricultural',1,10000); INSERT INTO max_water_usage_per_month (year,sector,month,usage) VALUES (2020,'agricultural',2,12000); INSERT INTO max_water_usage_per_month (year,sector,month,usage) VALUES (2020,'agricultural',3,15000); | SELECT MAX(usage) FROM max_water_usage_per_month WHERE year = 2020 AND sector = 'agricultural'; |
What is the total number of visitors who attended exhibitions in Mumbai with an entry fee below 5? | CREATE TABLE Exhibitions (exhibition_id INT,location VARCHAR(20),entry_fee INT); INSERT INTO Exhibitions (exhibition_id,location,entry_fee) VALUES (1,'Mumbai',0),(2,'Mumbai',4),(3,'Mumbai',10); CREATE TABLE Visitors (visitor_id INT,exhibition_id INT); INSERT INTO Visitors (visitor_id,exhibition_id) VALUES (1,1),(2,1),(3,1),(4,2),(5,3),(6,3); | SELECT COUNT(DISTINCT visitor_id) FROM Visitors v JOIN Exhibitions e ON v.exhibition_id = e.exhibition_id WHERE e.location = 'Mumbai' AND e.entry_fee < 5; |
What is the average carbon price (in USD) in the European Union Emissions Trading System? | CREATE TABLE carbon_prices (region VARCHAR(20),price FLOAT); INSERT INTO carbon_prices (region,price) VALUES ('European Union Emissions Trading System',25.0),('European Union Emissions Trading System',24.0),('European Union Emissions Trading System',26.0); | SELECT AVG(price) FROM carbon_prices WHERE region = 'European Union Emissions Trading System'; |
What is the difference in average temperature between the hottest and coldest days for each region in the past week? | CREATE TABLE daily_temp_data (region VARCHAR(255),temperature INT,date DATE); INSERT INTO daily_temp_data (region,temperature,date) VALUES ('North',25,'2022-06-01'),('South',10,'2022-06-01'),('East',15,'2022-06-01'),('West',30,'2022-06-01'),('North',20,'2022-06-02'),('South',12,'2022-06-02'),('East',18,'2022-06-02'),('West',28,'2022-06-02'); | SELECT region, MAX(temperature) - MIN(temperature) as temp_diff FROM daily_temp_data WHERE date BETWEEN '2022-06-01' AND '2022-06-07' GROUP BY region; |
What is the total number of professional development hours completed by teachers in each subject area? | CREATE TABLE teacher_pd (teacher_id INT,subject_area VARCHAR(255),hours INT); INSERT INTO teacher_pd (teacher_id,subject_area,hours) VALUES (1,'Math',10),(2,'Science',15),(3,'Math',12),(4,'English',18),(5,'Science',20); | SELECT subject_area, SUM(hours) as total_hours FROM teacher_pd GROUP BY subject_area; |
What is the defense spending trend for South America from 2015 to 2020? | CREATE TABLE defense_spending_trend (year INT,region VARCHAR(50),spending NUMERIC(10,2)); INSERT INTO defense_spending_trend (year,region,spending) VALUES (2015,'South America',4000000000),(2016,'South America',4500000000),(2017,'South America',5000000000),(2018,'South America',5500000000),(2019,'South America',6000000000),(2020,'South America',6500000000); | SELECT year, spending FROM defense_spending_trend WHERE region = 'South America' ORDER BY year; |
What are the top 3 countries with the most diverse cultural heritage in Oceania and the number of their heritage sites? | CREATE TABLE Countries (id INT,name TEXT); INSERT INTO Countries (id,name) VALUES (1,'Australia'); CREATE TABLE CountryHeritages (id INT,country_id INT,heritage_site TEXT); INSERT INTO CountryHeritages (id,country_id,heritage_site) VALUES (1,1,'Sydney Opera House'); | SELECT C.name, COUNT(*) FROM Countries C INNER JOIN CountryHeritages CH ON C.id = CH.country_id GROUP BY C.name ORDER BY COUNT(*) DESC LIMIT 3; |
Identify top 5 customers by total transactions in H1 2022. | CREATE TABLE customers (customer_id INT,customer_name TEXT,transactions INT); CREATE TABLE customer_transactions (transaction_id INT,customer_id INT,transaction_date DATE); | SELECT customer_name, SUM(transactions) FROM customers c JOIN customer_transactions t ON c.customer_id = t.customer_id WHERE transaction_date BETWEEN '2022-01-01' AND '2022-06-30' GROUP BY customer_id ORDER BY SUM(transactions) DESC LIMIT 5; |
What is the average defense spending by the top 3 countries with the highest military expenditure in 2022? | CREATE TABLE DefenseSpending (CountryName VARCHAR(50),Year INT,Spending DECIMAL(18,2)); INSERT INTO DefenseSpending (CountryName,Year,Spending) VALUES ('USA',2022,800000000000),('China',2022,280000000000),('Russia',2022,70000000000),('India',2022,75000000000),('Saudi Arabia',2022,70000000000); | SELECT AVG(Spending) FROM DefenseSpending WHERE Year = 2022 QUALIFY ROW_NUMBER() OVER (ORDER BY Spending DESC) <= 3; |
What is the percentage of female workers in each department? | CREATE TABLE employee (id INT,name TEXT,department TEXT,role TEXT,gender TEXT); INSERT INTO employee (id,name,department,role,gender) VALUES (1,'John Doe','Mining','Operator','Male'),(2,'Jane Smith','Environment','Analyst','Female'); | SELECT department, ROUND(100.0 * SUM(CASE WHEN gender = 'Female' THEN 1 ELSE 0 END) / COUNT(*) , 2) as percentage_female FROM employee GROUP BY department; |
Identify crops that are present in both indoor and outdoor farming methods. | CREATE TABLE Crops (name VARCHAR(50),farming_method VARCHAR(50)); INSERT INTO Crops (name,farming_method) VALUES ('Lettuce','Indoor'),('Strawberries','Outdoor'),('Spinach','Indoor'); | SELECT name FROM Crops WHERE farming_method IN ('Indoor', 'Outdoor') GROUP BY name HAVING COUNT(DISTINCT farming_method) = 2 |
Delete drug sales for DrugC in Q3 2018. | CREATE TABLE sales_figures (quarter INT,drug_name VARCHAR(255),sales_amount FLOAT); INSERT INTO sales_figures (quarter,drug_name,sales_amount) VALUES (1,'DrugB',45000),(1,'DrugA',40000),(2,'DrugA',55000),(2,'DrugB',65000),(3,'DrugC',75000); | DELETE FROM sales_figures WHERE drug_name = 'DrugC' AND quarter = 3; |
Calculate the average CO2 emissions reduction (in metric tons) for Electric Vehicle charging stations in each state | CREATE TABLE ev_charging_stations (id INT,state VARCHAR(50),name VARCHAR(100),co2_emissions_reduction_tons FLOAT); | SELECT state, AVG(co2_emissions_reduction_tons) FROM ev_charging_stations GROUP BY state; |
How many Boeing 737 MAX aircraft have been manufactured to date? | CREATE TABLE Boeing737MAX (id INT,manufactured_date DATE); | SELECT COUNT(*) FROM Boeing737MAX WHERE manufactured_date IS NOT NULL; |
What is the total cost of Mars missions by NASA? | CREATE TABLE mars_missions (id INT,agency VARCHAR(50),mission VARCHAR(50),cost FLOAT,launch_year INT);INSERT INTO mars_missions (id,agency,mission,cost,launch_year) VALUES (1,'NASA','Mars Pathfinder',269.0,1996); | SELECT SUM(cost) FROM mars_missions WHERE agency = 'NASA'; |
Display the billing amount for each case | CREATE TABLE cases (id INT,case_number VARCHAR(20),billing_amount DECIMAL(10,2)); INSERT INTO cases (id,case_number,billing_amount) VALUES (1,'12345',5000.00); INSERT INTO cases (id,case_number,billing_amount) VALUES (2,'54321',3000.00); INSERT INTO cases (id,case_number,billing_amount) VALUES (3,'98765',7000.00); | SELECT case_number, billing_amount FROM cases; |
List the top 5 streamed songs for each genre. | CREATE TABLE artists (id INT PRIMARY KEY,name VARCHAR(255),genre VARCHAR(255),country VARCHAR(255)); CREATE TABLE songs (id INT PRIMARY KEY,title VARCHAR(255),artist_id INT,released DATE); CREATE TABLE streams (id INT PRIMARY KEY,song_id INT,user_id INT,stream_date DATE,FOREIGN KEY (song_id) REFERENCES songs(id)); CREATE TABLE users (id INT PRIMARY KEY,gender VARCHAR(50),age INT); CREATE VIEW top_streamed_songs_per_genre AS SELECT genre,songs.title,COUNT(streams.id) AS total_streams FROM songs JOIN artists ON songs.artist_id = artists.id JOIN streams ON songs.id = streams.song_id GROUP BY genre,songs.title ORDER BY total_streams DESC; | SELECT genre, title, total_streams FROM top_streamed_songs_per_genre WHERE row_number() OVER (PARTITION BY genre ORDER BY total_streams DESC) <= 5; |
List all spacecraft involved in Mars missions, along with the mission start and end dates. | CREATE TABLE Spacecraft (id INT,name VARCHAR(50),manufacturer VARCHAR(50),type VARCHAR(50),launch_date DATE); INSERT INTO Spacecraft (id,name,manufacturer,type,launch_date) VALUES (1,'Spirit','NASA','Mars Rover','2003-06-10'),(2,'Opportunity','NASA','Mars Rover','2003-07-07'),(3,'Perseverance','NASA','Mars Rover','2020-07-30'); CREATE TABLE SpaceMissions (id INT,name VARCHAR(50),spacecraft_id INT,start_date DATE,end_date DATE); INSERT INTO SpaceMissions (id,name,spacecraft_id,start_date,end_date) VALUES (1,'Mars Exploration Rover',1,'2004-01-04','2018-05-24'),(2,'Mars Exploration Rover',2,'2004-01-25','2018-06-13'),(3,'Mars 2020',3,'2021-02-18','ONGOING'); | SELECT s.name, s.manufacturer, sm.start_date, sm.end_date FROM Spacecraft s JOIN SpaceMissions sm ON s.id = sm.spacecraft_id WHERE s.type = 'Mars Rover'; |
What is the maximum fine for violating travel advisories in Canada? | CREATE TABLE travel_advisories (advisory_id INT,country TEXT,advisory_level INT,fine FLOAT); INSERT INTO travel_advisories (advisory_id,country,advisory_level,fine) VALUES (1,'Canada',3,5000),(2,'Mexico',4,10000),(3,'Brazil',2,2000),(4,'Argentina',1,1000); | SELECT MAX(fine) FROM travel_advisories WHERE country = 'Canada'; |
Find the total sales revenue for each brand and their average sales revenue? | CREATE TABLE sales(sale_id INT,brand VARCHAR(255),revenue DECIMAL(5,2));INSERT INTO sales (sale_id,brand,revenue) VALUES (1,'Brand A',5000),(2,'Brand B',7500),(3,'Brand A',6000),(4,'Brand C',4000),(5,'Brand B',8000); | SELECT brand, AVG(revenue) as avg_revenue, SUM(revenue) as total_revenue FROM sales GROUP BY brand; |
Update the country column in the peacekeeping_operations table to uppercase for all records in Africa | CREATE TABLE peacekeeping_operations (operation_id INT,operation_name VARCHAR(50),country VARCHAR(50),start_date DATE,end_date DATE,operation_description TEXT); | UPDATE peacekeeping_operations SET country = UPPER(country) WHERE country = 'africa'; |
What is the total number of DApps launched in the 'polygon' network? | CREATE TABLE dapps (id INT,network VARCHAR(20),dapp_count INT); INSERT INTO dapps (id,network,dapp_count) VALUES (1,'polygon',1500); | SELECT SUM(dapp_count) FROM dapps WHERE network = 'polygon'; |
What is the most popular game genre among players from Asia? | CREATE TABLE Players (PlayerID INT,Age INT,Country VARCHAR(20),GamePreference VARCHAR(20)); INSERT INTO Players (PlayerID,Age,Country,GamePreference) VALUES (1,25,'Japan','RPG'); | SELECT GamePreference, COUNT(*) FROM Players WHERE Country LIKE 'Asia%' GROUP BY GamePreference ORDER BY COUNT(*) DESC LIMIT 1; |
What is the maximum billing amount for cases handled by attorneys in the 'Chicago' region? | CREATE TABLE cases (id INT,attorney_id INT,billing_amount INT); INSERT INTO cases (id,attorney_id,billing_amount) VALUES (1,1,5000); CREATE TABLE attorneys (id INT,name TEXT,region TEXT,title TEXT); INSERT INTO attorneys (id,name,region,title) VALUES (1,'Jim Brown','Chicago','Partner'); | SELECT MAX(billing_amount) FROM cases JOIN attorneys ON cases.attorney_id = attorneys.id WHERE attorneys.region = 'Chicago'; |
Find the number of unique users who have streamed or downloaded music from the classical genre, and the total sales for that genre. | CREATE TABLE users (user_id INT,genre VARCHAR(10),action VARCHAR(10)); CREATE TABLE sales (sale_id INT,genre VARCHAR(10),platform VARCHAR(10),sales FLOAT); | SELECT (SELECT COUNT(DISTINCT user_id) FROM users WHERE genre = 'classical') AS unique_users, SUM(sales) AS total_sales FROM sales WHERE genre = 'classical'; |
What is the impact area with the least number of strategies? | CREATE TABLE strategies (id INT,impact_area VARCHAR(30),investment_id INT); INSERT INTO strategies (id,impact_area,investment_id) VALUES (1,'Education',1),(2,'Healthcare',1),(3,'Health Clinics',2),(4,'Tutoring Programs',3),(5,'Capacity Building',3),(6,'Sustainable Agriculture',4); | SELECT impact_area, COUNT(*) as strategy_count FROM strategies GROUP BY impact_area ORDER BY strategy_count ASC LIMIT 1; |
What was the average donation amount in each country in Q1 2021? | CREATE TABLE Donations (DonationID int,Country varchar(50),AmountDonated numeric(10,2),DonationDate date); INSERT INTO Donations (DonationID,Country,AmountDonated,DonationDate) VALUES (1,'Mexico',100.00,'2021-01-01'),(2,'Brazil',150.00,'2021-04-30'); | SELECT Country, AVG(AmountDonated) as AvgDonation FROM Donations WHERE DonationDate BETWEEN '2021-01-01' AND '2021-03-31' GROUP BY Country; |
Find the total dissolved oxygen levels in fish farms located in the Indian Ocean. | CREATE TABLE oceanic_farms (id INT,name TEXT,country TEXT,dissolved_oxygen FLOAT); CREATE TABLE country_oceans (country TEXT,ocean TEXT); INSERT INTO oceanic_farms (id,name,country,dissolved_oxygen) VALUES (1,'Farm L','Indian Ocean Country',6.5),(2,'Farm M','Indian Ocean Country',7.0),(3,'Farm N','Atlantic Ocean Country',7.5); INSERT INTO country_oceans (country,ocean) VALUES ('Indian Ocean Country','Indian Ocean'); | SELECT SUM(dissolved_oxygen) FROM oceanic_farms OF JOIN country_oceans CO ON OF.country = CO.country WHERE CO.ocean = 'Indian Ocean'; |
List all sports in 'team_performances_table' and their respective total wins | CREATE TABLE team_performances_table (team_id INT,team_name VARCHAR(50),sport VARCHAR(20),wins INT,losses INT); INSERT INTO team_performances_table (team_id,team_name,sport,wins,losses) VALUES (1,'Blue Lions','Basketball',25,15); INSERT INTO team_performances_table (team_id,team_name,sport,wins,losses) VALUES (2,'Green Devils','Soccer',12,8); | SELECT sport, SUM(wins) AS total_wins FROM team_performances_table GROUP BY sport; |
What are the top 3 countries with the most reported malware incidents in the last quarter? | CREATE TABLE MalwareIncidents (incident_id INT,incident_country VARCHAR(50),incident_date DATE); | SELECT incident_country, COUNT(*) FROM MalwareIncidents WHERE incident_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH) AND CURRENT_DATE GROUP BY incident_country ORDER BY COUNT(*) DESC LIMIT 3; |
What is the total revenue for each route segment in the 'route_segments' table? | CREATE TABLE route_segments (route_segment_id INT,route_id INT,start_station VARCHAR(50),end_station VARCHAR(50),fare FLOAT,distance FLOAT); INSERT INTO route_segments (route_segment_id,route_id,start_station,end_station,fare,distance) VALUES (1,101,'StationA','StationB',2.50,12.0); | SELECT route_id, SUM(fare) as total_revenue FROM route_segments GROUP BY route_id; |
Delete all records for virtual tours from the database. | CREATE TABLE tours (id INT,name TEXT,location TEXT,type TEXT); INSERT INTO tours (id,name,location,type) VALUES (1,'Virtual Tour of the Great Wall','China','Virtual'),(2,'Virtual Tour of the Louvre','Paris','Virtual'); | DELETE FROM tours WHERE type = 'Virtual'; |
What is the maximum retail price of eco-friendly footwear in France? | CREATE TABLE footwear_sales (id INT,footwear_type VARCHAR(50),eco_friendly BOOLEAN,price DECIMAL(5,2),country VARCHAR(50)); INSERT INTO footwear_sales (id,footwear_type,eco_friendly,price,country) VALUES (1,'Sneakers',true,120.00,'France'); | SELECT MAX(price) FROM footwear_sales WHERE footwear_type = 'Sneakers' AND eco_friendly = true AND country = 'France'; |
What is the total number of streams for pop songs released before 2019? | CREATE TABLE songs (song_id INT,genre VARCHAR(20),release_year INT,streams INT); INSERT INTO songs (song_id,genre,release_year,streams) VALUES (1,'pop',2018,1000); INSERT INTO songs (song_id,genre,release_year,streams) VALUES (2,'pop',2017,2000); INSERT INTO songs (song_id,genre,release_year,streams) VALUES (3,'pop',2016,3000); | SELECT SUM(streams) FROM songs WHERE genre = 'pop' AND release_year < 2019; |
What is the total budget allocated for 'Green Spaces' maintenance? | CREATE TABLE City_Budget (budget_id INT,category VARCHAR(50),allocated_amount DECIMAL(10,2),PRIMARY KEY (budget_id)); INSERT INTO City_Budget (budget_id,category,allocated_amount) VALUES (1,'Road maintenance',500000.00),(2,'Street cleaning',350000.00),(3,'Green Spaces',700000.00); | SELECT SUM(allocated_amount) FROM City_Budget WHERE category = 'Green Spaces'; |
What is the maximum function length of genes associated with a biosensor of type 'Temperature'? | CREATE TABLE biosensor (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255),company_id INT); CREATE TABLE gene (id INT PRIMARY KEY,name VARCHAR(255),function VARCHAR(255),company_id INT,biosensor_id INT); INSERT INTO biosensor (id,name,type,company_id) VALUES (1,'BioSensor1','pH',2),(2,'BioSensor2','Temperature',1); INSERT INTO gene (id,name,function,company_id,biosensor_id) VALUES (1,'GeneA','Growth (short)',1,2),(2,'GeneB','Metabolism (medium length)',1,2),(3,'GeneC','Development (long)',1,2); | SELECT MAX(LENGTH(function)) FROM gene g JOIN biosensor b ON g.biosensor_id = b.id WHERE b.type = 'Temperature'; |
What is the total number of legal cases handled by each law firm, with a value over $100,000, in the past year? | CREATE TABLE legal_cases (id INT,value DECIMAL(10,2),case_date DATE,law_firm VARCHAR(50)); | SELECT law_firm, COUNT(*) FROM legal_cases WHERE value > 100000 AND case_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY law_firm HAVING COUNT(*) > 0; |
What is the average billing amount per case, grouped by case type? | CREATE TABLE cases (case_id INT,case_type TEXT,attorney_id INT,total_billing_amount DECIMAL); | SELECT case_type, AVG(total_billing_amount) AS avg_billing_per_case FROM cases GROUP BY case_type |
Find the top 3 mines with the highest CO2 emissions in the 'environmental_impact' table. | CREATE TABLE environmental_impact (mine_id INT,year INT,co2_emissions INT,methane_emissions INT,waste_generation INT); INSERT INTO environmental_impact (mine_id,year,co2_emissions,methane_emissions,waste_generation) VALUES (1,2020,5000,2000,15000); INSERT INTO environmental_impact (mine_id,year,co2_emissions,methane_emissions,waste_generation) VALUES (2,2020,6000,2500,18000); INSERT INTO environmental_impact (mine_id,year,co2_emissions,methane_emissions,waste_generation) VALUES (3,2020,7000,3000,20000); | SELECT mine_id, SUM(co2_emissions) FROM environmental_impact GROUP BY mine_id ORDER BY SUM(co2_emissions) DESC LIMIT 3; |
What are the names of all suppliers providing materials to brands with a sustainability score above 80? | CREATE TABLE Suppliers (SupplierID INT,SupplierName VARCHAR(50),Location VARCHAR(50)); INSERT INTO Suppliers (SupplierID,SupplierName,Location) VALUES (1,'Supplier1','Location1'),(2,'Supplier2','Location2'); CREATE TABLE Brands (BrandID INT,BrandName VARCHAR(50),SustainabilityScore INT); INSERT INTO Brands (BrandID,BrandName,SustainabilityScore) VALUES (1,'Brand1',85),(2,'Brand2',70); CREATE TABLE BrandSupplier (BrandID INT,SupplierID INT); INSERT INTO BrandSupplier (BrandID,SupplierID) VALUES (1,1),(1,2); | SELECT SupplierName FROM Suppliers INNER JOIN BrandSupplier ON Suppliers.SupplierID = BrandSupplier.SupplierID INNER JOIN Brands ON BrandSupplier.BrandID = Brands.BrandID WHERE Brands.SustainabilityScore > 80; |
What is the minimum number of workers on a single project in the state of New York? | CREATE TABLE Projects (project_id INT,state VARCHAR(255),num_workers INT); INSERT INTO Projects (project_id,state,num_workers) VALUES (1,'New York',10),(2,'New York',5); | SELECT MIN(num_workers) FROM Projects WHERE state = 'New York'; |
What is the total transaction volume for each customer in the past month, grouped by currency? | CREATE TABLE customers (customer_id INT,name VARCHAR(255)); CREATE TABLE transactions (transaction_id INT,customer_id INT,amount DECIMAL(10,2),currency VARCHAR(3),transaction_date DATE); | SELECT c.customer_id, c.name, t.currency, SUM(t.amount) as total_transaction_volume FROM customers c INNER JOIN transactions t ON c.customer_id = t.customer_id WHERE t.transaction_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY c.customer_id, t.currency; |
How many unique visitors have attended events at 'Art Gallery' in 2021? | CREATE TABLE if not exists venue (id INT,name VARCHAR(50)); CREATE TABLE if not exists event_calendar (id INT,venue_id INT,event_date DATE); INSERT INTO venue (id,name) VALUES (1,'Art Gallery'); INSERT INTO event_calendar (id,venue_id,event_date) VALUES (1,1,'2021-01-01'),(2,1,'2021-03-12'),(3,1,'2022-05-28'); | SELECT COUNT(DISTINCT e.id) FROM event_calendar ec JOIN (SELECT DISTINCT id FROM event_attendees) e ON ec.id = e.id WHERE ec.venue_id = (SELECT id FROM venue WHERE name = 'Art Gallery') AND ec.event_date BETWEEN '2021-01-01' AND '2021-12-31'; |
Find the number of unique ethical clothing brands available in each country. | CREATE TABLE ethical_brands (brand_id INT,brand_name TEXT,product_category TEXT); INSERT INTO ethical_brands (brand_id,brand_name,product_category) VALUES (1,'BrandA','Clothing'),(2,'BrandB','Electronics'),(3,'BrandC','Clothing'); CREATE TABLE sales (sale_id INT,brand_id INT,country TEXT); INSERT INTO sales (sale_id,brand_id,country) VALUES (1,1,'Germany'),(2,2,'France'),(3,3,'Germany'); | SELECT country, COUNT(DISTINCT brand_id) FROM sales JOIN ethical_brands ON sales.brand_id = ethical_brands.brand_id WHERE ethical_brands.product_category = 'Clothing' GROUP BY country; |
What is the total number of dental visits in the rural areas of "New York" and "New Jersey" for patients aged 60 and above? | CREATE TABLE dental_visits (visit_id INT,patient_id INT,visit_date DATE,location TEXT); INSERT INTO dental_visits (visit_id,patient_id,visit_date,location) VALUES (1,1,'2022-01-01','New York'); CREATE TABLE patient (patient_id INT,patient_name TEXT,age INT,gender TEXT,location TEXT); INSERT INTO patient (patient_id,patient_name,age,gender,location) VALUES (1,'Jane Doe',65,'Female','New York'); | SELECT SUM(visits) FROM (SELECT patient_id, COUNT(*) as visits FROM dental_visits WHERE location IN ('New York', 'New Jersey') AND patient.age >= 60 GROUP BY patient_id) as subquery; |
Which artifacts from 'Site C' have a weight greater than 20? | CREATE TABLE Site (SiteID VARCHAR(10),SiteName VARCHAR(20)); INSERT INTO Site (SiteID,SiteName) VALUES ('C','Site C'); CREATE TABLE Artifact (ArtifactID VARCHAR(10),SiteID VARCHAR(10),Weight FLOAT); INSERT INTO Artifact (ArtifactID,SiteID,Weight) VALUES ('1','C',12.3),('2','C',25.6),('3','C',18.9),('4','C',9.7); | SELECT ArtifactID, Weight FROM Artifact WHERE SiteID = 'C' AND Weight > 20; |
What is the total number of emergency calls during rush hours in 'Bronx'? | CREATE TABLE emergencies (id INT,hour INT,neighborhood VARCHAR(20),response_time FLOAT); INSERT INTO emergencies (id,hour,neighborhood,response_time) VALUES (1,8,'Bronx',12.5),(2,17,'Bronx',9.3),(3,17,'Downtown',10.1),(4,17,'Bronx',11.8),(5,8,'Bronx',13.9); | SELECT COUNT(*) FROM emergencies WHERE neighborhood = 'Bronx' AND hour IN (7, 8, 16, 17, 18); |
What are the call types and dates for calls in the 'forest_rangers' table that occurred on '2022-01-03'? | CREATE TABLE forest_rangers (id INT,call_type VARCHAR(20),call_date TIMESTAMP); INSERT INTO forest_rangers VALUES (1,'camping','2022-01-03 21:00:00'); | SELECT call_type, call_date FROM forest_rangers WHERE DATE(call_date) = '2022-01-03'; |
What is the total size of all green buildings in each city? | CREATE TABLE City (id INT,name VARCHAR(255),population INT,renewable_energy_projects INT); INSERT INTO City (id,name,population,renewable_energy_projects) VALUES (1,'San Francisco',874000,250); INSERT INTO City (id,name,population,renewable_energy_projects) VALUES (2,'New York',8500000,1200); CREATE TABLE Building (id INT,name VARCHAR(255),city_id INT,size INT,is_green_building BOOLEAN); INSERT INTO Building (id,name,city_id,size,is_green_building) VALUES (1,'City Hall',1,10000,true); INSERT INTO Building (id,name,city_id,size,is_green_building) VALUES (2,'Empire State Building',2,200000,false); | SELECT c.name, SUM(b.size) FROM Building b JOIN City c ON b.city_id = c.id WHERE is_green_building = true GROUP BY c.name; |
How many vessels have been inspected in the Mediterranean sea? | CREATE TABLE vessels_2 (name VARCHAR(255),type VARCHAR(255),flag_state VARCHAR(255)); CREATE TABLE inspections_2 (inspection_id INT,vessel_name VARCHAR(255),inspection_date DATE,region VARCHAR(255)); CREATE TABLE mediterranean_sea (name VARCHAR(255),region_type VARCHAR(255)); INSERT INTO vessels_2 (name,type,flag_state) VALUES ('VESSEL4','Cargo','Italy'),('VESSEL5','Passenger','Spain'); INSERT INTO inspections_2 (inspection_id,vessel_name,inspection_date,region) VALUES (3,'VESSEL4','2022-03-01','Mediterranean Sea'),(4,'VESSEL6','2022-04-01','Mediterranean Sea'); INSERT INTO mediterranean_sea (name,region_type) VALUES ('VESSEL4','Mediterranean Sea'); | SELECT COUNT(*) FROM inspections_2 i INNER JOIN mediterranean_sea cs ON i.region = cs.name; |
List companies in the 'Energy' sector with ESG scores below the sector average for 2022. | CREATE TABLE companies (id INT,name VARCHAR(255),sector VARCHAR(255),ESG_score FLOAT,year INT); INSERT INTO companies (id,name,sector,ESG_score,year) VALUES (1,'GreenEnergy','Energy',87.5,2022); INSERT INTO companies (id,name,sector,ESG_score,year) VALUES (2,'CleanEnergy','Energy',86.0,2022); INSERT INTO companies (id,name,sector,ESG_score,year) VALUES (3,'RenewableEnergy','Energy',88.0,2022); INSERT INTO companies (id,name,sector,ESG_score,year) VALUES (4,'SustainableEnergy','Energy',89.5,2022); | SELECT * FROM companies WHERE sector = 'Energy' AND ESG_score < (SELECT AVG(ESG_score) FROM companies WHERE sector = 'Energy' AND year = 2022); |
How many unique investments are made in each country? | CREATE TABLE countries (id INT,name VARCHAR(50),region VARCHAR(30)); CREATE TABLE investments (id INT,country_id INT,sector VARCHAR(20),amount DECIMAL(10,2)); INSERT INTO countries (id,name,region) VALUES (1,'Brazil','South America'),(2,'Canada','North America'),(3,'India','Asia'),(4,'Germany','Europe'); INSERT INTO investments (id,country_id,sector,amount) VALUES (1,1,'Education',5000.00),(2,2,'Healthcare',7000.00),(3,3,'Education',6000.00),(4,2,'Healthcare',8000.00),(5,3,'Education',9000.00); | SELECT c.name, COUNT(DISTINCT i.id) as investment_count FROM countries c INNER JOIN investments i ON c.id = i.country_id GROUP BY c.name; |
Delete all records of funiculars in the 'Istanbul' region with a fare less than 5.00. | CREATE TABLE funiculars (id INT,region VARCHAR(20),fare DECIMAL(5,2)); INSERT INTO funiculars (id,region,fare) VALUES (1,'Istanbul',4.00),(2,'Istanbul',6.00),(3,'Ankara',5.00); | DELETE FROM funiculars WHERE region = 'Istanbul' AND fare < 5.00; |
What is the most common art movement in the database? | CREATE TABLE Artworks (artwork_name VARCHAR(255),creation_date DATE,movement VARCHAR(255)); INSERT INTO Artworks (artwork_name,creation_date,movement) VALUES ('The Night Watch','1642-02-01','Baroque'),('Girl with a Pearl Earring','1665-06-22','Dutch Golden Age'),('The Persistence of Memory','1931-08-01','Surrealism'),('The Birth of Venus','1485-01-01','Renaissance'),('The Scream','1893-05-22','Expressionism'); | SELECT movement, COUNT(*) as count FROM Artworks GROUP BY movement ORDER BY count DESC LIMIT 1; |
Who are the male R&B artists with the lowest ticket sales? | CREATE TABLE Artists (ArtistID INT PRIMARY KEY,ArtistName VARCHAR(100),Gender VARCHAR(10),Genre VARCHAR(50),TicketsSold INT); INSERT INTO Artists (ArtistID,ArtistName,Gender,Genre,TicketsSold) VALUES (1,'Artist A','Male','R&B',300),(2,'Artist B','Female','Jazz',400),(3,'Artist C','Female','Pop',500),(4,'Artist D','Male','R&B',200),(5,'Artist E','Non-binary','Electronic',600); | SELECT ArtistName FROM Artists WHERE Gender = 'Male' AND Genre = 'R&B' ORDER BY TicketsSold LIMIT 1; |
Get defense contracts awarded in California | CREATE TABLE defense_contracts (contract_id INTEGER PRIMARY KEY,contract_name TEXT,contract_value REAL,state TEXT); | SELECT * FROM defense_contracts WHERE state = 'California'; |
How many tons of Dysprosium were produced in Q1 and Q3 of 2019? | CREATE TABLE production (year INT,element VARCHAR(10),quarter INT,quantity INT); INSERT INTO production (year,element,quarter,quantity) VALUES (2019,'Dysprosium',1,1500); INSERT INTO production (year,element,quarter,quantity) VALUES (2019,'Dysprosium',3,1800); | SELECT SUM(quantity) FROM production WHERE year = 2019 AND element = 'Dysprosium' AND quarter IN (1, 3); |
Identify regulatory frameworks in the US and their respective digital assets. | CREATE TABLE DigitalAssets (AssetId INT,AssetName VARCHAR(50),RegulatorId INT); CREATE TABLE Regulators (RegulatorId INT,RegulatorName VARCHAR(50),Region VARCHAR(50)); INSERT INTO DigitalAssets (AssetId,AssetName,RegulatorId) VALUES (1,'ETH',1); INSERT INTO DigitalAssets (AssetId,AssetName,RegulatorId) VALUES (2,'BTC',2); INSERT INTO DigitalAssets (AssetId,AssetName,RegulatorId) VALUES (3,'LTC',3); INSERT INTO Regulators (RegulatorId,RegulatorName,Region) VALUES (1,'Regulator1','US'); INSERT INTO Regulators (RegulatorId,RegulatorName,Region) VALUES (2,'Regulator2','US'); INSERT INTO Regulators (RegulatorId,RegulatorName,Region) VALUES (3,'Regulator3','Canada'); | SELECT da.AssetName, r.RegulatorName FROM DigitalAssets da INNER JOIN Regulators r ON da.RegulatorId = r.RegulatorId WHERE r.Region = 'US'; |
Find the percentage of people without health insurance in each census tract, ordered from the highest to lowest? | CREATE TABLE census_data (id INT,tract TEXT,uninsured INT,population INT); INSERT INTO census_data (id,tract,uninsured,population) VALUES (1,'Tract A',200,1000),(2,'Tract B',300,2000); | SELECT tract, (SUM(uninsured) OVER (PARTITION BY tract)) * 100.0 / SUM(population) OVER (PARTITION BY tract) as pct_uninsured FROM census_data ORDER BY pct_uninsured DESC; |
What is the total value of all aircraft contracts? | CREATE TABLE contracts (id INT,category VARCHAR(255),value DECIMAL(10,2));INSERT INTO contracts (id,category,value) VALUES (1,'Aircraft',5000000.00),(2,'Missiles',2000000.00),(3,'Shipbuilding',8000000.00),(4,'Cybersecurity',3000000.00),(5,'Aircraft',6000000.00),(6,'Shipbuilding',9000000.00); | SELECT SUM(value) as total_value FROM contracts WHERE category = 'Aircraft'; |
What is the average production of Neodymium in North America per year? | CREATE TABLE neodymium_production (year INT,region VARCHAR(20),quantity INT); INSERT INTO neodymium_production (year,region,quantity) VALUES (2015,'USA',12000),(2015,'Canada',8000),(2016,'USA',14000),(2016,'Canada',8500); | SELECT AVG(quantity) FROM neodymium_production WHERE region IN ('USA', 'Canada') AND element = 'Neodymium'; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.