instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the total number of autonomous vehicles sold in urban and rural areas? | CREATE TABLE av_sales (id INT,make VARCHAR,model VARCHAR,year INT,region VARCHAR,sold INT); | SELECT region, SUM(sold) as total_sold FROM av_sales WHERE model LIKE '%autonomous%' GROUP BY region; |
Which country contributed the most humanitarian assistance to disaster relief efforts in each year, including the year, country name, and total amount donated? | CREATE TABLE humanitarian_assistance (id INT,year INT,country VARCHAR(255),amount DECIMAL(10,2)); INSERT INTO humanitarian_assistance (id,year,country,amount) VALUES (1,2015,'USA',5000000),(2,2016,'Japan',6000000),(3,2017,'Germany',4000000),(4,2018,'USA',7000000),(5,2019,'Canada',5500000),(6,2015,'UK',4500000),(7,2016,'France',3000000),(8,2017,'Italy',2500000),(9,2018,'Australia',3500000),(10,2019,'Spain',4000000); | SELECT year, country, MAX(amount) AS max_amount FROM humanitarian_assistance GROUP BY year, country ORDER BY year; |
What is the total number of hours worked by legal technology professionals in a year? | CREATE TABLE legal_tech_professionals (professional_id INT,hours_worked INT,year INT); | SELECT SUM(hours_worked) FROM legal_tech_professionals WHERE year = (SELECT MAX(year) FROM legal_tech_professionals); |
Regions with the highest percentage of cruelty-free product preferences? | CREATE TABLE user_preferences (user_id INT,region VARCHAR(50),cruelty_free BOOLEAN); INSERT INTO user_preferences (user_id,region,cruelty_free) VALUES (1,'North America',true),(2,'Europe',false),(3,'Asia',true); | SELECT region, AVG(cruelty_free) as cruelty_free_avg FROM user_preferences GROUP BY region ORDER BY cruelty_free_avg DESC; |
Find the total number of AI safety incidents for each region and the overall average in the 'ai_safety' table. | CREATE TABLE ai_safety (region TEXT,incident_count INT); | SELECT region, AVG(incident_count) as avg_incident, SUM(incident_count) as total_incidents FROM ai_safety GROUP BY region; |
List all public events held in the capital cities of Asian countries over the past decade? | CREATE TABLE Events (EventID INT,City VARCHAR(50),Country VARCHAR(50),Year INT); CREATE TABLE Capitals (City VARCHAR(50),Country VARCHAR(50)); | SELECT Events.EventID, Events.City, Events.Country, Events.Year FROM Events INNER JOIN Capitals ON Events.City = Capitals.City WHERE Capitals.Country IN ('Afghanistan', 'Bangladesh', 'Bhutan', 'China', 'India', 'Indonesia', 'Maldives', 'Mongolia', 'Myanmar', 'Nepal', 'NorthKorea', 'Pakistan', 'Philippines', 'SriLanka', 'Taiwan', 'Thailand', 'TimorLeste', 'Vietnam') AND Events.Year >= 2012; |
What are the recycling rates in Africa for the year 2018, grouped by country? | CREATE TABLE RecyclingRatesAfrica (country VARCHAR(50),year INT,recycling_rate DECIMAL(5,2)); INSERT INTO RecyclingRatesAfrica (country,year,recycling_rate) VALUES ('South Africa',2018,0.38),('Nigeria',2018,0.25),('Egypt',2018,0.42),('Algeria',2018,0.30),('Morocco',2018,0.45); | SELECT country, AVG(recycling_rate) FROM RecyclingRatesAfrica WHERE year = 2018 GROUP BY country; |
Add a new record to the 'menu_engineering' table for 'Appetizers' with a 'contribution_margin' of 0.35 | CREATE TABLE menu_engineering (category TEXT,contribution_margin DECIMAL(3,2)); | INSERT INTO menu_engineering (category, contribution_margin) VALUES ('Appetizers', 0.35); |
Which employees are the longest serving in their respective job roles across the workforce? | CREATE TABLE EmployeeRoles (EmployeeID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Age INT,JobRole VARCHAR(50),MineName VARCHAR(50)); INSERT INTO EmployeeRoles (EmployeeID,FirstName,LastName,Age,JobRole,MineName) VALUES (1,'David','Lee',45,'Mining Engineer','ABC Mine'); INSERT INTO EmployeeRoles (EmployeeID,FirstName,LastName,Age,JobRole,MineName) VALUES (2,'Sophia','Liu',35,'Environmental Scientist','DEF Mine'); INSERT INTO EmployeeRoles (EmployeeID,FirstName,LastName,Age,JobRole,MineName) VALUES (3,'Daniel','Kim',50,'Mine Manager','GHI Mine'); INSERT INTO EmployeeRoles (EmployeeID,FirstName,LastName,Age,JobRole,MineName) VALUES (4,'Olivia','Wang',40,'Geologist','JKL Mine'); | SELECT EmployeeID, FirstName, LastName, Age, JobRole, MineName, ROW_NUMBER() OVER (PARTITION BY JobRole ORDER BY Age DESC) as 'AgeRank' FROM EmployeeRoles WHERE AgeRank = 1; |
List all smart city projects located in 'Urbanville' with their respective start dates. | CREATE TABLE smart_city_projects (project_id INT,project_name VARCHAR(100),location VARCHAR(50),start_date DATE); INSERT INTO smart_city_projects (project_id,project_name,location,start_date) VALUES (1,'Smart Grid 1','Urbanville','2018-01-01'); INSERT INTO smart_city_projects (project_id,project_name,location,start_date) VALUES (2,'Smart Traffic Lights 1','Urbanville','2019-05-15'); | SELECT * FROM smart_city_projects WHERE location = 'Urbanville'; |
What is the maximum number of workforce development programs offered by companies in a single country? | CREATE TABLE companies (id INT,name TEXT,country TEXT,num_workforce_programs INT); INSERT INTO companies (id,name,country,num_workforce_programs) VALUES (1,'Empowerment Enterprises','USA',3); INSERT INTO companies (id,name,country,num_workforce_programs) VALUES (2,'Skillset Solutions','Canada',2); INSERT INTO companies (id,name,country,num_workforce_programs) VALUES (3,'Proficiency Partners','Mexico',4); INSERT INTO companies (id,name,country,num_workforce_programs) VALUES (4,'Abilities Associates','Brazil',5); INSERT INTO companies (id,name,country,num_workforce_programs) VALUES (5,'Capability Creations','USA',1); INSERT INTO companies (id,name,country,num_workforce_programs) VALUES (6,'Knowledge Kingdom','Canada',6); | SELECT MAX(num_workforce_programs) AS max_programs FROM companies WHERE country IN ('USA', 'Canada', 'Mexico', 'Brazil'); |
What is the total number of transactions for each investment strategy? | CREATE TABLE investment_strategies (strategy_id INT,strategy_name VARCHAR(50),client_id INT); INSERT INTO investment_strategies (strategy_id,strategy_name,client_id) VALUES (1,'Equity',1),(2,'Fixed Income',2),(3,'Real Estate',3),(4,'Equity',1),(5,'Fixed Income',2),(6,'Equity',3); CREATE TABLE transactions (transaction_id INT,strategy_id INT,amount DECIMAL(10,2)); INSERT INTO transactions (transaction_id,strategy_id,amount) VALUES (1,1,500.00),(2,1,1000.00),(3,2,250.00),(4,3,10000.00),(5,3,500.00),(6,1,250.00); | SELECT strategy_name, COUNT(*) AS total_transactions FROM investment_strategies JOIN transactions ON investment_strategies.client_id = transactions.strategy_id GROUP BY strategy_name; |
Delete all mental health parity training records for community health workers who have not completed cultural competency training. | CREATE TABLE worker_training (worker_id INT,cultural_competency_training DATE,mental_health_parity_training DATE); INSERT INTO worker_training (worker_id,cultural_competency_training,mental_health_parity_training) VALUES (1,'2022-01-01','2022-02-01'),(2,'2022-02-01','2022-03-01'),(3,NULL,'2022-04-01'); | DELETE FROM worker_training WHERE worker_id IN (SELECT worker_id FROM worker_training WHERE cultural_competency_training IS NULL); |
What is the difference in temperature between the maximum and minimum temperature for each day in July 2020? | CREATE TABLE Temperature (id INT,timestamp DATE,temperature REAL); | SELECT EXTRACT(DAY FROM timestamp) as day, MAX(temperature) - MIN(temperature) as temp_difference FROM Temperature WHERE EXTRACT(MONTH FROM timestamp) = 7 AND EXTRACT(YEAR FROM timestamp) = 2020 GROUP BY day; |
Which countries have the highest number of defense contracts? | CREATE TABLE Contract_Country (id INT,country VARCHAR(50),contract_count INT); INSERT INTO Contract_Country (id,country,contract_count) VALUES (1,'USA',50),(2,'Canada',30); CREATE TABLE Contract_Country_Mapping (contract_id INT,country_id INT); INSERT INTO Contract_Country_Mapping (contract_id,country_id) VALUES (1,1),(2,1),(3,2); | SELECT Contract_Country.country, SUM(Contract_Country_Mapping.contract_id) AS contract_count FROM Contract_Country JOIN Contract_Country_Mapping ON Contract_Country.id = Contract_Country_Mapping.country_id GROUP BY Contract_Country.country ORDER BY contract_count DESC; |
how many excavation sites are there in 'Asia'? | CREATE TABLE excavation_site_continent (site_id INTEGER,site_name TEXT,country TEXT,continent TEXT); INSERT INTO excavation_site_continent (site_id,site_name,country,continent) VALUES (1,'Pompeii','Italy','Europe'),(2,'Angkor Wat','Cambodia','Asia'),(3,'Machu Picchu','Peru','South America'),(4,'Petra','Jordan','Asia'),(5,'Tikal','Guatemala','Central America'),(6,'Palmyra','Syria','Asia'),(7,'Easter Island','Chile','South America'); | SELECT COUNT(site_name) FROM excavation_site_continent WHERE continent = 'Asia'; |
What are the total sales and average product price for each product category in Washington state for the year 2020? | CREATE TABLE products (id INT,name TEXT,category TEXT); INSERT INTO products (id,name,category) VALUES (1,'Product X','Category A'); INSERT INTO products (id,name,category) VALUES (2,'Product Y','Category B'); CREATE TABLE sales (product_id INT,year INT,sales INT,price INT); INSERT INTO sales (product_id,year,sales,price) VALUES (1,2020,100,50); INSERT INTO sales (product_id,year,sales,price) VALUES (2,2020,150,75); | SELECT p.category, SUM(s.sales) as total_sales, AVG(s.price) as average_price FROM products p INNER JOIN sales s ON p.id = s.product_id WHERE p.name = 'Washington' AND s.year = 2020 GROUP BY p.category; |
What is the total amount donated to organizations focused on climate change by donors from the US? | CREATE TABLE donors (id INT,country VARCHAR(255)); INSERT INTO donors (id,country) VALUES (1,'United States'); INSERT INTO donors (id,country) VALUES (2,'Canada'); CREATE TABLE donations (id INT,donor_id INT,organization_id INT,amount DECIMAL(10,2),donation_date DATE); INSERT INTO donations (id,donor_id,organization_id,amount,donation_date) VALUES (1,1,3,5000,'2021-06-15'); CREATE TABLE organizations (id INT,name VARCHAR(255),focus VARCHAR(255)); INSERT INTO organizations (id,name,focus) VALUES (3,'Climate Foundation','Climate Change'); | SELECT SUM(amount) FROM donations JOIN donors ON donations.donor_id = donors.id JOIN organizations ON donations.organization_id = organizations.id WHERE donors.country = 'United States' AND organizations.focus = 'Climate Change'; |
What is the maximum temperature recorded for crop 'Cassava' in the last 30 days? | CREATE TABLE WeatherData (crop_type VARCHAR(20),temperature FLOAT,record_date DATE); INSERT INTO WeatherData (crop_type,temperature,record_date) VALUES ('Corn',22.5,'2022-01-01'); INSERT INTO WeatherData (crop_type,temperature,record_date) VALUES ('Rice',30.1,'2022-01-05'); INSERT INTO WeatherData (crop_type,temperature,record_date) VALUES ('Rice',29.6,'2022-01-06'); INSERT INTO WeatherData (crop_type,temperature,record_date) VALUES ('Cassava',35.2,'2022-01-25'); INSERT INTO WeatherData (crop_type,temperature,record_date) VALUES ('Cassava',34.8,'2022-01-26'); | SELECT MAX(temperature) FROM WeatherData WHERE crop_type = 'Cassava' AND record_date >= DATEADD(day, -30, GETDATE()); |
What is the total number of comments on posts with the hashtag #climatechange? | CREATE TABLE posts (id INT,hashtags VARCHAR(255),comments INT); INSERT INTO posts (id,hashtags,comments) VALUES (1,'#climatechange,#environment',10),(2,'#climatechange',20),(3,'#sustainability',30),(4,'#climateaction',40),(5,'#climatechange',50),(6,'#sustainability,#climatechange',60); | SELECT SUM(posts.comments) AS total_comments FROM posts WHERE posts.hashtags LIKE '%#climatechange%'; |
What is the number of facilities for each origin, grouped by origin? | CREATE TABLE AquacultureFacilities (ID INT PRIMARY KEY,Name VARCHAR,Location VARCHAR,SpeciesID INT,FOREIGN KEY (SpeciesID) REFERENCES Species(ID)); INSERT INTO AquacultureFacilities (ID,Name,Location,SpeciesID) VALUES (4,'Facility4','India',4); | SELECT f.Origin, COUNT(af.ID) AS NumFacilities FROM AquacultureFacilities af JOIN Species f ON af.SpeciesID = f.ID GROUP BY f.Origin; |
List the names of the TV shows that have more than one season, without any repetition. | CREATE TABLE tv_shows (id INT,title VARCHAR(255),seasons INT); INSERT INTO tv_shows VALUES (1,'Show A',1); INSERT INTO tv_shows VALUES (2,'Show B',2); INSERT INTO tv_shows VALUES (3,'Show C',3); INSERT INTO tv_shows VALUES (4,'Show D',2); INSERT INTO tv_shows VALUES (5,'Show E',1); | SELECT DISTINCT title FROM tv_shows WHERE seasons > 1; |
How many financial capability programs were launched in Q1 2022, grouped by country? | CREATE TABLE financial_capability_programs (id INT PRIMARY KEY,program_name TEXT,launch_date DATE,country TEXT); | SELECT country, COUNT(*) FROM financial_capability_programs WHERE launch_date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY country; |
How many startups have had an exit strategy of Acquisition in each continent? | CREATE TABLE startup (id INT,name TEXT,country TEXT,exit_strategy TEXT); CREATE TABLE continent (country TEXT,continent TEXT); INSERT INTO startup (id,name,country,exit_strategy) VALUES (1,'Omega Enterprises','USA','Acquisition'); INSERT INTO continent (country,continent) VALUES ('USA','North America'); INSERT INTO startup (id,name,country,exit_strategy) VALUES (2,'Psi Inc','Canada','Acquisition'); INSERT INTO continent (country,continent) VALUES ('Canada','North America'); | SELECT c.continent, COUNT(*) FROM startup s INNER JOIN continent c ON s.country = c.country WHERE s.exit_strategy = 'Acquisition' GROUP BY c.continent; |
Find the average safety score for each vehicle model in a specific country. | CREATE TABLE Vehicle_Models (model_id INT,model VARCHAR(50),country_id INT); INSERT INTO Vehicle_Models (model_id,model,country_id) VALUES (1001,'Tesla Model 3',1); CREATE TABLE Safety_Tests (test_id INT,model_id INT,result INT,test_type VARCHAR(50)); INSERT INTO Safety_Tests (test_id,model_id,result,test_type) VALUES (1,1001,95,'Crash Test'); CREATE TABLE Country (country_id INT,country_name VARCHAR(50)); INSERT INTO Country (country_id,country_name) VALUES (1,'USA'); | SELECT vm.model, AVG(st.result) as "Average Safety Score" FROM Vehicle_Models vm JOIN Safety_Tests st ON vm.model_id = st.model_id JOIN Country c ON vm.country_id = c.country_id WHERE c.country_name = 'USA' GROUP BY vm.model; |
What is the minimum delivery time for packages shipped to South America? | CREATE TABLE delivery_data (delivery_id INT,shipment_id INT,delivery_time INT); INSERT INTO delivery_data (delivery_id,shipment_id,delivery_time) VALUES (1,1,10),(2,2,15),(3,3,12),(4,4,18),(5,5,20); | SELECT MIN(delivery_time) FROM delivery_data JOIN shipment_data ON delivery_data.shipment_id = shipment_data.shipment_id WHERE shipment_data.destination_country IN ('South America', 'Brazil', 'Argentina', 'Colombia', 'Peru'); |
Get the total number of non-GMO items | CREATE TABLE items (id INT,name VARCHAR(50),is_non_gmo BOOLEAN,category VARCHAR(50)); INSERT INTO items (id,name,is_non_gmo,category) VALUES (1,'Corn',TRUE,'Produce'),(2,'Soy Milk',TRUE,'Dairy'),(3,'Bread',FALSE,'Bakery'); | SELECT COUNT(*) FROM items WHERE is_non_gmo = TRUE; |
What is the second deepest trench in the Indian Plate? | CREATE TABLE Indian_Plate (trench_name TEXT,location TEXT,avg_depth FLOAT); INSERT INTO Indian_Plate (trench_name,location,avg_depth) VALUES ('Sunda Trench','Indian Ocean',7450.0),('Java Trench','Indian Ocean',7250.0); | SELECT trench_name, avg_depth FROM (SELECT trench_name, avg_depth, ROW_NUMBER() OVER (ORDER BY avg_depth DESC) AS rn FROM Indian_Plate) AS subquery WHERE rn = 2; |
How many climate finance initiatives were inserted into the 'climate_finance' table in 2020? | CREATE TABLE climate_finance (initiative_name TEXT,year INTEGER,amount FLOAT); INSERT INTO climate_finance (initiative_name,year,amount) VALUES ('Green Grants',2019,50000.0),('Climate Innovation Fund',2020,100000.0),('Renewable Energy Loans',2018,75000.0); | SELECT COUNT(*) FROM climate_finance WHERE year = 2020; |
What is the total number of veteran and non-veteran job applicants for each job category in California? | CREATE TABLE JobApplicants (ApplicantID int,JobCategory varchar(50),JobLocation varchar(50),ApplicantType varchar(50)); INSERT INTO JobApplicants (ApplicantID,JobCategory,JobLocation,ApplicantType) VALUES (1,'Software Engineer','California','Veteran'),(2,'Project Manager','California','Non-Veteran'),(3,'Data Analyst','California','Veteran'),(4,'Software Engineer','California','Non-Veteran'),(5,'Project Manager','California','Veteran'),(6,'Data Scientist','California','Non-Veteran'); | SELECT JobCategory, COUNT(*) FILTER (WHERE ApplicantType = 'Veteran') as VeteranApplicants, COUNT(*) FILTER (WHERE ApplicantType = 'Non-Veteran') as NonVeteranApplicants FROM JobApplicants WHERE JobLocation = 'California' GROUP BY JobCategory; |
What is the total number of systems with a 'Low' severity vulnerability? | CREATE TABLE Vulnerabilities (id INT PRIMARY KEY,cve VARCHAR(255),severity VARCHAR(50),description TEXT,date DATE); INSERT INTO Vulnerabilities (id,cve,severity,description,date) VALUES (3,'CVE-2021-9876','Low','Information disclosure vulnerability','2021-06-01'); CREATE TABLE Systems (id INT PRIMARY KEY,hostname VARCHAR(255),ip VARCHAR(50),vulnerability_id INT,FOREIGN KEY (vulnerability_id) REFERENCES Vulnerabilities(id)); INSERT INTO Systems (id,hostname,ip,vulnerability_id) VALUES (3,'dbserver01','10.0.2.1',3); | SELECT COUNT(*) FROM Systems WHERE vulnerability_id IN (SELECT id FROM Vulnerabilities WHERE severity = 'Low'); |
What are the names of all countries that have purchased military equipment from Raytheon between 2018 and 2020? | CREATE TABLE military_sales (seller VARCHAR(255),buyer VARCHAR(255),equipment VARCHAR(255),quantity INT,sale_date DATE); INSERT INTO military_sales (seller,buyer,equipment,quantity,sale_date) VALUES ('Raytheon','Canada','missile',20,'2018-03-04'),('Raytheon','Mexico','radar',30,'2019-06-17'),('Raytheon','Brazil','aircraft',40,'2020-09-29'); | SELECT DISTINCT buyer FROM military_sales WHERE seller = 'Raytheon' AND YEAR(sale_date) BETWEEN 2018 AND 2020; |
Count the number of access to justice programs by location | CREATE TABLE programs (id INT PRIMARY KEY,location VARCHAR(255),type VARCHAR(255)); | SELECT location, COUNT(*) FROM programs WHERE type = 'Access to Justice' GROUP BY location; |
Display the number of founders who are people of color | CREATE TABLE startup (id INT,name TEXT,founding_year INT,founder_race TEXT); | SELECT COUNT(*) FROM startup WHERE founder_race IS NOT NULL; |
What is the total number of sustainable building projects in the 'sustainable_buildings' table with a material cost greater than $50,000? | CREATE TABLE sustainable_buildings (project_id INT,project_name TEXT,material_cost FLOAT); | SELECT COUNT(*) FROM sustainable_buildings WHERE material_cost > 50000; |
What is the average duration of training programs with capacity greater than 30? | CREATE TABLE Training_Programs (id INT,name VARCHAR(50),instructor VARCHAR(50),capacity INT,duration INT); INSERT INTO Training_Programs (id,name,instructor,capacity,duration) VALUES (2,'Java','Bob Johnson',40,40); | SELECT AVG(duration) FROM Training_Programs WHERE capacity > 30; |
List claim IDs and amounts for claims processed in the last month. | CREATE TABLE claims (id INT,claim_id INT,policy_id INT,claim_amount DECIMAL(10,2),claim_date DATE); INSERT INTO claims (id,claim_id,policy_id,claim_amount,claim_date) VALUES (1,1001,1,2500,'2022-02-15'); | SELECT claim_id, claim_amount FROM claims WHERE claim_date >= DATEADD(month, -1, GETDATE()); |
What is the total revenue generated by OTAs in France for hotels with a 3-star rating or lower? | CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,country TEXT,stars INT,revenue FLOAT); INSERT INTO hotels (hotel_id,hotel_name,country,stars,revenue) VALUES (1,'Hotel P','France',3,8000),(2,'Hotel Q','France',2,6000),(3,'Hotel R','France',5,15000); CREATE TABLE otas (ota_id INT,ota_name TEXT,hotel_id INT,otas_revenue FLOAT); INSERT INTO otas (ota_id,ota_name,hotel_id,otas_revenue) VALUES (1,'OTA1',1,4000),(2,'OTA2',2,3000),(3,'OTA3',3,12000); | SELECT SUM(otas_revenue) FROM otas JOIN hotels ON otas.hotel_id = hotels.hotel_id WHERE hotels.country = 'France' AND hotels.stars <= 3; |
What's the investment amount and date for climate change investors? | CREATE TABLE if not exists investors (id INT PRIMARY KEY,name TEXT,location TEXT,investment_goal TEXT); INSERT INTO investors (id,name,location,investment_goal) VALUES (1,'Jane Doe','Los Angeles','Climate Change'); | SELECT i.name, investment.amount, investment.investment_date FROM investors i JOIN investments investment ON i.id = investment.investor_id WHERE i.investment_goal = 'Climate Change'; |
How many artworks were added to museums each year? | CREATE TABLE artworks (id INT,museum_id INT,year INT,quantity INT); INSERT INTO artworks (id,museum_id,year,quantity) VALUES (1,1,2015,1200),(2,1,2016,1500),(3,2,2014,1000),(4,2,2015,1300),(5,3,2013,1600),(6,3,2014,1800); | SELECT year, SUM(quantity) FROM artworks GROUP BY year; |
Find the number of students who have enrolled in both 'Introduction to Programming' and 'Data Structures' courses. | CREATE TABLE course_enrollment (student_id INT,course_name VARCHAR(255)); INSERT INTO course_enrollment (student_id,course_name) VALUES (1,'Introduction to Programming'),(2,'Data Structures'),(3,'Introduction to Programming'),(2,'Introduction to Programming'); | SELECT student_id FROM course_enrollment WHERE course_name = 'Introduction to Programming' INTERSECT SELECT student_id FROM course_enrollment WHERE course_name = 'Data Structures'; |
What's the total number of volunteers and their average age, grouped by gender? | CREATE TABLE Volunteers (VolunteerID INT,Age INT,Gender VARCHAR(10)); INSERT INTO Volunteers (VolunteerID,Age,Gender) VALUES (1,25,'Male'),(2,30,'Female'),(3,35,'Male'); | SELECT Gender, COUNT(*) as NumVolunteers, AVG(Age) as AvgAge FROM Volunteers GROUP BY Gender; |
Find the number of unresolved security incidents in the African region. | CREATE TABLE security_incidents (id INT,region VARCHAR(50),resolved BOOLEAN); | SELECT COUNT(*) FROM security_incidents WHERE region = 'Africa' AND resolved = FALSE; |
Delete a port from the "ports" table | CREATE TABLE ports (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255)); | DELETE FROM ports WHERE id = 1; |
What is the maximum number of vulnerabilities found in a single system in the last year? | CREATE TABLE VulnerabilityAssessments(id INT,system_id VARCHAR(50),vulnerabilities INT,assessment_date DATE); | SELECT MAX(vulnerabilities) as max_vulnerabilities FROM VulnerabilityAssessments WHERE assessment_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 1 YEAR); |
What is the maximum number of daily visitors to cultural heritage sites in Brazil? | CREATE TABLE cultural_heritage_sites (id INT,name TEXT,country TEXT,daily_visitors INT); INSERT INTO cultural_heritage_sites (id,name,country,daily_visitors) VALUES (1,'Christ the Redeemer','Brazil',10000),(2,'Sugarloaf Mountain','Brazil',8000),(3,'Iguazu Falls','Brazil',12000); | SELECT MAX(daily_visitors) FROM cultural_heritage_sites WHERE country = 'Brazil'; |
What is the total number of community policing centers in suburban areas and the total number of emergency incidents reported at these centers, broken down by incident type? | CREATE TABLE community_policing_centers (id INT,center_name TEXT,location TEXT); INSERT INTO community_policing_centers (id,center_name,location) VALUES (1,'Center A','Suburban'),(2,'Center B','Urban'),(3,'Center C','Suburban'),(4,'Center D','Rural'); CREATE TABLE emergency_incidents (id INT,center_id INT,incident_type TEXT,incident_count INT); INSERT INTO emergency_incidents (id,center_id,incident_type,incident_count) VALUES (1,1,'Fire',20),(2,1,'Medical',30),(3,2,'Fire',40),(4,2,'Medical',50),(5,3,'Fire',25),(6,3,'Medical',35),(7,4,'Fire',15),(8,4,'Medical',20); | SELECT c.location, incident_type, SUM(incident_count) AS total_incidents FROM community_policing_centers c JOIN emergency_incidents e ON c.id = e.center_id WHERE c.location = 'Suburban' GROUP BY c.location, incident_type; |
What is the total capacity of vessels in a specific port, excluding vessels with a capacity below a certain threshold? | CREATE TABLE ports (id INT,name VARCHAR(255),location VARCHAR(255),operated_by VARCHAR(255)); CREATE TABLE vessels (id INT,name VARCHAR(255),port_id INT,capacity INT); INSERT INTO ports (id,name,location,operated_by) VALUES (1,'Port A','New York','Company A'),(2,'Port B','Los Angeles','Company B'); INSERT INTO vessels (id,name,port_id,capacity) VALUES (1,'Vessel A',1,5000),(2,'Vessel B',1,6000),(3,'Vessel C',2,4000),(4,'Vessel D',2,2000); | SELECT SUM(vessels.capacity) as total_capacity FROM vessels INNER JOIN ports ON vessels.port_id = ports.id WHERE ports.name = 'Port A' AND vessels.capacity >= 5000; |
Update the professional development status of teachers based on their years of experience. | CREATE TABLE teachers (teacher_id INT,years_of_experience INT,professional_development VARCHAR(255)); INSERT INTO teachers (teacher_id,years_of_experience,professional_development) VALUES (1,5,'Beginner'),(2,10,'Intermediate'),(3,15,'Advanced'); | UPDATE teachers SET professional_development = CASE WHEN years_of_experience >= 10 THEN 'Intermediate' WHEN years_of_experience >= 15 THEN 'Advanced' ELSE 'Beginner' END; |
Which 'Racing' game has the highest number of active players in India? | CREATE TABLE player_profiles (player_id INT,player_country VARCHAR(50)); INSERT INTO player_profiles (player_id,player_country) VALUES (1,'USA'),(2,'Canada'),(3,'India'),(4,'Brazil'),(5,'Germany'); CREATE TABLE player_games (player_id INT,game_name VARCHAR(100),game_type VARCHAR(50)); INSERT INTO player_games (player_id,game_name,game_type) VALUES (1,'GameE','Racing'),(2,'GameF','Shooter'),(3,'GameG','Racing'),(4,'GameH','Strategy'),(5,'GameI','Racing'); | SELECT game_name, COUNT(player_id) AS active_players FROM player_profiles JOIN player_games ON player_profiles.player_id = player_games.player_id WHERE player_country = 'India' AND game_type = 'Racing' GROUP BY game_name ORDER BY active_players DESC LIMIT 1; |
What's the average annual temperature change in the Arctic region? | CREATE TABLE arctic_temperature (year INT,region VARCHAR(255),temperature DECIMAL(5,2)); | SELECT AVG(temperature) FROM arctic_temperature WHERE region = 'Arctic' GROUP BY year; |
What is the average energy efficiency improvement in India and China over the last 5 years? | CREATE TABLE energy_efficiency (country VARCHAR(20),year INT,improvement FLOAT); INSERT INTO energy_efficiency (country,year,improvement) VALUES ('India',2017,2.5),('India',2018,3.0),('India',2019,3.5),('India',2020,4.0),('China',2017,1.5),('China',2018,2.0),('China',2019,2.5),('China',2020,3.0); | SELECT e1.country, AVG(e1.improvement) as avg_improvement FROM energy_efficiency e1 WHERE e1.country IN ('India', 'China') GROUP BY e1.country; |
What is the average CO2 emissions for each fabric type? | CREATE TABLE fabric_emissions (id INT,fabric VARCHAR(255),material_type VARCHAR(255),co2_emissions FLOAT); INSERT INTO fabric_emissions (id,fabric,material_type,co2_emissions) VALUES (1,'cotton','natural',5.0); INSERT INTO fabric_emissions (id,fabric,material_type,co2_emissions) VALUES (2,'polyester','synthetic',7.5); | SELECT fabric, AVG(co2_emissions) as avg_co2_emissions FROM fabric_emissions GROUP BY fabric; |
Who are the top 5 donors for 'African rural development' based on total donated amount? | CREATE TABLE donors (id INT,name TEXT,region TEXT,donated_amount FLOAT); INSERT INTO donors (id,name,region,donated_amount) VALUES (1,'Donor 1','Africa',1000000),(2,'Donor 2','Asia',750000),(3,'Donor 3','Africa',1250000),(4,'Donor 4','Europe',500000),(5,'Donor 5','Africa',1500000); | SELECT donors.name, SUM(donors.donated_amount) FROM donors WHERE donors.region = 'Africa' GROUP BY donors.name ORDER BY SUM(donors.donated_amount) DESC LIMIT 5; |
Create a view for displaying the top 3 subscription types with the highest total revenue. | CREATE TABLE Mobile_Subscribers (Subscriber_ID INT,Subscription_Type VARCHAR(20),Data_Allowance FLOAT,Monthly_Charge FLOAT); INSERT INTO Mobile_Subscribers (Subscriber_ID,Subscription_Type,Data_Allowance,Monthly_Charge) VALUES (1,'Postpaid',5.0,60.0),(2,'Prepaid',3.0,40.0); CREATE TABLE Broadband_Subscribers (Subscriber_ID INT,Subscription_Type VARCHAR(20),Download_Speed FLOAT,Monthly_Charge FLOAT); INSERT INTO Broadband_Subscribers (Subscriber_ID,Subscription_Type,Download_Speed,Monthly_Charge) VALUES (1,'Fiber',500.0,80.0),(2,'Cable',300.0,60.0); | CREATE VIEW Top_3_Subscription_Types AS SELECT COALESCE(MS.Subscription_Type, BS.Subscription_Type) as Subscription_Type, SUM(COALESCE(MS.Monthly_Charge, BS.Monthly_Charge)) as Total_Revenue FROM Mobile_Subscribers MS FULL OUTER JOIN Broadband_Subscribers BS ON MS.Subscription_Type = BS.Subscription_Type GROUP BY MS.Subscription_Type, BS.Subscription_Type ORDER BY Total_Revenue DESC LIMIT 3; |
Find the number of vegan dishes in the menu that have a rating greater than 4.5. | CREATE TABLE dishes (id INT,name TEXT,type TEXT,rating FLOAT); | SELECT COUNT(*) FROM dishes WHERE type = 'vegan' AND rating > 4.5; |
What is the total number of autonomous vehicles sold in the 'vehicle_sales' table by city? | CREATE TABLE schema.vehicle_sales (vehicle_id INT,vehicle_type VARCHAR(50),sale_date DATE,quantity INT,city VARCHAR(50)); INSERT INTO schema.vehicle_sales (vehicle_id,vehicle_type,sale_date,quantity,city) VALUES (1,'hybrid','2021-01-01',200,'San Francisco'),(2,'electric','2021-01-01',300,'San Francisco'),(3,'fossil_fuel','2021-01-01',400,'San Francisco'),(4,'hybrid','2021-04-01',250,'Los Angeles'),(5,'electric','2021-04-01',350,'Los Angeles'),(6,'fossil_fuel','2021-04-01',450,'Los Angeles'),(7,'hybrid','2021-07-01',300,'New York'),(8,'electric','2021-07-01',400,'New York'),(9,'fossil_fuel','2021-07-01',500,'New York'),(10,'autonomous','2021-10-01',50,'San Francisco'),(11,'autonomous','2021-10-01',75,'Los Angeles'),(12,'autonomous','2021-10-01',100,'New York'); | SELECT city, SUM(quantity) FROM schema.vehicle_sales WHERE vehicle_type = 'autonomous' GROUP BY city; |
How many players are from the Asia-Pacific region? | CREATE TABLE Players (PlayerID INT,Region VARCHAR(30)); INSERT INTO Players (PlayerID,Region) VALUES (1,'Asia-Pacific'),(2,'North America'),(3,'Europe'),(4,'Asia-Pacific'); | SELECT COUNT(*) FROM Players WHERE Region = 'Asia-Pacific'; |
What is the minimum founding year for companies founded by Latinx entrepreneurs in the e-commerce sector? | CREATE TABLE companies (company_id INT,company_name TEXT,industry TEXT,founding_year INT,founder_race TEXT); INSERT INTO companies (company_id,company_name,industry,founding_year,founder_race) VALUES (1,'ShopLatino','E-commerce',2012,'Latinx'); | SELECT MIN(founding_year) FROM companies WHERE industry = 'E-commerce' AND founder_race = 'Latinx'; |
What is the total number of workers in the textile industry in India and Pakistan? | CREATE TABLE textile_companies (id INT,company_name VARCHAR(100),country VARCHAR(50),worker_count INT); INSERT INTO textile_companies (id,company_name,country,worker_count) VALUES (1,'ABC Textiles','India',500); INSERT INTO textile_companies (id,company_name,country,worker_count) VALUES (2,'XYZ Weaving','Pakistan',300); | SELECT SUM(tc.worker_count) as total_workers FROM textile_companies tc WHERE tc.country IN ('India', 'Pakistan'); |
What is the total inventory value for non-organic items? | CREATE TABLE non_organic_items (id INT,item_name VARCHAR(255),category VARCHAR(255),quantity INT,unit_price DECIMAL(5,2)); INSERT INTO non_organic_items (id,item_name,category,quantity,unit_price) VALUES (1,'Chicken','Proteins',100,1.99),(2,'Rice','Grains',75,0.99); | SELECT SUM(quantity * unit_price) FROM non_organic_items; |
What is the percentage of the population that has completed higher education in each state? | CREATE TABLE education_stats (state VARCHAR(20),population INT,higher_education INT); INSERT INTO education_stats (state,population,higher_education) VALUES ('California',39512223,1321233),('Texas',29528404,921034),('Florida',21647197,710345); | SELECT state, (higher_education * 100.0 / population) as percentage FROM education_stats |
Update the record in the 'exploration_data' table where the country is 'Saudi Arabia' and the discovery_year is 2017, setting the 'discovery_number' to 25000 | CREATE TABLE exploration_data (id INT,field VARCHAR(50),country VARCHAR(50),discovery_year INT,discovery_number FLOAT); INSERT INTO exploration_data (id,field,country,discovery_year,discovery_number) VALUES (1,'Rub al Khali','Saudi Arabia',2017,24000); INSERT INTO exploration_data (id,field,country,discovery_year,discovery_number) VALUES (2,'Persian Gulf','Iran',2018,26000); | UPDATE exploration_data SET discovery_number = 25000 WHERE country = 'Saudi Arabia' AND discovery_year = 2017; |
Find the top 3 genetic research papers with the most citations in the last year, excluding self-citations. | CREATE TABLE genetic_research_papers (paper_id INT,paper_title VARCHAR(100),num_citations INT,publishing_year INT,author_id INT); INSERT INTO genetic_research_papers VALUES (1,'Genome Editing Techniques',50,2021,101); INSERT INTO genetic_research_papers VALUES (2,'Stem Cell Applications',75,2020,102); INSERT INTO genetic_research_papers VALUES (3,'Bioprocessing Methods',35,2021,103); INSERT INTO genetic_research_papers VALUES (4,'Biosensor Technology',40,2021,101); | SELECT * FROM (SELECT paper_id, paper_title, num_citations, RANK() OVER (ORDER BY num_citations DESC) AS rank FROM genetic_research_papers WHERE publishing_year = YEAR(CURDATE()) - 1 AND author_id != 101) ranked_papers WHERE rank <= 3; |
What is the average population of cities in 'Germany' and 'Spain'? | CREATE TABLE City (Id INT PRIMARY KEY,Name VARCHAR(50),Population INT,Country VARCHAR(50)); INSERT INTO City (Id,Name,Population,Country) VALUES (1,'Berlin',3600000,'Germany'); INSERT INTO City (Id,Name,Population,Country) VALUES (2,'Hamburg',1800000,'Germany'); INSERT INTO City (Id,Name,Population,Country) VALUES (3,'Madrid',3200000,'Spain'); INSERT INTO City (Id,Name,Population,Country) VALUES (4,'Barcelona',1600000,'Spain'); | SELECT Country, AVG(Population) as AvgPopulation FROM City WHERE Country IN ('Germany', 'Spain') GROUP BY Country; |
what is the total number of emergency medical services calls in Los Angeles in Q1 2022? | CREATE TABLE la_ems_calls (id INT,call_type TEXT,call_date DATE); INSERT INTO la_ems_calls (id,call_type,call_date) VALUES (1,'Medical','2022-01-01'),(2,'Trauma','2022-02-01'),(3,'Cardiac','2022-03-01'); | SELECT COUNT(*) FROM la_ems_calls WHERE QUARTER(call_date) = 1 AND YEAR(call_date) = 2022; |
What is the average quantity of sustainable fabrics sourced from Europe in the past year? | CREATE TABLE Sustainable_Fabrics (fabric_id INT,fabric_name VARCHAR(50),sourcing_country VARCHAR(50),quantity INT); INSERT INTO Sustainable_Fabrics (fabric_id,fabric_name,sourcing_country,quantity) VALUES (1,'Organic Cotton','France',500),(2,'Recycled Polyester','Germany',700),(3,'Tencel','Austria',600); | SELECT AVG(quantity) FROM Sustainable_Fabrics WHERE sourcing_country IN ('France', 'Germany', 'Austria') AND sourcing_country IS NOT NULL AND fabric_name IS NOT NULL AND quantity IS NOT NULL; |
What is the total amount donated by each program category? | CREATE TABLE ProgramDonations (DonationID int,ProgramID int,DonationAmount numeric(10,2),DonationDate date); CREATE TABLE Programs (ProgramID int,ProgramName varchar(50),ProgramCategory varchar(50),ProgramImpactScore numeric(3,1)); INSERT INTO ProgramDonations (DonationID,ProgramID,DonationAmount,DonationDate) VALUES (1,1,500,'2021-01-15'),(2,2,350,'2021-03-22'),(3,3,700,'2021-05-18'); INSERT INTO Programs (ProgramID,ProgramName,ProgramCategory,ProgramImpactScore) VALUES (1,'Education for All','Children',8.5),(2,'Healthcare for the Needy','Children',7.8),(3,'Nutrition for Seniors','Elderly',9.2); | SELECT Programs.ProgramCategory, SUM(ProgramDonations.DonationAmount) as TotalDonated FROM Programs INNER JOIN ProgramDonations ON Programs.ProgramID = ProgramDonations.ProgramID GROUP BY Programs.ProgramCategory; |
Count the number of publications in the 'Journal of Engineering' | CREATE TABLE publications (id INT,title VARCHAR(50),journal VARCHAR(30)); INSERT INTO publications (id,title,journal) VALUES (1,'A Study on Renewable Energy','Journal of Engineering'),(2,'The Impact of Climate Change','Journal of Natural Sciences'); | SELECT COUNT(*) FROM publications WHERE journal = 'Journal of Engineering'; |
List the names of all donors who have donated in a specific year, based on the 'donations' and 'donors' tables? | CREATE TABLE donors (id INT,name TEXT,email TEXT);CREATE TABLE donations (id INT,donor_id INT,amount DECIMAL(10,2),donation_date DATE); | SELECT donors.name FROM donors INNER JOIN donations ON donors.id = donations.donor_id WHERE YEAR(donations.donation_date) = 2021 GROUP BY donors.name; |
How many volunteers joined each month in 2023? | CREATE TABLE volunteer_registration (id INT,name VARCHAR(50),registration_date DATE); INSERT INTO volunteer_registration (id,name,registration_date) VALUES (1,'Alice','2023-01-05'); INSERT INTO volunteer_registration (id,name,registration_date) VALUES (2,'Bob','2023-02-10'); | SELECT EXTRACT(MONTH FROM registration_date) as month, COUNT(DISTINCT name) as volunteers_joined FROM volunteer_registration WHERE registration_date BETWEEN '2023-01-01' AND '2023-12-31' GROUP BY month; |
What are the names of all wells in 'Nigeria'? | CREATE TABLE wells (well_id INT,well_name VARCHAR(50),country VARCHAR(50)); INSERT INTO wells (well_id,well_name,country) VALUES (1,'WellA','Nigeria'),(2,'WellB','Nigeria'),(3,'WellC','USA'); | SELECT well_name FROM wells WHERE country = 'Nigeria'; |
Which companies have oil production facilities in the Middle East? | CREATE TABLE facility_operators (facility_id INT,operator_name VARCHAR(50)); | SELECT DISTINCT facility_operators.operator_name FROM facility_operators INNER JOIN production_facilities ON facility_operators.facility_id = production_facilities.facility_id WHERE production_facilities.location LIKE '%Middle East%'; |
Insert new records into the flights table for a flight from Sydney, Australia to Auckland, New Zealand | CREATE TABLE flights (id INT PRIMARY KEY,carrier VARCHAR(3),flight_number INT,origin VARCHAR(3),destination VARCHAR(3),scheduled_departure TIMESTAMP,scheduled_arrival TIMESTAMP); | INSERT INTO flights (carrier, flight_number, origin, destination, scheduled_departure, scheduled_arrival) VALUES ('QF', 45, 'SYD', 'AKL', '2022-12-01 09:00:00', '2022-12-01 15:00:00'); |
What is the average budget allocated for bioprocess engineering R&D in startups located in the United States? | CREATE TABLE startups (id INT,name VARCHAR(255),location VARCHAR(255),budget FLOAT); INSERT INTO startups (id,name,location,budget) VALUES (1,'StartupA','USA',5000000); INSERT INTO startups (id,name,location,budget) VALUES (2,'StartupB','USA',7000000); | SELECT AVG(budget) FROM startups WHERE location = 'USA' AND category = 'bioprocess engineering'; |
How many members have a favorite class starting with the letter 'Y'? | CREATE TABLE members (id INT,name VARCHAR(50),age INT,favorite_class VARCHAR(50)); INSERT INTO members (id,name,age,favorite_class) VALUES (1,'John Doe',30,'Cycling'),(2,'Jane Smith',40,'Yoga'),(3,'Mike Johnson',50,'Yoga'),(4,'Nancy Adams',60,'Zumba'); | SELECT COUNT(*) FROM members WHERE favorite_class LIKE 'Y%'; |
Which sustainable materials are used by factories in Africa? | CREATE TABLE Factories (factory_id INT,factory_name VARCHAR(50),country VARCHAR(50),certification VARCHAR(50)); CREATE TABLE Factory_Materials (factory_id INT,material_id INT); CREATE TABLE Materials (material_id INT,material_name VARCHAR(50),is_sustainable BOOLEAN); INSERT INTO Factories (factory_id,factory_name,country,certification) VALUES (1,'GreenAfrica','Kenya'),(2,'EcoTech','South Africa'),(3,'SustainableWest','Nigeria'); INSERT INTO Materials (material_id,material_name,is_sustainable) VALUES (1,'Organic Cotton',true),(2,'Synthetic Fiber',false),(3,'Recycled Plastic',true); INSERT INTO Factory_Materials (factory_id,material_id) VALUES (1,1),(1,3),(2,1),(2,3),(3,3); | SELECT m.material_name FROM Factories f INNER JOIN Factory_Materials fm ON f.factory_id = fm.factory_id INNER JOIN Materials m ON fm.material_id = m.material_id WHERE f.country IN ('Kenya', 'South Africa', 'Nigeria') AND m.is_sustainable = true; |
What is the trend of mental health scores by age group? | CREATE TABLE student_mental_health (student_id INT,score INT,age INT); INSERT INTO student_mental_health (student_id,score,age) VALUES (1,80,15),(1,85,16),(2,70,15),(2,75,16),(3,90,15),(3,95,16); | SELECT age, AVG(score) as avg_score FROM student_mental_health GROUP BY age ORDER BY age; |
What is the total amount of funds spent on refugee support in Africa? | CREATE TABLE funds (id INT,category TEXT,region TEXT,amount DECIMAL(10,2)); INSERT INTO funds (id,category,region,amount) VALUES (1,'Refugee Support','Middle East',250000.00),(2,'Disaster Response','Asia',300000.00),(3,'Community Development','Africa',150000.00),(4,'Refugee Support','Africa',50000.00),(5,'Refugee Support','Africa',75000.00); | SELECT SUM(amount) FROM funds WHERE category = 'Refugee Support' AND region = 'Africa'; |
What is the sum of safety ratings for vehicles at the Paris Auto Show? | CREATE TABLE VehicleSafetyTotal (VehicleID INT,SafetyRating INT,ShowName TEXT); | SELECT SUM(SafetyRating) FROM VehicleSafetyTotal WHERE ShowName = 'Paris Auto Show'; |
What is the maximum water temperature for each species, grouped by species, from the 'fish_stock' and 'ocean_health' tables? | CREATE TABLE fish_stock (species VARCHAR(255),water_temp FLOAT); CREATE TABLE ocean_health (species VARCHAR(255),water_temp FLOAT); INSERT INTO fish_stock (species,water_temp) VALUES ('Tuna',24.5),('Mackerel',21.2); INSERT INTO ocean_health (species,water_temp) VALUES ('Tuna',25.1),('Mackerel',22.0); | SELECT f.species, MAX(f.water_temp) FROM fish_stock f INNER JOIN ocean_health o ON f.species = o.species GROUP BY f.species; |
How many players who identify as genderfluid have used VR technology in gaming? | CREATE TABLE PlayerIdentities (PlayerID INT,Identity VARCHAR(50)); INSERT INTO PlayerIdentities (PlayerID,Identity) VALUES (1,'Male'),(2,'Female'),(3,'Non-Binary'),(4,'Genderfluid'),(5,'Male'),(6,'Female'),(7,'Genderfluid'); CREATE TABLE PlayerTechnologies (PlayerID INT,Technology VARCHAR(50)); INSERT INTO PlayerTechnologies (PlayerID,Technology) VALUES (1,'VR'),(2,'Non-VR'),(3,'AR'),(4,'VR'),(5,'VR'),(6,'AR'),(7,'VR'); | (SELECT COUNT(*) FROM PlayerIdentities JOIN PlayerTechnologies ON PlayerIdentities.PlayerID = PlayerTechnologies.PlayerID WHERE PlayerIdentities.Identity = 'Genderfluid' AND PlayerTechnologies.Technology = 'VR') |
How many satellites were launched per month by SpaceX? | CREATE TABLE spacex_missions (mission_id INT,launch_date DATE);CREATE TABLE satellites (satellite_id INT,mission_id INT,launch_date DATE); | SELECT DATE_FORMAT(satellites.launch_date, '%Y-%m') AS launch_month, COUNT(satellites.satellite_id) FROM satellites INNER JOIN spacex_missions ON satellites.mission_id = spacex_missions.mission_id GROUP BY launch_month ORDER BY launch_month; |
Count the number of marine species in each conservation status, ordered by the count | CREATE TABLE marine_species (id INT PRIMARY KEY,species_name VARCHAR(255),conservation_status VARCHAR(50)); | SELECT conservation_status, COUNT(*) AS species_count FROM marine_species GROUP BY conservation_status ORDER BY species_count DESC; |
What is the average water consumption per household in the city of San Francisco? | CREATE TABLE Household (id INT,city VARCHAR(20),water_consumption FLOAT); INSERT INTO Household (id,city,water_consumption) VALUES (1,'San Francisco',150),(2,'San Francisco',200),(3,'Oakland',180); | SELECT AVG(water_consumption) FROM Household WHERE city = 'San Francisco'; |
How many social good technology projects were completed in Q1, Q2, Q3, and Q4 of 2021, categorized by project status? | CREATE TABLE Social_Good_Tech_Quarters (quarter VARCHAR(10),status VARCHAR(20),projects INT); INSERT INTO Social_Good_Tech_Quarters (quarter,status,projects) VALUES ('Q1','completed',20),('Q1','in_progress',15),('Q2','completed',25),('Q2','in_progress',20),('Q3','completed',30),('Q3','in_progress',25),('Q4','completed',35),('Q4','in_progress',30); | SELECT Social_Good_Tech_Quarters.quarter, Social_Good_Tech_Quarters.status, SUM(Social_Good_Tech_Quarters.projects) FROM Social_Good_Tech_Quarters WHERE Social_Good_Tech_Quarters.quarter IN ('Q1', 'Q2', 'Q3', 'Q4') GROUP BY Social_Good_Tech_Quarters.quarter, Social_Good_Tech_Quarters.status; |
Insert a new space debris record into the "space_debris_monitoring" table for an object launched by India in 2008. | CREATE TABLE space_debris_monitoring (id INT,object_name VARCHAR(50),launch_country VARCHAR(50),launch_date DATE,latitude FLOAT,longitude FLOAT); | INSERT INTO space_debris_monitoring (object_name, launch_country, launch_date, latitude, longitude) VALUES ('Debris_2008_India', 'India', '2008-01-01', 10.123456, 20.123456); |
What is the median financial wellbeing score for rural households in Africa? | CREATE TABLE financial_wellbeing_rural (id INT,household_id INT,region VARCHAR(255),score FLOAT); | SELECT MEDIAN(score) FROM financial_wellbeing_rural WHERE household_id <= 50000 AND region = 'Africa'; |
Find the total number of employees in companies with circular economy initiatives in France. | CREATE TABLE companies (id INT,name TEXT,country TEXT,circular_economy BOOLEAN); INSERT INTO companies (id,name,country,circular_economy) VALUES (1,'ABC Corp','France',TRUE),(2,'DEF Corp','Germany',FALSE),(3,'GHI Corp','France',TRUE); | SELECT COUNT(*) FROM companies WHERE country = 'France' AND circular_economy = TRUE; |
Delete records with a funding amount of 0 for biotech startups in Q3 2021. | CREATE TABLE biotech_startups(id INT,company_name TEXT,location TEXT,funding_amount DECIMAL(10,2),quarter INT,year INT); | DELETE FROM biotech_startups WHERE funding_amount = 0 AND quarter = 3 AND year = 2021; |
List the top 5 most active volunteers by total hours in Q1 2022, grouped by their organization? | CREATE TABLE volunteer_hours (hour_id INT,volunteer_id INT,hours_spent FLOAT,hour_date DATE,volunteer_org TEXT); INSERT INTO volunteer_hours (hour_id,volunteer_id,hours_spent,hour_date,volunteer_org) VALUES (1,1,3,'2022-01-01','Greenpeace'); INSERT INTO volunteer_hours (hour_id,volunteer_id,hours_spent,hour_date,volunteer_org) VALUES (2,2,5,'2022-01-03','WHO'); | SELECT volunteer_org, volunteer_id, SUM(hours_spent) AS total_hours FROM volunteer_hours WHERE EXTRACT(MONTH FROM hour_date) BETWEEN 1 AND 3 GROUP BY volunteer_org, volunteer_id ORDER BY total_hours DESC FETCH FIRST 5 ROWS ONLY; |
What is the average donation amount from donors aged 25-34 in the United States? | CREATE TABLE Donors (DonorID INT,Age INT,Country VARCHAR(50)); INSERT INTO Donors (DonorID,Age,Country) VALUES (1,27,'United States'),(2,32,'United States'),(3,24,'Canada'); | SELECT AVG(DonationAmount) FROM Donors JOIN Donations ON Donors.DonorID = Donations.DonorID WHERE Donors.Country = 'United States' AND Donors.Age BETWEEN 25 AND 34; |
What is the average price of ethically sourced products, grouped by category? | CREATE TABLE products (product_id INT,category VARCHAR(255),price DECIMAL(5,2),ethically_sourced BOOLEAN); INSERT INTO products (product_id,category,price,ethically_sourced) VALUES (1,'Electronics',200.00,true); | SELECT category, AVG(price) AS avg_price FROM products WHERE ethically_sourced = true GROUP BY category; |
What is the total number of animals in each region? | CREATE TABLE animals_by_region (region VARCHAR(255),num_animals INT); INSERT INTO animals_by_region (region,num_animals) VALUES ('Africa',402000),('Asia',300000); | SELECT region, SUM(num_animals) FROM animals_by_region GROUP BY region; |
What is the average number of accommodations provided, per country? | CREATE TABLE Accommodations (ID INT PRIMARY KEY,Country VARCHAR(50),AccommodationType VARCHAR(50),Quantity INT); INSERT INTO Accommodations (ID,Country,AccommodationType,Quantity) VALUES (1,'USA','Sign Language Interpretation',300),(2,'Canada','Wheelchair Ramp',250),(3,'Mexico','Assistive Listening Devices',150); | SELECT Country, AVG(Quantity) as Average FROM Accommodations GROUP BY Country; |
What is the maximum number of military personnel in Asia who have received training in military technology in the past 5 years? | CREATE TABLE military_personnel (id INT,name VARCHAR(50),country VARCHAR(50),training_history TEXT); INSERT INTO military_personnel (id,name,country,training_history) VALUES (1,'John Doe','China','AI training,2021'); CREATE TABLE countries (id INT,name VARCHAR(50),region VARCHAR(50)); INSERT INTO countries (id,name,region) VALUES (1,'China','Asia'); | SELECT MAX(count(*)) FROM military_personnel m JOIN countries c ON m.country = c.name WHERE c.region = 'Asia' AND m.training_history LIKE '%[0-9]% training,[0-9][0-9][0-9][0-9]%' GROUP BY YEAR(SUBSTRING(m.training_history, INSTR(m.training_history, ',') + 1, 4)); |
What is the total grant amount awarded to graduate students in the Humanities department for the year 2021? | CREATE TABLE graduate_students (id INT,name VARCHAR(50),department VARCHAR(50)); INSERT INTO graduate_students (id,name,department) VALUES (1,'Charlie','Computer Science'); INSERT INTO graduate_students (id,name,department) VALUES (2,'Dana','Electrical Engineering'); INSERT INTO graduate_students (id,name,department) VALUES (3,'Eli','Arts'); INSERT INTO graduate_students (id,name,department) VALUES (4,'Fiona','Humanities'); CREATE TABLE research_grants (id INT,graduate_student_id INT,amount DECIMAL(10,2),year INT); INSERT INTO research_grants (id,graduate_student_id,amount,year) VALUES (1,4,10000,2021); INSERT INTO research_grants (id,graduate_student_id,amount,year) VALUES (2,4,15000,2021); | SELECT SUM(rg.amount) FROM research_grants rg JOIN graduate_students gs ON rg.graduate_student_id = gs.id WHERE gs.department = 'Humanities' AND rg.year = 2021; |
Update the "price" column in the "carbon_prices" table to 28 for records where the "country" is 'France' | CREATE TABLE carbon_prices (id INT PRIMARY KEY,country VARCHAR(50),price DECIMAL(5,2)); INSERT INTO carbon_prices (id,country,price) VALUES (1,'Germany',20),(2,'France',18),(3,'Spain',22); | UPDATE carbon_prices SET price = 28 WHERE country = 'France'; |
What is the minimum number of posts made by a user who has made at least one post on a weekend in the 'social_media' table, assuming the 'post_date' column is of type DATE? | CREATE TABLE social_media (user_id INT,post_id INT,post_date DATE); | SELECT MIN(COUNT(*)) FROM social_media WHERE DATE_PART('dow', post_date) IN (0, 6) GROUP BY user_id HAVING COUNT(*) > 0; |
How many volunteers engaged in each program and the total number of volunteer hours per program? | CREATE TABLE Volunteers (VolunteerID int,Program varchar(20),Hours numeric); INSERT INTO Volunteers (VolunteerID,Program,Hours) VALUES (1,'Feeding the Homeless',10),(2,'Tutoring Kids',20),(3,'Feeding the Homeless',15); | SELECT Program, COUNT(*) as NumVolunteers, SUM(Hours) as TotalHours FROM Volunteers GROUP BY Program; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.