instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
How many artworks were created by female artists in the 20th century?
|
CREATE TABLE artists (id INT,name TEXT,birth_year INT,death_year INT); INSERT INTO artists (id,name,birth_year,death_year) VALUES (1,'Artist 1',1900,1980); CREATE TABLE artworks (id INT,title TEXT,year_created INT,artist_id INT); INSERT INTO artworks (id,title,year_created,artist_id) VALUES (1,'Artwork 1',1920,1);
|
SELECT COUNT(*) FROM artworks a INNER JOIN artists ar ON a.artist_id = ar.id WHERE ar.death_year IS NULL AND ar.birth_year <= 1900 AND ar.birth_year >= 1900;
|
What is the maximum construction cost of highways in Texas?
|
CREATE TABLE Highways (id INT,name TEXT,location TEXT,state TEXT,cost FLOAT); INSERT INTO Highways (id,name,location,state,cost) VALUES (1,'Highway A','Location A','Texas',25000000),(2,'Highway B','Location B','New York',30000000);
|
SELECT MAX(cost) FROM Highways WHERE state = 'Texas';
|
Count the number of cases for each attorney who has more than 5 cases in the family law category.
|
CREATE TABLE attorneys (attorney_id INT,name VARCHAR(50)); CREATE TABLE cases (case_id INT,attorney_id INT,category VARCHAR(20));
|
SELECT attorney_id, COUNT(*) FROM cases WHERE category = 'family' GROUP BY attorney_id HAVING COUNT(*) > 5;
|
How many world heritage sites are in South America?
|
CREATE TABLE world_heritage_sites (name VARCHAR(255),location VARCHAR(255),year INT); INSERT INTO world_heritage_sites (name,location,year) VALUES ('Machu Picchu','Peru',1983),('Galápagos Islands','Ecuador',1978);
|
SELECT COUNT(*) FROM world_heritage_sites WHERE location LIKE '%South America%';
|
What is the average environmental impact score of mining operations in the Asian region?
|
CREATE TABLE MiningOperations (OperationID INT,OperationName VARCHAR(50),Country VARCHAR(50),ProductionRate FLOAT,EnvironmentalImpactScore INT); INSERT INTO MiningOperations (OperationID,OperationName,Country,ProductionRate,EnvironmentalImpactScore) VALUES (4,'Operation C','China',6000,50); INSERT INTO MiningOperations (OperationID,OperationName,Country,ProductionRate,EnvironmentalImpactScore) VALUES (5,'Operation D','Japan',8000,30);
|
SELECT AVG(EnvironmentalImpactScore) FROM MiningOperations WHERE Country IN (SELECT Country FROM Countries WHERE Region = 'Asia');
|
What is the maximum time to resolution for security incidents in the finance department, and which incident took the longest to resolve?
|
CREATE TABLE incidents (incident_id INT,incident_date DATE,resolution_date DATE,department VARCHAR(50));
|
SELECT department, MAX(DATEDIFF(resolution_date, incident_date)) as max_resolution_time FROM incidents WHERE department = 'finance' GROUP BY department; SELECT incident_id, DATEDIFF(resolution_date, incident_date) as resolution_time FROM incidents WHERE department = 'finance' ORDER BY resolution_time DESC LIMIT 1;
|
What is the minimum fairness score for creative AI applications in the 'creative_ai' table?
|
CREATE TABLE creative_ai (app_id INT,app_name TEXT,fairness_score FLOAT);
|
SELECT MIN(fairness_score) FROM creative_ai;
|
Which marine species have been observed in both the Atlantic and Pacific Oceans?
|
CREATE TABLE marine_species (id INT,name VARCHAR(50),region VARCHAR(50)); INSERT INTO marine_species (id,name,region) VALUES (1,'Tuna','Atlantic Ocean'),(2,'Tuna','Pacific Ocean');
|
SELECT marine_species.name FROM marine_species WHERE marine_species.region IN ('Atlantic Ocean', 'Pacific Ocean') GROUP BY marine_species.name HAVING COUNT(DISTINCT marine_species.region) > 1;
|
What is the average waste generation in the state of California?
|
CREATE TABLE waste_generation (state VARCHAR(2),generation INT); INSERT INTO waste_generation (state,generation) VALUES ('CA',5000000),('NY',4000000),('NJ',3000000);
|
SELECT AVG(generation) FROM waste_generation WHERE state = 'CA';
|
Update the 'name' field to 'Tiger' in the 'animal_population' table for all records where the 'species' is 'Panthera tigris'
|
CREATE TABLE animal_population (id INT PRIMARY KEY,species VARCHAR(30),name VARCHAR(20),population INT);
|
UPDATE animal_population SET name = 'Tiger' WHERE species = 'Panthera tigris';
|
How many museums are there in New York with more than 5 employees?
|
CREATE TABLE MuseumData (id INT,city VARCHAR(50),num_employees INT); INSERT INTO MuseumData (id,city,num_employees) VALUES (1,'New York',10),(2,'New York',3),(3,'Los Angeles',7),(4,'Los Angeles',8),(5,'Chicago',6);
|
SELECT COUNT(*) FROM MuseumData WHERE city = 'New York' AND num_employees > 5;
|
What is the total rainfall in the last week for region 'US-MN'?
|
CREATE TABLE region (id INT,name VARCHAR(255),rainfall FLOAT); INSERT INTO region (id,name,rainfall) VALUES (1,'US-MN',12.5),(2,'US-ND',11.8),(3,'CA-BC',18.3);
|
SELECT SUM(rainfall) FROM region WHERE name = 'US-MN' AND rainfall_timestamp >= DATEADD(week, -1, CURRENT_TIMESTAMP);
|
What is the total cargo weight handled by the company Orion Lines at the Port of Hong Kong?
|
CREATE TABLE ports (id INT,name VARCHAR(50),country VARCHAR(50)); CREATE TABLE cargo_operations (id INT,port_id INT,company VARCHAR(50),type VARCHAR(50),weight INT); INSERT INTO ports (id,name,country) VALUES (1,'Port of Oakland','USA'),(2,'Port of Singapore','Singapore'),(3,'Port of Hong Kong','China'); INSERT INTO cargo_operations (id,port_id,company,type,weight) VALUES (1,1,'Orion Lines','import',5000),(2,1,'Orion Lines','export',7000),(3,3,'Orion Lines','import',8000),(4,3,'Orion Lines','export',9000);
|
SELECT SUM(weight) FROM cargo_operations WHERE company = 'Orion Lines' AND port_id = (SELECT id FROM ports WHERE name = 'Port of Hong Kong');
|
Calculate the total amount donated by top 3 donors in Q1 2022.
|
CREATE TABLE Donations (DonationID int,DonationDate date,Amount decimal(10,2)); INSERT INTO Donations (DonationID,DonationDate,Amount) VALUES (1,'2022-01-01',500.00),(2,'2022-01-02',200.00);
|
SELECT SUM(Amount) as TotalDonation FROM (SELECT DonorID, SUM(Amount) as Amount FROM Donations WHERE DonationDate BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY DonorID ORDER BY Amount DESC LIMIT 3) as TopDonors;
|
Generate a table 'veteran_skills' to store veteran skills and experience
|
CREATE TABLE veteran_skills (id INT PRIMARY KEY,veteran_id INT,skill VARCHAR(50),years_of_experience INT);
|
CREATE TABLE veteran_skills (id INT PRIMARY KEY, veteran_id INT, skill VARCHAR(50), years_of_experience INT);
|
Which garment types were most frequently restocked in the past year in the North region?
|
CREATE TABLE garment (garment_id INT,garment_type VARCHAR(255),restocked_date DATE); INSERT INTO garment (garment_id,garment_type,restocked_date) VALUES (1,'T-Shirt','2021-07-15'),(2,'Jeans','2021-08-01'),(3,'Jackets','2021-10-10');
|
SELECT garment_type, COUNT(*) as restock_count FROM garment WHERE restocked_date >= DATEADD(year, -1, CURRENT_DATE) AND region = 'North' GROUP BY garment_type ORDER BY restock_count DESC;
|
Find the average air pollution for elements with symbol 'H'
|
CREATE TABLE elements_producers (element_id INT,producer_id INT,PRIMARY KEY (element_id,producer_id)); CREATE TABLE producers (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),air_pollution INT); CREATE TABLE elements (id INT PRIMARY KEY,name VARCHAR(255),symbol VARCHAR(3),weight FLOAT,element_id INT,FOREIGN KEY (element_id) REFERENCES elements_producers(element_id));
|
SELECT AVG(p.air_pollution) FROM elements AS e JOIN elements_producers AS ep ON e.id = ep.element_id JOIN producers AS p ON ep.producer_id = p.id WHERE e.symbol LIKE 'H%';
|
Which farm type has the highest average area of organic farming in 'Oceania'?
|
CREATE TABLE organic_farms (id INT,country VARCHAR(50),region VARCHAR(50),farm_type VARCHAR(50),area_ha FLOAT); INSERT INTO organic_farms (id,country,region,farm_type,area_ha) VALUES (1,'Australia','Oceania','Smallholder',1234.5); INSERT INTO organic_farms (id,country,region,farm_type,area_ha) VALUES (2,'Australia','Oceania','Cooperative',3456.7); INSERT INTO organic_farms (id,country,region,farm_type,area_ha) VALUES (3,'New Zealand','Oceania','Smallholder',890.1);
|
SELECT farm_type, AVG(area_ha) FROM organic_farms WHERE region = 'Oceania' GROUP BY farm_type ORDER BY AVG(area_ha) DESC LIMIT 1;
|
What is the maximum energy efficiency score in Texas
|
CREATE TABLE energy_efficiency_scores_3 (state VARCHAR(20),score INT); INSERT INTO energy_efficiency_scores_3 (state,score) VALUES ('Texas',90),('Texas',85),('Texas',95);
|
SELECT state, MAX(score) FROM energy_efficiency_scores_3 WHERE state = 'Texas';
|
Create a new table for storing artist demographics with columns for artist_id, name, age, and genre.
|
CREATE SCHEMA music; USE music;
|
CREATE TABLE artist_demographics (artist_id INT, name VARCHAR(255), age INT, genre VARCHAR(255));
|
What is the total defense spending by countries in North America for the year 2020?
|
CREATE TABLE defense_spending (country VARCHAR(50),continent VARCHAR(50),year INT,amount FLOAT); INSERT INTO defense_spending (country,continent,year,amount) VALUES ('United States','North America',2020,750.3),('Canada','North America',2020,23.4),('Mexico','North America',2020,6.7);
|
SELECT SUM(amount) FROM defense_spending WHERE continent = 'North America' AND year = 2020;
|
What is the average CO2 emission per vehicle type in the transportation sector?
|
CREATE TABLE Vehicles (ID INT,VehicleType VARCHAR(255),CO2Emission INT); INSERT INTO Vehicles (ID,VehicleType,CO2Emission) VALUES (1,'Car',4000),(2,'Truck',8000),(3,'Motorcycle',2000);
|
SELECT VehicleType, AVG(CO2Emission) FROM Vehicles GROUP BY VehicleType;
|
What is the total number of likes received by users in Germany and the UK?
|
CREATE TABLE likes (id INT,post_id INT,user_id INT); INSERT INTO likes (id,post_id,user_id) VALUES (1,1,1),(2,1,2),(3,2,1); CREATE TABLE posts (id INT,user_id INT); INSERT INTO posts (id,user_id) VALUES (1,1),(2,2),(3,3); CREATE TABLE users (id INT,country VARCHAR(255)); INSERT INTO users (id,country) VALUES (1,'Germany'),(2,'UK'),(3,'Canada');
|
SELECT SUM(1) FROM (SELECT * FROM likes INNER JOIN posts ON likes.post_id = posts.id INNER JOIN users ON posts.user_id = users.id WHERE users.country IN ('Germany', 'UK')) AS subquery;
|
List all the wildlife sanctuaries that do not intersect with areas used for timber production
|
CREATE TABLE wildlife_sanctuaries (id INT,name VARCHAR(50),location POINT); CREATE TABLE timber_production (id INT,location POINT);
|
SELECT w.name FROM wildlife_sanctuaries w LEFT JOIN timber_production t ON ST_Intersects(w.location, t.location) WHERE t.id IS NULL;
|
Delete co-ownership properties in cities with a population below 1,000,000.
|
CREATE TABLE CoOwnershipProperties (PropertyID INT,City VARCHAR(50),Population INT,MaintenanceCost DECIMAL(5,2)); INSERT INTO CoOwnershipProperties (PropertyID,City,Population,MaintenanceCost) VALUES (1,'New York',8500000,50.50),(2,'Los Angeles',4000000,120.00),(3,'Chicago',2700000,75.25);
|
DELETE FROM CoOwnershipProperties WHERE Population < 1000000;
|
Find the average retail price of organic cotton t-shirts sold in Germany
|
CREATE TABLE garments (id INT,garment_type VARCHAR(255),material VARCHAR(255),price DECIMAL(5,2),country VARCHAR(255));
|
SELECT AVG(price) FROM garments WHERE garment_type = 'T-Shirt' AND material = 'Organic Cotton' AND country = 'Germany';
|
Find the average runtime of TV shows released in 2019 with an IMDb rating above 8.0.
|
CREATE TABLE TV_shows (id INT,title VARCHAR(255),release_year INT,runtime INT,imdb_rating DECIMAL(2,1)); INSERT INTO TV_shows (id,title,release_year,runtime,imdb_rating) VALUES (1,'Show1',2018,60,7.2),(2,'Show2',2019,45,8.1),(3,'Show3',2020,30,6.5);
|
SELECT AVG(runtime) FROM TV_shows WHERE release_year = 2019 AND imdb_rating > 8.0;
|
What's the average age of patients diagnosed with depression in the 'clinic_a' database?
|
CREATE TABLE patient (patient_id INT,name VARCHAR(50),age INT,diagnosis VARCHAR(50)); INSERT INTO patient (patient_id,name,age,diagnosis) VALUES (1,'John Doe',30,'Depression');
|
SELECT AVG(age) FROM patient WHERE diagnosis = 'Depression' AND database_name = 'clinic_a';
|
What is the average ticket price for football and basketball games?
|
CREATE TABLE games (game_type VARCHAR(20),ticket_price DECIMAL(5,2)); INSERT INTO games (game_type,ticket_price) VALUES ('Football',80.50),('Football',90.00),('Basketball',60.00),('Basketball',65.00);
|
SELECT AVG(ticket_price) FROM games WHERE game_type IN ('Football', 'Basketball');
|
What is the total revenue generated from eco-friendly hotel bookings in Germany and France?
|
CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,country TEXT,revenue FLOAT); INSERT INTO hotels (hotel_id,hotel_name,country,revenue) VALUES (1,'Green Lodge','Germany',50000.00),(2,'Eco Retreat','France',75000.00);
|
SELECT SUM(revenue) FROM hotels WHERE country IN ('Germany', 'France') AND hotel_name LIKE '%eco%';
|
What is the total cost of all projects in 'Roads' category?
|
CREATE TABLE InfrastructureProjects (id INT,category VARCHAR(20),cost FLOAT); INSERT INTO InfrastructureProjects (id,category,cost) VALUES (1,'Roads',500000),(2,'Bridges',750000);
|
SELECT SUM(cost) FROM InfrastructureProjects WHERE category = 'Roads';
|
Which countries have 'Critical' severity vulnerabilities and the number of such vulnerabilities? Provide the output in the format: country, count_of_critical_severity_vulnerabilities.
|
CREATE TABLE country_severity (id INT,ip_address VARCHAR(255),country VARCHAR(255),severity VARCHAR(255)); INSERT INTO country_severity (id,ip_address,country,severity) VALUES (1,'172.16.0.1','Brazil','Critical'),(2,'10.0.0.1','Canada','Low'),(3,'172.16.0.2','India','Critical'),(4,'10.0.0.2','Canada','Medium'),(5,'10.0.0.3','Canada','High'),(6,'10.0.0.4','Colombia','Critical');
|
SELECT country, COUNT(*) as count_of_critical_severity_vulnerabilities FROM country_severity WHERE severity = 'Critical' GROUP BY country;
|
What is the total installed capacity (in MW) of all renewable energy projects in the 'east' region?
|
CREATE TABLE wind_farms (id INT,name TEXT,region TEXT,capacity_mw FLOAT); INSERT INTO wind_farms (id,name,region,capacity_mw) VALUES (1,'Windfarm A','west',150.5); INSERT INTO wind_farms (id,name,region,capacity_mw) VALUES (2,'Windfarm B','east',120.2); CREATE TABLE solar_power_plants (id INT,name TEXT,region TEXT,capacity_mw FLOAT); INSERT INTO solar_power_plants (id,name,region,capacity_mw) VALUES (1,'Solar Plant A','north',125.8); INSERT INTO solar_power_plants (id,name,region,capacity_mw) VALUES (2,'Solar Plant B','south',180.3);
|
SELECT SUM(capacity_mw) FROM wind_farms WHERE region = 'east' UNION ALL SELECT SUM(capacity_mw) FROM solar_power_plants WHERE region = 'east';
|
What is the maximum age of visitors who attended the 'Contemporary Art' exhibition?
|
CREATE TABLE Exhibitions (exhibition_id INT,name VARCHAR(50),start_date DATE,end_date DATE); CREATE TABLE Visitors (visitor_id INT,exhibition_id INT,age INT,gender VARCHAR(50));
|
SELECT MAX(age) FROM Visitors v JOIN Exhibitions e ON v.exhibition_id = e.exhibition_id WHERE e.name = 'Contemporary Art';
|
What is the maximum and minimum energy efficiency rating for buildings in France?
|
CREATE TABLE BuildingEfficiency (BuildingID INT,Country VARCHAR(255),Rating FLOAT);
|
SELECT MAX(Rating) as MaxRating, MIN(Rating) as MinRating FROM BuildingEfficiency WHERE Country = 'France';
|
What is the maximum price of a print created by an Indigenous artist from Canada or the USA?
|
CREATE TABLE Artworks (id INT,name TEXT,artist TEXT,year INT,price FLOAT,country TEXT,category TEXT,is_indigenous BOOLEAN); INSERT INTO Artworks (id,name,artist,year,price,country,category,is_indigenous) VALUES (1,'Print1','CanadianIndigenousArtist1',2000,1000.00,'Canada','print',true),(2,'Painting2','AmericanArtist1',2005,8000.00,'USA','painting',false),(3,'Sculpture3','GermanArtist1',2010,12000.00,'Germany','sculpture',false);
|
SELECT MAX(price) FROM Artworks WHERE (country IN ('Canada', 'USA') AND is_indigenous = true AND category = 'print');
|
What is the maximum depth ever recorded for a marine species habitat that is found in the Southern Ocean?
|
CREATE TABLE species (id INT,name VARCHAR(255),max_habitat_depth FLOAT,ocean_basin VARCHAR(255)); INSERT INTO species (id,name,max_habitat_depth,ocean_basin) VALUES (1,'Atlantic Salmon',100.0,'Atlantic'),(2,'Blue Whale',500.0,'Pacific'),(3,'Southern Ocean Orca',1000.0,'Southern');
|
SELECT MAX(max_habitat_depth) FROM species WHERE ocean_basin = 'Southern';
|
Create a table named "routes" with columns "route_id", "name", and "stations_served" that references the "stations" table.
|
CREATE TABLE routes (route_id INT,name VARCHAR(255),stations_served INT,FOREIGN KEY (stations_served) REFERENCES stations(station_id));
|
CREATE TABLE routes (route_id INT, name VARCHAR(255), stations_served INT, FOREIGN KEY (stations_served) REFERENCES stations(station_id));
|
What is the total waste produced by the 'Bakery' department in the month of 'November' 2021?
|
CREATE TABLE Waste(department VARCHAR(255),waste_quantity INT,waste_date DATE);INSERT INTO Waste(department,waste_quantity,waste_date) VALUES('Bakery',50,'2021-11-01'),('Bakery',60,'2021-11-02'),('Bakery',40,'2021-11-03');
|
SELECT SUM(waste_quantity) FROM Waste WHERE department = 'Bakery' AND waste_date BETWEEN '2021-11-01' AND '2021-11-30';
|
List the number of veteran job applications received in Q2 2021?
|
CREATE TABLE VeteranJobs (JobID INT,JobTitle VARCHAR(50),Quarter INT,Year INT,JobApplications INT); INSERT INTO VeteranJobs (JobID,JobTitle,Quarter,Year,JobApplications) VALUES (1,'Software Engineer',2,2021,25),(2,'Mechanical Engineer',2,2021,30),(3,'Data Analyst',2,2021,20),(4,'Project Manager',2,2021,35),(5,'Business Analyst',2,2021,15),(6,'System Administrator',2,2021,20);
|
SELECT SUM(JobApplications) FROM VeteranJobs WHERE Quarter = 2 AND Year = 2021;
|
Insert a new record of safety inspection with a score of 90 and inspection date of 2022-01-01 for vessel with ID 789 into the SAFETY_INSPECTIONS table
|
CREATE TABLE SAFETY_INSPECTIONS (ID INT,VESSEL_ID INT,INSPECTION_DATE DATE,SCORE INT);
|
INSERT INTO SAFETY_INSPECTIONS (ID, VESSEL_ID, INSPECTION_DATE, SCORE) VALUES (1, 789, '2022-01-01', 90);
|
What are the top 3 genres by total number of songs in the music streaming platform?
|
CREATE TABLE genres (genre_id INT,genre VARCHAR(50)); INSERT INTO genres VALUES (1,'Pop'),(2,'Rock'),(3,'Jazz'); CREATE TABLE songs (song_id INT,song VARCHAR(50),genre_id INT); INSERT INTO songs VALUES (1,'Hit Me Baby',1),(2,'Smells Like Teen Spirit',2),(3,'Take Five',3);
|
SELECT g.genre, COUNT(s.song_id) as song_count FROM genres g JOIN songs s ON g.genre_id = s.genre_id GROUP BY g.genre ORDER BY song_count DESC LIMIT 3;
|
What is the total CO2 concentration in the ocean for each year?
|
CREATE TABLE ocean_co2_concentration (year INTEGER,co2_concentration FLOAT);
|
SELECT year, SUM(co2_concentration) FROM ocean_co2_concentration GROUP BY year;
|
What is the average fare for each service in the first quarter of 2023?
|
CREATE TABLE fares (service text,date date,fare decimal); INSERT INTO fares (service,date,fare) VALUES ('subway','2023-01-01',2.50),('bus','2023-01-02',1.50),('subway','2023-02-01',2.50),('bus','2023-02-02',1.50),('subway','2023-03-01',2.50),('bus','2023-03-02',1.50);
|
SELECT service, AVG(fare) FROM fares WHERE date BETWEEN '2023-01-01' AND '2023-03-31' GROUP BY service;
|
What is the total military equipment sale value to Japan, grouped by the quarter of the sale date?
|
CREATE TABLE Military_Equipment_Sales (sale_date DATE,equipment_name VARCHAR(50),customer_country VARCHAR(50),sale_value INT); INSERT INTO Military_Equipment_Sales (sale_date,equipment_name,customer_country,sale_value) VALUES ('2020-01-01','Tank A','Japan',5000000); INSERT INTO Military_Equipment_Sales (sale_date,equipment_name,customer_country,sale_value) VALUES ('2021-04-01','Helicopter B','Japan',10000000);
|
SELECT EXTRACT(QUARTER FROM sale_date) AS quarter, SUM(sale_value) FROM Military_Equipment_Sales WHERE customer_country = 'Japan' GROUP BY quarter;
|
Show the total cost of ingredients for each menu item
|
CREATE TABLE ingredients (id INT PRIMARY KEY,name VARCHAR(255),cost DECIMAL(10,2),menu_item_id INT); INSERT INTO ingredients (id,name,cost,menu_item_id) VALUES (1,'Tomato',0.50,1),(2,'Pasta',1.00,1),(3,'Chicken',2.50,2); CREATE TABLE menu_items (id INT PRIMARY KEY,name VARCHAR(255),price DECIMAL(10,2)); INSERT INTO menu_items (id,name,price) VALUES (1,'Spaghetti',12.00),(2,'Chicken Alfredo',15.00);
|
SELECT menu_items.name, SUM(ingredients.cost) AS total_cost FROM ingredients JOIN menu_items ON ingredients.menu_item_id = menu_items.id GROUP BY menu_items.name;
|
Update the price of 'Organic Cotton Shirts' to $19.99 in stores located in 'California' and 'Colorado'
|
CREATE TABLE Stores (store_id INT,store_name VARCHAR(50),state VARCHAR(50)); INSERT INTO Stores (store_id,store_name,state) VALUES (1,'Eco-Store','California'),(2,'Green Haven','Colorado'); CREATE TABLE Inventory (product_id INT,product_name VARCHAR(50),store_id INT,price DECIMAL(5,2)); INSERT INTO Inventory (product_id,product_name,store_id,price) VALUES (1,'Organic Cotton Shirts',1,14.99),(2,'Bamboo Towels',2,29.99);
|
UPDATE Inventory SET price = 19.99 WHERE product_name = 'Organic Cotton Shirts' AND store_id IN (SELECT store_id FROM Stores WHERE state IN ('California', 'Colorado'));
|
How many unique games were played by users from 'europe' region?
|
CREATE TABLE game_sessions (game_id INT,user_id INT,region VARCHAR(10)); INSERT INTO game_sessions (game_id,user_id,region) VALUES (1,2,'europe'),(2,3,'america'),(1,4,'europe');
|
SELECT COUNT(DISTINCT game_id) FROM game_sessions WHERE region = 'europe';
|
Find the total billing amount for each attorney, ordered by the total amount in descending order.
|
CREATE TABLE Attorneys (AttorneyID INT,Name VARCHAR(50),TotalBilling FLOAT); INSERT INTO Attorneys (AttorneyID,Name,TotalBilling) VALUES (1,'Smith',5000.00),(2,'Johnson',3500.00),(3,'Williams',7000.00);
|
SELECT AttorneyID, Name, TotalBilling FROM Attorneys ORDER BY TotalBilling DESC;
|
What is the total donation amount per category, ranked by the highest total?
|
CREATE TABLE Donations (DonationID INT,DonationCategory TEXT,DonationAmount DECIMAL(10,2)); INSERT INTO Donations (DonationID,DonationCategory,DonationAmount) VALUES (1,'Education',1000.00),(2,'Health',1500.00),(3,'Environment',2000.00),(4,'Education',500.00),(5,'Health',800.00),(6,'Environment',1200.00);
|
SELECT DonationCategory, SUM(DonationAmount) AS TotalDonation, RANK() OVER (ORDER BY SUM(DonationAmount) DESC) AS Rank FROM Donations GROUP BY DonationCategory;
|
What is the average safety rating for sedans in the 'vehicle_safety' schema?
|
CREATE TABLE vehicles (id INT,type VARCHAR(50)); CREATE TABLE vehicle_safety (id INT,vehicle_id INT,safety_rating FLOAT); INSERT INTO vehicles VALUES (1,'sedan'); INSERT INTO vehicle_safety VALUES (1,1,4.5);
|
SELECT AVG(safety_rating) FROM vehicle_safety INNER JOIN vehicles ON vehicle_safety.vehicle_id = vehicles.id WHERE vehicles.type = 'sedan';
|
how many wildlife habitats are there in each country in the 'forestry' schema?
|
CREATE TABLE wildlife_habitats (id INT,country VARCHAR(255),habitat_type VARCHAR(255));
|
SELECT country, COUNT(DISTINCT habitat_type) as num_habitats FROM wildlife_habitats GROUP BY country;
|
Return the names and descriptions of all threats that have been mitigated in the energy sector.
|
CREATE TABLE threats (name VARCHAR(50),description TEXT,mitigated BOOLEAN); INSERT INTO threats (name,description,mitigated) VALUES ('Threat 1','...',TRUE),('Threat 2','...',FALSE);
|
SELECT name, description FROM threats WHERE mitigated = TRUE AND sector = 'Energy';
|
Which countries have received the most humanitarian aid in the form of water and sanitation assistance in the last 5 years?
|
CREATE TABLE water_sanitation_assistance (id INT,country VARCHAR(50),aid_type VARCHAR(50),amount FLOAT,date DATE); INSERT INTO water_sanitation_assistance (id,country,aid_type,amount,date) VALUES (1,'Syria','water',1200000,'2017-01-01');
|
SELECT country, SUM(amount) as total_water_sanitation_aid FROM water_sanitation_assistance WHERE aid_type = 'water' AND date >= DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR) GROUP BY country ORDER BY total_water_sanitation_aid DESC;
|
What is the average daily water consumption per customer in the commercial category for the year 2019 in the city of Miami?
|
CREATE TABLE water_consumption_miami (customer_id INT,category VARCHAR(20),consumption FLOAT,day INT,month INT,year INT,city VARCHAR(20)); INSERT INTO water_consumption_miami (customer_id,category,consumption,day,month,year,city) VALUES (1,'commercial',30,1,1,2019,'Miami'); INSERT INTO water_consumption_miami (customer_id,category,consumption,day,month,year,city) VALUES (2,'commercial',35,2,1,2019,'Miami');
|
SELECT AVG(consumption) FROM water_consumption_miami WHERE category = 'commercial' AND year = 2019 AND city = 'Miami' GROUP BY day;
|
What is the policy retention rate for male policyholders in New York and Florida?
|
CREATE TABLE Policyholders (PolicyID INT,Gender VARCHAR(10),State VARCHAR(10)); INSERT INTO Policyholders VALUES (1,'Male','New York'); INSERT INTO Policyholders VALUES (2,'Female','Florida'); CREATE TABLE Policies (PolicyID INT,RetentionRate DECIMAL(3,2)); INSERT INTO Policies VALUES (1,0.80); INSERT INTO Policies VALUES (2,0.85);
|
SELECT p.Gender, AVG(pr.RetentionRate) as RetentionRate FROM Policyholders p INNER JOIN Policies pr ON p.PolicyID = pr.PolicyID WHERE (p.Gender = 'Male' AND p.State IN ('New York', 'Florida')) GROUP BY p.Gender;
|
What is the total number of tourists visiting countries in the South American continent?
|
CREATE TABLE south_american_tourists (id INT,country VARCHAR(20),tourists INT); INSERT INTO south_american_tourists (id,country,tourists) VALUES (1,'Brazil',60000000),(2,'Argentina',5000000),(3,'Colombia',4000000);
|
SELECT SUM(tourists) FROM south_american_tourists;
|
What is the maximum recorded length for each shark species in the 'shark_population' table?
|
CREATE TABLE shark_population (shark_id INTEGER,species TEXT,length REAL); INSERT INTO shark_population (shark_id,species,length) VALUES (1,'Whale Shark',12000.1),(2,'Basking Shark',10000.2),(3,'Great White Shark',6000.3);
|
SELECT species, MAX(length) FROM shark_population GROUP BY species;
|
What is the count of non-white female employees who have completed diversity training?
|
CREATE TABLE Employees (EmployeeID INT,Gender VARCHAR(20),Ethnicity VARCHAR(20),CompletedDiversityTraining BOOLEAN);
|
SELECT COUNT(*) FROM Employees WHERE Gender = 'Female' AND Ethnicity != 'White' AND CompletedDiversityTraining = TRUE;
|
Delete all records for products that have not been restocked in the last 6 months.
|
CREATE TABLE products (product_id INT,product_name VARCHAR(50),restock_date DATE); INSERT INTO products (product_id,product_name,restock_date) VALUES (1,'Product A','2022-01-01'),(2,'Product B','2022-04-15'),(3,'Product C','2021-12-01');
|
DELETE FROM products WHERE restock_date < DATEADD(month, -6, GETDATE());
|
What is the total quantity of orders for each product category?
|
CREATE TABLE Products (id INT,category VARCHAR(20),price DECIMAL(5,2)); CREATE TABLE Orders (id INT,product_id INT,quantity INT,order_date DATE); INSERT INTO Products (id,category,price) VALUES (1,'Tops',15.99),(2,'Bottoms',29.99),(3,'Outerwear',49.99),(4,'Accessories',7.99),(5,'Tops',12.99); INSERT INTO Orders (id,product_id,quantity,order_date) VALUES (1,1,10,'2021-01-01'),(2,2,5,'2021-01-02'),(3,3,2,'2021-01-03'),(4,4,15,'2021-01-04'),(5,5,8,'2021-01-05');
|
SELECT p.category, SUM(o.quantity) FROM Products p JOIN Orders o ON p.id = o.product_id GROUP BY p.category;
|
List the top 5 water consuming cities in the state of California for the year 2019, ordered by water consumption in descending order.
|
CREATE TABLE california_cities (id INT,city VARCHAR(50),water_consumption FLOAT,year INT); INSERT INTO california_cities (id,city,water_consumption,year) VALUES (1,'Los Angeles',1200000,2019); INSERT INTO california_cities (id,city,water_consumption,year) VALUES (2,'San Diego',800000,2019); INSERT INTO california_cities (id,city,water_consumption,year) VALUES (3,'San Jose',600000,2019); INSERT INTO california_cities (id,city,water_consumption,year) VALUES (4,'San Francisco',400000,2019); INSERT INTO california_cities (id,city,water_consumption,year) VALUES (5,'Sacramento',350000,2019);
|
SELECT city, water_consumption FROM california_cities WHERE year = 2019 ORDER BY water_consumption DESC LIMIT 5;
|
Which are the top 3 cities with the most inventory quantity?
|
CREATE TABLE warehouses (id VARCHAR(10),name VARCHAR(20),city VARCHAR(10),country VARCHAR(10)); CREATE TABLE inventory (item VARCHAR(10),warehouse_id VARCHAR(10),quantity INT); INSERT INTO warehouses (id,name,city,country) VALUES ('SEA-WH-01','Seattle Warehouse','Seattle','USA'),('NYC-WH-01','New York City Warehouse','New York','USA'),('LAX-WH-01','Los Angeles Warehouse','Los Angeles','USA'); INSERT INTO inventory (item,warehouse_id,quantity) VALUES ('Laptop','SEA-WH-01',300),('Monitor','SEA-WH-01',200),('Keyboard','SEA-WH-01',150),('Laptop','NYC-WH-01',400),('Monitor','NYC-WH-01',300),('Keyboard','NYC-WH-01',250),('Laptop','LAX-WH-01',500),('Monitor','LAX-WH-01',400),('Keyboard','LAX-WH-01',350);
|
SELECT city, SUM(quantity) as total_quantity FROM inventory i JOIN warehouses w ON i.warehouse_id = w.id GROUP BY city ORDER BY total_quantity DESC LIMIT 3;
|
How many virtual tours were engaged in the last month for hotels in Japan, grouped by city?
|
CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,city TEXT,country TEXT);CREATE TABLE virtual_tours (tour_id INT,hotel_id INT,tour_date DATE); INSERT INTO hotels VALUES (1,'Hotel B','Tokyo','Japan'); INSERT INTO virtual_tours VALUES (1,1,'2022-03-15');
|
SELECT city, COUNT(*) FROM hotels INNER JOIN virtual_tours ON hotels.hotel_id = virtual_tours.hotel_id WHERE country = 'Japan' AND tour_date >= DATEADD(month, -1, GETDATE()) GROUP BY city;
|
What is the maximum pollution level and corresponding mine name for mines in the Arctic region?
|
CREATE TABLE mine_operations (id INT PRIMARY KEY,mine_name VARCHAR(255),location VARCHAR(255),extraction_type VARCHAR(255),production_volume INT);CREATE TABLE environmental_impact (id INT PRIMARY KEY,mine_id INT,pollution_level INT,waste_generation INT);
|
SELECT m.mine_name, e.pollution_level FROM mine_operations m JOIN environmental_impact e ON m.id = e.mine_id WHERE m.location = 'Arctic' AND e.pollution_level = (SELECT MAX(pollution_level) FROM environmental_impact WHERE mine_id = m.id);
|
What is the average price per size for men's shirts in size XL, for all brands, and display the top 5 results?
|
CREATE TABLE Products (ProductID int,ProductName varchar(50),ProductType varchar(50),Size varchar(10),Price decimal(5,2)); INSERT INTO Products (ProductID,ProductName,ProductType,Size,Price) VALUES (1,'Eco Casual Shirt','Men','XL',40); INSERT INTO Products (ProductID,ProductName,ProductType,Size,Price) VALUES (2,'Green Formal Shirt','Men','L',45);
|
SELECT AVG(Price) as AvgPrice, ProductType FROM Products WHERE ProductType = 'Men' AND Size = 'XL' GROUP BY ProductType ORDER BY AvgPrice DESC LIMIT 5;
|
Calculate the average number of construction labor hours per week in Texas
|
CREATE TABLE labor_hours (worker_id INT,state VARCHAR(20),hours_per_week DECIMAL(5,2)); INSERT INTO labor_hours (worker_id,state,hours_per_week) VALUES (1,'TX',40.00),(2,'TX',45.00);
|
SELECT AVG(hours_per_week) FROM labor_hours WHERE state = 'TX';
|
What is the total number of traditional arts and heritage sites in Asia?
|
CREATE TABLE arts_and_sites (id INT,item_name VARCHAR(255),type VARCHAR(255),location VARCHAR(255)); INSERT INTO arts_and_sites (id,item_name,type,location) VALUES (1,'Taiko','traditional art','Japan'),(2,'Great Wall','heritage site','China');
|
SELECT COUNT(*) FROM arts_and_sites WHERE location = 'Asia';
|
How many volunteers engaged in each program in Q1 2022?
|
CREATE TABLE Programs (ProgramID int,ProgramName varchar(50)); CREATE TABLE Volunteers (VolunteerID int,ProgramID int,VolunteerDate date);
|
SELECT Programs.ProgramName, COUNT(Volunteers.VolunteerID) as VolunteersInProgram FROM Programs INNER JOIN Volunteers ON Programs.ProgramID = Volunteers.ProgramID WHERE QUARTER(VolunteerDate) = 1 AND YEAR(VolunteerDate) = 2022 GROUP BY Programs.ProgramName;
|
Which countries had the lowest local economic impact from virtual tours in Q1 2022?
|
CREATE TABLE virtual_tours (country VARCHAR(255),quarter VARCHAR(10),local_impact FLOAT); INSERT INTO virtual_tours (country,quarter,local_impact) VALUES ('Australia','Q1',500000),('Brazil','Q1',600000),('Russia','Q1',400000);
|
SELECT country, MIN(local_impact) FROM virtual_tours WHERE quarter = 'Q1' GROUP BY country ORDER BY MIN(local_impact) ASC;
|
Find the customer with the lowest balance in the Shariah-compliant checking accounts, and display their account number, name, and balance.
|
CREATE TABLE checking_acct (acct_number INT,name VARCHAR(50),balance DECIMAL(10,2),is_shariah BOOLEAN); INSERT INTO checking_acct (acct_number,name,balance,is_shariah) VALUES (2001,'Fatima',5000.00,true),(2002,'Hassan',7000.00,false),(2003,'Aisha',3000.00,true),(2004,'Ali',9000.00,false);
|
SELECT acct_number, name, balance FROM (SELECT acct_number, name, balance, ROW_NUMBER() OVER (PARTITION BY is_shariah ORDER BY balance ASC) as rn FROM checking_acct WHERE is_shariah = true) t WHERE rn = 1;
|
How many volunteers worked at each event in H1 of 2020?
|
CREATE TABLE Events (event_name TEXT,volunteers INTEGER,event_date DATE); INSERT INTO Events (event_name,volunteers,event_date) VALUES ('Event A',50,'2020-01-10'); INSERT INTO Events (event_name,volunteers,event_date) VALUES ('Event B',75,'2020-04-20');
|
SELECT event_name, SUM(volunteers) FROM Events WHERE event_date BETWEEN '2020-01-01' AND '2020-06-30' GROUP BY event_name;
|
Which open pedagogy resources have been accessed by the most teachers?
|
CREATE TABLE TeacherAccess (TeacherID INT,Resource VARCHAR(100),AccessDate DATE); INSERT INTO TeacherAccess (TeacherID,Resource,AccessDate) VALUES (1,'Open Textbook','2022-01-15');
|
SELECT Resource, COUNT(*) FROM TeacherAccess GROUP BY Resource ORDER BY COUNT(*) DESC;
|
List all marine species and their average depth distribution.
|
CREATE TABLE marine_species (species_id INT,species_name VARCHAR(255)); CREATE TABLE depth_distribution (distribution_id INT,species_id INT,avg_depth DECIMAL(5,2)); INSERT INTO marine_species (species_id,species_name) VALUES (1,'Green Sea Turtle'),(2,'Humpback Whale'); INSERT INTO depth_distribution (distribution_id,species_id,avg_depth) VALUES (1,1,50.00),(2,2,200.00);
|
SELECT marine_species.species_name, depth_distribution.avg_depth FROM marine_species INNER JOIN depth_distribution ON marine_species.species_id = depth_distribution.species_id;
|
What was the total revenue for each state in the first quarter of 2022?
|
CREATE TABLE sales (id INT,state VARCHAR(20),revenue DECIMAL(10,2),month INT,year INT);
|
SELECT state, SUM(revenue) FROM sales WHERE month BETWEEN 1 AND 3 AND year = 2022 GROUP BY state;
|
Get total funding for autonomous driving research projects in North America
|
CREATE TABLE funding_breakdown (id INT,project VARCHAR(50),region VARCHAR(50),funding FLOAT); INSERT INTO funding_breakdown VALUES (1,'Project Epsilon','North America',4500000); INSERT INTO funding_breakdown VALUES (2,'Project Zeta','Asia',5000000);
|
SELECT SUM(funding) FROM funding_breakdown WHERE region = 'North America';
|
What is the total revenue generated by Airbus A320 family aircraft sales?
|
CREATE TABLE A320Sales (id INT,sale_date DATE,sale_price DECIMAL(10,2));
|
SELECT SUM(sale_price) FROM A320Sales WHERE sale_price IS NOT NULL;
|
What is the average age of all hip-hop artists in our database?
|
CREATE TABLE Artists (ArtistID INT,ArtistName VARCHAR(100),Age INT,Genre VARCHAR(50)); INSERT INTO Artists VALUES (1,'Artist A',35,'Hip-Hop'),(2,'Artist B',28,'Pop');
|
SELECT AVG(Age) FROM Artists WHERE Genre = 'Hip-Hop';
|
What is the total waste generation in Europe for the year 2020, separated by region?
|
CREATE TABLE WasteGenerationEurope (region VARCHAR(50),year INT,waste_quantity INT); INSERT INTO WasteGenerationEurope (region,year,waste_quantity) VALUES ('Europe/East',2020,250000),('Europe/West',2020,270000),('Europe/North',2020,300000),('Europe/South',2020,280000);
|
SELECT region, SUM(waste_quantity) FROM WasteGenerationEurope WHERE year = 2020 GROUP BY region;
|
What is the total number of models trained and tested for fairness across all regions?
|
CREATE TABLE models (id INT,name VARCHAR(255),region VARCHAR(255),is_fairness_test BOOLEAN); INSERT INTO models (id,name,region,is_fairness_test) VALUES (1,'ModelA','US',true),(2,'ModelB','EU',false),(3,'ModelC','APAC',true);
|
SELECT COUNT(*) FROM models WHERE is_fairness_test = true;
|
Show the top 5 artists with the highest number of streams on the music streaming platform in the USA.
|
CREATE TABLE music_platform (id INT,artist VARCHAR(100),country VARCHAR(50),streams INT);
|
SELECT artist, SUM(streams) as total_streams FROM music_platform WHERE country = 'USA' GROUP BY artist ORDER BY total_streams DESC LIMIT 5;
|
List the names and number of workplace safety incidents of unions in the 'mining' sector, ordered by the number of incidents in descending order.
|
CREATE TABLE mining_unions (id INT,name TEXT,sector TEXT,incident_count INT); CREATE TABLE mining_incidents (id INT,union_id INT,incident_type TEXT,incident_date DATE);
|
SELECT m.name, COUNT(mi.id) as incidents_count FROM mining_unions m JOIN mining_incidents mi ON m.id = mi.union_id WHERE m.sector = 'mining' GROUP BY m.id ORDER BY incidents_count DESC;
|
What's the name and market capitalization of the digital asset with the lowest market capitalization in the 'Solana' network?
|
CREATE TABLE solana_digital_assets (id INT,name VARCHAR(255),network VARCHAR(255),market_cap DECIMAL(10,2)); INSERT INTO solana_digital_assets (id,name,network,market_cap) VALUES (1,'Asset3','solana',200),(2,'Asset4','solana',250);
|
SELECT name, market_cap FROM solana_digital_assets WHERE network = 'solana' ORDER BY market_cap LIMIT 1;
|
Maximum number of sustainable investments in African countries?
|
CREATE TABLE sustainable_investments(investment_id INT,investment_type VARCHAR(20),country VARCHAR(10));
|
SELECT MAX(COUNT(*)) FROM sustainable_investments WHERE country LIKE 'Africa%' GROUP BY country;
|
What is the average number of employees for startups founded by immigrants from Asia in the e-commerce sector?
|
CREATE TABLE companies (id INT,name TEXT,industry TEXT,founding_year INT,founder_immigration_status TEXT,num_employees INT); INSERT INTO companies (id,name,industry,founding_year,founder_immigration_status,num_employees) VALUES (1,'ShopEase','E-commerce',2019,'Immigrant',50); INSERT INTO companies (id,name,industry,founding_year,founder_immigration_status,num_employees) VALUES (2,'MarketFlex','E-commerce',2018,'Non-immigrant',75);
|
SELECT AVG(companies.num_employees) FROM companies WHERE companies.industry = 'E-commerce' AND companies.founder_immigration_status = 'Immigrant';
|
How many unique streaming platforms have distributed songs by artist 'The Beatles'?
|
CREATE TABLE platforms (platform_id INT,platform VARCHAR(50)); INSERT INTO platforms VALUES (1,'Spotify'),(2,'Apple Music'),(3,'Tidal'); CREATE TABLE song_platforms (song_id INT,platform_id INT); INSERT INTO song_platforms VALUES (1,1),(1,2),(2,2),(3,3); CREATE TABLE songs (song_id INT,song VARCHAR(50),artist VARCHAR(50)); INSERT INTO songs VALUES (1,'Hey Jude','The Beatles'),(2,'Blackbird','The Beatles'),(3,'So What','Miles Davis');
|
SELECT COUNT(DISTINCT p.platform_id) as platform_count FROM platforms p JOIN song_platforms sp ON p.platform_id = sp.platform_id JOIN songs s ON sp.song_id = s.song_id WHERE s.artist = 'The Beatles';
|
What is the average depth of all trenches in the Pacific Ocean?
|
CREATE TABLE ocean_trenches (name VARCHAR(50),location VARCHAR(50),avg_depth FLOAT); INSERT INTO ocean_trenches
|
SELECT AVG(avg_depth) FROM ocean_trenches WHERE location = 'Pacific Ocean';
|
What is the number of union members who have participated in labor rights advocacy events, by union?
|
CREATE TABLE labor_rights_advocacy_events (event_id INTEGER,union_name TEXT); INSERT INTO labor_rights_advocacy_events (event_id,union_name) VALUES (1,'Union A'),(2,'Union A'),(3,'Union B'),(4,'Union C'),(5,'Union D'),(6,'Union E'),(7,'Union A'),(8,'Union B'),(9,'Union C'),(10,'Union D'),(11,'Union E'),(12,'Union A'),(13,'Union B'),(14,'Union C'),(15,'Union D'),(16,'Union E');
|
SELECT union_name, COUNT(*) as num_participants FROM labor_rights_advocacy_events GROUP BY union_name;
|
How many satellites were launched per country?
|
CREATE TABLE international_satellite_launches (id INT,launch_year INT,country VARCHAR(50),satellites INT); INSERT INTO international_satellite_launches (id,launch_year,country,satellites) VALUES (1,2020,'USA',20),(2,2020,'China',30),(3,2021,'Russia',15);
|
SELECT country, SUM(satellites) FROM international_satellite_launches GROUP BY country;
|
Who are the farmers that raised animals in 'region1' and what was the total quantity of animals?
|
CREATE TABLE farmer (farmer_id INT,farmer_name TEXT,region TEXT); INSERT INTO farmer (farmer_id,farmer_name,region) VALUES (1,'FarmerA','region1'),(2,'FarmerB','region2'),(3,'FarmerC','region2'); CREATE TABLE animal_rearing (rearing_id INT,farmer_id INT,animal_type TEXT,quantity INT); INSERT INTO animal_rearing (rearing_id,farmer_id,animal_type,quantity) VALUES (1,1,'Cattle',10),(2,1,'Chickens',50),(3,2,'Pigs',20),(4,3,'Goats',30);
|
SELECT f.farmer_name, SUM(ar.quantity) as total_animals FROM farmer f INNER JOIN animal_rearing ar ON f.farmer_id = ar.farmer_id WHERE f.region = 'region1' GROUP BY f.farmer_name;
|
What is the total number of security incidents caused by insider threats in the last six months?
|
CREATE TABLE incidents (id INT,threat_actor VARCHAR(255),incident_date DATE); INSERT INTO incidents (id,threat_actor,incident_date) VALUES (1,'insider','2022-01-15'),(2,'outsider','2022-02-20'),(3,'insider','2022-03-05'); SELECT CURDATE(),DATE_SUB(CURDATE(),INTERVAL 6 MONTH) INTO @current_date,@start_date; SELECT COUNT(*) FROM incidents WHERE threat_actor = 'insider' AND incident_date BETWEEN @start_date AND @current_date;
|
SELECT COUNT(*) FROM incidents WHERE threat_actor = 'insider' AND incident_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 6 MONTH) AND CURDATE();
|
What is the total duration of videos by language?
|
CREATE TABLE Videos (id INT,title VARCHAR(255),language VARCHAR(255),duration INT); INSERT INTO Videos (id,title,language,duration) VALUES (1,'Video1','English',60),(2,'Video2','French',90),(3,'Video3','English',45);
|
SELECT language, SUM(duration) as total_duration FROM Videos GROUP BY language;
|
Determine the total number of wells drilled in the North Sea region
|
CREATE TABLE wells (id INT,region VARCHAR(20),well_type VARCHAR(20)); INSERT INTO wells (id,region,well_type) VALUES (1,'North Sea','Exploration'),(2,'Gulf of Mexico','Production');
|
SELECT COUNT(*) FROM wells WHERE region = 'North Sea';
|
Calculate the average range of electric vehicles for each make, excluding null values
|
CREATE TABLE electric_vehicles (id INT,make VARCHAR(50),range INT); INSERT INTO electric_vehicles (id,make,range) VALUES (1,'Tesla',350),(2,'Tesla',400),(3,'Nissan',250),(4,'Nissan',280),(5,'Ford',310),(6,'Ford',NULL),(7,'Chevy',240);
|
SELECT make, AVG(range) as avg_range FROM electric_vehicles WHERE range IS NOT NULL GROUP BY make;
|
Delete all records in the 'auto_shows' table for the year 2023
|
CREATE TABLE auto_shows (show_name VARCHAR(255),year INT,location VARCHAR(255));
|
DELETE FROM auto_shows WHERE year = 2023;
|
What is the maximum production capacity of the African coal mines?
|
CREATE TABLE Mines (MineID INT,MineType VARCHAR(20),ProductionCapacity INT); INSERT INTO Mines (MineID,MineType,ProductionCapacity) VALUES (1,'Coal',500000); INSERT INTO Mines (MineID,MineType,ProductionCapacity) VALUES (2,'Gold',200000);
|
SELECT MAX(ProductionCapacity) FROM Mines WHERE MineType = 'Coal' AND Location LIKE 'Africa%';
|
List the names and total labor hours of construction workers who have worked on sustainable building projects in New York City.
|
CREATE TABLE construction_workers (worker_id INT,name TEXT); CREATE TABLE project_types (project_id INT,project_type TEXT); CREATE TABLE worker_projects (worker_id INT,project_id INT,total_labor_hours INT); CREATE TABLE projects (project_id INT,city TEXT,state TEXT); INSERT INTO construction_workers (worker_id,name) VALUES (1,'John Doe'),(2,'Jane Smith'),(3,'Maria Garcia'); INSERT INTO project_types (project_id,project_type) VALUES (1,'Residential'),(2,'Commercial'),(3,'Sustainable'); INSERT INTO worker_projects (worker_id,project_id,total_labor_hours) VALUES (1,1,500),(1,2,300),(2,2,600),(2,3,400),(3,1,700),(3,3,500); INSERT INTO projects (project_id,city,state) VALUES (1,'New York City','New York'),(2,'Houston','Texas'),(3,'Los Angeles','California');
|
SELECT construction_workers.name, SUM(worker_projects.total_labor_hours) FROM construction_workers INNER JOIN worker_projects ON construction_workers.worker_id = worker_projects.worker_id INNER JOIN (SELECT DISTINCT project_id FROM projects INNER JOIN project_types ON projects.city = 'New York City' AND project_types.project_type = 'Sustainable') AS sustainable_projects ON worker_projects.project_id = sustainable_projects.project_id GROUP BY construction_workers.name;
|
Find the daily change in oil price from the 'oil_prices' table.
|
CREATE TABLE oil_prices (price_date DATE,oil_price NUMERIC(10,2)); INSERT INTO oil_prices (price_date,oil_price) VALUES ('2022-01-01',70),('2022-01-02',72),('2022-01-03',75),('2022-01-04',78);
|
SELECT price_date, oil_price, LAG(oil_price, 1) OVER (ORDER BY price_date) as prev_oil_price, oil_price - LAG(oil_price, 1) OVER (ORDER BY price_date) as daily_change FROM oil_prices;
|
What is the average 'green_score' in the 'green_buildings' table?
|
CREATE TABLE green_buildings (id INT,city VARCHAR(20),green_score INT); INSERT INTO green_buildings (id,city,green_score) VALUES (1,'Boston',85),(2,'Philadelphia',75),(3,'Atlanta',90);
|
SELECT AVG(green_score) FROM green_buildings;
|
What is the total transaction amount by transaction type for the first quarter of 2022?
|
CREATE TABLE transactions (transaction_id INT,transaction_type VARCHAR(20),transaction_amount DECIMAL(10,2),transaction_date DATE); INSERT INTO transactions (transaction_id,transaction_type,transaction_amount,transaction_date) VALUES (1,'Withdrawal',500.00,'2022-01-01');
|
SELECT SUM(transaction_amount), transaction_type FROM transactions WHERE transaction_date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY transaction_type;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.