instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the total revenue of freight forwarder 'MNO Logistics'?
CREATE TABLE freight_forwarder (id INT,name VARCHAR(255),revenue FLOAT); INSERT INTO freight_forwarder (id,name,revenue) VALUES (1,'ABC Logistics',500000),(2,'XYZ Freight',600000),(3,'MNO Logistics',400000);
SELECT revenue FROM freight_forwarder WHERE name = 'MNO Logistics';
What are the cosmetic products and their ingredients that are not cruelty-free?
CREATE TABLE cosmetics (id INT,name VARCHAR(255),is_cruelty_free BOOLEAN); INSERT INTO cosmetics (id,name,is_cruelty_free) VALUES (1,'Lipstick',true),(2,'Mascara',false); CREATE TABLE ingredients (cosmetic_id INT,ingredient VARCHAR(255)); INSERT INTO ingredients (cosmetic_id,ingredient) VALUES (1,'Ricinus Communis Seed Oil'),(1,'Cera Alba'),(2,'Aqua'),(2,'Paraffin'),(2,'Glycerin');
SELECT c.name, i.ingredient FROM cosmetics c INNER JOIN ingredients i ON c.id = i.cosmetic_id WHERE c.is_cruelty_free = false;
Find the top 5 users who have posted the most about "climate change" in the past month, in Canada, based on the number of posts.
CREATE TABLE users (id INT,username VARCHAR(255)); CREATE TABLE posts (id INT,user_id INT,title VARCHAR(255),content TEXT,hashtags VARCHAR(255),created_at TIMESTAMP);
SELECT u.username, COUNT(p.id) as post_count FROM users u JOIN posts p ON u.id = p.user_id WHERE u.country = 'Canada' AND p.hashtags LIKE '%#climatechange%' GROUP BY u.username ORDER BY post_count DESC LIMIT 5;
What is the GrossTonnage of all vessels owned by the carrier registered in Singapore?
CREATE TABLE Vessel (VesselID INT,Name VARCHAR(255),CarrierID INT,GrossTonnage INT,YearBuilt INT); INSERT INTO Vessel (VesselID,Name,CarrierID,GrossTonnage,YearBuilt) VALUES (3,'PIL Container',3,45000,2010);
SELECT Vessel.GrossTonnage FROM Vessel INNER JOIN Carrier ON Vessel.CarrierID = Carrier.CarrierID WHERE Carrier.FlagState = 'Singapore';
Create a table for water usage in Canadian provinces and insert data.
CREATE TABLE canadian_provinces (province VARCHAR(255),water_usage INT);
INSERT INTO canadian_provinces (province, water_usage) VALUES ('Ontario', 5000000), ('Quebec', 4000000), ('British Columbia', 3000000);
Rank community health workers by cultural competency score in descending order within each state.
CREATE TABLE CommunityHealthWorker (WorkerID INT,State CHAR(2),CulturalCompetencyScore INT); INSERT INTO CommunityHealthWorker (WorkerID,State,CulturalCompetencyScore) VALUES (1,'CA',85),(2,'TX',80),(3,'CA',90),(4,'TX',82);
SELECT WorkerID, State, CulturalCompetencyScore, RANK() OVER (PARTITION BY State ORDER BY CulturalCompetencyScore DESC) AS Rank FROM CommunityHealthWorker;
Display the total quantity of each ingredient used in the last 7 days
CREATE TABLE ingredients (id INT PRIMARY KEY,name VARCHAR(255),cost DECIMAL(10,2)); CREATE TABLE inventory (id INT PRIMARY KEY,ingredient_id INT,quantity INT,use_date DATE); INSERT INTO ingredients (id,name,cost) VALUES (1,'Tomato',0.50),(2,'Pasta',1.00),(3,'Chicken',2.50); INSERT INTO inventory (id,ingredient_id,quantity,use_date) VALUES (1,1,50,'2022-03-01'),(2,2,25,'2022-03-05'),(3,1,75,'2022-03-10');
SELECT ingredients.name, SUM(inventory.quantity) AS total_quantity FROM ingredients JOIN inventory ON ingredients.id = inventory.ingredient_id WHERE inventory.use_date >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) GROUP BY ingredients.name;
What is the total cost of each space mission?
CREATE TABLE space_missions (id INT,name VARCHAR(50),cost INT); INSERT INTO space_missions (id,name,cost) VALUES (1,'Mars Rover',2500000),(2,'ISS',150000000),(3,'Hubble Space Telescope',1000000000);
SELECT name, SUM(cost) OVER (PARTITION BY 1) as total_cost FROM space_missions;
What are the top 3 countries with the most security incidents, in the last year?
CREATE TABLE security_incidents (id INT,timestamp TIMESTAMP,country VARCHAR(255),incident_type VARCHAR(255));
SELECT country, COUNT(*) as incident_count FROM security_incidents WHERE timestamp >= DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 YEAR) GROUP BY country ORDER BY incident_count DESC LIMIT 3;
Count the number of security incidents in the APAC region in the last month.
CREATE TABLE security_incidents (id INT,region VARCHAR(50),incident_date DATE);
SELECT COUNT(*) FROM security_incidents WHERE region = 'APAC' AND incident_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);
What is the total number of volunteers for each organization in the 'organizations' table?
CREATE TABLE organizations (org_id INT,org_name TEXT,num_volunteers INT);
SELECT org_name, SUM(num_volunteers) FROM organizations GROUP BY org_name;
Insert a new record with the following details into the 'workplace_safety' table: (5, 'Warehouse', 'Medium', 80)
CREATE TABLE workplace_safety (id INT,location VARCHAR(50),risk_level VARCHAR(10),safety_score INT); INSERT INTO workplace_safety (id,location,risk_level,safety_score) VALUES (1,'Office','Low',90),(2,'Factory','High',60),(3,'Construction Site','Very High',50),(4,'Warehouse','Medium',70);
INSERT INTO workplace_safety (id, location, risk_level, safety_score) VALUES (5, 'Warehouse', 'Medium', 80);
What is the percentage of mobile and broadband subscribers that are using a 4G network technology?
CREATE TABLE mobile_subscribers(id INT,name VARCHAR(50),technology VARCHAR(50)); CREATE TABLE broadband_subscribers(id INT,name VARCHAR(50),technology VARCHAR(50));
SELECT 'mobile' as type, COUNT(*) * 100.0 / (SELECT COUNT(*) FROM mobile_subscribers WHERE technology = '4G') as pct_4g_mobile FROM mobile_subscribers WHERE technology = '4G' UNION ALL SELECT 'broadband' as type, COUNT(*) * 100.0 / (SELECT COUNT(*) FROM broadband_subscribers WHERE technology = '4G') as pct_4g_broadband FROM broadband_subscribers WHERE technology = '4G';
What is the average water temperature in fish farms located in the Mediterranean and Aegean seas?
CREATE TABLE Farm(id INT,location VARCHAR(50),temperature FLOAT); INSERT INTO Farm(id,location,temperature) VALUES (1,'Mediterranean Sea',22.5),(2,'Aegean Sea',21.3);
SELECT AVG(temperature) FROM Farm WHERE location LIKE '%Mediterranean Sea%' OR location LIKE '%Aegean Sea%';
Find the total number of songs released by each artist.
CREATE TABLE song_releases (song_id INT,artist_name VARCHAR(50),genre VARCHAR(20));
SELECT artist_name, COUNT(*) FROM song_releases GROUP BY artist_name;
Create a table named "coral_reefs"
CREATE TABLE coral_reefs (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),status VARCHAR(255));
CREATE TABLE coral_reefs (id INT PRIMARY KEY, name VARCHAR(255), location VARCHAR(255), status VARCHAR(255));
Delete the marine life research station with station ID 2 from the database.
CREATE TABLE marine_life_research_stations (station_id INT,station_name TEXT,region TEXT); INSERT INTO marine_life_research_stations (station_id,station_name,region) VALUES (1,'Station A','Pacific'),(2,'Station B','Atlantic');
DELETE FROM marine_life_research_stations WHERE station_id = 2;
Who are the top 3 users with the most posts containing the hashtag '#food' in 'Japan'?
CREATE TABLE users (id INT,name VARCHAR(50),post_country VARCHAR(50)); INSERT INTO users (id,name,post_country) VALUES (1,'Hiroshi','Japan'); INSERT INTO users (id,name,post_country) VALUES (2,'Ichigo','Japan'); INSERT INTO users (id,name,post_country) VALUES (3,'Carla','USA'); CREATE TABLE user_posts (user_id INT,post_country VARCHAR(50),post_hashtags TEXT); INSERT INTO user_posts (user_id,post_country,post_hashtags) VALUES (1,'Japan','#food,#sushi'); INSERT INTO user_posts (user_id,post_country,post_hashtags) VALUES (2,'Japan','#food,#ramen'); INSERT INTO user_posts (user_id,post_country,post_hashtags) VALUES (3,'USA','#nature');
SELECT name FROM (SELECT name, ROW_NUMBER() OVER (PARTITION BY post_country ORDER BY COUNT(*) DESC) as rank FROM users JOIN user_posts ON users.id = user_posts.user_id WHERE post_country = 'Japan' AND post_hashtags LIKE '%#food%' GROUP BY name, post_country) AS user_ranks WHERE rank <= 3;
Delete policies that were issued in Texas.
CREATE TABLE policies (policy_number INT,policyholder_name TEXT,issue_date DATE,state TEXT); INSERT INTO policies (policy_number,policyholder_name,issue_date,state) VALUES (12345,'John Doe','2021-06-01','California'); INSERT INTO policies (policy_number,policyholder_name,issue_date,state) VALUES (67890,'Jane Smith','2021-07-01','Texas');
DELETE FROM policies WHERE state = 'Texas';
What is the total cargo weight (in metric tons) handled by each port in the last month, including the port name and the total cargo weight?
CREATE TABLE Port (port_name VARCHAR(50),dock_count INT); INSERT INTO Port VALUES ('Port of Oakland',12),('Port of Los Angeles',15),('Port of Seattle',10),('Port of Tacoma',13),('Port of Vancouver',14); CREATE TABLE Cargo (cargo_id INT,cargo_weight FLOAT,vessel_name VARCHAR(50),dock_date DATE); INSERT INTO Cargo VALUES (1,5000,'Vessel A','2022-03-05'),(2,8000,'Vessel B','2022-03-10'),(3,6000,'Vessel C','2022-03-15'),(4,7000,'Vessel D','2022-03-20'),(5,9000,'Vessel E','2022-03-25'),(6,4000,'Vessel F','2022-03-28'),(7,3000,'Vessel G','2022-03-30');
SELECT P.port_name, SUM(C.cargo_weight) as total_cargo_weight FROM Port P INNER JOIN Cargo C ON 1=1 WHERE C.dock_date >= DATEADD(MONTH, -1, GETDATE()) GROUP BY P.port_name;
Identify the number of cultural heritage sites in Japan with virtual tours.
CREATE TABLE CulturalHeritage (site_id INT,site_name VARCHAR(50),country VARCHAR(50),has_virtual_tour BOOLEAN); INSERT INTO CulturalHeritage (site_id,site_name,country,has_virtual_tour) VALUES (1,'Temple of Izumo','Japan',true);
SELECT COUNT(*) FROM CulturalHeritage WHERE country = 'Japan' AND has_virtual_tour = true;
What is the average depth of marine species habitats?
CREATE TABLE marine_species (species_name VARCHAR(50),avg_depth FLOAT); INSERT INTO marine_species (species_name,avg_depth) VALUES ('Clownfish',5.0),('Blue Whale',200.0);
SELECT AVG(avg_depth) FROM marine_species;
Identify faculty members in the Humanities department who have not received any research grants.
CREATE TABLE grants (id INT,faculty_id INT,title VARCHAR(100),amount DECIMAL(10,2)); INSERT INTO grants (id,faculty_id,title,amount) VALUES (1,1,'Research Grant 1',50000),(2,2,'Research Grant 2',75000),(3,3,'Research Grant 3',80000); CREATE TABLE faculty (id INT,name VARCHAR(50),department VARCHAR(50)); INSERT INTO faculty (id,name,department) VALUES (1,'Fiona','Natural Sciences'),(2,'Gabriel','Computer Science'),(3,'Heidi','Humanities'),(4,'Ivan','Humanities'),(5,'Jasmine','Humanities');
SELECT f.name FROM faculty f LEFT JOIN grants g ON f.id = g.faculty_id WHERE f.department = 'Humanities' AND g.id IS NULL;
What is the percentage of male and female fans in the stadium?
CREATE TABLE fan_demographics_by_game (id INT,game_id INT,gender VARCHAR(50),count INT); INSERT INTO fan_demographics_by_game (id,game_id,gender,count) VALUES (1,1,'Male',2000),(2,1,'Female',3000),(3,2,'Male',1500),(4,2,'Female',4000);
SELECT game_id, gender, 100.0*SUM(count) / (SELECT SUM(count) FROM fan_demographics_by_game WHERE game_id = f.game_id) as percentage FROM fan_demographics_by_game f GROUP BY game_id, gender;
Which programs had the most volunteer hours in Q2 2022?
CREATE TABLE programs (id INT,name TEXT,hours DECIMAL,program_date DATE);
SELECT name, SUM(hours) as total_hours FROM programs WHERE program_date >= '2022-04-01' AND program_date < '2022-07-01' GROUP BY name ORDER BY total_hours DESC;
What is the total budget for programs in Africa and Asia?
CREATE TABLE Programs (id INT,name TEXT,region TEXT,budget FLOAT); INSERT INTO Programs (id,name,region,budget) VALUES (1,'Education','Africa',1000.0),(2,'Healthcare','Asia',2000.0);
SELECT SUM(budget) FROM Programs WHERE region IN ('Africa', 'Asia');
Which climate mitigation initiatives in the Caribbean were initiated after 2017, and what is their total investment?
CREATE TABLE climate_mitigation (initiative VARCHAR(50),region VARCHAR(50),start_year INT,investment FLOAT); INSERT INTO climate_mitigation (initiative,region,start_year,investment) VALUES ('Energy Efficiency','Caribbean',2018,500000),('Green Buildings','Caribbean',2019,700000);
SELECT initiative, region, SUM(investment) as total_investment FROM climate_mitigation WHERE region = 'Caribbean' AND start_year > 2017 GROUP BY initiative;
Identify the well with the lowest daily production in the past month
CREATE TABLE production (well_id INT,date DATE,quantity FLOAT); INSERT INTO production (well_id,date,quantity) VALUES (1,'2021-01-01',100.0),(1,'2021-01-02',120.0),(2,'2021-01-01',150.0);
SELECT well_id, MIN(quantity) FROM production WHERE date >= DATEADD(month, -1, CURRENT_DATE) GROUP BY well_id ORDER BY MIN(quantity) LIMIT 1;
What is the distribution of genres in movies produced in the UK?
CREATE TABLE movies (id INT,title VARCHAR(255),genre VARCHAR(50),production_year INT,country VARCHAR(50)); INSERT INTO movies (id,title,genre,production_year,country) VALUES (1,'Movie1','Action',2015,'UK'),(2,'Movie2','Drama',2018,'USA'),(3,'Movie3','Comedy',2012,'UK');
SELECT genre, COUNT(*) as count FROM movies WHERE country = 'UK' GROUP BY genre;
Delete users who have not played any game in the last month.
CREATE TABLE user_actions (user_id INT,game_id INT,action_date DATE);
DELETE u FROM users u LEFT JOIN user_actions a ON u.id = a.user_id WHERE a.user_id IS NULL AND u.last_login_date < DATE_SUB(CURDATE(), INTERVAL 1 MONTH);
What is the total funding for astrobiology projects in the last 5 years?
CREATE TABLE astrobiology_funding (year INT,amount FLOAT); INSERT INTO astrobiology_funding (year,amount) VALUES (2017,1200000),(2018,1500000),(2019,1800000),(2020,2000000),(2021,2500000);
SELECT SUM(amount) FROM astrobiology_funding WHERE year BETWEEN 2017 AND 2021;
List the names and types of all farms in the 'farming' database that use sustainable practices.
CREATE TABLE farm (id INT,name VARCHAR(255),type VARCHAR(255),sustainability VARCHAR(255)); INSERT INTO farm (id,name,type,sustainability) VALUES (1,'Smith Farm','organic','sustainable'),(2,'Johnson Farm','conventional','non-sustainable'),(3,'Brown Farm','organic','sustainable'),(4,'Davis Farm','conventional','non-sustainable');
SELECT name, type FROM farm WHERE sustainability = 'sustainable';
Delete all employees who have 'Senior' in their job title from the Employee table
CREATE TABLE Employee (EmployeeID INT PRIMARY KEY,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50),JobTitle VARCHAR(50),LastActivity DATETIME);
DELETE FROM Employee WHERE JobTitle LIKE '%Senior%';
What are the sales for a specific product in a specific month?
CREATE TABLE if not exists sales (id INT PRIMARY KEY,product_id INT,purchase_date DATE,quantity INT,price DECIMAL(5,2)); INSERT INTO sales (id,product_id,purchase_date,quantity,price) VALUES (3,1,'2022-02-01',2,12.99); CREATE TABLE if not exists product (id INT PRIMARY KEY,name TEXT,brand_id INT,price DECIMAL(5,2)); INSERT INTO product (id,name,brand_id,price) VALUES (1,'Solid Shampoo Bar',1,12.99);
SELECT SUM(quantity * price) FROM sales WHERE product_id = 1 AND EXTRACT(MONTH FROM purchase_date) = 2;
What is the average response time for emergency calls in the "downtown" region?
CREATE TABLE EmergencyCalls (id INT,region VARCHAR(20),response_time INT);
SELECT AVG(response_time) FROM EmergencyCalls WHERE region = 'downtown';
What are the products with a quantity below 25 at the Hong Kong warehouse?
CREATE TABLE Inventory (InventoryID INT,WarehouseID INT,ProductID INT,Quantity INT); INSERT INTO Inventory (InventoryID,WarehouseID,ProductID,Quantity) VALUES (3,3,3,50); INSERT INTO Inventory (InventoryID,WarehouseID,ProductID,Quantity) VALUES (4,3,4,30);
SELECT p.ProductName, i.Quantity FROM Inventory i JOIN Products p ON i.ProductID = p.ProductID WHERE i.WarehouseID = 3 AND i.Quantity < 25;
List the top 5 ingredients sourced from sustainable suppliers for skincare products in the USA.
CREATE TABLE ingredients (product_id INT,ingredient_name VARCHAR(50),is_sustainable BOOLEAN,supplier_country VARCHAR(50)); INSERT INTO ingredients (product_id,ingredient_name,is_sustainable,supplier_country) VALUES (101,'Jojoba Oil',true,'USA'),(102,'Shea Butter',true,'Ghana'),(103,'Rosehip Oil',false,'Chile'),(104,'Aloe Vera',true,'Mexico'),(105,'Coconut Oil',true,'Philippines');
SELECT ingredient_name, supplier_country FROM ingredients WHERE is_sustainable = true AND supplier_country = 'USA' LIMIT 5;
What is the total weight of meat and dairy products ordered by a specific customer?
CREATE TABLE orders (id INT,customer_id INT,order_date DATE,product_type VARCHAR(255),weight INT); INSERT INTO orders (id,customer_id,order_date,product_type,weight) VALUES (1,1001,'2022-01-01','Meat',1000),(2,1001,'2022-01-01','Dairy',500),(3,1001,'2022-01-02','Meat',1500);
SELECT SUM(weight) FROM orders WHERE customer_id = 1001 AND (product_type = 'Meat' OR product_type = 'Dairy');
Delete records of athletes from the 'hockey_athletes' table who have not participated in the Olympics?
CREATE TABLE hockey_athletes (athlete_id INT,name VARCHAR(50),age INT,position VARCHAR(50),team VARCHAR(50),participated_in_olympics INT);
DELETE FROM hockey_athletes WHERE participated_in_olympics = 0;
What is the maximum number of personnel that can be deployed by each military technology?
CREATE TABLE Military_Technologies (Name VARCHAR(255),Max_Personnel INT); INSERT INTO Military_Technologies (Name,Max_Personnel) VALUES ('M1 Abrams',4),('AH-64 Apache',2),('M2 Bradley',3);
SELECT Name, Max_Personnel FROM Military_Technologies ORDER BY Max_Personnel DESC;
Identify artists who have had their works exhibited in more than one country but have never had their works sold at auctions.
CREATE TABLE Artists (artist_id INT,artist_name VARCHAR(50)); INSERT INTO Artists (artist_id,artist_name) VALUES (1,'Picasso'),(2,'Warhol'),(3,'Matisse'),(4,'Banksy'); CREATE TABLE Exhibitions (exhibit_id INT,artist_name VARCHAR(50),city VARCHAR(20)); INSERT INTO Exhibitions (exhibit_id,artist_name,city) VALUES (1,'Picasso','New York'),(2,'Warhol','London'),(3,'Matisse','New York'),(4,'Banksy','London'); CREATE TABLE Auctions (auction_id INT,artist_name VARCHAR(50)); INSERT INTO Auctions (auction_id,artist_name) VALUES (1,'Picasso'),(2,'Warhol'),(3,'Matisse');
SELECT artist_name FROM Artists WHERE artist_name NOT IN (SELECT artist_name FROM Auctions) INTERSECT SELECT artist_name FROM Exhibitions GROUP BY artist_name HAVING COUNT(DISTINCT city) > 1;
What is the average smart city technology adoption rate in Asia?
CREATE TABLE Cities (id INT,region VARCHAR(20),adoption_rate FLOAT); INSERT INTO Cities (id,region,adoption_rate) VALUES (1,'CityA',0.65),(2,'CityB',0.78),(3,'CityC',0.92);
SELECT AVG(adoption_rate) FROM Cities WHERE region = 'Asia';
How many products are made from organic cotton by each brand?
CREATE TABLE Brands (BrandID INT,BrandName VARCHAR(50)); INSERT INTO Brands (BrandID,BrandName) VALUES (1,'BrandX'),(2,'BrandY'),(3,'BrandZ'); CREATE TABLE Products (ProductID INT,ProductName VARCHAR(50),BrandID INT,OrganicCotton INT); INSERT INTO Products (ProductID,ProductName,BrandID,OrganicCotton) VALUES (1,'ProductA',1,1),(2,'ProductB',1,0),(3,'ProductC',2,1),(4,'ProductD',2,0),(5,'ProductE',3,1),(6,'ProductF',3,1);
SELECT BrandName, SUM(OrganicCotton) as TotalOrganicCotton FROM Brands b JOIN Products p ON b.BrandID = p.BrandID GROUP BY BrandName;
What is the total number of polar bear sightings in each region?
CREATE TABLE polar_bear_sightings (id INT,date DATE,region VARCHAR(255));
SELECT region, COUNT(*) FROM polar_bear_sightings GROUP BY region;
What is the total biomass of all mammal species in the Arctic tundra?
CREATE TABLE Biomass (species VARCHAR(50),habitat VARCHAR(50),biomass FLOAT); INSERT INTO Biomass (species,habitat,biomass) VALUES ('Arctic Fox','Tundra',1.5); INSERT INTO Biomass (species,habitat,biomass) VALUES ('Reindeer','Tundra',120); INSERT INTO Biomass (species,habitat,biomass) VALUES ('Polar Bear','Tundra',650);
SELECT SUM(biomass) FROM Biomass WHERE habitat = 'Tundra';
What is the total contract amount for each vendor in 2021?
CREATE TABLE defense_contracts (contract_id INT,vendor VARCHAR(50),contract_amount DECIMAL(10,2),contract_date DATE);INSERT INTO defense_contracts (contract_id,vendor,contract_amount,contract_date) VALUES (1,'XYZ Defense Inc.',7000000.00,'2021-04-01');
SELECT vendor, SUM(contract_amount) FROM defense_contracts WHERE contract_date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY vendor;
What is the total number of renewable energy projects in each country and their total installed capacity (in kW)?
CREATE TABLE renewable_projects (project_id INT,project_name VARCHAR(255),capacity_kW INT,country VARCHAR(255)); INSERT INTO renewable_projects (project_id,project_name,capacity_kW,country) VALUES (1,'Solar Farm 1',1000,'USA'); INSERT INTO renewable_projects (project_id,project_name,capacity_kW,country) VALUES (2,'Wind Farm 1',2000,'Canada'); INSERT INTO renewable_projects (project_id,project_name,capacity_kW,country) VALUES (3,'Solar Farm 2',3000,'Mexico');
SELECT country, COUNT(*), SUM(capacity_kW) as total_capacity_kW FROM renewable_projects GROUP BY country;
List policy numbers and claim amounts for policyholders living in 'California' or 'Florida' who have filed a claim.
CREATE TABLE Policies (PolicyNumber INT,PolicyholderID INT,PolicyState VARCHAR(20)); CREATE TABLE Claims (PolicyholderID INT,ClaimAmount DECIMAL(10,2),PolicyState VARCHAR(20)); INSERT INTO Policies (PolicyNumber,PolicyholderID,PolicyState) VALUES (1001,3,'California'),(1002,4,'California'),(1003,5,'Florida'); INSERT INTO Claims (PolicyholderID,ClaimAmount,PolicyState) VALUES (3,500,'California'),(4,200,'Texas'),(5,300,'Florida');
SELECT Policies.PolicyNumber, Claims.ClaimAmount FROM Policies JOIN Claims ON Policies.PolicyholderID = Claims.PolicyholderID WHERE Policies.PolicyState IN ('California', 'Florida');
Identify the states with the highest wastewater treatment plant construction rates between 2005 and 2015, excluding California.
CREATE TABLE wastewater_plants(state VARCHAR(20),year INT,num_plants INT); INSERT INTO wastewater_plants VALUES ('California',2005,10),('California',2006,12),('California',2007,14),('New York',2005,5),('New York',2006,6),('New York',2007,7),('Texas',2005,15),('Texas',2006,17),('Texas',2007,19);
SELECT state, AVG(num_plants) AS avg_construction_rate FROM wastewater_plants WHERE state != 'California' AND year BETWEEN 2005 AND 2007 GROUP BY state ORDER BY avg_construction_rate DESC LIMIT 2;
Update the market capitalization of 'Asset3' to 9000000.
CREATE TABLE digital_asset (id INT,name VARCHAR(255),category VARCHAR(255)); CREATE TABLE market_capitalization (id INT,asset_id INT,value INT); INSERT INTO digital_asset (id,name,category) VALUES (1,'Asset1','Crypto'),(2,'Asset2','Crypto'),(3,'Asset3','Security'),(4,'Asset4','Security'),(5,'Asset5','Stablecoin'); INSERT INTO market_capitalization (id,asset_id,value) VALUES (1,1,1000000),(2,2,2000000),(3,3,3000000),(4,4,4000000),(5,5,5000000);
UPDATE market_capitalization SET value = 9000000 WHERE asset_id = (SELECT id FROM digital_asset WHERE name = 'Asset3');
List all environmental impact assessments by year and their total CO2 emissions.
CREATE TABLE environmental_assessments (assessment_id INT,year INT,co2_emissions INT); INSERT INTO environmental_assessments (assessment_id,year,co2_emissions) VALUES (1,2018,5000),(2,2019,6000),(3,2020,7000);
SELECT year, SUM(co2_emissions) FROM environmental_assessments GROUP BY year;
What is the total number of high-impact investments in the renewable energy sector?
CREATE TABLE Investments (InvestmentID INT,Sector VARCHAR(50),ImpactRating INT,Amount FLOAT); INSERT INTO Investments (InvestmentID,Sector,ImpactRating,Amount) VALUES (1,'Renewable Energy',3,10000),(2,'Renewable Energy',2,15000),(3,'Technology',4,20000);
SELECT SUM(Amount) FROM Investments WHERE Sector = 'Renewable Energy' AND ImpactRating = 3;
Add a new music consumption record 'Spotify' with 100 listens and artist_id 3 in the music_consumption table
CREATE TABLE music_consumption (id INT,platform VARCHAR(50),listens INT,artist_id INT);
INSERT INTO music_consumption (platform, listens, artist_id) VALUES ('Spotify', 100, 3);
What is the average number of containers handled per day by vessels in the South China Sea in Q2 2020?
CREATE TABLE Vessel_Stats (vessel_name TEXT,location TEXT,handling_date DATE,containers_handled INTEGER); INSERT INTO Vessel_Stats (vessel_name,location,handling_date,containers_handled) VALUES ('VesselA','South China Sea','2020-04-01',50),('VesselB','South China Sea','2020-04-02',75),('VesselC','South China Sea','2020-05-01',65),('VesselD','South China Sea','2020-05-02',80);
SELECT AVG(containers_handled/30.0) FROM Vessel_Stats WHERE location = 'South China Sea' AND handling_date >= '2020-04-01' AND handling_date <= '2020-06-30';
Find the maximum number of artworks created by an individual artist
CREATE TABLE Artists (ArtistID INT PRIMARY KEY,ArtistName VARCHAR(255),NumberOfArtworks INT); INSERT INTO Artists (ArtistID,ArtistName,NumberOfArtworks) VALUES (1,'Vincent van Gogh',2100),(2,'Pablo Picasso',1347),(3,'Claude Monet',1643),(4,'Jackson Pollock',287);
SELECT MAX(NumberOfArtworks) AS MaxArtworks FROM Artists;
Who are the top three funded biotech startups in Canada?
CREATE SCHEMA if not exists biotech; CREATE TABLE if not exists biotech.startups (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),funding FLOAT); INSERT INTO biotech.startups (id,name,location,funding) VALUES (1,'StartupA','Canada',8000000),(2,'StartupB','Canada',6000000),(3,'StartupC','USA',5000000),(4,'StartupD','Canada',9000000);
SELECT name, funding FROM biotech.startups WHERE location = 'Canada' ORDER BY funding DESC LIMIT 3;
What is the total number of players who prefer VR technology?
CREATE TABLE PlayerPreferences (PlayerID INT,VRPreference INT); INSERT INTO PlayerPreferences (PlayerID,VRPreference) VALUES (1,1),(2,0),(3,1),(4,0);
SELECT COUNT(*) FROM PlayerPreferences WHERE VRPreference = 1;
What are the names and years of all modern art movements?
CREATE TABLE modern_art_movements (name TEXT,year INTEGER); INSERT INTO modern_art_movements (name,year) VALUES ('Cubism',1907),('Fauvism',1904),('Expressionism',1905);
SELECT name, year FROM modern_art_movements;
Which defense projects have a start date after 2020-01-01 and a budget over 5 million?
CREATE TABLE Defense_Projects (project_id INT,start_year INT,budget FLOAT); INSERT INTO Defense_Projects (project_id,start_year,budget) VALUES (1,2021,6000000),(2,2022,7000000);
SELECT project_id, start_year, budget FROM Defense_Projects WHERE start_year > 2020 AND budget > 5000000;
What is the total installed capacity of wind energy projects in the state of Texas, grouped by project type?
CREATE TABLE wind_energy (project_id INT,project_name VARCHAR(255),state VARCHAR(255),project_type VARCHAR(255),installed_capacity FLOAT);
SELECT project_type, SUM(installed_capacity) FROM wind_energy WHERE state = 'Texas' GROUP BY project_type;
Update the union affiliation for a specific workplace.
CREATE TABLE workplaces (id INT,name TEXT,safety_violation BOOLEAN,union_affiliation TEXT); INSERT INTO workplaces (id,name,safety_violation,union_affiliation) VALUES (1,'ABC Company',TRUE,'Union A'),(2,'XYZ Corporation',FALSE,'Union B'),(3,'LMN Industries',TRUE,'Union A');
UPDATE workplaces SET union_affiliation = 'Union C' WHERE id = 1;
List all the unique investment strategies and their descriptions.
CREATE TABLE investment_strategies (strategy_id INT,strategy_description TEXT); INSERT INTO investment_strategies (strategy_id,strategy_description) VALUES (1,'Impact first investing'),(2,'Financial first investing'),(3,'Diversified investing');
SELECT DISTINCT strategy_id, strategy_description FROM investment_strategies;
What is the average speed of vessels that arrived in the US east coast ports in January 2020?
CREATE TABLE ports (id INT,name TEXT,country TEXT); INSERT INTO ports (id,name,country) VALUES (1,'New York','USA'),(2,'Baltimore','USA'); CREATE TABLE vessels (id INT,name TEXT,model TEXT,port_id INT); INSERT INTO vessels (id,name,model,port_id) VALUES (1,'TestVessel1','ModelA',1),(2,'TestVessel2','ModelB',2); CREATE TABLE vessel_positions (id INT,vessel_id INT,timestamp TIMESTAMP,latitude DECIMAL,longitude DECIMAL,speed DECIMAL); INSERT INTO vessel_positions (id,vessel_id,timestamp,latitude,longitude,speed) VALUES (1,1,'2020-01-01 12:00:00',40.71,-74.01,20),(2,2,'2020-01-02 10:00:00',39.29,-76.61,18);
SELECT AVG(vp.speed) FROM vessel_positions vp JOIN vessels v ON vp.vessel_id = v.id JOIN ports p ON v.port_id = p.id WHERE p.country = 'USA' AND EXTRACT(MONTH FROM vp.timestamp) = 1;
Find the top 3 categories with the highest revenue
CREATE TABLE sales (category VARCHAR(255),revenue DECIMAL(10,2)); INSERT INTO sales (category,revenue) VALUES ('Appetizers',1784.1),('Entrees',4318.8),('Desserts',3381.7);
SELECT category, revenue FROM sales ORDER BY revenue DESC LIMIT 3;
Which artworks by artists from India were exhibited in museums in London?
CREATE TABLE Artists (ArtistID INT PRIMARY KEY,Name VARCHAR(255),Nationality VARCHAR(255)); CREATE TABLE Artworks (ArtworkID INT PRIMARY KEY,Title VARCHAR(255),ArtistID INT,Year INT); CREATE TABLE Exhibitions (ExhibitionID INT PRIMARY KEY,Name VARCHAR(255),StartDate DATE,EndDate DATE,MuseumID INT); CREATE TABLE Museums (MuseumID INT PRIMARY KEY,Name VARCHAR(255),City VARCHAR(255)); CREATE TABLE ExhibitionArtworks (ExhibitionID INT,ArtworkID INT);
SELECT Artworks.Title FROM Artists INNER JOIN Artworks ON Artists.ArtistID = Artworks.ArtistID INNER JOIN ExhibitionArtworks ON Artworks.ArtworkID = ExhibitionArtworks.ArtworkID INNER JOIN Exhibitions ON ExhibitionArtworks.ExhibitionID = Exhibitions.ExhibitionID INNER JOIN Museums ON Exhibitions.MuseumID = Museums.MuseumID WHERE Artists.Nationality = 'Indian' AND Museums.City = 'London';
What is the number of students who have completed each course in the professional_development table, and what is the overall pass rate for all courses?
CREATE TABLE courses (course_id INT,course_name TEXT,course_type TEXT); CREATE TABLE professional_development (pd_id INT,course_id INT,student_id INT,pass_fail TEXT);
SELECT c.course_name, COUNT(p.student_id) as num_students, (SELECT COUNT(*) FROM professional_development p WHERE p.pass_fail = 'PASS' AND p.course_id = c.course_id) as num_passed FROM courses c JOIN professional_development p ON c.course_id = p.course_id GROUP BY c.course_name; SELECT (SELECT COUNT(*) FROM professional_development p WHERE p.pass_fail = 'PASS') / COUNT(*) as overall_pass_rate FROM professional_development;
How many chemical spills occurred in the northwest region in the past year, excluding spills from the month of July?
CREATE TABLE spills (id INT,date DATE,location TEXT,chemical TEXT); INSERT INTO spills (id,date,location,chemical) VALUES (1,'2022-01-01','Oregon','Acetone'),(2,'2022-02-15','Washington','Ammonia'),(3,'2022-07-05','Idaho','Benzene');
SELECT COUNT(*) AS num_spills FROM spills WHERE location LIKE 'Northwest%' AND date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) AND EXTRACT(MONTH FROM date) != 7;
Update the 'Members' table to add a new column 'MembershipEndDate' and set the value as NULL
CREATE TABLE Members (MemberID INT,MemberName VARCHAR(50),JoinDate DATETIME,MembershipEndDate DATETIME);
ALTER TABLE Members ADD MembershipEndDate DATETIME; UPDATE Members SET MembershipEndDate = NULL;
What are the total revenues for vegetarian and non-vegetarian menu items?
CREATE TABLE Menu (menu_id INT,item_name TEXT,price DECIMAL,vegetarian BOOLEAN); INSERT INTO Menu (menu_id,item_name,price,vegetarian) VALUES (1,'Hamburger',5.99,false),(2,'Cheeseburger',6.49,false),(3,'Fries',2.49,null),(4,'Salad',4.99,true),(5,'Pizza',7.99,false);
SELECT SUM(price) as total_revenue FROM Menu WHERE vegetarian = true; SELECT SUM(price) as total_revenue FROM Menu WHERE vegetarian = false;
What is the average waste generation rate per capita in Australia and Canada?
CREATE TABLE Population (country VARCHAR(255),population INT); INSERT INTO Population (country,population) VALUES ('Australia',25499703),('Canada',37410003); CREATE TABLE WasteGeneration (country VARCHAR(255),generation_rate FLOAT); INSERT INTO WasteGeneration (country,generation_rate) VALUES ('Australia',21.3),('Canada',18.5);
SELECT AVG(generation_rate/population*1000000) FROM Population, WasteGeneration WHERE Population.country IN ('Australia', 'Canada') AND WasteGeneration.country = Population.country
List the average labor costs for construction projects in California in 2022.
CREATE TABLE labor_costs (project_id INT,location VARCHAR(100),labor_cost FLOAT,year INT); INSERT INTO labor_costs (project_id,location,labor_cost,year) VALUES (1,'California',20000,2022),(2,'New York',25000,2022),(3,'Texas',18000,2022);
SELECT AVG(labor_cost) FROM labor_costs WHERE location = 'California' AND year = 2022;
What is the total number of regulatory frameworks in place, and for which regions are they applicable?
CREATE TABLE RegulatoryFrameworksByRegion (FrameworkRegion VARCHAR(50),FrameworkCount INT); INSERT INTO RegulatoryFrameworksByRegion (FrameworkRegion,FrameworkCount) VALUES ('APAC',2),('Europe',1),('North America',3); ALTER TABLE RegulatoryFrameworksByRegion ADD COLUMN FrameworkRegion VARCHAR(50);
SELECT FrameworkRegion, FrameworkCount FROM RegulatoryFrameworksByRegion;
Find the total area (in hectares) of organic farming for each country in 2020.
CREATE TABLE countries (id INT,name VARCHAR(255)); INSERT INTO countries (id,name) VALUES (1,'USA'),(2,'Canada'); CREATE TABLE organic_farming (country_id INT,year INT,area_ha INT); INSERT INTO organic_farming (country_id,year,area_ha) VALUES (1,2020,1000),(1,2019,800),(2,2020,1500),(2,2019,1200);
SELECT c.name, SUM(of.area_ha) as total_area_2020 FROM countries c JOIN organic_farming of ON c.id = of.country_id WHERE of.year = 2020 GROUP BY c.name;
Determine the total number of ambulances and medical helicopters in rural areas
CREATE TABLE ambulances (id INT,type VARCHAR(15),location VARCHAR(10)); INSERT INTO ambulances VALUES (1,'ground','rural'); INSERT INTO ambulances VALUES (2,'helicopter','rural')
SELECT COUNT(*) FROM ambulances WHERE location = 'rural' AND type IN ('ground', 'helicopter')
What is the average cultural competency score for mental health facilities in Indigenous areas?
CREATE TABLE mental_health_facilities (facility_id INT,location TEXT,score INT); INSERT INTO mental_health_facilities (facility_id,location,score) VALUES (1,'Urban',80),(2,'Rural',75),(3,'Indigenous',90);
SELECT AVG(score) FROM mental_health_facilities WHERE location = 'Indigenous';
Find the three sites with the highest chemical waste production and their corresponding ranks, in South America.
CREATE TABLE chemical_waste (site_name VARCHAR(50),waste_amount FLOAT,region VARCHAR(50)); INSERT INTO chemical_waste (site_name,waste_amount,region) VALUES ('Site A',150.5,'South America'),('Site B',125.7,'South America'),('Site C',200.3,'South America'),('Site D',75.9,'South America'),('Site E',175.4,'South America');
SELECT site_name, waste_amount, RANK() OVER (PARTITION BY region ORDER BY waste_amount DESC) as waste_rank FROM chemical_waste WHERE region = 'South America' AND waste_rank <= 3;
Count the number of vessels in the 'Passenger' category with a loading capacity greater than 50000 tons
CREATE TABLE Vessels (VesselID INT,Category VARCHAR(50),LoadingCapacity FLOAT); INSERT INTO Vessels (VesselID,Category,LoadingCapacity) VALUES (1,'Cargo',80000),(2,'Passenger',65000),(3,'Cargo',55000),(4,'Passenger',48000),(5,'Passenger',72000),(6,'Cargo',30000);
SELECT COUNT(*) FROM Vessels WHERE Category = 'Passenger' AND LoadingCapacity > 50000;
Which countries have had the most defense contracts awarded to women-owned businesses in the past 6 months?
CREATE TABLE defense_contracts (id INT,contract_date DATE,contract_value FLOAT,business_id INT,business_owner_gender VARCHAR(255),business_location VARCHAR(255)); INSERT INTO defense_contracts (id,contract_date,contract_value,business_id,business_owner_gender,business_location) VALUES (1,'2022-01-01',10000,1,'Female','United States'); INSERT INTO defense_contracts (id,contract_date,contract_value,business_id,business_owner_gender,business_location) VALUES (2,'2022-02-15',5000,1,'Female','Canada'); INSERT INTO defense_contracts (id,contract_date,contract_value,business_id,business_owner_gender,business_location) VALUES (3,'2022-03-01',20000,2,'Male','United Kingdom');
SELECT business_location, COUNT(*) as num_contracts FROM defense_contracts WHERE business_owner_gender = 'Female' AND contract_date >= DATEADD(month, -6, GETDATE()) GROUP BY business_location ORDER BY num_contracts DESC;
What is the total energy consumption (in GWh) by country, for the years 2017 to 2020, broken down by energy source?
CREATE TABLE energy_consumption (country VARCHAR(255),year INT,energy_source VARCHAR(255),consumption DECIMAL(10,2));
SELECT energy_source, SUM(consumption) FROM energy_consumption WHERE year IN (2017, 2018, 2019, 2020) GROUP BY energy_source;
How many water quality violations were there in each state in the year 2021?
CREATE TABLE water_quality_violations(violation_id INT,violation_date DATE,state TEXT); INSERT INTO water_quality_violations(violation_id,violation_date,state) VALUES (1,'2021-01-01','California'),(2,'2021-02-01','Texas'),(3,'2021-03-01','Florida'),(4,'2021-04-01','California'),(5,'2021-05-01','Texas');
SELECT state, COUNT(*) FROM water_quality_violations WHERE YEAR(violation_date) = 2021 GROUP BY state;
What is the total renewable energy consumption for the year 2019?
CREATE TABLE energy_consumption_data (id INT,year INT,renewable_energy_consumption DECIMAL); INSERT INTO energy_consumption_data (id,year,renewable_energy_consumption) VALUES (1,2019,4567.8); INSERT INTO energy_consumption_data (id,year,renewable_energy_consumption) VALUES (2,2020,5678.9);
SELECT SUM(renewable_energy_consumption) FROM energy_consumption_data WHERE year = 2019;
List policy numbers and claim amounts for policyholders living in 'Ontario' who have filed a claim.
CREATE TABLE Policies (PolicyNumber INT,PolicyholderID INT,PolicyState VARCHAR(20)); CREATE TABLE Claims (PolicyholderID INT,ClaimAmount DECIMAL(10,2),PolicyState VARCHAR(20)); INSERT INTO Policies (PolicyNumber,PolicyholderID,PolicyState) VALUES (2001,9,'Ontario'),(2002,10,'Ontario'); INSERT INTO Claims (PolicyholderID,ClaimAmount,PolicyState) VALUES (9,800,'Ontario'),(10,900,'Ontario');
SELECT Policies.PolicyNumber, Claims.ClaimAmount FROM Policies JOIN Claims ON Policies.PolicyholderID = Claims.PolicyholderID WHERE Policies.PolicyState = 'Ontario';
Update address in 'rural_clinics' where id=1
CREATE TABLE if not exists 'rural_clinics' (id INT,name TEXT,address TEXT,PRIMARY KEY(id));
UPDATE 'rural_clinics' SET address = 'New Address' WHERE id = 1;
What is the average quantity of sustainable fabric sourced from the USA?
CREATE TABLE sourcing (id INT,fabric_type VARCHAR(20),quantity INT,country VARCHAR(20)); INSERT INTO sourcing (id,fabric_type,quantity,country) VALUES (1,'organic_cotton',500,'USA'); INSERT INTO sourcing (id,fabric_type,quantity,country) VALUES (2,'recycled_polyester',300,'China');
SELECT AVG(quantity) FROM sourcing WHERE fabric_type = 'organic_cotton' AND country = 'USA';
How many virtual tours are available for each city?
CREATE TABLE cities (city_id INT,name VARCHAR(255),country VARCHAR(255)); CREATE TABLE virtual_tours (virtual_tour_id INT,name VARCHAR(255),location VARCHAR(255),city_id INT); INSERT INTO cities (city_id,name,country) VALUES (1,'Rome','Italy'),(2,'Athens','Greece'); INSERT INTO virtual_tours (virtual_tour_id,name,location,city_id) VALUES (1,'Rome Virtual Tour','Rome',1),(2,'Ancient Rome Virtual Tour','Rome',1),(3,'Athens Virtual Tour','Athens',2);
SELECT c.name, COUNT(v.virtual_tour_id) AS num_tours FROM cities c LEFT JOIN virtual_tours v ON c.city_id = v.city_id GROUP BY c.name;
Delete all concert records with a price greater than 500.
CREATE TABLE concert_sales (id INT,price DECIMAL);
DELETE FROM concert_sales WHERE price > 500;
What is the percentage of employees who have completed compliance training, by department and gender?
CREATE TABLE Employees (EmployeeID int,FirstName varchar(50),LastName varchar(50),Department varchar(50),Gender varchar(50),ComplianceTraining bit); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,Gender,ComplianceTraining) VALUES (1,'John','Doe','IT','Male',1),(2,'Jane','Doe','IT','Female',1),(3,'Jim','Smith','HR','Non-binary',0);
SELECT Employees.Department, Employees.Gender, COUNT(CASE WHEN Employees.ComplianceTraining = 1 THEN 1 ELSE NULL END) as Completed_Training, COUNT(Employees.EmployeeID) as Total_Employees, COUNT(CASE WHEN Employees.ComplianceTraining = 1 THEN 1 ELSE NULL END) * 100.0 / COUNT(Employees.EmployeeID) as Percentage_Completed FROM Employees GROUP BY Employees.Department, Employees.Gender;
What is the total number of professional development courses completed by teachers in each subject area, and what is the maximum mental health score for students in each district?
CREATE TABLE teachers (teacher_id INT,teacher_name TEXT,subject_area TEXT,courses_completed INT); INSERT INTO teachers (teacher_id,teacher_name,subject_area,courses_completed) VALUES (1,'Sonia','Math',5),(2,'Tariq','Science',3),(3,'Ella','English',7),(4,'Victor','Math',2),(5,'Kiara','Science',4); CREATE TABLE students (student_id INT,student_name TEXT,district_id INT,mental_health_score INT,subject_area TEXT); INSERT INTO students (student_id,student_name,district_id,mental_health_score,subject_area) VALUES (1,'Jamie',1,75,'Math'),(2,'Noah',2,80,'Science'),(3,'Avery',3,70,'English'),(4,'Sophia',1,85,'Math'),(5,'Liam',3,88,'English');
SELECT teachers.subject_area, COUNT(teachers.courses_completed) AS total_courses, MAX(students.mental_health_score) AS max_mental_health_score FROM teachers JOIN students ON teachers.subject_area = students.subject_area GROUP BY teachers.subject_area;
Insert a new crime record for the 'Southside' district with a date of '2022-01-01'.
CREATE TABLE districts (district_id INT,district_name TEXT);CREATE TABLE crimes (crime_id INT,district_id INT,crime_date DATE);
INSERT INTO crimes (crime_id, district_id, crime_date) SELECT NULL, (SELECT district_id FROM districts WHERE district_name = 'Southside'), '2022-01-01';
Find the three sites with the highest chemical waste production and their corresponding ranks.
CREATE TABLE chemical_waste (site_name VARCHAR(50),waste_amount FLOAT); INSERT INTO chemical_waste (site_name,waste_amount) VALUES ('Site A',150.5),('Site B',125.7),('Site C',200.3),('Site D',75.9),('Site E',175.4);
SELECT site_name, waste_amount, RANK() OVER (ORDER BY waste_amount DESC) as waste_rank FROM chemical_waste WHERE waste_rank <= 3;
What is the total quantity of fabric used by each textile supplier in the last 6 months?
CREATE TABLE FabricData (FabricID INT,SupplierID INT,FabricType TEXT,Quantity FLOAT,Sustainable BOOLEAN); INSERT INTO FabricData (FabricID,SupplierID,FabricType,Quantity,Sustainable) VALUES (1001,1,'Cotton',500,true),(1002,1,'Polyester',700,false),(1003,2,'Hemp',800,true);
SELECT SupplierID, SUM(Quantity) FROM FabricData WHERE FabricDate >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH) GROUP BY SupplierID;
What is the percentage of games won by team 'Black' in the eSports tournament?
CREATE TABLE eSports_games_2 (id INT,team1 TEXT,team2 TEXT,winner TEXT); INSERT INTO eSports_games_2 (id,team1,team2,winner) VALUES (1,'Black','White','Black'),(2,'Gray','Black','Gray'),(3,'Black','Red','Red');
SELECT (COUNT(*) FILTER (WHERE winner = 'Black')) * 100.0 / COUNT(*) FROM eSports_games_2 WHERE team1 = 'Black' OR team2 = 'Black';
How many medical supplies were delivered to region_id 3 in the medical_supplies table?
CREATE TABLE medical_supplies (id INT PRIMARY KEY,region_id INT,medical_supplies INT); INSERT INTO medical_supplies (id,region_id,medical_supplies) VALUES (1,1,1000); INSERT INTO medical_supplies (id,region_id,medical_supplies) VALUES (2,2,2000); INSERT INTO medical_supplies (id,region_id,medical_supplies) VALUES (3,3,3000);
SELECT SUM(medical_supplies) FROM medical_supplies WHERE region_id = 3;
How many climate mitigation initiatives were implemented in Arctic in 2021?
CREATE TABLE Initiatives (Year INT,Region VARCHAR(20),Status VARCHAR(20),Type VARCHAR(20)); INSERT INTO Initiatives (Year,Region,Status,Type) VALUES (2021,'Arctic','Implemented','Climate Mitigation');
SELECT COUNT(*) FROM Initiatives WHERE Year = 2021 AND Region = 'Arctic' AND Type = 'Climate Mitigation' AND Status = 'Implemented';
How many policyholders are there in California with auto insurance policies?
CREATE TABLE if NOT EXISTS policyholders (id INT,first_name VARCHAR(50),last_name VARCHAR(50),state VARCHAR(50),policy_type VARCHAR(50)); INSERT INTO policyholders (id,first_name,last_name,state,policy_type) VALUES (1,'John','Doe','California','Auto');
SELECT COUNT(*) FROM policyholders WHERE state = 'California' AND policy_type = 'Auto';
List the names and ages of all artists who have created more than 50 works.
CREATE TABLE artists (id INT,name TEXT,age INT,num_works INT); INSERT INTO artists (id,name,age,num_works) VALUES (1,'Picasso',56,550),(2,'Van Gogh',37,210),(3,'Monet',86,690);
SELECT name, age FROM artists WHERE num_works > 50;
List the number of restaurants in each city, grouped by cuisine.
CREATE TABLE Restaurants (restaurant_id INT,name TEXT,city TEXT,cuisine TEXT,revenue FLOAT); INSERT INTO Restaurants (restaurant_id,name,city,cuisine,revenue) VALUES (1,'Asian Fusion','New York','Asian',50000.00),(2,'Bella Italia','Los Angeles','Italian',60000.00),(3,'Sushi House','New York','Asian',70000.00),(4,'Pizzeria La Rosa','Chicago','Italian',80000.00);
SELECT city, cuisine, COUNT(*) FROM Restaurants GROUP BY city, cuisine;
Identify the number of threat intelligence reports generated in the last 6 months, categorized by region, with at least 2 reports per region.
CREATE TABLE threat_intelligence (report_id INT,report_date DATE,region VARCHAR(50)); INSERT INTO threat_intelligence (report_id,report_date,region) VALUES (1,'2021-12-01','Europe'),(2,'2021-11-15','Asia'),(3,'2021-10-05','Europe');
SELECT region, COUNT(region) as num_reports FROM threat_intelligence WHERE report_date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH) GROUP BY region HAVING num_reports >= 2;
Percentage of female attendees at events, grouped by event type, for events that took place in Paris or Rome between 2016 and 2018.
CREATE TABLE events (event_id INT,event_type VARCHAR(50),event_location VARCHAR(50),event_date DATE,attendee_gender VARCHAR(10));
SELECT e.event_type, (COUNT(*) FILTER (WHERE e.attendee_gender = 'female') * 100.0 / COUNT(*)) as pct_female_attendees FROM events e WHERE e.event_location IN ('Paris', 'Rome') AND e.event_date BETWEEN '2016-01-01' AND '2018-12-31' GROUP BY e.event_type;
What is the average carbon price in the European Union and United States?
CREATE TABLE carbon_prices (country VARCHAR(50),price DECIMAL(5,2)); INSERT INTO carbon_prices (country,price) VALUES ('European Union',25.87),('United States',10.21);
SELECT AVG(price) FROM carbon_prices WHERE country IN ('European Union', 'United States');