instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
How many of each dish were sold to customers in a specific location last week?
CREATE TABLE orders (dish VARCHAR(255),customer_location VARCHAR(50),order_date DATE); INSERT INTO orders (dish,customer_location,order_date) VALUES ('Chicken Shawarma','Toronto','2021-10-01'),('Beef Shawarma','Toronto','2021-10-02'),('Falafel Plate','Montreal','2021-10-01');
SELECT customer_location, dish, COUNT(*) FROM orders WHERE order_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 7 DAY) GROUP BY customer_location, dish;
What are the top 5 most sold dishes among vegetarian customers in the last month?
CREATE TABLE orders (id INT,dish_id INT,order_date DATE,quantity INT); CREATE TABLE customers (id INT,is_vegetarian BOOLEAN); CREATE TABLE dishes (id INT,name TEXT);
SELECT dishes.name, SUM(orders.quantity) as total_quantity FROM orders JOIN customers ON orders.id = customers.id JOIN dishes ON orders.dish_id = dishes.id WHERE customers.is_vegetarian = true AND orders.order_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) AND CURRENT_DATE GROUP BY dishes.name ORDER BY total_quantity DESC LIMIT 5;
List the members who are in the 'mining' union but not in the 'finance' union.
CREATE TABLE mining_union (id INT,name VARCHAR); INSERT INTO mining_union (id,name) VALUES (1,'Karen'); CREATE TABLE finance_union (id INT,name VARCHAR); INSERT INTO finance_union (id,name) VALUES (1,'Larry');
SELECT name FROM mining_union WHERE name NOT IN (SELECT name FROM finance_union);
What is the total CO2 emissions by region in the 'suppliers' table?
CREATE TABLE suppliers (id INT,region VARCHAR(20),co2_emissions INT); INSERT INTO suppliers (id,region,co2_emissions) VALUES (1,'North',500),(2,'South',800),(3,'East',300);
SELECT region, SUM(co2_emissions) FROM suppliers GROUP BY region;
How many autonomous taxis are there in each city in the UK?
CREATE TABLE uk_taxis (city VARCHAR(20),num_taxis INT);
SELECT city, SUM(num_taxis) AS total_autonomous_taxis FROM uk_taxis GROUP BY city;
What is the total quantity of ethically sourced products in all warehouses, grouped by product category?
CREATE TABLE warehouses (warehouse_id INT,product_id INT,quantity INT,is_ethically_sourced BOOLEAN); INSERT INTO warehouses (warehouse_id,product_id,quantity,is_ethically_sourced) VALUES (1,101,50,TRUE),(1,102,30,TRUE),(2,103,70,TRUE),(2,104,40,FALSE),(3,105,60,TRUE); CREATE TABLE products (product_id INT,category TEXT); INSERT INTO products (product_id,category) VALUES (101,'clothing'),(102,'clothing'),(103,'electronics'),(104,'jewelry'),(105,'furniture');
SELECT p.category, SUM(w.quantity) FROM warehouses w INNER JOIN products p ON w.product_id = p.product_id WHERE w.is_ethically_sourced = TRUE GROUP BY p.category;
What is the average number of military technology programs in the North American region, excluding programs with a budget above $1 billion?
CREATE TABLE MilitaryPrograms (region VARCHAR(255),program VARCHAR(255),budget DECIMAL(10,2)); INSERT INTO MilitaryPrograms (region,program,budget) VALUES ('North America','ProgramA',400000000.00),('North America','ProgramB',600000000.00),('North America','ProgramC',50000000.00),('Asia','ProgramD',300000000.00),('Asia','ProgramE',200000000.00);
SELECT AVG(budget) FROM MilitaryPrograms WHERE region = 'North America' AND budget < 1000000000;
What is the total weight of oil transported by vessels with a safety score above 85 in the Atlantic Ocean in Q4 2021?
CREATE TABLE vessels (id INT,name TEXT,type TEXT,safety_score FLOAT);CREATE TABLE cargos (id INT,vessel_id INT,material TEXT,weight FLOAT,destination TEXT,date DATE); INSERT INTO vessels (id,name,type,safety_score) VALUES (1,'VesselG','Tanker',87.5); INSERT INTO cargos (id,vessel_id,material,weight,destination,date) VALUES (1,1,'Oil',15000,'Atlantic','2021-12-31');
SELECT SUM(c.weight) FROM vessels v JOIN cargos c ON v.id = c.vessel_id WHERE v.safety_score > 85 AND c.material = 'Oil' AND c.destination = 'Atlantic' AND c.date BETWEEN '2021-10-01' AND '2021-12-31';
How many employees work at each site, sorted by the number of employees?
CREATE TABLE site (site_id INT,site_name VARCHAR(50),num_employees INT);
SELECT site_name, num_employees FROM site ORDER BY num_employees DESC;
What is the number of artifacts made of gold or silver, grouped by excavation site?
CREATE TABLE ArtifactMaterials (MaterialID INT,ArtifactID INT,Material TEXT); INSERT INTO ArtifactMaterials (MaterialID,ArtifactID,Material) VALUES (1,1,'Gold'); INSERT INTO ArtifactMaterials (MaterialID,ArtifactID,Material) VALUES (2,2,'Silver'); INSERT INTO ArtifactMaterials (MaterialID,ArtifactID,Material) VALUES (3,3,'Bronze'); INSERT INTO ArtifactMaterials (MaterialID,ArtifactID,Material) VALUES (4,4,'Iron');
SELECT e.SiteName, COUNT(*) AS Count FROM ExcavationSites e JOIN ArtifactAnalysis a ON e.SiteID = a.SiteID JOIN ArtifactMaterials m ON a.ArtifactID = m.ArtifactID WHERE m.Material IN ('Gold', 'Silver') GROUP BY e.SiteName;
How many infrastructure projects are there for each category?
CREATE TABLE InfrastructureProjects (id INT,name TEXT,category TEXT,budget FLOAT); INSERT INTO InfrastructureProjects (id,name,category,budget) VALUES (1,'Highway 12 Expansion','Transportation',2000000); INSERT INTO InfrastructureProjects (id,name,category,budget) VALUES (2,'Bridgewater Park Pedestrian Path','Parks',500000); INSERT INTO InfrastructureProjects (id,name,category,budget) VALUES (3,'Railway Crossing Upgrade','Transportation',1500000); INSERT INTO InfrastructureProjects (id,name,category,budget) VALUES (4,'New Community Center','Community',3000000);
SELECT category, COUNT(*) FROM InfrastructureProjects GROUP BY category;
Find the number of animals per species, grouped by region in the "animal_population" and "countries" tables
CREATE TABLE animal_population (species VARCHAR(255),animal_count INT,country VARCHAR(255)); CREATE TABLE countries (country VARCHAR(255),region VARCHAR(255));
SELECT c1.region, e1.species, SUM(e1.animal_count) as total_count FROM animal_population e1 INNER JOIN countries c1 ON e1.country = c1.country GROUP BY c1.region, e1.species;
List all mobile subscribers who joined in the first quarter of 2021 and their respective joining dates.
CREATE TABLE mobile_subscribers (subscriber_id INT,join_date DATE); INSERT INTO mobile_subscribers (subscriber_id,join_date) VALUES (1,'2021-01-01'),(2,'2021-03-01'),(3,'2020-12-01');
SELECT * FROM mobile_subscribers WHERE join_date BETWEEN '2021-01-01' AND '2021-03-31';
List of creative AI projects with budget over 50000.
CREATE TABLE creative_ai_budget (id INT PRIMARY KEY,project_name VARCHAR(50),budget FLOAT); INSERT INTO creative_ai_budget (id,project_name,budget) VALUES (1,'AI-generated Art',75000.0),(2,'AI-written Poetry',32000.0),(3,'AI-composed Music',48000.0),(4,'AI-designed Fashion',51000.0),(5,'AI-generated Architecture',80000.0);
SELECT project_name, budget FROM creative_ai_budget WHERE budget > 50000;
Determine the most sold garment category by week.
CREATE TABLE garment_sales (id INT,garment_id INT,category VARCHAR(20),sale_date DATE,quantity INT);CREATE VIEW weekly_sales_by_category AS SELECT EXTRACT(YEAR_WEEK FROM sale_date) as year_week,category,SUM(quantity) as total_sold FROM garment_sales GROUP BY year_week,category;
SELECT year_week, category, total_sold, RANK() OVER (PARTITION BY year_week ORDER BY total_sold DESC) as sales_rank FROM weekly_sales_by_category WHERE sales_rank = 1;
What is the average number of matches played per day by all players in World of Tanks?
CREATE TABLE players (id INT,name VARCHAR(50),age INT,game VARCHAR(50),matches_played INT,first_played DATE); INSERT INTO players (id,name,age,game,matches_played,first_played) VALUES (1,'Jane Doe',22,'World of Tanks',50,'2022-01-01');
SELECT AVG(matches_played / (CURRENT_DATE - first_played)) AS avg_matches_per_day FROM players WHERE game = 'World of Tanks';
What is the total cargo weight for each vessel type?
CREATE TABLE vessels (id INT,type VARCHAR(255)); INSERT INTO vessels (id,type) VALUES (1,'Tanker'),(2,'Bulk Carrier'),(3,'Container Ship'); CREATE TABLE cargo (id INT,vessel_id INT,weight INT); INSERT INTO cargo (id,vessel_id,weight) VALUES (1,1,50000),(2,2,75000),(3,3,100000);
SELECT v.type, SUM(c.weight) as total_weight FROM cargo c JOIN vessels v ON c.vessel_id = v.id GROUP BY v.type;
What is the total number of military personnel from each country involved in peacekeeping operations?
CREATE TABLE peacekeeping_operations (id INT,country VARCHAR,military_personnel INT);
SELECT country, SUM(military_personnel) FROM peacekeeping_operations GROUP BY country;
Insert a new record of a mental health parity report for the state of California in 2022
CREATE TABLE mental_health_parity_reports (report_id INT,state VARCHAR(255),year INT,total_complaints INT);
INSERT INTO mental_health_parity_reports (report_id, state, year, total_complaints) VALUES (1, 'California', 2022, 250);
What is the total transaction amount for each company, ranked by the total transaction amount in descending order?
CREATE TABLE blockchain_companies (company_id INT,company_name VARCHAR(50),platform VARCHAR(50)); INSERT INTO blockchain_companies (company_id,company_name,platform) VALUES (1,'Ethereum Foundation','Ethereum'); INSERT INTO blockchain_companies (company_id,company_name,platform) VALUES (2,'Blockstream','Bitcoin'); CREATE TABLE blockchain_transactions (transaction_id INT,company_id INT,amount DECIMAL(10,2)); INSERT INTO blockchain_transactions (transaction_id,company_id,amount) VALUES (1,1,1000.50); INSERT INTO blockchain_transactions (transaction_id,company_id,amount) VALUES (2,1,200.75); INSERT INTO blockchain_transactions (transaction_id,company_id,amount) VALUES (3,2,500.00);
SELECT b.company_name, SUM(bt.amount) as total_amount, ROW_NUMBER() OVER (ORDER BY SUM(bt.amount) DESC) as rank FROM blockchain_transactions bt JOIN blockchain_companies b ON bt.company_id = b.company_id GROUP BY b.company_id, b.company_name;
What is the budget quartile (1-4) for each mental health campaign by region, ordered by budget in descending order?
CREATE TABLE campaigns (id INT,campaign_name VARCHAR(50),start_date DATE,end_date DATE,budget FLOAT,region VARCHAR(50)); INSERT INTO campaigns (id,campaign_name,start_date,end_date,budget,region) VALUES (5,'EmpowerMinds','2022-01-01','2022-03-31',22000,'Asia'); INSERT INTO campaigns (id,campaign_name,start_date,end_date,budget,region) VALUES (6,'MindfulLiving','2022-04-01','2022-06-30',33000,'Africa'); INSERT INTO campaigns (id,campaign_name,start_date,end_date,budget,region) VALUES (7,'HarmonyHearts','2022-07-01','2022-09-30',17000,'Europe'); INSERT INTO campaigns (id,campaign_name,start_date,end_date,budget,region) VALUES (8,'BraveSpirits','2022-10-01','2022-12-31',27000,'Americas');
SELECT id, campaign_name, start_date, end_date, budget, region, NTILE(4) OVER (ORDER BY budget DESC) as quartile FROM campaigns;
Update the delivery address for all shipments with a shipment ID between 10 and 20 to a new address.
CREATE TABLE Shipments (ShipmentID INT,DeliveryAddress VARCHAR(255),ShipmentType VARCHAR(50),ShipmentDuration INT); INSERT INTO Shipments (ShipmentID,DeliveryAddress,ShipmentType,ShipmentDuration) VALUES (1,'123 Main St','Air',48),(2,'456 Elm St','Ground',72),(3,'789 Oak St','Air',60),(4,'321 Pine St','Ground',84),(5,'654 Maple St','Air',54);
UPDATE Shipments SET DeliveryAddress = 'New Address' WHERE ShipmentID BETWEEN 10 AND 20;
List all the routes and their associated vehicles that have 'accessible' as a feature.
CREATE TABLE Routes (id INT,name VARCHAR(255),vehicle_id INT); CREATE TABLE Vehicles (id INT,model VARCHAR(255),accessibility VARCHAR(50));
SELECT Routes.name, Vehicles.model FROM Routes JOIN Vehicles ON Routes.vehicle_id = Vehicles.id WHERE accessibility = 'accessible';
What is the maximum and minimum transaction volume for each decentralized exchange in the past week?
CREATE TABLE decentralized_exchanges (exchange_name TEXT,transaction_volume INTEGER,transaction_date DATE);
SELECT exchange_name, MAX(transaction_volume) AS max_volume, MIN(transaction_volume) AS min_volume FROM decentralized_exchanges WHERE transaction_date >= DATEADD(week, -1, GETDATE()) GROUP BY exchange_name;
What are the departments with an environmental impact above the threshold of 150,000?
CREATE TABLE EnvironmentalImpact (ImpactID INT,Department VARCHAR(20),ImpactQuantity INT,ImpactDate DATE);CREATE VIEW DepartmentImpact AS SELECT Department,SUM(ImpactQuantity) as TotalImpact FROM EnvironmentalImpact GROUP BY Department;
SELECT Department FROM DepartmentImpact WHERE TotalImpact >= 150000;
Get the well ID, start year, and average production forecast for wells in the Gulf of Guinea, ordered by the forecast start year.
CREATE TABLE gulf_of_guinea_forecasts (forecast_id INT,well_id INT,start_year INT,end_year INT,production_forecast FLOAT); INSERT INTO gulf_of_guinea_forecasts (forecast_id,well_id,start_year,end_year,production_forecast) VALUES (21,17,2022,2022,900.0),(22,17,2023,2023,950.0),(23,18,2022,2022,1000.0),(24,18,2023,2023,1050.0);
SELECT well_id, start_year, AVG(production_forecast) OVER (PARTITION BY well_id ORDER BY start_year ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as avg_forecast FROM gulf_of_guinea_forecasts WHERE wells.location = 'Gulf of Guinea';
Update the price of 'Blue Dream' to $1200 per pound in the strain price history table.
CREATE TABLE StrainPriceHistory (StrainName VARCHAR(255),Price DECIMAL(10,2),EffectiveDate DATE,Location VARCHAR(255));
UPDATE StrainPriceHistory SET Price = 1200 WHERE StrainName = 'Blue Dream' AND EffectiveDate = CURDATE() AND Location = 'California';
Identify the number of unique genres in the platform's catalog.
CREATE TABLE genres (id INT,name TEXT);CREATE TABLE songs (id INT,title TEXT,genre_id INT); INSERT INTO genres (id,name) VALUES (1,'Rock'),(2,'Pop'),(3,'Jazz'); INSERT INTO songs (id,title,genre_id) VALUES (1,'Song 1',1),(2,'Song 2',2),(3,'Song 3',3),(4,'Song 4',1);
SELECT COUNT(DISTINCT genres.name) FROM genres JOIN songs ON genres.id = songs.genre_id;
What is the average heart rate of female members aged 25-34 who joined in 2021?
CREATE TABLE members (member_id INT,gender VARCHAR(10),age INT,join_date DATE); INSERT INTO members (member_id,gender,age,join_date) VALUES (1,'Female',26,'2021-01-15'),(2,'Male',45,'2020-07-28');
SELECT AVG(heart_rate) FROM workout_data JOIN members ON workout_data.member_id = members.member_id WHERE members.gender = 'Female' AND members.age BETWEEN 25 AND 34 AND members.join_date >= '2021-01-01' AND members.join_date < '2022-01-01';
What is the minimum price of a product in the 'electronics' category?
CREATE TABLE products (product_id INT,category VARCHAR(20),price DECIMAL(5,2)); INSERT INTO products (product_id,category,price) VALUES (1,'electronics',150.00),(2,'electronics',200.00),(3,'electronics',125.00);
SELECT MIN(price) FROM products WHERE category = 'electronics';
How can I update the artist name for a specific art piece in the museum collection?
CREATE TABLE ArtPieces (ArtPieceID INT,Name TEXT,Artist TEXT,YearAdded INT); INSERT INTO ArtPieces (ArtPieceID,Name,Artist,YearAdded) VALUES (1,'Starry Night','Vincent van Gogh',1889); INSERT INTO ArtPieces (ArtPieceID,Name,Artist,YearAdded) VALUES (2,'The Persistence of Memory','Salvador Dalí',1931); INSERT INTO ArtPieces (ArtPieceID,Name,Artist,YearAdded) VALUES (3,'Guernica','Pablo Picasso',1937); INSERT INTO ArtPieces (ArtPieceID,Name,Artist,YearAdded) VALUES (4,'The Starry Night Over the Rhone','Vincent van Gogh',1888); INSERT INTO ArtPieces (ArtPieceID,Name,Artist,YearAdded) VALUES (5,'Girl with a Pearl Earring','Johannes Vermeer',1665);
UPDATE ArtPieces SET Artist = 'New Artist Name' WHERE ArtPieceID = 1;
What is the total carbon offset for green buildings in 'Texas'?
CREATE TABLE green_buildings (id INT,state VARCHAR(20),carbon_offset FLOAT); INSERT INTO green_buildings (id,state,carbon_offset) VALUES (1,'Texas',123.4),(2,'California',234.5),(3,'Texas',345.6),(4,'New_York',456.7); CREATE TABLE green_building_types (id INT,green_building_id INT,type VARCHAR(20)); INSERT INTO green_building_types (id,green_building_id,type) VALUES (1,1,'Residential'),(2,2,'Commercial'),(3,3,'Residential'),(4,4,'Government');
SELECT SUM(gb.carbon_offset) FROM green_buildings gb JOIN green_building_types gbt ON gb.id = gbt.green_building_id WHERE gb.state = 'Texas' AND gbt.type = 'Residential';
Insert a new record for a donation of $250.00 from a donor named 'David Lee' and give him a DonorID of 6.
CREATE TABLE Donors (DonorID INT,Name VARCHAR(50),TotalDonation DECIMAL(10,2)); INSERT INTO Donors (DonorID,Name,TotalDonation) VALUES (1,'John Doe',500.00),(2,'Jane Smith',350.00),(3,'Mike Johnson',200.00);
INSERT INTO Donors (DonorID, Name, TotalDonation) VALUES (6, 'David Lee', 250.00);
What is the average number of employees for companies founded in 2011?
CREATE TABLE company_profiles (company_id INT,founding_year INT,num_employees INT); INSERT INTO company_profiles (company_id,founding_year,num_employees) VALUES (1,2010,15),(2,2011,10),(3,2010,12),(4,2011,20),(5,2009,25);
SELECT AVG(num_employees) FROM company_profiles WHERE founding_year = 2011;
Insert a new record into the "harvest_data" table with the following data: farm_id: 2, yield: 60, date: '2023-01-08'
CREATE TABLE harvest_data (id INT PRIMARY KEY,farm_id INT,yield FLOAT,date DATE);
INSERT INTO harvest_data (farm_id, yield, date) VALUES (2, 60, '2023-01-08');
Add a row to the 'mental_health_parity' table
CREATE TABLE mental_health_parity (id INT PRIMARY KEY,state VARCHAR(2),parity_law TEXT,year INT);
INSERT INTO mental_health_parity (id, state, parity_law) VALUES (1, 'CA', 'California Mental Health Parity Act');
What is the total budget for AI projects in the 'americas' region in the 'ai_ethics' table?
CREATE TABLE ai_ethics (region TEXT,project TEXT,budget INTEGER); INSERT INTO ai_ethics (region,project,budget) VALUES ('Americas','AI Ethics for Government',250000); INSERT INTO ai_ethics (region,project,budget) VALUES ('Americas','AI Ethics for Business',300000);
SELECT SUM(budget) FROM ai_ethics WHERE region = 'Americas';
How many disaster relief supplies were distributed in each country in 2018?
CREATE TABLE supplies (id INT,supply_name VARCHAR(50),quantity INT,distribution_date DATE,country_code CHAR(2));
SELECT country_code, SUM(quantity) FROM supplies WHERE YEAR(distribution_date) = 2018 GROUP BY country_code;
How many individuals in each region have limited access to the internet due to infrastructure challenges?
CREATE TABLE individuals (individual_id INT,name VARCHAR(50),region VARCHAR(50),limited_internet_access BOOLEAN); INSERT INTO individuals (individual_id,name,region,limited_internet_access) VALUES (1,'David','Rural America',TRUE),(2,'Evelyn','Urban Africa',FALSE),(3,'Frank','Rural Asia',TRUE);
SELECT region, COUNT(*), SUM(limited_internet_access) FROM individuals GROUP BY region;
What is the average income in 'Seattle'?
CREATE TABLE city_income_data (city VARCHAR(255),income FLOAT); INSERT INTO city_income_data (city,income) VALUES ('Seattle',85000),('Portland',70000);
SELECT AVG(income) FROM city_income_data WHERE city = 'Seattle';
What is the total revenue for ingredients sourced from US-based suppliers?
CREATE TABLE products (product_id INT,name VARCHAR(50),revenue INT); INSERT INTO products (product_id,name,revenue) VALUES (1,'Lipstick A',200),(2,'Lipstick B',300),(3,'Eyeshadow C',150); CREATE TABLE ingredient_suppliers (ingredient_id INT,supplier_country VARCHAR(50),product_id INT); INSERT INTO ingredient_suppliers (ingredient_id,supplier_country,product_id) VALUES (1,'US',1),(2,'CA',1),(3,'US',2),(4,'MX',3);
SELECT SUM(products.revenue) FROM products INNER JOIN ingredient_suppliers ON products.product_id = ingredient_suppliers.product_id WHERE ingredient_suppliers.supplier_country = 'US';
What is the average price of vegan dishes in the San Francisco region?
CREATE TABLE menu (item_id INT,dish_type VARCHAR(10),price DECIMAL(5,2),region VARCHAR(20)); INSERT INTO menu (item_id,dish_type,price,region) VALUES (1,'vegan',12.99,'San Francisco'),(2,'vegetarian',9.99,'Los Angeles');
SELECT AVG(price) FROM menu WHERE dish_type = 'vegan' AND region = 'San Francisco';
What are the names of all the teams in the 'soccer_teams' table that have played more than 20 games?
CREATE TABLE soccer_teams (team_id INT,team_name VARCHAR(100),num_games INT);
SELECT team_name FROM soccer_teams WHERE num_games > 20;
What is the average age of healthcare workers in the "rural_clinics" table?
CREATE TABLE rural_clinics (id INT,name VARCHAR(50),location VARCHAR(50),num_workers INT,avg_age INT);
SELECT AVG(avg_age) FROM rural_clinics;
Which climate finance sources are used for more than one project in Oceania?
CREATE TABLE climate_finance(project_name TEXT,region TEXT,source TEXT); INSERT INTO climate_finance(project_name,region,source) VALUES ('Project M','New Zealand','Carbon Tax'),('Project N','Australia','Carbon Tax'),('Project O','Australia','Government Grant');
SELECT source FROM climate_finance WHERE region = 'Oceania' GROUP BY source HAVING COUNT(project_name) > 1;
How many rural hospitals are in the state of 'Georgia'?
CREATE SCHEMA if not exists rural_healthcare; use rural_healthcare; CREATE TABLE hospitals (id int,name varchar(255),location varchar(255),type varchar(255)); INSERT INTO hospitals (id,name,location,type) VALUES (1,'Hospital A','Atlanta','Urban'),(2,'Hospital B','Savannah','Urban'),(3,'Hospital C','Macon','Rural');
SELECT COUNT(*) FROM hospitals WHERE type = 'Rural' AND location = 'Georgia';
Create a table named 'conditions'
CREATE TABLE conditions (condition_id INT PRIMARY KEY,name VARCHAR(100),description TEXT);
CREATE TABLE conditions ( condition_id INT PRIMARY KEY, name VARCHAR(100), description TEXT);
What is the total number of public libraries in Canada, and what are their names?
CREATE TABLE libraries (name VARCHAR(255),country VARCHAR(255),num_books INT); INSERT INTO libraries (name,country,num_books) VALUES ('Toronto Public Library','Canada',1000000),('Vancouver Public Library','Canada',2000000);
SELECT SUM(num_books) FROM libraries WHERE country = 'Canada'; SELECT name FROM libraries WHERE country = 'Canada';
What is the total donation amount for organizations focused on Education?
CREATE TABLE organizations (id INT PRIMARY KEY,name VARCHAR(255),city VARCHAR(255),cause VARCHAR(255)); INSERT INTO organizations (id,name,city,cause) VALUES (1,'Education Fund','Los Angeles','Education'); INSERT INTO organizations (id,name,city,cause) VALUES (2,'Impact Investing Fund','New York','Sustainable Investments');
SELECT o.name as organization_name, SUM(d.donation_amount) as total_donation FROM donations d JOIN organizations o ON d.organization_id = o.id WHERE o.cause = 'Education' GROUP BY o.name;
Find the difference in total production of Cerium between 2019 and 2020 for mining companies that produced more Cerium in 2020 than in 2019.
CREATE TABLE MiningCompany (Name TEXT,Location TEXT,StartYear INT); INSERT INTO MiningCompany (Name,Location,StartYear) VALUES ('Alpha Mining','Australia',2005),('Beta Mines','China',2008),('Gamma Resources','USA',2012); CREATE TABLE ProductionYearly (Year INT,MiningCompany TEXT,Element TEXT,Quantity INT); INSERT INTO ProductionYearly (Year,MiningCompany,Element,Quantity) VALUES (2019,'Alpha Mining','Cerium',1000),(2019,'Beta Mines','Cerium',1200),(2019,'Gamma Resources','Cerium',800),(2020,'Alpha Mining','Cerium',1100),(2020,'Beta Mines','Cerium',1350),(2020,'Gamma Resources','Cerium',900);
SELECT a.MiningCompany, b.Quantity - a.Quantity AS Difference FROM ProductionYearly a JOIN ProductionYearly b ON a.MiningCompany = b.MiningCompany WHERE a.Element = 'Cerium' AND b.Element = 'Cerium' AND a.Year = 2019 AND b.Year = 2020 AND b.Quantity > a.Quantity;
List the number of veteran employees in the defense industry by job category
CREATE TABLE veteran_categories (state TEXT,veteran_count INT,job_category TEXT); INSERT INTO veteran_categories (state,veteran_count,job_category) VALUES ('California',1500,'Engineering'),('Texas',1200,'Management'),('Florida',1000,'Finance'),('New York',900,'IT'),('Virginia',1800,'Operations');
SELECT job_category, SUM(veteran_count) FROM veteran_categories GROUP BY job_category;
What is the average mental health score by county for Community Health Workers?
CREATE TABLE Counties (CountyID INT,CountyName VARCHAR(50),State VARCHAR(50)); CREATE TABLE CommunityHealthWorkers (CHW_ID INT,CountyID INT,MentalHealthScore INT); INSERT INTO Counties (CountyID,CountyName,State) VALUES (1,'Harris','Texas'),(2,'Los Angeles','California'); INSERT INTO CommunityHealthWorkers (CHW_ID,CountyID,MentalHealthScore) VALUES (1,1,85),(2,1,90),(3,2,75),(4,2,70);
SELECT c.CountyName, AVG(chw.MentalHealthScore) as Avg_Score FROM CommunityHealthWorkers chw JOIN Counties c ON chw.CountyID = c.CountyID GROUP BY c.CountyName;
What is the average consumer preference score for cosmetic products that are not certified cruelty-free?
CREATE TABLE cosmetics (product_name TEXT,consumer_preference_score INTEGER,cruelty_free BOOLEAN); INSERT INTO cosmetics (product_name,consumer_preference_score,cruelty_free) VALUES ('ProductA',85,true),('ProductB',90,false),('ProductC',70,true),('ProductD',95,true),('ProductE',80,false),('ProductF',75,true);
SELECT AVG(consumer_preference_score) FROM cosmetics WHERE cruelty_free = false;
Calculate the total volume of timber harvested in tropical forests
CREATE TABLE forests (id INT,name VARCHAR(50),type VARCHAR(50)); INSERT INTO forests (id,name,type) VALUES (1,'Amazon','tropical'),(2,'Daintree','tropical'),(3,'Boreal','temperate'); CREATE TABLE harvests (id INT,forest_id INT,volume DECIMAL(10,2)); INSERT INTO harvests (id,forest_id,volume) VALUES (1,1,150.50),(2,1,120.25),(3,3,180.75);
SELECT SUM(h.volume) FROM harvests h JOIN forests f ON h.forest_id = f.id WHERE f.type = 'tropical';
What is the trend of crime counts for each type of crime in different neighborhoods?
CREATE TABLE neighborhoods (neighborhood_id INT,neighborhood_name VARCHAR(255));CREATE TABLE crimes (crime_id INT,crime_type VARCHAR(255),neighborhood_id INT,crime_date DATE); INSERT INTO neighborhoods VALUES (1,'West Hill'),(2,'East End'); INSERT INTO crimes VALUES (1,'Theft',1,'2019-01-01'),(2,'Vandalism',2,'2019-02-01');
SELECT neighborhood_id, crime_type, DATE_TRUNC('month', crime_date) as month, COUNT(*) as num_crimes FROM crimes GROUP BY neighborhood_id, crime_type, month ORDER BY neighborhood_id, crime_type, month
Calculate the percentage of factories in each country that have produced sustainable materials in the past year.
CREATE TABLE Factories (FactoryID INT,Company VARCHAR(50),Location VARCHAR(50)); CREATE TABLE Production (ProductionID INT,FactoryID INT,Material VARCHAR(50),Quantity INT,ProductionDate DATE); INSERT INTO Factories VALUES (1,'Green Enterprises','Country A'),(2,'Green Enterprises','Country B'),(3,'Another Company','Country C'),(4,'Yet Another Company','Country A'); INSERT INTO Production VALUES (1,1,'Eco-Friendly Material',100,'2022-01-01'),(2,1,'Eco-Friendly Material',150,'2022-02-01'),(3,2,'Eco-Friendly Material',200,'2022-03-01'),(4,3,'Regular Material',50,'2022-04-01'),(5,4,'Eco-Friendly Material',75,'2021-05-01');
SELECT f.Location, COUNT(DISTINCT f.FactoryID) * 100.0 / (SELECT COUNT(DISTINCT FactoryID) FROM Factories) AS Percentage FROM Factories f JOIN Production p ON f.FactoryID = p.FactoryID WHERE p.ProductionDate >= DATEADD(year, -1, GETDATE()) AND Material IN ('Eco-Friendly Material', 'Sustainable Material') GROUP BY f.Location;
Who are the instructors for the 'Python for Data Science' course?
CREATE TABLE course_instructor (course_name VARCHAR(50),instructor_name VARCHAR(50));
SELECT instructor_name FROM course_instructor WHERE course_name = 'Python for Data Science';
What are the top 2 countries with the highest revenue for lipsticks?
CREATE TABLE Sales (product_id INT,product_name TEXT,product_category TEXT,price DECIMAL(5,2),quantity_sold INT,country TEXT); INSERT INTO Sales (product_id,product_name,product_category,price,quantity_sold,country) VALUES (1,'Ruby Woo','Lipstick',18.00,1500,'USA'),(2,'Russian Red','Lipstick',19.50,1200,'Canada'),(3,'Lady Danger','Lipstick',17.50,1800,'USA'),(4,'Mineral Powder','Face',25.00,2000,'France'),(5,'Nourishing Cream','Skincare',30.00,2500,'Germany');
SELECT country, SUM(price * quantity_sold) AS revenue FROM Sales WHERE product_category = 'Lipstick' GROUP BY country ORDER BY revenue DESC LIMIT 2;
Which marine species were observed at the 'Oceanic Trench' site?
CREATE TABLE marine_species (species_id INT,site_id INT,species_name TEXT); INSERT INTO marine_species (species_id,site_id,species_name) VALUES (1,1,'Anglerfish'),(2,3,'Giant Squid'),(3,1,'Oceanic Trench Snailfish');
SELECT species_name FROM marine_species WHERE site_id = (SELECT site_id FROM marine_sites WHERE site_name = 'Oceanic Trench');
Find the maximum construction cost for a project in the UK
CREATE TABLE infrastructure_projects (id INT,name TEXT,location TEXT,construction_cost FLOAT); INSERT INTO infrastructure_projects (id,name,location,construction_cost) VALUES (1,'Brooklyn Bridge','USA',15000000); INSERT INTO infrastructure_projects (id,name,location,construction_cost) VALUES (2,'Chunnel','UK',21000000); INSERT INTO infrastructure_projects (id,name,location,construction_cost) VALUES (3,'Tokyo Tower','Japan',33000000); INSERT INTO infrastructure_projects (id,name,location,construction_cost) VALUES (4,'Golden Gate Bridge','USA',11000000);
SELECT MAX(construction_cost) FROM infrastructure_projects WHERE location = 'UK';
How many sustainable building projects were completed in the city of Chicago between January 1, 2020 and December 31, 2020?
CREATE TABLE sustainable_building_projects (project_id INT,project_name VARCHAR(50),city VARCHAR(50),completion_date DATE,is_sustainable BOOLEAN); INSERT INTO sustainable_building_projects (project_id,project_name,city,completion_date,is_sustainable) VALUES (1,'Green Building','Chicago','2020-01-01',TRUE); INSERT INTO sustainable_building_projects (project_id,project_name,city,completion_date,is_sustainable) VALUES (2,'Solar Powered Apartments','Chicago','2020-02-01',TRUE);
SELECT COUNT(*) FROM sustainable_building_projects WHERE city = 'Chicago' AND completion_date BETWEEN '2020-01-01' AND '2020-12-31' AND is_sustainable = TRUE;
Increase the loan amount for Green Financial Services in Africa by 15%
CREATE SCHEMA if not exists finance;CREATE TABLE if not exists loans (id INT PRIMARY KEY,institution_name TEXT,region TEXT,amount DECIMAL(10,2)); INSERT INTO loans (id,institution_name,region,amount) VALUES (1,'Green Financial Services','Africa',12000.00);
UPDATE finance.loans SET amount = amount * 1.15 WHERE institution_name = 'Green Financial Services' AND region = 'Africa';
What is the average price per pound for the top 3 most produced strains in Nevada in 2021?
CREATE TABLE strain_prices (id INT,strain_name VARCHAR(255),dispensary_name VARCHAR(255),state VARCHAR(255),price_per_pound DECIMAL(10,2),price_date DATE);
SELECT AVG(price_per_pound) FROM strain_prices JOIN (SELECT strain_name, SUM(production_weight) AS total_weight FROM production WHERE state = 'Nevada' AND production_date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY strain_name ORDER BY total_weight DESC LIMIT 3) AS top_strains ON strain_prices.strain_name = top_strains.strain_name;
Identify the top 5 threat types and their counts in the 'threat_intelligence' table
CREATE TABLE threat_intelligence (threat_id INT,threat_type VARCHAR(50),threat_level VARCHAR(10),occurrence_date DATE);
SELECT threat_type, COUNT(*) as threat_count FROM threat_intelligence GROUP BY threat_type ORDER BY threat_count DESC LIMIT 5;
What is the median property price for co-ownership properties in Seattle?
CREATE TABLE seattle_prop (id INT,address TEXT,price FLOAT,co_ownership BOOLEAN); INSERT INTO seattle_prop (id,address,price,co_ownership) VALUES (1,'345 Pine St',400000,TRUE),(2,'678 Juniper St',500000,FALSE),(3,'901 Oak St',450000,TRUE),(4,'213 Fir St',550000,FALSE);
SELECT median(price) FROM (SELECT DISTINCT price FROM seattle_prop WHERE co_ownership = TRUE) tmp;
What are the names of astronauts who have piloted spacecrafts produced by different companies?
CREATE TABLE Astronauts (id INT,name VARCHAR(255),age INT); CREATE TABLE SpacecraftManufacturing (id INT,company VARCHAR(255),spacecraft VARCHAR(255)); CREATE TABLE SpacecraftPilots (id INT,astronaut_id INT,spacecraft VARCHAR(255));
SELECT DISTINCT Astronauts.name FROM Astronauts INNER JOIN SpacecraftPilots ON Astronauts.id = SpacecraftPilots.astronaut_id INNER JOIN SpacecraftManufacturing ON SpacecraftPilots.spacecraft = SpacecraftManufacturing.spacecraft GROUP BY Astronauts.name HAVING COUNT(DISTINCT SpacecraftManufacturing.company) > 1;
What is the total revenue generated by cultural heritage tours in Greece and Turkey?
CREATE TABLE cultural_tours (tour_id INT,name TEXT,revenue FLOAT,country TEXT); INSERT INTO cultural_tours (tour_id,name,revenue,country) VALUES (1,'Acropolis Tour',60000,'Greece'),(2,'Hagia Sophia Tour',70000,'Turkey');
SELECT SUM(revenue) FROM cultural_tours WHERE country IN ('Greece', 'Turkey');
Identify the products with the lowest and highest calorie counts in the product_nutrition table.
CREATE TABLE product_nutrition (product_id INT,calorie_count INT); INSERT INTO product_nutrition (product_id,calorie_count) VALUES (1,95),(2,50),(3,18),(4,300),(5,200);
SELECT product_id, calorie_count FROM (SELECT product_id, calorie_count, MIN(calorie_count) OVER () AS min_calorie_count, MAX(calorie_count) OVER () AS max_calorie_count FROM product_nutrition) WHERE calorie_count IN (min_calorie_count, max_calorie_count);
Update the CO2 emissions for specific countries in 2022.
CREATE TABLE international_tourists (id INT,country VARCHAR(50),co2_emission INT,visit_date DATE); INSERT INTO international_tourists (id,country,co2_emission,visit_date) VALUES (1,'France',1500,'2022-01-01');
UPDATE international_tourists SET co2_emission = 1600 WHERE country = 'France' AND visit_date = '2022-01-01';
What was the total number of attendees at the 'Music in the Park' events in Chicago that featured jazz music?
CREATE TABLE event_genre (event_name VARCHAR(50),city VARCHAR(50),genre VARCHAR(20),attendees INT); INSERT INTO event_genre (event_name,city,genre,attendees) VALUES ('Music in the Park','Chicago','Jazz',800);
SELECT SUM(attendees) FROM event_genre WHERE event_name = 'Music in the Park' AND city = 'Chicago' AND genre = 'Jazz';
What was the maximum and minimum construction cost for each type of infrastructure project in New York in 2019?
CREATE TABLE InfrastructureCostsNY (State TEXT,Year INTEGER,ProjectType TEXT,ConstructionCost REAL); INSERT INTO InfrastructureCostsNY (State,Year,ProjectType,ConstructionCost) VALUES ('New York',2019,'Bridge',1700000.0),('New York',2019,'Highway',2300000.0),('New York',2019,'Tunnel',3200000.0),('New York',2019,'Rail',2000000.0);
SELECT ProjectType, MIN(ConstructionCost) as MinCost, MAX(ConstructionCost) as MaxCost FROM InfrastructureCostsNY WHERE State = 'New York' AND Year = 2019 GROUP BY ProjectType;
What is the total revenue generated from sales of products made from recycled materials in the North American market?
CREATE TABLE sales (sale_id INT,product_id INT,quantity INT,price DECIMAL(5,2)); CREATE TABLE products (product_id INT,material VARCHAR(20),market VARCHAR(20)); INSERT INTO sales (sale_id,product_id,quantity,price) VALUES (1,1,10,25.00),(2,2,5,10.00),(3,3,8,30.00); INSERT INTO products (product_id,material,market) VALUES (1,'recycled polyester','North America'),(2,'nylon','Asia'),(3,'recycled cotton','North America');
SELECT SUM(quantity * price) FROM sales JOIN products ON sales.product_id = products.product_id WHERE products.material LIKE '%recycled%' AND products.market = 'North America';
Show the number of wheelchair ramps used on 'Red Line' subway platforms each month
CREATE TABLE wheelchair_ramp_usage (service_type VARCHAR(50),usage_date DATE,platform_location VARCHAR(50)); INSERT INTO wheelchair_ramp_usage (service_type,usage_date,platform_location) VALUES ('Wheelchair Ramp','2021-01-01','Red Line'),('Wheelchair Ramp','2021-01-05','Red Line'),('Wheelchair Ramp','2021-02-03','Red Line');
SELECT EXTRACT(MONTH FROM usage_date), COUNT(*) FROM wheelchair_ramp_usage WHERE service_type = 'Wheelchair Ramp' AND platform_location = 'Red Line' GROUP BY EXTRACT(MONTH FROM usage_date);
Retrieve the number of users by gender in the 'user_demographics' table
CREATE TABLE user_demographics (user_id INT,age INT,gender VARCHAR(10),occupation VARCHAR(255)); INSERT INTO user_demographics (user_id,age,gender,occupation) VALUES (1,35,'male','software engineer');
SELECT * FROM user_gender_counts;
What is the average pH level in the water at the Mexican fish farm 'Farm W' in August?
CREATE TABLE fish_farms (id INT,name TEXT,country TEXT,latitude DECIMAL(9,6),longitude DECIMAL(9,6)); INSERT INTO fish_farms (id,name,country,latitude,longitude) VALUES (1,'Farm A','Mexico',21.34567,-106.45678); INSERT INTO fish_farms (id,name,country,latitude,longitude) VALUES (2,'Farm B','Mexico',23.56789,-108.67890); CREATE TABLE water_quality (date DATE,farm_id INT,pH DECIMAL(5,2)); INSERT INTO water_quality (date,farm_id,pH) VALUES ('2022-08-01',1,8.1); INSERT INTO water_quality (date,farm_id,pH) VALUES ('2022-08-01',2,8.3);
SELECT AVG(pH) FROM water_quality wq JOIN fish_farms ff ON wq.farm_id = ff.id WHERE wq.date = '2022-08-01' AND ff.country = 'Mexico' AND ff.name LIKE 'Farm W%';
List all autonomous bus routes in Tokyo and their total distance covered?
CREATE TABLE autonomous_buses (bus_id INT,route VARCHAR(50),distance FLOAT,city VARCHAR(50));
SELECT route, SUM(distance) FROM autonomous_buses WHERE city = 'Tokyo' GROUP BY route;
List the top 3 countries with the highest virtual tour engagement
CREATE TABLE virtual_tours (tour_id INT,hotel_id INT,country TEXT,user_engagement FLOAT);
SELECT country, SUM(user_engagement) as total_engagement FROM virtual_tours GROUP BY country ORDER BY total_engagement DESC LIMIT 3;
List the top 5 employees who handled the most hazardous materials in the 'South' plant in 2021.
CREATE TABLE employee (id int,name varchar(20),plant varchar(10)); CREATE TABLE handling (id int,employee_id int,material varchar(20),quantity int); INSERT INTO employee (id,name,plant) VALUES (1,'John','North Plant'),(2,'Jane','South Plant'),(3,'Doe','West Plant'); INSERT INTO handling (id,employee_id,material,quantity) VALUES (1,1,'Hazardous A',100),(2,2,'Hazardous B',200),(3,2,'Hazardous A',150),(4,3,'Hazardous C',50);
SELECT e.name, SUM(h.quantity) as total_handled FROM employee e JOIN handling h ON e.id = h.employee_id WHERE e.plant = 'South Plant' AND material = 'Hazardous' GROUP BY e.name ORDER BY total_handled DESC LIMIT 5;
Insert a new record into the sustainable_sourcing table for restaurant_id 456 with organic_produce set to true
CREATE TABLE sustainable_sourcing (restaurant_id INT,organic_produce BOOLEAN);
INSERT INTO sustainable_sourcing (restaurant_id, organic_produce) VALUES (456, true);
What is the average number of participants per language preservation program?
CREATE TABLE LanguagePreservation (ProgramID int,ParticipantCount int); INSERT INTO LanguagePreservation (ProgramID,ParticipantCount) VALUES (101,45),(102,62),(103,38),(104,71),(105,54);
SELECT AVG(ParticipantCount) FROM LanguagePreservation;
How many farms were there in each province in Canada in 2016?
CREATE TABLE canadian_provinces (province_name TEXT,province_abbr TEXT); INSERT INTO canadian_provinces (province_name,province_abbr) VALUES ('Alberta','AB'),('British Columbia','BC'); CREATE TABLE farms (farm_name TEXT,province TEXT,year INTEGER); INSERT INTO farms (farm_name,province,year) VALUES ('Farm A','AB',2016),('Farm B','AB',2016);
SELECT province, COUNT(*) FROM farms JOIN canadian_provinces ON farms.province = canadian_provinces.province_abbr WHERE year = 2016 GROUP BY province;
List all the vehicle maintenance records for trams in January 2023.
CREATE TABLE tram_maintenance (maintenance_id INT,maintenance_date DATE,maintenance_type VARCHAR(20),vehicle_id INT,vehicle_model VARCHAR(20));
SELECT * FROM tram_maintenance WHERE maintenance_date BETWEEN '2023-01-01' AND '2023-01-31' AND vehicle_model LIKE '%Tram%';
What is the distribution of energy consumption (kWh) in India by region?
CREATE TABLE india_energy_consumption (region TEXT,consumption_kwh FLOAT); INSERT INTO india_energy_consumption (region,consumption_kwh) VALUES ('North',1000.0),('South',1200.0),('East',800.0),('West',1500.0);
SELECT region, consumption_kwh FROM india_energy_consumption ORDER BY consumption_kwh;
Remove all records from the 'museums' table where the 'website' is empty or null.
CREATE TABLE museums (name VARCHAR(255),location VARCHAR(255),website VARCHAR(255));
DELETE FROM museums WHERE website IS NULL OR website = '';
List the top 3 countries with the most satellites in orbit?
CREATE TABLE satellites (id INT,country VARCHAR(255),name VARCHAR(255)); INSERT INTO satellites (id,country,name) VALUES (1,'USA','Starlink 1'),(2,'China','Shijian 21'),(3,'Russia','Yamal 601');
SELECT country, COUNT(*) as total_satellites FROM satellites GROUP BY country ORDER BY total_satellites DESC LIMIT 3;
List the bottom 3 destinations in South America for adventure tourism, ordered by the number of tourists.
CREATE TABLE south_america_adventure (country VARCHAR(50),tourists INT); INSERT INTO south_america_adventure VALUES ('Brazil',250000),('Argentina',200000),('Colombia',180000),('Peru',150000),('Ecuador',120000);
SELECT country FROM south_america_adventure ORDER BY tourists ASC LIMIT 3;
List all investments made by customers in Sydney with an investment amount greater than 5000.
CREATE TABLE investment (id INT,customer_id INT,investment_date DATE,amount DECIMAL(10,2)); INSERT INTO investment (id,customer_id,investment_date,amount) VALUES (1,1,'2022-01-01',6000.00),(2,2,'2022-01-02',7000.00); CREATE TABLE customer (id INT,name VARCHAR(255),address VARCHAR(255)); INSERT INTO customer (id,name,address) VALUES (1,'John Smith','Sydney'),(2,'Jane Doe','Melbourne');
SELECT * FROM investment i JOIN customer c ON i.customer_id = c.id WHERE c.address = 'Sydney' AND i.amount > 5000;
What is the total revenue generated from cultural heritage preservation activities in Africa?
CREATE TABLE tourism_revenue (region VARCHAR(50),activity VARCHAR(50),revenue FLOAT); INSERT INTO tourism_revenue (region,activity,revenue) VALUES ('Asia','Sustainable Tourism',8000000),('Europe','Cultural Tourism',9000000),('Africa','Cultural Heritage Preservation',7500000),('Americas','Virtual Tourism',6000000);
SELECT SUM(revenue) AS total_revenue FROM tourism_revenue WHERE region = 'Africa' AND activity = 'Cultural Heritage Preservation';
Which circular economy initiatives are present in Tokyo?
CREATE TABLE circular_economy (city VARCHAR(20),initiatives VARCHAR(50)); INSERT INTO circular_economy VALUES ('Tokyo','Waste-to-Energy,Material Recycling');
SELECT initiatives FROM circular_economy WHERE city = 'Tokyo';
What is the total number of cases with a favorable judgment in January 2022?
CREATE TABLE Judgments (JudgmentID INT,CaseID INT,JudgmentDate DATE,Judgment VARCHAR(20)); INSERT INTO Judgments (JudgmentID,CaseID,JudgmentDate,Judgment) VALUES (1,1,'2022-01-05','Favorable');
SELECT COUNT(*) FROM Judgments WHERE Judgment = 'Favorable' AND MONTH(JudgmentDate) = 1 AND YEAR(JudgmentDate) = 2022;
What is the average number of electric vehicle sales for Tesla and Nissan?
CREATE TABLE EV_Sales (Year INT,Make VARCHAR(50),Model VARCHAR(50),Sales INT); INSERT INTO EV_Sales (Year,Make,Model,Sales) VALUES (2020,'Tesla','Model 3',300000); INSERT INTO EV_Sales (Year,Make,Model,Sales) VALUES (2020,'Tesla','Model Y',150000); INSERT INTO EV_Sales (Year,Make,Model,Sales) VALUES (2019,'Nissan','Leaf',120000);
SELECT AVG(Sales) FROM EV_Sales WHERE Make IN ('Tesla', 'Nissan');
How many collective bargaining agreements were signed in New York in the year 2019?
CREATE TABLE collective_bargaining (id INT,location VARCHAR(255),year INT,num_agreements INT); INSERT INTO collective_bargaining (id,location,year,num_agreements) VALUES (1,'New York',2019,10),(2,'Los Angeles',2020,12),(3,'Chicago',2019,8);
SELECT COUNT(*) FROM collective_bargaining WHERE location = 'New York' AND year = 2019;
What is the total number of patients treated for depression and anxiety in the patient_treatment table?
CREATE TABLE patient_treatment (patient_id INT,condition VARCHAR(50),treatment_date DATE); INSERT INTO patient_treatment (patient_id,condition,treatment_date) VALUES (1,'Depression','2020-02-14'); INSERT INTO patient_treatment (patient_id,condition,treatment_date) VALUES (2,'Anxiety','2019-06-21'); INSERT INTO patient_treatment (patient_id,condition,treatment_date) VALUES (3,'Depression','2021-08-05');
SELECT SUM(CASE WHEN condition IN ('Depression', 'Anxiety') THEN 1 ELSE 0 END) FROM patient_treatment;
Which country had the most visitors in the museums database?
CREATE TABLE VisitorCountry (id INT,visitor_name VARCHAR(50),country VARCHAR(50));
SELECT country, COUNT(*) FROM VisitorCountry GROUP BY country ORDER BY COUNT(*) DESC LIMIT 1;
List the names and extraction amounts of minerals that are extracted by companies operating in Australia.
CREATE TABLE company (id INT,name VARCHAR(255),country VARCHAR(255));CREATE TABLE extraction (company_id INT,mineral VARCHAR(255),amount INT);
SELECT DISTINCT e.mineral, SUM(e.amount) as total_extraction FROM extraction e JOIN company c ON e.company_id = c.id WHERE c.country = 'Australia' GROUP BY e.mineral;
How many disability accommodations were provided for each type of disability in 2022?
CREATE TABLE DisabilityAccommodations (AccommodationID INT,DisabilityType VARCHAR(50),AccommodationDate DATE); INSERT INTO DisabilityAccommodations VALUES (1,'Mobility Impairment','2022-01-01'),(2,'Visual Impairment','2022-01-05'),(3,'Hearing Impairment','2022-01-10'),(4,'Mobility Impairment','2022-02-15'),(5,'Learning Disability','2022-03-01');
SELECT DisabilityType, COUNT(*) as NumAccommodations FROM DisabilityAccommodations WHERE YEAR(AccommodationDate) = 2022 GROUP BY DisabilityType;
Which menu items have been sold more than 500 times and are sourced sustainably?
CREATE TABLE menu_items (id INT,name TEXT,sustainable BOOLEAN,sales INT);
SELECT menu_items.name FROM menu_items WHERE menu_items.sales > 500 AND menu_items.sustainable = TRUE;
Delete policy records with a policy_type of 'Commercial Auto' and a policy_start_date older than 5 years
CREATE TABLE policy (policy_id INT,policy_holder_id INT,policy_type VARCHAR(50),policy_start_date DATE); INSERT INTO policy (policy_id,policy_holder_id,policy_type,policy_start_date) VALUES (1,10001,'Commercial Auto','2015-01-01'); INSERT INTO policy (policy_id,policy_holder_id,policy_type,policy_start_date) VALUES (2,10002,'Homeowners','2018-05-15');
DELETE FROM policy WHERE policy_type = 'Commercial Auto' AND policy_start_date < DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR);
How many renewable energy projects are there in total for each country?
CREATE TABLE projects (name TEXT,type TEXT,country TEXT); INSERT INTO projects (name,type,country) VALUES ('Project 1','Wind','USA'),('Project 2','Solar','Germany'),('Project 3','Wind','France');
SELECT country, COUNT(*) FROM projects GROUP BY country
List all multimodal mobility modes and their popularity scores in Paris
multimodal_mobility
SELECT * FROM multimodal_mobility WHERE city = 'Paris';