instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
Delete the record for 'Cairo' on '2022-09-01'. | CREATE TABLE weather (city VARCHAR(255),wind_speed FLOAT,date DATE); INSERT INTO weather (city,wind_speed,date) VALUES ('Cairo',20,'2022-09-01'); | DELETE FROM weather WHERE city = 'Cairo' AND date = '2022-09-01'; |
List all authors who have published articles in the 'business' section. | CREATE TABLE articles (id INT,author VARCHAR(255),title VARCHAR(255),section VARCHAR(255),date DATE); | SELECT DISTINCT author FROM articles WHERE section='business'; |
List all astronauts who have worked on both active and decommissioned spacecraft, along with their professions. | CREATE TABLE Astronaut_Experience (id INT,astronaut_id INT,spacecraft_id INT,role VARCHAR(50),start_date DATE,end_date DATE); INSERT INTO Astronaut_Experience (id,astronaut_id,spacecraft_id,role,start_date,end_date) VALUES (1,2,1,'Pilot','1983-04-04','1992-12-18'); | SELECT DISTINCT ae1.astronaut_id, a.name, a.profession FROM Astronaut_Experience ae1 JOIN Astronaut_Experience ae2 ON ae1.astronaut_id = ae2.astronaut_id JOIN Astronaut a ON ae1.astronaut_id = a.id WHERE ae1.spacecraft_id IN (SELECT id FROM Spacecraft WHERE status = 'Active') AND ae2.spacecraft_id IN (SELECT id FROM Spacecraft WHERE status = 'Decommissioned') |
Which chemicals have not been updated in the last 6 months in the 'chemicals' table? | CREATE TABLE chemicals (id INT PRIMARY KEY,name VARCHAR(255),last_updated DATE); | SELECT name FROM chemicals WHERE last_updated < DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH); |
List the programs, their locations, and total budget from 'programs' and 'budgets' tables. | CREATE TABLE programs (id INT,name TEXT,location TEXT); CREATE TABLE budges (id INT,program_id INT,program_name TEXT,allocated_budget DECIMAL(10,2)); | SELECT p.name, p.location, SUM(b.allocated_budget) FROM programs p INNER JOIN budges b ON p.id = b.program_id GROUP BY p.name, p.location; |
Which retailers have purchased the most garments from Indian manufacturers in the past year? | CREATE TABLE retailers (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255)); INSERT INTO retailers (id,name,location) VALUES (2,'Sustainable Styles','New York,USA'); CREATE TABLE purchases (id INT PRIMARY KEY,retailer_id INT,manufacturer_id INT,date DATE,quantity INT,FOREIGN KEY (retailer_id) REFERENCES retailers(id),FOREIGN KEY (manufacturer_id) REFERENCES manufacturers(id)); INSERT INTO purchases (id,retailer_id,manufacturer_id,date,quantity) VALUES (2,2,3,'2022-05-07',250); CREATE TABLE manufacturers (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255)); INSERT INTO manufacturers (id,name,location) VALUES (3,'Handmade Ethics','Bangalore,India'); | SELECT r.name, SUM(p.quantity) AS total_quantity FROM retailers r JOIN purchases p ON r.id = p.retailer_id JOIN manufacturers m ON p.manufacturer_id = m.id WHERE m.location = 'Bangalore, India' AND p.date BETWEEN DATE_SUB(CURDATE(), INTERVAL 1 YEAR) AND CURDATE() GROUP BY r.id ORDER BY total_quantity DESC; |
Find the top 3 organizations with the highest average donation amount, including the average donation amount and the total number of donations for each organization. | CREATE TABLE organization (org_id INT,org_name VARCHAR(255)); CREATE TABLE donation (don_id INT,donor_id INT,org_id INT,donation_amount DECIMAL(10,2)); | SELECT org_id, AVG(donation_amount) AS avg_donation, COUNT(*) AS total_donations FROM donation GROUP BY org_id ORDER BY avg_donation DESC LIMIT 3; |
What is the average age of patients who were diagnosed with depression and anxiety disorders in 2021? | CREATE TABLE diagnoses (patient_id INT,age INT,diagnosis_name VARCHAR(50),diagnosis_date DATE); INSERT INTO diagnoses (patient_id,age,diagnosis_name,diagnosis_date) VALUES (1,22,'Depression','2021-08-18'); INSERT INTO diagnoses (patient_id,age,diagnosis_name,diagnosis_date) VALUES (2,35,'Anxiety Disorder','2021-12-11'); INSERT INTO diagnoses (patient_id,age,diagnosis_name,diagnosis_date) VALUES (3,42,'Depression','2021-05-03'); INSERT INTO diagnoses (patient_id,age,diagnosis_name,diagnosis_date) VALUES (4,45,'Anxiety Disorder','2021-02-15'); INSERT INTO diagnoses (patient_id,age,diagnosis_name,diagnosis_date) VALUES (5,28,'Depression','2021-07-01'); | SELECT AVG(age) FROM diagnoses WHERE diagnosis_name IN ('Depression', 'Anxiety Disorder') AND YEAR(diagnosis_date) = 2021; |
What are the 'names' and 'completion_dates' of the projects that have been completed and have a 'total_cost' less than 50000000 in the 'projects' schema? | CREATE TABLE projects (id INT,name VARCHAR(50),total_cost FLOAT,start_date DATE,completion_date DATE); INSERT INTO projects (id,name,total_cost,start_date,completion_date) VALUES (1,'Big Dig',14800000000,'1982-01-01','2007-01-01'); | SELECT name, completion_date FROM projects WHERE total_cost < 50000000 AND completion_date IS NOT NULL; |
What is the total number of multimodal trips in the transportation system of Seoul, South Korea? | CREATE TABLE multimodal_trips (id INT,city VARCHAR(255),country VARCHAR(255),trip_type VARCHAR(255),quantity INT); INSERT INTO multimodal_trips (id,city,country,trip_type,quantity) VALUES (1,'Seoul','South Korea','Bike-Subway',15000),(2,'Seoul','South Korea','Bus-Bike',20000); | SELECT SUM(quantity) FROM multimodal_trips WHERE city = 'Seoul' AND country = 'South Korea'; |
Find the top 5 cities with the highest average energy consumption per building in the 'GreenBuildings' schema, excluding cities with less than 100 buildings. | CREATE TABLE GreenBuildings.CityEnergy (city VARCHAR(50),avg_energy_per_building FLOAT,num_buildings INT); INSERT INTO GreenBuildings.CityEnergy (city,avg_energy_per_building,num_buildings) VALUES ('Mumbai',1100.5,1500),('Delhi',1300.2,1800),('Bangalore',1000.7,1200),('Chennai',1400.3,2000),('Hyderabad',1500.0,2500),('Kolkata',1200.4,800); | SELECT city, AVG(energy_consumption) AS avg_energy_per_building FROM GreenBuildings.Buildings GROUP BY city HAVING num_buildings > 100 ORDER BY avg_energy_per_building DESC LIMIT 5; |
Update the salary of all employees in the 'IT' department to 90000 in the "Employees" table. | CREATE TABLE Employees (id INT,name VARCHAR(50),department VARCHAR(50),salary FLOAT,gender VARCHAR(10)); INSERT INTO Employees (id,name,department,salary,gender) VALUES (1,'John Doe','HR',70000.0,'Male'),(2,'Jane Smith','IT',80000.0,'Female'),(3,'Mike Johnson','IT',85000.0,'Male'),(4,'Emily Davis','HR',72000.0,'Female'); | UPDATE Employees SET salary = 90000.0 WHERE department = 'IT'; |
What was the minimum attendance at any cultural event in Sydney? | CREATE TABLE CulturalEvents (id INT,city VARCHAR(50),attendance INT); INSERT INTO CulturalEvents (id,city,attendance) VALUES (1,'Sydney',200),(2,'Sydney',100),(3,'Melbourne',150),(4,'Melbourne',250),(5,'Brisbane',300); | SELECT MIN(attendance) FROM CulturalEvents WHERE city = 'Sydney'; |
What is the average size of properties in the city of Dubai, United Arab Emirates that are wheelchair accessible? | CREATE TABLE dubai_real_estate(id INT,city VARCHAR(50),size INT,wheelchair_accessible BOOLEAN); INSERT INTO dubai_real_estate VALUES (1,'Dubai',1500,true); | SELECT AVG(size) FROM dubai_real_estate WHERE city = 'Dubai' AND wheelchair_accessible = true; |
How many community health workers are there in total, categorized by their ethnicity? | CREATE TABLE community_health_worker (id INT,name TEXT,ethnicity TEXT); INSERT INTO community_health_worker (id,name,ethnicity) VALUES (1,'Ana Garcia','Latino'),(2,'Hiroshi Tanaka','Asian'),(3,'Sara Johnson','African American'),(4,'Peter Brown','Caucasian'); | SELECT COUNT(*), ethnicity FROM community_health_worker GROUP BY ethnicity; |
How many startups have been founded by people from each country in the last 5 years? | CREATE TABLE companies (id INT,name TEXT,founding_date DATE,founder_country TEXT); | SELECT founder_country, COUNT(*) as num_startups FROM companies WHERE founding_date >= DATE_SUB(CURDATE(), INTERVAL 5 YEAR) GROUP BY founder_country; |
List the total budget for community development initiatives by state and initiative type in the 'community_development_budget' table. | CREATE TABLE community_development_budget (state VARCHAR(255),initiative_type VARCHAR(255),budget INT); INSERT INTO community_development_budget (state,initiative_type,budget) VALUES ('California','Youth Center',200000),('Texas','Library',300000); | SELECT state, initiative_type, SUM(budget) FROM community_development_budget GROUP BY state, initiative_type; |
What are the names and labor productivity of employees in the 'Drilling' department? | CREATE TABLE Departments (DepartmentID INT PRIMARY KEY,DepartmentName VARCHAR(50),ManagerID INT,ManagerFirstName VARCHAR(50),ManagerLastName VARCHAR(50)); INSERT INTO Departments (DepartmentID,DepartmentName,ManagerID,ManagerFirstName,ManagerLastName) VALUES (1,'Mining',3,'Peter','Smith'); INSERT INTO Departments (DepartmentID,DepartmentName,ManagerID,ManagerFirstName,ManagerLastName) VALUES (2,'Geology',4,'Amy','Johnson'); INSERT INTO Departments (DepartmentID,DepartmentName,ManagerID,ManagerFirstName,ManagerLastName) VALUES (3,'Drilling',5,'Liam','Neil'); | SELECT Employees.FirstName, Employees.LastName, AVG(LaborProductivity.QuantityProduced/LaborProductivity.HoursWorked) FROM Employees INNER JOIN Departments ON Employees.Department = Departments.DepartmentName INNER JOIN LaborProductivity ON Employees.EmployeeID = LaborProductivity.EmployeeID WHERE Departments.DepartmentName = 'Drilling' GROUP BY Employees.EmployeeID; |
Identify the top 2 safety ratings for chemical manufacturers in Asia, sorted by manufacturer? | CREATE TABLE chemical_manufacturing (manufacturing_id INT,safety_rating INT,manufacturer_country VARCHAR(255)); INSERT INTO chemical_manufacturing (manufacturing_id,safety_rating,manufacturer_country) VALUES (1,90,'China'),(2,85,'Japan'),(3,92,'India'),(4,80,'China'),(5,95,'Japan'); | SELECT manufacturing_id, safety_rating FROM (SELECT manufacturing_id, safety_rating, RANK() OVER (PARTITION BY manufacturer_country ORDER BY safety_rating DESC) as safety_rank FROM chemical_manufacturing WHERE manufacturer_country = 'Asia') WHERE safety_rank <= 2 |
Find the names of the habitats in the 'habitat_preservation' table that do not have any associated education programs in the 'education_programs' table. | CREATE TABLE habitat_preservation (id INT,habitat_name VARCHAR(50),preservation_status VARCHAR(20)); CREATE TABLE education_programs (id INT,habitat_id INT,coordinator_name VARCHAR(50)); | SELECT h.habitat_name FROM habitat_preservation h LEFT JOIN education_programs e ON h.habitat_name = e.habitat_name WHERE e.id IS NULL; |
List all artists and their artwork counts in the 'Impressionism' period, ordered alphabetically. | CREATE TABLE Artworks (id INT,artist_name VARCHAR(100),period VARCHAR(50),artwork_name VARCHAR(100)); INSERT INTO Artworks (id,artist_name,period,artwork_name) VALUES (1,'Claude Monet','Impressionism','Water Lilies'); INSERT INTO Artworks (id,artist_name,period,artwork_name) VALUES (2,'Pierre-Auguste Renoir','Impressionism','Dance at Le Moulin de la Galette'); INSERT INTO Artworks (id,artist_name,period,artwork_name) VALUES (3,'Edgar Degas','Impressionism','Ballet Rehearsal'); | SELECT artist_name, COUNT(*) as artwork_count FROM Artworks WHERE period = 'Impressionism' GROUP BY artist_name ORDER BY artist_name; |
Insert a new record of a $10,000 donation to 'Schistosomiasis Control Initiative' in the table 'philanthropic_trends'. | CREATE TABLE philanthropic_trends (organization_name TEXT,donation_amount INTEGER); | INSERT INTO philanthropic_trends (organization_name, donation_amount) VALUES ('Schistosomiasis Control Initiative', 10000); |
What is the minimum number of military bases operated by any country in the Caribbean? | CREATE TABLE military_bases (country VARCHAR(50),region VARCHAR(50),num_bases INT); INSERT INTO military_bases (country,region,num_bases) VALUES ('Country16','Caribbean',30),('Country17','Caribbean',40),('Country18','Caribbean',50),('Country19','South America',60),('Country20','Caribbean',20); | SELECT MIN(num_bases) FROM military_bases WHERE region = 'Caribbean'; |
What is the total CO2 emission reduction for carbon offset programs in 'CarbonOffsets' table, by region? | CREATE TABLE CarbonOffsets (id INT,program_name TEXT,region TEXT,start_date DATE,end_date DATE,co2_reduction_tonnes INT); | SELECT region, SUM(co2_reduction_tonnes) FROM CarbonOffsets GROUP BY region; |
What is the total number of successful and failed satellite launches by AstroCorp? | CREATE TABLE Satellite_Launches (launch_id INT,launch_date DATE,result VARCHAR(255),manufacturer VARCHAR(255)); INSERT INTO Satellite_Launches (launch_id,launch_date,result,manufacturer) VALUES (1,'2021-01-01','Success','AstroCorp'),(2,'2021-02-01','Failed','AstroCorp'),(3,'2021-03-01','Success','AstroCorp'); | SELECT SUM(CASE WHEN result = 'Success' THEN 1 ELSE 0 END) + SUM(CASE WHEN result = 'Failed' THEN 1 ELSE 0 END) FROM Satellite_Launches WHERE manufacturer = 'AstroCorp'; |
Which sustainable material is used most frequently in garments? | CREATE TABLE GarmentMaterials (id INT,garment_id INT,material VARCHAR(20));CREATE TABLE Garments (id INT,name VARCHAR(50)); INSERT INTO GarmentMaterials (id,garment_id,material) VALUES (1,1001,'organic_cotton'),(2,1002,'recycled_polyester'),(3,1003,'organic_cotton'),(4,1004,'hemp'),(5,1005,'organic_cotton'); INSERT INTO Garments (id,name) VALUES (1001,'Eco T-Shirt'),(1002,'Green Sweater'),(1003,'Circular Hoodie'),(1004,'Hemp Shirt'),(1005,'Ethical Jacket'); | SELECT material, COUNT(DISTINCT garment_id) as garment_count FROM GarmentMaterials GROUP BY material ORDER BY garment_count DESC LIMIT 1; |
Calculate the median number of research grants awarded per faculty member in the Arts department. | CREATE TABLE grants (id INT,faculty_id INT,year INT,amount DECIMAL(10,2)); INSERT INTO grants (id,faculty_id,year,amount) VALUES (1,1,2020,25000); INSERT INTO grants (id,faculty_id,year,amount) VALUES (2,2,2019,30000); CREATE TABLE faculty (id INT,name VARCHAR(50),department VARCHAR(50)); INSERT INTO faculty (id,name,department) VALUES (1,'Eva','Arts'); INSERT INTO faculty (id,name,department) VALUES (2,'Frank','Chemistry'); | SELECT AVG(g.num_grants) FROM (SELECT faculty_id, PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY COUNT(*)) OVER () AS median_num_grants FROM grants GROUP BY faculty_id) g JOIN faculty f ON g.faculty_id = f.id WHERE f.department = 'Arts'; |
How many energy storage projects were completed in Australia and India in 2021? | CREATE TABLE storage_project (id INT,name VARCHAR(50),country VARCHAR(20),year INT); INSERT INTO storage_project (id,name,country,year) VALUES (1,'Project 1','Australia',2021),(2,'Project 2','India',2021),(3,'Project 3','Australia',2020); | SELECT COUNT(*) FROM storage_project WHERE country IN ('Australia', 'India') AND year = 2021; |
Which water treatment plants had a drought impact in 2020? | CREATE TABLE water_treatment_plants (id INT,name VARCHAR(50),location VARCHAR(50),year_established INT); INSERT INTO water_treatment_plants (id,name,location,year_established) VALUES (1,'PlantA','CityA',1990),(2,'PlantB','CityB',2005),(3,'PlantC','CityC',2010),(4,'PlantD','CityD',2015); CREATE TABLE drought_impact (id INT,plant_id INT,year INT,impact INT); INSERT INTO drought_impact (id,plant_id,year,impact) VALUES (1,1,2019,0),(2,1,2020,10),(3,2,2019,5),(4,2,2020,15),(5,3,2019,0),(6,3,2020,8),(7,4,2019,2),(8,4,2020,12); | SELECT wtp.name FROM water_treatment_plants wtp JOIN drought_impact di ON wtp.id = di.plant_id WHERE di.year = 2020 AND di.impact > 0; |
What is the ratio of domestic to international tourists for a given country? | CREATE TABLE tourists (id INT,name VARCHAR(50),nationality VARCHAR(50),is_domestic BOOLEAN); INSERT INTO tourists (id,name,nationality,is_domestic) VALUES (1,'John Doe','Canada',false),(2,'Jane Doe','Canada',true); | SELECT ROUND(AVG(CASE WHEN is_domestic THEN 1.0 ELSE 0.0 END), 2) as domestic_to_international_ratio FROM tourists WHERE nationality = 'Canada'; |
What is the minimum mental health score of students in each department? | CREATE TABLE student_mental_health (student_id INT,department_id INT,mental_health_score INT); | SELECT department_id, MIN(mental_health_score) as min_mental_health_score FROM student_mental_health GROUP BY department_id; |
What is the population distribution by age group in CityY? | CREATE TABLE City_Demographics (City VARCHAR(20),Age_Group VARCHAR(20),Population INT); INSERT INTO City_Demographics (City,Age_Group,Population) VALUES ('CityY','0-17',45000); INSERT INTO City_Demographics (City,Age_Group,Population) VALUES ('CityY','18-64',180000); INSERT INTO City_Demographics (City,Age_Group,Population) VALUES ('CityY','65+',55000); | SELECT City, SUM(CASE WHEN Age_Group = '0-17' THEN Population ELSE 0 END) AS 'Population 0-17', SUM(CASE WHEN Age_Group = '18-64' THEN Population ELSE 0 END) AS 'Population 18-64', SUM(CASE WHEN Age_Group = '65+' THEN Population ELSE 0 END) AS 'Population 65+' FROM City_Demographics WHERE City = 'CityY' GROUP BY City; |
How many hip-hop songs were streamed in Asia in the past year? | CREATE TABLE Streams (StreamID INT,UserID INT,SongID INT,StreamDate TIMESTAMP,Country VARCHAR(50)); CREATE TABLE Songs (SongID INT,SongName VARCHAR(100),ArtistID INT,Genre VARCHAR(50)); INSERT INTO Streams VALUES (1,1,1,'2023-01-01 10:00:00','China'),(2,1,2,'2023-01-01 11:00:00','China'),(3,2,1,'2023-01-02 12:00:00','Japan'); INSERT INTO Songs VALUES (1,'Boom Bap',1,'Hip-Hop'),(2,'Rock Out',2,'Rock'); | SELECT SUM(*) FROM Streams JOIN Songs ON Streams.SongID = Songs.SongID WHERE Songs.Genre = 'Hip-Hop' AND Streams.Country IN ('Asia', 'Asian countries') AND Streams.StreamDate BETWEEN (CURRENT_DATE - INTERVAL '1 year') AND CURRENT_DATE; |
Which excavation sites have more artifacts from the Roman period than the Iron Age? | CREATE TABLE SiteArtifacts (SiteID INT,ArtifactID INT,Period TEXT); INSERT INTO SiteArtifacts (SiteID,ArtifactID,Period) VALUES (1,1,'Roman'),(1,2,'Iron Age'),(2,3,'Roman'); | SELECT SiteID FROM SiteArtifacts WHERE Period = 'Roman' GROUP BY SiteID HAVING COUNT(*) > (SELECT COUNT(*) FROM SiteArtifacts WHERE SiteID = SiteArtifacts.SiteID AND Period = 'Iron Age') |
Which space centers have a capacity greater than 2000 and have launched at least one space mission? | CREATE TABLE Space_Center (id INT,name VARCHAR(255),location VARCHAR(255),capacity INT); CREATE TABLE Space_Mission (id INT,name VARCHAR(255),space_center_id INT,launch_date DATE,launch_status VARCHAR(255)); INSERT INTO Space_Center (id,name,location,capacity) VALUES (1,'Vandenberg Air Force Base','California,USA',2500); INSERT INTO Space_Mission (id,name,space_center_id,launch_date,launch_status) VALUES (1,'GPS III SV03',1,'2020-06-30','Success'); | SELECT Space_Center.* FROM Space_Center INNER JOIN Space_Mission ON Space_Center.id = Space_Mission.space_center_id WHERE Space_Center.capacity > 2000 AND Space_Mission.launch_status = 'Success'; |
What is the maximum calorie count for vegan products in the NutritionData table, grouped by product type? | CREATE TABLE NutritionData(product_id INT,product_type VARCHAR(50),is_vegan BOOLEAN,calorie_count INT); | SELECT product_type, MAX(calorie_count) FROM NutritionData WHERE is_vegan = TRUE GROUP BY product_type; |
What's the total number of pieces in the 'ArtCollection' table created before '1950-01-01'? | CREATE TABLE ArtCollection (id INT PRIMARY KEY,name VARCHAR(50),artist VARCHAR(50),date DATE); | SELECT COUNT(*) FROM ArtCollection WHERE date < '1950-01-01'; |
What is the maximum and minimum runtime (in minutes) of shows by genre? | CREATE TABLE shows (id INT,title VARCHAR(100),genre VARCHAR(50),country VARCHAR(50),release_year INT,runtime INT); | SELECT genre, MAX(runtime), MIN(runtime) FROM shows GROUP BY genre; |
Create a table named 'technology_accessibility_stats' | CREATE TABLE technology_accessibility_stats (id INT PRIMARY KEY,country VARCHAR(255),internet_users INT,broadband_penetration DECIMAL(5,2),mobile_users INT,disabled_population INT); | CREATE TABLE technology_accessibility_stats (id INT PRIMARY KEY, country VARCHAR(255), internet_users INT, broadband_penetration DECIMAL(5,2), mobile_users INT, disabled_population INT); |
What is the maximum severity of vulnerabilities detected in the IT department? | CREATE TABLE vulnerabilities (id INT,department VARCHAR(255),severity FLOAT); INSERT INTO vulnerabilities (id,department,severity) VALUES (1,'Finance',7.5),(2,'HR',5.0),(3,'IT',9.3),(4,'IT',8.1); | SELECT MAX(severity) FROM vulnerabilities WHERE department = 'IT'; |
Find the number of contracts awarded to each contractor in the IT industry in 2020? | CREATE TABLE Contractors (ContractorID INT,ContractorName VARCHAR(100),Industry VARCHAR(50)); INSERT INTO Contractors (ContractorID,ContractorName,Industry) VALUES (1,'Lockheed Martin','Aerospace'),(2,'Boeing','Aerospace'),(3,'Microsoft','IT'),(4,'Amazon','IT'),(5,'Northrop Grumman','Aerospace'); CREATE TABLE Contracts (ContractID INT,ContractorID INT,Year INT,ContractsAwarded INT); INSERT INTO Contracts (ContractID,ContractorID,Year,ContractsAwarded) VALUES (1,1,2021,50),(2,1,2020,40),(3,2,2021,60),(4,2,2020,70),(5,5,2021,80),(6,5,2020,90),(7,3,2020,55),(8,4,2020,65); | SELECT ContractorName, SUM(ContractsAwarded) as Total_Contracts FROM Contracts c JOIN Contractors con ON c.ContractorID = con.ContractorID WHERE Industry = 'IT' AND Year = 2020 GROUP BY ContractorName; |
What is the highest number of likes received by posts from female content creators in the "Gaming" category on the platform? | CREATE TABLE Posts (id INT,title VARCHAR(255),content_creator_name VARCHAR(100),content_creator_gender VARCHAR(10),category VARCHAR(50),likes INT); INSERT INTO Posts (id,title,content_creator_name,content_creator_gender,category,likes) VALUES (1,'Post1','Creator1','Female','Gaming',1000),(2,'Post2','Creator2','Male','Gaming',1500),(3,'Post3','Creator3','Female','Tech',800); | SELECT MAX(likes) FROM Posts WHERE content_creator_gender = 'Female' AND category = 'Gaming'; |
Create a table named 'diversity_metrics' | CREATE TABLE diversity_metrics (id INT PRIMARY KEY,gender VARCHAR(50),ethnicity VARCHAR(50),department VARCHAR(50),employee_count INT); | CREATE TABLE diversity_metrics (id INT PRIMARY KEY, gender VARCHAR(50), ethnicity VARCHAR(50), department VARCHAR(50), employee_count INT); |
Who are the top 5 users with the most security incidents in the last month? | CREATE TABLE security_incidents (id INT,user_id INT,timestamp DATETIME); INSERT INTO security_incidents (id,user_id,timestamp) VALUES (1,123,'2022-01-01 10:00:00'),(2,456,'2022-01-02 15:30:00'),(3,123,'2022-01-03 08:45:00'),(4,789,'2022-01-04 14:10:00'),(5,123,'2022-01-05 21:25:00'); | SELECT user_id, COUNT(*) as incident_count FROM security_incidents WHERE timestamp >= DATE_SUB(NOW(), INTERVAL 1 MONTH) GROUP BY user_id ORDER BY incident_count DESC LIMIT 5; |
What is the maximum production volume in the 'Africa' region for the year 2018?' | CREATE TABLE mines (id INT,name TEXT,location TEXT,production_volume INT,product TEXT,year INT); INSERT INTO mines (id,name,location,production_volume,product,year) VALUES (1,'Diamond Dust Mine','Africa',20000,'Diamond',2018); INSERT INTO mines (id,name,location,production_volume,product,year) VALUES (2,'Ruby Ridge Mine','Africa',18000,'Ruby',2018); | SELECT MAX(production_volume) FROM mines WHERE location = 'Africa' AND year = 2018; |
What is the total number of mining accidents and the associated labor productivity metrics for each country in Africa? | CREATE TABLE african_countries (id INT,country TEXT); INSERT INTO african_countries (id,country) VALUES (1,'South Africa'),(2,'Ghana'),(3,'Zambia'),(4,'Tanzania'),(5,'Mali'); CREATE TABLE mines (id INT,country TEXT,accidents INT,productivity FLOAT); INSERT INTO mines (id,country,accidents,productivity) VALUES (1,'South Africa',5,1.2),(2,'Ghana',3,1.5),(3,'Zambia',7,1.8),(4,'Tanzania',4,1.3),(5,'Mali',6,1.6); | SELECT m.country, COUNT(m.id) AS total_accidents, AVG(m.productivity) AS avg_productivity FROM mines m GROUP BY m.country; |
List all climate adaptation projects and their respective completion years. | CREATE TABLE climate_adaptation_projects (project_id INT,project_name TEXT,completion_year INT,project_type TEXT); INSERT INTO climate_adaptation_projects (project_id,project_name,completion_year,project_type) VALUES (16,'Coastal Erosion Protection P',2018,'adaptation'),(17,'Water Management Q',2019,'adaptation'),(18,'Disaster Risk Reduction R',2020,'adaptation'),(19,'Climate Resilient Agriculture S',2021,'adaptation'); | SELECT project_name, completion_year FROM climate_adaptation_projects WHERE project_type = 'adaptation'; |
What are the details of the national security threats that originated in a specific year, say 2018, from the 'nat_sec_threats' table? | CREATE TABLE nat_sec_threats (id INT,threat_name VARCHAR(255),country VARCHAR(255),threat_date DATE); | SELECT * FROM nat_sec_threats WHERE YEAR(threat_date) = 2018; |
What is the maximum number of hospital beds in Rural North? | CREATE TABLE Hospitals (name TEXT,location TEXT,type TEXT,num_beds INTEGER,state TEXT); INSERT INTO Hospitals (name,location,type,num_beds,state) VALUES ('Hospital A','City A,Rural North','General',200,'Rural North'),('Hospital B','City B,Rural North','Specialty',100,'Rural North'); | SELECT MAX(num_beds) as max_beds FROM Hospitals WHERE state = 'Rural North'; |
How many economic diversification initiatives in the tourism sector were completed between January 2018 and December 2021? | CREATE TABLE EconomicDiversification (id INT PRIMARY KEY,name VARCHAR(50),location VARCHAR(50),sector VARCHAR(20),start_date DATE,end_date DATE); INSERT INTO EconomicDiversification (id,name,location,sector,start_date,end_date) VALUES (1,'Handicraft Market','Rural Nepal','Crafts','2019-07-01','2022-06-30'),(2,'Artisan Workshop','Rural Morocco','Crafts','2022-01-01','2023-12-31'),(3,'Eco-Lodge','Rural Costa Rica','Tourism','2018-01-01','2021-12-31'); | SELECT COUNT(*) FROM EconomicDiversification WHERE start_date <= '2021-12-31' AND end_date >= '2018-01-01' AND sector = 'Tourism'; |
What is the minimum age of attendees at events in the past month? | CREATE TABLE Events (EventID INT,EventName TEXT,EventDate DATE,AttendeeAge INT); INSERT INTO Events (EventID,EventName,EventDate,AttendeeAge) VALUES (1,'Art Exhibition','2021-06-01',28),(2,'Theater Performance','2021-07-15',32),(3,'Music Concert','2020-12-31',26); | SELECT MIN(AttendeeAge) FROM Events WHERE EventDate >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH); |
What is the minimum distance between Mars and Earth for the year 2030? | CREATE TABLE planet_distances(id INT,planet1 VARCHAR(255),planet2 VARCHAR(255),date DATE,distance FLOAT); INSERT INTO planet_distances VALUES (1,'Mars','Earth','2030-01-01',54.6); INSERT INTO planet_distances VALUES (2,'Mars','Earth','2030-06-01',38.6); INSERT INTO planet_distances VALUES (3,'Mars','Earth','2030-12-01',60.2); | SELECT MIN(distance) FROM planet_distances WHERE planet1 = 'Mars' AND planet2 = 'Earth' AND date LIKE '2030-%'; |
Find the program with the lowest average attendee age. | CREATE TABLE ProgramAttendance (program_name VARCHAR(255),attendee_age INT,attendee_gender VARCHAR(50)); INSERT INTO ProgramAttendance (program_name,attendee_age,attendee_gender) VALUES ('Art Workshops',25),('Dance Classes',30),('Music Lessons',35),('Theater Workshops',20); | SELECT program_name, AVG(attendee_age) FROM ProgramAttendance GROUP BY program_name ORDER BY AVG(attendee_age) LIMIT 1; |
Delete virtual tours in Tokyo with a length greater than 60 minutes. | CREATE TABLE virtual_tour (tour_id INT,name TEXT,city TEXT,length INT); INSERT INTO virtual_tour (tour_id,name,city,length) VALUES (1,'Tokyo Skytree','Tokyo',45); | DELETE FROM virtual_tour WHERE city = 'Tokyo' AND length > 60; |
List all unique agricultural innovation projects in the 'rural_infrastructure' table and their completion years. | CREATE TABLE rural_infrastructure (project_name VARCHAR(255),project_type VARCHAR(255),completion_year INT); INSERT INTO rural_infrastructure (project_name,project_type,completion_year) VALUES ('Greenhouse Project','Agricultural Innovation',2018),('Drip Irrigation System','Agricultural Innovation',2019),('Rural Road Construction','Infrastructure',2020),('Greenhouse Project','Agricultural Innovation',2019); | SELECT project_name, project_type, completion_year FROM (SELECT project_name, project_type, completion_year, ROW_NUMBER() OVER (PARTITION BY project_name, project_type ORDER BY completion_year DESC) rn FROM rural_infrastructure) t WHERE rn = 1; |
What is the total number of streams for jazz music on Amazon Music, grouped by quarter? | CREATE TABLE QuarterlyStreams (StreamID INT,TrackID INT,PlatformID INT,Date DATE,Streams INT); INSERT INTO QuarterlyStreams (StreamID,TrackID,PlatformID,Date,Streams) VALUES (1,1,6,'2022-01-01',100); | SELECT EXTRACT(QUARTER FROM Date) as Quarter, EXTRACT(YEAR FROM Date) as Year, SUM(Streams) as TotalStreams FROM QuarterlyStreams JOIN Tracks ON QuarterlyStreams.TrackID = Tracks.TrackID JOIN StreamingPlatforms ON QuarterlyStreams.PlatformID = StreamingPlatforms.PlatformID WHERE Genre = 'Jazz' AND PlatformName = 'Amazon Music' GROUP BY Quarter, Year; |
Insert new records of medals for an athlete | CREATE TABLE athletes (id INT,name VARCHAR(50),age INT,sport VARCHAR(50)); INSERT INTO athletes (id,name,age,sport) VALUES (1,'John Doe',30,'Basketball'),(2,'Jane Smith',28,'Soccer'); CREATE TABLE medals (medal_id INT,athlete_id INT,medal_type VARCHAR(50)); | INSERT INTO medals (medal_id, athlete_id, medal_type) VALUES (101, 1, 'Gold'), (102, 1, 'Silver'), (103, 2, 'Bronze'); |
How many investments have been made with a risk assessment score greater than 80? | CREATE TABLE investments (id INT,sector VARCHAR(255),risk_assessment_score INT); INSERT INTO investments (id,sector,risk_assessment_score) VALUES (1,'Technology',80),(2,'Healthcare',70),(3,'Social Impact Investing',90); | SELECT COUNT(*) FROM investments WHERE risk_assessment_score > 80; |
Find the total number of peacekeeping missions in 'Asia' | CREATE TABLE peacekeeping_missions (mission_name VARCHAR(50),location VARCHAR(50),start_date DATE); | SELECT COUNT(*) FROM peacekeeping_missions WHERE location = 'Asia'; |
Delete all unused autonomous buses in Boston. | CREATE TABLE public.buses (id SERIAL PRIMARY KEY,name TEXT,in_use BOOLEAN,city TEXT); INSERT INTO public.buses (name,in_use,city) VALUES ('Autonomous Bus 1',FALSE,'Boston'),('Autonomous Bus 2',TRUE,'Boston'); | DELETE FROM public.buses WHERE city = 'Boston' AND name LIKE 'Autonomous Bus%' AND in_use = FALSE; |
Create a new table for tracking volunteer hours | CREATE TABLE Volunteers (VolunteerID INT,FirstName VARCHAR(255),LastName VARCHAR(255),Email VARCHAR(255),Phone VARCHAR(255)); CREATE TABLE Events (EventID INT,EventName VARCHAR(255),EventDate DATE); | CREATE TABLE VolunteerHours (VolunteerHoursID INT, VolunteerID INT, EventID INT, Hours DECIMAL(3,1), HourDate DATE); |
How many impact investments were made by Brazilian investors in 2022? | CREATE TABLE investor (investor_id INT,name VARCHAR(255),country VARCHAR(255)); INSERT INTO investor (investor_id,name,country) VALUES (1,'Acme Corp','Brazil'); CREATE TABLE investment (investment_id INT,investor_id INT,strategy VARCHAR(255),impact_score FLOAT,investment_date DATE); | SELECT COUNT(*) FROM investment JOIN investor ON investment.investor_id = investor.investor_id WHERE investor.country = 'Brazil' AND EXTRACT(YEAR FROM investment_date) = 2022; |
How many labor hours were spent on sustainable building practices in the city of San Francisco in 2022? | CREATE TABLE labor_hours (labor_id INT,hours FLOAT,city VARCHAR(50),year INT,sustainable BOOLEAN); INSERT INTO labor_hours (labor_id,hours,city,year,sustainable) VALUES (1,100,'San Francisco',2022,TRUE); INSERT INTO labor_hours (labor_id,hours,city,year,sustainable) VALUES (2,120,'San Francisco',2022,TRUE); | SELECT SUM(hours) FROM labor_hours WHERE city = 'San Francisco' AND year = 2022 AND sustainable = TRUE; |
Delete the record for 'ManufacturerE' from the circular_economy_initiatives table, as they are no longer participating. | CREATE TABLE circular_economy_initiatives (initiative_id INT,manufacturer_name TEXT,initiative_description TEXT); INSERT INTO circular_economy_initiatives (initiative_id,manufacturer_name,initiative_description) VALUES (1,'ManufacturerA','Recycling Program'),(2,'ManufacturerB','Remanufacturing Program'),(3,'ManufacturerC','Waste Reduction Program'),(4,'ManufacturerE','Upcycling Program'); | DELETE FROM circular_economy_initiatives WHERE manufacturer_name = 'ManufacturerE'; |
What are the names and transaction dates of all transactions that occurred in the United States? | CREATE TABLE transactions (id INT,transaction_date DATE,country VARCHAR(255),amount DECIMAL(10,2)); INSERT INTO transactions (id,transaction_date,country,amount) VALUES (1,'2022-01-01','USA',100.00),(2,'2022-01-02','Canada',200.00),(3,'2022-01-03','USA',300.00); | SELECT country, transaction_date FROM transactions WHERE country = 'USA'; |
What is the percentage of successful collective bargaining agreements per state for the year 2020, based on the 'collective_bargaining_2020' table? | CREATE TABLE collective_bargaining_2020 (id INT,state VARCHAR(255),success INT,total_attempts INT); INSERT INTO collective_bargaining_2020 (id,state,success,total_attempts) VALUES (1,'California',30,40),(2,'New York',25,30),(3,'Texas',20,25); | SELECT state, (SUM(success) * 100.0 / SUM(total_attempts)) as success_percentage FROM collective_bargaining_2020 GROUP BY state; |
What is the number of customers with financial capability in Oceania? | CREATE TABLE financial_capability_oceania (id INT,customer_id INT,country VARCHAR(255),capable BOOLEAN); INSERT INTO financial_capability_oceania (id,customer_id,country,capable) VALUES (1,4001,'Australia',true),(2,4002,'New Zealand',false); | SELECT COUNT(*) FROM financial_capability_oceania WHERE capable = true AND country IN ('Australia', 'New Zealand'); |
Update the name of a specific event, identified by its event ID. | CREATE TABLE events (event_id INT,name VARCHAR(50),date DATE); INSERT INTO events VALUES (1,'Old Concert','2023-03-01'); | UPDATE events e SET e.name = 'New Concert' WHERE e.event_id = 1; |
What is the average number of days it takes for a patient with diabetes to receive treatment in the state of California? | CREATE TABLE diabetes_treatment (patient_id INT,state TEXT,date_diagnosed DATE,date_treated DATE); INSERT INTO diabetes_treatment (patient_id,state,date_diagnosed,date_treated) VALUES (1,'California','2021-01-01','2021-01-10'); | SELECT AVG(DATEDIFF(date_treated, date_diagnosed)) FROM diabetes_treatment WHERE state = 'California'; |
Update the "UnionName" to "United Labor Union" in the "Unions" table where the "UnionID" is 2. | CREATE TABLE Unions (UnionID INT,UnionName TEXT); | UPDATE Unions SET UnionName = 'United Labor Union' WHERE UnionID = 2; |
What is the sum of transaction amounts for clients living in Texas? | CREATE TABLE clients (id INT,name TEXT,age INT,state TEXT,transaction_amount DECIMAL(10,2)); INSERT INTO clients (id,name,age,state,transaction_amount) VALUES (1,'Juan Hernandez',35,'Texas',120.00); INSERT INTO clients (id,name,age,state,transaction_amount) VALUES (2,'Maria Lopez',40,'Texas',180.50); INSERT INTO clients (id,name,age,state,transaction_amount) VALUES (3,'Carlos Martinez',45,'Texas',250.00); | SELECT SUM(transaction_amount) FROM clients WHERE state = 'Texas'; |
What is the total amount of minerals extracted in 'Zambales', Philippines, by month, for the last 2 years? | CREATE TABLE extraction (id INT,site_name VARCHAR(50),date DATE,mineral VARCHAR(50),quantity INT); INSERT INTO extraction (id,site_name,date,mineral,quantity) VALUES (1,'Mine A','2020-03-15','Gold',1500); | SELECT MONTH(date) AS month, SUM(quantity) AS total_quantity FROM extraction WHERE site_name = 'Zambales' AND date >= DATE_SUB(CURDATE(), INTERVAL 2 YEAR) GROUP BY month; |
What is the average monthly income for clients who have received socially responsible loans, in the West region? | CREATE TABLE shariah_loans (id INT,client_id INT); INSERT INTO shariah_loans (id,client_id) VALUES (1,101),(2,101),(1,102); CREATE TABLE socially_responsible_loans (id INT,client_id INT); INSERT INTO socially_responsible_loans (id,client_id) VALUES (1,102),(2,103),(1,104); CREATE TABLE client_info (id INT,name VARCHAR,monthly_income DECIMAL,region VARCHAR); INSERT INTO client_info (id,name,monthly_income,region) VALUES (101,'Ahmed',3000,'West'),(102,'Fatima',4000,'East'),(103,'Zainab',5000,'South'),(104,'Hassan',6000,'West'); | SELECT AVG(monthly_income) FROM client_info JOIN socially_responsible_loans ON client_info.id = socially_responsible_loans.client_id WHERE region = 'West'; |
What is the average donation per month for each donor in the 'donations' table? | CREATE TABLE donations (donation_id INT,donor_id INT,donation_date DATE,donation_amount DECIMAL(10,2)); | SELECT donor_id, AVG(donation_amount) FROM donations GROUP BY donor_id, EXTRACT(MONTH FROM donation_date); |
Update the ticket price for a theater performance in Paris to 45 euros. | CREATE TABLE Theater_Performances (id INT,city VARCHAR(50),price DECIMAL(5,2)); INSERT INTO Theater_Performances VALUES (1,'Paris',35.00); | UPDATE Theater_Performances SET price = 45.00 WHERE id = 1 AND city = 'Paris'; |
Insert a new row into the "company" table for a startup called "GreenTech Solutions" founded in 2022 | CREATE TABLE company (id INT PRIMARY KEY AUTO_INCREMENT,name VARCHAR(255),industry VARCHAR(255),founding_date DATE); | INSERT INTO company (name, industry, founding_date) VALUES ('GreenTech Solutions', 'Technology', '2022-05-15'); |
What is the average salary of employees who identify as female, grouped by department? | CREATE TABLE Employees (EmployeeID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50),Salary DECIMAL(10,2),Gender VARCHAR(10)); | SELECT Department, AVG(Salary) as Avg_Salary FROM Employees WHERE Gender = 'Female' GROUP BY Department; |
What is the total area covered by seagrass meadows in the Mediterranean?" | CREATE TABLE seagrass (id INT,name TEXT,area_size FLOAT,location TEXT); INSERT INTO seagrass (id,name,area_size,location) VALUES (1,'Posidonia oceanica',1500,'Mediterranean'); | SELECT SUM(area_size) FROM seagrass WHERE location = 'Mediterranean'; |
What is the average budget for AI projects in all sectors? | CREATE TABLE ai_projects (sector VARCHAR(20),budget INT); INSERT INTO ai_projects (sector,budget) VALUES ('Education',200000),('Healthcare',500000),('Finance',1000000),('Technology',300000); | SELECT AVG(budget) FROM ai_projects; |
Add a new record to the "physician_practices" table for a practice in "CA" with 30 total doctors | CREATE TABLE physician_practices (id INT PRIMARY KEY,name TEXT,state TEXT,total_doctors INT); INSERT INTO physician_practices (id,name,state,total_doctors) VALUES (1,'Practice 1','TX',10),(2,'Practice 2','NY',15),(3,'Practice 3','FL',20); | INSERT INTO physician_practices (name, state, total_doctors) VALUES ('Practice CA', 'CA', 30); |
What is the percentage of patients who visited a hospital vs. clinic? | CREATE TABLE visits (id INT,visit_type TEXT,visit_date DATE); | SELECT (SUM(CASE WHEN visit_type = 'Hospital' THEN 1 ELSE 0 END) * 100.0 / COUNT(*)) as hospital_percentage, |
What is the total production cost of garments produced in each region using eco-friendly dyes? | CREATE TABLE Eco_Friendly_Dye_Garments_Region (id INT,region VARCHAR,production_cost DECIMAL); | SELECT region, SUM(production_cost) FROM Eco_Friendly_Dye_Garments_Region GROUP BY region; |
Identify the suppliers and their respective countries for chemicals with a price higher than the average price of all chemicals in the inventory. | CREATE TABLE chemical_inventory (id INT PRIMARY KEY,chemical_name VARCHAR(255),quantity INT,supplier VARCHAR(255),last_updated TIMESTAMP);CREATE TABLE supplier_info (id INT PRIMARY KEY,supplier_name VARCHAR(255),address VARCHAR(255),country VARCHAR(255));CREATE TABLE chemical_prices (id INT PRIMARY KEY,chemical_name VARCHAR(255),price DECIMAL(10,2),price_updated_date DATE); | SELECT s.supplier_name, s.country, cp.price FROM supplier_info s JOIN chemical_inventory ci ON s.supplier_name = ci.supplier JOIN chemical_prices cp ON ci.chemical_name = cp.chemical_name WHERE cp.price > (SELECT AVG(price) FROM chemical_prices); |
Identify top 3 investment strategies by ROI for Q1 2022. | CREATE TABLE investment_strategies (strategy_id INT,strategy_name TEXT,investment_date DATE,amount FLOAT); CREATE TABLE returns (return_id INT,strategy_id INT,return_date DATE,return_amount FLOAT); | SELECT strategy_name, 100.0 * SUM(return_amount) / SUM(amount) AS roi FROM investment_strategies s JOIN returns r ON s.strategy_id = r.strategy_id WHERE investment_date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY strategy_id, strategy_name ORDER BY roi DESC LIMIT 3; |
What is the total sales for vegetarian and non-vegetarian menu items? | CREATE TABLE menu_sales(menu_item VARCHAR(50),sales INT,type VARCHAR(10)); INSERT INTO menu_sales VALUES ('Burger',300,'non-veg'),('Pizza',200,'veg'),('Salad',150,'veg'),('Steak',400,'non-veg'); | SELECT type, SUM(sales) AS total_sales FROM menu_sales GROUP BY type; |
What is the total capacity of all programs in the programs table, grouped by their location? | CREATE TABLE programs (program_id INT,location VARCHAR(25),capacity INT); INSERT INTO programs (program_id,location,capacity) VALUES (1,'New York',50),(2,'Los Angeles',75),(3,'New York',100); | SELECT SUM(capacity) as total_capacity, location FROM programs GROUP BY location; |
Which donors have donated to organizations in both the Health and Education focus areas? | CREATE TABLE donors (id INT PRIMARY KEY,name VARCHAR(255),age INT,city VARCHAR(255)); INSERT INTO donors (id,name,age,city) VALUES (1,'Alice Johnson',35,'San Francisco'); INSERT INTO donors (id,name,age,city) VALUES (2,'Bob Smith',42,'New York'); | SELECT d.name as donor_name FROM donors d JOIN donations don ON d.id = don.donor_id JOIN organizations o ON don.organization_id = o.id WHERE o.cause IN ('Health', 'Education') GROUP BY d.name HAVING COUNT(DISTINCT o.cause) = 2; |
What is the average temperature change in the US and Canada over the last 10 years? | CREATE TABLE weather (country VARCHAR(20),year INT,temperature DECIMAL(5,2)); INSERT INTO weather VALUES ('US',2010,10.5),('US',2011,11.2),('US',2012,12.1),('CA',2010,8.7),('CA',2011,8.9),('CA',2012,9.3); | SELECT AVG(temperature) as avg_temp_change, country FROM (SELECT ROW_NUMBER() OVER (PARTITION BY country ORDER BY year DESC) rn, country, temperature FROM weather WHERE year >= 2010) t WHERE rn <= 10 GROUP BY country; |
What was the average number of volunteer hours per volunteer in the Education program in 2021? | CREATE TABLE Volunteer_Hours (id INT,volunteer VARCHAR(50),program VARCHAR(50),hours FLOAT,hours_date DATE); INSERT INTO Volunteer_Hours (id,volunteer,program,hours,hours_date) VALUES (1,'Alice','Education',10,'2021-01-01'); INSERT INTO Volunteer_Hours (id,volunteer,program,hours,hours_date) VALUES (2,'Bob','Environment',15,'2021-02-01'); | SELECT program, AVG(hours) as avg_hours_per_volunteer FROM Volunteer_Hours WHERE YEAR(hours_date) = 2021 AND program = 'Education' GROUP BY program; |
What is the maximum number of hospital beds in rural hospitals of Colorado? | CREATE TABLE hospitals (id INT,name TEXT,location TEXT,beds INT,rural BOOLEAN); INSERT INTO hospitals (id,name,location,beds,rural) VALUES (1,'Hospital A','Colorado',200,true),(2,'Hospital B','Colorado',250,true); | SELECT MAX(beds) FROM hospitals WHERE location = 'Colorado' AND rural = true; |
What is the maximum number of peacekeeping personnel deployed by African Union in a single mission? | CREATE TABLE Peacekeeping_Mission (mission VARCHAR(255),organization VARCHAR(255),start_date DATE,end_date DATE,max_personnel INT); INSERT INTO Peacekeeping_Mission (mission,organization,start_date,end_date,max_personnel) VALUES ('AMISOM','African Union','2007-03-01','2022-02-28',22000); | SELECT MAX(max_personnel) FROM Peacekeeping_Mission WHERE organization = 'African Union'; |
What is the total number of shared e-scooters in Tokyo and Sydney? | CREATE TABLE shared_scooters (city VARCHAR(20),scooters INT);INSERT INTO shared_scooters (city,scooters) VALUES ('Tokyo',1200),('Sydney',1500); | SELECT SUM(scooters) FROM shared_scooters WHERE city IN ('Tokyo', 'Sydney'); |
What is the maximum fair labor certification score for each supplier? | CREATE TABLE suppliers (supplier_id INT,supplier_name VARCHAR(50),fair_labor_certified BOOLEAN,certification_score INT); INSERT INTO suppliers (supplier_id,supplier_name,fair_labor_certified,certification_score) VALUES (1,'Green Vendors',true,90),(2,'Eco Supplies',false,85),(3,'Sustainable Resources',true,95); | SELECT supplier_name, MAX(certification_score) FROM suppliers WHERE fair_labor_certified = true GROUP BY supplier_name; |
What is the total biomass of fish in the 'fish_stock' table for the African region? | CREATE TABLE fish_stock (id INT,location TEXT,biomass FLOAT); INSERT INTO fish_stock (id,location,biomass) VALUES (1,'Africa',500.3); INSERT INTO fish_stock (id,location,biomass) VALUES (2,'Asia',700.9); INSERT INTO fish_stock (id,location,biomass) VALUES (3,'Europe',400.2); INSERT INTO fish_stock (id,location,biomass) VALUES (4,'North America',600.7); | SELECT SUM(biomass) FROM fish_stock WHERE location = 'Africa'; |
Compare the water consumption between commercial and agricultural sectors in 2016 using a UNION operator. | CREATE TABLE water_usage(sector VARCHAR(20),year INT,consumption INT); INSERT INTO water_usage VALUES ('Commercial',2016,7000),('Agricultural',2016,12000); | SELECT sector, consumption FROM (SELECT sector, consumption FROM water_usage WHERE sector = 'Commercial' AND year = 2016 UNION ALL SELECT sector, consumption FROM water_usage WHERE sector = 'Agricultural' AND year = 2016) AS combined_data ORDER BY consumption DESC; |
What's the total production budget for movies released in 2018? | CREATE TABLE movies (id INT,title VARCHAR(255),release_year INT,production_budget INT); INSERT INTO movies (id,title,release_year,production_budget) VALUES (1,'MovieA',2018,12000000); INSERT INTO movies (id,title,release_year,production_budget) VALUES (2,'MovieB',2019,15000000); INSERT INTO movies (id,title,release_year,production_budget) VALUES (3,'MovieC',2018,18000000); | SELECT SUM(production_budget) FROM movies WHERE release_year = 2018; |
What are the names of the traditional music instruments in the Asian culture domain and their countries of origin? | CREATE TABLE TraditionalMusicalInstruments (InstrumentID int,InstrumentName varchar(255),OriginCountry varchar(255),CultureDomain varchar(255)); INSERT INTO TraditionalMusicalInstruments (InstrumentID,InstrumentName,OriginCountry,CultureDomain) VALUES (1,'Sitar','India','Asian'); | SELECT InstrumentName, OriginCountry FROM TraditionalMusicalInstruments WHERE CultureDomain = 'Asian'; |
How many customers have purchased cruelty-free makeup products from our online store? | CREATE TABLE Customers (customer_id INT,customer_name VARCHAR(100),has_purchased_cruelty_free BOOLEAN);CREATE TABLE MakeupSales (sale_id INT,customer_id INT,product_id INT,is_cruelty_free BOOLEAN); | SELECT COUNT(DISTINCT customer_id) FROM Customers c INNER JOIN MakeupSales ms ON c.customer_id = ms.customer_id WHERE c.has_purchased_cruelty_free = TRUE AND ms.is_cruelty_free = TRUE; |
What is the total revenue generated from 'Eco-Friendly Denim' sales in 'Asia' in the last month? | CREATE TABLE Sales (id INT,product VARCHAR(20),region VARCHAR(20),price DECIMAL(5,2),sale_date DATE); INSERT INTO Sales (id,product,region,price,sale_date) VALUES (1,'Sustainable T-Shirt','Europe',25.99,'2022-01-02'),(2,'Regular T-Shirt','North America',19.99,'2022-02-15'),(3,'Eco-Friendly Denim','Asia',39.99,'2022-04-25'),(4,'Eco-Friendly Denim','Asia',39.99,'2022-05-01'),(5,'Eco-Friendly Denim','Asia',39.99,'2022-05-10'); | SELECT SUM(price) FROM Sales WHERE product = 'Eco-Friendly Denim' AND region = 'Asia' AND sale_date >= DATEADD(month, -1, CURRENT_DATE); |
What is the average time to market for each drug that has been approved by the FDA, including the drug name and approval date? | CREATE TABLE drugs (drug_id INT,name VARCHAR(255),approval_date DATE,development_start_date DATE); | SELECT d.name, d.approval_date, AVG(DATEDIFF(d.approval_date, d.development_start_date)) as avg_time_to_market FROM drugs d GROUP BY d.name; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.