instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
Insert a new spacecraft record for Rocket X launched by JAXA in 2025
|
CREATE TABLE Spacecraft (Name TEXT,Agency TEXT,Launch_Date TEXT);
|
INSERT INTO Spacecraft (Name, Agency, Launch_Date) VALUES ('Rocket X', 'JAXA', '2025-04-25');
|
Which countries in Africa have a carbon pricing (in USD/ton) that is lower than the average for the continent?
|
CREATE TABLE africa_carbon_pricing (id INT,country VARCHAR(50),price FLOAT); INSERT INTO africa_carbon_pricing (id,country,price) VALUES (1,'South Africa',10.5),(2,'Egypt',15.2),(3,'Nigeria',5.1);
|
SELECT country, price FROM africa_carbon_pricing WHERE price < (SELECT AVG(price) FROM africa_carbon_pricing);
|
How many rural infrastructure projects in Mexico were completed in the last 5 years?
|
CREATE TABLE projects(id INT,name TEXT,country TEXT,completion_date DATE); INSERT INTO projects(id,name,country,completion_date) VALUES (1,'Bridge Construction','Mexico','2022-03-01'),(2,'Power Grid Expansion','Mexico','2020-12-31');
|
SELECT COUNT(*) FROM projects WHERE country = 'Mexico' AND completion_date >= DATE('2016-01-01');
|
What is the most popular destination by month for each continent?
|
CREATE TABLE continent (continent_code CHAR(2),continent_name VARCHAR(50)); INSERT INTO continent VALUES ('AF','Africa'),('AS','Asia'); CREATE TABLE visit_details (continent_code CHAR(2),visit_month DATE,destination VARCHAR(50),visitor_count INT); INSERT INTO visit_details VALUES ('AF','2021-01-01','Marrakech',200),('AF','2021-02-01','Cairo',300),('AS','2021-01-01','Tokyo',500),('AS','2021-02-01','Beijing',400);
|
SELECT continent_code, visit_month, destination, ROW_NUMBER() OVER (PARTITION BY continent_code, visit_month ORDER BY visitor_count DESC) AS rank FROM visit_details;
|
Identify the number of wind energy transactions for each buyer in 2023.
|
CREATE TABLE renewable_energy_transactions (id INT,buyer_id INT,seller_id INT,type VARCHAR(15),amount INT,date DATE); INSERT INTO renewable_energy_transactions (id,buyer_id,seller_id,type,amount,date) VALUES (1,1001,2001,'Wind Energy',200,'2023-01-01');
|
SELECT buyer_id, COUNT(*) as num_wind_transactions FROM renewable_energy_transactions WHERE type = 'Wind Energy' AND date BETWEEN '2023-01-01' AND '2023-12-31' GROUP BY buyer_id;
|
What is the average total funding for successful biotech startups founded between 2018 and 2020, grouped by their country of origin?
|
CREATE TABLE biotech_startups (id INT PRIMARY KEY,name VARCHAR(255),total_funding DECIMAL(10,2),employees INT,founding_year INT,country VARCHAR(255));
|
SELECT country, AVG(total_funding) FROM biotech_startups WHERE founding_year BETWEEN 2018 AND 2020 AND employees > 50 GROUP BY country;
|
Which members have a resting heart rate above 85?
|
CREATE TABLE member_hr (member_id INT,resting_heart_rate INT); INSERT INTO member_hr (member_id,resting_heart_rate) VALUES (1,75),(2,82),(3,65),(4,88),(5,72);
|
SELECT member_id FROM member_hr WHERE resting_heart_rate > 85;
|
Add a new healthcare facility 'RuralHealthFacility11' with 50 beds.
|
CREATE TABLE RuralHealthFacility11 (facility_id INT,facility_name VARCHAR(50),num_beds INT);
|
INSERT INTO RuralHealthFacility11 (facility_id, facility_name, num_beds) VALUES (31, 'RuralHealthFacility11', 50);
|
How many rural infrastructure projects were completed in Nigeria before 2020?'
|
CREATE TABLE RuralInfrastructureProjects (id INT,country VARCHAR(50),project_name VARCHAR(100),start_date DATE,end_date DATE); INSERT INTO RuralInfrastructureProjects (id,country,project_name,start_date,end_date) VALUES (1,'Nigeria','Electricity Grid Extension','2018-01-01','2019-12-31');
|
SELECT COUNT(*) FROM RuralInfrastructureProjects WHERE country = 'Nigeria' AND YEAR(end_date) < 2020;
|
Delete records of artisans who have not been active since 2010
|
CREATE TABLE Artisans (Id INT,Name TEXT,ActivityYear INT,Country TEXT); INSERT INTO Artisans (Id,Name,ActivityYear,Country) VALUES (1,'John',2005,'USA');
|
DELETE FROM Artisans WHERE ActivityYear < 2010;
|
How many attendees at the ArtExpo event identified as Hispanic or Latino?
|
CREATE TABLE ArtExpo (AttendeeID INT,AttendeeEthnicity VARCHAR(50));
|
SELECT COUNT(*) FROM ArtExpo WHERE AttendeeEthnicity = 'Hispanic' OR AttendeeEthnicity = 'Latino';
|
Find the number of articles published per month in the 'politics' section in 2022
|
CREATE TABLE articles (id INT PRIMARY KEY,title VARCHAR(255),section VARCHAR(255),date DATE); INSERT INTO articles (id,title,section,date) VALUES (1,'The Future of Politics','politics','2022-01-01'),(2,'The Impact of Climate Change on Agriculture','environment','2022-03-15'),(3,'The Rise of Solar Energy','technology','2021-12-20'),(4,'The Hidden World of Cryptocurrency','business','2022-06-01'),(5,'The Future of Education','politics','2022-02-01');
|
SELECT MONTH(date), COUNT(*) FROM articles WHERE section = 'politics' AND YEAR(date) = 2022 GROUP BY MONTH(date);
|
What is the average maintenance cost for military equipment in the past year, broken down by equipment type?
|
CREATE TABLE Equipment_Maintenance (Equipment_ID INT,Equipment_Type VARCHAR(50),Maintenance_Date DATE,Maintenance_Cost FLOAT,Maintenance_Company VARCHAR(50));
|
SELECT Equipment_Type, AVG(Maintenance_Cost) as Average_Maintenance_Cost FROM Equipment_Maintenance WHERE Maintenance_Date >= DATEADD(year, -1, GETDATE()) GROUP BY Equipment_Type;
|
What is the average donation amount for donors who have made more than 3 donations in the year 2021?
|
CREATE TABLE donations (donor_id INT,donation_amount DECIMAL(10,2),donation_date DATE);
|
SELECT AVG(donation_amount) FROM donations WHERE YEAR(donation_date) = 2021 GROUP BY donor_id HAVING COUNT(*) > 3;
|
What is the maximum amount invested in a single project in the education sector?
|
CREATE TABLE ImpactInvestments (InvestmentID INT,InvestorID INT,NonprofitID INT,Amount DECIMAL(10,2),Year INT,Sector VARCHAR(50)); INSERT INTO ImpactInvestments (InvestmentID,InvestorID,NonprofitID,Amount,Year,Sector) VALUES (1,3,1,20000.00,2021,'Education'); INSERT INTO ImpactInvestments (InvestmentID,InvestorID,NonprofitID,Amount,Year,Sector) VALUES (2,4,2,15000.00,2020,'Health'); INSERT INTO ImpactInvestments (InvestmentID,InvestorID,NonprofitID,Amount,Year,Sector) VALUES (3,5,3,25000.00,2022,'Education');
|
SELECT MAX(Amount) FROM ImpactInvestments WHERE Sector = 'Education';
|
Find the number of renewable energy infrastructure projects per category, ordered by the number of projects in descending order?
|
CREATE TABLE renewable_energy (id INT,name VARCHAR(255),category VARCHAR(255)); INSERT INTO renewable_energy (id,name,category) VALUES (1,'Solar Farm','solar'); INSERT INTO renewable_energy (id,name,category) VALUES (2,'Wind Farm','wind'); INSERT INTO renewable_energy (id,name,category) VALUES (3,'Hydroelectric Dam','hydro'); INSERT INTO renewable_energy (id,name,category) VALUES (4,'Geothermal Plant','geothermal'); INSERT INTO renewable_energy (id,name,category) VALUES (5,'Biomass Power Plant','biomass');
|
SELECT category, COUNT(*) OVER (PARTITION BY category) AS num_projects FROM renewable_energy ORDER BY num_projects DESC;
|
What is the average duration of tours in Brazil longer than 3 days?
|
CREATE TABLE tours (tour_id INT,name TEXT,country TEXT,duration INT,is_sustainable BOOLEAN); INSERT INTO tours (tour_id,name,country,duration,is_sustainable) VALUES (1,'Brazil Explorer','Brazia',7,TRUE),(2,'Quick Brazil Tour','Brazil',2,FALSE);
|
SELECT AVG(duration) FROM tours WHERE country = 'Brazil' AND duration > 3;
|
Update the email address for donor 'John Doe' in the Donors table.
|
CREATE TABLE Donors (donor_id INT PRIMARY KEY,donor_name TEXT,email TEXT);
|
UPDATE Donors SET email = '[email protected]' WHERE donor_name = 'John Doe';
|
What is the most common art medium for artists from Africa?
|
CREATE TABLE artists (id INT,name TEXT,country TEXT,medium TEXT); INSERT INTO artists (id,name,country,medium) VALUES (1,'John Doe','Nigeria','Sculpture'),(2,'Jane Smith','Kenya','Painting'),(3,'Mohamed Ahmed','Egypt','Sculpture'),(4,'Aisha Mohamed','Senegal','Painting'),(5,'Pedro Gonzales','South Africa','Drawing');
|
SELECT country, medium, COUNT(*) AS frequency FROM artists WHERE country LIKE '%Africa%' GROUP BY country, medium ORDER BY frequency DESC LIMIT 1;
|
List all excavation sites where at least one pottery artifact was found.
|
CREATE TABLE excavation_sites (id INT,site_name VARCHAR(255)); CREATE TABLE artifacts (id INT,excavation_site_id INT,artifact_type VARCHAR(255));
|
SELECT e.site_name FROM excavation_sites e JOIN artifacts a ON e.id = a.excavation_site_id WHERE a.artifact_type = 'pottery' GROUP BY e.site_name HAVING COUNT(a.id) > 0;
|
List all unique countries where ads were shown on Instagram in the last month.
|
CREATE TABLE ad_data (ad_id INT,platform VARCHAR(20),country VARCHAR(50),date DATE); INSERT INTO ad_data (ad_id,platform,country,date) VALUES (1,'Instagram','USA','2022-01-01'),(2,'Facebook','Canada','2022-01-02'),(3,'Instagram','Mexico','2022-01-03');
|
SELECT DISTINCT country FROM ad_data WHERE platform = 'Instagram' AND date >= DATEADD(month, -1, GETDATE());
|
What is the average capacity of plants located in 'CityX'?
|
CREATE TABLE plants (plant_id INT,plant_name VARCHAR(50),city VARCHAR(50),capacity INT); INSERT INTO plants (plant_id,plant_name,city,capacity) VALUES (1,'PlantA','CityX',1000),(2,'PlantB','CityY',700),(3,'PlantC','CityX',1500),(4,'PlantD','CityZ',800);
|
SELECT AVG(capacity) FROM plants WHERE city = 'CityX';
|
What is the average waste generation and production volume for mines located in the Andes?
|
CREATE TABLE mine_operations (id INT PRIMARY KEY,mine_name VARCHAR(255),location VARCHAR(255),extraction_type VARCHAR(255),production_volume INT);CREATE TABLE environmental_impact (id INT PRIMARY KEY,mine_id INT,pollution_level INT,waste_generation INT);
|
SELECT AVG(m.production_volume) as avg_production, AVG(e.waste_generation) as avg_waste_generation FROM mine_operations m JOIN environmental_impact e ON m.id = e.mine_id WHERE m.location = 'Andes';
|
What is the number of Tuberculosis cases in Asia by country?
|
CREATE TABLE Tuberculosis (Country VARCHAR(50),Continent VARCHAR(50),Number_Cases INT); INSERT INTO Tuberculosis (Country,Continent,Number_Cases) VALUES ('China','Asia',869033),('India','Asia',2690400);
|
SELECT Country, Number_Cases FROM Tuberculosis WHERE Continent = 'Asia';
|
What is the total number of registered voters by county in the state of Ohio?
|
CREATE TABLE voters (id INT,voter_name VARCHAR(50),county VARCHAR(50),state VARCHAR(50)); INSERT INTO voters (id,voter_name,county,state) VALUES (1,'Voter A','County A','Ohio'),(2,'Voter B','County B','Ohio'),(3,'Voter C','County A','Ohio');
|
SELECT state, county, COUNT(*) as total_voters FROM voters WHERE state = 'Ohio' GROUP BY state, county;
|
What is the total amount of food aid delivered to "Middle East" in Q1 2022?
|
CREATE TABLE food_aid (id INT,delivery_id INT,destination_country VARCHAR(255),delivery_quantity INT,delivery_date DATE); INSERT INTO food_aid (id,delivery_id,destination_country,delivery_quantity,delivery_date) VALUES (1,5001,'Iraq',500,'2022-01-01'); INSERT INTO food_aid (id,delivery_id,destination_country,delivery_quantity,delivery_date) VALUES (2,5002,'Syria',750,'2022-03-01');
|
SELECT SUM(delivery_quantity) FROM food_aid WHERE destination_country = 'Middle East' AND QUARTER(delivery_date) = 1 AND YEAR(delivery_date) = 2022;
|
What is the difference in the average income of citizens in 'CityY' and 'CityZ' in 2021?
|
CREATE TABLE CityY_Income (ID INT,Year INT,Income FLOAT); INSERT INTO CityY_Income (ID,Year,Income) VALUES (1,2021,50000),(2,2021,55000); CREATE TABLE CityZ_Income (ID INT,Year INT,Income FLOAT); INSERT INTO CityZ_Income (ID,Year,Income) VALUES (1,2021,60000),(2,2021,65000);
|
SELECT AVG(CityY_Income.Income) - AVG(CityZ_Income.Income) FROM CityY_Income, CityZ_Income WHERE CityY_Income.Year = 2021 AND CityZ_Income.Year = 2021;
|
Count the number of active rigs in the Caspian Sea in 2019
|
CREATE TABLE rigs (id INT PRIMARY KEY,name TEXT,status TEXT,location TEXT); INSERT INTO rigs (id,name,status,location) VALUES (9,'Rig E','Active','Caspian Sea'),(10,'Rig F','Inactive','Caspian Sea'),(11,'Rig G','Active','Caspian Sea'),(12,'Rig H','Inactive','North Sea'); CREATE TABLE rig_history (rig_id INT,year INT,active_rigs INT); INSERT INTO rig_history (rig_id,year,active_rigs) VALUES (9,2018,1),(9,2019,1),(10,2018,0),(10,2019,0),(11,2018,1),(11,2019,1),(12,2018,0),(12,2019,0);
|
SELECT COUNT(*) as num_active_rigs FROM rig_history rh JOIN rigs r ON rh.rig_id = r.id WHERE r.location = 'Caspian Sea' AND rh.year = 2019 AND r.status = 'Active';
|
List the diversity metrics for each company, including the percentage of female founders and the average age of founders.
|
CREATE TABLE companies (id INT,name TEXT); CREATE TABLE founders (id INT,company_id INT,name TEXT,gender TEXT,birthdate DATE); INSERT INTO companies (id,name) VALUES (1,'Acme Inc'),(2,'Zebra Corp'); INSERT INTO founders (id,company_id,name,gender,birthdate) VALUES (1,1,'Alice','Female','1980-05-05'),(2,1,'Bob','Male','1978-08-12'),(3,2,'Charlie','Male','1990-03-14'),(4,2,'David','Male','1985-11-17'),(5,2,'Eve','Female','1992-06-20');
|
SELECT companies.name, AVG(YEAR(CURRENT_DATE) - YEAR(founders.birthdate)) as avg_age, COUNT(*) FILTER (WHERE founders.gender = 'Female') * 100.0 / COUNT(*) as female_founders_percentage FROM companies INNER JOIN founders ON companies.id = founders.company_id GROUP BY companies.name;
|
What is the total revenue generated by eco-friendly hotels in Paris?
|
CREATE TABLE hotels(id INT,name TEXT,city TEXT,sustainable BOOLEAN,revenue FLOAT); INSERT INTO hotels(id,name,city,sustainable,revenue) VALUES (1,'EcoHotel de Paris','Paris',true,120000.0);
|
SELECT SUM(revenue) FROM hotels WHERE sustainable = true AND city = 'Paris';
|
Find the number of clean energy policies implemented in each country and the percentage of total policies they represent.
|
CREATE TABLE Country (CountryID INT,CountryName VARCHAR(100)); INSERT INTO Country VALUES (1,'Canada'),(2,'USA'),(3,'Mexico'),(4,'Brazil'),(5,'Germany'); CREATE TABLE Policy (PolicyID INT,PolicyName VARCHAR(100),CountryID INT); INSERT INTO Policy VALUES (1,'Clean Energy Policy 1',1),(2,'Clean Energy Policy 2',1),(3,'Clean Energy Policy 3',2),(4,'Clean Energy Policy 4',2),(5,'Clean Energy Policy 5',3);
|
SELECT CountryName, COUNT(PolicyID) AS NumPolicies, (COUNT(PolicyID) * 100.0 / (SELECT COUNT(PolicyID) FROM Policy)) AS Percentage FROM Policy JOIN Country ON Policy.CountryID = Country.CountryID GROUP BY CountryName;
|
How many species of fish are present in sustainable seafood trend reports from the last 5 years?
|
CREATE TABLE seafood_trends (year INT,species VARCHAR(50)); INSERT INTO seafood_trends (year,species) VALUES (2017,'Salmon'),(2017,'Tuna'),(2017,'Shrimp'),(2018,'Cod'),(2018,'Salmon'),(2018,'Tuna'),(2019,'Shrimp'),(2019,'Cod'),(2019,'Salmon'),(2020,'Tuna'),(2020,'Shrimp'),(2021,'Cod'),(2021,'Salmon'),(2021,'Tuna'),(2021,'Pollock');
|
SELECT COUNT(DISTINCT species) FROM seafood_trends WHERE year BETWEEN 2016 AND 2021;
|
What is the minimum ad revenue for users from Canada?
|
CREATE TABLE users (id INT,country VARCHAR(2),ad_revenue DECIMAL(10,2)); INSERT INTO users (id,country,ad_revenue) VALUES (1,'CA',500.00),(2,'US',450.00),(3,'CA',600.00),(4,'MX',300.00);
|
SELECT MIN(ad_revenue) FROM users WHERE country = 'CA';
|
Find all restaurants with a high number of violations and their respective inspections dates.
|
CREATE TABLE Restaurant_Inspections (RestaurantID INT PRIMARY KEY,RestaurantName VARCHAR(50),InspectionDate DATE,Violations INT); INSERT INTO Restaurant_Inspections (RestaurantID,RestaurantName,InspectionDate,Violations) VALUES (1,'Tasty Burgers','2022-01-10',15);
|
SELECT RestaurantName, InspectionDate FROM Restaurant_Inspections WHERE Violations > 10;
|
What is the maximum number of stories in sustainable buildings in the West?
|
CREATE TABLE West_Sustainable (building_id INT,location VARCHAR(20),stories INT,is_sustainable INT); INSERT INTO West_Sustainable VALUES (5001,'CA',5,1),(5002,'WA',7,1),(5003,'OR',3,0);
|
SELECT MAX(stories) FROM West_Sustainable WHERE is_sustainable = 1;
|
What is the total marketing budget for movies and TV shows combined?
|
CREATE TABLE marketing_budget (media_type VARCHAR(10),budget DECIMAL(10,2)); INSERT INTO marketing_budget (media_type,budget) VALUES ('Movies',5000000.00),('TV Shows',3000000.00);
|
SELECT SUM(budget) as total_budget FROM marketing_budget;
|
How many students in the database have taken a course on lifelong learning?
|
CREATE TABLE Students (StudentID INT,Age INT,Gender VARCHAR(10),CoursesTaken VARCHAR(20)); INSERT INTO Students (StudentID,Age,Gender,CoursesTaken) VALUES (1,22,'Male','Lifelong Learning'); INSERT INTO Students (StudentID,Age,Gender,CoursesTaken) VALUES (2,20,'Female','Open Pedagogy'); INSERT INTO Students (StudentID,Age,Gender,CoursesTaken) VALUES (3,25,'Male','Lifelong Learning');
|
SELECT COUNT(*) FROM Students WHERE CoursesTaken = 'Lifelong Learning';
|
What is the maximum safety score for each chemical category?
|
CREATE TABLE chemical_safety_scores_v2 (chemical_id INT,category VARCHAR(255),safety_score INT); INSERT INTO chemical_safety_scores_v2 (chemical_id,category,safety_score) VALUES (1,'Flammable Liquids',85),(2,'Corrosive Materials',92),(3,'Flammable Gases',98),(4,'Flammable Liquids',90);
|
SELECT category, MAX(safety_score) FROM chemical_safety_scores_v2 GROUP BY category;
|
Identify all ingredients that have never been used in a vegetarian dish.
|
CREATE TABLE dishes (id INT,name TEXT,vegetarian BOOLEAN,ingredient TEXT);
|
SELECT ingredient FROM dishes WHERE vegetarian = TRUE GROUP BY ingredient HAVING COUNT(DISTINCT name) = (SELECT COUNT(DISTINCT id) FROM dishes);
|
What is the total revenue of hotels in the Middle East that offer virtual tours?
|
CREATE TABLE hotel_virtual_tours_middle_east (hotel_id INT,hotel_name TEXT,country TEXT,revenue FLOAT,has_virtual_tour BOOLEAN); INSERT INTO hotel_virtual_tours_middle_east (hotel_id,hotel_name,country,revenue,has_virtual_tour) VALUES (1,'The Desert Inn','UAE',25000,true),(2,'The Seaside Resort','Oman',30000,false),(3,'Arabian Nights Hotel','Saudi Arabia',15000,true);
|
SELECT SUM(revenue) FROM hotel_virtual_tours_middle_east WHERE has_virtual_tour = true AND country = 'Middle East';
|
What is the number of unique users who streamed hip-hop music in the United States in the month of January 2022?
|
CREATE TABLE genres (genre_id INT,genre_name VARCHAR(50)); ALTER TABLE streams ADD genre_id INT; INSERT INTO genres (genre_id,genre_name) VALUES (1,'Hip-Hop'),(2,'Rock'),(3,'Pop'); ALTER TABLE streams ADD FOREIGN KEY (genre_id) REFERENCES genres(genre_id); UPDATE streams SET genre_id = 1 WHERE user_id IN (SELECT user_id FROM users WHERE user_country = 'United States' AND EXTRACT(MONTH FROM streams.stream_date) = 1 AND EXTRACT(YEAR FROM streams.stream_date) = 2022);
|
SELECT COUNT(DISTINCT user_id) AS num_unique_users FROM streams WHERE genre_id = 1;
|
Create a table for waste generation metrics
|
CREATE TABLE waste_generation_metrics (id INT PRIMARY KEY,region VARCHAR(255),total_waste_generated FLOAT,recycled_waste FLOAT,landfilled_waste FLOAT);
|
CREATE TABLE waste_generation_metrics ( id INT PRIMARY KEY, region VARCHAR(255), total_waste_generated FLOAT, recycled_waste FLOAT, landfilled_waste FLOAT);
|
Find the average depth of oceanic trenches
|
CREATE TABLE ocean_trenches (trench_name TEXT,location TEXT,average_depth FLOAT); INSERT INTO ocean_trenches (trench_name,location,average_depth) VALUES ('Mariana Trench','Western Pacific',10994),('Tonga Trench','South Pacific',10820),('Kuril Trench','North Pacific',10542);
|
SELECT AVG(average_depth) FROM ocean_trenches;
|
What is the total revenue for each drug in Q2 2018?
|
CREATE TABLE sales (drug_name TEXT,quarter TEXT,year INTEGER,revenue INTEGER); INSERT INTO sales (drug_name,quarter,year,revenue) VALUES ('DrugA','Q2',2018,4000000); INSERT INTO sales (drug_name,quarter,year,revenue) VALUES ('DrugB','Q2',2018,6000000);
|
SELECT drug_name, SUM(revenue) FROM sales WHERE quarter = 'Q2' AND year = 2018 GROUP BY drug_name;
|
What are the names and ratings of eco-friendly hotels in Germany?
|
CREATE TABLE hotel_info (hotel_id INT,hotel_name TEXT,country TEXT,rating FLOAT); INSERT INTO hotel_info (hotel_id,hotel_name,country,rating) VALUES (1,'Eco Hotel Berlin','Germany',4.5),(2,'Green Munich','Germany',4.2);
|
SELECT hotel_name, rating FROM hotel_info WHERE country = 'Germany';
|
What is the average speed of vessels with 'APL' prefix that carried dangerous goods in the Arctic Ocean in 2019?
|
CREATE TABLE Vessels (ID INT,Name TEXT,Speed FLOAT,Dangerous_Goods BOOLEAN,Prefix TEXT,Year INT);CREATE VIEW Arctic_Ocean_Vessels AS SELECT * FROM Vessels WHERE Region = 'Arctic Ocean';
|
SELECT AVG(Speed) FROM Arctic_Ocean_Vessels WHERE Prefix = 'APL' AND Dangerous_Goods = 1 AND Year = 2019;
|
How many building permits were issued in Texas in June 2020?
|
CREATE TABLE Building_Permits (Permit_ID INT,Permit_Date DATE,Location TEXT,Type TEXT); INSERT INTO Building_Permits (Permit_ID,Permit_Date,Location,Type) VALUES (1,'2020-01-01','Texas','Residential'),(2,'2020-02-15','California','Commercial'),(3,'2020-04-20','Texas','Residential'),(4,'2020-06-30','Texas','Commercial');
|
SELECT COUNT(*) FROM Building_Permits WHERE Location = 'Texas' AND Permit_Date = '2020-06-30';
|
What is the average ticket price for dance events in the city of Chicago?
|
CREATE TABLE events (name VARCHAR(255),location VARCHAR(255),category VARCHAR(255),price DECIMAL(5,2)); INSERT INTO events (name,location,category,price) VALUES ('Swan Lake','Chicago','Dance',95.00),('The Nutcracker','New York','Dance',125.00),('Hamilton','Chicago','Theatre',225.00);
|
SELECT AVG(price) FROM events WHERE location = 'Chicago' AND category = 'Dance';
|
Which excavation sites have no artifact analysis records?
|
CREATE TABLE site_e (site_id INT); CREATE TABLE artifact_analysis (site_id INT,artifact_id INT); INSERT INTO site_e (site_id) VALUES (1),(2),(3); INSERT INTO artifact_analysis (site_id,artifact_id) VALUES (1,1),(2,2),(3,3),(4,4);
|
SELECT context FROM (SELECT 'site_e' AS context EXCEPT SELECT site_id FROM artifact_analysis) AS subquery;
|
List all art pieces and artifacts from the 'ArtCollection' and 'AncientArtifacts' tables that are not currently on display.
|
CREATE TABLE ArtCollection (id INT,name VARCHAR(50),on_display BOOLEAN); CREATE TABLE AncientArtifacts (id INT,name VARCHAR(50),on_display BOOLEAN);
|
SELECT name FROM ArtCollection WHERE on_display = FALSE UNION SELECT name FROM AncientArtifacts WHERE on_display = FALSE;
|
What is the average number of hours spent on mental health support sessions per student in each department?
|
CREATE TABLE departments (department_id INT,department_name TEXT); CREATE TABLE teachers (teacher_id INT,teacher_name TEXT,department_id INT); CREATE TABLE sessions (session_id INT,teacher_id INT,student_id INT,session_date DATE,support_type TEXT,hours_spent INT); INSERT INTO departments VALUES (1,'Mathematics'),(2,'Science'),(3,'English'); INSERT INTO teachers VALUES (1,'Ms. Acevedo',1),(2,'Mr. Chen',2),(3,'Mx. Patel',3); INSERT INTO sessions VALUES (1,1,1,'2022-01-01','mental health',2),(2,2,2,'2022-01-02','mental health',3),(3,3,3,'2022-01-03','mental health',4);
|
SELECT d.department_name, AVG(s.hours_spent) FROM departments d INNER JOIN teachers t ON d.department_id = t.department_id INNER JOIN sessions s ON t.teacher_id = s.teacher_id WHERE s.support_type = 'mental health' GROUP BY d.department_id;
|
What is the total cost of sustainable building materials for each project in the 'GreenBuildings' table?
|
CREATE TABLE GreenBuildings (projectID INT,sustainableMaterialCost DECIMAL(10,2));
|
SELECT projectID, SUM(sustainableMaterialCost) FROM GreenBuildings GROUP BY projectID;
|
Determine the average bioprocess engineering efficiency of startups located in North America.
|
CREATE TABLE startups (id INT,name VARCHAR(100),location VARCHAR(50),category VARCHAR(50),efficiency FLOAT); INSERT INTO startups (id,name,location,category,efficiency) VALUES (1,'BioTech North','New York','bioprocess engineering',0.85); INSERT INTO startups (id,name,location,category,efficiency) VALUES (2,'Genetech Canada','Toronto','genetic research',0.75); INSERT INTO startups (id,name,location,category,efficiency) VALUES (3,'BioSense Mexico','Mexico City','biosensor technology',0.95);
|
SELECT AVG(efficiency) FROM startups WHERE location LIKE '%America%' AND category = 'bioprocess engineering';
|
Display the model, year, and battery range for electric vehicles in the ElectricVehicles table with a battery range of exactly 300 miles.
|
CREATE TABLE ElectricVehicles (Id INT,Brand VARCHAR(50),Model VARCHAR(50),Year INT,BatteryRange INT); INSERT INTO ElectricVehicles (Id,Brand,Model,Year,BatteryRange) VALUES (1,'Tesla','Model S',2020,402),(2,'Chevrolet','Bolt',2021,366),(3,'Nissan','Leaf',2022,300);
|
SELECT Model, Year, BatteryRange FROM ElectricVehicles WHERE BatteryRange = 300;
|
What is the average price of ethically sourced clothing items?
|
CREATE TABLE products (product_id INT,category VARCHAR(20),is_ethically_sourced BOOLEAN,price INT); INSERT INTO products (product_id,category,is_ethically_sourced,price) VALUES (1,'clothing',true,50),(2,'electronics',false,200),(3,'clothing',true,75);
|
SELECT AVG(products.price) FROM products WHERE products.category = 'clothing' AND products.is_ethically_sourced = true;
|
What is the biomass of fish in the Barents Sea grouped by feeding type?
|
CREATE TABLE fish_data (fish_name VARCHAR(50),biomass FLOAT,feeding_type VARCHAR(50)); INSERT INTO fish_data (fish_name,biomass,feeding_type) VALUES ('Cod',3000,'Carnivore'),('Herring',3500,'Planktivore'),('Capelin',2500,'Planktivore'),('Saithe',4000,'Carnivore');
|
SELECT feeding_type, SUM(biomass) AS total_biomass FROM fish_data WHERE fish_name IN (SELECT fish_name FROM barents_sea) GROUP BY feeding_type;
|
What is the total amount donated by each donor in the 'Donations' table?
|
CREATE TABLE Donations (DonorID INT,DonationDate DATE,Amount DECIMAL(10,2)); INSERT INTO Donations (DonorID,DonationDate,Amount) VALUES (1,'2020-01-01',50.00),(2,'2019-12-31',100.00);
|
SELECT DonorID, SUM(Amount) as TotalDonated FROM Donations GROUP BY DonorID;
|
Delete all sales records for the strain 'OG Kush' that occurred more than 30 days ago.
|
CREATE TABLE Sales (SaleID INT,StrainID INT,QuantitySold INT,SaleDate DATE);
|
DELETE FROM Sales WHERE StrainID = (SELECT StrainID FROM Strains WHERE StrainName = 'OG Kush') AND SaleDate < DATEADD(day, -30, GETDATE());
|
How many agricultural innovations were introduced in 2021 and 2022?
|
CREATE TABLE agri_innovations (id INT,innovation_name VARCHAR(255),introduction_year INT); INSERT INTO agri_innovations (id,innovation_name,introduction_year) VALUES (1,'Precision Agriculture',2018),(2,'Drip Irrigation',2019),(3,'Vertical Farming',2021);
|
SELECT COUNT(*) FROM agri_innovations WHERE introduction_year BETWEEN 2021 AND 2022;
|
Find the player with the most kills in a single 'Overwatch' match, and display the game, player, and kill count.
|
CREATE TABLE matches (id INT,game VARCHAR(10),player VARCHAR(50),kills INT,deaths INT,match_date DATE); INSERT INTO matches (id,game,player,kills,deaths,match_date) VALUES (1,'Overwatch','Jjonak',65,20,'2023-03-12');
|
SELECT game, player, kills FROM matches WHERE kills = (SELECT MAX(kills) FROM matches);
|
Which mines have a higher proportion of employees who are members of underrepresented communities?
|
CREATE TABLE mines (id INT,name TEXT,location TEXT,total_employees INT,underrepresented_communities INT); INSERT INTO mines (id,name,location,total_employees,underrepresented_communities) VALUES (1,'Golden Mine','Colorado,USA',300,150),(2,'Silver Ridge','Nevada,USA',400,200),(3,'Bronze Basin','Utah,USA',500,250);
|
SELECT name FROM mines WHERE underrepresented_communities > (SELECT AVG(underrepresented_communities) FROM mines)
|
Show the total number of marine species in each ocean, excluding duplicates
|
CREATE TABLE species_ocean (id INT,name VARCHAR(255),ocean VARCHAR(255)); INSERT INTO species_ocean (id,name,ocean) VALUES (1,'Dolphin','Pacific'); INSERT INTO species_ocean (id,name,ocean) VALUES (2,'Shark','Atlantic'); INSERT INTO species_ocean (id,name,ocean) VALUES (3,'Tuna','Pacific'); INSERT INTO species_ocean (id,name,ocean) VALUES (4,'Shark','Pacific');
|
SELECT ocean, COUNT(DISTINCT name) as unique_species_count FROM species_ocean GROUP BY ocean;
|
Which state in the US had the highest oil production in 2019?
|
CREATE TABLE wells (well_id INT,well_name TEXT,location TEXT,oil_production FLOAT); INSERT INTO wells (well_id,well_name,location,oil_production) VALUES (1,'Well 1','Texas',1200.5),(2,'Well 2','Texas',1500.3),(3,'Well 3','California',1700.2),(4,'Well 4','Oklahoma',800.8),(5,'Well 5','Louisiana',900.7);
|
SELECT location, SUM(oil_production) as total_oil_production FROM wells GROUP BY location ORDER BY total_oil_production DESC LIMIT 1;
|
What are the water conservation initiatives implemented in regions with increasing contaminant levels in 2020?
|
CREATE TABLE water_quality (region VARCHAR(255),year INT,contaminant_level INT); INSERT INTO water_quality (region,year,contaminant_level) VALUES ('North',2019,12),('North',2020,15),('South',2019,18),('South',2020,20); CREATE TABLE conservation_initiatives (region VARCHAR(255),year INT,initiative VARCHAR(255)); INSERT INTO conservation_initiatives (region,year,initiative) VALUES ('North',2019,'Greywater reuse'),('North',2020,'Smart toilets'),('South',2019,'Smart irrigation'),('South',2020,'Green roofs');
|
SELECT c.initiative FROM conservation_initiatives c JOIN water_quality w ON c.region = w.region WHERE c.year = w.year AND w.contaminant_level > (SELECT contaminant_level FROM water_quality WHERE region = w.region AND year = w.year - 1);
|
Find the number of autonomous driving research papers published by the top 3 countries?
|
CREATE TABLE if not exists ResearchPapers (Id int,Title varchar(200),Abstract varchar(500),Authors varchar(200),PublicationDate date,Country varchar(50),IsAutonomousDriving varchar(5)); INSERT INTO ResearchPapers (Id,Title,Abstract,Authors,PublicationDate,Country,IsAutonomousDriving) VALUES (1,'title1','abstract1','author1','2020-01-01','USA','Yes'),(2,'title2','abstract2','author2','2019-05-15','China','Yes'),(3,'title3','abstract3','author3','2018-12-30','Germany','Yes'),(4,'title4','abstract4','author4','2017-09-25','USA','No'),(5,'title5','abstract5','author5','2016-03-18','China','Yes');
|
SELECT COUNT(*) FROM (SELECT Country FROM ResearchPapers WHERE IsAutonomousDriving = 'Yes' GROUP BY Country ORDER BY COUNT(*) DESC LIMIT 3) AS Subquery;
|
What is the average call duration for each mobile network operator in the last month?
|
CREATE TABLE operator_call_history (call_history_id INT,subscriber_id INT,operator_id INT,call_duration INT,call_date DATE);
|
SELECT o.operator_name, AVG(och.call_duration) AS avg_call_duration FROM operator_call_history och INNER JOIN mobile_operators o ON och.operator_id = o.operator_id WHERE och.call_date >= DATEADD(month, -1, GETDATE()) GROUP BY o.operator_name;
|
What is the percentage of electric vehicles out of total vehicles in each city in the 'transportation' schema?
|
CREATE TABLE city_vehicles (city_name VARCHAR(255),num_electric_vehicles INT,num_total_vehicles INT); INSERT INTO city_vehicles (city_name,num_electric_vehicles,num_total_vehicles) VALUES ('San Francisco',15000,50000),('Los Angeles',20000,80000),('New York',30000,120000);
|
SELECT city_name, (num_electric_vehicles * 100.0 / num_total_vehicles) AS percentage FROM city_vehicles;
|
Which region had the highest budget for healthcare services in 2019?
|
CREATE TABLE Budget(Year INT,Region VARCHAR(20),Department VARCHAR(20),Amount INT); INSERT INTO Budget(Year,Region,Department,Amount) VALUES (2018,'North','Healthcare',25000000),(2018,'South','Healthcare',22000000),(2019,'North','Healthcare',27000000),(2019,'South','Healthcare',28000000);
|
SELECT Region, MAX(Amount) FROM Budget WHERE Year = 2019 AND Department = 'Healthcare' GROUP BY Region;
|
Find the total number of IoT sensors and their current status
|
CREATE TABLE iot_sensors (id INT,sensor_type VARCHAR(50),region VARCHAR(50),status VARCHAR(50)); INSERT INTO iot_sensors (id,sensor_type,region,status) VALUES (1,'SensorX','North','active'),(2,'SensorY','South','inactive');
|
SELECT sensor_type, COUNT(*) as total_sensors, status FROM iot_sensors GROUP BY status;
|
What is the average funding amount for startups founded by women in the technology sector?
|
CREATE TABLE startups(id INT,name TEXT,industry TEXT,founding_year INT,founder_gender TEXT); INSERT INTO startups (id,name,industry,founding_year,founder_gender) VALUES (1,'Acme Corp','Technology',2010,'Female'); INSERT INTO startups (id,name,industry,founding_year,founder_gender) VALUES (2,'Beta Inc','Technology',2015,'Male');
|
SELECT AVG(funding_amount) FROM funding JOIN startups ON startups.id = funding.startup_id WHERE startups.industry = 'Technology' AND startups.founder_gender = 'Female';
|
How many unique donors are there in each non-social cause category?
|
CREATE TABLE donors (id INT,name VARCHAR(255),country VARCHAR(255)); INSERT INTO donors (id,name,country) VALUES (1,'John Doe','USA'),(2,'Jane Smith','Canada'),(3,'Marie Johnson','France'),(4,'James Brown','USA'),(5,'Sophie White','UK'),(6,'Raul Rodriguez','Mexico'),(7,'Nina Patel','India'),(8,'Jung Kim','South Korea');
|
SELECT c.type, COUNT(DISTINCT d.id) FROM donations d JOIN causes c ON d.cause_id = c.id GROUP BY c.type HAVING c.type != 'Social';
|
What is the average response time for emergency calls in the city of 'Los Angeles'?
|
CREATE TABLE emergency_calls (id INT,city VARCHAR(20),response_time INT); INSERT INTO emergency_calls (id,city,response_time) VALUES (1,'Los Angeles',120);
|
SELECT AVG(response_time) FROM emergency_calls WHERE city = 'Los Angeles';
|
What are the types of military aircrafts owned by the US and Russia?
|
CREATE TABLE MilitaryAircrafts (Country VARCHAR(255),Type VARCHAR(255)); INSERT INTO MilitaryAircrafts (Country,Type) VALUES ('USA','F-16'),('USA','F-22'),('Russia','MiG-29'),('Russia','Su-35');
|
SELECT Type FROM MilitaryAircrafts WHERE Country IN ('USA', 'Russia') UNION SELECT Type FROM MilitaryAircrafts WHERE Country IN ('USA', 'Russia');
|
What is the total volume of timber harvested by tree species?
|
CREATE TABLE Forestry (species VARCHAR(255),volume INT); INSERT INTO Forestry (species,volume) VALUES ('Pine',2500),('Spruce',2000),('Oak',2200),('Maple',1800);
|
SELECT species, SUM(volume) as total_volume FROM Forestry GROUP BY species;
|
What is the minimum employment tenure for mines with 'emerald' mineral deposits?
|
CREATE TABLE labor_statistics (mine_name TEXT,employee_salary INTEGER,employment_tenure INTEGER,safety_record TEXT,mineral_deposit TEXT); INSERT INTO labor_statistics (mine_name,employee_salary,employment_tenure,safety_record,mineral_deposit) VALUES ('Golden Ridge Mine',60000,5,'excellent','gold'),('Silver Peak Mine',70000,7,'good','silver'),('Emerald Paradise Mine',55000,3,'very good','emerald'),('Sapphire Stone Mine',65000,6,'excellent','emerald');
|
SELECT MIN(employment_tenure) as min_employment_tenure FROM labor_statistics WHERE mineral_deposit = 'emerald';
|
What are the total expenses for restorative justice programs in the state of New York?
|
CREATE TABLE restorative_justice_programs (program_id INT,program_name TEXT,state TEXT,expenses DECIMAL(10,2)); INSERT INTO restorative_justice_programs (program_id,program_name,state,expenses) VALUES (1,'Victim-Offender Mediation','New York',50000),(2,'Restorative Circles','New York',35000),(3,'Peacemaking Circles','New York',75000);
|
SELECT SUM(expenses) FROM restorative_justice_programs WHERE state = 'New York';
|
Identify the top 3 states with the highest solar power capacity in the "SolarProjects" schema.
|
CREATE TABLE SolarCapacity (project_id INT,state VARCHAR(50),capacity INT); INSERT INTO SolarCapacity (project_id,state,capacity) VALUES (1,'California',500),(2,'Texas',400),(3,'Arizona',350);
|
SELECT state, SUM(capacity) as total_capacity FROM SolarProjects.SolarCapacity GROUP BY state ORDER BY total_capacity DESC LIMIT 3;
|
What is the average age of community health workers who identify as Latinx or Hispanic, and work in California?
|
CREATE TABLE community_health_workers (id INT,name VARCHAR(50),ethnicity VARCHAR(50),state VARCHAR(50),age INT); INSERT INTO community_health_workers (id,name,ethnicity,state,age) VALUES (1,'John Doe','Latinx','California',35),(2,'Jane Smith','Hispanic','California',40),(3,'Maria Garcia','Latinx','California',45),(4,'Pedro Rodriguez','Hispanic','California',50);
|
SELECT AVG(age) FROM community_health_workers WHERE ethnicity IN ('Latinx', 'Hispanic') AND state = 'California';
|
What is the name and email address of therapists who have conducted more than 50 therapy sessions in mental health centers located in Los Angeles?
|
CREATE TABLE mental_health_center (center_id INT,name VARCHAR(255),location VARCHAR(255)); INSERT INTO mental_health_center (center_id,name,location) VALUES (1,'Mental Health Center 1','Los Angeles'),(2,'Mental Health Center 2','Los Angeles'),(3,'Mental Health Center 3','New York'); CREATE TABLE patient (patient_id INT,center_id INT); CREATE TABLE therapy_session (session_id INT,patient_id INT,therapist_id INT,therapist_name VARCHAR(255),therapist_email VARCHAR(255),session_language VARCHAR(255));
|
SELECT therapist_name, therapist_email FROM therapy_session JOIN (SELECT therapist_id FROM therapy_session JOIN patient ON therapy_session.patient_id = patient.patient_id JOIN mental_health_center ON patient.center_id = mental_health_center.center_id WHERE mental_health_center.location = 'Los Angeles' GROUP BY therapist_id HAVING COUNT(DISTINCT patient_id) > 50) AS subquery ON therapy_session.therapist_id = subquery.therapist_id;
|
Identify the autonomous vehicles with the lowest price per mile in each country
|
CREATE TABLE autonomous_vehicles (vehicle_id INT,vehicle_name VARCHAR(255),price_per_mile DECIMAL(5,2),country VARCHAR(255));
|
SELECT vehicle_name, price_per_mile, country FROM (SELECT vehicle_name, price_per_mile, country, ROW_NUMBER() OVER (PARTITION BY country ORDER BY price_per_mile ASC) as rn FROM autonomous_vehicles) t WHERE rn = 1;
|
Find the number of players who adopted VR technology in Canada
|
CREATE TABLE Players (PlayerID INT,PlayerName VARCHAR(50),Country VARCHAR(50)); INSERT INTO Players (PlayerID,PlayerName,Country) VALUES (1,'John Smith','Canada'); INSERT INTO Players (PlayerID,PlayerName,Country) VALUES (2,'Jane Doe','USA'); CREATE TABLE VRAdoption (PlayerID INT,VRAdopted DATE); INSERT INTO VRAdoption (PlayerID,VRAdopted) VALUES (1,'2021-08-01');
|
SELECT COUNT(*) FROM Players p INNER JOIN VRAdoption va ON p.PlayerID = va.PlayerID WHERE p.Country = 'Canada';
|
Find the total number of community health centers in California and Texas
|
CREATE TABLE community_health_centers (id INT,name TEXT,state TEXT); INSERT INTO community_health_centers (id,name,state) VALUES (1,'Center A','California'),(2,'Center B','California'),(3,'Center C','Texas');
|
SELECT SUM(state IN ('California', 'Texas')) FROM community_health_centers;
|
What is the maximum number of workers in each union by industry in Texas?
|
CREATE TABLE unions (id INT,name VARCHAR(255),state VARCHAR(255)); CREATE TABLE union_industry (id INT,union_id INT,industry VARCHAR(255),workers INT); INSERT INTO unions (id,name,state) VALUES (1,'AFT','Texas'); INSERT INTO union_industry (id,union_id,industry,workers) VALUES (1,1,'Education',15000);
|
SELECT ui.industry, MAX(ui.workers) as max_workers FROM union_industry ui JOIN unions u ON ui.union_id = u.id WHERE u.state = 'Texas' GROUP BY ui.industry;
|
What is the total revenue generated from vegetarian dishes in the West region?
|
CREATE TABLE orders (order_id INT,order_date DATE,region VARCHAR(50)); CREATE TABLE order_details (order_id INT,menu_id INT,quantity_sold INT); CREATE TABLE menu (menu_id INT,menu_name VARCHAR(255),is_vegetarian BOOLEAN,price DECIMAL(5,2)); INSERT INTO orders (order_id,order_date,region) VALUES (1,'2022-01-01','North'),(2,'2022-01-02','West'),(3,'2022-01-03','South'); INSERT INTO order_details (order_id,menu_id,quantity_sold) VALUES (1,1,10),(1,2,5),(2,2,8),(2,3,12),(3,4,20),(3,5,15); INSERT INTO menu (menu_id,menu_name,is_vegetarian,price) VALUES (1,'Quinoa Salad',TRUE,10.50),(2,'Margherita Pizza',FALSE,12.00),(3,'Vegetable Curry',TRUE,11.25),(4,'Beef Burger',FALSE,13.50),(5,'Chia Pudding',TRUE,8.00);
|
SELECT SUM(quantity_sold * price) as revenue FROM order_details od JOIN menu m ON od.menu_id = m.menu_id WHERE is_vegetarian = TRUE AND region = 'West';
|
Show all menu items in the breakfast category
|
CREATE TABLE Menu (id INT PRIMARY KEY,name VARCHAR(255),category VARCHAR(255),price DECIMAL(5,2));
|
SELECT * FROM Menu WHERE category = 'Breakfast';
|
What are the total grant amounts awarded to female and non-binary faculty in the College of Engineering?
|
CREATE TABLE faculty (id INT,name VARCHAR(50),department VARCHAR(50),gender VARCHAR(10)); INSERT INTO faculty VALUES (1,'Alice','Engineering','Female'),(2,'Bob','Engineering','Male'),(3,'Charlie','Engineering','Non-binary'); CREATE TABLE grants (id INT,faculty_id INT,amount INT); INSERT INTO grants VALUES (1,1,5000),(2,1,7000),(3,2,6000),(4,3,4000);
|
SELECT SUM(amount) FROM grants INNER JOIN faculty ON grants.faculty_id = faculty.id WHERE gender IN ('Female', 'Non-binary');
|
Summarize intelligence budgets by fiscal year and country
|
CREATE TABLE FiscalYear (id INT PRIMARY KEY,year INT); CREATE TABLE IntelligenceBudget (id INT PRIMARY KEY,fiscal_year_id INT,country_code VARCHAR(255),amount INT); INSERT INTO FiscalYear (id,year) VALUES (1,2010),(2,2011),(3,2012); INSERT INTO IntelligenceBudget (id,fiscal_year_id,country_code,amount) VALUES (1,1,'USA',50000000),(2,1,'UK',30000000),(3,2,'USA',55000000),(4,2,'UK',32000000),(5,3,'USA',58000000),(6,3,'UK',34000000);
|
SELECT fy.year, i.country_code, SUM(i.amount) FROM FiscalYear fy INNER JOIN IntelligenceBudget i ON fy.id = i.fiscal_year_id GROUP BY fy.year, i.country_code;
|
Find all warehouses located in countries with more than 5 fulfillment centers?
|
CREATE TABLE Warehouse (WarehouseID INT,WarehouseName TEXT,Country TEXT); INSERT INTO Warehouse (WarehouseID,WarehouseName,Country) VALUES (1,'Central Warehouse','USA'),(2,'East Coast Warehouse','USA'),(3,'West Coast Warehouse','USA'),(4,'Toronto Warehouse','Canada'); CREATE TABLE FulfillmentCenter (FCID INT,FCName TEXT,Country TEXT); INSERT INTO FulfillmentCenter (FCID,FCName,Country) VALUES (1,'Chicago FC','USA'),(2,'New York FC','USA'),(3,'Los Angeles FC','USA'),(4,'Toronto FC','Canada');
|
SELECT Country FROM Warehouse GROUP BY Country HAVING COUNT(DISTINCT WarehouseID) <= (SELECT COUNT(DISTINCT FCID) FROM FulfillmentCenter GROUP BY Country HAVING COUNT(DISTINCT FCID) > 5);
|
Which climate mitigation projects were initiated in Central America since 2017?
|
CREATE TABLE mitigation_projects_central_america (project_id INT,year INT,region VARCHAR(255)); INSERT INTO mitigation_projects_central_america VALUES (1,2017,'Central America');
|
SELECT * FROM mitigation_projects_central_america WHERE year >= 2017;
|
What is the total CO2 emission in the Arctic per industry category since 2000?
|
CREATE TABLE arctic_emissions (year INT,industry VARCHAR(50),co2_emission FLOAT); INSERT INTO arctic_emissions (year,industry,co2_emission) VALUES (2000,'Oil',100.0),(2001,'Gas',120.0);
|
SELECT a.industry, SUM(a.co2_emission) as total_emission FROM arctic_emissions a GROUP BY a.industry;
|
What is the minimum number of followers for users who have posted about #veganism in the past week?
|
CREATE TABLE users (id INT,followers INT,posts TEXT);
|
SELECT MIN(followers) FROM users WHERE posts LIKE '%#veganism%' AND posts IS NOT NULL AND posts != '';
|
Who are the volunteers who have not yet completed their required training?
|
CREATE TABLE volunteer_training (id INT,volunteer_id INT,training_completed BOOLEAN);
|
SELECT first_name, last_name FROM volunteers JOIN volunteer_training ON volunteers.id = volunteer_training.volunteer_id WHERE training_completed = FALSE;
|
Insert new staff member 'Alex Garcia' with role 'Counselor'
|
CREATE TABLE Staff (StaffID INT PRIMARY KEY,Name VARCHAR(50),Role VARCHAR(20));
|
INSERT INTO Staff (Name, Role) VALUES ('Alex Garcia', 'Counselor');
|
What is the average community education program attendance rate per state for the last 2 years?
|
CREATE TABLE education_attendance (id INT,state VARCHAR(255),attendance_rate FLOAT,event_date DATE);
|
SELECT state, AVG(attendance_rate) as avg_attendance_rate FROM education_attendance WHERE event_date >= (CURRENT_DATE - INTERVAL '2 years') GROUP BY state;
|
List all job titles held by veterans employed in 2019
|
CREATE TABLE veteran_employment (employee_id INT,veteran_status VARCHAR(50),job_title VARCHAR(50),employment_date DATE);INSERT INTO veteran_employment (employee_id,veteran_status,job_title,employment_date) VALUES (2,'Yes','Data Analyst','2019-05-01');
|
SELECT job_title FROM veteran_employment WHERE veteran_status = 'Yes' AND employment_date BETWEEN '2019-01-01' AND '2019-12-31';
|
What is the obesity rate by gender in Texas in 2019?
|
CREATE TABLE health_survey_3 (id INT,gender TEXT,state TEXT,year INT,obese BOOLEAN); INSERT INTO health_survey_3 (id,gender,state,year,obese) VALUES (1,'Female','Texas',2019,true);
|
SELECT gender, AVG(obese::INT) as obesity_rate FROM health_survey_3 WHERE state = 'Texas' AND year = 2019 GROUP BY gender;
|
What is the average sustainability score for Italian restaurants?
|
CREATE TABLE Restaurants (RestaurantID int,Name varchar(50),Cuisine varchar(50),SustainabilityScore int); INSERT INTO Restaurants (RestaurantID,Name,Cuisine,SustainabilityScore) VALUES (1,'Bella Italia','Italian',88);
|
SELECT AVG(SustainabilityScore) as AvgSustainabilityScore FROM Restaurants WHERE Cuisine = 'Italian';
|
Identify companies founded in India that have received funding from both VCs and angel investors, but exclude companies that have also received funding from crowdfunding platforms.
|
CREATE TABLE Companies (id INT,name TEXT,country TEXT); INSERT INTO Companies (id,name,country) VALUES (1,'India Co','India'); INSERT INTO Companies (id,name,country) VALUES (2,'Incredible India','India'); CREATE TABLE Funding (id INT,company_id INT,investor_type TEXT,amount INT); INSERT INTO Funding (id,company_id,investor_type,amount) VALUES (1,1,'VC',8000000); INSERT INTO Funding (id,company_id,investor_type,amount) VALUES (2,1,'Angel',3000000); INSERT INTO Funding (id,company_id,investor_type,amount) VALUES (3,2,'VC',10000000); INSERT INTO Funding (id,company_id,investor_type,amount) VALUES (4,2,'Crowdfunding',1500000);
|
SELECT Companies.name FROM Companies INNER JOIN Funding funding_vc ON Companies.id = funding_vc.company_id INNER JOIN Funding funding_angel ON Companies.id = funding_angel.company_id WHERE Companies.country = 'India' AND funding_vc.investor_type = 'VC' AND funding_angel.investor_type = 'Angel' AND NOT EXISTS (SELECT 1 FROM Funding funding_crowdfunding WHERE Companies.id = funding_crowdfunding.company_id AND funding_crowdfunding.investor_type = 'Crowdfunding')
|
What is the average depth of ocean floor mapping projects in the Pacific region where the maximum depth is greater than 6000 meters?
|
CREATE TABLE ocean_floor_mapping(id INT,region VARCHAR(20),depth FLOAT); INSERT INTO ocean_floor_mapping(id,region,depth) VALUES (1,'Pacific',5000.5),(2,'Atlantic',4500.3),(3,'Pacific',6200.7),(4,'Indian',4200.0);
|
SELECT AVG(depth) FROM ocean_floor_mapping WHERE region = 'Pacific' HAVING MAX(depth) > 6000;
|
What is the total investment made by each fund in the renewable energy sector?
|
CREATE TABLE investments (id INT,fund_name VARCHAR(255),sector VARCHAR(255),investment_amount FLOAT);
|
SELECT fund_name, SUM(investment_amount) as total_investment FROM investments WHERE sector = 'renewable energy' GROUP BY fund_name;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.