instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
What is the total revenue generated by OTAs in 'London' in 2022?
|
CREATE TABLE ota_revenue (ota_id INT,city TEXT,revenue FLOAT,year INT); INSERT INTO ota_revenue (ota_id,city,revenue,year) VALUES (1,'London',5000,2022),(2,'London',7000,2022),(3,'Paris',6000,2022);
|
SELECT SUM(revenue) FROM ota_revenue WHERE city = 'London' AND year = 2022;
|
Which volunteers are not assigned to any project in Asia?
|
CREATE TABLE if not exists countries (id INT PRIMARY KEY,name VARCHAR(50),continent VARCHAR(50)); INSERT INTO countries (id,name,continent) VALUES (1,'Afghanistan','Asia'); INSERT INTO countries (id,name,continent) VALUES (2,'Algeria','Africa'); CREATE TABLE if not exists projects (id INT PRIMARY KEY,name VARCHAR(50),country_id INT); INSERT INTO projects (id,name,country_id) VALUES (1,'Disaster Response',2); INSERT INTO projects (id,name,country_id) VALUES (2,'Community Development',2); CREATE TABLE if not exists volunteers (id INT PRIMARY KEY,name VARCHAR(50),project_id INT); INSERT INTO volunteers (id,name,project_id) VALUES (1,'John Doe',1); INSERT INTO volunteers (id,name,project_id) VALUES (2,'Jane Smith',NULL); INSERT INTO volunteers (id,name,project_id) VALUES (3,'Jim Brown',2);
|
SELECT v.name FROM volunteers v LEFT JOIN projects p ON v.project_id = p.id WHERE p.id IS NULL AND c.continent = 'Asia';
|
Update the email addresses of all graduate students in the Physics department with the domain 'physics.ac.uk'.
|
CREATE TABLE graduate_students (id INT,name VARCHAR(50),department VARCHAR(50),email VARCHAR(50)); INSERT INTO graduate_students VALUES (1,'Charlie','Physics','[email protected]'),(2,'David','Physics','[email protected]'),(3,'Eve','Chemistry','[email protected]');
|
UPDATE graduate_students SET email = CONCAT(SUBSTRING_INDEX(email, '@', 1), '@physics.ac.uk') WHERE department = 'Physics';
|
Delete community engagement events held more than 6 months ago
|
CREATE TABLE CommunityEvents (event_id INT,region VARCHAR(50),event_type VARCHAR(50),event_date DATE);
|
DELETE FROM CommunityEvents WHERE event_date < NOW() - INTERVAL '6 month';
|
List all cultural heritage sites in Spain and Italy.
|
CREATE TABLE Cultural_Sites (site_id INT,site_name VARCHAR(50),country VARCHAR(50)); INSERT INTO Cultural_Sites (site_id,site_name,country) VALUES (1,'Alhambra','Spain'),(2,'Colosseum','Italy');
|
SELECT site_name FROM Cultural_Sites WHERE country IN ('Spain', 'Italy');
|
List all the pipelines located in 'Siberia'
|
CREATE TABLE pipelines (pipeline_name TEXT,location TEXT); INSERT INTO pipelines (pipeline_name,location) VALUES ('Pipeline A','Gulf of Mexico'),('Pipeline B','Siberia'),('Pipeline C','Gulf of Mexico');
|
SELECT pipeline_name FROM pipelines WHERE location = 'Siberia';
|
Find the total number of hours worked by miners in each mine site, located in South Africa.
|
CREATE TABLE LaborProductivity (SiteID INT,EmployeeID INT,Role VARCHAR(50),HoursWorkedDecimal FLOAT,Date DATE); ALTER TABLE Employees ADD CONSTRAINT FK_SiteID FOREIGN KEY (SiteID) REFERENCES LaborProductivity(SiteID);
|
SELECT MineSites.Name, SUM(LaborProductivity.HoursWorkedDecimal) AS TotalHoursWorked FROM MineSites JOIN Employees ON MineSites.SiteID = Employees.SiteID JOIN LaborProductivity ON Employees.EmployeeID = LaborProductivity.EmployeeID WHERE Employees.Role = 'Miner' AND MineSites.Country = 'South Africa' GROUP BY MineSites.Name;
|
What is the average age of defendants per court case?
|
CREATE TABLE court_cases (case_id INT,court_date DATE); INSERT INTO court_cases (case_id,court_date) VALUES (1,'2022-01-01'),(2,'2021-12-20'),(3,'2022-02-15'); CREATE TABLE defendant_info (defendant_id INT,case_id INT,age INT,gender VARCHAR(50)); INSERT INTO defendant_info (defendant_id,case_id,age,gender) VALUES (1,1,35,'Male'),(2,2,27,'Female'),(3,1,42,'Non-binary'),(4,3,19,'Female'),(5,3,50,'Male');
|
SELECT AVG(age) as avg_age, court_date FROM defendant_info d INNER JOIN court_cases c ON d.case_id = c.case_id GROUP BY court_date;
|
What is the number of clients who made their first transaction in Q1 2023 and their total assets value?
|
CREATE TABLE clients (client_id INT,name VARCHAR(50),total_assets DECIMAL(10,2),first_transaction_date DATE);CREATE TABLE transactions (transaction_id INT,client_id INT,transaction_date DATE);
|
SELECT c.total_assets, COUNT(*) FROM clients c INNER JOIN transactions t ON c.client_id = t.client_id WHERE c.first_transaction_date = t.transaction_date AND t.transaction_date BETWEEN '2023-01-01' AND '2023-03-31' GROUP BY c.total_assets
|
What is the total revenue for each restaurant, including their sustainable sourcing costs, for the month of January 2021?
|
CREATE TABLE Restaurants (RestaurantID int,Name varchar(50),TotalRevenue decimal(10,2));CREATE TABLE SustainableSourcing (SourcingID int,RestaurantID int,Cost decimal(10,2));
|
SELECT R.Name, SUM(R.TotalRevenue + SS.Cost) as TotalRevenueWithSustainableCosts FROM Restaurants R INNER JOIN SustainableSourcing SS ON R.RestaurantID = SS.RestaurantID WHERE MONTH(R.OrderDate) = 1 AND YEAR(R.OrderDate) = 2021 GROUP BY R.Name;
|
List the mines that have shown an increase in water consumption compared to the previous day.
|
CREATE TABLE daily_mine_water_consumption (mine_id INT,consumption_date DATE,total_water_consumption FLOAT); INSERT INTO daily_mine_water_consumption (mine_id,consumption_date,total_water_consumption) VALUES (1,'2021-01-01',30000),(1,'2021-01-02',31000),(1,'2021-01-03',32000),(1,'2021-01-04',33000),(2,'2021-01-01',40000),(2,'2021-01-02',41000),(2,'2021-01-03',42000),(2,'2021-01-04',41000);
|
SELECT mine_id, consumption_date, total_water_consumption, LAG(total_water_consumption) OVER (PARTITION BY mine_id ORDER BY consumption_date) as prev_day_consumption, total_water_consumption - LAG(total_water_consumption) OVER (PARTITION BY mine_id ORDER BY consumption_date) as consumption_change FROM daily_mine_water_consumption WHERE total_water_consumption > LAG(total_water_consumption) OVER (PARTITION BY mine_id ORDER BY consumption_date);
|
What is the total number of organic ingredients used in cosmetics products for each category?
|
CREATE TABLE ingredient_sourcing(ingredient_id INT,product_id INT,ingredient VARCHAR(50),organic BOOLEAN);
|
SELECT cosmetics_products.category, SUM(CASE WHEN ingredient_sourcing.organic THEN 1 ELSE 0 END) as organic_ingredient_count FROM ingredient_sourcing JOIN cosmetics_products ON ingredient_sourcing.product_id = cosmetics_products.product_id GROUP BY cosmetics_products.category;
|
What is the total funding amount for the 'Theater' category in 2022?
|
CREATE TABLE funding_sources (funding_source_id INT,funding_category VARCHAR(255),year INT,amount INT); INSERT INTO funding_sources (funding_source_id,funding_category,year,amount) VALUES (1,'Visual Arts',2022,5000),(2,'Theater',2021,7000),(3,'Theater',2022,12000);
|
SELECT SUM(amount) as total_funding FROM funding_sources WHERE funding_category = 'Theater' AND year = 2022;
|
What is the total population in Africa with access to clean water?
|
CREATE TABLE WaterAccess (country_name TEXT,continent TEXT,population INTEGER,clean_water_access BOOLEAN); INSERT INTO WaterAccess (country_name,continent,population,clean_water_access) VALUES ('Algeria','Africa',43073003,true),('Angola','Africa',32898569,false),('Benin','Africa',12131338,true),('Botswana','Africa',2359373,true),('Burkina Faso','Africa',20807289,false),('Burundi','Africa',11526794,false),('Cameroon','Africa',25678974,true);
|
SELECT SUM(population) FROM WaterAccess WHERE clean_water_access = true AND continent = 'Africa';
|
How many travel advisories have been issued for European cities in the past month?
|
CREATE TABLE TravelAdvisories (id INT,city TEXT,issued_date DATE);
|
SELECT COUNT(*) FROM TravelAdvisories WHERE city IN ('Paris', 'London', 'Rome', 'Berlin', 'Madrid') AND issued_date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH);
|
What is the total water usage in MW for the residential sector in January 2020?
|
CREATE TABLE water_usage_mwh (region VARCHAR(20),sector VARCHAR(20),year INT,month INT,units VARCHAR(10),value FLOAT); INSERT INTO water_usage_mwh (region,sector,year,month,units,value) VALUES ('California','Residential',2020,1,'MWh',1500000);
|
SELECT value FROM water_usage_mwh WHERE sector = 'Residential' AND region = 'California' AND year = 2020 AND month = 1 AND units = 'MWh';
|
How many AI safety incidents were reported in each country for the past 2 years?
|
CREATE TABLE ai_safety_incidents (incident_id INT,incident_date DATE,incident_country TEXT); INSERT INTO ai_safety_incidents (incident_id,incident_date,incident_country) VALUES (1,'2021-03-15','USA'),(2,'2020-12-21','Canada'),(3,'2021-08-01','UK'),(4,'2020-01-10','Mexico'),(5,'2021-06-12','France');
|
SELECT incident_country, EXTRACT(YEAR FROM incident_date) as year, COUNT(*) as num_incidents FROM ai_safety_incidents GROUP BY incident_country, year;
|
Create a view named 'space_debris_view' showing all debris entries
|
CREATE TABLE space_debris (id INT PRIMARY KEY,debris_id INT,debris_name VARCHAR(255),launch_date DATE,location VARCHAR(255),type VARCHAR(255)); CREATE VIEW space_debris_view AS SELECT * FROM space_debris;
|
CREATE VIEW space_debris_view AS SELECT * FROM space_debris;
|
Find the daily revenue for 'Vegan Pizza' on 2021-08-01
|
CREATE TABLE restaurants (id INT,name VARCHAR(50),category VARCHAR(50)); INSERT INTO restaurants (id,name,category) VALUES (1,'Pizza Palace','Vegan Pizza'); CREATE TABLE menu_items (id INT,name VARCHAR(50),category VARCHAR(50),price DECIMAL(5,2)); INSERT INTO menu_items (id,name,category,price) VALUES (101,'Vegan Pepperoni Pizza','Vegan Pizza',14.99),(102,'Vegan Margherita Pizza','Vegan Pizza',12.99); CREATE TABLE orders (id INT,menu_item_id INT,quantity INT,order_date DATE); INSERT INTO orders (id,menu_item_id,quantity,order_date) VALUES (1001,101,1,'2021-08-01'),(1002,102,3,'2021-08-01'),(1003,101,2,'2021-08-03');
|
SELECT SUM(menu_items.price * orders.quantity) AS daily_revenue FROM orders JOIN menu_items ON orders.menu_item_id = menu_items.id WHERE menu_items.category = 'Vegan Pizza' AND orders.order_date = '2021-08-01';
|
What is the 'maintenance_cost' for 'Plant D' in 'water_treatment_plants'?
|
CREATE TABLE water_treatment_plants (id INT,plant_name VARCHAR(50),maintenance_cost INT); INSERT INTO water_treatment_plants (id,plant_name,maintenance_cost) VALUES (1,'Plant A',30000),(2,'Plant B',50000),(3,'Plant C',40000),(4,'Plant D',35000);
|
SELECT maintenance_cost FROM water_treatment_plants WHERE plant_name = 'Plant D';
|
What is the minimum wage in factories in Southeast Asia?
|
CREATE TABLE factory_wages (id INT,factory VARCHAR(100),location VARCHAR(100),min_wage DECIMAL(5,2)); INSERT INTO factory_wages (id,factory,location,min_wage) VALUES (1,'Vietnam Factory','Vietnam',5),(2,'Thailand Factory','Thailand',7),(3,'Cambodia Factory','Cambodia',3);
|
SELECT MIN(min_wage) FROM factory_wages WHERE location = 'Southeast Asia';
|
What is the maximum pollution level recorded in the Pacific Ocean?
|
CREATE TABLE ocean_pollution (location VARCHAR(255),pollution_level FLOAT); INSERT INTO ocean_pollution (location,pollution_level) VALUES ('Pacific Ocean',7.5),('Atlantic Ocean',6.2);
|
SELECT MAX(pollution_level) FROM ocean_pollution WHERE location = 'Pacific Ocean';
|
How many artists were born in each country?
|
CREATE TABLE artists (artist_id INT,name VARCHAR(50),birth_place VARCHAR(50)); INSERT INTO artists (artist_id,name,birth_place) VALUES (1,'Vincent Van Gogh','Netherlands');
|
SELECT a.birth_place, COUNT(*) FROM artists a GROUP BY a.birth_place;
|
What is the total number of military bases grouped by country?
|
CREATE TABLE MilitaryBases (BaseID int,BaseName varchar(100),Country varchar(50),NumSoldiers int); INSERT INTO MilitaryBases (BaseID,BaseName,Country,NumSoldiers) VALUES (1,'Fort Bragg','USA',53000),(2,'Camp Bastion','UK',28000),(3,'Camp Taji','Iraq',15000);
|
SELECT Country, COUNT(*) as TotalBases FROM MilitaryBases GROUP BY Country;
|
Identify the number of food allergens for each dish in the 'menu_items' table, with a dish rating of 'excellent' or 'good' in the 'dish_ratings' table?
|
CREATE TABLE menu_items (menu_id INT,dish_name VARCHAR(255),allergen_count INT);CREATE TABLE dish_ratings (dish_name VARCHAR(255),dish_rating VARCHAR(20));
|
SELECT menu_items.dish_name, SUM(menu_items.allergen_count) as total_allergens FROM menu_items INNER JOIN dish_ratings ON menu_items.dish_name = dish_ratings.dish_name WHERE dish_ratings.dish_rating IN ('excellent', 'good') GROUP BY menu_items.dish_name;
|
What is the average installed capacity for a renewable energy project in the 'renewables' schema?
|
CREATE SCHEMA if not exists renewables; CREATE TABLE if not exists renewables.renewable_projects (project_id int,name varchar(255),location varchar(255),installed_capacity float); INSERT INTO renewables.renewable_projects (project_id,name,location,installed_capacity) VALUES (1,'Renewable Project 1','Country A',100.0),(2,'Renewable Project 2','Country B',150.0),(3,'Renewable Project 3','Country C',200.0);
|
SELECT AVG(installed_capacity) FROM renewables.renewable_projects;
|
What is the total number of 'organic' and 'local' food products in the 'products' table?
|
CREATE TABLE products (product VARCHAR(255),is_organic BOOLEAN,is_local BOOLEAN); INSERT INTO products (product,is_organic,is_local) VALUES ('Apples',true,false),('Carrots',true,true),('Chicken',false,false),('Eggs',true,true);
|
SELECT COUNT(*) as total_organic_local_products FROM products WHERE is_organic = true OR is_local = true;
|
What is the total number of crime incidents, emergency calls, and fire incidents in the last week in Oakland, CA?
|
CREATE TABLE crime_incidents (id INT,date DATE,type VARCHAR(20)); INSERT INTO crime_incidents (id,date,type) VALUES (1,'2022-01-01','theft'),(2,'2022-01-02','burglary'); CREATE TABLE emergency_calls (id INT,date DATE,type VARCHAR(20)); INSERT INTO emergency_calls (id,date,type) VALUES (1,'2022-01-01','emergency call'); CREATE TABLE fire_incidents (id INT,date DATE,type VARCHAR(20)); INSERT INTO fire_incidents (id,date,type) VALUES (1,'2022-01-02','fire incident'); CREATE TABLE locations (id INT,city VARCHAR(20),state VARCHAR(20)); INSERT INTO locations (id,city,state) VALUES (1,'Oakland','CA');
|
SELECT 'crime incidents' AS type, COUNT(*) FROM crime_incidents INNER JOIN locations ON crime_incidents.date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK) AND locations.city = 'Oakland' AND locations.state = 'CA' UNION ALL SELECT 'emergency calls' AS type, COUNT(*) FROM emergency_calls INNER JOIN locations ON emergency_calls.date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK) AND locations.city = 'Oakland' AND locations.state = 'CA' UNION ALL SELECT 'fire incidents' AS type, COUNT(*) FROM fire_incidents INNER JOIN locations ON fire_incidents.date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK) AND locations.city = 'Oakland' AND locations.state = 'CA';
|
What is the total number of satellites launched by countries in the Asia-Pacific region?
|
CREATE TABLE satellites (satellite_id INT,satellite_name VARCHAR(100),launch_country VARCHAR(50),launch_date DATE); INSERT INTO satellites (satellite_id,satellite_name,launch_country,launch_date) VALUES (1,'Sentinel-1A','France','2012-04-03'); INSERT INTO satellites (satellite_id,satellite_name,launch_country,launch_date) VALUES (2,'Sentinel-1B','Germany','2016-04-22'); CREATE TABLE countries (country_id INT,country_name VARCHAR(50),region VARCHAR(50)); INSERT INTO countries (country_id,country_name,region) VALUES (1,'France','Europe'); INSERT INTO countries (country_id,country_name,region) VALUES (2,'Germany','Europe'); INSERT INTO countries (country_id,country_name,region) VALUES (3,'Australia','Asia-Pacific'); INSERT INTO countries (country_id,country_name,region) VALUES (4,'China','Asia-Pacific');
|
SELECT COUNT(*) FROM satellites s JOIN countries c ON s.launch_country = c.country_name WHERE c.region = 'Asia-Pacific';
|
How many donors registered in Q1 2022?
|
CREATE TABLE donors (id INT,donor_reg_date DATE); INSERT INTO donors (id,donor_reg_date) VALUES (1,'2022-01-01'),(2,'2022-02-15'),(3,'2022-03-30');
|
SELECT COUNT(*) FROM donors WHERE donor_reg_date BETWEEN '2022-01-01' AND '2022-03-31';
|
What is the average speed of vessels that have a maximum speed greater than 25 knots?
|
CREATE TABLE Vessels (Id INT,Name VARCHAR(100),MaxSpeed FLOAT); INSERT INTO Vessels (Id,Name,MaxSpeed) VALUES (1,'VesselA',30.5),(2,'VesselB',24.3),(3,'VesselC',28.8);
|
SELECT AVG(MaxSpeed) FROM Vessels WHERE MaxSpeed > 25;
|
What is the total balance for customers in the Seattle branch?
|
CREATE TABLE accounts (customer_id INT,account_type VARCHAR(20),branch VARCHAR(20),balance DECIMAL(10,2)); INSERT INTO accounts (customer_id,account_type,branch,balance) VALUES (1,'Savings','New York',5000.00),(2,'Checking','New York',7000.00),(3,'Checking','Seattle',3000.00),(4,'Savings','Seattle',4000.00),(5,'Credit Card','Seattle',1000.00);
|
SELECT SUM(balance) FROM accounts WHERE branch = 'Seattle';
|
What is the average rating for products sold in India?
|
CREATE TABLE ratings (product_id INT,rating INT,country_name VARCHAR(20)); INSERT INTO ratings (product_id,rating,country_name) VALUES (1,4,'India'),(2,3,'USA'),(3,5,'Canada'),(4,2,'Brazil');
|
SELECT AVG(rating) FROM ratings WHERE country_name = 'India';
|
List all artists and their artwork counts in the 'Cubism' period.
|
CREATE TABLE Artworks (id INT,artist_name VARCHAR(100),period VARCHAR(50),artwork_name VARCHAR(100)); INSERT INTO Artworks (id,artist_name,period,artwork_name) VALUES (1,'Pablo Picasso','Cubism','Guernica'); INSERT INTO Artworks (id,artist_name,period,artwork_name) VALUES (2,'Georges Braque','Cubism','Woman with a Guitar'); INSERT INTO Artworks (id,artist_name,period,artwork_name) VALUES (3,'Fernand Léger','Cubism','The Seasons');
|
SELECT artist_name, COUNT(*) as artwork_count FROM Artworks WHERE period = 'Cubism' GROUP BY artist_name;
|
What is the average rating of movies by genre?
|
CREATE TABLE movies (id INT,title VARCHAR(255),genre VARCHAR(255),rating FLOAT); INSERT INTO movies (id,title,genre,rating) VALUES (1,'Movie1','Action',7.5),(2,'Movie2','Drama',8.2),(3,'Movie3','Comedy',6.8),(4,'Movie4','Action',8.0),(5,'Movie5','Drama',7.0);
|
SELECT genre, AVG(rating) as avg_rating FROM movies GROUP BY genre;
|
What is the average network investment in the 'Africa' region over the last year?
|
CREATE TABLE network_investments (id INT,region VARCHAR(20),investment_date DATE,amount DECIMAL(10,2)); INSERT INTO network_investments (id,region,investment_date,amount) VALUES (1,'Europe','2022-01-01',50000.00),(2,'Asia','2022-02-01',75000.00),(3,'Europe','2022-03-01',60000.00),(4,'Africa','2022-04-01',45000.00),(5,'Africa','2022-05-01',55000.00);
|
SELECT AVG(amount) FROM network_investments WHERE region = 'Africa' AND investment_date BETWEEN DATE_SUB('2022-04-01', INTERVAL 1 YEAR) AND '2022-04-01';
|
Update all records in the 'Menu' table with a price less than 7.00 and set their price to 7.00.
|
CREATE TABLE Menu (id INT,name VARCHAR(255),price DECIMAL(5,2),vegetarian BOOLEAN); INSERT INTO Menu (id,name,price,vegetarian) VALUES (1,'Chicken Burger',7.99,FALSE),(2,'Veggie Wrap',6.49,TRUE),(3,'Chicken Caesar Salad',9.99,FALSE);
|
UPDATE Menu SET price = 7.00 WHERE price < 7.00;
|
What is the total investment in the Renewable Energy sector for the past 3 years?
|
CREATE TABLE investments (id INT,company_id INT,sector VARCHAR(255),year INT,amount FLOAT); INSERT INTO investments (id,company_id,sector,year,amount) VALUES (1,1,'Renewable Energy',2020,500000.0); INSERT INTO investments (id,company_id,sector,year,amount) VALUES (2,2,'Renewable Energy',2019,600000.0); INSERT INTO investments (id,company_id,sector,year,amount) VALUES (3,3,'Renewable Energy',2020,700000.0);
|
SELECT SUM(amount) FROM investments WHERE sector = 'Renewable Energy' AND year BETWEEN 2019 AND 2021;
|
What is the minimum donation amount received by each program?
|
CREATE TABLE programs (id INT,name VARCHAR(255)); INSERT INTO programs (id,name) VALUES (1,'Education'),(2,'Health'),(3,'Environment'); CREATE TABLE donations (id INT,program_id INT,amount DECIMAL(10,2)); INSERT INTO donations (id,program_id,amount) VALUES (1,1,500),(2,1,300),(3,2,800),(4,3,400);
|
SELECT program_id, MIN(amount) OVER (PARTITION BY program_id) AS min_donation_amount FROM donations;
|
What is the total number of security incidents and their average resolution time, grouped by quarter?
|
CREATE TABLE incidents (id INT,incident_date DATE,resolution_time INT); INSERT INTO incidents (id,incident_date,resolution_time) VALUES (1,'2021-04-01',5); INSERT INTO incidents (id,incident_date,resolution_time) VALUES (2,'2021-07-15',7); INSERT INTO incidents (id,incident_date,resolution_time) VALUES (3,'2021-10-02',3);
|
SELECT YEAR(incident_date) as year, QUARTER(incident_date) as quarter, COUNT(*) as num_incidents, AVG(resolution_time) as avg_resolution_time FROM incidents GROUP BY year, quarter;
|
What is the maximum quantity of a single product sold in a day?
|
CREATE TABLE Orders (id INT,product_id INT,quantity INT,order_date DATE); INSERT INTO Orders (id,product_id,quantity,order_date) VALUES (1,1,10,'2021-01-01'),(2,2,5,'2021-01-02'),(3,3,2,'2021-01-03'),(4,4,15,'2021-01-04'),(5,5,8,'2021-01-05'),(6,1,12,'2021-01-06');
|
SELECT product_id, MAX(quantity) FROM Orders GROUP BY product_id;
|
What is the maximum budget allocated to libraries in each borough?
|
CREATE TABLE budget_allocations (allocation_id INT,borough TEXT,category TEXT,budget INT); INSERT INTO budget_allocations (allocation_id,borough,category,budget) VALUES (1,'Manhattan','Parks',5000000),(2,'Brooklyn','Libraries',3000000),(3,'Bronx','Parks',2000000);
|
SELECT borough, MAX(budget) FROM budget_allocations WHERE category = 'Libraries' GROUP BY borough;
|
What is the average safety rating of sedans released since 2018?
|
CREATE TABLE SafetyTesting (id INT,vehicle_type VARCHAR(50),rating INT,release_year INT); INSERT INTO SafetyTesting (id,vehicle_type,rating,release_year) VALUES (1,'Sedan',5,2018),(2,'Sedan',5,2019),(3,'Sedan',4,2018),(4,'Sedan',5,2020),(5,'Sedan',4,2019),(6,'Sedan',4,2021),(7,'Sedan',5,2021);
|
SELECT AVG(rating) FROM SafetyTesting WHERE vehicle_type = 'Sedan' AND release_year >= 2018;
|
Find the average cost of ingredients for vegan menu items?
|
CREATE TABLE MenuItems (MenuItemID int,MenuItemName varchar(255),MenuItemType varchar(255),Cost int); INSERT INTO MenuItems (MenuItemID,MenuItemName,MenuItemType,Cost) VALUES (1,'Margherita Pizza','Entree',8),(2,'Spaghetti Bolognese','Entree',9),(3,'Caprese Salad','Appetizer',7),(4,'Veggie Burger','Entree',10),(5,'Garden Salad','Appetizer',5),(6,'Chickpea Curry','Entree',11),(7,'Falafel Wrap','Entree',9),(8,'Tofu Stir Fry','Entree',12),(9,'Vegan Cheese Pizza','Entree',10),(10,'Quinoa Salad','Entree',13);
|
SELECT AVG(Cost) FROM MenuItems WHERE MenuItemType = 'Entree' AND MenuItemName IN ('Vegan Cheese Pizza', 'Quinoa Salad', 'Chickpea Curry');
|
What is the total number of hotels in India and China that have received a sustainability certification?
|
CREATE TABLE hotel_certifications (country VARCHAR(50),certified INT); INSERT INTO hotel_certifications (country,certified) VALUES ('India',1000),('China',1500);
|
SELECT SUM(certified) FROM hotel_certifications WHERE country IN ('India', 'China');
|
How many times has a specific malware been detected in the last month?
|
CREATE TABLE MalwareDetections(id INT,malware_name VARCHAR(50),detection_date DATE);
|
SELECT COUNT(*) as detections FROM MalwareDetections WHERE malware_name = 'specific_malware' AND detection_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH);
|
What was the manufacturing cost of the last spacecraft launched?
|
CREATE TABLE Spacecrafts (id INT,name VARCHAR(255),launch_date DATE,manufacturing_cost FLOAT); INSERT INTO Spacecrafts (id,name,launch_date,manufacturing_cost) VALUES (1,'Sputnik 1','1957-10-04',140000); INSERT INTO Spacecrafts (id,name,launch_date,manufacturing_cost) VALUES (2,'Explorer 1','1958-01-31',150000); INSERT INTO Spacecrafts (id,name,launch_date,manufacturing_cost) VALUES (3,'Vostok 1','1961-04-12',240000); INSERT INTO Spacecrafts (id,name,launch_date,manufacturing_cost) VALUES (4,'Voyager 1','1977-09-05',250000);
|
SELECT manufacturing_cost FROM Spacecrafts ORDER BY launch_date DESC LIMIT 1;
|
Find the team with the most wins in the MLB in the 2021 season.
|
CREATE TABLE mlb_2021 (team TEXT,wins INT);
|
SELECT team, MAX(wins) FROM mlb_2021 GROUP BY team ORDER BY wins DESC LIMIT 1;
|
What is the average amount of humanitarian aid received per family in Europe, grouped by disaster type, ordered by the highest average?
|
CREATE TABLE aid_distribution_europe (family_id INT,region VARCHAR(20),disaster_type VARCHAR(20),amount_aid FLOAT); INSERT INTO aid_distribution_europe (family_id,region,disaster_type,amount_aid) VALUES (1,'Europe','Flood',5000),(2,'Europe','Earthquake',7000),(3,'Europe','Flood',6000),(4,'Europe','Tsunami',8000),(5,'Europe','Tornado',9000);
|
SELECT disaster_type, AVG(amount_aid) as avg_aid FROM aid_distribution_europe GROUP BY disaster_type ORDER BY avg_aid DESC;
|
What is the total number of acres of corn and soybeans in the 'crops' table?
|
CREATE TABLE crops (id INT,crop_type VARCHAR(255),yield INT,acres INT); INSERT INTO crops (id,crop_type,yield,acres) VALUES (1,'corn',100,100),(2,'soybeans',80,150),(3,'wheat',70,120);
|
SELECT SUM(acres) as total_acres FROM crops WHERE crop_type IN ('corn', 'soybeans');
|
Which genetic mutations were discovered in the clinical trial 'Trial_A'?
|
CREATE TABLE ClinicalTrial (ID INT,Name TEXT,Mutations TEXT); INSERT INTO ClinicalTrial (ID,Name,Mutations) VALUES (1,'Trial_A','MT1,MT2');
|
SELECT Mutations FROM ClinicalTrial WHERE Name = 'Trial_A';
|
What is the total number of autonomous vehicles tested in the state of California?
|
CREATE TABLE AutonomousVehicles (Id INT,TestLocation VARCHAR(50),TestDate DATE,VehicleCount INT); INSERT INTO AutonomousVehicles (Id,TestLocation,TestDate,VehicleCount) VALUES (1,'California','2018-01-01',500),(2,'California','2019-01-01',1000),(3,'California','2020-01-01',1500),(4,'California','2021-01-01',2000);
|
SELECT SUM(VehicleCount) FROM AutonomousVehicles WHERE TestLocation = 'California';
|
List all the cities and their total waste generation quantities for 2018, excluding records that have missing data?
|
CREATE TABLE CityWaste (CityName VARCHAR(50),WasteQuantity INT,WasteYear INT); INSERT INTO CityWaste (CityName,WasteQuantity,WasteYear) VALUES ('CityA',12000,2018),('CityB',15000,2018),('CityC',NULL,2018),('CityD',18000,2018);
|
SELECT CityName, SUM(WasteQuantity) FROM CityWaste WHERE WasteYear = 2018 AND WasteQuantity IS NOT NULL GROUP BY CityName;
|
Get the top 2 languages with the most posts related to AI.
|
CREATE TABLE users (id INT,name VARCHAR(255),country VARCHAR(255),language VARCHAR(10)); CREATE TABLE posts (id INT,user_id INT,content TEXT,created_at TIMESTAMP);
|
SELECT posts.language, COUNT(posts.id) AS posts_count FROM posts JOIN users ON users.id = posts.user_id WHERE posts.content LIKE '%AI%' GROUP BY posts.language ORDER BY posts_count DESC LIMIT 2;
|
What is the average age of policyholders in 'Texas'?
|
CREATE TABLE policyholders (id INT,name TEXT,age INT,gender TEXT,state TEXT); INSERT INTO policyholders (id,name,age,gender,state) VALUES (1,'John Doe',35,'Male','Texas'); INSERT INTO policyholders (id,name,age,gender,state) VALUES (2,'Jane Smith',42,'Female','Texas'); INSERT INTO policyholders (id,name,age,gender,state) VALUES (3,'Bob Johnson',27,'Male','California'); INSERT INTO policyholders (id,name,age,gender,state) VALUES (4,'Alice Williams',32,'Female','Texas');
|
SELECT AVG(policyholders.age) AS avg_age FROM policyholders WHERE policyholders.state = 'Texas';
|
What is the total budget allocated to all education projects in the state of New York in the year 2020?
|
CREATE TABLE EducationProjects (ProjectID INT,Name VARCHAR(100),Budget DECIMAL(10,2),Year INT,State VARCHAR(50)); INSERT INTO EducationProjects (ProjectID,Name,Budget,Year,State) VALUES (1,'School Construction',10000000,2020,'New York'),(2,'Teacher Training',500000,2019,'New York'),(3,'Education Technology',800000,2020,'California');
|
SELECT SUM(Budget) FROM EducationProjects WHERE Year = 2020 AND State = 'New York';
|
What are the opening hours and locations of all cultural centers in the 'culture' schema?
|
CREATE TABLE cultural_centers (name VARCHAR(255),opening_hours VARCHAR(255),location VARCHAR(255)); INSERT INTO cultural_centers (name,opening_hours,location) VALUES ('Native American Cultural Center','09:00-17:00','New Mexico'),('Asian Cultural Center','10:00-18:00','New York');
|
SELECT name, opening_hours, location FROM culture.cultural_centers;
|
What is the total volume of freight forwarded to Asia from 'warehouse2' in Q3 2021?
|
CREATE TABLE warehouse (id INT,location VARCHAR(255),capacity INT); INSERT INTO warehouse (id,location,capacity) VALUES (1,'warehouse1',5000),(2,'warehouse2',7000); CREATE TABLE freight (id INT,warehouse_id INT,volume INT,destination VARCHAR(255),shipped_date DATE); INSERT INTO freight (id,warehouse_id,volume,destination,shipped_date) VALUES (1,1,150,'Europe','2021-08-01'),(2,2,200,'Asia','2021-09-05'),(3,1,120,'Africa','2021-10-10'),(4,2,220,'Asia','2021-09-15'),(5,1,180,'Europe','2021-08-20');
|
SELECT SUM(volume) FROM freight WHERE warehouse_id = 2 AND destination LIKE 'Asia%' AND shipped_date BETWEEN '2021-07-01' AND '2021-12-31' AND EXTRACT(QUARTER FROM shipped_date) = 3;
|
Find the number of schools and hospitals in each region, and their sum
|
CREATE TABLE regions (id INT,name VARCHAR(255)); INSERT INTO regions (id,name) VALUES (1,'Region1'); CREATE TABLE schools (id INT,region_id INT,name VARCHAR(255)); CREATE TABLE hospitals (id INT,region_id INT,name VARCHAR(255));
|
SELECT r.name, COUNT(s.id) AS school_count, COUNT(h.id) AS hospital_count, COUNT(s.id) + COUNT(h.id) AS total FROM regions r
|
What is the total waste generation in gram for each country in 2020, sorted by the highest amount?
|
CREATE TABLE waste_generation (country VARCHAR(50),year INT,waste_amount FLOAT); INSERT INTO waste_generation (country,year,waste_amount) VALUES ('Canada',2020,1200.5),('Mexico',2020,1500.3),('USA',2020,2000.0),('Brazil',2020,1800.2),('Argentina',2020,1300.9);
|
SELECT country, SUM(waste_amount) FROM waste_generation WHERE year = 2020 GROUP BY country ORDER BY SUM(waste_amount) DESC;
|
What is the average risk level for customers in Florida?
|
CREATE TABLE customers (customer_id INT,customer_name VARCHAR(50),state VARCHAR(20),risk_level VARCHAR(10)); INSERT INTO customers (customer_id,customer_name,state,risk_level) VALUES (1,'John Doe','FL','medium'),(2,'Jane Smith','NY','medium');
|
SELECT AVG(CASE WHEN risk_level = 'high' THEN 3 WHEN risk_level = 'medium' THEN 2 WHEN risk_level = 'low' THEN 1 END) FROM customers WHERE state = 'FL';
|
Who are the archaeologists specializing in 'Underwater Archaeology'?
|
CREATE TABLE Archaeologists (ArchaeologistID INT PRIMARY KEY,Name VARCHAR(255),Age INT,Specialization VARCHAR(255)); INSERT INTO Archaeologists (ArchaeologistID,Name,Age,Specialization) VALUES (6,'Marie-Louise von Plessen',72,'Underwater Archaeology'),(7,'Francesco Bandelli',55,'Historical Archaeology'),(8,'Sophie de Schaepdrijver',58,'Archaeology of War');
|
SELECT * FROM Archaeologists WHERE Specialization = 'Underwater Archaeology';
|
Which temperature sensors in 'Field17' and 'Field18' have recorded data between '2021-06-15' and '2021-06-30'?
|
CREATE TABLE Field17 (sensor_id INT,sensor_name VARCHAR(50),sensor_type VARCHAR(50),data DATETIME); INSERT INTO Field17 (sensor_id,sensor_name,sensor_type,data) VALUES (1,'TemperatureSensor1','Temperature','2021-06-16 10:00:00'),(2,'TemperatureSensor2','Temperature','2021-06-14 12:45:00'); CREATE TABLE Field18 (sensor_id INT,sensor_name VARCHAR(50),sensor_type VARCHAR(50),data DATETIME); INSERT INTO Field18 (sensor_id,sensor_name,sensor_type,data) VALUES (3,'TemperatureSensor3','Temperature','2021-06-30 09:30:00'),(4,'TemperatureSensor4','Temperature','2021-06-28 11:00:00');
|
SELECT DISTINCT sensor_name FROM Field17 WHERE data BETWEEN '2021-06-15' AND '2021-06-30' UNION SELECT DISTINCT sensor_name FROM Field18 WHERE data BETWEEN '2021-06-15' AND '2021-06-30';
|
List all unique art mediums used in the artworks
|
CREATE TABLE artists (artist_id INT PRIMARY KEY,name VARCHAR(100),birth_date DATE,death_date DATE,nationality VARCHAR(50)); CREATE TABLE artworks (artwork_id INT PRIMARY KEY,title VARCHAR(100),year INT,artist_id INT,art_medium VARCHAR(50),FOREIGN KEY (artist_id) REFERENCES artists(artist_id));
|
SELECT DISTINCT art_medium FROM artworks;
|
How many smart city features does each city have?
|
CREATE TABLE smart_city_features (city VARCHAR(50),feature VARCHAR(50)); INSERT INTO smart_city_features (city,feature) VALUES ('CityA','Smart Lighting'),('CityA','Smart Transportation'),('CityB','Smart Waste Management'),('CityB','Smart Grid');
|
SELECT city, COUNT(feature) FROM smart_city_features GROUP BY city;
|
What is the average amount of funding allocated to businesses in the Energy sector?
|
CREATE TABLE businesses (id INT,name TEXT,industry TEXT,ownership TEXT,funding FLOAT); INSERT INTO businesses (id,name,industry,ownership,funding) VALUES (1,'EnergyCo','Energy','Majority',350000.00); INSERT INTO businesses (id,name,industry,ownership,funding) VALUES (2,'TechCo','Technology','Minority',500000.00);
|
SELECT AVG(funding) FROM businesses WHERE industry = 'Energy';
|
Insert a new restorative justice service (type: 'Peacemaking Circle') for a victim (id: 3) in Colorado.
|
CREATE TABLE victims (id INT,name TEXT,state TEXT); CREATE TABLE restorative_justice_services (id INT,victim_id INT,service_type TEXT); INSERT INTO victims (id,name,state) VALUES (1,'Olivia Johnson','Colorado'); INSERT INTO victims (id,name,state) VALUES (2,'Daniel Lee','Colorado'); INSERT INTO victims (id,name,state) VALUES (3,'Maria Garcia','Colorado');
|
INSERT INTO restorative_justice_services (id, victim_id, service_type) VALUES (1, 3, 'Peacemaking Circle');
|
Display the total biomass of coral reefs in the Indo-Pacific region
|
CREATE TABLE coral_reefs (reef_name TEXT,biomass REAL,region TEXT);
|
SELECT SUM(biomass) FROM coral_reefs WHERE region = 'Indo-Pacific';
|
Calculate the total annual energy savings for green buildings constructed in 2020
|
CREATE TABLE green_buildings_timeline (id INT,building_id INT,start_date DATE);
|
SELECT SUM(green_buildings.annual_energy_savings_kWh) FROM green_buildings JOIN green_buildings_timeline ON green_buildings.id = green_buildings_timeline.building_id WHERE green_buildings_timeline.start_date >= '2020-01-01' AND green_buildings_timeline.start_date < '2021-01-01';
|
What is the minimum area required for a sustainable farm in India?
|
CREATE TABLE farm_sizes (id INT,size INT,country VARCHAR(255)); INSERT INTO farm_sizes (id,size,country) VALUES (1,2,'India');
|
SELECT MIN(size) FROM farm_sizes WHERE country = 'India';
|
Calculate the average population of each animal
|
CREATE TABLE if not exists animal_population (id INT,animal VARCHAR(255),country VARCHAR(255),population INT); INSERT INTO animal_population (id,animal,country,population) VALUES (1,'Tiger','India',2500),(2,'Tiger','Bangladesh',150),(3,'Elephant','India',5000),(4,'Elephant','Sri Lanka',2500);
|
SELECT animal, AVG(population) FROM animal_population GROUP BY animal;
|
What is the average age of football players in the English Premier League by position?
|
CREATE TABLE teams (team_id INT,team_name VARCHAR(255),league VARCHAR(255));CREATE TABLE players (player_id INT,player_name VARCHAR(255),position VARCHAR(50),team_id INT,birth_date DATE); INSERT INTO teams VALUES (1,'Liverpool','English Premier League'); INSERT INTO players VALUES (1,'Alisson Becker','Goalkeeper',1,'1992-10-02');
|
SELECT position, AVG(YEAR(CURRENT_DATE) - YEAR(birth_date)) AS avg_age FROM players JOIN teams ON players.team_id = teams.team_id WHERE teams.league = 'English Premier League' GROUP BY position;
|
Which sports teams had a win rate greater than 60% and an average fan age above 35?
|
CREATE TABLE SportsTeamPerformance (id INT,team_name VARCHAR(255),win_rate DECIMAL(5,2),avg_fan_age INT); INSERT INTO SportsTeamPerformance (id,team_name,win_rate,avg_fan_age) VALUES (1,'TeamA',0.75,32),(2,'TeamB',0.62,40),(3,'TeamC',0.58,38); CREATE TABLE FanDemographics (id INT,name VARCHAR(255),gender VARCHAR(50),team_name VARCHAR(255),fan_age INT); INSERT INTO FanDemographics (id,name,gender,team_name,fan_age) VALUES (1,'FanD','Male','TeamA',30),(2,'FanE','Female','TeamB',45),(3,'FanF','Male','TeamC',35);
|
SELECT team_name FROM SportsTeamPerformance WHERE win_rate > 0.6 AND (SELECT AVG(fan_age) FROM FanDemographics WHERE team_name = SportsTeamPerformance.team_name) > 35;
|
How many patents were filed by companies founded before 2010?
|
CREATE TABLE company_innovation (company_id INT,founding_year INT,patent_count INT); INSERT INTO company_innovation (company_id,founding_year,patent_count) VALUES (1,2009,3),(2,2011,1),(3,2008,2),(4,2010,4);
|
SELECT founding_year, SUM(patent_count) FROM company_innovation WHERE founding_year < 2010 GROUP BY founding_year;
|
How many players are there in each country playing 'Simulation' games?
|
CREATE TABLE Players (Id INT,Name VARCHAR(100),Country VARCHAR(50),Game VARCHAR(50)); INSERT INTO Players VALUES (1,'Player1','USA','GameX'),(2,'Player2','Canada','GameY'),(3,'Player3','USA','GameZ'),(4,'Player4','Mexico','GameX'),(5,'Player5','Canada','GameY'),(6,'Player6','USA','GameW'),(7,'Player7','Brazil','GameX'); CREATE TABLE Games (Id INT,Name VARCHAR(100),Genre VARCHAR(50)); INSERT INTO Games VALUES (1,'GameX','Adventure'),(2,'GameY','Simulation'),(3,'GameZ','Adventure'),(4,'GameW','Strategy');
|
SELECT p.Country, COUNT(*) AS Players_Count FROM Players p JOIN Games g ON p.Game = g.Name WHERE g.Genre = 'Simulation' GROUP BY p.Country;
|
How many legal technology grants were awarded to organizations in 'North Valley' justice district?
|
CREATE TABLE LegalTechnologyGrants (ID INT,GrantID VARCHAR(20),District VARCHAR(20),Amount INT,Year INT); INSERT INTO LegalTechnologyGrants (ID,GrantID,District,Amount,Year) VALUES (1,'LTG2016','North Valley',15000,2016),(2,'LTG2017','East River',20000,2017),(3,'LTG2018','North Valley',10000,2018);
|
SELECT COUNT(*) FROM LegalTechnologyGrants WHERE District = 'North Valley';
|
What is the average property price per square foot in each neighborhood?
|
CREATE TABLE neighborhoods (name VARCHAR(50),id INT,PRIMARY KEY (id)); INSERT INTO neighborhoods (name,id) VALUES ('Brewerytown',1),('Fairmount',2); CREATE TABLE properties (id INT,neighborhood_id INT,price FLOAT,livable_square_feet INT,PRIMARY KEY (id),FOREIGN KEY (neighborhood_id) REFERENCES neighborhoods(id));
|
SELECT neighborhood_id, AVG(price/livable_square_feet) AS avg_price_per_sqft FROM properties GROUP BY neighborhood_id;
|
What is the total installed capacity (in MW) for wind and solar power plants by country as of 2020?
|
CREATE TABLE capacity (country VARCHAR(255),technology VARCHAR(255),year INT,capacity FLOAT);
|
SELECT country, SUM(capacity) FROM capacity WHERE year = 2020 AND technology IN ('wind', 'solar') GROUP BY country;
|
Find all the paintings from the 'Impressionist' movement.
|
CREATE TABLE Paintings (PaintingID INT,Title VARCHAR(50),ArtistID INT,YearCreated INT,Movement VARCHAR(50)); INSERT INTO Paintings (PaintingID,Title,ArtistID,YearCreated,Movement) VALUES (1,'Starry Night',1,1889,'Post-Impressionism'); INSERT INTO Paintings (PaintingID,Title,ArtistID,YearCreated,Movement) VALUES (2,'The Persistence of Memory',3,1931,'Surrealism'); CREATE TABLE Movements (MovementID INT,Name VARCHAR(50)); INSERT INTO Movements (MovementID,Name) VALUES (1,'Impressionism'); INSERT INTO Movements (MovementID,Name) VALUES (2,'Post-Impressionism');
|
SELECT PaintingID, Title, ArtistID, YearCreated, Movement FROM Paintings WHERE Movement IN ('Impressionism', 'Post-Impressionism');
|
What is the number of primary care physicians per capita?
|
CREATE TABLE population (county_id INT,county_name TEXT,population_count INT); INSERT INTO population (county_id,county_name,population_count) VALUES (1,'County A',10000),(2,'County B',20000),(3,'County C',30000); CREATE TABLE physicians (physician_id INT,physician_name TEXT,county_id INT,specialty TEXT); INSERT INTO physicians (physician_id,physician_name,county_id,specialty) VALUES (1,'Physician A',1,'Primary Care'),(2,'Physician B',2,'Specialty Care'),(3,'Physician C',3,'Primary Care');
|
SELECT p.county_name, COUNT(*) FILTER (WHERE p.specialty = 'Primary Care') * 1.0 / p.population_count as ratio FROM physicians p INNER JOIN population pop ON p.county_id = pop.county_id GROUP BY p.county_id;
|
List the top 5 users who have posted the most on Tuesdays in the social_media database.
|
CREATE TABLE user (user_id INT,username VARCHAR(20),posts INT,created_at DATE); INSERT INTO user (user_id,username,posts,created_at) VALUES (1,'user1',10,'2022-01-01'),(2,'user2',20,'2022-01-02'),(3,'user3',30,'2022-01-03'),(4,'user4',40,'2022-01-04'),(5,'user5',50,'2022-01-05'),(6,'user6',6,'2022-01-04'),(7,'user7',7,'2022-01-03'),(8,'user8',8,'2022-01-02'),(9,'user9',9,'2022-01-01'),(10,'user10',10,'2022-01-05');
|
SELECT user_id, username, SUM(posts) as total_posts FROM user WHERE DATEPART(dw, created_at) = 3 GROUP BY user_id, username ORDER BY total_posts DESC LIMIT 5;
|
Identify the top 3 most eco-certified accommodations in Africa
|
CREATE TABLE accommodations (id INT,continent VARCHAR(255),eco_certified INT); INSERT INTO accommodations (id,continent,eco_certified) VALUES (1,'Africa',1),(2,'Africa',1),(3,'Africa',1),(4,'Africa',0),(5,'Asia',1);
|
SELECT continent, SUM(eco_certified) as eco_certified_count FROM accommodations WHERE continent = 'Africa' GROUP BY continent ORDER BY eco_certified_count DESC LIMIT 3;
|
What is the average dissolved oxygen level in freshwater aquaculture facilities in the Great Lakes region?
|
CREATE TABLE freshwater_aquaculture (id INT,name TEXT,region TEXT,dissolved_oxygen FLOAT); INSERT INTO freshwater_aquaculture (id,name,region,dissolved_oxygen) VALUES (1,'Facility G','Great Lakes',8.1),(2,'Facility H','Great Lakes',7.9),(3,'Facility I','Mississippi River',7.5);
|
SELECT AVG(dissolved_oxygen) FROM freshwater_aquaculture WHERE region = 'Great Lakes';
|
What is the total number of eco-friendly accommodations in Thailand and Indonesia?
|
CREATE TABLE eco_accommodations (accom_id INT,accom_name TEXT,location TEXT); INSERT INTO eco_accommodations (accom_id,accom_name,location) VALUES (1,'Eco Lodge','Thailand'),(2,'Green Villa','Indonesia');
|
SELECT COUNT(*) FROM eco_accommodations WHERE location IN ('Thailand', 'Indonesia');
|
What is the minimum confidence level for threat indicators in the aviation sector globally?
|
CREATE TABLE threat_indicators (id INT,sector TEXT,confidence INT); INSERT INTO threat_indicators (id,sector,confidence) VALUES (1,'Aviation',85); INSERT INTO threat_indicators (id,sector,confidence) VALUES (2,'Aviation',70); INSERT INTO threat_indicators (id,sector,confidence) VALUES (3,'Healthcare',65);
|
SELECT MIN(confidence) FROM threat_indicators WHERE sector = 'Aviation';
|
What is the average funding per genetic research project in Q2 2022?
|
CREATE TABLE funding(id INT,project VARCHAR(50),date DATE,amount DECIMAL(10,2)); INSERT INTO funding VALUES (1,'ProjectA','2022-04-15',250000.00),(2,'ProjectB','2022-06-30',350000.00),(3,'ProjectC','2022-05-28',300000.00);
|
SELECT AVG(amount) FROM funding WHERE date BETWEEN '2022-04-01' AND '2022-06-30';
|
List the names of all companies in the manufacturing industry that have implemented industry 4.0 technologies.
|
CREATE TABLE companies (id INT,name TEXT,country TEXT,industry TEXT,industry_4_0 BOOLEAN); INSERT INTO companies (id,name,country,industry,industry_4_0) VALUES (1,'ABC Corp','Germany','Manufacturing',TRUE),(2,'DEF Corp','France','Service',FALSE),(3,'GHI Corp','Germany','Manufacturing',FALSE);
|
SELECT name FROM companies WHERE industry = 'Manufacturing' AND industry_4_0 = TRUE;
|
What is the average monthly water consumption per capita in the city of Seattle over the last year?
|
CREATE TABLE seattle_water_consumption (id INT,date DATE,household_size INT,water_consumption FLOAT); INSERT INTO seattle_water_consumption (id,date,household_size,water_consumption) VALUES (1,'2021-01-01',4,1200.0),(2,'2021-01-02',3,900.0);
|
SELECT AVG(water_consumption / household_size) FROM seattle_water_consumption WHERE date >= DATEADD(year, -1, CURRENT_DATE) AND city = 'Seattle';
|
What is the percentage of patients in mental health treatment centers in North America who have been diagnosed with PTSD?
|
CREATE TABLE north_american_health_centers (id INT,name VARCHAR(255),patients INT,condition VARCHAR(255)); INSERT INTO north_american_health_centers (id,name,patients,condition) VALUES (1,'Sunshine Mental Health',50,'PTSD'); INSERT INTO north_american_health_centers (id,name,patients,condition) VALUES (2,'Oceanic Mental Health',75,'Depression'); INSERT INTO north_american_health_centers (id,name,patients,condition) VALUES (3,'Peak Mental Health',100,'Anxiety Disorder');
|
SELECT 100.0 * SUM(CASE WHEN condition = 'PTSD' THEN patients ELSE 0 END) / SUM(patients) FROM north_american_health_centers;
|
Delete all records related to unsold garments in India in 2021.
|
CREATE TABLE garment_sales (garment_type VARCHAR(20),country VARCHAR(20),year INT,units_sold INT); INSERT INTO garment_sales (garment_type,country,year,units_sold) VALUES ('hoodie','India',2021,0),('jacket','India',2021,0);
|
DELETE FROM garment_sales WHERE country = 'India' AND year = 2021 AND units_sold = 0;
|
What are the names of all spacecraft that were launched by Roscosmos?
|
CREATE TABLE Spacecraft (id INT,name VARCHAR(50),manufacturer VARCHAR(50),launch_date DATE); INSERT INTO Spacecraft (id,name,manufacturer,launch_date) VALUES (1,'Vostok 1','Roscosmos','1961-04-12'),(2,'Mercury-Redstone 3','NASA','1961-05-05'),(3,'Sputnik 1','Roscosmos','1957-10-04');
|
SELECT s.name FROM Spacecraft s WHERE s.manufacturer = 'Roscosmos';
|
What is the maximum duration of a workout for member 3?
|
CREATE TABLE Workouts (WorkoutID INT,MemberID INT,WorkoutDate DATE,Duration INT); INSERT INTO Workouts (WorkoutID,MemberID,WorkoutDate,Duration) VALUES (1,3,'2021-01-01',60),(2,3,'2021-02-01',75);
|
SELECT MAX(Duration) FROM Workouts WHERE MemberID = 3;
|
Which farmers in the US are using outdated tractors?
|
CREATE TABLE Farmers (id INT PRIMARY KEY,name VARCHAR(255),age INT,gender VARCHAR(10),location VARCHAR(255),farmer_id INT); CREATE TABLE Equipment (id INT PRIMARY KEY,type VARCHAR(255),model VARCHAR(255),purchased_date DATE,farmer_id INT,FOREIGN KEY (farmer_id) REFERENCES Farmers(farmer_id));
|
SELECT Farmers.name, Equipment.type, Equipment.model FROM Farmers INNER JOIN Equipment ON Farmers.farmer_id = Equipment.farmer_id WHERE Farmers.location = 'US' AND Equipment.purchased_date < DATE_SUB(CURRENT_DATE, INTERVAL 10 YEAR) AND Equipment.type = 'tractor';
|
List all farms utilizing IoT sensors and the number of sensors used in 2020.
|
CREATE TABLE farm_info (farm_id INT,farm_name VARCHAR(50),location VARCHAR(50)); CREATE TABLE sensor_data (id INT,sensor_id INT,farm_id INT,install_date DATE); INSERT INTO farm_info (farm_id,farm_name,location) VALUES (1,'Green Acres','USA'); INSERT INTO farm_info (farm_id,farm_name,location) VALUES (2,'Blue Fields','Canada'); INSERT INTO sensor_data (id,sensor_id,farm_id,install_date) VALUES (1,101,1,'2020-01-01'); INSERT INTO sensor_data (id,sensor_id,farm_id,install_date) VALUES (2,102,1,'2020-03-01'); INSERT INTO sensor_data (id,sensor_id,farm_id,install_date) VALUES (3,201,2,'2019-08-01');
|
SELECT farm_id, COUNT(DISTINCT sensor_id) as sensor_count FROM sensor_data WHERE YEAR(install_date) = 2020 GROUP BY farm_id;
|
What are the legal precedents cited in cases handled by the attorney with the highest billing rate?
|
CREATE TABLE Attorneys (id INT,name VARCHAR(50),billing_rate DECIMAL(5,2)); CREATE TABLE Cases (id INT,attorney_id INT,precedent VARCHAR(100)); INSERT INTO Attorneys (id,name,billing_rate) VALUES (1,'Attorney1',500.00),(2,'Attorney2',600.00),(3,'Attorney3',700.00); INSERT INTO Cases (id,attorney_id,precedent) VALUES (1,1,'Precedent1'),(2,1,'Precedent2'),(3,2,'Precedent3'),(4,3,'Precedent4');
|
SELECT Cases.precedent FROM Cases INNER JOIN Attorneys ON Cases.attorney_id = Attorneys.id WHERE Attorneys.billing_rate = (SELECT MAX(billing_rate) FROM Attorneys);
|
Get the names and certification levels of all the green buildings in the city of Seattle.
|
CREATE TABLE green_buildings (id INT,name VARCHAR(255),location VARCHAR(255),certification_level VARCHAR(50));
|
SELECT name, certification_level FROM green_buildings WHERE location = 'Seattle';
|
What is the average labor cost for construction projects in Canada?
|
CREATE TABLE labor_cost_canada (cost_id INT,country VARCHAR(50),project_type VARCHAR(50),cost FLOAT); INSERT INTO labor_cost_canada (cost_id,country,project_type,cost) VALUES (1,'Canada','Construction',20000);
|
SELECT AVG(cost) FROM labor_cost_canada WHERE country = 'Canada' AND project_type = 'Construction';
|
What is the name of the community development initiative with the highest number of participants in the 'community_development' table?;
|
CREATE TABLE community_development (id INT,initiative_name VARCHAR(50),number_of_participants INT); INSERT INTO community_development VALUES (1,'Youth Skills Training',100),(2,'Women Empowerment',120),(3,'Elderly Care',80),(4,'Environmental Conservation',150),(5,'Cultural Preservation',110);
|
SELECT initiative_name FROM community_development WHERE number_of_participants = (SELECT MAX(number_of_participants) FROM community_development);
|
List transactions from the last 30 days
|
CREATE TABLE transactions (id INT PRIMARY KEY,customer_id INT,amount DECIMAL(10,2),transaction_date DATE); INSERT INTO transactions (id,customer_id,amount,transaction_date) VALUES (1,1,500.00,'2022-01-01'); INSERT INTO transactions (id,customer_id,amount,transaction_date) VALUES (2,2,750.00,'2022-01-02');
|
SELECT * FROM transactions t WHERE t.transaction_date >= CURDATE() - INTERVAL 30 DAY;
|
Insert a new record for a farmer who received training in 'Agroforestry' in the 'Amazon Basin' region in 2022.
|
CREATE TABLE farmers (id INT,name VARCHAR(255),region VARCHAR(255),training_year INT,training_topic VARCHAR(255));
|
INSERT INTO farmers (id, name, region, training_year, training_topic) VALUES (2, 'Marcia Santos', 'Amazon Basin', 2022, 'Agroforestry');
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.