instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the average transaction fee for digital assets created by developers from India?
CREATE TABLE Developers (developer_id INT,developer_name TEXT,developer_country TEXT); INSERT INTO Developers (developer_id,developer_name,developer_country) VALUES (1,'Alice','India'),(2,'Bob','Canada'); CREATE TABLE DigitalAssets (asset_id INT,asset_name TEXT,developer_id INT,transaction_fee DECIMAL(10,2)); INSERT INTO DigitalAssets (asset_id,asset_name,developer_id,transaction_fee) VALUES (1,'Asset1',1,10.50),(2,'Asset2',1,20.00),(3,'Asset3',2,5.00);
SELECT AVG(DigitalAssets.transaction_fee) FROM DigitalAssets INNER JOIN Developers ON DigitalAssets.developer_id = Developers.developer_id WHERE Developers.developer_country = 'India';
List the names of renewable energy projects in France that were completed after 2015.
CREATE TABLE renewable_energy_projects (id INT,name TEXT,country TEXT,completion_date DATE); INSERT INTO renewable_energy_projects (id,name,country,completion_date) VALUES (1,'Solar Farm 1','France','2016-01-01'); INSERT INTO renewable_energy_projects (id,name,country,completion_date) VALUES (2,'Wind Farm 2','France','2014-01-01');
SELECT name FROM renewable_energy_projects WHERE country = 'France' AND completion_date > '2015-01-01';
What is the average budget for support programs by region?
CREATE TABLE support_programs (program_id INT,program_name VARCHAR(50),budget INT,region VARCHAR(50)); INSERT INTO support_programs (program_id,program_name,budget,region) VALUES (1,'Assistive Technology',50000,'Northeast');
SELECT region, AVG(budget) as avg_budget FROM support_programs GROUP BY region;
What is the latest launch date of a satellite by China or India?
CREATE TABLE satellites (id INT,country VARCHAR(255),launch_date DATE);
SELECT MAX(launch_date) FROM satellites WHERE country IN ('China', 'India');
What is the total number of high-risk vulnerabilities that have been open for more than 60 days?
CREATE TABLE Vulnerabilities (id INT,name VARCHAR(255),risk_score INT,open_date DATE,resolved DATE); INSERT INTO Vulnerabilities (id,name,risk_score,open_date,resolved) VALUES (7,'Curious George',9,'2022-01-01',NULL);
SELECT COUNT(*) FROM Vulnerabilities WHERE risk_score >= 9 AND open_date <= DATE_SUB(CURDATE(), INTERVAL 60 DAY) AND resolved IS NULL;
What is the total revenue for Restaurant I in the month of March 2021?
CREATE TABLE revenue (restaurant_id INT,revenue_date DATE,amount DECIMAL); INSERT INTO revenue (restaurant_id,revenue_date,amount) VALUES (1,'2021-01-01',5000),(1,'2021-02-01',6000),(2,'2021-03-01',7000),(2,'2021-04-01',8000),(3,'2021-05-01',9000);
SELECT SUM(r.amount) as total_revenue FROM revenue r WHERE r.restaurant_id = 7 AND EXTRACT(MONTH FROM r.revenue_date) = 3 AND EXTRACT(YEAR FROM r.revenue_date) = 2021;
What is the minimum water pH level in Bass Farms?
CREATE TABLE Bass_Farms (Farm_ID INT,Farm_Name TEXT,Water_pH FLOAT); INSERT INTO Bass_Farms (Farm_ID,Farm_Name,Water_pH) VALUES (1,'Farm J',7.2); INSERT INTO Bass_Farms (Farm_ID,Farm_Name,Water_pH) VALUES (2,'Farm K',7.4); INSERT INTO Bass_Farms (Farm_ID,Farm_Name,Water_pH) VALUES (3,'Farm L',7.6);
SELECT MIN(Water_pH) FROM Bass_Farms;
What is the total number of volunteers who engaged in programs in the second half of 2020, and the total amount of time they volunteered in that time period, broken down by program?
CREATE TABLE Volunteers (VolunteerID INT,Name TEXT,ProgramID INT,VolunteerHours DECIMAL(10,2),VolunteerDate DATE); INSERT INTO Volunteers VALUES (1,'Nia White',1,5.00,'2020-07-01'),(2,'Jamal Brown',1,3.00,'2020-12-31'),(3,'Fatima Davis',2,4.00,'2020-08-01'),(4,'Kareem Johnson',2,6.00,'2020-11-01');
SELECT P.ProgramID, P.ProgramName, COUNT(*) as NumVolunteers, SUM(VolunteerHours) as TotalHours FROM Volunteers V INNER JOIN Programs P ON V.ProgramID = P.ProgramID WHERE MONTH(VolunteerDate) >= 7 AND YEAR(VolunteerDate) = 2020 GROUP BY P.ProgramID, P.ProgramName;
What is the average mental health score for students in each grade level, by gender?
CREATE TABLE student_mental_health (student_id INT,grade INT,score INT,gender TEXT); INSERT INTO student_mental_health (student_id,grade,score,gender) VALUES (1,6,75,'Male'),(2,8,82,'Female'),(3,9,78,'Non-binary'),(4,10,85,'Male'),(5,6,68,'Female'),(6,9,90,'Non-binary');
SELECT grade, gender, AVG(score) FROM student_mental_health GROUP BY grade, gender;
What is the most common mental health condition treated in a public awareness campaign?
CREATE TABLE campaigns (campaign_id INT,condition_targeted VARCHAR(50),reach INT); INSERT INTO campaigns (campaign_id,condition_targeted,reach) VALUES (1,'Depression',1000);
SELECT condition_targeted, MAX(reach) FROM campaigns GROUP BY condition_targeted;
Which routes have accessibility features in the 'routes' schema?
CREATE SCHEMA routes; CREATE TABLE routes.route_data (id INT PRIMARY KEY,name VARCHAR(255),accessible BOOLEAN); INSERT INTO routes.route_data (id,name,accessible) VALUES (1,'Route 1',true),(2,'Route 2',false),(3,'Route 3',true),(4,'Route 4',false);
SELECT name FROM routes.route_data WHERE accessible = true;
What is the total quantity of product A produced by each factory, ordered by the factories' names?
CREATE TABLE factories (factory_id INT,name VARCHAR(50)); INSERT INTO factories (factory_id,name) VALUES (1,'Factory A'),(2,'Factory B'); CREATE TABLE products (product_id INT,name VARCHAR(50),factory_id INT); INSERT INTO products (product_id,name,factory_id) VALUES (1,'Product A',1),(2,'Product B',1),(3,'Product A',2); CREATE TABLE production (product_id INT,quantity INT,production_date DATE); INSERT INTO production (product_id,quantity,production_date) VALUES (1,500,'2021-01-01'),(2,300,'2021-01-01'),(3,400,'2021-01-02');
SELECT f.name, SUM(p.quantity) as total_quantity FROM factories f JOIN products pr ON f.factory_id = pr.factory_id JOIN production p ON pr.product_id = p.product_id WHERE pr.name = 'Product A' GROUP BY f.name ORDER BY f.name;
What is the percentage of agricultural innovation projects in 'rural_development' schema, categorized by funding source?
CREATE TABLE innovation_projects(id INT,funding_source VARCHAR(50),value INT); INSERT INTO innovation_projects VALUES (1,'Government',1000),(2,'Private',2000),(3,'Government',1500);
SELECT funding_source, (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM innovation_projects)) as percentage FROM innovation_projects GROUP BY funding_source;
What is the average ESG score for organizations in the Consumer Staples sector?
CREATE TABLE org_consumer_staples (id INT,name VARCHAR(100),sector VARCHAR(50),ESG_score FLOAT); INSERT INTO org_consumer_staples (id,name,sector,ESG_score) VALUES (1,'Procter & Gamble','Consumer Staples',70.0),(2,'Coca-Cola','Consumer Staples',75.0),(3,'PepsiCo','Consumer Staples',72.5);
SELECT AVG(ESG_score) FROM org_consumer_staples WHERE sector = 'Consumer Staples';
Insert a new record into the 'charging_stations' table with 'station_name'='City Hall', 'city'='San Francisco', 'num_ports'=10
CREATE TABLE charging_stations (id INT PRIMARY KEY,station_name VARCHAR(255),city VARCHAR(255),num_ports INT);
INSERT INTO charging_stations (station_name, city, num_ports) VALUES ('City Hall', 'San Francisco', 10);
How many artifacts are there at each site in the 'Northern Region'?
CREATE TABLE excavation_sites (site_id INT,site_name TEXT,region TEXT); CREATE TABLE artifacts (artifact_id INT,site_id INT,artifact_type TEXT); INSERT INTO excavation_sites (site_id,site_name,region) VALUES (1,'Site A','Northern Region'),(2,'Site B','Western Region'),(3,'Site C','Southern Region'); INSERT INTO artifacts (artifact_id,site_id,artifact_type) VALUES (1,1,'pottery'),(2,1,'stone'),(3,2,'metal'),(4,3,'pottery'),(5,3,'wooden'),(6,1,'metal'),(7,2,'stone');
SELECT e.site_name, COUNT(a.artifact_id) as artifact_count FROM excavation_sites e JOIN artifacts a ON e.site_id = a.site_id WHERE e.region = 'Northern Region' GROUP BY e.site_name;
What is the distribution of directors by genre in the Media database?
CREATE TABLE GenreDirectors (MovieTitle VARCHAR(50),Genre VARCHAR(50),Director VARCHAR(50)); INSERT INTO GenreDirectors (MovieTitle,Genre,Director) VALUES ('The Godfather','Crime','Francis Ford Coppola'),('The Shawshank Redemption','Drama','Frank Darabont'),('The Godfather: Part II','Crime','Francis Ford Coppola'),('The Dark Knight','Crime','Christopher Nolan'),('Star Wars: Episode IV - A New Hope','Sci-Fi','George Lucas');
SELECT Genre, Director, COUNT(*) as CountOfMovies FROM GenreDirectors GROUP BY Genre, Director;
Which gender participated the most in depression-related campaigns since 2010?
CREATE TABLE campaigns (campaign_id INT,campaign_name TEXT,launch_date DATE,country TEXT,target_demographic TEXT); INSERT INTO campaigns (campaign_id,campaign_name,launch_date,country,target_demographic) VALUES (1,'Campaign A','2010-01-01','India','Depression - Female'); INSERT INTO campaigns (campaign_id,campaign_name,launch_date,country,target_demographic) VALUES (2,'Campaign B','2011-05-15','India','Depression - Male');
SELECT target_demographic, COUNT(*) AS campaigns_per_gender FROM campaigns WHERE launch_date >= '2010-01-01' AND target_demographic LIKE '%Depression%' GROUP BY target_demographic;
What is the total landfill capacity in cubic meters for Oceania?
CREATE TABLE LandfillCapacity (country VARCHAR(255),landfill_capacity_cubic_meters DECIMAL(15,2),region VARCHAR(255)); INSERT INTO LandfillCapacity (country,landfill_capacity_cubic_meters,region) VALUES ('Australia',30000000.0,'Oceania'),('New Zealand',1500000.0,'Oceania');
SELECT SUM(landfill_capacity_cubic_meters) FROM LandfillCapacity WHERE region = 'Oceania';
What's the viewership trend for comedy shows?
CREATE TABLE shows (id INT,title VARCHAR(100),genre VARCHAR(50),viewership INT); INSERT INTO shows (id,title,genre,viewership) VALUES (1,'Show1','Comedy',1000000),(2,'Show2','Drama',8000000),(3,'Show3','Comedy',12000000);
SELECT genre, AVG(viewership) FROM shows WHERE genre = 'Comedy' GROUP BY genre;
What is the most expensive space mission by NASA?
CREATE TABLE SpaceMissions (name TEXT,agency TEXT,cost INTEGER);INSERT INTO SpaceMissions (name,agency,cost) VALUES ('Hubble Space Telescope','NASA',4800000000); INSERT INTO SpaceMissions (name,agency,cost) VALUES ('James Webb Space Telescope','NASA',10000000000);
SELECT name FROM SpaceMissions WHERE agency = 'NASA' ORDER BY cost DESC LIMIT 1;
What is the total quantity of each size in the 'inventory' table?
CREATE TABLE inventory (id INT,size INT,quantity INT); INSERT INTO inventory (id,size,quantity) VALUES (1,8,25),(2,10,30),(3,12,40);
SELECT size, SUM(quantity) FROM inventory GROUP BY size;
How many unique users have streamed songs from the country genre?
CREATE TABLE songs (id INT,title VARCHAR(255),genre VARCHAR(255),release_year INT); CREATE TABLE streams (stream_id INT,song_id INT,user_id INT,timestamp TIMESTAMP); INSERT INTO songs (id,title,genre,release_year) VALUES (1,'Song1','Country',2016),(2,'Song2','Rock',2010),(3,'Song3','Country',2015); INSERT INTO streams (stream_id,song_id,user_id,timestamp) VALUES (1,1,1,'2022-01-01 10:00:00'),(2,2,2,'2022-01-02 10:00:00'),(3,1,3,'2022-01-03 10:00:00'),(4,3,4,'2022-01-04 10:00:00'),(5,1,5,'2022-01-05 10:00:00');
SELECT COUNT(DISTINCT user_id) FROM streams JOIN songs ON streams.song_id = songs.id WHERE songs.genre = 'Country';
What is the average number of streams per user for R&B songs in Canada?
CREATE TABLE Streams (StreamID INT,UserID INT,SongID INT,StreamDate TIMESTAMP,Country VARCHAR(50)); CREATE TABLE Users (UserID INT,UserName VARCHAR(100)); CREATE TABLE Songs (SongID INT,SongName VARCHAR(100),ArtistID INT,Genre VARCHAR(50)); INSERT INTO Streams VALUES (1,1,1,'2023-01-01 10:00:00','Canada'),(2,1,2,'2023-01-01 11:00:00','Canada'),(3,2,1,'2023-01-02 12:00:00','Canada'); INSERT INTO Users VALUES (1,'John Doe'),(2,'Jane Doe'); INSERT INTO Songs VALUES (1,'Love Song',1,'R&B'),(2,'Rock Out',2,'Rock');
SELECT AVG(StreamsPerUser) FROM (SELECT UserID, COUNT(*) AS StreamsPerUser FROM Streams JOIN Users ON Streams.UserID = Users.UserID JOIN Songs ON Streams.SongID = Songs.SongID WHERE Songs.Genre = 'R&B' AND Streams.Country = 'Canada' GROUP BY UserID) AS SubQuery;
What is the minimum age of patients who received teletherapy sessions?
CREATE TABLE patients (patient_id INT,age INT,teletherapy VARCHAR(5)); INSERT INTO patients (patient_id,age,teletherapy) VALUES (1,30,'yes'),(2,45,'no'),(3,50,'yes'),(4,25,'no'),(5,40,'yes'),(6,35,'yes');
SELECT MIN(age) FROM patients WHERE teletherapy = 'yes';
List the players with the highest 3-point shooting percentage in the 'nba_games' table.
CREATE TABLE nba_games (game_id INT,home_team_id INT,away_team_id INT,home_team_points INT,away_team_points INT); CREATE TABLE nba_3_point_shots (game_id INT,player_name VARCHAR(255),three_point_attempts INT,three_point_makes INT);
SELECT player_name, (SUM(three_point_makes) / SUM(three_point_attempts)) * 100 AS three_point_shooting_percentage FROM nba_3_point_shots JOIN nba_games ON nba_3_point_shots.game_id = nba_games.game_id GROUP BY player_name ORDER BY three_point_shooting_percentage DESC LIMIT 3;
Insert a new record for an NGO with the name 'Action Against Hunger' in the ngo_info table.
CREATE TABLE ngo_info (id INT PRIMARY KEY,ngo_name TEXT,ngo_address TEXT);
INSERT INTO ngo_info (id, ngo_name, ngo_address) VALUES (1, 'Action Against Hunger', 'France, Paris');
Which marine conservation initiatives received funding in the past 5 years?'
CREATE TABLE marine_conservation_initiatives (initiative_id INT,name VARCHAR(50),year INT,funding FLOAT);
SELECT name, funding FROM marine_conservation_initiatives WHERE year BETWEEN YEAR(CURRENT_DATE) - 5 AND YEAR(CURRENT_DATE);
What is the most expensive property type in Vancouver?
CREATE TABLE property_prices (property_type VARCHAR(20),city VARCHAR(20),price INT); INSERT INTO property_prices (property_type,city,price) VALUES ('Detached','Vancouver',1500000); INSERT INTO property_prices (property_type,city,price) VALUES ('Townhouse','Vancouver',1200000);
SELECT property_type, MAX(price) FROM property_prices WHERE city = 'Vancouver';
What is the minimum and maximum age of policyholders who have filed a claim?
CREATE TABLE policyholders (id INT,age INT);CREATE TABLE claims (id INT,policyholder_id INT);
SELECT MIN(policyholders.age), MAX(policyholders.age) FROM policyholders JOIN claims ON policyholders.id = claims.policyholder_id;
What is the minimum budget allocated to a project in the Healthcare department?
CREATE TABLE Healthcare_Dept (Project_ID INT,Dept_Name VARCHAR(255),Budget INT); INSERT INTO Healthcare_Dept VALUES (1,'Healthcare',1000000),(2,'Healthcare',1500000),(3,'Healthcare',1200000);
SELECT MIN(Budget) FROM Healthcare_Dept WHERE Dept_Name = 'Healthcare';
What was the minimum age of attendees who participated in 'Dance for All' programs in San Francisco?
CREATE TABLE age_restriction (program_name VARCHAR(50),city VARCHAR(50),min_age INT); INSERT INTO age_restriction (program_name,city,min_age) VALUES ('Dance for All','San Francisco',16);
SELECT MIN(min_age) FROM age_restriction WHERE program_name = 'Dance for All' AND city = 'San Francisco';
How many primary care physicians work in rural healthcare facilities in Texas and California?
CREATE VIEW primary_care_physicians AS SELECT * FROM healthcare_staff WHERE role = 'Primary Care Physician'; CREATE TABLE healthcare_staff (id INT,name TEXT,role TEXT,location TEXT); INSERT INTO healthcare_staff (id,name,role,location) VALUES (1,'Dr. Johnson','Primary Care Physician','Texas'),(2,'Dr. Smith','Primary Care Physician','California'),(3,'Dr. Brown','Nurse','Texas');
SELECT COUNT(*) FROM primary_care_physicians WHERE location IN ('Texas', 'California');
What is the average production cost of ethical fashion items in France?
CREATE TABLE Costs (id INT,item VARCHAR(255),cost DECIMAL(10,2),country VARCHAR(255)); INSERT INTO Costs (id,item,cost,country) VALUES (1,'Dress',120.00,'France'); INSERT INTO Costs (id,item,cost,country) VALUES (2,'Blouse',80.00,'France');
SELECT AVG(cost) FROM Costs WHERE country = 'France' AND item IN ('Dress', 'Blouse')
What is the average production rate per well for each country?
CREATE TABLE Wells (WellID INT,WellName VARCHAR(50),ProductionRate FLOAT,Country VARCHAR(50)); INSERT INTO Wells (WellID,WellName,ProductionRate,Country) VALUES (1,'Well A',500,'USA'),(2,'Well B',600,'Canada'),(3,'Well C',700,'Mexico');
SELECT Country, AVG(ProductionRate) AS AvgProductionRate FROM Wells GROUP BY Country;
Insert a new record into the Warehouse table for a new warehouse in 'City Y'.
CREATE TABLE Warehouse (WarehouseID int,WarehouseName varchar(50),City varchar(50)); INSERT INTO Warehouse VALUES (1,'Warehouse 1','City X'),(2,'Warehouse 2','City Z'),(3,'Warehouse 3','City X');
INSERT INTO Warehouse (WarehouseID, WarehouseName, City) VALUES (4, 'Warehouse 4', 'City Y');
What is the earliest completion year for any renewable energy project in the 'project_summary' table?
CREATE TABLE project_summary (project_id INT,project_type VARCHAR(50),completion_year INT); INSERT INTO project_summary (project_id,project_type,completion_year) VALUES (1,'Wind',2010),(2,'Solar',2012),(3,'Hydro',2005);
SELECT MIN(completion_year) FROM project_summary;
Find the total area and average temperature for farms using a specific fertilizer.
CREATE TABLE farm (id INT,name VARCHAR(50),size FLOAT,fertilizer VARCHAR(50),PRIMARY KEY(id)); INSERT INTO farm (id,name,size,fertilizer) VALUES (1,'Farm A',50.3,'Fertilizer X'); INSERT INTO farm (id,name,size,fertilizer) VALUES (2,'Farm B',75.8,'Fertilizer Y'); CREATE TABLE sensor (id INT,farm_id INT,temperature FLOAT,PRIMARY KEY(id)); INSERT INTO sensor (id,farm_id,temperature) VALUES (1,1,23.5); INSERT INTO sensor (id,farm_id,temperature) VALUES (2,1,24.2); INSERT INTO sensor (id,farm_id,temperature) VALUES (3,2,20.8); CREATE TABLE fertilizer_application (id INT,farm_id INT,application_date DATE,PRIMARY KEY(id)); INSERT INTO fertilizer_application (id,farm_id,application_date) VALUES (1,1,'2022-01-01'); INSERT INTO fertilizer_application (id,farm_id,application_date) VALUES (2,2,'2022-02-01');
SELECT f.fertilizer, SUM(f.size) AS total_area, AVG(s.temperature) AS avg_temperature FROM farm f INNER JOIN sensor s ON f.id = s.farm_id INNER JOIN fertilizer_application a ON f.id = a.farm_id WHERE f.fertilizer = 'Fertilizer X' GROUP BY f.fertilizer;
What is the maximum order quantity for products made with recycled materials?
CREATE TABLE order_quantities (id INT,material VARCHAR(20),order_quantity INT); INSERT INTO order_quantities (id,material,order_quantity) VALUES (1,'Recycled Material A',500),(2,'Virgin Material B',700),(3,'Recycled Material C',600);
SELECT MAX(order_quantity) FROM order_quantities WHERE material LIKE 'Recycled%';
Show the total amount of resources extracted by resource type
CREATE TABLE resource_type (type VARCHAR(255),amount INT); INSERT INTO resource_type (type,amount) VALUES ('Gold',500),('Silver',300),('Coal',700);
SELECT rt.type, SUM(rt.amount) as total_resources_extracted FROM resource_type rt GROUP BY rt.type;
List all managers and their respective departments who have not completed diversity and inclusion training.
CREATE TABLE Employees (EmployeeID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50),Position VARCHAR(50)); CREATE TABLE DiversityTraining (EmployeeID INT,TrainingID INT,Completed DATE); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,Position) VALUES (1,'John','Doe','IT','Manager'),(2,'Jane','Smith','HR','Manager'); INSERT INTO DiversityTraining (EmployeeID,TrainingID,Completed) VALUES (1,1,'2021-06-01');
SELECT Employees.FirstName, Employees.LastName, Employees.Department FROM Employees LEFT JOIN DiversityTraining ON Employees.EmployeeID = DiversityTraining.EmployeeID WHERE Employees.Position = 'Manager' AND DiversityTraining.Completed IS NULL;
How many employees who identify as male were hired in the last 3 months in the Engineering department?
CREATE TABLE Hiring (HireID INT,Gender VARCHAR(10),Department VARCHAR(20),HireDate DATE); INSERT INTO Hiring (HireID,Gender,Department,HireDate) VALUES (1,'Male','Engineering','2022-01-01'),(2,'Female','IT','2022-02-01'),(3,'Non-binary','HR','2022-03-01');
SELECT COUNT(*) FROM Hiring WHERE Gender = 'Male' AND Department = 'Engineering' AND HireDate >= DATE_SUB(CURDATE(), INTERVAL 3 MONTH);
What is the average investment in smart city initiatives per year?
CREATE TABLE initiatives (id INT,name TEXT,year INT,investment FLOAT);
SELECT AVG(investment) FROM initiatives GROUP BY year;
Delete all records from the 'exploration_data' table where the 'discovery_year' is less than 2000
CREATE TABLE exploration_data (id INT,field VARCHAR(50),country VARCHAR(50),discovery_year INT,discovery_number FLOAT); INSERT INTO exploration_data (id,field,country,discovery_year,discovery_number) VALUES (1,'Sahara','Algeria',1999,12345.67); INSERT INTO exploration_data (id,field,country,discovery_year,discovery_number) VALUES (2,'Gulf of Mexico','USA',2000,9876.54);
DELETE FROM exploration_data WHERE discovery_year < 2000;
List the names of members who are older than 35.
CREATE TABLE Members (MemberID INT,Name VARCHAR(50),Age INT); INSERT INTO Members (MemberID,Name,Age) VALUES (1,'John Doe',30); INSERT INTO Members (MemberID,Name,Age) VALUES (2,'Jane Smith',45); INSERT INTO Members (MemberID,Name,Age) VALUES (3,'Alice Johnson',28);
SELECT Name FROM Members WHERE Age > 35;
List the unique industries for startups founded by Latinx individuals that have raised Series B or later funding.
CREATE TABLE startup (id INT,industry TEXT,founder_identity TEXT); INSERT INTO startup (id,industry,founder_identity) VALUES (1,'Software','Latinx Female'),(2,'Hardware','Asian Male'),(3,'Healthcare','Latinx Non-binary'),(4,'AI','Black Female'),(5,'CleanTech','Latinx Male'),(6,'FinTech','AAPI Female');
SELECT DISTINCT industry FROM startup WHERE founder_identity LIKE '%Latinx%' AND funding IN ('Series B', 'Series C', 'Series D', 'Series E');
How many items were sold in each city?
CREATE TABLE sales (id INT,city VARCHAR(255),quantity INT);
SELECT city, SUM(quantity) FROM sales GROUP BY city;
What is the total number of art events in the city of Tokyo for the years 2019 and 2020?
CREATE TABLE events (name VARCHAR(255),location VARCHAR(255),category VARCHAR(255),year INT); INSERT INTO events (name,location,category,year) VALUES ('Van Gogh Alive','Tokyo','Art',2019),('Monet Exhibition','Tokyo','Art',2020),('Hamilton','Tokyo','Theatre',2020);
SELECT COUNT(*) FROM events WHERE location = 'Tokyo' AND year IN (2019, 2020) AND category = 'Art';
What is the total number of tickets sold for each game of the Boston Celtics?
CREATE TABLE games (game_id INT,team_id INT); CREATE TABLE tickets (ticket_id INT,game_id INT,price DECIMAL(5,2)); CREATE TABLE teams (team_id INT,team_name VARCHAR(20)); INSERT INTO teams (team_id,team_name) VALUES (5,'Boston Celtics'); INSERT INTO games (game_id,team_id) VALUES (5,5); INSERT INTO tickets (ticket_id,game_id,price) VALUES (5,5,100.00);
SELECT COUNT(tickets.ticket_id), games.game_id FROM tickets INNER JOIN games ON tickets.game_id = games.game_id INNER JOIN teams ON games.team_id = teams.team_id WHERE teams.team_name = 'Boston Celtics' GROUP BY games.game_id;
Which sustainable material has usage greater than 250?
CREATE TABLE Materials (material_id INT PRIMARY KEY,material VARCHAR(50),usage INT); INSERT INTO Materials (material_id,material,usage) VALUES (1,'Organic Cotton',500),(2,'Recycled Polyester',300),(3,'Hemp',100);
SELECT material FROM Materials WHERE usage > 250;
Identify vessels with safety scores between 70 and 85.
CREATE TABLE VesselSafety (VesselID INT,SafetyScore DECIMAL(3,1)); INSERT INTO VesselSafety (VesselID,SafetyScore) VALUES (1,60.2),(2,82.1),(3,73.3),(4,91.1);
SELECT VesselID FROM VesselSafety WHERE SafetyScore BETWEEN 70 AND 85;
How many cargo ships are currently in the 'cargoships' table?
CREATE TABLE cargoships (id INT PRIMARY KEY,name VARCHAR(50),status VARCHAR(20));
SELECT COUNT(*) FROM cargoships WHERE status = 'active';
What is the total number of spacecraft manufactured by AstroCorp?
CREATE TABLE Spacecraft (id INT,name VARCHAR(255),manufacturer VARCHAR(255)); INSERT INTO Spacecraft (id,name,manufacturer) VALUES (1,'Voyager 1','AstroCorp'); INSERT INTO Spacecraft (id,name,manufacturer) VALUES (2,'Voyager 2','AstroCorp');
SELECT COUNT(*) FROM Spacecraft WHERE manufacturer = 'AstroCorp';
List all traditional arts and their origins from the "arts" table.
CREATE TABLE arts (id INT,art_name VARCHAR(50),origin_country VARCHAR(50)); INSERT INTO arts (id,art_name,origin_country) VALUES (1,'Ukiyo-e','Japan'),(2,'Batik','Indonesia');
SELECT art_name, origin_country FROM arts;
Update the 'wastewater_treatment' table to reflect a 15% increase in the 'treatment_efficiency' for the 'West' region
CREATE TABLE wastewater_treatment (id INT PRIMARY KEY,region VARCHAR(20),treatment_efficiency DECIMAL(5,2));
UPDATE wastewater_treatment SET treatment_efficiency = treatment_efficiency * 1.15 WHERE region = 'West';
Delete menu items that have not been ordered in the last 30 days.
CREATE TABLE Restaurants (RestaurantID INT,Name VARCHAR(50)); CREATE TABLE Menu (MenuID INT,RestaurantID INT,Item VARCHAR(50),Price DECIMAL(10,2),LastOrderDate DATE);
DELETE FROM Menu WHERE LastOrderDate < DATE_SUB(CURDATE(), INTERVAL 30 DAY);
List all projects in the "public" schema that have a start date within the last 30 days?
CREATE TABLE IF NOT EXISTS public.projects (id SERIAL PRIMARY KEY,name TEXT,start_date DATE); INSERT INTO public.projects (name,start_date) SELECT 'ExampleProject1',CURRENT_DATE - INTERVAL '15 days' FROM generate_series(1,10); INSERT INTO public.projects (name,start_date) SELECT 'ExampleProject2',CURRENT_DATE - INTERVAL '60 days' FROM generate_series(1,10);
SELECT name, start_date FROM public.projects WHERE start_date >= CURRENT_DATE - INTERVAL '30 days';
Update the records of players who are interested in esports events and have participated in more than 5 events to indicate that they are professional players.
CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),EsportsInterest BOOLEAN,EventsPlayed INT);CREATE TABLE EsportsEvents (EventID INT,PlayerID INT,EventType VARCHAR(20));
UPDATE Players SET EsportsInterest = TRUE WHERE EventsPlayed > 5 AND EsportsInterest = TRUE;
Create a table named 'ocean_health'
CREATE TABLE ocean_health (id INT PRIMARY KEY,location VARCHAR(255),temperature FLOAT,ph FLOAT);
CREATE TABLE ocean_health (id INT PRIMARY KEY, location VARCHAR(255), temperature FLOAT, ph FLOAT);
What are the companies that have CO2 emissions greater than 14000 and are located in Asia?
CREATE TABLE emissions (id INT,year INT,company VARCHAR(50),co2_emissions INT,location VARCHAR(50)); INSERT INTO emissions (id,year,company,co2_emissions,location) VALUES (1,2015,'Neo Chemicals & Metals Ltd',12000,'India'); INSERT INTO emissions (id,year,company,co2_emissions,location) VALUES (2,2016,'Luoyang Molibdenum',15000,'China'); INSERT INTO emissions (id,year,company,co2_emissions,location) VALUES (3,2017,'Asian Rare Earth',14000,'China');
SELECT company FROM emissions WHERE co2_emissions > 14000 AND location LIKE 'Asia%';
What is the average energy efficiency rating of hotels in London?
CREATE TABLE hotel_ratings (hotel_id INT,name VARCHAR(255),city VARCHAR(255),energy_efficiency_rating DECIMAL(3,2)); INSERT INTO hotel_ratings (hotel_id,name,city,energy_efficiency_rating) VALUES (1,'EcoHotel London','London',4.20),(2,'GreenHotel London','London',4.80);
SELECT AVG(energy_efficiency_rating) FROM hotel_ratings WHERE city = 'London';
Insert new exploration data for Well K in the North Sea.
CREATE TABLE exploration_data (well_name VARCHAR(50),location VARCHAR(50),discovery_date DATE,reserves_oil NUMERIC(10,2),reserves_gas NUMERIC(10,2));
INSERT INTO exploration_data (well_name, location, discovery_date, reserves_oil, reserves_gas) VALUES ('Well K', 'North Sea', '2023-02-15', 5000000, 2000000);
What is the average donation amount for each disaster type?
CREATE TABLE donations (id INT PRIMARY KEY,donor_name VARCHAR(50),disaster_type VARCHAR(50),donation_amount DECIMAL(10,2)); INSERT INTO donations (id,donor_name,disaster_type,donation_amount) VALUES (1,'John Doe','Earthquake',100.00),(2,'Jane Smith','Flood',200.00),(3,'Mike Johnson','Tornado',50.00);
SELECT disaster_type, AVG(donation_amount) as avg_donation FROM donations GROUP BY disaster_type;
Which destinations have the most sustainable tourism awards?
CREATE TABLE Destinations (destination_id INT,destination_name TEXT,country TEXT,awards INT); INSERT INTO Destinations (destination_id,destination_name,country,awards) VALUES (1,'City A','Germany',3),(2,'City B','Switzerland',5),(3,'City C','Norway',2);
SELECT destination_name, country, awards, RANK() OVER (PARTITION BY country ORDER BY awards DESC) AS rank FROM Destinations;
Calculate the total funding for startups in the renewable energy sector founded since 2010
CREATE TABLE funding (id INT,company_id INT,amount INT,industry TEXT,founding_year INT); INSERT INTO funding (id,company_id,amount,industry,founding_year) VALUES (1,1,75000,'Renewable Energy',2012); INSERT INTO funding (id,company_id,amount,industry,founding_year) VALUES (2,2,100000,'Finance',2008);
SELECT SUM(amount) FROM funding JOIN company ON funding.company_id = company.id WHERE funding.industry = 'Renewable Energy' AND company.founding_year >= 2010
What is the total spending on cultural competency programs in Wisconsin and Minnesota?
CREATE TABLE cultural_competency_programs (program_id INT,name TEXT,state TEXT,spending INT); INSERT INTO cultural_competency_programs (program_id,name,state,spending) VALUES (1,'Program A','Wisconsin',11000),(2,'Program B','Minnesota',13000),(3,'Program C','Wisconsin',12000),(4,'Program D','Minnesota',14000);
SELECT state, SUM(spending) FROM cultural_competency_programs WHERE state IN ('Wisconsin', 'Minnesota') GROUP BY state;
What is the total biomass of fish caught for each species in the Mediterranean?
CREATE TABLE fish_catch_data (species VARCHAR(255),region VARCHAR(255),biomass FLOAT); INSERT INTO fish_catch_data (species,region,biomass) VALUES ('Salmon','North Atlantic',5000),('Salmon','Mediterranean',1200),('Cod','North Atlantic',7000),('Halibut','Pacific',8000),('Tuna','Mediterranean',9000),('Sardines','Atlantic',3000);
SELECT species, region, SUM(biomass) as total_biomass FROM fish_catch_data WHERE region = 'Mediterranean' GROUP BY species, region;
What is the average cultural competency score of community health workers who have completed cultural competency training?
CREATE TABLE cultural_competency_scores (id INT,worker_id INT,score INT); CREATE TABLE cultural_competency_training (id INT,worker_id INT); INSERT INTO cultural_competency_scores (id,worker_id,score) VALUES (1,1,85),(2,2,95),(3,3,75); INSERT INTO cultural_competency_training (id,worker_id) VALUES (1,1),(2,2);
SELECT AVG(ccs.score) FROM cultural_competency_scores ccs INNER JOIN cultural_competency_training cct ON ccs.worker_id = cct.worker_id;
What was the total revenue for each art movement's works sold in 2022?
CREATE TABLE ArtMovementSales (ArtMovement VARCHAR(255),ArtWork VARCHAR(255),Year INT,Revenue DECIMAL(10,2)); INSERT INTO ArtMovementSales (ArtMovement,ArtWork,Year,Revenue) VALUES ('Post-Impressionism','Artwork 1',2022,500.00),('Post-Impressionism','Artwork 2',2022,400.00),('Pop Art','Artwork 3',2022,750.00),('Pop Art','Artwork 4',2022,1000.00);
SELECT ArtMovement, SUM(Revenue) as TotalRevenue FROM ArtMovementSales WHERE Year = 2022 GROUP BY ArtMovement;
What is the total runtime of movies directed by female directors and released after 2010?
CREATE TABLE Directors (id INT,director_name VARCHAR(100),gender VARCHAR(10)); CREATE TABLE Movies (id INT,title VARCHAR(100),director_id INT,runtime INT,release_year INT); INSERT INTO Directors (id,director_name,gender) VALUES (1,'Director1','Female'),(2,'Director2','Male'),(3,'Director3','Female'); INSERT INTO Movies (id,title,director_id,runtime,release_year) VALUES (1,'Movie1',1,120,2011),(2,'Movie2',1,90,2012),(3,'Movie3',2,100,2013),(4,'Movie4',3,110,2016);
SELECT SUM(runtime) FROM Movies WHERE director_id IN (SELECT id FROM Directors WHERE gender = 'Female') AND release_year > 2010;
What is the total amount of funding received by refugee support organizations in Asia?
CREATE TABLE funding (id INT,organization VARCHAR(255),region VARCHAR(255),amount DECIMAL(10,2));
SELECT SUM(amount) FROM funding WHERE region = 'Asia' AND organization LIKE '%refugee support%';
How many freedom of information requests were submitted to the city of Toronto in 2020?
CREATE TABLE foia_requests (id INT,city VARCHAR,year INT,submitted BOOLEAN); INSERT INTO foia_requests (id,city,year,submitted) VALUES (1,'Toronto',2020,TRUE);
SELECT COUNT(*) FROM foia_requests WHERE city = 'Toronto' AND year = 2020 AND submitted = TRUE;
What is the number of climate communication initiatives and their total budget in Africa in the year 2021?
CREATE TABLE climate_communication (initiative_name VARCHAR(50),location VARCHAR(50),year INT,budget INT); INSERT INTO climate_communication (initiative_name,location,year,budget) VALUES ('African Climate Congress','Kenya',2021,100000); INSERT INTO climate_communication (initiative_name,location,year,budget) VALUES ('Climate Schools','Nigeria',2021,150000); INSERT INTO climate_communication (initiative_name,location,year,budget) VALUES ('Climate Art','South Africa',2021,200000);
SELECT COUNT(*) as num_initiatives, SUM(budget) as total_budget FROM climate_communication WHERE year = 2021 AND location = 'Africa';
Show all peacekeeping operations that started after 2015
CREATE TABLE peacekeeping_operations (id INT,name VARCHAR(255),start_date DATE);
SELECT * FROM peacekeeping_operations WHERE start_date > '2015-01-01';
What is the total cargo weight handled by each port?
CREATE TABLE ports (port_id INT,port_name TEXT,country TEXT); INSERT INTO ports (port_id,port_name,country) VALUES (1,'Port A','USA'),(2,'Port B','Canada'); CREATE TABLE shipments (shipment_id INT,port_id INT,cargo_weight INT); INSERT INTO shipments (shipment_id,port_id,cargo_weight) VALUES (1,1,5000),(2,1,5500),(3,2,4000),(4,2,4500);
SELECT ports.port_name, SUM(shipments.cargo_weight) FROM ports JOIN shipments ON ports.port_id = shipments.port_id GROUP BY ports.port_name;
Delete records from the 'Farmers' table where the 'region' is 'North'
CREATE TABLE Farmers (id INT,name VARCHAR(50),age INT,region VARCHAR(20),innovation_score FLOAT);
DELETE FROM Farmers WHERE region = 'North';
What is the name of the supplier with the highest rating for part 'P1'?
CREATE TABLE part_suppliers (id INT,part_id INT,supplier_id INT,rating INT); INSERT INTO part_suppliers (id,part_id,supplier_id,rating) VALUES (1,1,1,90),(2,1,2,85),(3,2,1,92),(4,2,2,95);
SELECT supplier_id FROM part_suppliers WHERE part_id = 1 ORDER BY rating DESC LIMIT 1; SELECT name FROM suppliers WHERE id = (SELECT supplier_id FROM part_suppliers WHERE part_id = 1 ORDER BY rating DESC LIMIT 1);
Find the total billing amount for cases in the family law category that were opened before 2020-01-01.
CREATE TABLE cases (case_id INT,category VARCHAR(20),billing_amount DECIMAL(10,2),opened_date DATE);
SELECT SUM(billing_amount) FROM cases WHERE category = 'family' AND opened_date < '2020-01-01';
What is the average number of posts per day for users in 'US' region?
CREATE TABLE users (id INT,name VARCHAR(50),region VARCHAR(50)); INSERT INTO users (id,name,region) VALUES (1,'John Doe','US'),(2,'Jane Smith','CA'); CREATE TABLE posts (id INT,user_id INT,content TEXT,date DATE); INSERT INTO posts (id,user_id,content,date) VALUES (1,1,'Hello World!','2021-01-01'),(2,1,'Test Post','2021-01-02');
SELECT AVG(COUNT(posts.date)) FROM posts JOIN users ON posts.user_id = users.id WHERE users.region = 'US' GROUP BY users.id;
Delete records in the wildlife table where the animal_type is 'Mammal' and region is 'Europe'
CREATE TABLE wildlife (id INT PRIMARY KEY,animal_type TEXT,region TEXT,conservation_status TEXT); INSERT INTO wildlife (id,animal_type,region,conservation_status) VALUES (1,'Mammal','Europe','Endangered');
DELETE FROM wildlife WHERE animal_type = 'Mammal' AND region = 'Europe';
What is the name and date of the most recent public hearing in the South?
CREATE TABLE public_hearings (hearing_id INT,hearing_name VARCHAR(255),state VARCHAR(255),region VARCHAR(255),hearing_date DATE); INSERT INTO public_hearings (hearing_id,hearing_name,state,region,hearing_date) VALUES (1,'Hearing A','Florida','South','2022-03-01'),(2,'Hearing B','Georgia','South','2022-04-01');
SELECT hearing_name, hearing_date FROM public_hearings WHERE region = 'South' ORDER BY hearing_date DESC LIMIT 1;
What is the total amount donated to effective altruism causes in the last 5 years?
CREATE TABLE donations (id INT,cause VARCHAR(50),donation DECIMAL(10,2),donation_date DATE);
SELECT SUM(donation) FROM donations WHERE cause = 'Effective Altruism' AND donation_date >= DATEADD(year, -5, GETDATE());
Identify the top 3 health issues affecting the elderly population in India, based on hospital admission records.
CREATE TABLE hospital_admissions (id INT,admission_id INT,patient_id INT,issue VARCHAR(50),admission_date DATE,age INT,country VARCHAR(50)); INSERT INTO hospital_admissions (id,admission_id,patient_id,issue,admission_date,age,country) VALUES (1,2001,901,'Heart Disease','2021-01-01',75,'India'); INSERT INTO hospital_admissions (id,admission_id,patient_id,issue,admission_date,age,country) VALUES (2,2002,902,'Diabetes','2021-02-10',80,'India');
SELECT issue, COUNT(*) AS admissions FROM hospital_admissions WHERE country = 'India' AND age >= 60 GROUP BY issue ORDER BY admissions DESC LIMIT 3;
What was the average daily revenue for each restaurant category in 2022?
CREATE TABLE daily_revenue (restaurant_name TEXT,category TEXT,daily_revenue NUMERIC,date DATE); INSERT INTO daily_revenue (restaurant_name,category,daily_revenue,date) VALUES ('ABC Bistro','Italian',250,'2022-01-01'),('ABC Bistro','Italian',250,'2022-01-02'),('XYZ Café','Coffee Shop',150,'2022-01-01'),('XYZ Café','Coffee Shop',150,'2022-01-02');
SELECT category, AVG(daily_revenue) as avg_daily_revenue FROM daily_revenue WHERE date BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY category;
What is the maximum transaction amount for a customer in the Asia-Pacific region?
CREATE TABLE regions (customer_id INT,name VARCHAR(50),region VARCHAR(20)); INSERT INTO regions (customer_id,name,region) VALUES (1,'John Doe','Asia-Pacific'),(2,'Jane Smith','Europe'),(3,'Alice Johnson','Asia-Pacific'),(4,'Bob Brown','Americas'); CREATE TABLE transactions_5 (transaction_id INT,customer_id INT,amount DECIMAL(10,2)); INSERT INTO transactions_5 (transaction_id,customer_id,amount) VALUES (1,1,500.00),(2,1,750.00),(3,2,300.00),(4,3,1000.00);
SELECT MAX(amount) FROM transactions_5 t JOIN regions r ON t.customer_id = r.customer_id WHERE r.region = 'Asia-Pacific';
What are the average home run distances for athletes in the MLB?
CREATE TABLE mlb_home_runs (player_id INT,player_name VARCHAR(50),home_run_distance FLOAT); INSERT INTO mlb_home_runs (player_id,player_name,home_run_distance) VALUES (1,'Aaron Judge',449.6),(2,'Giancarlo Stanton',434.7),(3,'Nelson Cruz',423.5);
SELECT AVG(home_run_distance) FROM mlb_home_runs;
What is the total sales for each category of menu items?
CREATE TABLE menu (item_id INT,item_name VARCHAR(255),category VARCHAR(255)); CREATE TABLE sales (sales_id INT,item_id INT,sales_amount DECIMAL(5,2)); INSERT INTO menu VALUES (1,'Cheese Pizza','Pizza'),(2,'Margherita Pizza','Pizza'),(3,'Chicken Alfredo','Pasta'),(4,'Beef Lasagna','Pasta'); INSERT INTO sales VALUES (1,1,20.00),(2,1,30.00),(3,2,40.00),(4,3,50.00),(5,4,60.00);
SELECT menu.category, SUM(sales.sales_amount) FROM menu JOIN sales ON menu.item_id = sales.item_id GROUP BY menu.category;
List the circular economy initiatives and their descriptions in 'CountryA'.
CREATE TABLE Country (country_id INT,country_name VARCHAR(255)); INSERT INTO Country (country_id,country_name) VALUES (1,'CountryA'),(2,'CountryB'); CREATE TABLE Initiatives (init_id INT,country_id INT,initiative_name VARCHAR(255),description VARCHAR(255)); INSERT INTO Initiatives (init_id,country_id,initiative_name,description) VALUES (1,1,'Remanufacturing','Reusing components from end-of-life products to make new ones'),(2,1,'Product-as-a-service','Leasing or sharing models instead of selling products'),(3,2,'Refurbishment','Repairing and upgrading used products for resale'),(4,2,'Recycling','Collecting and processing waste materials for reuse');
SELECT Country.country_name, Initiatives.initiative_name, Initiatives.description FROM Country INNER JOIN Initiatives ON Country.country_id = Initiatives.country_id WHERE Country.country_name = 'CountryA';
Count the number of sensors of each type
CREATE TABLE sensor (id INT,type VARCHAR(255)); INSERT INTO sensor (id,type) VALUES (1,'temperature'),(2,'humidity'),(3,'moisture'),(4,'temperature'),(5,'temperature');
SELECT type, COUNT(*) FROM sensor GROUP BY type;
Pivot the 'courses' table to display course name and duration in separate columns
CREATE TABLE courses (course_id INT,course_name_duration VARCHAR(50));
SELECT course_id, SPLIT_PART(course_name_duration, ' ', 1) AS course_name, SPLIT_PART(course_name_duration, ' ', 2) AS course_duration FROM courses;
List all countries that have not reported their plastic waste contribution in the last 2 years.
CREATE TABLE country_plastic_waste (country_name TEXT,last_report_date DATE);
SELECT country_name FROM country_plastic_waste WHERE last_report_date < NOW() - INTERVAL '2 year';
List the vessels that have complied with maritime law in the Indian Ocean for the last 5 years.
CREATE TABLE vessels (vessel_name TEXT,compliance_status TEXT,ocean TEXT,year INT); INSERT INTO vessels (vessel_name,compliance_status,ocean,year) VALUES ('VesselA','compliant','Indian',2018),('VesselB','non-compliant','Indian',2018),('VesselC','compliant','Indian',2018),('VesselA','compliant','Indian',2019),('VesselB','non-compliant','Indian',2019),('VesselC','compliant','Indian',2019);
SELECT vessel_name FROM vessels WHERE compliance_status = 'compliant' AND ocean = 'Indian' AND year BETWEEN 2017 AND 2021;
Remove the ethical manufacturing record with ID 1
CREATE SCHEMA manufacturing;CREATE TABLE ethical_manufacturers (id INT PRIMARY KEY,name TEXT,region TEXT);INSERT INTO ethical_manufacturers (id,name,region) VALUES (1,'Ethical Manufacturer A','North'); INSERT INTO ethical_manufacturers (id,name,region) VALUES (2,'Ethical Manufacturer B','South');
DELETE FROM ethical_manufacturers WHERE id = 1;
What is the average age of female artists in the 'ArtistDemographics' table?
CREATE TABLE ArtistDemographics (ArtistID INT,ArtistAge INT,ArtistGender VARCHAR(10)); INSERT INTO ArtistDemographics (ArtistID,ArtistAge,ArtistGender) VALUES (1,37,'Female'),(2,56,'Male'),(3,81,'Non-binary'),(4,62,'Female'),(5,28,'Female');
SELECT AVG(ArtistAge) AS AvgFemaleArtistAge FROM ArtistDemographics WHERE ArtistGender = 'Female';
What is the maximum advertising spend by companies from Egypt, in April 2022?
CREATE TABLE companies (id INT,name TEXT,country TEXT); INSERT INTO companies (id,name,country) VALUES (1,'Company1','Egypt'),(2,'Company2','Egypt'),(3,'Company3','France'),(4,'Company4','Germany'); CREATE TABLE ad_spend (company_id INT,amount DECIMAL,date DATE); INSERT INTO ad_spend (company_id,amount,date) VALUES (1,1500,'2022-04-01'),(1,1200,'2022-04-05'),(2,1800,'2022-04-03'),(3,800,'2022-04-04'),(4,1000,'2022-04-04');
SELECT MAX(ad_spend.amount) FROM ad_spend JOIN companies ON ad_spend.company_id = companies.id WHERE companies.country = 'Egypt' AND ad_spend.date >= '2022-04-01' AND ad_spend.date <= '2022-04-30';
What are the total items shipped between Mexico and Spain in May 2021?
CREATE TABLE Shipment (id INT,source_country VARCHAR(255),destination_country VARCHAR(255),items_quantity INT,shipment_date DATE); INSERT INTO Shipment (id,source_country,destination_country,items_quantity,shipment_date) VALUES (1,'Mexico','Spain',150,'2021-05-01'),(2,'Spain','Mexico',100,'2021-05-03');
SELECT SUM(items_quantity) FROM Shipment WHERE (source_country = 'Mexico' AND destination_country = 'Spain') OR (source_country = 'Spain' AND destination_country = 'Mexico') AND shipment_date BETWEEN '2021-05-01' AND '2021-05-31';
Show ferry routes with bike racks for the 'South Harbor'
CREATE TABLE ferries (id INT PRIMARY KEY,route_id INT,station VARCHAR(20),bike_racks BOOLEAN);
SELECT DISTINCT route_id, station FROM ferries WHERE station = 'South Harbor' AND bike_racks = TRUE;
How many companies have had an IPO as an exit strategy for each year?
CREATE TABLE company (id INT,name TEXT,founding_date DATE); CREATE TABLE exit_strategy (id INT,company_id INT,exit_date DATE,exit_type TEXT);
SELECT YEAR(exit_strategy.exit_date), COUNT(*) FROM company JOIN exit_strategy ON company.id = exit_strategy.company_id WHERE exit_strategy.exit_type = 'IPO' GROUP BY YEAR(exit_strategy.exit_date);
What is the average delivery time for each carrier, calculated across all shipments?
CREATE TABLE shipments (id INT,carrier VARCHAR(50),delivery_time INT); INSERT INTO shipments (id,carrier,delivery_time) VALUES (1,'Carrier A',5),(2,'Carrier B',7),(3,'Carrier A',6),(4,'Carrier C',4);
SELECT carrier, AVG(delivery_time) as avg_delivery_time FROM shipments GROUP BY carrier;
What is the average weight of containers handled by each crane in port 'Seattle'?
CREATE TABLE port (port_id INT,name TEXT);CREATE TABLE crane (crane_id INT,port_id INT,name TEXT);CREATE TABLE container (container_id INT,crane_id INT,weight INT);INSERT INTO port VALUES (1,'Seattle');
SELECT crane.name, AVG(container.weight) FROM crane JOIN port ON crane.port_id = port.port_id JOIN container ON crane.crane_id = container.crane_id WHERE port.name = 'Seattle' GROUP BY crane.name;