instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the average speed of public electric buses in New York? | CREATE TABLE public_transportation (id INT,type VARCHAR(20),speed FLOAT,city VARCHAR(20)); INSERT INTO public_transportation (id,type,speed,city) VALUES (1,'Bus',15.5,'New York'); | SELECT AVG(speed) FROM public_transportation WHERE type = 'Bus' AND city = 'New York'; |
How many heritage sites are in each African country? | CREATE TABLE Countries (CountryID INT,CountryName VARCHAR(50),Continent VARCHAR(50)); CREATE TABLE HeritageSites (SiteID INT,CountryID INT,SiteName VARCHAR(50),SiteYear INT); INSERT INTO Countries VALUES (1,'Egypt','Africa'),(2,'South Africa','Africa'),(3,'Canada','North America'); INSERT INTO HeritageSites VALUES (1,1,'Pyramids of Giza',2490),(2,1,'Abu Simbel',1244),(3,2,'Cradle of Humankind',1999); | SELECT Countries.CountryName, COUNT(HeritageSites.SiteID) AS SiteCount FROM Countries INNER JOIN HeritageSites ON Countries.CountryID = HeritageSites.CountryID WHERE Countries.Continent = 'Africa' GROUP BY Countries.CountryName; |
What are the names and locations of all factories with a production output above 5000 units that use renewable energy sources? | CREATE TABLE factories (factory_id INT,name VARCHAR(100),location VARCHAR(100),renewable_energy BOOLEAN,production_output INT); INSERT INTO factories (factory_id,name,location,renewable_energy,production_output) VALUES (1,'ABC Factory','New York',TRUE,5500),(2,'XYZ Factory','California',FALSE,4000),(3,'LMN Factory','Texas',TRUE,6000); | SELECT name, location FROM factories WHERE production_output > 5000 AND renewable_energy = TRUE; |
What is the maximum number of sessions attended by a participant in the 'Oakland_Reentry' program? | CREATE TABLE participants (id INT,program VARCHAR(20),sessions INT); INSERT INTO participants (id,program,sessions) VALUES (1,'Oakland_Reentry',10),(2,'San_Francisco_Reentry',12),(3,'Oakland_Reentry',8),(4,'Legal_Assistance',6); | SELECT MAX(sessions) FROM participants WHERE program = 'Oakland_Reentry'; |
Which maritime laws apply to the Atlantic Ocean? | CREATE TABLE MaritimeLaw (ID INT,Law VARCHAR(255),Applies_To VARCHAR(255)); INSERT INTO MaritimeLaw (ID,Law,Applies_To) VALUES (2,'Navigation Rules','Atlantic Ocean'); | SELECT Law FROM MaritimeLaw WHERE Applies_To = 'Atlantic Ocean'; |
Find all bus and train routes with accessibility features for disabled passengers in London and Tokyo. | CREATE TABLE london_routes (route_id INT,route_name VARCHAR(50),is_accessible BOOLEAN); INSERT INTO london_routes (route_id,route_name,is_accessible) VALUES (1,'Victoria Line',true),(2,'Central Line',false),(3,'Northern Line',true); CREATE TABLE tokyo_routes (route_id INT,route_name VARCHAR(50),is_accessible BOOLEAN); INSERT INTO tokyo_routes (route_id,route_name,is_accessible) VALUES (4,'Yamanote Line',true),(5,'Chuo Line',false),(6,'Tokaido Line',true); | SELECT route_name FROM london_routes WHERE is_accessible = true UNION SELECT route_name FROM tokyo_routes WHERE is_accessible = true; |
List the names of all hospitals in Texas and their corresponding city. | CREATE TABLE Hospitals (HospitalID int,HospitalName varchar(255),State varchar(255),City varchar(255)); INSERT INTO Hospitals (HospitalID,HospitalName,State,City) VALUES (1,'Texas General Hospital','Texas','Austin'),(2,'Houston Medical Center','Texas','Houston'); | SELECT HospitalName, City FROM Hospitals WHERE State = 'Texas'; |
Find the number of new threat intelligence reports created per day in the last week. | CREATE TABLE threat_intelligence (report_id INT,creation_date DATE); INSERT INTO threat_intelligence VALUES (1,'2021-07-01'),(2,'2021-07-02'),(3,'2021-07-02'); | SELECT creation_date, COUNT(*) OVER (PARTITION BY creation_date) FROM threat_intelligence WHERE creation_date >= CURRENT_DATE - INTERVAL '7 days'; |
Which countries have the highest and lowest production costs for ethical garments? | CREATE TABLE country_costs (id INT,country VARCHAR(255),garment_type VARCHAR(255),production_cost DECIMAL(10,2)); | SELECT country, production_cost FROM country_costs WHERE garment_type IN (SELECT garment_type FROM ethical_materials) ORDER BY production_cost ASC, production_cost DESC LIMIT 1; |
How many garments are made with recycled materials in total? | CREATE TABLE RecycledMaterialsTotal (id INT,garment_type VARCHAR(255),quantity INT); INSERT INTO RecycledMaterialsTotal (id,garment_type,quantity) VALUES (1,'T-Shirt',1500),(2,'Pants',2000),(3,'Dress',1200); | SELECT SUM(quantity) FROM RecycledMaterialsTotal; |
How many indigenous food producers are there in urban areas? | CREATE TABLE indigenous_food_producers (region VARCHAR(50),producer_type VARCHAR(50)); INSERT INTO indigenous_food_producers (region,producer_type) VALUES ('Rural','Non-indigenous'),('Urban','Indigenous'),('Urban','Non-indigenous'); | SELECT COUNT(*) FROM indigenous_food_producers WHERE region = 'Urban' AND producer_type = 'Indigenous'; |
Which co-owned properties have more than 2000 sqft in the Bronx? | CREATE TABLE co_ownership (co_ownership_id INT,property_id INT,owner_id INT); INSERT INTO co_ownership (co_ownership_id,property_id,owner_id) VALUES (1,1,101),(2,2,102),(3,3,103); | SELECT p.property_id, p.sqft FROM property p INNER JOIN co_ownership co ON p.property_id = co.property_id INNER JOIN borough b ON p.borough_id = b.borough_id WHERE b.name = 'Bronx' AND p.sqft > 2000; |
What is the average salary of male employees in the marketing department? | CREATE TABLE Employees (EmployeeID INT,Gender VARCHAR(10),Department VARCHAR(20),Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID,Gender,Department,Salary) VALUES (1,'Male','Marketing',75000.00),(2,'Female','Marketing',70000.00); | SELECT AVG(Salary) FROM Employees WHERE Gender = 'Male' AND Department = 'Marketing'; |
What is the percentage of cases won by the prosecution and the defense in each court location in the US? | CREATE TABLE case_outcomes (case_id INT,prosecution_win BOOLEAN,defense_win BOOLEAN,court_location VARCHAR(50)); INSERT INTO case_outcomes (case_id,prosecution_win,defense_win,court_location) VALUES (1,true,false,'Southern District of New York'),(2,false,true,'Central District of California'),(3,true,false,'Eastern District of Virginia'); | SELECT court_location, 100.0 * AVG(prosecution_win::INT) AS prosecution_win_percentage, 100.0 * AVG(defense_win::INT) AS defense_win_percentage FROM case_outcomes GROUP BY court_location; |
What is the average number of points scored per game by players from historically underrepresented communities in the last 5 seasons, for teams located in the Pacific Northwest region of the United States? | CREATE TABLE players (id INT,name TEXT,ethnicity TEXT,team_id INT,points INT,season INT); INSERT INTO players (id,name,ethnicity,team_id,points,season) VALUES (1,'Amy Lee','Asian',101,15,2018),(2,'Juan Lopez','Hispanic',102,20,2018),(3,'Sarah Johnson','African American',103,25,2018),(4,'Oliver Smith','Caucasian',101,10,2018); CREATE TABLE teams (id INT,name TEXT,location TEXT); INSERT INTO teams (id,name,location) VALUES (101,'Storm','Seattle'),(102,'Lakers','Los Angeles'),(103,'Blazers','Portland'); | SELECT AVG(points) FROM players JOIN teams ON players.team_id = teams.id WHERE ethnicity IN ('Asian', 'Hispanic', 'African American') AND location LIKE 'Pacific%' AND season >= 2017; |
What is the change in energy consumption per machine, per day, for the past week? | CREATE TABLE EnergyConsumption (Machine VARCHAR(50),Energy INT,Timestamp DATETIME); | SELECT Machine, LAG(Energy) OVER (PARTITION BY Machine ORDER BY Timestamp) - Energy AS EnergyChange FROM EnergyConsumption WHERE Timestamp >= DATEADD(day, -7, CURRENT_TIMESTAMP) |
What is the percentage of citizen feedback records received for public safety in Q3 2022? | CREATE TABLE FeedbackQ3 (Service TEXT,Quarter INT,Year INT,FeedbackCount INT); INSERT INTO FeedbackQ3 (Service,Quarter,Year,FeedbackCount) VALUES ('Public Safety',3,2022,800),('Transportation',3,2022,1000),('Healthcare',3,2022,1200); CREATE TABLE TotalFeedbackQ3 (Service TEXT,Quarter INT,Year INT,TotalCount INT); INSERT INTO TotalFeedbackQ3 (Service,Quarter,Year,TotalCount) VALUES ('Public Safety',3,2022,10000),('Transportation',3,2022,15000),('Healthcare',3,2022,20000); | SELECT Service, (SUM(FeedbackCount) * 100.0 / SUM(TotalCount)) AS Percentage FROM FeedbackQ3 INNER JOIN TotalFeedbackQ3 ON FeedbackQ3.Service = TotalFeedbackQ3.Service WHERE Quarter = 3 AND Year = 2022 AND Service = 'Public Safety' GROUP BY Service; |
What is the total number of tickets sold for TeamC's home games? | CREATE TABLE tickets (id INT,team VARCHAR(50),location VARCHAR(50),price DECIMAL(5,2),sold INT); INSERT INTO tickets (id,team,location,price,sold) VALUES (1,'TeamA','Home',100.00,500),(2,'TeamA','Away',75.00,400),(3,'TeamB','Home',120.00,600),(4,'TeamB','Away',80.00,300),(5,'TeamC','Home',150.00,800),(6,'TeamC','Away',100.00,700); | SELECT SUM(sold) FROM tickets WHERE team = 'TeamC' AND location = 'Home'; |
Identify the number of virtual tours taken in Indonesia, Argentina, and Russia. | CREATE TABLE virtual_tours (tour_id INT,country TEXT,participants INT); INSERT INTO virtual_tours (tour_id,country,participants) VALUES (1,'Indonesia',200),(2,'Argentina',300),(3,'Russia',100),(4,'Italy',50); | SELECT SUM(participants) FROM virtual_tours WHERE country IN ('Indonesia', 'Argentina', 'Russia'); |
What is the total number of mental health facilities with a health equity score above 85 in urban areas? | CREATE TABLE mental_health_facilities (facility_id INT,location VARCHAR(255),health_equity_score INT); INSERT INTO mental_health_facilities (facility_id,location,health_equity_score) VALUES (1,'Urban',85),(2,'Rural',75),(3,'Urban',90),(4,'Rural',80),(5,'Rural',78),(6,'Urban',95),(7,'Urban',88),(8,'Rural',72); | SELECT COUNT(*) as total FROM mental_health_facilities WHERE location = 'Urban' AND health_equity_score > 85; |
Find the average temperature of all ocean basins | CREATE TABLE ocean_basin (id INT,name VARCHAR(255),avg_temp FLOAT); | SELECT AVG(avg_temp) FROM ocean_basin; |
Create a table for storing customer feedback | CREATE TABLE dishes (dish_id INT,dish_name VARCHAR(255),cuisine VARCHAR(255)); INSERT INTO dishes (dish_id,dish_name,cuisine) VALUES (1,'Quinoa Salad','Mediterranean'),(2,'Chicken Caesar Wrap','Mediterranean'),(3,'Tacos','Mexican'); | CREATE TABLE feedback (feedback_id INT, dish_id INT, customer_id INT, rating INT, comment TEXT); |
What is the maximum salary for employees in the IT department who identify as non-binary or female? | CREATE TABLE Employees (EmployeeID INT,Department VARCHAR(20),GenderIdentity VARCHAR(20),Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID,Department,GenderIdentity,Salary) VALUES (1,'IT','Male',70000.00),(2,'IT','Female',75000.00),(3,'HR','Non-binary',60000.00),(4,'IT','Non-binary',70000.00); | SELECT MAX(Salary) FROM Employees WHERE Department = 'IT' AND GenderIdentity IN ('Non-binary', 'Female'); |
List all the distinct workouts and their average duration for members aged 40 or older, grouped by the workout type. | CREATE TABLE Members (MemberID INT,Age INT,Gender VARCHAR(10)); INSERT INTO Members (MemberID,Age,Gender) VALUES (3,45,'Male'); CREATE TABLE Workouts (WorkoutID INT,WorkoutType VARCHAR(20),Duration INT,MemberID INT); INSERT INTO Workouts (WorkoutID,WorkoutType,Duration,MemberID) VALUES (30,'Yoga',60,3); | SELECT Workouts.WorkoutType, AVG(Workouts.Duration) FROM Members INNER JOIN Workouts ON Members.MemberID = Workouts.MemberID WHERE Members.Age >= 40 GROUP BY Workouts.WorkoutType; |
List all wastewater treatment facilities in India that were built after 2000. | CREATE TABLE facilities(name VARCHAR(50),country VARCHAR(50),build_year INT); INSERT INTO facilities(name,country,build_year) VALUES ('Facility1','India',2005),('Facility2','India',2002),('Facility3','India',2008); | SELECT name FROM facilities WHERE country = 'India' AND build_year > 2000; |
Delete records of mineral extraction that occurred before a certain date. | CREATE TABLE ExtractionData (ExtractionDataID INT,MineID INT,Date DATE,Mineral TEXT,Quantity INT); | DELETE FROM ExtractionData WHERE Date < '2020-01-01'; |
What is the total revenue for a given restaurant on each day of the week? | CREATE TABLE sales (sale_id INT,restaurant_id INT,sale_date DATE,revenue INT); INSERT INTO sales (sale_id,restaurant_id,sale_date,revenue) VALUES (1,1,'2022-01-01',1000),(2,1,'2022-01-02',1200),(3,2,'2022-01-01',1500),(4,2,'2022-01-02',1800); | SELECT restaurant_id, DATE_TRUNC('week', sale_date) AS week_start, SUM(revenue) FROM sales GROUP BY restaurant_id, week_start; |
Find the average playtime of adventure games that have cross-platform support, grouped by player's country of residence. | CREATE TABLE Players (PlayerID INT,Name VARCHAR(100),Country VARCHAR(50),TotalHoursPlayed INT); INSERT INTO Players VALUES (1,'Alex Garcia','Mexico',60); INSERT INTO Players VALUES (2,'Sophia Lee','South Korea',80); CREATE TABLE GameDesign (GameID INT,GameName VARCHAR(100),Genre VARCHAR(50),CrossPlatform BIT); INSERT INTO GameDesign VALUES (1,'GameX','Adventure',1); INSERT INTO GameDesign VALUES (2,'GameY','Puzzle',0); | SELECT P.Country, AVG(P.TotalHoursPlayed) as AvgPlaytime FROM Players P JOIN GameDesign GD ON P.PlayerID = GD.GameID WHERE GD.Genre = 'Adventure' AND GD.CrossPlatform = 1 GROUP BY P.Country; |
What are the average sale prices for military equipment in the Middle East and Africa? | CREATE TABLE MilitaryEquipmentPrices (id INT,region VARCHAR(255),product VARCHAR(255),sale_price DECIMAL(10,2)); INSERT INTO MilitaryEquipmentPrices (id,region,product,sale_price) VALUES (1,'Middle East','Tank',10000000.00),(2,'Africa','Fighter Jet',25000000.00); | SELECT AVG(sale_price) FROM MilitaryEquipmentPrices WHERE region IN ('Middle East', 'Africa'); |
Which vessels have traveled to the Arctic and carried more than 5000 tons of cargo? | CREATE TABLE vessels (id INT,name VARCHAR(50),type VARCHAR(50),max_cargo_weight INT); INSERT INTO vessels (id,name,type,max_cargo_weight) VALUES (1,'VesselA','Cargo',10000),(2,'VesselB','Tanker',8000),(3,'VesselC','Passenger',0); CREATE TABLE voyages (id INT,vessel_id INT,region VARCHAR(50),distance DECIMAL(5,2),cargo_weight INT); INSERT INTO voyages (id,vessel_id,region,distance,cargo_weight) VALUES (1,1,'Arctic',700,8000),(2,1,'Atlantic',500,7000),(3,2,'Arctic',600,6000),(4,3,'Pacific',800,0); | SELECT v.name FROM vessels v INNER JOIN voyages voy ON v.id = voy.vessel_id WHERE region = 'Arctic' AND cargo_weight > 5000; |
Update the gender of the founder with id 1001 from male to non-binary in the "company_founding_data" table | CREATE TABLE company_founding_data (id INT PRIMARY KEY,company_id INT,founder_id INT,founder_name VARCHAR(50),founder_gender VARCHAR(10)); INSERT INTO company_founding_data (id,company_id,founder_id,founder_name,founder_gender) VALUES (1,1001,1,'John Doe','male'),(2,1002,2,'Jane Smith','female'),(3,1003,3,'Alice Johnson','female'); | UPDATE company_founding_data SET founder_gender = 'non-binary' WHERE founder_id = 1; |
Calculate the average salary of male and female members of the 'LaborUnionABC' | CREATE TABLE LaborUnionABC (id INT,gender VARCHAR(10),salary FLOAT); INSERT INTO LaborUnionABC (id,gender,salary) VALUES (1,'Male',50000.0),(2,'Female',55000.0),(3,'Male',52000.0); | SELECT AVG(salary) as avg_salary, gender FROM LaborUnionABC GROUP BY gender; |
What was the average supply quantity for each type of supply in 2020? | CREATE TABLE Supplies (id INT,name VARCHAR(50),quantity INT,supply_date DATE); INSERT INTO Supplies (id,name,quantity,supply_date) VALUES (1,'Food',100,'2020-01-01'),(2,'Medicine',50,'2020-02-01'); | SELECT s.name, AVG(s.quantity) as avg_quantity FROM Supplies s WHERE s.supply_date >= '2020-01-01' AND s.supply_date <= '2020-12-31' GROUP BY s.name; |
What is the average number of hospital beds per facility in urban areas, ordered by the highest average? | CREATE TABLE hospitals (id INT,name TEXT,beds INT,location TEXT); INSERT INTO hospitals (id,name,beds,location) VALUES (1,'Hospital A',300,'urban'),(2,'Hospital B',500,'urban'),(3,'Hospital C',200,'rural'); | SELECT AVG(beds) FROM hospitals WHERE location = 'urban' GROUP BY location ORDER BY AVG(beds) DESC; |
What is the maximum salary for employees in the company? | CREATE TABLE Employees (EmployeeID INT,Gender VARCHAR(10),Department VARCHAR(20),Salary FLOAT); INSERT INTO Employees (EmployeeID,Gender,Department,Salary) VALUES (1,'Male','IT',75000),(2,'Female','IT',70000),(3,'Non-binary','HR',65000),(4,'Male','HR',70000); | SELECT MAX(Salary) FROM Employees; |
What is the maximum investment made by a customer in the eastern region in the technology sector? | CREATE TABLE customer_data (customer_id INT,name VARCHAR(20),region VARCHAR(10)); INSERT INTO customer_data (customer_id,name,region) VALUES (1,'John Doe','east'),(2,'Jane Smith','south'),(3,'Mary Johnson','east'); CREATE TABLE investment_data (customer_id INT,sector VARCHAR(20),investment FLOAT); INSERT INTO investment_data (customer_id,sector,investment) VALUES (1,'technology',5000),(2,'technology',6000),(3,'technology',7000); | SELECT MAX(investment) FROM investment_data INNER JOIN customer_data ON investment_data.customer_id = customer_data.customer_id WHERE customer_data.region = 'east' AND sector = 'technology'; |
What is the lowest rated eco-friendly hotel in Argentina? | CREATE TABLE eco_hotels_arg (hotel_id INT,hotel_name VARCHAR(255),country VARCHAR(255),rating DECIMAL(2,1)); INSERT INTO eco_hotels_arg (hotel_id,hotel_name,country,rating) VALUES (1,'Eco Hotel Buenos Aires','Argentina',3.5); INSERT INTO eco_hotels_arg (hotel_id,hotel_name,country,rating) VALUES (2,'Green Hotel Cordoba','Argentina',4.0); INSERT INTO eco_hotels_arg (hotel_id,hotel_name,country,rating) VALUES (3,'Eco Hotel Mendoza','Argentina',3.8); | SELECT hotel_name, MIN(rating) FROM eco_hotels_arg WHERE country = 'Argentina'; |
What is the total revenue for each genre of music in the 'digital_sales' table, joined with the 'genre' table? | CREATE TABLE genre (genre_id INT,genre_name VARCHAR(255)); CREATE TABLE digital_sales (sale_id INT,song_id INT,genre_id INT,sales_revenue DECIMAL(10,2)); | SELECT g.genre_name, SUM(ds.sales_revenue) AS total_revenue FROM genre g INNER JOIN digital_sales ds ON g.genre_id = ds.genre_id GROUP BY g.genre_name; |
Find the total number of marine species in the 'species_info' table that belong to the 'Mammalia' class. | CREATE TABLE species_info (species_id INT,species_name VARCHAR(50),scientific_name VARCHAR(50),class VARCHAR(20)); | SELECT COUNT(*) FROM species_info WHERE class = 'Mammalia'; |
Update the 'wastewater_treatment' table to reflect a 10% increase in the 'treatment_efficiency' for the 'Northeast' region | CREATE TABLE wastewater_treatment (id INT PRIMARY KEY,region VARCHAR(20),treatment_efficiency DECIMAL(5,2)); | UPDATE wastewater_treatment SET treatment_efficiency = treatment_efficiency * 1.1 WHERE region = 'Northeast'; |
What are the names and games of players who have a higher score than the average score in game C? | CREATE TABLE Players (PlayerID INT,Name VARCHAR(50),Game VARCHAR(50),Score INT); INSERT INTO Players (PlayerID,Name,Game,Score) VALUES (1,'John Doe','GameA',1000); INSERT INTO Players (PlayerID,Name,Game,Score) VALUES (2,'Jane Doe','GameB',2000); INSERT INTO Players (PlayerID,Name,Game,Score) VALUES (3,'Alice','GameC',1500); INSERT INTO Players (PlayerID,Name,Game,Score) VALUES (4,'Bob','GameC',1200); | SELECT Name, Game FROM Players WHERE Game = 'GameC' AND Score > (SELECT AVG(Score) FROM Players WHERE Game = 'GameC'); |
Create a view named "sustainable_hotels" that displays the hotel name, location, and sustainable practices for all hotels in the "hotel_sustainability" table | CREATE TABLE hotel_sustainability (hotel_id integer,name text,location text,sustainable_practices text); | CREATE VIEW sustainable_hotels AS SELECT name, location, sustainable_practices FROM hotel_sustainability; |
Who are the faculty members with no publications in the 'Physics' department? | CREATE TABLE departments (id INT,name TEXT,budget INT); INSERT INTO departments (id,name,budget) VALUES (1,'Computer Science',1000000),(2,'Physics',800000); CREATE TABLE faculty (id INT,name TEXT,department TEXT,publications INT); INSERT INTO faculty (id,name,department,publications) VALUES (1,'John Doe','Computer Science',2),(2,'Jane Smith','Physics',5),(3,'Alice Johnson','Physics',0); | SELECT f.name FROM faculty f RIGHT JOIN departments d ON f.department = d.name WHERE d.name = 'Physics' AND f.publications = 0; |
Find the names and regulatory statuses of smart contracts related to DeFi in the EU. | CREATE TABLE smart_contracts (id INT,name TEXT,category TEXT,regulatory_status TEXT); INSERT INTO smart_contracts (id,name,category,regulatory_status) VALUES (1,'Contract1','DeFi','Compliant'); | SELECT name, regulatory_status FROM smart_contracts WHERE category = 'DeFi' AND country = 'EU'; |
How many indigenous languages are endangered in 'Pacific Islands'? | CREATE TABLE IndigenousLanguages (LanguageID INT PRIMARY KEY,LanguageName VARCHAR(50),Status VARCHAR(50),Location VARCHAR(50)); INSERT INTO IndigenousLanguages (LanguageID,LanguageName,Status,Location) VALUES (1,'Rapa Nui','Endangered','Easter Island'),(2,'Palauan','Vulnerable','Palau'); | SELECT COUNT(*) FROM IndigenousLanguages WHERE Location LIKE '%Pacific Islands%' AND Status = 'Endangered'; |
How many volunteers have there been in total from the 'technology' sector? | CREATE TABLE volunteers (volunteer_id INT,sector TEXT,total_hours FLOAT); INSERT INTO volunteers (volunteer_id,sector,total_hours) VALUES (1,'technology',100.00),(2,'finance',200.00); | SELECT COUNT(*) FROM volunteers WHERE sector = 'technology'; |
Which offenders were released early due to overcrowding in California prisons in 2020? | CREATE TABLE offenders (offender_id INT,release_date DATE,release_reason VARCHAR(255)); INSERT INTO offenders (offender_id,release_date,release_reason) VALUES (1,'2020-03-15','overcrowding'); | SELECT offender_id, release_date FROM offenders WHERE release_reason = 'overcrowding' AND YEAR(release_date) = 2020 |
Find the total revenue for each product category in the 'product_sales' table, considering transactions from the current month? | CREATE TABLE product_sales (product_category VARCHAR(255),sale_date DATE,revenue DECIMAL(5,2)); | SELECT product_category, SUM(revenue) FROM product_sales WHERE MONTH(sale_date) = MONTH(CURDATE()) AND YEAR(sale_date) = YEAR(CURDATE()) GROUP BY product_category; |
How many vegetarian dishes are offered by organic vendors? | CREATE TABLE VendorCategory (VendorID INT,VendorCategory VARCHAR(50)); INSERT INTO VendorCategory (VendorID,VendorCategory) VALUES (1,'Organic'),(2,'Local'); CREATE TABLE MenuItems (MenuItemID INT,VendorID INT,MenuItemName VARCHAR(50),MenuItemType VARCHAR(50)); INSERT INTO MenuItems (MenuItemID,VendorID,MenuItemName,MenuItemType) VALUES (1,1,'Quinoa Salad','Vegetarian'),(2,1,'Chicken Wrap','Not Vegetarian'),(3,2,'Seasonal Vegetables','Vegetarian'); | SELECT COUNT(*) FROM MenuItems WHERE VendorID IN (SELECT VendorID FROM VendorCategory WHERE VendorCategory = 'Organic') AND MenuItemType = 'Vegetarian'; |
Delete spacecraft records with mass greater than 10000 kg? | CREATE TABLE SpacecraftManufacturing (ID INT,Manufacturer VARCHAR(255),Mass INT); INSERT INTO SpacecraftManufacturing (ID,Manufacturer,Mass) VALUES (1,'SpaceCorp',5000),(2,'SpaceCorp',15000); | DELETE FROM SpacecraftManufacturing WHERE Mass > 10000; |
What is the minimum project timeline for construction projects in France that were completed in the last year? | CREATE TABLE Project_Timelines (id INT,project_id TEXT,start_date DATE,end_date DATE,timeline_months INT,country TEXT); | SELECT MIN(timeline_months) FROM Project_Timelines WHERE end_date IS NOT NULL AND country = 'France' AND end_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR); |
Find the top 3 unsafe AI algorithms by their total number of incidents | CREATE TABLE unsafe_ai_algorithms (ai_algorithm VARCHAR(255),incidents INT); INSERT INTO unsafe_ai_algorithms (ai_algorithm,incidents) VALUES ('Algorithm A',50),('Algorithm B',75),('Algorithm C',100),('Algorithm D',125); | SELECT ai_algorithm, SUM(incidents) AS total_incidents FROM unsafe_ai_algorithms GROUP BY ai_algorithm ORDER BY total_incidents DESC LIMIT 3; |
What cities have a high crime rate and low disaster preparedness? | CREATE TABLE CrimeStatistics (id INT PRIMARY KEY,city VARCHAR(255),crime_rate FLOAT); CREATE VIEW HighCrimeCities AS SELECT city,crime_rate FROM CrimeStatistics WHERE crime_rate > (SELECT AVG(crime_rate) FROM CrimeStatistics); | SELECT hcc.city, hcc.crime_rate, dp.preparedness FROM HighCrimeCities hcc JOIN DisasterPreparedness dp ON hcc.city = dp.city WHERE dp.preparedness < 50; |
Find the maximum and minimum number of funding rounds for companies in the renewable energy sector. | CREATE TABLE funding_rounds (id INT,company_id INT,round_number INT,funding_date DATE); CREATE TABLE companies (id INT,name TEXT,industry TEXT,founding_date DATE); | SELECT MAX(round_number), MIN(round_number) FROM funding_rounds JOIN companies ON funding_rounds.company_id = companies.id WHERE companies.industry = 'Renewable Energy'; |
What is the average number of cybersecurity trainings conducted in the 'Americas' region this year? | CREATE TABLE trainings (region TEXT,training_date DATE); INSERT INTO trainings (region,training_date) VALUES ('Europe','2023-01-01'); INSERT INTO trainings (region,training_date) VALUES ('Americas','2023-02-01'); | SELECT AVG(training_count) FROM (SELECT COUNT(*) AS training_count FROM trainings WHERE region = 'Americas' AND EXTRACT(YEAR FROM training_date) = EXTRACT(YEAR FROM CURRENT_DATE) GROUP BY region) subquery; |
What are the details of the most recent vulnerability found in the government sector? | CREATE TABLE vulnerabilities (id INT,sector VARCHAR(20),description TEXT,date DATE); INSERT INTO vulnerabilities (id,sector,description,date) VALUES (1,'government','Cross-site scripting vulnerability','2022-04-15'); (2,'government','Buffer overflow vulnerability','2022-05-01'); | SELECT * FROM vulnerabilities WHERE sector = 'government' ORDER BY date DESC LIMIT 1; |
What 'applications' are present in the 'app_database' table? | CREATE TABLE app_database (id INT,name TEXT,application_type TEXT); INSERT INTO app_database (id,name,application_type) VALUES (1,'appA','creative'),(2,'appB','safety'),(3,'appC','fairness'); | SELECT DISTINCT application_type FROM app_database; |
Find the number of unique donors from each continent. | CREATE TABLE donors (id INT,name VARCHAR(100),continent VARCHAR(50)); INSERT INTO donors (id,name,continent) VALUES (1,'John Doe','North America'),(2,'Jane Smith','Europe'),(3,'Pedro Rodriguez','South America'); | SELECT continent, COUNT(DISTINCT name) FROM donors GROUP BY continent; |
How many autonomous buses are there in the Tokyo public transportation system? | CREATE TABLE buses (bus_id INT,is_autonomous BOOLEAN,city VARCHAR(20)); INSERT INTO buses (bus_id,is_autonomous,city) VALUES (1,true,'Tokyo'),(2,false,'Tokyo'),(3,true,'Tokyo'); | SELECT COUNT(*) FROM buses WHERE is_autonomous = true AND city = 'Tokyo'; |
What are the accommodations that are most commonly granted to each student, and how many times are they granted? | CREATE TABLE accommodations (id INT,student_id INT,accommodation_type VARCHAR(255),accommodation_date DATE); INSERT INTO accommodations (id,student_id,accommodation_type,accommodation_date) VALUES (7,5,'Wheelchair','2022-02-02'),(8,6,'Sign language interpreter','2022-03-02'),(9,5,'Wheelchair','2022-02-03'); | SELECT s.name, a.accommodation_type, COUNT(*) as count FROM students s JOIN accommodations a ON s.id = a.student_id GROUP BY s.name, a.accommodation_type HAVING COUNT(*) > 1 ORDER BY count DESC; |
List public transportation systems that have increased their ridership by over 10% since 2019 | CREATE TABLE public_transportation (system_id INT,system_name VARCHAR(255),ridership INT,year INT); | SELECT system_name, ridership, year FROM public_transportation WHERE year > 2019 AND ridership > 1.1 * (SELECT ridership FROM public_transportation WHERE system_id = system_id AND year = 2019); |
How many unique donors are there for each cause, sorted by the number of donors in descending order? | CREATE TABLE donors (id INT,name TEXT,country TEXT); INSERT INTO donors (id,name,country) VALUES (1,'Donor1','USA'),(2,'Donor2','Canada'),(3,'Donor3','USA'),(4,'Donor4','Mexico'),(5,'Donor5','Canada'); CREATE TABLE donations (id INT,donor_id INT,cause TEXT,amount FLOAT); INSERT INTO donations (id,donor_id,cause,amount) VALUES (1,1,'Education',1000.00),(2,1,'Health',2000.00),(3,2,'Education',1500.00),(4,2,'Environment',2500.00),(5,3,'Education',500.00),(6,4,'Health',3000.00),(7,5,'Education',2000.00),(8,5,'Environment',1000.00); | SELECT d.cause, COUNT(DISTINCT don.id) as num_donors FROM donations d JOIN donors don ON d.donor_id = don.id GROUP BY d.cause ORDER BY num_donors DESC; |
What are the names and total square footage of all commercial buildings that have a platinum LEED certification? | CREATE TABLE Buildings (BuildingID int,Name varchar(50),Type varchar(20),SquareFootage int,LEEDCertification varchar(20)); INSERT INTO Buildings (BuildingID,Name,Type,SquareFootage,LEEDCertification) VALUES (1,'Green Tower','Commercial',500000,'Platinum'); INSERT INTO Buildings (BuildingID,Name,Type,SquareFootage,LEEDCertification) VALUES (2,'Eco Building','Commercial',300000,'Gold'); | SELECT Name, SquareFootage FROM Buildings WHERE Type = 'Commercial' AND LEEDCertification = 'Platinum'; |
How many renewable energy projects were completed in India in the last 5 years? | CREATE TABLE renewable_energy_projects (id INT,country VARCHAR(255),year INT,completed BOOLEAN); INSERT INTO renewable_energy_projects (id,country,year,completed) VALUES (1,'India',2021,true),(2,'India',2019,true),(3,'India',2020,true),(4,'India',2018,true),(5,'India',2017,true),(6,'India',2016,true); | SELECT COUNT(*) FROM renewable_energy_projects WHERE country = 'India' AND year >= (SELECT YEAR(CURRENT_DATE()) - 5); |
What is the total donation amount per year, per donor, in descending order of the total donation amount? | CREATE TABLE Donations (DonationID int,DonorID int,DonationAmount decimal(10,2),DonationDate date); INSERT INTO Donations (DonationID,DonorID,DonationAmount,DonationDate) VALUES (1,1,500.00,'2022-01-01'),(2,1,800.00,'2022-02-01'),(3,2,300.00,'2022-01-01'),(4,3,700.00,'2022-01-01'); | SELECT DonorID, DATE_TRUNC('year', DonationDate) AS Year, SUM(DonationAmount) OVER (PARTITION BY DATE_TRUNC('year', DonationDate), DonorID) AS TotalDonationPerYear FROM Donations GROUP BY DonorID, Year ORDER BY TotalDonationPerYear DESC; |
List the geopolitical risk assessments for the Asia-Pacific region in Q2 2022, ordered by risk level. | CREATE TABLE risk_assessments (id INT,region VARCHAR,assessment_date DATE,risk_level INT); INSERT INTO risk_assessments (id,region,assessment_date,risk_level) VALUES (1,'Asia-Pacific','2022-04-22',6); INSERT INTO risk_assessments (id,region,assessment_date,risk_level) VALUES (2,'Asia-Pacific','2022-05-10',4); INSERT INTO risk_assessments (id,region,assessment_date,risk_level) VALUES (3,'Asia-Pacific','2022-04-03',7); | SELECT region, risk_level FROM risk_assessments WHERE region = 'Asia-Pacific' AND assessment_date BETWEEN '2022-04-01' AND '2022-06-30' ORDER BY risk_level; |
What is the total CO2 emissions of the natural fabric production? | CREATE TABLE emissions (fabric VARCHAR(255),co2_emissions DECIMAL(10,2)); INSERT INTO emissions (fabric,co2_emissions) VALUES ('cotton',4.00),('linen',2.50),('hemp',1.50); | SELECT SUM(co2_emissions) FROM emissions WHERE fabric IN ('cotton', 'linen', 'hemp'); |
What is the average word count of articles in the 'opinion' category from the "articles" table? | CREATE TABLE articles (id INT PRIMARY KEY,title TEXT,category TEXT,publication_date DATE,word_count INT,author_id INT); | SELECT AVG(word_count) FROM articles WHERE category = 'opinion'; |
What is the average bioprocess engineering project cost per country, ordered by total cost? | CREATE SCHEMA if not exists bioprocess;CREATE TABLE if not exists bioprocess.projects (id INT PRIMARY KEY,country VARCHAR(50),name VARCHAR(255),cost DECIMAL(10,2)); INSERT INTO bioprocess.projects (id,country,name,cost) VALUES (1,'USA','ProjectA',50000.00),(2,'Canada','ProjectB',75000.00),(3,'Mexico','ProjectC',35000.00),(4,'USA','ProjectD',80000.00); | SELECT country, AVG(cost) AS avg_cost FROM bioprocess.projects GROUP BY country ORDER BY avg_cost DESC; |
What is the number of hybrid vehicles sold in '2019' in the 'sales' table? | CREATE TABLE sales (year INT,vehicle_type VARCHAR(10),vehicle_count INT); INSERT INTO sales VALUES (2018,'electric',1000),(2019,'electric',2000),(2020,'electric',3000),(2019,'gasoline',4000),(2019,'hybrid',500),(2020,'hybrid',700); | SELECT SUM(vehicle_count) FROM sales WHERE vehicle_type = 'hybrid' AND year = 2019; |
What is the earliest performance date at the "Royal Opera House"? | CREATE TABLE OperaPerformances (TheatreName TEXT,PerformanceDate DATE); INSERT INTO OperaPerformances (TheatreName,PerformanceDate) VALUES ('Royal Opera House','2021-11-01'),('Royal Opera House','2021-12-15'),('Royal Opera House','2022-01-20'); | SELECT MIN(PerformanceDate) FROM OperaPerformances WHERE TheatreName = 'Royal Opera House'; |
Update environmental_impact table to set 'co2_emissions' to 1200 for 'site_id' 008 | CREATE TABLE environmental_impact (site_id VARCHAR(10) PRIMARY KEY,co2_emissions INT,water_usage DECIMAL(5,2)); | UPDATE environmental_impact SET co2_emissions = 1200 WHERE site_id = '008'; |
Delete records in the vessel_performance table where the measurement_value is less than 50 and the measurement_date is within the last month | CREATE TABLE vessel_performance (vessel_name VARCHAR(255),measurement_date DATE,measurement_value INT); | DELETE FROM vessel_performance WHERE measurement_value < 50 AND measurement_date > DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH); |
Which space agencies have collaborated with the most countries on space missions? | CREATE TABLE space_missions (id INT,mission_name VARCHAR(50),partner_country VARCHAR(50),year INT); INSERT INTO space_missions (id,mission_name,partner_country,year) VALUES (1,'Apollo','Germany',1969),(2,'Mir','Russia',1986),(3,'Shenzhou','China',2003),(4,'Artemis','Canada',2024),(5,'Gaganyaan','Russia',2022),(6,'Shijian','Brazil',2021); | SELECT partner_country, COUNT(DISTINCT mission_name) as mission_count FROM space_missions GROUP BY partner_country ORDER BY mission_count DESC; |
What are the total number of transactions for each decentralized application in 'Q3 2022'? | CREATE TABLE decentralized_apps (id INT,name TEXT,transactions INT); INSERT INTO decentralized_apps (id,name,transactions) VALUES (1,'App1',10),(2,'App2',20),(3,'App3',30); CREATE TABLE dates (date DATE,quarter TEXT,year INT); INSERT INTO dates (date,quarter,year) VALUES ('2022-07-01','Q3',2022),('2022-10-01','Q4',2022); | SELECT decentralized_apps.name, SUM(decentralized_apps.transactions) AS total_transactions FROM decentralized_apps INNER JOIN dates ON decentralized_apps.id = dates.date WHERE dates.quarter = 'Q3' AND dates.year = 2022 GROUP BY decentralized_apps.name; |
Display the names and ratings of all mutual funds that have been rated by exactly two rating agencies. | CREATE TABLE mutual_funds (fund_id INT,fund_name VARCHAR(50),agency_1_rating DECIMAL(3,1),agency_2_rating DECIMAL(3,1),agency_3_rating DECIMAL(3,1)); INSERT INTO mutual_funds (fund_id,fund_name,agency_1_rating,agency_2_rating,agency_3_rating) VALUES (1,'Fund A',4.5,4.2,4.0),(2,'Fund B',3.8,3.9,3.6),(3,'Fund C',4.7,4.6,NULL); | SELECT fund_name, agency_1_rating, agency_2_rating FROM mutual_funds WHERE agency_1_rating IS NOT NULL AND agency_3_rating IS NULL GROUP BY fund_name HAVING COUNT(*) = 2; |
What is the total number of volunteers in each program in each month? | CREATE TABLE Volunteers (VolunteerID INT,VolunteerName TEXT,ProgramID INT,VolunteerDate DATE); INSERT INTO Volunteers (VolunteerID,VolunteerName,ProgramID,VolunteerDate) VALUES (1,'John Doe',1,'2022-01-01'),(2,'Jane Smith',2,'2022-01-15'),(3,'Alice Johnson',2,'2022-02-01'),(4,'Bob Brown',3,'2022-02-15'),(5,'Charlie Davis',1,'2022-02-01'); | SELECT ProgramID, EXTRACT(MONTH FROM VolunteerDate) AS Month, COUNT(VolunteerID) OVER (PARTITION BY ProgramID, EXTRACT(MONTH FROM VolunteerDate) ORDER BY ProgramID, EXTRACT(MONTH FROM VolunteerDate)) AS VolunteerCount FROM Volunteers; |
Delete regulatory frameworks before 2022 from the 'regulatory_frameworks' table | CREATE TABLE regulatory_frameworks (framework_id INT PRIMARY KEY,name VARCHAR(255),description TEXT,country VARCHAR(255),enforcement_date DATE); | DELETE FROM regulatory_frameworks WHERE enforcement_date < '2022-01-01'; |
What is the average survival rate of salmon by ocean and year, considering only fish born in the second quarter? | CREATE TABLE Ocean (OceanID INT,OceanName TEXT); CREATE TABLE Fish (FishID INT,OceanID INT,BirthDate DATE,SurvivalRate DECIMAL); INSERT INTO Ocean VALUES (1,'Atlantic'); INSERT INTO Ocean VALUES (2,'Pacific'); INSERT INTO Fish VALUES (1,1,'2020-04-01',0.85); INSERT INTO Fish VALUES (2,1,'2020-04-01',0.90); INSERT INTO Fish VALUES (3,2,'2019-04-01',0.75); | SELECT OceanName, EXTRACT(YEAR FROM BirthDate) AS Year, AVG(SurvivalRate) AS AvgSurvivalRate FROM Ocean INNER JOIN Fish ON Ocean.OceanID = Fish.OceanID WHERE EXTRACT(MONTH FROM BirthDate) BETWEEN 4 AND 6 GROUP BY OceanName, Year; |
What is the average duration of songs per artist, based on the 'digital_sales' table, joined with the 'song' and 'artist' tables? | CREATE TABLE artist (artist_id INT,artist_name VARCHAR(255)); CREATE TABLE song (song_id INT,song_name VARCHAR(255),artist_id INT,duration_id INT); CREATE TABLE duration (duration_id INT,duration_seconds INT); CREATE TABLE digital_sales (sale_id INT,song_id INT,sales_revenue DECIMAL(10,2)); | SELECT a.artist_name, AVG(d.duration_seconds) AS avg_duration FROM artist a INNER JOIN song s ON a.artist_id = s.artist_id INNER JOIN duration d ON s.duration_id = d.duration_id GROUP BY a.artist_name; |
What is the total number of accidents in the 'environmental_impact' table by incident type? | CREATE TABLE environmental_impact (id INT,incident_date DATE,incident_type VARCHAR(50),description TEXT,quantity INT); | SELECT incident_type, SUM(quantity) FROM environmental_impact WHERE incident_type IN ('accident', 'incident') GROUP BY incident_type; |
What was the number of humanitarian assistance missions performed by the UN in 2018? | CREATE TABLE humanitarian_assistance (agency VARCHAR(255),year INT,missions INT); INSERT INTO humanitarian_assistance (agency,year,missions) VALUES ('United Nations',2018,120); | SELECT missions FROM humanitarian_assistance WHERE agency = 'United Nations' AND year = 2018; |
What is the maximum number of reviews for eco-friendly hotels in India? | CREATE TABLE eco_hotels (hotel_id INT,hotel_name TEXT,reviews INT,country TEXT); INSERT INTO eco_hotels (hotel_id,hotel_name,reviews,country) VALUES (1,'Eco Lodge Jaipur',100,'India'),(2,'Green Hotel New Delhi',150,'India'); | SELECT MAX(reviews) FROM eco_hotels WHERE country = 'India'; |
Delete community development initiatives that were completed before 2018 in the 'community_development_completion_dates' table. | CREATE TABLE community_development_completion_dates (id INT,initiative_name VARCHAR(50),completion_date DATE); INSERT INTO community_development_completion_dates (id,initiative_name,completion_date) VALUES (1,'Waste Management','2017-05-01'),(2,'Library','2019-12-31'); | DELETE FROM community_development_completion_dates WHERE completion_date < '2018-01-01'; |
What percentage of cosmetic products sourced from Mexico are certified organic? | CREATE TABLE ingredients (product_id INT,ingredient TEXT); INSERT INTO ingredients (product_id,ingredient) VALUES (1,'paraben'),(2,'alcohol'),(3,'water'),(4,'paraben'),(5,'lavender'),(6,'paraben'),(7,'jojoba'),(8,'chamomile'),(9,'beeswax'),(10,'carmine'),(11,'coconut'),(12,'shea butter'); CREATE TABLE products (product_id INT,product_name TEXT,country TEXT,certified TEXT); INSERT INTO products (product_id,product_name,country,certified) VALUES (1,'Lipstick A','USA','organic'),(2,'Eye Shadow B','Canada','vegan'),(3,'Mascara C','France','organic'),(4,'Foundation D','USA','cruelty-free'),(5,'Blush E','Mexico','organic'),(6,'Moisturizer F','France','paraben-free'),(7,'Cleanser G','Mexico','organic'),(8,'Toner H','Japan','paraben-free'),(9,'Lip Balm I','USA','cruelty-free'),(10,'Nail Polish J','Italy','paraben-free'),(11,'Lotion K','Mexico','organic'),(12,'Serum L','Germany','cruelty-free'); | SELECT 100.0 * COUNT(p.product_id) / (SELECT COUNT(*) FROM products WHERE country = 'Mexico') AS organic_percentage FROM products p WHERE p.certified = 'organic' AND p.country = 'Mexico'; |
Insert a new drug 'DrugB' into the 'drug_approval' table. | CREATE TABLE drug_approval (drug_id INT,drug_name VARCHAR(255),approval_date DATE,manufacturer VARCHAR(255)); | INSERT INTO drug_approval (drug_id, drug_name, approval_date, manufacturer) VALUES (2, 'DrugB', CURDATE(), 'ManufacturerB'); |
Delete farmers from 'Europe' growing 'Potatoes'? | CREATE TABLE crops (id INT PRIMARY KEY,name VARCHAR(50),yield INT,country VARCHAR(50)); INSERT INTO crops (id,name,yield,country) VALUES (1,'Rice',7500,'China'),(2,'Potatoes',1800,'Germany'),(3,'Wheat',2600,'India'); CREATE TABLE farmers (id INT PRIMARY KEY,name VARCHAR(50),location VARCHAR(50),crops VARCHAR(50)); INSERT INTO farmers (id,name,location,crops) VALUES (1,'John Doe','USA','Corn,Soybeans'),(2,'Max Müller','Germany','Potatoes'),(3,'Kim Lee','South Korea','Barley'); | DELETE FROM farmers WHERE location = 'Europe' AND crops = 'Potatoes'; |
Find the number of wildlife species observed in each forest and the year of the most recent observation for that forest. | CREATE TABLE wildlife (id INT,forest VARCHAR(50),year INT,species VARCHAR(50)); INSERT INTO wildlife (id,forest,year,species) VALUES (1,'Forest A',2018,'Deer'),(2,'Forest A',2020,'Bear'),(3,'Forest B',2019,'Rabbit'),(4,'Forest B',2021,'Fox'); | SELECT forest, COUNT(DISTINCT species) AS num_species, MAX(year) AS latest_year FROM wildlife GROUP BY forest; |
Find the number of volunteers who participated in the "Environment" program in each quarter of 2019, ranked by quarter. | CREATE TABLE Volunteers (id INT,volunteer VARCHAR(50),program VARCHAR(50),volunteer_date DATE); INSERT INTO Volunteers (id,volunteer,program,volunteer_date) VALUES (1,'Jane Doe','Environment','2019-01-01'); | SELECT QUARTER(volunteer_date) AS Quarter, COUNT(volunteer) AS Volunteer_Count FROM Volunteers WHERE program = 'Environment' AND YEAR(volunteer_date) = 2019 GROUP BY Quarter ORDER BY Quarter; |
List the number of mobile and broadband subscribers in each country, grouped by region and type, with a cross join. | CREATE TABLE subscribers(id INT,subscription_type VARCHAR(10),region VARCHAR(10),country VARCHAR(10)); INSERT INTO subscribers VALUES (1,'mobile','South','USA'); INSERT INTO subscribers VALUES (2,'broadband','South','Mexico'); INSERT INTO subscribers VALUES (3,'mobile','East','China'); | SELECT region, country, subscription_type, COUNT(*) as total_subscribers FROM subscribers GROUP BY region, country, subscription_type; |
Delete records in the ProductionData table for Well ID 601 and ProductionDate '2022-01-01'. | CREATE TABLE ProductionData (WellID int,ProductionDate date,BarrelsPerDay int); INSERT INTO ProductionData (WellID,ProductionDate,BarrelsPerDay) VALUES (601,'2022-01-01',1000),(601,'2022-01-02',1100),(602,'2022-01-03',1200); | DELETE FROM ProductionData WHERE WellID = 601 AND ProductionDate = '2022-01-01'; |
Show the names, ranks, and departments of military personnel with a 'Top Secret' or 'Confidential' security clearance level. | CREATE TABLE Personnel (id INT,name VARCHAR(50),rank VARCHAR(20),department VARCHAR(20)); CREATE TABLE ClearanceLevels (id INT,level VARCHAR(20)); CREATE TABLE PersonnelClearances (personnel_id INT,clearance_id INT); INSERT INTO Personnel (id,name,rank,department) VALUES (1,'John Doe','Captain','Intelligence'),(2,'Jane Smith','Lieutenant','Intelligence'),(3,'Alice Johnson','Colonel','Military'),(4,'Bob Brown','Petty Officer','Navy'); INSERT INTO ClearanceLevels (id,level) VALUES (1,'Secret'),(2,'Top Secret'),(3,'Confidential'),(4,'Top Secret Plus'); INSERT INTO PersonnelClearances (personnel_id,clearance_id) VALUES (1,2),(2,3),(3,1),(4,1); | SELECT p.name, p.rank, p.department FROM Personnel p INNER JOIN PersonnelClearances pc ON p.id = pc.personnel_id INNER JOIN ClearanceLevels cl ON pc.clearance_id = cl.id WHERE cl.level IN ('Top Secret', 'Confidential'); |
What is the name of the movie with the shortest runtime in the movies table? | CREATE TABLE movies (id INT,title TEXT,runtime INT); | SELECT title FROM movies ORDER BY runtime ASC LIMIT 1; |
What is the minimum transaction amount in New York? | CREATE TABLE clients (id INT,name TEXT,age INT,state TEXT,transaction_amount DECIMAL(10,2)); INSERT INTO clients (id,name,age,state,transaction_amount) VALUES (1,'John Doe',35,'New York',250.00); INSERT INTO clients (id,name,age,state,transaction_amount) VALUES (2,'Jane Smith',40,'New York',300.50); | SELECT MIN(transaction_amount) FROM clients WHERE state = 'New York'; |
Insert a new 'Vegan Dessert' option in the 'Desserts' section with 'Vegan Brownie' priced at $6.49 and quantity 25. | CREATE TABLE Menu (item VARCHAR(20),type VARCHAR(20),price DECIMAL(5,2),quantity INT); | INSERT INTO Menu (item, type, price, quantity) VALUES ('Vegan Brownie', 'Desserts', 6.49, 25); |
List the names of athletes who have participated in both the Olympics and Commonwealth Games. | CREATE TABLE athletes (id INT,name VARCHAR(50),age INT,sport VARCHAR(50),event VARCHAR(50)); INSERT INTO athletes (id,name,age,sport,event) VALUES (1,'John Doe',25,'Athletics','Olympics'),(2,'Jane Smith',30,'Swimming','Commonwealth Games'),(3,'Richard Roe',28,'Athletics','Commonwealth Games'),(4,'Jessica Brown',27,'Athletics','Olympics'),(5,'Michael Green',31,'Swimming','Olympics'),(6,'Emily White',24,'Athletics','Commonwealth Games'); | SELECT name FROM athletes WHERE event IN ('Olympics', 'Commonwealth Games') GROUP BY name HAVING COUNT(DISTINCT event) = 2; |
How many indigenous food systems exist in African countries? | CREATE TABLE indigenous_food_systems (country VARCHAR(255)); INSERT INTO indigenous_food_systems (country) VALUES ('Mali'),('Nigeria'),('Kenya'),('Tanzania'); | SELECT COUNT(*) FROM indigenous_food_systems WHERE country LIKE 'Africa%' |
What is the number of IoT devices connected to the satellite imagery system in the past month? | CREATE TABLE iot_device (id INT,connected VARCHAR(255),connect_timestamp DATETIME); INSERT INTO iot_device (id,connected,connect_timestamp) VALUES (1,'Connected','2022-02-15 10:30:00'),(2,'Disconnected','2022-02-17 15:45:00'),(3,'Connected','2022-03-01 08:00:00'); | SELECT COUNT(*) FROM iot_device WHERE connected = 'Connected' AND connect_timestamp >= DATEADD(month, -1, CURRENT_TIMESTAMP); |
How many artists from underrepresented communities had exhibitions in 2021? | CREATE TABLE Artists (artist_id INT,artist_name VARCHAR(255),community VARCHAR(255)); CREATE TABLE Exhibitions (exhibition_id INT,artist_id INT,exhibition_year INT); INSERT INTO Artists (artist_id,artist_name,community) VALUES (1,'Alice','Female'),(2,'Bob','Minority'),(3,'Charlie','Native American'); INSERT INTO Exhibitions (exhibition_id,artist_id,exhibition_year) VALUES (1,1,2019),(2,2,2021),(3,3,2021); | SELECT COUNT(*) FROM Artists JOIN Exhibitions ON Artists.artist_id = Exhibitions.artist_id WHERE Exhibitions.exhibition_year = 2021 AND Artists.community IN ('Minority', 'Native American'); |
What is the average heart rate of members from India during morning workouts? | CREATE TABLE members (id INT,country VARCHAR(50)); INSERT INTO members (id,country) VALUES (1,'India'); CREATE TABLE workouts (id INT,member_id INT,date DATE,heart_rate INT); INSERT INTO workouts (id,member_id,date,heart_rate) VALUES (1,1,'2021-08-01',80); | SELECT AVG(heart_rate) FROM members JOIN workouts ON members.id = workouts.member_id WHERE members.country = 'India' AND HOUR(workouts.date) BETWEEN 6 AND 11; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.