instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
Insert a new record in the 'water_conservation_goals' table with the following data: region = 'Southeast', goal = 5, year = 2023 | CREATE TABLE water_conservation_goals (region VARCHAR(50) PRIMARY KEY,goal INT,year INT); | INSERT INTO water_conservation_goals (region, goal, year) VALUES ('Southeast', 5, 2023); |
What is the total number of words spoken by non-binary characters in the 'Fantasy' genre in the last 3 years? | CREATE TABLE movies (id INT,title VARCHAR(50),genre VARCHAR(20));CREATE TABLE characters (id INT,movie_id INT,name VARCHAR(50),gender VARCHAR(20),lines_spoken INT); | SELECT genre, SUM(CASE WHEN gender = 'non-binary' THEN lines_spoken ELSE 0 END) AS total_non_binary_lines FROM movies m JOIN characters c ON m.id = c.movie_id WHERE m.genre = 'Fantasy' AND publish_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 3 YEAR) AND CURRENT_DATE GROUP BY genre; |
What is the maximum water depth in marine aquaculture facilities in the North Sea? | CREATE TABLE marine_aquaculture (id INT,name TEXT,region TEXT,water_depth INT); INSERT INTO marine_aquaculture (id,name,region,water_depth) VALUES (1,'Facility A','North Sea',50),(2,'Facility B','North Sea',60),(3,'Facility C','South China Sea',80); | SELECT MAX(water_depth) FROM marine_aquaculture WHERE region = 'North Sea'; |
Which countries have the highest average calorie intake per meal? | CREATE TABLE Countries (CountryID int,CountryName varchar(50)); CREATE TABLE Meals (MealID int,CountryID int,Calories int); INSERT INTO Countries VALUES (1,'USA'),(2,'Canada'),(3,'Mexico'); INSERT INTO Meals VALUES (1,1,1000),(2,1,1500),(3,2,800),(4,3,1200); | SELECT CountryName, AVG(Calories) as AvgCaloriesPerMeal FROM Meals m JOIN Countries c ON m.CountryID = c.CountryID GROUP BY CountryName ORDER BY AvgCaloriesPerMeal DESC; |
Which crops were planted in 'Berlin' and in which year? | CREATE TABLE crops (id INT PRIMARY KEY,name VARCHAR(50),yield INT,year INT,farmer_id INT,FOREIGN KEY (farmer_id) REFERENCES farmers(id)); INSERT INTO crops (id,name,yield,year,farmer_id) VALUES (3,'Wheat',120,2021,3); | SELECT c.name, c.year FROM crops c JOIN farmers f ON c.farmer_id = f.id WHERE f.location = 'Berlin'; |
What is the average age of female residents in 'CityData' table? | CREATE TABLE CityData (resident_id INT,age INT,gender VARCHAR(10)); | SELECT AVG(age) FROM CityData WHERE gender = 'Female'; |
What is the total duration (in hours) spent by visitors at the museum's digital exhibits? | CREATE TABLE Visitor_Interactions (ID INT,Visitor_ID INT,Start_Time TIMESTAMP,End_Time TIMESTAMP); INSERT INTO Visitor_Interactions (ID,Visitor_ID,Start_Time,End_Time) VALUES (1,1001,'2022-01-01 10:00:00','2022-01-01 12:00:00'),(2,1002,'2022-01-01 14:00:00','2022-01-01 15:00:00'),(3,1003,'2022-01-01 16:00:00','2022-01-01 18:00:00'); CREATE TABLE Exhibits (ID INT,Name VARCHAR(255),Type VARCHAR(255)); INSERT INTO Exhibits (ID,Name,Type) VALUES (1,'Digital Art Display','Digital'),(2,'Classic Art Exhibit','Physical'); | SELECT SUM(TIMESTAMPDIFF(HOUR, Start_Time, End_Time)) FROM Visitor_Interactions INNER JOIN Exhibits ON Visitor_Interactions.ID = Exhibits.ID WHERE Type = 'Digital'; |
What was the total revenue from users in India and Japan for the 'electronics' product category in Q1 2023? | CREATE TABLE products (product_id INT,product_name VARCHAR(255),category VARCHAR(255)); INSERT INTO products (product_id,product_name,category) VALUES (1,'Phone 1','electronics'),(2,'Laptop 1','electronics'); CREATE TABLE users (user_id INT,user_country VARCHAR(255)); INSERT INTO users (user_id,user_country) VALUES (1,'India'),(2,'Japan'); CREATE TABLE orders (order_id INT,user_id INT,product_id INT,order_date DATE,revenue DECIMAL(10,2)); INSERT INTO orders (order_id,user_id,product_id,order_date,revenue) VALUES (1,1,1,'2023-01-01',500),(2,2,1,'2023-01-05',600); | SELECT SUM(revenue) FROM orders o JOIN products p ON o.product_id = p.product_id JOIN users u ON o.user_id = u.user_id WHERE u.user_country IN ('India', 'Japan') AND p.category = 'electronics' AND o.order_date BETWEEN '2023-01-01' AND '2023-03-31'; |
What was the total weight of cannabis sold in the city of Los Angeles in the year 2020? | CREATE TABLE sales (id INT,city VARCHAR(50),year INT,weight INT); INSERT INTO sales (id,city,year,weight) VALUES (1,'Los Angeles',2020,70000); | SELECT SUM(weight) FROM sales WHERE city = 'Los Angeles' AND year = 2020; |
What is the average fare for public transportation in Melbourne? | CREATE TABLE public_transportation (trip_id INT,fare INT,trip_duration INT); INSERT INTO public_transportation (trip_id,fare,trip_duration) VALUES (1,5,30),(2,7,45),(3,9,60),(4,11,75); | SELECT AVG(fare) as avg_fare FROM public_transportation; |
How many fans are from each region in the fan_demographics table? | CREATE TABLE fan_demographics (fan_id INT,fan_name VARCHAR(50),region VARCHAR(50)); INSERT INTO fan_demographics (fan_id,fan_name,region) VALUES (1,'FanA','North America'),(2,'FanB','South America'),(3,'FanC','Asia'),(4,'FanD','Europe'); | SELECT region, COUNT(*) as num_fans FROM fan_demographics GROUP BY region; |
How many employees were hired in each month of 2021? | CREATE TABLE Employees (EmployeeID INT,Name VARCHAR(50),Department VARCHAR(50),Position VARCHAR(50),Salary FLOAT,HireDate DATE); INSERT INTO Employees (EmployeeID,Name,Department,Position,Salary,HireDate) VALUES (1,'John Doe','IT','Developer',75000.00,'2021-02-14'),(2,'Jane Smith','IT','Developer',80000.00,'2021-05-11'),(3,'Alice Johnson','Marketing','Marketing Specialist',60000.00,'2021-08-01'),(4,'Bob Brown','HR','HR Specialist',65000.00,'2021-11-15'); | SELECT DATE_FORMAT(HireDate, '%Y-%m') AS Month, COUNT(*) FROM Employees WHERE HireDate >= '2021-01-01' AND HireDate < '2022-01-01' GROUP BY Month; |
Delete all records related to the 'Accommodation' category in the 'disability_services' table. | CREATE TABLE disability_services (service_id INT,service_name TEXT,category TEXT); INSERT INTO disability_services (service_id,service_name,category) VALUES (1,'Wheelchair Ramp','Accommodation'); INSERT INTO disability_services (service_id,service_name,category) VALUES (2,'Sign Language Interpreter','Accommodation'); | DELETE FROM disability_services WHERE category = 'Accommodation'; |
What is the minimum cultural competency score of community health workers in each race? | CREATE TABLE CommunityHealthWorkers (WorkerID INT,Race VARCHAR(255),Score INT); INSERT INTO CommunityHealthWorkers (WorkerID,Race,Score) VALUES (1,'Hispanic',80),(2,'African American',85),(3,'Caucasian',90); | SELECT Race, MIN(Score) as MinScore FROM CommunityHealthWorkers GROUP BY Race; |
How many female employees are there in the sales department? | CREATE TABLE employees (id INT,name VARCHAR(50),gender VARCHAR(10),department VARCHAR(50)); INSERT INTO employees (id,name,gender,department) VALUES (1,'John Doe','Male','Sales'),(2,'Jane Smith','Female','Sales'),(3,'Alice Johnson','Female','Marketing'); | SELECT COUNT(*) FROM employees WHERE gender = 'Female' AND department = 'Sales'; |
What is the total number of customers and their total assets value for each investment strategy? | CREATE TABLE customers (id INT,name TEXT,age INT,country TEXT,assets FLOAT,investment_strategy TEXT); INSERT INTO customers (id,name,age,country,assets,investment_strategy) VALUES (1,'John Doe',45,'USA',250000.00,'Conservative'); INSERT INTO customers (id,name,age,country,assets,investment_strategy) VALUES (2,'Jane Smith',34,'Canada',320000.00,'Moderate'); INSERT INTO customers (id,name,age,country,assets,investment_strategy) VALUES (3,'Alice Johnson',29,'UK',450000.00,'Aggressive'); INSERT INTO customers (id,name,age,country,assets,investment_strategy) VALUES (4,'Bob Brown',51,'UK',150000.00,'Conservative'); INSERT INTO customers (id,name,age,country,assets,investment_strategy) VALUES (5,'Charlie Davis',48,'USA',800000.00,'Aggressive'); INSERT INTO customers (id,name,age,country,assets,investment_strategy) VALUES (6,'David Kim',38,'Singapore',520000.00,'Moderate'); | SELECT investment_strategy, COUNT(*), SUM(assets) FROM customers GROUP BY investment_strategy; |
Identify the number of offshore drilling platforms in the Gulf of Mexico and the North Sea. | CREATE TABLE drilling_platforms(location VARCHAR(255),platform_type VARCHAR(255),count INT);INSERT INTO drilling_platforms(location,platform_type,count) VALUES('Gulf of Mexico','Offshore',30),('North Sea','Offshore',25),('Baltic Sea','Offshore',10),('Gulf of Guinea','Onshore',15),('South China Sea','Offshore',20); | SELECT location, SUM(count) AS total_platforms FROM drilling_platforms WHERE platform_type = 'Offshore' AND location IN ('Gulf of Mexico', 'North Sea') GROUP BY location; |
What is the average salary of female workers in the manufacturing sector in Mexico? | CREATE TABLE manufacturing_sector (id INT,country VARCHAR(50),industry VARCHAR(50),worker_count INT,avg_salary DECIMAL(10,2),gender VARCHAR(10)); INSERT INTO manufacturing_sector (id,country,industry,worker_count,avg_salary,gender) VALUES (1,'Mexico','Manufacturing',500,80000,'Female'); INSERT INTO manufacturing_sector (id,country,industry,worker_count,avg_salary,gender) VALUES (2,'Mexico','Manufacturing',700,85000,'Male'); | SELECT AVG(ms.avg_salary) as avg_salary FROM manufacturing_sector ms WHERE ms.country = 'Mexico' AND ms.gender = 'Female'; |
How many patients were treated for 'Anxiety' or 'Depression' per quarter in 2019? | CREATE TABLE treatments (id INT,patient_id INT,condition VARCHAR(50),treatment_date DATE); INSERT INTO treatments (id,patient_id,condition,treatment_date) VALUES (1,1,'Depression','2019-03-05'); INSERT INTO treatments (id,patient_id,condition,treatment_date) VALUES (2,2,'Anxiety','2019-06-12'); INSERT INTO treatments (id,patient_id,condition,treatment_date) VALUES (3,3,'Depression','2019-09-25'); INSERT INTO treatments (id,patient_id,condition,treatment_date) VALUES (4,4,'Anxiety','2019-12-31'); | SELECT condition, COUNT(*) as count, DATE_FORMAT(treatment_date, '%Y-%m') as quarter FROM treatments WHERE condition IN ('Anxiety', 'Depression') AND YEAR(treatment_date) = 2019 GROUP BY quarter; |
How many cruelty-free makeup products were sold in the UK in 2021? | CREATE TABLE MakeupProducts(productId INT,productName VARCHAR(100),isCrueltyFree BOOLEAN,saleYear INT,country VARCHAR(50)); INSERT INTO MakeupProducts(productId,productName,isCrueltyFree,saleYear,country) VALUES (1,'Matte Lipstick',true,2021,'UK'),(2,'Liquid Eyeliner',false,2020,'UK'); | SELECT COUNT(*) FROM MakeupProducts WHERE isCrueltyFree = true AND saleYear = 2021 AND country = 'UK'; |
List the community health workers and their cultural competency scores. | CREATE TABLE community_health_workers (worker_id INT,name VARCHAR(50),cultural_competency_score INT); | SELECT worker_id, name, cultural_competency_score FROM community_health_workers; |
What is the average total area of protected forests in Indonesia? | CREATE TABLE forests (id INT,name TEXT,area REAL,country TEXT,category TEXT); INSERT INTO forests (id,name,area,country,category) VALUES (1,'Kerinci Seblat National Park',1379100.0,'Indonesia','protected'),(2,'Bukit Barisan Selatan National Park',356800.0,'Indonesia','protected'); | SELECT AVG(area) FROM forests WHERE country = 'Indonesia' AND category = 'protected'; |
List all technology initiatives focused on social good in Pacific Asian countries. | CREATE TABLE TechInitiatives (InitiativeID INT,InitiativeName TEXT,Country TEXT,Focus TEXT); INSERT INTO TechInitiatives (InitiativeID,InitiativeName,Country,Focus) VALUES (1,'Initiative A','Japan','Social Good'); INSERT INTO TechInitiatives (InitiativeID,InitiativeName,Country,Focus) VALUES (2,'Initiative B','South Korea','Healthcare'); INSERT INTO TechInitiatives (InitiativeID,InitiativeName,Country,Focus) VALUES (3,'Initiative C','Singapore','Social Good'); | SELECT InitiativeName, Country FROM TechInitiatives WHERE Country IN ('Japan', 'South Korea', 'Singapore') AND Focus = 'Social Good'; |
What is the maximum size of a sustainable urbanism project in the city of Berlin? | CREATE TABLE SustainableUrbanism (id INT,city VARCHAR(20),size FLOAT); | SELECT MAX(size) FROM SustainableUrbanism WHERE city = 'Berlin'; |
How many public hospitals are in New York? | CREATE TABLE regions (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255)); INSERT INTO regions (id,name,country) VALUES (1,'New York','USA'),(2,'Ontario','Canada'); CREATE TABLE hospitals (id INT PRIMARY KEY,name VARCHAR(255),region_id INT,type VARCHAR(255)); INSERT INTO hospitals (id,name,region_id,type) VALUES (1,'Hospital A',1,'Public'),(2,'Hospital B',1,'Private'); | SELECT COUNT(*) FROM hospitals WHERE type = 'Public' AND region_id IN (SELECT id FROM regions WHERE name = 'New York'); |
List donors who have not donated in the last 6 months | CREATE TABLE donors (id INT,last_donation DATE); INSERT INTO donors VALUES (1,'2021-06-01') | SELECT d.id, d.last_donation FROM donors d WHERE d.last_donation < DATE_SUB(CURDATE(), INTERVAL 6 MONTH); |
Determine the number of days between the "InstallationDate" and "InspectionDate" for each renewable energy project in the "ProjectData" table. | CREATE TABLE ProjectData (ProjectID INT,InstallationDate DATE,InspectionDate DATE); | SELECT ProjectID, InspectionDate - InstallationDate AS DaysBetweenDates FROM ProjectData; |
Which climate adaptation projects were completed in Africa in 2018? | CREATE TABLE Projects (Year INT,Region VARCHAR(20),Status VARCHAR(20),Type VARCHAR(20)); INSERT INTO Projects (Year,Region,Status,Type) VALUES (2018,'Africa','Completed','Climate Adaptation'); | SELECT * FROM Projects WHERE Year = 2018 AND Region = 'Africa' AND Type = 'Climate Adaptation' AND Status = 'Completed'; |
How many renewable energy projects have been implemented in the Africa region, excluding solar power plants, in the last 3 years? | CREATE TABLE RenewableEnergyProjects (id INT,region VARCHAR(20),project_type VARCHAR(20),project_start_date DATE); INSERT INTO RenewableEnergyProjects (id,region,project_type,project_start_date) VALUES (1,'Africa','Wind','2019-01-01'),(2,'Africa','Hydroelectric','2020-06-17'),(3,'Europe','Solar','2021-03-25'); | SELECT COUNT(*) FROM RenewableEnergyProjects WHERE region = 'Africa' AND project_type != 'Solar' AND project_start_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 YEAR); |
How many policy changes were made per quarter in 2021? | CREATE TABLE QuarterlyPolicy (Quarter TEXT,Year INTEGER,Change INTEGER); INSERT INTO QuarterlyPolicy (Quarter,Year,Change) VALUES ('Q1 2021',2021,12),('Q2 2021',2021,15),('Q3 2021',2021,10),('Q4 2021',2021,18); | SELECT Quarter, SUM(Change) FROM QuarterlyPolicy WHERE Year = 2021 GROUP BY Quarter; |
What was the average ticket price for concerts in a specific city? | CREATE TABLE Concerts (id INT,city VARCHAR(20),price FLOAT,tickets_sold INT); INSERT INTO Concerts (id,city,price,tickets_sold) VALUES (1,'Chicago',100.0,200),(2,'Chicago',120.0,150),(3,'New York',150.0,250); | SELECT AVG(price) FROM Concerts WHERE city = 'Chicago'; |
Which suppliers have not provided any materials to factory5 in the past year? | CREATE TABLE Suppliers (id INT,name TEXT,location TEXT);CREATE TABLE Materials (id INT,supplier_id INT,factory_id INT,material TEXT,quantity INT,date DATE);INSERT INTO Suppliers VALUES (1,'SupplierA','CityA'),(2,'SupplierB','CityB'),(3,'SupplierC','CityC');INSERT INTO Materials VALUES (1,1,5,'MaterialX',100,'2021-06-01'),(2,1,5,'MaterialY',200,'2021-07-15'),(3,2,5,'MaterialX',150,'2021-08-01'),(4,3,6,'MaterialZ',50,'2021-09-10'); | SELECT DISTINCT s.name FROM Suppliers s WHERE s.id NOT IN (SELECT m.supplier_id FROM Materials m WHERE m.factory_id = 5 AND m.date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) AND CURRENT_DATE); |
List the names of volunteers who have participated in both education and health programs in the same organization. | CREATE TABLE volunteers (id INT,name TEXT,organization_id INT); INSERT INTO volunteers (id,name,organization_id) VALUES (1,'John Doe',1),(2,'Jane Smith',1),(3,'Mike Johnson',2); | SELECT volunteers.name FROM volunteers JOIN (SELECT organization_id FROM grants WHERE initiative_type IN ('Education', 'Health') GROUP BY organization_id HAVING COUNT(DISTINCT initiative_type) = 2) AS grp_org ON volunteers.organization_id = grp_org.organization_id; |
What is the maximum depth of the ocean? | CREATE TABLE ocean_depth (location TEXT,depth INTEGER); | SELECT MAX(depth) FROM ocean_depth; |
What percentage of companies were founded by refugees in Sweden in 2019? | CREATE TABLE company (id INT,name TEXT,country TEXT,founding_date DATE,founder_refugee BOOLEAN); INSERT INTO company (id,name,country,founding_date,founder_refugee) VALUES (1,'Chi Corp','Sweden','2019-01-01',TRUE); INSERT INTO company (id,name,country,founding_date,founder_refugee) VALUES (2,'Psi Enterprises','Sweden','2018-01-01',FALSE); | SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM company WHERE founding_date >= '2019-01-01' AND country = 'Sweden')) FROM company WHERE founder_refugee = TRUE AND founding_date >= '2019-01-01' AND country = 'Sweden'; |
Which defense projects had a budget decrease in 2022 compared to 2021? | CREATE TABLE defense_projects_2 (project_name varchar(255),year int,budget int); INSERT INTO defense_projects_2 (project_name,year,budget) VALUES ('Project A',2021,5500000),('Project A',2022,5000000),('Project B',2021,7500000),('Project B',2022,7000000); | SELECT project_name FROM defense_projects_2 WHERE budget[(SELECT budget FROM defense_projects_2 WHERE project_name = defense_projects_2.project_name AND year = 2021)] > budget WHERE year = 2022; |
What is the average age of patients in community health center B? | CREATE TABLE community_health_center (name TEXT,patient_id INTEGER,age INTEGER); INSERT INTO community_health_center (name,patient_id,age) VALUES ('Community health center A',1,45),('Community health center A',2,50),('Community health center A',3,30),('Community health center A',4,60),('Community health center B',5,25),('Community health center B',6,45); | SELECT AVG(age) FROM community_health_center WHERE name = 'Community health center B' |
What is the total revenue generated from the sale of clothing products in Oceania? | CREATE TABLE revenue (region VARCHAR(10),product VARCHAR(20),revenue INT); INSERT INTO revenue (region,product,revenue) VALUES ('Oceania','shirt',10000),('Oceania','pants',12000); | SELECT SUM(revenue) FROM revenue WHERE region = 'Oceania'; |
List all suppliers providing ingredients for a vegan-only menu. | CREATE TABLE Ingredients (IngredientID INT,Name TEXT,IsVegan BOOLEAN,SupplierID INT); CREATE TABLE Suppliers (SupplierID INT,Name TEXT); | SELECT DISTINCT Suppliers.Name FROM Suppliers INNER JOIN Ingredients ON Suppliers.SupplierID = Ingredients.SupplierID WHERE IsVegan = TRUE; |
What is the average waiting time for public buses in Sydney, Australia during peak hours? | CREATE TABLE public_buses (bus_id INT,trip_id INT,trip_start_time TIMESTAMP,trip_end_time TIMESTAMP,start_location TEXT,end_location TEXT,city TEXT,avg_waiting_time DECIMAL,peak_hours TEXT); | SELECT AVG(avg_waiting_time) FROM public_buses WHERE city = 'Sydney' AND peak_hours = 'yes'; |
What are the policy numbers and claim dates for policyholders in Texas with claims exceeding $1000? | CREATE TABLE Claims (ClaimID INT,PolicyID INT,ClaimAmount DECIMAL(5,2),ClaimDate DATE); INSERT INTO Claims (ClaimID,PolicyID,ClaimAmount,ClaimDate) VALUES (1,1,500,'2020-01-01'); INSERT INTO Claims (ClaimID,PolicyID,ClaimAmount,ClaimDate) VALUES (2,1,750,'2020-02-01'); INSERT INTO Claims (ClaimID,PolicyID,ClaimAmount,ClaimDate) VALUES (3,2,400,'2020-03-01'); CREATE TABLE Policyholders (PolicyID INT,PolicyholderName VARCHAR(50),State VARCHAR(2)); INSERT INTO Policyholders (PolicyID,PolicyholderName,State) VALUES (1,'Juan Garcia','Texas'); INSERT INTO Policyholders (PolicyID,PolicyholderName,State) VALUES (2,'Thanh Nguyen','Texas'); | SELECT PolicyID, ClaimDate FROM Claims JOIN Policyholders ON Claims.PolicyID = Policyholders.PolicyID WHERE Policyholders.State = 'Texas' AND ClaimAmount > 1000; |
What is the total number of mental health parity violations by state and training level of community health workers? | CREATE TABLE mental_health_parity (state VARCHAR(255),violations INT); CREATE TABLE community_health_workers (state VARCHAR(255),training_level VARCHAR(255),workers INT); INSERT INTO mental_health_parity (state,violations) VALUES ('California',150),('New York',120),('Texas',180),('Florida',100); INSERT INTO community_health_workers (state,training_level,workers) VALUES ('California','Beginner',100),('California','Intermediate',200),('California','Advanced',300),('New York','Beginner',150),('New York','Intermediate',150),('New York','Advanced',200),('Texas','Beginner',200),('Texas','Intermediate',300),('Texas','Advanced',400),('Florida','Beginner',100),('Florida','Intermediate',200),('Florida','Advanced',300); | SELECT m.state, t.training_level, SUM(m.violations) FROM mental_health_parity m INNER JOIN community_health_workers t ON m.state = t.state GROUP BY m.state, t.training_level; |
Delete articles with less than 20 likes and published before 2022. | CREATE TABLE articles (id INT,title TEXT,category TEXT,likes INT,created_at DATETIME); INSERT INTO articles (id,title,category,likes,created_at) VALUES (1,'Climate crisis: 12 years to save the planet','climate change',100,'2022-01-01 10:30:00'); | DELETE FROM articles WHERE likes < 20 AND created_at < '2022-01-01 00:00:00'; |
Calculate the total donation amount and average donation per volunteer for the 'Food Support' program in 2021. | CREATE TABLE Donations (DonationID int,DonationDate date,DonationAmount int,Program varchar(50)); INSERT INTO Donations (DonationID,DonationDate,DonationAmount,Program) VALUES (1,'2021-01-01',100,'Food Support'),(2,'2021-01-10',200,'Food Support'); | SELECT AVG(DonationAmount) as AverageDonationPerVolunteer, SUM(DonationAmount) as TotalDonationAmount FROM Donations WHERE Program = 'Food Support' AND YEAR(DonationDate) = 2021; |
What was the total R&D expenditure for 'BioCure' in 'Asia' for 2021? | CREATE TABLE rd_expenditure (company TEXT,region TEXT,expenditure_year INT,expenditure_amount INT); INSERT INTO rd_expenditure (company,region,expenditure_year,expenditure_amount) VALUES ('BioCure','Asia',2021,20000); | SELECT SUM(expenditure_amount) FROM rd_expenditure WHERE company = 'BioCure' AND region = 'Asia' AND expenditure_year = 2021; |
What is the average wellbeing program participation rate by athlete? | CREATE TABLE athlete_participation (id INT,athlete VARCHAR(255),program VARCHAR(255),participation DECIMAL(5,2)); INSERT INTO athlete_participation (id,athlete,program,participation) VALUES (1,'John Doe','Yoga',0.75),(2,'Jane Doe','Meditation',0.85),(3,'John Doe','Pilates',0.65),(4,'Jane Doe','Yoga',0.95); | SELECT athlete, AVG(participation) as avg_participation FROM athlete_participation GROUP BY athlete; |
What is the total billing amount for each client? | CREATE TABLE clients (client_id INT,client_name VARCHAR(255)); INSERT INTO clients (client_id,client_name) VALUES (1,'Acme Inc'),(2,'Beta Corp'); CREATE TABLE billing (bill_id INT,client_id INT,amount DECIMAL(10,2)); INSERT INTO billing (bill_id,client_id,amount) VALUES (1,1,500.00),(2,1,250.00),(3,2,750.00); | SELECT c.client_name, SUM(b.amount) as total_billing FROM clients c INNER JOIN billing b ON c.client_id = b.client_id GROUP BY c.client_id, c.client_name; |
List the satellite images in the 'satellite_images' table that were taken in July 2021. | CREATE TABLE satellite_images (id INT,image_name VARCHAR(50),capture_date DATE); INSERT INTO satellite_images (id,image_name,capture_date) VALUES (1,'image1','2021-07-01'),(2,'image2','2021-08-01'); | SELECT * FROM satellite_images WHERE MONTH(capture_date) = 7 AND YEAR(capture_date) = 2021; |
List explainable AI algorithms that have been used in the last month. | CREATE TABLE explainable_ai (transaction_id INT,algorithm_name VARCHAR(255),transaction_date DATE); INSERT INTO explainable_ai (transaction_id,algorithm_name,transaction_date) VALUES (1,'SHAP','2022-01-01'),(2,'LIME','2022-01-05'),(3,'SHAP','2022-01-10'); | SELECT algorithm_name FROM explainable_ai WHERE transaction_date >= DATEADD(month, -1, GETDATE()); |
What is the retention rate of volunteers who signed up in the last 6 months? | CREATE TABLE Volunteers (VolunteerID INT,SignUpDate DATE,IsActive BOOLEAN); INSERT INTO Volunteers (VolunteerID,SignUpDate,IsActive) VALUES (1,'2022-01-15',true),(2,'2022-02-20',false),(3,'2022-03-05',true); | SELECT COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Volunteers WHERE SignUpDate >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '6 months') AND IsActive) as RetentionRate FROM Volunteers WHERE SignUpDate < DATE_TRUNC('month', CURRENT_DATE - INTERVAL '6 months') AND IsActive; |
How many polar bear sightings have been recorded in each park in the last 5 years? | CREATE TABLE park_data (park VARCHAR(255),year INT,polar_bear_sightings INT); CREATE TABLE park_information (park VARCHAR(255),size FLOAT,location VARCHAR(255)); | SELECT park, COUNT(polar_bear_sightings) OVER (PARTITION BY park) FROM park_data WHERE year BETWEEN 2018 AND 2022; |
What is the minimum number of successful lunar landings by any space agency, and which agency achieved this milestone first? | CREATE TABLE lunar_landings(id INT,agency VARCHAR(255),mission_name VARCHAR(255),launch_date DATE,landing_date DATE,mission_status VARCHAR(255)); | SELECT agency, MIN(mission_status = 'successful') as first_successful_mission FROM lunar_landings GROUP BY agency; |
List all marine species that inhabit more than one oceanographic station. | CREATE TABLE marine_species (id INT,name VARCHAR(255)); CREATE TABLE oceanography_stations (id INT,station_name VARCHAR(255),species_id INT); INSERT INTO marine_species (id,name) VALUES (1,'Clownfish'),(2,'Blue Whale'); INSERT INTO oceanography_stations (id,station_name,species_id) VALUES (1,'Station A',1),(2,'Station B',1),(3,'Station A',2); | SELECT marine_species.name FROM marine_species INNER JOIN oceanography_stations ON marine_species.id = oceanography_stations.species_id GROUP BY marine_species.name HAVING COUNT(DISTINCT oceanography_stations.station_name) > 1; |
What is the total waste produced by each production line in April 2021? | CREATE TABLE ProductionWaste (ID INT,LineID INT,WasteDate DATE,WasteQuantity INT); INSERT INTO ProductionWaste (ID,LineID,WasteDate,WasteQuantity) VALUES (1,100,'2021-04-03',25),(2,101,'2021-04-15',35),(3,102,'2021-04-28',45); | SELECT LineID, SUM(WasteQuantity) as TotalWaste FROM ProductionWaste WHERE WasteDate >= '2021-04-01' AND WasteDate < '2021-05-01' GROUP BY LineID; |
Get the number of public libraries in each city in Texas | CREATE TABLE public_libraries (library_id INT,name VARCHAR(255),location VARCHAR(255),city VARCHAR(255),state VARCHAR(255),zip INT); INSERT INTO public_libraries (library_id,name,location,city,state,zip) VALUES (1,'Houston Public Library','500 McKinney','Houston','Texas',77002); INSERT INTO public_libraries (library_id,name,location,city,state,zip) VALUES (2,'Austin Public Library','710 W Cesar Chavez St','Austin','Texas',78701); | SELECT city, COUNT(*) FROM public_libraries WHERE state = 'Texas' GROUP BY city; |
What is the total sales revenue for each sales representative's territory, ordered by highest revenue first, for the year 2020?' | CREATE TABLE sales_representatives (rep_id INT,rep_name TEXT,territory TEXT); INSERT INTO sales_representatives (rep_id,rep_name,territory) VALUES (1,'John Smith','Northeast'),(2,'Jane Doe','Southeast'); CREATE TABLE sales_data (rep_id INT,sale_date DATE,revenue INT); INSERT INTO sales_data (rep_id,sale_date,revenue) VALUES (1,'2020-01-01',5000),(1,'2020-01-15',7000),(2,'2020-02-01',6000),(2,'2020-03-15',8000); | SELECT rep_name, SUM(revenue) AS total_sales FROM sales_data JOIN sales_representatives ON sales_data.rep_id = sales_representatives.rep_id WHERE sale_date BETWEEN '2020-01-01' AND '2020-12-31' GROUP BY rep_name ORDER BY total_sales DESC; |
What is the average age of patients with hypertension in Appalachian rural areas? | CREATE TABLE patients (id INT,age INT,has_hypertension BOOLEAN); INSERT INTO patients (id,age,has_hypertension) VALUES (1,60,true),(2,45,false); CREATE TABLE locations (id INT,region VARCHAR,is_rural BOOLEAN); INSERT INTO locations (id,region,is_rural) VALUES (1,'Appalachia',true),(2,'California',false); | SELECT AVG(patients.age) FROM patients INNER JOIN locations ON patients.id = locations.id WHERE patients.has_hypertension = true AND locations.is_rural = true; |
Update the loan amount for ABC Microfinance in Latin America to $6500.00 | CREATE SCHEMA if not exists finance;CREATE TABLE if not exists loans (id INT PRIMARY KEY,institution_name TEXT,region TEXT,amount DECIMAL(10,2)); INSERT INTO loans (id,institution_name,region,amount) VALUES (1,'ABC Microfinance','Latin America',5000.00); | UPDATE finance.loans SET amount = 6500.00 WHERE institution_name = 'ABC Microfinance' AND region = 'Latin America'; |
What is the average network investment for the telecom provider in all regions? | CREATE TABLE network_investments (investment FLOAT,region VARCHAR(20)); INSERT INTO network_investments (investment,region) VALUES (120000,'Western'),(150000,'Northern'),(180000,'Western'),(200000,'Northern'),(250000,'Eastern'); | SELECT AVG(investment) FROM network_investments; |
Which countries have the lowest percentage of textile waste sent to landfills and their corresponding waste management strategies? | CREATE TABLE waste_management (country VARCHAR(50),textile_waste_percentage FLOAT,waste_management_strategy VARCHAR(50)); INSERT INTO waste_management (country,textile_waste_percentage,waste_management_strategy) VALUES ('Germany',0.15,'Extensive Recycling Programs'),('France',0.18,'Ban on Textile Waste Incineration'),('Austria',0.20,'Waste Reduction Campaigns'),('Belgium',0.22,'Waste Sorting and Recycling'),('Netherlands',0.25,'Textile Waste Composting'); | SELECT country, waste_management_strategy FROM waste_management WHERE textile_waste_percentage <= 0.22 ORDER BY textile_waste_percentage ASC LIMIT 3; |
How many professional development courses did each teacher complete in the last 3 years? | CREATE TABLE teacher_pd (teacher_id INT,course_id INT,completion_date DATE); INSERT INTO teacher_pd (teacher_id,course_id,completion_date) VALUES (1,1001,'2020-01-01'),(1,1002,'2020-06-01'),(2,1001,'2019-12-31'),(3,1003,'2021-03-15'); | SELECT teacher_id, COUNT(*) FROM teacher_pd WHERE completion_date >= DATE_SUB(CURDATE(), INTERVAL 3 YEAR) GROUP BY teacher_id; |
Delete all transactions related to digital asset 'ABC' in the year 2022 | CREATE TABLE transactions (id INT,digital_asset VARCHAR(10),transaction_date DATE,amount DECIMAL(10,2)); INSERT INTO transactions (id,digital_asset,transaction_date,amount) VALUES (1,'ABC','2022-01-01',100.00),(2,'DEF','2022-02-01',200.00); | DELETE FROM transactions WHERE digital_asset = 'ABC' AND YEAR(transaction_date) = 2022; |
What is the most common nationality of tourists visiting the Great Wall of China? | CREATE TABLE great_wall_visitors (id INT,name VARCHAR(50),nationality VARCHAR(50)); INSERT INTO great_wall_visitors (id,name,nationality) VALUES (1,'John Smith','British'),(2,'Li Xiang','Chinese'),(3,'Sophia Lee','British'); | SELECT nationality, COUNT(*) AS count FROM great_wall_visitors GROUP BY nationality ORDER BY count DESC LIMIT 1; |
Display the total number of hours played by all players, separated by game | CREATE TABLE games (game_id INT,name VARCHAR(255)); CREATE TABLE players (player_id INT,name VARCHAR(255)); CREATE TABLE player_games (player_id INT,game_id INT,hours_played INT); | SELECT games.name, SUM(player_games.hours_played) as total_hours_played FROM games JOIN player_games ON games.game_id = player_games.game_id GROUP BY games.name; |
Which countries have the highest average grant amount? | CREATE TABLE if NOT EXISTS countries (country_code VARCHAR(3),country_name VARCHAR(50),avg_grant_amount DECIMAL(10,2)); INSERT INTO countries (country_code,country_name,avg_grant_amount) VALUES ('USA','United States',150000.00),('CAN','Canada',120000.00); | SELECT country_name, AVG(grant_amount) as avg_grant_amount FROM grants INNER JOIN countries ON grants.country_code = countries.country_code GROUP BY country_name ORDER BY avg_grant_amount DESC LIMIT 1; |
How many new mining sites were added in Africa in the past year? | CREATE TABLE mining_sites (id INT,name VARCHAR(50),location VARCHAR(50),added_date DATE,PRIMARY KEY (id)); INSERT INTO mining_sites (id,name,location,added_date) VALUES (1,'Diamond Mine','South Africa','2020-01-15'); INSERT INTO mining_sites (id,name,location,added_date) VALUES (2,'Gold Mine','Ghana','2021-02-20'); INSERT INTO mining_sites (id,name,location,added_date) VALUES (3,'Coal Mine','Mozambique','2022-03-05'); | SELECT COUNT(*) FROM mining_sites WHERE added_date >= DATEADD(year, -1, GETDATE()) AND location LIKE 'Africa%'; |
What is the average monthly donation amount per donor, for the last year, excluding donors with only one donation? | CREATE TABLE donations (donor_id INT,donation_date DATE,donation_amount DECIMAL(10,2)); INSERT INTO donations (donor_id,donation_date,donation_amount) VALUES (1,'2022-01-01',500.00),(1,'2022-02-01',300.00),(2,'2022-03-01',700.00),(3,'2022-04-01',200.00); | SELECT AVG(donation_amount) as avg_monthly_donation_amount FROM (SELECT donor_id, YEAR(donation_date) as donation_year, MONTH(donation_date) as donation_month, AVG(donation_amount) as donation_amount FROM donations WHERE donation_date >= DATEADD(year, -1, GETDATE()) GROUP BY donor_id, YEAR(donation_date), MONTH(donation_date) HAVING COUNT(*) > 1) t GROUP BY donation_year, donation_month; |
List all ports where the company has operated and their first visit date. | CREATE TABLE ports (id INT,name VARCHAR(50),country VARCHAR(50)); CREATE TABLE visits (ship_id INT,port_id INT,visit_date DATE); INSERT INTO ports (id,name,country) VALUES (1,'Los Angeles','USA'),(2,'Singapore','Singapore'),(3,'Rotterdam','Netherlands'); INSERT INTO visits (ship_id,port_id,visit_date) VALUES (1,1,'2020-01-01'),(1,2,'2020-02-01'),(2,3,'2019-01-15'),(3,1,'2020-03-01'); | SELECT ports.name, MIN(visits.visit_date) FROM ports INNER JOIN visits ON ports.id = visits.port_id GROUP BY ports.name; |
Create a view to show the number of teachers attending each workshop | CREATE TABLE teacher_workshops (id INT PRIMARY KEY,workshop_name TEXT,workshop_date DATE,location TEXT,max_attendees INT); | CREATE VIEW workshop_attendance AS SELECT workshop_name, COUNT(attendee_id) as num_attendees FROM teacher_workshops JOIN teacher_attendance ON teacher_workshops.id = teacher_attendance.workshop_id GROUP BY workshop_name; |
List all social equity programs and their respective dispensary counts across the US. | CREATE TABLE Dispensaries (id INT,name TEXT,state TEXT,social_equity_program TEXT); INSERT INTO Dispensaries (id,name,state,social_equity_program) VALUES (1,'Green Leaf','California','SEP1'),(2,'Buds R Us','California','SEP2'),(3,'Happy High','Colorado','SEP3'),(4,'Cannabis Corner','Colorado','SEP4'),(5,'Elevated Elements','New York','SEP5'); | SELECT social_equity_program, COUNT(DISTINCT state) as dispensary_count FROM Dispensaries GROUP BY social_equity_program; |
What is the maximum salary of employees who identify as LGBTQ+? | CREATE TABLE Employees (EmployeeID INT,LGBTQ VARCHAR(10),Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID,LGBTQ,Salary) VALUES (7,'Yes',90000.00); | SELECT MAX(Salary) FROM Employees WHERE LGBTQ = 'Yes'; |
What is the number of hospitals and the population in each city in the state of New York? | CREATE TABLE cities (city_name VARCHAR(255),population INT,state_abbreviation VARCHAR(255)); INSERT INTO cities (city_name,population,state_abbreviation) VALUES ('CityA',1500000,'NY'),('CityB',800000,'NY'),('CityC',2500000,'NY'); CREATE TABLE hospitals (hospital_name VARCHAR(255),city_name VARCHAR(255)); INSERT INTO hospitals (hospital_name,city_name) VALUES ('HospitalX','CityA'),('HospitalY','CityA'),('HospitalZ','CityB'); | SELECT c.city_name, COUNT(h.hospital_name) AS num_hospitals, c.population FROM cities c LEFT JOIN hospitals h ON c.city_name = h.city_name GROUP BY c.city_name; |
Count the number of female and male employees in each department | CREATE TABLE Departments (department_id INT,department_name VARCHAR(50),manufacturer_id INT); INSERT INTO Departments (department_id,department_name,manufacturer_id) VALUES (1,'Ethical Manufacturing',1),(2,'Circular Economy',2),(3,'Workforce Development',3); CREATE TABLE Employees (employee_id INT,employee_name VARCHAR(50),department_id INT,gender VARCHAR(10)); INSERT INTO Employees (employee_id,employee_name,department_id,gender) VALUES (1,'Employee1',1,'Female'),(2,'Employee2',1,'Male'),(3,'Employee3',2,'Female'),(4,'Employee4',3,'Non-binary'); | SELECT d.department_name, e.gender, COUNT(e.employee_id) AS num_employees FROM Departments d INNER JOIN Employees e ON d.department_id = e.department_id GROUP BY d.department_name, e.gender; |
Find the number of electric vehicles by manufacturer | CREATE TABLE Manufacturers (ManufacturerID INT,ManufacturerName VARCHAR(50)); INSERT INTO Manufacturers (ManufacturerID,ManufacturerName) VALUES (1,'Tesla'),(2,'Nissan'),(3,'BMW'); CREATE TABLE Vehicles (VehicleID INT,ManufacturerID INT,VehicleType VARCHAR(50),Electric BOOLEAN); INSERT INTO Vehicles (VehicleID,ManufacturerID,VehicleType,Electric) VALUES (1,1,'Model S',true),(2,1,'Model 3',true),(3,2,'Leaf',true),(4,2,'Versa',false),(5,3,'i3',true),(6,3,'X5',false); | SELECT ManufacturerName, COUNT(*) as Total FROM Manufacturers m JOIN Vehicles v ON m.ManufacturerID = v.ManufacturerID WHERE Electric = true GROUP BY ManufacturerName; |
Find the average number of points scored by each team in the NBA during the 2021-2022 regular season. | CREATE TABLE nba_games (id INT,season INT,category VARCHAR(50),home_team VARCHAR(50),away_team VARCHAR(50),points_home INT,points_away INT); | SELECT home_team, AVG(points_home) as avg_points FROM nba_games WHERE season = 2021 AND category = 'regular' GROUP BY home_team; SELECT away_team, AVG(points_away) as avg_points FROM nba_games WHERE season = 2021 AND category = 'regular' GROUP BY away_team; |
What is the average property price in sustainable communities? | CREATE TABLE Properties (id INT,price INT,sustainable BOOLEAN); INSERT INTO Properties (id,price,sustainable) VALUES (1,600000,TRUE),(2,500000,FALSE),(3,800000,TRUE),(4,700000,FALSE); | SELECT AVG(price) AS avg_price_sustainable FROM Properties WHERE sustainable = TRUE; |
Who are the top 3 artists by total plays in a genre? | CREATE TABLE Artists (artist_id INT,artist_name VARCHAR(255)); INSERT INTO Artists (artist_id,artist_name) VALUES (1,'Artist1'),(2,'Artist2'),(3,'Artist3'); CREATE TABLE Genres (genre_id INT,genre_name VARCHAR(255)); INSERT INTO Genres (genre_id,genre_name) VALUES (1,'Pop'),(2,'Rock'); CREATE TABLE Plays (play_id INT,song_id INT,artist_id INT,genre_id INT); INSERT INTO Plays (play_id,song_id,artist_id,genre_id) VALUES (1,1,1,1),(2,2,1,1),(3,3,2,2); | SELECT a.artist_name, g.genre_name, SUM(p.plays) AS total_plays FROM Artists a JOIN Plays p ON a.artist_id = p.artist_id JOIN Songs s ON p.song_id = s.song_id JOIN Albums al ON s.album_id = al.album_id JOIN Genres g ON al.genre_id = g.genre_id GROUP BY a.artist_name, g.genre_name ORDER BY total_plays DESC LIMIT 3; |
What is the total quantity of products sold in the month of May in 2021 and 2022? | CREATE TABLE sales (product_id VARCHAR(255),sale_date DATE,quantity INT); INSERT INTO sales (product_id,sale_date,quantity) VALUES ('A','2021-05-01',5),('A','2021-05-02',3),('B','2021-05-01',7),('C','2022-05-01',10); | SELECT SUM(quantity) FROM sales WHERE MONTH(sale_date) = 5 AND (YEAR(sale_date) = 2021 OR YEAR(sale_date) = 2022); |
Create a table named 'water_conservation' | CREATE TABLE water_conservation (id INT PRIMARY KEY,location VARCHAR(50),water_savings FLOAT); | CREATE TABLE water_conservation (id INT PRIMARY KEY, location VARCHAR(50), water_savings FLOAT); |
What is the total number of public works projects in 'PublicWorks' table with a budget over 500000? | CREATE TABLE PublicWorks(project_id INT,budget INT,location VARCHAR(255)); INSERT INTO PublicWorks VALUES(1,600000,'CityA'),(2,400000,'CityB'),(3,700000,'CityC'),(4,300000,'CityD'),(5,800000,'CityE'),(6,250000,'CityF'); | SELECT COUNT(*) FROM PublicWorks WHERE budget > 500000; |
What is the total number of military bases in Oceania? | CREATE TABLE military_bases(base_id INT,country VARCHAR(255),region VARCHAR(255)); INSERT INTO military_bases(base_id,country,region) VALUES (1,'Australia','Oceania'),(2,'New Zealand','Oceania'),(3,'Papua New Guinea','Oceania'),(4,'Fiji','Oceania'),(5,'United States','Oceania'),(6,'France','Oceania'),(7,'United Kingdom','Oceania'); | SELECT COUNT(*) FROM military_bases WHERE region = 'Oceania'; |
How many polar bear sightings are in each Arctic region per year? | CREATE TABLE polar_bear_sightings (sighting_date DATE,region VARCHAR(50)); INSERT INTO polar_bear_sightings (sighting_date,region) VALUES ('2010-01-01','Arctic North America'),('2010-01-05','Arctic Europe'); | SELECT e.region, EXTRACT(YEAR FROM e.sighting_date) as year, COUNT(e.sighting_date) as sighting_count FROM polar_bear_sightings e GROUP BY e.region, e.sighting_date; |
How many users from the USA in the "social_media_users" table liked at least 5 posts with the hashtag "#nature" in the "user_activity" table? | CREATE TABLE social_media_users (id INT,country VARCHAR(2)); INSERT INTO social_media_users (id,country) VALUES (1,'USA'),(2,'Canada'); CREATE TABLE user_activity (user_id INT,post_id INT,likes INT,hashtags VARCHAR(255)); INSERT INTO user_activity (user_id,post_id,likes,hashtags) VALUES (1,1,10,'#nature'),(1,2,5,'#nature'),(1,3,8,'#travel'),(2,4,3,'#nature'); | SELECT COUNT(DISTINCT su.id) FROM social_media_users su JOIN user_activity ua ON su.id = ua.user_id WHERE su.country = 'USA' AND ua.hashtags LIKE '%#nature%' GROUP BY su.id HAVING COUNT(ua.likes) >= 5; |
What is the average mental health score for students in each subject, ranked by score? | CREATE TABLE student_mental_health (student_id INT,mental_health_score INT,subject VARCHAR(255)); INSERT INTO student_mental_health (student_id,mental_health_score,subject) VALUES (1,80,'Mathematics'),(2,90,'Computer Science'),(3,70,'Computer Science'),(4,85,'English'); | SELECT subject, AVG(mental_health_score) as avg_score, RANK() OVER (ORDER BY AVG(mental_health_score) DESC) as rank FROM student_mental_health GROUP BY subject ORDER BY rank; |
Create a view to display top 3 crime types by count | CREATE TABLE crime_statistics (crime_type VARCHAR(255),count INT,location VARCHAR(255)); | CREATE VIEW top_3_crime_types AS SELECT crime_type, count FROM crime_statistics GROUP BY crime_type ORDER BY count DESC LIMIT 3; |
Show the total number of safety tests performed for each brand | CREATE TABLE safety_tests (id INT PRIMARY KEY,company VARCHAR(255),brand VARCHAR(255),test_location VARCHAR(255),test_date DATE,safety_rating INT); | SELECT brand, COUNT(*) as total_tests FROM safety_tests GROUP BY brand; |
List all the users who have clicked on ads related to "vegan diet" in the past 3 months, along with their demographic info and the number of times they clicked on the ad. | CREATE TABLE users (user_id INT,first_name VARCHAR(50),last_name VARCHAR(50),age INT,gender VARCHAR(10),country VARCHAR(50));CREATE TABLE ad_activity (activity_id INT,user_id INT,ad_id INT,activity_type VARCHAR(50),activity_date DATE);CREATE TABLE ads (ad_id INT,ad_name VARCHAR(255),ad_category VARCHAR(255)); | SELECT u.first_name, u.last_name, u.age, u.gender, u.country, COUNT(a.activity_id) as clicks FROM users u JOIN ad_activity a ON u.user_id = a.user_id JOIN ads ad ON a.ad_id = ad.ad_id WHERE ad.ad_name LIKE '%vegan diet%' AND a.activity_date >= (CURRENT_DATE - INTERVAL 3 MONTH) AND a.activity_type = 'click' GROUP BY u.user_id; |
How many virtual tours were conducted in Asia in the last month? | CREATE TABLE virtual_tours (tour_id INT,hotel_id INT,country TEXT,date DATE); INSERT INTO virtual_tours (tour_id,hotel_id,country,date) VALUES (1,1,'India','2022-03-05'),(2,2,'Japan','2022-03-10'),(3,3,'China','2022-03-15'); | SELECT COUNT(*) FROM virtual_tours WHERE country IN ('India', 'Japan', 'China') AND date >= DATEADD(day, -30, GETDATE()); |
What is the total amount of climate finance spent on renewable energy sources in South America and North America? | CREATE TABLE renewable_energy (country VARCHAR(50),source VARCHAR(50),amount NUMERIC(12,2)); INSERT INTO renewable_energy (country,source,amount) VALUES ('Argentina','Wind',500.50),('Argentina','Solar',700.20),('Brazil','Wind',800.00),('Brazil','Solar',1000.00),('Canada','Wind',1200.00),('Canada','Solar',1500.00),('USA','Wind',1800.00),('USA','Solar',2000.00); | SELECT SUM(amount) FROM renewable_energy WHERE country IN ('South America', 'North America') AND source IN ('Wind', 'Solar'); |
What is the maximum dissolved oxygen level for each species, grouped by species, from the 'fish_stock' and 'ocean_health' tables? | CREATE TABLE fish_stock (species VARCHAR(255),dissolved_oxygen FLOAT); CREATE TABLE ocean_health (species VARCHAR(255),dissolved_oxygen FLOAT); INSERT INTO fish_stock (species,dissolved_oxygen) VALUES ('Tilapia',6.5),('Salmon',7.1); INSERT INTO ocean_health (species,dissolved_oxygen) VALUES ('Tilapia',6.8),('Salmon',7.4); | SELECT f.species, MAX(f.dissolved_oxygen) FROM fish_stock f INNER JOIN ocean_health o ON f.species = o.species GROUP BY f.species; |
What is the average calorie count for organic items in the FOOD_ITEMS table? | CREATE TABLE FOOD_ITEMS (id INT,name VARCHAR(50),category VARCHAR(50),is_organic BOOLEAN,avg_calories FLOAT); INSERT INTO FOOD_ITEMS (id,name,category,is_organic,avg_calories) VALUES (1,'Apple','Fruit',true,95),(2,'Broccoli','Vegetable',true,55); | SELECT AVG(avg_calories) FROM FOOD_ITEMS WHERE is_organic = true AND category = 'Fruit'; |
What is the total population of all animals in the wetlands habitat? | CREATE TABLE animals (id INT,name VARCHAR(50),species VARCHAR(50),population INT,habitat VARCHAR(50)); INSERT INTO animals (id,name,species,population,habitat) VALUES (5,'Frog','Amphibian',150,'Wetlands'); INSERT INTO animals (id,name,species,population,habitat) VALUES (6,'Duck','Bird',75,'Wetlands'); | SELECT SUM(population) FROM animals WHERE habitat = 'Wetlands'; |
List the renewable energy power plants and their capacities (MW) in New York | CREATE TABLE power_plants (id INT,state VARCHAR(50),type VARCHAR(50),capacity FLOAT); INSERT INTO power_plants (id,state,type,capacity) VALUES (1,'New York','Solar',500),(2,'New York','Wind',700),(3,'California','Solar',800); | SELECT type, capacity FROM power_plants WHERE state = 'New York'; |
Who are the top 5 donors in Canada? | CREATE TABLE donors (id INT,donor_name TEXT,country TEXT); CREATE TABLE donations (id INT,donor_id INT,donation_amount DECIMAL(10,2)); INSERT INTO donors (id,donor_name,country) VALUES (1,'John Doe','CA'),(2,'Jane Smith','CA'),(3,'Mary Johnson','US'); INSERT INTO donations (id,donor_id,donation_amount) VALUES (1,1,50.00),(2,2,100.00),(3,1,150.00); | SELECT donor_name, SUM(donation_amount) as total_donation FROM donations JOIN donors ON donations.donor_id = donors.id WHERE country = 'CA' GROUP BY donor_name ORDER BY total_donation DESC LIMIT 5; |
What is the average age of employees in each position in the 'mining_operations' table? | CREATE TABLE mining_operations (employee_id INT,first_name VARCHAR(50),last_name VARCHAR(50),position VARCHAR(50),age INT,country VARCHAR(50)); INSERT INTO mining_operations (employee_id,first_name,last_name,position,age,country) VALUES (1,'John','Doe','Engineer',35,'USA'); INSERT INTO mining_operations (employee_id,first_name,last_name,position,age,country) VALUES (2,'Jane','Smith','Supervisor',42,'Canada'); INSERT INTO mining_operations (employee_id,first_name,last_name,position,age,country) VALUES (7,'Eva','Green','Engineer',32,'France'); | SELECT position, AVG(age) FROM mining_operations GROUP BY position; |
How many eyeshadows have been sold in Canada in the past year? | CREATE TABLE SalesByDate (product VARCHAR(255),country VARCHAR(255),date DATE,quantity INT); | SELECT COUNT(*) FROM SalesByDate WHERE product = 'Eyeshadow' AND country = 'Canada' AND date >= DATEADD(year, -1, GETDATE()); |
What is the name of the community development initiative with the least number of participants in the 'community_development' table?; | CREATE TABLE community_development (id INT,initiative_name VARCHAR(50),number_of_participants INT); INSERT INTO community_development VALUES (1,'Youth Skills Training',100),(2,'Women Empowerment',120),(3,'Elderly Care',80),(4,'Environmental Conservation',150),(5,'Cultural Preservation',110); | SELECT initiative_name FROM community_development WHERE number_of_participants = (SELECT MIN(number_of_participants) FROM community_development); |
What is the total number of 'returns' in the 'reverse_logistics' table? | CREATE TABLE reverse_logistics (return_id INT,return_reason VARCHAR(50),return_quantity INT); INSERT INTO reverse_logistics (return_id,return_reason,return_quantity) VALUES (1,'Damaged',50),(2,'Wrong Item',75),(3,'Return to Stock',100); | SELECT SUM(return_quantity) FROM reverse_logistics WHERE return_reason = 'Return to Stock'; |
How many community development initiatives were completed in 2020 and 2021 in the 'rural_development' database? | CREATE TABLE community_initiative (initiative_id INT,initiative_name VARCHAR(50),year INT,completed BOOLEAN); INSERT INTO community_initiative (initiative_id,initiative_name,year,completed) VALUES (1,'Community Health Center',2020,true); | SELECT COUNT(*) FROM community_initiative WHERE year IN (2020, 2021) AND completed = true; |
Which materials had a lower recycling rate in 2020 compared to 2018? | CREATE TABLE recycling_rates(year INT,material VARCHAR(255),recycling_rate DECIMAL(5,2)); INSERT INTO recycling_rates VALUES (2018,'Paper',0.45),(2018,'Plastic',0.20),(2018,'Glass',0.35),(2019,'Paper',0.47),(2019,'Plastic',0.21),(2019,'Glass',0.36),(2020,'Paper',0.50),(2020,'Plastic',0.23),(2020,'Glass',0.38); | SELECT material, (r20.recycling_rate - r18.recycling_rate) AS difference FROM recycling_rates r20 JOIN recycling_rates r18 ON r20.material = r18.material WHERE r20.year = 2020 AND r18.year = 2018 AND r20.recycling_rate < r18.recycling_rate; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.