instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the minimum cargo weight for vessels in the Indian Ocean?
CREATE TABLE Vessels (VesselID varchar(10),CargoWeight int,Region varchar(10)); INSERT INTO Vessels (VesselID,CargoWeight,Region) VALUES ('VesselO',1200,'Indian Ocean'),('VesselP',1800,'Indian Ocean'),('VesselQ',1500,'Atlantic');
SELECT MIN(CargoWeight) FROM Vessels WHERE Region = 'Indian Ocean';
Delete records from 'RuralHealthFacilities' table where total beds are below 30.
CREATE TABLE RuralHealthFacilities (FacilityID INT,Name VARCHAR(50),Address VARCHAR(100),TotalBeds INT); INSERT INTO RuralHealthFacilities (FacilityID,Name,Address,TotalBeds) VALUES (1,'Rural Community Hospital','1234 Rural Rd',50),(2,'Small Rural Clinic','8899 Smalltown Ln',25);
DELETE FROM RuralHealthFacilities WHERE TotalBeds < 30;
Show the number of research grants awarded each year for the Physics department
CREATE TABLE Grant (id INT,department_id INT,year INT,amount INT); INSERT INTO Grant (id,department_id,year,amount) VALUES (1,1,2018,50000),(2,1,2019,75000),(3,2,2018,60000),(4,3,2017,40000);
SELECT YEAR(g.year) as year, SUM(g.amount) as total_grants FROM Grant g WHERE g.department_id = (SELECT id FROM Department WHERE name = 'Physics') GROUP BY YEAR(g.year);
What is the maximum wind speed in field H in the past week?
CREATE TABLE Wind (field VARCHAR(50),date DATE,wind_speed FLOAT); INSERT INTO Wind (field,date,wind_speed) VALUES ('Field H','2022-06-01',12.1),('Field H','2022-06-02',15.6),('Field H','2022-06-03',10.3);
SELECT MAX(wind_speed) FROM Wind WHERE field = 'Field H' AND date >= DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY);
How many home runs did Hank Aaron hit at home during his career and what is the average number of home runs he hit per game at home?
CREATE TABLE homeruns (player VARCHAR(50),team VARCHAR(50),location VARCHAR(50),homeruns INTEGER); INSERT INTO homeruns (player,team,location,homeruns) VALUES ('Hank Aaron','Atlanta Braves','Home',225),('Hank Aaron','Milwaukee Brewers','Home',83);
SELECT COUNT(*) AS home_runs, AVG(homeruns) AS avg_home_runs_per_game FROM homeruns WHERE player = 'Hank Aaron' AND location = 'Home';
What is the minimum and maximum budget allocated for transportation services?
CREATE TABLE TransportationBudget (Service VARCHAR(25),Budget INT); INSERT INTO TransportationBudget (Service,Budget) VALUES ('Bus',3000000),('Train',5000000),('Subway',4000000);
SELECT MIN(Budget), MAX(Budget) FROM TransportationBudget;
What is the total duration of all electronic songs?
CREATE TABLE songs (id INT,title TEXT,length FLOAT,genre TEXT); INSERT INTO songs (id,title,length,genre) VALUES (1,'Song1',3.1,'electronic'),(2,'Song2',4.3,'dubstep'),(3,'Song3',4.1,'house'),(4,'Song4',2.9,'techno'),(5,'Song5',5.5,'drum and bass'),(6,'Song6',6.4,'trance');
SELECT SUM(length) FROM songs WHERE genre IN ('electronic', 'dubstep', 'house', 'techno', 'drum and bass', 'trance');
What is the number of AI safety incidents per quarter in North America?
CREATE TABLE ai_safety_incidents_na (id INT,incident_name VARCHAR(255),incident_date DATE,region VARCHAR(255));
SELECT region, DATEPART(YEAR, incident_date) as year, DATEPART(QUARTER, incident_date) as quarter, COUNT(*) FROM ai_safety_incidents_na WHERE region = 'North America' GROUP BY region, DATEPART(YEAR, incident_date), DATEPART(QUARTER, incident_date);
What is the minimum number of fans for each team in the 'events' table?
CREATE TABLE events (event_id INT,team_id INT,num_fans INT);
SELECT team_id, MIN(num_fans) FROM events GROUP BY team_id;
What is the average temperature in Arizona in the past week?
CREATE TABLE Weather (location VARCHAR(50),temperature INT,timestamp TIMESTAMP);
SELECT AVG(temperature) FROM Weather WHERE location = 'Arizona' AND timestamp > NOW() - INTERVAL '1 week';
What are the names of all vessels that have visited ports in Oceania but not in Australia?
CREATE TABLE Vessels (VesselID INT,Name VARCHAR(255),Type VARCHAR(255),Flag VARCHAR(255)); CREATE TABLE PortVisits (VisitID INT,VesselID INT,Port VARCHAR(255),VisitDate DATE,Country VARCHAR(255)); INSERT INTO Vessels (VesselID,Name,Type,Flag) VALUES (1,'Island Explorer','Cruise','Bahamas'); INSERT INTO PortVisits (VisitID,VesselID,Port,VisitDate,Country) VALUES (1,1,'Auckland','2022-03-14','New Zealand'),(2,1,'Sydney','2022-04-01','Australia');
SELECT Vessels.Name FROM Vessels LEFT JOIN PortVisits ON Vessels.VesselID = PortVisits.VesselID WHERE PortVisits.Country NOT LIKE 'Australia%' AND Vessels.Flag LIKE 'Oceania%' GROUP BY Vessels.Name;
What is the percentage of players from Africa who have played the game "Starship Showdown"?
CREATE TABLE Players (PlayerID INT,PlayerAge INT,GameName VARCHAR(20),Country VARCHAR(20)); INSERT INTO Players (PlayerID,PlayerAge,GameName,Country) VALUES (1,25,'Galactic Gold','United States'); INSERT INTO Players (PlayerID,PlayerAge,GameName,Country) VALUES (2,32,'Starship Showdown','Egypt'); INSERT INTO Players (PlayerID,PlayerAge,GameName,Country) VALUES (3,28,'Cosmic Conquerors','Japan');
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Players WHERE Country LIKE 'Africa%')) as Percentage FROM Players WHERE GameName = 'Starship Showdown' AND Country LIKE 'Africa%';
What is the total revenue for each sport?
CREATE TABLE sports (sport_id INT,sport_name VARCHAR(50)); CREATE TABLE tickets (ticket_id INT,purchase_date DATE,revenue DECIMAL(10,2),quantity INT,sport_id INT);
SELECT s.sport_name, SUM(t.revenue) as total_revenue FROM sports s JOIN tickets t ON s.sport_id = t.sport_id GROUP BY s.sport_name;
What is the total number of cases handled by each restorative justice center and the average duration of cases?
CREATE TABLE restorative_justice_center (case_id INT,center_name VARCHAR(50),case_duration INT); INSERT INTO restorative_justice_center VALUES (1,'Center A',30),(2,'Center B',45),(3,'Center C',60),(4,'Center A',45);
SELECT center_name, COUNT(*) AS cases_handled, AVG(case_duration) AS avg_duration FROM restorative_justice_center GROUP BY center_name;
What was the average CO2 emissions per capita in China in 2015 and 2020?
CREATE TABLE co2_emissions (country VARCHAR(255),year INT,population INT,emissions FLOAT); INSERT INTO co2_emissions (country,year,population,emissions) VALUES ('China',2015,1367000000,10000),('China',2015,1367000000,10500),('China',2020,1439000000,12000),('China',2020,1439000000,12500);
SELECT AVG(emissions/population) as avg_emissions_per_capita, year FROM co2_emissions WHERE country = 'China' GROUP BY year;
What is the total quantity of each inventory category?
CREATE TABLE inventory (inventory_id INT,inventory_category VARCHAR(50),quantity INT); INSERT INTO inventory (inventory_id,inventory_category,quantity) VALUES (1,'Produce',500),(2,'Meat',1000),(3,'Dairy',750);
SELECT inventory_category, SUM(quantity) FROM inventory GROUP BY inventory_category;
What was the total amount of funds spent by UN agencies in Somalia in 2016?
CREATE TABLE un_agencies (agency_name VARCHAR(255),country VARCHAR(255),funds_spent DECIMAL(10,2),funds_date DATE); INSERT INTO un_agencies (agency_name,country,funds_spent,funds_date) VALUES ('UNA','Somalia',60000,'2016-02-25'),('UNB','Somalia',70000,'2016-08-17'),('UNC','Somalia',80000,'2016-11-29');
SELECT SUM(funds_spent) FROM un_agencies WHERE country = 'Somalia' AND YEAR(funds_date) = 2016;
Update 'brand' table, setting 'sustainability_rating' as 'high' if 'market_value' is above 1000000000
CREATE TABLE brand (id INT PRIMARY KEY,name VARCHAR(50),market_value INT,sustainability_rating VARCHAR(10)); INSERT INTO brand (id,name,market_value,sustainability_rating) VALUES (1,'Brand A',1200000000,'medium'),(2,'Brand B',800000000,'low'),(3,'Brand C',1500000000,'medium');
UPDATE brand SET sustainability_rating = 'high' WHERE market_value > 1000000000;
How many public works projects were completed in the city of Toronto, Canada between 2015 and 2020?
CREATE TABLE PublicWorksProjects (id INT,city VARCHAR(50),country VARCHAR(50),completion_year INT);
SELECT COUNT(*) FROM PublicWorksProjects WHERE city = 'Toronto' AND country = 'Canada' AND completion_year BETWEEN 2015 AND 2020;
Update the founder_gender to 'Non-binary' for the startup with name 'TechForAll'.
CREATE TABLE companies (id INT,name TEXT,industry TEXT,founding_year INT,founder_gender TEXT); INSERT INTO companies (id,name,industry,founding_year,founder_gender) VALUES (1,'TechFem','Technology',2015,'Female'),(2,'GreenInno','GreenTech',2018,'Male'),(3,'TechForAll','Technology',2017,'Female');
UPDATE companies SET founder_gender = 'Non-binary' WHERE name = 'TechForAll';
What is the average budget allocated per school district in the state of New York?
CREATE TABLE school_districts (district_id INT,district_name TEXT,state TEXT,budget FLOAT); INSERT INTO school_districts (district_id,district_name,state,budget) VALUES (1,'Albany','New York',2000000),(2,'Buffalo','New York',2500000),(3,'New York City','New York',12000000);
SELECT AVG(budget) FROM school_districts WHERE state = 'New York';
How many unique donors made donations in each quarter of 2020?
CREATE TABLE Donors (DonorID INT,DonationDate DATE); INSERT INTO Donors (DonorID,DonationDate) VALUES (1,'2020-01-01'),(2,'2020-04-15'),(3,'2020-07-01');
SELECT DATE_FORMAT(DonationDate, '%Y-%V') as 'Year-Quarter', COUNT(DISTINCT DonorID) as 'Unique Donors' FROM Donors WHERE YEAR(DonationDate) = 2020 GROUP BY 'Year-Quarter';
What is the total number of patients served by rural health centers in South America and how many of these centers serve more than 10000 patients?
CREATE TABLE rural_health_centers (center_id INT,center_name VARCHAR(100),country VARCHAR(50),num_patients INT); INSERT INTO rural_health_centers (center_id,center_name,country,num_patients) VALUES (1,'Center A','Brazil',15000),(2,'Center B','Brazil',12000),(3,'Center C','Argentina',8000),(4,'Center D','Argentina',11000);
SELECT COUNT(*) AS total_patients_served, COUNT(*) FILTER (WHERE num_patients > 10000) AS centers_with_more_than_10000_patients FROM rural_health_centers WHERE country IN (SELECT name FROM countries WHERE continent = 'South America');
What is the most common type of disaster in the state of Florida?
CREATE TABLE public.disaster_types (id SERIAL PRIMARY KEY,state VARCHAR(255),disaster_type VARCHAR(255),count INTEGER); INSERT INTO public.disaster_types (state,disaster_type,count) VALUES ('Florida','Hurricane',2000),('Florida','Tornado',1500),('Florida','Hurricane',2500);
SELECT disaster_type FROM public.disaster_types WHERE state = 'Florida' GROUP BY disaster_type ORDER BY COUNT(*) DESC LIMIT 1;
What was the average citizen feedback score for healthcare services in 2021?
CREATE TABLE CitizenFeedback (Year INT,Service TEXT,Score INT); INSERT INTO CitizenFeedback (Year,Service,Score) VALUES (2021,'Healthcare',8),(2021,'Healthcare',9),(2021,'Healthcare',7),(2021,'Healthcare',8);
SELECT AVG(Score) FROM CitizenFeedback WHERE Service = 'Healthcare' AND Year = 2021;
What is the average salary of employees in the finance department?
CREATE TABLE Employees (id INT,name VARCHAR(50),department VARCHAR(50),salary DECIMAL(10,2)); INSERT INTO Employees (id,name,department,salary) VALUES (1,'John Doe','Finance',50000.00); INSERT INTO Employees (id,name,department,salary) VALUES (2,'Jane Smith','IT',60000.00); INSERT INTO Employees (id,name,department,salary) VALUES (3,'Alice Johnson','Finance',55000.00);
SELECT AVG(salary) AS avg_salary FROM Employees WHERE department = 'Finance';
What is the average runtime for TV shows by genre?
CREATE TABLE tv_shows_extended (id INT,title VARCHAR(255),genre VARCHAR(255),runtime INT); INSERT INTO tv_shows_extended (id,title,genre,runtime) VALUES (1,'Show1','Action',60),(2,'Show2','Comedy',30),(3,'Show3','Drama',45);
SELECT genre, AVG(runtime) as avg_runtime FROM tv_shows_extended GROUP BY genre;
Update the record in the 'patients' table for a patient from Chicago, IL to show they now live in Atlanta, GA
CREATE TABLE patients (patient_id INT,first_name VARCHAR(50),last_name VARCHAR(50),city VARCHAR(50),state VARCHAR(2));
UPDATE patients SET city = 'Atlanta', state = 'GA' WHERE patient_id = 5678 AND city = 'Chicago' AND state = 'IL';
Delete the record for Twitter engagement metrics from the social_media_engagement table
CREATE TABLE social_media_engagement (id INT PRIMARY KEY,platform VARCHAR(15),likes INT,shares INT,comments INT);
DELETE FROM social_media_engagement WHERE platform = 'Twitter';
What is the average population of 'clinics' in the 'health_facilities' table?
CREATE TABLE health_facilities (facility_id INT,name VARCHAR(50),type VARCHAR(50),population INT,city VARCHAR(50),state VARCHAR(50));
SELECT AVG(population) FROM health_facilities WHERE type = 'clinic';
Insert a new record with id 50, title "Machine Learning for Journalists", publication date 2022-10-01, and author id 10 into the "articles" table
CREATE TABLE articles (article_id INT,title VARCHAR(255),publication_date DATE,author_id INT);
INSERT INTO articles (article_id, title, publication_date, author_id) VALUES (50, 'Machine Learning for Journalists', '2022-10-01', 10);
What is the minimum water usage by residential users in the state of New Mexico?
CREATE TABLE residential_users (id INT,state VARCHAR(20),water_usage FLOAT); INSERT INTO residential_users (id,state,water_usage) VALUES (1,'New Mexico',7.5),(2,'New Mexico',9.6),(3,'California',12.2);
SELECT MIN(water_usage) FROM residential_users WHERE state = 'New Mexico';
Select all records from trends table where forecast='Winter' and trend_name like '%Jacket%'
CREATE TABLE trends (id INT,trend_name VARCHAR(50),region VARCHAR(50),forecast VARCHAR(50),popularity INT);
SELECT * FROM trends WHERE forecast = 'Winter' AND trend_name LIKE '%Jacket%';
Identify the number of citizen complaints received for each public service in the city of Chicago.
CREATE SCHEMA gov_data;CREATE TABLE gov_data.citizen_complaints (city VARCHAR(20),service VARCHAR(20),complaint INT); INSERT INTO gov_data.citizen_complaints (city,service,complaint) VALUES ('Chicago','Public Transportation',100),('Chicago','Street Cleaning',50),('Chicago','Parks',75);
SELECT service, SUM(complaint) as total_complaints FROM gov_data.citizen_complaints WHERE city = 'Chicago' GROUP BY service;
Show the number of visitors per month for Africa.
CREATE TABLE continent_visitors (id INT,continent VARCHAR(50),visit_month DATE,visitors INT); INSERT INTO continent_visitors (id,continent,visit_month,visitors) VALUES (1,'Africa','2022-01-01',5000000); INSERT INTO continent_visitors (id,continent,visit_month,visitors) VALUES (2,'Africa','2022-02-01',4500000);
SELECT visit_month, visitors, COUNT(visitors) OVER (PARTITION BY continent ORDER BY visit_month) as monthly_visitors FROM continent_visitors WHERE continent = 'Africa';
Calculate the total value of defense contracts with the US Government in the last quarter?
CREATE TABLE defense_contracts (id INT,contract_name VARCHAR(50),contract_value DECIMAL(10,2),contract_date DATE,contract_party VARCHAR(50)); INSERT INTO defense_contracts (id,contract_name,contract_value,contract_date,contract_party) VALUES (1,'Contract A',1000000,'2022-01-01','US Government'),(2,'Contract B',2000000,'2021-06-01','Foreign Government');
SELECT SUM(contract_value) FROM defense_contracts WHERE contract_party = 'US Government' AND contract_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH);
Which technology for social good projects were implemented in the Asia-Pacific region?
CREATE TABLE project (project_id INT,project_name TEXT,region TEXT); INSERT INTO project (project_id,project_name,region) VALUES (1,'ProjectAA','Asia-Pacific'),(2,'ProjectAB','Europe'),(3,'ProjectAC','Asia-Pacific');
SELECT project_name FROM project WHERE region = 'Asia-Pacific';
How many orders were shipped to each country in the 'warehouse_shipments' table, ordered by the most shipped orders?
CREATE TABLE warehouse_shipments AS SELECT order_id,'USA' as country FROM orders WHERE shipping_address LIKE '123%' UNION ALL SELECT order_id,'Canada' as country FROM orders WHERE shipping_address LIKE '456%' UNION ALL SELECT order_id,'Mexico' as country FROM orders WHERE shipping_address LIKE '789%';
SELECT country, COUNT(order_id) as orders_shipped FROM warehouse_shipments GROUP BY country ORDER BY orders_shipped DESC;
What are the names and positions of intelligence agents who work for the internal_intelligence agency and have a budget greater than 50000, listed in the intelligence_agents table?
CREATE TABLE intelligence_agents (id INT,name VARCHAR(50),position VARCHAR(50),agency VARCHAR(50),budget INT);
SELECT name, position FROM intelligence_agents WHERE agency = 'internal_intelligence' AND budget > 50000;
Identify the community engagement programs in countries with the highest number of endangered languages.
CREATE TABLE programs (name VARCHAR(255),location VARCHAR(255),endangered_languages INTEGER); INSERT INTO programs (name,location,endangered_languages) VALUES ('Program A','Country A',10); INSERT INTO programs (name,location,endangered_languages) VALUES ('Program B','Country B',5);
SELECT programs.name, programs.location FROM programs JOIN (SELECT location, MAX(endangered_languages) AS max_endangered_languages FROM programs GROUP BY location) AS max_endangered_locations ON programs.location = max_endangered_locations.location AND programs.endangered_languages = max_endangered_locations.max_endangered_languages;
What is the percentage of funding for exhibitions and performances from government sources?
CREATE TABLE funding_sources (id INT,name VARCHAR(255),type VARCHAR(255)); INSERT INTO funding_sources (id,name,type) VALUES (1,'Government','government'),(2,'Private','private'),(3,'Corporate','corporate'); CREATE TABLE exhibitions (id INT,name VARCHAR(255),funding_source_id INT); INSERT INTO exhibitions (id,name,funding_source_id) VALUES (1,'ExhibitionA',1),(2,'ExhibitionB',2),(3,'ExhibitionC',3); CREATE TABLE performances (id INT,name VARCHAR(255),funding_source_id INT); INSERT INTO performances (id,name,funding_source_id) VALUES (1,'PerformanceA',1),(2,'PerformanceB',2),(3,'PerformanceC',3);
SELECT (COUNT(CASE WHEN f.name = 'Government' AND t.type IN ('exhibitions', 'performances') THEN 1 END) * 100.0 / COUNT(*)) AS government_funding_percentage FROM funding_sources f JOIN exhibitions e ON f.id = e.funding_source_id JOIN performances p ON f.id = p.funding_source_id JOIN (VALUES ('exhibitions'), ('performances')) AS t(type) ON TRUE
What is the total revenue for each store?
CREATE TABLE sales (sale_id INT,product_id INT,store_id INT,sale_date DATE,revenue DECIMAL(5,2)); INSERT INTO sales (sale_id,product_id,store_id,sale_date,revenue) VALUES (1,1,1,'2022-01-01',200.00),(2,2,1,'2022-01-02',50.00),(3,1,2,'2022-01-03',300.00); CREATE TABLE stores (store_id INT,store_name VARCHAR(255)); INSERT INTO stores (store_id,store_name) VALUES (1,'Store A'),(2,'Store B');
SELECT s.store_name, SUM(sales.revenue) as total_revenue FROM sales JOIN stores s ON sales.store_id = s.store_id GROUP BY s.store_id;
Identify the number of hospitals and clinics in indigenous communities, and calculate the ratio.
CREATE TABLE areas (name text,type text,community text); INSERT INTO areas VALUES ('Urban','CityA',''),('Suburban','CityB',''),('Rural','CityC','Indigenous'),('Rural','CityD','Indigenous'); CREATE TABLE hospitals (name text,area_type text); INSERT INTO hospitals VALUES ('Hospital1','Urban'),('Hospital2','Rural'),('Hospital3','Suburban'); CREATE TABLE clinics (name text,area_type text); INSERT INTO clinics VALUES ('Clinic1','Urban'),('Clinic2','Rural'),('Clinic3','Suburban');
SELECT (SELECT COUNT(*) FROM hospitals WHERE area_type = 'Rural' AND communities = 'Indigenous') / COUNT(DISTINCT areas.type) AS indigenous_hospital_ratio, (SELECT COUNT(*) FROM clinics WHERE area_type = 'Rural' AND communities = 'Indigenous') / COUNT(DISTINCT areas.type) AS indigenous_clinic_ratio
How many marine species are there in each habitat?
CREATE TABLE marine_species (name TEXT,habitat TEXT); INSERT INTO marine_species (name,habitat) VALUES ('Coral','Coral Reef'),('Clownfish','Coral Reef'),('Sea Star','Coral Reef'),('Tuna','Open Ocean'),('Blue Whale','Open Ocean'),('Dolphin','Open Ocean'),('Sea Turtle','Beaches'),('Swordfish','Open Ocean');
SELECT habitat, COUNT(*) FROM marine_species GROUP BY habitat;
What is the average transaction value for the 'Currency Exchange' industry sector in the 'XRP' digital asset in Q3 2021?
CREATE TABLE avg_transaction_value (industry_sector VARCHAR(10),asset_name VARCHAR(10),quarter INT,avg_transaction_value INT); INSERT INTO avg_transaction_value (industry_sector,asset_name,quarter,avg_transaction_value) VALUES ('Currency Exchange','BTC',1,1000),('Currency Exchange','BTC',2,1500),('Currency Exchange','BTC',3,2000),('Currency Exchange','ETH',1,2500),('Currency Exchange','ETH',2,3000),('Currency Exchange','ETH',3,3500),('Currency Exchange','XRP',1,4000),('Currency Exchange','XRP',2,4500),('Currency Exchange','XRP',3,5000);
SELECT avg_transaction_value FROM avg_transaction_value WHERE industry_sector = 'Currency Exchange' AND asset_name = 'XRP' AND quarter = 3;
Create a new table named 'animal_population'
CREATE TABLE IF NOT EXISTS region (id INT PRIMARY KEY,name VARCHAR(50));CREATE TABLE IF NOT EXISTS animal (id INT PRIMARY KEY,name VARCHAR(50));CREATE TABLE IF NOT EXISTS animal_population (id INT PRIMARY KEY,animal_id INT,region_id INT,population INT);
CREATE TABLE IF NOT EXISTS animal_population (id INT PRIMARY KEY, animal_id INT, region_id INT, population INT);
Find the number of unique departments that have employees hired in 2021
CREATE TABLE hiring (id INT,employee_id INT,hire_date DATE,department VARCHAR(255)); INSERT INTO hiring (id,employee_id,hire_date,department) VALUES (1,101,'2020-01-02','HR'); INSERT INTO hiring (id,employee_id,hire_date,department) VALUES (2,102,'2019-12-20','IT');
SELECT COUNT(DISTINCT department) FROM hiring WHERE YEAR(hire_date) = 2021;
Update the prices of specific menu items for a given restaurant.
CREATE TABLE Restaurants (RestaurantID INT,Name VARCHAR(50)); CREATE TABLE Menu (MenuID INT,RestaurantID INT,Item VARCHAR(50),Price DECIMAL(10,2));
UPDATE Menu SET Price = 11.99 WHERE Item = 'Vegan Burger' AND RestaurantID = 1; UPDATE Menu SET Price = 8.99 WHERE Item = 'Impossible Taco' AND RestaurantID = 1;
What was the average waste generation per person in the city of Boston in 2017?
CREATE TABLE waste_generation_person (city VARCHAR(20),year INT,person INT,quantity INT); INSERT INTO waste_generation_person (city,year,person,quantity) VALUES ('Boston',2017,1,100),('Boston',2017,2,200),('Boston',2017,3,300);
SELECT AVG(quantity) AS avg_waste_generation FROM waste_generation_person WHERE city = 'Boston' AND year = 2017;
What is the percentage of students who received accommodations out of the total number of students, for each department?
CREATE TABLE Department (DeptID INT,DeptName VARCHAR(50),City VARCHAR(50)); INSERT INTO Department (DeptID,DeptName,City) VALUES (1,'Disability Services','New York'); INSERT INTO Department (DeptID,DeptName,City) VALUES (2,'Student Support','Los Angeles'); CREATE TABLE Accommodation (AccID INT,AccName VARCHAR(50),StudentID INT,DeptID INT); INSERT INTO Accommodation (AccID,AccName,StudentID,DeptID) VALUES (1,'Sign Language Interpreter',1,1); INSERT INTO Accommodation (AccID,AccName,StudentID,DeptID) VALUES (2,'Note Taker',2,1); INSERT INTO Accommodation (AccID,AccName,StudentID,DeptID) VALUES (3,'Adaptive Equipment',3,2); CREATE TABLE Student (StudentID INT,StudentName VARCHAR(50)); INSERT INTO Student (StudentID,StudentName) VALUES (1,'John Doe'); INSERT INTO Student (StudentID,StudentName) VALUES (2,'Jane Smith'); INSERT INTO Student (StudentID,StudentName) VALUES (3,'Michael Lee');
SELECT DeptName, (COUNT(DISTINCT A.StudentID) * 100.0 / COUNT(DISTINCT S.StudentID)) AS Percentage FROM Accommodation A JOIN Department D ON A.DeptID = D.DeptID JOIN Student S ON A.StudentID = S.StudentID GROUP BY DeptName;
Which community centers in the city of Houston have a budget allocation over $350,000?
CREATE TABLE community_centers (name TEXT,city TEXT,budget_allocation INT); INSERT INTO community_centers (name,city,budget_allocation) VALUES ('Community Center A','Houston',400000),('Community Center B','Houston',300000);
SELECT name, budget_allocation FROM community_centers WHERE city = 'Houston' AND budget_allocation > 350000;
Delete the entry for the German mine in the 'mine' table.
CREATE TABLE mine (id INT,name TEXT,location TEXT,Neodymium_production FLOAT); INSERT INTO mine (id,name,location,Neodymium_production) VALUES (1,'German Mine','Germany',1100.0),(2,'Finnish Mine','Finland',900.0);
DELETE FROM mine WHERE name = 'German Mine';
List all fish species and their populations in sustainable fisheries in the South China Sea.
CREATE TABLE fisheries (fishery_name VARCHAR(50),fish_species VARCHAR(50),population INT); INSERT INTO fisheries (fishery_name,fish_species,population) VALUES ('South China Sea Sustainable 1','Pomfret',120000),('South China Sea Sustainable 1','Grouper',180000),('South China Sea Sustainable 2','Squid',60000),('South China Sea Sustainable 2','Shrimp',70000);
SELECT fish_species, population FROM fisheries WHERE fishery_name LIKE 'South China Sea Sustainable%';
What is the total number of workers in mining operations in the state of New York that have less than 2 years of experience?
CREATE TABLE mining_workforce (id INT,state VARCHAR(50),years_of_experience INT,position VARCHAR(50)); INSERT INTO mining_workforce (id,state,years_of_experience,position) VALUES (4,'New York',1,'Miner'); INSERT INTO mining_workforce (id,state,years_of_experience,position) VALUES (5,'New York',3,'Miner'); INSERT INTO mining_workforce (id,state,years_of_experience,position) VALUES (6,'New York',0,'Miner'); INSERT INTO mining_workforce (id,state,years_of_experience,position) VALUES (7,'New York',2,'Miner');
SELECT COUNT(*) FROM mining_workforce WHERE state = 'New York' AND years_of_experience < 2;
How many users in each state have a heart rate above 120 bpm on average during their workouts?
CREATE SCHEMA fitness; CREATE TABLE users (id INT,user_name VARCHAR(255),state VARCHAR(255)); CREATE TABLE workouts (id INT,user_id INT,workout_date DATE,avg_heart_rate INT);
SELECT state, AVG(avg_heart_rate) FROM fitness.workouts INNER JOIN fitness.users ON workouts.user_id = users.id GROUP BY state HAVING AVG(avg_heart_rate) > 120;
Find all marine species that have been observed in the Arctic region but not in the Atlantic region
CREATE TABLE marine_species (name TEXT,region TEXT); INSERT INTO marine_species (name,region) VALUES ('Species1','Arctic'); INSERT INTO marine_species (name,region) VALUES ('Species2','Atlantic');
SELECT m1.name FROM marine_species m1 LEFT JOIN marine_species m2 ON m1.name = m2.name WHERE m1.region = 'Arctic' AND m2.region IS NULL;
What are the top 5 most popular news categories among users aged 25-34?
CREATE TABLE news_categories (id INT,category VARCHAR(255),popularity INT); INSERT INTO news_categories (id,category,popularity) VALUES
SELECT category, SUM(popularity) as total_popularity FROM news_categories JOIN user_demographics ON news_categories.id = user_demographics.news_id
What was the average resilience rating for infrastructure projects in Texas over the past 5 years?
CREATE TABLE InfrastructureResilience (State TEXT,Year INTEGER,ProjectType TEXT,ResilienceRating INTEGER); INSERT INTO InfrastructureResilience (State,Year,ProjectType,ResilienceRating) VALUES ('Texas',2017,'Bridge',80),('Texas',2017,'Highway',75),('Texas',2017,'Tunnel',85),('Texas',2018,'Bridge',82),('Texas',2018,'Highway',78),('Texas',2018,'Tunnel',87),('Texas',2019,'Bridge',84),('Texas',2019,'Highway',79),('Texas',2019,'Tunnel',88),('Texas',2020,'Bridge',86),('Texas',2020,'Highway',77),('Texas',2020,'Tunnel',89),('Texas',2021,'Bridge',88),('Texas',2021,'Highway',80),('Texas',2021,'Tunnel',90);
SELECT ProjectType, AVG(ResilienceRating) as AvgResilience FROM InfrastructureResilience WHERE State = 'Texas' GROUP BY ProjectType;
What is the total revenue for the restaurants located in 'New York'?
CREATE TABLE restaurant_info (restaurant_id INT,location VARCHAR(50)); INSERT INTO restaurant_info (restaurant_id,location) VALUES (1,'New York'),(2,'Los Angeles'),(3,'Chicago'),(4,'New York'); CREATE TABLE restaurant_revenue (restaurant_id INT,revenue INT); INSERT INTO restaurant_revenue (restaurant_id,revenue) VALUES (1,5000),(2,6000),(3,7000),(4,8000);
SELECT SUM(revenue) FROM restaurant_revenue INNER JOIN restaurant_info ON restaurant_revenue.restaurant_id = restaurant_info.restaurant_id WHERE location = 'New York';
Find mines in California with low environmental impact scores.
CREATE TABLE mine_env (id INT,name VARCHAR(50),location VARCHAR(50),environmental_score FLOAT); INSERT INTO mine_env VALUES (1,'Mine K','California',35),(2,'Mine L','California',65),(3,'Mine M','California',25);
SELECT name, environmental_score FROM mine_env WHERE location = 'California' AND environmental_score < 40;
What is the total budget for 'youth-focused economic diversification projects' in 'South America' since 2016?
CREATE TABLE projects (id INT,name TEXT,region TEXT,budget FLOAT,focus TEXT,start_date DATE); INSERT INTO projects (id,name,region,budget,focus,start_date) VALUES (1,'Project 1','South America',500000,'youth-focused economic diversification','2016-01-01'),(2,'Project 2','North America',750000,'infrastructure development','2017-01-01'),(3,'Project 3','South America',1000000,'rural development','2015-01-01');
SELECT SUM(projects.budget) FROM projects WHERE projects.region = 'South America' AND projects.focus = 'youth-focused economic diversification' AND projects.start_date >= '2016-01-01';
What are the names of the factories that have never reported recycling rates?
CREATE TABLE factories (name TEXT,id INTEGER); INSERT INTO factories (name,id) VALUES ('Factory A',1),('Factory B',2),('Factory C',3); CREATE TABLE recycling_rates (factory_id INTEGER,rate FLOAT); INSERT INTO recycling_rates (factory_id,rate) VALUES (1,0.3),(2,0.5),(3,0.7);
SELECT f.name FROM factories f LEFT JOIN recycling_rates r ON f.id = r.factory_id WHERE r.rate IS NULL;
Identify drugs approved in the UK, but not yet approved in the US market.
CREATE TABLE drugs (drug_id INT,drug_name VARCHAR(255),manufacturer VARCHAR(255),approval_status VARCHAR(255),market_availability VARCHAR(255)); INSERT INTO drugs (drug_id,drug_name,manufacturer,approval_status,market_availability) VALUES (1,'DrugI','ManufacturerG','Approved','Available in UK'),(2,'DrugJ','ManufacturerH','Not Approved','Not available in US'); CREATE TABLE sales (sale_id INT,drug_id INT,sale_amount DECIMAL(10,2),sale_tax DECIMAL(10,2),country VARCHAR(255)); INSERT INTO sales (sale_id,drug_id,sale_amount,sale_tax,country) VALUES (1,1,0.00,0.00,'US');
SELECT d.drug_name FROM drugs d LEFT JOIN sales s ON d.drug_id = s.drug_id WHERE d.approval_status = 'Approved' AND d.market_availability = 'Available in UK' AND s.country = 'US' GROUP BY d.drug_name;
What are the top 5 most used mobile devices among prepaid customers in the state of California, and how many subscribers use each device?
CREATE TABLE mobile_devices (device_id INT,device_name VARCHAR(50),mobile_services INT,state VARCHAR(20)); CREATE TABLE mobile_customers (customer_id INT,device_id INT,plan_type VARCHAR(10));
SELECT device_name, COUNT(*) as num_subscribers FROM mobile_devices JOIN mobile_customers ON mobile_devices.device_id = mobile_customers.device_id WHERE plan_type = 'prepaid' AND state = 'California' GROUP BY device_name ORDER BY num_subscribers DESC LIMIT 5;
Show the total revenue for the top 3 customers in France, in descending order.
CREATE TABLE customer_sales (customer_id INT,sales_revenue FLOAT,country VARCHAR(50)); INSERT INTO customer_sales (customer_id,sales_revenue,country) VALUES (1,5000,'CA'),(2,7000,'US'),(3,3000,'FR'),(4,8000,'CA'),(5,4000,'FR'),(6,6000,'US'),(7,9000,'FR');
SELECT customer_id, SUM(sales_revenue) as total_revenue FROM customer_sales WHERE country = 'FR' GROUP BY customer_id ORDER BY total_revenue DESC LIMIT 3;
What is the maximum price of a size 12 dress?
CREATE TABLE products (product_id INTEGER,name TEXT,size INTEGER,price FLOAT); INSERT INTO products (product_id,name,size,price) VALUES (1001,'Organic Cotton Dress',12,80.0),(1002,'Silk Blouse',8,60.0),(1003,'Recycled Polyester Jacket',14,120.0),(1004,'Bamboo T-Shirt',6,30.0);
SELECT MAX(price) FROM products WHERE size = 12;
List the top 10 cities with the most funding, based on the total funding received by companies located in those cities
CREATE TABLE company_location (id INT,company_name VARCHAR(50),city VARCHAR(50),funding_amount DECIMAL(10,2));
SELECT city, SUM(funding_amount) AS total_funding FROM company_location GROUP BY city ORDER BY total_funding DESC LIMIT 10;
What was the total production volume of chemical Z in the first half of 2022?
CREATE TABLE ProductionVolume (id INT,chemical VARCHAR(255),volume INT,date DATE); INSERT INTO ProductionVolume (id,chemical,volume,date) VALUES (1,'chemical Z',500,'2022-01-01'),(2,'chemical X',600,'2022-02-15');
SELECT SUM(volume) FROM ProductionVolume WHERE chemical = 'chemical Z' AND date >= '2022-01-01' AND date <= '2022-06-30';
What is the minimum age of patients who tested positive for chlamydia in Australia?
CREATE TABLE patients (id INT,age INT,gender TEXT,state TEXT,disease TEXT); INSERT INTO patients (id,age,gender,state,disease) VALUES (1,18,'Female','Australia','Chlamydia'); INSERT INTO patients (id,age,gender,state,disease) VALUES (2,30,'Male','Australia','Chlamydia');
SELECT MIN(age) FROM patients WHERE state = 'Australia' AND disease = 'Chlamydia';
What is the average speed for each bus route?
CREATE TABLE route (route_id INT,route_name TEXT,avg_speed DECIMAL); INSERT INTO route (route_id,route_name,avg_speed) VALUES (1,'Route1',25.00),(2,'Route2',30.00),(3,'Route3',20.00),(4,'Route4',35.00),(5,'Route5',40.00);
SELECT route_name, avg_speed FROM route ORDER BY avg_speed DESC;
What is the number of fair labor certifications obtained by each company?
CREATE TABLE fair_labor_certifications(company VARCHAR(50),certification VARCHAR(50),obtained_date DATE);
SELECT company, COUNT(DISTINCT certification) FROM fair_labor_certifications GROUP BY company;
What is the average sentence length for offenders who have been convicted of a specific crime, by gender?
CREATE TABLE offenders (id INT,gender VARCHAR(10),sentence_length INT);CREATE TABLE convictions (id INT,offender_id INT,crime VARCHAR(50));
SELECT AVG(offenders.sentence_length) as avg_sentence, offenders.gender FROM offenders INNER JOIN convictions ON offenders.id = convictions.offender_id WHERE crime = 'Robbery' GROUP BY offenders.gender;
What is the maximum number of beds in hospitals by state?
CREATE TABLE hospitals (id INT,name TEXT,city TEXT,state TEXT,beds INT); INSERT INTO hospitals (id,name,city,state,beds) VALUES (1,'General Hospital','Miami','Florida',500); INSERT INTO hospitals (id,name,city,state,beds) VALUES (2,'Memorial Hospital','Boston','Massachusetts',600);
SELECT state, MAX(beds) as max_beds FROM hospitals GROUP BY state;
What is the total number of complaints filed for each station in the Paris Metro?
CREATE TABLE stations (station_id INT,station_name VARCHAR(255),line_id INT);CREATE TABLE complaints (complaint_id INT,station_id INT,complaint_type VARCHAR(255),complaint_date DATETIME);
SELECT s.station_id, s.station_name, COUNT(c.complaint_id) as total_complaints FROM stations s JOIN complaints c ON s.station_id = c.station_id GROUP BY s.station_id, s.station_name;
What is the maximum number of cases resolved in the cases table in a single year?
CREATE TABLE cases (id INT,year INT,restorative_justice BOOLEAN);
SELECT MAX(COUNT(*)) FROM cases GROUP BY year;
How many artworks were sold in each region?
CREATE TABLE Artworks (ArtworkID INT,Region TEXT); INSERT INTO Artworks (ArtworkID,Region) VALUES (1,'Europe'),(2,'Europe'),(3,'Asia'),(4,'Asia'),(5,'Americas');
SELECT Region, COUNT(*) as ArtworksSold FROM Artworks GROUP BY Region;
What is the average duration of news programs in Canada and the US?
CREATE TABLE news_programs (id INT,title VARCHAR(255),release_year INT,views INT,country VARCHAR(50),duration INT); INSERT INTO news_programs (id,title,release_year,views,country,duration) VALUES (1,'News1',2010,10000,'Canada',30),(2,'News2',2015,15000,'Canada',45),(3,'News3',2020,20000,'US',60); INSERT INTO news_programs (id,title,release_year,views,country,duration) VALUES (4,'News4',2005,20000,'US',45),(5,'News5',2018,25000,'US',60),(6,'News6',2021,30000,'Canada',45);
SELECT AVG(duration) FROM news_programs WHERE country = 'Canada' UNION SELECT AVG(duration) FROM news_programs WHERE country = 'US';
Identify the number of renewable energy projects in the 'Asia' and 'Europe' regions, excluding hydroelectric projects.
CREATE SCHEMA renewable_energy; CREATE TABLE projects (project_name VARCHAR(255),region VARCHAR(255),project_type VARCHAR(255)); INSERT INTO projects (project_name,region,project_type) VALUES ('Sunrise Solar Farm','Asia','Solar'),('Windy Solar Park','Europe','Solar'),('Solar Bliss Ranch','North America','Solar'),('Hydroelectric Dam','South America','Hydroelectric');
SELECT region, COUNT(*) FROM renewable_energy.projects WHERE region IN ('Asia', 'Europe') AND project_type != 'Hydroelectric' GROUP BY region;
Identify the communication strategies that led to a significant reduction in carbon emissions in Southeast Asia?
CREATE TABLE communication_strategies (strategy VARCHAR(50),location VARCHAR(50),reduction_emissions INT); INSERT INTO communication_strategies (strategy,location,reduction_emissions) VALUES ('Public transportation campaigns','Southeast Asia',500000),('Tree planting drives','Southeast Asia',300000),('Solar energy awareness programs','Southeast Asia',250000);
SELECT strategy, reduction_emissions FROM communication_strategies WHERE location = 'Southeast Asia' AND reduction_emissions > 300000;
How many volunteers from Asia joined our programs in Q2 of 2022?
CREATE TABLE Volunteers (VolunteerID int,VolunteerName varchar(50),Country varchar(50),JoinDate date);
SELECT COUNT(*) FROM Volunteers WHERE Country LIKE 'Asia%' AND QUARTER(JoinDate) = 2;
Count the number of animals in 'animal_population' table that are not present in 'endangered_species' or 'recovering_species' tables in Africa.
CREATE TABLE animal_population (id INT,animal_name VARCHAR(50),population INT,region VARCHAR(50)); INSERT INTO animal_population VALUES (1,'Elephant',15000,'Africa'); CREATE TABLE endangered_species (id INT,animal_name VARCHAR(50),population INT,region VARCHAR(50)); INSERT INTO endangered_species VALUES (1,'Rhino',1000,'Africa'); CREATE TABLE recovering_species (id INT,animal_name VARCHAR(50),population INT,region VARCHAR(50)); INSERT INTO recovering_species VALUES (1,'Lion',2000,'Africa');
SELECT population FROM animal_population WHERE animal_name NOT IN (SELECT animal_name FROM endangered_species WHERE region = 'Africa') AND animal_name NOT IN (SELECT animal_name FROM recovering_species WHERE region = 'Africa');
How many peacekeeping operations were conducted by ASEAN in the last 3 years, ordered by date?
CREATE TABLE AseanPeacekeepingOperations (id INT,operation_name VARCHAR(255),operation_start_date DATE,operation_end_date DATE);
SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY operation_start_date DESC) as rn FROM AseanPeacekeepingOperations WHERE organization = 'ASEAN' AND operation_start_date >= DATEADD(year, -3, CURRENT_DATE)) x WHERE rn = 1;
What is the average data usage, in GB, for customers in each country, in the last 6 months, partitioned by network type?
CREATE TABLE customers (customer_id INT,name VARCHAR(50),country VARCHAR(50),network_type VARCHAR(50),data_usage FLOAT,usage_date DATE); INSERT INTO customers (customer_id,name,country,network_type,data_usage,usage_date) VALUES (1,'John Doe','USA','4G',45.6,'2022-01-01'),(2,'Jane Smith','Canada','5G',30.9,'2022-02-01'),(3,'Mike Johnson','Mexico','4G',60.7,'2022-03-01');
SELECT country, network_type, AVG(data_usage) as avg_data_usage FROM customers WHERE usage_date >= DATEADD(month, -6, GETDATE()) GROUP BY country, network_type;
What is the total production cost of garments in Vietnam for the month of June 2021?
CREATE TABLE production (id INT,factory VARCHAR(255),country VARCHAR(255),cost DECIMAL(10,2),production_date DATE); INSERT INTO production (id,factory,country,cost,production_date) VALUES (1,'Fabric Inc','Vietnam',120.00,'2021-06-01'),(2,'Stitch Time','USA',150.00,'2021-06-15');
SELECT SUM(cost) FROM production WHERE country = 'Vietnam' AND MONTH(production_date) = 6 AND YEAR(production_date) = 2021;
Find the total number of green buildings in the city of Seattle.
CREATE TABLE green_buildings (id INT,city VARCHAR(20)); INSERT INTO green_buildings (id,city) VALUES (1,'Seattle'),(2,'Portland');
SELECT COUNT(*) FROM green_buildings WHERE city = 'Seattle';
Show the names and locations of mines where the total amount of coal mined is greater than the total amount of iron mined.
CREATE TABLE mine (id INT,name VARCHAR(50),location VARCHAR(50));CREATE TABLE coal_mine (mine_id INT,amount INT);CREATE TABLE iron_mine (mine_id INT,amount INT);
SELECT m.name, m.location FROM mine m INNER JOIN coal_mine c ON m.id = c.mine_id INNER JOIN iron_mine i ON m.id = i.mine_id GROUP BY m.id, m.name, m.location HAVING SUM(c.amount) > SUM(i.amount);
List the unique job titles held by employees who identify as female or non-binary.
CREATE TABLE employees (id INT,name VARCHAR(50),job_title VARCHAR(50),gender VARCHAR(10)); INSERT INTO employees (id,name,job_title,gender) VALUES (1,'John Doe','Software Engineer','Male'),(2,'Jane Smith','Marketing Manager','Female'),(3,'Mike Johnson','Data Analyst','Male'),(4,'Sara Connor','Project Manager','Non-binary');
SELECT DISTINCT job_title FROM employees WHERE gender IN ('Female', 'Non-binary');
Determine the maximum and minimum transaction amounts for accounts in Florida in the past month.
CREATE TABLE transactions (id INT,account_id INT,transaction_date DATE,transaction_amount DECIMAL(10,2)); CREATE TABLE accounts (id INT,state VARCHAR(50));
SELECT MAX(transaction_amount) as max_transaction, MIN(transaction_amount) as min_transaction FROM transactions t JOIN accounts a ON t.account_id = a.id WHERE a.state = 'Florida' AND t.transaction_date >= DATEADD(month, -1, CURRENT_DATE);
Which clean energy policy trends were implemented in 2018, ordered by the policy id?
CREATE TABLE clean_energy_policy_trends (id INT,policy_name VARCHAR(100),description TEXT,start_date DATE);
SELECT * FROM clean_energy_policy_trends WHERE YEAR(start_date) = 2018 ORDER BY id;
What is the percentage of female and non-binary employees in the mining industry, per country, for operations with more than 100 employees?
CREATE TABLE workforce (workforce_id INT,mine_id INT,employee_name VARCHAR(50),gender VARCHAR(10),country VARCHAR(20)); INSERT INTO workforce (workforce_id,mine_id,employee_name,gender,country) VALUES (1,1,'Juan Lopez','Male','Mexico'),(2,1,'Maria Rodriguez','Female','Mexico'),(3,2,'Peter Jackson','Male','Canada'),(4,3,'Emily White','Female','USA'),(5,3,'Alex Brown','Non-binary','USA'),(6,4,'Fatima Ahmed','Female','Pakistan'),(7,4,'Ahmed Raza','Male','Pakistan'),(8,5,'Minh Nguyen','Non-binary','Vietnam'),(9,5,'Hoa Le','Female','Vietnam');
SELECT country, gender, COUNT(*) as employee_count, ROUND(COUNT(*) * 100.0 / SUM(COUNT(*)) OVER (PARTITION BY country), 2) as percentage FROM workforce WHERE (SELECT COUNT(*) FROM workforce w WHERE w.mine_id = workforce.mine_id) > 100 GROUP BY country, gender;
What is the average hotel rating in the 'luxury' category?
CREATE TABLE hotels (hotel_id INT,name TEXT,category TEXT,rating FLOAT); INSERT INTO hotels (hotel_id,name,category,rating) VALUES (1,'Hotel X','luxury',4.5),(2,'Hotel Y','budget',3.2);
SELECT AVG(rating) FROM hotels WHERE category = 'luxury';
What is the percentage of donations made by each age group?
CREATE TABLE AgeGroups (id INT,age_range VARCHAR(20),total_donors INT); INSERT INTO AgeGroups (id,age_range,total_donors) VALUES (1,'18-24',1000),(2,'25-34',2000),(3,'35-44',3000); CREATE TABLE Donors (id INT,age_group INT,donation_id INT); INSERT INTO Donors (id,age_group,donation_id) VALUES (1,1,1001),(2,2,1002),(3,3,1003); CREATE TABLE Donations (id INT,donor_id INT,amount DECIMAL(10,2)); INSERT INTO Donations (id,donor_id,amount) VALUES (1001,1,50.00),(1002,2,75.00),(1003,3,100.00);
SELECT g.age_range, SUM(d.amount) / SUM(ag.total_donors) * 100 as percentage FROM Donors g JOIN Donations d ON g.id = d.donor_id JOIN AgeGroups ag ON g.age_group = ag.id GROUP BY g.age_range;
What is the total revenue of cosmetics sold in the US in Q1 2022, grouped by brand?
CREATE TABLE sales (id INT,brand VARCHAR(255),country VARCHAR(255),sales_amount DECIMAL(10,2),sale_date DATE);
SELECT brand, SUM(sales_amount) FROM sales WHERE country = 'US' AND sale_date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY brand;
Insert a new record for a student with a physical disability who requires mobility assistance accommodations.
CREATE TABLE StudentAccommodations (StudentID INT,StudentName VARCHAR(255),DisabilityType VARCHAR(255),AccommodationType VARCHAR(255)); INSERT INTO StudentAccommodations (StudentID,StudentName,DisabilityType,AccommodationType) VALUES (1,'John Doe','Visual Impairment','Sign Language Interpretation'),(2,'Jane Smith','Hearing Impairment','Assistive Listening Devices'),(3,'Mike Brown','Learning Disability','Assistive Technology');
INSERT INTO StudentAccommodations (StudentID, StudentName, DisabilityType, AccommodationType) VALUES (4, 'Sara Johnson', 'Physical Disability', 'Mobility Assistance');
Update the 'quality_control' table and set the 'test_result' to 'Failed' for all records with 'defect_count' greater than 5
CREATE TABLE quality_control (id INT,test_type VARCHAR(255),test_result VARCHAR(255),defect_count INT,shift VARCHAR(255));
UPDATE quality_control SET test_result = 'Failed' WHERE defect_count > 5;
What is the minimum installed capacity of a wind farm in Asia?
CREATE TABLE asian_wind_farms (id INT,country VARCHAR(255),name VARCHAR(255),capacity FLOAT); INSERT INTO asian_wind_farms (id,country,name,capacity) VALUES (1,'China','Wind Farm A',250),(2,'India','Wind Farm B',300),(3,'Japan','Wind Farm C',150),(4,'South Korea','Wind Farm D',200);
SELECT MIN(capacity) FROM asian_wind_farms;
What is the total amount of Shariah-compliant mortgages issued by each bank, partitioned by bank and ordered by the total amount?
CREATE TABLE bank_mortgages (mortgage_id INT,bank_id INT,mortgage_amount DECIMAL(10,2)); INSERT INTO bank_mortgages (mortgage_id,bank_id,mortgage_amount) VALUES (1,1,5000.00),(2,1,7000.00),(3,2,10000.00),(4,2,12000.00),(5,3,8000.00); CREATE TABLE banks (bank_id INT,bank_name VARCHAR(50),location VARCHAR(50)); INSERT INTO banks (bank_id,bank_name,location) VALUES (1,'ABC Bank','Indonesia'),(2,'Islamic Mortgage Bank','Malaysia'),(3,'Shariah Finance Ltd','UAE');
SELECT bank_id, SUM(mortgage_amount) OVER (PARTITION BY bank_id) AS total_mortgage_amount, bank_name, location FROM bank_mortgages JOIN banks ON bank_mortgages.bank_id = banks.bank_id ORDER BY total_mortgage_amount DESC;
How many agricultural innovation projects were initiated in South Africa between 2012 and 2018?
CREATE TABLE agri_innovation_south_africa (project VARCHAR(50),country VARCHAR(50),start_year INT,end_year INT); INSERT INTO agri_innovation_south_africa (project,country,start_year,end_year) VALUES ('Precision Agriculture','South Africa',2012,2014),('Climate-smart Farming','South Africa',2015,2018),('Organic Farming','South Africa',2016,2018);
SELECT COUNT(*) FROM agri_innovation_south_africa WHERE country = 'South Africa' AND start_year BETWEEN 2012 AND 2018 AND end_year BETWEEN 2012 AND 2018;
What is the most popular game genre among players aged 25-30?
CREATE TABLE players (id INT,age INT,game_genre VARCHAR(20)); INSERT INTO players (id,age,game_genre) VALUES (1,25,'racing'),(2,30,'rpg'),(3,22,'shooter');
SELECT game_genre, COUNT(*) AS count FROM players WHERE age BETWEEN 25 AND 30 GROUP BY game_genre ORDER BY count DESC LIMIT 1;
What is the total amount of hazardous waste generated in the world, and how does that compare to the amount of hazardous waste generated in Europe?
CREATE TABLE HazardousWaste (Region VARCHAR(50),WasteQuantity INT); INSERT INTO HazardousWaste (Region,WasteQuantity) VALUES ('World',15000000),('Europe',1500000),('North America',5000000),('Asia',6000000);
SELECT Region, WasteQuantity FROM HazardousWaste WHERE Region IN ('World', 'Europe');