instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
What percentage of research grants are awarded to faculty members who identify as neurodivergent?
|
CREATE TABLE faculty (id INT,name VARCHAR(100),department VARCHAR(50),gender VARCHAR(50),neurodivergent VARCHAR(50)); INSERT INTO faculty VALUES (1,'Quinn Smith','Psychology','Non-binary','Yes'); CREATE TABLE grants (id INT,faculty_id INT,amount DECIMAL(10,2)); INSERT INTO grants VALUES (1,1,60000);
|
SELECT 100.0 * SUM(CASE WHEN faculty.neurodivergent = 'Yes' THEN grants.amount ELSE 0 END) / SUM(grants.amount) AS percentage FROM grants JOIN faculty ON grants.faculty_id = faculty.id;
|
Update the download speed for an existing broadband plan in the 'broadband_plans' table
|
CREATE TABLE broadband_plans (plan_id INT,plan_name VARCHAR(255),download_speed INT,upload_speed INT,price DECIMAL(5,2));
|
UPDATE broadband_plans SET download_speed = 1500 WHERE plan_id = 3001;
|
Identify the number of water quality violations in each district of Los Angeles in the last year
|
CREATE TABLE districts (id INT,city VARCHAR(255)); INSERT INTO districts (id,city) VALUES (1,'Los Angeles'); CREATE TABLE water_quality_violations (id INT,district_id INT,violation_date DATE); INSERT INTO water_quality_violations (id,district_id) VALUES (1,1);
|
SELECT water_quality_violations.district_id, COUNT(*) as number_of_violations FROM water_quality_violations WHERE water_quality_violations.violation_date >= (CURRENT_DATE - INTERVAL '1 year')::date AND water_quality_violations.district_id IN (SELECT id FROM districts WHERE city = 'Los Angeles') GROUP BY water_quality_violations.district_id;
|
Which traditional art types have the most pieces in the database?
|
CREATE TABLE ArtTypes (ArtTypeID INT,ArtType VARCHAR(50)); CREATE TABLE ArtPieces (ArtPieceID INT,ArtTypeID INT,ArtistID INT,Year INT); INSERT INTO ArtTypes VALUES (1,'Painting'),(2,'Sculpture'),(3,'Textile'),(4,'Pottery'); INSERT INTO ArtPieces VALUES (1,1,1,2010),(2,1,2,2015),(3,2,3,2005),(4,2,4,2020),(5,3,5,2018),(6,3,6,2021),(7,4,7,2019);
|
SELECT ArtTypes.ArtType, COUNT(ArtPieces.ArtPieceID) AS ArtPieceCount FROM ArtTypes INNER JOIN ArtPieces ON ArtTypes.ArtTypeID = ArtPieces.ArtTypeID GROUP BY ArtTypes.ArtType ORDER BY ArtPieceCount DESC;
|
What is the number of climate mitigation projects completed by each organization in 2019?
|
CREATE TABLE org_mitigation_projects (org_name VARCHAR(50),year INT,status VARCHAR(50)); INSERT INTO org_mitigation_projects (org_name,year,status) VALUES ('UNFCCC',2019,'Completed'),('Greenpeace',2019,'Completed'),('WWF',2019,'Completed'),('UN',2019,'In-progress');
|
SELECT org_name, SUM(CASE WHEN status = 'Completed' THEN 1 ELSE 0 END) as completed_projects FROM org_mitigation_projects WHERE year = 2019 GROUP BY org_name;
|
What is the average delivery time for shipments to India from the United States?
|
CREATE TABLE shipment_deliveries(id INT,shipment_id INT,delivery_time INT); CREATE TABLE shipments(id INT,source VARCHAR(255),destination VARCHAR(255),shipment_date DATE); INSERT INTO shipment_deliveries(id,shipment_id,delivery_time) VALUES (1,1,7),(2,2,10),(3,3,8); INSERT INTO shipments(id,source,destination,shipment_date) VALUES (1,'United States','India','2022-01-01'),(2,'United States','Canada','2022-01-07');
|
SELECT AVG(delivery_time) FROM shipment_deliveries JOIN shipments ON shipment_deliveries.shipment_id = shipments.id WHERE shipments.source = 'United States' AND shipments.destination = 'India';
|
Find the number of orders placed by each customer and the average delivery time for each customer.
|
CREATE TABLE orders (order_id INT,customer_id INT,order_date DATE,delivery_time INT); INSERT INTO orders VALUES (1,1,'2022-01-01',3),(2,1,'2022-01-05',5),(3,2,'2022-02-01',2),(4,2,'2022-02-03',4),(5,3,'2022-03-01',6);
|
SELECT customer_id, COUNT(*) as num_orders, AVG(delivery_time) as avg_delivery_time FROM orders GROUP BY customer_id ORDER BY num_orders DESC;
|
Identify the top 3 energy-efficient countries in the energy market domain, considering renewable energy production, energy storage capacity, and carbon pricing.
|
CREATE TABLE energy_efficiency (country VARCHAR(20),renewable_energy_production INT,energy_storage_capacity INT,carbon_price DECIMAL(5,2)); INSERT INTO energy_efficiency (country,renewable_energy_production,energy_storage_capacity,carbon_price) VALUES ('Sweden',650000,12000,120.00),('Norway',800000,15000,150.00),('Denmark',450000,8000,110.00),('Finland',500000,9000,90.00);
|
SELECT country, (renewable_energy_production + energy_storage_capacity + carbon_price) AS total_energy_efficiency FROM energy_efficiency GROUP BY country ORDER BY total_energy_efficiency DESC LIMIT 3;
|
Update the rating of 'Breaking Bad' to 4.9.
|
CREATE TABLE tv_shows (show_id INT,title VARCHAR(100),release_year INT,rating FLOAT); INSERT INTO tv_shows (show_id,title,release_year,rating) VALUES (1,'Game of Thrones',2011,4.1),(2,'Stranger Things',2016,4.6),(3,'Breaking Bad',2008,4.8);
|
UPDATE tv_shows SET rating = 4.9 WHERE title = 'Breaking Bad';
|
Who are the top 5 actors by lines in a movie?
|
CREATE TABLE lines (id INT,movie_id INT,actor_id INT,lines INT); CREATE TABLE movies (id INT,title VARCHAR(255));
|
SELECT m.title, a.name, SUM(l.lines) as total_lines FROM lines l
|
Identify the top 3 districts with the highest number of community policing events, in the central region, for the past year.
|
CREATE TABLE CommunityEvents (id INT,district_id INT,event_date DATE,region_id INT); CREATE TABLE Districts (id INT,region_id INT,district_name VARCHAR(255)); INSERT INTO Districts (id,region_id,district_name) VALUES (1,1,'Downtown'),(2,1,'Uptown'),(3,2,'Harbor'),(4,2,'International'),(5,3,'Central'),(6,3,'North'),(7,4,'East'),(8,4,'West'); INSERT INTO CommunityEvents (id,district_id,event_date,region_id) VALUES (1,1,'2022-01-01',3),(2,2,'2022-02-01',3),(3,3,'2022-03-01',3),(4,4,'2022-04-01',3),(5,5,'2022-05-01',3),(6,6,'2022-06-01',3),(7,7,'2022-07-01',3),(8,8,'2022-08-01',3);
|
SELECT district_id, district_name, COUNT(*) as num_events FROM CommunityEvents JOIN Districts ON Districts.id = CommunityEvents.district_id WHERE event_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) AND CURRENT_DATE AND region_id = 3 GROUP BY district_id, district_name ORDER BY num_events DESC LIMIT 3;
|
What is the total number of bookings for each region in the 'Regional_Bookings' table?
|
CREATE TABLE Regional_Bookings (region VARCHAR(50),bookings INT); INSERT INTO Regional_Bookings (region,bookings) VALUES ('North America',10000),('South America',5000),('Europe',15000);
|
SELECT region, SUM(bookings) FROM Regional_Bookings GROUP BY region;
|
What is the average age of artists in the 'music_festivals' table?
|
CREATE TABLE music_festivals (artist_id INT,artist_name TEXT,artist_age INT);
|
SELECT AVG(artist_age) FROM music_festivals;
|
Add a record to the table "coral_reefs"
|
CREATE TABLE coral_reefs (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),status VARCHAR(255));
|
INSERT INTO coral_reefs (id, name, location, status) VALUES (1, 'Great Barrier Reef', 'Australia', 'Vulnerable');
|
What is the most common service accessed in the 'legal_aid_services' table?
|
CREATE TABLE legal_aid_services (service_id INT,service_name VARCHAR(25),location VARCHAR(30),access_date DATE);
|
SELECT service_name, COUNT(*) AS count FROM legal_aid_services GROUP BY service_name ORDER BY count DESC LIMIT 1;
|
What is the average food safety score for restaurants in the city of Los Angeles for the month of May 2022?
|
CREATE TABLE Restaurants (RestaurantID int,Name varchar(50),City varchar(50));CREATE TABLE FoodInspections (InspectionID int,RestaurantID int,InspectionDate date,Score int);
|
SELECT AVG(FI.Score) as AverageScore, R.City FROM FoodInspections FI INNER JOIN Restaurants R ON FI.RestaurantID = R.RestaurantID WHERE R.City = 'Los Angeles' AND MONTH(FI.InspectionDate) = 5 AND YEAR(FI.InspectionDate) = 2022 GROUP BY R.City;
|
What is the average age of female offenders who committed property crimes in Oakland?
|
CREATE TABLE offenders (id INT,age INT,gender VARCHAR(10),city VARCHAR(20)); INSERT INTO offenders (id,age,gender,city) VALUES (1,34,'Female','Oakland'),(2,42,'Male','San_Francisco'); CREATE TABLE crimes (id INT,type VARCHAR(20),location VARCHAR(20)); INSERT INTO crimes (id,type,location) VALUES (1,'Property_Crime','Oakland'),(2,'Assault','San_Francisco');
|
SELECT AVG(age) FROM offenders JOIN crimes ON offenders.id = crimes.id WHERE gender = 'Female' AND type = 'Property_Crime' AND city = 'Oakland';
|
Show the number of workers in each department by gender for the past month.
|
CREATE TABLE Workforce (ID INT,Department VARCHAR(255),Gender VARCHAR(255),HireDate DATE); INSERT INTO Workforce (ID,Department,Gender,HireDate) VALUES (1,'Mining','Male','2021-12-01'),(2,'Mining','Male','2021-11-01'),(3,'Mining','Female','2021-10-01'),(4,'Maintenance','Male','2021-12-01'),(5,'Maintenance','Female','2021-11-01'),(6,'Maintenance','Male','2021-10-01'),(7,'Environment','Female','2021-12-01'),(8,'Environment','Female','2021-11-01'),(9,'Environment','Male','2021-10-01'),(10,'Safety','Male','2021-12-01'),(11,'Safety','Female','2021-11-01'),(12,'Safety','Male','2021-10-01');
|
SELECT Department, Gender, COUNT(*) as Number_of_Workers FROM Workforce WHERE HireDate >= DATEADD(MONTH, -1, GETDATE()) GROUP BY Department, Gender;
|
What is the number of female, male, and non-binary founders for each company?
|
CREATE TABLE GenderCounts (id INT,company_id INT,gender VARCHAR(10)); INSERT INTO GenderCounts (id,company_id,gender) VALUES (1,1,'Female'),(2,1,'Male'),(3,2,'Male'),(4,2,'Non-binary');
|
SELECT company_id, gender, COUNT(*) as num_founders FROM GenderCounts GROUP BY company_id, gender;
|
Find the total number of wells drilled in the North Sea by oil companies in 2020
|
CREATE TABLE wells (id INT,well_name VARCHAR(50),location VARCHAR(50),company VARCHAR(50),num_drills INT,drill_date DATE); INSERT INTO wells VALUES (1,'Well A','North Sea','ABC Oil',3,'2020-01-02'); INSERT INTO wells VALUES (2,'Well B','North Sea','XYZ Oil',5,'2020-03-15'); INSERT INTO wells VALUES (3,'Well C','Gulf of Mexico','ABC Oil',2,'2019-12-27');
|
SELECT SUM(num_drills) FROM wells WHERE location = 'North Sea' AND company LIKE '%Oil%' AND drill_date BETWEEN '2020-01-01' AND '2020-12-31';
|
How many pedestrian bridges are there in New York City?
|
CREATE TABLE Bridge (id INT,name TEXT,location TEXT,type TEXT); INSERT INTO Bridge (id,name,location,type) VALUES (1,'Brooklyn Bridge','NYC,NY','Pedestrian'),(2,'Manhattan Bridge','NYC,NY','Pedestrian');
|
SELECT COUNT(*) FROM Bridge WHERE location = 'NYC, NY' AND type = 'Pedestrian';
|
What is the average number of fouls committed by a team in basketball games played after 2021 in the 'basketball_games' table?
|
CREATE TABLE basketball_games (id INT,home_team VARCHAR(50),away_team VARCHAR(50),date DATE,fouls_home INT,fouls_away INT); INSERT INTO basketball_games (id,home_team,away_team,date,fouls_home,fouls_away) VALUES (1,'Chicago Bulls','Milwaukee Bucks','2023-01-01',14,16); INSERT INTO basketball_games (id,home_team,away_team,date,fouls_home,fouls_away) VALUES (2,'Los Angeles Lakers','Golden State Warriors','2023-02-10',18,20);
|
SELECT AVG(fouls_home + fouls_away) FROM basketball_games WHERE date > '2021-12-31';
|
Show the number of public transportation trips and the total cost for each trip in the city of Chicago.
|
CREATE TABLE trips (id INT,trip_id INT,trip_type VARCHAR(255),city_id INT,trip_cost DECIMAL(10,2));CREATE TABLE public_transportation (id INT,trip_id INT,transportation_type VARCHAR(255));
|
SELECT t.trip_type, COUNT(t.id) as num_trips, SUM(t.trip_cost) as total_cost FROM trips t INNER JOIN public_transportation pt ON t.id = pt.trip_id WHERE t.city_id = (SELECT id FROM cities WHERE city_name = 'Chicago') GROUP BY t.trip_type;
|
List all veteran unemployment rates by state in the last quarter of 2021, along with their respective military spending.
|
CREATE TABLE veteran_unemployment(id INT,state VARCHAR(255),quarter INT,year INT,rate DECIMAL(5,2)); CREATE TABLE military_spending(id INT,state VARCHAR(255),quarter INT,year INT,spending INT);
|
SELECT v.state, v.rate, m.spending FROM veteran_unemployment v INNER JOIN military_spending m ON v.state = m.state WHERE v.quarter = 4 AND v.year = 2021;
|
What is the minimum shipment weight for deliveries to Canada after January 10, 2021?
|
CREATE TABLE Deliveries (id INT,weight FLOAT,destination VARCHAR(20),ship_date DATE); INSERT INTO Deliveries (id,weight,destination,ship_date) VALUES (1,30.5,'Canada','2021-01-11'),(2,40.2,'Mexico','2021-01-12');
|
SELECT MIN(weight) FROM Deliveries WHERE destination = 'Canada' AND ship_date > '2021-01-10';
|
Find the total quantity of sustainable materials used, partitioned by material type, and ordered by total quantity in descending order?
|
CREATE TABLE EthicalFashion.SustainableMaterials (material_id INT,material_type VARCHAR(20),quantity INT); INSERT INTO EthicalFashion.SustainableMaterials (material_id,material_type,quantity) VALUES (1,'Organic Cotton',3000),(2,'Recycled Polyester',4500),(3,'Tencel',2000);
|
SELECT material_type, SUM(quantity) AS total_quantity FROM EthicalFashion.SustainableMaterials GROUP BY material_type ORDER BY total_quantity DESC;
|
What is the average rating of makeup products that are not tested on animals and contain at least one vegan ingredient in the EU?
|
CREATE TABLE makeup_ingredients (ingredient_id INT,product_id INT,is_vegan BOOLEAN,is_animal_tested BOOLEAN,region VARCHAR(255));
|
SELECT AVG(rating) FROM makeup_ingredients WHERE is_vegan = TRUE AND is_animal_tested = FALSE AND region = 'EU';
|
Display the names of all climate finance recipients who received funding in either 2019 or 2022.
|
CREATE TABLE climate_finance_2019 (recipient_name TEXT,funding_year INTEGER); INSERT INTO climate_finance_2019 (recipient_name,funding_year) VALUES ('Recipient D',2019),('Recipient E',2019),('Recipient D',2020); CREATE TABLE climate_finance_2022 (recipient_name TEXT,funding_year INTEGER); INSERT INTO climate_finance_2022 (recipient_name,funding_year) VALUES ('Recipient D',2022),('Recipient F',2022);
|
SELECT recipient_name FROM climate_finance_2019 WHERE funding_year = 2019 UNION SELECT recipient_name FROM climate_finance_2022 WHERE funding_year = 2022;
|
What percentage of consumers prefer Natural over Organic in France?
|
CREATE TABLE consumer_preferences (consumer_id INT,country VARCHAR(100),preference VARCHAR(100),preference_score INT); INSERT INTO consumer_preferences (consumer_id,country,preference,preference_score) VALUES (1,'France','Natural',4000),(2,'France','Organic',3000),(3,'USA','Natural',5000),(4,'USA','Organic',6000);
|
SELECT 100.0 * SUM(CASE WHEN preference = 'Natural' THEN preference_score ELSE 0 END) / SUM(preference_score) AS natural_percentage
|
What was the total prize money of the 2016 UEFA Champions League?
|
CREATE TABLE football_tournaments (name VARCHAR(255),year INT,prize_money INT); INSERT INTO football_tournaments (name,year,prize_money) VALUES ('UEFA Champions League',2016,139000000);
|
SELECT prize_money FROM football_tournaments WHERE name = 'UEFA Champions League' AND year = 2016;
|
Update the "co2_emission" of the record in the "emissions" table with ID 789 to 1200 tons for a coal mine in "South Africa" in 2020
|
CREATE TABLE emissions (id INT,mine_type VARCHAR(50),country VARCHAR(50),year INT,co2_emission INT); INSERT INTO emissions (id,mine_type,country,year,co2_emission) VALUES (789,'coal','South Africa',2020,1000);
|
UPDATE emissions SET co2_emission = 1200 WHERE id = 789;
|
What is the recycling rate in the city of Toronto for the year 2020?'
|
CREATE TABLE recycling_rates (city VARCHAR(20),year INT,recycling_rate FLOAT); INSERT INTO recycling_rates (city,year,recycling_rate) VALUES ('Toronto',2020,0.35);
|
SELECT recycling_rate FROM recycling_rates WHERE city = 'Toronto' AND year = 2020;
|
What is the minimum depth of all marine protected areas with a conservation status of 'Endangered'?
|
CREATE TABLE marine_protected_areas (id INT,name VARCHAR(255),area_size FLOAT,avg_depth FLOAT,conservation_status VARCHAR(100)); INSERT INTO marine_protected_areas (id,name,area_size,avg_depth,conservation_status) VALUES (1,'Coral Triangle',518000,-200,'Least Concern'),(2,'Great Barrier Reef',344400,-500,'Critically Endangered'),(3,'Galapagos Marine Reserve',133000,-300,'Endangered');
|
SELECT MIN(avg_depth) FROM marine_protected_areas WHERE conservation_status = 'Endangered';
|
What are the three rural areas with the highest obesity rate in Canada?
|
CREATE TABLE areas_canada (id INT,name VARCHAR(255),rural_designation VARCHAR(50)); INSERT INTO areas_canada (id,name,rural_designation) VALUES (1,'Area X','Rural'); CREATE TABLE obesity_rates (id INT,area_id INT,obesity_rate FLOAT); INSERT INTO obesity_rates (id,area_id,obesity_rate) VALUES (1,1,30.5);
|
SELECT a.name, ob.obesity_rate FROM areas_canada a JOIN obesity_rates ob ON a.id = ob.area_id WHERE a.rural_designation = 'Rural' ORDER BY ob.obesity_rate DESC LIMIT 3;
|
Insert a new record into the TV_shows table for a show with ID 3, 'New Show', released in 2022, with a runtime of 30 minutes, and an IMDb rating of 8.5.
|
CREATE TABLE TV_shows (id INT,title VARCHAR(255),release_year INT,runtime INT,imdb_rating DECIMAL(2,1));
|
INSERT INTO TV_shows (id, title, release_year, runtime, imdb_rating) VALUES (3, 'New Show', 2022, 30, 8.5);
|
Who are the volunteers with the most volunteer hours for the Food Bank program?
|
CREATE TABLE Volunteers (VolunteerID int,Name varchar(100),Program varchar(50),Hours int,VolunteerDate date); INSERT INTO Volunteers (VolunteerID,Name,Program,Hours,VolunteerDate) VALUES (1,'Charlotte Lee','Food Bank',50); INSERT INTO Volunteers (VolunteerID,Name,Program,Hours,VolunteerDate) VALUES (2,'Daniel Kim','Health Clinic',75);
|
SELECT Name, SUM(Hours) as TotalHours FROM Volunteers WHERE Program = 'Food Bank' GROUP BY Name ORDER BY TotalHours DESC;
|
Identify the top 3 countries with the highest number of security incidents in the last year.
|
CREATE TABLE security_incidents (country VARCHAR(50),incident_count INT,incident_date DATE); INSERT INTO security_incidents (country,incident_count,incident_date) VALUES ('Country A',120,'2022-01-01'),('Country B',140,'2022-01-02'),('Country C',160,'2022-01-03'),('Country D',130,'2022-01-04'),('Country E',110,'2022-01-05');
|
SELECT country, SUM(incident_count) as total_incidents FROM security_incidents WHERE incident_date >= DATEADD(year, -1, GETDATE()) GROUP BY country ORDER BY total_incidents DESC LIMIT 3;
|
What is the total weight of containers shipped from the Port of Dar es Salaam to Tanzania in the last 6 months?
|
CREATE TABLE Port (port_id INT,port_name TEXT,country TEXT); INSERT INTO Port (port_id,port_name,country) VALUES (1,'Port of Dar es Salaam','Tanzania'); CREATE TABLE Shipment (shipment_id INT,container_id INT,port_id INT,shipping_date DATE); CREATE TABLE Container (container_id INT,weight FLOAT);
|
SELECT SUM(c.weight) as total_weight FROM Container c JOIN Shipment s ON c.container_id = s.container_id JOIN Port p ON s.port_id = p.port_id WHERE p.country = 'Tanzania' AND s.shipping_date >= NOW() - INTERVAL '6 months' AND p.port_name = 'Port of Dar es Salaam';
|
Delete records of military equipment that have not been maintained in the past year?
|
CREATE TABLE Equipment (EquipmentID INT,EquipmentName VARCHAR(50),LastMaintenanceDate DATE); INSERT INTO Equipment (EquipmentID,EquipmentName,LastMaintenanceDate) VALUES (1,'M1 Abrams','2022-01-01'),(2,'F-15 Eagle','2021-12-15'),(3,'M2 Bradley','2020-05-23');
|
DELETE FROM Equipment WHERE LastMaintenanceDate < DATE_SUB(CURDATE(), INTERVAL 1 YEAR);
|
What is the highest daily trading volume for each digital asset category?
|
CREATE TABLE digital_asset_categories (id INT,name VARCHAR(255)); CREATE TABLE digital_assets (id INT,category_id INT,name VARCHAR(255),daily_trading_volume DECIMAL(10,2)); INSERT INTO digital_asset_categories (id,name) VALUES (1,'CategoryA'),(2,'CategoryB'),(3,'CategoryC'); INSERT INTO digital_assets (id,category_id,name,daily_trading_volume) VALUES (1,1,'Asset1',5000),(2,1,'Asset2',3000),(3,2,'Asset3',2000),(4,2,'Asset4',1000),(5,3,'Asset5',500);
|
SELECT category_id, MAX(daily_trading_volume) AS Highest_Daily_Trading_Volume FROM digital_assets GROUP BY category_id;
|
What is the average number of ingredients per cruelty-free product in the database?
|
CREATE TABLE Product_Ingredients (id INT,product VARCHAR(255),ingredient VARCHAR(255),cruelty_free BOOLEAN); INSERT INTO Product_Ingredients (id,product,ingredient,cruelty_free) VALUES (1,'Lush Soak Stimulant Bath Bomb','Sodium Bicarbonate',true),(2,'The Body Shop Born Lippy Strawberry Lip Balm','Caprylic/Capric Triglyceride',true),(3,'Estee Lauder Advanced Night Repair','Water',false),(4,'Lush Soak Stimulant Bath Bomb','Citric Acid',true),(5,'The Body Shop Tea Tree Skin Clearing Facial Wash','Salicylic Acid',true);
|
SELECT AVG(COUNT(*)) as avg_ingredients FROM Product_Ingredients GROUP BY cruelty_free;
|
How many rides started between 7-8 AM for the tram system in October 2022?
|
CREATE TABLE trips (trip_id INT,trip_start_time DATETIME,trip_end_time DATETIME,system_name VARCHAR(20));
|
SELECT system_name, COUNT(*) FROM trips WHERE trip_start_time BETWEEN '2022-10-01 07:00:00' AND '2022-10-31 08:00:00' AND system_name = 'Tram' GROUP BY system_name;
|
Determine the percentage of funding received from private sources in the year 2022.
|
CREATE TABLE Funding (FundingID INT,Source TEXT,Year INT,Amount INT); INSERT INTO Funding (FundingID,Source,Year,Amount) VALUES (1,'Private Donation',2022,75000),(2,'Government Grant',2021,100000),(3,'Corporate Sponsorship',2022,50000);
|
SELECT (SUM(CASE WHEN Year = 2022 AND Source = 'Private Donation' THEN Amount ELSE 0 END) / SUM(CASE WHEN Year = 2022 THEN Amount ELSE 0 END)) * 100 AS 'Percentage of Funding from Private Sources in 2022' FROM Funding;
|
What is the total number of military bases located in the United States and Canada, and how many personnel are stationed at these bases?
|
CREATE TABLE MilitaryBases (BaseID INT,BaseName TEXT,Country TEXT,Personnel INT); INSERT INTO MilitaryBases (BaseID,BaseName,Country,Personnel) VALUES (1,'Fort Bragg','USA',53104); INSERT INTO MilitaryBases (BaseID,BaseName,Country,Personnel) VALUES (2,'CFB Petawawa','Canada',7685);
|
SELECT SUM(Personnel) as TotalPersonnel, COUNT(*) as BaseCount FROM MilitaryBases WHERE Country IN ('USA', 'Canada');
|
What is the total revenue generated from each product category in the last quarter?
|
CREATE TABLE sales(id INT,product_category VARCHAR(255),revenue DECIMAL(10,2),sale_date DATE); INSERT INTO sales(id,product_category,revenue,sale_date) VALUES (1,'Electronics',1000.00,'2022-01-01'),(2,'Furniture',1500.00,'2022-01-05'),(3,'Electronics',1200.00,'2022-04-10'); INSERT INTO sales(id,product_category,revenue,sale_date) VALUES (4,'Fashion',1800.00,'2022-03-20'),(5,'Furniture',2000.00,'2022-04-01');
|
SELECT product_category, SUM(revenue) FROM sales WHERE sale_date >= CURDATE() - INTERVAL 90 DAY GROUP BY product_category;
|
List all marine species observed in the Arctic region with their endangerment status.
|
CREATE TABLE marine_species (species_name VARCHAR(255),region VARCHAR(255),endangerment_status VARCHAR(255)); INSERT INTO marine_species (species_name,region,endangerment_status) VALUES ('Polar Bear','Arctic','Vulnerable'),('Narwhal','Arctic','Near Threatened');
|
SELECT species_name, endangerment_status FROM marine_species WHERE region = 'Arctic';
|
What is the average number of hospital beds per location, for locations with more than 1000 beds?
|
CREATE TABLE hospitals (id INT PRIMARY KEY,name VARCHAR(255),beds INT,location VARCHAR(255)); INSERT INTO hospitals (id,name,beds,location) VALUES (1,'Johns Hopkins Hospital',1138,'Baltimore,MD'); INSERT INTO hospitals (id,name,beds,location) VALUES (2,'Massachusetts General Hospital',999,'Boston,MA'); INSERT INTO hospitals (id,name,beds,location) VALUES (3,'University of Washington Medical Center',1025,'Seattle,WA');
|
SELECT location, AVG(beds) FROM hospitals GROUP BY location HAVING SUM(beds) > 1000;
|
What is the average speed of vessels that arrived in the Port of Los Angeles in January 2022?
|
CREATE TABLE ports (id INT,name TEXT); INSERT INTO ports (id,name) VALUES (1,'Port of Los Angeles'); CREATE TABLE vessels (id INT,name TEXT,port_id INT,speed FLOAT); INSERT INTO vessels (id,name,port_id,speed) VALUES (1,'Vessel A',1,15.5),(2,'Vessel B',1,14.3),(3,'Vessel C',1,16.8);
|
SELECT AVG(speed) FROM vessels WHERE port_id = 1 AND arrival_date BETWEEN '2022-01-01' AND '2022-01-31';
|
What is the total revenue generated from medical marijuana sales in Oregon?
|
CREATE TABLE Revenue (revenue_id INT,sale_type TEXT,state TEXT,revenue DECIMAL(10,2)); INSERT INTO Revenue (revenue_id,sale_type,state,revenue) VALUES (1,'medical','Oregon',5000.00),(2,'recreational','Oregon',7000.00),(3,'medical','California',8000.00),(4,'recreational','California',10000.00);
|
SELECT SUM(revenue) as total_revenue FROM Revenue WHERE state = 'Oregon' AND sale_type = 'medical';
|
What is the total amount of climate finance committed to projects in Small Island Developing States (SIDS) in the Pacific region?
|
CREATE TABLE sids_projects (project_id INT,project_name TEXT,location TEXT,funding_amount DECIMAL(10,2),funder TEXT,commitment_date DATE);
|
SELECT SUM(funding_amount) FROM sids_projects WHERE location LIKE '%Pacific%' AND funder LIKE '%Climate Finance%' AND location IN (SELECT location FROM sids WHERE sids.region = 'Small Island Developing States');
|
What is the percentage of households in the city of NYC that consume more than 12 gallons of water per day?
|
CREATE TABLE Household (ID INT,City VARCHAR(20),Consumption FLOAT); INSERT INTO Household (ID,City,Consumption) VALUES (1,'NYC',12.3),(2,'NYC',13.8),(3,'NYC',11.5),(4,'Seattle',10.5);
|
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Household WHERE City = 'NYC')) FROM Household WHERE City = 'NYC' AND Consumption > 12;
|
Find the top 3 most popular workout activities in the month of February 2022.
|
CREATE TABLE user_workouts_feb (id INT,user_id INT,activity VARCHAR(50),duration INT,timestamp TIMESTAMP); INSERT INTO user_workouts_feb (id,user_id,activity,duration,timestamp) VALUES (1,1001,'running',30,'2022-02-01 10:00:00'); INSERT INTO user_workouts_feb (id,user_id,activity,duration,timestamp) VALUES (2,1002,'swimming',45,'2022-02-01 11:30:00'); INSERT INTO user_workouts_feb (id,user_id,activity,duration,timestamp) VALUES (3,1003,'yoga',60,'2022-02-02 09:00:00');
|
SELECT activity, COUNT(*) as count FROM user_workouts_feb WHERE EXTRACT(MONTH FROM timestamp) = 2 GROUP BY activity ORDER BY count DESC LIMIT 3;
|
What is the average delivery time for aircraft by manufacturer, considering only successful missions?
|
CREATE SCHEMA Aerospace;CREATE TABLE Aerospace.AircraftManufacturing (manufacturer VARCHAR(50),country VARCHAR(50),delivery_time INT,mission_result VARCHAR(10));INSERT INTO Aerospace.AircraftManufacturing (manufacturer,country,delivery_time,mission_result) VALUES ('Boeing','USA',20,'Success'),('Airbus','Europe',25,'Failure'),('Comac','China',35,'Success'),('Mitsubishi','Japan',15,'Success');
|
SELECT manufacturer, AVG(delivery_time) AS avg_delivery_time FROM Aerospace.AircraftManufacturing WHERE mission_result = 'Success' GROUP BY manufacturer;
|
What is the maximum number of crimes committed in a single day in the 'south' division?
|
CREATE TABLE crimes (id INT,date DATE,division VARCHAR(10)); INSERT INTO crimes (id,date,division) VALUES (1,'2022-01-01','south'),(2,'2022-01-02','south'),(3,'2022-01-03','north'); INSERT INTO crimes (id,date,division) VALUES (4,'2022-01-04','south'),(5,'2022-01-05','south'),(6,'2022-01-06','north');
|
SELECT MAX(count) FROM (SELECT date, COUNT(*) AS count FROM crimes WHERE division = 'south' GROUP BY date) AS subquery;
|
What is the total number of academic publications by female authors in the humanities department?
|
CREATE TABLE academic_publications (id INT,author_name TEXT,author_gender TEXT,department TEXT,publication_date DATE); INSERT INTO academic_publications (id,author_name,author_gender,department,publication_date) VALUES (1,'Grace','F','Humanities','2021-05-01'); INSERT INTO academic_publications (id,author_name,author_gender,department,publication_date) VALUES (2,'Hugo','M','Engineering','2022-09-15');
|
SELECT COUNT(*) FROM academic_publications WHERE author_gender = 'F' AND department = 'Humanities'
|
Determine the difference in the number of military equipment sold by Boeing and General Atomics in 2020.
|
CREATE TABLE BoeingSales (equipment_type TEXT,quantity INT,year INT); INSERT INTO BoeingSales VALUES ('F-15',20,2020); INSERT INTO BoeingSales VALUES ('Chinook',5,2020); CREATE TABLE GeneralAtomicsSales (country TEXT,quantity INT,year INT); INSERT INTO GeneralAtomicsSales VALUES ('United States',40,2020); INSERT INTO GeneralAtomicsSales VALUES ('Italy',5,2020);
|
SELECT BoeingSales.quantity - GeneralAtomicsSales.quantity AS Difference
|
What is the maximum production quantity for wells owned by 'Big Oil' and located in the 'North Sea'?
|
CREATE TABLE wells (id INT,name VARCHAR(255),location VARCHAR(255),owner VARCHAR(255),production_quantity INT); INSERT INTO wells (id,name,location,owner,production_quantity) VALUES (1,'Well A','North Sea','Acme Oil',1000),(2,'Well B','Gulf of Mexico','Big Oil',2000),(3,'Well C','North Sea','Acme Oil',1500),(4,'Well D','North Sea','Big Oil',2500),(5,'Well E','North Sea','Big Oil',3000);
|
SELECT MAX(production_quantity) FROM wells WHERE location = 'North Sea' AND owner = 'Big Oil';
|
What is the total amount of climate finance provided to countries in the Asia Pacific region for climate mitigation initiatives in the year 2020?
|
CREATE TABLE climate_finance (year INT,region VARCHAR(50),initiative VARCHAR(50),amount FLOAT); INSERT INTO climate_finance (year,region,initiative,amount) VALUES (2020,'Asia Pacific','climate mitigation',12000000);
|
SELECT SUM(amount) FROM climate_finance WHERE year = 2020 AND region = 'Asia Pacific' AND initiative = 'climate mitigation';
|
What are the skills training programs and their corresponding manufacturer names?
|
CREATE TABLE workforce_development_programs (id INT,name VARCHAR(255),manufacturer_id INT,program_type VARCHAR(255)); INSERT INTO workforce_development_programs (id,name,manufacturer_id,program_type) VALUES (1,'Apprenticeship Program',1,'Skills Training'); CREATE TABLE manufacturers (id INT,name VARCHAR(255),location VARCHAR(255),employee_count INT); INSERT INTO manufacturers (id,name,location,employee_count) VALUES (1,'Manufacturer X','Sydney',500);
|
SELECT wdp.name, m.name AS manufacturer_name FROM workforce_development_programs wdp INNER JOIN manufacturers m ON wdp.manufacturer_id = m.id WHERE wdp.program_type = 'Skills Training';
|
What is the average CO2 emission in the 'environmental_impact' table for the years 2018 and 2019?
|
CREATE TABLE environmental_impact (id INT,year INT,co2_emission FLOAT); INSERT INTO environmental_impact (id,year,co2_emission) VALUES (1,2018,12000.00); INSERT INTO environmental_impact (id,year,co2_emission) VALUES (2,2019,15000.00); INSERT INTO environmental_impact (id,year,co2_emission) VALUES (3,2020,18000.00);
|
SELECT AVG(co2_emission) FROM environmental_impact WHERE year IN (2018, 2019);
|
How many disaster response events were organized by non-profit organizations in Asia in 2021?
|
CREATE TABLE DisasterEvents (event_id INT,event_year INT,event_location VARCHAR(50),event_organizer VARCHAR(50)); INSERT INTO DisasterEvents (event_id,event_year,event_location,event_organizer) VALUES (1,2021,'India','Non-Profit A'),(2,2020,'Indonesia','Non-Profit B'),(3,2021,'Philippines','Government Agency C');
|
SELECT COUNT(*) FROM DisasterEvents WHERE event_year = 2021 AND event_location LIKE 'Asia%' AND event_organizer LIKE 'Non-Profit%';
|
What are the names and categories of the decentralized applications that have been deployed on the Binance Smart Chain and have had the most number of transactions?
|
CREATE TABLE IF NOT EXISTS decentralized_applications (dapp_id INT PRIMARY KEY,name VARCHAR(100),tx_id INT,category VARCHAR(50),blockchain VARCHAR(50),FOREIGN KEY (tx_id) REFERENCES blockchain_transactions(tx_id)); CREATE TABLE IF NOT EXISTS blockchain_transactions (tx_id INT PRIMARY KEY,blockchain VARCHAR(50)); INSERT INTO blockchain_transactions (tx_id,blockchain) VALUES (1,'Binance Smart Chain');
|
SELECT dapp_name, category, COUNT(dapp_id) FROM decentralized_applications da JOIN blockchain_transactions bt ON da.tx_id = bt.tx_id WHERE bt.blockchain = 'Binance Smart Chain' GROUP BY dapp_name, category ORDER BY COUNT(dapp_id) DESC LIMIT 10;
|
What is the annual production volume trend for the mine with the ID 'mine001'?
|
CREATE TABLE production_data (id INT PRIMARY KEY,mine_id INT,year INT,monthly_production INT);
|
SELECT year, AVG(monthly_production) as annual_production FROM production_data WHERE mine_id = 'mine001' GROUP BY year;
|
Delete records of workers who earn less than $50,000 in the 'oil' industry in Texas, USA.
|
CREATE TABLE workers (id INT,name VARCHAR(50),industry VARCHAR(50),salary FLOAT,state VARCHAR(50)); INSERT INTO workers (id,name,industry,salary,state) VALUES (1,'John Doe','oil',45000,'Texas'); INSERT INTO workers (id,name,industry,salary,state) VALUES (2,'Jane Smith','oil',60000,'Texas'); INSERT INTO workers (id,name,industry,salary,state) VALUES (3,'Mike Johnson','coal',70000,'Texas');
|
DELETE FROM workers WHERE industry = 'oil' AND salary < 50000 AND state = 'Texas';
|
Which sustainable hotels in South Africa have the lowest carbon footprint?
|
CREATE TABLE hotel_carbon_footprint(hotel_id INT,hotel_name TEXT,country TEXT,is_sustainable BOOLEAN,carbon_footprint INT); INSERT INTO hotel_carbon_footprint (hotel_id,hotel_name,country,is_sustainable,carbon_footprint) VALUES (1,'Eco Hotel','South Africa',true,40),(2,'Luxury Resort','South Africa',false,100),(3,'Green Hotel','South Africa',true,50);
|
SELECT hotel_name, carbon_footprint FROM hotel_carbon_footprint WHERE country = 'South Africa' AND is_sustainable = true ORDER BY carbon_footprint ASC;
|
How many energy storage facilities are there in California, Texas, and New York, and what are their names?
|
CREATE TABLE energy_storage_facilities (id INT,name VARCHAR(255),state VARCHAR(50)); INSERT INTO energy_storage_facilities (id,name,state) VALUES (1,'Facility A','California'),(2,'Facility B','Texas'),(3,'Facility C','California'),(4,'Facility D','New York');
|
SELECT e.state, COUNT(*), e.name FROM energy_storage_facilities e WHERE e.state IN ('California', 'Texas', 'New York') GROUP BY e.state, e.name;
|
Delete records of cargo with a weight over 10000 tons from the CARGO table
|
CREATE TABLE CARGO (ID INT,VESSEL_ID INT,CARGO_NAME VARCHAR(50),WEIGHT INT);
|
DELETE FROM CARGO WHERE WEIGHT > 10000;
|
What is the average biomass of fish farmed in each country, excluding fish from Norway?
|
CREATE TABLE FarmF (country VARCHAR(20),species VARCHAR(20),biomass FLOAT); INSERT INTO FarmF (country,species,biomass) VALUES ('Norway','Salmon',5000); INSERT INTO FarmF (country,species,biomass) VALUES ('Norway','Cod',3000); INSERT INTO FarmF (country,species,biomass) VALUES ('Scotland','Herring',2000); INSERT INTO FarmF (country,species,biomass) VALUES ('Scotland','Mackerel',1000); INSERT INTO FarmF (country,species,biomass) VALUES ('Canada','Halibut',4000);
|
SELECT country, AVG(biomass) FROM FarmF WHERE country != 'Norway' GROUP BY country;
|
What is the total water consumption for each production process in 2022?
|
CREATE TABLE Production_Processes (id INT,process VARCHAR(255)); INSERT INTO Production_Processes (id,process) VALUES (1,'Dyeing'),(2,'Cutting'),(3,'Sewing'),(4,'Finishing'); CREATE TABLE Water_Consumption (id INT,process_id INT,year INT,consumption INT); INSERT INTO Water_Consumption (id,process_id,year,consumption) VALUES (1,1,2022,5000),(2,2,2022,4000),(3,3,2022,3000),(4,4,2022,2000);
|
SELECT p.process, SUM(w.consumption) FROM Water_Consumption w JOIN Production_Processes p ON w.process_id = p.id WHERE w.year = 2022 GROUP BY p.process;
|
What's the sum of donations for education causes?
|
CREATE TABLE Donations (DonationID int,DonorID int,Cause text,DonationAmount numeric); INSERT INTO Donations VALUES (1,1,'Education',500); INSERT INTO Donations VALUES (2,2,'Health',1000);
|
SELECT SUM(DonationAmount) FROM Donations WHERE Cause = 'Education';
|
What is the maximum ocean depth recorded?
|
CREATE TABLE ocean_depths (ocean VARCHAR(50),depth FLOAT); INSERT INTO ocean_depths (ocean,depth) VALUES ('Mariana Trench',10994),('Tonga Trench',10882),('Kermadec Trench',10047),('Java Trench',8047),('Samoa Trench',7999);
|
SELECT MAX(depth) FROM ocean_depths;
|
How many graduate students have published in academic journals in the past year, and what is the distribution of publications by department?
|
CREATE TABLE graduate_students (student_id INT,dept_name VARCHAR(50)); CREATE TABLE publications (publication_id INT,student_id INT,pub_date DATE);
|
SELECT g.dept_name, COUNT(p.publication_id) as num_publications FROM graduate_students g INNER JOIN publications p ON g.student_id = p.student_id WHERE p.pub_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 1 YEAR) GROUP BY g.dept_name;
|
Which countries have the least media representation in the media_content table?
|
CREATE TABLE media_content (id INT,country VARCHAR(50),genre VARCHAR(50),frequency INT); INSERT INTO media_content (id,country,genre,frequency) VALUES (1,'USA','Movie',100),(2,'Canada','Movie',20),(3,'Mexico','TV Show',30);
|
SELECT country, frequency FROM media_content ORDER BY frequency LIMIT 1;
|
What is the total number of hospital beds by ownership in Australia?
|
CREATE TABLE australian_hospitals (id INT,hospital_name VARCHAR(50),hospital_type VARCHAR(50),num_beds INT,ownership VARCHAR(50)); INSERT INTO australian_hospitals (id,hospital_name,hospital_type,num_beds,ownership) VALUES (1,'Hospital A','Public',500,'Public');
|
SELECT ownership, SUM(num_beds) as total_beds FROM australian_hospitals GROUP BY ownership;
|
What is the total population of cities with a population over 1 million?
|
CREATE TABLE City (CityName VARCHAR(50),Country VARCHAR(50),Population INT); INSERT INTO City (CityName,Country,Population) VALUES ('New York','USA',8500000),('Los Angeles','USA',4000000),('Tokyo','Japan',9000000),('Delhi','India',19000000);
|
SELECT SUM(Population) FROM City WHERE Population > 1000000;
|
Which stores in the stores table have an 'organic' certification?
|
CREATE TABLE stores (id INT,name TEXT,location TEXT,certified_organic BOOLEAN); INSERT INTO stores (id,name,location,certified_organic) VALUES (1,'Eco-Market','San Francisco',true); INSERT INTO stores (id,name,location,certified_organic) VALUES (2,'Farm Fresh','Los Angeles',false);
|
SELECT name FROM stores WHERE certified_organic = true;
|
List all the workplaces in Canada that have implemented workplace safety measures.
|
CREATE TABLE ca_workplaces (id INT,name TEXT,country TEXT,workplace_safety BOOLEAN); INSERT INTO ca_workplaces (id,name,country,workplace_safety) VALUES (1,'Workplace D','Canada',true),(2,'Workplace E','Canada',true),(3,'Workplace F','Canada',false);
|
SELECT name FROM ca_workplaces WHERE workplace_safety = true;
|
What's the average temperature change in South America between 1950 and 2000, and how does it compare to the global average temperature change during the same period?
|
CREATE TABLE WeatherData (location VARCHAR(50),year INT,avg_temp FLOAT);
|
SELECT w1.avg_temp - w2.avg_temp AS temp_diff FROM (SELECT AVG(avg_temp) FROM WeatherData WHERE location LIKE 'South America%' AND year BETWEEN 1950 AND 2000) w1, (SELECT AVG(avg_temp) FROM WeatherData WHERE year BETWEEN 1950 AND 2000) w2;
|
What is the average recycling rate for Africa?
|
CREATE TABLE recycling_rates (country VARCHAR(255),recycling_rate FLOAT); INSERT INTO recycling_rates (country,recycling_rate) VALUES ('South Africa',0.36),('Egypt',0.22),('Nigeria',0.15);
|
SELECT AVG(recycling_rate) FROM recycling_rates WHERE country IN ('South Africa', 'Egypt', 'Nigeria');
|
Which defense diplomacy events involved Japan and Canada from 2015 to 2017?
|
CREATE TABLE defense_diplomacy (country VARCHAR(50),year INT,event VARCHAR(50)); INSERT INTO defense_diplomacy (country,year,event) VALUES ('Japan',2015,'G7 Defense Ministerial'); INSERT INTO defense_diplomacy (country,year,event) VALUES ('Japan',2016,'Japan-US Defense Ministerial'); INSERT INTO defense_diplomacy (country,year,event) VALUES ('Japan',2017,'Japan-India Defense Ministerial'); INSERT INTO defense_diplomacy (country,year,event) VALUES ('Canada',2015,'NATO Defense Ministerial'); INSERT INTO defense_diplomacy (country,year,event) VALUES ('Canada',2016,'Canada-UK Defense Ministerial'); INSERT INTO defense_diplomacy (country,year,event) VALUES ('Canada',2017,'Canada-France Defense Ministerial');
|
SELECT country, GROUP_CONCAT(event) as events FROM defense_diplomacy WHERE (country = 'Japan' OR country = 'Canada') AND (year BETWEEN 2015 AND 2017) GROUP BY country;
|
Create a view named 'contract_summary' with columns 'company_name', 'total_contracts', 'total_value
|
CREATE VIEW contract_summary AS SELECT company_name,COUNT(*) AS total_contracts,SUM(contract_value) AS total_value FROM contract_negotiations JOIN contract ON contract_negotiations.contract_id = contract.id GROUP BY company_name;
|
CREATE VIEW contract_summary AS SELECT company_name, COUNT(*) AS total_contracts, SUM(contract_value) AS total_value FROM contract_negotiations JOIN contract ON contract_negotiations.contract_id = contract.id GROUP BY company_name;
|
Identify users from rural areas with more than 3 transactions in the month of June 2021, and rank them by transaction value.
|
CREATE TABLE users (user_id INT,user_location VARCHAR(30)); CREATE TABLE transactions (transaction_id INT,user_id INT,transaction_value FLOAT,transaction_date DATE); INSERT INTO users (user_id,user_location) VALUES (1,'Rural'); INSERT INTO transactions (transaction_id,user_id,transaction_value,transaction_date) VALUES (1,1,100.00,'2021-06-01');
|
SELECT user_id, RANK() OVER (ORDER BY SUM(transaction_value) DESC) as rank FROM transactions INNER JOIN users ON transactions.user_id = users.user_id WHERE EXTRACT(MONTH FROM transaction_date) = 6 AND user_location = 'Rural' GROUP BY user_id HAVING COUNT(*) > 3;
|
Which organizations have developed models with a fairness score greater than 0.9?
|
CREATE TABLE organizations_fairness (org_id INT,fairness_score FLOAT); INSERT INTO organizations_fairness (org_id,fairness_score) VALUES (1,0.85),(2,0.92),(3,0.88),(4,0.7),(5,0.95);
|
SELECT org_id FROM organizations_fairness WHERE fairness_score > 0.9;
|
Add a new vessel 'Sea Turtle' to the 'Eco-friendly' fleet.
|
CREATE TABLE Fleets (id INT,name VARCHAR(255)); INSERT INTO Fleets (id,name) VALUES (1,'Eco-friendly'); CREATE TABLE Vessels (id INT,name VARCHAR(255),fleet_id INT); INSERT INTO Vessels (id,name,fleet_id) VALUES (1,'Eco Warrior',1);
|
INSERT INTO Vessels (id, name, fleet_id) SELECT 2, 'Sea Turtle', id FROM Fleets WHERE name = 'Eco-friendly';
|
What is the number of public service requests received in 2022, grouped by request type, in the 'service_requests' table?
|
CREATE TABLE service_requests (id INT,request_type VARCHAR(255),request_date DATE); INSERT INTO service_requests (id,request_type,request_date) VALUES (1,'Road Repair','2022-01-01'),(2,'Waste Collection','2022-02-01'),(3,'Street Lighting','2022-01-15');
|
SELECT request_type, COUNT(*) FROM service_requests WHERE YEAR(request_date) = 2022 GROUP BY request_type;
|
Update all autonomous vehicle records in 'mumbai' with a new adoption rate of 28.5
|
CREATE TABLE if not exists vehicle_types (vehicle_type varchar(20)); INSERT INTO vehicle_types (vehicle_type) VALUES ('autonomous'),('manual'); CREATE TABLE if not exists adoption_rates (vehicle_type varchar(20),city varchar(20),adoption_rate float); INSERT INTO adoption_rates (vehicle_type,city,adoption_rate) VALUES ('autonomous','mumbai',25.6),('manual','mumbai',74.1);
|
UPDATE adoption_rates SET adoption_rate = 28.5 WHERE vehicle_type = 'autonomous' AND city = 'mumbai';
|
What is the current total value locked in DeFi protocols on the Polygon network?
|
CREATE TABLE polygon_defi (protocol_name VARCHAR(50),tvl DECIMAL(18,2));
|
SELECT SUM(tvl) FROM polygon_defi WHERE protocol_name = 'Aave';
|
What is the average number of autonomous taxis in the taxis table for each city?
|
CREATE TABLE taxis (id INT,city TEXT,vehicle_type TEXT,fuel_type TEXT,total_taxis INT); INSERT INTO taxis (id,city,vehicle_type,fuel_type,total_taxis) VALUES (1,'San Francisco','Taxi','Autonomous',100),(2,'New York','Taxi','Gasoline',800),(3,'Los Angeles','Taxi','Autonomous',150);
|
SELECT city, AVG(total_taxis) as avg_autonomous_taxis FROM taxis WHERE vehicle_type = 'Taxi' AND fuel_type = 'Autonomous' GROUP BY city;
|
Which users have posted the most in the last 3 days?
|
CREATE TABLE users (id INT,user_id INT); INSERT INTO users (id,user_id) VALUES (1,1),(2,2),(3,3),(4,4),(5,5); CREATE TABLE posts (id INT,user_id INT,post_date DATE); INSERT INTO posts (id,user_id,post_date) VALUES (1,1,'2022-01-01'),(2,2,'2022-01-02'),(3,1,'2022-01-03'),(4,2,'2022-01-04'),(5,3,'2022-01-05'),(6,3,'2022-01-05'),(7,1,'2022-01-06'),(8,2,'2022-01-07'),(9,4,'2022-01-08'),(10,5,'2022-01-09'),(11,1,'2022-01-10'),(12,2,'2022-01-11');
|
SELECT user_id, COUNT(*) AS num_posts FROM posts WHERE post_date >= DATEADD(day, -3, GETDATE()) GROUP BY user_id ORDER BY num_posts DESC;
|
What is the average donation amount in the 'Donations' table?
|
CREATE TABLE Donations (id INT,department VARCHAR(20),amount FLOAT); INSERT INTO Donations (id,department,amount) VALUES (1,'Animals',500.00),(2,'Education',300.00);
|
SELECT AVG(amount) FROM Donations
|
What is the total quantity (in metric tons) of textile waste generated in each region?
|
CREATE TABLE waste_generation(region VARCHAR(50),waste FLOAT); INSERT INTO waste_generation(region,waste) VALUES('RegionA',12.5),('RegionB',15.8),('RegionC',18.3);
|
SELECT region, SUM(waste) FROM waste_generation GROUP BY region;
|
What is the total investment of all clients in the "US Equity" fund?
|
CREATE TABLE clients (client_id INT,name VARCHAR(50),investment FLOAT); CREATE TABLE fund_investments (client_id INT,fund_name VARCHAR(50),investment FLOAT);
|
SELECT SUM(investment) FROM clients INNER JOIN fund_investments ON clients.client_id = fund_investments.client_id WHERE fund_investments.fund_name = 'US Equity';
|
Create a table to store cruelty-free certification information
|
CREATE TABLE cruelty_free_certification (certification_id INT PRIMARY KEY,product_id INT,certification_date DATE,certification_authority TEXT);
|
CREATE TABLE cruelty_free_certification (certification_id INT PRIMARY KEY, product_id INT, certification_date DATE, certification_authority TEXT);
|
List the unique types of healthcare facilities in 'rural' areas, excluding pharmacies.
|
CREATE TABLE healthcare_facilities (id INT,name TEXT,location TEXT,type TEXT); INSERT INTO healthcare_facilities (id,name,location,type) VALUES (1,'Hospital A','rural','hospital'); INSERT INTO healthcare_facilities (id,name,location,type) VALUES (2,'Clinic A','rural','clinic'); INSERT INTO healthcare_facilities (id,name,location,type) VALUES (3,'Pharmacy A','rural','pharmacy');
|
SELECT DISTINCT type FROM healthcare_facilities WHERE location = 'rural' AND type != 'pharmacy';
|
What is the total energy produced by wind power in the United States for the year 2020?
|
CREATE TABLE renewable_energy (country VARCHAR(255),year INT,energy_produced FLOAT); INSERT INTO renewable_energy (country,year,energy_produced) VALUES ('United States',2020,456.78);
|
SELECT SUM(energy_produced) FROM renewable_energy WHERE country = 'United States' AND energy_type = 'Wind' AND year = 2020;
|
What is the average age of all astronauts who have been on a spacewalk?
|
CREATE TABLE Astronauts (AstronautID INT,Age INT,HasSpacewalked BOOLEAN);
|
SELECT AVG(Age) FROM Astronauts WHERE HasSpacewalked = TRUE;
|
What is the total revenue generated by Spanish movies released in 2022?
|
CREATE TABLE spanish_movies (id INT PRIMARY KEY,name VARCHAR(255),release_year INT,revenue INT); INSERT INTO spanish_movies (id,name,release_year,revenue) VALUES (1,'Dolor y Gloria',2022,12000000),(2,'Mientras Dure la Guerra',2022,9000000),(3,'La Trinchera Infinita',2022,10000000);
|
SELECT SUM(revenue) FROM spanish_movies WHERE release_year = 2022;
|
What is the percentage of the population that is Indigenous in Australia?
|
CREATE TABLE indigenous_composition (id INT,country VARCHAR(50),population INT,indigenous INT); INSERT INTO indigenous_composition (id,country,population,indigenous) VALUES (1,'Australia',25368000,798200);
|
SELECT (indigenous * 100.0 / population) FROM indigenous_composition WHERE country = 'Australia';
|
What is the total number of job openings in the IT sector in the last quarter?
|
CREATE TABLE Jobs (Quarter INT,Sector VARCHAR(255),Openings INT); INSERT INTO Jobs (Quarter,Sector,Openings) VALUES (1,'IT',1000),(1,'Finance',800),(2,'IT',1200),(2,'Finance',900);
|
SELECT SUM(Openings) FROM Jobs WHERE Quarter IN (3, 4) AND Sector = 'IT';
|
List all brands that have products with a price higher than the average product price.
|
CREATE TABLE products (product_id INT,product_name VARCHAR(255),brand VARCHAR(255),price DECIMAL(10,2)); INSERT INTO products VALUES (1,'ProductA','BrandX',50),(2,'ProductB','BrandX',75),(3,'ProductC','BrandY',60);
|
SELECT brand FROM products WHERE price > (SELECT AVG(price) FROM products);
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.