instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
Which countries have the lowest transparency score in beauty product ingredient disclosure?
|
CREATE TABLE beauty_ingredients (product_id INT,country VARCHAR(255),transparency_score INT); CREATE TABLE products (product_id INT,product_name VARCHAR(255)); INSERT INTO beauty_ingredients (product_id,country,transparency_score) VALUES (1,'Mexico',60),(2,'Brazil',70),(3,'Argentina',80); INSERT INTO products (product_id,product_name) VALUES (1,'Lipstick'),(2,'Eyeshadow'),(3,'Blush');
|
SELECT country, AVG(transparency_score) AS avg_transparency_score FROM beauty_ingredients INNER JOIN products ON beauty_ingredients.product_id = products.product_id GROUP BY country ORDER BY avg_transparency_score ASC;
|
How many marine species have been discovered in the Arctic Ocean and the Mediterranean Sea?
|
CREATE TABLE Species (species_name VARCHAR(50),ocean_name VARCHAR(50)); INSERT INTO Species (species_name,ocean_name) VALUES ('Species A','Arctic Ocean'),('Species B','Mediterranean Sea');
|
SELECT COUNT(DISTINCT species_name) FROM Species WHERE ocean_name IN ('Arctic Ocean', 'Mediterranean Sea');
|
What is the minimum depth of the Puerto Rico Trench?
|
CREATE TABLE ocean_floor_mapping (name VARCHAR(255),location VARCHAR(255),min_depth FLOAT); INSERT INTO ocean_floor_mapping (name,location,min_depth) VALUES ('Puerto Rico Trench','Atlantic Ocean',8605.0);
|
SELECT min_depth FROM ocean_floor_mapping WHERE name = 'Puerto Rico Trench';
|
List the top 3 countries with the highest stream counts, along with their total stream counts.
|
CREATE TABLE users (id INT,country VARCHAR(50),stream_count INT); INSERT INTO users (id,country,stream_count) VALUES (1,'USA',100),(2,'Canada',120),(3,'USA',150),(4,'Mexico',80),(5,'Brazil',200);
|
SELECT country, SUM(stream_count) AS total_streams, ROW_NUMBER() OVER(ORDER BY SUM(stream_count) DESC) AS rank FROM users GROUP BY country ORDER BY rank ASC LIMIT 3;
|
What is the total quantity of resources depleted for each resource type, for the year 2022, in the 'environmental_impact' table?
|
CREATE TABLE environmental_impact (resource_type VARCHAR(50),year INT,quantity INT);
|
SELECT resource_type, SUM(quantity) FROM environmental_impact WHERE year = 2022 GROUP BY resource_type;
|
Which locations have had the most safety inspections in the past 2 years?
|
CREATE TABLE safety_inspections (id INT PRIMARY KEY,location VARCHAR(255),inspection_date DATE); INSERT INTO safety_inspections (id,location,inspection_date) VALUES ('Lab A','2022-01-01'); INSERT INTO safety_inspections (id,location,inspection_date) VALUES ('Lab B','2022-02-01');
|
SELECT location, COUNT(*) as num_inspections, RANK() OVER(ORDER BY COUNT(*) DESC) as inspection_rank FROM safety_inspections WHERE inspection_date >= DATEADD(year, -2, GETDATE()) GROUP BY location;
|
What is the total CO2 emissions of products from a specific manufacturer?
|
CREATE TABLE products (product_id int,product_name varchar(255),manufacturer_id int,CO2_emissions float); INSERT INTO products (product_id,product_name,manufacturer_id,CO2_emissions) VALUES (1,'Product A',1,100),(2,'Product B',1,150),(3,'Product C',2,75); CREATE TABLE manufacturers (manufacturer_id int,manufacturer_name varchar(255)); INSERT INTO manufacturers (manufacturer_id,manufacturer_name) VALUES (1,'Manufacturer X'),(2,'Manufacturer Y');
|
SELECT SUM(CO2_emissions) FROM products WHERE manufacturer_id = 1;
|
Identify the top 2 countries with the highest number of climate mitigation projects in Southeast Asia.
|
CREATE TABLE climate_mitigation_southeast_asia (country VARCHAR(50),project VARCHAR(50)); INSERT INTO climate_mitigation_southeast_asia (country,project) VALUES ('Indonesia','Forest Conservation Project'),('Thailand','Energy Efficiency Project'),('Malaysia','Renewable Energy Project'),('Vietnam','Sustainable Agriculture Project');
|
SELECT country, COUNT(project) AS project_count FROM climate_mitigation_southeast_asia WHERE country IN ('Indonesia', 'Thailand', 'Malaysia', 'Vietnam', 'Philippines') GROUP BY country ORDER BY project_count DESC LIMIT 2;
|
Update the funding amount for 'Startup A' to 10000000.
|
CREATE TABLE biotech_startups (id INT,name VARCHAR(100),location VARCHAR(100),funding FLOAT); INSERT INTO biotech_startups (id,name,location,funding) VALUES (1,'Startup A','Africa',8000000); INSERT INTO biotech_startups (id,name,location,funding) VALUES (2,'Startup B','Africa',10000000);
|
UPDATE biotech_startups SET funding = 10000000 WHERE name = 'Startup A';
|
Which restaurant categories have an average revenue over $5000?
|
CREATE TABLE restaurants (restaurant_id INT,name VARCHAR(50),cuisine VARCHAR(50),revenue INT); INSERT INTO restaurants VALUES (1,'Asian Fusion','Asian',5000),(2,'Tuscan Bistro','Italian',7000),(3,'Baja Coast','Mexican',4000);
|
SELECT cuisine, AVG(revenue) FROM restaurants GROUP BY cuisine HAVING AVG(revenue) > 5000;
|
Rank outcomes by outcome type
|
CREATE TABLE Outcomes (Id INT,ProgramId INT,Outcome VARCHAR(50),OutcomeDate DATE); INSERT INTO Outcomes (Id,ProgramId,Outcome,OutcomeDate) VALUES (1,1,'Graduated','2021-01-01'),(2,2,'Fed 50 people','2021-01-02'),(3,1,'Graduated','2021-01-02'),(4,2,'Fed 75 people','2021-01-03');
|
SELECT ProgramId, Outcome, COUNT(*) AS OutcomeCount, RANK() OVER(PARTITION BY ProgramId ORDER BY COUNT(*) DESC) AS OutcomeRank FROM Outcomes GROUP BY ProgramId, Outcome;
|
What is the total budget allocated for technology accessibility programs in each continent?
|
CREATE TABLE Tech_Accessibility (continent VARCHAR(255),budget INT); INSERT INTO Tech_Accessibility (continent,budget) VALUES ('Asia',2500000),('Africa',1800000),('South America',1200000),('Europe',900000),('Oceania',700000);
|
SELECT continent, SUM(budget) as total_budget FROM Tech_Accessibility GROUP BY continent;
|
What is the total number of citizens registered to vote in each county in the 'voting' table?
|
CREATE TABLE voting (id INT,county VARCHAR(50),registration_date DATE,voter_count INT); INSERT INTO voting (id,county,registration_date,voter_count) VALUES (1,'Los Angeles','2022-01-01',2000000),(2,'New York','2022-01-01',1500000),(3,'Harris','2022-01-01',1200000);
|
SELECT county, SUM(voter_count) as total_voters FROM voting GROUP BY county;
|
Find the number of unique chemical types produced by each manufacturer, ordered from most to least diverse
|
CREATE TABLE manufacturer_chemicals (manufacturer_id INT,manufacturer_name VARCHAR(50),chemical_type VARCHAR(50)); INSERT INTO manufacturer_chemicals (manufacturer_id,manufacturer_name,chemical_type) VALUES (1,'AusChem','Acid'),(1,'AusChem','Alkali'),(2,'British Biotech','Solvent'),(2,'British Biotech','Solute'),(3,'ChemCorp','Acid'),(3,'ChemCorp','Alkali'),(3,'ChemCorp','Solvent');
|
SELECT manufacturer_id, manufacturer_name, COUNT(DISTINCT chemical_type) as unique_chemical_types FROM manufacturer_chemicals GROUP BY manufacturer_id, manufacturer_name ORDER BY unique_chemical_types DESC;
|
What is the total number of public transportation users in New York, London, and Paris in 2020?
|
CREATE TABLE CityTransport (city VARCHAR(30),users INT,year INT); INSERT INTO CityTransport (city,users,year) VALUES ('New York',1000000,2020),('London',1200000,2020),('Paris',1100000,2020);
|
SELECT SUM(users) FROM CityTransport WHERE city IN ('New York', 'London', 'Paris') AND year = 2020;
|
What is the minimum fare for each route segment in the 'route_segments' table?
|
CREATE TABLE route_segments (route_id INT,segment_id INT,start_station VARCHAR(255),end_station VARCHAR(255),fare FLOAT);
|
SELECT route_id, segment_id, MIN(fare) as min_fare FROM route_segments GROUP BY route_id, segment_id;
|
Insert new records for two suppliers that provide sustainable materials and comply with fair labor practices.
|
CREATE TABLE supplier_ethics (supplier_id INT,name TEXT,sustainability_score INT,compliance_score INT);
|
INSERT INTO supplier_ethics (supplier_id, name, sustainability_score, compliance_score) VALUES (6, 'Supplier E', 85, 90), (7, 'Supplier F', 95, 95);
|
Show veteran employment statistics for the state of 'California'
|
CREATE TABLE veteran_employment (state VARCHAR(255),employed INT,unemployed INT,total_veterans INT); INSERT INTO veteran_employment (state,employed,unemployed,total_veterans) VALUES ('California',50000,3000,55000),('New York',45000,4000,50000);
|
SELECT employed, unemployed, total_veterans FROM veteran_employment WHERE state = 'California';
|
What are the names and locations of all renewable energy projects that received funding in 2020?
|
CREATE TABLE renewable_energy_projects (project_name TEXT,location TEXT,funding_year INTEGER); INSERT INTO renewable_energy_projects (project_name,location,funding_year) VALUES ('Solar Farm A','California',2020),('Wind Farm B','Texas',2019),('Hydro Plant C','Oregon',2020);
|
SELECT project_name, location FROM renewable_energy_projects WHERE funding_year = 2020;
|
List all electric vehicle models with autonomous capabilities in California, ordered by the year they were first manufactured.
|
CREATE TABLE electric_vehicles (model VARCHAR(30),autonomous BOOLEAN,manufacture_year INT); INSERT INTO electric_vehicles VALUES ('Tesla Model S',true,2012);
|
SELECT model FROM electric_vehicles WHERE autonomous = true AND state = 'California' ORDER BY manufacture_year;
|
Identify the unique genres of music that have been streamed in at least one country in each continent (North America, South America, Europe, Asia, Africa, and Australia).
|
CREATE TABLE Streams (country TEXT,genre TEXT); INSERT INTO Streams (country,genre) VALUES ('USA','Pop'),('USA','Rock'),('Brazil','Samba'),('France','Jazz'),('Japan','Pop'),('Kenya','Reggae'),('Australia','Pop');
|
SELECT genre FROM Streams WHERE country IN (SELECT DISTINCT country FROM (SELECT 'North America' as continent UNION ALL SELECT 'South America' UNION ALL SELECT 'Europe' UNION ALL SELECT 'Asia' UNION ALL SELECT 'Africa' UNION ALL SELECT 'Australia') as Continents) GROUP BY genre HAVING COUNT(DISTINCT country) >= 6;
|
List all biotech startups that received funding from VCs in the US after 2018?
|
CREATE TABLE startups (id INT,name TEXT,industry TEXT,funding_source TEXT,funding_date DATE); INSERT INTO startups (id,name,industry,funding_source,funding_date) VALUES (1,'BiotecHive','Biotech','VC','2019-04-01');
|
SELECT name FROM startups WHERE industry = 'Biotech' AND funding_source = 'VC' AND funding_date > '2018-12-31';
|
Calculate the total number of citizens who have participated in public hearings in each district
|
CREATE TABLE Citizens (CitizenID INT,FirstName TEXT,LastName TEXT,District TEXT,ParticipatedInPublicHearings INT); INSERT INTO Citizens (CitizenID,FirstName,LastName,District,ParticipatedInPublicHearings) VALUES (1,'John','Doe','District1',1),(2,'Jane','Doe','District2',1),(3,'Bob','Smith','District1',1);
|
SELECT District, SUM(ParticipatedInPublicHearings) FROM Citizens GROUP BY District;
|
What is the average cost of sustainable building projects in WA?
|
CREATE TABLE SustainableCosts (ProjectID int,State varchar(25),Sustainable bit,Cost decimal(10,2)); INSERT INTO SustainableCosts (ProjectID,State,Sustainable,Cost) VALUES (1,'WA',1,100000.00),(2,'WA',0,200000.00),(4,'WA',1,125000.00);
|
SELECT State, AVG(Cost) AS AvgCost FROM SustainableCosts WHERE State = 'WA' AND Sustainable = 1 GROUP BY State;
|
What is the total fuel consumption by vessels in the Caribbean in Q3 2020?
|
CREATE TABLE vessels(id INT,name VARCHAR(100),region VARCHAR(50));CREATE TABLE fuel_consumption(id INT,vessel_id INT,consumption FLOAT,consumption_date DATE);
|
SELECT SUM(consumption) FROM fuel_consumption fc JOIN vessels v ON fc.vessel_id = v.id WHERE v.region = 'Caribbean' AND consumption_date BETWEEN '2020-07-01' AND '2020-09-30';
|
What are the unique job titles of users who have engaged with posts about sustainability but have not applied to any jobs in the sustainability sector?
|
CREATE TABLE user_posts (user_id INT,post_topic VARCHAR(50),job_title VARCHAR(50)); INSERT INTO user_posts (user_id,post_topic,job_title) VALUES (1,'sustainability','Environmental Scientist'),(2,'technology','Software Engineer'),(3,'sustainability','Sustainability Consultant'),(4,'education','Teacher'),(5,'sustainability','Renewable Energy Engineer'),(6,'healthcare','Nurse');
|
SELECT job_title FROM user_posts WHERE post_topic = 'sustainability' AND user_id NOT IN (SELECT user_id FROM user_posts WHERE job_title LIKE '%sustainability%');
|
What is the total CO2 emissions for each region?
|
CREATE TABLE regions (id INT,name VARCHAR(50),co2_emissions INT); INSERT INTO regions (id,name,co2_emissions) VALUES (1,'North',5000),(2,'South',7000),(3,'East',9000),(4,'West',8000);
|
SELECT name, SUM(co2_emissions) as total_emissions FROM regions GROUP BY name;
|
Which systems have been affected by ransomware in the past month?
|
CREATE TABLE systems (system_id INT PRIMARY KEY,system_name VARCHAR(255),last_updated TIMESTAMP);CREATE TABLE malware_events (event_id INT PRIMARY KEY,system_id INT,event_date TIMESTAMP,malware_type VARCHAR(50));
|
SELECT s.system_name FROM systems s JOIN malware_events m ON s.system_id = m.system_id WHERE m.event_date >= NOW() - INTERVAL 1 MONTH AND m.malware_type = 'ransomware';
|
How many community policing events occurred in each borough in 2020?
|
CREATE TABLE boroughs (bid INT,borough_name VARCHAR(255)); CREATE TABLE events (eid INT,bid INT,event_date DATE);
|
SELECT b.borough_name, COUNT(e.eid) FROM boroughs b INNER JOIN events e ON b.bid = e.bid WHERE YEAR(e.event_date) = 2020 GROUP BY b.borough_name;
|
What is the percentage of community health workers in Florida who have received anti-discrimination training?
|
CREATE TABLE anti_discrimination_training (id INT,worker_id INT,training_date DATE); INSERT INTO anti_discrimination_training (id,worker_id,training_date) VALUES (1,789,'2021-04-01'),(2,789,'2021-06-15'); CREATE TABLE community_health_workers (id INT,name VARCHAR(50),region VARCHAR(50)); INSERT INTO community_health_workers (id,name,region) VALUES (789,'Jane Doe','Florida'); SELECT COUNT(DISTINCT worker_id) FROM anti_discrimination_training INNER JOIN community_health_workers ON anti_discrimination_training.worker_id = community_health_workers.id WHERE community_health_workers.region = 'Florida';
|
SELECT 100.0 * COUNT(DISTINCT anti_discrimination_training.worker_id) / COUNT(DISTINCT community_health_workers.id) FROM anti_discrimination_training RIGHT JOIN community_health_workers ON anti_discrimination_training.worker_id = community_health_workers.id WHERE community_health_workers.region = 'Florida';
|
How many events in each art discipline had an attendance of over 500 people in the past year, and what is the total funding received by these events?
|
CREATE TABLE events (event_id INT,event_name VARCHAR(50),event_date DATE,event_discipline VARCHAR(20)); CREATE TABLE event_attendance (attendee_id INT,event_id INT,attendance INT); CREATE TABLE funding_sources (funding_id INT,event_id INT,source_name VARCHAR(50),funding_amount DECIMAL(10,2)); INSERT INTO events (event_id,event_name,event_date,event_discipline) VALUES (1,'Art Exhibit','2022-04-01','Visual Arts'),(2,'Dance Performance','2022-05-01','Performing Arts'); INSERT INTO event_attendance (attendee_id,event_id,attendance) VALUES (1,1,600),(2,2,400); INSERT INTO funding_sources (funding_id,event_id,source_name,funding_amount) VALUES (1,1,'Local Arts Foundation',3000),(2,2,'National Endowment for the Arts',5000);
|
SELECT e.event_discipline, COUNT(e.event_id) AS event_count, SUM(fs.funding_amount) AS total_funding FROM events e INNER JOIN event_attendance ea ON e.event_id = ea.event_id INNER JOIN funding_sources fs ON e.event_id = fs.event_id WHERE e.event_date >= DATEADD(year, -1, GETDATE()) AND ea.attendance > 500 GROUP BY e.event_discipline;
|
What is the maximum and average amount of fertilizer used per hectare in the 'Agricultural Innovation' program in 'Oceania'?
|
CREATE TABLE Agricultural_Innovation(hectare_id INT,hectare_area FLOAT,country VARCHAR(50),fertilizer_used FLOAT); INSERT INTO Agricultural_Innovation(hectare_id,hectare_area,country,fertilizer_used) VALUES (1,2.5,'Australia',200),(2,3.0,'New Zealand',250);
|
SELECT MAX(fertilizer_used) as max_fertilizer_used, AVG(fertilizer_used) as avg_fertilizer_used FROM Agricultural_Innovation WHERE country = 'Oceania';
|
Find the maximum temperature and humidity for the crops in field 4 during the last 7 days.
|
CREATE TABLE field_sensors (field_id INT,sensor_type VARCHAR(20),value FLOAT,timestamp TIMESTAMP); INSERT INTO field_sensors (field_id,sensor_type,value,timestamp) VALUES (4,'temperature',25.5,'2023-02-15 10:00:00'),(4,'humidity',70.0,'2023-02-15 10:00:00');
|
SELECT field_id, MAX(value) FROM field_sensors WHERE sensor_type IN ('temperature', 'humidity') AND timestamp >= NOW() - INTERVAL 7 DAY GROUP BY field_id;
|
Show the total revenue for each cuisine type
|
CREATE TABLE cuisine (id INT,type VARCHAR(255)); INSERT INTO cuisine (id,type) VALUES (1,'Italian'),(2,'Mexican'),(3,'Chinese'); CREATE TABLE restaurant (id INT,name VARCHAR(255),cuisine_id INT); INSERT INTO restaurant (id,name,cuisine_id) VALUES (1,'Pizzeria',1),(2,'Taco House',2),(3,'Wok Palace',3); CREATE TABLE menu (id INT,item VARCHAR(255),price DECIMAL(5,2),daily_sales INT,restaurant_id INT);
|
SELECT c.type, SUM(m.price * m.daily_sales) as revenue FROM menu m JOIN restaurant r ON m.restaurant_id = r.id JOIN cuisine c ON r.cuisine_id = c.id GROUP BY c.type;
|
How many podcasts were published in Brazil in the last year?
|
CREATE TABLE podcasts (id INT,title VARCHAR(255),publish_date DATE,location VARCHAR(50)); INSERT INTO podcasts (id,title,publish_date,location) VALUES (1,'Podcast1','2022-06-01','Brazil'),(2,'Podcast2','2021-08-05','Brazil'),(3,'Podcast3','2022-01-03','Brazil');
|
SELECT COUNT(*) FROM podcasts WHERE location = 'Brazil' AND publish_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 1 YEAR) AND CURDATE();
|
Who are the top 5 donors for the 'Food Bank' program?
|
CREATE TABLE Programs (ProgramID INT,ProgramName VARCHAR(50)); INSERT INTO Programs (ProgramID,ProgramName) VALUES (1,'Food Bank'),(2,'Elderly Care'),(3,'Youth Mentoring'); CREATE TABLE Donors (DonorID INT,DonorName VARCHAR(50)); INSERT INTO Donors (DonorID,DonorName) VALUES (1001,'John Doe'),(1002,'Jane Doe'),(2001,'Mike Johnson'),(3001,'Emma Smith'); CREATE TABLE Donations (DonationID INT,DonorID INT,ProgramID INT,DonationAmount DECIMAL(10,2)); INSERT INTO Donations (DonationID,DonorID,ProgramID,DonationAmount) VALUES (1,1001,1,50.00),(2,1001,1,100.00),(3,1002,1,200.00),(4,2001,2,300.00),(5,2001,3,400.00),(6,3001,1,500.00),(7,3001,3,600.00),(8,3001,3,700.00);
|
SELECT d.DonorName, SUM(d.DonationAmount) AS TotalDonationAmount FROM Donors d JOIN Donations don ON d.DonorID = don.DonorID WHERE don.ProgramID = 1 GROUP BY d.DonorName ORDER BY TotalDonationAmount DESC LIMIT 5;
|
What is the average bridge length in the transport division?
|
CREATE TABLE Projects (id INT,division VARCHAR(10)); INSERT INTO Projects (id,division) VALUES (1,'water'),(2,'transport'),(3,'energy'); CREATE TABLE TransportProjects (id INT,project_id INT,length DECIMAL(10,2)); INSERT INTO TransportProjects (id,project_id,length) VALUES (1,2,500),(2,2,550),(3,3,600);
|
SELECT AVG(t.length) FROM TransportProjects t JOIN Projects p ON t.project_id = p.id WHERE p.division = 'transport';
|
What is the policy number, policy type, and coverage amount for policies with a policy start date within the last 30 days?
|
CREATE TABLE policies (policy_number INT,policy_type VARCHAR(50),coverage_amount INT,policy_start_date DATE); INSERT INTO policies (policy_number,policy_type,coverage_amount,policy_start_date) VALUES (12345,'Auto',50000,'2022-01-01'); INSERT INTO policies (policy_number,policy_type,coverage_amount,policy_start_date) VALUES (67890,'Home',300000,'2022-02-15');
|
SELECT policy_number, policy_type, coverage_amount FROM policies WHERE policy_start_date >= CURDATE() - INTERVAL 30 DAY;
|
Insert a new row into the 'trades' table with a trade ID of 123, a customer ID of 456, a trade date of '2022-01-01', a security symbol of 'ABC', and a quantity of 100
|
CREATE TABLE trades (trade_id INT PRIMARY KEY,customer_id INT,trade_date DATE,security_symbol VARCHAR(10),quantity INT);
|
INSERT INTO trades (trade_id, customer_id, trade_date, security_symbol, quantity) VALUES (123, 456, '2022-01-01', 'ABC', 100);
|
Get the details of military technology expenditures for 'Artificial Intelligence' in the 'MilitaryTech' schema.
|
CREATE SCHEMA IF NOT EXISTS MilitaryTech; CREATE TABLE IF NOT EXISTS MilitaryTech.Tech_Expenditures (expenditure_id INT,tech_name VARCHAR(255),year INT,amount DECIMAL(10,2),description TEXT); INSERT INTO MilitaryTech.Tech_Expenditures (expenditure_id,tech_name,year,amount,description) VALUES (1,'Artificial Intelligence',2021,15000000.00,'AI research for military applications'),(2,'Cybersecurity',2022,12000000.00,'Cybersecurity tools development');
|
SELECT * FROM MilitaryTech.Tech_Expenditures WHERE tech_name = 'Artificial Intelligence';
|
What is the average ticket price for concerts in the city of Chicago?
|
CREATE TABLE concert_sales (id INT,city VARCHAR,price DECIMAL);
|
SELECT AVG(price) FROM concert_sales WHERE city = 'Chicago';
|
What is the minimum property price in the 'affordable_housing' table?
|
CREATE TABLE affordable_housing (id INT,city VARCHAR(20),price INT); INSERT INTO affordable_housing (id,city,price) VALUES (1,'Miami',200000),(2,'Houston',150000),(3,'Dallas',180000);
|
SELECT MIN(price) FROM affordable_housing;
|
Delete records from the FoodInspections table where the InspectionDate is older than 90 days from today.
|
CREATE TABLE FoodInspections (InspectionID int,RestaurantID varchar(50),InspectionDate date);
|
DELETE FI FROM FoodInspections FI WHERE DATEDIFF(day, FI.InspectionDate, GETDATE()) > 90;
|
What is the percentage of patients with Diabetes in New York who are over 40 years old?
|
CREATE TABLE Patients (ID INT,Age INT,Disease VARCHAR(20),State VARCHAR(20)); INSERT INTO Patients (ID,Age,Disease,State) VALUES (1,45,'Diabetes','New York');
|
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Patients WHERE Disease = 'Diabetes' AND State = 'New York')) FROM Patients WHERE Age > 40 AND Disease = 'Diabetes' AND State = 'New York';
|
What is the total cost of emergency responses and disaster recovery efforts in each district, sorted by the total cost in descending order?
|
CREATE TABLE Districts (DId INT,Name VARCHAR(50)); CREATE TABLE EmergencyResponses (ResponseId INT,DId INT,Cost INT); CREATE TABLE DisasterRecovery (RecoveryId INT,DId INT,Cost INT);
|
SELECT D.Name, SUM(ER.Cost) + SUM(DR.Cost) AS TotalCost FROM Districts D LEFT JOIN EmergencyResponses ER ON D.DId = ER.DId LEFT JOIN DisasterRecovery DR ON D.DId = DR.DId GROUP BY D.Name ORDER BY TotalCost DESC;
|
List all the platforms, including the ones that have not started production yet, with their corresponding field names
|
CREATE TABLE platforms (platform_id INT,platform_name VARCHAR(255),field_name VARCHAR(255),started_production BOOLEAN); INSERT INTO platforms (platform_id,platform_name,field_name,started_production) VALUES (1,'A','Field A',true),(2,'B','Field B',false);
|
SELECT platform_name, field_name FROM platforms;
|
Find the daily average revenue for 'Dinner' and 'Snacks' menu categories in the last month.
|
CREATE TABLE daily_revenue(menu_category VARCHAR(20),revenue DECIMAL(10,2),order_date DATE); INSERT INTO daily_revenue(menu_category,revenue,order_date) VALUES ('Dinner',7000,'2021-04-01'),('Snacks',3000,'2021-04-01'),('Dinner',6000,'2021-04-02'),('Snacks',3500,'2021-04-02');
|
SELECT menu_category, AVG(revenue) AS avg_daily_revenue FROM daily_revenue WHERE order_date >= (SELECT DATE(CURRENT_DATE - INTERVAL 30 DAY)) AND menu_category IN ('Dinner', 'Snacks') GROUP BY menu_category;
|
How many exhibitions were held in each country since 2000?
|
CREATE TABLE Exhibitions (ExhibitionID INT,Gallery VARCHAR(100),ArtworkID INT,Country VARCHAR(50),Year INT);
|
SELECT Exhibitions.Country, COUNT(DISTINCT Exhibitions.ExhibitionID) AS ExhibitionCount FROM Exhibitions WHERE Exhibitions.Year >= 2000 GROUP BY Exhibitions.Country;
|
Who is the policy advocate for the 'Assistive Technology' program in the 'California' office?
|
CREATE TABLE office (office_id INT,office_state VARCHAR(50),program_name VARCHAR(50)); CREATE TABLE staff (staff_id INT,staff_name VARCHAR(50),role VARCHAR(50)); INSERT INTO office (office_id,office_state,program_name) VALUES (1,'California','Assistive Technology'); INSERT INTO staff (staff_id,staff_name,role) VALUES (101,'John Doe','Policy Advocate'),(102,'Jane Smith','Support Staff');
|
SELECT staff_name FROM office o JOIN staff s ON o.office_state = s.staff_name WHERE o.program_name = 'Assistive Technology' AND s.role = 'Policy Advocate';
|
What is the average rating of skincare products that are vegan and have not been tested on animals?
|
CREATE TABLE products (product_id INT,product_name VARCHAR(100),product_type VARCHAR(50),vegan BOOLEAN,cruelty_free BOOLEAN,rating FLOAT);
|
SELECT AVG(rating) FROM products WHERE product_type = 'skincare' AND vegan = TRUE AND cruelty_free = TRUE;
|
What is the number of transactions by customer name for the month of April 2022?
|
CREATE TABLE customers (customer_id INT,customer_name VARCHAR(50),account_number VARCHAR(20),primary_contact VARCHAR(50)); CREATE TABLE transactions (transaction_id INT,customer_id INT,transaction_type VARCHAR(20),transaction_amount DECIMAL(10,2),transaction_date DATE);
|
SELECT c.customer_name, COUNT(t.transaction_id) as number_of_transactions FROM customers c JOIN transactions t ON c.customer_id = t.customer_id WHERE transaction_date BETWEEN '2022-04-01' AND '2022-04-30' GROUP BY c.customer_name;
|
What is the average health metric for all species?
|
CREATE TABLE health_metrics (id INT,species VARCHAR(50),metric FLOAT); INSERT INTO health_metrics (id,species,metric) VALUES (1,'Tilapia',75.0),(2,'Catfish',80.0),(3,'Salmon',60.0);
|
SELECT AVG(metric) FROM health_metrics;
|
What is the total number of properties in Seattle with a co-housing model?
|
CREATE TABLE property_type (property_id INT,city VARCHAR(50),model VARCHAR(50)); INSERT INTO property_type VALUES (1,'Seattle','co-housing'),(2,'Seattle','rental'),(3,'Portland','co-housing');
|
SELECT COUNT(*) FROM property_type WHERE city = 'Seattle' AND model = 'co-housing';
|
Compare the environmental impact of Samarium and Gadolinium production
|
CREATE TABLE environmental_impact (country VARCHAR(20),element VARCHAR(10),impact FLOAT); INSERT INTO environmental_impact VALUES ('China','Samarium',6.1),('China','Gadolinium',7.6),('United States','Samarium',2.7),('United States','Gadolinium',3.5),('Australia','Samarium',2.2),('Australia','Gadolinium',3.3);
|
SELECT element, impact FROM environmental_impact WHERE country = 'China' UNION SELECT element, impact FROM environmental_impact WHERE country = 'United States' ORDER BY element, impact;
|
What are the unique combinations of Culture and Specialty for CulturallyCompetentHealthcareProviders table?
|
CREATE TABLE CulturallyCompetentHealthcareProviders (ProviderID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Culture VARCHAR(50),Specialty VARCHAR(50)); INSERT INTO CulturallyCompetentHealthcareProviders (ProviderID,FirstName,LastName,Culture,Specialty) VALUES (1,'Ali','Ahmed','Arabic','Pediatrics');
|
SELECT Culture, Specialty FROM CulturallyCompetentHealthcareProviders;
|
What is the policy number, coverage amount, and effective date for policies underwritten by 'John Smith'?
|
CREATE TABLE Underwriting (policy_number INT,coverage_amount INT,underwriter VARCHAR(20)); INSERT INTO Underwriting (policy_number,coverage_amount,underwriter) VALUES (123,50000,'Jane Smith'),(234,75000,'John Smith'),(345,30000,'John Smith');
|
SELECT policy_number, coverage_amount, effective_date FROM Underwriting JOIN Policy ON Underwriting.policy_number = Policy.policy_number WHERE underwriter = 'John Smith';
|
Which program had the highest average donation amount?
|
CREATE TABLE Donations (DonationID int,Amount decimal(10,2),PaymentMethod varchar(50),DonationDate date,Program varchar(50)); INSERT INTO Donations (DonationID,Amount,PaymentMethod,DonationDate,Program) VALUES (1,100.00,'Credit Card','2021-01-01','Education'); INSERT INTO Donations (DonationID,Amount,PaymentMethod,DonationDate,Program) VALUES (2,50.00,'PayPal','2021-02-01','Health');
|
SELECT Program, AVG(Amount) as AverageDonationAmount FROM Donations GROUP BY Program ORDER BY AverageDonationAmount DESC LIMIT 1;
|
What are the founding years and locations for companies based in Texas?
|
CREATE TABLE Founding_Data (company_name VARCHAR(50),founding_year INT,founding_location VARCHAR(50)); INSERT INTO Founding_Data (company_name,founding_year,founding_location) VALUES ('Waystar Royco',1980,'New York'); INSERT INTO Founding_Data (company_name,founding_year,founding_location) VALUES ('Pied Piper',2012,'California'); INSERT INTO Founding_Data (company_name,founding_year,founding_location) VALUES ('Austin Biotech',2005,'Texas');
|
SELECT company_name, founding_year FROM Founding_Data WHERE founding_location = 'Texas';
|
What is the difference in budget between consecutive departments in each city?
|
CREATE TABLE CityBudget (CityName VARCHAR(50),Department VARCHAR(50),Budget INT); INSERT INTO CityBudget (CityName,Department,Budget) VALUES ('CityA','Parks',5000000),('CityA','Roads',7000000),('CityB','Parks',6000000),('CityB','Roads',8000000);
|
SELECT CityName, Department, LAG(Budget) OVER(PARTITION BY CityName ORDER BY Department) as PreviousBudget, Budget - LAG(Budget) OVER(PARTITION BY CityName ORDER BY Department) as BudgetDifference FROM CityBudget;
|
Which ports have had a decrease in cargo handling in the last month?
|
CREATE TABLE port_updates (update_id INT,port_name VARCHAR(50),total_cargo INT,update_date DATE); INSERT INTO port_updates VALUES (1,'Port of Shanghai',43032442,'2022-02-15'); INSERT INTO port_updates VALUES (2,'Port of Singapore',37439402,'2022-03-20'); INSERT INTO port_updates VALUES (3,'Port of Shenzhen',27162000,'2022-03-08');
|
SELECT port_name FROM port_updates WHERE total_cargo < LAG(total_cargo) OVER (PARTITION BY port_name ORDER BY update_date);
|
List all rural infrastructure projects in India and their respective start dates.
|
CREATE TABLE rural_infrastructure_projects (id INT,project_name VARCHAR(50),country VARCHAR(50),start_date DATE); INSERT INTO rural_infrastructure_projects (id,project_name,country,start_date) VALUES (1,'Rajiv Gandhi Rural Electrification Program','India','2010-04-01'),(2,'BharatNet Rural Broadband Initiative','India','2015-07-26');
|
SELECT project_name, start_date FROM rural_infrastructure_projects WHERE country = 'India';
|
What is the total number of visitors and the number of heritage sites in each continent?
|
CREATE TABLE VisitorsAndSites (id INT,site_name VARCHAR(255),continent VARCHAR(255),visitors INT); INSERT INTO VisitorsAndSites (id,site_name,continent,visitors) VALUES (1,'Machu Picchu','South America',1200000),(2,'Angkor Wat','Asia',2000000),(3,'Petra','Asia',800000);
|
SELECT continent, COUNT(*), SUM(visitors) FROM VisitorsAndSites GROUP BY continent;
|
What is the average yield of soybeans grown in the USA?
|
CREATE TABLE Crops (id INT,name VARCHAR(50),yield INT,farm_id INT); INSERT INTO Crops (id,name,yield,farm_id) VALUES (1,'Corn',120,1); INSERT INTO Crops (id,name,yield,farm_id) VALUES (2,'Soybeans',50,1); INSERT INTO Crops (id,name,yield,farm_id) VALUES (3,'Wheat',75,2);
|
SELECT AVG(yield) FROM Crops WHERE name = 'Soybeans' AND farm_id IN (SELECT id FROM Farmers WHERE country = 'USA');
|
How many autonomous vehicles are in use in each region?
|
CREATE TABLE AutonomousVehicles(Region VARCHAR(50),Type VARCHAR(50),InUse INT);
|
SELECT Region, SUM(InUse) FROM AutonomousVehicles GROUP BY Region;
|
List all campaigns in Oregon that started before 2017-01-01.
|
CREATE TABLE campaigns (campaign_id INT,name TEXT,start_date DATE,location TEXT); INSERT INTO campaigns (campaign_id,name,start_date,location) VALUES (1,'End Stigma','2017-12-01','New York'); INSERT INTO campaigns (campaign_id,name,start_date,location) VALUES (2,'Mental Health Matters','2019-06-01','California'); INSERT INTO campaigns (campaign_id,name,start_date,location) VALUES (3,'Mental Health Awareness','2016-06-01','Oregon');
|
SELECT name, start_date FROM campaigns WHERE location = 'Oregon' AND start_date < '2017-01-01';
|
What is the average temperature recorded in the 'arctic_weather' table for each month in 2020, grouped by month?
|
CREATE TABLE arctic_weather (measurement_id INT,measurement_date DATE,temperature DECIMAL(5,2)); INSERT INTO arctic_weather (measurement_id,measurement_date,temperature) VALUES (1,'2020-01-01',20.5),(2,'2020-01-02',21.3);
|
SELECT AVG(temperature) as avg_temperature, EXTRACT(MONTH FROM measurement_date) as month FROM arctic_weather WHERE EXTRACT(YEAR FROM measurement_date) = 2020 GROUP BY month;
|
Calculate the number of records in the explainable_ai table with a fairness score greater than 0.8.
|
CREATE TABLE explainable_ai (record_id INT,algorithm_name TEXT,fairness_score REAL); INSERT INTO explainable_ai VALUES (1,'SHAP',0.8),(2,'LIME',0.6),(3,'Anchors',0.9);
|
SELECT COUNT(*) FROM explainable_ai WHERE fairness_score > 0.8;
|
Which countries have our organization supported the most refugees, and how many refugees were supported in each?
|
CREATE TABLE refugees (id INT,name TEXT,country TEXT,status TEXT); INSERT INTO refugees (id,name,country,status) VALUES (1,'Sara','Syria','active'); INSERT INTO refugees (id,name,country,status) VALUES (2,'Hussein','Afghanistan','active'); INSERT INTO refugees (id,name,country,status) VALUES (3,'Mariam','Syria','inactive');
|
SELECT country, COUNT(*) as refugee_count FROM refugees GROUP BY country ORDER BY refugee_count DESC;
|
List all traditional art pieces along with their respective art types and the dates when they were last updated.
|
CREATE TABLE TraditionalArt (art_id INT,art_name VARCHAR(20),art_type VARCHAR(20),last_updated_date DATE);
|
SELECT art_name, art_type, last_updated_date FROM TraditionalArt;
|
Find the minimum age of female patients diagnosed with any disease in the 'Florida' region.
|
CREATE TABLE Patients (PatientID INT,Age INT,Gender VARCHAR(10),Disease VARCHAR(20),Region VARCHAR(20)); INSERT INTO Patients (PatientID,Age,Gender,Disease,Region) VALUES (1,34,'Male','Influenza','Los Angeles'); INSERT INTO Patients (PatientID,Age,Gender,Disease,Region) VALUES (2,42,'Female','Pneumonia','New York');
|
SELECT MIN(Age) FROM Patients WHERE Gender = 'Female' AND Region = 'Florida';
|
Find the number of vehicles that passed the safety test, grouped by make
|
CREATE TABLE vehicle_safety_test (id INT,vehicle_make VARCHAR(50),test_result VARCHAR(10)); INSERT INTO vehicle_safety_test (id,vehicle_make,test_result) VALUES (1,'Toyota','Pass'),(2,'Toyota','Pass'),(3,'Honda','Fail'),(4,'Tesla','Pass');
|
SELECT vehicle_make, COUNT(*) as passed_count FROM vehicle_safety_test WHERE test_result = 'Pass' GROUP BY vehicle_make;
|
Find the top 3 countries with the highest revenue from cultural heritage tours?
|
CREATE TABLE Tours (id INT,name TEXT,country TEXT,type TEXT,revenue INT); INSERT INTO Tours (id,name,country,type,revenue) VALUES (1,'Cultural Heritage Tour','Italy','Cultural',30000);
|
SELECT country, SUM(revenue) AS total_revenue FROM Tours GROUP BY country ORDER BY total_revenue DESC LIMIT 3;
|
How many unique cannabis strains were produced in Michigan in 2021?
|
CREATE TABLE Producers (id INT,name TEXT,state TEXT);CREATE TABLE Strains (id INT,producer_id INT,name TEXT,year INT); INSERT INTO Producers (id,name,state) VALUES (1,'Producer A','Michigan'); INSERT INTO Strains (id,producer_id,name,year) VALUES (1,1,'Strain X',2021);
|
SELECT COUNT(DISTINCT s.name) FROM Producers p INNER JOIN Strains s ON p.id = s.producer_id WHERE p.state = 'Michigan' AND s.year = 2021;
|
How many market access strategies were implemented for 'DrugD' in 2021?
|
CREATE TABLE market_access (drug_name TEXT,year INTEGER,strategy_count INTEGER); INSERT INTO market_access (drug_name,year,strategy_count) VALUES ('DrugD',2021,3);
|
SELECT strategy_count FROM market_access WHERE drug_name = 'DrugD' AND year = 2021;
|
What is the total number of art workshops attended by users from the "Young Adults" age group?
|
CREATE TABLE Users (UserID INT,AgeGroup VARCHAR(20)); INSERT INTO Users (UserID,AgeGroup) VALUES (1,'Young Adults'),(2,'Seniors'); CREATE TABLE Workshops (WorkshopID INT,Title VARCHAR(50),UsersAttended INT); INSERT INTO Workshops (WorkshopID,Title,UsersAttended) VALUES (1,'Watercolor Basics',30),(2,'Pottery Making',25);
|
SELECT SUM(Workshops.UsersAttended) AS TotalWorkshopsAttended FROM Users INNER JOIN Workshops ON Users.AgeGroup = 'Young Adults' AND Workshops.WorkshopID = Users.UserID;
|
How many digital divide initiatives were implemented in Africa?
|
CREATE TABLE div_initiatives (initiative TEXT,region TEXT); INSERT INTO div_initiatives (initiative,region) VALUES ('digital divide','Africa'),('digital divide','Asia'),('ethical AI','Europe');
|
SELECT COUNT(*) FROM div_initiatives WHERE region = 'Africa';
|
How many attendees participated in dance programs by age group in H1 2022?
|
CREATE TABLE DanceAttendance (id INT,age_group VARCHAR(10),program VARCHAR(20),attendance INT,attendance_date DATE); INSERT INTO DanceAttendance (id,age_group,program,attendance,attendance_date) VALUES (1,'5-10','Ballet',25,'2022-01-05'),(2,'11-15','Hip Hop',30,'2022-03-12'),(3,'16-20','Contemporary',20,'2022-02-25');
|
SELECT program, age_group, SUM(attendance) as total_attendance FROM DanceAttendance WHERE YEAR(attendance_date) = 2022 AND MONTH(attendance_date) <= 6 AND program = 'Dance' GROUP BY program, age_group;
|
What is the total revenue generated by Latin music festivals in South America?
|
CREATE TABLE Festivals (FestivalID INT,Name VARCHAR(255),Genre VARCHAR(255),Location VARCHAR(255),Country VARCHAR(255),Year INT,Revenue INT); INSERT INTO Festivals VALUES (1,'Lollapalooza','Various','Grant Park','USA',2022,2000000); INSERT INTO Festivals VALUES (2,'Rock in Rio','Various','City of Rock','Brazil',2019,8000000); INSERT INTO Festivals VALUES (3,'Vive Latino','Latin','Foro Sol','Mexico',2022,5000000);
|
SELECT SUM(Revenue) FROM Festivals WHERE Genre = 'Latin' AND Country = 'South America';
|
What is the total number of healthcare visits in the "rural_clinic_d" table?
|
CREATE TABLE rural_clinic_d (id INT,visit_date DATE); INSERT INTO rural_clinic_d (id,visit_date) VALUES (1,'2022-01-01'),(2,'2022-02-01'),(3,'2022-03-01');
|
SELECT COUNT(*) FROM rural_clinic_d;
|
What is the total budget for AI projects in Asia?
|
CREATE TABLE ai_projects (id INT,region VARCHAR(255),budget DECIMAL(10,2)); INSERT INTO ai_projects (id,region,budget) VALUES (1,'North America',1500000.00),(2,'Asia',900000.00),(3,'South America',600000.00);
|
SELECT SUM(budget) FROM ai_projects WHERE region = 'Asia';
|
What are the unique travel advisories issued for African countries in the past year?
|
CREATE TABLE africa_travel_advisories (country VARCHAR(50),advisory TEXT,date DATE); INSERT INTO africa_travel_advisories VALUES ('Kenya','Terrorism threat','2022-01-01'),('Tanzania','Political unrest','2022-02-15'),('Nigeria','Health warnings','2021-12-30'),('Egypt','Protests','2022-03-10'),('Morocco','Natural disasters','2022-04-20');
|
SELECT DISTINCT country, advisory FROM africa_travel_advisories WHERE date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR);
|
Find the number of unique genres for TV shows produced in the US and their average runtime.
|
CREATE TABLE tv_show (id INT,title VARCHAR(100),genre VARCHAR(20),production_country VARCHAR(50),runtime INT); INSERT INTO tv_show (id,title,genre,production_country,runtime) VALUES (1,'Breaking Bad','Drama','United States',45);
|
SELECT COUNT(DISTINCT genre), AVG(runtime) FROM tv_show WHERE production_country = 'United States';
|
What is the water consumption trend in the state of Florida over the past 3 years?
|
CREATE TABLE historical_water_consumption (id INT,state VARCHAR(255),year INT,water_consumption FLOAT); INSERT INTO historical_water_consumption (id,state,year,water_consumption) VALUES (1,'Florida',2020,2000000),(2,'Florida',2021,2100000),(3,'Florida',2022,2200000);
|
SELECT year, water_consumption FROM historical_water_consumption WHERE state = 'Florida' ORDER BY year;
|
What was the total investment in energy efficiency projects in the US in 2021?
|
CREATE TABLE investment (project_location VARCHAR(255),year INT,investment FLOAT); INSERT INTO investment (project_location,year,investment) VALUES ('US',2021,5000000),('Canada',2021,3000000),('Mexico',2021,2000000);
|
SELECT SUM(investment) as total_investment FROM investment WHERE project_location = 'US' AND year = 2021;
|
Which brands in the ethical fashion database have not been involved in any labor practice violations?
|
CREATE TABLE labor_violations (brand VARCHAR(50),violation_count INT); INSERT INTO labor_violations (brand,violation_count) VALUES ('Brand A',15),('Brand B',5),('Brand C',2),('Brand D',NULL);
|
SELECT brand FROM labor_violations WHERE violation_count IS NULL;
|
How many training sessions did each employee attend in descending order?
|
CREATE TABLE Employees (EmployeeID int,FirstName varchar(50),LastName varchar(50)); CREATE TABLE Trainings (TrainingID int,EmployeeID int,TrainingTitle varchar(100),TrainingDate date); INSERT INTO Employees (EmployeeID,FirstName,LastName) VALUES (1,'John','Doe'); INSERT INTO Employees (EmployeeID,FirstName,LastName) VALUES (2,'Jane','Smith'); INSERT INTO Trainings (TrainingID,EmployeeID,TrainingTitle,TrainingDate) VALUES (1,1,'SQL Fundamentals','2020-01-01'); INSERT INTO Trainings (TrainingID,EmployeeID,TrainingTitle,TrainingDate) VALUES (2,1,'Intermediate SQL','2020-02-01'); INSERT INTO Trainings (TrainingID,EmployeeID,TrainingTitle,TrainingDate) VALUES (3,2,'SQL Fundamentals','2020-01-01');
|
SELECT EmployeeID, COUNT(*) as SessionCount FROM Trainings GROUP BY EmployeeID ORDER BY SessionCount DESC;
|
What is the maximum temperature recorded in the Arctic per month?
|
CREATE TABLE weather_data (id INT,date DATE,temp FLOAT);
|
SELECT MAX(temp) FROM weather_data WHERE date >= DATE_SUB(CURDATE(), INTERVAL 12 MONTH) GROUP BY MONTH(date);
|
How many threat intelligence entries are in the 'threats' table?
|
CREATE TABLE threats (threat_id INT,category VARCHAR(50),description TEXT); INSERT INTO threats (threat_id,category,description) VALUES (1,'Phishing','Email-based phishing attack...'),(2,'Malware','New ransomware variant...'),(3,'Phishing','Spear-phishing attack...'),(4,'Malware','Advanced persistent threat...');
|
SELECT COUNT(*) FROM threats;
|
Update the 'vaccination_stats' table with new data
|
CREATE TABLE vaccination_stats (id INT PRIMARY KEY,state VARCHAR(50),total_vaccinations INT); INSERT INTO vaccination_stats (id,state,total_vaccinations) VALUES (1,'California',25000000);
|
UPDATE vaccination_stats SET total_vaccinations = 26000000 WHERE state = 'California';
|
Retrieve the ID and name of the employee in the 'Lena Spencer' department with the latest hire date, excluding any employees in the same department with earlier hire dates.
|
CREATE TABLE Employees (EmployeeID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50),HireDate DATE); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,HireDate) VALUES (1,'Lena','Spencer','HR','2022-01-05');
|
SELECT EmployeeID, FirstName, LastName FROM Employees WHERE Department = (SELECT Department FROM Employees WHERE FirstName = 'Lena' AND LastName = 'Spencer') AND HireDate > ALL(SELECT HireDate FROM Employees E2 WHERE E2.Department = (SELECT Department FROM Employees WHERE FirstName = 'Lena' AND LastName = 'Spencer'));
|
What is the total fare collected by each driver for the 'LightRail' service?
|
CREATE TABLE Drivers (DriverID INT,DriverName VARCHAR(50),Service VARCHAR(50)); INSERT INTO Drivers (DriverID,DriverName,Service) VALUES (1,'John Doe','LightRail'),(2,'Jane Smith','Bus'),(3,'Alice Johnson','LightRail'); CREATE TABLE Fares (FareID INT,DriverID INT,FareAmount DECIMAL(5,2)); INSERT INTO Fares (FareID,DriverID,FareAmount) VALUES (1,1,5.00),(2,1,7.50),(3,2,3.00),(4,3,6.00),(5,1,4.50);
|
SELECT d.DriverName, SUM(f.FareAmount) as TotalFare FROM Drivers d JOIN Fares f ON d.DriverID = f.DriverID WHERE d.Service = 'LightRail' GROUP BY d.DriverName;
|
What is the minimum adoption score for smart cities in the 'smart_cities' table?
|
CREATE TABLE if not exists smart_cities (city_id INT,city_name VARCHAR(255),country VARCHAR(255),adoption_score FLOAT);
|
SELECT MIN(adoption_score) FROM smart_cities WHERE adoption_score IS NOT NULL;
|
What is the total revenue for each mobile plan in the current quarter?
|
CREATE TABLE mobile_plans (plan_id INT,plan_name VARCHAR(255),monthly_cost DECIMAL(10,2)); INSERT INTO mobile_plans (plan_id,plan_name,monthly_cost) VALUES (1,'Basic',30.00),(2,'Premium',60.00);
|
SELECT plan_name, SUM(monthly_cost) as total_revenue FROM mobile_plans JOIN subscriptions ON mobile_plans.plan_id = subscriptions.plan_id WHERE subscriptions.subscription_date >= DATE_SUB(CURDATE(), INTERVAL QUARTER(CURDATE()) QUARTER) AND subscriptions.subscription_date < DATE_ADD(LAST_DAY(CURDATE()), INTERVAL 1 DAY) GROUP BY plan_name;
|
What is the maximum gas limit for transactions on the Algorand network?
|
CREATE TABLE algorand_transactions (gas_limit INT);
|
SELECT MAX(gas_limit) FROM algorand_transactions;
|
What are the top 5 most active users in terms of content creation and engagement, and what is their total number of interactions?
|
CREATE TABLE users (id INT,username VARCHAR(50)); CREATE TABLE content (id INT,user_id INT,content_time TIMESTAMP); CREATE TABLE likes (content_id INT,user_id INT,like_time TIMESTAMP); CREATE TABLE comments (content_id INT,user_id INT,comment_time TIMESTAMP); CREATE TABLE shares (content_id INT,user_id INT,share_time TIMESTAMP);
|
SELECT users.username, COUNT(content.id) + COUNT(likes.content_id) + COUNT(comments.content_id) + COUNT(shares.content_id) as total_interactions FROM users LEFT JOIN content ON users.id = content.user_id LEFT JOIN likes ON users.id = likes.user_id LEFT JOIN comments ON users.id = comments.user_id LEFT JOIN shares ON users.id = shares.user_id GROUP BY users.username ORDER BY total_interactions DESC LIMIT 5;
|
What is the difference in square footage between the largest and smallest units in each building, partitioned by building type and ordered by difference?
|
CREATE TABLE Buildings (building_id INT,name VARCHAR(50),building_type VARCHAR(50),year_built INT);CREATE TABLE Units (unit_id INT,building_id INT,square_footage INT);
|
SELECT b.building_type, b.name, b.year_built, MAX(u.square_footage) - MIN(u.square_footage) as square_footage_difference FROM Units u JOIN Buildings b ON u.building_id = b.building_id GROUP BY b.building_type, b.name, b.year_built ORDER BY b.building_type, square_footage_difference;
|
What is the total budget for AI projects in all sectors?
|
CREATE TABLE ai_projects (sector VARCHAR(20),budget INT); INSERT INTO ai_projects (sector,budget) VALUES ('Education',200000),('Healthcare',500000),('Finance',1000000),('Technology',300000);
|
SELECT SUM(budget) FROM ai_projects;
|
What is the total revenue by food category for a specific restaurant in March 2021?
|
CREATE TABLE restaurant (restaurant_id INT,name TEXT); CREATE TABLE menu (menu_id INT,restaurant_id INT,food_category TEXT,price DECIMAL(5,2)); INSERT INTO restaurant (restaurant_id,name) VALUES (1,'Restaurant A'); INSERT INTO menu (menu_id,restaurant_id,food_category,price) VALUES (1,1,'Appetizers',7.99),(2,1,'Entrees',14.99),(3,1,'Desserts',6.50);
|
SELECT m.food_category, SUM(m.price) AS total_revenue FROM menu m JOIN restaurant r ON m.restaurant_id = r.restaurant_id WHERE r.name = 'Restaurant A' AND m.food_category IS NOT NULL AND m.price > 0 AND EXTRACT(MONTH FROM m.order_date) = 3 AND EXTRACT(YEAR FROM m.order_date) = 2021 GROUP BY m.food_category;
|
Identify the number of public transit users in Tokyo by train line.
|
CREATE TABLE train_ridership (user_id INT,trip_date DATE,trip_train_line VARCHAR(20)); INSERT INTO train_ridership (user_id,trip_date,trip_train_line) VALUES (1,'2022-03-01','Yamanote'),(2,'2022-03-01','Chuo');
|
SELECT trip_train_line, COUNT(DISTINCT user_id) AS unique_users FROM train_ridership GROUP BY trip_train_line;
|
What is the minimum investment in healthcare initiatives by female investors?
|
CREATE TABLE investors (id INT,gender VARCHAR(50),investments INT); INSERT INTO investors (id,gender,investments) VALUES (1,'Female',3),(2,'Male',2),(3,'Female',4),(4,'Male',5); CREATE TABLE investments (id INT,investor_id INT,sector VARCHAR(50),amount FLOAT); INSERT INTO investments (id,investor_id,sector,amount) VALUES (1,1,'Healthcare',100000),(2,1,'Education',150000),(3,2,'Healthcare',120000),(4,3,'Healthcare',175000),(5,3,'Renewable Energy',200000),(6,4,'Education',250000);
|
SELECT MIN(i.amount) as min_investment FROM investments i JOIN investors j ON i.investor_id = j.id WHERE j.gender = 'Female' AND i.sector = 'Healthcare';
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.