instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
How many products are in each category? | CREATE TABLE products (product_id INT,name VARCHAR(255),category VARCHAR(50)); INSERT INTO products (product_id,name,category) VALUES (1,'Refurbished Laptop','Electronics'),(2,'Bamboo Toothbrush','Personal Care'); | SELECT category, COUNT(*) FROM products GROUP BY category; |
Update the 'cases' table: change the case_type to 'juvenile' for the record with case_id 1 | CREATE TABLE cases (case_id INT,case_type VARCHAR(10)); INSERT INTO cases (case_id,case_type) VALUES (1,'civil'),(2,'criminal'); | UPDATE cases SET case_type = 'juvenile' WHERE case_id = 1; |
List the case types and the number of cases, excluding cases with a billing amount greater than $10,000. | CREATE TABLE cases (id INT,case_type VARCHAR(20),billing_amount INT); INSERT INTO cases (id,case_type,billing_amount) VALUES (1,'Civil',5000),(2,'Criminal',7000),(3,'Civil',6000),(4,'Civil',15000); | SELECT case_type, COUNT(*) AS num_cases FROM cases WHERE billing_amount <= 10000 GROUP BY case_type; |
What was the total amount of humanitarian aid (in USD) distributed in the region "Southeast Asia" in 2019? | CREATE TABLE humanitarian_aid (id INT,year INT,region VARCHAR(20),amount INT); INSERT INTO humanitarian_aid (id,year,region,amount) VALUES (1,2019,'Southeast Asia',120000),(2,2018,'Africa',200000),(3,2019,'Southeast Asia',150000); | SELECT SUM(amount) FROM humanitarian_aid WHERE year = 2019 AND region = 'Southeast Asia'; |
What is the earliest release date for an inmate in the 'detention_facilities' table? | CREATE TABLE detention_facilities (inmate_id INT,age INT,ethnicity VARCHAR(20),release_date DATE); | SELECT MIN(release_date) FROM detention_facilities; |
What are the top 5 most mentioned 'electronics' brands in user posts from users aged 31-35 in the 'United States'? | CREATE TABLE user_posts (user_id INT,age INT,country VARCHAR(255),brand VARCHAR(255)); | SELECT brand, COUNT(*) AS mentions FROM user_posts WHERE age BETWEEN 31 AND 35 AND country = 'United States' AND brand IN ('brand1', 'brand2', 'brand3', 'brand4', 'brand5') GROUP BY brand LIMIT 5; |
Delete records in the 'Academic_Publications' table where the 'Publication_Type' is 'Conference_Paper' and the 'Publication_Year' is before 2010 | CREATE TABLE Academic_Publications (Publication_ID INT,Title VARCHAR(100),Publication_Type VARCHAR(50),Publication_Year INT,Author_ID INT); | DELETE FROM Academic_Publications WHERE Publication_Type = 'Conference_Paper' AND Publication_Year < 2010; |
Identify the top 5 sustainable fabric manufacturers with the highest total quantity of fabric produced. | CREATE TABLE Manufacturers (manufacturer_id INT,manufacturer_name TEXT,country TEXT); CREATE TABLE Fabric_Manufacturers (fabric_id INT,manufacturer_id INT,is_sustainable BOOLEAN,quantity INT); | SELECT m.manufacturer_name, SUM(fm.quantity) as total_quantity FROM Manufacturers m JOIN Fabric_Manufacturers fm ON m.manufacturer_id = fm.manufacturer_id WHERE fm.is_sustainable = TRUE GROUP BY m.manufacturer_name ORDER BY total_quantity DESC LIMIT 5; |
Identify the total number of electric vehicles in the vehicle_sales table and the autonomous_vehicles table. | CREATE TABLE vehicle_sales (id INT,vehicle_type VARCHAR(50)); INSERT INTO vehicle_sales (id,vehicle_type) VALUES (1,'Tesla Model 3'),(2,'Nissan Leaf'),(3,'Honda Civic'),(4,'Toyota Prius'); CREATE TABLE autonomous_vehicles (id INT,vehicle_type VARCHAR(50)); INSERT INTO autonomous_vehicles (id,vehicle_type) VALUES (1,'Wa... | SELECT COUNT(*) FROM vehicle_sales WHERE vehicle_type = 'electric' UNION SELECT COUNT(*) FROM autonomous_vehicles WHERE vehicle_type = 'electric'; |
List all the distinct players and their total points in descending order in the "nba_games" table | CREATE TABLE nba_games (player VARCHAR(255),points INTEGER); | SELECT player, SUM(points) as total_points FROM nba_games GROUP BY player ORDER BY total_points DESC; |
What is the average labor cost for sustainable construction projects in Georgia, grouped by building type? | CREATE TABLE labor_costs (project_id INT,state VARCHAR(2),building_type VARCHAR(20),labor_cost DECIMAL(5,2)); INSERT INTO labor_costs (project_id,state,building_type,labor_cost) VALUES (1,'GA','Residential',25000.00),(2,'GA','Residential',27000.50),(3,'GA','Commercial',30000.00); | SELECT building_type, AVG(labor_cost) FROM labor_costs WHERE state = 'GA' GROUP BY building_type; |
What is the average calorie content for each cuisine type? | CREATE TABLE cuisine (id INT,type VARCHAR(50),calories INT); INSERT INTO cuisine (id,type,calories) VALUES (1,'Italian',500),(2,'Mexican',600),(3,'Japanese',400); | SELECT type, AVG(calories) as avg_calories FROM cuisine GROUP BY type; |
How many mining operations are there in each region with at least one violation? | CREATE TABLE mining_violations (operation_id INT,region VARCHAR(20),has_violation BOOLEAN); INSERT INTO mining_violations (operation_id,region,has_violation) VALUES (1001,'West',TRUE),(1002,'East',FALSE),(1003,'North',TRUE),(1004,'South',FALSE),(1005,'West',TRUE),(1006,'East',TRUE); | SELECT region, COUNT(*) FROM mining_violations WHERE has_violation = TRUE GROUP BY region; |
Which smart contracts have the highest number of transactions per day? | CREATE TABLE smart_contracts (id INT,name VARCHAR(255),daily_transactions INT); INSERT INTO smart_contracts (id,name,daily_transactions) VALUES (1,'SC1',100),(2,'SC2',150),(3,'SC3',200),(4,'SC4',50),(5,'SC5',75); | SELECT name, daily_transactions AS Highest_Daily_Transactions FROM smart_contracts ORDER BY daily_transactions DESC LIMIT 1; |
What is the percentage change in average temperature for each region compared to the same month in the previous year? | CREATE TABLE monthly_temp_2 (region VARCHAR(255),temperature INT,month INT,year INT); INSERT INTO monthly_temp_2 (region,temperature,month,year) VALUES ('North',25,1,2021),('South',30,1,2021),('East',28,1,2021),('West',22,1,2021),('North',27,1,2022),('South',29,1,2022),('East',31,1,2022),('West',24,1,2022); | SELECT region, ((current_temp - prev_temp) * 100.0 / prev_temp) as pct_change FROM (SELECT region, temperature as current_temp, LAG(temperature) OVER (PARTITION BY region, month ORDER BY year) as prev_temp FROM monthly_temp_2) subquery; |
What is the minimum salinity level for each fish species in Tank7? | CREATE TABLE Tank7 (species VARCHAR(20),salinity FLOAT); INSERT INTO Tank7 (species,salinity) VALUES ('Tilapia',30),('Salmon',20),('Trout',15),('Tilapia',35),('Salmon',25); | SELECT species, MIN(salinity) FROM Tank7 GROUP BY species; |
What is the average production cost of garments made from recycled materials? | CREATE TABLE RecycledMaterialsGarments (garment_id INT,production_cost DECIMAL(5,2)); INSERT INTO RecycledMaterialsGarments (garment_id,production_cost) VALUES (1,22.50),(2,27.00),(3,24.75); | SELECT AVG(production_cost) FROM RecycledMaterialsGarments; |
How many pollution control initiatives are there in the Southern Ocean? | CREATE TABLE oceans (id INT,name TEXT,area FLOAT); CREATE TABLE regions (id INT,region TEXT); CREATE TABLE pollution_control (id INT,initiative TEXT,ocean_id INT,region_id INT); INSERT INTO oceans (id,name,area) VALUES (1,'Pacific Ocean',165200000); INSERT INTO oceans (id,name,area) VALUES (5,'Southern Ocean',20327000)... | SELECT COUNT(*) FROM pollution_control WHERE ocean_id = (SELECT id FROM oceans WHERE name = 'Southern Ocean') AND region_id = (SELECT id FROM regions WHERE region = 'South America'); |
What is the average explainability score for AI models in the 'explainable_ai' table that have a bias score less than 0.5? | CREATE TABLE explainable_ai (model_id INT,model_name TEXT,bias_score FLOAT,explainability_score FLOAT); | SELECT AVG(explainability_score) FROM explainable_ai WHERE bias_score < 0.5; |
What are the top 5 countries with the most security incidents in the last 6 months, according to our Threat Intelligence database? | CREATE TABLE ThreatIntel (id INT,country VARCHAR(50),incident_count INT,timestamp DATETIME); INSERT INTO ThreatIntel (id,country,incident_count,timestamp) VALUES (1,'USA',200,'2021-01-01 10:00:00'),(2,'Canada',150,'2021-01-01 10:00:00'); | SELECT country, COUNT(*) as incident_count FROM ThreatIntel WHERE timestamp >= DATE_SUB(NOW(), INTERVAL 6 MONTH) GROUP BY country ORDER BY incident_count DESC LIMIT 5; |
What is the average budget allocated to education in urban areas? | CREATE TABLE districts (id INT,name VARCHAR(20),type VARCHAR(10)); INSERT INTO districts (id,name,type) VALUES (1,'City A','urban'),(2,'Town B','urban'),(3,'Village C','rural'); CREATE TABLE budget_allocations (id INT,district_id INT,category VARCHAR(20),amount INT); INSERT INTO budget_allocations (id,district_id,categ... | SELECT AVG(ba.amount) FROM budget_allocations ba JOIN districts d ON ba.district_id = d.id WHERE d.type = 'urban' AND ba.category = 'education'; |
What are the details of the 5 most recent security incidents in the 'Incidents' table? | CREATE TABLE incidents (id INT,incident_name TEXT,description TEXT,incident_date DATETIME); INSERT INTO incidents (id,incident_name,description,incident_date) VALUES (1,'Incident1','Desc1','2022-01-01 10:00:00'),(2,'Incident2','Desc2','2022-02-01 11:00:00'); | SELECT * FROM incidents ORDER BY incident_date DESC LIMIT 5; |
Insert a new record in the "courts" table with the name "Supreme Court of Hawaii" located in the city "Honolulu" | CREATE TABLE courts (id INT,name VARCHAR(50),location VARCHAR(50)); | INSERT INTO courts (id, name, location) VALUES (1, 'Supreme Court of Hawaii', 'Honolulu'); |
What is the total number of cultural competency and mental health parity trainings conducted? | CREATE TABLE Trainings (Training_ID INT,Training_Name VARCHAR(50),Training_Date DATE); INSERT INTO Trainings (Training_ID,Training_Name,Training_Date) VALUES (1,'Cultural Competency','2021-01-01'); INSERT INTO Trainings (Training_ID,Training_Name,Training_Date) VALUES (2,'Mental Health Parity','2021-02-15'); | SELECT Training_Name, COUNT(*) FROM Trainings GROUP BY Training_Name; |
How many restorative justice programs are there in the justice_schemas.restorative_programs table for each region in the justice_schemas.regions table? | CREATE TABLE justice_schemas.restorative_programs (id INT PRIMARY KEY,name TEXT,region_id INT); CREATE TABLE justice_schemas.regions (id INT PRIMARY KEY,name TEXT); | SELECT r.name AS region, COUNT(*) AS num_programs FROM justice_schemas.restorative_programs rp INNER JOIN justice_schemas.regions r ON rp.region_id = r.id GROUP BY r.name; |
Discover customers who made purchases from both local and overseas suppliers. | CREATE TABLE customers (customer_id INT,customer_name VARCHAR(50),local_supplier BOOLEAN,overseas_supplier BOOLEAN); INSERT INTO customers (customer_id,customer_name,local_supplier,overseas_supplier) VALUES (1,'Customer N',TRUE,TRUE),(2,'Customer O',FALSE,FALSE),(3,'Customer P',TRUE,FALSE),(4,'Customer Q',FALSE,TRUE); ... | SELECT COUNT(DISTINCT customer_id) FROM (SELECT customer_id FROM purchases p JOIN customers c ON p.customer_id = c.customer_id WHERE c.local_supplier = TRUE INTERSECT SELECT customer_id FROM purchases p JOIN customers c ON p.customer_id = c.customer_id WHERE c.overseas_supplier = TRUE); |
What is the average population size of all marine mammal species? | CREATE TABLE marine_species (name TEXT,category TEXT,population INT); INSERT INTO marine_species (name,category,population) VALUES ('Blue Whale','Mammal',10000),('Dolphin','Mammal',25000),('Clownfish','Fish',150000); | SELECT AVG(population) FROM marine_species WHERE category = 'Mammal'; |
How many garments were produced in each region using recycled materials? | CREATE TABLE Recycled_Material_Garments (id INT,region VARCHAR,quantity INT); | SELECT region, SUM(quantity) FROM Recycled_Material_Garments GROUP BY region; |
How can I delete water conservation initiatives of type 'Greywater Recycling' in 'WaterConservation' table? | CREATE TABLE WaterConservation (initiative_id INT,initiative_type VARCHAR(20),region VARCHAR(20)); INSERT INTO WaterConservation (initiative_id,initiative_type,region) VALUES (1,'Rainwater Harvesting','RegionA'),(2,'Greywater Recycling','RegionB'),(3,'Smart Irrigation','RegionC'); | DELETE FROM WaterConservation WHERE initiative_type = 'Greywater Recycling'; |
What is the maximum number of bike-sharing trips in New York City in a day? | CREATE TABLE if not exists BikeSharing (id INT,city VARCHAR(20),trips INT,date DATE); INSERT INTO BikeSharing (id,city,trips,date) VALUES (1,'New York City',8000,'2022-03-15'),(2,'New York City',8500,'2022-03-16'),(3,'Los Angeles',6000,'2022-03-15'); | SELECT MAX(trips) FROM BikeSharing WHERE city = 'New York City'; |
Find the total budget allocated for infrastructure projects in the state of New York. | CREATE SCHEMA gov_data;CREATE TABLE gov_data.infrastructure_budget (state VARCHAR(20),project VARCHAR(20),budget INT); INSERT INTO gov_data.infrastructure_budget (state,project,budget) VALUES ('New York','Bridges',1000000),('New York','Roads',1500000),('California','Bridges',800000),('California','Roads',1200000); | SELECT state, SUM(budget) as total_budget FROM gov_data.infrastructure_budget WHERE state = 'New York' GROUP BY state; |
What was the average number of tourists visiting Asia in 2019 and 2020? | CREATE TABLE tourists (id INT,continent VARCHAR(50),country VARCHAR(50),visitors INT,year INT); INSERT INTO tourists (id,continent,country,visitors,year) VALUES (1,'Asia','China',3000,2019),(2,'Asia','India',2500,2019),(3,'Asia','China',2000,2020),(4,'Asia','India',1500,2020); | SELECT AVG(visitors) FROM tourists WHERE continent = 'Asia' AND year IN (2019, 2020) GROUP BY year; |
What is the total number of heritage sites in each country of Central America? | CREATE TABLE HeritageSites (id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO HeritageSites (id,name,country) VALUES (1,'Copan','Honduras'),(2,'Tikal','Guatemala'),(3,'Panamá Viejo','Panama'),(4,'Granada','Nicaragua'),(5,'León Viejo','Nicaragua'); | SELECT country, COUNT(*) as total_sites FROM HeritageSites GROUP BY country; |
List all unique soil types and their corresponding ph levels in descending order of ph level | CREATE TABLE soil (soil_type VARCHAR(255),ph DECIMAL(3,1)); INSERT INTO soil (soil_type,ph) VALUES ('loam',6.8),('silt',7.1),('clay',6.5),('sand',7.5); | SELECT DISTINCT soil_type, ph FROM soil ORDER BY ph DESC; |
What is the maximum volume of timber harvested in forests in each year? | CREATE TABLE forests (id INT,year INT,volume FLOAT); INSERT INTO forests (id,year,volume) VALUES (1,2010,1200.5),(2,2011,1500.3),(3,2010,800.2),(4,2011,900.1); | SELECT year, MAX(volume) FROM forests GROUP BY year; |
Display the number of new users who joined the social_media platform each month in the year 2021, and the total number of users on the platform at the end of each month. | CREATE TABLE user_history (username VARCHAR(50),join_date DATE); | SELECT DATE_FORMAT(join_date, '%Y-%m') as month, COUNT(DISTINCT username) as new_users, (SELECT COUNT(DISTINCT username) FROM user_history WHERE join_date <= LAST_DAY(join_date)) as total_users FROM user_history WHERE YEAR(join_date) = 2021 GROUP BY month ORDER BY month; |
What is the average budget allocated for inclusion efforts in each state? | CREATE TABLE Inclusion(inclusion_id INT,state TEXT,budget DECIMAL(5,2)); | SELECT a.state, AVG(a.budget) FROM Inclusion a GROUP BY a.state; |
What is the average funding received by startups founded in each month? | CREATE TABLE startups(id INT,name TEXT,founding_month INT,funding FLOAT); INSERT INTO startups(id,name,founding_month,funding) VALUES (1,'StartupA',1,500000),(2,'StartupB',2,750000),(3,'StartupC',3,250000),(4,'StartupD',4,300000),(5,'StartupE',5,150000); | SELECT founding_month, AVG(funding) FROM startups GROUP BY founding_month; |
What is the most visited 'Temporary Exhibition'? | CREATE TABLE exhibitions (id INT,name VARCHAR(255),type VARCHAR(255),visits INT); INSERT INTO exhibitions (id,name,type,visits) VALUES (1,'Cubism','Modern',3000),(2,'Abstract','Modern',4500),(3,'Impressionism','Classic',5000),(4,'Surrealism','Modern',2500),(5,'Renaissance','Classic',6000),(6,'Temporary Exhibit A','Temp... | SELECT name FROM exhibitions WHERE type = 'Temporary' AND visits = (SELECT MAX(visits) FROM exhibitions WHERE type = 'Temporary'); |
Display the veteran employment statistics for each state in the US. | CREATE TABLE veteran_employment(id INT,state VARCHAR(20),employed_veterans INT,total_veterans INT); | SELECT state, employed_veterans, total_veterans, (employed_veterans::FLOAT/total_veterans)*100 AS employment_rate FROM veteran_employment; |
Calculate the percentage of resolved security incidents for each department in the company, for the current year? | CREATE TABLE incidents (incident_id INT,department VARCHAR(255),incident_date DATE,incident_status VARCHAR(255)); INSERT INTO incidents (incident_id,department,incident_date,incident_status) VALUES (1,'IT','2022-01-01','Resolved'),(2,'HR','2022-02-01','Open'),(3,'IT','2022-03-01','Resolved'),(4,'Finance','2022-04-01','... | SELECT department, COUNT(incident_id) as total_incidents, COUNT(CASE WHEN incident_status = 'Resolved' THEN 1 END) as resolved_incidents, 100.0 * COUNT(CASE WHEN incident_status = 'Resolved' THEN 1 END) / COUNT(incident_id) as resolved_percentage FROM incidents WHERE incident_date >= DATEADD(year, -1, GETDATE()) GROUP ... |
Update records of clients who have taken loans from the Financial Capability database | CREATE TABLE financial_capability_client (client_id INT PRIMARY KEY,name VARCHAR(100),age INT,education_level VARCHAR(20));CREATE TABLE financial_capability_loan (loan_id INT PRIMARY KEY,client_id INT,loan_amount DECIMAL(10,2),loan_date DATE);INSERT INTO financial_capability_client (client_id,name,age,education_level) ... | UPDATE client SET education_level = (SELECT education_level FROM financial_capability_client f WHERE f.client_id = client.client_id) FROM client INNER JOIN financial_capability_loan l ON client.client_id = l.client_id; |
Which green buildings were built before 2010? | CREATE TABLE green_buildings (id INT,building_name TEXT,built_date DATE); INSERT INTO green_buildings (id,building_name,built_date) VALUES (1,'Building A','2009-01-01'),(2,'Building B','2011-01-01'); | SELECT building_name FROM green_buildings WHERE YEAR(built_date) < 2010; |
How many job applications were received from candidates in each country in the past month? | CREATE TABLE job_applications (id INT,applicant_name VARCHAR(50),date_applied DATE,country VARCHAR(50)); | SELECT country, COUNT(*) FROM job_applications WHERE date_applied >= DATEADD(month, -1, GETDATE()) GROUP BY country; |
What is the average price of organic fruits in the 'farmers_market' table? | CREATE TABLE farmers_market (id INT,type VARCHAR(10),name VARCHAR(20),price DECIMAL(5,2)); | SELECT AVG(price) FROM farmers_market WHERE type = 'organic' AND category = 'fruit'; |
Which electric vehicles have the highest safety ratings? | CREATE TABLE Safety_Testing (vehicle VARCHAR(100),safety_rating INT); INSERT INTO Safety_Testing (vehicle,safety_rating) VALUES ('2019 Toyota Camry',5),('2020 Tesla Model 3',5),('2021 Ford Mustang Mach-E',5),('2018 Nissan Leaf',4),('2022 Hyundai Kona Electric',5); CREATE TABLE Electric_Vehicles (vehicle VARCHAR(100),ma... | SELECT e.make, e.model, s.safety_rating FROM Safety_Testing s INNER JOIN Electric_Vehicles e ON s.vehicle = e.vehicle WHERE s.safety_rating = 5; |
What are the names of animals in 'sanctuary_c' with a population greater than 50? | CREATE TABLE sanctuary_c (animal_id INT,animal_name VARCHAR(50),population INT); INSERT INTO sanctuary_c VALUES (1,'lion',60); INSERT INTO sanctuary_c VALUES (2,'zebra',45); | SELECT animal_name FROM sanctuary_c WHERE population > 50; |
How much water has been saved by water conservation initiatives in New Mexico? | CREATE TABLE conservation_initiatives (id INT,name TEXT,state TEXT,water_savings FLOAT); INSERT INTO conservation_initiatives (id,name,state,water_savings) VALUES (1,'Water-efficient appliances','New Mexico',8),(2,'Rainwater harvesting','New Mexico',12),(3,'Greywater reuse','New Mexico',10); | SELECT SUM(water_savings) as total_water_saved FROM conservation_initiatives WHERE state = 'New Mexico'; |
List all drugs that were approved in 2018 and their respective approval times. | CREATE TABLE drug_approval (drug_name VARCHAR(255),approval_date DATE); INSERT INTO drug_approval (drug_name,approval_date) VALUES ('Drug A','2018-01-01'),('Drug B','2018-06-15'),('Drug C','2018-12-25'); | SELECT drug_name, DATEDIFF('2018-12-31', approval_date) as approval_time FROM drug_approval; |
Find the number of times each crop type was recorded in the 'sensor_data_2021' table. | CREATE TABLE sensor_data_2021 (id INT,crop VARCHAR(20)); INSERT INTO sensor_data_2021 (id,crop) VALUES (1,'Corn'),(2,'Soybean'),(3,'Corn'),(4,'Wheat'); | SELECT crop, COUNT(*) FROM sensor_data_2021 GROUP BY crop; |
How many ethical AI research papers were published in 2020 and 2021? | CREATE TABLE papers (id INT,title TEXT,publication_year INT,country TEXT); INSERT INTO papers (id,title,publication_year,country) VALUES (1,'PaperA',2020,'USA'),(2,'PaperB',2019,'Canada'),(3,'PaperC',2021,'Brazil'); | SELECT publication_year, COUNT(*) FROM papers WHERE publication_year IN (2020, 2021) GROUP BY publication_year; |
Display the number of academic publications by journal for the last 5 years | CREATE TABLE Publication (id INT,year INT,journal VARCHAR(255),department_id INT); INSERT INTO Publication (id,year,journal,department_id) VALUES (1,2018,'Journal of Computer Science',1),(2,2019,'Physical Review',2),(3,2018,'English Literature Review',3),(4,2017,'Journal of Mathematics',1),(5,2020,'Journal of Computer ... | SELECT p.journal, COUNT(*) as num_publications FROM Publication p WHERE YEAR(p.year) BETWEEN YEAR(CURDATE()) - 5 AND YEAR(CURDATE()) GROUP BY p.journal; |
How many TEUs were handled by each port in the cargo_handling table in reverse chronological order? | CREATE TABLE cargo_handling (port_id INT,port_name VARCHAR(50),teu_count INT,handling_date DATE); INSERT INTO cargo_handling (port_id,port_name,teu_count,handling_date) VALUES (1,'Port_A',2000,'2022-01-01'),(2,'Port_B',3000,'2022-01-02'),(3,'Port_C',1000,'2022-01-03'); | SELECT port_name, teu_count, ROW_NUMBER() OVER (PARTITION BY port_name ORDER BY handling_date DESC) as rn FROM cargo_handling; |
Update the 'Sour Diesel' sales record from June 15, 2021 to 5 units. | CREATE TABLE Sales (id INT,product VARCHAR(255),sold_date DATE,quantity INT); INSERT INTO Sales (id,product,sold_date,quantity) VALUES (1,'Sour Diesel','2021-01-02',3),(2,'Sour Diesel','2021-06-15',2); | UPDATE Sales SET quantity = 5 WHERE product = 'Sour Diesel' AND sold_date = '2021-06-15'; |
What is the average attendance for games played in the current season? | CREATE TABLE games (team_id INT,attendance INT); INSERT INTO games (team_id,attendance) VALUES (1,15000),(1,16000),(2,12000),(2,13000),(3,17000); | SELECT AVG(attendance) FROM games WHERE team_id IN (SELECT team_id FROM (SELECT team_id, SUM(played) AS games_played FROM team_schedule GROUP BY team_id) AS subquery WHERE games_played = (SELECT MAX(subquery2.games_played) FROM subquery AS subquery2)); |
What is the total watch time in minutes for videos about climate change, having a duration of more than 15 minutes? | CREATE TABLE videos (id INT,title VARCHAR(100),topic VARCHAR(50),duration INT,watch_time INT); INSERT INTO videos (id,title,topic,duration,watch_time) VALUES (1,'Video1','Climate Change',22,1500),(2,'Video2','Politics',10,500),(3,'Video3','Climate Change',20,1200); | SELECT SUM(watch_time) FROM videos WHERE topic = 'Climate Change' AND duration > 15; |
Who are the top 5 customers by spending on sustainable products? | CREATE TABLE customers (customer_id INT,name VARCHAR(20),total_spent DECIMAL(5,2)); INSERT INTO customers (customer_id,name,total_spent) VALUES (1,'Alice',150.00),(2,'Bob',200.00),(3,'Charlie',300.00),(4,'David',50.00),(5,'Eve',400.00); CREATE TABLE sales (sale_id INT,customer_id INT,product_id INT,sale_amount DECIMAL(... | SELECT customers.name, SUM(sales.sale_amount) AS total_spent FROM customers JOIN sales ON customers.customer_id = sales.customer_id JOIN products ON sales.product_id = products.product_id WHERE products.material IN ('organic cotton', 'hemp', 'recycled polyester') GROUP BY customers.name ORDER BY total_spent DESC LIMIT ... |
List all dispensaries that have purchased products from cultivators in states that have legalized recreational cannabis. | CREATE TABLE Dispensaries (DispensaryID INT,DispensaryName TEXT,State TEXT); INSERT INTO Dispensaries (DispensaryID,DispensaryName,State) VALUES (1,'High Plains','Colorado'); CREATE TABLE Cultivators (CultivatorID INT,CultivatorName TEXT,State TEXT); INSERT INTO Cultivators (CultivatorID,CultivatorName,State) VALUES (1... | SELECT d.DispensaryName FROM Dispensaries d INNER JOIN Inventory i ON d.DispensaryID = i.DispensaryID INNER JOIN Cultivators c ON i.CultivatorID = c.CultivatorID WHERE c.State IN ('California', 'Colorado', 'Vermont', 'Oregon', 'Alaska', 'Nevada', 'Michigan', 'Massachusetts', 'Maine', 'Washington', 'Illinois', 'Arizona'... |
Show all records from the bike sharing table | CREATE TABLE bike_share (id INT PRIMARY KEY,station_name VARCHAR(255),station_latitude DECIMAL(9,6),station_longitude DECIMAL(9,6),dock_count INT,city VARCHAR(255)); INSERT INTO bike_share (id,station_name,station_latitude,station_longitude,dock_count,city) VALUES (1,'City Hall',37.7749,-122.4194,30,'San Francisco'); | SELECT * FROM bike_share; |
What is the maximum number of defense contracts signed by a single company in the United States? | CREATE TABLE defense_contracts (dc_id INT,dc_company VARCHAR(50),dc_country VARCHAR(50)); INSERT INTO defense_contracts (dc_id,dc_company,dc_country) VALUES (1,'Company A','United States'),(2,'Company B','United States'),(3,'Company C','Canada'); | SELECT MAX(dc_count) FROM (SELECT COUNT(*) AS dc_count FROM defense_contracts WHERE dc_country = 'United States' GROUP BY dc_company) AS subquery; |
What is the total yield for each crop type in the 'Agroecology' schema? | CREATE SCHEMA Agroecology; CREATE TABLE crop_yields (crop_type TEXT,yield NUMERIC) IN Agroecology; INSERT INTO crop_yields (crop_type,yield) VALUES ('Wheat',12000),('Rice',15000),('Corn',20000),('Wheat',14000),('Rice',16000); | SELECT crop_type, SUM(yield) as total_yield FROM Agroecology.crop_yields GROUP BY crop_type; |
What is the average phosphorus level in soil samples taken from farm ID 201? | CREATE TABLE soil_samples (id INT PRIMARY KEY,farm_id INT,sample_date DATE,nitrogen FLOAT,phosphorus FLOAT,potassium FLOAT); INSERT INTO soil_samples (id,farm_id,sample_date,nitrogen,phosphorus,potassium) VALUES (1,201,'2021-02-01',32.5,15.2,87.6); INSERT INTO soil_samples (id,farm_id,sample_date,nitrogen,phosphorus,po... | SELECT AVG(phosphorus) FROM soil_samples WHERE farm_id = 201; |
What is the total funding received by startups in the 'bioprocess engineering' sector, excluding 'BioVentures'? | CREATE TABLE startups (id INT,name VARCHAR(50),sector VARCHAR(50),funding FLOAT); INSERT INTO startups (id,name,sector,funding) VALUES (1,'Genetech','genetic research',2000000),(2,'BioVentures','bioprocess engineering',1500000),(3,'NanoBio','biosensor technology',1000000); | SELECT SUM(funding) FROM startups WHERE sector = 'bioprocess engineering' AND name != 'BioVentures'; |
What is the total biomass of tilapia and salmon in all farms? | CREATE TABLE biomass (farm_id INT,fish_type VARCHAR(20),biomass_kg FLOAT); INSERT INTO biomass (farm_id,fish_type,biomass_kg) VALUES (1,'tilapia',1200),(2,'salmon',1500),(3,'tilapia',1300),(4,'salmon',1600); | SELECT SUM(biomass_kg) FROM biomass WHERE fish_type IN ('tilapia', 'salmon'); |
What is the average data usage for mobile customers in each country, segmented by prepaid and postpaid? | CREATE TABLE mobile_customers (customer_id INT,data_usage FLOAT,country VARCHAR(50),postpaid BOOLEAN); INSERT INTO mobile_customers (customer_id,data_usage,country,postpaid) VALUES (1,2000,'USA',TRUE),(2,1500,'Mexico',FALSE),(3,3000,'Canada',TRUE); | SELECT country, postpaid, AVG(data_usage) AS avg_data_usage FROM mobile_customers GROUP BY country, postpaid; |
Insert a new record in the restaurant_menu table for 'Tofu Stir Fry' dish under 'Asian Cuisine' category. | CREATE TABLE restaurant_menu (dish VARCHAR(255),category VARCHAR(255),price DECIMAL(10,2)); INSERT INTO restaurant_menu (dish,category,price) VALUES ('Veg Samosas','Indian Cuisine',5.50); INSERT INTO restaurant_menu (dish,category,price) VALUES ('Chicken Tikka Masala','Indian Cuisine',12.99); | INSERT INTO restaurant_menu (dish, category, price) VALUES ('Tofu Stir Fry', 'Asian Cuisine', 11.99); |
What was the total military spending in the Middle East in 2017? | CREATE TABLE MilitarySpending (ID INT,Year INT,Amount INT,Region TEXT); INSERT INTO MilitarySpending (ID,Year,Amount,Region) VALUES (1,2016,600,'Middle East'),(2,2017,650,'Middle East'),(3,2018,700,'Asia-Pacific'); | SELECT SUM(Amount) FROM MilitarySpending WHERE Year = 2017 AND Region = 'Middle East'; |
Show all players who play games from the same genre as 'Max' | CREATE TABLE Players (player_id INT,name VARCHAR(255),age INT,game_genre VARCHAR(255)); INSERT INTO Players (player_id,name,age,game_genre) VALUES (1,'John',27,'FPS'),(2,'Sarah',30,'RPG'),(3,'Alex',22,'FPS'),(4,'Max',25,'Strategy'),(5,'Zoe',28,'FPS'); | SELECT * FROM Players WHERE game_genre = (SELECT game_genre FROM Players WHERE name = 'Max'); |
How many heritage sites are located in each country in the Middle East, and what is the name of the site in each country with the highest number of visitors? | CREATE TABLE Heritage_Sites_Visitors (Site_Name VARCHAR(50),Country VARCHAR(50),Visitors INT); INSERT INTO Heritage_Sites_Visitors (Site_Name,Country,Visitors) VALUES ('Petra','Jordan',800000),('Machu Picchu','Peru',1200000); | SELECT Country, COUNT(*) AS Site_Count, MAX(Visitors) AS Max_Visitors, MIN(Site_Name) AS Max_Visitors_Site FROM Heritage_Sites_Visitors WHERE Country IN ('Jordan', 'Peru') GROUP BY Country; |
Which countries have the most diverse set of topics covered in articles? | CREATE TABLE Articles (id INT,country TEXT,topic TEXT); INSERT INTO Articles (id,country,topic) VALUES (1,'Country 1','Topic 1'),(2,'Country 1','Topic 2'),(3,'Country 2','Topic 1'); | SELECT country, COUNT(DISTINCT topic) as unique_topics FROM Articles GROUP BY country ORDER BY unique_topics DESC; |
What is the maximum R&D expenditure for drugs approved by the MHRA in 2020? | CREATE TABLE drug_approval (drug_name VARCHAR(255),approval_body VARCHAR(255),approval_year INT); CREATE TABLE rd_expenditure (drug_name VARCHAR(255),rd_expenditure FLOAT); INSERT INTO drug_approval (drug_name,approval_body,approval_year) VALUES ('DrugA','FDA',2019),('DrugB','EMA',2018),('DrugC','MHRA',2020),('DrugD','... | SELECT MAX(rd_expenditure) FROM rd_expenditure INNER JOIN drug_approval ON rd_expenditure.drug_name = drug_approval.drug_name WHERE drug_approval.approval_body = 'MHRA' AND drug_approval.approval_year = 2020; |
Which genetic research projects have the highest and lowest average temperature requirements? | CREATE TABLE genetic_research (id INT,project_name VARCHAR(255),temperature_min FLOAT,temperature_max FLOAT); INSERT INTO genetic_research (id,project_name,temperature_min,temperature_max) VALUES (1,'ProjectA',15,25); INSERT INTO genetic_research (id,project_name,temperature_min,temperature_max) VALUES (2,'ProjectB',20... | SELECT project_name, AVG(temperature_min) AS avg_temp_min, AVG(temperature_max) AS avg_temp_max FROM genetic_research GROUP BY project_name ORDER BY avg_temp_min, avg_temp_max; |
Show the top 5 AI safety incidents that had the highest financial impact, ordered by the financial impact in descending order. | CREATE TABLE IncidentFinancials (incident_id INT,financial_impact DECIMAL(10,2)); INSERT INTO IncidentFinancials (incident_id,financial_impact) VALUES (1,10000.00),(2,5000.00),(3,25000.00),(4,15000.00),(5,7500.00),(6,3000.00),(7,20000.00),(8,12000.00),(9,8000.00),(10,4000.00); | SELECT incident_id, financial_impact FROM (SELECT incident_id, financial_impact, ROW_NUMBER() OVER (ORDER BY financial_impact DESC) as rank FROM IncidentFinancials) subquery WHERE rank <= 5; |
What is the total number of accessible technology initiatives in all continents? | CREATE TABLE accessible_tech_2 (initiative_id INT,continent VARCHAR(20),initiatives INT); INSERT INTO accessible_tech_2 (initiative_id,continent,initiatives) VALUES (1,'Asia',150),(2,'Africa',200),(3,'Europe',120),(4,'South America',180),(5,'North America',220); | SELECT SUM(initiatives) FROM accessible_tech_2; |
What is the total investment in each region? | CREATE TABLE region_investments (region VARCHAR(255),investment_amount DECIMAL(10,2),investment_type VARCHAR(255)); | SELECT region, SUM(investment_amount) AS total_investment FROM region_investments GROUP BY region; |
What is the total number of military personnel in the African Union and their respective countries of origin? | CREATE TABLE MilitaryPersonnel (id INT,personell INT,country TEXT); INSERT INTO MilitaryPersonnel (id,personell,country) VALUES (1,100000,'Nigeria'),(2,150000,'Egypt'); | SELECT MilitaryPersonnel.country, SUM(MilitaryPersonnel.personell) as total_personell FROM MilitaryPersonnel WHERE MilitaryPersonnel.country IN (SELECT country FROM Countries WHERE Continent = 'Africa') GROUP BY MilitaryPersonnel.country; |
How many properties are available for sale in each borough in New York City? | CREATE TABLE properties (id INT,borough VARCHAR(255),for_sale BOOLEAN); INSERT INTO properties (id,borough,for_sale) VALUES (1,'Manhattan',TRUE),(2,'Brooklyn',FALSE),(3,'Queens',TRUE),(4,'Manhattan',TRUE); | SELECT borough, COUNT(*) FROM properties WHERE for_sale = TRUE GROUP BY borough; |
Which underwater volcanoes in the Atlantic Ocean have been active since 2000? | CREATE TABLE underwater_volcanoes (name VARCHAR(255),ocean VARCHAR(255),last_eruption DATE); INSERT INTO underwater_volcanoes (name,ocean,last_eruption) VALUES ('Kavachi','Pacific','2007-01-01'),('Tagoro','Atlantic','2011-01-01'); | SELECT name FROM underwater_volcanoes WHERE ocean = 'Atlantic' AND last_eruption >= '2000-01-01'; |
What is the maximum price of seafood per pound in the Northeast? | CREATE TABLE prices (id INT,product VARCHAR(30),unit VARCHAR(10),price DECIMAL(5,2)); INSERT INTO prices (id,product,unit,price) VALUES (1,'Salmon','pound',15.99),(2,'Shrimp','pound',9.99),(3,'Tuna','pound',19.99),(4,'Northeast Lobster','pound',34.99); | SELECT MAX(price) FROM prices WHERE product LIKE '%Northeast%' AND unit = 'pound'; |
What is the most popular appetizer and its quantity sold? | CREATE TABLE orders (order_id INT,appetizer VARCHAR(255),appetizer_quantity INT); INSERT INTO orders VALUES (1,'Bruschetta',15),(2,'Calamari',8),(3,'Bruschetta',12); | SELECT appetizer, MAX(appetizer_quantity) FROM orders WHERE appetizer IS NOT NULL GROUP BY appetizer; |
List all countries with their respective number of news channels and the total number of employees in those channels. | CREATE TABLE news_channels (id INT,name VARCHAR(255),country VARCHAR(255),num_employees INT); INSERT INTO news_channels (id,name,country,num_employees) VALUES (1,'Channel1','Country1',100),(2,'Channel2','Country2',200); | SELECT country, COUNT(*) as num_channels, SUM(num_employees) as total_employees FROM news_channels GROUP BY country; |
What are the 'employee_id' and 'department' of employees with 'skills' in 'welding'? | CREATE TABLE employee_skills (employee_id INT,skill VARCHAR(50)); INSERT INTO employee_skills (employee_id,skill) VALUES (1,'welding'),(2,'painting'),(3,'welding'); CREATE TABLE employees (id INT,name VARCHAR(100),department VARCHAR(50)); INSERT INTO employees (id,name,department) VALUES (1,'Jane Smith','manufacturing'... | SELECT e.id, e.department FROM employees e JOIN employee_skills es ON e.id = es.employee_id WHERE es.skill = 'welding'; |
How many times did IP 192.168.0.10 appear in firewall logs this week? | CREATE TABLE firewall_logs (id INT,ip TEXT,timestamp TIMESTAMP); INSERT INTO firewall_logs (id,ip,timestamp) VALUES (1,'192.168.0.11','2021-02-01 12:00:00'),(2,'192.168.0.10','2021-02-04 14:30:00'),(3,'192.168.0.12','2021-02-05 10:15:00'); | SELECT COUNT(*) FROM firewall_logs WHERE ip = '192.168.0.10' AND timestamp >= NOW() - INTERVAL '1 week'; |
List the total quantity of products sold in stores located in Canada that have 'organic' in their name. | CREATE TABLE stores (store_id INT,name VARCHAR(100),location VARCHAR(50)); INSERT INTO stores (store_id,name,location) VALUES (1,'Organic Cotton Store','Canada'); INSERT INTO stores (store_id,name,location) VALUES (2,'Green Living Store','Canada'); CREATE TABLE products (product_id INT,name VARCHAR(100),quantity INT); ... | SELECT SUM(p.quantity) FROM products p JOIN sales s ON p.product_id = s.product_id JOIN stores st ON s.store_id = st.store_id WHERE st.location = 'Canada' AND st.name LIKE '%organic%'; |
List all genetic research projects in the UK and their respective leads. | CREATE TABLE genetics_research (id INT,project_name VARCHAR(50),lead_name VARCHAR(50),lead_email VARCHAR(50)); INSERT INTO genetics_research (id,project_name,lead_name,lead_email) VALUES (1,'ProjectX','John Doe','johndoe@email.com'); INSERT INTO genetics_research (id,project_name,lead_name,lead_email) VALUES (2,'Projec... | SELECT project_name, lead_name FROM genetics_research WHERE lead_email LIKE '%.uk'; |
Identify distinct artisans in each heritage site. | CREATE TABLE Heritage_Sites (id INT,site_name VARCHAR(100),country VARCHAR(50),year_established INT,UNIQUE (id));CREATE TABLE Artisans (artisan_id INT,name VARCHAR(100),age INT,heritage_site_id INT,PRIMARY KEY (artisan_id),FOREIGN KEY (heritage_site_id) REFERENCES Heritage_Sites(id)); | SELECT heritage_site_id, COUNT(DISTINCT artisan_id) FROM Artisans GROUP BY heritage_site_id; |
What is the number of transactions per transaction category for the month of March 2022? | CREATE TABLE transactions (transaction_id INT,transaction_date DATE,transaction_category VARCHAR(255),transaction_value DECIMAL(10,2)); INSERT INTO transactions (transaction_id,transaction_date,transaction_category,transaction_value) VALUES (1,'2022-03-02','Food',75.00),(2,'2022-03-05','Electronics',350.00),(3,'2022-03... | SELECT transaction_category, COUNT(transaction_id) as num_transactions FROM transactions WHERE transaction_date BETWEEN '2022-03-01' AND '2022-03-31' GROUP BY transaction_category; |
What is the total number of employees in each industry for cities with a population greater than 5,000,000? | CREATE TABLE City (id INT,name VARCHAR,population INT); INSERT INTO City (id,name,population) VALUES (1,'New York',8500000); INSERT INTO City (id,name,population) VALUES (2,'Los Angeles',4000000); INSERT INTO City (id,name,population) VALUES (3,'Chicago',2700000); CREATE TABLE Industry (id INT,city_id INT,industry_name... | SELECT i.industry_name, SUM(i.employment) FROM Industry i INNER JOIN City c ON i.city_id = c.id WHERE c.population > 5000000 GROUP BY i.industry_name; |
What is the percentage of fans that are female in each age group? | CREATE TABLE FanDemographics (FanID INT,Age INT,Gender VARCHAR(10)); INSERT INTO FanDemographics (FanID,Age,Gender) VALUES (1,20,'Female'); | SELECT Age, Gender, COUNT(*) * 100.0 / (SELECT COUNT(*) FROM FanDemographics) AS Percentage FROM FanDemographics GROUP BY Age, Gender; |
What is the total quantity of organic products sold between '2021-06-01' and '2021-06-15'? | CREATE TABLE ProductSales (product_id INT,sale_date DATE,quantity_sold INT,is_organic BOOLEAN); INSERT INTO ProductSales (product_id,sale_date,quantity_sold,is_organic) VALUES (1,'2021-06-02',15,true); | SELECT SUM(quantity_sold) as total_quantity_sold FROM ProductSales WHERE sale_date BETWEEN '2021-06-01' AND '2021-06-15' AND is_organic = true; |
What are the total items shipped between the USA and Germany in February 2021? | CREATE TABLE Shipment (id INT,source_country VARCHAR(255),destination_country VARCHAR(255),items_quantity INT,shipment_date DATE); INSERT INTO Shipment (id,source_country,destination_country,items_quantity,shipment_date) VALUES (1,'USA','Germany',150,'2021-02-01'),(2,'Germany','USA',100,'2021-02-03'); | SELECT SUM(items_quantity) FROM Shipment WHERE (source_country = 'USA' AND destination_country = 'Germany') OR (source_country = 'Germany' AND destination_country = 'USA') AND shipment_date BETWEEN '2021-02-01' AND '2021-02-28'; |
Find the number of wins for each player for game X in the 'PlayerGames' and 'Games' tables | CREATE TABLE PlayerGames (PlayerID INT,GameID INT,GameWon BOOLEAN); CREATE TABLE Games (GameID INT,GameName VARCHAR(255)); INSERT INTO Games (GameID,GameName) VALUES (1,'GameX'),(2,'GameY'),(3,'GameZ'); | SELECT PlayerID, SUM(GameWon) as WinsForGameX FROM PlayerGames JOIN Games ON PlayerGames.GameID = Games.GameID WHERE Games.GameName = 'GameX' GROUP BY PlayerID; |
What are the drug categories with no sales? | CREATE TABLE drug_sales (drug_category VARCHAR(255),sales INT); INSERT INTO drug_sales (drug_category,sales) VALUES ('Analgesics',5000000),('Antidepressants',7000000),('Cardiovascular',8000000); CREATE TABLE drug_categories (drug_category VARCHAR(255)); INSERT INTO drug_categories (drug_category) VALUES ('Dermatology')... | SELECT dc.drug_category FROM drug_categories dc LEFT JOIN drug_sales ds ON dc.drug_category = ds.drug_category WHERE ds.sales IS NULL; |
What is the total number of hotels in 'Barcelona' and 'Rome'? | CREATE TABLE hotels (hotel_id INT,name VARCHAR(50),location VARCHAR(50),stars INT); | SELECT SUM(stars) FROM hotels WHERE location IN ('Barcelona', 'Rome'); |
How many financial wellbeing programs were introduced in Q3 2021? | CREATE TABLE financial_wellbeing_programs (id INT PRIMARY KEY,program_name TEXT,introduction_date DATE); | SELECT COUNT(*) FROM financial_wellbeing_programs WHERE introduction_date BETWEEN '2021-07-01' AND '2021-09-30'; |
How many trains in the 'Central' region have a maintenance frequency greater than once a month? | CREATE TABLE Trains (train_id INT,region VARCHAR(20),maintenance_frequency INT); INSERT INTO Trains (train_id,region,maintenance_frequency) VALUES (101,'Central',30),(102,'Eastside',60),(103,'Central',45); | SELECT COUNT(*) FROM Trains WHERE region = 'Central' AND maintenance_frequency > 30; |
Update the average donation amount for the Red Cross organization in the Southeast region. | CREATE TABLE organizations (id INT,name TEXT,region TEXT,avg_donation DECIMAL(10,2)); INSERT INTO organizations (id,name,region,avg_donation) VALUES (1,'Habitat for Humanity','Southeast',150.00),(2,'Red Cross','Southeast',125.00),(3,'UNICEF','Northeast',200.00); | UPDATE organizations SET avg_donation = 135.00 WHERE name = 'Red Cross' AND region = 'Southeast'; |
Delete companies with no electric vehicles in the ElectricVehicles table. | CREATE TABLE ElectricVehicles (id INT,company VARCHAR(20),vehicle_type VARCHAR(20),num_vehicles INT); INSERT INTO ElectricVehicles (id,company,vehicle_type,num_vehicles) VALUES (1,'Tesla','EV',1500000),(2,'Nissan','Leaf',500000),(3,'Chevrolet','Bolt',300000),(4,'Ford','No EV',0); | DELETE FROM ElectricVehicles WHERE company NOT IN (SELECT company FROM ElectricVehicles WHERE vehicle_type = 'EV'); |
Which donors have made a donation in every quarter of the current year? | CREATE TABLE donations (id INT,donor_id INT,amount DECIMAL(10,2),donation_date DATE); INSERT INTO donations (id,donor_id,amount,donation_date) VALUES (1,101,500.00,'2022-01-01'),(2,102,300.00,'2022-02-15'),(3,101,600.00,'2022-04-01'); | SELECT donor_id FROM (SELECT donor_id, COUNT(DISTINCT quarter) AS quarters FROM (SELECT donor_id, YEAR(donation_date) AS year, QUARTER(donation_date) AS quarter FROM donations WHERE donation_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 1 YEAR) AND CURDATE()) AS subquery GROUP BY donor_id) AS subquery2 WHERE quarters = 4; |
What is the total amount of energy consumed by mining operations in each country? | CREATE TABLE mining_operations (operation_id INT,operation_name TEXT,country TEXT,energy_consumption FLOAT); INSERT INTO mining_operations (operation_id,operation_name,country,energy_consumption) VALUES (1,'Dalny Mine','Russia',30000),(2,'Grasberg Mine','Indonesia',40000),(3,'Chuquicamata Mine','Chile',50000); | SELECT country, SUM(energy_consumption) AS total_energy_consumption FROM mining_operations GROUP BY country; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.