instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
Add new textile suppliers with sustainability ratings | CREATE TABLE TextileSuppliers (SupplierID INT,SupplierName TEXT,SustainabilityRating INT); INSERT INTO TextileSuppliers (SupplierID,SupplierName,SustainabilityRating) VALUES (1,'Supplier A',85),(2,'Supplier B',90),(3,'Supplier C',70); | INSERT INTO TextileSuppliers (SupplierID, SupplierName, SustainabilityRating) VALUES (4, 'Supplier D', 82), (5, 'Supplier E', 92); |
What is the total sales revenue for vegetarian and non-vegetarian menu items in the last month? | CREATE TABLE sales (menu_item VARCHAR(255),category VARCHAR(255),sales_revenue DECIMAL(10,2)); INSERT INTO sales (menu_item,category,sales_revenue) VALUES ('Vegetarian Pizza','Pizzas',18.99); INSERT INTO sales (menu_item,category,sales_revenue) VALUES ('Beef Burger','Main Dishes',15.99); | SELECT category, SUM(sales_revenue) as total_revenue FROM sales WHERE sale_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY category; |
Insert data for a recent theater performance | CREATE TABLE EventAttendance (EventID INT PRIMARY KEY,EventName VARCHAR(100),Date DATE,TotalAttendance INT); | INSERT INTO EventAttendance (EventID, EventName, Date, TotalAttendance) VALUES (1, 'Theater Performance', '2022-02-20', 150); |
Delete a broadband subscriber record from the broadband_subscribers table | CREATE TABLE broadband_subscribers (subscriber_id INT,name VARCHAR(100),dob DATE,plan VARCHAR(50),speed INT); | DELETE FROM broadband_subscribers WHERE subscriber_id = 1002; |
How many wildlife habitat scores are available for each South American forest in 2019? | CREATE TABLE wildlife_habitat_scores(year INT,region VARCHAR(255),forest VARCHAR(255),score FLOAT); INSERT INTO wildlife_habitat_scores(year,region,forest,score) VALUES (2018,'Asia','Tropical Forest',80.0),(2018,'Asia','Temperate Forest',85.0),(2019,'South America','Tropical Forest',90.0),(2019,'South America','Temperate Forest',95.0),(2020,'Asia','Tropical Forest',70.0),(2020,'Asia','Temperate Forest',75.0); | SELECT forest, COUNT(*) as num_of_scores FROM wildlife_habitat_scores WHERE year = 2019 AND region = 'South America' GROUP BY forest; |
Show total number of members in each union | CREATE TABLE union_members (id INT,union_name VARCHAR(255),member_count INT); INSERT INTO union_members (id,union_name,member_count) VALUES (1,'Communication Workers of America',700000); INSERT INTO union_members (id,union_name,member_count) VALUES (2,'Service Employees International Union',2000000); | SELECT union_name, SUM(member_count) FROM union_members GROUP BY union_name; |
Delete the record in the "sustainable_practices" table with an ID of 4 | CREATE TABLE sustainable_practices (practice_id INT,description TEXT,category VARCHAR(20)); INSERT INTO sustainable_practices (practice_id,description,category) VALUES (4,'Reducing paper usage','Waste'); | DELETE FROM sustainable_practices WHERE practice_id = 4; |
What is the average donation amount by zip code from the 'donations' table? | CREATE TABLE donations (donor_id INT,zip_code VARCHAR(10),donation_amount DECIMAL(10,2)); INSERT INTO donations (donor_id,zip_code,donation_amount) VALUES (1,'10001',500.00),(2,'10001',750.00),(3,'10002',250.00),(4,'10003',350.00); | SELECT zip_code, AVG(donation_amount) AS 'Average Donation Amount' FROM donations GROUP BY zip_code; |
List all volunteers who have volunteered in both the 'FoodBank' and 'ElderlyCare' programs in the 'Volunteers' and 'VolunteerPrograms' tables. | CREATE TABLE Volunteers (VolunteerID INT,FirstName VARCHAR(50),LastName VARCHAR(50)); CREATE TABLE VolunteerPrograms (ProgramID INT,ProgramName VARCHAR(50),VolunteerID INT); | SELECT V.FirstName, V.LastName FROM Volunteers V INNER JOIN VolunteerPrograms F ON V.VolunteerID = F.VolunteerID INNER JOIN VolunteerPrograms E ON V.VolunteerID = E.VolunteerID WHERE F.ProgramName = 'FoodBank' AND E.ProgramName = 'ElderlyCare'; |
Show the countries with the highest and lowest capacity of wind energy | CREATE TABLE renewable_sources (id INT,name TEXT,country TEXT,capacity FLOAT); INSERT INTO renewable_sources (id,name,country,capacity) VALUES (1,'Wind','China',300); INSERT INTO renewable_sources (id,name,country,capacity) VALUES (2,'Wind','US',250); INSERT INTO renewable_sources (id,name,country,capacity) VALUES (3,'Wind','Germany',200); INSERT INTO renewable_sources (id,name,country,capacity) VALUES (4,'Wind','Spain',150); | SELECT country FROM (SELECT country, ROW_NUMBER() OVER (ORDER BY capacity DESC) as rank FROM renewable_sources WHERE name = 'Wind' UNION ALL SELECT country, ROW_NUMBER() OVER (ORDER BY capacity) as rank FROM renewable_sources WHERE name = 'Wind') as ranked_wind WHERE rank = 1 OR rank = (SELECT COUNT(*) FROM renewable_sources WHERE name = 'Wind') |
Display water conservation initiatives and their durations | CREATE TABLE water_conservation_initiatives (id INT,name VARCHAR(50),description TEXT,start_date DATE,end_date DATE); | SELECT name, end_date - start_date as duration FROM water_conservation_initiatives; |
Who provided the most shelter assistance in Iraq in Q2 2022? | CREATE TABLE shelter_assistance (id INT,organization TEXT,quantity INT,country TEXT,quarter INT,year INT); INSERT INTO shelter_assistance (id,organization,quantity,country,quarter,year) VALUES (1,'UNHCR',1000,'Iraq',2,2022),(2,'IRC',800,'Iraq',2,2022),(3,'Save the Children',600,'Iraq',2,2022); | SELECT organization, SUM(quantity) FROM shelter_assistance WHERE country = 'Iraq' AND quarter = 2 AND year = 2022 GROUP BY organization ORDER BY SUM(quantity) DESC LIMIT 1; |
Insert new satellite imagery records for the specified list of fields. | CREATE TABLE satellite_imagery (image_id INT,user_id INT,field_id INT,image_date DATE,image_quality INT); | INSERT INTO satellite_imagery (image_id, user_id, field_id, image_date, image_quality) VALUES (1, 5, 10, '2022-02-01', 8), (2, 6, 11, '2022-02-02', 9); |
What is the average number of publications per graduate student in the Mathematics department? | CREATE TABLE graduate_students (id INT,student_name VARCHAR(255),department VARCHAR(255)); CREATE TABLE published_papers (id INT,paper_title VARCHAR(255),student_id INT,PRIMARY KEY (id),FOREIGN KEY (student_id) REFERENCES graduate_students(id)); INSERT INTO graduate_students (id,student_name,department) VALUES (1,'Student1','Mathematics'),(2,'Student2','Mathematics'),(3,'Student3','Mathematics'),(4,'Student4','Physics'),(5,'Student5','Physics'); INSERT INTO published_papers (id,paper_title,student_id) VALUES (1,'Paper1',1),(2,'Paper2',2),(3,'Paper3',3),(4,'Paper4',1),(5,'Paper5',5); | SELECT AVG(pp_count) as avg_publications FROM (SELECT COUNT(pp.id) as pp_count FROM published_papers pp JOIN graduate_students gs ON pp.student_id = gs.id WHERE gs.department = 'Mathematics' GROUP BY gs.id) AS subquery; |
What is the average depth of all marine protected areas in the Antarctic region? | CREATE TABLE marine_protected_areas_antarctic (name VARCHAR(255),region VARCHAR(255),avg_depth FLOAT); INSERT INTO marine_protected_areas_antarctic (name,region,avg_depth) VALUES ('Ross Sea','Antarctic',150.0),('Weddell Sea','Antarctic',250.0); | SELECT AVG(avg_depth) FROM marine_protected_areas_antarctic WHERE region = 'Antarctic'; |
How many users signed up for a membership plan with 'Premium' label? | CREATE TABLE memberships (id INT,user_id INT,plan_label VARCHAR(10)); INSERT INTO memberships (id,user_id,plan_label) VALUES (1,3,'Basic'); INSERT INTO memberships (id,user_id,plan_label) VALUES (2,4,'Premium'); | SELECT COUNT(*) FROM memberships WHERE plan_label = 'Premium'; |
What is the adoption rate of AI-powered concierge services in the hotel industry for the 'Americas' region? | CREATE TABLE ai_concierge (id INT,hotel_id INT,region TEXT,adoption_rate FLOAT); INSERT INTO ai_concierge (id,hotel_id,region,adoption_rate) VALUES (1,1,'Americas',0.5),(2,2,'Americas',0.7),(3,3,'Europe',0.9),(4,4,'Asia-Pacific',0.8); CREATE TABLE hotels (id INT,name TEXT,region TEXT); INSERT INTO hotels (id,name,region) VALUES (1,'Hotel Z','Americas'),(2,'Hotel AA','Americas'),(3,'Hotel AB','Europe'),(4,'Hotel AC','Asia-Pacific'); | SELECT region, AVG(adoption_rate) FROM ai_concierge a JOIN hotels h ON a.hotel_id = h.id WHERE h.region = 'Americas' GROUP BY region; |
What's the highest priced digital asset by type? | CREATE TABLE digital_assets (id INT,name VARCHAR(255),type VARCHAR(50),price DECIMAL(10,2)); INSERT INTO digital_assets (id,name,type,price) VALUES (1,'Asset1','Crypto',10.5); INSERT INTO digital_assets (id,name,type,price) VALUES (2,'Asset2','Crypto',20.2); INSERT INTO digital_assets (id,name,type,price) VALUES (3,'Asset3','Security',50.0); INSERT INTO digital_assets (id,name,type,price) VALUES (4,'Asset4','Security',75.0); | SELECT type, MAX(price) FROM digital_assets GROUP BY type; |
Add a new record to the "AgriculturalInnovations" table for a new precision agriculture tool called 'Autosteer System' | CREATE TABLE AgriculturalInnovations (id INT PRIMARY KEY,innovation_name VARCHAR(255),category VARCHAR(255),year_introduced INT); | INSERT INTO AgriculturalInnovations (innovation_name, category, year_introduced) VALUES ('Autosteer System', 'Precision Agriculture', 2022); |
List all volunteers who have made donations in the last month. | CREATE TABLE Volunteers (VolunteerID INT,Name TEXT); INSERT INTO Volunteers (VolunteerID,Name) VALUES (1,'Jamal Smith'),(2,'Sophia Rodriguez'); CREATE TABLE Donors (DonorID INT,VolunteerID INT,DonationDate DATE); INSERT INTO Donors (DonorID,VolunteerID,DonationDate) VALUES (1,1,'2022-02-10'),(2,1,'2022-03-15'),(3,2,'2022-01-20'); | SELECT Volunteers.Name FROM Volunteers INNER JOIN Donors ON Volunteers.VolunteerID = Donors.VolunteerID WHERE Donors.DonationDate >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH); |
What is the total quantity of sustainable fabric used by each textile supplier in the EU? | CREATE TABLE TextileSuppliers (SupplierID INT,SupplierName TEXT,Country TEXT,SustainableFabricQty INT); INSERT INTO TextileSuppliers (SupplierID,SupplierName,Country,SustainableFabricQty) VALUES (1,'GreenFabrics','Germany',5000),(2,'EcoWeaves','France',7000),(3,'SustainableTextiles','Italy',6000); | SELECT Country, SUM(SustainableFabricQty) FROM TextileSuppliers WHERE Country IN ('Germany', 'France', 'Italy') GROUP BY Country; |
What is the minimum and maximum labor hours for producing each product? | CREATE TABLE Products (ProductID INT,ProductName VARCHAR(50)); INSERT INTO Products (ProductID,ProductName) VALUES (1,'ProductA'),(2,'ProductB'),(3,'ProductC'); CREATE TABLE LaborHours (HourID INT,LaborHours DECIMAL(5,2),ProductID INT); INSERT INTO LaborHours (HourID,LaborHours,ProductID) VALUES (1,5.50,1),(2,6.60,1),(3,7.70,2),(4,8.80,2),(5,9.90,3),(6,10.00,3); | SELECT ProductName, MIN(LaborHours) as MinLaborHours, MAX(LaborHours) as MaxLaborHours FROM Products p JOIN LaborHours lh ON p.ProductID = lh.ProductID GROUP BY ProductName; |
What is the average safety rating of Japanese cars? | CREATE TABLE Safety_Testing (year INT,make VARCHAR(50),model VARCHAR(50),rating FLOAT); INSERT INTO Safety_Testing (year,make,model,rating) VALUES (2022,'Toyota','Corolla',5.2); INSERT INTO Safety_Testing (year,make,model,rating) VALUES (2022,'Honda','Civic',5.1); | SELECT AVG(rating) FROM Safety_Testing WHERE make = 'Japanese'; |
What is the average success rate of 'sustainable agricultural innovation projects' in 'Sub-Saharan Africa'? | CREATE TABLE projects (id INT,name TEXT,region TEXT,success BOOLEAN,type TEXT); INSERT INTO projects (id,name,region,success,type) VALUES (1,'Project 1','Sub-Saharan Africa',TRUE,'sustainable agricultural'),(2,'Project 2','Sub-Saharan Africa',FALSE,'agricultural'),(3,'Project 3','Sub-Saharan Africa',TRUE,'sustainable agricultural'); | SELECT AVG(projects.success) FROM projects WHERE projects.region = 'Sub-Saharan Africa' AND projects.type = 'sustainable agricultural'; |
What is the total revenue for each sustainable menu item category in 2022? | CREATE TABLE sustainable_revenue(menu_item VARCHAR(255),category VARCHAR(255),revenue DECIMAL(10,2),sustainable_source BOOLEAN); INSERT INTO sustainable_revenue VALUES ('Vegan Sushi','Vegan',1500,TRUE); INSERT INTO sustainable_revenue VALUES ('Chicken Caesar Salad','Salads',2000,FALSE); INSERT INTO sustainable_revenue VALUES ('Falafel Wrap','Middle Eastern',1000,TRUE); | SELECT category, SUM(revenue) FROM sustainable_revenue WHERE sustainable_source = TRUE AND YEAR(date) = 2022 GROUP BY category; |
What is the location of 'Site Delta' in the 'mining_sites' table? | CREATE TABLE mining_sites (id INT,name VARCHAR(50),location VARCHAR(50),num_employees INT); INSERT INTO mining_sites (id,name,location,num_employees) VALUES (1,'Site Alpha','USA',100),(2,'Site Bravo','Canada',150),(3,'Site Charlie','Australia',200),(4,'Site Delta','India',250); | SELECT location FROM mining_sites WHERE name = 'Site Delta'; |
List all the unique threat types in the healthcare sector. | CREATE TABLE threats (id INT,sector VARCHAR(20),type VARCHAR(50)); INSERT INTO threats (id,sector,type) VALUES (1,'Healthcare','Phishing'),(2,'Healthcare','Malware'),(3,'Financial','Ransomware'); | SELECT DISTINCT type FROM threats WHERE sector = 'Healthcare'; |
Delete the chemical_manufacturing table and all of its records. | CREATE TABLE chemical_manufacturing (id INT PRIMARY KEY,chemical_name VARCHAR(100),manufacturing_location VARCHAR(100),production_volume INT); INSERT INTO chemical_manufacturing (id,chemical_name,manufacturing_location,production_volume) VALUES (1,'Hydrochloric Acid','USA',1000),(2,'Sulfuric Acid','China',1500),(3,'Sodium Hydroxide','India',800); | DROP TABLE chemical_manufacturing; |
What was the total value of military equipment sales to South America in the last quarter? | CREATE TABLE Military_Equipment_Sales(sale_id INT,sale_date DATE,equipment_type VARCHAR(50),country VARCHAR(50),sale_value DECIMAL(10,2)); | SELECT SUM(sale_value) FROM Military_Equipment_Sales WHERE country IN (SELECT country FROM World_Countries WHERE continent = 'South America') AND sale_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH); |
What is the total revenue for each sales region in the ethical fashion market in the last month? | CREATE TABLE sales_region(sale_id INT,region VARCHAR(20),revenue DECIMAL(5,2)); INSERT INTO sales_region(sale_id,region,revenue) VALUES(1,'North America',200.00),(2,'Europe',150.00),(3,'Asia',250.00),(4,'Australia',100.00),(5,'Africa',50.00); | SELECT region, SUM(revenue) FROM sales_region WHERE date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY region; |
Which sustainable suppliers are located in Africa? | CREATE TABLE Suppliers (id INT,country VARCHAR(20),supplier VARCHAR(20),sustainable BOOLEAN); INSERT INTO Suppliers (id,country,supplier,sustainable) VALUES (1,'USA','Acme',true),(2,'Canada','Beta',false),(3,'Mexico','Charlie',true),(4,'China','Delta',false),(5,'Egypt','Epsilon',true); | SELECT supplier FROM Suppliers WHERE sustainable = true AND country LIKE 'Africa%'; |
What is the average severity of vulnerabilities detected in the financial sector in the last quarter? | CREATE TABLE vulnerabilities (id INT,sector VARCHAR(255),severity FLOAT,detection_date DATE); INSERT INTO vulnerabilities (id,sector,severity,detection_date) VALUES (1,'financial',7.5,'2021-01-01'); | SELECT AVG(severity) FROM vulnerabilities WHERE sector = 'financial' AND detection_date >= DATE_SUB(CURDATE(), INTERVAL 3 MONTH); |
What is the total climate finance for projects in the Pacific region focused on climate adaptation and water management? | CREATE TABLE pacific_climate_finance (fund_id INT,project_name VARCHAR(100),country VARCHAR(50),sector VARCHAR(50),amount FLOAT,adaptation_flag BOOLEAN,water_management_flag BOOLEAN); INSERT INTO pacific_climate_finance (fund_id,project_name,country,sector,amount,adaptation_flag,water_management_flag) VALUES (1,'Water Management for Climate Adaptation','Fiji','Water',15000000,TRUE,TRUE); | SELECT SUM(amount) FROM pacific_climate_finance WHERE country LIKE '%%pacific%%' AND adaptation_flag = TRUE AND water_management_flag = TRUE; |
Find the average cost of rural infrastructure projects in the 'Infrastructure' table that were completed after 2016? | CREATE TABLE Infrastructure (id INT,project VARCHAR(255),location VARCHAR(255),year INT,cost FLOAT); INSERT INTO Infrastructure (id,project,location,year,cost) VALUES (1,'Bridge','Rural East',2015,1500000),(2,'Road','Urban North',2017,5000000),(3,'Water Supply','Rural South',2016,3000000),(4,'Electricity','Urban West',2018,7000000); | SELECT AVG(cost) as avg_cost FROM Infrastructure WHERE location LIKE '%Rural%' AND year > 2016; |
Who are the teachers that have participated in the most professional development courses? | CREATE TABLE teacher_pd (teacher_id INT,course VARCHAR(20),hours INT); INSERT INTO teacher_pd (teacher_id,course,hours) VALUES (1,'technology integration',12),(2,'classroom_management',10),(3,'technology integration',15),(4,'diversity_equity_inclusion',20); CREATE VIEW hours_per_teacher AS SELECT teacher_id,SUM(hours) as total_hours FROM teacher_pd GROUP BY teacher_id; | SELECT teacher_id FROM hours_per_teacher ORDER BY total_hours DESC LIMIT 1; |
What are the names and regions of all traditional artists? | CREATE TABLE Artists (Artist_ID INT PRIMARY KEY,Name VARCHAR(100),Country VARCHAR(50),Region VARCHAR(50)); INSERT INTO Artists (Artist_ID,Name,Country,Region) VALUES (1,'Alice','Australia','Southern'); INSERT INTO Artists (Artist_ID,Name,Country,Region) VALUES (2,'Bob','New Zealand','Southern'); | SELECT Name, Region FROM Artists; |
What is the total cost of military equipment maintenance contracts awarded to each vendor, ranked from highest to lowest? | CREATE TABLE Vendors (VendorID INT PRIMARY KEY,Name VARCHAR(50)); CREATE TABLE Contracts (ContractID INT PRIMARY KEY,VendorID INT,Cost DECIMAL(10,2),FOREIGN KEY (VendorID) REFERENCES Vendors(VendorID)); INSERT INTO Vendors (VendorID,Name) VALUES (1,'ABC Corp'),(2,'DEF Industries'),(3,'GHI Inc'),(4,'JKL Enterprises'); INSERT INTO Contracts (ContractID,VendorID,Cost) VALUES (1,1,1250000.00),(2,1,1500000.00),(3,2,1100000.00),(4,3,800000.00),(5,3,900000.00),(6,4,1600000.00),(7,4,1800000.00); | SELECT v.Name, SUM(c.Cost) AS TotalCost FROM Vendors v JOIN Contracts c ON v.VendorID = c.VendorID GROUP BY v.Name ORDER BY TotalCost DESC; |
How many patients with hypertension in rural Montana are over the age of 70? | CREATE TABLE patients (id INT,name VARCHAR(50),age INT,gender VARCHAR(10),diagnosis VARCHAR(50),location VARCHAR(50)); INSERT INTO patients (id,name,age,gender,diagnosis,location) VALUES (1,'Jane Doe',75,'Female','Hypertension','Montana'),(2,'John Doe',50,'Male','Hypertension','Montana'),(3,'Jim Brown',72,'Male','Hypertension','Montana'); | SELECT COUNT(*) FROM patients WHERE diagnosis = 'Hypertension' AND location = 'Montana' AND age > 70; |
How many volunteers are needed for each program in the Asian region? | CREATE TABLE programs (id INT,name VARCHAR(50),location VARCHAR(50)); CREATE TABLE volunteers (id INT,name VARCHAR(50),program_id INT); INSERT INTO programs (id,name,location) VALUES (1,'Education','Asia'),(2,'Environment','Asia'),(3,'Arts','Asia'); INSERT INTO volunteers (id,name,program_id) VALUES (1,'Alice',1),(2,'Bob',1),(3,'Charlie',2),(4,'David',3),(5,'Eve',3),(6,'Faye',NULL); | SELECT p.name, COUNT(v.id) FROM programs p LEFT JOIN volunteers v ON p.id = v.program_id WHERE p.location = 'Asia' GROUP BY p.name; |
How many tunnels are there in total? | CREATE TABLE tunnels (id INT,name TEXT,location TEXT); INSERT INTO tunnels (id,name,location) VALUES (1,'Tunnel1','northwest'),(2,'Tunnel2','northwest'),(3,'Tunnel3','southeast'); | SELECT COUNT(*) FROM tunnels; |
Insert a new record for a student with the following details: student_id: 1002, name: John Doe, last_attendance: 2023-01-16 | CREATE TABLE students (student_id INT,name VARCHAR(50),last_attendance DATETIME); | INSERT INTO students (student_id, name, last_attendance) VALUES (1002, 'John Doe', '2023-01-16'); |
What is the total quantity of seafood harvested from sustainable aquatic farms in North America? | CREATE TABLE aquatic_farms (id INT,name TEXT,country TEXT,sustainable BOOLEAN); CREATE TABLE harvests (id INT,farm_id INT,quantity INT); INSERT INTO aquatic_farms (id,name,country,sustainable) VALUES (1,'Farm A','Canada',TRUE),(2,'Farm B','Canada',FALSE),(3,'Farm C','US',TRUE),(4,'Farm D','US',TRUE); INSERT INTO harvests (id,farm_id,quantity) VALUES (1,1,500),(2,1,700),(3,3,800),(4,3,900),(5,4,600); | SELECT SUM(harvests.quantity) FROM harvests JOIN aquatic_farms ON harvests.farm_id = aquatic_farms.id WHERE aquatic_farms.sustainable = TRUE AND aquatic_farms.country = 'Canada' OR aquatic_farms.country = 'US'; |
List the stars hosting at least 2 habitable exoplanets in the Libra constellation. | CREATE TABLE exoplanets (id INT,name VARCHAR(50),discovery_date DATE,discovery_method VARCHAR(50),host_star VARCHAR(50),right_ascension FLOAT,declination FLOAT,habitable BOOLEAN); CREATE VIEW habitable_exoplanets AS SELECT * FROM exoplanets WHERE habitable = TRUE; CREATE VIEW libra_exoplanets AS SELECT * FROM habitable_exoplanets WHERE right_ascension BETWEEN 14.5 AND 16 AND declination BETWEEN -20 AND -5; | SELECT host_star FROM libra_exoplanets GROUP BY host_star HAVING COUNT(*) >= 2; |
How many events were hosted by the National Museum of African American History and Culture in 2021? | CREATE TABLE MuseumEvents (EventID int,EventName varchar(100),EventDate date,MuseumName varchar(100)); INSERT INTO MuseumEvents (EventID,EventName,EventDate,MuseumName) VALUES (1,'Exhibit A','2021-01-01','National Museum of African American History and Culture'),(2,'Concert B','2021-12-31','National Museum of African American History and Culture'),(3,'Lecture X','2022-02-01','Smithsonian American Art Museum'); | SELECT COUNT(*) FROM MuseumEvents WHERE MuseumName = 'National Museum of African American History and Culture' AND YEAR(EventDate) = 2021; |
Count the number of products in the 'home goods' category | CREATE TABLE products (product_id INT,category VARCHAR(20),quantity INT); INSERT INTO products (product_id,category,quantity) VALUES (1,'home goods',10),(2,'home goods',20),(3,'home goods',30); | SELECT COUNT(*) FROM products WHERE category = 'home goods'; |
What is the maximum military equipment sale price by Northrop Grumman in 2020? | CREATE TABLE MilitaryEquipmentSales (EquipmentID INT,Manufacturer VARCHAR(50),DestinationCountry VARCHAR(50),SaleDate DATE,Quantity INT,UnitPrice FLOAT); INSERT INTO MilitaryEquipmentSales (EquipmentID,Manufacturer,DestinationCountry,SaleDate,Quantity,UnitPrice) VALUES (1,'Lockheed Martin','Algeria','2020-01-10',5,1000000.00),(2,'Northrop Grumman','Egypt','2020-02-15',3,1500000.00),(3,'Lockheed Martin','Nigeria','2020-03-20',7,800000.00); | SELECT MAX(UnitPrice) FROM MilitaryEquipmentSales WHERE Manufacturer = 'Northrop Grumman' AND YEAR(SaleDate) = 2020; |
What was the total revenue for the Hip-Hop genre in 2019? | CREATE TABLE music_sales (sale_id INT,genre VARCHAR(10),year INT,revenue FLOAT); INSERT INTO music_sales (sale_id,genre,year,revenue) VALUES (1,'Pop',2021,50000.00),(2,'Rock',2021,45000.00),(3,'Pop',2020,40000.00),(4,'Jazz',2020,30000.00),(5,'Hip-Hop',2019,25000.00); CREATE VIEW genre_sales AS SELECT genre,SUM(revenue) as total_revenue FROM music_sales GROUP BY genre; | SELECT total_revenue FROM genre_sales WHERE genre = 'Hip-Hop' AND year = 2019; |
What is the name of the latest military aircraft manufactured in the United Kingdom? | CREATE TABLE MilitaryAircrafts(id INT PRIMARY KEY,name VARCHAR(50),model VARCHAR(50),country VARCHAR(50));INSERT INTO MilitaryAircrafts(id,name,model,country) VALUES (1,'Tempest','FCAS','United Kingdom'); | SELECT name FROM MilitaryAircrafts WHERE country = 'United Kingdom' ORDER BY id DESC LIMIT 1; |
What is the average revenue per cultural heritage site in Spain and Portugal? | CREATE TABLE cultural_heritage (id INT,country VARCHAR(20),site VARCHAR(20),revenue FLOAT); INSERT INTO cultural_heritage (id,country,site,revenue) VALUES (1,'Spain','Alhambra',1000.0),(2,'Spain','Prado Museum',1500.0),(3,'Portugal','Belem Tower',800.0); | SELECT AVG(revenue) FROM cultural_heritage WHERE country IN ('Spain', 'Portugal'); |
What is the average landfill capacity in cubic meters for the top 2 regions in 2018? | CREATE TABLE landfill_capacity (region VARCHAR(255),year INT,capacity FLOAT); INSERT INTO landfill_capacity (region,year,capacity) VALUES ('North America',2018,5000000.0),('South America',2018,3000000.0),('Europe',2018,4000000.0); | SELECT lc.region, AVG(lc.capacity) as avg_capacity FROM landfill_capacity lc WHERE lc.year = 2018 AND lc.region IN (SELECT region FROM landfill_capacity WHERE year = 2018 ORDER BY capacity DESC LIMIT 2) GROUP BY lc.region; |
Update the purchase date for all submarines to be one month earlier than their current purchase date | CREATE TABLE military_equipment (equipment_type VARCHAR(255),purchase_date DATE); INSERT INTO military_equipment (equipment_type,purchase_date) VALUES ('Tank','2011-01-01'),('Jet','2012-01-01'),('Submarine','2005-01-01'); | UPDATE military_equipment SET purchase_date = DATE_SUB(purchase_date, INTERVAL 1 MONTH) WHERE equipment_type = 'Submarine'; |
Identify the top 5 fields with the highest total oil production in 2022 | CREATE TABLE field (id INT,name VARCHAR(50),location VARCHAR(50)); CREATE TABLE oil_production (field_id INT,date DATE,oil_production FLOAT); | SELECT f.name, SUM(op.oil_production) AS total_oil_production FROM field f JOIN oil_production op ON f.id = op.field_id WHERE op.date BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY f.id ORDER BY total_oil_production DESC LIMIT 5; |
What is the average age of volunteers who participated in the 'Education' program? | CREATE TABLE Programs (ProgramID int,Name varchar(50),Budget money); CREATE TABLE Volunteers (VolunteerID int,Name varchar(50),Age int,ProgramID int); INSERT INTO Programs (ProgramID,Name,Budget) VALUES (1,'Education',10000),(2,'Healthcare',15000); INSERT INTO Volunteers (VolunteerID,Name,Age,ProgramID) VALUES (1,'Alice',25,1),(2,'Bob',22,1),(3,'Charlie',30,2),(4,'David',28,2); | SELECT AVG(V.Age) as AvgAge FROM Volunteers V WHERE V.ProgramID = (SELECT P.ProgramID FROM Programs P WHERE P.Name = 'Education'); |
What is the total CO2 emissions for garments sourced from Africa? | CREATE TABLE sourcing (id INT,garment_id INT,country VARCHAR(50),CO2_emissions INT); INSERT INTO sourcing (id,garment_id,country,CO2_emissions) VALUES (1,1006,'Africa',8); | SELECT SUM(CO2_emissions) FROM sourcing WHERE country = 'Africa'; |
What is the total revenue generated from the sale of clothing products in the EU? | CREATE TABLE revenue (region VARCHAR(10),product VARCHAR(20),revenue INT); INSERT INTO revenue (region,product,revenue) VALUES ('EU','shirt',15000),('EU','pants',20000); | SELECT SUM(revenue) FROM revenue WHERE region = 'EU'; |
Which regions have the highest and lowest energy efficiency ratings in the buildings, energy_efficiency, and regions tables? | CREATE TABLE buildings(id INT,building_name VARCHAR(50),building_type VARCHAR(50),region_id INT);CREATE TABLE energy_efficiency(building_id INT,rating INT);CREATE TABLE regions(id INT,region_name VARCHAR(50),country VARCHAR(50)); | SELECT r.region_name, AVG(e.rating) AS avg_rating FROM buildings b INNER JOIN energy_efficiency e ON b.id = e.building_id INNER JOIN regions r ON b.region_id = r.id GROUP BY r.region_name ORDER BY avg_rating DESC, region_name; |
Count the number of sustainable items per category | CREATE TABLE items (id INT,category VARCHAR(50),subcategory VARCHAR(50),is_sustainable BOOLEAN); INSERT INTO items (id,category,subcategory,is_sustainable) VALUES (1,'Clothing','Tops',TRUE),(2,'Clothing','Pants',TRUE),(3,'Clothing','Dresses',FALSE),(4,'Clothing','Jackets',TRUE),(5,'Clothing','Skirts',FALSE),(6,'Accessories','Hats',FALSE),(7,'Accessories','Scarves',TRUE),(8,'Accessories','Belts',FALSE),(9,'Footwear','Sneakers',TRUE),(10,'Footwear','Sandals',FALSE); | SELECT category, COUNT(*) FROM items WHERE is_sustainable = TRUE GROUP BY category; |
What is the average age of patients diagnosed with asthma in 'RuralHealthFacility1'? | CREATE TABLE RuralHealthFacility1 (id INT,name TEXT,age INT,diagnosis TEXT); INSERT INTO RuralHealthFacility1 (id,name,age,diagnosis) VALUES (1,'John Doe',35,'Asthma'),(2,'Jane Smith',42,'Pneumonia'); | SELECT AVG(age) FROM RuralHealthFacility1 WHERE diagnosis = 'Asthma'; |
What is the total quantity of each mineral extracted, ordered by the most to least? | CREATE TABLE MineralExtraction (ExtractionID INT,MineName VARCHAR(50),Mineral VARCHAR(50),Quantity DECIMAL(10,2)); INSERT INTO MineralExtraction (ExtractionID,MineName,Mineral,Quantity) VALUES (1,'ABC Mine','Coal',150000.00); INSERT INTO MineralExtraction (ExtractionID,MineName,Mineral,Quantity) VALUES (2,'DEF Mine','Gold',5000.00); INSERT INTO MineralExtraction (ExtractionID,MineName,Mineral,Quantity) VALUES (3,'GHI Mine','Iron Ore',80000.00); | SELECT ExtractionID, MineName, Mineral, Quantity, ROW_NUMBER() OVER (ORDER BY Quantity DESC) as 'Rank' FROM MineralExtraction; |
What is the total cost of astronaut medical treatments? | CREATE TABLE astronauts (id INT,name VARCHAR(50));CREATE TABLE medical_treatments (id INT,astronaut_id INT,cost INT); INSERT INTO astronauts VALUES (1,'Melissa Lewis'); INSERT INTO medical_treatments VALUES (1,1),(2,1),(3,1); INSERT INTO medical_treatments VALUES (1,1,5000),(2,1,7000),(3,1,10000); | SELECT SUM(medical_treatments.cost) as total_cost FROM medical_treatments INNER JOIN astronauts ON medical_treatments.astronaut_id = astronauts.id; |
Update the investment amounts for all organizations in the technology sector to 1.1 times their current value. | CREATE TABLE investments (investment_id INT,investor_id INT,org_id INT,investment_amount INT); INSERT INTO investments (investment_id,investor_id,org_id,investment_amount) VALUES (1,1,8,45000),(2,2,9,55000),(3,1,7,75000),(4,3,8,60000),(5,2,7,90000); CREATE TABLE organizations (org_id INT,org_name TEXT,focus_topic TEXT); INSERT INTO organizations (org_id,org_name,focus_topic) VALUES (7,'Org 7','Technology'),(8,'Org 8','Technology'),(9,'Org 9','Healthcare'); | UPDATE investments SET investment_amount = investments.investment_amount * 1.1 WHERE investments.org_id IN (SELECT organizations.org_id FROM organizations WHERE organizations.focus_topic = 'Technology'); |
How many clinical trials were conducted in each country in 2023, unpivoted by phase? | CREATE TABLE clinical_trials_2023 (country VARCHAR(20),phase INT,trials INT); INSERT INTO clinical_trials_2023 (country,phase,trials) VALUES ('USA',1,25),('USA',2,35),('USA',3,45),('Canada',1,20),('Canada',2,30),('Canada',3,40); | SELECT country, phase, SUM(trials) AS total_trials FROM clinical_trials_2023 GROUP BY country, phase ORDER BY country; |
What is the total number of mental health appointments by day of the week for each gender? | CREATE TABLE mental_health_appointments (id INT,gender VARCHAR(50),appointment_date DATE); INSERT INTO mental_health_appointments (id,gender,appointment_date) VALUES (1,'Female','2022-01-01'),(2,'Male','2022-01-02'),(3,'Female','2022-01-03'); | SELECT gender, DATE_FORMAT(appointment_date, '%W') AS day_of_week, COUNT(*) FROM mental_health_appointments GROUP BY gender, day_of_week; |
What is the average daily number of visitors for exhibits in the museum_operations table, excluding temporary exhibits? | CREATE TABLE museum_operations (exhibit_id INT,exhibit_name TEXT,start_date DATE,end_date DATE,daily_visitors INT); | SELECT AVG(daily_visitors) FROM museum_operations WHERE DATEDIFF(end_date, start_date) > 30; |
Calculate the total number of members in unions that have a focus on worker safety. | CREATE TABLE union_safety (union_id INT,union_name TEXT,safety_focus BOOLEAN); INSERT INTO union_safety (union_id,union_name,safety_focus) VALUES (1,'Safety Union A',true),(2,'Labor Union B',false),(3,'Safety Union C',true); | SELECT COUNT(*) FROM union_safety WHERE safety_focus = true; |
What is the average popularity of products in each size per month? | CREATE TABLE trend (id INT,product_id INT,popularity INT,date DATE); INSERT INTO trend (id,product_id,popularity,date) VALUES (1,1,100,'2023-01-01'); CREATE TABLE size (id INT,size VARCHAR(50)); INSERT INTO size (id,size) VALUES (1,'Small'),(2,'Medium'),(3,'Large'); | SELECT s.size, AVG(t.popularity) as avg_popularity, DATE_TRUNC('month', t.date) as month FROM trend t JOIN product p ON t.product_id = p.id JOIN size s ON p.size = s.size GROUP BY month, s.size ORDER BY month; |
Determine the maximum price of 'Recycled Nylon Bags' sold in a single order. | CREATE TABLE garments (id INT,name VARCHAR(255),category VARCHAR(255),country VARCHAR(255),price DECIMAL(10,2)); INSERT INTO garments (id,name,category,country,price) VALUES (1,'Recycled Nylon Bag','Accessories','Germany',120.00); CREATE TABLE orders (id INT,garment_id INT,quantity INT,order_date DATE,price DECIMAL(10,2)); | SELECT MAX(price) FROM orders WHERE garment_id IN (SELECT id FROM garments WHERE name = 'Recycled Nylon Bag'); |
How many ports are there in the Asia-Pacific region? | CREATE TABLE ports (id INT,name VARCHAR(50),region VARCHAR(50)); INSERT INTO ports (id,name,region) VALUES (1,'PortA','Asia-Pacific'),(2,'PortB','Americas'),(3,'PortC','Asia-Pacific'); | SELECT COUNT(*) FROM ports WHERE region = 'Asia-Pacific'; |
What was the market access strategy for 'DrugB' in 'CountryZ'? | CREATE TABLE market_access (drug varchar(20),country varchar(20),strategy varchar(50)); INSERT INTO market_access (drug,country,strategy) VALUES ('DrugB','CountryZ','Exclusive Distribution'); | SELECT strategy FROM market_access WHERE drug = 'DrugB' AND country = 'CountryZ'; |
What is the average price of artworks for each year in the 'Artworks' table? | CREATE TABLE Artworks (id INT,art_category VARCHAR(255),artist_name VARCHAR(255),year INT,art_medium VARCHAR(255),price DECIMAL(10,2)); | SELECT year, AVG(price) as avg_price FROM Artworks GROUP BY year; |
Which countries have the highest and lowest climate finance investments in renewable energy? | CREATE TABLE finance (country VARCHAR(255),sector VARCHAR(255),amount FLOAT); INSERT INTO finance (country,sector,amount) VALUES ('CountryX','Renewable Energy',5000000),('CountryY','Renewable Energy',7000000),('CountryZ','Renewable Energy',3000000); | SELECT sector, MAX(amount) AS max_investment, MIN(amount) AS min_investment FROM finance WHERE sector = 'Renewable Energy' GROUP BY sector; |
What is the maximum investment in water conservation initiatives for organizations with over 5000 employees? | CREATE TABLE water_conservation_investments (id INT,organization_name VARCHAR(50),employees INT,investment DECIMAL(10,2)); INSERT INTO water_conservation_investments (id,organization_name,employees,investment) VALUES (1,'Corp X',10000,15000.00),(2,'Corp Y',3000,5000.00),(3,'Corp Z',5000,8000.00); | SELECT MAX(investment) FROM water_conservation_investments WHERE employees > 5000; |
What is the average salary of employees in the Engineering department, and the number of employees with a salary higher than the average salary? | CREATE TABLE Employees (EmployeeID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50),Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,Salary) VALUES (1,'John','Doe','Engineering',75000.00),(2,'Jane','Doe','Engineering',80000.00),(3,'Mike','Smith','Marketing',60000.00),(4,'Samantha','Johnson','Engineering',85000.00),(5,'David','Brown','Marketing',65000.00); | SELECT AVG(Salary) OVER (PARTITION BY Department) AS Avg_Salary, COUNT(CASE WHEN Salary > AVG(Salary) OVER (PARTITION BY Department) THEN 1 END) OVER (PARTITION BY Department) AS High_Salary_Count FROM Employees WHERE Department = 'Engineering'; |
Show the top 3 countries with the highest total ticket sales | CREATE TABLE ticket_sales (ticket_id INT,team_id INT,country VARCHAR(50),price DECIMAL(5,2)); INSERT INTO ticket_sales (ticket_id,team_id,country,price) VALUES (1,1,'USA',75.50),(2,1,'Canada',85.20),(3,2,'USA',65.00),(4,2,'Canada',75.00),(5,3,'Mexico',100.00),(6,3,'Mexico',120.00); | SELECT country, SUM(price) FROM ticket_sales GROUP BY country ORDER BY SUM(price) DESC LIMIT 3; |
How many clients have made at least one investment in the past year? | CREATE TABLE clients (id INT,registered_date DATE);CREATE TABLE investments (id INT,client_id INT,investment_date DATE); INSERT INTO clients (id,registered_date) VALUES (1,'2020-01-01'),(2,'2019-01-01'),(3,'2018-01-01'); INSERT INTO investments (id,client_id,investment_date) VALUES (1,1,'2021-02-01'),(2,1,'2021-03-01'),(3,2,'2020-04-01'),(4,3,'2017-05-01'); | SELECT COUNT(DISTINCT c.id) FROM clients c WHERE EXISTS (SELECT 1 FROM investments i WHERE c.id = i.client_id AND i.investment_date >= c.registered_date + INTERVAL '1 year'); |
Which OTA has the highest number of bookings in the EMEA region? | CREATE TABLE otas (id INT,name TEXT,region TEXT,bookings INT); INSERT INTO otas (id,name,region,bookings) VALUES (1,'OTA 1','EMEA',1200),(2,'OTA 2','APAC',800),(3,'OTA 3','Americas',1500),(4,'OTA 4','EMEA',1800),(5,'OTA 5','APAC',900); | SELECT name FROM otas WHERE region = 'EMEA' AND bookings = (SELECT MAX(bookings) FROM otas WHERE region = 'EMEA'); |
What are the EIA reports that are still in progress, and list the corresponding mine names and report IDs? | CREATE TABLE eia_reports (report_id INT,mine_id INT,report_status TEXT); INSERT INTO eia_reports (report_id,mine_id,report_status) VALUES (5,5,'In Progress'),(6,6,'Completed'),(7,7,'Approved'),(8,8,'Rejected'); CREATE TABLE mines (mine_id INT,mine_name TEXT); INSERT INTO mines (mine_id,mine_name) VALUES (5,'MineJ'),(6,'MineK'),(7,'MineL'),(8,'MineM'); | SELECT e.report_id, m.mine_name FROM eia_reports e JOIN mines m ON e.mine_id = m.mine_id WHERE e.report_status = 'In Progress'; |
Show the number of one-time donors in the past year | CREATE TABLE donor_types (id INT,donor_type VARCHAR(255)); INSERT INTO donor_types (id,donor_type) VALUES (1,'One-time'),(2,'Recurring'); CREATE TABLE donations (id INT,donor_type_id INT,donation_date DATE); | SELECT COUNT(d.id) as one_time_donors FROM donations d JOIN donor_types dt ON d.donor_type_id = dt.id WHERE dt.donor_type = 'One-time' AND d.donation_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR); |
What is the average rating of tour companies in India? | CREATE TABLE Tour_Company (id INT PRIMARY KEY,name VARCHAR(50),country VARCHAR(50),num_employees INT,establishment_year INT);CREATE TABLE Tour_Review (id INT PRIMARY KEY,tour_id INT,visitor_id INT,review TEXT,rating INT);CREATE VIEW Avg_Rating_By_Country AS SELECT Tour_Company.country,AVG(Tour_Review.rating) AS avg_rating FROM Tour_Company JOIN Tour_Review ON Tour_Company.id = Tour_Review.tour_id GROUP BY Tour_Company.country; | SELECT * FROM Avg_Rating_By_Country WHERE country = 'India'; |
What is the number of art pieces created by artists from different countries in the oil painting medium? | CREATE SCHEMA art; CREATE TABLE art_pieces (art_id INT,art_name VARCHAR(255),artist_name VARCHAR(255),artist_country VARCHAR(50),medium VARCHAR(50),creation_date DATE); INSERT INTO art.art_pieces (art_id,art_name,artist_name,artist_country,medium,creation_date) VALUES (1,'Painting','Sarah Johnson','USA','Oil','2018-01-01'),(2,'Sculpture','Mia Kim','South Korea','Bronze','2019-05-15'),(3,'Print','Jamie Lee','Canada','Woodcut','2020-12-31'),(4,'Installation','David Park','Mexico','Mixed Media','2020-06-01'),(5,'Painting','David Park','Brazil','Watercolor','2019-12-31'); | SELECT artist_country, COUNT(*) as count FROM art.art_pieces WHERE medium = 'Oil' GROUP BY artist_country; |
What is the maximum square footage of a Green-Star certified building in the 'GreenBuildings' table? | 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,'Green-Star'),(4,'EfficientTower',60000,'Green-Star'); | SELECT MAX(squareFootage) FROM GreenBuildings WHERE certification = 'Green-Star'; |
What is the difference in average speed between sports cars and electric vehicles in the 'test_drives' table? | CREATE TABLE test_drives (id INT,vehicle_name VARCHAR(50),avg_speed FLOAT,vehicle_type VARCHAR(20)); | SELECT AVG(avg_speed) FILTER (WHERE vehicle_type = 'Sports') - AVG(avg_speed) FILTER (WHERE vehicle_type = 'Electric') AS speed_difference FROM test_drives; |
List the farms that have had no rainfall in the past week and their corresponding average soil moisture levels | CREATE TABLE farm (id INT,name VARCHAR(255));CREATE TABLE rainfall (id INT,farm_id INT,measurement DATE,rainfall INT);CREATE TABLE field (id INT,name VARCHAR(255),farm_id INT);CREATE TABLE soil_moisture (id INT,field_id INT,measurement DATE,level INT); | SELECT farm.name as farm_name, AVG(soil_moisture.level) as avg_level FROM farm JOIN field ON farm.id = field.farm_id JOIN soil_moisture ON field.id = soil_moisture.field_id WHERE farm.id NOT IN (SELECT farm_id FROM rainfall WHERE measurement >= DATEADD(day, -7, GETDATE()) AND rainfall > 0) GROUP BY farm.id; |
What is the average score of players who joined after January 1, 2021? | CREATE TABLE players (player_id INT,join_date DATE,score INT); INSERT INTO players (player_id,join_date,score) VALUES (1,'2021-01-05',100),(2,'2021-01-07',200),(3,'2020-12-31',300); | SELECT AVG(score) FROM players WHERE join_date > '2021-01-01'; |
What is the percentage of sustainable material usage across all clothing items in the database? | CREATE TABLE clothing_items (item_id INT,material VARCHAR(255),sustainable BOOLEAN); INSERT INTO clothing_items (item_id,material,sustainable) VALUES (1,'Organic Cotton',true),(2,'Conventional Cotton',false),(3,'Recycled Polyester',true),(4,'Viscose',false),(5,'Bamboo',true); | SELECT 100.0 * SUM(sustainable) / COUNT(*) AS percentage FROM clothing_items; |
What is the total amount of seafood imported from Asia to the United States in 2021? | CREATE TABLE seafood_import (product VARCHAR(255),quantity INT,year INT,country VARCHAR(255),PRIMARY KEY (product,year,country)); INSERT INTO seafood_import (product,quantity,year,country) VALUES ('Shrimp',20000,2021,'United States'),('Tuna',15000,2021,'United States'),('Salmon',10000,2021,'Canada'); | SELECT SUM(quantity) FROM seafood_import WHERE year = 2021 AND country = 'United States' AND region = 'Asia'; |
How can we update the names of donors with the last name 'Green' to 'Greene'? | CREATE TABLE donors (donor_id INT,name TEXT);INSERT INTO donors VALUES (1,'Eva Green'),(2,'Frank Red'),(3,'Grace Blue'),(4,'Harry Yellow'),(5,'John Green'); | UPDATE donors SET name = REPLACE(name, 'Green', 'Greene') WHERE name LIKE '% Green'; |
What is the average heart rate of users during their workout sessions? | CREATE TABLE workout_sessions (id INT,user_id INT,session_date DATE,heart_rate INT); | SELECT AVG(heart_rate) as avg_heart_rate FROM workout_sessions |
What is the total cost of labor for the project with ID 2? | CREATE TABLE Costs (CostID INT PRIMARY KEY,CostType TEXT,CostValue FLOAT,ProjectID INT); INSERT INTO Costs (CostID,CostType,CostValue,ProjectID) VALUES (1,'Labor',15000.0,1),(2,'Labor',20000.0,2); | SELECT SUM(CostValue) FROM Costs WHERE CostType = 'Labor' AND ProjectID = 2; |
What is the name and number of crimes for each police department in the state of Texas? | CREATE TABLE states (id INT,name VARCHAR(255)); CREATE TABLE police_departments (id INT,state_id INT,name VARCHAR(255)); CREATE TABLE crimes (id INT,department_id INT,name VARCHAR(255),number INT); | SELECT pd.name, c.name, c.number FROM police_departments pd JOIN crimes c ON pd.id = c.department_id WHERE pd.state_id = (SELECT id FROM states WHERE name = 'Texas'); |
Update the hygiene rating for restaurant 3 to 82. Use the restaurant_hygiene table. | CREATE TABLE restaurant_hygiene (restaurant_id INT,hygiene_rating INT); INSERT INTO restaurant_hygiene (restaurant_id,hygiene_rating) VALUES (1,85),(2,92),(3,78),(4,97),(5,88); | UPDATE restaurant_hygiene SET hygiene_rating = 82 WHERE restaurant_id = 3; |
What is the average horsepower of electric vehicles, partitioned by vehicle make? | CREATE TABLE vehicles (vehicle_id INT,vehicle_make VARCHAR(20),horsepower FLOAT); INSERT INTO vehicles (vehicle_id,vehicle_make,horsepower) VALUES (1,'Tesla',469),(2,'Tesla',451),(3,'Rivian',402),(4,'Rivian',415),(5,'Fisker',300); | SELECT vehicle_make, AVG(horsepower) avg_horsepower FROM vehicles WHERE vehicle_make IN ('Tesla', 'Rivian', 'Fisker') GROUP BY vehicle_make; |
Find the top 3 countries by total donations. | CREATE TABLE Donors (DonorID int,Country varchar(50)); INSERT INTO Donors (DonorID,Country) VALUES (1,'USA'),(2,'Canada'),(3,'Mexico'),(4,'USA'),(5,'Canada'); CREATE TABLE Donations (DonationID int,DonorID int,Amount decimal(10,2)); INSERT INTO Donations (DonationID,DonorID,Amount) VALUES (1,1,500),(2,1,750),(3,2,300),(4,2,800),(5,3,900); | SELECT C.Country, SUM(D.Amount) as TotalDonated FROM Donors C INNER JOIN Donations D ON C.DonorID = D.DonorID GROUP BY C.Country ORDER BY TotalDonated DESC LIMIT 3; |
What is the total quantity of mineral extracted for each mine in the second half of a specific year? | CREATE TABLE ExtractionData (ExtractionDataID INT,MineID INT,Date DATE,Mineral TEXT,Quantity INT); | SELECT MineID, SUM(Quantity) FROM ExtractionData WHERE Date BETWEEN '2022-07-01' AND '2022-12-31' GROUP BY MineID; |
What is the total revenue for vegan menu items at 'Plant-Based Bites'? | CREATE TABLE restaurants (restaurant_id INT,name VARCHAR(255)); INSERT INTO restaurants (restaurant_id,name) VALUES (11,'Plant-Based Bites'); CREATE TABLE menu_items (menu_item_id INT,name VARCHAR(255),price DECIMAL(5,2),is_vegan BOOLEAN); INSERT INTO menu_items (menu_item_id,name,price,is_vegan) VALUES (12,'Veggie Burger',9.99,true),(13,'Tofu Stir Fry',12.99,true); CREATE TABLE orders (order_id INT,menu_item_id INT,quantity INT,order_date DATE,restaurant_id INT); INSERT INTO orders (order_id,menu_item_id,quantity,order_date,restaurant_id) VALUES (14,12,2,'2022-01-03',11),(15,13,1,'2022-01-04',11); | SELECT SUM(price * quantity) FROM orders o JOIN menu_items mi ON o.menu_item_id = mi.menu_item_id WHERE mi.is_vegan = true AND o.restaurant_id = 11; |
What is the total revenue of virtual tours in the 'Ancient Rome' exhibit? | CREATE TABLE virtual_tours (tour_id INT,name TEXT,exhibit TEXT,revenue FLOAT); INSERT INTO virtual_tours (tour_id,name,exhibit,revenue) VALUES (1,'360 Tour','Ancient Rome',1500),(2,'VR Experience','Egyptian Antiquities',2000); | SELECT SUM(revenue) FROM virtual_tours WHERE exhibit = 'Ancient Rome'; |
What is the total value of transactions per month, by product category? | CREATE TABLE transactions (transaction_id INT,transaction_date DATE,product_category VARCHAR(50),amount DECIMAL(10,2)); INSERT INTO transactions (transaction_id,transaction_date,product_category,amount) VALUES (1,'2021-04-01','Stocks',500); INSERT INTO transactions (transaction_id,transaction_date,product_category,amount) VALUES (2,'2021-04-15','Bonds',300); INSERT INTO transactions (transaction_id,transaction_date,product_category,amount) VALUES (3,'2021-04-20','Mutual Funds',700); | SELECT DATE_FORMAT(transaction_date, '%Y-%m') as month, product_category, SUM(amount) as total_value FROM transactions GROUP BY month, product_category; |
What is the total number of broadband subscribers per technology in the 'subscriber_tech' table? | CREATE TABLE subscriber_tech (subscriber_id INT,subscription_start_date DATE,technology VARCHAR(50),subscription_fee DECIMAL(10,2)); INSERT INTO subscriber_tech (subscriber_id,subscription_start_date,technology,subscription_fee) VALUES (1,'2020-01-01','Fiber',50.00),(2,'2019-06-15','Cable',40.00),(3,'2021-02-20','Fiber',55.00); | SELECT technology, COUNT(*) as total_subscribers FROM subscriber_tech GROUP BY technology; |
What is the total count of organic dishes by cuisine type? | CREATE TABLE Dishes (id INT,cuisine VARCHAR(255),organic BOOLEAN); INSERT INTO Dishes (id,cuisine,organic) VALUES (1,'Italian',TRUE),(2,'Italian',FALSE),(3,'Mexican',TRUE),(4,'Mexican',TRUE),(5,'Indian',FALSE); | SELECT cuisine, COUNT(*) as total_organic FROM Dishes WHERE organic = TRUE GROUP BY cuisine; |
What is the total quantity of natural nail polish sold in Canada in Q1 2022? | CREATE TABLE NailPolishSales (sale_id INT,product_name VARCHAR(100),category VARCHAR(50),price DECIMAL(10,2),quantity INT,sale_date DATE,country VARCHAR(50),natural BOOLEAN); | SELECT SUM(quantity) FROM NailPolishSales WHERE category = 'Nail Polish' AND country = 'Canada' AND natural = TRUE AND sale_date >= '2022-01-01' AND sale_date < '2022-04-01'; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.