instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the average size of small-scale organic farms in hectares, grouped by country and only considering farms with more than 50 farms?
CREATE TABLE organic_farms (id INT,name VARCHAR(255),size FLOAT,country VARCHAR(255)); INSERT INTO organic_farms (id,name,size,country) VALUES (1,'Farm A',12.5,'USA'),(2,'Farm B',20.0,'Canada'),(3,'Farm C',5.5,'Mexico');
SELECT country, AVG(size) as avg_size FROM organic_farms GROUP BY country HAVING COUNT(*) > 50;
How many episodes of each TV show are there in the "episodes" table?
CREATE TABLE tv_shows (id INT,name VARCHAR(100)); CREATE TABLE episodes (id INT,tv_show_id INT,season_number INT,episode_number INT); INSERT INTO tv_shows (id,name) VALUES (1,'Show1'),(2,'Show2'); INSERT INTO episodes (id,tv_show_id,season_number,episode_number) VALUES (1,1,1,1),(2,1,1,2),(3,2,1,1);
SELECT tv_shows.name, COUNT(episodes.id) FROM tv_shows INNER JOIN episodes ON tv_shows.id = episodes.tv_show_id GROUP BY tv_shows.name;
What is the total cost of projects that started in the first quarter of 2022?
CREATE TABLE construction_projects (project_name TEXT,start_date DATE,end_date DATE,total_cost FLOAT); INSERT INTO construction_projects (project_name,start_date,end_date,total_cost) VALUES ('Solar Panel Installation','2022-02-15','2022-03-31',12000.0),('Green Building Demo','2022-04-01','2022-07-31',150000.0);
SELECT SUM(total_cost) FROM construction_projects WHERE start_date >= '2022-01-01' AND start_date < '2022-04-01';
What is the average amount of climate finance provided to projects in Africa for renewable energy by the Climate and Clean Air Coalition?
CREATE TABLE climate_and_clean_air_coalition (fund_id INT,project_name VARCHAR(100),country VARCHAR(50),sector VARCHAR(50),amount FLOAT,renewable_energy_flag BOOLEAN); INSERT INTO climate_and_clean_air_coalition (fund_id,project_name,country,sector,amount,renewable_energy_flag) VALUES (1,'Solar Power Africa','Africa','...
SELECT AVG(amount) FROM climate_and_clean_air_coalition WHERE country = 'Africa' AND sector = 'Energy' AND renewable_energy_flag = TRUE;
Show the number of workers who have worked on projects in each state, excluding states with no construction projects.
CREATE TABLE project_locations (project_id INT,city TEXT,state TEXT); CREATE TABLE construction_workers (worker_id INT,name TEXT); CREATE TABLE worker_projects (worker_id INT,project_id INT); INSERT INTO project_locations (project_id,city,state) VALUES (1,'Seattle','Washington'),(2,'Houston','Texas'),(3,'Los Angeles','...
SELECT project_locations.state, COUNT(DISTINCT worker_projects.worker_id) FROM worker_projects INNER JOIN project_locations ON worker_projects.project_id = project_locations.project_id GROUP BY project_locations.state HAVING COUNT(DISTINCT worker_projects.project_id) > 0 ORDER BY COUNT(DISTINCT worker_projects.worker_i...
Update the name of the regulatory framework with id 1 to 'EU General Data Protection Regulation'.
CREATE TABLE regulatory_framework (id INT,name VARCHAR(255)); INSERT INTO regulatory_framework (id,name) VALUES (1,'EU GDPR'),(2,'US CFTC'),(3,'Japan FSA');
UPDATE regulatory_framework SET name = 'EU General Data Protection Regulation' WHERE id = 1;
Identify the total number of military equipment maintenance requests and associated costs for the top 5 countries with the most requests
CREATE TABLE military_equipment (equipment_id INT,country VARCHAR(50)); CREATE TABLE maintenance_requests (request_id INT,equipment_id INT,request_date DATE,cost FLOAT);
SELECT m.country, COUNT(mr.request_id) AS num_requests, SUM(mr.cost) AS total_cost FROM military_equipment m JOIN maintenance_requests mr ON m.equipment_id = mr.equipment_id GROUP BY m.country ORDER BY num_requests DESC LIMIT 5;
Find all vendors in France that sell both fair trade and organic products.
CREATE TABLE Vendors (VendorID INT,VendorName TEXT,Country TEXT);CREATE TABLE Products (ProductID INT,ProductName TEXT,Price DECIMAL,Organic BOOLEAN,FairTrade BOOLEAN,VendorID INT); INSERT INTO Vendors VALUES (1,'VendorB','France'); INSERT INTO Products VALUES (1,'Coffee',7.5,true,true,1),(2,'Tea',3.5,false,true,1),(3,...
SELECT v.VendorName FROM Vendors v JOIN Products p ON v.VendorID = p.VendorID WHERE v.Country = 'France' AND p.Organic = true AND p.FairTrade = true GROUP BY v.VendorName HAVING COUNT(DISTINCT p.ProductID) > 1;
How many albums were released in each year?
CREATE TABLE Album (AlbumID INT,ReleaseYear INT,GenreID INT); INSERT INTO Album (AlbumID,ReleaseYear,GenreID) VALUES (1,2010,1),(2,2011,1),(3,2012,2),(4,2013,2),(5,2014,3);
SELECT ReleaseYear, COUNT(*) OVER (PARTITION BY ReleaseYear) AS AlbumCount FROM Album;
What is the average response time for medical emergencies in Chicago?"
CREATE TABLE medical_emergencies (id INT,incident_type VARCHAR(255),city VARCHAR(255),response_time INT,incident_date DATE); INSERT INTO medical_emergencies (id,incident_type,city,response_time,incident_date) VALUES (1,'Medical','Chicago',7,'2022-01-15');
SELECT AVG(response_time) as avg_response_time FROM medical_emergencies WHERE city = 'Chicago' AND incident_type = 'Medical';
Delete records of humanitarian aid with a specific aid_name in the humanitarian_aid table.
CREATE TABLE humanitarian_aid (id INT PRIMARY KEY,aid_name VARCHAR(50),recipient_country VARCHAR(50),amount_donated DECIMAL(10,2)); INSERT INTO humanitarian_aid (id,aid_name,recipient_country,amount_donated) VALUES (5,'Medical Aid','Afghanistan',250000.00),(6,'Food Aid','Afghanistan',300000.00);
WITH del_data AS (DELETE FROM humanitarian_aid WHERE aid_name = 'Medical Aid' RETURNING *) DELETE FROM humanitarian_aid WHERE id IN (SELECT id FROM del_data);
Find the total quantity of sustainable fabric used by the 'Green Garments' brand in the 'Textiles' table.
CREATE TABLE Textiles (brand VARCHAR(20),fabric_type VARCHAR(20),quantity INT); INSERT INTO Textiles (brand,fabric_type,quantity) VALUES ('Eco-friendly Fashions','Organic Cotton',1500),('Eco-friendly Fashions','Recycled Polyester',2000),('Fab Fashions','Viscose',1200),('Fab Fashions','Recycled Polyester',1000),('Fab Fa...
SELECT SUM(quantity) FROM Textiles WHERE brand = 'Green Garments';
Update the 'principle' column to 'Transparency' for 'IBM' in the 'ai_ethics' table
CREATE TABLE ai_ethics (developer VARCHAR(255),principle VARCHAR(255)); INSERT INTO ai_ethics (developer,principle) VALUES ('IBM','Fairness'),('Google','Accountability'),('IBM','Transparency');
UPDATE ai_ethics SET principle = 'Transparency' WHERE developer = 'IBM';
What is the average release year of shows in the shows table, excluding shows with a runtime of less than 30 minutes?
CREATE TABLE shows (id INT,title VARCHAR(100),genre VARCHAR(50),country VARCHAR(50),release_year INT,runtime INT);
SELECT AVG(release_year) FROM shows WHERE runtime >= 30;
Find the buildings certified by the same type as 'GreenBuilding3'
CREATE TABLE building_certifications (id INT,name VARCHAR(255),certification_type VARCHAR(255)); INSERT INTO building_certifications (id,name,certification_type) VALUES (1,'GreenBuilding1','LEED'),(2,'GreenBuilding2','BREEAM'),(3,'GreenBuilding3','WELL');
SELECT name FROM building_certifications WHERE certification_type = (SELECT certification_type FROM building_certifications WHERE name = 'GreenBuilding3');
List the regulatory frameworks in place for the 'NFT' sector.
CREATE TABLE regulatory_frameworks (framework_id INT,framework_name VARCHAR(255),sector VARCHAR(255)); INSERT INTO regulatory_frameworks (framework_id,framework_name,sector) VALUES (1,'Regulation1','NFT'),(2,'Regulation2','NFT'),(3,'Regulation3','Traditional Finance');
SELECT framework_name FROM regulatory_frameworks WHERE sector = 'NFT';
What is the average cultural competency score for healthcare providers by city?
CREATE TABLE healthcare_providers (provider_id INT,name TEXT,city TEXT,state TEXT,score INT); INSERT INTO healthcare_providers (provider_id,name,city,state,score) VALUES (1,'Dr. Smith','San Francisco','CA',90),(2,'Dr. Johnson','Los Angeles','CA',85),(3,'Dr. Rodriguez','Houston','TX',95),(4,'Dr. Lee','New York','NY',80)...
SELECT city, AVG(score) FROM healthcare_providers GROUP BY city;
Who are the top 5 donors by total donation amount in 2021?
CREATE TABLE Donors (DonorID INT,DonorName TEXT,Country TEXT); INSERT INTO Donors (DonorID,DonorName,Country) VALUES (1,'John Doe','USA'); INSERT INTO Donors (DonorID,DonorName,Country) VALUES (2,'Jane Smith','Canada'); CREATE TABLE Donations (DonationID INT,DonorID INT,DonationAmount DECIMAL,DonationDate DATE); INSERT...
SELECT DonorName, SUM(Donations.DonationAmount) AS TotalDonationAmount FROM Donors INNER JOIN Donations ON Donors.DonorID = Donations.DonorID GROUP BY DonorName ORDER BY TotalDonationAmount DESC LIMIT 5;
Update the country for all players who live in 'United States' to 'USA'?
CREATE TABLE players (id INT,name VARCHAR(100),country VARCHAR(100)); INSERT INTO players (id,name,country) VALUES (1,'John Doe','United States'),(2,'Jane Smith','Canada'),(3,'Alex Brown','United States');
UPDATE players SET country = 'USA' WHERE country = 'United States';
How many rocky exoplanets were discovered by NASA before 2015?
CREATE TABLE Exoplanets (ExoplanetId INT,PlanetName VARCHAR(50),DiscoveryDate DATE,StarName VARCHAR(50),PlanetType VARCHAR(50)); INSERT INTO Exoplanets (ExoplanetId,PlanetName,DiscoveryDate,StarName,PlanetType) VALUES (5,'Kepler-10b','2011-01-10','Kepler-10','Rocky');
SELECT COUNT(*) FROM Exoplanets WHERE PlanetType = 'Rocky' AND DiscoveryDate < '2015-01-01' AND StarName = 'NASA';
How many fish were harvested in the OceanicFarm table for May 2022?
CREATE TABLE OceanicFarm (date DATE,fish_harvested INT); INSERT INTO OceanicFarm (date,fish_harvested) VALUES ('2022-05-01',120),('2022-05-02',150),('2022-05-03',180);
SELECT SUM(fish_harvested) FROM OceanicFarm WHERE MONTH(date) = 5 AND YEAR(date) = 2022;
Which artifacts have a quantity greater than the average?
CREATE TABLE Artifacts (ArtifactID INT,ArtifactType VARCHAR(50),Quantity INT); INSERT INTO Artifacts (ArtifactID,ArtifactType,Quantity) VALUES (1,'Pottery',25),(2,'Tools',12),(3,'Pottery',30);
SELECT ArtifactID, ArtifactType, Quantity FROM (SELECT ArtifactID, ArtifactType, Quantity, AVG(Quantity) OVER () AS AvgQuantity FROM Artifacts) AS Subquery WHERE Quantity > AvgQuantity;
What is the difference in average customer spending between customers in Japan and South Korea?
CREATE TABLE CustomerSpendingJP (CustomerID INT,Country TEXT,AvgSpending DECIMAL(5,2)); INSERT INTO CustomerSpendingJP (CustomerID,Country,AvgSpending) VALUES (1,'Japan',120.50),(2,'Japan',110.50),(3,'Japan',130.50),(4,'Japan',90.50); CREATE TABLE CustomerSpendingKR (CustomerID INT,Country TEXT,AvgSpending DECIMAL(5,2)...
SELECT AVG(CSJP.AvgSpending) - AVG(CSKR.AvgSpending) FROM CustomerSpendingJP CSJP, CustomerSpendingKR CSKR WHERE CSJP.Country = 'Japan' AND CSKR.Country = 'South Korea';
What is the minimum temperature (in Kelvin) recorded by the Voyager 1 probe?
CREATE TABLE probes (id INT,name VARCHAR(50),launch_date DATE,current_location VARCHAR(50),max_temperature FLOAT,min_temperature FLOAT);
SELECT MIN(min_temperature) FROM probes WHERE name = 'Voyager 1';
What is the total number of workers in construction labor statistics for the state of Texas for the year 2021?
CREATE TABLE labor_statistics (state TEXT,year INTEGER,workers INTEGER,hours_worked INTEGER);INSERT INTO labor_statistics (state,year,workers,hours_worked) VALUES ('Texas',2021,1500,900000),('Texas',2021,2000,1200000);
SELECT SUM(workers) FROM labor_statistics WHERE state = 'Texas' AND year = 2021;
Update the depth of the 'Galapagos Islands' marine protected area to 3000 meters
CREATE TABLE marine_protected_areas (name VARCHAR(255),depth FLOAT); INSERT INTO marine_protected_areas (name,depth) VALUES ('Galapagos Islands',2000.0),('Great Barrier Reef',500.0);
UPDATE marine_protected_areas SET depth = 3000 WHERE name = 'Galapagos Islands';
What is the average transaction volume for each decentralized application in the last 30 days?
CREATE TABLE transactions (tx_id INT,app_id INT,transaction_volume DECIMAL(10,2),transaction_date DATE); CREATE TABLE decentralized_applications (app_id INT,name VARCHAR(255));
SELECT app_id, name, AVG(transaction_volume) OVER (PARTITION BY app_id) as avg_transaction_volume FROM transactions t JOIN decentralized_applications d ON t.app_id = d.app_id WHERE transaction_date >= DATEADD(day, -30, CURRENT_DATE);
How many items were sold between specific dates?
CREATE TABLE orders(order_id INT,order_date DATE,menu_item_id INT,quantity INT); CREATE TABLE menu_items(menu_item_id INT,name TEXT,type TEXT,price DECIMAL);
SELECT SUM(orders.quantity) FROM orders WHERE orders.order_date BETWEEN '2022-01-01' AND '2022-01-15';
How many players are there in each country playing 'RPG' games?
CREATE TABLE Players (Id INT,Name VARCHAR(100),Country VARCHAR(50),Game VARCHAR(50)); INSERT INTO Players VALUES (1,'Player1','USA','GameA'),(2,'Player2','Canada','GameB'),(3,'Player3','USA','GameC'),(4,'Player4','Mexico','GameA'),(5,'Player5','Canada','GameB'),(6,'Player6','USA','GameD'),(7,'Player7','Brazil','GameA')...
SELECT p.Country, COUNT(*) AS Players_Count FROM Players p JOIN Games g ON p.Game = g.Name WHERE g.Genre = 'RPG' GROUP BY p.Country;
List the unique case types and the number of cases for each type, sorted alphabetically by case type.
CREATE TABLE cases (id INT,case_type VARCHAR(20)); INSERT INTO cases (id,case_type) VALUES (1,'Civil'),(2,'Criminal'),(3,'Civil');
SELECT case_type, COUNT(*) AS num_cases FROM cases GROUP BY case_type ORDER BY case_type;
What is the maximum depth recorded for all marine protected areas?
CREATE TABLE marine_protected_areas (name VARCHAR(255),location VARCHAR(255),avg_depth FLOAT,max_depth FLOAT);
SELECT max_depth FROM marine_protected_areas;
What is the difference in ocean acidity levels between the Arctic and Atlantic regions?
CREATE TABLE ocean_acidity (region VARCHAR(255),year INT,acidity FLOAT); INSERT INTO ocean_acidity (region,year,acidity) VALUES ('Arctic',2010,8.1),('Arctic',2011,8.15),('Arctic',2012,8.2),('Atlantic',2010,8.05),('Atlantic',2011,8.08),('Atlantic',2012,8.1);
SELECT region, acidity - LAG(acidity) OVER(PARTITION BY region ORDER BY year) as acidity_difference FROM ocean_acidity;
What is the average travel advisory level for African countries in 2021?
CREATE TABLE advisory_levels (id INT,country VARCHAR(20),advisory_level INT,advisory_date DATE); INSERT INTO advisory_levels (id,country,advisory_level,advisory_date) VALUES (1,'Kenya',2,'2021-01-01'),(2,'Tanzania',3,'2021-01-02'),(3,'Kenya',2,'2021-01-03');
SELECT AVG(advisory_level) FROM advisory_levels WHERE country IN ('Kenya', 'Tanzania', 'Nigeria', 'Egypt', 'South Africa') AND advisory_date BETWEEN '2021-01-01' AND '2021-12-31';
What is the average income of citizens in each Canadian province in 2020?
CREATE TABLE incomes (id INT,province VARCHAR(50),income FLOAT,year INT); INSERT INTO incomes (id,province,income,year) VALUES (1,'Ontario',55000,2020),(2,'Quebec',48000,2020),(3,'British Columbia',60000,2020),(4,'Alberta',70000,2020),(5,'Manitoba',45000,2020);
SELECT province, AVG(income) FROM incomes WHERE year = 2020 GROUP BY province;
What is the total cost of ingredients for dish 'Paella' in the ingredients table?
CREATE TABLE ingredients (id INT,dish TEXT,ingredient TEXT,cost FLOAT); INSERT INTO ingredients (id,dish,ingredient,cost) VALUES (1,'Paella','Rice',1.50); INSERT INTO ingredients (id,dish,ingredient,cost) VALUES (2,'Paella','Chicken',5.00);
SELECT SUM(cost) FROM ingredients WHERE dish = 'Paella';
What is the total weight of organic fruits and vegetables in the inventory?
CREATE TABLE inventory (id INT,product_id INT,name TEXT,is_organic BOOLEAN,weight FLOAT); INSERT INTO inventory (id,product_id,name,is_organic,weight) VALUES (1,1,'apple',true,0.5),(2,2,'banana',false,0.3),(3,3,'carrot',true,1.0),(4,4,'broccoli',true,2.0);
SELECT SUM(weight) FROM inventory WHERE is_organic = true AND category = 'fruit' OR category = 'vegetable';
What was the maximum price of kids' garments in Australia?
CREATE TABLE Categories (category_id INT,category VARCHAR(50),PRIMARY KEY (category_id)); INSERT INTO Categories (category_id,category) VALUES (1,'Kids'),(2,'Adults');
SELECT MAX(price) as max_price FROM Products JOIN Categories ON Products.category = Categories.category WHERE Categories.category = 'Kids' AND Products.country = 'Australia';
What is the average number of security incidents per day for the last year?
CREATE TABLE DailyIncidents (id INT,incident_date DATE,incident_count INT); INSERT INTO DailyIncidents (id,incident_date,incident_count) VALUES (1,'2021-01-01',10),(2,'2021-01-02',15);
SELECT AVG(incident_count) as daily_average FROM DailyIncidents WHERE incident_date >= DATEADD(year, -1, GETDATE());
What is the name of the military technology with the highest budget?
CREATE SCHEMA IF NOT EXISTS military_tech; CREATE TABLE IF NOT EXISTS tech_budget (id INT PRIMARY KEY,name TEXT,budget DECIMAL(10,2)); INSERT INTO tech_budget (id,name,budget) VALUES (1,'F-35 Fighter Jet',100000000.00),(2,'Navy Destroyer',50000000.00),(3,'Submarine',70000000.00);
SELECT name FROM military_tech.tech_budget WHERE budget = (SELECT MAX(budget) FROM military_tech.tech_budget);
What is the distribution of eco-friendly materials sourced by country and material type?
CREATE TABLE sourcing (country VARCHAR(255),material VARCHAR(255),eco_friendly BOOLEAN);
SELECT country, material, COUNT(*) as eco_friendly_materials_count FROM sourcing WHERE eco_friendly = TRUE GROUP BY country, material;
What is the maximum snow depth recorded in the Arctic Research Station 11 and 12?
CREATE TABLE Arctic_Research_Station_11 (date DATE,snow_depth FLOAT); CREATE TABLE Arctic_Research_Station_12 (date DATE,snow_depth FLOAT);
SELECT MAX(snow_depth) FROM Arctic_Research_Station_11; SELECT MAX(snow_depth) FROM Arctic_Research_Station_12; SELECT GREATEST(MAX(snow_depth), MAX(snow_depth)) FROM Arctic_Research_Station_11, Arctic_Research_Station_12;
What is the total number of founders who are female or from India?
CREATE TABLE company (id INT,name VARCHAR(255),founder VARCHAR(255),founder_country VARCHAR(255),founder_gender VARCHAR(10)); INSERT INTO company (id,name,founder,founder_country,founder_gender) VALUES (1,'Acme Inc','Sara','India','female'),(2,'Beta Corp','Ahmed','Pakistan','male'),(3,'Charlie Inc','David','USA','male'...
SELECT COUNT(*) FROM company WHERE founder_gender = 'female' OR founder_country = 'India';
List all mining sites that have reported environmental violations.
CREATE TABLE environmental_violations (site_id INT,site_name TEXT,violation_date DATE);
SELECT site_name FROM environmental_violations WHERE violation_date IS NOT NULL;
What is the total number of visitors to visual art exhibitions by city?
CREATE TABLE visual_art_exhibitions (id INT,exhibition_name VARCHAR(255),city VARCHAR(255),visitor_count INT);
SELECT city, SUM(visitor_count) as total_visitors FROM visual_art_exhibitions GROUP BY city;
What is the total number of electric vehicle charging stations in the city of Seattle, and what is their total capacity?
CREATE TABLE ev_charging_stations (id INT,name VARCHAR(255),city VARCHAR(255),capacity FLOAT,installation_date DATE);
SELECT COUNT(*) AS total_stations, SUM(capacity) AS total_capacity FROM ev_charging_stations WHERE city = 'Seattle';
Select all records from sales table where country='India' and quantity>10
CREATE TABLE sales (id INT,product_name VARCHAR(50),country VARCHAR(50),quantity INT,sale_date DATE);
SELECT * FROM sales WHERE country = 'India' AND quantity > 10;
Update the 'ConservationStatus' of the 'Shark' species in the 'MarineSpecies' table
CREATE TABLE MarineSpecies (SpeciesID INT,SpeciesName VARCHAR(255),Habitat VARCHAR(255),ConservationStatus VARCHAR(255));
UPDATE MarineSpecies SET ConservationStatus = 'Vulnerable' WHERE SpeciesName = 'Shark';
How many female employees were hired in each department in 2020?
CREATE TABLE Employees (EmployeeID INT,Department VARCHAR(50),Gender VARCHAR(10),Salary FLOAT,HireDate DATE); INSERT INTO Employees (EmployeeID,Department,Gender,Salary,HireDate) VALUES (1,'IT','Male',85000,'2021-04-20'),(2,'HR','Female',75000,'2020-02-15'),(3,'IT','Female',80000,'2020-01-08'),(4,'IT','Male',90000,'202...
SELECT Department, COUNT(*) FROM Employees WHERE Gender = 'Female' AND YEAR(HireDate) = 2020 GROUP BY Department;
List all regions and their total carbon sequestration.
CREATE TABLE carbon_sequestration (region VARCHAR(255),amount INT); INSERT INTO carbon_sequestration (region,amount) VALUES ('Amazon',2000),('Congo',1500),('Boreal',1800),('Temperate',1200);
SELECT region, SUM(amount) FROM carbon_sequestration GROUP BY region;
What are the total donation amounts for each program in the 'Arts & Culture' and 'Environment' categories?
CREATE TABLE Programs (ProgramID int,ProgramName varchar(50),Category varchar(50)); INSERT INTO Programs (ProgramID,ProgramName,Category) VALUES (1,'Theater Workshop','Arts & Culture'),(2,'Eco-Gardening','Environment'); CREATE TABLE Donations (DonationID int,DonationAmount decimal(10,2),ProgramID int); INSERT INTO Dona...
SELECT p.Category, SUM(d.DonationAmount) as TotalDonationAmount FROM Donations d JOIN Programs p ON d.ProgramID = p.ProgramID WHERE p.Category IN ('Arts & Culture', 'Environment') GROUP BY p.Category;
Which artists have performed in 'Tokyo' and 'Paris'?
CREATE TABLE Venues (VenueID INT,VenueName VARCHAR(100),Location VARCHAR(50)); INSERT INTO Venues (VenueID,VenueName,Location) VALUES (1001,'VenueA','New York'),(1002,'VenueB','Los Angeles'),(1003,'VenueC','Tokyo'),(1004,'VenueD','Paris'),(1005,'VenueE','Sydney'); CREATE TABLE Concerts (ConcertID INT,VenueID INT,Artist...
SELECT ArtistID FROM Concerts C1 JOIN Venues V1 ON C1.VenueID = V1.VenueID WHERE V1.Location = 'Tokyo' INTERSECT SELECT ArtistID FROM Concerts C2 JOIN Venues V2 ON C2.VenueID = V2.VenueID WHERE V2.Location = 'Paris';
What is the sum of energy consumption for buildings in the 'green_buildings' schema, grouped by city, and only for buildings with consumption > 2000?
CREATE TABLE green_buildings.building_energy_consumption (city VARCHAR(50),consumption FLOAT); INSERT INTO green_buildings.building_energy_consumption (city,consumption) VALUES ('London',5000.0),('Tokyo',6000.0),('Sydney',7000.0),('Paris',8000.0),('Berlin',1500.0),('Rome',2500.0);
SELECT city, SUM(consumption) AS total_consumption FROM green_buildings.building_energy_consumption WHERE consumption > 2000 GROUP BY city;
Identify the top 3 customers by total spending on ethically sourced products
CREATE TABLE customer_spending (customer_id INT,product_id INT,quantity INT,revenue FLOAT,is_ethically_sourced BOOLEAN);
SELECT customer_id, SUM(revenue) as total_spending FROM customer_spending WHERE is_ethically_sourced = TRUE GROUP BY customer_id ORDER BY total_spending DESC LIMIT 3;
What is the maximum weight of shipments sent to 'South America' in March?
CREATE TABLE shipments (id INT,shipped_date DATE,destination VARCHAR(20),weight INT); INSERT INTO shipments (id,shipped_date,destination,weight) VALUES (1,'2022-03-05','South America',150),(2,'2022-03-07','North America',200),(3,'2022-03-16','South America',250);
SELECT MAX(weight) FROM shipments WHERE shipped_date >= '2022-03-01' AND shipped_date < '2022-04-01' AND destination = 'South America';
How many community health workers of each race have a cultural competency score greater than 80?
CREATE TABLE CommunityHealthWorkers (WorkerID INT,Race VARCHAR(255),Score INT); INSERT INTO CommunityHealthWorkers (WorkerID,Race,Score) VALUES (1,'Hispanic',85),(2,'African American',85),(3,'Caucasian',90);
SELECT Race, COUNT(*) as Count FROM CommunityHealthWorkers WHERE Score > 80 GROUP BY Race;
List the top 3 countries with the most unique IP addresses involved in cyber attacks in the last month.
CREATE TABLE cyber_attacks (attack_id INT,attack_date DATE,attack_country VARCHAR(50),attack_ip VARCHAR(50)); INSERT INTO cyber_attacks (attack_id,attack_date,attack_country,attack_ip) VALUES (1,'2022-01-01','USA','192.168.1.1'),(2,'2022-01-02','Canada','192.168.1.2'),(3,'2022-01-01','USA','192.168.1.3');
SELECT attack_country, COUNT(DISTINCT attack_ip) as unique_ips FROM cyber_attacks WHERE attack_date >= DATEADD(month, -1, GETDATE()) GROUP BY attack_country ORDER BY unique_ips DESC LIMIT 3;
List the names of states that have both healthcare facilities and mental health facilities.
CREATE TABLE healthcare_facilities (id INT,name VARCHAR(50),state VARCHAR(10)); INSERT INTO healthcare_facilities (id,name,state) VALUES (1,'Facility A','State 1'),(2,'Facility B','State 2'),(3,'Facility C','State 3');
SELECT h.state FROM healthcare_facilities h INNER JOIN mental_health_facilities m ON h.state = m.state GROUP BY h.state;
What is the average income and expenses for financial wellbeing programs in the United Kingdom?
CREATE TABLE FinancialWellbeingPrograms (id INT,program_name VARCHAR(50),country VARCHAR(50),income FLOAT,expenses FLOAT); INSERT INTO FinancialWellbeingPrograms (id,program_name,country,income,expenses) VALUES (1,'Financial Literacy Program','UK',30000,18000),(2,'Debt Management Program','UK',35000,21000),(3,'Retireme...
SELECT country, AVG(income) as avg_income, AVG(expenses) as avg_expenses FROM FinancialWellbeingPrograms WHERE country = 'UK';
Find the number of pollution control initiatives by type in the 'PollutionTypes' and 'PollutionProjects' tables
CREATE TABLE PollutionTypes (id INT PRIMARY KEY,type VARCHAR(255)); CREATE TABLE PollutionProjects (id INT PRIMARY KEY,type_id INT,name VARCHAR(255),location VARCHAR(255),start_date DATE,end_date DATE,FOREIGN KEY (type_id) REFERENCES PollutionTypes(id));
SELECT PollutionTypes.type, COUNT(*) FROM PollutionTypes INNER JOIN PollutionProjects ON PollutionTypes.id = PollutionProjects.type_id GROUP BY PollutionTypes.type;
What is the total volume of water (in cubic meters) consumed by the residential sector in Mexico City in the year 2020?
CREATE TABLE ResidentialWaterConsumption (date DATE,city VARCHAR(20),water_consumption FLOAT);
SELECT SUM(water_consumption) FROM ResidentialWaterConsumption WHERE date BETWEEN '2020-01-01' AND '2020-12-31' AND city = 'Mexico City';
Identify the water conservation initiatives that overlap between two regions, X and Y?
CREATE TABLE conservation_initiatives(initiative_id INT,initiative_name TEXT,region TEXT); INSERT INTO conservation_initiatives(initiative_id,initiative_name,region) VALUES (1,'Rainwater harvesting','X'),(2,'Greywater recycling','X'),(3,'Smart irrigation','Y'),(4,'Drip irrigation','Y');
SELECT initiative_name FROM conservation_initiatives WHERE region IN ('X', 'Y') GROUP BY initiative_name HAVING COUNT(DISTINCT region) = 2;
Insert 3 records into 'rural_clinics' table
CREATE TABLE rural_clinics(clinic_id INT PRIMARY KEY,name VARCHAR(255),beds INT,doctor_count INT);
INSERT INTO rural_clinics(clinic_id, name, beds, doctor_count) VALUES (1, 'Clinic A', 5, 3), (2, 'Clinic B', 3, 2), (3, 'Clinic C', 4, 3);
What is the total number of diabetes consultations in urban areas in the last month?
CREATE TABLE diabetes_consultations (id INT,consult_date DATE,location TEXT,consultation BOOLEAN); INSERT INTO diabetes_consultations (id,consult_date,location,consultation) VALUES (1,'2022-02-15','Urban',true); INSERT INTO diabetes_consultations (id,consult_date,location,consultation) VALUES (2,'2022-03-03','Urban',tr...
SELECT SUM(CASE WHEN location = 'Urban' THEN 1 ELSE 0 END) FROM diabetes_consultations WHERE consult_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);
How many accessories were sold in Japan in Q1 2021?
CREATE TABLE japan_accessories (accessory_type VARCHAR(255),sales_quantity INT,quarter INT,year INT); INSERT INTO japan_accessories (accessory_type,sales_quantity,quarter,year) VALUES ('Hat',200,1,2021),('Scarf',300,1,2021);
SELECT SUM(sales_quantity) FROM japan_accessories WHERE quarter = 1 AND year = 2021;
What's the maximum duration of a podcast in the 'Education' category?
CREATE TABLE podcasts (id INT,title TEXT,category TEXT,duration INT); INSERT INTO podcasts (id,title,category,duration) VALUES (1,'Podcast1','Education',60),(2,'Podcast2','Education',90);
SELECT MAX(duration) FROM podcasts WHERE category = 'Education';
Delete the TV show with the title "ShowX" and release year 2017.
CREATE TABLE tv_shows (id INT,title VARCHAR(100),genre VARCHAR(50),release_year INT,marketing_spend INT); INSERT INTO tv_shows (id,title,genre,release_year,marketing_spend) VALUES (1,'ShowX','Comedy',2017,5000000); INSERT INTO tv_shows (id,title,genre,release_year,marketing_spend) VALUES (2,'ShowY','Romance',2018,60000...
DELETE FROM tv_shows WHERE title = 'ShowX' AND release_year = 2017;
Insert data about a software engineer position submitted through LinkedIn on 2023-01-10
CREATE TABLE talent_acquisition (id SERIAL PRIMARY KEY,job_title VARCHAR(50),source VARCHAR(50),submission_date DATE);
INSERT INTO talent_acquisition (job_title, source, submission_date) VALUES ('Software Engineer', 'LinkedIn', '2023-01-10');
Get all athletes who participated in 2021
CREATE TABLE athletes (id INT PRIMARY KEY,name VARCHAR(100),gender VARCHAR(10),sport VARCHAR(50)); CREATE TABLE participation (id INT PRIMARY KEY,athlete_id INT,year INT);
SELECT athletes.name FROM athletes INNER JOIN participation ON athletes.id = participation.athlete_id WHERE participation.year = 2021;
Which professional development programs were attended by teachers in a specific school?
CREATE TABLE teacher_professional_development (teacher_id INT,program_id INT,school_id INT); INSERT INTO teacher_professional_development (teacher_id,program_id,school_id) VALUES (1,1001,101),(2,1002,101),(3,1003,102),(4,1004,103),(5,1005,104); CREATE TABLE programs (program_id INT,program_name VARCHAR(50)); INSERT INT...
SELECT p.program_name FROM teacher_professional_development tpd JOIN programs p ON tpd.program_id = p.program_id WHERE tpd.school_id = 101;
Identify all the unique beneficiaries who received support from the 'education' and 'health' sectors in Afghanistan in 2019, and the number of times they received support.
CREATE TABLE beneficiaries (id INT,name TEXT,country TEXT); INSERT INTO beneficiaries VALUES (1,'Ahmed','Afghanistan'); CREATE TABLE support (id INT,beneficiary_id INT,sector TEXT,support_date DATE); INSERT INTO support VALUES (1,1,'education','2019-01-01'); INSERT INTO support VALUES (2,1,'health','2019-02-01');
SELECT b.name, COUNT(s.id) FROM beneficiaries b INNER JOIN support s ON b.id = s.beneficiary_id WHERE b.country = 'Afghanistan' AND s.sector IN ('education', 'health') AND s.support_date BETWEEN '2019-01-01' AND '2019-12-31' GROUP BY b.name;
What is the average age of employees in the HR department who have received diversity and inclusion training?
CREATE TABLE Employees (EmployeeID INT,Department VARCHAR(20),Age INT,HasReceivedDiversityTraining BOOLEAN); INSERT INTO Employees (EmployeeID,Department,Age,HasReceivedDiversityTraining) VALUES (1,'HR',35,true),(2,'IT',28,false),(3,'HR',40,true); CREATE TABLE DiversityTraining (TrainingID INT,EmployeeID INT); INSERT I...
SELECT AVG(Age) FROM Employees INNER JOIN DiversityTraining ON Employees.EmployeeID = DiversityTraining.EmployeeID WHERE Department = 'HR';
Show top 3 expensive biosensors in descending order.
CREATE TABLE biosensors (id INT,manufacturer VARCHAR(50),model VARCHAR(50),price FLOAT,quantity INT,date DATE);
SELECT manufacturer, model, price FROM biosensors ORDER BY price DESC LIMIT 3;
Calculate the total premium for policyholders living in 'NY' and 'NJ'.
CREATE TABLE policyholders (id INT,name TEXT,state TEXT,policy_type TEXT,premium FLOAT); INSERT INTO policyholders (id,name,state,policy_type,premium) VALUES (1,'John Doe','NY','Auto',1200.00),(2,'Jane Smith','CA','Home',2500.00),(3,'Jim Brown','NJ','Auto',1500.00);
SELECT state, SUM(premium) as total_premium FROM policyholders WHERE state IN ('NY', 'NJ') GROUP BY state;
What is the total number of indigenous communities in the Arctic region?
CREATE TABLE IndigenousCommunities (community VARCHAR(50),country VARCHAR(50)); INSERT INTO IndigenousCommunities (community,country) VALUES ('Inuit','Greenland'); INSERT INTO IndigenousCommunities (community,country) VALUES ('Sami','Norway'); INSERT INTO IndigenousCommunities (community,country) VALUES ('Chukchi','Rus...
SELECT COUNT(community) FROM IndigenousCommunities;
What is the average salary of employees working in ethical supply chain roles, grouped by job title and region?
CREATE TABLE employees (id INT,name VARCHAR(50),title VARCHAR(50),salary DECIMAL(10,2),department VARCHAR(50),region VARCHAR(50));
SELECT title, region, AVG(salary) as avg_salary FROM employees WHERE department = 'Ethical Supply Chain' GROUP BY title, region;
What is the average heart rate of members from Australia during evening workouts?
CREATE TABLE members (id INT,country VARCHAR(50)); INSERT INTO members (id,country) VALUES (1,'Australia'); CREATE TABLE workouts (id INT,member_id INT,date DATE,heart_rate INT); INSERT INTO workouts (id,member_id,date,heart_rate) VALUES (1,1,'2021-08-01',120);
SELECT AVG(heart_rate) FROM members JOIN workouts ON members.id = workouts.member_id WHERE members.country = 'Australia' AND HOUR(workouts.date) BETWEEN 17 AND 23;
What is the total budget allocated for public safety in the city of Toronto, including all departments, for the fiscal year 2024?
CREATE TABLE city_budget (city VARCHAR(20),department VARCHAR(20),budget INT); INSERT INTO city_budget (city,department,budget) VALUES ('Toronto','Police',8000000);
SELECT SUM(budget) FROM city_budget WHERE city = 'Toronto' AND department LIKE '%Safety%' AND fiscal_year = 2024;
When did the first cybersecurity incident occur in the database?
CREATE TABLE CybersecurityIncidents(id INT PRIMARY KEY,year INT,incidents INT);INSERT INTO CybersecurityIncidents(id,year,incidents) VALUES (1,2005,50),(2,2010,100),(3,2015,150);
SELECT MIN(year) FROM CybersecurityIncidents;
List all mining sites that have higher coal depletion compared to gold depletion.
CREATE TABLE coal_depletion (site_id INT,amount FLOAT); CREATE TABLE gold_depletion (site_id INT,amount FLOAT); INSERT INTO coal_depletion (site_id,amount) VALUES (1,200),(2,300),(3,150); INSERT INTO gold_depletion (site_id,amount) VALUES (1,50),(2,75),(3,100);
SELECT c.site_id, c.amount as coal_depletion, g.amount as gold_depletion FROM coal_depletion c INNER JOIN gold_depletion g ON c.site_id = g.site_id WHERE c.amount > g.amount;
What is the maximum daily CO2 emission for each mine site in the first week of 2020, if any site had over 1000 tons of daily CO2 emission, exclude it from the results?
CREATE TABLE Emissions (Id INT,Mine_Site VARCHAR(50),Material VARCHAR(50),Emission_Tons INT,Date DATE); INSERT INTO Emissions (Id,Mine_Site,Material,Emission_Tons,Date) VALUES (1,'SiteA','Coal',800,'2020-01-01'); INSERT INTO Emissions (Id,Mine_Site,Material,Emission_Tons,Date) VALUES (2,'SiteB','Iron',900,'2020-01-02')...
SELECT Mine_Site, MAX(Emission_Tons) as Max_Daily_Emission FROM Emissions WHERE Material IN ('Coal', 'Iron') AND Date >= '2020-01-01' AND Date < '2020-01-08' GROUP BY Mine_Site HAVING Max_Daily_Emission < 1000;
What was the production of Gadolinium in 2020 and 2021?
CREATE TABLE production_data (year INT,element VARCHAR(10),quantity INT); INSERT INTO production_data (year,element,quantity) VALUES (2018,'Gadolinium',50),(2019,'Gadolinium',60),(2020,'Gadolinium',75),(2021,'Gadolinium',90);
SELECT quantity FROM production_data WHERE element = 'Gadolinium' AND year IN (2020, 2021);
How many orders were placed by each customer in the 'medium' size category?
CREATE TABLE orders (customer_id INT,order_date DATE,size VARCHAR(10),quantity INT); INSERT INTO orders (customer_id,order_date,size,quantity) VALUES (1,'2022-01-01','large',100),(2,'2022-01-02','large',200),(3,'2022-01-03','large',150),(4,'2022-01-04','medium',120),(4,'2022-01-05','medium',130);
SELECT customer_id, COUNT(*) as num_orders FROM orders WHERE size = 'medium' GROUP BY customer_id;
What is the average price of cruelty-free makeup products sold in Canada?
CREATE TABLE cosmetics_sales(product_name TEXT,price DECIMAL(5,2),is_cruelty_free BOOLEAN,country TEXT); INSERT INTO cosmetics_sales VALUES ('Lipstick',15.99,true,'Canada'); INSERT INTO cosmetics_sales VALUES ('Mascara',9.99,false,'Canada'); INSERT INTO cosmetics_sales VALUES ('Eyeshadow',19.99,true,'Canada');
SELECT AVG(price) FROM cosmetics_sales WHERE is_cruelty_free = true AND country = 'Canada';
Identify the total number of players from the United States who play "Fortnite".
CREATE TABLE Players (PlayerID INT,PlayerName VARCHAR(100),Age INT,Country VARCHAR(100),Game VARCHAR(100)); INSERT INTO Players (PlayerID,PlayerName,Age,Country,Game) VALUES (1,'John Doe',25,'USA','Fortnite'),(2,'Jane Smith',30,'Canada','Fortnite'),(3,'Mike Johnson',35,'USA','Call of Duty');
SELECT COUNT(*) FROM Players WHERE Country = 'USA' AND Game = 'Fortnite';
What is the total number of satellites launched by country and their successful launch rate?
CREATE TABLE satellites(satellite_id INT,name VARCHAR(50),country VARCHAR(50),launch_date DATE,launch_success BOOLEAN); INSERT INTO satellites VALUES (1,'Sat1','USA','2000-01-01',true); INSERT INTO satellites VALUES (2,'Sat2','USA','2001-01-01',false); INSERT INTO satellites VALUES (3,'Sat3','China','2002-01-01',true);
SELECT country, COUNT(*) as total_satellites, ROUND(SUM(launch_success)/COUNT(*)*100, 2) as success_rate FROM satellites GROUP BY country;
Find the number of unique users who have rated R-rated movies and watched sports shows.
CREATE TABLE user_ratings (user_id INT,movie_title VARCHAR(50),rating INT,rating_date DATE); CREATE TABLE shows (show_id INT,show_name VARCHAR(50),category VARCHAR(20),air_date DATE);
SELECT COUNT(DISTINCT user_id) FROM user_ratings INNER JOIN movies ON user_ratings.movie_title = movies.title INNER JOIN shows ON user_ratings.user_id = shows.show_id WHERE movies.rating = 'R' AND shows.category = 'Sports';
Identify the user with the maximum number of posts in the 'social_media' schema.
CREATE TABLE user_details (user_id INT,num_posts INT); INSERT INTO user_details (user_id,num_posts) VALUES (1,25),(2,32),(3,18),(4,45);
SELECT user_id, num_posts FROM user_details ORDER BY num_posts DESC LIMIT 1;
List all farms in the 'farms' table and their corresponding region.
CREATE TABLE farms (id INT,name TEXT,region TEXT); INSERT INTO farms (id,name,region) VALUES (1,'Farm A','Asia-Pacific'); INSERT INTO farms (id,name,region) VALUES (2,'Farm B','Europe'); INSERT INTO farms (id,name,region) VALUES (3,'Farm C','Asia-Pacific'); INSERT INTO farms (id,name,region) VALUES (4,'Farm D','Europe'...
SELECT name, region FROM farms;
What is the total number of policies and total claim amount for each city?
CREATE TABLE Policies (Policy_ID INT,City TEXT); INSERT INTO Policies (Policy_ID,City) VALUES (1,'Chicago'),(2,'Houston'),(3,'Chicago'),(4,'Miami'); CREATE TABLE Claims (Claim_ID INT,Policy_ID INT,Amount INT); INSERT INTO Claims (Claim_ID,Policy_ID,Amount) VALUES (1,1,2000),(2,2,3000),(3,1,1500),(4,4,500);
SELECT City, COUNT(DISTINCT Policies.Policy_ID) AS Num_Policies, SUM(Claims.Amount) AS Total_Claim_Amount FROM Policies INNER JOIN Claims ON Policies.Policy_ID = Claims.Policy_ID GROUP BY City;
What is the total number of OTA bookings made for hotels in the Caribbean, in the last month?
CREATE TABLE ota_bookings (booking_id INT,hotel_id INT,ota_platform TEXT,region TEXT,booking_date DATE); INSERT INTO ota_bookings (booking_id,hotel_id,ota_platform,region,booking_date) VALUES (1,1,'OTA E','Caribbean','2022-02-01'),(2,2,'OTA F','Africa','2022-02-10'),(3,3,'OTA G','Caribbean','2022-02-15');
SELECT COUNT(*) FROM ota_bookings WHERE region = 'Caribbean' AND booking_date >= DATEADD(month, -1, CURRENT_DATE);
Insert new safety metrics for an application with an id of 4 and a safety score of 0.91 for the category 'Reliability'.
CREATE TABLE safety_data (id INT PRIMARY KEY,application_id INT,safety_score DECIMAL(5,4),safety_category VARCHAR(50),measurement_date DATE); INSERT INTO safety_data (id,application_id,safety_score,safety_category,measurement_date) VALUES (1,1,0.9123,'Security','2021-01-15'),(2,2,0.8321,'Reliability','2021-01-15');
INSERT INTO safety_data (id, application_id, safety_score, safety_category, measurement_date) VALUES (3, 4, 0.91, 'Reliability', '2021-01-15');
How many recycling centers are there in the rural areas and in each province?
CREATE TABLE recycling_centers (location VARCHAR(50),area VARCHAR(50),province VARCHAR(50)); INSERT INTO recycling_centers (location,area,province) VALUES ('CenterA','rural','ProvinceX'),('CenterB','urban','ProvinceY'),('CenterC','rural','ProvinceX');
SELECT province, COUNT(*) FROM recycling_centers WHERE area = 'rural' GROUP BY province;
What is the total value of military equipment sales for each defense contractor, grouped by region?
CREATE TABLE contractor_regions (contractor_id INT,region VARCHAR(255)); INSERT INTO contractor_regions (contractor_id,region) VALUES (1,'North America'),(2,'North America'),(3,'Europe');
SELECT r.region, d.contractor_name, SUM(s.sale_value) as total_sales FROM defense_contractors d INNER JOIN contractor_regions r ON d.contractor_id = r.contractor_id INNER JOIN military_sales s ON d.contractor_id = s.contractor_id GROUP BY r.region, d.contractor_name;
What is the most common therapy type for patients with anxiety?
CREATE TABLE patients (patient_id INT,age INT,gender TEXT,therapy_type TEXT); INSERT INTO patients (patient_id,age,gender,therapy_type) VALUES (1,35,'Female','CBT'); INSERT INTO patients (patient_id,age,gender,therapy_type) VALUES (2,42,'Male','DBT');
SELECT therapy_type, COUNT(*) as count FROM patients WHERE condition = 'Anxiety' GROUP BY therapy_type ORDER BY count DESC LIMIT 1;
What is the total amount of funds allocated to restorative justice programs in 'North Valley' justice district?
CREATE TABLE RestorativeJusticeFunds (ID INT,FundID VARCHAR(20),District VARCHAR(20),Amount INT,Year INT); INSERT INTO RestorativeJusticeFunds (ID,FundID,District,Amount,Year) VALUES (1,'RJF2015','North Valley',5000,2015),(2,'RJF2016','South Peak',8000,2016),(3,'RJF2018','North Valley',6000,2018);
SELECT SUM(Amount) FROM RestorativeJusticeFunds WHERE District = 'North Valley';
What is the total number of accommodations provided in Australia by accommodation type?
CREATE TABLE accommodations (id INT,country VARCHAR(255),region VARCHAR(255),accommodation_type VARCHAR(255),count INT); INSERT INTO accommodations (id,country,region,accommodation_type,count) VALUES (1,'Australia','Northern','Braille Materials',150); INSERT INTO accommodations (id,country,region,accommodation_type,cou...
SELECT accommodation_type, SUM(count) as total_count FROM accommodations WHERE country = 'Australia' GROUP BY accommodation_type;
What is the total number of accidents for each aircraft type?
CREATE TABLE AircraftType (ID INT,Name VARCHAR(50)); CREATE TABLE Accidents (AircraftTypeID INT,AccidentDate DATE);
SELECT at.Name, COUNT(a.AircraftTypeID) AS AccidentCount FROM AircraftType at JOIN Accidents a ON at.ID = a.AircraftTypeID GROUP BY at.Name;
What is the minimum revenue generated by a single virtual tour in Sweden?
CREATE TABLE virtual_tours_sweden (id INT,country VARCHAR(20),revenue FLOAT); INSERT INTO virtual_tours_sweden (id,country,revenue) VALUES (1,'Sweden',800.0),(2,'Sweden',900.0),(3,'Sweden',1000.0);
SELECT MIN(revenue) FROM virtual_tours_sweden WHERE country = 'Sweden';
Find the top 10 deepest trenches in the Indian Ocean.
CREATE TABLE trench_info (trench_name TEXT,ocean_basin TEXT,max_depth INTEGER);
SELECT trench_name, max_depth FROM trench_info WHERE ocean_basin = 'Indian Ocean' ORDER BY max_depth DESC LIMIT 10;
How many non-binary graduate students are there in the 'students' and 'departments' tables, grouped by department?
CREATE TABLE students (id INT,name VARCHAR(255),gender VARCHAR(10),department VARCHAR(255)); CREATE TABLE departments (id INT,name VARCHAR(255),type VARCHAR(10)); INSERT INTO students (id,name,gender,department) VALUES (1,'Alex','Non-binary','Physics'),(2,'Bob','Male','Mathematics'),(3,'Charlie','Male','Chemistry'),(4,...
SELECT d.name, COUNT(s.id) FROM students s JOIN departments d ON s.department = d.name WHERE s.gender = 'Non-binary' AND d.type = 'Graduate' GROUP BY d.name;