instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
What is the adoption rate of electric vehicles in major cities? | CREATE TABLE ElectricVehicleAdoption (City VARCHAR(50),Make VARCHAR(50),Model VARCHAR(50),Year INT,Adoption DECIMAL(5,2)); INSERT INTO ElectricVehicleAdoption (City,Make,Model,Year,Adoption) VALUES ('Los Angeles','Tesla','Model 3',2020,25.3),('New York','Chevrolet','Bolt',2020,12.6),('Beijing','BYD','e5',2020,18.8),('Berlin','Audi','e-Tron',2020,10.5),('Tokyo','Nissan','Leaf',2020,15.2); | SELECT City, AVG(Adoption) as Avg_Adoption_Rate FROM ElectricVehicleAdoption GROUP BY City; |
Delete vessels from the 'Vessels' table with a cargo weight less than 3000 tons. | CREATE TABLE Vessels (ID INT PRIMARY KEY,Name TEXT,Category TEXT,CargoWeight FLOAT); INSERT INTO Vessels (ID,Name,Category,CargoWeight) VALUES (1,'Cargo Ship 1','Cargo Ship',5500),(2,'Fishing Vessel 1','Fishing Vessel',300),(3,'Cargo Ship 2','Cargo Ship',7000); | DELETE FROM Vessels WHERE CargoWeight < 3000; |
What is the total waste generation by region for the year 2020, including recyclables and non-recyclables? | CREATE TABLE WasteGeneration (region VARCHAR(255),waste_type VARCHAR(255),year INT,amount INT); INSERT INTO WasteGeneration (region,waste_type,year,amount) VALUES ('North','Recyclables',2020,15000),('North','Non-Recyclables',2020,20000),('South','Recyclables',2020,10000),('South','Non-Recyclables',2020,25000),('East','Recyclables',2020,20000),('East','Non-Recyclables',2020,18000),('West','Recyclables',2020,12000),('West','Non-Recyclables',2020,22000); | SELECT SUM(amount) as TotalWaste, region FROM WasteGeneration WHERE year = 2020 GROUP BY region; |
What is the total water usage for all customers in the top 5 most populous counties in California? | CREATE TABLE customers (customer_id INT,county VARCHAR(50),water_usage FLOAT); INSERT INTO customers (customer_id,county,water_usage) VALUES (1,'Los_Angeles',5000),(2,'San_Diego',4000),(3,'Orange',6000),(4,'Riverside',7000),(5,'San_Bernardino',8000),(6,'Ventura',9000),(7,'Santa_Barbara',10000),(8,'San_Luis_Obispo',11000),(9,'Monterey',12000),(10,'Alameda',13000); CREATE TABLE counties (county VARCHAR(50),PRIMARY KEY (county)); INSERT INTO counties (county) VALUES ('Los_Angeles'),('San_Diego'),('Orange'),('Riverside'),('San_Bernardino'),('Ventura'),('Santa_Barbara'),('San_Luis_Obispo'),('Monterey'),('Alameda'); | SELECT SUM(customers.water_usage) FROM customers JOIN (SELECT county FROM counties GROUP BY county ORDER BY COUNT(*) DESC LIMIT 5) AS top_counties ON customers.county = top_counties.county; |
Identify the average age of all animals in the 'critically endangered' status | CREATE TABLE animals (id INT,name VARCHAR(50),status VARCHAR(20),age INT); INSERT INTO animals (id,name,status,age) VALUES (1,'Tiger','Endangered',10); INSERT INTO animals (id,name,status,age) VALUES (2,'Elephant','Vulnerable',30); INSERT INTO animals (id,name,status,age) VALUES (3,'Rhino','Critically Endangered',5); | SELECT AVG(age) FROM animals WHERE status = 'Critically Endangered'; |
What is the average size of habitats in the 'habitat_preservation' table? | CREATE TABLE habitat_preservation (id INT,habitat_name VARCHAR(50),acres FLOAT); INSERT INTO habitat_preservation (id,habitat_name,acres) VALUES (1,'Forest',500.5),(2,'Wetlands',300.2),(3,'Grasslands',700.1); | SELECT AVG(acres) FROM habitat_preservation; |
What is the maximum age of all koalas in the 'australia' habitat? | CREATE TABLE habitats (name VARCHAR(255),animal_type VARCHAR(255),max_age DECIMAL(5,2)); INSERT INTO habitats (name,animal_type,max_age) VALUES ('australia','koala',15.5); | SELECT max_age FROM habitats WHERE name = 'australia' AND animal_type = 'koala'; |
What is the average price of cannabis concentrate per gram in Illinois in Q2 2022? | CREATE TABLE concentrate_prices (price DECIMAL(5,2),gram INT,state VARCHAR(20),quarter VARCHAR(10)); INSERT INTO concentrate_prices (price,gram,state,quarter) VALUES (30,2,'Illinois','Q2'),(32,2,'Illinois','Q2'),(28,2,'Illinois','Q2'); | SELECT AVG(price / gram) as avg_price_per_gram FROM concentrate_prices WHERE state = 'Illinois' AND quarter = 'Q2'; |
How many safety incidents were reported by the chemical plant in the North American region in the last 90 days? | CREATE TABLE safety_incident_records (id INT,incident_date DATE,plant_name VARCHAR(255),region VARCHAR(255),incident_description VARCHAR(255)); INSERT INTO safety_incident_records (id,incident_date,plant_name,region,incident_description) VALUES (1,'2022-04-10','Plant Z','North America','Fire'),(2,'2022-05-25','Plant Z','North America','Explosion'); | SELECT COUNT(*) FROM safety_incident_records WHERE plant_name = 'Plant Z' AND region = 'North America' AND incident_date >= '2022-02-01' AND incident_date < '2022-05-01'; |
What is the R&D expenditure for each quarter in 2021? | CREATE TABLE rd_expenditure (quarter INT,year INT,amount FLOAT); INSERT INTO rd_expenditure (quarter,year,amount) VALUES (1,2021,150000),(2,2021,160000),(3,2021,180000),(4,2021,190000); | SELECT CONCAT('Q', quarter), year, amount FROM rd_expenditure WHERE year = 2021; |
How many startups have received funding in the transportation sector, and what percentage of all startups is this? | CREATE TABLE startup (id INT,name TEXT,industry TEXT); INSERT INTO startup VALUES (1,'StartupA','Transportation'); INSERT INTO startup VALUES (2,'StartupB','Tech'); | SELECT COUNT(*) as transportation_funded, (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM startup)) as funded_percentage FROM startup WHERE industry = 'Transportation' AND id IN (SELECT startup_id FROM investment_round); |
What is the count of organic farms in the USA? | CREATE TABLE farms (country VARCHAR(255),organic BOOLEAN); INSERT INTO farms (country,organic) VALUES ('USA',TRUE),('USA',FALSE),('USA',TRUE),('USA',TRUE),('Canada',FALSE); | SELECT COUNT(*) FROM farms WHERE country = 'USA' AND organic = TRUE; |
Find the earliest accommodation date and the accommodation type for students with learning disabilities. | CREATE TABLE accommodation (student_id INT,accommodation_type TEXT,accommodation_date DATE); INSERT INTO accommodation (student_id,accommodation_type,accommodation_date) VALUES (1,'Tutoring','2022-01-01'),(2,'Quiet Space','2022-02-01'),(3,'Extended Testing Time','2022-03-01'),(4,'Tutoring','2022-04-01'); | SELECT accommodation_type, MIN(accommodation_date) as min_date FROM accommodation WHERE student_id IN (SELECT student_id FROM student WHERE disability = 'Learning Disability') GROUP BY accommodation_type; |
How many students have multiple accommodations in NY and CA? | CREATE TABLE Accommodations (id INT,student_id INT,accommodation_type VARCHAR(50),cost FLOAT); | SELECT state, COUNT(DISTINCT student_id) as multiple_accommodations_count FROM Accommodations a JOIN Students s ON a.student_id = s.id WHERE s.state IN ('NY', 'CA') GROUP BY state; |
What is the minimum age of students with visual impairments who have received accommodations in the last 6 months? | CREATE TABLE Accommodations (id INT,student VARCHAR(255),date DATE); CREATE TABLE Students (id INT,name VARCHAR(255),age INT,disability VARCHAR(255)); | SELECT MIN(age) FROM Students INNER JOIN Accommodations ON Students.id = Accommodations.student WHERE disability = 'visual impairment' AND date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH); |
What are the dapps using the Rust smart contract? | CREATE TABLE if not exists blockchain_domain.smart_contracts (contract_id INT PRIMARY KEY,name VARCHAR(255),gas_cost FLOAT); CREATE TABLE if not exists blockchain_domain.decentralized_applications (dapp_id INT PRIMARY KEY,name VARCHAR(255),smart_contract_id INT,FOREIGN KEY (smart_contract_id) REFERENCES blockchain_domain.smart_contracts(contract_id)); | SELECT dapp_id, name FROM blockchain_domain.decentralized_applications WHERE smart_contract_id = (SELECT contract_id FROM blockchain_domain.smart_contracts WHERE name = 'Rust'); |
What is the regulatory framework status in 'singapore'? | CREATE TABLE regulation (id INT,country VARCHAR(20),status VARCHAR(20)); INSERT INTO regulation (id,country,status) VALUES (1,'singapore','approved'); | SELECT status FROM regulation WHERE country = 'singapore'; |
List the top 5 regions with the highest total sustainable forest management area, in square kilometers, for the year 2019? | CREATE TABLE sustainable_forest_management (id INT,region VARCHAR(255),year INT,area FLOAT); INSERT INTO sustainable_forest_management (id,region,year,area) VALUES (1,'North America',2019,123456.12),(2,'South America',2019,234567.12),(3,'Europe',2019,345678.12); | SELECT region, SUM(area) as total_area FROM sustainable_forest_management WHERE year = 2019 GROUP BY region ORDER BY total_area DESC LIMIT 5; |
What is the total area of forests in each region? | CREATE TABLE forests (forest_id INT,region TEXT,area REAL); INSERT INTO forests (forest_id,region,area) VALUES (1,'North',5000),(2,'South',7000),(3,'Mexico',3000); | SELECT region, SUM(area) as total_area FROM forests GROUP BY region; |
What is the average price of eco-friendly nail polish sold in France? | CREATE TABLE NailPolishSales (productID INT,productName VARCHAR(50),category VARCHAR(50),country VARCHAR(50),isEcoFriendly BOOLEAN,price DECIMAL(5,2)); INSERT INTO NailPolishSales (productID,productName,category,country,isEcoFriendly,price) VALUES (1,'Nail Polish','Nail Care','France',TRUE,12.99); | SELECT AVG(price) FROM NailPolishSales WHERE category = 'Nail Care' AND country = 'France' AND isEcoFriendly = TRUE; |
What is the total number of artworks in the 'ArtCollection' table, categorized by the style of the artwork? | CREATE TABLE ArtCollection (ArtworkID INT,ArtworkStyle VARCHAR(50)); INSERT INTO ArtCollection (ArtworkID,ArtworkStyle) VALUES (1,'Abstract'),(2,'Realism'),(3,'Impressionism'),(4,'Cubism'),(5,'Surrealism'),(6,'Expressionism'); | SELECT ArtworkStyle, COUNT(*) AS ArtworksByStyle FROM ArtCollection GROUP BY ArtworkStyle; |
What is the total number of veteran employment applications and hires in Florida in the past quarter? | CREATE TABLE veteran_employment (application_id INT,application_date DATE,application_status VARCHAR(255),state VARCHAR(255)); INSERT INTO veteran_employment (application_id,application_date,application_status,state) VALUES (1,'2021-01-01','Applied','Florida'); INSERT INTO veteran_employment (application_id,application_date,application_status,state) VALUES (2,'2021-03-01','Hired','Florida'); | SELECT SUM(CASE WHEN application_status = 'Applied' THEN 1 ELSE 0 END) as total_applications, SUM(CASE WHEN application_status = 'Hired' THEN 1 ELSE 0 END) as total_hires FROM veteran_employment WHERE state = 'Florida' AND application_date >= DATEADD(quarter, -1, GETDATE()); |
Update the 'peacekeeping_operations' table and change the location of the 'MONUSCO' to 'South Sudan' | CREATE TABLE peacekeeping_operations (id INT PRIMARY KEY,operation_name VARCHAR(50),location VARCHAR(50)); INSERT INTO peacekeeping_operations (id,operation_name,location) VALUES (1,'MONUSCO','Democratic Republic of the Congo'); INSERT INTO peacekeeping_operations (id,operation_name,location) VALUES (2,'MINUSCA','Central African Republic'); | UPDATE peacekeeping_operations SET location = 'South Sudan' WHERE operation_name = 'MONUSCO'; |
What is the maximum number of personnel deployed in defense diplomacy events by each department, and the average number of defense diplomacy events per department, for departments that have deployed more than 500 personnel, ordered by the average number of events in descending order? | CREATE TABLE Departments(DepartmentID INT,DepartmentName TEXT); CREATE TABLE DefenseDiplomacyEvents(EventID INT,EventName TEXT,DepartmentID INT,Personnel INT); | SELECT DepartmentName, MAX(Personnel) as MaxPersonnel, AVG(COUNT(EventID)) as AvgEventsPerDept FROM DefenseDiplomacyEvents JOIN Departments ON DefenseDiplomacyEvents.DepartmentID = Departments.DepartmentID GROUP BY DepartmentName HAVING MaxPersonnel > 500 ORDER BY AvgEventsPerDept DESC; |
What is the average assets value for customers in each region? | CREATE TABLE customers (customer_id INT,name TEXT,region TEXT,assets_value DECIMAL); INSERT INTO customers (customer_id,name,region,assets_value) VALUES (1,'John Doe','New York',50000.00),(2,'Jane Smith','California',75000.00),(3,'Bob Johnson','New York',60000.00); | SELECT region, AVG(assets_value) FROM customers GROUP BY region; |
What is the total value of assets for clients who have made at least one transaction in the last month? | CREATE TABLE clients (client_id INT,currency VARCHAR(10)); INSERT INTO clients (client_id,currency) VALUES (1,'USD'),(2,'EUR'); CREATE TABLE assets (asset_id INT,client_id INT,value INT,transaction_date DATE); INSERT INTO assets (asset_id,client_id,value,transaction_date) VALUES (1,1,5000,'2022-01-01'),(2,1,7000,'2022-01-05'),(3,2,30000,'2022-02-01'); | SELECT SUM(value) FROM assets WHERE client_id IN (SELECT client_id FROM assets WHERE transaction_date >= DATEADD(month, -1, GETDATE())); |
What is the total capacity of refrigerated cargo ships that docked at the port of Oakland in 2021? | CREATE TABLE ships (ship_id INT,ship_name VARCHAR(255),ship_type VARCHAR(255),capacity INT);CREATE TABLE docking (docking_id INT,ship_id INT,port VARCHAR(255),year INT);INSERT INTO ships (ship_id,ship_name,ship_type,capacity) VALUES (1,'MSC Tigris','refrigerated cargo',12000);INSERT INTO docking (docking_id,ship_id,port,year) VALUES (1,1,'Oakland',2021); | SELECT SUM(capacity) FROM ships S JOIN docking D ON S.ship_id = D.ship_id WHERE S.ship_type = 'refrigerated cargo' AND D.port = 'Oakland' AND D.year = 2021; |
Do any manufacturers in the USA have a recycling program and a waste reduction percentage above 25%? | CREATE TABLE manufacturers (manufacturer_id INT,name VARCHAR(255),location VARCHAR(255),industry_4_0_investment FLOAT,recycling_program BOOLEAN,waste_reduction_percentage FLOAT); INSERT INTO manufacturers (manufacturer_id,name,location,industry_4_0_investment,recycling_program,waste_reduction_percentage) VALUES (1,'Smart Machines','Germany',350000,FALSE,20.5),(2,'Eco Engines','Sweden',420000,TRUE,35.0),(3,'Precision Robotics','Japan',500000,TRUE,15.7),(4,'Green Innovations','USA',375000,TRUE,28.2),(5,'FutureTech','USA',410000,FALSE,12.0); | SELECT m.name FROM manufacturers m WHERE m.location = 'USA' AND m.recycling_program = TRUE AND m.waste_reduction_percentage > 25; |
What is the average number of hospital beds per rural hospital? | CREATE TABLE hospitals (id INT,num_beds INT,rural BOOLEAN); INSERT INTO hospitals (id,num_beds,rural) VALUES (1,50,true),(2,100,false); | SELECT AVG(num_beds) FROM hospitals WHERE rural = true; |
What is the maximum number of patients served by a rural health center in Europe? | CREATE TABLE centers (id INT,name VARCHAR(50),location VARCHAR(50),patients_served INT); | SELECT MAX(patients_served) FROM centers WHERE location LIKE '%Europe%' AND location LIKE '%rural%'; |
How many investments were made in the 'Africa' region in Q4 2021? | CREATE TABLE investments (id INT,region VARCHAR(20),date DATE); INSERT INTO investments (id,region,date) VALUES (1,'Asia-Pacific','2021-01-05'),(2,'Europe','2021-02-10'),(3,'Asia-Pacific','2021-03-25'),(4,'Africa','2021-10-15'),(5,'Europe','2021-11-30'),(6,'Africa','2021-12-12'); | SELECT COUNT(*) FROM investments WHERE region = 'Africa' AND date BETWEEN '2021-10-01' AND '2021-12-31'; |
How many social impact investments were made by investors from 'Canada' in 2020? | CREATE TABLE investments (id INT,investor_country VARCHAR(20),investment_year INT,investment_amount FLOAT); INSERT INTO investments (id,investor_country,investment_year,investment_amount) VALUES (1,'Canada',2020,150000),(2,'USA',2019,120000),(3,'Canada',2018,175000); | SELECT COUNT(*) FROM investments WHERE investor_country = 'Canada' AND investment_year = 2020; |
What is the total number of military vehicles produced by company 'XYZ'? | CREATE TABLE military_vehicles (company TEXT,quantity INT,production_date DATE); INSERT INTO military_vehicles (company,quantity,production_date) VALUES ('ABC',100,'2023-01-01'); INSERT INTO military_vehicles (company,quantity,production_date) VALUES ('XYZ',200,'2023-02-01'); | SELECT SUM(quantity) FROM military_vehicles WHERE company = 'XYZ'; |
Which countries have not reported any national security incidents in the last 3 years? | CREATE TABLE if not exists national_security_incidents (country VARCHAR(50),year INT,incident_count INT); | SELECT country FROM national_security_incidents WHERE year >= 2020 AND incident_count = 0 GROUP BY country; |
Which onshore wells in the Permian Basin have the highest production rate? | CREATE TABLE wells (well_id INT,well_name VARCHAR(255),well_type VARCHAR(255),location VARCHAR(255)); INSERT INTO wells VALUES (1,'Well A','Offshore','Gulf of Mexico'); INSERT INTO wells VALUES (2,'Well B','Onshore','Permian Basin'); | SELECT well_id, well_name, production_rate FROM (SELECT well_id, well_name, production_rate, row_number() OVER (PARTITION BY well_type ORDER BY production_rate DESC) as rn FROM well_production WHERE well_type = 'Onshore' AND location = 'Permian Basin') WHERE rn = 1; |
Calculate the average goals conceded per game for the top 5 teams in the English Premier League | CREATE TABLE teams (id INT PRIMARY KEY,name TEXT,league TEXT,goals_conceded INT,goals_scored INT,games_played INT); INSERT INTO teams (id,name,league,goals_conceded,goals_scored,games_played) VALUES (1,'Manchester City','English Premier League',14,51,23),(2,'Liverpool','English Premier League',14,50,22),(3,'Chelsea','English Premier League',17,45,23),(4,'Arsenal','English Premier League',21,38,23),(5,'Manchester United','English Premier League',21,43,23),(6,'Tottenham Hotspur','English Premier League',22,41,23); | SELECT AVG(goals_conceded/games_played) FROM (SELECT * FROM teams ORDER BY goals_conceded ASC LIMIT 5) AS top_five_teams; |
What is the maximum number of wins by a team in a single English Premier League season, and which team was it? | CREATE TABLE seasons (season_id INT,team TEXT,wins INT); | SELECT team, MAX(wins) FROM seasons; |
Calculate the number of schools and hospitals in each community by joining the schools, hospitals, and communities tables. | CREATE TABLE communities (id INT,name VARCHAR(255)); CREATE TABLE schools (id INT,community_id INT,name VARCHAR(255)); CREATE TABLE hospitals (id INT,community_id INT,name VARCHAR(255)); | SELECT c.name, COUNT(s.id) as school_count, COUNT(h.id) as hospital_count FROM communities c INNER JOIN schools s ON c.id = s.community_id INNER JOIN hospitals h ON c.id = h.community_id GROUP BY c.id; |
How many vehicles are due for maintenance in the 'vehicles' table, grouped by vehicle type? | CREATE TABLE vehicles (vehicle_id INT,vehicle_type VARCHAR(50),last_maintenance DATE); INSERT INTO vehicles (vehicle_id,vehicle_type,last_maintenance) VALUES (1,'Bus','2022-01-01'),(2,'Tram','2022-02-15'),(3,'Train','2022-03-05'),(4,'Bus','2022-04-10'); | SELECT vehicle_type, COUNT(*) as num_vehicles FROM vehicles WHERE last_maintenance < DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH) GROUP BY vehicle_type; |
List the vehicle models for which there is a record of maintenance in the last month. | CREATE TABLE Vehicles (id INT,model VARCHAR(255),last_maintenance DATE); | SELECT model FROM Vehicles WHERE last_maintenance >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH); |
Calculate the percentage of sustainable materials in the inventory for each size. | CREATE TABLE Inventory (id INT,size VARCHAR(20),material VARCHAR(20),is_sustainable BOOLEAN); INSERT INTO Inventory (id,size,material,is_sustainable) VALUES (1,'S','Cotton',TRUE),(2,'M','Polyester',FALSE),(3,'L','Wool',TRUE),(4,'XL','Silk',FALSE),(5,'S','Denim',TRUE),(6,'M','Tencel',TRUE),(7,'L','Hemp',TRUE),(8,'XL','Modal',FALSE),(9,'S','Linen',TRUE); | SELECT size, 100.0 * SUM(is_sustainable) / COUNT(*) AS percentage FROM Inventory GROUP BY size; |
What is the average price difference between regular and sale items for each brand? | CREATE TABLE Brands (brand_id INT,brand_name TEXT); CREATE TABLE Items (item_id INT,brand_id INT,price DECIMAL,is_on_sale BOOLEAN); | SELECT b.brand_name, AVG(CASE WHEN i.is_on_sale THEN i.price ELSE NULL END) - AVG(CASE WHEN NOT i.is_on_sale THEN i.price ELSE NULL END) as price_difference FROM Brands b JOIN Items i ON b.brand_id = i.brand_id GROUP BY b.brand_name; |
Update the financial wellbeing score of clients in Singapore to 1 point higher than their current score, if their score is currently below 7. | CREATE TABLE financial_wellbeing_sg (client_id INT,financial_wellbeing_score INT,country VARCHAR(50)); INSERT INTO financial_wellbeing_sg (client_id,financial_wellbeing_score,country) VALUES (1,7,'Singapore'),(2,3,'Singapore'),(3,6,'Singapore'); | WITH updated_scores AS (UPDATE financial_wellbeing_sg SET financial_wellbeing_score = financial_wellbeing_score + 1 WHERE country = 'Singapore' AND financial_wellbeing_score < 7) SELECT * FROM updated_scores; |
List the programs and their total expenses in 2022, sorted by expenses in descending order. | CREATE TABLE programs (id INT,program_name TEXT,start_date DATE,end_date DATE,total_expenses FLOAT); INSERT INTO programs (id,program_name,start_date,end_date,total_expenses) VALUES (1,'Education','2021-01-01','2022-12-31',25000.00),(2,'Health','2021-07-01','2023-06-30',30000.00); | SELECT program_name, total_expenses FROM programs WHERE YEAR(start_date) = 2022 OR YEAR(end_date) = 2022 OR (YEAR(start_date) < 2022 AND YEAR(end_date) > 2022) ORDER BY total_expenses DESC; |
List all food recalls in the last 30 days, ordered by date? | CREATE TABLE recall (id INT,product VARCHAR(50),date DATE); INSERT INTO recall (id,product,date) VALUES (1,'Chicken nuggets','2022-05-01'),(2,'Almond milk','2022-03-15'),(3,'Frozen berries','2022-01-20'),(4,'Tuna','2022-06-10'); | SELECT * FROM recall WHERE date >= DATEADD(day, -30, GETDATE()) ORDER BY date; |
Who are the top 3 countries with the most evidence-based policy making programs in the last 3 years? | CREATE TABLE evidence_based_policy_making (program_id INT,country VARCHAR(50),launch_year INT); INSERT INTO evidence_based_policy_making (program_id,country,launch_year) VALUES (1,'United States',2019),(2,'Canada',2018),(3,'United Kingdom',2020),(4,'United States',2018),(5,'Canada',2019),(6,'United States',2020),(7,'Germany',2019),(8,'France',2018),(9,'United Kingdom',2019),(10,'Germany',2020); | SELECT country, COUNT(*) as num_programs FROM evidence_based_policy_making WHERE launch_year >= 2018 GROUP BY country ORDER BY num_programs DESC LIMIT 3; |
What is the average age of community health workers who identify as non-binary, by state? | CREATE TABLE CommunityHealthWorkers (WorkerID INT,Age INT,Gender VARCHAR(10),State VARCHAR(20)); INSERT INTO CommunityHealthWorkers (WorkerID,Age,Gender,State) VALUES (1,34,'Female','California'),(2,42,'Male','Texas'),(3,50,'Female','California'),(4,48,'Non-binary','New York'); | SELECT State, AVG(Age) as AvgAge FROM CommunityHealthWorkers WHERE Gender = 'Non-binary' GROUP BY State; |
What is the average visitor count of museums in the UK? | CREATE TABLE museum_visitors(id INT,museum_name TEXT,country TEXT,visitor_count INT); INSERT INTO museum_visitors (id,museum_name,country,visitor_count) VALUES (1,'British Museum','UK',2000),(2,'Museum of Modern Art','USA',1500); | SELECT AVG(visitor_count) FROM museum_visitors WHERE country = 'UK'; |
What is the name of the most rated museum in the USA? | CREATE TABLE museums (museum_id INT,museum_name TEXT,country TEXT,rating FLOAT); INSERT INTO museums (museum_id,museum_name,country,rating) VALUES (1,'Museum A','USA',4.6),(2,'Museum B','USA',4.5),(3,'Museum C','USA',4.7); | SELECT museum_name FROM museums WHERE country = 'USA' GROUP BY museum_name ORDER BY AVG(rating) DESC LIMIT 1; |
What is the total number of eco-friendly hotels in Rome? | CREATE TABLE eco_hotels (hotel_id INT,city TEXT,sustainable_certification BOOLEAN); INSERT INTO eco_hotels (hotel_id,city,sustainable_certification) VALUES (1,'Rome',true),(2,'Rome',false); | SELECT COUNT(*) FROM eco_hotels WHERE city = 'Rome' AND sustainable_certification = true; |
What was the daily revenue of virtual tours in India on Independence Day? | CREATE TABLE daily_revenue(date DATE,site_id INT,revenue INT); INSERT INTO daily_revenue (date,site_id,revenue) VALUES ('2021-08-15',1,500),('2021-08-15',2,700),('2021-08-16',1,600); CREATE TABLE virtual_tours(site_id INT,site_name TEXT,country TEXT); INSERT INTO virtual_tours (site_id,site_name,country) VALUES (1,'Taj Mahal','India'),(2,'Red Fort','India'); | SELECT SUM(revenue) FROM daily_revenue WHERE date = '2021-08-15' AND site_id IN (SELECT site_id FROM virtual_tours WHERE country = 'India'); |
Update the price of all bookings in the "luxury" hotel category that were made before 2020 to a 10% increase | CREATE TABLE hotels (hotel_id INT,hotel_name VARCHAR(50),city VARCHAR(50),category VARCHAR(50)); CREATE TABLE bookings (booking_id INT,hotel_id INT,guest_name VARCHAR(50),checkin_date DATE,checkout_date DATE,price DECIMAL(10,2)); | UPDATE bookings b SET price = b.price * 1.10 WHERE EXISTS (SELECT 1 FROM hotels h WHERE h.hotel_id = b.hotel_id AND h.category = 'luxury') AND b.checkin_date < '2020-01-01'; |
Which artists have their artwork displayed in the 'Impressionist Gallery'? | CREATE TABLE Artworks (artwork_id INT,artist_name VARCHAR(50),gallery_name VARCHAR(50)); INSERT INTO Artworks (artwork_id,artist_name,gallery_name) VALUES (1,'Claude Monet','Impressionist Gallery'),(2,'Pierre-Auguste Renoir','Impressionist Gallery'); | SELECT DISTINCT artist_name FROM Artworks WHERE gallery_name = 'Impressionist Gallery'; |
What is the average eco-friendliness score of accommodations in Oceania by year? | CREATE TABLE Accommodations (Accommodation_ID INT,Accommodation_Name VARCHAR(50),City VARCHAR(30),Country VARCHAR(50),Eco_Friendliness_Score INT,Visit_Year INT); INSERT INTO Accommodations (Accommodation_ID,Accommodation_Name,City,Country,Eco_Friendliness_Score,Visit_Year) VALUES (1,'EcoLodge','Sydney','Australia',85,2019),(2,'GreenHotel','Melbourne','Australia',90,2019),(3,'SustainableResort','Auckland','New Zealand',80,2019),(4,'EcoVilla','Wellington','New Zealand',88,2019); CREATE TABLE Countries (Country VARCHAR(50),Continent VARCHAR(30)); INSERT INTO Countries (Country,Continent) VALUES ('Australia','Oceania'),('New Zealand','Oceania'); | SELECT C.Continent, V.Visit_Year, AVG(A.Eco_Friendliness_Score) AS Avg_Eco_Score FROM Accommodations A JOIN Countries C ON A.Country = C.Country WHERE C.Continent = 'Oceania' GROUP BY C.Continent, V.Visit_Year ORDER BY V.Visit_Year; |
What is the change in international tourist arrivals in Oceania between 2018 and 2020? | CREATE TABLE ArrivalsByRegion (Year INT,Region VARCHAR(255),Arrivals INT); INSERT INTO ArrivalsByRegion (Year,Region,Arrivals) VALUES (2018,'Oceania',10000000),(2019,'Oceania',10500000),(2020,'Oceania',5000000); | SELECT Region, Arrivals, (Arrivals - LAG(Arrivals, 1) OVER (PARTITION BY Region ORDER BY Year)) AS ArrivalChange FROM ArrivalsByRegion WHERE Region = 'Oceania' AND Year BETWEEN 2018 AND 2020; |
Which dish has the most orders in Spain? | CREATE TABLE orders (id INT,dish_id INT,quantity INT);INSERT INTO orders (id,dish_id,quantity) VALUES (1,1,2),(2,2,3),(3,3,5); | SELECT d.name, MAX(o.quantity) FROM dishes d JOIN orders o ON d.id = o.dish_id GROUP BY d.name HAVING country = 'Spain'; |
List all mobile towers that have not experienced any network outages in the past six months. | CREATE TABLE mobile_towers (id INT,latitude DECIMAL(9,6),longitude DECIMAL(9,6),status VARCHAR(255));CREATE VIEW network_outages AS SELECT tower_id,date FROM network_issues WHERE issue_type = 'outage'; | SELECT mt.id, mt.latitude, mt.longitude FROM mobile_towers mt LEFT JOIN network_outages no ON mt.id = no.tower_id WHERE no.tower_id IS NULL AND no.date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH); |
Show the total revenue from concert ticket sales for the artist 'BTS' | CREATE TABLE concerts (id INT,artist_name VARCHAR(255),tickets_sold INT,ticket_price DECIMAL(5,2)); INSERT INTO concerts (id,artist_name,tickets_sold,ticket_price) VALUES (1,'Taylor Swift',12000,75),(2,'BTS',15000,100); | SELECT artist_name, SUM(tickets_sold * ticket_price) as total_revenue FROM concerts WHERE artist_name = 'BTS' GROUP BY artist_name; |
What is the total revenue for each artist in the Music_Streaming table? | CREATE TABLE Music_Streaming (song_id INT,artist VARCHAR(50),price DECIMAL(10,2)); INSERT INTO Music_Streaming (song_id,artist,price) VALUES (1,'Taylor Swift',0.99),(2,'The Rolling Stones',1.29),(3,'Miles Davis',1.49),(4,'Taylor Swift',0.99),(5,'Jay Z',1.79); | SELECT artist, SUM(price) as total_revenue FROM Music_Streaming GROUP BY artist; |
Which news articles were published before the earliest published date in the news_articles table? | CREATE TABLE news_articles (id INT,title VARCHAR(100),author_id INT,published_date DATE); INSERT INTO news_articles (id,title,author_id,published_date) VALUES (1,'Media Ethics in Journalism',3,'2022-03-15'); INSERT INTO news_articles (id,title,author_id,published_date) VALUES (2,'Audience Demographics in News Reporting',1,'2022-03-17'); | SELECT * FROM news_articles WHERE published_date < (SELECT MIN(published_date) FROM news_articles); |
What is the average number of victories for players from Japan in 'Battle Royale' games? | CREATE TABLE player_profiles (player_id INT,player_country VARCHAR(50)); INSERT INTO player_profiles (player_id,player_country) VALUES (1,'USA'),(2,'Canada'),(3,'Mexico'),(4,'Brazil'),(5,'Japan'); CREATE TABLE player_games (player_id INT,game_name VARCHAR(100),victories INT); INSERT INTO player_games (player_id,game_name,victories) VALUES (1,'GameA',5),(2,'GameB',7),(3,'GameC',8),(4,'GameD',3),(5,'GameA',6); | SELECT player_country, AVG(victories) FROM player_profiles JOIN player_games ON player_profiles.player_id = player_games.player_id WHERE player_country = 'Japan' AND game_name = 'Battle Royale' GROUP BY player_country; |
Delete the satellite image for farm 501 taken on May 3, 2022 | CREATE TABLE satellite_images (farm_id INT,image_data VARCHAR(500),timestamp DATETIME); | DELETE FROM satellite_images WHERE farm_id = 501 AND timestamp = '2022-05-03 14:30:00'; |
Identify the top 5 mining locations with the highest average Gadolinium production in 2020, using a cross join. | CREATE TABLE mines (id INT,location VARCHAR(50),Gadolinium_prod FLOAT,datetime DATETIME); INSERT INTO mines (id,location,Gadolinium_prod,datetime) VALUES (1,'Mount Weld',120.0,'2020-01-01 10:00:00'),(2,'Bayan Obo',350.0,'2020-02-15 14:30:00'); | SELECT a.location, AVG(a.Gadolinium_prod) FROM mines a CROSS JOIN mines b GROUP BY a.location ORDER BY AVG(a.Gadolinium_prod) DESC LIMIT 5; |
Which ethical labor certifications are associated with which products in the product_labor_certifications table? | CREATE TABLE products (product_id INT,product_name VARCHAR(50)); CREATE TABLE labor_certifications (certification_id INT,certification_name VARCHAR(50)); CREATE TABLE product_labor_certifications (product_id INT,certification_id INT); INSERT INTO products (product_id,product_name) VALUES (1,'Eco Sweatshirt'),(2,'Sustainable Sneakers'); INSERT INTO labor_certifications (certification_id,certification_name) VALUES (1,'Fair Trade'),(2,'Certified B Corporation'); INSERT INTO product_labor_certifications (product_id,certification_id) VALUES (1,1),(1,2),(2,1); | SELECT p.product_name, lc.certification_name FROM products p INNER JOIN product_labor_certifications plc ON p.product_id = plc.product_id INNER JOIN labor_certifications lc ON plc.certification_id = lc.certification_id; |
How many astronauts are there from Russia? | CREATE TABLE Astronauts (ID INT,Name VARCHAR(50),Nationality VARCHAR(50)); INSERT INTO Astronauts VALUES (1,'Mark Watney','USA'),(2,'Melissa Lewis','USA'),(3,'Alex Vogel','Russia'),(4,'Kelly Stuart','USA'); | SELECT COUNT(*) FROM Astronauts WHERE Nationality = 'Russia'; |
What is the distribution of security incidents by day of the week for the last year? | CREATE TABLE security_incidents_by_day (day_of_week VARCHAR(10),incident_count INT,incident_date DATE); INSERT INTO security_incidents_by_day (day_of_week,incident_count,incident_date) VALUES ('Monday',120,'2022-01-01'),('Tuesday',140,'2022-01-02'),('Wednesday',160,'2022-01-03'),('Thursday',130,'2022-01-04'),('Friday',110,'2022-01-05'); | SELECT DATENAME(dw, incident_date) AS day_of_week, COUNT(*) AS incident_count FROM security_incidents WHERE incident_date >= DATEADD(year, -1, GETDATE()) GROUP BY DATENAME(dw, incident_date); |
What is the maximum number of days to resolve a security incident in each region? | CREATE TABLE IncidentResolution (id INT,region VARCHAR(255),resolution_days INT); INSERT INTO IncidentResolution (id,region,resolution_days) VALUES (1,'Americas',15),(2,'Europe',10),(3,'Asia',20); | SELECT IncidentResolution.region AS Region, MAX(IncidentResolution.resolution_days) AS Max_Resolution_Days FROM IncidentResolution GROUP BY IncidentResolution.region; |
Delete records in the garments table where the quantity is less than 10 | CREATE TABLE garments (id INT,garment_name VARCHAR(50),category VARCHAR(50),quantity INT); | DELETE FROM garments WHERE quantity < 10; |
What is the average salary of part-time workers in the 'finance' sector? | CREATE TABLE finance (id INT,employee_name TEXT,hours_worked INT,salary REAL); INSERT INTO finance (id,employee_name,hours_worked,salary) VALUES (1,'Mark Anderson',20,70000.00),(2,'Nancy Thompson',25,75000.00),(3,'Oliver Brown',30,80000.00); | SELECT AVG(salary) FROM finance WHERE hours_worked < 30 AND sector = 'finance'; |
How many cargo vessels are there? | CREATE TABLE Vessels (ID VARCHAR(20),Name VARCHAR(20),Type VARCHAR(20),AverageSpeed FLOAT); INSERT INTO Vessels VALUES ('V018','Vessel R','Cargo',18.2),('V019','Vessel S','Cargo',16.3),('V020','Vessel T','Passenger',28.0); | SELECT COUNT(*) FROM Vessels WHERE Type = 'Cargo'; |
List all vessels in the 'cargo' table that have an average speed greater than 25 knots | CREATE TABLE IF NOT EXISTS cargo (id INT PRIMARY KEY,vessel_name VARCHAR(255),average_speed DECIMAL(5,2)); INSERT INTO cargo (id,vessel_name,average_speed) VALUES (1,'Poseidon',26.3),(2,'Oceanus',28.1),(3,'Neptune',22.9),(4,'Atlantis',30.5),(5,'Aquarius',24.7); | SELECT vessel_name FROM cargo WHERE average_speed > 25; |
List the exhibitions with the highest number of visitors from outside the EU. | CREATE TABLE Exhibition (id INT,name VARCHAR(100),Visitor_id INT); CREATE TABLE Visitor (id INT,name VARCHAR(100),country VARCHAR(50)); INSERT INTO Exhibition (id,name,Visitor_id) VALUES (1,'Ancient Civilizations',1),(2,'Modern Art',2); INSERT INTO Visitor (id,name,country) VALUES (1,'James Bond','UK'),(2,'Maria Garcia','Mexico'); | SELECT Exhibition.name FROM Exhibition JOIN Visitor ON Exhibition.Visitor_id = Visitor.id WHERE Visitor.country NOT IN ('Austria', 'Belgium', 'Bulgaria', 'Croatia', 'Cyprus', 'Czech Republic', 'Denmark', 'Estonia', 'Finland', 'France', 'Germany', 'Greece', 'Hungary', 'Ireland', 'Italy', 'Latvia', 'Lithuania', 'Luxembourg', 'Malta', 'Netherlands', 'Poland', 'Portugal', 'Romania', 'Slovakia', 'Slovenia', 'Spain', 'Sweden') GROUP BY Exhibition.name ORDER BY COUNT(DISTINCT Exhibition.Visitor_id) DESC LIMIT 1; |
What is the change in landfill capacity in the last month for each country? | CREATE TABLE landfill_capacity(country VARCHAR(255),capacity_date DATE,capacity INT); INSERT INTO landfill_capacity VALUES ('CountryA','2022-01-01',1000); | SELECT country, LAG(capacity) OVER (PARTITION BY country ORDER BY capacity_date) as previous_capacity, capacity, capacity - LAG(capacity) OVER (PARTITION BY country ORDER BY capacity_date) as capacity_change FROM landfill_capacity WHERE capacity_date > DATEADD(month, -1, CURRENT_DATE) |
What is the total water usage by region and day of the week? | CREATE TABLE WaterUsage (id INT,region VARCHAR(50),usage_date DATE,usage_amount INT); INSERT INTO WaterUsage (id,region,usage_date,usage_amount) VALUES (1,'Northeast','2022-01-01',5000); INSERT INTO WaterUsage (id,region,usage_date,usage_amount) VALUES (2,'Southeast','2022-01-02',7000); | SELECT region, EXTRACT(DOW FROM usage_date) AS day_of_week, SUM(usage_amount) AS total_usage FROM WaterUsage GROUP BY region, day_of_week; |
Insert a new record of a user who joined on Jan 1, 2022 and last logged in on Jan 5, 2022 into the "Members" table | CREATE TABLE Members (Id INT PRIMARY KEY,FirstName VARCHAR(50),LastName VARCHAR(50),JoinDate DATETIME,LastLogin DATETIME); | INSERT INTO Members (Id, FirstName, LastName, JoinDate, LastLogin) VALUES (10, 'John', 'Doe', '2022-01-01', '2022-01-05'); |
Who are the top 3 users with the highest step count on a specific day? | CREATE TABLE Users (id INT,name VARCHAR(20)); INSERT INTO Users (id,name) VALUES (1,'John'),(2,'Sarah'),(3,'Mike'); CREATE TABLE Steps (user_id INT,step_count INT,date DATE); INSERT INTO Steps (user_id,step_count,date) VALUES (1,10000,'2022-01-01'),(2,8000,'2022-01-01'),(3,12000,'2022-01-01'),(1,9000,'2022-01-02'),(2,11000,'2022-01-02'),(3,13000,'2022-01-02'); | SELECT u.name, s.step_count FROM Users u JOIN Steps s ON u.id = s.user_id WHERE s.date = '2022-01-02' ORDER BY s.step_count DESC LIMIT 3; |
List the top 5 AI safety incidents by the number of user complaints, in the last 3 years, for AI models used in the finance domain, and display the incident type, AI algorithm, and number of complaints. | CREATE TABLE ai_safety_incidents (incident_id INT,incident_type VARCHAR(50),ai_algorithm VARCHAR(50),incident_date DATE,user_complaints INT,domain VARCHAR(50)); | SELECT incident_type, ai_algorithm, SUM(user_complaints) AS total_complaints FROM ai_safety_incidents WHERE domain = 'finance' AND incident_date >= DATE(CURRENT_DATE) - INTERVAL 3 YEAR GROUP BY incident_type, ai_algorithm ORDER BY total_complaints DESC LIMIT 5; |
What is the maximum number of launches for a SpaceX Falcon9 mission? | CREATE TABLE SpaceX_Missions (Id INT,Name VARCHAR(50),NumLaunches INT); INSERT INTO SpaceX_Missions (Id,Name,NumLaunches) VALUES (1,'Falcon1',5),(2,'Falcon9',10),(3,'FalconHeavy',3); | SELECT MAX(NumLaunches) FROM SpaceX_Missions WHERE Name = 'Falcon9'; |
List all the animals in the 'animal_population' table that are part of a vulnerable or endangered species | CREATE TABLE animal_population (species VARCHAR(50),animal_count INT,conservation_status VARCHAR(20)); | SELECT species FROM animal_population WHERE conservation_status IN ('vulnerable', 'endangered'); |
What was the average production cost per gram for each strain grown in Colorado in 2020? | CREATE TABLE Production (id INT,strain TEXT,state TEXT,cost_per_gram FLOAT); INSERT INTO Production (id,strain,state,cost_per_gram) VALUES (1,'Strain X','CO',5.00),(2,'Strain Y','CO',7.00),(3,'Strain Z','CO',3.00); | SELECT strain, AVG(cost_per_gram) FROM Production WHERE state = 'CO' GROUP BY strain; |
List all departments, the number of chemicals they handle, and the number of machines used in their manufacturing processes. | CREATE TABLE Departments (DepartmentID INT,DepartmentName VARCHAR(20)); INSERT INTO Departments (DepartmentID,DepartmentName) VALUES (1,'Manufacturing'),(2,'Engineering'),(3,'Chemical Safety'),(4,'Product Development'); CREATE TABLE Chemicals (ChemicalID INT,ChemicalName VARCHAR(20),DepartmentID INT); INSERT INTO Chemicals (ChemicalID,ChemicalName,DepartmentID) VALUES (1,'Hydrochloric Acid',1),(2,'Nitric Acid',2),(3,'Sodium Hydroxide',3),(4,'New Chemical',4); CREATE TABLE Machinery (MachineID INT,MachineName VARCHAR(20),DepartmentID INT); INSERT INTO Machinery (MachineID,MachineName,DepartmentID) VALUES (1,'Mixer 1',1),(2,'Cutter 2',2),(3,'Dispenser 3',3),(4,'Innovator 4',4); | SELECT D.DepartmentName, COUNT(C.ChemicalID) AS ChemicalCount, COUNT(M.MachineID) AS MachineCount FROM Departments D LEFT JOIN Chemicals C ON D.DepartmentID = C.DepartmentID LEFT JOIN Machinery M ON D.DepartmentID = M.DepartmentID GROUP BY D.DepartmentName; |
List safety officers in the Production and Research departments. | CREATE TABLE Employees (Id INT,Name VARCHAR(50),Role VARCHAR(50),Department VARCHAR(50)); INSERT INTO Employees (Id,Name,Role,Department) VALUES (1,'Jane Smith','Safety Officer','Production'),(2,'Robert Johnson','Engineer','Research'); | SELECT * FROM Employees WHERE Role = 'Safety Officer' AND Department IN ('Production', 'Research'); |
What is the average temperature in the chemical storage facilities in New York and New Jersey combined? | CREATE TABLE storage_facilities (id INT,name TEXT,state TEXT,temperature FLOAT); INSERT INTO storage_facilities (id,name,state,temperature) VALUES (1,'Facility1','New York',20.5),(2,'Facility2','New York',21.3),(3,'Facility3','New Jersey',18.8),(4,'Facility4','New Jersey',19.9); | SELECT AVG(temperature) FROM storage_facilities WHERE state IN ('New York', 'New Jersey'); |
What is the total energy consumption of the Chemical Plant B in the last quarter? | CREATE TABLE EnergyConsumption (EnergyID INT,Plant VARCHAR(255),EnergyQuantity DECIMAL(5,2),Timestamp DATETIME); | SELECT SUM(EnergyQuantity) FROM EnergyConsumption WHERE Plant = 'Chemical Plant B' AND Timestamp BETWEEN DATE_SUB(CURRENT_DATE(), INTERVAL 3 MONTH) AND CURRENT_DATE(); |
What is the total quantity of chemical 'A' stored in tanks? | CREATE TABLE tank_inventory (tank_id INT,chemical VARCHAR(20),quantity INT); INSERT INTO tank_inventory (tank_id,chemical,quantity) VALUES (1,'A',500),(2,'B',300),(3,'A',700); | SELECT SUM(quantity) FROM tank_inventory WHERE chemical = 'A'; |
What is the average life expectancy in Africa and Asia? | CREATE TABLE life_expectancy (continent VARCHAR(20),life_expectancy DECIMAL(5,2)); INSERT INTO life_expectancy (continent,life_expectancy) VALUES ('Africa',60.5),('Asia',71.0); | SELECT AVG(life_expectancy) FROM life_expectancy WHERE continent IN ('Africa', 'Asia'); |
What is the percentage of the population that is fully vaccinated against COVID-19 in Australia and Argentina? | CREATE TABLE covid_vaccinations (country VARCHAR(20),percentage_fully_vaccinated DECIMAL(5,2)); INSERT INTO covid_vaccinations (country,percentage_fully_vaccinated) VALUES ('Australia',80.0),('Argentina',50.0); | SELECT AVG(percentage_fully_vaccinated) FROM covid_vaccinations WHERE country IN ('Australia', 'Argentina'); |
What is the ranking of hospitals in Canada by budget? | CREATE TABLE hospitals (id INT,name VARCHAR,city VARCHAR,state VARCHAR,country VARCHAR,budget DECIMAL(10,2)); INSERT INTO hospitals (id,name,city,state,country,budget) VALUES (1,'Toronto General Hospital','Toronto','ON','Canada',800000); INSERT INTO hospitals (id,name,city,state,country,budget) VALUES (2,'Vancouver General Hospital','Vancouver','BC','Canada',700000); | SELECT hospitals.*, ROW_NUMBER() OVER(PARTITION BY hospitals.country ORDER BY hospitals.budget DESC) as rank FROM hospitals WHERE hospitals.country = 'Canada'; |
List the names of startups that have more funding than the startup with the highest funding in the 'east_coast' region | CREATE TABLE companies (id INT,name TEXT,region TEXT,funding FLOAT); INSERT INTO companies (id,name,region,funding) VALUES (1,'Startup A','west_coast',5000000),(2,'Startup B','east_coast',3000000),(3,'Startup C','west_coast',7000000),(4,'Startup D','east_coast',8000000); | SELECT name FROM companies WHERE funding > (SELECT MAX(funding) FROM companies WHERE region = 'east_coast'); |
Which marine species have been observed in both the Arctic and Antarctic oceans? | CREATE TABLE marine_species (id INT,species_name VARCHAR(50),common_name VARCHAR(50),region VARCHAR(20));INSERT INTO marine_species (id,species_name,common_name,region) VALUES (1,'Orcinus_orca','Killer Whale','Arctic');INSERT INTO marine_species (id,species_name,common_name,region) VALUES (2,'Balaenoptera_bonaerensis','Antarctic Minke Whale','Antarctic'); | SELECT species_name FROM marine_species WHERE region IN ('Arctic', 'Antarctic') GROUP BY species_name HAVING COUNT(DISTINCT region) = 2; |
list all marine species that are found exclusively in the Indian Ocean, excluding sharks and rays | CREATE TABLE marine_species (id INT,species_name TEXT,habitat TEXT,conservation_status TEXT); INSERT INTO marine_species (id,species_name,habitat,conservation_status) VALUES (1,'Clownfish','Coral Reefs','Least Concern'); | SELECT species_name FROM marine_species WHERE habitat LIKE '%Indian Ocean%' AND species_name NOT IN (SELECT species_name FROM marine_species WHERE species_name LIKE '%Shark%' OR species_name LIKE '%Ray%') AND id NOT IN (SELECT species_id FROM sharks_and_rays) GROUP BY species_name HAVING COUNT(*) = 1; |
List the smart contract names and their corresponding blockchain networks from the 'smart_contracts' and 'blockchains' tables. | CREATE TABLE smart_contracts (contract_id INT,contract_name VARCHAR(50),blockchain_id INT); CREATE TABLE blockchains (blockchain_id INT,blockchain_name VARCHAR(50)); INSERT INTO smart_contracts (contract_id,contract_name,blockchain_id) VALUES (1,'Uniswap',1); INSERT INTO blockchains (blockchain_id,blockchain_name) VALUES (1,'Ethereum'); | SELECT smart_contracts.contract_name, blockchains.blockchain_name FROM smart_contracts INNER JOIN blockchains ON smart_contracts.blockchain_id = blockchains.blockchain_id; |
Update the 'SmartContracts' table to insert a new smart contract with a unique ContractID and the given parameters. | CREATE TABLE SmartContracts (ContractID INT,ContractName VARCHAR(255),ContractVersion VARCHAR(255),ContractOwner VARCHAR(255)); | INSERT INTO SmartContracts (ContractID, ContractName, ContractVersion, ContractOwner) SELECT MAX(ContractID) + 1, 'SampleContract', '1.0', 'SampleOwner' FROM SmartContracts WHERE NOT EXISTS (SELECT 1 FROM SmartContracts WHERE ContractID = MAX(ContractID) + 1); |
What is the percentage of violent crimes reported in the city of New York in 2019, grouped by the type of crime? | CREATE TABLE crimes (id INT,city VARCHAR(20),year INT,violent_crime BOOLEAN,crime_type VARCHAR(20)); INSERT INTO crimes (id,city,year,violent_crime,crime_type) VALUES (1,'New York',2019,true,'Assault'),(2,'New York',2019,false,'Theft'),(3,'New York',2019,true,'Robbery'); | SELECT crime_type, (COUNT(*) FILTER (WHERE violent_crime)) * 100.0 / COUNT(*) FROM crimes WHERE city = 'New York' AND year = 2019 GROUP BY crime_type; |
Show the number of humanitarian assistance missions conducted by the European Union in 2021 | CREATE TABLE humanitarian_assistance_missions (mission_id INT,organization VARCHAR(255),mission_name VARCHAR(255),start_date DATE,end_date DATE); INSERT INTO humanitarian_assistance_missions (mission_id,organization,mission_name,start_date,end_date) VALUES (1,'European Union','Mission A','2021-01-01','2021-12-31'); | SELECT COUNT(*) FROM humanitarian_assistance_missions WHERE organization = 'European Union' AND YEAR(start_date) = 2021; |
Identify any machines in the manufacturing process that have not been serviced in the past 6 months. | CREATE TABLE machines (machine_id INT,last_service DATE); INSERT INTO machines VALUES (1,'2021-08-01'),(2,'2021-10-15'),(3,'2022-02-05'),(4,'2022-03-10'),(5,'2022-04-02'); | SELECT machine_id FROM machines WHERE last_service < DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH); |
What is the total waste produced by the textile industry in Asia? | CREATE TABLE waste (factory_id INT,industry VARCHAR(50),region VARCHAR(50),waste_generated INT); | SELECT SUM(waste_generated) FROM waste WHERE industry = 'textile' AND region = 'Asia'; |
Find the number of artifacts excavated from 'Africa' in the year 2000. | CREATE TABLE Artifacts (ArtifactID int,Name text,SiteID int,ExcavationYear int); INSERT INTO Artifacts (ArtifactID,Name,SiteID,ExcavationYear) VALUES (1,'Artifact1',3,2000); | SELECT COUNT(*) FROM Artifacts WHERE Country = 'Africa' AND ExcavationYear = 2000; |
What is the average age of patients diagnosed with Asthma in the rural areas of Texas? | CREATE TABLE Patients (PatientID INT,Age INT,Gender VARCHAR(10),Diagnosis VARCHAR(20),Location VARCHAR(20)); INSERT INTO Patients (PatientID,Age,Gender,Diagnosis,Location) VALUES (1,35,'Male','Asthma','Texas'); INSERT INTO Patients (PatientID,Age,Gender,Diagnosis,Location) VALUES (2,42,'Female','Asthma','Texas'); | SELECT AVG(Age) FROM Patients WHERE Diagnosis = 'Asthma' AND Location = 'Texas'; |
What is the average investment amount made in a specific country? | CREATE TABLE Investments (InvestmentID INT,InvestorID INT,Country VARCHAR(20),Amount INT); INSERT INTO Investments (InvestmentID,InvestorID,Country,Amount) VALUES (1,1,'USA',4000),(2,1,'Canada',3000),(3,2,'Mexico',5000),(4,2,'Brazil',6000),(5,3,'USA',7000),(6,3,'Canada',8000); | SELECT AVG(Amount) as AverageInvestment FROM Investments WHERE Country = 'USA'; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.