instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the average stocking density of salmon farms in Norway?
CREATE TABLE salmon_farms (id INT,name TEXT,country TEXT,stocking_density FLOAT); INSERT INTO salmon_farms (id,name,country,stocking_density) VALUES (1,'Farm A','Norway',25.3); INSERT INTO salmon_farms (id,name,country,stocking_density) VALUES (2,'Farm B','Norway',23.1);
SELECT AVG(stocking_density) FROM salmon_farms WHERE country = 'Norway';
Calculate the total number of animals in each habitat type.
CREATE TABLE habitat (species VARCHAR(50),habitat_type VARCHAR(50),animal_count INT);
SELECT habitat_type, SUM(animal_count) FROM habitat GROUP BY habitat_type;
List all companies that have not yet had an exit event and are in the Fintech industry
CREATE TABLE exit_strategies (company_id INT,exit_type TEXT,exit_year INT); INSERT INTO exit_strategies (company_id,exit_type,exit_year) VALUES (1,'Acquisition',2020); INSERT INTO exit_strategies (company_id,exit_type,exit_year) VALUES (2,NULL,NULL); CREATE TABLE industry (company_id INT,industry TEXT); INSERT INTO industry (company_id,industry) VALUES (1,'Fintech'); INSERT INTO industry (company_id,industry) VALUES (2,'Retail');
SELECT name FROM company WHERE id NOT IN (SELECT company_id FROM exit_strategies WHERE exit_type IS NOT NULL) AND id IN (SELECT company_id FROM industry WHERE industry = 'Fintech');
List all sustainable projects with their start and end dates
CREATE TABLE Project (id INT,name VARCHAR(20),start_date DATE,end_date DATE); CREATE TABLE Sustainability_Standard (project_id INT,standard VARCHAR(20));
SELECT Project.name, Project.start_date, Project.end_date FROM Project INNER JOIN Sustainability_Standard ON Project.id = Sustainability_Standard.project_id;
What was the total revenue for each cuisine type in February 2022?
CREATE TABLE restaurant_revenue (restaurant_id INT,cuisine_type VARCHAR(255),revenue DECIMAL(10,2),transaction_date DATE); INSERT INTO restaurant_revenue (restaurant_id,cuisine_type,revenue,transaction_date) VALUES (1,'Indian',6000,'2022-02-01'),(2,'Japanese',8000,'2022-02-02');
SELECT cuisine_type, SUM(revenue) as total_revenue FROM restaurant_revenue WHERE transaction_date BETWEEN '2022-02-01' AND '2022-02-28' GROUP BY cuisine_type;
What is the maximum number of workplace safety violations for any sector in the last year?
CREATE TABLE if not exists violations (id INT PRIMARY KEY,sector VARCHAR(255),violation_date DATE,num_violations INT); INSERT INTO violations (id,sector,violation_date,num_violations) VALUES (1,'construction','2022-01-01',5),(2,'construction','2022-04-01',10),(3,'mining','2022-07-01',7);
SELECT MAX(num_violations) FROM violations WHERE violation_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR);
What is the maximum funding amount for biotech startups in Texas?
CREATE TABLE startups (id INT,name VARCHAR(100),location VARCHAR(50),industry VARCHAR(50),funding FLOAT); INSERT INTO startups (id,name,location,industry,funding) VALUES (1,'StartupA','TX','Biotech',2000000.0); INSERT INTO startups (id,name,location,industry,funding) VALUES (2,'StartupB','TX','Biotech',3000000.0); INSERT INTO startups (id,name,location,industry,funding) VALUES (3,'StartupC','NY','Biotech',4000000.0);
SELECT MAX(funding) FROM startups WHERE location = 'TX' AND industry = 'Biotech';
How many autonomous driving research studies were conducted in Japan in the year 2020?
CREATE TABLE ResearchStudy (id INT,title VARCHAR(100),year INT,location VARCHAR(50),type VARCHAR(50));
SELECT COUNT(*) FROM ResearchStudy WHERE year = 2020 AND location = 'Japan' AND type = 'Autonomous Driving';
What is the average project timeline for sustainable building projects in the state of Washington?
CREATE TABLE ProjectTimeline (ProjectID INT,State TEXT,Timeline INT); INSERT INTO ProjectTimeline (ProjectID,State,Timeline) VALUES (101,'WA',60),(102,'OR',50),(103,'WA',70),(104,'OR',55);
SELECT AVG(Timeline) FROM ProjectTimeline WHERE State = 'WA' AND ProjectID IN (SELECT ProjectID FROM SustainableProjects);
Delete records in waste_generation table where waste type is 'Plastic Bags'
CREATE TABLE waste_generation (id INT PRIMARY KEY,location VARCHAR(255),waste_type VARCHAR(255),quantity INT,date DATE);
DELETE FROM waste_generation WHERE waste_type = 'Plastic Bags';
Find the minimum temperature for each crop type
CREATE TABLE crop (id INT,type VARCHAR(255),temperature FLOAT); INSERT INTO crop (id,type,temperature) VALUES (1,'corn',22.5),(2,'soybean',20.0),(3,'cotton',24.3),(4,'corn',18.5),(5,'soybean',19.5);
SELECT type, MIN(temperature) FROM crop GROUP BY type;
What is the average number of physiotherapists in rural areas in South Africa?
CREATE TABLE SouthAfricanHealthcare (Province VARCHAR(20),Location VARCHAR(50),ProviderType VARCHAR(30),NumberOfProviders INT); INSERT INTO SouthAfricanHealthcare (Province,Location,ProviderType,NumberOfProviders) VALUES ('Province A','Rural Area A','Doctor',15),('Province A','Rural Area B','Nurse',20),('Province A','Rural Area C','Physiotherapist',12),('Province B','Rural Area D','Physiotherapist',10);
SELECT AVG(NumberOfProviders) FROM SouthAfricanHealthcare WHERE Province IN ('Province A', 'Province B') AND Location LIKE '%Rural Area%' AND ProviderType = 'Physiotherapist';
Identify the defense projects with timelines that overlap with at least one other project.
CREATE TABLE DefenseProjects (ProjectID INT,ProjectName VARCHAR(100),StartDate DATE,EndDate DATE);
SELECT A.ProjectID, A.ProjectName FROM DefenseProjects A JOIN DefenseProjects B ON A.ProjectID <> B.ProjectID AND A.StartDate <= B.EndDate AND B.StartDate <= A.EndDate;
Add a new 'habitat' record into the 'habitats' table
CREATE TABLE habitats (id INT,name VARCHAR(50),location VARCHAR(50),size FLOAT);
INSERT INTO habitats (id, name, location, size) VALUES (1, 'Forest', 'Amazon', 50000.0);
Find the average response time for natural disasters in each quarter of 2018
CREATE TABLE natural_disasters_2018 (id INT,disaster_date DATE,response_time INT); INSERT INTO natural_disasters_2018 (id,disaster_date,response_time) VALUES (1,'2018-01-01',12),(2,'2018-04-01',15),(3,'2018-07-01',18),(4,'2018-10-01',20);
SELECT EXTRACT(QUARTER FROM disaster_date) as quarter, AVG(response_time) as avg_response_time FROM natural_disasters_2018 GROUP BY EXTRACT(QUARTER FROM disaster_date);
How many times has the most popular vegan dish been ordered?
CREATE TABLE Menu (id INT,dish_name VARCHAR(255),dish_type VARCHAR(255),popularity INT); INSERT INTO Menu (id,dish_name,dish_type,popularity) VALUES (1,'Tofu Stir Fry','Vegan',150),(2,'Black Bean Burger','Vegan',200),(3,'Chickpea Curry','Vegan',250);
SELECT MAX(popularity) FROM Menu WHERE dish_type = 'Vegan';
What is the minimum number of artworks created by artists who have works in the 'MoMA' museum?
CREATE TABLE artist_museums (artist_id INT,museum_name TEXT); INSERT INTO artist_museums (artist_id,museum_name) VALUES (1,'MoMA'),(2,'Met'),(3,'Tate'),(4,'MoMA'),(5,'Tate'); CREATE TABLE artworks (id INT,artist_id INT,title TEXT,museum_id INT); INSERT INTO artworks (id,artist_id,title,museum_id) VALUES (1,1,'Dora Maar au Chat',1),(2,2,'Red Painting',NULL),(3,3,'Untitled',3),(4,4,'The Persistence of Memory',1),(5,5,'Composition with Red Blue and Yellow',NULL); CREATE TABLE museums (id INT,name TEXT); INSERT INTO museums (id,name) VALUES (1,'MoMA'),(2,'Met'),(3,'Tate'); CREATE TABLE museum_artworks (museum_id INT,artwork_id INT); INSERT INTO museum_artworks (museum_id,artwork_id) VALUES (1,1),(1,4),(3,3);
SELECT MIN(artworks.id) FROM artworks JOIN artist_museums ON artworks.artist_id = artist_museums.artist_id JOIN museum_artworks ON artworks.id = museum_artworks.artwork_id WHERE museums.name = 'MoMA';
Determine the number of volunteers who participated in 'Environment' projects in H1 2022, broken down by month.
CREATE TABLE volunteer_hours (volunteer_id INT,project_id INT,hours INT,volunteer_date DATE);
SELECT DATE_FORMAT(vp.volunteer_date, '%Y-%m') as month, COUNT(DISTINCT v.volunteer_id) as total_volunteers FROM volunteer_projects vp JOIN volunteer_hours vh ON vp.project_id = vh.project_id WHERE vp.cause = 'Environment' AND vp.year = 2022 AND vh.volunteer_date BETWEEN '2022-01-01' AND '2022-06-30' GROUP BY month;
What is the combined environmental impact of our mining and processing operations in 2020?
CREATE TABLE environmental_impact (operation_id INT,operation_type VARCHAR(20),impact_score INT,year INT); INSERT INTO environmental_impact (operation_id,operation_type,impact_score,year) VALUES (1,'mining',50,2020),(2,'processing',80,2020),(3,'mining',60,2019),(4,'processing',90,2019);
SELECT impact_score FROM environmental_impact WHERE operation_type IN ('mining', 'processing') AND year = 2020
Identify the number of schools built in each country in Europe between 2010 and 2020, inclusive.
CREATE TABLE Schools (id INT,name TEXT,country TEXT,build_date DATE); INSERT INTO Schools (id,name,country,build_date) VALUES (1,'Primary School A','France','2016-01-01'); INSERT INTO Schools (id,name,country,build_date) VALUES (2,'Secondary School B','Germany','2018-01-01');
SELECT country, COUNT(*) FROM Schools WHERE build_date BETWEEN '2010-01-01' AND '2020-12-31' GROUP BY country;
Which artists in 'London' have more than 2 collections?
CREATE TABLE artists (id INT,city VARCHAR(20),collections INT); INSERT INTO artists (id,city,collections) VALUES (1,'London',2),(2,'London',3),(3,'New York',1),(4,'London',4),(5,'London',1);
SELECT city, collections FROM artists WHERE city = 'London' AND collections > 2;
What is the average flight safety score for flights operated by SkyHigh Airlines in Europe?
CREATE TABLE Flights (flight_id INT,airline VARCHAR(255),region VARCHAR(255),safety_score INT);
SELECT AVG(safety_score) FROM Flights WHERE airline = 'SkyHigh Airlines' AND region = 'Europe';
What is the average donation amount for donors who donated more than $1000 in 2021?
CREATE TABLE donations (id INT,donor_id INT,donation DECIMAL(10,2),donation_date DATE);
SELECT AVG(donation) FROM donations WHERE donation > 1000 AND YEAR(donation_date) = 2021;
What is the minimum speed for vessels that have transported coal?
CREATE TABLE Vessels (id INT,name VARCHAR(50),type VARCHAR(50),average_speed DECIMAL(5,2)); CREATE TABLE Cargo (vessel_id INT,cargo_type VARCHAR(50),transport_date DATE); INSERT INTO Vessels (id,name,type,average_speed) VALUES (1,'Vessel1','OilTanker',15.5),(2,'Vessel2','BulkCarrier',12.3),(3,'Vessel3','BulkCarrier',11.2); INSERT INTO Cargo (vessel_id,cargo_type,transport_date) VALUES (1,'Oil','2022-01-01'),(1,'Oil','2022-04-01'),(2,'Coal','2022-01-15'),(3,'Coal','2022-02-01');
SELECT MIN(Vessels.average_speed) FROM Vessels INNER JOIN Cargo ON Vessels.id = Cargo.vessel_id WHERE Cargo.cargo_type = 'Coal';
What is the total number of teachers who have completed professional development courses in each subject area and have more than 5 years of teaching experience?
CREATE TABLE teacher_training (teacher_id INT,subject_area VARCHAR(50),completed BOOLEAN,teaching_experience INT); INSERT INTO teacher_training (teacher_id,subject_area,completed,teaching_experience) VALUES (1,'Mathematics',TRUE,10),(2,'Mathematics',FALSE,2),(3,'Science',TRUE,8),(4,'Science',TRUE,6),(5,'English',FALSE,3);
SELECT subject_area, SUM(completed) as num_teachers FROM teacher_training WHERE teaching_experience > 5 GROUP BY subject_area;
How many journalists were arrested in Africa in the last 6 months?
CREATE TABLE journalist_arrests (id INT,journalist VARCHAR(255),location VARCHAR(255),date DATE); INSERT INTO journalist_arrests (id,journalist,location,date) VALUES (1,'Journalist 1','Africa','2023-01-01'),(2,'Journalist 2','Africa','2023-02-01');
SELECT COUNT(*) FROM journalist_arrests WHERE location = 'Africa' AND date >= DATEADD(month, -6, GETDATE());
What is the average rating of the TV shows produced in India and released between 2010 and 2015, categorized by genre?
CREATE TABLE tv_shows (id INT,title VARCHAR(255),rating FLOAT,release_year INT,country VARCHAR(50),genre VARCHAR(50)); INSERT INTO tv_shows (id,title,rating,release_year,country,genre) VALUES (1,'Show1',7.5,2010,'India','Comedy'),(2,'Show2',8.2,2012,'India','Drama'),(3,'Show3',6.8,2015,'India','Action');
SELECT genre, AVG(rating) FROM tv_shows WHERE release_year BETWEEN 2010 AND 2015 AND country = 'India' GROUP BY genre;
Alter the workforce_training table to add a column for employee ID in the national identification format
CREATE TABLE workforce_training (id INT PRIMARY KEY,employee_name VARCHAR(255),training_topic VARCHAR(255),training_hours INT,training_completion_date DATE);
ALTER TABLE workforce_training ADD COLUMN national_id VARCHAR(50);
What is the 'Production Time' for 'Jeans' in 'Europe'?
CREATE TABLE jeans_production(garment VARCHAR(20),region VARCHAR(20),production_time INT); INSERT INTO jeans_production VALUES('Jeans','Europe',18);
SELECT production_time FROM jeans_production WHERE garment = 'Jeans' AND region = 'Europe';
What is the average rating of tours in Europe that are both wheelchair accessible and offer vegetarian meals?
CREATE TABLE if NOT EXISTS tours (id INT,name TEXT,rating FLOAT,wheelchair_accessible BOOLEAN,vegetarian_meal BOOLEAN); INSERT INTO tours (id,name,rating,wheelchair_accessible,vegetarian_meal) VALUES (1,'Mountain Biking Adventure',4.5,false,true),(2,'Historic City Tour',4.2,true,false),(3,'Cultural Exploration',4.8,true,true);
SELECT AVG(rating) FROM tours WHERE wheelchair_accessible = true AND vegetarian_meal = true AND country = 'Europe';
What is the average permit cost per square foot for each permit type in the state of New York?
CREATE TABLE permit_costs (permit_id INT,permit_type TEXT,state TEXT,cost INT,sqft INT); INSERT INTO permit_costs (permit_id,permit_type,state,cost,sqft) VALUES (1,'Residential','New York',80000,2500),(2,'Commercial','New York',300000,7500);
SELECT permit_type, AVG(cost/sqft) FROM permit_costs WHERE state = 'New York' GROUP BY permit_type;
What is the maximum song_length in the hiphop genre?
CREATE TABLE genres (genre VARCHAR(10),song_id INT,song_length FLOAT); INSERT INTO genres (genre,song_id,song_length) VALUES ('hiphop',7,202.5),('hiphop',8,245.8),('hiphop',9,198.1);
SELECT MAX(song_length) FROM genres WHERE genre = 'hiphop';
Delete sessions with session_duration less than 1 hour
CREATE TABLE game_sessions (session_id INT,player_id INT,session_start_time TIMESTAMP,session_duration INTERVAL);
DELETE FROM game_sessions WHERE session_duration < '01:00:00';
What is the total number of marine species observed in the Pacific region?
CREATE TABLE marine_species (name varchar(255),region varchar(255),observations int); INSERT INTO marine_species (name,region,observations) VALUES ('Blue Whale','Pacific',3000),('Hammerhead Shark','Pacific',1500),('Sea Otter','Pacific',2000);
SELECT SUM(observations) FROM marine_species WHERE region = 'Pacific';
How many mental health support sessions were conducted by teachers from underrepresented communities in each department?
CREATE TABLE departments (department_id INT,department_name TEXT); CREATE TABLE teachers (teacher_id INT,teacher_name TEXT,department_id INT,community_representation TEXT); CREATE TABLE sessions (session_id INT,teacher_id INT,session_date DATE,support_type TEXT); INSERT INTO departments VALUES (1,'Mathematics'),(2,'Science'),(3,'English'); INSERT INTO teachers VALUES (1,'Ms. Acevedo',1,'underrepresented'),(2,'Mr. Chen',2,'mainstream'),(3,'Mx. Patel',3,'underrepresented'); INSERT INTO sessions VALUES (1,1,'2022-02-01','mental health'),(2,2,'2022-02-02','academic'),(3,3,'2022-02-03','mental health');
SELECT d.department_name, COUNT(s.session_id) FROM departments d INNER JOIN teachers t ON d.department_id = t.department_id INNER JOIN sessions s ON t.teacher_id = s.teacher_id WHERE t.community_representation = 'underrepresented' AND s.support_type = 'mental health' GROUP BY d.department_id;
List the species and maximum depth for deep-sea fish found in the Indian Ocean.
CREATE TABLE deep_sea_fish (species VARCHAR(255),ocean VARCHAR(255),max_depth INT); INSERT INTO deep_sea_fish (species,ocean,max_depth) VALUES ('Anglerfish','Indian Ocean',3000);
SELECT species, max_depth FROM deep_sea_fish WHERE ocean = 'Indian Ocean'
What is the difference in crop yield between organic and non-organic farming methods in India?
CREATE TABLE CropYield (region VARCHAR(255),farming_method VARCHAR(255),yield INT); INSERT INTO CropYield (region,farming_method,yield) VALUES ('India','Organic',100),('India','Non-Organic',120),('China','Organic',110),('China','Non-Organic',130);
SELECT farming_method, AVG(yield) FROM CropYield WHERE region = 'India' GROUP BY farming_method;
List the names of all startups that have received funding in the last 3 years
CREATE TABLE funding_data (company_name VARCHAR(100),funding_year INT,funding_amount INT);
SELECT company_name FROM funding_data WHERE funding_year >= (YEAR(CURRENT_DATE) - 3);
Calculate the average funding for biotech startups in the USA and Canada.
CREATE SCHEMA if not exists startup_funding;CREATE TABLE if not exists startup_funding.data (id INT,startup VARCHAR(50),country VARCHAR(50),funding DECIMAL(10,2)); INSERT INTO startup_funding.data (id,startup,country,funding) VALUES (1,'StartupA','USA',1500000.00),(2,'StartupB','USA',2000000.00),(3,'StartupC','Canada',1000000.00),(4,'StartupD','Canada',1250000.00),(5,'StartupE','Mexico',750000.00);
SELECT country, AVG(funding) FROM startup_funding.data WHERE country IN ('USA', 'Canada') GROUP BY country;
What is the total number of minutes spent working out by users in their 30s?
CREATE TABLE workout_minutes (user_id INT,age INT,workout_minutes INT); INSERT INTO workout_minutes (user_id,age,workout_minutes) VALUES (1,32,120),(2,28,150),(3,35,180),(4,31,240);
SELECT SUM(workout_minutes) FROM workout_minutes WHERE age BETWEEN 30 AND 39;
What is the maximum number of traffic violations in the "TrafficViolations" table, per type of violation, for violations that occurred in school zones?
CREATE TABLE TrafficViolations (id INT,violation_type VARCHAR(50),location VARCHAR(50),fine DECIMAL(5,2)); INSERT INTO TrafficViolations (id,violation_type,location,fine) VALUES (1,'Speeding','School Zone',100),(2,'Illegal Parking','Business District',50),(3,'Speeding','Residential Area',30),(4,'Running Red Light','School Zone',150),(5,'Speeding','School Zone',200);
SELECT violation_type, COUNT(*) as num_violations FROM TrafficViolations WHERE location LIKE '%School%' GROUP BY violation_type;
What is the average funding amount per company, and the company with the highest average funding?
CREATE TABLE Company (id INT,name VARCHAR(50)); INSERT INTO Company (id,name) VALUES (1,'Acme Inc'); INSERT INTO Company (id,name) VALUES (2,'Beta Corp'); INSERT INTO Company (id,name) VALUES (3,'Gamma Startup'); CREATE TABLE Funding (company_id INT,funding_amount INT,funding_date DATE); INSERT INTO Funding (company_id,funding_amount,funding_date) VALUES (1,5000000,'2012-01-01'); INSERT INTO Funding (company_id,funding_amount,funding_date) VALUES (1,10000000,'2016-01-01'); INSERT INTO Funding (company_id,funding_amount,funding_date) VALUES (2,2000000,'2016-05-10'); INSERT INTO Funding (company_id,funding_amount,funding_date) VALUES (3,8000000,'2019-04-20');
SELECT c.name, AVG(f.funding_amount) as avg_funding, RANK() OVER (ORDER BY AVG(f.funding_amount) DESC) as rank FROM Company c JOIN Funding f ON c.id = f.company_id GROUP BY c.name;
What is the total value of assets held by the bank in each country?
CREATE TABLE assets (id INT,country VARCHAR(50),value DECIMAL(10,2)); INSERT INTO assets (id,country,value) VALUES (1,'USA',1000000.00),(2,'Canada',500000.00),(3,'Mexico',300000.00);
SELECT country, SUM(value) FROM assets GROUP BY country;
What is the total number of military vehicles and their corresponding types, along with the country responsible for manufacturing them?
CREATE TABLE military_vehicles (id INT,name VARCHAR(255),country_code VARCHAR(3),vehicle_type VARCHAR(255)); CREATE TABLE countries (code VARCHAR(3),name VARCHAR(255)); INSERT INTO military_vehicles (id,name,country_code,vehicle_type) VALUES (1,'Vehicle A','USA','Tank'),(2,'Vehicle B','RUS','Aircraft'),(3,'Vehicle C','CHN','Ship'); INSERT INTO countries (code,name) VALUES ('USA','United States of America'),('RUS','Russian Federation'),('CHN','People''s Republic of China');
SELECT COUNT(id) as total_vehicles, v.vehicle_type, c.name as country_name FROM military_vehicles v JOIN countries c ON v.country_code = c.code GROUP BY v.vehicle_type, c.name;
What is the maximum production capacity of Erbium mines in Australia?
CREATE TABLE erbium_mines (mine VARCHAR(50),country VARCHAR(50),capacity INT);
SELECT MAX(capacity) FROM erbium_mines WHERE country = 'Australia';
What is the total salary paid by each factory?
CREATE TABLE factories (factory_id INT,factory_name VARCHAR(20)); INSERT INTO factories VALUES (1,'Factory A'),(2,'Factory B'),(3,'Factory C'); CREATE TABLE workers (worker_id INT,factory_id INT,salary DECIMAL(5,2)); INSERT INTO workers VALUES (1,1,35000.00),(2,1,36000.00),(3,2,45000.00),(4,3,34000.00);
SELECT f.factory_name, SUM(salary) FROM workers w INNER JOIN factories f ON w.factory_id = f.factory_id GROUP BY f.factory_name;
List the number of times each crop type was harvested in the 'Western' region in 2021.
CREATE TABLE HarvestData (id INT,region VARCHAR(255),crop_type VARCHAR(255),harvest_date DATE);
SELECT region, crop_type, COUNT(DISTINCT harvest_date) FROM HarvestData WHERE region = 'Western' AND YEAR(harvest_date) = 2021 GROUP BY region, crop_type;
How many artists from each country released an album in 2020?
CREATE TABLE Country (id INT,country VARCHAR(255)); CREATE TABLE Artist (id INT,country_id INT,name VARCHAR(255)); CREATE TABLE Album (id INT,artist_id INT,year INT);
SELECT C.country, COUNT(DISTINCT A.artist_id) as album_count FROM Country C INNER JOIN Artist A ON C.id = A.country_id INNER JOIN Album AL ON A.id = AL.artist_id WHERE AL.year = 2020 GROUP BY C.country;
What is the total biomass of krill in the Arctic Ocean?
CREATE TABLE Biomass (species VARCHAR(255),ocean VARCHAR(255),biomass FLOAT); INSERT INTO Biomass (species,ocean,biomass) VALUES ('Krill','Arctic Ocean',2.1); INSERT INTO Biomass (species,ocean,biomass) VALUES ('Krill','Arctic Ocean',1.9);
SELECT SUM(biomass) FROM Biomass WHERE species = 'Krill' AND ocean = 'Arctic Ocean';
Show the top 5 oldest policyholders by age.
CREATE TABLE Policyholders (PolicyholderID INT,Name VARCHAR(50),Age INT,Gender VARCHAR(10),State VARCHAR(2)); INSERT INTO Policyholders (PolicyholderID,Name,Age,Gender,State) VALUES (1,'Aisha Brown',68,'Female','NY'); INSERT INTO Policyholders (PolicyholderID,Name,Age,Gender,State) VALUES (2,'Brian Green',55,'Male','CA'); INSERT INTO Policyholders (PolicyholderID,Name,Age,Gender,State) VALUES (3,'Charlotte Lee',72,'Female','FL');
SELECT * FROM Policyholders ORDER BY Age DESC LIMIT 5;
How many biosensor technology projects were completed in Q2 2021?
CREATE SCHEMA if not exists biotech;CREATE TABLE if not exists biotech.projects (id INT,name VARCHAR(100),status VARCHAR(20),completion_date DATE); INSERT INTO biotech.projects (id,name,status,completion_date) VALUES (1,'Project1','Completed','2021-04-15'),(2,'Project2','In Progress','2021-07-20'),(3,'Project3','Completed','2021-06-30');
SELECT COUNT(*) FROM biotech.projects WHERE status = 'Completed' AND completion_date BETWEEN '2021-04-01' AND '2021-06-30';
What is the average cost of a space mission over the last 10 years?
CREATE TABLE space_missions_cost (year INT,cost FLOAT); INSERT INTO space_missions_cost (year,cost) VALUES (2012,5000000),(2013,6000000),(2014,7000000),(2015,8000000),(2016,9000000),(2017,10000000),(2018,11000000),(2019,12000000),(2020,13000000),(2021,14000000);
SELECT AVG(cost) FROM space_missions_cost WHERE year BETWEEN 2012 AND 2021;
What is the maximum billing amount for cases in the 'Western' region?
CREATE TABLE cases (id INT,region VARCHAR(10),billing_amount INT); INSERT INTO cases (id,region,billing_amount) VALUES (1,'Eastern',5000),(2,'Western',7000),(3,'Eastern',6000),(4,'Western',9000);
SELECT MAX(billing_amount) FROM cases WHERE region = 'Western';
What is the minimum depth of the deepest oceanographic areas?
CREATE TABLE Oceanography (id INT PRIMARY KEY,location VARCHAR(255),depth FLOAT,salinity FLOAT); INSERT INTO Oceanography (id,location,depth,salinity) VALUES (1,'Pacific Ocean Trench',10000,35),(2,'Southern Ocean',7000,34);
SELECT location, MIN(depth) FROM Oceanography WHERE depth < 8000;
What vehicles passed the 'Pedestrian Safety Test' in the SafetyTesting table?
CREATE TABLE SafetyTesting (Id INT,Vehicle VARCHAR(50),Test VARCHAR(50),Result VARCHAR(50)); INSERT INTO SafetyTesting (Id,Vehicle,Test,Result) VALUES (1,'Volvo XC60','Frontal Crash Test','Passed'),(2,'Nissan Leaf','Pedestrian Safety Test','Passed');
SELECT Vehicle FROM SafetyTesting WHERE Test = 'Pedestrian Safety Test' AND Result = 'Passed';
Identify the unique soil types analyzed in vineyards located in South Africa.
CREATE TABLE vineyard_soil_analysis (id INT,location VARCHAR(255),soil_type VARCHAR(255)); INSERT INTO vineyard_soil_analysis (id,location,soil_type) VALUES (1,'South Africa-Stellenbosch','loam'),(2,'South Africa-Franschhoek','clay'),(3,'South Africa-Stellenbosch','sand'),(4,'South Africa-Paarl','loam');
SELECT DISTINCT soil_type FROM vineyard_soil_analysis WHERE location LIKE '%South Africa%';
What is the total revenue for lipstick products in the organic category?
CREATE TABLE cosmetics_sales (product_category VARCHAR(20),product_type VARCHAR(20),is_organic BOOLEAN,revenue DECIMAL(10,2)); INSERT INTO cosmetics_sales (product_category,product_type,is_organic,revenue) VALUES ('Makeup','Lipstick',true,5000),('Makeup','Lipstick',false,7000),('Makeup','Foundation',true,8000),('Makeup','Mascara',false,6000);
SELECT SUM(revenue) FROM cosmetics_sales WHERE product_type = 'Lipstick' AND is_organic = true;
What is the total grant amount awarded to female faculty members in the Computer Science department in the last 3 years?
CREATE SCHEMA if not exists higher_ed;CREATE TABLE if not exists higher_ed.faculty(id INT,name VARCHAR(255),department VARCHAR(255),grant_amount DECIMAL(10,2),grant_date DATE,gender VARCHAR(10));
SELECT SUM(grant_amount) FROM higher_ed.faculty WHERE department = 'Computer Science' AND gender = 'Female' AND grant_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 YEAR);
What is the total amount of donations received by each NGO, grouped by category?
CREATE TABLE ngo_donations (ngo_id INT,donation_amount FLOAT,donation_year INT,ngo_category VARCHAR(255)); INSERT INTO ngo_donations (ngo_id,donation_amount,donation_year,ngo_category) VALUES (1,50000,2019,'Health'),(2,75000,2020,'Education'),(3,30000,2018,'Health'),(4,100000,2020,'Education'); CREATE TABLE ngo_categories (ngo_category_id INT,ngo_category VARCHAR(255)); INSERT INTO ngo_categories (ngo_category_id,ngo_category) VALUES (1,'Health'),(2,'Education'),(3,'Housing');
SELECT ngo_category, SUM(donation_amount) as total_donations FROM ngo_donations INNER JOIN ngo_categories ON ngo_donations.ngo_category = ngo_categories.ngo_category GROUP BY ngo_category;
What is the age of the second-oldest artifact at each excavation site?
CREATE TABLE ancient_artifacts (id INT,artifact_name VARCHAR(50),age INT,excavation_site VARCHAR(50));
SELECT excavation_site, LEAD(age) OVER (PARTITION BY excavation_site ORDER BY age) as second_oldest_artifact_age FROM ancient_artifacts;
What is the total number of suppliers in each country, and the number of suppliers with environmental certifications for each country?
CREATE TABLE suppliers (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),environmental_certification VARCHAR(255)); INSERT INTO suppliers (id,name,location,environmental_certification) VALUES (1,'Supplier A','Germany','ISO 14001'),(2,'Supplier B','Brazil','ISO 14001'),(3,'Supplier C','Japan',NULL),(4,'Supplier D','Canada','ISO 14001');
SELECT location as country, COUNT(*) as total_suppliers, SUM(CASE WHEN environmental_certification IS NOT NULL THEN 1 ELSE 0 END) as certified_suppliers FROM suppliers GROUP BY location;
Find the total energy production (in MWh) from renewable energy sources for each state in the renewable_energy_production table.
CREATE TABLE renewable_energy_production (state VARCHAR(50),year INT,energy_production FLOAT,energy_source VARCHAR(50));
SELECT state, SUM(energy_production) as total_renewable_energy FROM renewable_energy_production WHERE energy_source = 'Wind' OR energy_source = 'Solar' GROUP BY state;
What is the total number of shipments made by vendor X in March 2021?
CREATE TABLE shipments (id INT,vendor VARCHAR(50),ship_date DATE); INSERT INTO shipments (id,vendor,ship_date) VALUES (1,'Vendor X','2021-03-01'); INSERT INTO shipments (id,vendor,ship_date) VALUES (2,'Vendor Y','2021-03-05');
SELECT COUNT(*) FROM shipments WHERE vendor = 'Vendor X' AND EXTRACT(MONTH FROM ship_date) = 3 AND EXTRACT(YEAR FROM ship_date) = 2021;
What is the average monthly rainfall at each mine location?
CREATE TABLE mine (id INT,name TEXT,location TEXT); INSERT INTO mine (id,name,location) VALUES (1,'Golden Mine','USA'),(2,'Silver Mine','Canada'); CREATE TABLE weather (id INT,mine_id INT,date DATE,rainfall REAL); INSERT INTO weather (id,mine_id,date,rainfall) VALUES (1,1,'2022-01-01',30),(2,1,'2022-02-01',40),(3,1,'2022-03-01',50),(4,2,'2022-01-01',60),(5,2,'2022-02-01',70),(6,2,'2022-03-01',80);
SELECT mine_id, AVG(rainfall) as avg_rainfall FROM weather GROUP BY mine_id;
What are the names and total budgets for bills related to education and health with a budget over 500000 dollars?
CREATE TABLE Bills (BillID INT,Department VARCHAR(50),Amount FLOAT);
SELECT Bills.Department, SUM(Bills.Amount) AS TotalBudget FROM Bills WHERE Bills.Department IN ('Education', 'Health') AND Bills.Amount > 500000 GROUP BY Bills.Department;
What is the maximum monthly salary in the 'Construction Workers Union'?
CREATE TABLE union_members (member_id INT,member_name VARCHAR(255),union_id INT,monthly_salary DECIMAL(10,2)); CREATE TABLE unions (union_id INT,union_name VARCHAR(255)); INSERT INTO unions (union_id,union_name) VALUES (123,'Transportation Workers Union'); INSERT INTO unions (union_id,union_name) VALUES (456,'Construction Workers Union'); INSERT INTO union_members (member_id,member_name,union_id,monthly_salary) VALUES (1,'John Doe',456,4000.50); INSERT INTO union_members (member_id,member_name,union_id,monthly_salary) VALUES (2,'Jane Doe',456,4500.25);
SELECT MAX(monthly_salary) FROM union_members WHERE union_id = (SELECT union_id FROM unions WHERE union_name = 'Construction Workers Union');
Compare the drought-impacted areas between 'East' and 'West' regions.
CREATE TABLE drought_impact (area VARCHAR(255),region VARCHAR(255),population INT); INSERT INTO drought_impact (area,region,population) VALUES ('City A','East',600000),('City B','East',700000),('City C','East',500000),('City D','West',800000),('City E','West',900000),('City F','West',750000);
SELECT region, COUNT(*) FROM drought_impact GROUP BY region;
Find the total revenue for digital and physical sales for the year 2020.
CREATE TABLE Sales (SaleID INT,SaleDate DATE,SaleType VARCHAR(10),Revenue DECIMAL(10,2)); INSERT INTO Sales (SaleID,SaleDate,SaleType,Revenue) VALUES (1,'2020-01-01','Digital',1000); INSERT INTO Sales (SaleID,SaleDate,SaleType,Revenue) VALUES (2,'2020-02-01','Physical',2000);
SELECT SUM(Revenue) FROM Sales WHERE SaleDate BETWEEN '2020-01-01' AND '2020-12-31' AND SaleType IN ('Digital', 'Physical');
Find the total number of marine species in each ocean.
CREATE TABLE marine_species (species_id INTEGER,species_name VARCHAR(255),ocean VARCHAR(50)); CREATE TABLE oceanography (ocean_id INTEGER,ocean_name VARCHAR(50),total_area FLOAT);
SELECT ocean, COUNT(species_id) FROM marine_species GROUP BY ocean;
What is the total number of accessibility-related staff hires in Q2 and Q3 of 2022?
CREATE TABLE StaffHires (hire_date DATE,staff_type VARCHAR(255)); INSERT INTO StaffHires (hire_date,staff_type) VALUES ('2022-04-05','Accessibility Specialist'); INSERT INTO StaffHires (hire_date,staff_type) VALUES ('2022-08-10','Accessibility Coordinator');
SELECT SUM(total_hires) as q2_q3_hires FROM (SELECT CASE WHEN hire_date BETWEEN '2022-04-01' AND LAST_DAY('2022-06-30') THEN 1 WHEN hire_date BETWEEN '2022-07-01' AND LAST_DAY('2022-09-30') THEN 1 ELSE 0 END as total_hires FROM StaffHires) AS subquery;
What is the name and budget of the public university with the largest budget in Oregon?
CREATE TABLE public_universities (name TEXT,budget INTEGER,state TEXT); INSERT INTO public_universities (name,budget,state) VALUES ('University1',100000,'Oregon'),('University2',120000,'Oregon'),('University3',90000,'Oregon');
SELECT name, budget FROM public_universities WHERE state = 'Oregon' ORDER BY budget DESC LIMIT 1;
What is the number of cases for each attorney and their respective success rates?
CREATE TABLE attorneys (attorney_id INT,name TEXT); CREATE TABLE cases (case_id INT,attorney_id INT,won BOOLEAN);
SELECT a.attorney_id, a.name, COUNT(c.case_id) AS cases_handled, AVG(CASE WHEN won THEN 1.0 ELSE 0.0 END) * 100.0 AS success_rate FROM attorneys a JOIN cases c ON a.attorney_id = c.attorney_id GROUP BY a.attorney_id, a.name;
What is the average budget allocated for education in urban areas?
CREATE TABLE district (id INT,name VARCHAR(50),type VARCHAR(50)); INSERT INTO district (id,name,type) VALUES (1,'City A','urban'),(2,'Town B','urban'),(3,'Village C','rural'); CREATE TABLE budget (district_id INT,category VARCHAR(50),amount INT); INSERT INTO budget (district_id,category,amount) VALUES (1,'education',500000),(1,'healthcare',300000),(2,'education',350000),(2,'healthcare',400000),(3,'education',200000),(3,'healthcare',500000);
SELECT AVG(amount) FROM budget WHERE category = 'education' AND district_id IN (SELECT id FROM district WHERE type = 'urban');
Find the total volume of timber sold by mills located in 'Region A' or 'Region B'.
CREATE TABLE MillSales(mill_name TEXT,sale_volume INT,region TEXT); INSERT INTO MillSales (mill_name,sale_volume,region) VALUES ('Mill X',500,'Region A'),('Mill Y',350,'Region B'),('Mill Z',700,'Region A');
SELECT SUM(sale_volume) FROM MillSales WHERE region IN ('Region A', 'Region B');
What is the total water usage by mine site in 2021?
CREATE TABLE water_usage (site_id INT,site_name TEXT,month INT,year INT,water_usage INT); INSERT INTO water_usage (site_id,site_name,month,year,water_usage) VALUES (1,'ABC Mine',3,2021,15000),(2,'DEF Mine',5,2021,20000),(3,'GHI Mine',1,2022,25000),(1,'ABC Mine',4,2021,17000),(2,'DEF Mine',6,2021,18000);
SELECT site_name, SUM(water_usage) as total_water_usage_2021 FROM water_usage WHERE year = 2021 GROUP BY site_name;
What is the total weight of sustainable materials used in each production facility?
CREATE TABLE Production_Facilities (facility_id INT,facility_name VARCHAR(50),sustainable_material_weight FLOAT);
SELECT Production_Facilities.facility_name, SUM(Production_Facilities.sustainable_material_weight) as total_weight FROM Production_Facilities GROUP BY Production_Facilities.facility_name;
Update the 'launch_site' for the 'Mars_2023' satellite mission to 'Cape Canaveral' in the 'satellite_deployment' table.
CREATE TABLE satellite_deployment (mission VARCHAR(50),launch_site VARCHAR(50)); INSERT INTO satellite_deployment (mission,launch_site) VALUES ('Mars_2020','Vandenberg'),('Mars_2022','Cape_Canaveral'),('Mars_2023','Kennedy_Space_Center');
UPDATE satellite_deployment SET launch_site = 'Cape_Canaveral' WHERE mission = 'Mars_2023';
What is the total number of trips taken in autonomous vehicles in Singapore?
CREATE TABLE autonomous_vehicles (vehicle_id int,city varchar(20),trips int); INSERT INTO autonomous_vehicles (vehicle_id,city,trips) VALUES (1,'Singapore',235),(2,'Singapore',345),(3,'Singapore',456);
SELECT SUM(trips) FROM autonomous_vehicles WHERE city = 'Singapore';
What is the total revenue of all R-rated movies?
CREATE TABLE Movies (id INT,title VARCHAR(255),rating VARCHAR(10),revenue INT);
SELECT SUM(revenue) FROM Movies WHERE rating = 'R';
Update 'Age' column in 'Students' table to 16 for StudentId 1001
CREATE TABLE Students (StudentId INT,Name VARCHAR(50),Age INT); INSERT INTO Students (StudentId,Name,Age) VALUES (1001,'John Doe',16); CREATE VIEW StudentNames AS SELECT * FROM Students;
UPDATE Students SET Age = 16 WHERE StudentId = 1001;
List the total gold exports and mercury emissions from Ghana and Mali between 2016 and 2018.
CREATE TABLE ghana_gold_export (year INT,export_amount FLOAT); INSERT INTO ghana_gold_export (year,export_amount) VALUES (2016,2000.0),(2017,2100.0),(2018,2200.0); CREATE TABLE mali_gold_export (year INT,export_amount FLOAT); INSERT INTO mali_gold_export (year,export_amount) VALUES (2016,1500.0),(2017,1600.0),(2018,1700.0); CREATE TABLE ghana_mercury_emission (year INT,emission FLOAT); INSERT INTO ghana_mercury_emission (year,emission) VALUES (2016,10.0),(2017,11.0),(2018,12.0); CREATE TABLE mali_mercury_emission (year INT,emission FLOAT); INSERT INTO mali_mercury_emission (year,emission) VALUES (2016,8.0),(2017,9.0),(2018,10.0);
SELECT 'Ghana' AS country, SUM(ghana_gold_export.export_amount) AS gold_export, SUM(ghana_mercury_emission.emission) AS mercury_emission FROM ghana_gold_export INNER JOIN ghana_mercury_emission ON ghana_gold_export.year = ghana_mercury_emission.year WHERE ghana_gold_export.year BETWEEN 2016 AND 2018 UNION ALL SELECT 'Mali', SUM(mali_gold_export.export_amount), SUM(mali_mercury_emission.emission) FROM mali_gold_export INNER JOIN mali_mercury_emission ON mali_gold_export.year = mali_mercury_emission.year WHERE mali_gold_export.year BETWEEN 2016 AND 2018;
How many traffic accidents were reported in Texas in the past year?
CREATE TABLE accidents (id INT,report_date DATE,city TEXT,type TEXT); INSERT INTO accidents (id,report_date,city,type) VALUES (1,'2022-01-01','Houston','minor');
SELECT COUNT(*) FROM accidents WHERE accidents.report_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) AND accidents.city IN (SELECT cities.name FROM cities WHERE cities.state = 'Texas');
Which union represents the company with the most workplace safety violations?
CREATE TABLE unions (id INT,name VARCHAR(50)); INSERT INTO unions (id,name) VALUES (1,'Union A'),(2,'Union B'),(3,'Union C'); CREATE TABLE companies (id INT,name VARCHAR(50),union_id INT,safety_violations INT); INSERT INTO companies (id,name,union_id,safety_violations) VALUES (1,'Company X',1,10),(2,'Company Y',2,5),(3,'Company Z',3,15),(4,'Company W',1,0),(5,'Company V',3,20);
SELECT unions.name, MAX(companies.safety_violations) FROM unions JOIN companies ON unions.id = companies.union_id GROUP BY unions.name ORDER BY MAX(companies.safety_violations) DESC LIMIT 1;
Delete all records from the military equipment table that are older than 10 years
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');
DELETE FROM military_equipment WHERE purchase_date < '2011-01-01';
Which vendors have the highest average maintenance costs for military equipment, and the number of different equipment types maintained by these vendors?
CREATE TABLE Equipment (EID INT,Type VARCHAR(50),VendorID INT,MaintenanceCost INT); INSERT INTO Equipment (EID,Type,VendorID,MaintenanceCost) VALUES (1,'Tank',1,10000),(2,'Fighter Jet',1,20000),(3,'Helicopter',2,15000); CREATE TABLE Vendors (VID INT,Name VARCHAR(100)); INSERT INTO Vendors (VID,Name) VALUES (1,'Raytheon Technologies'),(2,'BAE Systems');
SELECT v.Name, AVG(Equipment.MaintenanceCost) as AvgMaintenanceCost, COUNT(DISTINCT Equipment.Type) as NumEquipmentTypes FROM Equipment JOIN Vendors v ON Equipment.VendorID = v.VID GROUP BY v.Name ORDER BY AvgMaintenanceCost DESC;
Which country has the most female players?
CREATE TABLE Players (PlayerID INT PRIMARY KEY,Age INT,Gender VARCHAR(10),Country VARCHAR(50)); INSERT INTO Players (PlayerID,Age,Gender,Country) VALUES (6,28,'Female','France'),(7,30,'Male','Germany'),(8,24,'Female','France'),(9,22,'Male','Canada'),(10,32,'Female','USA');
SELECT Country, COUNT(*) FROM Players WHERE Gender = 'Female' GROUP BY Country ORDER BY COUNT(*) DESC LIMIT 1;
What is the average salary for workers in the manufacturing sector in France and Germany?
CREATE TABLE worker_salaries (employee_id INT,country VARCHAR(50),sector VARCHAR(50),salary FLOAT);
SELECT AVG(salary) FROM worker_salaries WHERE country IN ('France', 'Germany') AND sector = 'Manufacturing';
List all unique modes of transportation and their associated average costs for freight forwarding in the Asia-Pacific region.
CREATE TABLE Transportation (id INT,mode TEXT,type TEXT,cost FLOAT); INSERT INTO Transportation (id,mode,type,cost) VALUES (1,'Sea','Full Container Load',1500),(2,'Air','Express',5000),(3,'Rail','Less than Container Load',800);
SELECT DISTINCT mode, AVG(cost) FROM Transportation WHERE type = 'Full Container Load' AND country IN ('Asia', 'Pacific') GROUP BY mode;
Which TV shows have the highest average rating per season in the horror genre?
CREATE TABLE tv_shows (id INT,title VARCHAR(255),season INT,genre VARCHAR(255),rating DECIMAL(3,2)); INSERT INTO tv_shows (id,title,season,genre,rating) VALUES (1,'TVShow1',1,'Horror',8.2),(2,'TVShow1',2,'Horror',8.5),(3,'TVShow2',1,'Horror',7.8),(4,'TVShow2',2,'Horror',8.0),(5,'TVShow3',1,'Comedy',9.0),(6,'TVShow3',2,'Comedy',8.8);
SELECT title, AVG(rating) AS avg_rating FROM tv_shows WHERE genre = 'Horror' GROUP BY title ORDER BY avg_rating DESC;
What is the average playtime of players who use VR technology?
CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),Playtime INT,VR INT); INSERT INTO Players (PlayerID,Age,Gender,Playtime,VR) VALUES (1,25,'Male',10,1); INSERT INTO Players (PlayerID,Age,Gender,Playtime,VR) VALUES (2,30,'Female',15,1); CREATE TABLE VRPlayers (PlayerID INT); INSERT INTO VRPlayers (PlayerID) VALUES (1); INSERT INTO VRPlayers (PlayerID) VALUES (2);
SELECT AVG(Players.Playtime) FROM Players INNER JOIN VRPlayers ON Players.PlayerID = VRPlayers.PlayerID;
What is the minimum number of deep-sea species observed in a single expedition in the Southern Ocean?
CREATE TABLE deep_sea_expeditions (id INT,expedition_name VARCHAR(255),year INT,country VARCHAR(255),region VARCHAR(255),num_species INT); INSERT INTO deep_sea_expeditions (id,expedition_name,year,country,region,num_species) VALUES (1,'Antarctic Circumnavigation Expedition',2016,'Australia','Southern',345),(2,'Southern Ocean Deep-Sea Expedition',2017,'New Zealand','Southern',567);
SELECT MIN(num_species) FROM deep_sea_expeditions WHERE region = 'Southern';
Which genes are involved in the 'pathway1'?
CREATE TABLE GenePathways (gene_id INT,gene_name TEXT,pathway TEXT); INSERT INTO GenePathways (gene_id,gene_name,pathway) VALUES (1,'GeneA','pathway1'),(2,'GeneB','pathway2'),(3,'GeneC','pathway1');
SELECT gene_name FROM GenePathways WHERE pathway = 'pathway1';
How many roundabouts have been built in Texas since 2010?
CREATE TABLE Intersection (id INT,name TEXT,location TEXT,type TEXT,build_date DATE); INSERT INTO Intersection (id,name,location,type,build_date) VALUES (1,'Dallas Circle','Dallas,TX','Roundabout','2012-05-01');
SELECT COUNT(*) FROM Intersection WHERE location LIKE '%TX%' AND type = 'Roundabout' AND build_date >= '2010-01-01';
What is the total area of fields in the "loamy" soil type category, grouped by the region?
CREATE TABLE fields (id INT,field_name VARCHAR(255),area FLOAT,soil_type VARCHAR(255),region VARCHAR(255)); INSERT INTO fields (id,field_name,area,soil_type,region) VALUES (1,'field1',10.5,'loamy','Northeast'),(2,'field2',12.3,'sandy','South'),(3,'field3',8.9,'loamy','Northeast'),(4,'field4',15.7,'clay','Midwest');
SELECT region, SUM(area) FROM fields WHERE soil_type = 'loamy' GROUP BY region;
How many artworks were created per year by artists in the 'ArtCollection' table?
CREATE TABLE ArtCollection (ArtworkID INT,ArtistID INT,ArtworkYear INT); INSERT INTO ArtCollection (ArtworkID,ArtistID,ArtworkYear) VALUES (1,1,1880),(2,1,1885),(3,2,1890),(4,2,1895),(5,3,1890),(6,3,1895),(7,4,1940),(8,4,1945),(9,5,1790),(10,5,1795);
SELECT ArtworkYear, COUNT(*) AS ArtworksPerYear FROM ArtCollection GROUP BY ArtworkYear;
What is the average age of readers who prefer news on 'politics'?
CREATE TABLE readers (id INT,name VARCHAR(20),age INT,favorite_category VARCHAR(20)); INSERT INTO readers (id,name,age,favorite_category) VALUES (1,'John Doe',35,'politics'),(2,'Jane Smith',40,'business');
SELECT AVG(age) FROM readers WHERE favorite_category = 'politics';
List all the machines that have usage hours greater than 100 and their last maintenance date.
CREATE TABLE machine_maintenance_new3 (id INT PRIMARY KEY,machine_name VARCHAR(50),last_maintenance_date DATE); CREATE TABLE machine_usage_new3 (id INT PRIMARY KEY,machine_name VARCHAR(50),usage_hours INT);
SELECT m.machine_name, m.last_maintenance_date FROM machine_maintenance_new3 m INNER JOIN machine_usage_new3 u ON m.machine_name = u.machine_name WHERE u.usage_hours > 100;
What is the average yield for each crop type in the 'agriculture' database, grouped by crop type, for farms that use sustainable practices?
CREATE TABLE crop (id INT,type VARCHAR(255),region VARCHAR(255),yield FLOAT,sustainability VARCHAR(255)); INSERT INTO crop (id,type,region,yield,sustainability) VALUES (1,'corn','Midwest',150.3,'sustainable'),(2,'wheat','Great Plains',120.5,'non-sustainable'),(3,'rice','Southeast',180.7,'sustainable'),(4,'corn','Midwest',165.2,'sustainable'),(5,'corn','Northeast',145.8,'non-sustainable');
SELECT type, AVG(yield) as avg_yield FROM crop WHERE sustainability = 'sustainable' GROUP BY type;
What is the total population of animals in the 'habitat_preservation' region?
CREATE TABLE habitat_preservation (id INT,region VARCHAR(50),animal_name VARCHAR(50),population INT); INSERT INTO habitat_preservation (id,region,animal_name,population) VALUES (1,'Habitat Preservation','Tiger',1500),(2,'Habitat Preservation','Elephant',3000);
SELECT SUM(population) FROM habitat_preservation WHERE region = 'Habitat Preservation';
How many instances of disinformation were detected in blogs in South America in the last month?
CREATE TABLE disinformation_detections (id INT,date DATE,source VARCHAR(255),location VARCHAR(255)); INSERT INTO disinformation_detections (id,date,source,location) VALUES (4,'2023-02-01','Blog 1','South America'),(5,'2023-02-02','Blog 2','South America'),(6,'2023-02-03','Blog 3','South America');
SELECT COUNT(*) FROM disinformation_detections WHERE location = 'South America' AND source LIKE '%Blog%' AND date >= DATEADD(month, -1, GETDATE());