instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Find the number of rural residents who have been diagnosed with a chronic condition, grouped by age and gender.
CREATE TABLE residents (id INT,name TEXT,age INT,gender TEXT,chronic_condition BOOLEAN);
SELECT age, gender, COUNT(*) FROM residents WHERE chronic_condition = TRUE GROUP BY age, gender;
What is the average exit valuation for startups founded by women in the healthcare industry?
CREATE TABLE startups(id INT,name TEXT,industry TEXT,founder_gender TEXT,exit_valuation INT); INSERT INTO startups VALUES (1,'StartupA','Healthcare','Female',100000000); INSERT INTO startups VALUES (2,'StartupB','Healthcare','Female',50000000); INSERT INTO startups VALUES (3,'StartupC','Tech','Male',200000000);
SELECT AVG(exit_valuation) FROM startups WHERE founder_gender = 'Female' AND industry = 'Healthcare';
What is the minimum delivery time for shipments to Nigeria?
CREATE TABLE Africa_Shipments (id INT,destination_country VARCHAR(50),delivery_time INT); INSERT INTO Africa_Shipments (id,destination_country,delivery_time) VALUES (1,'Nigeria',14),(2,'Nigeria',16),(3,'Egypt',15);
SELECT MIN(delivery_time) FROM Africa_Shipments WHERE destination_country = 'Nigeria';
What is the maximum number of parameters for models used in Explainable AI applications?
CREATE TABLE params_data (model_id INT,model_name VARCHAR(50),application VARCHAR(50),num_params INT);
SELECT MAX(num_params) FROM params_data WHERE application = 'Explainable AI';
Calculate the average safety rating of cosmetic products that use at least one non-organic ingredient.
CREATE TABLE products (product_id INT,safety_rating FLOAT,organic BOOLEAN); CREATE TABLE ingredients (ingredient_id INT,product_id INT,organic BOOLEAN);
SELECT AVG(products.safety_rating) as avg_safety_rating FROM products JOIN ingredients ON products.product_id = ingredients.product_id WHERE ingredients.organic = FALSE;
What is the maximum word count for articles published in the 'news' schema?
CREATE TABLE news.articles (article_id INT,title VARCHAR(100),word_count INT); INSERT INTO news.articles (article_id,title,word_count) VALUES (1,'Article 1',500),(2,'Article 2',600),(3,'Article 3',700);
SELECT MAX(word_count) FROM news.articles;
Insert new records into the Waste table with the following data: WasteType 'Toxic Chemicals', Amount 120, Date '2022-01-01'.
CREATE TABLE Waste (WasteID INT,WasteType VARCHAR(50),Amount INT,Date DATE);
INSERT INTO Waste (WasteID, WasteType, Amount, Date) VALUES (1, 'Toxic Chemicals', 120, '2022-01-01');
list the mines in the mining_sites table that have the highest extraction rates, up to a maximum of 3 mines
CREATE TABLE mining_sites (id INT,name VARCHAR(50),location VARCHAR(50),extraction_rate DECIMAL(5,2)); INSERT INTO mining_sites (id,name,location,extraction_rate) VALUES (1,'Gold Mine','California',12.5),(2,'Silver Mine','Nevada',15.2),(3,'Copper Mine','Arizona',18.9),(4,'Iron Mine','Minnesota',21.1);
SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY extraction_rate DESC) rn FROM mining_sites) t WHERE rn <= 3;
What is the total quantity of vegan ingredients used in each dish category?
CREATE TABLE dish(category VARCHAR(255),ingredient VARCHAR(255),quantity INT); INSERT INTO dish(category,ingredient,quantity) VALUES ('Starter','Lettuce',100),('Starter','Tofu',150),('Main','Chickpeas',200),('Main','Tofu',250),('Side','Quinoa',120),('Side','Lettuce',180);
SELECT category, SUM(quantity) as total_vegan_quantity FROM dish WHERE ingredient IN ('Lettuce', 'Tofu', 'Chickpeas') GROUP BY category;
How many first-time attendees were there at each visual arts event, in the past year, broken down by funding source and age group?
CREATE TABLE Events (id INT,date DATE,funding_source VARCHAR(50),event_type VARCHAR(50)); INSERT INTO Events (id,date,funding_source,event_type) VALUES (1,'2021-01-01','Foundation','Exhibition'),(2,'2021-02-01','Corporate','Gallery'); CREATE TABLE Attendance (id INT,event_id INT,is_new_attendee BOOLEAN,age_group VARCHA...
SELECT e.funding_source, a.age_group, COUNT(a.id) AS count FROM Events e INNER JOIN Attendance a ON e.id = a.event_id AND a.is_new_attendee = TRUE WHERE e.date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) AND e.event_type = 'Visual Arts' GROUP BY e.funding_source, a.age_group;
What is the average age of inmates who have participated in restorative justice programs in California prisons?
CREATE TABLE prisons (id INT,state VARCHAR(2)); INSERT INTO prisons (id,state) VALUES (1,'California'); CREATE TABLE inmates (id INT,age INT,prison_id INT); CREATE TABLE restorative_justice_programs (id INT,inmate_id INT);
SELECT AVG(inmates.age) FROM inmates INNER JOIN restorative_justice_programs ON inmates.id = restorative_justice_programs.inmate_id INNER JOIN prisons ON inmates.prison_id = prisons.id WHERE prisons.state = 'California';
What is the total number of trips for route 'Purple Line' in January 2022?
CREATE TABLE routes (id INT,name VARCHAR(50),start_stop_id INT,end_stop_id INT); INSERT INTO routes (id,name,start_stop_id,end_stop_id) VALUES (6,'Purple Line',110,125); CREATE TABLE trips (id INT,start_time TIMESTAMP,end_time TIMESTAMP,passenger_count INT,stop_id INT); INSERT INTO trips (id,start_time,end_time,passeng...
SELECT COUNT(t.id) FROM trips t INNER JOIN routes r ON t.stop_id = r.start_stop_id WHERE r.name = 'Purple Line' AND t.start_time BETWEEN '2022-01-01 00:00:00' AND '2022-01-31 23:59:59';
What green building certifications are not held by companies based in South America?
CREATE TABLE green_buildings (id INT,company_name TEXT,certification TEXT,region TEXT); INSERT INTO green_buildings (id,company_name,certification,region) VALUES (1,'EcoBuild Pte Ltd','LEED','Asia-Pacific'),(2,'GreenTech India','IGBC','Asia-Pacific'),(3,'GreenBuild S.A.','LEED','South America');
SELECT certification FROM green_buildings WHERE region != 'South America';
Find the number of green buildings in each city.
CREATE TABLE green_buildings (building_id INT,city VARCHAR(50)); INSERT INTO green_buildings (building_id,city) VALUES (1,'New York'),(2,'Toronto'),(3,'Mexico City'),(4,'New York'),(5,'Los Angeles');
SELECT city, COUNT(*) FROM green_buildings GROUP BY city
What is the number of products certified by Leaping Bunny?
CREATE TABLE Certifications (ProductID INT,LeapingBunny BOOLEAN); INSERT INTO Certifications (ProductID,LeapingBunny) VALUES (1,TRUE),(2,FALSE),(3,TRUE);
SELECT COUNT(*) FROM Certifications WHERE LeapingBunny = TRUE;
Which policies have been updated in the last 90 days but not in the last 60 days? Provide the output in the format: policy_name, last_updated_date.
CREATE TABLE policies (id INT,policy_name VARCHAR(255),last_updated_date DATE); INSERT INTO policies (id,policy_name,last_updated_date) VALUES (1,'Access Control','2022-01-01'),(2,'Incident Response','2022-03-15'),(3,'Data Privacy','2022-04-10'),(4,'Network Security','2022-06-05');
SELECT policy_name, last_updated_date FROM policies WHERE last_updated_date >= DATE(NOW()) - INTERVAL 90 DAY AND last_updated_date < DATE(NOW()) - INTERVAL 60 DAY;
List the number of employees who have been hired in each month of the year in the 'hr' schema's 'employee_hires' table
CREATE TABLE hr.employee_hires (id INT,employee_id INT,hire_date DATE,job_id VARCHAR(20));
SELECT MONTH(hire_date) AS month, COUNT(*) FROM hr.employee_hires GROUP BY month;
Delete the record with service_id 2 from the 'Public_Services' table
CREATE TABLE Public_Services(service_id INT PRIMARY KEY,service_name VARCHAR(255),location VARCHAR(255),budget FLOAT,created_date DATE); INSERT INTO Public_Services (service_id,service_name,location,budget,created_date) VALUES (1,'Road Maintenance','NYC',5000000.00,'2022-01-01'),(2,'Waste Management','NYC',7000000.00,...
DELETE FROM Public_Services WHERE service_id = 2;
What is the total number of community projects?
CREATE TABLE community_projects (id INT,project_name VARCHAR(50),start_date DATE,end_date DATE); INSERT INTO community_projects (id,project_name,start_date,end_date) VALUES (1,'Library','2019-01-01','2019-12-31'); INSERT INTO community_projects (id,project_name,start_date,end_date) VALUES (2,'Park','2020-01-01','2020-1...
SELECT COUNT(*) FROM community_projects;
List the number of community development initiatives for each state in the 'community_development' table.
CREATE TABLE community_development (state VARCHAR(255),initiative_type VARCHAR(255),initiative_name VARCHAR(255)); INSERT INTO community_development (state,initiative_type,initiative_name) VALUES ('California','Youth Center','Oakland Youth Hub'),('Texas','Library','Austin Public Library');
SELECT state, COUNT(*) FROM community_development GROUP BY state;
What is the number of cases and total revenue for each attorney by region?
CREATE TABLE attorney_region (attorney TEXT,region TEXT); INSERT INTO attorney_region (attorney,region) VALUES ('Smith','boston'),('Johnson','nyc'),('Williams','boston'),('Brown','nyc'); CREATE TABLE attorney_cases (attorney TEXT,cases INT,revenue DECIMAL(10,2)); INSERT INTO attorney_cases (attorney,cases,revenue) VALU...
SELECT attorney_region.region, SUM(attorney_cases.revenue) as total_revenue, SUM(attorney_cases.cases) as case_count FROM attorney_region JOIN attorney_cases ON attorney_region.attorney = attorney_cases.attorney GROUP BY attorney_region.region;
Find the number of events funded by "Arts Council" per city
CREATE TABLE events (event_id INT,event_name VARCHAR(50),city VARCHAR(30),funding_source VARCHAR(30)); INSERT INTO events (event_id,event_name,city,funding_source) VALUES (1,'Theater Play','New York','Arts Council'),(2,'Art Exhibit','Los Angeles','Private Donors');
SELECT city, COUNT(*) as num_events FROM events WHERE funding_source = 'Arts Council' GROUP BY city;
What is the total quantity of traditional art pieces by type?
CREATE TABLE Art (ArtID INT,Type VARCHAR(255),Region VARCHAR(255),Quantity INT); INSERT INTO Art (ArtID,Type,Region,Quantity) VALUES (1,'Painting','Asia',25),(2,'Sculpture','Africa',18),(3,'Textile','South America',30),(4,'Pottery','Europe',20),(5,'Jewelry','North America',12);
SELECT Type, SUM(Quantity) as Total_Quantity FROM Art GROUP BY Type;
Show the number of heritage sites in each country, ordered from the most to the least, along with their respective percentage in relation to the total number of heritage sites.
CREATE TABLE UNESCO_Heritage_Sites (id INT,country VARCHAR(50),site VARCHAR(100)); INSERT INTO UNESCO_Heritage_Sites (id,country,site) VALUES (1,'Italy','Colosseum'),(2,'China','Great Wall'),(3,'Spain','Alhambra');
SELECT country, COUNT(site) as num_sites, ROUND(COUNT(site) * 100.0 / (SELECT COUNT(*) FROM UNESCO_Heritage_Sites), 2) as percentage FROM UNESCO_Heritage_Sites GROUP BY country ORDER BY num_sites DESC;
Show the number of renewable energy sources and the total energy generated by those sources for each region
CREATE TABLE renewable_energy (region VARCHAR(20),source VARCHAR(20),energy_generated INT);
SELECT region, COUNT(source) AS num_sources, SUM(energy_generated) AS total_energy FROM renewable_energy GROUP BY region;
What is the name of the sponsor who has contributed the most to the conservation program with ID 2?
CREATE TABLE Sponsors (SponsorID INT,Name VARCHAR(50),SponsorshipAmount FLOAT,ProgramID INT); INSERT INTO Sponsors (SponsorID,Name,SponsorshipAmount,ProgramID) VALUES (1,'ABC Corporation',10000,1),(2,'XYZ Foundation',15000,2);
SELECT Sponsors.Name FROM Sponsors WHERE Sponsors.ProgramID = 2 ORDER BY Sponsors.SponsorshipAmount DESC LIMIT 1;
What is the average square footage of sustainable buildings in the state of Texas?
CREATE TABLE building_info (info_id INT,sq_footage INT,city TEXT,state TEXT,sustainable BOOLEAN); INSERT INTO building_info VALUES (1,50000,'Seattle','Washington',TRUE),(2,60000,'Houston','Texas',FALSE),(3,70000,'Seattle','Washington',TRUE),(4,40000,'New York','New York',FALSE),(5,80000,'Austin','Texas',TRUE),(6,90000,...
SELECT AVG(sq_footage) FROM building_info WHERE state = 'Texas' AND sustainable = TRUE;
How many resources were allocated to clinics in rural Mississippi in 2020?
CREATE TABLE resources (id INT,clinic_id INT,name VARCHAR(50),quantity INT,allocation_date DATE); INSERT INTO resources (id,clinic_id,name,quantity,allocation_date) VALUES (1,1,'Insulin',100,'2020-01-01');
SELECT SUM(resources.quantity) FROM resources WHERE resources.allocation_date >= '2020-01-01' AND resources.allocation_date < '2021-01-01' AND resources.clinic_id IN (SELECT clinics.id FROM clinics WHERE clinics.region = 'Rural Mississippi');
Get the number of marine reserves established per year, including the year of establishment in the 'reserve_years' table.
CREATE TABLE reserve_years (reserve_id INT,year_established INT);
SELECT year_established, COUNT(*) FROM reserve_years GROUP BY year_established;
Show the number of members who have used wearable technology to track their workouts
CREATE TABLE member_workouts (member_id INT,wearable_tech BOOLEAN);
SELECT COUNT(*) FROM member_workouts WHERE wearable_tech = TRUE;
What is the total area of affordable housing units in the city of Seattle, Washington, broken down by property type?
CREATE TABLE affordable_housing_units (id INT,city VARCHAR(255),property_type VARCHAR(255),area FLOAT); INSERT INTO affordable_housing_units (id,city,property_type,area) VALUES (1,'Seattle','Apartment',800.00),(2,'Seattle','Condo',900.00);
SELECT property_type, SUM(area) FROM affordable_housing_units WHERE city = 'Seattle' GROUP BY property_type;
How many new members joined the community art center in the past month?
CREATE TABLE CommunityArtCenter (memberID INT,joinDate DATE); INSERT INTO CommunityArtCenter (memberID,joinDate) VALUES (4,'2022-04-15'),(5,'2022-04-22'),(6,'2022-04-29');
SELECT COUNT(*) FROM CommunityArtCenter WHERE joinDate >= '2022-04-01' AND joinDate <= '2022-04-30';
List all military equipment sales records where the buyer is "Country B" and the quantity sold is greater than 50, ordered by the equipment type in ascending order.
CREATE TABLE military_sales (id INT PRIMARY KEY,seller VARCHAR(255),buyer VARCHAR(255),equipment_type VARCHAR(255),quantity INT);
SELECT * FROM military_sales WHERE buyer = 'Country B' AND quantity > 50 ORDER BY equipment_type ASC;
How many users watched TV show 'The Crown' per season?
CREATE TABLE tv_shows (id INT,title VARCHAR(255),season INT,user_count INT); INSERT INTO tv_shows (id,title,season,user_count) VALUES (1,'The Crown',1,1000000); INSERT INTO tv_shows (id,title,season,user_count) VALUES (2,'The Crown',2,1200000); INSERT INTO tv_shows (id,title,season,user_count) VALUES (3,'The Mandaloria...
SELECT season, user_count FROM tv_shows WHERE title = 'The Crown';
What is the minimum number of accommodations provided, per country?
CREATE TABLE Accommodations (ID INT PRIMARY KEY,Country VARCHAR(50),AccommodationType VARCHAR(50),Quantity INT); INSERT INTO Accommodations (ID,Country,AccommodationType,Quantity) VALUES (1,'USA','Sign Language Interpretation',300),(2,'Canada','Wheelchair Ramp',250),(3,'Mexico','Assistive Listening Devices',150);
SELECT Country, MIN(Quantity) as Minimum FROM Accommodations GROUP BY Country;
How many artists are in our database from Asia?
CREATE TABLE Artists (ArtistID INT,Name VARCHAR(255),Nationality VARCHAR(255),Genre VARCHAR(255)); INSERT INTO Artists VALUES (8,'Agnez Mo','Indonesian','Pop',); INSERT INTO Artists VALUES (9,'Wang Leehom','Taiwanese-American','Mandopop',);
SELECT COUNT(*) FROM Artists WHERE Nationality = 'Asian';
What is the maximum price of artworks created in the '1920s'?
CREATE TABLE Artworks (id INT,artwork_name VARCHAR(255),year_created INT,price FLOAT); INSERT INTO Artworks (id,artwork_name,year_created,price) VALUES (1,'Composition with Red Blue and Yellow',1930,800000); INSERT INTO Artworks (id,artwork_name,year_created,price) VALUES (2,'The Persistence of Memory',1931,900000); IN...
SELECT MAX(price) FROM Artworks WHERE year_created BETWEEN 1920 AND 1929;
What is the total revenue for each game?
CREATE TABLE Game (GameID INT,GameName VARCHAR(100),Genre VARCHAR(50),Price DECIMAL(5,2)); INSERT INTO Game (GameID,GameName,Genre,Price) VALUES (1,'GameA','Shooter',50.00),(2,'GameB','Strategy',60.00),(3,'GameC','RPG',40.00); CREATE TABLE Sales (SaleID INT,GameID INT,Quantity INT); INSERT INTO Sales (SaleID,GameID,Qua...
SELECT GameID, SUM(Price * Quantity) FROM Game G JOIN Sales S ON G.GameID = S.GameID GROUP BY GameID;
How many mental health parity violations were reported in California, Michigan, and Washington in 2020?
CREATE TABLE MentalHealthParityViolations (Id INT,State VARCHAR(2),Year INT,ViolationCount INT); INSERT INTO MentalHealthParityViolations (Id,State,Year,ViolationCount) VALUES (1,'CA',2020,135),(2,'MI',2020,125),(3,'WA',2020,110),(4,'NY',2019,140),(5,'TX',2019,155);
SELECT State, SUM(ViolationCount) as TotalViolations FROM MentalHealthParityViolations WHERE State IN ('CA', 'MI', 'WA') AND Year = 2020 GROUP BY State;
How many customers in the 'large' size range have made purchases in the last six months?
CREATE TABLE customer_size(customer_id INT,size VARCHAR(10),purchase_date DATE); INSERT INTO customer_size(customer_id,size,purchase_date) VALUES(1,'large','2022-01-05'),(2,'medium','2022-02-10'),(3,'large','2022-03-25');
SELECT COUNT(*) FROM customer_size WHERE size = 'large' AND purchase_date >= DATEADD(month, -6, CURRENT_DATE);
Insert a new record into the "hotels" table with id 102, name "Heritage Hotel", city "Delhi", country "India", and star_rating 5
CREATE TABLE hotels (id INT,name VARCHAR(50),city VARCHAR(50),country VARCHAR(50),star_rating INT);
INSERT INTO hotels VALUES (102, 'Heritage Hotel', 'Delhi', 'India', 5);
What is the total energy efficiency improvement (in percentage) in each sector in Australia?
CREATE TABLE energy_efficiency (id INT,sector VARCHAR(50),improvement FLOAT); INSERT INTO energy_efficiency (id,sector,improvement) VALUES (1,'Industry',5.5),(2,'Transportation',3.2),(3,'Residential',7.1),(4,'Commercial',4.0);
SELECT sector, SUM(improvement) FROM energy_efficiency GROUP BY sector;
Which vessels arrived at the Port of Los Angeles with more than 1000 containers in Q3 2019?
CREATE TABLE vessels (id INT PRIMARY KEY,vessel_name VARCHAR(50)); CREATE TABLE vessel_movements (id INT PRIMARY KEY,vessel_id INT,port VARCHAR(50),arrival_date DATE,containers_unloaded INT,FOREIGN KEY (vessel_id) REFERENCES vessels(id));
SELECT vessel_name FROM vessels INNER JOIN vessel_movements ON vessels.id = vessel_movements.vessel_id WHERE port = 'Port of Los Angeles' AND arrival_date BETWEEN '2019-07-01' AND '2019-09-30' GROUP BY vessel_name HAVING COUNT(*) > 1000;
What is the percentage of students who have received accommodations for visual impairments?
CREATE TABLE students (student_id INT,student_name VARCHAR(255));
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM students)) as percentage FROM student_accommodations SA JOIN visual_impairments VI ON SA.student_id = VI.student_id WHERE SA.accommodation_type = 'Visual Impairment';
What are the average wellhead prices for oil in the North Sea, broken down by country, for the year 2020?
CREATE TABLE north_sea_oil (country VARCHAR(255),wellhead_price DECIMAL(10,2),year INT);
SELECT nso.country, AVG(nso.wellhead_price) FROM north_sea_oil nso WHERE nso.year = 2020 GROUP BY nso.country;
List the names and construction dates of all tunnels in New York
CREATE TABLE Tunnels (id INT,name VARCHAR(50),construction_date DATE); INSERT INTO Tunnels (id,name,construction_date) VALUES (1,'Hudson Tunnel','2010-01-01');
SELECT name, construction_date FROM Tunnels WHERE state = 'New York';
Update the title of a research grant in the "grants" table
CREATE TABLE grants (id INT PRIMARY KEY,title VARCHAR(100),principal_investigator VARCHAR(50),amount NUMERIC,start_date DATE,end_date DATE);
WITH updated_grant AS (UPDATE grants SET title = 'Advanced Quantum Computing' WHERE id = 1 RETURNING *) SELECT * FROM updated_grant;
Add a new property owner to the property_owners table
CREATE TABLE public.property_owners (id SERIAL PRIMARY KEY,property_owner_name VARCHAR(255),property_owner_email VARCHAR(255)); INSERT INTO public.property_owners (property_owner_name,property_owner_email) VALUES ('John Smith','john.smith@example.com'),('Jane Doe','jane.doe@example.com'),('Mary Major','mary.major@examp...
INSERT INTO public.property_owners (property_owner_name, property_owner_email) VALUES ('Mohammad Ahmad', 'mohammad.ahmad@example.com');
What is the earliest founding date for a startup with a female founder?
CREATE TABLE startups (id INT,name TEXT,founding_date DATE,founder_gender TEXT);
SELECT MIN(founding_date) FROM startups WHERE founder_gender = 'Female';
Which levees in Louisiana were built after 2000?
CREATE TABLE Levees(id INT,name TEXT,location TEXT,built DATE); INSERT INTO Levees(id,name,location,built) VALUES (1,'New Orleans East Levee','Louisiana','2006-01-01');
SELECT name FROM Levees WHERE location = 'Louisiana' AND built > '2000-01-01';
What is the total budget allocated to each program in 2021?
CREATE TABLE Programs (ProgramID int,ProgramName varchar(50),Budget decimal(10,2)); INSERT INTO Programs (ProgramID,ProgramName,Budget) VALUES (1,'Education',5000.00),(2,'Health',7000.00);
SELECT ProgramName, SUM(Budget) as TotalBudget FROM Programs WHERE YEAR(ProgramStartDate) = 2021 GROUP BY ProgramName;
Get the number of patents filed per month for a specific year.
CREATE TABLE patents (id INT,title VARCHAR(50),filed_by VARCHAR(50),filed_date DATE,type VARCHAR(50),industry VARCHAR(50));
SELECT EXTRACT(MONTH FROM filed_date) AS month, COUNT(*) FROM patents WHERE industry = 'biotech' AND EXTRACT(YEAR FROM filed_date) = 2020 GROUP BY month;
What is the number of satellite deployments by country and manufacturer in the last 10 years?
CREATE TABLE satellite_deployments (id INT,country VARCHAR(255),manufacturer VARCHAR(255),deployment_date DATE);
SELECT country, manufacturer, COUNT(*) as num_deployments FROM satellite_deployments WHERE deployment_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 10 YEAR) GROUP BY country, manufacturer;
Identify the number of fish farms in each country?
CREATE TABLE fish_farms (id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO fish_farms (id,name,country) VALUES (1,'Farm A','Norway'),(2,'Farm B','Canada'),(3,'Farm C','Norway'),(4,'Farm D','Japan'),(5,'Farm E','Norway'),(6,'Farm F','Philippines');
SELECT country, COUNT(*) FROM fish_farms GROUP BY country;
Add a new record to the "routes" table with the following data: route_id = 5, origin = "Seattle", destination = "New York", distance = 2500, and eta = '2022-07-01'
CREATE TABLE routes (route_id INT,origin VARCHAR(50),destination VARCHAR(50),distance INT,eta DATE);
INSERT INTO routes (route_id, origin, destination, distance, eta) VALUES (5, 'Seattle', 'New York', 2500, '2022-07-01');
Find the top 3 clients with the highest account balance in the West region.
CREATE TABLE clients (client_id INT,name VARCHAR(50),region VARCHAR(20),account_balance DECIMAL(10,2)); INSERT INTO clients (client_id,name,region,account_balance) VALUES (1,'John Smith','West',30000.00),(2,'Jane Doe','Northeast',22000.00),(3,'Mike Johnson','West',35000.00),(4,'Sara Jones','Southeast',12000.00);
SELECT client_id, name, account_balance FROM clients WHERE region = 'West' ORDER BY account_balance DESC LIMIT 3;
Identify legal aid providers offering restorative practice services in the 'legal_aid_practices' and 'restorative_practices' tables?
CREATE TABLE legal_aid (provider_id INT,provider VARCHAR(255),location VARCHAR(255)); CREATE TABLE legal_aid_practices (provider_id INT,practice_id INT); CREATE TABLE restorative_practices (practice_id INT,practice VARCHAR(255));
SELECT legal_aid.provider FROM legal_aid INNER JOIN legal_aid_practices ON legal_aid.provider_id = legal_aid_practices.provider_id INNER JOIN restorative_practices ON legal_aid_practices.practice_id = restorative_practices.practice_id;
Find total timber production in North America by country
CREATE TABLE timber_production (year INT,country VARCHAR(255),region VARCHAR(255),volume FLOAT);
SELECT country, SUM(volume) FROM timber_production WHERE region = 'North America' GROUP BY country;
Identify the top 3 most common disability-related complaints received in the last 6 months?
CREATE TABLE complaints (complaint_id INT,complaint_type VARCHAR(255),date DATE); INSERT INTO complaints (complaint_id,complaint_type,date) VALUES (1,'Physical Barrier','2021-03-15'); INSERT INTO complaints (complaint_id,complaint_type,date) VALUES (2,'Lack of Communication','2021-02-20');
SELECT complaint_type, COUNT(*) as count FROM complaints WHERE date BETWEEN DATE_SUB(NOW(), INTERVAL 6 MONTH) AND NOW() GROUP BY complaint_type ORDER BY count DESC LIMIT 3;
Identify the top 3 crops with the highest production increase between 2015 and 2016 in the 'crop_production' table.
CREATE TABLE crop_production (crop_variety VARCHAR(255),year INT,production FLOAT); INSERT INTO crop_production (crop_variety,year,production) VALUES ('CropVarietyA',2015,1200.5),('CropVarietyA',2016,1500.7),('CropVarietyB',2015,1800.9),('CropVarietyB',2016,2000.2),('CropVarietyC',2015,800.0),('CropVarietyC',2016,900.0...
SELECT cp1.crop_variety, (cp2.production - cp1.production) as production_increase FROM crop_production cp1 INNER JOIN crop_production cp2 ON cp1.crop_variety = cp2.crop_variety WHERE cp1.year = 2015 AND cp2.year = 2016 ORDER BY production_increase DESC LIMIT 3;
Who are the top 5 suppliers for cosmetic products that are certified organic?
CREATE TABLE products (product_id INT,product_name TEXT,supplier_id INT,certified TEXT); INSERT INTO products (product_id,product_name,supplier_id,certified) VALUES (1,'Lipstick A',1001,'organic'),(2,'Eye Shadow B',1002,'vegan'),(3,'Mascara C',1001,'organic'),(4,'Foundation D',1003,'cruelty-free'),(5,'Blush E',1004,'or...
SELECT s.supplier_name, COUNT(p.product_id) AS product_count FROM suppliers s JOIN products p ON s.supplier_id = p.supplier_id WHERE p.certified = 'organic' GROUP BY s.supplier_name ORDER BY product_count DESC LIMIT 5;
What is the maximum depth reached by a marine research mission?
CREATE TABLE marine_research_missions (id INT,mission_name TEXT,mission_depth FLOAT); INSERT INTO marine_research_missions (id,mission_name,mission_depth) VALUES (1,'Mission Alpha',4000.1),(2,'Mission Bravo',3500.5),(3,'Mission Charlie',5000.7);
SELECT MAX(mission_depth) FROM marine_research_missions;
What is the total oil production for offshore platforms in the Gulf of Mexico?
CREATE TABLE offshore_platforms (platform_id INT,platform_name VARCHAR(50),location VARCHAR(50),operational_status VARCHAR(15)); INSERT INTO offshore_platforms VALUES (1,'Gulfstar','Gulf of Mexico','Active'); INSERT INTO offshore_platforms VALUES (2,'Atlantis','Gulf of Mexico','Active'); CREATE TABLE oil_production (pl...
SELECT SUM(production) FROM oil_production JOIN offshore_platforms ON oil_production.platform_id = offshore_platforms.platform_id WHERE offshore_platforms.location = 'Gulf of Mexico';
Which cricket team has the most World Cup titles?
CREATE TABLE cricket_world_cup (year INT,winner VARCHAR(50)); INSERT INTO cricket_world_cup (year,winner) VALUES (1975,'West Indies'); INSERT INTO cricket_world_cup (year,winner) VALUES (1979,'West Indies');
SELECT winner FROM cricket_world_cup WHERE (SELECT COUNT(*) FROM cricket_world_cup WHERE winner = (SELECT winner FROM cricket_world_cup WHERE year = 1975)) > (SELECT COUNT(*) FROM cricket_world_cup WHERE winner = (SELECT winner FROM cricket_world_cup WHERE year = 1992));
What is the total CO2 offset for each carbon offset project?
CREATE TABLE CarbonOffsetProjects (id INT,name VARCHAR(50),co2_offset FLOAT); INSERT INTO CarbonOffsetProjects (id,name,co2_offset) VALUES (1,'ProjectA',1000),(2,'ProjectB',2000),(3,'ProjectC',3000);
SELECT name, SUM(co2_offset) FROM CarbonOffsetProjects GROUP BY name;
What is the average ticket price for each team, split by sport?
CREATE TABLE ticket_prices (ticket_id INT,team_id INT,sport_id INT,avg_ticket_price DECIMAL(10,2)); CREATE TABLE teams (team_id INT,team_name VARCHAR(255),sport_id INT); CREATE TABLE sports (sport_id INT,sport_name VARCHAR(255)); INSERT INTO ticket_prices VALUES (1,101,1,75.00),(2,102,2,100.00),(3,101,1,85.00),(4,103,3...
SELECT sp.sport_name, t.team_name, tp.avg_ticket_price FROM ticket_prices tp JOIN teams t ON tp.team_id = t.team_id JOIN sports sp ON t.sport_id = sp.sport_id;
What is the maximum number of 'silver' reserves?
CREATE TABLE reserves_summary (id INT,metal VARCHAR(10),max_quantity INT); INSERT INTO reserves_summary (id,metal,max_quantity) VALUES (1,'gold',1000),(2,'silver',750),(3,'copper',900);
SELECT MAX(max_quantity) FROM reserves_summary WHERE metal = 'silver';
What is the total snowfall per year for the past 5 years?
CREATE TABLE SnowfallData (id INT,year INT,month INT,snowfall FLOAT); INSERT INTO SnowfallData (id,year,month,snowfall) VALUES (1,2017,1,15.2),(2,2017,2,13.5),(3,2017,3,16.3);
SELECT year, SUM(snowfall) FROM SnowfallData WHERE year IN (2017, 2018, 2019, 2020, 2021) GROUP BY year;
Find the maximum and minimum temperature in the Canadian Arctic in the year 2021
CREATE TABLE WeatherData (location VARCHAR(255),temperature INT,time DATETIME); INSERT INTO WeatherData (location,temperature,time) VALUES ('Canadian Arctic',10,'2021-01-01 00:00:00'); INSERT INTO WeatherData (location,temperature,time) VALUES ('Canadian Arctic',12,'2021-01-02 00:00:00');
SELECT MAX(temperature) as max_temp, MIN(temperature) as min_temp FROM WeatherData WHERE location = 'Canadian Arctic' AND YEAR(time) = 2021;
Which country hosted the most eSports events in 2023?
CREATE TABLE Events (EventID INT,Name VARCHAR(50),Country VARCHAR(50),StartDate DATE,EndDate DATE); INSERT INTO Events (EventID,Name,Country,StartDate,EndDate) VALUES (1,'Evo','USA','2023-08-04','2023-08-06'); INSERT INTO Events (EventID,Name,Country,StartDate,EndDate) VALUES (2,'DreamHack','Sweden','2023-06-16','2023-...
SELECT Country, COUNT(*) as NumEvents FROM Events WHERE YEAR(StartDate) = 2023 GROUP BY Country ORDER BY NumEvents DESC LIMIT 1;
How many investments were made using each investment strategy?
CREATE TABLE Investments (InvestmentID INT,StrategyID INT); INSERT INTO Investments (InvestmentID,StrategyID) VALUES (1,1),(2,1),(3,2),(4,2),(5,3),(6,3),(7,4),(8,4),(9,1),(10,2); CREATE TABLE InvestmentStrategies (StrategyID INT,StrategyName VARCHAR(20)); INSERT INTO InvestmentStrategies (StrategyID,StrategyName) VALUE...
SELECT StrategyName, COUNT(*) as NumberOfInvestments FROM Investments JOIN InvestmentStrategies ON Investments.StrategyID = InvestmentStrategies.StrategyID GROUP BY StrategyName;
Identify customers who have both checking and credit card accounts, and determine the total balance for each customer's checking and credit card accounts.
CREATE TABLE accounts_4 (id INT,customer_id INT,type VARCHAR(255),balance DECIMAL(10,2)); INSERT INTO accounts_4 (id,customer_id,type,balance) VALUES (1,1,'Checking',5000.00),(2,1,'Credit Card',2000.00),(3,2,'Checking',2000.00),(4,3,'Credit Card',8000.00);
SELECT a1.customer_id, SUM(a1.balance + a2.balance) as total_balance FROM accounts_4 a1 JOIN accounts_4 a2 ON a1.customer_id = a2.customer_id WHERE a1.type = 'Checking' AND a2.type = 'Credit Card' GROUP BY a1.customer_id;
What was the total amount of donations received in 2019, categorized by donation type and month?
CREATE TABLE Donations (donation_id INT,donation_type VARCHAR(20),amount INT,year INT,month INT); INSERT INTO Donations (donation_id,donation_type,amount,year,month) VALUES (1,'Individual',50,2019,1),(2,'Corporate',1000,2019,1),(3,'Individual',75,2019,2),(4,'Corporate',1200,2019,2),(5,'Foundation',5000,2019,3),(6,'Indi...
SELECT donation_type, month, SUM(amount) FROM Donations WHERE year = 2019 GROUP BY donation_type, month;
How many unique genres of music are there in the database?
CREATE TABLE Songs (SongID INT,SongName VARCHAR(100),Genre VARCHAR(50),Country VARCHAR(50)); INSERT INTO Songs VALUES (1,'Song1','Pop','USA'); INSERT INTO Songs VALUES (2,'Song2','Pop','Canada'); INSERT INTO Songs VALUES (3,'Song3','Rock','USA');
SELECT COUNT(DISTINCT Genre) FROM Songs;
List the impact categories and the number of investments made in each category.
CREATE TABLE impact_categories (category_id INT,category_name TEXT); CREATE TABLE investments (investment_id INT,category_id INT);
SELECT category_name, COUNT(*) FROM impact_categories i JOIN investments j ON i.category_id = j.category_id GROUP BY category_name;
Show all records from the Inventory table where the item_name is 'Apples' or 'Bananas'
CREATE TABLE Inventory (item_id INT,item_name VARCHAR(50),quantity INT,warehouse_id INT);
SELECT * FROM Inventory WHERE item_name IN ('Apples', 'Bananas');
Delete music platform with id 2 from the music_platforms table
CREATE TABLE music_platforms (id INT,platform_name VARCHAR(50));
DELETE FROM music_platforms WHERE id = 2;
How many hospitals are there in rural California with fewer than 50 beds?
CREATE TABLE hospitals (id INT,name VARCHAR(255),num_beds INT,rural BOOLEAN,state VARCHAR(255)); INSERT INTO hospitals (id,name,num_beds,rural,state) VALUES (1,'Hospital A',40,true,'California'); INSERT INTO hospitals (id,name,num_beds,rural,state) VALUES (2,'Hospital B',75,false,'California');
SELECT COUNT(*) FROM hospitals WHERE num_beds < 50 AND rural = true AND state = 'California';
How many transactions were made in each month for the last year?
CREATE TABLE transactions (id INT,customer_id INT,transaction_date DATE,amount DECIMAL(10,2)); INSERT INTO transactions (id,customer_id,transaction_date,amount) VALUES (1,1,'2023-02-14',100.00),(2,2,'2023-02-15',200.00),(3,1,'2022-12-31',150.00);
SELECT MONTH(transaction_date), COUNT(*) FROM transactions WHERE transaction_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY MONTH(transaction_date);
Update the number of local employees for a cultural heritage site
CREATE TABLE heritage_site_employment (id INT PRIMARY KEY,site_id INT,local_employment INT);
UPDATE heritage_site_employment SET local_employment = 25 WHERE site_id = 1;
What is the publication rate of graduate students in the Art department?
CREATE TABLE students (id INT,name VARCHAR(100),department VARCHAR(50),publication_count INT); INSERT INTO students VALUES (1,'Taylor Brown','Art',1);
SELECT department, AVG(publication_count) FROM students WHERE department = 'Art' GROUP BY department;
Which artists have released songs both in the Pop and Rock genres?
CREATE TABLE Artists (ArtistID INT,ArtistName VARCHAR(100),Genre VARCHAR(50)); INSERT INTO Artists (ArtistID,ArtistName,Genre) VALUES (1,'Taylor Swift','Pop'); INSERT INTO Artists (ArtistID,ArtistName,Genre) VALUES (2,'Green Day','Rock');
SELECT ArtistName FROM Artists WHERE Genre = 'Pop' INTERSECT SELECT ArtistName FROM Artists WHERE Genre = 'Rock';
Find the number of unique donors who made a donation in each month of 2022.
CREATE TABLE donations (id INT,donor_id INT,donation_amount DECIMAL(10,2),donation_date DATE); INSERT INTO donations (id,donor_id,donation_amount,donation_date) VALUES (1,1,500.00,'2022-01-01'),(2,2,300.00,'2022-01-15'),(3,1,200.00,'2022-02-01');
SELECT EXTRACT(MONTH FROM donation_date) as month, COUNT(DISTINCT donor_id) as num_donors FROM donations WHERE donation_date >= '2022-01-01' AND donation_date <= '2022-12-31' GROUP BY month ORDER BY month;
What is the production rate trend for each well over the past month?
CREATE TABLE Production (ProductionID INT,WellID INT,ProductionDate DATE,ProductionRate FLOAT,Country VARCHAR(50)); INSERT INTO Production (ProductionID,WellID,ProductionDate,ProductionRate,Country) VALUES (1,1,'2022-01-01',500,'USA'),(2,2,'2022-01-15',600,'Canada'),(3,3,'2022-02-01',700,'Mexico');
SELECT WellID, ProductionDate, ProductionRate, ROW_NUMBER() OVER (PARTITION BY WellID ORDER BY ProductionDate DESC) AS RowNumber FROM Production WHERE ProductionDate >= DATEADD(month, -1, GETDATE());
What is the total attendance by age group, for music events in Berlin, in the last 3 months?
CREATE TABLE Events (id INT,event_name VARCHAR(100),event_type VARCHAR(50),location VARCHAR(100),start_time TIMESTAMP,end_time TIMESTAMP); CREATE TABLE Attendees (id INT,attendee_age INT,event_id INT);
SELECT attendee_age_group, SUM(attendance) as total_attendance FROM (SELECT attendee_age AS attendee_age_group, COUNT(*) AS attendance FROM Attendees JOIN Events ON Attendees.event_id = Events.id WHERE Events.event_type = 'music' AND Events.location LIKE '%Berlin%' AND start_time >= NOW() - INTERVAL '3 months' GROUP BY...
What is the average number of construction labor hours worked per worker in Michigan in 2019?
CREATE TABLE labor_hours (employee_id INT,state VARCHAR(2),year INT,hours INT); INSERT INTO labor_hours (employee_id,state,year,hours) VALUES (1,'MI',2019,2000); CREATE TABLE employment (employee_id INT,industry VARCHAR(20),state VARCHAR(2),year INT,employed INT); INSERT INTO employment (employee_id,industry,state,year...
SELECT AVG(hours/employed) FROM labor_hours, employment WHERE labor_hours.employee_id = employment.employee_id AND state = 'MI' AND year = 2019;
What is the total quantity of unsold garments for each country where the manufacturer is based, grouped by country and ordered by total quantity in descending order?
CREATE TABLE manufacturers (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255)); INSERT INTO manufacturers (id,name,country) VALUES (1,'ABC Garments','India'),(2,'XYZ Fashion','Bangladesh'),(3,'MNO Clothing','Vietnam'); CREATE TABLE garments (id INT PRIMARY KEY,manufacturer_id INT,quantity_manufactured INT,quant...
SELECT country, SUM(quantity_manufactured - quantity_sold) as total_unsold_quantity FROM garments JOIN manufacturers ON garments.manufacturer_id = manufacturers.id GROUP BY country ORDER BY total_unsold_quantity DESC;
Which locations in Australia had the highest drought impact in the last 5 years?
CREATE TABLE drought_impact_australia(id INT,location VARCHAR(50),impact FLOAT,year INT); INSERT INTO drought_impact_australia(id,location,impact,year) VALUES (1,'Melbourne',22.3,2019);
SELECT location, MAX(impact) as max_impact FROM drought_impact_australia WHERE year BETWEEN (SELECT MAX(year) - 5 FROM drought_impact_australia) AND MAX(year) GROUP BY location ORDER BY max_impact DESC;
What are the total tons of silver mined by each country in Q1 2021?
CREATE TABLE mines (country VARCHAR(50),mineral VARCHAR(50),tons FLOAT,date DATE); INSERT INTO mines (country,mineral,tons,date) VALUES ('Mexico','Silver',120,'2021-01-01'),('Peru','Silver',150,'2021-01-01'),('Chile','Silver',90,'2021-01-01'),('Mexico','Silver',130,'2021-02-01'),('Peru','Silver',160,'2021-02-01'),('Chi...
SELECT country, SUM(tons) as total_tons FROM mines WHERE mineral = 'Silver' AND YEAR(date) = 2021 AND QUARTER(date) = 1 GROUP BY country;
How many employees have completed diversity and inclusion training in the Marketing department?
CREATE TABLE Employees (EmployeeID int,Name varchar(50),Department varchar(50)); CREATE TABLE Training (TrainingID int,EmployeeID int,TrainingName varchar(50),CompletedDate date); CREATE TABLE TrainingCategories (TrainingID int,Category varchar(50)); INSERT INTO Employees (EmployeeID,Name,Department) VALUES (1,'John Do...
SELECT COUNT(*) FROM Employees e JOIN Training t ON e.EmployeeID = t.EmployeeID JOIN TrainingCategories tc ON t.TrainingID = tc.TrainingID WHERE e.Department = 'Marketing' AND tc.Category = 'Diversity and Inclusion';
Show market access strategies
CREATE TABLE reimbursement_rates (drug_name VARCHAR(255),reimbursement_status VARCHAR(255));
SELECT * FROM market_access_strategies;
What is the percentage of recyclable waste that was actually recycled in Australia in 2020?
CREATE TABLE waste_generation (country VARCHAR(50),year INT,total_waste FLOAT,recyclable_waste FLOAT,recycled_waste FLOAT); INSERT INTO waste_generation (country,year,total_waste,recyclable_waste,recycled_waste) VALUES ('Australia',2020,150,75,60);
SELECT recycled_waste / recyclable_waste * 100 AS percentage_recycled FROM waste_generation WHERE country = 'Australia' AND year = 2020;
Add a new record to the "military_equipment" table with the following information: (4, 'artillery', 18)
CREATE TABLE military_equipment (id INT,equipment_name VARCHAR(50),quantity INT); INSERT INTO military_equipment (id,equipment_name,quantity) VALUES (1,'tank',20),(2,'fighter_jet',12),(3,'humvee',8);
INSERT INTO military_equipment (id, equipment_name, quantity) VALUES (4, 'artillery', 18);
Select the location and average yield of the fields with a size greater than 5000 square meters
CREATE TABLE PrecisionAgriculture.HarvestYield (FieldID INT,Yield FLOAT,HarvestDate DATE); CREATE TABLE PrecisionAgriculture.FieldDetails (FieldID INT,FieldSize FLOAT,Location VARCHAR(255));
SELECT fd.Location, AVG(hy.Yield) FROM PrecisionAgriculture.FieldDetails fd INNER JOIN PrecisionAgriculture.HarvestYield hy ON fd.FieldID = hy.FieldID WHERE fd.FieldSize > 5000 GROUP BY fd.Location;
List the names of all donors who have donated more than $500 in total from the 'Donors' table.
CREATE TABLE Donors (DonorID int,Name varchar(50),TotalDonation numeric); INSERT INTO Donors (DonorID,Name,TotalDonation) VALUES (1,'John Doe',500),(2,'Jane Smith',800),(3,'Michael Lee',300),(4,'Sophia Chen',600);
SELECT Name FROM Donors WHERE TotalDonation > 500;
Identify the top 5 cities with the most registered users in Europe, returning city name, country, and number of users.
CREATE TABLE europe_users (id INT,name VARCHAR(255),city VARCHAR(255),country VARCHAR(255)); INSERT INTO europe_users (id,name,city,country) VALUES (1,'Jan Kowalski','Warsaw','Poland'),(2,'Marie Dubois','Paris','France');
SELECT city, country, COUNT(*) as num_users FROM europe_users GROUP BY city, country ORDER BY num_users DESC LIMIT 5;
Which regions have the highest VR set adoption rates?
CREATE TABLE Region_VR_Adoption (Region VARCHAR(20),VR_Users INT,Total_Users INT); INSERT INTO Region_VR_Adoption (Region,VR_Users,Total_Users) VALUES ('North America',5000,10000),('Europe',7000,15000),('Asia',8000,20000),('South America',3000,12000),('Africa',1000,5000);
SELECT Region, (VR_Users * 100.0 / Total_Users) AS Adoption_Rate FROM Region_VR_Adoption;
What is the average hotel star rating for eco-friendly hotels in Australia?
CREATE TABLE hotels (hotel_id INT,name TEXT,country TEXT,stars FLOAT,is_eco_friendly BOOLEAN);
SELECT AVG(stars) FROM hotels WHERE country = 'Australia' AND is_eco_friendly = TRUE;
What is the total quantity of items sold in the transparency_sales table where the supplier is based in Africa?
CREATE TABLE transparency_sales (sale_id INT,product_id INT,supplier_id INT,sale_quantity INT); INSERT INTO transparency_sales (sale_id,product_id,supplier_id,sale_quantity) VALUES (1,1,101,30),(2,2,102,50),(3,3,103,25); CREATE TABLE suppliers (supplier_id INT,supplier_name TEXT,country TEXT); INSERT INTO suppliers (su...
SELECT SUM(sale_quantity) FROM transparency_sales JOIN suppliers ON transparency_sales.supplier_id = suppliers.supplier_id WHERE suppliers.country = 'Kenya';
What are the names and languages of all heritage sites in the 'Africa' region?
CREATE TABLE heritage_sites (id INT,name VARCHAR(50),location VARCHAR(50),language VARCHAR(50)); INSERT INTO heritage_sites (id,name,location,language) VALUES (1,'Giza Pyramids','Egypt','Ancient Egyptian');
SELECT name, language FROM heritage_sites WHERE location = 'Africa';