instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the average call duration per day for each customer?
CREATE TABLE calls (call_id INT,customer_id INT,call_duration INT,call_date DATE); INSERT INTO calls VALUES (1,1,200,'2022-01-01'); INSERT INTO calls VALUES (2,1,150,'2022-01-02'); INSERT INTO calls VALUES (3,2,250,'2022-01-03');
SELECT customer_id, DATE(call_date) as call_date, AVG(call_duration) as avg_call_duration FROM calls GROUP BY customer_id, call_date;
Find the difference between the sum of capacities for hydro and wind power in the 'renewables' schema?
CREATE SCHEMA renewables;CREATE TABLE hydro_power (name VARCHAR(50),capacity INT);INSERT INTO renewables.hydro_power (name,capacity) VALUES ('PowerPlant1',300);CREATE TABLE wind_farms (name VARCHAR(50),capacity INT);INSERT INTO renewables.wind_farms (name,capacity) VALUES ('Farm1',100),('Farm2',200);
SELECT (SELECT SUM(capacity) FROM renewables.hydro_power) - (SELECT SUM(capacity) FROM renewables.wind_farms);
What is the total revenue of jazz festivals in North America?
CREATE TABLE Festivals (FestivalID INT,Name VARCHAR(255),Genre VARCHAR(255),Location VARCHAR(255),Country VARCHAR(255),Year INT,Revenue INT); INSERT INTO Festivals VALUES (4,'Montreal Jazz Festival','Jazz','Montreal','Canada',2022,12000000); INSERT INTO Festivals VALUES (5,'Newport Jazz Festival','Jazz','Newport','USA'...
SELECT SUM(Revenue) FROM Festivals WHERE Genre = 'Jazz' AND Country = 'North America';
How many employees were hired in each month of 2020?
CREATE TABLE employees (employee_id INT,name TEXT,hire_date DATE);
SELECT EXTRACT(MONTH FROM hire_date) AS month, COUNT(*) AS num_hired FROM employees WHERE hire_date BETWEEN '2020-01-01' AND '2020-12-31' GROUP BY month;
What is the total number of tourists who visited Canadian national parks in 2019 and 2020?
CREATE TABLE national_parks (country VARCHAR(20),park VARCHAR(50),visitors INT,year INT); INSERT INTO national_parks (country,park,visitors,year) VALUES ('Canada','Banff National Park',800000,2019),('Canada','Jasper National Park',600000,2019),('Canada','Banff National Park',700000,2020),('Canada','Jasper National Park...
SELECT year, SUM(visitors) as total_visitors FROM national_parks WHERE country = 'Canada' GROUP BY year;
What is the minimum, maximum, and average explainability score of the models developed by different organizations?
CREATE TABLE models_explainability (model_id INT,org_id INT,explainability_score FLOAT); INSERT INTO models_explainability (model_id,org_id,explainability_score) VALUES (101,1,0.85),(102,1,0.92),(103,2,0.88),(104,2,0.9),(105,3,0.95);
SELECT org_id, MIN(explainability_score) as min_score, MAX(explainability_score) as max_score, AVG(explainability_score) as avg_score FROM models_explainability GROUP BY org_id;
What's the average rating for horror movies?
CREATE TABLE movies (id INT,title VARCHAR(255),genre VARCHAR(50),rating DECIMAL(3,2)); INSERT INTO movies (id,title,genre,rating) VALUES (1,'MovieA','Horror',7.2); INSERT INTO movies (id,title,genre,rating) VALUES (2,'MovieB','Comedy',8.5); INSERT INTO movies (id,title,genre,rating) VALUES (3,'MovieC','Horror',6.8);
SELECT AVG(rating) FROM movies WHERE genre = 'Horror';
Display the total revenue generated from broadband services for each quarter in the year 2021.
CREATE TABLE broadband_revenue (revenue_id INT,revenue_date DATE,revenue_amount FLOAT); INSERT INTO broadband_revenue (revenue_id,revenue_date,revenue_amount) VALUES (1,'2021-01-01',25000); INSERT INTO broadband_revenue (revenue_id,revenue_date,revenue_amount) VALUES (2,'2021-02-15',30000);
SELECT DATE_TRUNC('quarter', revenue_date) AS quarter, SUM(revenue_amount) AS total_revenue FROM broadband_revenue WHERE revenue_date >= '2021-01-01' AND revenue_date < '2022-01-01' GROUP BY quarter;
How many security incidents were recorded in each city in the last 6 months?
CREATE TABLE security_incidents (id INT,city VARCHAR(255),timestamp TIMESTAMP);
SELECT city, COUNT(*) FROM security_incidents WHERE timestamp >= NOW() - INTERVAL 6 MONTH GROUP BY city;
Which state has the least landfill capacity remaining?
CREATE TABLE landfill_capacity (state VARCHAR(20),capacity_remaining FLOAT); INSERT INTO landfill_capacity (state,capacity_remaining) VALUES ('New York',75.0),('Pennsylvania',70.0),('New Jersey',65.0);
SELECT state, MIN(capacity_remaining) FROM landfill_capacity;
What is the average price of military equipment sold to European countries in the last quarter?
CREATE TABLE military_equipment (id INT,equipment_name VARCHAR(50),equipment_type VARCHAR(30),price DECIMAL(10,2),sale_date DATE);
SELECT AVG(price) as avg_price FROM military_equipment WHERE sale_date >= DATEADD(quarter, -1, GETDATE()) AND country IN ('France', 'Germany', 'Italy', 'Spain', 'United Kingdom');
Calculate the percentage of space debris that is larger than 10 cm?
CREATE TABLE space_debris (id INT,size DECIMAL(3,1),source VARCHAR(50));
SELECT 100.0 * COUNT(CASE WHEN size > 10 THEN 1 END) / COUNT(*) AS pct_large_debris FROM space_debris;
What is the average number of followers for users who posted in the 'cooking' category on Facebook?
CREATE TABLE user_data (user_id INT,followers INT,category VARCHAR(50),platform VARCHAR(20)); INSERT INTO user_data (user_id,followers,category,platform) VALUES (1,1000,'cooking','Facebook'),(2,2000,'technology','Facebook'),(3,500,'cooking','Facebook');
SELECT AVG(followers) FROM user_data WHERE category = 'cooking' AND platform = 'Facebook';
List all wildlife habitats that have an area greater than 60
CREATE TABLE wildlife_habitat (id INT,name VARCHAR(50),area FLOAT); INSERT INTO wildlife_habitat (id,name,area) VALUES (1,'Habitat1',50.23); INSERT INTO wildlife_habitat (id,name,area) VALUES (2,'Habitat2',75.64); INSERT INTO wildlife_habitat (id,name,area) VALUES (3,'Habitat3',85.34);
SELECT * FROM wildlife_habitat WHERE area > 60;
Update the prevalence to 0.12 for the record with the name 'Influenza' in the 'rural_diseases' table
CREATE TABLE rural_diseases (id INT,name VARCHAR(50),prevalence DECIMAL(3,2),location VARCHAR(50));
UPDATE rural_diseases SET prevalence = 0.12 WHERE name = 'Influenza';
What is the most common type of aid provided for each disaster, and the total cost of that type of aid?
CREATE TABLE Disasters (DisasterID INT,DisasterName VARCHAR(100),DisasterType VARCHAR(100)); INSERT INTO Disasters (DisasterID,DisasterName,DisasterType) VALUES (1,'Disaster1','Flood'),(2,'Disaster2','Earthquake'),(3,'Disaster3','Flood'); CREATE TABLE Aid (AidID INT,AidType VARCHAR(100),DisasterID INT,Cost DECIMAL(10,2...
SELECT DisasterType, AidType, COUNT(*) as Count, SUM(Cost) as TotalCost FROM Aid JOIN Disasters ON Aid.DisasterID = Disasters.DisasterID GROUP BY DisasterType, AidType ORDER BY Count DESC, TotalCost DESC;
What is the total number of vegetarian dishes offered by each cuisine?
CREATE TABLE cuisine (cuisine_id INT,cuisine_name VARCHAR(255)); INSERT INTO cuisine VALUES (1,'Italian'); INSERT INTO cuisine VALUES (2,'Indian'); CREATE TABLE dishes (dish_id INT,dish_name VARCHAR(255),cuisine_id INT,is_vegetarian BOOLEAN); INSERT INTO dishes VALUES (1,'Pizza Margherita',1,true); INSERT INTO dishes V...
SELECT cuisine_name, COUNT(*) as total_veg_dishes FROM cuisine JOIN dishes ON cuisine.cuisine_id = dishes.cuisine_id WHERE is_vegetarian = true GROUP BY cuisine_name;
What is the total number of flight safety incidents and fatalities for each airline?
CREATE TABLE Flight_Safety_Record (id INT,airline VARCHAR(255),incidents INT,fatalities INT); INSERT INTO Flight_Safety_Record (id,airline,incidents,fatalities) VALUES (1,'Delta Airlines',5,0),(2,'American Airlines',3,1);
SELECT airline, SUM(incidents + fatalities) as total_safety_issues FROM Flight_Safety_Record GROUP BY airline;
Get the total number of accidents in the past 12 months?
CREATE TABLE accidents (id INT,date DATE,description VARCHAR(50),severity INT);
SELECT COUNT(*) FROM accidents WHERE date >= DATE_SUB(CURRENT_DATE, INTERVAL 12 MONTH);
What is the total number of paintings created by artists from different continents in the last 50 years?
CREATE TABLE artists (id INT,name VARCHAR(50),continent VARCHAR(50)); INSERT INTO artists (id,name,continent) VALUES (1,'Frida Kahlo','North America'); CREATE TABLE paintings (id INT,artist_id INT,year INT); INSERT INTO paintings (id,artist_id,year) VALUES (1,1,2000); INSERT INTO paintings (id,artist_id,year) VALUES (2...
SELECT a.continent, COUNT(p.id) as total_paintings FROM paintings p JOIN artists a ON p.artist_id = a.id WHERE p.year BETWEEN YEAR(GETDATE()) - 50 AND YEAR(GETDATE()) GROUP BY a.continent;
Delete records of sizes that are not available in the inventory.
CREATE TABLE clothing_items (id INT PRIMARY KEY,name VARCHAR(50),category VARCHAR(20),available_sizes TEXT); CREATE TABLE inventory (id INT PRIMARY KEY,clothing_item_id INT,size VARCHAR(10),quantity INT);
DELETE FROM clothing_items WHERE available_sizes NOT LIKE CONCAT('%', (SELECT GROUP_CONCAT(DISTINCT size) FROM inventory WHERE clothing_item_id = clothing_items.id), '%');
What are the average THC and CBD percentages for strains grown in Colorado, grouped by the farm they come from?
CREATE TABLE farms (id INT,name TEXT,state TEXT); INSERT INTO farms (id,name,state) VALUES (1,'Farm A','Colorado'),(2,'Farm B','California'),(3,'Farm C','Colorado'); CREATE TABLE strains (id INT,farm_id INT,name TEXT,thc_percentage DECIMAL(5,2),cbd_percentage DECIMAL(5,2)); INSERT INTO strains (id,farm_id,name,thc_perc...
SELECT f.name AS farm_name, AVG(s.thc_percentage) AS avg_thc, AVG(s.cbd_percentage) AS avg_cbd FROM strains s JOIN farms f ON s.farm_id = f.id WHERE f.state = 'Colorado' GROUP BY f.name;
Find the transaction date with the maximum transaction amount for each customer.
CREATE TABLE customer_transactions (transaction_date DATE,customer_id INT,transaction_amt DECIMAL(10,2)); INSERT INTO customer_transactions (transaction_date,customer_id,transaction_amt) VALUES ('2022-01-01',1,200.00),('2022-01-02',2,300.50),('2022-01-03',3,150.25);
SELECT transaction_date, customer_id, transaction_amt, RANK() OVER (PARTITION BY customer_id ORDER BY transaction_amt DESC) AS rank FROM customer_transactions;
How many graduate students in the College of Social Sciences have published more than 2 papers?
CREATE TABLE graduate_students (id INT,name VARCHAR(100),department VARCHAR(50),publications INT); INSERT INTO graduate_students (id,name,department,publications) VALUES (1,'Heidi','Sociology',3),(2,'Anthropology',4); CREATE VIEW social_sciences_departments AS SELECT DISTINCT department FROM graduate_students WHERE dep...
SELECT COUNT(*) FROM graduate_students WHERE department IN (SELECT department FROM social_sciences_departments) AND publications > 2;
Which safety measures are used in Japan for storing toxic chemicals?
CREATE TABLE Chemicals (Id INT,Name VARCHAR(255),Toxicity INT,Manufacturing_Country VARCHAR(255)); CREATE TABLE Safety_Protocols (Id INT,Chemical_Id INT,Safety_Measure VARCHAR(255)); INSERT INTO Chemicals (Id,Name,Toxicity,Manufacturing_Country) VALUES (1,'Sodium Cyanide',10,'Japan'); INSERT INTO Safety_Protocols (Id,C...
SELECT Chemicals.Name, Safety_Protocols.Safety_Measure FROM Chemicals INNER JOIN Safety_Protocols ON Chemicals.Id = Safety_Protocols.Chemical_Id WHERE Chemicals.Manufacturing_Country = 'Japan' AND Chemicals.Toxicity > 5;
List the agricultural innovation projects in Uganda that started in 2019 or later.
CREATE TABLE AgriculturalInnovations (id INT,country VARCHAR(50),project VARCHAR(50),start_date DATE); INSERT INTO AgriculturalInnovations (id,country,project,start_date) VALUES (1,'Uganda','AgriTech App Development','2019-03-01'),(2,'Uganda','Modern Irrigation Systems','2018-08-15'),(3,'Kenya','Solar Powered Pumps','2...
SELECT project FROM AgriculturalInnovations WHERE country = 'Uganda' AND start_date >= '2019-01-01';
What is the total spending on military innovation by country and year?
CREATE TABLE military_innovation_spending (spending_id INT,country VARCHAR(50),year INT,spending INT); INSERT INTO military_innovation_spending (spending_id,country,year,spending) VALUES (1,'United States',2018,500000),(2,'China',2019,300000),(3,'Russia',2020,200000),(4,'United States',2017,600000),(5,'India',2016,4000...
SELECT mi.country, YEAR(mi.year), SUM(mi.spending) as total_spending FROM military_innovation_spending mi GROUP BY mi.country, YEAR(mi.year);
What is the total weight of imported plant-based protein?
CREATE TABLE imports (id INT,product TEXT,quantity INT,country TEXT); INSERT INTO imports (id,product,quantity,country) VALUES (1,'Tofu',1000,'China'),(2,'Lentils',2000,'Canada');
SELECT SUM(quantity) FROM imports WHERE product LIKE '%plant-based%' AND country NOT IN ('United States', 'Mexico');
Determine the percentage of hair care products that contain sulfates, based on the current inventory.
CREATE TABLE inventory (product_id INT,product_name TEXT,product_type TEXT,contains_sulfates BOOLEAN); INSERT INTO inventory (product_id,product_name,product_type,contains_sulfates) VALUES (1,'Product 1','Hair Care',true),(2,'Product 2','Hair Care',false),(3,'Product 3','Skin Care',false),(4,'Product 4','Hair Care',tru...
SELECT 100.0 * COUNT(*) / (SELECT COUNT(*) FROM inventory WHERE product_type = 'Hair Care') AS pct_sulfates FROM inventory WHERE product_type = 'Hair Care' AND contains_sulfates = true;
What is the average funding received by startups founded by women in the renewable energy sector?
CREATE TABLE startup (id INT,name VARCHAR(255),sector VARCHAR(255),founding_date DATE,funding FLOAT,founder_gender VARCHAR(50)); INSERT INTO startup (id,name,sector,founding_date,funding,founder_gender) VALUES (1,'Echo Inc','Technology','2010-01-01',3000000.0,'Male'); INSERT INTO startup (id,name,sector,founding_date,f...
SELECT AVG(funding) FROM startup WHERE sector = 'Renewable Energy' AND founder_gender = 'Female';
What is the total water consumption by residential sector in 2020 and 2021?
CREATE TABLE water_consumption (year INT,sector TEXT,consumption FLOAT); INSERT INTO water_consumption (year,sector,consumption) VALUES (2015,'residential',123.5),(2015,'commercial',234.6),(2016,'residential',130.2),(2016,'commercial',240.1),(2020,'residential',150.8),(2020,'commercial',255.9),(2021,'residential',160.5...
SELECT consumption FROM water_consumption WHERE sector = 'residential' AND (year = 2020 OR year = 2021)
Which socially equitable dispensaries in WA have a specific strain?
CREATE TABLE dispensaries (id INT,name TEXT,state TEXT,equitable BOOLEAN); INSERT INTO dispensaries (id,name,state,equitable) VALUES (1,'Dispensary X','Washington',true),(2,'Dispensary Y','Washington',false); CREATE TABLE strains (id INT,name TEXT,dispensary_id INT); INSERT INTO strains (id,name,dispensary_id) VALUES (...
SELECT d.name FROM dispensaries d JOIN strains s ON d.id = s.dispensary_id WHERE d.state = 'Washington' AND d.equitable = true AND s.name = 'Strain A';
What is the number of employees in each department?
CREATE TABLE Employees (EmployeeID INT,Department VARCHAR(20)); INSERT INTO Employees (EmployeeID,Department) VALUES (1,'Marketing'),(2,'Marketing'),(3,'IT'),(4,'HR'); CREATE TABLE Departments (Department VARCHAR(20),Manager VARCHAR(20)); INSERT INTO Departments (Department,Manager) VALUES ('Marketing','John'),('IT','J...
SELECT Department, COUNT(*) FROM Employees GROUP BY Department;
Update the Players table to set the country to 'Africa' for players who are 18 or older and prefer racing games.
CREATE TABLE Players (PlayerID INT PRIMARY KEY,Gender VARCHAR(10),Age INT,Country VARCHAR(50),PreferredGenre VARCHAR(20)); INSERT INTO Players (PlayerID,Gender,Age,Country,PreferredGenre) VALUES (6,'Male',19,'Nigeria','Racing'); INSERT INTO Players (PlayerID,Gender,Age,Country,PreferredGenre) VALUES (7,'Female',22,'Sou...
UPDATE Players SET Country = 'Africa' WHERE Age >= 18 AND PreferredGenre = 'Racing';
What is the average number of visitors per day for each exhibition?
CREATE TABLE Exhibitions (id INT,name VARCHAR(20),start_date DATE,end_date DATE); INSERT INTO Exhibitions VALUES (1,'Exhibition A','2022-01-01','2022-03-31'),(2,'Exhibition B','2022-02-01','2022-04-30'),(3,'Exhibition C','2022-03-01','2022-05-31'); CREATE TABLE Visitors (id INT,exhibition_id INT,visit_date DATE); INSER...
SELECT Exhibitions.name, AVG(DATEDIFF(Visitors.visit_date, Exhibitions.start_date) + 1) AS avg_visitors_per_day FROM Exhibitions INNER JOIN Visitors ON Exhibitions.id = Visitors.exhibition_id GROUP BY Exhibitions.name;
What is the maximum depth of the South Sandwich Trench in the South Atlantic Ocean?
CREATE TABLE South_Atlantic_Trenches (trench_name TEXT,location TEXT,max_depth FLOAT); INSERT INTO South_Atlantic_Trenches (trench_name,location,max_depth) VALUES ('South Sandwich Trench','South Atlantic Ocean',8428.0);
SELECT max_depth FROM South_Atlantic_Trenches WHERE trench_name = 'South Sandwich Trench';
What are the names and completion dates of community development initiatives in 'RuralDev' database that have been completed in the last year?
CREATE TABLE community_initiatives_2 (id INT,name VARCHAR(255),completion_date DATE); INSERT INTO community_initiatives_2 (id,name,completion_date) VALUES (1,'Youth Skills Training','2021-03-01'),(2,'Women Empowerment Program','2020-05-15'),(3,'Elderly Care Center','2019-12-20');
SELECT name, completion_date FROM community_initiatives_2 WHERE completion_date >= DATEADD(year, -1, GETDATE());
How many students in 'StudentMentalHealth' table have a mental health score greater than 80?
CREATE TABLE StudentMentalHealth (id INT,name TEXT,mental_health_score INT); INSERT INTO StudentMentalHealth (id,name,mental_health_score) VALUES (1,'Jessica',75),(2,'Lucas',85),(3,'Oliver',95);
SELECT COUNT(*) FROM StudentMentalHealth WHERE mental_health_score > 80;
What is the earliest pickup date for pending freights in 'CA' warehouses?
CREATE TABLE Warehouses (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255)); CREATE TABLE Freights (id INT PRIMARY KEY,warehouse_id INT,status VARCHAR(255),quantity INT,pickup_date DATETIME); CREATE VIEW PendingFreights AS SELECT * FROM Freights WHERE status = 'pending';
SELECT MIN(pickup_date) as earliest_pickup_date FROM PendingFreights p INNER JOIN Warehouses w ON p.warehouse_id = w.id WHERE w.location = 'CA';
What is the total number of trips made by electric buses in Bangkok over the past year?
CREATE TABLE public.yearly_trips_by_vehicle (id SERIAL PRIMARY KEY,vehicle_type TEXT,city TEXT,year_start DATE,year_trips INTEGER); INSERT INTO public.yearly_trips_by_vehicle (vehicle_type,city,year_start,year_trips) VALUES ('electric_bus','Bangkok','2021-01-01',1200000),('electric_bus','Bangkok','2021-07-01',1500000);
SELECT SUM(year_trips) FROM public.yearly_trips_by_vehicle WHERE vehicle_type = 'electric_bus' AND city = 'Bangkok' AND year_start BETWEEN DATE_TRUNC('year', CURRENT_DATE - INTERVAL '1 year') AND CURRENT_DATE;
What is the minimum salary of workers in the 'Design' department for each factory?
CREATE TABLE factories (factory_id INT,department VARCHAR(255)); INSERT INTO factories VALUES (1,'Assembly'),(1,'Quality Control'),(2,'Design'),(2,'Testing'); CREATE TABLE workers (worker_id INT,factory_id INT,department VARCHAR(255),role VARCHAR(255),salary INT); INSERT INTO workers VALUES (1,1,'Assembly','Engineer',5...
SELECT f.factory_id, MIN(w.salary) as min_salary FROM factories f JOIN workers w ON f.factory_id = w.factory_id WHERE f.department = 'Design' GROUP BY f.factory_id;
What are the total sales and average sales per game for each genre?
CREATE TABLE game_sales (game_id INT,genre VARCHAR(255),sales FLOAT); INSERT INTO game_sales (game_id,genre,sales) VALUES (1,'RPG',5000000),(2,'FPS',7000000),(3,'Simulation',4000000);
SELECT genre, SUM(sales) as total_sales, AVG(sales) as avg_sales_per_game FROM game_sales GROUP BY genre;
What are the galleries with the most modern art exhibitions?
CREATE TABLE Exhibitions (ExhibitionID INT,Gallery VARCHAR(100),ArtworkID INT,Country VARCHAR(50),Year INT);
SELECT Exhibitions.Gallery, COUNT(DISTINCT Exhibitions.ExhibitionID) AS ExhibitionCount FROM Exhibitions INNER JOIN Artworks ON Exhibitions.ArtworkID = Artworks.ArtworkID WHERE Artworks.Year >= 1900 GROUP BY Exhibitions.Gallery;
What is the maximum cargo weight for vessels arriving in Singapore in April 2022?
CREATE TABLE vessel_performance (id INT,name TEXT,speed DECIMAL(5,2),arrived_date DATE,country TEXT,cargo_weight INT); INSERT INTO vessel_performance (id,name,speed,arrived_date,country,cargo_weight) VALUES (1,'Vessel J',15.5,'2022-04-04','Singapore',8000),(2,'Vessel K',17.2,'2022-04-17','Singapore',8500),(3,'Vessel L'...
SELECT MAX(cargo_weight) FROM vessel_performance WHERE YEAR(arrived_date) = 2022 AND MONTH(arrived_date) = 4 AND country = 'Singapore';
List the number of community development projects in 'rural_development' database, grouped by region and project type.
CREATE TABLE projects (id INT,region TEXT,project_type TEXT,start_date DATE,end_date DATE);
SELECT region, project_type, COUNT(*) FROM projects GROUP BY region, project_type;
What is the total claim amount for each policyholder?
CREATE TABLE claims (id INT,policyholder_id INT,claim_amount DECIMAL(10,2)); INSERT INTO claims (id,policyholder_id,claim_amount) VALUES (1,1,1500.00),(2,2,3000.00),(3,3,500.00),(4,4,4500.00),(5,1,2000.00);
SELECT policyholder_id, SUM(claim_amount) as total_claim_amount FROM claims GROUP BY policyholder_id;
List all disaster types and their respective average preparedness scores, for the last 2 years, from 'DisasterPreparedness' table.
CREATE TABLE DisasterPreparedness (id INT,year INT,disasterType VARCHAR(30),score INT);
SELECT disasterType, AVG(score) FROM DisasterPreparedness WHERE year BETWEEN (YEAR(CURRENT_DATE) - 2) AND YEAR(CURRENT_DATE) GROUP BY disasterType;
How many hospital beds are there in Asia?
CREATE TABLE Continent (name VARCHAR(50),hospital_beds INT); INSERT INTO Continent (name,hospital_beds) VALUES ('China',3000000),('India',1600000);
SELECT SUM(hospital_beds) FROM Continent WHERE name IN ('China', 'India');
What is the average maintenance cost for military equipment in the Pacific region?
CREATE TABLE MilitaryEquipment (Id INT,EquipmentName VARCHAR(50),MaintenanceCost DECIMAL(10,2),Region VARCHAR(50)); INSERT INTO MilitaryEquipment (Id,EquipmentName,MaintenanceCost,Region) VALUES (1,'Tank',5000,'Pacific'),(2,'Helicopter',8000,'Europe');
SELECT AVG(MaintenanceCost) FROM MilitaryEquipment WHERE Region = 'Pacific';
Delete records of citizens who are over 65 in the 'Citizens' table
CREATE TABLE Citizens (citizen_id INT,name VARCHAR(50),age INT,city VARCHAR(50));
DELETE FROM Citizens WHERE age > 65;
Which broadband services have a higher number of subscribers compared to mobile services in the same region?
CREATE TABLE broadband_services (service_id INT,subscribers INT,region VARCHAR(20)); CREATE TABLE mobile_services (service_id INT,subscribers INT,region VARCHAR(20));
SELECT b.region, b.service_id, b.subscribers FROM broadband_services b LEFT JOIN mobile_services m ON b.region = m.region WHERE b.subscribers > COALESCE(m.subscribers, 0);
Add a new record to the 'rural_hospitals' table
CREATE TABLE rural_hospitals (id INT,name VARCHAR(50),beds INT,location VARCHAR(50));
INSERT INTO rural_hospitals (id, name, beds, location) VALUES (1, 'Eureka Community Hospital', 50, 'Eureka');
Find the average sustainability score for Oceania.
CREATE TABLE tourism_stats (id INT,country VARCHAR(50),continent VARCHAR(50),visitors INT,sustainability_score INT); INSERT INTO tourism_stats (id,country,continent,visitors,sustainability_score) VALUES (1,'Australia','Oceania',20000000,85); INSERT INTO tourism_stats (id,country,continent,visitors,sustainability_score)...
SELECT AVG(sustainability_score) FROM tourism_stats WHERE continent = 'Oceania';
What is the average length of news articles published in each quarter of 2021?
CREATE TABLE articles (id INT,title VARCHAR(100),publication_date DATE,word_count INT);
SELECT EXTRACT(QUARTER FROM publication_date) AS quarter, AVG(word_count) AS avg_word_count FROM articles WHERE EXTRACT(YEAR FROM publication_date) = 2021 GROUP BY quarter;
What is the total donation amount for each donor in Nigeria?
CREATE TABLE Donors (id INT,name VARCHAR(50),donation_date DATE,amount INT,country VARCHAR(50)); INSERT INTO Donors (id,name,donation_date,amount,country) VALUES (1,'Alice','2021-01-01',500,'USA'),(2,'Bob','2021-02-01',1000,'Nigeria');
SELECT name, SUM(amount) as total_donation FROM Donors WHERE country = 'Nigeria' GROUP BY name;
What is the maximum calorie burn during 'Strength' workouts for members with 'Premium' membership types?
CREATE TABLE Workouts (MemberID INT,MembershipType VARCHAR(20),WorkoutType VARCHAR(20),CaloriesBurned INT); INSERT INTO Workouts (MemberID,MembershipType,WorkoutType,CaloriesBurned) VALUES (1,'Premium','Cardio',300),(2,'Basic','Strength',250),(3,'Premium','Strength',350);
SELECT MAX(CaloriesBurned) FROM Workouts WHERE MembershipType = 'Premium' AND WorkoutType = 'Strength';
What is the total number of users registered for events with a start time after 2022-06-01?
CREATE TABLE Events (EventID INT,StartTime DATETIME); INSERT INTO Events (EventID,StartTime) VALUES (1,'2022-06-02 15:00:00'),(2,'2022-05-31 18:00:00'); CREATE TABLE Users (UserID INT,EventID INT); INSERT INTO Users (UserID,EventID) VALUES (1,1),(2,2);
SELECT COUNT(DISTINCT Users.UserID) AS TotalUsersRegistered FROM Users INNER JOIN Events ON Users.EventID = Events.EventID WHERE Events.StartTime > '2022-06-01';
What's the total revenue of movies and TV shows in a specific country?
CREATE TABLE movie_revenue (id INT,title VARCHAR(50),country VARCHAR(50),revenue DECIMAL(10,2)); CREATE TABLE tv_revenue (id INT,show VARCHAR(50),country VARCHAR(50),revenue DECIMAL(10,2));
SELECT SUM(movie_revenue.revenue + tv_revenue.revenue) FROM movie_revenue INNER JOIN tv_revenue ON movie_revenue.country = tv_revenue.country WHERE movie_revenue.country = 'CountryName';
What is the three-year rolling average of agricultural innovation investments in India?
CREATE TABLE agricultural_investments (country TEXT,year INT,innovation_investment NUMERIC); INSERT INTO agricultural_investments (country,year,innovation_investment) VALUES ('India',2017,1000000),('India',2018,1200000),('India',2019,1500000),('India',2020,1800000),('India',2021,2200000);
SELECT year, AVG(innovation_investment) OVER (ORDER BY year ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS rolling_average FROM agricultural_investments WHERE country = 'India';
What was the total amount donated by each donor in 2021, sorted by the highest amount?
CREATE TABLE Donors (DonorID INT,Name TEXT,TotalDonation FLOAT); INSERT INTO Donors (DonorID,Name,TotalDonation) VALUES (1,'John Doe',5000.00),(2,'Jane Smith',3500.00);
SELECT Name, SUM(TotalDonation) as TotalDonated FROM Donors WHERE YEAR(DonationDate) = 2021 GROUP BY Name ORDER BY TotalDonated DESC;
List the number of unique industries for companies with more than 50 employees founded between 2015 and 2018.
CREATE TABLE companies (id INT,name TEXT,industry TEXT,employees INT,founding_date DATE);
SELECT COUNT(DISTINCT industry) FROM companies WHERE employees > 50 AND founding_date BETWEEN '2015-01-01' AND '2018-12-31';
What is the maximum number of vessels registered in any country?
CREATE TABLE max_vessels_by_country (country TEXT,max_vessels INT); INSERT INTO max_vessels_by_country (country,max_vessels) VALUES ('Canada',50000),('USA',100000),('Mexico',30000);
SELECT MAX(max_vessels) FROM max_vessels_by_country;
What is the minimum risk score for the energy sector in each region?
CREATE TABLE threat_intelligence (id INT,sector VARCHAR(20),region VARCHAR(20),risk_score INT);
SELECT region, MIN(risk_score) FROM threat_intelligence WHERE sector = 'energy' GROUP BY region;
What is the ranking of customer preferences for each cosmetic product?
CREATE TABLE customer_preferences (customer_id INT,product_id INT,preference_score INT); INSERT INTO customer_preferences (customer_id,product_id,preference_score) VALUES (1,1,90),(1,2,70),(2,1,80),(2,2,85),(3,1,50),(3,2,95),(4,1,90),(4,2,80),(5,1,60),(5,2,90);
SELECT customer_id, product_id, preference_score, RANK() OVER (PARTITION BY product_id ORDER BY preference_score DESC) as preference_rank FROM customer_preferences;
Reduce the Terbium production in India by 10% for 2021 and later.
CREATE TABLE production (year INT,element VARCHAR(10),country VARCHAR(10),quantity INT); INSERT INTO production (year,element,country,quantity) VALUES (2017,'Terbium','India',1200),(2018,'Terbium','India',1400),(2019,'Terbium','India',1600),(2020,'Terbium','India',1800),(2021,'Terbium','India',2000);
UPDATE production SET quantity = quantity * 0.9 WHERE element = 'Terbium' AND country = 'India' AND year >= 2021;
Total number of viewers by age group, for a specific movie?
CREATE TABLE Viewers (id INT,movie_title VARCHAR(100),age_group INT,viewers INT);
SELECT age_group, SUM(viewers) FROM Viewers WHERE movie_title = 'The Matrix Resurrections' GROUP BY age_group;
What is the total funding for maritime law compliance initiatives in the Arctic region?
CREATE TABLE maritime_law_compliance_initiatives (id INT,initiative TEXT,region TEXT,funding FLOAT); INSERT INTO maritime_law_compliance_initiatives (id,initiative,region,funding) VALUES (1,'Initiative X','Arctic',400000),(2,'Initiative Y','Atlantic',300000),(3,'Initiative Z','Arctic',500000);
SELECT SUM(funding) FROM maritime_law_compliance_initiatives WHERE region = 'Arctic';
What is the average salary for male and female employees?
CREATE TABLE EmployeeData (EmployeeID INT,Gender VARCHAR(10),Salary DECIMAL(10,2)); INSERT INTO EmployeeData (EmployeeID,Gender,Salary) VALUES (1,'Male',75000.00),(2,'Female',65000.00),(3,'Non-binary',62000.00);
SELECT Gender, AVG(Salary) FROM EmployeeData WHERE Gender IN ('Male', 'Female') GROUP BY Gender;
How many unique chemical compounds were used in the production of each product in the past month?
CREATE TABLE products (product_id INT,name TEXT); CREATE TABLE product_compounds (compound_id INT,product_id INT); CREATE TABLE chemical_compounds (compound_id INT,name TEXT);
SELECT products.name, COUNT(DISTINCT chemical_compounds.compound_id) FROM products INNER JOIN product_compounds ON products.product_id = product_compounds.product_id INNER JOIN chemical_compounds ON product_compounds.compound_id = chemical_compounds.compound_id WHERE products.production_date > DATEADD(month, -1, GETDAT...
What is the total R&D expenditure for companies that have launched a drug after 2015?
CREATE TABLE company_drugs (id INT PRIMARY KEY,company VARCHAR(50),drug_name VARCHAR(50),launch_date DATE); CREATE TABLE rd_expenditures (id INT PRIMARY KEY,company VARCHAR(50),year INT,amount DECIMAL(10,2));
SELECT SUM(re.amount) FROM rd_expenditures re JOIN company_drugs cd ON re.company = cd.company WHERE cd.launch_date > '2015-01-01';
Rank the top 5 countries by the number of sustainable tourism awards received in the last 3 years.
CREATE TABLE awards (year INT,country TEXT,num_awards INT); INSERT INTO awards (year,country,num_awards) VALUES ('2019','Italy',3),('2020','Italy',2),('2021','Italy',5),('2019','Spain',2),('2020','Spain',4),('2021','Spain',1),('2019','Greece',1),('2020','Greece',3),('2021','Greece',4),('2019','Portugal',5),('2020','Por...
SELECT country, RANK() OVER (ORDER BY SUM(num_awards) DESC) as rank FROM awards WHERE year >= (SELECT MAX(year) - 3) GROUP BY country HAVING COUNT(*) = 3;
List athletes who have participated in both baseball and football during their career?
CREATE TABLE athletes (athlete_id INT,athlete_name VARCHAR(50),sport VARCHAR(10));INSERT INTO athletes (athlete_id,athlete_name,sport) VALUES (1,'John Doe','Baseball'),(2,'Jane Doe','Football'),(3,'Janet Doe','Baseball'),(4,'Jack Doe','Football');
SELECT a.athlete_name FROM athletes a WHERE a.sport = 'Baseball' INTERSECT SELECT a.athlete_name FROM athletes a WHERE a.sport = 'Football';
Delete the record of the least attended jazz concert.
CREATE TABLE Concerts (city VARCHAR(255),genre VARCHAR(255),attendance INT); INSERT INTO Concerts (city,genre,attendance) VALUES ('New York','Jazz',300),('Los Angeles','Jazz',200),('Chicago','Jazz',250);
DELETE FROM Concerts WHERE city = 'Los Angeles' AND genre = 'Jazz' AND attendance = (SELECT MIN(attendance) FROM Concerts WHERE genre = 'Jazz');
What is the total revenue from concert ticket sales for Latin artists in the United States?
CREATE TABLE Concerts (ConcertID INT,ConcertName VARCHAR(100),ConcertType VARCHAR(50),VenueID INT,TicketPrice DECIMAL(5,2),ArtistID INT,ArtistNationality VARCHAR(50)); CREATE TABLE Tickets (TicketID INT,ConcertID INT,TicketSold BOOLEAN,PurchaseDate TIMESTAMP); INSERT INTO Concerts VALUES (1,'Salsa Night','Concert',1,75...
SELECT SUM(Concerts.TicketPrice) AS TotalRevenue FROM Concerts JOIN Tickets ON Concerts.ConcertID = Tickets.ConcertID WHERE Concerts.ArtistNationality = 'Latin' AND Tickets.PurchaseDate BETWEEN (CURRENT_DATE - INTERVAL '1 year') AND CURRENT_DATE AND Concerts.ConcertType = 'Concert';
Create a new table named "sustainable_materials" with columns "material_name" (text), "manufacturing_emissions" (integer), and "recycling_potential" (real)
CREATE TABLE sustainable_materials (material_name text,manufacturing_emissions integer,recycling_potential real);
CREATE TABLE sustainable_materials (material_name text, manufacturing_emissions integer, recycling_potential real);
What is the total recycling rate in the state of California?
CREATE TABLE recycling_rates (state VARCHAR(2),recycling_rate DECIMAL(4,2)); INSERT INTO recycling_rates (state,recycling_rate) VALUES ('US',35.01),('CA',50.03),('NY',25.10);
SELECT SUM(recycling_rate) FROM recycling_rates WHERE state = 'CA';
List all vessel IDs and their corresponding average speeds from the "vessel_summary" view.
CREATE VIEW vessel_summary AS SELECT vessel_id,AVG(avg_speed) AS average_speed,SUM(fuel_efficiency) AS total_fuel_efficiency,COUNT(*) FILTER (WHERE result = 'PASS') AS successful_inspections FROM vessel_performance JOIN safety_records ON vessel_performance.vessel_id = safety_records.vessel_id GROUP BY vessel_id;
SELECT vessel_id, average_speed FROM vessel_summary;
Who are the top 5 students with the highest GRE scores in the Electrical Engineering department?
CREATE TABLE students (id INT,name VARCHAR(50),department VARCHAR(50),gre_score INT); INSERT INTO students (id,name,department,gre_score) VALUES (1,'John Doe','Electrical Engineering',165),(2,'Jane Smith','Electrical Engineering',160),(3,'Bob Johnson','Electrical Engineering',170),(4,'Alice Smith','Electrical Engineeri...
SELECT * FROM students WHERE department = 'Electrical Engineering' ORDER BY gre_score DESC LIMIT 5;
Insert a new sale for the state of Michigan in Q1 2022 with a revenue of 15000 and a strain of "Blue Dream"
CREATE TABLE sales (id INT,state VARCHAR(50),quarter VARCHAR(10),strain VARCHAR(50),revenue INT);
INSERT INTO sales (state, quarter, strain, revenue) VALUES ('Michigan', 'Q1', 'Blue Dream', 15000);
Which are the top 3 countries with the highest energy efficiency ratings in the 'GreenEnergy' schema?
CREATE SCHEMA GreenEnergy; CREATE TABLE Countries (country_id INT,country_name VARCHAR(100),energy_efficiency_rating INT); INSERT INTO Countries (country_id,country_name,energy_efficiency_rating) VALUES (1,'Switzerland',90),(2,'Sweden',85),(3,'Norway',80),(4,'Finland',75),(5,'Denmark',70),(6,'Austria',65);
SELECT country_name, energy_efficiency_rating FROM GreenEnergy.Countries ORDER BY energy_efficiency_rating DESC LIMIT 3;
Find the number of unique users who have streamed songs from artists who identify as LGBTQ+ in the 'music_streaming' table.
CREATE TABLE music_streaming (stream_id INT,user_id INT,song_id INT,streams INT,date DATE,artist_id INT,artist_lgbtq BOOLEAN);
SELECT COUNT(DISTINCT user_id) FROM music_streaming WHERE artist_lgbtq = true;
List the vessels and their last cargo handling operation by type in the 'fleet_management' schema.
CREATE TABLE fleet_management.vessels (id INT,name VARCHAR(50),year_built INT,type VARCHAR(50)); CREATE TABLE fleet_management.cargo_handling (id INT,port_id INT,volume INT,handling_date DATE,vessel_id INT);
SELECT v.name, v.type, ch.handling_date FROM fleet_management.vessels v INNER JOIN (SELECT vessel_id, MAX(handling_date) AS max_handling_date FROM fleet_management.cargo_handling GROUP BY vessel_id) sub ON v.id = sub.vessel_id INNER JOIN fleet_management.cargo_handling ch ON v.id = ch.vessel_id AND sub.max_handling_dat...
What are the top 3 selling menu categories for the last month?
CREATE TABLE sales (menu_item VARCHAR(255),category VARCHAR(255),sales_quantity INT); INSERT INTO sales (menu_item,category,sales_quantity) VALUES ('Burger','Main Dishes',1200); INSERT INTO sales (menu_item,category,sales_quantity) VALUES ('Caesar Salad','Salads',450);
SELECT category, SUM(sales_quantity) as total_sold FROM sales WHERE sale_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY category ORDER BY total_sold DESC LIMIT 3;
What is the maximum and minimum number of community-supported agriculture (CSA) farms per state in the US?
CREATE TABLE CSADistribution (state VARCHAR(50),num_csa INT); INSERT INTO CSADistribution (state,num_csa) VALUES ('California',100),('Texas',50),('New York',75),('Wisconsin',25),('Massachusetts',50);
SELECT state, MAX(num_csa), MIN(num_csa) FROM CSADistribution GROUP BY state;
List the countries with the highest oil production in 2021
CREATE TABLE countries (id INT PRIMARY KEY,name TEXT,region TEXT); INSERT INTO countries (id,name,region) VALUES (1,'USA','North America'),(2,'Canada','North America'),(3,'Mexico','North America'),(4,'Brazil','South America'),(5,'Argentina','South America'); CREATE TABLE oil_production (country_id INT,year INT,producti...
SELECT c.name, op.production as total_production FROM countries c JOIN oil_production op ON c.id = op.country_id WHERE op.year = 2021 GROUP BY c.name ORDER BY total_production DESC LIMIT 5;
What is the total mass of space debris launched by each country?
CREATE TABLE space_debris (country TEXT,category TEXT,mass FLOAT); INSERT INTO space_debris (country,category,mass) VALUES ('USA','Aluminum',120.5),('USA','Titanium',170.1),('Russia','Aluminum',150.2),('Russia','Titanium',180.1),('China','Copper',100.1),('China','Steel',250.7);
SELECT country, SUM(mass) FROM space_debris GROUP BY country;
What is the total number of military aircraft by type, ordered by the most recent year?
CREATE TABLE Military_Aircraft (ID INT,Type VARCHAR(50),Year INT,Quantity INT); INSERT INTO Military_Aircraft (ID,Type,Year,Quantity) VALUES (1,'F-16',2015,50),(2,'F-35',2018,80),(3,'A-10',2017,30);
SELECT Type, MAX(Year), SUM(Quantity) FROM Military_Aircraft GROUP BY Type ORDER BY MAX(Year) DESC;
What is the average number of military bases in Middle Eastern countries?
CREATE TABLE military_bases (country VARCHAR(50),num_bases INT); INSERT INTO military_bases (country,num_bases) VALUES ('Iran',22),('Saudi Arabia',25),('Turkey',20),('Israel',18),('Egypt',12),('Iraq',15);
SELECT AVG(num_bases) FROM military_bases WHERE country IN ('Iran', 'Saudi Arabia', 'Turkey', 'Israel', 'Egypt', 'Iraq') AND country LIKE 'Middle%';
How many research grants were awarded to faculty members in the School of Engineering in 2020?
CREATE TABLE research_grants (id INT,year INT,faculty_name VARCHAR(50),faculty_department VARCHAR(50)); INSERT INTO research_grants (id,year,faculty_name,faculty_department) VALUES (1,2019,'John Smith','Mechanical Engineering'),(2,2020,'Jane Doe','Electrical Engineering'),(3,2018,'Bob Johnson','Civil Engineering');
SELECT COUNT(*) FROM research_grants WHERE faculty_department LIKE '%Engineering%' AND year = 2020;
What is the average yield per hectare of corn in the 'rural_dev' region?
CREATE TABLE rural_dev (region VARCHAR(20),crop VARCHAR(20),yield INT); INSERT INTO rural_dev (region,crop,yield) VALUES ('rural_dev','corn',70);
SELECT AVG(yield) FROM rural_dev WHERE crop = 'corn';
What is the difference in total goals scored between the home and away games for each team in the 2020-2021 UEFA Champions League?
CREATE TABLE ucl_season (team_id INT,team_name VARCHAR(50),games_played INT,goals_home INT,goals_away INT); INSERT INTO ucl_season (team_id,team_name,games_played,goals_home,goals_away) VALUES (1,'Bayern Munich',11,43,10);
SELECT team_name, (goals_home - goals_away) as diff FROM ucl_season;
List all unique cultural competency training programs offered by providers in California.
CREATE TABLE cultural_competency_training (id INT,provider_id INT,program_name VARCHAR(100),program_date DATE); INSERT INTO cultural_competency_training (id,provider_id,program_name,program_date) VALUES (1,456,'Cultural Sensitivity 101','2021-02-01'),(2,456,'Working with Diverse Communities','2021-03-15'); CREATE TABLE...
SELECT DISTINCT program_name FROM cultural_competency_training INNER JOIN healthcare_providers ON cultural_competency_training.provider_id = healthcare_providers.id WHERE healthcare_providers.region = 'California';
Calculate the total renewable energy investments made by public and private sectors in each country in 2020 from the 'renewable_investments' table.
CREATE TABLE renewable_investments (country VARCHAR(255),investment_amount DECIMAL(10,2),investment_type VARCHAR(255),year INT); INSERT INTO renewable_investments (country,investment_amount,investment_type,year) VALUES ('China',85000.0,'public',2020),('China',60000.0,'private',2020),('USA',50000.0,'private',2020),('Ger...
SELECT country, SUM(investment_amount) as total_investments FROM renewable_investments WHERE year = 2020 GROUP BY country;
Which decentralized applications were created by developers from underrepresented communities?
CREATE TABLE developers (developer_id INT,name VARCHAR(255),community VARCHAR(255)); CREATE TABLE decentralized_applications (app_id INT,name VARCHAR(255),developer_id INT); INSERT INTO developers (developer_id,name,community) VALUES (1,'Alice','Women in Tech'),(2,'Bob','LGBTQ+'),(3,'Charlie','Minority Ethnicity'),(4,'...
SELECT da.name FROM decentralized_applications da JOIN developers d ON da.developer_id = d.developer_id WHERE d.community IS NOT NULL;
Calculate the average weight of marine mammals in the Atlantic Ocean.
CREATE TABLE Species (id INT PRIMARY KEY,name VARCHAR(50),type VARCHAR(50)); INSERT INTO Species (id,name,type) VALUES (1,'Tuna','Fish'); INSERT INTO Species (id,name,type) VALUES (2,'Krill','Crustacean'); INSERT INTO Species (id,name,type) VALUES (3,'Dolphin','Mammal'); CREATE TABLE Observations (id INT PRIMARY KEY,...
SELECT AVG(O.weight) FROM Observations O JOIN Species S ON O.species_id = S.id WHERE S.type = 'Mammal' AND O.location = 'Atlantic Ocean';
Calculate the average grant amount awarded to all departments
CREATE TABLE grants (id INT,department VARCHAR(20),amount FLOAT); INSERT INTO grants (id,department,amount) VALUES (1,'Arts and Humanities',50000.0),(2,'Sciences',75000.0);
SELECT AVG(amount) FROM grants;
What is the total production volume (in tons) for each species in ProductionZone1?
CREATE TABLE ProductionZone1 (species VARCHAR(20),production_volume FLOAT); INSERT INTO ProductionZone1 (species,production_volume) VALUES ('Salmon',120),('Trout',150),('Tuna',180);
SELECT species, SUM(production_volume) FROM ProductionZone1 GROUP BY species;
What is the total number of cybersecurity incidents reported worldwide each month for the past 12 months and their respective impact levels?
CREATE TABLE CybersecurityImpact (id INT,impact_level TEXT); INSERT INTO CybersecurityImpact (id,impact_level) VALUES (1,'High'),(2,'Medium'),(3,'Low'); CREATE TABLE CybersecurityIncidentsByMonth (id INT,month INT,impact_id INT); INSERT INTO CybersecurityIncidentsByMonth (id,month,impact_id) VALUES (1,12,1),(2,11,2);
SELECT MONTH(CybersecurityIncidentsByMonth.month) as month, COUNT(CybersecurityIncidentsByMonth.id) as total_incidents, AVG(CybersecurityImpact.impact_level) as avg_impact FROM CybersecurityIncidentsByMonth INNER JOIN CybersecurityImpact ON CybersecurityIncidentsByMonth.impact_id = CybersecurityImpact.id GROUP BY MONTH...
List the unique sports that have ticket sales data.
CREATE TABLE sports (sport_id INT,sport_name VARCHAR(20)); INSERT INTO sports (sport_id,sport_name) VALUES (1,'Basketball'),(2,'Soccer'),(3,'Rugby'); CREATE TABLE sales (sale_id INT,sport_id INT,revenue DECIMAL(5,2)); INSERT INTO sales (sale_id,sport_id,revenue) VALUES (1,1,500.00),(2,1,750.00),(3,2,800.00),(4,2,1000.0...
SELECT DISTINCT sports.sport_name FROM sports JOIN sales ON sports.sport_id = sales.sport_id;
What is the average speed of vessels in the 'vessel_performance' table, grouped by month?
CREATE TABLE vessel_performance (vessel_id INT,speed FLOAT,timestamp TIMESTAMP);
SELECT DATE_FORMAT(timestamp, '%Y-%m') AS month, AVG(speed) FROM vessel_performance GROUP BY month;