instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the average annual production of cannabis for producers located in Oregon and Washington, and the number of employees for each of these producers? | CREATE TABLE producers (id INT PRIMARY KEY,location TEXT,annual_production INT); INSERT INTO producers (id,location,annual_production) VALUES (1,'Oregon',1500); INSERT INTO producers (id,location,annual_production) VALUES (2,'Washington',2000); CREATE TABLE labor (id INT PRIMARY KEY,producer_id INT,employee_count INT); INSERT INTO labor (id,producer_id,employee_count) VALUES (1,1,20); INSERT INTO labor (id,producer_id,employee_count) VALUES (2,2,25); | SELECT p.location, AVG(p.annual_production) as avg_production, l.employee_count FROM producers p INNER JOIN labor l ON p.id = l.producer_id WHERE p.location IN ('Oregon', 'Washington') GROUP BY p.location; |
List all members who have a 'Gold' or 'Diamond' membership. | CREATE TABLE member_details (member_id INT,membership VARCHAR(10)); INSERT INTO member_details (member_id,membership) VALUES (1,'Gold'),(2,'Platinum'),(3,'Silver'),(4,'Platinum'),(5,'Gold'),(6,'Diamond'),(7,'Bronze'); | SELECT member_id FROM member_details WHERE membership IN ('Gold', 'Diamond'); |
Update the names of all users who have a name that matches a specified pattern. | CREATE TABLE users (user_id INT,name VARCHAR(255)); | UPDATE users SET name = REPLACE(name, 'Smith', 'Black') WHERE name LIKE '%Smith%'; |
Avg. rating of TV shows directed by women? | CREATE TABLE TV_Show_Data (tv_show VARCHAR(255),director VARCHAR(50),rating FLOAT); | SELECT AVG(rating) FROM TV_Show_Data WHERE director LIKE '%female%'; |
What's the regulatory status of digital assets in the European Union? | CREATE TABLE digital_assets (id INT,name VARCHAR(255),country VARCHAR(255),regulatory_status VARCHAR(255)); INSERT INTO digital_assets (id,name,country,regulatory_status) VALUES (1,'Asset 1','France','Approved'),(2,'Asset 2','Germany','Under Review'),(3,'Asset 3','Spain','Approved'),(4,'Asset 4','Ireland','Approved'),(5,'Asset 5','Italy','Under Review'),(6,'Asset 6','Netherlands','Approved'); | SELECT regulatory_status FROM digital_assets WHERE country IN ('France', 'Germany', 'Spain', 'Ireland', 'Italy', 'Netherlands') AND country = 'European Union'; |
What is the average quantity of organic fertilizers used by farmers in the North region, grouped by their names? | CREATE TABLE fertilizers (id INT,date DATE,type VARCHAR(50),quantity INT,farm_id INT,FOREIGN KEY (farm_id) REFERENCES farmers(id)); INSERT INTO fertilizers (id,date,type,quantity,farm_id) VALUES (1,'2022-01-01','Organic',50,1),(2,'2022-01-02','Organic',75,3),(3,'2022-01-03','Organic',60,4); INSERT INTO farmers (id,name,region,age) VALUES (1,'James','North',50),(2,'Sophia','South',40),(3,'Mason','North',45),(4,'Lily','East',55); | SELECT f.name, AVG(fertilizers.quantity) as avg_quantity FROM fertilizers JOIN farmers f ON fertilizers.farm_id = f.id WHERE fertilizers.type = 'Organic' AND f.region = 'North' GROUP BY f.name; |
Insert new records into the 'wellness_trends' table for the month of January 2023 with a value of 50 for 'meditation_minutes' | CREATE TABLE wellness_trends (month VARCHAR(7),meditation_minutes INT,yoga_minutes INT); | INSERT INTO wellness_trends (month, meditation_minutes, yoga_minutes) VALUES ('January 2023', 50, 0); |
What is the total carbon tax revenue for each country for the last 3 years? | CREATE TABLE CarbonTax (Id INT,Country VARCHAR(255),Year INT,Revenue INT); INSERT INTO CarbonTax VALUES (1,'Germany',2018,1000),(2,'Germany',2019,1500),(3,'Germany',2020,2000),(4,'France',2018,1200),(5,'France',2019,1800),(6,'France',2020,2500),(7,'Italy',2018,800),(8,'Italy',2019,1200),(9,'Italy',2020,1600); | SELECT Country, SUM(Revenue) as Total_Revenue FROM CarbonTax WHERE Year IN (2018, 2019, 2020) GROUP BY Country; |
What is the maximum engine lifespan for each aircraft type? | CREATE TABLE AircraftTypes (AircraftTypeID INT,AircraftType VARCHAR(50));CREATE TABLE EngineLifespan (EngineLifespanID INT,AircraftTypeID INT,EngineLifespan INT); | SELECT AircraftType, MAX(EngineLifespan) AS MaxEngineLifespan FROM EngineLifespan EL INNER JOIN AircraftTypes AT ON EL.AircraftTypeID = AT.AircraftTypeID GROUP BY AircraftType; |
Update the recycling rate for 'Germany' to 0.42 in the last month's data. | CREATE TABLE europe_recycling_rates (country_name VARCHAR(50),recycling_rate NUMERIC(10,2),measurement_date DATE); INSERT INTO europe_recycling_rates (country_name,recycling_rate,measurement_date) VALUES ('Germany',0.40,'2022-02-28'),('France',0.30,'2022-02-28'); | UPDATE europe_recycling_rates SET recycling_rate = 0.42 WHERE country_name = 'Germany' AND measurement_date >= DATEADD(month, -1, CURRENT_DATE); |
What is the average quantity of products sold in stores located in urban areas? | CREATE TABLE stores (store_id INT,location VARCHAR(20),quantity INT); INSERT INTO stores (store_id,location,quantity) VALUES (1,'urban',100),(2,'rural',50),(3,'urban',150),(4,'suburban',75); | SELECT AVG(quantity) FROM stores WHERE location = 'urban'; |
What is the total billing amount for cases handled by the attorney with the ID 2? | CREATE TABLE Attorneys (AttorneyID INT,Name VARCHAR(50)); INSERT INTO Attorneys (AttorneyID,Name) VALUES (1,'Smith,John'),(2,'Garcia,Maria'),(3,'Johnson,James'); CREATE TABLE Cases (CaseID INT,AttorneyID INT,BillingAmount DECIMAL(10,2)); INSERT INTO Cases (CaseID,AttorneyID,BillingAmount) VALUES (1,1,5000.00),(2,2,3500.00),(3,2,4000.00),(4,3,6000.00); | SELECT SUM(BillingAmount) FROM Cases WHERE AttorneyID = 2; |
What is the total fare collected for each route segment? | CREATE TABLE route_segments (segment_id INT,segment_name TEXT,route_id INT); CREATE TABLE fares (fare_id INT,segment_id INT,fare_amount DECIMAL); INSERT INTO route_segments (segment_id,segment_name,route_id) VALUES (1,'Downtown to Midtown',1),(2,'Midtown to Uptown',1),(3,'City Center to Suburbs',2); INSERT INTO fares (fare_id,segment_id,fare_amount) VALUES (1,1,2.50),(2,1,2.50),(3,2,2.50),(4,2,2.50),(5,3,3.50),(6,3,3.50); | SELECT f.segment_id, r.segment_name, SUM(f.fare_amount) AS total_fare FROM fares f JOIN route_segments r ON f.segment_id = r.segment_id GROUP BY f.segment_id; |
List all policy types that have a claim amount less than $500. | CREATE TABLE GeneralPolicyTypes (PolicyTypeID int,PolicyType varchar(20)); CREATE TABLE GeneralClaims (ClaimID int,PolicyTypeID int,ClaimAmount decimal); INSERT INTO GeneralPolicyTypes (PolicyTypeID,PolicyType) VALUES (1,'Boat'); INSERT INTO GeneralPolicyTypes (PolicyTypeID,PolicyType) VALUES (2,'Motorcycle'); INSERT INTO GeneralClaims (ClaimID,PolicyTypeID,ClaimAmount) VALUES (1,1,400); INSERT INTO GeneralClaims (ClaimID,PolicyTypeID,ClaimAmount) VALUES (2,2,600); | SELECT GeneralPolicyTypes.PolicyType FROM GeneralPolicyTypes INNER JOIN GeneralClaims ON GeneralPolicyTypes.PolicyTypeID = GeneralClaims.PolicyTypeID WHERE GeneralClaims.ClaimAmount < 500; |
Who is the officer with the fewest community engagement activities in the last month? | CREATE TABLE officers (id INT,name VARCHAR(255),division VARCHAR(255)); INSERT INTO officers (id,name,division) VALUES (1,'Sophia Chen','NYPD'),(2,'Jose Hernandez','NYPD'); CREATE TABLE community_engagements (id INT,officer_id INT,engagement_type VARCHAR(255),engagement_time TIMESTAMP); INSERT INTO community_engagements (id,officer_id,engagement_type,engagement_time) VALUES (1,1,'Community Meeting','2022-02-01 10:00:00'),(2,2,'Neighborhood Watch','2022-02-15 11:00:00'),(3,1,'Coffee with a Cop','2022-02-10 09:00:00'); | SELECT o.name, COUNT(ce.id) as total_engagements FROM community_engagements ce JOIN officers o ON ce.officer_id = o.id WHERE ce.engagement_time >= DATEADD(month, -1, CURRENT_TIMESTAMP) GROUP BY o.name ORDER BY total_engagements ASC; |
What percentage of cosmetics sold in Canada contain organic ingredients? | CREATE TABLE sales (product_name TEXT,sale_date DATE,country TEXT,organic BOOLEAN); INSERT INTO sales (product_name,sale_date,country,organic) VALUES ('Mascara A','2022-02-01','Canada',true),('Foundation B','2022-02-02','US',false),('Lipstick C','2022-02-03','Canada',false); | SELECT (COUNT(*) FILTER (WHERE organic = true)) * 100.0 / COUNT(*) as organic_percentage FROM sales WHERE country = 'Canada'; |
Select all data from the view 'v_space_debris_summary' | CREATE TABLE space_debris (id INT PRIMARY KEY,debris_name VARCHAR(100),launch_date DATE,type VARCHAR(50));CREATE VIEW v_space_debris_summary AS SELECT id,debris_name,launch_date,type FROM space_debris; | SELECT * FROM v_space_debris_summary; |
What is the maximum recycling rate for glass in regions where the recycling rate for metal is above 50%? | CREATE TABLE recycling_stats (region TEXT,material TEXT,recycling_rate FLOAT); INSERT INTO recycling_stats (region,material,recycling_rate) VALUES ('Region A','Metal',0.55),('Region A','Glass',0.45),('Region B','Metal',0.60),('Region B','Glass',0.35),('Region C','Metal',0.45),('Region C','Glass',0.40); | SELECT MAX(recycling_rate) FROM recycling_stats WHERE region IN (SELECT region FROM recycling_stats WHERE material = 'Metal' AND recycling_rate > 0.5) AND material = 'Glass'; |
Delete all petitions related to the 'Transportation' department from the 'petitions' table. | CREATE TABLE petitions (id INT PRIMARY KEY,department_id INT,title VARCHAR(255)); | DELETE FROM petitions WHERE department_id IN (SELECT id FROM departments WHERE name = 'Transportation'); |
What was the total water consumption by all states in the year 2018? | CREATE TABLE water_usage (id INT,state VARCHAR(20),year INT,usage FLOAT); | SELECT SUM(usage) FROM water_usage WHERE year = 2018; |
What is the total crop yield for each crop grown in Canada? | CREATE TABLE provinces (id INT,name TEXT,country TEXT); INSERT INTO provinces (id,name,country) VALUES (1,'Ontario','Canada'),(2,'Quebec','Canada'); | SELECT crops.name, SUM(crop_yield.yield) FROM crop_yield JOIN farms ON crop_yield.farm_id = farms.id JOIN crops ON crop_yield.crop_id = crops.id JOIN provinces ON farms.id = provinces.id WHERE provinces.country = 'Canada' GROUP BY crops.name; |
Insert a new record for a sustainable tourism initiative in Japan. | CREATE TABLE sustainable_tourism (id INT,country VARCHAR(50),initiative_name VARCHAR(100),start_date DATE,end_date DATE); | INSERT INTO sustainable_tourism (id, country, initiative_name, start_date, end_date) VALUES (1, 'Japan', 'Eco-Friendly Island Cleanup', '2023-04-01', '2023-12-31'); |
Update the quantity of garment with id 2 to 100. | CREATE TABLE inventories (id INT PRIMARY KEY,garment_id INT,quantity INT); INSERT INTO inventories (id,garment_id,quantity) VALUES (1,1,50),(2,2,75); | UPDATE inventories SET quantity = 100 WHERE id = 2; |
Generate a view for top 10 eSports teams | CREATE VIEW top_10_teams AS SELECT team_id,SUM(wins) as total_wins,AVG(average_score) as average_score FROM esports_games GROUP BY team_id; | CREATE VIEW top_10_teams_view AS SELECT * FROM top_10_teams WHERE row_number() OVER (ORDER BY total_wins DESC, average_score DESC) <= 10; |
Update the salary of 'Bob Johnson' in the 'Assembly' department to $65000. | CREATE TABLE employees (id INT,name TEXT,department TEXT,salary INT); INSERT INTO employees (id,name,department,salary) VALUES (1,'John Doe','Engineering',70000),(2,'Jane Smith','Management',90000),(3,'Bob Johnson','Assembly',50000),(4,'Alice Williams','Engineering',75000),(5,'Charlie Brown','Assembly',55000),(6,'Janet Doe','Quality',60000),(7,'Jim Smith','Management',85000),(8,'Jake Johnson','Assembly',60000); | UPDATE employees SET salary = 65000 WHERE id = 3; |
Find the top 3 cities by total concert revenue for a given artist. | CREATE TABLE Concerts (id INT,artist_id INT,city VARCHAR(50),revenue DECIMAL(10,2)); | SELECT city, SUM(revenue) AS total_revenue FROM Concerts WHERE artist_id = 1 GROUP BY city ORDER BY total_revenue DESC LIMIT 3; |
What is the total quantity of 'organic cotton' products sold by each brand, ordered by total quantity in descending order? | CREATE TABLE brands(brand_id INT,brand_name TEXT); INSERT INTO brands(brand_id,brand_name) VALUES (1,'BrandA'),(2,'BrandB'),(3,'BrandC'); CREATE TABLE products(product_id INT,product_name TEXT,brand_id INT,quantity INT); INSERT INTO products(product_id,product_name,brand_id,quantity) VALUES (1,'Product1',1,200),(2,'Product2',1,300),(3,'Product3',2,500),(4,'Product4',3,1000),(5,'Product5',3,800); | SELECT brand_id, SUM(quantity) as total_quantity FROM products WHERE product_name LIKE '%organic cotton%' GROUP BY brand_id ORDER BY total_quantity DESC; |
Calculate the average age of athletes in the "athletes" table. | CREATE TABLE athletes (id INT,name VARCHAR(50),age INT,sport VARCHAR(50),country VARCHAR(50)); INSERT INTO athletes (id,name,age,sport,country) VALUES (1,'John Doe',30,'Basketball','USA'); | SELECT AVG(age) FROM athletes; |
Which space missions had the highest and lowest cost in the last 10 years? | CREATE SCHEMA space_exploration; CREATE TABLE space_exploration.missions (mission_id INT,mission_name VARCHAR(50),mission_cost INT,mission_date DATE); INSERT INTO space_exploration.missions VALUES (1,'Mars Rover',2500000,'2012-08-05'); INSERT INTO space_exploration.missions VALUES (2,'SpaceX Falcon Heavy',9000000,'2018-02-06'); INSERT INTO space_exploration.missions VALUES (3,'Hubble Space Telescope',1000000,'1990-04-24'); | SELECT mission_name, mission_cost, ROW_NUMBER() OVER (ORDER BY mission_cost DESC) as mission_rank FROM space_exploration.missions WHERE mission_date >= DATEADD(year, -10, GETDATE()) ORDER BY mission_cost; |
What is the minimum salary of remote employees? | CREATE TABLE EmployeeDetails (EmployeeID INT,Department TEXT,Salary REAL,Remote TEXT); INSERT INTO EmployeeDetails (EmployeeID,Department,Salary,Remote) VALUES (1,'IT',70000,'Yes'); | SELECT MIN(Salary) FROM EmployeeDetails WHERE Remote = 'Yes'; |
How many endangered animals are there in total, by type, in Asia? | CREATE TABLE Animals (AnimalID INT,AnimalName VARCHAR(50),Population INT,Habitat VARCHAR(50),Status VARCHAR(20)); INSERT INTO Animals (AnimalID,AnimalName,Population,Habitat,Status) VALUES (1,'Tiger',3890,'Asia','Endangered'); INSERT INTO Animals (AnimalID,AnimalName,Population,Habitat,Status) VALUES (2,'Giant Panda',1864,'Asia','Endangered'); | SELECT Status, AnimalName, SUM(Population) FROM Animals WHERE Habitat = 'Asia' AND Status = 'Endangered' GROUP BY Status, AnimalName; |
What is the total number of cultural competency trainings attended by community health workers of each gender, in the 'training_attendance' table? | CREATE TABLE community_health_workers (id INT,name VARCHAR(50),gender VARCHAR(50)); CREATE TABLE training_attendance (id INT,worker_id INT,training_id INT); CREATE TABLE trainings (id INT,name VARCHAR(50),date DATE); INSERT INTO community_health_workers (id,name,gender) VALUES (1,'John Doe','Male'),(2,'Jane Smith','Female'); INSERT INTO training_attendance (id,worker_id,training_id) VALUES (1,1,1),(2,1,2),(3,2,1); INSERT INTO trainings (id,name,date) VALUES (1,'Cultural Competency 101','2022-01-01'),(2,'Advanced Cultural Competency','2022-02-01'); | SELECT g.gender, COUNT(ta.id) FROM training_attendance ta JOIN community_health_workers g ON ta.worker_id = g.id GROUP BY g.gender; |
How many members have joined in each month of 2022? | CREATE TABLE gym_memberships (id INT,member_name VARCHAR(50),start_date DATE,end_date DATE,membership_type VARCHAR(50),price DECIMAL(5,2)); | SELECT DATE_FORMAT(start_date, '%Y-%m') AS month, COUNT(DISTINCT id) AS members_joined FROM gym_memberships WHERE start_date BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY month; |
Insert new humanitarian aid records for disaster_id 307, 308, and 309, country_name 'Nigeria', 'Congo', and 'Madagascar' respectively | CREATE TABLE humanitarian_aid (disaster_id INT,country_name VARCHAR(50),aid_amount INT,aid_date DATE); | INSERT INTO humanitarian_aid (disaster_id, country_name, aid_amount, aid_date) VALUES (307, 'Nigeria', 45000, '2022-01-05'), (308, 'Congo', 55000, '2022-02-01'), (309, 'Madagascar', 65000, '2022-02-15'); |
Delete the well with well_id 3. | CREATE TABLE wells (well_id INT,well_type VARCHAR(10),location VARCHAR(20),production_rate FLOAT); INSERT INTO wells (well_id,well_type,location,production_rate) VALUES (1,'offshore','Gulf of Mexico',1000),(2,'onshore','Texas',800),(3,'offshore','North Sea',1200); | DELETE FROM wells WHERE well_id = 3; |
What is the minimum ocean acidification level in the Pacific Ocean? | CREATE TABLE ocean_acidification (location TEXT,value FLOAT); INSERT INTO ocean_acidification (location,value) VALUES ('Pacific Ocean',8.1),('Atlantic Ocean',8.0); | SELECT MIN(value) FROM ocean_acidification WHERE location = 'Pacific Ocean'; |
How many workplace safety inspections have been conducted in the construction sector in the last 3 months? | CREATE TABLE sectors (id INT,sector_name VARCHAR(255)); INSERT INTO sectors (id,sector_name) VALUES (1,'Construction'),(2,'Transportation'); CREATE TABLE inspections (id INT,sector_id INT,inspection_date DATE); INSERT INTO inspections (id,sector_id,inspection_date) VALUES (1,1,'2022-03-01'),(2,1,'2022-02-15'); | SELECT COUNT(*) as total_inspections FROM inspections i JOIN sectors s ON i.sector_id = s.id WHERE s.sector_name = 'Construction' AND i.inspection_date >= DATE(NOW()) - INTERVAL 3 MONTH; |
What is the percentage of on-time deliveries for each courier company in the last month? | CREATE TABLE CourierCompany (id INT,name VARCHAR(255),on_time_deliveries INT,total_deliveries INT); | SELECT name, ROUND(on_time_deliveries * 100.0 / total_deliveries, 2) as percentage_on_time_deliveries FROM CourierCompany WHERE sale_date >= (CURRENT_DATE - INTERVAL '1 month') ORDER BY percentage_on_time_deliveries DESC; |
What is the maximum number of mental health assessments conducted per student in the last academic year? | CREATE TABLE assessments (assessment_id INT,student_id INT,assessment_date DATE); INSERT INTO assessments (assessment_id,student_id,assessment_date) VALUES (1,1,'2021-09-01'),(2,1,'2022-02-15'),(3,2,'2021-10-05'),(4,2,'2022-03-28'),(5,3,'2021-11-12'),(6,3,'2022-05-03'); | SELECT student_id, MAX(COUNT(assessment_id)) FROM assessments WHERE assessment_date >= DATE_SUB('2022-08-01', INTERVAL 1 YEAR) GROUP BY student_id; |
How many traffic violations were issued in Chicago in the year 2020, and what was the most common type? | CREATE TABLE violations (id INT,city VARCHAR(255),date DATE,type VARCHAR(255),description TEXT); INSERT INTO violations (id,city,date,type,description) VALUES (1,'Chicago','2020-01-01','Speeding','Exceeding the speed limit'),(2,'Chicago','2020-02-01','Parking','Parking in a no-parking zone'); | SELECT COUNT(*) FROM violations WHERE city = 'Chicago' AND YEAR(date) = 2020; SELECT type, COUNT(*) FROM violations WHERE city = 'Chicago' AND YEAR(date) = 2020 GROUP BY type ORDER BY COUNT(*) DESC LIMIT 1; |
Which stop is the last stop for route 'Green Line'? | CREATE TABLE routes (id INT,name VARCHAR(50),start_stop_id INT,end_stop_id INT); INSERT INTO routes (id,name,start_stop_id,end_stop_id) VALUES (3,'Green Line',45,60); | SELECT s.name FROM stops s INNER JOIN (SELECT end_stop_id FROM routes WHERE name = 'Green Line' LIMIT 1) rt ON s.id = rt.end_stop_id; |
Delete products with a sustainability score less than 50. | CREATE TABLE Products (id INT,name VARCHAR(255),sustainability_score INT); | DELETE FROM Products WHERE sustainability_score < 50; |
Delete all mental health parity regulations that have not been implemented. | CREATE TABLE mental_health_parity (id INT,regulation VARCHAR(100),state VARCHAR(20),implementation_date DATE); INSERT INTO mental_health_parity (id,regulation,state,implementation_date) VALUES (1,'Regulation 1','New York','2011-01-01'),(2,'Regulation 2','Florida','2012-01-01'),(3,'Regulation 3','New York',NULL); | DELETE FROM mental_health_parity WHERE implementation_date IS NULL; |
What is the maximum amount of funding received by a company with a female CEO in the renewable energy sector? | CREATE TABLE companies (id INT,name TEXT,industry TEXT,ceo TEXT,funding FLOAT); INSERT INTO companies (id,name,industry,ceo,funding) VALUES (1,'GreenEnergy','Renewable Energy','Female',20000000.0); | SELECT MAX(funding) FROM companies WHERE ceo = 'Female' AND industry = 'Renewable Energy'; |
What is the total amount of funds donated by each organization for the education sector in Afghanistan in 2020? | CREATE TABLE donors (donor_id INT,donor_name TEXT,donation_amount DECIMAL,donation_date DATE,sector TEXT,country TEXT); INSERT INTO donors (donor_id,donor_name,donation_amount,donation_date,sector,country) VALUES (1,'UNICEF',50000,'2020-01-01','education','Afghanistan'); | SELECT donor_name, SUM(donation_amount) as total_donation FROM donors WHERE country = 'Afghanistan' AND sector = 'education' GROUP BY donor_name; |
What is the average daily water consumption for residential use in each province of Canada, for the year 2021? | CREATE TABLE canada_residential_water (province VARCHAR(255),year INT,usage FLOAT); INSERT INTO canada_residential_water (province,year,usage) VALUES ('Alberta',2021,500.5),('British Columbia',2021,450.3),('Ontario',2021,600.2),('Quebec',2021,400.1),('Nova Scotia',2021,350.0); | SELECT province, AVG(usage) as avg_daily_usage FROM canada_residential_water WHERE year = 2021 GROUP BY province; |
How many unique public services are offered in each county in 'county_services' table? | CREATE TABLE county_services (county VARCHAR(255),service_type VARCHAR(255)); | SELECT county, COUNT(DISTINCT service_type) FROM county_services GROUP BY county; |
What is the maximum age of patients who received the Pfizer vaccine in California? | CREATE TABLE vaccine_records (patient_id INT,vaccine_name VARCHAR(20),age INT,state VARCHAR(20)); INSERT INTO vaccine_records VALUES (1,'Pfizer',35,'California'),(2,'Pfizer',42,'California'),(3,'Moderna',50,'Florida'); INSERT INTO vaccine_records VALUES (4,'Pfizer',60,'California'),(5,'Pfizer',65,'California'),(6,'Johnson',40,'California'); | SELECT MAX(age) FROM vaccine_records WHERE vaccine_name = 'Pfizer' AND state = 'California'; |
Calculate the total cost of green building projects in the GreenBuildings schema | CREATE SCHEMA GreenBuildings; USE GreenBuildings; CREATE TABLE GreenBuildingProjects (id INT,project_name VARCHAR(100),cost DECIMAL(10,2)); INSERT INTO GreenBuildingProjects (id,project_name,cost) VALUES (1,'Solar Panel Installation',150000.00),(2,'Wind Turbine Installation',200000.00); | SELECT SUM(cost) FROM GreenBuildings.GreenBuildingProjects; |
Calculate the total incident count for each product in 2021. | CREATE TABLE ProductSafety (id INT,product_id INT,year INT,incident_count INT); INSERT INTO ProductSafety (id,product_id,year,incident_count) VALUES (1,1,2020,2),(2,1,2019,1),(3,2,2020,0),(4,2,2019,3),(5,3,2021,4),(6,3,2020,1),(7,4,2019,2),(8,4,2020,0),(9,4,2021,3),(10,5,2021,1); | SELECT product_id, SUM(incident_count) as total_incident_count FROM ProductSafety WHERE year = 2021 GROUP BY product_id; |
What is the total spending on humanitarian assistance in the last 3 years? | CREATE TABLE HumanitarianAssistance (Year INT,Spending DECIMAL(10,2)); INSERT INTO HumanitarianAssistance (Year,Spending) VALUES (2020,120000),(2021,150000),(2022,180000),(2023,200000); | SELECT SUM(Spending) FROM HumanitarianAssistance WHERE Year BETWEEN (SELECT MAX(Year) - 2 FROM HumanitarianAssistance) AND MAX(Year); |
Count total number of volunteers and total number of donors | CREATE TABLE volunteers (id INT,joined DATE); CREATE TABLE donors (id INT,last_donation DATE) | SELECT COUNT(DISTINCT v.id) AS total_volunteers, COUNT(DISTINCT d.id) AS total_donors FROM volunteers v, donors d; |
Show all claim records for claim status 'Open' as separate columns for claim ID, claim state, and a column for each claim status value | CREATE TABLE claim (claim_id INT,claim_state VARCHAR(20),claim_status VARCHAR(20)); INSERT INTO claim VALUES (1,'California','Pending'); INSERT INTO claim VALUES (2,'Texas','Open'); | SELECT claim_id, claim_state, MAX(CASE WHEN claim_status = 'Paid' THEN claim_status END) AS Paid, MAX(CASE WHEN claim_status = 'Pending' THEN claim_status END) AS Pending, MAX(CASE WHEN claim_status = 'Open' THEN claim_status END) AS Open FROM claim GROUP BY claim_id, claim_state; |
What is the number of virtual tours in Africa between Q2 and Q4 2022? | CREATE TABLE Continents (id INT,name VARCHAR(255)); INSERT INTO Continents (id,name) VALUES (1,'Africa'),(2,'Europe'),(3,'Asia'),(4,'North America'),(5,'South America'); CREATE TABLE VirtualTours (id INT,continent_id INT,year INT,quarter INT,views INT); INSERT INTO VirtualTours (id,continent_id,year,quarter,views) VALUES (1,1,2022,2,2000),(2,1,2022,3,2500),(3,1,2022,4,3000),(4,2,2022,2,3500),(5,2,2022,3,4000),(6,2,2022,4,4500),(7,3,2022,2,5000),(8,3,2022,3,5500),(9,3,2022,4,6000),(10,4,2022,2,6500),(11,4,2022,3,7000),(12,4,2022,4,7500); | SELECT SUM(vt.views) as total_views FROM VirtualTours vt JOIN Continents c ON vt.continent_id = c.id WHERE c.name = 'Africa' AND vt.year = 2022 AND vt.quarter BETWEEN 2 AND 4; |
What is the average arrival age of visitors in 'sustainable_tourism' table? | CREATE TABLE sustainable_tourism (visitor_id INT,arrival_age INT); INSERT INTO sustainable_tourism (visitor_id,arrival_age) VALUES (1,35),(2,45),(3,28); | SELECT AVG(arrival_age) FROM sustainable_tourism; |
What is the market share of autonomous vehicles by region in 2025? | CREATE TABLE av_sales (id INT,make VARCHAR,model VARCHAR,year INT,region VARCHAR,sold INT); CREATE VIEW av_market_share AS SELECT region,SUM(sold) as total_sold FROM av_sales WHERE model LIKE '%autonomous%' GROUP BY region; | SELECT region, total_sold/SUM(total_sold) OVER (PARTITION BY NULL) as market_share FROM av_market_share WHERE year = 2025; |
What is the total revenue for each genre in the last 3 years? | CREATE TABLE songs (song_id INT,title TEXT,release_year INT,genre TEXT,revenue FLOAT); | SELECT genre, SUM(revenue) FROM songs WHERE release_year >= 2018 GROUP BY genre; |
Calculate the average account balance for customers in each city in the USA. | CREATE TABLE customers (id INT,name VARCHAR(100),age INT,gender VARCHAR(10),city VARCHAR(50),state VARCHAR(50),account_balance DECIMAL(10,2)); | SELECT city, AVG(account_balance) as avg_balance FROM customers WHERE state = 'USA' GROUP BY city; |
Which intelligence operations have been conducted against adversarial nations in the 'intelligence_operations' table? | CREATE TABLE intelligence_operations (id INT,operation_name VARCHAR(50),target_country VARCHAR(50),operation_type VARCHAR(50)); INSERT INTO intelligence_operations (id,operation_name,target_country,operation_type) VALUES (1,'Olympic Games','Iran','Cyberwarfare'),(2,'Bounty Hunter','Russia','Human intelligence'); | SELECT operation_name, target_country, operation_type FROM intelligence_operations WHERE target_country IN ('Iran', 'Russia', 'North Korea', 'China'); |
How many ingredients in the 'lotion' product are not vegan? | CREATE TABLE product_ingredients (product_id INT,ingredient VARCHAR(255),percentage FLOAT,is_vegan BOOLEAN,PRIMARY KEY (product_id,ingredient)); | SELECT COUNT(ingredient) FROM product_ingredients WHERE product_id = (SELECT product_id FROM products WHERE product_name = 'lotion') AND is_vegan = false; |
What is the maximum duration of a space mission led by a female astronaut? | CREATE TABLE Astronauts(id INT,name VARCHAR(50),gender VARCHAR(50)); CREATE TABLE SpaceMissions(id INT,mission VARCHAR(50),leader_id INT,duration FLOAT); INSERT INTO Astronauts(id,name,gender) VALUES (1,'Jane Smith','Female'),(2,'John Doe','Male'); INSERT INTO SpaceMissions(id,mission,leader_id,duration) VALUES (1,'Apollo 11',1,12),(2,'Artemis I',2,15),(3,'Ares III',1,18); | SELECT MAX(duration) FROM SpaceMissions INNER JOIN Astronauts ON SpaceMissions.leader_id = Astronauts.id WHERE Astronauts.gender = 'Female'; |
List all clinics in Arizona that have reduced their rural patient base by over 15% since 2018. | CREATE TABLE clinics (clinic_id INT,name TEXT,location TEXT,rural BOOLEAN);CREATE TABLE patients (patient_id INT,clinic_id INT,year INT,rural BOOLEAN); | SELECT c.name FROM clinics c JOIN (SELECT clinic_id, 100.0 * COUNT(*) FILTER (WHERE rural) / SUM(COUNT(*)) OVER (PARTITION BY clinic_id) AS reduction_ratio FROM patients WHERE year IN (2018, 2022) GROUP BY clinic_id) t ON c.clinic_id = t.clinic_id WHERE t.reduction_ratio > 15.0 AND c.state = 'Arizona'; |
What is the total oil and gas production for each country in H1 2021? | CREATE TABLE country_production_figures (country_code CHAR(2),production_date DATE,oil_production FLOAT,gas_production FLOAT); | SELECT country_code, SUM(oil_production) as total_oil_production, SUM(gas_production) as total_gas_production FROM country_production_figures WHERE production_date BETWEEN '2021-01-01' AND '2021-06-30' GROUP BY country_code; |
What is the total donation amount and number of volunteers for each country? | CREATE TABLE volunteers (id INT,name TEXT,country TEXT); INSERT INTO volunteers (id,name,country) VALUES (1,'Alice','Canada'),(2,'Bob','USA'),(3,'Charlie','Mexico'); CREATE TABLE donations (id INT,amount REAL,program_id INT,donor_id INT,country TEXT); INSERT INTO donations (id,amount,program_id,donor_id,country) VALUES (1,50.0,100,4,'Canada'),(2,100.0,200,5,'Canada'),(3,75.0,100,6,'Mexico'); | SELECT d.country, SUM(d.amount) AS total_donation_amount, COUNT(DISTINCT v.id) AS num_volunteers FROM donations d INNER JOIN volunteers v ON d.donor_id = v.id GROUP BY d.country; |
What is the average number of volunteer hours per volunteer? | CREATE TABLE volunteers (id INT,name VARCHAR(255)); CREATE TABLE volunteer_hours (id INT,volunteer_id INT,hours DECIMAL(10,2)); INSERT INTO volunteers (id,name) VALUES (1,'John'),(2,'Jane'),(3,'Mary'); INSERT INTO volunteer_hours (id,volunteer_id,hours) VALUES (1,1,5),(2,2,10),(3,1,15),(4,3,20); | SELECT volunteer_id, AVG(hours) OVER (PARTITION BY volunteer_id) AS avg_hours_per_volunteer FROM volunteer_hours; |
List all marine species in the 'marine_species' table with a conservation status of 'Vulnerable' | CREATE TABLE marine_species (id INT PRIMARY KEY,species_name VARCHAR(255),conservation_status VARCHAR(255)); INSERT INTO marine_species (id,species_name,conservation_status) VALUES (1001,'Oceanic Whitetip Shark','Vulnerable'),(1002,'Green Sea Turtle','Threatened'),(1003,'Leatherback Sea Turtle','Vulnerable'); | SELECT species_name FROM marine_species WHERE conservation_status = 'Vulnerable'; |
How many streams does artist 'Sia' have in total? | CREATE TABLE Streaming (id INT,artist VARCHAR(50),streams INT); INSERT INTO Streaming (id,artist,streams) VALUES (1,'Sia',1000000),(2,'Taylor Swift',2000000),(3,'Drake',1500000); | SELECT SUM(streams) FROM Streaming WHERE artist = 'Sia'; |
How many interplanetary probes have been launched by India? | CREATE TABLE interplanetary_probes (id INT,country VARCHAR(255),probe_name VARCHAR(255)); INSERT INTO interplanetary_probes (id,country,probe_name) VALUES (1,'India','Chandrayaan 1'),(2,'India','Mangalyaan'),(3,'India','Chandrayaan 2'),(4,'India','Aditya-L1'); | SELECT COUNT(*) FROM interplanetary_probes WHERE country = 'India'; |
Determine the revenue generated from the sale of dishes in a specific region in the last month. | CREATE TABLE inventory (item_id INT,quantity INT,unit_price DECIMAL(5,2)); INSERT INTO inventory (item_id,quantity,unit_price) VALUES (1,10,12.99),(2,20,7.50),(3,30,9.99),(4,40,15.49),(5,50,8.99); CREATE TABLE orders (order_id INT,item_id INT,order_date DATE,restaurant_id INT); INSERT INTO orders (order_id,item_id,order_date,restaurant_id) VALUES (1,1,'2022-03-01',2),(2,3,'2022-03-02',2),(3,2,'2022-03-03',1),(4,4,'2022-03-04',1),(5,5,'2022-03-05',2); CREATE TABLE menu_items (item_id INT,name TEXT,is_vegan BOOLEAN,price DECIMAL(5,2)); INSERT INTO menu_items (item_id,name,is_vegan,price) VALUES (1,'Quinoa Salad',true,12.99),(2,'Beef Burger',false,7.50),(3,'Chickpea Curry',true,9.99),(4,'Cheesecake',false,15.49),(5,'Veggie Pizza',true,8.99); CREATE TABLE restaurants (restaurant_id INT,name TEXT,region TEXT); INSERT INTO restaurants (restaurant_id,name,region) VALUES (1,'Big Burger','East'),(2,'Veggies R Us','Midwest'),(3,'Tasty Bites','West'); | SELECT SUM(i.quantity * m.price) as revenue FROM inventory i JOIN orders o ON i.item_id = o.item_id JOIN menu_items m ON i.item_id = m.item_id JOIN restaurants r ON o.restaurant_id = r.restaurant_id WHERE o.order_date BETWEEN '2022-02-01' AND '2022-02-28' AND r.region = 'Midwest'; |
Delete the workout with workout_id 1 | CREATE TABLE workouts (workout_id INT,member_id INT,gym_id INT,workout_date DATE,calories INT); INSERT INTO workouts (workout_id,member_id,gym_id,workout_date,calories) VALUES (1,1,1,'2022-01-01',300),(2,2,1,'2022-01-02',400),(3,3,2,'2022-01-03',500); | DELETE FROM workouts WHERE workout_id = 1; |
What is the average fare collected per trip for buses in the month of January 2022? | CREATE TABLE bus_routes (route_id INT,vehicle_type VARCHAR(10),fare DECIMAL(5,2)); CREATE TABLE fares (fare_id INT,route_id INT,fare_amount DECIMAL(5,2),fare_collection_date DATE); INSERT INTO bus_routes VALUES (1,'Bus',2.50),(2,'Bus',3.00); INSERT INTO fares VALUES (1,1,2.50,'2022-01-01'),(2,1,2.50,'2022-01-02'),(3,2,3.00,'2022-01-03'); | SELECT AVG(f.fare_amount) FROM fares f JOIN bus_routes br ON f.route_id = br.route_id WHERE f.fare_collection_date BETWEEN '2022-01-01' AND '2022-01-31' AND br.vehicle_type = 'Bus'; |
How many public outreach events have been held at each excavation site, and what was the average attendance? | CREATE TABLE ExcavationSites (SiteID int,SiteName varchar(50),Location varchar(50)); CREATE TABLE PublicOutreach (EventID int,SiteID int,EventType varchar(20),Attendance int); | SELECT ExcavationSites.SiteName, AVG(PublicOutreach.Attendance) AS AverageAttendance, COUNT(PublicOutreach.EventID) AS NumberOfEvents FROM ExcavationSites INNER JOIN PublicOutreach ON ExcavationSites.SiteID = PublicOutreach.SiteID GROUP BY ExcavationSites.SiteName; |
Show all records in digital_divide table with 'Female' gender | CREATE TABLE digital_divide (region VARCHAR(255),year INT,gender VARCHAR(10),internet_accessibility FLOAT,mobile_accessibility FLOAT); INSERT INTO digital_divide (region,year,gender,internet_accessibility,mobile_accessibility) VALUES ('North America',2015,'Male',0.85,0.93),('South America',2016,'Female',0.68,0.82),('Asia',2017,'Male',0.52,0.81); | SELECT * FROM digital_divide WHERE gender = 'Female'; |
What is the number of cases in each court, broken down by case type, case status, and year? | CREATE TABLE CourtCases (CourtName text,CaseType text,CaseStatus text,Year int,NumCases int); INSERT INTO CourtCases VALUES ('Court1','Assault','Open',2022,30,'2022-01-01'),('Court1','Theft','Closed',2022,25,'2022-01-01'),('Court2','Assault','Open',2022,28,'2022-01-01'),('Court2','Theft','Closed',2022,22,'2022-01-01'); | SELECT CourtName, CaseType, CaseStatus, Year, SUM(NumCases) FROM CourtCases GROUP BY CourtName, CaseType, CaseStatus, Year; |
Update the explainability score for 'modelB' to 75 in the 'creative_ai' table. | CREATE TABLE creative_ai (model_name TEXT,explainability_score INTEGER); INSERT INTO creative_ai (model_name,explainability_score) VALUES ('modelB',72),('modelD',78); | UPDATE creative_ai SET explainability_score = 75 WHERE model_name = 'modelB'; |
Which regions have more than 5 articles published? | CREATE TABLE regions (id INT,name TEXT); CREATE TABLE articles (id INT,title TEXT,content TEXT,region_id INT); INSERT INTO regions (id,name) VALUES (1,'North'),(2,'South'),(3,'East'),(4,'West'); INSERT INTO articles (id,title,content,region_id) VALUES (1,'Article 1','Content 1',1),(2,'Article 2','Content 2',2),(3,'Article 3','Content 3',2),(4,'Article 4','Content 4',3),(5,'Article 5','Content 5',4); | SELECT regions.name, COUNT(articles.id) FROM regions INNER JOIN articles ON regions.id = articles.region_id GROUP BY regions.name HAVING COUNT(articles.id) > 5; |
What is the average budget for technology for social good projects in Europe? | CREATE TABLE social_good (id INT,project_name TEXT,budget INT,region TEXT); INSERT INTO social_good (id,project_name,budget,region) VALUES (1,'Tech4Good Initiative',50000,'Europe'),(2,'SocialTech Program',75000,'North America'),(3,'DigitalDivide Fund',60000,'Europe'); | SELECT AVG(budget) as avg_budget FROM social_good WHERE region = 'Europe'; |
What is the total number of articles published by authors from different regions in the 'media_ethics' table? | CREATE TABLE media_ethics (article_id INT,author VARCHAR(50),title VARCHAR(100),published_date DATE,category VARCHAR(30),author_region VARCHAR(30)); INSERT INTO media_ethics (article_id,author,title,published_date,category,author_region) VALUES (1,'John Doe','Article 5','2021-01-05','Ethics','North America'),(2,'Jane Smith','Article 6','2021-01-06','Ethics','Europe'); | SELECT author_region, COUNT(article_id) AS total_articles FROM media_ethics GROUP BY author_region; |
What is the maximum number of visitors to any sustainable destination in South America in a month? | CREATE TABLE MonthlyVisitors (visitor_id INT,destination VARCHAR(50),country VARCHAR(50),visit_month DATE); INSERT INTO MonthlyVisitors (visitor_id,destination,country,visit_month) VALUES (1,'Eco Park','Brazil','2022-02-01'); INSERT INTO MonthlyVisitors (visitor_id,destination,country,visit_month) VALUES (2,'Green Beach','Argentina','2022-03-01'); | SELECT MAX(visitor_id) FROM MonthlyVisitors WHERE country IN ('South America') AND visit_month BETWEEN '2022-01-01' AND '2022-12-31'; |
What is the total number of military innovation projects and humanitarian assistance missions? | CREATE TABLE Military_Innovation (Project_ID INT,Project_Name VARCHAR(50),Start_Date DATE); INSERT INTO Military_Innovation (Project_ID,Project_Name,Start_Date) VALUES (1,'Stealth Fighter Project','1980-01-01'); CREATE TABLE Humanitarian_Assistance (Mission_ID INT,Mission_Name VARCHAR(50),Location VARCHAR(50),Start_Date DATE,End_Date DATE); INSERT INTO Humanitarian_Assistance (Mission_ID,Mission_Name,Location,Start_Date,End_Date) VALUES (1,'Operation Restore Hope','Somalia','1992-01-01','1993-12-31'); | SELECT COUNT(*) as Total_Projects FROM Military_Innovation; SELECT COUNT(*) as Total_Missions FROM Humanitarian_Assistance; |
Which military innovations were introduced in the last 2 years? | CREATE TABLE military_innovations (innovation_id INT,innovation_name VARCHAR(255),year INT); INSERT INTO military_innovations (innovation_id,innovation_name,year) VALUES (1,'Stealth Drone',2019),(2,'Cyber Warfare Unit',2018),(3,'Laser Weapon System',2020),(4,'Artificial Intelligence in Battlefield',2021),(5,'Hypersonic Missile',2019); | SELECT innovation_name FROM military_innovations WHERE year BETWEEN (SELECT YEAR(CURRENT_DATE) - 2) AND YEAR(CURRENT_DATE); |
List the top 5 most popular game genres in the last month, along with the number of games released in each genre and the percentage of VR games. | CREATE TABLE games (id INT,title VARCHAR(50),release_date DATE,genre VARCHAR(20),vr_compatible VARCHAR(5)); | SELECT g.genre, COUNT(g.id) AS games_released, SUM(CASE WHEN g.release_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) THEN 1 ELSE 0 END) AS popular_in_last_month, 100.0 * SUM(CASE WHEN g.vr_compatible = 'Yes' THEN 1 ELSE 0 END) / COUNT(g.id) AS vr_percentage FROM games g GROUP BY g.genre ORDER BY games_released DESC, popular_in_last_month DESC, vr_percentage DESC LIMIT 5; |
Delete the 'player' record with ID '123' from the 'players' table | CREATE TABLE players (id INT PRIMARY KEY,first_name VARCHAR(50),last_name VARCHAR(50),position VARCHAR(50),team VARCHAR(50)); | DELETE FROM players WHERE id = 123; |
What is the average number of military equipment repairs per month? | CREATE TABLE Equipment_Repairs (ID INT,Month VARCHAR(50),Year INT,Repairs INT); INSERT INTO Equipment_Repairs (ID,Month,Year,Repairs) VALUES (1,'January',2017,150),(2,'February',2017,120),(3,'March',2017,180); | SELECT Month, AVG(Repairs) FROM Equipment_Repairs GROUP BY Month; |
Count the number of properties in each 'building_type' in green_buildings. | CREATE TABLE green_buildings (property_id INT,building_type TEXT,construction_year INT); INSERT INTO green_buildings VALUES (1,'Apartment',2010),(2,'House',2005),(3,'Townhouse',2015) | SELECT building_type, COUNT(*) AS num_properties FROM green_buildings GROUP BY building_type; |
What's the average gas price for transactions on the Binance Smart Chain? | CREATE TABLE gas_prices (id INT PRIMARY KEY,tx_hash VARCHAR(255),gas_price DECIMAL(10,2),chain VARCHAR(255)); INSERT INTO gas_prices (id,tx_hash,gas_price,chain) VALUES (1,'tx1',50,'Binance Smart Chain'),(2,'tx2',75,'Binance Smart Chain'); | SELECT AVG(gas_price) FROM gas_prices WHERE chain = 'Binance Smart Chain'; |
Identify countries with a significant increase in sustainable tourism scores between 2018 and 2019. | CREATE TABLE CountryScores (id INT,country_id INT,year INT,score INT); INSERT INTO CountryScores (id,country_id,year,score) VALUES (1,1,2018,70); INSERT INTO CountryScores (id,country_id,year,score) VALUES (2,1,2019,75); INSERT INTO CountryScores (id,country_id,year,score) VALUES (3,2,2018,80); INSERT INTO CountryScores (id,country_id,year,score) VALUES (4,2,2019,85); INSERT INTO CountryScores (id,country_id,year,score) VALUES (5,3,2018,60); INSERT INTO CountryScores (id,country_id,year,score) VALUES (6,3,2019,65); INSERT INTO CountryScores (id,country_id,year,score) VALUES (7,4,2018,90); INSERT INTO CountryScores (id,country_id,year,score) VALUES (8,4,2019,95); | SELECT country_id, (score - LAG(score, 1) OVER (PARTITION BY country_id ORDER BY year)) as score_change FROM CountryScores WHERE score_change >= 5; |
List the names and total spending of all rural infrastructure projects in Africa? | CREATE TABLE project (project_id INT,name VARCHAR(50),location VARCHAR(50),spending FLOAT); CREATE TABLE continent (continent_id INT,name VARCHAR(50),description TEXT); | SELECT p.name, SUM(p.spending) FROM project p JOIN continent c ON p.location = c.name WHERE c.name = 'Africa' GROUP BY p.name; |
List all VR games with a rating above 8.5. | CREATE TABLE games (id INT,name VARCHAR(20),type VARCHAR(20),rating FLOAT); INSERT INTO games (id,name,type,rating) VALUES (1,'GameA','VR',8.7); INSERT INTO games (id,name,type,rating) VALUES (2,'GameB','Non-VR',9.1); | SELECT * FROM games WHERE type = 'VR' AND rating > 8.5; |
What is the number of drugs approved for use in 'RegionH' between Q1 and Q3 of 2020? | CREATE TABLE drug_approval(drug_name TEXT,region TEXT,approval_quarter INT); INSERT INTO drug_approval (drug_name,region,approval_quarter) VALUES ('DrugA','RegionX',1),('DrugB','RegionY',2),('DrugD','RegionH',1),('DrugC','RegionZ',4),('DrugE','RegionH',3),('DrugF','RegionH',2); | SELECT COUNT(*) FROM drug_approval WHERE region = 'RegionH' AND approval_quarter BETWEEN 1 AND 3; |
What is the average length of all subway lines in Seoul, South Korea? | CREATE TABLE subway (id INT,name VARCHAR(255),location VARCHAR(255),length FLOAT); INSERT INTO subway (id,name,location,length) VALUES (1,'Line 1','Seoul,South Korea',19.6); | SELECT AVG(length) FROM subway WHERE location = 'Seoul, South Korea'; |
What is the total number of donations made by each donor? | CREATE TABLE Donor (id INT,name VARCHAR(255)); | SELECT Donor.name, SUM(Donation.amount) as total_donations FROM Donor JOIN Donation ON Donor.id = Donation.donor_id GROUP BY Donor.name; |
How many electric vehicles were added to the fleet in New York in the past month? | CREATE TABLE fleet_data (id INT,vehicle_type VARCHAR(20),added_date DATE,city VARCHAR(20)); INSERT INTO fleet_data (id,vehicle_type,added_date,city) VALUES (1,'Electric','2022-04-15','New York'); INSERT INTO fleet_data (id,vehicle_type,added_date,city) VALUES (2,'Electric','2022-04-20','New York'); INSERT INTO fleet_data (id,vehicle_type,added_date,city) VALUES (3,'Conventional','2022-04-25','New York'); | SELECT COUNT(*) as num_electric_vehicles FROM fleet_data WHERE vehicle_type = 'Electric' AND city = 'New York' AND added_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 1 MONTH) AND CURDATE(); |
Show me the name and start date of all climate finance projects in 'Asia' that ended after 2010. | CREATE TABLE climate_finance (project_id INT,project_name VARCHAR(255),location VARCHAR(255),start_date DATE,end_date DATE); | SELECT project_name, start_date FROM climate_finance WHERE location = 'Asia' AND end_date >= '2010-12-31'; |
List all construction labor statistics for the state of New York, broken down by city. | CREATE TABLE labor_statistics (id INT,city VARCHAR(255),state VARCHAR(255),hourly_wage FLOAT); | SELECT city, state, hourly_wage FROM labor_statistics WHERE state = 'New York' ORDER BY city; |
What is the total oil production, in barrels, for all wells in the Permian Basin, for the year 2020? | CREATE TABLE OilWells (WellID INT,Location VARCHAR(20),ProductionYear INT,OilProduction INT); INSERT INTO OilWells (WellID,Location,ProductionYear,OilProduction) VALUES (1,'Permian Basin',2020,900000),(2,'Permian Basin',2019,800000),(3,'North Sea',2021,700000); | SELECT SUM(OilProduction) FROM OilWells WHERE Location = 'Permian Basin' AND ProductionYear = 2020; |
Display the total revenue generated from each vendor in the 'sales' table. | CREATE TABLE sales (id INT PRIMARY KEY,vendor VARCHAR(50),quantity INT,species VARCHAR(50),price DECIMAL(5,2)); INSERT INTO sales (id,vendor,quantity,species,price) VALUES (1,'Seafood Haven',20,'Salmon',12.99),(2,'Sea Bounty',30,'Tilapia',9.49),(3,'Sea Bounty',15,'Cod',14.50); | SELECT vendor, SUM(quantity * price) FROM sales GROUP BY vendor; |
What is the total number of ethical AI training sessions conducted in 2021? | CREATE TABLE trainings(id INT,date DATE,location TEXT,participants INT); INSERT INTO trainings(id,date,location,participants) VALUES (1,'2021-01-10','New York',25); INSERT INTO trainings(id,date,location,participants) VALUES (2,'2021-03-15','San Francisco',30); INSERT INTO trainings(id,date,location,participants) VALUES (3,'2022-06-30','London',20); | SELECT SUM(participants) FROM trainings WHERE YEAR(date) = 2021 AND location LIKE '%AI%'; |
What is the average quantity of sustainable fabric sourced from Oceania? | CREATE TABLE sustainable_fabric (id INT,fabric_type VARCHAR(20),quantity INT,continent VARCHAR(20)); INSERT INTO sustainable_fabric (id,fabric_type,quantity,continent) VALUES (1,'organic_cotton',500,'Australia'); INSERT INTO sustainable_fabric (id,fabric_type,quantity,continent) VALUES (2,'recycled_polyester',300,'New Zealand'); | SELECT AVG(quantity) FROM sustainable_fabric WHERE continent IN ('Australia', 'New Zealand'); |
What is the trend in health equity metrics for a specific community based on age? | CREATE TABLE HealthEquityMetrics (MetricID INT,Community VARCHAR(25),Age INT,MetricDate DATE,Value FLOAT); INSERT INTO HealthEquityMetrics (MetricID,Community,Age,MetricDate,Value) VALUES (1,'South Bronx',25,'2021-01-01',78.5); INSERT INTO HealthEquityMetrics (MetricID,Community,Age,MetricDate,Value) VALUES (2,'South Bronx',30,'2021-02-15',79.2); INSERT INTO HealthEquityMetrics (MetricID,Community,Age,MetricDate,Value) VALUES (3,'South Bronx',35,'2021-03-30',80.1); INSERT INTO HealthEquityMetrics (MetricID,Community,Age,MetricDate,Value) VALUES (4,'South Bronx',40,'2021-04-15',81.0); | SELECT Age, Value FROM HealthEquityMetrics WHERE Community = 'South Bronx' ORDER BY Age; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.