instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the sum of zinc produced by mines in Peru? | CREATE TABLE zinc_mines (id INT,name TEXT,location TEXT,zinc_production INT); INSERT INTO zinc_mines (id,name,location,zinc_production) VALUES (1,'Antamina','Ancash,Peru',560000),(2,'Cerro Verde','Arequipa,Peru',480000),(3,'Tara','Junin,Peru',340000); | SELECT SUM(zinc_production) FROM zinc_mines WHERE location LIKE '%Peru%'; |
How many eco-friendly tours are there in total? | CREATE TABLE tours(id INT,name TEXT,eco_friendly BOOLEAN,revenue FLOAT); INSERT INTO tours (id,name,eco_friendly,revenue) VALUES (1,'Amazon Rainforest Tour',TRUE,5000),(2,'City Bus Tour',FALSE,2000),(3,'Solar Powered Bike Tour',TRUE,3000); | SELECT COUNT(*) FROM tours WHERE eco_friendly = TRUE; |
Identify the top 3 countries with the highest wheat production in the 'agriculture' database. | CREATE TABLE production (id INT,crop VARCHAR(255),country VARCHAR(255),quantity INT); INSERT INTO production (id,crop,country,quantity) VALUES (1,'wheat','USA',5000000),(2,'wheat','Canada',3000000),(3,'rice','China',8000000),(4,'wheat','Australia',2500000); | SELECT country, SUM(quantity) as total_production FROM production WHERE crop = 'wheat' GROUP BY country ORDER BY total_production DESC LIMIT 3; |
What is the total number of acres of habitat for each animal species in the 'animal_habitat' table? | CREATE TABLE animal_habitat (habitat_id INT,habitat_name VARCHAR(50),animal_name VARCHAR(50),acres FLOAT); INSERT INTO animal_habitat (habitat_id,habitat_name,animal_name,acres) VALUES (1,'African Savannah','Lion',5000.0),(2,'Asian Rainforest','Tiger',2000.0),(3,'African Rainforest','Elephant',3000.0); | SELECT animal_name, SUM(acres) FROM animal_habitat GROUP BY animal_name; |
Calculate the total biomass of fish in all aquaculture farms, categorized by the farm's country. | CREATE TABLE Farm (id INT,name VARCHAR(50),country VARCHAR(50)); CREATE TABLE Species (id INT,name VARCHAR(50),scientific_name VARCHAR(50)); CREATE TABLE FarmSpecies (farm_id INT,species_id INT,biomass INT); | SELECT f.country, SUM(fs.biomass) FROM Farm f JOIN FarmSpecies fs ON f.id = fs.farm_id GROUP BY f.country; |
Update wastewater treatment records with treatment_date in 2022 in 'WastewaterTreatment' table? | CREATE TABLE WastewaterTreatment (record_id INT,treatment_date DATE,region VARCHAR(20)); INSERT INTO WastewaterTreatment (record_id,treatment_date,region) VALUES (1,'2019-01-01','RegionA'),(2,'2021-05-03','RegionB'),(3,'2018-07-15','RegionC'); | UPDATE WastewaterTreatment SET treatment_date = '2022-01-01' WHERE record_id = 1; |
What is the policy cancellation rate for policyholders from Mexico, calculated as the percentage of policyholders who cancelled their policies within the first month? | CREATE TABLE Policyholders (PolicyholderID INT,Country VARCHAR(50),Cancelled BOOLEAN,FirstMonth BOOLEAN); INSERT INTO Policyholders VALUES (1,'Mexico',TRUE,TRUE); INSERT INTO Policyholders VALUES (2,'Mexico',FALSE,TRUE); INSERT INTO Policyholders VALUES (3,'Mexico',FALSE,FALSE); | SELECT COUNT(*) * 100.0 / SUM(CASE WHEN FirstMonth THEN 1 ELSE 0 END) AS PolicyCancellationRate FROM Policyholders WHERE Country = 'Mexico'; |
What is the maximum number of fans in the 'events' table? | CREATE TABLE events (event_id INT,team_id INT,num_fans INT); | SELECT MAX(num_fans) FROM events; |
What are the names and locations of all excavation sites that have yielded bronze age artifacts? | CREATE TABLE ExcavationSites (SiteID int,SiteName varchar(50),Location varchar(50)); CREATE TABLE Artifacts (ArtifactID int,SiteID int,Age varchar(20),Description varchar(100)); | SELECT ExcavationSites.SiteName, ExcavationSites.Location FROM ExcavationSites INNER JOIN Artifacts ON ExcavationSites.SiteID = Artifacts.SiteID WHERE Artifacts.Age = 'Bronze Age'; |
What is the total length of all the roads in the road network that intersect with a river? | CREATE TABLE Roads (id INT,name TEXT,length REAL,intersects_river BOOLEAN); INSERT INTO Roads (id,name,length,intersects_river) VALUES (1,'I-5',1381.5,TRUE),(2,'I-80',2899.8,FALSE),(3,'I-90',3020.5,FALSE); | SELECT SUM(length) FROM Roads WHERE intersects_river = TRUE |
What is the total investment in community development initiatives in Nigeria and South Africa? | CREATE TABLE investments (id INT,initiative TEXT,country TEXT,investment FLOAT); INSERT INTO investments (id,initiative,country,investment) VALUES (1,'Training','Nigeria',50000),(2,'Workshop','South Africa',75000); | SELECT SUM(investment) FROM investments WHERE country IN ('Nigeria', 'South Africa'); |
What is the maximum energy efficiency rating of appliances in Japan? | CREATE TABLE energy_efficiency (id INT,appliance TEXT,country TEXT,rating FLOAT); INSERT INTO energy_efficiency (id,appliance,country,rating) VALUES (1,'Fridge','Japan',5.0),(2,'TV','Japan',4.5); | SELECT MAX(rating) FROM energy_efficiency WHERE country = 'Japan'; |
What is the difference in the number of art pieces between the Modern Art Museum and the Contemporary Art Gallery? | CREATE TABLE ModernArtMuseum(id INT,type VARCHAR(20),artist VARCHAR(30)); CREATE TABLE ContemporaryArtGallery(id INT,type VARCHAR(20),artist VARCHAR(30)); INSERT INTO ModernArtMuseum(id,type,artist) VALUES (1,'Painting','Matisse'),(2,'Sculpture','Brancusi'),(3,'Painting','Miro'); INSERT INTO ContemporaryArtGallery(id,type,artist) VALUES (1,'Installation','Kapoor'),(2,'Painting','Basquiat'),(3,'Photography','Avedon'),(4,'Painting','Warhol'); | SELECT COUNT(*) FROM ModernArtMuseum.artpieces EXCEPT SELECT COUNT(*) FROM ContemporaryArtGallery.artpieces; |
List the names and cities of vegan restaurants with gluten-free options. | CREATE TABLE Restaurant (id INT,name VARCHAR(50),city VARCHAR(50),is_vegan BOOLEAN,is_gluten_free BOOLEAN); INSERT INTO Restaurant (id,name,city,is_vegan,is_gluten_free) VALUES (1,'Vegan Vibes','Seattle',TRUE,TRUE); INSERT INTO Restaurant (id,name,city,is_vegan,is_gluten_free) VALUES (2,'Plant-Based Pizza','Boston',TRUE,FALSE); | SELECT name, city FROM Restaurant WHERE is_vegan = TRUE AND is_gluten_free = TRUE; |
What was the total number of military equipment sales to Japan in Q3 2019? | CREATE TABLE military_sales (id INT,region VARCHAR,sale_value DECIMAL,sale_date DATE); INSERT INTO military_sales (id,region,sale_value,sale_date) VALUES (1,'Japan',12000,'2019-07-14'); INSERT INTO military_sales (id,region,sale_value,sale_date) VALUES (2,'Japan',15000,'2019-09-28'); INSERT INTO military_sales (id,region,sale_value,sale_date) VALUES (3,'Japan',18000,'2019-10-15'); | SELECT SUM(sale_value) FROM military_sales WHERE region = 'Japan' AND sale_date BETWEEN '2019-07-01' AND '2019-09-30'; |
Delete records from the "satellite_image_analysis" table where the "image_timestamp" is before '2022-01-01' | CREATE TABLE satellite_image_analysis (image_id INT,image_timestamp TIMESTAMP,cloud_cover FLOAT,rainfall_probability FLOAT); | DELETE FROM satellite_image_analysis WHERE image_timestamp < '2022-01-01'; |
What is the average renewable energy consumption and CO2 emissions for companies in the mining industry? | CREATE TABLE Renewable_Energy (Company VARCHAR(255),Year INT,Solar_Energy FLOAT,Wind_Energy FLOAT); INSERT INTO Renewable_Energy (Company,Year,Solar_Energy,Wind_Energy) VALUES ('DEF Mining',2017,15.5,16.6),('GHI Mining',2018,17.7,18.8); CREATE TABLE Emissions (Company VARCHAR(255),Year INT,CO2_Emissions FLOAT); INSERT INTO Emissions (Company,Year,CO2_Emissions) VALUES ('DEF Mining',2017,500.5),('GHI Mining',2018,550.6); | SELECT R.Company, AVG(R.Solar_Energy + R.Wind_Energy) AS Average_Renewable_Energy, E.CO2_Emissions FROM Renewable_Energy R JOIN Emissions E ON R.Company = E.Company WHERE R.Year = E.Year GROUP BY R.Company, E.CO2_Emissions; |
What is the total volume of water consumed by the industrial sector in the state of Florida in 2020? | CREATE TABLE Water_Usage (Year INT,Sector VARCHAR(20),Volume INT); INSERT INTO Water_Usage (Year,Sector,Volume) VALUES (2019,'Industry',12300000),(2018,'Industry',12000000),(2020,'Industry',12500000); | SELECT SUM(Volume) FROM Water_Usage WHERE Year = 2020 AND Sector = 'Industry'; |
What was the total weight of cannabis flower sold by each dispensary in the city of Denver in the month of April 2021? | CREATE TABLE Dispensaries (id INT,name VARCHAR(255),city VARCHAR(255),state VARCHAR(255));CREATE TABLE Inventory (id INT,dispensary_id INT,weight DECIMAL(10,2),product_type VARCHAR(255),month INT,year INT);INSERT INTO Dispensaries (id,name,city,state) VALUES (1,'Green Leaf','Denver','CO');INSERT INTO Inventory (id,dispensary_id,weight,product_type,month,year) VALUES (1,1,250,'flower',4,2021); | SELECT d.name, SUM(i.weight) as total_weight FROM Dispensaries d JOIN Inventory i ON d.id = i.dispensary_id WHERE d.city = 'Denver' AND i.product_type = 'flower' AND i.month = 4 AND i.year = 2021 GROUP BY d.name; |
What is the total budget for disability accommodations in departments with more than 20% of students with disabilities in a university in Canada? | CREATE TABLE Departments (DepartmentID INT PRIMARY KEY,DepartmentName VARCHAR(50),BudgetForDisabilityAccommodations DECIMAL(10,2),NumberOfStudentsWithDisabilities INT); CREATE TABLE Universities (UniversityID INT PRIMARY KEY,UniversityName VARCHAR(50),UniversityLocation VARCHAR(50)); CREATE TABLE UniversityDepartments (UniversityDepartmentID INT PRIMARY KEY,UniversityID INT,DepartmentID INT,FOREIGN KEY (UniversityID) REFERENCES Universities(UniversityID),FOREIGN KEY (DepartmentID) REFERENCES Departments(DepartmentID)); | SELECT SUM(BudgetForDisabilityAccommodations) as TotalBudget FROM UniversityDepartments ud JOIN Departments d ON ud.DepartmentID = d.DepartmentID JOIN Universities u ON ud.UniversityID = u.UniversityID WHERE u.UniversityLocation LIKE '%Canada%' GROUP BY ud.UniversityID HAVING AVG(d.NumberOfStudentsWithDisabilities) > 0.2*AVG(d.TotalStudents); |
List all aircraft models with more than 150 orders in descending order. | CREATE TABLE Aircraft (aircraft_id INT,model VARCHAR(50),orders INT); INSERT INTO Aircraft (aircraft_id,model,orders) VALUES (1,'B787',180),(2,'A320',220),(3,'A350',120); | SELECT model FROM Aircraft WHERE orders > 150 ORDER BY orders DESC; |
Find the number of classical concerts in the last year. | CREATE TABLE Concerts (genre VARCHAR(20),concert_date DATE); INSERT INTO Concerts (genre,concert_date) VALUES ('Classical','2022-03-12'),('Jazz','2021-11-28'),('Classical','2022-01-01'); | SELECT COUNT(*) FROM Concerts WHERE genre = 'Classical' AND concert_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR); |
Update the 'status' column to 'inactive' for all records in the 'locations' table where the 'country' is 'India' | CREATE TABLE locations (location_id INT PRIMARY KEY,location_name VARCHAR(50),country VARCHAR(50)); | UPDATE locations SET status = 'inactive' WHERE country = 'India'; |
Find the average sustainability rating of fabrics by supplier | CREATE TABLE fabrics (id INT,supplier VARCHAR(50),fabric_type VARCHAR(50),sustainability_rating INT); INSERT INTO fabrics (id,supplier,fabric_type,sustainability_rating) VALUES (1,'Supplier1','Cotton',80); INSERT INTO fabrics (id,supplier,fabric_type,sustainability_rating) VALUES (2,'Supplier2','Polyester',50); INSERT INTO fabrics (id,supplier,fabric_type,sustainability_rating) VALUES (3,'Supplier1','Hemp',90); | SELECT supplier, AVG(sustainability_rating) FROM fabrics GROUP BY supplier; |
What was the local economic impact of virtual tours in Asia in Q3 2022? | CREATE TABLE virtual_tours (country VARCHAR(255),quarter VARCHAR(10),local_impact FLOAT); INSERT INTO virtual_tours (country,quarter,local_impact) VALUES ('China','Q3',1000000),('Japan','Q3',800000),('South Korea','Q3',900000); | SELECT SUM(local_impact) FROM virtual_tours WHERE country IN ('China', 'Japan', 'South Korea') AND quarter = 'Q3'; |
What is the total sales volume of makeup products with SPF sold in Australia? | CREATE TABLE sales_volume(product_name TEXT,spf DECIMAL(3,1),sales_volume INT); INSERT INTO sales_volume VALUES ('Sunscreen',50,500); INSERT INTO sales_volume VALUES ('Moisturizer',15,300); INSERT INTO sales_volume VALUES ('Foundation',20,700); | SELECT SUM(sales_volume) FROM sales_volume WHERE spf IS NOT NULL AND country = 'Australia'; |
Who are the founders that have not filed any patents? | CREATE TABLE companies(id INT,name VARCHAR(50),industry VARCHAR(20),num_patents INT); INSERT INTO companies VALUES (1,'Alpha','Healthcare',5); INSERT INTO companies VALUES (2,'Beta','Finance',3); INSERT INTO companies VALUES (3,'Gamma','Healthcare',7); CREATE TABLE founders(id INT,company_id INT); INSERT INTO founders VALUES (1,1); INSERT INTO founders VALUES (2,1); INSERT INTO founders VALUES (3,2); INSERT INTO founders VALUES (4,3); | SELECT founders.id, founders.company_id FROM founders LEFT JOIN companies ON founders.company_id = companies.id WHERE companies.num_patents IS NULL; |
List policy numbers and claim amounts for policyholders living in 'California' who have not filed a claim. | CREATE TABLE Policies (PolicyNumber INT,PolicyholderID INT,PolicyState VARCHAR(20)); CREATE TABLE Claims (PolicyholderID INT,ClaimAmount DECIMAL(10,2),PolicyState VARCHAR(20)); INSERT INTO Policies (PolicyNumber,PolicyholderID,PolicyState) VALUES (1001,3,'California'),(1002,4,'California'),(1003,5,'California'); INSERT INTO Claims (PolicyholderID,ClaimAmount,PolicyState) VALUES (3,500,'California'),(4,200,'Texas'); | SELECT Policies.PolicyNumber, NULL AS ClaimAmount FROM Policies LEFT JOIN Claims ON Policies.PolicyholderID = Claims.PolicyholderID WHERE Policies.PolicyState = 'California' AND Claims.PolicyholderID IS NULL; |
Delete all records for the vessel 'Eco Warrior' in the 'FuelConsumption' table. | CREATE TABLE Vessels (id INT,name VARCHAR(255)); INSERT INTO Vessels (id,name) VALUES (1,'Eco Warrior'); CREATE TABLE FuelConsumption (vessel_id INT,fuel_consumption INT,timestamp TIMESTAMP); INSERT INTO FuelConsumption (vessel_id,fuel_consumption,timestamp) VALUES (1,500,'2021-09-01 10:00:00'); | DELETE FROM FuelConsumption WHERE vessel_id = (SELECT id FROM Vessels WHERE name = 'Eco Warrior'); |
How many renewable energy projects were completed in Brazil between 2016 and 2018? | CREATE TABLE renewable_energy (country VARCHAR(255),year INT,num_projects INT); INSERT INTO renewable_energy (country,year,num_projects) VALUES ('Brazil',2016,150),('Brazil',2017,180),('Brazil',2018,200),('Brazil',2019,220),('Brazil',2020,250); | SELECT SUM(num_projects) FROM renewable_energy WHERE country = 'Brazil' AND year BETWEEN 2016 AND 2018; |
List all marine species that have been impacted by climate change. | CREATE TABLE climate_change_impact (id INT,species_id INT,PRIMARY KEY (id,species_id),FOREIGN KEY (species_id) REFERENCES marine_species(id)); INSERT INTO climate_change_impact (id,species_id) VALUES (1,1),(2,3); | SELECT marine_species.species_name FROM marine_species INNER JOIN climate_change_impact ON marine_species.id = climate_change_impact.species_id; |
Which regions had the highest total donation amounts in Q2 2021? | CREATE TABLE regions (id INT,name VARCHAR(255)); INSERT INTO regions (id,name) VALUES (1,'North'),(2,'South'),(3,'East'),(4,'West'); CREATE TABLE donations (id INT,region_id INT,amount DECIMAL(10,2),donation_date DATE); INSERT INTO donations (id,region_id,amount,donation_date) VALUES (1,2,500.00,'2021-04-01'),(2,4,800.00,'2021-04-05'),(3,1,300.00,'2021-03-27'),(4,2,700.00,'2021-05-16'),(5,3,600.00,'2021-04-23'),(6,4,900.00,'2021-06-01'); | SELECT region_id, SUM(amount) as total_donations FROM donations WHERE donation_date BETWEEN '2021-04-01' AND '2021-06-30' GROUP BY region_id ORDER BY total_donations DESC; |
What is the average budget of movies produced in the USA? | CREATE TABLE movies (id INT,title TEXT,budget INT,production_country TEXT); INSERT INTO movies (id,title,budget,production_country) VALUES (1,'Movie1',5000000,'USA'),(2,'Movie2',10000000,'Canada'),(3,'Movie3',7000000,'USA'); | SELECT AVG(budget) FROM movies WHERE production_country = 'USA'; |
Which countries have launched the most satellites in the Satellites table? | CREATE TABLE Satellites (id INT,country VARCHAR(50),launch_date DATE); INSERT INTO Satellites (id,country,launch_date) VALUES (1,'USA','2020-01-01'),(2,'China','2020-02-14'),(3,'Russia','2020-04-22'),(4,'India','2020-05-15'),(5,'Japan','2020-06-20'); | SELECT country, COUNT(*) as total_satellites FROM Satellites GROUP BY country ORDER BY total_satellites DESC; |
Which artworks in the 'Post-Impressionism' exhibit were created by artists from France? | CREATE TABLE Artists (ArtistID int,Name varchar(50),Nationality varchar(50)); CREATE TABLE Artworks (ArtworkID int,ArtistID int,Title varchar(50)); CREATE TABLE Exhibits (ExhibitID int,Gallery varchar(50),ArtworkID int); CREATE TABLE ExhibitionTitles (ExhibitID int,Title varchar(50)); INSERT INTO Artists (ArtistID,Name,Nationality) VALUES (1,'Pablo Picasso','Spanish'),(2,'Claude Monet','French'),(3,'Vincent Van Gogh','Dutch'); INSERT INTO Artworks (ArtworkID,ArtistID,Title) VALUES (101,1,'Guernica'),(102,2,'Water Lilies'),(103,3,'Starry Night'); INSERT INTO Exhibits (ExhibitID,Gallery,ArtworkID) VALUES (1,'Impressionism',102),(2,'Post-Impressionism',103),(3,'Surrealism',201); INSERT INTO ExhibitionTitles (ExhibitID,Title) VALUES (1,'Impressionist Masterpieces'),(2,'Post-Impressionism'),(3,'Surrealist Dreams'); | SELECT a.Title FROM Artists a INNER JOIN Artworks aw ON a.ArtistID = aw.ArtistID INNER JOIN Exhibits e ON aw.ArtworkID = e.ArtworkID INNER JOIN ExhibitionTitles et ON e.ExhibitID = et.ExhibitID WHERE et.Title = 'Post-Impressionism' AND a.Nationality = 'French'; |
What is the average number of likes on posts from users in the United States? | CREATE TABLE users (id INT,country VARCHAR(255)); INSERT INTO users (id,country) VALUES (1,'United States'),(2,'Canada'); CREATE TABLE posts (id INT,user_id INT,likes INT); INSERT INTO posts (id,user_id,likes) VALUES (1,1,100),(2,1,200),(3,2,50); | SELECT AVG(posts.likes) FROM posts JOIN users ON posts.user_id = users.id WHERE users.country = 'United States'; |
Get the number of tickets sold for each event in the events table. | CREATE TABLE events (event_id INT,name VARCHAR(50),type VARCHAR(50),tickets_sold INT,ticket_price DECIMAL(5,2)); INSERT INTO events (event_id,name,type,tickets_sold,ticket_price) VALUES (1,'Basketball Game','Sports',500,50.00),(2,'Concert','Music',1000,75.00); | SELECT type, SUM(tickets_sold) FROM events GROUP BY type; |
What is the maximum distance traveled by the Voyager 1 space probe? | CREATE TABLE SpaceProbes (id INT,name VARCHAR(50),launch_date DATE,current_distance INT); INSERT INTO SpaceProbes (id,name,launch_date,current_distance) VALUES (1,'Voyager 1','1977-09-05',145000000000); | SELECT MAX(current_distance) FROM SpaceProbes WHERE name = 'Voyager 1'; |
List all marine conservation projects in the Mediterranean Sea and their budgets. | CREATE TABLE conservation_projects (id INT,project_name VARCHAR(50),ocean VARCHAR(50),budget DECIMAL(10,2)); INSERT INTO conservation_projects (id,project_name,ocean,budget) VALUES (1,'Project A','Mediterranean Sea',10000),(2,'Project B','Mediterranean Sea',15000),(3,'Project C','Atlantic Ocean',20000); | SELECT project_name, budget FROM conservation_projects WHERE ocean = 'Mediterranean Sea'; |
Identify the number of new volunteers and donors in the year 2022. | CREATE TABLE Volunteers (id INT,name TEXT,joined DATE); INSERT INTO Volunteers (id,name,joined) VALUES (1,'John Doe','2021-01-01'),(2,'Jane Smith','2022-01-01'); CREATE TABLE Donors (id INT,name TEXT,donated DATE); INSERT INTO Donors (id,name,donated) VALUES (3,'Mike Johnson','2021-01-01'),(4,'Sara Williams','2022-01-01'); | SELECT 'Volunteers' as type, COUNT(*) as total FROM Volunteers WHERE YEAR(joined) = 2022 UNION ALL SELECT 'Donors' as type, COUNT(*) as total FROM Donors WHERE YEAR(donated) = 2022; |
What is the minimum humidity recorded for each sensor in 'farm2'? | CREATE TABLE sensor (id INT,name VARCHAR(20),location VARCHAR(20),type VARCHAR(20)); INSERT INTO sensor (id,name,location,type) VALUES (1,'sensor1','farm1','temperature'),(2,'sensor2','farm2','humidity'),(3,'sensor3','farm3','temperature'); CREATE TABLE humidity (id INT,sensor_id INT,timestamp DATETIME,value FLOAT); INSERT INTO humidity (id,sensor_id,timestamp,value) VALUES (1,2,'2022-07-01 00:00:00',60.3),(2,2,'2022-07-01 12:00:00',55.1),(3,2,'2022-07-02 00:00:00',58.9); | SELECT sensor.name as sensor_name, MIN(value) as min_humidity FROM humidity JOIN sensor ON humidity.sensor_id = sensor.id WHERE sensor.location = 'farm2' GROUP BY sensor.name; |
What is the median investment amount per round for companies founded in the last 3 years? | CREATE TABLE investments (company_id INT,round_type TEXT,raised_amount INT); INSERT INTO investments (company_id,round_type,raised_amount) VALUES (1,'Series A',5000000); INSERT INTO investments (company_id,round_type,raised_amount) VALUES (2,'Seed',1000000); CREATE TABLE companies (id INT,name TEXT,founding_year INT); INSERT INTO companies (id,name,founding_year) VALUES (1,'Acme Inc',2020); INSERT INTO companies (id,name,founding_year) VALUES (2,'Bravo Corp',2018); | SELECT AVG(raised_amount) as median_investment_per_round FROM (SELECT raised_amount FROM investments JOIN companies ON investments.company_id = companies.id WHERE companies.founding_year >= YEAR(CURRENT_DATE) - 3 ORDER BY raised_amount) AS subquery WHERE ROW_NUMBER() OVER (ORDER BY raised_amount) IN ( (SELECT CEIL(COUNT(*)/2) FROM investments JOIN companies ON investments.company_id = companies.id WHERE companies.founding_year >= YEAR(CURRENT_DATE) - 3) , (SELECT FLOOR(COUNT(*)/2) FROM investments JOIN companies ON investments.company_id = companies.id WHERE companies.founding_year >= YEAR(CURRENT_DATE) - 3) ); |
What is the maximum biosensor temperature recorded in the United States? | CREATE SCHEMA if not exists biosensors;CREATE TABLE if not exists biosensors.measurements (id INT PRIMARY KEY,location VARCHAR(100),temperature FLOAT); INSERT INTO biosensors.measurements (id,location,temperature) VALUES (1,'New York',25.5),(2,'Los Angeles',28.2),(3,'Chicago',24.3),(4,'Houston',27.1),(5,'Phoenix',30.0); | SELECT MAX(temperature) FROM biosensors.measurements WHERE location = 'United States'; |
List all fish species that have a quantity greater than 50 in the 'fish_inventory' table. | CREATE TABLE fish_inventory (id INT PRIMARY KEY,species VARCHAR(50),quantity INT,location VARCHAR(50)); INSERT INTO fish_inventory (id,species,quantity,location) VALUES (1,'Salmon',50,'Tank A'),(2,'Tilapia',75,'Tank B'),(3,'Cod',100,'Tank C'),(4,'Herring',25,'Tank A'); | SELECT DISTINCT species FROM fish_inventory WHERE quantity > 50; |
List all clinics in a rural area with their respective healthcare professionals? | CREATE TABLE RuralClinics (ClinicID int,ClinicName varchar(50),State varchar(20)); CREATE TABLE HealthcareProfessionals (ProfessionalID int,ProfessionalName varchar(50),ClinicID int,Specialty varchar(50)); INSERT INTO RuralClinics (ClinicID,ClinicName,State) VALUES (1,'Rural Clinic A','QLD'); INSERT INTO HealthcareProfessionals (ProfessionalID,ProfessionalName,ClinicID,Specialty) VALUES (1,'Dr. Jane',1,'GP'); | SELECT Clinics.ClinicName, Professionals.ProfessionalName, Professionals.Specialty FROM RuralClinics AS Clinics JOIN HealthcareProfessionals AS Professionals ON Clinics.ClinicID = Professionals.ClinicID; |
Delete records of garments that have a retail price greater than $100 in the 'Eco_Friendly' store. | CREATE TABLE Garments(id INT,store VARCHAR(20),retail_price DECIMAL(5,2)); INSERT INTO Garments(id,store,retail_price) VALUES (1,'Eco_Friendly',150.00),(2,'Eco_Friendly',75.00),(3,'Sustainable_Outlet',120.00); | DELETE FROM Garments WHERE store = 'Eco_Friendly' AND retail_price > 100; |
What is the infant mortality rate in each state of Nigeria? | CREATE TABLE NigerianStates (State VARCHAR(50),Births INT,Deaths INT); INSERT INTO NigerianStates (State,Births,Deaths) VALUES ('Lagos',200000,5000),('Kano',180000,4500),('Rivers',160000,4000),('Anambra',150000,3500); | SELECT State, (SUM(Deaths) / SUM(Births)) * 100000 AS InfantMortalityRate FROM NigerianStates GROUP BY State; |
Which forests have sustainable management methods? | CREATE TABLE Forests (ForestID INT PRIMARY KEY,Name VARCHAR(50),Country VARCHAR(50),Hectares FLOAT); CREATE TABLE Management (ManagementID INT PRIMARY KEY,Method VARCHAR(50),ForestID INT,FOREIGN KEY (ForestID) REFERENCES Forests(ForestID)); CREATE TABLE Sustainability (SustainabilityID INT PRIMARY KEY,Certified BOOLEAN,ManagementID INT,FOREIGN KEY (ManagementID) REFERENCES Management(ManagementID)); | SELECT Forests.Name FROM Forests INNER JOIN Management ON Forests.ForestID = Management.ForestID INNER JOIN Sustainability ON Management.ManagementID = Sustainability.ManagementID WHERE Sustainability.Certified = TRUE; |
Show the average length of bridges built before 1960 | CREATE TABLE bridges (id INT,name VARCHAR(50),state VARCHAR(50),length FLOAT,year_built INT); INSERT INTO bridges (id,name,state,length,year_built) VALUES (1,'Golden Gate Bridge','California',2737,1937); INSERT INTO bridges (id,name,state,length,year_built) VALUES (2,'Houston Ship Channel Bridge','Texas',7650,1952); | SELECT AVG(length) FROM bridges WHERE year_built < 1960; |
What is the percentage of repeat attendees for literary events, and what is the average time between their first and last attendance? | CREATE TABLE LiteraryEvents (EventID INT,EventName VARCHAR(50),Date DATE); CREATE TABLE Attendees (AttendeeID INT,AttendeeName VARCHAR(50),FirstAttendance DATE,LastAttendance DATE); CREATE TABLE EventAttendees (EventID INT,AttendeeID INT,FOREIGN KEY (EventID) REFERENCES LiteraryEvents(EventID),FOREIGN KEY (AttendeeID) REFERENCES Attendees(AttendeeID)); | SELECT AVG(DATEDIFF(Attendees.LastAttendance, Attendees.FirstAttendance))/365, COUNT(DISTINCT EventAttendees.AttendeeID)/COUNT(DISTINCT Attendees.AttendeeID) * 100 FROM EventAttendees INNER JOIN Attendees ON EventAttendees.AttendeeID = Attendees.AttendeeID INNER JOIN LiteraryEvents ON EventAttendees.EventID = LiteraryEvents.EventID WHERE LiteraryEvents.EventName LIKE '%literary%'; |
What is the average age of community health workers by race, excluding those with a salary over $70,000? | CREATE TABLE CommunityHealthWorkers (Id INT,Age INT,Race VARCHAR(25),Salary DECIMAL(10,2)); INSERT INTO CommunityHealthWorkers (Id,Age,Race,Salary) VALUES (1,45,'Hispanic',60000.00),(2,32,'African American',55000.00),(3,50,'Caucasian',72000.00),(4,40,'Asian',68000.00),(5,38,'Native American',52000.00); | SELECT Race, AVG(Age) as AvgAge FROM CommunityHealthWorkers WHERE Salary < 70000 GROUP BY Race; |
What is the total value of all ERC-20 tokens issued on the Ethereum network? | CREATE TABLE ERC20Tokens (id INT,name VARCHAR(100),symbol VARCHAR(50),total_supply DECIMAL(20,2)); INSERT INTO ERC20Tokens (id,name,symbol,total_supply) VALUES (1,'Tether','USDT',80000000),(2,'Uniswap','UNI',1000000); | SELECT SUM(total_supply) FROM ERC20Tokens WHERE symbol IN ('USDT', 'UNI', '...'); |
What is the total area (in square kilometers) of all marine protected areas deeper than 3000 meters? | CREATE TABLE marine_protected_areas (name TEXT,depth INTEGER,area INTEGER); INSERT INTO marine_protected_areas (name,depth,area) VALUES ('Phoenix Islands Protected Area',4000,408054),('Weddell Sea Marine Protected Area',3500,2309120),('Ross Sea Marine Protected Area',3000,1599400); | SELECT SUM(area) FROM marine_protected_areas WHERE depth > 3000; |
Number of Oscars won by movies directed by people of color | CREATE TABLE Movies_Awards (movie VARCHAR(255),director VARCHAR(50),oscar_wins INT); | SELECT SUM(oscar_wins) FROM Movies_Awards WHERE director LIKE '%person%of%color%'; |
How much water is used in the domestic sector in New Mexico? | CREATE TABLE water_usage_nm (sector VARCHAR(20),usage FLOAT); INSERT INTO water_usage_nm (sector,usage) VALUES ('Industrial',1200),('Agriculture',3000),('Domestic',800); | SELECT usage FROM water_usage_nm WHERE sector = 'Domestic'; |
List defense contracts awarded to companies in underrepresented communities | CREATE TABLE defense_contracts (contract_id INT,company_name TEXT,community TEXT,value FLOAT); INSERT INTO defense_contracts (contract_id,company_name,community,value) VALUES (1,'ACME Corp','Veteran Owned',700000),(2,'DEF Inc','Minority Owned',800000),(3,'GHI Ltd','Women Owned',900000),(4,'JKL PLC','Service Disabled Veteran Owned',500000); | SELECT company_name FROM defense_contracts WHERE community IN ('Veteran Owned', 'Minority Owned', 'Women Owned', 'Service Disabled Veteran Owned'); |
What was the total funding for visual arts programs? | CREATE TABLE programs (id INT,category VARCHAR(20),funding DECIMAL(10,2)); INSERT INTO programs (id,category,funding) VALUES (1,'Visual Arts',15000.00),(2,'Performing Arts',20000.00),(3,'Literary Arts',10000.00); | SELECT SUM(funding) FROM programs WHERE category = 'Visual Arts'; |
What is the percentage of international tourists visiting Japan that are from Asian countries? | CREATE TABLE japan_tourism (name VARCHAR(255),country VARCHAR(255),year INT,tourists INT); INSERT INTO japan_tourism (name,country,year,tourists) VALUES ('Tokyo','China',2015,2020000),('Osaka','South Korea',2015,1110000); | SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM japan_tourism)) AS percentage FROM japan_tourism WHERE country LIKE '%Asia%'; |
What is the maximum budget allocated to a 'social services' department in 2025? | CREATE TABLE department (id INT,name TEXT,budget INT,created_at DATETIME); INSERT INTO department (id,name,budget,created_at) VALUES (1,'education',500000,'2021-01-01'),(2,'social services',1200000,'2022-01-01'); | SELECT name, MAX(budget) as max_budget FROM department WHERE name = 'social services' AND created_at BETWEEN '2025-01-01' AND '2025-12-31' GROUP BY name; |
Who is the lead researcher for the study on the environmental impact of electric vehicles? | CREATE TABLE EnvironmentalImpact (StudyID INT,StudyName VARCHAR(50),LeadResearcher VARCHAR(50)); INSERT INTO EnvironmentalImpact (StudyID,StudyName,LeadResearcher) VALUES (1,'Environmental Impact of Electric Vehicles','Dr. Maria Garcia'); | SELECT LeadResearcher FROM EnvironmentalImpact WHERE StudyName = 'Environmental Impact of Electric Vehicles'; |
What was the total number of disability support programs created in the year 2020? | CREATE TABLE disability_support_programs (program_id INT,name VARCHAR(255),created_date DATE); INSERT INTO disability_support_programs (program_id,name,created_date) VALUES (1,'Peer Mentoring','2020-01-15'); INSERT INTO disability_support_programs (program_id,name,created_date) VALUES (2,'Assistive Technology Training','2019-06-20'); | SELECT COUNT(*) FROM disability_support_programs WHERE YEAR(created_date) = 2020; |
Calculate the number of unresolved security incidents for each department in the company, for the last 6 months, partitioned by department and status? | CREATE TABLE incidents (incident_id INT,department VARCHAR(255),incident_date DATE,incident_status VARCHAR(255)); INSERT INTO incidents (incident_id,department,incident_date,incident_status) VALUES (1,'IT','2022-01-01','Resolved'),(2,'HR','2022-02-01','Open'),(3,'IT','2022-03-01','Resolved'),(4,'Finance','2022-04-01','Open'),(5,'HR','2022-05-01','Open'); | SELECT department, incident_status, COUNT(incident_id) as unresolved_incidents FROM incidents WHERE incident_date >= DATEADD(month, -6, GETDATE()) GROUP BY department, incident_status; |
How many marine protected areas are there in the South Atlantic Ocean? | CREATE TABLE marine_protected_areas_sa (id INT,name VARCHAR(255),region VARCHAR(255)); INSERT INTO marine_protected_areas_sa (id,name,region) VALUES (1,'South Georgia and the South Sandwich Islands Marine Protected Area','South Atlantic'); INSERT INTO marine_protected_areas_sa (id,name,region) VALUES (2,'Tristan da Cunha Marine Protection Zone','South Atlantic'); | SELECT COUNT(DISTINCT name) FROM marine_protected_areas_sa WHERE region = 'South Atlantic'; |
What is the average price of dishes in each menu category, excluding the cheapest and most expensive dishes? | CREATE TABLE menu (category VARCHAR(255),price FLOAT); INSERT INTO menu (category,price) VALUES ('Appetizers',7.99),('Entrees',14.99),('Desserts',5.99),('Drinks',2.99),('Sides',1.99); | SELECT category, AVG(price) FROM (SELECT category, price FROM menu WHERE price NOT IN (SELECT MIN(price) FROM menu WHERE category = menu.category) AND price NOT IN (SELECT MAX(price) FROM menu WHERE category = menu.category)) AS filtered_menu GROUP BY category; |
List the top 3 countries with the highest sales revenue for natural hair care products | CREATE TABLE sales (country VARCHAR(20),product_type VARCHAR(20),revenue DECIMAL(10,2)); INSERT INTO sales (country,product_type,revenue) VALUES ('US','natural hair care',2500),('Canada','natural hair care',1800),('Mexico','natural hair care',2000),('US','organic skincare',5000),('Canada','organic skincare',4500),('Mexico','organic skincare',4000); | SELECT country, SUM(revenue) AS total_revenue FROM sales WHERE product_type = 'natural hair care' GROUP BY country ORDER BY total_revenue DESC LIMIT 3; |
What is the minimum network infrastructure investment in Japan for the last 3 years? | CREATE TABLE japan_data (year INT,investment FLOAT); INSERT INTO japan_data (year,investment) VALUES (2019,5000000),(2020,5500000),(2021,6000000); | SELECT MIN(investment) as min_investment FROM japan_data WHERE year BETWEEN 2019 AND 2021; |
What is the average rating of hotels in urban areas with more than 3 virtual tour engagements? | CREATE TABLE hotel_reviews (id INT PRIMARY KEY,hotel_name VARCHAR(50),user_rating FLOAT,review_date DATE,hotel_location VARCHAR(50),virtual_tour_engagements INT); INSERT INTO hotel_reviews (id,hotel_name,user_rating,review_date,hotel_location,virtual_tour_engagements) VALUES (1,'Urban Retreat',4.6,'2022-03-03','Urban',4),(2,'Downtown Suites',4.8,'2022-03-04','Urban',5); | SELECT hotel_location, AVG(user_rating) FROM hotel_reviews WHERE virtual_tour_engagements > 3 GROUP BY hotel_location HAVING COUNT(*) > 1; |
Delete records in the 'cargo' table where the type is 'General Cargo' and the origin is 'Brazil' | CREATE TABLE cargo (id INT,type VARCHAR(20),origin VARCHAR(20),destination VARCHAR(20),weight FLOAT); INSERT INTO cargo (id,type,origin,destination,weight) VALUES (1,'Containers','China','USA',1000.0); INSERT INTO cargo (id,type,origin,destination,weight) VALUES (2,'Dangerous Goods','China','Japan',500.0); INSERT INTO cargo (id,type,origin,destination,weight) VALUES (3,'General Cargo','Brazil','USA',750.0); | DELETE FROM cargo WHERE type = 'General Cargo' AND origin = 'Brazil'; |
How many art pieces were created by female artists from the 'Impressionism' movement? | CREATE TABLE art_pieces (piece_id INT,artist_name VARCHAR(50),artist_gender VARCHAR(10),artist_ethnicity VARCHAR(20),movement VARCHAR(20)); INSERT INTO art_pieces (piece_id,artist_name,artist_gender,artist_ethnicity,movement) VALUES (1,'Claude Monet','Male','French','Impressionism'); INSERT INTO art_pieces (piece_id,artist_name,artist_gender,artist_ethnicity,movement) VALUES (2,'Mary Cassatt','Female','American','Impressionism'); | SELECT COUNT(*) FROM art_pieces WHERE artist_gender = 'Female' AND movement = 'Impressionism'; |
What is the maximum environmental impact score for chemical manufacturing plants in the EU? | CREATE TABLE ei_scores (plant_id INT,score FLOAT); INSERT INTO ei_scores (plant_id,score) VALUES (1,87.3),(2,78.9),(3,91.5),(4,65.2),(5,85.6),(6,94.1); CREATE TABLE plants (id INT,name TEXT,location TEXT,PRIMARY KEY (id)); INSERT INTO plants (id,name,location) VALUES (1,'PlantA','DE'),(2,'PlantB','FR'),(3,'PlantC','IT'),(4,'PlantD','ES'),(5,'PlantE','NL'),(6,'PlantF','UK'); | SELECT MAX(score) FROM ei_scores INNER JOIN plants ON ei_scores.plant_id = plants.id WHERE location LIKE 'EU%'; |
What is the average price of organic cotton garments per manufacturer? | CREATE TABLE manufacturers (manufacturer_id INT,manufacturer_name VARCHAR(255));CREATE TABLE garments (garment_id INT,garment_name VARCHAR(255),manufacturer_id INT,price DECIMAL(10,2),is_organic BOOLEAN); | SELECT m.manufacturer_name, AVG(g.price) AS avg_price FROM garments g JOIN manufacturers m ON g.manufacturer_id = m.manufacturer_id WHERE g.is_organic = TRUE GROUP BY m.manufacturer_name; |
What is the recycling rate in Germany? | CREATE TABLE recycling_rates (country VARCHAR(255),recycling_rate FLOAT); INSERT INTO recycling_rates (country,recycling_rate) VALUES ('Germany',66.1); | SELECT recycling_rate FROM recycling_rates WHERE country = 'Germany'; |
List the fields that started production after 2015 | CREATE TABLE field_start_date (field VARCHAR(50),start_date DATE); INSERT INTO field_start_date (field,start_date) VALUES ('Ekofisk','2015-01-01'); INSERT INTO field_start_date (field,start_date) VALUES ('Statfjord','2016-01-01'); INSERT INTO field_start_date (field,start_date) VALUES ('Gullfaks','2017-01-01'); INSERT INTO field_start_date (field,start_date) VALUES ('Troll','2018-01-01'); INSERT INTO field_start_date (field,start_date) VALUES ('Johan Sverdrup','2020-01-01'); | SELECT field FROM field_start_date WHERE start_date > '2015-01-01'; |
What is the average THC content of products sold by each dispensary in Alaska? | CREATE TABLE Dispensaries (id INT,name TEXT,state TEXT);CREATE TABLE Products (id INT,dispensary_id INT,thc_content DECIMAL); | SELECT D.name, AVG(P.thc_content) FROM Dispensaries D JOIN Products P ON D.id = P.dispensary_id WHERE D.state = 'Alaska' GROUP BY D.id; |
Who are the mission directors that have overseen missions with a total cost greater than $200,000? | CREATE TABLE missions (mission_name VARCHAR(255),mission_director VARCHAR(255),total_cost DECIMAL(10,2)); INSERT INTO missions (mission_name,mission_director,total_cost) VALUES ('Mission1','Dir1',150000.00),('Mission2','Dir2',200000.00),('Mission3','Dir3',120000.00),('Mission4','Dir1',180000.00),('Mission5','Dir2',250000.00); | SELECT DISTINCT mission_director FROM missions WHERE total_cost > 200000.00; |
What is the total cost of defense projects with a duration greater than 24 months? | CREATE TABLE defense_projects(project_id INT,project_name VARCHAR(50),duration INT,cost FLOAT); INSERT INTO defense_projects VALUES (1,'Project A',36,5000000),(2,'Project B',24,4000000),(3,'Project C',18,3000000); | SELECT SUM(cost) FROM defense_projects WHERE duration > 24; |
What was the average production rate per machine for the month of January 2022? | CREATE TABLE Machine_Production (Machine_ID INT,Production_Date DATE,Production_Rate INT); INSERT INTO Machine_Production (Machine_ID,Production_Date,Production_Rate) VALUES (1,'2022-01-01',50),(1,'2022-01-02',55),(2,'2022-01-01',60),(2,'2022-01-03',65); | SELECT AVG(Production_Rate) FROM (SELECT Production_Rate, ROW_NUMBER() OVER(PARTITION BY Machine_ID ORDER BY Production_Date) as rn FROM Machine_Production WHERE Production_Date >= '2022-01-01' AND Production_Date < '2022-02-01' AND Machine_ID IN (1,2)) tmp WHERE rn = 1; |
Delete the record for the bus fare in Rio de Janeiro | CREATE TABLE if not exists bus_fares (id INT,city VARCHAR(20),avg_fare DECIMAL(3,2)); INSERT INTO bus_fares (id,city,avg_fare) VALUES (1,'Rio de Janeiro',2.20),(2,'Sao Paulo',2.50); | DELETE FROM bus_fares WHERE city = 'Rio de Janeiro'; |
What was the minimum deep-sea exploration depth by year? | CREATE TABLE yearly_dives (year INT,depth FLOAT); INSERT INTO yearly_dives (year,depth) VALUES (2017,6500),(2018,6600),(2019,6700),(2020,6800),(2021,6900); | SELECT year, MIN(depth) FROM yearly_dives; |
List the names and locations of genetic research institutions in Germany. | CREATE SCHEMA if not exists biotech;CREATE TABLE if not exists biotech.genetic_research(id INT,name STRING,location STRING);INSERT INTO biotech.genetic_research(id,name,location) VALUES (1,'InstituteA','Germany'),(2,'InstituteB','US'),(3,'InstituteC','UK'); | SELECT name, location FROM biotech.genetic_research WHERE location = 'Germany'; |
Display the number of patents filed by companies in each state | CREATE TABLE companies (company_id INT,company_name VARCHAR(255),state VARCHAR(255));CREATE TABLE patents (patent_id INT,company_id INT,filed_date DATE); | SELECT c.state, COUNT(c.company_id) FROM companies c INNER JOIN patents p ON c.company_id = p.company_id GROUP BY c.state; |
Find the total production of Lanthanum and Yttrium for each year? | CREATE TABLE ProductionData (year INT,element TEXT,production INT); INSERT INTO ProductionData (year,element,production) VALUES (2017,'Lanthanum',1000); INSERT INTO ProductionData (year,element,production) VALUES (2018,'Lanthanum',1500); INSERT INTO ProductionData (year,element,production) VALUES (2019,'Lanthanum',2000); INSERT INTO ProductionData (year,element,production) VALUES (2017,'Yttrium',800); INSERT INTO ProductionData (year,element,production) VALUES (2018,'Yttrium',1200); INSERT INTO ProductionData (year,element,production) VALUES (2019,'Yttrium',1500); | SELECT year, SUM(production) as total_production FROM ProductionData WHERE element IN ('Lanthanum', 'Yttrium') GROUP BY year; |
What is the average depth of all oceanic trenches? | CREATE TABLE ocean_trenches (name TEXT,average_depth REAL); INSERT INTO ocean_trenches (name,average_depth) VALUES ('Mariana Trench',10994),('Tonga Trench',10820),('Kuril-Kamchatka Trench',10542),('Philippine Trench',10540),('Kermadec Trench',10047); | SELECT AVG(average_depth) FROM ocean_trenches; |
How many pollution control initiatives are present in the North Pacific Ocean? | CREATE TABLE pollution_control (initiative_id INT,ocean TEXT); INSERT INTO pollution_control (initiative_id,ocean) VALUES (1,'North Pacific'),(2,'South Atlantic'),(3,'Indian Ocean'),(4,'North Pacific'),(5,'Arctic Ocean'); | SELECT COUNT(*) FROM pollution_control WHERE ocean = 'North Pacific'; |
What is the success rate of startups founded by people from each country? | CREATE TABLE companies (id INT,name TEXT,founder_country TEXT,is_active BOOLEAN); | SELECT founder_country, 100.0 * AVG(CASE WHEN is_active THEN 1.0 ELSE 0.0 END) as success_rate FROM companies GROUP BY founder_country; |
List all the financial products offered by Al-Rahman Bank with their corresponding annual percentage rates. | CREATE TABLE financial_products (bank VARCHAR(50),product VARCHAR(50),apr FLOAT); INSERT INTO financial_products (bank,product,apr) VALUES ('Al-Rahman Bank','Home Mortgage',4.5),('Al-Rahman Bank','Car Loan',6.0),('Al-Rahman Bank','Personal Loan',7.5); | SELECT bank, product, apr FROM financial_products WHERE bank = 'Al-Rahman Bank'; |
Find the number of sensors that have not sent data in the past week and the number of sensors that have sent data in the past week. | CREATE TABLE Sensors (SensorID varchar(5),SensorName varchar(10),LastDataSent timestamp); INSERT INTO Sensors (SensorID,SensorName,LastDataSent) VALUES ('1','Sensor 1','2022-06-22 12:30:00'),('2','Sensor 2','2022-06-25 16:45:00'),('3','Sensor 3','2022-06-28 09:10:00'); | SELECT COUNT(*) FROM (SELECT SensorName FROM Sensors WHERE LastDataSent < NOW() - INTERVAL '7 days' UNION SELECT SensorName FROM Sensors WHERE LastDataSent > NOW() - INTERVAL '7 days') AS Subquery; |
How many legal technology patents were granted per month in 2019? | CREATE TABLE patents_monthly (id INT,year INT,month INT,granted BOOLEAN); INSERT INTO patents_monthly (id,year,month,granted) VALUES (1,2015,1,TRUE),(2,2016,2,TRUE),(3,2017,3,FALSE),(4,2018,4,TRUE),(5,2019,5,FALSE),(6,2020,6,TRUE); | SELECT p.year, p.month, COUNT(p.id) AS total_patents FROM patents_monthly p WHERE p.granted = TRUE AND p.year = 2019 GROUP BY p.year, p.month; |
What is the average volume of wastewater treated per day in 2022, for treatment plants with a capacity of over 1,000,000 liters? | CREATE TABLE treatment_plants (id INT PRIMARY KEY,name VARCHAR(255),capacity INT,plant_type VARCHAR(255)); CREATE TABLE wastewater (id INT PRIMARY KEY,treatment_plant_id INT,volume_treated FLOAT,treatment_date DATE); | SELECT AVG(w.volume_treated/DATEDIFF('2022-12-31', '2022-01-01')) as avg_daily_volume_treated FROM treatment_plants t JOIN wastewater w ON t.id = w.treatment_plant_id WHERE t.capacity > 1000000; |
How many movies were released by each studio in 2020 and 2021? | CREATE TABLE Studios (studio_id INT,studio_name VARCHAR(255),country VARCHAR(255)); INSERT INTO Studios (studio_id,studio_name,country) VALUES (1,'Studio G','USA'),(2,'Studio H','USA'),(3,'Studio I','Canada'); CREATE TABLE Movies (movie_id INT,movie_name VARCHAR(255),studio_id INT,release_year INT); INSERT INTO Movies (movie_id,movie_name,studio_id,release_year) VALUES (1,'Movie E',1,2020),(2,'Movie F',1,2021),(3,'Movie G',2,2020),(4,'Movie H',3,2019); | SELECT s.studio_name, COUNT(*) as movies_in_2020_and_2021 FROM Studios s JOIN Movies t ON s.studio_id = t.studio_id WHERE t.release_year IN (2020, 2021) GROUP BY s.studio_id, s.studio_name; |
find the total number of escalators and elevators in each metro station | CREATE TABLE MetroStations (station VARCHAR(20),num_escalators INT,num_elevators INT); INSERT INTO MetroStations (station,num_escalators,num_elevators) VALUES ('Station A',5,2),('Station B',3,3),('Station C',6,1); | SELECT station, SUM(num_escalators + num_elevators) as total FROM MetroStations GROUP BY station; |
What is the average rainfall in Kenya and Ethiopia? | CREATE TABLE rainfall (country VARCHAR(20),rainfall INT); INSERT INTO rainfall VALUES ('Kenya',800),('Kenya',900),('Ethiopia',1200),('Ethiopia',1100); | SELECT AVG(rainfall) FROM rainfall WHERE country = 'Kenya' UNION SELECT AVG(rainfall) FROM rainfall WHERE country = 'Ethiopia' |
What is the standard deviation of balance for clients with checking accounts in the Chicago branch? | CREATE TABLE clients (client_id INT,name TEXT,dob DATE,branch TEXT);CREATE TABLE accounts (account_id INT,client_id INT,account_type TEXT,balance DECIMAL);INSERT INTO clients VALUES (8,'Sophia Taylor','1992-08-30','Chicago');INSERT INTO accounts VALUES (108,8,'Checking',4000); | SELECT STDEV(accounts.balance) FROM clients INNER JOIN accounts ON clients.client_id = accounts.client_id WHERE accounts.account_type = 'Checking' AND clients.branch = 'Chicago'; |
Find the total number of ambulance dispatches and the average response time for ambulance services in each zip code area over the last three months. | CREATE TABLE ZipCodes (ZipCodeID INT,ZipCode VARCHAR(255)); CREATE TABLE AmbulanceDispatches (DispatchID INT,DispatchType VARCHAR(255),ZipCodeID INT,DispatchDate DATE,DispatchTime INT); | SELECT ZipCode, COUNT(DispatchID) as TotalDispatches, AVG(DispatchTime) as AvgResponseTime FROM AmbulanceDispatches d JOIN ZipCodes z ON d.ZipCodeID = z.ZipCodeID WHERE d.DispatchDate >= DATEADD(month, -3, GETDATE()) AND d.DispatchType = 'Ambulance' GROUP BY ZipCode; |
What is the average allocation for climate finance projects in the first half of 2021? | CREATE TABLE climate_finance_projects (project_id INT,project_name VARCHAR(255),allocation DECIMAL(10,2),year INT,month INT); INSERT INTO climate_finance_projects (project_id,project_name,allocation,year,month) VALUES (1,'Green Bond Issue',10000000,2021,1),(2,'Carbon Tax Implementation',7000000,2021,2); | SELECT AVG(allocation) FROM climate_finance_projects WHERE year = 2021 AND month BETWEEN 1 AND 6; |
What is the average salary of developers in the Ethical AI team? | CREATE TABLE employees (id INT,name VARCHAR(50),team VARCHAR(50),salary FLOAT); INSERT INTO employees (id,name,team,salary) VALUES (1,'Alice','Ethical AI',70000.00),(2,'Bob','Data Science',75000.00),(3,'Charlie','Ethical AI',72000.00); | SELECT AVG(salary) FROM employees WHERE team = 'Ethical AI' AND position = 'Developer'; |
What is the total runtime of movies and TV shows in the 'Action' genre, and how many unique directors are there? | CREATE TABLE media_content (id INT,title VARCHAR(255),release_year INT,runtime INT,genre VARCHAR(255),format VARCHAR(50),country VARCHAR(255),director VARCHAR(255)); | SELECT genre, SUM(runtime) AS total_runtime, COUNT(DISTINCT director) AS unique_directors FROM media_content WHERE genre = 'Action' GROUP BY genre; |
Determine the total waste generation for the year 2020 for all cities | CREATE TABLE waste_generation (city VARCHAR(20),year INT,daily_waste_generation FLOAT);INSERT INTO waste_generation (city,year,daily_waste_generation) VALUES ('San Francisco',2019,3.2),('San Francisco',2020,3.5),('San Francisco',2021,3.7),('Oakland',2019,2.8),('Oakland',2020,3.1),('Oakland',2021,3.3); | SELECT SUM(daily_waste_generation * 365) FROM waste_generation WHERE year = 2020; |
Find the average ESG score for 'Sustainable Futures' in 2021. | CREATE TABLE company_scores (id INT,company VARCHAR(255),esg_score FLOAT,year INT); INSERT INTO company_scores (id,company,esg_score,year) VALUES (15,'Sustainable Futures',88,2021); INSERT INTO company_scores (id,company,esg_score,year) VALUES (16,'Sustainable Futures',92,2020); | SELECT AVG(esg_score) FROM company_scores WHERE company = 'Sustainable Futures' AND year = 2021; |
List the top 3 climate finance initiatives with the highest budget in the Middle East and North Africa, ordered by budget. | CREATE TABLE climate_finance_initiatives (id INT PRIMARY KEY,name VARCHAR(50),location VARCHAR(50),budget DECIMAL(10,2));CREATE VIEW v_middle_east_north_africa_finance_initiatives AS SELECT cfi.name,cfi.location,cfi.budget FROM climate_finance_initiatives cfi WHERE cfi.location LIKE 'Middle East%' OR cfi.location LIKE 'North Africa%'; | SELECT * FROM v_middle_east_north_africa_finance_initiatives ORDER BY budget DESC LIMIT 3; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.