instruction stringlengths 0 1.06k | input stringlengths 11 5.3k | response stringlengths 2 4.44k |
|---|---|---|
What are the top 5 destinations with the most positive impact on sustainable tourism? | CREATE TABLE sustainable_practices (practice_id INT,practice_name VARCHAR(50),destination_id INT,PRIMARY KEY (practice_id),FOREIGN KEY (destination_id) REFERENCES destinations(destination_id));CREATE TABLE destinations (destination_id INT,destination_name VARCHAR(50),region_id INT,PRIMARY KEY (destination_id));CREATE T... | SELECT d.destination_name, COUNT(r.rating_id) as total_ratings, AVG(r.rating) as avg_rating, RANK() OVER (ORDER BY AVG(r.rating) DESC) as rating_rank FROM destinations d JOIN ratings r ON d.destination_id = r.destination_id GROUP BY d.destination_name ORDER BY total_ratings DESC, avg_rating DESC LIMIT 5; |
List the top 3 organic items with the highest inventory value? | CREATE TABLE organic_inventory (item_id INT,item_name VARCHAR(255),category VARCHAR(255),quantity INT,unit_price DECIMAL(5,2)); INSERT INTO organic_inventory (item_id,item_name,category,quantity,unit_price) VALUES (1,'Quinoa','Grains',50,3.99),(2,'Tofu','Proteins',30,2.99),(3,'Almond Milk','Dairy Alternatives',40,2.59)... | SELECT item_name, quantity * unit_price as total_value FROM organic_inventory ORDER BY total_value DESC LIMIT 3; |
What is the total quantity of menu items sold in the 'Appetizers' category from the 'Asian' cuisine type? | CREATE TABLE menu (menu_id INT,menu_name VARCHAR(50),category VARCHAR(50),cuisine VARCHAR(50),quantity_sold INT,price DECIMAL(5,2),month_sold INT); INSERT INTO menu (menu_id,menu_name,category,cuisine,quantity_sold,price,month_sold) VALUES (12,'Spring Rolls','Appetizers','Asian',30,4.99,1),(13,'Edamame','Appetizers','A... | SELECT SUM(quantity_sold) FROM menu WHERE category = 'Appetizers' AND cuisine = 'Asian'; |
List the number of employees by gender and department in the mining company | CREATE TABLE department (id INT,name VARCHAR(255)); CREATE TABLE employee (id INT,name VARCHAR(255),department VARCHAR(255),role VARCHAR(255),salary INT,gender VARCHAR(255)); INSERT INTO department (id,name) VALUES (1,'Mining'),(2,'Engineering'),(3,'Human Resources'); INSERT INTO employee (id,name,department,role,salar... | SELECT d.name as department, e.gender as gender, COUNT(e.id) as num_employees FROM department d JOIN employee e ON d.name = e.department GROUP BY d.name, e.gender; |
Calculate the percentage of mobile and broadband subscribers in each region. | CREATE TABLE mobile_subscribers (subscriber_id INT,region_id INT); INSERT INTO mobile_subscribers (subscriber_id,region_id) VALUES (1,1),(2,2),(3,3),(4,4),(5,1),(6,2),(7,3),(8,4); CREATE TABLE broadband_subscribers (subscriber_id INT,region_id INT); INSERT INTO broadband_subscribers (subscriber_id,region_id) VALUES (9,... | SELECT r.region_name, (COUNT(m.subscriber_id) * 100.0 / (COUNT(m.subscriber_id) + COUNT(b.subscriber_id))) AS mobile_percentage, (COUNT(b.subscriber_id) * 100.0 / (COUNT(m.subscriber_id) + COUNT(b.subscriber_id))) AS broadband_percentage FROM regions r LEFT JOIN mobile_subscribers m ON r.region_id = m.region_id LEFT JO... |
Delete broadband subscribers who have not used their service in the last 6 months. | CREATE TABLE broadband_subscribers_usage (subscriber_id INT,usage_date DATE); INSERT INTO broadband_subscribers_usage (subscriber_id,usage_date) VALUES (17,'2022-01-02'); INSERT INTO broadband_subscribers_usage (subscriber_id,usage_date) VALUES (18,'2022-02-03'); | DELETE FROM broadband_subscribers WHERE subscriber_id NOT IN (SELECT subscriber_id FROM broadband_subscribers_usage WHERE usage_date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH)); |
How many mobile customers have used more than 20 GB of data in the past week? | CREATE TABLE mobile_usage (customer_id INT,last_week_data_usage INT,international_call BOOLEAN); INSERT INTO mobile_usage (customer_id,last_week_data_usage,international_call) VALUES (6,25,FALSE),(7,18,FALSE),(8,22,FALSE),(9,15,FALSE),(10,28,FALSE); | SELECT COUNT(*) FROM mobile_usage WHERE last_week_data_usage > 20; |
What are the top 5 genres by the number of streams in the United States? | CREATE TABLE streams (stream_id int,user_id int,track_id int,genre varchar(255),timestamp datetime); INSERT INTO streams (stream_id,user_id,track_id,genre,timestamp) VALUES (1,123,345,'Rock','2022-01-01 10:00:00'),(2,124,346,'Pop','2022-01-01 11:00:00'); | SELECT genre, COUNT(*) as stream_count FROM streams WHERE timestamp BETWEEN '2022-01-01' AND '2022-12-31' AND genre IS NOT NULL GROUP BY genre ORDER BY stream_count DESC LIMIT 5; |
What is the maximum word count for articles published by 'Sophia Garcia' in the 'media' schema? | CREATE TABLE media.articles (article_id INT,title VARCHAR(100),author VARCHAR(100),publish_date DATE,word_count INT); INSERT INTO media.articles (article_id,title,author,publish_date,word_count) VALUES (1,'Artículo 1','Sophia Garcia','2021-01-01',500),(2,'Artículo 2','Sophia Garcia','2021-02-01',600),(3,'Artículo 3','M... | SELECT MAX(word_count) FROM media.articles WHERE author = 'Sophia Garcia'; |
What is the total number of volunteers for nonprofits in California? | CREATE TABLE Nonprofits (NonprofitID INT,Name VARCHAR(50),City VARCHAR(50),State VARCHAR(2),Zip VARCHAR(10),MissionStatement TEXT,TotalVolunteers INT); CREATE TABLE Volunteers (VolunteerID INT,VolunteerName VARCHAR(50),NonprofitID INT,Hours INT); | SELECT SUM(V.Hours) FROM Volunteers V INNER JOIN Nonprofits N ON V.NonprofitID = N.NonprofitID WHERE N.State = 'CA'; |
Delete the record with id 6 from the table "ocean_acidification" | CREATE TABLE ocean_acidification (id INT,location VARCHAR(50),pH FLOAT,date DATE); | DELETE FROM ocean_acidification WHERE id = 6; |
List all countries with deep-sea exploration programs and their budgets. | CREATE TABLE countries (country_name TEXT,exploration_program BOOLEAN); CREATE TABLE budgets (country_name TEXT,budget FLOAT); INSERT INTO countries (country_name,exploration_program) VALUES ('Canada',TRUE),('Mexico',FALSE); INSERT INTO budgets (country_name,budget) VALUES ('Canada',1000000.0),('Mexico',50000.0); | SELECT countries.country_name, budgets.budget FROM countries INNER JOIN budgets ON countries.country_name = budgets.country_name WHERE countries.exploration_program = TRUE; |
What is the maximum age of players who have not participated in esports events? | CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10),Country VARCHAR(50)); INSERT INTO Players (PlayerID,Age,Gender,Country) VALUES (1,25,'Male','USA'); INSERT INTO Players (PlayerID,Age,Gender,Country) VALUES (2,30,'Female','Canada'); CREATE TABLE EsportsEvents (EventID INT,PlayerID INT,EventName VARCHAR(50))... | SELECT MAX(Players.Age) FROM Players LEFT JOIN EsportsEvents ON Players.PlayerID = EsportsEvents.PlayerID WHERE EsportsEvents.PlayerID IS NULL; |
Delete the farm record with ID 203 | CREATE TABLE farms (farm_id INT,name VARCHAR(50),location VARCHAR(50)); | DELETE FROM farms WHERE farm_id = 203; |
What is the production trend of Neodymium and Dysprosium from 2018 to 2021? | CREATE TABLE production (year INT,element VARCHAR(10),quantity INT); INSERT INTO production (year,element,quantity) VALUES (2018,'Neodymium',5000),(2019,'Neodymium',5500),(2020,'Neodymium',6000),(2021,'Neodymium',6500),(2018,'Dysprosium',3000),(2019,'Dysprosium',3500),(2020,'Dysprosium',4000),(2021,'Dysprosium',4500); | SELECT year, element, SUM(quantity) FROM production GROUP BY year, element; |
List all co-owners and the properties they own in New York, NY. | CREATE TABLE properties (id INT,city VARCHAR(50),price INT); CREATE TABLE co_owners (property_id INT,owner_name VARCHAR(50)); INSERT INTO properties (id,city,price) VALUES (1,'New York',800000),(2,'Los Angeles',600000); INSERT INTO co_owners (property_id,owner_name) VALUES (1,'David'),(1,'Ella'),(2,'Frank'); | SELECT properties.city, co_owners.owner_name FROM properties INNER JOIN co_owners ON properties.id = co_owners.property_id WHERE properties.city = 'New York'; |
What is the average revenue per day for each restaurant location in the breakfast category? | CREATE TABLE daily_revenue(location VARCHAR(255),revenue DECIMAL(10,2),date DATE); CREATE TABLE menu_category(menu_item VARCHAR(255),category VARCHAR(255)); INSERT INTO daily_revenue VALUES ('Location A',500,'2023-01-01'); INSERT INTO daily_revenue VALUES ('Location A',600,'2023-01-02'); INSERT INTO menu_category VALUE... | SELECT location, AVG(revenue/COUNT(*)) as avg_revenue FROM daily_revenue dr INNER JOIN menu_category mc ON dr.date = mc.menu_item WHERE category = 'Breakfast' GROUP BY location; |
Which menu items have been sold for more than $10,000, and what is the total quantity sold? | CREATE TABLE menu_items (menu_item_id INT,menu_item_name VARCHAR(50),category VARCHAR(50),price FLOAT,quantity_sold INT); INSERT INTO menu_items (menu_item_id,menu_item_name,category,price,quantity_sold) VALUES (1,'Burger','Main Course',12.99,1500); | SELECT menu_item_name, SUM(quantity_sold) FROM menu_items WHERE price * quantity_sold > 10000 GROUP BY menu_item_name; |
What is the name of all Russian astronauts? | CREATE TABLE Astronauts (id INT,name VARCHAR(255),agency VARCHAR(255),missions INT); INSERT INTO Astronauts (id,name,agency,missions) VALUES (1,'Mae Jemison','NASA',2),(2,'Yuri Gagarin','Roscosmos',1); | SELECT name FROM Astronauts WHERE agency = 'Roscosmos'; |
Which company has manufactured the most satellites? | CREATE TABLE manufacturers (id INT,name TEXT); CREATE TABLE satellites (id INT,manufacturer_id INT,name TEXT,launch_date DATE); INSERT INTO manufacturers (id,name) VALUES (1,'SpaceX'),(2,'Blue Origin'),(3,'ISRO'),(4,'CAST'); INSERT INTO satellites (id,manufacturer_id,name,launch_date) VALUES (1,1,'StarDragon','2012-05-... | SELECT m.name, COUNT(s.id) FROM manufacturers m JOIN satellites s ON m.id = s.manufacturer_id GROUP BY m.name ORDER BY COUNT(s.id) DESC; |
Show the number of security incidents and their severity by quarter | CREATE TABLE incident_quarterly (id INT,incident_date DATE,severity VARCHAR(10)); INSERT INTO incident_quarterly (id,incident_date,severity) VALUES (1,'2022-01-01','Low'),(2,'2022-01-15','Medium'),(3,'2022-04-01','High'),(4,'2022-07-01','Critical'),(5,'2022-10-01','Low'),(6,'2022-10-15','Medium'); | SELECT EXTRACT(QUARTER FROM incident_date) as quarter, severity, COUNT(*) as incidents FROM incident_quarterly GROUP BY quarter, severity; |
Find the top 5 most profitable garments based on their sales in Q2 of 2022, and display the garment_name and total revenue. | CREATE TABLE Garments (garment_id INT,garment_name VARCHAR(50),category VARCHAR(50)); INSERT INTO Garments (garment_id,garment_name,category) VALUES (1,'Cotton T-Shirt','Tops'),(2,'Jeans','Bottoms'),(3,'Silk Blouse','Tops'),(4,'Wool Coat','Outerwear'); CREATE TABLE Sales_Details (sale_id INT,garment_id INT,sale_quantit... | SELECT g.garment_name, SUM(sd.sale_quantity * sd.sale_price) AS total_revenue FROM Sales s JOIN Sales_Details sd ON s.sale_id = sd.sale_id JOIN Garments g ON sd.garment_id = g.garment_id WHERE s.sale_date BETWEEN '2022-04-01' AND '2022-06-30' GROUP BY g.garment_name ORDER BY total_revenue DESC LIMIT 5; |
How many workplace safety inspections were conducted in each state? | CREATE TABLE safety_inspections (id INT,state VARCHAR(2),inspections INT); INSERT INTO safety_inspections (id,state,inspections) VALUES (1,'California',350),(2,'Texas',420),(3,'New York',500); | SELECT state, SUM(inspections) as total_inspections FROM safety_inspections GROUP BY state; |
What is the average safety rating of vehicles manufactured in Germany? | CREATE TABLE Vehicle (id INT,make VARCHAR(50),model VARCHAR(50),safety_rating FLOAT,country VARCHAR(50)); | SELECT AVG(safety_rating) FROM Vehicle WHERE country = 'Germany'; |
Insert a new record into the vessel_performance table with the following details: vessel_id = V003, max_speed = 20 knots, average_speed = 15 knots | vessel_performance(vessel_id,max_speed,average_speed) | INSERT INTO vessel_performance (vessel_id, max_speed, average_speed) VALUES ('V003', 20, 15); |
What is the total cargo weight for each vessel? | CREATE TABLE vessel_cargo (id INT,vessel_id INT,trip_id INT,cargo_weight INT); INSERT INTO vessel_cargo VALUES (1,1,1,500),(2,1,2,700),(3,2,1,600),(4,3,1,800); | SELECT vessel_id, SUM(cargo_weight) FROM vessel_cargo GROUP BY vessel_id; |
What is the waste generation per capita for each country in 'waste_generation'? | CREATE TABLE waste_generation (country VARCHAR(50),year INT,population INT,waste_amount INT); | SELECT country, AVG(waste_amount/population) as avg_waste_per_capita FROM waste_generation GROUP BY country; |
What is the average water consumption per household in Mumbai for the years 2018 and 2019? | CREATE TABLE Household_Water_Usage (Household_ID INT,City VARCHAR(20),Year INT,Water_Consumption FLOAT); INSERT INTO Household_Water_Usage (Household_ID,City,Year,Water_Consumption) VALUES (1,'Mumbai',2018,150.5),(2,'Mumbai',2019,130.2); | SELECT Year, AVG(Water_Consumption) FROM Household_Water_Usage WHERE City = 'Mumbai' AND Year IN (2018, 2019) GROUP BY Year; |
List the top 3 datasets with the longest average testing times for models using the 'random_forest' algorithm. | CREATE TABLE testing_times (id INT,dataset VARCHAR(255),algorithm VARCHAR(255),avg_time FLOAT); INSERT INTO testing_times (id,dataset,algorithm,avg_time) VALUES (1,'MNIST','random_forest',1.2),(2,'CIFAR-10','random_forest',1.5),(3,'ImageNet','svm',1.9),(4,'MNIST','svm',1.1); | SELECT dataset, avg_time FROM testing_times WHERE algorithm = 'random_forest' ORDER BY avg_time DESC LIMIT 3; |
Update the output_quality to 'good' for records in the creative_ai table where the id is between 1 and 10 and the application is 'image generation' | CREATE TABLE creative_ai (id INTEGER,application TEXT,output_quality TEXT,last_updated TIMESTAMP); | UPDATE creative_ai SET output_quality = 'good' WHERE id BETWEEN 1 AND 10 AND application = 'image generation'; |
How many rural infrastructure projects were completed in '2022' in the 'Asia-Pacific' region? | CREATE TABLE rural_infrastructure(id INT,project TEXT,location TEXT,completion_year INT); INSERT INTO rural_infrastructure (id,project,location,completion_year) VALUES (1,'Rural Road Project','Asia-Pacific',2022); | SELECT COUNT(*) FROM rural_infrastructure WHERE location = 'Asia-Pacific' AND completion_year = 2022; |
Insert a new animal 'Giant Panda' into the database with the habitat_id 1 (Forest) | CREATE TABLE habitats (id INT PRIMARY KEY,habitat_type VARCHAR(50)); INSERT INTO habitats (id,habitat_type) VALUES (1,'Forest'); INSERT INTO habitats (id,habitat_type) VALUES (2,'Grassland'); INSERT INTO habitats (id,habitat_type) VALUES (3,'Wetland'); CREATE TABLE animals (id INT PRIMARY KEY,animal_name VARCHAR(50),ha... | INSERT INTO animals (id, animal_name, habitat_id) VALUES ((SELECT COALESCE(MAX(id), 0) + 1 FROM animals), 'Giant Panda', 1); |
What is the maximum viewership for TV shows in the Comedy genre? | CREATE TABLE TV_Shows (show_id INT,title VARCHAR(100),genre VARCHAR(50),viewership INT); INSERT INTO TV_Shows (show_id,title,genre,viewership) VALUES (1,'ShowA','Comedy',9000000); INSERT INTO TV_Shows (show_id,title,genre,viewership) VALUES (2,'ShowB','Drama',8000000); INSERT INTO TV_Shows (show_id,title,genre,viewersh... | SELECT title, MAX(viewership) FROM TV_Shows WHERE genre = 'Comedy' GROUP BY title; |
Calculate the total billing for each case type | CREATE TABLE billing (id INT,case_id INT,attorney_id INT,hours_worked INT,billable_rate DECIMAL(10,2)); INSERT INTO billing (id,case_id,attorney_id,hours_worked,billable_rate) VALUES (1,1,1,15,200.00); INSERT INTO billing (id,case_id,attorney_id,hours_worked,billable_rate) VALUES (2,2,2,20,250.00); CREATE TABLE cases (... | SELECT case_type, SUM(hours_worked * billable_rate) as total_billing FROM billing JOIN cases ON billing.case_id = cases.id GROUP BY case_type; |
What are the total climate finance expenditures for Oceania in each sector? | CREATE TABLE climate_finance_oceania (id INT,country VARCHAR(50),sector VARCHAR(50),amount FLOAT); INSERT INTO climate_finance_oceania (id,country,sector,amount) VALUES (1,'Australia','Climate Mitigation',3500000); INSERT INTO climate_finance_oceania (id,country,sector,amount) VALUES (2,'Australia','Climate Adaptation'... | SELECT sector, SUM(amount) as total_amount FROM climate_finance_oceania WHERE country IN ('Australia', 'New Zealand') GROUP BY sector; |
What are the combined sales figures for 'Lipitor' in the US and 'Crestor' in Canada? | CREATE TABLE drug_sales (drug_name TEXT,region TEXT,revenue FLOAT); INSERT INTO drug_sales (drug_name,region,revenue) VALUES ('Lipitor','US',3000000),('Crestor','Canada',2500000); | SELECT SUM(revenue) FROM drug_sales WHERE (drug_name = 'Lipitor' AND region = 'US') OR (drug_name = 'Crestor' AND region = 'Canada'); |
What is the percentage of patients diagnosed with Measles who have been vaccinated in each state? | CREATE TABLE Patients (ID INT,Disease VARCHAR(20),Vaccinated VARCHAR(5),State VARCHAR(20)); INSERT INTO Patients (ID,Disease,Vaccinated,State) VALUES (1,'Measles','Yes','California'),(2,'Measles','No','California'); | SELECT State, (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Patients WHERE Disease = 'Measles' AND State = Patients.State)) AS Percentage FROM Patients WHERE Vaccinated = 'Yes' GROUP BY State; |
Which female founders have received the most funding? | CREATE TABLE founders (founder_id INT,founder_name VARCHAR(50),gender CHAR(1),startup_id INT); CREATE TABLE startups (startup_id INT,funding_amount INT); INSERT INTO founders VALUES (1,'Alice','F',1),(2,'Bob','M',2),(3,'Charlie','M',3); INSERT INTO startups VALUES (1,500000),(2,750000),(3,300000); | SELECT f.founder_name, SUM(s.funding_amount) as total_funding FROM founders f JOIN startups s ON f.startup_id = s.startup_id WHERE f.gender = 'F' GROUP BY f.founder_name ORDER BY total_funding DESC; |
What is the total funding raised by startups from the US? | CREATE TABLE startups (id INT,name TEXT,founded_year INT,industry TEXT,country TEXT,funding FLOAT); | SELECT SUM(funding) FROM startups WHERE country = 'United States'; |
How many 'crop_yield' records are there for each 'farm' in the 'crop_yields' table? | CREATE TABLE crop_yields (id INT,farm_id INT,crop VARCHAR(50),yield FLOAT); | SELECT farm_id, COUNT(*) FROM crop_yields GROUP BY farm_id; |
Count the number of endangered species in the table "marine_mammals" | CREATE TABLE marine_mammals (id INT PRIMARY KEY,name VARCHAR(255),species VARCHAR(255),population INT,conservation_status VARCHAR(255)); INSERT INTO marine_mammals (id,name,species,population,conservation_status) VALUES (1,'Blue Whale','Balaenoptera musculus',10000,'Endangered'),(2,'Dolphin','Tursiops truncatus',60000,... | SELECT COUNT(*) FROM marine_mammals WHERE conservation_status = 'Endangered'; |
What is the total number of digital assets issued by companies based in the US? | CREATE TABLE companies (id INT,name TEXT,country TEXT); INSERT INTO companies (id,name,country) VALUES (1,'Securitize','USA'),(2,'Polymath','Canada'); | SELECT SUM(CASE WHEN country = 'USA' THEN 1 ELSE 0 END) FROM companies; |
What is the total carbon sequestration for each type of forest? | CREATE TABLE forest_type (forest_type VARCHAR(255),avg_carbon_ton FLOAT,area_ha INT); INSERT INTO forest_type (forest_type,avg_carbon_ton,area_ha) VALUES ('Forest1',2.3,5000),('Forest2',2.5,7000),('Forest3',2.8,6000),('Forest4',3.0,8000),('Forest5',3.2,9000); | SELECT forest_type, AVG(avg_carbon_ton)*area_ha AS total_carbon_seq FROM forest_type GROUP BY forest_type; |
What is the average consumer rating for cruelty-free cosmetics products sourced from India? | CREATE TABLE product_info (product_name TEXT,is_cruelty_free BOOLEAN,consumer_rating REAL,source_country TEXT); INSERT INTO product_info (product_name,is_cruelty_free,consumer_rating,source_country) VALUES ('Product 16',true,4.6,'IN'),('Product 17',false,3.9,'CN'),('Product 18',true,4.2,'US'),('Product 19',false,1.7,'C... | SELECT AVG(consumer_rating) FROM product_info WHERE is_cruelty_free = true AND source_country = 'IN'; |
Find the average price of cruelty-free foundation products in Canada. | CREATE TABLE cosmetics (product VARCHAR(255),price DECIMAL(10,2),cruelty_free BOOLEAN); CREATE VIEW canada_cosmetics AS SELECT * FROM cosmetics WHERE country = 'Canada'; | SELECT AVG(price) FROM canada_cosmetics WHERE product_category = 'Foundations' AND cruelty_free = true; |
Find the number of products with a price point below $10 and a rating above 4.5? | CREATE TABLE Product_Info(Product_Name VARCHAR(30),Price DECIMAL(5,2),Rating DECIMAL(3,2)); INSERT INTO Product_Info(Product_Name,Price,Rating) VALUES('Product A',8.50,4.7),('Product B',12.00,4.8),('Product C',7.99,4.6),('Product D',9.99,4.9),('Product E',6.50,4.4),('Product F',11.00,4.2),('Product G',5.99,4.8),('Produ... | SELECT COUNT(*) FROM Product_Info WHERE Price < 10 AND Rating > 4.5; |
List vegan skincare products with a price below 15 EUR, available in Spain | CREATE TABLE products (product_id INT,product_name TEXT,price DECIMAL(5,2),is_vegan BOOLEAN,country TEXT); | SELECT * FROM products WHERE is_vegan = TRUE AND price < 15 AND country = 'Spain'; |
What is the average rating of cosmetics products manufactured in the USA? | CREATE TABLE Product (product_id INT,product_name VARCHAR(50),category VARCHAR(50),manufacturer_country VARCHAR(50)); INSERT INTO Product (product_id,product_name,category,manufacturer_country) VALUES (1,'Lipstick','Cosmetics','USA'); | SELECT AVG(Review.rating) FROM Review INNER JOIN Product ON Review.product_id = Product.product_id WHERE Product.manufacturer_country = 'USA' AND Product.category = 'Cosmetics'; |
Delete all veteran unemployment claims filed more than 1 year ago in all states? | CREATE TABLE veteran_unemployment (id INT,claim_date DATE,state VARCHAR(50),claim_status VARCHAR(50)); INSERT INTO veteran_unemployment (id,claim_date,state,claim_status) VALUES (1,'2021-01-05','California','Filed'),(2,'2022-02-10','Texas','Rejected'); | DELETE FROM veteran_unemployment WHERE claim_date < DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR); |
What are the threat intelligence metrics for a specific country over the past year? | CREATE TABLE threat_intelligence (date DATE,threat_level INT,incident_count INT,country VARCHAR(255)); INSERT INTO threat_intelligence (date,threat_level,incident_count,country) VALUES ('2021-01-01',5,200,'USA'),('2021-02-01',4,150,'USA'),('2021-03-01',6,220,'USA'),('2021-04-01',3,100,'USA'),('2021-05-01',7,250,'USA'),... | SELECT country, EXTRACT(YEAR FROM date) AS year, AVG(threat_level), AVG(incident_count) FROM threat_intelligence WHERE country = 'USA' GROUP BY country, year; |
Display all peacekeeping operations from the 'peacekeeping_operations' table | CREATE TABLE peacekeeping_operations (operation_id INT,operation_name VARCHAR(255),start_date DATE,end_date DATE,operation_region VARCHAR(255)); | SELECT * FROM peacekeeping_operations WHERE end_date IS NULL; |
What is the average unloading time in minutes for ports in Asia? | CREATE TABLE Port (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),continent VARCHAR(255)); INSERT INTO Port (id,name,country,continent) VALUES (1,'Port of Shanghai','Shanghai','Asia'); | SELECT Port_id, AVG(unloading_time) FROM Port_Performance WHERE continent = 'Asia' GROUP BY Port_id; |
What is the maximum cargo weight handled by each crane in the last month? | CREATE TABLE cranes (id INT,name VARCHAR(50),type VARCHAR(50),max_weight INT); CREATE TABLE cargo_handling (id INT,crane_id INT,cargo_weight INT,handling_date DATE); INSERT INTO cranes VALUES (1,'Crane 1','Gantry',50); INSERT INTO cranes VALUES (2,'Crane 2','Gantry',60); INSERT INTO cargo_handling VALUES (1,1,40,'2022-... | SELECT cranes.name, MAX(cargo_handling.cargo_weight) FROM cranes INNER JOIN cargo_handling ON cranes.id = cargo_handling.crane_id WHERE cargo_handling.handling_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY cranes.name; |
List all 'recycling' initiatives in the 'sustainability_programs' table. | CREATE TABLE sustainability_programs (id INT,name TEXT,type TEXT); INSERT INTO sustainability_programs (id,name,type) VALUES (1,'plastic_recycling','recycling'),(2,'paper_recycling','recycling'),(3,'electronic_waste','disposal'); | SELECT name FROM sustainability_programs WHERE type = 'recycling'; |
What is the average salary of workers in the 'manufacturing' industry across different regions? | CREATE TABLE Workers (id INT,name VARCHAR(50),salary FLOAT,industry VARCHAR(50)); INSERT INTO Workers (id,name,salary,industry) VALUES (1,'John Doe',50000,'manufacturing'); INSERT INTO Workers (id,name,salary,industry) VALUES (2,'Jane Smith',55000,'manufacturing'); CREATE TABLE Regions (id INT,region_name VARCHAR(50));... | SELECT AVG(Workers.salary) FROM Workers INNER JOIN Regions ON Workers.id = Regions.id WHERE Workers.industry = 'manufacturing'; |
Find the total number of investments in each sector, ordered from highest to lowest. | CREATE TABLE investments(id INT,sector VARCHAR(20),esg_score INT); INSERT INTO investments VALUES(1,'Tech',85),(2,'Healthcare',75),(3,'Tech',82); | SELECT sector, COUNT(*) as total_investments FROM investments GROUP BY sector ORDER BY total_investments DESC; |
How many military satellites of space_power type are present in the SATELLITE_DATA table? | CREATE TABLE SATELLITE_DATA (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255),country VARCHAR(255)); | SELECT COUNT(*) FROM SATELLITE_DATA WHERE type = 'space_power'; |
What is the total number of cybersecurity incidents in the Asia-Pacific region by year? | CREATE TABLE cybersecurity_incidents (id INT,incident_date DATE,region VARCHAR(255)); INSERT INTO cybersecurity_incidents (id,incident_date,region) VALUES (1,'2020-01-01','Asia-Pacific'); INSERT INTO cybersecurity_incidents (id,incident_date,region) VALUES (2,'2021-03-15','Europe'); | SELECT YEAR(incident_date) AS year, COUNT(*) AS total_incidents FROM cybersecurity_incidents WHERE region = 'Asia-Pacific' GROUP BY year; |
What is the total revenue, by platform, for the last quarter? | CREATE TABLE revenue_platform (revenue_id INT,platform VARCHAR(255),revenue DECIMAL); CREATE VIEW quarterly_revenue AS SELECT platform,SUM(revenue) as total_revenue FROM revenue_platform WHERE revenue_date >= DATEADD(quarter,-1,CURRENT_DATE) GROUP BY platform; | SELECT * FROM quarterly_revenue; |
Show the total budget allocated for each program category in 2023. | CREATE TABLE Budget (id INT,category TEXT,year INT,allocated_amount INT); INSERT INTO Budget (id,category,year,allocated_amount) VALUES (1,'Education',2023,30000); INSERT INTO Budget (id,category,year,allocated_amount) VALUES (2,'Healthcare',2023,50000); | SELECT category, SUM(allocated_amount) FROM Budget WHERE year = 2023 GROUP BY category; |
Update the budget for program_id 104 to 8500 starting from 2022-07-01. | CREATE TABLE Programs (program_id INT,budget DECIMAL(10,2),start_date DATE); INSERT INTO Programs (program_id,budget,start_date) VALUES (101,10000,'2021-01-01'),(104,7000,'2021-04-01'); | UPDATE Programs SET budget = 8500, start_date = '2022-07-01' WHERE program_id = 104; |
What was the average donation amount per donor by country for 2022? | CREATE TABLE Donors (donor_id INT,donation_amount DECIMAL(10,2),donor_country VARCHAR(255),donation_date DATE); INSERT INTO Donors (donor_id,donation_amount,donor_country,donation_date) VALUES (6,500,'Canada','2022-01-01'),(7,350,'Mexico','2022-02-01'),(8,700,'Brazil','2022-03-01'),(9,280,'South Africa','2022-04-01'),(... | SELECT donor_country, AVG(donation_amount) as avg_donation FROM Donors WHERE donation_date BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY donor_country; |
What's the average amount donated and number of donors per day for the past week? | CREATE TABLE Donations (Id INT,DonationDate DATE,Amount DECIMAL(10,2),DonorId INT); INSERT INTO Donations VALUES (1,'2022-01-01',100.00,1),(2,'2022-01-01',200.00,2); | SELECT DATE_TRUNC('day', DonationDate) as Day, AVG(Amount) as AvgAmount, COUNT(DISTINCT DonorId) as DistinctDonors FROM Donations WHERE DonationDate >= DATEADD(day, -7, CURRENT_DATE) GROUP BY Day; |
List all the community centers in Colombia, including their capacities and locations. | CREATE TABLE community_centers (id INT,name TEXT,capacity INT,location TEXT,country TEXT); INSERT INTO community_centers (id,name,capacity,location,country) VALUES (1,'Centro Comunitario 1',100,'Bogotá','Colombia'); INSERT INTO community_centers (id,name,capacity,location,country) VALUES (2,'Centro Comunitario 2',150,'... | SELECT * FROM community_centers WHERE country = 'Colombia'; |
What is the total funding received by organizations that have implemented digital divide initiatives? | CREATE TABLE funding (funding_id INT,org_id INT,amount INT); INSERT INTO funding (funding_id,org_id,amount) VALUES (1,1,100000),(2,1,200000),(3,2,150000); CREATE TABLE organizations (org_id INT,name VARCHAR(50),implemented_digital_divide_initiatives BOOLEAN); INSERT INTO organizations (org_id,name,implemented_digital_d... | SELECT SUM(amount) FROM funding INNER JOIN organizations ON funding.org_id = organizations.org_id WHERE implemented_digital_divide_initiatives = TRUE; |
Which vehicle type in the 'Bus' service had the most maintenance incidents in the last month? | CREATE TABLE MaintenanceIncidents (IncidentID INT,VehicleID INT,VehicleType VARCHAR(50),IncidentDate DATE); INSERT INTO MaintenanceIncidents (IncidentID,VehicleID,VehicleType,IncidentDate) VALUES (1,1,'MiniBus','2022-02-01'),(2,1,'MiniBus','2022-02-03'),(3,2,'Coach','2022-02-02'),(4,3,'MidiBus','2022-02-04'),(5,4,'Mini... | SELECT v.VehicleType, COUNT(*) as MaintenanceIncidents FROM Vehicles v JOIN MaintenanceIncidents mi ON v.VehicleID = mi.VehicleID WHERE v.Service = 'Bus' AND mi.IncidentDate >= DATEADD(month, -1, GETDATE()) GROUP BY v.VehicleType ORDER BY MaintenanceIncidents DESC; |
Update the minimum living wage for 'Bangladesh' in the 'apparel_manufacturing' sector | CREATE TABLE living_wage (country VARCHAR(50),apparel_manufacturing_sector VARCHAR(50),living_wage_minimum FLOAT,living_wage_maximum FLOAT); INSERT INTO living_wage (country,apparel_manufacturing_sector,living_wage_minimum,living_wage_maximum) VALUES ('Bangladesh','apparel_manufacturing',80,120); | UPDATE living_wage SET living_wage_minimum = 90 WHERE country = 'Bangladesh' AND apparel_manufacturing_sector = 'apparel_manufacturing'; |
What is the percentage of factories in each country that have implemented circular economy practices? | CREATE TABLE factory_circle (factory VARCHAR(255),country VARCHAR(255),practice VARCHAR(255)); INSERT INTO factory_circle (factory,country,practice) VALUES ('Factory1','Bangladesh','yes'),('Factory2','Bangladesh','no'),('Factory3','Bangladesh','yes'),('Factory4','China','yes'),('Factory5','China','no'),('Factory6','Ind... | SELECT country, 100.0 * COUNT(*) FILTER (WHERE practice = 'yes') / COUNT(*) AS percentage FROM factory_circle GROUP BY country; |
What is the total quantity of sustainable material 'organic cotton' used by manufacturers in the 'Europe' region? | CREATE TABLE Manufacturers (ManufacturerID INT,ManufacturerName VARCHAR(50),Region VARCHAR(50)); INSERT INTO Manufacturers (ManufacturerID,ManufacturerName,Region) VALUES (1,'EcoFriendlyFabrics','Europe'),(2,'GreenYarns','Asia'); CREATE TABLE Materials (MaterialID INT,MaterialName VARCHAR(50),QuantityUsed INT); INSERT ... | SELECT SUM(QuantityUsed) FROM Materials WHERE MaterialName = 'organic cotton' AND Region = 'Europe'; |
Show the number of financial wellbeing programs offered in each country. | CREATE TABLE financial_wellbeing_programs (program_id INT,program_name TEXT,country TEXT); INSERT INTO financial_wellbeing_programs (program_id,program_name,country) VALUES (1,'Wellness Workshops','Canada'),(2,'Financial Fitness','Mexico'),(3,'Empowerment Seminars','Brazil'),(4,'Mindful Money','USA'); | SELECT financial_wellbeing_programs.country, COUNT(financial_wellbeing_programs.program_id) FROM financial_wellbeing_programs GROUP BY financial_wellbeing_programs.country; |
What is the average amount of Shariah-compliant financing for clients in the top 3 countries with the most Shariah-compliant financing, excluding clients from Saudi Arabia and the UAE? | CREATE TABLE shariah_financing(client_id INT,client_country VARCHAR(25),amount FLOAT);INSERT INTO shariah_financing(client_id,client_country,amount) VALUES (1,'Bahrain',5000),(2,'UAE',7000),(3,'Indonesia',6000),(4,'Saudi Arabia',8000),(5,'Bahrain',9000),(6,'UAE',10000),(7,'Indonesia',11000),(8,'Saudi Arabia',12000),(9,... | SELECT client_country, AVG(amount) as avg_financing FROM shariah_financing WHERE client_country NOT IN ('Saudi Arabia', 'UAE') GROUP BY client_country ORDER BY AVG(amount) DESC LIMIT 3; |
List the programs that have not received any donations in the last year, excluding those related to Disaster Relief? | CREATE TABLE Programs (ProgramID INT,ProgramName TEXT,Category TEXT); CREATE TABLE Donations (DonationID INT,ProgramID INT,DonationDate DATE); INSERT INTO Programs (ProgramID,ProgramName,Category) VALUES (1,'Education','General'),(2,'Health','General'),(3,'Disaster Relief','Special'); INSERT INTO Donations (DonationID,... | SELECT ProgramName FROM Programs p WHERE ProgramID NOT IN (SELECT Donations.ProgramID FROM Donations WHERE Donations.DonationDate >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR)) AND Category != 'Special'; |
What is the total budget and number of programs for each program category? | CREATE TABLE Programs (ProgramID INT,ProgramName TEXT,ProgramCategory TEXT,Budget DECIMAL); INSERT INTO Programs (ProgramID,ProgramName,ProgramCategory,Budget) VALUES (1,'Education','Social',15000.00),(2,'Healthcare','Health',20000.00),(3,'Environment','Environment',10000.00),(4,'Awareness','Social',5000.00); | SELECT ProgramCategory, SUM(Budget) as TotalBudget, COUNT(ProgramID) as TotalPrograms FROM Programs GROUP BY ProgramCategory; |
What is the total number of packages shipped from each warehouse in the province of Ontario, Canada in the month of June? | CREATE TABLE warehouses (id INT,city VARCHAR(255),state VARCHAR(255),country VARCHAR(255)); CREATE TABLE packages (id INT,warehouse_id INT,weight INT,shipped_date DATE); INSERT INTO packages (id,warehouse_id,weight,shipped_date) VALUES (1,1,50,'2022-06-01'),(2,2,30,'2022-06-02'),(3,3,40,'2022-06-03'); INSERT INTO wareh... | SELECT warehouses.city, COUNT(*) FROM packages JOIN warehouses ON packages.warehouse_id = warehouses.id WHERE warehouses.state = 'Ontario' AND warehouses.country = 'Canada' AND MONTH(packages.shipped_date) = 6 GROUP BY warehouses.city; |
How many bioprocess engineering projects have been conducted in Africa using CRISPR technology? | CREATE TABLE bioprocess_engineering (project_name VARCHAR(255),location VARCHAR(255),technology VARCHAR(255)); INSERT INTO bioprocess_engineering (project_name,location,technology) VALUES ('ProjAfrica','Africa','CRISPR-Cas9'); | SELECT COUNT(*) FROM bioprocess_engineering WHERE location = 'Africa' AND technology = 'CRISPR-Cas9'; |
What is the average funding received by biotech startups in the US, grouped by state? | CREATE SCHEMA if not exists biotech; USE biotech; CREATE TABLE if not exists startups (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),industry VARCHAR(255),funding DECIMAL(10,2)); INSERT INTO startups (id,name,location,industry,funding) VALUES (1,'StartupA','California','Biotech',5000000.00),(2,'StartupB','... | SELECT location, AVG(funding) FROM startups WHERE industry = 'Biotech' GROUP BY location; |
What is the name of the biotech startup that received the most funding in the United States? | CREATE SCHEMA if not exists biotech; CREATE TABLE if not exists biotech.startups (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),funding FLOAT); INSERT INTO biotech.startups (id,name,location,funding) VALUES (1,'StartupA','USA',9000000),(2,'StartupB','USA',6000000),(3,'StartupC','Canada',3000000),(4,'Startu... | SELECT name FROM biotech.startups WHERE location = 'USA' AND funding = (SELECT MAX(funding) FROM biotech.startups WHERE location = 'USA'); |
What is the total budget allocated for healthcare projects in each city in the state of Florida? | CREATE TABLE Cities (CityID INTEGER,CityName TEXT,State TEXT); CREATE TABLE HealthcareProjects (ProjectID INTEGER,ProjectCityID INTEGER,ProjectBudget INTEGER); | SELECT C.CityName, SUM(HP.ProjectBudget) FROM Cities C INNER JOIN HealthcareProjects HP ON C.CityID = HP.ProjectCityID WHERE C.State = 'Florida' GROUP BY C.CityName; |
How many students are enrolled in the Data Science program in the Fall semester? | CREATE TABLE student_enrollment(id INT,program TEXT,semester TEXT); INSERT INTO student_enrollment(id,program,semester) VALUES (1,'Data Science','Fall'),(2,'Mathematics','Spring'); | SELECT COUNT(*) FROM student_enrollment WHERE program = 'Data Science' AND semester = 'Fall'; |
How many indigenous communities are in the Arctic Research Station 13 and 14? | CREATE TABLE Arctic_Research_Station_13 (id INT,community TEXT); CREATE TABLE Arctic_Research_Station_14 (id INT,community TEXT); | SELECT COUNT(DISTINCT community) FROM Arctic_Research_Station_13; SELECT COUNT(DISTINCT community) FROM Arctic_Research_Station_14; SELECT COUNT(DISTINCT community) FROM (SELECT * FROM Arctic_Research_Station_13 UNION ALL SELECT * FROM Arctic_Research_Station_14) AS Arctic_Communities; |
What is the maximum number of years a heritage site has been closed for restoration? | CREATE TABLE restoration (id INT,site_name VARCHAR(255),start_year INT,end_year INT); INSERT INTO restoration (id,site_name,start_year,end_year) VALUES (1,'Angkor Wat',1965,1972),(2,'Petra',1993,1998); | SELECT MAX(end_year - start_year) FROM restoration; |
Get the names of all solar farms in Arizona | CREATE TABLE Infrastructure (id INT,name VARCHAR(100),type VARCHAR(50),location VARCHAR(100),state VARCHAR(50)); INSERT INTO Infrastructure (id,name,type,location,state) VALUES (10,'Arizona Solar One','Solar Farm','Buckeye','Arizona'); | SELECT name FROM Infrastructure WHERE type = 'Solar Farm' AND state = 'Arizona'; |
Update the name of the record with id 2 in the 'contractors' table to 'GreenTech' | CREATE TABLE contractors (id INT,name VARCHAR(50),country VARCHAR(50),registration_date DATE); | UPDATE contractors SET name = 'GreenTech' WHERE id = 2; |
What is the total length of all the rail tracks in 'Asia'? | CREATE TABLE RailTracks (TrackID int,Location varchar(100),Length decimal(10,2)); INSERT INTO RailTracks VALUES (1,'Asia',500); INSERT INTO RailTracks VALUES (2,'Asia',700); | SELECT SUM(Length) FROM RailTracks WHERE Location = 'Asia'; |
Which projects in 'bridge_data' have a 'construction_year' between 2010 and 2020? | CREATE TABLE bridge_data (id INT,bridge_name VARCHAR(50),construction_year INT); INSERT INTO bridge_data (id,bridge_name,construction_year) VALUES (1,'Golden Gate Bridge',1937),(2,'Sydney Harbour Bridge',1932); INSERT INTO bridge_data (id,bridge_name,construction_year) VALUES (3,'New Bridge',2015); | SELECT * FROM bridge_data WHERE construction_year BETWEEN 2010 AND 2020; |
What is the average travel advisory level for each country in Europe? | CREATE TABLE if not exists countries (id INT,name VARCHAR(20)); CREATE TABLE if not exists advisories (id INT,country_id INT,level INT); | SELECT c.name, AVG(a.level) FROM advisories a JOIN countries c ON a.country_id = c.id WHERE c.name IN ('Austria', 'Belgium', 'Czech Republic', 'Denmark', 'Estonia', 'Finland', 'France', 'Germany', 'Greece', 'Hungary', 'Ireland', 'Italy', 'Latvia', 'Lithuania', 'Luxembourg', 'Malta', 'Netherlands', 'Norway', 'Poland', '... |
What is the maximum carbon emissions reduction achieved by hotels in each continent, and the number of hotels that achieved this reduction? | CREATE TABLE Hotels (HotelID INT,HotelName VARCHAR(50),Continent VARCHAR(20),CO2EmissionsReduction INT); INSERT INTO Hotels (HotelID,HotelName,Continent,CO2EmissionsReduction) VALUES (1,'GreenPalace','Asia',30),(2,'EcoLodge','Africa',25); | SELECT Continent, MAX(CO2EmissionsReduction) as MaxReduction, COUNT(*) as HotelCount FROM Hotels GROUP BY Continent; |
Which countries have had a travel advisory of "Reconsider travel" or higher since 2010? | CREATE TABLE TravelAdvisories (id INT PRIMARY KEY,country_id INT,year INT,advisory VARCHAR(255)); INSERT INTO TravelAdvisories (id,country_id,year,advisory) VALUES (1,1,2010,'Exercise normal precautions'); INSERT INTO TravelAdvisories (id,country_id,year,advisory) VALUES (2,1,2011,'Exercise normal precautions'); INSERT... | SELECT country_id FROM TravelAdvisories WHERE advisory IN ('Reconsider travel', 'Do not travel') AND year >= 2010 GROUP BY country_id; |
List all the marine research stations and their respective regions | CREATE TABLE research_stations (station_id INT,station_name VARCHAR(30),region_id INT); INSERT INTO research_stations (station_id,station_name,region_id) VALUES (1,'Station A',1),(2,'Station B',2),(3,'Station C',3); | SELECT station_name, region_id FROM research_stations; |
Determine the most popular dish in each category | CREATE TABLE menu (dish_id INT,dish_name VARCHAR(255),dish_type VARCHAR(255),sales INT); INSERT INTO menu (dish_id,dish_name,dish_type,sales) VALUES (1,'Quinoa Salad','Vegetarian',150),(2,'Chicken Sandwich','Non-Vegetarian',200),(3,'Pumpkin Soup','Vegetarian',120); | SELECT dish_type, dish_name, sales FROM menu m1 WHERE sales = (SELECT MAX(sales) FROM menu m2 WHERE m1.dish_type = m2.dish_type) GROUP BY dish_type; |
How many menu items have a price below $5? | CREATE TABLE menus (menu_id INT,menu_name VARCHAR(50),type VARCHAR(20),price DECIMAL(5,2)); INSERT INTO menus (menu_id,menu_name,type,price) VALUES (1,'Quinoa Salad','vegetarian',9.99),(2,'Margherita Pizza','non-vegetarian',12.99),(3,'Chickpea Curry','vegetarian',10.99),(5,'Vegan Burger','vegan',11.99),(6,'Vegan Ice Cr... | SELECT COUNT(*) FROM menus WHERE price < 5.00; |
What is the total number of ground vehicles sold by Lockheed Martin in 2020? | CREATE TABLE military_sales (equipment_type VARCHAR(20),manufacturer VARCHAR(20),year INT,quantity INT); INSERT INTO military_sales (equipment_type,manufacturer,year,quantity) VALUES ('Ground Vehicles','Lockheed Martin',2020,1200); | SELECT SUM(quantity) FROM military_sales WHERE equipment_type = 'Ground Vehicles' AND manufacturer = 'Lockheed Martin' AND year = 2020; |
What is the average productivity score for workers in the 'extraction' site?' | CREATE TABLE productivity (id INT,site TEXT,worker INT,score INT); INSERT INTO productivity (id,site,worker,score) VALUES (1,'extraction',1,90),(2,'extraction',2,95),(3,'drilling',1,85); | SELECT AVG(score) FROM productivity WHERE site = 'extraction'; |
What is the percentage of workers who identify as female or male in each department, including the total number of workers in each department? | CREATE TABLE department (dept_id INT,dept_name VARCHAR(50),worker_id INT); INSERT INTO department (dept_id,dept_name,worker_id) VALUES (1,'Mining',1),(1,'Mining',5),(2,'Engineering',2); CREATE TABLE worker_demographics (worker_id INT,worker_gender VARCHAR(10)); INSERT INTO worker_demographics (worker_id,worker_gender) ... | SELECT dept_name, worker_gender, COUNT(*) as count, COUNT(*) * 100.0 / (SELECT COUNT(*) FROM department d JOIN worker_demographics w ON d.worker_id = w.worker_id) as percentage, (SELECT COUNT(*) FROM department d JOIN worker_demographics w ON d.worker_id = w.worker_id) as total FROM department d JOIN worker_demographic... |
What is the average number of words in news articles in the "news_articles" table written by female authors? | CREATE TABLE news_articles (id INT,title VARCHAR(100),author_id INT,word_count INT,author_gender VARCHAR(10)); INSERT INTO news_articles (id,title,author_id,word_count,author_gender) VALUES (1,'News Article 1',1,500,'Female'),(2,'News Article 2',2,700,'Male'); | SELECT AVG(word_count) FROM news_articles WHERE author_gender = 'Female'; |
What is the average word count for articles published in the 'news' schema, grouped by author? | CREATE TABLE news.articles (article_id INT,title VARCHAR(100),author VARCHAR(100),word_count INT); INSERT INTO news.articles (article_id,title,author,word_count) VALUES (1,'Article 1','John Doe',500),(2,'Article 2','Jane Doe',600),(3,'Article 3','John Doe',700); | SELECT author, AVG(word_count) FROM news.articles GROUP BY author; |
What is the total number of news articles published per month in 2021, grouped by their respective categories? | CREATE TABLE news_articles (article_id INT,pub_date DATE,category VARCHAR(255)); INSERT INTO news_articles (article_id,pub_date,category) VALUES (1,'2021-01-01','Politics'),(2,'2021-01-10','Sports'),(3,'2021-03-15','Entertainment'); | SELECT MONTH(pub_date) AS month, category, COUNT(*) AS total FROM news_articles WHERE YEAR(pub_date) = 2021 GROUP BY month, category; |
What is the sum of donations and the number of volunteers for organizations that have more than 2 volunteers? | CREATE TABLE Organization (OrgID INT,Name VARCHAR(255)); CREATE TABLE Volunteer (VolID INT,OrgID INT,Name VARCHAR(255)); CREATE TABLE Donation (DonID INT,OrgID INT,Amount DECIMAL(10,2)); INSERT INTO Organization VALUES (1,'Greenpeace'),(2,'Red Cross'),(3,'Wildlife Fund'); INSERT INTO Volunteer VALUES (1,1,'John'),(2,1,... | SELECT o.OrgID, SUM(d.Amount) as TotalDonations, COUNT(v.VolID) as TotalVolunteers FROM Organization o LEFT JOIN Volunteer v ON o.OrgID = v.OrgID LEFT JOIN Donation d ON o.OrgID = d.OrgID WHERE (SELECT COUNT(*) FROM Volunteer WHERE Volunteer.OrgID = o.OrgID) > 2 GROUP BY o.OrgID; |
What is the maximum donation amount for each organization in the 'Donations' and 'Organizations' tables? | CREATE TABLE Donations (donation_id INT,org_id INT,donation_amount DECIMAL(10,2)); | SELECT O.name, MAX(D.donation_amount) FROM Donations D INNER JOIN Organizations O ON D.org_id = O.org_id GROUP BY O.name; |
What is the total donation amount in 2022 by donors located in the Middle East or North Africa? | CREATE TABLE Donors (DonorID int,DonorType varchar(50),Country varchar(50),AmountDonated numeric(18,2),DonationDate date); INSERT INTO Donors (DonorID,DonorType,Country,AmountDonated,DonationDate) VALUES (1,'Organization','Egypt',10000,'2022-01-01'),(2,'Individual','Saudi Arabia',5000,'2022-02-01'),(3,'Organization','I... | SELECT SUM(AmountDonated) FROM Donors WHERE DonorType = 'Organization' AND (Country LIKE 'Middle East%' OR Country LIKE 'North Africa%') AND YEAR(DonationDate) = 2022; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.