instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the average amount of waste produced daily by the chemical manufacturing plant located in New York in the past year?
CREATE TABLE waste_production (id INT,plant_location VARCHAR(50),production_date DATE,amount_wasted FLOAT);
SELECT AVG(amount_wasted) FROM waste_production WHERE plant_location = 'New York' AND production_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR);
List all vehicle maintenance records for the 'Yellow Line' subway fleet
CREATE TABLE subway_maintenance (vehicle_type VARCHAR(50),last_maintenance DATE); INSERT INTO subway_maintenance (vehicle_type,last_maintenance) VALUES ('Yellow Line','2021-07-01'),('Yellow Line','2021-09-15'),('Green Line','2021-08-20');
SELECT * FROM subway_maintenance WHERE vehicle_type = 'Yellow Line';
Insert a new record for a basketball player named "Sue Bird" into the "players" table
CREATE TABLE players (player_id INT PRIMARY KEY,first_name VARCHAR(50),last_name VARCHAR(50),sport VARCHAR(50),team VARCHAR(50));
INSERT INTO players (player_id, first_name, last_name, sport, team) VALUES (6, 'Sue', 'Bird', 'Basketball', 'Storm');
What was the total quantity of parts produced by each worker in the 'machining' department for January 2021?
CREATE TABLE workers (id INT,name VARCHAR(50),department VARCHAR(50)); INSERT INTO workers (id,name,department) VALUES (1,'John Doe','Machining'),(2,'Jane Smith','Assembly'); CREATE TABLE parts (id INT,worker_id INT,quantity INT,date DATE); INSERT INTO parts (id,worker_id,quantity,date) VALUES (1,1,150,'2021-01-01'),(2,1,160,'2021-01-02'),(3,2,145,'2021-01-01');
SELECT w.name, SUM(p.quantity) as total_quantity FROM workers w JOIN parts p ON w.id = p.worker_id WHERE w.department = 'Machining' AND p.date BETWEEN '2021-01-01' AND '2021-01-31' GROUP BY w.name;
What is the total number of publications by graduate students from historically underrepresented communities?
CREATE TABLE graduate_student_publications (id INT,student_id INT,community VARCHAR(255),num_publications INT); INSERT INTO graduate_student_publications (id,student_id,community,num_publications) VALUES (1,1,'African American',2),(2,2,'Latinx',1),(3,3,'Native American',3),(4,4,'Asian American',1),(5,5,'Latinx',2);
SELECT community, SUM(num_publications) as total_publications FROM graduate_student_publications WHERE community IN ('African American', 'Latinx', 'Native American') GROUP BY community;
What is the total amount of climate finance provided to projects in the Pacific region for climate adaptation by the European Investment Bank?
CREATE TABLE european_investment_bank (fund_id INT,project_name VARCHAR(100),country VARCHAR(50),sector VARCHAR(50),amount FLOAT,climate_adaptation_flag BOOLEAN); INSERT INTO european_investment_bank (fund_id,project_name,country,sector,amount,climate_adaptation_flag) VALUES (1,'Sea Level Rise Protection','Tuvalu','Infrastructure',20000000,TRUE);
SELECT SUM(amount) FROM european_investment_bank WHERE country LIKE '%%pacific%%' AND climate_adaptation_flag = TRUE;
What is the total number of aircraft sales to India in the last 3 years?
CREATE TABLE military_sales (id INT,equipment_type VARCHAR(255),country VARCHAR(255),year INT,total_sales DECIMAL(10,2)); INSERT INTO military_sales (id,equipment_type,country,year,total_sales) VALUES (1,'Aircraft','India',2019,5000000.00),(2,'Ground Vehicle','India',2020,3000000.00);
SELECT SUM(total_sales) FROM military_sales WHERE equipment_type = 'Aircraft' AND country = 'India' AND year BETWEEN (SELECT YEAR(CURRENT_DATE) - 3) AND YEAR(CURRENT_DATE);
What is the total number of electric vehicles by manufacturer, grouped by country, with a count greater than 500?
CREATE TABLE Manufacturers (ManufacturerID INT,ManufacturerName VARCHAR(100),Country VARCHAR(50)); INSERT INTO Manufacturers (ManufacturerID,ManufacturerName,Country) VALUES (1,'Tesla','USA'),(2,'Nissan','Japan'),(3,'BMW','Germany'); CREATE TABLE ElectricVehicles (EVID INT,ManufacturerID INT,Model VARCHAR(50),Year INT); INSERT INTO ElectricVehicles (EVID,ManufacturerID,Model,Year) VALUES (1,1,'Model S',2012),(2,1,'Model 3',2017),(3,2,'Leaf',2010),(4,3,'i3',2013);
SELECT Country, ManufacturerName, COUNT(*) as Total FROM ElectricVehicles EV JOIN Manufacturers M ON EV.ManufacturerID = M.ManufacturerID GROUP BY Country, ManufacturerName HAVING COUNT(*) > 500;
What is the distribution of genetic research data by the type of genetic mutation, for the top 3 countries with the most data, and for each month in the year 2022?
CREATE TABLE genetic_research (id INT PRIMARY KEY,country VARCHAR(255),genetic_mutation VARCHAR(255),data_size INT,research_date DATE);
SELECT EXTRACT(MONTH FROM research_date) AS month, genetic_mutation, SUM(data_size) FROM genetic_research WHERE country IN (SELECT country FROM genetic_research GROUP BY country ORDER BY SUM(data_size) DESC LIMIT 3) AND research_date BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY month, genetic_mutation;
What is the total revenue of skincare products sold in the US in the last month?
CREATE TABLE sales (sale_id INT,product_id INT,sale_date DATE,quantity INT,price DECIMAL(5,2)); CREATE TABLE products (product_id INT,product_name VARCHAR(100),category VARCHAR(50),country VARCHAR(50));
SELECT SUM(sales.quantity * sales.price) FROM sales JOIN products ON sales.product_id = products.product_id WHERE products.category = 'Skincare' AND products.country = 'US' AND sales.sale_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH);
What is the total revenue from sales of sustainable organic cotton garments?
CREATE TABLE garments (item VARCHAR(20),material VARCHAR(20),sustainability VARCHAR(10),price DECIMAL(5,2)); INSERT INTO garments (item,material,sustainability,price) VALUES ('T-Shirt','Organic Cotton','Yes',25.00),('Pants','Organic Cotton','Yes',30.00); CREATE TABLE sales_volume (item VARCHAR(20),quantity INT); INSERT INTO sales_volume (item,quantity) VALUES ('T-Shirt',15),('Pants',20);
SELECT SUM(garments.price * sales_volume.quantity) FROM garments INNER JOIN sales_volume ON garments.item = sales_volume.item WHERE garments.material = 'Organic Cotton' AND sustainability = 'Yes';
What is the distribution of space debris by debris type?
CREATE TABLE space_debris (debris_id INT,name VARCHAR(255),country VARCHAR(255),debris_type VARCHAR(255));
SELECT debris_type, COUNT(*) as total_debris FROM space_debris GROUP BY debris_type;
What is the percentage of organic produce in 'HealthyHarvest'?
CREATE TABLE Products (id INT,is_organic BOOLEAN,name VARCHAR(255)); INSERT INTO Products (id,is_organic,name) VALUES (1,true,'Broccoli'),(2,true,'Carrots'),(3,false,'Potatoes'),(4,true,'Cauliflower'),(5,false,'Onions'),(6,true,'Garlic'); CREATE TABLE MarketProducts (market_id INT,product_id INT); INSERT INTO MarketProducts (market_id,product_id) VALUES (1,1),(1,2),(1,4),(1,5),(1,6);
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM MarketProducts WHERE market_id = 1)) AS percentage FROM Products WHERE is_organic = true AND id IN (SELECT product_id FROM MarketProducts WHERE market_id = 1);
What is the average data usage per mobile user in the Philippines, partitioned by age group?
CREATE TABLE mobile_users (user_id INT,age INT,data_usage FLOAT,country VARCHAR(20)); INSERT INTO mobile_users (user_id,age,data_usage,country) VALUES (1,23,2.5,'Philippines'); INSERT INTO mobile_users (user_id,age,data_usage,country) VALUES (2,31,3.2,'Philippines');
SELECT age_group, AVG(data_usage) FROM (SELECT age, data_usage, FLOOR(age/10)*10 AS age_group FROM mobile_users WHERE country = 'Philippines') subquery GROUP BY age_group;
Which community development initiatives have budget allocations between 75000 and 125000 in the 'community_development_2' table?
CREATE TABLE community_development_2 (id INT,initiative_name VARCHAR(50),budget DECIMAL(10,2)); INSERT INTO community_development_2 (id,initiative_name,budget) VALUES (1,'Clean Water Initiative',50000.00),(2,'Renewable Energy',75000.00),(3,'Waste Management',45000.00),(4,'Affordable Housing',110000.00);
SELECT initiative_name, budget FROM community_development_2 WHERE budget BETWEEN 75000 AND 125000;
What is the distribution of policy types across different regions?
CREATE TABLE Policies (PolicyID int,PolicyType varchar(20),SaleRegion varchar(20)); INSERT INTO Policies (PolicyID,PolicyType,SaleRegion) VALUES (1,'Auto','West'),(2,'Home','East'),(3,'Auto','West'),(4,'Life','Midwest');
SELECT PolicyType, SaleRegion, COUNT(*) OVER (PARTITION BY PolicyType, SaleRegion) as PolicyCount FROM Policies;
What is the minimum fare for each mode of transportation?
CREATE TABLE modes (mode_id INT,mode_name VARCHAR(255)); CREATE TABLE fares (fare_id INT,mode_id INT,fare_amount DECIMAL(5,2)); INSERT INTO modes VALUES (1,'Bus'); INSERT INTO modes VALUES (2,'Train'); INSERT INTO fares VALUES (1,1,2.50); INSERT INTO fares VALUES (2,1,3.00); INSERT INTO fares VALUES (3,2,1.75);
SELECT mode_name, MIN(fare_amount) as min_fare FROM modes m JOIN fares f ON m.mode_id = f.mode_id GROUP BY m.mode_name;
Identify companies that received funding in the range of $500,000 to $1,000,000, ordered by founding year.
CREATE TABLE companies(id INT,name VARCHAR(50),founding_year INT,industry VARCHAR(20),funding FLOAT); INSERT INTO companies(id,name,founding_year,industry,funding) VALUES (1,'CompanyA',2010,'Tech',750000); INSERT INTO companies(id,name,founding_year,industry,funding) VALUES (2,'CompanyB',2015,'Healthcare',1500000); INSERT INTO companies(id,name,founding_year,industry,funding) VALUES (3,'CompanyC',2012,'Finance',500000); INSERT INTO companies(id,name,founding_year,industry,funding) VALUES (4,'CompanyD',2017,'Retail',2000000);
SELECT name, founding_year FROM companies WHERE funding BETWEEN 500000 AND 1000000 ORDER BY founding_year;
What is the total revenue for each product category sold at every dispensary in Oregon in 2021?
CREATE TABLE Dispensaries (id INT,name TEXT,state TEXT); CREATE TABLE Sales (dispid INT,date DATE,product_category TEXT,revenue DECIMAL(10,2)); INSERT INTO Dispensaries (id,name,state) VALUES (1,'Dispensary A','Oregon'); INSERT INTO Dispensaries (id,name,state) VALUES (2,'Dispensary B','Oregon'); INSERT INTO Sales (dispid,date,product_category,revenue) VALUES (1,'2021-01-01','Flower',500); INSERT INTO Sales (dispid,date,product_category,revenue) VALUES (1,'2021-01-02','Flower',600); INSERT INTO Sales (dispid,date,product_category,revenue) VALUES (2,'2021-01-01','Concentrate',300);
SELECT d.name, s.product_category, SUM(s.revenue) as total_revenue FROM Dispensaries d JOIN Sales s ON d.id = s.dispid WHERE d.state = 'Oregon' AND YEAR(s.date) = 2021 GROUP BY d.name, s.product_category;
Find the total water usage for residential purposes in 'July 2021' from the 'water_usage' table
CREATE TABLE water_usage (id INT,usage FLOAT,purpose VARCHAR(20),date DATE); INSERT INTO water_usage (id,usage,purpose,date) VALUES (1,150,'residential','2021-07-01'); INSERT INTO water_usage (id,usage,purpose,date) VALUES (2,120,'industrial','2021-07-01');
SELECT SUM(usage) FROM water_usage WHERE purpose = 'residential' AND date = '2021-07-01';
Which restaurants in the 'fine_dining' schema have a health score above 90?
CREATE TABLE fine_dining.restaurants (restaurant_id INT,name TEXT,health_score INT); INSERT INTO fine_dining.restaurants (restaurant_id,name,health_score) VALUES (1,'The Classy Spoon',95),(2,'Gourmet Delights',88);
SELECT * FROM fine_dining.restaurants WHERE health_score > 90;
Create a table for storing electric vehicle (EV) data
CREATE TABLE ev_sales (id INT PRIMARY KEY,model VARCHAR(100),manufacturer VARCHAR(100),year INT,total_sales INT);
CREATE TABLE ev_data (id INT PRIMARY KEY, model VARCHAR(100), manufacturer VARCHAR(100), year INT, total_sales INT);
What's the total revenue for music artists from the USA?
CREATE TABLE Artists (id INT,name VARCHAR(100),country VARCHAR(50),revenue FLOAT);
SELECT SUM(revenue) FROM Artists WHERE country = 'USA';
What is the average life expectancy in each region of South Asia?
CREATE TABLE south_asia_regions (id INT,name VARCHAR(255)); CREATE TABLE life_expectancy (id INT,region_id INT,expectancy DECIMAL(5,2)); INSERT INTO south_asia_regions (id,name) VALUES (1,'South Asia West'),(2,'South Asia Central'),(3,'South Asia East'),(4,'South Asia South');
SELECT r.name, AVG(le.expectancy) FROM life_expectancy le JOIN south_asia_regions r ON le.region_id = r.id GROUP BY r.name;
Which countries have made the least progress in climate adaptation in the last 5 years?
CREATE TABLE least_progress (country TEXT,year INT,progress FLOAT); INSERT INTO least_progress (country,year,progress) VALUES ('Argentina',2017,0.2);
SELECT country, MIN(progress) FROM least_progress WHERE year BETWEEN 2016 AND 2021 GROUP BY country ORDER BY progress ASC;
Identify buildings with the lowest sustainability ratings
CREATE TABLE green_buildings (id INT,name VARCHAR(50),location VARCHAR(50),area FLOAT,sustainability_rating INT);
SELECT name FROM green_buildings WHERE sustainability_rating = (SELECT MIN(sustainability_rating) FROM green_buildings);
Add new records of intelligence operations in a specific year to the "intelligence_ops" table
CREATE TABLE intelligence_ops (id INT,year INT,location VARCHAR(255),type VARCHAR(255),result VARCHAR(255));
INSERT INTO intelligence_ops (id, year, location, type, result) VALUES (1, 2015, 'Russia', 'Surveillance', 'Success'), (2, 2015, 'Germany', 'Infiltration', 'Failure');
List the artworks in the 'art_collection' table, ordered by the artist's name.
CREATE TABLE art_collection (artwork_id INT,name VARCHAR(50),artist VARCHAR(50),year INT,medium VARCHAR(50));
SELECT * FROM art_collection ORDER BY artist;
What is the total number of students who participated in lifelong learning programs in 'Suburb B' and 'City C'?
CREATE TABLE SuburbBLifelong (studentID INT,suburb VARCHAR(50),program VARCHAR(50)); INSERT INTO SuburbBLifelong (studentID,suburb,program) VALUES (1,'Suburb B','lifelong learning'),(2,'City C','lifelong learning'); CREATE TABLE CityCLifelong (studentID INT,city VARCHAR(50),program VARCHAR(50)); INSERT INTO CityCLifelong (studentID,city,program) VALUES (3,'City C','lifelong learning');
SELECT COUNT(DISTINCT studentID) FROM SuburbBLifelong WHERE suburb IN ('Suburb B', 'City C') AND program = 'lifelong learning' UNION ALL SELECT COUNT(DISTINCT studentID) FROM CityCLifelong WHERE city IN ('Suburb B', 'City C') AND program = 'lifelong learning';
What is the average population density in census tracts for each state, ordered from highest to lowest?
CREATE SCHEMA RuralHealth; USE RuralHealth; CREATE TABLE CensusTracts (TractID INT,TractPopulation INT,TractArea FLOAT,StateAbbreviation VARCHAR(10)); INSERT INTO CensusTracts (TractID,TractPopulation,TractArea,StateAbbreviation) VALUES (1,500,10.5,'AL'),(2,1500,34.2,'AK');
SELECT StateAbbreviation, AVG(TractPopulation / TractArea) as AvgPopulationDensity FROM CensusTracts GROUP BY StateAbbreviation ORDER BY AvgPopulationDensity DESC;
What is the average landfill capacity in Asia in 2020?'
CREATE TABLE landfills (country VARCHAR(50),capacity INT,year INT); INSERT INTO landfills (country,capacity,year) VALUES ('China',25000,2020),('India',18000,2020),('Indonesia',12000,2020),('Japan',15000,2020),('Pakistan',10000,2020);
SELECT AVG(capacity) as avg_capacity FROM landfills WHERE year = 2020 AND country IN ('China', 'India', 'Indonesia', 'Japan', 'Pakistan');
What is the total spending on education and healthcare services for indigenous communities in Mexico, Brazil, and Canada in 2021?
CREATE TABLE Spending (Country VARCHAR(50),Service VARCHAR(50),Year INT,Amount DECIMAL(10,2)); INSERT INTO Spending (Country,Service,Year,Amount) VALUES ('Mexico','Education',2021,5000.00),('Mexico','Healthcare',2021,8000.00),('Brazil','Education',2021,7000.00),('Brazil','Healthcare',2021,10000.00),('Canada','Education',2021,9000.00),('Canada','Healthcare',2021,12000.00);
SELECT Country, SUM(Amount) as TotalSpending FROM Spending WHERE Service IN ('Education', 'Healthcare') AND Year = 2021 AND Country IN ('Mexico', 'Brazil', 'Canada') GROUP BY Country;
What is the total revenue for each event by state in the 'concerts' and 'fans' tables?
CREATE TABLE concerts (event_id INT,event_name VARCHAR(50),location VARCHAR(50),date DATE,ticket_price DECIMAL(5,2),num_tickets INT,city VARCHAR(50)); CREATE TABLE fans (fan_id INT,fan_name VARCHAR(50),age INT,city VARCHAR(50),state VARCHAR(50),country VARCHAR(50));
SELECT event_name, state, SUM(ticket_price * num_tickets) as total_revenue FROM concerts c JOIN fans f ON c.city = f.city GROUP BY event_name, state;
What is the ranking of each city based on its total population, and what is the annual rainfall for each city?
CREATE TABLE City (Id INT,Name VARCHAR(50),Population INT,AnnualRainfall DECIMAL(5,2)); INSERT INTO City (Id,Name,Population,AnnualRainfall) VALUES (1,'Tokyo',9000000,60.5),(2,'Delhi',3000000,55.3),(3,'Shanghai',25000000,62.4),(4,'Sao Paulo',12000000,120.0);
SELECT Name, Population, AnnualRainfall, ROW_NUMBER() OVER (ORDER BY Population DESC) AS CityRank FROM City;
What is the total number of building permits issued in the state of New York and Texas combined?
CREATE TABLE Building_Permits (state TEXT,permits_issued INTEGER); INSERT INTO Building_Permits (state,permits_issued) VALUES ('New York',1500),('Texas',2000),('California',1200);
SELECT SUM(permits_issued) FROM Building_Permits WHERE state IN ('New York', 'Texas');
How many artworks were exhibited in Spain between 1850 and 1900?
CREATE TABLE Artworks (artwork_id INT,title VARCHAR(50),year_made INT,artist_id INT,price FLOAT); INSERT INTO Artworks (artwork_id,title,year_made,artist_id,price) VALUES (1,'The Card Players',1892,1,3000.0); CREATE TABLE Exhibitions (exhibition_id INT,exhibition_name VARCHAR(50),start_date DATE,end_date DATE,artwork_id INT); INSERT INTO Exhibitions (exhibition_id,exhibition_name,start_date,end_date,artwork_id) VALUES (1,'Art Exhibition','1900-01-01','1900-12-31',1);
SELECT COUNT(*) FROM Exhibitions WHERE Exhibitions.start_date BETWEEN '1850-01-01' AND '1900-12-31' AND Exhibitions.country = 'Spain';
How many construction laborers were employed in the state of New York in 2020?
CREATE TABLE Labor_Statistics (id INT,employee_count INT,year INT,state VARCHAR(20)); INSERT INTO Labor_Statistics (id,employee_count,year,state) VALUES (1,10000,2020,'New York');
SELECT SUM(employee_count) FROM Labor_Statistics WHERE year = 2020 AND state = 'New York';
Find the top 3 most expensive electric taxi rides by ride_distance.
CREATE TABLE taxi_trips (ride_id INT,ride_start_time TIMESTAMP,ride_end_time TIMESTAMP,ride_distance FLOAT,fare FLOAT,vehicle_type VARCHAR(10));
SELECT ride_id, ride_distance, fare FROM (SELECT ride_id, ride_distance, fare, ROW_NUMBER() OVER (PARTITION BY vehicle_type ORDER BY ride_distance DESC, fare DESC) AS rank FROM taxi_trips WHERE vehicle_type = 'Electric Taxi') AS subquery WHERE rank <= 3;
Identify the total number of transactions and total sales for each designer, in descending order by total sales.
CREATE TABLE Designers (DesignerID INT,DesignerName VARCHAR(50)); INSERT INTO Designers VALUES (1,'DesignerA'),(2,'DesignerB'),(3,'DesignerC'); CREATE TABLE Transactions (TransactionID INT,DesignerID INT,Quantity INT,Sales DECIMAL(10,2)); INSERT INTO Transactions VALUES (1,1,50,1000),(2,1,75,1500),(3,2,30,750),(4,3,60,1800);
SELECT DesignerName, SUM(Quantity) AS Total_Quantity, SUM(Sales) AS Total_Sales, ROW_NUMBER() OVER (ORDER BY SUM(Sales) DESC) AS Rank FROM Designers JOIN Transactions ON Designers.DesignerID = Transactions.DesignerID GROUP BY DesignerName ORDER BY Rank;
What are the names of all artists who have created artworks in the 'expressionism' movement?
CREATE TABLE Artists (artist_id INT,name TEXT); INSERT INTO Artists (artist_id,name) VALUES (1,'Edvard Munch'),(2,'Vincent Van Gogh'); CREATE TABLE Artworks (artwork_id INT,title TEXT,creation_year INT,art_movement TEXT,artist_id INT); INSERT INTO Artworks (artwork_id,title,creation_year,art_movement,artist_id) VALUES (1,'The Scream',1893,'Expressionism',1),(2,'The Starry Night',1889,'Post-Impressionism',2);
SELECT Artists.name FROM Artists INNER JOIN Artworks ON Artists.artist_id = Artworks.artist_id WHERE Artworks.art_movement = 'Expressionism' GROUP BY Artists.name;
What is the total number of members in unions based in the US and Canada, excluding any duplicate entries?
CREATE TABLE union_membership (id INT,name VARCHAR(255),country VARCHAR(255)); INSERT INTO union_membership (id,name,country) VALUES (1,'Union A','USA'),(2,'Union B','Canada'),(3,'Union C','USA'),(4,'Union D','Canada');
SELECT COUNT(DISTINCT name) FROM union_membership WHERE country IN ('USA', 'Canada')
Update the court for precedent 'Brown v. Board of Education' to 'Supreme Court' in the 'precedents' table
CREATE TABLE precedents (precedent_id INT PRIMARY KEY,precedent_name VARCHAR(50),year DECIMAL(4,0),court VARCHAR(50)); INSERT INTO precedents (precedent_id,precedent_name,year,court) VALUES (1,'Brown v. Board of Education',1954,'District Court'),(2,'Miranda v. Arizona',1966,'Supreme Court');
UPDATE precedents SET court = 'Supreme Court' WHERE precedent_name = 'Brown v. Board of Education';
How many fish are there in each cage at the Indian fish farm 'Farm D'?
CREATE TABLE fish_cages (id INT,farm_id INT,cage_number INT,fish_count INT); INSERT INTO fish_cages (id,farm_id,cage_number,fish_count) VALUES (1,4,1,1500); INSERT INTO fish_cages (id,farm_id,cage_number,fish_count) VALUES (2,4,2,2500); INSERT INTO fish_cages (id,farm_id,cage_number,fish_count) VALUES (3,4,3,3500);
SELECT cage_number, fish_count FROM fish_cages WHERE farm_id = (SELECT id FROM salmon_farms WHERE name = 'Farm D' AND country = 'India' LIMIT 1);
What is the maximum temperature change in Africa and minimum temperature change in Australia over the last 10 years?
CREATE TABLE weather_global (country VARCHAR(20),year INT,temperature DECIMAL(5,2)); INSERT INTO weather_global VALUES ('AF',2010,10.5),('AF',2011,11.2),('AF',2012,12.1),('AU',2010,8.7),('AU',2011,8.9),('AU',2012,9.3);
SELECT MAX(CASE WHEN country = 'AF' THEN temperature END) AS max_temp_change_AF, MIN(CASE WHEN country = 'AU' THEN temperature END) AS min_temp_change_AU FROM (SELECT ROW_NUMBER() OVER (PARTITION BY country ORDER BY year DESC) rn, country, temperature FROM weather_global WHERE year >= 2010) t WHERE rn <= 10;
What is the maximum CO2 emission of fossil fuel vehicles in Brazil?
CREATE TABLE Fossil_Fuel_Vehicles_Brazil (Id INT,Vehicle VARCHAR(50),CO2_Emission DECIMAL(5,2)); INSERT INTO Fossil_Fuel_Vehicles_Brazil (Id,Vehicle,CO2_Emission) VALUES (1,'Chevrolet Onix',135.0),(2,'Ford Ka',140.0),(3,'Volkswagen Gol',145.0);
SELECT MAX(CO2_Emission) FROM Fossil_Fuel_Vehicles_Brazil;
List all legal technology patents that were filed in the US, Canada, or Mexico in the last 5 years.
CREATE TABLE LegalPatents (Id INT,Country VARCHAR(50),FilingDate DATE); INSERT INTO LegalPatents (Id,Country,FilingDate) VALUES (1,'USA','2020-01-01'),(2,'Canada','2021-05-15'),(3,'Mexico','2019-12-31');
SELECT Country FROM LegalPatents WHERE FilingDate >= DATEADD(year, -5, GETDATE()) AND Country IN ('USA', 'Canada', 'Mexico') ORDER BY Country;
What is the maximum cost of building permits issued in 'New York' in 2019?
CREATE TABLE building_permits (id INT,permit_number TEXT,location TEXT,cost INT,issue_date DATE); INSERT INTO building_permits (id,permit_number,location,cost,issue_date) VALUES (1,'NY-1234','New York',500000,'2019-03-01'); INSERT INTO building_permits (id,permit_number,location,cost,issue_date) VALUES (2,'NY-5678','New York',700000,'2019-11-15');
SELECT MAX(cost) FROM building_permits WHERE location = 'New York' AND YEAR(issue_date) = 2019;
What is the total funding received by female founders in the tech industry?
CREATE TABLE founders(id INT,name VARCHAR(50),gender VARCHAR(10),industry VARCHAR(20)); INSERT INTO founders VALUES (1,'Alice','Female','Tech'); INSERT INTO founders VALUES (2,'Bob','Male','Finance'); CREATE TABLE funding(id INT,founder_id INT,amount INT); INSERT INTO funding VALUES (1,1,500000); INSERT INTO funding VALUES (2,1,750000);
SELECT SUM(funding.amount) FROM founders INNER JOIN funding ON founders.id = funding.founder_id WHERE founders.gender = 'Female' AND founders.industry = 'Tech';
What is the total number of restorative justice programs in the justice_schemas.restorative_programs table, categorized by the type of program?
CREATE TABLE justice_schemas.restorative_programs (id INT PRIMARY KEY,program_name TEXT,program_type TEXT);
SELECT program_type, COUNT(*) FROM justice_schemas.restorative_programs GROUP BY program_type;
What is the average energy consumption per machine, per day, for the past week?
CREATE TABLE EnergyConsumption (Machine VARCHAR(50),Energy INT,Timestamp DATETIME); INSERT INTO EnergyConsumption (Machine,Energy,Timestamp) VALUES ('MachineA',1000,'2022-02-01 00:00:00'),('MachineB',1200,'2022-02-01 00:00:00');
SELECT Machine, AVG(Energy) OVER (PARTITION BY Machine ORDER BY Timestamp ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) FROM EnergyConsumption WHERE Timestamp >= DATEADD(day, -7, CURRENT_TIMESTAMP)
What are the quartiles for sustainable fashion metrics values across all categories?
CREATE TABLE sustainable_fashion_metrics (id INT PRIMARY KEY,metric VARCHAR(255),value INT,category VARCHAR(255),metric_date DATE);
SELECT metric, value, NTILE(4) OVER (ORDER BY value DESC) as quartile FROM sustainable_fashion_metrics;
What is the total funding for genetic research projects in Australia?
CREATE SCHEMA if not exists funding; USE funding; CREATE TABLE if not exists research_funding (id INT,project_id INT,country VARCHAR(255),funding DECIMAL(10,2)); INSERT INTO research_funding (id,project_id,country,funding) VALUES (1,1,'Australia',7000000.00),(2,2,'Canada',6000000.00),(3,3,'Australia',8000000.00),(4,4,'Canada',9000000.00);
SELECT SUM(funding) FROM funding.research_funding WHERE country = 'Australia';
What is the maximum retail price of cruelty-free nail polishes?
CREATE TABLE Nail_Polish (ProductID int,ProductName varchar(100),Price decimal(5,2),CrueltyFree bit); INSERT INTO Nail_Polish (ProductID,ProductName,Price,CrueltyFree) VALUES (1,'Cruelty-free Red Nail Polish',9.99,1); INSERT INTO Nail_Polish (ProductID,ProductName,Price,CrueltyFree) VALUES (2,'Classic Nail Polish',7.50,0);
SELECT MAX(Price) FROM Nail_Polish WHERE CrueltyFree = 1;
Find the species with the least number of animals in the 'animal_population' table and the corresponding number of preservation efforts for the same species in the 'habitat_preservation' table.
CREATE TABLE animal_population (id INT,species VARCHAR(20),population INT); INSERT INTO animal_population (id,species,population) VALUES (1,'tiger',500),(2,'elephant',300); CREATE TABLE habitat_preservation (id INT,species VARCHAR(20),efforts INT); INSERT INTO habitat_preservation (id,species,efforts) VALUES (1,'tiger',100),(2,'elephant',150);
SELECT species, population, efforts FROM animal_population INNER JOIN habitat_preservation ON animal_population.species = habitat_preservation.species WHERE population = (SELECT MIN(population) FROM animal_population);
What is the average age of athletes who participated in the 2020 Olympics?
CREATE TABLE athletes (id INT,name VARCHAR(100),age INT,sport VARCHAR(50),olympics BOOLEAN); INSERT INTO athletes (id,name,age,sport,olympics) VALUES (1,'John Doe',30,'Athletics',true),(2,'Jane Smith',25,'Gymnastics',true);
SELECT AVG(age) FROM athletes WHERE olympics = true;
What is the total number of publications by graduate students in the year 2019?
CREATE TABLE publications (id INT,author VARCHAR(50),year INT,journal VARCHAR(50)); INSERT INTO publications (id,author,year,journal) VALUES (1,'Alice',2019,'Journal of Computer Science'),(2,'Bob',2018,'Journal of Physics'),(3,'Eve',2019,'Journal of Mathematics');
SELECT COUNT(*) FROM publications WHERE year = 2019 AND author IN (SELECT name FROM students WHERE graduate_student = 'Yes');
How many defense projects were delayed in the Asia-Pacific region in 2020?
CREATE TABLE DefenseProjects (id INT,project_name VARCHAR(100),region VARCHAR(50),start_date DATE,end_date DATE); INSERT INTO DefenseProjects (id,project_name,region,start_date,end_date) VALUES (1,'Project A','Asia-Pacific','2019-01-01','2020-12-31'); INSERT INTO DefenseProjects (id,project_name,region,start_date,end_date) VALUES (2,'Project B','Asia-Pacific','2020-01-01','2021-06-30'); INSERT INTO DefenseProjects (id,project_name,region,start_date,end_date) VALUES (3,'Project C','Asia-Pacific','2021-01-01','2022-12-31');
SELECT COUNT(*) FROM DefenseProjects WHERE region = 'Asia-Pacific' AND end_date > start_date + INTERVAL 1 YEAR;
What is the total number of employees hired in the South Asia region in 2022, grouped by gender?
CREATE TABLE employees (id INT,first_name VARCHAR(50),last_name VARCHAR(50),hire_date DATE,gender VARCHAR(50),country VARCHAR(50)); INSERT INTO employees (id,first_name,last_name,hire_date,gender,country) VALUES (7,'Aarav','Singh','2022-02-15','Male','India');
SELECT e.gender, COUNT(e.id) as total_hired FROM employees e WHERE e.hire_date >= '2022-01-01' AND e.hire_date < '2023-01-01' AND e.country IN (SELECT region FROM regions WHERE region_name = 'South Asia') GROUP BY e.gender;
What is the minimum water usage in a single day in Brazil in 2019?
CREATE TABLE daily_water_usage(country VARCHAR(50),year INT,day INT,volume FLOAT); INSERT INTO daily_water_usage(country,year,day,volume) VALUES ('Brazil',2019,1,4.58),('Brazil',2019,2,4.61),('Brazil',2019,3,4.64);
SELECT MIN(volume) FROM daily_water_usage WHERE country = 'Brazil' AND year = 2019;
What is the total volume of water consumed by the domestic sector in the state of New York in 2019?
CREATE TABLE Water_Usage (Year INT,Sector VARCHAR(20),Volume INT); INSERT INTO Water_Usage (Year,Sector,Volume) VALUES (2019,'Domestic',12300000),(2018,'Domestic',12000000),(2020,'Domestic',12500000);
SELECT SUM(Volume) FROM Water_Usage WHERE Year = 2019 AND Sector = 'Domestic';
Show the names and positions of employees in the Engineering department who earn a salary above the average salary for the department.
CREATE TABLE Employees (EmployeeID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Position VARCHAR(50),Department VARCHAR(50),Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID,FirstName,LastName,Position,Department,Salary) VALUES (1,'John','Doe','Manager','Manufacturing',75000.00); INSERT INTO Employees (EmployeeID,FirstName,LastName,Position,Department,Salary) VALUES (2,'Jane','Doe','Engineer','Engineering',65000.00); INSERT INTO Employees (EmployeeID,FirstName,LastName,Position,Department,Salary) VALUES (3,'Bob','Smith','Engineer','Engineering',70000.00);
SELECT FirstName, LastName, Position FROM Employees WHERE Department = 'Engineering' AND Salary > (SELECT AVG(Salary) FROM Employees WHERE Department = 'Engineering');
What is the average number of families assisted per day by each community center in Q3 of 2021?
CREATE TABLE Community_Centers (cc_name TEXT,families_assisted INTEGER,assist_date DATE); INSERT INTO Community_Centers (cc_name,families_assisted,assist_date) VALUES ('Center A',10,'2021-07-04'); INSERT INTO Community_Centers (cc_name,families_assisted,assist_date) VALUES ('Center B',15,'2021-08-18');
SELECT cc_name, AVG(families_assisted/DATEDIFF('2021-10-01', assist_date)) FROM Community_Centers WHERE assist_date BETWEEN '2021-07-01' AND '2021-09-30' GROUP BY cc_name;
What is the total sales revenue of each product category in the top 3 African regions for 2022?
CREATE TABLE sales_data_4 (sale_id INT,product_category VARCHAR(255),region VARCHAR(255),sale_quantity INT,sale_revenue DECIMAL(10,2),sale_year INT);
SELECT a.product_category, a.region, SUM(a.sale_revenue) AS total_sales_revenue FROM sales_data_4 a JOIN (SELECT region, SUM(sale_revenue) AS total_sale_revenue FROM sales_data_4 WHERE sale_year = 2022 GROUP BY region ORDER BY total_sale_revenue DESC LIMIT 3) b ON a.region = b.region WHERE a.sale_year = 2022 GROUP BY a.product_category, a.region;
What is the average time spent on ice by each defenseman in the 2021-2022 NHL season?
CREATE TABLE nhl_season (player_id INT,player_name VARCHAR(50),team_id INT,team_name VARCHAR(50),position VARCHAR(50),games_played INT,time_on_ice INT); INSERT INTO nhl_season (player_id,player_name,team_id,team_name,position,games_played,time_on_ice) VALUES (1,'Victor Hedman',1,'Tampa Bay Lightning','D',82,2000);
SELECT player_name, AVG(time_on_ice) as avg_time FROM nhl_season WHERE position = 'D' GROUP BY player_name;
How many circular supply chain products were sold last month?
CREATE TABLE products (product_id INT,name VARCHAR(255),circular_supply_chain BOOLEAN); INSERT INTO products (product_id,name,circular_supply_chain) VALUES (1,'Refurbished Phone',TRUE),(2,'Vintage Dress',FALSE); CREATE TABLE sales (sale_id INT,product_id INT,sale_date DATE); INSERT INTO sales (sale_id,product_id,sale_date) VALUES (1,1,'2022-02-05'),(2,2,'2022-03-10');
SELECT COUNT(*) FROM products JOIN sales ON products.product_id = sales.product_id WHERE circular_supply_chain = TRUE AND sale_date BETWEEN '2022-02-01' AND '2022-02-28';
Calculate the average production of Neodymium in 2020
CREATE TABLE production_neodymium (year INT,quantity INT); INSERT INTO production_neodymium (year,quantity) VALUES (2015,1200),(2016,1400),(2017,1800),(2018,2000),(2019,2200),(2020,2500),(2021,2800);
SELECT AVG(quantity) FROM production_neodymium WHERE year = 2020;
What is the carbon price in Japanese Yen for each country that has a carbon pricing mechanism?
CREATE TABLE Carbon_Pricing (Country VARCHAR(20),Currency VARCHAR(20),Price DECIMAL(10,2)); INSERT INTO Carbon_Pricing VALUES ('Japan','JPY',3000),('Canada','CAD',20),('Sweden','SEK',40);
SELECT Country, Price * (SELECT AVG(Exchange_Rate) FROM Exchange_Rates WHERE Currency_Code = Carbon_Pricing.Currency) AS Price_In_JPY FROM Carbon_Pricing;
What is the total revenue for each textile supplier this year?
CREATE TABLE supplier_revenue (id INT,supplier TEXT,revenue FLOAT,date DATE);
SELECT supplier, SUM(revenue) FROM supplier_revenue WHERE YEAR(date) = YEAR(CURDATE()) GROUP BY supplier;
Update the weight of the 'Elephant' in the 'Forest' habitat to 5500.0.
CREATE TABLE animals (id INT,animal_name VARCHAR(255),habitat_type VARCHAR(255),weight DECIMAL(5,2)); INSERT INTO animals (id,animal_name,habitat_type,weight) VALUES (1,'Lion','Savannah',190.0),(2,'Elephant','Forest',6000.0),(3,'Hippo','Wetlands',3300.0),(4,'Giraffe','Savannah',1600.0),(5,'Duck','Wetlands',15.0),(6,'Bear','Mountains',300.0);
UPDATE animals SET weight = 5500.0 WHERE animal_name = 'Elephant' AND habitat_type = 'Forest';
What is the total number of transactions and their average value for each digital asset in the 'ethereum' network?
CREATE TABLE digital_assets (asset_id INT,asset_name VARCHAR(255),network VARCHAR(255)); INSERT INTO digital_assets (asset_id,asset_name,network) VALUES (1,'ETH','ethereum'),(2,'USDC','ethereum'),(3,'UNI','ethereum'); CREATE TABLE transactions (transaction_id INT,asset_id INT,value DECIMAL(10,2)); INSERT INTO transactions (transaction_id,asset_id,value) VALUES (1,1,100),(2,1,200),(3,2,50),(4,2,75),(5,3,300),(6,3,400);
SELECT d.asset_name, COUNT(t.transaction_id) as total_transactions, AVG(t.value) as average_value FROM digital_assets d JOIN transactions t ON d.asset_id = t.asset_id WHERE d.network = 'ethereum' GROUP BY d.asset_name;
What is the percentage of patients who improved after therapy sessions in Nigeria?
CREATE TABLE patients (patient_id INT,country VARCHAR(50)); INSERT INTO patients (patient_id,country) VALUES (1,'Nigeria'),(2,'Nigeria'),(3,'USA'),(4,'Nigeria'); CREATE TABLE therapy_sessions (patient_id INT,session_count INT,improvement BOOLEAN); INSERT INTO therapy_sessions (patient_id,session_count,improvement) VALUES (1,5,TRUE),(2,3,TRUE),(3,4,FALSE),(4,6,TRUE);
SELECT AVG(CASE WHEN therapy_sessions.improvement = TRUE THEN 1.0 ELSE 0.0 END) * 100.0 / COUNT(DISTINCT patients.patient_id) AS percentage FROM patients INNER JOIN therapy_sessions ON patients.patient_id = therapy_sessions.patient_id WHERE patients.country = 'Nigeria';
What is the maximum number of peacekeeping operations conducted by the African Union in a single year?
CREATE SCHEMA if not exists defense; CREATE TABLE if not exists au_peacekeeping_operations (id INT PRIMARY KEY,year INT,operation_count INT); INSERT INTO au_peacekeeping_operations (id,year,operation_count) VALUES (1,2018,5),(2,2019,7),(3,2020,10),(4,2021,12);
SELECT MAX(operation_count) FROM defense.au_peacekeeping_operations;
Update records in the "workplace_safety" table by increasing the "total_incidents" column by 1 for the row where the "facility_id" is 42
CREATE TABLE workplace_safety (facility_id INT,total_incidents INT); INSERT INTO workplace_safety (facility_id,total_incidents) VALUES (42,5); INSERT INTO workplace_safety (facility_id,total_incidents) VALUES (43,3);
UPDATE workplace_safety SET total_incidents = total_incidents + 1 WHERE facility_id = 42;
Identify the factory with the highest number of labor rights violations in Asia.
CREATE TABLE labor_violations (id INT,factory VARCHAR(100),country VARCHAR(50),violations INT); INSERT INTO labor_violations (id,factory,country,violations) VALUES (1,'Blue Factory','Indonesia',15),(2,'Green Factory','Cambodia',20),(3,'Red Factory','Vietnam',25);
SELECT factory, SUM(violations) as total_violations FROM labor_violations WHERE country = 'Asia' GROUP BY factory ORDER BY total_violations DESC LIMIT 1;
What is the maximum salary in the "tech_company" database for data analysts?
CREATE TABLE employees (id INT,name VARCHAR(50),department VARCHAR(50),salary DECIMAL(10,2)); INSERT INTO employees (id,name,department,salary) VALUES (1,'John Doe','Software Engineer',150000.00),(2,'Jane Smith','Data Analyst',120000.00),(3,'Bob Brown','Data Analyst',130000.00);
SELECT MAX(salary) FROM employees WHERE department = 'Data Analyst';
Delete all artworks created by 'Male Hispanic' artists
CREATE TABLE Artists (id INT,artist_name VARCHAR(255),gender VARCHAR(10),ethnicity VARCHAR(255)); CREATE TABLE Artworks (id INT,artist_id INT,artwork_name VARCHAR(255),year_created INT); INSERT INTO Artists (id,artist_name,gender,ethnicity) VALUES (1,'José Clemente Orozco','Male','Hispanic'); INSERT INTO Artworks (id,artist_id,artwork_name,year_created) VALUES (1,1,'La Cordobesa',1927); INSERT INTO Artists (id,artist_name,gender,ethnicity) VALUES (2,'Diego Rivera','Male','Hispanic'); INSERT INTO Artworks (id,artist_id,artwork_name,year_created) VALUES (2,2,'Dream of a Sunday Afternoon in Alameda Park',1947);
DELETE A FROM Artworks A INNER JOIN Artists B ON A.artist_id = B.id WHERE B.gender = 'Male' AND B.ethnicity = 'Hispanic'; DELETE FROM Artists WHERE gender = 'Male' AND ethnicity = 'Hispanic';
What is the total waste generation for each sector in Q1 2021?
CREATE TABLE waste_generation (id INT,sector VARCHAR(50),generation_kg INT,date DATE); INSERT INTO waste_generation (id,sector,generation_kg,date) VALUES (1,'Industrial',2500,'2021-01-01'),(2,'Commercial',1800,'2021-01-01'),(3,'Residential',1200,'2021-01-01'),(4,'Industrial',2300,'2021-02-01'),(5,'Commercial',1600,'2021-02-01'),(6,'Residential',1100,'2021-02-01'),(7,'Industrial',2700,'2021-03-01'),(8,'Commercial',1900,'2021-03-01'),(9,'Residential',1300,'2021-03-01');
SELECT sector, SUM(generation_kg) FROM waste_generation WHERE date BETWEEN '2021-01-01' AND '2021-03-31' GROUP BY sector;
Find the titles and runtimes of all movies and tv shows in the media table that have a runtime over 120 minutes and were produced in the US or Canada.
CREATE TABLE media (id INT,title VARCHAR(50),runtime INT,type VARCHAR(10),country VARCHAR(50));
SELECT title, runtime FROM media WHERE type IN ('movie', 'tv_show') AND runtime > 120 AND country IN ('US', 'Canada');
What is the maximum construction cost per square meter for buildings in 'East Asia'?
CREATE TABLE Buildings (id INT,name TEXT,location TEXT,cost_per_sqm FLOAT); INSERT INTO Buildings (id,name,location,cost_per_sqm) VALUES (1,'BuildingA','East Asia',8000.00),(2,'BuildingB','East Asia',9000.50),(3,'BuildingC','East Asia',7500.25);
SELECT MAX(cost_per_sqm) FROM Buildings WHERE location = 'East Asia';
Insert a new record into the 'volunteers' table
CREATE TABLE volunteers (id INT PRIMARY KEY,name VARCHAR(255),email VARCHAR(255),hours_per_week FLOAT);
INSERT INTO volunteers (id, name, email, hours_per_week) VALUES (1, 'John Doe', '[john.doe@gmail.com](mailto:john.doe@gmail.com)', 10.0);
Which state has the lowest workforce diversity index?
CREATE TABLE diversity (id INT,state VARCHAR(20),diversity_index FLOAT); INSERT INTO diversity (id,state,diversity_index) VALUES (1,'Queensland',0.65),(2,'NewSouthWales',0.72),(3,'Victoria',0.70);
SELECT state, MIN(diversity_index) as min_index FROM diversity GROUP BY state;
Find the number of articles published in each news category in 'categoryanalysis' database for the last year.
CREATE TABLE articles (article_id INT,title TEXT,category TEXT,publish_date DATE); INSERT INTO articles VALUES (1,'Article 1','Politics','2022-01-01'); INSERT INTO articles VALUES (2,'Article 2','Sports','2022-01-02');
SELECT category, COUNT(*) FROM articles WHERE publish_date >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR) GROUP BY category
What is the total CO2 emission by mine for the last 6 months?
CREATE TABLE mines (id INT,name VARCHAR(255),last_co2_report_date DATE,co2_emission INT); INSERT INTO mines (id,name,last_co2_report_date,co2_emission) VALUES (1,'Mine A','2022-01-15',5000),(2,'Mine B','2022-02-20',7000),(3,'Mine C','2022-03-10',6000),(4,'Mine D','2022-04-01',8000);
SELECT m.name, SUM(m.co2_emission) as total_co2_emission FROM mines m WHERE m.last_co2_report_date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH) GROUP BY m.name;
List all digital assets and their regulatory laws in North America.
CREATE TABLE Digital_Assets (id INT PRIMARY KEY,name VARCHAR(50),smart_contract_id INT,FOREIGN KEY (smart_contract_id) REFERENCES Smart_Contracts(id)); INSERT INTO Digital_Assets (id,name,smart_contract_id) VALUES (1,'Asset1',1); INSERT INTO Digital_Assets (id,name,smart_contract_id) VALUES (2,'Asset2',2);
SELECT da.name, r.law FROM Digital_Assets da INNER JOIN Smart_Contracts sc ON da.smart_contract_id = sc.id INNER JOIN Regulations r ON sc.country = r.country WHERE r.region = 'North America';
What is the total production volume for each location in the Catfish_Production table?
CREATE TABLE Catfish_Production (Production_ID INT,Farm_ID INT,Location TEXT,Production_Volume INT); INSERT INTO Catfish_Production (Production_ID,Farm_ID,Location,Production_Volume) VALUES (1,1,'Mississippi',1500),(2,2,'Alabama',2000),(3,3,'Mississippi',1700);
SELECT Location, SUM(Production_Volume) FROM Catfish_Production GROUP BY Location;
What is the daily caloric intake for vegetarian meals in a French restaurant?
CREATE TABLE Meals (meal_id INT,meal_name VARCHAR(255),is_vegetarian BOOLEAN,restaurant_country VARCHAR(255)); INSERT INTO Meals (meal_id,meal_name,is_vegetarian,restaurant_country) VALUES (1,'Spaghetti Bolognese',FALSE,'Italy'),(2,'Vegetable Lasagna',TRUE,'Italy'),(3,'Coq au Vin',FALSE,'France'),(4,'Ratatouille',TRUE,'France'); CREATE TABLE Nutrition (nutrition_id INT,meal_id INT,calories INT); INSERT INTO Nutrition (nutrition_id,meal_id,calories) VALUES (1,1,500),(2,2,600),(3,3,700),(4,4,400); CREATE TABLE Days (day_id INT,date DATE); INSERT INTO Days (day_id,date) VALUES (1,'2022-01-01'),(2,'2022-01-02'),(3,'2022-01-03');
SELECT d.date, SUM(n.calories) as daily_caloric_intake FROM Days d JOIN Meals m ON d.day_id = m.meal_id JOIN Nutrition n ON m.meal_id = n.meal_id WHERE m.is_vegetarian = TRUE AND m.restaurant_country = 'France' GROUP BY d.date;
What is the total price of organic cosmetic products?
CREATE TABLE Products (id INT,name VARCHAR(50),category VARCHAR(50),price DECIMAL(5,2),organic BOOLEAN); INSERT INTO Products (id,name,category,price,organic) VALUES (1,'Nourishing Lipstick','Makeup',14.99,true),(2,'Luxury Foundation','Makeup',45.50,false),(3,'Tinted Mascara','Makeup',8.99,true);
SELECT SUM(p.price) as total_price FROM Products p WHERE p.organic = true;
What is the total number of police stations in CityM?
CREATE TABLE police_stations_2 (id INT,city VARCHAR(50),station_count INT); INSERT INTO police_stations_2 (id,city,station_count) VALUES (1,'CityM',5),(2,'CityN',10),(3,'CityO',8);
SELECT station_count FROM police_stations_2 WHERE city = 'CityM';
What is the total number of community policing initiatives in the city of Vancouver?
CREATE TABLE community_policing (id INT,city VARCHAR(20),initiative VARCHAR(50)); INSERT INTO community_policing (id,city,initiative) VALUES (1,'Vancouver','Neighborhood Watch'),(2,'Montreal','Coffee with a Cop'),(3,'Vancouver','Citizens Police Academy');
SELECT COUNT(*) FROM community_policing WHERE city = 'Vancouver';
What is the average sugar content in vegan desserts?
CREATE TABLE desserts (id INT,name TEXT,type TEXT,sugar_grams INT); INSERT INTO desserts (id,name,type,sugar_grams) VALUES (1,'Chocolate Mousse','vegan',25),(2,'Blueberry Cheesecake','non_vegan',35);
SELECT AVG(sugar_grams) FROM desserts WHERE type = 'vegan';
What percentage of healthcare facilities in the rural county of 'Pineville' have telemedicine capabilities?
CREATE TABLE healthcare_facilities (facility_id INT,name VARCHAR(255),county VARCHAR(255),has_telemedicine BOOLEAN); INSERT INTO healthcare_facilities (facility_id,name,county,has_telemedicine) VALUES (1,'Pineville General','Pineville',true),(2,'Pineville Clinic','Pineville',false),(3,'Pineville Specialty Care','Pineville',true);
SELECT 100.0 * COUNT(*) FILTER (WHERE has_telemedicine = true) / COUNT(*) FROM healthcare_facilities WHERE county = 'Pineville';
What is the average waiting time for patients to see a doctor, grouped by the day of the week and the location of the clinic?
CREATE TABLE WaitingTimes (WaitingTimeID INT,ClinicID INT,DoctorID INT,Date DATE,WaitingTime INT); INSERT INTO WaitingTimes (WaitingTimeID,ClinicID,DoctorID,Date,WaitingTime) VALUES (1,1,1,'2021-10-01',30);
SELECT DATEPART(dw, Date) AS DayOfWeek, Location, AVG(WaitingTime) FROM WaitingTimes wt JOIN Clinics cl ON wt.ClinicID = cl.ClinicID GROUP BY DATEPART(dw, Date), Location;
Find the number of unique chemicals produced by each factory.
CREATE TABLE factories (id INT,name TEXT); INSERT INTO factories (id,name) VALUES (1,'Factory A'),(2,'Factory B'); CREATE TABLE chemical_produced (factory_id INT,chemical_name TEXT); INSERT INTO chemical_produced (factory_id,chemical_name) VALUES (1,'Chemical X'),(1,'Chemical X'),(2,'Chemical Y'),(2,'Chemical Z');
SELECT factory_id, COUNT(DISTINCT chemical_name) AS unique_chemicals_produced FROM chemical_produced GROUP BY factory_id;
What is the maximum water usage for a single day in the 'water_usage' table?
CREATE TABLE water_usage (id INT,date DATE,water_usage INT); INSERT INTO water_usage (id,date,water_usage) VALUES (1,'2022-01-01',5000),(2,'2022-01-02',5500),(3,'2022-01-03',4500);
SELECT MAX(water_usage) FROM water_usage;
Insert a new train route from 'New York' to 'Boston' with a distance of 400 km and a fare of $150.
CREATE TABLE stations (station_id INT,station_name TEXT); INSERT INTO stations (station_id,station_name) VALUES (1,'New York'),(2,'Boston'); CREATE TABLE train_routes (route_id INT,start_station INT,end_station INT,distance INT,fare DECIMAL);
INSERT INTO train_routes (route_id, start_station, end_station, distance, fare) VALUES (1, (SELECT station_id FROM stations WHERE station_name = 'New York'), (SELECT station_id FROM stations WHERE station_name = 'Boston'), 400, 150);
List all financial institutions offering Shariah-compliant finance in Southeast Asia, sorted by the number of branches in descending order.
CREATE TABLE financial_institutions (id INT,name VARCHAR(255),region VARCHAR(255)); CREATE TABLE shariah_compliant_finance (id INT,financial_institution_id INT,branches INT);
SELECT financial_institutions.name FROM financial_institutions INNER JOIN shariah_compliant_finance ON financial_institutions.id = shariah_compliant_finance.financial_institution_id WHERE region = 'Southeast Asia' ORDER BY branches DESC;
Determine the total number of animals in each region
CREATE TABLE animal_populations (id INT,species VARCHAR(50),population INT,region VARCHAR(50)); INSERT INTO animal_populations (id,species,population,region) VALUES (1,'Giraffe',1000,'Africa'),(2,'Elephant',500,'Asia'),(3,'Lion',200,'Africa'),(4,'Rhinoceros',100,'Asia'),(5,'Hippopotamus',300,'Africa'),(6,'Polar Bear',50,'Arctic'),(7,'Penguin',250,'Antarctica');
SELECT region, SUM(population) as total_animals FROM animal_populations GROUP BY region;
What is the sales figure for DrugA in Q1 2023?
CREATE TABLE sales_data (drug VARCHAR(255),quarter INT,year INT,sales FLOAT); INSERT INTO sales_data (drug,quarter,year,sales) VALUES ('DrugA',1,2023,12000),('DrugA',2,2023,15000),('DrugB',1,2023,8000);
SELECT sales FROM sales_data WHERE drug = 'DrugA' AND quarter = 1 AND year = 2023;
Which programs have more than 5 volunteers in the Western region?
CREATE TABLE programs (id INT,name VARCHAR(50),location VARCHAR(50)); CREATE TABLE volunteers (id INT,name VARCHAR(50),program_id INT); INSERT INTO programs (id,name,location) VALUES (1,'Education','California'),(2,'Environment','Oregon'),(3,'Arts','Washington'); INSERT INTO volunteers (id,name,program_id) VALUES (1,'Alice',1),(2,'Bob',1),(3,'Charlie',2),(4,'David',3),(5,'Eve',3),(6,'Frank',3);
SELECT p.name FROM programs p INNER JOIN volunteers v ON p.id = v.program_id WHERE p.location IN ('California', 'Oregon', 'Washington') GROUP BY p.name HAVING COUNT(v.id) > 5;
Find the number of unique investors for companies founded by Latinx or Black individuals?
CREATE TABLE Founders (id INT,name TEXT,ethnicity TEXT); INSERT INTO Founders (id,name,ethnicity) VALUES (1,'Charity Inc','Latinx'); INSERT INTO Founders (id,name,ethnicity) VALUES (2,'Diverse Enterprises','Black'); INSERT INTO Founders (id,name,ethnicity) VALUES (3,'Eco Solutions','Asian'); CREATE TABLE Investments (company_id INT,investor_id INT); INSERT INTO Investments (company_id,investor_id) VALUES (1,1); INSERT INTO Investments (company_id,investor_id) VALUES (1,2); INSERT INTO Investments (company_id,investor_id) VALUES (2,3); INSERT INTO Investments (company_id,investor_id) VALUES (2,4);
SELECT COUNT(DISTINCT Investments.investor_id) FROM Founders JOIN Investments ON Founders.id = Investments.company_id WHERE Founders.ethnicity IN ('Latinx', 'Black');