instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
How many cases were opened in 2020? | CREATE TABLE CaseDates (CaseID INT,OpenDate DATE); INSERT INTO CaseDates (CaseID,OpenDate) VALUES (1,'2020-01-01'),(2,'2019-12-31'),(3,'2020-03-15'); | SELECT COUNT(*) FROM CaseDates WHERE YEAR(OpenDate) = 2020; |
Which suppliers have provided raw materials for the production of chemicals with high environmental impact? | CREATE TABLE suppliers (id INT,name TEXT); INSERT INTO suppliers (id,name) VALUES (1,'Supplier1'),(2,'Supplier2'),(3,'Supplier3'); CREATE TABLE chemicals (id INT,name TEXT,environmental_impact INT); INSERT INTO chemicals (id,name,environmental_impact) VALUES (1,'ChemA',10),(2,'ChemB',20),(3,'ChemC',15); CREATE TABLE raw_materials (chemical_id INT,supplier_id INT); INSERT INTO raw_materials (chemical_id,supplier_id) VALUES (1,1),(1,2),(2,3),(3,1); | SELECT s.name FROM suppliers s INNER JOIN raw_materials rm ON s.id = rm.supplier_id INNER JOIN chemicals c ON rm.chemical_id = c.id WHERE c.environmental_impact > 10; |
What is the total funding allocated for climate adaptation in 'Europe'? | CREATE TABLE climate_funding (id INT,allocation FLOAT,initiative_type TEXT,region_id INT); CREATE TABLE regions (id INT,region TEXT); INSERT INTO climate_funding (id,allocation,initiative_type,region_id) VALUES (1,500000.00,'Mitigation',1),(2,750000.00,'Adaptation',2),(3,300000.00,'Communication',1); INSERT INTO regions (id,region) VALUES (1,'Americas'),(2,'Europe'),(3,'Asia'); | SELECT SUM(allocation) FROM climate_funding INNER JOIN regions ON climate_funding.region_id = regions.id WHERE regions.region = 'Europe' AND climate_funding.initiative_type = 'Adaptation'; |
What are the top 3 countries with the highest R&D expenditures in 2020? | CREATE TABLE rd_expenditures (country VARCHAR(50),year INT,amount FLOAT); INSERT INTO rd_expenditures (country,year,amount) VALUES ('USA',2020,70000000),('China',2020,40000000),('Germany',2020,30000000); | SELECT country, SUM(amount) as total_expenditure FROM rd_expenditures WHERE year = 2020 GROUP BY country ORDER BY total_expenditure DESC LIMIT 3; |
What is the most common type of cancer in Australia? | CREATE TABLE cancer_data (id INT,country VARCHAR(20),type VARCHAR(20),cases INT); INSERT INTO cancer_data (id,country,type,cases) VALUES (1,'Australia','Breast',15000),(2,'Australia','Lung',12000),(3,'Australia','Colon',10000); | SELECT type, cases FROM cancer_data WHERE country = 'Australia' ORDER BY cases DESC LIMIT 1; |
Count the number of startups founded by underrepresented minorities in the healthcare industry | CREATE TABLE company (id INT,name TEXT,industry TEXT,founding_year INT,founder_gender TEXT,founder_race TEXT); INSERT INTO company (id,name,industry,founding_year,founder_gender,founder_race) VALUES (1,'Diverse Health','Healthcare',2015,'Female','African American'); INSERT INTO company (id,name,industry,founding_year,founder_gender,founder_race) VALUES (2,'Careforce','Healthcare',2020,'Male','Latino'); | SELECT COUNT(*) FROM company WHERE industry = 'Healthcare' AND (founder_gender = 'Female' AND founder_race = 'African American') OR (founder_gender = 'Male' AND founder_race = 'Latino') |
What is the total production of 'wheat' and 'rice' by small farmers in 'Asia'? | CREATE TABLE farmers (id INT,name TEXT,country TEXT); INSERT INTO farmers (id,name,country) VALUES (1,'John','India'),(2,'Jane','China'),(3,'Alice','Japan'); CREATE TABLE crops (id INT,farmer_id INT,name TEXT,yield INT); INSERT INTO crops (id,farmer_id,name,yield) VALUES (1,1,'wheat',500),(2,1,'rice',800),(3,2,'wheat',700),(4,2,'rice',900),(5,3,'wheat',600),(6,3,'rice',1000); | SELECT SUM(yield) FROM crops JOIN farmers ON crops.farmer_id = farmers.id WHERE farmers.country = 'Asia' AND crops.name IN ('wheat', 'rice'); |
What marine species have been observed in both the Arctic and Southern Oceans? | CREATE TABLE oceans (ocean_id INT,name VARCHAR(50)); CREATE TABLE species (species_id INT,name VARCHAR(50),ocean_id INT); INSERT INTO oceans VALUES (1,'Arctic'),(2,'Antarctic (Southern)'),(3,'Indian'); INSERT INTO species VALUES (1,'Polar Bear',1),(2,'Penguin',2),(3,'Seal',2),(4,'Clownfish',3),(5,'Shark',1),(6,'Dolphin',2),(7,'Turtle',3),(8,'Squid',2),(9,'Polar Bear',2); | SELECT s.name FROM species s WHERE s.ocean_id IN (1, 2) GROUP BY s.name HAVING COUNT(DISTINCT s.ocean_id) = 2; |
Find the minimum transaction amount for 'ETH'. | CREATE TABLE digital_assets (asset_id varchar(10),asset_name varchar(10)); INSERT INTO digital_assets (asset_id,asset_name) VALUES ('ETH','Ethereum'),('BTC','Bitcoin'); CREATE TABLE transactions (transaction_id serial,asset_id varchar(10),transaction_amount numeric); INSERT INTO transactions (asset_id,transaction_amount) VALUES ('ETH',120),('ETH',230),('BTC',500),('ETH',100); | SELECT MIN(transaction_amount) FROM transactions WHERE asset_id = 'ETH'; |
What is the average carbon sequestration per hectare for each region? | CREATE TABLE carbon_sequestration(region VARCHAR(255),sequestration FLOAT,area INT); INSERT INTO carbon_sequestration(region,sequestration,area) VALUES ('North',5.6,1000),('South',4.8,1500),('East',6.2,1200),('West',5.1,1800); | SELECT region, AVG(sequestration) FROM carbon_sequestration; |
List all ingredients used in products from a specific brand. | CREATE TABLE ingredients (product_id INT,brand_id INT,ingredient VARCHAR(50)); INSERT INTO ingredients (product_id,brand_id,ingredient) VALUES (1,1,'Water'),(1,1,'Glycerin'),(2,2,'Aqua'),(2,2,'Parabens'),(3,3,'Shea Butter'),(3,3,'Essential Oils'),(4,4,'Petroleum'),(4,4,'Mineral Oil'),(5,5,'Jojoba Oil'),(5,5,'Vitamin E'); CREATE TABLE brands (brand_id INT,brand_name VARCHAR(50)); INSERT INTO brands (brand_id,brand_name) VALUES (1,'Lush'),(2,'The Body Shop'),(3,'Estée Lauder'),(4,'Urban Decay'),(5,'Maybelline'); | SELECT ingredient FROM ingredients INNER JOIN brands ON ingredients.brand_id = brands.brand_id WHERE brand_name = 'Lush'; |
Delete all skincare products with 'Sensitive' in their name | CREATE TABLE products (product_id INT,product_name VARCHAR(255),category VARCHAR(255),price DECIMAL(10,2)); INSERT INTO products (product_id,product_name,category,price) VALUES (1,'Sensitive Skin Cleanser','Skincare',17.99),(2,'Gentle Makeup Remover','Skincare',12.99),(3,'Nourishing Sensitive Face Cream','Skincare',22.99); | DELETE FROM products WHERE category = 'Skincare' AND product_name LIKE '%Sensitive%'; |
How many new cosmetic products were launched by each brand in the last 12 months, ordered by the number of new products in descending order? | CREATE TABLE products (product_id INT,brand_id INT,launch_date DATE); INSERT INTO products (product_id,brand_id,launch_date) VALUES (1,1,'2022-01-01'),(2,1,'2021-06-15'),(3,2,'2022-03-01'),(4,2,'2021-12-31'),(5,3,'2021-09-01'); CREATE TABLE brands (brand_id INT,name VARCHAR(255)); INSERT INTO brands (brand_id,name) VALUES (1,'BrandA'),(2,'BrandB'),(3,'BrandC'); | SELECT brands.name, COUNT(*) as num_new_products FROM products JOIN brands ON products.brand_id = brands.brand_id WHERE products.launch_date >= DATEADD(year, -1, CURRENT_DATE) GROUP BY brands.name ORDER BY num_new_products DESC; |
What was the average response time for fire incidents in January 2022? | CREATE TABLE fire_incidents (id INT,incident_date DATE,response_time INT); INSERT INTO fire_incidents (id,incident_date,response_time) VALUES (1,'2022-01-01',34),(2,'2022-01-02',28),(3,'2022-01-03',45); | SELECT AVG(response_time) FROM fire_incidents WHERE incident_date BETWEEN '2022-01-01' AND '2022-01-31'; |
What is the average attendance at events organized by cultural institutions in France? | CREATE TABLE cultural_events (id INT,name VARCHAR(255),date DATE,country VARCHAR(255),attendance INT); INSERT INTO cultural_events (id,name,date,country,attendance) VALUES (1,'Art Exhibition','2020-02-01','France',1500),(2,'Theatre Performance','2020-03-15','France',800); | SELECT AVG(attendance) FROM cultural_events WHERE country = 'France'; |
Provide the number of threat intelligence reports generated per month for the past year, for the Asia-Pacific region. | CREATE TABLE threat_intelligence (report_id INT,report_date DATE,region TEXT); INSERT INTO threat_intelligence (report_id,report_date,region) VALUES (1,'2022-01-15','Asia-Pacific'),(2,'2022-03-10','Asia-Pacific'),(3,'2021-12-25','Asia-Pacific'); | SELECT DATE_FORMAT(report_date, '%Y-%m') as month, COUNT(*) as reports FROM threat_intelligence WHERE region = 'Asia-Pacific' AND report_date >= '2021-01-01' GROUP BY month; |
What is the average transaction amount in EUR by city for the month of May 2022? | CREATE TABLE customers (customer_id INT,customer_city VARCHAR(30)); CREATE TABLE transactions (transaction_id INT,customer_id INT,transaction_amount DECIMAL(10,2),transaction_date DATE,transaction_currency VARCHAR(3)); | SELECT customer_city, AVG(transaction_amount) as average_transaction_amount FROM customers JOIN transactions ON customers.customer_id = transactions.customer_id WHERE transaction_date BETWEEN '2022-05-01' AND '2022-05-31' AND transaction_currency = 'EUR' GROUP BY customer_city; |
What is the total transaction value for each month of the year 2021? | CREATE TABLE transactions (transaction_id INT,transaction_date DATE,transaction_category VARCHAR(255),transaction_value DECIMAL(10,2)); INSERT INTO transactions (transaction_id,transaction_date,transaction_category,transaction_value) VALUES (1,'2021-01-02','Food',50.00),(2,'2021-01-05','Electronics',300.00),(3,'2021-02-10','Clothing',150.00); | SELECT YEAR(transaction_date) as year, MONTH(transaction_date) as month, SUM(transaction_value) as total_value FROM transactions WHERE transaction_date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY year, month; |
List the total number of workers in each department across all manufacturing plants | CREATE TABLE departments (department_id INT,department_name VARCHAR(255),plant_id INT); INSERT INTO departments (department_id,department_name,plant_id) VALUES (1,'Production',1),(2,'Quality Control',1),(3,'Engineering',1),(4,'Administration',1),(1,'Production',2),(2,'Quality Control',2),(3,'Engineering',2),(4,'Administration',2); CREATE TABLE workers (worker_id INT,worker_name VARCHAR(255),department_id INT); INSERT INTO workers (worker_id,worker_name,department_id) VALUES (1,'John Smith',1),(2,'Jane Doe',1),(3,'Bob Johnson',2),(4,'Alice Williams',2),(5,'Charlie Brown',3),(6,'Sally Green',4); | SELECT d.department_name, COUNT(w.worker_id) as worker_count FROM departments d JOIN workers w ON d.department_id = w.department_id GROUP BY d.department_name; |
What is the average salary of 'engineer' workers in each factory? | CREATE TABLE factories (factory_id INT,factory_name VARCHAR(20)); INSERT INTO factories VALUES (1,'Factory X'),(2,'Factory Y'),(3,'Factory Z'); CREATE TABLE roles (role_id INT,role_name VARCHAR(20)); INSERT INTO roles VALUES (1,'engineer'),(2,'manager'),(3,'assistant'); CREATE TABLE workers (worker_id INT,factory_id INT,role_id INT,salary DECIMAL(5,2)); INSERT INTO workers VALUES (1,1,1,50000.00),(2,1,2,70000.00),(3,2,1,55000.00),(4,2,3,40000.00),(5,3,1,60000.00); | SELECT f.factory_name, AVG(salary) FROM workers w INNER JOIN factories f ON w.factory_id = f.factory_id INNER JOIN roles r ON w.role_id = r.role_id WHERE r.role_name = 'engineer' GROUP BY f.factory_name; |
How many healthcare workers are there in the "rural_healthcenters" table? | CREATE TABLE rural_healthcenters (id INT,name TEXT,location TEXT,position TEXT); INSERT INTO rural_healthcenters (id,name,location,position) VALUES (1,'Healthcenter A','Rural Area 1','Doctor'),(2,'Healthcenter B','Rural Area 2','Nurse'),(3,'Healthcenter C','Rural Area 3','Admin'); | SELECT COUNT(*) FROM rural_healthcenters; |
What is the total number of medical facilities in rural Vietnam? | CREATE TABLE medical_facilities (id INT,name TEXT,location TEXT); INSERT INTO medical_facilities (id,name,location) VALUES (1,'Facility A','Rural'); | SELECT COUNT(*) FROM medical_facilities WHERE location = 'Rural'; |
Calculate the number of donations to human rights organizations in the USA. | CREATE TABLE organization (org_id INT PRIMARY KEY,name VARCHAR(255),industry VARCHAR(255),country VARCHAR(255)); INSERT INTO organization (org_id,name,industry,country) VALUES (5,'Human Rights USA','Nonprofit','USA'); | SELECT COUNT(*) FROM (SELECT donation.donation_id FROM donation JOIN organization ON donation.org_id = organization.org_id WHERE organization.country = 'USA' AND organization.industry = 'Nonprofit' AND organization.name = 'Human Rights USA') AS donation_subquery; |
What is the average annual budget for military technology in Europe, and how has it changed over the past 5 years? | CREATE TABLE military_budget (id INT,year INT,country TEXT,budget FLOAT); INSERT INTO military_budget (id,year,country,budget) VALUES (1,2018,'France',50000000),(2,2018,'Germany',60000000),(3,2018,'UK',70000000),(4,2019,'France',55000000),(5,2019,'Germany',65000000),(6,2019,'UK',75000000),(7,2020,'France',60000000),(8,2020,'Germany',70000000),(9,2020,'UK',80000000); | SELECT AVG(budget) as avg_annual_budget, year FROM military_budget WHERE country IN ('France', 'Germany', 'UK') GROUP BY year; |
What is the number of intelligence personnel with experience greater than 5 years in the 'Intelligence_Personnel' table? | CREATE TABLE Intelligence_Personnel (id INT,name VARCHAR(50),role VARCHAR(50),age INT,experience INT); INSERT INTO Intelligence_Personnel (id,name,role,age,experience) VALUES (1,'Charlie Brown','Analyst',30,5); INSERT INTO Intelligence_Personnel (id,name,role,age,experience) VALUES (2,'Diana Ross','Agent',35,10); | SELECT COUNT(*) FROM Intelligence_Personnel WHERE experience > 5; |
What is the total number of volunteers and donors who are not from the United States or Canada? | CREATE TABLE Volunteers (id INT,name TEXT,country TEXT); INSERT INTO Volunteers (id,name,country) VALUES (1,'John Doe','USA'),(2,'Jane Smith','Canada'); CREATE TABLE Donors (id INT,name TEXT,country TEXT); INSERT INTO Donors (id,name,country) VALUES (1,'Alice Johnson','USA'),(2,'Bob Brown','Canada'); CREATE TABLE VolunteersAndDonors (id INT,name TEXT,country TEXT); INSERT INTO VolunteersAndDonors (id,name,country) SELECT * FROM Volunteers UNION ALL SELECT * FROM Donors; | SELECT COUNT(*) FROM VolunteersAndDonors WHERE country NOT IN ('USA', 'Canada'); |
List all employees who have not completed any training programs, along with their department and position. | CREATE TABLE Employees (EmployeeID int,FirstName varchar(50),LastName varchar(50),Department varchar(50),Position varchar(50)); CREATE TABLE TrainingPrograms (TrainingID int,EmployeeID int,ProgramName varchar(50)); CREATE TABLE EmployeeTrainings (TrainingID int,EmployeeID int,CompletionDate date); | SELECT e.EmployeeID, e.FirstName, e.LastName, e.Department, e.Position FROM Employees e LEFT JOIN TrainingPrograms tp ON e.EmployeeID = tp.EmployeeID LEFT JOIN EmployeeTrainings et ON tp.TrainingID = et.TrainingID AND e.EmployeeID = et.EmployeeID WHERE et.CompletionDate IS NULL; |
Insert a new record into the 'energy_storage' table for a flow battery with 5 MWh capacity, located in 'Quebec' | CREATE TABLE energy_storage (id INT PRIMARY KEY,technology VARCHAR(255),capacity FLOAT,location VARCHAR(255)); | INSERT INTO energy_storage (technology, capacity, location) VALUES ('flow', 5, 'Quebec'); |
Calculate the total production from wells in the North Sea | CREATE TABLE wells (id INT,well_name VARCHAR(100),location VARCHAR(50),status VARCHAR(20),production FLOAT); INSERT INTO wells VALUES (1,'Well A','North Sea','Producing',1000.5); INSERT INTO wells VALUES (2,'Well B','Gulf of Mexico','Abandoned',1200.3); INSERT INTO wells VALUES (3,'Well C','Gulf of Mexico','Producing',1500.2); INSERT INTO wells VALUES (4,'Well D','North Sea','Producing',2000.7); INSERT INTO wells VALUES (5,'Well E','North Sea','Idle',0); | SELECT SUM(production) FROM wells WHERE location = 'North Sea'; |
How many offshore wells were drilled in the Gulf of Mexico in each year since 2016? | CREATE TABLE OffshoreWells (WellName TEXT,DrillDate DATE,Location TEXT); INSERT INTO OffshoreWells (WellName,DrillDate,Location) VALUES ('Well1','2016-05-01','Gulf of Mexico'),('Well2','2017-07-15','Gulf of Mexico'),('Well3','2018-03-28','Gulf of Mexico'); | SELECT COUNT(*) AS WellCount, EXTRACT(YEAR FROM DrillDate) AS Year FROM OffshoreWells WHERE Location = 'Gulf of Mexico' GROUP BY Year; |
Which football teams have the highest number of wins in the 2021-2022 season? | CREATE TABLE football_teams (team_id INT,team_name VARCHAR(50),wins INT); INSERT INTO football_teams (team_id,team_name,wins) VALUES (1,'Barcelona',25),(2,'Real Madrid',27),(3,'Manchester United',22); | SELECT team_name, wins FROM football_teams ORDER BY wins DESC LIMIT 2; |
Delete records in the supplier_ethics table where the country is 'Bangladesh' and certification is not 'Fair Trade' | CREATE TABLE supplier_ethics (id INT PRIMARY KEY,name VARCHAR(255),country VARCHAR(255),certification VARCHAR(255)); INSERT INTO supplier_ethics (id,name,country,certification) VALUES (1,'Supplier A','Bangladesh','Fair Trade'),(2,'Supplier B','Bangladesh','SA8000'),(3,'Supplier C','India','Fair Trade'); | DELETE FROM supplier_ethics WHERE country = 'Bangladesh' AND certification != 'Fair Trade'; |
Delete posts older than 30 days | CREATE TABLE posts (id INT PRIMARY KEY,user_id INT,title TEXT,created_at DATETIME,FOREIGN KEY (user_id) REFERENCES users(id)); | DELETE FROM posts WHERE created_at < NOW() - INTERVAL 30 DAY; |
List all programs and their total budget | CREATE TABLE programs (id INT,name VARCHAR(50),budget DECIMAL(10,2)); INSERT INTO programs (id,name,budget) VALUES (1,'Education',50000.00); INSERT INTO programs (id,name,budget) VALUES (2,'Healthcare',75000.00); | SELECT name, SUM(budget) as total_budget FROM programs GROUP BY name; |
What is the average price of free-range eggs per store? | CREATE TABLE Stores (store_id INT,store_name VARCHAR(255)); CREATE TABLE Products (product_id INT,product_name VARCHAR(255),is_free_range BOOLEAN,price INT); CREATE TABLE Inventory (store_id INT,product_id INT,quantity INT); | SELECT s.store_name, AVG(p.price) as avg_price FROM Inventory i JOIN Stores s ON i.store_id = s.store_id JOIN Products p ON i.product_id = p.product_id WHERE p.is_free_range = TRUE AND p.product_category = 'egg' GROUP BY s.store_name; |
What is the average delivery time for shipments to the Southeast region, grouped by shipment type? | CREATE SCHEMA IF NOT EXISTS logistics;CREATE TABLE IF NOT EXISTS shipments (shipment_id INT,region VARCHAR(20),shipment_type VARCHAR(20),delivery_time INT);INSERT INTO shipments (shipment_id,region,shipment_type,delivery_time) VALUES (1,'Southeast','domestic',3),(2,'Northeast','international',7),(3,'Southeast','domestic',2); | SELECT shipment_type, AVG(delivery_time) FROM logistics.shipments WHERE region = 'Southeast' GROUP BY shipment_type; |
What is the total quantity of items shipped per warehouse to each country? | CREATE TABLE Shipments (id INT,WarehouseId INT,Product VARCHAR(50),Quantity INT,Destination VARCHAR(50),ShippedDate DATE); INSERT INTO Shipments (id,WarehouseId,Product,Quantity,Destination,ShippedDate) VALUES (1,1,'Laptop',50,'Toronto,Canada','2022-01-01'); INSERT INTO Shipments (id,WarehouseId,Product,Quantity,Destination,ShippedDate) VALUES (2,1,'Monitor',75,'Sydney,Australia','2022-01-05'); INSERT INTO Shipments (id,WarehouseId,Product,Quantity,Destination,ShippedDate) VALUES (3,2,'Keyboard',100,'Berlin,Germany','2022-01-07'); | SELECT WarehouseId, Destination, SUM(Quantity) AS TotalQuantity FROM Shipments GROUP BY WarehouseId, Destination; |
What is the total amount of budget allocated for each sector by the state government for the year 2021? | CREATE TABLE sector (id INT,name VARCHAR); INSERT INTO sector (id,name) VALUES (1,'Education'),(2,'Health'),(3,'Transport'),(4,'Housing'); CREATE TABLE budget (id INT,sector_id INT,amount INT,year INT); INSERT INTO budget (id,sector_id,amount,year) VALUES (1,1,5000000,2021),(2,2,7000000,2021),(3,3,9000000,2021),(4,4,6000000,2021); | SELECT sector_id, SUM(amount) as total_budget FROM budget WHERE year = 2021 GROUP BY sector_id; |
Create a view for health equity metrics | CREATE TABLE health_equity (id INT PRIMARY KEY,state VARCHAR(2),year INT,disparity_rate FLOAT); | CREATE OR REPLACE VIEW health_equity_view AS SELECT * FROM health_equity; |
List the number of virtual tours in India and Argentina. | CREATE TABLE virtual_tours (tour_id INT,location VARCHAR(255),type VARCHAR(255)); INSERT INTO virtual_tours (tour_id,location,type) VALUES (1,'India Virtual Tour','virtual'),(2,'Argentina Virtual Tour','virtual'); | SELECT COUNT(*) FROM virtual_tours WHERE location IN ('India', 'Argentina'); |
What is the total number of sustainable tour packages sold by each vendor, including virtual packages? | CREATE TABLE Vendors (VendorID INT,VendorName VARCHAR(50)); INSERT INTO Vendors (VendorID,VendorName) VALUES (1,'GreenVacations'),(2,'EcoTours'),(3,'SustainableJourneys'); CREATE TABLE Packages (PackageID INT,VendorID INT,PackageType VARCHAR(20),Sales INT); INSERT INTO Packages (PackageID,VendorID,PackageType,Sales) VALUES (1,1,'Sustainable',500),(2,1,'Virtual',300),(3,2,'Sustainable',700),(4,2,'Virtual',600),(5,3,'Sustainable',800),(6,3,'Virtual',400),(7,1,'Sustainable',400),(8,2,'Sustainable',600),(9,3,'Sustainable',700),(10,1,'Virtual',500),(11,2,'Virtual',700),(12,3,'Virtual',600); | SELECT V.VendorName, SUM(P.Sales) as TotalSales FROM Vendors V INNER JOIN Packages P ON V.VendorID = P.VendorID GROUP BY V.VendorName; |
Maximum number of visitors for Impressionist exhibitions in London? | CREATE TABLE Exhibitions (id INT,exhibition_name VARCHAR(50),location VARCHAR(30),visitors INT,art_period VARCHAR(20),start_date DATE); INSERT INTO Exhibitions (id,exhibition_name,location,visitors,art_period,start_date) VALUES (1,'Exhibition1','London',800,'Impressionist','2018-01-01'); | SELECT MAX(visitors) FROM Exhibitions WHERE art_period = 'Impressionist' AND location = 'London'; |
Insert new records into the 'officers' table with officer_id 4, 5, first_name 'James', 'Karen', last_name 'Davis' | CREATE TABLE officers (officer_id INT,first_name VARCHAR(20),last_name VARCHAR(20)); | INSERT INTO officers (officer_id, first_name, last_name) VALUES (4, 'James', 'Davis'), (5, 'Karen', 'Davis'); |
Identify the number of whale sightings in the Arctic Ocean by year. | CREATE TABLE WhaleSightings (id INT,year INT,location VARCHAR(255)); INSERT INTO WhaleSightings (id,year,location) VALUES (1,2020,'Arctic Ocean'); INSERT INTO WhaleSightings (id,year,location) VALUES (2,2019,'Arctic Ocean'); | SELECT year, COUNT(*) FROM WhaleSightings WHERE location = 'Arctic Ocean' GROUP BY year; |
What is the total quantity of a specific dish sold on a given date? | CREATE TABLE dishes (id INT,name TEXT,type TEXT,price DECIMAL,inventory INT); INSERT INTO dishes (id,name,type,price,inventory) VALUES (1,'Pizza Margherita','Veg',7.50,50),(2,'Chicken Alfredo','Non-Veg',12.00,30),(3,'Veggie Delight Sandwich','Veg',6.50,75); CREATE TABLE sales (id INT,dish_id INT,quantity INT,date DATE); INSERT INTO sales (id,dish_id,quantity,date) VALUES (1,2,3,'2022-01-01'),(2,1,2,'2022-01-02'),(3,3,1,'2022-01-03'); | SELECT SUM(quantity) as total_quantity_sold FROM sales WHERE dish_id = 1 AND date = '2022-01-02'; |
What is the total quantity of ingredients sourced from local farmers? | CREATE TABLE suppliers (supplier_id INT,supplier_name VARCHAR(50),location VARCHAR(50)); INSERT INTO suppliers VALUES (1,'Green Acres','Local'),(2,'Sunrise Farms','Out of State'),(3,'Farm Fresh','Local'); CREATE TABLE inventory (ingredient_id INT,ingredient_name VARCHAR(50),supplier_id INT,quantity INT); INSERT INTO inventory VALUES (1,'Tomatoes',1,100),(2,'Chicken',2,50),(3,'Lettuce',3,80); | SELECT SUM(inventory.quantity) FROM inventory INNER JOIN suppliers ON inventory.supplier_id = suppliers.supplier_id WHERE suppliers.location = 'Local'; |
What is the minimum production rate of zinc mines in India? | CREATE TABLE zinc_mines (id INT,name TEXT,location TEXT,production_rate INT); INSERT INTO zinc_mines (id,name,location,production_rate) VALUES (1,'Rampura Agucha','India',5000),(2,'Zawar','India',4000); | SELECT MIN(production_rate) FROM zinc_mines WHERE location = 'India'; |
What is the maximum data usage for prepaid mobile customers in the Midwest region in the past month? | CREATE TABLE usage(customer_id INT,data_usage INT,usage_date DATE); CREATE TABLE customers(id INT,type VARCHAR(10),region VARCHAR(10)); | SELECT MAX(usage.data_usage) FROM usage JOIN customers ON usage.customer_id = customers.id WHERE customers.type = 'prepaid' AND customers.region = 'Midwest' AND usage.usage_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH); |
Which mobile subscribers have not made a call in the last 60 days? | CREATE TABLE mobile_subscribers (subscriber_id INT,last_call_date DATETIME); INSERT INTO mobile_subscribers (subscriber_id,last_call_date) VALUES (1,'2022-01-15'),(2,'2022-02-03'),(3,NULL),(4,'2022-01-20'),(5,'2022-03-05'); | SELECT subscriber_id FROM mobile_subscribers WHERE last_call_date IS NULL OR last_call_date < DATE_SUB(CURDATE(), INTERVAL 60 DAY); |
What is the total revenue for each concert by city, ordered by total revenue? | CREATE TABLE Concerts (ConcertID INT,Artist VARCHAR(50),City VARCHAR(50),Revenue DECIMAL(10,2)); INSERT INTO Concerts (ConcertID,Artist,City,Revenue) VALUES (1,'Taylor Swift','Los Angeles',500000.00),(2,'BTS','New York',750000.00),(3,'Adele','London',600000.00); | SELECT City, SUM(Revenue) as TotalRevenue FROM Concerts GROUP BY City ORDER BY TotalRevenue DESC; |
Create a table for storing volunteer information and insert a record for a volunteer. | CREATE TABLE volunteers (id INT,name VARCHAR(255),hours DECIMAL(10,2)); | INSERT INTO volunteers (id, name, hours) VALUES (1, 'Sarah Jones', 50.50); |
How many unique donors have contributed to Canadian non-profit organizations since January 1, 2020? | CREATE TABLE donors_canada (id INT,donor_name TEXT,country TEXT,donation_amount DECIMAL,donation_date DATE); INSERT INTO donors_canada (id,donor_name,country,donation_amount,donation_date) VALUES (1,'Alexander Smith','Canada',100.00,'2020-08-03'); INSERT INTO donors_canada (id,donor_name,country,donation_amount,donation_date) VALUES (2,'Sophia Johnson','Canada',75.00,'2020-11-12'); | SELECT COUNT(DISTINCT donor_name) FROM donors_canada WHERE country = 'Canada' AND donation_date >= '2020-01-01'; |
Which countries have the highest ocean acidification levels in the Southern Ocean? | CREATE TABLE southern_ocean (id INT,name VARCHAR(100),region VARCHAR(50)); CREATE TABLE country_acidification (id INT,country VARCHAR(100),acidification_level FLOAT,ocean_id INT); INSERT INTO southern_ocean (id,name,region) VALUES (1,'Southern Ocean','Southern'); INSERT INTO country_acidification (id,country,acidification_level,ocean_id) VALUES (1,'Argentina',9.8,1),(2,'Chile',9.6,1); | SELECT country, acidification_level FROM country_acidification ca INNER JOIN southern_ocean s ON ca.ocean_id = s.id ORDER BY acidification_level DESC; |
List the top 3 recipient countries with the highest total donation amounts in the past year? | CREATE TABLE Donations (DonationID INT,DonationDate DATE,RecipientCountry VARCHAR(50),DonationAmount NUMERIC(15,2)); | SELECT RecipientCountry, SUM(DonationAmount) as TotalDonations FROM Donations WHERE DonationDate >= DATEADD(year, -1, CURRENT_TIMESTAMP) GROUP BY RecipientCountry ORDER BY TotalDonations DESC LIMIT 3; |
Display the top 10 players with the highest total playtime in 'player_stats' table | CREATE TABLE player_stats (player_id INT,player_name VARCHAR(255),game_name VARCHAR(255),total_playtime INT); | SELECT player_name, SUM(total_playtime) AS total_playtime FROM player_stats GROUP BY player_name ORDER BY total_playtime DESC LIMIT 10; |
What are the budget allocations for the top 2 most expensive public facilities in the state of California? | CREATE TABLE public_facilities (name TEXT,state TEXT,budget_allocation INT); INSERT INTO public_facilities (name,state,budget_allocation) VALUES ('Facility A','California',600000),('Facility B','California',550000),('Facility C','California',500000); | SELECT name, budget_allocation FROM public_facilities WHERE state = 'California' ORDER BY budget_allocation DESC LIMIT 2; |
What is the total number of public hospitals in cities with a population greater than 1 million? | CREATE TABLE City (id INT,name VARCHAR(50),population INT,num_hospitals INT); INSERT INTO City (id,name,population,num_hospitals) VALUES (1,'Mumbai',20411274,50); INSERT INTO City (id,name,population,num_hospitals) VALUES (2,'São Paulo',21846507,75); INSERT INTO City (id,name,population,num_hospitals) VALUES (3,'Seoul',9733509,35); | SELECT name, SUM(num_hospitals) as 'Total Public Hospitals' FROM City WHERE population > 1000000 GROUP BY name; |
Get the number of carbon offset programs implemented by year | CREATE TABLE carbon_offset_programs (program_id INT,program_name VARCHAR(255),start_year INT,end_year INT); | SELECT start_year, COUNT(*) as num_programs FROM carbon_offset_programs GROUP BY start_year ORDER BY start_year; |
Calculate the revenue for each restaurant, considering only transactions that occurred after a specific date (e.g., '2022-01-01'). | CREATE TABLE Restaurants (id INT,name VARCHAR(255),city VARCHAR(255),revenue FLOAT); CREATE TABLE Transactions (id INT,rest_id INT,date DATE,amount FLOAT); | SELECT R.name, SUM(T.amount) as revenue FROM Restaurants R JOIN Transactions T ON R.id = T.rest_id WHERE T.date > '2022-01-01' GROUP BY R.name; |
What is the daily revenue trend for all restaurants? | CREATE TABLE daily_revenue (date DATE,restaurant_id INT,revenue FLOAT); INSERT INTO daily_revenue VALUES ('2021-01-01',1,500),('2021-01-02',1,700),('2021-01-03',1,600),('2021-01-01',2,800),('2021-01-02',2,900),('2021-01-03',2,700); | SELECT date, restaurant_id, revenue FROM daily_revenue; |
What is the total revenue generated by organic menu items in Seattle? | CREATE TABLE MenuItems (menu_item_id INT,menu_item VARCHAR(50),price INT,cost INT,location VARCHAR(50),organic BOOLEAN); INSERT INTO MenuItems (menu_item_id,menu_item,price,cost,location,organic) VALUES (1,'Grilled Chicken Salad',12,4,'Seattle',TRUE),(2,'Cheeseburger',8,3,'Seattle',FALSE),(3,'Veggie Burger',9,3,'Seattle',TRUE); | SELECT SUM(price - cost) AS total_revenue FROM MenuItems WHERE location = 'Seattle' AND organic = TRUE; |
Which menu items are served at all locations? | CREATE TABLE menu_items(menu_item VARCHAR(255),location VARCHAR(255)); INSERT INTO menu_items(menu_item,location) VALUES ('Burger','Location1'),('Pizza','Location2'),('Pasta','Location1'),('Salad','Location2'),('Burger','Location3'),('Pizza','Location3'); | SELECT menu_item FROM menu_items GROUP BY menu_item HAVING COUNT(DISTINCT location) = (SELECT COUNT(DISTINCT location) FROM menu_items); |
What is the total number of security incidents that occurred in the last month and were resolved within 24 hours? | create table incidents (id int,date date,resolved date,sector varchar(255)); insert into incidents values (1,'2022-01-01','2022-01-02','retail'); insert into incidents values (2,'2022-01-05','2022-01-06','retail'); insert into incidents values (3,'2022-01-10',null,'financial services'); insert into incidents values (4,'2022-02-01','2022-02-02','financial services'); insert into incidents values (5,'2022-07-01','2022-07-02','healthcare'); | SELECT COUNT(*) FROM incidents WHERE DATEDIFF(resolved, date) <= 1 AND date >= '2022-01-01' AND date < '2022-02-01'; |
Which cybersecurity policies were added or updated in the last month and apply to cloud infrastructure in the financial sector? | CREATE TABLE Policies (policy_id INT,policy_name VARCHAR(50),policy_date DATE,policy_category VARCHAR(50),policy_applies_to VARCHAR(50),policy_target_sector VARCHAR(50)); | SELECT policy_id, policy_name FROM Policies WHERE policy_category = 'cloud infrastructure' AND policy_target_sector = 'financial' AND (policy_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) AND CURRENT_DATE OR (policy_date < DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) AND EXISTS (SELECT * FROM Policies AS updated_policies WHERE updated_policies.policy_id = Policies.policy_id AND updated_policies.policy_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) AND CURRENT_DATE))); |
Find the maximum number of electric vehicles sold in a single month | CREATE TABLE Sales (SaleID INT,Month INT,Year INT,Electric BOOLEAN); INSERT INTO Sales (SaleID,Month,Year,Electric) VALUES (1,1,2020,true),(2,1,2020,false),(3,2,2020,true),(4,2,2020,true),(5,3,2020,false),(6,3,2020,false); | SELECT MAX(COUNT(*)) as MaxSales FROM Sales WHERE Electric = true GROUP BY Month, Year; |
How many autonomous cars were sold in 2020 and 2021 in the autonomous_vehicles table? | CREATE TABLE autonomous_vehicles (year INT,model VARCHAR(20),sales INT); INSERT INTO autonomous_vehicles (year,model,sales) VALUES (2020,'Model A',1000),(2021,'Model A',1200),(2020,'Model B',800),(2021,'Model B',1100); | SELECT SUM(sales) FROM autonomous_vehicles WHERE year IN (2020, 2021) AND model IN ('Model A', 'Model B'); |
What is the average safety rating achieved by electric vehicles at the Detroit Auto Show? | CREATE TABLE ElectricVehicleSafety (VehicleID INT,SafetyRating INT,Make TEXT,Model TEXT,ShowName TEXT); | SELECT AVG(SafetyRating) FROM ElectricVehicleSafety WHERE Make LIKE '%electric%' AND ShowName = 'Detroit Auto Show'; |
Calculate the total downtime (in hours) for 'VesselR' during its maintenance periods in Q2 of 2020. | CREATE TABLE Vessels (vessel_name VARCHAR(255)); INSERT INTO Vessels (vessel_name) VALUES ('VesselR'),('VesselS'); CREATE TABLE Maintenance (vessel_name VARCHAR(255),maintenance_start_date DATE,maintenance_end_date DATE); INSERT INTO Maintenance (vessel_name,maintenance_start_date,maintenance_end_date) VALUES ('VesselR','2020-04-10','2020-04-12'),('VesselR','2020-06-25','2020-06-28'),('VesselS','2020-08-01','2020-08-03'); | SELECT SUM(DATEDIFF(hour, maintenance_start_date, maintenance_end_date)) FROM Maintenance WHERE vessel_name = 'VesselR' AND maintenance_start_date BETWEEN '2020-04-01' AND '2020-06-30'; |
Count the number of vessels that have loaded cargo. | CREATE TABLE VesselCargo (VesselID INT,CargoID INT); INSERT INTO VesselCargo (VesselID,CargoID) VALUES (1,1),(2,2),(3,3),(4,NULL),(5,5); | SELECT COUNT(DISTINCT VesselID) FROM VesselCargo WHERE CargoID IS NOT NULL; |
Calculate the average usage_amount for the residential category in the water_usage table | CREATE TABLE water_usage (date DATE,usage_category VARCHAR(20),region VARCHAR(20),usage_amount INT); INSERT INTO water_usage (date,usage_category,region,usage_amount) VALUES ('2022-07-01','Residential','Northeast',15000),('2022-07-02','Industrial','Midwest',200000),('2022-07-03','Agricultural','West',800000); | SELECT AVG(usage_amount) FROM water_usage WHERE usage_category = 'Residential'; |
List all the water conservation initiatives in each country in 2020. | CREATE TABLE water_conservation (initiative_name VARCHAR(50),country VARCHAR(30),year INT,initiative_type VARCHAR(30)); | SELECT country, initiative_name FROM water_conservation WHERE year=2020 GROUP BY country; |
What was the change in water consumption between 2020 and 2021 for each city? | CREATE TABLE city_water_usage (city VARCHAR(50),year INT,consumption INT); INSERT INTO city_water_usage (city,year,consumption) VALUES ('CityA',2019,1200),('CityA',2020,1500),('CityA',2021,1700),('CityB',2019,1000),('CityB',2020,1100),('CityB',2021,1300); | SELECT a.city, (a.consumption - b.consumption) AS consumption_change FROM city_water_usage a INNER JOIN city_water_usage b ON a.city = b.city AND a.year = 2021 AND b.year = 2020; |
Find the intersection of AI safety and algorithmic fairness datasets? | CREATE TABLE AI_Safety (dataset_name TEXT,purpose TEXT); CREATE TABLE Algorithmic_Fairness (dataset_name TEXT,metric TEXT); | SELECT AI_Safety.dataset_name FROM AI_Safety INNER JOIN Algorithmic_Fairness ON AI_Safety.dataset_name = Algorithmic_Fairness.dataset_name; |
How many economic diversification efforts were successful in South Africa between 2015 and 2021? | CREATE TABLE economic_diversification_efforts (id INT,country VARCHAR(20),success BOOLEAN,start_year INT,end_year INT); INSERT INTO economic_diversification_efforts (id,country,success,start_year,end_year) VALUES (1,'South Africa',true,2015,2021),(2,'South Africa',false,2014,2016); | SELECT COUNT(*) FROM economic_diversification_efforts WHERE country = 'South Africa' AND start_year >= 2015 AND end_year <= 2021 AND success = true; |
How many rural infrastructure projects in the 'rural_development' schema have a type that starts with the letter 'E'? | CREATE SCHEMA IF NOT EXISTS rural_development;CREATE TABLE IF NOT EXISTS rural_development.infrastructure_projects (type VARCHAR(255),id INT);INSERT INTO rural_development.infrastructure_projects (type,id) VALUES ('road_construction',1),('electricity_distribution',2),('railway_construction',3),('housing_development',4); | SELECT COUNT(*) FROM rural_development.infrastructure_projects WHERE type LIKE 'E%'; |
How many women-led farming initiatives were successful in the past year in the Asia-Pacific region, grouped by country? | CREATE TABLE farming_projects (id INT,leader_gender TEXT,project_status TEXT,country TEXT); INSERT INTO farming_projects (id,leader_gender,project_status,country) VALUES (1,'female','successful','Nepal'),(2,'male','unsuccessful','India'),(3,'female','successful','Indonesia'); | SELECT country, COUNT(*) FROM farming_projects WHERE leader_gender = 'female' AND project_status = 'successful' AND country IN ('Asia', 'Pacific') GROUP BY country; |
Remove all movies with a production budget greater than 300000000 | CREATE TABLE movies (id INT,title TEXT,production_budget INT); | DELETE FROM movies WHERE production_budget > 300000000; |
What was the minimum price per gram of the Gelato strain in Nevada in 2022? | CREATE TABLE inventory (id INT,state VARCHAR(50),year INT,strain VARCHAR(50),price FLOAT,grams INT); INSERT INTO inventory (id,state,year,strain,price,grams) VALUES (1,'Nevada',2022,'Gelato',12.0,10),(2,'Nevada',2022,'Gelato',10.0,15),(3,'Nevada',2023,'Gelato',14.0,12); | SELECT MIN(price/grams) FROM inventory WHERE state = 'Nevada' AND year = 2022 AND strain = 'Gelato'; |
Display the total billing information for each attorney | CREATE TABLE billing_information (bill_id INT PRIMARY KEY,attorney_id INT,amount DECIMAL(10,2),bill_date DATE); | SELECT attorney_id, SUM(amount) FROM billing_information GROUP BY attorney_id; |
How many cases were opened in 'july' 2019 and closed in 'october' 2019? | CREATE TABLE cases (case_id INT,case_open_date DATE,case_close_date DATE); | SELECT COUNT(*) FROM cases WHERE case_open_date BETWEEN '2019-07-01' AND '2019-07-31' AND case_close_date BETWEEN '2019-10-01' AND '2019-10-31'; |
Identify attorneys who have never handled cases in the 'West' region but have in the 'North' or 'South'. | CREATE TABLE attorney_regions(attorney_id INT,region VARCHAR(20)); INSERT INTO attorney_regions(attorney_id,region) VALUES (1,'North'),(2,'South'),(3,'East'),(4,'West'),(5,'West'),(6,'North'); CREATE TABLE handled_cases(attorney_id INT,case_id INT); INSERT INTO handled_cases(attorney_id,case_id) VALUES (1,101),(2,102),(3,103),(4,104),(5,105),(6,106),(1,107),(1,108); | SELECT h.attorney_id FROM attorney_regions h LEFT JOIN handled_cases i ON h.attorney_id = i.attorney_id WHERE h.region IN ('North', 'South') AND h.region != 'West' AND i.attorney_id IS NOT NULL AND h.attorney_id NOT IN (SELECT attorney_id FROM attorney_regions WHERE region = 'West'); |
What is the maximum production capacity of the chemical manufacturing plants located in Canada? | CREATE TABLE chemical_plants (id INT,plant_name VARCHAR(100),country VARCHAR(50),production_capacity INT); INSERT INTO chemical_plants (id,plant_name,country,production_capacity) VALUES (1,'Canada Plant 1','Canada',5000),(2,'Canada Plant 2','Canada',7000); | SELECT MAX(production_capacity) FROM chemical_plants WHERE country = 'Canada'; |
What is the total number of electric vehicle charging stations installed in each state of the United States in 2022? | CREATE TABLE charging_stations_us (id INT,location VARCHAR(50),state VARCHAR(50),year INT,size INT); INSERT INTO charging_stations_us (id,location,state,year,size) VALUES (1,'Los Angeles','California',2022,500); INSERT INTO charging_stations_us (id,location,state,year,size) VALUES (2,'New York','New York',2022,600); INSERT INTO charging_stations_us (id,location,state,year,size) VALUES (3,'Chicago','Illinois',2022,700); INSERT INTO charging_stations_us (id,location,state,year,size) VALUES (4,'Houston','Texas',2022,400); | SELECT state, COUNT(size) FROM charging_stations_us WHERE year = 2022 GROUP BY state; |
What is the average R&D expenditure for drugs that were approved in the US market? | CREATE TABLE r_and_d_expenditures (drug_name TEXT,expenditures INTEGER); INSERT INTO r_and_d_expenditures (drug_name,expenditures) VALUES ('DrugA',5000000); INSERT INTO r_and_d_expenditures (drug_name,expenditures) VALUES ('DrugC',6000000); INSERT INTO r_and_d_expenditures (drug_name,expenditures) VALUES ('DrugD',4000000); CREATE TABLE drug_approval (drug_name TEXT,market TEXT,approval_date DATE); INSERT INTO drug_approval (drug_name,market,approval_date) VALUES ('DrugA','US','2016-01-01'); INSERT INTO drug_approval (drug_name,market,approval_date) VALUES ('DrugC','US','2017-04-20'); | SELECT AVG(expenditures) FROM r_and_d_expenditures JOIN drug_approval ON r_and_d_expenditures.drug_name = drug_approval.drug_name WHERE drug_approval.market = 'US'; |
What is the total number of disability accommodations requested and approved by department? | CREATE TABLE Accommodation_Data (Request_ID INT,Request_Date DATE,Accommodation_Type VARCHAR(50),Request_Status VARCHAR(10),Department VARCHAR(50)); | SELECT Department, COUNT(*) as Total_Requests FROM Accommodation_Data WHERE Request_Status = 'Approved' GROUP BY Department; |
Delete wildlife habitat data for Australia before 2015 | CREATE TABLE wildlife_habitat (country_code CHAR(3),year INT,habitat_area INT); INSERT INTO wildlife_habitat (country_code,year,habitat_area) VALUES ('AUS',2015,120000),('AUS',2010,110000),('NZL',2015,90000); | DELETE FROM wildlife_habitat WHERE country_code = 'AUS' AND year < 2015; |
What is the total volume of timber harvested in tropical rainforests for the year 2020? | CREATE TABLE rainforests (id INT,name VARCHAR(255),country VARCHAR(255),volume DECIMAL(10,2)); INSERT INTO rainforests (id,name,country,volume) VALUES (1,'Amazon Rainforest','Brazil',50.50),(2,'Congo Rainforest','Congo',35.25),(3,'Southeast Asian Rainforest','Indonesia',42.10); | SELECT SUM(volume) FROM rainforests WHERE country IN ('Brazil', 'Congo', 'Indonesia') AND YEAR(harvest_date) = 2020 AND type = 'tropical'; |
Show veteran employment statistics for each state in the 'veteran_employment' table | CREATE TABLE veteran_employment (employee_id INT,state VARCHAR(2),job_title VARCHAR(50),employment_date DATE); | SELECT state, COUNT(*) as veteran_employees FROM veteran_employment WHERE state IN ('CA', 'NY', 'TX', 'FL', 'PA') GROUP BY state; |
What is the total cargo handling time for all ports? | CREATE TABLE ports (port_id INT,cargo_handling_time INT); INSERT INTO ports (port_id,cargo_handling_time) VALUES (1,500),(2,700),(3,300); | SELECT SUM(cargo_handling_time) FROM ports; |
Which vessels have not had their annual inspections in the last 3 years? | CREATE TABLE Vessels (ID INT,Name TEXT,LastInspection DATE); INSERT INTO Vessels (ID,Name,LastInspection) VALUES (1,'Vessel 1','2020-01-01'),(2,'Vessel 2','2018-01-01'); | SELECT Name FROM Vessels WHERE DATEDIFF(year, LastInspection, GETDATE()) >= 3; |
List all suppliers from the Asia-Pacific region who have supplied materials to ManufacturerC | CREATE TABLE Suppliers (supplier_id INT,supplier_name VARCHAR(50),region VARCHAR(50)); INSERT INTO Suppliers (supplier_id,supplier_name,region) VALUES (1,'Supplier1','Asia-Pacific'),(2,'Supplier2','Europe'); CREATE TABLE Supplies (supplier_id INT,manufacturer_id INT,material VARCHAR(50),quantity INT); INSERT INTO Supplies (supplier_id,manufacturer_id,material,quantity) VALUES (1,3,'Material1',50),(2,3,'Material2',75); CREATE TABLE Manufacturers (manufacturer_id INT,manufacturer_name VARCHAR(50),region VARCHAR(50)); INSERT INTO Manufacturers (manufacturer_id,manufacturer_name,region) VALUES (3,'ManufacturerC','North America'); | SELECT s.supplier_name FROM Suppliers s INNER JOIN Supplies sp ON s.supplier_id = sp.supplier_id INNER JOIN Manufacturers m ON sp.manufacturer_id = m.manufacturer_id WHERE m.region = 'North America' AND m.manufacturer_name = 'ManufacturerC' AND s.region = 'Asia-Pacific'; |
Find the number of healthcare providers in each type of facility in the rural healthcare system. | CREATE TABLE Providers (ID INT,Name TEXT,Type TEXT,FacilityType TEXT); INSERT INTO Providers VALUES (1,'Dr. Smith','Doctor','Hospital'); INSERT INTO Providers VALUES (2,'Jane Doe,RN','Nurse','Clinic'); INSERT INTO Providers VALUES (3,'Mobile Medical Unit','Clinic','Mobile'); | SELECT FacilityType, COUNT(*) AS Total FROM Providers GROUP BY FacilityType; |
Show companies with below average ESG scores in the education sector. | INSERT INTO companies (id,name,country,sector,ESG_score) VALUES (4,'EdCo','US','Education',70.0),(5,'LearnCo','UK','Education',80.0); | SELECT * FROM companies WHERE sector = 'Education' AND ESG_score < (SELECT AVG(ESG_score) FROM companies WHERE sector = 'Education'); |
Determine the number of unique donors who made donations in the last month from the 'donations' table. | CREATE TABLE donations (id INT,donor_name VARCHAR(50),donation_date DATE,amount DECIMAL(10,2)); | SELECT COUNT(DISTINCT donor_name) FROM donations WHERE donation_date >= DATEADD(month, -1, GETDATE()); |
How many volunteers joined after participating in a community outreach event in '2020'? | CREATE TABLE volunteer_events (id INT,event_name TEXT,year INT,num_volunteers INT); INSERT INTO volunteer_events (id,event_name,year,num_volunteers) VALUES (1,'Youth Mentoring Program',2020,120),(2,'Feeding the Homeless',2020,180),(3,'Climate Action Rally',2020,90); | SELECT SUM(num_volunteers) FROM volunteer_events WHERE year = 2020 AND event_name IN (SELECT event_name FROM volunteer_events WHERE year = 2020 AND num_volunteers > 0); |
What was the budget for the Marketing department in each quarter of 2019? | CREATE TABLE Department_Budget (id INT,department VARCHAR(50),category VARCHAR(50),amount FLOAT,budget_date DATE); INSERT INTO Department_Budget (id,department,category,amount,budget_date) VALUES (1,'Marketing','Advertising',20000,'2019-01-01'); INSERT INTO Department_Budget (id,department,category,amount,budget_date) VALUES (2,'Marketing','Promotions',15000,'2019-02-01'); | SELECT department, QUARTER(budget_date) as quarter, SUM(amount) as total_budget FROM Department_Budget WHERE YEAR(budget_date) = 2019 AND department = 'Marketing' GROUP BY department, quarter; |
What is the maximum mental health score of students in 'Fall 2021'? | CREATE TABLE student_mental_health (student_id INT,mental_health_score INT,date DATE); INSERT INTO student_mental_health (student_id,mental_health_score,date) VALUES (1,80,'2021-09-01'),(2,85,'2021-09-01'),(3,70,'2021-09-02'); | SELECT MAX(mental_health_score) FROM student_mental_health WHERE date = '2021-09-01'; |
Create a view to display all employees' ages and ethnicities | CREATE TABLE EmployeeDemographics (EmployeeID INT PRIMARY KEY,Age INT,Gender VARCHAR(10),Ethnicity VARCHAR(20)); | CREATE VIEW EmployeeAgesEthnicities AS SELECT Age, Ethnicity FROM EmployeeDemographics; |
What is the average salary of employees who identify as Latinx in the Engineering department? | CREATE TABLE Employees (EmployeeID int,Name varchar(50),Gender varchar(10),Department varchar(50),Salary decimal(10,2),Ethnicity varchar(50)); INSERT INTO Employees (EmployeeID,Name,Gender,Department,Salary,Ethnicity) VALUES (1,'Juan Garcia','Male','Engineering',85000.00,'Latinx'); INSERT INTO Employees (EmployeeID,Name,Gender,Department,Salary,Ethnicity) VALUES (2,'Maria Rodriguez','Female','Engineering',90000.00,'Latinx'); | SELECT AVG(Salary) FROM Employees WHERE Department = 'Engineering' AND Ethnicity = 'Latinx'; |
List all the hockey players and their respective positions. | CREATE TABLE players (id INT,name VARCHAR(50),position VARCHAR(20),sport VARCHAR(20)); INSERT INTO players (id,name,position,sport) VALUES (1,'Sidney Crosby','Center','Hockey'); INSERT INTO players (id,name,position,sport) VALUES (2,'Alex Ovechkin','Left Wing','Hockey'); | SELECT name, position FROM players WHERE sport = 'Hockey'; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.