instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
How many deep-sea expeditions have been conducted in the Pacific Ocean?
CREATE TABLE deep_sea_expeditions (expedition_id INT,location VARCHAR(255),year INT);
SELECT COUNT(*) FROM deep_sea_expeditions WHERE location = 'Pacific Ocean';
List all marine species found in the Arctic Ocean.
CREATE TABLE marine_species (species_name TEXT,ocean_location TEXT); INSERT INTO marine_species (species_name,ocean_location) VALUES ('Narwhal','Arctic Ocean'),('Polar Bear','Arctic Ocean'),('Beluga Whale','Arctic Ocean');
SELECT species_name FROM marine_species WHERE ocean_location = 'Arctic Ocean';
Retrieve the number of marine species by type in the 'marine_species' table.
CREATE TABLE marine_species (species_id INT,name VARCHAR(255),type VARCHAR(255),conservation_status VARCHAR(255));
SELECT type, COUNT(*) FROM marine_species GROUP BY type;
List the top 3 most humid cities in the past week?
CREATE TABLE Weather (location VARCHAR(50),temperature INT,humidity INT,timestamp TIMESTAMP);
SELECT location, AVG(humidity) as avg_humidity FROM Weather WHERE timestamp > NOW() - INTERVAL '1 week' GROUP BY location ORDER BY avg_humidity DESC LIMIT 3;
What is the total precipitation in 'Field E' for the month of January 2022?
CREATE TABLE sensors (sensor_id INT,location VARCHAR(50)); INSERT INTO sensors (sensor_id,location) VALUES (005,'Field E'); CREATE TABLE precipitation (sensor_id INT,precipitation FLOAT,timestamp TIMESTAMP); INSERT INTO precipitation (sensor_id,precipitation,timestamp) VALUES (005,12.3,'2022-01-01 10:00:00'); INSERT INTO precipitation (sensor_id,precipitation,timestamp) VALUES (005,15.6,'2022-01-02 11:00:00');
SELECT SUM(precipitation) FROM precipitation WHERE sensor_id = 005 AND timestamp BETWEEN '2022-01-01 00:00:00' AND '2022-01-31 23:59:59';
What is the difference in property size between the largest and smallest properties in Sydney?
CREATE TABLE properties (id INT,size FLOAT,city VARCHAR(20)); INSERT INTO properties (id,size,city) VALUES (1,1500,'Sydney'),(2,2000,'Sydney'),(3,1000,'Sydney');
SELECT MAX(size) - MIN(size) FROM properties WHERE city = 'Sydney';
Determine the number of clean energy policies implemented in each country in the clean_energy_policies table.
CREATE TABLE clean_energy_policies (country VARCHAR(50),policy VARCHAR(50),year INT,policy_status VARCHAR(50));
SELECT country, COUNT(*) as num_policies FROM clean_energy_policies WHERE policy_status = 'Implemented' GROUP BY country;
Identify the top 3 product categories with the highest sales revenue in the European market.
CREATE TABLE products (product_id INT,product_category VARCHAR(50),sales_price DECIMAL(5,2)); INSERT INTO products (product_id,product_category,sales_price) VALUES (1,'T-Shirts',20.99),(2,'Pants',25.49),(3,'Jackets',35.99); CREATE TABLE sales (sale_id INT,product_id INT,sale_region VARCHAR(50),sale_amount INT); INSERT INTO sales (sale_id,product_id,sale_region,sale_amount) VALUES (1,1,'UK',100),(2,2,'France',75),(3,3,'Germany',50);
SELECT product_category, SUM(sale_amount * sales_price) AS total_revenue FROM products p JOIN sales s ON p.product_id = s.product_id WHERE sale_region IN ('UK', 'France', 'Germany') GROUP BY product_category ORDER BY total_revenue DESC LIMIT 3;
Create a table named 'planets'
CREATE TABLE planets (id INT PRIMARY KEY,name VARCHAR(50),distance_to_sun FLOAT);
CREATE TABLE planets (id INT PRIMARY KEY, name VARCHAR(50), distance_to_sun FLOAT);
What is the total cost of spacecraft manufactured by Cosmic Corp. and Starlight Inc. in 2023?
CREATE TABLE SpacecraftManuf (company VARCHAR(20),year INT,cost INT); INSERT INTO SpacecraftManuf (company,year,cost) VALUES ('Cosmic Corp.',2023,40000000); INSERT INTO SpacecraftManuf (company,year,cost) VALUES ('Starlight Inc.',2023,50000000);
SELECT SUM(cost) FROM SpacecraftManuf WHERE company IN ('Cosmic Corp.', 'Starlight Inc.') AND year = 2023;
Insert new ticket sales records from the 'new_ticket_sales' staging table into the 'ticket_sales' table
CREATE TABLE new_ticket_sales (sale_id INT,ticket_price DECIMAL(5,2),sale_date DATE,team_id INT); CREATE TABLE ticket_sales (sale_id INT PRIMARY KEY,ticket_price DECIMAL(5,2),sale_date DATE,team_id INT);
INSERT INTO ticket_sales (sale_id, ticket_price, sale_date, team_id) SELECT sale_id, ticket_price, sale_date, team_id FROM new_ticket_sales;
What is the minimum number of security incidents reported in a single day in the past year?
CREATE TABLE security_incidents (id INT,sector VARCHAR(255),date DATE);
SELECT MIN(number_of_incidents_per_day) FROM (SELECT DATE(date) as date, COUNT(*) as number_of_incidents_per_day FROM security_incidents WHERE date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY date) as subquery;
What is the total number of shared bikes in New York?
CREATE TABLE if not exists bike_share (id INT,city VARCHAR(20),bike_type VARCHAR(20),quantity INT);INSERT INTO bike_share (id,city,bike_type,quantity) VALUES (1,'New York','electric_bike',400),(2,'New York','classic_bike',500),(3,'Los Angeles','electric_bike',350),(4,'Los Angeles','classic_bike',450);
SELECT SUM(quantity) FROM bike_share WHERE city = 'New York';
What was the total number of multimodal trips taken in New York City in January 2022?
CREATE TABLE Multimodal_Trips (city VARCHAR(20),month INT,year INT,num_trips INT); INSERT INTO Multimodal_Trips (city,month,year,num_trips) VALUES ('New York City',1,2022,120000),('New York City',2,2022,140000),('Los Angeles',1,2022,90000),('Los Angeles',2,2022,110000);
SELECT SUM(num_trips) FROM Multimodal_Trips WHERE city = 'New York City' AND month = 1 AND year = 2022;
Determine the number of new garments introduced each month in 2021.
CREATE TABLE garment_inventory (inventory_id INT,garment_id INT,garment_name VARCHAR(255),inventory_date DATE);
SELECT EXTRACT(MONTH FROM inventory_date) as month, COUNT(DISTINCT garment_id) FROM garment_inventory WHERE inventory_date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY month;
Update the policy type to 'Renters' for policy ID 1
CREATE TABLE policy (policy_id INT,policy_type VARCHAR(20),effective_date DATE); INSERT INTO policy VALUES (1,'Personal Auto','2018-01-01');
UPDATE policy SET policy_type = 'Renters' WHERE policy_id = 1;
What is the average age of policyholders who live in 'CA' and have a home insurance policy?
CREATE TABLE policyholders (id INT,age INT,state VARCHAR(2),policy_type VARCHAR(10)); INSERT INTO policyholders (id,age,state,policy_type) VALUES (1,35,'NY','car'),(2,45,'CA','home'),(3,28,'NY','car'),(4,55,'CA','home');
SELECT AVG(age) FROM policyholders WHERE state = 'CA' AND policy_type = 'home';
What is the total number of workplaces by industry with safety inspections in California in 2022?
CREATE TABLE workplaces (id INT,industry VARCHAR,state VARCHAR,num_inspections INT,inspection_date DATE); INSERT INTO workplaces (id,industry,state,num_inspections,inspection_date) VALUES (1,'Manufacturing','California',3,'2022-01-01');
SELECT industry, SUM(num_inspections) as total_inspections FROM workplaces WHERE state = 'California' AND inspection_date >= '2022-01-01' GROUP BY industry;
Count the number of autonomous vehicle accidents in 2022
CREATE TABLE autonomous_vehicles (vehicle_id INT,accident_year INT,accident_type VARCHAR(20)); INSERT INTO autonomous_vehicles VALUES (1,2021,'Minor'),(2,2022,'Major'),(3,2022,'Minor'),(4,2021,'Major'),(5,2022,'Major');
SELECT COUNT(*) FROM autonomous_vehicles WHERE accident_year = 2022 AND accident_type IS NOT NULL;
What is the average horsepower of electric vehicles in the 'Luxury' category sold between 2018 and 2020?
CREATE TABLE EVSales (id INT,name VARCHAR(50),horsepower INT,category VARCHAR(50),sale_year INT); INSERT INTO EVSales (id,name,horsepower,category,sale_year) VALUES (1,'Tesla Model S',503,'Luxury',2018),(2,'Audi e-Tron',408,'Luxury',2019),(3,'Porsche Taycan',562,'Luxury',2020);
SELECT AVG(horsepower) FROM EVSales WHERE category = 'Luxury' AND sale_year BETWEEN 2018 AND 2020;
What are the top 3 ports where vessels have had the most safety incidents in the past year?
CREATE TABLE Safety_Records(Vessel_ID INT,Incident_Date DATE,Incident_Port VARCHAR(50)); INSERT INTO Safety_Records VALUES (1,'2022-03-12','Port of Oakland'),(2,'2022-03-15','Port of Los Angeles'),(3,'2022-03-20','Port of Oakland'),(1,'2022-03-25','Port of Miami');
SELECT Incident_Port, COUNT(*) as Num_Incidents FROM Safety_Records WHERE Incident_Date >= DATEADD(YEAR, -1, GETDATE()) GROUP BY Incident_Port ORDER BY Num_Incidents DESC LIMIT 3;
What was the total revenue generated from adult ticket sales for the Modern Art exhibition?
CREATE TABLE exhibitions (name VARCHAR(50),tickets_sold INT,price DECIMAL(5,2)); INSERT INTO exhibitions (name,tickets_sold,price) VALUES ('Modern Art',300,20.00),('Classic Art',250,15.00);
SELECT SUM(price * tickets_sold) FROM exhibitions WHERE name = 'Modern Art' AND tickets_sold = (SELECT SUM(tickets_sold) FROM tickets WHERE age_group = 'Adult');
Calculate the average recycling rate
CREATE TABLE recycling_rates (id INT PRIMARY KEY,location VARCHAR(50),rate FLOAT);
SELECT AVG(rate) FROM recycling_rates;
Insert new records into the 'recycling_rates' table for 'Berlin', 'Germany'
CREATE TABLE recycling_rates (id INT,city VARCHAR(255),state VARCHAR(255),country VARCHAR(255),rate DECIMAL(5,2));
INSERT INTO recycling_rates (city, state, country, rate) VALUES ('Berlin', NULL, 'Germany', 0.65);
Determine the maximum water usage in a single day from 'DailyWaterUsage' table
CREATE TABLE DailyWaterUsage (day DATE,usage INT);
SELECT MAX(usage) FROM DailyWaterUsage;
List all the drought-impacted counties in Texas in 2018.
CREATE TABLE drought_impact(county VARCHAR(20),state VARCHAR(20),year INT,impacted BOOLEAN); INSERT INTO drought_impact(county,state,year,impacted) VALUES ('Harris','Texas',2015,true),('Harris','Texas',2016,true),('Harris','Texas',2017,true),('Harris','Texas',2018,true),('Bexar','Texas',2015,false),('Bexar','Texas',2016,false),('Bexar','Texas',2017,false),('Bexar','Texas',2018,false);
SELECT county FROM drought_impact WHERE state = 'Texas' AND year = 2018 AND impacted = true;
Insert a new record into the models table for a new AI model, "ModelF", a Generative model developed in France with a safety score of 89.00 and explainability score of 84.00.
CREATE TABLE models (model_id INT,model_name VARCHAR(50),model_type VARCHAR(50),country VARCHAR(50),safety_score DECIMAL(5,2),explainability_score DECIMAL(5,2));
INSERT INTO models (model_name, model_type, country, safety_score, explainability_score) VALUES ('ModelF', 'Generative', 'France', 89.00, 84.00);
Which creative AI applications were developed in the US and Europe?
CREATE TABLE Creative_AI (id INT,name TEXT,country TEXT); INSERT INTO Creative_AI (id,name,country) VALUES (1,'DeepArt','Germany'),(2,'DeepDream','USA'),(3,'Artbreeder','Switzerland');
SELECT name FROM Creative_AI WHERE country IN ('USA', 'Germany', 'Switzerland');
What is the percentage of agricultural innovations that received funding in the last year?
CREATE TABLE AgriculturalInnovations (innovation VARCHAR(50),funding_year INT,funding_amount FLOAT);
SELECT 100.0 * COUNT(*) / NULLIF(SUM(COUNT(*)), 0) FROM AgriculturalInnovations WHERE funding_year = YEAR(CURRENT_DATE) - 1;
Find the total biomass of fish for each salmon farm in the Baltic Sea.
CREATE TABLE farm (id INT,name VARCHAR(50),location VARCHAR(50)); CREATE TABLE farm_stock (farm_id INT,species VARCHAR(50),quantity INT,biomass FLOAT); INSERT INTO farm VALUES (1,'Baltic Sea Salmon Farm 1','Baltic Sea'),(2,'Baltic Sea Salmon Farm 2','Baltic Sea'),(3,'North Sea Salmon Farm 1','North Sea'); INSERT INTO farm_stock VALUES (1,'Atlantic Salmon',2500,10000),(1,'Coho Salmon',1500,6000),(2,'Atlantic Salmon',3500,14000),(2,'Pacific Salmon',600,2400);
SELECT f.name, SUM(fs.biomass) as total_biomass FROM farm f INNER JOIN farm_stock fs ON f.id = fs.farm_id WHERE f.location = 'Baltic Sea' GROUP BY f.id;
How many times has each farm experienced a disease outbreak?
CREATE TABLE Farm (FarmID INT,FarmName VARCHAR(50),FishSpecies VARCHAR(50)); INSERT INTO Farm (FarmID,FarmName,FishSpecies) VALUES (1,'Farm A','Salmon'); INSERT INTO Farm (FarmID,FarmName,FishSpecies) VALUES (2,'Farm B','Tilapia'); CREATE TABLE Disease (DiseaseID INT,DiseaseName VARCHAR(50),DiseaseImpact FLOAT,FarmID INT); INSERT INTO Disease (DiseaseID,DiseaseName,DiseaseImpact,FarmID) VALUES (1,'Bacterial Infection',0.35,1); INSERT INTO Disease (DiseaseID,DiseaseName,DiseaseImpact,FarmID) VALUES (2,'Fungal Infection',0.25,2);
SELECT Farm.FarmID, COUNT(*) FROM Farm INNER JOIN Disease ON Farm.FarmID = Disease.FarmID GROUP BY Farm.FarmID;
How many events were attended by people from rural areas in Texas and Florida?
CREATE TABLE Events (id INT,state VARCHAR(2),city VARCHAR(20),attendees INT); INSERT INTO Events (id,state,city,attendees) VALUES (1,'TX','Austin',500),(2,'FL','Miami',300),(3,'TX','Dallas',400); CREATE TABLE Demographics (id INT,state VARCHAR(2),zip INT,rural VARCHAR(5)); INSERT INTO Demographics (id,state,zip,rural) VALUES (1,'TX',75000,'yes'),(2,'FL',33000,'yes'),(3,'TX',78000,'no');
SELECT SUM(attendees) FROM Events INNER JOIN Demographics ON Events.state = Demographics.state WHERE rural = 'yes' AND state IN ('TX', 'FL');
What is the total weight of unsold cannabis inventory for Dispensary C?
CREATE TABLE inventory (id INT,dispensary VARCHAR(255),product VARCHAR(255),weight FLOAT,sold BOOLEAN); INSERT INTO inventory (id,dispensary,product,weight,sold) VALUES (1,'Dispensary C','Cannabis',200.0,FALSE);
SELECT SUM(weight) FROM inventory WHERE dispensary = 'Dispensary C' AND product = 'Cannabis' AND sold = FALSE;
What is the reactor temperature trend for each production run?
CREATE TABLE production_runs (id INT,reactor_temp FLOAT,reactor_temp_time TIME); INSERT INTO production_runs (id,reactor_temp,reactor_temp_time) VALUES (1,120.5,'08:00:00'),(1,122.3,'09:00:00'),(2,125.3,'08:00:00');
SELECT id, reactor_temp_time, AVG(reactor_temp) OVER (PARTITION BY id ORDER BY reactor_temp_time ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS avg_reactor_temp FROM production_runs;
What is the average temperature in the Arctic region between 2010 and 2015?
CREATE TABLE weather (region VARCHAR(20),year INT,temperature FLOAT); INSERT INTO weather VALUES ('Arctic',2010,-10.5),('Arctic',2011,-12.2),('Arctic',2012,-9.8),('Arctic',2013,-8.5),('Arctic',2014,-7.6),('Arctic',2015,-6.2);
SELECT AVG(temperature) FROM weather WHERE region = 'Arctic' AND year BETWEEN 2010 AND 2015;
What is the percentage of GHG emissions by sector in 2015?
CREATE TABLE ghg_emissions (year INT,sector TEXT,ghg_emission FLOAT); INSERT INTO ghg_emissions (year,sector,ghg_emission) VALUES (2015,'Energy',0.32),(2015,'Industry',0.21),(2015,'Transport',0.15),(2015,'Residential',0.14),(2015,'Commercial',0.13),(2015,'Agriculture',0.05);
SELECT sector, ROUND(ghg_emission / SUM(ghg_emission) OVER(), 2) * 100 AS percentage FROM ghg_emissions WHERE year = 2015;
What is the percentage of uninsured individuals in California?
CREATE TABLE healthcare_access (id INT,individual_id INT,insurance_status TEXT,state TEXT); INSERT INTO healthcare_access (id,individual_id,insurance_status,state) VALUES (1,1,'Insured','California'); INSERT INTO healthcare_access (id,individual_id,insurance_status,state) VALUES (2,2,'Uninsured','California');
SELECT (COUNT(*) FILTER (WHERE insurance_status = 'Uninsured')) * 100.0 / COUNT(*) FROM healthcare_access WHERE state = 'California';
What is the success rate of diverse-led startups (at least 1 female or underrepresented racial or ethnic group executive) in the past 3 years?
CREATE TABLE DiverseStartups(id INT,name TEXT,country TEXT,year INT,success BOOLEAN); INSERT INTO DiverseStartups VALUES (1,'FemTech','USA',2020,true),(2,'GreenCity','Canada',2019,false),(3,'AI-Health','UK',2021,true),(4,'SolarEnergy','USA',2020,false),(5,'DataAnalytics','Germany',2019,true),(6,'SmartGrid','USA',2021,true),(7,'CloudServices','India',2020,false),(8,'RenewableEnergy','USA',2019,true);
SELECT COUNT(*) * 100.0 / (SELECT COUNT(*) FROM DiverseStartups WHERE year >= YEAR(CURRENT_DATE) - 3) AS success_rate FROM DiverseStartups WHERE year >= YEAR(CURRENT_DATE) - 3 AND success = true;
What is the number of students who received accommodations for each disability type?
CREATE TABLE Disability_Accommodations (Student_ID INT,Student_Name TEXT,Disability_Type TEXT,Accommodation_Type TEXT); INSERT INTO Disability_Accommodations (Student_ID,Student_Name,Disability_Type,Accommodation_Type) VALUES (1,'John Doe','Visual Impairment','Extended Time'),(2,'Jane Smith','Hearing Impairment','Sign Language Interpreting'),(3,'Michael Brown','ADHD','Extended Time');
SELECT Disability_Type, Accommodation_Type, COUNT(*) FROM Disability_Accommodations GROUP BY Disability_Type, Accommodation_Type;
Add a new decentralized application 'BlockchainBank' with symbol 'BB' and total supply of 500,000,000 to the 'DecentralizedApplications' table
CREATE TABLE DecentralizedApplications (name VARCHAR(64),symbol VARCHAR(8),total_supply DECIMAL(20,8),platform VARCHAR(64),project_url VARCHAR(128));
INSERT INTO DecentralizedApplications (name, symbol, total_supply) VALUES ('BlockchainBank', 'BB', 500000000);
What is the name of the user who owns the digital asset named 'Asset1'?
CREATE TABLE users (id INT PRIMARY KEY,name VARCHAR(255),digital_asset_id INT,FOREIGN KEY (digital_asset_id) REFERENCES digital_assets(id)); INSERT INTO users (id,name,digital_asset_id) VALUES (1,'User1',1),(2,'User2',2);
SELECT u.name FROM users u INNER JOIN digital_assets d ON u.digital_asset_id = d.id WHERE d.name = 'Asset1';
What is the percentage of products that are certified vegan for each brand?
CREATE TABLE products (product_id INT,brand_id INT,product_name VARCHAR(50),certified_vegan BOOLEAN); INSERT INTO products (product_id,brand_id,product_name,certified_vegan) VALUES (1,1,'Soap',true),(2,1,'Lotion',false),(3,2,'Shower Gel',true),(4,2,'Body Butter',true),(5,3,'Foundation',false); CREATE TABLE brands (brand_id INT,brand_name VARCHAR(50),country VARCHAR(50),cruelty_free BOOLEAN); INSERT INTO brands (brand_id,brand_name,country,cruelty_free) VALUES (1,'Lush','United Kingdom',true),(2,'The Body Shop','United Kingdom',true),(3,'Bare Minerals','United States',true);
SELECT b.brand_name, (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM products p WHERE p.brand_id = b.brand_id)) as vegan_percentage FROM products p JOIN brands b ON p.brand_id = b.brand_id WHERE p.certified_vegan = true GROUP BY b.brand_name;
What is the percentage of vegan products for each brand?
CREATE TABLE brand_ingredient (brand VARCHAR(255),product_count INT,vegan_product_count INT); INSERT INTO brand_ingredient (brand,product_count,vegan_product_count) VALUES ('Lush',100,60),('The Body Shop',75,50),('Sephora',150,30);
SELECT brand, (vegan_product_count * 100.0 / product_count) as vegan_percentage FROM brand_ingredient;
What is the average response time for emergency calls during different times of the day?
CREATE TABLE emergency_calls (id INT,call_time TIME,response_time INT);CREATE TABLE districts (district_id INT,district_name VARCHAR(255));
SELECT DATEPART(hour, call_time) AS hour_of_day, AVG(response_time) AS avg_response_time FROM emergency_calls JOIN districts ON 1=1 GROUP BY DATEPART(hour, call_time);
What is the minimum number of crimes committed in each type for the past year?
CREATE TABLE crimes (crime_id INT,crime_type VARCHAR(255),committed_date DATE); INSERT INTO crimes (crime_id,crime_type,committed_date) VALUES (1,'Theft','2022-01-01'),(2,'Assault','2022-01-02'),(3,'Theft','2022-01-03');
SELECT c.crime_type, MIN(COUNT(c.crime_id)) FROM crimes c WHERE c.committed_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY c.crime_type;
What is the minimum response time for fire incidents in each borough?
CREATE TABLE borough (id INT,name VARCHAR(50)); INSERT INTO borough (id,name) VALUES (1,'Manhattan'),(2,'Brooklyn'),(3,'Queens'),(4,'Bronx'),(5,'Staten Island'); CREATE TABLE incident (id INT,borough_id INT,type VARCHAR(50),timestamp TIMESTAMP,response_time INT);
SELECT borough_id, MIN(response_time) as min_response_time FROM incident WHERE type = 'fire' GROUP BY borough_id;
What is the total number of community policing events in 'City Park' in 2021?
CREATE TABLE locations (id INT,name VARCHAR(255)); CREATE TABLE community_policing (id INT,location_id INT,year INT,events INT); INSERT INTO locations (id,name) VALUES (1,'City Park'); INSERT INTO community_policing (id,location_id,year,events) VALUES (1,1,2021,5);
SELECT SUM(events) FROM community_policing WHERE location_id = (SELECT id FROM locations WHERE name = 'City Park') AND year = 2021;
List all artists who have created more than 100 pieces of artwork in the 'Modern Art' category.
CREATE TABLE Artists (artist_id INT,artist_name VARCHAR(255),category VARCHAR(255),num_pieces INT); INSERT INTO Artists (artist_id,artist_name,category,num_pieces) VALUES (1,'Pablo Picasso','Modern Art',120),(2,'Vincent van Gogh','Post-Impressionism',90),(3,'Jackson Pollock','Modern Art',150);
SELECT artist_name, category, num_pieces FROM Artists WHERE category = 'Modern Art' AND num_pieces > 100;
List all military equipment types that require maintenance but haven't had any maintenance requests in the past month
CREATE TABLE military_equipment (equipment_id INT,equipment_type VARCHAR(50),last_maintenance_date DATE); INSERT INTO military_equipment (equipment_id,equipment_type,last_maintenance_date) VALUES (1,'Tank','2022-01-05'),(2,'Helicopter','2022-02-10'),(3,'Submarine',NULL);
SELECT equipment_type FROM military_equipment WHERE last_maintenance_date IS NULL OR last_maintenance_date < DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);
Which department has the highest veteran employment rate?
CREATE TABLE veteran_employment (department VARCHAR(100),num_veterans INT,total_employees INT);
SELECT department, (num_veterans/total_employees)*100 AS veteran_rate FROM veteran_employment ORDER BY veteran_rate DESC LIMIT 1;
How many peacekeeping missions has the UN conducted in Asia in the last 15 years, excluding those led by China or India?
CREATE TABLE Peacekeeping_Missions (Mission VARCHAR(255),Location VARCHAR(255),Year INT,Leader VARCHAR(255));
SELECT COUNT(DISTINCT Mission) FROM Peacekeeping_Missions WHERE Location LIKE '%Asia%' AND Year BETWEEN (YEAR(CURRENT_DATE)-15) AND YEAR(CURRENT_DATE) AND Leader NOT IN ('China', 'India');
Show the names of all workers who have the same last name as 'John Doe'
CREATE TABLE workers_last_name (id INT,name VARCHAR(50),last_name VARCHAR(50)); INSERT INTO workers_last_name (id,name,last_name) VALUES (1,'John Doe','Doe'),(2,'Jane Smith','Smith'),(3,'Alice Johnson','Johnson');
SELECT name FROM workers_last_name WHERE last_name = (SELECT last_name FROM workers_last_name WHERE name = 'John Doe');
What is the average salary of workers in the automotive industry in North America by gender?
CREATE TABLE workers (id INT,name VARCHAR(50),gender VARCHAR(10),industry VARCHAR(50),salary FLOAT); INSERT INTO workers (id,name,gender,industry,salary) VALUES (1,'John Doe','Male','Automotive',50000.0),(2,'Jane Doe','Female','Automotive',55000.0),(3,'Jim Brown','Male','Automotive',48000.0);
SELECT gender, AVG(salary) FROM workers WHERE industry = 'Automotive' GROUP BY gender;
What is the maximum salary of workers in the automotive industry by country?
CREATE TABLE AutomotiveWorkers (WorkerID INT,Country VARCHAR(50),Salary DECIMAL(10,2)); INSERT INTO AutomotiveWorkers (WorkerID,Country,Salary) VALUES (1,'Germany',8000),(2,'Japan',9000),(3,'USA',10000);
SELECT Country, MAX(Salary) as MaxSalary FROM AutomotiveWorkers GROUP BY Country;
List all cybersecurity strategies and their corresponding budgets.
CREATE TABLE CybersecurityStrategies (id INT,strategy VARCHAR(100),budget FLOAT); INSERT INTO CybersecurityStrategies (id,strategy,budget) VALUES (1,'Next-Gen Firewalls',500000.00); INSERT INTO CybersecurityStrategies (id,strategy,budget) VALUES (2,'Intrusion Prevention Systems',750000.00);
SELECT strategy, budget FROM CybersecurityStrategies;
What are the intelligence operations in the 'americas' region?
CREATE TABLE intelligence_operations (id INT,operation TEXT,region TEXT); INSERT INTO intelligence_operations (id,operation,region) VALUES (1,'Op1','americas'),(2,'Op2','americas'),(3,'Op3','asia'),(4,'Op4','asia');
SELECT operation FROM intelligence_operations WHERE region = 'americas';
Calculate the average number of streams per day for each song released in 2010.
CREATE TABLE songs (song_id INT,title VARCHAR(255),genre_id INT,release_date DATE); INSERT INTO songs VALUES (1,'Bad Romance',1,'2010-01-01');
SELECT s.title, AVG(st.stream_count) as avg_daily_streams FROM songs s JOIN (SELECT song_id, COUNT(*) as stream_count, stream_date FROM streams GROUP BY song_id, stream_date) st ON s.song_id = st.song_id WHERE YEAR(s.release_date) = 2010 GROUP BY s.title;
How many jazz albums were sold in the US in Q4 of 2019?
CREATE TABLE albums (album_id INT,genre VARCHAR(10),country VARCHAR(10),release_quarter INT,sales INT); INSERT INTO albums (album_id,genre,country,release_quarter,sales) VALUES (1,'jazz','US',4,1000),(2,'rock','UK',1,2000),(3,'jazz','US',4,1500);
SELECT COUNT(*) FROM albums WHERE genre = 'jazz' AND country = 'US' AND release_quarter = 4;
What is the maximum number of hours contributed by a single volunteer in the second quarter of 2026?
CREATE TABLE Volunteers (VolunteerID INT,Name TEXT);CREATE TABLE VolunteerHours (HourID INT,VolunteerID INT,Hours DECIMAL(10,2),HourDate DATE);
SELECT V.Name, MAX(VH.Hours) as MaxHours FROM VolunteerHours VH JOIN Volunteers V ON VH.VolunteerID = Volunteers.VolunteerID WHERE VH.HourDate BETWEEN '2026-04-01' AND '2026-06-30' GROUP BY V.VolunteerID, V.Name;
Find the number of employees who were hired in the last 30 days and have not received diversity and inclusion training.
CREATE TABLE Employees (EmployeeID INT,HireDate DATE,Training VARCHAR(50));
SELECT COUNT(*) FROM Employees WHERE HireDate >= DATEADD(day, -30, GETDATE()) AND Training IS NULL;
What is the average carbon price in the 'carbon_prices' table, grouped by region?
CREATE TABLE carbon_prices (id INT,region VARCHAR(50),price FLOAT); INSERT INTO carbon_prices (id,region,price) VALUES (1,'EU',25),(2,'US',40),(3,'EU',22),(4,'US',38),(5,'EU',28);
SELECT c.region, AVG(c.price) as avg_price FROM carbon_prices c GROUP BY c.region;
Insert a new record into the 'production_figures' table with the following details: 'well_id' = 3, 'year' = 2020, 'oil_production' = 1500, 'gas_production' = 2500000
CREATE TABLE production_figures (well_id INT,year INT,oil_production INT,gas_production INT);
INSERT INTO production_figures (well_id, year, oil_production, gas_production) VALUES (3, 2020, 1500, 2500000);
What is the average height of players in the basketball team 'Atlanta Hawks'?
CREATE TABLE players (player_name TEXT,team TEXT,height FLOAT); INSERT INTO players (player_name,team,height) VALUES ('John Doe','Atlanta Hawks',196.85); INSERT INTO players (player_name,team,height) VALUES ('Jane Smith','Atlanta Hawks',185.42);
SELECT AVG(height) FROM players WHERE team = 'Atlanta Hawks';
What is the average funding for projects in the technology for social good category?
CREATE TABLE projects (id INT,name TEXT,category TEXT,funding FLOAT); INSERT INTO projects (id,name,category,funding) VALUES (1,'ProjA','DigitalDivide',50000),(2,'ProjB','SocialGood',35000),(4,'ProjD','SocialGood',80000);
SELECT AVG(funding) FROM projects WHERE category = 'SocialGood';
Add a column "region" to "stations_view" with values 'North', 'South', 'East', 'West'.
CREATE TABLE stations (station_id INT,name VARCHAR(255),latitude FLOAT,longitude FLOAT,region VARCHAR(5)); CREATE TABLE routes (route_id INT,name VARCHAR(255),start_station_id INT,end_station_id INT); CREATE VIEW stations_view AS SELECT station_id,name,latitude,longitude,'North' AS region FROM stations WHERE latitude > 40 AND longitude < -70; SELECT * FROM stations WHERE latitude < 40 OR longitude > -70;
ALTER VIEW stations_view AS SELECT station_id, name, latitude, longitude, 'North' AS region FROM stations WHERE latitude > 40 AND longitude < -70; SELECT * FROM stations WHERE latitude < 40 OR longitude > -70;
What is the average delivery time for each route in the delivery database?
CREATE TABLE delivery (route VARCHAR(20),delivery_time INT); INSERT INTO delivery (route,delivery_time) VALUES ('Route1',30),('Route2',40),('Route3',50);
SELECT route, AVG(delivery_time) FROM delivery GROUP BY route;
What is the total weight of all shipments from Brazil to India that were handled by 'DEF Logistics'?
CREATE TABLE FreightForwarders (ID INT,Name VARCHAR(50),Country VARCHAR(50)); INSERT INTO FreightForwarders (ID,Name,Country) VALUES (1,'ABC Logistics','USA'),(2,'XYZ Shipping','Canada'),(3,'DEF Logistics','India'); CREATE TABLE Shipments (ID INT,FreightForwarderID INT,Origin VARCHAR(50),Destination VARCHAR(50),Weight INT); INSERT INTO Shipments (ID,FreightForwarderID,Origin,Destination,Weight) VALUES (1,1,'Tokyo','New York',100),(2,2,'Paris','London',200),(3,3,'Brazil','India',300);
SELECT SUM(Shipments.Weight) FROM FreightForwarders INNER JOIN Shipments ON FreightForwarders.ID = Shipments.FreightForwarderID WHERE FreightForwarders.Name = 'DEF Logistics' AND Shipments.Origin = 'Brazil' AND Shipments.Destination = 'India';
Which biotech startups in Canada have received funding for bioprocess engineering?
CREATE SCHEMA if not exists biotech; CREATE TABLE if not exists biotech.startups (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),total_funding FLOAT); CREATE TABLE if not exists biotech.funding (id INT PRIMARY KEY,startup_id INT,type VARCHAR(255),amount FLOAT); INSERT INTO biotech.startups (id,name,country,total_funding) VALUES (1,'BioCanada','Canada',2000000); INSERT INTO biotech.funding (id,startup_id,type,amount) VALUES (1,1,'Bioprocess Engineering',1000000); INSERT INTO biotech.funding (id,startup_id,type,amount) VALUES (2,1,'Biosensor Technology Development',1000000); INSERT INTO biotech.startups (id,name,country,total_funding) VALUES (2,'BioQuebec','Canada',3000000); INSERT INTO biotech.funding (id,startup_id,type,amount) VALUES (3,2,'Genetic Research',2000000); INSERT INTO biotech.funding (id,startup_id,type,amount) VALUES (4,2,'Bioprocess Engineering',1000000);
SELECT s.name FROM biotech.startups s JOIN biotech.funding f ON s.id = f.startup_id WHERE s.country = 'Canada' AND f.type = 'Bioprocess Engineering';
How many public schools are there in California, and what is the average enrollment per school?
CREATE TABLE public_schools (name VARCHAR(255),state VARCHAR(255),enrollment INT); INSERT INTO public_schools (name,state,enrollment) VALUES ('Los Angeles High School','California',3150),('San Francisco High School','California',2500),('Oakland High School','California',2200);
SELECT AVG(enrollment) AS avg_enrollment FROM public_schools WHERE state = 'California';
What is the total number of petitions submitted by each city in the state of California?
CREATE TABLE city (id INT,name VARCHAR(255),state VARCHAR(255)); INSERT INTO city (id,name,state) VALUES (1,'San Francisco','California'); INSERT INTO city (id,name,state) VALUES (2,'Los Angeles','California'); CREATE TABLE petition (id INT,city_id INT,num_signatures INT); INSERT INTO petition (id,city_id,num_signatures) VALUES (1,1,300); INSERT INTO petition (id,city_id,num_signatures) VALUES (2,1,500); INSERT INTO petition (id,city_id,num_signatures) VALUES (3,2,700);
SELECT city.name, SUM(petition.num_signatures) as total_signatures FROM city JOIN petition ON city.id = petition.city_id WHERE city.state = 'California' GROUP BY city.name;
List all renewable energy projects in the 'renewable_projects' view that started after a specific date (e.g., '2020-01-01').
CREATE VIEW renewable_projects AS SELECT project_id,city,start_date FROM energy_projects WHERE renewable = TRUE; CREATE TABLE energy_projects (project_id INT,city VARCHAR(255),start_date DATE,renewable BOOLEAN);
SELECT * FROM renewable_projects WHERE start_date > '2020-01-01';
List all renewable energy projects in the 'renewable_projects' view, along with their corresponding city and start date.
CREATE VIEW renewable_projects AS SELECT project_id,city,start_date FROM energy_projects WHERE renewable = TRUE; CREATE TABLE energy_projects (project_id INT,city VARCHAR(255),start_date DATE,renewable BOOLEAN);
SELECT * FROM renewable_projects;
What is the average water consumption and waste generation for each building in a specific city?
CREATE TABLE building_data (id INT,building_id INT,city VARCHAR(255),type VARCHAR(255),value FLOAT,timestamp TIMESTAMP); INSERT INTO building_data (id,building_id,city,type,value,timestamp) VALUES (1,1,'EcoCity','Water Consumption',5000,'2022-04-01 10:00:00'),(2,1,'EcoCity','Waste Generation',200,'2022-04-01 10:00:00');
SELECT building_id, city, type, AVG(value) as avg_value FROM building_data GROUP BY building_id, city, type;
List the names of hotels in Europe that have sustainable practices.
CREATE TABLE hotels (hotel_id INT,name VARCHAR,location VARCHAR,sustainable BOOLEAN); CREATE VIEW european_hotels AS SELECT * FROM hotels WHERE location LIKE '%%Europe%%';
SELECT name FROM european_hotels WHERE sustainable = TRUE;
Find the number of paintings created per year for the artist 'Frida Kahlo'.
CREATE TABLE Artists (ArtistID INT,Name VARCHAR(50),Nationality VARCHAR(50)); INSERT INTO Artists (ArtistID,Name,Nationality) VALUES (1,'Vincent van Gogh','Dutch'); INSERT INTO Artists (ArtistID,Name,Nationality) VALUES (2,'Frida Kahlo','Mexican'); CREATE TABLE Paintings (PaintingID INT,Title VARCHAR(50),ArtistID INT,YearCreated INT); INSERT INTO Paintings (PaintingID,Title,ArtistID,YearCreated) VALUES (1,'The Two Fridas',2,1939); INSERT INTO Paintings (PaintingID,Title,ArtistID,YearCreated) VALUES (2,'Self-Portrait with Cropped Hair',2,1940);
SELECT YearCreated, COUNT(*) as NumberOfPaintings FROM Paintings WHERE ArtistID = 2 GROUP BY YearCreated ORDER BY YearCreated;
What are the most common art mediums in the database?
CREATE TABLE Art (id INT,title VARCHAR(255),medium VARCHAR(50)); CREATE TABLE Medium (id INT,name VARCHAR(50)); CREATE TABLE Art_Medium (art_id INT,medium_id INT);
SELECT Medium.name, COUNT(Art_Medium.art_id) AS artwork_count FROM Medium JOIN Art_Medium ON Medium.id = Art_Medium.medium_id JOIN Art ON Art_Medium.art_id = Art.id GROUP BY Medium.name ORDER BY artwork_count DESC LIMIT 1;
What is the total cost of projects for each category?
CREATE TABLE Projects (category VARCHAR(20),project_cost INT); INSERT INTO Projects (category,project_cost) VALUES ('Bridge',5000000),('Road',3000000),('Water Treatment',6500000),('Dams Safety',7500000),('Transit System',9000000);
SELECT category, SUM(project_cost) FROM Projects GROUP BY category;
How many tourists visited Marrakech from Morocco in 2019?
CREATE TABLE visitor_stats_2 (id INT,year INT,country VARCHAR(10),city VARCHAR(20),num_tourists INT); INSERT INTO visitor_stats_2 (id,year,country,city,num_tourists) VALUES (1,2019,'Morocco','Marrakech',65000),(2,2019,'France','Marrakech',40000),(3,2018,'Morocco','Marrakech',55000);
SELECT SUM(num_tourists) FROM visitor_stats_2 WHERE year = 2019 AND country = 'Morocco' AND city = 'Marrakech';
How many traffic citations were issued to drivers of each age group in California in the last year?
CREATE TABLE traffic_citations (citation_number INT,driver_age INT,issue_date DATE,citation_amount FLOAT); INSERT INTO traffic_citations (citation_number,driver_age,issue_date,citation_amount) VALUES (1,25,'2021-01-01',150),(2,35,'2021-02-01',200),(3,45,'2021-03-01',100),(4,55,'2021-04-01',250);
SELECT FLOOR(DATEDIFF(CURRENT_DATE, issue_date)/365) AS driver_age, COUNT(*) AS citations_issued FROM traffic_citations GROUP BY FLOOR(DATEDIFF(CURRENT_DATE, issue_date)/365);
What is the number of cases in each court, broken down by case type and case status?
CREATE TABLE CourtCases (CourtName text,CaseType text,CaseStatus text,NumCases int); INSERT INTO CourtCases VALUES ('Court1','Assault','Open',30,'2022-01-01'),('Court1','Theft','Closed',25,'2022-01-01'),('Court2','Assault','Open',28,'2022-01-01'),('Court2','Theft','Closed',22,'2022-01-01');
SELECT CourtName, CaseType, CaseStatus, SUM(NumCases) FROM CourtCases GROUP BY CourtName, CaseType, CaseStatus;
What is the number of offenders who have not committed any offenses in the last 3 years?
CREATE TABLE offenses (offender_id INT,offense_date DATE); INSERT INTO offenses (offender_id,offense_date) VALUES (1,'2018-01-01'),(1,'2019-01-01'),(2,'2017-01-01');
SELECT COUNT(DISTINCT offender_id) AS num_offenders_no_offenses FROM offenses WHERE offense_date < DATEADD(year, -3, CURRENT_DATE());
Which countries have more than one marine law?
CREATE TABLE Laws (id INT,country VARCHAR(255),name VARCHAR(255),description TEXT); INSERT INTO Laws (id,country,name,description) VALUES (5,'UK','Maritime Law','Regulates navigation and commerce in the UK waters'); INSERT INTO Laws (id,country,name,description) VALUES (6,'Germany','Marine Protection Act','Protects the marine environment in Germany');
SELECT country, COUNT(*) FROM Laws WHERE name LIKE '%Marine%' GROUP BY country HAVING COUNT(*) > 1;
What is the average rating of films directed by women?
CREATE TABLE movies (id INT,title TEXT,rating FLOAT,director TEXT); INSERT INTO movies (id,title,rating,director) VALUES (1,'Movie1',7.5,'DirectorA'),(2,'Movie2',8.2,'DirectorB'),(3,'Movie3',6.8,'DirectorA');
SELECT AVG(rating) FROM movies WHERE director IN ('DirectorA', 'DirectorC');
What is the average word count of articles published in the last week by authors from historically marginalized communities?
CREATE TABLE articles (title VARCHAR(255),publication_date DATE,author VARCHAR(255),community VARCHAR(255),word_count INT); INSERT INTO articles (title,publication_date,author,community,word_count) VALUES ('Article1','2023-03-28','Author1','Historically Marginalized Community1',800),('Article2','2023-03-30','Author2','Historically Marginalized Community2',1000),('Article3','2023-04-03','Author3','Historically Marginalized Community1',1200),('Article4','2023-04-05','Author4','Historically Marginalized Community2',900),('Article5','2023-04-07','Author5','Historically Marginalized Community3',1100);
SELECT AVG(word_count) FROM articles WHERE publication_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK) AND community IN ('Historically Marginalized Community1', 'Historically Marginalized Community2', 'Historically Marginalized Community3');
What is the total duration of videos in the 'Entertainment' category with a rating higher than 8?
CREATE TABLE Videos (video_id INT,title VARCHAR(255),category VARCHAR(50),rating FLOAT,duration INT); INSERT INTO Videos (video_id,title,category,rating,duration) VALUES (1,'Video1','Entertainment',8.5,60),(2,'Video2','Entertainment',7.2,90),(3,'Video3','Education',9.0,120);
SELECT SUM(duration) FROM Videos WHERE category = 'Entertainment' AND rating > 8;
List all defense projects with a start date after January 1, 2022.
CREATE TABLE DefenseProjects (project_id INT,project_name VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO DefenseProjects (project_id,project_name,start_date,end_date) VALUES (1,'Project A','2022-02-01','2023-01-31'),(2,'Project B','2021-06-15','2022-05-31'),(3,'Project C','2023-04-01','2024-03-31');
SELECT * FROM DefenseProjects WHERE start_date > '2022-01-01';
Which defense projects have a duration greater than the average defense project duration?
CREATE TABLE Defense_Project_Timelines (project_id INT,project_name VARCHAR(50),start_date DATE,end_date DATE); INSERT INTO Defense_Project_Timelines (project_id,project_name,start_date,end_date) VALUES (1,'Project X','2018-01-01','2020-12-31'); INSERT INTO Defense_Project_Timelines (project_id,project_name,start_date,end_date) VALUES (2,'Project Y','2019-01-01','2021-12-31'); INSERT INTO Defense_Project_Timelines (project_id,project_name,start_date,end_date) VALUES (3,'Project Z','2020-01-01','2022-12-31');
SELECT project_id, project_name, DATEDIFF('day', start_date, end_date) AS project_duration FROM Defense_Project_Timelines WHERE DATEDIFF('day', start_date, end_date) > AVG(DATEDIFF('day', start_date, end_date)) OVER (PARTITION BY NULL);
Which mining company has the lowest labor productivity in coal extraction?
CREATE TABLE companies (company VARCHAR(50),location VARCHAR(50),material VARCHAR(50),productivity FLOAT); INSERT INTO companies (company,location,material,productivity) VALUES ('ABC Corp','USA','Coal',1.2),('XYZ Inc','China','Coal',1.5),('DEF Mining','Australia','Coal',1.3),('GHI Enterprises','India','Coal',1.1);
SELECT company, MIN(productivity) as lowest_productivity FROM companies WHERE material = 'Coal' GROUP BY company ORDER BY lowest_productivity ASC LIMIT 1;
What is the total quantity of resources extracted by gender and race in the 'mining_operations' database?
CREATE TABLE resource_extraction (resource_id INT PRIMARY KEY,resource_name VARCHAR(50),quantity INT,extractor_gender VARCHAR(10),extractor_race VARCHAR(30)); INSERT INTO resource_extraction (resource_id,resource_name,quantity,extractor_gender,extractor_race) VALUES (1,'Gold',1000,'Male','Caucasian'),(2,'Silver',800,'Female','African American'),(3,'Copper',1200,'Non-binary','Hispanic'),(4,'Iron',1500,'Male','Asian');
SELECT extractor_gender, extractor_race, SUM(quantity) as total_quantity FROM resource_extraction GROUP BY extractor_gender, extractor_race;
What is the total number of mobile subscribers in each state, excluding those with a monthly data usage of 0?
CREATE TABLE states (id INT,name VARCHAR(255),region VARCHAR(255));CREATE TABLE mobile_subscribers (id INT,state_id INT,monthly_data_usage DECIMAL(10,2));
SELECT s.name, COUNT(ms.id) as total_subscribers FROM states s LEFT JOIN mobile_subscribers ms ON s.id = ms.state_id WHERE ms.monthly_data_usage > 0 GROUP BY s.name;
Which mobile and broadband subscribers have not used their services in the last 30 days?
CREATE TABLE mobile_usage (customer_id INT,last_usage DATE); CREATE TABLE broadband_usage (customer_id INT,last_usage DATE); INSERT INTO mobile_usage (customer_id,last_usage) VALUES (1,'2022-01-01'),(2,'2022-02-01'); INSERT INTO broadband_usage (customer_id,last_usage) VALUES (1,'2022-01-15'),(3,'2022-02-10');
SELECT customer_id FROM mobile_usage WHERE last_usage < NOW() - INTERVAL 30 DAY UNION SELECT customer_id FROM broadband_usage WHERE last_usage < NOW() - INTERVAL 30 DAY;
Update the name of the 'audience_demographics' table to 'audience'
CREATE TABLE audience_demographics (id INT,age INT,gender VARCHAR(10),location VARCHAR(100));
ALTER TABLE audience_demographics RENAME TO audience;
What is the maximum water pressure at the deepest point in the Atlantic?
CREATE TABLE deep_sea_pressure (id INT,location VARCHAR(255),pressure INT,depth INT); INSERT INTO deep_sea_pressure (id,location,pressure,depth) VALUES (1,'Challenger Deep',1100,10972),(2,'Mariana Trench',800,10994);
SELECT MAX(pressure) FROM deep_sea_pressure WHERE location = 'Challenger Deep';
Which vessels have the most severe maritime safety violations?
CREATE TABLE countries (id INT,name TEXT); CREATE TABLE vessels (id INT,country_id INT,name TEXT,num_employees INT); CREATE TABLE violations (id INT,vessel_id INT,severity INT); INSERT INTO countries VALUES (1,'Peru'),(2,'Chile'),(3,'Ecuador'); INSERT INTO vessels VALUES (1,1,'Peruvian 1',20),(2,2,'Chilean 1',30),(3,3,'Ecuadorian 1',40); INSERT INTO violations VALUES (1,1,5),(2,1,3),(3,2,10),(4,3,7);
SELECT v.name, SUM(vio.severity) as total_severity FROM vessels v INNER JOIN violations vio ON v.id = vio.vessel_id GROUP BY v.name ORDER BY total_severity DESC;
Which virtual reality games have been reviewed the most in gaming magazines?
CREATE TABLE Games (GameName VARCHAR(255),MagazineReviews INT); INSERT INTO Games (GameName,MagazineReviews) VALUES ('Game1',12),('Game2',15),('Game3',21),('Game4',8),('Game5',17);
SELECT GameName FROM Games ORDER BY MagazineReviews DESC LIMIT 2;
How many soil moisture sensors are currently malfunctioning?
CREATE TABLE SensorData (sensor_id INT,status VARCHAR(255),crop VARCHAR(255)); CREATE TABLE SoilMoistureSensor (sensor_id INT,location VARCHAR(255));
SELECT COUNT(*) FROM SensorData SD JOIN SoilMoistureSensor SMS ON SD.sensor_id = SMS.sensor_id WHERE SD.status = 'malfunctioning';
What is the distribution of property types for properties with a property tax greater than $5000?
CREATE TABLE properties (property_id INT,property_type VARCHAR(50),property_tax FLOAT);
SELECT property_type, COUNT(*) as count FROM properties WHERE property_tax > 5000 GROUP BY property_type;
Update the type of debris with id 1 to 'Abandoned Spacecraft'
CREATE TABLE space_debris (id INT PRIMARY KEY,debris_name VARCHAR(100),launch_date DATE,type VARCHAR(50));
UPDATE space_debris SET type = 'Abandoned Spacecraft' WHERE id = 1;
What is the total mass of exoplanets with a discovered atmosphere?
CREATE TABLE exoplanets (id INT,name VARCHAR(50),mass FLOAT,atmosphere BOOLEAN); INSERT INTO exoplanets (id,name,mass,atmosphere) VALUES (1,'Kepler-10b',4.5,true),(2,'Gliese 436 b',9.4,true),(3,'CoRoT-7b',5.7,false);
SELECT SUM(mass) FROM exoplanets WHERE atmosphere = true;
What is the average mass of spacecraft manufactured by 'Galactic Instruments'?
CREATE TABLE Spacecraft_Manufacturing (Manufacturer VARCHAR(255),Spacecraft_Name VARCHAR(255),Mass FLOAT); INSERT INTO Spacecraft_Manufacturing (Manufacturer,Spacecraft_Name,Mass) VALUES ('Galactic Instruments','Starlight Explorer',2000.5),('Galactic Instruments','Nebula Chaser',2500.3);
SELECT AVG(Mass) FROM Spacecraft_Manufacturing WHERE Manufacturer = 'Galactic Instruments';