instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the number of new customers acquired each month in 2022? | CREATE TABLE customer_activity (activity_id INT,customer_id INT,activity_date DATE); INSERT INTO customer_activity (activity_id,customer_id,activity_date) VALUES (1,1,'2022-01-01'),(2,2,'2022-01-05'),(3,3,'2022-01-10'),(4,4,'2022-02-01'),(5,5,'2022-02-05'),(6,6,'2022-03-01'),(7,7,'2022-03-05'),(8,8,'2022-04-01'),(9,9,'2022-04-05'); | SELECT EXTRACT(MONTH FROM activity_date) AS month, COUNT(DISTINCT customer_id) AS new_customers FROM customer_activity WHERE EXTRACT(YEAR FROM activity_date) = 2022 GROUP BY month; |
What is the minimum price of ethical AI solutions developed by companies in Asia? | CREATE TABLE AI (id INT,solution VARCHAR(50),company VARCHAR(50),price DECIMAL(5,2),region VARCHAR(50)); INSERT INTO AI (id,solution,company,price,region) VALUES (1,'Ethical AI Algorithm','Fair Tech',2000.00,'Asia'),(2,'Transparent AI Model','Trustworthy Tech',3000.00,'Asia'),(3,'Bias-free AI System','Equal Tech',1500.00,'Asia'); | SELECT MIN(price) FROM AI WHERE region = 'Asia' AND solution LIKE '%ethical%'; |
Update the description of the design standard with id 1 to 'Standard for designing highways in North America' | CREATE TABLE design_standards (id INT PRIMARY KEY,standard_name VARCHAR(255),description TEXT,region VARCHAR(255)); INSERT INTO design_standards (id,standard_name,description,region) VALUES (1,'Highway Design Standard','Standard for designing highways','North America'); INSERT INTO design_standards (id,standard_name,description,region) VALUES (2,'Railway Design Standard','Standard for designing railways','Europe'); | UPDATE design_standards SET description = 'Standard for designing highways in North America' WHERE id = 1; |
Find the total revenue for concerts in Asia. | CREATE TABLE concerts (id INT,artist_id INT,location TEXT,price DECIMAL); | SELECT SUM(price) FROM concerts WHERE location LIKE '%Asia%'; |
How many public parks were opened in 2021 in regions with a population greater than 5 million? | CREATE TABLE Parks(Year INT,Region VARCHAR(20),Status VARCHAR(20)); INSERT INTO Parks(Year,Region,Status) VALUES (2018,'Region A','Opened'),(2018,'Region B','Closed'),(2019,'Region A','Opened'),(2019,'Region B','Opened'),(2020,'Region A','Opened'),(2020,'Region B','Closed'),(2021,'Region A','Opened'),(2021,'Region B','Opened'),(2021,'Region C','Opened'); CREATE TABLE Population(Region VARCHAR(20),Population INT); INSERT INTO Population(Region,Population) VALUES ('Region A',6000000),('Region B',4000000),('Region C',8000000); | SELECT COUNT(*) FROM Parks, Population WHERE Parks.Year = 2021 AND Parks.Region = Population.Region AND Population.Population > 5000000 AND Parks.Status = 'Opened'; |
What is the number of marine species with a vulnerable or endangered conservation status in the Caribbean? | CREATE TABLE species_conservation_status (id INT,name VARCHAR(255),status VARCHAR(255),location VARCHAR(255)); | SELECT COUNT(*) FROM species_conservation_status WHERE status IN ('Vulnerable', 'Endangered') AND location = 'Caribbean'; |
What is the sum of production in 'FieldI' for the second half of 2021? | CREATE TABLE wells (well_id varchar(10),field varchar(10),production int,datetime date); INSERT INTO wells (well_id,field,production,datetime) VALUES ('W011','FieldI',1200,'2021-07-01'),('W012','FieldI',1400,'2021-08-01'); | SELECT SUM(production) FROM wells WHERE field = 'FieldI' AND YEAR(datetime) = 2021 AND MONTH(datetime) >= 7 AND MONTH(datetime) <= 12; |
What is the maximum donation amount per volunteer? | CREATE TABLE volunteers (id INT,name TEXT,donation FLOAT); INSERT INTO volunteers (id,name,donation) VALUES (1,'John Doe',50.00),(2,'Jane Smith',100.00),(3,'Alice Johnson',25.00); | SELECT name, MAX(donation) FROM volunteers GROUP BY name; |
Find the number of publications by female faculty members in the Computer Science department for the last 3 years. | CREATE TABLE faculty (faculty_id INT,faculty_name VARCHAR(255),faculty_gender VARCHAR(10),faculty_department VARCHAR(255)); CREATE TABLE publications (publication_id INT,faculty_id INT,publication_title VARCHAR(255),publication_date DATE); | SELECT COUNT(*) FROM faculty f INNER JOIN publications p ON f.faculty_id = p.faculty_id WHERE f.faculty_gender = 'Female' AND f.faculty_department = 'Computer Science' AND p.publication_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 YEAR); |
What is the total revenue for each menu category in the last month? | CREATE TABLE menus (menu_category VARCHAR(255),revenue DECIMAL(10,2),order_date DATE); INSERT INTO menus VALUES ('Appetizers',5000.00,'2022-01-01'),('Entrees',12000.00,'2022-01-03'),('Desserts',6000.00,'2022-01-02'); | SELECT menu_category, SUM(revenue) FROM menus WHERE order_date >= DATEADD(month, -1, GETDATE()) GROUP BY menu_category; |
What is the total funding received by organizations that have implemented technology for social good initiatives, broken down by the type of funding (government or private)? | CREATE TABLE funding (funding_id INT,org_id INT,amount INT,funding_type VARCHAR(50)); INSERT INTO funding (funding_id,org_id,amount,funding_type) VALUES (1,1,100000,'government'),(2,1,200000,'private'),(3,2,150000,'private'),(4,3,50000,'government'); CREATE TABLE organizations (org_id INT,name VARCHAR(50),implemented_social_good BOOLEAN); INSERT INTO organizations (org_id,name,implemented_social_good) VALUES (1,'Social Good Inc.',TRUE),(2,'Private Social Impact',TRUE),(3,'Government Social Program',TRUE),(4,'Non-profit Social',FALSE); | SELECT implemented_social_good, funding_type, SUM(amount) FROM funding INNER JOIN organizations ON funding.org_id = organizations.org_id GROUP BY implemented_social_good, funding_type; |
How many accessible technology projects were launched in each year in Asia? | CREATE TABLE AccessibleTech (project_id INT,launch_date DATE,location VARCHAR(20)); INSERT INTO AccessibleTech (project_id,launch_date,location) VALUES (1,'2005-02-17','Asia'),(2,'2007-11-09','Asia'),(3,'2009-06-23','Asia'),(4,'2011-08-04','Asia'),(5,'2013-01-15','Asia'),(6,'2015-07-01','Asia'),(7,'2017-02-20','Asia'),(8,'2019-09-01','Asia'); | SELECT YEAR(launch_date) AS year, COUNT(*) AS project_count FROM AccessibleTech WHERE location = 'Asia' GROUP BY year ORDER BY year; |
What is the total amount donated to projects in the technology sector, in descending order? | CREATE TABLE donors (donor_id INT,name TEXT);CREATE TABLE projects (project_id INT,name TEXT,sector TEXT);CREATE TABLE donations (donation_id INT,donor_id INT,project_id INT,amount FLOAT);INSERT INTO donors VALUES (1,'Ivan Black'),(2,'Julia White'),(3,'Karen Gray'),(4,'Luke Brown');INSERT INTO projects VALUES (1,'AI Research','technology'),(2,'Machine Learning','technology'),(3,'Physics Lab','science'),(4,'Art Studio','arts');INSERT INTO donations VALUES (1,1,1,1000.00),(2,1,2,2000.00),(3,2,1,3000.00),(4,2,2,4000.00),(5,3,3,5000.00),(6,3,4,6000.00),(7,4,1,7000.00),(8,4,2,8000.00); | SELECT SUM(donations.amount) as total_donated_tech FROM donations INNER JOIN projects ON donations.project_id = projects.project_id WHERE projects.sector = 'technology' GROUP BY projects.sector ORDER BY total_donated_tech DESC; |
What was the total revenue for each team's merchandise sales in 2021? | CREATE TABLE teams (id INT,name VARCHAR(255)); INSERT INTO teams (id,name) VALUES (1,'TeamA'),(2,'TeamB'); CREATE TABLE merchandise_sales (team_id INT,year INT,revenue DECIMAL(10,2)); | SELECT t.name, SUM(m.revenue) as total_revenue FROM merchandise_sales m JOIN teams t ON m.team_id = t.id WHERE m.year = 2021 GROUP BY t.name; |
What is the average health equity metric assessment score by community health worker? | CREATE TABLE if not exists health_equity_metric_assessments (assessment_id INT,worker_id INT,score INT); INSERT INTO health_equity_metric_assessments (assessment_id,worker_id,score) VALUES (1,1,90),(2,1,85),(3,2,95),(4,3,80); | SELECT AVG(score), worker_id FROM health_equity_metric_assessments GROUP BY worker_id; |
What is the average donation amount per attendee by state, sorted by the highest average donation? | CREATE TABLE Attendees (ID INT,AttendeeName TEXT,State TEXT); INSERT INTO Attendees (ID,AttendeeName,State) VALUES (1,'Jane Doe','California'),(2,'John Smith','New York'),(3,'Alice Johnson','Texas'); CREATE TABLE Donations (ID INT,AttendeeID INT,DonationAmount DECIMAL(10,2),DonationDate DATE); INSERT INTO Donations (ID,AttendeeID,DonationAmount,DonationDate) VALUES (1,1,100.00,'2022-01-01'),(2,2,200.00,'2022-02-01'),(3,3,150.00,'2022-03-01'),(4,1,50.00,'2022-04-01'); | SELECT State, AVG(DonationAmount) as AvgDonation, ROW_NUMBER() OVER (ORDER BY AVG(DonationAmount) DESC) as Rank FROM Donations JOIN Attendees ON Donations.AttendeeID = Attendees.ID GROUP BY State ORDER BY Rank; |
What is the total production of rice in India in the year 2020? | CREATE TABLE Production (id INT PRIMARY KEY,crop VARCHAR(50),country VARCHAR(50),year INT,quantity INT); INSERT INTO Production (id,crop,country,year,quantity) VALUES (1,'Rice','India',2019,15000000); INSERT INTO Production (id,crop,country,year,quantity) VALUES (2,'Rice','India',2020,16000000); INSERT INTO Production (id,crop,country,year,quantity) VALUES (3,'Wheat','China',2020,13000000); | SELECT SUM(quantity) FROM Production WHERE crop = 'Rice' AND country = 'India' AND year = 2020; |
What is the total number of hours of educational content consumed by users from rural areas? | CREATE TABLE user_profiles (user_id INT,user_location VARCHAR(20)); CREATE TABLE content_views (view_id INT,user_id INT,content_id INT,view_date DATE,content_type VARCHAR(20),content_length INT); | SELECT SUM(content_length / 60) as total_hours FROM content_views JOIN user_profiles ON content_views.user_id = user_profiles.user_id WHERE content_type = 'educational' AND user_profiles.user_location = 'rural'; |
List the top 3 countries with the highest quantity of CO2 emissions in the textile industry. | CREATE TABLE co2_emissions (id INT PRIMARY KEY,country VARCHAR(50),industry_type VARCHAR(50),co2_emissions FLOAT); INSERT INTO co2_emissions (id,country,industry_type,co2_emissions) VALUES (1,'China','Textile',12000.00),(2,'India','Textile',8000.00),(3,'United States','Textile',6000.00),(4,'Indonesia','Textile',4000.00),(5,'Bangladesh','Textile',3000.00); | SELECT country, SUM(co2_emissions) as total_emissions FROM co2_emissions WHERE industry_type = 'Textile' GROUP BY country ORDER BY total_emissions DESC LIMIT 3; |
Who are the top 2 external threat actors by number of successful attacks in the last 6 months? | CREATE TABLE threat_actors (id INT,actor_name VARCHAR(255),actor_type VARCHAR(255)); INSERT INTO threat_actors (id,actor_name,actor_type) VALUES (1,'Nation-state Actor 1','nation-state'),(2,'Cybercriminal Group 1','cybercriminal'),(3,'Hacktivist Group 1','hacktivist'),(4,'Nation-state Actor 2','nation-state'),(5,'Cybercriminal Group 2','cybercriminal'); CREATE TABLE attack_results (id INT,attack_id INT,actor_id INT,success BOOLEAN); INSERT INTO attack_results (id,attack_id,actor_id,success) VALUES (1,111,1,true),(2,222,2,false),(3,333,3,true),(4,444,4,true),(5,555,5,false); | SELECT actor_id, COUNT(*) as successful_attacks FROM attack_results WHERE success = true AND timestamp >= DATE_SUB(NOW(), INTERVAL 6 MONTH) GROUP BY actor_id ORDER BY successful_attacks DESC LIMIT 2; |
Show the community development initiatives with their respective start and end dates. | CREATE TABLE community_dev (id INT,initiative_name VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO community_dev (id,initiative_name,start_date,end_date) VALUES (1,'Education Program','2020-01-01','2022-12-31'),(2,'Health Care Center','2019-07-01','2024-06-30'); | SELECT initiative_name, start_date, end_date FROM community_dev; |
What is the maximum support duration for each location? | CREATE TABLE If Not Exists refugee_support (supporter_id INT,supporter_name TEXT,location TEXT,support_duration INT); INSERT INTO refugee_support (supporter_id,supporter_name,location,support_duration) VALUES (4,'Alex Johnson','Afghanistan',75),(5,'Sophia Lee','Pakistan',50); | SELECT location, MAX(support_duration) as max_support_duration FROM refugee_support GROUP BY location; |
What is the total revenue generated from concerts for artist 'Ariana Grande' in Germany? | CREATE TABLE Concerts (id INT,artist VARCHAR(100),country VARCHAR(100),price DECIMAL(5,2),tickets INT); INSERT INTO Concerts (id,artist,country,price,tickets) VALUES (1,'Ariana Grande','Germany',120.00,15000),(2,'Ariana Grande','Germany',150.00,20000); | SELECT SUM(price*tickets) FROM Concerts WHERE artist = 'Ariana Grande' AND country = 'Germany' |
What is the total number of international visitors to Japan per month in the year 2022? | CREATE TABLE visitors (visitor_id INT,visit_date DATE,destination TEXT); INSERT INTO visitors (visitor_id,visit_date,destination) VALUES (1,'2022-01-15','Japan'),(2,'2022-02-20','Japan'),(3,'2022-03-05','Japan'),(4,'2022-04-12','Japan'),(5,'2022-05-28','Japan'); | SELECT EXTRACT(MONTH FROM visit_date) AS month, COUNT(*) AS visitors FROM visitors WHERE destination = 'Japan' AND visit_date BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY month; |
Which districts in Texas have more than 500,000 residents? | CREATE TABLE districts (id INT,name VARCHAR(50),state VARCHAR(20),population INT); INSERT INTO districts (id,name,state,population) VALUES (1,'District 1','Texas',600000); INSERT INTO districts (id,name,state,population) VALUES (2,'District 2','Texas',450000); | SELECT name FROM districts WHERE population > 500000 AND state = 'Texas'; |
How many military bases are present in South Korea? | CREATE TABLE MilitaryBases (ID INT,Country VARCHAR(20),Quantity INT); INSERT INTO MilitaryBases (ID,Country,Quantity) VALUES (1,'South Korea',58); | SELECT Quantity FROM MilitaryBases WHERE Country = 'South Korea'; |
What is the total CO2 emission of the 'East Coast' plant in 2021? | CREATE TABLE emissions (plant varchar(10),year int,co2_emission int); INSERT INTO emissions (plant,year,co2_emission) VALUES ('East Plant',2020,1200),('East Plant',2021,1500),('West Plant',2020,1800),('West Plant',2021,1900); | SELECT SUM(co2_emission) FROM emissions WHERE plant = 'East Plant' AND year = 2021; |
What is the average temperature and dissolved oxygen level for each species of fish in the aquaculture facility in the last 30 days? | CREATE TABLE fish_species (id INT,species TEXT,dissolved_oxygen_tolerance FLOAT);CREATE TABLE temperature_readings (id INT,species TEXT,date DATE,temperature FLOAT,dissolved_oxygen FLOAT); | SELECT species, AVG(temperature) AS avg_temperature, AVG(dissolved_oxygen) AS avg_dissolved_oxygen FROM temperature_readings tr JOIN fish_species fs ON tr.species = fs.species WHERE date >= (CURRENT_DATE - INTERVAL '30 days') GROUP BY species; |
How many startups have had an exit strategy of IPO in each country? | CREATE TABLE startup (id INT,name TEXT,country TEXT,exit_strategy TEXT); INSERT INTO startup (id,name,country,exit_strategy) VALUES (1,'Omicron Enterprises','USA','IPO'); INSERT INTO startup (id,name,country,exit_strategy) VALUES (2,'Pi Inc','Canada','Acquisition'); INSERT INTO startup (id,name,country,exit_strategy) VALUES (3,'Rho Ltd','Mexico','IPO'); | SELECT s.country, COUNT(*) FROM startup s WHERE s.exit_strategy = 'IPO' GROUP BY s.country; |
List all the broadband customers who have not opted for a plan with a speed greater than 100 Mbps. | CREATE TABLE broadband_customers (customer_id INT,speed FLOAT); INSERT INTO broadband_customers (customer_id,speed) VALUES (1,50),(2,150),(3,75); | SELECT * FROM broadband_customers WHERE speed <= 100; |
What is the maximum number of peacekeeping operations conducted by each country in 2019? | CREATE TABLE PeacekeepingOperationsByCountry (Year INT,Country VARCHAR(50),Operations INT); INSERT INTO PeacekeepingOperationsByCountry (Year,Country,Operations) VALUES (2019,'Country A',3),(2019,'Country B',5),(2019,'Country C',7); | SELECT Country, MAX(Operations) FROM PeacekeepingOperationsByCountry WHERE Year = 2019 GROUP BY Country; |
What is the total data usage for all customers? | CREATE TABLE total_usage (id INT,name VARCHAR(50),data_usage FLOAT); INSERT INTO total_usage (id,name,data_usage) VALUES (1,'John Doe',15.0); | SELECT SUM(data_usage) FROM total_usage; |
What is the maximum quantity of any single dish sold in a day? | CREATE TABLE orders (order_id INT,order_date DATE,menu_id INT,quantity INT); INSERT INTO orders (order_id,order_date,menu_id,quantity) VALUES (1,'2022-01-03',1,3),(2,'2022-01-03',2,2),(3,'2022-01-05',3,1),(4,'2022-01-05',1,5); | SELECT MAX(quantity) FROM orders; |
What is the maximum carbon sequestration amount before 2022? | CREATE TABLE carbon_sequestration (id INT,year INT,amount FLOAT); INSERT INTO carbon_sequestration (id,year,amount) VALUES (1,2020,500.3),(2,2021,700.5),(3,2022,800.2); | SELECT MAX(amount) FROM carbon_sequestration WHERE year < 2022; |
What is the total funding received by all biotech startups in the Bay Area? | CREATE SCHEMA if not exists biotech;CREATE TABLE if not exists biotech.startups (id INT PRIMARY KEY,name VARCHAR(100),location VARCHAR(100),funding FLOAT); INSERT INTO biotech.startups (id,name,location,funding) VALUES (1,'StartupA','San Francisco',15000000.0),(2,'StartupB','San Jose',12000000.0),(3,'StartupC','Oakland',13000000.0); | SELECT SUM(funding) FROM biotech.startups WHERE location = 'Bay Area'; |
How many space missions were successfully completed by each space agency between 2015 and 2020? | CREATE TABLE space_missions (mission_id INT,agency VARCHAR(50),launch_year INT,mission_status VARCHAR(50)); INSERT INTO space_missions (mission_id,agency,launch_year,mission_status) VALUES (1,'NASA',2015,'Success'),(2,'ESA',2016,'Failure'),(3,'ISRO',2017,'Success'),(4,'JAXA',2018,'Success'),(5,'CNSA',2019,'Success'),(6,'Roscosmos',2020,'Success'); | SELECT agency, COUNT(*) as successful_missions FROM space_missions WHERE launch_year BETWEEN 2015 AND 2020 AND mission_status = 'Success' GROUP BY agency; |
What is the minimum data usage in gigabytes per month for customers in the state of Texas? | CREATE TABLE customers_usa (customer_id INT,name VARCHAR(255),state VARCHAR(255)); INSERT INTO customers_usa (customer_id,name,state) VALUES (1,'John Doe','California'),(2,'Jane Smith','Texas'); CREATE TABLE data_usage_usa (customer_id INT,monthly_data_usage DECIMAL(10,2)); INSERT INTO data_usage_usa (customer_id,monthly_data_usage) VALUES (1,10.5),(2,15.6),(3,8.7); | SELECT MIN(monthly_data_usage) FROM data_usage_usa INNER JOIN customers_usa ON data_usage_usa.customer_id = customers_usa.customer_id WHERE state = 'Texas'; |
What is the total number of permits issued for residential buildings in the city of Seattle in 2020? | CREATE TABLE building_permits (permit_id INT,building_type VARCHAR(50),city VARCHAR(50),issue_date DATE); INSERT INTO building_permits (permit_id,building_type,city,issue_date) VALUES (1,'Residential','Seattle','2020-01-01'); INSERT INTO building_permits (permit_id,building_type,city,issue_date) VALUES (2,'Residential','Seattle','2020-02-01'); | SELECT COUNT(*) FROM building_permits WHERE building_type = 'Residential' AND city = 'Seattle' AND YEAR(issue_date) = 2020; |
What is the total number of hours volunteered in all programs? | CREATE TABLE volunteers (id INT,name TEXT,program TEXT,hours INT); INSERT INTO volunteers (id,name,program,hours) VALUES (1,'John Doe','Food Distribution',10),(2,'Jane Smith','Education Support',20); | SELECT SUM(hours) FROM volunteers; |
What is the average number of virtual tours taken per user in 'Asia'? | CREATE TABLE user_activity (id INT,user_id INT,virtual_tour_id INT,country TEXT); INSERT INTO user_activity (id,user_id,virtual_tour_id,country) VALUES (1,1,1,'Japan'),(2,1,2,'China'),(3,2,3,'South Korea'),(4,2,4,'India'); CREATE TABLE virtual_tours (id INT,name TEXT,country TEXT); INSERT INTO virtual_tours (id,name,country) VALUES (1,'Tokyo Tower','Japan'),(2,'Great Wall of China','China'),(3,'Seoul Tower','South Korea'),(4,'Taj Mahal','India'); | SELECT AVG(number_of_tours) FROM (SELECT user_id, COUNT(DISTINCT virtual_tour_id) as number_of_tours FROM user_activity WHERE country = 'Asia' GROUP BY user_id) as user_tours; |
How many professional development courses were completed by teachers in each role? | CREATE TABLE roles (role_id INT,role VARCHAR(20),teacher_id INT,course_completed INT); INSERT INTO roles (role_id,role,teacher_id,course_completed) VALUES (1,'Teacher',1,3),(2,'Assistant Teacher',2,5),(3,'Teacher',3,4),(4,'Teacher',4,2),(5,'Assistant Teacher',5,1); | SELECT role, SUM(course_completed) as total_courses FROM roles GROUP BY role; |
List the names and dates of weather records in 'Paris'. | CREATE TABLE weather (id INT PRIMARY KEY,temperature DECIMAL(3,1),precipitation DECIMAL(3,1),date DATE,location VARCHAR(50)); INSERT INTO weather (id,temperature,precipitation,date,location) VALUES (3,65.4,0.0,'2021-11-01','Paris'); | SELECT date, location FROM weather WHERE location = 'Paris'; |
Show the number of employees and their roles in each department for the mining company 'LMN Mining'. | CREATE TABLE MiningCompany (id INT,name VARCHAR(255)); INSERT INTO MiningCompany (id,name) VALUES (1,'ABC Mining'),(2,'LMN Mining'); CREATE TABLE MiningDepartment (id INT,name VARCHAR(255)); INSERT INTO MiningDepartment (id,name) VALUES (1,'Mining Operations'),(2,'Maintenance'),(3,'Safety'); CREATE TABLE Employee (id INT,name VARCHAR(255),department_id INT,role VARCHAR(255),company_id INT); INSERT INTO Employee (id,name,department_id,role,company_id) VALUES (1,'John Smith',1,'Mining Engineer',2),(2,'Jane Doe',2,'Mechanic',2); | SELECT d.name AS department, e.role, COUNT(e.id) AS employee_count FROM Employee e, MiningDepartment d, MiningCompany mc WHERE e.department_id = d.id AND e.company_id = mc.id AND mc.name = 'LMN Mining' GROUP BY e.role; |
What was the total donation amount by individuals in Canada in Q1 2021? | CREATE TABLE Donations (id INT,donor_name VARCHAR(255),donation_amount DECIMAL(10,2),donation_date DATE); INSERT INTO Donations (id,donor_name,donation_amount,donation_date) VALUES (1,'John Smith',50.00,'2021-01-10'),(2,'Emily Johnson',75.00,'2021-03-15'); | SELECT SUM(donation_amount) FROM Donations WHERE donor_name NOT LIKE '%org%' AND donation_date BETWEEN '2021-01-01' AND '2021-03-31'; |
Update the safety scores of vessels that have a historical non-compliance record. | CREATE TABLE Vessels (VesselID INT,VesselName TEXT,SafetyScore INT,NonCompliance TEXT); INSERT INTO Vessels (VesselID,VesselName,SafetyScore,NonCompliance) VALUES (1,'Vessel1',85,'Yes'),(2,'Vessel2',92,'No'),(3,'Vessel3',78,'Yes'); | UPDATE Vessels SET SafetyScore = SafetyScore - 10 WHERE NonCompliance = 'Yes'; |
What is the total fare collected for a specific bus route in Mexico City? | CREATE TABLE bus_routes (route_id INT,city VARCHAR(50),fare DECIMAL(5,2)); INSERT INTO bus_routes (route_id,city,fare) VALUES (1,'Mexico City',4.50),(2,'Mexico City',3.20),(3,'Mexico City',5.00); CREATE TABLE fares_collected (route_id INT,fare DECIMAL(5,2)); INSERT INTO fares_collected (route_id,fare) VALUES (1,100.00),(1,150.00),(2,75.00),(3,125.00); | SELECT SUM(fares_collected.fare) FROM fares_collected INNER JOIN bus_routes ON fares_collected.route_id = bus_routes.route_id WHERE city = 'Mexico City' AND bus_routes.route_id = 1; |
Find the number of endangered species in the 'endangered_animals' view | CREATE TABLE animals (id INT,name VARCHAR(255),conservation_status VARCHAR(255)); INSERT INTO animals (id,name,conservation_status) VALUES (1,'Black Rhino','Endangered'),(2,'Giant Panda','Vulnerable'),(3,'Mountain Gorilla','Endangered'),(4,'Tiger','Endangered'),(5,'Asian Elephant','Endangered'); CREATE VIEW endangered_animals AS SELECT * FROM animals WHERE conservation_status = 'Endangered'; | SELECT COUNT(*) FROM endangered_animals; |
Update policy records with coverage amounts greater than $75000 to have a coverage amount of $75000 for policyholders who are members of the LGBTQ+ community. | CREATE TABLE Policies (PolicyNumber VARCHAR(20),CoverageAmount INT,PolicyholderName VARCHAR(50)); INSERT INTO Policies (PolicyNumber,CoverageAmount,PolicyholderName) VALUES ('P001',50000,'John Doe'); CREATE TABLE Policyholders (PolicyNumber VARCHAR(20),Community VARCHAR(50)); INSERT INTO Policyholders (PolicyNumber,Community) VALUES ('P001','LGBTQ+'); | UPDATE Policies SET CoverageAmount = 75000 WHERE CoverageAmount > 75000 AND PolicyNumber IN (SELECT p.PolicyNumber FROM Policies p INNER JOIN Policyholders ph ON p.PolicyholderName = ph.PolicyholderName WHERE ph.Community = 'LGBTQ+'); |
What is the average number of vehicles per household in 'household_data' table? | CREATE TABLE household_data (id INT,city VARCHAR(25),vehicles INT,households INT); | SELECT AVG(vehicles / NULLIF(households, 0)) FROM household_data; |
What is the total number of volunteers and total hours they have contributed, by region, for the current year? | CREATE TABLE volunteers (volunteer_id INT,region VARCHAR(50),total_hours INT); INSERT INTO volunteers (volunteer_id,region,total_hours) VALUES (1,'North',500),(2,'South',300),(3,'East',700),(4,'West',200); | SELECT region, SUM(total_hours) as total_hours, COUNT(*) as total_volunteers FROM volunteers WHERE YEAR(donation_date) = YEAR(GETDATE()) GROUP BY region; |
Number of public libraries in each state of the USA. | CREATE TABLE libraries (id INT,name VARCHAR(50),state VARCHAR(50),country VARCHAR(50)); INSERT INTO libraries (id,name,state,country) VALUES (1,'New York Public Library','New York','USA'),(2,'Los Angeles Public Library','California','USA'),(3,'Chicago Public Library','Illinois','USA'),(4,'Houston Public Library','Texas','USA'),(5,'Phoenix Public Library','Arizona','USA'),(6,'Philadelphia Public Library','Pennsylvania','USA'),(7,'San Antonio Public Library','Texas','USA'); | SELECT state, COUNT(*) FROM libraries WHERE country = 'USA' GROUP BY state; |
What is the average hydro power generation in Nigeria and Kenya between 2022-01-01 and 2022-12-31? | CREATE TABLE hydro_power (date DATE,location VARCHAR(255),hydro_power_generation FLOAT); INSERT INTO hydro_power (date,location,hydro_power_generation) VALUES ('2022-01-01','Nigeria',1200),('2022-01-01','Kenya',1800); | SELECT location, AVG(hydro_power_generation) as avg_hydro_power_generation FROM hydro_power WHERE date BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY location; |
Which programs have a budget greater than the average budget and are currently active? | CREATE TABLE Programs (ProgramID INT PRIMARY KEY,ProgramName VARCHAR(30),ProgramCost DECIMAL(5,2),ProgramStartDate DATE,ProgramEndDate DATE); INSERT INTO Programs (ProgramID,ProgramName,ProgramCost,ProgramStartDate,ProgramEndDate) VALUES (27,'Education Program',12000.00,'2021-07-01','2023-06-30'),(28,'Healthcare Program',15000.00,'2020-04-01','2022-03-31'),(29,'Disaster Relief Program',20000.00,'2022-01-01','2024-12-31'),(30,'Food Security Program',10000.00,'2022-06-01','2024-05-31'); | SELECT ProgramName, ProgramCost FROM Programs WHERE ProgramCost > (SELECT AVG(ProgramCost) FROM Programs) AND ProgramStartDate <= CURDATE() AND ProgramEndDate >= CURDATE(); |
Add new players to the players table? | CREATE TABLE players (id INT,name VARCHAR(100),country VARCHAR(100)); INSERT INTO players (id,name,country) VALUES (1,'John Doe','USA'),(2,'Jane Smith','USA'),(3,'Alex Brown','Canada'); | INSERT INTO players (id, name, country) VALUES (4, 'Jackie Chan', 'China'), (5, 'Sophia Gonzalez', 'Mexico'), (6, 'Kim Lee', 'South Korea'); |
What is the total number of cultural competency training sessions by age group? | CREATE TABLE cultural_competency_training (age_group VARCHAR(255),sessions INT); INSERT INTO cultural_competency_training (age_group,sessions) VALUES ('Under 18',100),('18-30',200),('31-50',300),('Over 50',400); | SELECT age_group, SUM(sessions) FROM cultural_competency_training GROUP BY age_group; |
Find AI models that have higher explainability scores in the creative AI domain compared to the algorithmic fairness domain. | CREATE TABLE ai_models (model_name TEXT,explainability_score INTEGER,domain TEXT); INSERT INTO ai_models (model_name,explainability_score,domain) VALUES ('ModelA',85,'Algorithmic Fairness'),('ModelB',90,'Creative AI'),('ModelC',80,'Algorithmic Fairness'); | SELECT domain, AVG(explainability_score) FROM ai_models WHERE domain IN ('Algorithmic Fairness', 'Creative AI') GROUP BY domain; |
Insert a new vegan and cruelty-free cosmetic brand from India. | CREATE TABLE Brands (BrandID INT,BrandName VARCHAR(50),Country VARCHAR(50),IsVegan BOOLEAN,IsCrueltyFree BOOLEAN); INSERT INTO Brands (BrandID,BrandName,Country,IsVegan,IsCrueltyFree) VALUES (1,'Lush','UK',true,true),(2,'The Body Shop','UK',true,true),(3,'Burt''s Bees','USA',true,true); | INSERT INTO Brands (BrandID, BrandName, Country, IsVegan, IsCrueltyFree) VALUES (4, 'Kama Ayurveda', 'India', true, true); |
Update the email of the donor with ID 3 to 'new_email@example.com' | CREATE TABLE Donors (ID INT PRIMARY KEY,Name TEXT,Email TEXT); | UPDATE Donors SET Email = 'new_email@example.com' WHERE ID = 3; |
Identify the health equity metrics that have been measured in the past six months and their respective measurement dates for the South region. | CREATE TABLE Health_Equity_Metrics_By_Region (Metric_ID INT,Metric_Name VARCHAR(255),Measurement_Date DATE,Region VARCHAR(255)); INSERT INTO Health_Equity_Metrics_By_Region (Metric_ID,Metric_Name,Measurement_Date,Region) VALUES (1,'Access to Care','2022-03-01','South'),(2,'Quality of Care','2022-02-15','North'); | SELECT Metric_Name, Measurement_Date FROM Health_Equity_Metrics_By_Region WHERE Region = 'South' AND Measurement_Date >= DATEADD(month, -6, GETDATE()); |
What is the count of community health workers by gender in California? | CREATE TABLE community_health_workers (worker_id INT,name TEXT,gender TEXT,state TEXT); INSERT INTO community_health_workers (worker_id,name,gender,state) VALUES (1,'Alex','Male','CA'),(2,'Bella','Female','CA'),(3,'Chris','Non-binary','NY'),(4,'Danny','Male','CA'); | SELECT state, gender, COUNT(*) FROM community_health_workers WHERE state = 'CA' GROUP BY state, gender; |
What is the total number of aircraft maintained by each contractor in Q2 2021? | CREATE TABLE AircraftMaintenance (id INT,contractor VARCHAR(255),quarter INT,aircraft INT); INSERT INTO AircraftMaintenance (id,contractor,quarter,aircraft) VALUES (1,'Global Defence',2,30),(2,'AeroTech',2,40),(3,'Military Avionics',3,50),(4,'Global Defence',3,60),(5,'AeroTech',3,70); | SELECT contractor, SUM(aircraft) FROM AircraftMaintenance WHERE quarter = 2 GROUP BY contractor; |
What is the number of male visitors to the 'Digital Art' exhibition? | CREATE TABLE Exhibitions (exhibition_id INT,exhibition_name VARCHAR(255)); INSERT INTO Exhibitions (exhibition_id,exhibition_name) VALUES (1,'Digital Art'); CREATE TABLE Visitors (visitor_id INT,exhibition_id INT,age INT,gender VARCHAR(50)); INSERT INTO Visitors (visitor_id,exhibition_id,age,gender) VALUES (1,1,28,'Male'),(2,1,30,'Female'),(3,1,25,'Male'); | SELECT COUNT(*) FROM Visitors WHERE exhibition_id = 1 AND gender = 'Male'; |
What is the minimum age of policyholders with a home insurance policy? | CREATE TABLE policyholders (id INT,age INT,state VARCHAR(2),policy_type VARCHAR(10)); INSERT INTO policyholders (id,age,state,policy_type) VALUES (1,35,'NY','car'),(2,45,'CA','home'),(3,28,'NY','car'),(4,50,'TX','home'); | SELECT MIN(age) FROM policyholders WHERE policy_type = 'home'; |
What is the name of the runner with the second-best time in the 'marathon_results' table? | CREATE TABLE marathon_results (runner_id INT,name VARCHAR(50),time_minutes DECIMAL(4,2)); INSERT INTO marathon_results (runner_id,name,time_minutes) VALUES (1,'Eliud Kipchoge',2.01); INSERT INTO marathon_results (runner_id,name,time_minutes) VALUES (2,'Brigid Kosgei',2.14); | SELECT name FROM marathon_results WHERE time_minutes = (SELECT MIN(time_minutes) FROM marathon_results WHERE name != (SELECT MIN(name) FROM marathon_results)); |
How many male faculty members are there in the College of Arts and Humanities, and how many of them have published research in the past 2 years? | CREATE TABLE arts_faculty (faculty_id INT,faculty_gender VARCHAR(10),last_publication_date DATE,faculty_department VARCHAR(50)); INSERT INTO arts_faculty (faculty_id,faculty_gender,last_publication_date,faculty_department) VALUES (1,'Male','2021-01-01','College of Arts and Humanities'),(2,'Female','2022-06-15','College of Arts and Humanities'),(3,'Male','2020-12-31','College of Arts and Humanities'),(4,'Female','2019-05-15','College of Arts and Humanities'),(5,'Male','2021-04-01','College of Arts and Humanities'); | SELECT COUNT(*) as num_faculty, SUM(CASE WHEN last_publication_date >= DATEADD(year, -2, GETDATE()) THEN 1 ELSE 0 END) as num_published FROM arts_faculty WHERE faculty_department = 'College of Arts and Humanities' AND faculty_gender = 'Male'; |
List the top 3 favorite game genres of players aged 18-24 | CREATE TABLE Players (PlayerID INT,Age INT,FavoriteGenre VARCHAR(20)); INSERT INTO Players (PlayerID,Age,FavoriteGenre) VALUES (1,22,'RPG'),(2,19,'FPS'),(3,25,'Strategy'); | SELECT FavoriteGenre, COUNT(*) AS Count FROM Players WHERE Age BETWEEN 18 AND 24 GROUP BY FavoriteGenre ORDER BY Count DESC LIMIT 3; |
List all policies with risk assessment model scores higher than 800, ordered by score in descending order | CREATE TABLE policies (policy_id INT,policyholder_id INT,policy_start_date DATE,policy_end_date DATE); CREATE TABLE risk_assessment (risk_id INT,policy_id INT,risk_score INT); INSERT INTO policies VALUES (1,1,'2020-01-01','2021-01-01'); INSERT INTO policies VALUES (2,2,'2019-01-01','2020-01-01'); INSERT INTO risk_assessment VALUES (1,1,900); INSERT INTO risk_assessment VALUES (2,2,700); | SELECT policies.policy_id, risk_score FROM policies INNER JOIN risk_assessment USING (policy_id) WHERE risk_score > 800 ORDER BY risk_score DESC |
What are the total installed capacities (in MW) of solar farms in Spain and Italy? | CREATE TABLE solar_farm_spain (id INT,name TEXT,location TEXT,capacity_mw FLOAT); INSERT INTO solar_farm_spain (id,name,location,capacity_mw) VALUES (1,'Solana Generating Station','Spain',200.0); CREATE TABLE solar_farm_italy (id INT,name TEXT,location TEXT,capacity_mw FLOAT); INSERT INTO solar_farm_italy (id,name,location,capacity_mw) VALUES (1,'Montalto di Castro Solar Park','Italy',84.0); | SELECT SUM(capacity_mw) FROM solar_farm_spain WHERE location = 'Spain' UNION SELECT SUM(capacity_mw) FROM solar_farm_italy WHERE location = 'Italy'; |
What is the name of the exhibition with the highest visitor count? | CREATE TABLE Exhibitions (id INT,name TEXT,visitor_count INT); INSERT INTO Exhibitions (id,name,visitor_count) VALUES (1,'Dinosaurs',1000),(2,'Egypt',800); | SELECT name FROM (SELECT name, visitor_count, ROW_NUMBER() OVER (ORDER BY visitor_count DESC) as row_num FROM Exhibitions) WHERE row_num = 1; |
What are the names and countries of all AI researchers who are over the age of 40 and have published at least one research paper? | CREATE TABLE Researchers (id INT,name VARCHAR(255),age INT,country VARCHAR(255),paper VARCHAR(255)); | SELECT name, country FROM Researchers WHERE age > 40 AND paper IS NOT NULL; |
List all cities with public transportation systems that support wheelchair accessibility? | CREATE TABLE public_transportation (id INT,city VARCHAR(20),wheelchair_accessible BOOLEAN); INSERT INTO public_transportation (id,city,wheelchair_accessible) VALUES (1,'San Francisco',TRUE),(2,'New York',TRUE),(3,'Los Angeles',FALSE); | SELECT city FROM public_transportation WHERE wheelchair_accessible = TRUE; |
What is the average number of public transportation trips taken per day in the city of Los Angeles in the month of July? | CREATE TABLE DailyPublicTransportationTrips (TripID INT,StartLocation VARCHAR(50),EndLocation VARCHAR(50),TripDate DATE); INSERT INTO DailyPublicTransportationTrips (TripID,StartLocation,EndLocation,TripDate) VALUES (1,'Downtown Los Angeles','Santa Monica','2022-07-01'),(2,'Hollywood','Venice Beach','2022-07-02'),(3,'Silver Lake','Pasadena','2022-07-03'); | SELECT AVG(DailyTrips) FROM (SELECT COUNT(*) AS DailyTrips FROM DailyPublicTransportationTrips WHERE StartLocation = 'Los Angeles' AND MONTH(TripDate) = 7 GROUP BY DATE(TripDate)) AS TripsPerDay; |
What is the name and location of the first health center in Syria, ordered by center ID? | CREATE TABLE Syria (id INT,name TEXT,type TEXT,location TEXT); INSERT INTO Syria (id,name,type,location) VALUES (1,'Center A','Health','Damascus'); INSERT INTO Syria (id,name,type,location) VALUES (2,'Center B','Community','Aleppo'); INSERT INTO Syria (id,name,type,location) VALUES (3,'Center C','Health','Homs'); | SELECT name, location FROM (SELECT name, location, ROW_NUMBER() OVER (ORDER BY id) AS row_num FROM Syria WHERE type = 'Health') AS health_centers WHERE row_num = 1; |
What is the difference in mental health scores between the first and last year for each student? | CREATE TABLE student_scores_extended (student_id INT,year INT,mental_health_score INT,row_number INT); INSERT INTO student_scores_extended (student_id,year,mental_health_score,row_number) VALUES (1,2020,75,1),(1,2021,80,2),(2,2020,80,1),(2,2021,85,2); | SELECT a.student_id, (b.mental_health_score - a.mental_health_score) as difference FROM student_scores_extended a JOIN student_scores_extended b ON a.student_id = b.student_id WHERE a.row_number = 1 AND b.row_number = (SELECT MAX(row_number) FROM student_scores_extended c WHERE a.student_id = c.student_id); |
What is the average sustainability rating for hotels in 'New York'? | CREATE TABLE hotels (hotel_id INT,name VARCHAR(50),location VARCHAR(50),stars INT,sustainability_rating INT); | SELECT AVG(sustainability_rating) FROM hotels WHERE location = 'New York'; |
List the top 3 chemical products with the highest revenue in the last financial year. | CREATE TABLE sales (id INT,product VARCHAR(255),revenue FLOAT,sale_date DATE); INSERT INTO sales (id,product,revenue,sale_date) VALUES (1,'Chemical A',1200.5,'2021-03-01'),(2,'Chemical B',1500.6,'2021-06-10'),(3,'Chemical C',1800.2,'2021-09-15'); CREATE VIEW revenue_ranking AS SELECT product,SUM(revenue) as total_revenue FROM sales GROUP BY product ORDER BY total_revenue DESC; | SELECT product FROM revenue_ranking WHERE ROWNUM <= 3 |
Who is the contractor with the highest total project value in the state of Texas? | CREATE TABLE contractors (contractor_id INT,contractor_name TEXT,state TEXT,total_project_value DECIMAL); INSERT INTO contractors VALUES (1,'ABC Construction','Texas',5000000),(2,'XYZ Builders','California',7000000),(3,'123 Contracting','Texas',6000000),(4,'Easy Builders','California',6000000),(5,'Green Construction','New York',8000000); | SELECT contractor_name, total_project_value FROM contractors WHERE state = 'Texas' ORDER BY total_project_value DESC LIMIT 1; |
Increase the budget for 'Accessible Technology' program by 10% in the 'Disability Services' department. | CREATE TABLE budget (dept VARCHAR(50),program VARCHAR(50),amount INT); INSERT INTO budget (dept,program,amount) VALUES ('Disability Services','Accessible Technology',50000),('Disability Services','Sign Language Interpretation',75000),('Human Resources','Diversity Training',30000); | UPDATE budget SET amount = amount * 1.10 WHERE dept = 'Disability Services' AND program = 'Accessible Technology'; |
What is the maximum number of unsuccessful login attempts for 'guest' accounts in the past month? | CREATE TABLE login_attempts (id INT,user_account TEXT,attempt_time TIMESTAMP,role TEXT); INSERT INTO login_attempts (id,user_account,attempt_time,role) VALUES (1,'guest1','2023-03-12 15:30:00','guest'); INSERT INTO login_attempts (id,user_account,attempt_time,role) VALUES (2,'user2','2023-03-13 09:45:00','admin'); | SELECT user_account, MAX(TIMESTAMP_DIFF(attempt_time, LAG(attempt_time) OVER (PARTITION BY user_account ORDER BY attempt_time), MINUTE)) FROM login_attempts WHERE role = 'guest' AND attempt_time >= CURRENT_DATE - INTERVAL 30 DAY GROUP BY user_account; |
Find all brands that use ingredients from 'Brazil' and have a safety record after 2021-01-01 | CREATE TABLE ingredient (product_id INT,ingredient TEXT,origin TEXT); | SELECT DISTINCT brand FROM ingredient INNER JOIN safety_record ON ingredient.product_id = safety_record.product_id WHERE origin = 'Brazil' AND report_date > '2021-01-01'; |
Show the top 5 customers by total transaction amount in Spain. | CREATE TABLE transactions (customer_id INT,transaction_amount DECIMAL(10,2),country VARCHAR(50)); INSERT INTO transactions (customer_id,transaction_amount,country) VALUES (1,120.50,'Spain'),(2,75.30,'Spain'),(3,150.00,'Spain'),(4,50.00,'Spain'),(5,250.00,'Spain'),(6,100.00,'Spain'),(7,300.00,'Spain'),(8,200.00,'Spain'),(9,400.00,'Spain'),(10,500.00,'Spain'); | SELECT customer_id, SUM(transaction_amount) AS total_amount FROM transactions WHERE country = 'Spain' GROUP BY customer_id ORDER BY total_amount DESC LIMIT 5; |
Get the number of peacekeeping operations participated in by each military branch | CREATE TABLE peacekeeping_operations (id INT,operation_name VARCHAR(255),military_branch VARCHAR(255),year INT); | SELECT military_branch, COUNT(*) FROM peacekeeping_operations GROUP BY military_branch; |
What is the total number of military personnel for each type of military branch? | CREATE TABLE Military_Personnel (Branch VARCHAR(255),Personnel INT); INSERT INTO Military_Personnel (Branch,Personnel) VALUES ('Army',1500000),('Navy',500000),('Air Force',800000),('Marines',200000),('Coast Guard',30000); | SELECT Branch, SUM(Personnel) FROM Military_Personnel GROUP BY Branch; |
Delete the row with the animal id 2 from the "animals" table | CREATE TABLE animals (animal_id SERIAL PRIMARY KEY,name VARCHAR(255),species VARCHAR(255)); INSERT INTO animals (animal_id,name,species) VALUES (1,'Lion','Feline'),(2,'Tiger','Feline'),(3,'Bear','Ursidae'); | DELETE FROM animals WHERE animal_id = 2; |
What is the maximum number of kills achieved by a player in a single match of "Arena Wars" in the last week? | CREATE TABLE matches (id INT,player_id INT,game VARCHAR(50),kills INT,match_date DATETIME); INSERT INTO matches VALUES (1,1,'Arena Wars',25,'2022-03-01 12:15:00'); INSERT INTO matches VALUES (2,2,'Arena Wars',30,'2022-03-07 18:30:00'); | SELECT MAX(kills) FROM matches WHERE game = 'Arena Wars' AND match_date >= DATE_SUB(NOW(), INTERVAL 1 WEEK); |
What is the average carbon offset of initiatives in the 'carbon_offset_initiatives' table? | CREATE TABLE carbon_offset_initiatives (initiative_id INT,initiative_name VARCHAR(100),location VARCHAR(100),carbon_offset_tonnes FLOAT); INSERT INTO carbon_offset_initiatives (initiative_id,initiative_name,location,carbon_offset_tonnes) VALUES (1,'Initiative 1','India',1000.5),(2,'Initiative 2','China',1500.2); | SELECT AVG(carbon_offset_tonnes) FROM carbon_offset_initiatives; |
How many mental health parity violations were reported in 2020 and 2021? | CREATE TABLE mental_health_parity (violation_id INT,violation_date DATE,violation_details VARCHAR(255)); | SELECT COUNT(*) as violation_count FROM mental_health_parity WHERE violation_date BETWEEN '2020-01-01' AND '2021-12-31'; |
What is the total cost of medical services provided to patients with diabetes in rural New Mexico? | CREATE TABLE services (service_id INT,patient_id INT,service_date DATE,service_cost INT,state TEXT); INSERT INTO services (service_id,patient_id,service_date,service_cost,state) VALUES (1,3,'2022-01-10',200,'New Mexico'); | SELECT SUM(service_cost) FROM services JOIN patients ON services.patient_id = patients.patient_id WHERE patients.diagnosis = 'Diabetes' AND patients.state = 'New Mexico'; |
What is the average price of vegan cosmetics in the United States and United Kingdom? | CREATE TABLE products (product_id INT,name TEXT,is_vegan BOOLEAN,price DECIMAL,country TEXT); INSERT INTO products (product_id,name,is_vegan,price,country) VALUES (1,'Lipstick',TRUE,17.99,'USA'); INSERT INTO products (product_id,name,is_vegan,price,country) VALUES (2,'Eye Shadow',TRUE,14.49,'UK'); | SELECT AVG(price) FROM products WHERE is_vegan = TRUE AND (country = 'USA' OR country = 'UK'); |
Calculate the percentage of visitors who attended exhibitions in each city. | CREATE TABLE Exhibitions (id INT,city VARCHAR(20),visitor_id INT); CREATE TABLE Visitors (id INT,name VARCHAR(50)); | SELECT city, 100.0 * COUNT(DISTINCT Exhibitions.visitor_id) / (SELECT COUNT(DISTINCT Visitors.id) FROM Visitors) AS pct_visitors FROM Exhibitions GROUP BY city; |
What is the maximum capacity of any program in the programs table? | CREATE TABLE programs (program_id INT,capacity INT); INSERT INTO programs (program_id,capacity) VALUES (1,50),(2,75),(3,100); | SELECT MAX(capacity) as max_capacity FROM programs; |
What is the average water usage per capita in Washington state? | CREATE TABLE water_usage_metrics (id INT,location TEXT,population INT,water_usage FLOAT); INSERT INTO water_usage_metrics (id,location,population,water_usage) VALUES (1,'Seattle',730000,12000000),(2,'Spokane',220000,4000000),(3,'Tacoma',210000,3500000); | SELECT location, water_usage/population as avg_water_usage FROM water_usage_metrics WHERE location = 'Washington'; |
Update the 'energy_efficiency' table, setting the 'rating' value to 90 for all 'SuperLED' bulbs | CREATE TABLE energy_efficiency (id INT PRIMARY KEY,product VARCHAR(255),rating INT); | UPDATE energy_efficiency SET rating = 90 WHERE product = 'SuperLED'; |
What is the average delivery time for each mode of transportation? | CREATE TABLE deliveries (id INT,order_id INT,delivery_time INT,transportation_mode VARCHAR(50)); INSERT INTO deliveries (id,order_id,delivery_time,transportation_mode) VALUES (1,1001,3,'Air'),(2,1002,7,'Road'),(3,1003,5,'Rail'),(4,1004,2,'Sea'); | SELECT transportation_mode, AVG(delivery_time) as avg_delivery_time FROM deliveries GROUP BY transportation_mode; |
Create a view with manufacturers and their autonomous vehicles | CREATE TABLE autonomous_vehicles (id INT PRIMARY KEY,manufacturer VARCHAR(255),model VARCHAR(255),year INT,type VARCHAR(255)); | CREATE VIEW autonomous_vehicles_view AS SELECT manufacturer, STRING_AGG(model, ', ') AS models FROM autonomous_vehicles GROUP BY manufacturer; |
List all inspections for restaurants with 'Excellent' rating in 'London' | CREATE TABLE city (id INT,name VARCHAR(255)); INSERT INTO city (id,name) VALUES (1,'London'); CREATE TABLE restaurant_inspections (id INT,restaurant_id INT,inspection_date DATE,rating VARCHAR(255)); | SELECT r.name, i.inspection_date, i.rating FROM restaurant_inspections i JOIN restaurant r ON i.restaurant_id = r.id JOIN city c ON r.city_id = c.id WHERE c.name = 'London' AND i.rating = 'Excellent'; |
What was the average number of volunteer hours per month in the 'Arts & Culture' category in 2021? | CREATE TABLE volunteer_hours (id INT,volunteer_id INT,category VARCHAR(20),hours INT,hour_date DATE); INSERT INTO volunteer_hours (id,volunteer_id,category,hours,hour_date) VALUES (1,1,'Education',5,'2021-01-05'),(2,2,'Health',7,'2021-01-10'),(3,3,'Arts & Culture',6,'2021-02-15'),(4,4,'Arts & Culture',3,'2021-03-01'),(5,5,'Health',8,'2021-01-20'),(6,6,'Education',9,'2021-02-25'),(7,7,'Arts & Culture',4,'2021-03-10'),(8,8,'Arts & Culture',7,'2021-04-15'),(9,9,'Arts & Culture',8,'2021-12-25'); | SELECT AVG(hours / 12) as avg_monthly_volunteer_hours FROM volunteer_hours WHERE category = 'Arts & Culture' AND YEAR(hour_date) = 2021; |
Show the unique sizes of customers from the USA and Mexico? | CREATE TABLE customers_us_mx (id INT,size VARCHAR(10),country VARCHAR(20)); INSERT INTO customers_us_mx (id,size,country) VALUES (1,'M','USA'); INSERT INTO customers_us_mx (id,size,country) VALUES (2,'L','Mexico'); | SELECT size FROM customers_us_mx WHERE country = 'USA' INTERSECT SELECT size FROM customers_us_mx WHERE country = 'Mexico'; |
What is the maximum lifespan of an astronaut who has led a space mission and is from India? | CREATE TABLE astronauts_india (id INT,name VARCHAR(255),country VARCHAR(255),lifespan INT,is_lead_astronaut BOOLEAN); INSERT INTO astronauts_india (id,name,country,lifespan,is_lead_astronaut) VALUES (1,'AstronautA','India',80,true),(2,'AstronautB','India',70,false); | SELECT MAX(lifespan) FROM astronauts_india WHERE is_lead_astronaut = true; |
List the financial wellbeing programs implemented in Sub-Saharan Africa. | CREATE TABLE africa_programs (program_id INT,program_name TEXT,region TEXT); | SELECT africa_programs.program_name FROM africa_programs WHERE africa_programs.region = 'Sub-Saharan Africa'; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.