instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
List all broadband customers in California who have a plan with speeds greater than 100 Mbps. | CREATE TABLE broadband_customers (customer_id INT,name VARCHAR(50),plan_speed FLOAT,state VARCHAR(20)); INSERT INTO broadband_customers (customer_id,name,plan_speed,state) VALUES (1,'Jane Smith',150,'California'); | SELECT * FROM broadband_customers WHERE state = 'California' AND plan_speed > 100; |
Which metro lines have the most delays? | CREATE TABLE Lines(id INT,name TEXT); CREATE TABLE Delays(line_id INT,delay TIME); | SELECT Lines.name, COUNT(*) FROM Lines JOIN Delays ON Lines.id = Delays.line_id GROUP BY Lines.name ORDER BY COUNT(*) DESC; |
Count the number of animals in each habitat | CREATE TABLE habitats (id INT,name VARCHAR(255)); INSERT INTO habitats (id,name) VALUES (1,'Forest'),(2,'Savannah'),(3,'Wetlands'); CREATE TABLE animals (id INT,name VARCHAR(255),habitat_id INT); INSERT INTO animals (id,name,habitat_id) VALUES (1,'Lion',2),(2,'Elephant',1),(3,'Hippo',3),(4,'Giraffe',2),(5,'Duck',3); | SELECT habitats.name, COUNT(animals.id) AS animal_count FROM habitats JOIN animals ON habitats.id = animals.habitat_id GROUP BY habitats.name; |
What is the average water temperature in each region for the past week? | CREATE TABLE water_temps (id INT,region TEXT,date DATE,temp FLOAT); INSERT INTO water_temps (id,region,date,temp) VALUES (1,'North','2022-01-01',12.3),(2,'South','2022-01-01',14.2),(3,'North','2022-01-02',12.4),(4,'South','2022-01-02',14.1); | SELECT region, AVG(temp) FROM water_temps WHERE date >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) GROUP BY region; |
Total financial wellbeing score for the United States. | CREATE TABLE financial_wellbeing_2 (id INT,country VARCHAR(20),score INT); INSERT INTO financial_wellbeing_2 (id,country,score) VALUES (1,'United States',75); | SELECT SUM(score) FROM financial_wellbeing_2 WHERE country = 'United States'; |
What is the total number of users in each country? | CREATE TABLE Users (UserID INT,Country VARCHAR(255)); INSERT INTO Users (UserID,Country) VALUES (1,'USA'),(2,'Canada'),(3,'USA'); | SELECT Country, COUNT(*) FROM Users GROUP BY Country; |
Which districts have the highest total budget for public services? | CREATE TABLE districts (id INT,name TEXT,budget INT); | SELECT d.name, SUM(s.budget) as total_budget FROM districts d JOIN schools s ON d.id = s.district_id GROUP BY d.name ORDER BY total_budget DESC LIMIT 1; |
What is the maximum number of public transportation trips taken in a day in CityD? | CREATE TABLE trips (id INT,date DATE,mode VARCHAR(20)); INSERT INTO trips VALUES (1,'2022-01-01','Bus'),(2,'2022-01-02','Train'),(3,'2022-01-03','Subway'),(4,'2022-01-04','Bus'),(5,'2022-01-05','Train'); | SELECT MAX(count) FROM (SELECT date, COUNT(*) AS count FROM trips GROUP BY date) AS temp WHERE date = (SELECT MAX(date) FROM trips); |
Find the average funding amount per industry | CREATE TABLE companies (id INT,industry VARCHAR(255),funding_amount DECIMAL(10,2)); INSERT INTO companies (id,industry,funding_amount) VALUES (1,'Tech',50000.00),(2,'Biotech',20000.00),(3,'Tech',75000.00); | SELECT industry, AVG(funding_amount) FROM companies GROUP BY industry; |
Which deep-sea expeditions have discovered new marine life forms? | CREATE TABLE deep_sea_expeditions (expedition_name TEXT,year INTEGER,discovered_new_species BOOLEAN); INSERT INTO deep_sea_expeditions (expedition_name,year,discovered_new_species) VALUES ('Challenger Expedition',1872,TRUE),('Galathea Expedition',1950,FALSE); | SELECT expedition_name FROM deep_sea_expeditions WHERE discovered_new_species = TRUE; |
How many articles were published per month in the 'technology' category over the last 2 years? | CREATE TABLE articles (id INT,title TEXT,category TEXT,publish_date DATE); INSERT INTO articles (id,title,category,publish_date) VALUES (1,'Article Title 1','technology','2020-02-01'),(2,'Article Title 2','technology','2022-06-05'); | SELECT DATE_FORMAT(publish_date, '%Y-%m') AS pub_month, COUNT(*) AS num_articles FROM articles WHERE category = 'technology' AND publish_date >= NOW() - INTERVAL 2 YEAR GROUP BY pub_month ORDER BY pub_month; |
What is the number of hotels in Africa that have adopted AI technology and offer virtual tours? | CREATE TABLE ai_hotels (hotel_id INT,hotel_name TEXT,country TEXT,ai_adoption BOOLEAN,virtual_tour BOOLEAN); INSERT INTO ai_hotels (hotel_id,hotel_name,country,ai_adoption,virtual_tour) VALUES (1,'Hotel X','Africa',true,true),(2,'Hotel Y','Europe',true,false),(3,'Hotel Z','Africa',false,true); | SELECT COUNT(*) FROM ai_hotels WHERE country = 'Africa' AND ai_adoption = true AND virtual_tour = true; |
What is the total revenue generated by museum stores in the last month? | CREATE TABLE MuseumStores (id INT,location VARCHAR(50),date DATE,revenue DECIMAL(5,2)); INSERT INTO MuseumStores (id,location,date,revenue) VALUES (1,'New York','2022-01-01',100.00),(2,'Los Angeles','2022-01-02',200.00),(3,'New York','2022-01-03',300.00); | SELECT SUM(revenue) FROM MuseumStores WHERE date >= DATEADD(month, -1, GETDATE()); |
Create a view named 'virtual_tour_stats_summary' that shows the number of virtual tours and the average view duration for each hotel_id in the 'virtual_tour_stats' table | CREATE TABLE virtual_tour_stats (hotel_id INT,view_date DATE,view_duration INT); | CREATE VIEW virtual_tour_stats_summary AS SELECT hotel_id, COUNT(*), AVG(view_duration) FROM virtual_tour_stats GROUP BY hotel_id; |
How many LEED certified buildings are there in the 'GreenBuildings' table that have a square footage greater than 40,000? | CREATE TABLE GreenBuildings (id INT,name VARCHAR(50),squareFootage INT,certification VARCHAR(10)); INSERT INTO GreenBuildings (id,name,squareFootage,certification) VALUES (1,'EcoTower',50000,'LEED Platinum'),(2,'SolarHills',75000,'LEED Gold'),(3,'GreenHaven',35000,'LEED Silver'); | SELECT COUNT(*) FROM GreenBuildings WHERE squareFootage > 40000 AND certification = 'LEED'; |
What is the number of rural women-led businesses in the state of Karnataka, India, that have adopted sustainable agricultural practices? | CREATE TABLE businesses_india (business_id INT,state TEXT,owner_gender TEXT,sustainable_practices BOOLEAN); INSERT INTO businesses_india (business_id,state,owner_gender,sustainable_practices) VALUES (1,'Karnataka','Female',TRUE),(2,'Karnataka','Male',FALSE),(3,'Karnataka','Female',TRUE); | SELECT COUNT(*) as num_women_led_sustainable FROM businesses_india WHERE state = 'Karnataka' AND owner_gender = 'Female' AND sustainable_practices = TRUE; |
List all the designers who have created VR games, along with the average age of players who have played their games. | CREATE TABLE Designers (DesignerID INT,DesignerName VARCHAR(50),Age INT); CREATE TABLE VR_Games (GameID INT,GameName VARCHAR(50),Genre VARCHAR(20),DesignerID INT); CREATE TABLE GamePlayer (PlayerID INT,GameID INT); CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10)); | SELECT Designers.DesignerName, AVG(Players.Age) FROM Designers INNER JOIN VR_Games ON Designers.DesignerID = VR_Games.DesignerID INNER JOIN GamePlayer ON VR_Games.GameID = GamePlayer.GameID INNER JOIN Players ON GamePlayer.PlayerID = Players.PlayerID GROUP BY Designers.DesignerName; |
What are the names and locations of the local businesses in 'Europe' with a tourism impact lower than 2000? | CREATE TABLE LocalBusinesses (BusinessID INTEGER,BusinessName TEXT,Location TEXT,TourismImpact INTEGER); INSERT INTO LocalBusinesses (BusinessID,BusinessName,Location,TourismImpact) VALUES (1,'Family-Owned Restaurant','Italy',1500),(2,'Artisanal Bakery','France',800),(3,'Handmade Jewelry Shop','Spain',1200),(4,'Local Winery','Germany',3000),(5,'Traditional Brewery','Ireland',2500); | SELECT BusinessName, Location FROM LocalBusinesses WHERE Location = 'Europe' AND TourismImpact < 2000; |
How many mobile customers have a postpaid subscription in the country of Australia? | CREATE TABLE mobile_subscribers (subscriber_id INT,subscription_type VARCHAR(10),country VARCHAR(20)); INSERT INTO mobile_subscribers (subscriber_id,subscription_type,country) VALUES (1,'postpaid','Australia'),(2,'prepaid','Australia'),(3,'postpaid','Australia'); | SELECT COUNT(*) FROM mobile_subscribers WHERE subscription_type = 'postpaid' AND country = 'Australia'; |
List all the platforms located in the 'Gulf of Mexico' | CREATE TABLE platforms (platform_name TEXT,location TEXT); INSERT INTO platforms (platform_name,location) VALUES ('Platform A','Gulf of Mexico'),('Platform B','North Sea'),('Platform C','Gulf of Mexico'); | SELECT platform_name FROM platforms WHERE location = 'Gulf of Mexico'; |
What is the minimum funding received by a startup in the 'genetic research' sector? | CREATE TABLE startups (id INT,name VARCHAR(50),sector VARCHAR(50),funding FLOAT); INSERT INTO startups (id,name,sector,funding) VALUES (1,'Genetech','genetic research',2000000),(2,'BioVentures','bioprocess engineering',1500000),(3,'NanoBio','biosensor technology',1000000); | SELECT MIN(funding) FROM startups WHERE sector = 'genetic research'; |
What is the average number of members in all unions? | CREATE TABLE union_membership (id INT,union VARCHAR(20),member_count INT); INSERT INTO union_membership (id,union,member_count) VALUES (1,'construction',3500),(2,'education',8000),(3,'manufacturing',5000); | SELECT AVG(member_count) FROM union_membership; |
What are the top 3 most common vulnerabilities in the 'Web Applications' category in the last 6 months? | CREATE TABLE vulnerabilities (id INT,timestamp TIMESTAMP,category VARCHAR(255),vulnerability VARCHAR(255),severity VARCHAR(255)); INSERT INTO vulnerabilities (id,timestamp,category,vulnerability,severity) VALUES (1,'2022-01-01 10:00:00','Web Applications','SQL Injection','High'),(2,'2022-01-01 10:00:00','Web Applications','Cross-site Scripting','Medium'); | SELECT category, vulnerability, COUNT(*) as vulnerability_count FROM vulnerabilities WHERE timestamp >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 6 MONTH) AND category = 'Web Applications' GROUP BY category, vulnerability ORDER BY vulnerability_count DESC LIMIT 3; |
How many public schools and public libraries exist in total, in the 'CityData' schema's 'CityEducation' and 'CityLibrary' tables, | CREATE SCHEMA CityData; CREATE TABLE CityEducation (Name varchar(255),Type varchar(255)); INSERT INTO CityEducation (Name,Type) VALUES ('SchoolA','Public'),('SchoolB','Public'),('SchoolC','Private'); CREATE TABLE CityLibrary (Name varchar(255),Type varchar(255)); INSERT INTO CityLibrary (Name,Type) VALUES ('LibraryA','Public'),('LibraryB','Public'),('LibraryC','Private'); | SELECT COUNT(*) FROM CityData.CityEducation WHERE Type = 'Public' INTERSECT SELECT COUNT(*) FROM CityData.CityLibrary WHERE Type = 'Public'; |
What is the total number of tourists who visited Asian countries in 2019 and 2020? | CREATE TABLE Tourist_Arrivals (id INT,country_id INT,year INT,visitors INT,FOREIGN KEY (country_id) REFERENCES Countries(id)); INSERT INTO Tourist_Arrivals (id,country_id,year,visitors) VALUES (1,3,2019,9000000); INSERT INTO Tourist_Arrivals (id,country_id,year,visitors) VALUES (2,4,2019,6000000); INSERT INTO Tourist_Arrivals (id,country_id,year,visitors) VALUES (3,3,2020,10000000); INSERT INTO Tourist_Arrivals (id,country_id,year,visitors) VALUES (4,4,2020,7000000); | SELECT SUM(t.visitors) as total_visitors FROM Tourist_Arrivals t WHERE t.year IN (2019, 2020) AND t.country_id IN (SELECT id FROM Countries WHERE continent = 'Asia'); |
What are the average distances from Earth for all space missions to each planet in our solar system? | CREATE TABLE SpaceMissions (MissionID INT,DestinationPlanet VARCHAR,AverageDistance FLOAT); | SELECT DestinationPlanet, AVG(AverageDistance) FROM SpaceMissions GROUP BY DestinationPlanet; |
What is the average CO2 offset of carbon offset initiatives in the United Kingdom? | CREATE TABLE carbon_offsets (id INT,initiative_name VARCHAR(100),co2_offset FLOAT); INSERT INTO carbon_offsets (id,initiative_name,co2_offset) VALUES (1,'Green Transport UK',1234.5),(2,'Renewable Energy UK',678.9),(3,'Energy Efficiency UK',345.6); | SELECT AVG(co2_offset) FROM carbon_offsets WHERE country = 'United Kingdom'; |
List all unique countries from which donations were received in 2022. | CREATE TABLE Donations (id INT,donor_name VARCHAR(50),donation_amount DECIMAL(10,2),donation_date DATE,donor_location VARCHAR(50)); | SELECT DISTINCT donor_location FROM Donations WHERE donation_date BETWEEN '2022-01-01' AND '2022-12-31'; |
What is the name of the graduate student who received the largest research grant in the past year? | CREATE TABLE students (student_id INT,name TEXT); INSERT INTO students (student_id,name) VALUES (1,'Alice Johnson'),(2,'Bob Brown'); CREATE TABLE grants (grant_id INT,student_id INT,year INT,amount INT); INSERT INTO grants (grant_id,student_id,year,amount) VALUES (1,1,2021,10000),(2,2,2022,20000); | SELECT s.name FROM students s INNER JOIN (SELECT student_id, MAX(amount) as max_amount FROM grants WHERE year = 2022 GROUP BY student_id) g ON s.student_id = g.student_id WHERE g.max_amount = (SELECT MAX(amount) FROM grants WHERE year = 2022); |
Update the record of the virtual tour in Paris with a new link. | CREATE TABLE virtual_tours (tour_id INT,title TEXT,city TEXT,link TEXT); INSERT INTO virtual_tours (tour_id,title,city,link) VALUES (1,'Paris Virtual Tour','Paris','old_link'); | UPDATE virtual_tours SET link = 'new_link' WHERE tour_id = 1 AND city = 'Paris'; |
What is the average rainfall for all regions growing 'Quinoa'? | CREATE TABLE farm (id INT PRIMARY KEY,name VARCHAR(50),region_id INT,avg_rainfall DECIMAL(5,2)); CREATE TABLE region (id INT PRIMARY KEY,name VARCHAR(50)); INSERT INTO region (id,name) VALUES (1,'Andes'),(2,'Altiplano'); INSERT INTO farm (id,name,region_id,avg_rainfall) VALUES (1,'Quinoa Farm 1',1,450.1),(2,'Quinoa Farm 2',1,460.2),(3,'Quinoa Farm 3',2,500.0); | SELECT AVG(f.avg_rainfall) FROM farm f INNER JOIN region r ON f.region_id = r.id WHERE r.name IN (SELECT name FROM region WHERE id IN (SELECT region_id FROM farm WHERE name = 'Quinoa')); |
What is the total number of healthcare access metrics for indigenous communities? | CREATE TABLE healthcare_access (id INT,community TEXT,metric TEXT); INSERT INTO healthcare_access (id,community,metric) VALUES (1,'Indigenous A','Accessibility'),(2,'Indigenous B','Availability'),(3,'Indigenous A','Quality'); | SELECT COUNT(DISTINCT community) FROM healthcare_access WHERE community LIKE '%Indigenous%'; |
What is the maximum depth of marine protected areas in the Pacific Ocean? | CREATE TABLE marine_protected_areas (name VARCHAR(255),area_id INT,depth FLOAT,size INT,country VARCHAR(255)); INSERT INTO marine_protected_areas (name,area_id,depth,size,country) VALUES ('Palau National Marine Sanctuary',5,3000,500000,'Palau'),('Phoenix Islands Protected Area',6,5000,408000,'Kiribati'); | SELECT MAX(depth) FROM marine_protected_areas WHERE country = 'Pacific Ocean'; |
What is the average production output for each machine in the company's facility in India? | CREATE TABLE production_output (output_id INT,machine_id INT,production_date DATE,output_quantity INT); INSERT INTO production_output (output_id,machine_id,production_date,output_quantity) VALUES (5,3,'2022-07-01',200),(6,3,'2022-07-02',220),(7,4,'2022-07-01',250),(8,4,'2022-07-02',260); CREATE TABLE facilities (facility_id INT,facility_name VARCHAR(255),country VARCHAR(255)); INSERT INTO facilities (facility_id,facility_name,country) VALUES (3,'Mumbai Plant','India'),(4,'New Delhi Plant','India'),(5,'Bangalore Plant','India'); | SELECT machine_id, AVG(output_quantity) as avg_output FROM production_output po JOIN facilities f ON f.facility_name = 'Mumbai Plant' WHERE po.production_date BETWEEN '2022-07-01' AND '2022-12-31' GROUP BY machine_id; |
List all courts with their average case duration, in descending order of average duration? | CREATE TABLE courts (court_id INT,name VARCHAR(50)); INSERT INTO courts (court_id,name) VALUES (1001,'Court A'),(1002,'Court B'),(1003,'Court C'); CREATE TABLE cases (case_id INT,court_id INT,duration INT); INSERT INTO cases (case_id,court_id,duration) VALUES (1,1001,30),(2,1001,45),(3,1002,60),(4,1002,75),(5,1003,90),(6,1003,105); | SELECT court_id, AVG(duration) as avg_duration FROM cases GROUP BY court_id ORDER BY avg_duration DESC; |
What is the vaccination rate for measles in Africa? | CREATE TABLE Disease (name VARCHAR(50),vaccination_rate FLOAT); INSERT INTO Disease (name,vaccination_rate) VALUES ('Nigeria',77.2),('South Africa',88.6); | SELECT AVG(vaccination_rate) FROM Disease WHERE name IN ('Nigeria', 'South Africa'); |
What is the maximum heart rate recorded for any member? | CREATE TABLE member_workouts (member_id INT,max_heart_rate INT); INSERT INTO member_workouts (member_id,max_heart_rate) VALUES (1,190),(2,170),(3,185),(4,160),(5,200); | SELECT MAX(max_heart_rate) FROM member_workouts; |
What is the average THC content of cannabis flower sold in Missouri dispensaries? | CREATE TABLE flower_sales (dispensary_id INT,thc_content DECIMAL(3,2),sale_date DATE); INSERT INTO flower_sales (dispensary_id,thc_content,sale_date) VALUES (1,25.3,'2022-01-01'),(2,23.5,'2022-02-01'),(3,24.6,'2022-01-15'); CREATE TABLE dispensaries (dispensary_id INT,state CHAR(2)); INSERT INTO dispensaries (dispensary_id,state) VALUES (1,'MO'),(2,'CA'),(3,'OR'); | SELECT AVG(thc_content) FROM flower_sales fs JOIN dispensaries d ON fs.dispensary_id = d.dispensary_id WHERE d.state = 'MO'; |
What is the total number of menu items sold in the Hawaii region? | CREATE TABLE menu (menu_id INT,menu_name TEXT,menu_type TEXT,price DECIMAL,daily_sales INT,region TEXT); | SELECT SUM(daily_sales) FROM menu WHERE region = 'Hawaii'; |
List all military innovation operations with a budget greater than $50 million, excluding those from countries with a defense expenditure lower than 3% of their GDP. | CREATE TABLE military_innovation_operations (id INT,operation VARCHAR(50),date DATE,budget INT,country VARCHAR(50),gdp DECIMAL(10,2),defense_expenditure DECIMAL(10,2)); INSERT INTO military_innovation_operations (id,operation,date,budget,country,gdp,defense_expenditure) VALUES (1,'Operation Lightning Bolt','2021-06-15',75000000,'United States',21433000,0.73),(2,'Operation Thunder Strike','2022-02-03',60000000,'China',16177000,1.9),(3,'Operation Iron Fist','2021-10-10',80000000,'Russia',16177000,4.3),(4,'Operation Northern Wind','2022-07-25',45000000,'Germany',3984300,1.5),(5,'Operation Red Storm','2021-03-09',50000000,'France',2813600,2.3),(6,'Operation Sky Shield','2022-09-18',90000000,'United Kingdom',2435000,2.2),(7,'Operation Pacific Vanguard','2022-12-12',40000000,'Japan',5364000,1); | SELECT * FROM military_innovation_operations WHERE budget > 50000000 AND defense_expenditure/gdp > 0.03; |
Identify and display any records in the decentralized_applications table that have launch_date in the next 30 days. | CREATE TABLE decentralized_applications (app_id INT PRIMARY KEY,name VARCHAR(255),category VARCHAR(50),launch_date DATETIME); | SELECT * FROM decentralized_applications WHERE launch_date BETWEEN CURRENT_DATE AND DATE_ADD(CURRENT_DATE, INTERVAL 30 DAY); |
Show the number of esports events hosted in the Asia-Pacific region | CREATE TABLE EsportsEvents (EventName VARCHAR(50),EventLocation VARCHAR(50)); INSERT INTO EsportsEvents (EventName,EventLocation) VALUES ('Asia-Pacific Games','Tokyo'); INSERT INTO EsportsEvents (EventName,EventLocation) VALUES ('North American Championships','New York'); | SELECT COUNT(*) FROM EsportsEvents WHERE EventLocation LIKE '%Asia-Pacific%'; |
What is the maximum playtime per user for players from Argentina, calculated for each day of the week? | CREATE TABLE GameSessions (SessionID INT,UserID INT,Playtime INT,SessionDate DATE); INSERT INTO GameSessions (SessionID,UserID,Playtime,SessionDate) VALUES (1,9,300,'2022-03-06'),(2,10,250,'2022-03-07'),(3,11,400,'2022-03-08'); | SELECT EXTRACT(DOW FROM SessionDate) AS Day, MAX(Playtime) FROM GameSessions WHERE Country = 'Argentina' GROUP BY Day; |
Delete records of players who have not played any game in the last 6 months | CREATE TABLE games (id INT PRIMARY KEY,player_id INT,game_name VARCHAR(100),last_played TIMESTAMP); INSERT INTO games VALUES (1,1001,'GameA','2021-01-01 12:00:00'),(2,1002,'GameB','2021-02-15 14:30:00'),(3,1003,'GameA','2021-06-20 09:15:00'); CREATE TABLE players (id INT PRIMARY KEY,name VARCHAR(50)); | DELETE FROM players WHERE id NOT IN (SELECT player_id FROM games WHERE last_played > DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 6 MONTH)); |
What is the average word count of reviews for products in the 'Eco-friendly' category in the last month? | CREATE TABLE products (id INT,name VARCHAR(50),category VARCHAR(50)); INSERT INTO products (id,name,category) VALUES (1,'Reusable Water Bottle','Eco-friendly'); CREATE TABLE reviews (id INT,product_id INT,review TEXT,review_date DATE); INSERT INTO reviews (id,product_id,review,review_date) VALUES (1,1,'Great quality and sustainable!','2022-03-20'); | SELECT AVG(LENGTH(r.review) - LENGTH(REPLACE(r.review, ' ', '')) + 1) as avg_word_count FROM reviews r JOIN products p ON r.product_id = p.id WHERE p.category = 'Eco-friendly' AND r.review_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 1 MONTH) AND CURDATE(); |
What is the average water salinity for fish farms in the 'Arctic Ocean' region? | CREATE TABLE fish_farms (id INT,name TEXT,region TEXT); INSERT INTO fish_farms (id,name,region) VALUES (1,'Farm A','Arctic Ocean'),(2,'Farm B','Antarctic Ocean'); CREATE TABLE water_quality (id INT,farm_id INT,region TEXT,salinity FLOAT); INSERT INTO water_quality (id,farm_id,region,salinity) VALUES (1,1,'Arctic Ocean',33.2),(2,1,'Arctic Ocean',33.3),(3,2,'Antarctic Ocean',34.1); | SELECT AVG(water_quality.salinity) FROM water_quality INNER JOIN fish_farms ON water_quality.farm_id = fish_farms.id WHERE fish_farms.region = 'Arctic Ocean'; |
Calculate the total value of defense projects in the Southeast Asia region that have not been completed yet, ordered by the sum in descending order. | CREATE TABLE defense_projects (id INT,project_name VARCHAR(255),region VARCHAR(255),start_date DATE,end_date DATE,budget DECIMAL(10,2)); INSERT INTO defense_projects (id,project_name,region,start_date,end_date,budget) VALUES (1,'Project C','Southeast Asia','2017-01-01','2021-12-31',1000000); INSERT INTO defense_projects (id,project_name,region,start_date,end_date,budget) VALUES (2,'Project D','Southeast Asia','2018-01-01',NULL,1500000); | SELECT region, SUM(budget) FROM defense_projects WHERE end_date IS NULL GROUP BY region ORDER BY SUM(budget) DESC; |
Which ESG factors are most relevant to Purple Partners' investment strategy? | CREATE TABLE Purple_Partners (id INT,esg_factor VARCHAR(30)); INSERT INTO Purple_Partners (id,esg_factor) VALUES (1,'Climate Change'),(2,'Gender Equality'),(3,'Labor Practices'); | SELECT esg_factor FROM Purple_Partners WHERE TRUE; |
What is the total number of customers who have made at least one transaction in the last week? | CREATE TABLE customers (customer_id INT,name VARCHAR(50),last_transaction_date DATE); INSERT INTO customers (customer_id,name,last_transaction_date) VALUES (1,'John Doe','2022-02-05'),(2,'Jane Smith',NULL),(3,'Bob Johnson','2022-02-02'); | SELECT COUNT(DISTINCT customer_id) FROM customers WHERE last_transaction_date >= DATE_SUB(CURDATE(), INTERVAL 1 WEEK); |
How many papers on algorithmic fairness were published by authors from underrepresented communities in the past year, in the AI Research database? | CREATE TABLE authors (id INT,name VARCHAR(255),underrepresented BOOLEAN); INSERT INTO authors (id,name,underrepresented) VALUES (1,'Alice',true),(2,'Bob',false); CREATE TABLE papers (id INT,title VARCHAR(255),published_date DATE,author_id INT); INSERT INTO papers (id,title,published_date,author_id) VALUES (1,'Paper1','2021-06-01',1),(2,'Paper2','2020-12-25',2); CREATE TABLE topics (id INT,paper_id INT,title VARCHAR(255)) INSERT INTO topics (id,paper_id,title) VALUES (1,1,'Algorithmic Fairness'),(2,2,'AI Safety'); | SELECT COUNT(*) FROM papers JOIN authors ON papers.author_id = authors.id WHERE authors.underrepresented = true AND YEAR(papers.published_date) = YEAR(CURRENT_DATE()) AND topics.title = 'Algorithmic Fairness'; |
What is the minimum budget for peacekeeping operations in Europe since 2016? | CREATE TABLE PeacekeepingOperations (id INT PRIMARY KEY,operation VARCHAR(100),location VARCHAR(50),year INT,budget INT); INSERT INTO PeacekeepingOperations (id,operation,location,year,budget) VALUES (2,'EUFOR ALTHEA','Bosnia and Herzegovina',2016,12345678); | SELECT MIN(budget) FROM PeacekeepingOperations WHERE location LIKE '%Europe%' AND year >= 2016; |
What is the change in infectious disease cases between consecutive years? | CREATE TABLE infectious_disease_yearly (year INT,region VARCHAR(10),cases INT); INSERT INTO infectious_disease_yearly (year,region,cases) VALUES (2019,'North',100),(2020,'North',120),(2019,'South',150),(2020,'South',180); | SELECT year, region, cases, LAG(cases, 1) OVER (PARTITION BY region ORDER BY year) AS prev_cases, cases - LAG(cases, 1) OVER (PARTITION BY region ORDER BY year) AS change FROM infectious_disease_yearly; |
How many female and male graduate students are there in each department? | CREATE TABLE dept_students (id INT,department VARCHAR(255),gender VARCHAR(10),student_count INT); INSERT INTO dept_students (id,department,gender,student_count) VALUES (1,'Physics','Male',15),(2,'Physics','Female',10),(3,'Computer Science','Male',20),(4,'Computer Science','Female',18); | SELECT department, gender, SUM(student_count) AS total_students FROM dept_students GROUP BY department, gender; |
What are the top 3 genres with the highest average song length in the 'song_details' table? | CREATE TABLE song_details (song_id INT,genre VARCHAR(20),length DECIMAL(5,2)); INSERT INTO song_details (song_id,genre,length) VALUES (1,'Pop',3.45),(2,'Rock',4.10),(3,'Jazz',5.20),(4,'Pop',3.20),(5,'Rock',4.25); | SELECT genre, AVG(length) as avg_length FROM song_details GROUP BY genre ORDER BY avg_length DESC LIMIT 3; |
Create a view for active recycling initiatives | CREATE TABLE recycling_initiatives (id INT PRIMARY KEY,region VARCHAR(255),initiative_name VARCHAR(255),initiative_description TEXT,start_date DATE,end_date DATE); INSERT INTO recycling_initiatives (id,region,initiative_name,initiative_description,start_date,end_date) VALUES (1,'Africa','Plastic Bottle Collection','Collecting plastic bottles in schools and parks.','2020-01-01','2020-12-31'),(2,'South America','E-Waste Disposal','Establishing e-waste drop-off points in major cities.','2019-06-15','2021-06-14'),(3,'Oceania','Composting Program','Implementing composting programs in households.','2018-04-22','2022-04-21'),(4,'Antarctica','Research and Development','Researching new waste reduction methods.','2023-07-04','2026-07-03'); CREATE VIEW active_recycling_initiatives AS SELECT * FROM recycling_initiatives WHERE end_date >= CURDATE(); | CREATE VIEW active_recycling_initiatives AS SELECT * FROM recycling_initiatives WHERE end_date >= CURDATE(); |
How many home runs has each baseball player hit in the current season? | CREATE TABLE baseball_players (player_name TEXT,team TEXT,home_runs INT); INSERT INTO baseball_players (player_name,team,home_runs) VALUES ('Mike Trout','Angels',45),('Aaron Judge','Yankees',44),('Nolan Arenado','Rockies',42); | SELECT player_name, team, home_runs FROM baseball_players; |
Rank garment categories by the number of times they were sold, per month, and show only the top ranked category in each month. | CREATE TABLE GarmentSales (SaleID INT,Category VARCHAR(255),SaleMonth VARCHAR(255)); INSERT INTO GarmentSales (SaleID,Category,SaleMonth) VALUES (1,'Tops','January'); | SELECT Category, SaleMonth, ROW_NUMBER() OVER (PARTITION BY SaleMonth ORDER BY COUNT(*) DESC) as Rank FROM GarmentSales GROUP BY Category, SaleMonth HAVING Rank = 1; |
Find the average ESG score for each country in the Americas region? | CREATE TABLE OrganizationESG (OrgID INT,Country VARCHAR(50),Region VARCHAR(50),ESG FLOAT); INSERT INTO OrganizationESG (OrgID,Country,Region,ESG) VALUES (1,'US','Americas',75),(2,'Canada','Americas',80),(3,'Mexico','Americas',70),(4,'Brazil','Americas',85),(5,'Argentina','Americas',78),(6,'Colombia','Americas',72); | SELECT Country, AVG(ESG) as AvgESG FROM OrganizationESG WHERE Region = 'Americas' GROUP BY Country; |
What is the name and creation date of the artifact with the second latest creation date? | CREATE TABLE Artifacts (ArtifactID INT,Name VARCHAR(100),CreationDate DATETIME); INSERT INTO Artifacts (ArtifactID,Name,CreationDate) VALUES (1,'Ancient Dagger','1500-01-01'),(2,'Modern Artifact','2020-01-01'); | SELECT Name, CreationDate FROM (SELECT Name, CreationDate, ROW_NUMBER() OVER (ORDER BY CreationDate DESC) as RowNum FROM Artifacts) as ArtifactRank WHERE RowNum = 2; |
What is the minimum ph level recorded in fish farms in the South China Sea? | CREATE TABLE south_china_sea_farms (id INT,name TEXT,ph FLOAT); | SELECT MIN(ph) FROM south_china_sea_farms; |
Summarize REE production by company and year. | CREATE TABLE production (company_id INT,year INT,ree_production INT); INSERT INTO production (company_id,year,ree_production) VALUES (1,2019,1200),(1,2020,1500),(1,2021,1800),(2,2019,800),(2,2020,1000),(2,2021,1200); | SELECT company_id, year, SUM(ree_production) as total_production FROM production GROUP BY company_id, year; |
Insert a new record into the 'workforce_development' table with 'employee_name' as 'Sophia Lee', 'department' as 'engineering', and 'safety_training_hours' as 12 | CREATE TABLE workforce_development (id INT PRIMARY KEY,employee_name VARCHAR(255),department VARCHAR(64),safety_training_hours INT); | INSERT INTO workforce_development (employee_name, department, safety_training_hours) VALUES ('Sophia Lee', 'engineering', 12); |
List all sustainable tourism activities in Brazil and their respective capacities. | CREATE TABLE sustainable_activities (activity_id INT,activity_name TEXT,country TEXT,capacity INT); INSERT INTO sustainable_activities (activity_id,activity_name,country,capacity) VALUES (1,'Amazon Rainforest Tour','Brazil',50),(2,'Iguazu Falls Hike','Brazil',100); | SELECT activity_name, capacity FROM sustainable_activities WHERE country = 'Brazil'; |
How many community health workers identify as part of the LGBTQ+ community in urban areas? | CREATE TABLE community_health_workers (id INT,name VARCHAR,location VARCHAR,LGBTQ_identification VARCHAR); INSERT INTO community_health_workers (id,name,location,LGBTQ_identification) VALUES (1,'John Doe','Urban','Yes'); INSERT INTO community_health_workers (id,name,location,LGBTQ_identification) VALUES (2,'Jane Smith','Rural','No'); | SELECT location, COUNT(*) as total_LGBTQ_workers FROM community_health_workers WHERE location = 'Urban' AND LGBTQ_identification = 'Yes' GROUP BY location; |
What is the percentage of visitors who attended "Poetry Readings" and were aged 18-35? | CREATE TABLE PoetryReadings(id INT,age INT,gender VARCHAR(10),visit_date DATE); | SELECT 100.0 * COUNT(*) / (SELECT COUNT(*) FROM PoetryReadings) FROM PoetryReadings WHERE age BETWEEN 18 AND 35; |
What is the average score of players residing in Asia? | CREATE TABLE Player (PlayerID INT,Name VARCHAR(50),Country VARCHAR(50),Score INT); | SELECT AVG(Score) FROM Player WHERE Country IN ('China', 'India', 'Japan', 'South Korea', 'Indonesia'); |
What is the total quantity of items in warehouses located in 'NY' and 'NJ'? | CREATE TABLE warehouses (id INT,location VARCHAR(10),item VARCHAR(10),quantity INT); INSERT INTO warehouses (id,location,item,quantity) VALUES (1,'NY','A101',200),(2,'NJ','A101',300),(3,'CA','B203',150),(4,'NY','C304',50); | SELECT SUM(quantity) FROM warehouses WHERE location IN ('NY', 'NJ'); |
What is the average number of hospital beds in rural areas of each state? | CREATE TABLE hospital (hospital_id INT,name TEXT,location TEXT,beds INT,state TEXT); | SELECT state, AVG(beds) FROM hospital WHERE location LIKE '%rural%' GROUP BY state; |
Find the number of unique climate communication campaigns in 2020 that targeted countries with high vulnerability to climate change, and the average budget for these campaigns. | CREATE TABLE climate_communication (year INT,campaign VARCHAR(20),target VARCHAR(20),budget FLOAT); INSERT INTO climate_communication (year,campaign,target,budget) VALUES (2020,'Campaign1','Bangladesh',2000000),(2020,'Campaign2','Pakistan',1500000),(2020,'Campaign3','Mozambique',1800000),(2020,'Campaign4','Maldives',2200000),(2020,'Campaign5','Fiji',1900000); | SELECT COUNT(DISTINCT campaign) AS num_campaigns, AVG(budget) AS avg_budget FROM climate_communication WHERE year = 2020 AND target IN ('Bangladesh', 'Pakistan', 'Mozambique', 'Maldives', 'Fiji'); |
What is the number of fish deaths in the Pacific Ocean in the last 3 months? | CREATE TABLE Pacific_Ocean (id INT,date DATE,deaths INT); INSERT INTO Pacific_Ocean (id,date,deaths) VALUES (1,'2022-01-01',100),(2,'2022-01-05',200),(3,'2022-02-15',300); | SELECT COUNT(deaths) FROM Pacific_Ocean WHERE date >= DATE_SUB(CURDATE(), INTERVAL 3 MONTH); |
Show the names and locations of restorative justice programs that have ended, grouped by location | CREATE TABLE programs (id INT,name VARCHAR(50),location VARCHAR(50),type VARCHAR(50),start_date DATE,end_date DATE); | SELECT location, GROUP_CONCAT(name) AS Programs FROM programs WHERE type = 'Restorative Justice' AND end_date IS NOT NULL GROUP BY location; |
What is the maximum number of marine species in each region? | CREATE TABLE marine_species (name VARCHAR,region VARCHAR); INSERT INTO marine_species (name,region) VALUES ('Dolphin','Atlantic'),('Shark','Pacific'),('Clownfish','Indian'),('Tuna','Atlantic'),('Jellyfish','Atlantic'); | SELECT region, MAX(COUNT(*)) OVER (PARTITION BY NULL) FROM marine_species GROUP BY region; |
What is the percentage of voters in 'Florida' who voted for the Democratic party in the 2020 presidential election? | CREATE TABLE election_data (state VARCHAR(255),party VARCHAR(255),votes INT,total_votes INT); INSERT INTO election_data (state,party,votes,total_votes) VALUES ('Florida','Democratic',4800000,11000000); | SELECT (votes * 100.0 / total_votes) AS percentage FROM election_data WHERE state = 'Florida' AND party = 'Democratic'; |
How many goals did Messi score in 2019? | CREATE TABLE player_stats (player VARCHAR(255),year INT,goals INT); INSERT INTO player_stats (player,year,goals) VALUES ('Messi',2019,51); | SELECT goals FROM player_stats WHERE player = 'Messi' AND year = 2019; |
Add a new column 'disability_status' to 'Player_Demographics' | CREATE TABLE Player_Demographics (id INT PRIMARY KEY,player_id INT,age INT,gender VARCHAR(255),country VARCHAR(255)); | ALTER TABLE Player_Demographics ADD COLUMN disability_status VARCHAR(255); |
List the case types and their respective average billing amounts for cases handled by attorneys from New York or California. | CREATE TABLE Attorneys (AttorneyID INT,State VARCHAR(10)); CREATE TABLE Cases (CaseID INT,CaseType VARCHAR(20),BillingAmount INT); INSERT INTO Attorneys (AttorneyID,State) VALUES (1,'NY'),(2,'CA'),(3,'NY'),(4,'NJ'); INSERT INTO Cases (CaseID,CaseType,BillingAmount) VALUES (1,'Civil',500),(2,'Criminal',1000),(3,'Civil',750),(4,'Civil',800); | SELECT CaseType, AVG(BillingAmount) FROM Cases JOIN Attorneys ON Cases.AttorneyID = Attorneys.AttorneyID WHERE Attorneys.State = 'NY' OR Attorneys.State = 'CA' GROUP BY CaseType; |
What is the average balance of all digital assets with a type of 'coin'? | CREATE TABLE digital_assets (id INT,name TEXT,balance INT,type TEXT); INSERT INTO digital_assets (id,name,balance,type) VALUES (1,'Asset1',50,'token'),(2,'Asset2',100,'coin'),(3,'Asset3',150,'token'); | SELECT AVG(digital_assets.balance) AS avg_balance FROM digital_assets WHERE digital_assets.type = 'coin'; |
List all the community education programs in the 'education_programs' table that are not associated with any animal species in the 'animal_population' table. | CREATE TABLE animal_population (id INT,animal_name VARCHAR(50)); CREATE TABLE education_programs (id INT,habitat_id INT,coordinator_name VARCHAR(50)); | SELECT e.coordinator_name FROM education_programs e LEFT JOIN animal_population a ON e.habitat_id = a.id WHERE a.id IS NULL; |
Which climate communication initiatives in Africa were not funded in 2020? | CREATE TABLE climate_communication (id INT,initiative_name VARCHAR(50),country VARCHAR(50),year INT,funded BOOLEAN); INSERT INTO climate_communication (id,initiative_name,country,year,funded) VALUES (1,'Climate Awareness Campaign','Nigeria',2020,FALSE); | SELECT initiative_name FROM climate_communication WHERE country = 'Africa' AND year = 2020 AND funded = FALSE; |
How many defense contracts were awarded to small businesses in the month of March? | CREATE TABLE defense_contracts (contract_id INT,business_size VARCHAR(255),contract_date DATE); INSERT INTO defense_contracts (contract_id,business_size,contract_date) VALUES (1,'Small Business','2022-03-01'),(2,'Large Business','2022-04-02'),(3,'Small Business','2022-03-03'); | SELECT COUNT(*) FROM defense_contracts WHERE business_size = 'Small Business' AND EXTRACT(MONTH FROM contract_date) = 3; |
What is the total fare collected for trams in Berlin? | CREATE TABLE trams (id INT,city VARCHAR(50),fare DECIMAL(5,2)); INSERT INTO trams (id,city,fare) VALUES (1,'Berlin',2.10),(2,'Berlin',1.90),(3,'Berlin',2.30),(4,'New York',3.50); | SELECT SUM(fare) FROM trams WHERE city = 'Berlin'; |
List all community health workers from Brazil | CREATE TABLE community_health_workers (id INT PRIMARY KEY,worker_name VARCHAR(50),language_spoken VARCHAR(20),years_of_experience INT); | SELECT * FROM community_health_workers WHERE state = 'Brazil'; |
Which species have the highest total population in a specific country? | CREATE TABLE Forests (ForestID INT PRIMARY KEY,Name VARCHAR(50),Country VARCHAR(50),Hectares FLOAT); CREATE TABLE Species (SpeciesID INT PRIMARY KEY,Name VARCHAR(50),ForestID INT,FOREIGN KEY (ForestID) REFERENCES Forests(ForestID)); CREATE TABLE Wildlife (WildlifeID INT PRIMARY KEY,Species VARCHAR(50),Population INT,ForestID INT,FOREIGN KEY (ForestID) REFERENCES Forests(ForestID)); CREATE VIEW TotalPopulation AS SELECT Species,SUM(Population) AS TotalPopulation FROM Wildlife GROUP BY Species; | SELECT Species, TotalPopulation FROM Wildlife INNER JOIN TotalPopulation ON Wildlife.Species = TotalPopulation.Species WHERE Forests.Country = 'Brazil' GROUP BY Species ORDER BY TotalPopulation DESC LIMIT 1; |
Add new record to sustainable_practices table with id 12, title 'Rainwater Harvesting Systems Installation', description 'Installation of rainwater harvesting systems on buildings', date '2022-05-05' | CREATE TABLE sustainable_practices (id INT,title VARCHAR(50),description TEXT,date DATE); | INSERT INTO sustainable_practices (id, title, description, date) VALUES (12, 'Rainwater Harvesting Systems Installation', 'Installation of rainwater harvesting systems on buildings', '2022-05-05'); |
What is the recycling rate by material type in city S? | CREATE TABLE recycling_rates(city TEXT,material_type TEXT,recycling_rate FLOAT); INSERT INTO recycling_rates(city,material_type,recycling_rate) VALUES('S','plastic',0.7),('S','glass',0.8),('S','paper',0.9); | SELECT material_type, AVG(recycling_rate) FROM recycling_rates WHERE city = 'S' GROUP BY material_type; |
How many fish are raised in each farm in the Baltic Sea region? | CREATE TABLE fish_farm (farm_id INT,location VARCHAR(20),num_fish INT); INSERT INTO fish_farm (farm_id,location,num_fish) VALUES (1,'Baltic Sea',5000),(2,'North Sea',7000),(3,'Baltic Sea',6000); | SELECT farm_id, location, num_fish FROM fish_farm WHERE location = 'Baltic Sea'; |
What is the average number of posts per day, for users from Japan, grouped by age and gender? | CREATE TABLE posts (post_id INT,user_id INT,post_type VARCHAR(20),posted_at TIMESTAMP); INSERT INTO posts (post_id,user_id,post_type,posted_at) VALUES (1,101,'Text','2021-01-01 12:00:00'),(2,102,'Image','2021-01-02 13:00:00'); CREATE TABLE users (user_id INT,age INT,gender VARCHAR(10),country VARCHAR(10)); INSERT INTO users (user_id,age,gender,country) VALUES (101,25,'Female','Japan'),(102,35,'Male','France'); | SELECT u.age, u.gender, AVG(COUNT(*)) AS avg_posts_per_day FROM users u INNER JOIN posts p ON u.user_id = p.user_id WHERE u.country = 'Japan' GROUP BY u.age, u.gender; |
List the projects in the 'resilience_standards' table that have a start date within the next 30 days, ordered by their start date. | CREATE TABLE resilience_standards (id INT,name VARCHAR(50),location VARCHAR(50),start_date DATE,completion_date DATE); | SELECT * FROM resilience_standards WHERE start_date >= GETDATE() AND start_date < DATEADD(day, 30, GETDATE()) ORDER BY start_date; |
Which genetic research experiments used CRISPR technology for gene editing in plants? | CREATE TABLE experiments (id INT,name VARCHAR(50),technology VARCHAR(50),description TEXT,target VARCHAR(50)); INSERT INTO experiments (id,name,technology,description,target) VALUES (2,'Experiment2','CRISPR','Gene editing using CRISPR...','Plants'); | SELECT name FROM experiments WHERE technology = 'CRISPR' AND target = 'Plants'; |
Update the contact information for the disability services office at the specified campus, including phone number and email address. | CREATE TABLE campus (id INT,name VARCHAR(50),region VARCHAR(50)); CREATE TABLE disability_services_office (id INT,campus_id INT,phone VARCHAR(20),email VARCHAR(50)); | UPDATE disability_services_office dso SET phone = '555-123-4567', email = 'ds@campus.edu' WHERE campus_id = (SELECT id FROM campus WHERE name = 'Campus Name'); |
Which satellite images in the 'satellite_images' table were taken after 2021-06-01? | CREATE TABLE satellite_images (image_id INT,image_url TEXT,capture_time TIMESTAMP); INSERT INTO satellite_images (image_id,image_url,capture_time) VALUES (1,'image1.jpg','2022-01-01 10:00:00'),(2,'image2.jpg','2021-05-01 10:00:00'); | SELECT image_id, image_url, capture_time FROM satellite_images WHERE capture_time > '2021-06-01'; |
Show me the names and locations of all military bases located in 'north_africa' schema | CREATE SCHEMA if not exists north_africa; USE north_africa; CREATE TABLE if not exists military_bases (id INT,name VARCHAR(255),type VARCHAR(255),location VARCHAR(255)); INSERT INTO military_bases (id,name,type,location) VALUES (1,'Wheelus Air Base','Air Force Base','Libya'),(2,'Mers El Kébir','Navy Base','Algeria'),(3,'British Army Training Unit Suffield','Army Base','Canada'); | SELECT name, location FROM north_africa.military_bases; |
What is the average age of community health workers in Texas? | CREATE TABLE CommunityHealthWorker (WorkerID INT,Age INT,Gender VARCHAR(20),State VARCHAR(20)); INSERT INTO CommunityHealthWorker (WorkerID,Age,Gender,State) VALUES (1,45,'Female','Texas'); INSERT INTO CommunityHealthWorker (WorkerID,Age,Gender,State) VALUES (2,35,'Male','Texas'); | SELECT AVG(Age) FROM CommunityHealthWorker WHERE State = 'Texas' AND Gender = 'Community Health Worker'; |
What is the percentage of the population in Melbourne that has completed a tertiary education, and what is the population size? | CREATE TABLE education_levels (person_id INT,city VARCHAR(255),tertiary_education BOOLEAN); INSERT INTO education_levels (person_id,city,tertiary_education) VALUES (1,'Melbourne',TRUE),(2,'Melbourne',TRUE),(3,'Melbourne',FALSE); CREATE TABLE population_sizes (city VARCHAR(255),size INT); INSERT INTO population_sizes (city,size) VALUES ('Melbourne',5000000); | SELECT (COUNT(*) * 100.0 / (SELECT size FROM population_sizes WHERE city = 'Melbourne')) AS education_percentage FROM education_levels WHERE city = 'Melbourne' AND tertiary_education = TRUE; |
Find the total water usage by each sector across all regions using a UNION. | CREATE TABLE water_usage_north (sector VARCHAR(20),usage INT); INSERT INTO water_usage_north (sector,usage) VALUES ('Agriculture',300),('Domestic',200),('Industrial',500); CREATE TABLE water_usage_south (sector VARCHAR(20),usage INT); INSERT INTO water_usage_south (sector,usage) VALUES ('Agriculture',400),('Domestic',250),('Industrial',600); | (SELECT sector, SUM(usage) FROM water_usage_north GROUP BY sector) UNION (SELECT sector, SUM(usage) FROM water_usage_south GROUP BY sector) |
What is the total number of art pieces in the abstract and surrealist categories? | CREATE TABLE ArtData (id INT,art_category VARCHAR(50),num_pieces INT); INSERT INTO ArtData (id,art_category,num_pieces) VALUES (1,'Abstract',100),(2,'Surrealist',150),(3,'Impressionist',200),(4,'Cubist',120),(5,'Expressionist',180); | SELECT SUM(num_pieces) FROM ArtData WHERE art_category IN ('Abstract', 'Surrealist'); |
How many professional development workshops were conducted in the social sciences department in 2022? | CREATE TABLE department (dept_id INT,dept_name TEXT,building TEXT); CREATE TABLE workshops (workshop_id INT,workshop_name TEXT,year INT,dept_id INT); INSERT INTO department (dept_id,dept_name,building) VALUES (10,'Social Sciences','Westside Building'),(20,'Physical Education','Gymnasium'); INSERT INTO workshops (workshop_id,workshop_name,year,dept_id) VALUES (101,'Teaching Strategies',2022,10),(102,'Inclusive Education',2022,10),(103,'Data Analysis',2021,20); | SELECT COUNT(w.workshop_id) as num_workshops FROM workshops w INNER JOIN department d ON w.dept_id = d.dept_id WHERE w.year = 2022 AND d.dept_name = 'Social Sciences'; |
List the names and locations of rural infrastructure projects in 'rural_development' database, grouped by project status and year of completion. | CREATE TABLE infrastructure (id INT,name TEXT,location TEXT,project_status TEXT,completion_date DATE); | SELECT name, location, project_status, completion_date FROM infrastructure GROUP BY name, location, project_status, completion_date; |
How many electric vehicle charging stations were installed in each region of India in 2022? | CREATE TABLE charging_stations (id INT,location VARCHAR(50),region VARCHAR(50),year INT,size INT); INSERT INTO charging_stations (id,location,region,year,size) VALUES (1,'Delhi','North',2022,500); INSERT INTO charging_stations (id,location,region,year,size) VALUES (2,'Mumbai','West',2022,600); INSERT INTO charging_stations (id,location,region,year,size) VALUES (3,'Bangalore','South',2022,700); INSERT INTO charging_stations (id,location,region,year,size) VALUES (4,'Kolkata','East',2022,400); | SELECT region, COUNT(size) FROM charging_stations WHERE year = 2022 GROUP BY region; |
Find the top 3 teams with the highest total ticket revenue. | CREATE TABLE TeamSales (TeamID INT,GameID INT,TicketPrice DECIMAL(5,2),Attendance INT); INSERT INTO TeamSales (TeamID,GameID,TicketPrice,Attendance) VALUES (1,1,50.00,1000),(1,2,55.00,1200),(2,1,45.00,800),(2,2,50.00,900),(3,1,60.00,1500),(3,2,65.00,1800); | SELECT TeamID, SUM(TicketPrice * Attendance) as TotalRevenue FROM TeamSales GROUP BY TeamID ORDER BY TotalRevenue DESC LIMIT 3; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.