instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the total number of climate mitigation and adaptation projects in North America? | CREATE TABLE climate_projects_na (id INT,country VARCHAR(50),type VARCHAR(50),status VARCHAR(50)); INSERT INTO climate_projects_na (id,country,type,status) VALUES (1,'USA','climate mitigation','completed'),(2,'Canada','climate adaptation','in progress'),(3,'Mexico','climate mitigation','completed'),(4,'USA','climate ad... | SELECT COUNT(*) FROM climate_projects_na WHERE country IN ('USA', 'Canada', 'Mexico') AND (type = 'climate mitigation' OR type = 'climate adaptation'); |
What is the average property price for buildings in the UrbanSustainability schema with a wind turbine installation? | CREATE TABLE UrbanSustainability.WindTurbineBuildings (id INT,price FLOAT); INSERT INTO UrbanSustainability.WindTurbineBuildings (id,price) VALUES (1,350000.0),(2,650000.0); | SELECT AVG(price) FROM UrbanSustainability.WindTurbineBuildings; |
Count the number of mining incidents per month in 2021, broken down by incident type. | CREATE TABLE incident_type_distribution (id INT,date DATE,incident_type TEXT); INSERT INTO incident_type_distribution (id,date,incident_type) VALUES (1,'2021-02-03','equipment_failure'); INSERT INTO incident_type_distribution (id,date,incident_type) VALUES (2,'2021-03-15','safety_violation'); | SELECT DATE_PART('month', date) AS month, incident_type, COUNT(*) FROM incident_type_distribution WHERE date >= '2021-01-01' AND date < '2022-01-01' GROUP BY month, incident_type; |
What is the total capacity of renewable energy projects in 'California' in the 'RenewableEnergyProjects' table? | CREATE TABLE RenewableEnergyProjects (id INT,name VARCHAR(100),location VARCHAR(100),type VARCHAR(50),capacity FLOAT); | SELECT SUM(capacity) FROM RenewableEnergyProjects WHERE location = 'California'; |
What are the CO2 emissions of all green buildings in the 'green_buildings' schema, grouped by country? | CREATE SCHEMA if not exists green_buildings; CREATE TABLE if not exists green_buildings.buildings (id INT,building_name VARCHAR,country VARCHAR,co2_emissions FLOAT); INSERT INTO green_buildings.buildings (id,building_name,country,co2_emissions) VALUES (1,'Green Building 1','USA',100),(2,'Green Building 2','Canada',120)... | SELECT country, SUM(co2_emissions) FROM green_buildings.buildings GROUP BY country; |
What is the number of unique users who have read each investigative report in the current month? | CREATE TABLE reports (report_id INT,report_title VARCHAR(255),user_id INT); INSERT INTO reports (report_id,report_title,user_id) VALUES (1,'Investigation 1',1),(2,'Investigation 2',2),(3,'Investigation 3',3); | SELECT report_title, COUNT(DISTINCT user_id) FROM reports WHERE MONTH(report_date) = MONTH(GETDATE()) GROUP BY report_title; |
What are the species and populations for species found in a specific forest? | CREATE TABLE Forests (ForestID INT PRIMARY KEY,Name VARCHAR(50),Country VARCHAR(50),Hectares FLOAT); CREATE TABLE Species (SpeciesID INT PRIMARY KEY,Name VARCHAR(50),ForestID INT,FOREIGN KEY (ForestID) REFERENCES Forests(ForestID)); CREATE TABLE Wildlife (WildlifeID INT PRIMARY KEY,Species VARCHAR(50),Population INT,Fo... | SELECT Species.Name, Wildlife.Population FROM Species INNER JOIN Wildlife ON Species.SpeciesID = Wildlife.SpeciesID WHERE Species.Name = 'Oak'; |
Which countries have the most vegan-friendly products? | CREATE TABLE countries (country_id INT PRIMARY KEY,country_name VARCHAR(50)); INSERT INTO countries (country_id,country_name) VALUES (1,'India'),(2,'USA'),(3,'Canada'),(4,'Germany'); CREATE TABLE vegan_products (product_id INT,country_id INT,FOREIGN KEY (country_id) REFERENCES countries(country_id)); INSERT INTO vegan_... | SELECT country_name, COUNT(*) as product_count FROM vegan_products JOIN countries ON vegan_products.country_id = countries.country_id GROUP BY country_id ORDER BY product_count DESC; |
What is the percentage of community health workers who have received cultural competency training, by county? | CREATE TABLE cultural_competency_training (worker_id INT,county TEXT,received_training BOOLEAN); INSERT INTO cultural_competency_training (worker_id,county,received_training) VALUES (1,'Los Angeles',true),(2,'San Francisco',false),(3,'San Diego',true); | SELECT county, 100.0 * SUM(received_training) / COUNT(*) as pct_trained FROM cultural_competency_training GROUP BY county; |
List all smart contracts and their developers that were deployed in '2022'? | CREATE TABLE smart_contracts (id INT,name TEXT,developer TEXT,deployment_date DATE); INSERT INTO smart_contracts (id,name,developer,deployment_date) VALUES (1,'Contract1','Developer1','2022-01-01'),(2,'Contract2','Developer2','2021-12-01'); | SELECT smart_contracts.name, smart_contracts.developer FROM smart_contracts INNER JOIN (SELECT * FROM dates WHERE year = 2022) AS dates ON smart_contracts.deployment_date = dates.date |
Insert a new record for a policy advocacy event on November 15th, 2022, in the 'Events' table. | CREATE TABLE Events (EventID INT,EventName VARCHAR(50),EventDate DATE,EventType VARCHAR(50)); INSERT INTO Events (EventID,EventName,EventDate,EventType) VALUES (1,'Disability Rights Rally','2022-07-23','Protest'),(2,'Inclusion Panel Discussion','2022-08-12','Seminar'),(3,'ADA Anniversary Celebration','2022-07-26','Cele... | INSERT INTO Events (EventID, EventName, EventDate, EventType) VALUES (4, 'Accessibility Policy Meeting', '2022-11-15', 'Meeting'); |
What's the change in volunteer hours per month? | CREATE TABLE VolunteerHours (Id INT,VolunteerId INT,Hours DECIMAL(10,2),HoursDate DATE); INSERT INTO VolunteerHours VALUES (1,1,10.00,'2022-01-01'),(2,1,15.00,'2022-02-01'); | SELECT EXTRACT(MONTH FROM HoursDate) as Month, (LAG(SUM(Hours)) OVER (PARTITION BY VolunteerId ORDER BY HoursDate) - SUM(Hours)) as HoursChange FROM VolunteerHours GROUP BY Month; |
Find the total number of hybrid vehicles sold in Q2 of 2021 and Q3 of 2021 by manufacturer? | CREATE TABLE Hybrid_Sales (Id INT,Manufacturer VARCHAR(50),Sales INT,Quarter VARCHAR(10),Year INT); INSERT INTO Hybrid_Sales (Id,Manufacturer,Sales,Quarter,Year) VALUES (1,'Toyota',1500,'Q2',2021); INSERT INTO Hybrid_Sales (Id,Manufacturer,Sales,Quarter,Year) VALUES (2,'Honda',1200,'Q3',2021); | SELECT Manufacturer, SUM(Sales) FROM Hybrid_Sales WHERE (Quarter = 'Q2' AND Year = 2021) OR (Quarter = 'Q3' AND Year = 2021) AND Manufacturer IN (SELECT Manufacturer FROM Hybrid_Sales WHERE Type = 'Hybrid') GROUP BY Manufacturer; |
CREATE a table named 'education_programs' | CREATE TABLE education_programs (id INT PRIMARY KEY,name VARCHAR(255),description TEXT,target_species VARCHAR(255),start_date DATE,end_date DATE); | CREATE TABLE education_programs (id INT PRIMARY KEY, name VARCHAR(255), description TEXT, target_species VARCHAR(255), start_date DATE, end_date DATE); |
Insert new records for the "supply_chain" table with vendor "Organic Farm 123" and risk scores 3, 4, and 5 | CREATE TABLE supply_chain (id INT,vendor VARCHAR(255),risk_score INT); | INSERT INTO supply_chain (vendor, risk_score) VALUES ('Organic Farm 123', 3), ('Organic Farm 123', 4), ('Organic Farm 123', 5); |
List all safety incidents reported in chemical manufacturing plants in Brazil in June 2021. | CREATE TABLE PlantSafety (id INT,plant_location VARCHAR(50),incident_date DATE); INSERT INTO PlantSafety (id,plant_location,incident_date) VALUES (1,'Brazil','2021-06-15'),(2,'Canada','2021-12-21'),(3,'Brazil','2021-06-05'); | SELECT id, plant_location FROM PlantSafety WHERE plant_location = 'Brazil' AND EXTRACT(MONTH FROM incident_date) = 6 AND EXTRACT(YEAR FROM incident_date) = 2021; |
Identify the top 3 departments with the highest average salaries. | CREATE TABLE Employees (EmployeeID int,EmployeeName varchar(50),Department varchar(50),Salary float,Gender varchar(10)); INSERT INTO Employees (EmployeeID,EmployeeName,Department,Salary,Gender) VALUES (1,'John Doe','IT',80000,'Male'),(2,'Jane Smith','HR',70000,'Female'),(3,'Mike Johnson','IT',85000,'Male'); | SELECT Department, AVG(Salary) as Avg_Salary, RANK() OVER (ORDER BY AVG(Salary) DESC) as Department_Rank FROM Employees GROUP BY Department HAVING Department_Rank <= 3; |
What is the total billing amount for each case in the 'billing' table, grouped by case type? | CREATE TABLE cases (case_id INT,case_type VARCHAR(255)); INSERT INTO cases (case_id,case_type) VALUES (1,'Criminal'),(2,'Family'),(3,'Personal Injury'),(4,'Criminal'),(5,'Family'); CREATE TABLE billing (bill_id INT,case_id INT,amount DECIMAL(10,2)); INSERT INTO billing (bill_id,case_id,amount) VALUES (1,1,500.00),(2,1,... | SELECT cases.case_type, SUM(billing.amount) FROM billing JOIN cases ON billing.case_id = cases.case_id GROUP BY cases.case_type; |
What is the total number of conservation efforts for 'Turtle' and 'Shark' species? | CREATE TABLE conservation_efforts (effort_id INT,species_name VARCHAR(50),year INT,description TEXT); INSERT INTO conservation_efforts (effort_id,species_name,year,description) VALUES (1,'Turtle',2005,'Hawaiian green turtle recovery'),(2,'Clownfish',2010,'Clownfish conservation program'),(3,'Shark',2008,'Shark finning ... | SELECT COUNT(*) FROM conservation_efforts WHERE species_name IN ('Turtle', 'Shark'); |
What is the total number of marine pollution incidents in the South China Sea, grouped by pollutant type? | CREATE TABLE marine_pollution_incidents (incident_id INTEGER,incident_date DATE,pollutant_type TEXT,ocean TEXT); | SELECT pollutant_type, COUNT(incident_id) FROM marine_pollution_incidents WHERE ocean = 'South China Sea' GROUP BY pollutant_type; |
How many electric vehicles were sold in Canada in 2021? | CREATE TABLE Sales (year INT,country VARCHAR(50),vehicle_type VARCHAR(50),quantity INT); INSERT INTO Sales (year,country,vehicle_type,quantity) VALUES (2021,'Canada','Electric',75000); | SELECT SUM(quantity) FROM Sales WHERE year = 2021 AND country = 'Canada' AND vehicle_type = 'Electric'; |
How many customers have taken out socially responsible loans? | CREATE TABLE customers (id INT,name TEXT); CREATE TABLE loans (id INT,customer_id INT,amount REAL,socially_responsible BOOLEAN); | SELECT COUNT(DISTINCT customers.id) FROM customers JOIN loans ON customers.id = loans.customer_id WHERE loans.socially_responsible = TRUE; |
List the names of all visitors who attended events in both 'New York' and 'Los Angeles'. | CREATE TABLE Events (id INT,name TEXT,location TEXT); CREATE TABLE Visitors_Events (visitor_id INT,event_id INT); INSERT INTO Events (id,name,location) VALUES (1,'Art Exhibition','New York'),(2,'Music Festival','Los Angeles'); INSERT INTO Visitors_Events (visitor_id,event_id) VALUES (1,1),(1,2); | SELECT Visitors_Events.visitor_id FROM Visitors_Events INNER JOIN Events ON Visitors_Events.event_id = Events.id GROUP BY Visitors_Events.visitor_id HAVING COUNT(DISTINCT Events.location) = 2; |
Insert a new donor with ID '5', name 'Sophia Lee', and donation amount '700' | CREATE TABLE donors (donor_id INT,donor_name VARCHAR(30),donation_amount DECIMAL(5,2)); INSERT INTO donors (donor_id,donor_name,donation_amount) VALUES (1,'Jane Doe',300),(2,'Mary Smith',400),(3,'Bob Johnson',200),(5,'Sophia Lee',700); | INSERT INTO donors (donor_id, donor_name, donation_amount) VALUES (5, 'Sophia Lee', 700); |
What is the average response time for fire departments in the state of Texas by county? | CREATE TABLE fire_department (id INT,county VARCHAR(255),response_time INT); | SELECT county, AVG(response_time) as avg_response_time FROM fire_department GROUP BY county; |
Add a new renewable energy project to the 'renewable_energy_projects' table for a solar farm project initiated by 'SunStride' in 2023 with a capacity of 250 MW | CREATE TABLE renewable_energy_projects (id INT,project_type VARCHAR(255),initiator VARCHAR(255),initiated_year INT,capacity FLOAT); | INSERT INTO renewable_energy_projects (id, project_type, initiator, initiated_year, capacity) VALUES (2, 'solar farm', 'SunStride', 2023, 250); |
Delete all records for organizations in the Northeast region with an average donation of less than $100. | CREATE TABLE organizations (id INT,name TEXT,region TEXT,avg_donation DECIMAL(10,2)); INSERT INTO organizations (id,name,region,avg_donation) VALUES (1,'Habitat for Humanity','Northeast',150.00),(2,'Red Cross','Northeast',125.00),(3,'UNICEF','Northeast',50.00); | DELETE FROM organizations WHERE region = 'Northeast' AND avg_donation < 100.00; |
Update the speed of vessel with ID 123 to 25 knots in the VESSEL_PERFORMANCE table | CREATE TABLE VESSEL_PERFORMANCE (ID INT,VESSEL_ID INT,SPEED INT,DATE DATE); | UPDATE VESSEL_PERFORMANCE SET SPEED = 25 WHERE VESSEL_ID = 123; |
What is the total number of free admission days offered by museums in Australia during 2020? | CREATE TABLE Free_Admission_Days (id INT,country VARCHAR(255),year INT,number_of_days INT); | SELECT SUM(number_of_days) FROM Free_Admission_Days WHERE country = 'Australia' AND year = 2020; |
What is the maximum salary in the Engineering department? | CREATE TABLE Employees (EmployeeID INT,Department VARCHAR(20),Salary FLOAT); INSERT INTO Employees (EmployeeID,Department,Salary) VALUES (1,'IT',75000.00),(2,'IT',70000.00),(3,'Engineering',95000.00),(4,'Finance',85000.00); | SELECT MAX(Salary) FROM Employees WHERE Department = 'Engineering'; |
What is the total number of visitors from Asia? | CREATE TABLE VisitorDemographics (visitor_id INT,country VARCHAR(50),num_visits INT); INSERT INTO VisitorDemographics (visitor_id,country,num_visits) VALUES (1001,'Japan',2),(1002,'China',5),(1003,'United States',3); | SELECT SUM(num_visits) FROM VisitorDemographics WHERE country IN ('Japan', 'China', 'India', 'South Korea', 'Indonesia'); |
What is the running total of Holmium production by month? | CREATE TABLE production (country VARCHAR(255),element VARCHAR(255),quantity INT,year INT,month INT); INSERT INTO production (country,element,quantity,year,month) VALUES ('China','Holmium',1000,2018,1),('China','Holmium',1200,2018,2),('China','Holmium',1400,2018,3),('China','Holmium',1600,2018,4),('China','Holmium',1800... | SELECT year, month, SUM(quantity) OVER (PARTITION BY element ORDER BY year, month) as running_total FROM production WHERE element = 'Holmium' ORDER BY year, month; |
List all circular economy initiatives in the 'Energy' sector. | CREATE TABLE Sectors (id INT,sector VARCHAR(255)); INSERT INTO Sectors (id,sector) VALUES (1,'Energy'),(2,'Manufacturing'),(3,'Agriculture'); CREATE TABLE Initiatives (id INT,name VARCHAR(255),sector_id INT); INSERT INTO Initiatives (id,name,sector_id) VALUES (1,'ProjectA',1),(2,'ProjectB',2),(3,'ProjectC',1); | SELECT Initiatives.name FROM Initiatives JOIN Sectors ON Initiatives.sector_id = Sectors.id WHERE Sectors.sector = 'Energy'; |
Calculate the average transaction amount for each salesperson | CREATE TABLE salesperson_transactions (transaction_id INT,salesperson_id INT,amount DECIMAL(10,2)); INSERT INTO salesperson_transactions (transaction_id,salesperson_id,amount) VALUES (1,1,500.00),(2,1,300.00),(3,2,700.00); | SELECT s.id, AVG(st.amount) as avg_transaction_amount FROM salesperson s JOIN salesperson_transactions st ON s.id = st.salesperson_id GROUP BY s.id; |
What is the rank of the most common mental health condition treated in Brazil? | CREATE TABLE conditions (condition_id INT,condition VARCHAR(50)); INSERT INTO conditions (condition_id,condition) VALUES (1,'Depression'),(2,'Anxiety'),(3,'Bipolar Disorder'),(4,'Depression'),(5,'Brazil'); CREATE TABLE patients (patient_id INT,condition_id INT); INSERT INTO patients (patient_id,condition_id) VALUES (1,... | SELECT conditions.condition, ROW_NUMBER() OVER(ORDER BY COUNT(patients.condition_id) DESC) AS rank FROM conditions INNER JOIN patients ON conditions.condition_id = patients.condition_id GROUP BY conditions.condition; |
What is the minimum explainability score for creative AI applications in the Creative_AI table? | CREATE TABLE Creative_AI (app_name TEXT,explainability_score INT); INSERT INTO Creative_AI (app_name,explainability_score) VALUES ('AI Painter',65),('AI Poet',72),('AI Music Composer',68); | SELECT MIN(explainability_score) FROM Creative_AI; |
What is the total number of criminal justice reform initiatives in the justice_schemas.criminal_justice_reform table, categorized by the primary goal of the initiative? | CREATE TABLE justice_schemas.criminal_justice_reform (id INT PRIMARY KEY,initiative_name TEXT,primary_goal TEXT); | SELECT primary_goal, COUNT(*) FROM justice_schemas.criminal_justice_reform GROUP BY primary_goal; |
What is the total quantity of menu items sold by each chef in the past year? | CREATE TABLE chefs (chef_id INT,name VARCHAR(100),age INT); CREATE TABLE menus (menu_id INT,name VARCHAR(100),chef_id INT,category VARCHAR(50),price DECIMAL(5,2),quantity INT); INSERT INTO chefs (chef_id,name,age) VALUES (1,'John Doe',35),(2,'Jane Smith',40); | SELECT chef_id, name, SUM(quantity) as total_quantity FROM chefs JOIN menus ON chefs.chef_id = menus.chef_id JOIN orders ON menus.menu_id = order_items.menu_id JOIN (SELECT order_id, MAX(order_date) as max_order_date FROM orders GROUP BY order_id) x ON orders.order_id = x.order_id AND orders.order_date = x.max_order_da... |
List the rock types in mines with a production metric greater than 40000 and located in Nevada. | CREATE TABLE geological_survey (id INT,mine_id INT,rock_type VARCHAR(50),FOREIGN KEY (mine_id) REFERENCES mines(id)); INSERT INTO geological_survey (id,mine_id,rock_type) VALUES (3,5,'Limestone'); INSERT INTO geological_survey (id,mine_id,rock_type) VALUES (4,6,'Sandstone'); | SELECT gs.rock_type FROM geological_survey gs JOIN mines m ON gs.mine_id = m.id WHERE m.production_metric > 40000 AND m.location = 'Nevada'; |
Delete the record with name 'Dr. Jane Smith' in 'healthcare_staff' table | CREATE TABLE healthcare_staff (name VARCHAR(255),gender VARCHAR(255),position VARCHAR(255),hospital_id INT); INSERT INTO healthcare_staff (name,gender,position,hospital_id) VALUES ('Dr. Jane Smith','Female','Doctor',1),('Dr. Maria Garcia','Female','Doctor',2); | DELETE FROM healthcare_staff WHERE name = 'Dr. Jane Smith'; |
Identify the chemical batch with the highest temperature value. | CREATE TABLE batch_temperature (batch_id INT,temperature FLOAT,timestamp TIMESTAMP); INSERT INTO batch_temperature (batch_id,temperature,timestamp) VALUES (1,300,'2022-01-01 00:00:00'); INSERT INTO batch_temperature (batch_id,temperature,timestamp) VALUES (2,310,'2022-01-02 00:00:00'); | SELECT batch_id, temperature FROM (SELECT batch_id, temperature, ROW_NUMBER() OVER (ORDER BY temperature DESC) as row_num FROM batch_temperature) as subquery WHERE row_num = 1; |
Which community health worker programs have the highest health equity metrics in the Northeast region? | CREATE TABLE community_health_worker_programs_equity (id INT,program_name VARCHAR(50),location VARCHAR(20),health_equity_score INT); INSERT INTO community_health_worker_programs_equity (id,program_name,location,health_equity_score) VALUES (1,'CHW Program 1','Northeast',90),(2,'CHW Program 2','California',95),(3,'CHW Pr... | SELECT program_name, location, health_equity_score FROM community_health_worker_programs_equity WHERE location = 'Northeast' ORDER BY health_equity_score DESC; |
What is the minimum transaction amount for clients living in Ohio? | CREATE TABLE clients (id INT,name TEXT,age INT,state TEXT,transaction_amount DECIMAL(10,2)); INSERT INTO clients (id,name,age,state,transaction_amount) VALUES (1,'John Doe',35,'Ohio',200.00); INSERT INTO clients (id,name,age,state,transaction_amount) VALUES (2,'Jane Smith',40,'Ohio',250.50); | SELECT MIN(transaction_amount) FROM clients WHERE state = 'Ohio'; |
What is the maximum supply of the top 10 digital assets on the Tezos network? | CREATE TABLE tezos_assets (asset_id INT,asset_name VARCHAR(255),max_supply INT,network VARCHAR(50)); | SELECT asset_name, max_supply FROM tezos_assets WHERE network = 'Tezos' ORDER BY max_supply DESC LIMIT 10; |
What is the percentage of posts about climate change, published by users in the UK with fewer than 5,000 followers, in the month of January 2022? | CREATE TABLE posts (post_id INT,user_id INT,followers INT,post_date DATE,content TEXT); | SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM posts WHERE post_date >= '2022-01-01' AND post_date < '2022-02-01' AND country = 'UK')) AS pct FROM posts p WHERE p.content LIKE '%climate change%' AND p.followers < 5000 AND p.post_date >= '2022-01-01' AND p.post_date < '2022-02-01' AND p.country = 'UK'; |
What is the percentage of water consumption that is reclaimed for each water treatment plant? | CREATE TABLE water_treatment_plants (plant_name VARCHAR(50),plant_id INT,plant_location VARCHAR(50)); INSERT INTO water_treatment_plants (plant_name,plant_id,plant_location) VALUES ('Toronto Water Treatment Plant',1,'Toronto,Canada'),('Sydney Water Treatment Plant',2,'Sydney,Australia'),('Moscow Water Treatment Plant',... | SELECT wtp.plant_name, AVG(w.reclaimed_gallons * 100.0 / w.consumption_gallons) as avg_reclaimed_percentage FROM water_consumption w JOIN water_treatment_plants wtp ON w.plant_id = wtp.plant_id WHERE w.consumption_date >= DATEADD(year, -1, GETDATE()) GROUP BY wtp.plant_name; |
What is the average price of organic products sold by suppliers in the US? | CREATE TABLE Suppliers (SupplierID INT,SupplierName TEXT,Country TEXT);CREATE TABLE Products (ProductID INT,ProductName TEXT,Price DECIMAL,Organic BOOLEAN,SupplierID INT); INSERT INTO Suppliers (SupplierID,SupplierName,Country) VALUES (1,'SupplierA','USA'),(2,'SupplierB','Canada'); INSERT INTO Products (ProductID,Produ... | SELECT AVG(Price) FROM Products JOIN Suppliers ON Products.SupplierID = Suppliers.SupplierID WHERE Organic = true AND Country = 'USA'; |
How many cases were heard in each county and the case type per month? | CREATE TABLE case_hearing (case_id INT,county_name VARCHAR(50),court_type VARCHAR(20),case_month DATE); INSERT INTO case_hearing VALUES (1,'County A','Community','2021-01-01'),(2,'County A','Community','2021-01-05'),(3,'County B','Traditional','2021-02-02'),(4,'County B','Traditional','2021-02-06'); | SELECT county_name, court_type, DATE_FORMAT(case_month, '%Y-%m') AS case_month, COUNT(*) AS cases_per_month FROM case_hearing GROUP BY county_name, court_type, case_month; |
List the infrastructure projects that have been completed but not yet evaluated in the 'rural_development' database. | CREATE TABLE InfrastructureProjects (id INT PRIMARY KEY,name VARCHAR(100),status VARCHAR(20),evaluation_date DATE); INSERT INTO InfrastructureProjects (id,name,status,evaluation_date) VALUES (1,'Water Treatment Plant','completed',NULL),(2,'Renewable Energy Center','in_progress','2023-02-28'),(3,'Rural Connectivity','co... | SELECT name FROM InfrastructureProjects WHERE status = 'completed' AND evaluation_date IS NULL; |
What is the average donation amount for each organization? | CREATE TABLE organizations (id INT,name TEXT,avg_donation DECIMAL(10,2)); INSERT INTO organizations (id,name,avg_donation) VALUES (1,'Nonprofit A',50.00),(2,'Nonprofit B',100.00); | SELECT name, AVG(donation_amount) as avg_donation FROM donations JOIN organizations ON donations.organization_id = organizations.id GROUP BY organizations.name; |
What is the total gold production in Western Australia, by financial year (July to June)? | CREATE TABLE mine_labor (mine_id INT,worker_count INT,year INT,province VARCHAR(20)); INSERT INTO mine_labor (mine_id,worker_count,year,province) VALUES (1,50,2010,'Western Australia'),(2,75,2011,'Western Australia'),(3,60,2012,'Western Australia'); CREATE TABLE mine_production (mine_id INT,gold_kg FLOAT); INSERT INTO ... | SELECT SUM(gold_kg) as total_gold_production FROM mine_production INNER JOIN mine_labor ON mine_production.mine_id = mine_labor.mine_id WHERE mine_labor.province = 'Western Australia' AND mine_labor.year BETWEEN YEAR(DATE_SUB(CURDATE(), INTERVAL 18 MONTH)) AND YEAR(DATE_SUB(CURDATE(), INTERVAL 6 MONTH)); |
Insert a new marine species record into the 'marine_species' table | CREATE TABLE marine_species (id INT PRIMARY KEY,species_name VARCHAR(255),conservation_status VARCHAR(50)); | INSERT INTO marine_species (id, species_name, conservation_status) VALUES (1001, 'Oceanic Whitetip Shark', 'Vulnerable'); |
Who are the top 3 countries receiving climate finance for communication projects? | CREATE TABLE climate_finance (id INT,country VARCHAR(50),amount FLOAT,sector VARCHAR(50)); | SELECT cf.country, SUM(cf.amount) FROM climate_finance cf WHERE cf.sector = 'communication' GROUP BY cf.country ORDER BY SUM(cf.amount) DESC LIMIT 3; |
List all smart contracts and their developers, if the smart contract was deployed after 2020-01-01. | CREATE TABLE smart_contracts (name TEXT,developer TEXT,date DATE); INSERT INTO smart_contracts (name,developer,date) VALUES ('Contract1','Alice','2019-12-31'),('Contract2','Bob','2021-01-01'); | SELECT smart_contracts.name, smart_contracts.developer FROM smart_contracts WHERE smart_contracts.date > '2020-01-01'; |
How many environmental impacts have been recorded for each mineral? | CREATE TABLE EnvironmentalImpact (ImpactID INT PRIMARY KEY,MineralID INT,ExtractionSite VARCHAR(50),Impact VARCHAR(50),Date DATE,MitigationMeasure VARCHAR(50)); INSERT INTO EnvironmentalImpact (ImpactID,MineralID,ExtractionSite,Impact,Date,MitigationMeasure) VALUES (1,1,'South Africa','Water Pollution','2022-01-01','Wa... | SELECT EnvironmentalImpact.MineralID, COUNT(EnvironmentalImpact.Impact) FROM EnvironmentalImpact GROUP BY EnvironmentalImpact.MineralID; |
List all the ingredients for products that have a sourcing_rating above 80. | CREATE TABLE ingredients (ingredient_id INT,product_id INT,name VARCHAR(255),sourcing_rating INT); INSERT INTO ingredients (ingredient_id,product_id,name,sourcing_rating) VALUES (1,1,'Beeswax',85),(2,1,'Castor Oil',90),(3,2,'Talc',75),(4,2,'Mica',82),(5,3,'Rosewater',95); | SELECT i.name FROM ingredients i JOIN products p ON i.product_id = p.product_id WHERE p.cruelty_free = true AND i.sourcing_rating > 80; |
List all peacekeeping operations that involved more than 5000 personnel and their respective operation start dates. | CREATE TABLE peacekeeping_operations (operation_name VARCHAR(50),personnel INT,operation_start_date DATE); INSERT INTO peacekeeping_operations (operation_name,personnel,operation_start_date) VALUES ('Operation United Shield',5500,'1995-03-03'),('Operation Allied Force',25000,'1999-03-24'),('Operation Iraqi Freedom',150... | SELECT operation_name, personnel, operation_start_date FROM peacekeeping_operations WHERE personnel > 5000; |
What is the earliest and latest scheduled departure for each route? | CREATE TABLE trips (id INT,route_id INT,vehicle_id INT,scheduled_departure TIMESTAMP,actual_departure TIMESTAMP); INSERT INTO trips (id,route_id,vehicle_id,scheduled_departure,actual_departure) VALUES (4,302,55,'2022-04-01 05:45:00','2022-04-01 05:45:30'); | SELECT route_id, MIN(scheduled_departure) as earliest_departure, MAX(scheduled_departure) as latest_departure FROM trips GROUP BY route_id; |
What is the name and donation amount of the top donor for each cause? | CREATE TABLE causes (cause_id INT,cause_name VARCHAR(255)); INSERT INTO causes (cause_id,cause_name) VALUES (1,'Education'),(2,'Health'),(3,'Environment'); CREATE TABLE donations (donor_id INT,donor_name VARCHAR(255),cause_id INT,donation_amount INT); INSERT INTO donations (donor_id,donor_name,cause_id,donation_amount)... | SELECT c.cause_name, d.donor_name, d.donation_amount FROM (SELECT donor_name, cause_id, donation_amount, ROW_NUMBER() OVER (PARTITION BY cause_id ORDER BY donation_amount DESC) AS rn FROM donations) d JOIN causes c ON d.cause_id = c.cause_id WHERE d.rn = 1; |
What is the total workout duration for each membership type? | CREATE TABLE users (id INT,name TEXT,membership_type TEXT); CREATE TABLE workouts (id INT,user_id INT,duration INT); INSERT INTO users (id,name,membership_type) VALUES (1,'John Doe','Premium'),(2,'Jane Smith','Basic'); INSERT INTO workouts (id,user_id,duration) VALUES (1,1,60),(2,1,30),(3,2,45); | SELECT users.membership_type, SUM(workouts.duration) AS total_duration FROM users JOIN workouts ON users.id = workouts.user_id GROUP BY users.membership_type; |
Which cybersecurity domains had no vulnerabilities discovered in the last week? | CREATE TABLE domain_vulnerabilities_by_date (id INT,domain TEXT,vulnerability_id INT,date_discovered DATE); INSERT INTO domain_vulnerabilities_by_date (id,domain,vulnerability_id,date_discovered) VALUES (1,'Network Security',1,'2022-07-21'); INSERT INTO domain_vulnerabilities_by_date (id,domain,vulnerability_id,date_di... | SELECT domain FROM domain_vulnerabilities_by_date WHERE date_discovered >= DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY) GROUP BY domain HAVING COUNT(*) = 0; |
Find the maximum price of Gadolinium transactions in African countries. | CREATE TABLE gadolinium_transactions (country VARCHAR(20),element VARCHAR(20),price DECIMAL(5,2),transaction_date DATE); INSERT INTO gadolinium_transactions (country,element,price,transaction_date) VALUES ('South Africa','Gadolinium',40,'2020-01-01'),('Egypt','Gadolinium',45,'2020-02-01'),('South Africa','Gadolinium',5... | SELECT MAX(price) FROM gadolinium_transactions WHERE country IN ('South Africa', 'Egypt') AND element = 'Gadolinium'; |
What's the total amount of donations made by individual donors from 'asia' and 'europe' regions? | CREATE TABLE donors (id INT,name TEXT,region TEXT,donation_amount FLOAT); INSERT INTO donors (id,name,region,donation_amount) VALUES (1,'John Doe','Asia',5000.00),(2,'Jane Smith','Europe',3000.00); | SELECT SUM(donation_amount) FROM donors WHERE region IN ('Asia', 'Europe'); |
What is the number of user signups for each region in the first week of August 2022? | CREATE TABLE signups (signup_id INT,signup_date DATE,region VARCHAR(50),signup_count INT); INSERT INTO signups VALUES (405,'2022-08-01','Africa',60),(406,'2022-08-03','Oceania',45),(407,'2022-08-05','Antarctica',10),(408,'2022-08-07','Australia',30); | SELECT region, SUM(signup_count) as total_signups FROM signups WHERE signup_date BETWEEN '2022-08-01' AND '2022-08-07' GROUP BY region; |
Count the number of employees working in 'Accessibility Services' who have been with the organization for over 5 years. | CREATE TABLE Employees (ID INT,Department TEXT,YearsAtOrg FLOAT); INSERT INTO Employees (ID,Department,YearsAtOrg) VALUES (1,'Accessibility Services',6.5),(2,'IT',3.2),(3,'Accessibility Services',4.7); | SELECT COUNT(*) FROM Employees WHERE Department = 'Accessibility Services' AND YearsAtOrg > 5; |
What is the maximum number of steps taken by a member in a day? | CREATE TABLE Members (MemberID INT,Name VARCHAR(50),Age INT,Membership VARCHAR(20)); CREATE TABLE Steps (StepID INT,MemberID INT,Steps INT,Date DATE); INSERT INTO Members (MemberID,Name,Age,Membership) VALUES (1,'John Doe',35,'Platinum'),(2,'Jane Smith',28,'Gold'); INSERT INTO Steps (StepID,MemberID,Steps,Date) VALUES ... | SELECT MemberID, MAX(Steps) FROM Members JOIN Steps ON Members.MemberID = Steps.MemberID GROUP BY MemberID; |
What is the chemical with the highest waste generation? | CREATE TABLE waste_generation (id INT PRIMARY KEY,chemical_name VARCHAR(255),waste_generation INT); INSERT INTO waste_generation (id,chemical_name,waste_generation) VALUES (1,'Sodium Hydroxide',300); | SELECT chemical_name, waste_generation, RANK() OVER (ORDER BY waste_generation DESC) AS rank FROM waste_generation WHERE rank = 1; |
Insert new data into the 'MarineResearch' table | CREATE TABLE MarineResearch (ResearchID INT,ResearchTitle VARCHAR(255),ResearchArea VARCHAR(255),Researcher VARCHAR(255),StartDate DATE,EndDate DATE); | INSERT INTO MarineResearch (ResearchID, ResearchTitle, ResearchArea, Researcher, StartDate, EndDate) VALUES (1, 'Impact of Climate Change on Marine Life', 'Climate Change', 'Dr. Jane Smith', '2023-01-01', '2023-12-31'); |
What is the total contract value for each vendor in the past year? | CREATE TABLE vendors (vendor_id INT,vendor_name TEXT,contract_value DECIMAL(10,2),contract_date DATE); INSERT INTO vendors VALUES (1,'VendorA',500000,'2021-01-01'),(2,'VendorB',700000,'2021-02-01'),(3,'VendorC',600000,'2021-03-01'); | SELECT vendor_name, SUM(contract_value) OVER (PARTITION BY vendor_name) AS total_contract_value FROM vendors WHERE contract_date >= DATEADD(year, -1, CURRENT_DATE); |
How many unique clients are there for attorneys with the first name 'James'? | CREATE TABLE attorneys (id INT,first_name VARCHAR(10),client_id INT); INSERT INTO attorneys (id,first_name,client_id) VALUES (1,'James',1),(2,'James',2),(3,'Robert',3); | SELECT COUNT(DISTINCT client_id) FROM attorneys WHERE first_name = 'James'; |
Determine the number of court types in the criminal justice system of the US and Canada, grouped by their respective countries. | CREATE TABLE court_types_count (id INT,country VARCHAR(255),court_type VARCHAR(255)); INSERT INTO court_types_count (id,country,court_type) VALUES (1,'US','District Court'),(2,'Canada','Provincial Court'),(3,'US','Supreme Court'),(4,'Canada','Superior Court'); | SELECT country, COUNT(*) AS court_type_count FROM court_types_count GROUP BY country; |
Which members have not attended a workout since joining? | CREATE TABLE member_data (member_id INT,join_date DATE); CREATE TABLE member_workouts (member_id INT,workout_date DATE); | SELECT mdata.member_id FROM member_data mdata LEFT JOIN member_workouts mworkouts ON mdata.member_id = mworkouts.member_id WHERE mworkouts.member_id IS NULL; |
How many arrests were made per month in each community district for the past 6 months? | CREATE TABLE community_districts (cd_number INT,community_name VARCHAR(255)); INSERT INTO community_districts (cd_number,community_name) VALUES (1,'Manhattan 1'),(2,'Manhattan 2'),(3,'Manhattan 3'); CREATE TABLE arrest_data (arrest_date DATE,cd_number INT,arrest_count INT); | SELECT cd.community_name, EXTRACT(MONTH FROM ad.arrest_date) as month, AVG(ad.arrest_count) as avg_arrests_per_month FROM community_districts cd JOIN arrest_data ad ON cd.cd_number = ad.cd_number WHERE ad.arrest_date >= CURDATE() - INTERVAL 6 MONTH GROUP BY cd.community_name, month; |
Update the "session_length" to 40 minutes for session_id 2 in the "game_sessions" table | CREATE TABLE game_sessions (session_id INT,player_id INT,session_length INT); INSERT INTO game_sessions (session_id,player_id,session_length) VALUES (1,1,20),(2,2,45),(3,3,35); | UPDATE game_sessions SET session_length = 40 WHERE session_id = 2; |
Which destinations in Asia have the highest eco-friendliness ratings? | CREATE TABLE asia_destinations (destination VARCHAR(50),eco_rating INT); INSERT INTO asia_destinations (destination,eco_rating) VALUES ('Bali',4),('Kyoto',5),('Bangkok',3),('Singapore',5),('New Delhi',2),('Seoul',4),('Hong Kong',3),('Tokyo',5); | SELECT destination FROM asia_destinations WHERE eco_rating = (SELECT MAX(eco_rating) FROM asia_destinations) ORDER BY eco_rating DESC; |
Update the implementation date of an inclusive housing policy to 2012-02-15. | CREATE TABLE InclusiveHousingPolicies (PolicyID INT,PolicyName VARCHAR(50),ImplementationDate DATE); INSERT INTO InclusiveHousingPolicies (PolicyID,PolicyName,ImplementationDate) VALUES (1,'Policy A','2008-01-01'),(2,'Policy B','2011-01-01'),(3,'Policy C','2009-06-15'); | UPDATE InclusiveHousingPolicies SET ImplementationDate = '2012-02-15' WHERE PolicyID = 1; |
Insert a new record into the 'Donations' table | CREATE TABLE Donations (DonationID INT PRIMARY KEY,DonorID INT,Amount DECIMAL(10,2),DonationDate DATE); | INSERT INTO Donations (DonationID, DonorID, Amount, DonationDate) VALUES (301, 101, 500.00, '2022-03-01'); |
How many complaints were filed with the city of Philadelphia, broken down by department, for the month of October 2022? | CREATE TABLE complaints (department VARCHAR(20),complaint_count INT,complaint_date DATE); INSERT INTO complaints (department,complaint_count,complaint_date) VALUES ('Public Works',200,'2022-10-01'); | SELECT department, SUM(complaint_count) FROM complaints WHERE complaint_date BETWEEN '2022-10-01' AND '2022-10-31' GROUP BY department; |
What is the highest scoring game in the history of the FIFA World Cup? | CREATE TABLE games (game_id INT,home_team INT,away_team INT,home_score INT,away_score INT,tournament VARCHAR(100)); | SELECT home_team, away_team, home_score, away_score FROM games WHERE tournament = 'FIFA World Cup' AND (home_score + away_score) = (SELECT MAX(home_score + away_score) FROM games WHERE tournament = 'FIFA World Cup'); |
Find broadband subscribers with no data allowance and insert them into mobile_subscribers table | CREATE TABLE mobile_subscribers (id INT,name VARCHAR(255),data_allowance INT,contract_start DATE); INSERT INTO mobile_subscribers (id,name,data_allowance,contract_start) VALUES (1,'John Doe',5000,'2020-01-01'); CREATE TABLE broadband_subscribers (id INT,name VARCHAR(255),speed INT,contract_start DATE); INSERT INTO broa... | INSERT INTO mobile_subscribers (id, name, data_allowance, contract_start) SELECT id, name, 2000, contract_start FROM broadband_subscribers WHERE data_allowance IS NULL; |
What is the total CO2 emissions from manufacturing organic skincare products in the last 6 months? | CREATE TABLE organic_skincare_emissions (emission_id INT,product_id INT,co2_emissions FLOAT,emission_date DATE); | SELECT SUM(co2_emissions) FROM organic_skincare_emissions WHERE emission_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH) AND CURRENT_DATE AND product_id IN (SELECT product_id FROM organic_skincare_products WHERE is_organic = TRUE); |
Count the number of mines with gold as the primary metal in the "mine_info" and "metals" tables | CREATE TABLE mine_info (id INT,name VARCHAR(20)); INSERT INTO mine_info (id,name) VALUES (1,'Golden Mine'),(2,'Silver Mine'),(3,'Copper Mine'); CREATE TABLE metals (mine_id INT,primary_metal VARCHAR(10)); INSERT INTO metals (mine_id,primary_metal) VALUES (1,'gold'),(2,'silver'),(3,'copper'); | SELECT COUNT(*) FROM mine_info mi JOIN metals m ON mi.id = m.mine_id WHERE m.primary_metal = 'gold'; |
What is the total number of volunteers for each program in the 'programs' table? | CREATE TABLE programs (program_id INT,program_name TEXT,org_id INT,num_volunteers INT); | SELECT program_name, SUM(num_volunteers) FROM programs GROUP BY program_name; |
What was the average economic diversification score for African countries in Q3 2021? | CREATE TABLE EconomicDiversification (id INT,country VARCHAR(20),quarter INT,score FLOAT); INSERT INTO EconomicDiversification (id,country,quarter,score) VALUES (1,'Nigeria',3,78.5),(2,'Kenya',2,72.3),(3,'Egypt',1,81.7),(4,'South Africa',4,85.2),(5,'Morocco',3,75.9); | SELECT AVG(score) FROM EconomicDiversification WHERE country IN ('Nigeria', 'Kenya', 'Egypt', 'South Africa', 'Morocco') AND quarter = 3; |
Which vendors have had contracts awarded in California in the last year? | CREATE TABLE vendors (id INT,vendor_name VARCHAR(255),vendor_location VARCHAR(255)); CREATE TABLE contracts (id INT,vendor_id INT,equipment_type VARCHAR(255),manufacturer VARCHAR(255),quantity INT,contract_value FLOAT,contract_date DATE); INSERT INTO vendors (id,vendor_name,vendor_location) VALUES (1,'General Dynamics'... | SELECT v.vendor_name FROM vendors v JOIN contracts c ON v.id = c.vendor_id WHERE c.contract_date >= DATEADD(year, -1, GETDATE()) AND c.vendor_id = v.id AND c.contract_date BETWEEN '2021-01-01' AND '2021-12-31' AND v.vendor_location = 'California'; |
What is the maximum budget for a single climate adaptation project in Africa? | CREATE TABLE climate_adaptation_projects (project_id INT,project_name VARCHAR(255),location VARCHAR(255),budget DECIMAL(10,2)); INSERT INTO climate_adaptation_projects (project_id,project_name,location,budget) VALUES (1,'Water Management in Senegal','Senegal',3000000.00),(2,'Coastal Protection in Mozambique','Mozambiqu... | SELECT MAX(budget) FROM climate_adaptation_projects WHERE location = 'Africa'; |
What is the total area of mangrove forests in the 'Africa' region? | CREATE TABLE forests (id INT,name TEXT,area FLOAT,region TEXT,is_mangrove BOOLEAN); INSERT INTO forests (id,name,area,region,is_mangrove) VALUES (1,'Congo Rainforest',3400000.0,'Africa',false),(2,'Niger Delta',25000.0,'Africa',true); | SELECT SUM(area) FROM forests WHERE region = 'Africa' AND is_mangrove = true; |
What are the unique cultural events in Asia that happened in the last 6 months? | CREATE TABLE asia_events (country VARCHAR(50),event VARCHAR(50),date DATE); INSERT INTO asia_events VALUES ('China','Lantern Festival','2022-02-15'),('Japan','Cherry Blossom Festival','2022-04-01'),('India','Diwali','2021-11-04'),('Indonesia','Independence Day','2021-08-17'),('Thailand','Songkran','2022-04-13'); | SELECT DISTINCT country, event FROM asia_events WHERE date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH); |
Find the top 3 most streamed songs in 'music_streaming' table for users from the USA. | CREATE TABLE music_streaming (user_id INT,song_id INT,streams INT,date DATE,country VARCHAR(50)); CREATE TABLE songs (song_id INT,song_name VARCHAR(100),artist_id INT); | SELECT s.song_name, SUM(ms.streams) AS total_streams FROM music_streaming ms JOIN songs s ON ms.song_id = s.song_id WHERE ms.country = 'USA' GROUP BY s.song_name ORDER BY total_streams DESC LIMIT 3; |
How many songs were released by "Artist Z" before 2010? | CREATE TABLE songs (song_id INT,title VARCHAR(255),artist VARCHAR(100),release_year INT,length FLOAT); INSERT INTO songs (song_id,title,artist,release_year,length) VALUES (1,'Song1','Artist X',2005,120.5),(2,'Song2','Artist Y',2015,210.3),(3,'Song3','Artist Z',2002,180.7); | SELECT COUNT(*) FROM songs WHERE artist = 'Artist Z' AND release_year < 2010; |
List the names, genders, and ages of all news reporters who have published more than 50 news stories. | CREATE TABLE reporters (id INT,name VARCHAR(50),gender VARCHAR(10),age INT,country VARCHAR(50)); CREATE TABLE published_stories (reporter_id INT,news_id INT); CREATE TABLE news (id INT,title VARCHAR(100),views INT,date DATE); | SELECT r.name, r.gender, r.age FROM reporters r INNER JOIN published_stories ps ON r.id = ps.reporter_id INNER JOIN news n ON ps.news_id = n.id GROUP BY r.name, r.gender, r.age HAVING COUNT(*) > 50; |
List the number of accessible vehicles for each company in the Chicago public transportation system. | CREATE TABLE chicago_transport (company VARCHAR(20),vehicle_type VARCHAR(10),accessible BOOLEAN); INSERT INTO chicago_transport (company,vehicle_type,accessible) VALUES ('ABC Buses','Bus',true),('ABC Buses','Train',false),('XYZ Transit','Bus',false),('XYZ Transit','Train',true); | SELECT company, COUNT(*) FROM chicago_transport WHERE accessible = true GROUP BY company; |
List all the suppliers providing eggs, their country, and the number of eggs supplied per month | CREATE TABLE suppliers (supplier_id INT,supplier_name TEXT,country TEXT); INSERT INTO suppliers (supplier_id,supplier_name,country) VALUES (1,'Supplier1','USA'),(2,'Supplier2','Canada'),(3,'Supplier3','Mexico'); CREATE TABLE supplies (supply_id INT,supply_date DATE,quantity INT,supplier_id INT,produce_name TEXT); INSER... | SELECT suppliers.supplier_name, suppliers.country, MONTH(supplies.supply_date), AVG(supplies.quantity) FROM suppliers JOIN supplies ON suppliers.supplier_id = supplies.supplier_id WHERE produce_name = 'Eggs' GROUP BY suppliers.supplier_name, suppliers.country, MONTH(supplies.supply_date); |
How many attendees identified as Hispanic or Latino at the 'Cultural Diversity Festival' in Los Angeles? | CREATE TABLE demographics (event_name VARCHAR(50),city VARCHAR(50),ethnicity VARCHAR(20),attendees INT); INSERT INTO demographics (event_name,city,ethnicity,attendees) VALUES ('Cultural Diversity Festival','Los Angeles','Hispanic or Latino',300); | SELECT SUM(attendees) FROM demographics WHERE event_name = 'Cultural Diversity Festival' AND city = 'Los Angeles' AND ethnicity = 'Hispanic or Latino'; |
What is the total duration of 'Swimming' workouts? | CREATE TABLE Workout (WorkoutID INT,MemberID INT,WorkoutType VARCHAR(30),Duration INT); INSERT INTO Workout (WorkoutID,MemberID,WorkoutType,Duration) VALUES (1,1,'Running',60); INSERT INTO Workout (WorkoutID,MemberID,WorkoutType,Duration) VALUES (2,1,'Cycling',90); INSERT INTO Workout (WorkoutID,MemberID,WorkoutType,Du... | SELECT SUM(Duration) FROM Workout WHERE WorkoutType = 'Swimming'; |
What is the number of safety incidents in each manufacturing plant, grouped by the state? | CREATE TABLE ManufacturingPlants (PlantID INT,PlantName TEXT,State TEXT,SafetyIncidents INT); INSERT INTO ManufacturingPlants (PlantID,PlantName,State,SafetyIncidents) VALUES (1,'Plant A','Texas',3),(2,'Plant B','California',2),(3,'Plant C','Texas',1),(4,'Plant D','California',5); | SELECT State, SUM(SafetyIncidents) AS TotalSafetyIncidents FROM ManufacturingPlants GROUP BY State; |
How many accounts are associated with each risk category and what is the total assets value for each category? | CREATE TABLE account_risk (id INT,account_id INT,risk_category VARCHAR(255)); INSERT INTO account_risk (id,account_id,risk_category) VALUES (1,1,'High'),(2,2,'Medium'),(3,3,'Low'),(4,4,'High'),(5,5,'Medium'); CREATE TABLE accounts (id INT,customer_id INT,total_assets DECIMAL(10,2)); INSERT INTO accounts (id,customer_id... | SELECT r.risk_category, COUNT(r.account_id) AS num_accounts, SUM(a.total_assets) AS total_assets FROM account_risk r INNER JOIN accounts a ON r.account_id = a.id GROUP BY r.risk_category; |
What is the minimum water consumption in the public sector in Alberta? | CREATE TABLE public_sector (id INT,province VARCHAR(20),water_consumption FLOAT); INSERT INTO public_sector (id,province,water_consumption) VALUES (1,'Alberta',100000000),(2,'Alberta',90000000),(3,'Alberta',80000000); | SELECT MIN(water_consumption) FROM public_sector WHERE province = 'Alberta'; |
What is the minimum waste generation per day for residential areas in New York for the month of July? | CREATE TABLE waste_generation_us(location VARCHAR(50),date DATE,waste_quantity INT); INSERT INTO waste_generation_us(location,date,waste_quantity) VALUES ('New York','2022-07-01',12000),('New York','2022-07-02',11000),('New York','2022-07-03',13000),('Los Angeles','2022-07-01',9000),('Los Angeles','2022-07-02',10000),(... | SELECT MIN(waste_quantity) FROM waste_generation_us WHERE location = 'New York' AND date BETWEEN '2022-07-01' AND '2022-07-31' AND waste_quantity IS NOT NULL; |
Insert new records for 2 EV charging stations in New York into the 'charging_stations' table | CREATE TABLE charging_stations (id INT,station_name VARCHAR(255),station_type VARCHAR(255),location VARCHAR(255)); | INSERT INTO charging_stations (id, station_name, station_type, location) VALUES (1, 'New York EV 1', 'Level 2', 'New York'), (2, 'New York EV 2', 'DC Fast', 'New York'); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.