instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
How many units of women's tops were sold in Q3 2020?
CREATE TABLE inventory (item_type VARCHAR(10),quarter VARCHAR(2),year INT,units_sold INT); INSERT INTO inventory (item_type,quarter,year,units_sold) VALUES ('women_tops','Q3',2020,1200),('women_tops','Q3',2020,1500),('women_tops','Q3',2020,1300);
SELECT SUM(units_sold) FROM inventory WHERE item_type = 'women_tops' AND quarter = 'Q3' AND year = 2020;
Find the average size, in square feet, of properties with inclusive housing policies in the city of Denver.
CREATE TABLE property (id INT,size INT,city VARCHAR(20),inclusive_housing_policy BOOLEAN);
SELECT AVG(size) FROM property WHERE city = 'Denver' AND inclusive_housing_policy = TRUE;
Identify the farm with the lowest biomass of fish for a given species in a given year?
CREATE TABLE Farm (FarmID INT,FarmName VARCHAR(255)); CREATE TABLE Stock (StockID INT,FarmID INT,FishSpecies VARCHAR(255),Weight DECIMAL(10,2),StockDate DATE); INSERT INTO Farm (FarmID,FarmName) VALUES (1,'Farm A'),(2,'Farm B'),(3,'Farm C'),(4,'Farm D'); INSERT INTO Stock (StockID,FarmID,FishSpecies,Weight,StockDate) VALUES (1,1,'Tilapia',5.5,'2022-01-01'),(2,1,'Salmon',12.3,'2022-01-02'),(3,2,'Tilapia',6.0,'2022-01-03'),(4,2,'Catfish',8.2,'2022-01-04'),(5,3,'Tilapia',9.0,'2022-01-05'),(6,3,'Salmon',11.0,'2022-01-06'),(7,4,'Tilapia',10.0,'2022-01-07'),(8,4,'Salmon',12.0,'2022-01-08');
SELECT FarmName, FishSpecies, MIN(Weight) OVER (PARTITION BY FishSpecies) as MinBiomass FROM Stock JOIN Farm ON Stock.FarmID = Farm.FarmID WHERE DATE_TRUNC('year', StockDate) = 2022;
Find the number of unique viewers for each movie and the total number of views for each movie
CREATE TABLE views (viewer_id INT,movie_title VARCHAR(255),views INT); INSERT INTO views (viewer_id,movie_title,views) VALUES (1,'Movie1',1000000),(2,'Movie2',2000000),(3,'Movie1',1500000),(4,'Movie3',500000);
SELECT movie_title, COUNT(DISTINCT viewer_id) as unique_viewers, SUM(views) as total_views FROM views GROUP BY movie_title;
What is the minimum number of doctors working in rural hospitals in India?
CREATE TABLE hospitals (id INT,name VARCHAR(50),location VARCHAR(50),num_doctors INT);
SELECT MIN(num_doctors) FROM hospitals WHERE location LIKE '%India%' AND location LIKE '%rural%';
What are the total fare collections for each vehicle type in the past month?
CREATE TABLE vehicle_types (vehicle_type_id INT,vehicle_type VARCHAR(255)); CREATE TABLE trips (trip_id INT,vehicle_type_id INT,fare_amount DECIMAL(5,2),trip_date DATE);
SELECT vt.vehicle_type, SUM(t.fare_amount) as total_fare FROM vehicle_types vt INNER JOIN trips t ON vt.vehicle_type_id = t.vehicle_type_id WHERE t.trip_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY vt.vehicle_type;
How many vessels are there in the 'Atlantic' and 'Arctic' regions combined?
CREATE TABLE vessels (id INT,name TEXT,region TEXT); INSERT INTO vessels (id,name,region) VALUES (1,'VesselA','Atlantic'); INSERT INTO vessels (id,name,region) VALUES (2,'VesselB','Arctic'); INSERT INTO vessels (id,name,region) VALUES (3,'VesselC','Atlantic');
SELECT COUNT(*) FROM vessels WHERE region IN ('Atlantic', 'Arctic')
Update the 'Explainable AI' model named 'SHAP' with a new method
CREATE TABLE xai_models (id INT,name VARCHAR(255),type VARCHAR(255),method VARCHAR(255)); INSERT INTO xai_models (id,name,type,method) VALUES (1,'SHAP','Explainable AI','TreeExplainer'),(2,'DeepLIFT','Explainable AI','Backpropagation');
UPDATE xai_models SET method = 'KernelExplainer' WHERE name = 'SHAP';
How many items are there in the menu that have 'Spicy' in their name?
CREATE TABLE menu (item_id INT,item_name TEXT); INSERT INTO menu (item_id,item_name) VALUES (1,'Spicy Quinoa'),(2,'Tofu Stir Fry'),(3,'Chickpea Curry'),(4,'Beef Burrito'),(5,'Chicken Alfredo'),(6,'Fish and Chips'),(7,'Veggie Pizza'),(8,'Spicy Beef Burrito'),(9,'Spicy Fish and Chips'),(10,'Spicy Veggie Pizza');
SELECT COUNT(*) FROM menu WHERE item_name LIKE '%Spicy%';
Remove a record from the network_investments table
CREATE TABLE network_investments (investment_id INT,location VARCHAR(50),investment_type VARCHAR(50),investment_amount DECIMAL(10,2),investment_date DATE);
DELETE FROM network_investments WHERE investment_id = 67890;
Which regions have the most companies founded by individuals from underrepresented racial or ethnic groups?
CREATE TABLE Companies (id INT,name TEXT,region TEXT,founder_underrepresented BOOLEAN); INSERT INTO Companies (id,name,region,founder_underrepresented) VALUES (1,'Solar Power LLC','North America',TRUE); INSERT INTO Companies (id,name,region,founder_underrepresented) VALUES (2,'Wind Energy GmbH','Europe',FALSE);
SELECT region, COUNT(*) FROM Companies WHERE founder_underrepresented = TRUE GROUP BY region;
What is the average safety_rating for vehicles manufactured in the US?
CREATE TABLE vehicles (id INT,make VARCHAR(50),model VARCHAR(50),year INT,safety_rating FLOAT,manufacturer_country VARCHAR(50)); INSERT INTO vehicles (id,make,model,year,safety_rating,manufacturer_country) VALUES (1,'Tesla','Model S',2020,5.3,'USA'); INSERT INTO vehicles (id,make,model,year,safety_rating,manufacturer_country) VALUES (2,'Toyota','Camry',2021,5.1,'Japan'); INSERT INTO vehicles (id,make,model,year,safety_rating,manufacturer_country) VALUES (3,'Ford','F-150',2022,5.0,'USA');
SELECT AVG(safety_rating) FROM vehicles WHERE manufacturer_country = 'USA';
What is the total runtime of movies directed by 'Director1'?
CREATE TABLE movies (id INT,title TEXT,runtime INT,director TEXT); INSERT INTO movies (id,title,runtime,director) VALUES (1,'Movie1',120,'Director1'),(2,'Movie2',90,'Director2'),(3,'Movie3',105,'Director1');
SELECT SUM(runtime) FROM movies WHERE director = 'Director1';
Delete the aircraft with id 1 from the manufacturing table
CREATE TABLE aircraft_manufacturing (id INT PRIMARY KEY,model VARCHAR(255),manufacturer VARCHAR(255),production_year INT); INSERT INTO aircraft_manufacturing (id,model,manufacturer,production_year) VALUES (1,'A320neo','Boeing',2016);
DELETE FROM aircraft_manufacturing WHERE id = 1;
Find the number of days between the first and last sale for each strain type in Oregon dispensaries.
CREATE TABLE DispensarySales(id INT,dispensary VARCHAR(255),state VARCHAR(255),strain_type VARCHAR(255),sale_date DATE);
SELECT strain_type, MAX(sale_date) - MIN(sale_date) as days_between_sales FROM DispensarySales WHERE state = 'Oregon' GROUP BY strain_type;
How many building permits were issued in Florida in Q2 2022?
CREATE TABLE BuildingPermits (PermitID INT,PermitDate DATE,State TEXT); INSERT INTO BuildingPermits VALUES (1,'2022-04-01','Florida'),(2,'2022-06-15','Florida'),(3,'2022-05-05','Florida');
SELECT COUNT(*) FROM BuildingPermits WHERE State = 'Florida' AND YEAR(PermitDate) = 2022 AND QUARTER(PermitDate) = 2;
What is the total funding amount for startups founded by people from underrepresented racial or ethnic backgrounds and are in the biotech industry?
CREATE TABLE company (id INT,name TEXT,founder_race TEXT,industry TEXT,total_funding INT); INSERT INTO company (id,name,founder_race,industry,total_funding) VALUES (1,'Acme Inc','Hispanic','Biotech',500000); INSERT INTO company (id,name,founder_race,industry,total_funding) VALUES (2,'Beta Inc','Black','Biotech',1000000);
SELECT SUM(total_funding) FROM company WHERE founder_race IN ('Hispanic', 'Black', 'Native American', 'Pacific Islander') AND industry = 'Biotech';
Show the top 3 roles with the highest average salary in the 'salaries' table.
CREATE TABLE salaries (id INT,employee_id INT,job_title VARCHAR(50),annual_salary DECIMAL(10,2)); INSERT INTO salaries (id,employee_id,job_title,annual_salary) VALUES (1,1,'Engineer',75000.00),(2,2,'Manager',85000.00),(3,3,'Operator',60000.00);
SELECT job_title, AVG(annual_salary) as avg_salary FROM salaries GROUP BY job_title ORDER BY avg_salary DESC LIMIT 3;
Total R&D expenditure for Oncology drugs in 2020
CREATE TABLE rd_expenditure (expenditure_id INT,drug_name TEXT,disease_area TEXT,year INT,amount DECIMAL); INSERT INTO rd_expenditure (expenditure_id,drug_name,disease_area,year,amount) VALUES (1,'DrugC','Oncology',2020,5000000),(2,'DrugD','Cardiovascular',2019,6000000);
SELECT SUM(amount) FROM rd_expenditure WHERE disease_area = 'Oncology' AND year = 2020;
Which ESG factors are most commonly considered in sustainable agriculture investments?
CREATE TABLE investment (investment_id INT,strategy VARCHAR(255),esg_factors TEXT); INSERT INTO investment (investment_id,strategy,esg_factors) VALUES (1,'Sustainable Agriculture','Water Management,Fair Trade,Biodiversity');
SELECT strategy, REGEXP_SPLIT_TO_TABLE(esg_factors, ',') as esg_factor FROM investment WHERE strategy = 'Sustainable Agriculture' GROUP BY strategy, esg_factor;
Insert a new album for the musician with id 3 with a title 'Eternal Sunshine' and a release date of '2024-05-15'
CREATE TABLE musicians (id INT PRIMARY KEY,name VARCHAR(100),genre VARCHAR(50),country VARCHAR(50),birth_date DATE); CREATE TABLE albums (id INT PRIMARY KEY,title VARCHAR(100),release_date DATE,musician_id INT,FOREIGN KEY (musician_id) REFERENCES musicians(id));
INSERT INTO albums (title, release_date, musician_id) VALUES ('Eternal Sunshine', '2024-05-15', 3);
Identify the top 5 cities with the highest percentage of electric vehicle adoption in the 'ev_adoption_stats' table.
CREATE TABLE ev_adoption_stats (id INT,city VARCHAR,state VARCHAR,num_evs INT,population INT);
SELECT city, state, (num_evs * 100.0 / population)::DECIMAL(5,2) AS ev_adoption_percentage, RANK() OVER (ORDER BY (num_evs * 100.0 / population) DESC) AS rank FROM ev_adoption_stats WHERE rank <= 5;
What is the minimum water pH level for each species, grouped by species, from the 'fish_stock' and 'ocean_health' tables?
CREATE TABLE fish_stock (species VARCHAR(255),pH FLOAT); CREATE TABLE ocean_health (species VARCHAR(255),pH FLOAT); INSERT INTO fish_stock (species,pH) VALUES ('Cod',7.8),('Haddock',7.6); INSERT INTO ocean_health (species,pH) VALUES ('Cod',7.6),('Haddock',7.5);
SELECT f.species, MIN(f.pH) FROM fish_stock f INNER JOIN ocean_health o ON f.species = o.species GROUP BY f.species;
What is the CO2 emission reduction for each smart city initiative, ranked by the reduction?
CREATE TABLE CityInitiatives (City VARCHAR(255),Initiative VARCHAR(255),CO2EmissionReduction FLOAT); INSERT INTO CityInitiatives (City,Initiative,CO2EmissionReduction) VALUES ('NYC','SmartGrid',15000),('LA','SmartTransit',20000),('Chicago','SmartBuildings',10000);
SELECT Initiative, SUM(CO2EmissionReduction) AS Total_Reduction FROM CityInitiatives GROUP BY Initiative ORDER BY Total_Reduction DESC;
How many vulnerabilities were found in the last 6 months for each product?
CREATE TABLE vulnerabilities (id INT,timestamp TIMESTAMP,product VARCHAR(255),vulnerability_severity VARCHAR(255)); INSERT INTO vulnerabilities (id,timestamp,product,vulnerability_severity) VALUES (1,'2020-07-01 14:00:00','Product A','High'),(2,'2020-08-05 09:30:00','Product B','Medium');
SELECT product, COUNT(*) as num_vulnerabilities FROM vulnerabilities WHERE timestamp >= NOW() - INTERVAL 6 MONTH GROUP BY product;
Calculate the percentage of successful phishing attacks in the healthcare sector in the first half of 2021
CREATE TABLE attacks (id INT,type VARCHAR(255),result VARCHAR(255),date DATE); INSERT INTO attacks (id,type,result,date) VALUES (1,'phishing','successful','2021-01-01'); INSERT INTO attacks (id,type,result,date) VALUES (2,'malware','unsuccessful','2021-01-02');
SELECT 100.0 * SUM(CASE WHEN type = 'phishing' AND result = 'successful' THEN 1 ELSE 0 END) / COUNT(*) as percentage FROM attacks WHERE sector = 'healthcare' AND date >= '2021-01-01' AND date < '2021-07-01';
How many energy efficiency projects are there in each state in the United States?
CREATE TABLE project_energy_efficiency (project_name TEXT,state TEXT); INSERT INTO project_energy_efficiency (project_name,state) VALUES ('Project A','State A'),('Project B','State A'),('Project C','State B'),('Project D','State B'),('Project E','State C');
SELECT state, COUNT(*) FROM project_energy_efficiency GROUP BY state;
List the top 5 mobile and broadband plans with the highest monthly revenue, including the plan name, plan type, monthly fee, and average data usage, and the total number of subscribers for each plan.
CREATE TABLE plan_info (plan_name VARCHAR(50),plan_type VARCHAR(20),monthly_fee FLOAT,average_data_usage FLOAT); CREATE TABLE subscriber_data (customer_id INT,service_type VARCHAR(20),plan_name VARCHAR(50));
SELECT plan_info.plan_name, plan_info.plan_type, plan_info.monthly_fee, plan_info.average_data_usage, SUM(subscriber_data.customer_id) as total_subscribers FROM plan_info JOIN subscriber_data ON plan_info.plan_name = subscriber_data.plan_name WHERE plan_info.plan_name IN (SELECT plan_name FROM (SELECT plan_name, ROW_NUMBER() OVER (ORDER BY monthly_fee * average_data_usage DESC) as rank FROM plan_info) as subquery WHERE rank <= 5) GROUP BY plan_info.plan_name, plan_info.plan_type, plan_info.monthly_fee, plan_info.average_data_usage ORDER BY total_subscribers DESC;
How many labor hours were reported for not sustainable construction projects?
CREATE TABLE LaborHours (project_id INT,hours FLOAT,sustainability VARCHAR(255)); INSERT INTO LaborHours (project_id,hours,sustainability) VALUES (1,500.5,'sustainable'),(2,300.2,'not sustainable'),(3,400,'not sustainable');
SELECT SUM(hours) FROM LaborHours WHERE sustainability = 'not sustainable';
How many peacekeeping operations have been conducted by each country in Africa?
CREATE TABLE peacekeeping_operations_2 (country VARCHAR(50),continent VARCHAR(50),operation_name VARCHAR(50),year INT); INSERT INTO peacekeeping_operations_2 (country,continent,operation_name,year) VALUES ('Egypt','Africa','UNOGIL',1958),('South Africa','Africa','UNAVEM',1991),('Nigeria','Africa','UNAMIR',1993),('Kenya','Africa','ONUSAL',1991),('Algeria','Africa','MINURSO',1991);
SELECT country, COUNT(*) as total_operations FROM peacekeeping_operations_2 WHERE continent = 'Africa' GROUP BY country;
Display the average voyage duration for each vessel type in the 'voyage_log' table
CREATE TABLE voyage_log (id INT,vessel_type VARCHAR(50),voyage_duration INT);
SELECT vessel_type, AVG(voyage_duration) FROM voyage_log GROUP BY vessel_type;
Calculate the percentage change in chemical waste production per site, quarter over quarter.
CREATE TABLE waste_production (site_name VARCHAR(50),quarter INT,year INT,waste_amount FLOAT); INSERT INTO waste_production (site_name,quarter,year,waste_amount) VALUES ('Site A',1,2021,150.5),('Site A',2,2021,160.7),('Site B',1,2021,125.7),('Site B',2,2021,130.5),('Site C',1,2021,200.3),('Site C',2,2021,210.9),('Site D',1,2021,75.9),('Site D',2,2021,80.1);
SELECT site_name, ((waste_amount - LAG(waste_amount) OVER (PARTITION BY site_name ORDER BY year, quarter))/ABS(LAG(waste_amount) OVER (PARTITION BY site_name ORDER BY year, quarter))) * 100 as pct_change FROM waste_production;
Delete records of drugs that were not approved in 2022 from the drug_approval table.
CREATE TABLE drug_approval (drug VARCHAR(20),approval_date DATE); INSERT INTO drug_approval (drug,approval_date) VALUES ('DrugA','2022-01-01'),('DrugB','2022-02-01'),('DrugC','2021-03-01');
DELETE FROM drug_approval WHERE drug NOT IN (SELECT drug FROM drug_approval WHERE approval_date BETWEEN '2022-01-01' AND '2022-12-31');
Who are the top 5 donors contributing to political campaigns in the state of New York, including their donation amounts?
CREATE TABLE donors(id INT,name TEXT,state TEXT,donations_total INT); INSERT INTO donors VALUES (1,'Donor A','New York',50000); INSERT INTO donors VALUES (2,'Donor B','New York',30000); INSERT INTO donors VALUES (3,'Donor C','California',70000); INSERT INTO donors VALUES (4,'Donor D','New York',60000); INSERT INTO donors VALUES (5,'Donor E','Texas',40000);
SELECT name, SUM(donations_total) as total_donations FROM donors WHERE state = 'New York' GROUP BY name ORDER BY total_donations DESC LIMIT 5;
Which warehouse has the highest inventory value for item 'Thingamajig'?
CREATE TABLE Inventory (id INT,item VARCHAR(50),quantity INT,purchase_price DECIMAL(10,2)); INSERT INTO Inventory (id,item,quantity,purchase_price) VALUES (1,'Thingamajig',100,25.50),(2,'Doohickey',75,18.35);
SELECT item, MAX(quantity * purchase_price) FROM Inventory WHERE item = 'Thingamajig' GROUP BY item;
How many renewable energy projects were initiated in California in 2020?
CREATE TABLE renewable_projects (state VARCHAR(20),year INT,num_projects INT); INSERT INTO renewable_projects (state,year,num_projects) VALUES ('California',2020,150),('California',2019,140),('California',2018,130),('Texas',2020,120),('Texas',2019,110);
SELECT num_projects FROM renewable_projects WHERE state = 'California' AND year = 2020;
What is the total volume of timber produced by countries in Europe?
CREATE TABLE timber_production (country VARCHAR(255),volume INT); INSERT INTO timber_production (country,volume) VALUES ('Canada',1200),('USA',2000),('France',500),('Germany',700);
SELECT SUM(volume) FROM timber_production WHERE country IN ('France', 'Germany');
Find the average price of products that are not ethically sourced in the 'Product' table
CREATE TABLE Product (product_id INT PRIMARY KEY,product_name VARCHAR(50),price DECIMAL(5,2),is_ethically_sourced BOOLEAN);
SELECT AVG(price) FROM Product WHERE is_ethically_sourced = FALSE;
What is the total number of autonomous vehicles in operation in Oslo?
CREATE TABLE autonomous_vehicles (vehicle_id INT,vehicle_type VARCHAR(20)); INSERT INTO autonomous_vehicles (vehicle_id,vehicle_type) VALUES (1,'Car'),(2,'Truck'),(3,'Car'),(4,'Bus'),(5,'Car');
SELECT COUNT(*) as num_vehicles FROM autonomous_vehicles WHERE vehicle_type IN ('Car', 'Truck', 'Bus');
What is the total number of tourists visiting Switzerland in 2023?
CREATE TABLE tourism_data (id INT,country VARCHAR(50),destination VARCHAR(50),arrival_date DATE,age INT); INSERT INTO tourism_data (id,country,destination,arrival_date,age) VALUES (8,'Brazil','Switzerland','2023-03-07',45),(9,'Argentina','Switzerland','2023-07-20',29);
SELECT COUNT(*) FROM tourism_data WHERE destination = 'Switzerland' AND YEAR(arrival_date) = 2023;
Find the total bioprocess engineering cost for each month in 2021.
CREATE SCHEMA if not exists engineering; USE engineering; CREATE TABLE if not exists costs (id INT,date DATE,amount DECIMAL(10,2)); INSERT INTO costs (id,date,amount) VALUES (1,'2021-01-01',15000.00),(2,'2021-01-15',7000.00),(3,'2021-02-01',12000.00),(4,'2021-03-01',10000.00);
SELECT MONTH(date) AS month, SUM(amount) AS total_cost FROM costs WHERE YEAR(date) = 2021 GROUP BY month;
What is the total CO2 emissions reduction from all carbon offset programs in Canada?
CREATE TABLE carbon_offsets_canada (id INT,name TEXT,country TEXT,co2_reduction INT); INSERT INTO carbon_offsets_canada (id,name,country,co2_reduction) VALUES (1,'The Gold Standard','Canada',50000),(2,'Verified Carbon Standard','Canada',75000);
SELECT SUM(co2_reduction) FROM carbon_offsets_canada WHERE country = 'Canada';
List the recycling rates for facility ID 1
CREATE TABLE WasteTypes (waste_type_id INT PRIMARY KEY,name VARCHAR,description VARCHAR); CREATE TABLE Facilities (facility_id INT PRIMARY KEY,name VARCHAR,location VARCHAR,capacity INT,waste_type_id INT,FOREIGN KEY (waste_type_id) REFERENCES WasteTypes(waste_type_id)); CREATE TABLE RecyclingRates (rate_id INT PRIMARY KEY,facility_id INT,year INT,rate DECIMAL,FOREIGN KEY (facility_id) REFERENCES Facilities(facility_id)); INSERT INTO RecyclingRates (rate_id,facility_id,year,rate) VALUES (1,1,2018,0.75),(2,1,2019,0.78),(3,1,2020,0.81);
SELECT year, rate FROM RecyclingRates WHERE facility_id = 1;
What is the total installed capacity of solar energy projects, grouped by project location?
CREATE TABLE RenewableEnergyProjects (id INT,project_type VARCHAR(50),project_location VARCHAR(50),installed_capacity FLOAT); INSERT INTO RenewableEnergyProjects (id,project_type,project_location,installed_capacity) VALUES (1,'Solar','NYC',1000.0),(2,'Wind','LA',1500.0),(3,'Solar','SF',1200.0);
SELECT project_location, SUM(installed_capacity) FROM RenewableEnergyProjects WHERE project_type = 'Solar' GROUP BY project_location;
What is the maximum revenue generated from a single sale in the 'footwear' category?
CREATE TABLE sales (sale_id INT,product_id INT,category VARCHAR(20),revenue DECIMAL(5,2)); INSERT INTO sales (sale_id,product_id,category,revenue) VALUES (1,1,'footwear',200.00),(2,2,'footwear',150.00),(3,3,'footwear',250.00);
SELECT MAX(revenue) FROM sales WHERE category = 'footwear';
Update the country for volunteer 'Bob' to Canada.
CREATE TABLE Volunteers (id INT,name VARCHAR(255),country VARCHAR(255)); INSERT INTO Volunteers (id,name,country) VALUES (1,'Alice','United States'),(2,'Bob','United States');
UPDATE Volunteers SET country = 'Canada' WHERE name = 'Bob';
Add a new faculty member to the faculty table
CREATE TABLE faculty (id INT,name VARCHAR(50),department VARCHAR(50),rank VARCHAR(10));
INSERT INTO faculty (id, name, department, rank) VALUES (101, 'Jane Smith', 'Mathematics', 'Assistant Professor');
What is the maximum budget for any genetic research project?
CREATE TABLE research_projects (id INT,name VARCHAR(50),budget FLOAT); INSERT INTO research_projects VALUES (1,'ProjectM',1000000); INSERT INTO research_projects VALUES (2,'ProjectN',1200000); INSERT INTO research_projects VALUES (3,'ProjectO',1500000);
SELECT MAX(budget) FROM research_projects;
What is the minimum water temperature in each month in 2021?
CREATE TABLE temperature_records (id INT,date DATE,temperature FLOAT);
SELECT EXTRACT(MONTH FROM date) AS month, MIN(temperature) FROM temperature_records WHERE date LIKE '2021-%' GROUP BY month;
What is the total revenue of products sold in each state?
CREATE TABLE Product_Revenue (product_id INT,revenue INT); INSERT INTO Product_Revenue (product_id,revenue) VALUES (1,100),(2,150),(3,200),(4,50),(5,300);
SELECT S.state_name, SUM(Revenue) FROM Sales S JOIN Product_Revenue PR ON S.product_id = PR.product_id GROUP BY S.state_name;
Update the timber_production table to set the annual_production to 1000 for 'Oregon'
CREATE TABLE timber_production (id INT PRIMARY KEY,state TEXT,annual_production INT); INSERT INTO timber_production (id,state,annual_production) VALUES (1,'Oregon',900);
UPDATE timber_production SET annual_production = 1000 WHERE state = 'Oregon';
What's the average rating of movies produced by studios located in the US?
CREATE TABLE Studios (studio_id INT,studio_name VARCHAR(255),country VARCHAR(255)); INSERT INTO Studios (studio_id,studio_name,country) VALUES (1,'Studio A','USA'),(2,'Studio B','USA'),(3,'Studio C','Canada'); CREATE TABLE Movies (movie_id INT,movie_name VARCHAR(255),studio_id INT,rating DECIMAL(3,2)); INSERT INTO Movies (movie_id,movie_name,studio_id,rating) VALUES (1,'Movie X',1,8.5),(2,'Movie Y',1,8.2),(3,'Movie Z',2,7.8),(4,'Movie W',3,6.9);
SELECT AVG(m.rating) FROM Movies m JOIN Studios s ON m.studio_id = s.studio_id WHERE s.country = 'USA';
What is the average monthly mobile data usage for customers in the 'urban' region?
CREATE TABLE subscribers (id INT,region VARCHAR(10),monthly_data_usage DECIMAL(5,2)); INSERT INTO subscribers (id,region,monthly_data_usage) VALUES (1,'urban',3.5),(2,'rural',2.2);
SELECT AVG(monthly_data_usage) FROM subscribers WHERE region = 'urban';
What is the average rating of cruelty-free skincare products launched in 2021?
CREATE TABLE skincare_products (product_id INT,name VARCHAR(255),launch_year INT,is_cruelty_free BOOLEAN,rating DECIMAL(2,1));
SELECT AVG(rating) FROM skincare_products WHERE is_cruelty_free = TRUE AND launch_year = 2021;
Identify the number of unique founders who have founded companies that have had at least one investment round.
CREATE TABLE company (id INT,name TEXT,founder_id INT); INSERT INTO company (id,name,founder_id) VALUES (1,'Acme Inc',101),(2,'Beta Corp',102),(3,'Gamma PLC',103); CREATE TABLE investment (id INT,company_id INT); INSERT INTO investment (id,company_id) VALUES (1,1),(2,1),(3,2);
SELECT COUNT(DISTINCT founder_id) FROM company WHERE id IN (SELECT company_id FROM investment)
What was the recycling rate in percentage for the region 'Cairo' in 2020?
CREATE TABLE recycling_rates (region VARCHAR(50),year INT,recycling_rate FLOAT); INSERT INTO recycling_rates (region,year,recycling_rate) VALUES ('Cairo',2020,45.67);
SELECT recycling_rate FROM recycling_rates WHERE region = 'Cairo' AND year = 2020;
How many events were held for each art form in 2021?
CREATE TABLE Events (event_id INT,event_date DATE,art_form VARCHAR(50)); INSERT INTO Events (event_id,event_date,art_form) VALUES (1,'2021-01-01','Dance'),(2,'2021-02-01','Theater'),(3,'2021-03-01','Music'),(4,'2021-04-01','Art'),(5,'2021-05-01','Dance'),(6,'2021-06-01','Theater'),(7,'2021-07-01','Music'),(8,'2021-08-01','Art');
SELECT art_form, COUNT(*) AS event_count FROM Events WHERE event_date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY art_form;
Calculate the total distance covered in miles by users in outdoor workouts.
CREATE TABLE OutdoorWorkouts (UserID INT,Distance FLOAT,WorkoutLocation VARCHAR(20)); INSERT INTO OutdoorWorkouts (UserID,Distance,WorkoutLocation) VALUES (1,4.2,'Park'),(1,3.5,'Street'),(2,5.1,'Trail'),(3,6.0,'Beach');
SELECT SUM(Distance) FROM OutdoorWorkouts WHERE WorkoutLocation IN ('Park', 'Street', 'Trail', 'Beach');
What is the most common mental health score in each district?
CREATE TABLE student_mental_health (student_id INT,district_id INT,mental_health_score INT,date DATE); CREATE TABLE districts (district_id INT,district_name VARCHAR(100));
SELECT d.district_name, mental_health_score as most_common_score FROM districts d JOIN (SELECT district_id, mental_health_score, COUNT(*) as count FROM student_mental_health GROUP BY district_id, mental_health_score) smh ON d.district_id = smh.district_id WHERE smh.count = (SELECT MAX(count) FROM (SELECT district_id, mental_health_score, COUNT(*) as count FROM student_mental_health GROUP BY district_id, mental_health_score) smh2 WHERE smh2.district_id = smh.district_id);
What is the maximum number of passengers an aircraft can carry?
CREATE TABLE Aircraft (aircraft_id INT,model VARCHAR(50),passengers INT); INSERT INTO Aircraft (aircraft_id,model,passengers) VALUES (1,'B747',416),(2,'A380',525),(3,'B777',396);
SELECT MAX(passengers) FROM Aircraft;
Which community projects in Brazil have the highest budget?
CREATE TABLE community_projects (id INT,name VARCHAR(100),budget INT,country VARCHAR(50)); INSERT INTO community_projects (id,name,budget,country) VALUES (1,'Projeto X',50000,'Brazil');
SELECT name, budget FROM community_projects WHERE country = 'Brazil' AND budget = (SELECT MAX(budget) FROM community_projects WHERE country = 'Brazil')
Show the number of athletes from each team in the 'Northern Division'
CREATE TABLE division_info (team VARCHAR(255),division VARCHAR(255)); INSERT INTO division_info (team,division) VALUES ('TeamC','Northern Division'),('TeamD','Southern Division');
SELECT a.team, COUNT(a.athlete_id) FROM athlete_stats a INNER JOIN division_info d ON a.team = d.team WHERE d.division = 'Northern Division' GROUP BY a.team;
How many building permits were issued per month in New York between 2020 and 2022?
CREATE TABLE Permits_NY (permit_id INT,permit_date DATE); INSERT INTO Permits_NY (permit_id,permit_date) VALUES (1,'2020-01-01'),(2,'2020-02-01'),(3,'2022-03-01');
SELECT permit_date, COUNT(*) OVER (PARTITION BY EXTRACT(YEAR FROM permit_date)) AS permits_per_year FROM Permits_NY WHERE permit_date >= '2020-01-01' AND permit_date < '2023-01-01' ORDER BY permit_date;
What is the minimum soil moisture (%) in corn fields in India in the past month?
CREATE TABLE soil_moisture (moisture DECIMAL(3,1),reading_date DATE,location TEXT); INSERT INTO soil_moisture (moisture,reading_date,location) VALUES (42.5,'2021-07-01','India'),(45.3,'2021-07-02','India'),(39.2,'2021-04-01','India');
SELECT MIN(moisture) FROM soil_moisture WHERE location = 'India' AND reading_date > DATE_SUB(CURDATE(), INTERVAL 1 MONTH) AND location LIKE '%corn%';
What is the average ticket price for events in Paris, France?
CREATE TABLE Events (id INT,city VARCHAR(20),country VARCHAR(20),price DECIMAL(5,2)); INSERT INTO Events (id,city,country,price) VALUES (1,'Paris','France',25.50),(2,'London','UK',30.00);
SELECT AVG(price) FROM Events WHERE city = 'Paris' AND country = 'France';
What is the total number of electric vehicles sold in the world?
CREATE TABLE if not exists EVSales (Id int,Vehicle varchar(100),City varchar(100),Country varchar(50),Quantity int); INSERT INTO EVSales (Id,Vehicle,City,Country,Quantity) VALUES (1,'Tesla Model 3','Tokyo','Japan',1000),(2,'Nissan Leaf','Yokohama','Japan',800),(3,'Mitsubishi i-MiEV','Osaka','Japan',1200),(4,'Toyota Prius','Nagoya','Japan',600),(5,'Honda Fit','Sapporo','Japan',900),(6,'Audi e-Tron','Berlin','Germany',700),(7,'Renault Zoe','Paris','France',1100),(8,'BYD e6','Beijing','China',1500),(9,'Ford Mustang Mach-E','New York','USA',1300),(10,'Volvo XC40 Recharge','Stockholm','Sweden',800);
SELECT SUM(Quantity) FROM EVSales WHERE Country != '';
List all the international calls made by a subscriber with the subscriber_id of 5 and the call duration, along with the international call charges.
CREATE TABLE subscribers (subscriber_id INT,name VARCHAR(50)); INSERT INTO subscribers (subscriber_id,name) VALUES (1,'John Doe'),(2,'Jane Smith'),(3,'Bob Johnson'),(5,'Alice Davis'); CREATE TABLE international_calls (call_id INT,subscriber_id INT,call_duration INT,call_charge DECIMAL(10,2)); INSERT INTO international_calls (call_id,subscriber_id,call_duration,call_charge) VALUES (1,5,30,1.25),(2,5,45,1.85),(3,2,20,1.10);
SELECT i.subscriber_id, i.call_duration, i.call_charge FROM subscribers s JOIN international_calls i ON s.subscriber_id = i.subscriber_id WHERE s.subscriber_id = 5;
Which indigenous food systems have the highest crop diversity?
CREATE TABLE Region (id INT,name VARCHAR(255)); INSERT INTO Region (id,name) VALUES (1,'Amazonia'),(2,'Central America'),(3,'Andes'); CREATE TABLE Crop (id INT,name VARCHAR(255),region_id INT); INSERT INTO Crop (id,name,region_id) VALUES (1,'Yuca',1),(2,'Corn',2),(3,'Potato',3),(4,'Quinoa',3);
SELECT Region.name, COUNT(DISTINCT Crop.name) FROM Region INNER JOIN Crop ON Region.id = Crop.region_id GROUP BY Region.name ORDER BY COUNT(DISTINCT Crop.name) DESC;
What is the average daily production of oil from wells owned by Chevron in the Marcellus Shale?
CREATE TABLE well_production (well_id INT,company VARCHAR(255),basin VARCHAR(255),daily_production INT); INSERT INTO well_production (well_id,company,basin,daily_production) VALUES (1,'Chevron','Marcellus Shale',100); INSERT INTO well_production (well_id,company,basin,daily_production) VALUES (2,'Chevron','Marcellus Shale',120); INSERT INTO well_production (well_id,company,basin,daily_production) VALUES (3,'Chevron','Bakken Formation',150);
SELECT AVG(daily_production) FROM well_production WHERE company = 'Chevron' AND basin = 'Marcellus Shale';
What is the number of donors who increased their donation amount from 2021 to 2022?
CREATE TABLE donations (id INT,donor VARCHAR(50),amount DECIMAL(10,2),donation_date DATE,year INT); INSERT INTO donations (id,donor,amount,donation_date,year) VALUES (1,'Sophia Lee',250,'2022-02-14',2022); INSERT INTO donations (id,donor,amount,donation_date,year) VALUES (2,'Ali Al-Khaleej',400,'2022-07-03',2022); INSERT INTO donations (id,donor,amount,donation_date,year) VALUES (3,'Sophia Lee',200,'2021-02-14',2021); INSERT INTO donations (id,donor,amount,donation_date,year) VALUES (4,'Ali Al-Khaleej',300,'2021-07-03',2021);
SELECT COUNT(DISTINCT donor) as increased_donor_count FROM donations d1 INNER JOIN donations d2 ON d1.donor = d2.donor WHERE d1.year = 2022 AND d2.year = 2021 AND d1.amount > d2.amount;
Identify the top three crops by acreage in 'urban' farming communities.
CREATE TABLE urban_community_farms AS SELECT f.name AS farmer_name,c.crop_name,c.acres FROM farmers f JOIN crops c ON f.id = c.farmer_id JOIN farm_communities fr ON f.id = fr.farm_id WHERE fr.community = 'urban'; INSERT INTO urban_community_farms (farmer_name,crop_name,acres) VALUES ('Jane','maize',50),('Alice','carrot',75),('Bob','soybean',100),('Jane','carrot',25);
SELECT crop_name, SUM(acres) AS total_acres FROM urban_community_farms GROUP BY crop_name ORDER BY total_acres DESC LIMIT 3;
What is the total number of employees in each mine?
CREATE TABLE mines (id INT,name TEXT,location TEXT,total_employees INT); INSERT INTO mines (id,name,location,total_employees) VALUES (1,'Golden Mine','Colorado,USA',300),(2,'Silver Ridge','Nevada,USA',400),(3,'Bronze Basin','Utah,USA',500);
SELECT name, SUM(total_employees) FROM mines GROUP BY name
Which circular economy initiatives have been implemented in Europe?
CREATE TABLE CircularEconomy(id INT,initiative VARCHAR(50),region VARCHAR(50)); INSERT INTO CircularEconomy(id,initiative,region) VALUES (1,'Clothing Swap Events','France'),(2,'Repair Cafes','Germany'),(3,'E-Waste Recycling Programs','Spain');
SELECT initiative, region FROM CircularEconomy WHERE region = 'Europe';
What was the total REE production for each quarter in 2020?
CREATE TABLE mines (id INT,name TEXT,location TEXT,quarter INT,annual_production INT); INSERT INTO mines (id,name,location,quarter,annual_production) VALUES (1,'Mine A','Country X',1,375),(2,'Mine B','Country Y',1,500),(3,'Mine C','Country Z',1,437),(1,'Mine A','Country X',2,400),(2,'Mine B','Country Y',2,500),(3,'Mine C','Country Z',2,437),(1,'Mine A','Country X',3,425),(2,'Mine B','Country Y',3,500),(3,'Mine C','Country Z',3,462),(1,'Mine A','Country X',4,375),(2,'Mine B','Country Y',4,500),(3,'Mine C','Country Z',4,463);
SELECT YEAR(timestamp) as year, QUARTER(timestamp) as quarter, SUM(annual_production) as total_production FROM mines WHERE YEAR(timestamp) = 2020 GROUP BY year, quarter;
Insert a new product into the "products" table
CREATE TABLE products (product_id INT,name VARCHAR(255),category VARCHAR(255),price DECIMAL(5,2));
INSERT INTO products (product_id, name, category, price) VALUES (1001, 'Organic Cotton Shirt', 'Clothing', 35.99);
Count the number of gas wells in North Dakota and Montana and their total daily production
CREATE TABLE gas_wells (well_id INT,state VARCHAR(10),daily_production FLOAT); INSERT INTO gas_wells (well_id,state,daily_production) VALUES (1,'North Dakota',120.5),(2,'North Dakota',130.2),(3,'Montana',105.6);
SELECT state, COUNT(*), SUM(daily_production) FROM gas_wells WHERE state IN ('North Dakota', 'Montana') GROUP BY state;
What was the average donation amount per donor in Q3 2022?
CREATE TABLE donors (donor_id INT,donation_date DATE,donation_amount DECIMAL(10,2)); INSERT INTO donors VALUES (8,'2022-09-01',100.00),(9,'2022-10-15',200.00),(10,'2022-11-05',300.00);
SELECT AVG(donation_amount) FROM donors WHERE donation_date BETWEEN '2022-07-01' AND '2022-09-30' GROUP BY donor_id HAVING COUNT(*) > 0;
What is the minimum maintenance cost for military vehicles?
CREATE TABLE military_vehicles (id INT,model VARCHAR(50),maintenance_cost FLOAT); INSERT INTO military_vehicles (id,model,maintenance_cost) VALUES (1,'HMMWV',12000),(2,'Stryker',18000),(3,'Tank',25000);
SELECT MIN(maintenance_cost) FROM military_vehicles;
What is the total funding received by companies founded by Black entrepreneurs in the renewable energy sector?
CREATE TABLE companies (company_id INT,company_name TEXT,industry TEXT,founding_year INT,founder_race TEXT); INSERT INTO companies (company_id,company_name,industry,founding_year,founder_race) VALUES (1,'SolarForce','Renewable Energy',2015,'Black'); CREATE TABLE funding_records (funding_id INT,company_id INT,amount INT); INSERT INTO funding_records (funding_id,company_id,amount) VALUES (1,1,1200000);
SELECT SUM(fr.amount) FROM companies c JOIN funding_records fr ON c.company_id = fr.company_id WHERE c.industry = 'Renewable Energy' AND c.founder_race = 'Black';
List all oceanographic studies in 'Atlantic Ocean' since 2010.
CREATE TABLE if not exists oceanographic_studies (id INT,name TEXT,location TEXT,year INT);
SELECT * FROM oceanographic_studies WHERE location = 'Atlantic Ocean' AND year >= 2010;
Update the cargo_tracking table and set the status as 'Delivered' for records where the destination_port is 'Tokyo'
CREATE TABLE cargo_tracking (voyage_date DATE,departure_port VARCHAR(255),destination_port VARCHAR(255),cargo_weight INT,vessel_name VARCHAR(255),status VARCHAR(255));
UPDATE cargo_tracking SET status = 'Delivered' WHERE destination_port = 'Tokyo';
What is the total square footage of sustainable buildings in New York City?
CREATE TABLE sustainable_buildings (city VARCHAR(255),total_sqft INTEGER,sustainable BOOLEAN); INSERT INTO sustainable_buildings (city,total_sqft,sustainable) VALUES ('New York City',5000000,true),('New York City',3000000,false),('Los Angeles',4000000,true);
SELECT SUM(total_sqft) FROM sustainable_buildings WHERE city = 'New York City' AND sustainable = true;
What is the average age of users who attended events in the "Dance" category?
CREATE TABLE Users (UserID INT,Age INT,Category VARCHAR(50)); INSERT INTO Users (UserID,Age,Category) VALUES (1,30,'Dance'),(2,25,'Music'); CREATE TABLE Events (EventID INT,Category VARCHAR(50)); INSERT INTO Events (EventID,Category) VALUES (1,'Dance'),(2,'Music');
SELECT AVG(Users.Age) AS AverageAge FROM Users INNER JOIN Events ON Users.Category = Events.Category WHERE Events.Category = 'Dance';
How many workers in each factory are not paid a living wage?
CREATE TABLE factories (id INT,name VARCHAR(255),workers INT,living_wage_workers INT); INSERT INTO factories (id,name,workers,living_wage_workers) VALUES (1,'EthicalFactory1',500,450),(2,'EthicalFactory2',300,280),(3,'EthicalFactory3',400,360),(4,'EthicalFactory4',600,540),(5,'EthicalFactory5',700,630);
SELECT name, (workers - living_wage_workers) AS non_living_wage_workers FROM factories;
Insert a new donation record for donor 5 with a donation amount of 800 on 2021-05-01.
CREATE TABLE Donations (donor_id INT,donation_amount DECIMAL(10,2),donation_date DATE);
INSERT INTO Donations (donor_id, donation_amount, donation_date) VALUES (5, 800, '2021-05-01');
How many pollution control initiatives are there in each region?
CREATE TABLE pollution_control_initiatives (id INT,initiative TEXT,region TEXT); INSERT INTO pollution_control_initiatives (id,initiative,region) VALUES (1,'Initiative X','North Atlantic'),(2,'Initiative Y','Arctic'),(3,'Initiative Z','North Atlantic'),(4,'Initiative W','Indian Ocean');
SELECT region, COUNT(*) FROM pollution_control_initiatives GROUP BY region;
What is the maximum and minimum serving size for dishes in the 'Vegan' cuisine category?
CREATE TABLE Dishes (id INT,cuisine VARCHAR(255),serving_size INT); INSERT INTO Dishes (id,cuisine,serving_size) VALUES (1,'Vegan',300),(2,'Vegan',450),(3,'Vegan',200),(4,'Italian',500);
SELECT cuisine, MIN(serving_size) as min_serving_size, MAX(serving_size) as max_serving_size FROM Dishes WHERE cuisine = 'Vegan' GROUP BY cuisine;
Find the number of defense diplomacy events where 'country A' was involved in the last 3 years
CREATE TABLE defense_diplomacy (country VARCHAR(50),event_date DATE);
SELECT COUNT(*) FROM defense_diplomacy WHERE country = 'country A' AND event_date >= DATE(CURRENT_DATE) - INTERVAL 3 YEAR;
Delete all cases with a billing amount of $0.
CREATE TABLE cases (case_id INT,billing_amount INT); INSERT INTO cases (case_id,billing_amount) VALUES (1,5000),(2,0),(3,4000);
DELETE FROM cases WHERE billing_amount = 0;
What is the number of employees who have completed diversity and inclusion training, by department?
CREATE TABLE departments (dept_id INT,dept_name TEXT); INSERT INTO departments (dept_id,dept_name) VALUES (1,'HR'),(2,'IT'),(3,'Sales'); CREATE TABLE employees (employee_id INT,name TEXT,dept_id INT,diversity_inclusion_training BOOLEAN); INSERT INTO employees (employee_id,name,dept_id,diversity_inclusion_training) VALUES (1,'Alice',1,TRUE),(2,'Bob',2,FALSE),(3,'Charlie',1,TRUE),(4,'Dave',2,TRUE),(5,'Eve',1,FALSE);
SELECT dept_name, SUM(CASE WHEN diversity_inclusion_training THEN 1 ELSE 0 END) AS num_trained FROM employees JOIN departments ON employees.dept_id = departments.dept_id GROUP BY dept_name;
What is the total runtime (in minutes) of all the movies and TV shows in the media table?
CREATE TABLE media (id INT,title TEXT,type TEXT,runtime INT);
SELECT SUM(runtime) FROM media WHERE type = 'movie' UNION SELECT SUM(runtime) FROM media WHERE type = 'tv_show';
How many unique donors made donations in each region in 2021, and what was the total donation amount per region for the year?
CREATE TABLE Donors (DonorID INT,DonorName TEXT,DonorRegion TEXT,DonationAmount FLOAT,DonationDate DATE); INSERT INTO Donors (DonorID,DonorName,DonorRegion,DonationAmount,DonationDate) VALUES (1,'John Doe','North',500.00,'2021-01-01'),(2,'Jane Smith','South',350.00,'2021-02-14'),(3,'Bob Johnson','East',1000.00,'2021-12-31'),(4,'Alice Williams','North',200.00,'2021-03-15');
SELECT DonorRegion, COUNT(DISTINCT DonorID) as UniqueDonors, SUM(DonationAmount) as TotalDonationPerYear FROM Donors WHERE YEAR(DonationDate) = 2021 GROUP BY DonorRegion;
Identify the peacekeeping operations where the African Union is the lead organization
CREATE TABLE peacekeeping_operations (id INT,operation_name VARCHAR(255),lead_organization VARCHAR(255),start_date DATE); INSERT INTO peacekeeping_operations (id,operation_name,lead_organization,start_date) VALUES (1,'AMISOM','African Union','2007-01-19'),(2,'MINUSMA','United Nations','2013-07-25');
SELECT * FROM peacekeeping_operations WHERE lead_organization = 'African Union';
Insert new records for 5 employees who joined the mining department in January 2022.
CREATE TABLE Employees (employee_id INT,name VARCHAR(50),gender VARCHAR(10),department VARCHAR(20),hire_date DATE); INSERT INTO Employees (employee_id,name,gender,department,hire_date) VALUES (1,'John Doe','Male','Mining','2020-01-01'),(2,'Jane Smith','Female','Mining','2019-06-15');
INSERT INTO Employees (employee_id, name, gender, department, hire_date) VALUES (4, 'Bruce Wayne', 'Male', 'Mining', '2022-01-05'), (5, 'Clark Kent', 'Male', 'Mining', '2022-01-10'), (6, 'Diana Prince', 'Female', 'Mining', '2022-01-12'), (7, 'Peter Parker', 'Male', 'Mining', '2022-01-15'), (8, 'Natasha Romanoff', 'Female', 'Mining', '2022-01-20');
Calculate the average range of vehicles grouped by type in the 'green_vehicles' table
CREATE TABLE green_vehicles (id INT PRIMARY KEY,make VARCHAR(50),model VARCHAR(50),year INT,type VARCHAR(50),range INT);
SELECT type, AVG(range) FROM green_vehicles GROUP BY type;
What is the maximum daily production rate of oil wells in the Arctic Ocean that were drilled after 2016?
CREATE TABLE arctic_ocean (id INT,well_name VARCHAR(255),drill_date DATE,daily_production_oil FLOAT);
SELECT MAX(daily_production_oil) as max_daily_production_oil FROM arctic_ocean WHERE drill_date > '2016-12-31';
Insert new records for the rare earth elements promethium and samarium into the environmental_impact table
CREATE TABLE environmental_impact (id INT PRIMARY KEY,element VARCHAR(10),impact_score INT);
INSERT INTO environmental_impact (element, impact_score) VALUES ('promethium', 7), ('samarium', 6);
What is the difference between the maximum performance score of models trained on dataset A and dataset B, for each region?
CREATE TABLE models (id INT,dataset VARCHAR(20),performance FLOAT,region VARCHAR(20)); INSERT INTO models VALUES (1,'datasetA',4.3,'Europe'),(2,'datasetA',4.5,'Asia'),(3,'datasetB',3.9,'Africa'),(4,'datasetB',4.1,'Africa'),(5,'datasetA',4.2,'North America');
SELECT region, MAX(m.performance) - (SELECT MAX(performance) FROM models m2 WHERE m.region = m2.region AND m2.dataset = 'datasetB') FROM models m WHERE m.dataset = 'datasetA' GROUP BY region;
Calculate the average monthly water consumption per capita in the city of Austin
CREATE TABLE city (id INT,name VARCHAR(255)); INSERT INTO city (id,name) VALUES (1,'Austin'); CREATE TABLE water_meter_readings (id INT,city_id INT,consumption FLOAT,reading_date DATE); INSERT INTO water_meter_readings (id,city_id,consumption,reading_date) VALUES (1,1,100,'2022-01-01'); INSERT INTO water_meter_readings (id,city_id,consumption,reading_date) VALUES (2,1,120,'2022-02-01');
SELECT AVG(consumption / population) FROM (SELECT water_meter_readings.consumption, city.population, EXTRACT(MONTH FROM water_meter_readings.reading_date) as month FROM water_meter_readings JOIN city ON water_meter_readings.city_id = city.id WHERE city.name = 'Austin') as subquery GROUP BY month;
Delete wells that have gas production less than 5000 in 2020?
CREATE TABLE well (well_id INT,well_name TEXT,gas_production_2020 FLOAT); INSERT INTO well (well_id,well_name,gas_production_2020) VALUES (1,'Well A',9000),(2,'Well B',11000),(3,'Well C',8000);
DELETE FROM well WHERE gas_production_2020 < 5000;