instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
Update the name of the dish "Chicken Tikka Masala" to "Tikka Masala with Chicken"
|
CREATE TABLE menu_items (id INT,name VARCHAR(255),category VARCHAR(255));
|
UPDATE menu_items SET name = 'Tikka Masala with Chicken' WHERE name = 'Chicken Tikka Masala';
|
List the countries and their military branches that use drone technology.
|
CREATE TABLE DroneMilitary (Country VARCHAR(255),Branch VARCHAR(255)); INSERT INTO DroneMilitary (Country,Branch) VALUES ('USA','Air Force'),('USA','Navy'),('Israel','Air Force'),('Turkey','Air Force');
|
SELECT Country FROM DroneMilitary WHERE Branch IN ('Air Force', 'Navy');
|
What is the total number of yellow and red cards issued to players from different countries in the 2022 FIFA World Cup?
|
CREATE TABLE yellow_red_cards (player_id INT,player_name VARCHAR(50),country VARCHAR(50),card_type VARCHAR(50)); INSERT INTO yellow_red_cards (player_id,player_name,country,card_type) VALUES (1,'Harry Kane','England','Yellow'),(2,'Luka Modric','Croatia','Yellow'),(3,'Lionel Messi','Argentina','Red'),(4,'Cristiano Ronaldo','Portugal','Yellow'),(5,'Neymar','Brazil','Yellow');
|
SELECT country, SUM(CASE WHEN card_type = 'Yellow' THEN 1 ELSE 0 END) as yellow_cards, SUM(CASE WHEN card_type = 'Red' THEN 1 ELSE 0 END) as red_cards FROM yellow_red_cards GROUP BY country;
|
Delete all menu items from Restaurant E that are not vegan or vegetarian.
|
CREATE TABLE menu (restaurant_id INT,item_name TEXT,item_type TEXT,diet TEXT); INSERT INTO menu (restaurant_id,item_name,item_type,diet) VALUES (1,'Spaghetti','Entree','Vegetarian'),(1,'Quinoa Salad','Entree','Vegan'),(1,'Garden Burger','Entree','Vegan'),(2,'Tofu Stir Fry','Entree','Vegan'),(2,'Vegetable Curry','Entree','Vegetarian'),(3,'Eggplant Parmesan','Entree','Vegetarian'),(3,'Vegetable Lasagna','Entree','Vegetarian'),(3,'Lentil Soup','Entree','Vegan'),(4,'Chickpea Salad','Entree','Vegan'),(4,'Mushroom Risotto','Entree','Vegetarian'),(4,'Spinach Stuffed Shells','Entree','Vegetarian'),(5,'Beef Stew','Entree','Carnivore'),(5,'Chicken Parmesan','Entree','Carnivore'),(5,'Fish Tacos','Entree','Seafood');
|
DELETE FROM menu WHERE restaurant_id = 5 AND diet NOT IN ('Vegan', 'Vegetarian');
|
How many employees in the employees table have a salary that is higher than the median salary in their department?
|
CREATE TABLE employees (employee_name VARCHAR(50),department_name VARCHAR(50),salary DECIMAL(10,2));
|
SELECT COUNT(*) FROM employees AS e1 WHERE salary > (SELECT AVG(salary) FROM (SELECT salary FROM employees AS e2 WHERE e1.department_name = e2.department_name ORDER BY salary LIMIT 2) AS e3);
|
Determine the number of agricultural innovation projects in the 'Innovation' table, grouped by type, that have a cost above the average?
|
CREATE TABLE Innovation (id INT,project VARCHAR(255),region VARCHAR(255),year INT,cost INT); INSERT INTO Innovation (id,project,region,year,cost) VALUES (1,'Precision Farming','Rural North',2013,2000000),(2,'Drip Irrigation','Urban East',2017,3000000),(3,'Soil Sensor','Rural South',2015,1000000),(4,'Vertical Farming','Urban West',2016,4000000);
|
SELECT SUBSTRING(project, 1, INSTR(project, ' ')-1) as project_type, COUNT(*) as num_projects FROM Innovation WHERE cost > (SELECT AVG(cost) FROM Innovation) GROUP BY project_type;
|
What is the total quantity of sustainable materials sourced from Africa?
|
CREATE TABLE africa_sourcing (id INT,material VARCHAR(50),country VARCHAR(50),quantity INT); INSERT INTO africa_sourcing (id,material,country,quantity) VALUES (1,'recycled polyester','Egypt',1500);
|
SELECT SUM(quantity) FROM africa_sourcing WHERE material = 'recycled polyester';
|
Delete records in the 'MultimodalHubs' table where 'hub_id' is 300
|
CREATE TABLE MultimodalHubs (hub_id INT,address VARCHAR(30),PRIMARY KEY (hub_id));
|
DELETE FROM MultimodalHubs WHERE hub_id = 300;
|
How many students received accommodations in "Southwest" region in 2019?
|
CREATE TABLE Accommodations (student_id INT,region VARCHAR(20),accommodation_date DATE); INSERT INTO Accommodations (student_id,region,accommodation_date) VALUES (1,'West Coast','2020-01-01'),(2,'East Coast','2019-12-31'),(3,'West Coast','2020-02-01'),(4,'Southwest','2019-01-01');
|
SELECT COUNT(*) FROM Accommodations WHERE region = 'Southwest' AND EXTRACT(YEAR FROM accommodation_date) = 2019;
|
What is the name of the port with UN/LOCODE 'NLRTM' in the 'ports' table?
|
CREATE TABLE ports (port_id INT,name VARCHAR(50),un_locode VARCHAR(10)); INSERT INTO ports (port_id,name,un_locode) VALUES (1,'Port of Rotterdam','NLRTM'),(2,'Port of Amsterdam','NLAMS');
|
SELECT name FROM ports WHERE un_locode = 'NLRTM';
|
Find the average investment amount for carbon offset projects in each region, excluding oceanic projects.
|
CREATE SCHEMA carbon_offsets; CREATE TABLE projects (project_name VARCHAR(255),region VARCHAR(255),investment_amount INT); INSERT INTO projects (project_name,region,investment_amount) VALUES ('Tropical Forest Conservation','Asia',5000000),('Wind Power Generation','Europe',8000000),('Soil Carbon Sequestration','Africa',3000000),('Oceanic Algae Farming','Oceania',7000000);
|
SELECT region, AVG(investment_amount) FROM carbon_offsets.projects WHERE region != 'Oceania' GROUP BY region;
|
What is the average waste generation rate per month in the 'MunicipalityA'?
|
CREATE TABLE MunicipalityA (WasteQuantity INT,GenerationDate DATE); INSERT INTO MunicipalityA (WasteQuantity,GenerationDate) VALUES (500,'2021-01-01'),(600,'2021-02-01'),(700,'2021-03-01');
|
SELECT AVG(WasteQuantity) FROM (SELECT WasteQuantity, ROW_NUMBER() OVER (PARTITION BY EXTRACT(MONTH FROM GenerationDate) ORDER BY GenerationDate) as rn FROM MunicipalityA) tmp WHERE rn = 1;
|
How many renewable energy projects have been completed in the state of California since 2015?
|
CREATE TABLE Renewable_Energy_Projects (id INT,project_name VARCHAR(30),state VARCHAR(20),completion_year INT); INSERT INTO Renewable_Energy_Projects (id,project_name,state,completion_year) VALUES (1,'Solar Farm 1','California',2016),(2,'Wind Farm 2','California',2017),(3,'Geothermal Plant 3','California',2018),(4,'Hydroelectric Dam 4','California',2019),(5,'Biomass Powerstation 5','California',2020);
|
SELECT COUNT(*) FROM Renewable_Energy_Projects WHERE state = 'California' AND completion_year >= 2015;
|
What is the total weight of Blue Dream strain produced in Oregon in Q1 of 2023?
|
CREATE TABLE production (id INT,strain_name VARCHAR(255),dispensary_name VARCHAR(255),state VARCHAR(255),production_weight INT,production_date DATE);
|
SELECT SUM(production_weight) FROM production WHERE strain_name = 'Blue Dream' AND state = 'Oregon' AND production_date BETWEEN '2023-01-01' AND '2023-03-31';
|
What is the total number of public transportation trips taken in 'nyc' in the last 30 days?
|
CREATE TABLE trips (id INT,city VARCHAR(20),trip_date DATE,mode VARCHAR(20),distance INT); INSERT INTO trips VALUES (1,'nyc','2022-01-01','subway',10); INSERT INTO trips VALUES (2,'nyc','2022-01-05','bus',15); INSERT INTO trips VALUES (3,'la','2022-01-10','light_rail',8);
|
SELECT SUM(distance) FROM trips WHERE city = 'nyc' AND trip_date >= DATEADD(day, -30, GETDATE());
|
What is the average speed of spacecraft in the "space_exploration" table, ordered by speed in descending order?
|
CREATE TABLE space_exploration (id INT,name VARCHAR(50),max_speed FLOAT,launch_date DATE); INSERT INTO space_exploration (id,name,max_speed,launch_date) VALUES (1,'Voyager 1',17000,'1977-09-05'); INSERT INTO space_exploration (id,name,max_speed,launch_date) VALUES (2,'New Horizons',14000,'2006-01-19');
|
SELECT AVG(max_speed) AS avg_speed FROM (SELECT max_speed, ROW_NUMBER() OVER (ORDER BY max_speed DESC) as row_num FROM space_exploration) tmp WHERE row_num = 1;
|
What is the minimum labor productivity in the mining industry?
|
CREATE TABLE labor_productivity (id INT,region VARCHAR(20),industry VARCHAR(20),productivity FLOAT); INSERT INTO labor_productivity (id,region,industry,productivity) VALUES (1,'Asia-Pacific','mining',2.5),(2,'Americas','mining',3.2),(3,'Europe','mining',1.8);
|
SELECT MIN(productivity) FROM labor_productivity WHERE industry = 'mining';
|
List all peacekeeping operations led by African countries in 2020.
|
CREATE TABLE peacekeeping_operations (operation_id INT,operation_name VARCHAR(255),leader_country VARCHAR(255),start_date DATE); INSERT INTO peacekeeping_operations (operation_id,operation_name,leader_country,start_date) VALUES (1,'Operation X','Country A','2020-01-01'),(2,'Operation Y','Country B','2019-01-01'),(3,'Operation Z','Country C','2020-12-31'); CREATE TABLE countries (country VARCHAR(255));
|
SELECT operation_name FROM peacekeeping_operations INNER JOIN countries ON peacekeeping_operations.leader_country = countries.country WHERE countries.country LIKE '%Africa%' AND YEAR(start_date) = 2020;
|
Which cities have a recycling rate lower than the average recycling rate for all cities in the 'North' region?
|
CREATE TABLE cities (city_name VARCHAR(50),region VARCHAR(50)); INSERT INTO cities (city_name,region) VALUES ('Chicago','North'),('Detroit','North'),('New York','East Coast'),('Boston','East Coast'); CREATE TABLE recycling_rates (city_name VARCHAR(50),region VARCHAR(50),recycling_rate DECIMAL(5,2)); INSERT INTO recycling_rates (city_name,region,recycling_rate) VALUES ('Chicago','North',0.30),('Detroit','North',0.25),('New York','East Coast',0.35),('Boston','East Coast',0.40);
|
SELECT city_name FROM recycling_rates WHERE region = 'North' AND recycling_rate < (SELECT AVG(recycling_rate) FROM recycling_rates WHERE region = 'North');
|
What is the total number of disaster response drills performed by the police and fire departments in 2022?
|
CREATE TABLE drills (id SERIAL PRIMARY KEY,department VARCHAR(255),drill_date DATE); INSERT INTO drills (department,drill_date) VALUES ('Police','2022-03-01'),('Fire','2022-03-01'),('Police','2022-06-15'),('Fire','2022-06-15');
|
SELECT COUNT(id) as total_drills FROM drills WHERE department IN ('Police', 'Fire') AND drill_date >= '2022-01-01' AND drill_date < '2023-01-01';
|
What is the average trip duration for tourists visiting South Africa from Asia?
|
CREATE TABLE trip_duration (destination_country VARCHAR(50),visitor_country VARCHAR(50),avg_duration FLOAT); INSERT INTO trip_duration (destination_country,visitor_country,avg_duration) VALUES ('South Africa','Asia',10.5);
|
SELECT avg_duration FROM trip_duration WHERE destination_country = 'South Africa' AND visitor_country = 'Asia';
|
How many unique species have been observed per year in the Arctic?
|
CREATE TABLE SpeciesObservations (year INT,species TEXT); INSERT INTO SpeciesObservations (year,species) VALUES (2000,'Polar Bear'),(2000,'Arctic Fox'),(2001,'Polar Bear'),(2001,'Arctic Fox'),(2001,'Beluga Whale'),(2002,'Polar Bear'),(2002,'Arctic Fox'),(2002,'Beluga Whale'),(2002,'Reindeer'),(2003,'Polar Bear'),(2003,'Arctic Fox'),(2003,'Beluga Whale'),(2003,'Reindeer'),(2003,'Walrus');
|
SELECT year, COUNT(DISTINCT species) FROM SpeciesObservations GROUP BY year;
|
Compare the number of sustainable fabric types used by brands 'Green Visions' and 'Ethical Fashions' in the 'Textiles' table.
|
CREATE TABLE Textiles (brand VARCHAR(20),fabric_type VARCHAR(20)); INSERT INTO Textiles (brand,fabric_type) VALUES ('Eco-friendly Fashions','Organic Cotton'),('Eco-friendly Fashions','Recycled Polyester'),('Fab Fashions','Viscose'),('Fab Fashions','Recycled Polyester'),('Fab Fashions','Hemp'),('Green Visions','Organic Silk'),('Green Visions','Ecovero'),('Ethical Fashions','Tencel'),('Ethical Fashions','Lyocell');
|
SELECT COUNT(DISTINCT fabric_type) FROM Textiles WHERE brand = 'Green Visions' INTERSECT SELECT COUNT(DISTINCT fabric_type) FROM Textiles WHERE brand = 'Ethical Fashions';
|
What's the average ESG rating of companies in the technology sector that have received investments since 2020?
|
CREATE TABLE companies (id INT,sector VARCHAR(20),ESG_rating FLOAT); INSERT INTO companies (id,sector,ESG_rating) VALUES (1,'technology',78.3),(2,'healthcare',81.5),(3,'technology',84.1); CREATE TABLE investments (id INT,company_id INT,investment_date DATE); INSERT INTO investments (id,company_id,investment_date) VALUES (1,1,'2021-01-01'),(2,3,'2020-12-31'),(3,2,'2019-12-31');
|
SELECT AVG(companies.ESG_rating) FROM companies INNER JOIN investments ON companies.id = investments.company_id WHERE companies.sector = 'technology' AND investments.investment_date >= '2020-01-01';
|
What is the average annual humanitarian aid expenditure for each region in the 'humanitarian_aid' and 'regions' tables?
|
CREATE TABLE regions (region_id INT,region_name VARCHAR(50)); CREATE TABLE humanitarian_aid (aid_id INT,year INT,amount INT,region_id INT); INSERT INTO regions VALUES (1,'Africa'),(2,'Asia'),(3,'Europe'); INSERT INTO humanitarian_aid VALUES (1,2015,100,1),(2,2016,150,1),(3,2015,200,2),(4,2016,250,2),(5,2015,300,3),(6,2016,350,3);
|
SELECT r.region_name, AVG(h.amount) as avg_annual_expenditure FROM regions r JOIN humanitarian_aid h ON r.region_id = h.region_id GROUP BY r.region_name;
|
Calculate the total amount of restorative justice grants awarded per year
|
CREATE TABLE grants (id INT PRIMARY KEY,date_awarded DATE,type VARCHAR(255),amount DECIMAL(10,2));
|
SELECT YEAR(date_awarded) AS year, SUM(amount) AS total_amount FROM grants WHERE type = 'Restorative Justice' GROUP BY year;
|
Show the total revenue for each region in the "regional_sales" and "regions" tables, considering only regions with at least one sale.
|
CREATE TABLE regions (id INT PRIMARY KEY,region_name VARCHAR(50)); CREATE TABLE regional_sales (id INT PRIMARY KEY,plan_id INT,region_id INT,quantity INT); INSERT INTO regions (id,region_name) VALUES (1,'North'),(2,'South'),(3,'East'),(4,'West'); INSERT INTO regional_sales (id,plan_id,region_id,quantity) VALUES (1,1,1,10),(2,2,3,5),(3,1,4,8);
|
SELECT r.region_name, SUM(regional_sales.quantity * plans.monthly_cost) AS total_revenue FROM regional_sales INNER JOIN plans ON regional_sales.plan_id = plans.id INNER JOIN regions ON regional_sales.region_id = regions.id GROUP BY regions.region_name HAVING COUNT(regions.id) > 0;
|
What is the average carbon offset of initiatives in the 'CarbonOffset' schema, grouped by initiative type?
|
CREATE SCHEMA CarbonOffset; CREATE TABLE Initiatives (initiative_id INT,name VARCHAR(50),location VARCHAR(50),initiative_type VARCHAR(20),carbon_offset FLOAT); INSERT INTO Initiatives (initiative_id,name,location,initiative_type,carbon_offset) VALUES (1,'Tree Planting A','City A','Tree Planting',500.0),(2,'Carbon Capture B','City B','Carbon Capture',750.0);
|
SELECT initiative_type, AVG(carbon_offset) FROM CarbonOffset.Initiatives GROUP BY initiative_type;
|
How many products are made from 'Organic Cotton' in each country?
|
CREATE TABLE products (product_id INT,name TEXT,material TEXT,country TEXT); INSERT INTO products (product_id,name,material,country) VALUES (1,'Organic Cotton Shirt','Organic Cotton','India'),(2,'Regular Cotton Shirt','Cotton','China'); CREATE TABLE countries (country TEXT,region TEXT); INSERT INTO countries (country,region) VALUES ('India','Asia'),('China','Asia');
|
SELECT countries.country, COUNT(*) as product_count FROM products INNER JOIN countries ON products.country = countries.country WHERE products.material = 'Organic Cotton' GROUP BY countries.country;
|
What is the average viewership for TV shows in the horror genre?
|
CREATE TABLE tv_show (id INT,title VARCHAR(100),genre VARCHAR(20),average_viewership INT); INSERT INTO tv_show (id,title,genre,average_viewership) VALUES (1,'Stranger Things','Horror',15000000);
|
SELECT AVG(average_viewership) FROM tv_show WHERE genre = 'Horror';
|
What is the minimum population size for cities in the "city_data" table that are located in 'CountryB'?
|
CREATE TABLE city_data (city_name VARCHAR(50),state VARCHAR(50),country VARCHAR(50),population INT); INSERT INTO city_data (city_name,state,country,population) VALUES ('CityN','StateN','CountryB',300000),('CityO','StateO','CountryB',400000),('CityP','StateP','CountryC',500000);
|
SELECT MIN(population) FROM city_data WHERE country = 'CountryB';
|
What is the total transaction value for decentralized exchanges in the US?
|
CREATE TABLE decentralized_exchanges (exchange_name TEXT,country TEXT,daily_transaction_value INTEGER); INSERT INTO decentralized_exchanges (exchange_name,country,daily_transaction_value) VALUES ('Uniswap','US',15000000),('Sushiswap','US',8000000);
|
SELECT SUM(daily_transaction_value) FROM decentralized_exchanges WHERE country = 'US';
|
Which forests in Russia have more than 10 distinct years of timber production data?
|
CREATE TABLE Forests (id INT,name VARCHAR(50),hectares FLOAT,country VARCHAR(50)); INSERT INTO Forests (id,name,hectares,country) VALUES (1,'Amazon Rainforest',55000000.0,'Brazil'); CREATE TABLE Timber_Production (id INT,forest_id INT,year INT,production_cubic_meters INT); INSERT INTO Timber_Production (id,forest_id,year,production_cubic_meters) VALUES (1,1,2000,15000);
|
SELECT forest_id FROM Timber_Production WHERE forest_id IN (SELECT id FROM Forests WHERE country = 'Russia') GROUP BY forest_id HAVING COUNT(DISTINCT year) > 10;
|
How many decentralized applications are on the Cardano platform?
|
CREATE TABLE dapps (dapp_id INT,name VARCHAR(100),platform VARCHAR(50)); INSERT INTO dapps (dapp_id,name,platform) VALUES (1,'SingularityNET','Cardano'),(2,'OccamFi','Cardano'),(3,'Liqwid','Cardano');
|
SELECT COUNT(*) FROM dapps WHERE platform = 'Cardano';
|
What is the average weight of satellites launched by OneWeb?
|
CREATE TABLE Satellite_Weight_OneWeb (id INT,name VARCHAR(50),manufacturer VARCHAR(50),weight INT); INSERT INTO Satellite_Weight_OneWeb (id,name,manufacturer,weight) VALUES (1,'OneWeb 1','OneWeb',150),(2,'OneWeb 2','OneWeb',155),(3,'OneWeb 3','OneWeb',160);
|
SELECT AVG(weight) FROM Satellite_Weight_OneWeb WHERE manufacturer = 'OneWeb';
|
What is the total volume of timber produced per year by country and species?
|
CREATE TABLE countries (country_id INT,country_name VARCHAR(100)); INSERT INTO countries (country_id,country_name) VALUES (1,'Canada'),(2,'USA'),(3,'Brazil'); CREATE TABLE tree_species (species_id INT,species_name VARCHAR(100),avg_carbon_sequestration_rate DECIMAL(5,2)); INSERT INTO tree_species (species_id,species_name,avg_carbon_sequestration_rate) VALUES (1,'Oak',15.5),(2,'Pine',12.8),(3,'Maple',18.2),(4,'Birch',10.9); CREATE TABLE timber_production (production_id INT,country_id INT,species_id INT,year INT,volume INT); INSERT INTO timber_production (production_id,country_id,species_id,year,volume) VALUES (1,1,1,2000,1200),(2,1,2,2000,800),(3,2,3,2000,1500),(4,2,4,2000,900);
|
SELECT c.country_name, ts.species_name, tp.year, SUM(tp.volume) as total_volume FROM timber_production tp JOIN countries c ON tp.country_id = c.country_id JOIN tree_species ts ON tp.species_id = ts.species_id GROUP BY c.country_name, ts.species_name, tp.year;
|
What is the maximum bioprocess engineering cost for projects in Spain?
|
CREATE TABLE costs (id INT,project VARCHAR(50),country VARCHAR(50),cost FLOAT); INSERT INTO costs (id,project,country,cost) VALUES (1,'Bioprocess1','Spain',80000); INSERT INTO costs (id,project,country,cost) VALUES (2,'Bioprocess2','Spain',90000); INSERT INTO costs (id,project,country,cost) VALUES (3,'Bioprocess3','Spain',70000);
|
SELECT MAX(cost) FROM costs WHERE country = 'Spain';
|
Find the concert with the highest ticket price.
|
CREATE TABLE concerts (id INT,artist_id INT,location TEXT,price DECIMAL); INSERT INTO concerts (id,artist_id,location,price) VALUES (1,1,'New York,USA',200);
|
SELECT * FROM concerts ORDER BY price DESC LIMIT 1;
|
What was the average cost of rural community development initiatives in Peru in 2017?
|
CREATE TABLE Community_Development (id INT,country VARCHAR(50),year INT,cost FLOAT); INSERT INTO Community_Development (id,country,year,cost) VALUES (1,'Peru',2017,20000.0),(2,'Brazil',2018,30000.0),(3,'Peru',2019,25000.0);
|
SELECT AVG(cost) FROM Community_Development WHERE country = 'Peru' AND year = 2017;
|
How many infrastructure projects were completed in the top 5 provinces with the most completed projects?
|
CREATE TABLE RuralInfrastructure (province VARCHAR(50),year INT,project VARCHAR(50),status VARCHAR(50));
|
SELECT project FROM (SELECT province, project, ROW_NUMBER() OVER(PARTITION BY province ORDER BY COUNT(*) DESC) as rn FROM RuralInfrastructure WHERE status = 'completed' GROUP BY province, project) WHERE rn <= 5;
|
Show the number of fans from each location
|
CREATE TABLE fans (id INT PRIMARY KEY,age INT,gender VARCHAR(255),location VARCHAR(255)); INSERT INTO fans (id,age,gender,location) VALUES (1,25,'Female','Los Angeles'); INSERT INTO fans (id,age,gender,location) VALUES (2,35,'Male','New York'); INSERT INTO fans (id,age,gender,location) VALUES (3,30,'Non-binary','Toronto');
|
SELECT location, COUNT(*) FROM fans GROUP BY location;
|
Calculate the total waste produced by each manufacturing process
|
CREATE TABLE manufacturing_processes (process_id INT,process_name VARCHAR(255),waste_generated INT); INSERT INTO manufacturing_processes (process_id,process_name,waste_generated) VALUES (1,'Process E',100),(2,'Process F',150),(3,'Process G',200),(4,'Process H',250);
|
SELECT process_name, SUM(waste_generated) as total_waste_generated FROM manufacturing_processes GROUP BY process_name;
|
Delete all records from the 'habitat_preservation' table where the preservation status is 'Critical' and the region is 'Asia'.
|
CREATE TABLE habitat_preservation (id INT,region VARCHAR(255),preservation_status VARCHAR(255)); INSERT INTO habitat_preservation (id,region,preservation_status) VALUES (1,'Asia','Critical'),(2,'Africa','Vulnerable'),(3,'South America','Stable');
|
DELETE FROM habitat_preservation WHERE preservation_status = 'Critical' AND region = 'Asia';
|
What is the average salary of employees who work in the 'Quality' department?
|
CREATE TABLE Employees (EmployeeID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50),Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,Salary) VALUES (1,'John','Doe','Assembly',60000.00),(2,'Jane','Doe','Quality',55000.00),(3,'Mike','Smith','Assembly',52000.00);
|
SELECT AVG(Salary) FROM Employees WHERE Department = 'Quality';
|
What is the average horsepower of sedans and SUVs combined in the 'vehicle_specs' table?
|
CREATE TABLE vehicle_specs (vehicle_name VARCHAR(50),vehicle_type VARCHAR(20),horsepower INT);
|
SELECT AVG(horsepower) FROM vehicle_specs WHERE vehicle_type IN ('Sedan', 'SUV');
|
What are the average medical metrics for astronauts from 'USA'?
|
CREATE TABLE AstronautData (id INT,name VARCHAR(50),country VARCHAR(50),height FLOAT,weight FLOAT,blood_pressure FLOAT); INSERT INTO AstronautData (id,name,country,height,weight,blood_pressure) VALUES (1,'John','USA',180,80,120),(2,'Jane','Canada',170,70,110),(3,'Alex','USA',190,90,130);
|
SELECT AVG(height), AVG(weight), AVG(blood_pressure) FROM AstronautData WHERE country = 'USA';
|
What is the average investment amount in each industry category?
|
CREATE TABLE Companies (CompanyID INT,CompanyName VARCHAR(50),Industry VARCHAR(30)); CREATE TABLE Investments (InvestmentID INT,InvestorID INT,CompanyID INT,InvestmentAmount DECIMAL(10,2));
|
SELECT C.Industry, AVG(I.InvestmentAmount) AS AvgInvestmentAmount FROM Companies C JOIN Investments I ON C.CompanyID = I.CompanyID GROUP BY C.Industry;
|
List the name and material of all the building permits issued in the last 3 months.
|
CREATE TABLE Permits (id INT,name TEXT,issue_date DATE,material TEXT); INSERT INTO Permits (id,name,issue_date,material) VALUES (1,'High-Rise Construction','2023-02-01','Concrete'),(2,'Townhome Construction','2023-03-15','Wood');
|
SELECT name, material FROM Permits WHERE issue_date > (CURRENT_DATE - INTERVAL '3 months')
|
What is the average sustainability score for Tropical Wear trends that use Hemp as their fabric type?
|
CREATE TABLE FashionTrends (trend_id INT,category VARCHAR(255),popularity INT,sustainability_score DECIMAL(3,2));CREATE TABLE FabricSources (source_id INT,fabric_type VARCHAR(255),country_of_origin VARCHAR(255),ethical_rating DECIMAL(3,2));CREATE TABLE Garments (garment_id INT,trend_id INT,fabric_source_id INT);CREATE VIEW EthicalFabricSources AS SELECT * FROM FabricSources WHERE ethical_rating >= 8.0;CREATE VIEW TropicalWearHempTrends AS SELECT * FROM FashionTrends WHERE category = 'Tropical Wear' AND trend_id IN (SELECT trend_id FROM Garments WHERE fabric_source_id IN (SELECT source_id FROM EthicalFabricSources WHERE fabric_type = 'Hemp'));
|
SELECT AVG(sustainability_score) FROM TropicalWearHempTrends;
|
What is the average monthly data usage per mobile subscriber for each state, excluding those subscribers with a monthly data usage of 0?
|
CREATE TABLE states (id INT,name VARCHAR(255));CREATE TABLE mobile_subscribers (id INT,state_id INT,monthly_data_usage DECIMAL(10,2));
|
SELECT s.name, AVG(ms.monthly_data_usage) as avg_data_usage FROM states s INNER JOIN mobile_subscribers ms ON s.id = ms.state_id WHERE ms.monthly_data_usage > 0 GROUP BY s.name;
|
What is the average agricultural innovation investment per community in Africa?
|
CREATE TABLE community (id INT,name TEXT,location TEXT,investment_amount INT); INSERT INTO community (id,name,location,investment_amount) VALUES (1,'Kirumba','Uganda',5000),(2,'Bangangte','Cameroon',8000),(3,'Mpumalanga','South Africa',12000);
|
SELECT AVG(investment_amount) FROM community WHERE location LIKE 'Africa%'
|
What is the average grade of all students enrolled in the 'Data Science' program?
|
CREATE TABLE Students (ID INT,Name VARCHAR(50),Program VARCHAR(50),Grade FLOAT); INSERT INTO Students (ID,Name,Program,Grade) VALUES (1,'John Doe','Data Science',85.6),(2,'Jane Smith','Computer Science',88.2);
|
SELECT AVG(Grade) FROM Students WHERE Program = 'Data Science';
|
What is the maximum number of goals scored in a single game by a player from Japan?
|
CREATE TABLE players (player_id INT,name TEXT,country TEXT); INSERT INTO players (player_id,name,country) VALUES (1,'Okazaki','Japan'),(2,'Iniesta','Spain'),(3,'Matsui','Japan'); CREATE TABLE goals (goal_id INT,player_id INT,league TEXT,goals INT); INSERT INTO goals (goal_id,player_id,league,goals) VALUES (1,1,'Bundesliga',3),(2,1,'Bundesliga',2),(3,2,'La Liga',4),(4,2,'La Liga',5),(5,3,'J League',6);
|
SELECT MAX(goals) FROM goals JOIN players ON goals.player_id = players.player_id WHERE players.country = 'Japan';
|
What is the total number of community health centers in 'southeast' and 'southwest' regions?
|
CREATE TABLE centers (id INT,name TEXT,region TEXT); INSERT INTO centers (id,name,region) VALUES (1,'Center A','southeast'); INSERT INTO centers (id,name,region) VALUES (2,'Center B','southwest'); INSERT INTO centers (id,name,region) VALUES (3,'Center C','northwest');
|
SELECT 'Total Community Health Centers', COUNT(*) FROM ( (SELECT * FROM centers WHERE region IN ('southeast', 'southwest')) );
|
List the top 3 teams with the highest total ticket sales, along with their total sales, in descending order.
|
CREATE TABLE ticket_sales (team_id INT,team_name VARCHAR(50),total_sales DECIMAL(10,2)); INSERT INTO ticket_sales (team_id,team_name,total_sales) VALUES (1,'Team A',45000.00),(2,'Team B',32000.00),(3,'Team C',50000.00),(4,'Team D',42000.00),(5,'Team E',38000.00);
|
SELECT team_name, total_sales FROM (SELECT team_name, total_sales, ROW_NUMBER() OVER (ORDER BY total_sales DESC) AS rank FROM ticket_sales) AS team_ranks WHERE rank <= 3;
|
What are the names of the heritage sites that were added to the list in the last 3 years, along with the year they were added?
|
CREATE TABLE UNESCO_Heritage_Sites (id INT,site VARCHAR(100),year INT); INSERT INTO UNESCO_Heritage_Sites (id,site,year) VALUES (1,'Colosseum',1980),(2,'Great Wall',1987),(3,'Alhambra',1984),(4,'Machu Picchu',1983),(5,'Petra',1985);
|
SELECT site, year FROM UNESCO_Heritage_Sites WHERE year >= YEAR(CURRENT_DATE) - 3;
|
Update records in the 'electric_vehicles' table where the 'battery_capacity' is less than 70
|
CREATE TABLE electric_vehicles (id INT,model VARCHAR(50),battery_capacity INT);
|
UPDATE electric_vehicles SET battery_capacity = 75 WHERE battery_capacity < 70;
|
Display the names of companies that have not received any funding
|
CREATE TABLE funds (company_id INT,funding_amount DECIMAL(10,2),funding_date DATE); INSERT INTO funds VALUES (1,500000,'2022-01-01'); INSERT INTO funds VALUES (2,300000,'2021-06-15');
|
SELECT company_name FROM companies LEFT JOIN funds ON companies.company_id = funds.company_id WHERE funds.funding_amount IS NULL;
|
Find the number of new donors each month in the past year, and the total amount donated by new donors each month.
|
CREATE TABLE Donors (DonorID INT,DonorName TEXT,DonationDate DATE,Amount DECIMAL(10,2));
|
SELECT DATEPART(month, DonationDate) AS Month, DATEPART(year, DonationDate) AS Year, COUNT(DISTINCT DonorID) AS NewDonors, SUM(Amount) AS TotalDonated FROM Donors WHERE DonationDate >= DATEADD(year, -1, GETDATE()) GROUP BY DATEPART(month, DonationDate), DATEPART(year, DonationDate);
|
What is the total number of hours spent on technical skills training for employees in the 'Finance' department?
|
CREATE TABLE Training (Employee_ID INT,Training_Type VARCHAR(50),Hours_Spent DECIMAL(5,2)); INSERT INTO Training (Employee_ID,Training_Type,Hours_Spent) VALUES (3,'Technical Skills',8.00),(4,'Technical Skills',10.00),(5,'Technical Skills',6.00),(9,'Technical Skills',9.00),(10,'Technical Skills',7.00);
|
SELECT SUM(Hours_Spent) FROM Training WHERE Employee_ID IN (SELECT Employee_ID FROM Employee WHERE Department = 'Finance');
|
What is the total number of volunteers in Jordan and the number of unique skills they have?
|
CREATE TABLE volunteers (id INT,country VARCHAR(255),name VARCHAR(255),skill VARCHAR(255)); INSERT INTO volunteers (id,country,name,skill) VALUES (1,'Jordan','Volunteer 1','Skill 1'),(2,'Jordan','Volunteer 2','Skill 2'),(3,'Jordan','Volunteer 3','Skill 1'),(4,'Jordan','Volunteer 4','Skill 3');
|
SELECT country, COUNT(*) FROM volunteers GROUP BY country; SELECT country, COUNT(DISTINCT skill) FROM volunteers GROUP BY country;
|
Identify the bottom 3 rural counties with the highest percentage of residents living below the poverty line.
|
CREATE TABLE county (name VARCHAR(50),population INT,poverty_rate FLOAT); INSERT INTO county (name,population,poverty_rate) VALUES ('Greenfield',25000,15.5); INSERT INTO county (name,population,poverty_rate) VALUES ('Pineville',18000,18.0); INSERT INTO county (name,population,poverty_rate) VALUES ('Riverton',32000,12.8); INSERT INTO county (name,population,poverty_rate) VALUES ('Seabrook',21000,16.2); INSERT INTO county (name,population,poverty_rate) VALUES ('Whitmore',19000,19.5); INSERT INTO county (name,population,poverty_rate) VALUES ('Elmfield',27000,14.3);
|
SELECT name, poverty_rate FROM county ORDER BY poverty_rate DESC LIMIT 3;
|
What is the average virtual tour engagement time in Africa?
|
CREATE TABLE virtual_tour_engagement (engagement_id INT,tour_id INT,engagement_time FLOAT); INSERT INTO virtual_tour_engagement (engagement_id,tour_id,engagement_time) VALUES (1,1,15.5),(2,2,20.0),(3,3,18.3),(4,4,12.7),(5,5,19.8); CREATE TABLE tour_region (tour_id INT,region TEXT); INSERT INTO tour_region (tour_id,region) VALUES (1,'Africa'),(2,'Africa'),(3,'Africa'),(4,'Africa'),(5,'Africa');
|
SELECT AVG(engagement_time) FROM virtual_tour_engagement INNER JOIN tour_region ON virtual_tour_engagement.tour_id = tour_region.tour_id WHERE tour_region.region = 'Africa';
|
What is the total cost of astrophysics research projects with a duration over 3 years?
|
CREATE TABLE AstroPhysicsResearch (id INT,project_name VARCHAR(30),cost FLOAT,duration INT);
|
SELECT SUM(cost) FROM AstroPhysicsResearch WHERE duration > 3 AND project_name LIKE 'Astro%';
|
What is the total quantity of products sold through transparent supply chains, by brand and country?
|
CREATE TABLE Brands (id INT,brand VARCHAR(255),country VARCHAR(255)); INSERT INTO Brands (id,brand,country) VALUES (1,'BrandA','USA'),(2,'BrandB','Canada'),(3,'BrandC','Mexico'); CREATE TABLE Sales (id INT,brand_id INT,product VARCHAR(255),quantity INT,transparent_supply_chain BOOLEAN); INSERT INTO Sales (id,brand_id,product,quantity,transparent_supply_chain) VALUES (1,1,'Product1',50,true),(2,1,'Product2',75,true),(3,2,'Product3',30,false),(4,2,'Product4',40,false),(5,3,'Product5',60,true),(6,3,'Product6',80,true);
|
SELECT s.country, b.brand, SUM(s.quantity) AS total_quantity FROM Sales s JOIN Brands b ON s.brand_id = b.id WHERE s.transparent_supply_chain = true GROUP BY s.country, b.brand;
|
What is the total budget for technology for social good initiatives in 'Asia' and 'Europe'?
|
CREATE TABLE tech_for_social_good_budget (initiative_id INT,initiative_name VARCHAR(255),region VARCHAR(255),budget DECIMAL(10,2)); INSERT INTO tech_for_social_good_budget (initiative_id,initiative_name,region,budget) VALUES (1,'Smart city project','Asia',1000000),(2,'Green technology initiative','Europe',800000),(3,'Accessible technology for rural areas','Asia',500000),(4,'Educational technology for refugees','Europe',900000),(5,'Women in tech program','Asia',700000);
|
SELECT SUM(budget) as total_budget, region FROM tech_for_social_good_budget WHERE region IN ('Asia', 'Europe') GROUP BY region;
|
Which countries have the highest CO2 emissions from garment manufacturing?
|
CREATE TABLE country_emissions (country_name VARCHAR(50),co2_emissions DECIMAL(10,2));
|
SELECT country_name, co2_emissions FROM country_emissions ORDER BY co2_emissions DESC LIMIT 5;
|
Delete all multimodal mobility records for 'madrid' before 2020-01-01
|
CREATE TABLE if not exists mobility_data (mobility_type varchar(20),city varchar(20),date date); INSERT INTO mobility_data (mobility_type,city,date) VALUES ('multimodal','madrid','2019-12-31'),('multimodal','madrid','2020-01-01'),('multimodal','madrid','2020-01-02');
|
DELETE FROM mobility_data WHERE mobility_type = 'multimodal' AND city = 'madrid' AND date < '2020-01-01';
|
What is the total fish weight and feed conversion ratio for each country in 2020?
|
CREATE TABLE Country_Feed (Country TEXT,Year INT,Fish_Weight FLOAT,Feed_Conversion_Ratio FLOAT); INSERT INTO Country_Feed (Country,Year,Fish_Weight,Feed_Conversion_Ratio) VALUES ('China',2019,1200000,1.2),('Indonesia',2019,800000,1.3),('India',2019,600000,1.1),('China',2020,1400000,1.15),('Indonesia',2020,900000,1.2),('India',2020,700000,1.12);
|
SELECT Country, SUM(Fish_Weight) OVER (PARTITION BY Country) AS Total_Fish_Weight, Feed_Conversion_Ratio FROM Country_Feed WHERE Year = 2020;
|
What are the names of the marine species in the Pacific Ocean?
|
CREATE TABLE marine_species (id INT,species_name TEXT,ocean_basin TEXT);
|
SELECT species_name FROM marine_species WHERE ocean_basin = 'Pacific Ocean';
|
What are the names and gas prices of smart contracts on the Binance Smart Chain with gas prices above the average?
|
CREATE TABLE smart_contracts (contract_id INT,name VARCHAR(50),developer_id INT,gas_price DECIMAL(10,2),network VARCHAR(50)); INSERT INTO smart_contracts (contract_id,name,developer_id,gas_price,network) VALUES (1,'BSCContract1',1,21000,'Binance Smart Chain'),(2,'BSCContract2',2,19000,'Binance Smart Chain');
|
SELECT smart_contracts.name, smart_contracts.gas_price FROM smart_contracts WHERE smart_contracts.network = 'Binance Smart Chain' AND smart_contracts.gas_price > (SELECT AVG(smart_contracts.gas_price) FROM smart_contracts WHERE smart_contracts.network = 'Binance Smart Chain');
|
What was the maximum score of players from Europe in the 'recent_tournament' table?
|
CREATE TABLE recent_tournament (player_id INT,player_name TEXT,score INT,country TEXT);
|
SELECT MAX(score) FROM recent_tournament WHERE country = 'Europe';
|
Update the hospital name for hospital_id 1.
|
CREATE TABLE hospitals (hospital_id INT,hospital_name VARCHAR(100),rural BOOLEAN); INSERT INTO hospitals (hospital_id,hospital_name,rural) VALUES (1,'Rural Hospital A',true),(2,'Urban Hospital B',false);
|
UPDATE hospitals SET hospital_name = 'New Rural Hospital A' WHERE hospital_id = 1;
|
Update the network investment amount to $52,000 for the record with the investment date of '2022-04-01' in the 'Africa' region.
|
CREATE TABLE network_investments (id INT,region VARCHAR(20),investment_date DATE,amount DECIMAL(10,2)); INSERT INTO network_investments (id,region,investment_date,amount) VALUES (1,'Europe','2022-01-01',50000.00),(2,'Asia','2022-02-01',75000.00),(3,'Europe','2022-03-01',60000.00),(4,'Africa','2022-04-01',45000.00),(5,'Africa','2022-05-01',55000.00);
|
UPDATE network_investments SET amount = 52000 WHERE region = 'Africa' AND investment_date = '2022-04-01';
|
How many droughts have been declared in Canada since 2000?
|
CREATE TABLE drought_declarations_canada (province VARCHAR(50),year INT); INSERT INTO drought_declarations_canada (province,year) VALUES ('Ontario',2000),('Alberta',2003),('British Columbia',2006);
|
SELECT COUNT(*) FROM drought_declarations_canada WHERE year >= 2000;
|
What is the total number of flight hours for each aircraft model in the flight_hours table?
|
CREATE TABLE flight_hours (flight_id INT,model_id INT,flight_hours INT);
|
SELECT model_id, SUM(flight_hours) as total_flight_hours FROM flight_hours GROUP BY model_id;
|
How many volunteers and donors are there for each program?
|
CREATE TABLE program_volunteers (program_id INT,volunteer_id INT); INSERT INTO program_volunteers (program_id,volunteer_id) VALUES (100,1),(100,2),(200,3); CREATE TABLE program_donors (program_id INT,donor_id INT); INSERT INTO program_donors (program_id,donor_id) VALUES (100,4),(100,5),(200,6);
|
SELECT p.name, COUNT(DISTINCT v.id) AS num_volunteers, COUNT(DISTINCT d.id) AS num_donors FROM programs p LEFT JOIN program_volunteers v ON p.id = v.program_id LEFT JOIN program_donors d ON p.id = d.program_id GROUP BY p.name;
|
List the top 5 most productive graduate students in terms of published papers in the College of Arts and Sciences, excluding students who have not published any papers.
|
CREATE TABLE students (id INT,name VARCHAR(50),department VARCHAR(50)); CREATE TABLE papers (id INT,student_id INT,title VARCHAR(100)); INSERT INTO students VALUES (1,'Dana','Arts and Sciences'),(2,'Eli','Arts and Sciences'),(3,'Fiona','Arts and Sciences'); INSERT INTO papers VALUES (1,1,'Paper 1'),(2,1,'Paper 2'),(3,2,'Paper 3'),(4,3,'Paper 4'),(5,3,'Paper 5'),(6,3,'Paper 6');
|
SELECT student_id, COUNT(*) AS paper_count FROM papers GROUP BY student_id ORDER BY paper_count DESC LIMIT 5;
|
How many unique donors have donated to each organization in the past 3 years?
|
CREATE TABLE donor_org (donor_id INT,org_id INT,donation_year INT); INSERT INTO donor_org (donor_id,org_id,donation_year) VALUES (1,1,2019),(2,1,2020),(3,1,2021),(4,2,2019),(5,2,2020),(6,2,2021),(7,3,2019),(8,3,2020),(9,3,2021);
|
SELECT org_id, COUNT(DISTINCT donor_id) num_donors FROM donor_org WHERE donation_year BETWEEN (YEAR(CURRENT_DATE) - 3) AND YEAR(CURRENT_DATE) GROUP BY org_id;
|
What percentage of products are certified cruelty-free in the UK?
|
CREATE TABLE cosmetics.product_safety (product_id INT,country VARCHAR(50),is_cruelty_free BOOLEAN); INSERT INTO cosmetics.product_safety (product_id,country,is_cruelty_free) VALUES (1,'UK',true),(2,'France',false),(3,'Germany',true),(4,'Italy',true),(5,'Spain',false);
|
SELECT (SUM(is_cruelty_free) * 100.0 / COUNT(*)) as cruelty_free_percentage FROM cosmetics.product_safety WHERE country = 'UK';
|
List the names of all wells that produced more than 1,000,000 barrels of oil in North Dakota in 2019
|
CREATE TABLE oil_production (id INT,well_id INT,state VARCHAR(20),year INT,oil_volume FLOAT); INSERT INTO oil_production (id,well_id,state,year,oil_volume) VALUES (1,1,'North Dakota',2019,1200000); INSERT INTO oil_production (id,well_id,state,year,oil_volume) VALUES (2,2,'Texas',2020,1500000); INSERT INTO oil_production (id,well_id,state,year,oil_volume) VALUES (3,3,'North Dakota',2018,1800000);
|
SELECT well_id, well_name, oil_volume FROM wells w INNER JOIN oil_production op ON w.id = op.well_id WHERE state = 'North Dakota' AND year = 2019 AND oil_volume > 1000000;
|
What is the total quantity of 'Cerium' produced by 'South Africa' before 2018?
|
CREATE TABLE production (element VARCHAR(10),country VARCHAR(20),quantity INT,year INT); INSERT INTO production (element,country,quantity,year) VALUES ('Cerium','South Africa',120000,2015),('Cerium','South Africa',130000,2016),('Cerium','South Africa',140000,2017);
|
SELECT SUM(quantity) FROM production WHERE element = 'Cerium' AND country = 'South Africa' AND year < 2018;
|
What is the average salary for employees who identify as female, hired between 2019 and 2021, and work in the IT department?
|
SAME AS ABOVE
|
SELECT AVG(Salary) FROM Employees WHERE Gender = 'Female' AND HireYear BETWEEN 2019 AND 2021 AND Department = 'IT';
|
How many unique attendees have donated to performing arts programs in India in the last 2 years?
|
CREATE TABLE donations (id INT,donor VARCHAR(50),country VARCHAR(50),year INT,amount INT); INSERT INTO donations (id,donor,country,year,amount) VALUES (1,'John Doe','India',2020,500),(2,'Jane Smith','India',2021,750),(3,'John Doe','India',2021,1000);
|
SELECT COUNT(DISTINCT donor) FROM donations WHERE country = 'India' AND event IN ('Theater', 'Dance', 'Music') AND year BETWEEN 2020 AND 2021;
|
Insert a new record with an community_policing_id of 6 and is_active set to 'false' into the 'community_policing' table
|
CREATE TABLE community_policing (community_policing_id INT,is_active BOOLEAN);
|
INSERT INTO community_policing (community_policing_id, is_active) VALUES (6, false);
|
What is the total health equity metric for each region in 2022?
|
CREATE TABLE HealthEquityMetrics (MetricID INT,Region VARCHAR(255),MetricValue INT,ReportDate DATE); INSERT INTO HealthEquityMetrics (MetricID,Region,MetricValue,ReportDate) VALUES (1,'Northeast',85,'2022-01-01'); INSERT INTO HealthEquityMetrics (MetricID,Region,MetricValue,ReportDate) VALUES (2,'Southeast',78,'2022-02-15'); INSERT INTO HealthEquityMetrics (MetricID,Region,MetricValue,ReportDate) VALUES (3,'Midwest',92,'2022-03-05'); INSERT INTO HealthEquityMetrics (MetricID,Region,MetricValue,ReportDate) VALUES (4,'West',64,'2022-04-10');
|
SELECT Region, SUM(MetricValue) FROM HealthEquityMetrics WHERE YEAR(ReportDate) = 2022 GROUP BY Region;
|
Delete a customer record from the customers table
|
CREATE TABLE customers (customer_id INT,first_name VARCHAR(50),last_name VARCHAR(50),email VARCHAR(100),phone_number VARCHAR(15),created_at TIMESTAMP);
|
DELETE FROM customers WHERE customer_id = 1001;
|
What is the highest risk investment strategy and its associated risk score?
|
CREATE TABLE investment_strategies (id INT,strategy TEXT,risk_score FLOAT); INSERT INTO investment_strategies (id,strategy,risk_score) VALUES (1,'Equity Investment',6.5),(2,'Real Estate Investment',4.8),(3,'Bond Investment',3.2);
|
SELECT strategy, MAX(risk_score) FROM investment_strategies;
|
What is the average sales quantity and sales amount for each drug, unpivoted and with a total row?
|
CREATE TABLE SalesData (drug_name VARCHAR(255),sales_quantity INT,sales_amount DECIMAL(10,2)); INSERT INTO SalesData (drug_name,sales_quantity,sales_amount) VALUES ('DrugK',200,30000.00),('DrugL',100,15000.00),('DrugM',150,25000.00);
|
SELECT drug_name, 'sales_quantity' as metric, AVG(sales_quantity) as value FROM SalesData GROUP BY drug_name UNION ALL SELECT drug_name, 'sales_amount' as metric, AVG(sales_amount) as value FROM SalesData GROUP BY drug_name UNION ALL SELECT 'Total', AVG(value) as value FROM (SELECT drug_name, 'sales_quantity' as metric, AVG(sales_quantity) as value FROM SalesData GROUP BY drug_name UNION ALL SELECT drug_name, 'sales_amount' as metric, AVG(sales_amount) as value FROM SalesData GROUP BY drug_name) sub;
|
Update the 'infrastructure_development' table to reflect a new end date of January 1, 2024 for project 'E'
|
CREATE TABLE infrastructure_development (id INT,project VARCHAR(255),location VARCHAR(255),start_date DATE,end_date DATE);
|
UPDATE infrastructure_development SET end_date = '2024-01-01' WHERE project = 'E';
|
What is the average attendance at dance performances in Rio de Janeiro in 2019?
|
CREATE TABLE performance_attendance (id INT,city VARCHAR(20),year INT,genre VARCHAR(20),attendance INT); INSERT INTO performance_attendance (id,city,year,genre,attendance) VALUES (1,'Tokyo',2018,'dance',500),(2,'Rio de Janeiro',2019,'dance',600),(3,'New York',2019,'dance',450),(4,'Paris',2018,'dance',550),(5,'London',2019,'dance',700);
|
SELECT AVG(attendance) FROM performance_attendance WHERE city = 'Rio de Janeiro' AND genre = 'dance' AND year = 2019;
|
Find the total carbon emissions for each state from the PowerPlants and CarbonEmissions tables
|
CREATE TABLE PowerPlants (id INT,state CHAR(2),capacity FLOAT,fuel VARCHAR(10));CREATE TABLE CarbonEmissions (id INT,powerplant_id INT,year INT,emissions FLOAT);
|
SELECT p.state, SUM(ce.emissions) as total_emissions FROM PowerPlants p INNER JOIN CarbonEmissions ce ON p.id = ce.powerplant_id GROUP BY p.state;
|
What is the maximum number of clinical trials conducted for a single drug?
|
CREATE TABLE clinical_trials (trial_id INT,drug_name VARCHAR(255)); INSERT INTO clinical_trials (trial_id,drug_name) VALUES (1,'DrugA'),(2,'DrugB'),(3,'DrugB'),(4,'DrugC'),(5,'DrugC'),(6,'DrugC');
|
SELECT drug_name, MAX(cnt) FROM (SELECT drug_name, COUNT(*) AS cnt FROM clinical_trials GROUP BY drug_name) AS subquery;
|
What is the average humidity per day for each city in the past week?
|
CREATE TABLE WeatherData (City VARCHAR(50),Humidity INT,Timestamp DATETIME); INSERT INTO WeatherData (City,Humidity,Timestamp) VALUES ('CityA',60,'2022-01-01 00:00:00'),('CityB',70,'2022-01-01 00:00:00');
|
SELECT City, AVG(Humidity) OVER (PARTITION BY City ORDER BY Timestamp ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) FROM WeatherData
|
What is the minimum price of all non-vegan makeup products?
|
CREATE TABLE products (product_id INT PRIMARY KEY,product_name TEXT,product_type TEXT,brand_id INT,is_vegan BOOLEAN,price DECIMAL); INSERT INTO products (product_id,product_name,product_type,brand_id,is_vegan,price) VALUES (1,'Lipstick','Makeup',1,false,25.99),(2,'Mascara','Makeup',2,false,20.99),(3,'Eyeshadow','Makeup',3,false,30.99),(4,'Blush','Makeup',3,true,18.99),(5,'Foundation','Makeup',4,false,35.99);
|
SELECT MIN(price) FROM products WHERE product_type = 'Makeup' AND is_vegan = false;
|
How many customers are there in each investment strategy?
|
CREATE TABLE customers (customer_id INT,name VARCHAR(50),age INT,region VARCHAR(20),strategy_name VARCHAR(50)); INSERT INTO customers (customer_id,name,age,region,strategy_name) VALUES (1,'John Doe',35,'Southeast','Equity'),(2,'Jane Smith',45,'Northeast','Bond'),(3,'Mike Johnson',50,'Southeast','Equity'),(4,'Alice Davis',25,'Midwest','Bond'),(5,'Bob Brown',60,'Northwest','Real Estate'),(6,'Charlie Davis',30,'Midwest','Real Estate');
|
SELECT strategy_name, COUNT(*) FROM customers GROUP BY strategy_name;
|
What is the total number of professional development programs conducted in 'Rural District Z' and 'Urban District W' last year?
|
CREATE TABLE RuralDistrictZPD (programID INT,district VARCHAR(50),programDate DATE); INSERT INTO RuralDistrictZPD (programID,district,programDate) VALUES (1,'Rural District Z','2021-02-01'),(2,'Rural District Z','2021-06-15'); CREATE TABLE UrbanDistrictWPD (programID INT,district VARCHAR(50),programDate DATE); INSERT INTO UrbanDistrictWPD (programID,district,programDate) VALUES (3,'Urban District W','2021-09-30'),(4,'Urban District W','2021-12-25');
|
SELECT COUNT(DISTINCT programID) FROM RuralDistrictZPD WHERE district IN ('Rural District Z', 'Urban District W') AND YEAR(programDate) = 2021 UNION ALL SELECT COUNT(DISTINCT programID) FROM UrbanDistrictWPD WHERE district IN ('Rural District Z', 'Urban District W') AND YEAR(programDate) = 2021;
|
Which menu items have been sold more than 300 times and are not 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 > 300 AND menu_items.sustainable = FALSE;
|
What is the average number of public meetings held per department in the state of New York?
|
CREATE TABLE department (id INT PRIMARY KEY,name TEXT,city_id INT,FOREIGN KEY (city_id) REFERENCES city(id)); CREATE TABLE meeting (id INT PRIMARY KEY,date DATE,department_id INT,FOREIGN KEY (department_id) REFERENCES department(id));
|
SELECT AVG(meetings_per_dept) FROM (SELECT COUNT(*) as meetings_per_dept FROM meeting JOIN department ON meeting.department_id = department.id WHERE department.city_id IN (SELECT id FROM city WHERE state = 'NY') GROUP BY department.id) as subquery;
|
Find the number of marine protected areas in the Pacific Ocean.
|
CREATE TABLE marine_protected_areas (name TEXT,location TEXT); INSERT INTO marine_protected_areas (name,location) VALUES ('Galapagos Marine Reserve','Pacific'),('Great Barrier Reef','Pacific'),('Channel Islands National Marine Sanctuary','Pacific'),('Monterey Bay National Marine Sanctuary','Pacific'),('Cordell Bank National Marine Sanctuary','Pacific');
|
SELECT COUNT(*) FROM marine_protected_areas WHERE location = 'Pacific';
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.