instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
How many cases were handled by the attorney with the highest total billing amount?
CREATE TABLE attorneys (id INT,name VARCHAR(20)); INSERT INTO attorneys (id,name) VALUES (1,'Smith'),(2,'Garcia'),(3,'Kim'); CREATE TABLE cases (id INT,attorney_id INT,case_type VARCHAR(10),billing_amount INT);
SELECT COUNT(*) FROM (SELECT attorney_id, SUM(billing_amount) AS total_billing FROM cases GROUP BY attorney_id ORDER BY total_billing DESC LIMIT 1) AS top_attorney;
Insert a new case for attorney 'Laura Johnson' with case ID 4, open date '2022-06-01', and billing amount $6000.
CREATE TABLE attorneys (attorney_id INT,last_name VARCHAR(20),first_name VARCHAR(20)); INSERT INTO attorneys (attorney_id,last_name,first_name) VALUES (1,'Garcia','Jose'),(2,'Johnson','Laura'); CREATE TABLE cases (case_id INT,attorney_id INT,open_date DATE,billing_amount INT);
INSERT INTO cases (case_id, attorney_id, open_date, billing_amount) VALUES (4, (SELECT attorney_id FROM attorneys WHERE last_name = 'Johnson' AND first_name = 'Laura'), '2022-06-01', 6000);
Delete records in the safety_protocols table where the chemical_name is LMN.
CREATE TABLE safety_protocols (id INT PRIMARY KEY,chemical_name VARCHAR(100),protocol VARCHAR(500)); INSERT INTO safety_protocols (id,chemical_name,protocol) VALUES (1,'XYZ','Store in a cool,dry place. Use protective gloves and eyewear.'),(2,'ABC','Keep away from heat and open flames.'),(3,'LMN','Use in a well-ventilated area.');
DELETE FROM safety_protocols WHERE chemical_name = 'LMN';
Which chemical compounds were used in the production of each product category, and in what quantities?
CREATE TABLE Product(Id INT,Category VARCHAR(50)); CREATE TABLE ChemicalUsage(Id INT,ProductId INT,ChemicalId INT,QuantityUsed INT); CREATE TABLE Chemical(Id INT,Name VARCHAR(50));
SELECT p.Category, c.Name AS ChemicalName, SUM(cu.QuantityUsed) AS TotalQuantityUsed FROM ChemicalUsage cu JOIN Product p ON cu.ProductId = p.Id JOIN Chemical c ON cu.ChemicalId = c.Id GROUP BY p.Category, c.Name;
What is the total amount of climate finance dedicated to afforestation projects in Asia before 2015?
CREATE TABLE climate_finance_projects (id INT,region VARCHAR(255),year INT,sector VARCHAR(255),amount FLOAT); INSERT INTO climate_finance_projects (id,region,year,sector,amount) VALUES (1,'Asia',2008,'afforestation',2000000);
SELECT SUM(amount) FROM climate_finance_projects WHERE region = 'Asia' AND sector = 'afforestation' AND year < 2015;
What was the total funding amount for startups founded by veterans in Japan?
CREATE TABLE company (id INT,name TEXT,country TEXT,founding_date DATE,founder_veteran BOOLEAN); INSERT INTO company (id,name,country,founding_date,founder_veteran) VALUES (1,'Pi Corp','Japan','2016-01-01',TRUE); INSERT INTO company (id,name,country,founding_date,founder_veteran) VALUES (2,'Rho Inc','Japan','2017-01-01',FALSE);
SELECT SUM(funding_amount) FROM funding INNER JOIN company ON funding.company_id = company.id WHERE company.country = 'Japan' AND company.founder_veteran = TRUE;
List the top 3 industries with the highest average total funding per company, excluding companies with less than $1M in total funding.
CREATE TABLE Companies (id INT,name TEXT,industry TEXT,total_funding FLOAT,num_investments INT); INSERT INTO Companies (id,name,industry,total_funding,num_investments) VALUES (1,'Acme Inc','Software',2500000,2),(2,'Beta Corp','Software',5000000,1),(3,'Gamma Startup','Hardware',1000000,3),(4,'Delta LLC','Hardware',2000000,1),(5,'Epsilon Ltd','Biotech',3000000,2),(6,'Zeta PLC','Biotech',500000,1);
SELECT industry, AVG(total_funding) AS industry_avg_funding FROM Companies WHERE total_funding >= 1000000 GROUP BY industry ORDER BY industry_avg_funding DESC LIMIT 3;
What is the average temperature in Brazil's Northeast region in January?
CREATE TABLE weather (country VARCHAR(255),region VARCHAR(255),month INT,temperature FLOAT); INSERT INTO weather (country,region,month,temperature) VALUES ('Brazil','Northeast',1,28.3),('Brazil','Northeast',1,28.7),('Brazil','Northeast',1,27.9),('Brazil','Northeast',1,28.4);
SELECT AVG(temperature) FROM weather WHERE country = 'Brazil' AND region = 'Northeast' AND month = 1;
What is the total number of indigenous food systems in Australia?
CREATE TABLE indigenous_food_systems (system_id INT,name TEXT,location TEXT,type TEXT,community TEXT,country TEXT); INSERT INTO indigenous_food_systems (system_id,name,location,type,community,country) VALUES (1,'Bush Tucker Project',' rural area','gardening','Aboriginal community','Australia');
SELECT COUNT(*) FROM indigenous_food_systems WHERE country = 'Australia';
What is the total number of digital assets issued by companies based in the United States, ordered by the date of issuance?
CREATE TABLE digital_assets (id INT,name VARCHAR(100),issuer_country VARCHAR(50),issue_date DATE); INSERT INTO digital_assets (id,name,issuer_country,issue_date) VALUES (1,'CryptoCoin','USA','2018-01-01'); INSERT INTO digital_assets (id,name,issuer_country,issue_date) VALUES (2,'BitAsset','USA','2019-03-15');
SELECT SUM(id) OVER (ORDER BY issue_date) as total_assets_issued, name, issuer_country, issue_date FROM digital_assets WHERE issuer_country = 'USA' ORDER BY issue_date;
Increase the price of all makeup products from the United States by 5%.
CREATE TABLE products (id INT,name TEXT,price DECIMAL,country TEXT);
UPDATE products SET price = price * 1.05 WHERE country = 'United States' AND product_type = 'makeup';
What is the total sales volume of natural hair care products sold in the US?
CREATE TABLE hair_care_sales(product_name TEXT,price DECIMAL(5,2),is_natural BOOLEAN,country TEXT); INSERT INTO hair_care_sales VALUES ('Shampoo',12.99,true,'USA'); INSERT INTO hair_care_sales VALUES ('Conditioner',14.99,true,'USA'); INSERT INTO hair_care_sales VALUES ('Styling Cream',8.99,false,'USA');
SELECT SUM(sales_volume) FROM (SELECT product_name, sales_volume FROM sales_volume JOIN hair_care_sales ON sales_volume.product_name = hair_care_sales.product_name WHERE hair_care_sales.is_natural = true AND hair_care_sales.country = 'USA') AS subquery;
What is the most common type of crime in each region?
CREATE TABLE regions (region_id INT,region_name VARCHAR(255));CREATE TABLE districts (district_id INT,district_name VARCHAR(255),region_id INT);CREATE TABLE crimes (crime_id INT,district_id INT,crime_type VARCHAR(255),crime_date DATE);
SELECT r.region_name, c.crime_type, COUNT(*) AS count FROM regions r JOIN districts d ON r.region_id = d.region_id JOIN crimes c ON d.district_id = c.district_id GROUP BY r.region_name, c.crime_type ORDER BY count DESC;
List the top 3 countries with the most veteran employment in the IT industry
CREATE TABLE veteran_employment (employee_id INT,industry VARCHAR(255),salary DECIMAL(10,2),state VARCHAR(2),country VARCHAR(255)); CREATE TABLE countries (country_id INT,country VARCHAR(255));
SELECT country, COUNT(*) as num_veterans FROM veteran_employment JOIN countries ON veteran_employment.country = countries.country WHERE industry = 'IT' GROUP BY country ORDER BY num_veterans DESC LIMIT 3;
Update the 'troops' value for 'Afghanistan' in the year 2005 to 850 in the 'peacekeeping_operations' table
CREATE TABLE peacekeeping_operations (id INT PRIMARY KEY,country VARCHAR(50),year INT,troops INT,cost FLOAT);
WITH cte AS (UPDATE peacekeeping_operations SET troops = 850 WHERE country = 'Afghanistan' AND year = 2005 RETURNING *) INSERT INTO peacekeeping_operations SELECT * FROM cte;
Which are the top 5 ports with the highest cargo weight handled in 2021?
CREATE TABLE port (port_id INT,port_name VARCHAR(50),country VARCHAR(50)); INSERT INTO port VALUES (1,'Port of Shanghai','China'); INSERT INTO port VALUES (2,'Port of Singapore','Singapore'); CREATE TABLE cargo (cargo_id INT,port_id INT,cargo_weight INT,handling_date DATE); INSERT INTO cargo VALUES (1,1,50000,'2021-01-01');
SELECT p.port_name, SUM(c.cargo_weight) as total_weight FROM port p JOIN cargo c ON p.port_id = c.port_id WHERE handling_date >= '2021-01-01' AND handling_date < '2022-01-01' GROUP BY p.port_name ORDER BY total_weight DESC LIMIT 5;
Which excavation sites have over 2000 artifacts?
CREATE TABLE Excavation_Sites (Site_ID INT,Site_Name TEXT,Country TEXT,Number_of_Artifacts INT);INSERT INTO Excavation_Sites (Site_ID,Site_Name,Country,Number_of_Artifacts) VALUES (1,'Pompeii','Italy',10000);INSERT INTO Excavation_Sites (Site_ID,Site_Name,Country,Number_of_Artifacts) VALUES (2,'Tutankhamun','Egypt',5000);INSERT INTO Excavation_Sites (Site_ID,Site_Name,Country,Number_of_Artifacts) VALUES (3,'Machu Picchu','Peru',3000);INSERT INTO Excavation_Sites (Site_ID,Site_Name,Country,Number_of_Artifacts) VALUES (4,'Angkor Wat','Cambodia',2500);INSERT INTO Excavation_Sites (Site_ID,Site_Name,Country,Number_of_Artifacts) VALUES (5,'Teotihuacan','Mexico',2001);
SELECT Site_ID, Site_Name, Number_of_Artifacts FROM Excavation_Sites WHERE Number_of_Artifacts > 2000;
How many employees have completed compliance training by quarter?
CREATE TABLE training_records (id INT,employee_id INT,training_type VARCHAR(255),completion_date DATE); INSERT INTO training_records (id,employee_id,training_type,completion_date) VALUES (1,1,'Diversity and Inclusion','2022-02-01'),(2,2,'Sexual Harassment Prevention','2022-03-15'),(3,3,'Compliance','2022-01-05'),(4,4,'Sexual Harassment Prevention','2022-04-30'),(5,5,'Compliance','2022-03-01');
SELECT QUARTER(completion_date) as completion_quarter, COUNT(*) as num_completed FROM training_records WHERE training_type = 'Compliance' AND completion_date IS NOT NULL GROUP BY completion_quarter;
Who has the most Grand Slam titles in tennis?
CREATE TABLE tennis_players (player_id INT,name VARCHAR(50),country VARCHAR(50),grand_slam_titles INT); INSERT INTO tennis_players (player_id,name,country,grand_slam_titles) VALUES (1,'Roger Federer','Switzerland',20); INSERT INTO tennis_players (player_id,name,country,grand_slam_titles) VALUES (2,'Serena Williams','United States',23);
SELECT name FROM tennis_players WHERE grand_slam_titles = (SELECT MAX(grand_slam_titles) FROM tennis_players);
Calculate the percentage of Shariah-compliant investments held by each investor in the top 5 countries with the highest percentage?
CREATE TABLE investors (investor_id INT,investor_name TEXT,country TEXT); INSERT INTO investors (investor_id,investor_name,country) VALUES (1,'Al Thani','Qatar'),(2,'Saudi Investment Group','Saudi Arabia'),(3,'Temasek Holdings','Singapore'); CREATE TABLE investments (investment_id INT,investor_id INT,investment_type TEXT,investment_value DECIMAL,is_shariah_compliant BOOLEAN); INSERT INTO investments (investment_id,investor_id,investment_type,investment_value,is_shariah_compliant) VALUES (1,1,'Real Estate',15000000,true),(2,2,'Stocks',20000000,false);
SELECT investor_name, ROUND((SUM(CASE WHEN is_shariah_compliant THEN investment_value ELSE 0 END) / SUM(investment_value)) * 100, 2) AS percentage FROM investments JOIN investors ON investments.investor_id = investors.investor_id GROUP BY investor_name ORDER BY percentage DESC LIMIT 5;
Find the total number of unique donors from the year 2020 who have never donated again?
CREATE TABLE Donors (id INT,donor_name VARCHAR(255),first_donation_date DATE,last_donation_date DATE); INSERT INTO Donors (id,donor_name,first_donation_date,last_donation_date) VALUES (1,'John Doe','2020-01-01','2020-12-31'),(2,'Jane Smith','2020-02-01','2021-01-01'),(3,'Alice Johnson','2020-03-01','2020-03-31');
SELECT COUNT(DISTINCT donor_name) as total_unique_donors FROM Donors WHERE first_donation_date >= '2020-01-01' AND last_donation_date < '2021-01-01' AND NOT EXISTS (SELECT 1 FROM Donors d2 WHERE d2.donor_name = Donors.donor_name AND d2.last_donation_date > '2020-12-31');
What is the minimum donation amount for each program?
CREATE TABLE Programs (ProgramID INT,ProgramName TEXT); CREATE TABLE Donations (DonationID INT,DonationAmount NUMERIC,ProgramID INT);
SELECT Programs.ProgramName, MIN(Donations.DonationAmount) FROM Programs JOIN Donations ON Programs.ProgramID = Donations.ProgramID GROUP BY Programs.ProgramName;
Show the capacity of all warehouses located in California
CREATE TABLE warehouse (id INT,city VARCHAR(20),capacity INT); INSERT INTO warehouse (id,city,capacity) VALUES (1,'Chicago',1000),(2,'Houston',1500),(3,'Miami',800),(4,'Los Angeles',1200),(5,'San Francisco',1800);
SELECT capacity FROM warehouse WHERE city IN ('Los Angeles', 'San Francisco');
Find the average investment amount in biotech startups for the year 2019.
CREATE SCHEMA if not exists biotech;CREATE TABLE if not exists biotech.investments (id INT,startup_id INT,amount DECIMAL(10,2),investment_year INT); INSERT INTO biotech.investments (id,startup_id,amount,investment_year) VALUES (1,1,500000,2020),(2,2,300000,2019),(3,1,750000,2020),(4,4,250000,2019);
SELECT AVG(amount) FROM biotech.investments WHERE investment_year = 2019;
Find the initiative names with type 'Education' and their costs?
CREATE TABLE Initiatives (initiative_id INT,initiative_name VARCHAR(50),initiative_cost INT,initiative_type VARCHAR(20));
SELECT initiative_name, initiative_cost FROM Initiatives WHERE initiative_type = 'Education';
Determine the number of female and male students in the School of Engineering, and calculate the percentage of each gender in the school, rounded to two decimal places.
CREATE TABLE StudentDemographics (id INT,name VARCHAR(255),department VARCHAR(255),gender VARCHAR(10));
SELECT department, gender, COUNT(*) as count, ROUND(COUNT(*) * 100.0 / SUM(COUNT(*)) OVER (PARTITION BY department), 2) as percentage FROM StudentDemographics WHERE department LIKE 'Engineering%' GROUP BY department, gender;
What is the percentage of female faculty members in each department?
CREATE TABLE faculty (id INT,name VARCHAR(50),department VARCHAR(50),gender VARCHAR(10)); INSERT INTO faculty VALUES (1,'Alice','Computer Science','Female'); INSERT INTO faculty VALUES (2,'Bob','Physics','Male'); INSERT INTO faculty VALUES (3,'Eve','Computer Science','Female'); CREATE TABLE departments (id INT,name VARCHAR(50)); INSERT INTO departments VALUES (1,'Computer Science'); INSERT INTO departments VALUES (2,'Physics');
SELECT departments.name, COUNT(faculty.id), COUNT(CASE WHEN faculty.gender = 'Female' THEN 1 END)/COUNT(faculty.id)*100 FROM faculty JOIN departments ON faculty.department = departments.name GROUP BY departments.name;
What is the total installed capacity of renewable energy projects in the United States?
CREATE TABLE RenewableEnergyProjects (project_id INT,project_name VARCHAR(255),country VARCHAR(255),capacity FLOAT,technology VARCHAR(255));
SELECT SUM(capacity) FROM RenewableEnergyProjects WHERE country = 'United States';
What is the count of community health workers who speak Spanish, by job title?
CREATE TABLE CommunityHealthWorkers (CHW_ID INT,Name VARCHAR(50),Job_Title VARCHAR(50),Language VARCHAR(50)); INSERT INTO CommunityHealthWorkers (CHW_ID,Name,Job_Title,Language) VALUES (1,'Ana','Community Health Worker','Spanish'); INSERT INTO CommunityHealthWorkers (CHW_ID,Name,Job_Title,Language) VALUES (2,'Carlos','Senior Community Health Worker','Spanish');
SELECT Job_Title, COUNT(*) FROM CommunityHealthWorkers WHERE Language = 'Spanish' GROUP BY Job_Title;
What are the average energy consumption and carbon emissions per tourist for each country?
CREATE TABLE energy_consumption (country VARCHAR(50),tourists INT,energy_consumption FLOAT); INSERT INTO energy_consumption (country,tourists,energy_consumption) VALUES ('Canada',10000,5000000),('Mexico',12000,4500000),('France',15000,4000000); CREATE TABLE carbon_emissions (country VARCHAR(50),tourists INT,emissions FLOAT); INSERT INTO carbon_emissions (country,tourists,emissions) VALUES ('Canada',10000,1200000),('Mexico',12000,1100000),('France',15000,900000);
SELECT e.country, AVG(e.energy_consumption / t.tourists) AS avg_energy_consumption, AVG(c.emissions / t.tourists) AS avg_carbon_emissions FROM energy_consumption e JOIN carbon_emissions c ON e.country = c.country JOIN (SELECT country, SUM(tourists) AS tourists FROM (SELECT country, tourists FROM energy_consumption UNION ALL SELECT country, tourists FROM carbon_emissions) combined GROUP BY country) t ON e.country = t.country GROUP BY e.country;
What is the average rating of eco-friendly hotels in France?
CREATE TABLE eco_hotels(hotel_id INT,hotel_name TEXT,country TEXT,rating FLOAT); INSERT INTO eco_hotels(hotel_id,hotel_name,country,rating) VALUES (1,'Hotel Eco Ville','France',4.2),(2,'Eco Chateau','France',4.5),(3,'Green Provence Hotel','France',4.7);
SELECT AVG(rating) FROM eco_hotels WHERE country = 'France';
What's the name and birthplace of the artist with the most works in the Post-Impressionism genre?
CREATE TABLE Artists (ArtistID INT,Name TEXT,Birthplace TEXT);CREATE TABLE Artworks (ArtworkID INT,Title TEXT,Genre TEXT,ArtistID INT); INSERT INTO Artists (ArtistID,Name,Birthplace) VALUES (1,'Vincent van Gogh','Netherlands'); INSERT INTO Artworks (ArtworkID,Title,Genre,ArtistID) VALUES (1,'Starry Night','Post-Impressionism',1);
SELECT Artists.Name, Artists.Birthplace FROM Artists INNER JOIN Artworks ON Artists.ArtistID = Artworks.ArtistID WHERE Genre = 'Post-Impressionism' GROUP BY Artists.ArtistID ORDER BY COUNT(Artworks.ArtworkID) DESC LIMIT 1;
Delete all records from the 'research_projects' table where the 'funding_amount' is greater than $500000
CREATE TABLE research_projects (id INT PRIMARY KEY,project_name VARCHAR(255),funding_source VARCHAR(255),funding_amount DECIMAL(10,2)); INSERT INTO research_projects (id,project_name,funding_source,funding_amount) VALUES (1,'Climate Change Impact Study','National Science Foundation',750000.00),(2,'Biodiversity Loss in Arctic Region','European Union',450000.00),(3,'Indigenous Communities and Climate Change','World Bank',800000.00),(4,'Arctic Resource Management','Global Environment Facility',550000.00);
DELETE FROM research_projects WHERE funding_amount > 500000.00;
How many records are there in the 'arctic_weather' table for each month?
CREATE TABLE arctic_weather (date DATE,temperature FLOAT);
SELECT EXTRACT(MONTH FROM date) AS month, COUNT(*) AS records_count FROM arctic_weather GROUP BY month;
What is the average temperature per year in the Arctic Research Lab?
CREATE TABLE ArcticResearchLab (id INT,year INT,temperature FLOAT); INSERT INTO ArcticResearchLab (id,year,temperature) VALUES (1,2000,-10.5),(2,2001,-11.3),(3,2002,-12.1);
SELECT AVG(temperature) FROM ArcticResearchLab GROUP BY year;
What is the average temperature recorded in the Arctic Research Station 15 in March?
CREATE TABLE Arctic_Research_Station_15 (date DATE,temperature FLOAT);
SELECT AVG(temperature) FROM Arctic_Research_Station_15 WHERE EXTRACT(MONTH FROM date) = 3;
What is the total length of highways in 'Highways' table for each state?
CREATE TABLE Highways(state VARCHAR(255),length FLOAT,type VARCHAR(255)); INSERT INTO Highways VALUES('California',500.0,'Rural'),('California',700.0,'Urban'),('Texas',400.0,'Rural'),('Texas',800.0,'Urban'),('NewYork',300.0,'Rural'),('NewYork',600.0,'Urban');
SELECT state, SUM(length) FROM Highways GROUP BY state;
What is the minimum depth recorded in the Mariana Trench?
CREATE TABLE ocean_floor_mapping (location VARCHAR(255),depth FLOAT); INSERT INTO ocean_floor_mapping (location,depth) VALUES ('Mariana Trench',10994.0),('Challenger Deep',10972.8);
SELECT MIN(depth) FROM ocean_floor_mapping WHERE location = 'Mariana Trench';
How many employees of each position work in the 'drilling' department?
CREATE TABLE departments (id INT,name VARCHAR(50)); CREATE TABLE employee_positions (id INT,name VARCHAR(50),dept_id INT,emp_id INT); CREATE TABLE employee_dept (id INT,dept_id INT,emp_id INT); CREATE TABLE employees (id INT,name VARCHAR(50),salary DECIMAL(10,2));
SELECT e.position, COUNT(*) as num_employees FROM employee_positions ep JOIN employees e ON e.id = ep.emp_id JOIN employee_dept ed ON e.id = ed.emp_id JOIN departments d ON d.id = ed.dept_id WHERE d.name = 'drilling' GROUP BY e.position;
List all subscribers who have both mobile and broadband services, along with their contract start and end dates.
CREATE TABLE subscribers (subscriber_id INT,name VARCHAR(50),mobile_contract_start_date DATE,mobile_contract_end_date DATE,broadband_contract_start_date DATE,broadband_contract_end_date DATE); INSERT INTO subscribers (subscriber_id,name,mobile_contract_start_date,mobile_contract_end_date,broadband_contract_start_date,broadband_contract_end_date) VALUES (1,'John Doe','2021-01-01','2022-01-01','2021-02-01','2022-02-01'),(2,'Jane Smith','2021-03-01','2022-03-01','2021-04-01','2022-04-01');
SELECT subscriber_id, name, mobile_contract_start_date, mobile_contract_end_date, broadband_contract_start_date, broadband_contract_end_date FROM subscribers WHERE mobile_contract_start_date IS NOT NULL AND broadband_contract_start_date IS NOT NULL;
What is the most common word in the 'politics' category?
CREATE TABLE news (title VARCHAR(255),author VARCHAR(255),word_count INT,category VARCHAR(255),word VARCHAR(255)); INSERT INTO news (title,author,word_count,category,word) VALUES ('Sample News','Jane Smith',800,'Politics','Democracy');
SELECT word, COUNT(*) as count FROM news WHERE category = 'Politics' GROUP BY word ORDER BY count DESC LIMIT 1;
What is the average depth of the five deepest trenches in the Pacific Ocean?
CREATE TABLE TRENCHES (NAME TEXT,DEPTH NUMERIC,REGION TEXT); INSERT INTO TRENCHES (NAME,DEPTH,REGION) VALUES ('Mariana Trench',36090,'Pacific Ocean'),('Tonga Trench',35702,'Pacific Ocean'),('Kuril-Kamchatka Trench',34455,'Pacific Ocean'),('Philippine Trench',33100,'Pacific Ocean'),('Sibuyan Sea Trench',33070,'Pacific Ocean'),('Izu-Bonin Trench',31890,'Pacific Ocean');
SELECT AVG(DEPTH) FROM (SELECT DEPTH FROM TRENCHES WHERE REGION = 'Pacific Ocean' ORDER BY DEPTH DESC LIMIT 5) AS T;
What is the maximum temperature recorded in 'Field D'?
CREATE TABLE sensors (sensor_id INT,location VARCHAR(50)); INSERT INTO sensors (sensor_id,location) VALUES (004,'Field D'); CREATE TABLE temps (sensor_id INT,temp FLOAT,timestamp TIMESTAMP); INSERT INTO temps (sensor_id,temp,timestamp) VALUES (004,29.5,'2022-01-01 10:00:00'); INSERT INTO temps (sensor_id,temp,timestamp) VALUES (004,31.6,'2022-01-02 11:00:00');
SELECT MAX(temp) FROM temps WHERE sensor_id = 004;
What is the minimum price of Promethium from 2016 to 2018?
CREATE TABLE price_data (element VARCHAR(10),year INT,price DECIMAL(5,2)); INSERT INTO price_data VALUES ('Promethium',2015,22.50),('Promethium',2016,23.10),('Promethium',2017,21.90),('Promethium',2018,22.80),('Promethium',2019,23.30);
SELECT MIN(price) FROM price_data WHERE element = 'Promethium' AND year BETWEEN 2016 AND 2018;
List the top 3 most affordable properties based on their sustainability scores in the 'RenewableHeights' neighborhood, ordered by size.
CREATE TABLE Properties (PropertyID INT,Price INT,SustainabilityScore INT,Neighborhood VARCHAR(20),Size INT); INSERT INTO Properties (PropertyID,Price,SustainabilityScore,Neighborhood,Size) VALUES (1,300000,80,'RenewableHeights',1200),(2,450000,95,'RenewableHeights',1500),(3,250000,60,'RenewableHeights',1800),(4,200000,85,'RenewableHeights',1000);
SELECT * FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY Neighborhood ORDER BY Price, Size) AS rn FROM Properties WHERE Neighborhood = 'RenewableHeights' ORDER BY Price, Size) sub WHERE rn <= 3;
What is the average size, in square feet, of co-owned properties in the city of Seattle?
CREATE TABLE property (id INT,size INT,city VARCHAR(20),co_owned BOOLEAN); INSERT INTO property (id,size,city,co_owned) VALUES (1,1200,'Seattle',TRUE),(2,1500,'Seattle',FALSE),(3,900,'Seattle',TRUE);
SELECT AVG(size) FROM property WHERE city = 'Seattle' AND co_owned = TRUE;
What is the total number of threat indicators for the energy sector with a confidence level higher than 75?
CREATE TABLE threat_indicators (id INT,sector TEXT,confidence INT); INSERT INTO threat_indicators (id,sector,confidence) VALUES (1,'Energy',80); INSERT INTO threat_indicators (id,sector,confidence) VALUES (2,'Transportation',70); INSERT INTO threat_indicators (id,sector,confidence) VALUES (3,'Energy',78);
SELECT SUM(confidence) FROM threat_indicators WHERE sector = 'Energy' AND confidence > 75;
Update the fuel type for cars produced before 2010 in the cars table to 'conventional'.
cars (id,make,model,year,fuel_type)
UPDATE cars SET fuel_type = 'conventional' WHERE cars.year < 2010;
What is the average fuel efficiency of hybrid vehicles in Japan?
CREATE TABLE JPHybridVehicles (id INT,company VARCHAR(30),model VARCHAR(30),fuel_efficiency DECIMAL(5,2));
SELECT AVG(fuel_efficiency) FROM JPHybridVehicles WHERE company = 'Toyota';
List the total quantity of sustainable fabric types used in 2020.
CREATE TABLE Fabrics (id INT PRIMARY KEY,type VARCHAR(20),year INT,quantity INT); INSERT INTO Fabrics (id,type,year,quantity) VALUES (1,'Organic_Cotton',2020,5000),(2,'Recycled_Polyester',2020,7000);
SELECT SUM(quantity) FROM Fabrics WHERE year = 2020 AND type IN ('Organic_Cotton', 'Recycled_Polyester');
What is the average lead time for eco-friendly packaging suppliers?
CREATE TABLE suppliers (id INT,name VARCHAR(255),material VARCHAR(255),lead_time INT); INSERT INTO suppliers (id,name,material,lead_time) VALUES
SELECT AVG(lead_time) FROM suppliers WHERE material = 'Eco-friendly Packaging';
List all claims that were processed in the last 60 days.
CREATE TABLE Claims (ClaimID INT,ProcessingDate DATE); INSERT INTO Claims (ClaimID,ProcessingDate) VALUES (1,'2022-02-01'),(2,'2022-02-15'),(3,'2022-01-01');
SELECT ClaimID, ProcessingDate FROM Claims WHERE ProcessingDate >= DATE_SUB(CURRENT_DATE(), INTERVAL 60 DAY);
What is the total claim amount for each gender?
CREATE TABLE policyholders (id INT,policyholder_name TEXT,state TEXT,age INT,gender TEXT); INSERT INTO policyholders (id,policyholder_name,state,age,gender) VALUES (1,'John Doe','NY',35,'Male'); INSERT INTO policyholders (id,policyholder_name,state,age,gender) VALUES (2,'Jane Smith','NY',42,'Female'); CREATE TABLE claims (id INT,policyholder_id INT,claim_amount INT); INSERT INTO claims (id,policyholder_id,claim_amount) VALUES (1,1,500); INSERT INTO claims (id,policyholder_id,claim_amount) VALUES (2,2,750);
SELECT gender, SUM(claim_amount) AS total_claim_amount FROM claims JOIN policyholders ON claims.policyholder_id = policyholders.id GROUP BY gender;
Which states have no union members?
CREATE TABLE union_members (id INT,name VARCHAR(50),state VARCHAR(2),joined_date DATE); INSERT INTO union_members (id,name,state,joined_date) VALUES (1,'John Doe','NY','2020-01-01'); INSERT INTO union_members (id,name,state,joined_date) VALUES (2,'Jane Smith','CA','2019-06-15'); INSERT INTO union_members (id,name,state,joined_date) VALUES (3,'Maria Rodriguez','CA','2018-12-21'); INSERT INTO union_members (id,name,state,joined_date) VALUES (4,'David Kim','NY','2019-04-10');
SELECT state FROM union_members GROUP BY state HAVING COUNT(*) = 0;
How many visitors are from the city of "Seattle" in the "Visitor" table?
CREATE TABLE visitor (visitor_id INT,visitor_city VARCHAR(255)); INSERT INTO visitor (visitor_id,visitor_city) VALUES (1,'Seattle');
SELECT COUNT(*) FROM visitor WHERE visitor_city = 'Seattle';
What is the total waste generation in kilograms for all organizations in the 'urban' sector for the year 2021?
CREATE TABLE organizations (id INT,name TEXT,sector TEXT,annual_waste_generation_kg FLOAT); INSERT INTO organizations (id,name,sector,annual_waste_generation_kg) VALUES (1,'EcoCity Recycling','urban',15000.5); INSERT INTO organizations (id,name,sector,annual_waste_generation_kg) VALUES (2,'GreenTech Waste Solutions','urban',12000.3);
SELECT SUM(annual_waste_generation_kg) FROM organizations WHERE sector = 'urban' AND YEAR(event_date) = 2021;
What is the maximum wastewater volume treated by each plant in New York on February 10, 2022?
CREATE TABLE WasteWaterTreatment (Id INT PRIMARY KEY,Plant VARCHAR(255),Volume FLOAT,Date DATE); INSERT INTO WasteWaterTreatment (Id,Plant,Volume,Date) VALUES (1,'Plant A',500,'2022-02-10'); INSERT INTO WasteWaterTreatment (Id,Plant,Volume,Date) VALUES (2,'Plant B',600,'2022-02-10'); INSERT INTO WasteWaterTreatment (Id,Plant,Volume,Date) VALUES (3,'Plant C',700,'2022-02-10');
SELECT Plant, MAX(Volume) FROM WasteWaterTreatment WHERE Date = '2022-02-10' AND Plant IN ('Plant A', 'Plant B', 'Plant C') GROUP BY Plant;
Calculate the total workout duration and number of workouts for each user in the month of January.
CREATE TABLE Workouts (user_id INT,workout_date DATE,workout_duration INT); INSERT INTO Workouts (user_id,workout_date,workout_duration) VALUES (1,'2022-01-01',60),(1,'2022-01-02',30),(2,'2022-01-01',45),(2,'2022-01-02',60);
SELECT user_id, SUM(workout_duration) as total_duration, COUNT(*) as num_workouts FROM Workouts WHERE MONTH(workout_date) = 1 GROUP BY user_id;
How many users have a higher heart rate on weekends compared to weekdays?
CREATE TABLE heart_rates (id INT,user_id INT,heart_rate INT,day_type VARCHAR(9)); INSERT INTO heart_rates (id,user_id,heart_rate,day_type) VALUES (1,1,120,'Weekday'),(2,2,130,'Weekend');
SELECT COUNT(*) FROM (SELECT user_id, CASE WHEN day_type = 'Weekday' THEN heart_rate END AS weekday_heart_rate, CASE WHEN day_type = 'Weekend' THEN heart_rate END AS weekend_heart_rate FROM heart_rates) AS subquery WHERE weekend_heart_rate > weekday_heart_rate;