instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
List the Yttrium market trends for 2017 and 2018. | CREATE TABLE YttriumMarket(year INT,trend VARCHAR(50)); INSERT INTO YttriumMarket(year,trend) VALUES (2017,'Increase'),(2017,'Steady demand'),(2018,'Price decrease'),(2018,'Decreasing demand'); | SELECT year, trend FROM YttriumMarket WHERE year IN (2017, 2018); |
What is the total number of artworks and total number of artists in the database? | CREATE TABLE Artworks (ArtworkID int,Name varchar(50),ArtistID int); CREATE TABLE Artists (ArtistID int,Name varchar(50),BirthYear int,DeathYear int); INSERT INTO Artworks (ArtworkID,Name,ArtistID) VALUES (1,'Mona Lisa',1),(2,'The Starry Night',2),(3,'The Persistence of Memory',3); INSERT INTO Artists (ArtistID,Name,BirthYear,DeathYear) VALUES (1,'Leonardo da Vinci',1452,1519),(2,'Vincent van Gogh',1853,1890),(3,'Salvador Dalí',1904,1989); | SELECT COUNT(DISTINCT A.ArtworkID) AS TotalArtworks, COUNT(DISTINCT AR.ArtistID) AS TotalArtists FROM Artworks A JOIN Artists AR ON A.ArtistID = AR.ArtistID; |
What are the names of vessels that have not been involved in any accidents? | CREATE TABLE vessels (vessel_id INT,name VARCHAR(100)); INSERT INTO vessels (vessel_id,name) VALUES (1,'Sea Serpent'); INSERT INTO vessels (vessel_id,name) VALUES (2,'Ocean Wave'); INSERT INTO maritime_accidents (accident_id,vessel_id,country) VALUES (1,1,'Canada'); | SELECT name FROM vessels WHERE vessel_id NOT IN (SELECT vessel_id FROM maritime_accidents); |
How many eco-friendly accommodations are there in each country? | CREATE TABLE eco_accommodations (id INT,country VARCHAR(255),type VARCHAR(255)); INSERT INTO eco_accommodations (id,country,type) VALUES (1,'France','Eco Lodge'),(2,'Germany','Green Hotel'),(3,'Italy','Eco Hotel'); | SELECT country, COUNT(*) FROM eco_accommodations GROUP BY country; |
What is the total number of hours of community service performed, by offender's age, in the past year? | CREATE TABLE offenders (id INT,age INT,community_service_hours INT,community_service_date DATE); | SELECT age, SUM(community_service_hours) FROM offenders WHERE community_service_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY age; |
What is the total number of points scored by each team in the FIFA World Cup? | CREATE TABLE fifa_world_cup (id INT,team VARCHAR(50),year INT,points INT); INSERT INTO fifa_world_cup (id,team,year,points) VALUES (1,'Brazil',2022,12),(2,'Germany',2022,14); | SELECT team, SUM(points) FROM fifa_world_cup GROUP BY team ORDER BY SUM(points) DESC; |
What is the maximum quantity of fish caught per species in the Indian Ocean? | CREATE TABLE FishCaught (species VARCHAR(50),ocean VARCHAR(50),quantity INT); INSERT INTO FishCaught (species,ocean,quantity) VALUES ('Tuna','Indian Ocean',500),('Salmon','Indian Ocean',400),('Cod','Indian Ocean',300),('Sardines','Indian Ocean',600); | SELECT species, MAX(quantity) as max_quantity FROM FishCaught WHERE ocean = 'Indian Ocean' GROUP BY species; |
Calculate the average weight of chemical substances in the category 'agrochemicals' manufactured in Spain in the last 9 months. | CREATE TABLE chemicals (id INT,name VARCHAR(255),weight FLOAT,manufacturer_country VARCHAR(255),category VARCHAR(255),production_date DATE); | SELECT category, AVG(weight) as avg_weight FROM chemicals WHERE manufacturer_country = 'Spain' AND category = 'agrochemicals' AND production_date > DATE_SUB(CURDATE(), INTERVAL 9 MONTH) GROUP BY category; |
Get the number of artifacts analyzed by each archaeologist in the 'artifact_analysis' table. | CREATE TABLE archaeologists (id INT,name VARCHAR(50),age INT,gender VARCHAR(10),country VARCHAR(50)); CREATE TABLE artifact_analysis (id INT,archaeologist_id INT,artifact_id INT,analysis_date DATE); | SELECT archaeologist_id, COUNT(artifact_id) FROM artifact_analysis GROUP BY archaeologist_id; |
What is the total number of unique customers who have made a purchase in each dispensary in California, grouped by dispensary? | CREATE TABLE customers (customer_id INT,name TEXT,dispensary_id INT); INSERT INTO customers (customer_id,name,dispensary_id) VALUES (1,'Customer A',1),(2,'Customer B',1),(3,'Customer C',2); | SELECT d.name, COUNT(DISTINCT c.customer_id) AS unique_customers FROM dispensaries d JOIN customers c ON d.dispensary_id = c.dispensary_id WHERE d.state = 'California' GROUP BY d.name; |
What was the average donation amount and total number of donors for each month in 2021? | CREATE TABLE MonthlyDonations (DonorID INT,DonationDate DATE); INSERT INTO MonthlyDonations (DonorID,DonationDate) VALUES (1,'2021-01-12'),(2,'2021-01-25'),(3,'2021-02-03'),(1,'2021-03-14'),(4,'2021-03-28'); | SELECT EXTRACT(MONTH FROM DonationDate) AS Month, AVG(DonationAmount) AS AverageDonation, COUNT(DISTINCT DonorID) AS TotalDonors FROM Donations GROUP BY Month ORDER BY Month; |
Update the hospital location of a rural healthcare worker in the "healthcare_workers" table. | CREATE TABLE healthcare_workers (id INT,name TEXT,age INT,position TEXT,hospital_id INT); CREATE TABLE rural_hospitals (id INT,name TEXT,location TEXT,state TEXT); INSERT INTO rural_hospitals (id,name,location,state) VALUES (3,'Hospital C','Rural Area 3','New York'); | UPDATE healthcare_workers SET hospital_id = 3 WHERE id = 1; |
Which products have the highest and lowest inventory levels, and what are their prices? | CREATE TABLE inventory (product_id INT,product_name VARCHAR(255),quantity INT,price DECIMAL(10,2)); INSERT INTO inventory (product_id,product_name,quantity,price) VALUES (1,'Product X',100,50.00),(2,'Product Y',50,75.00),(3,'Product Z',200,25.00); | SELECT product_name, quantity, price, NTILE(2) OVER (ORDER BY quantity DESC) as tier FROM inventory; |
Insert a new rural infrastructure project in the 'Nairobi' region with ID 5, name 'Solar Powered Irrigation', and status 'completed' into the 'infrastructure_projects' table. | CREATE TABLE infrastructure_projects(id INT,region TEXT,project_name TEXT,status TEXT); | INSERT INTO infrastructure_projects (id, region, project_name, status) VALUES (5, 'Nairobi', 'Solar Powered Irrigation', 'completed'); |
List all the satellite images and their metadata for the 'Precision Farming' project in the precision_farming database. | CREATE TABLE satellite_images (id INT,project VARCHAR(255),date DATE,time TIME,resolution INT); INSERT INTO satellite_images (id,project,date,time,resolution) VALUES (1,'Precision Farming','2022-01-01','12:00:00',10),(2,'Precision Farming','2022-01-02','12:00:00',15),(3,'Autonomous Tractors','2022-01-01','12:00:00',20); | SELECT * FROM satellite_images WHERE project = 'Precision Farming'; |
Remove products that have an ethical rating lower than 7 | CREATE TABLE products (product_id INT,supplier_id INT,ethical_rating INT); CREATE TABLE suppliers (supplier_id INT,supplier_name VARCHAR(50),ethical_rating INT); INSERT INTO products (product_id,supplier_id,ethical_rating) VALUES (1,101,9),(2,102,5),(3,103,8); INSERT INTO suppliers (supplier_id,supplier_name,ethical_rating) VALUES (101,'Supplier X',9),(102,'Supplier Y',5),(103,'Supplier Z',8); | DELETE FROM products WHERE ethical_rating < 7; |
How many legal aid applications were denied in the past month, broken down by the reason for denial and the applicant's race? | CREATE TABLE legal_aid_denials (id INT,denial_reason TEXT,race TEXT,application_date DATE); | SELECT race, denial_reason, COUNT(*) FROM legal_aid_denials WHERE application_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY race, denial_reason; |
What are the average number of days to resolve incidents for each threat type? | CREATE TABLE security_incidents (id INT,incident_date DATE,threat_type VARCHAR(50),resolution_date DATE); INSERT INTO security_incidents (id,incident_date,threat_type,resolution_date) VALUES (1,'2022-01-01','Malware','2022-01-05'),(2,'2022-01-05','Phishing','2022-01-12'),(3,'2022-01-10','Ransomware','2022-01-15'); | SELECT threat_type, AVG(DATEDIFF(day, incident_date, resolution_date)) as avg_days_to_resolve FROM security_incidents GROUP BY threat_type; |
Show the defense contracts awarded to companies in California and Texas with amounts over $1,000,000, and their respective award dates. | CREATE TABLE defense_contracts(id INT,company VARCHAR(50),amount INT,award_date DATE,state VARCHAR(20)); | SELECT company, amount, award_date FROM defense_contracts WHERE state IN ('California', 'Texas') AND amount > 1000000; |
How many members have a 'Basic' membership type and have attended a class in the past week? | CREATE TABLE Members (MemberID INT,Age INT,Gender VARCHAR(10),MembershipType VARCHAR(20)); INSERT INTO Members (MemberID,Age,Gender,MembershipType) VALUES (1,35,'Female','Basic'),(2,45,'Male','Elite'),(3,28,'Female','Premium'),(4,32,'Male','Basic'),(5,48,'Female','Elite'); CREATE TABLE ClassAttendance (MemberID INT,Class VARCHAR(20),Date DATE); INSERT INTO ClassAttendance (MemberID,Class,Date) VALUES (1,'Cycling','2022-02-01'),(2,'Yoga','2022-02-02'),(3,'Cycling','2022-02-03'),(4,'Yoga','2022-02-04'),(5,'Pilates','2022-02-05'),(1,'Cycling','2022-02-06'),(2,'Yoga','2022-02-07'),(3,'Cycling','2022-02-08'),(4,'Yoga','2022-02-09'),(5,'Pilates','2022-02-10'); | SELECT COUNT(*) FROM Members JOIN ClassAttendance ON Members.MemberID = ClassAttendance.MemberID WHERE Members.MembershipType = 'Basic' AND ClassAttendance.Date >= DATEADD(week, -1, GETDATE()); |
What is the maximum depth of the Galathea Trench in the Indian Ocean? | CREATE TABLE marine_trenches (ocean TEXT,trench TEXT,max_depth INTEGER);INSERT INTO marine_trenches (ocean,trench,max_depth) VALUES ('Pacific','Mariana Trench',10994),('Indian','Galathea Trench',8020); | SELECT ocean, trench, max_depth FROM marine_trenches WHERE ocean = 'Indian' AND trench = 'Galathea Trench' AND max_depth = (SELECT MAX(max_depth) FROM marine_trenches WHERE ocean = 'Indian'); |
List all the satellite images taken over a specific farm in the past month. | CREATE TABLE satellite_images (image_id TEXT,farm_id TEXT,date DATE); | SELECT image_id FROM satellite_images WHERE farm_id = 'farm123' AND date >= DATEADD(day, -30, GETDATE()); |
What is the average CO2 emissions reduction (in tonnes) achieved by carbon offset programs implemented in Germany? | CREATE TABLE Carbon_Offset_Programs (program_id INT,program_name VARCHAR(100),country VARCHAR(100),co2_reduction_tonnes FLOAT); | SELECT AVG(co2_reduction_tonnes) FROM Carbon_Offset_Programs WHERE country = 'Germany'; |
What is the maximum berthing time for each vessel type? | CREATE TABLE berthing (id INT,vessel_type VARCHAR(255),berthing_time INT); INSERT INTO berthing VALUES (1,'container',120),(2,'bulk',150),(3,'tanker',200); | SELECT vessel_type, MAX(berthing_time) as max_berthing_time FROM berthing GROUP BY vessel_type; |
What is the total amount of water saved through conservation initiatives in the year 2020? | CREATE TABLE savings (id INT,amount FLOAT,year INT); INSERT INTO savings (id,amount,year) VALUES (1,1000,2020),(2,1500,2019),(3,2000,2018); | SELECT SUM(amount) FROM savings WHERE year = 2020; |
How many companies in the healthcare sector have an ESG rating above 8.0? | CREATE TABLE companies (id INT,name TEXT,sector TEXT,ESG_rating FLOAT); INSERT INTO companies (id,name,sector,ESG_rating) VALUES (1,'Pfizer','Healthcare',8.5),(2,'Johnson & Johnson','Healthcare',7.9),(3,'Medtronic','Healthcare',8.3),(4,'Abbott','Healthcare',7.7); | SELECT COUNT(*) FROM companies WHERE sector = 'Healthcare' AND ESG_rating > 8.0; |
What is the average number of trips per day for autonomous buses in Tokyo? | CREATE TABLE public.daily_trips (id SERIAL PRIMARY KEY,vehicle_type TEXT,city TEXT,trips_per_day DECIMAL(10,2)); INSERT INTO public.daily_trips (vehicle_type,city,trips_per_day) VALUES ('autonomous_bus','Tokyo',250.50),('autonomous_bus','Tokyo',275.25),('autonomous_bus','Sydney',300.00); | SELECT AVG(trips_per_day) FROM public.daily_trips WHERE vehicle_type = 'autonomous_bus' AND city = 'Tokyo'; |
What are the top 3 countries with the highest number of security incidents in the past year, and their respective percentages of the total incidents? | CREATE TABLE country_incidents (incident_id INT,country_name VARCHAR(255),incident_count INT); INSERT INTO country_incidents (incident_id,country_name,incident_count) VALUES (1,'United States',250),(2,'United Kingdom',120),(3,'Canada',80),(4,'Australia',60),(5,'Germany',50); | SELECT country_name, incident_count, ROUND(incident_count / SUM(incident_count) OVER(), 2) * 100 as incident_percentage FROM country_incidents ORDER BY incident_count DESC LIMIT 3; |
What is the reclamation cost for the miner with the most workers in Europe? | CREATE TABLE reclamation_expenses (miner_name VARCHAR(50),country VARCHAR(50),reclamation_costs DECIMAL(10,2),year INT,PRIMARY KEY (miner_name,year));INSERT INTO reclamation_expenses (miner_name,country,reclamation_costs,year) VALUES ('Emma White','Germany',120000.00,2020),('Oliver Black','France',180000.00,2020),('Jessica Green','Italy',90000.00,2020);CREATE VIEW miner_year_worker_count AS SELECT miner_name,country,ROW_NUMBER() OVER(PARTITION BY miner_name ORDER BY worker_count DESC) as worker_rank FROM labor_force; | SELECT context.miner_name, sql.reclamation_costs FROM reclamation_expenses sql JOIN (SELECT miner_name, worker_count, worker_rank FROM labor_force, miner_year_worker_count WHERE labor_force.miner_name = miner_year_worker_count.miner_name AND worker_rank = 1 AND country = 'Europe') context ON sql.miner_name = context.miner_name |
What is the total number of pallets stored in each warehouse, broken down by the month and year of storage? | CREATE TABLE warehouses (id INT,pallets INT,storage_date DATE); INSERT INTO warehouses (id,pallets,storage_date) VALUES (1,200,'2022-01-01'),(2,300,'2022-02-01'),(3,150,'2022-01-15'); | SELECT YEAR(storage_date) as storage_year, MONTH(storage_date) as storage_month, SUM(pallets) as total_pallets FROM warehouses GROUP BY YEAR(storage_date), MONTH(storage_date); |
What intelligence operations were conducted in the Middle East since 2018? | CREATE TABLE intelligence_operations (id INT,operation_name VARCHAR(255),location VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO intelligence_operations (id,operation_name,location,start_date,end_date) VALUES (1,'Operation Red Sands','Middle East','2018-01-01','2018-12-31'),(2,'Operation Silent Shield','Europe','2019-01-01','2019-12-31'); | SELECT DISTINCT operation_name, location FROM intelligence_operations WHERE location = 'Middle East' AND (start_date IS NULL OR start_date <= CURDATE()) AND (end_date IS NULL OR end_date >= CURDATE()); |
Identify the average word count for articles in the 'news_stories' table, and display the result rounded to the nearest integer. | CREATE TABLE news_stories (id INT,headline VARCHAR(255),article_text TEXT,word_count INT); | SELECT ROUND(AVG(word_count)) FROM news_stories; |
How many players registered from Asia play on PlayStation consoles? | CREATE TABLE players (player_id INT,name VARCHAR(30),age INT,gender VARCHAR(10),country VARCHAR(30),registration_date DATE,platform VARCHAR(20)); | SELECT COUNT(*) FROM players WHERE country LIKE 'Asia%' AND platform = 'PlayStation'; |
How many rows in the videos table have a language other than 'English'? | CREATE TABLE videos (title VARCHAR(255),host VARCHAR(255),date DATE,language VARCHAR(255),views INT); | SELECT COUNT(*) FROM videos WHERE language <> 'English'; |
What is the earliest vehicle maintenance date for 'Blue Line'? | CREATE TABLE route (route_id INT,route_name VARCHAR(50)); INSERT INTO route (route_id,route_name) VALUES (1,'Red Line'),(2,'Green Line'),(3,'Blue Line'),(4,'Yellow Line'); CREATE TABLE maintenance (maintenance_id INT,route_id INT,maintenance_date DATE); INSERT INTO maintenance (maintenance_id,route_id,maintenance_date) VALUES (1,3,'2022-06-01'),(2,3,'2022-06-15'),(3,4,'2022-07-01'),(4,4,'2022-07-15'); | SELECT MIN(maintenance_date) FROM maintenance WHERE route_id = 3; |
What is the combined budget of the top 3 agencies in Washington DC? | CREATE TABLE washington_agencies (name TEXT,budget INTEGER); INSERT INTO washington_agencies (name,budget) VALUES ('Department of Defense',693000000000),('Department of Health and Human Services',134000000000),('Department of Veterans Affairs',243000000000); | SELECT SUM(budget) FROM (SELECT budget FROM washington_agencies ORDER BY budget DESC LIMIT 3) AS top_three; |
How many workers are employed in the 'renewable energy' sector in China? | CREATE TABLE worker_departments (id INT,worker_name VARCHAR(255),department VARCHAR(255),country VARCHAR(255)); INSERT INTO worker_departments (id,worker_name,department,country) VALUES (1,'John Doe','renewable energy','China'),(2,'Jane Smith','textiles','USA'),(3,'Michael Brown','renewable energy','China'); | SELECT COUNT(*) FROM worker_departments WHERE department = 'renewable energy' AND country = 'China'; |
Create a new table named 'Culture' with columns 'CultureID', 'CultureName', and 'Region'. | CREATE TABLE ExcavationSite (SiteID INT,SiteName VARCHAR(50),Continent VARCHAR(50)); INSERT INTO ExcavationSite (SiteID,SiteName,Continent) VALUES (1,'Site A','Africa'),(2,'Site B','Asia'),(3,'Site C','Europe'); CREATE TABLE Artifact (ArtifactID INT,SiteID INT,Weight FLOAT,ObjectType VARCHAR(50)); INSERT INTO Artifact (ArtifactID,SiteID,Weight,ObjectType) VALUES (1,1,54.3,'Pottery'),(2,1,32.1,'Tool'),(3,2,120.5,'Statue'),(4,2,12.7,'Bead'),(5,3,8.4,'Bead'),(6,1,20.5,'Bead'); | CREATE TABLE Culture (CultureID INT, CultureName VARCHAR(50), Region VARCHAR(50)); |
How many teachers have completed professional development courses in STEM subjects? | CREATE TABLE teachers (teacher_id INT,subject_area VARCHAR(255)); INSERT INTO teachers (teacher_id,subject_area) VALUES (1,'Math'),(2,'English'),(3,'Science'),(4,'History'),(5,'Technology'),(6,'Engineering'); CREATE TABLE courses (course_id INT,course_name VARCHAR(255),subject_area VARCHAR(255)); INSERT INTO courses (course_id,course_name,subject_area) VALUES (1,'Algebra I','Math'),(2,'Geometry','Math'),(3,'English Lit','English'),(4,'Chemistry','Science'),(5,'Physics','Science'),(6,'Programming I','Technology'),(7,'Engineering Design','Engineering'); CREATE TABLE completions (teacher_id INT,course_id INT); INSERT INTO completions (teacher_id,course_id) VALUES (1,1),(1,2),(2,3),(3,4),(3,5),(5,6),(6,7); | SELECT COUNT(DISTINCT t.teacher_id) as num_teachers FROM teachers t JOIN completions c ON t.teacher_id = c.teacher_id JOIN courses co ON c.course_id = co.course_id WHERE co.subject_area IN ('Math', 'Science', 'Technology', 'Engineering'); |
What is the minimum price per gram of flower sold by Grower H in Q3 2022? | CREATE TABLE grower_inventory (id INT,grower VARCHAR(255),product VARCHAR(255),price FLOAT,gram_weight FLOAT); INSERT INTO grower_inventory (id,grower,product,price,gram_weight) VALUES (1,'Grower H','Flower',12.0,3.5); | SELECT MIN(price / gram_weight) FROM grower_inventory WHERE grower = 'Grower H' AND product = 'Flower' AND QUARTER(sale_date) = 3 AND YEAR(sale_date) = 2022; |
Update the country_origin column of the designer table to 'Mexico' for designers who have created garments made of linen. | CREATE TABLE designer (id INT PRIMARY KEY,name VARCHAR(255),country_origin VARCHAR(255)); CREATE TABLE designer_garments (id INT PRIMARY KEY,designer_id INT,garment_id INT,FOREIGN KEY (designer_id) REFERENCES designer(id)); | UPDATE designer SET country_origin = 'Mexico' WHERE designer.id IN (SELECT designer_id FROM designer_garments WHERE garment_id IN (SELECT id FROM garment_production WHERE fabric_type = 'Linen')); |
Update the community representation for subscriber 5 to 'Native Hawaiian or Other Pacific Islander'. | CREATE TABLE mobile_subscribers (subscriber_id INT,data_usage FLOAT,community_representation VARCHAR(30)); INSERT INTO mobile_subscribers (subscriber_id,data_usage,community_representation) VALUES (1,30.5,'Latinx'),(2,40.3,'Black/African American'),(3,50.2,'Native American'),(4,60.1,'Asian'),(5,35.6,'Pacific Islander'); | UPDATE mobile_subscribers SET community_representation = 'Native Hawaiian or Other Pacific Islander' WHERE subscriber_id = 5; |
What is the Union membership rate in the Finance sector? | CREATE TABLE UnionMembership (id INT,sector VARCHAR(255),membership DECIMAL(5,2)); INSERT INTO UnionMembership (id,sector,membership) VALUES (1,'Finance',0.10); | SELECT membership FROM UnionMembership WHERE sector = 'Finance'; |
List all regulatory frameworks in the blockchain domain that were implemented in 2022. | CREATE TABLE RegulatoryFrameworks (framework_id INT,framework_name TEXT,implementation_year INT); INSERT INTO RegulatoryFrameworks (framework_id,framework_name,implementation_year) VALUES (1,'Framework1',2020),(2,'Framework2',2021),(3,'Framework3',2022); | SELECT framework_name FROM RegulatoryFrameworks WHERE implementation_year = 2022; |
What is the name of the client with the highest billing amount in the 'Personal Injury' category? | CREATE TABLE Clients (ClientID INT,Name VARCHAR(50),Category VARCHAR(50),BillingAmount DECIMAL(10,2)); INSERT INTO Clients (ClientID,Name,Category,BillingAmount) VALUES (1,'John Doe','Personal Injury',5000.00),(2,'Jane Smith','Personal Injury',3000.00); | SELECT Name FROM Clients WHERE Category = 'Personal Injury' AND BillingAmount = (SELECT MAX(BillingAmount) FROM Clients WHERE Category = 'Personal Injury'); |
What is the average age of artists who had the most streams in their respective countries? | CREATE TABLE artists (id INT,name VARCHAR(255),age INT,country VARCHAR(255)); INSERT INTO artists (id,name,age,country) VALUES (1,'Bruce Springsteen',72,'United States'),(2,'Beyoncé',40,'United States'); CREATE TABLE streams (song VARCHAR(255),artist VARCHAR(255),location VARCHAR(255),streams INT); INSERT INTO streams (song,artist,location,streams) VALUES ('Born in the U.S.A.','Bruce Springsteen','United States',2000),('Crazy in Love','Beyoncé','United States',2500); | SELECT AVG(age) FROM artists a JOIN (SELECT artist, MAX(streams) as max_streams FROM streams GROUP BY artist) b ON a.name = b.artist; |
Identify the hotels with a year-over-year increase in energy consumption. | CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,city TEXT,country TEXT,energy_consumption FLOAT,year INT); INSERT INTO hotels (hotel_id,hotel_name,city,country,energy_consumption,year) VALUES (1,'Hotel A','Rome','Italy',12000.0,2021),(1,'Hotel A','Rome','Italy',13000.0,2022); | SELECT hotel_name, energy_consumption FROM (SELECT hotel_name, energy_consumption, energy_consumption - LAG(energy_consumption) OVER (PARTITION BY hotel_name ORDER BY year) as diff FROM hotels) where diff > 0; |
What is the total number of electric vehicles sold in Seoul last year? | CREATE TABLE vehicle_sales (sale_id INT,vehicle_id INT,sale_date DATE,vehicle_type TEXT); | SELECT COUNT(*) FROM vehicle_sales WHERE vehicle_type = 'electric' AND sale_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 1 YEAR) AND DATE_SUB(CURDATE(), INTERVAL 1 DAY); |
What is the total quantity of garments sold by each salesperson, for each month, sorted by salesperson and then by month? | CREATE TABLE sales_data (salesperson VARCHAR(50),sale_date DATE,quantity INT); INSERT INTO sales_data (salesperson,sale_date,quantity) VALUES ('John','2021-01-01',15),('Jane','2021-01-05',20),('John','2021-01-07',10); | SELECT salesperson, DATE_TRUNC('month', sale_date) AS month, SUM(quantity) AS total_quantity FROM sales_data GROUP BY salesperson, month ORDER BY salesperson, month; |
What was the revenue from online sales in May 2022? | CREATE TABLE online_sales (sale_date DATE,revenue FLOAT); INSERT INTO online_sales (sale_date,revenue) VALUES ('2022-05-01',5000.0),('2022-05-02',6000.0),('2022-05-03',7000.0); | SELECT SUM(revenue) FROM online_sales WHERE sale_date BETWEEN '2022-05-01' AND '2022-05-31'; |
What is the maximum number of passengers on a public transportation vehicle in Paris? | CREATE TABLE public_transportation (vehicle_id INT,passengers INT,city VARCHAR(50)); | SELECT MAX(passengers) FROM public_transportation WHERE city = 'Paris'; |
How many sustainable sourcing certifications does each restaurant have, grouped by certification type? | CREATE TABLE Certifications (restaurant TEXT,certification TEXT); INSERT INTO Certifications (restaurant,certification) VALUES ('Asian Fusion','Seafood Watch'),('Asian Fusion','Fair Trade'),('Bistro Bella Vita','Organic'),('Taqueria Tsunami','Local Food Plus'),('Asian Fusion','Local Food Plus'); | SELECT certification, COUNT(DISTINCT restaurant) FROM Certifications GROUP BY certification; |
What are the total sales and quantity of garments sold for each category in Q1 2022, grouped by week? | CREATE TABLE sales_q1_2022 (sale_date DATE,category VARCHAR(50),quantity INT,sales DECIMAL(10,2)); | SELECT DATE_TRUNC('week', sale_date) AS week, category, SUM(quantity) AS total_quantity, SUM(sales) AS total_sales FROM sales_q1_2022 WHERE sale_date >= '2022-01-01' AND sale_date < '2022-04-01' GROUP BY week, category; |
Which menu items had the most sales in the first week of July 2022? | CREATE TABLE menu_sales_3 (item VARCHAR(255),sales INTEGER,sale_date DATE); INSERT INTO menu_sales_3 (item,sales,sale_date) VALUES ('Burger',150,'2022-07-01'),('Pizza',200,'2022-07-02'),('Sushi',250,'2022-07-03'); | SELECT item, SUM(sales) as total_sales FROM menu_sales_3 WHERE sale_date BETWEEN '2022-07-01' AND '2022-07-07' GROUP BY item ORDER BY total_sales DESC LIMIT 1; |
What is the percentage of sustainable projects in California out of all projects in the state? | CREATE TABLE Projects (ProjectID INT,State CHAR(2),IsSustainable BOOLEAN); INSERT INTO Projects (ProjectID,State,IsSustainable) VALUES (1,'CA',true),(2,'NY',false),(3,'TX',true),(4,'CA',false),(5,'CA',true); | SELECT (COUNT(*) FILTER (WHERE Projects.IsSustainable = true) * 100.0 / COUNT(*)) AS SustainablePercentage FROM Projects WHERE Projects.State = 'CA'; |
How many wildlife habitats are there in the 'Mountainous' region? | CREATE TABLE wildlife_habitats (id INT,name TEXT,region TEXT); INSERT INTO wildlife_habitats (id,name,region) VALUES (1,'Habitat1','Coastal'),(2,'Habitat2','Mountainous'); | SELECT COUNT(*) FROM wildlife_habitats WHERE region = 'Mountainous'; |
Which ethical fashion brands have the lowest revenue per employee? | CREATE TABLE brand_data (brand VARCHAR(255),year INT,revenue FLOAT,employees INT); INSERT INTO brand_data (brand,year,revenue,employees) VALUES ('Brand A',2019,20000,100),('Brand A',2020,25000,120),('Brand B',2019,18000,80),('Brand B',2020,23000,100),('Brand C',2019,16000,60),('Brand C',2020,21000,75); | SELECT brand, revenue/employees as revenue_per_employee FROM brand_data ORDER BY revenue_per_employee ASC; |
List unique investors who have invested in companies based in the US and Canada. | CREATE TABLE company (id INT,name TEXT,country TEXT); INSERT INTO company (id,name,country) VALUES (1,'Acme Inc','USA'),(2,'Beta Corp','Canada'),(3,'Gamma PLC','UK'); CREATE TABLE investment (investor_id INT,company_id INT); INSERT INTO investment (investor_id,company_id) VALUES (1,1),(2,1),(3,2); | SELECT DISTINCT investor_id FROM investment WHERE company_id IN (SELECT id FROM company WHERE country IN ('USA', 'Canada')) |
What is the percentage of students who participated in the 'Critical Thinking' program in the 'Spring 2022' semester? | CREATE TABLE student_program_participation (student_id INT,program_name VARCHAR(50),semester VARCHAR(20)); | SELECT (COUNT(student_id) * 100.0 / (SELECT COUNT(*) FROM student_program_participation WHERE semester = 'Spring 2022')) AS percentage FROM student_program_participation WHERE program_name = 'Critical Thinking' AND semester = 'Spring 2022'; |
Show military spending by each country in the last 5 years | CREATE TABLE military_spending (country VARCHAR(50),year INT,amount FLOAT); INSERT INTO military_spending (country,year,amount) VALUES ('USA',2017,611000000),('USA',2018,623000000),('USA',2019,649000000),('USA',2020,680000000),('USA',2021,705000000),('China',2017,215000000),('China',2018,219000000),('China',2019,228000000),('China',2020,235000000),('China',2021,242000000),('Russia',2017,69000000),('Russia',2018,70000000),('Russia',2019,71000000),('Russia',2020,72000000),('Russia',2021,73000000); | SELECT country, year, amount FROM military_spending WHERE year >= (YEAR(CURDATE()) - 5); |
What is the total number of articles published per year by 'BBC News'? | CREATE TABLE publishers (id INT,name VARCHAR(50)); INSERT INTO publishers (id,name) VALUES (1,'BBC News'); CREATE TABLE articles (id INT,title VARCHAR(50),publisher_id INT,publish_year INT); INSERT INTO articles (id,title,publisher_id,publish_year) VALUES (1,'Article 1',1,2010),(2,'Article 2',1,2015),(3,'Article 3',1,2020); | SELECT publish_year, COUNT(*) as count FROM articles WHERE publisher_id = (SELECT id FROM publishers WHERE name = 'BBC News') GROUP BY publish_year ORDER BY publish_year; |
What is the recycling rate in region X and Y? | CREATE TABLE recycling_rates(region TEXT,recycling_rate FLOAT); INSERT INTO recycling_rates(region,recycling_rate) VALUES('X',0.65),('Y',0.73); | SELECT AVG(recycling_rate) FROM recycling_rates WHERE region IN ('X', 'Y'); |
What is the total number of public hospitals in each state of the USA? | CREATE TABLE hospitals (id INT,name VARCHAR(100),state VARCHAR(20),public BOOLEAN); INSERT INTO hospitals (id,name,state,public) VALUES (1,'Hospital 1','California',true); INSERT INTO hospitals (id,name,state,public) VALUES (2,'Hospital 2','California',false); | SELECT state, COUNT(*) FROM hospitals WHERE public = true GROUP BY state; |
What is the total waste generation in Beijing in 2020? | CREATE TABLE waste_generation (city VARCHAR(50),generation_quantity INT,generation_date DATE); INSERT INTO waste_generation (city,generation_quantity,generation_date) VALUES ('Beijing',3000,'2020-01-01'),('Beijing',3500,'2020-02-01'),('Beijing',4000,'2020-03-01'); | SELECT SUM(generation_quantity) FROM waste_generation WHERE city = 'Beijing' AND generation_date >= '2020-01-01' AND generation_date <= '2020-12-31'; |
List all meals and their associated suppliers from the 'Meals' and 'Suppliers' tables. | CREATE TABLE Meals (meal_id INT,meal_name TEXT); CREATE TABLE Suppliers (supplier_id INT,meal_id INT,supplier_name TEXT); | SELECT Meals.meal_name, Suppliers.supplier_name FROM Meals INNER JOIN Suppliers ON Meals.meal_id = Suppliers.meal_id; |
How many students have increased their mental health score by more than 10% in the last 6 months? | CREATE TABLE student_mental_health_history (student_id INT,score INT,date DATE); INSERT INTO student_mental_health_history VALUES (1,60,'2022-01-01'),(1,66,'2022-07-01'),(2,80,'2022-01-01'),(2,88,'2022-07-01'); | SELECT COUNT(*) FROM (SELECT student_id, (score - LAG(score) OVER(PARTITION BY student_id ORDER BY date)) / LAG(score) OVER(PARTITION BY student_id ORDER BY date) * 100.0 as increase_percentage FROM student_mental_health_history WHERE date >= DATEADD(month, -6, GETDATE())) t WHERE increase_percentage > 10; |
How many successful satellite deployments were there in China since 2010? | CREATE TABLE SatelliteDeployments (id INT,country VARCHAR(255),year INT,success BOOLEAN); INSERT INTO SatelliteDeployments VALUES (1,'China',2010,true),(2,'USA',2012,false),(3,'China',2015,true),(4,'India',2017,true); | SELECT COUNT(*) FROM SatelliteDeployments WHERE country = 'China' AND success = true AND year >= 2010; |
What is the average mental health parity violation score for healthcare facilities serving predominantly Asian American and Pacific Islander communities in California and New York? | CREATE TABLE healthcare_facilities (facility_id INT,state VARCHAR(2),serves_aapi BOOLEAN,violations INT); INSERT INTO healthcare_facilities (facility_id,state,serves_aapi,violations) VALUES (1,'CA',TRUE,10),(2,'NY',TRUE,15),(3,'CA',FALSE,5),(4,'NY',FALSE,20); | SELECT AVG(h.violations) FROM healthcare_facilities h WHERE h.state IN ('CA', 'NY') AND h.serves_aapi = TRUE; |
How many local vendors are part of the virtual tourism initiative in Japan? | CREATE TABLE virtual_tourism_japan (vendor_id INT,vendor_name VARCHAR(255),country VARCHAR(255),participation INT); INSERT INTO virtual_tourism_japan (vendor_id,vendor_name,country,participation) VALUES (1,'Vendor A','Japan',1); INSERT INTO virtual_tourism_japan (vendor_id,vendor_name,country,participation) VALUES (2,'Vendor B','Japan',1); INSERT INTO virtual_tourism_japan (vendor_id,vendor_name,country,participation) VALUES (3,'Vendor C','Japan',1); | SELECT COUNT(*) FROM virtual_tourism_japan WHERE country = 'Japan'; |
What is the average ticket price for events at the Museum of Modern Art? | CREATE TABLE Events (id INT,museum VARCHAR(30),price DECIMAL(5,2)); INSERT INTO Events (id,museum,price) VALUES (1,'Museum of Modern Art',25.00),(2,'Metropolitan Museum of Art',30.00),(3,'Museum of Modern Art',20.00); | SELECT AVG(price) FROM Events WHERE museum = 'Museum of Modern Art'; |
Find chemicals with 'Solvent' type. | CREATE TABLE Chemicals (Id INT,Name VARCHAR(50),Type VARCHAR(50),ManufacturingDate DATE); INSERT INTO Chemicals (Id,Name,Type,ManufacturingDate) VALUES (1,'Acetone','Solvent','2021-01-01'),(2,'Ammonia','Gas','2022-02-01'); | SELECT * FROM Chemicals WHERE Type = 'Solvent'; |
Which players have played more than 10 hours of 'RPG' games since 2017? | CREATE TABLE players (player_id INT,name VARCHAR(50)); INSERT INTO players VALUES (1,'John'); INSERT INTO players VALUES (2,'Jane'); CREATE TABLE game_sessions (session_id INT,player_id INT,game VARCHAR(50),duration INT); INSERT INTO game_sessions VALUES (1,1,'RPG',12); INSERT INTO game_sessions VALUES (2,1,'RPG',15); INSERT INTO game_sessions VALUES (3,2,'RPG',8); INSERT INTO game_sessions VALUES (4,2,'RPG',9); | SELECT p.name, COUNT(*) as rpg_sessions FROM players p JOIN game_sessions s ON p.player_id = s.player_id WHERE s.game = 'RPG' AND s.duration > 0 AND s.duration < 61 GROUP BY p.player_id HAVING COUNT(*) > 10; |
Identify the top 3 contractors with the highest average square footage of green-certified buildings in the Midwest, for the year 2021. | CREATE TABLE ContractorBuildings (ContractorID int,Region varchar(20),Year int,GreenCertified bit,SquareFootage decimal(10,2)); INSERT INTO ContractorBuildings (ContractorID,Region,Year,GreenCertified,SquareFootage) VALUES (1,'Midwest',2021,1,75000.00),(2,'Midwest',2021,1,60000.00),(3,'Midwest',2021,0,80000.00); | SELECT ContractorID, AVG(SquareFootage) as Avg_SqFt FROM ContractorBuildings WHERE Region = 'Midwest' AND Year = 2021 AND GreenCertified = 1 GROUP BY ContractorID ORDER BY Avg_SqFt DESC LIMIT 3; |
How many virtual tours were conducted in the USA in Q1 2022? | CREATE TABLE virtual_tours (tour_id INT,location VARCHAR(255),country VARCHAR(255),tour_date DATE); INSERT INTO virtual_tours (tour_id,location,country,tour_date) VALUES (1,'Statue of Liberty','USA','2022-01-01'),(2,'Golden Gate Bridge','USA','2022-02-15'); | SELECT COUNT(*) FROM virtual_tours WHERE country = 'USA' AND tour_date BETWEEN '2022-01-01' AND '2022-03-31'; |
List the carbon pricing schemes and their corresponding carbon prices for the year 2021, sorted by carbon price in descending order. | CREATE TABLE carbon_pricing (scheme VARCHAR(255),year INT,carbon_price FLOAT); INSERT INTO carbon_pricing (scheme,year,carbon_price) VALUES ('ETS',2021,30.56); | SELECT * FROM carbon_pricing WHERE year = 2021 ORDER BY carbon_price DESC; |
What is the number of employees working in each mining operation type? | CREATE TABLE workforce (id INT,name VARCHAR(50),position VARCHAR(50),department VARCHAR(50),operation_type VARCHAR(50)); INSERT INTO workforce (id,name,position,department,operation_type) VALUES (1,'John Doe','Engineer','Mining','Coal'),(2,'Jane Smith','Technician','Environment','Gold'),(3,'Alice Johnson','Manager','Operations','Gold'); | SELECT operation_type, COUNT(*) as num_employees FROM workforce GROUP BY operation_type; |
Show the number of satellites in the satellite_database table, grouped by their country, and order by the count in descending order, only showing the top 5 countries | CREATE TABLE satellite_database (id INT,name VARCHAR(50),type VARCHAR(50),orbit_type VARCHAR(50),country VARCHAR(50),launch_date DATE); | SELECT country, COUNT(*) as satellite_count FROM satellite_database GROUP BY country ORDER BY satellite_count DESC LIMIT 5; |
What is the number of women-led businesses in the agricultural sector in each country? | CREATE TABLE women_businesses (country VARCHAR(50),business_count INT); INSERT INTO women_businesses (country,business_count) VALUES ('Bangladesh',500),('Kenya',300),('Guatemala',250); | SELECT country, business_count FROM women_businesses; |
What is the total number of vulnerabilities and the average severity score for each organization, ordered by the highest average severity score, for the last 90 days? | CREATE TABLE vulnerabilities (vulnerability_id INT,organization VARCHAR(255),country VARCHAR(255),severity_score INT,vulnerability_date DATE); INSERT INTO vulnerabilities (vulnerability_id,organization,country,severity_score,vulnerability_date) VALUES (1,'Org1','USA',7,'2022-06-01'),(2,'Org2','Canada',5,'2022-06-02'),(3,'Org3','Mexico',8,'2022-06-03'),(4,'Org1','USA',9,'2022-07-01'),(5,'Org2','Canada',6,'2022-07-02'),(6,'Org3','Mexico',7,'2022-07-03'); | SELECT organization, COUNT(vulnerability_id) as total_vulnerabilities, AVG(severity_score) as avg_severity_score FROM vulnerabilities WHERE vulnerability_date >= DATEADD(day, -90, GETDATE()) GROUP BY organization ORDER BY avg_severity_score DESC; |
What percentage of visitors identified as preferring digital experiences? | CREATE TABLE Visitors (id INT,exhibition_id INT,age INT,prefers_digital BOOLEAN); INSERT INTO Visitors (id,exhibition_id,age,prefers_digital) VALUES (1,1,30,TRUE),(2,1,35,FALSE),(3,2,40,TRUE); | SELECT 100.0 * COUNT(v.id) / (SELECT COUNT(id) FROM Visitors) AS percentage FROM Visitors v WHERE v.prefers_digital = TRUE |
Show the number of cargo inspections per month, including months with no inspections. | CREATE TABLE cargo_inspections (inspection_id INT,inspection_date DATE); | SELECT EXTRACT(MONTH FROM inspection_date) as month, COUNT(*) as num_inspections FROM cargo_inspections GROUP BY month ORDER BY month; |
What was the average oil production per platform in Q2 2021? | CREATE TABLE platform (platform_id INT,platform_name TEXT,oil_production_q2_2021 FLOAT); INSERT INTO platform (platform_id,platform_name,oil_production_q2_2021) VALUES (1,'X',1400),(2,'Y',1600),(3,'Z',1900); | SELECT AVG(oil_production_q2_2021) as avg_oil_production FROM platform; |
What is the distribution of explainable AI algorithms by application domain and complexity score? | CREATE TABLE explainable_ai_algorithms (algorithm_id INT,algorithm_name TEXT,application_domain TEXT,complexity_score INT); INSERT INTO explainable_ai_algorithms (algorithm_id,algorithm_name,application_domain,complexity_score) VALUES (1,'AI Transparency','Healthcare',7),(2,'Explainable Deep Learning','Finance',9),(3,'Interpretable AI','Education',5); | SELECT application_domain, complexity_score, COUNT(*) as num_algorithms FROM explainable_ai_algorithms GROUP BY application_domain, complexity_score; |
What is the total transaction value for socially responsible loans in Q1 2022? | CREATE TABLE socially_responsible_loans (loan_id INT,loan_type VARCHAR(20),transaction_value DECIMAL(10,2),transaction_date DATE); INSERT INTO socially_responsible_loans (loan_id,loan_type,transaction_value,transaction_date) VALUES (1,'Microfinance',500,'2022-01-05'),(2,'Green Energy',1500,'2022-01-10'),(3,'Education',800,'2022-03-01'); | SELECT SUM(transaction_value) FROM socially_responsible_loans WHERE transaction_date BETWEEN '2022-01-01' AND '2022-03-31'; |
What was the average volunteer hours per volunteer in 2023? | CREATE TABLE volunteer_hours (volunteer_id INT,program_id INT,hours DECIMAL(10,2),hour_date DATE); INSERT INTO volunteer_hours VALUES (23,101,3.00,'2023-01-01'),(24,101,2.50,'2023-02-01'),(25,102,4.00,'2023-01-10'); | SELECT AVG(hours) FROM volunteer_hours GROUP BY volunteer_id HAVING COUNT(*) > 0; |
What was the total amount of funding received for programs in the 'Performances' category? | CREATE TABLE programs (id INT,category VARCHAR(10),funding_received DECIMAL(10,2)); INSERT INTO programs (id,category,funding_received) VALUES (1,'Exhibitions',10000.00),(2,'Education',25000.00),(3,'Performances',12000.00); | SELECT SUM(funding_received) FROM programs WHERE category = 'Performances'; |
How many marine species are there in each ocean, ranked by population size? | CREATE TABLE marine_species (id INT,species_name VARCHAR(255),population INT,habitat VARCHAR(255),ocean VARCHAR(255)); INSERT INTO marine_species (id,species_name,population,habitat,ocean) VALUES (1,'Atlantic Salmon',1000000,'Freshwater','Atlantic'); | SELECT ocean, COUNT(*) AS num_species, SUM(population) AS total_population FROM marine_species GROUP BY ocean ORDER BY total_population DESC; |
How many non-profit organizations are there in the 'environment' sector with an annual revenue less than $250,000? | CREATE TABLE organizations (org_id INT,org_name TEXT,sector TEXT,annual_revenue FLOAT); INSERT INTO organizations (org_id,org_name,sector,annual_revenue) VALUES (1,'Greenpeace','environment',200000.00),(2,'World Wildlife Fund','environment',300000.00); | SELECT COUNT(*) FROM organizations WHERE sector = 'environment' AND annual_revenue < 250000.00; |
Find the number of active drilling rigs in the North Sea and the Gulf of Mexico. | CREATE TABLE drilling_rigs(region VARCHAR(255),status VARCHAR(255),count INT);INSERT INTO drilling_rigs(region,status,count) VALUES('North Sea','Active',30),('North Sea','Inactive',10),('Gulf of Mexico','Active',50),('Gulf of Mexico','Inactive',20),('Barents Sea','Active',15),('Barents Sea','Inactive',5),('South China Sea','Active',20),('South China Sea','Inactive',10); | SELECT region, COUNT(*) AS active_rigs_count FROM drilling_rigs WHERE status = 'Active' AND region IN ('North Sea', 'Gulf of Mexico') GROUP BY region; |
Insert a new record of a chemical container that has a container name of 'Container F', has not been inspected yet, and is currently in use. | CREATE TABLE chemical_containers (container_id INT,container_name TEXT,last_inspection_date DATE,in_use BOOLEAN); INSERT INTO chemical_containers (container_id,container_name,last_inspection_date,in_use) VALUES (1,'Container A','2021-01-01',TRUE),(2,'Container B','2021-04-15',FALSE),(3,'Container C','2021-07-22',TRUE),(4,'Container D','2020-12-31',FALSE),(5,'Container E',NULL,FALSE); | INSERT INTO chemical_containers (container_name, last_inspection_date, in_use) VALUES ('Container F', NULL, TRUE); |
What is the total number of sustainable tourism initiatives in Africa? | CREATE TABLE tourism_initiatives (initiative_id INT,region VARCHAR(50),sustainability_level VARCHAR(50)); INSERT INTO tourism_initiatives (initiative_id,region,sustainability_level) VALUES (1,'Africa','Sustainable'),(2,'Asia','Standard'),(3,'Africa','Sustainable'),(4,'Europe','Luxury'),(5,'Africa','Sustainable'); | SELECT COUNT(*) FROM tourism_initiatives WHERE region = 'Africa' AND sustainability_level = 'Sustainable'; |
What is the average data usage for mobile customers in each state? | CREATE TABLE mobile_customers (customer_id INT,data_usage FLOAT,state VARCHAR(20),last_update DATE); INSERT INTO mobile_customers (customer_id,data_usage,state,last_update) VALUES (1,6.0,'NY','2022-01-10'),(2,3.5,'CA','2022-01-15'),(3,8.2,'TX','2022-01-28'); | SELECT state, AVG(data_usage) FROM mobile_customers GROUP BY state; |
List all the unique courses taught by female teachers | CREATE TABLE Teacher (TeacherID INT,Gender VARCHAR(10)); CREATE TABLE Course (CourseID INT,TeacherID INT); INSERT INTO Teacher (TeacherID,Gender) VALUES (1,'Female'),(2,'Male'); INSERT INTO Course (CourseID,TeacherID) VALUES (101,1),(102,2),(103,1); | SELECT CourseID FROM Course c JOIN Teacher t ON c.TeacherID = t.TeacherID WHERE t.Gender = 'Female' GROUP BY CourseID; |
What is the total number of contracts negotiated by each contractor and their total duration? | CREATE TABLE ContractNegotiations (contract_id INT,contractor VARCHAR(50),contract_duration INT); INSERT INTO ContractNegotiations (contract_id,contractor,contract_duration) VALUES (1,'Acme Corp',12); INSERT INTO ContractNegotiations (contract_id,contractor,contract_duration) VALUES (2,'Global Defense',18); | SELECT contractor, COUNT(*) as total_contracts, SUM(contract_duration) as total_duration FROM ContractNegotiations GROUP BY contractor; |
Which companies have not yet received any investment? | CREATE TABLE companies_funding (id INT,company_id INT,funding_amount INT); CREATE TABLE companies (id INT,name TEXT); | SELECT companies.name FROM companies LEFT JOIN companies_funding ON companies.id = companies_funding.company_id WHERE funding_amount IS NULL; |
Find the number of distinct artifact types per site and their historical periods. | CREATE TABLE excavation_sites (site_id INT,site_name VARCHAR(255)); CREATE TABLE artifacts (artifact_id INT,site_id INT,artifact_type VARCHAR(255),historical_period VARCHAR(255)); INSERT INTO excavation_sites (site_id,site_name) VALUES (1,'site_a'),(2,'site_b'),(3,'site_c'); INSERT INTO artifacts (artifact_id,site_id,artifact_type,historical_period) VALUES (1,1,'Pottery','Iron Age'),(2,1,'Bone Fragments','Stone Age'),(3,2,'Pottery','Iron Age'),(4,2,'Coins','Medieval'),(5,3,'Bone Fragments','Stone Age'),(6,3,'Bronze Tools','Bronze Age'); | SELECT site_name, historical_period, COUNT(DISTINCT artifact_type) as artifact_count FROM excavation_sites s JOIN artifacts a ON s.site_id = a.site_id GROUP BY site_name, historical_period; |
What is the monthly data usage distribution for customers in the 'rural' region? | CREATE TABLE subscribers (id INT,region VARCHAR(10),monthly_data_usage DECIMAL(5,2)); INSERT INTO subscribers (id,region,monthly_data_usage) VALUES (1,'urban',3.5),(2,'rural',2.2),(3,'urban',4.1),(4,'rural',1.9),(5,'urban',3.9); | SELECT monthly_data_usage, COUNT(*) FROM subscribers WHERE region = 'rural' GROUP BY monthly_data_usage; |
What is the sum of ESG scores for investments in the Healthcare sector? | CREATE TABLE investments(id INT,sector VARCHAR(20),esg_score INT); INSERT INTO investments VALUES(1,'Tech',85),(2,'Healthcare',75),(3,'Tech',82); | SELECT SUM(esg_score) as total_esg_score FROM investments WHERE sector = 'Healthcare'; |
Update the funding amount for 'Climate Adaptation Asia' project to '1800000' | CREATE TABLE climate_adaptation (region VARCHAR(255),funding FLOAT); INSERT INTO climate_adaptation (region,funding) VALUES ('Climate Adaptation Asia',1500000),('Climate Adaptation Africa',1200000); | UPDATE climate_adaptation SET funding = 1800000 WHERE region = 'Climate Adaptation Asia'; |
Show the number of satellites in geostationary orbit by each country | CREATE TABLE satellites_by_orbit (satellite_id INT,country VARCHAR(50),orbit_type VARCHAR(50)); INSERT INTO satellites_by_orbit (satellite_id,country,orbit_type) VALUES (1,'USA','Geostationary'); INSERT INTO satellites_by_orbit (satellite_id,country,orbit_type) VALUES (2,'Russia','Low Earth Orbit'); INSERT INTO satellites_by_orbit (satellite_id,country,orbit_type) VALUES (3,'China','Geostationary'); | SELECT country, COUNT(*) as num_satellites FROM satellites_by_orbit WHERE orbit_type = 'Geostationary' GROUP BY country; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.