instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the average price of menu items in each category? | CREATE TABLE menu_items (item_id INT,item_name VARCHAR(50),category VARCHAR(20),price DECIMAL(5,2)); INSERT INTO menu_items (item_id,item_name,category,price) VALUES (1,'Cheeseburger','Main',8.99),(2,'Fried Chicken','Main',9.99),(3,'Veggie Burger','Main',7.99),(4,'Fries','Side',2.99),(5,'Salad','Side',4.99); | SELECT category, AVG(price) AS avg_price FROM menu_items GROUP BY category; |
Who are the astronauts who have been on the most space missions, and how many missions have they been on? | CREATE TABLE Astronauts (AstronautID INT,NumberOfMissions INT); | SELECT AstronautID, NumberOfMissions FROM (SELECT AstronautID, COUNT(*) AS NumberOfMissions FROM SpaceMissions GROUP BY AstronautID) subquery ORDER BY NumberOfMissions DESC LIMIT 1; |
What are the top 5 countries with the highest number of players who reached level 10 in game 'A'? | CREATE TABLE GameA (player_id INT,country VARCHAR(20),level INT); INSERT INTO GameA (player_id,country,level) VALUES (1,'US',10),(2,'CA',9),(3,'MX',10),(4,'US',8),(5,'CA',10); | SELECT country, COUNT(*) as player_count FROM GameA WHERE level >= 10 GROUP BY country ORDER BY player_count DESC LIMIT 5; |
What is the maximum number of medical appointments in rural areas of France in the past month? | CREATE TABLE Appointments (AppointmentID int,Date date,Location varchar(50),Type varchar(50)); INSERT INTO Appointments (AppointmentID,Date,Location,Type) VALUES (1,'2021-12-01','Rural France','Checkup'); | SELECT MAX(COUNT(*)) FROM Appointments WHERE Location LIKE '%Rural France%' AND Date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY Date; |
What is the ratio of hospital beds to doctors in urban and rural areas? | CREATE TABLE hospitals (id INT,name TEXT,location TEXT,num_beds INT); INSERT INTO hospitals (id,name,location,num_beds) VALUES (1,'General Hospital','City A',500),(2,'Rural Hospital','Rural Area A',100); CREATE TABLE clinics (id INT,name TEXT,location TEXT,num_doctors INT,num_beds INT); INSERT INTO clinics (id,name,location,num_doctors,num_beds) VALUES (1,'Downtown Clinic','City A',10,0),(2,'Rural Clinic','Rural Area A',5,25); | SELECT location, h.num_beds / c.num_doctors AS bed_to_doctor_ratio FROM hospitals h JOIN clinics c ON h.location = c.location; |
How many sustainable fashion items were sold in the 'fashion_trend_data' table? | CREATE TABLE fashion_trend_data (id INT,product_name VARCHAR(30),is_sustainable BOOLEAN); INSERT INTO fashion_trend_data (id,product_name,is_sustainable) VALUES (1,'T-shirt',true),(2,'Jeans',false); | SELECT COUNT(*) FROM fashion_trend_data WHERE is_sustainable = true; |
Get top 3 users with the most posts | CREATE TABLE users (id INT,name TEXT,post_count INT); INSERT INTO users (id,name,post_count) VALUES (1,'Fiona',50); INSERT INTO users (id,name,post_count) VALUES (2,'George',200); INSERT INTO users (id,name,post_count) VALUES (3,'Hannah',150); INSERT INTO users (id,name,post_count) VALUES (4,'Ivan',250); | SELECT id, name, post_count, RANK() OVER (ORDER BY post_count DESC) as post_rank FROM users WHERE post_rank <= 3; |
Which state has the highest energy efficiency rating for commercial buildings? | CREATE TABLE commercial_buildings (building_id INT,building_name TEXT,state TEXT,energy_efficiency_rating FLOAT); INSERT INTO commercial_buildings (building_id,building_name,state,energy_efficiency_rating) VALUES (1,'Commercial Building A','New York',85.5),(2,'Commercial Building B','California',82.7),(3,'Commercial Building C','Texas',79.6); | SELECT state, MAX(energy_efficiency_rating) AS max_rating FROM commercial_buildings WHERE building_type = 'Commercial' GROUP BY state ORDER BY max_rating DESC LIMIT 1; |
What is the minimum size of sustainable urbanism projects in Tokyo? | CREATE TABLE sustainable_urbanism (size INT,city VARCHAR(20)); | SELECT MIN(size) FROM sustainable_urbanism WHERE city = 'Tokyo'; |
What is the average water temperature in the Mediterranean Sea? | CREATE TABLE location (location_id INT,location_name TEXT); INSERT INTO location (location_id,location_name) VALUES (1,'Mediterranean Sea'); CREATE TABLE temperature (temperature_id INT,location_id INT,water_temp FLOAT); INSERT INTO temperature (temperature_id,location_id,water_temp) VALUES (1,1,18.3),(2,1,18.2),(3,1,18.1),(4,1,18.4),(5,1,18.5); | SELECT AVG(water_temp) FROM temperature WHERE location_id = (SELECT location_id FROM location WHERE location_name = 'Mediterranean Sea'); |
What is the average quantity of sustainable fabric sourced from Africa? | CREATE TABLE sustainable_fabric (id INT,fabric_type VARCHAR(20),quantity INT,country VARCHAR(20)); INSERT INTO sustainable_fabric (id,fabric_type,quantity,country) VALUES (1,'organic_cotton',500,'Egypt'); INSERT INTO sustainable_fabric (id,fabric_type,quantity,country) VALUES (2,'recycled_polyester',300,'South Africa'); | SELECT AVG(quantity) FROM sustainable_fabric WHERE country IN ('Egypt', 'South Africa', 'Tunisia'); |
What is the total budget for peacekeeping operations for each region? | CREATE TABLE peacekeeping_operations (id INT,region VARCHAR(255),operation VARCHAR(255),budget DECIMAL(10,2)); | SELECT region, SUM(budget) FROM peacekeeping_operations GROUP BY region; |
What is the total coverage amount and number of policies for policies in the state of 'CA'? | CREATE TABLE policies (policy_number INT,policy_type VARCHAR(50),coverage_amount INT,state VARCHAR(2)); INSERT INTO policies (policy_number,policy_type,coverage_amount,state) VALUES (12345,'Auto',50000,'TX'); INSERT INTO policies (policy_number,policy_type,coverage_amount,state) VALUES (67890,'Home',300000,'CA'); | SELECT SUM(coverage_amount) as total_coverage_amount, COUNT(*) as number_of_policies FROM policies WHERE state = 'CA'; |
How many ocean health monitoring stations are there in Spain and the United Kingdom? | CREATE TABLE spain_stations (id INT,station_number INT);CREATE TABLE uk_stations (id INT,station_number INT);INSERT INTO spain_stations (id,station_number) VALUES (1,5001),(2,5002);INSERT INTO uk_stations (id,station_number) VALUES (1,6001),(2,6002); | SELECT COUNT(*) FROM spain_stations UNION SELECT COUNT(*) FROM uk_stations |
What is the maximum bridge weight limit in 'BridgeWeights' table? | CREATE TABLE BridgeWeights(bridge_id INT,max_weight FLOAT); INSERT INTO BridgeWeights VALUES(1,120.0),(2,150.0),(3,180.0),(4,100.0),(5,200.0),(6,130.0); | SELECT MAX(max_weight) FROM BridgeWeights; |
Insert new strain 'Purple Haze' into the Strains table with a StrainID of 105. | CREATE TABLE Strains (StrainID INT,StrainName VARCHAR(50)); | INSERT INTO Strains (StrainID, StrainName) VALUES (105, 'Purple Haze'); |
Generate a view 'contract_value_trends' to display the total value of defense contracts awarded by quarter | CREATE TABLE defense_contracts (id INT PRIMARY KEY,department VARCHAR(50),contract_date DATE,contract_value FLOAT);INSERT INTO defense_contracts (id,department,contract_date,contract_value) VALUES (1,'Army','2018-01-01',1000000),(2,'Navy','2018-01-15',2000000),(3,'Air Force','2018-02-01',1500000); | CREATE VIEW contract_value_trends AS SELECT DATE_TRUNC('quarter', contract_date) as quarter, department, SUM(contract_value) as total_contract_value FROM defense_contracts GROUP BY quarter, department; |
Find the top 3 most active users by post count in the 'music' category since 2021-06-01. | CREATE TABLE users (id INT,username TEXT); CREATE TABLE posts (user_id INT,category TEXT,timestamp TIMESTAMP); | SELECT u.username, COUNT(p.user_id) as post_count FROM users u JOIN posts p ON u.id = p.user_id WHERE p.category = 'music' AND p.timestamp >= '2021-06-01' GROUP BY u.username ORDER BY post_count DESC LIMIT 3; |
What is the total calories burned for members from India? | CREATE TABLE member_workouts (member_id INT,country VARCHAR(50),calories_burned INT); INSERT INTO member_workouts (member_id,country,calories_burned) VALUES (1,'USA',300),(2,'Canada',400),(3,'India',500),(4,'Brazil',600),(5,'Argentina',700); | SELECT SUM(calories_burned) FROM member_workouts WHERE country = 'India'; |
Insert a new record into the menu_item table with the following data: item_id = 205, item_name = 'Tofu Stir Fry', category = 'Entrees', price = 14.99 | CREATE TABLE menu_item (item_id INT,item_name VARCHAR(50),category VARCHAR(20),price DECIMAL(5,2)); | INSERT INTO menu_item (item_id, item_name, category, price) VALUES (205, 'Tofu Stir Fry', 'Entrees', 14.99); |
What is the total revenue generated by small freight forwarding companies in the first half of the year? | CREATE TABLE revenue_data (revenue_id INT,company_id INT,revenue INT,revenue_date DATE); INSERT INTO revenue_data (revenue_id,company_id,revenue,revenue_date) VALUES (1,1,10000,'2022-01-01'),(2,2,8000,'2022-02-01'),(3,3,12000,'2022-03-01'),(4,4,15000,'2022-04-01'),(5,5,9000,'2022-05-01'),(6,6,7000,'2022-06-01'); CREATE TABLE company_data (company_id INT,company_size VARCHAR(50)); INSERT INTO company_data (company_id,company_size) VALUES (1,'Small'),(2,'Medium'),(3,'Large'),(4,'Small'),(5,'Medium'),(6,'Small'); | SELECT SUM(revenue) FROM revenue_data JOIN company_data ON revenue_data.company_id = company_data.company_id WHERE company_data.company_size = 'Small' AND revenue_date BETWEEN '2022-01-01' AND '2022-06-30'; |
What are the names of the top 5 communities with the most projects in the 'community_projects' table? | CREATE TABLE community_projects (community_id INT,community_name TEXT,project_count INT); | SELECT community_name, project_count FROM community_projects ORDER BY project_count DESC LIMIT 5; |
How many pollution control initiatives have been conducted in the Pacific Ocean? | CREATE TABLE pollution_control (id INT,name VARCHAR(255),ocean VARCHAR(255),year INT); INSERT INTO pollution_control (id,name,ocean,year) VALUES (1,'Project Clean Pacific','Pacific Ocean',2010),(2,'Ocean Wave Energy','Pacific Ocean',2015); | SELECT COUNT(*) FROM pollution_control WHERE ocean = 'Pacific Ocean'; |
Show canals with a length greater than 50 miles and less than 100 miles. | CREATE TABLE Canals (name TEXT,length FLOAT,location TEXT); | SELECT name FROM Canals WHERE length > 50 AND length < 100; |
What is the total budget allocated for infrastructure in the city of Phoenix, including all projects, for the fiscal year 2025? | CREATE TABLE city_budget (city VARCHAR(20),project VARCHAR(20),budget INT); INSERT INTO city_budget (city,project,budget) VALUES ('Phoenix','Road Repair',1000000); | SELECT SUM(budget) FROM city_budget WHERE city = 'Phoenix' AND project LIKE '%Infrastructure%' AND fiscal_year = 2025; |
List all genetic research data tables that have a 'sample_result' column. | CREATE SCHEMA if not exists genetics;CREATE TABLE if not exists genetics.research_data_1 (id INT PRIMARY KEY,sample_id VARCHAR(50),sample_date DATE,sample_result INT);CREATE TABLE if not exists genetics.research_data_2 (id INT PRIMARY KEY,sample_id VARCHAR(50),sample_date DATE);CREATE TABLE if not exists genetics.research_data_3 (id INT PRIMARY KEY,sample_id VARCHAR(50),sample_time TIME); | SELECT table_name FROM information_schema.columns WHERE table_schema = 'genetics' AND column_name = 'sample_result'; |
How many education supply distributions were made in Nigeria in the last month? | CREATE TABLE education_supplies (id INT,location VARCHAR(255),distribution_date DATE); INSERT INTO education_supplies (id,location,distribution_date) VALUES (1,'Nigeria','2022-04-15'),(2,'Syria','2022-04-14'),(3,'Nigeria','2022-04-16'); | SELECT COUNT(*) FROM education_supplies WHERE location = 'Nigeria' AND distribution_date >= DATEADD(day, -30, GETDATE()); |
What is the total funding for art programs from government grants? | CREATE TABLE Funding (funding_id INT,source VARCHAR(255),amount DECIMAL(10,2)); CREATE TABLE Programs (program_id INT,name VARCHAR(255),funding_source VARCHAR(255)); | SELECT SUM(amount) FROM Funding F JOIN Programs P ON F.funding_id = P.funding_id WHERE F.source = 'Government Grant' AND P.name LIKE '%Art%'; |
Update the cargo weight of the vessel 'VesselB' to 800 in the table 'vessels'. | CREATE TABLE vessels (id INT,name TEXT,port_id INT,speed FLOAT,cargo_weight INT); INSERT INTO vessels (id,name,port_id,speed,cargo_weight) VALUES (1,'VesselA',1,20.5,400),(2,'VesselB',1,21.3,600),(3,'VesselC',2,25.0,700); | UPDATE vessels SET cargo_weight = 800 WHERE name = 'VesselB'; |
What is the maximum area of marine protected areas established before 1985, grouped by location and excluding locations with only one protected area? | CREATE TABLE marine_protected_areas (id INT PRIMARY KEY,name VARCHAR(255),year INT,location VARCHAR(255),area REAL); INSERT INTO marine_protected_areas (id,name,year,location,area) VALUES (1,'Great Barrier Reef Marine Park',1975,'Pacific Ocean',344400),(2,'Galapagos Marine Reserve',1998,'Pacific Ocean',133000),(3,'Sargasso Sea Protection Area',1982,'Atlantic Ocean',5000000); | SELECT location, MAX(area) FROM marine_protected_areas WHERE year < 1985 GROUP BY location HAVING COUNT(*) > 1; |
What is the total number of agricultural innovation projects led by women in Rwanda? | CREATE TABLE agricultural_projects (id INT,name TEXT,location TEXT,led_by TEXT); INSERT INTO agricultural_projects (id,name,location,led_by) VALUES (1,'New Crops Research','Rwanda','Women'),(2,'Livestock Breeding','Uganda','Men'),(3,'Organic Farming','Rwanda','Men'); | SELECT COUNT(*) FROM agricultural_projects WHERE location = 'Rwanda' AND led_by = 'Women'; |
Calculate the average amount of funding per economic diversification project from the "diversification_funding" table | CREATE TABLE diversification_funding (id INT,project_id INT,funding DECIMAL(10,2)); | SELECT AVG(funding) FROM diversification_funding; |
Find the number of water conservation initiatives implemented in 'Hanoi' for each year from 2015 to 2020 | CREATE TABLE conservation_initiatives (region VARCHAR(50),date DATE,initiative VARCHAR(50)); INSERT INTO conservation_initiatives (region,date,initiative) VALUES ('Hanoi','2015-01-01','Rainwater harvesting'),('Hanoi','2016-01-01','Greywater reuse'),('Hanoi','2017-01-01','Smart irrigation'),('Hanoi','2018-01-01','Leak detection'),('Hanoi','2019-01-01','Water-efficient appliances'); | SELECT YEAR(date) AS year, COUNT(*) FROM conservation_initiatives WHERE region = 'Hanoi' AND date BETWEEN '2015-01-01' AND '2020-12-31' GROUP BY year; |
Get the number of cases handled per attorney | CREATE TABLE attorneys (id INT,name VARCHAR(50),cases_handled INT,region VARCHAR(50),billable_rate DECIMAL(10,2)); INSERT INTO attorneys (id,name,cases_handled,region,billable_rate) VALUES (1,'John Lee',40,'Northeast',200.00); INSERT INTO attorneys (id,name,cases_handled,region,billable_rate) VALUES (2,'Jane Doe',50,'Southwest',250.00); | SELECT name, cases_handled FROM attorneys; |
Identify patients who switched treatments in the US between 2015 and 2017? | CREATE TABLE patients (patient_id INT,age INT,gender TEXT,country TEXT); INSERT INTO patients (patient_id,age,gender,country) VALUES (1,35,'Male','USA'); INSERT INTO patients (patient_id,age,gender,country) VALUES (2,42,'Female','USA'); CREATE TABLE treatments (treatment_id INT,patient_id INT,treatment_type TEXT,treatment_date DATE); INSERT INTO treatments (treatment_id,patient_id,treatment_type,treatment_date) VALUES (1,1,'CBT','2015-06-01'); INSERT INTO treatments (treatment_id,patient_id,treatment_type,treatment_date) VALUES (2,2,'CBT','2015-08-15'); | SELECT patient_id, MIN(treatment_date) AS first_treatment_date, MAX(treatment_date) AS last_treatment_date FROM treatments WHERE country = 'USA' AND treatment_date BETWEEN '2015-01-01' AND '2017-12-31' GROUP BY patient_id HAVING COUNT(DISTINCT treatment_type) > 1; |
What is the number of investigative articles published by the "Daily Planet" that received over 10,000 views? | CREATE TABLE articles (id INT,title VARCHAR(50),views INT,source VARCHAR(50)); INSERT INTO articles (id,title,views,source) VALUES (1,'Article 1',5000,'Daily Planet'),(2,'Article 2',15000,'Daily Planet'); CREATE TABLE categories (id INT,article_id INT,category VARCHAR(50)); INSERT INTO categories (id,article_id,category) VALUES (1,1,'investigative'),(2,2,'investigative'); | SELECT COUNT(articles.id) FROM articles INNER JOIN categories ON articles.id = categories.article_id WHERE articles.source = 'Daily Planet' AND articles.views > 10000 AND categories.category = 'investigative'; |
Update the title of a publication in the "publications" table | CREATE TABLE publications (id INT PRIMARY KEY,title VARCHAR(100),author VARCHAR(50),journal VARCHAR(50),publication_date DATE); | WITH updated_publication AS (UPDATE publications SET title = 'Revolutionary Quantum Computing Advancement' WHERE id = 1 RETURNING *) SELECT * FROM updated_publication; |
Update the capacity of Hospital D in Louisiana to 100 beds. | CREATE TABLE hospitals (id INT,name TEXT,location TEXT,capacity INT); INSERT INTO hospitals (id,name,location,capacity) VALUES (1,'Hospital A','Rural Texas',50); INSERT INTO hospitals (id,name,location,capacity) VALUES (4,'Hospital D','Rural Louisiana',75); | UPDATE hospitals SET capacity = 100 WHERE name = 'Hospital D' AND location = 'Rural Louisiana'; |
What is the minimum gas fee for Ethereum smart contracts involved in cross-chain communication? | CREATE TABLE ethereum_smart_contracts (id INT,gas_fees DECIMAL(10,2),cross_chain_communication BOOLEAN); INSERT INTO ethereum_smart_contracts (id,gas_fees,cross_chain_communication) VALUES (1,30,TRUE); | SELECT MIN(gas_fees) FROM ethereum_smart_contracts WHERE cross_chain_communication = TRUE; |
What is the total revenue for all Italian restaurants? | CREATE TABLE Restaurants (id INT,name VARCHAR,category VARCHAR,revenue INT); INSERT INTO Restaurants (id,name,category,revenue) VALUES (1,'Bistro','French',500000); INSERT INTO Restaurants (id,name,category,revenue) VALUES (2,'Pizzeria','Italian',600000); | SELECT SUM(revenue) FROM Restaurants WHERE category = 'Italian'; |
What is the total mineral extraction for each mining company in Brazil, by year, for the last 3 years? | CREATE TABLE MiningCompanyExtraction (year INT,company TEXT,country TEXT,mineral TEXT,quantity INT); INSERT INTO MiningCompanyExtraction (year,company,country,mineral,quantity) VALUES (2019,'ABC Mining','Brazil','Gold',10000),(2020,'ABC Mining','Brazil','Gold',12000),(2021,'ABC Mining','Brazil','Gold',15000),(2019,'XYZ Mining','Brazil','Silver',12000),(2020,'XYZ Mining','Brazil','Silver',14000),(2021,'XYZ Mining','Brazil','Silver',16000); | SELECT context.year, context.company, SUM(context.quantity) as total_mineral_extraction FROM MiningCompanyExtraction context WHERE context.country = 'Brazil' AND context.year BETWEEN 2019 AND 2021 GROUP BY context.year, context.company; |
What is the total number of doctors in each region in Australia's rural healthcare system? | CREATE SCHEMA if not exists australia_rural_healthcare; USE australia_rural_healthcare; CREATE TABLE Doctors (id INT,name VARCHAR(100),hospital_id INT,specialty VARCHAR(50),region VARCHAR(50)); INSERT INTO Doctors VALUES (1,'Dr. Smith',1,'General Practitioner','New South Wales'),(2,'Dr. Johnson',1,'General Practitioner','New South Wales'),(3,'Dr. Brown',2,'Specialist','Queensland'),(4,'Dr. Davis',3,'General Practitioner','Victoria'),(5,'Dr. Patel',3,'Specialist','Victoria'); | SELECT region, COUNT(*) FROM Doctors GROUP BY region; |
What is the average amount of Shariah-compliant financing for clients in each country? | CREATE TABLE shariah_financing(client_id INT,country VARCHAR(25),amount FLOAT);INSERT INTO shariah_financing(client_id,country,amount) VALUES (1,'Malaysia',5000),(2,'UAE',7000),(3,'Indonesia',6000),(4,'Saudi Arabia',8000),(5,'Malaysia',9000),(6,'UAE',10000); | SELECT country, AVG(amount) as avg_financing FROM shariah_financing GROUP BY country; |
Insert a new ad campaign with a start date of 2023-03-01 and an end date of 2023-03-15 | CREATE TABLE ad_campaigns (id INT,name VARCHAR(255),start_date DATE,end_date DATE); | INSERT INTO ad_campaigns (id, name, start_date, end_date) VALUES (1, 'Spring Sale', '2023-03-01', '2023-03-15'); |
What is the average mental health score of students who have participated in open pedagogy projects? | CREATE TABLE open_pedagogy_projects (student_id INT,mental_health_score FLOAT); INSERT INTO open_pedagogy_projects (student_id,mental_health_score) VALUES (1,70.5),(2,85.2),(3,68.1); | SELECT AVG(mental_health_score) FROM open_pedagogy_projects; |
What is the total quantity of each product in the Sydney warehouse? | CREATE TABLE Warehouses (WarehouseID int,WarehouseName varchar(255),City varchar(255),Country varchar(255)); INSERT INTO Warehouses (WarehouseID,WarehouseName,City,Country) VALUES (4,'Sydney Warehouse','Sydney','Australia'); CREATE TABLE Inventory (InventoryID int,WarehouseID int,ProductName varchar(255),Quantity int); INSERT INTO Inventory (InventoryID,WarehouseID,ProductName,Quantity) VALUES (4,4,'Pears',100); | SELECT ProductName, SUM(Quantity) AS TotalQuantity FROM Inventory WHERE WarehouseID = 4 GROUP BY ProductName; |
Insert a new row into the 'virtual_tour_stats' table with hotel_id 123, view_date '2022-01-01', and view_duration 120 | CREATE TABLE virtual_tour_stats (hotel_id INT,view_date DATE,view_duration INT); | INSERT INTO virtual_tour_stats (hotel_id, view_date, view_duration) VALUES (123, '2022-01-01', 120); |
List the collective bargaining agreements for the 'Construction Workers Union' and 'Teachers Union'. | CREATE TABLE CollectiveBargaining (CBAID INT,UnionID INT,AgreementDate DATE); INSERT INTO CollectiveBargaining (CBAID,UnionID,AgreementDate) VALUES (1,1,'2020-01-01'),(2,2,'2019-06-15'),(3,3,'2018-09-01'); | SELECT Unions.UnionName, CollectiveBargaining.AgreementDate FROM Unions JOIN CollectiveBargaining ON Unions.UnionID = CollectiveBargaining.UnionID WHERE Unions.UnionName IN ('Construction Workers Union', 'Teachers Union'); |
What is the average temperature change in the Arctic per decade? | CREATE TABLE weather (year INT,avg_temp FLOAT); INSERT INTO weather (year,avg_temp) VALUES | SELECT AVG(avg_temp) FROM weather WHERE year BETWEEN 1950 AND 2020 GROUP BY (year - year % 10) / 10 HAVING COUNT(*) > 10; |
What are the common types of security incidents across all regions, according to our Incident Analysis database? | CREATE TABLE IncidentAnalysis (id INT,incident_type VARCHAR(50),region VARCHAR(50)); INSERT INTO IncidentAnalysis (id,incident_type,region) VALUES (1,'Phishing','APAC'),(2,'Malware','EMEA'); | SELECT incident_type FROM IncidentAnalysis GROUP BY incident_type HAVING COUNT(DISTINCT region) = (SELECT COUNT(DISTINCT region) FROM IncidentAnalysis); |
List the policy areas and their respective feedback scores in India in 2017. | CREATE SCHEMA in_schema;CREATE TABLE in_schema.policy_areas (area_id INT,area_name VARCHAR(20),feedback_score INT);INSERT INTO in_schema.policy_areas (area_id,area_name,feedback_score) VALUES (1,'Healthcare',75),(2,'Education',85),(3,'Transportation',80),(4,'Housing',70); | SELECT area_name, feedback_score FROM in_schema.policy_areas; |
How many permits were issued per month in 2019 and 2020? | CREATE TABLE Month (id INT,name VARCHAR(10)); CREATE TABLE Permit (id INT,issue_date DATE); | SELECT Month.name, YEAR(Permit.issue_date) AS year, COUNT(Permit.id) AS permits_issued FROM Month INNER JOIN Permit ON Month.id = MONTH(Permit.issue_date) WHERE YEAR(Permit.issue_date) IN (2019, 2020) GROUP BY Month.name, YEAR(Permit.issue_date); |
What is the average yield of corn for each state in 2020, sorted by the highest yield? | CREATE TABLE states (state_name TEXT,state_abbr TEXT); INSERT INTO states (state_name,state_abbr) VALUES ('Alabama','AL'),('Alaska','AK'); CREATE TABLE crops (crop_name TEXT,state TEXT,yield INTEGER,year INTEGER); INSERT INTO crops (crop_name,state,yield,year) VALUES ('Corn','AL',120,2020),('Corn','AK',150,2020); | SELECT state, AVG(yield) FROM crops JOIN states ON crops.state = states.state_abbr WHERE crop_name = 'Corn' AND year = 2020 GROUP BY state ORDER BY AVG(yield) DESC; |
What is the total number of packages shipped by each warehouse? | CREATE TABLE warehouses (warehouse_id INT,warehouse_name VARCHAR(50)); INSERT INTO warehouses (warehouse_id,warehouse_name) VALUES (1,'New York'),(2,'Chicago'),(3,'Los Angeles'); | SELECT warehouse_id, COUNT(*) FROM packages GROUP BY warehouse_id; |
What is the average water usage for households in CityA in 2019? | CREATE TABLE WaterUsage (Id INT,HouseholdId INT,Month INT,Year INT,Usage FLOAT); INSERT INTO WaterUsage (Id,HouseholdId,Month,Year,Usage) VALUES (1,101,1,2019,12.5); INSERT INTO WaterUsage (Id,HouseholdId,Month,Year,Usage) VALUES (2,101,2,2019,15.2); INSERT INTO WaterUsage (Id,HouseholdId,Month,Year,Usage) VALUES (3,102,1,2019,18.3); INSERT INTO WaterUsage (Id,HouseholdId,Month,Year,Usage) VALUES (4,102,2,2019,19.8); | SELECT AVG(Usage) FROM WaterUsage WHERE HouseholdId IN (SELECT HouseholdId FROM WaterUsage WHERE Year = 2019 AND Location = 'CityA' GROUP BY HouseholdId) AND Year = 2019; |
How many people have been vaccinated against measles in the African region in the last 5 years? | CREATE TABLE vaccinations (vaccination_id INT,patient_id INT,vaccine VARCHAR(20),date DATE); INSERT INTO vaccinations (vaccination_id,patient_id,vaccine,date) VALUES (1,3,'Measles','2018-01-01'); INSERT INTO vaccinations (vaccination_id,patient_id,vaccine,date) VALUES (2,4,'Influenza','2020-02-01'); | SELECT COUNT(*) FROM vaccinations WHERE vaccine = 'Measles' AND date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR) AND CURRENT_DATE AND region = 'African' |
What is the average disaster preparedness score in Downtown? | CREATE TABLE DisasterPreparedness (id INT,district VARCHAR(255),preparedness_score INT); INSERT INTO DisasterPreparedness (id,district,preparedness_score) VALUES (3,'Downtown',88); | SELECT district, AVG(preparedness_score) as avg_preparedness FROM DisasterPreparedness WHERE district = 'Downtown' GROUP BY district; |
How many environmental impact assessments have been conducted in 'Africa'? | CREATE TABLE regions (id INT,name TEXT); INSERT INTO regions (id,name) VALUES (1,'North America'),(2,'South America'),(3,'Europe'),(4,'Middle East'),(5,'Asia'),(6,'Africa'); CREATE TABLE assessments (id INT,region_id INT,type TEXT); INSERT INTO assessments (id,region_id,type) VALUES (1,1,'Safety'),(2,4,'Environmental'),(3,3,'Quality'),(4,5,'Sustainability'),(5,4,'Environmental'),(6,6,'Environmental'); | SELECT COUNT(assessments.id) FROM assessments JOIN regions ON assessments.region_id = regions.id WHERE regions.name = 'Africa'; |
What is the average temperature per day in the 'temperature_readings' table? | CREATE TABLE temperature_readings (reading_date DATE,temperature FLOAT); | SELECT reading_date, AVG(temperature) FROM temperature_readings GROUP BY reading_date; |
What is the total revenue by platform? | CREATE TABLE ad_data (platform VARCHAR(20),revenue NUMERIC(10,2));INSERT INTO ad_data VALUES ('FB',1000),('IG',2000),('TW',3000),('SN',4000),('LI',5000); | SELECT platform, SUM(revenue) FROM ad_data GROUP BY platform; |
What is the average satisfaction score for models trained on dataset A, for all regions, excluding North America? | CREATE TABLE models (id INT,dataset VARCHAR(20),satisfaction FLOAT);CREATE TABLE regions (id INT,name VARCHAR(20)); INSERT INTO models VALUES (1,'datasetA',4.3),(2,'datasetA',4.5),(3,'datasetB',3.9); INSERT INTO regions VALUES (1,'North America'),(2,'Europe'),(3,'Asia'),(4,'South America'); | SELECT AVG(m.satisfaction) FROM models m JOIN regions r ON TRUE WHERE m.dataset = 'datasetA' AND r.name != 'North America'; |
How many heritage sites are registered in the 'heritage' schema? | CREATE TABLE heritage_sites (id INT,name VARCHAR(255),type VARCHAR(255)); INSERT INTO heritage_sites (id,name,type) VALUES (1,'Taj Mahal','Architecture'),(2,'Great Barrier Reef','Natural'); | SELECT COUNT(*) FROM heritage.heritage_sites; |
What is the average amount of minerals extracted per day for each mining site in the state of Queensland, Australia, for the year 2018, and what is the overall average for all mining sites in the state? | CREATE TABLE mining_sites (site_id INT,site_name TEXT,state TEXT,country TEXT);CREATE TABLE mineral_extraction (extraction_id INT,site_id INT,extraction_day DATE,tons_extracted INT); | SELECT s.site_name, AVG(me.tons_extracted / DATEDIFF('2018-12-31', me.extraction_day)) AS avg_tons_extracted_per_day FROM mining_sites s INNER JOIN mineral_extraction me ON s.site_id = me.site_id WHERE s.state = 'Queensland' AND me.extraction_day BETWEEN '2018-01-01' AND '2018-12-31' GROUP BY s.site_id, s.site_name;SELECT 'Queensland Overall Average' AS site_name, AVG(me.tons_extracted / DATEDIFF('2018-12-31', me.extraction_day)) AS avg_tons_extracted_per_day FROM mining_sites s INNER JOIN mineral_extraction me ON s.site_id = me.site_id WHERE s.state = 'Queensland' AND me.extraction_day BETWEEN '2018-01-01' AND '2018-12-31'; |
How many safety incidents were reported for each vessel type in the Arctic region in the last year? | CREATE TABLE safety_incidents (id INT,vessel_id INT,vessel_type VARCHAR(255),incident_date DATE,region VARCHAR(255)); INSERT INTO safety_incidents (id,vessel_id,vessel_type,incident_date,region) VALUES (7,22,'Icebreaker','2022-01-15','Arctic'); INSERT INTO safety_incidents (id,vessel_id,vessel_type,incident_date,region) VALUES (8,23,'Fishing','2022-02-18','Arctic'); | SELECT vessel_type, COUNT(*) as safety_incidents_count FROM safety_incidents WHERE region = 'Arctic' AND incident_date BETWEEN '2021-01-01' AND '2022-01-01' GROUP BY vessel_type; |
Which military equipment type had the greatest cost increase in maintenance from 2018 to 2019? | CREATE TABLE IF NOT EXISTS military_equipment (equipment_id INT,equipment_type VARCHAR(50),acquisition_date DATE,cost FLOAT,last_maintenance_date DATE); | SELECT equipment_type, (MAX(cost) - MIN(cost)) as cost_increase FROM military_equipment WHERE last_maintenance_date BETWEEN '2018-01-01' AND '2019-12-31' GROUP BY equipment_type ORDER BY cost_increase DESC FETCH FIRST 1 ROW ONLY; |
Update status to 'inactive' for vessels that have not been maintained in 9 months | CREATE SCHEMA if not exists ocean_shipping;CREATE TABLE if not exists ocean_shipping.vessels (id INT,name VARCHAR(255),status VARCHAR(255),last_maintenance DATE); | UPDATE ocean_shipping.vessels SET status = 'inactive' WHERE last_maintenance < DATE_SUB(CURRENT_DATE, INTERVAL 9 MONTH); |
What is the total salary cost for the Sustainability department? | CREATE TABLE Departments (id INT,name VARCHAR(50),budget DECIMAL(10,2)); | SELECT SUM(d.budget) FROM Departments d JOIN Employees e ON d.name = e.department WHERE d.name = 'Sustainability'; |
What is the average length of all bridges in the province of Ontario? | CREATE TABLE Bridges (id INT,name TEXT,province TEXT,length FLOAT); INSERT INTO Bridges (id,name,province,length) VALUES (1,'Bloor Street Viaduct','Ontario',496.0); INSERT INTO Bridges (id,name,province,length) VALUES (2,'Prince Edward Viaduct','Ontario',476.0); | SELECT AVG(length) FROM Bridges WHERE province = 'Ontario' |
How many climate adaptation projects were completed in Latin America and the Caribbean between 2015 and 2019? | CREATE TABLE climate_adaptation (region VARCHAR(50),year INT,project_status VARCHAR(20)); INSERT INTO climate_adaptation (region,year,project_status) VALUES ('Latin America',2015,'completed'),('Caribbean',2015,'completed'),('Latin America',2016,'completed'),('Caribbean',2016,'completed'),('Latin America',2017,'completed'),('Caribbean',2017,'completed'),('Latin America',2018,'completed'),('Caribbean',2018,'completed'),('Latin America',2019,'completed'),('Caribbean',2019,'completed'); | SELECT COUNT(*) FROM climate_adaptation WHERE region IN ('Latin America', 'Caribbean') AND year BETWEEN 2015 AND 2019 AND project_status = 'completed'; |
List the names of players who have played in esports events, in the last 3 months, in any country. | CREATE TABLE players (id INT,name VARCHAR(50),age INT); INSERT INTO players (id,name,age) VALUES (1,'John Doe',25); INSERT INTO players (id,name,age) VALUES (2,'Jane Smith',30); CREATE TABLE events (id INT,name VARCHAR(50),date DATE); INSERT INTO events (id,name,date) VALUES (1,'GameCon','2022-04-01'); INSERT INTO events (id,name,date) VALUES (2,'TechFest','2022-05-15'); | SELECT players.name FROM players INNER JOIN events ON players.id = events.id WHERE events.date >= DATEADD(month, -3, GETDATE()); |
What is the percentage of transactions that were declined for each salesperson? | CREATE TABLE transactions (transaction_id INT,salesperson_id INT,amount DECIMAL(10,2),status VARCHAR(50)); INSERT INTO transactions (transaction_id,salesperson_id,amount,status) VALUES (1,1,50.00,'approved'),(2,1,100.00,'declined'),(3,2,75.00,'approved'); CREATE TABLE salespeople (salesperson_id INT,name VARCHAR(50)); INSERT INTO salespeople (salesperson_id,name) VALUES (1,'John Doe'),(2,'Jane Smith'); | SELECT s.name, (COUNT(t.transaction_id) * 100.0 / (SELECT COUNT(*) FROM transactions t2 WHERE t2.salesperson_id = s.salesperson_id)) AS percentage FROM salespeople s LEFT JOIN transactions t ON s.salesperson_id = t.salesperson_id AND t.status = 'declined' GROUP BY s.name; |
Which customers have not made any transactions in the last 30 days? | CREATE TABLE TransactionDates (TransactionID INT,TransactionDate DATE); INSERT INTO TransactionDates (TransactionID,TransactionDate) VALUES (1,'2022-01-01'),(2,'2022-01-15'),(3,'2022-02-03'),(4,'2022-02-20'); | SELECT c.CustomerID FROM Customers c LEFT JOIN TransactionDates t ON c.CustomerID = t.CustomerID WHERE t.TransactionDate IS NULL AND t.TransactionDate > NOW() - INTERVAL '30 days'; |
What is the minimum number of hospital beds per capita in each county? | CREATE TABLE hospital_beds (id INT,county TEXT,beds_per_capita FLOAT); INSERT INTO hospital_beds (id,county,beds_per_capita) VALUES (1,'Los Angeles County',2.5),(2,'Orange County',3.0); | SELECT county, MIN(beds_per_capita) FROM hospital_beds GROUP BY county; |
Identify the top 2 countries with the highest number of offshore wells drilled in 2019 | CREATE TABLE wells_drilled (country VARCHAR(50),well_id INT,drill_date DATE,offshore BOOLEAN); INSERT INTO wells_drilled (country,well_id,drill_date,offshore) VALUES ('Norway',1,'2019-01-01',true); INSERT INTO wells_drilled (country,well_id,drill_date,offshore) VALUES ('USA',2,'2018-12-31',true); INSERT INTO wells_drilled (country,well_id,drill_date,offshore) VALUES ('Brazil',3,'2019-06-15',true); INSERT INTO wells_drilled (country,well_id,drill_date,offshore) VALUES ('Mexico',4,'2019-07-20',true); INSERT INTO wells_drilled (country,well_id,drill_date,offshore) VALUES ('UK',5,'2019-12-25',true); | SELECT country, COUNT(*) as num_wells FROM wells_drilled WHERE YEAR(drill_date) = 2019 AND offshore = true GROUP BY country ORDER BY num_wells DESC LIMIT 2; |
What's the average donation amount for each cause? | CREATE TABLE donors (id INT,name VARCHAR(255),country VARCHAR(255));CREATE TABLE donations (id INT,donor_id INT,cause_id INT,amount DECIMAL(10,2));CREATE TABLE causes (id INT,name VARCHAR(255)); | SELECT c.name, AVG(d.amount) FROM donations d INNER JOIN causes c ON d.cause_id = c.id GROUP BY c.name; |
Identify the defense diplomacy activities between Colombia and other countries. | CREATE TABLE colombia_diplomacy (id INT,country VARCHAR(50),partner VARCHAR(50)); INSERT INTO colombia_diplomacy (id,country,partner) VALUES (1,'Colombia','United States'),(2,'Colombia','Brazil'),(3,'Colombia','Ecuador'),(4,'Colombia','Peru'); | SELECT DISTINCT partner FROM colombia_diplomacy WHERE country = 'Colombia'; |
What are the top 5 states with the highest installed solar capacity in the US? | CREATE TABLE states (state_name VARCHAR(255),solar_capacity FLOAT); INSERT INTO states (state_name,solar_capacity) VALUES ('California',32722),('Texas',8807),('Florida',7256),('North Carolina',6321),('Arizona',5653); | SELECT state_name, SUM(solar_capacity) as total_capacity FROM states GROUP BY state_name ORDER BY total_capacity DESC LIMIT 5; |
What is the total revenue generated by Latin music on iTunes in the United States? | CREATE TABLE Sales (SaleID INT,Song TEXT,Platform TEXT,Country TEXT,Revenue FLOAT); INSERT INTO Sales (SaleID,Song,Platform,Country,Revenue) VALUES (1,'Despacito','iTunes','United States',1.29),(2,'Havana','iTunes','United States',1.29); | SELECT SUM(Revenue) FROM Sales WHERE Platform = 'iTunes' AND Country = 'United States' AND Genre = 'Latin'; |
How many missions were launched per month in 2020? | CREATE TABLE mission_launch_dates (mission_name VARCHAR(50),launch_date DATE); | SELECT EXTRACT(MONTH FROM launch_date) as month, COUNT(*) as num_missions FROM mission_launch_dates WHERE EXTRACT(YEAR FROM launch_date) = 2020 GROUP BY month; |
What is the minimum age of male offenders who committed violent crimes in San Francisco? | CREATE TABLE offenders (id INT,age INT,gender VARCHAR(10),city VARCHAR(20)); INSERT INTO offenders (id,age,gender,city) VALUES (1,34,'Female','Oakland'),(2,42,'Male','San_Francisco'),(3,25,'Male','San_Francisco'),(4,45,'Female','San_Francisco'); CREATE TABLE crimes (id INT,type VARCHAR(20),city VARCHAR(20)); INSERT INTO crimes (id,type,city) VALUES (1,'Property_Crime','Oakland'),(2,'Violent_Crime','San_Francisco'),(3,'Assault','Oakland'),(4,'Violent_Crime','San_Francisco'); | SELECT MIN(age) FROM offenders JOIN crimes ON offenders.id = crimes.id WHERE gender = 'Male' AND type = 'Violent_Crime' AND city = 'San_Francisco'; |
What is the total number of hospital beds available in the state of New York as of 2022? | CREATE TABLE hospitals (state VARCHAR(255),year INT,hospital_beds INT); INSERT INTO hospitals (state,year,hospital_beds) VALUES ('New York',2022,50000); | SELECT SUM(hospital_beds) AS total_hospital_beds FROM hospitals WHERE state = 'New York' AND year = 2022; |
Delete genetic research data for a specific project that is no longer active | CREATE TABLE genetic_research (id INT PRIMARY KEY,name VARCHAR(255),description TEXT,active BOOLEAN); INSERT INTO genetic_research (id,name,description,active) VALUES (1,'CRISPR Cas9','A genome editing tool',true),(2,'Genetic Sequencing','Determining the order of nucleotides in DNA',true); | DELETE FROM genetic_research WHERE id = 1; |
What is the average cost of military equipment maintenance in the US? | CREATE TABLE military_equipment (id INT,country VARCHAR(50),cost FLOAT); INSERT INTO military_equipment (id,country,cost) VALUES (1,'USA',1500000); INSERT INTO military_equipment (id,country,cost) VALUES (2,'USA',1800000); | SELECT AVG(cost) FROM military_equipment WHERE country = 'USA'; |
What is the total number of vulnerabilities for each software type, ordered by the highest number of vulnerabilities? | CREATE TABLE software (software_type VARCHAR(255),total_vulnerabilities INT); INSERT INTO software (software_type,total_vulnerabilities) VALUES ('Application',100),('Operating System',200),('Database',150); | SELECT software_type, total_vulnerabilities FROM software ORDER BY total_vulnerabilities DESC; |
Determine the revenue generated by each menu category in the APAC region. | CREATE TABLE menu_items (item_id INT,item_name VARCHAR(50),category VARCHAR(20),region VARCHAR(20),price DECIMAL(5,2),sales INT); INSERT INTO menu_items (item_id,item_name,category,region,price,sales) VALUES (1,'Vegetable Spring Rolls','Appetizers','APAC',4.99,300),(2,'Spicy Tofu','Entrees','APAC',12.99,200),(3,'Mango Sticky Rice','Desserts','APAC',6.99,250); | SELECT category, SUM(price * sales) AS revenue FROM menu_items WHERE region = 'APAC' GROUP BY category; |
Delete all records in the 'athletes' table where age is less than 20 | CREATE TABLE athletes (id INT,name VARCHAR(50),position VARCHAR(50),team VARCHAR(50),age INT); | DELETE FROM athletes WHERE age < 20; |
What was the earliest and latest time a ride ended for each system in June 2023? | CREATE TABLE trips (trip_id INT,trip_start_time DATETIME,trip_end_time DATETIME,system_name VARCHAR(20)); | SELECT system_name, MIN(trip_end_time) AS min_end_time, MAX(trip_end_time) AS max_end_time FROM trips WHERE system_name IN ('Bus', 'Subway', 'Tram') AND trip_end_time BETWEEN '2023-06-01' AND '2023-06-30' GROUP BY system_name; |
Insert a new record for a veteran employment application from a new applicant in India? | CREATE TABLE VeteranEmployment (ApplicationID INT,Applicant VARCHAR(50),Country VARCHAR(50)); INSERT INTO VeteranEmployment (ApplicationID,Applicant,Country) VALUES (1,'John Doe','USA'),(2,'Jane Smith','Canada'),(3,'Michael Johnson','USA'); | INSERT INTO VeteranEmployment (ApplicationID, Applicant, Country) VALUES (4, 'Akshay Kumar', 'India'); |
What is the average carbon offset of green buildings constructed in 2020 and 2021, grouped by city? | CREATE TABLE green_buildings (id INT,city VARCHAR(50),year INT,carbon_offsets FLOAT); | SELECT city, AVG(carbon_offsets) FROM green_buildings WHERE year IN (2020, 2021) GROUP BY city; |
What is the average energy efficiency rating for each building type in the buildings and energy_efficiency tables, excluding buildings in the "Industrial" category? | CREATE TABLE buildings(id INT,building_name VARCHAR(50),building_type VARCHAR(50));CREATE TABLE energy_efficiency(building_id INT,rating INT); | SELECT b.building_type, AVG(e.rating) AS avg_rating FROM buildings b INNER JOIN energy_efficiency e ON b.id = e.building_id WHERE b.building_type != 'Industrial' GROUP BY b.building_type; |
How many hospitals are there in the Midwest region of the US? | CREATE TABLE Hospital (Name TEXT,Region TEXT); INSERT INTO Hospital (Name,Region) VALUES ('Hospital A','Northeast'); INSERT INTO Hospital (Name,Region) VALUES ('Hospital B','South'); | SELECT COUNT(*) FROM Hospital WHERE Region = 'Midwest'; |
Update the production quantity for product "Gizmo Y" to 250 on 2022-06-15 in the "production" table | CREATE TABLE production (product VARCHAR(50),units_produced INT,production_date DATE); | UPDATE production SET units_produced = 250 WHERE product = 'Gizmo Y' AND production_date = '2022-06-15'; |
Which community education program has the highest enrollment? | CREATE TABLE community_education (id INT,program_name VARCHAR(50),enrollment INT); INSERT INTO community_education (id,program_name,enrollment) VALUES (1,'Wildlife Conservation',1500),(2,'Biodiversity Awareness',1200),(3,'Climate Change Education',1800); | SELECT program_name, MAX(enrollment) FROM community_education; |
List all support programs and their respective coordinators, ordered alphabetically by support program name. | CREATE TABLE support_programs (id INT,name TEXT,coordinator TEXT); | SELECT * FROM support_programs ORDER BY name; |
Which policies have had the most violations in the past year from the 'policy_violations' table? | CREATE TABLE policy_violations (id INT,policy VARCHAR(50),violations INT,year INT); | SELECT policy, SUM(violations) FROM policy_violations WHERE year = YEAR(CURRENT_DATE) - 1 GROUP BY policy ORDER BY SUM(violations) DESC; |
What was the total budget for all climate projects in '2018' from the 'mitigation_projects' and 'adaptation_projects' tables? | CREATE TABLE mitigation_projects (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),description TEXT,start_date DATE,end_date DATE,budget FLOAT); INSERT INTO mitigation_projects (id,name,location,description,start_date,end_date,budget) VALUES (1,'Solar Farm Installation','California','Installation of solar panels','2018-01-01','2019-12-31',10000000); CREATE TABLE adaptation_projects (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),description TEXT,start_date DATE,end_date DATE,budget FLOAT); INSERT INTO adaptation_projects (id,name,location,description,start_date,end_date,budget) VALUES (1,'Sea Wall Construction','Miami','Coastal protection for sea level rise','2018-01-01','2020-12-31',5000000); | SELECT SUM(budget) FROM mitigation_projects WHERE start_date <= '2018-12-31' AND end_date >= '2018-01-01' UNION ALL SELECT SUM(budget) FROM adaptation_projects WHERE start_date <= '2018-12-31' AND end_date >= '2018-01-01'; |
Which support programs have more than 20 students participating? | CREATE TABLE Students(student_id INT,name TEXT);CREATE TABLE Programs(program_id INT,program_name TEXT);CREATE TABLE Student_Programs(student_id INT,program_id INT); | SELECT p.program_name FROM Programs p INNER JOIN Student_Programs sp ON p.program_id = sp.program_id GROUP BY p.program_name HAVING COUNT(DISTINCT sp.student_id) > 20; |
Find the total billing amount for cases in the 'Family Law' practice area that were opened in the first quarter of 2022? | CREATE TABLE cases (case_id INT,practice_area VARCHAR(20),billing_amount DECIMAL(10,2),open_date DATE); INSERT INTO cases (case_id,practice_area,billing_amount,open_date) VALUES (1,'Family Law',2000,'2022-01-01'),(2,'Criminal Law',1500,'2022-03-15'),(3,'Family Law',3000,'2022-04-01'); | SELECT SUM(billing_amount) FROM cases WHERE practice_area = 'Family Law' AND QUARTER(open_date) = 1 AND YEAR(open_date) = 2022; |
What is the average daily water usage for each water source in the eastern region in 2020?' | CREATE TABLE water_usage (region VARCHAR(255),source VARCHAR(255),date DATE,usage INT); INSERT INTO water_usage (region,source,date,usage) VALUES ('Eastern','River','2020-01-01',15000); | SELECT region, source, AVG(usage) FROM water_usage WHERE region = 'Eastern' AND YEAR(date) = 2020 GROUP BY region, source; |
Update the 'emission_level' of the 'Coal Power Plant' record in the 'plants' table to 'High' | CREATE TABLE plants (id VARCHAR(10),name VARCHAR(50),location VARCHAR(50),type VARCHAR(50),emission_level VARCHAR(50)); INSERT INTO plants (id,name,location,type,emission_level) VALUES ('Plant_001','Coal Power Plant','Ohio','Power Plant','Medium'); INSERT INTO plants (id,name,location,type,emission_level) VALUES ('Plant_002','Gas Power Plant','Texas','Power Plant','Low'); | UPDATE plants SET emission_level = 'High' WHERE name = 'Coal Power Plant'; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.