instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
Show the minimum quantity of all items in the Inventory table | CREATE TABLE Inventory (item_id INT,item_name VARCHAR(50),quantity INT,warehouse_id INT); | SELECT MIN(quantity) FROM Inventory; |
What are the total quantities of items shipped to each continent? | CREATE TABLE Shipment (id INT,source_country VARCHAR(255),destination_continent VARCHAR(255),quantity INT); INSERT INTO Shipment (id,source_country,destination_continent,quantity) VALUES (1,'China','Asia',500),(2,'United States','North America',300),(3,'Germany','Europe',200),(4,'Brazil','South America',100); | SELECT destination_continent, SUM(quantity) FROM Shipment GROUP BY destination_continent |
What is the order ID and delivery time for the fastest delivery made by each courier in the 'courier_performances' view, ordered by the fastest delivery time? | CREATE VIEW courier_performances AS SELECT courier_id,order_id,MIN(delivery_time) as fastest_delivery_time FROM orders GROUP BY courier_id,order_id; | SELECT courier_id, order_id, MIN(fastest_delivery_time) as fastest_delivery_time FROM courier_performances GROUP BY courier_id, order_id ORDER BY fastest_delivery_time; |
How many female and male faculty members are there in each college? | CREATE TABLE college (college_name TEXT); INSERT INTO college (college_name) VALUES ('College of Science'),('College of Arts'),('College of Business'); CREATE TABLE faculty (faculty_id INTEGER,college_name TEXT,gender TEXT); INSERT INTO faculty (faculty_id,college_name,gender) VALUES (1,'College of Science','Male'),(2,'College of Science','Female'),(3,'College of Arts','Non-binary'),(4,'College of Business','Male'); | SELECT college_name, gender, COUNT(*) FROM faculty GROUP BY college_name, gender; |
Identify the local economic impact of each region by summing the revenue of all hotels in that region? | CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,region TEXT,revenue FLOAT); INSERT INTO hotels (hotel_id,hotel_name,region,revenue) VALUES (1,'Hotel 1','Region 1',100000),(2,'Hotel 2','Region 1',200000),(3,'Hotel 3','Region 2',150000),(4,'Hotel 4','Region 2',250000); | SELECT region, SUM(revenue) AS total_revenue FROM hotels GROUP BY region; |
Display the top 3 most booked 'eco-friendly' hotels based on the last month's bookings. | CREATE TABLE ecohotels (id INT,name VARCHAR(255),eco_friendly BOOLEAN,rating FLOAT); INSERT INTO ecohotels (id,name,eco_friendly,rating) VALUES (1,'Green Hotel',1,4.2); INSERT INTO ecohotels (id,name,eco_friendly,rating) VALUES (2,'Eco Lodge',1,4.5); | SELECT * FROM ecohotels WHERE eco_friendly = 1 AND id IN (SELECT hotel_id FROM otabookings WHERE booking_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY hotel_id ORDER BY COUNT(*) DESC LIMIT 3); |
How many research stations are there per country in the Arctic with more than 30 scientists? | CREATE TABLE research_stations (id INT,station_name VARCHAR,country VARCHAR,num_scientists INT); INSERT INTO research_stations VALUES (1,'Station A','Norway',50); | SELECT country, COUNT(*) FROM research_stations WHERE num_scientists > 30 GROUP BY country; |
Update the 'design_standards' table to set the 'standard_status' to 'Obsolete' for all records where 'standard_version' is less than 3 | CREATE TABLE design_standards (standard_id INT,standard_name TEXT,standard_version INT,standard_status TEXT); | UPDATE design_standards SET standard_status = 'Obsolete' WHERE standard_version < 3; |
What are the total construction costs for all projects in 'New York' and 'Texas'? | CREATE TABLE Projects (name TEXT,state TEXT,cost INTEGER); INSERT INTO Projects (name,state,cost) VALUES ('Highway Expansion','New York',1000000); INSERT INTO Projects (name,state,cost) VALUES ('Transportation Upgrade','Texas',2000000); | SELECT SUM(cost) FROM Projects WHERE state IN ('New York', 'Texas'); |
Compare the number of tourists visiting eco-friendly destinations in 2021 and 2022. | CREATE TABLE destinations_2021 (id INT,destination VARCHAR(50),num_tourists INT); INSERT INTO destinations_2021 (id,destination,num_tourists) VALUES (1,'Bali',1200),(2,'Maldives',1500),(3,'New Zealand',1800),(4,'Costa Rica',900),(5,'Nepal',1000); CREATE TABLE destinations_2022 (id INT,destination VARCHAR(50),num_tourists INT); INSERT INTO destinations_2022 (id,destination,num_tourists) VALUES (1,'Bali',1500),(2,'Maldives',1700),(3,'New Zealand',2000),(4,'Costa Rica',1200),(5,'Nepal',1300); CREATE TABLE eco_destinations (id INT,destination VARCHAR(50)); INSERT INTO eco_destinations (id,destination) VALUES (1,'Bali'),(2,'Costa Rica'),(3,'Nepal'); | SELECT d2022.destination, (d2022.num_tourists - d2021.num_tourists) AS tourist_change FROM destinations_2022 d2022 JOIN destinations_2021 d2021 ON d2022.destination = d2021.destination JOIN eco_destinations ed ON d2022.destination = ed.destination; |
What is the average sentence length (in months) for offenders in the justice_data schema's sentencing table who have been convicted of violent crimes? | CREATE TABLE justice_data.sentencing (id INT,case_number INT,offender_id INT,sentence_length INT,conviction VARCHAR(50)); | SELECT AVG(sentence_length) FROM justice_data.sentencing WHERE conviction LIKE '%violent%'; |
What is the percentage of cases that are dismissed in the criminal justice system? | CREATE TABLE cases (case_id INT,dismissed BOOLEAN); | SELECT 100.0 * COUNT(*) / (SELECT COUNT(*) FROM cases) AS percentage FROM cases WHERE dismissed = TRUE; |
What is the distribution of articles by language in the 'articles' table? | CREATE TABLE articles (article_language VARCHAR(50),article_title VARCHAR(100),publication_date DATE); INSERT INTO articles (article_language,article_title,publication_date) VALUES ('English','Article 1','2021-01-01'); INSERT INTO articles (article_language,article_title,publication_date) VALUES ('Spanish','Article 2','2021-01-02'); | SELECT article_language, COUNT(*) as article_count FROM articles GROUP BY article_language; |
How many vendors offer gluten-free options in the downtown area? | CREATE TABLE VendorLocation (VendorID INT,Location VARCHAR(50)); INSERT INTO VendorLocation (VendorID,Location) VALUES (1,'Downtown'),(2,'Uptown'); CREATE TABLE MenuItems (MenuItemID INT,VendorID INT,MenuItemName VARCHAR(50),MenuItemType VARCHAR(50),GlutenFree VARCHAR(5)); INSERT INTO MenuItems (MenuItemID,VendorID,MenuItemName,MenuItemType,GlutenFree) VALUES (1,1,'Chicken Caesar Salad','Salad','Yes'),(2,1,'Ham Sandwich','Sandwich','No'),(3,2,'Beef Burrito','Mexican','No'); | SELECT COUNT(*) FROM MenuItems WHERE VendorID IN (SELECT VendorID FROM VendorLocation WHERE Location = 'Downtown') AND GlutenFree = 'Yes'; |
What was the average waste per menu item last month? | CREATE TABLE inventory (item VARCHAR(255),daily_waste NUMERIC,date DATE); INSERT INTO inventory (item,daily_waste,date) VALUES ('Chicken Alfredo',20,'2021-10-01'),('Veggie Lasagna',15,'2021-10-01'),('Beef Tacos',10,'2021-10-01'); | SELECT item, AVG(daily_waste) FROM inventory WHERE date >= DATE_SUB(CURRENT_DATE(), INTERVAL 30 DAY) GROUP BY item; |
What are the workforce diversity statistics for each mining site? | CREATE TABLE mining_sites (id INT,name VARCHAR(50)); CREATE TABLE workforce (site_id INT,gender VARCHAR(10),role VARCHAR(20)); INSERT INTO mining_sites (id,name) VALUES (1,'Site A'),(2,'Site B'),(3,'Site C'); INSERT INTO workforce (site_id,gender,role) VALUES (1,'Male','Engineer'),(1,'Female','Operator'),(2,'Male','Manager'),(2,'Non-binary','Engineer'),(3,'Male','Operator'),(3,'Female','Manager'); | SELECT ms.name, w.gender, COUNT(w.site_id) as count FROM mining_sites ms INNER JOIN workforce w ON ms.id = w.site_id GROUP BY ms.name, w.gender; |
What is the percentage of mobile customers who use more than 10 GB of data per month in each state? | CREATE TABLE mobile_customers (id INT,state VARCHAR(50),data_usage FLOAT); | SELECT state, 100.0 * SUM(CASE WHEN data_usage > 10 THEN 1 ELSE 0 END) / COUNT(*) AS pct FROM mobile_customers GROUP BY state; |
What is the total number of mobile and broadband subscribers for each technology, ranked in descending order? | CREATE TABLE mobile_subscribers (subscriber_id INT,technology VARCHAR(20),region VARCHAR(50)); INSERT INTO mobile_subscribers (subscriber_id,technology,region) VALUES (1,'4G','North'),(2,'5G','North'),(3,'3G','South'),(4,'5G','East'); CREATE TABLE broadband_subscribers (subscriber_id INT,technology VARCHAR(20),region VARCHAR(50)); INSERT INTO broadband_subscribers (subscriber_id,technology,region) VALUES (5,'Fiber','North'),(6,'Cable','North'),(7,'Fiber','West'),(8,'DSL','East'); | SELECT 'Mobile' AS source, technology, COUNT(*) AS total FROM mobile_subscribers GROUP BY technology UNION ALL SELECT 'Broadband' AS source, technology, COUNT(*) AS total FROM broadband_subscribers GROUP BY technology ORDER BY total DESC; |
What is the total number of investigative journalism articles published in the last 3 months, and what percentage of the total publications do they represent? | CREATE TABLE publications (id INT,title VARCHAR(100),genre VARCHAR(20),publication_date DATE);INSERT INTO publications (id,title,genre,publication_date) VALUES (1,'Uncovering Corruption','investigative journalism','2022-04-01');INSERT INTO publications (id,title,genre,publication_date) VALUES (2,'The Hidden Truth','opinion','2022-03-15'); | SELECT COUNT(*) AS total_investigative_articles FROM publications WHERE genre = 'investigative journalism' AND publication_date >= DATEADD(month, -3, GETDATE());SELECT COUNT(*) AS total_publications FROM publications;SELECT (total_investigative_articles * 100.0 / total_publications) AS percentage FROM (SELECT COUNT(*) AS total_investigative_articles FROM publications WHERE genre = 'investigative journalism' AND publication_date >= DATEADD(month, -3, GETDATE())) AS investigative_articles, (SELECT COUNT(*) AS total_publications FROM publications) AS total_publications; |
What is the average donation amount in the education sector, for donations made in the last 6 months? | CREATE TABLE donations (id INT,donation_date DATE,donation_amount DECIMAL(10,2),sector TEXT); INSERT INTO donations (id,donation_date,donation_amount,sector) VALUES (1,'2022-01-01',100.00,'Education'),(2,'2022-02-14',200.00,'Health'),(3,'2022-03-05',150.00,'Education'); | SELECT sector, AVG(donation_amount) as avg_donation FROM donations WHERE donation_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH) AND sector = 'Education' GROUP BY sector; |
List all records from the 'PlayerData' table | CREATE TABLE PlayerData (PlayerID INT,Name VARCHAR(50),Age INT,Country VARCHAR(50)); INSERT INTO PlayerData (PlayerID,Name,Age,Country) VALUES ('1','John Doe','25','USA'),('2','Jane Smith','30','Canada'); | SELECT * FROM PlayerData; |
Identify the number of IoT sensors in operation in Texas | CREATE TABLE sensor_data (sensor_id INT,sensor_location VARCHAR(50),operation_status VARCHAR(10)); | SELECT COUNT(sensor_id) FROM sensor_data WHERE sensor_location = 'Texas'; |
List all hospitals in California with their corresponding budgets and number of beds? | CREATE TABLE hospitals (id INT,name TEXT,city TEXT,budget FLOAT,beds INT); INSERT INTO hospitals (id,name,city,budget,beds) VALUES (1,'UCLA Medical Center','Los Angeles',3000000,500); | SELECT hospitals.name, hospitals.budget, hospitals.beds FROM hospitals WHERE hospitals.city IN (SELECT cities.name FROM cities WHERE cities.state = 'California'); |
Who are the top 5 customers in the 'customers' table that have purchased the most products from the 'sustainable_products' table? | CREATE TABLE customers (customer_id INT,name VARCHAR(255),email VARCHAR(255)); | SELECT c.name, COUNT(sp.product_id) as purchases FROM customers c JOIN sustainable_products sp ON c.customer_id = sp.customer_id GROUP BY c.name ORDER BY purchases DESC LIMIT 5; |
How many tickets were sold for home games in Q1 of 2021? | CREATE TABLE games (id INT,home_team_id INT,away_team_id INT,home_team_score INT,away_team_score INT,price DECIMAL(5,2),game_date DATE); CREATE VIEW home_games AS SELECT id,home_team_id,price,game_date FROM games; | SELECT COUNT(*) as tickets_sold FROM home_games WHERE game_date BETWEEN '2021-01-01' AND '2021-03-31'; |
Insert new records of ticket sales for a new event, including event and salesperson information. | CREATE TABLE salesperson (salesperson_id INT,name VARCHAR(50),position VARCHAR(50)); CREATE TABLE tickets (ticket_id INT,salesperson_id INT,event_id INT,price DECIMAL(5,2),quantity INT); CREATE TABLE events (event_id INT,name VARCHAR(50),date DATE); INSERT INTO salesperson VALUES (1,'John Doe','Senior Salesperson'); INSERT INTO events VALUES (2,'New Event','2023-04-15'); | INSERT INTO tickets (ticket_id, salesperson_id, event_id, price, quantity) VALUES (2, 1, 2, 75, 50), (3, 2, 2, 65, 75); INSERT INTO events (event_id, name, date) VALUES (2, 'New Event', '2023-04-15'); |
What is the average age of athletes in the athlete_wellbeing table? | CREATE TABLE athlete_wellbeing (athlete_id INT,name VARCHAR(50),age INT,sport VARCHAR(20)); | SELECT AVG(age) FROM athlete_wellbeing; |
What are the top 3 most common types of vulnerabilities found in the healthcare sector in the year 2020? | CREATE TABLE vulnerabilities (id INT,sector VARCHAR(255),year INT,vulnerability VARCHAR(255),count INT); INSERT INTO vulnerabilities (id,sector,year,vulnerability,count) VALUES (1,'healthcare',2020,'SQL injection',2),(2,'healthcare',2020,'Cross-site scripting',3),(3,'healthcare',2020,'Buffer overflow',1); | SELECT vulnerability, count FROM vulnerabilities WHERE sector = 'healthcare' AND year = 2020 GROUP BY vulnerability ORDER BY count DESC LIMIT 3; |
What is the average cost of materials for each garment category? | CREATE TABLE material_costs (garment_category VARCHAR(50),material_cost DECIMAL(10,2)); | SELECT garment_category, AVG(material_cost) AS avg_material_cost FROM material_costs GROUP BY garment_category; |
Which garment type has the highest total sales revenue? | CREATE TABLE transactions (id INT,garment_id INT,price DECIMAL(5,2),quantity INT); INSERT INTO transactions (id,garment_id,price,quantity) VALUES | SELECT garments.type, SUM(transactions.price * transactions.quantity) AS revenue FROM transactions INNER JOIN garments ON transactions.garment_id = garments.id GROUP BY garments.type ORDER BY revenue DESC LIMIT 1; |
What is the policy number, coverage amount, and effective date for policies with a policyholder address in 'New York'? | CREATE TABLE policy (policy_number INT,coverage_amount INT,policyholder_address VARCHAR(50)); INSERT INTO policy VALUES (1,50000,'New York'); INSERT INTO policy VALUES (2,75000,'Los Angeles'); | SELECT policy_number, coverage_amount, effective_date FROM policy INNER JOIN address ON policy.policyholder_address = address.address_line1 WHERE address.city = 'New York'; |
How many workers are represented by the 'United Steelworkers' union? | CREATE TABLE if not exists union_membership (union_id INT,worker_id INT); INSERT INTO union_membership (union_id,worker_id) VALUES (1,1001),(1,1002),(1,1003),(2,2001),(2,2002),(3,3001); | SELECT COUNT(worker_id) FROM union_membership WHERE union_id = (SELECT union_id FROM unions WHERE union_name = 'United Steelworkers'); |
What is the average fuel consumption of vessels with Type 'Tanker'? | CREATE TABLE Vessels (ID VARCHAR(10),Name VARCHAR(20),Type VARCHAR(20),Fuel_Consumption FLOAT); INSERT INTO Vessels (ID,Name,Type,Fuel_Consumption) VALUES ('1','Vessel A','Cargo',5.5),('2','Vessel B','Tanker',7.0),('3','Vessel C','Bulk Carrier',6.0),('4','Vessel D','Container',5.0); | SELECT AVG(Fuel_Consumption) FROM Vessels WHERE Type = 'Tanker'; |
Which vessels had safety incidents in the Mediterranean Sea in the past year? | CREATE TABLE SafetyRecords (Id INT,VesselName VARCHAR(50),Location VARCHAR(50),IncidentDate DATETIME); | SELECT DISTINCT VesselName FROM SafetyRecords WHERE Location LIKE '%Mediterranean Sea%' AND IncidentDate >= DATEADD(YEAR, -1, GETDATE()) GROUP BY VesselName HAVING COUNT(*) > 0; |
What is the average number of installations visited per visitor, partitioned by city? | CREATE TABLE Cities (CityID INT,City VARCHAR(50)); INSERT INTO Cities (CityID,City) VALUES (1,'New York'),(2,'Los Angeles'); CREATE TABLE Visits (VisitID INT,VisitorID INT,CityID INT,InstallationID INT); INSERT INTO Visits (VisitID,VisitorID,CityID,InstallationID) VALUES (1,1,1,1),(2,1,1,2),(3,2,2,3); | SELECT City, AVG(InstallationID) OVER (PARTITION BY CityID) AS AvgInstallationsPerVisitor FROM Visits V JOIN Cities C ON V.CityID = C.CityID; |
Insert a new record of circular economy initiative for the city of New York in 2025. | CREATE TABLE circular_economy(city VARCHAR(20),year INT,initiative VARCHAR(50)); | INSERT INTO circular_economy VALUES('New York', 2025, 'Implementing a city-wide composting program'); |
List the top 3 states with highest water usage in the agricultural sector in 2020. | CREATE TABLE water_usage_by_state (year INT,sector VARCHAR(20),state VARCHAR(20),usage FLOAT); INSERT INTO water_usage_by_state (year,sector,state,usage) VALUES (2020,'agricultural','California',50000); INSERT INTO water_usage_by_state (year,sector,state,usage) VALUES (2020,'agricultural','Texas',45000); INSERT INTO water_usage_by_state (year,sector,state,usage) VALUES (2020,'agricultural','Florida',40000); | SELECT sector, state, SUM(usage) AS total_usage FROM water_usage_by_state WHERE year = 2020 AND sector = 'agricultural' GROUP BY sector, state ORDER BY total_usage DESC LIMIT 3; |
What is the total duration of weightlifting sessions for each member? | CREATE TABLE WorkoutSessions (SessionID INT,MemberID INT,Duration INT,WorkoutType VARCHAR(20)); INSERT INTO WorkoutSessions (SessionID,MemberID,Duration,WorkoutType) VALUES (1,1,60,'Weightlifting'),(2,2,45,'Yoga'),(3,1,75,'Weightlifting'),(4,3,90,'Running'); | SELECT MemberID, SUM(Duration) AS TotalWeightliftingDuration FROM WorkoutSessions WHERE WorkoutType = 'Weightlifting' GROUP BY MemberID; |
What is the total number of workouts and total workout time per user for users with a membership type of 'Basic'? | CREATE TABLE Members (id INT,user_name VARCHAR,membership_type VARCHAR,signup_date DATE); CREATE TABLE Workouts (id INT,user_id INT,workout_date DATE,workout_duration INT); INSERT INTO Members (id,user_name,membership_type,signup_date) VALUES (1,'John Doe','Premium','2020-01-01'),(2,'Jane Smith','Basic','2019-06-15'),(3,'Alice Johnson','Premium','2020-03-20'); INSERT INTO Workouts (id,user_id,workout_date,workout_duration) VALUES (1,1,'2020-01-01',60),(2,1,'2020-01-02',70),(3,2,'2019-06-15',90),(4,3,'2020-03-20',65),(5,3,'2020-03-21',70); | SELECT Members.user_name, SUM(Workouts.workout_duration) AS total_workout_time, COUNT(Workouts.id) AS total_workouts FROM Members JOIN Workouts ON Members.id = Workouts.user_id WHERE Members.membership_type = 'Basic' GROUP BY Members.user_name; |
What is the median investment for agricultural innovation projects in Europe? | CREATE TABLE AgriculturalInnovation (ProjectID INT,ProjectName VARCHAR(50),Location VARCHAR(50),Investment FLOAT); INSERT INTO AgriculturalInnovation (ProjectID,ProjectName,Location,Investment) VALUES (1,'Precision Farming Project','France',120000.00),(2,'Vertical Farming Project','Germany',180000.00); | SELECT AVG(Investment) FROM (SELECT DISTINCT Investment FROM AgriculturalInnovation WHERE Location = 'Europe' ORDER BY Investment) WHERE PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY Investment) = Investment; |
How many satellites have been deployed by each country in the last 10 years? | CREATE TABLE satellite_deployments (id INT,country VARCHAR(255),launch_year INT); INSERT INTO satellite_deployments (id,country,launch_year) VALUES (1,'USA',2012),(2,'China',2013),(3,'Russia',2011),(4,'India',2010),(5,'Japan',2014),(6,'USA',2018),(7,'Germany',2019),(8,'France',2020),(9,'Canada',2017),(10,'Australia',2016); | SELECT country, COUNT(*) AS num_satellites FROM satellite_deployments WHERE launch_year >= 2011 GROUP BY country; |
How many space missions were successfully completed by 'AgencyX'? | CREATE TABLE Missions (id INT,name VARCHAR(50),agency VARCHAR(50),success BOOLEAN); INSERT INTO Missions (id,name,agency,success) VALUES (1,'Mission1','AgencyX',TRUE),(2,'Mission2','AgencyX',FALSE),(3,'Mission3','AgencyY',TRUE); | SELECT COUNT(*) FROM Missions WHERE agency = 'AgencyX' AND success = TRUE; |
Create a view that displays all fish in the 'tropical' and 'temperate' locations | CREATE TABLE fish_stock (fish_id INT PRIMARY KEY,species VARCHAR(50),location VARCHAR(50),biomass FLOAT); INSERT INTO fish_stock (fish_id,species,location,biomass) VALUES (1,'tuna','tropical',250.5),(2,'salmon','arctic',180.3),(3,'cod','temperate',120.0); | CREATE VIEW fish_in_warm_waters AS SELECT * FROM fish_stock WHERE location IN ('tropical', 'temperate'); |
Update the name of the dispensary with dispensary_id 502 to 'The Healing Center' in the 'dispensaries' table | CREATE TABLE dispensaries (dispensary_id INT,name VARCHAR(255),address VARCHAR(255)); | UPDATE dispensaries SET name = 'The Healing Center' WHERE dispensary_id = 502; |
What are the average innovation scores for products manufactured in France and Germany, grouped by chemical compound? | CREATE TABLE product (id INT,name VARCHAR(255),manufacturer_country VARCHAR(255),chemical_compound VARCHAR(255),innovation_score INT); INSERT INTO product (id,name,manufacturer_country,chemical_compound,innovation_score) VALUES (1,'Product A','France','Compound X',80),(2,'Product B','Germany','Compound Y',85),(3,'Product C','Mexico','Compound Z',70); | SELECT chemical_compound, AVG(innovation_score) FROM product WHERE manufacturer_country IN ('France', 'Germany') GROUP BY chemical_compound; |
Remove the 'budget' column from 'climate_mitigation_projects' table | CREATE TABLE climate_mitigation_projects (id INT PRIMARY KEY,name VARCHAR(50),location VARCHAR(50),start_date DATE,end_date DATE,budget FLOAT); | ALTER TABLE climate_mitigation_projects DROP COLUMN budget; |
What is the total R&D expenditure for each drug category? | CREATE TABLE rd_expenditure (drug_id INT,category_id INT,amount INT); INSERT INTO rd_expenditure (drug_id,category_id,amount) VALUES (101,1,20000),(102,1,25000),(201,2,15000),(202,2,20000),(301,3,30000); CREATE TABLE drug_categories (id INT,category VARCHAR(255)); INSERT INTO drug_categories (id,category) VALUES (1,'Analgesics'),(2,'Antidepressants'),(3,'Antihistamines'); | SELECT dc.category, SUM(re.amount) as total_rd_expenditure FROM rd_expenditure re JOIN drug_categories dc ON re.category_id = dc.id GROUP BY dc.category; |
How many infectious disease cases were reported in Texas and Florida in 2020 and 2021? | CREATE TABLE infectious_disease_reporting (state VARCHAR(20),year INT,cases INT); INSERT INTO infectious_disease_reporting (state,year,cases) VALUES ('Texas',2020,1000),('Texas',2021,1200),('Florida',2020,1500),('Florida',2021,1800); | SELECT SUM(cases) FROM infectious_disease_reporting WHERE state IN ('Texas', 'Florida') AND year BETWEEN 2020 AND 2021; |
What is the minimum funding received by a startup founded by a person from the LGBTQ+ community in the real estate sector? | CREATE TABLE startups(id INT,name TEXT,industry TEXT,founder_community TEXT,funding FLOAT); INSERT INTO startups (id,name,industry,founder_community,funding) VALUES (1,'RealtyPride','Real Estate','LGBTQ+',500000); | SELECT MIN(funding) FROM startups WHERE industry = 'Real Estate' AND founder_community = 'LGBTQ+'; |
What is the average yield of crops for each country, ranked by average yield? | CREATE TABLE farming (id INT,name TEXT,country TEXT,crop TEXT,yield INT); INSERT INTO farming VALUES (1,'Smith Farm','USA','Corn',120),(2,'Brown Farm','Canada','Soybeans',45),(3,'Jones Farm','Mexico','Wheat',80); | SELECT country, AVG(yield) as avg_yield, ROW_NUMBER() OVER (ORDER BY AVG(yield) DESC) as rank FROM farming GROUP BY country; |
What is the average yield per acre for crops grown in the Pacific region in 2021? | CREATE TABLE crops (id INT,name VARCHAR(50),yield INT,acrate DECIMAL(5,2),region VARCHAR(50),year INT); INSERT INTO crops (id,name,yield,acrate,region,year) VALUES (1,'Corn',150,2.3,'Pacific',2021); | SELECT AVG(yield * acrate) FROM crops WHERE region = 'Pacific' AND year = 2021; |
How many students with disabilities are enrolled in each region's universities? | CREATE TABLE Regions (RegionID INT PRIMARY KEY,RegionName VARCHAR(50)); CREATE TABLE Universities (UniversityID INT PRIMARY KEY,UniversityName VARCHAR(50),RegionID INT,FOREIGN KEY (RegionID) REFERENCES Regions(RegionID)); CREATE TABLE Students (StudentID INT PRIMARY KEY,StudentName VARCHAR(50),Disability BOOLEAN,UniversityID INT,FOREIGN KEY (UniversityID) REFERENCES Universities(UniversityID)); | SELECT r.RegionName, COUNT(s.StudentID) as StudentCount FROM Regions r JOIN Universities u ON r.RegionID = u.RegionID JOIN Students s ON u.UniversityID = s.UniversityID WHERE s.Disability = TRUE GROUP BY r.RegionName; |
What is the minimum depth ever reached by a submersible in the Pacific Ocean? | CREATE TABLE submersible_dives (id INT,submersible_name VARCHAR(50),region VARCHAR(20),dive_date DATE,max_depth INT,min_depth INT);INSERT INTO submersible_dives (id,submersible_name,region,dive_date,max_depth,min_depth) VALUES (1,'Trieste','Atlantic','1960-01-23',10972,10916);INSERT INTO submersible_dives (id,submersible_name,region,dive_date,max_depth,min_depth) VALUES (2,'Mir','Atlantic','2000-08-23',6170,6000);INSERT INTO submersible_dives (id,submersible_name,region,dive_date,max_depth,min_depth) VALUES (3,'Pacific_Drop','Pacific','2005-06-15',8000,7500); | SELECT MIN(min_depth) FROM submersible_dives WHERE region = 'Pacific'; |
What are the cryptocurrency exchanges with their corresponding blockchain companies, ranked by exchange ID in ascending order, for the Bitcoin platform? | CREATE TABLE cryptocurrency_exchanges (exchange_id INT,exchange_name VARCHAR(50),company_id INT); INSERT INTO cryptocurrency_exchanges (exchange_id,exchange_name,company_id) VALUES (1,'Binance',1); INSERT INTO cryptocurrency_exchanges (exchange_id,exchange_name,company_id) VALUES (2,'Coinbase',2); INSERT INTO cryptocurrency_exchanges (exchange_id,exchange_name,company_id) VALUES (3,'Kraken',3); CREATE TABLE blockchain_companies (company_id INT,company_name VARCHAR(50),platform VARCHAR(50)); INSERT INTO blockchain_companies (company_id,company_name,platform) VALUES (1,'Binance','Bitcoin'); INSERT INTO blockchain_companies (company_id,company_name,platform) VALUES (2,'Blockstream','Bitcoin'); INSERT INTO blockchain_companies (company_id,company_name,platform) VALUES (3,'Blockchair','Bitcoin'); | SELECT ce.exchange_name, bc.company_name, ce.exchange_id, ROW_NUMBER() OVER (PARTITION BY bc.platform ORDER BY ce.exchange_id ASC) as rank FROM cryptocurrency_exchanges ce JOIN blockchain_companies bc ON ce.company_id = bc.company_id WHERE bc.platform = 'Bitcoin'; |
What is the average carbon sequestration per hectare for the entire dataset? | CREATE TABLE carbon_sequestration(region VARCHAR(255),sequestration FLOAT,area INT); INSERT INTO carbon_sequestration(region,sequestration,area) VALUES ('North',5.6,1000),('South',4.8,1500),('East',6.2,1200),('West',5.1,1800); | SELECT AVG(sequestration) FROM carbon_sequestration; |
What is the average carbon sequestration rate per tree species by region? | 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 regions (region_id INT,region_name VARCHAR(100)); INSERT INTO regions (region_id,region_name) VALUES (1,'Northern'),(2,'Southern'),(3,'Eastern'),(4,'Western'); CREATE TABLE tree_regions (tree_id INT,species_id INT,region_id INT); INSERT INTO tree_regions (tree_id,species_id,region_id) VALUES (1,1,1),(2,2,2),(3,3,3),(4,4,4); | SELECT r.region_name, AVG(ts.avg_carbon_sequestration_rate) as avg_rate FROM tree_regions tr JOIN tree_species ts ON tr.species_id = ts.species_id JOIN regions r ON tr.region_id = r.region_id GROUP BY r.region_name; |
Update the price of all "Lipstick" products to $10.00. | CREATE TABLE products (id INT PRIMARY KEY,name VARCHAR(255),category VARCHAR(255),price DECIMAL(5,2)); | UPDATE products SET price = 10.00 WHERE name = 'Lipstick'; |
What was the average response time for each community district in the past month? | CREATE TABLE community_districts (cd_number INT,community_name VARCHAR(255)); INSERT INTO community_districts (cd_number,community_name) VALUES (1,'Williamsburg'),(2,'Greenpoint'),(3,'Bushwick'); CREATE TABLE response_times (response_date DATE,cd_number INT,response_time INT); | SELECT cd.community_name, AVG(rt.response_time) as avg_response_time FROM community_districts cd JOIN response_times rt ON cd.cd_number = rt.cd_number WHERE rt.response_date >= CURDATE() - INTERVAL 1 MONTH GROUP BY cd.community_name; |
List all artists who have performed in New York and Chicago, along with their highest-earning performance. | CREATE TABLE artist_events (artist_id INT,event_id INT,earnings DECIMAL(5,2)); CREATE TABLE artists (id INT,name VARCHAR(50)); CREATE TABLE events (id INT,city VARCHAR(20)); | SELECT artists.name, MAX(artist_events.earnings) FROM artists INNER JOIN artist_events ON artists.id = artist_events.artist_id INNER JOIN events ON artist_events.event_id = events.id WHERE city IN ('New York', 'Chicago') GROUP BY artists.name; |
Identify the number of unique clients in the Oceanian region who have made at least one transaction. | CREATE TABLE clients (client_id INT,name VARCHAR(50),region VARCHAR(20)); CREATE TABLE transactions (transaction_id INT,client_id INT); INSERT INTO clients (client_id,name,region) VALUES (1,'John Doe','Oceanian'),(2,'Jane Smith','Oceanian'),(3,'Mike Johnson','European'); INSERT INTO transactions (transaction_id,client_id) VALUES (1,1),(2,1),(3,2),(4,3); | SELECT COUNT(DISTINCT c.client_id) FROM clients c INNER JOIN transactions t ON c.client_id = t.client_id WHERE c.region = 'Oceanian'; |
What is the number of patients diagnosed with hypertension in the rural county of "Mountain" who are also over the age of 65? | CREATE TABLE patients (id INT,name VARCHAR(50),age INT,diagnosis VARCHAR(50)); INSERT INTO patients (id,name,age,diagnosis) VALUES (1,'John Doe',55,'Diabetes'); INSERT INTO patients (id,name,age,diagnosis) VALUES (2,'Jane Smith',60,'Hypertension'); INSERT INTO patients (id,name,age,diagnosis) VALUES (3,'Bob Johnson',65,'Hypertension'); INSERT INTO patients (id,name,age,diagnosis) VALUES (4,'Alice Williams',70,'Hypertension'); CREATE TABLE county (name VARCHAR(50),population INT); INSERT INTO county (name,population) VALUES ('Mountain',7000); | SELECT COUNT(*) FROM patients WHERE diagnosis = 'Hypertension' AND age > 65 AND (SELECT name FROM county WHERE population = (SELECT population FROM county WHERE name = 'Mountain')) = 'Mountain'; |
List all countries with their respective number of artists | CREATE TABLE Country (id INT,country VARCHAR(255)); CREATE TABLE Artist (id INT,country_id INT,name VARCHAR(255)); | SELECT C.country, COUNT(A.id) as artist_count FROM Country C INNER JOIN Artist A ON C.id = A.country_id GROUP BY C.country; |
How many open pedagogy resources were accessed in 'Spring 2022'? | CREATE TABLE open_pedagogy_resources (resource_id INT,access_date DATE); INSERT INTO open_pedagogy_resources (resource_id,access_date) VALUES (1,'2022-03-01'),(2,'2022-03-02'),(3,'2022-03-03'); | SELECT COUNT(DISTINCT resource_id) FROM open_pedagogy_resources WHERE access_date = '2022-03-01'; |
What is the average mental health score of students in each school, ranked from highest to lowest? | CREATE TABLE schools (school_id INT,school_name VARCHAR(50)); INSERT INTO schools VALUES (1,'School A'),(2,'School B'),(3,'School C'); CREATE TABLE student_mental_health (student_id INT,school_id INT,mental_health_score INT); INSERT INTO student_mental_health VALUES (1,1,75),(2,1,80),(3,2,60),(4,2,65),(5,3,85),(6,3,90); | SELECT school_id, school_name, AVG(mental_health_score) as avg_score FROM student_mental_health JOIN schools ON student_mental_health.school_id = schools.school_id GROUP BY school_id, school_name ORDER BY avg_score DESC; |
What is the maximum production quantity for wells in the 'gulf of Mexico'? | CREATE TABLE wells (id INT,name VARCHAR(255),location VARCHAR(255),production_quantity INT); INSERT INTO wells (id,name,location,production_quantity) VALUES (1,'Well A','North Sea',1000),(2,'Well B','Gulf of Mexico',2000),(3,'Well C','North Sea',1500),(4,'Well D','Gulf of Mexico',2500); | SELECT MAX(production_quantity) FROM wells WHERE location = 'Gulf of Mexico'; |
Which wells in 'FieldA' have a production greater than 1500 in any month of 2021? | CREATE TABLE wells (well_id varchar(10),field varchar(10),production int,datetime date); INSERT INTO wells (well_id,field,production,datetime) VALUES ('W001','FieldA',1500,'2021-01-01'),('W002','FieldA',1800,'2021-02-01'); | SELECT well_id, field, production FROM wells WHERE field = 'FieldA' AND production > 1500 AND YEAR(datetime) = 2021; |
Calculate the average number of goals per game for the top 2 teams in the Indian Super League | CREATE TABLE teams (id INT PRIMARY KEY,name TEXT,league TEXT,goals_scored INT,goals_conceded INT,games_played INT); INSERT INTO teams (id,name,league,goals_scored,goals_conceded,games_played) VALUES (1,'Mumbai City FC','Indian Super League',22,12,16),(2,'Hyderabad FC','Indian Super League',20,12,16),(3,'Goa FC','Indian Super League',18,12,16),(4,'Kerala Blasters FC','Indian Super League',17,13,16),(5,'Bengaluru FC','Indian Super League',15,12,16); | SELECT AVG(goals_scored/games_played) FROM (SELECT * FROM teams ORDER BY goals_scored DESC LIMIT 2) AS top_two_teams; |
Find the average height of basketball players in the NBA, categorized by their position. | CREATE TABLE nba_players_height (id INT,player_id INT,height_feet INT,height_inches INT); CREATE TABLE nba_players (id INT,name VARCHAR(100),team VARCHAR(50),position VARCHAR(50)); | SELECT position, AVG(height_feet + height_inches / 12) as avg_height FROM nba_players_height JOIN nba_players ON nba_players_height.player_id = nba_players.id GROUP BY position; |
List the top 5 countries with the most gold medals won in the Summer Olympics. | CREATE TABLE summer_olympics (country_id INT,country_name VARCHAR(255),medal VARCHAR(10)); | SELECT country_name, COUNT(*) AS total_golds FROM summer_olympics WHERE medal = 'Gold' GROUP BY country_name ORDER BY total_golds DESC LIMIT 5; |
List the names and organizations of all volunteers who have provided support in Syria and Yemen, sorted by organization. | CREATE TABLE support_provision (id INT,name VARCHAR(255),organization VARCHAR(255),country VARCHAR(255)); INSERT INTO support_provision (id,name,organization,country) VALUES ('1','Ahmad','Doctors Without Borders','Syria'),('2','Bana','UNHCR','Yemen'),('3','Cemal','World Food Programme','Syria'),('4','Dalia','Red Cross','Yemen'),('5','Elias','Doctors Without Borders','Yemen'),('6','Farah','UNHCR','Syria'); | SELECT name, organization FROM support_provision WHERE country IN ('Syria', 'Yemen') ORDER BY organization ASC; |
What was the total number of community development projects and total funds spent on them by each organization in 2021? | CREATE TABLE community_development (project_id INT,organization_id INT,sector VARCHAR(20),budget DECIMAL(10,2),start_date DATE); INSERT INTO community_development (project_id,organization_id,sector,budget,start_date) VALUES (1101,1001,'Education',60000.00,'2021-01-01'),(1102,1001,'Healthcare',85000.00,'2021-02-15'),(1103,1002,'Infrastructure',110000.00,'2021-03-30'),(1104,1003,'Agriculture',90000.00,'2021-04-12'); | SELECT organization_id, COUNT(*) as total_projects, SUM(budget) as total_funds_spent FROM community_development WHERE EXTRACT(YEAR FROM start_date) = 2021 GROUP BY organization_id; |
Which organizations have provided legal assistance to refugees in the Middle East and North Africa? | CREATE TABLE legal_assistance (id INT,organization_name VARCHAR(50),region VARCHAR(20),provided_legal_assistance BOOLEAN); INSERT INTO legal_assistance (id,organization_name,region,provided_legal_assistance) VALUES (1,'Amnesty International','Middle East',TRUE),(2,'International Rescue Committee','North Africa',TRUE),(3,'Save the Children','Asia',FALSE),(4,'Oxfam','Africa',FALSE); | SELECT DISTINCT organization_name FROM legal_assistance WHERE region IN ('Middle East', 'North Africa') AND provided_legal_assistance = TRUE; |
How many AI ethics research papers were published in the last 6 months? | CREATE TABLE papers(id INT,title TEXT,publication_date DATE); INSERT INTO papers(id,title,publication_date) VALUES (1,'Ethical AI: A Review','2022-01-01'); INSERT INTO papers(id,title,publication_date) VALUES (2,'Bias in AI Systems','2022-02-15'); INSERT INTO papers(id,title,publication_date) VALUES (3,'AI for Social Good','2021-07-01'); | SELECT COUNT(*) FROM papers WHERE publication_date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH); |
What is the minimum fare for ferries in the 'coastal' schema, excluding fares greater than $5? | CREATE SCHEMA coastal; CREATE TABLE coastal.ferries (id INT,fare DECIMAL); INSERT INTO coastal.ferries (id,fare) VALUES (1,4.50),(2,3.75),(3,5.00); | SELECT MIN(fare) FROM coastal.ferries WHERE fare < 5; |
What is the average rating of factories in a given country, based on worker satisfaction surveys? | CREATE TABLE FactoryRatings (id INT,country VARCHAR(50),rating DECIMAL(2,1)); | SELECT country, AVG(rating) as avg_rating FROM FactoryRatings GROUP BY country; |
Which workers in the 'fair_labor' table earn more than the worker 'Alice'? | CREATE TABLE fair_labor (id INT,worker VARCHAR(20),hourly_wage DECIMAL(4,2)); INSERT INTO fair_labor (id,worker,hourly_wage) VALUES (1,'John',15.00),(2,'Jane',14.50),(3,'Alice',17.00); | SELECT * FROM fair_labor WHERE hourly_wage > (SELECT hourly_wage FROM fair_labor WHERE worker = 'Alice'); |
Select all fabrics with a sustainability score greater than 0.8 | CREATE TABLE sustainable_fabrics (fabric_id INT PRIMARY KEY,fabric_name VARCHAR(100),country_of_origin VARCHAR(50),sustainability_score FLOAT); INSERT INTO sustainable_fabrics (fabric_id,fabric_name,country_of_origin,sustainability_score) VALUES (1,'Organic Cotton','India',0.9),(2,'Recycled Polyester','China',0.7),(3,'Hemp','France',0.85); | SELECT * FROM sustainable_fabrics WHERE sustainability_score > 0.8; |
What is the percentage of plus size clothing in the fashion trend data? | CREATE TABLE fashion_trends (trend_id INT,clothing_size VARCHAR(10),popularity INT); INSERT INTO fashion_trends (trend_id,clothing_size,popularity) VALUES (1,'Small',2000),(2,'Medium',3000),(3,'Large',2500),(4,'XL',1800),(5,'XXL',1200); | SELECT (SUM(CASE WHEN clothing_size LIKE '%Plus%' THEN popularity ELSE 0 END) / SUM(popularity)) * 100 AS percentage FROM fashion_trends; |
List all clients who have a socially responsible loan and a credit card? | CREATE TABLE socially_responsible_loans (client_id INT,loan_type VARCHAR(20)); INSERT INTO socially_responsible_loans (client_id,loan_type) VALUES (1,'personal'),(2,'auto'),(3,'mortgage'); CREATE TABLE credit_cards (client_id INT,card_type VARCHAR(20)); INSERT INTO credit_cards (client_id,card_type) VALUES (1,'gold'),(2,'platinum'),(4,'black'); | SELECT DISTINCT srl.client_id FROM socially_responsible_loans srl JOIN credit_cards cc ON srl.client_id = cc.client_id; |
Which food safety records were updated in the last 7 days for products in the 'Seafood' category? | CREATE TABLE FoodSafetyRecords (record_id INT,product_id INT,updated_at TIMESTAMP); CREATE TABLE Products (product_id INT,product_name VARCHAR(100),category VARCHAR(50)); INSERT INTO FoodSafetyRecords (record_id,product_id,updated_at) VALUES (1,1,'2022-01-01 12:00:00'),(2,2,'2022-01-15 14:00:00'),(3,3,'2022-02-01 09:00:00'); INSERT INTO Products (product_id,product_name,category) VALUES (1,'Salmon','Seafood'),(2,'Broccoli','Vegetables'),(3,'Bread','Bakery'); | SELECT * FROM FoodSafetyRecords INNER JOIN Products ON FoodSafetyRecords.product_id = Products.product_id WHERE Products.category = 'Seafood' AND FoodSafetyRecords.updated_at >= NOW() - INTERVAL '7 days'; |
What are the bioprocess engineering companies that received the most funding? | CREATE TABLE biotech_funding (company_id INT,industry TEXT,amount INT); INSERT INTO biotech_funding (company_id,industry,amount) VALUES (1,'Genetic Research',5000000); INSERT INTO biotech_funding (company_id,industry,amount) VALUES (2,'Bioprocess Engineering',7000000); CREATE TABLE biotech_companies (company_id INT PRIMARY KEY,name TEXT,location TEXT,industry TEXT); INSERT INTO biotech_companies (company_id,name,location,industry) VALUES (1,'Company C','Seattle','Bioprocess Engineering'); INSERT INTO biotech_companies (company_id,name,location,industry) VALUES (2,'Company D','London','Genetic Research'); | SELECT b.name, b.industry, f.amount FROM biotech_companies b INNER JOIN biotech_funding f ON b.company_id = f.company_id WHERE b.industry = 'Bioprocess Engineering' ORDER BY f.amount DESC; |
What is the total number of criminal cases heard by the Supreme Court in the fiscal year 2021? | CREATE TABLE court_cases(case_id INT,case_date DATE,case_type VARCHAR(255),agency VARCHAR(255),fiscal_year INT); INSERT INTO court_cases(case_id,case_date,case_type,agency,fiscal_year) VALUES (1,'2021-01-01','criminal','Supreme Court',2021); | SELECT COUNT(*) FROM court_cases WHERE agency = 'Supreme Court' AND case_type = 'criminal' AND fiscal_year = 2021; |
What is the cultural competency score for each hospital in the northeast region? | CREATE TABLE Hospitals (HospitalID INT,Name VARCHAR(255),Region VARCHAR(25),CulturalCompetencyScore INT); INSERT INTO Hospitals (HospitalID,Name,Region,CulturalCompetencyScore) VALUES (1,'Hospital A','Northeast',85),(2,'Hospital B','Northeast',90),(3,'Hospital C','South',75),(4,'Hospital D','Midwest',80); | SELECT Region, AVG(CulturalCompetencyScore) as AverageScore FROM Hospitals WHERE Region = 'Northeast' GROUP BY Region; |
What is the difference in the number of eco-friendly hotels between the top 2 countries? | CREATE TABLE eco_hotel_count (country TEXT,num_hotels INT); INSERT INTO eco_hotel_count (country,num_hotels) VALUES ('France',100),('Italy',120),('Germany',150),('Spain',110),('UK',160); | SELECT (MAX(num_hotels) OVER (PARTITION BY num_hotels <= 2) - MIN(num_hotels) OVER (PARTITION BY num_hotels <= 2)) AS hotel_difference FROM eco_hotel_count WHERE country IN ('France', 'Italy'); |
What is the average temperature change in the Arctic region by month for the year 2020? | CREATE TABLE WeatherData (location varchar(50),date DATE,temperature float); | SELECT MONTH(date) AS month, AVG(temperature) AS avg_temp FROM WeatherData WHERE location LIKE 'Arctic%' AND YEAR(date) = 2020 GROUP BY month; |
What is the maximum number of whales seen in a single sighting? | CREATE TABLE WhaleSightings (id INT,sighting_id INT,number_of_whales INT); INSERT INTO WhaleSightings (id,sighting_id,number_of_whales) VALUES (1,1001,3),(2,1002,5),(3,1003,4); | SELECT sighting_id, MAX(number_of_whales) FROM WhaleSightings; |
Find the number of unique mental health conditions that have been treated in each region, excluding conditions that have been treated in only one region. | CREATE TABLE treatments (id INT,condition_id INT,region VARCHAR(50)); INSERT INTO treatments (id,condition_id,region) VALUES (1,1,'Asia'),(2,1,'Europe'),(3,2,'Asia'),(4,2,'Europe'),(5,3,'Asia'),(6,3,'Europe'),(7,4,'Asia'),(8,4,'Europe'),(9,5,'Asia'),(10,5,'Europe'),(11,6,'Asia'),(12,6,'Europe'),(13,7,'Asia'),(14,7,'Europe'),(15,8,'Asia'),(16,8,'Europe'),(17,9,'Asia'),(18,9,'Europe'),(19,10,'Asia'),(20,10,'Europe'); | SELECT region, COUNT(DISTINCT condition_id) FROM treatments GROUP BY region HAVING COUNT(DISTINCT condition_id) > 1; |
What is the average age of psychologists in the mental_health_professionals table? | CREATE TABLE mental_health_professionals (professional_id INT,name VARCHAR(50),age INT,profession VARCHAR(50)); INSERT INTO mental_health_professionals (professional_id,name,age,profession) VALUES (1,'John Doe',45,'Psychologist'); INSERT INTO mental_health_professionals (professional_id,name,age,profession) VALUES (2,'Jane Smith',38,'Psychologist'); | SELECT AVG(age) FROM mental_health_professionals WHERE profession = 'Psychologist'; |
What is the average arrival age of visitors from 'Canada' and 'Mexico'? | CREATE TABLE Visitors (VisitorID INT,Age INT,Country VARCHAR(50)); INSERT INTO Visitors (VisitorID,Age,Country) VALUES (1,35,'Canada'),(2,45,'Mexico'); | SELECT AVG(Age) FROM Visitors WHERE Country IN ('Canada', 'Mexico'); |
What is the average age of volunteers who have completed more than 5 training sessions in the volunteers table? | CREATE TABLE volunteers (id INT,name VARCHAR(50),age INT,sessions_completed INT); | SELECT AVG(age) FROM volunteers WHERE sessions_completed > 5; |
What are the total sales for the 'Dessert' category for the current year? | CREATE TABLE menus (menu_id INT,name VARCHAR(100),category VARCHAR(50),price DECIMAL(5,2),quantity INT); INSERT INTO menus (menu_id,name,category,price,quantity) VALUES (1,'Chocolate Mousse','Dessert',6.99,250),(2,'Tiramisu','Dessert',7.99,200); | SELECT category, SUM(quantity * price) as total_sales FROM menus WHERE YEAR(order_date) = YEAR(CURRENT_DATE()) AND category = 'Dessert' GROUP BY category; |
What is the total number of military equipment sold to each country and the total cost for each equipment type? | CREATE TABLE EquipmentSales (equipment_id INT,country VARCHAR(50),equipment_type VARCHAR(50),quantity INT,sale_price DECIMAL(10,2),sale_date DATE); INSERT INTO EquipmentSales (equipment_id,country,equipment_type,quantity,sale_price,sale_date) VALUES (1,'USA','Tank',15,1000000.00,'2021-04-15'); INSERT INTO EquipmentSales (equipment_id,country,equipment_type,quantity,sale_price,sale_date) VALUES (2,'Canada','Fighter Jet',10,80000000.00,'2021-04-20'); | SELECT country, equipment_type, COUNT(*) as total_sales, SUM(quantity) as total_quantity, SUM(sale_price) as total_cost FROM EquipmentSales GROUP BY country, equipment_type; |
Who were the top 3 suppliers of military equipment to North America in Q3 2022? | CREATE TABLE military_sales (id INT,supplier VARCHAR(50),region VARCHAR(20),quarter VARCHAR(10),year INT,quantity INT); INSERT INTO military_sales (id,supplier,region,quarter,year,quantity) VALUES (1,'Supplier X','North America','Q3',2022,500); | SELECT supplier, SUM(quantity) as total_quantity FROM military_sales WHERE region = 'North America' AND quarter = 'Q3' AND year = 2022 GROUP BY supplier ORDER BY total_quantity DESC LIMIT 3; |
Update the 'mine_revenue' table by increasing the revenue of 'Grasberg' mine in Indonesia by 10% for the year 2019. | CREATE TABLE mine_revenue (id INT,mine_name VARCHAR(50),country VARCHAR(50),revenue FLOAT,year INT,PRIMARY KEY (id)); INSERT INTO mine_revenue (id,mine_name,country,revenue,year) VALUES (1,'Grasberg','Indonesia',12000000000,2019),(2,'Cerrejon','Colombia',13500000000,2019); | UPDATE mine_revenue SET revenue = revenue * 1.1 WHERE mine_name = 'Grasberg' AND country = 'Indonesia' AND year = 2019; |
What is the average labor productivity of the Emerald Echo mine for each year? | CREATE TABLE labor_productivity (year INT,mine_name TEXT,workers INT,productivity FLOAT); INSERT INTO labor_productivity (year,mine_name,workers,productivity) VALUES (2015,'Aggromine A',50,32.4),(2016,'Borax Bravo',80,45.6),(2017,'Carbon Cat',100,136.7),(2017,'Carbon Cat',110,142.3),(2018,'Diamond Delta',120,150.5),(2019,'Emerald Echo',130,165.2),(2019,'Emerald Echo',140,170.8); | SELECT year, mine_name, AVG(productivity) as avg_productivity FROM labor_productivity WHERE mine_name = 'Emerald Echo' GROUP BY year; |
Delete records from the 'resource_depletion' table where the 'resource_type' is 'Coal' | CREATE TABLE resource_depletion (id INT,resource_type VARCHAR(20),quantity INT,depletion_date DATE); INSERT INTO resource_depletion (id,resource_type,quantity,depletion_date) VALUES (1,'Coal',1000,'2020-01-01'),(2,'Iron Ore',500,'2019-12-31'),(3,'Coal',1500,'2018-12-31'); | DELETE FROM resource_depletion WHERE resource_type = 'Coal'; |
Update the 'reserve_tons' of the record in the 'resources' table with ID 789 to 1500 tons for a copper mine in 'Chile' in 2020 | CREATE TABLE resources (id INT,mine_type VARCHAR(50),country VARCHAR(50),year INT,reserve_tons INT); INSERT INTO resources (id,mine_type,country,year,reserve_tons) VALUES (789,'copper','Chile',2020,1000); | UPDATE resources SET reserve_tons = 1500 WHERE id = 789; |
List the broadband subscribers with compliance issues and the corresponding compliance issue description. | CREATE TABLE broadband_subscribers (subscriber_id INT,name VARCHAR(50),has_compliance_issue INT); CREATE TABLE compliance_issues (issue_id INT,description VARCHAR(100)); INSERT INTO broadband_subscribers (subscriber_id,name,has_compliance_issue) VALUES (1,'Jane Doe',1); INSERT INTO compliance_issues (issue_id,description) VALUES (1,'Non-payment of annual fee'); | SELECT subscribers.name, compliance_issues.description FROM broadband_subscribers AS subscribers JOIN compliance_issues ON subscribers.has_compliance_issue = compliance_issues.issue_id; |
What is the average monthly data usage for mobile subscribers in each region, and the total number of network devices installed in each region? | CREATE TABLE mobile_subscribers (id INT,region VARCHAR(20),data_usage INT,usage_date DATE); CREATE TABLE network_devices (id INT,region VARCHAR(20),install_date DATE); | SELECT m.region, AVG(m.data_usage) AS avg_data_usage, COUNT(n.id) AS num_devices FROM mobile_subscribers m INNER JOIN network_devices n ON m.region = n.region GROUP BY m.region; |
What is the average monthly data usage for mobile subscribers in the city of Dallas? | CREATE TABLE mobile_subscribers (subscriber_id INT,city VARCHAR(255),data_usage_gb DECIMAL(5,2)); INSERT INTO mobile_subscribers (subscriber_id,city,data_usage_gb) VALUES (1,'Dallas',12.3),(2,'Dallas',10.5),(3,'Austin',11.7); | SELECT AVG(data_usage_gb) FROM mobile_subscribers WHERE city = 'Dallas'; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.