instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
List all the vessels that have a safety record between 5 and 10 years old.
|
CREATE TABLE vessel_safety (id INT,vessel_id INT,record_date DATE);
|
SELECT v.name FROM vessel_safety vs JOIN vessel v ON vs.vessel_id = v.id WHERE vs.record_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 10 YEAR) AND DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR);
|
Find the difference in average rainfall between farms with drip irrigation and flood irrigation systems.
|
CREATE TABLE FarmIrrigation (farm_type VARCHAR(10),irrigation_type VARCHAR(20),rainfall FLOAT); INSERT INTO FarmIrrigation (farm_type,irrigation_type,rainfall) VALUES ('Farm A','Drip Irrigation',45.2),('Farm A','Drip Irrigation',46.1),('Farm A','Flood Irrigation',50.5),('Farm A','Flood Irrigation',51.0),('Farm B','Drip Irrigation',48.7),('Farm B','Drip Irrigation',49.3),('Farm B','Flood Irrigation',54.1),('Farm B','Flood Irrigation',55.0);
|
SELECT farm_type, AVG(CASE WHEN irrigation_type = 'Drip Irrigation' THEN rainfall ELSE NULL END) - AVG(CASE WHEN irrigation_type = 'Flood Irrigation' THEN rainfall ELSE NULL END) as rainfall_diff FROM FarmIrrigation GROUP BY farm_type;
|
Determine the number of infectious disease outbreaks, by type and year.
|
CREATE TABLE outbreaks (id INT,year INT,type VARCHAR,location VARCHAR,cases INT);
|
SELECT o.type, o.year, COUNT(o.id) AS num_outbreaks FROM outbreaks o GROUP BY o.type, o.year;
|
Delete the record for the Downtown area from the InclusiveHousing table.
|
CREATE TABLE InclusiveHousing (area TEXT,num_units INT,wheelchair_accessible BOOLEAN,pets_allowed BOOLEAN); INSERT INTO InclusiveHousing (area,num_units,wheelchair_accessible,pets_allowed) VALUES ('Eastside',10,TRUE,FALSE),('Westside',15,TRUE,TRUE),('Downtown',25,TRUE,TRUE);
|
DELETE FROM InclusiveHousing WHERE area = 'Downtown';
|
What are the names of marine species that have been recorded in the same location as a research expedition?
|
CREATE TABLE marine_species (id INT PRIMARY KEY,name VARCHAR(255),species VARCHAR(255),location VARCHAR(255),conservation_status VARCHAR(255)); INSERT INTO marine_species (id,name,species,location,conservation_status) VALUES (1,'Blue Whale','Balaenoptera musculus','Great Barrier Reef','Endangered'); CREATE TABLE expeditions (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),year INT,type VARCHAR(255)); INSERT INTO expeditions (id,name,location,year,type) VALUES (1,'Great Barrier Reef Expedition','Great Barrier Reef',2022,'Research');
|
SELECT ms.name FROM marine_species ms INNER JOIN expeditions e ON ms.location = e.location WHERE e.type = 'Research';
|
Insert a new record into the covid_cases table with a case number of 8008 from the country of Brazil.
|
CREATE TABLE covid_cases (id INT,country VARCHAR(255),case_number INT);
|
INSERT INTO covid_cases (id, country, case_number) VALUES (8, 'Brazil', 8008);
|
Show the number of observations for each species
|
species_observations
|
SELECT species, COUNT(*) as total_observations FROM species_observations GROUP BY species;
|
What is the average budget allocated per project in the Transportation department?
|
CREATE TABLE Transportation_Dept (Dept_Name VARCHAR(255),Project_Name VARCHAR(255),Budget INT); INSERT INTO Transportation_Dept VALUES ('Transportation','Road Construction',5000000),('Transportation','Bridge Building',8000000),('Transportation','Traffic Signal Installation',2000000);
|
SELECT AVG(Budget) FROM Transportation_Dept WHERE Dept_Name = 'Transportation';
|
What is the average monthly cost of mobile and broadband services offered by the telecom company in the state of Florida?
|
CREATE TABLE mobile_plans (plan_id INT,plan_name VARCHAR(25),state VARCHAR(20),monthly_cost FLOAT); CREATE TABLE broadband_plans (plan_id INT,plan_name VARCHAR(25),state VARCHAR(20),monthly_cost FLOAT); INSERT INTO mobile_plans (plan_id,plan_name,state,monthly_cost) VALUES (1,'Basic','Florida',30),(2,'Premium','Florida',60); INSERT INTO broadband_plans (plan_id,plan_name,state,monthly_cost) VALUES (1,'Basic','Florida',40),(2,'Premium','Florida',80);
|
SELECT AVG(mobile_plans.monthly_cost + broadband_plans.monthly_cost) FROM mobile_plans, broadband_plans WHERE mobile_plans.state = 'Florida' AND broadband_plans.state = 'Florida' AND mobile_plans.plan_id = broadband_plans.plan_id;
|
Calculate the average ticket price for each city.
|
CREATE TABLE tickets (id INT,salesperson_id INT,quantity INT,city VARCHAR(50),price DECIMAL(5,2)); INSERT INTO tickets (id,salesperson_id,quantity,city,price) VALUES (1,1,50,'New York',100.00),(2,1,75,'New York',100.00),(3,2,30,'Los Angeles',75.00),(4,2,40,'Los Angeles',75.00),(5,3,25,'Chicago',50.00);
|
SELECT city, AVG(price) as avg_price FROM tickets GROUP BY city;
|
Find the garment with the highest revenue for each category and year.
|
CREATE TABLE GarmentSales (garment_id INT,category VARCHAR(50),year INT,revenue DECIMAL(10,2)); INSERT INTO GarmentSales (garment_id,category,year,revenue) VALUES (1,'Tops',2020,5000.00),(2,'Bottoms',2020,6000.00),(3,'Tops',2020,4000.00);
|
SELECT garment_id, category, year, MAX(revenue) AS max_revenue FROM GarmentSales GROUP BY category, year;
|
What are the case outcomes for all clients who identify as Native American or Alaska Native?
|
CREATE TABLE clients (client_id INT,first_name VARCHAR(20),last_name VARCHAR(20),ethnicity VARCHAR(20)); INSERT INTO clients (client_id,first_name,last_name,ethnicity) VALUES (1,'John','Doe','Caucasian'); INSERT INTO clients (client_id,first_name,last_name,ethnicity) VALUES (2,'Jane','Smith','Native American'); INSERT INTO clients (client_id,first_name,last_name,ethnicity) VALUES (3,'Maria','Garcia','Hispanic');
|
SELECT case_outcome FROM cases INNER JOIN clients ON cases.client_id = clients.client_id WHERE clients.ethnicity IN ('Native American', 'Alaska Native');
|
What is the total financial contribution by each department for Q3 2023?
|
CREATE TABLE departments (department_id INT,department_name TEXT); CREATE TABLE financials (financial_id INT,department_id INT,financial_date DATE,financial_amount FLOAT); INSERT INTO financials (financial_id,department_id,financial_date,financial_amount) VALUES (1,1,'2023-07-01',6000.00),(2,1,'2023-09-15',4000.00),(3,2,'2023-08-30',9000.00);
|
SELECT department_name, SUM(financial_amount) as total_financial_contribution FROM financials f JOIN departments d ON f.department_id = d.department_id WHERE financial_date BETWEEN '2023-07-01' AND '2023-09-30' GROUP BY department_name;
|
List the number of fish caught and total revenue for each trawler in the South Pacific during 2020.
|
CREATE TABLE trawlers (id INT,name VARCHAR(50)); CREATE TABLE catch (trawler_id INT,date DATE,species VARCHAR(50),quantity INT,price FLOAT); INSERT INTO trawlers VALUES (1,'South Pacific Trawler 1'),(2,'South Pacific Trawler 2'),(3,'South Pacific Trawler 3'); INSERT INTO catch VALUES (1,'2020-01-01','Tuna',1300,5.5),(1,'2020-01-02','Marlin',1100,4.2),(2,'2020-01-01','Swordfish',1600,3.8);
|
SELECT t.name, COUNT(c.trawler_id) as catches, SUM(c.quantity * c.price) as revenue FROM trawlers t INNER JOIN catch c ON t.id = c.trawler_id WHERE YEAR(c.date) = 2020 AND t.name LIKE '%South Pacific%' GROUP BY t.id;
|
What is the difference in total points scored between the home and away games, for each team in the hockey table?
|
CREATE TABLE hockey (team VARCHAR(50),location VARCHAR(5),points INT);
|
SELECT team, SUM(CASE WHEN location = 'home' THEN points ELSE 0 END) - SUM(CASE WHEN location = 'away' THEN points ELSE 0 END) AS points_diff FROM hockey GROUP BY team;
|
What is the minimum donation amount in the year 2020 from donors who have donated more than once?
|
CREATE TABLE donors (donor_id INT PRIMARY KEY,donation_amount DECIMAL(10,2),donation_date DATE,first_donation_date DATE); INSERT INTO donors (donor_id,donation_amount,donation_date,first_donation_date) VALUES (1,250,'2020-01-01','2019-01-01'),(2,750,'2020-01-03','2018-01-01'),(3,900,'2020-02-05','2020-01-01');
|
SELECT MIN(donation_amount) FROM donors WHERE YEAR(donation_date) = 2020 AND donor_id IN (SELECT donor_id FROM donors GROUP BY donor_id HAVING COUNT(*) > 1);
|
Count the number of threat intelligence metrics reported in the Middle East in the last 6 months.
|
CREATE TABLE threat_intelligence (metric_id INT,metric_date DATE,region VARCHAR(255)); INSERT INTO threat_intelligence (metric_id,metric_date,region) VALUES (1,'2021-08-01','Middle East'),(2,'2021-06-15','Europe'),(3,'2021-02-14','Middle East');
|
SELECT COUNT(*) FROM threat_intelligence WHERE region = 'Middle East' AND metric_date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH);
|
What is the total volume of NFT assets in the last 30 days?
|
CREATE TABLE digital_assets (asset_id INT,timestamp TIMESTAMP,asset_name VARCHAR(50),asset_type VARCHAR(50),asset_price DECIMAL(18,8),asset_volume DECIMAL(18,8)); INSERT INTO digital_assets VALUES (2,'2022-02-01 10:00:00','asset2','NFT',200,500000);
|
SELECT asset_type, SUM(asset_volume) OVER (PARTITION BY asset_type ORDER BY timestamp ROWS BETWEEN 30 PRECEDING AND CURRENT ROW) as total_volume_30d FROM digital_assets WHERE asset_type = 'NFT' ORDER BY timestamp
|
What is the total cost of military equipment sales to India?
|
CREATE TABLE military_sales(sale_id INT,equipment_name VARCHAR(50),sale_country VARCHAR(50),sale_price FLOAT); INSERT INTO military_sales VALUES (1,'Tank','India',5000000),(2,'Helicopter','Canada',2000000),(3,'Airplane','Mexico',8000000),(4,'Radar','India',3000000);
|
SELECT SUM(sale_price) FROM military_sales WHERE sale_country = 'India';
|
What is the maximum balance for clients with investment accounts in the Los Angeles 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 (7,'William Garcia','1988-04-05','Los Angeles');INSERT INTO accounts VALUES (107,7,'Investment',30000);
|
SELECT MAX(accounts.balance) FROM clients INNER JOIN accounts ON clients.client_id = accounts.client_id WHERE accounts.account_type = 'Investment' AND clients.branch = 'Los Angeles';
|
What is the average production rate of oil wells in the North Sea and Gulf of Mexico?
|
CREATE TABLE wells (id INT,region VARCHAR(255),well_type VARCHAR(255),production_rate DECIMAL(5,2)); INSERT INTO wells (id,region,well_type,production_rate) VALUES (1,'North Sea','Oil',100.5),(2,'North Sea','Gas',75.2),(3,'Gulf of Mexico','Oil',150.0),(4,'Gulf of Mexico','Gas',120.5);
|
SELECT AVG(production_rate) as avg_oil_production_rate FROM wells WHERE region IN ('North Sea', 'Gulf of Mexico') AND well_type = 'Oil';
|
What is the virtual tour engagement rate by city and month?
|
CREATE TABLE virtual_tours_engagement (tour_id INT,city TEXT,views INT,clicks INT,month INT); INSERT INTO virtual_tours_engagement (tour_id,city,views,clicks,month) VALUES (1,'City A',1000,200,1),(1,'City A',1200,240,2),(1,'City A',1400,280,3),(2,'City B',1500,300,1),(2,'City B',1800,360,2),(2,'City B',2100,420,3);
|
SELECT city, month, (SUM(clicks) * 100.0 / SUM(views)) as engagement_rate FROM virtual_tours_engagement GROUP BY city, month;
|
What is the earliest launch date for a successful Mars rover mission, and which mission was it?
|
CREATE TABLE Rovers (RoverID INT,Name VARCHAR(50),LaunchDate DATE,Destination VARCHAR(50),Success BOOLEAN); INSERT INTO Rovers VALUES (1,'Perseverance','2020-07-30','Mars',true); INSERT INTO Rovers VALUES (2,'Curiosity','2011-11-26','Mars',true); INSERT INTO Rovers VALUES (3,'Beagle 2','2003-06-02','Mars',false);
|
SELECT * FROM Rovers WHERE Destination = 'Mars' AND Success = true AND ROW_NUMBER() OVER (ORDER BY LaunchDate ASC) = 1
|
What is the average CO2 emission of buildings in the 'urban' region?
|
CREATE TABLE buildings (id INT,name TEXT,region TEXT,co2_emission FLOAT); INSERT INTO buildings (id,name,region,co2_emission) VALUES (1,'A','urban',1200.0),(2,'B','rural',800.0);
|
SELECT AVG(co2_emission) FROM buildings WHERE region = 'urban';
|
What is the total weight of plastic waste generated in a year?
|
CREATE TABLE inventory (item_id INT,name TEXT,category TEXT,unit_price FLOAT,unit_quantity INT,unit_weight FLOAT,waste_factor FLOAT); INSERT INTO inventory (item_id,name,category,unit_price,unit_quantity,unit_weight,waste_factor) VALUES (1,'Plastic Spoon','Disposable',0.05,100,0.01,0.02),(2,'Paper Plate','Disposable',0.10,50,0.05,0.10); CREATE TABLE sales (sale_id INT,item_id INT,sale_quantity INT,sale_date DATE); INSERT INTO sales (sale_id,item_id,sale_quantity,sale_date) VALUES (1,1,200,'2022-01-01'),(2,1,300,'2022-04-12'),(3,2,100,'2022-03-15'),(4,1,150,'2022-12-31');
|
SELECT SUM(i.unit_quantity * i.unit_weight * s.sale_quantity * i.waste_factor) as total_waste FROM inventory i JOIN sales s ON i.item_id = s.item_id WHERE i.category = 'Disposable' AND s.sale_date BETWEEN '2022-01-01' AND '2022-12-31';
|
Delete the data for crop B in region Y in June.
|
CREATE TABLE WeatherData (region TEXT,crop TEXT,month INTEGER,temperature REAL); INSERT INTO WeatherData (region,crop,month,temperature) VALUES ('X','A',6,22.5),('X','A',7,25.0),('Y','B',6,18.2);
|
DELETE FROM WeatherData WHERE region = 'Y' AND crop = 'B' AND month = 6;
|
What is the sum of sales for the 'Eye Shadow' category?
|
CREATE TABLE Sales (SaleID int,ProductID int,ProductName varchar(50),Category varchar(50),SalesNumber int); INSERT INTO Sales (SaleID,ProductID,ProductName,Category,SalesNumber) VALUES (1,1,'Eye Shadow A','Eye Shadow',100),(2,2,'Eye Shadow B','Eye Shadow',200),(3,3,'Lipstick C','Lipstick',300);
|
SELECT SUM(SalesNumber) as TotalSales FROM Sales WHERE Category = 'Eye Shadow';
|
What is the total number of contract negotiations with the Russian government by all defense contractors in 2019?
|
CREATE TABLE contract_negotiations (contractor VARCHAR(255),country VARCHAR(255),negotiation_year INT); INSERT INTO contract_negotiations (contractor,country,negotiation_year) VALUES ('Lockheed Martin','Russia',2019),('Raytheon','Russia',2019),('BAE Systems','Russia',2018);
|
SELECT COUNT(*) FROM contract_negotiations WHERE country = 'Russia' AND negotiation_year = 2019;
|
Which artists have never held a solo exhibition at the museum_artists table?
|
CREATE TABLE museum_artists (artist_id INT,artist_name TEXT,num_solo_exhibitions INT);
|
DELETE FROM museum_artists WHERE artist_id IN (SELECT artist_id FROM (SELECT artist_id, MIN(num_solo_exhibitions) AS min_solo FROM museum_artists) WHERE min_solo = 0);
|
What is the average speed of electric vehicles per day for the last 7 days in the 'trips' table?
|
CREATE TABLE trips (id INT,vehicle_type VARCHAR(20),speed FLOAT,date DATE); INSERT INTO trips (id,vehicle_type,speed,date) VALUES (1,'ElectricCar',75.3,'2022-04-01'); INSERT INTO trips (id,vehicle_type,speed,date) VALUES (2,'ElectricBike',28.1,'2022-04-02'); INSERT INTO trips (id,vehicle_type,speed,date) VALUES (3,'ElectricScooter',42.7,'2022-04-03');
|
SELECT DATE(date) as trip_date, AVG(speed) as avg_speed FROM trips WHERE vehicle_type LIKE 'Electric%' AND date BETWEEN DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND CURDATE() GROUP BY trip_date ORDER BY trip_date;
|
How many green buildings are there in the city of New York, by type?
|
CREATE TABLE green_buildings (id INT,building_name VARCHAR(50),city VARCHAR(50),building_type VARCHAR(50)); INSERT INTO green_buildings (id,building_name,city,building_type) VALUES (1,'New York Green Tower','New York','Residential');
|
SELECT building_type, COUNT(*) FROM green_buildings WHERE city = 'New York' GROUP BY building_type;
|
How many matches did each player participate in during the 2020 tennis season?
|
CREATE TABLE tennis (player VARCHAR(255),match_id INT); INSERT INTO tennis (player,match_id) VALUES ('Federer',1),('Federer',2),('Federer',3),('Djokovic',4),('Djokovic',5);
|
SELECT player, COUNT(*) FROM tennis GROUP BY player;
|
How many unique donors supported each cause in Q1 2021?
|
CREATE TABLE donors (id INT,donor_name VARCHAR(255)); INSERT INTO donors (id,donor_name) VALUES (1,'Alice'),(2,'Bob'),(3,'Charlie'); CREATE TABLE causes (id INT,cause_name VARCHAR(255)); INSERT INTO causes (id,cause_name) VALUES (1,'Poverty Reduction'),(2,'Disaster Relief'); CREATE TABLE donations (id INT,donor_id INT,cause_id INT,donation_date DATE); INSERT INTO donations (id,donor_id,cause_id,donation_date) VALUES (1,1,1,'2021-01-01'),(2,2,1,'2021-01-02'),(3,3,2,'2021-01-03');
|
SELECT d.cause_id, COUNT(DISTINCT d.donor_id) as unique_donors FROM donations d WHERE QUARTER(d.donation_date) = 1 AND YEAR(d.donation_date) = 2021 GROUP BY d.cause_id;
|
Which organizations have more male than female volunteers?
|
CREATE TABLE gender (vol_id INT,vol_name VARCHAR(255),gender VARCHAR(10)); INSERT INTO gender (vol_id,vol_name,gender) VALUES (1,'John Doe','Male'),(2,'Jane Smith','Female'),(3,'Mike Johnson','Male'),(4,'Alice Davis','Female'),(5,'Bob Brown','Male'),(6,'Charlie Green','Female');
|
SELECT organization.org_name, COUNT(CASE WHEN gender.gender = 'Male' THEN 1 END) as num_male, COUNT(CASE WHEN gender.gender = 'Female' THEN 1 END) as num_female FROM organization JOIN volunteer ON organization.org_id = volunteer.org_id JOIN gender ON volunteer.vol_id = gender.vol_id GROUP BY organization.org_name HAVING num_male > num_female;
|
How many creators in the media_creators table are from underrepresented communities?
|
CREATE TABLE media_creators (id INT,community VARCHAR(50)); INSERT INTO media_creators (id,community) VALUES (1,'LGBTQ+'),(2,'Female'),(3,'Minority'),(4,'Male'),(5,'Minority');
|
SELECT COUNT(*) FROM media_creators WHERE community = 'LGBTQ+' OR community = 'Female' OR community = 'Minority';
|
What is the percentage change in the number of cases opened and closed in the last 6 months?
|
CREATE TABLE Cases (ID INT,CaseNumber INT,DateOpened DATE,DateClosed DATE); INSERT INTO Cases (ID,CaseNumber,DateOpened,DateClosed) VALUES (1,12345,'2022-01-01','2022-03-15'),(2,67890,'2022-02-15','2022-04-30'),(3,111213,'2022-03-28',NULL);
|
SELECT (SUM(CASE WHEN DateClosed IS NOT NULL THEN 1 ELSE 0 END) - SUM(CASE WHEN DateOpened IS NOT NULL THEN 1 ELSE 0 END)) * 100.0 / COUNT(*) as PercentageChange FROM Cases WHERE DateOpened >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH);
|
What are the names of all dams and their reservoir capacities in 'Oregon' and 'Washington'?
|
CREATE TABLE Dams (name TEXT,state TEXT,reservoir_capacity INTEGER); INSERT INTO Dams (name,state,reservoir_capacity) VALUES ('Bonneville Dam','Oregon',750000); INSERT INTO Dams (name,state,reservoir_capacity) VALUES ('Grand Coulee Dam','Washington',5500000);
|
SELECT name, reservoir_capacity FROM Dams WHERE state IN ('Oregon', 'Washington');
|
Which sustainable building practices were implemented in New York and when were they added to the database?
|
CREATE TABLE sustainable_practices (practice_id INT,practice_name VARCHAR(20),implementation_date DATE);INSERT INTO sustainable_practices (practice_id,practice_name,implementation_date) VALUES (1,'Solar Panels','2020-01-01');INSERT INTO sustainable_practices (practice_id,practice_name,implementation_date) VALUES (2,'Green Roofs','2019-06-15');
|
SELECT practice_name, implementation_date FROM sustainable_practices WHERE practice_name IN ('Solar Panels', 'Green Roofs') AND location = 'New York';
|
What is the average food safety inspection score for restaurants in each city, grouped by city and year?'
|
CREATE TABLE Restaurants (RestaurantID int,RestaurantName varchar(255),City varchar(255)); CREATE TABLE Inspections (InspectionID int,RestaurantID int,ViolationCount int,InspectionScore int,InspectionDate date);
|
SELECT R.City, YEAR(I.InspectionDate) as Year, AVG(I.InspectionScore) as AverageInspectionScore FROM Restaurants R INNER JOIN Inspections I ON R.RestaurantID = I.RestaurantID GROUP BY R.City, YEAR(I.InspectionDate);
|
What is the maximum biomass of a tree in the Trees table, if each tree has a biomass of 0.022 pounds per year per inch of age?
|
CREATE TABLE Trees (id INT,species VARCHAR(255),age INT); INSERT INTO Trees (id,species,age) VALUES (1,'Oak',50),(2,'Pine',30),(3,'Maple',40);
|
SELECT MAX(age * 0.022) FROM Trees;
|
Compare the average revenue of restaurants in cities with a population greater than 5 million to the average revenue of restaurants in cities with a population less than 1 million.
|
CREATE TABLE Restaurants (restaurant_id INT,name TEXT,city TEXT,population INT,revenue FLOAT); INSERT INTO Restaurants (restaurant_id,name,city,population,revenue) VALUES (1,'Asian Fusion','New York',8500000,50000.00),(2,'Bella Italia','Los Angeles',4000000,60000.00),(3,'Sushi House','New York',8500000,70000.00),(4,'Pizzeria La Rosa','Chicago',2700000,80000.00),(5,'Taqueria El Sol','Los Angeles',4000000,40000.00),(6,'Fish and Chips','London',8700000,30000.00),(7,'Brasserie Moderne','Paris',2200000,45000.00);
|
SELECT 'Greater than 5 million' as city, AVG(revenue) as avg_revenue FROM Restaurants WHERE population > 5000000 UNION ALL SELECT 'Less than 1 million', AVG(revenue) FROM Restaurants WHERE population < 1000000;
|
List the names and component types of suppliers that have been updated in the last month and supply components for circular economy initiatives.
|
CREATE TABLE suppliers (name TEXT,last_update DATE,component_type TEXT,circular_economy BOOLEAN); INSERT INTO suppliers (name,last_update,component_type,circular_economy) VALUES ('Mu Supplies','2022-03-10','Recycled Materials',TRUE),('Nu Components','2022-02-05','Renewable Energy',FALSE);
|
SELECT name, component_type FROM suppliers WHERE last_update >= DATE('now', '-1 month') AND circular_economy = TRUE;
|
Calculate the number of agricultural innovation projects completed in Vietnam between 2018 and 2020.
|
CREATE TABLE agri_innovation (id INT,country VARCHAR(50),project VARCHAR(50),completion_year INT); INSERT INTO agri_innovation (id,country,project,completion_year) VALUES (1,'Vietnam','GMO Crops',2018),(2,'Vietnam','Drip Irrigation',2020),(3,'Vietnam','Solar-Powered Pumps',2019);
|
SELECT COUNT(*) FROM agri_innovation WHERE country = 'Vietnam' AND completion_year BETWEEN 2018 AND 2020;
|
What is the total funding received by startups founded by individuals from each continent?
|
CREATE TABLE startups(id INT,name TEXT,founder_continent TEXT,funding FLOAT); INSERT INTO startups(id,name,founder_continent,funding) VALUES (1,'StartupA','North America',500000),(2,'StartupB','North America',750000),(3,'StartupC','North America',250000),(4,'StartupD','South America',300000),(5,'StartupE','South America',150000);
|
SELECT founder_continent, SUM(funding) FROM startups GROUP BY founder_continent;
|
Count the number of users who have never participated in a workout during the weekends.
|
CREATE TABLE WeekdayWorkouts (WorkoutID INT,MemberID INT,WorkoutDate DATE); INSERT INTO WeekdayWorkouts (WorkoutID,MemberID,WorkoutDate) VALUES (1,1,'2021-01-05'),(2,1,'2021-01-06'),(3,2,'2021-03-18'),(4,3,'2021-08-14');
|
SELECT COUNT(DISTINCT Members.MemberID) FROM Members LEFT JOIN WeekdayWorkouts ON Members.MemberID = WeekdayWorkouts.MemberID WHERE WeekdayWorkouts.WorkoutDate IS NULL OR DATEPART(dw, WeekdayWorkouts.WorkoutDate) NOT IN (1, 7);
|
What was the highest military spending in 2020 by a Southeast Asian country?
|
CREATE TABLE se_asian_spending (country VARCHAR(50),year INT,spending FLOAT); INSERT INTO se_asian_spending (country,year,spending) VALUES ('Indonesia',2020,8700000000),('Thailand',2020,6600000000),('Malaysia',2020,5200000000),('Singapore',2020,11000000000),('Vietnam',2020,5700000000),('Philippines',2020,3700000000);
|
SELECT MAX(spending) FROM se_asian_spending WHERE year = 2020;
|
How many economic diversification projects were initiated in Mexico in 2016 or 2017?
|
CREATE TABLE Economic_Diversification (id INT,country VARCHAR(50),year INT,initiative VARCHAR(50)); INSERT INTO Economic_Diversification (id,country,year,initiative) VALUES (1,'Mexico',2016,'Initiated'),(2,'Mexico',2017,'Planned'),(3,'Brazil',2018,'Initiated');
|
SELECT COUNT(*) FROM Economic_Diversification WHERE country = 'Mexico' AND (year = 2016 OR year = 2017);
|
What is the total amount donated by the top 3 donor organizations based in the US?
|
CREATE TABLE Donors (DonorID INT,DonorName TEXT,DonorType TEXT,Country TEXT,TotalDonations INT); INSERT INTO Donors (DonorID,DonorName,DonorType,Country,TotalDonations) VALUES (1,'Bill & Melinda Gates Foundation','Organization','United States',5000000),(2,'Open Society Foundations','Organization','United States',4000000),(3,'Ford Foundation','Organization','United States',3000000),(4,'The William and Flora Hewlett Foundation','Organization','United States',2000000);
|
SELECT SUM(TotalDonations) FROM Donors WHERE DonorType = 'Organization' AND Country = 'United States' AND DonorID IN (SELECT DonorID FROM (SELECT DonorID, ROW_NUMBER() OVER (ORDER BY TotalDonations DESC) rn FROM Donors WHERE DonorType = 'Organization' AND Country = 'United States') t WHERE rn <= 3);
|
Count the number of users who have never checked in
|
CREATE TABLE user_check_ins (user_id INT,check_in_id INT);
|
SELECT COUNT(DISTINCT user_id) as num_users FROM user_check_ins WHERE user_id NOT IN (SELECT DISTINCT user_id FROM check_ins);
|
What is the average fairness score of models trained on different geographical regions?
|
CREATE TABLE regions (region_id INT,region_name VARCHAR(50)); INSERT INTO regions (region_id,region_name) VALUES (1,'North America'),(2,'Europe'),(3,'Asia'),(4,'Africa'),(5,'South America'); CREATE TABLE model_fairness (model_id INT,region_id INT,fairness_score FLOAT);
|
SELECT AVG(mf.fairness_score) FROM model_fairness mf JOIN regions r ON mf.region_id = r.region_id;
|
What are the average threat intelligence metrics for each region in 2020?
|
CREATE TABLE threat_intelligence (region VARCHAR(255),date DATE,metric1 FLOAT,metric2 FLOAT,metric3 FLOAT); INSERT INTO threat_intelligence (region,date,metric1,metric2,metric3) VALUES ('Northeast','2020-01-01',12.3,45.6,78.9),('Midwest','2020-01-01',23.4,56.7,89.0),('South','2020-01-01',34.5,67.8,90.1),('West','2020-01-01',45.6,78.9,12.3);
|
SELECT region, AVG(metric1) as avg_metric1, AVG(metric2) as avg_metric2, AVG(metric3) as avg_metric3 FROM threat_intelligence WHERE date BETWEEN '2020-01-01' AND '2020-12-31' GROUP BY region;
|
What is the total volume of wastewater treated by the water treatment facility in Sacramento in 2018?
|
CREATE TABLE WastewaterTreatment (id INT,facility VARCHAR,year INT,volume INT); INSERT INTO WastewaterTreatment (id,facility,year,volume) VALUES (1,'Sacramento',2018,12000000),(2,'Sacramento',2019,12500000),(3,'San Diego',2018,14000000);
|
SELECT SUM(volume) FROM WastewaterTreatment WHERE facility = 'Sacramento' AND year = 2018;
|
Delete the records of doctors who are not assigned to any hospital from the doctors table.
|
CREATE TABLE hospitals (hospital_id INT,hospital_name VARCHAR(255)); CREATE TABLE doctors (doctor_id INT,doctor_name VARCHAR(255),hospital_id INT); INSERT INTO hospitals (hospital_id,hospital_name) VALUES (1,'Hospital A'),(2,'Hospital B'); INSERT INTO doctors (doctor_id,doctor_name,hospital_id) VALUES (1,'Dr. Smith',1),(2,'Dr. Johnson',NULL),(3,'Dr. Williams',2);
|
DELETE FROM doctors WHERE hospital_id IS NULL;
|
What are the names of warehouses with no pending freights?
|
CREATE TABLE Warehouses (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255)); CREATE TABLE Freights (id INT PRIMARY KEY,warehouse_id INT,status VARCHAR(255),quantity INT,pickup_date DATETIME); CREATE VIEW PendingFreights AS SELECT * FROM Freights WHERE status = 'pending';
|
SELECT w.name FROM Warehouses w LEFT JOIN PendingFreights p ON w.id = p.warehouse_id WHERE p.id IS NULL;
|
How many biosensor technology patents were granted in each year in the 'Patents' table?
|
CREATE SCHEMA Biosensors; CREATE TABLE Patents (patent_name VARCHAR(50),grant_year INT); INSERT INTO Patents VALUES ('Patent1',2018),('Patent2',2019);
|
SELECT grant_year, COUNT(*) as num_patents FROM Biosensors.Patents GROUP BY grant_year;
|
What was the total number of visitors to each continent in 2021?
|
CREATE TABLE if not exists VisitorContinents (Continent VARCHAR(50),Country VARCHAR(50),Visitors INT); INSERT INTO VisitorContinents (Continent,Country,Visitors) VALUES ('Africa','Egypt',120000),('Asia','Japan',240000),('Europe','France',300000),('South America','Brazil',140000),('North America','Canada',170000),('Oceania','Australia',270000);
|
SELECT a.Continent, SUM(a.Visitors) AS TotalVisitors FROM VisitorContinents a WHERE a.Year = 2021 GROUP BY a.Continent;
|
What is the infection rate of Malaria and Dengue Fever in tropical and temperate regions over the past 5 years?
|
CREATE TABLE Infection_Rates (ID INT,Year INT,Disease TEXT,Region TEXT,Rate FLOAT); INSERT INTO Infection_Rates (ID,Year,Disease,Region,Rate) VALUES (1,2017,'Malaria','Tropical',0.15); INSERT INTO Infection_Rates (ID,Year,Disease,Region,Rate) VALUES (2,2018,'Dengue Fever','Temperate',0.07);
|
SELECT Region, Disease, AVG(Rate) FROM Infection_Rates WHERE Year BETWEEN 2017 AND 2021 GROUP BY Region, Disease;
|
How many complaints were filed in the last 6 months for a specific brand?
|
CREATE TABLE product_complaints (complaint_id INT,brand_name VARCHAR(255),complaint_date DATE); CREATE TABLE brand_catalog (brand_id INT,brand_name VARCHAR(255));
|
SELECT COUNT(*) FROM product_complaints JOIN brand_catalog ON product_complaints.brand_id = brand_catalog.brand_id WHERE brand_name = 'Example Brand' AND complaint_date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH);
|
Find the number of articles published by 'Acme News Agency' in 'Germany' and 'France'?
|
CREATE TABLE news_agencies (id INT,name TEXT); INSERT INTO news_agencies VALUES (1,'Acme News Agency'); INSERT INTO news_agencies VALUES (2,'Global News'); CREATE TABLE articles (id INT,agency_id INT,title TEXT,location TEXT); INSERT INTO articles VALUES (1,1,'Article 1','Germany'); INSERT INTO articles VALUES (2,1,'Article 2','France'); INSERT INTO articles VALUES (3,2,'Article 3','USA');
|
SELECT COUNT(articles.id) FROM articles INNER JOIN news_agencies ON articles.agency_id = news_agencies.id WHERE news_agencies.name = 'Acme News Agency' AND articles.location IN ('Germany', 'France');
|
What is the total CO2 emission in the Arctic by industry since 2000?
|
CREATE TABLE co2_emission (country VARCHAR(50),year INT,industry VARCHAR(50),co2_emission FLOAT); INSERT INTO co2_emission (country,year,industry,co2_emission) VALUES ('Canada',2000,'Oil',100.0),('Canada',2001,'Oil',120.0),('Norway',2000,'Gas',80.0);
|
SELECT c.country, c.industry, SUM(c.co2_emission) as total_emission FROM co2_emission c GROUP BY c.country, c.industry;
|
What is the maximum number of crimes committed in a single day in each location type?
|
CREATE TABLE Locations (LocId INT,Type VARCHAR(50)); CREATE TABLE Crimes (CrimeId INT,LocId INT,Date DATE,Time TIME);
|
SELECT L.Type, MAX(C.Count) FROM Locations L INNER JOIN (SELECT LocId, COUNT(*) AS Count FROM Crimes GROUP BY LocId, Date, Time) C ON L.LocId = C.LocId GROUP BY L.Type;
|
What is the total biomass of farmed fish in each country's aquatic farms?
|
CREATE TABLE aquatic_farms (id INT,country VARCHAR(50),biomass FLOAT); INSERT INTO aquatic_farms (id,country,biomass) VALUES (1,'Norway',350000),(2,'Chile',280000),(3,'China',740000);
|
SELECT country, SUM(biomass) as total_biomass FROM aquatic_farms GROUP BY country;
|
What was the total donation amount in Q1 2021?
|
CREATE TABLE donations (id INT,donation_date DATE,amount DECIMAL(10,2)); INSERT INTO donations (id,donation_date,amount) VALUES (1,'2021-01-01',100.00),(2,'2021-01-15',250.50),(3,'2021-03-01',150.25);
|
SELECT SUM(amount) FROM donations WHERE donation_date BETWEEN '2021-01-01' AND '2021-03-31';
|
Which sites have exceeded their annual emission limits?
|
CREATE TABLE sites (id INT,name VARCHAR(255),annual_emission_limit INT); INSERT INTO sites (id,name,annual_emission_limit) VALUES (1,'Site A',1000),(2,'Site B',1200),(3,'Site C',1500); INSERT INTO sites (id,name,annual_emission_limit,yearly_emissions) VALUES (1,'Site A',1000,1100),(2,'Site B',1200,1150),(3,'Site C',1500,1400);
|
SELECT name FROM (SELECT name, yearly_emissions, annual_emission_limit, ROW_NUMBER() OVER (PARTITION BY name ORDER BY yearly_emissions DESC) as row_num FROM sites) subquery WHERE row_num = 1 AND yearly_emissions > annual_emission_limit;
|
What is the minimum algorithmic fairness score for algorithms created in H1 2020, per category?
|
CREATE TABLE AlgorithmicFairness (ID INT,Algorithm VARCHAR(255),Category VARCHAR(255),Score FLOAT,Date DATE); INSERT INTO AlgorithmicFairness (ID,Algorithm,Category,Score,Date) VALUES (1,'Algo1','CategoryA',0.85,'2020-01-01'),(2,'Algo2','CategoryB',0.78,'2020-01-05'),(3,'Algo3','CategoryA',0.91,'2020-02-12'),(4,'Algo4','CategoryB',0.89,'2020-02-15'),(5,'Algo5','CategoryA',0.75,'2020-03-01');
|
SELECT Category, MIN(Score) as Min_Score FROM AlgorithmicFairness WHERE Date BETWEEN '2020-01-01' AND '2020-06-30' GROUP BY Category;
|
What is the change in the number of HIV cases between consecutive years, for each city?
|
CREATE TABLE hiv_data (id INT,city TEXT,year INT,cases INT); INSERT INTO hiv_data (id,city,year,cases) VALUES (1,'Los Angeles',2018,500),(2,'Los Angeles',2019,600);
|
SELECT city, year, cases, LAG(cases) OVER (PARTITION BY city ORDER BY year) as prev_year_cases, cases - LAG(cases) OVER (PARTITION BY city ORDER BY year) as change FROM hiv_data;
|
What is the total budget for all spacecraft manufactured by 'AeroSpace Inc.' and 'SpaceX'?
|
CREATE TABLE Spacecraft (id INT,name VARCHAR(255),manufacturer VARCHAR(255),budget DECIMAL(10,2)); INSERT INTO Spacecraft (id,name,manufacturer,budget) VALUES (1,'Voyager I','AeroSpace Inc.',800000000.00),(2,'Voyager II','AeroSpace Inc.',850000000.00),(3,'Dragon C106','SpaceX',150000000.00);
|
SELECT SUM(budget) FROM Spacecraft WHERE manufacturer IN ('AeroSpace Inc.', 'SpaceX');
|
Identify the total number of tickets sold for games held in New York or Los Angeles.
|
CREATE TABLE ticket_sales(ticket_id INT,game_id INT,location VARCHAR(50),tickets_sold INT);
|
SELECT SUM(tickets_sold) FROM ticket_sales WHERE location IN ('New York', 'Los Angeles');
|
What is the average speed of spaceships that landed on Mars?
|
CREATE TABLE spaceships (id INT,name VARCHAR(50),max_speed FLOAT,launch_date DATE); INSERT INTO spaceships (id,name,max_speed,launch_date) VALUES (1,'Viking 1',21000,'1975-08-20'); INSERT INTO spaceships (id,name,max_speed,launch_date) VALUES (2,'Curiosity Rover',13000,'2011-11-26');
|
SELECT AVG(max_speed) FROM spaceships WHERE name IN ('Viking 1', 'Curiosity Rover') AND launch_date LIKE '19__-__-__' OR launch_date LIKE '20__-__-__';
|
How can I update the CO2 emissions for a specific project?
|
CREATE TABLE emissions (id INT,project_id INT,year INT,CO2_emissions_tonnes INT); INSERT INTO emissions (id,project_id,year,CO2_emissions_tonnes) VALUES (1,1,2018,1000);
|
UPDATE emissions SET CO2_emissions_tonnes = 1200 WHERE project_id = 1 AND year = 2018;
|
How many rural infrastructure projects were completed in 2021, categorized by project type?
|
CREATE TABLE years (year_id INT,year INT); CREATE TABLE projects (project_id INT,project_type VARCHAR(255),year_id INT);
|
SELECT p.project_type, COUNT(p.project_id) as project_count FROM projects p JOIN years y ON p.year_id = y.year_id WHERE y.year = 2021 GROUP BY p.project_type;
|
Find the average salary of employees in the 'HumanResources' department who have a salary higher than the overall average salary.
|
CREATE TABLE Employees (EmployeeID INT,Department VARCHAR(255),Salary FLOAT);
|
SELECT AVG(Salary) FROM Employees WHERE Department = 'HumanResources' AND Salary > (SELECT AVG(Salary) FROM Employees);
|
What is the maximum price of organic makeup products sold in Australia?
|
CREATE TABLE MakeupProducts (product_id INT,product_name VARCHAR(255),price DECIMAL(5,2),is_organic BOOLEAN,country VARCHAR(50));
|
SELECT MAX(price) FROM MakeupProducts WHERE is_organic = TRUE AND country = 'Australia';
|
What is the average speed of vessels that departed from the port of Oakland in January 2020?
|
CREATE TABLE vessels (id INT,name TEXT,speed FLOAT,departed_port TEXT,departed_date DATE); INSERT INTO vessels (id,name,speed,departed_port,departed_date) VALUES (1,'VesselA',15.2,'Oakland','2020-01-01'); INSERT INTO vessels (id,name,speed,departed_port,departed_date) VALUES (2,'VesselB',17.8,'Oakland','2020-01-15');
|
SELECT AVG(speed) FROM vessels WHERE departed_port = 'Oakland' AND departed_date >= '2020-01-01' AND departed_date < '2020-02-01';
|
Find the total carbon offset of all carbon offset initiatives in the database.
|
CREATE TABLE carbon_offset_initiatives (id INT,name VARCHAR(255),description TEXT,total_carbon_offset FLOAT);
|
SELECT SUM(total_carbon_offset) FROM carbon_offset_initiatives;
|
List all drugs that were approved in 2019 and have sales revenue greater than $150,000 in Q4 2020?
|
CREATE TABLE drug_approval_2019 (drug VARCHAR(50),year INT,status VARCHAR(50)); INSERT INTO drug_approval_2019 (drug,year,status) VALUES ('DrugA',2019,'Approved'),('DrugD',2019,'Approved'),('DrugE',2019,'Approved'); CREATE TABLE drug_sales_q4_2020 (drug VARCHAR(50),quarter VARCHAR(5),year INT,revenue INT); INSERT INTO drug_sales_q4_2020 (drug,quarter,year,revenue) VALUES ('DrugA','Q4',2020,200000),('DrugD','Q4',2020,150000),('DrugF','Q4',2020,180000);
|
SELECT drug_sales_q4_2020.drug FROM drug_sales_q4_2020 INNER JOIN drug_approval_2019 ON drug_sales_q4_2020.drug = drug_approval_2019.drug WHERE drug_sales_q4_2020.quarter = 'Q4' AND drug_sales_q4_2020.year = 2020 AND drug_sales_q4_2020.revenue > 150000 AND drug_approval_2019.year = 2019 AND drug_approval_2019.status = 'Approved';
|
Which decentralized applications have been banned in China?
|
CREATE TABLE if not exists dapps (dapp_id INT,dapp_name VARCHAR(255),country VARCHAR(255)); INSERT INTO dapps (dapp_id,dapp_name,country) VALUES (1,'Uniswap','USA'),(2,'Aave','UK'),(3,'Compound','USA'),(4,'Balancer','Switzerland'),(5,'Yearn Finance','USA'),(6,'Tether','Hong Kong'),(7,'Binance DEX','Malta'),(8,'Bitforex','China'),(9,'IDEX','USA'),(10,'Kyber Network','Singapore');
|
SELECT dapp_name FROM dapps WHERE country = 'China';
|
What is the maximum funding received by any Indigenous artist grant program?
|
CREATE TABLE ArtistGrants (grantID INT,grantAmount DECIMAL(10,2),grantType VARCHAR(50)); INSERT INTO ArtistGrants (grantID,grantAmount,grantType) VALUES (1,12000.00,'Indigenous Artist Grant'),(2,8000.00,'Emerging Artist Grant'),(3,15000.00,'Established Artist Grant');
|
SELECT MAX(grantAmount) FROM ArtistGrants WHERE grantType = 'Indigenous Artist Grant';
|
How many algorithmic fairness entries have a value greater than 0.8 for each AI category in the 'ai_fairness' table?
|
CREATE TABLE ai_fairness (ai_category TEXT,fairness_metric TEXT,value FLOAT);
|
SELECT ai_category, COUNT(*) FROM ai_fairness WHERE value > 0.8 GROUP BY ai_category;
|
What is the drought impact on industrial water usage in California in terms of water usage reduction?
|
CREATE TABLE drought_impact_ca (sector VARCHAR(20),reduction FLOAT); INSERT INTO drought_impact_ca (sector,reduction) VALUES ('Industrial',0.1),('Agriculture',0.2),('Domestic',0.15);
|
SELECT reduction FROM drought_impact_ca WHERE sector = 'Industrial';
|
Delete all records in the virtual_tours table where the tour_type is 'city_tour'
|
CREATE TABLE virtual_tours (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),tour_type VARCHAR(255)); INSERT INTO virtual_tours (id,name,location,tour_type) VALUES (1,'Paris Virtual Tour','Paris','museum_tour'); INSERT INTO virtual_tours (id,name,location,tour_type) VALUES (2,'Rome Virtual Tour','Rome','city_tour');
|
DELETE FROM virtual_tours WHERE tour_type = 'city_tour';
|
Find the top 2 countries with the highest financial capability.
|
CREATE TABLE financial_capability_2 (id INT,country VARCHAR(20),capability DECIMAL(3,2)); INSERT INTO financial_capability_2 (id,country,capability) VALUES (1,'Switzerland',0.87),(2,'Denmark',0.86),(3,'Netherlands',0.85);
|
SELECT country, capability FROM (SELECT country, capability, ROW_NUMBER() OVER (ORDER BY capability DESC) rn FROM financial_capability_2) t WHERE rn <= 2;
|
What was the total value of military equipment sales to Canada in Q1 2020?
|
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,'Canada',12000,'2020-01-05'); INSERT INTO military_sales (id,region,sale_value,sale_date) VALUES (2,'Canada',15000,'2020-03-30');
|
SELECT SUM(sale_value) FROM military_sales WHERE region = 'Canada' AND sale_date BETWEEN '2020-01-01' AND '2020-03-31';
|
Show the names of unions with collective bargaining agreements in the 'southwest' region that have more than 100 members.
|
CREATE TABLE unions (id INT,name TEXT,region TEXT,collective_bargaining BOOLEAN,member_count INT);
|
SELECT name FROM unions WHERE region = 'southwest' AND collective_bargaining = true AND member_count > 100;
|
How many clinical trials were conducted for each drug in 2020?
|
CREATE TABLE clinical_trials (drug varchar(255),year int,trials int); INSERT INTO clinical_trials (drug,year,trials) VALUES ('DrugA',2020,1),('DrugB',2020,3);
|
SELECT drug, SUM(trials) FROM clinical_trials WHERE year = 2020 GROUP BY drug;
|
What is the most common type of crime in New York City?
|
CREATE TABLE crimes (id INT,city VARCHAR(255),type VARCHAR(255),number_of_crimes INT); INSERT INTO crimes (id,city,type,number_of_crimes) VALUES (1,'New_York_City','Theft',50000),(2,'New_York_City','Assault',30000);
|
SELECT type, COUNT(*) AS count FROM crimes WHERE city = 'New_York_City' GROUP BY type ORDER BY count DESC LIMIT 1;
|
List the urban farming practices utilizing the least amount of water.
|
CREATE TABLE water_usage (practice VARCHAR(20),water_usage INT); INSERT INTO water_usage (practice,water_usage) VALUES ('Hydroponics',500),('Aquaponics',400),('Vertical Farming',600),('Rooftop Farming',300),('Urban Ranching',700),('Community Gardens',200);
|
SELECT practice FROM water_usage WHERE water_usage IN (SELECT MIN(water_usage) FROM water_usage);
|
How many TV shows were produced in India in the last 5 years?
|
CREATE TABLE Indian_TV (title TEXT,year INTEGER); INSERT INTO Indian_TV (title,year) VALUES ('TVShow1',2016),('TVShow2',2017),('TVShow3',2018),('TVShow4',2019),('TVShow5',2020),('TVShow6',2021);
|
SELECT COUNT(*) FROM Indian_TV WHERE year BETWEEN 2016 AND 2021;
|
Which digital divide initiatives were completed in 2020?
|
CREATE TABLE Digital_Divide (project_id INT,project_name VARCHAR(100),completion_year INT); INSERT INTO Digital_Divide (project_id,project_name,completion_year) VALUES (1,'Project X',2019),(2,'Project Y',2020),(3,'Project Z',2018);
|
SELECT project_name FROM Digital_Divide WHERE completion_year = 2020;
|
What are the names of the flood control projects in the 'Resilience_Measures' table?
|
CREATE TABLE Resilience_Measures (project_id INT,project_name VARCHAR(50),location VARCHAR(50)); INSERT INTO Resilience_Measures (project_id,project_name,location) VALUES (1,'Levee Construction','Mississippi'); INSERT INTO Resilience_Measures (project_id,project_name,location) VALUES (2,'Coastal Restoration','Florida');
|
SELECT project_name FROM Resilience_Measures WHERE project_name LIKE '%Flood%';
|
What is the average speed of vessels that docked in the Port of Los Angeles in the last month?
|
CREATE TABLE vessels (id INT,name TEXT,speed FLOAT,dock_date DATE);
|
SELECT AVG(speed) FROM vessels WHERE dock_date >= DATEADD(month, -1, GETDATE()) AND dock_port = 'Los Angeles';
|
Compute the moving average water consumption for the past 3 months in Miami.
|
CREATE TABLE water_consumption (city VARCHAR(50),consumption FLOAT,month INT,year INT); INSERT INTO water_consumption (city,consumption,month,year) VALUES ('Miami',12.3,1,2021),('Miami',13.1,2,2021),('Miami',11.9,3,2021);
|
SELECT city, AVG(consumption) OVER (PARTITION BY city ORDER BY year, month ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) FROM water_consumption;
|
What is the average prize pool for esports events in Asia?
|
CREATE TABLE PrizePools (EventID INT,Region VARCHAR(50),PrizePool INT); INSERT INTO PrizePools (EventID,Region,PrizePool) VALUES (1,'North America',100000),(2,'Europe',150000),(4,'Asia',250000);
|
SELECT AVG(PrizePool) FROM PrizePools WHERE Region = 'Asia';
|
Identify the top three deepest marine trenches using window functions.
|
CREATE TABLE marine_trenches (name VARCHAR(255),location VARCHAR(255),depth FLOAT); INSERT INTO marine_trenches (name,location,depth) VALUES ('Mariana Trench','USA',10994.0),('Tonga Trench','Tonga',10882.0),('Kermadec Trench','New Zealand',10047.0);
|
SELECT name, location, depth, ROW_NUMBER() OVER (ORDER BY depth DESC) as rn FROM marine_trenches WHERE rn <= 3;
|
Add a new record to the 'Parks' table
|
CREATE TABLE Parks(park_id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),area FLOAT,created_date DATE);
|
INSERT INTO Parks (park_id, name, location, area, created_date) VALUES (4, 'Stanley Park', 'Vancouver', 1001.00, '2000-01-04');
|
What is the minimum population of any city in the cities table?
|
CREATE TABLE cities (id INT,name TEXT,population INT);INSERT INTO cities (id,name,population) VALUES (1,'CityA',150000),(2,'CityB',80000),(3,'CityC',120000),(4,'CityD',200000);
|
SELECT MIN(population) FROM cities;
|
Delete the program 'Education Support' from the programs table
|
CREATE TABLE programs (id INT,program VARCHAR,community VARCHAR); INSERT INTO programs (id,program,community) VALUES (1,'Youth Mentoring','Underrepresented'),(2,'Women Empowerment','Underrepresented'),(3,'Community Service','Underrepresented'),(4,'Education Support','Underrepresented');
|
DELETE FROM programs WHERE program = 'Education Support';
|
Insert a new record into the 'public_art' table for a new public art sculpture.
|
CREATE TABLE public_art (type VARCHAR(255),location VARCHAR(255),date DATE);
|
INSERT INTO public_art (type, location, date) VALUES ('Sculpture', 'City Park', '2023-02-14');
|
What are the names of the vessels that have spotted more than 200 marine species?
|
CREATE TABLE ResearchVessels (VesselID INT,Name VARCHAR(50),SpeciesSpotted INT); INSERT INTO ResearchVessels (VesselID,Name,SpeciesSpotted) VALUES (1,'RV1',100),(2,'RV2',150),(3,'RV3',250),(4,'RV4',50);
|
SELECT Name FROM ResearchVessels WHERE SpeciesSpotted > 200;
|
What is the number of different species observed in 2022?
|
CREATE TABLE species (id INT PRIMARY KEY,name VARCHAR(255)); INSERT INTO species (id,name) VALUES (1,'polar_bear'),(2,'arctic_fox'); CREATE TABLE observations (id INT PRIMARY KEY,species_id INT,observation_date DATE,FOREIGN KEY (species_id) REFERENCES species(id)); INSERT INTO observations (id,species_id,observation_date) VALUES (1,1,'2022-01-01'),(2,2,'2022-01-02'),(3,1,'2022-02-03');
|
SELECT COUNT(DISTINCT species_id) FROM observations WHERE observation_date BETWEEN '2022-01-01' AND '2022-12-31';
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.