instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the total number of marine species samples collected in the Pacific Ocean region with a depth greater than 3000 meters? | CREATE TABLE pacific_species (id INT,species VARCHAR(255),collection_depth INT); INSERT INTO pacific_species (id,species,collection_depth) VALUES (1,'Anglerfish',3500),(2,'Goblin Shark',4200),(3,'Starry Octopus',3100); | SELECT COUNT(species) FROM pacific_species WHERE collection_depth > 3000; |
What is the total waste generation for Tokyo in the year 2020? | CREATE TABLE waste_generation (city VARCHAR(50),generation_quantity INT,generation_date DATE,year INT); INSERT INTO waste_generation (city,generation_quantity,generation_date,year) VALUES ('Tokyo',3000,'2020-01-01',2020),('Tokyo',3500,'2020-02-01',2020),('Tokyo',4000,'2020-03-01',2020); | SELECT SUM(generation_quantity) FROM waste_generation WHERE city = 'Tokyo' AND year = 2020; |
Delete all records from the Water_Conservation table where the initiative_id is 4? | CREATE TABLE Water_Conservation (initiative_id INT,description VARCHAR(50)); INSERT INTO Water_Conservation (initiative_id,description) VALUES (1,'Rainwater harvesting'),(2,'Drought-resistant landscaping'),(3,'Low-flow fixtures'),(4,'Smart irrigation controllers'),(5,'Water audits'); | DELETE FROM Water_Conservation WHERE initiative_id = 4; |
What is the total installed capacity of solar power plants (in GW) in Japan, grouped by prefecture? | CREATE TABLE SolarPowerPlants (id INT,prefecture VARCHAR(50),capacity FLOAT); INSERT INTO SolarPowerPlants (id,prefecture,capacity) VALUES (1,'Hokkaido',1.2),(2,'Tokyo',2.5),(3,'Hokkaido',1.8),(4,'Kyoto',0.9); | SELECT prefecture, SUM(capacity) FROM SolarPowerPlants WHERE prefecture = 'Hokkaido' GROUP BY prefecture; |
What is the maximum number of simultaneous viewers of a League of Legends stream? | CREATE TABLE Streams (StreamID INT,Game VARCHAR(10),Viewers INT); INSERT INTO Streams (StreamID,Game,Viewers) VALUES (1,'League of Legends',500000); | SELECT MAX(Viewers) FROM Streams WHERE Game = 'League of Legends'; |
What is the average age of players who identify as female and are from Japan? | CREATE TABLE PlayerGender (PlayerID INT,Gender VARCHAR(10),FOREIGN KEY (PlayerID) REFERENCES Players(PlayerID)); INSERT INTO PlayerGender (PlayerID,Gender) VALUES (1,'Female'); CREATE TABLE PlayerCountry (PlayerID INT,Country VARCHAR(50),FOREIGN KEY (PlayerID) REFERENCES Players(PlayerID)); INSERT INTO PlayerCountry (P... | SELECT AVG(PlayerAge.Age) FROM PlayerAge INNER JOIN PlayerGender ON PlayerAge.PlayerID = PlayerGender.PlayerID INNER JOIN PlayerCountry ON PlayerAge.PlayerID = PlayerCountry.PlayerID WHERE PlayerGender.Gender = 'Female' AND PlayerCountry.Country = 'Japan'; |
Update the 'Academic_Publications' table to change the 'Publication_Type' to 'Journal Article' for publications with 'Publication_ID' in (501, 505, 512) | CREATE TABLE Academic_Publications (Publication_ID INT,Title VARCHAR(100),Publication_Type VARCHAR(50),Publication_Year INT,Author_ID INT); | UPDATE Academic_Publications SET Publication_Type = 'Journal Article' WHERE Publication_ID IN (501, 505, 512); |
Which genetic research projects are using next-generation sequencing? | CREATE SCHEMA if not exists genetics; CREATE TABLE if not exists genetics.projects(project_id INT PRIMARY KEY,name VARCHAR(100),technology VARCHAR(50)); CREATE TABLE if not exists genetics.sequencing(sequencing_id INT PRIMARY KEY,project_id INT,name VARCHAR(100),FOREIGN KEY (project_id) REFERENCES genetics.projects(pro... | SELECT p.name FROM genetics.projects p JOIN genetics.sequencing s ON p.project_id = s.project_id WHERE p.technology = 'next-generation sequencing'; |
What is the average temperature and precipitation for all organic farms in Canada and France? | CREATE TABLE OrganicFarm (id INT,country VARCHAR(50),temperature DECIMAL(5,2),precipitation DECIMAL(5,2)); INSERT INTO OrganicFarm (id,country,temperature,precipitation) VALUES (1,'Canada',12.5,60.0); INSERT INTO OrganicFarm (id,country,temperature,precipitation) VALUES (2,'France',14.2,75.6); | SELECT AVG(temperature), AVG(precipitation) FROM OrganicFarm WHERE country IN ('Canada', 'France'); |
Calculate the moving average of claims paid for the last 3 months. | CREATE TABLE Claim (ClaimID INT,ClaimDate DATE,ClaimAmount DECIMAL(10,2)); INSERT INTO Claim VALUES (1,'2021-01-01',5000),(2,'2021-02-01',3000),(3,'2021-03-01',7000),(4,'2021-04-01',8000),(5,'2021-05-01',9000); | SELECT ClaimDate, AVG(ClaimAmount) OVER (ORDER BY ClaimDate ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) as MovingAvg FROM Claim WHERE ClaimDate >= DATEADD(MONTH, -3, GETDATE()) ORDER BY ClaimDate; |
How many donors are there in the 'Donors' table for each donor_type? | CREATE TABLE Donors (donor_id INT,name VARCHAR(50),donor_type VARCHAR(20)); | SELECT donor_type, COUNT(*) FROM Donors GROUP BY donor_type; |
Count of socially responsible loans in the Western region | CREATE TABLE socially_responsible_loans (id INT,state VARCHAR(255),region VARCHAR(255)); | SELECT COUNT(*) FROM socially_responsible_loans WHERE region = 'Western'; |
What was the total budget allocated for the 'Education' department in the year 2020? | CREATE TABLE Budget (Year INT,Department VARCHAR(20),Amount INT); INSERT INTO Budget (Year,Department,Amount) VALUES (2020,'Education',1200000); | SELECT SUM(Amount) FROM Budget WHERE Year = 2020 AND Department = 'Education'; |
Calculate the percentage of rural hospitals that have implemented telemedicine services. | CREATE TABLE hospitals (id INT,telemedicine BOOLEAN,location VARCHAR(20),state VARCHAR(10)); INSERT INTO hospitals (id,telemedicine,location,state) VALUES (1,true,'rural','NY'),(2,false,'urban','NY'),(3,true,'rural','CA'),(4,false,'rural','TX'); | SELECT (SELECT COUNT(*) FROM hospitals WHERE telemedicine = true AND location LIKE '%rural%') * 100.0 / (SELECT COUNT(*) FROM hospitals WHERE location LIKE '%rural%') AS percentage; |
What is the number of countries in the Latin America and Caribbean region that have reduced their carbon emissions in the last 5 years? | CREATE TABLE country_emissions (name VARCHAR(50),region VARCHAR(50),year INT,carbon_emissions INT); INSERT INTO country_emissions (name,region,year,carbon_emissions) VALUES ('Country 1','Latin America and Caribbean',2017,10000); INSERT INTO country_emissions (name,region,year,carbon_emissions) VALUES ('Country 1','Lati... | SELECT region, COUNT(*) FROM country_emissions WHERE region = 'Latin America and Caribbean' AND carbon_emissions < (SELECT carbon_emissions FROM country_emissions WHERE name = 'Country 1' AND year = 2017 AND region = 'Latin America and Caribbean' ORDER BY year DESC LIMIT 1) GROUP BY region HAVING COUNT(*) > 1; |
What is the total biomass of each species in the 'arctic_biodiversity' table for the 'north_arctic' region? | CREATE TABLE arctic_biodiversity (id INTEGER,species_name TEXT,biomass FLOAT,region TEXT); CREATE TABLE arctic_regions (id INTEGER,region TEXT); INSERT INTO arctic_regions (id,region) VALUES (1,'north_arctic'),(2,'south_arctic'); | SELECT species_name, SUM(biomass) as total_biomass FROM arctic_biodiversity INNER JOIN arctic_regions ON arctic_biodiversity.region = arctic_regions.region WHERE arctic_regions.region = 'north_arctic' GROUP BY species_name; |
List the top 5 threat actors, based on the number of security incidents they are responsible for, in the last 6 months? | CREATE TABLE security_incidents (id INT,threat_actor VARCHAR(255),timestamp TIMESTAMP);CREATE VIEW threat_actor_count AS SELECT threat_actor,COUNT(*) as incident_count FROM security_incidents WHERE timestamp >= NOW() - INTERVAL '6 months' GROUP BY threat_actor; | SELECT threat_actor, incident_count FROM threat_actor_count ORDER BY incident_count DESC LIMIT 5; |
What is the maximum number of transactions per second on the Solana network in the past month? | CREATE TABLE solana_transactions (transaction_time TIMESTAMP,transaction_id BIGINT); | SELECT MAX(COUNT(transaction_id)) FROM solana_transactions WHERE transaction_time >= NOW() - INTERVAL '1 month'; |
What is the latest launch date for each country in the satellites table? | CREATE TABLE satellites (id INT,name VARCHAR(50),launch_country VARCHAR(50),launch_date DATE); INSERT INTO satellites VALUES (1,'Sputnik 1','Russia','1957-10-04'); INSERT INTO satellites VALUES (2,'Explorer 1','USA','1958-01-31'); INSERT INTO satellites VALUES (3,'Echo 1','USA','1960-08-12'); INSERT INTO satellites VAL... | SELECT launch_country, MAX(launch_date) as latest_launch FROM satellites GROUP BY launch_country; |
What is the total number of tourists visiting Japan and France in 2019 and 2020? | CREATE TABLE japan_tourists (year INT,tourists INT);CREATE TABLE france_tourists (year INT,tourists INT); | SELECT SUM(tourists) FROM (SELECT year, tourists FROM japan_tourists WHERE year IN (2019, 2020) UNION ALL SELECT year, tourists FROM france_tourists WHERE year IN (2019, 2020)) AS total; |
What is the average number of humanitarian assistance operations per country in the 'africa' region? | CREATE TABLE humanitarian_assistance (country VARCHAR(50),region VARCHAR(50),operations INT); INSERT INTO humanitarian_assistance (country,region,operations) VALUES ('Egypt','Africa',20),('South Africa','Africa',30),('Nigeria','Africa',25); | SELECT region, AVG(operations) as avg_operations FROM humanitarian_assistance WHERE region = 'Africa' GROUP BY region; |
What are the names of vessels that have visited the 'PortA'? | CREATE TABLE vessel_visits (id INT,vessel_id INT,port_id INT); INSERT INTO vessel_visits (id,vessel_id,port_id) VALUES (1,1,1),(2,2,2); | SELECT DISTINCT v.name FROM vessel_visits vv JOIN vessels v ON vv.vessel_id = v.id WHERE vv.port_id = 1; |
What was the minimum temperature in field 3 over the last week? | CREATE TABLE field_temperature (field_id INT,date DATE,temperature FLOAT); INSERT INTO field_temperature (field_id,date,temperature) VALUES (3,'2021-07-01',25.5),(3,'2021-07-02',24.3),(3,'2021-07-03',26.1); | SELECT MIN(temperature) FROM field_temperature WHERE field_id = 3 AND date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK); |
Insert a new record of circular economy initiative for the city of Tokyo in 2027. | CREATE TABLE circular_economy(city VARCHAR(20),year INT,initiative VARCHAR(50)); | INSERT INTO circular_economy VALUES('Tokyo', 2027, 'Implementing a city-wide food waste reduction program'); |
Show the names and safety scores of AI applications, excluding any applications with a safety score less than 0.8. | CREATE TABLE ai_applications (app_id INT,app_name VARCHAR(255),app_type VARCHAR(255),safety_score DECIMAL(3,2),creativity_score DECIMAL(3,2)); INSERT INTO ai_applications (app_id,app_name,app_type,safety_score,creativity_score) VALUES (1,'App1','Safety',0.95,0.75),(2,'App2','Creativity',0.85,0.92),(3,'App3','Safety',0.... | SELECT app_name, safety_score FROM ai_applications WHERE safety_score >= 0.8; |
Decrease the price of standard tickets for a particular event by 5%. | CREATE TABLE ticket_types (type_id INT,event_id INT,description VARCHAR(50),price DECIMAL(5,2)); INSERT INTO ticket_types VALUES (2,1,'Standard',70); | UPDATE ticket_types tt SET tt.price = tt.price * 0.95 WHERE tt.type_id = 2 AND tt.event_id = 1; |
What are the top 3 most visited art museums in 'Asia'? | CREATE TABLE Museums (id INT,museum_name VARCHAR(255),location VARCHAR(255),yearly_visitors INT); INSERT INTO Museums (id,museum_name,location,yearly_visitors) VALUES (1,'National Museum of China','China',8000000); INSERT INTO Museums (id,museum_name,location,yearly_visitors) VALUES (2,'Louvre Museum','France',10000000... | SELECT museum_name, SUM(yearly_visitors) as total_visitors FROM Museums WHERE location = 'Asia' GROUP BY museum_name ORDER BY total_visitors DESC LIMIT 3; |
Who is the director with the highest average rating for their movies? | CREATE TABLE Movies (id INT,title VARCHAR(255),release_year INT,rating DECIMAL(3,2),director_id INT); INSERT INTO Movies (id,title,release_year,rating,director_id) VALUES (1,'Movie1',2016,7.5,1),(2,'Movie2',2017,8.2,2),(3,'Movie3',2018,6.8,1),(4,'Movie4',2019,9.0,3),(5,'Movie5',2020,8.5,2); CREATE TABLE Directors (id I... | SELECT d.name, AVG(m.rating) FROM Directors d JOIN Movies m ON d.id = m.director_id GROUP BY d.id ORDER BY AVG(m.rating) DESC LIMIT 1; |
What is the explainability rating for the AI system named 'AI Judge'? | CREATE TABLE explainable_ai (ai_system TEXT,rating FLOAT); INSERT INTO explainable_ai (ai_system,rating) VALUES ('AI Judge',0.75),('AI Translator',0.90),('AI Artist',0.60); | SELECT rating FROM explainable_ai WHERE ai_system = 'AI Judge'; |
What is the total quantity of each mineral extracted from all mines? | CREATE TABLE ExtractionData (ExtractionDataID INT,MineID INT,Date DATE,Mineral TEXT,Quantity INT); | SELECT Mineral, SUM(Quantity) FROM ExtractionData GROUP BY Mineral; |
What is the total donation amount from recurring donors in 2021? | CREATE TABLE Donations (DonationID INT,DonationAmount INT,DonorID INT,DonationDate DATE,IsRecurring BOOLEAN); INSERT INTO Donations (DonationID,DonationAmount,DonorID,DonationDate,IsRecurring) VALUES (1,100,1,'2022-01-01',true),(2,200,2,'2021-05-15',false); | SELECT SUM(DonationAmount) FROM Donations WHERE IsRecurring = true AND YEAR(DonationDate) = 2021; |
What is the maximum capacity of the largest hotel in Brazil? | CREATE TABLE Hotels (id INT,name TEXT,location TEXT,capacity INT); INSERT INTO Hotels (id,name,location,capacity) VALUES (1,'Hotel Rio','Rio de Janeiro,Brazil',800),(2,'Hotel Sao Paulo','Sao Paulo,Brazil',1000),(3,'Hotel Amazon','Amazonas,Brazil',1200); | SELECT MAX(capacity) FROM Hotels WHERE location LIKE '%Brazil%'; |
What is the total number of season tickets sold for each team in the Western Conference? | CREATE TABLE teams (team_id INT,team_name VARCHAR(50),conference VARCHAR(50)); INSERT INTO teams (team_id,team_name,conference) VALUES (4,'Lakers','Western'),(5,'Warriors','Western'),(6,'Suns','Western'); CREATE TABLE season_ticket_sales (team_id INT,sales INT); INSERT INTO season_ticket_sales (team_id,sales) VALUES (4... | SELECT t.team_name, SUM(sts.sales) as total_sales FROM teams t JOIN season_ticket_sales sts ON t.team_id = sts.team_id WHERE t.conference = 'Western' GROUP BY t.team_name; |
What is the total funding received by startups founded by people from each country? | CREATE TABLE company (name VARCHAR(255),country VARCHAR(100),founder_underrepresented BOOLEAN); INSERT INTO company (name,country,founder_underrepresented) VALUES ('CompanyA','USA',FALSE),('CompanyB','Canada',TRUE),('CompanyC','USA',TRUE),('CompanyD','Mexico',FALSE),('CompanyE','Brazil',TRUE),('CompanyF','USA',FALSE); ... | SELECT country, SUM(funding.amount) as total_funding FROM funding INNER JOIN company ON funding.company_name = company.name GROUP BY country; |
How many water treatment plants are there in total across the states of New York, New Jersey, and Pennsylvania? | CREATE TABLE water_treatment_plants (state VARCHAR(20),num_plants INTEGER); INSERT INTO water_treatment_plants (state,num_plants) VALUES ('New York',120),('New Jersey',85),('Pennsylvania',150); | SELECT SUM(num_plants) FROM water_treatment_plants WHERE state IN ('New York', 'New Jersey', 'Pennsylvania'); |
Delete all records in the space_exploration table where launch_date is after '2030-01-01' | CREATE TABLE space_exploration (id INT,mission_name VARCHAR(255),mission_status VARCHAR(255),agency VARCHAR(255),launch_date DATE); | DELETE FROM space_exploration WHERE launch_date > '2030-01-01'; |
Delete records for players who have not played the "RPG Quest" game | CREATE TABLE players (player_id INT,name VARCHAR(255),country VARCHAR(255),date_registered DATE); CREATE TABLE player_scores (player_id INT,game_name VARCHAR(255),score INT,date DATE); | DELETE FROM players WHERE player_id NOT IN (SELECT player_id FROM player_scores WHERE game_name = 'RPG Quest'); |
What is the average daily production rate of lithium in Chile? | CREATE TABLE daily_lithium_production (id INT,country VARCHAR(255),date DATE,quantity INT); INSERT INTO daily_lithium_production (id,country,date,quantity) VALUES (1,'Chile','2022-01-01',50),(2,'Chile','2022-01-02',60),(3,'Chile','2022-01-03',70),(4,'Chile','2022-01-04',80),(5,'Chile','2022-01-05',90); | SELECT AVG(quantity) as average_daily_production_rate FROM daily_lithium_production WHERE country = 'Chile'; |
What is the total budget for programs focused on education and literacy? | CREATE TABLE Programs (ProgramID INT,ProgramName TEXT,Budget DECIMAL(10,2),Category TEXT); INSERT INTO Programs (ProgramID,ProgramName,Budget,Category) VALUES (1,'Reading for All',75000.00,'Education'); INSERT INTO Programs (ProgramID,ProgramName,Budget,Category) VALUES (2,'Math and Science',100000.00,'Education'); INS... | SELECT SUM(Budget) FROM Programs WHERE Category IN ('Education', 'Literacy'); |
Show the number of active projects and total budget for 'Community Development' sector projects in the 'Asia-Pacific' region as of 2022-01-01. | CREATE TABLE Projects (project_id INT,project_name VARCHAR(255),sector VARCHAR(255),region VARCHAR(255),start_date DATE,end_date DATE,budget INT); INSERT INTO Projects (project_id,project_name,sector,region,start_date,end_date,budget) VALUES (2,'ProjectB','Community Development','Asia-Pacific','2022-01-01','2023-12-31'... | SELECT COUNT(project_id) AS active_projects, SUM(budget) AS total_budget FROM Projects WHERE sector = 'Community Development' AND region = 'Asia-Pacific' AND end_date >= '2022-01-01'; |
What is the average production quantity of Dysprosium in African countries in the last 5 years? | CREATE TABLE DysprosiumProduction (id INT PRIMARY KEY,year INT,country VARCHAR(50),production_quantity INT); | SELECT AVG(production_quantity) FROM DysprosiumProduction WHERE country IN ('Africa') AND year BETWEEN (YEAR(CURRENT_DATE) - 5) AND YEAR(CURRENT_DATE); |
What is the maximum donation amount received from a single donor in Q4, and how many times did they donate that quarter? | CREATE TABLE donations (donor_id INT,donation_date DATE,donation_amount FLOAT); INSERT INTO donations (donor_id,donation_date,donation_amount) VALUES (1,'2021-10-05',500.00),(1,'2021-11-15',250.00),(2,'2021-12-25',1000.00),(3,'2021-11-30',150.00); | SELECT MAX(donation_amount) AS max_donation, COUNT(*) AS donation_count FROM donations WHERE QUARTER(donation_date) = 4 GROUP BY donor_id HAVING max_donation = (SELECT MAX(donation_amount) FROM donations WHERE QUARTER(donation_date) = 4); |
What is the total number of community events attended by visitors from each continent? | CREATE TABLE visitor_attendance (visitor_id INT,continent VARCHAR(30),event_name VARCHAR(50)); INSERT INTO visitor_attendance (visitor_id,continent,event_name) VALUES (1,'North America','Art Festival'),(2,'North America','Art Exhibition'),(3,'Europe','History Day'); | SELECT continent, COUNT(*) as num_events FROM visitor_attendance GROUP BY continent; |
Show total customers for each size | CREATE TABLE customer_size (id INT PRIMARY KEY,size VARCHAR(10),customer_count INT); INSERT INTO customer_size (id,size,customer_count) VALUES (1,'XS',500),(2,'S',800),(3,'M',1200),(4,'L',1500); | SELECT size, SUM(customer_count) FROM customer_size GROUP BY size; |
What is the average mass of all space debris in orbit around Earth? | CREATE TABLE debris (id INT,name VARCHAR(255),mass FLOAT,orbit VARCHAR(255)); | SELECT AVG(debris.mass) FROM debris WHERE debris.orbit = 'LEO' OR debris.orbit = 'GEO' OR debris.orbit = 'MEO'; |
What is the total waste generation in grams for each circular economy initiative in 2018? | CREATE TABLE circular_economy (initiative VARCHAR(50),year INT,waste_generation FLOAT); INSERT INTO circular_economy (initiative,year,waste_generation) VALUES ('Waste to Energy',2018,3000),('Recycling Program',2018,4000),('Composting Program',2018,2000); | SELECT initiative, SUM(waste_generation) FROM circular_economy WHERE year = 2018 GROUP BY initiative; |
What is the minimum number of animals that need to be reintroduced in Africa for the 'Lion' species? | CREATE TABLE Reintroduction (AnimalID INT,AnimalName VARCHAR(50),Minimum INT,Location VARCHAR(50)); INSERT INTO Reintroduction (AnimalID,AnimalName,Minimum,Location) VALUES (1,'Lion',150,'Africa'); INSERT INTO Reintroduction (AnimalID,AnimalName,Minimum,Location) VALUES (2,'Elephant',200,'Africa'); | SELECT MIN(Minimum) FROM Reintroduction WHERE AnimalName = 'Lion' AND Location = 'Africa'; |
List the top 5 jurisdictions with the highest number of traffic violations in 2019. | CREATE TABLE traffic_violations (id INT PRIMARY KEY,jurisdiction VARCHAR(255),violation_year INT,violation_count INT); INSERT INTO traffic_violations (id,jurisdiction,violation_year,violation_count) VALUES (1,'Los Angeles',2019,50000),(2,'San Francisco',2019,30000),(3,'San Diego',2019,25000),(4,'Oakland',2019,20000),(5... | SELECT jurisdiction, SUM(violation_count) as total_violations FROM traffic_violations WHERE violation_year = 2019 GROUP BY jurisdiction ORDER BY total_violations DESC LIMIT 5; |
What are the names of the top 2 most active researchers in terms of published articles? | CREATE TABLE researchers (id INT,name TEXT,affiliation TEXT); INSERT INTO researchers (id,name,affiliation) VALUES (1,'Alice','University A'); INSERT INTO researchers (id,name,affiliation) VALUES (2,'Bob','University B'); INSERT INTO researchers (id,name,affiliation) VALUES (3,'Charlie','University C'); CREATE TABLE ar... | SELECT name, RANK() OVER (ORDER BY COUNT(author_id) DESC) as rank FROM articles GROUP BY author_id, name HAVING rank <= 2; |
Compute the percentage of non-renewable energy consumption in South America, for each country, in the last 3 years. | CREATE TABLE SA_Energy_Consumption (country VARCHAR(255),year INT,consumption INT); INSERT INTO SA_Energy_Consumption (country,year,consumption) VALUES ('Brazil',2020,70),('Argentina',2020,80),('Colombia',2020,75),('Brazil',2021,72),('Argentina',2021,82),('Colombia',2021,78); | SELECT country, (SUM(consumption) FILTER (WHERE year BETWEEN 2020 AND 2022) OVER (PARTITION BY country)::DECIMAL / SUM(consumption) OVER (PARTITION BY country)) * 100 AS pct_non_renewable FROM SA_Energy_Consumption; |
What is the total number of crimes reported in 'Park A' and 'Park B'? | CREATE TABLE crimes (id INT,park VARCHAR(20),reported_crimes INT); | SELECT SUM(reported_crimes) FROM crimes WHERE park IN ('Park A', 'Park B'); |
Which mine site had the lowest labor productivity in Q3 2023? | CREATE TABLE labor_productivity_q3_2023 (site_id INT,productivity FLOAT); INSERT INTO labor_productivity_q3_2023 (site_id,productivity) VALUES (6,12.5),(7,15.0),(8,13.3); | SELECT site_id, productivity FROM labor_productivity_q3_2023 ORDER BY productivity ASC LIMIT 1; |
What was the average cost of community development initiatives in Peru in 2018? | CREATE TABLE Community_Development_Peru (id INT,country VARCHAR(50),year INT,cost FLOAT); INSERT INTO Community_Development_Peru (id,country,year,cost) VALUES (1,'Peru',2018,12000.0),(2,'Peru',2019,14000.0),(3,'Peru',2020,16000.0); | SELECT AVG(cost) FROM Community_Development_Peru WHERE country = 'Peru' AND year = 2018; |
List the names and billing rates of all attorneys in the 'new_york' office. | CREATE TABLE office (office_id INT,office_name VARCHAR(20)); INSERT INTO office (office_id,office_name) VALUES (1,'boston'),(2,'new_york'); CREATE TABLE attorney (attorney_id INT,attorney_name VARCHAR(30),office_id INT,billing_rate DECIMAL(5,2)); | SELECT attorney_name, billing_rate FROM attorney WHERE office_id = (SELECT office_id FROM office WHERE office_name = 'new_york'); |
How many clinical trials were conducted for CardioMed in 2019? | CREATE TABLE clinical_trials (drug varchar(255),year int,trials int); INSERT INTO clinical_trials (drug,year,trials) VALUES ('CardioMed',2019,3),('CardioMed',2018,2); | SELECT trials FROM clinical_trials WHERE drug = 'CardioMed' AND year = 2019; |
How many lunar and Martian meteorites have been discovered by each country? | CREATE SCHEMA space; USE space; CREATE TABLE country (name VARCHAR(50),population INT); CREATE TABLE meteorite (id INT,name VARCHAR(50),type VARCHAR(50),country VARCHAR(50)); INSERT INTO country (name,population) VALUES ('USA',330000000),('Russia',145000000); INSERT INTO meteorite (id,name,type,country) VALUES (1,'Dhof... | SELECT s.country, COUNT(s.id) FROM space.meteorite s JOIN space.country c ON s.country = c.name WHERE s.type IN ('Lunar', 'Mars') GROUP BY s.country; |
What is the market share of Hotel Chain A in Asia? | CREATE TABLE market_share (hotel_chain VARCHAR(255),region VARCHAR(255),market_share FLOAT); INSERT INTO market_share (hotel_chain,region,market_share) VALUES ('Hotel Chain A','Asia',0.35),('Hotel Chain B','Asia',0.42),('Hotel Chain C','Asia',0.23); | SELECT market_share * 100 FROM market_share WHERE hotel_chain = 'Hotel Chain A'; |
Create a view 'safety_protocols' that includes 'chemical_id', 'chemical_name', and 'safety_rating' columns from 'chemical_inventory' table and 'safety_ratings' table | CREATE TABLE safety_ratings (chemical_id INT,safety_rating INT); | CREATE VIEW safety_protocols AS SELECT chemical_inventory.chemical_id, chemical_inventory.chemical_name, safety_ratings.safety_rating FROM chemical_inventory INNER JOIN safety_ratings ON chemical_inventory.chemical_id = safety_ratings.chemical_id; |
Insert a new record for a school named 'ABC School' located in 'New York' | CREATE TABLE schools (id INT PRIMARY KEY,name TEXT,location TEXT); | INSERT INTO schools (id, name, location) VALUES (1, 'ABC School', 'New York'); |
What is the total contract value awarded to each contracting agency in the Pacific region in 2022? | CREATE TABLE defense_contracts (contract_id INT,contract_value FLOAT,contract_date DATE,contracting_agency VARCHAR(255),region VARCHAR(255)); | SELECT contracting_agency, SUM(contract_value) FROM defense_contracts WHERE contract_date BETWEEN '2022-01-01' AND '2022-12-31' AND region = 'Pacific' GROUP BY contracting_agency; |
Get the total number of VR headsets sold in Japan and the United States | CREATE TABLE VRAdoption (Region VARCHAR(20),HeadsetsSold INT); INSERT INTO VRAdoption (Region,HeadsetsSold) VALUES ('Japan',120000),('United States',500000),('Canada',80000); | SELECT SUM(HeadsetsSold) FROM VRAdoption WHERE Region IN ('Japan', 'United States') |
What is the total budget allocated for healthcare and transportation services in Q2 2022? | CREATE TABLE MultiYearBudget2 (Quarter TEXT,Year INTEGER,Service TEXT,Amount INTEGER); INSERT INTO MultiYearBudget2 (Quarter,Year,Service,Amount) VALUES ('Q2 2022',2022,'Healthcare',1400000),('Q2 2022',2022,'Transportation',1500000); | SELECT SUM(Amount) FROM MultiYearBudget2 WHERE Quarter = 'Q2 2022' AND Service IN ('Healthcare', 'Transportation'); |
What is the total salary cost for the 'manufacturing' department? | CREATE TABLE employees (id INT,name VARCHAR(50),department VARCHAR(50),salary FLOAT); INSERT INTO employees (id,name,department,salary) VALUES (1,'John Doe','manufacturing',60000),(2,'Jane Smith','marketing',70000); | SELECT SUM(salary) FROM employees WHERE department = 'manufacturing'; |
Update records of chemical compounds with a name 'Styrene', changing safety_rating to 7 | CREATE TABLE chemical_compounds (id INT PRIMARY KEY,name VARCHAR(255),safety_rating INT,manufacturing_location VARCHAR(255)); | UPDATE chemical_compounds SET safety_rating = 7 WHERE name = 'Styrene'; |
Calculate the average budget for completed habitat preservation projects in the last 6 months | CREATE TABLE habitat_preservation (project_id INT,project_name VARCHAR(100),region VARCHAR(50),project_status VARCHAR(20),budget DECIMAL(10,2),start_date DATE); | SELECT AVG(budget) as avg_budget FROM habitat_preservation WHERE project_status = 'completed' AND start_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH); |
What is the average contract value for each vendor by contract type? | CREATE TABLE Contracts (ContractID int,ContractValue numeric(18,2),ContractType varchar(50),VendorName varchar(50)); INSERT INTO Contracts (ContractID,ContractValue,ContractType,VendorName) VALUES (1,1500000.00,'Services','Global Enterprises'),(2,1200000.00,'Goods','ABC Corp'),(3,800000.00,'Services','XYZ Inc'),(4,9000... | SELECT VendorName, ContractType, AVG(ContractValue) as AvgContractValue FROM Contracts GROUP BY VendorName, ContractType; |
What is the total value of investments for each investment strategy? | CREATE TABLE investment_strategies (id INT,name VARCHAR(255)); INSERT INTO investment_strategies (id,name) VALUES (1,'Value Investing'),(2,'Growth Investing'),(3,'Index Investing'); CREATE TABLE investments (id INT,investment_strategy_id INT,value DECIMAL(10,2)); INSERT INTO investments (id,investment_strategy_id,value... | SELECT investment_strategies.name, SUM(investments.value) FROM investment_strategies INNER JOIN investments ON investment_strategies.id = investments.investment_strategy_id GROUP BY investment_strategies.name; |
What is the average number of construction permits issued per month in Texas? | CREATE TABLE Permits (Id INT,ProjectId INT,Type VARCHAR(50),IssueDate DATE,ExpirationDate DATE,State VARCHAR(50)); INSERT INTO Permits (Id,ProjectId,Type,IssueDate,ExpirationDate,State) VALUES (1,1,'Building','2020-01-01','2020-03-01','Texas'); | SELECT COUNT(*)/COUNT(DISTINCT DATE_FORMAT(IssueDate, '%Y-%m')) AS AvgPermitsPerMonth FROM Permits WHERE State = 'Texas'; |
How many legal aid organizations exist in urban areas? | CREATE TABLE organizations (id INT,name VARCHAR(20),location VARCHAR(10)); INSERT INTO organizations (id,name,location) VALUES (1,'Legal Aid 1','Urban'); INSERT INTO organizations (id,name,location) VALUES (2,'Legal Aid 2','Rural'); | SELECT COUNT(*) FROM organizations WHERE location = 'Urban'; |
List all projects from the 'Renewable_Energy' table that are located in 'Mountain' or 'Desert' areas. | CREATE TABLE Renewable_Energy (project_id INT,project_name VARCHAR(50),location VARCHAR(50)); INSERT INTO Renewable_Energy (project_id,project_name,location) VALUES (1,'Wind Farm','Mountain'),(2,'Solar Farm','Desert'),(3,'Geothermal Plant','Volcanic Area'),(4,'Hydroelectric Dam','River'); | SELECT project_name FROM Renewable_Energy WHERE location IN ('Mountain', 'Desert'); |
Delete all rural infrastructure projects that were completed before 2020 | CREATE TABLE RuralInfrastructure (id INT,name VARCHAR(50),location VARCHAR(20),project_type VARCHAR(30),completion_date DATE); | DELETE FROM RuralInfrastructure WHERE completion_date < '2020-01-01'; |
How many volunteers signed up in each month of 2024? | CREATE TABLE volunteers (volunteer_id INT,volunteer_name TEXT,volunteer_date DATE); INSERT INTO volunteers (volunteer_id,volunteer_name,volunteer_date) VALUES (1,'Fatima Lopez','2024-01-15'),(2,'Hamza Ahmed','2024-02-20'),(3,'Jasmine Kim','2024-03-05'); | SELECT DATE_PART('month', volunteer_date) as month, COUNT(volunteer_id) as num_volunteers FROM volunteers WHERE volunteer_date BETWEEN '2024-01-01' AND '2024-12-31' GROUP BY month; |
What is the name of the player with the highest score in the Racing genre? | CREATE TABLE player (player_id INT,name VARCHAR(50),score INT,game_genre VARCHAR(20)); INSERT INTO player (player_id,name,score,game_genre) VALUES (1,'John Doe',250,'Racing'); INSERT INTO player (player_id,name,score,game_genre) VALUES (2,'Jane Smith',300,'RPG'); INSERT INTO player (player_id,name,score,game_genre) VAL... | SELECT name FROM player WHERE game_genre = 'Racing' AND score = (SELECT MAX(score) FROM player WHERE game_genre = 'Racing'); |
What is the total number of marine species in the Pacific Ocean? | CREATE TABLE pacific_species (species_name VARCHAR(255),species_count INT); INSERT INTO pacific_species (species_name,species_count) VALUES ('Clownfish',1),('Jellyfish',2); | SELECT SUM(species_count) FROM pacific_species; |
Create a new table for preservation projects with an ID, name, country, and start date. | CREATE TABLE preservation_projects (project_id INT,project_name TEXT,country TEXT,start_date DATE); | INSERT INTO preservation_projects (project_id, project_name, country, start_date) VALUES (1, 'Green Gate Restoration', 'Poland', '2022-05-01'), (2, 'Machu Picchu Conservation', 'Peru', '2022-06-15'); |
List all legal technology grants awarded by a specific organization | CREATE TABLE grants (id INT PRIMARY KEY,organization VARCHAR(255),category VARCHAR(255),amount DECIMAL(10,2),date_awarded DATE); | SELECT * FROM grants WHERE organization = 'Legal Code Foundation'; |
What is the total number of libraries and parks in California, and how many of them are located in Los Angeles County? | CREATE TABLE states (id INT,name VARCHAR(255)); INSERT INTO states (id,name) VALUES (1,'California'); CREATE TABLE libraries (id INT,state_id INT,name VARCHAR(255)); INSERT INTO libraries (id,state_id) VALUES (1,1),(2,1),(3,1); CREATE TABLE parks (id INT,state_id INT,name VARCHAR(255)); INSERT INTO parks (id,state_id) ... | SELECT COUNT(libraries.id) + COUNT(parks.id) AS total_locations, COUNT(counties.name) AS la_county_locations FROM libraries INNER JOIN states ON libraries.state_id = states.id INNER JOIN parks ON libraries.state_id = parks.state_id INNER JOIN counties ON states.id = counties.state_id WHERE states.name = 'California' AN... |
Identify ethical manufacturing companies in India | CREATE TABLE ethical_manufacturing (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),ethical_rating DECIMAL(3,2)); INSERT INTO ethical_manufacturing (id,name,location,ethical_rating) VALUES (6,'Fair Trade Fabrics','Mumbai,India',4.8); | SELECT * FROM ethical_manufacturing WHERE location = 'Mumbai, India'; |
What are the names of all spacecraft that were launched by both NASA and SpaceX? | CREATE TABLE Spacecraft (id INT,name VARCHAR(50),manufacturer VARCHAR(50),launch_date DATE); INSERT INTO Spacecraft (id,name,manufacturer,launch_date) VALUES (1,'Voyager 1','NASA','1977-09-05'),(2,'Dragon 1','SpaceX','2010-12-08'); | SELECT s.name FROM Spacecraft s WHERE s.manufacturer IN ('NASA', 'SpaceX') GROUP BY s.name HAVING COUNT(DISTINCT s.manufacturer) = 2; |
Update the name of the smart contract with ID 3 to 'SmartContractX' | CREATE TABLE smart_contracts (id INT,name VARCHAR(20),description VARCHAR(50)); INSERT INTO smart_contracts (id,name,description) VALUES (1,'SmartContractA','Sample Description A'),(2,'SmartContractB','Sample Description B'),(3,'SmartContractY','Sample Description Y'); | UPDATE smart_contracts SET name = 'SmartContractX' WHERE id = 3; |
Show the number of startups founded by 'Alice Zhang' | CREATE TABLE company (id INT,name TEXT,founding_year INT,founder_name TEXT); INSERT INTO company (id,name,founding_year,founder_name) VALUES (1,'Acme Inc',2010,'Alice Zhang'); INSERT INTO company (id,name,founding_year,founder_name) VALUES (2,'Brick Co',2012,'John Smith'); | SELECT COUNT(*) FROM company c WHERE c.founder_name = 'Alice Zhang'; |
Find the average investment in renewable energy projects in the 'renewable_energy' schema located in 'TX'. | CREATE TABLE renewable_energy (id INT,project_name VARCHAR(50),location VARCHAR(50),investment FLOAT); INSERT INTO renewable_energy (id,project_name,location,investment) VALUES (1,'Solar Farm','Arizona',12000000),(2,'Wind Turbines','Texas',8000000); | SELECT AVG(investment) FROM renewable_energy WHERE location = 'Texas'; |
How many satellites were deployed in each country? | CREATE TABLE satellite_deployment (country VARCHAR(20),satellites INT); INSERT INTO satellite_deployment (country,satellites) VALUES ('United States',1500),('Russia',1200),('China',800); | SELECT country, satellites FROM satellite_deployment; |
What is the average trip duration for tourists visiting Barcelona? | CREATE TABLE tourism_stats (id INT,city VARCHAR(20),trip_duration FLOAT); INSERT INTO tourism_stats (id,city,trip_duration) VALUES (1,'Barcelona',5.6),(2,'Barcelona',4.8),(3,'Rome',6.2); | SELECT AVG(trip_duration) FROM tourism_stats WHERE city = 'Barcelona'; |
What is the maximum flight altitude for each aircraft model? | CREATE TABLE AircraftModel (ID INT,Name VARCHAR(50),ManufacturerID INT); CREATE TABLE FlightData (ID INT,AircraftModelID INT,Altitude INT); | SELECT am.Name, MAX(fd.Altitude) AS MaxAltitude FROM AircraftModel am JOIN FlightData fd ON am.ID = fd.AircraftModelID GROUP BY am.Name; |
How many games were won by the home team in the last season? | CREATE TABLE games (id INT,team TEXT,season INT,home_or_away TEXT,wins INT,losses INT); INSERT INTO games (id,team,season,home_or_away,wins,losses) VALUES (1,'Team A',2021,'Home',25,8); INSERT INTO games (id,team,season,home_or_away,wins,losses) VALUES (2,'Team B',2021,'Away',18,14); | SELECT team, SUM(wins) FROM games WHERE home_or_away = 'Home' AND season = 2021 GROUP BY team; |
Find the number of Renewable Energy projects in Ontario, Canada | CREATE TABLE renewable_projects_3 (project_id INT,name VARCHAR(50),type VARCHAR(50),location VARCHAR(50)); INSERT INTO renewable_projects_3 (project_id,name,type,location) VALUES (1,'Canada Renewable Project 1','Solar','Ontario'); | SELECT COUNT(*) FROM renewable_projects_3 WHERE location = 'Ontario'; |
Display the total number of cases won by each attorney | CREATE TABLE attorney_performance_metrics (attorney_id INT PRIMARY KEY,win_rate DECIMAL(5,4),cases_handled INT); CREATE TABLE case_assignments (case_id INT,attorney_id INT,PRIMARY KEY (case_id,attorney_id)); CREATE TABLE case_outcomes (case_id INT,outcome TEXT,precedent TEXT); | SELECT attorney_id, SUM(CASE WHEN outcome = 'Won' THEN 1 ELSE 0 END) as cases_won FROM case_assignments JOIN case_outcomes ON case_assignments.case_id = case_outcomes.case_id GROUP BY attorney_id; |
What is the maximum number of hours volunteered in a single day in 2021? | CREATE TABLE volunteer_hours (volunteer_hours_id INT,hours_volunteered INT,volunteer_date DATE); INSERT INTO volunteer_hours (volunteer_hours_id,hours_volunteered,volunteer_date) VALUES (1,10,'2021-01-01'),(2,15,'2021-02-15'),(3,20,'2021-03-15'); | SELECT MAX(hours_volunteered) FROM volunteer_hours WHERE YEAR(volunteer_date) = 2021; |
What is the total amount donated by small donors (those who have donated less than $1000) in the Donations table? | CREATE TABLE Donations (DonationID INT PRIMARY KEY,DonorID INT,DonationDate DATE,DonationAmount DECIMAL(10,2)); INSERT INTO Donations (DonationID,DonorID,DonationDate,DonationAmount) VALUES (1,1,'2020-01-01',500.00),(2,2,'2020-01-02',750.00),(3,3,'2020-01-03',1200.00); | SELECT SUM(DonationAmount) FROM Donations WHERE DonationAmount < 1000; |
What is the minimum age of astronauts who have flown on SpaceX or NASA crafts? | CREATE TABLE astronauts (astronaut_id INT,name VARCHAR(100),age INT,craft VARCHAR(50)); INSERT INTO astronauts (astronaut_id,name,age,craft) VALUES (1,'John',45,'Dragon'),(2,'Sarah',36,'Starship'),(3,'Mike',50,'Falcon'),(4,'Jane',42,'Apollo'),(5,'Emma',34,'Shuttle'),(6,'Bruce',30,'Shuttle'); CREATE TABLE spacex_crafts ... | SELECT MIN(age) FROM astronauts WHERE craft IN (SELECT craft FROM spacex_crafts) OR craft IN (SELECT craft FROM nasa_crafts); |
What is the average response time for emergency incidents in each region, broken down by incident type? | CREATE TABLE emergency_responses (id INT,region TEXT,incident_type TEXT,response_time INT); INSERT INTO emergency_responses (id,region,incident_type,response_time) VALUES (1,'Region 1','Fire',8),(2,'Region 1','Fire',9),(3,'Region 1','Medical',10),(4,'Region 1','Medical',12),(5,'Region 2','Fire',7),(6,'Region 2','Fire',... | SELECT region, incident_type, AVG(response_time) AS avg_response_time FROM emergency_responses GROUP BY region, incident_type; |
Identify the top five states with the highest water usage in industrial applications in the last quarter. | CREATE TABLE industrial_usage (state VARCHAR(20),usage FLOAT,timestamp TIMESTAMP); INSERT INTO industrial_usage (state,usage,timestamp) VALUES ('California',12000,'2022-01-01 10:00:00'),('Texas',15000,'2022-01-02 10:00:00'); | SELECT state, SUM(usage) AS total_usage FROM industrial_usage WHERE timestamp BETWEEN DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 3 MONTH) AND CURRENT_TIMESTAMP GROUP BY state ORDER BY total_usage DESC LIMIT 5; |
What is the average price of a quarter of an ounce of cannabis in each state, rounded to the nearest dollar? | CREATE TABLE PricesByState (state VARCHAR(255),price DECIMAL(10,2),product VARCHAR(255)); INSERT INTO PricesByState (state,price,product) VALUES ('CA',45,'Quarter'),('CO',40,'Quarter'),('OR',35,'Quarter'),('WA',42,'Quarter'),('MI',38,'Quarter'); | SELECT state, ROUND(AVG(price)) as average_price FROM PricesByState WHERE product = 'Quarter' GROUP BY state; |
Who are the top 5 countries receiving climate finance for mitigation projects? | CREATE TABLE climate_finance (id INT,country VARCHAR(50),amount FLOAT,sector VARCHAR(50)); | SELECT cf.country, SUM(cf.amount) FROM climate_finance cf WHERE cf.sector = 'mitigation' GROUP BY cf.country ORDER BY SUM(cf.amount) DESC LIMIT 5; |
What is the total biomass of all whale shark populations? | CREATE TABLE whale_sharks (population TEXT,biomass NUMERIC); INSERT INTO whale_sharks (population,biomass) VALUES ('Atlantic Ocean','18000000'); INSERT INTO whale_sharks (population,biomass) VALUES ('Pacific Ocean','23000000'); | SELECT SUM(biomass) FROM whale_sharks; |
List all policyholders who have not filed any claims, ordered alphabetically by policyholder name. | CREATE TABLE Policyholders (PolicyID INT,PolicyholderName TEXT); INSERT INTO Policyholders (PolicyID,PolicyholderName) VALUES (1,'John Doe'),(2,'Jane Smith'),(3,'Bob Johnson'); CREATE TABLE Claims (ClaimID INT,PolicyID INT); INSERT INTO Claims (ClaimID,PolicyID) VALUES (1,1),(2,1),(3,2); | SELECT Policyholders.PolicyID, Policyholders.PolicyholderName FROM Policyholders LEFT JOIN Claims ON Policyholders.PolicyID = Claims.PolicyID WHERE Claims.ClaimID IS NULL ORDER BY Policyholders.PolicyholderName; |
What is the total billing amount for cases in the 'Central' region, excluding cases with a billing amount less than $7000? | CREATE TABLE cases (id INT,region VARCHAR(10),billing_amount INT); INSERT INTO cases (id,region,billing_amount) VALUES (1,'Eastern',5000),(2,'Western',7000),(3,'Eastern',6000),(4,'Central',8000),(5,'Central',6000),(6,'Central',4000); | SELECT SUM(billing_amount) FROM cases WHERE region = 'Central' AND billing_amount > 7000; |
What are the names and ethnicities of farmers in the Southeast who practice agroecology? | CREATE TABLE farmers (id INT PRIMARY KEY,name VARCHAR(50),age INT,ethnicity VARCHAR(20),region VARCHAR(25),practice VARCHAR(25)); INSERT INTO farmers (id,name,age,ethnicity,region,practice) VALUES (1,'Jamal Davis',42,'African American','Southeast','Agroecology'); INSERT INTO farmers (id,name,age,ethnicity,region,practi... | SELECT name, ethnicity FROM farmers WHERE practice = 'Agroecology' AND region = 'Southeast'; |
What is the total amount of humanitarian assistance provided by the United Nations in 2018? | CREATE TABLE humanitarian_assistance (id INT,provider VARCHAR(255),year INT,amount FLOAT); INSERT INTO humanitarian_assistance (id,provider,year,amount) VALUES (1,'United Nations',2018,50000000); | SELECT SUM(amount) FROM humanitarian_assistance WHERE provider = 'United Nations' AND year = 2018; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.