instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
How many artworks were created by Indigenous artists in Canada? | CREATE TABLE Artists (id INT,name VARCHAR(50),ethnicity VARCHAR(20)); INSERT INTO Artists (id,name,ethnicity) VALUES (1,'Carl Beam','Indigenous'),(2,'Emily Carr','Canadian'),(3,'Jack Bush','Canadian'),(4,'Daphne Odjig','Indigenous'); CREATE TABLE Artworks (id INT,artist_id INT,title VARCHAR(50)); INSERT INTO Artworks (id,artist_id,title) VALUES (1,1,'The Columbian Exchange'),(2,3,'The Figure'),(3,4,'People of the Woodlands'); CREATE TABLE Countries (id INT,name VARCHAR(20)); INSERT INTO Countries (id,name) VALUES (1,'Canada'); | SELECT COUNT(*) FROM Artworks JOIN Artists ON Artworks.artist_id = Artists.id JOIN Countries ON Artists.country = Countries.name WHERE Artists.ethnicity = 'Indigenous' AND Countries.name = 'Canada'; |
What is the average revenue generated per day from catering orders? | CREATE TABLE Orders (id INT,order_channel VARCHAR(50),price DECIMAL(10,2),date DATE); CREATE VIEW Catering_Orders AS SELECT price FROM Orders WHERE order_channel = 'catering'; | SELECT AVG(SUM(price)) FROM Catering_Orders GROUP BY date; |
Insert a new ethical fashion brand 'GreenEarth' into Brands table with revenue of $2,000,000 in 2023 | CREATE TABLE Revenue (id INT,brand_id INT,year INT,revenue INT); INSERT INTO Revenue (id,brand_id,year,revenue) VALUES (1,4001,2021,1000000),(2,4002,2022,1200000),(3,4003,2021,1100000),(4,4004,2022,1500000); CREATE TABLE Brands (id INT,brand_name VARCHAR(255),ethical BOOLEAN); INSERT INTO Brands (id,brand_name,ethical) VALUES (4001,'BrandA',true),(4002,'BrandB',true),(4003,'BrandC',false),(4004,'BrandD',true); | INSERT INTO Brands (id, brand_name, ethical) VALUES (4005, 'GreenEarth', true); INSERT INTO Revenue (id, brand_id, year, revenue) VALUES (5, 4005, 2023, 2000000); |
What are the items with low stock levels and their suppliers? | CREATE TABLE Suppliers (SupplierID INT,Name VARCHAR(50),Item VARCHAR(50),Quantity INT,Cost DECIMAL(5,2)); CREATE VIEW LowStock AS SELECT SupplierID,Item FROM Suppliers WHERE Quantity < 10; | SELECT Suppliers.Name, Suppliers.Item, Suppliers.Quantity, Suppliers.Cost FROM Suppliers JOIN LowStock ON Suppliers.SupplierID = LowStock.SupplierID; |
What is the rank of the number of sustainable accommodations in each continent, ordered by the total number of accommodations? | CREATE TABLE SustainableAccommodations (country VARCHAR(20),continent VARCHAR(20),num_sustainable INT,num_total INT); INSERT INTO SustainableAccommodations (country,continent,num_sustainable,num_total) VALUES ('France','Europe',1500,2000),('Italy','Europe',1200,1800),('Spain','Europe',1000,1500),('Brazil','South America',500,700); | SELECT country, continent, ROW_NUMBER() OVER (ORDER BY num_total DESC) AS rank FROM SustainableAccommodations; |
Count the number of artists from each country. | CREATE TABLE artists (id INT,name TEXT,country TEXT); INSERT INTO artists (id,name,country) VALUES (1,'Ed Sheeran','United Kingdom'); | SELECT country, COUNT(*) FROM artists GROUP BY country; |
What is the average response time for disaster relief appeals in African regions? | CREATE TABLE DisasterReliefAppeals (Region VARCHAR(20),AppealID INT,ResponseTime INT); INSERT INTO DisasterReliefAppeals (Region,AppealID,ResponseTime) VALUES ('East Africa',1,3),('West Africa',2,5),('Central Africa',3,8),('North Africa',4,10),('Southern Africa',5,12); | SELECT Region, AVG(ResponseTime) as AvgResponseTime FROM DisasterReliefAppeals WHERE Region LIKE 'Africa%' GROUP BY Region; |
List the names of all employees who were hired before their manager. | CREATE TABLE employees (id INT,name VARCHAR(50),manager_id INT,hire_date DATE); | SELECT e1.name FROM employees e1, employees e2 WHERE e1.id = e2.manager_id AND e1.hire_date > e2.hire_date; |
What is the average retail price per gram for Indica strains sold in Washington dispensaries in June 2022? | CREATE TABLE dispensaries (id INT,name VARCHAR(50),state VARCHAR(20)); CREATE TABLE strains (id INT,name VARCHAR(50),type VARCHAR(20),price DECIMAL(5,2)); INSERT INTO dispensaries (id,name,state) VALUES (1,'High Desert','Washington'),(2,'Mountain View','Washington'); INSERT INTO strains (id,name,type,price) VALUES (1,'Purple Kush','Indica',15.00),(2,'Bubba Kush','Indica',12.00); | SELECT AVG(price) as avg_price FROM strains st JOIN dispensaries d ON st.state = d.state WHERE st.type = 'Indica' AND d.state = 'Washington'; |
What is the number of vulnerabilities with a severity greater than 7 in the 'HR' department? | CREATE TABLE vulnerabilities (id INT,department VARCHAR(20),severity FLOAT); INSERT INTO vulnerabilities (id,department,severity) VALUES (1,'HR',6.5); INSERT INTO vulnerabilities (id,department,severity) VALUES (2,'Finance',8.2); INSERT INTO vulnerabilities (id,department,severity) VALUES (3,'HR',7.3); | SELECT COUNT(*) FROM vulnerabilities WHERE department = 'HR' AND severity > 7; |
What is the most popular material based on inventory quantity? | CREATE TABLE trends (id INT,material VARCHAR(255),popularity FLOAT); INSERT INTO trends (id,material,popularity) VALUES (3,'Hemp',0.85); INSERT INTO trends (id,material,popularity) VALUES (4,'Tencel',0.15); | SELECT t.material, t.popularity FROM trends t JOIN (SELECT material, SUM(quantity) as total_quantity FROM inventory GROUP BY material ORDER BY total_quantity DESC LIMIT 1) i ON t.material = i.material; |
What is the total revenue generated by the "Special" exhibitions? | CREATE TABLE ticket_receipts (receipt_id INT,receipt_amount DECIMAL(10,2),exhibition_id INT); INSERT INTO ticket_receipts (receipt_id,receipt_amount,exhibition_id) VALUES (10,35.00,1); | SELECT SUM(receipt_amount) FROM ticket_receipts JOIN exhibitions ON ticket_receipts.exhibition_id = exhibitions.exhibition_id WHERE exhibitions.exhibition_type = 'Special'; |
What are the average response times for security incidents in the LATAM region in the last month? | CREATE TABLE security_incidents (incident_id INT,incident_date DATE,mitigation_team VARCHAR(255),region VARCHAR(255),response_time INT); INSERT INTO security_incidents (incident_id,incident_date,mitigation_team,region,response_time) VALUES (1,'2021-03-22','Incident Response Team A','LATAM',480),(2,'2021-04-15','Incident Response Team B','APAC',360),(3,'2021-05-09','Incident Response Team A','LATAM',540),(4,'2021-07-03','Incident Response Team B','APAC',720),(5,'2021-09-18','Incident Response Team A','LATAM',600),(6,'2021-10-27','Incident Response Team B','APAC',300),(7,'2021-11-12','Incident Response Team A','LATAM',420),(8,'2021-12-08','Incident Response Team B','APAC',600); | SELECT region, AVG(response_time) AS avg_response_time FROM security_incidents WHERE incident_date >= DATE_SUB(NOW(), INTERVAL 1 MONTH) AND region = 'LATAM' GROUP BY region; |
Display policy type and count of claims for each policy type | CREATE TABLE claims (claim_id INT,policy_type VARCHAR(20)); INSERT INTO claims (claim_id,policy_type) VALUES (1,'Auto'),(2,'Home'),(3,'Auto'),(4,'Life'),(5,'Auto'),(6,'Home'); | SELECT policy_type, COUNT(*) AS claim_count FROM claims GROUP BY policy_type; |
What is the average lifespan of communication satellites and how many have been launched? | CREATE TABLE satellite (id INT,name VARCHAR(255),type VARCHAR(255),country VARCHAR(255),launch_date DATE); INSERT INTO satellite VALUES (6,'Communication Satellite','Communication','Germany','1989-02-14'),(7,'Communication Satellite','Communication','Japan','1992-07-23'); | SELECT type, COUNT(id) as total, AVG(DATEDIFF(CURDATE(), launch_date)) as avg_lifespan FROM satellite WHERE type = 'Communication Satellite' GROUP BY type; |
Insert a new public transportation train in Tokyo. | CREATE TABLE public_transportation (transport_id INT,type VARCHAR(20),city VARCHAR(20)); INSERT INTO public_transportation (transport_id,type,city) VALUES (1,'Bus','Tokyo'),(2,'Tram','Tokyo'),(3,'Train','Osaka'); | INSERT INTO public_transportation (transport_id, type, city) VALUES (4, 'Train', 'Tokyo'); |
Update the quantity of the reverse logistics record with ID 2 | CREATE TABLE reverse_logistics (id INT,item_id INT,quantity INT); INSERT INTO reverse_logistics (id,item_id,quantity) VALUES (1,333,2),(2,333,3),(3,334,1); | UPDATE reverse_logistics SET quantity = 5 WHERE id = 2; |
What is the maximum flight distance for each aircraft type? | CREATE TABLE flights (flight_id INT,aircraft_type VARCHAR(50),flight_distance INT); | SELECT aircraft_type, MAX(flight_distance) as max_distance FROM flights GROUP BY aircraft_type; |
How many mobile subscribers have changed their plan in the state of California in the last month? | CREATE TABLE mobile_changes (id INT,subscriber_id INT,state VARCHAR(20),change_date DATE); | SELECT state, COUNT(*) FROM mobile_changes WHERE state = 'California' AND change_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH); |
How many green buildings in the 'green_buildings' table have a 'Gold' certification level? | CREATE TABLE green_buildings (building_id INT,location TEXT,certification_level TEXT); INSERT INTO green_buildings (building_id,location,certification_level) VALUES (1,'Los Angeles','Gold'),(2,'Chicago','Platinum'),(3,'Houston','Silver'),(4,'Dallas','Gold'); | SELECT COUNT(*) FROM green_buildings WHERE certification_level = 'Gold'; |
What is the average energy production of wind turbines in the 'Pacific' region? | CREATE TABLE wind_turbines (id INT,region VARCHAR(20),energy_production FLOAT); INSERT INTO wind_turbines (id,region,energy_production) VALUES (1,'Pacific',2345.6),(2,'Mountain',3456.7),(3,'Pacific',4567.8),(4,'Central',5678.9); | SELECT AVG(energy_production) FROM wind_turbines WHERE region = 'Pacific'; |
What is the average accommodation cost for students with hearing impairments in the Northeast? | CREATE TABLE Accommodations (ID INT,Type VARCHAR(50),Cost FLOAT,Disability VARCHAR(50),Region VARCHAR(50)); INSERT INTO Accommodations (ID,Type,Cost,Disability,Region) VALUES (1,'Sign Language Interpretation',50.0,'Hearing Impairment','Northeast'),(2,'Assistive Listening Devices',75.0,'Hearing Impairment','Northeast'); | SELECT AVG(Cost) FROM Accommodations WHERE Disability = 'Hearing Impairment' AND Region = 'Northeast'; |
List the number of satellites in orbit around Mars, grouped by the country that launched each satellite, and show the total number of satellites in orbit around Mars. | CREATE TABLE Satellites (id INT,country VARCHAR(255),orbiting_body VARCHAR(255)); | SELECT country, COUNT(*) as total_satellites FROM Satellites WHERE orbiting_body = 'Mars' GROUP BY country; SELECT COUNT(*) as total_satellites_around_mars FROM Satellites WHERE orbiting_body = 'Mars'; |
Calculate the total volume of the Mariana Trench | CREATE TABLE marine_trenches (name TEXT,location TEXT,max_depth INTEGER,avg_depth INTEGER);INSERT INTO marine_trenches (name,location,max_depth,avg_depth) VALUES ('Mariana Trench','Pacific Ocean',10994,5000); | SELECT name, pi() * (max_depth * avg_depth * avg_depth) / 3 FROM marine_trenches WHERE name = 'Mariana Trench'; |
What is the total number of crimes committed in each borough? | CREATE TABLE boroughs (bid INT,borough_name TEXT); CREATE TABLE crimes (cid INT,borough_id INT,crime_type TEXT,committed_date TEXT); INSERT INTO boroughs VALUES (1,'Manhattan'); INSERT INTO boroughs VALUES (2,'Brooklyn'); INSERT INTO crimes VALUES (1,1,'Theft','2022-01-05'); INSERT INTO crimes VALUES (2,1,'Burglary','2022-02-10'); INSERT INTO crimes VALUES (3,2,'Vandalism','2022-03-01'); INSERT INTO crimes VALUES (4,2,'Theft','2022-03-15'); | SELECT b.borough_name, COUNT(c.cid) FROM boroughs b JOIN crimes c ON b.bid = c.borough_id GROUP BY b.borough_name; |
Determine the number of unique IP addresses associated with each threat category in the last 90 days. | CREATE TABLE ThreatIPs (Id INT,Threat VARCHAR(255),IP VARCHAR(255),Timestamp DATETIME); INSERT INTO ThreatIPs (Id,Threat,IP,Timestamp) VALUES (1,'Ransomware','192.168.1.1','2022-01-01 10:00:00'),(2,'Phishing','192.168.1.2','2022-01-02 12:00:00'),(3,'Ransomware','192.168.1.3','2022-01-03 14:00:00'); | SELECT Threat, COUNT(DISTINCT IP) as IPCount FROM ThreatIPs WHERE Timestamp >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 90 DAY) GROUP BY Threat; |
What is the average production quantity (in metric tons) of Europium? | CREATE TABLE production (element VARCHAR(10),year INT,quantity FLOAT); INSERT INTO production (element,year,quantity) VALUES ('Europium',2015,500),('Europium',2016,600),('Europium',2017,700),('Europium',2018,800),('Europium',2019,900); | SELECT AVG(quantity) FROM production WHERE element = 'Europium'; |
What is the total number of emergency response units in California? | CREATE TABLE EmergencyResponseUnits (id INT,state VARCHAR(20),unit_type VARCHAR(20),quantity INT); | SELECT SUM(quantity) FROM EmergencyResponseUnits WHERE state = 'California'; |
List all 'renewable' energy sources in the 'energies' table. | CREATE TABLE energies (id INT,name TEXT,type TEXT); INSERT INTO energies (id,name,type) VALUES (1,'solar','renewable'),(2,'wind','renewable'),(3,'coal','non-renewable'); | SELECT name FROM energies WHERE type = 'renewable'; |
What is the average time spent on disability-related policy advocacy per month? | CREATE TABLE PolicyAdvocacy (advocate_id INT,date DATE,hours_spent FLOAT); INSERT INTO PolicyAdvocacy (advocate_id,date,hours_spent) VALUES (1,'2022-01-05',5.5); INSERT INTO PolicyAdvocacy (advocate_id,date,hours_spent) VALUES (2,'2022-02-10',7.3); | SELECT AVG(hours_spent) as avg_hours_per_month FROM PolicyAdvocacy WHERE date BETWEEN '2022-01-01' AND LAST_DAY('2022-02-28'); |
What is the total number of aircraft manufactured by each company before 2010? | CREATE TABLE aircraft (id INT,model VARCHAR(255),manufacturer_id INT,manufacture_date DATE); INSERT INTO aircraft (id,model,manufacturer_id,manufacture_date) VALUES (1,'B737',1,'2000-01-01'),(2,'A320',2,'2005-03-14'),(3,'B787',1,'2008-08-01'); CREATE TABLE manufacturer (id INT,name VARCHAR(255)); INSERT INTO manufacturer (id,name) VALUES (1,'Boeing'),(2,'Airbus'); | SELECT m.name, COUNT(a.id) FROM aircraft a INNER JOIN manufacturer m ON a.manufacturer_id = m.id WHERE YEAR(a.manufacture_date) < 2010 GROUP BY m.name; |
What is the total cost of projects in the 'Roads' and 'Buildings' categories? | CREATE TABLE InfrastructureProjects (id INT,category VARCHAR(20),cost FLOAT); INSERT INTO InfrastructureProjects (id,category,cost) VALUES (1,'Roads',500000),(2,'Bridges',750000),(3,'Buildings',900000); | SELECT SUM(cost) FROM InfrastructureProjects WHERE category IN ('Roads', 'Buildings'); |
How many marine species are there in the Coral Triangle? | CREATE TABLE marine_species (name VARCHAR(255),location VARCHAR(255)); INSERT INTO marine_species (name,location) VALUES ('Clownfish','Coral Triangle'),('Sea Turtle','Coral Triangle'); | SELECT COUNT(*) FROM marine_species WHERE location = 'Coral Triangle'; |
How many vegetarian and non-vegetarian menu items does each restaurant offer? | CREATE TABLE Restaurants (RestaurantID int,Name varchar(50)); CREATE TABLE MenuItems (MenuID int,Name varchar(50),RestaurantID int,Vegetarian bit); INSERT INTO Restaurants (RestaurantID,Name) VALUES (1,'Big Burger'); INSERT INTO MenuItems (MenuID,Name,RestaurantID,Vegetarian) VALUES (1,'Big Burger',1,0); INSERT INTO MenuItems (MenuID,Name,RestaurantID,Vegetarian) VALUES (2,'Veggie Burger',1,1); | SELECT r.Name, Vegetarian, COUNT(*) as MenuItemCount FROM Restaurants r JOIN MenuItems m ON r.RestaurantID = m.RestaurantID GROUP BY r.Name, Vegetarian; |
Which economic diversification projects in Malawi had the highest average budget? | CREATE TABLE economic_diversification (id INT,country VARCHAR(20),project_name VARCHAR(50),project_budget FLOAT); INSERT INTO economic_diversification (id,country,project_name,project_budget) VALUES (1,'Malawi','Renewable Energy',100000.00),(2,'Zambia','Solar Power Plant',150000.00); | SELECT project_name, AVG(project_budget) AS avg_budget, RANK() OVER (ORDER BY AVG(project_budget) DESC) AS rank FROM economic_diversification WHERE country = 'Malawi' GROUP BY project_name HAVING rank = 1; |
Show the change in negotiator for each contract negotiation, if any. | CREATE TABLE ContractNegotiations (Id INT,Contract VARCHAR(255),NegotiationDate DATE,Negotiator VARCHAR(255)); INSERT INTO ContractNegotiations (Id,Contract,NegotiationDate,Negotiator) VALUES (5,'Communications Equipment','2021-03-01','Michael Brown'); INSERT INTO ContractNegotiations (Id,Contract,NegotiationDate,Negotiator) VALUES (6,'Training Services','2022-02-15','Taylor Green'); | SELECT Contract, NegotiationDate, Negotiator, LAG(Negotiator, 1) OVER (PARTITION BY Contract ORDER BY NegotiationDate) as PreviousNegotiator FROM ContractNegotiations; |
What's the total number of players who play action games in South America? | CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),Location VARCHAR(20)); INSERT INTO Players (PlayerID,Age,Gender,Location) VALUES (1,22,'Female','Brazil'); INSERT INTO Players (PlayerID,Age,Gender,Location) VALUES (2,35,'Male','Argentina'); CREATE TABLE Games (GameID INT,GameName VARCHAR(20),Genre VARCHAR(20)); INSERT INTO Games (GameID,GameName,Genre) VALUES (1,'Jungle Rush','Action'); | SELECT COUNT(*) FROM Players INNER JOIN (SELECT DISTINCT PlayerID FROM Games WHERE Genre = 'Action') AS ActionPlayers ON Players.PlayerID = ActionPlayers.PlayerID WHERE Players.Location = 'South America'; |
Find the total length of all tunnels in the 'transportation' category | CREATE TABLE tunnels (id INT,name VARCHAR(50),category VARCHAR(50),length FLOAT,year_built INT); INSERT INTO tunnels (id,name,category,length,year_built) VALUES (1,'Hudson River Tunnel','transportation',8500,1908); INSERT INTO tunnels (id,name,category,length,year_built) VALUES (2,'Big Dig Tunnel','transportation',5300,1991); INSERT INTO tunnels (id,name,category,length,year_built) VALUES (3,'Eisenhower Tunnel','transportation',3400,1973); | SELECT SUM(length) FROM tunnels WHERE category = 'transportation'; |
What is the average sale value of military equipment sales to Indonesia and Malaysia combined from 2017 to 2020? | CREATE TABLE MilitaryEquipmentSales (id INT PRIMARY KEY,sale_year INT,equipment_type VARCHAR(50),country VARCHAR(50),sale_value FLOAT); INSERT INTO MilitaryEquipmentSales (id,sale_year,equipment_type,country,sale_value) VALUES (1,2017,'Aircraft','United States',20000000),(2,2018,'Vehicles','United States',15000000),(3,2019,'Naval Equipment','Indonesia',10000000),(4,2020,'Radars','Malaysia',8000000); | SELECT AVG(sale_value) FROM MilitaryEquipmentSales WHERE (country = 'Indonesia' OR country = 'Malaysia') AND sale_year BETWEEN 2017 AND 2020; |
Update the name of the refined rare earth element 'Gadolinium' to 'Gadolinium-157' in the production_data table | CREATE TABLE production_data (id INT PRIMARY KEY,year INT,refined_rare_earth_element TEXT,quantity INT); INSERT INTO production_data (id,year,refined_rare_earth_element,quantity) VALUES (1,2019,'Neodymium',500),(2,2019,'Praseodymium',350),(3,2021,'Neodymium',600),(4,2021,'Praseodymium',400),(5,2020,'Gadolinium',450); | UPDATE production_data SET refined_rare_earth_element = 'Gadolinium-157' WHERE refined_rare_earth_element = 'Gadolinium'; |
Calculate the total revenue of eco-friendly hotels in Australia. | CREATE TABLE hotels (id INT,name TEXT,country TEXT,type TEXT,revenue INT); INSERT INTO hotels (id,name,country,type,revenue) VALUES (1,'Eco Hotel Sydney','Australia','eco',60000); | SELECT SUM(revenue) FROM hotels WHERE country = 'Australia' AND type = 'eco'; |
What is the minimum number of safety issues in a workplace for each state? | CREATE TABLE workplaces (id INT,state VARCHAR(2),safety_issues INT); INSERT INTO workplaces (id,state,safety_issues) VALUES (1,'NY',10),(2,'CA',5),(3,'TX',15),(4,'FL',8); | SELECT state, MIN(safety_issues) OVER (PARTITION BY state) AS min_safety_issues FROM workplaces; |
Find the percentage of articles published by 'Associated Press' with the word 'investigation' in the title? | CREATE TABLE associated_press (article_id INT,title TEXT,publish_date DATE); INSERT INTO associated_press (article_id,title,publish_date) VALUES (1,'Article Title 1 with investigation','2022-01-01'),(2,'Article Title 2 without investigation','2022-01-02'),(3,'Article Title 3 with investigation','2022-01-03'); | SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM associated_press)) AS percentage FROM associated_press WHERE title LIKE '%investigation%' |
List all the unique investors who have invested in at least one startup founded by a person of color in the UK. | CREATE TABLE investors(id INT,name TEXT,country TEXT); CREATE TABLE startups(id INT,name TEXT,founder TEXT,country TEXT); CREATE TABLE investments(investor_id INT,startup_id INT); INSERT INTO investors(id,name,country) VALUES (1,'Firm A','US'),(2,'Firm B','UK'),(3,'Firm C','India'); INSERT INTO startups(id,name,founder,country) VALUES (1,'Acme Inc','John Doe','US'),(2,'Beta Corp','Rajesh Patel','UK'),(3,'Gamma Startup','Pedro Sanchez','Spain'); INSERT INTO investments(investor_id,startup_id) VALUES (1,1),(2,1),(3,2); | SELECT DISTINCT investors.name FROM investors JOIN investments ON investors.id = investments.investor_id JOIN startups ON investments.startup_id = startups.id WHERE startups.founder IN ('Rajesh Patel') AND investors.country = 'UK'; |
Show all military innovation budgets for countries in the Middle East in the last 2 years, along with the budget increase or decrease compared to the previous year. | CREATE TABLE MilitaryBudget (ID INT,Country TEXT,Budget DECIMAL(10,2),Year INT); INSERT INTO MilitaryBudget VALUES (1,'Iran',500000,2020); CREATE VIEW MiddleEast AS SELECT Country FROM MilitaryBudget WHERE Country IN ('Iran','Iraq','Saudi Arabia','Turkey','Israel'); | SELECT m.Country, m.Budget, m.Year, m.Budget - ISNULL(p.Budget, 0) as BudgetChange FROM MilitaryBudget m LEFT JOIN MilitaryBudget p ON m.Country = p.Country AND YEAR(m.Year) = YEAR(p.Year) + 1 JOIN MiddleEast me ON m.Country = me.Country WHERE m.Year BETWEEN DATEADD(year, -2, GETDATE()) AND GETDATE(); |
Identify the number of graduate students enrolled in each Engineering discipline | CREATE TABLE graduate_students(student_id INT,name VARCHAR(50),gender VARCHAR(10),discipline VARCHAR(20)); INSERT INTO graduate_students VALUES (1,'Aarav','Male','Electrical Engineering'); INSERT INTO graduate_students VALUES (2,'Bella','Female','Mechanical Engineering'); INSERT INTO graduate_students VALUES (3,'Charlie','Non-binary','Civil Engineering'); | SELECT discipline, COUNT(*) as enrolled_students FROM graduate_students WHERE discipline LIKE 'Engineering%' GROUP BY discipline; |
What is the average budget for renewable energy projects in each country, excluding projects with a budget greater than 8000000? | CREATE TABLE Renewable_Energy_Projects (id INT,project_name VARCHAR(50),budget FLOAT,country VARCHAR(50)); INSERT INTO Renewable_Energy_Projects (id,project_name,budget,country) VALUES (1,'Solar Farm',5000000,'USA'),(2,'Wind Farm',7000000,'Canada'),(3,'Hydroelectric Plant',6000000,'Mexico'),(4,'Geothermal Plant',4000000,'USA'),(5,'Tidal Energy',3000000,'Canada'); | SELECT country, AVG(budget) FROM Renewable_Energy_Projects WHERE budget <= 8000000 GROUP BY country; |
What is the average rainfall for each region in the past 3 months? | CREATE TABLE Rainfall_Regions (date DATE,rainfall INT,region VARCHAR(20)); | SELECT region, AVG(rainfall) OVER(PARTITION BY region ORDER BY date ROWS BETWEEN 3 PRECEDING AND CURRENT ROW) as avg_rainfall FROM Rainfall_Regions WHERE date >= DATEADD(month, -3, CURRENT_DATE); |
What is the total revenue generated from fair trade products in France? | CREATE TABLE products (product_id INT,name VARCHAR(100),category VARCHAR(50),price DECIMAL(5,2),fair_trade BOOLEAN);CREATE TABLE sales (sale_id INT,product_id INT,quantity INT,sale_date DATE);CREATE VIEW sales_summary AS SELECT product_id,SUM(quantity) as total_sold FROM sales GROUP BY product_id; | SELECT SUM(sales.quantity * products.price) as total_revenue FROM sales INNER JOIN products ON sales.product_id = products.product_id WHERE products.fair_trade = true AND products.category <> '' GROUP BY products.category HAVING products.category = 'France'; |
What is the most popular movie in the 'Action' genre? | CREATE TABLE movies (id INT,title VARCHAR(255),genre VARCHAR(255),budget DECIMAL(10,2)); INSERT INTO movies (id,title,genre,budget) VALUES (1,'Movie A','Action',8000000.00),(2,'Movie B','Comedy',4000000.00),(3,'Movie C','Action',9000000.00); CREATE TABLE movie_viewers (movie_id INT,viewer_id INT); INSERT INTO movie_viewers (movie_id,viewer_id) VALUES (1,1),(2,1),(3,2),(3,3); | SELECT movies.title, COUNT(movie_viewers.movie_id) AS total FROM movies JOIN movie_viewers ON movies.id = movie_viewers.movie_id WHERE genre = 'Action' GROUP BY movies.title ORDER BY total DESC LIMIT 1; |
What is the average hotel rating in each city for a specific year? | CREATE TABLE Hotels (Hotel_ID INT,Hotel_Name VARCHAR(50),City VARCHAR(30)); INSERT INTO Hotels (Hotel_ID,Hotel_Name,City) VALUES (1,'HotelA','CityA'),(2,'HotelB','CityB'),(3,'HotelC','CityA'); CREATE TABLE Ratings (Rating_ID INT,Hotel_ID INT,Rating INT,Visit_Year INT); INSERT INTO Ratings (Rating_ID,Hotel_ID,Rating,Visit_Year) VALUES (1,1,4,2019),(2,1,4,2020),(3,2,5,2019),(4,2,5,2020),(5,3,3,2019),(6,3,3,2020); | SELECT H.City, V.Visit_Year, AVG(R.Rating) AS Average_Rating FROM Ratings R JOIN Hotels H ON R.Hotel_ID = H.Hotel_ID JOIN (SELECT Hotel_ID, MAX(Visit_Year) AS Visit_Year FROM Ratings GROUP BY Hotel_ID) V ON R.Hotel_ID = V.Hotel_ID AND R.Visit_Year = V.Visit_Year GROUP BY H.City, V.Visit_Year; |
How many roads are there in each state in the 'state_roads' table? | CREATE TABLE state_roads (road_id INT,road_name VARCHAR(50),state VARCHAR(50),length DECIMAL(10,2)); | SELECT state, COUNT(*) FROM state_roads GROUP BY state; |
Insert data into the artifact table | CREATE TABLE Artifacts (ArtifactID INT PRIMARY KEY,SiteID INT,ArtifactName VARCHAR(255),Description TEXT,Material VARCHAR(255),DateFound DATE); INSERT INTO Artifacts (ArtifactID,SiteID,ArtifactName,Description,Material,DateFound) VALUES (1,1,'Fresco of Neptune','Depicts the Roman god Neptune','Plaster','1962-05-14'); | INSERT INTO Artifacts (ArtifactID, SiteID, ArtifactName, Description, Material, DateFound) VALUES (1, 1, 'Fresco of Neptune', 'Depicts the Roman god Neptune', 'Plaster', '1962-05-14'); |
Minimum how many solar panels are installed in buildings located in Australia? | CREATE TABLE solar_panels (building_id INT,quantity INT); CREATE TABLE buildings (id INT,country TEXT); | SELECT MIN(quantity) FROM solar_panels JOIN buildings ON solar_panels.building_id = buildings.id WHERE country = 'Australia'; |
What is the maximum number of views for a video produced in 2021 by a creator from Asia? | CREATE TABLE videos (title VARCHAR(255),release_year INT,views INT,creator VARCHAR(255),region VARCHAR(255)); INSERT INTO videos (title,release_year,views,creator,region) VALUES ('Video1',2021,10000,'Creator1','Asia'),('Video2',2021,8000,'Creator2','Europe'),('Video3',2021,12000,'Creator3','Asia'),('Video4',2020,9000,'Creator4','America'),('Video5',2020,7000,'Creator5','Asia'); | SELECT MAX(views) FROM videos WHERE release_year = 2021 AND region = 'Asia'; |
What is the number of refugees who have received food assistance in the past 6 months from the 'Food for Life' program, grouped by their region? | CREATE TABLE refugees(id INT,region TEXT,assistance TEXT,date DATE); INSERT INTO refugees(id,region,assistance,date) VALUES (1,'Africa','Food for Life','2022-01-01'),(2,'Asia','Health Care','2022-02-01'),(3,'Africa','Food for Life','2022-06-01'); | SELECT region, COUNT(*) FROM refugees WHERE assistance = 'Food for Life' AND date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH) GROUP BY region; |
How many workers are there in each union, including unions with no members? | CREATE TABLE unions (id INT,name TEXT,member_count INT); INSERT INTO unions (id,name,member_count) VALUES (1,'Union A',50),(2,'Union B',0); | SELECT name, NVL(member_count, 0) FROM unions; |
Which artists are from Africa? | CREATE TABLE artists (id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO artists (id,name,country) VALUES (1,'John Doe','USA'),(2,'Jane Smith','Nigeria'),(3,'Alice Johnson','South Africa'); | SELECT name FROM artists WHERE country IN ('Nigeria', 'South Africa'); |
List all ingredients and their suppliers in the ingredients and supplier_ingredients tables that are not organic. | CREATE TABLE ingredients (ingredient_id INT,ingredient_name TEXT); CREATE TABLE supplier_ingredients (supplier_id INT,ingredient_id INT,is_organic BOOLEAN); | SELECT ingredients.ingredient_name, supplier_ingredients.supplier_id FROM ingredients LEFT JOIN supplier_ingredients ON ingredients.ingredient_id = supplier_ingredients.ingredient_id WHERE supplier_ingredients.is_organic IS NULL; |
Create a new table named 'regulatory_compliance' with columns 'country', 'carrier', 'law', and 'compliance_date'. | CREATE TABLE regulatory_compliance (country VARCHAR(50),carrier VARCHAR(50),law VARCHAR(50),compliance_date DATE); | INSERT INTO regulatory_compliance (country, carrier, law, compliance_date) VALUES ('Brazil', 'Vivo', 'Data Privacy Act', '2023-05-01'); |
What is the total size of protected habitats for each animal type? | CREATE TABLE Protected_Habitats (id INT,animal_type VARCHAR(50),size INT); | SELECT animal_type, SUM(size) FROM Protected_Habitats GROUP BY animal_type; |
How many cultural heritage sites are there in Japan's Hokkaido region? | CREATE TABLE sites (id INT,name TEXT,country TEXT,region TEXT); INSERT INTO sites (id,name,country,region) VALUES (1,'Site1','Japan','Hokkaido'),(2,'Site2','Japan','Hokkaido'); | SELECT COUNT(*) FROM sites WHERE country = 'Japan' AND region = 'Hokkaido'; |
What is the total number of marine protected areas in Asia and Europe? | CREATE TABLE marine_protected_areas (id INT,name TEXT,location TEXT,size FLOAT); INSERT INTO marine_protected_areas (id,name,location,size) VALUES (1,'Great Barrier Reef','Australia',344400.0); INSERT INTO marine_protected_areas (id,name,location,size) VALUES (2,'Galapagos Marine Reserve','Ecuador',133000.0); INSERT INTO marine_protected_areas (id,name,location,size) VALUES (3,'Nordvest-Spidsbergen National Park','Norway',97600.0); | SELECT SUM(size) FROM marine_protected_areas WHERE location IN ('Asia', 'Europe'); |
What are the names and quantities of chemicals produced by the 'Chemical Plant A' located in 'California'? | CREATE TABLE Chemical_Plant (plant_name VARCHAR(255),location VARCHAR(255),chemical VARCHAR(255),quantity INT);INSERT INTO Chemical_Plant (plant_name,location,chemical,quantity) VALUES ('Chemical Plant A','California','Ammonia',500),('Chemical Plant A','California','Sodium Hydroxide',800); | SELECT chemical, quantity FROM Chemical_Plant WHERE plant_name = 'Chemical Plant A' AND location = 'California'; |
What is the total CO2 emission for each mode of transportation in Asia by year? | CREATE TABLE Emissions (Emission_ID INT,Transportation_Mode VARCHAR(30),Year INT,CO2_Emissions INT); INSERT INTO Emissions (Emission_ID,Transportation_Mode,Year,CO2_Emissions) VALUES (1,'Plane',2019,1000),(2,'Train',2019,500),(3,'Bus',2019,300),(4,'Plane',2020,1200),(5,'Train',2020,600),(6,'Bus',2020,350); CREATE TABLE Transportation (Transportation_Mode VARCHAR(30),Continent VARCHAR(30)); INSERT INTO Transportation (Transportation_Mode,Continent) VALUES ('Plane','Asia'),('Train','Asia'),('Bus','Asia'); | SELECT T.Continent, E.Year, T.Transportation_Mode, SUM(E.CO2_Emissions) AS Total_Emissions FROM Emissions E JOIN Transportation T ON E.Transportation_Mode = T.Transportation_Mode WHERE T.Continent = 'Asia' GROUP BY T.Continent, E.Year, T.Transportation_Mode ORDER BY E.Year; |
What is the next carbon offset quantity for each project, ordered by offset_quantity in descending order? | CREATE TABLE carbon_offset_projects (id INT,project_name VARCHAR(255),location VARCHAR(255),offset_quantity INT,start_date DATE); INSERT INTO carbon_offset_projects (id,project_name,location,offset_quantity,start_date) VALUES (1,'Forest Conservation','Amazon Rainforest',10000,'2020-01-01'); INSERT INTO carbon_offset_projects (id,project_name,location,offset_quantity,start_date) VALUES (2,'Soil Carbon Sequestration','Mississippi Delta',25000,'2019-06-15'); | SELECT project_name, location, offset_quantity, start_date, LEAD(offset_quantity) OVER(ORDER BY offset_quantity DESC) as next_offset FROM carbon_offset_projects; |
What is the number of employees in the factories, partitioned by material type and ordered by the most number of employees? | CREATE TABLE factories (factory_id INT,material_type VARCHAR(255),num_employees INT); INSERT INTO factories (factory_id,material_type,num_employees) VALUES (1,'Organic cotton',200),(2,'Conventional cotton',300),(3,'Recycled polyester',150),(4,'Organic cotton',100); | SELECT material_type, COUNT(*) as num_factories, AVG(num_employees) as avg_num_employees FROM factories GROUP BY material_type ORDER BY avg_num_employees DESC; |
What is the total weight of shipments to a given country from all continents? | CREATE TABLE shipments (id INT,origin_continent VARCHAR(255),destination_country VARCHAR(255),weight FLOAT); INSERT INTO shipments (id,origin_continent,destination_country,weight) VALUES (1,'Asia','Australia',700.0),(2,'Africa','Australia',800.0); | SELECT destination_country, SUM(weight) as total_weight FROM shipments GROUP BY destination_country; |
Update the 'rare_earth_market' table to reflect the current market price of Dysprosium as $210 per kg. | CREATE TABLE rare_earth_market (id INT,element TEXT,current_price FLOAT); | UPDATE rare_earth_market SET current_price = 210 WHERE element = 'Dysprosium'; |
How many building permits were issued for residential buildings in the 'building_permits' table? | CREATE TABLE building_permits (permit_number INT,building_type VARCHAR(255)); | select count(*) as residential_permits from building_permits where building_type = 'residential'; |
Which cultural heritage sites in Italy have more than 30000 visitors in 2021? | CREATE TABLE sites (site_id INT,site_name VARCHAR(50),country VARCHAR(50),year INT,visitors INT); INSERT INTO sites (site_id,site_name,country,year,visitors) VALUES (1,'Roman Colosseum','Italy',2021,45000),(2,'Leaning Tower of Pisa','Italy',2021,32000),(3,'Florence Cathedral','Italy',2021,38000),(4,'Spanish Steps','Italy',2021,29000); | SELECT site_name, visitors FROM sites WHERE country = 'Italy' AND year = 2021 AND visitors > 30000; |
Find the number of sustainable tourism businesses in India with a 5-star rating. | CREATE TABLE businesses (business_id INT,country VARCHAR(50),rating INT,sustainability_level VARCHAR(10)); INSERT INTO businesses (business_id,country,rating,sustainability_level) VALUES (1,'India',5,'sustainable'),(2,'India',4,'sustainable'),(3,'Brazil',5,'not sustainable'); | SELECT COUNT(*) FROM businesses bs WHERE bs.country = 'India' AND bs.rating = 5 AND bs.sustainability_level = 'sustainable'; |
What is the maximum frequency of content for each genre in the media_content table? | CREATE TABLE media_content (id INT,genre VARCHAR(50),frequency INT); INSERT INTO media_content (id,genre,frequency) VALUES (1,'Movie',100),(2,'TV Show',30),(3,'Documentary',40); | SELECT genre, MAX(frequency) FROM media_content GROUP BY genre; |
What are the top 5 most common vulnerabilities by severity in the last month? | CREATE TABLE vulnerabilities (id INT,title TEXT,severity TEXT,date_reported DATE); INSERT INTO vulnerabilities (id,title,severity,date_reported) VALUES (1,'SQL Injection Vulnerability','High','2022-01-02'),(2,'Cross-Site Scripting (XSS)','Medium','2022-01-05'),(3,'Insecure Direct Object References','Low','2022-01-10'),(4,'Security Misconfiguration','High','2022-01-15'),(5,'Missing Function Level Access Control','Medium','2022-01-20'); | SELECT severity, title, COUNT(*) as count FROM vulnerabilities WHERE date_reported >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY severity, title ORDER BY count DESC LIMIT 5; |
What is the average salary of workers in each factory, and the number of workers in each factory. | CREATE TABLE factories (factory_id INT,name TEXT,location TEXT,avg_salary FLOAT,num_workers INT); | SELECT factory_id, name, AVG(avg_salary) as avg_salary, SUM(num_workers) as total_workers FROM factories GROUP BY factory_id; |
Delete the 'Director of Engineering' job title from the JobTitle table | CREATE TABLE JobTitle (JobTitleID INT PRIMARY KEY,JobTitleName VARCHAR(50)); | DELETE FROM JobTitle WHERE JobTitleName = 'Director of Engineering'; |
Show players who joined in the same month as the player with the latest join date in 'gaming_players' table | CREATE TABLE gaming_players (player_id INT,name VARCHAR(50),join_date DATE); | SELECT * FROM gaming_players WHERE MONTH(join_date) = (SELECT MONTH(MAX(join_date)) FROM gaming_players); |
What is the average duration of membership for each membership type? | CREATE TABLE gym_memberships (id INT,member_name VARCHAR(50),start_date DATE,end_date DATE,membership_type VARCHAR(50),price DECIMAL(5,2)); | SELECT membership_type, AVG(DATEDIFF(end_date, start_date))/30 AS avg_duration FROM gym_memberships GROUP BY membership_type; |
What is the total quantity of ingredients used in the past week, broken down by ingredient? | CREATE TABLE menu (menu_id INT,item_name VARCHAR(255),category VARCHAR(255),price DECIMAL(5,2),inventory_count INT,last_updated TIMESTAMP);CREATE TABLE inventory (ingredient_id INT,ingredient_name VARCHAR(255),quantity INT,reorder_threshold INT,last_updated TIMESTAMP);CREATE TABLE inventory_transactions (transaction_id INT,ingredient_id INT,transaction_type VARCHAR(50),quantity INT,transaction_date TIMESTAMP,PRIMARY KEY (transaction_id),FOREIGN KEY (ingredient_id) REFERENCES inventory(ingredient_id)); | SELECT ingredient_name, SUM(quantity) as total_quantity FROM inventory_transactions JOIN inventory ON inventory_transactions.ingredient_id = inventory.ingredient_id WHERE transaction_date >= CURRENT_DATE - INTERVAL '7 days' GROUP BY ingredient_name; |
Delete all menu items with a quantity of 0. | CREATE TABLE Menu (id INT,item VARCHAR(50),price DECIMAL(5,2),qty INT); INSERT INTO Menu (id,item,price,qty) VALUES (1,'Steak',25.99,10),(2,'Salad',15.99,0); | DELETE FROM Menu WHERE qty = 0; |
Find the mining operations with an environmental impact score above the average. | CREATE TABLE mining_operations (id INT,name VARCHAR(50),environmental_impact_score INT); | SELECT name FROM mining_operations WHERE environmental_impact_score > (SELECT AVG(environmental_impact_score) FROM mining_operations); |
What is the maximum donation amount made in the month of July? | CREATE TABLE Donations (DonationID INT,DonationDate DATE,DonationAmount DECIMAL); INSERT INTO Donations (DonationID,DonationDate,DonationAmount) VALUES (1,'2022-07-01',200.00),(2,'2022-07-15',300.00); | SELECT MAX(DonationAmount) FROM Donations WHERE MONTH(DonationDate) = 7; |
Create a new table for athlete demographics | CREATE TABLE athletes (athlete_id INT,team_id INT,name VARCHAR(50)); | CREATE TABLE athlete_demographics (demographics_id INT, athlete_id INT, age INT, gender VARCHAR(10), nationality VARCHAR(50)); |
Determine the number of bioprocess engineering jobs in the UK, Germany, and Japan. | CREATE SCHEMA if not exists bioprocess;CREATE TABLE if not exists bioprocess.jobs (id INT,title VARCHAR(50),country VARCHAR(50)); INSERT INTO bioprocess.jobs (id,title,country) VALUES (1,'JobA','France'),(2,'JobB','Spain'),(3,'JobC','France'),(4,'JobD','USA'),(5,'JobE','Spain'),(6,'JobF','UK'),(7,'JobG','Germany'),(8,'JobH','Japan'); | SELECT country, COUNT(*) FROM bioprocess.jobs WHERE country IN ('UK', 'Germany', 'Japan') GROUP BY country; |
What are the top 3 countries by total sales for the genre 'Pop'? | CREATE TABLE sales (genre VARCHAR(255),country VARCHAR(255),sales FLOAT); CREATE TABLE genres (genre VARCHAR(255)); INSERT INTO genres (genre) VALUES ('Pop'),('Rock'),('Jazz'),('Classical'); INSERT INTO sales (genre,country,sales) VALUES ('Pop','United States',1000000),('Pop','Canada',750000),('Pop','Mexico',600000),('Rock','United States',1200000),('Rock','Canada',800000),('Rock','United Kingdom',900000),('Jazz','France',500000),('Jazz','United States',400000),('Classical','Germany',350000),('Classical','Austria',300000); | SELECT s.country, SUM(s.sales) as total_sales FROM sales s JOIN genres g ON s.genre = g.genre WHERE s.genre = 'Pop' GROUP BY s.country ORDER BY total_sales DESC LIMIT 3; |
Find the mining sites with the highest resource extraction by type | CREATE TABLE mining_site (id INT,name VARCHAR(255),resource VARCHAR(255),amount INT); INSERT INTO mining_site (id,name,resource,amount) VALUES (1,'Site A','Gold',150),(2,'Site B','Silver',200),(3,'Site A','Coal',250),(4,'Site C','Gold',175),(5,'Site C','Silver',225),(6,'Site D','Coal',300); | SELECT ms.name as site, ms.resource as resource, MAX(ms.amount) as max_resource_extraction FROM mining_site ms GROUP BY ms.name, ms.resource; |
What is the total number of streams for each genre on Spotify? | CREATE TABLE Artists (ArtistID INT,ArtistName VARCHAR(100),Genre VARCHAR(50)); INSERT INTO Artists (ArtistID,ArtistName,Genre) VALUES (5,'Ariana Grande','Pop'),(6,'Drake','Rap/Hip-Hop'); CREATE TABLE StreamingPlatforms (PlatformID INT,PlatformName VARCHAR(50)); INSERT INTO StreamingPlatforms (PlatformID,PlatformName) VALUES (1,'Spotify'),(2,'Apple Music'); CREATE TABLE SongsStreams (SongID INT,ArtistID INT,PlatformID INT,StreamCount INT); INSERT INTO SongsStreams (SongID,ArtistID,PlatformID,StreamCount) VALUES (6,5,1,3000000),(7,6,1,2000000); | SELECT a.Genre, SUM(ss.StreamCount) FROM Artists a JOIN SongsStreams ss ON a.ArtistID = ss.ArtistID JOIN StreamingPlatforms sp ON ss.PlatformID = sp.PlatformID WHERE sp.PlatformName = 'Spotify' GROUP BY a.Genre; |
How many agricultural innovation projects were implemented in India between 2015 and 2018? | CREATE TABLE Agricultural_Innovation (id INT,country VARCHAR(50),year INT,type VARCHAR(50)); INSERT INTO Agricultural_Innovation (id,country,year,type) VALUES (1,'India',2015,'Implemented'),(2,'India',2016,'Planned'),(3,'India',2018,'Implemented'); | SELECT COUNT(*) FROM Agricultural_Innovation WHERE country = 'India' AND type = 'Implemented' AND year BETWEEN 2015 AND 2018; |
What is the minimum mass of spacecrafts manufactured by Orbital Sciences that have been launched? | CREATE TABLE Spacecrafts (id INT,name VARCHAR(100),manufacturer VARCHAR(100),mass FLOAT,launched BOOLEAN); INSERT INTO Spacecrafts (id,name,manufacturer,mass,launched) VALUES (1,'OrbitalShip 1','Orbital Sciences',1000,true),(2,'OrbitalShip 2','Orbital Sciences',2000,false); | SELECT MIN(mass) FROM Spacecrafts WHERE manufacturer = 'Orbital Sciences' AND launched = true; |
Delete the record with id 2 from the "plants" table | CREATE TABLE plants (id INT PRIMARY KEY,name VARCHAR(100),family VARCHAR(100),region VARCHAR(100),population INT); | WITH del AS (DELETE FROM plants WHERE id = 2 RETURNING id) SELECT id FROM del; |
What is the total weight of 'bananas' and 'oranges' in the 'inventory' table? | CREATE TABLE inventory (product VARCHAR(255),weight FLOAT); INSERT INTO inventory (product,weight) VALUES ('Apples',500.0),('Bananas',300.0),('Oranges',600.0),('Bananas',400.0),('Oranges',700.0); | SELECT SUM(IIF(product IN ('Bananas', 'Oranges'), weight, 0)) as total_weight FROM inventory; |
List the top 3 salaries in the Sales department, in descending order. | CREATE TABLE Employees (EmployeeID INT,Name VARCHAR(50),Department VARCHAR(50),Salary FLOAT); INSERT INTO Employees (EmployeeID,Name,Department,Salary) VALUES (1,'John Doe','IT',75000.00),(2,'Jane Smith','IT',80000.00),(3,'Mike Johnson','Sales',90000.00),(4,'Laura Jones','Sales',95000.00),(5,'Alex Brown','Sales',85000.00); | SELECT * FROM (SELECT ROW_NUMBER() OVER (PARTITION BY Department ORDER BY Salary DESC) AS rn, EmployeeID, Name, Department, Salary FROM Employees) t WHERE rn <= 3 AND Department = 'Sales'; |
What is the average rating (on a scale of 1 to 5) for each fashion brand? | CREATE TABLE customer_reviews(brand VARCHAR(50),rating INT); INSERT INTO customer_reviews(brand,rating) VALUES('BrandA',4),('BrandB',3),('BrandC',5); | SELECT brand, AVG(rating) FROM customer_reviews GROUP BY brand; |
What is the total revenue generated from route optimization for customers in Canada in H1 2022? | CREATE TABLE RouteOptimization (id INT,customer VARCHAR(255),revenue FLOAT,country VARCHAR(255),half INT,year INT); | SELECT SUM(revenue) FROM RouteOptimization WHERE country = 'Canada' AND half = 1 AND year = 2022; |
What are the details of intelligence operations in the Middle East? | CREATE TABLE intel_ops (id INT,region VARCHAR(255),operation VARCHAR(255),budget DECIMAL(10,2)); INSERT INTO intel_ops (id,region,operation,budget) VALUES (1,'Middle East','SIGINT',3000000),(2,'Europe','HUMINT',4000000),(3,'Middle East','GEOINT',5000000),(4,'Americas','OSINT',6000000); | SELECT * FROM intel_ops WHERE region = 'Middle East'; |
Delete all incidents involving the Boeing 737 MAX | CREATE TABLE Incidents (IncidentID INT,IncidentDate DATE,AircraftModel VARCHAR(50),IncidentType VARCHAR(50),Description TEXT,NumberOfPeople INT,Fatalities INT); INSERT INTO Incidents (IncidentID,IncidentDate,AircraftModel,IncidentType,Description,NumberOfPeople,Fatalities) VALUES (1,'2021-01-01','B737 MAX','Technical','Engine failure',150,0); INSERT INTO Incidents (IncidentID,IncidentDate,AircraftModel,IncidentType,Description,NumberOfPeople,Fatalities) VALUES (2,'2021-02-10','B787','Collision','Ran into birds',250,0); | DELETE FROM Incidents WHERE AircraftModel = 'B737 MAX'; |
Delete movies with a release date before 2000 from the 'movies' table | CREATE TABLE movies (id INT,title TEXT,release_year INT); | DELETE FROM movies WHERE release_year < 2000; |
What is the total waste for each item? | CREATE TABLE waste (waste_id INT,item_name VARCHAR(50),waste_amount DECIMAL(10,2)); INSERT INTO waste (waste_id,item_name,waste_amount) VALUES (1,'Tomato',100.00),(2,'Chicken Breast',250.00),(3,'Vanilla Ice Cream',150.00); | SELECT item_name, SUM(waste_amount) FROM waste GROUP BY item_name; |
What is the percentage of accessible subway stations in Paris? | CREATE TABLE subway_stations_paris(station_name VARCHAR(50),accessible BOOLEAN); INSERT INTO subway_stations_paris (station_name,accessible) VALUES ('Station A',true),('Station B',false); | SELECT (COUNT(*) FILTER (WHERE accessible = true)) * 100.0 / COUNT(*) AS percentage_accessible FROM subway_stations_paris; |
What is the minimum and maximum salary for workers in unions advocating for workplace safety? | CREATE TABLE unions (id INT,name VARCHAR(50),location VARCHAR(50),type VARCHAR(50)); CREATE TABLE workers (id INT,union_id INT,salary DECIMAL(10,2)); INSERT INTO unions (id,name,location,type) VALUES (1,'International Association of Fire Fighters','USA','Workplace Safety'); INSERT INTO unions (id,name,location,type) VALUES (2,'Maritime Union of Australia','Australia','Workplace Safety'); INSERT INTO workers (id,union_id,salary) VALUES (1,1,50000); INSERT INTO workers (id,union_id,salary) VALUES (2,1,55000); INSERT INTO workers (id,union_id,salary) VALUES (3,2,70000); INSERT INTO workers (id,union_id,salary) VALUES (4,2,75000); | SELECT MIN(salary) AS min_salary, MAX(salary) AS max_salary FROM workers JOIN unions ON workers.union_id = unions.id WHERE unions.type = 'Workplace Safety'; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.