instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Display the total budget allocated to animal conservation in each country
CREATE TABLE conservation_projects (id INT,name VARCHAR(255),location_country VARCHAR(20),budget DECIMAL(10,2)); INSERT INTO conservation_projects (id,name,location_country,budget) VALUES (1,'Habitat Restoration','Kenya',50000),(2,'Wildlife Corridors','Tanzania',75000),(3,'Wetlands Conservation','India',60000),(4,'Forest Protection','Brazil',45000),(5,'Savannah Conservation','South Africa',80000),(6,'Mangrove Preservation','Indonesia',65000),(7,'Sea Turtle Rescue','Australia',35000);
SELECT location_country, SUM(budget) as total_budget FROM conservation_projects GROUP BY location_country;
List all union members from the 'construction' industry in New York.
CREATE TABLE union_members (id INT,name VARCHAR(50),union_id INT,industry VARCHAR(20)); INSERT INTO union_members (id,name,union_id,industry) VALUES (1,'John Doe',123,'construction'),(2,'Jane Smith',456,'retail'),(3,'Mike Johnson',789,'construction');
SELECT name, industry FROM union_members WHERE industry = 'construction' AND state = 'New York';
Insert new recycling rate records for the 'Coastal' region in 2023 with a recycling rate of 45%.
CREATE TABLE recycling_rates(region VARCHAR(20),year INT,recycling_rate FLOAT);
INSERT INTO recycling_rates(region, year, recycling_rate) VALUES('Coastal', 2023, 45);
What is the total research grant amount awarded to each graduate program in the 'arts' discipline?
CREATE TABLE graduate_programs (program_id INT,program_name VARCHAR(50),discipline VARCHAR(50)); INSERT INTO graduate_programs (program_id,program_name,discipline) VALUES (1,'Fine Arts','arts'),(2,'Theater','arts'); CREATE TABLE research_grants (grant_id INT,program_id INT,grant_amount DECIMAL(10,2)); INSERT INTO research_grants (grant_id,program_id,grant_amount) VALUES (1,1,50000),(2,1,75000),(3,2,35000);
SELECT program_name, SUM(grant_amount) as total_grant_amount FROM graduate_programs JOIN research_grants ON graduate_programs.program_id = research_grants.program_id WHERE discipline = 'arts' GROUP BY program_name;
What percentage of products are certified vegan?
CREATE TABLE products (product_id INT,certified_vegan BOOLEAN); INSERT INTO products VALUES (1,true),(2,false),(3,false),(4,true),(5,true),(6,false),(7,true),(8,false),(9,true),(10,false);
SELECT (COUNT(p.certified_vegan) * 100.0 / (SELECT COUNT(*) FROM products)) AS vegan_percentage FROM products p WHERE p.certified_vegan = true;
How many peacekeeping operations has each country participated in over the last 20 years?
CREATE TABLE Peacekeeping_Operations (id INT,country VARCHAR(50),year INT); CREATE TABLE Countries (id INT,name VARCHAR(50),region VARCHAR(50));
SELECT co.name, COUNT(po.year) FROM Peacekeeping_Operations po INNER JOIN Countries co ON po.country = co.name WHERE po.year BETWEEN (YEAR(CURRENT_DATE) - 20) AND YEAR(CURRENT_DATE) GROUP BY co.name;
Calculate the total number of tours for each guide who has conducted cultural heritage tours, in 2023, and find the guide with the most tours.
CREATE TABLE Guides (id INT,name TEXT,city TEXT,country TEXT);CREATE TABLE Tours (id INT,guide_id INT,date DATE,cultural_heritage BOOLEAN);
SELECT guide_id, SUM(tours_per_guide) FROM (SELECT guide_id, COUNT(*) AS tours_per_guide FROM Tours WHERE YEAR(date) = 2023 AND cultural_heritage = TRUE GROUP BY guide_id) AS Subquery GROUP BY guide_id ORDER BY SUM(tours_per_guide) DESC LIMIT 1;
What is the average cost of sustainable construction materials in the 'materials' table?
CREATE TABLE materials (material_name VARCHAR(30),is_sustainable BOOLEAN,cost FLOAT); INSERT INTO materials (material_name,is_sustainable,cost) VALUES ('Bamboo Flooring',TRUE,10); INSERT INTO materials (material_name,is_sustainable,cost) VALUES ('Concrete',FALSE,15);
SELECT AVG(cost) FROM materials WHERE is_sustainable = TRUE;
What is the percentage of teachers who have completed a professional development course in the last year?
CREATE TABLE teachers (teacher_id INT,first_name VARCHAR(255),last_name VARCHAR(255)); CREATE TABLE courses (course_id INT,course_name VARCHAR(255),completion_date DATE); CREATE TABLE teacher_courses (teacher_id INT,course_id INT);
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM teachers)) AS percentage FROM teacher_courses tc JOIN courses c ON tc.course_id = c.course_id WHERE c.completion_date >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR);
How many artists from each country are represented in the museums of Berlin?
CREATE TABLE Museums_Artists (museum VARCHAR(30),artist VARCHAR(30),country VARCHAR(20)); INSERT INTO Museums_Artists (museum,artist,country) VALUES ('Berlin Museum','Klee','German'),('Berlin Museum','Kandinsky','Russian'),('Berlin Museum','Pollock','American'),('Berlin Gallery','Munch','Norwegian'),('Berlin Gallery','Matisse','French');
SELECT country, COUNT(*) FROM Museums_Artists WHERE museum = 'Berlin Museum' OR museum = 'Berlin Gallery' GROUP BY country;
What is the total number of high severity vulnerabilities that have been seen more than once since January 2022?
CREATE TABLE vulnerabilities (id INT,title VARCHAR(255),description TEXT,severity VARCHAR(50),last_seen DATETIME); INSERT INTO vulnerabilities (id,title,description,severity,last_seen) VALUES (1,'Cross-site Scripting','Allows attackers to inject malicious scripts...','High','2022-01-01 10:00:00');
SELECT severity, COUNT(*) as total FROM vulnerabilities WHERE last_seen > '2022-01-01' AND severity = 'High' GROUP BY severity HAVING total > 1;
Which military technologies in the 'military_technology' table have a development cost greater than 100000000?
CREATE TABLE military_technology (id INT,technology_name TEXT,type TEXT,development_cost FLOAT,development_year INT); INSERT INTO military_technology (id,technology_name,type,development_cost,development_year) VALUES (1,'Stealth Bomber','Aircraft',50000000,2019),(2,'Submarine','Naval',300000000,2018),(3,'Cybersecurity Software','Software',5000000,2019);
SELECT technology_name FROM military_technology WHERE development_cost > 100000000;
What is the number of properties in each property type category?
CREATE TABLE Properties (id INT,price INT,property_type TEXT); INSERT INTO Properties (id,price,property_type) VALUES (1,500000,'House'),(2,400000,'Condo'),(3,700000,'Townhouse');
SELECT property_type, COUNT(*) AS property_count FROM Properties GROUP BY property_type;
What's the average funding for community development initiatives in the Middle East?
CREATE TABLE CommunityDevelopment (id INT PRIMARY KEY,region VARCHAR(20),funding FLOAT);
SELECT AVG(funding) FROM CommunityDevelopment WHERE region = 'Middle East';
How many Shariah-compliant financial products were sold in the East region last year?
CREATE TABLE sales (sale_id INT,product_type VARCHAR(30),region VARCHAR(20),sale_date DATE); INSERT INTO sales (sale_id,product_type,region,sale_date) VALUES (1,'Shariah-compliant Mortgage','East','2021-03-21'),(2,'Conventional Car Loan','West','2022-05-14');
SELECT COUNT(*) FROM sales WHERE product_type LIKE '%Shariah-compliant%' AND region = 'East' AND sale_date BETWEEN '2021-01-01' AND '2021-12-31';
What is the total volume of wastewater treated in regions that experienced a drought in 2019?
CREATE TABLE wastewater_treatment (region VARCHAR(255),year INT,treated_volume INT); INSERT INTO wastewater_treatment (region,year,treated_volume) VALUES ('North',2018,4000),('North',2019,4500),('North',2020,5000),('South',2018,4800),('South',2019,5200),('South',2020,5500); CREATE TABLE drought_info (region VARCHAR(255),year INT,severity INT); INSERT INTO drought_info (region,year,severity) VALUES ('North',2018,3),('North',2019,5),('South',2018,2),('South',2019,4);
SELECT SUM(w.treated_volume) FROM wastewater_treatment w JOIN drought_info d ON w.region = d.region WHERE w.year = 2019 AND d.severity > 0;
What is the maximum amount of budget allocated for transportation in the state of New York and Texas in the year 2021?
CREATE TABLE transportation_budget (budget_id INT,budget_year INT,budget_state TEXT,budget_amount FLOAT); INSERT INTO transportation_budget (budget_id,budget_year,budget_state,budget_amount) VALUES (1,2021,'New York',1000000),(2,2021,'Texas',1500000),(3,2022,'California',2000000);
SELECT MAX(budget_amount) FROM transportation_budget WHERE (budget_year = 2021 AND budget_state IN ('New York', 'Texas'));
What is the average soil moisture in India for the past month from IoT sensor metrics?
CREATE TABLE if not exists iot_metrics (id INT,location VARCHAR(255),soil_moisture FLOAT,metric_time DATETIME); INSERT INTO iot_metrics (id,location,soil_moisture,metric_time) VALUES (1,'India',45.6,'2022-01-01 10:00:00'),(2,'Pakistan',32.3,'2022-01-01 10:00:00');
SELECT AVG(soil_moisture) FROM iot_metrics WHERE location = 'India' AND metric_time BETWEEN DATE_SUB(NOW(), INTERVAL 1 MONTH) AND NOW();
Delete all records in the "vessels" table where the name contains the word "Star"
CREATE TABLE vessels (id INT,name TEXT);
DELETE FROM vessels WHERE name LIKE '%Star%';
Calculate the average CO2 emission for countries in the 'emissions' table, partitioned by the first letter of the country name for the year 2015.
CREATE TABLE emissions (country VARCHAR(255),year INT,co2_emission FLOAT); INSERT INTO emissions (country,year,co2_emission) VALUES ('Canada',2015,550.0),('US',2015,5200.0),('Russia',2015,1900.0),('Finland',2015,60.0),('Sweden',2015,450.0);
SELECT country[1] AS first_letter, AVG(co2_emission) AS avg_co2_emission FROM emissions WHERE year = 2015 GROUP BY country[1] ORDER BY avg_co2_emission DESC;
List the unique types of healthcare services provided in the rural healthcare system.
CREATE TABLE Services (ID INT,Name TEXT,Type TEXT); INSERT INTO Services VALUES (1,'Primary Care','Clinic'); INSERT INTO Services VALUES (2,'Surgery','Hospital'); INSERT INTO Services VALUES (3,'Dental','Clinic');
SELECT DISTINCT Type FROM Services;
What is the total mass of space debris in GEO orbit?
CREATE TABLE Space_Debris (Debris_ID INT,Debris_Name VARCHAR(50),Mass FLOAT,Orbit VARCHAR(50),PRIMARY KEY (Debris_ID)); INSERT INTO Space_Debris (Debris_ID,Debris_Name,Mass,Orbit) VALUES (1,'Envisat',8212,'LEO'),(2,'Tiangong-1',8500,'GEO'),(3,'Fengyun-1C',3500,'GEO');
SELECT SUM(Mass) FROM Space_Debris WHERE Orbit = 'GEO';
Number of threat intelligence reports and their sources for the month of April 2022?
CREATE TABLE threat_intelligence (report_id INT,report_date DATE,source VARCHAR(100)); INSERT INTO threat_intelligence (report_id,report_date,source) VALUES (1,'2022-04-01','Open Source Intelligence'),(2,'2022-04-05','Human Intelligence'),(3,'2022-04-10','Signals Intelligence'),(4,'2022-04-15','Geospatial Intelligence');
SELECT source, COUNT(report_id) as num_reports FROM threat_intelligence WHERE report_date BETWEEN '2022-04-01' AND '2022-04-30' GROUP BY source;
Delete mobile subscribers who have not updated their billing information in the last 90 days.
CREATE TABLE billing_updates (subscriber_id INT,name VARCHAR(50),billing_updated_date DATE); INSERT INTO billing_updates (subscriber_id,name,billing_updated_date) VALUES (11,'Imani White','2022-04-15'); INSERT INTO billing_updates (subscriber_id,name,billing_updated_date) VALUES (12,'Jaxon Black','2022-06-20');
DELETE FROM mobile_subscribers WHERE subscriber_id IN (SELECT subscriber_id FROM billing_updates WHERE billing_updated_date <= DATE_SUB(CURRENT_DATE, INTERVAL 90 DAY));
What is the average energy efficiency of buildings in each country?
CREATE TABLE building_efficiency (country VARCHAR(50),building_type VARCHAR(50),efficiency FLOAT);
SELECT country, AVG(efficiency) AS avg_efficiency FROM building_efficiency GROUP BY country;
What is the total revenue generated by organic and conventional dairy sales in North America, and what is the percentage of revenue generated by organic dairy?
CREATE TABLE sales (region VARCHAR(20),product_type VARCHAR(20),revenue INT,organic BOOLEAN); INSERT INTO sales VALUES ('North America','Milk',8000,true),('North America','Cheese',9000,false),('North America','Yogurt',7000,true);
SELECT SUM(s.revenue) as total_revenue, ROUND(SUM(CASE WHEN s.organic THEN s.revenue ELSE 0 END) / SUM(s.revenue) * 100, 2) as organic_percentage FROM sales s WHERE s.region = 'North America' AND s.product_type = 'Dairy';
What is the total number of attendees at events with a 'Performance' program category?
CREATE TABLE events (event_id INT,event_name VARCHAR(50),program_category VARCHAR(50),num_attendees INT); INSERT INTO events (event_id,event_name,program_category,num_attendees) VALUES (1,'Dance Recital','Performance',500),(2,'Art Exhibit','Visual Arts',300),(3,'Music Concert','Performance',700);
SELECT SUM(num_attendees) FROM events WHERE program_category = 'Performance';
What is the total number of hours spent by underrepresented communities on AI training programs in universities?
CREATE TABLE communities_underrepresented (community_id INT,community_name VARCHAR(100)); INSERT INTO communities_underrepresented VALUES (1,'Minority Women in STEM'),(2,'Rural AI Learners'); CREATE TABLE university_programs (program_id INT,program_name VARCHAR(100),community_id INT); INSERT INTO university_programs VALUES (1,'AI for Good',1),(2,'AI Ethics',1),(3,'AI Basics',2); CREATE TABLE participation (participation_id INT,participant_id INT,program_id INT,hours DECIMAL(5,2)); INSERT INTO participation VALUES (1,1,1,20.00),(2,2,1,25.00),(3,3,2,15.00);
SELECT SUM(hours) FROM participation INNER JOIN university_programs ON participation.program_id = university_programs.program_id INNER JOIN communities_underrepresented ON university_programs.community_id = communities_underrepresented.community_id;
How many citizen complaints were there in Texas for transportation and utilities in 2020?
CREATE TABLE CitizenComplaints (state VARCHAR(20),year INT,service VARCHAR(30),complaints INT); INSERT INTO CitizenComplaints (state,year,service,complaints) VALUES ('Texas',2020,'Transportation',1500),('Texas',2020,'Utilities',1200);
SELECT SUM(complaints) FROM CitizenComplaints WHERE state = 'Texas' AND service IN ('Transportation', 'Utilities') AND year = 2020;
What is the total production volume for wells in the Utica Shale formation in the last quarter?
CREATE TABLE wells (well_id INT,well_name VARCHAR(255),well_type VARCHAR(255),location VARCHAR(255)); INSERT INTO wells VALUES (1,'Well A','Onshore','Utica Shale'); INSERT INTO wells VALUES (2,'Well B','Onshore','Bakken Formation');
SELECT SUM(production_volume) FROM well_production WHERE location LIKE 'Utica%' AND date >= CURRENT_DATE - INTERVAL '3 months';
What is the maximum maritime law penalty in the Caribbean in USD?
CREATE TABLE maritime_laws (law_id INT,law_name VARCHAR(50),region VARCHAR(50),penalty_amount INT);
SELECT MAX(penalty_amount) FROM maritime_laws WHERE region = 'Caribbean';
What is the percentage of cruelty-free cosmetic products with a consumer preference score above 85?
CREATE TABLE cosmetics (product_name TEXT,consumer_preference_score INTEGER,cruelty_free BOOLEAN); INSERT INTO cosmetics (product_name,consumer_preference_score,cruelty_free) VALUES ('ProductA',85,true),('ProductB',90,false),('ProductC',70,true),('ProductD',95,true),('ProductE',80,false),('ProductF',75,true);
SELECT 100.0 * COUNT(*) / (SELECT COUNT(*) FROM cosmetics WHERE consumer_preference_score > 85 AND cruelty_free = true) AS percentage FROM cosmetics WHERE cruelty_free = true AND consumer_preference_score > 85;
How many members have a heart rate monitor?
CREATE TABLE Members (MemberID INT,Age INT,Gender VARCHAR(10),HasHeartRateMonitor BOOLEAN); INSERT INTO Members (MemberID,Age,Gender,HasHeartRateMonitor) VALUES (1,35,'Male',true),(2,28,'Female',false),(3,42,'Male',true);
SELECT COUNT(*) FROM Members WHERE HasHeartRateMonitor = true;
What is the maximum wage in factories, by country, for the year 2021?
CREATE SCHEMA ethical_fashion; CREATE TABLE factories (factory_id INT,country VARCHAR(255),wage FLOAT,year INT); INSERT INTO factories VALUES (1,'USA',9.0,2021),(2,'USA',9.5,2022),(3,'USA',8.5,2020),(4,'Canada',12.0,2021),(5,'Canada',11.5,2022),(6,'Canada',10.5,2020);
SELECT country, MAX(wage) FROM ethical_fashion.factories WHERE year = 2021 GROUP BY country;
What is the total claim amount and policy type for each policy that has a claim amount greater than $1500?
CREATE TABLE Claims (ClaimID INT,PolicyID INT,PolicyType VARCHAR(20),ClaimAmount DECIMAL(10,2)); INSERT INTO Claims (ClaimID,PolicyID,PolicyType,ClaimAmount) VALUES (1,1,'Auto',1500.00),(2,2,'Home',1800.00),(3,3,'Life',3000.00);
SELECT PolicyType, SUM(ClaimAmount) as TotalClaimAmount FROM Claims WHERE ClaimAmount > 1500 GROUP BY PolicyType;
What is the sum of revenue for vegan products in Mumbai over the last quarter?
CREATE TABLE products(product_id VARCHAR(20),product_name VARCHAR(20),is_vegan BOOLEAN,price DECIMAL(5,2)); INSERT INTO products (product_id,product_name,is_vegan,price) VALUES ('Vegan Chocolate',true,4.99),('Vegan Cookies',true,2.99); CREATE TABLE sales(product_id VARCHAR(20),store_location VARCHAR(20),sale_date DATE,quantity INTEGER); INSERT INTO sales (product_id,store_location,sale_date,quantity) VALUES ('Vegan Chocolate','Mumbai','2022-01-01',20),('Vegan Cookies','Mumbai','2022-02-01',10);
SELECT SUM(quantity * price) FROM products JOIN sales ON products.product_id = sales.product_id WHERE products.is_vegan = true AND sales.store_location = 'Mumbai' AND sale_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH) AND CURRENT_DATE;
How many TEUs were handled by each port in the cargo_handling table in chronological order?
CREATE TABLE cargo_handling (port_id INT,port_name VARCHAR(50),teu_count INT,handling_date DATE); INSERT INTO cargo_handling (port_id,port_name,teu_count,handling_date) VALUES (1,'Port_A',2000,'2022-01-01'),(2,'Port_B',3000,'2022-01-02'),(3,'Port_C',1000,'2022-01-03');
SELECT port_name, teu_count, ROW_NUMBER() OVER (PARTITION BY port_name ORDER BY handling_date) as rn FROM cargo_handling;
What is the total number of articles published in Spanish-speaking countries?
CREATE TABLE Articles (ArticleID INT,Title TEXT,Language TEXT,Country TEXT); INSERT INTO Articles (ArticleID,Title,Language,Country) VALUES (1,'Article1','Spanish','Spain'),(2,'Article2','English','USA');
SELECT COUNT(*) FROM Articles WHERE Country IN ('Spain', 'Mexico', 'Colombia', 'Argentina') AND Language = 'Spanish';
What were the top 5 most common vulnerabilities in the healthcare sector in Q4 2021?
CREATE TABLE vulnerabilities (id INT,sector VARCHAR(255),vulnerability_type VARCHAR(255),occurrence_count INT,occurrence_date DATE); INSERT INTO vulnerabilities (id,sector,vulnerability_type,occurrence_count,occurrence_date) VALUES (1,'Healthcare','SQL Injection',20,'2021-10-01');
SELECT vulnerability_type, occurrence_count FROM vulnerabilities WHERE sector = 'Healthcare' AND occurrence_date >= '2021-10-01' AND occurrence_date < '2022-01-01' GROUP BY vulnerability_type ORDER BY occurrence_count DESC LIMIT 5;
What is the total revenue from each data plan in the 'plans' table?
CREATE TABLE plans (id INT,name VARCHAR(255),type VARCHAR(255),price DECIMAL(10,2)); INSERT INTO plans (id,name,type,price) VALUES (1,'Basic','Data',29.99),(2,'Premium','Data',49.99),(3,'Family','Data',69.99);
SELECT type, SUM(price) FROM plans GROUP BY type;
What was the total freight cost for exports to Singapore in August 2021?
CREATE TABLE singapore_exports (id INT,freight_cost DECIMAL(10,2),shipment_date DATE); INSERT INTO singapore_exports (id,freight_cost,shipment_date) VALUES (1,1500.00,'2021-08-01'); INSERT INTO singapore_exports (id,freight_cost,shipment_date) VALUES (2,1200.00,'2021-08-15');
SELECT SUM(freight_cost) FROM singapore_exports WHERE shipment_date >= '2021-08-01' AND shipment_date < '2021-09-01' AND destination = 'Singapore';
What is the minimum duration of a space mission led by an astronaut from India?
CREATE TABLE Astronauts(id INT,name VARCHAR(50),nationality VARCHAR(50)); CREATE TABLE SpaceMissions(id INT,mission VARCHAR(50),leader_id INT,duration FLOAT); INSERT INTO Astronauts(id,name,nationality) VALUES (1,'Rakesh Sharma','India'),(2,'Kalpana Chawla','India'),(3,'Sunita Williams','India'); INSERT INTO SpaceMissions(id,mission,leader_id,duration) VALUES (1,'Apollo 11',1,12),(2,'Artemis I',2,15),(3,'Ares III',3,18),(4,'Mangalyaan',1,300);
SELECT MIN(duration) FROM SpaceMissions INNER JOIN Astronauts ON SpaceMissions.leader_id = Astronauts.id WHERE Astronauts.nationality = 'India';
What was the total donation amount for the 'Health' program in 2021?
CREATE TABLE Programs (ProgramID int,ProgramName varchar(255)); INSERT INTO Programs (ProgramID,ProgramName) VALUES (1,'Education'),(2,'Health'),(3,'Environment'); CREATE TABLE Donations (DonationID int,DonationAmount decimal(10,2),DonationDate date,ProgramID int); INSERT INTO Donations (DonationID,DonationAmount,DonationDate,ProgramID) VALUES (1,500,'2021-07-01',2),(2,300,'2021-09-05',2),(3,700,'2021-10-30',3);
SELECT SUM(DonationAmount) FROM Donations WHERE ProgramID = (SELECT ProgramID FROM Programs WHERE ProgramName = 'Health') AND DonationDate BETWEEN '2021-01-01' AND '2021-12-31';
Which community policing programs were implemented in the 'Central' district in the last year?
CREATE TABLE district (did INT,district_name VARCHAR(255)); INSERT INTO district (did,district_name) VALUES (1,'Central'),(2,'North'),(3,'South'); CREATE TABLE community_policing (program_id INT,did INT,program_name VARCHAR(255),program_start_date DATE);
SELECT program_name FROM community_policing WHERE did = 1 AND program_start_date >= DATEADD(year, -1, GETDATE());
What is the average capacity of vessels from each continent in the vessels table?
CREATE TABLE vessels (id INT,name VARCHAR(255),continent VARCHAR(255),capacity INT); INSERT INTO vessels (id,name,continent,capacity) VALUES (1,'Vessel1','Asia',10000),(2,'Vessel2','Africa',12000),(3,'Vessel3','Europe',8000);
SELECT continent, AVG(capacity) as average_capacity FROM vessels GROUP BY continent;
What are the names and addresses of all shippers in Canada?
CREATE TABLE Shippers (ShipperID INT,Name VARCHAR(255),Address VARCHAR(255),City VARCHAR(255),Region VARCHAR(255),PostalCode VARCHAR(255),Country VARCHAR(255)); INSERT INTO Shippers (ShipperID,Name,Address,City,Region,PostalCode,Country) VALUES (1,'Oceanic Transport','4567 Aqua Way','Vancouver','BC','V6B 1A1','Canada');
SELECT Name, Address FROM Shippers WHERE Country = 'Canada';
What is the total waste generation in kg for each country in 2020?
CREATE TABLE waste_generation (country VARCHAR(255),year INT,amount FLOAT); INSERT INTO waste_generation (country,year,amount) VALUES ('USA',2020,500.0),('Canada',2020,350.0),('Mexico',2020,400.0);
SELECT wg.country, SUM(wg.amount) as total_waste FROM waste_generation wg WHERE wg.year = 2020 GROUP BY wg.country;
Which sustainable material types are used by the top 3 clothing brands, and how many items of each type do they produce?
CREATE TABLE sustainable_materials (brand VARCHAR(50),material_type VARCHAR(50),items_produced INT); INSERT INTO sustainable_materials (brand,material_type,items_produced) VALUES ('Brand F','Organic Cotton',50000),('Brand F','Recycled Polyester',30000),('Brand F','Hemp',20000),('Brand G','Organic Cotton',40000),('Brand G','Tencel',35000),('Brand G','Recycled Polyester',25000),('Brand H','Organic Cotton',60000),('Brand H','Tencel',45000),('Brand H','Hemp',30000);
SELECT material_type, SUM(items_produced) as total_items FROM sustainable_materials WHERE brand IN ('Brand F', 'Brand G', 'Brand H') GROUP BY material_type ORDER BY total_items DESC LIMIT 3;
What is the average age of policyholders who have a car insurance policy in the 'west' region?
CREATE TABLE policyholders (id INT,age INT,policy_type VARCHAR(20)); INSERT INTO policyholders (id,age,policy_type) VALUES (1,35,'car insurance'),(2,45,'home insurance'); CREATE TABLE regions (id INT,region VARCHAR(10)); INSERT INTO regions (id,region) VALUES (1,'west'),(2,'east');
SELECT AVG(age) FROM policyholders JOIN regions ON policyholders.id = regions.id WHERE policy_type = 'car insurance' AND region = 'west';
How many professional development workshops have been attended by teachers in each subject area?
CREATE TABLE teachers (teacher_id INT,subject_area VARCHAR(50),workshops_attended INT); INSERT INTO teachers (teacher_id,subject_area,workshops_attended) VALUES (1,'Mathematics',3),(2,'Mathematics',2),(3,'Science',4),(4,'Science',1);
SELECT subject_area, SUM(workshops_attended) as total_workshops_attended FROM teachers GROUP BY subject_area;
What is the maximum revenue from concert ticket sales for artists from Africa or South America?
CREATE TABLE Concerts (concert_id INT,concert_name TEXT,attendees INT,artist_id INT,artist_revenue INT); INSERT INTO Concerts (concert_id,concert_name,attendees,artist_id,artist_revenue) VALUES (1,'African Music Festival',5000,1,50000),(2,'South American Music Festival',7000,2,75000),(3,'World Music Festival',8000,3,80000); CREATE TABLE Artists (artist_id INT,artist_name TEXT,continent TEXT); INSERT INTO Artists (artist_id,artist_name,continent) VALUES (1,'Angélique Kidjo','Africa'),(2,'Gilberto Gil','South America'),(3,'Yo-Yo Ma','Asia');
SELECT MAX(c.artist_revenue) FROM Concerts c JOIN Artists a ON c.artist_id = a.artist_id WHERE a.continent IN ('Africa', 'South America');
Which artwork entries in Oceania were created in the 1920s and have a high selling price?
CREATE TABLE Artwork (ArtworkID INT,ArtworkName TEXT,CreationDate DATE,SellingPrice DECIMAL); INSERT INTO Artwork (ArtworkID,ArtworkName,CreationDate,SellingPrice) VALUES (1,'Starry Night','1920-01-01',300000),(2,'The Scream','1920-05-15',400000);
SELECT * FROM Artwork WHERE Continent = 'Oceania' AND EXTRACT(YEAR FROM CreationDate) BETWEEN 1920 AND 1929 AND SellingPrice > 300000;
Find the top 3 countries with the most language preservation programs.
CREATE TABLE language_preservation (id INT,country VARCHAR(50),program VARCHAR(50)); INSERT INTO language_preservation (id,country,program) VALUES (1,'Australia','Indigenous Language Program'),(2,'Canada','First Nations Language Program');
SELECT country, COUNT(*) as num_programs FROM language_preservation GROUP BY country ORDER BY num_programs DESC LIMIT 3;
What is the total budget allocated for military innovation by South American countries from 2018 to 2020?
CREATE TABLE military_innovation_south_amer (country VARCHAR(50),year INT,budget INT); INSERT INTO military_innovation_south_amer (country,year,budget) VALUES ('Brazil',2018,1000000),('Colombia',2018,700000),('Argentina',2018,800000),('Brazil',2019,1200000),('Colombia',2019,800000),('Argentina',2019,900000),('Brazil',2020,1500000),('Colombia',2020,1000000),('Argentina',2020,1100000);
SELECT country, SUM(budget) total_budget FROM military_innovation_south_amer WHERE (country IN ('Brazil', 'Colombia', 'Argentina')) AND (year BETWEEN 2018 AND 2020) GROUP BY country;
How many vegan menu items are there?
CREATE TABLE menus (menu_id INT,menu_name VARCHAR(255),type VARCHAR(255),price DECIMAL(5,2)); INSERT INTO menus (menu_id,menu_name,type,price) VALUES (1,'Quinoa Salad','Vegetarian',12.99),(2,'Margherita Pizza','Non-Vegetarian',9.99),(3,'Falafel Wrap','Vegetarian',8.99),(5,'Vegan Burger','Vegan',10.99),(6,'Vegan Tacos','Vegan',7.99);
SELECT COUNT(*) FROM menus WHERE type = 'Vegan';
What was the revenue for 'DrugC' in Q2 2020?
CREATE TABLE sales (drug varchar(20),quarter varchar(10),revenue int); INSERT INTO sales (drug,quarter,revenue) VALUES ('DrugC','Q2 2020',2000000);
SELECT revenue FROM sales WHERE drug = 'DrugC' AND quarter = 'Q2 2020';
What is the number of hospitals per state in Rural South?
CREATE TABLE Hospitals (name TEXT,location TEXT,type TEXT,num_beds INTEGER,state TEXT); INSERT INTO Hospitals (name,location,type,num_beds,state) VALUES ('Hospital A','City A,Rural South','General',50,'Rural South'),('Hospital B','City B,Rural South','Specialty',25,'Rural South');
SELECT state, COUNT(*) as hospital_count FROM Hospitals WHERE state = 'Rural South' GROUP BY state;
What is the maximum number of reindeer in the 'arctic_reindeer' table, grouped by year?
CREATE TABLE arctic_reindeer (year INT,count INT);
SELECT year, MAX(count) FROM arctic_reindeer GROUP BY year;
What is the total sales for all strains with a THC percentage greater than 20%?
CREATE TABLE strains (id INT,name TEXT,thc_percentage DECIMAL(5,2),cbd_percentage DECIMAL(5,2),sales INT); INSERT INTO strains (id,name,thc_percentage,cbd_percentage,sales) VALUES (1,'Strain 1',21.5,0.5,500),(2,'Strain 2',15.0,0.8,700),(3,'Strain 3',25.0,1.2,800),(4,'Strain 4',12.0,0.0,900),(5,'Strain 5',22.0,0.5,1000);
SELECT SUM(sales) AS total_sales FROM strains WHERE thc_percentage > 20.0;
Find the total number of streams for songs in the Pop genre released in 2020.
CREATE TABLE songs (id INT PRIMARY KEY,title TEXT,genre TEXT,year INT,artist TEXT,streams INT);
SELECT SUM(streams) FROM songs WHERE genre = 'Pop' AND year = 2020;
Which departments have the highest and lowest budgets?
CREATE TABLE departments (dept_id INT,name VARCHAR(255),budget DECIMAL(10,2)); INSERT INTO departments (dept_id,name,budget) VALUES (1,'Education',500000),(2,'Transportation',750000),(3,'Health',800000),(4,'Housing',650000),(5,'Public Safety',400000);
SELECT name, budget FROM departments ORDER BY budget DESC LIMIT 1; SELECT name, budget FROM departments ORDER BY budget ASC LIMIT 1;
How many creative AI applications were developed for the education sector in the past two years, in the Creative AI database?
CREATE TABLE applications (id INT,name VARCHAR(255),sector VARCHAR(255),published_date DATE);
SELECT COUNT(*) FROM applications WHERE sector = 'Education' AND YEAR(published_date) >= YEAR(CURRENT_DATE()) - 2;
Which indigenous communities have a population growth rate higher than 10% in the last 5 years?
CREATE TABLE Indigenous_Communities (Id INT,Community VARCHAR(20),Population INT,Region VARCHAR(20),Last_Census DATE,Previous_Census DATE); INSERT INTO Indigenous_Communities (Id,Community,Population,Region,Last_Census,Previous_Census) VALUES (1,'Community1',500,'Region1','2021-01-01','2016-01-01'),(2,'Community2',650,'Region2','2021-01-01','2016-01-01');
SELECT Community, Region, Last_Census, (Population - LAG(Population) OVER (PARTITION BY Community ORDER BY Last_Census))*100.0/LAG(Population) OVER (PARTITION BY Community ORDER BY Last_Census) as Population_Growth_Rate FROM Indigenous_Communities WHERE Last_Census > DATEADD(year, -5, Last_Census) AND Population_Growth_Rate > 10.0;
What is the average temperature recorded in the 'arctic_weather' table for each month in the year 2020?
CREATE TABLE arctic_weather (date DATE,temperature FLOAT);
SELECT EXTRACT(MONTH FROM date) as month, AVG(temperature) as avg_temperature FROM arctic_weather WHERE EXTRACT(YEAR FROM date) = 2020 GROUP BY month;
What is the maximum water temperature recorded in each monitoring station?
CREATE TABLE MonitoringStations (StationID INT,StationName VARCHAR(50),WaterTemp DECIMAL(4,2)); INSERT INTO MonitoringStations VALUES (1,'Station A',24.5),(2,'Station B',22.3),(3,'Station C',26.7);
SELECT StationName, MAX(WaterTemp) FROM MonitoringStations GROUP BY StationName;
Determine the total oil production for each platform in the South China Sea
CREATE TABLE platforms (platform_id INT,platform_name TEXT,region TEXT); INSERT INTO platforms (platform_id,platform_name,region) VALUES (1,'Platform A','South China Sea'),(2,'Platform B','South China Sea'),(3,'Platform C','South China Sea'); CREATE TABLE oil_production (platform_id INT,year INT,oil_production FLOAT); INSERT INTO oil_production (platform_id,year,oil_production) VALUES (1,2020,100000),(1,2021,120000),(2,2020,150000),(2,2021,180000),(3,2020,200000),(3,2021,220000);
SELECT p.platform_name, SUM(op.oil_production) AS total_oil_production FROM oil_production op JOIN platforms p ON op.platform_id = p.platform_id WHERE p.region = 'South China Sea' GROUP BY op.platform_id;
List the green building certifications for all buildings in the state of California.
CREATE TABLE green_buildings (building_id INT,building_name VARCHAR(255),state VARCHAR(255),certification_level VARCHAR(255));
SELECT DISTINCT certification_level FROM green_buildings WHERE state = 'California';
What is the average time taken to resolve each type of customer complaint?
CREATE TABLE customer_complaints (id INT,complaint_type VARCHAR(20),resolution_time DECIMAL(5,2)); INSERT INTO customer_complaints (id,complaint_type,resolution_time) VALUES (1,'coverage',5.3),(2,'data_speed',3.2),(3,'customer_service',4.5),(4,'billing',2.9),(5,'technical_support',6.1);
SELECT complaint_type, AVG(resolution_time) FROM customer_complaints GROUP BY complaint_type;
Retrieve all spacecraft launched before 2020 and insert them into a new table.
CREATE TABLE Spacecraft (id INT,name VARCHAR(50),type VARCHAR(20),launch_date DATE); INSERT INTO Spacecraft (id,name,type,launch_date) VALUES (1,'Hermes','Mars Rover','2035-06-03'); INSERT INTO Spacecraft (id,name,type,launch_date) VALUES (2,'Juno','Orbiter','2011-08-05');
CREATE TABLE Old_Spacecraft AS SELECT * FROM Spacecraft WHERE launch_date < '2020-01-01';
What are the names, locations, and construction dates of all hydroelectric power plants in Brazil and Colombia, along with their respective power generation capacities?
CREATE TABLE Hydroelectric (HydroID INT,Name VARCHAR(255),Country VARCHAR(255),Location VARCHAR(255),ConstructionDate DATE,PowerGenerationCapacity INT); INSERT INTO Hydroelectric VALUES (1,'Hydro Plant A','Brazil','Amazon','2005-01-01',1000); INSERT INTO Hydroelectric VALUES (2,'Hydro Plant B','Colombia','Andes','2008-05-15',1200); INSERT INTO Hydroelectric VALUES (3,'Hydro Plant C','Brazil','Parana','2012-09-20',1400);
SELECT Name, Location, ConstructionDate, PowerGenerationCapacity FROM Hydroelectric WHERE Country IN ('Brazil', 'Colombia');
What is the maximum age of players who play VR games in Canada?
CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),Country VARCHAR(20)); INSERT INTO Players (PlayerID,Age,Gender,Country) VALUES (1,25,'Male','USA'),(2,30,'Female','Canada'),(3,35,'Female','Mexico'),(4,45,'Male','Canada'); CREATE TABLE VR_Games (GameID INT,GameName VARCHAR(20),Players INT); INSERT INTO VR_Games (GameID,GameName,Players) VALUES (1,'Beat Saber',2),(2,'Job Simulator',3);
SELECT MAX(Players.Age) FROM Players WHERE Players.Country = 'Canada' AND Players.PlayerID IN (SELECT Players_VR.PlayerID FROM Players AS Players_VR INNER JOIN VR_Games AS VR_Games_VR ON Players_VR.PlayerID = VR_Games_VR.Players);
Insert a new regulatory framework into the 'regulatory_frameworks' table.
CREATE TABLE regulatory_frameworks (framework_id INT,name VARCHAR(64),description VARCHAR(256));
INSERT INTO regulatory_frameworks (framework_id, name, description) VALUES (1, 'SEC', 'United States Securities and Exchange Commission');
What is the average water consumption for organic cotton farming in India?
CREATE TABLE OrganicCotton (country VARCHAR(50),water_consumption INT); INSERT INTO OrganicCotton VALUES ('India',1200),('Nepal',1500),('India',1000),('Sri_Lanka',1400);
SELECT AVG(water_consumption) FROM OrganicCotton WHERE country = 'India';
Insert missing vessel_performance records with average values
CREATE TABLE vessel_performance_averages (vessel_id INT,avg_engine_power INT,avg_fuel_consumption INT); INSERT INTO vessel_performance_averages (vessel_id,avg_engine_power,avg_fuel_consumption) VALUES (1,2000,500),(3,2500,600),(4,1500,400);
INSERT INTO vessel_performance (vessel_id, engine_power, fuel_consumption) SELECT vpavg.vessel_id, vpavg.avg_engine_power, vpavg.avg_fuel_consumption FROM vessel_performance_averages vpavg LEFT JOIN vessel_performance vp ON vpavg.vessel_id = vp.vessel_id WHERE vp.vessel_id IS NULL;
How many days in the last month did each customer have data usage, and what is the total data usage in GB for each customer on those days?
CREATE TABLE daily_usage (customer_id INT,date DATE,data_usage FLOAT); INSERT INTO daily_usage VALUES (1,'2022-01-01',5),(1,'2022-01-02',7);
SELECT customer_id, COUNT(*) as days_with_data_usage, SUM(data_usage)/1024/1024/1024 as total_data_usage_gb FROM daily_usage WHERE date >= DATEADD(month, -1, GETDATE()) GROUP BY customer_id;
List the program outcomes for programs with a budget lower than the average budget of all programs?
CREATE TABLE ProgramBudget (ProgramID INT,ProgramName VARCHAR(50),Budget DECIMAL(10,2)); INSERT INTO ProgramBudget (ProgramID,ProgramName,Budget) VALUES (101,'Education Support',12000.00),(102,'Healthcare Support',15000.00),(103,'Environment Support',9000.00);
SELECT ProgramName FROM ProgramBudget WHERE Budget < (SELECT AVG(Budget) FROM ProgramBudget);
Which startups have the most diverse teams and received funding over $1M?
CREATE TABLE startups (startup_id INT,team_diversity DECIMAL(5,2),funding_amount INT); INSERT INTO startups VALUES (1,75.5,1500000),(2,82.3,750000),(3,65.9,1200000);
SELECT startup_id, team_diversity, funding_amount FROM startups WHERE team_diversity > 80 AND funding_amount > 1000000;
What are the total mining operation costs for Australia and South Africa, grouped by operation type?
CREATE TABLE australian_states (id INT,name VARCHAR(50)); CREATE TABLE south_african_provinces (id INT,name VARCHAR(50)); CREATE TABLE mining_operations (id INT,country_id INT,operation_type VARCHAR(20),total_cost INT); INSERT INTO australian_states (id,name) VALUES (1,'Queensland'),(2,'Western Australia'); INSERT INTO south_african_provinces (id,name) VALUES (1,'Gauteng'),(2,'North West'); INSERT INTO mining_operations (id,country_id,operation_type,total_cost) VALUES (1,1,'Open Pit',1000000),(2,1,'Underground',1500000),(3,2,'Open Pit',2000000),(4,2,'Underground',2500000);
SELECT m.operation_type, SUM(m.total_cost) as total_cost FROM mining_operations m INNER JOIN (SELECT * FROM australian_states WHERE name IN ('Queensland', 'Western Australia') UNION ALL SELECT * FROM south_african_provinces WHERE name IN ('Gauteng', 'North West')) c ON m.country_id = c.id GROUP BY m.operation_type;
List all volunteers aged 25 or older with 'Medical' skills and their associated organizations.
CREATE TABLE Volunteer (id INT PRIMARY KEY,name VARCHAR(50),age INT,skill VARCHAR(20),organization_id INT); INSERT INTO Volunteer (id,name,age,skill,organization_id) VALUES (1,'Sophia Beltran',28,'Medical',1); INSERT INTO Volunteer (id,name,age,skill,organization_id) VALUES (2,'Juan Carlos',32,'Logistics',2); CREATE TABLE Organization (id INT PRIMARY KEY,name VARCHAR(50),type VARCHAR(20),country VARCHAR(20)); INSERT INTO Organization (id,name,type,country) VALUES (1,'Médecins Sans Frontières','Health Services','Switzerland'); INSERT INTO Organization (id,name,type,country) VALUES (2,'International Federation of Red Cross and Red Crescent Societies','Relief Services','Switzerland');
SELECT Volunteer.name, Volunteer.age, Volunteer.skill, Organization.name AS organization_name FROM Volunteer INNER JOIN Organization ON Volunteer.organization_id = Organization.id WHERE Volunteer.age >= 25 AND Volunteer.skill = 'Medical';
Update the animal population data when animals are transferred between sanctuaries
CREATE TABLE wildlife_sanctuaries (sanctuary_id INT,sanctuary_name VARCHAR(50));CREATE TABLE animal_population (population_id INT,animal_id INT,species_id INT,sanctuary_id INT);
UPDATE animal_population SET sanctuary_id = 3 WHERE animal_id = 103;
List all the unique types of peacekeeping operations in the 'Peacekeeping' table, excluding the 'Observer mission' type.
CREATE TABLE Peacekeeping (id INT,operation VARCHAR(255),type VARCHAR(255));
SELECT DISTINCT type FROM Peacekeeping WHERE type != 'Observer mission';
What is the maximum score achieved in the game "Virtual Virtuosos" by players from Asia?
CREATE TABLE Scores (PlayerID INT,PlayerName VARCHAR(50),Game VARCHAR(50),Score INT,Country VARCHAR(50)); INSERT INTO Scores (PlayerID,PlayerName,Game,Score,Country) VALUES (1,'John Doe','Virtual Virtuosos',1000,'Japan'); INSERT INTO Scores (PlayerID,PlayerName,Game,Score,Country) VALUES (2,'Jane Smith','Virtual Virtuosos',1200,'China');
SELECT MAX(Score) FROM Scores WHERE Game = 'Virtual Virtuosos' AND Country LIKE 'Asia%';
Determine the policyholder with the highest average claim amount.
CREATE TABLE Policyholders (PolicyholderID INT,Name VARCHAR(50),Address VARCHAR(100)); CREATE TABLE Claims (ClaimID INT,PolicyholderID INT,ClaimAmount INT); INSERT INTO Policyholders (PolicyholderID,Name,Address) VALUES (1,'John Doe','123 Main St,Springfield'); INSERT INTO Policyholders (PolicyholderID,Name,Address) VALUES (2,'Jane Smith','456 Country Rd,Greenville'); INSERT INTO Claims (ClaimID,PolicyholderID,ClaimAmount) VALUES (1,1,500); INSERT INTO Claims (ClaimID,PolicyholderID,ClaimAmount) VALUES (2,1,700); INSERT INTO Claims (ClaimID,PolicyholderID,ClaimAmount) VALUES (3,2,300);
SELECT PolicyholderID, AVG(ClaimAmount) AS AverageClaimAmount, RANK() OVER (ORDER BY AverageClaimAmount DESC) FROM Claims C JOIN Policyholders P ON C.PolicyholderID = P.PolicyholderID GROUP BY PolicyholderID ORDER BY AverageClaimAmount DESC FETCH FIRST 1 ROW ONLY;
What is the average income of veterans in France?
CREATE TABLE income (id INT,type VARCHAR(20),amount INT,veteran BOOLEAN); INSERT INTO income (id,type,amount,veteran) VALUES (1,'Salary',30000,true); INSERT INTO income (id,type,amount,veteran) VALUES (2,'Pension',20000,true); INSERT INTO income (id,type,amount,veteran) VALUES (3,'Salary',35000,false);
SELECT AVG(amount) FROM income WHERE veteran = true;
Who is the officer with the most community engagement activities in the last month?
CREATE TABLE officers (id INT,name VARCHAR(255),division VARCHAR(255)); INSERT INTO officers (id,name,division) VALUES (1,'John Doe','NYPD'),(2,'Jane Smith','NYPD'); CREATE TABLE community_engagements (id INT,officer_id INT,engagement_type VARCHAR(255),engagement_time TIMESTAMP); INSERT INTO community_engagements (id,officer_id,engagement_type,engagement_time) VALUES (1,1,'Community Meeting','2022-02-01 10:00:00'),(2,2,'Neighborhood Watch','2022-02-15 11:00:00');
SELECT o.name, COUNT(ce.id) as total_engagements FROM community_engagements ce JOIN officers o ON ce.officer_id = o.id WHERE ce.engagement_time >= DATEADD(month, -1, CURRENT_TIMESTAMP) GROUP BY o.name ORDER BY total_engagements DESC;
Identify dispensaries in Colorado with more than 500 sales transactions and the total quantity of products sold in Q2 2022.
CREATE TABLE dispensaries (name VARCHAR(50),state VARCHAR(20),transactions INT,quantity INT); INSERT INTO dispensaries (name,state,transactions,quantity) VALUES ('Denver Dispensary','Colorado',600,1200),('Boulder Buds','Colorado',400,800);
SELECT name, SUM(quantity) FROM dispensaries WHERE state = 'Colorado' AND transactions > 500 GROUP BY name;
Update the team for an athlete in the athletes table
CREATE TABLE athletes (athlete_id INT,name VARCHAR(50),sport VARCHAR(20),age INT,height DECIMAL(3,1),weight DECIMAL(3,1),team VARCHAR(50)); INSERT INTO athletes (athlete_id,name,sport,age,height,weight,team) VALUES (1,'Sofia Herrera','Soccer',25,6.2,140.5,'Shooting Stars'),(2,'Jerome Green','Basketball',30,6.6,210.0,'Bouncing Bears');
UPDATE athletes SET team = 'Sky High Flyers' WHERE name = 'Sofia Herrera';
Insert a new album by an artist into the database
CREATE TABLE Country (id INT,country VARCHAR(255)); CREATE TABLE Artist (id INT,country_id INT,name VARCHAR(255)); CREATE TABLE Album (id INT,artist_id INT,title VARCHAR(255),year INT);
INSERT INTO Artist (id, country_id, name) VALUES (1, 1, 'Taylor Swift'); INSERT INTO Album (id, artist_id, title, year) VALUES (1, 1, 'Lover', 2019);
What are the names of the military technologies used in intelligence operations located in the Asia-Pacific region?
CREATE TABLE Military_Technologies (Name VARCHAR(255),Technology VARCHAR(255)); INSERT INTO Military_Technologies (Name,Technology) VALUES ('Operation Pacific Prowler','M1 Abrams'),('Operation Pacific Haven','AH-64 Apache'),('Operation Pacific Repose','M2 Bradley'); CREATE TABLE Locations (Location VARCHAR(255)); INSERT INTO Locations (Location) VALUES ('Asia-Pacific');
SELECT Military_Technologies.Name FROM Military_Technologies INNER JOIN Locations ON Military_Technologies.Name = Locations.Location WHERE Locations.Location = 'Asia-Pacific';
Find the most popular fabric origin by total quantity of sustainable garments made.
CREATE TABLE garments (id INT PRIMARY KEY,material VARCHAR(255),country_of_origin VARCHAR(255),sustainable BOOLEAN,quantity INT); INSERT INTO garments (id,material,country_of_origin,sustainable,quantity) VALUES (1,'cotton','India',true,100); INSERT INTO garments (id,material,country_of_origin,sustainable,quantity) VALUES (2,'polyester','China',false,200); INSERT INTO garments (id,material,country_of_origin,sustainable,quantity) VALUES (3,'hemp','Nepal',true,150);
SELECT country_of_origin, SUM(quantity) FROM garments WHERE sustainable = true GROUP BY country_of_origin ORDER BY SUM(quantity) DESC LIMIT 1;
What are the top 3 most sold menu items in the Southeast region?
CREATE TABLE menu_items (item_id INT,item_name VARCHAR(50),region VARCHAR(20),sales INT); INSERT INTO menu_items (item_id,item_name,region,sales) VALUES (1,'Shrimp and Grits','Southeast',300),(2,'Fried Catfish','Southeast',280),(3,'BBQ Tofu','Southeast',250);
SELECT item_name, SUM(sales) as total_sales FROM menu_items WHERE region = 'Southeast' GROUP BY item_name ORDER BY total_sales DESC LIMIT 3;
Display the number of days between the first and last matches for each team, and the difference between the total wins and losses, in the rugby_cup dataset.
CREATE TABLE rugby_cup (team VARCHAR(50),match_date DATE,result VARCHAR(50));
SELECT team, DATEDIFF(MAX(match_date), MIN(match_date)) as days_between, SUM(CASE WHEN result = 'win' THEN 1 ELSE 0 END) - SUM(CASE WHEN result = 'loss' THEN 1 ELSE 0 END) as wins_minus_losses FROM rugby_cup GROUP BY team;
Delete all records from the ocean floor mapping table that have a station ID greater than 5.
CREATE TABLE ocean_floor_mapping (station_id INT,trench_name TEXT,mean_depth REAL); INSERT INTO ocean_floor_mapping (station_id,trench_name,mean_depth) VALUES (1,'Mariana Trench',10994),(2,'Sunda Trench',8047),(3,'Puerto Rico Trench',8376),(4,'Java Trench',7725),(5,'Kuril Trench',10542);
DELETE FROM ocean_floor_mapping WHERE station_id > 5;
What is the maximum budget allocated to a public transportation project in Chicago?
CREATE TABLE public_transportation (project_id INT,project_name TEXT,city TEXT,state TEXT,budget INT); INSERT INTO public_transportation (project_id,project_name,city,state,budget) VALUES (1,'CTA Red Line Extension','Chicago','Illinois',2100000000); INSERT INTO public_transportation (project_id,project_name,city,state,budget) VALUES (2,'Chicago Transit Authority Improvements','Chicago','Illinois',1500000000); INSERT INTO public_transportation (project_id,project_name,city,state,budget) VALUES (3,'Downtown Streetcar Loop','Chicago','Illinois',100000000);
SELECT MAX(budget) FROM public_transportation WHERE city = 'Chicago';
What is the average number of stories in buildings in the 'Midwest'?
CREATE TABLE Buildings (BuildingID int,Name varchar(100),Location varchar(100),NumberOfStories int); INSERT INTO Buildings VALUES (1,'Building A','Midwest',5); INSERT INTO Buildings VALUES (2,'Building B','Midwest',7);
SELECT AVG(NumberOfStories) FROM Buildings WHERE Location = 'Midwest';
What is the average size of customers who purchased dresses in Canada?
CREATE TABLE CustomerData (id INT,customer_id INT,product VARCHAR(20),size INT,country VARCHAR(10)); INSERT INTO CustomerData (id,customer_id,product,size,country) VALUES (1,1001,'dress',12,'Canada'),(2,1002,'shirt',10,'USA');
SELECT AVG(size) FROM CustomerData WHERE product = 'dress' AND country = 'Canada';
What is the total number of cultural heritage sites in 'Asia' and 'Oceania'?
CREATE TABLE CulturalHeritage (HeritageID INTEGER,HeritageName TEXT,Location TEXT); INSERT INTO CulturalHeritage (HeritageID,HeritageName,Location) VALUES (1,'Ancient Ruins','India'),(2,'Historic Temple','China'),(3,'Traditional Village','Japan'),(4,'Ancient City','Thailand'),(5,'Aboriginal Rock Art','Australia'),(6,'Ancient Burial Site','New Zealand');
SELECT SUM(CASE WHEN Location IN ('Asia', 'Oceania') THEN 1 ELSE 0 END) FROM CulturalHeritage;
What are the top 3 least popular teams by fan demographics in the West region?
CREATE TABLE Teams(id INT,name TEXT,region TEXT); CREATE TABLE FanDemographics(id INT,team_id INT,fan_age INT,fan_gender TEXT,fan_income INT);
SELECT t.name, COUNT(DISTINCT f.id) AS fan_count FROM Teams t JOIN FanDemographics f ON t.id = f.team_id WHERE t.region = 'West' GROUP BY t.name ORDER BY fan_count ASC LIMIT 3
List all the community development initiatives in 'rural_development' database for regions with a population density greater than 500 people per square kilometer.
CREATE TABLE community_development (id INT,initiative_name TEXT,region TEXT,population_density FLOAT); INSERT INTO community_development (id,initiative_name,region,population_density) VALUES (1,'CommunityDevA','Region1',600); INSERT INTO community_development (id,initiative_name,region,population_density) VALUES (2,'CommunityDevB','Region2',450);
SELECT community_development.initiative_name FROM community_development WHERE community_development.population_density > 500;
What is the name of the top scorer in the FPS genre?
CREATE TABLE player (player_id INT,name VARCHAR(50),score INT,game_genre VARCHAR(20)); INSERT INTO player (player_id,name,score,game_genre) VALUES (1,'John Doe',500,'FPS'); INSERT INTO player (player_id,name,score,game_genre) VALUES (2,'Jane Smith',700,'RPG');
SELECT name FROM player WHERE game_genre = 'FPS' AND score = (SELECT MAX(score) FROM player WHERE game_genre = 'FPS');