instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
Who was the top donor in the 'Southeast' region in the year 2020?
|
CREATE TABLE Donors (donor_id INT,region VARCHAR(20),amount DECIMAL(10,2),donation_year INT); INSERT INTO Donors (donor_id,region,amount,donation_year) VALUES (1,'Southeast',7000.00,2020),(2,'Southeast',6000.00,2020);
|
SELECT donor_id, MAX(amount) FROM Donors WHERE region = 'Southeast' AND donation_year = 2020 GROUP BY donor_id;
|
What is the maximum ESG score for investments in 'Oceania'?
|
CREATE TABLE esg_scores_3 (investment_id INT,region VARCHAR(20),esg_score FLOAT); INSERT INTO esg_scores_3 (investment_id,region,esg_score) VALUES (1,'Africa',75.5),(2,'Oceania',87.6),(3,'Africa',78.2),(4,'South America',82.1);
|
SELECT MAX(esg_score) FROM esg_scores_3 WHERE region = 'Oceania';
|
How many defense projects were delayed in the Asia-Pacific region in 2019?
|
CREATE TABLE defense_projects (id INT,year INT,region VARCHAR(20),project_name VARCHAR(30),delayed BOOLEAN); INSERT INTO defense_projects (id,year,region,project_name,delayed) VALUES (1,2019,'Asia-Pacific','Project A',true); INSERT INTO defense_projects (id,year,region,project_name,delayed) VALUES (2,2019,'Asia-Pacific','Project B',false);
|
SELECT COUNT(*) FROM defense_projects WHERE year = 2019 AND region = 'Asia-Pacific' AND delayed = true;
|
Find the number of properties in each city that were built before 2000.
|
CREATE TABLE cities (id INT,name VARCHAR(30)); CREATE TABLE properties (id INT,city VARCHAR(20),year_built INT); INSERT INTO cities (id,name) VALUES (1,'Vancouver'),(2,'Seattle'),(3,'Portland'); INSERT INTO properties (id,city,year_built) VALUES (101,'Vancouver',1995),(102,'Vancouver',2010),(103,'Seattle',1985),(104,'Seattle',2005),(105,'Portland',1999),(106,'Portland',2002);
|
SELECT cities.name, COUNT(properties.id) FROM cities INNER JOIN properties ON cities.name = properties.city WHERE properties.year_built < 2000 GROUP BY cities.name;
|
Find the minimum and maximum calorie count for vegan items in the inventory.
|
CREATE TABLE Inventory(item_id INT,item_name VARCHAR(50),is_vegan BOOLEAN,calorie_count INT); INSERT INTO Inventory VALUES(1,'Apples',TRUE,80),(2,'Bananas',TRUE,105),(3,'Chips',FALSE,150);
|
SELECT MIN(calorie_count), MAX(calorie_count) FROM Inventory WHERE is_vegan = TRUE;
|
Delete the 'Antarctica' habitat record from the 'habitats' table
|
CREATE TABLE habitats (id INT,name VARCHAR(50),location VARCHAR(50),size FLOAT);
|
DELETE FROM habitats WHERE location = 'Antarctica';
|
Find the customer with the highest balance in the Shariah-compliant savings accounts, and display their account number, name, and balance.
|
CREATE TABLE savings_acct (acct_number INT,name VARCHAR(50),balance DECIMAL(10,2),is_shariah BOOLEAN); INSERT INTO savings_acct (acct_number,name,balance,is_shariah) VALUES (1001,'Ahmed',15000.00,true),(1002,'Sara',20000.00,false),(1003,'Mohammed',12000.00,true);
|
SELECT acct_number, name, balance FROM (SELECT acct_number, name, balance, ROW_NUMBER() OVER (PARTITION BY is_shariah ORDER BY balance DESC) as rn FROM savings_acct WHERE is_shariah = true) t WHERE rn = 1;
|
How many vessels with flag_state 'Panama' were active in the last month?
|
CREATE TABLE vessel_activity (id INT,vessel_name VARCHAR(50),flag_state VARCHAR(50),activity_date DATE); INSERT INTO vessel_activity (id,vessel_name,flag_state,activity_date) VALUES (1,'Panama Titan','Panama','2022-03-20'),(2,'Panama Titan','Panama','2022-03-23');
|
SELECT COUNT(DISTINCT vessel_name) FROM vessel_activity WHERE flag_state = 'Panama' AND activity_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) AND CURRENT_DATE;
|
What is the average rating of organic skincare products in the North American market?
|
CREATE TABLE products (product_id INT,product_name VARCHAR(255),region VARCHAR(255),organic BOOLEAN,rating FLOAT); INSERT INTO products (product_id,product_name,region,organic,rating) VALUES (1,'Nourishing Cream','Asia Pacific',false,4.5),(2,'Revitalizing Serum','Europe',false,4.7),(3,'Gentle Cleanser','Asia Pacific',true,4.8),(4,'Hydrating Lotion','North America',true,4.6),(5,'Soothing Toner','Asia Pacific',true,4.9),(6,'Brightening Essence','Europe',false,4.4);
|
SELECT AVG(rating) AS average_rating FROM products WHERE region = 'North America' AND organic = true;
|
Find the average donation amount for each campaign in 2022.
|
CREATE TABLE campaigns (id INT PRIMARY KEY,campaign_name VARCHAR(50),campaign_start_date DATE,campaign_end_date DATE); INSERT INTO campaigns (id,campaign_name,campaign_start_date,campaign_end_date) VALUES (1,'Food Drive','2022-01-01','2022-01-15'); INSERT INTO campaigns (id,campaign_name,campaign_start_date,campaign_end_date) VALUES (2,'Clothing Drive','2022-02-01','2022-02-28');
|
SELECT campaign_name, AVG(donation_amount) FROM donations d JOIN campaigns c ON d.donation_date BETWEEN c.campaign_start_date AND c.campaign_end_date GROUP BY campaign_name;
|
How many rovers have been deployed on the surface of Mars and are not operational?
|
CREATE TABLE mars_rovers (id INT,name VARCHAR(50),status VARCHAR(50)); INSERT INTO mars_rovers (id,name,status) VALUES (1,'Rover1','Operational'),(2,'Rover2','Operational'),(3,'Rover3','Decommissioned'),(4,'Rover4','Operational'),(5,'Rover5','Not Operational');
|
SELECT COUNT(*) FROM mars_rovers WHERE status != 'Operational';
|
List all artists who have more than 10 million total streams
|
CREATE TABLE artists (artist_id INT PRIMARY KEY,artist_name VARCHAR(100),genre VARCHAR(50),total_streams INT); INSERT INTO artists (artist_id,artist_name,genre,total_streams) VALUES (1,'Taylor Swift','Pop',15000000); INSERT INTO artists (artist_id,artist_name,genre,total_streams) VALUES (2,'BTS','K-Pop',20000000); INSERT INTO artists (artist_id,artist_name,genre,total_streams) VALUES (3,'Drake','Hip-Hop',12000000);
|
SELECT artist_name FROM artists WHERE total_streams > 10000000;
|
What is the average mental health rating of courses for each teacher?
|
CREATE TABLE course_ratings (course_id INT,teacher_id INT,mental_health_rating FLOAT); INSERT INTO course_ratings (course_id,teacher_id,mental_health_rating) VALUES (1,1,4.5),(2,1,3.8),(3,2,4.7),(4,2,4.2),(5,3,5.0);
|
SELECT teacher_id, AVG(mental_health_rating) FROM course_ratings GROUP BY teacher_id;
|
What is the number of skincare products made in the USA that are certified organic?
|
CREATE TABLE Skincare_Products (ProductID int,ProductName varchar(100),Country varchar(50),IsOrganic bit); INSERT INTO Skincare_Products (ProductID,ProductName,Country,IsOrganic) VALUES (1,'Organic Moisturizer','USA',1); INSERT INTO Skincare_Products (ProductID,ProductName,Country,IsOrganic) VALUES (2,'Natural Toner','France',0); INSERT INTO Skincare_Products (ProductID,ProductName,Country,IsOrganic) VALUES (3,'Certified Organic Serum','USA',1);
|
SELECT COUNT(*) FROM Skincare_Products WHERE Country = 'USA' AND IsOrganic = 1;
|
What are the unique IP addresses that have attempted both unsuccessful and successful SSH logins, excluding any IP addresses with only unsuccessful attempts?
|
CREATE TABLE login_attempts (ip_address VARCHAR(15),login_status VARCHAR(10)); INSERT INTO login_attempts (ip_address,login_status) VALUES ('192.168.1.1','successful'),('192.168.1.2','unsuccessful'),('192.168.1.3','successful'),('192.168.1.2','successful'),('10.0.0.1','unsuccessful');
|
SELECT ip_address FROM login_attempts WHERE login_status = 'successful' INTERSECT SELECT ip_address FROM login_attempts WHERE login_status = 'unsuccessful';
|
List dispensaries that have not had sales in the last 14 days, along with the number of days since their last sale.
|
CREATE TABLE Dispensaries (DispensaryID INT,DispensaryName VARCHAR(50)); CREATE TABLE Sales (SaleID INT,DispensaryID INT,QuantitySold INT,SaleDate DATE);
|
SELECT D.DispensaryID, D.DispensaryName, DATEDIFF(day, MAX(S.SaleDate), GETDATE()) AS DaysSinceLastSale FROM Dispensaries D LEFT JOIN Sales S ON D.DispensaryID = S.DispensaryID WHERE S.SaleDate IS NULL OR S.SaleDate < DATEADD(day, -14, GETDATE()) GROUP BY D.DispensaryID, D.DispensaryName;
|
What is the lowest energy production cost for Solar Power Plants in Japan?
|
CREATE TABLE Solar_Power_Plants (project_id INT,location VARCHAR(50),energy_production_cost FLOAT); INSERT INTO Solar_Power_Plants (project_id,location,energy_production_cost) VALUES (1,'Japan',0.08),(2,'Japan',0.07),(3,'Japan',0.06),(4,'Japan',0.09);
|
SELECT MIN(energy_production_cost) FROM Solar_Power_Plants WHERE location = 'Japan';
|
What is the total funding allocated for climate mitigation projects in 2020?
|
CREATE TABLE climate_finance (project_name TEXT,project_type TEXT,allocation INTEGER,year INTEGER); INSERT INTO climate_finance (project_name,project_type,allocation,year) VALUES ('GreenTech Innovations','Mitigation',5000000,2020);
|
SELECT SUM(allocation) FROM climate_finance WHERE project_type = 'Mitigation' AND year = 2020;
|
Find the maximum number of virtual tour attendees in the Middle East in any month.
|
CREATE TABLE tour_attendees (id INT,location TEXT,attendees INT,tour_date DATE); INSERT INTO tour_attendees (id,location,attendees,tour_date) VALUES (1,'Dubai',25,'2022-01-01'),(2,'Abu Dhabi',30,'2022-02-10');
|
SELECT MAX(attendees) AS max_attendees FROM tour_attendees WHERE location LIKE '%Middle East%';
|
What are the freight forwarding costs for Route 2 and Route 6?
|
CREATE TABLE FreightForwarding (id INT,route VARCHAR(50),cost INT); INSERT INTO FreightForwarding (id,route,cost) VALUES (1,'Route 2',300),(2,'Route 6',800);
|
SELECT route, cost FROM FreightForwarding WHERE route IN ('Route 2', 'Route 6');
|
What is the minimum donation amount given on Giving Tuesday?
|
CREATE TABLE donations(id INT,donor_name TEXT,donation_amount FLOAT,donation_date DATE); INSERT INTO donations(id,donor_name,donation_amount,donation_date) VALUES (1,'James Lee',50,'2022-11-29'),(2,'Grace Kim',100,'2022-12-01'),(3,'Anthony Nguyen',25,'2022-11-29');
|
SELECT MIN(donation_amount) FROM donations WHERE donation_date = '2022-11-29';
|
Identify the indigenous communities in the Arctic region that are most affected by coastal erosion and their corresponding coastal erosion rates.
|
CREATE TABLE communities (community_id INT,community_name VARCHAR(50),region VARCHAR(50));CREATE TABLE erosion_data (measurement_id INT,measurement_date DATE,erosion_rate FLOAT,community_id INT);
|
SELECT c.community_name, AVG(ed.erosion_rate) AS avg_erosion_rate FROM communities c JOIN erosion_data ed ON c.community_id = ed.community_id WHERE c.region LIKE '%Arctic%' GROUP BY c.community_name ORDER BY avg_erosion_rate DESC;
|
What is the total liabilities value for clients in the healthcare sector who have liabilities greater than 200000?
|
CREATE TABLE clients (id INT,name VARCHAR(255),sector VARCHAR(255),liabilities DECIMAL(10,2)); INSERT INTO clients (id,name,sector,liabilities) VALUES (1,'Emma White','Healthcare',120000.00),(2,'Liam Black','Healthcare',180000.00),(3,'Noah Gray','Healthcare',220000.00),(4,'Olivia Brown','Healthcare',280000.00),(5,'Ethan Green','Technology',50000.00),(6,'Harper Blue','Retail',90000.00);
|
SELECT SUM(liabilities) FROM clients WHERE sector = 'Healthcare' AND liabilities > 200000.00;
|
What is the total recyclability rating of materials from the United Kingdom and Ireland?
|
CREATE TABLE materials (id INT PRIMARY KEY,name VARCHAR(255),origin VARCHAR(255),recyclability_rating FLOAT); INSERT INTO materials (id,name,origin,recyclability_rating) VALUES (1,'Recycled Plastic','UK',4.6),(2,'Reused Metal','Ireland',4.5),(3,'Eco-Friendly Paper','UK',4.7);
|
SELECT SUM(recyclability_rating) FROM materials WHERE origin IN ('UK', 'Ireland');
|
Determine the number of wildlife habitats in boreal forests with timber harvesting
|
CREATE TABLE wildlife_habitats (id INT,name VARCHAR(50),forest_id INT); INSERT INTO wildlife_habitats (id,name,forest_id) VALUES (1,'Wetlands',1),(2,'Grasslands',3),(3,'Forest',2),(4,'Scrublands',2);
|
SELECT COUNT(*) FROM wildlife_habitats wh JOIN forests f ON wh.forest_id = f.id WHERE f.type = 'boreal' AND EXISTS (SELECT 1 FROM harvests h WHERE h.forest_id = f.id);
|
What is the minimum R&D expenditure for drugs approved by the EMA since 2018?
|
CREATE TABLE drug_approval (drug_name VARCHAR(255),approval_body VARCHAR(255),approval_year INT); CREATE TABLE rd_expenditure (drug_name VARCHAR(255),rd_expenditure FLOAT); INSERT INTO drug_approval (drug_name,approval_body,approval_year) VALUES ('DrugA','EMA',2019),('DrugB','EMA',2018),('DrugC','EMA',2020),('DrugD','EMA',2019),('DrugE','EMA',2021); INSERT INTO rd_expenditure (drug_name,rd_expenditure) VALUES ('DrugA',45000000),('DrugB',35000000),('DrugC',55000000),('DrugD',40000000),('DrugE',60000000);
|
SELECT MIN(rd_expenditure) FROM rd_expenditure INNER JOIN drug_approval ON rd_expenditure.drug_name = drug_approval.drug_name WHERE drug_approval.approval_body = 'EMA' AND drug_approval.approval_year >= 2018;
|
What is the average water temperature in the Pacific Ocean for fish farms in May?
|
CREATE TABLE pacific_ocean (temperature FLOAT,month INT,year INT,PRIMARY KEY (temperature,month,year)); INSERT INTO pacific_ocean (temperature,month,year) VALUES (16.5,5,2021),(17.3,5,2022),(16.8,5,2023);
|
SELECT AVG(temperature) FROM pacific_ocean WHERE month = 5 AND region = 'Pacific Ocean';
|
What is the maximum number of failed login attempts in a single day for the 'guest' account in the last week?
|
CREATE TABLE LoginAttempts (id INT,username VARCHAR(255),date DATE,success BOOLEAN); INSERT INTO LoginAttempts (id,username,date,success) VALUES (7,'guest','2022-02-15',FALSE);
|
SELECT MAX(failed_attempts) FROM (SELECT COUNT(*) AS failed_attempts FROM LoginAttempts WHERE username = 'guest' AND success = FALSE AND date >= DATE_SUB(CURDATE(), INTERVAL 1 WEEK) GROUP BY date) AS subquery;
|
Which dams in the 'public_works' schema have a capacity lower than the dam named 'Hoover'?
|
CREATE TABLE dams (name VARCHAR(255),capacity INT); INSERT INTO dams (name,capacity) VALUES ('Dam1',5000000),('Dam2',6000000),('Hoover',7000000);
|
SELECT name FROM dams WHERE capacity < (SELECT capacity FROM dams WHERE name = 'Hoover');
|
Update 'product_cost' in 'product_inventory' table for product 'Bamboo Toothbrush' to '3.50'
|
CREATE TABLE product_inventory (product_name VARCHAR(255),product_cost DECIMAL(5,2));
|
UPDATE product_inventory SET product_cost = 3.50 WHERE product_name = 'Bamboo Toothbrush';
|
What is the average visit duration by destination?
|
CREATE TABLE if not exists destinations (destination_id int,destination_name varchar(50),region_id int); INSERT INTO destinations (destination_id,destination_name,region_id) VALUES (1,'Seattle',1),(2,'Portland',1),(3,'London',2); CREATE TABLE if not exists visitor_stats (visitor_id int,destination_id int,visit_date date,departure_date date); INSERT INTO visitor_stats (visitor_id,destination_id,visit_date,departure_date) VALUES (1,1,'2022-06-01','2022-06-04'),(2,1,'2022-06-03','2022-06-05'),(3,2,'2022-06-02','2022-06-06'),(4,3,'2022-06-04','2022-06-08'),(5,3,'2022-06-30','2022-07-02');
|
SELECT d.destination_name, AVG(DATEDIFF('day', visit_date, departure_date)) as avg_duration FROM destinations d JOIN visitor_stats vs ON d.destination_id = vs.destination_id GROUP BY d.destination_name;
|
What are the union names with labor rights advocacy activities in the 'central_region' and 'west_region'?
|
CREATE TABLE union_advocacy (union_name TEXT,region TEXT); INSERT INTO union_advocacy (union_name,region) VALUES ('Union A','central_region'),('Union E','west_region'),('Union B','south_region'),('Union F','central_region');
|
SELECT union_name FROM union_advocacy WHERE region IN ('central_region', 'west_region');
|
What is the total waste generation in grams for each country in 2020?
|
CREATE TABLE WasteGeneration (country VARCHAR(255),year INT,waste_generation FLOAT); INSERT INTO WasteGeneration (country,year,waste_generation) VALUES ('USA',2020,5000),('Canada',2020,4000),('Mexico',2020,3000);
|
SELECT country, SUM(waste_generation) FROM WasteGeneration WHERE year = 2020 GROUP BY country;
|
What is the total salary cost for the entire company?
|
SAME AS ABOVE
|
SELECT SUM(Employees.Salary) FROM Employees;
|
Which city has the most public libraries in the libraries table?
|
CREATE TABLE libraries (library_name VARCHAR(50),city VARCHAR(50),state VARCHAR(50),num_books_loaned INT);
|
SELECT city FROM libraries WHERE (SELECT COUNT(*) FROM libraries AS e2 WHERE libraries.city = e2.city) = (SELECT MAX(count_libs) FROM (SELECT city, COUNT(*) AS count_libs FROM libraries GROUP BY city) AS e3);
|
Get the names of all teams with an average ticket price above $130.
|
CREATE TABLE teams (id INT,name TEXT,city TEXT); INSERT INTO teams (id,name,city) VALUES (1,'Boston Celtics','Boston'),(2,'NY Knicks','NY'),(3,'LA Lakers','LA'),(4,'Atlanta Hawks','Atlanta'),(5,'Chicago Bulls','Chicago'),(6,'Golden State Warriors','San Francisco'); CREATE TABLE tickets (id INT,team TEXT,home_team TEXT,price DECIMAL(5,2)); INSERT INTO tickets (id,team,price) VALUES (1,'Boston Celtics',125.99),(2,'NY Knicks',130.99),(3,'LA Lakers',150.99),(4,'Atlanta Hawks',160.99),(5,'Chicago Bulls',110.99),(6,'Golden State Warriors',170.99);
|
SELECT DISTINCT team as name FROM tickets WHERE price > (SELECT AVG(price) FROM tickets);
|
How many community engagement events have been held in Peru?
|
CREATE TABLE Events (EventID INT,Name TEXT,Country TEXT,Type TEXT); INSERT INTO Events (EventID,Name,Country,Type) VALUES (1,'Festival de la Candelaria','Peru','Community Engagement'); INSERT INTO Events (EventID,Name,Country,Type) VALUES (2,'Mistura','Peru','Community Engagement');
|
SELECT COUNT(*) FROM Events WHERE Country = 'Peru' AND Type = 'Community Engagement';
|
What are the distinct carrier names that have shipped to port 'LA'?
|
CREATE TABLE ports (port_code CHAR(3),port_name VARCHAR(20)); INSERT INTO ports (port_code,port_name) VALUES ('LA','Los Angeles'),('NY','New York'); CREATE TABLE carriers (carrier_code CHAR(3),carrier_name VARCHAR(20)); INSERT INTO carriers (carrier_code,carrier_name) VALUES ('ABC','ABC Shipping'),('DEF','DEF Shipping'),('GHI','GHI Shipping'); CREATE TABLE shipments (carrier_code CHAR(3),port_code CHAR(3)); INSERT INTO shipments (carrier_code,port_code) VALUES ('ABC','LA'),('ABC','NY'),('DEF','LA'),('GHI','NY');
|
SELECT DISTINCT carriers.carrier_name FROM carriers JOIN shipments ON carriers.carrier_code = shipments.carrier_code JOIN ports ON shipments.port_code = ports.port_code WHERE ports.port_name = 'LA';
|
Insert a new record into the 'ocean_temperature' table with the following data: date '2022-03-01', temperature 25.5, location 'Pacific Ocean'
|
CREATE TABLE ocean_temperature (date DATE,temperature DECIMAL(5,2),location VARCHAR(50));
|
INSERT INTO ocean_temperature (date, temperature, location) VALUES ('2022-03-01', 25.5, 'Pacific Ocean');
|
What is the total spending on national security by country?
|
CREATE TABLE national_security_spending (id INT,country VARCHAR(255),year INT,amount DECIMAL(10,2)); INSERT INTO national_security_spending (id,country,year,amount) VALUES (1,'United States',2019,7000000000),(2,'China',2019,4000000000),(3,'Russia',2019,3000000000),(4,'United Kingdom',2019,2000000000);
|
SELECT country, SUM(amount) as total_spending FROM national_security_spending WHERE year = 2019 GROUP BY country;
|
What is the total number of members in unions that are involved in collective bargaining?
|
CREATE TABLE union_members (member_id INT,name VARCHAR(50),union_id INT); CREATE TABLE unions (union_id INT,union_name VARCHAR(50),involved_in_cb BOOLEAN); INSERT INTO union_members (member_id,name,union_id) VALUES (1,'John Doe',1),(2,'Jane Smith',1),(3,'Mike Johnson',2); INSERT INTO unions (union_id,union_name,involved_in_cb) VALUES (1,'Healthcare Workers Union',true),(2,'Teachers Union',false);
|
SELECT COUNT(DISTINCT um.union_id) FROM union_members um INNER JOIN unions u ON um.union_id = u.union_id WHERE u.involved_in_cb = true;
|
Who are the suppliers of items made from organic cotton?
|
CREATE TABLE items (id INT,name VARCHAR(50),material VARCHAR(50)); INSERT INTO items (id,name,material) VALUES (1,'Tote Bag','organic cotton'),(2,'Hoodie','organic cotton'),(3,'Backpack','recycled polyester'); CREATE TABLE supplier_items (id INT,supplier_id INT,item_id INT); INSERT INTO supplier_items (id,supplier_id,item_id) VALUES (1,1,1),(2,1,2),(3,2,3); CREATE TABLE suppliers (id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO suppliers (id,name,country) VALUES (1,'Green Trade','India'),(2,'EcoFriendly Co.','China'),(3,'Sustainable Source','Brazil');
|
SELECT suppliers.name FROM suppliers INNER JOIN supplier_items ON suppliers.id = supplier_items.supplier_id INNER JOIN items ON supplier_items.item_id = items.id WHERE items.material = 'organic cotton';
|
What is the maximum billing amount for cases in the 'Civil' category?
|
CREATE TABLE cases (case_id INT,attorney_id INT,category VARCHAR(20),billing_amount DECIMAL); INSERT INTO cases (case_id,attorney_id,category,billing_amount) VALUES (1,1,'Civil',500.00),(2,2,'Criminal',400.00),(3,1,'Civil',700.00),(4,3,'Civil',600.00);
|
SELECT MAX(billing_amount) FROM cases WHERE category = 'Civil';
|
What is the average number of building permits issued per month for commercial construction in the United Kingdom?
|
CREATE TABLE Permits_Over_Time (id INT,permit_number TEXT,permit_type TEXT,date DATE,location TEXT);
|
SELECT AVG(COUNT(*)) FROM Permits_Over_Time WHERE permit_type = 'Commercial' AND date >= DATE_SUB(CURRENT_DATE, INTERVAL 12 MONTH) AND location = 'United Kingdom' GROUP BY EXTRACT(YEAR_MONTH FROM date);
|
Update all records with the occupation 'Clerk' to 'Admin' in the 'union_contracts' table
|
CREATE TABLE union_contracts (id INT,worker_id INT,occupation VARCHAR(50),start_date DATE,end_date DATE); INSERT INTO union_contracts (id,worker_id,occupation,start_date,end_date) VALUES (1,1,'Engineer','2022-01-01','2023-12-31'),(2,2,'Clerk','2021-06-15','2022-06-14'),(3,3,'Clerk','2022-01-01','2023-12-31'),(4,4,'Engineer','2021-06-15','2022-06-14');
|
UPDATE union_contracts SET occupation = 'Admin' WHERE occupation = 'Clerk';
|
Insert a new row into the "funding" table for "GreenTech Solutions" with a funding amount of 5000000 and a funding date of 2022-06-15
|
CREATE TABLE funding (id INT PRIMARY KEY AUTO_INCREMENT,company_id INT,amount FLOAT,funding_date DATE);
|
INSERT INTO funding (company_id, amount, funding_date) VALUES ((SELECT id FROM company WHERE name = 'GreenTech Solutions'), 5000000, '2022-06-15');
|
Find the total ad spend by all brands in the 'tech' category on Instagram in the past year, along with the number of impressions generated.
|
CREATE TABLE ads (brand VARCHAR(20),category VARCHAR(20),platform VARCHAR(20),spend INT,impressions INT,date DATE); INSERT INTO ads VALUES ('BrandA','tech','Instagram',1000,5000,'2022-01-01'),('BrandB','fashion','Instagram',1500,7000,'2022-01-01');
|
SELECT SUM(a.spend) as total_spend, SUM(a.impressions) as total_impressions FROM ads a WHERE a.platform = 'Instagram' AND a.category = 'tech' AND a.date >= DATEADD(year, -1, GETDATE());
|
What is the average rating of hotels in 'Asia' that have been reviewed more than 50 times?
|
CREATE TABLE hotels (hotel_id INT,hotel_name VARCHAR(255),rating DECIMAL(2,1),country VARCHAR(255)); INSERT INTO hotels (hotel_id,hotel_name,rating,country) VALUES (1,'Hotel Tokyo',4.3,'Japan'),(2,'Hotel Mumbai',4.0,'India'),(3,'Hotel Bangkok',4.7,'Thailand');
|
SELECT AVG(rating) FROM (SELECT rating FROM hotels WHERE country = 'Asia' GROUP BY rating HAVING COUNT(*) > 50) AS subquery;
|
What is the average response time for emergency calls, categorized by incident type?
|
CREATE TABLE emergencies (eid INT,incident_type VARCHAR(255),response_time INT);
|
SELECT i.incident_type, AVG(e.response_time) FROM emergencies e INNER JOIN incidents i ON e.eid = i.iid GROUP BY i.incident_type;
|
List all concerts in the United States that had a higher revenue than the average revenue in California.
|
CREATE TABLE Concerts (id INT,state VARCHAR(50),revenue FLOAT);
|
SELECT * FROM Concerts WHERE revenue > (SELECT AVG(revenue) FROM Concerts WHERE state = 'California') AND state = 'United States';
|
What is the total number of visitors who attended exhibitions in the 'History' category, and the percentage of visitors who attended each exhibition in this category?
|
CREATE TABLE Exhibitions (id INT,name VARCHAR(20),category VARCHAR(20),visitors INT); INSERT INTO Exhibitions VALUES (1,'Exhibition A','Art',3000),(2,'Exhibition B','Science',2000),(3,'Exhibition C','Art',4000),(4,'Exhibition D','History',5000); CREATE TABLE Visitors (id INT,exhibition_id INT,age INT,country VARCHAR(20)); INSERT INTO Visitors VALUES (1,1,35,'USA'),(2,1,45,'Canada'),(3,2,25,'Mexico'),(4,3,50,'Brazil'),(5,3,30,'USA');
|
SELECT E.category, E.name, SUM(E.visitors) AS total_visitors, (SUM(E.visitors) * 100.0 / (SELECT SUM(visitors) FROM Exhibitions WHERE category = 'History')) AS percentage FROM Exhibitions E INNER JOIN Visitors V ON E.id = V.exhibition_id WHERE E.category = 'History' GROUP BY E.category, E.name;
|
Update the disability type for all students with IDs between 100 and 200 to 'Learning'
|
CREATE TABLE Students (StudentID INT PRIMARY KEY,Name VARCHAR(50),Disability VARCHAR(20));
|
UPDATE Students SET Disability = 'Learning' WHERE StudentID BETWEEN 100 AND 200;
|
What is the maximum and minimum rating of hotels in 'Africa' with a gym?
|
CREATE TABLE hotel_ratings (hotel_id INT,country TEXT,rating FLOAT,has_gym BOOLEAN); INSERT INTO hotel_ratings (hotel_id,country,rating,has_gym) VALUES (1,'Egypt',4.2,true),(2,'Morocco',4.5,false),(3,'South Africa',4.7,true),(4,'Egypt',4.3,false),(5,'Kenya',4.6,true);
|
SELECT MAX(rating) as max_rating, MIN(rating) as min_rating FROM hotel_ratings WHERE country LIKE 'Africa%' AND has_gym = true;
|
What is the total number of registered users from each country?
|
CREATE TABLE users (id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO users (id,name,country) VALUES (1,'John Doe','USA'),(2,'Jane Smith','Canada'),(3,'Pedro Martinez','Mexico');
|
SELECT country, COUNT(*) OVER (PARTITION BY country) as total_users FROM users;
|
What is the minimum recycling rate for the top 3 most populous countries in Africa?
|
CREATE TABLE RecyclingRates (country VARCHAR(50),recycling_rate FLOAT); INSERT INTO RecyclingRates (country,recycling_rate) VALUES ('Nigeria',0.15),('Egypt',0.2),('South Africa',0.35);
|
SELECT MIN(recycling_rate) FROM (SELECT * FROM RecyclingRates WHERE country IN ('Nigeria', 'Egypt', 'South Africa') ORDER BY recycling_rate DESC LIMIT 3);
|
List the total number of cargo items handled at each port, including ports that have not handled any cargo. Display the port name and its corresponding total cargo count, even if the count is zero.
|
CREATE TABLE ports(port_id INT,port_name TEXT);CREATE TABLE cargo(cargo_id INT,port_id INT);INSERT INTO ports VALUES (1,'Port A'),(2,'Port B'),(3,'Port C'),(4,'Port D'),(5,'Port E');INSERT INTO cargo VALUES (1,1),(2,1),(3,2),(4,3),(5,5);
|
SELECT p.port_name, COUNT(c.cargo_id) as total_cargo FROM ports p LEFT JOIN cargo c ON p.port_id = c.port_id GROUP BY p.port_id;
|
What is the minimum assets value for customers in 'North America'?
|
CREATE TABLE customers (id INT,name VARCHAR(50),region VARCHAR(20),assets DECIMAL(10,2)); INSERT INTO customers (id,name,region,assets) VALUES (1,'John Doe','Southwest',50000.00),(2,'Jane Smith','Northeast',75000.00),(3,'Michael Johnson','North America',30000.00),(4,'Sarah Lee','North America',40000.00);
|
SELECT MIN(assets) FROM customers WHERE region = 'North America';
|
Identify vessels that have handled cargo at both the ports of 'Hong Kong' and 'Shanghai'.
|
CREATE TABLE vessels (vessel_id INT,vessel_name VARCHAR(50),type VARCHAR(50)); CREATE TABLE cargo (cargo_id INT,vessel_id INT,port_id INT,weight FLOAT,handling_date DATE);
|
SELECT v.vessel_name FROM vessels v JOIN cargo c ON v.vessel_id = c.vessel_id WHERE c.port_id IN (SELECT port_id FROM ports WHERE port_name = 'Hong Kong') AND c.port_id IN (SELECT port_id FROM ports WHERE port_name = 'Shanghai') GROUP BY v.vessel_name HAVING COUNT(DISTINCT c.port_id) = 2;
|
What is the total number of visitors who attended exhibitions in Tokyo?
|
CREATE TABLE exhibitions (id INT,city VARCHAR(50),visitor_count INT); INSERT INTO exhibitions (id,city,visitor_count) VALUES (1,'Tokyo',100),(2,'Tokyo',200),(3,'Tokyo',300);
|
SELECT city, SUM(visitor_count) FROM exhibitions WHERE city = 'Tokyo';
|
What is the average attendance for ice hockey games in the Northeast in the 2020 season?
|
CREATE TABLE ice_hockey_games(id INT,team VARCHAR(50),location VARCHAR(50),year INT,attendance INT); INSERT INTO ice_hockey_games(id,team,location,year,attendance) VALUES (1,'Boston Bruins','TD Garden',2020,17500),(2,'Buffalo Sabres','KeyBank Center',2020,15000),(3,'Montreal Canadiens','Bell Centre',2020,21000);
|
SELECT AVG(attendance) FROM ice_hockey_games WHERE location IN ('TD Garden', 'KeyBank Center', 'Bell Centre') AND year = 2020;
|
Get the total number of VR headsets sold in Canada and the United Kingdom
|
CREATE TABLE VRAdoption (Region VARCHAR(20),HeadsetsSold INT); INSERT INTO VRAdoption (Region,HeadsetsSold) VALUES ('Canada',80000),('United States',500000),('United Kingdom',150000);
|
SELECT SUM(HeadsetsSold) FROM VRAdoption WHERE Region IN ('Canada', 'United Kingdom')
|
Which country in the 'Asia-Pacific' region has the most virtual tour engagements?
|
CREATE TABLE virtual_tours (id INT,hotel_id INT,country TEXT,engagements INT); INSERT INTO virtual_tours (id,hotel_id,country,engagements) VALUES (1,1,'Japan',300),(2,2,'Australia',450),(3,3,'New Zealand',500),(4,4,'China',250); CREATE TABLE hotels (id INT,name TEXT,region TEXT); INSERT INTO hotels (id,name,region) VALUES (1,'Hotel A','Asia-Pacific'),(2,'Hotel B','Asia-Pacific'),(3,'Hotel C','Asia-Pacific'),(4,'Hotel D','Asia-Pacific');
|
SELECT country, MAX(engagements) FROM virtual_tours v JOIN hotels h ON v.hotel_id = h.id WHERE h.region = 'Asia-Pacific' GROUP BY country;
|
How many parking tickets were issued by gender in San Francisco?
|
CREATE TABLE ParkingTickets (ID INT,Gender VARCHAR(50),City VARCHAR(50)); INSERT INTO ParkingTickets VALUES (1,'Male','San Francisco'),(2,'Female','San Francisco'),(3,'Other','San Francisco');
|
SELECT Gender, COUNT(*) OVER (PARTITION BY Gender) AS Count FROM ParkingTickets WHERE City = 'San Francisco';
|
What is the maximum cost of a project in the 'Buildings' category?
|
CREATE TABLE InfrastructureProjects (id INT,category VARCHAR(20),cost FLOAT); INSERT INTO InfrastructureProjects (id,category,cost) VALUES (1,'Roads',500000),(2,'Bridges',750000),(3,'Buildings',900000);
|
SELECT MAX(cost) FROM InfrastructureProjects WHERE category = 'Buildings';
|
Identify the top 3 animal populations in the 'animal_population' table
|
CREATE TABLE animal_population (species VARCHAR(50),animal_count INT);
|
SELECT species, SUM(animal_count) as total FROM animal_population GROUP BY species ORDER BY total DESC LIMIT 3;
|
Create a view with athletes above 25
|
CREATE TABLE athlete_wellbeing (athlete_id INT PRIMARY KEY,name VARCHAR(100),age INT,sport VARCHAR(50),wellbeing_score INT); INSERT INTO athlete_wellbeing (athlete_id,name,age,sport,wellbeing_score) VALUES (1,'Aisha Smith',25,'Basketball',80);
|
CREATE VIEW athlete_view AS SELECT * FROM athlete_wellbeing WHERE age > 25;
|
How many people attended the 'Poetry Slam' event by age group?
|
CREATE TABLE Events (event_id INT,event_name VARCHAR(50)); CREATE TABLE Attendees (attendee_id INT,event_id INT,age INT); INSERT INTO Events (event_id,event_name) VALUES (3,'Poetry Slam'); INSERT INTO Attendees (attendee_id,event_id,age) VALUES (4,3,18),(5,3,28),(6,3,38);
|
SELECT e.event_name, a.age, COUNT(a.attendee_id) FROM Events e JOIN Attendees a ON e.event_id = a.event_id WHERE e.event_name = 'Poetry Slam' GROUP BY e.event_name, a.age;
|
What is the average price of products made from each material?
|
CREATE TABLE products (product_id INT,name VARCHAR(255),material VARCHAR(50),price DECIMAL(5,2)); INSERT INTO products (product_id,name,material,price) VALUES (1,'T-Shirt','Recycled Polyester',19.99),(2,'Hoodie','Organic Cotton',49.99),(3,'Pants','Tencel',39.99),(4,'Shorts','Hemp',29.99),(5,'Dress','Bamboo Viscose',59.99),(6,'Skirt','Recycled Polyester',24.99);
|
SELECT material, AVG(price) FROM products GROUP BY material;
|
What is the total number of attendees for performing arts events and workshops, excluding repeat attendees?
|
CREATE TABLE events (id INT,type VARCHAR(20)); INSERT INTO events (id,type) VALUES (1,'Theater'),(2,'Dance'),(3,'Workshop'); CREATE TABLE attendees (id INT,event_id INT); INSERT INTO attendees (id,event_id) VALUES (1,1),(2,1),(3,2),(1,3),(4,2);
|
SELECT COUNT(DISTINCT a.id) FROM attendees a JOIN events e ON a.event_id = e.id WHERE e.type IN ('Theater', 'Workshop');
|
What is the total playtime (in minutes) for each game in the "MobileGamingCommunity"?
|
CREATE TABLE Games (GameID INT PRIMARY KEY,GameName VARCHAR(50),GamingCommunity VARCHAR(50)); CREATE TABLE GameSessions (SessionID INT PRIMARY KEY,GameName VARCHAR(50),Playtime MINUTE,FOREIGN KEY (GameName) REFERENCES Games(GameName)); INSERT INTO Games (GameID,GameName,GamingCommunity) VALUES (1,'ClashOfClans','MobileGamingCommunity'),(2,'PUBGMobile','MobileGamingCommunity'),(3,'FortniteMobile','MobileGamingCommunity'); INSERT INTO GameSessions (SessionID,GameName,Playtime) VALUES (1,'ClashOfClans',120),(2,'ClashOfClans',150),(3,'PUBGMobile',200),(4,'FortniteMobile',250);
|
SELECT GameName, SUM(Playtime) FROM GameSessions JOIN Games ON GameSessions.GameName = Games.GameName WHERE Games.GamingCommunity = 'MobileGamingCommunity' GROUP BY GameName;
|
Update records in landfill_capacity table where capacity is less than 20000 tons
|
CREATE TABLE landfill_capacity (location VARCHAR(50),capacity INT);
|
UPDATE landfill_capacity SET capacity = capacity + 5000 WHERE capacity < 20000;
|
What is the average age of players who have won an esports event in North America?
|
CREATE TABLE Players (PlayerID INT,Age INT,Country VARCHAR(255)); INSERT INTO Players (PlayerID,Age,Country) VALUES (1,25,'USA'); INSERT INTO Players (PlayerID,Age,Country) VALUES (2,30,'Canada'); CREATE TABLE Events (EventID INT,Location VARCHAR(255)); INSERT INTO Events (EventID,Location) VALUES (1,'New York'); INSERT INTO Events (EventID,Location) VALUES (2,'Toronto'); CREATE TABLE Winners (PlayerID INT,EventID INT); INSERT INTO Winners (PlayerID,EventID) VALUES (1,1); INSERT INTO Winners (PlayerID,EventID) VALUES (2,2);
|
SELECT AVG(Players.Age) FROM Players INNER JOIN Winners ON Players.PlayerID = Winners.PlayerID INNER JOIN Events ON Winners.EventID = Events.EventID WHERE Events.Location LIKE '%North America%';
|
Rank the highways in Australia by length.
|
CREATE TABLE highways (id INT,name TEXT,length_km FLOAT,location TEXT,built YEAR); INSERT INTO highways (id,name,length_km,location,built) VALUES (1,'Autobahn A9',530.5,'Germany',1936); INSERT INTO highways (id,name,length_km,location,built) VALUES (2,'I-90',498.7,'USA',1956); INSERT INTO highways (id,name,length_km,location,built) VALUES (3,'Trans-Canada',7821,'Canada',1962); INSERT INTO highways (id,name,length_km,location,built) VALUES (4,'Hume',820,'Australia',1928);
|
SELECT name, length_km, RANK() OVER(ORDER BY length_km DESC) as length_rank FROM highways WHERE location = 'Australia';
|
Which mobile subscribers have a subscription type of 'Postpaid'?
|
CREATE TABLE mobile_subscribers (subscriber_id INT,subscription_type VARCHAR(50)); INSERT INTO mobile_subscribers (subscriber_id,subscription_type) VALUES (1,'Postpaid'),(2,'Prepaid');
|
SELECT subscriber_id FROM mobile_subscribers WHERE subscription_type = 'Postpaid';
|
What is the maximum crime severity score in each year?
|
CREATE TABLE crimes (id INT,crime_date DATE,severity_score FLOAT); INSERT INTO crimes VALUES (1,'2021-01-01',8.5),(2,'2022-01-01',9.2);
|
SELECT YEAR(crime_date) AS year, MAX(severity_score) FROM crimes GROUP BY year;
|
What is the installed capacity and location of renewable energy projects with certification level?
|
CREATE TABLE renewable_energy_projects (project_id INT,project_name VARCHAR(50),city VARCHAR(50),installed_capacity FLOAT,certification_level VARCHAR(50)); INSERT INTO renewable_energy_projects (project_id,project_name,city,installed_capacity,certification_level) VALUES (1,'Solar Farm 1','CityA',10000.0,'Gold'),(2,'Wind Farm 1','CityB',15000.0,'Platinum'),(3,'Hydro Plant 1','CityA',20000.0,'Silver');
|
SELECT city, installed_capacity, certification_level FROM renewable_energy_projects;
|
What is the average age of all employees working in mining operations across Canada, Peru, and Chile?
|
CREATE TABLE mining_operations (id INT,location VARCHAR(50)); INSERT INTO mining_operations (id,location) VALUES (1,'Canada'),(2,'Peru'),(3,'Chile'); CREATE TABLE employees (id INT,age INT,position VARCHAR(50),operation_id INT); INSERT INTO employees (id,age,position,operation_id) VALUES (1,35,'Engineer',1),(2,42,'Manager',1),(3,28,'Operator',2),(4,31,'Supervisor',3);
|
SELECT AVG(e.age) FROM employees e INNER JOIN mining_operations m ON e.operation_id = m.id WHERE m.location IN ('Canada', 'Peru', 'Chile');
|
Delete all records from the 'space_missions' table that are not related to Mars exploration
|
CREATE TABLE space_missions (id INT PRIMARY KEY,name VARCHAR(50),objective VARCHAR(50)); INSERT INTO space_missions (id,name,objective) VALUES (1,'Mars Pathfinder','Mars exploration'),(2,'Galileo','Jupiter exploration'),(3,'Cassini-Huygens','Saturn exploration'),(4,'Voyager 1','Interstellar mission'),(5,'New Horizons','Pluto exploration');
|
DELETE FROM space_missions WHERE objective NOT LIKE '%Mars exploration%';
|
What is the average number of traditional art performances per year in Japan, partitioned by region?
|
CREATE TABLE Regions (Region VARCHAR(255)); INSERT INTO Regions (Region) VALUES ('Hokkaido'),('Tohoku'),('Kanto'),('Chubu'),('Kansai'),('Chugoku'),('Shikoku'),('Kyushu'); CREATE TABLE Performances (PerformanceID INT,Name VARCHAR(255),Region VARCHAR(255),Year INT,PRIMARY KEY (PerformanceID));
|
SELECT Region, AVG(Year) AS AvgYear FROM (SELECT Region, YEAR(PerformanceDate) AS Year, ROW_NUMBER() OVER (PARTITION BY Region ORDER BY YEAR(PerformanceDate)) AS RN FROM Performances) AS PerformancesPerYear WHERE RN = 1 GROUP BY Region;
|
What is the failure rate of rocket engines by type?
|
CREATE TABLE Rocket_Engine_Types (ID INT,Engine_Type VARCHAR(20),Failure_Rate DECIMAL(5,2)); INSERT INTO Rocket_Engine_Types (ID,Engine_Type,Failure_Rate) VALUES (1,'Kerosene',0.05),(2,'Liquid Hydrogen',0.02),(3,'Solid',0.01);
|
SELECT Engine_Type, Failure_Rate FROM Rocket_Engine_Types;
|
Insert new traditional art records for 'Kente Cloth' and 'Batik'
|
CREATE TABLE TraditionalArts (Id INT,Art TEXT,Description TEXT);
|
INSERT INTO TraditionalArts (Id, Art, Description) VALUES (1, 'Kente Cloth', 'Handwoven fabric from Ghana'), (2, 'Batik', 'Indonesian art of wax-resist dyeing');
|
List all the unique defense contract categories and their total spending?
|
CREATE TABLE Spending_Categories (id INT,category VARCHAR(50),amount FLOAT); INSERT INTO Spending_Categories (id,category,amount) VALUES (1,'Threat Intelligence',500000),(2,'Incident Response',750000); CREATE TABLE Spending_Mapping (spending_id INT,category_id INT); INSERT INTO Spending_Mapping (spending_id,category_id) VALUES (1,1),(2,2),(3,1);
|
SELECT Spending_Categories.category, SUM(Spending_Mapping.spending_id) AS total_spending FROM Spending_Categories JOIN Spending_Mapping ON Spending_Categories.id = Spending_Mapping.category_id GROUP BY Spending_Categories.category;
|
Retrieve the ID, name, and department of employees who were hired after the latest hire date in the 'Finance' department, excluding employees from the 'Finance' department.
|
CREATE TABLE Employees (EmployeeID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50),HireDate DATE); INSERT INTO Employees (EmployeeID,FirstName,LastName,Department,HireDate) VALUES (1,'Tony','Stark','Finance','2021-06-12');
|
SELECT EmployeeID, FirstName, Department FROM Employees WHERE Department <> 'Finance' AND HireDate > (SELECT MAX(HireDate) FROM Employees WHERE Department = 'Finance');
|
List the names of carbon offset projects that started after 2021-06-30 and were completed before 2023-01-01.
|
CREATE TABLE if not exists carbon_offset_projects (project_id INT PRIMARY KEY,project_name VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO carbon_offset_projects (project_id,project_name,start_date,end_date) VALUES (1,'Reforestation','2022-07-01','2023-01-01'),(2,'Soil Carbon Sequestration','2021-07-15','2022-12-31'),(3,'Blue Carbon','2023-02-01','2024-01-31');
|
SELECT project_name FROM carbon_offset_projects WHERE start_date > '2021-06-30' AND end_date < '2023-01-01';
|
How many climate communication campaigns were launched in each country during 2021?
|
CREATE TABLE climate_communication (campaign_name VARCHAR(255),country VARCHAR(255),launch_date DATE);
|
SELECT country, COUNT(DISTINCT campaign_name) FROM climate_communication WHERE EXTRACT(YEAR FROM launch_date) = 2021 GROUP BY country;
|
What is the total amount of waste generated in the year 2018 in the residential sector?
|
CREATE TABLE waste_generation (id INT,sector VARCHAR(20),year INT,waste_generated FLOAT); INSERT INTO waste_generation (id,sector,year,waste_generated) VALUES (1,'residential',2018,120.2),(2,'residential',2017,110.1),(3,'commercial',2018,180.5);
|
SELECT SUM(waste_generated) FROM waste_generation WHERE sector = 'residential' AND year = 2018;
|
List all the railways along with their lengths from the 'railway_info' and 'railway_lengths' tables.
|
CREATE TABLE railway_info (railway_id INT,railway_name VARCHAR(50)); CREATE TABLE railway_lengths (railway_id INT,railway_length INT); INSERT INTO railway_info (railway_id,railway_name) VALUES (1,'Trans-Siberian Railway'),(2,'California High-Speed Rail'),(3,'China Railway High-speed'); INSERT INTO railway_lengths (railway_id,railway_length) VALUES (1,9289),(2,1300),(3,25000);
|
SELECT railway_info.railway_name, railway_lengths.railway_length FROM railway_info INNER JOIN railway_lengths ON railway_info.railway_id = railway_lengths.railway_id;
|
How many clinical trials are ongoing or have been completed for drug Z in France?
|
CREATE TABLE clinical_trials (id INT,drug VARCHAR(255),country VARCHAR(255),status VARCHAR(255)); INSERT INTO clinical_trials (id,drug,country,status) VALUES (1,'Drug Z','France','Completed');
|
SELECT COUNT(*) FROM clinical_trials WHERE drug = 'Drug Z' AND country = 'France' AND status IN ('Completed', 'Ongoing');
|
How many medical examinations have been conducted on each astronaut?
|
CREATE TABLE Astronauts (AstronautID INT,Name VARCHAR(50),Age INT,CountryOfOrigin VARCHAR(50)); INSERT INTO Astronauts (AstronautID,Name,Age,CountryOfOrigin) VALUES (1,'Anna Ivanova',35,'Russia'),(2,'John Doe',45,'USA'),(3,'Pedro Gomez',50,'Mexico'); CREATE TABLE MedicalExaminations (ExaminationID INT,AstronautID INT,ExaminationDate DATE); INSERT INTO MedicalExaminations (ExaminationID,AstronautID,ExaminationDate) VALUES (1,1,'2020-01-01'),(2,1,'2021-01-01'),(3,2,'2020-01-01'),(4,3,'2021-01-01');
|
SELECT Astronauts.Name, COUNT(*) FROM Astronauts INNER JOIN MedicalExaminations ON Astronauts.AstronautID = MedicalExaminations.AstronautID GROUP BY Astronauts.Name;
|
What is the total claim amount for policyholders living in 'New York'?
|
CREATE TABLE Claims (PolicyholderID INT,ClaimAmount DECIMAL(10,2),PolicyState VARCHAR(20)); INSERT INTO Claims (PolicyholderID,ClaimAmount,PolicyState) VALUES (7,1200,'New York'),(8,1500,'New York');
|
SELECT SUM(ClaimAmount) FROM Claims WHERE PolicyState = 'New York';
|
Which Shariah-compliant banks have the highest number of loans in Turkey?
|
CREATE TABLE shariah_compliant_banks (id INT,bank_name VARCHAR(50),country VARCHAR(50),num_loans INT); INSERT INTO shariah_compliant_banks (id,bank_name,country,num_loans) VALUES (1,'Kuveyt Turk Participation Bank','Turkey',5000),(2,'Albaraka Turk Participation Bank','Turkey',6000);
|
SELECT country, bank_name, num_loans, RANK() OVER (ORDER BY num_loans DESC) as rank FROM shariah_compliant_banks WHERE country = 'Turkey';
|
What is the total number of male and female volunteers and staff in the organization?
|
CREATE TABLE org_roles (role VARCHAR(10),gender VARCHAR(6),count INT); INSERT INTO org_roles (role,gender,count) VALUES ('Volunteer','Female',20),('Volunteer','Male',10),('Staff','Female',25),('Staff','Male',15);
|
SELECT gender, SUM(count) FROM org_roles GROUP BY gender;
|
What is the total amount of waste generation in kg for each waste type in 'RuralArea' in 2021?
|
CREATE TABLE waste_generation(waste_type VARCHAR(50),location VARCHAR(50),year INT,amount FLOAT); INSERT INTO waste_generation(waste_type,location,year,amount) VALUES('Plastic','RuralArea',2021,10000),('Paper','RuralArea',2021,12000),('Glass','RuralArea',2021,15000),('Metal','RuralArea',2021,18000);
|
SELECT waste_type, SUM(amount) FROM waste_generation WHERE location = 'RuralArea' AND year = 2021 GROUP BY waste_type;
|
What is the total number of emergency incidents in each borough of New York City in 2022?
|
CREATE TABLE emergency_incidents (id INT,borough VARCHAR(255),incident_type VARCHAR(255),reported_date DATE); INSERT INTO emergency_incidents (id,borough,incident_type,reported_date) VALUES (1,'Manhattan','Fire','2022-01-01'); INSERT INTO emergency_incidents (id,borough,incident_type,reported_date) VALUES (2,'Brooklyn','Medical Emergency','2022-01-02');
|
SELECT borough, SUM(number_of_incidents) FROM (SELECT borough, COUNT(*) as number_of_incidents FROM emergency_incidents WHERE borough IN ('Manhattan', 'Brooklyn', 'Queens', 'Bronx', 'Staten Island') AND reported_date >= '2022-01-01' AND reported_date < '2023-01-01' GROUP BY borough) as incidents_by_borough GROUP BY borough;
|
Delete 'Trial002' from 'ClinicalTrials' table.
|
CREATE TABLE ClinicalTrials (clinical_trial_id TEXT,medicine_name TEXT); INSERT INTO ClinicalTrials (clinical_trial_id,medicine_name) VALUES ('Trial002','DrugY');
|
DELETE FROM ClinicalTrials WHERE clinical_trial_id = 'Trial002';
|
What was the total cost of all infrastructure projects in Bangladesh in 2018?
|
CREATE TABLE Infrastructure_Projects_Bangladesh (id INT,country VARCHAR(50),year INT,cost FLOAT); INSERT INTO Infrastructure_Projects_Bangladesh (id,country,year,cost) VALUES (1,'Bangladesh',2018,120000.0),(2,'Bangladesh',2019,150000.0),(3,'Bangladesh',2020,130000.0);
|
SELECT SUM(cost) FROM Infrastructure_Projects_Bangladesh WHERE country = 'Bangladesh' AND year = 2018;
|
Update the number of beds in Rural Health Center D in Guam to 50.
|
CREATE TABLE health_centers (id INT,name TEXT,location TEXT,beds INT); INSERT INTO health_centers (id,name,location,beds) VALUES (1,'Health Center A','Rural Alaska',25); INSERT INTO health_centers (id,name,location,beds) VALUES (4,'Health Center D','Rural Guam',40);
|
UPDATE health_centers SET beds = 50 WHERE name = 'Health Center D' AND location = 'Rural Guam';
|
What is the total number of employees, contractors, and interns in the mining industry?
|
CREATE TABLE employees (id INT,name VARCHAR(50),role VARCHAR(50)); INSERT INTO employees (id,name,role) VALUES (1,'John Doe','Employee'),(2,'Jane Smith','Contractor'),(3,'Alice Johnson','Intern');
|
SELECT SUM(CASE WHEN role = 'Employee' THEN 1 ELSE 0 END) AS employees, SUM(CASE WHEN role = 'Contractor' THEN 1 ELSE 0 END) AS contractors, SUM(CASE WHEN role = 'Intern' THEN 1 ELSE 0 END) AS interns FROM employees;
|
What is the average water temperature and pH level for all marine life habitats?
|
CREATE TABLE marine_life_habitats (id INT,name VARCHAR(255),water_temp DECIMAL(5,2),ph DECIMAL(3,2)); INSERT INTO marine_life_habitats (id,name,water_temp,ph) VALUES (1,'Coral Reef',28.5,8.2),(2,'Open Ocean',18.0,8.0),(3,'Estuary',22.0,7.5);
|
SELECT AVG(water_temp) AS avg_water_temp, AVG(ph) AS avg_ph FROM marine_life_habitats;
|
What is the average donation amount from donors in California?
|
CREATE TABLE donors (id INT,name TEXT,state TEXT,donation_amount DECIMAL); INSERT INTO donors (id,name,state,donation_amount) VALUES (1,'John Doe','California',150.00),(2,'Jane Smith','Texas',200.00);
|
SELECT AVG(donation_amount) FROM donors WHERE state = 'California';
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.