instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the total amount donated by new and returning donors?
CREATE TABLE DonorTypes (DonorID int,DonorType varchar(10),DonationAmount decimal(10,2)); INSERT INTO DonorTypes (DonorID,DonorType,DonationAmount) VALUES (1,'New',50.00),(2,'Returning',75.00),(3,'New',62.50);
SELECT DonorType, SUM(DonationAmount) AS TotalDonation FROM DonorTypes GROUP BY DonorType;
What is the total donation amount for each year?
CREATE TABLE donations (donation_id INT,donation_amount DECIMAL(10,2),donation_year INT); INSERT INTO donations (donation_id,donation_amount,donation_year) VALUES (1,5000.00,2020),(2,3000.00,2019),(3,7000.00,2020),(4,4000.00,2018); CREATE VIEW yearly_donations AS SELECT donation_year,SUM(donation_amount) AS total_donation_amount FROM donations GROUP BY donation_year;
SELECT * FROM yearly_donations;
How many users have adopted VR technology in India?
CREATE TABLE users_technology (id INT,user_id INT,has_vr BOOLEAN); INSERT INTO users_technology (id,user_id,has_vr) VALUES
SELECT COUNT(DISTINCT user_id) FROM users_technology WHERE has_vr = TRUE
What is the maximum number of games played concurrently by a player, for each platform?
CREATE TABLE PlayerGames (PlayerID INT,Platform VARCHAR(10),MaxGames INT); INSERT INTO PlayerGames (PlayerID,Platform,MaxGames) VALUES (1,'PC',3);
SELECT Platform, MAX(MaxGames) as MaxConcurrentGames FROM PlayerGames GROUP BY Platform;
What is the average temperature in region 'Northwest' for the past week, grouped by day?
CREATE TABLE weather_data (temperature FLOAT,time DATETIME,region VARCHAR(20)); INSERT INTO weather_data (temperature,time,region) VALUES (23.5,'2022-06-01 12:00:00','Northwest');
SELECT DATE(time) as date, AVG(temperature) as avg_temp FROM weather_data WHERE region = 'Northwest' AND time >= DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK) GROUP BY DATE(time)
What is the total number of IoT sensors in Brazil as of today?
CREATE TABLE iot_sensors (id INT,location VARCHAR(50),sensor_type VARCHAR(50),installed_date DATE);
SELECT COUNT(id) FROM iot_sensors WHERE location = 'Brazil' AND installed_date <= CURDATE();
Add a new record to the "PolicyImpact" table
CREATE TABLE PolicyImpact (ID INT,Policy TEXT,Impact TEXT,StartDate DATE,EndDate DATE);
INSERT INTO PolicyImpact (ID, Policy, Impact, StartDate, EndDate) VALUES (3002, 'Community Policing', 'Increase in community trust by 30%', '2021-01-01', '2022-12-31');
What is the maximum co-ownership duration for properties in the neighborhood of 'Chinatown' in San Francisco?'
CREATE TABLE sf_neighborhoods (neighborhood_id INT,name VARCHAR(255),city VARCHAR(255)); INSERT INTO sf_neighborhoods (neighborhood_id,name,city) VALUES (1,'Chinatown','San Francisco'); CREATE TABLE co_ownership (co_ownership_id INT,property_id INT,co_owner_id INT,start_date DATE,end_date DATE); INSERT INTO co_ownership (co_ownership_id,property_id,co_owner_id,start_date,end_date) VALUES (1,1,2,'2010-01-01','2020-01-01'),(2,2,3,'2015-01-01','2022-01-01'); CREATE TABLE properties (property_id INT,city VARCHAR(255)); INSERT INTO properties (property_id,city) VALUES (1,'San Francisco'),(2,'San Francisco');
SELECT MAX(DATEDIFF(end_date, start_date)) as max_duration FROM co_ownership JOIN properties ON co_ownership.property_id = properties.property_id WHERE properties.city = 'San Francisco' AND name = 'Chinatown';
Show the total energy efficiency improvement (in %) for each energy policy in India since 2015
CREATE TABLE india_energy_policies (id INT,policy_name VARCHAR(100),policy_type VARCHAR(50),enactment_date DATE,improvement_percentage FLOAT); INSERT INTO india_energy_policies (id,policy_name,policy_type,enactment_date,improvement_percentage) VALUES (1,'Policy 1','Renewable Energy','2015-07-14',5.0),(2,'Policy 2','Energy Efficiency','2017-02-28',3.5),(3,'Policy 3','Carbon Pricing','2018-11-11',7.0);
SELECT policy_name, improvement_percentage FROM india_energy_policies WHERE enactment_date <= '2015-01-01' AND country = 'India';
What is the combined energy output of all hydro power projects in South America?
CREATE TABLE project_south_america (project_name TEXT,type TEXT,capacity NUMERIC); INSERT INTO project_south_america (project_name,type,capacity) VALUES ('Hydro Dam A','Hydro',15000),('Hydro Dam B','Hydro',16000),('Solar Park C','Solar',5000),('Wind Farm D','Wind',8000);
SELECT SUM(capacity) FROM project_south_america WHERE type = 'Hydro';
What is the total installed capacity of renewable energy projects in the state of Florida, grouped by project type and project location?
CREATE TABLE fl_projects (id INT,project_name VARCHAR(100),state VARCHAR(50),project_type VARCHAR(50),project_location VARCHAR(50),installed_capacity INT); INSERT INTO fl_projects (id,project_name,state,project_type,project_location,installed_capacity) VALUES (1,'FL Project A','Florida','Solar','North Florida',10000),(2,'FL Project B','Florida','Wind','Central Florida',20000);
SELECT project_type, project_location, SUM(installed_capacity) FROM fl_projects WHERE state = 'Florida' GROUP BY project_type, project_location;
How many restaurants serve Mexican food and have a revenue greater than $8000?
CREATE TABLE Restaurants (id INT,name TEXT,type TEXT,revenue FLOAT); INSERT INTO Restaurants (id,name,type,revenue) VALUES (1,'Restaurant A','Italian',5000.00),(2,'Restaurant B','Mexican',8500.00),(3,'Restaurant C','Mexican',7000.00);
SELECT COUNT(*) FROM Restaurants WHERE type = 'Mexican' AND revenue > 8000;
What is the total cost of ingredients for each menu item, including their organic premium?
CREATE TABLE menu_items (item_id INT,item_name VARCHAR(255),base_cost DECIMAL(10,2),organic_premium DECIMAL(10,2)); INSERT INTO menu_items (item_id,item_name,base_cost,organic_premium) VALUES (1,'Bruschetta',5,1),(2,'Spaghetti Bolognese',8,0),(3,'Calamari',7,2),(4,'Lasagna',10,0);
SELECT item_name, base_cost + organic_premium as total_cost FROM menu_items;
Find the number of operational spacecraft manufactured by SpaceX.
CREATE TABLE Spacecrafts (Spacecraft_ID INT,Name VARCHAR(100),Manufacturer VARCHAR(100),Operational BOOLEAN); INSERT INTO Spacecrafts (Spacecraft_ID,Name,Manufacturer,Operational) VALUES (1,'Crew Dragon','SpaceX',TRUE);
SELECT COUNT(*) FROM Spacecrafts WHERE Manufacturer = 'SpaceX' AND Operational = TRUE;
What are the names of space telescopes launched by NASA between 1990 and 2010?
CREATE TABLE SpaceTelescopes (id INT,name VARCHAR(255),country VARCHAR(255),launch_date DATE); INSERT INTO SpaceTelescopes (id,name,country,launch_date) VALUES (1,'Hubble Space Telescope','United States','1990-04-24'); INSERT INTO SpaceTelescopes (id,name,country,launch_date) VALUES (2,'Spitzer Space Telescope','United States','2003-08-25');
SELECT name FROM SpaceTelescopes WHERE country = 'United States' AND launch_date BETWEEN '1990-01-01' AND '2010-12-31' AND type = 'Space Telescope'
What is the earliest launch date of a spacecraft by any agency?
CREATE TABLE space_missions (agency VARCHAR(50),spacecraft VARCHAR(50),launch_date DATE); INSERT INTO space_missions (agency,spacecraft,launch_date) VALUES ('NASA','Explorer 1','1958-01-31'),('Soviet Union','Sputnik 1','1957-10-04'),('ESA','Venera 1','1961-02-12'),('ISRO','Aryabhata','1975-04-19'),('CNSA','Dong Fang Hong 1','1970-04-24');
SELECT MIN(launch_date) FROM space_missions;
What is the maximum height of an astronaut?
CREATE TABLE MedicalProfiles(astronaut_id INT,height INT,weight INT);
SELECT MAX(height) FROM MedicalProfiles;
update the age of the athlete with id 100 in the athletes table
CREATE TABLE athletes (id INT PRIMARY KEY,name VARCHAR(100),age INT,sport VARCHAR(50),team VARCHAR(50));
UPDATE athletes SET age = 26 WHERE id = 100;
Delete all records from the 'routes' table where the 'route_name' is 'Green Line'
CREATE TABLE routes (id INT,route_name VARCHAR(20),agency VARCHAR(20),start_date DATE);
DELETE FROM routes WHERE route_name = 'Green Line';
Find the top 3 most popular garment types sold in the European market.
CREATE TABLE garment_sales (id INT,garment_type VARCHAR(255),region VARCHAR(255),quantity INT); INSERT INTO garment_sales (id,garment_type,region,quantity) VALUES (1,'T-Shirt','Europe',500),(2,'Jeans','Europe',700),(3,'Sweater','Europe',800);
SELECT garment_type, SUM(quantity) as total_quantity FROM garment_sales WHERE region = 'Europe' GROUP BY garment_type ORDER BY total_quantity DESC LIMIT 3;
Identify the top 3 garments by total sales in each region.
CREATE TABLE garment_sales (id INT,garment_id INT,region VARCHAR(20),quantity INT,price DECIMAL(5,2),sale_date DATE);CREATE VIEW top_selling_garments_by_region AS SELECT region,garment_id,SUM(quantity) as total_sold FROM garment_sales GROUP BY region,garment_id;
SELECT region, garment_id, total_sold, RANK() OVER (PARTITION BY region ORDER BY total_sold DESC) as sales_rank FROM top_selling_garments_by_region WHERE sales_rank <= 3;
Update the sustainability_metrics table to reflect the latest CO2 emissions data for garment production in Asia.
CREATE TABLE sustainability_metrics (id INT,region VARCHAR(255),co2_emissions INT); INSERT INTO sustainability_metrics (id,region,co2_emissions) VALUES (1,'South America',130),(2,'Europe',100),(3,'Asia',150);
UPDATE sustainability_metrics SET co2_emissions = 160 WHERE region = 'Asia';
How many claims were processed for each policy type in the Underwriting department in Q3 2022?
CREATE TABLE Claims (ClaimID INT,PolicyType VARCHAR(20),ProcessingDepartment VARCHAR(20),ProcessingDate DATE); INSERT INTO Claims (ClaimID,PolicyType,ProcessingDepartment,ProcessingDate) VALUES (1,'Auto','Underwriting','2022-07-15'),(2,'Home','Claims','2022-06-20'),(3,'Auto','Underwriting','2022-08-01');
SELECT PolicyType, COUNT(*) as TotalClaims FROM Claims WHERE ProcessingDepartment = 'Underwriting' AND ProcessingDate BETWEEN '2022-07-01' AND '2022-09-30' GROUP BY PolicyType;
What is the average claim amount for policyholders with multiple claims in the last 6 months?
CREATE TABLE Claims (ClaimID int,ClaimDate date,ClaimAmount decimal(10,2),PolicyType varchar(50),PolicyholderID int); INSERT INTO Claims (ClaimID,ClaimDate,ClaimAmount,PolicyType,PolicyholderID) VALUES (1,'2022-01-15',4500.00,'Auto',1001),(2,'2022-02-03',3200.00,'Home',1002),(3,'2022-03-17',5700.00,'Auto',1001),(4,'2022-04-01',6100.00,'Life',1004),(5,'2022-05-12',4200.00,'Auto',1001),(6,'2022-06-20',3800.00,'Home',1002); CREATE TABLE Policyholders (PolicyholderID int,FirstName varchar(50),LastName varchar(50)); INSERT INTO Policyholders (PolicyholderID,FirstName,LastName) VALUES (1001,'Mohammed','Ali'),(1002,'Sarah','Smith'),(1003,'Pedro','Gonzales'),(1004,'Anna','Jensen'),(1005,'Hiroshi','Tanaka');
SELECT PolicyholderID, AVG(ClaimAmount) AS AvgClaimAmount FROM (SELECT PolicyholderID, ClaimAmount FROM Claims WHERE ClaimDate >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH) GROUP BY PolicyholderID, ClaimAmount HAVING COUNT(DISTINCT PolicyholderID) > 1) AS Subquery GROUP BY PolicyholderID;
What is the maximum claim amount for pet insurance policies?
CREATE TABLE PetPolicies (PolicyID int,ClaimAmount decimal); INSERT INTO PetPolicies (PolicyID,ClaimAmount) VALUES (1,100); INSERT INTO PetPolicies (PolicyID,ClaimAmount) VALUES (2,200); INSERT INTO PetPolicies (PolicyID,ClaimAmount) VALUES (3,300);
SELECT MAX(ClaimAmount) FROM PetPolicies;
Delete all records of workplaces in the state of Georgia.
CREATE TABLE workplaces (id INT,name TEXT,state TEXT); INSERT INTO workplaces (id,name,state) VALUES (1,'GHI Company','Georgia');
DELETE FROM workplaces WHERE state = 'Georgia';
List unions with more than 3 workplaces and their average rates.
CREATE TABLE union_workplaces (id INT,union_id INT,workplace_name VARCHAR(50),injury_rate DECIMAL(5,2)); INSERT INTO union_workplaces (id,union_id,workplace_name,injury_rate) VALUES (1,1001,'ABC Factory',6.5),(2,1001,'DEF Warehouse',2.9),(3,1002,'XYZ Inc',3.2),(4,1003,'LMN Corp',9.1),(5,1003,'OPQ Office',4.7);
SELECT union_id, AVG(injury_rate) as avg_injury_rate FROM union_workplaces GROUP BY union_id HAVING COUNT(*) > 3;
What is the maximum number of union members in workplaces that have successful collective bargaining in the tech sector?
CREATE TABLE workplaces (id INT,name TEXT,location TEXT,sector TEXT,total_employees INT,union_members INT,successful_cb BOOLEAN,cb_year INT);
SELECT MAX(union_members) FROM workplaces WHERE successful_cb = TRUE AND sector = 'tech';
What is the percentage of union members in the construction sector who are people of color?
CREATE TABLE construction (id INT,union_member BOOLEAN,race TEXT); INSERT INTO construction (id,union_member,race) VALUES (1,TRUE,'White'),(2,TRUE,'Black'),(3,FALSE,'Hispanic'),(4,TRUE,'Asian'),(5,FALSE,'White');
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM construction WHERE union_member = TRUE)) FROM construction WHERE race IN ('Black', 'Hispanic', 'Asian');
Delete all vehicles with a safety rating below 4.0 in the "vehicle_safety" table.
CREATE TABLE vehicles (id INT,type VARCHAR(50)); CREATE TABLE vehicle_safety (id INT,vehicle_id INT,safety_rating FLOAT); INSERT INTO vehicles VALUES (1,'sedan'); INSERT INTO vehicle_safety VALUES (1,1,4.5); INSERT INTO vehicle_safety VALUES (2,1,3.5);
DELETE FROM vehicle_safety WHERE safety_rating < 4.0;
Delete records from the safety_records table where the status is 'Failed' and the inspection_date is after '2022-06-01'
CREATE TABLE safety_records (id INT PRIMARY KEY,vessel_id INT,inspection_date DATE,status VARCHAR(255)); INSERT INTO safety_records (id,vessel_id,inspection_date,status) VALUES (1,1,'2022-03-01','Passed'),(2,2,'2022-06-03','Failed'),(3,3,'2021-03-01','Passed');
DELETE FROM safety_records WHERE status = 'Failed' AND inspection_date > '2022-06-01';
Which vessels have traveled between the Port of Santos and the Port of Hong Kong, and what is the median travel time (in days)?
CREATE TABLE Routes (route_id INT,departure_port VARCHAR(20),arrival_port VARCHAR(20)); CREATE TABLE VesselTravel (vessel_id INT,route INT,departure_date DATE,travel_time INT); INSERT INTO Routes (route_id,departure_port,arrival_port) VALUES (1,'Los Angeles','Tokyo'),(2,'Rotterdam','New York'),(3,'Santos','Hong Kong'); INSERT INTO VesselTravel (vessel_id,route,departure_date,travel_time) VALUES (1,1,'2021-01-01',14),(2,1,'2021-02-01',15),(3,1,'2021-03-01',16),(4,3,'2021-01-01',20),(5,3,'2021-02-01',21),(6,3,'2021-03-01',22),(7,3,'2021-04-01',19),(8,3,'2021-05-01',20),(9,3,'2021-06-01',23);
SELECT vessel_id, MEDIAN(travel_time) as median_travel_time FROM VesselTravel WHERE route = 3 GROUP BY vessel_id;
What is the distribution of visitor age groups across museums?
CREATE TABLE MuseumVisitors (visitor_id INT,museum_id INT,age INT); INSERT INTO MuseumVisitors (visitor_id,museum_id,age) VALUES (1,100,25),(2,101,30),(3,102,45);
SELECT museum_id, CASE WHEN age BETWEEN 0 AND 17 THEN 'Children' WHEN age BETWEEN 18 AND 35 THEN 'Young Adults' WHEN age BETWEEN 36 AND 55 THEN 'Adults' ELSE 'Seniors' END as age_group, COUNT(*) as visitor_count FROM MuseumVisitors GROUP BY museum_id, age_group;
Update recycling initiative records in Paris in 2022
CREATE TABLE recycling_initiatives (year INT,city VARCHAR(255),initiative_type VARCHAR(255)); INSERT INTO recycling_initiatives (year,city,initiative_type) VALUES (2022,'Paris','Plastic Recycling'),(2022,'Paris','Paper Recycling'),(2022,'Paris','Glass Recycling');
UPDATE recycling_initiatives SET initiative_type = 'Composting' WHERE year = 2022 AND city = 'Paris';
What is the total landfill capacity in Japan and China?
CREATE TABLE LandfillCapacity (country VARCHAR(255),capacity INT); INSERT INTO LandfillCapacity (country,capacity) VALUES ('Japan',850000),('China',2300000);
SELECT SUM(capacity) FROM LandfillCapacity WHERE country IN ('Japan', 'China')
Find the number of wastewater treatment plants in California and Texas.
CREATE TABLE treatment_plants (state TEXT,num_plants INT); INSERT INTO treatment_plants (state,num_plants) VALUES ('California',321),('Texas',456),('New York',123),('Florida',345);
SELECT num_plants FROM treatment_plants WHERE state IN ('California', 'Texas')
Show the water usage distribution by city in 'RegionE'
CREATE TABLE City_Water_Usage (id INT,city VARCHAR(20),water_usage FLOAT,region VARCHAR(20)); INSERT INTO City_Water_Usage (id,city,water_usage,region) VALUES (1,'City1',12.5,'RegionE'),(2,'City2',10.0,'RegionE'),(3,'City3',15.0,'RegionF');
SELECT city, water_usage FROM City_Water_Usage WHERE region = 'RegionE' ORDER BY water_usage;
Calculate the maximum duration of any workout for users aged 40-50.
CREATE TABLE workouts (id INT,user_id INT,duration INT,date DATE);
SELECT MAX(duration) FROM workouts w JOIN users u ON w.user_id = u.id WHERE u.age BETWEEN 40 AND 50;
What is the average safety score for AI models in the healthcare industry?
CREATE TABLE ai_models (model_name TEXT,industry TEXT,safety_score FLOAT); INSERT INTO ai_models (model_name,industry,safety_score) VALUES ('ModelA','Healthcare',0.85),('ModelB','Finance',0.92),('ModelC','Retail',0.78),('ModelD','Healthcare',0.95);
SELECT industry, AVG(safety_score) FROM ai_models WHERE industry = 'Healthcare' GROUP BY industry;
How many community development initiatives were started but not completed in Rwanda between 2017 and 2019?
CREATE TABLE CommunityDevelopment (id INT,country VARCHAR(50),initiative VARCHAR(50),start_date DATE,completion_date DATE); INSERT INTO CommunityDevelopment (id,country,initiative,start_date,completion_date) VALUES (1,'Rwanda','Library Construction','2017-12-15','2018-06-30'),(2,'Rwanda','Water Purification Plant','2018-07-22','2019-02-28'),(3,'Ghana','Community Health Center','2019-04-01','2020-01-01');
SELECT COUNT(*) FROM CommunityDevelopment WHERE country = 'Rwanda' AND start_date BETWEEN '2017-01-01' AND '2019-12-31' AND completion_date IS NULL;
Insert new records into the 'rural_infrastructure' table for a new water supply project in Kenya
CREATE TABLE rural_infrastructure (id INT,project_name VARCHAR(255),country VARCHAR(255),sector VARCHAR(255));
INSERT INTO rural_infrastructure (id, project_name, country, sector) VALUES (1, 'Water Supply Project', 'Kenya', 'Water & Sanitation');
What is the total number of agricultural innovation metrics reported in Brazil?
CREATE TABLE Metrics (id INT,metric_id INT,metric_type VARCHAR(20),country VARCHAR(20),report_date DATE); INSERT INTO Metrics (id,metric_id,metric_type,country,report_date) VALUES (1,5001,'Agricultural Innovation','Brazil','2020-01-01'),(2,5002,'Economic Diversification','Brazil','2020-02-15'),(3,5003,'Agricultural Innovation','Brazil','2020-03-31');
SELECT COUNT(*) FROM Metrics WHERE metric_type = 'Agricultural Innovation' AND country = 'Brazil';
Which rural infrastructure projects were completed before 2020 and their respective completion dates in the 'rural_infrastructure' table?
CREATE TABLE rural_infrastructure (id INT,project_name VARCHAR(50),location VARCHAR(50),budget DECIMAL(10,2),completion_date DATE); INSERT INTO rural_infrastructure (id,project_name,location,budget,completion_date) VALUES (1,'Water Supply','Village A',25000.00,'2018-05-15'),(2,'Road Construction','Village B',50000.00,'2019-08-22'),(3,'Electricity Supply','Village A',30000.00,'2021-03-30');
SELECT project_name, completion_date FROM rural_infrastructure WHERE completion_date < '2020-01-01';
How many times did the program "Dance Performances" occur in each borough of New York City in 2019?
CREATE TABLE Events (EventID int,EventName varchar(50),Borough varchar(50),Year int); INSERT INTO Events (EventID,EventName,Borough,Year) VALUES (1,'Dance Performances','Manhattan',2019),(2,'Music Concert','Brooklyn',2019);
SELECT Borough, COUNT(*) as EventCount FROM Events WHERE EventName = 'Dance Performances' AND Year = 2019 GROUP BY Borough;
Insert a new record for a TV show with title "ShowC", genre "Drama", and release year 2020.
CREATE TABLE tv_shows (id INT,title VARCHAR(100),genre VARCHAR(50),release_year INT);
INSERT INTO tv_shows (title, genre, release_year) VALUES ('ShowC', 'Drama', 2020);
What is the minimum rating for movies released in 2021 and rated PG-13?
CREATE TABLE MovieRatings (movie_id INT,release_date DATE,rating DECIMAL(3,2),rating_category VARCHAR(255)); INSERT INTO MovieRatings (movie_id,release_date,rating,rating_category) VALUES (1,'2021-01-01',7.2,'PG-13'),(2,'2020-05-15',8.8,'G'),(3,'2021-09-22',6.5,'PG-13');
SELECT MIN(rating) FROM MovieRatings WHERE release_date >= '2021-01-01' AND release_date < '2022-01-01' AND rating_category = 'PG-13';
List the approved clinical trials for drug 'DrugX' in 2019?
CREATE TABLE clinical_trials_data (drug_name VARCHAR(50),approval_year INT,approval_status VARCHAR(10)); INSERT INTO clinical_trials_data (drug_name,approval_year,approval_status) VALUES ('DrugX',2019,'Approved'),('DrugY',2018,'Rejected');
SELECT drug_name FROM clinical_trials_data WHERE drug_name = 'DrugX' AND approval_year = 2019 AND approval_status = 'Approved';
What is the average duration of clinical trials for a specific drug category?
CREATE TABLE trial_duration (drug_category VARCHAR(255),trial_duration INT);
SELECT AVG(trial_duration) FROM trial_duration WHERE drug_category = 'CategoryZ';
What is the most common age range for HIV patients in South Africa?
CREATE TABLE hiv_patients (id INT,patient_id INT,age INT,gender VARCHAR(10),location VARCHAR(50)); INSERT INTO hiv_patients (id,patient_id,age,gender,location) VALUES (1,601,28,'Male','South Africa'); INSERT INTO hiv_patients (id,patient_id,age,gender,location) VALUES (2,602,45,'Female','South Africa');
SELECT age DIV 10 * 10 AS age_range, COUNT(*) FROM hiv_patients WHERE location = 'South Africa' GROUP BY age_range ORDER BY COUNT(*) DESC LIMIT 1;
Calculate the percentage of inclusion efforts in the "Midwest" region.
CREATE TABLE inclusion_efforts (effort_id INT,region VARCHAR(10),type VARCHAR(20)); INSERT INTO inclusion_efforts (effort_id,region,type) VALUES (1,'Northeast','Training'),(2,'Southeast','Hiring'),(3,'Midwest','Accessibility'),(4,'Northeast','Events');
SELECT 100.0 * COUNT(*) / (SELECT COUNT(*) FROM inclusion_efforts) AS percentage FROM inclusion_efforts WHERE region = 'Midwest';
What is the maximum depth of any trench in the Southern Ocean?
CREATE TABLE oceanography (id INT,location VARCHAR(255),depth INT); INSERT INTO oceanography (id,location,depth) VALUES (1,'Southern Ocean Trench',8000);
SELECT MAX(depth) FROM oceanography WHERE location = 'Southern Ocean Trench';
Which ingredients are used in products that are not cruelty-free?
CREATE TABLE ingredients (ingredient_id INT PRIMARY KEY,ingredient_name VARCHAR(50)); CREATE TABLE products (product_id INT PRIMARY KEY,cruelty_free BOOLEAN); CREATE TABLE product_ingredients (product_id INT,ingredient_id INT,PRIMARY KEY (product_id,ingredient_id),FOREIGN KEY (product_id) REFERENCES products(product_id),FOREIGN KEY (ingredient_id) REFERENCES ingredients(ingredient_id)); INSERT INTO ingredients (ingredient_id,ingredient_name) VALUES (1,'Palm Oil'),(2,'Parabens'),(3,'Sulfates'); INSERT INTO products (product_id,cruelty_free) VALUES (1,false),(2,true),(3,false),(4,true),(5,false); INSERT INTO product_ingredients (product_id,ingredient_id) VALUES (1,1),(1,2),(2,3),(3,1),(4,2),(5,1);
SELECT ingredient_name FROM ingredients JOIN product_ingredients ON ingredients.ingredient_id = product_ingredients.ingredient_id JOIN products ON product_ingredients.product_id = products.product_id WHERE products.cruelty_free = false;
How many veterans are employed by ABC company in California?
CREATE TABLE veteran_employment (id INT,company VARCHAR(50),state VARCHAR(50),num_veterans INT); INSERT INTO veteran_employment (id,company,state,num_veterans) VALUES (1,'ABC','California',1000); INSERT INTO veteran_employment (id,company,state,num_veterans) VALUES (2,'XYZ','California',1500);
SELECT SUM(num_veterans) FROM veteran_employment WHERE company = 'ABC' AND state = 'California';
What is the average balance for customers in the West region?
CREATE TABLE customers (id INT,name VARCHAR(50),region VARCHAR(50),balance DECIMAL(10,2)); INSERT INTO customers (id,name,region,balance) VALUES (1,'John Doe','West',5000.00),(2,'Jane Smith','West',7000.00),(3,'Alice Johnson','East',6000.00);
SELECT AVG(balance) FROM customers WHERE region = 'West';
What is the maximum transaction amount for clients in the Americas region?
CREATE TABLE clients (client_id INT,region VARCHAR(20)); INSERT INTO clients (client_id,region) VALUES (1,'North America'),(2,'South America'),(3,'Europe'); CREATE TABLE transactions (transaction_id INT,client_id INT,amount DECIMAL(10,2)); INSERT INTO transactions (transaction_id,client_id,amount) VALUES (1,1,500.00),(2,1,1000.00),(3,2,250.00),(4,3,10000.00);
SELECT MAX(amount) FROM transactions JOIN clients ON transactions.client_id = clients.client_id WHERE clients.region = 'North America';
Update the compliance status for a specific regulatory compliance record in the "regulatory_compliance" table
CREATE TABLE regulatory_compliance (id INT PRIMARY KEY,vessel_id INT,regulation_id INT,compliance_date DATE,is_compliant BOOLEAN);
UPDATE regulatory_compliance SET is_compliant = false WHERE id = 2;
How many employees have completed workforce development training in the textile sector in Bangladesh?
CREATE TABLE employees (employee_id INT,employee_name VARCHAR(255),sector VARCHAR(255),country VARCHAR(255)); INSERT INTO employees (employee_id,employee_name,sector,country) VALUES (1,'John Doe','Textile','Bangladesh'),(2,'Jane Smith','Manufacturing','United States'),(3,'Bob Johnson','Textile','Bangladesh'); CREATE TABLE trainings (training_id INT,training_name VARCHAR(255),sector VARCHAR(255)); INSERT INTO trainings (training_id,training_name,sector) VALUES (1,'Weaving Training','Textile'),(2,'Dyeing Training','Textile'),(3,'Metalworking Training','Manufacturing');
SELECT COUNT(DISTINCT e.employee_id) as num_employees FROM employees e JOIN trainings t ON e.sector = t.sector WHERE e.country = 'Bangladesh' AND t.training_name = 'Weaving Training';
What is the average salary of workers in the 'manufacturing' industry across all regions?
CREATE TABLE regions (region_id INT,region_name TEXT); CREATE TABLE workers (worker_id INT,worker_name TEXT,salary INT,region_id INT); CREATE TABLE industries (industry_id INT,industry_name TEXT); INSERT INTO regions VALUES (1,'North'),(2,'South'),(3,'East'),(4,'West'); INSERT INTO workers VALUES (1,'John',50000,1),(2,'Jane',55000,1),(3,'Bob',60000,2),(4,'Alice',58000,3); INSERT INTO industries VALUES (1,'manufacturing'),(2,'technology'),(3,'finance'),(4,'retail');
SELECT AVG(salary) FROM workers INNER JOIN industries ON workers.region_id = regions.region_id WHERE industries.industry_name = 'manufacturing';
What is the average budget allocated for cybersecurity operations in the last 3 years?
CREATE TABLE budget (fiscal_year INT,amount INT,category TEXT);INSERT INTO budget (fiscal_year,amount,category) VALUES (2019,5000000,'Cybersecurity');INSERT INTO budget (fiscal_year,amount,category) VALUES (2020,5500000,'Cybersecurity');INSERT INTO budget (fiscal_year,amount,category) VALUES (2021,6000000,'Cybersecurity');
SELECT AVG(amount) FROM budget WHERE category = 'Cybersecurity' AND fiscal_year BETWEEN 2019 AND 2021;
What is the distribution of lifelong learning course enrollments by age group, in total?
CREATE TABLE lifelong_learning (student_id INT,age_group VARCHAR(255),course_id INT); CREATE TABLE courses (course_id INT,course_name VARCHAR(255));
SELECT l.age_group, COUNT(l.course_id) FROM lifelong_learning l INNER JOIN courses c ON l.course_id = c.course_id GROUP BY l.age_group;
Which students have improved their mental health score the most?
CREATE TABLE student_mental_health (student_id INT,score INT,year INT); INSERT INTO student_mental_health (student_id,score,year) VALUES (1,80,2021),(1,85,2022),(2,70,2021),(2,75,2022),(3,90,2021),(3,95,2022);
SELECT student_id, MAX(score) - MIN(score) as score_improvement FROM student_mental_health GROUP BY student_id ORDER BY score_improvement DESC;
What is the average salary of employees in each position?
CREATE TABLE Employees (EmployeeID INT,Name VARCHAR(50),Department VARCHAR(50),Position VARCHAR(50),Salary FLOAT); INSERT INTO Employees (EmployeeID,Name,Department,Position,Salary) VALUES (1,'John Doe','IT','Developer',75000.00),(2,'Jane Smith','IT','Developer',80000.00),(3,'Alice Johnson','Marketing','Marketing Specialist',60000.00),(4,'Bob Brown','HR','HR Specialist',65000.00);
SELECT Position, AVG(Salary) FROM Employees GROUP BY Position;
What is the total energy produced by renewable sources in Germany for the year 2020?
CREATE TABLE renewable_energy (country VARCHAR(255),year INT,energy_produced FLOAT); INSERT INTO renewable_energy (country,year,energy_produced) VALUES ('Germany',2020,123.45);
SELECT SUM(energy_produced) FROM renewable_energy WHERE country = 'Germany' AND year = 2020;
How many games have been played in the 'NHL' league since the year 2000?
CREATE TABLE games (game_id INT,team1 VARCHAR(50),team2 VARCHAR(50),league VARCHAR(50),season INT,year INT); INSERT INTO games (game_id,team1,team2,league,season,year) VALUES (1,'Sharks','Kings','NHL',2000,2000);
SELECT COUNT(*) FROM games WHERE league = 'NHL' AND year >= 2000;
What is the number of fans engaging with each team's social media on a daily basis?
CREATE TABLE social_media (team VARCHAR(255),date DATE,engagement INT); INSERT INTO social_media (team,date,engagement) VALUES ('Bears','2022-01-01',5000),('Bears','2022-01-02',6000),('Bills','2022-01-01',3000),('Bills','2022-01-02',4000);
SELECT team, AVG(engagement) FROM social_media GROUP BY team;
What is the minimum number of team members in 'disaster_response_teams' table?
CREATE TABLE disaster_response_teams (id INT,team_name VARCHAR(255),team_size INT); INSERT INTO disaster_response_teams (id,team_name,team_size) VALUES (1,'Team A',5),(2,'Team B',10),(3,'Team C',15);
SELECT MIN(team_size) as min_team_size FROM disaster_response_teams;
What is the total amount of funds raised by NGOs for disaster relief efforts in Africa in the year 2019?
CREATE TABLE ngo_funds(id INT,ngo_name TEXT,region TEXT,amount FLOAT,year INT); INSERT INTO ngo_funds(id,ngo_name,region,amount,year) VALUES (1,'Oxfam','Africa',500000.00,2019),(2,'Save the Children','Africa',600000.00,2019),(3,'World Vision','South Asia',700000.00,2019);
SELECT SUM(amount) FROM ngo_funds WHERE region = 'Africa' AND year = 2019;
Which region has the highest average shelter capacity?
CREATE TABLE region (region_id INT,name VARCHAR(255)); INSERT INTO region (region_id,name) VALUES (1,'west_africa'),(2,'east_asia'),(3,'south_america'); CREATE TABLE shelter (shelter_id INT,name VARCHAR(255),region_id INT,capacity INT); INSERT INTO shelter (shelter_id,name,region_id,capacity) VALUES (1,'Shelter1',1,50),(2,'Shelter2',1,75),(3,'Shelter3',2,100),(4,'Shelter4',3,150);
SELECT region_id, AVG(capacity) as avg_capacity FROM shelter GROUP BY region_id ORDER BY avg_capacity DESC LIMIT 1;
What is the minimum price of devices produced by companies located in underrepresented communities?
CREATE TABLE Devices (id INT,name VARCHAR(50),company VARCHAR(50),price DECIMAL(5,2),community VARCHAR(50)); INSERT INTO Devices (id,name,company,price,community) VALUES (1,'Phone X','ABC Tech',200.00,'Minority Owned Business'),(2,'Tablet Y','XYZ Enterprises',350.00,'Women Owned Business'),(3,'Laptop Z','Tech for Good',700.00,'Non-Profit');
SELECT MIN(price) FROM Devices WHERE community IN ('Minority Owned Business', 'Women Owned Business', 'Non-Profit');
What is the maximum number of likes received by a single post in India?
CREATE TABLE post_likes (post_id INT,user_id INT,country VARCHAR(2)); INSERT INTO post_likes (post_id,user_id,country) VALUES (1,1,'US'),(1,2,'IN'),(2,3,'CA'),(2,4,'IN'),(3,5,'IN');
SELECT MAX(likes) FROM (SELECT post_id, COUNT(*) AS likes FROM post_likes WHERE country = 'IN' GROUP BY post_id) AS post_likes_in;
How many size 16 customers have made a purchase in the last month?
CREATE TABLE customers(id INT PRIMARY KEY,size INT,last_purchase DATE); INSERT INTO customers(id,size,last_purchase) VALUES (1,16,'2022-01-15'),(2,12,'2022-02-01'),(3,16,'2022-02-10');
SELECT COUNT(*) FROM customers WHERE size = 16 AND last_purchase >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH);
What is the total quantity of sustainable fabric used by each supplier?
CREATE TABLE FabricSuppliers (SupplierID INT,SupplierName TEXT,FabricType TEXT,Quantity INT,IsSustainable BOOLEAN); INSERT INTO FabricSuppliers (SupplierID,SupplierName,FabricType,Quantity,IsSustainable) VALUES (1,'SupplierA','Cotton',500,true),(2,'SupplierB','Polyester',300,false),(3,'SupplierC','Wool',150,true);
SELECT SupplierName, SUM(Quantity) as TotalQuantity FROM FabricSuppliers WHERE IsSustainable = true GROUP BY SupplierName;
Insert new socially responsible lending data into SociallyResponsibleLending table.
CREATE TABLE SociallyResponsibleLending (lendingID INT,lenderName VARCHAR(50),borrowerName VARCHAR(50),amountLent DECIMAL(10,2),interestRate DECIMAL(4,2),lendingDate DATE); INSERT INTO SociallyResponsibleLending (lendingID,lenderName,borrowerName,amountLent,interestRate,lendingDate) VALUES (1,'GreenLenders','EcoFriendlyInc',25000.00,2.50,'2022-02-01'),(2,'FairFinance','HelpingHands',10000.00,1.00,'2022-02-02');
INSERT INTO SociallyResponsibleLending (lendingID, lenderName, borrowerName, amountLent, interestRate, lendingDate) VALUES (3, 'CommunityBank', 'LocalCharity', 15000.00, 1.50, '2022-02-03');
Identify bioprocess engineering papers published in 2021
CREATE TABLE papers (id INT,title VARCHAR(50),year INT,authors VARCHAR(50),publication VARCHAR(50)); INSERT INTO papers (id,title,year,authors,publication) VALUES (1,'Paper A',2021,'John Doe','Journal of Bioprocessing'); INSERT INTO papers (id,title,year,authors,publication) VALUES (2,'Paper B',2020,'Jane Smith','Journal of Genetic Engineering');
SELECT * FROM papers WHERE year = 2021 AND domain = 'Bioprocess Engineering';
What is the minimum salary of city council members in the city of Chicago?
CREATE TABLE council_members (id INT,city VARCHAR,job_title VARCHAR,salary FLOAT); INSERT INTO council_members (id,city,job_title,salary) VALUES (1,'Chicago','City Council Member',90000.00);
SELECT MIN(salary) FROM council_members WHERE city = 'Chicago' AND job_title = 'City Council Member';
What is the total revenue generated from virtual tours in the United Kingdom?
CREATE TABLE virtual_tours (tour_id INT,name TEXT,country TEXT,revenue FLOAT); INSERT INTO virtual_tours VALUES (1,'Virtual London Tour','United Kingdom',60000),(2,'British Museum Tour','United Kingdom',40000);
SELECT SUM(revenue) FROM virtual_tours WHERE country = 'United Kingdom';
What is the average number of listings per hotel in 'Americas'?
CREATE TABLE ota_hotels (hotel_id INT,hotel_name TEXT,country TEXT,listings INT); INSERT INTO ota_hotels (hotel_id,hotel_name,country,listings) VALUES (1,'Hotel Paraiso','Mexico',550),(2,'Plaza Hotel','USA',700),(3,'Fazenda Resort','Brazil',850),(4,'Boutique Hotel','Canada',600);
SELECT region, AVG(listings) FROM ota_hotels WHERE region = 'Americas' GROUP BY region;
What is the percentage of hotels in Europe that offer virtual tours?
CREATE TABLE hotel_features (hotel_id INT,hotel_name TEXT,virtual_tour INT,country TEXT); INSERT INTO hotel_features (hotel_id,hotel_name,virtual_tour,country) VALUES (1,'Hotel A',1,'France'),(2,'Hotel B',0,'Germany'),(3,'Hotel C',1,'Italy'),(4,'Hotel D',0,'France'),(5,'Hotel E',1,'Spain');
SELECT (COUNT(*) FILTER (WHERE virtual_tour = 1) * 100.0 / COUNT(*)) AS percentage FROM hotel_features WHERE country = 'Europe';
What is the percentage of hotels in Paris that have adopted AI technology?
CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,city TEXT,ai_adoption BOOLEAN); INSERT INTO hotels (hotel_id,hotel_name,city,ai_adoption) VALUES (1,'Hotel X','Paris',TRUE),(2,'Hotel Y','London',FALSE);
SELECT (COUNT(CASE WHEN ai_adoption = TRUE THEN 1 END) * 100.0 / COUNT(ai_adoption)) AS percentage FROM hotels WHERE city = 'Paris';
What is the species name and corresponding management location for species with a population between 300 and 600?
CREATE TABLE Species (id INT PRIMARY KEY,name VARCHAR(255),population INT); CREATE TABLE ResourceManagement (id INT PRIMARY KEY,location VARCHAR(255),manager VARCHAR(255));
SELECT Species.name, ResourceManagement.location FROM Species INNER JOIN ResourceManagement ON 1=1 WHERE Species.population BETWEEN 300 AND 600;
What is the maximum age of patients who have a primary diagnosis of PTSD and have attended at least one therapy session?
CREATE TABLE patients (id INT,name TEXT,age INT,condition TEXT,therapy_sessions INT);
SELECT MAX(age) FROM patients WHERE condition = 'PTSD' AND therapy_sessions > 0;
What is the total cost of projects with 'Solar' as project_name in the 'renewable_energy' table?
CREATE TABLE renewable_energy (id INT,project_name VARCHAR(50),location VARCHAR(50),cost FLOAT); INSERT INTO renewable_energy (id,project_name,location,cost) VALUES (1,'Solar Farm','Miami',10000000); INSERT INTO renewable_energy (id,project_name,location,cost) VALUES (2,'Wind Farm','Seattle',6000000);
SELECT SUM(cost) FROM renewable_energy WHERE project_name LIKE '%Solar%';
Show travel advisory updates for Southeast Asian countries in the last month
CREATE TABLE travel_advisories (id INT,country VARCHAR(255),advisory_date DATE,advisory_update TEXT); INSERT INTO travel_advisories (id,country,advisory_date,advisory_update) VALUES (1,'Thailand','2023-02-10','Protests in Bangkok...'),(2,'Vietnam','2023-02-15','New entry requirements...'),(3,'Cambodia','2023-01-20','Typhoon warnings...'),(4,'Indonesia','2023-01-05','Volcano eruption...');
SELECT country, advisory_update FROM travel_advisories WHERE country IN ('Thailand', 'Vietnam', 'Cambodia', 'Indonesia', 'Laos', 'Malaysia', 'Myanmar', 'Philippines', 'Singapore', 'Brunei') AND advisory_date >= DATEADD(day, -30, CURRENT_DATE);
What is the average hotel price for beachfront hotels in Mexico?
CREATE TABLE hotels (hotel_id INT,name TEXT,country TEXT,has_beachfront BOOLEAN,price INT); INSERT INTO hotels (hotel_id,name,country,has_beachfront,price) VALUES (1,'Beach Palace','Mexico',true,200),(2,'Green Valley','USA',false,150);
SELECT AVG(price) FROM hotels WHERE has_beachfront = true AND country = 'Mexico';
What was the total number of tourists who visited Asian museums in 2019 and 2020?
CREATE TABLE museum_visitors (country VARCHAR(20),museum VARCHAR(50),visitors INT,year INT); INSERT INTO museum_visitors (country,museum,visitors,year) VALUES ('Japan','Tokyo National Museum',3000000,2019),('China','Forbidden City',4000000,2019),('Japan','Tokyo National Museum',2500000,2020),('China','Forbidden City',3000000,2020);
SELECT year, SUM(visitors) as total_visitors FROM museum_visitors WHERE country IN ('Japan', 'China') GROUP BY year;
What is the total population of marine species in the Southern hemisphere?
CREATE TABLE marine_species (id INT,name TEXT,population INT,location TEXT); INSERT INTO marine_species (id,name,population,location) VALUES (1,'Dolphin',50,'Atlantic'); INSERT INTO marine_species (id,name,population,location) VALUES (2,'Turtle',25,'Atlantic'); INSERT INTO marine_species (id,name,population,location) VALUES (3,'Shark',100,'Pacific'); INSERT INTO marine_species (id,name,population,location) VALUES (4,'Whale',200,'Antarctic');
SELECT SUM(population) FROM marine_species WHERE location LIKE 'S%';
What is the average salary of full-time employees in the Mining 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','Mining',75000.00),(2,'Jane Smith','HR',60000.00);
SELECT AVG(salary) FROM Employees WHERE department = 'Mining' AND employment_status = 'Full-time';
What is the percentage of female workers in the mining industry by role?
CREATE TABLE workers (id INT,role TEXT,gender TEXT); INSERT INTO workers (id,role,gender) VALUES (1,'Manager','Male'),(2,'Engineer','Female'),(3,'Operator','Male'),(4,'Manager','Female'),(5,'Engineer','Male'),(6,'Operator','Female');
SELECT role, (COUNT(*) FILTER (WHERE gender = 'Female')) * 100.0 / COUNT(*) FROM workers GROUP BY role;
How many unique volunteers worked on projects in each cause area?
CREATE TABLE volunteers (id INT,name VARCHAR(30),cause_area VARCHAR(20)); INSERT INTO volunteers (id,name,cause_area) VALUES (1,'Bob','children'),(2,'Alice','children'),(3,'Charlie','health');
SELECT cause_area, COUNT(DISTINCT name) FROM volunteers GROUP BY cause_area;
Insert a new record for a volunteer who has provided their email address
CREATE TABLE volunteer (vol_id INT,vol_name TEXT,org_id INT,vol_email TEXT);
INSERT INTO volunteer (vol_id, vol_name, org_id, vol_email) VALUES (4, 'David', 1, '[email protected]');
What is the total amount donated by small donors in the 'animals' cause area?
CREATE TABLE donations (id INT,donor_size VARCHAR(10),cause_area VARCHAR(20),amount INT); INSERT INTO donations (id,donor_size,cause_area,amount) VALUES (1,'small','animals',500);
SELECT SUM(amount) FROM donations WHERE donor_size = 'small' AND cause_area = 'animals';
What is the total donation amount for the 'Food' department in the 'Donations' table?
CREATE TABLE Donations (id INT,department VARCHAR(20),amount FLOAT); INSERT INTO Donations (id,department,amount) VALUES (1,'Animals',500.00),(2,'Food',700.00);
SELECT SUM(amount) FROM Donations WHERE department = 'Food'
How many public schools and public libraries exist in total, in the 'CityData' schema's 'CityEducation' and 'CityLibrary' tables?
CREATE SCHEMA CityData; CREATE TABLE CityEducation (Name varchar(255),Type varchar(255)); INSERT INTO CityEducation (Name,Type) VALUES ('SchoolA','Public'),('SchoolB','Public'),('SchoolC','Private'); CREATE TABLE CityLibrary (Name varchar(255),Type varchar(255)); INSERT INTO CityLibrary (Name,Type) VALUES ('LibraryA','Public'),('LibraryB','Public'),('LibraryC','Private');
SELECT COUNT(*) FROM CityData.CityEducation WHERE Type = 'Public' UNION ALL SELECT COUNT(*) FROM CityData.CityLibrary WHERE Type = 'Public';
List all public transportation routes in the city of San Francisco and their respective budgets for 2023, ordered by budget amount in ascending order.
CREATE TABLE routes (city varchar(50),year int,route varchar(50),budget int); INSERT INTO routes (city,year,route,budget) VALUES ('San Francisco',2023,'Route A',3000000),('San Francisco',2023,'Route B',2000000),('San Francisco',2023,'Route C',1000000),('San Francisco',2023,'Route D',4000000);
SELECT route, budget FROM routes WHERE city = 'San Francisco' AND year = 2023 ORDER BY budget ASC;
What is the ratio of affordable to total housing units for each community type?
CREATE TABLE Community_Types (name VARCHAR(50),affordable_housing INT,total_housing INT); INSERT INTO Community_Types (name,affordable_housing,total_housing) VALUES ('Urban',2000,5000),('Suburban',1500,4000),('Rural',500,2000);
SELECT name, affordable_housing/total_housing AS ratio FROM Community_Types;
What is the maximum CO2 emission reduction achieved by any carbon offset program in the industry sector?
CREATE TABLE co2_emission_reduction (id INT,sector VARCHAR(50),co2_emission_reduction_tonnes INT); INSERT INTO co2_emission_reduction (id,sector,co2_emission_reduction_tonnes) VALUES (1,'Industry',12000),(2,'Energy',15000),(3,'Transportation',10000),(4,'Industry',18000),(5,'Industry',13000);
SELECT MAX(co2_emission_reduction_tonnes) FROM co2_emission_reduction WHERE sector = 'Industry';
Count the number of restaurants with sustainable sourcing practices
CREATE TABLE restaurants (id INT,name VARCHAR(255),sustainable_sourcing BOOLEAN); INSERT INTO restaurants (id,name,sustainable_sourcing) VALUES (1,'Restaurant A',TRUE),(2,'Restaurant B',FALSE),(3,'Restaurant C',TRUE),(4,'Restaurant D',FALSE);
SELECT COUNT(*) FROM restaurants WHERE sustainable_sourcing = TRUE;
What is the total revenue for each restaurant in the 'fine_dining' category?
CREATE TABLE restaurants (id INT,name TEXT,category TEXT); INSERT INTO restaurants (id,name,category) VALUES (1,'Restaurant A','fine_dining'),(2,'Restaurant B','casual_dining'); CREATE TABLE revenue (restaurant_id INT,revenue INT); INSERT INTO revenue (restaurant_id,revenue) VALUES (1,5000),(1,6000),(2,3000);
SELECT r.name, SUM(re.revenue) as total_revenue FROM restaurants r JOIN revenue re ON r.id = re.restaurant_id WHERE r.category = 'fine_dining' GROUP BY r.name;
Which menu items have had their prices changed more than once?
CREATE TABLE menu_items (item_name VARCHAR(255),price DECIMAL(10,2),last_updated TIMESTAMP); INSERT INTO menu_items (item_name,price,last_updated) VALUES ('Pizza',12.99,'2022-01-01 10:00:00'),('Burrito',9.99,'2022-01-01 11:00:00'),('Pizza',13.99,'2022-02-01 10:00:00');
SELECT item_name FROM menu_items GROUP BY item_name HAVING COUNT(DISTINCT last_updated) > 1;
Update 'payment_status' in 'payments' table for payment_id '12345' to 'Completed'
CREATE TABLE payments (payment_id INT,payment_status VARCHAR(50));
UPDATE payments SET payment_status = 'Completed' WHERE payment_id = 12345;