instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the average hydroelectric power generation in Norway and Sweden?
CREATE TABLE hydro_power (country VARCHAR(20),generation FLOAT); INSERT INTO hydro_power (country,generation) VALUES ('Norway',128.5),('Norway',129.1),('Sweden',98.7),('Sweden',99.3);
SELECT AVG(generation) as avg_generation, country FROM hydro_power GROUP BY country;
List all the projects implemented in Nepal, their implementing organizations, and the total budget for each project, sorted by the implementing organizations.
CREATE TABLE projects (id INT,name TEXT,country TEXT,budget INT); INSERT INTO projects VALUES (1,'School Rebuilding','Nepal',100000); CREATE TABLE organizations_projects (organization_id INT,project_id INT); INSERT INTO organizations_projects VALUES (1,1); CREATE TABLE organizations (id INT,name TEXT); INSERT INTO organizations VALUES (1,'UNICEF');
SELECT o.name, p.name, SUM(p.budget) FROM projects p INNER JOIN organizations_projects op ON p.id = op.project_id INNER JOIN organizations o ON op.organization_id = o.id WHERE p.country = 'Nepal' GROUP BY o.id, p.name ORDER BY o.name;
What is the average amount of aid provided per refugee in the Middle East?
CREATE TABLE refugees (id INT,name TEXT,region TEXT); CREATE TABLE aid_distributions (id INT,refugee_id INT,amount DECIMAL); INSERT INTO refugees (id,name,region) VALUES (1,'Ahmed','Middle East'),(2,'Fatima','Middle East'),(3,'Jose','South America'); INSERT INTO aid_distributions (id,refugee_id,amount) VALUES (1,1,100.00),(2,1,150.00),(3,2,200.00);
SELECT AVG(ad.amount) as avg_aid_per_refugee FROM refugees r INNER JOIN aid_distributions ad ON r.id = ad.refugee_id WHERE r.region = 'Middle East';
Which users live in 'North America' and are in the 'Older' age group?
CREATE TABLE users (id INT PRIMARY KEY,name VARCHAR(50),age INT,city VARCHAR(50),region VARCHAR(50)); INSERT INTO users (id,name,age,city,region) VALUES (1,'Alice',30,'New York','North America'); INSERT INTO users (id,name,age,city,region) VALUES (2,'Bob',25,'San Francisco','North America'); INSERT INTO users (id,name,age,city,region) VALUES (3,'Charlie',65,'Los Angeles','North America');
SELECT name FROM users WHERE region = 'North America' AND (CASE WHEN age > 30 THEN 'Older' ELSE 'Younger' END) = 'Older';
Find the number of accessible and non-accessible vehicles in the wheelchair-friendly fleet
CREATE TABLE wheelchair_friendly_fleet (vehicle_id INT,vehicle_type VARCHAR(10),accessible BOOLEAN); INSERT INTO wheelchair_friendly_fleet (vehicle_id,vehicle_type,accessible) VALUES (5,'Minibus',true),(6,'Van',true),(7,'Minibus',false),(8,'Tuk-tuk',true);
SELECT vehicle_type, SUM(accessible) as number_of_accessible_vehicles, SUM(NOT accessible) as number_of_non_accessible_vehicles FROM wheelchair_friendly_fleet GROUP BY vehicle_type;
What are the names of all routes that have a bus and a subway service?
CREATE TABLE Routes (RouteID int,RouteName varchar(50),ServiceType varchar(50)); INSERT INTO Routes VALUES (1,'Route 1','Bus'); INSERT INTO Routes VALUES (2,'Route 2','Subway'); INSERT INTO Routes VALUES (3,'Route 3','Bus and Subway');
SELECT RouteName FROM Routes WHERE ServiceType = 'Bus' INTERSECT SELECT RouteName FROM Routes WHERE ServiceType = 'Subway';
Which routes are wheelchair accessible in a given city?
CREATE TABLE routes (id INT,name VARCHAR(255),type VARCHAR(255),city VARCHAR(255),length INT,wheelchair_accessible BOOLEAN); INSERT INTO routes (id,name,type,city,length,wheelchair_accessible) VALUES (1,'10','Bus','NYC',25000,true),(2,'20','Train','NYC',50000,true),(3,'30','Tram','Paris',30000,false),(4,'40','Subway','London',40000,true),(5,'50','Ferry','Sydney',15000,true);
SELECT r.name, r.city, CASE WHEN r.wheelchair_accessible THEN 'Yes' ELSE 'No' END as Accessible FROM routes r WHERE r.city = 'NYC';
Identify the number of unique garment categories in the 'circular_economy' table.
CREATE TABLE circular_economy (id INT,garment VARCHAR(20),garment_category VARCHAR(20)); INSERT INTO circular_economy (id,garment,garment_category) VALUES (1,'recycled_sweater','sweaters'),(2,'upcycled_jeans','jeans'),(3,'refurbished_shoes','shoes'),(4,'vintage_dress','dresses');
SELECT COUNT(DISTINCT garment_category) FROM circular_economy;
What are the top 3 countries with the most users who have interacted with sponsored posts in the last month?
CREATE TABLE sponsored_posts (post_id INT,user_id INT,country VARCHAR(50),interaction_date DATE); INSERT INTO sponsored_posts (post_id,user_id,country,interaction_date) VALUES (1,123,'USA','2021-08-01');
SELECT country, COUNT(user_id) as interaction_count FROM sponsored_posts WHERE interaction_date >= DATEADD(month, -1, GETDATE()) GROUP BY country ORDER BY interaction_count DESC LIMIT 3;
Insert a new record for a donation of $1000 made by an individual donor named "John Doe" on January 1, 2022.
CREATE TABLE donations (id INT,donor_id INT,donation_date DATE,amount_donated DECIMAL(10,2)); CREATE TABLE donors (id INT,name TEXT);
INSERT INTO donations (id, donor_id, donation_date, amount_donated) VALUES (1, (SELECT id FROM donors WHERE name = 'John Doe' LIMIT 1), '2022-01-01', 1000); INSERT INTO donors (id, name) VALUES (1, 'John Doe') ON DUPLICATE KEY UPDATE id = id;
How many food safety records were updated in Q1 of 2022?
CREATE TABLE FoodSafetyRecords (RecordID INT,UpdateDate DATE); INSERT INTO FoodSafetyRecords (RecordID,UpdateDate) VALUES (1,'2022-01-01'),(2,'2022-01-05'),(3,'2022-02-10'),(4,'2022-03-20'),(5,'2022-03-30');
SELECT COUNT(*) FROM FoodSafetyRecords WHERE UpdateDate BETWEEN '2022-01-01' AND '2022-03-31';
What are the names of startups that have received funding from investors with over 3 million funds, and are involved in Genetic Research or Bioprocess Engineering?
CREATE TABLE public.investors (id SERIAL PRIMARY KEY,name VARCHAR(100),type VARCHAR(50),funds INTEGER); CREATE TABLE public.investments (id SERIAL PRIMARY KEY,investor_id INTEGER,startup_id INTEGER); CREATE TABLE public.startups (id SERIAL PRIMARY KEY,name VARCHAR(100),industry VARCHAR(50),funding INTEGER);
SELECT startups.name FROM public.startups JOIN public.investments ON startups.id = investments.startup_id JOIN public.investors ON investments.investor_id = investors.id WHERE (startups.industry = 'Genetic Research' OR startups.industry = 'Bioprocess Engineering') AND investors.funds > 3000000;
Who are the researchers that have contributed to the 'gene sequencing' project?
CREATE TABLE researchers (id INT,name VARCHAR(50),project VARCHAR(50)); INSERT INTO researchers (id,name,project) VALUES (1,'Alice','gene sequencing'),(2,'Bob','biosensor development'),(3,'Charlie','gene sequencing');
SELECT name FROM researchers WHERE project = 'gene sequencing';
What are the total research grant funds awarded to faculty members in the Mathematics department, excluding grants awarded to faculty members named Karen?
CREATE SCHEMA research;CREATE TABLE grants(faculty_name TEXT,department TEXT,amount INTEGER);INSERT INTO grants(faculty_name,department,amount)VALUES('Karen','Mathematics',150000),('Larry','Physics',200000),('Melissa','Physics',50000);
SELECT SUM(amount) FROM research.grants WHERE department='Mathematics' AND faculty_name<>'Karen';
What is the minimum amount of funding received by a graduate student in the Engineering department from research grants?
CREATE TABLE graduate_students (id INT,name VARCHAR(50),department VARCHAR(50)); CREATE TABLE research_grants (id INT,graduate_student_id INT,amount DECIMAL(10,2));
SELECT MIN(rg.amount) FROM research_grants rg JOIN graduate_students gs ON rg.graduate_student_id = gs.id WHERE gs.department = 'Engineering';
How many green buildings are there in the green_buildings table?
CREATE TABLE IF NOT EXISTS green_buildings (building_id INT,building_name VARCHAR(255),PRIMARY KEY (building_id)); INSERT INTO green_buildings (building_id,building_name) VALUES (1,'Eco-Tower'),(2,'Green Heights'),(3,'Sustainable Haven');
SELECT COUNT(*) FROM green_buildings;
Insert a new record into the "buildings" table
CREATE TABLE buildings (id INT PRIMARY KEY,name VARCHAR(255),city VARCHAR(255),country VARCHAR(255),built_year INT);
INSERT INTO buildings (id, name, city, country, built_year) VALUES (1, 'GreenHub', 'San Francisco', 'USA', 2020);
What is the average CO2 emission reduction of green building projects in the 'GreenBuildingProjects' table, grouped by reduction_type?
CREATE TABLE GreenBuildingProjects (id INT,reduction_type VARCHAR(50),co2_reduction FLOAT); INSERT INTO GreenBuildingProjects (id,reduction_type,co2_reduction) VALUES (1,'Insulation',50.0),(2,'Lighting',75.0),(3,'Insulation',60.0);
SELECT reduction_type, AVG(co2_reduction) FROM GreenBuildingProjects GROUP BY reduction_type;
Which countries have the highest average spending on virtual tours per user?
CREATE TABLE Users (UserID INT,CountryID INT); INSERT INTO Users (UserID,CountryID) VALUES (1,1),(2,1),(3,2),(4,2),(5,3),(6,3),(7,4),(8,4); CREATE TABLE Spending (SpendingID INT,UserID INT,VirtualTourID INT,Amount DECIMAL(10,2)); INSERT INTO Spending (SpendingID,UserID,VirtualTourID,Amount) VALUES (1,1,1,50),(2,1,2,75),(3,2,1,60),(4,2,3,80),(5,3,4,90),(6,3,5,100),(7,5,6,70),(8,5,7,85),(9,6,8,95),(10,6,9,100),(11,7,10,80),(12,7,11,90),(13,8,12,75),(14,8,13,85);
SELECT U.CountryName, AVG(S.Amount) as AvgSpending FROM Users U INNER JOIN Spending S ON U.UserID = S.UserID INNER JOIN VirtualTours VT ON S.VirtualTourID = VT.VirtualTourID GROUP BY U.CountryID ORDER BY AvgSpending DESC;
What are the top 3 most common mediums used by artists from Italy?
CREATE TABLE ArtWorks (ArtworkID int,Title varchar(100),Medium varchar(100),ArtistID int);
SELECT Medium, COUNT(ArtworkID) FROM ArtWorks
What is the total budget allocated for each resource category in the 'resource_categories' table?
CREATE TABLE resource_categories (resource_category TEXT,allocated_budget FLOAT);
SELECT resource_category, SUM(allocated_budget) as total_allocated_budget FROM resource_categories GROUP BY resource_category;
How many cultural and natural heritage sites are in Asia?
CREATE TABLE Heritage_Sites (Site_ID INT PRIMARY KEY,Name VARCHAR(100),Country VARCHAR(50),Type VARCHAR(50)); INSERT INTO Heritage_Sites (Site_ID,Name,Country,Type) VALUES (1,'Angkor Wat','Cambodia','Cultural'); INSERT INTO Heritage_Sites (Site_ID,Name,Country,Type) VALUES (2,'Machu Picchu','Peru','Cultural'); INSERT INTO Heritage_Sites (Site_ID,Name,Country,Type) VALUES (3,'Great Barrier Reef','Australia','Natural');
SELECT COUNT(*) FROM Heritage_Sites WHERE Country IN ('Cambodia', 'Peru', 'Australia') AND Type IN ('Cultural', 'Natural');
How many public awareness campaigns were launched in February and August in the 'campaigns' schema?
CREATE TABLE campaigns (campaign_id INT,launch_date DATE); INSERT INTO campaigns (campaign_id,launch_date) VALUES (1,'2019-02-01'),(2,'2020-05-15'),(3,'2018-12-31'),(4,'2021-03-20'),(5,'2021-08-01'),(6,'2022-02-10');
SELECT EXTRACT(MONTH FROM launch_date) AS month, COUNT(*) AS campaigns_launched FROM campaigns WHERE EXTRACT(MONTH FROM launch_date) IN (2, 8) GROUP BY month;
Find the maximum construction cost for a project in Germany
CREATE TABLE infrastructure_projects (id INT,name TEXT,location TEXT,construction_cost FLOAT); INSERT INTO infrastructure_projects (id,name,location,construction_cost) VALUES (1,'Brooklyn Bridge','USA',15000000); INSERT INTO infrastructure_projects (id,name,location,construction_cost) VALUES (2,'Chunnel','UK',21000000); INSERT INTO infrastructure_projects (id,name,location,construction_cost) VALUES (3,'Tokyo Tower','Japan',33000000); INSERT INTO infrastructure_projects (id,name,location,construction_cost) VALUES (4,'Brandenburg Gate','Germany',25000000);
SELECT MAX(construction_cost) FROM infrastructure_projects WHERE location = 'Germany';
How many infrastructure projects are there for each 'city'?
CREATE TABLE InfrastructureProjects (id INT,name TEXT,city TEXT,category TEXT,budget FLOAT); INSERT INTO InfrastructureProjects (id,name,city,category,budget) VALUES (1,'Highway 12 Expansion','CityA','Transportation',2000000); INSERT INTO InfrastructureProjects (id,name,city,category,budget) VALUES (2,'Bridgewater Park Pedestrian Path','CityB','Parks',500000); INSERT INTO InfrastructureProjects (id,name,city,category,budget) VALUES (3,'Railway Crossing Upgrade','CityA','Transportation',1500000); INSERT INTO InfrastructureProjects (id,name,city,category,budget) VALUES (4,'New Community Center','CityB','Community',3000000); INSERT INTO InfrastructureProjects (id,name,city,category,budget) VALUES (5,'Wastewater Treatment Plant','CityC','Waste Management',1200000);
SELECT city, COUNT(*) FROM InfrastructureProjects GROUP BY city;
Identify the longest tunnel in each region of the United States, and display the region, tunnel name, and length.
CREATE TABLE tunnels (id INT,tunnel_name VARCHAR(255),region VARCHAR(255),length FLOAT); INSERT INTO tunnels (id,tunnel_name,region,length) VALUES (1,'Hoosac Tunnel','Northeast',24.7),(2,'Cascade Tunnel','Northwest',26.2),(3,'Selmon Crosstown Expressway','Southeast',21.5);
SELECT region, tunnel_name, length FROM tunnels T1 WHERE length = (SELECT MAX(length) FROM tunnels T2 WHERE T2.region = T1.region) ORDER BY region;
What is the maximum resilience score of all infrastructure in the city of Tokyo, Japan?
CREATE TABLE Infrastructure (id INT,type VARCHAR(50),location VARCHAR(50),resilience_score FLOAT);
SELECT MAX(resilience_score) FROM Infrastructure WHERE location = 'Tokyo';
Insert a new record into the "international_visitor_statistics" table for "Japan" with 2021 visit data
CREATE TABLE international_visitor_statistics (id INT PRIMARY KEY,country TEXT,year INT,visitor_count INT);
INSERT INTO international_visitor_statistics (id, country, year, visitor_count) VALUES (1, 'Japan', 2021, 15000000);
Total CO2 emissions for each transportation method in Oceania
CREATE TABLE if not exists transportation (transport_id INT,transport VARCHAR(20),region VARCHAR(50),co2_emission INT); INSERT INTO transportation (transport_id,transport,region,co2_emission) VALUES (1,'Airplane','Oceania',445),(2,'Train','Oceania',14),(3,'Car','Oceania',185),(4,'Bus','Oceania',80),(5,'Bicycle','Oceania',0);
SELECT transport, SUM(co2_emission) as total_emission FROM transportation WHERE region = 'Oceania' GROUP BY transport;
What is the maximum depth of any ocean floor mapping project site in the 'OceanMapping' schema?
CREATE SCHEMA OceanMapping; CREATE TABLE Sites (site_id INT,depth FLOAT); INSERT INTO Sites (site_id,depth) VALUES (1,3000.2),(2,4000.3),(3,5000.4),(4,6000.5),(5,7000.6);
SELECT MAX(depth) FROM OceanMapping.Sites;
What is the total number of articles, published in 2020, that contain the word "disinformation" and were written by authors from South America?
CREATE TABLE articles (id INT,title VARCHAR(255),publication_year INT,content TEXT,author_location VARCHAR(255));
SELECT COUNT(*) as num_articles FROM articles WHERE publication_year = 2020 AND author_location = 'South America' AND content LIKE '%disinformation%';
What is the total waste generated for vegan and non-vegan items?
CREATE TABLE items (item_name VARCHAR(50),item_type VARCHAR(10)); INSERT INTO items (item_name,item_type) VALUES ('Bruschetta','non-vegan'),('Veggie Burger','vegan'); CREATE TABLE location_waste (location_name VARCHAR(50),waste_amount NUMERIC(10,2)); INSERT INTO location_waste (location_name,waste_amount) VALUES ('San Francisco',1000.00),('New York',1500.00),('Los Angeles',500.00);
SELECT item_type, SUM(waste_amount) AS total_waste FROM items JOIN location_waste ON '1' = '1' GROUP BY item_type;
List all defense projects with a budget greater than 500,000,000 that were completed after 2020.
CREATE TABLE DefenseProjects (project_name VARCHAR(255),start_date DATE,end_date DATE,budget FLOAT); INSERT INTO DefenseProjects (project_name,start_date,end_date,budget) VALUES ('Project B','2021-01-01','2023-12-31',600000000);
SELECT * FROM DefenseProjects WHERE budget > 500000000 AND end_date > '2020-12-31';
Which defense projects had a delay of over 6 months in H1 2022?
CREATE TABLE projects(id INT,project VARCHAR(50),start_date DATE,end_date DATE,planned BOOLEAN);
SELECT project FROM projects WHERE start_date BETWEEN '2022-01-01' AND '2022-06-30' AND end_date BETWEEN '2022-07-01' AND '2022-12-31' AND planned = FALSE;
Rank the mining operations by the total amount of coal produced, with ties.
CREATE TABLE CoalProduction (MineID INT,Production DATE,CoalProduced INT); INSERT INTO CoalProduction (MineID,ProductionDate,CoalProduced) VALUES (1,'2022-01-01',500),(1,'2022-01-02',550),(1,'2022-01-03',600),(2,'2022-01-01',700),(2,'2022-01-02',750),(2,'2022-01-03',800),(3,'2022-01-01',900),(3,'2022-01-02',950),(3,'2022-01-03',1000),(4,'2022-01-01',400),(4,'2022-01-02',450),(4,'2022-01-03',500);
SELECT MineID, SUM(CoalProduced) as Total_CoalProduced, RANK() OVER (ORDER BY SUM(CoalProduced) DESC) as Rank FROM CoalProduction GROUP BY MineID;
Which mine had the highest lead production?
CREATE TABLE mine_resources (mine_name VARCHAR(50),year INT,lead_production FLOAT);
SELECT mine_name, MAX(lead_production) FROM mine_resources GROUP BY mine_name;
Create a view named 'top_artists' to show the top 5 artists by total streams
CREATE TABLE artists (artist_id INT PRIMARY KEY,artist_name VARCHAR(100),genre VARCHAR(50),total_streams INT); INSERT INTO artists (artist_id,artist_name,genre,total_streams) VALUES (1,'Taylor Swift','Pop',15000000); INSERT INTO artists (artist_id,artist_name,genre,total_streams) VALUES (2,'BTS','K-Pop',20000000); INSERT INTO artists (artist_id,artist_name,genre,total_streams) VALUES (3,'Drake','Hip-Hop',12000000); INSERT INTO artists (artist_id,artist_name,genre,total_streams) VALUES (4,'Eminem','Hip-Hop',30000000); INSERT INTO artists (artist_id,artist_name,genre,total_streams) VALUES (5,'Adele','Pop',18000000);
CREATE VIEW top_artists AS SELECT * FROM artists ORDER BY total_streams DESC LIMIT 5;
What is the average number of streams per day for jazz songs in New Orleans last month?
CREATE TABLE Streams (song_genre VARCHAR(255),city VARCHAR(255),stream_count INT,stream_date DATE); INSERT INTO Streams (song_genre,city,stream_count,stream_date) VALUES ('jazz','New Orleans',300,'2022-02-01'),('pop','New York',500,'2022-02-02');
SELECT AVG(stream_count/1.0) FROM Streams WHERE song_genre = 'jazz' AND city = 'New Orleans' AND stream_date >= DATEADD(MONTH, -1, GETDATE());
Insert a new marine protected area in the Mediterranean Sea with a depth of 1000 meters
CREATE TABLE marine_protected_areas (name TEXT,depth FLOAT);
INSERT INTO marine_protected_areas (name, depth) VALUES ('Mediterranean Sanctuary', 1000.0);
Which causes received donations from the most countries?
CREATE TABLE Donors (DonorID INT,DonorName VARCHAR(50),DonationAmount DECIMAL(10,2),CauseID INT,Country VARCHAR(50));CREATE TABLE Causes (CauseID INT,CauseName VARCHAR(50));
SELECT C.CauseName, COUNT(DISTINCT D.Country) FROM Donors D JOIN Causes C ON D.CauseID = C.CauseID GROUP BY C.CauseName ORDER BY COUNT(DISTINCT D.Country) DESC;
Who are the eSports players with the lowest number of losses in "Dota 2" tournaments?
CREATE TABLE Players (PlayerName VARCHAR(255),TournamentLosses INT); INSERT INTO Players (PlayerName,TournamentLosses) VALUES ('PlayerA',3),('PlayerB',1),('PlayerC',0),('PlayerD',4),('PlayerE',2);
SELECT PlayerName FROM Players WHERE TournamentLosses = (SELECT MIN(TournamentLosses) FROM Players);
What is the total playtime of a specific game on different platforms?
CREATE TABLE game_platforms (id INT,game VARCHAR(20),platform VARCHAR(10),playtime INT); INSERT INTO game_platforms (id,game,platform,playtime) VALUES (1,'Game1','PC',20),(2,'Game1','Console',30),(3,'Game1','Mobile',10);
SELECT platform, SUM(playtime) as sum FROM game_platforms WHERE game = 'Game1' GROUP BY platform;
What is the minimum temperature recorded in Field21 and Field22 in the year 2023?
CREATE TABLE Field21 (date DATE,temperature FLOAT); INSERT INTO Field21 VALUES ('2023-01-01',10),('2023-01-02',5); CREATE TABLE Field22 (date DATE,temperature FLOAT); INSERT INTO Field22 VALUES ('2023-01-01',8),('2023-01-02',3);
SELECT LEAST(f21.temperature, f22.temperature) as min_temperature FROM Field21 f21 INNER JOIN Field22 f22 ON f21.date = f22.date WHERE EXTRACT(YEAR FROM f21.date) = 2023;
What was the total budget allocated for education in the year 2020 across all regions?
CREATE TABLE Budget (year INT,region VARCHAR(255),category VARCHAR(255),amount INT); INSERT INTO Budget (year,region,category,amount) VALUES (2020,'North','Education',5000000),(2020,'South','Education',6000000),(2020,'East','Education',4000000),(2020,'West','Education',7000000);
SELECT SUM(amount) FROM Budget WHERE year = 2020 AND category = 'Education';
What is the total number of inclusive housing units in the cities of Tokyo, Japan and Berlin, Germany?
CREATE TABLE inclusive_housing (id INT,city VARCHAR(50),units INT); INSERT INTO inclusive_housing (id,city,units) VALUES (1,'Tokyo',80),(2,'Berlin',90),(3,'Tokyo',100),(4,'Berlin',110);
SELECT SUM(units) as total_units FROM inclusive_housing WHERE city IN ('Tokyo', 'Berlin');
Delete the 'Chicken Caesar Salad' record with the lowest revenue on February 22, 2022?
CREATE TABLE restaurant_revenue (item VARCHAR(50),revenue NUMERIC(10,2),sales_date DATE); INSERT INTO restaurant_revenue (item,revenue,sales_date) VALUES ('Chicken Caesar Salad',25.00,'2022-02-22'),('Organic Veggie Pizza',120.50,'2022-01-01'),('Organic Veggie Pizza',155.25,'2022-01-02');
DELETE FROM restaurant_revenue WHERE item = 'Chicken Caesar Salad' AND sales_date = '2022-02-22' AND revenue = (SELECT MIN(revenue) FROM restaurant_revenue WHERE item = 'Chicken Caesar Salad' AND sales_date = '2022-02-22');
How many menu items contain ingredients sourced from local suppliers for each restaurant?
CREATE TABLE restaurants (id INT,name VARCHAR(50),location VARCHAR(50)); INSERT INTO restaurants VALUES (1,'Restaurant A','City A'); INSERT INTO restaurants VALUES (2,'Restaurant B','City B'); CREATE TABLE menu_items (id INT,name VARCHAR(50),restaurant_id INT,price DECIMAL(5,2)); INSERT INTO menu_items VALUES (1,'Item A',1,10.99); INSERT INTO menu_items VALUES (2,'Item B',1,12.99); INSERT INTO menu_items VALUES (3,'Item C',2,11.99); CREATE TABLE ingredients (id INT,name VARCHAR(50),local_source BOOLEAN,menu_item_id INT); INSERT INTO ingredients VALUES (1,'Ingredient A',TRUE,1); INSERT INTO ingredients VALUES (2,'Ingredient B',FALSE,1); INSERT INTO ingredients VALUES (3,'Ingredient C',TRUE,2); INSERT INTO ingredients VALUES (4,'Ingredient D',FALSE,2); INSERT INTO ingredients VALUES (5,'Ingredient E',TRUE,3);
SELECT r.name, COUNT(DISTINCT mi.id) as num_local_items FROM restaurants r JOIN menu_items mi ON r.id = mi.restaurant_id JOIN ingredients i ON mi.id = i.menu_item_id WHERE i.local_source = TRUE GROUP BY r.name;
What is the total sales for 'Restaurant A' for the month of January?
CREATE TABLE sales (id INT,restaurant_id INT,sales DECIMAL(5,2),sale_date DATE); INSERT INTO sales (id,restaurant_id,sales,sale_date) VALUES (1,1,100.00,'2022-01-01'),(2,1,200.00,'2022-01-02'),(3,2,150.00,'2022-01-03'),(4,3,50.00,'2022-01-04'),(5,4,300.00,'2022-02-01');
SELECT SUM(sales) FROM sales WHERE restaurant_id = 1 AND MONTH(sale_date) = 1;
Create a table named 'supplier_ethics'
CREATE TABLE supplier_ethics (supplier_id INT,country VARCHAR(50),labor_practices VARCHAR(50),sustainability_score INT);
CREATE TABLE supplier_ethics (supplier_id INT, country VARCHAR(50), labor_practices VARCHAR(50), sustainability_score INT);
List the names of all Mars rovers and their launch dates.
CREATE TABLE spacecraft (id INT,name VARCHAR(255),type VARCHAR(255),launch_date DATE);
SELECT spacecraft.name, spacecraft.launch_date FROM spacecraft WHERE type = 'Mars rover';
What is the lifespan of each satellite, ranked by lifespan?
CREATE TABLE satellites (satellite_name VARCHAR(50),launch_date DATE,decommission_date DATE); INSERT INTO satellites (satellite_name,launch_date,decommission_date) VALUES ('ISS','1998-11-20','2028-11-20'),('Hubble Space Telescope','1990-04-24','2040-04-24'),('Spitzer Space Telescope','2003-08-25','2023-01-30');
SELECT satellite_name, DATEDIFF(day, launch_date, decommission_date) AS lifespan FROM satellites ORDER BY lifespan DESC;
What is the latest end date of astronaut medical records in 2012?
CREATE TABLE MedicalRecords (id INT,astronaut_id INT,start_date DATE,end_date DATE); INSERT INTO MedicalRecords (id,astronaut_id,start_date,end_date) VALUES (1,1,'2010-01-01','2010-01-10'),(2,2,'2012-05-01','2012-12-31');
SELECT MAX(end_date) FROM MedicalRecords WHERE YEAR(end_date) = 2012;
Which spacecraft have been used in the most unique space missions?
CREATE TABLE spacecraft_missions_unique (id INT PRIMARY KEY,spacecraft_name VARCHAR(50),mission_name VARCHAR(50));
SELECT spacecraft_name, COUNT(DISTINCT mission_name) as unique_missions FROM spacecraft_missions_unique GROUP BY spacecraft_name;
How many tickets were sold for each team's away games in Q2 of 2022?
CREATE TABLE teams (id INT,name VARCHAR(255)); INSERT INTO teams (id,name) VALUES (1,'TeamA'),(2,'TeamB'),(3,'TeamC'); CREATE TABLE games (id INT,home_team_id INT,away_team_id INT,home_team_score INT,away_team_score INT,price DECIMAL(5,2),game_date DATE); CREATE VIEW away_games AS SELECT id,away_team_id,price,game_date FROM games;
SELECT t.name, COUNT(*) as tickets_sold FROM away_games h JOIN teams t ON h.away_team_id = t.id WHERE h.game_date BETWEEN '2022-04-01' AND '2022-06-30' GROUP BY t.name;
List all unique sports and the number of teams for each sport in 'team_performances_table'
CREATE TABLE team_performances_table (team_id INT,team_name VARCHAR(50),sport VARCHAR(20),wins INT,losses INT); INSERT INTO team_performances_table (team_id,team_name,sport,wins,losses) VALUES (1,'Blue Lions','Basketball',25,15); INSERT INTO team_performances_table (team_id,team_name,sport,wins,losses) VALUES (2,'Green Devils','Soccer',12,8);
SELECT sport, COUNT(DISTINCT team_name) AS team_count FROM team_performances_table GROUP BY sport;
What is the total number of trips taken in autonomous tuk-tuks in Bangkok?
CREATE TABLE autonomous_tuk_tuks (tuk_tuk_id INT,trip_id INT,trip_start_time TIMESTAMP,trip_end_time TIMESTAMP,start_latitude DECIMAL(9,6),start_longitude DECIMAL(9,6),end_latitude DECIMAL(9,6),end_longitude DECIMAL(9,6));
SELECT COUNT(DISTINCT trip_id) FROM autonomous_tuk_tuks WHERE start_longitude BETWEEN 100.3 AND 100.9 AND start_latitude BETWEEN 13.5 AND 14.1;
What are the union membership statistics for unions that have engaged in successful collective bargaining in the healthcare sector?
CREATE TABLE Membership (UnionName TEXT,Sector TEXT,MemberCount INT); INSERT INTO Membership (UnionName,Sector,MemberCount) VALUES ('UnionHealthA','Healthcare',3000),('UnionHealthB','Healthcare',5000),('UnionHealthC','Healthcare',2000);
SELECT UnionName, MemberCount FROM Membership WHERE Sector = 'Healthcare' AND UnionName IN (SELECT UnionName FROM CBAs WHERE ExpirationDate > CURDATE());
What is the maximum weekly wage for workers in the 'service' industry in unions?
CREATE TABLE unions (id INT,name TEXT); CREATE TABLE workers (id INT,union_id INT,industry TEXT,wage FLOAT); INSERT INTO unions (id,name) VALUES (1,'Union M'),(2,'Union N'),(3,'Union O'); INSERT INTO workers (id,union_id,industry,wage) VALUES (1,1,'service',600),(2,1,'service',650),(3,2,'service',700),(4,2,'service',750),(5,3,'service',800),(6,3,'service',850);
SELECT MAX(wage) FROM workers JOIN unions ON workers.union_id = unions.id WHERE industry = 'service';
What is the minimum mileage range of the Nissan Leaf?
CREATE TABLE vehicle_range (make VARCHAR(255),model VARCHAR(255),mileage_range INT); INSERT INTO vehicle_range (make,model,mileage_range) VALUES ('Nissan','Leaf',150),('Nissan','Versa',400);
SELECT mileage_range FROM vehicle_range WHERE make = 'Nissan' AND model = 'Leaf';
What is the maximum speed recorded for vessels in the Baltic Sea, and which vessels achieved this speed?
CREATE TABLE vessel_speed (id INT,vessel_id INT,speed FLOAT,speed_date DATE,speed_location TEXT);
SELECT vessel_id, MAX(speed) FROM vessel_speed WHERE speed_location = 'Baltic Sea' GROUP BY vessel_id HAVING MAX(speed) = (SELECT MAX(speed) FROM vessel_speed WHERE speed_location = 'Baltic Sea');
Insert new records into 'water_usage' table
CREATE TABLE water_usage (id INT PRIMARY KEY,region VARCHAR(20),usage FLOAT);
INSERT INTO water_usage (id, region, usage) VALUES (1, 'Midwest', 500.5), (2, 'Northwest', 700.2), (3, 'Southeast', 800.1);
List all algorithmic fairness tables that have a primary key named 'algorithm_id'
CREATE TABLE AlgoFairness_Table1 (algorithm_id INT,metric VARCHAR(50),value FLOAT); CREATE TABLE AlgoFairness_Table2 (algorithm_id INT,bias INT,mitigation VARCHAR(50)); CREATE TABLE AlgoFairness_Table3 (id INT,algorithm_id INT,accuracy FLOAT,fairness INT);
SELECT table_name FROM information_schema.columns WHERE column_name = 'algorithm_id' AND table_schema = 'your_schema';
What are the names of all innovation projects in the 'rural_infrastructure' table, excluding those with a budget over 50000?
CREATE TABLE rural_infrastructure (name VARCHAR(255),budget INT); INSERT INTO rural_infrastructure (name,budget) VALUES ('Dam Construction',40000),('Well Digging',30000),('Irrigation System',70000);
SELECT name FROM rural_infrastructure WHERE budget <= 50000;
Add a new safety incident to the safety_incidents table (id: 4, aircraft: 'Space Shuttle Challenger', date: '1986-01-28', description: 'O-ring failure')
CREATE TABLE safety_incidents (id INT,aircraft VARCHAR(255),date DATE,description VARCHAR(255));
INSERT INTO safety_incidents (id, aircraft, date, description) VALUES (4, 'Space Shuttle Challenger', '1986-01-28', 'O-ring failure');
Update the size of the 'Serengeti Plains' habitat in the 'habitat_preservation' table
CREATE TABLE habitat_preservation (id INT PRIMARY KEY,location VARCHAR(50),size_acres FLOAT,preservation_status VARCHAR(50),protected_species VARCHAR(50));
UPDATE habitat_preservation SET size_acres = 5700000.0 WHERE location = 'Serengeti Plains';
What is the number of animals in each sanctuary that have increased by more than 10% since the last year?
CREATE TABLE animal_count_data (sanctuary_id INT,year INT,animal_count INT); INSERT INTO animal_count_data (sanctuary_id,year,animal_count) VALUES (1,2021,25),(1,2022,30),(2,2021,30),(2,2022,35),(3,2021,20),(3,2022,22),(4,2021,15),(4,2022,16);
SELECT sanctuary_id, (animal_count-LAG(animal_count, 1) OVER (PARTITION BY sanctuary_id ORDER BY year))/LAG(animal_count, 1) OVER (PARTITION BY sanctuary_id ORDER BY year) * 100 AS increase_percentage FROM animal_count_data WHERE (animal_count-LAG(animal_count, 1) OVER (PARTITION BY sanctuary_id ORDER BY year))/LAG(animal_count, 1) OVER (PARTITION BY sanctuary_id ORDER BY year) > 10;
What was the number of volunteers who contributed more than 10 hours to the "Music Outreach" program?
CREATE TABLE volunteers_2 (program VARCHAR(255),hours INT); INSERT INTO volunteers_2 (program,hours) VALUES ('Music Outreach',12),('Music Outreach',8),('Theater Education',15);
SELECT COUNT(*) FROM volunteers_2 WHERE program = 'Music Outreach' AND hours > 10;
Identify the top 3 customers with the highest total purchases at a specific dispensary in Colorado.
CREATE TABLE Customers (Customer_ID INT,Customer_Name TEXT,Dispensary_ID INT); INSERT INTO Customers (Customer_ID,Customer_Name,Dispensary_ID) VALUES (1,'Lila Green',2); CREATE TABLE Sales (Sale_ID INT,Customer_ID INT,Total_Purchase DECIMAL); INSERT INTO Sales (Sale_ID,Customer_ID,Total_Purchase) VALUES (1,1,200.00);
SELECT Customer_Name, SUM(Total_Purchase) as Total FROM Sales JOIN Customers ON Sales.Customer_ID = Customers.Customer_ID WHERE Dispensary_ID = 2 GROUP BY Customer_ID ORDER BY Total DESC LIMIT 3;
Display the total billing amount for cases in the 'Boston' office.
CREATE TABLE cases (case_id INT,billing_amount DECIMAL(10,2),office_id INT); INSERT INTO cases (case_id,billing_amount,office_id) VALUES (1,500.00,1),(2,750.00,1),(3,1000.00,2); CREATE TABLE offices (office_id INT,office_name VARCHAR(20)); INSERT INTO offices (office_id,office_name) VALUES (1,'Boston'),(2,'New York'),(3,'Chicago');
SELECT SUM(billing_amount) FROM cases c JOIN offices o ON c.office_id = o.office_id WHERE o.office_name = 'Boston';
What is the minimum billing amount for cases in the real estate category?
CREATE TABLE cases (case_id INT,category VARCHAR(20),billing_amount DECIMAL(10,2));
SELECT MIN(billing_amount) FROM cases WHERE category = 'real estate';
What is the win rate for cases handled by attorneys with more than 10 years of experience?
CREATE TABLE Cases (CaseID INT,CaseYear INT,AttorneyID INT,ClientID INT,CaseOutcome VARCHAR(10)); INSERT INTO Cases (CaseID,CaseYear,AttorneyID,ClientID,CaseOutcome) VALUES (3,2021,3,3,'Won'); INSERT INTO Cases (CaseID,CaseYear,AttorneyID,ClientID,CaseOutcome) VALUES (4,2020,4,4,'Lost');
SELECT COUNT(CaseID) as NumberOfCases, AVG(CASE WHEN CaseOutcome = 'Won' THEN 1 ELSE 0 END) as WinRate FROM Cases WHERE YearsOfExperience > 10;
Identify the chemical plants in Canada with safety violation costs higher than their preceding plant.
CREATE TABLE chemical_plants (plant_id INT,plant_name VARCHAR(50),country VARCHAR(50),safety_violation_cost DECIMAL(10,2),plant_order INT); INSERT INTO chemical_plants (plant_id,plant_name,country,safety_violation_cost,plant_order) VALUES (1,'Plant A','Canada',5000,1),(2,'Plant B','Canada',7000,2),(3,'Plant C','USA',3000,1);
SELECT plant_id, plant_name, safety_violation_cost FROM (SELECT plant_id, plant_name, safety_violation_cost, LAG(safety_violation_cost) OVER (PARTITION BY country ORDER BY plant_order) AS lag_value FROM chemical_plants WHERE country = 'Canada') tmp WHERE safety_violation_cost > lag_value;
What is the maximum temperature in the chemical storage facilities located in Canada?
CREATE TABLE storage_facilities (id INT,facility_name TEXT,country TEXT,temperature DECIMAL(5,2)); INSERT INTO storage_facilities (id,facility_name,country,temperature) VALUES (1,'Facility A','Canada',15.3),(2,'Facility B','Mexico',28.9);
SELECT MAX(temperature) FROM storage_facilities WHERE country = 'Canada';
What is the average number of hospital beds per 1000 people in Southeast Asia?
CREATE TABLE hospitals (id INT,beds INT,population INT,location TEXT); INSERT INTO hospitals (id,beds,population,location) VALUES (1,500,10000,'Southeast Asia'); INSERT INTO hospitals (id,beds,population,location) VALUES (2,600,12000,'Southeast Asia');
SELECT AVG(beds / population * 1000) FROM hospitals WHERE location = 'Southeast Asia';
List all unique industries that have startups founded before 2015.
CREATE TABLE startups (id INT,name TEXT,industry TEXT,founder_gender TEXT,founding_year INT); INSERT INTO startups (id,name,industry,founder_gender,founding_year) VALUES (1,'Acme Inc','Tech','Male',2010),(2,'Beta Corp','Retail','Female',2015),(3,'Gamma Startups','Biotech','Male',2020);
SELECT DISTINCT industry FROM startups WHERE founding_year < 2015;
What is the success rate of startups founded by immigrants?
CREATE TABLE companies (id INT,name TEXT,founder_immigrant BOOLEAN,is_active BOOLEAN);
SELECT 100.0 * AVG(CASE WHEN founder_immigrant THEN 1.0 ELSE 0.0 END * CASE WHEN is_active THEN 1.0 ELSE 0.0 END) as success_rate FROM companies;
What is the minimum funding amount received by a company founded by a person with a disability in the education industry?
CREATE TABLE Companies (id INT,name TEXT,founders TEXT,industry TEXT); INSERT INTO Companies (id,name,founders,industry) VALUES (1,'EdLift','Disabled,Male','Education'); INSERT INTO Companies (id,name,founders,industry) VALUES (2,'TechBoost','Asian,Male','Technology'); CREATE TABLE Investment_Rounds (company_id INT,funding_amount INT,round_number INT); INSERT INTO Investment_Rounds (company_id,funding_amount,round_number) VALUES (1,500000,1); INSERT INTO Investment_Rounds (company_id,funding_amount,round_number) VALUES (1,750000,2); INSERT INTO Investment_Rounds (company_id,funding_amount,round_number) VALUES (2,3000000,1);
SELECT MIN(r.funding_amount) FROM Companies c JOIN Investment_Rounds r ON c.id = r.company_id WHERE c.founders LIKE '%Disabled%' AND c.industry = 'Education';
Identify the change in crop yield for each farm, from 2021 to 2022.
CREATE TABLE Yield (FarmID int,Year int,Yield int); INSERT INTO Yield (FarmID,Year,Yield) VALUES (1,2021,150),(1,2022,180),(2,2021,200),(2,2022,220),(3,2021,100),(3,2022,110);
SELECT FarmID, (Y2.Yield - Y1.Yield) as YieldChange FROM Yield Y1 JOIN Yield Y2 ON Y1.FarmID = Y2.FarmID AND Y1.Year = 2021 AND Y2.Year = 2022;
How many marine mammal species are listed as endangered?
CREATE TABLE marine_mammals (name VARCHAR(255),conservation_status VARCHAR(50)); INSERT INTO marine_mammals (name,conservation_status) VALUES ('Blue Whale','Endangered'),('Dolphin','Least Concern');
SELECT COUNT(*) FROM marine_mammals WHERE conservation_status = 'Endangered';
What is the total number of marine mammals in the Arctic and Antarctic?
CREATE TABLE marine_mammals (mammal_name VARCHAR(255),region VARCHAR(255)); CREATE TABLE regions (region_name VARCHAR(255),region_id INTEGER);
SELECT SUM(region = 'Arctic' OR region = 'Antarctic') FROM marine_mammals;
What is the total number of marine species observed in the Pacific and Atlantic oceans?
CREATE TABLE oceans (ocean_id INT,name VARCHAR(20)); INSERT INTO oceans (ocean_id,name) VALUES (1,'Pacific'),(2,'Atlantic'); CREATE TABLE species_oceans (species_id INT,species_name VARCHAR(20),ocean_id INT); INSERT INTO species_oceans (species_id,species_name,ocean_id) VALUES (1,'Clownfish',1),(2,'Dolphin',2),(3,'Shark',1),(4,'Starfish',2);
SELECT COUNT(*) FROM species_oceans WHERE ocean_id IN (1, 2);
What is the total transaction volume for the top 3 digital assets by market capitalization in the 'developed_markets' schema?
CREATE SCHEMA developed_markets; CREATE TABLE developed_markets.digital_assets (asset_name VARCHAR(10),market_cap BIGINT,daily_transaction_volume BIGINT); INSERT INTO developed_markets.digital_assets (asset_name,market_cap,daily_transaction_volume) VALUES ('AssetG',30000000,15000000),('AssetH',25000000,12000000),('AssetI',20000000,10000000),('AssetJ',15000000,8000000),('AssetK',10000000,6000000);
SELECT SUM(daily_transaction_volume) FROM (SELECT daily_transaction_volume FROM developed_markets.digital_assets ORDER BY market_cap DESC FETCH NEXT 3 ROWS ONLY) t;
What is the density of trees (trees per hectare) by tree type in each country?
CREATE TABLE countries (id INT,name VARCHAR(255)); INSERT INTO countries (id,name) VALUES (1,'Canada'),(2,'USA'); CREATE TABLE tree_densities (id INT,country_id INT,tree_type_id INT,trees_per_hectare INT); INSERT INTO tree_densities (id,country_id,tree_type_id,trees_per_hectare) VALUES (1,1,1,100),(2,1,2,150),(3,2,1,80),(4,2,2,120); CREATE TABLE tree_types (id INT,name VARCHAR(255)); INSERT INTO tree_types (id,name) VALUES (1,'Coniferous'),(2,'Deciduous');
SELECT c.name, tt.name, AVG(td.trees_per_hectare) avg_trees_per_hectare FROM tree_densities td JOIN countries c ON td.country_id = c.id JOIN tree_types tt ON td.tree_type_id = tt.id GROUP BY c.name, tt.name;
What are the top 5 cruelty-free cosmetic products with the highest consumer preference ratings?
CREATE TABLE cosmetics (product_id INT,product_name TEXT,cruelty_free BOOLEAN,consumer_rating FLOAT); INSERT INTO cosmetics VALUES (1,'Lipstick A',true,4.6),(2,'Foundation B',false,4.3),(3,'Mascara C',true,4.7),(4,'Eyeshadow D',true,4.5),(5,'Blush E',false,4.4);
SELECT product_name, cruelty_free, consumer_rating FROM cosmetics WHERE cruelty_free = true ORDER BY consumer_rating DESC LIMIT 5;
When was the first military innovation initiated?
CREATE TABLE Timeline (id INT,event VARCHAR(50),year INT); INSERT INTO Timeline (id,event,year) VALUES (1,'First Innovation',1950);
SELECT MIN(year) FROM Timeline;
Find the average transaction amount for each customer
CREATE TABLE customers (customer_id INT,name VARCHAR(50)); INSERT INTO customers VALUES (1,'Alice'); INSERT INTO customers VALUES (2,'Bob'); CREATE TABLE transactions (transaction_id INT,customer_id INT,amount DECIMAL(10,2)); INSERT INTO transactions VALUES (1,1,50.00); INSERT INTO transactions VALUES (2,1,75.00); INSERT INTO transactions VALUES (3,2,100.00);
SELECT t.customer_id, AVG(t.amount) as avg_amount FROM transactions t GROUP BY t.customer_id;
What is the total transaction amount for each customer?
CREATE TABLE customers (customer_id INT,name VARCHAR(50)); CREATE TABLE transactions (transaction_id INT,customer_id INT,transaction_amount DECIMAL(10,2)); INSERT INTO customers (customer_id,name) VALUES (1,'John Doe'),(2,'Jane Smith'); INSERT INTO transactions (transaction_id,customer_id,transaction_amount) VALUES (1,1,500.00),(2,1,700.00),(3,2,300.00);
SELECT c.name, SUM(t.transaction_amount) FROM customers c JOIN transactions t ON c.customer_id = t.customer_id GROUP BY c.name;
How many vessels are owned by companies based in the European Union, with a total capacity of over 1,000,000 tons?
CREATE TABLE companies (company_id INT,company_name TEXT,country TEXT); INSERT INTO companies VALUES (1,'Company X','Germany'),(2,'Company Y','France'),(3,'Company Z','Italy'); CREATE TABLE vessels (vessel_id INT,company_id INT,capacity INT); INSERT INTO vessels VALUES (1,1,800000),(2,1,900000),(3,2,700000),(4,3,1200000);
SELECT COUNT(vessels.vessel_id) FROM vessels JOIN companies ON vessels.company_id = companies.company_id WHERE companies.country = 'European Union' GROUP BY vessels.company_id HAVING SUM(vessels.capacity) > 1000000;
What is the total revenue for mental health services provided in rural healthcare facilities in Oregon and Washington, grouped by facility?
CREATE TABLE services (id INT,name TEXT,revenue INT,facility_id INT); INSERT INTO services (id,name,revenue,facility_id) VALUES (1,'Mental Health',5000,101); CREATE TABLE facilities (id INT,name TEXT,location TEXT,capacity INT);
SELECT facilities.name, SUM(services.revenue) as total_revenue FROM services JOIN facilities ON services.facility_id = facilities.id WHERE facilities.location IN ('Oregon', 'Washington') AND services.name = 'Mental Health' GROUP BY facilities.name;
Who are the top 3 suppliers of military equipment to the African Union in 2022?
CREATE TABLE suppliers(supplier_id INT,supplier_name VARCHAR(255),country VARCHAR(255),total_sales FLOAT,year INT); INSERT INTO suppliers(supplier_id,supplier_name,country,total_sales,year) VALUES (1,'Supplier1','Country1',30000000,2022),(2,'Supplier2','Country2',25000000,2022),(3,'Supplier3','Country3',20000000,2022),(4,'Supplier4','Country4',15000000,2022);
SELECT supplier_name, total_sales FROM suppliers WHERE country = 'African Union' AND year = 2022 ORDER BY total_sales DESC LIMIT 3;
Which artist has the highest number of total streams on Spotify and Apple Music?
CREATE TABLE artist_streams (stream_id INT,artist_name VARCHAR(100),platform VARCHAR(20),total_streams INT); INSERT INTO artist_streams (stream_id,artist_name,platform,total_streams) VALUES (1,'Queen','Spotify',10000000),(2,'Queen','Apple Music',5000000),(3,'Taylor Swift','Spotify',8000000),(4,'Taylor Swift','Apple Music',6000000);
SELECT a.artist_name, MAX(a.total_streams) as highest_streams FROM artist_streams a WHERE a.platform IN ('Spotify', 'Apple Music') GROUP BY a.artist_name;
Calculate the percentage of employees in each department who are from underrepresented racial or ethnic groups.
CREATE TABLE Employees (EmployeeID int,Department varchar(20),RaceEthnicity varchar(50)); INSERT INTO Employees (EmployeeID,Department,RaceEthnicity) VALUES (1,'IT','Asian'),(2,'IT','White'),(3,'Sales','Black'),(4,'Sales','Hispanic'),(5,'Sales','Asian');
SELECT e.Department, ROUND(COUNT(CASE WHEN e.RaceEthnicity IN ('Black', 'Hispanic', 'Native American', 'Pacific Islander') THEN 1 END) * 100.0 / COUNT(*), 1) AS Percent_Underrepresented FROM Employees e GROUP BY e.Department;
Find the average salary for athletes in each sport in the athlete_salaries table.
CREATE TABLE athlete_salaries (athlete_id INT,name VARCHAR(50),sport VARCHAR(20),salary DECIMAL(10,2)); INSERT INTO athlete_salaries (athlete_id,name,sport,salary) VALUES (1,'LeBron James','Basketball',45000000.00); INSERT INTO athlete_salaries (athlete_id,name,sport,salary) VALUES (2,'Tom Brady','Football',30000000.00);
SELECT sport, AVG(salary) FROM athlete_salaries GROUP BY sport;
What is the minimum donation amount made in the year 2019?
CREATE TABLE donations (id INT,donation_date DATE,donation_amount DECIMAL); INSERT INTO donations (id,donation_date,donation_amount) VALUES (1,'2019-01-01',50.00),(2,'2019-01-01',10.00),(3,'2019-12-31',25.00);
SELECT MIN(donation_amount) FROM donations WHERE YEAR(donation_date) = 2019;
Delete patents not related to AI.
CREATE TABLE patents (id INT,inventor_id INT,patent_year INT,ai_related BOOLEAN);
DELETE FROM patents WHERE id NOT IN (SELECT p.id FROM patents p WHERE p.ai_related = true);
What is the maximum budget allocated for technology for social good projects in African countries?
CREATE TABLE SocialGoodBudget (Country VARCHAR(50),Budget DECIMAL(10,2)); INSERT INTO SocialGoodBudget (Country,Budget) VALUES ('Kenya',1200000.00),('Nigeria',1500000.00),('South Africa',1800000.00); CREATE TABLE Countries (Country VARCHAR(50),Continent VARCHAR(50)); INSERT INTO Countries (Country,Continent) VALUES ('Kenya','Africa'),('Nigeria','Africa'),('South Africa','Africa');
SELECT MAX(SocialGoodBudget.Budget) AS MaxBudget FROM SocialGoodBudget INNER JOIN Countries ON SocialGoodBudget.Country = Countries.Country WHERE Countries.Continent = 'Africa';
List the number of vehicles of each type in the Berlin U-Bahn fleet
CREATE TABLE berlin_ubahn_inventory (inventory_id int,vehicle_type varchar(255),model varchar(255)); INSERT INTO berlin_ubahn_inventory (inventory_id,vehicle_type,model) VALUES (1,'Train','Type A'),(2,'Train','Type B'),(3,'Tram','Type C');
SELECT vehicle_type, COUNT(*) AS count FROM berlin_ubahn_inventory GROUP BY vehicle_type;
Show the total revenue generated from circular economy practices in the 'EthicalFashion' database
CREATE TABLE sales (sale_id INT,item_id INT,sale_price DECIMAL(10,2),is_circular_economy BOOLEAN);
SELECT SUM(sale_price) FROM sales WHERE is_circular_economy = TRUE;
What is the percentage of users in Canada who have used the hashtag #travel?
CREATE TABLE posts (id INT,user_id INT,hashtags TEXT); INSERT INTO posts (id,user_id,hashtags) VALUES (1,1,'#travel'),(2,1,'#food'),(3,2,'#travel'),(4,3,'#art'),(5,4,'#music'); CREATE TABLE users (id INT,country VARCHAR(2)); INSERT INTO users (id,country) VALUES (1,'CA'),(2,'US'),(3,'CA'),(4,'DE');
SELECT 100.0 * COUNT(DISTINCT user_id) / (SELECT COUNT(DISTINCT user_id) FROM posts JOIN users ON posts.user_id = users.id WHERE users.country = 'CA') as percentage_travel FROM posts JOIN users ON posts.user_id = users.id WHERE hashtags LIKE '%#travel%' AND users.country = 'CA';
Insert a new sustainable fabric type 'Organic Hemp' into the 'Fabric' table
CREATE TABLE Fabric (id INT PRIMARY KEY,name VARCHAR(50),source_country VARCHAR(50),sustainability_score INT);
INSERT INTO Fabric (id, name, source_country, sustainability_score) VALUES (10, 'Organic Hemp', 'China', 85);