instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Which counties in 'voting_data' table have more than 50,000 registered voters?
CREATE TABLE voting_data (county VARCHAR(255),num_voters INT);
SELECT county FROM voting_data WHERE num_voters > 50000;
Which countries have the highest sales of organic skincare products?
CREATE TABLE sales (sale_id INT,product_id INT,country VARCHAR(50),sales_volume INT); CREATE TABLE products (product_id INT,product_name VARCHAR(100),is_organic BOOLEAN);
SELECT country, SUM(sales_volume) as total_sales FROM sales JOIN products ON sales.product_id = products.product_id WHERE is_organic = TRUE GROUP BY country ORDER BY total_sales DESC LIMIT 5;
What is the total number of likes for posts with the hashtag #climateaction?
CREATE TABLE posts (id INT,hashtags VARCHAR(255),likes INT); INSERT INTO posts (id,hashtags,likes) VALUES (1,'#climateaction,#sustainability',10),(2,'#climateaction',20),(3,'#sustainability,#climateaction',30),(4,'#climatechange',40),(5,'#climateaction',50),(6,'#climatechange,#climateaction',60);
SELECT SUM(posts.likes) AS total_likes FROM posts WHERE posts.hashtags LIKE '%#climateaction%';
Update the safety score of model 2 from France to 0.95.
CREATE TABLE models_france (model_id INT,name VARCHAR(255),country VARCHAR(255),safety_score FLOAT); INSERT INTO models_france (model_id,name,country,safety_score) VALUES (1,'Model1','France',0.85),(2,'Model2','France',0.92),(3,'Model3','France',0.78),(4,'Model4','France',0.88),(5,'Model5','France',0.90);
UPDATE models_france SET safety_score = 0.95 WHERE model_id = 2 AND country = 'France';
What is the total waste generation by city in the year 2020?
CREATE TABLE WasteGeneration (city VARCHAR(255),year INT,waste_quantity INT); INSERT INTO WasteGeneration (city,year,waste_quantity) VALUES ('CityA',2020,1500),('CityB',2020,1200),('CityC',2020,1800);
SELECT city, SUM(waste_quantity) FROM WasteGeneration WHERE year = 2020 GROUP BY city;
What are the names of forests in Australia and their respective wildlife species, along with their populations?
CREATE TABLE Forests (Fid INT PRIMARY KEY,Name VARCHAR(50),Country VARCHAR(50),Area FLOAT); CREATE TABLE Wildlife (Wid INT PRIMARY KEY,Fid INT,Species VARCHAR(50),Population INT,FOREIGN KEY (Fid) REFERENCES Forests(Fid));
SELECT Forests.Name, Wildlife.Species, Wildlife.Population FROM Forests FULL OUTER JOIN Wildlife ON Forests.Fid = Wildlife.Fid WHERE Forests.Country = 'Australia';
What is the total number of green buildings in Australia and their average energy savings?
CREATE TABLE green_buildings (id INT,building_type VARCHAR(50),energy_savings FLOAT,country VARCHAR(50)); INSERT INTO green_buildings (id,building_type,energy_savings,country) VALUES (1,'Residential',12.5,'Australia'),(2,'Commercial',20.7,'Canada'),(3,'Industrial',30.4,'Japan'),(4,'Public',16.3,'Australia');
SELECT COUNT(*), AVG(energy_savings) FROM green_buildings WHERE country = 'Australia';
Delete the record with the highest water_usage in the month of June 2022 from the residential table.
CREATE TABLE residential (customer_id INT,water_usage FLOAT,usage_date DATE); INSERT INTO residential (customer_id,water_usage,usage_date) VALUES (1,150.5,'2022-06-01'),(2,1200.7,'2022-06-02'),(3,800.4,'2022-06-03');
DELETE FROM residential WHERE customer_id = (SELECT customer_id FROM residential WHERE usage_date BETWEEN '2022-06-01' AND '2022-06-30' ORDER BY water_usage DESC LIMIT 1);
Update the severity of the threat with threat_id 1 to 'medium'
CREATE TABLE threats (threat_id INT,type VARCHAR(255),description VARCHAR(255),severity VARCHAR(255));
UPDATE threats SET severity = 'medium' WHERE threat_id = 1;
What is the total quantity of locally-sourced products sold in each region?
CREATE TABLE Regions (region_id INT,region_name VARCHAR(255)); CREATE TABLE Stores (store_id INT,store_name VARCHAR(255),region_id INT); CREATE TABLE Products (product_id INT,product_name VARCHAR(255),is_local BOOLEAN,product_category VARCHAR(255)); CREATE TABLE Inventory (store_id INT,product_id INT,quantity INT);
SELECT r.region_name, p.product_category, SUM(i.quantity) as total_quantity FROM Inventory i JOIN Stores s ON i.store_id = s.store_id JOIN Products p ON i.product_id = p.product_id JOIN Regions r ON s.region_id = r.region_id WHERE p.is_local = TRUE GROUP BY r.region_name, p.product_category;
What is the distribution of audience demographics for articles about politics, categorized by gender and age?
CREATE TABLE audience (id INT,age INT,gender VARCHAR(10),article_id INT);CREATE TABLE articles (id INT,topic VARCHAR(50)); INSERT INTO audience VALUES (1,45,'Female',1); INSERT INTO articles VALUES (1,'Politics');
SELECT articles.topic, audience.gender, audience.age, COUNT(audience.id) FROM audience INNER JOIN articles ON audience.article_id = articles.id WHERE articles.topic = 'Politics' GROUP BY articles.topic, audience.gender, audience.age;
List all wastewater treatment plants and their corresponding county names.
CREATE TABLE wastewater_plants (id INT,name VARCHAR(255),lat FLOAT,long FLOAT); INSERT INTO wastewater_plants (id,name,lat,long) VALUES (1,'Plant A',34.0534,-118.2453),(2,'Plant B',40.7128,-74.0060); CREATE TABLE counties (id INT,name VARCHAR(255),state VARCHAR(2),lat_min FLOAT,lat_max FLOAT,long_min FLOAT,long_max FLOAT); INSERT INTO counties (id,name,state,lat_min,lat_max,long_min,long_max) VALUES (1,'Los Angeles County','CA',33.7802,34.5454,-118.6094,-117.8008),(2,'New York County','NY',40.6935,40.8065,-74.0134,-73.9003);
SELECT w.name, c.name as county_name FROM wastewater_plants w JOIN counties c ON ST_Intersects(ST_Point(w.long, w.lat), ST_MakeEnvelope(c.long_min, c.lat_min, c.long_max, c.lat_max))
What is the average budget allocated for disability support programs per region, ordered by the highest average budget?
CREATE TABLE Disability_Support_Programs (Region VARCHAR(50),Budget NUMERIC(10,2)); INSERT INTO Disability_Support_Programs VALUES ('Northeast',500000),('Southeast',600000),('Midwest',400000),('Southwest',700000),('West',550000);
SELECT Region, AVG(Budget) as Avg_Budget FROM Disability_Support_Programs GROUP BY Region ORDER BY Avg_Budget DESC;
Find the difference between the maximum and minimum balance for each customer's account, partitioned by account type.
CREATE TABLE accounts (customer_id INT,account_type VARCHAR(20),balance DECIMAL(10,2),transaction_date DATE);
SELECT customer_id, account_type, MAX(balance) - MIN(balance) AS balance_range FROM accounts GROUP BY customer_id, account_type;
What is the salary range for each department?
CREATE TABLE Employees (EmployeeID int,EmployeeName varchar(50),Department varchar(50),Salary float,Gender varchar(10)); INSERT INTO Employees (EmployeeID,EmployeeName,Department,Salary,Gender) VALUES (1,'John Doe','IT',80000,'Male'),(2,'Jane Smith','HR',70000,'Female'),(3,'Mike Johnson','IT',85000,'Male');
SELECT Department, MIN(Salary) as Min_Salary, MAX(Salary) as Max_Salary FROM Employees GROUP BY Department;
What is the average price of lip balms with organic ingredients?
CREATE TABLE Cosmetics (product_id INT,name VARCHAR(50),price DECIMAL(5,2),has_organic_ingredients BOOLEAN,type VARCHAR(50));
SELECT AVG(price) FROM Cosmetics WHERE type = 'Lip Balm' AND has_organic_ingredients = TRUE;
What is the average price of garments in the women's section?
CREATE TABLE garment_info (id INT,section VARCHAR(20),size INT,price DECIMAL(5,2)); INSERT INTO garment_info (id,section,size,price) VALUES (1,'women',8,50.00),(2,'men',10,60.00),(3,'women',12,65.00),(4,'children',6,30.00);
SELECT AVG(price) FROM garment_info WHERE section = 'women';
List the top 3 cultural heritage sites in Tokyo by visitor count.
CREATE TABLE cultural_sites (site_id INT,name TEXT,city TEXT,visitors INT); INSERT INTO cultural_sites (site_id,name,city,visitors) VALUES (1,'Imperial Palace','Tokyo',3000000),(2,'Meiji Shrine','Tokyo',2500000),(3,'Tsukiji Fish Market','Tokyo',2000000);
SELECT name, visitors FROM cultural_sites WHERE city = 'Tokyo' ORDER BY visitors DESC LIMIT 3;
Which climate adaptation projects in South America have the lowest CO2 emission reduction, and when were they initiated?
CREATE TABLE climate_adaptation (project VARCHAR(50),region VARCHAR(50),co2_reduction FLOAT,start_year INT); INSERT INTO climate_adaptation (project,region,co2_reduction,start_year) VALUES ('Water Conservation','South America',500,2014),('Soil Management','South America',300,2015);
SELECT project, region, co2_reduction, start_year FROM climate_adaptation WHERE region = 'South America' ORDER BY co2_reduction ASC;
Delete all shipments older than 30 days
CREATE TABLE Shipments (id INT,warehouse_id INT,shipped_date DATE,packages INT); INSERT INTO Shipments (id,warehouse_id,shipped_date,packages) VALUES (1,1,'2022-01-01',50),(2,1,'2022-01-02',75),(3,2,'2022-01-03',100);
DELETE FROM Shipments WHERE shipped_date < DATE_SUB(NOW(), INTERVAL 30 DAY);
Which basketball players have scored the most points in their careers?
CREATE TABLE players (id INT,name VARCHAR(50),sport VARCHAR(20),points INT); INSERT INTO players (id,name,sport,points) VALUES (1,'LeBron James','Basketball',35000); INSERT INTO players (id,name,sport,points) VALUES (2,'Kevin Durant','Basketball',25000);
SELECT name, points FROM players WHERE sport = 'Basketball' ORDER BY points DESC;
What is the daily water consumption for the state of Texas in the month of January?
CREATE TABLE DailyWaterUsage (Date DATE,State VARCHAR(20),Usage FLOAT); INSERT INTO DailyWaterUsage (Date,State,Usage) VALUES ('2022-01-01','Texas',500),('2022-01-02','Texas',800),('2022-01-03','Texas',900);
SELECT Date, Usage FROM DailyWaterUsage WHERE State = 'Texas' AND Date >= '2022-01-01' AND Date <= '2022-01-31';
What is the maximum number of tickets sold for tennis matches in '2018'?
CREATE TABLE tennis_matches (match_id INT,season INT,tickets_sold INT); INSERT INTO tennis_matches (match_id,season,tickets_sold) VALUES (1,2018,22000),(2,2018,25000),(3,2019,28000);
SELECT MAX(tickets_sold) FROM tennis_matches WHERE season = 2018;
Get the number of unique attendees for each event in the 'Theater' category.
CREATE TABLE Attendance (attendance_id INT PRIMARY KEY,event_id INT,attendee_id INT,attendee_age INT);
SELECT event_id, COUNT(DISTINCT attendee_id) FROM Attendance JOIN Events ON Attendance.event_id = Events.event_id WHERE Events.category = 'Theater' GROUP BY event_id;
What is the total budget allocated to public healthcare services in the West region in 2021?
CREATE TABLE Budget (Year INT,Service VARCHAR(255),Region VARCHAR(255),Amount DECIMAL(10,2)); INSERT INTO Budget (Year,Service,Region,Amount) VALUES (2021,'Healthcare','West',1500000.00),(2021,'Education','West',1200000.00),(2021,'Transportation','West',900000.00),(2021,'Utilities','West',1300000.00);
SELECT SUM(Amount) FROM Budget WHERE Year = 2021 AND Region = 'West' AND Service = 'Healthcare';
Insert records for new employees who have completed Industry 4.0 training.
CREATE TABLE employee_details (employee_id INT,name VARCHAR(50),country VARCHAR(50),training_date DATE);
INSERT INTO employee_details (employee_id, name, country, training_date) VALUES (104, 'Svetlana', 'Russia', '2021-11-01'), (105, 'Javier', 'Mexico', '2021-12-10'), (106, 'Minh', 'Vietnam', '2021-12-25');
What is the average density of Arctic Fox in Svalbard?
CREATE TABLE species_distribution (id INT,species VARCHAR(255),location VARCHAR(255),density INT); INSERT INTO species_distribution (id,species,location,density) VALUES (1,'Polar Bear','North Pole',10); INSERT INTO species_distribution (id,species,location,density) VALUES (2,'Arctic Fox','Svalbard',5);
SELECT species, location, AVG(density) FROM species_distribution WHERE species = 'Arctic Fox' AND location = 'Svalbard' GROUP BY species, location;
What is the total number of unique users who engaged with posts containing '#music' hashtag in 'EU' region?
CREATE TABLE comments (id INT,post_id INT,user_id INT,text VARCHAR(100)); CREATE TABLE users (id INT,region VARCHAR(10)); INSERT INTO comments (id,post_id,user_id) VALUES (1,1,1),(2,2,2),(3,3,3); INSERT INTO users (id,region) VALUES (1,'EU'),(2,'EU'),(3,'APAC'); INSERT INTO hashtags (id,post_id,tag) VALUES (1,1,'#music'),(2,2,'#music');
SELECT COUNT(DISTINCT comments.user_id) FROM comments JOIN hashtags ON hashtags.post_id = comments.post_id JOIN users ON comments.user_id = users.id WHERE users.region = 'EU' AND hashtags.tag = '#music';
Calculate the total water consumption for the summer months (June-August) for the city of Boston in the year 2021.
CREATE TABLE water_consumption (city VARCHAR(50),consumption FLOAT,month INT,year INT); INSERT INTO water_consumption (city,consumption,month,year) VALUES ('Boston',180.2,6,2021),('Boston',190.5,7,2021),('Boston',200.8,8,2021);
SELECT SUM(consumption) FROM water_consumption WHERE city = 'Boston' AND year = 2021 AND month BETWEEN 6 AND 8;
What is the maximum funding amount for biotech startups in California?
CREATE SCHEMA if not exists biotech; CREATE TABLE if not exists biotech.startups (id INT,name TEXT,location TEXT,funding FLOAT); INSERT INTO biotech.startups (id,name,location,funding) VALUES (1,'StartupA','Texas',5000000.00); INSERT INTO biotech.startups (id,name,location,funding) VALUES (2,'StartupB','California',7000000.00); INSERT INTO biotech.startups (id,name,location,funding) VALUES (3,'StartupC','Texas',3000000.00); INSERT INTO biotech.startups (id,name,location,funding) VALUES (4,'StartupD','California',8000000.00);
SELECT MAX(funding) FROM biotech.startups WHERE location = 'California';
What is the total CO2 emission from waste management in Australia?
CREATE TABLE AustralianWasteData (waste_type VARCHAR(50),CO2_emission_tonnes FLOAT); INSERT INTO AustralianWasteData (waste_type,CO2_emission_tonnes) VALUES ('Municipal Solid Waste',12.3),('Industrial Waste',45.8),('Hazardous Waste',3.6);
SELECT SUM(CO2_emission_tonnes) FROM AustralianWasteData;
What is the total amount of Shariah-compliant finance transactions conducted by each customer?
CREATE TABLE shariah_transactions (customer_id INT,transaction_date DATE,transaction_amount DECIMAL(10,2));
SELECT customer_id, SUM(transaction_amount) FROM shariah_transactions WHERE transaction_date >= '2022-01-01' GROUP BY customer_id;
Identify the unique countries with donors who have donated more than $10,000 in total?
CREATE TABLE Donors (DonorID INT,DonorName TEXT,Country TEXT); CREATE TABLE Donations (DonationID INT,DonorID INT,DonationAmount DECIMAL(10,2)); INSERT INTO Donors (DonorID,DonorName,Country) VALUES (1,'Jane Smith','USA'),(2,'ABC NGO','India'); INSERT INTO Donations (DonationID,DonorID,DonationAmount) VALUES (1,1,8000.00),(2,1,3000.00),(3,2,12000.00);
SELECT Country FROM Donors d JOIN (SELECT DonorID, SUM(DonationAmount) AS TotalDonationAmount FROM Donations GROUP BY DonorID HAVING TotalDonationAmount > 10000) sub ON d.DonorID = sub.DonorID;
What is the percentage of broadband customers who have upgraded to the latest plan in the last year?
CREATE TABLE broadband_plans (customer_id INT,plan_upgraded BOOLEAN);
SELECT 100.0 * COUNT(*) / (SELECT COUNT(*) FROM broadband_plans) as percentage FROM broadband_plans WHERE plan_upgraded = TRUE;
What is the name and capacity of each sports stadium in the state of Florida?
CREATE TABLE states (id INT,name VARCHAR(255)); CREATE TABLE stadiums (id INT,state_id INT,name VARCHAR(255),capacity INT);
SELECT name, capacity FROM stadiums WHERE state_id = (SELECT id FROM states WHERE name = 'Florida');
List all crime types and their respective total crime counts across all districts.
CREATE TABLE crimes (crime_id INT,district_id INT,crime_type TEXT,crime_count INT);
SELECT c.crime_type, SUM(c.crime_count) FROM crimes c GROUP BY c.crime_type;
What is the total revenue generated by each chef?
CREATE TABLE chefs (chef VARCHAR(255),menu VARCHAR(255),price DECIMAL(10,2),sales INT); INSERT INTO chefs VALUES ('Mario','Bruschetta',7.99,350); INSERT INTO chefs VALUES ('Luigi','Lasagna',12.99,200);
SELECT chef, SUM(price * sales) AS total_revenue FROM chefs GROUP BY chef;
What is the total quantity of textiles transported by the Kota Pertama?
CREATE TABLE Vessels (VesselID INT,VesselName VARCHAR(100),VesselType VARCHAR(100),PortID INT); INSERT INTO Vessels (VesselID,VesselName,VesselType,PortID) VALUES (1,'Kota Pertama','Container Ship',1); CREATE TABLE Cargo (CargoID INT,CargoName VARCHAR(100),Quantity INT,VesselID INT); INSERT INTO Cargo (CargoID,CargoName,Quantity,VesselID) VALUES (1,'Textiles',8000,1); INSERT INTO Cargo (CargoID,CargoName,Quantity,VesselID) VALUES (2,'Machinery',6000,2);
SELECT SUM(Cargo.Quantity) FROM Cargo WHERE Cargo.VesselID = 1 AND Cargo.CargoName = 'Textiles';
What are the consumer preference scores for product 104 in the Americas?
CREATE TABLE consumer_preferences (id INT,consumer_id INT,product_id INT,preference_score INT,country VARCHAR(50)); INSERT INTO consumer_preferences (id,consumer_id,product_id,preference_score,country) VALUES (1,1,101,8,'Asia-Pacific'),(2,2,102,9,'Asia-Pacific'),(3,3,101,7,'Asia-Pacific'),(4,4,103,10,'Asia-Pacific'),(5,5,102,8,'Asia-Pacific'),(6,6,104,9,'Americas'),(7,7,105,8,'Americas');
SELECT product_id, preference_score, country FROM consumer_preferences WHERE product_id = 104 AND country LIKE 'Americas';
Find menu items with the lowest price decrease since last month.
CREATE TABLE Dishes (DishID INT,Name TEXT,Price FLOAT,LastUpdated DATE);
SELECT Name, Price FROM Dishes WHERE LastUpdated IN (SELECT MAX(LastUpdated) FROM Dishes) INTERSECT SELECT Name, Price FROM Dishes WHERE LastUpdated < DATEADD(month, -1, GETDATE()) ORDER BY Price ASC;
Which defense projects had a budget increase from 2019 to 2020?
CREATE TABLE defense_projects (id INT,project VARCHAR(50),year INT,budget FLOAT); INSERT INTO defense_projects (id,project,year,budget) VALUES (1,'Project A',2019,1000000),(2,'Project A',2020,1200000),(3,'Project B',2019,1500000),(4,'Project B',2020,1400000);
SELECT project, (budget_2020 - budget_2019) as budget_increase FROM (SELECT project, budget as budget_2019, LEAD(budget) OVER (PARTITION BY project ORDER BY year) as budget_2020 FROM defense_projects) as subquery WHERE budget_2020 IS NOT NULL AND budget_2019 IS NOT NULL;
How many diverse artists from underrepresented communities were featured in our programs in the last two years?
CREATE TABLE artists (id INT,year INT,community_represented VARCHAR(50)); INSERT INTO artists (id,year,community_represented) VALUES (1,2021,'Indigenous'),(2,2021,'Latinx'),(3,2021,'Asian'),(4,2022,'Black'),(5,2022,'LGBTQ+'),(6,2022,'Disability');
SELECT COUNT(DISTINCT id) FROM artists WHERE year BETWEEN 2021 AND 2022 AND community_represented IN ('Indigenous', 'Latinx', 'Asian', 'Black', 'LGBTQ+', 'Disability');
Find the number of unique instructors who have taught open pedagogy courses in 'Coastal District V' and 'Island District U'.
CREATE TABLE CoastalDistrictVCourses (courseID INT,instructorName VARCHAR(50),courseType VARCHAR(50)); INSERT INTO CoastalDistrictVCourses (courseID,instructorName,courseType) VALUES (1,'Amina Ahmed','open pedagogy'),(2,'Brian Chen','traditional'); CREATE TABLE IslandDistrictUCourses (courseID INT,instructorName VARCHAR(50),courseType VARCHAR(50)); INSERT INTO IslandDistrictUCourses (courseID,instructorName,courseType) VALUES (3,'Fatima Adebayo','open pedagogy'),(4,'Giovanni Lopez','traditional');
SELECT COUNT(DISTINCT instructorName) FROM (SELECT instructorName FROM CoastalDistrictVCourses WHERE courseType = 'open pedagogy' UNION ALL SELECT instructorName FROM IslandDistrictUCourses WHERE courseType = 'open pedagogy') AS derived;
What are the labor statistics for female construction workers over the age of 30 in the last year?
CREATE TABLE LaborStatistics (StatID INT,Gender TEXT,Age INT,JobCategory TEXT,HourlyWage NUMERIC,DateRecorded DATE);
SELECT * FROM LaborStatistics WHERE Gender = 'Female' AND Age > 30 AND DateRecorded >= DATEADD(year, -1, GETDATE());
Add a new community health worker to the table
CREATE TABLE community_health_workers (id INT PRIMARY KEY,worker_name VARCHAR(50),language_spoken VARCHAR(20),years_of_experience INT);
INSERT INTO community_health_workers (id, worker_name, language_spoken, years_of_experience) VALUES (1, 'Abena', 'Twi', 7);
How many products are fair trade certified for each country of origin?
CREATE TABLE products (product_id INT,product_name TEXT,country_of_origin TEXT,fair_trade_certified BOOLEAN); INSERT INTO products (product_id,product_name,country_of_origin,fair_trade_certified) VALUES (1,'Organic Cotton Shirt','India',TRUE),(2,'Recycled Polyester Jacket','China',FALSE),(3,'Hemp T-Shirt','France',TRUE);
SELECT country_of_origin, SUM(fair_trade_certified) as fair_trade_count FROM products GROUP BY country_of_origin;
What is the average water temperature in Canadian fish farms in July?
CREATE TABLE canadian_farms (id INT,name TEXT,country TEXT,latitude DECIMAL(9,6),longitude DECIMAL(9,6)); INSERT INTO canadian_farms (id,name,country,latitude,longitude) VALUES (1,'Farm G','Canada',52.123456,-114.123456),(2,'Farm H','Canada',53.123456,-115.123456); CREATE TABLE water_temperature (id INT,farm_id INT,date DATE,temperature DECIMAL(4,2)); INSERT INTO water_temperature (id,farm_id,date,temperature) VALUES (1,1,'2022-07-01',15.5),(2,1,'2022-07-02',16.0),(3,2,'2022-07-01',14.0),(4,2,'2022-07-02',14.5);
SELECT AVG(temperature) FROM water_temperature wt JOIN canadian_farms cf ON wt.farm_id = cf.id WHERE cf.country = 'Canada' AND MONTH(wt.date) = 7;
What is the total amount of socially responsible loans issued by financial institutions in the United States?
CREATE TABLE financial_institutions (institution_id INT,institution_name TEXT,country TEXT); INSERT INTO financial_institutions (institution_id,institution_name,country) VALUES (1,'GreenBank','United States'),(2,'FairFinance','United Kingdom'); CREATE TABLE loans (loan_id INT,institution_id INT,amount FLOAT,loan_type TEXT); INSERT INTO loans (loan_id,institution_id,amount,loan_type) VALUES (1,1,5000,'socially responsible'),(2,1,7000,'conventional'),(3,2,4000,'socially responsible');
SELECT SUM(amount) FROM loans WHERE loan_type = 'socially responsible' AND country = 'United States';
What is the average CO2 emission of diesel vehicles in 'suburban' areas?
CREATE TABLE public.emissions_by_fuel_type(id serial PRIMARY KEY,vehicle_type varchar(255),location varchar(255),fuel_type varchar(255),co2_emission numeric);
SELECT AVG(co2_emission) FROM public.emissions_by_fuel_type WHERE vehicle_type = 'Diesel' AND location = 'Suburban';
What is the maximum salary earned by a construction worker in New York?
CREATE TABLE construction_workers (id INT,name VARCHAR(50),salary DECIMAL(10,2),state VARCHAR(2)); INSERT INTO construction_workers (id,name,salary,state) VALUES (1,'John Doe',80000,'New York'); INSERT INTO construction_workers (id,name,salary,state) VALUES (2,'Jane Smith',85000,'New York');
SELECT MAX(salary) FROM construction_workers WHERE state = 'New York';
What is the total amount donated by each organization, for organizations with at least one donation above $1000?
CREATE TABLE donors (id INT,name TEXT,organization TEXT);CREATE TABLE donations (id INT,donor_id INT,amount DECIMAL(10,2)); INSERT INTO donors (id,name,organization) VALUES (1,'Donor A','Organization 1'),(2,'Donor B','Organization 2'),(3,'Donor C','Organization 3'); INSERT INTO donations (id,donor_id,amount) VALUES (1,1,500.00),(2,1,1500.00),(3,2,300.00),(4,3,750.00);
SELECT donors.organization, SUM(donations.amount) FROM donors INNER JOIN donations ON donors.id = donations.donor_id WHERE donations.amount > 1000 GROUP BY donors.organization;
Update the "Population" column in the "CoralReefs" table, setting the value to 25000 for all records where "Location" is "Pacific Ocean"
CREATE TABLE CoralReefs (Location VARCHAR(20),Population INT);
UPDATE CoralReefs SET Population = 25000 WHERE Location = 'Pacific Ocean';
Which materials were landfilled the least in the city of Denver in 2016?
CREATE TABLE landfilled_materials (city VARCHAR(20),year INT,material VARCHAR(20),landfilled_quantity INT); INSERT INTO landfilled_materials (city,year,material,landfilled_quantity) VALUES ('Denver',2016,'Plastic',500),('Denver',2016,'Glass',700),('Denver',2016,'Paper',800),('Denver',2016,'Metal',400);
SELECT MIN(landfilled_quantity) AS min_landfilled, material FROM landfilled_materials WHERE city = 'Denver' AND year = 2016 GROUP BY material;
What is the minimum age of employees in the "mining_operations" table, broken down by department?
CREATE TABLE mining_operations (id INT,name VARCHAR(50),department VARCHAR(50),age INT);
SELECT department, MIN(age) FROM mining_operations GROUP BY department;
Delete the record for the customer with ID 3 and update their data usage to 0 in the 'subscribers' table.
CREATE TABLE subscribers (id INT,name VARCHAR(50),data_usage DECIMAL(10,2),region VARCHAR(10)); INSERT INTO subscribers (id,name,data_usage,region) VALUES (1,'John Doe',30.5,'west'),(2,'Jane Smith',45.3,'west'),(3,'Alice Johnson',22.8,'west'),(4,'Bob Brown',51.9,'west'),(5,'Charlie Green',60.2,'west');
DELETE FROM subscribers WHERE id = 3; UPDATE subscribers SET data_usage = 0 WHERE id = 3;
Calculate the total number of female and male farmers in the 'agriculture_innovation' table
CREATE TABLE agriculture_innovation (farmer_id INT,farmer_name VARCHAR(50),gender VARCHAR(10),age INT,innovation_id INT);
SELECT SUM(CASE WHEN gender = 'Female' THEN 1 ELSE 0 END) AS total_female, SUM(CASE WHEN gender = 'Male' THEN 1 ELSE 0 END) AS total_male FROM agriculture_innovation;
How many farmers are there in each country?
CREATE TABLE farmer (id INT PRIMARY KEY,name VARCHAR(50),country_id INT); CREATE TABLE country (id INT PRIMARY KEY,name VARCHAR(50)); INSERT INTO country (id,name) VALUES (1,'Brazil'),(2,'Colombia'); INSERT INTO farmer (id,name,country_id) VALUES (1,'Joao',1),(2,'Maria',1),(3,'Carlos',2);
SELECT co.name, COUNT(f.id) FROM farmer f INNER JOIN country co ON f.country_id = co.id GROUP BY co.name;
What is the total number of crimes committed in 'Chicago' in the month of 'January' for each year?
CREATE TABLE crimes (id INT,city VARCHAR(20),month VARCHAR(10),year INT,crimes INT);
SELECT year, SUM(crimes) FROM crimes WHERE city = 'Chicago' AND month = 'January' GROUP BY year;
Identify the top 2 sectors with the highest increase in CO2 emissions between 2019 and 2020 from the 'greenhouse_gas_emissions' table.
CREATE TABLE greenhouse_gas_emissions (sector VARCHAR(255),co2_emissions DECIMAL(10,2),year INT); INSERT INTO greenhouse_gas_emissions (sector,co2_emissions,year) VALUES ('Energy',32000.0,2019),('Industry',15000.0,2019),('Transport',14000.0,2019),('Residential',8000.0,2019),('Commercial',6000.0,2019),('Agriculture',5000.0,2019),('Energy',37000.0,2020),('Industry',18000.0,2020),('Transport',16000.0,2020),('Residential',9000.0,2020),('Commercial',7000.0,2020),('Agriculture',6000.0,2020);
SELECT sector, (co2_emissions - LAG(co2_emissions) OVER (ORDER BY year)) as co2_emissions_increase FROM greenhouse_gas_emissions WHERE year IN (2019, 2020) ORDER BY co2_emissions_increase DESC LIMIT 2;
What is the maximum speed of the fastest autonomous vehicle?
CREATE TABLE AutonomousVehicles (Id INT,Name VARCHAR(100),MaxSpeed FLOAT); INSERT INTO AutonomousVehicles (Id,Name,MaxSpeed) VALUES (1,'Apollo',240),(2,'Buddy',150),(3,'RoboCar',180);
SELECT MAX(MaxSpeed) FROM AutonomousVehicles
What is the average salary of employees in the 'manufacturing' department?
CREATE TABLE employees (id INT,name VARCHAR(50),department VARCHAR(50),salary FLOAT); INSERT INTO employees (id,name,department,salary) VALUES (1,'John Doe','manufacturing',60000),(2,'Jane Smith','marketing',70000);
SELECT AVG(salary) FROM employees WHERE department = 'manufacturing';
What is the maximum altitude reached by SpaceX's Falcon Heavy?
CREATE TABLE RocketAltitudes (id INT,rocket_name VARCHAR(100),company VARCHAR(100),max_altitude FLOAT); INSERT INTO RocketAltitudes (id,rocket_name,company,max_altitude) VALUES (1,'Falcon Heavy','SpaceX',12300000); INSERT INTO RocketAltitudes (id,rocket_name,company,max_altitude) VALUES (2,'Falcon 9','SpaceX',8000000);
SELECT MAX(max_altitude) FROM RocketAltitudes WHERE rocket_name = 'Falcon Heavy';
What is the average account balance for clients who have improved their financial wellbeing in the last 3 months?
CREATE TABLE clients (client_id INT,financial_wellbeing_score INT,last_updated DATE); INSERT INTO clients (client_id,financial_wellbeing_score,last_updated) VALUES (1,5,'2022-03-01'),(2,7,'2022-02-15'),(3,6,'2022-01-01'),(4,8,'2022-04-01'),(5,4,'2022-02-01'); CREATE TABLE accounts (account_id INT,client_id INT,balance DECIMAL(10,2)); INSERT INTO accounts (account_id,client_id,balance) VALUES (1001,1,5000),(1002,1,7000),(1003,2,3000),(1004,3,6000),(1005,3,4000),(1006,4,9000),(1007,5,2000);
SELECT AVG(accounts.balance) FROM accounts INNER JOIN clients ON accounts.client_id = clients.client_id WHERE clients.last_updated > DATE_SUB(NOW(), INTERVAL 3 MONTH) AND clients.client_id IN (SELECT client_id FROM clients GROUP BY client_id HAVING MAX(financial_wellbeing_score) > MIN(financial_wellbeing_score));
List the top 5 volunteers with the most volunteer hours in the Youth Empowerment Program.
CREATE TABLE Volunteers (VolunteerID INT,Name TEXT,Age INT); CREATE TABLE Volunteer_Hours (VolunteerID INT,Program TEXT,Hours DECIMAL);
SELECT V.Name, SUM(VH.Hours) as TotalHours FROM Volunteers V INNER JOIN Volunteer_Hours VH ON V.VolunteerID = VH.VolunteerID WHERE VH.Program = 'Youth Empowerment Program' GROUP BY V.VolunteerID, V.Name ORDER BY TotalHours DESC LIMIT 5;
Show the top 3 digital divide issues by number of reported cases, for Africa only.
CREATE TABLE digital_divide (id INT,issue VARCHAR(50),country VARCHAR(2),cases INT); INSERT INTO digital_divide (id,issue,country,cases) VALUES (1,'Lack of infrastructure','NG',100),(2,'High cost of internet','EG',80),(3,'Lack of digital literacy','ZA',70),(4,'Lack of infrastructure','ET',90),(5,'High cost of internet','GH',75);
SELECT issue, cases FROM digital_divide WHERE country = 'NG' OR country = 'EG' OR country = 'ZA' OR country = 'ET' OR country = 'GH' GROUP BY issue ORDER BY SUM(cases) DESC LIMIT 3;
What is the maximum budget, in US dollars, for rural infrastructure projects in India that were completed in 2018?
CREATE TABLE rural_infrastructure_projects (id INT,country VARCHAR(255),budget_usd FLOAT,completion_date DATE); INSERT INTO rural_infrastructure_projects (id,country,budget_usd,completion_date) VALUES (1,'India',250000.0,'2018-01-10'),(2,'India',320000.0,'2019-05-15'),(3,'Bangladesh',150000.0,'2017-12-22');
SELECT MAX(budget_usd) FROM rural_infrastructure_projects WHERE country = 'India' AND completion_date <= '2018-12-31';
What is the total playtime for players who have played the game "Cybernetic Mayhem" and have more than 50 hours of playtime?
CREATE TABLE Players (PlayerID INT,Playtime INT,GameName VARCHAR(20)); INSERT INTO Players (PlayerID,Playtime,GameName) VALUES (1,65,'Cybernetic Mayhem'),(2,35,'Quantum Rush'),(3,70,'Cybernetic Mayhem');
SELECT SUM(Playtime) FROM Players WHERE GameName = 'Cybernetic Mayhem' AND Playtime > 50;
Delete cargo records that have been at the destination for over a year
CREATE SCHEMA if not exists ocean_shipping;CREATE TABLE if not exists ocean_shipping.cargo (id INT,cargo_type VARCHAR(255),arrived_at DATE);
DELETE FROM ocean_shipping.cargo WHERE arrived_at < DATE_SUB(CURRENT_DATE, INTERVAL 365 DAY);
What is the minimum age of patients diagnosed with diabetes in urban areas?
CREATE TABLE patients (id INT,age INT,diagnosis VARCHAR(20),location VARCHAR(20)); INSERT INTO patients (id,age,diagnosis,location) VALUES (1,50,'diabetes','rural'),(2,45,'diabetes','rural'),(3,60,'not diabetes','urban');
SELECT MIN(age) FROM patients WHERE diagnosis = 'diabetes' AND location = 'urban';
Which countries have launched military satellites most recently?
CREATE TABLE satellites (id INT,name VARCHAR(50),type VARCHAR(50),country VARCHAR(50),launch_date DATE); CREATE VIEW latest_satellites AS SELECT * FROM satellites WHERE launch_date IN (SELECT MAX(launch_date) FROM satellites GROUP BY country);
SELECT country FROM latest_satellites WHERE type = 'Military';
Calculate the monthly energy efficiency savings for a given customer in a specific region.
CREATE TABLE customer_data (customer_id INT,region VARCHAR(50),energy_usage_prev_month FLOAT,energy_usage_current_month FLOAT,primary key (customer_id)); INSERT INTO customer_data (customer_id,region,energy_usage_prev_month,energy_usage_current_month) VALUES (1,'California',1200,1000),(2,'California',1500,1300),(3,'California',1800,1600),(4,'Nevada',2000,1800),(5,'Nevada',2500,2300),(6,'Nevada',3000,2800);
SELECT customer_id, region, energy_usage_prev_month, energy_usage_current_month, energy_usage_prev_month - energy_usage_current_month as savings FROM customer_data WHERE region = 'California' AND EXTRACT(MONTH FROM energy_usage_prev_month) = EXTRACT(MONTH FROM energy_usage_current_month)
Rank vessels by total cargo transported in descending order
CREATE TABLE vessels (vessel_id INT,name VARCHAR(100),type VARCHAR(50),total_cargo INT); INSERT INTO vessels VALUES (1,'Cargo Ship 1','Non-Hazardous',5000),(2,'Tanker 1','Hazardous',3000),(3,'Tanker 2','Hazardous',4000),(4,'Cargo Ship 2','Non-Hazardous',5500),(5,'Cargo Ship 3','Non-Hazardous',4500);
ROW_NUMBER() OVER (ORDER BY total_cargo DESC) as rank
Delete all records from the "waste" table where the "waste_type" is "Plastic"
CREATE TABLE waste (id INT PRIMARY KEY,name VARCHAR(100),waste_type VARCHAR(50)); INSERT INTO waste (id,name,waste_type) VALUES (1,'wasteA','Plastic'),(2,'wasteB','Metal');
DELETE FROM waste WHERE waste_type = 'Plastic';
Which funding sources supported events with the highest total attendance?
CREATE TABLE Events (EventID INT,Title VARCHAR(50),TotalAttendance INT); INSERT INTO Events (EventID,Title,TotalAttendance) VALUES (1,'Art in the Park',500),(2,'Music under the Stars',350); CREATE TABLE Funding (FundingID INT,Source VARCHAR(50),EventID INT); INSERT INTO Funding (FundingID,Source,EventID) VALUES (1,'City Grant',1),(2,'Private Donor',2);
SELECT Funding.Source, Events.Title, Events.TotalAttendance FROM Funding INNER JOIN Events ON Funding.EventID = Events.EventID ORDER BY Events.TotalAttendance DESC;
Display the names and oceans of marine species with an index greater than 50 in their respective pollution table
CREATE TABLE pollution_atlantic (id INT,species VARCHAR(255),index INT); INSERT INTO pollution_atlantic (id,species,index) VALUES (1,'Dolphin',60); INSERT INTO pollution_atlantic (id,species,index) VALUES (2,'Tuna',55); CREATE TABLE pollution_pacific (id INT,species VARCHAR(255),index INT); INSERT INTO pollution_pacific (id,species,index) VALUES (1,'Shark',45); INSERT INTO pollution_pacific (id,species,index) VALUES (2,'Jellyfish',80);
SELECT species, ocean FROM (SELECT 'Atlantic' as ocean, species, index FROM pollution_atlantic WHERE index > 50 UNION SELECT 'Pacific' as ocean, species, index FROM pollution_pacific WHERE index > 50) as combined_pollution WHERE index > 50;
What is the number of items sold in each country for a specific designer?
CREATE TABLE DesignerSales (id INT,designer VARCHAR(20),country VARCHAR(10),quantity INT); INSERT INTO DesignerSales (id,designer,country,quantity) VALUES (1,'Riccardo Tisci','Italy',500),(2,'Pierpaolo Piccioli','France',600);
SELECT country, SUM(quantity) FROM DesignerSales WHERE designer = 'Riccardo Tisci' GROUP BY country;
What is the total flight time for astronauts from NASA?
CREATE TABLE Astronauts (id INT,name VARCHAR(255),gender VARCHAR(255),agency VARCHAR(255),mission VARCHAR(255),role VARCHAR(255),flight_hours DECIMAL(5,2)); INSERT INTO Astronauts (id,name,gender,agency,mission,role,flight_hours) VALUES (1,'Neil Armstrong','Male','NASA','Apollo 11','Commander',21.5); INSERT INTO Astronauts (id,name,gender,agency,mission,role,flight_hours) VALUES (2,'Buzz Aldrin','Male','NASA','Apollo 11','Lunar Module Pilot',19.0);
SELECT agency, SUM(flight_hours) as total_flight_hours FROM Astronauts WHERE agency = 'NASA' GROUP BY agency;
What is the total number of autonomous driving research papers published in 2021 and 2022?
CREATE TABLE ResearchPapers (id INT,title VARCHAR(255),publication_year INT,autonomous_driving BOOLEAN); INSERT INTO ResearchPapers (id,title,publication_year,autonomous_driving) VALUES (1,'Paper A',2019,FALSE); INSERT INTO ResearchPapers (id,title,publication_year,autonomous_driving) VALUES (2,'Paper B',2021,TRUE);
SELECT COUNT(*) FROM ResearchPapers WHERE publication_year IN (2021, 2022) AND autonomous_driving = TRUE;
Which ethical fashion brands have the most positive consumer sentiment in social media?
CREATE TABLE Brands (id INT,brand VARCHAR,sentiment FLOAT); CREATE TABLE BrandSentimentData (brand VARCHAR,sentiment_score INT);
SELECT b.brand, AVG(b.sentiment) as average_sentiment FROM Brands b JOIN BrandSentimentData bsd ON b.brand = bsd.brand GROUP BY b.brand ORDER BY average_sentiment DESC LIMIT 5;
List all teachers who have not taken any professional development courses in the past year, along with their IDs, from the 'teacher_trainings' table.
CREATE TABLE teacher_trainings (teacher_id INT,course_id INT,training_date DATE);
SELECT teacher_id FROM teacher_trainings WHERE teacher_id NOT IN (SELECT teacher_id FROM teacher_trainings WHERE training_date >= DATE(NOW()) - INTERVAL 1 YEAR);
Which countries source the most organic ingredients for cosmetic products, and which brands are associated with those countries?
CREATE TABLE ingredient_sourcing (ingredient_id INT,product_id INT,country_name VARCHAR(50),organic_sourced BOOLEAN); INSERT INTO ingredient_sourcing (ingredient_id,product_id,country_name,organic_sourced) VALUES (1,1,'France',true),(2,1,'Italy',false),(3,2,'USA',true),(4,2,'Mexico',true),(5,3,'Canada',false),(6,3,'UK',false),(7,4,'Brazil',true),(8,4,'Argentina',true),(9,5,'Australia',false),(10,5,'New Zealand',true),(11,6,'Spain',true),(12,6,'Germany',true); CREATE TABLE brand_info (brand_name VARCHAR(50),country_of_origin VARCHAR(50)); INSERT INTO brand_info (brand_name,country_of_origin) VALUES ('Loreal','France'),('Maybelline','USA'),('Estee Lauder','USA'),('Urban Decay','USA'),('MAC','Canada'),('Clinique','USA');
SELECT i.country_name, b.brand_name FROM ingredient_sourcing i INNER JOIN brand_info b ON i.country_name = b.country_of_origin WHERE i.organic_sourced = true GROUP BY i.country_name, b.brand_name HAVING COUNT(i.ingredient_id) >= 2;
What is the number of donations and investments for each cause, separated by donations and investments, in the 'cause_donations' and 'cause_investments' tables, respectively, ordered by the number of contributions in descending order?
CREATE TABLE cause_donations (cause_id INT,cause_name TEXT,num_donations INT); CREATE TABLE cause_investments (cause_id INT,cause_name TEXT,num_investments INT);
SELECT cause_name, COUNT(num_donations) as total_donations FROM cause_donations GROUP BY cause_name UNION ALL SELECT cause_name, COUNT(num_investments) as total_investments FROM cause_investments GROUP BY cause_name ORDER BY total_donations DESC;
What is the average duration of dance performances in Paris in the last 3 years?
CREATE TABLE performance_durations (id INT,city VARCHAR(20),year INT,type VARCHAR(10),duration INT); INSERT INTO performance_durations (id,city,year,type,duration) VALUES (1,'Tokyo',2017,'dance',60),(2,'Tokyo',2018,'dance',90),(3,'Paris',2018,'dance',120),(4,'London',2018,'dance',75),(5,'New York',2018,'dance',105),(6,'Paris',2019,'dance',135),(7,'Paris',2020,'dance',150);
SELECT AVG(duration) FROM performance_durations WHERE city = 'Paris' AND type = 'dance' AND year BETWEEN 2018 AND 2020;
Insert a new record into the algorithmic_fairness table with algorithm set to 'SVM', bias_level set to 'low', risk_score set to 5, and last_updated set to the current timestamp
CREATE TABLE algorithmic_fairness (id INTEGER,algorithm TEXT,bias_level TEXT,risk_score INTEGER,last_updated TIMESTAMP);
INSERT INTO algorithmic_fairness (algorithm, bias_level, risk_score, last_updated) VALUES ('SVM', 'low', 5, CURRENT_TIMESTAMP);
What is the number of teachers who have participated in professional development programs by subject area?
CREATE TABLE teachers (teacher_id INT,teacher_name VARCHAR(50),subject_area VARCHAR(50)); CREATE TABLE professional_development (pd_id INT,teacher_id INT,program_name VARCHAR(50),topic VARCHAR(50)); INSERT INTO teachers (teacher_id,teacher_name,subject_area) VALUES (1,'John Doe','Math'),(2,'Jane Smith','Science'),(3,'Mike Johnson','English'); INSERT INTO professional_development (pd_id,teacher_id,program_name,topic) VALUES (1,1,'Professional Development Workshop','Professional Development'),(2,2,'Diversity Training','Diversity'),(3,3,'Open Pedagogy Workshop','Open Pedagogy');
SELECT teachers.subject_area, COUNT(DISTINCT teachers.teacher_id) as num_teachers FROM teachers INNER JOIN professional_development ON teachers.teacher_id = professional_development.teacher_id GROUP BY teachers.subject_area;
What is the average response time for emergency medical incidents in urban and rural areas?
CREATE TABLE emergency_responses (id INT,location TEXT,incident_type TEXT,response_time INT); INSERT INTO emergency_responses (id,location,incident_type,response_time) VALUES (1,'Urban','Medical',6),(2,'Urban','Medical',8),(3,'Rural','Medical',10),(4,'Rural','Medical',12),(5,'Urban','Fire',7),(6,'Urban','Fire',9),(7,'Rural','Fire',8),(8,'Rural','Fire',11);
SELECT location, AVG(response_time) AS avg_response_time FROM emergency_responses WHERE incident_type = 'Medical' GROUP BY location;
list all timber production sites and their annual production
CREATE SCHEMA forestry; CREATE TABLE sites (id INT,name VARCHAR(50),annual_production INT); INSERT INTO sites (id,name,annual_production) VALUES (1,'site1',1200),(2,'site2',1800),(3,'site3',2000);
SELECT name, annual_production FROM forestry.sites;
What is the total oil and gas production for each rig in H1 2021?
CREATE TABLE rig_production_figures (rig_id INT,production_date DATE,oil_production FLOAT,gas_production FLOAT);
SELECT rig_id, SUM(oil_production) as total_oil_production, SUM(gas_production) as total_gas_production FROM rig_production_figures WHERE production_date BETWEEN '2021-01-01' AND '2021-06-30' GROUP BY rig_id;
What is the average time between failures for each bus model?
CREATE TABLE bus (bus_id INT,bus_model TEXT,time_between_failures DECIMAL); INSERT INTO bus (bus_id,bus_model,time_between_failures) VALUES (1,'BusModel1',100.00),(2,'BusModel2',150.00),(3,'BusModel3',200.00),(4,'BusModel4',50.00),(5,'BusModel5',250.00);
SELECT bus_model, time_between_failures FROM bus ORDER BY time_between_failures ASC;
Count the number of unique authors who have published articles in the 'tech' section.
CREATE TABLE articles (id INT,author VARCHAR(255),title VARCHAR(255),section VARCHAR(255),date DATE);
SELECT COUNT(DISTINCT author) FROM articles WHERE section='tech';
Which countries have the most freight forwarding activity, and what are the average costs for each country?
CREATE TABLE Forwarding (id INT,country TEXT,mode TEXT,cost FLOAT); INSERT INTO Forwarding (id,country,mode,cost) VALUES (1,'USA','Sea',1200),(2,'USA','Air',4000),(3,'China','Sea',1000),(4,'China','Air',4500),(5,'Japan','Sea',1100),(6,'Japan','Air',4800);
SELECT country, COUNT(*), AVG(cost) FROM Forwarding GROUP BY country;
What is the total number of labor hours spent on each mining site in the past year?
CREATE TABLE mining_sites (id INT,site_name TEXT); CREATE TABLE labor_hours (site_id INT,hours INT,date DATE); INSERT INTO mining_sites (id,site_name) VALUES (1,'siteA'),(2,'siteB'),(3,'siteC'); INSERT INTO labor_hours (site_id,hours,date) VALUES (1,250,'2022-01-01'),(1,275,'2022-01-02'),(2,300,'2022-01-01'),(3,325,'2022-01-02'),(1,200,'2022-02-01'),(2,225,'2022-02-01'),(3,250,'2022-02-01'),(1,300,'2022-03-01'),(2,350,'2022-03-01'),(3,400,'2022-03-01');
SELECT mining_sites.site_name, SUM(labor_hours.hours) FROM mining_sites INNER JOIN labor_hours ON mining_sites.id = labor_hours.site_id WHERE labor_hours.date >= '2022-01-01' AND labor_hours.date < '2023-01-01' GROUP BY mining_sites.site_name;
What is the average launch date of satellites launched by China?
CREATE TABLE satellites (satellite_id INT,name VARCHAR(255),launch_country VARCHAR(255),launch_date DATE);
SELECT AVG(launch_date) as avg_launch_date FROM satellites WHERE launch_country = 'China';
What is the total number of wildlife sightings in the Arctic?
CREATE TABLE WildlifeSightings (id INT,territory VARCHAR(20),animal VARCHAR(20),sighted_date DATE); INSERT INTO WildlifeSightings (id,territory,animal,sighted_date) VALUES (1,'Yukon','Moose','2021-07-01'); INSERT INTO WildlifeSightings (id,territory,animal,sighted_date) VALUES (2,'Northwest Territories','Caribou','2021-08-10');
SELECT COUNT(*) FROM WildlifeSightings WHERE territory LIKE 'Arctic%';
Update the 'price' column in the 'menu_items' table to $9.99 where the 'item_name' is 'Cheese Pizza'
CREATE TABLE menu_items (item_name TEXT,category TEXT,price DECIMAL(5,2));
UPDATE menu_items SET price = 9.99 WHERE item_name = 'Cheese Pizza';
What is the total value of digital assets owned by users in Latin America and Caribbean region?
CREATE TABLE users (id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO users (id,name,country) VALUES (1,'Eve','Brazil'),(2,'Frank','Mexico'),(3,'Grace','Jamaica'); CREATE TABLE assets (id INT,user_id INT,name VARCHAR(50),value DECIMAL(10,2)); INSERT INTO assets (id,user_id,name,value) VALUES (1,1,'Asset1',100),(2,2,'Asset2',200),(3,3,'Asset3',300);
SELECT SUM(value) FROM assets a INNER JOIN users u ON a.user_id = u.id WHERE u.country IN ('Brazil', 'Mexico', 'Jamaica');
What was the average score of players who played 'MobaGame' in 'NA' region?
CREATE TABLE MobaGame (playerID INT,region VARCHAR(5),score INT); INSERT INTO MobaGame (playerID,region,score) VALUES (1,'NA',20),(2,'NA',30),(3,'EU',25);
SELECT AVG(score) FROM MobaGame WHERE region = 'NA' AND game = 'MobaGame';
What is the maximum number of shared scooters available in a single day in the city of Denver?
CREATE TABLE ScooterShares (id INT,scooters INT,city VARCHAR(50),date DATE); INSERT INTO ScooterShares (id,scooters,city,date) VALUES (1,500,'Denver','2022-01-01'); INSERT INTO ScooterShares (id,scooters,city,date) VALUES (2,600,'Denver','2022-01-02');
SELECT MAX(scooters) FROM ScooterShares WHERE city = 'Denver';
How many electric vehicle charging stations were installed in India in 2020?
CREATE TABLE charging_stations (id INT,name TEXT,location TEXT,year INT);
SELECT COUNT(*) FROM charging_stations WHERE location LIKE '%India%' AND year = 2020;
Who are the top 2 artists with the highest average painting price?
CREATE TABLE Artists (id INT,name VARCHAR(50)); INSERT INTO Artists (id,name) VALUES (1,'Van Gogh'),(2,'Monet'),(3,'Picasso'); CREATE TABLE Paintings (id INT,artist_id INT,price DECIMAL(5,2)); INSERT INTO Paintings (id,artist_id,price) VALUES (1,1,20.50),(2,2,30.00),(3,1,25.00);
SELECT Artists.name, AVG(Paintings.price) as avg_price FROM Artists JOIN Paintings ON Artists.id = Paintings.artist_id GROUP BY Artists.name ORDER BY avg_price DESC LIMIT 2;