instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
List all unique machinery types used in the 'Engineering' department across all plants. | CREATE TABLE machinery (machinery_id INT,plant_id INT,machinery_type VARCHAR(50)); INSERT INTO machinery (machinery_id,plant_id,machinery_type) VALUES (1,1,'CNC Milling'),(2,1,'Lathe'),(3,2,'3D Printer'),(4,2,'Injection Molding'),(5,3,'CNC Milling'),(6,3,'Lathe'); | SELECT DISTINCT machinery_type FROM machinery WHERE plant_id IN (SELECT plant_id FROM plants WHERE department = 'Engineering'); |
What is the latest smart city technology adoption date in the 'smart_city_technology' table? | CREATE TABLE smart_city_technology (tech_id INT,tech_name VARCHAR(100),adoption_date DATE); INSERT INTO smart_city_technology (tech_id,tech_name,adoption_date) VALUES (1,'Smart Grid','2020-03-15'),(2,'Smart Lighting','2019-08-01'); | SELECT MAX(adoption_date) FROM smart_city_technology; |
Delete all artworks by Pablo Picasso. | CREATE TABLE Artists (ArtistID INT,Name TEXT);CREATE TABLE Artworks (ArtworkID INT,Title TEXT,Genre TEXT,ArtistID INT); INSERT INTO Artists (ArtistID,Name) VALUES (1,'Pablo Picasso'); INSERT INTO Artworks (ArtworkID,Title,Genre,ArtistID) VALUES (1,'Guernica','Cubism',1),(2,'The Old Guitarist','Blue Period',1); | DELETE FROM Artworks WHERE ArtistID = 1; |
What is the distribution of articles by category in 'news_articles' table? | CREATE TABLE news_articles (id INT,title VARCHAR(100),publication_date DATE,category VARCHAR(50)); INSERT INTO news_articles (id,title,publication_date,category) VALUES (1,'Article 1','2022-01-01','Politics'),(2,'Article 2','2022-01-02','Sports'); | SELECT category, COUNT(*) as num_articles, ROW_NUMBER() OVER (ORDER BY COUNT(*) DESC) as rank FROM news_articles GROUP BY category; |
Insert a new post with the content 'Hello world!' and hashtags '#hello' and '#world' into the 'posts' table. | CREATE TABLE posts (id INT,user_id INT,timestamp DATETIME,content TEXT,hashtags TEXT); | INSERT INTO posts (id, user_id, timestamp, content, hashtags) VALUES (1, 1, NOW(), 'Hello world!', '#hello #world'); |
How many visitors from California engaged with the digital museum's online workshops? | CREATE TABLE visitor_workshops (visitor_id INT,state VARCHAR(20),workshop_name VARCHAR(50)); INSERT INTO visitor_workshops (visitor_id,state,workshop_name) VALUES (1,'California','Painting'),(2,'New York','Sculpture'),(3,'Texas','Digital Art'); | SELECT state, COUNT(*) as num_visitors FROM visitor_workshops WHERE state = 'California' GROUP BY state; |
What is the maximum number of investments made by a client in a single month? | CREATE TABLE clients (id INT,registered_date DATE);CREATE TABLE investments (id INT,client_id INT,investment_date DATE); INSERT INTO clients (id,registered_date) VALUES (1,'2020-01-01'),(2,'2019-01-01'),(3,'2018-01-01'),(4,'2017-01-01'); INSERT INTO investments (id,client_id,investment_date) VALUES (1,1,'2021-02-01'),(2,1,'2021-03-01'),(3,2,'2020-04-01'),(4,3,'2019-05-01'),(5,4,'2018-06-01'),(6,1,'2021-02-02'),(7,1,'2021-02-03'); | SELECT client_id, MAX(COUNT(*)) FROM investments GROUP BY client_id, DATE_TRUNC('month', investment_date); |
Which garment has the highest total sales quantity? | CREATE TABLE garment_sales (sales_id INT PRIMARY KEY,garment_id INT,store_id INT,quantity INT,price DECIMAL(5,2),date DATE); CREATE TABLE garments (garment_id INT PRIMARY KEY,garment_name TEXT,garment_category TEXT,sustainability_score INT); INSERT INTO garments (garment_id,garment_name,garment_category,sustainability_score) VALUES (1,'Cotton Shirt','Tops',80),(2,'Denim Jeans','Bottoms',60),(3,'Silk Scarf','Accessories',90); | SELECT g.garment_name, SUM(gs.quantity) as total_quantity FROM garment_sales gs JOIN garments g ON gs.garment_id = g.garment_id GROUP BY g.garment_name ORDER BY total_quantity DESC LIMIT 1; |
Which aircraft models have a wingspan greater than their fuselage length? | CREATE TABLE AircraftDimensions (Model VARCHAR(50),Wingspan INT,FuselageLength INT); INSERT INTO AircraftDimensions (Model,Wingspan,FuselageLength) VALUES ('Boeing 747',211,232),('Boeing 787 Dreamliner',197,186),('Airbus A320',118,124),('Airbus A380',262,245),('Bombardier CRJ700',91,124); | SELECT Model FROM AircraftDimensions WHERE Wingspan > FuselageLength; |
How many players from each continent play Non-VR games? | CREATE TABLE countries (id INT,name VARCHAR(255),continent VARCHAR(255)); INSERT INTO countries (id,name,continent) VALUES (1,'USA','North America'),(2,'Canada','North America'),(3,'Mexico','North America'),(4,'Brazil','South America'),(5,'Argentina','South America'); | SELECT c.continent, COUNT(DISTINCT p.id) as num_players FROM players p JOIN player_games pg ON p.id = pg.player_id JOIN games g ON pg.game_id = g.id JOIN countries c ON p.country = c.name WHERE g.category = 'Non-VR' GROUP BY c.continent; |
How many military satellites are there in the 'SouthAmerica' schema? | CREATE SCHEMA SouthAmerica; CREATE TABLE MilitarySatellites (id INT,name VARCHAR(255),type VARCHAR(255),in_orbit BOOLEAN); INSERT INTO MilitarySatellites (id,name,type,in_orbit) VALUES (1,'SGE-SC','Earth Observation',true); INSERT INTO MilitarySatellites (id,name,type,in_orbit) VALUES (2,'GEO-I','Communications',true); | SELECT COUNT(*) FROM SouthAmerica.MilitarySatellites WHERE in_orbit = true; |
What is the total number of rural hospitals in each state, and the average number of hospital beds? | CREATE TABLE rural_hospitals (id INT,state VARCHAR(2),hospital_name VARCHAR(50),num_beds INT); INSERT INTO rural_hospitals (id,state,hospital_name,num_beds) VALUES (1,'AK','Bartlett Regional Hospital',72); CREATE TABLE states (state_abbr VARCHAR(2),state_name VARCHAR(20)); INSERT INTO states (state_abbr,state_name) VALUES ('AK','Alaska'); | SELECT r.state, COUNT(r.id) AS num_hospitals, AVG(r.num_beds) AS avg_beds FROM rural_hospitals r JOIN states s ON r.state = s.state_abbr GROUP BY r.state; |
List all unique workplace names from the 'workplace_data' table that do not have any records in the 'collective_bargaining' table. | CREATE TABLE workplace_data (workplace_id INT,workplace_name TEXT); CREATE TABLE collective_bargaining (agreement_status TEXT,workplace_id INT); | SELECT DISTINCT workplace_data.workplace_name FROM workplace_data LEFT JOIN collective_bargaining ON workplace_data.workplace_id = collective_bargaining.workplace_id WHERE collective_bargaining.workplace_id IS NULL; |
How many female attendees were there at the 'Dance Recital'? | CREATE TABLE attendee_demographics (attendee_id INT,attendee_name VARCHAR(50),attendee_gender VARCHAR(50)); INSERT INTO attendee_demographics (attendee_id,attendee_name,attendee_gender) VALUES (1,'Jane Smith','Female'),(2,'Michael Johnson','Male'),(3,'Sophia Rodriguez','Female'); CREATE TABLE event_attendance (attendee_id INT,event_name VARCHAR(50)); INSERT INTO event_attendance (attendee_id,event_name) VALUES (1,'Dance Recital'),(2,'Art in the Park'),(3,'Dance Recital'); | SELECT COUNT(*) FROM attendee_demographics ad JOIN event_attendance ea ON ad.attendee_id = ea.attendee_id WHERE attendee_gender = 'Female' AND event_name = 'Dance Recital'; |
What is the minimum age of patients who have had a tetanus shot in the last 10 years in Florida? | CREATE TABLE Patients (PatientID INT,Age INT,TetanusShot DATE,State TEXT); INSERT INTO Patients (PatientID,Age,TetanusShot,State) VALUES (1,30,'2020-05-01','Florida'); | SELECT MIN(Age) FROM Patients WHERE TetanusShot >= DATEADD(year, -10, GETDATE()) AND State = 'Florida'; |
What is the total donation amount per category in Q1 2022? | CREATE TABLE donations (id INT,donor_name VARCHAR(50),donation_amount DECIMAL(10,2),donation_date DATE,category VARCHAR(50)); INSERT INTO donations (id,donor_name,donation_amount,donation_date,category) VALUES (1,'John Doe',100,'2022-01-01','Education'),(2,'Jane Smith',150,'2022-03-15','Health'); | SELECT category, SUM(donation_amount) as total_donation FROM donations WHERE donation_date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY category; |
List the top 5 legaltech patents filed by year, ordered by the number of patents filed | CREATE TABLE legaltech_patents (patent_id INT,filing_year INT,company VARCHAR(50)); INSERT INTO legaltech_patents (patent_id,filing_year,company) VALUES (1,2019,'TechCorp'),(2,2020,'LegalLabs'),(3,2019,'JusticeTech'),(4,2018,'TechCorp'),(5,2020,'JusticeTech'); | SELECT filing_year, COUNT(*) AS num_patents FROM legaltech_patents GROUP BY filing_year ORDER BY num_patents DESC LIMIT 5; |
What is the average R&D expenditure for a specific drug category? | CREATE TABLE drugs (id INT,name VARCHAR(255),category VARCHAR(255)); CREATE TABLE rd_expenditures (id INT,drug_id INT,amount DECIMAL(10,2)); | SELECT AVG(rd_expenditures.amount) FROM rd_expenditures JOIN drugs ON rd_expenditures.drug_id = drugs.id WHERE drugs.category = 'Pain Relievers'; |
What is the total number of followers for users in Brazil? | CREATE TABLE users (id INT,country VARCHAR(255),followers INT); INSERT INTO users (id,country,followers) VALUES (1,'Brazil',1000),(2,'USA',2000),(3,'Brazil',3000),(4,'USA',4000); | SELECT SUM(followers) FROM users WHERE country = 'Brazil'; |
How many autonomous buses are in operation in New York, Chicago, and Los Angeles? | CREATE TABLE autonomous_buses (bus_id INT,city VARCHAR(20),in_operation BOOLEAN); INSERT INTO autonomous_buses (bus_id,city,in_operation) VALUES (1,'New York',TRUE),(2,'New York',FALSE),(3,'Chicago',TRUE),(4,'Chicago',TRUE),(5,'Los Angeles',FALSE),(6,'Los Angeles',TRUE); | SELECT city, COUNT(*) FROM autonomous_buses WHERE in_operation = TRUE GROUP BY city; |
List the regulatory frameworks for each decentralized application in the 'DeFi' category, ordered by the date of implementation. | CREATE TABLE dapps (id INT,name TEXT,category TEXT,launch_date DATE); INSERT INTO dapps (id,name,category,launch_date) VALUES (1,'AppA','DeFi','2020-01-01'),(2,'AppB','DeFi','2019-06-15'),(3,'AppC','NFT','2021-03-20'); CREATE TABLE regulatory_frameworks (id INT,dapp_id INT,name TEXT,implementation_date DATE); INSERT INTO regulatory_frameworks (id,dapp_id,name,implementation_date) VALUES (1,1,'RegA','2020-02-01'),(2,1,'RegB','2020-06-01'),(3,2,'RegC','2019-07-01'); | SELECT d.name, r.name, r.implementation_date FROM dapps d JOIN regulatory_frameworks r ON d.id = r.dapp_id WHERE d.category = 'DeFi' ORDER BY r.implementation_date; |
Who is the oldest athlete in the 'golf_players' table? | CREATE TABLE golf_players (player_id INT,name VARCHAR(50),age INT); INSERT INTO golf_players (player_id,name,age) VALUES (1,'Tiger Woods',45); INSERT INTO golf_players (player_id,name,age) VALUES (2,'Phil Mickelson',51); | SELECT name, MAX(age) FROM golf_players; |
What's the total investment in climate communication in Asia and South America from 2010 to 2020? | CREATE TABLE investments (region TEXT,year INT,amount FLOAT); INSERT INTO investments (region,year,amount) VALUES ('Asia',2010,100000); INSERT INTO investments (region,year,amount) VALUES ('South America',2010,50000); | SELECT SUM(amount) FROM investments WHERE region IN ('Asia', 'South America') AND year BETWEEN 2010 AND 2020; |
What is the total installed capacity of wind energy in Germany and France, and which one has a higher capacity? | CREATE TABLE wind_energy (country VARCHAR(20),installed_capacity INT); INSERT INTO wind_energy (country,installed_capacity) VALUES ('Germany',60000),('France',45000); | SELECT w1.country, SUM(w1.installed_capacity) as total_capacity FROM wind_energy w1 WHERE w1.country IN ('Germany', 'France') GROUP BY w1.country; |
What is the sum of economic impact of sustainable tourism in Africa? | CREATE TABLE sustainable_tourism (tourism_id INT,location VARCHAR(50),economic_impact INT); INSERT INTO sustainable_tourism VALUES (1,'Maasai Mara',15000),(2,'Victoria Falls',20000),(3,'Sahara Desert',10000),(4,'Serengeti',25000); | SELECT SUM(economic_impact) FROM sustainable_tourism WHERE location LIKE '%Africa%'; |
Find the exhibition with the highest visitor count in the 'Renaissance' genre. | CREATE TABLE Exhibitions (id INT,name TEXT,genre TEXT,visitor_count INT); | SELECT name, visitor_count FROM (SELECT name, visitor_count, ROW_NUMBER() OVER (PARTITION BY genre ORDER BY visitor_count DESC) as rn FROM Exhibitions WHERE genre = 'Renaissance') t WHERE rn = 1; |
What is the total number of satellites launched by country in the SpaceLaunchs table? | CREATE TABLE SpaceLaunchs (LaunchID INT,Country VARCHAR(50),SatelliteID INT); INSERT INTO SpaceLaunchs (LaunchID,Country,SatelliteID) VALUES (1,'USA',101),(2,'Russia',201),(3,'China',301),(4,'India',401),(5,'Japan',501); | SELECT Country, COUNT(SatelliteID) AS TotalSatellites FROM SpaceLaunchs GROUP BY Country; |
What is the treatment duration for the patient with ID 3? | CREATE TABLE treatments (id INT PRIMARY KEY,patient_id INT,name VARCHAR(255),duration INT); INSERT INTO treatments (id,patient_id,name,duration) VALUES (1,3,'Psychotherapy',20); | SELECT duration FROM treatments WHERE patient_id = 3; |
How many wildlife species are present in each region and their conservation status? | CREATE TABLE wildlife (region VARCHAR(50),species VARCHAR(50),conservation_status VARCHAR(50)); INSERT INTO wildlife (region,species,conservation_status) VALUES ('North America','Grizzly Bear','Vulnerable'),('North America','Caribou','Threatened'),('South America','Jaguar','Near Threatened'); | SELECT region, COUNT(species) as species_count, STRING_AGG(conservation_status, ',') as conservation_status FROM wildlife GROUP BY region; |
What is the total number of traffic violations in the "TrafficViolations" table, per type of violation, for violations that occurred in school zones? | CREATE TABLE TrafficViolations (id INT,violation_type VARCHAR(50),location VARCHAR(50),fine DECIMAL(5,2)); INSERT INTO TrafficViolations (id,violation_type,location,fine) VALUES (1,'Speeding','School Zone',100),(2,'Illegal Parking','Business District',50),(3,'Speeding','Residential Area',80),(4,'Running Red Light','School Zone',150); | SELECT violation_type, COUNT(*) as num_violations FROM TrafficViolations WHERE location LIKE '%School%' GROUP BY violation_type; |
What is the average cultural competency score for mental health facilities in California? | CREATE TABLE mental_health_facilities (id INT,name VARCHAR,state VARCHAR,cultural_competency_score INT); INSERT INTO mental_health_facilities (id,name,state,cultural_competency_score) VALUES (1,'Facility One','California',85); INSERT INTO mental_health_facilities (id,name,state,cultural_competency_score) VALUES (2,'Facility Two','California',90); | SELECT state, AVG(cultural_competency_score) as avg_score FROM mental_health_facilities WHERE state = 'California' GROUP BY state; |
What is the minimum transaction value for social impact investments in Germany? | CREATE TABLE social_impact_investments (id INT,country VARCHAR(50),transaction_value FLOAT); INSERT INTO social_impact_investments (id,country,transaction_value) VALUES (1,'United States',5000.0),(2,'Canada',7000.0),(3,'United Kingdom',10000.0),(4,'Germany',3000.0); | SELECT MIN(transaction_value) FROM social_impact_investments WHERE country = 'Germany'; |
Delete landfill capacity data for January 2021. | CREATE TABLE landfill_capacity (id INT,date DATE,capacity INT); INSERT INTO landfill_capacity (id,date,capacity) VALUES (1,'2021-01-01',10000),(2,'2021-02-01',9500),(3,'2021-03-01',9200),(4,'2021-04-01',8900); | DELETE FROM landfill_capacity WHERE date = '2021-01-01'; |
Insert a new record into the 'fan_demographics' table with age 35, gender 'Female' and location 'California' | CREATE TABLE fan_demographics (age INT,gender VARCHAR(10),location VARCHAR(20)); | INSERT INTO fan_demographics (age, gender, location) VALUES (35, 'Female', 'California'); |
What is the maximum weight of artifacts excavated from 'Site F'? | CREATE TABLE Site (SiteID VARCHAR(10),SiteName VARCHAR(20)); INSERT INTO Site (SiteID,SiteName) VALUES ('F','Site F'); CREATE TABLE Artifact (ArtifactID VARCHAR(10),SiteID VARCHAR(10),Weight FLOAT); INSERT INTO Artifact (ArtifactID,SiteID,Weight) VALUES ('1','F',12.3),('2','F',15.6),('3','F',18.9),('4','F',20.7),('5','F',25.6); | SELECT MAX(Weight) FROM Artifact WHERE SiteID = 'F'; |
What is the average rating of movies by director? | CREATE TABLE movies (id INT,title VARCHAR(255),release_year INT,director VARCHAR(255),rating DECIMAL(3,2)); | SELECT director, AVG(rating) as avg_rating FROM movies GROUP BY director; |
Which countries received military humanitarian assistance in 2020? | CREATE TABLE countries (id INT,name TEXT,region TEXT); INSERT INTO countries (id,name,region) VALUES (1,'Country1','Africa'),(2,'Country2','Asia'),(3,'Country3','Europe'); CREATE TABLE military_humanitarian_assistance (id INT,country_id INT,year INT); INSERT INTO military_humanitarian_assistance (id,country_id,year) VALUES (1,1,2019),(2,3,2020),(3,1,2020); | SELECT DISTINCT countries.name FROM countries JOIN military_humanitarian_assistance ON countries.id = military_humanitarian_assistance.country_id WHERE military_humanitarian_assistance.year = 2020; |
What are the average preparation times for vegan dishes compared to non-vegan dishes? | CREATE TABLE dish_prep_times (id INT,dish_id INT,prep_time INT); CREATE TABLE dishes (id INT,name TEXT,is_vegan BOOLEAN); | SELECT AVG(prep_time) as avg_prep_time FROM dish_prep_times JOIN dishes ON dish_prep_times.dish_id = dishes.id WHERE dishes.is_vegan = true; SELECT AVG(prep_time) as avg_prep_time FROM dish_prep_times JOIN dishes ON dish_prep_times.dish_id = dishes.id WHERE dishes.is_vegan = false; |
What is the total cost of ingredients for the vegan menu? | CREATE TABLE Menu (menu_id INT,menu_name VARCHAR(20)); INSERT INTO Menu (menu_id,menu_name) VALUES (1,'Vegan'),(2,'Non-Vegan'); CREATE TABLE Menu_Ingredients (ingredient_id INT,ingredient_cost FLOAT,menu_id INT); INSERT INTO Menu_Ingredients (ingredient_id,ingredient_cost,menu_id) VALUES (1,5.0,1),(2,3.5,1),(3,8.0,2),(4,7.0,2); | SELECT SUM(ingredient_cost) FROM Menu_Ingredients WHERE menu_id = 1; |
Insert a new subscriber for the 'Mobile' service in the 'Rural' region with a revenue of 25.00 in Q3 of 2022. | CREATE TABLE Subscribers (subscriber_id INT,service VARCHAR(20),region VARCHAR(20),revenue FLOAT,payment_date DATE); | INSERT INTO Subscribers (subscriber_id, service, region, revenue, payment_date) VALUES (6, 'Mobile', 'Rural', 25.00, '2022-10-01'); |
What is the total landfill capacity in cubic meters for Asia? | CREATE TABLE LandfillCapacity (country VARCHAR(255),landfill_capacity_cubic_meters DECIMAL(15,2),region VARCHAR(255)); INSERT INTO LandfillCapacity (country,landfill_capacity_cubic_meters,region) VALUES ('Japan',45000000.0,'Asia'),('China',75000000.0,'Asia'),('India',55000000.0,'Asia'); | SELECT SUM(landfill_capacity_cubic_meters) FROM LandfillCapacity WHERE region = 'Asia'; |
Insert new records into the water_usage table | CREATE TABLE water_usage (location VARCHAR(255),usage INT); | INSERT INTO water_usage (location, usage) VALUES ('City D', 30), ('City E', 40); |
Update mobile subscribers' data plans if they have used more than 10GB of data in the last week. | CREATE TABLE high_data_users (subscriber_id INT,name VARCHAR(50),data_usage_gb FLOAT); INSERT INTO high_data_users (subscriber_id,name,data_usage_gb) VALUES (13,'Kai Lewis',12); INSERT INTO high_data_users (subscriber_id,name,data_usage_gb) VALUES (14,'Lila Clark',15); | UPDATE mobile_subscribers M SET data_plan = 'Unlimited' FROM mobile_subscribers M INNER JOIN high_data_users H ON M.subscriber_id = H.subscriber_id WHERE M.data_plan != 'Unlimited' AND H.data_usage_gb > 10; |
What is the average DBH for trees in the tropical rainforest that belong to the Dipterocarpaceae family? | CREATE TABLE biomes (biome_id INT PRIMARY KEY,name VARCHAR(50),area_km2 FLOAT); INSERT INTO biomes (biome_id,name,area_km2) VALUES (1,'Tropical Rainforest',15000000.0),(2,'Temperate Rainforest',250000.0),(3,'Boreal Forest',12000000.0); CREATE TABLE trees (tree_id INT PRIMARY KEY,species VARCHAR(50),biome_id INT,family VARCHAR(50),dbh FLOAT,FOREIGN KEY (biome_id) REFERENCES biomes(biome_id)); INSERT INTO trees (tree_id,species,biome_id,family,dbh) VALUES (1,'Dipterocarpus',1,'Dipterocarpaceae',50.0),(2,'Shorea',1,'Dipterocarpaceae',60.0),(3,'Vatica',1,'Dipterocarpaceae',40.0); | SELECT AVG(dbh) FROM trees WHERE trees.family = 'Dipterocarpaceae' AND biomes.name = 'Tropical Rainforest'; |
What are the top 3 countries with the highest environmental impact assessments for mining companies, for the last 2 years? | CREATE TABLE MiningEnvironmentalImpact (year INT,company TEXT,country TEXT,impact_assessment_score INT); INSERT INTO MiningEnvironmentalImpact (year,company,country,impact_assessment_score) VALUES (2020,'Canada Gold Corp','Canada',80),(2021,'Canada Gold Corp','Canada',85),(2020,'Australian Mining Inc','Australia',90),(2021,'Australian Mining Inc','Australia',95),(2020,'Brazilian Mining Co','Brazil',75),(2021,'Brazilian Mining Co','Brazil',80),(2020,'South African Mining Ltd','South Africa',85),(2021,'South African Mining Ltd','South Africa',90); | SELECT context.country, SUM(context.impact_assessment_score) as total_impact_score FROM MiningEnvironmentalImpact context WHERE context.year BETWEEN 2020 AND 2021 GROUP BY context.country ORDER BY total_impact_score DESC LIMIT 3; |
How many intelligence operations were conducted in the Middle East and North Africa between 2015 and 2020? | CREATE TABLE intelligence_operations (id INT,name VARCHAR(50),location VARCHAR(50),year INT); INSERT INTO intelligence_operations (id,name,location,year) VALUES (1,'Operation Red Sword','Middle East',2018); | SELECT COUNT(*) FROM intelligence_operations WHERE location IN ('Middle East', 'North Africa') AND year BETWEEN 2015 AND 2020; |
What is the count of stone artifacts from excavation sites in South America? | CREATE TABLE excavation_sites (site_id INT,site_name VARCHAR(255)); INSERT INTO excavation_sites (site_id,site_name) VALUES (1,'Peruvian Ruins'),(2,'Brazilian Dig'),(3,'Argentine Excavation'); CREATE TABLE artifacts (artifact_id INT,artifact_name VARCHAR(255),site_id INT,artifact_weight FLOAT,artifact_material VARCHAR(255)); INSERT INTO artifacts (artifact_id,artifact_name,site_id,artifact_weight,artifact_material) VALUES (1,'Stone Tool',1,2.5,'Stone'),(2,'Pottery Shard',1,0.3,'Clay'),(3,'Metal Artifact',2,1.2,'Metal'),(4,'Stone Ornament',3,0.7,'Stone'); | SELECT COUNT(*) FROM artifacts JOIN excavation_sites ON artifacts.site_id = excavation_sites.site_id WHERE excavation_sites.site_name LIKE '%South America%' AND artifacts.artifact_material = 'Stone'; |
Create a view to display the total number of community policing activities by location | CREATE TABLE community_policing (policing_type VARCHAR(255),frequency INT,location VARCHAR(255)); | CREATE VIEW total_policing_activities AS SELECT location, SUM(frequency) as total_frequency FROM community_policing GROUP BY location; |
Find the top 3 most visited exhibitions by city and the number of visitors? | CREATE TABLE Exhibitions (ExhibitionID INT,ExhibitionName VARCHAR(100),City VARCHAR(50)); CREATE TABLE Visits (VisitID INT,ExhibitionID INT,VisitorID INT); INSERT INTO Exhibitions (ExhibitionID,ExhibitionName,City) VALUES (1,'Mona Lisa','Paris'),(2,'Starry Night','Amsterdam'),(3,'Sunflowers','Amsterdam'),(4,'David','Rome'); INSERT INTO Visits (VisitID,ExhibitionID,VisitorID) VALUES (1,1,1),(2,1,2),(3,2,1),(4,3,2),(5,4,1),(6,1,3); | SELECT City, ExhibitionName, COUNT(VisitorID) AS NumberOfVisitors FROM Exhibitions A JOIN Visits B ON A.ExhibitionID = B.ExhibitionID GROUP BY City, ExhibitionName ORDER BY City, NumberOfVisitors DESC LIMIT 3; |
What is the total weight of all ingredients for each product? | CREATE TABLE product (product_id INT,product_name TEXT); CREATE TABLE ingredient (ingredient_id INT,product_id INT,weight FLOAT,country TEXT); INSERT INTO product VALUES (1,'Lipstick'),(2,'Moisturizer'); INSERT INTO ingredient VALUES (1,1,50.0,'CA'),(2,1,25.0,'US'),(3,2,30.0,'CA'); | SELECT p.product_name, SUM(i.weight) FROM product p JOIN ingredient i ON p.product_id = i.product_id GROUP BY p.product_name; |
What is the total production of 'wheat' and 'rice' for each country in 2020, sorted by production amount? | CREATE TABLE crops (id INT,crop_name VARCHAR(20),country VARCHAR(20),production INT,year INT); INSERT INTO crops (id,crop_name,country,production,year) VALUES (1,'wheat','USA',50000,2020),(2,'rice','China',60000,2020); | SELECT country, SUM(production) as total_production FROM crops WHERE crop_name IN ('wheat', 'rice') AND year = 2020 GROUP BY country ORDER BY total_production DESC; |
How many humanitarian assistance missions were conducted by year? | CREATE TABLE IF NOT EXISTS humanitarian_assistance (id INT PRIMARY KEY,year INT,num_missions INT); | SELECT year, SUM(num_missions) FROM humanitarian_assistance GROUP BY year; |
List the total investment made by socially responsible investors from Latin America | CREATE TABLE investors(id INT,name TEXT,region TEXT,socially_responsible BOOLEAN); CREATE TABLE investments(id INT,investor_id INT,startup_id INT,investment_amount FLOAT); INSERT INTO investors (id,name,region,socially_responsible) VALUES (1,'Pedro Alvarez','Latin America',true); INSERT INTO investors (id,name,region,socially_responsible) VALUES (2,'Mariana Santos','North America',false); INSERT INTO investors (id,name,region,socially_responsible) VALUES (3,'Jaime Garcia','Latin America',true); INSERT INTO investors (id,name,region,socially_responsible) VALUES (4,'Heidi Johnson','Europe',false); INSERT INTO investments (id,investor_id,startup_id,investment_amount) VALUES (1,1,1,250000); INSERT INTO investments (id,investor_id,startup_id,investment_amount) VALUES (2,2,3,800000); INSERT INTO investments (id,investor_id,startup_id,investment_amount) VALUES (3,3,2,550000); INSERT INTO investments (id,investor_id,startup_id,investment_amount) VALUES (4,4,4,700000); | SELECT SUM(investment_amount) FROM investments i JOIN investors a ON i.investor_id = a.id WHERE a.region = 'Latin America' AND a.socially_responsible = true; |
What is the average depth of all deep-sea expeditions led by the 'Ocean Explorers' organization? | CREATE TABLE deep_sea_expeditions (id INT,name TEXT,organization TEXT,max_depth FLOAT); INSERT INTO deep_sea_expeditions (id,name,organization,max_depth) VALUES (1,'Expedition 1','Ocean Explorers',8000.0),(2,'Expedition 2','Ocean Researchers',10000.0),(3,'Expedition 3','Ocean Explorers',6000.0); | SELECT AVG(max_depth) FROM deep_sea_expeditions WHERE organization = 'Ocean Explorers'; |
What is the earliest approval date for drugs that have a sales figure greater than 2000000 in any market? | CREATE TABLE drug_sales (drug_name TEXT,year INTEGER,sales INTEGER,market TEXT); INSERT INTO drug_sales (drug_name,year,sales,market) VALUES ('DrugA',2018,3000000,'US'); INSERT INTO drug_sales (drug_name,year,sales,market) VALUES ('DrugB',2018,1500000,'Canada'); INSERT INTO drug_sales (drug_name,year,sales,market) VALUES ('DrugC',2019,2200000,'Mexico'); CREATE TABLE drug_approval (drug_name TEXT,approval_date DATE); INSERT INTO drug_approval (drug_name,approval_date) VALUES ('DrugA','2016-01-01'); INSERT INTO drug_approval (drug_name,approval_date) VALUES ('DrugB','2017-04-20'); INSERT INTO drug_approval (drug_name,approval_date) VALUES ('DrugC','2018-12-31'); | SELECT MIN(drug_approval.approval_date) FROM drug_approval JOIN drug_sales ON drug_approval.drug_name = drug_sales.drug_name WHERE drug_sales.sales > 2000000; |
Find the water usage data with the highest usage amount in the water_usage table | CREATE TABLE water_usage (date DATE,usage_category VARCHAR(20),region VARCHAR(20),usage_amount INT); INSERT INTO water_usage (date,usage_category,region,usage_amount) VALUES ('2022-07-01','Residential','Northeast',15000),('2022-07-02','Industrial','Midwest',200000),('2022-07-03','Agricultural','West',800000); | SELECT * FROM water_usage WHERE usage_amount = (SELECT MAX(usage_amount) FROM water_usage); |
Which properties in the sustainable_urbanism table have a size larger than the average property size? | CREATE TABLE sustainable_urbanism (property_id INT,size FLOAT,location VARCHAR(255)); INSERT INTO sustainable_urbanism (property_id,size,location) VALUES (1,1200,'Eco City'),(2,1500,'Green Valley'); | SELECT * FROM sustainable_urbanism WHERE size > (SELECT AVG(size) FROM sustainable_urbanism); |
Rank the mining operations with the highest carbon emissions in the past year. | CREATE TABLE Mining_Operation (Operation_ID INT,Mine_Name VARCHAR(50),Location VARCHAR(50),Operation_Type VARCHAR(50),Start_Date DATE,End_Date DATE); CREATE TABLE Environmental_Impact (Impact_ID INT,Operation_ID INT,Date DATE,Carbon_Emissions INT,Water_Usage INT,Waste_Generation INT); | SELECT Operation_ID, Mine_Name, Carbon_Emissions, RANK() OVER (ORDER BY SUM(Carbon_Emissions) DESC) AS Carbon_Emissions_Rank FROM Environmental_Impact JOIN Mining_Operation ON Environmental_Impact.Operation_ID = Mining_Operation.Operation_ID WHERE Date >= DATEADD(year, -1, GETDATE()) GROUP BY Operation_ID, Mine_Name; |
What is the average cost of cybersecurity strategies for each sector in 2019? | CREATE TABLE cybersecurity_strategies (id INT PRIMARY KEY,strategy VARCHAR(50),cost INT,sector VARCHAR(50),year INT); INSERT INTO cybersecurity_strategies (id,strategy,cost,sector,year) VALUES (5,'Encryption',75000,'Public',2019); INSERT INTO cybersecurity_strategies (id,strategy,cost,sector,year) VALUES (6,'Intrusion Prevention Systems',120000,'Private',2019); | SELECT sector, AVG(cost) as avg_cost FROM cybersecurity_strategies WHERE year = 2019 GROUP BY sector; |
Update the water temperature for February 14, 2022, to 22.3 degrees in the FishTank table. | CREATE TABLE FishTank (date DATE,temperature FLOAT); INSERT INTO FishTank (date,temperature) VALUES ('2022-01-01',20.5),('2022-01-02',21.0),('2022-01-03',21.5),('2022-02-14',20.0); | UPDATE FishTank SET temperature = 22.3 WHERE date = '2022-02-14'; |
What is the average age of teachers in New York public schools? | CREATE TABLE public_schools (id INT,name TEXT,location TEXT,num_students INT,avg_teacher_age FLOAT); INSERT INTO public_schools (id,name,location,num_students,avg_teacher_age) VALUES (1,'School 1','NY',500,45.3),(2,'School 2','NY',600,43.2); | SELECT AVG(avg_teacher_age) FROM public_schools WHERE location = 'NY'; |
What is the average speed of shared electric scooters in San Francisco, partitioned by company? | CREATE TABLE shared_scooters (scooter_id INT,company VARCHAR(255),speed FLOAT,timestamp TIMESTAMP); INSERT INTO shared_scooters (scooter_id,company,speed,timestamp) VALUES (1,'CompanyA',15.5,'2022-01-01 10:00:00'),(2,'CompanyB',14.3,'2022-01-01 10:00:00'); | SELECT company, AVG(speed) AS avg_speed FROM (SELECT company, speed, TIMESTAMP_TRUNC(timestamp, HOUR) AS truncated_time, ROW_NUMBER() OVER (PARTITION BY company, TIMESTAMP_TRUNC(timestamp, HOUR) ORDER BY timestamp) rn FROM shared_scooters WHERE city = 'San Francisco') WHERE rn = 1 GROUP BY company; |
What is the total capacity of all cargo ships owned by Pacific Shipping Company? | CREATE TABLE shipping_companies (company_id INT,name VARCHAR(255)); INSERT INTO shipping_companies (company_id,name) VALUES (1,'Pacific Shipping Company'); CREATE TABLE cargo_ships (ship_id INT,company_id INT,capacity INT); INSERT INTO cargo_ships (ship_id,company_id,capacity) VALUES (1,1,15000),(2,1,18000),(3,1,20000); | SELECT SUM(capacity) FROM cargo_ships WHERE company_id = (SELECT company_id FROM shipping_companies WHERE name = 'Pacific Shipping Company'); |
List all artworks that have been created by artists from Africa and are on display in Europe. | CREATE TABLE Artists (ArtistID INT,Name TEXT,Country TEXT);CREATE TABLE Artworks (ArtworkID INT,Title TEXT,ArtistID INT);CREATE TABLE GalleryArtworks (GalleryID INT,ArtworkID INT);CREATE TABLE GalleryLocations (GalleryID INT,Country TEXT); | SELECT Artworks.Title FROM Artists INNER JOIN Artworks ON Artworks.ArtistID = Artists.ArtistID INNER JOIN GalleryArtworks ON Artworks.ArtworkID = GalleryArtworks.ArtworkID INNER JOIN GalleryLocations ON GalleryArtworks.GalleryID = GalleryLocations.GalleryID WHERE Artists.Country = 'Africa' AND GalleryLocations.Country = 'Europe'; |
List all unique job titles in Union 'P' with more than 25 members. | CREATE TABLE UnionP(member_id INT,job_title VARCHAR(20)); INSERT INTO UnionP(member_id,job_title) VALUES(16001,'Developer'),(16002,'Developer'),(16003,'Designer'),(16004,'Tester'),(16005,'Designer'); | SELECT DISTINCT job_title FROM UnionP GROUP BY job_title HAVING COUNT(*) > 25; |
What is the total number of hospitals and clinics in the public health database? | CREATE TABLE hospitals (id INT,name VARCHAR(50),location VARCHAR(50)); INSERT INTO hospitals (id,name,location) VALUES (1,'Hospital A','City A'); INSERT INTO hospitals (id,name,location) VALUES (2,'Hospital B','City B'); CREATE TABLE clinics (id INT,name VARCHAR(50),location VARCHAR(50)); INSERT INTO clinics (id,name,location) VALUES (1,'Clinic A','City A'); INSERT INTO clinics (id,name,location) VALUES (2,'Clinic B','City B'); | SELECT COUNT(*) FROM hospitals UNION SELECT COUNT(*) FROM clinics; |
What was the total energy consumption of the top 5 renewable energy sources, by country, in 2018? | CREATE TABLE energy_consumption (country text,source text,year integer,consumption integer); | SELECT country, source, SUM(consumption) as total_consumption FROM energy_consumption WHERE year = 2018 AND source IN ('Solar', 'Wind', 'Hydro', 'Geothermal', 'Biomass') GROUP BY country ORDER BY total_consumption DESC LIMIT 5; |
What is the 3rd largest property size in Spain? | CREATE TABLE properties (id INT,size INT,country VARCHAR(255)); INSERT INTO properties (id,size,country) VALUES (1,1500,'Spain'),(2,2000,'Spain'),(3,1800,'Spain'); | SELECT size FROM (SELECT size, ROW_NUMBER() OVER (ORDER BY size DESC) as rn FROM properties WHERE country = 'Spain') t WHERE rn = 3; |
Who are the top 5 employees with the most disability accommodations requests? | CREATE TABLE employees (employee_id INT,employee_name VARCHAR(255),department VARCHAR(255)); CREATE TABLE accommodations (accommodation_id INT,employee_id INT,accommodation_type VARCHAR(255),request_date DATE); INSERT INTO employees (employee_id,employee_name,department) VALUES (1,'Jane Smith','HR'),(2,'John Doe','IT'),(3,'Alice Johnson','HR'),(4,'Bob Brown','IT'),(5,'Charlie Green','Finance'); INSERT INTO accommodations (accommodation_id,employee_id,accommodation_type,request_date) VALUES (1,1,'Ergonomic Chair','2021-06-01'),(2,2,'Screen Reader','2021-05-15'),(3,1,'Adjustable Desk','2021-04-20'),(4,3,'Sign Language Interpreter','2021-03-05'),(5,2,'Speech-to-Text Software','2021-02-28'),(6,1,'Accessible Keyboard','2021-01-10'); | SELECT e.employee_name, COUNT(a.employee_id) as num_requests FROM employees e INNER JOIN accommodations a ON e.employee_id = a.employee_id GROUP BY e.employee_name ORDER BY num_requests DESC LIMIT 5; |
What is the number of unique donors and volunteers for each organization, ordered by the number of total contributions? | CREATE TABLE Donors (DonorID int,DonorName text); INSERT INTO Donors (DonorID,DonorName) VALUES (1,'Alice Johnson'),(2,'Bob Smith'),(3,'Carol Brown'); | SELECT OrganizationID, ROW_NUMBER() OVER (ORDER BY DonorCount + VolunteerCount DESC) as Rank, DonorCount, VolunteerCount FROM (SELECT OrganizationID, COUNT(DISTINCT DonorID) as DonorCount, COUNT(DISTINCT VolunteerID) as VolunteerCount FROM Volunteers JOIN Donations ON Volunteers.DonorID = Donations.DonorID JOIN DonationRecipients ON Donations.DonationID = DonationRecipients.DonationID GROUP BY OrganizationID) as Subquery; |
Find the total claim amount for each gender? | CREATE TABLE Policyholder (PolicyholderID INT,PolicyholderAge INT,PolicyholderGender VARCHAR(10)); CREATE TABLE Claim (ClaimID INT,PolicyholderID INT,ClaimAmount DECIMAL(10,2)); INSERT INTO Policyholder VALUES (1,45,'Female'),(2,55,'Male'),(3,30,'Female'); INSERT INTO Claim VALUES (1,1,5000),(2,1,3000),(3,2,7000),(4,3,8000); | SELECT PolicyholderGender, SUM(ClaimAmount) as TotalClaimAmount FROM Claim JOIN Policyholder ON Claim.PolicyholderID = Policyholder.PolicyholderID GROUP BY PolicyholderGender; |
What is the average duration of successful space missions for each organization? | CREATE TABLE space_missions (id INT,organization VARCHAR(255),result VARCHAR(10),duration INT); INSERT INTO space_missions (id,organization,result,duration) VALUES (1,'NASA','successful',120),(2,'SpaceX','successful',200),(3,'ESA','unsuccessful',150),(4,'NASA','successful',180),(5,'SpaceX','unsuccessful',100); | SELECT organization, AVG(duration) FROM space_missions WHERE result = 'successful' GROUP BY organization; |
Find suppliers offering the most variety of organic ingredients | CREATE TABLE ingredients (id INT,name VARCHAR(50),is_organic BOOLEAN,supplier_id INT); INSERT INTO ingredients (id,name,is_organic,supplier_id) VALUES (1,'Kale',TRUE,101),(2,'Quinoa',TRUE,101),(3,'Eggs',FALSE,102),(4,'Garlic',TRUE,103); CREATE TABLE suppliers (id INT,name VARCHAR(50)); INSERT INTO suppliers (id,name) VALUES (101,'Eco Farms'),(102,'Hen House'),(103,'Spice Station'); | SELECT s.name, COUNT(DISTINCT i.name) FROM ingredients i INNER JOIN suppliers s ON i.supplier_id = s.id WHERE i.is_organic = TRUE GROUP BY s.name ORDER BY COUNT(DISTINCT i.name) DESC LIMIT 1; |
How many cases did each attorney work on, grouped by attorney name? | CREATE TABLE attorneys (attorney_id INT,name TEXT); CREATE TABLE cases (case_id INT,attorney_id INT); | SELECT a.name, COUNT(c.attorney_id) AS case_count FROM attorneys a JOIN cases c ON a.attorney_id = c.attorney_id GROUP BY a.name |
List all indigenous communities in the 'arctic_circle' region. | CREATE TABLE indigenous_communities (id INT,community_name VARCHAR(255),region VARCHAR(255)); INSERT INTO indigenous_communities (id,community_name,region) VALUES (1,'Community A','arctic_circle'),(2,'Community B','canada'),(3,'Community C','greenland'),(4,'Community D','arctic_circle'); | SELECT community_name FROM indigenous_communities WHERE region = 'arctic_circle'; |
Find the number of geopolitical risk assessments for the South American region in the year 2018. | CREATE TABLE geopolitical_risk_assessments (id INT,region VARCHAR(255),assessment_year INT,assessment_text TEXT); INSERT INTO geopolitical_risk_assessments (id,region,assessment_year,assessment_text) VALUES (1,'South America',2018,'Assessment 3'); INSERT INTO geopolitical_risk_assessments (id,region,assessment_year,assessment_text) VALUES (2,'South America',2019,'Assessment 4'); | SELECT COUNT(*) FROM geopolitical_risk_assessments WHERE region = 'South America' AND assessment_year = 2018; |
How many factories are there in total? | CREATE TABLE factories (factory_id INT,location VARCHAR(50),capacity INT); INSERT INTO factories (factory_id,location,capacity) VALUES (1,'Madrid,Spain',5000),(2,'Paris,France',7000),(3,'London,UK',6000); | SELECT COUNT(*) FROM factories; |
What is the difference in average salary between male and female employees? | CREATE TABLE Employees (EmployeeID INT,Name VARCHAR(50),Gender VARCHAR(50),Salary FLOAT); INSERT INTO Employees (EmployeeID,Name,Gender,Salary) VALUES (1,'John Doe','Male',75000.00),(2,'Jane Smith','Female',80000.00),(3,'Mike Johnson','Male',60000.00); | SELECT (AVG(CASE WHEN Gender = 'Male' THEN Salary ELSE NULL END) - AVG(CASE WHEN Gender = 'Female' THEN Salary ELSE NULL END)) AS salary_difference; |
What is the percentage of financial capability programs offered in the East region? | CREATE TABLE programs (program_id INT,name VARCHAR(50),region VARCHAR(20),program_type VARCHAR(30)); INSERT INTO programs (program_id,name,region,program_type) VALUES (1,'Financial Education','East','Financial Capability'),(2,'Credit Counseling','West','Debt Management'); | SELECT region, (COUNT(*) FILTER (WHERE program_type = 'Financial Capability')) * 100.0 / COUNT(*) AS percentage FROM programs GROUP BY region; |
Compare threat levels for 'USA' and 'Canada' in Q2 2022 | CREATE TABLE threat_intelligence (country VARCHAR(100),threat_level VARCHAR(20),quarter VARCHAR(10)); | SELECT country, threat_level FROM threat_intelligence WHERE country IN ('USA', 'Canada') AND quarter = 'Q2 2022'; |
What is the maximum capacity of a shelter in 'west_africa' region? | CREATE TABLE region (region_id INT,name VARCHAR(255)); INSERT INTO region (region_id,name) VALUES (1,'west_africa'); CREATE TABLE shelter (shelter_id INT,name VARCHAR(255),region_id INT,capacity INT); INSERT INTO shelter (shelter_id,name,region_id,capacity) VALUES (1,'Shelter1',1,50),(2,'Shelter2',1,75); | SELECT MAX(capacity) FROM shelter WHERE region_id = (SELECT region_id FROM region WHERE name = 'west_africa'); |
What is the total sales volume for natural cosmetics in the Middle Eastern market? | CREATE TABLE cosmetic_sales (product_id INT,sale_volume INT,market VARCHAR(10)); CREATE TABLE product_info (product_id INT,is_natural BOOLEAN); INSERT INTO product_info (product_id,is_natural) VALUES (1,true),(2,false),(3,true); INSERT INTO cosmetic_sales (product_id,sale_volume,market) VALUES (1,200,'ME'),(2,300,'CA'),(3,400,'ME'); | SELECT SUM(cs.sale_volume) FROM cosmetic_sales cs JOIN product_info pi ON cs.product_id = pi.product_id WHERE pi.is_natural = true AND cs.market = 'ME'; |
What is the total number of AI safety incidents reported for each AI subfield in the first half of 2021? | CREATE TABLE ai_safety_incidents (incident_id INT,incident_date DATE,ai_subfield TEXT,incident_description TEXT); INSERT INTO ai_safety_incidents (incident_id,incident_date,ai_subfield,incident_description) VALUES (1,'2020-01-01','Explainable AI','Model failed to provide clear explanations'); INSERT INTO ai_safety_incidents (incident_id,incident_date,ai_subfield,incident_description) VALUES (2,'2019-12-31','Algorithmic Fairness','AI system showed bias against certain groups'); INSERT INTO ai_safety_incidents (incident_id,incident_date,ai_subfield,incident_description) VALUES (3,'2020-02-01','Explainable AI','Model provided inconsistent explanations'); | SELECT ai_subfield, COUNT(*) as incidents FROM ai_safety_incidents WHERE incident_date BETWEEN '2021-01-01' AND '2021-06-30' GROUP BY ai_subfield; |
Which regions have the highest and lowest rated AI tools? | CREATE TABLE ai_tools (tool_id INT,tool_name VARCHAR(50),region VARCHAR(50),rating FLOAT); INSERT INTO ai_tools (tool_id,tool_name,region,rating) VALUES (1,'AITSG1','APAC',4.3),(2,'AITSG2','EMEA',4.6),(3,'AITSG3','AMER',4.5); | SELECT region, MAX(rating) as max_rating, MIN(rating) as min_rating FROM ai_tools GROUP BY region; |
Delete the garment records with a price less than 20.00 or greater than 40.00 in the Garment table. | CREATE TABLE Garment (garment_id INT PRIMARY KEY,garment_name VARCHAR(50),category VARCHAR(50),price DECIMAL(10,2)); INSERT INTO Garment (garment_id,garment_name,category,price) VALUES (1,'Cotton T-Shirt','Tops',20.00),(2,'Jeans Pants','Bottoms',40.00),(3,'Linen Blouse','Tops',30.00); | DELETE FROM Garment WHERE price < 20.00 OR price > 40.00; |
What was the average speed of vessels visiting port Seattle in the fourth quarter of 2020? | CREATE TABLE Port (port_id INT PRIMARY KEY,port_name VARCHAR(255)); INSERT INTO Port (port_id,port_name) VALUES (1,'Seattle'); CREATE TABLE Vessel_Movement (vessel_id INT,movement_date DATE,port_id INT,speed DECIMAL(5,2),PRIMARY KEY (vessel_id,movement_date)); | SELECT AVG(speed) FROM Vessel_Movement VM JOIN Port P ON VM.port_id = P.port_id WHERE P.port_name = 'Seattle' AND EXTRACT(MONTH FROM VM.movement_date) BETWEEN 10 AND 12 AND EXTRACT(YEAR FROM VM.movement_date) = 2020; |
Insert a new record into the explainable_ai table with method set to 'SHAP', interpretability_score set to 0.9, and last_updated set to the current timestamp | CREATE TABLE explainable_ai (id INTEGER,method TEXT,interpretability_score REAL,last_updated TIMESTAMP); | INSERT INTO explainable_ai (method, interpretability_score, last_updated) VALUES ('SHAP', 0.9, CURRENT_TIMESTAMP); |
How many marine protected areas are in the Caribbean sea? | CREATE TABLE marine_protected_areas (area_name TEXT,location TEXT); INSERT INTO marine_protected_areas (area_name,location) VALUES ('Area 1','Caribbean Sea'),('Area 2','Mediterranean Sea'),('Area 3','Caribbean Sea'),('Area 4','Indian Ocean'); | SELECT COUNT(*) FROM marine_protected_areas WHERE location = 'Caribbean Sea'; |
What are the types of economic diversification projects in the 'economic_diversification' table? | CREATE TABLE economic_diversification (id INT,name VARCHAR(50),type VARCHAR(50),budget FLOAT); INSERT INTO economic_diversification (id,name,type,budget) VALUES (1,'Handicraft Training','Economic Diversification',50000.00),(2,'Eco-tourism Development','Economic Diversification',120000.00); | SELECT DISTINCT type FROM economic_diversification WHERE type = 'Economic Diversification'; |
What is the maximum orbital speed (in km/s) of all satellites in the Geostationary orbit? | CREATE TABLE satellite_orbits (id INT,satellite_id VARCHAR(50),orbit_type VARCHAR(20),orbital_speed FLOAT); | SELECT MAX(orbital_speed) FROM satellite_orbits WHERE orbit_type = 'Geostationary'; |
Find the total number of delayed shipments for each freight forwarder in the last month? | CREATE TABLE Forwarders (id INT,name VARCHAR(255)); CREATE TABLE Shipments (id INT,forwarder_id INT,shipped_date DATE,delivered_date DATE,delay INT); | SELECT f.name, SUM(CASE WHEN s.delay > 0 THEN 1 ELSE 0 END) as total_delayed FROM Forwarders f JOIN Shipments s ON f.id = s.forwarder_id WHERE shipped_date >= DATEADD(month, -1, GETDATE()) GROUP BY f.id, f.name; |
What is the total calories burned by users living in New York on Tuesdays? | CREATE TABLE users (id INT,state VARCHAR(20)); CREATE TABLE workout_data (id INT,user_id INT,date DATE,calories INT); | SELECT SUM(calories) FROM workout_data w JOIN users u ON w.user_id = u.id WHERE u.state = 'New York' AND DAYOFWEEK(w.date) = 3; |
Identify the top 3 countries with the highest concert ticket sales in Q2 of 2022, ordered by sales amount. | CREATE TABLE ticket_sales (ticket_id INT,price DECIMAL(10,2),country VARCHAR(50),concert_date DATE); | SELECT country, SUM(price) as total_sales FROM ticket_sales WHERE EXTRACT(MONTH FROM concert_date) BETWEEN 4 AND 6 GROUP BY country ORDER BY total_sales DESC LIMIT 3; |
Insert new cargo records for 'rare earth minerals' with IDs 300, 301, and 302, arrived at port on Jun 15, 2022, Jun 16, 2022, and Jun 17, 2022 respectively | CREATE SCHEMA if not exists ocean_shipping;CREATE TABLE if not exists ocean_shipping.cargo (id INT,cargo_type VARCHAR(255),arrived_at DATE); | INSERT INTO ocean_shipping.cargo (id, cargo_type, arrived_at) VALUES (300, 'rare earth minerals', '2022-06-15'), (301, 'rare earth minerals', '2022-06-16'), (302, 'rare earth minerals', '2022-06-17'); |
What is the percentage of hotels in 'Africa' that have adopted AI? | CREATE TABLE hotel_ai (hotel TEXT,ai BOOLEAN); INSERT INTO hotel_ai (hotel,ai) VALUES ('Hotel Marrakech',true),('Hotel Cairo',false),('Hotel Capetown',true),('Hotel Alexandria',false),('Hotel Tunis',true); CREATE TABLE hotels_africa (hotel TEXT,region TEXT); INSERT INTO hotels_africa (hotel,region) VALUES ('Hotel Marrakech','Africa'),('Hotel Cairo','Africa'),('Hotel Capetown','Africa'),('Hotel Alexandria','Africa'),('Hotel Tunis','Africa'); | SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM hotels_africa)) AS percentage FROM hotel_ai WHERE ai = true AND region = 'Africa'; |
List the number of IoT sensors in the 'PrecisionFarming' schema that have a 'moisture' or 'temperature' measurement. | CREATE SCHEMA PrecisionFarming; CREATE TABLE IoT_Sensors (sensor_id INT,sensor_name VARCHAR(50),measurement VARCHAR(50)); INSERT INTO PrecisionFarming.IoT_Sensors (sensor_id,sensor_name,measurement) VALUES (1,'Sensor1','temperature'),(2,'Sensor2','humidity'),(4,'Sensor4','moisture'),(5,'Sensor5','moisture'),(6,'Sensor6','temperature'); | SELECT COUNT(*) FROM PrecisionFarming.IoT_Sensors WHERE measurement = 'moisture' OR measurement = 'temperature'; |
Which claims were processed by the claims adjuster 'Maria Silva'? | CREATE TABLE claim (claim_id INT,processed_by VARCHAR(50)); INSERT INTO claim VALUES (1,'Laura Smith'); INSERT INTO claim VALUES (2,'Maria Silva'); | SELECT claim_id FROM claim WHERE processed_by = 'Maria Silva'; |
Insert new ad interactions for user with ID 1111 | CREATE TABLE ad_interactions (id INT,user_id INT,timestamp TIMESTAMP); | INSERT INTO ad_interactions (user_id) VALUES (1111), (1111), (1111); |
What is the release year of the most recent album for each artist? | CREATE TABLE Album (AlbumID INT,AlbumName VARCHAR(50),ReleaseYear INT,ArtistID INT); CREATE TABLE Artist (ArtistID INT,ArtistName VARCHAR(50)); INSERT INTO Album (AlbumID,AlbumName,ReleaseYear,ArtistID) VALUES (1,'Fearless',2008,1),(2,'Red',2012,1),(3,'Map of the Soul: Persona',2019,2),(4,'BE',2020,2),(5,'19',2019,1); INSERT INTO Artist (ArtistID,ArtistName) VALUES (1,'Taylor Swift'),(2,'BTS'),(3,'Adele'); | SELECT ArtistName, ReleaseYear, ROW_NUMBER() OVER (PARTITION BY ArtistID ORDER BY ReleaseYear DESC) AS Rank FROM Album JOIN Artist ON Album.ArtistID = Artist.ArtistID; |
How many tons of REEs were produced by Myanmar between 2018 and 2020? | CREATE TABLE production (country VARCHAR(255),amount INT,year INT); INSERT INTO production (country,amount,year) VALUES ('Myanmar',5000,2018); INSERT INTO production (country,amount,year) VALUES ('Myanmar',5500,2019); INSERT INTO production (country,amount,year) VALUES ('Myanmar',6000,2020); | SELECT SUM(amount) as total_production FROM production WHERE country = 'Myanmar' AND year BETWEEN 2018 AND 2020; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.