instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the total number of autonomous driving research papers published in the research_papers table?
CREATE TABLE research_papers (id INT,title VARCHAR(100),publication_year INT,abstract TEXT); INSERT INTO research_papers (id,title,publication_year,abstract) VALUES (1,'Deep Learning for Autonomous Driving',2021,'In this paper,we propose a deep learning approach for autonomous driving...'),(2,'Motion Planning for Auton...
SELECT COUNT(*) FROM research_papers;
Which countries have the highest and lowest average flight speed in the FlightLogs table?
CREATE TABLE FlightLogs (flight_id INT,aircraft_model VARCHAR(50),country VARCHAR(50),flight_speed FLOAT,flight_date DATE); INSERT INTO FlightLogs (flight_id,aircraft_model,country,flight_speed,flight_date) VALUES (1,'B747','USA',850.0,'2022-01-01'),(2,'A320','France',800.0,'2021-05-01'),(3,'B747','Canada',900.0,'2022-...
SELECT country, AVG(flight_speed) AS avg_flight_speed FROM (SELECT country, flight_speed, ROW_NUMBER() OVER (PARTITION BY country ORDER BY flight_speed DESC) AS high_avg, ROW_NUMBER() OVER (PARTITION BY country ORDER BY flight_speed ASC) AS low_avg FROM FlightLogs) AS subquery WHERE high_avg = 1 OR low_avg = 1 GROUP BY...
How many visitors identify as non-binary at music festivals?
CREATE TABLE events (event_id INT,event_name VARCHAR(50),event_type VARCHAR(50),visitor_count INT,gender VARCHAR(50));
SELECT SUM(CASE WHEN gender = 'Non-binary' THEN visitor_count ELSE 0 END) AS non_binary_visitors FROM events WHERE event_type = 'Music Festival';
List all investments made by investors based in the US?
CREATE TABLE Investors (InvestorID INT,InvestorName VARCHAR(50),Country VARCHAR(20)); CREATE TABLE Investments (InvestmentID INT,InvestorID INT,CompanyID INT,InvestmentAmount DECIMAL(10,2));
SELECT I.InvestorName, I.InvestmentAmount FROM Investments I JOIN Investors ON I.InvestorID = Investors.InvestorID WHERE Investors.Country = 'USA';
What is the number of products sold in each category in the past week, ordered by the number of products sold in descending order?
CREATE TABLE orders (id INT PRIMARY KEY,product_id INT,quantity INT,order_date DATETIME,category VARCHAR(255),FOREIGN KEY (product_id) REFERENCES products(id)); INSERT INTO orders (id,product_id,quantity,order_date,category) VALUES (1,1,10,'2022-07-01 10:00:00','Category A'),(2,2,20,'2022-07-02 15:00:00','Category B'),...
SELECT o.category, COUNT(o.product_id) as num_products FROM orders o WHERE o.order_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK) GROUP BY o.category ORDER BY num_products DESC;
What is the total amount of donations for each donor in the last year?
CREATE TABLE donors (id INT PRIMARY KEY,donor_name VARCHAR(50),donation_date DATE,donation_amount DECIMAL(10,2)); INSERT INTO donors (id,donor_name,donation_date,donation_amount) VALUES (1,'John Doe','2022-01-01',100.00),(2,'Jane Smith','2022-02-01',200.00),(3,'Mike Johnson','2021-12-31',50.00);
SELECT donor_name, SUM(donation_amount) as total_donations FROM donors WHERE donation_date >= DATE_SUB(NOW(), INTERVAL 1 YEAR) GROUP BY donor_name;
What is the total funding amount for companies founded by underrepresented minorities each year?
CREATE TABLE funding (funding_id INT,company_id INT,amount DECIMAL(10,2)); CREATE TABLE companies (company_id INT,founding_year INT,underrepresented_minority BOOLEAN); INSERT INTO funding (funding_id,company_id,amount) VALUES (1,1,150000.00),(2,2,200000.00),(3,3,250000.00); INSERT INTO companies (company_id,founding_ye...
SELECT founding_year, SUM(funding.amount) as total_funding_underrepresented_minorities FROM funding JOIN companies ON funding.company_id = companies.company_id WHERE companies.underrepresented_minority = true GROUP BY founding_year;
Which countries have the lowest average sustainability scores for fabrics and what are their corresponding manufacturing costs?
CREATE TABLE fabrics (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),sustainability_score INT); INSERT INTO fabrics (id,name,country,sustainability_score) VALUES (1,'Fabric A','Country C',60); INSERT INTO fabrics (id,name,country,sustainability_score) VALUES (2,'Fabric B','Country D',65); CREATE TABLE manufa...
SELECT f.country, AVG(f.sustainability_score) AS avg_sustainability_score, m.manufacturing_cost FROM fabrics f CROSS JOIN (SELECT '2022-01-01' AS date, SUM(cost) AS manufacturing_cost FROM manufacturing WHERE fabric_id = f.id) m GROUP BY f.country HAVING AVG(f.sustainability_score) = (SELECT MIN(avg_sustainability_scor...
Delete health equity metrics table if it exists
CREATE TABLE HealthEquityMetrics (MetricID INT PRIMARY KEY,MetricName TEXT,MetricGoal INT,MetricCurrent INT);
DROP TABLE IF EXISTS HealthEquityMetrics;
What is the total number of 'recycling' facilities in 'Japan'?
CREATE TABLE facilities (id INT,name TEXT,type TEXT,location TEXT); INSERT INTO facilities (id,name,type,location) VALUES (1,'recycling plant','recycling','Japan'),(2,'waste treatment plant','waste','Japan'),(3,'recycling plant','recycling','China');
SELECT COUNT(*) FROM facilities WHERE type = 'recycling' AND location = 'Japan';
Insert a new record into the 'community_education' table for the 'Polar Bear Conservation Initiative'
CREATE TABLE community_education (id INT,center_name VARCHAR(50),location VARCHAR(50),num_participants INT);
INSERT INTO community_education (id, center_name, location, num_participants) VALUES (1, 'Polar Bear Conservation Initiative', 'Canada', NULL);
Show the total fuel efficiency for vessels with IDs "VT-123" and "VT-456" from the "vessel_performance" table.
CREATE TABLE vessel_performance (id INT PRIMARY KEY,vessel_id INT,max_speed FLOAT,avg_speed FLOAT,fuel_efficiency FLOAT);
SELECT SUM(fuel_efficiency) FROM vessel_performance WHERE vessel_id IN (123, 456);
Update the price column to increase the price of all vegan entrees by $1.50
CREATE TABLE menu_items (menu_item_id INT,name VARCHAR(50),description TEXT,price DECIMAL(5,2),category VARCHAR(20),is_vegan BOOLEAN);
UPDATE menu_items SET price = price + 1.50 WHERE category = 'entree' AND is_vegan = TRUE;
Insert a new record in the 'electric_vehicles' table for a new electric car from 'EcoCar'
CREATE TABLE electric_vehicles (id INT PRIMARY KEY,manufacturer VARCHAR(255),model VARCHAR(255),year INT,battery_range INT);
INSERT INTO electric_vehicles (id, manufacturer, model, year, battery_range) VALUES ((SELECT COALESCE(MAX(id), 0) + 1 FROM electric_vehicles), 'EcoCar', 'EcoCar X', 2022, 300);
Update the research_topic of 'TuSimple' to 'Computer Vision' in the 'autonomous_driving_research' table
CREATE TABLE autonomous_driving_research (id INT,vehicle_name VARCHAR(50),research_topic VARCHAR(50));
UPDATE autonomous_driving_research SET research_topic = 'Computer Vision' WHERE vehicle_name = 'TuSimple';
What is the minimum funding amount received by a company founded by a veteran in the biotech industry?
CREATE TABLE companies (id INT,name TEXT,industry TEXT,founding_date DATE,founder_status TEXT); INSERT INTO companies (id,name,industry,founding_date,founder_status) VALUES (1,'MedicalInnovations','Biotech','2017-01-01','Veteran');
SELECT MIN(funding_amount) FROM funding_records JOIN companies ON funding_records.company_id = companies.id WHERE companies.industry = 'Biotech' AND companies.founder_status = 'Veteran';
What is the maximum word count for articles by 'John Doe'?
CREATE TABLE news (title VARCHAR(255),author VARCHAR(255),word_count INT,category VARCHAR(255)); INSERT INTO news (title,author,word_count,category) VALUES ('Sample News','John Doe',500,'Politics');
SELECT MAX(word_count) FROM news WHERE author = 'John Doe';
What is the maximum playtime for each player on a single day?
CREATE TABLE player_daily_playtime (player_id INT,play_date DATE,playtime INT); INSERT INTO player_daily_playtime (player_id,play_date,playtime) VALUES (1,'2021-01-01',100),(1,'2021-01-02',200),(1,'2021-01-03',300),(2,'2021-01-01',400),(2,'2021-01-02',500),(2,'2021-01-03',600);
SELECT player_id, MAX(playtime) FROM player_daily_playtime GROUP BY player_id;
How many tourists visited each Caribbean country's top beach in 2021?
CREATE TABLE top_beaches (country VARCHAR(30),beach VARCHAR(50),visitors INT,year INT); INSERT INTO top_beaches (country,beach,visitors,year) VALUES ('Bahamas','Pink Sands Beach',500000,2021),('Jamaica','Seven Mile Beach',700000,2021),('Barbados','Crane Beach',400000,2021);
SELECT country, SUM(visitors) as total_visitors FROM top_beaches WHERE year = 2021 GROUP BY country;
Which property in the housing_affordability table has the largest size?
CREATE TABLE housing_affordability (property_id INT,size FLOAT,owner_id INT,location VARCHAR(255)); INSERT INTO housing_affordability (property_id,size,owner_id,location) VALUES (1,800,1,'City A'),(2,900,1,'City A'),(3,1000,2,'City B');
SELECT property_id, size FROM housing_affordability ORDER BY size DESC LIMIT 1;
Delete records in the 'defense_contracts' table where the 'contract_amount' is zero
CREATE TABLE defense_contracts (contract_id INT,contract_amount FLOAT,award_date DATE);
DELETE FROM defense_contracts WHERE contract_amount = 0;
What are the circular economy initiatives in the EU, including their budgets and the number of people they have impacted, as of 2021?
CREATE TABLE circular_initiatives_eu (initiative TEXT,budget INTEGER,people_impacted INTEGER,start_date DATE);
SELECT initiative, budget, people_impacted FROM circular_initiatives_eu WHERE country = 'EU' AND start_date <= '2021-12-31';
Which company launched the most recent innovation?
CREATE TABLE Company (id INT,name VARCHAR(50)); INSERT INTO Company (id,name) VALUES (1,'Acme Inc'); INSERT INTO Company (id,name) VALUES (2,'Beta Corp'); INSERT INTO Company (id,name) VALUES (3,'Gamma Startup'); CREATE TABLE Innovation (company_id INT,innovation_type VARCHAR(50),launch_date DATE); INSERT INTO Innovati...
SELECT c.name, MAX(launch_date) as max_launch_date FROM Company c JOIN Innovation i ON c.id = i.company_id GROUP BY c.name;
What is the average depth of marine life research stations in each country, sorted by the average depth?
CREATE TABLE marine_life_research_stations (id INT,station_name TEXT,country TEXT,depth FLOAT);
SELECT country, AVG(depth) AS avg_depth FROM marine_life_research_stations GROUP BY country ORDER BY avg_depth DESC;
What is the percentage of locally sourced ingredients used in menu items?
CREATE TABLE menu_items (item_id INT,item_name VARCHAR(50),uses_local BOOLEAN); INSERT INTO menu_items (item_id,item_name,uses_local) VALUES (1,'Chicken Caesar Salad',false),(2,'Margherita Pizza',true),(3,'Beef Tacos',false);
SELECT COUNT(*) * 100.0 / (SELECT COUNT(*) FROM menu_items) AS percentage FROM menu_items WHERE uses_local = true;
Delete all records from the 'accessibility' table where the 'station_id' is not present in the 'stations' table
CREATE TABLE accessibility (accessibility_id INT,station_id INT,wheelchair_accessibility VARCHAR(10)); CREATE TABLE stations (station_id INT,station_name VARCHAR(50),station_type VARCHAR(20)); INSERT INTO stations (station_id,station_name,station_type) VALUES (1,'StationA','Underground'),(2,'StationB','Overground'); IN...
DELETE FROM accessibility WHERE station_id NOT IN (SELECT station_id FROM stations);
What is the success rate of each mediator in the 'case_outcomes' table?
CREATE TABLE case_outcomes (case_id INT,mediator_id INT,case_status VARCHAR(20));
SELECT mediator_id, (SUM(CASE WHEN case_status = 'Success' THEN 1 ELSE 0 END) / COUNT(*)) * 100.0 AS success_rate FROM case_outcomes GROUP BY mediator_id;
What is the percentage of revenue that comes from each cuisine type?
CREATE TABLE restaurants (restaurant_id INT,cuisine VARCHAR(255),revenue INT); INSERT INTO restaurants (restaurant_id,cuisine,revenue) VALUES (1,'Italian',5000),(2,'Mexican',7000),(3,'Italian',8000);
SELECT cuisine, (SUM(revenue) OVER (PARTITION BY cuisine) * 100.0 / SUM(revenue) OVER ()) AS percentage_of_revenue FROM restaurants;
Which countries have no renewable energy projects in the renewable_projects table?
CREATE TABLE renewable_projects (id INT,project_name VARCHAR(100),country VARCHAR(50)); INSERT INTO renewable_projects (id,project_name,country) VALUES (1,'Renewable Project 1','Germany'),(2,'Renewable Project 2','Sweden');
SELECT rp.country FROM renewable_projects rp GROUP BY rp.country HAVING COUNT(*) = 0;
How many unique cities are represented in the government departments dataset?
CREATE TABLE government_departments (dept_name TEXT,city TEXT); INSERT INTO government_departments (dept_name,city) VALUES ('Human Services Department','CityA'),('Education Department','CityB'),('Health Department','CityA'),('Library Department','CityC'),('Transportation Department','CityD');
SELECT COUNT(DISTINCT city) FROM government_departments;
What is the number of marine protected areas in the Southern Ocean?
CREATE TABLE marine_protected_areas (name TEXT,avg_depth REAL,ocean TEXT); INSERT INTO marine_protected_areas (name,avg_depth,ocean) VALUES ('Ross Sea Marine Protected Area',1900,'Southern'),('Kerguelen Islands Marine Reserve',1000,'Southern');
SELECT COUNT(*) FROM marine_protected_areas WHERE ocean = 'Southern';
What is the highest rated eco-friendly hotel in Amsterdam?
CREATE TABLE eco_hotels (hotel_id INT,name TEXT,city TEXT,rating FLOAT); INSERT INTO eco_hotels (hotel_id,name,city,rating) VALUES (1,'Eco Hotel Amsterdam','Amsterdam',4.7),(2,'Green Haven Amsterdam','Amsterdam',4.5),(3,'Eco Lodge Amsterdam','Amsterdam',4.8);
SELECT name FROM eco_hotels WHERE city = 'Amsterdam' ORDER BY rating DESC LIMIT 1;
What is the total quantity of each feed type?
CREATE TABLE Feed (FeedID INT,FeedType VARCHAR(50),FeedCost DECIMAL(5,2),FarmID INT); INSERT INTO Feed (FeedID,FeedType,FeedCost,FarmID) VALUES (1,'Pellets',1.25,1); INSERT INTO Feed (FeedID,FeedType,FeedCost,FarmID) VALUES (2,'Granules',1.15,2); CREATE TABLE FeedStock (FeedStockID INT,FeedType VARCHAR(50),Quantity INT...
SELECT Feed.FeedType, SUM(FeedStock.Quantity) FROM Feed INNER JOIN FeedStock ON Feed.FeedID = FeedStock.FeedID GROUP BY Feed.FeedType;
What is the minimum price of dishes that are both vegan and gluten-free?
CREATE TABLE Menu (item_id INT,name VARCHAR(50),is_vegan BOOLEAN,is_gluten_free BOOLEAN,price DECIMAL(5,2)); INSERT INTO Menu (item_id,name,is_vegan,is_gluten_free,price) VALUES (1,'Vegan Burger',true,false,12.99),(2,'Vegan Pizza',true,true,14.99);
SELECT MIN(price) FROM Menu WHERE is_vegan = true AND is_gluten_free = true;
How many crops have been grown in the 'indigenous' farming systems in the 'rainy' season?
CREATE TABLE crops (id INT,name VARCHAR(20),growing_season VARCHAR(10),farming_system VARCHAR(20));
SELECT COUNT(*) FROM crops WHERE farming_system = 'indigenous' AND growing_season = 'rainy';
Find the total sales for each salesperson who has made sales over $50,000.
CREATE TABLE sales (id INT,salesperson VARCHAR(255),sales_amount DECIMAL(10,2)); INSERT INTO sales (id,salesperson,sales_amount) VALUES (1,'Alex',55000.00),(2,'Taylor',40000.00),(3,'Alex',75000.00),(4,'Jamie',30000.00);
SELECT salesperson, SUM(sales_amount) FROM sales WHERE sales_amount > 50000 GROUP BY salesperson;
What was the total number of visitors from each continent in 2021?
CREATE TABLE if not exists VisitorContinents (Continent VARCHAR(50),Country VARCHAR(50),Visitors INT); INSERT INTO VisitorContinents (Continent,Country,Visitors) VALUES ('North America','Canada',150000),('Asia','Japan',200000),('Europe','France',300000),('Oceania','Australia',250000),('Africa','Egypt',100000),('South A...
SELECT a.Continent, SUM(a.Visitors) AS TotalVisitors FROM VisitorContinents a WHERE a.Year = 2021 GROUP BY a.Continent;
What is the total training cost for each department, including only mandatory training programs?
CREATE TABLE Employees (EmployeeID int,Department varchar(50)); CREATE TABLE TrainingPrograms (TrainingProgramID int,TrainingProgram varchar(50),Department varchar(50),Mandatory boolean); CREATE TABLE EmployeeTrainings (EmployeeID int,TrainingProgramID int,Cost int,TrainingDate date);
SELECT e.Department, SUM(et.Cost) as TotalCost FROM Employees e JOIN TrainingPrograms tp ON e.Department = tp.Department JOIN EmployeeTrainings et ON tp.TrainingProgramID = et.TrainingProgramID WHERE tp.Mandatory = TRUE GROUP BY e.Department;
List all countries that have launched satellites, but have not launched any missions to the International Space Station.
CREATE TABLE SatelliteLaunches (SatelliteName TEXT,LaunchCountry TEXT);CREATE TABLE ISSMissions (AstronautName TEXT,MissionCountry TEXT);
(SELECT LaunchCountry FROM SatelliteLaunches EXCEPT SELECT MissionCountry FROM ISSMissions) EXCEPT (SELECT NULL);
Find the total revenue of horror and romance movies.
CREATE TABLE movies (id INT,title VARCHAR(50),genre VARCHAR(20),revenue DECIMAL(10,2)); INSERT INTO movies (id,title,genre,revenue) VALUES (1,'MovieC','Horror',15000000),(2,'MovieD','Romance',12000000);
SELECT SUM(revenue) FROM movies WHERE genre IN ('Horror', 'Romance');
List the defense projects that Contractor Z has in common with Contractor W.
CREATE TABLE ProjectParticipation (ParticipationID INT,Contractor VARCHAR(255),ProjectID INT); INSERT INTO ProjectParticipation (ParticipationID,Contractor,ProjectID) VALUES (1,'Contractor Z',1),(2,'Contractor W',1);
SELECT pp1.ProjectID FROM ProjectParticipation pp1 INNER JOIN ProjectParticipation pp2 ON pp1.ProjectID = pp2.ProjectID WHERE pp1.Contractor = 'Contractor Z' AND pp2.Contractor = 'Contractor W';
What is the average explainability score of models developed by organizations based in the United States?
CREATE TABLE model (model_id INT,name VARCHAR(50),organization_id INT,explainability_score INT,country VARCHAR(50)); INSERT INTO model VALUES (1,'ModelA',1,8,'United States'),(2,'ModelB',2,7,'Canada'),(3,'ModelC',3,6,'United Kingdom'),(4,'ModelD',1,9,'United States'),(5,'ModelE',3,5,'Canada'); CREATE TABLE organization...
SELECT AVG(model.explainability_score) FROM model JOIN organization ON model.organization_id = organization.organization_id WHERE model.country = 'United States';
What is the number of flu cases reported, by state, in the last week?
CREATE TABLE states (state_id INT,state_name VARCHAR(255),region VARCHAR(255)); CREATE TABLE flu_cases (case_id INT,state_id INT,case_date DATE); INSERT INTO states (state_id,state_name,region) VALUES (1,'California','West'),(2,'Texas','South'),(3,'New York','East'),(4,'Alaska','North'); INSERT INTO flu_cases (case_id,...
SELECT states.state_name, COUNT(flu_cases.case_id) as flu_cases_count FROM states JOIN flu_cases ON states.state_id = flu_cases.state_id WHERE flu_cases.case_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK) AND CURRENT_DATE GROUP BY states.state_name;
What is the total number of safety incidents for each vessel type, including types with no incidents?
CREATE TABLE vessel_types (type_id INT,type_name VARCHAR(50)); CREATE TABLE vessels (vessel_id INT,type_id INT,vessel_name VARCHAR(50)); CREATE TABLE safety_incidents (incident_id INT,vessel_id INT,incident_date DATE);
SELECT vt.type_name, COALESCE(COUNT(si.incident_id), 0) as total_incidents FROM vessel_types vt LEFT JOIN vessels v ON vt.type_id = v.type_id LEFT JOIN safety_incidents si ON v.vessel_id = si.vessel_id GROUP BY vt.type_name;
What is the total number of safety tests conducted for vehicles manufactured in Japan?
CREATE TABLE Safety_Tests (id INT,vehicle_id INT,test_date DATE,test_result VARCHAR(255)); INSERT INTO Safety_Tests (id,vehicle_id,test_date,test_result) VALUES (1,1,'2022-01-01','Pass'); INSERT INTO Safety_Tests (id,vehicle_id,test_date,test_result) VALUES (2,2,'2022-02-01','Fail'); CREATE TABLE Vehicles_Manufactured ...
SELECT COUNT(st.id) FROM Safety_Tests st JOIN Vehicles_Manufactured vm ON st.vehicle_id = vm.vehicle_id WHERE vm.manufacturing_country = 'Japan';
What is the total number of tickets sold for games in the Northeast region?
CREATE TABLE regions (id INT,name VARCHAR(255),games_hosted INT); INSERT INTO regions (id,name,games_hosted) VALUES (1,'Northeast',10); INSERT INTO regions (id,name,games_hosted) VALUES (2,'Southeast',8);
SELECT COUNT(*) FROM tickets t JOIN games g ON t.game_id = g.id JOIN regions r ON g.region_id = r.id WHERE r.name = 'Northeast';
Show the number of players who played a specific game in the last year, grouped by gender and age.
CREATE TABLE players(id INT,name VARCHAR(50),gender VARCHAR(50),age INT,last_login DATETIME); CREATE TABLE game_sessions(id INT,player_id INT,game_name VARCHAR(50),start_time DATETIME);
SELECT game_name, gender, age, COUNT(DISTINCT players.id) as num_players FROM game_sessions JOIN players ON game_sessions.player_id = players.id WHERE start_time >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY game_name, gender, age;
What are the names and average temperatures of the top 3 coldest months in the 'monthly_temperature' table?
CREATE TABLE monthly_temperature (month TEXT,temperature FLOAT,other_data TEXT);
SELECT mt1.month, AVG(mt1.temperature) as avg_temp FROM monthly_temperature mt1 JOIN (SELECT month, MIN(temperature) as min_temp FROM monthly_temperature GROUP BY month LIMIT 3) mt2 ON mt1.month = mt2.month GROUP BY mt1.month ORDER BY avg_temp ASC;
What is the total fare collected for each type of public transportation?
CREATE TABLE fares (id INT,route_id INT,fare DECIMAL(5,2),date DATE); INSERT INTO fares (id,route_id,fare,date) VALUES (1,1,2.5,'2022-03-01'),(2,2,1.8,'2022-03-01'),(3,3,5.0,'2022-03-01'),(4,1,2.5,'2022-03-02'),(5,2,1.8,'2022-03-02'),(6,3,5.0,'2022-03-02'); CREATE TABLE fare_types (id INT,type VARCHAR(10)); INSERT INTO...
SELECT f.type, SUM(fares.fare) FROM fares JOIN fare_types f ON fares.route_id = f.id GROUP BY f.type;
What is the total amount of funding received by each cultural heritage program in Nigeria in 2020?
CREATE TABLE funding (id INT,program VARCHAR(50),country VARCHAR(50),year INT,amount INT); INSERT INTO funding (id,program,country,year,amount) VALUES (1,'Cultural Heritage Program 1','Nigeria',2020,25000),(2,'Cultural Heritage Program 2','Nigeria',2020,30000);
SELECT program, SUM(amount) AS total_amount FROM funding WHERE country = 'Nigeria' AND year = 2020 GROUP BY program;
What is the total revenue for all restaurants that serve seafood?
CREATE TABLE Restaurants (id INT,name VARCHAR,category VARCHAR,revenue INT); INSERT INTO Restaurants (id,name,category,revenue) VALUES (1,'Bistro','French',500000); INSERT INTO Restaurants (id,name,category,revenue) VALUES (2,'Pizzeria','Italian',600000); INSERT INTO Restaurants (id,name,category,revenue) VALUES (3,'Se...
SELECT SUM(revenue) FROM Restaurants WHERE category = 'Seafood';
Which fields have experienced pest issues but have not yet received any pesticide treatment?
CREATE TABLE Fields (FieldID varchar(5),FieldName varchar(10),PestIssue bool,PesticideTreatment timestamp); INSERT INTO Fields (FieldID,FieldName,PestIssue,PesticideTreatment) VALUES ('A','Field A',true,'2022-06-15 11:30:00'),('B','Field B',false,null),('C','Field C',true,'2022-06-27 14:15:00');
SELECT FieldName FROM Fields WHERE PestIssue = true AND PesticideTreatment IS NULL;
How many users from country 'US' liked post ID 1001?
CREATE TABLE users (id INT,country VARCHAR(2)); INSERT INTO users (id,country) VALUES (1,'US'),(2,'CA'); CREATE TABLE post_likes (user_id INT,post_id INT); INSERT INTO post_likes (user_id,post_id) VALUES (1,1001),(3,1001),(4,1002);
SELECT COUNT(*) FROM users JOIN post_likes ON users.id = post_likes.user_id WHERE users.country = 'US' AND post_likes.post_id = 1001;
List the wastewater treatment facilities in Texas and their capacities?
CREATE TABLE treatment_facilities (name VARCHAR(50),state VARCHAR(20),capacity INT); INSERT INTO treatment_facilities (name,state,capacity) VALUES ('Facility1','Texas',5000),('Facility2','Texas',7000);
SELECT name, capacity FROM treatment_facilities WHERE state = 'Texas';
What is the total carbon sequestered by trees in each region in 2019?
CREATE TABLE trees (id INT,region VARCHAR(255),carbon_sequestered DECIMAL(10,2),year INT);
SELECT region, SUM(carbon_sequestered) as total_carbon_sequestered FROM trees WHERE year = 2019 GROUP BY region;
Delete all games from the genre 'Strategy'
CREATE TABLE games (id INT PRIMARY KEY,name VARCHAR(50),genre VARCHAR(50)); INSERT INTO games (id,name,genre) VALUES (1,'Starcraft','Strategy'); INSERT INTO games (id,name,genre) VALUES (2,'Civilization','Strategy');
DELETE FROM games WHERE genre = 'Strategy';
Count the number of gas wells in the Urengoy gas field and their total daily production
CREATE TABLE gas_wells (well_id INT,location VARCHAR(20),daily_production FLOAT); INSERT INTO gas_wells (well_id,location,daily_production) VALUES (1,'Urengoy gas field',3500.1),(2,'Urengoy gas field',3300.2),(3,'Urengoy gas field',3200.3);
SELECT location, COUNT(*), SUM(daily_production) FROM gas_wells WHERE location = 'Urengoy gas field' GROUP BY location;
What is the maximum rating of a product sold by vendors with a green supply chain?
CREATE TABLE vendors(vendor_id INT,vendor_name TEXT,green_supply_chain BOOLEAN); INSERT INTO vendors(vendor_id,vendor_name,green_supply_chain) VALUES (1,'VendorA',TRUE),(2,'VendorB',FALSE),(3,'VendorC',TRUE); CREATE TABLE products(product_id INT,product_name TEXT,rating INT); INSERT INTO products(product_id,product_nam...
SELECT MAX(products.rating) FROM products JOIN vendors ON products.vendor_id = vendors.vendor_id WHERE vendors.green_supply_chain = TRUE;
Who are the exhibitors at auto shows in Tokyo that showcase electric vehicles?
CREATE TABLE Auto_Shows (id INT PRIMARY KEY,show_name VARCHAR(50),location VARCHAR(50),start_date DATE,end_date DATE); CREATE TABLE Exhibitors (id INT PRIMARY KEY,auto_show_id INT,exhibitor_name VARCHAR(50),booth_number INT); CREATE TABLE Vehicles (id INT PRIMARY KEY,make VARCHAR(50),model VARCHAR(50),year INT,type VAR...
SELECT a.show_name, e.exhibitor_name, v.make, v.model FROM Auto_Shows a INNER JOIN Exhibitors e ON a.id = e.auto_show_id INNER JOIN Vehicles v ON e.exhibitor_name = v.make WHERE a.location = 'Tokyo' AND v.type = 'Electric';
Show the total number of intelligence operations per type in 2021.
CREATE TABLE intelligence_ops (id INT,operation_type VARCHAR(30),operation_date DATE); INSERT INTO intelligence_ops (id,operation_type,operation_date) VALUES (1,'Counterintelligence','2021-06-15'); INSERT INTO intelligence_ops (id,operation_type,operation_date) VALUES (2,'Cybersecurity','2022-02-03');
SELECT operation_type, COUNT(*) FROM intelligence_ops WHERE YEAR(operation_date) = 2021 GROUP BY operation_type;
What is the average number of AI-powered solutions implemented per hotel in the EMEA region?
CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,region TEXT); CREATE TABLE ai_solutions (solution_id INT,hotel_id INT,implemented_date DATE); INSERT INTO hotels (hotel_id,hotel_name,region) VALUES (1,'Alpine Chalet','EMEA'),(2,'Mediterranean Villa','EMEA'); INSERT INTO ai_solutions (solution_id,hotel_id,implemented_d...
SELECT AVG(ai_solutions_per_hotel) AS average_solutions FROM (SELECT h.hotel_id, COUNT(ai.solution_id) AS ai_solutions_per_hotel FROM hotels h INNER JOIN ai_solutions ai ON h.hotel_id = ai.hotel_id WHERE h.region = 'EMEA' GROUP BY h.hotel_id) AS subquery;
Insert a new record for a customer with ID 6, name 'Diana White', data usage 35.0, and region 'east'.
CREATE TABLE subscribers (id INT,name VARCHAR(50),data_usage DECIMAL(10,2),region VARCHAR(10)); INSERT INTO subscribers (id,name,data_usage,region) VALUES (1,'John Doe',30.5,'west'),(2,'Jane Smith',45.3,'west'),(3,'Alice Johnson',22.8,'west'),(4,'Bob Brown',51.9,'west'),(5,'Charlie Green',60.2,'west');
INSERT INTO subscribers (id, name, data_usage, region) VALUES (6, 'Diana White', 35.0, 'east');
What is the minimum ocean acidity level (pH value) recorded in the Pacific Ocean in 2020?
CREATE TABLE ocean_acidity (id INT,location TEXT,pH FLOAT,year INT); INSERT INTO ocean_acidity (id,location,pH,year) VALUES (1,'Pacific Ocean',8.2,2020),(2,'Pacific Ocean',8.1,2019),(3,'Pacific Ocean',8.3,2018);
SELECT MIN(pH) FROM ocean_acidity WHERE location = 'Pacific Ocean' AND year = 2020;
Delete the record with the minimum temperature from the 'dives' table.
CREATE TABLE dives (dive_id INT,diver_name TEXT,depth FLOAT,temperature FLOAT,date DATE);
DELETE FROM dives WHERE temperature = (SELECT MIN(temperature) FROM dives);
Create a table named 'tech_donations' to store details about technology donations made by various organizations
CREATE TABLE tech_donations (id INT PRIMARY KEY,organization VARCHAR(50),city VARCHAR(50),country VARCHAR(50),donation_date DATE,donation_value FLOAT);
CREATE TABLE tech_donations (id INT PRIMARY KEY, organization VARCHAR(50), city VARCHAR(50), country VARCHAR(50), donation_date DATE, donation_value FLOAT);
Determine the mining sites with no resource extraction
CREATE TABLE mining_site (id INT,name VARCHAR(255),resource VARCHAR(255),amount INT); INSERT INTO mining_site (id,name,resource,amount) VALUES (1,'Site A','Gold',100),(2,'Site B','Silver',150),(3,'Site A','Coal',200),(4,'Site C','Gold',120),(5,'Site C','Silver',180),(6,'Site D','Coal',NULL);
SELECT ms.name FROM mining_site ms WHERE ms.amount IS NULL;
What is the policy renewal rate for female policyholders in California?
CREATE TABLE Policyholders (PolicyID INT,Gender VARCHAR(10),State VARCHAR(10)); INSERT INTO Policyholders VALUES (1,'Female','California'); INSERT INTO Policyholders VALUES (2,'Male','New York'); CREATE TABLE Policies (PolicyID INT,RenewalRate DECIMAL(3,2)); INSERT INTO Policies VALUES (1,0.85); INSERT INTO Policies VA...
SELECT p.Gender, AVG(pr.RenewalRate) as RenewalRate FROM Policyholders p INNER JOIN Policies pr ON p.PolicyID = pr.PolicyID WHERE p.Gender = 'Female' AND p.State = 'California' GROUP BY p.Gender;
What is the average size of traditional arts centers by region?
CREATE TABLE traditional_arts_centers (id INT,center_name VARCHAR(100),size INT,region VARCHAR(50)); INSERT INTO traditional_arts_centers (id,center_name,size,region) VALUES (1,'Folk Arts Center',2000,'Northeast'),(2,'Western Arts Center',3000,'Midwest');
SELECT region, AVG(size) as avg_size FROM traditional_arts_centers GROUP BY region;
Which stations on the Silver Line have bike racks?
CREATE TABLE BikeRacks (line VARCHAR(20),station VARCHAR(20),racks BOOLEAN); INSERT INTO BikeRacks (line,station,racks) VALUES ('Silver Line','South Station',true),('Silver Line','World Trade Center',false);
SELECT station FROM BikeRacks WHERE line = 'Silver Line' AND racks = true;
What is the salesperson with the smallest average order size?
CREATE TABLE salesperson (id INT,name VARCHAR(50),region VARCHAR(50)); INSERT INTO salesperson (id,name,region) VALUES (1,'John Doe','North'),(2,'Jane Smith','South'); CREATE TABLE orders (id INT,salesperson_id INT,size INT); INSERT INTO orders (id,salesperson_id,size) VALUES (1,1,10),(2,1,15),(3,2,20),(4,2,25);
SELECT salesperson_id, MIN(AVG(size)) OVER (PARTITION BY salesperson_id) as min_avg_size FROM orders GROUP BY salesperson_id;
What is the minimum billing amount for cases handled by female attorneys?
CREATE TABLE attorneys (id INT,gender VARCHAR,department VARCHAR,billing_amount DECIMAL); INSERT INTO attorneys (id,gender,department,billing_amount) VALUES (1,'Female','Civil',75000.00),(2,'Male','Criminal',100000.00),(3,'Female','Family',60000.00),(4,'Male','Civil',90000.00);
SELECT MIN(billing_amount) FROM attorneys WHERE gender = 'Female';
Compare the sales data for two different salespersons, showing the product, sales amount, and quantity sold.
CREATE TABLE salesperson_data (salesperson VARCHAR(20),product VARCHAR(20),sales_amount DECIMAL(10,2),quantity INT); INSERT INTO salesperson_data VALUES ('John','Laptop',1200.00,2),('John','Phone',500.00,1),('Jane','Phone',300.00,1),('Jane','Tablet',800.00,2);
SELECT salesperson, product, sales_amount, quantity FROM salesperson_data WHERE salesperson IN ('John', 'Jane') ORDER BY salesperson, sales_amount DESC;
What is the total number of ethical AI initiatives in the US and Canada, and how many of them are open source?
CREATE SCHEMA if not exists social_good; CREATE TABLE if not exists social_good.ethical_ai (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),open_source BOOLEAN); INSERT INTO social_good.ethical_ai (id,name,location,open_source) VALUES (1,'AI for Social Good','USA',true),(2,'Ethical AI Canada','Canada',false)...
SELECT SUM(open_source) as total_open_source, COUNT(*) as total_initiatives FROM social_good.ethical_ai WHERE location IN ('USA', 'Canada');
What is the average sea level rise in the Indian Ocean per decade since 1990?
CREATE TABLE SeaLevel(id INT,rise DECIMAL(5,2),date DATE); INSERT INTO SeaLevel(id,rise,date) VALUES (1,0.3,'1990-01-01'),(2,0.6,'2000-01-01'),(3,1.0,'2010-01-01'),(4,1.5,'2020-01-01');
SELECT AVG(rise) FROM (SELECT rise FROM SeaLevel WHERE YEAR(date) >= 1990 GROUP BY rise, YEAR(date)/10) AS Decades;
Display the total revenue of products that are ethically sourced and have transparent production methods.
CREATE TABLE Products (ProductID INT,ProductName TEXT,Price DECIMAL,EthicalSource BOOLEAN,TransparentProduction BOOLEAN,VendorID INT);CREATE TABLE Vendors (VendorID INT,VendorName TEXT,Country TEXT); INSERT INTO Products VALUES (1,'Shirt',20,true,true,1),(2,'Pants',30,true,false,1),(3,'Shoes',50,false,true,1); INSERT I...
SELECT SUM(Price) FROM Products p WHERE p.EthicalSource = true AND p.TransparentProduction = true;
What is the average time taken for appeals to be resolved for each appellate court?
CREATE TABLE appeals (id INT,appeal_date DATE,resolution_date DATE,appellate_court VARCHAR(50));
SELECT appellate_court, AVG(DATEDIFF(day, appeal_date, resolution_date)) AS avg_time_taken FROM appeals GROUP BY appellate_court;
How many claims were filed per policy type in 'Texas'?
CREATE TABLE Claims (ClaimID INT,PolicyID INT,PolicyType VARCHAR(20),ClaimState VARCHAR(20)); INSERT INTO Claims (ClaimID,PolicyID,PolicyType,ClaimState) VALUES (1,1,'Auto','Texas'),(2,2,'Home','Texas'),(3,3,'Life','Texas');
SELECT PolicyType, COUNT(*) as ClaimCount FROM Claims WHERE ClaimState = 'Texas' GROUP BY PolicyType;
What is the average CO2 level in the Arctic per year?
CREATE TABLE air_quality_data (id INT,year INT,co2_level FLOAT);
SELECT AVG(co2_level) FROM air_quality_data GROUP BY year;
Which countries have made the most progress in climate adaptation in the last 5 years?
CREATE TABLE progress (country TEXT,year INT,progress FLOAT); INSERT INTO progress (country,year,progress) VALUES ('India',2017,0.7);
SELECT country, MAX(progress) FROM progress WHERE year BETWEEN 2016 AND 2021 GROUP BY country ORDER BY progress DESC;
Update the salaries of all employees in the Sales department to be the average salary for the department plus 15%.
CREATE TABLE employees (id INT,name VARCHAR(50),department VARCHAR(50),salary DECIMAL(5,2)); INSERT INTO employees (id,name,department,salary) VALUES (1,'Juan Garcia','Sales',50000.00);
UPDATE employees SET salary = (SELECT AVG(salary) * 1.15 FROM employees e WHERE e.department = employees.department) WHERE department = 'Sales';
What is the total amount of loans issued to microfinance organizations in Latin America?
CREATE TABLE loans (id INT,amount DECIMAL(10,2),issuance_date DATE,borrower_type VARCHAR(20)); INSERT INTO loans (id,amount,issuance_date,borrower_type) VALUES (1,5000,'2022-01-01','Microfinance Organization'); CREATE TABLE regions (id INT,name VARCHAR(20),description VARCHAR(50)); INSERT INTO regions (id,name,descript...
SELECT SUM(loans.amount) FROM loans INNER JOIN regions ON loans.borrower_type = regions.name WHERE regions.name = 'Microfinance Organization';
Who are the top five intelligence agency directors with the longest tenures, and what are their start and end dates?
CREATE TABLE intelligence_agency (id INT,name VARCHAR(255),director VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO intelligence_agency (id,name,director,start_date,end_date) VALUES (1,'CIA','John Doe','2010-01-01','2020-01-01'),(2,'NSA','Jane Smith','2015-01-01','2021-01-01'),(3,'FBI','Mike Johnson','2018-01-...
SELECT director, start_date, end_date FROM intelligence_agency ORDER BY DATEDIFF(end_date, start_date) DESC LIMIT 5;
What is the average orbital height of satellites launched by Japan?
CREATE TABLE satellites_orbital (id INT,name VARCHAR(255),country VARCHAR(255),orbital_height FLOAT);
SELECT AVG(orbital_height) FROM satellites_orbital WHERE country = 'Japan';
What is the total number of security incidents caused by insiders in the retail sector in 2021 and 2022?
CREATE TABLE retail_sector (year INT,incidents INT,insider BOOLEAN); INSERT INTO retail_sector (year,incidents,insider) VALUES (2022,25,true),(2022,35,false),(2021,50,true),(2021,40,false),(2020,20,true);
SELECT SUM(incidents) FROM retail_sector WHERE year IN (2021, 2022) AND insider = true;
What is the distribution of cybersecurity vulnerabilities reported by Microsoft and Google between 2019 and 2021?
CREATE TABLE vulnerabilities (company VARCHAR(50),year INT,vulnerabilities INT); INSERT INTO vulnerabilities (company,year,vulnerabilities) VALUES ('Microsoft',2019,726),('Microsoft',2020,869),('Microsoft',2021,977),('Google',2019,673),('Google',2020,772),('Google',2021,876);
SELECT company, year, vulnerabilities FROM vulnerabilities WHERE company IN ('Microsoft', 'Google') ORDER BY company, year;
What is the total number of transactions made on the Binance Smart Chain in the last month?
CREATE TABLE BinanceTransactions (id INT,txid VARCHAR(100),timestamp BIGINT); INSERT INTO BinanceTransactions (id,txid,timestamp) VALUES (1,'...',1643324480),(2,'...',1643410880);
SELECT COUNT(*) FROM BinanceTransactions WHERE timestamp >= UNIX_TIMESTAMP(DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH)) * 1000;
What is the total number of green buildings in each state?
CREATE TABLE State (state_id INT,state_name VARCHAR(50)); CREATE TABLE Building (building_id INT,building_name VARCHAR(50),building_type VARCHAR(50),state_id INT);
SELECT State.state_name, COUNT(*) as num_buildings FROM State JOIN Building ON State.state_id = Building.state_id WHERE Building.building_type = 'green' GROUP BY State.state_name;
List the names and locations of factories that use renewable energy sources.
CREATE TABLE factories (factory_id INT,name TEXT,location TEXT,uses_renewable_energy BOOLEAN); INSERT INTO factories VALUES (1,'Factory A','City A',true),(2,'Factory B','City B',false),(3,'Factory C','City C',true);
SELECT name, location FROM factories WHERE uses_renewable_energy = true;
What is the number of clients in the Midwest region with an account balance greater than $20,000?
CREATE TABLE clients (client_id INT,name VARCHAR(50),region VARCHAR(20),account_balance DECIMAL(10,2)); INSERT INTO clients (client_id,name,region,account_balance) VALUES (1,'John Smith','Midwest',25000.00),(2,'Jane Doe','Northeast',22000.00),(3,'Mike Johnson','Midwest',18000.00),(4,'Sara Jones','Southeast',12000.00),(...
SELECT COUNT(*) FROM clients WHERE region = 'Midwest' AND account_balance > 20000.00;
List the mineral extraction statistics for each mine, including the mine name, the total amount of minerals extracted, and the total operational costs. Calculate the revenue for each mine.
CREATE TABLE mineral_extraction (mine_id INT,amount_extracted INT,operational_costs INT); INSERT INTO mineral_extraction (mine_id,amount_extracted,operational_costs) VALUES (7,2000,500000),(7,2500,625000),(8,1500,375000),(8,1800,450000); CREATE TABLE mines (mine_id INT,mine_name TEXT); INSERT INTO mines (mine_id,mine_n...
SELECT m.mine_name, AVG(me.amount_extracted) AS avg_amount_extracted, AVG(me.operational_costs) AS avg_operational_costs, AVG(me.amount_extracted - me.operational_costs) AS revenue FROM mineral_extraction me JOIN mines m ON me.mine_id = m.mine_id GROUP BY m.mine_name;
What are the renewable energy project costs for the state of California?
CREATE TABLE RenewableCosts (state VARCHAR(20),project_type VARCHAR(20),cost FLOAT); INSERT INTO RenewableCosts (state,project_type,cost) VALUES ('California','Solar',1000000.0);
SELECT cost FROM RenewableCosts WHERE state = 'California' AND project_type = 'Solar';
What is the total prize pool for tournaments in which a player with the name 'Chloe Lee' has participated?
CREATE TABLE tournaments (id INT,name VARCHAR(50),prize_pool INT); CREATE TABLE tournament_participation (id INT,tournament_id INT,player_id INT); INSERT INTO tournaments VALUES (1,'Tournament1',70000); INSERT INTO tournaments VALUES (2,'Tournament2',30000); INSERT INTO tournament_participation VALUES (1,1,1); INSERT I...
SELECT SUM(tournaments.prize_pool) FROM tournaments INNER JOIN tournament_participation ON tournaments.id = tournament_participation.tournament_id INNER JOIN players ON tournament_participation.player_id = players.id WHERE players.name = 'Chloe Lee';
What is the success rate of cases in which the plaintiff identifies as a woman?
CREATE TABLE cases (id INT,plaintiff_gender VARCHAR(10),case_outcome VARCHAR(10)); INSERT INTO cases (id,plaintiff_gender,case_outcome) VALUES (1,'female','won');
SELECT 100.0 * AVG(CASE WHEN cases.plaintiff_gender = 'female' THEN (CASE WHEN cases.case_outcome = 'won' THEN 1 ELSE 0 END) ELSE 0 END) / COUNT(*) AS success_rate FROM cases;
Identify the companies with the lowest ESG score in each sector.
CREATE TABLE companies (id INT,sector VARCHAR(20),ESG_score FLOAT); INSERT INTO companies (id,sector,ESG_score) VALUES (1,'Technology',75.0),(2,'Finance',60.0),(3,'Healthcare',80.0),(4,'Technology',85.0),(5,'Finance',82.0);
SELECT sector, MIN(ESG_score) FROM companies GROUP BY sector;
What is the average salary of developers in the IT department, grouped by gender?
CREATE TABLE Employees (EmployeeID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50),Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,Salary) VALUES (1,'John','Doe','IT',80000.00),(2,'Jane','Doe','IT',85000.00),(3,'Mike','Johnson','IT',90000.00); CREATE TABLE De...
SELECT G.Gender, AVG(E.Salary) AS AvgSalary FROM Employees E INNER JOIN Genders G ON E.EmployeeID = G.EmployeeID WHERE E.Department = 'IT' AND E.Department IN (SELECT Department FROM Departments WHERE DepartmentHead = 'John Doe') GROUP BY G.Gender;
List all vehicle maintenance records for the 'Red Line' subway fleet
CREATE TABLE vehicle_maintenance (vehicle_type VARCHAR(50),last_maintenance DATE); INSERT INTO vehicle_maintenance (vehicle_type,last_maintenance) VALUES ('Red Line','2021-06-01'),('Red Line','2021-08-15'),('Blue Line','2021-07-20');
SELECT * FROM vehicle_maintenance WHERE vehicle_type = 'Red Line';
What is the average production volume per mining method in the past 12 months?
CREATE TABLE mining_production (production_date DATE,production_volume INT,mining_method VARCHAR(255)); INSERT INTO mining_production (production_date,production_volume,mining_method) VALUES ('2021-08-01',1000,'Open Pit'),('2021-07-01',1200,'Underground'),('2020-08-01',1500,'Open Pit'),('2020-07-01',1800,'Underground')...
SELECT mining_method, AVG(production_volume) as avg_production_volume FROM (SELECT mining_method, production_volume, production_date, ROW_NUMBER() OVER (PARTITION BY mining_method ORDER BY production_date DESC) as rn FROM mining_production WHERE production_date >= DATEADD(month, -12, CURRENT_DATE)) t WHERE rn = 1 GROUP...
Delete all records from the ships table for ships that were decommissioned before 2010
CREATE TABLE ships (id INT,name TEXT,type TEXT,year_built INT,decommission_year INT); INSERT INTO ships (id,name,type,year_built,decommission_year) VALUES (1,'Seabourn Pride','Passenger',1988,2011);
DELETE FROM ships WHERE decommission_year < 2010;
Which projects were completed before 2018-01-01 and their respective total costs?
CREATE TABLE ProjectTimeline (project_id INT,start_date DATE,end_date DATE); INSERT INTO ProjectTimeline (project_id,start_date,end_date) VALUES (1,'2016-01-01','2017-12-31'); INSERT INTO ProjectTimeline (project_id,start_date,end_date) VALUES (2,'2019-01-01','2020-12-31'); INSERT INTO InfrastructureProjects (id,name,l...
SELECT p.name, p.cost FROM InfrastructureProjects p JOIN ProjectTimeline t ON p.id = t.project_id WHERE t.end_date < '2018-01-01';
Which energy storage technologies are used in Australia and their corresponding capacities?
CREATE TABLE australia_energy_storage (technology VARCHAR(20),capacity INT); INSERT INTO australia_energy_storage (technology,capacity) VALUES ('Batteries',2000),('Pumped Hydro',6000),('Flywheels',100);
SELECT technology, capacity FROM australia_energy_storage;