instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Update the salary of the council member representing district 3 to $90,000.00.
CREATE TABLE City_Council (council_id INT,council_member VARCHAR(50),district_number INT,salary DECIMAL(10,2),PRIMARY KEY (council_id)); INSERT INTO City_Council (council_id,council_member,district_number,salary) VALUES (1,'James Smith',1,85000.00),(2,'Katherine Johnson',2,85000.00),(3,'Mohammed Ahmed',3,80000.00);
UPDATE City_Council SET salary = 90000.00 WHERE district_number = 3;
What are the names and locations of all surface mining sites?
CREATE TABLE extraction_sites (site_id INT PRIMARY KEY,site_name VARCHAR(100),location VARCHAR(100),extraction_type VARCHAR(50)); INSERT INTO extraction_sites (site_id,site_name,location,extraction_type) VALUES (1,'Site A','Country X','Surface mining'),(2,'Site B','Country Y','Underground mining');
SELECT site_name, location FROM extraction_sites WHERE extraction_type = 'Surface mining';
What are the service names with the highest budget?
CREATE TABLE Service (id INT,department_id INT,name VARCHAR(50),cost DECIMAL(10,2)); INSERT INTO Service (id,department_id,name,cost) VALUES (1,1,'ServiceA',25000.00); INSERT INTO Service (id,department_id,name,cost) VALUES (2,1,'ServiceB',30000.00); INSERT INTO Service (id,department_id,name,cost) VALUES (3,2,'ServiceC',35000.00);
SELECT Service.name FROM Service WHERE cost = (SELECT MAX(cost) FROM Service)
What is the total market value of Europium in Africa?
CREATE TABLE europium_market (country VARCHAR(255),value DECIMAL(10,2)); INSERT INTO europium_market (country,value) VALUES ('South Africa',125.60),('Egypt',132.90),('Nigeria',110.00);
SELECT SUM(value) FROM europium_market WHERE country IN ('South Africa', 'Egypt', 'Nigeria');
What is the total number of community development projects in each continent?
CREATE TABLE Projects (project_id INT,project_location VARCHAR(50),project_type VARCHAR(50)); INSERT INTO Projects (project_id,project_location,project_type) VALUES (1,'Nigeria','Community Development'),(2,'Canada','Education'),(3,'Kenya','Community Development');
SELECT project_location, COUNT(*) AS 'Total Projects' FROM Projects WHERE project_type = 'Community Development' GROUP BY project_location;
What is the average donation amount and total volunteer hours for programs related to environmental conservation?
CREATE TABLE Programs (ProgramID INT,ProgramName VARCHAR(50),ProgramType VARCHAR(50),DonationAmount DECIMAL(10,2),VolunteerHours INT); INSERT INTO Programs (ProgramID,ProgramName,ProgramType,DonationAmount,VolunteerHours) VALUES (101,'Environmental Conservation','Donation',1000.00,50),(102,'Education Support','Volunteer',NULL,30),(103,'Healthcare Support','Donation',1500.00,40);
SELECT ProgramType, AVG(DonationAmount) AS AvgDonation, SUM(VolunteerHours) AS TotalVolunteerHours FROM Programs WHERE ProgramType = 'Donation' GROUP BY ProgramType;
What is the total savings account balance for customers in the Phoenix branch?
CREATE TABLE accounts (customer_id INT,account_type VARCHAR(20),branch VARCHAR(20),balance DECIMAL(10,2)); INSERT INTO accounts (customer_id,account_type,branch,balance) VALUES (1,'Savings','New York',5000.00),(2,'Checking','New York',7000.00),(3,'Savings','Phoenix',6000.00),(4,'Savings','Phoenix',5000.00);
SELECT SUM(balance) FROM accounts WHERE account_type = 'Savings' AND branch = 'Phoenix';
Delete the 'Indian Ocean' record from the 'oceanography' table
CREATE TABLE oceanography (id INT PRIMARY KEY,name VARCHAR(255),average_depth FLOAT,area FLOAT,volume FLOAT);
WITH deleted_indian AS (DELETE FROM oceanography WHERE name = 'Indian Ocean') SELECT * FROM deleted_indian;
What is the total claim amount and policy type for each policyholder?
CREATE TABLE Policy (PolicyID int,PolicyholderName varchar(50),PolicyType varchar(50),Premium int); INSERT INTO Policy (PolicyID,PolicyholderName,PolicyType,Premium) VALUES (1,'John Doe','Auto',1000),(2,'Jane Smith','Home',2000); CREATE TABLE Claim (ClaimID int,PolicyID int,ClaimAmount int); INSERT INTO Claim (ClaimID,PolicyID,ClaimAmount) VALUES (1,1,500),(2,1,300),(3,2,800);
SELECT P.PolicyholderName, P.PolicyType, SUM(C.ClaimAmount) AS TotalClaimAmount FROM Policy P JOIN Claim C ON P.PolicyID = C.PolicyID GROUP BY P.PolicyholderName, P.PolicyType;
What are the total waste generation quantities for each city, along with the number of circular economy initiatives implemented in the corresponding region, for 2020?
CREATE TABLE CityWaste (CityName VARCHAR(50),WasteQuantity INT,WasteYear INT,CityRegion VARCHAR(50)); CREATE TABLE CircularEconomy (Region VARCHAR(50),Initiative VARCHAR(50),ImplementationYear INT); INSERT INTO CityWaste (CityName,WasteQuantity,WasteYear,CityRegion) VALUES ('CityA',12000,2020,'RegionA'),('CityB',15000,2020,'RegionA'),('CityC',18000,2020,'RegionB'),('CityD',10000,2020,'RegionB'); INSERT INTO CircularEconomy (Region,Initiative,ImplementationYear) VALUES ('RegionA','Initiative1',2020),('RegionA','Initiative2',2020),('RegionB','Initiative3',2020),('RegionB','Initiative4',2020);
SELECT CityWaste.CityName, SUM(CityWaste.WasteQuantity) AS TotalWasteQuantity, COUNT(CircularEconomy.Initiative) AS NumberOfInitiatives FROM CityWaste INNER JOIN CircularEconomy ON CityWaste.CityRegion = CircularEconomy.Region WHERE CityWaste.WasteYear = 2020 GROUP BY CityWaste.CityName;
Which tree species are present in each forest plot?
CREATE TABLE ForestPlots (PlotID int,PlotName varchar(50)); INSERT INTO ForestPlots VALUES (1,'Plot1'),(2,'Plot2'); CREATE TABLE Trees (TreeID int,TreeSpecies varchar(50),PlotID int); INSERT INTO Trees VALUES (1,'Oak',1),(2,'Maple',1),(3,'Pine',2);
SELECT ForestPlots.PlotName, Trees.TreeSpecies FROM ForestPlots INNER JOIN Trees ON ForestPlots.PlotID = Trees.PlotID;
What is the total transaction value per customer type?
CREATE TABLE customers (customer_id INT,customer_type VARCHAR(20)); INSERT INTO customers (customer_id,customer_type) VALUES (1,'Retail'),(2,'Wholesale'),(3,'Institutional'); CREATE TABLE transactions (transaction_id INT,customer_id INT,transaction_value DECIMAL(10,2)); INSERT INTO transactions (transaction_id,customer_id,transaction_value) VALUES (1,1,500.00),(2,1,750.00),(3,2,3000.00),(4,3,15000.00);
SELECT customer_type, SUM(transaction_value) as total_transaction_value FROM transactions JOIN customers ON transactions.customer_id = customers.customer_id GROUP BY customer_type;
Insert data about an archaeologist into the Archaeologists table
CREATE TABLE Archaeologists (id INT PRIMARY KEY,name VARCHAR(255),specialty TEXT,years_experience INT); INSERT INTO Archaeologists (id,name,specialty,years_experience) VALUES (1,'Dr. Jane Doe','Egyptology',20);
INSERT INTO Archaeologists (id, name, specialty, years_experience) VALUES (2, 'Dr. John Smith', 'Mayan Civilization', 15);
Calculate the year-over-year percentage change in energy consumption for all hotels.
CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,city TEXT,country TEXT,energy_consumption FLOAT,year INT); INSERT INTO hotels (hotel_id,hotel_name,city,country,energy_consumption,year) VALUES (1,'Hotel A','Rome','Italy',12000.0,2021),(1,'Hotel A','Rome','Italy',13000.0,2022);
SELECT hotel_name, ((energy_consumption - LAG(energy_consumption) OVER (PARTITION BY hotel_name ORDER BY year))/LAG(energy_consumption) OVER (PARTITION BY hotel_name ORDER BY year))*100 as percentage_change FROM hotels;
List all donation categories and their respective minimum donation amounts.
CREATE TABLE Donation_Categories (id INT,category TEXT,min_donation INT); INSERT INTO Donation_Categories (id,category,min_donation) VALUES (1,'Education',50); INSERT INTO Donation_Categories (id,category,min_donation) VALUES (2,'Healthcare',100);
SELECT category, min_donation FROM Donation_Categories;
What is the total carbon offset of renewable energy projects in Canada and Mexico?
CREATE TABLE carbon_offsets (id INT,country VARCHAR(255),project_name VARCHAR(255),carbon_offset INT); INSERT INTO carbon_offsets (id,country,project_name,carbon_offset) VALUES (1,'Canada','Project G',1000),(2,'Mexico','Project H',1500);
SELECT SUM(carbon_offset) FROM carbon_offsets WHERE country IN ('Canada', 'Mexico');
What is the average number of open pedagogy projects completed by students who identify as first-generation, broken down by their gender identity?
CREATE TABLE students (student_id INT,gender_identity VARCHAR(255),first_generation_status VARCHAR(255),num_open_pedagogy_projects INT); INSERT INTO students (student_id,gender_identity,first_generation_status,num_open_pedagogy_projects) VALUES (1,'Female','Yes',3),(2,'Non-binary','No',5),(3,'Male','Yes',4);
SELECT gender_identity, AVG(num_open_pedagogy_projects) as avg_projects FROM students WHERE first_generation_status = 'Yes' GROUP BY gender_identity;
What is the maximum order quantity for recycled packaging materials?
CREATE TABLE packaging_materials (id INT,order_qty INT,recycled BOOLEAN); INSERT INTO packaging_materials (id,order_qty,recycled) VALUES (1,500,true),(2,750,false),(3,600,true);
SELECT MAX(order_qty) FROM packaging_materials WHERE recycled = true;
Display the top 5 most frequently used explainable AI techniques in Latin America and Oceania.
CREATE TABLE explainable_ai (technique_id INT,technique_name VARCHAR(255),region VARCHAR(255),usage_count INT); INSERT INTO explainable_ai (technique_id,technique_name,region,usage_count) VALUES (1,'SHAP','Argentina',150),(2,'LIME','Australia',200),(3,'TreeExplainer','New Zealand',120),(4,'Partial Dependence Plot','Brazil',250),(5,'Feature Importance','Fiji',180);
SELECT technique_name, usage_count FROM explainable_ai WHERE region IN ('Latin America', 'Oceania') ORDER BY usage_count DESC LIMIT 5;
What is the total budget allocation for education and healthcare services in 2022?
CREATE TABLE BudgetAllocations (Year INT,Service TEXT,Amount INT); INSERT INTO BudgetAllocations (Year,Service,Amount) VALUES (2022,'Education',15000000),(2022,'Healthcare',20000000);
SELECT SUM(Amount) FROM BudgetAllocations WHERE Service IN ('Education', 'Healthcare') AND Year = 2022;
What is the total fare collected for trams in 'south' region in January 2022?
CREATE TABLE tram_fares (fare_id INT,tram_id INT,fare DECIMAL(5,2),date DATE); INSERT INTO tram_fares (fare_id,tram_id,fare,date) VALUES (1,101,3.00,'2022-01-01'),(2,102,2.50,'2022-01-02'),(3,101,3.00,'2022-01-03'),(4,103,2.00,'2022-01-04');
SELECT SUM(fare) FROM tram_fares WHERE region = 'south' AND date >= '2022-01-01' AND date <= '2022-01-31';
List all climate adaptation projects in the Pacific Islands and their respective start years.
CREATE TABLE climate_adaptation_projects (id INT,project_name VARCHAR(100),location VARCHAR(100),start_year INT); INSERT INTO climate_adaptation_projects (id,project_name,location,start_year) VALUES (1,'Sea Level Rise Protection','Pacific Islands',2010),(2,'Coastal Erosion Prevention','Europe',2005);
SELECT project_name, start_year FROM climate_adaptation_projects WHERE location = 'Pacific Islands';
How many hotel virtual tours have been viewed in France, ordered by the most popular?
CREATE TABLE hotel_virtual_tours (hotel_id INT,country VARCHAR(50),views INT); INSERT INTO hotel_virtual_tours (hotel_id,country,views) VALUES (1,'France',1000),(2,'France',1200),(3,'Germany',800); CREATE TABLE hotel_info (hotel_id INT,hotel_name VARCHAR(50)); INSERT INTO hotel_info (hotel_id,hotel_name) VALUES (1,'Hotel Paris'),(2,'Hotel Lyon'),(3,'Hotel Berlin');
SELECT hv.country, hi.hotel_name, hv.views FROM hotel_virtual_tours hv JOIN hotel_info hi ON hv.hotel_id = hi.hotel_id WHERE country = 'France' ORDER BY views DESC;
What is the total installed capacity (MW) of renewable energy projects?
CREATE TABLE renewable_projects (id INT,name VARCHAR(255),location VARCHAR(255),capacity FLOAT,technology VARCHAR(255));
SELECT SUM(capacity) FROM renewable_projects WHERE technology IN ('Solar', 'Wind', 'Hydro', 'Geothermal', 'Biomass');
How many fish escapes were recorded in the past year for each species?
CREATE TABLE fish_escapes (id INT,escape_date DATE,species VARCHAR(50),quantity INT); INSERT INTO fish_escapes (id,escape_date,species,quantity) VALUES (1,'2021-02-12','Salmon',250),(2,'2021-03-04','Tilapia',120),(3,'2021-07-18','Salmon',300);
SELECT species, YEAR(escape_date) as escape_year, SUM(quantity) as total_escapes FROM fish_escapes WHERE escape_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY species, YEAR(escape_date);
What is the total number of labor hours worked in the construction industry in Brazil in the last quarter?
CREATE TABLE Labor_Hours (id INT,worker_id TEXT,company TEXT,job_title TEXT,hours_worked FLOAT,country TEXT);
SELECT SUM(hours_worked) FROM Labor_Hours WHERE country = 'Brazil' AND start_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH);
List all excavation sites and their total number of artifacts
CREATE TABLE ExcavationSites (SiteID INT,SiteName TEXT,Country TEXT,StartDate DATE,EndDate DATE);CREATE VIEW ArtifactCountPerSite AS SELECT SiteID,COUNT(*) AS ArtifactCount FROM Artifacts GROUP BY SiteID;
SELECT e.SiteName, ac.ArtifactCount FROM ExcavationSites e JOIN ArtifactCountPerSite ac ON e.SiteID = ac.SiteID;
What is the median age of patients who improved after CBT?
CREATE TABLE patients (id INT,age INT,improvement VARCHAR(255)); INSERT INTO patients (id,age,improvement) VALUES (1,35,'Improved'),(2,42,'Not Improved'),(3,32,'Improved'); CREATE TABLE therapy (patient_id INT,therapy_type VARCHAR(255)); INSERT INTO therapy (patient_id,therapy_type) VALUES (1,'CBT'),(2,'CBT'),(3,'DBT');
SELECT MEDIAN(age) as median_age FROM patients JOIN therapy ON patients.id = therapy.patient_id WHERE improvement = 'Improved' AND therapy_type = 'CBT';
List all programs with their respective volunteer and community member impact counts.
CREATE TABLE Programs (ProgramID INT,ProgramName TEXT); INSERT INTO Programs (ProgramID,ProgramName) VALUES (1,'Feed the Hungry'),(2,'Tutoring'); CREATE TABLE VolunteerPrograms (VolunteerID INT,ProgramID INT); INSERT INTO VolunteerPrograms (VolunteerID,ProgramID) VALUES (1,1),(1,2),(2,1),(2,2); CREATE TABLE CommunityImpact (ImpactID INT,ProgramID INT,Impacted INT); INSERT INTO CommunityImpact (ImpactID,ProgramID,Impacted) VALUES (1,1,500),(2,1,1000),(3,2,800);
SELECT Programs.ProgramName, COUNT(DISTINCT VolunteerPrograms.VolunteerID) AS VolunteerCount, SUM(CommunityImpact.Impacted) AS CommunityImpactCount FROM Programs INNER JOIN VolunteerPrograms ON Programs.ProgramID = VolunteerPrograms.ProgramID INNER JOIN CommunityImpact ON Programs.ProgramID = CommunityImpact.ProgramID GROUP BY Programs.ProgramName;
What is the average age of patients diagnosed with depression in the 'mental_health' schema?
CREATE TABLE patients (patient_id INT,diagnosis VARCHAR(255),age INT); INSERT INTO patients (patient_id,diagnosis,age) VALUES (1,'depression',35),(2,'anxiety',28),(3,'depression',42);
SELECT AVG(age) FROM mental_health.patients WHERE diagnosis = 'depression';
List all the countries with their respective number of Oscar-winning movies and total production budget.
CREATE TABLE movie (id INT,title VARCHAR(100),production_country VARCHAR(50),production_budget INT,won_Oscar BOOLEAN); INSERT INTO movie (id,title,production_country,production_budget,won_Oscar) VALUES (1,'The Shape of Water','United States',190000000,true);
SELECT production_country, COUNT(*), SUM(production_budget) FROM movie WHERE won_Oscar = true GROUP BY production_country;
Calculate the sum of interest-free loans issued to 'Mohammed' in 2022.
CREATE TABLE interest_free_loans (loan_id INT,amount DECIMAL(10,2),borrower VARCHAR(255),loan_date DATE); INSERT INTO interest_free_loans (loan_id,amount,borrower,loan_date) VALUES (1,5000,'Mohammed','2022-04-01'); INSERT INTO interest_free_loans (loan_id,amount,borrower,loan_date) VALUES (2,6000,'Fatima','2022-05-15');
SELECT SUM(amount) FROM interest_free_loans WHERE borrower = 'Mohammed' AND loan_date BETWEEN '2022-01-01' AND '2022-12-31';
Determine the total number of AI models trained for algorithmic fairness in the last 3 years, grouped by the training location.
CREATE TABLE ai_models (model_id INT,model_name VARCHAR(50),trained_for VARCHAR(50),training_location VARCHAR(50),training_date DATE);
SELECT training_location, COUNT(*) AS total FROM ai_models WHERE trained_for = 'algorithmic fairness' AND training_date >= DATE(CURRENT_DATE) - INTERVAL 3 YEAR GROUP BY training_location;
How many virtual tours were engaged in the last month for hotels in France?
CREATE TABLE virtual_tours (tour_id INT,hotel_id INT,date DATE); INSERT INTO virtual_tours (tour_id,hotel_id,date) VALUES (1,4,'2022-02-15'),(2,4,'2022-02-17'),(3,5,'2022-03-01'),(4,5,'2022-03-05');
SELECT COUNT(*) FROM virtual_tours WHERE hotel_id IN (SELECT hotel_id FROM hotels WHERE country = 'France') AND date >= DATEADD(month, -1, GETDATE());
How many vehicles are due for maintenance in each region?
CREATE TABLE Vehicles (VehicleID INT,VehicleType VARCHAR(50),Region VARCHAR(50),NextMaintenanceDate DATE); INSERT INTO Vehicles (VehicleID,VehicleType,Region,NextMaintenanceDate) VALUES (1,'Bus','RegionA','2023-03-01'),(2,'Tram','RegionA','2023-04-15'),(3,'Train','RegionB','2023-02-28');
SELECT Region, COUNT(*) as VehiclesDueForMaintenance FROM Vehicles WHERE NextMaintenanceDate <= CURDATE() GROUP BY Region;
Show the number of fans from each location in the 'fan_demographics' table.
CREATE TABLE fan_demographics (fan_id INT,gender VARCHAR(10),age INT,location VARCHAR(30));
SELECT location, COUNT(*) FROM fan_demographics GROUP BY location;
How many startups were founded in the technology sector in the last 5 years?
CREATE TABLE startups(id INT,name TEXT,industry TEXT,founding_date DATE); INSERT INTO startups(id,name,industry,founding_date) VALUES (1,'TechStart','Technology','2019-01-01');
SELECT COUNT(*) FROM startups WHERE industry = 'Technology' AND founding_date >= DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR);
Update the labor productivity score of mine with ID 4 to 9.0.
CREATE TABLE Labor (LaborID INT,MineID INT,Year INT,LaborProductivityScore FLOAT); INSERT INTO Labor (LaborID,MineID,Year,LaborProductivityScore) VALUES (1,1,2019,5.5); INSERT INTO Labor (LaborID,MineID,Year,LaborProductivityScore) VALUES (2,1,2018,6.0); INSERT INTO Labor (LaborID,MineID,Year,LaborProductivityScore) VALUES (3,2,2019,7.0); INSERT INTO Labor (LaborID,MineID,Year,LaborProductivityScore) VALUES (4,2,2018,7.5); INSERT INTO Labor (LaborID,MineID,Year,LaborProductivityScore) VALUES (5,3,2019,8.0);
UPDATE Labor SET LaborProductivityScore = 9.0 WHERE MineID = 2;
Identify the number of virtual tours engaged for hotels in the 'Asia' region.
CREATE TABLE virtualtours (id INT,hotel_id INT,views INT); INSERT INTO virtualtours (id,hotel_id,views) VALUES (1,5,120); INSERT INTO virtualtours (id,hotel_id,views) VALUES (2,6,150);
SELECT COUNT(*) FROM virtualtours WHERE hotel_id IN (SELECT id FROM hotels WHERE region = 'Asia');
How many female farmers are in the 'farmers' table?
CREATE TABLE farmers (id INT,name VARCHAR(50),gender VARCHAR(50),location VARCHAR(50)); INSERT INTO farmers (id,name,gender,location) VALUES (1,'John Doe','Male','Springfield'); INSERT INTO farmers (id,name,gender,location) VALUES (2,'Jane Doe','Female','Springfield');
SELECT COUNT(*) FROM farmers WHERE gender = 'Female';
Count the number of carbon offset programs implemented in 'Europe' and 'Asia'.
CREATE TABLE carbon_offset_programs (id INT,location VARCHAR(20)); INSERT INTO carbon_offset_programs (id,location) VALUES (1,'Europe'),(2,'Asia'),(3,'North America'),(4,'Europe'),(5,'Asia');
SELECT location, COUNT(*) AS count FROM carbon_offset_programs WHERE location IN ('Europe', 'Asia') GROUP BY location;
What is the total number of articles published in 2020, written by female authors and belonging to the 'Investigative Journalism' category?
CREATE TABLE Articles (ArticleID INT,Title VARCHAR(100),AuthorID INT,Category VARCHAR(50),WordCount INT,PublishedDate DATE,AuthorGender VARCHAR(10));
SELECT COUNT(*) FROM Articles WHERE PublishedDate >= '2020-01-01' AND PublishedDate < '2021-01-01' AND AuthorGender = 'Female' AND Category = 'Investigative Journalism';
How many community development initiatives were completed in India's Uttar Pradesh state by NGOs in 2017?
CREATE TABLE community_development (id INT,initiative_name VARCHAR(255),completion_date DATE,organization_type VARCHAR(50),state VARCHAR(50)); INSERT INTO community_development (id,initiative_name,completion_date,organization_type,state) VALUES (1,'Education Program','2017-08-15','NGO','Uttar Pradesh'),(2,'Health Awareness Campaign','2018-02-28','Government','Uttar Pradesh'),(3,'Women Empowerment Project','2016-12-12','NGO','Uttar Pradesh');
SELECT COUNT(*) FROM community_development WHERE state = 'Uttar Pradesh' AND organization_type = 'NGO' AND EXTRACT(YEAR FROM completion_date) = 2017
Identify the average billing rate for attorneys who have represented clients from underrepresented communities.
CREATE TABLE Attorneys (id INT,cases INT,billing_rate DECIMAL(5,2),underrepresented_client BOOLEAN);
SELECT AVG(billing_rate) FROM Attorneys WHERE underrepresented_client = TRUE;
Identify users who increased their step count by more than 10% in the last 30 days.
CREATE TABLE steps (id INT,user_id INT,daily_step_count INT,step_date DATE); INSERT INTO steps (id,user_id,daily_step_count,step_date) VALUES (1,1,8000,'2022-03-01'),(2,2,9000,'2022-03-15');
SELECT user_id FROM (SELECT user_id, daily_step_count, LAG(daily_step_count, 1) OVER (PARTITION BY user_id ORDER BY id) AS previous_step_count, (daily_step_count::DECIMAL / LAG(daily_step_count, 1) OVER (PARTITION BY user_id ORDER BY id)) * 100 AS step_increase_percentage FROM steps WHERE DATE(CURRENT_DATE() - INTERVAL 30 DAY) <= DATE(step_date)) AS subquery WHERE step_increase_percentage > 100;
What is the total number of climate finance initiatives and their combined budget in North America in 2022?
CREATE TABLE climate_finance (initiative_name VARCHAR(50),country VARCHAR(50),year INT,budget INT); INSERT INTO climate_finance (initiative_name,country,year,budget) VALUES ('Green Cities Initiative','USA',2022,500000); INSERT INTO climate_finance (initiative_name,country,year,budget) VALUES ('Climate Smart Agriculture','Canada',2022,750000); INSERT INTO climate_finance (initiative_name,country,year,budget) VALUES ('Renewable Energy Fund','Mexico',2022,800000);
SELECT COUNT(*) as num_initiatives, SUM(budget) as total_budget FROM climate_finance WHERE year = 2022 AND country = 'North America';
Find the top 3 workout types with the longest duration, excluding those with a duration less than 15 minutes.
CREATE TABLE workout_data_extended(id INT,member_id INT,workout_type VARCHAR(20),workout_duration INT,country VARCHAR(20),additional_data VARCHAR(20)); INSERT INTO workout_data_extended(id,member_id,workout_type,workout_duration,country,additional_data) VALUES (1,1,'Running',60,'USA','Trail'),(2,2,'Cycling',20,'Canada','Home'),(3,3,'Swimming',45,'Australia','Pool');
SELECT workout_type, AVG(workout_duration) as avg_duration FROM workout_data_extended WHERE workout_duration >= 15 GROUP BY workout_type ORDER BY avg_duration DESC LIMIT 3;
What is the total cost of community development initiatives in rural areas of Kenya in 2019?
CREATE TABLE community_development (id INT,location VARCHAR(20),completion_year INT,initiative_name VARCHAR(50),project_cost FLOAT); INSERT INTO community_development (id,location,completion_year,initiative_name,project_cost) VALUES (1,'Rural',2018,'Community Library',15000.00),(2,'Urban',2019,'Community Park',20000.00);
SELECT SUM(project_cost) FROM community_development WHERE location = 'Rural' AND completion_year = 2019;
What is the maximum temperature recorded for each crop type in the past month?
CREATE TABLE crop_temperature (crop_type TEXT,date DATE,temperature INTEGER);
SELECT crop_type, MAX(temperature) as max_temp FROM crop_temperature WHERE date >= DATEADD(month, -1, GETDATE()) GROUP BY crop_type;
Show the total amount of funding for programs in 'Arts' and 'Culture' categories, excluding programs with a budget over $100,000.
CREATE TABLE Programs (id INT,name TEXT,category TEXT,budget INT); INSERT INTO Programs (id,name,category,budget) VALUES (1,'Art Exhibition','Arts',50000),(2,'Music Festival','Culture',150000),(3,'Theater Performance','Arts',80000);
SELECT SUM(budget) FROM Programs WHERE category IN ('Arts', 'Culture') AND budget <= 100000;
List the top 5 directors based on the total runtime of their movies, considering movies released between 2005 and 2015.
CREATE TABLE movies (id INT,title VARCHAR(255),release_year INT,runtime_minutes INT,director VARCHAR(255));
SELECT director, SUM(runtime_minutes) as total_runtime FROM movies WHERE release_year BETWEEN 2005 AND 2015 GROUP BY director ORDER BY total_runtime DESC LIMIT 5;
What is the total number of movies produced by studios located in the United States and Canada?
CREATE TABLE movie_studios (id INT,studio_name VARCHAR(255),country VARCHAR(255)); INSERT INTO movie_studios (id,studio_name,country) VALUES (1,'Universal Pictures','United States'); INSERT INTO movie_studios (id,studio_name,country) VALUES (2,'Paramount Pictures','United States'); INSERT INTO movie_studios (id,studio_name,country) VALUES (3,'Warner Bros. Pictures','United States'); INSERT INTO movie_studios (id,studio_name,country) VALUES (4,'Sony Pictures Entertainment','United States'); INSERT INTO movie_studios (id,studio_name,country) VALUES (5,'Cineplex','Canada');
SELECT COUNT(*) FROM movie_studios WHERE country IN ('United States', 'Canada');
How many veteran job applications were received in Q3 2021?
CREATE TABLE VeteranJobApplications (Quarter TEXT,Year INT,NumberOfApplications INT); INSERT INTO VeteranJobApplications (Quarter,Year,NumberOfApplications) VALUES ('Q1',2021,1200),('Q2',2021,1500),('Q3',2021,1800),('Q4',2021,1300);
SELECT NumberOfApplications FROM VeteranJobApplications WHERE Quarter = 'Q3' AND Year = 2021;
Find the total water consumption for the 10 largest cities in the United States?
CREATE TABLE City_Water_Usage (ID INT,City VARCHAR(50),State VARCHAR(20),Usage FLOAT);
SELECT City, SUM(Usage) FROM (SELECT City, Usage FROM City_Water_Usage WHERE City IN ('New York', 'Los Angeles', 'Chicago', 'Houston', 'Phoenix', 'Philadelphia', 'San Antonio', 'San Diego', 'Dallas', 'San Jose') ORDER BY Usage DESC LIMIT 10) t GROUP BY City;
What is the average attendance at cultural events in New York?
CREATE TABLE events (id INT,name TEXT,location TEXT,attendance INT); INSERT INTO events (id,name,location,attendance) VALUES (1,'Festival A','New York',500),(2,'Conference B','London',300),(3,'Exhibition C','New York',700);
SELECT AVG(attendance) FROM events WHERE location = 'New York';
How many education programs were successful in each region?
CREATE TABLE education_programs (id INT,name VARCHAR(255),region VARCHAR(255),habitat_preserved BOOLEAN); INSERT INTO education_programs (id,name,region,habitat_preserved) VALUES (1,'Save the Wetlands','Africa',true),(2,'Trees for Tomorrow','Asia',false);
SELECT region, COUNT(*) FROM education_programs WHERE habitat_preserved = true GROUP BY region;
List the number of female and male entrepreneurs who received funding for their projects in the 'entrepreneurs_funding' table, separated by project category?
CREATE TABLE entrepreneurs_funding (id INT,entrepreneur_name VARCHAR(50),gender VARCHAR(10),project_category VARCHAR(50),funding DECIMAL(10,2));
SELECT project_category, gender, COUNT(*) FROM entrepreneurs_funding GROUP BY project_category, gender;
How many hospitals are there in the rural areas of Texas and California?
CREATE TABLE hospitals (id INT,name TEXT,location TEXT,beds INT,rural BOOLEAN); INSERT INTO hospitals (id,name,location,beds,rural) VALUES (1,'Hospital A','Texas',200,true),(2,'Hospital B','California',300,true);
SELECT SUM(rural) FROM hospitals WHERE location IN ('Texas', 'California') AND rural = true;
What is the average donation amount in the 'East Coast' region?
CREATE TABLE Donations (id INT,name TEXT,region TEXT,donation FLOAT); INSERT INTO Donations (id,name,region,donation) VALUES (1,'Ella','East Coast',150.2),(2,'Fred','West Coast',200.0);
SELECT AVG(donation) FROM Donations WHERE region = 'East Coast';
What is the maximum pH level in the Southern Ocean for prawn farms?
CREATE TABLE Southern_Ocean (id INT,pH DECIMAL(3,2),prawn_farm VARCHAR(20)); INSERT INTO Southern_Ocean (id,pH,prawn_farm) VALUES (1,8.1,'Farm 1'),(2,7.9,'Farm 2'),(3,8.3,'Farm 3');
SELECT MAX(pH) FROM Southern_Ocean WHERE prawn_farm IS NOT NULL;
List all drugs that were approved in 2018 and have market access in Canada?
CREATE TABLE drug_approval_2018 (drug VARCHAR(50),year INT,status VARCHAR(50)); INSERT INTO drug_approval_2018 (drug,year,status) VALUES ('DrugM',2018,'Approved'),('DrugN',2018,'Approved'); CREATE TABLE market_access (drug VARCHAR(50),country VARCHAR(50)); INSERT INTO market_access (drug,country) VALUES ('DrugM','Canada'),('DrugO','Canada');
SELECT market_access.drug FROM market_access INNER JOIN drug_approval_2018 ON market_access.drug = drug_approval_2018.drug WHERE drug_approval_2018.year = 2018 AND drug_approval_2018.status = 'Approved' AND market_access.country = 'Canada';
What are the names of all savings products offered by ethical banks?
CREATE TABLE Banks (BankID INT,Name VARCHAR(255)); INSERT INTO Banks (BankID,Name) VALUES (1,'ABC Bank'); INSERT INTO Banks (BankID,Name) VALUES (2,'XYZ Bank'); CREATE TABLE Products (ProductID INT,Name VARCHAR(255),BankID INT); INSERT INTO Products (ProductID,Name,BankID) VALUES (1,'Savings Account',1); INSERT INTO Products (ProductID,Name,BankID) VALUES (2,'Checking Account',1); INSERT INTO Products (ProductID,Name,BankID) VALUES (3,'Islamic Savings Account',2);
SELECT P.Name FROM Products P INNER JOIN Banks B ON P.BankID = B.BankID WHERE B.Name IN ('ABC Bank', 'XYZ Bank') AND P.Name LIKE '%Savings%';
What is the total inventory value for each category in Mexico?
CREATE TABLE inventory (id INT,item_id INT,category TEXT,quantity INT,price DECIMAL(5,2));INSERT INTO inventory (id,item_id,category,quantity,price) VALUES (1,1,'Pizza',100,5.99),(2,2,'Pasta',75,6.99),(3,3,'Salad',50,4.99);
SELECT c.category, SUM(i.quantity * i.price) AS total_inventory_value FROM inventory i JOIN categories c ON i.category = c.id WHERE c.country = 'Mexico' GROUP BY c.category;
What was the change in price of 'Bananas' between January and December in 'QuarterlyFruitPrices' table?
CREATE TABLE QuarterlyFruitPrices (quarter INT,year INT,fruit VARCHAR(20),price FLOAT);
SELECT (SUM(CASE WHEN quarter = 4 THEN price ELSE 0 END) - SUM(CASE WHEN quarter = 1 THEN price ELSE 0 END)) as banana_price_change FROM QuarterlyFruitPrices WHERE fruit = 'Bananas';
How many donations were made in each city in 2021?
CREATE TABLE Donations (id INT,donation_amount DECIMAL(10,2),transaction_date DATE,city VARCHAR(50)); INSERT INTO Donations (id,donation_amount,transaction_date,city) VALUES (1,500,'2021-01-01','New York'),(2,300,'2021-04-15','Los Angeles'),(3,700,'2021-07-03','Chicago'),(4,800,'2021-10-17','Houston'),(5,600,'2021-12-02','Philadelphia');
SELECT city, COUNT(*) as donation_count FROM Donations WHERE YEAR(transaction_date) = 2021 GROUP BY city;
Which cosmetic brands have the highest and lowest product safety records in the Japanese market?
CREATE TABLE product_safety_records (brand TEXT,product_id INT,country TEXT,safety_rating INT);
SELECT brand, MAX(safety_rating) as highest_safety_rating, MIN(safety_rating) as lowest_safety_rating FROM product_safety_records WHERE country = 'Japan' GROUP BY brand ORDER BY highest_safety_rating DESC, lowest_safety_rating;
How many attendees were from underrepresented communities in 2020?
CREATE TABLE Attendees (attendee_id INT,attendee_community VARCHAR(50),attendance_date DATE); INSERT INTO Attendees (attendee_id,attendee_community,attendance_date) VALUES (1,'Hispanic','2020-01-01'),(2,'African American','2020-02-01'),(3,'Asian','2020-03-01'),(4,'Native American','2020-04-01'),(5,'Caucasian','2020-05-01'),(6,'LGBTQ+','2020-06-01'),(7,'Disabled','2020-07-01'),(8,'Women','2020-08-01'),(9,'Senior','2020-09-01'),(10,'Youth','2020-10-01'),(11,'Veteran','2020-11-01'),(12,'Refugee','2020-12-01');
SELECT COUNT(*) AS total_attendees FROM Attendees WHERE attendance_date BETWEEN '2020-01-01' AND '2020-12-31' AND attendee_community IN ('Hispanic', 'African American', 'Asian', 'Native American', 'LGBTQ+', 'Disabled', 'Women', 'Senior', 'Youth', 'Veteran', 'Refugee');
What was the total cost of projects in the 'water_infrastructure' category?
CREATE TABLE if not exists projects (id INT,name VARCHAR(100),category VARCHAR(50),total_cost FLOAT); INSERT INTO projects (id,name,category,total_cost) VALUES (1,'Water Treatment Plant','water_infrastructure',5000000);
SELECT SUM(total_cost) FROM projects WHERE category = 'water_infrastructure';
What are the names of all venues that have hosted esports events?
CREATE TABLE esports_events (id INT,event_name VARCHAR(50),date DATE,venue_id INT); CREATE TABLE venues (id INT,name VARCHAR(50),capacity INT); INSERT INTO esports_events (id,event_name,date,venue_id) VALUES (1,'GameX','2023-06-01',101); INSERT INTO venues (id,name,capacity) VALUES (101,'Staples Center',20000);
SELECT venues.name FROM venues INNER JOIN esports_events ON venues.id = esports_events.venue_id;
List all the unique majors offered in the 'Students' table.
CREATE TABLE students (student_id INT,major VARCHAR(255)); INSERT INTO students (student_id,major) VALUES (1,'Computer Science'),(2,'Mathematics'),(3,'Psychology'),(4,'Biology'),(5,'Computer Science');
SELECT DISTINCT major FROM students;
What was the total budget for spacecraft manufactured by 'AeroSpace Inc.'?
CREATE TABLE Spacecraft (id INT,name VARCHAR(255),manufacturer VARCHAR(255),budget DECIMAL(10,2)); INSERT INTO Spacecraft (id,name,manufacturer,budget) VALUES (1,'Voyager I','AeroSpace Inc.',800000000.00),(2,'Voyager II','AeroSpace Inc.',850000000.00);
SELECT SUM(budget) FROM Spacecraft WHERE manufacturer = 'AeroSpace Inc.';
Insert a new record into the carbon offset initiatives table
CREATE TABLE carbon_offset_initiatives (id INT,name VARCHAR(50),location VARCHAR(50),offset_amount INT);
INSERT INTO carbon_offset_initiatives (id, name, location, offset_amount) VALUES (5, 'Tree Planting', 'City M', 1000);
What is the minimum age of all animals in the 'oceanic_animal_profiles' table?
CREATE TABLE oceanic_animal_profiles (id INT,animal_name VARCHAR(50),age INT,species_id INT); INSERT INTO oceanic_animal_profiles (id,animal_name,age,species_id) VALUES (1,'Blue Whale',30,1001),(2,'Dolphin',8,1002),(3,'Sea Turtle',25,1003);
SELECT MIN(age) FROM oceanic_animal_profiles;
What is the average water consumption per person in South American countries?
CREATE TABLE south_american_countries (country VARCHAR(255),population INT,water_consumption INT); INSERT INTO south_american_countries (country,population,water_consumption) VALUES ('Brazil',210000000,4200000000),('Colombia',50000000,1000000000);
SELECT country, water_consumption / population AS avg_water_consumption FROM south_american_countries;
Insert records in the crew_members table for vessel "Pacific Voyager" with the following data: ('John Doe', 'Male', 'Captain', '2022-04-01')
CREATE TABLE crew_members (full_name VARCHAR(255),gender VARCHAR(10),position VARCHAR(255),hire_date DATE,vessel_name VARCHAR(255));
INSERT INTO crew_members (full_name, gender, position, hire_date, vessel_name) VALUES ('John Doe', 'Male', 'Captain', '2022-04-01', 'Pacific Voyager');
Identify the number of unique policy issues reported by citizens in 'CityB' and 'CityC' in 2021, excluding duplicates.
CREATE TABLE CityB_Issues (ID INT,Year INT,Issue VARCHAR(50)); INSERT INTO CityB_Issues (ID,Year,Issue) VALUES (1,2021,'Potholes'),(2,2021,'Street Lighting'); CREATE TABLE CityC_Issues (ID INT,Year INT,Issue VARCHAR(50)); INSERT INTO CityC_Issues (ID,Year,Issue) VALUES (3,2021,'Potholes'),(4,2021,'Garbage Collection');
SELECT COUNT(DISTINCT Issue) FROM (SELECT Issue FROM CityB_Issues WHERE Year = 2021 UNION SELECT Issue FROM CityC_Issues WHERE Year = 2021) AS CombinedIssues;
How many traditional art forms are there in Asia, and what are their names and origins?
CREATE TABLE Arts (id INT,name TEXT,origin TEXT); INSERT INTO Arts (id,name,origin) VALUES (1,'Kabuki','Japan'); CREATE TABLE Locations (id INT,art_id INT,continent TEXT); INSERT INTO Locations (id,art_id,continent) VALUES (1,1,'Asia');
SELECT A.name, A.origin, COUNT(*) FROM Arts A INNER JOIN Locations L ON A.id = L.art_id WHERE L.continent = 'Asia' GROUP BY A.name, A.origin;
How many auto shows have been held in Canada since the year 2000?
CREATE TABLE AutoShow (id INT,name VARCHAR(100),year INT,location VARCHAR(50));
SELECT COUNT(*) FROM AutoShow WHERE year >= 2000 AND location = 'Canada';
Delete the records in the expedition_researchers table for the expedition 'Expedition2'.
CREATE TABLE expeditions (id INT PRIMARY KEY,name VARCHAR(50),location VARCHAR(50),start_date DATE,end_date DATE); CREATE TABLE researchers (id INT PRIMARY KEY,name VARCHAR(50),affiliation VARCHAR(50)); CREATE TABLE expedition_researchers AS SELECT NULL id,e.name AS expedition,r.name AS researcher FROM expeditions e JOIN researchers r ON TRUE WHERE e.location = r.affiliation;
DELETE FROM expedition_researchers WHERE expedition = 'Expedition2';
Retrieve all records from the student_demographics table
CREATE TABLE student_demographics (id INT PRIMARY KEY,name VARCHAR(255),age INT,gender VARCHAR(50),ethnicity VARCHAR(50));
SELECT * FROM student_demographics;
What is the maximum budget for a resilience project in the 'Transport' sector?
CREATE TABLE ResilienceProjects (ProjectID int,Sector varchar(10),Budget int); INSERT INTO ResilienceProjects (ProjectID,Sector,Budget) VALUES (1,'Water',500000),(2,'Transport',800000),(3,'Energy',600000);
SELECT MAX(Budget) AS MaxBudget FROM ResilienceProjects WHERE Sector = 'Transport';
How many building permits were issued in Texas between January 2020 and June 2020?
CREATE TABLE Building_Permits (Permit_ID INT,Permit_Date DATE,Location TEXT,Type TEXT); INSERT INTO Building_Permits (Permit_ID,Permit_Date,Location,Type) VALUES (1,'2020-01-01','Texas','Residential'),(2,'2020-02-15','California','Commercial'),(3,'2020-04-20','Texas','Residential'),(4,'2020-06-30','Texas','Commercial');
SELECT COUNT(*) FROM Building_Permits WHERE Location = 'Texas' AND Permit_Date BETWEEN '2020-01-01' AND '2020-06-30';
Create a table named 'client_demographics'
CREATE TABLE client_demographics (client_id INT PRIMARY KEY,gender VARCHAR(10),income DECIMAL(10,2));
CREATE TABLE client_demographics (client_id INT PRIMARY KEY, gender VARCHAR(10), income DECIMAL(10,2));
What is the average amount of gold extracted annually from each mine in Australia?
CREATE TABLE Extraction (ExtractionID INT,MineID INT,Year INT,Material VARCHAR(255),Amount INT); INSERT INTO Extraction (ExtractionID,MineID,Year,Material,Amount) VALUES (1,1,2019,'Gold',100); INSERT INTO Extraction (ExtractionID,MineID,Year,Material,Amount) VALUES (2,1,2018,'Gold',110); INSERT INTO Extraction (ExtractionID,MineID,Year,Material,Amount) VALUES (3,2,2019,'Silver',120); INSERT INTO Extraction (ExtractionID,MineID,Year,Material,Amount) VALUES (4,2,2018,'Silver',130); INSERT INTO Extraction (ExtractionID,MineID,Year,Material,Amount) VALUES (5,3,2019,'Gold',140); INSERT INTO Extraction (ExtractionID,MineID,Year,Material,Amount) VALUES (6,3,2018,'Gold',150);
SELECT AVG(e.Amount) as AvgAnnualGoldExtraction FROM Extraction e INNER JOIN Mines m ON e.MineID = m.MineID WHERE m.Country = 'Australia' AND e.Material = 'Gold' GROUP BY e.MineID;
What is the maximum claim amount for policyholders in the state of New York?
CREATE TABLE policyholders (id INT,name VARCHAR(100),city VARCHAR(50),state VARCHAR(20)); CREATE TABLE claims (id INT,policyholder_id INT,amount DECIMAL(10,2)); INSERT INTO policyholders (id,name,city,state) VALUES (1,'Sarah Lee','New York','NY'),(2,'Tom Chen','Buffalo','NY'); INSERT INTO claims (id,policyholder_id,amount) VALUES (1,1,1500.00),(2,1,1000.00),(3,2,500.00);
SELECT MAX(claims.amount) FROM claims JOIN policyholders ON claims.policyholder_id = policyholders.id WHERE policyholders.state = 'NY';
How many incidents were reported for VesselB in the last year?
CREATE TABLE incidents(id INT,vessel_id INT,incident_date DATE); INSERT INTO incidents VALUES (1,2,'2021-09-15'),(2,2,'2022-02-03');
SELECT COUNT(*) FROM incidents WHERE vessel_id = 2 AND incident_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) AND CURRENT_DATE;
What is the total ad spend per advertiser for the month of July 2022?
CREATE TABLE advertisers (advertiser_id INT,advertiser_name VARCHAR(50),spend DECIMAL(10,2),spend_date DATE); INSERT INTO advertisers VALUES (304,'Advertiser G',4000,'2022-07-01'),(305,'Advertiser H',6000,'2022-07-05'),(306,'Advertiser I',8000,'2022-07-10');
SELECT advertiser_name, SUM(spend) as total_spend FROM advertisers WHERE MONTH(spend_date) = 7 AND YEAR(spend_date) = 2022 GROUP BY advertiser_name;
Determine the difference between the average wholesale price and average retail price per gram for each strain of cannabis flower.
CREATE TABLE Wholesale_Prices (Wholesale_Price_ID INT,Strain TEXT,Wholesale_Price DECIMAL); INSERT INTO Wholesale_Prices (Wholesale_Price_ID,Strain,Wholesale_Price) VALUES (1,'Sour Diesel',4.00);
SELECT Wholesale_Prices.Strain, AVG(Wholesale_Price) as Avg_Wholesale_Price, AVG(Retail_Price) as Avg_Retail_Price, AVG(Retail_Price) - AVG(Wholesale_Price) as Price_Difference FROM Wholesale_Prices JOIN Sales ON Wholesale_Prices.Strain = Sales.Strain GROUP BY Wholesale_Prices.Strain;
Display the number of community education programs for each month in the year 2020.
CREATE TABLE education_programs (program_date DATE,program_type VARCHAR(50));
SELECT EXTRACT(MONTH FROM program_date) as month, COUNT(*) as num_programs FROM education_programs WHERE EXTRACT(YEAR FROM program_date) = 2020 GROUP BY month;
What is the average funding amount for biotech startups in the Bay Area?
CREATE TABLE startups (id INT,name VARCHAR(50),location VARCHAR(50),funding FLOAT); INSERT INTO startups (id,name,location,funding) VALUES (1,'Genetech','San Francisco',12000000); INSERT INTO startups (id,name,location,funding) VALUES (2,'Zymergen','Emeryville',25000000);
SELECT AVG(funding) FROM startups WHERE location = 'Bay Area';
How many community development initiatives were completed in the region of Lombardy between 2015 and 2017?
CREATE TABLE community_development (id INT,region VARCHAR(50),initiative_type VARCHAR(50),cost FLOAT,start_date DATE,end_date DATE); INSERT INTO community_development (id,region,initiative_type,cost,start_date,end_date) VALUES (1,'Lombardy','Community Center',30000.00,'2015-01-01','2015-12-31');
SELECT COUNT(*) FROM community_development WHERE region = 'Lombardy' AND start_date <= '2017-12-31' AND end_date >= '2015-01-01' AND initiative_type = 'Community Center';
What is the local economic impact of sustainable tourism in Rome?
CREATE TABLE local_impact (city TEXT,sustainability_score INT,economic_impact INT); INSERT INTO local_impact (city,sustainability_score,economic_impact) VALUES ('Rome',8,5000000),('Rome',9,6000000);
SELECT economic_impact FROM local_impact WHERE city = 'Rome';
What is the total installed capacity of renewable energy projects in the 'GreenEnergy' schema?
CREATE SCHEMA GreenEnergy; CREATE TABLE RenewableProjects (project_id INT,name VARCHAR(50),location VARCHAR(50),installed_capacity FLOAT); INSERT INTO RenewableProjects (project_id,name,location,installed_capacity) VALUES (1,'Solar Farm A','City A',5000.0),(2,'Wind Farm B','City B',7500.0);
SELECT SUM(installed_capacity) FROM GreenEnergy.RenewableProjects;
What is the percentage of women in the workforce of each mining operation?
CREATE TABLE workforce (id INT,mining_operation_id INT,gender VARCHAR(50),role VARCHAR(50)); INSERT INTO workforce (id,mining_operation_id,gender,role) VALUES (1,1,'Female','Engineer'); INSERT INTO workforce (id,mining_operation_id,gender,role) VALUES (2,1,'Male','Manager'); INSERT INTO workforce (id,mining_operation_id,gender,role) VALUES (3,2,'Male','Engineer'); INSERT INTO workforce (id,mining_operation_id,gender,role) VALUES (4,2,'Female','Manager');
SELECT mining_operation_id, ROUND(100.0 * SUM(CASE WHEN gender = 'Female' THEN 1 ELSE 0 END) / COUNT(*), 2) as percentage FROM workforce GROUP BY mining_operation_id;
How many users have a body fat percentage less than 15% and weigh more than 200 pounds?
CREATE TABLE Members (id INT,gender VARCHAR(10),membershipLength INT,joinDate DATE); CREATE TABLE BodyMetrics (id INT,memberId INT,bodyFatPercentage DECIMAL(3,2),weight DECIMAL(5,2)); INSERT INTO Members (id,gender,membershipLength,joinDate) VALUES (1,'Female',12,'2020-01-01'),(2,'Male',6,'2019-07-15'),(3,'Female',24,'2018-01-01'); INSERT INTO BodyMetrics (id,memberId,bodyFatPercentage,weight) VALUES (1,1,0.18,135.5),(2,1,0.19,138.0),(3,2,0.15,180.0),(4,2,0.16,182.5),(5,3,0.17,210.0),(6,3,0.18,215.0);
SELECT COUNT(*) FROM BodyMetrics JOIN Members ON BodyMetrics.memberId = Members.id WHERE bodyFatPercentage < 0.15 AND weight > 200.0;
What is the total network investment for each region in the past year?
CREATE TABLE network_investments (investment_id INT,investment_date DATE,region VARCHAR(50),amount DECIMAL(5,2)); INSERT INTO network_investments (investment_id,investment_date,region,amount) VALUES (1,'2022-02-01','North',50000.00),(2,'2022-03-14','South',40000.00),(3,'2022-01-22','East',35000.00),(4,'2022-04-05','West',60000.00),(5,'2022-05-10','North',75000.00);
SELECT region, SUM(amount) as total_investment FROM network_investments WHERE investment_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY region;
What is the percentage of employees in each sector who are members of a union in the 'labor_rights' schema?
CREATE SCHEMA labor_rights; CREATE TABLE employees (id INT,name VARCHAR,sector VARCHAR,union_member BOOLEAN); INSERT INTO employees VALUES (1,'Jane Smith','Tech',TRUE); CREATE TABLE unions (id INT,name VARCHAR,sector VARCHAR); INSERT INTO unions VALUES (1,'Union X','Tech');
SELECT sector, 100.0 * AVG(CASE WHEN union_member THEN 1 ELSE 0 END) AS union_membership_percentage FROM labor_rights.employees JOIN labor_rights.unions ON employees.sector = unions.sector GROUP BY sector;
Find the 2nd most visited destination for each year in the 'visits' table.
CREATE TABLE visits (visit_id INT,destination TEXT,visit_date DATE); INSERT INTO visits (visit_id,destination,visit_date) VALUES (1,'New York','2022-01-01'),(2,'New York','2022-02-01'),(3,'Vancouver','2022-03-01');
SELECT destination, EXTRACT(YEAR FROM visit_date) AS visit_year, RANK() OVER (PARTITION BY EXTRACT(YEAR FROM visit_date) ORDER BY COUNT(*) DESC) AS visit_rank FROM visits GROUP BY destination, EXTRACT(YEAR FROM visit_date) HAVING visit_rank = 2;
What is the total number of players who have played action or adventure games?
CREATE TABLE Action_Players (Player_ID INT,Name VARCHAR(20)); INSERT INTO Action_Players (Player_ID,Name) VALUES (1,'John'),(2,'Sarah'),(3,'Mike'),(4,'David'); CREATE TABLE Adventure_Players (Player_ID INT,Name VARCHAR(20)); INSERT INTO Adventure_Players (Player_ID,Name) VALUES (2,'Sarah'),(3,'Mike'),(4,'David'),(5,'Emma');
SELECT COUNT(*) FROM Action_Players UNION SELECT COUNT(*) FROM Adventure_Players;
What is the total number of unique digital assets with a regulatory status of "partially regulated" in each country?
CREATE TABLE digital_assets_partial (asset_name TEXT,regulatory_status TEXT,country TEXT);
SELECT country, COUNT(DISTINCT asset_name) FROM digital_assets_partial WHERE regulatory_status = 'partially regulated' GROUP BY country;