instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What are the average ticket prices for each venue in the 'stadiums' table?
CREATE TABLE ticket_prices (venue_id INT,avg_ticket_price DECIMAL(5,2));
SELECT s.stadium_name, AVG(t.avg_ticket_price) AS avg_ticket_price FROM stadiums s INNER JOIN ticket_prices t ON s.stadium_id = t.venue_id GROUP BY s.stadium_name;
Find all marine species in 'Coral Sea' with a lifespan greater than 5 years.
CREATE TABLE if not exists marine_species (id INT,name TEXT,location TEXT,lifespan INT);
SELECT * FROM marine_species WHERE location = 'Coral Sea' AND lifespan > 5;
What is the average rainfall in Australia during the summer months, based on historical weather data?
CREATE TABLE weather_data (location VARCHAR(255),date DATE,rainfall FLOAT); INSERT INTO weather_data (location,date,rainfall) VALUES ('Australia','2020-12-01',23.6),('Australia','2020-12-02',24.7),('Australia','2021-01-01',35.6),('Australia','2021-01-02',36.7);
SELECT AVG(rainfall) FROM weather_data WHERE location = 'Australia' AND date BETWEEN '2020-12-01' AND '2021-02-28';
What is the average carbon price in EU ETS in EUR/tonne, for the years 2016 to 2020?
CREATE TABLE CarbonPrice (year INT,price FLOAT,market VARCHAR(50));
SELECT AVG(price) FROM CarbonPrice WHERE market = 'EU ETS' AND year BETWEEN 2016 AND 2020;
List all donations made by donors from the city of 'Los Angeles' in the 'donors' table, along with their corresponding organization information from the 'organizations' table.
CREATE TABLE donors (donor_id INT,donor_name TEXT,donation_amount DECIMAL,city_id INT); CREATE TABLE cities (city_id INT,city_name TEXT); CREATE TABLE organizations (org_id INT,org_name TEXT,city_id INT);
SELECT donors.donor_name, donors.donation_amount, organizations.org_name FROM donors INNER JOIN cities ON donors.city_id = cities.city_id INNER JOIN organizations ON donors.org_id = organizations.org_id WHERE cities.city_name = 'Los Angeles';
What is the total revenue from sustainable fashion sales in the last 6 months?
CREATE TABLE sales (id INT,garment_id INT,size INT,sale_date DATE,sustainable BOOLEAN); INSERT INTO sales (id,garment_id,size,sale_date,sustainable) VALUES (1,401,16,'2021-12-01',TRUE),(2,402,10,'2022-01-15',FALSE),(3,403,12,'2022-02-20',TRUE);
SELECT SUM(price * quantity) FROM sales s JOIN garment_pricing gp ON s.garment_id = gp.garment_id WHERE sustainable = TRUE AND sale_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 6 MONTH) AND CURDATE();
How many wind energy projects were completed in Canada in 2021?
CREATE TABLE renewable_energy (id INT,project TEXT,location TEXT,year INT,type TEXT,status TEXT); INSERT INTO renewable_energy (id,project,location,year,type,status) VALUES (1,'Alberta Wind Energy','Canada',2021,'wind','completed'),(2,'British Columbia Solar Energy','Canada',2021,'solar','in progress');
SELECT COUNT(*) FROM renewable_energy WHERE location = 'Canada' AND year = 2021 AND type = 'wind' AND status = 'completed';
How many volunteers participated in each program by month in 2021?
CREATE TABLE VolunteerHours (VolunteerID INT,ProgramID INT,Hours DECIMAL(5,2),HourDate DATE); INSERT INTO VolunteerHours (VolunteerID,ProgramID,Hours,HourDate) VALUES (1,1,5,'2021-01-15'),(2,2,3,'2021-03-02'),(1,1,4,'2021-04-30'),(3,3,2,'2021-01-01'); CREATE TABLE Programs (ProgramID INT,ProgramName TEXT); INSERT INTO ...
SELECT ProgramID, DATE_FORMAT(HourDate, '%Y-%m') as Month, COUNT(DISTINCT VolunteerID) as NumVolunteers FROM VolunteerHours JOIN Programs ON VolunteerHours.ProgramID = Programs.ProgramID GROUP BY ProgramID, Month;
Delete policies with a coverage amount over $500,000 from the policy_info table
CREATE TABLE policy_info (policy_id INT,policy_holder TEXT,coverage_amount INT); INSERT INTO policy_info (policy_id,policy_holder,coverage_amount) VALUES (1,'John Smith',600000),(2,'Jane Doe',400000),(3,'Mike Johnson',700000);
DELETE FROM policy_info WHERE coverage_amount > 500000;
Which policy had the highest budget allocation in the year 2019?
CREATE TABLE Policies (Year INT,Policy VARCHAR(255),Amount INT); INSERT INTO Policies (Year,Policy,Amount) VALUES (2019,'PolicyA',8000000),(2019,'PolicyB',6000000),(2019,'PolicyC',9000000),(2020,'PolicyA',8500000),(2020,'PolicyB',6500000),(2020,'PolicyC',9500000);
SELECT Policy, MAX(Amount) FROM Policies WHERE Year = 2019 GROUP BY Policy;
How many digital exhibitions were launched by museums in Seoul in the last three years?
CREATE TABLE SeoulDigitalExhibitions (id INT,exhibition_name VARCHAR(30),city VARCHAR(20),launch_date DATE); INSERT INTO SeoulDigitalExhibitions (id,exhibition_name,city,launch_date) VALUES (1,'Virtual Seoul','Seoul','2020-06-01'),(2,'Korean Art','Seoul','2021-02-15'),(3,'Ancient Korea','Seoul','2022-05-05');
SELECT COUNT(*) FROM SeoulDigitalExhibitions WHERE city = 'Seoul' AND launch_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 3 YEAR) AND CURRENT_DATE;
Update the principal investigator of a research grant in the "grants" table
CREATE TABLE grants (id INT PRIMARY KEY,title VARCHAR(100),principal_investigator VARCHAR(50),amount NUMERIC,start_date DATE,end_date DATE);
WITH updated_grant AS (UPDATE grants SET principal_investigator = 'Emilia Clarke' WHERE id = 2 RETURNING *) SELECT * FROM updated_grant;
How many accessible technology patents were granted to women-led teams?
CREATE TABLE patents (id INT,is_women_led BOOLEAN,is_accessible BOOLEAN); INSERT INTO patents (id,is_women_led,is_accessible) VALUES (1,true,true),(2,false,true),(3,true,false);
SELECT COUNT(*) FROM patents WHERE is_women_led = true AND is_accessible = true;
How many fans attended games in each region in 2021?
CREATE TABLE regions (id INT,name VARCHAR(255)); INSERT INTO regions (id,name) VALUES (1,'Northeast'),(2,'Southeast'),(3,'Midwest'),(4,'West'); CREATE TABLE games (id INT,region_id INT,attendees INT,year INT); INSERT INTO games (id,region_id,attendees,year) VALUES (1,1,2000,2021),(2,2,3000,2021),(3,3,4000,2021),(4,1,25...
SELECT r.name, SUM(g.attendees) as total_attendees FROM regions r JOIN games g ON r.id = g.region_id WHERE g.year = 2021 GROUP BY r.name;
What is the total sales revenue of the top 5 selling products in Q3 2020?
CREATE TABLE product_sales (product_id INT,product_category VARCHAR(50),sale_date DATE,revenue DECIMAL(10,2)); CREATE TABLE products (product_id INT,product_name VARCHAR(50)); CREATE VIEW product_sales_view AS SELECT product_id,product_category,EXTRACT(YEAR FROM sale_date) AS sale_year,EXTRACT(QUARTER FROM sale_date) A...
SELECT product_id, SUM(total_revenue) FROM product_sales_view WHERE sale_year = 2020 AND sale_quarter = 3 GROUP BY product_id ORDER BY SUM(total_revenue) DESC LIMIT 5;
What is the minimum production rate in the 'GH_Well' table for wells with a status of 'Active' in the 'Well_Status' table?
CREATE TABLE GH_Well (Well_ID VARCHAR(10),Production_Rate INT); INSERT INTO GH_Well (Well_ID,Production_Rate) VALUES ('W001',200),('W002',300);CREATE TABLE Well_Status (Well_ID VARCHAR(10),Status VARCHAR(10)); INSERT INTO Well_Status (Well_ID,Status) VALUES ('W001','Active'),('W002','Inactive');
SELECT MIN(Production_Rate) FROM GH_Well WHERE Well_ID IN (SELECT Well_ID FROM Well_Status WHERE Status = 'Active');
Show the total number of news stories in the 'news_stories' table, grouped by the year they were published.
CREATE TABLE news_stories (story_id INT,title VARCHAR(100),description TEXT,reporter_id INT,publish_date DATE);
SELECT YEAR(publish_date) AS year, COUNT(*) FROM news_stories GROUP BY year;
Insert a new row into the 'media_ethics' table with appropriate data
CREATE TABLE media_ethics (ethic_id INT PRIMARY KEY,ethic_name VARCHAR(255),description TEXT,source VARCHAR(255));
INSERT INTO media_ethics (ethic_id, ethic_name, description, source) VALUES (1, 'Freedom of Speech', 'The right to express one''s ideas and opinions freely through various forms of media.', 'United Nations');
Update the health status of the Porites Coral in the Pacific Ocean to Threatened.
CREATE TABLE Coral (Name VARCHAR(255),Ocean VARCHAR(255),Health_Status VARCHAR(255)); INSERT INTO Coral (Name,Ocean,Health_Status) VALUES ('Porites Coral','Pacific Ocean','Vulnerable');
UPDATE Coral SET Health_Status = 'Threatened' WHERE Name = 'Porites Coral' AND Ocean = 'Pacific Ocean';
What is the average visitor age for each exhibition?
CREATE TABLE Exhibitions (exhibition_id INT,visitor_age INT);
SELECT exhibition_id, AVG(visitor_age) FROM Exhibitions GROUP BY exhibition_id;
What is the total number of properties in New York with a co-ownership model?
CREATE TABLE property_model (property_id INT,city VARCHAR(50),model VARCHAR(50)); INSERT INTO property_model VALUES (1,'New_York','co-ownership'),(2,'New_York','rental'),(3,'Boston','co-ownership');
SELECT COUNT(*) FROM property_model WHERE city = 'New_York' AND model = 'co-ownership';
What is the percentage of waste generated by the top 3 waste-generating countries in 2020?
CREATE TABLE yearly_waste (country VARCHAR(50),year INT,total_waste FLOAT); INSERT INTO yearly_waste (country,year,total_waste) VALUES ('USA',2020,260),('China',2020,240),('India',2020,160),('Germany',2020,120),('Brazil',2020,100);
SELECT SUM(total_waste) / (SELECT SUM(total_waste) FROM yearly_waste WHERE year = 2020) AS percentage_of_waste FROM yearly_waste WHERE country IN (SELECT country FROM (SELECT country, ROW_NUMBER() OVER (ORDER BY total_waste DESC) rn FROM yearly_waste WHERE year = 2020) t WHERE rn <= 3);
What is the average depth of all marine life research stations in the Pacific Ocean?
CREATE TABLE marine_life_research_stations (id INT,name TEXT,location TEXT,depth FLOAT); INSERT INTO marine_life_research_stations (id,name,location,depth) VALUES (1,'Station A','Pacific Ocean',2500.5); INSERT INTO marine_life_research_stations (id,name,location,depth) VALUES (2,'Station B','Pacific Ocean',3201.2); CRE...
SELECT AVG(depth) FROM marine_life_research_stations WHERE location = 'Pacific Ocean';
Which regions had the most volunteers in 2021?
CREATE TABLE volunteer (vid INT,region VARCHAR(50),volunteer_date DATE); INSERT INTO volunteer (vid,region,volunteer_date) VALUES (1,'North','2021-01-03'),(2,'South','2021-02-15'),(3,'East','2021-03-27'),(4,'West','2021-04-01'),(5,'North','2021-05-12'),(6,'East','2021-06-20'),(7,'South','2021-07-30'),(8,'West','2021-08...
SELECT region, COUNT(*) AS num_volunteers FROM volunteer GROUP BY region;
Calculate the total number of students who have received accommodations in the Music faculty, but not in the Athletics faculty.
CREATE TABLE MusicAccommodations (StudentID INT,AccommodationType VARCHAR(50)); CREATE TABLE AthleticsAccommodations (StudentID INT,AccommodationType VARCHAR(50)); INSERT INTO MusicAccommodations VALUES (1,'Extra Time'),(2,'Assistive Technology'),(3,'Quiet Room'); INSERT INTO AthleticsAccommodations VALUES (2,'Extra Ti...
SELECT COUNT(StudentID) FROM MusicAccommodations WHERE StudentID NOT IN (SELECT StudentID FROM AthleticsAccommodations);
What is the total amount of mineral extraction by year?
CREATE TABLE extraction (extraction_id INT,mine_id INT,year INT,mineral VARCHAR(255),quantity INT); INSERT INTO extraction (extraction_id,mine_id,year,mineral,quantity) VALUES (1,1,2018,'Gold',1000),(2,1,2019,'Gold',1200),(3,2,2018,'Uranium',2000),(4,2,2019,'Uranium',2500);
SELECT year, SUM(quantity) FROM extraction GROUP BY year;
What is the most visited tourist attraction in Japan?
CREATE TABLE japan_attractions (id INT,attraction VARCHAR(100),visits INT); INSERT INTO japan_attractions (id,attraction,visits) VALUES (1,'Mount Fuji',2000000),(2,'Todai-ji Temple',3000000);
SELECT attraction FROM japan_attractions WHERE visits = (SELECT MAX(visits) FROM japan_attractions);
What is the maximum safety score for each AI algorithm in the 'algorithm_safety' table?
CREATE TABLE algorithm_safety (algorithm_name TEXT,safety_score FLOAT); INSERT INTO algorithm_safety (algorithm_name,safety_score) VALUES ('AlgorithmX',0.95),('AlgorithmY',0.80),('AlgorithmZ',0.90);
SELECT algorithm_name, MAX(safety_score) OVER (PARTITION BY algorithm_name) AS max_safety_score FROM algorithm_safety;
Show mental health parity laws for Texas
CREATE TABLE mental_health_parity (id INT PRIMARY KEY,state VARCHAR(2),parity_law TEXT,year INT);
SELECT parity_law FROM mental_health_parity WHERE state = 'TX';
Identify the garment with the highest sales for each transaction, partitioned by salesperson and ordered by date.
CREATE TABLE sales (salesperson VARCHAR(50),garment VARCHAR(50),quantity INT,transaction_date DATE); INSERT INTO sales (salesperson,garment,quantity,transaction_date) VALUES ('John','Shirt',15,'2021-01-05'),('John','Pants',20,'2021-01-05'),('Jane','Dress',30,'2021-01-10');
SELECT salesperson, transaction_date, FIRST_VALUE(garment) OVER (PARTITION BY salesperson ORDER BY quantity DESC, transaction_date DESC) as top_garment FROM sales;
How many satellites were deployed by 'Blue Origin' and 'Virgin Galactic'?
CREATE TABLE SatelliteDeployment(name VARCHAR(20),company VARCHAR(20)); INSERT INTO SatelliteDeployment VALUES('Satellite C','Blue Origin'),('Satellite D','Virgin Galactic');
SELECT COUNT(*) FROM SatelliteDeployment WHERE company IN ('Blue Origin', 'Virgin Galactic');
What is the percentage of incarcerated individuals who have completed a high school education or higher?
CREATE TABLE Prisoners (PrisonerID INT,Age INT,PrisonType VARCHAR(20),Education VARCHAR(20)); INSERT INTO Prisoners (PrisonerID,Age,PrisonType,Education) VALUES (1,30,'Maximum Security','High School'),(2,45,'Minimum Security','College'),(3,35,'Maximum Security','Some High School');
SELECT (COUNT(*) FILTER (WHERE Education IN ('High School', 'College', 'Some College'))) * 100.0 / COUNT(*) FROM Prisoners;
Identify the unique court types and their corresponding states or provinces in the criminal justice system of the US and Canada.
CREATE TABLE court_info (id INT,country VARCHAR(255),state_province VARCHAR(255),court_type VARCHAR(255)); INSERT INTO court_info (id,country,state_province,court_type) VALUES (1,'US','California','Superior Court'),(2,'US','New York','Supreme Court'),(3,'Canada','Ontario','Superior Court'),(4,'Canada','Quebec','Superio...
SELECT DISTINCT court_type, state_province FROM court_info WHERE country IN ('US', 'Canada') ORDER BY country, court_type;
What is the average energy efficiency rating for buildings in France?
CREATE TABLE building_efficiency (country VARCHAR(255),rating DECIMAL(3,2)); INSERT INTO building_efficiency (country,rating) VALUES ('France',78.5),('Germany',82.3),('Spain',65.2);
SELECT AVG(rating) FROM building_efficiency WHERE country = 'France';
Add fan demographics data to the 'fans' table
CREATE TABLE fans (id INT PRIMARY KEY,age INT,gender VARCHAR(255),location VARCHAR(255)); INSERT INTO fans (id,age,gender,location) VALUES (1,25,'Female','Los Angeles'); INSERT INTO fans (id,age,gender,location) VALUES (2,35,'Male','New York');
INSERT INTO fans (id, age, gender, location) VALUES (3, 30, 'Non-binary', 'Toronto');
What is the number of professional development events attended by teachers in each region, ordered by attendance?
CREATE TABLE teacher_events (teacher_id INT,region VARCHAR(20),event_attended INT); INSERT INTO teacher_events (teacher_id,region,event_attended) VALUES (1,'North',2),(2,'North',1),(3,'South',3),(4,'South',0);
SELECT region, SUM(event_attended) as total_events, ROW_NUMBER() OVER (ORDER BY SUM(event_attended) DESC) as rank FROM teacher_events GROUP BY region ORDER BY rank;
How many cases were handled by attorneys who identify as female and were billed at a rate of over $300 per hour?
CREATE TABLE attorneys (attorney_id INT,first_name VARCHAR(20),last_name VARCHAR(20),gender VARCHAR(10),hourly_rate DECIMAL(5,2)); INSERT INTO attorneys (attorney_id,first_name,last_name,gender,hourly_rate) VALUES (1,'John','Doe','Male',400); INSERT INTO attorneys (attorney_id,first_name,last_name,gender,hourly_rate) V...
SELECT COUNT(*) FROM attorneys WHERE gender = 'Female' AND hourly_rate > 300;
What is the maximum number of successful cases handled by attorneys who identify as African?
CREATE TABLE attorneys (attorney_id INT,ethnicity VARCHAR(20),successful_cases INT); INSERT INTO attorneys (attorney_id,ethnicity,successful_cases) VALUES (1,'Caucasian',15),(2,'African',12),(3,'African',16);
SELECT MAX(successful_cases) FROM attorneys WHERE ethnicity = 'African';
What is the minimum ocean health metric for coastal countries in Southeast Asia?
CREATE TABLE ocean_health (country VARCHAR(50),metric FLOAT,region VARCHAR(50)); INSERT INTO ocean_health (country,metric,region) VALUES ('Indonesia',6.1,'Southeast Asia'),('Thailand',6.5,'Southeast Asia'),('Philippines',6.8,'Southeast Asia'),('Vietnam',6.4,'Southeast Asia');
SELECT MIN(metric) FROM ocean_health WHERE region = 'Southeast Asia';
Add a new textile source 'Deadstock Fabrics' to the 'sources' table
CREATE TABLE sources (id INT PRIMARY KEY,source_name VARCHAR(50));
INSERT INTO sources (id, source_name) VALUES (3, 'Deadstock Fabrics');
How many times has each dish been ordered?
CREATE TABLE orders (order_id INT,dish VARCHAR(255),quantity INT); INSERT INTO orders VALUES (1,'Bruschetta',2); INSERT INTO orders VALUES (2,'Lasagna',1);
SELECT dish, SUM(quantity) AS total_orders FROM orders GROUP BY dish;
What is the minimum number of likes on posts published in the past week?
CREATE TABLE posts (id INT,user_id INT,timestamp TIMESTAMP,content TEXT,likes INT,shares INT);
SELECT MIN(likes) FROM posts WHERE timestamp BETWEEN DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 WEEK) AND CURRENT_TIMESTAMP;
Which countries have adopted electric vehicles the most?
CREATE TABLE Country (id INT,name TEXT); CREATE TABLE Vehicle (id INT,name TEXT,country_id INT); CREATE TABLE ElectricVehicle (id INT,vehicle_id INT); INSERT INTO Country (id,name) VALUES (1,'USA'),(2,'China'),(3,'Germany'); INSERT INTO Vehicle (id,name,country_id) VALUES (1,'Model S',1),(2,'Camry',1),(3,'Tesla Semi',2...
SELECT Country.name, COUNT(*) FROM Country INNER JOIN Vehicle ON Country.id = Vehicle.country_id INNER JOIN ElectricVehicle ON Vehicle.id = ElectricVehicle.vehicle_id GROUP BY Country.id ORDER BY COUNT(*) DESC;
Which player has the highest number of points scored in a single game?
CREATE TABLE players (player_id INT,player_name VARCHAR(50),team_id INT); INSERT INTO players (player_id,player_name,team_id) VALUES (1,'Curry',1),(2,'Durant',1),(3,'James',2); CREATE TABLE games (game_id INT,player_id INT,team_id INT,points INT); INSERT INTO games (game_id,player_id,team_id,points) VALUES (1,1,1,30),(...
SELECT player_id, MAX(points) as max_points FROM games;
Insert a new fairness issue for model 7 from Japan.
CREATE TABLE fairness_issues (issue_id INT,model_id INT,country VARCHAR(255),issue_description VARCHAR(255));
INSERT INTO fairness_issues (issue_id, model_id, country, issue_description) VALUES (1, 7, 'Japan', 'Fairness issue for model 7 in Japan');
Which artist has the most sculptures in their collection?
CREATE TABLE Artists (name VARCHAR(255),art VARCHAR(255),quantity INT); INSERT INTO Artists (name,art,quantity) VALUES ('Picasso','Painting',500,'Sculpture',300),('Moore','Sculpture',700),('Rodin','Sculpture',600);
SELECT name FROM Artists WHERE art = 'Sculpture' AND quantity = (SELECT MAX(quantity) FROM Artists WHERE art = 'Sculpture');
List all regulatory frameworks and the number of associated regulatory actions since their publication date.
CREATE TABLE regulatory_frameworks (framework_id INT,framework_name VARCHAR(255),jurisdiction VARCHAR(255),published_date TIMESTAMP,updated_date TIMESTAMP); CREATE TABLE regulatory_actions (action_id INT,framework_id INT,action_type VARCHAR(255),action_description TEXT,action_date TIMESTAMP);
SELECT f.framework_name, COUNT(a.action_id) as total_actions FROM regulatory_frameworks f LEFT JOIN regulatory_actions a ON f.framework_id = a.framework_id WHERE a.action_date >= f.published_date GROUP BY f.framework_name;
Insert a new record into the 'energy_storage' table for a lithium-ion battery with 10 MWh capacity, located in 'New York'
CREATE TABLE energy_storage (id INT PRIMARY KEY,technology VARCHAR(255),capacity FLOAT,location VARCHAR(255));
INSERT INTO energy_storage (technology, capacity, location) VALUES ('lithium-ion', 10, 'New York');
Calculate the total water usage in the United States in 2021.
CREATE TABLE water_usage(state VARCHAR(20),year INT,usage FLOAT);
SELECT SUM(usage) FROM water_usage WHERE year=2021 AND state IN ('Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', '...
Insert a new attorney with the following data: attorney_id 2, attorney_name 'Emily Brown', attorney_email 'emily.brown@lawfirm.com', attorney_phone '555-555-1212' into the 'attorneys' table
CREATE TABLE attorneys (attorney_id INT,attorney_name VARCHAR(50),attorney_email VARCHAR(50),attorney_phone VARCHAR(15));
INSERT INTO attorneys (attorney_id, attorney_name, attorney_email, attorney_phone) VALUES (2, 'Emily Brown', 'emily.brown@lawfirm.com', '555-555-1212');
Show the number of cities with public transportation systems that have more than 5 modes of transportation
CREATE TABLE transportation.public_transportation (city VARCHAR(50),mode VARCHAR(50));
SELECT city FROM transportation.public_transportation GROUP BY city HAVING COUNT(DISTINCT mode) > 5;
Delete records in the 'vessels' table where the type is 'Cruise Ship' and the flag is 'Panama'
CREATE TABLE vessels (id INT,name VARCHAR(50),type VARCHAR(20),flag VARCHAR(20),length FLOAT); INSERT INTO vessels (id,name,type,flag,length) VALUES (1,'Ocean Wave','Oil Tanker','Liberia',300.0); INSERT INTO vessels (id,name,type,flag,length) VALUES (2,'Island Princess','Cruise Ship','Panama',250.0);
DELETE FROM vessels WHERE type = 'Cruise Ship' AND flag = 'Panama';
Calculate the total budget for food justice initiatives in each state.
CREATE TABLE food_justice_initiatives (initiative_name VARCHAR(255),state VARCHAR(255),budget FLOAT);
SELECT state, SUM(budget) as total_budget FROM food_justice_initiatives GROUP BY state;
How many cosmetic products have been recalled in each country?
CREATE TABLE Country (CountryID INT,CountryName VARCHAR(50)); CREATE TABLE Product (ProductID INT,ProductName VARCHAR(50),CountryID INT); CREATE TABLE Recall (RecallID INT,ProductID INT,Reason VARCHAR(100)); INSERT INTO Country (CountryID,CountryName) VALUES (1,'USA'),(2,'Canada'),(3,'Mexico'); INSERT INTO Product (Pro...
SELECT c.CountryName, COUNT(r.ProductID) as RecallCount FROM Country c JOIN Product p ON c.CountryID = p.CountryID LEFT JOIN Recall r ON p.ProductID = r.ProductID GROUP BY c.CountryName;
List the number of unique artists who performed in festivals located in different countries in 2019?
CREATE TABLE FestivalArtists (artist_id INT,festival_id INT,year INT); CREATE TABLE Festivals (id INT,country VARCHAR(50));
SELECT COUNT(DISTINCT a.artist_id) FROM FestivalArtists a JOIN Festivals f ON a.festival_id = f.id WHERE a.year = 2019 GROUP BY f.country HAVING COUNT(DISTINCT a.festival_id) > 1;
Get the total area of the ocean floor mapped in the Pacific and Atlantic oceans
CREATE TABLE ocean_floor_mapping (mapping_id INT,region VARCHAR(255),area INT); CREATE VIEW pacific_atlantic_mapping AS SELECT * FROM ocean_floor_mapping WHERE region IN ('Pacific ocean','Atlantic ocean');
SELECT region, SUM(area) FROM pacific_atlantic_mapping GROUP BY region;
Insert a new record into the 'security_incidents' table
CREATE TABLE security_incidents (id INT PRIMARY KEY,type VARCHAR(255),date_time TIMESTAMP,description TEXT,severity VARCHAR(255),affected_asset_id INT,FOREIGN KEY (affected_asset_id) REFERENCES assets(id)); CREATE TABLE assets (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255),IP_address VARCHAR(255));
INSERT INTO security_incidents (id, type, date_time, description, severity, affected_asset_id) VALUES (1, 'Phishing Attack', '2023-03-14 12:34:56', 'Test phishing attack description', 'High', 123);
Find the total assets of socially responsible lenders in the financial sector.
CREATE TABLE lenders (lender_id INT,sector VARCHAR(20),is_socially_responsible BOOLEAN); CREATE TABLE assets (asset_id INT,lender_id INT,value DECIMAL(10,2)); INSERT INTO lenders (lender_id,sector,is_socially_responsible) VALUES (1,'financial',true),(2,'technology',false),(3,'financial',false); INSERT INTO assets (asse...
SELECT SUM(a.value) FROM assets a INNER JOIN lenders l ON a.lender_id = l.lender_id WHERE l.sector = 'financial' AND l.is_socially_responsible = true;
What is the number of biosensor technology development projects by research phase, for each country, in the continent of Asia?
CREATE TABLE biosensor_tech (id INT PRIMARY KEY,country VARCHAR(255),research_phase VARCHAR(255),project_name VARCHAR(255),start_date DATE,end_date DATE,continent VARCHAR(255));
SELECT continent, country, research_phase, COUNT(*) FROM biosensor_tech WHERE continent = 'Asia' GROUP BY continent, country, research_phase;
What is the total revenue generated by dispensaries in Vancouver selling flower products in Q3 2021?
CREATE TABLE sales (id INT,dispensary TEXT,product TEXT,revenue DECIMAL,sale_date DATE); INSERT INTO sales (id,dispensary,product,revenue,sale_date) VALUES (1,'Buds and Beyond','Blue Dream flower',20.0,'2021-07-01'),(2,'Buds and Beyond','Purple Kush flower',30.0,'2021-07-01');
SELECT SUM(revenue) FROM sales WHERE dispensary = 'Buds and Beyond' AND product LIKE '%flower%' AND sale_date >= '2021-07-01' AND sale_date < '2021-10-01';
What is the adoption rate of AI technology in 'Asian' hotels?
CREATE TABLE hotels_tech (hotel_id INT,hotel_name VARCHAR(50),region VARCHAR(50),ai_adoption BOOLEAN); INSERT INTO hotels_tech (hotel_id,hotel_name,region,ai_adoption) VALUES (1,'Mandarin Oriental','Asia',true),(2,'Four Seasons','North America',false);
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM hotels_tech WHERE region = 'Asia')) AS adoption_rate FROM hotels_tech WHERE region = 'Asia' AND ai_adoption = true;
What is the average content rating for anime TV shows released since 2015?
CREATE TABLE anime_shows (title VARCHAR(255),release_year INT,rating DECIMAL(3,2)); INSERT INTO anime_shows (title,release_year,rating) VALUES ('Anime1',2016,4.3),('Anime2',2017,4.7),('Anime3',2018,4.9);
SELECT AVG(rating) avg_rating FROM anime_shows WHERE release_year >= 2015;
What is the total donation amount for each quarter?
CREATE TABLE Donations (id INT,amount FLOAT,donation_date DATE); INSERT INTO Donations (id,amount,donation_date) VALUES (1,100.5,'2021-01-01'),(2,200.0,'2021-04-01'),(3,150.25,'2021-07-01');
SELECT DATE_FORMAT(donation_date, '%Y-%m') as quarter, SUM(amount) as total_donations FROM Donations GROUP BY quarter;
Which country had the highest average score in the 'virtual_reality_tournament' table?
CREATE TABLE virtual_reality_tournament (player_id INT,player_name TEXT,score INT,country TEXT);
SELECT country, AVG(score) as avg_score FROM virtual_reality_tournament GROUP BY country ORDER BY avg_score DESC LIMIT 1;
What is the ratio of organic cotton to conventional cotton products sold?
CREATE TABLE sales (id INT,product_id INT,material VARCHAR(50),quantity INT);
SELECT organic_cotton_sales / conventional_cotton_sales AS organic_conventional_ratio FROM (SELECT SUM(CASE WHEN material = 'organic_cotton' THEN quantity ELSE 0 END) AS organic_cotton_sales, SUM(CASE WHEN material = 'conventional_cotton' THEN quantity ELSE 0 END) AS conventional_cotton_sales FROM sales) AS sales_summa...
Calculate the total number of gluten-free and vegetarian products in stock.
CREATE TABLE Inventory (product_id INT,product_name VARCHAR(100),is_gluten_free BOOLEAN,is_vegetarian BOOLEAN); INSERT INTO Inventory (product_id,product_name,is_gluten_free,is_vegetarian) VALUES (1,'Quinoa',true,true),(2,'Bread',false,false),(3,'Pasta',false,true);
SELECT SUM(CASE WHEN is_gluten_free = true THEN 1 ELSE 0 END + CASE WHEN is_vegetarian = true THEN 1 ELSE 0 END) FROM Inventory;
Which genetic research projects have received funding in Canada?
CREATE TABLE genetic_research (id INT,project_name VARCHAR(50),location VARCHAR(50),funding_amount INT); INSERT INTO genetic_research (id,project_name,location,funding_amount) VALUES (1,'Project C','Canada',7000000); INSERT INTO genetic_research (id,project_name,location,funding_amount) VALUES (2,'Project D','France',9...
SELECT project_name, funding_amount FROM genetic_research WHERE location = 'Canada';
What is the total number of employees working in manufacturers located in Japan?
CREATE TABLE workforce (employee_id INT,manufacturer_id INT,role VARCHAR(255),years_of_experience INT); INSERT INTO workforce (employee_id,manufacturer_id,role,years_of_experience) VALUES (1,1,'Engineer',7),(2,2,'Manager',10),(3,3,'Technician',5),(4,4,'Designer',6),(5,5,'Assembler',4),(6,6,'Operator',3),(7,7,'Inspector...
SELECT COUNT(w.employee_id) FROM workforce w INNER JOIN manufacturers m ON w.manufacturer_id = m.manufacturer_id WHERE m.location = 'Japan';
Insert a new record into the "union_members" table with the following values: 5, "Leila Ahmed", "NY", "inactive"
CREATE TABLE union_members (member_id INT,name VARCHAR(50),state VARCHAR(2),membership_status VARCHAR(10));
INSERT INTO union_members (member_id, name, state, membership_status) VALUES (5, 'Leila Ahmed', 'NY', 'inactive');
Which team has the most sold-out games in the 2022 season?
CREATE TABLE games (game_id INT,team_id INT,date DATE,is_sold_out BOOLEAN); INSERT INTO games (game_id,team_id,date,is_sold_out) VALUES (1,1,'2022-01-01',true),(2,1,'2022-02-01',false),(3,2,'2022-03-01',true),(4,2,'2022-04-01',true);
SELECT teams.team_name, COUNT(games.game_id) as num_sold_out_games FROM games JOIN teams ON games.team_id = teams.team_id WHERE games.is_sold_out = true GROUP BY teams.team_name ORDER BY num_sold_out_games DESC LIMIT 1;
What is the total quantity of items in the 'warehouse_inventory' table?
CREATE TABLE warehouse_inventory (item_id INT,item_name VARCHAR(50),quantity INT); INSERT INTO warehouse_inventory (item_id,item_name,quantity) VALUES (1,'Apples',250),(2,'Oranges',180);
SELECT SUM(quantity) FROM warehouse_inventory;
What is the total sales revenue per garment category?
CREATE TABLE garment_sales (sales_id INT PRIMARY KEY,garment_id INT,store_id INT,quantity INT,price DECIMAL(5,2),date DATE); CREATE TABLE garments (garment_id INT PRIMARY KEY,garment_name TEXT,garment_category TEXT,sustainability_score INT); INSERT INTO garments (garment_id,garment_name,garment_category,sustainability_...
SELECT g.garment_category, SUM(gs.quantity * gs.price) as total_sales_revenue FROM garment_sales gs JOIN garments g ON gs.garment_id = g.garment_id GROUP BY g.garment_category;
What is the count of hotels in the 'hotel_tech_adoption' table that have adopted cloud-based PMS?
CREATE TABLE hotel_tech_adoption (hotel_id INT,hotel_name TEXT,cloud_pms BOOLEAN); INSERT INTO hotel_tech_adoption (hotel_id,hotel_name,cloud_pms) VALUES (1,'The Oberoi',true),(2,'Hotel Ritz',false),(3,'Four Seasons',true);
SELECT COUNT(*) FROM hotel_tech_adoption WHERE cloud_pms = true;
What is the total waste generated by the chemical production in the European region in the last quarter?
CREATE TABLE waste_generated (id INT,waste_date DATE,region VARCHAR(255),waste_amount INT); INSERT INTO waste_generated (id,waste_date,region,waste_amount) VALUES (1,'2022-01-01','Europe',25),(2,'2022-04-01','Europe',30);
SELECT SUM(waste_amount) FROM waste_generated WHERE region = 'Europe' AND waste_date >= '2022-01-01' AND waste_date < '2022-04-01';
What is the percentage of water bodies in Australia that are considered to be in a drought state, for each month of the year 2021?
CREATE TABLE australia_water_bodies (name VARCHAR(255),month INT,drought BOOLEAN); INSERT INTO australia_water_bodies (name,month,drought) VALUES ('Murray River',1,true),('Murray River',2,true),('Murray River',3,true),('Murray River',4,false),('Murray River',5,false),('Murray River',6,false),('Sydney Harbour',1,false),...
SELECT name, 100.0 * SUM(drought) / COUNT(name) as drought_percentage FROM australia_water_bodies GROUP BY name;
Add a new customer with name "Aaliyah Jackson", email "aaliyah.jackson@example.com", and loyalty_points 500
CREATE TABLE customers (customer_id INT,name VARCHAR(50),email VARCHAR(50),loyalty_points INT);
INSERT INTO customers (name, email, loyalty_points) VALUES ('Aaliyah Jackson', 'aaliyah.jackson@example.com', 500);
Find the average donation amount for each program?
CREATE TABLE donations (id INT,program VARCHAR(255),amount DECIMAL(10,2)); INSERT INTO donations (id,program,amount) VALUES (1,'Animal Welfare',500.00),(2,'Education',1000.00);
SELECT program, AVG(amount) FROM donations GROUP BY program;
How many humanitarian assistance missions were conducted by NATO in the last 5 years?
CREATE SCHEMA if not exists defense; CREATE TABLE if not exists humanitarian_assistance (id INT PRIMARY KEY,organization VARCHAR(50),year INT,mission_count INT); INSERT INTO humanitarian_assistance (id,organization,year,mission_count) VALUES (1,'NATO',2018,12),(2,'NATO',2019,15),(3,'NATO',2020,18),(4,'NATO',2021,20),(5...
SELECT SUM(mission_count) FROM defense.humanitarian_assistance WHERE organization = 'NATO' AND year BETWEEN 2017 AND 2022;
What is the average launch cost for astrobiology missions?
CREATE TABLE astrobiology_missions (id INT,name VARCHAR(255),launch_cost FLOAT); INSERT INTO astrobiology_missions (id,name,launch_cost) VALUES (1,'Viking 1',938000000),(2,'Viking 2',932000000),(3,'Cassini-Huygens',3270000000),(4,'Mars Science Laboratory',2400000000);
SELECT AVG(launch_cost) FROM astrobiology_missions;
Insert new records into the Policyholders, HomeInsurance, and AutoInsurance tables for a new policyholder who lives in New York.
CREATE TABLE Policyholders (PolicyholderID INT,Name VARCHAR(50),Address VARCHAR(100),State VARCHAR(2)); CREATE TABLE HomeInsurance (PolicyholderID INT,HomeAddress VARCHAR(100)); CREATE TABLE AutoInsurance (PolicyholderID INT,AutoAddress VARCHAR(100));
INSERT INTO Policyholders (PolicyholderID, Name, Address, State) VALUES (4, 'Sara Connor', '678 Maple St', 'NY'); INSERT INTO HomeInsurance (PolicyholderID, HomeAddress) VALUES (4, '678 Maple St'); INSERT INTO AutoInsurance (PolicyholderID, AutoAddress) VALUES (4, '678 Maple St');
Carbon offset initiatives in 2020
CREATE TABLE carbon_offset_initiatives (id INT,name VARCHAR(255),location VARCHAR(255),start_date DATE); INSERT INTO carbon_offset_initiatives (id,name,location,start_date) VALUES (1,'TreePlanting1','CityC','2020-01-01'),(2,'WasteReduction1','CityD','2019-06-15'),(3,'TreePlanting2','CityC','2020-07-01');
SELECT name FROM carbon_offset_initiatives WHERE start_date >= '2020-01-01' AND start_date < '2021-01-01';
What is the average age of all archeologists in the 'Archeologists' table?
CREATE TABLE Archeologists (ID INT,Name VARCHAR(50),Age INT,Specialization VARCHAR(50));
SELECT AVG(Age) FROM Archeologists;
What is the average rating of hotels in 'Asia' region?
CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,region TEXT,rating FLOAT); INSERT INTO hotels (hotel_id,hotel_name,region,rating) VALUES (1,'Hotel Royal','Asia',4.5),(2,'Palace Hotel','Europe',4.7),(3,'Beach Resort','Americas',4.3);
SELECT AVG(rating) FROM hotels WHERE region = 'Asia';
List the total playtime of each player, ordered by the total playtime in descending order.
CREATE TABLE players (id INT,name VARCHAR(255)); INSERT INTO players (id,name) VALUES (1,'Player1'),(2,'Player2'),(3,'Player3'),(4,'Player4'),(5,'Player5'); CREATE TABLE player_games (player_id INT,game_id INT,playtime INT); INSERT INTO player_games (player_id,game_id,playtime) VALUES (1,1,100),(2,2,200),(3,3,300),(4,1...
SELECT players.name, SUM(player_games.playtime) as total_playtime FROM players JOIN player_games ON players.id = player_games.player_id GROUP BY players.id ORDER BY total_playtime DESC;
What is the total transaction value for each customer in Q1 2022?
CREATE TABLE customers (customer_id INT,country_code CHAR(2)); CREATE TABLE transactions (transaction_id INT,customer_id INT,transaction_amount DECIMAL(10,2),transaction_date DATE);
SELECT SUM(transaction_amount), customer_id FROM transactions INNER JOIN customers ON transactions.customer_id = customers.customer_id WHERE transactions.transaction_date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY customer_id;
What is the percentage of hospitals in the state of Florida that offer mental health services?
CREATE TABLE Hospitals (HospitalID INT,Name TEXT,City TEXT,State TEXT,MentalHealth BOOLEAN); INSERT INTO Hospitals (HospitalID,Name,City,State,MentalHealth) VALUES (1,'Jackson Memorial Hospital','Miami','Florida',TRUE);
SELECT (COUNT(*) FILTER (WHERE MentalHealth = TRUE)) * 100.0 / COUNT(*) FROM Hospitals WHERE State = 'Florida';
What is the success rate of bioprocess engineering projects in Canada?
USE biotech; CREATE TABLE if not exists projects (id INT,name VARCHAR(255),country VARCHAR(255),success BOOLEAN); INSERT INTO projects (id,name,country,success) VALUES (1,'Project1','Canada',true),(2,'Project2','USA',false),(3,'Project3','Canada',true),(4,'Project4','Mexico',true);
SELECT COUNT(*) / (SELECT COUNT(*) FROM projects WHERE country = 'Canada') FROM projects WHERE country = 'Canada';
What is the maximum solar power generated in the 'renewable_energy' table for France?
CREATE TABLE renewable_energy (country VARCHAR(50),wind_speed NUMERIC(5,2),solar_power NUMERIC(5,2)); INSERT INTO renewable_energy (country,wind_speed,solar_power) VALUES ('Germany',7.5,12.0),('Germany',6.8,11.5),('France',6.2,15.0),('France',5.9,14.5);
SELECT MAX(solar_power) FROM renewable_energy WHERE country = 'France';
What is the average time spent on virtual tours for hotels in Germany, grouped by tour provider?
CREATE TABLE tour_stats (stat_id INT,tour_name TEXT,country TEXT,avg_time_spent FLOAT); INSERT INTO tour_stats (stat_id,tour_name,country,avg_time_spent) VALUES (1,'Tour 1','Germany',15.5),(2,'Tour 2','Germany',12.3),(3,'Tour 3','Germany',18.7);
SELECT tour_name, AVG(avg_time_spent) as avg_time_spent FROM tour_stats WHERE country = 'Germany' GROUP BY tour_name;
What is the second most expensive product in the Natural segment?
CREATE TABLE products (product_id INT,segment VARCHAR(20),price DECIMAL(5,2)); INSERT INTO products (product_id,segment,price) VALUES (1,'Natural',15.99),(2,'Organic',20.99),(3,'Natural',12.49);
SELECT segment, price FROM (SELECT segment, price, ROW_NUMBER() OVER (PARTITION BY segment ORDER BY price DESC) AS rn FROM products) t WHERE t.segment = 'Natural' AND rn = 2;
What is the percentage of female employees who work in the IT department?
CREATE TABLE employees (id INT,gender VARCHAR(10),department VARCHAR(20)); INSERT INTO employees (id,gender,department) VALUES (1,'Female','Marketing'); INSERT INTO employees (id,gender,department) VALUES (2,'Male','IT'); INSERT INTO employees (id,gender,department) VALUES (3,'Female','IT'); INSERT INTO employees (id,g...
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM employees WHERE department = 'IT')) as percentage FROM employees WHERE gender = 'Female' AND department = 'IT';
Which crops are common between smart_farm_3 and smart_farm_4?
CREATE TABLE smart_farm_3 (crop_type VARCHAR(50)); INSERT INTO smart_farm_3 (crop_type) VALUES ('Corn'),('Soybean'),('Wheat'),('Rice'); CREATE TABLE smart_farm_4 (crop_type VARCHAR(50)); INSERT INTO smart_farm_4 (crop_type) VALUES ('Corn'),('Soybean'),('Barley'),('Oats');
SELECT crop_type FROM smart_farm_3 WHERE crop_type IN (SELECT crop_type FROM smart_farm_4);
How many defense projects have been completed by 'Delta Defense' in 'South America' since 2010?
CREATE TABLE DefenseProjects (contractor VARCHAR(255),project_name VARCHAR(255),start_date DATE,end_date DATE);
SELECT COUNT(*) FROM DefenseProjects WHERE contractor = 'Delta Defense' AND region = 'South America' AND start_date <= '2010-12-31' AND end_date <= '2010-12-31' AND end_date IS NOT NULL;
What is the average depth of the Atlantic Ocean by region?
CREATE TABLE ocean_regions (region VARCHAR(255),depth FLOAT);
SELECT region, AVG(depth) FROM ocean_regions GROUP BY region;
List all legal technology programs from the 'programs' table
CREATE TABLE programs (id INT,name VARCHAR(50),location VARCHAR(50),type VARCHAR(50),start_date DATE,end_date DATE);
SELECT * FROM programs WHERE type = 'Legal Technology';
How many customers have made more than 5 transactions in the financial crimes table?
CREATE TABLE financial_crimes (customer_id INT,transaction_date DATE,transaction_value DECIMAL(10,2)); INSERT INTO financial_crimes (customer_id,transaction_date,transaction_value) VALUES (1,'2022-01-01',5000.00),(1,'2022-01-02',3000.00),(1,'2022-01-03',1000.00),(2,'2022-01-01',1000.00),(2,'2022-01-02',2000.00),(3,'202...
SELECT COUNT(*) FROM (SELECT customer_id, COUNT(*) FROM financial_crimes GROUP BY customer_id HAVING COUNT(*) > 5);
What's the percentage of climate finance allocated to climate mitigation projects by international organizations?
CREATE TABLE international_organizations(project_id INT,project_name TEXT,sector TEXT,amount_funded FLOAT);
SELECT (SUM(CASE WHEN sector = 'climate mitigation' THEN amount_funded ELSE 0 END) / SUM(amount_funded)) * 100 FROM international_organizations WHERE sector IN ('climate mitigation', 'climate adaptation');
List all marine protected areas in the 'Caribbean' region.
CREATE TABLE marine_protected_areas (country VARCHAR(255),name VARCHAR(255),size FLOAT,region VARCHAR(255)); INSERT INTO marine_protected_areas (country,name,size,region) VALUES ('Bahamas','Exuma Cays Land and Sea Park',119.5,'Caribbean'),('Cuba','Gardens of the Queen',840.0,'Caribbean');
SELECT * FROM marine_protected_areas WHERE region = 'Caribbean';
What is the percentage of energy consumption that comes from nuclear power in France?
CREATE TABLE Energy_Consumption (Country VARCHAR(20),Source VARCHAR(20),Consumption INT); INSERT INTO Energy_Consumption VALUES ('France','Nuclear',250000),('France','Renewable',120000),('France','Fossil Fuels',130000);
SELECT (SUM(CASE WHEN Source = 'Nuclear' THEN Consumption ELSE 0 END) * 100.0 / SUM(Consumption)) AS Nuclear_Percentage FROM Energy_Consumption WHERE Country = 'France';
What is the average attendance for comedy events?
CREATE TABLE Events (Id INT,Name VARCHAR(50),Type VARCHAR(50),Attendees INT);
SELECT AVG(Attendees) FROM Events WHERE Type = 'Comedy';