instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What is the average salary of workers in the 'mining' department across all companies? | CREATE TABLE companies (company_id INT,department VARCHAR(20));CREATE TABLE workers (worker_id INT,company_id INT,salary DECIMAL(5,2),position VARCHAR(20)); | SELECT AVG(salary) FROM workers w INNER JOIN companies c ON w.company_id = c.company_id WHERE department = 'mining'; |
Identify players who have not participated in any tournament with a prize pool over 5 million. | CREATE TABLE Tournaments (Game VARCHAR(50),TournamentName VARCHAR(50),PrizePool INT); INSERT INTO Tournaments (Game,TournamentName,PrizePool) VALUES ('CS:GO','EL Major 2022',500000); INSERT INTO Tournaments (Game,TournamentName,PrizePool) VALUES ('Dota 2','The International 2022',40000000); INSERT INTO Tournaments (Game,TournamentName,PrizePool) VALUES ('Fortnite','World Cup 2022',50000000); | SELECT Players.PlayerName, Players.Game FROM Players LEFT JOIN Tournaments ON Players.Game = Tournaments.Game WHERE Tournaments.PrizePool < 5000000 OR Tournaments.TournamentName IS NULL; |
Find the number of defense diplomacy events in each region | CREATE TABLE defense_diplomacy (event_date DATE,region VARCHAR(255)); INSERT INTO defense_diplomacy (event_date,region) VALUES ('2020-01-01','Europe'),('2021-01-01','Asia'),('2020-06-01','Africa'); | SELECT region, COUNT(*) as total_events FROM defense_diplomacy GROUP BY region; |
Update the depth of the 'Galapagos Islands' in the marine_protected_areas table to 1500 meters. | CREATE TABLE marine_protected_areas (name VARCHAR(255),depth FLOAT); INSERT INTO marine_protected_areas (name,depth) VALUES ('Galapagos Islands',2000.0),('Grand Bahama Bank',800.0); | UPDATE marine_protected_areas SET depth = 1500 WHERE name = 'Galapagos Islands'; |
List the 'Social Services' causes that received the most donations in H1 2022, along with their total donation amounts. | CREATE TABLE causes (cause_id INT,name VARCHAR(255),category VARCHAR(255)); | SELECT c.name, SUM(d.donation_amount) as total_donated FROM donations d JOIN causes c ON d.cause = c.name WHERE d.donation_date BETWEEN '2022-01-01' AND '2022-06-30' AND c.category = 'Social Services' GROUP BY c.name ORDER BY total_donated DESC LIMIT 5; |
What is the total donation amount received from all donors in the last month? | CREATE TABLE DonorRegistry (donorID INT,donationDate DATE,donationAmount DECIMAL(10,2)); INSERT INTO DonorRegistry (donorID,donationDate,donationAmount) VALUES (1,'2022-03-02',150.50),(2,'2022-03-15',200.00),(3,'2022-03-27',125.75); | SELECT SUM(donationAmount) FROM DonorRegistry WHERE donationDate >= '2022-03-01' AND donationDate <= '2022-03-31'; |
List all space missions that have had both male and female crew members. | CREATE TABLE Missions (MissionID INT,Name VARCHAR(50),LaunchDate DATETIME,CrewGender VARCHAR(10)); INSERT INTO Missions (MissionID,Name,LaunchDate,CrewGender) VALUES (1,'Artemis I','2022-08-29','Male'),(2,'Artemis II','2023-06-01','Mixed'),(3,'Artemis III','2024-08-10','Female'); | SELECT Name FROM Missions WHERE CrewGender = 'Male' AND CrewGender = 'Female'; |
What is the distribution of graduate students by research area in the School of Medicine? | CREATE TABLE student (id INT,name VARCHAR(255),department_id INT,research_area VARCHAR(255)); CREATE TABLE department (id INT,name VARCHAR(255),school VARCHAR(255)); | SELECT d.name, s.research_area, COUNT(s.id) as count FROM student s JOIN department d ON s.department_id = d.id WHERE d.school = 'School of Medicine' GROUP BY d.name, s.research_area; |
What is the minimum temperature recorded at ocean surface in the Southern Ocean? | CREATE TABLE ocean_surface_temperatures (id INT,location TEXT,temperature FLOAT,region TEXT); | SELECT MIN(temperature) FROM ocean_surface_temperatures WHERE region = 'Southern Ocean'; |
What is the rank of the humanitarian aid projects in Nigeria based on their costs? | CREATE TABLE if not exists humanitarian_aid (id INT,project_name VARCHAR(100),location VARCHAR(100),amount FLOAT,date DATE); INSERT INTO humanitarian_aid (id,project_name,location,amount,date) VALUES (1,'Flood Relief','Pakistan',5000000,'2010-07-01'); INSERT INTO humanitarian_aid (id,project_name,location,amount,date) VALUES (2,'Earthquake Relief','Haiti',7000000,'2010-01-12'); | SELECT project_name, location, amount, RANK() OVER(ORDER BY amount DESC) as rank FROM humanitarian_aid WHERE location = 'Nigeria'; |
Update astronaut records with medical procedure 'Y' to procedure 'Z' | CREATE TABLE Astronauts (Name TEXT,Medical_Procedures TEXT); INSERT INTO Astronauts (Name,Medical_Procedures) VALUES ('John Glenn','Y'),('Valentina Tereshkova','Y'),('Neil Armstrong','checkup'); | WITH updated_procedures AS (UPDATE Astronauts SET Medical_Procedures = 'Z' WHERE Medical_Procedures = 'Y') SELECT * FROM updated_procedures; |
What is the most common type of natural disaster in Texas? | CREATE TABLE natural_disasters (id INT,state VARCHAR(255),type VARCHAR(255),number_of_disasters INT); INSERT INTO natural_disasters (id,state,type,number_of_disasters) VALUES (1,'Texas','Tornado',30),(2,'Texas','Flood',40); | SELECT type, COUNT(*) AS count FROM natural_disasters WHERE state = 'Texas' GROUP BY type ORDER BY count DESC LIMIT 1; |
How many cricket games in the cricket_league table were won by teams that have a male coach? | CREATE TABLE cricket_league (game_id INT,team_name VARCHAR(50),coach_gender VARCHAR(10)); CREATE VIEW cricket_league_won AS SELECT game_id,team_name FROM cricket_league WHERE result = 'win'; | SELECT COUNT(*) FROM cricket_league_won JOIN cricket_league ON cricket_league_won.team_name = cricket_league.team_name WHERE coach_gender = 'male'; |
What is the maximum dissolved oxygen level for aquaculture sites located in Asia, partitioned by farm type? | CREATE TABLE aquaculture_sites (site_id INT,region VARCHAR(50),farm_type VARCHAR(50),dissolved_oxygen FLOAT); INSERT INTO aquaculture_sites VALUES (1,'Asia','Freshwater',8.5),(2,'Asia','Marine',9.2),(3,'Africa','Freshwater',7.8),(4,'Europe','Marine',7.5); | SELECT region, farm_type, MAX(dissolved_oxygen) AS max_dissolved_oxygen FROM aquaculture_sites WHERE region = 'Asia' GROUP BY region, farm_type; |
What is the total billing amount for cases in each state? | CREATE TABLE cases (id INT,state VARCHAR(2),billing_amount DECIMAL(10,2)); INSERT INTO cases (id,state,billing_amount) VALUES (1,'CA',5000.00),(2,'NY',3000.00),(3,'CA',4000.00),(4,'TX',6000.00); | SELECT state, SUM(billing_amount) FROM cases GROUP BY state; |
Which dispensaries in Washington have the highest total sales for concentrates this year? | CREATE TABLE dispensaries (id INT,name TEXT,state TEXT);CREATE TABLE orders (id INT,dispensary_id INT,item_type TEXT,price DECIMAL,order_date DATE); | SELECT d.name, SUM(o.price) as total_sales FROM dispensaries d INNER JOIN orders o ON d.id = o.dispensary_id WHERE d.state = 'Washington' AND o.item_type = 'concentrates' AND YEAR(o.order_date) = YEAR(CURRENT_DATE) GROUP BY d.name ORDER BY total_sales DESC; |
Insert a new record of impact investment in Kenya with an amount of 2500000 and strategy_id 3. | CREATE TABLE impact_investments (id INT,country VARCHAR(255),amount FLOAT,strategy_id INT); | INSERT INTO impact_investments (id, country, amount, strategy_id) VALUES (1, 'Kenya', 2500000, 3); |
What is the percentage of sustainable materials used in each country? | CREATE TABLE production (production_id INT,material_id INT,quantity INT,country TEXT); CREATE TABLE materials (material_id INT,material_name TEXT,is_sustainable BOOLEAN); INSERT INTO production (production_id,material_id,quantity,country) VALUES (1,1,100,'USA'),(2,1,200,'USA'),(3,2,50,'Canada'),(4,2,150,'Canada'),(5,1,75,'USA'); INSERT INTO materials (material_id,material_name,is_sustainable) VALUES (1,'Organic Cotton',TRUE),(2,'Polyester',FALSE); | SELECT country, 100.0 * SUM(quantity) / (SELECT SUM(quantity) FROM production WHERE country = production.country) AS percentage FROM production JOIN materials ON production.material_id = materials.material_id WHERE is_sustainable = TRUE GROUP BY country; |
What is the total number of Shariah-compliant and socially responsible loans issued in each quarter? | CREATE TABLE loans_issued (loan_id INT,issue_date DATE,loan_type VARCHAR(20)); INSERT INTO loans_issued (loan_id,issue_date,loan_type) VALUES (101,'2022-01-01','Shariah-compliant personal loan'),(102,'2022-04-01','Socially responsible auto loan'),(103,'2022-07-01','Shariah-compliant mortgage'); | SELECT DATE_FORMAT(issue_date, '%Y-%m') AS quarter, loan_type, COUNT(*) FROM loans_issued GROUP BY quarter, loan_type; |
What is the maximum number of transactions per day for the smart contract with the id 2 in the month of November 2021? | CREATE TABLE SmartContracts (id INT,name VARCHAR(255),transaction_count INT,transaction_date DATE); INSERT INTO SmartContracts (id,name,transaction_count,transaction_date) VALUES (1,'ContractA',10,'2021-11-01'),(2,'ContractB',5,'2021-11-02'),(3,'ContractC',15,'2021-11-03'); | SELECT MAX(transaction_count) FROM SmartContracts WHERE id = 2 AND transaction_date >= '2021-11-01' AND transaction_date < '2021-12-01'; |
How many hybrid vehicles were sold in 'California' from '2020' to '2022' in the 'sales_data' table? | CREATE TABLE sales_data (state VARCHAR(50),year INT,vehicle_type VARCHAR(50),sales INT); | SELECT SUM(sales) FROM sales_data WHERE vehicle_type = 'hybrid' AND state = 'California' AND year BETWEEN 2020 AND 2022; |
Delete records in the "workers" table where the "department" is "Human Resources" and the "country" is "Canada" from the past 6 months | CREATE TABLE workers (id INT,name VARCHAR(50),department VARCHAR(50),country VARCHAR(50),hire_date DATE); INSERT INTO workers (id,name,department,country,hire_date) VALUES (1,'John Doe','Human Resources','Canada','2021-06-01'); | DELETE FROM workers WHERE department = 'Human Resources' AND country = 'Canada' AND hire_date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH); |
Delete records in the "player_scores" table where the score is below 500 | CREATE TABLE player_scores (player_id INT,game_name VARCHAR(255),score INT,date DATE); | DELETE FROM player_scores WHERE score < 500; |
What is the total number of animals in habitats that are located in a specific region? | CREATE TABLE animals (id INT PRIMARY KEY,name VARCHAR(50),species VARCHAR(50),population INT); CREATE TABLE habitats (id INT PRIMARY KEY,name VARCHAR(50),location VARCHAR(50),size FLOAT,animal_id INT); CREATE TABLE regions (id INT PRIMARY KEY,name VARCHAR(50)); | SELECT COUNT(DISTINCT animals.id) AS total_animals FROM animals INNER JOIN habitats ON animals.id = habitats.animal_id INNER JOIN regions ON habitats.location = regions.name WHERE regions.name = 'African Savannah'; |
How many male patients are there in rural_hospitals and rural_clinics combined? | CREATE TABLE rural_clinics (patient_id INT,age INT,gender VARCHAR(10),country VARCHAR(20)); CREATE TABLE rural_hospitals (patient_id INT,age INT,gender VARCHAR(10),admission_date DATE); | SELECT COUNT(*) FROM (SELECT patient_id FROM rural_clinics WHERE gender = 'Male' UNION ALL SELECT patient_id FROM rural_hospitals WHERE gender = 'Male') AS combined_male_patients; |
What is the total number of construction labor hours worked on sustainable projects, and how many labor hours were spent on non-sustainable projects in the same region? | CREATE TABLE Sustainable_Projects (Project_ID INT,Labor_Hours INT,Region TEXT); INSERT INTO Sustainable_Projects (Project_ID,Labor_Hours,Region) VALUES (1,5000,'Northeast'),(2,7000,'Midwest'),(3,6000,'West'); CREATE TABLE Non_Sustainable_Projects (Project_ID INT,Labor_Hours INT,Region TEXT); INSERT INTO Non_Sustainable_Projects (Project_ID,Labor_Hours,Region) VALUES (1,4000,'Northeast'),(2,6500,'Midwest'),(3,8000,'West'); | SELECT SUM(Sustainable_Projects.Labor_Hours) AS Sustainable_Labor_Hours, SUM(Non_Sustainable_Projects.Labor_Hours) AS Non_Sustainable_Labor_Hours FROM Sustainable_Projects, Non_Sustainable_Projects WHERE Sustainable_Projects.Region = Non_Sustainable_Projects.Region; |
Display the military technologies and their development status, and determine the percentage of completed technologies. | CREATE TABLE military_tech_status (id INT,tech VARCHAR,status VARCHAR); INSERT INTO military_tech_status (id,tech,status) VALUES (1,'Stealth Helicopter','Completed'),(2,'AI-Powered Drone','In Progress'),(3,'Electric Tank','Completed'); | SELECT tech, status, COUNT(*) OVER () * 100.0 / SUM(CASE WHEN status = 'Completed' THEN 1.0 ELSE 0.0 END) OVER () as pct_completed FROM military_tech_status WHERE status = 'Completed'; |
Which biotech startups have received funding over 10 million and are located in California? | CREATE TABLE startups (id INT,name VARCHAR(50),location VARCHAR(50),funding FLOAT); INSERT INTO startups (id,name,location,funding) VALUES (1,'Genetech','California',12000000); INSERT INTO startups (id,name,location,funding) VALUES (2,'Zymergen','California',25000000); | SELECT name FROM startups WHERE funding > 10000000 AND location = 'California'; |
What is the average rainfall per month for each region in the 'agriculture_data' table? | CREATE TABLE agriculture_data (region VARCHAR(50),rainfall INT,record_date DATE); INSERT INTO agriculture_data VALUES ('Central America',100,'2022-01-01'); INSERT INTO agriculture_data VALUES ('Central America',120,'2022-02-01'); INSERT INTO agriculture_data VALUES ('South America',150,'2022-01-01'); INSERT INTO agriculture_data VALUES ('South America',180,'2022-02-01'); | SELECT region, EXTRACT(MONTH FROM record_date) AS month, AVG(rainfall) AS avg_rainfall FROM agriculture_data GROUP BY region, month; |
List all cities with more than 5 sustainable accommodations? | CREATE TABLE accommodation (id INT,name TEXT,city TEXT,sustainable INT); INSERT INTO accommodation (id,name,city,sustainable) VALUES (1,'Green Retreat','Sydney',1); INSERT INTO accommodation (id,name,city,sustainable) VALUES (2,'Eco Lodge','Melbourne',1); INSERT INTO accommodation (id,name,city,sustainable) VALUES (3,'Eco Villa','Brisbane',1); | SELECT city, COUNT(*) as num_sustainable FROM accommodation WHERE sustainable = 1 GROUP BY city HAVING COUNT(*) > 5; |
Insert a new vessel with vessel_name 'Seacrest' and fuel_efficiency 5.2 into the vessel_performance table | CREATE TABLE vessel_performance (id INT,vessel_name VARCHAR(50),fuel_efficiency DECIMAL(3,2)); | INSERT INTO vessel_performance (vessel_name, fuel_efficiency) VALUES ('Seacrest', 5.2); |
Which underrepresented communities have contributed to the development of creative AI applications for the entertainment sector in the past two years, in the Creative AI database? | CREATE TABLE communities (id INT,name VARCHAR(255)); INSERT INTO communities (id,name) VALUES (1,'Community1'),(2,'Community2'); CREATE TABLE applications (id INT,name VARCHAR(255),community_id INT,sector VARCHAR(255),published_date DATE); INSERT INTO applications (id,name,community_id,sector,published_date) VALUES (1,'App1',1,'Entertainment','2021-01-01'),(2,'App2',2,'Education','2020-01-01'); | SELECT communities.name FROM communities JOIN applications ON communities.id = applications.community_id WHERE sector = 'Entertainment' AND YEAR(published_date) >= YEAR(CURRENT_DATE()) - 2 AND communities.name IN ('Community1', 'Community2'); |
What is the total number of marine protected areas in the Atlantic region that were established after 2010? | CREATE TABLE marine_protected_areas (name VARCHAR(255),region VARCHAR(255),establishment_year INT); INSERT INTO marine_protected_areas (name,region,establishment_year) VALUES ('Azores Nature Park','Atlantic',2011),('Cape Verde Islands','Atlantic',2014),('Bermuda','Atlantic',1966); | SELECT COUNT(*) FROM marine_protected_areas WHERE region = 'Atlantic' AND establishment_year > 2010; |
What is the average response time for fire departments in urban areas with a population greater than 500,000? | CREATE TABLE fire_departments (id INT,department_name VARCHAR(50),location VARCHAR(50),population INT,average_response_time FLOAT); | SELECT AVG(average_response_time) FROM fire_departments WHERE population > 500000 AND location = 'urban'; |
How many individuals have been referred to diversion programs in the past month, broken down by the program category and the defendant's ethnicity? | CREATE TABLE diversion_referrals (id INT,program_category TEXT,defendant_ethnicity TEXT,referral_date DATE); | SELECT program_category, defendant_ethnicity, COUNT(*) FROM diversion_referrals WHERE referral_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY program_category, defendant_ethnicity; |
What is the total amount donated to each cause? | CREATE TABLE Donors (DonorID int,DonorName varchar(50),DonationAmount decimal(10,2),CauseID int); CREATE TABLE Causes (CauseID int,CauseName varchar(50)); INSERT INTO Donors (DonorID,DonorName,DonationAmount,CauseID) VALUES (1,'John Doe',1000,1),(2,'Jane Smith',2000,2),(3,'Mike Johnson',3000,3),(4,'Sara Connor',500,1),(5,'David Lee',1500,2); INSERT INTO Causes (CauseID,CauseName) VALUES (1,'Education'),(2,'Health'),(3,'Environment'); | SELECT c.CauseName, SUM(d.DonationAmount) as TotalDonationAmount FROM Donors d JOIN Causes c ON d.CauseID = c.CauseID GROUP BY c.CauseName; |
What is the total number of flu cases reported in the last 30 days in Florida? | CREATE TABLE flu_cases (case_id INT,reported_date DATE,state VARCHAR(255)); INSERT INTO flu_cases VALUES (1,'2021-12-01','Florida'); INSERT INTO flu_cases VALUES (2,'2021-12-03','Florida'); | SELECT COUNT(*) FROM flu_cases WHERE state = 'Florida' AND reported_date >= CURDATE() - INTERVAL 30 DAY; |
What is the total production of Lanthanum in 2018 and 2019? | CREATE TABLE production (year INT,element VARCHAR(10),quantity INT); INSERT INTO production (year,element,quantity) VALUES (2017,'Lanthanum',1500),(2018,'Lanthanum',1600),(2019,'Lanthanum',1700),(2020,'Lanthanum',1800); | SELECT SUM(quantity) FROM production WHERE element = 'Lanthanum' AND year IN (2018, 2019); |
What is the average amount of donations received by each program? | CREATE TABLE program_donations (program VARCHAR(10),amount DECIMAL(10,2)); INSERT INTO program_donations (program,amount) VALUES ('ProgA',5000.00),('ProgA',3000.00),('ProgB',7000.00); | SELECT program, AVG(amount) FROM program_donations GROUP BY program; |
What is the total investment in renewable energy by each organization in Europe since 2010? | CREATE TABLE RenewableEnergyInvestment (organization VARCHAR(50),year INT,investment FLOAT); INSERT INTO RenewableEnergyInvestment (organization,year,investment) VALUES ('Shell',2010,1500000),('Shell',2015,2000000),('BP',2010,1200000),('BP',2015,1800000); | SELECT organization, SUM(investment) as 'Total Investment in Renewable Energy' FROM RenewableEnergyInvestment WHERE year >= 2010 AND continent = 'Europe' GROUP BY organization; |
What is the maximum duration of a Pilates class attended by a member from Japan? | CREATE TABLE Members (MemberID INT,Age INT,Gender VARCHAR(10),MembershipType VARCHAR(20),Country VARCHAR(50)); INSERT INTO Members (MemberID,Age,Gender,MembershipType,Country) VALUES (1,35,'Female','Premium','Japan'),(2,45,'Male','Basic','Canada'),(3,28,'Female','Premium','USA'),(4,32,'Male','Premium','Mexico'),(5,48,'Female','Basic','Japan'); CREATE TABLE ClassAttendance (MemberID INT,Class VARCHAR(20),Duration INT,Date DATE); INSERT INTO ClassAttendance (MemberID,Class,Duration,Date) VALUES (1,'Cycling',60,'2022-01-01'),(2,'Yoga',45,'2022-01-02'),(3,'Cycling',60,'2022-01-03'),(4,'Yoga',45,'2022-01-04'),(5,'Pilates',90,'2022-01-05'),(1,'Cycling',60,'2022-01-06'),(2,'Yoga',45,'2022-01-07'),(3,'Cycling',60,'2022-01-08'),(4,'Yoga',45,'2022-01-09'),(5,'Pilates',120,'2022-01-10'); | SELECT MAX(Duration) FROM Members JOIN ClassAttendance ON Members.MemberID = ClassAttendance.MemberID WHERE Members.Country = 'Japan' AND Class = 'Pilates'; |
What is the total billing amount for cases in the last 3 months? | CREATE TABLE cases (case_id INT,billing_date DATE,billing_amount DECIMAL(10,2)); INSERT INTO cases (case_id,billing_date,billing_amount) VALUES (1,'2021-01-01',5000.00),(2,'2021-02-01',7000.00),(3,'2021-03-01',3000.00); | SELECT SUM(billing_amount) FROM cases WHERE billing_date >= (CURRENT_DATE - INTERVAL '3 months'); |
What is the number of transactions per day for the past week for customers in the 'Retail' customer type? | CREATE TABLE customers (customer_id INT,customer_type VARCHAR(20)); INSERT INTO customers (customer_id,customer_type) VALUES (1,'Retail'),(2,'Wholesale'),(3,'Institutional'); CREATE TABLE transactions (transaction_date DATE,customer_id INT,transaction_value DECIMAL(10,2)); INSERT INTO transactions (transaction_date,customer_id,transaction_value) VALUES ('2022-01-01',1,500.00),('2022-01-02',1,750.00),('2022-01-03',2,3000.00),('2022-01-04',3,15000.00),('2022-01-05',1,200.00),('2022-01-06',2,1200.00),('2022-01-07',3,800.00); | SELECT transactions.transaction_date, COUNT(transactions.transaction_id) as number_of_transactions FROM transactions JOIN customers ON transactions.customer_id = customers.customer_id WHERE transactions.transaction_date >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND customers.customer_type = 'Retail' GROUP BY transactions.transaction_date; |
List the food justices in North America. | CREATE TABLE FoodJustice (id INT,name VARCHAR(50),location VARCHAR(50),type VARCHAR(50)); INSERT INTO FoodJustice (id,name,location,type) VALUES (1,'Fair Trade','North America','Food Justice'); | SELECT * FROM FoodJustice WHERE location = 'North America' AND type = 'Food Justice'; |
What is the maximum water temperature recorded for each fish species? | CREATE TABLE FishSpecies (SpeciesID int,SpeciesName varchar(50),WaterTemp float); INSERT INTO FishSpecies (SpeciesID,SpeciesName,WaterTemp) VALUES (1,'Salmon',12.5),(2,'Tuna',15.2),(3,'Cod',10.9); | SELECT SpeciesName, MAX(WaterTemp) as MaxTemp FROM FishSpecies GROUP BY SpeciesName; |
What is the total number of cybersecurity incidents reported worldwide each year for the last 3 years and their respective impact levels? | CREATE TABLE CybersecurityImpact (id INT,impact_level TEXT); INSERT INTO CybersecurityImpact (id,impact_level) VALUES (1,'High'),(2,'Medium'),(3,'Low'); CREATE TABLE CybersecurityIncidentsByYear (id INT,year INT,impact_id INT); INSERT INTO CybersecurityIncidentsByYear (id,year,impact_id) VALUES (1,2021,1),(2,2020,2),(3,2019,3); | SELECT YEAR(CybersecurityIncidentsByYear.year) as year, COUNT(CybersecurityIncidentsByYear.id) as total_incidents, AVG(CybersecurityImpact.impact_level) as avg_impact FROM CybersecurityIncidentsByYear INNER JOIN CybersecurityImpact ON CybersecurityIncidentsByYear.impact_id = CybersecurityImpact.id GROUP BY YEAR(CybersecurityIncidentsByYear.year) ORDER BY YEAR(CybersecurityIncidentsByYear.year) DESC LIMIT 3; |
Which restaurants have a revenue greater than $700,000? | CREATE TABLE Restaurants (id INT,name VARCHAR,category VARCHAR,revenue INT); INSERT INTO Restaurants (id,name,category,revenue) VALUES (1,'Bistro','French',500000); INSERT INTO Restaurants (id,name,category,revenue) VALUES (2,'Pizzeria','Italian',600000); INSERT INTO Restaurants (id,name,category,revenue) VALUES (3,'Seafood','Seafood',750000); | SELECT name, revenue FROM Restaurants WHERE revenue > 700000; |
What is the total budget for disaster response projects in the Pacific, excluding those that were cancelled? | CREATE TABLE projects (id INT,project_name TEXT,region TEXT,budget DECIMAL,status TEXT); INSERT INTO projects (id,project_name,region,budget,status) VALUES (1,'Typhoon Relief','Pacific',100000.00,'completed'),(2,'Flood Recovery','Pacific',150000.00,'cancelled'),(3,'Earthquake Assistance','Pacific',200000.00,'ongoing'); | SELECT SUM(budget) as total_budget FROM projects WHERE region = 'Pacific' AND status != 'cancelled'; |
Find the total water usage by industrial customers in the month of February 2022, excluding any customers with a water usage of 0. | CREATE TABLE industrial_customers (customer_id INT,water_usage FLOAT,usage_date DATE); INSERT INTO industrial_customers (customer_id,water_usage,usage_date) VALUES (1,500.3,'2022-02-01'),(2,700.2,'2022-02-02'),(3,0,'2022-02-03'); | SELECT SUM(water_usage) FROM industrial_customers WHERE usage_date BETWEEN '2022-02-01' AND '2022-02-28' AND water_usage > 0; |
How many accidents occurred at each mine site in H1 2021? | CREATE TABLE site_safety (site_id INT,site_name TEXT,incident_date DATE,accident_type TEXT,accident_details TEXT); INSERT INTO site_safety (site_id,site_name,incident_date,accident_type,accident_details) VALUES (1,'ABC Mine','2021-03-15','Fire','Fire broke out in a mining tunnel'),(2,'DEF Mine','2021-02-01','Flood','Heavy rain caused flooding in the mine'),(3,'GHI Mine','2021-01-20','Fire','Small fire in the control room'); | SELECT site_name, COUNT(*) as accidents_h1_2021 FROM site_safety WHERE incident_date BETWEEN '2021-01-01' AND '2021-06-30' GROUP BY site_name; |
What is the percentage of patients with mental health disorders who have had a community health worker visit in the past month? | CREATE TABLE patients (id INT,has_mental_health_disorder BOOLEAN,last_visit_date DATE); CREATE TABLE community_health_workers_visits (patient_id INT,visit_date DATE); INSERT INTO patients (id,has_mental_health_disorder,last_visit_date) VALUES (1,true,'2022-02-20'),(2,false,'2022-03-05'),(3,true,'2022-03-10'); INSERT INTO community_health_workers_visits (patient_id,visit_date) VALUES (1,'2022-03-05'),(2,'2022-03-07'),(3,'2022-03-12'); | SELECT (COUNT(*) FILTER (WHERE patients.has_mental_health_disorder = true AND community_health_workers_visits.visit_date >= (CURRENT_DATE - INTERVAL '1 month'))) * 100.0 / (SELECT COUNT(*) FROM patients WHERE has_mental_health_disorder = true) as percentage; |
Which countries in Europe have the highest travel advisory level? | CREATE TABLE travel_advisories (id INT,country VARCHAR,region VARCHAR,level INT); INSERT INTO travel_advisories (id,country,region,level) VALUES (1,'Ukraine','Europe',4); | SELECT country FROM travel_advisories WHERE region = 'Europe' AND level = (SELECT MAX(level) FROM travel_advisories WHERE region = 'Europe'); |
What is the total fine collected, for each type of violation? | CREATE TABLE fines (fine_id INT,violation_type VARCHAR(20),fine INT,collection_date DATE); INSERT INTO fines (fine_id,violation_type,fine,collection_date) VALUES (1,'Speeding',200,'2022-01-15'),(2,'Parking',50,'2022-01-17'),(3,'Speeding',100,'2022-01-18'); | SELECT violation_type, SUM(fine) as total_fine FROM fines GROUP BY violation_type; |
How many volunteers are engaged in each program, based on the 'Volunteers' and 'VolunteerPrograms' tables? | CREATE TABLE Volunteers (VolunteerID INT,Name TEXT); CREATE TABLE VolunteerPrograms (VolunteerID INT,ProgramID INT); INSERT INTO Volunteers (VolunteerID,Name) VALUES (1,'Alice'),(2,'Bob'),(3,'Charlie'); INSERT INTO VolunteerPrograms (VolunteerID,ProgramID) VALUES (1,1),(2,1),(3,2); | SELECT VolunteerPrograms.ProgramID, COUNT(DISTINCT Volunteers.VolunteerID) as VolunteerCount FROM VolunteerPrograms INNER JOIN Volunteers ON VolunteerPrograms.VolunteerID = Volunteers.VolunteerID GROUP BY VolunteerPrograms.ProgramID; |
How many security incidents were resolved by 'Security Analyst 1' in the 'incident_responses' table? | CREATE TABLE incident_responses (id INT,incident_type VARCHAR(50),status VARCHAR(20),responded_by VARCHAR(100)); INSERT INTO incident_responses (id,incident_type,status,responded_by) VALUES (1,'Phishing','Resolved','Security Analyst 1'),(2,'Malware','In Progress','Security Analyst 2'),(3,'Ransomware','Resolved','Security Analyst 1'); | SELECT COUNT(*) FROM incident_responses WHERE responded_by = 'Security Analyst 1' AND status = 'Resolved'; |
What is the average funding amount received by startups founded by women in the healthcare sector? | CREATE TABLE startups(id INT,name TEXT,industry TEXT,founding_year INT,founder_gender TEXT); INSERT INTO startups VALUES (1,'StartupA','Healthcare',2010,'Female'); INSERT INTO startups VALUES (2,'StartupB','Tech',2015,'Male'); | SELECT AVG(funding_amount) FROM investments JOIN startups ON investments.startup_id = startups.id WHERE startups.founder_gender = 'Female' AND startups.industry = 'Healthcare'; |
What are the names of all the whale species in the Antarctic Ocean and their conservation status? | CREATE TABLE marine_mammals (mammal_id INT,mammal_name VARCHAR(255),PRIMARY KEY(mammal_id)); INSERT INTO marine_mammals (mammal_id,mammal_name) VALUES (1,'Blue Whale'),(2,'Fin Whale'); CREATE TABLE conservation_status (status_id INT,mammal_id INT,status VARCHAR(255),PRIMARY KEY(status_id,mammal_id),FOREIGN KEY (mammal_id) REFERENCES marine_mammals(mammal_id)); INSERT INTO conservation_status (status_id,mammal_id,status) VALUES (1,1,'Endangered'),(2,2,'Vulnerable'); CREATE TABLE ocean_distribution (distribution_id INT,mammal_id INT,region VARCHAR(255),PRIMARY KEY(distribution_id,mammal_id),FOREIGN KEY (mammal_id) REFERENCES marine_mammals(mammal_id)); INSERT INTO ocean_distribution (distribution_id,mammal_id,region) VALUES (1,1,'Antarctic Ocean'),(2,2,'Antarctic Ocean'); | SELECT marine_mammals.mammal_name, conservation_status.status FROM marine_mammals INNER JOIN conservation_status ON marine_mammals.mammal_id = conservation_status.mammal_id INNER JOIN ocean_distribution ON marine_mammals.mammal_id = ocean_distribution.mammal_id WHERE ocean_distribution.region = 'Antarctic Ocean'; |
What are the names of all the buses that have had maintenance work in the past month? | CREATE TABLE bus_maintenance (id INT,bus_name VARCHAR(255),maintenance_date DATE); INSERT INTO bus_maintenance (id,bus_name,maintenance_date) VALUES (1,'Bus 101','2022-01-05'),(2,'Bus 102','2022-01-10'); | SELECT bus_name FROM bus_maintenance WHERE maintenance_date >= DATEADD(month, -1, GETDATE()); |
What is the total number of electric and autonomous vehicles in 'melbourne' and 'rio de janeiro'? | CREATE TABLE if not exists cities (city varchar(20)); INSERT INTO cities (city) VALUES ('melbourne'),('rio de janeiro'); CREATE TABLE if not exists vehicle_counts (city varchar(20),vehicle_type varchar(20),count int); INSERT INTO vehicle_counts (city,vehicle_type,count) VALUES ('melbourne','electric',1000),('melbourne','autonomous',1200),('rio de janeiro','electric',1500),('rio de janeiro','autonomous',1700); | SELECT city, SUM(count) as total_count FROM vehicle_counts WHERE (vehicle_type = 'electric' OR vehicle_type = 'autonomous') AND city IN ('melbourne', 'rio de janeiro') GROUP BY city; |
Calculate the total amount of transactions made in 'Los Angeles' in the month of March. | CREATE TABLE transactions (id INT PRIMARY KEY,account_id INT,type VARCHAR(255),amount DECIMAL(10,2),date DATE,client_id INT); INSERT INTO transactions (id,account_id,type,amount,date,client_id) VALUES (1,1,'Deposit',2000.00,'2021-01-01',1001),(2,2,'Withdrawal',1500.00,'2021-02-10',1002),(3,3,'Transfer',500.00,'2021-03-20',1003),(4,1003,'Withdrawal',1000.00,'2021-04-01',1005),(5,1002,'Withdrawal',500.00,'2021-05-15',1006),(6,5,'Deposit',1000.00,'2021-06-01',1004),(7,4,'Payment',500.00,'2021-06-15',1004); | SELECT SUM(amount) FROM transactions WHERE date BETWEEN '2021-03-01' AND '2021-03-31' AND client_id IN (SELECT id FROM clients WHERE city = 'Los Angeles'); |
How many deep-sea expeditions have been conducted in each country? | CREATE TABLE deep_sea_expeditions (country TEXT,year INT); INSERT INTO deep_sea_expeditions (country,year) VALUES ('USA',2010),('USA',2012),('France',2011),('Japan',2015),('China',2018),('Germany',2016),('Spain',2017),('Canada',2019),('UK',2013),('Australia',2014); | SELECT country, COUNT(*) FROM deep_sea_expeditions GROUP BY country; |
Insert new sales data for 'Sunshine Dispensary' | CREATE TABLE sales (id INT,dispensary TEXT,product TEXT,quantity INT,price DECIMAL); INSERT INTO sales (id,dispensary,product,quantity,price) VALUES (1,'Rainbow Dispensary','Gorilla Glue',4,55.99); | INSERT INTO sales (id, dispensary, product, quantity, price) VALUES (2, 'Sunshine Dispensary', 'Blue Dream', 7, 42.00); |
Update the average teacher age for public schools in a state to be the average of all schools in that state. | CREATE TABLE public_schools (id INT,name TEXT,location TEXT,num_students INT,avg_teacher_age FLOAT); INSERT INTO public_schools (id,name,location,num_students,avg_teacher_age) VALUES (1,'School 1','NC',500,45.3),(2,'School 2','NC',600,43.2),(3,'School 3','NC',700,47.1); | UPDATE public_schools SET avg_teacher_age = (SELECT AVG(avg_teacher_age) FROM public_schools AS s WHERE public_schools.location = s.location) WHERE TRUE; |
Who are the top 3 music artists by number of albums in the US? | CREATE TABLE artist (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255)); CREATE TABLE album (id INT PRIMARY KEY,title VARCHAR(255),year INT,artist_id INT,FOREIGN KEY (artist_id) REFERENCES artist(id)); INSERT INTO artist (id,name,country) VALUES (1,'ArtistA','USA'),(2,'ArtistB','USA'),(3,'ArtistC','USA'); INSERT INTO album (id,title,year,artist_id) VALUES (1,'AlbumX',2000,1),(2,'AlbumY',2002,1),(3,'AlbumZ',2005,2); | SELECT a.name, COUNT(al.id) AS albums_count FROM artist a JOIN album al ON a.id = al.artist_id GROUP BY a.id ORDER BY albums_count DESC LIMIT 3; |
List the names and countries of donors who have donated more than $5000, but less than $10000. | CREATE TABLE donors (id INT,name TEXT,country TEXT,amount_donated DECIMAL(10,2)); INSERT INTO donors (id,name,country,amount_donated) VALUES (1,'Alice','USA',5000.00),(2,'Bob','Canada',3000.00),(3,'Charlie','USA',7000.00),(4,'David','UK',8000.00),(5,'Eve','Germany',9000.00); | SELECT name, country FROM donors WHERE amount_donated > 5000.00 AND amount_donated < 10000.00; |
Update the capacity of all cargo ships owned by Acme Corp by 10% | CREATE TABLE ships (id INT,name VARCHAR(255),capacity INT); INSERT INTO ships (id,name,capacity) VALUES (1,'Acme1',5000),(2,'Acme2',7000); | UPDATE ships SET capacity = capacity * 1.1 WHERE name LIKE 'Acme%'; |
What is the total quantity of military equipment sold to Canada since 2019? | CREATE TABLE MilitaryEquipmentSales (SaleID INT,Equipment VARCHAR(50),Quantity INT,Country VARCHAR(50),SaleDate DATE); INSERT INTO MilitaryEquipmentSales (SaleID,Equipment,Quantity,Country,SaleDate) VALUES (1,'Tank',10,'USA','2020-01-01'),(2,'Jet',5,'Canada','2019-07-15'); | SELECT Equipment, SUM(Quantity) FROM MilitaryEquipmentSales WHERE Country = 'Canada' AND SaleDate >= '2019-01-01' GROUP BY Equipment; |
What is the average transaction amount for retail customers in London? | CREATE TABLE customers (id INT,name VARCHAR(255),city VARCHAR(255)); CREATE TABLE transactions (id INT,customer_id INT,amount DECIMAL(10,2),transaction_type VARCHAR(255)); INSERT INTO customers (id,name,city) VALUES (1,'John Doe','London'); INSERT INTO transactions (id,customer_id,amount,transaction_type) VALUES (1,1,500.00,'Retail'); | SELECT AVG(t.amount) as avg_amount FROM transactions t JOIN customers c ON t.customer_id = c.id WHERE c.city = 'London' AND t.transaction_type = 'Retail'; |
How many rural infrastructure projects were completed in Latin America in 2022? | CREATE TABLE RuralInfrastructure (id INT PRIMARY KEY,region VARCHAR(20),year INT,completed BOOLEAN); | SELECT COUNT(*) FROM RuralInfrastructure WHERE region = 'Latin America' AND year = 2022 AND completed = TRUE; |
What is the average percentage of organic ingredients in cosmetic products sourced from Brazil? | CREATE TABLE brazil_ingredient_sourcing (id INT,product_id INT,organic_ingredients_percentage INT); INSERT INTO brazil_ingredient_sourcing (id,product_id,organic_ingredients_percentage) VALUES (1,1,75); | SELECT AVG(organic_ingredients_percentage) FROM brazil_ingredient_sourcing; |
What is the total production of nickel mines in Canada? | CREATE TABLE mine (id INT,name TEXT,location TEXT,mineral TEXT,production INT); INSERT INTO mine (id,name,location,mineral,production) VALUES (1,'Vale','Canada','Nickel',12000),(2,'Glencore','Canada','Nickel',15000); | SELECT SUM(production) FROM mine WHERE mineral = 'Nickel' AND location = 'Canada'; |
How many players from India play games that are available in the 'Action' category? | CREATE TABLE Players (PlayerID INT,Age INT,Country VARCHAR(50)); INSERT INTO Players (PlayerID,Age,Country) VALUES (1,25,'India'),(2,30,'Canada'),(3,22,'Germany'),(4,35,'Japan'); CREATE TABLE GameLibrary (GameID INT,GameName VARCHAR(50),GameType VARCHAR(50),Category VARCHAR(50)); INSERT INTO GameLibrary (GameID,GameName,GameType,Category) VALUES (1,'GameA','VR','Action'),(2,'GameB','Non-VR','Strategy'),(3,'GameC','VR','Action'); CREATE TABLE PlayerGameLibrary (PlayerID INT,GameID INT); INSERT INTO PlayerGameLibrary (PlayerID,GameID) VALUES (1,1),(2,2),(3,1),(4,3); | SELECT COUNT(Players.PlayerID) FROM Players JOIN PlayerGameLibrary ON Players.PlayerID = PlayerGameLibrary.PlayerID JOIN GameLibrary ON PlayerGameLibrary.GameID = GameLibrary.GameID WHERE Players.Country = 'India' AND GameLibrary.Category = 'Action'; |
How many confirmed COVID-19 cases are there in each region, ordered by the total number of cases, descending? | CREATE TABLE covid_data (id INT,state TEXT,region TEXT,confirmed_cases INT); INSERT INTO covid_data (id,state,region,confirmed_cases) VALUES (1,'State A','Region 1',500),(2,'State B','Region 2',300),(3,'State C','Region 1',700),(4,'State D','Region 3',800); | SELECT region, SUM(confirmed_cases) as total_cases FROM covid_data GROUP BY region ORDER BY total_cases DESC; |
How many multi-unit properties are there in each city? | CREATE TABLE Cities (CityID INT,CityName VARCHAR(255)); CREATE TABLE Properties (PropertyID INT,PropertyType VARCHAR(255),CityID INT); INSERT INTO Cities VALUES (1,'New York'); INSERT INTO Properties VALUES (1,'Multi-Unit',1); | SELECT CityName, COUNT(*) FROM Properties p JOIN Cities c ON p.CityID = c.CityID WHERE p.PropertyType = 'Multi-Unit' GROUP BY CityName; |
What is the maximum mental health score for students in the 'remote_learning' program? | CREATE TABLE student_mental_health (student_id INT,program VARCHAR(20),score INT); INSERT INTO student_mental_health (student_id,program,score) VALUES (1,'remote_learning',75),(2,'remote_learning',80),(3,'in_person',85),(4,'in_person',90); | SELECT MAX(score) FROM student_mental_health WHERE program = 'remote_learning'; |
Update the policy_type to 'Renters' for policy_id 1 in the policy table | CREATE TABLE policy (policy_id INT,policy_holder_id INT,policy_type VARCHAR(50),policy_start_date DATE); INSERT INTO policy (policy_id,policy_holder_id,policy_type,policy_start_date) VALUES (1,10001,'Commercial Auto','2015-01-01'); INSERT INTO policy (policy_id,policy_holder_id,policy_type,policy_start_date) VALUES (2,10002,'Homeowners','2018-05-15'); | UPDATE policy SET policy_type = 'Renters' WHERE policy_id = 1; |
What is the average quantity of containers handled per port, for ports located in Asia? | CREATE TABLE ports (port_id INT,port_name TEXT,country TEXT); INSERT INTO ports VALUES (1,'Port A','China'),(2,'Port B','Japan'),(3,'Port C','South Korea'); CREATE TABLE cargo (cargo_id INT,port_id INT,quantity INT); INSERT INTO cargo VALUES (1,1,500),(2,1,600),(3,2,700),(4,3,800); | SELECT AVG(cargo.quantity) FROM cargo JOIN ports ON cargo.port_id = ports.port_id WHERE ports.country = 'Asia'; |
Update the safety record of 'Seafarer' by adding a new safety inspection with a 'Pass' result on 2022-11-15. | CREATE TABLE vessels (id INT,name VARCHAR(255),type VARCHAR(255)); CREATE TABLE safety_inspections (id INT,vessel_id INT,inspection_date DATE,result VARCHAR(255)); | INSERT INTO safety_inspections (id, vessel_id, inspection_date, result) SELECT nextval('safety_inspections_id_seq'::regclass), v.id, '2022-11-15', 'Pass' FROM vessels v WHERE name = 'Seafarer'; |
What is the total budget allocated for cybersecurity and intelligence operations in the 'budget_data' view for the year 2021? | CREATE VIEW budget_data AS SELECT category,allocated_budget FROM budget_table WHERE year = 2021; CREATE TABLE budget_table (year INT,category VARCHAR(50),allocated_budget FLOAT); INSERT INTO budget_table (year,category,allocated_budget) VALUES (2021,'Cybersecurity',20000000),(2021,'Intelligence Operations',30000000); | SELECT SUM(allocated_budget) FROM budget_data WHERE category IN ('Cybersecurity', 'Intelligence Operations'); |
What is the maximum response time for fire incidents in the 'North' district? | CREATE TABLE districts (id INT,name VARCHAR(255)); CREATE TABLE emergency_responses (id INT,district_id INT,type VARCHAR(255),response_time INT); INSERT INTO districts (id,name) VALUES (1,'North'); INSERT INTO emergency_responses (id,district_id,type,response_time) VALUES (1,1,'Fire',12); | SELECT MAX(response_time) FROM emergency_responses WHERE district_id = (SELECT id FROM districts WHERE name = 'North') AND type = 'Fire'; |
Identify the average age of patients who received group sessions in Community Center A. | CREATE TABLE community_centers (id INT,name VARCHAR(255)); INSERT INTO community_centers (id,name) VALUES (1,'Community Center A'),(2,'Community Center B'); CREATE TABLE treatments (id INT,community_center_id INT,patient_id INT,type VARCHAR(255)); INSERT INTO treatments (id,community_center_id,patient_id,type) VALUES (1,1,1,'therapy'),(2,1,2,'group session'),(3,2,3,'therapy'); CREATE TABLE patients (id INT,age INT); INSERT INTO patients (id,age) VALUES (1,35),(2,45),(3,50); | SELECT AVG(p.age) FROM patients p JOIN treatments t ON p.id = t.patient_id WHERE t.type = 'group session' AND t.community_center_id = 1; |
What is the average donation amount from returning donors who increased their donation in 2021 compared to 2020? | CREATE TABLE Donations (DonationID INT,DonorID INT,Amount DECIMAL(10,2),Year INT); INSERT INTO Donations (DonationID,DonorID,Amount,Year) VALUES (1,1,500.00,2020),(2,1,600.00,2021),(3,2,300.00,2020); | SELECT AVG(Amount) FROM Donations WHERE DonorID IN (SELECT DonorID FROM Donations WHERE Year = 2020 GROUP BY DonorID HAVING AVG(Amount) < (SELECT AVG(Amount) FROM Donations WHERE DonorID = Donations.DonorID AND Year = 2021 GROUP BY DonorID)); |
What is the average age of patients by ethnicity? | CREATE TABLE patients (id INT,name VARCHAR(50),age INT,ethnicity VARCHAR(50)); INSERT INTO patients (id,name,age,ethnicity) VALUES (1,'John Doe',45,'Caucasian'),(2,'Jane Smith',35,'African American'),(3,'Alice Johnson',50,'Hispanic'); | SELECT ethnicity, AVG(age) FROM patients GROUP BY ethnicity; |
Create a table for storing information about funding sources | CREATE TABLE FundingSources (FundingSourceID INT PRIMARY KEY,Name VARCHAR(100),Amount FLOAT,Date DATE); | CREATE TABLE FundingSources (FundingSourceID INT PRIMARY KEY, Name VARCHAR(100), Amount FLOAT, Date DATE); |
What is the total assets value per client as of the last day of each quarter? | CREATE TABLE assets (client_id INT,assets_value FLOAT,assets_date DATE); INSERT INTO assets (client_id,assets_value,assets_date) VALUES (1,150000.00,'2022-01-01'),(1,160000.00,'2022-04-01'),(2,220000.00,'2022-01-01'),(2,230000.00,'2022-04-01'); | SELECT client_id, SUM(assets_value) as total_assets_value FROM assets WHERE assets_date IN (SELECT LAST_DAY(date_add(DATE(assets_date), INTERVAL (quarter(assets_date) - 1) * 3 MONTH)) as last_day_of_quarter FROM assets GROUP BY client_id) GROUP BY client_id; |
What is the percentage of households in the state of California with an income greater than $100,000? | CREATE TABLE households (id INT,state TEXT,income INT); INSERT INTO households (id,state,income) VALUES (1,'California',75000),(2,'California',120000),(3,'California',50000); | SELECT 100.0 * COUNT(*) / (SELECT COUNT(*) FROM households WHERE state = 'California') as pct_households FROM households WHERE state = 'California' AND income > 100000; |
What is the average investment amount for the year 2019? | CREATE TABLE impact_investments (id INT,region VARCHAR(20),investment_year INT,investment_amount FLOAT); INSERT INTO impact_investments (id,region,investment_year,investment_amount) VALUES (1,'Asia',2020,150000),(2,'Africa',2019,120000),(3,'Asia',2020,180000); | SELECT AVG(investment_amount) FROM impact_investments WHERE investment_year = 2019; |
How many donors from Colombia and Argentina combined have made donations in the past month? | CREATE TABLE donors (donor_id INT,donor_name TEXT,donor_country TEXT); INSERT INTO donors (donor_id,donor_name,donor_country) VALUES (1,'John Doe','Colombia'),(2,'Jane Smith','USA'),(3,'Alice Johnson','Canada'),(4,'Carlos Alvarez','Argentina'),(5,'Elizabeth Brown','UK'); CREATE TABLE donations (donation_id INT,donor_id INT,donation_date TIMESTAMP); INSERT INTO donations (donation_id,donor_id,donation_date) VALUES (1,1,'2022-01-15 10:30:00'),(2,2,'2022-02-12 14:45:00'),(3,3,'2022-03-03 09:20:00'),(4,4,'2022-02-28 17:15:00'),(5,5,'2022-01-05 11:50:00'); | SELECT COUNT(DISTINCT donor_country) as total_donors FROM donors d JOIN donations ON d.donor_id = donations.donor_id WHERE d.donor_country IN ('Colombia', 'Argentina') AND donations.donation_date >= DATEADD(month, -1, CURRENT_TIMESTAMP); |
Which mines have more than 250 employees and are located in Canada or Australia? | CREATE TABLE labor_force (mine_name VARCHAR(255),employee_count INT,country VARCHAR(255)); INSERT INTO labor_force (mine_name,employee_count,country) VALUES ('Diamond Dunes',300,'Canada'),('Ruby Ridges',260,'Australia'); | SELECT mine_name FROM labor_force WHERE employee_count > 250 AND (country = 'Canada' OR country = 'Australia'); |
How many cricket fans are there who have attended a game in the last 2 years and are from India? | CREATE TABLE fans (id INT,name VARCHAR(50),country VARCHAR(50),last_game_date DATE); INSERT INTO fans (id,name,country,last_game_date) VALUES (1,'Rajesh Patel','India','2021-01-01'); INSERT INTO fans (id,name,country,last_game_date) VALUES (2,'Priya Sharma','Pakistan','2020-01-01'); | SELECT COUNT(*) FROM fans WHERE country = 'India' AND last_game_date >= DATEADD(year, -2, GETDATE()); |
Add a new initiative 'Ethical AI for small businesses' to the 'ai_ethics' table | CREATE TABLE ai_ethics (id INT PRIMARY KEY,region VARCHAR(50),initiative VARCHAR(100)); INSERT INTO ai_ethics (id,region,initiative) VALUES (1,'North America','Ethical AI education program for schools'),(2,'Europe','Ethical AI research center'); | INSERT INTO ai_ethics (id, region, initiative) VALUES (3, 'North America', 'Ethical AI for small businesses'); |
What is the minimum salary of employees in the 'manufacturing' or 'engineering' department? | CREATE TABLE salaries (id INT,name VARCHAR(50),department VARCHAR(50),salary INT); INSERT INTO salaries (id,name,department,salary) VALUES (1,'John Doe','manufacturing',45000); INSERT INTO salaries (id,name,department,salary) VALUES (2,'Jane Smith','engineering',60000); | SELECT MIN(salary) FROM salaries WHERE department IN ('manufacturing', 'engineering'); |
What is the distribution of incident dates in the IncidentResponse table by month? | CREATE TABLE IncidentResponse (region VARCHAR(50),incidentDate DATE); INSERT INTO IncidentResponse (region,incidentDate) VALUES ('EMEA','2022-01-05'),('APAC','2022-01-12'),('AMER','2022-01-20'); | SELECT YEAR(incidentDate), MONTH(incidentDate), COUNT(*) FROM IncidentResponse GROUP BY YEAR(incidentDate), MONTH(incidentDate); |
What is the population of dolphins in the Indian Ocean? | CREATE TABLE MarineLife (ID INT,Species VARCHAR(255),Population INT,Location VARCHAR(255)); INSERT INTO MarineLife (ID,Species,Population,Location) VALUES (2,'Dolphin',2000,'Indian Ocean'); | SELECT Population FROM MarineLife WHERE Species = 'Dolphin' AND Location = 'Indian Ocean'; |
What is the total quantity of sustainable materials used by companies located in the Asia-Pacific region? | CREATE TABLE Companies (id INT,name VARCHAR(255),region VARCHAR(255)); INSERT INTO Companies (id,name,region) VALUES (1,'CompanyA','Asia-Pacific'),(2,'CompanyB','Europe'),(3,'CompanyC','Asia-Pacific'); CREATE TABLE Materials (id INT,company_id INT,material VARCHAR(255),quantity INT); INSERT INTO Materials (id,company_id,material,quantity) VALUES (1,1,'Organic cotton',500),(2,1,'Recycled polyester',300),(3,2,'Organic linen',400),(4,3,'Organic cotton',600),(5,3,'Tencel',700); | SELECT SUM(quantity) FROM Companies JOIN Materials ON Companies.id = Materials.company_id WHERE region = 'Asia-Pacific' AND material IN ('Organic cotton', 'Recycled polyester', 'Tencel'); |
What is the average annual salary for employees in the 'Finance' department? | CREATE TABLE Employee (Employee_ID INT,Employee_Name VARCHAR(50),Department VARCHAR(50),Country VARCHAR(50),Annual_Salary DECIMAL(10,2)); INSERT INTO Employee (Employee_ID,Employee_Name,Department,Country,Annual_Salary) VALUES (1,'John Smith','IT','USA',80000.00),(2,'Jane Doe','HR','Canada',85000.00),(3,'Alberto Rodriguez','Finance','Mexico',95000.00),(4,'Sophia Lee','Finance','USA',100000.00); | SELECT AVG(Annual_Salary) FROM Employee WHERE Department = 'Finance'; |
What is the total Shariah-compliant finance income in Africa? | CREATE TABLE shariah_compliant_finance_incomes_africa (id INT,country VARCHAR(255),income DECIMAL(10,2)); INSERT INTO shariah_compliant_finance_incomes_africa (id,country,income) VALUES (1,'South Africa',25000.00),(2,'Egypt',35000.00),(3,'Nigeria',28000.00); | SELECT SUM(income) FROM shariah_compliant_finance_incomes_africa WHERE country IN ('South Africa', 'Egypt', 'Nigeria'); |
What is the maximum cost of a space mission by ESA? | CREATE TABLE missions (id INT,name TEXT,country TEXT,launch_date DATE,cost FLOAT); INSERT INTO missions (id,name,country,launch_date,cost) VALUES (1,'Ariane 5','Europe','2002-12-15',145000000),(2,'Vega','Europe','2012-02-13',29000000); | SELECT MAX(cost) FROM missions WHERE country = 'Europe'; |
What is the total quantity of recycled materials used in production in the US? | CREATE TABLE Production (ProductionID INT,Material VARCHAR(20),Quantity INT,Country VARCHAR(20)); INSERT INTO Production VALUES (1,'Recycled Plastic',500,'US'); INSERT INTO Production VALUES (2,'Recycled Metal',300,'US'); | SELECT SUM(Quantity) FROM Production WHERE Material LIKE '%Recycled%' AND Country = 'US'; |
What is the total cargo weight for each vessel type in the last year? | CREATE TABLE vessels (id INT,type VARCHAR(255)); CREATE TABLE cargo (id INT,vessel_id INT,weight INT,timestamp TIMESTAMP); INSERT INTO vessels VALUES (1,'Tanker'),(2,'Cargo Ship'); INSERT INTO cargo VALUES (1,1,10000,'2021-01-01 10:00:00'),(2,1,12000,'2021-01-15 12:00:00'),(3,2,15000,'2021-01-03 08:00:00'),(4,1,11000,'2021-01-16 10:00:00'); | SELECT v.type, SUM(c.weight) as total_weight FROM vessels v JOIN cargo c ON v.id = c.vessel_id WHERE c.timestamp >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 YEAR) GROUP BY v.type; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.