instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
How many graduate students in the Physics department have a GPA of at least 3.5?
CREATE SCHEMA if not exists higher_ed;CREATE TABLE if not exists higher_ed.students(id INT,name VARCHAR(255),department VARCHAR(255),gpa DECIMAL(3,2));
SELECT COUNT(*) FROM higher_ed.students WHERE department = 'Physics' AND gpa >= 3.5;
List all electric vehicles in the 'green_vehicles' table that have a range of over 300 miles.
CREATE TABLE green_vehicles (make VARCHAR(50),model VARCHAR(50),year INT,range INT);
SELECT * FROM green_vehicles WHERE make IN ('Tesla', 'Rivian') AND range > 300;
What is the distribution of training program completion rates by gender and ethnicity?
CREATE TABLE Employees (EmployeeID int,FirstName varchar(50),LastName varchar(50),Gender varchar(50),Ethnicity varchar(50),TrainingProgramCompletion bit); INSERT INTO Employees (EmployeeID,FirstName,LastName,Gender,Ethnicity,TrainingProgramCompletion) VALUES (1,'John','Doe','Male','Asian',1),(2,'Jane','Doe','Female','Latino',0),(3,'Jim','Smith','Non-binary','African American',1);
SELECT Employees.Gender, Employees.Ethnicity, COUNT(Employees.EmployeeID) as Count_of_Employees, COUNT(CASE WHEN Employees.TrainingProgramCompletion = 1 THEN 1 ELSE NULL END) as Completed_Training FROM Employees GROUP BY Employees.Gender, Employees.Ethnicity;
Find countries with high consumer awareness
CREATE TABLE consumer_awareness (id INT PRIMARY KEY,country VARCHAR(50),awareness DECIMAL(3,2)); INSERT INTO consumer_awareness (id,country,awareness) VALUES (1,'Germany',0.85),(2,'Italy',0.70),(3,'France',0.80);
SELECT country FROM consumer_awareness WHERE awareness >= 0.8;
What is the total population of dolphins in the Pacific and Atlantic Oceans?
CREATE TABLE Dolphins (id INT,species VARCHAR(20),location VARCHAR(30),population INT); INSERT INTO Dolphins (id,species,location,population) VALUES (1,'Bottlenose Dolphin','Pacific Ocean',4000); INSERT INTO Dolphins (id,species,location,population) VALUES (2,'Oracle Dolphin','Atlantic Ocean',3500);
SELECT location, SUM(population) as total_population FROM Dolphins WHERE location IN ('Pacific Ocean', 'Atlantic Ocean') GROUP BY location;
What is the total quantity of gold mined by each mining company?
CREATE TABLE Mining_Company (id INT,name VARCHAR(50),location VARCHAR(50)); INSERT INTO Mining_Company (id,name,location) VALUES (1,'CompanyA','USA'),(2,'CompanyB','Canada'); CREATE TABLE Mining_Operation (id INT,company_id INT,mine_name VARCHAR(50),resource VARCHAR(10),quantity INT); INSERT INTO Mining_Operation (id,company_id,mine_name,resource,quantity) VALUES (1,1,'Mine1','Gold',1000),(2,1,'Mine2','Gold',1500),(3,2,'Mine3','Gold',800),(4,2,'Mine4','Silver',1200);
SELECT m.name, SUM(quantity) as total_gold_quantity FROM Mining_Operation o JOIN Mining_Company m ON o.company_id = m.id WHERE o.resource = 'Gold' GROUP BY m.name;
What is the average billing amount for cases handled by attorney Garcia in the last year?
CREATE TABLE cases (case_id INT,attorney_name VARCHAR(255),billing_amount FLOAT,case_date DATE); INSERT INTO cases (case_id,attorney_name,billing_amount,case_date) VALUES (1,'Smith',5000,'2020-01-01'),(2,'Jones',3000,'2020-05-15'),(3,'Garcia',3500,'2021-07-20'),(4,'Smith',4000,'2020-12-31'),(5,'Brown',6000,'2020-06-20');
SELECT AVG(billing_amount) FROM cases WHERE attorney_name = 'Garcia' AND case_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR);
Which threat actors have been active in Europe in the last 30 days, and what is the number of incidents they have been involved in?
CREATE TABLE incidents (id INT,date DATE,category VARCHAR(20),source_ip VARCHAR(15),target_ip VARCHAR(15)); CREATE TABLE threat_actors (id INT,date DATE,type VARCHAR(20),location VARCHAR(30)); INSERT INTO incidents (id,date,category,source_ip,target_ip) VALUES (1,'2021-01-01','malware','192.168.1.100','8.8.8.8'); INSERT INTO threat_actors (id,date,type,location) VALUES (1,'2021-01-01','APT','Russia');
SELECT threat_actors.type, COUNT(*) as incident_count FROM threat_actors JOIN incidents ON threat_actors.date = incidents.date WHERE threat_actors.location = 'Europe' AND incidents.date >= (CURRENT_DATE - INTERVAL '30' DAY) GROUP BY threat_actors.type;
What was the total revenue for the state of California in the year 2021?
CREATE TABLE dispensary_sales (id INT,dispensary_name VARCHAR(255),state VARCHAR(255),sales_amount DECIMAL(10,2),sale_date DATE);
SELECT SUM(sales_amount) FROM dispensary_sales WHERE state = 'California' AND sale_date BETWEEN '2021-01-01' AND '2021-12-31';
What is the number of rural healthcare professionals and their respective specialties, ordered by state and then by specialty?
CREATE TABLE healthcare_professionals (professional_id INT,name TEXT,specialty TEXT,rural BOOLEAN,state_code TEXT); INSERT INTO healthcare_professionals (professional_id,name,specialty,rural,state_code) VALUES (1,'Dr. Smith','Cardiology',TRUE,'CA'),(2,'Dr. Johnson','Pediatrics',TRUE,'TX');
SELECT healthcare_professionals.state_code, healthcare_professionals.specialty, COUNT(healthcare_professionals.professional_id) as count FROM healthcare_professionals WHERE healthcare_professionals.rural = TRUE GROUP BY healthcare_professionals.state_code, healthcare_professionals.specialty ORDER BY healthcare_professionals.state_code, healthcare_professionals.specialty;
Show the total number of streams for each genre in 2021.
CREATE TABLE genres (id INT PRIMARY KEY,name TEXT); CREATE TABLE songs (id INT PRIMARY KEY,title TEXT,genre_id INT,year INT,artist TEXT,streams INT); INSERT INTO genres (id,name) VALUES (1,'Pop'),(2,'Rock'),(3,'Jazz'),(4,'Hip Hop'),(5,'Country');
SELECT g.name, SUM(s.streams) as total_streams FROM songs s JOIN genres g ON s.genre_id = g.id WHERE s.year = 2021 GROUP BY g.name;
What is the maximum number of consecutive days without rain in the city of Cape Town in the year 2020?
CREATE TABLE RainfallData (date DATE,city VARCHAR(20),rainfall FLOAT);
SELECT DATEDIFF(date, LAG(date) OVER (PARTITION BY city ORDER BY date)) + 1 AS consecutive_days_no_rain FROM RainfallData WHERE city = 'Cape Town' AND rainfall = 0 ORDER BY consecutive_days_no_rain DESC LIMIT 1;
What is the average reactor temperature per site, ordered by the highest average temperature?
CREATE TABLE site (site_id INT,site_name VARCHAR(50)); CREATE TABLE reactor (reactor_id INT,site_id INT,temperature DECIMAL(5,2)); INSERT INTO site (site_id,site_name) VALUES (1,'Site A'),(2,'Site B'); INSERT INTO reactor (reactor_id,site_id,temperature) VALUES (1,1,80),(2,1,85),(3,2,70),(4,2,72);
SELECT AVG(temperature) AS avg_temperature, site_id FROM reactor GROUP BY site_id ORDER BY avg_temperature DESC;
What is the total research grant amount awarded to graduate students from the 'Computer Science' department?
CREATE TABLE graduate_students (id INT,name VARCHAR(50),department VARCHAR(50),research_grant_amount DECIMAL(10,2)); INSERT INTO graduate_students (id,name,department,research_grant_amount) VALUES (1,'Alice','Computer Science',15000.00),(2,'Bob','Computer Science',20000.00);
SELECT SUM(research_grant_amount) FROM graduate_students WHERE department = 'Computer Science';
What is the total number of successful launches for the Ariane 5 rocket?
CREATE TABLE Ariane5Launches (id INT,launch_date DATE,launch_result VARCHAR(10));
SELECT COUNT(*) FROM Ariane5Launches WHERE launch_result = 'Success';
Find the most popular menu item by sales in each category.
CREATE TABLE menu_categories(id INT,category VARCHAR(255)); INSERT INTO menu_categories (id,category) VALUES (1,'Sandwiches'),(2,'Salads'),(3,'Entrees'); CREATE TABLE menu_item_sales(id INT,menu_item_id INT,category_id INT,sales FLOAT); INSERT INTO menu_item_sales (id,menu_item_id,category_id,sales) VALUES (1,1,1,1500.00),(2,2,1,1000.00),(3,3,2,2000.00),(4,4,3,3000.00);
SELECT category_id, menu_item_id, MAX(sales) FROM menu_item_sales GROUP BY category_id;
Determine the number of researchers working on each project in the 'Project_Team' table and the 'Researchers' table, then remove duplicates.
CREATE TABLE Project_Team (id INT,project VARCHAR(30),researcher VARCHAR(30)); CREATE TABLE Researchers (id INT,project VARCHAR(30),researcher VARCHAR(30));
SELECT project, COUNT(DISTINCT researcher) FROM Project_Team GROUP BY project UNION SELECT project, COUNT(DISTINCT researcher) FROM Researchers GROUP BY project
List the number of mental health providers in each census tract, for tracts with a population density greater than 3,000 people per square mile.
CREATE TABLE mental_health_providers (id INT,census_tract VARCHAR(15),provider_type VARCHAR(20)); INSERT INTO mental_health_providers (id,census_tract,provider_type) VALUES (1,'9900100150','Psychiatrist'); CREATE TABLE census_tracts (census_tract VARCHAR(15),state VARCHAR(2),pop_density INT); INSERT INTO census_tracts (census_tract,state,pop_density) VALUES ('9900100150','AK',4000);
SELECT m.census_tract, COUNT(m.id) FROM mental_health_providers m JOIN census_tracts c ON m.census_tract = c.census_tract WHERE c.pop_density > 3000 GROUP BY m.census_tract;
How many times has the 'Jazz Ensemble' program received funding from the 'National Endowment for the Arts'?
CREATE TABLE Programs (program_id INT,program_name VARCHAR(255)); INSERT INTO Programs (program_id,program_name) VALUES (1,'Jazz Ensemble'),(2,'Theater Workshop'); CREATE TABLE Funding (funding_id INT,program_id INT,funder_name VARCHAR(255)); INSERT INTO Funding (funding_id,program_id,funder_name) VALUES (1,1,'National Endowment for the Arts'),(2,1,'Local Arts Council'),(3,2,'National Endowment for the Arts');
SELECT COUNT(f.funding_id) AS funding_count FROM Funding f JOIN Programs p ON f.program_id = p.program_id WHERE p.program_name = 'Jazz Ensemble' AND f.funder_name = 'National Endowment for the Arts';
Calculate the moving average of production rate for each machine over the last three days.
CREATE TABLE Machine_Production_Daily (Machine_ID INT,Production_Date DATE,Production_Rate INT); INSERT INTO Machine_Production_Daily (Machine_ID,Production_Date,Production_Rate) VALUES (1,'2022-01-01',50),(1,'2022-01-02',55),(1,'2022-01-03',60),(2,'2022-01-01',60),(2,'2022-01-03',65),(2,'2022-01-04',70);
SELECT Machine_ID, Production_Date, AVG(Production_Rate) OVER (PARTITION BY Machine_ID ORDER BY Production_Date RANGE BETWEEN INTERVAL '2' DAY PRECEDING AND CURRENT ROW) as Moving_Average FROM Machine_Production_Daily;
Get the names and salaries of workers earning more than the average salary
CREATE TABLE workers (id INT,name VARCHAR(20),department VARCHAR(20),salary FLOAT); INSERT INTO workers (id,name,department,salary) VALUES (1,'Alice','textiles',50000),(2,'Bob','textiles',55000),(3,'Charlie','metallurgy',60000),(4,'Dave','metallurgy',45000);
SELECT name, salary FROM workers WHERE salary > (SELECT AVG(salary) FROM workers);
What is the total number of employees from underrepresented communities working in the mining industry?
CREATE TABLE employee (id INT,name TEXT,gender TEXT,ethnicity TEXT,department TEXT,hire_date DATE);
SELECT COUNT(employee.id) as total_employees FROM employee WHERE employee.department IN ('Mining') AND employee.ethnicity IN ('African American', 'Hispanic', 'Native American', 'Asian Pacific Islander');
Who are the top 3 cricket teams with the highest win percentage?
CREATE TABLE Matches (MatchID INT,TeamName VARCHAR(50),Wins INT); INSERT INTO Matches (MatchID,TeamName,Wins) VALUES (1,'Australia',450),(2,'India',400),(3,'England',425);
SELECT TeamName, (SUM(Wins) * 100.0 / (SELECT COUNT(*) FROM Matches)) AS WinPercentage FROM Matches GROUP BY TeamName ORDER BY WinPercentage DESC LIMIT 3
What are the total production figures for each company, broken down by quarter, for the year 2021?
CREATE TABLE wells (well_id INT,well_name VARCHAR(255),location VARCHAR(255),company VARCHAR(255),production_figures DECIMAL(10,2),date DATE); INSERT INTO wells (well_id,well_name,location,company,production_figures,date) VALUES (1,'Well A','North Sea','Company A',12000.50,'2021-01-01'),(2,'Well B','North Sea','Company B',15000.25,'2021-02-01'),(3,'Well C','Gulf of Mexico','Company A',20000.00,'2021-03-01');
SELECT company, EXTRACT(QUARTER FROM date) AS quarter, SUM(production_figures) AS total_production FROM wells WHERE EXTRACT(YEAR FROM date) = 2021 GROUP BY company, quarter;
What is the total weight of all space debris in orbit?
CREATE TABLE space_debris (id INT,name VARCHAR(50),weight FLOAT);
SELECT SUM(weight) FROM space_debris;
List all Green Building certifications awarded per city.
CREATE TABLE Cities (id INT,name VARCHAR(50)); INSERT INTO Cities (id,name) VALUES (1,'CityA'),(2,'CityB'); CREATE TABLE GreenBuildings (id INT,city_id INT,certification VARCHAR(50)); INSERT INTO GreenBuildings (id,city_id,certification) VALUES (1,1,'LEED'),(2,1,'BREEAM'),(3,2,'LEED');
SELECT Cities.name, GreenBuildings.certification FROM Cities INNER JOIN GreenBuildings ON Cities.id = GreenBuildings.city_id;
Show the average salary for each department for the second half of 2021
CREATE TABLE salaries (id INT,employee_id INT,salary INT,salary_date DATE,department VARCHAR(255)); INSERT INTO salaries (id,employee_id,salary,salary_date,department) VALUES (1,801,55000,'2021-07-01','Sales'); INSERT INTO salaries (id,employee_id,salary,salary_date,department) VALUES (2,802,65000,'2021-08-01','Finance');
SELECT department, AVG(salary) FROM salaries WHERE salary_date BETWEEN '2021-07-01' AND '2021-12-31' GROUP BY department;
Provide the asset name and transaction hash for all transactions that occurred on 2022-12-31.
CREATE TABLE transactions (id INT PRIMARY KEY,tx_hash VARCHAR(255),smart_contract_id INT,timestamp TIMESTAMP); INSERT INTO transactions (id,tx_hash,smart_contract_id,timestamp) VALUES (1,'tx1',1,'2022-12-31 10:00:00'),(2,'tx2',2,'2022-12-30 11:00:00');
SELECT t.tx_hash, s.asset_name FROM transactions t INNER JOIN smart_contracts s ON t.smart_contract_id = s.id WHERE t.timestamp = '2022-12-31 00:00:00';
What is the total volume of timber harvested from public forests in 2020?
CREATE TABLE public_forests (id INT,name VARCHAR(50),hectares DECIMAL(5,2)); INSERT INTO public_forests (id,name,hectares) VALUES (1,'Forest 1',1500.00),(2,'Forest 2',2000.00); CREATE TABLE timber_harvest (id INT,forest_id INT,year INT,volume DECIMAL(10,2)); INSERT INTO timber_harvest (id,forest_id,year,volume) VALUES (1,1,2020,120.00),(2,1,2021,150.00),(3,2,2020,180.00),(4,2,2021,200.00);
SELECT SUM(th.volume) FROM public_forests pf INNER JOIN timber_harvest th ON pf.id = th.forest_id WHERE pf.hectares > 1000 AND th.year = 2020;
What is the total supply of ERC-20 tokens on the Ethereum network?
CREATE TABLE ethereum_erc20 (token_id INT,total_supply DECIMAL);
SELECT SUM(total_supply) FROM ethereum_erc20;
What is the average number of posts per user in the social_media database?
CREATE TABLE user (user_id INT,username VARCHAR(20),posts INT); INSERT INTO user (user_id,username,posts) VALUES (1,'user1',10),(2,'user2',20),(3,'user3',30);
SELECT AVG(posts) FROM user;
Delete all records with production quantities less than 100 in the 'LOW_PRODUCTION' table.
CREATE TABLE LOW_PRODUCTION AS SELECT * FROM GAS_WELLS WHERE PRODUCTION_QTY < 100;
DELETE FROM LOW_PRODUCTION;
What is the total mass of space debris orbiting Earth?
CREATE TABLE space_debris (id INT,name VARCHAR(50),mass FLOAT,orbit VARCHAR(50));INSERT INTO space_debris (id,name,mass,orbit) VALUES (1,'Debris 1',150.3,'LEO');
SELECT SUM(mass) FROM space_debris WHERE orbit = 'LEO';
What is the average property size in eco_friendly_homes table?
CREATE TABLE eco_friendly_homes (id INT,size FLOAT,location VARCHAR(255)); INSERT INTO eco_friendly_homes (id,size,location) VALUES (1,1200.0,'San Francisco'),(2,1800.0,'New York'),(3,900.0,'Los Angeles');
SELECT AVG(size) FROM eco_friendly_homes;
What is the total quantity of recycled polyester used by each manufacturer?
CREATE TABLE Manufacturers (id INT,name TEXT); CREATE TABLE RecycledPolyesterUsage (manufacturer_id INT,quantity INT); INSERT INTO Manufacturers (id,name) VALUES (1,'Manufacturer X'),(2,'Manufacturer Y'),(3,'Manufacturer Z'); INSERT INTO RecycledPolyesterUsage (manufacturer_id,quantity) VALUES (1,5000),(1,6000),(2,4000),(3,7000),(3,8000);
SELECT m.name, SUM(rpu.quantity) FROM Manufacturers m JOIN RecycledPolyesterUsage rpu ON m.id = rpu.manufacturer_id GROUP BY m.name;
What is the average carbon offset for green buildings in 'New York'?
CREATE TABLE green_buildings (id INT,city VARCHAR(20),carbon_offset FLOAT); INSERT INTO green_buildings (id,city,carbon_offset) VALUES (1,'New York',30.5),(2,'Los Angeles',25.3),(3,'New York',32.1),(4,'Chicago',28.9);
SELECT AVG(carbon_offset) FROM green_buildings WHERE city = 'New York';
List the events that had more than 50 visitors.
CREATE TABLE events_attendance (event_id INT,visitors INT); INSERT INTO events_attendance VALUES (1,60);
SELECT e.name FROM events e JOIN events_attendance ea ON e.id = ea.event_id GROUP BY e.name HAVING COUNT(ea.visitors) > 50;
What is the average revenue per night for hotels in Spain?
CREATE TABLE hotels (id INT,name TEXT,country TEXT,is_eco_friendly BOOLEAN,daily_revenue INT); INSERT INTO hotels (id,name,country,is_eco_friendly,daily_revenue) VALUES (1,'Barcelona Eco Hotel','Spain',true,300),(2,'Madrid Hotel','Spain',false,250),(3,'Ibiza Green Hotel','Spain',true,400);
SELECT AVG(daily_revenue) FROM hotels WHERE country = 'Spain';
How many tons of REE were produced by each mine in Q1 2018?
CREATE TABLE mines (id INT,name TEXT,location TEXT,quarter INT,annual_production INT); INSERT INTO mines (id,name,location,quarter,annual_production) VALUES (1,'Mine A','Country X',1,375),(2,'Mine B','Country Y',1,500),(3,'Mine C','Country Z',1,437);
SELECT name, SUM(annual_production) as total_production FROM mines WHERE YEAR(timestamp) = 2018 AND quarter = 1 GROUP BY name;
What is the average rating of hotels in New York City that have adopted hospitality AI?
CREATE TABLE hotels (id INT,name TEXT,city TEXT,rating FLOAT,ai_adoption BOOLEAN); INSERT INTO hotels (id,name,city,rating,ai_adoption) VALUES (1,'The Plaza','New York City',4.5,true),(2,'The Bowery Hotel','New York City',4.7,false);
SELECT AVG(rating) FROM hotels WHERE city = 'New York City' AND ai_adoption = true;
What is the earliest launch date of a spacecraft that visited Uranus?
CREATE TABLE SpacecraftMissions (MissionID INT,SpacecraftID INT,LaunchDate DATE,Destination VARCHAR(50));
SELECT MIN(LaunchDate) FROM SpacecraftMissions WHERE Destination = 'Uranus';
Find the minimum water_usage in the residential table for the month of July 2022, excluding any customers with a water_usage of 0.
CREATE TABLE residential (customer_id INT,water_usage FLOAT,usage_date DATE); INSERT INTO residential (customer_id,water_usage,usage_date) VALUES (1,150.5,'2022-07-01'),(2,0,'2022-07-02'),(3,800.4,'2022-07-03');
SELECT MIN(water_usage) FROM residential WHERE usage_date BETWEEN '2022-07-01' AND '2022-07-31' AND water_usage > 0;
What is the maximum water temperature recorded for each farm?
CREATE TABLE FarmTemp (FarmID int,Date date,WaterTemp float); INSERT INTO FarmTemp (FarmID,Date,WaterTemp) VALUES (1,'2022-01-01',10.5),(1,'2022-01-02',11.2),(2,'2022-01-01',12.1),(2,'2022-01-02',12.6);
SELECT FarmID, MAX(WaterTemp) as MaxTemp FROM FarmTemp GROUP BY FarmID;
Identify the top 3 nonprofits with the highest total donation amounts, regardless of their location or programs offered, and list their names and corresponding total donation amounts.
CREATE TABLE nonprofits (id INT,name TEXT,state TEXT,program TEXT,donation_amount FLOAT); INSERT INTO nonprofits (id,name,state,program,donation_amount) VALUES (1,'Nonprofit A','California','Education',25000.00),(2,'Nonprofit B','California','Health',50000.00),(3,'Nonprofit C','California','Environment',35000.00),(4,'Nonprofit D','Texas','Arts',60000.00),(5,'Nonprofit E','New York','Social Services',15000.00),(6,'Nonprofit F','Florida','Disaster Relief',70000.00);
SELECT name, SUM(donation_amount) as total_donation FROM nonprofits GROUP BY name ORDER BY total_donation DESC LIMIT 3;
What is the total number of local businesses in France that have implemented sustainable tourism practices?
CREATE TABLE local_biz (business_id INT,business_name TEXT,country TEXT,sustainability_practice BOOLEAN); INSERT INTO local_biz (business_id,business_name,country,sustainability_practice) VALUES (1,'Paris Patisserie','France',TRUE); INSERT INTO local_biz (business_id,business_name,country,sustainability_practice) VALUES (2,'Eiffel Tower Gift Shop','France',FALSE); INSERT INTO local_biz (business_id,business_name,country,sustainability_practice) VALUES (3,'Versailles Gardens Cafe','France',TRUE);
SELECT COUNT(*) FROM local_biz WHERE country = 'France' AND sustainability_practice = TRUE;
Find the mining sites where mining activities were recorded on a specific date
CREATE TABLE mining_sites (site_id INT,site_name VARCHAR(255)); INSERT INTO mining_sites (site_id,site_name) VALUES (1,'Site A'),(2,'Site B'); CREATE TABLE mining_activities (activity_id INT,site_id INT,activity_date DATE); INSERT INTO mining_activities (activity_id,site_id,activity_date) VALUES (1,1,'2022-01-01'),(2,1,'2022-01-02'),(3,2,'2022-01-01');
SELECT s.site_name FROM mining_sites s INNER JOIN mining_activities a ON s.site_id = a.site_id WHERE a.activity_date = '2022-01-01';
List all rural infrastructure projects in the 'rural_development' database, along with their corresponding budgets, and the total number of beneficiaries they have reached.
CREATE TABLE infrastructure_projects (project_id INT,project_name VARCHAR(50),budget INT,region VARCHAR(50)); CREATE TABLE beneficiaries (beneficiary_id INT,project_id INT,number_of_beneficiaries INT); INSERT INTO infrastructure_projects (project_id,project_name,budget,region) VALUES (1,'Road Construction',500000,'Midwest'),(2,'Bridge Building',700000,'Southeast'); INSERT INTO beneficiaries (beneficiary_id,project_id,number_of_beneficiaries) VALUES (1,1,500),(2,1,300),(3,2,800);
SELECT infrastructure_projects.project_name, infrastructure_projects.budget, SUM(beneficiaries.number_of_beneficiaries) FROM infrastructure_projects INNER JOIN beneficiaries ON infrastructure_projects.project_id = beneficiaries.project_id GROUP BY infrastructure_projects.project_name, infrastructure_projects.budget;
How many shared bikes were available in New York on the last day of each month?
CREATE TABLE bikes (id INT PRIMARY KEY,availability INT,date DATE); CREATE VIEW last_days AS SELECT MAX(date) FROM bikes GROUP BY EXTRACT(YEAR_MONTH FROM date);
SELECT COUNT(*) FROM bikes b JOIN last_days l ON b.date = l.MAX(date) WHERE b.availability > 0 AND EXTRACT(MONTH FROM b.date) = EXTRACT(MONTH FROM l.MAX(date));
What is the average monthly energy production for each wind farm in gigawatt-hours?
CREATE TABLE wind_farms (name VARCHAR(255),location VARCHAR(255),capacity FLOAT,monthly_production FLOAT); INSERT INTO wind_farms VALUES ('Farm A','USA',100,2000),('Farm B','Canada',150,3000),('Farm C','Germany',200,4000);
SELECT name, AVG(monthly_production) OVER (PARTITION BY name) AS avg_monthly_production FROM wind_farms;
What is the total cost of peacekeeping operations for African countries since 2010?
CREATE TABLE peacekeeping (id INT,country VARCHAR(50),operation VARCHAR(50),start_date DATE,end_date DATE,cost INT); INSERT INTO peacekeeping (id,country,operation,start_date,end_date,cost) VALUES (1,'Rwanda','UNAMIR','1993-10-22','1996-03-08',1234567),(2,'Burundi','ONUB','2004-06-01','2007-12-01',2345678);
SELECT SUM(cost) as total_cost FROM peacekeeping WHERE country LIKE 'Africa%' AND start_date >= '2010-01-01';
What is the average number of posts per user in the United States?
CREATE TABLE users (id INT,country VARCHAR(255)); INSERT INTO users (id,country) VALUES (1,'USA'),(2,'Canada'); CREATE TABLE posts (id INT,user_id INT,content TEXT); INSERT INTO posts (id,user_id,content) VALUES (1,1,'Hello'),(2,1,'World'),(3,2,'AI');
SELECT AVG(posts.user_id) FROM posts JOIN users ON posts.user_id = users.id WHERE users.country = 'USA';
List all aircraft models and their manufacturers with accidents since 2015.
CREATE TABLE aircraft (id INT,model VARCHAR(255),manufacturer_id INT); INSERT INTO aircraft (id,model,manufacturer_id) VALUES (1,'B737',1),(2,'A320',2),(3,'B787',1); CREATE TABLE manufacturer (id INT,name VARCHAR(255)); INSERT INTO manufacturer (id,name) VALUES (1,'Boeing'),(2,'Airbus'); CREATE TABLE accident (id INT,aircraft_id INT,accident_date DATE); INSERT INTO accident (id,aircraft_id,accident_date) VALUES (1,1,'2015-12-25'),(2,3,'2016-07-22');
SELECT a.model, m.name, COUNT(a.id) as accidents FROM aircraft a INNER JOIN manufacturer m ON a.manufacturer_id = m.id INNER JOIN accident ac ON a.id = ac.aircraft_id WHERE YEAR(ac.accident_date) >= 2015 GROUP BY a.model, m.name;
What is the average number of research grants received by graduate students in the Engineering program who identify as Latinx or Hispanic?
CREATE TABLE GraduateStudents(Id INT,Name VARCHAR(100),Program VARCHAR(50),GrantsReceived INT,Ethnicity VARCHAR(50)); INSERT INTO GraduateStudents(Id,Name,Program,GrantsReceived,Ethnicity) VALUES (1,'Aaliyah','Engineering',3,'Latinx'),(2,'Benjamin','Engineering',2,'Hispanic');
SELECT AVG(GrantsReceived) FROM GraduateStudents WHERE Program = 'Engineering' AND Ethnicity IN ('Latinx', 'Hispanic');
List all mining operations in the state of Pará, Brazil?
CREATE TABLE mining_operations (id INT,name VARCHAR(50),location VARCHAR(50)); INSERT INTO mining_operations (id,name,location) VALUES (1,'Mining Operation 1','Pará,Brazil'),(2,'Mining Operation 2','Amazonas,Brazil');
SELECT * FROM mining_operations WHERE location LIKE '%Pará, Brazil%';
What is the distribution of creative AI applications by region and application type?
CREATE TABLE creative_ai_applications (app_id INT,app_name TEXT,app_region TEXT,app_type TEXT); INSERT INTO creative_ai_applications (app_id,app_name,app_region,app_type) VALUES (1,'AI Art Generation','North America','Image'),(2,'AI Music Composition','Europe','Audio'),(3,'AI Poetry Writing','Asia','Text');
SELECT app_region, app_type, COUNT(*) as num_applications FROM creative_ai_applications GROUP BY app_region, app_type;
What is the racial and gender diversity of the company?
CREATE TABLE employees (employee_id INT,name TEXT,race TEXT,gender TEXT); INSERT INTO employees (employee_id,name,race,gender) VALUES (1,'Alice','Asian','Female'),(2,'Bob','White','Male'),(3,'Charlie','Black','Non-binary'),(4,'Dave','White','Male'),(5,'Eve','Latinx','Female');
SELECT race, gender, COUNT(*) AS num_employees FROM employees GROUP BY race, gender;
Delete record with id 1 from 'habitat_preservation'
CREATE TABLE habitat_preservation (id INT,project_name VARCHAR(50),location VARCHAR(50),size_acres DECIMAL(10,2),budget_USD DECIMAL(10,2),start_date DATE,end_date DATE);
WITH cte AS (DELETE FROM habitat_preservation WHERE id = 1) SELECT * FROM cte;
Delete records in the veteran_employment table where the 'name' is 'Sarah Lee' and 'job_start_date' is older than 2020-01-01
CREATE TABLE veteran_employment (veteran_id INT,name VARCHAR(50),job_start_date DATE);
DELETE FROM veteran_employment WHERE name = 'Sarah Lee' AND job_start_date < '2020-01-01';
Find animal species with a population greater than 1000 in a specific region
CREATE TABLE animal_population (id INT PRIMARY KEY,species VARCHAR(255),population INT,region VARCHAR(255));
SELECT species FROM animal_population WHERE population > 1000 AND region = 'African Savannah';
What is the minimum distance to the nearest healthcare facility for each village in the 'rural_villages' table, excluding villages with a population of less than 500?
CREATE TABLE rural_villages (id INT,name VARCHAR(100),population INT,healthcare_distance DECIMAL(5,2));
SELECT name, MIN(healthcare_distance) FROM rural_villages WHERE population >= 500 GROUP BY name;
Delete records of machines that have been under maintenance for over a year.
CREATE TABLE machines (id INT,model VARCHAR(50),year INT,status VARCHAR(50),maintenance_start_date DATE); INSERT INTO machines (id,model,year,status,maintenance_start_date) VALUES (1,'CNC Mill',2015,'Operational','2021-02-01'); INSERT INTO machines (id,model,year,status,maintenance_start_date) VALUES (2,'3D Printer',2018,'Under Maintenance','2022-05-10');
DELETE FROM machines WHERE status = 'Under Maintenance' AND maintenance_start_date <= DATEADD(year, -1, GETDATE());
What is the total number of military vehicles in the 'Europe' schema?
CREATE SCHEMA Europe; CREATE TABLE MilitaryVehicles (id INT,name VARCHAR(255),type VARCHAR(255),quantity INT); INSERT INTO MilitaryVehicles (id,name,type,quantity) VALUES (1,'Tank','Main Battle Tank',100); INSERT INTO MilitaryVehicles (id,name,type,quantity) VALUES (2,'APC','Armored Personnel Carrier',200);
SELECT SUM(quantity) FROM Europe.MilitaryVehicles;
What is the total number of volunteers for each program in the 'NonprofitDB' database?
CREATE TABLE Program (ID INT,Name VARCHAR(255)); INSERT INTO Program (ID,Name) VALUES (1,'Education'),(2,'Health'),(3,'Environment'); CREATE TABLE Volunteer (ID INT,Name VARCHAR(255),ProgramID INT); INSERT INTO Volunteer (ID,Name,ProgramID) VALUES (1,'John Doe',1),(2,'Jane Smith',2),(3,'Alice Johnson',3),(4,'Bob Brown',1),(5,'Charlie Davis',2);
SELECT v.ProgramID, COUNT(*) as TotalVolunteers FROM Volunteer v GROUP BY v.ProgramID;
What is the average financial wellbeing score for clients?
CREATE TABLE client_scores (id INT,client_id INT,financial_wellbeing_score INT); INSERT INTO client_scores (id,client_id,financial_wellbeing_score) VALUES (1,1,75),(2,2,60),(3,3,80);
SELECT AVG(financial_wellbeing_score) FROM client_scores;
Analyze the military technology used by different branches of the military, the year it was first introduced, and the latest version of the technology.
CREATE TABLE military_tech_branches (branch VARCHAR(255),tech_name VARCHAR(255),year_introduced INT,current_version INT);
SELECT branch, tech_name, MAX(year_introduced) as first_introduced, MAX(current_version) as latest_version FROM military_tech_branches GROUP BY branch, tech_name;
What is the maximum price of a vegan menu item?
CREATE TABLE menus (menu_id INT,menu_name TEXT,type TEXT,price DECIMAL); INSERT INTO menus (menu_id,menu_name,type,price) VALUES (1,'Quinoa Salad','Vegetarian',12.99),(2,'Chicken Caesar Wrap','Gluten-free',10.99),(3,'Vegan Burger','Vegan',14.99),(4,'Falafel Wrap','Vegan;Gluten-free',9.99);
SELECT MAX(price) FROM menus WHERE type = 'Vegan';
What is the average carbon sequestration of all forests in metric tons?
CREATE TABLE forest (id INT,name VARCHAR(255),area_ha INT,avg_carbon_ton FLOAT); INSERT INTO forest (id,name,area_ha,avg_carbon_ton) VALUES (1,'Forest1',10000,2.3),(2,'Forest2',12000,2.5),(3,'Forest3',15000,2.8);
SELECT AVG(avg_carbon_ton) FROM forest;
What is the average speed of electric vehicles in the "vehicles" table?
CREATE TABLE vehicles (id INT,make VARCHAR(255),model VARCHAR(255),type VARCHAR(255),top_speed INT); INSERT INTO vehicles (id,make,model,type,top_speed) VALUES (1,'Tesla','Model S','Electric',250);
SELECT AVG(top_speed) FROM vehicles WHERE type = 'Electric';
What is the minimum and maximum age of artists in the painting and sculpture media?
CREATE TABLE Artists (medium VARCHAR(20),age INT); INSERT INTO Artists (medium,age) VALUES ('Painting',25),('Painting',45),('Sculpture',30),('Sculpture',50);
SELECT MIN(age), MAX(age) FROM Artists WHERE medium IN ('Painting', 'Sculpture');
List the names and locations of all deep-sea hydrothermal vents.
CREATE TABLE hydrothermal_vents (vent_name TEXT,location TEXT,depth FLOAT); INSERT INTO hydrothermal_vents (vent_name,location,depth) VALUES ('Chimney 1','Atlantic Ocean',2100.0),('Vent A','Pacific Ocean',2700.0),('Vent B','Indian Ocean',3200.0);
SELECT vent_name, location FROM hydrothermal_vents;
What is the total weight (in kg) of packages shipped via each shipping method, in the last month?
CREATE TABLE shipments (shipment_id INT,shipping_method TEXT,weight FLOAT); INSERT INTO shipments (shipment_id,shipping_method,weight) VALUES (1,'ground',10.5),(2,'air',15.3),(3,'ocean',8.2);
SELECT shipping_method, SUM(weight) as total_weight FROM shipments WHERE shipped_date BETWEEN DATEADD(day, -30, GETDATE()) AND GETDATE() GROUP BY shipping_method;
What was the total revenue for music concerts, by city and continent?
CREATE TABLE MusicConcertsWorldwide (title VARCHAR(255),city VARCHAR(255),continent VARCHAR(255),revenue FLOAT,concert_date DATE); INSERT INTO MusicConcertsWorldwide (title,city,continent,revenue,concert_date) VALUES ('ConcertA','NYC','North America',100000,'2022-01-01'),('ConcertB','LA','North America',120000,'2022-01-02'),('ConcertC','Sydney','Australia',80000,'2022-01-03');
SELECT continent, city, SUM(revenue) FROM MusicConcertsWorldwide GROUP BY continent, city;
Which events have more than 10,000 fans attending in the 'concerts' table?
CREATE TABLE concerts (event_id INT,event_name VARCHAR(50),location VARCHAR(50),date DATE,ticket_price DECIMAL(5,2),num_tickets INT);
SELECT event_name FROM concerts WHERE num_tickets > 10000 GROUP BY event_name;
Find the number of fans who have attended ice hockey games in both Toronto and Vancouver.
CREATE TABLE fans (fan_id INT,age INT,gender VARCHAR(10),city VARCHAR(20)); INSERT INTO fans VALUES (1,25,'Male','Toronto'); INSERT INTO fans VALUES (2,35,'Female','Vancouver'); CREATE TABLE games (game_id INT,team VARCHAR(20),location VARCHAR(20)); INSERT INTO games VALUES (1,'Maple Leafs','Toronto'); INSERT INTO games VALUES (2,'Canucks','Vancouver');
SELECT COUNT(DISTINCT fans.fan_id) FROM fans WHERE fans.city IN ('Toronto', 'Vancouver') GROUP BY fans.city HAVING COUNT(DISTINCT fans.city) > 1;
Delete records from "labor_disputes" table where the "dispute_date" is before '2020-01-01'
CREATE TABLE labor_disputes (id INT,union_name VARCHAR(50),dispute_date DATE,dispute_reason VARCHAR(50)); INSERT INTO labor_disputes (id,union_name,dispute_date,dispute_reason) VALUES (1,'United Steelworkers','2019-12-01','Wages'),(2,'Teamsters','2020-06-15','Benefits'),(3,'Service Employees International Union','2018-03-03','Working conditions');
DELETE FROM labor_disputes WHERE dispute_date < '2020-01-01';
What is the minimum construction cost of any project in the city of Bangkok, Thailand?
CREATE TABLE ConstructionProjects (id INT,city VARCHAR(50),country VARCHAR(50),cost FLOAT);
SELECT MIN(cost) FROM ConstructionProjects WHERE city = 'Bangkok';
What is the average investment in Shariah-compliant funds per client?
CREATE TABLE clients (id INT,name VARCHAR(255)); INSERT INTO clients (id,name) VALUES (1,'John Doe'),(2,'Jane Smith'),(3,'Alice Johnson'); CREATE TABLE investments (id INT,client_id INT,fund_type VARCHAR(255),amount DECIMAL(10,2)); INSERT INTO investments (id,client_id,fund_type,amount) VALUES (1,1,'Shariah-compliant',5000),(2,1,'Standard',3000),(3,3,'Standard',7000),(4,2,'Shariah-compliant',4000),(5,2,'Shariah-compliant',6000);
SELECT AVG(amount / NULLIF(cnt, 0)) FROM (SELECT client_id, COUNT(*) AS cnt, SUM(amount) AS amount FROM investments WHERE fund_type = 'Shariah-compliant' GROUP BY client_id) t;
What is the minimum water salinity level for all shrimp farms in the Gulf of Mexico?
CREATE TABLE shrimp_farms (id INT,name TEXT,region TEXT,salinity FLOAT); INSERT INTO shrimp_farms (id,name,region,salinity) VALUES (1,'Farm K','Gulf of Mexico',30.1); INSERT INTO shrimp_farms (id,name,region,salinity) VALUES (2,'Farm L','Gulf of Mexico',32.5); INSERT INTO shrimp_farms (id,name,region,salinity) VALUES (3,'Farm M','Gulf of Mexico',29.9);
SELECT MIN(salinity) FROM shrimp_farms WHERE region = 'Gulf of Mexico';
How many customers in Japan have a waist size of 60 or larger?
CREATE TABLE customer_sizes (id INT,customer_id INT,waist DECIMAL(3,1),hip DECIMAL(3,1),country VARCHAR(50));
SELECT COUNT(*) FROM customer_sizes WHERE country = 'Japan' AND waist >= 60;
Show the average billing amount for cases with a 'Civil' case type.
CREATE TABLE cases (case_id INT,case_type VARCHAR(10),billing_amount DECIMAL(10,2)); INSERT INTO cases (case_id,case_type,billing_amount) VALUES (1,'Civil',500.00),(2,'Criminal',750.00),(3,'Civil',1000.00);
SELECT AVG(billing_amount) FROM cases WHERE case_type = 'Civil';
Find the total quantity of fish in the 'SeaBreeze' farm.
CREATE TABLE Farm (id INT,farm_name TEXT,species TEXT,weight FLOAT,age INT); INSERT INTO Farm (id,farm_name,species,weight,age) VALUES (1,'OceanPacific','Tilapia',500.3,2),(2,'SeaBreeze','Salmon',300.1,1),(3,'OceanPacific','Tilapia',600.5,3),(4,'FarmX','Salmon',700.2,4),(5,'SeaBreeze','Tilapia',400,2);
SELECT SUM(weight) FROM Farm WHERE farm_name = 'SeaBreeze';
What is the total number of military innovation projects for each department in the 'military_innovation' and 'departments' tables?
CREATE TABLE departments (department_id INT,department_name VARCHAR(50)); CREATE TABLE military_innovation (innovation_id INT,innovation_name VARCHAR(50),department_id INT); INSERT INTO departments VALUES (1,'Research'),(2,'Development'),(3,'Procurement'); INSERT INTO military_innovation VALUES (1,'Stealth Technology',1),(2,'Advanced Radar Systems',1),(3,'Electric Armored Vehicles',2),(4,'Automated Turrets',2),(5,'Conventional Rifles',3),(6,'Body Armor',3);
SELECT d.department_name, COUNT(mi.innovation_id) as total_projects FROM departments d JOIN military_innovation mi ON d.department_id = mi.department_id GROUP BY d.department_name;
How many consumers in the US have shown interest in circular economy practices?
CREATE TABLE consumers (consumer_id INT,country VARCHAR(50),interest_1 VARCHAR(50),interest_2 VARCHAR(50),interest_3 VARCHAR(50)); INSERT INTO consumers (consumer_id,country,interest_1,interest_2,interest_3) VALUES (1,'US','Circular Economy','Sustainability','Fair Labor'),(2,'Canada','Sustainability','Ethical Fashion',''),(3,'Mexico','Fair Labor','','');
SELECT COUNT(*) FROM consumers WHERE country = 'US' AND interest_1 = 'Circular Economy';
What is the average price of organic haircare products in Canada?
CREATE TABLE products (product_id INT,product_name VARCHAR(255),category VARCHAR(255),price DECIMAL(10,2),is_organic BOOLEAN); INSERT INTO products (product_id,product_name,category,price,is_organic) VALUES (1,'Moisturizing Shampoo','Haircare',14.99,true),(2,'Strengthening Conditioner','Haircare',12.99,false),(3,'Volumizing Shampoo','Haircare',15.99,true);
SELECT AVG(price) FROM products WHERE category = 'Haircare' AND is_organic = true AND country = 'Canada';
Calculate the average recycling rate for 'Asia' in 2021 from the 'recycling_rates' table
CREATE TABLE recycling_rates (country VARCHAR(50),year INT,recycling_rate FLOAT);
SELECT AVG(recycling_rate) FROM recycling_rates WHERE year = 2021 AND country = 'Asia';
What is the total number of members in the 'Service Union' who have been members for more than 5 years?
CREATE TABLE ServiceUnion (member_id INT,member_name TEXT,years_as_member INT); INSERT INTO ServiceUnion (member_id,member_name,years_as_member) VALUES (1,'John Doe',6); INSERT INTO ServiceUnion (member_id,member_name,years_as_member) VALUES (2,'Jane Smith',3);
SELECT COUNT(*) FROM ServiceUnion WHERE years_as_member > 5;
Insert a new record into the "game_sessions" table with session_id 4, player_id 4, and session_length 60
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);
INSERT INTO game_sessions (session_id, player_id, session_length) VALUES (4, 4, 60);
What is the number of events organized by nonprofits focused on capacity building in the US by year?
CREATE TABLE event_years (event_year_id INT,year INT); INSERT INTO event_years VALUES (1,2020);
SELECT e.year, COUNT(*) as num_events FROM nonprofit_events ne JOIN events e ON ne.event_id = e.event_id JOIN nonprofits n ON ne.nonprofit_id = n.nonprofit_id JOIN event_years ey ON e.year = ey.year WHERE n.sector = 'capacity building' GROUP BY e.year;
What is the average donation amount by donors from Asia?
CREATE TABLE donations (id INT,donor_continent VARCHAR(50),donation_amount DECIMAL(10,2)); INSERT INTO donations (id,donor_continent,donation_amount) VALUES (1,'Asia',50.00),(2,'North America',100.00);
SELECT AVG(donation_amount) FROM donations WHERE donor_continent = 'Asia';
What is the average age of community health workers by region in India?
CREATE TABLE indian_community_health_workers (id INT,name VARCHAR(50),age INT,region VARCHAR(50)); INSERT INTO indian_community_health_workers (id,name,age,region) VALUES (1,'Rajesh Patel',35,'North');
SELECT region, AVG(age) as avg_age FROM indian_community_health_workers GROUP BY region;
What is the minimum cost of satellites deployed by ISRO?
CREATE TABLE SatelliteDeployment(id INT,organization VARCHAR(255),satellite VARCHAR(255),cost FLOAT); INSERT INTO SatelliteDeployment(id,organization,satellite,cost) VALUES (1,'ISRO','Satellite 1',1200000),(2,'NASA','Satellite 2',1500000),(3,'ISRO','Satellite 3',1000000);
SELECT MIN(cost) FROM SatelliteDeployment WHERE organization = 'ISRO';
Delete all records related to the Hip Hop genre from the MusicArtists, MusicSales, and Tracks tables.
CREATE TABLE Tracks (track_id INT,track_name VARCHAR(50),genre VARCHAR(20),artist_id INT);
DELETE ma, ms, t FROM MusicArtists ma INNER JOIN MusicSales ms ON ma.artist_id = ms.artist_id INNER JOIN Tracks t ON ma.artist_id = t.artist_id WHERE ma.genre = 'Hip Hop';
What is the total investment amount made in the Latin America region in the last 6 months?
CREATE TABLE investments (id INT,region VARCHAR(255),date DATE,amount FLOAT); INSERT INTO investments (id,region,date,amount) VALUES (1,'Latin America','2021-03-15',25000),(2,'Europe','2020-12-21',30000),(3,'Latin America','2021-01-03',15000);
SELECT SUM(amount) FROM investments WHERE region = 'Latin America' AND date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH);
What is the total landfill capacity in cubic meters for each region as of January 1, 2022?
CREATE TABLE landfill_capacity (region VARCHAR(255),capacity_cubic_meter INT,date DATE); INSERT INTO landfill_capacity (region,capacity_cubic_meter,date) VALUES ('RegionA',100000,'2022-01-01'),('RegionB',120000,'2022-01-01'),('RegionC',150000,'2022-01-01');
SELECT region, SUM(capacity_cubic_meter) FROM landfill_capacity WHERE date = '2022-01-01' GROUP BY region;
Which threat types were most frequently detected in the APAC region in the past week?
CREATE TABLE detections (id INT,threat_type VARCHAR(255),region VARCHAR(255),detection_date DATE); INSERT INTO detections (id,threat_type,region,detection_date) VALUES (1,'Malware','APAC','2022-01-01'),(2,'Phishing','APAC','2022-01-02'),(3,'Ransomware','APAC','2022-01-03');
SELECT threat_type, COUNT(*) AS detection_count FROM detections WHERE region = 'APAC' AND detection_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK) GROUP BY threat_type ORDER BY detection_count DESC;
What was the average age of attendees for each event in 2022?
CREATE TABLE event_attendance (event_id INT,attendee_age INT,program_id INT,event_date DATE); INSERT INTO event_attendance (event_id,attendee_age,program_id,event_date) VALUES (1,34,101,'2022-05-12'); INSERT INTO event_attendance (event_id,attendee_age,program_id,event_date) VALUES (2,45,102,'2022-06-20');
SELECT event_id, AVG(attendee_age) as avg_age FROM event_attendance WHERE YEAR(event_date) = 2022 GROUP BY event_id;
What is the maximum transaction amount for each digital asset in the 'crypto_transactions' table, ordered by the maximum transaction amount in descending order?
CREATE TABLE crypto_transactions (transaction_id INT,digital_asset VARCHAR(20),transaction_amount DECIMAL(10,2),transaction_time DATETIME);
SELECT digital_asset, MAX(transaction_amount) as max_transaction_amount FROM crypto_transactions GROUP BY digital_asset ORDER BY max_transaction_amount DESC;
What is the ratio of completed to total projects for community development initiatives in Africa in the last 5 years?
CREATE TABLE CommunityProjects (ProjectID INT,ProjectName VARCHAR(50),Location VARCHAR(50),StartDate DATE,CompletionDate DATE); INSERT INTO CommunityProjects (ProjectID,ProjectName,Location,StartDate,CompletionDate) VALUES (1,'Clean Water Project','Nigeria','2016-01-01','2017-12-31'),(2,'Renewable Energy Initiative','Kenya','2018-01-01','2019-12-31');
SELECT AVG(CASE WHEN StartDate >= DATEADD(YEAR, -5, CURRENT_DATE) THEN 1.0 * COUNT(CASE WHEN CompletionDate IS NOT NULL THEN 1 END) / COUNT(*) ELSE NULL END) FROM CommunityProjects WHERE Location IN ('Nigeria', 'Kenya');
How many visitors attended the exhibition on African art from each continent in the last month?
CREATE TABLE exhibition_attendees (id INT,event_date DATE,continent VARCHAR(255)); INSERT INTO exhibition_attendees (id,event_date,continent) VALUES (1,'2022-04-15','Africa'),(2,'2022-04-20','Asia'),(3,'2022-04-25','Africa');
SELECT continent, COUNT(*) FROM exhibition_attendees WHERE event_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) AND CURRENT_DATE AND exhibition = 'African Art' GROUP BY continent;
What is the total waste generation in the Asian region for the year 2020?
CREATE TABLE waste_generation (id INT,region VARCHAR(255),year INT,waste_quantity INT); INSERT INTO waste_generation (id,region,year,waste_quantity) VALUES (1,'Asia',2020,5000),(2,'Asia',2019,4500),(3,'Europe',2020,6000);
SELECT SUM(waste_quantity) FROM waste_generation WHERE region = 'Asia' AND year = 2020;