instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Create a view named 'vw_fan_ethnicity_distribution' to display ethnicity distribution
CREATE TABLE fan_demographics (fan_id INT PRIMARY KEY,name VARCHAR(100),age INT,gender VARCHAR(10),location VARCHAR(100),ethnicity VARCHAR(50)); INSERT INTO fan_demographics (fan_id,name,age,gender,location,ethnicity) VALUES (1,'John Doe',30,'Male','NY','Hispanic'),(2,'Jane Smith',25,'Female','LA','Asian'),(3,'Raj Pate...
CREATE VIEW vw_fan_ethnicity_distribution AS SELECT ethnicity, COUNT(*) as count FROM fan_demographics GROUP BY ethnicity;
What is the average cargo handling time for 'Port of Santos'?
CREATE TABLE ports (id INT,name TEXT,handling_time INT); INSERT INTO ports (id,name,handling_time) VALUES (1,'Port of Santos',120),(2,'Port of Oakland',90),(3,'Port of Singapore',100);
SELECT AVG(handling_time) FROM ports WHERE name = 'Port of Santos';
What is the total number of tourists from Japan visiting sustainable tourism destinations in South America?
CREATE TABLE tourism (visitor_country VARCHAR(50),destination VARCHAR(50),is_sustainable BOOLEAN); INSERT INTO tourism (visitor_country,destination,is_sustainable) VALUES ('Japan','Galapagos Islands',true),('Japan','Machu Picchu',false),('Brazil','Iguazu Falls',true);
SELECT COUNT(*) FROM tourism WHERE visitor_country = 'Japan' AND destination IN ('Galapagos Islands', 'Amazon Rainforest', 'Patagonia') AND is_sustainable = true;
What is the distribution of socially responsible investment types in Canada?
CREATE TABLE socially_responsible_investments (id INT,client_id INT,country VARCHAR(50),investment_type VARCHAR(50)); INSERT INTO socially_responsible_investments (id,client_id,country,investment_type) VALUES (1,401,'Canada','Green Bonds'),(2,402,'Canada','Sustainable Equities');
SELECT country, investment_type, COUNT(*) as num_investments, 100.0 * COUNT(*) / (SELECT COUNT(*) FROM socially_responsible_investments WHERE country = 'Canada') as percentage FROM socially_responsible_investments WHERE country = 'Canada' GROUP BY country, investment_type;
List all customers with their financial capability score and corresponding Shariah-compliant finance product
CREATE TABLE customers (customer_id INT,financial_capability_score INT); CREATE TABLE shariah_finance (customer_id INT,product VARCHAR(255));
SELECT customers.customer_id, customers.financial_capability_score, shariah_finance.product FROM customers INNER JOIN shariah_finance ON customers.customer_id = shariah_finance.customer_id;
What is the total area of all forest management sites, in hectares, that are located in countries with a population of over 100 million?
CREATE TABLE forest_management (id INT,country VARCHAR(255),site_name VARCHAR(255),area FLOAT,population INT); INSERT INTO forest_management (id,country,site_name,area,population) VALUES (1,'Canada','Site I',50000.0,38000000),(2,'Brazil','Site J',60000.0,212000000),(3,'Indonesia','Site K',70000.0,276000000),(4,'Russia'...
SELECT SUM(area) FROM forest_management WHERE population > 100000000;
Calculate the total claim amount paid to policyholders in 'California' and 'Colorado' in June 2020.
CREATE TABLE claims (policyholder_id INT,claim_amount DECIMAL(10,2),policyholder_state VARCHAR(20),claim_date DATE); INSERT INTO claims (policyholder_id,claim_amount,policyholder_state,claim_date) VALUES (1,500.00,'California','2020-06-01'),(2,300.00,'Colorado','2020-06-15'),(3,700.00,'California','2020-06-30');
SELECT SUM(claim_amount) FROM claims WHERE policyholder_state IN ('California', 'Colorado') AND claim_date BETWEEN '2020-06-01' AND '2020-06-30';
What is the names and mental health scores of students who are in grade 12 and have a mental health score greater than 80?
CREATE TABLE Students (StudentID INT,Name VARCHAR(50),MentalHealthScore INT,GradeLevel INT); INSERT INTO Students (StudentID,Name,MentalHealthScore,GradeLevel) VALUES (3,'Jim Brown',82,12); INSERT INTO Students (StudentID,Name,MentalHealthScore,GradeLevel) VALUES (4,'Sara White',78,11);
SELECT Name, MentalHealthScore FROM Students WHERE GradeLevel = 12 INTERSECT SELECT Name, MentalHealthScore FROM Students WHERE MentalHealthScore > 80;
Get the average carbon offsets for projects in Germany.
CREATE TABLE renewable_projects (id INT PRIMARY KEY,project_name VARCHAR(255),project_location VARCHAR(255),project_type VARCHAR(255),capacity_mw FLOAT,carbon_offsets INT); CREATE VIEW german_projects AS SELECT * FROM renewable_projects WHERE project_location = 'Germany';
SELECT AVG(carbon_offsets) FROM german_projects;
What is the minimum number of operational hours for a geostationary satellite?
CREATE TABLE GeostationarySatellites (id INT,satellite_name VARCHAR(50),operational_hours INT);
SELECT MIN(operational_hours) FROM GeostationarySatellites WHERE operational_hours IS NOT NULL;
What is the maximum and minimum broadband download speed for customers living in the same household?
CREATE TABLE households (household_id INT,customer_id INT); CREATE TABLE customers (customer_id INT,broadband_download_speed FLOAT); INSERT INTO households (household_id,customer_id) VALUES (1,1),(1,2); INSERT INTO customers (customer_id,broadband_download_speed) VALUES (1,100),(2,150);
SELECT MAX(c.broadband_download_speed), MIN(c.broadband_download_speed) FROM customers c JOIN households h ON c.customer_id = h.customer_id WHERE h.household_id = 1;
Find the number of animals in 'AnimalPopulation' grouped by 'habitat_type'
CREATE TABLE AnimalPopulation (animal_id INT,species VARCHAR(50),habitat_type VARCHAR(50),animal_count INT);
SELECT habitat_type, COUNT(*) as animal_count FROM AnimalPopulation GROUP BY habitat_type;
What is the total revenue for each restaurant on a specific day of the week?
CREATE TABLE revenue_by_date (date DATE,restaurant VARCHAR(50),revenue INT); INSERT INTO revenue_by_date (date,restaurant,revenue) VALUES ('2022-01-01','Restaurant A',3000),('2022-01-01','Restaurant B',4000),('2022-01-01','Restaurant C',5000),('2022-01-02','Restaurant A',4000),('2022-01-02','Restaurant B',5000),('2022-...
SELECT restaurant, SUM(revenue) FROM revenue_by_date WHERE DATE_FORMAT(date, '%W') = 'Monday' GROUP BY restaurant;
What is the number of hybrid vehicles sold in the US and Canada?
CREATE TABLE vehicle_sales (id INT,country VARCHAR(50),vehicle_type VARCHAR(50),sales INT);
SELECT country, SUM(sales) FROM vehicle_sales WHERE country IN ('US', 'Canada') AND vehicle_type = 'hybrid' GROUP BY country;
What is the minimum salary for employees in the Marketing department?
CREATE TABLE Employees (EmployeeID INT,Department VARCHAR(50),Gender VARCHAR(10),Salary FLOAT); INSERT INTO Employees (EmployeeID,Department,Gender,Salary) VALUES (1,'IT','Male',75000),(2,'HR','Female',65000),(3,'IT','Female',70000),(4,'IT','Male',80000),(5,'Finance','Male',90000),(6,'Finance','Female',85000),(7,'Finan...
SELECT MIN(Salary) FROM Employees WHERE Department = 'Marketing';
Which donors have donated to projects in both the 'education' and 'technology' sectors?
CREATE TABLE donors (donor_id INT,name TEXT);CREATE TABLE projects (project_id INT,name TEXT,sector TEXT);CREATE TABLE donations (donation_id INT,donor_id INT,project_id INT,amount FLOAT);INSERT INTO donors VALUES (1,'Ivan Black'),(2,'Julia White'),(3,'Karen Gray'),(4,'Luke Brown');INSERT INTO projects VALUES (1,'AI Re...
SELECT donors.donor_id, donors.name FROM donors INNER JOIN donations ON donors.donor_id = donations.donor_id INNER JOIN projects ON donations.project_id = projects.project_id WHERE projects.sector IN ('education', 'technology') GROUP BY donors.donor_id HAVING COUNT(DISTINCT projects.sector) = 2;
Identify the top 3 cities with the highest number of citizen complaints submitted, including the number of complaints submitted in each city.
CREATE TABLE users (id INT PRIMARY KEY,city VARCHAR(255));CREATE TABLE complaints (id INT PRIMARY KEY,user_id INT,title VARCHAR(255));
SELECT u.city, COUNT(c.id) AS num_complaints FROM complaints c JOIN users u ON c.user_id = u.id GROUP BY u.city ORDER BY num_complaints DESC LIMIT 3;
What was the total budget allocated for healthcare in the East region in the first half of 2022?
CREATE TABLE Budget (half INT,region VARCHAR(255),service VARCHAR(255),amount INT); INSERT INTO Budget (half,region,service,amount) VALUES (1,'East','Healthcare',5000000),(1,'East','Healthcare',5500000),(2,'East','Healthcare',6000000),(2,'East','Healthcare',6500000);
SELECT SUM(amount) FROM Budget WHERE half IN (1, 2) AND region = 'East' AND service = 'Healthcare';
List the top 5 locations with the highest number of candidates interviewed for a job in the past month, including their respective job titles and the number of candidates interviewed?
CREATE TABLE Interviews (InterviewID int,InterviewDate date,CandidateName varchar(50),CandidateGender varchar(10),JobTitle varchar(50),Location varchar(50)); INSERT INTO Interviews (InterviewID,InterviewDate,CandidateName,CandidateGender,JobTitle,Location) VALUES (1,'2023-02-01','David Kim','Male','Software Engineer','...
SELECT Location, JobTitle, COUNT(*) AS num_candidates FROM Interviews WHERE InterviewDate >= DATEADD(month, -1, GETDATE()) GROUP BY Location, JobTitle ORDER BY num_candidates DESC, Location DESC LIMIT 5;
How many wastewater treatment plants are in the province of Quebec, Canada, that were built before 1990?
CREATE TABLE wastewater_treatment_plants (id INT,province VARCHAR(255),build_year INT); INSERT INTO wastewater_treatment_plants (id,province,build_year) VALUES (1,'Quebec',1985),(2,'Quebec',1995),(3,'Quebec',1988);
SELECT COUNT(*) FROM wastewater_treatment_plants WHERE province = 'Quebec' AND build_year < 1990;
What is the average number of mental health providers per capita in urban areas, ordered by the highest average?
CREATE TABLE mental_health_providers (id INT,name TEXT,specialty TEXT,location TEXT,population INT); INSERT INTO mental_health_providers (id,name,specialty,location,population) VALUES (1,'Dr. Garcia','Mental Health','urban',30000),(2,'Dr. Kim','Mental Health','rural',5000);
SELECT AVG(population / NULLIF(specialty = 'Mental Health', 0)) FROM mental_health_providers WHERE location = 'urban' GROUP BY location ORDER BY AVG(population / NULLIF(specialty = 'Mental Health', 0)) DESC;
Add a column to 'species'
CREATE TABLE species (id INT PRIMARY KEY,name VARCHAR(255),population INT,conservation_status VARCHAR(255));
ALTER TABLE species ADD COLUMN last_sighting DATE;
What is the daily recycling rate for the city of Berlin?
CREATE TABLE city_recycling (city VARCHAR(255),recycling_rate DECIMAL(5,2),total_waste INT,day INT); INSERT INTO city_recycling (city,recycling_rate,total_waste,day) VALUES ('Berlin',0.25,80000,3);
SELECT recycling_rate FROM city_recycling WHERE city='Berlin' AND day=3;
What is the number of employees of each nationality working at each mine and their total quantity of resources mined?
CREATE TABLE Mine (MineID int,MineName varchar(50),Location varchar(50),Nationality varchar(50),EmployeeCount int,CoalQuantity int,IronQuantity int,GoldQuantity int); INSERT INTO Mine VALUES (1,'ABC Mine','Colorado','American',20,1000,1600,2400),(2,'DEF Mine','Wyoming','Canadian',15,1200,1800,3000),(3,'GHI Mine','West ...
SELECT MineName, Nationality, EmployeeCount, SUM(CoalQuantity + IronQuantity + GoldQuantity) as TotalResources FROM Mine GROUP BY MineName, Nationality;
What is the total budget allocated for public transportation in the city of Dallas since its inception?
CREATE TABLE PublicTransportation (TransportID INT,City VARCHAR(255),Type VARCHAR(255),AllocationDate DATE,Budget DECIMAL(10,2)); INSERT INTO PublicTransportation (TransportID,City,Type,AllocationDate,Budget) VALUES (1,'Dallas','Bus','2010-01-01',100000.00),(2,'Dallas','Train','2015-01-01',200000.00);
SELECT SUM(Budget) FROM PublicTransportation WHERE City = 'Dallas' AND Type = 'Public Transportation';
Which region extracted the most mineral X in the year 2021?'
CREATE TABLE extraction_extended (id INT,region TEXT,mineral TEXT,year INT,quantity INT,hour INT); INSERT INTO extraction_extended (id,region,mineral,year,quantity,hour) VALUES (1,'north','X',2021,500,8),(2,'north','X',2020,550,9),(3,'south','X',2021,600,10);
SELECT region, SUM(quantity) AS total_quantity FROM extraction_extended WHERE mineral = 'X' AND year = 2021 GROUP BY region ORDER BY total_quantity DESC LIMIT 1;
How many heritage sites (tangible and intangible) are there in the Amazon region?
CREATE TABLE tangible_heritage (id INT,name VARCHAR(255),region VARCHAR(255)); INSERT INTO tangible_heritage (id,name,region) VALUES (1,'Historic Centre of Salvador de Bahia','Amazon'); CREATE TABLE intangible_heritage (id INT,name VARCHAR(255),region VARCHAR(255)); INSERT INTO intangible_heritage (id,name,region) VALU...
SELECT COUNT(*) FROM (SELECT 'tangible' as type, t.name FROM tangible_heritage t WHERE t.region = 'Amazon' UNION ALL SELECT 'intangible' as type, i.name FROM intangible_heritage i WHERE i.region = 'Amazon') AS h;
List all vessels that have a safety inspection score above 90.
CREATE TABLE Vessels (ID VARCHAR(10),Name VARCHAR(20),Type VARCHAR(20),Safety_Score INT); INSERT INTO Vessels (ID,Name,Type,Safety_Score) VALUES ('1','Vessel A','Cargo',95),('2','Vessel B','Tanker',88),('3','Vessel C','Bulk Carrier',92),('4','Vessel D','Container',85); CREATE TABLE Inspections (ID VARCHAR(10),Vessel_ID...
SELECT Vessels.Name FROM Vessels INNER JOIN Inspections ON Vessels.ID = Inspections.Vessel_ID WHERE Vessels.Safety_Score > 90;
What are the names of the animals in 'sanctuary_e' and their respective populations?
CREATE TABLE sanctuary_e (animal_id INT,animal_name VARCHAR(50),population INT); INSERT INTO sanctuary_e VALUES (1,'tiger',25); INSERT INTO sanctuary_e VALUES (2,'elephant',30); INSERT INTO sanctuary_e VALUES (3,'monkey',35);
SELECT animal_name, population FROM sanctuary_e;
What is the maximum energy efficiency rating for buildings in each of the following states: CA, NY, FL, TX?
CREATE TABLE buildings (id INT,state VARCHAR(255),energy_efficiency_rating FLOAT); INSERT INTO buildings (id,state,energy_efficiency_rating) VALUES (1,'CA',90.5),(2,'NY',85.0),(3,'FL',95.0),(4,'TX',88.0),(5,'CA',92.0),(6,'NY',87.5),(7,'FL',94.5),(8,'TX',89.5);
SELECT state, MAX(energy_efficiency_rating) as max_rating FROM buildings WHERE state IN ('CA', 'NY', 'FL', 'TX') GROUP BY state;
How many patients with diabetes are there in rural communities in India?
CREATE TABLE patient (patient_id INT,age INT,gender VARCHAR(10),state VARCHAR(10),disease VARCHAR(20)); INSERT INTO patient (patient_id,age,gender,state,disease) VALUES (1,65,'Male','rural India','Diabetes');
SELECT COUNT(*) FROM patient WHERE gender = 'Male' AND state = 'rural India' AND disease = 'Diabetes';
What is the total playtime for all players who have played the game 'Adventure'?
CREATE TABLE PlayerGameData (PlayerID INT,Game VARCHAR(20),Playtime INT); INSERT INTO PlayerGameData (PlayerID,Game,Playtime) VALUES (1,'Adventure',50),(2,'Shooter',30),(3,'Adventure',70);
SELECT SUM(Playtime) FROM PlayerGameData WHERE Game = 'Adventure';
What is the total number of marine research projects in the Mediterranean Sea?
CREATE TABLE marine_research_projects (id INT,name TEXT,location TEXT); INSERT INTO marine_research_projects (id,name,location) VALUES (1,'Coral Reef Study','Mediterranean Sea'),(2,'Turtle Migration Research','Atlantic Ocean'),(3,'Plastic Pollution Analysis','Pacific Ocean');
SELECT COUNT(*) FROM marine_research_projects WHERE location = 'Mediterranean Sea';
Show all students with a mental health score above 80
CREATE TABLE student_mental_health (student_id INT,mental_health_score INT);
SELECT * FROM student_mental_health WHERE mental_health_score > 80;
Who are the top 5 customers based on their purchases of halal cosmetics?
CREATE TABLE Customers (customer_id INT,customer_name VARCHAR(50),halal_purchase_value DECIMAL(10,2)); INSERT INTO Customers (customer_id,customer_name,halal_purchase_value) VALUES (1,'Sara',300.50),(2,'Aisha',450.25),(3,'John',0),(4,'Fatima',560.75),(5,'David',0),(6,'Maryam',600.00),(7,'Ahmed',700.50),(8,'Michael',0),...
SELECT customer_name FROM Customers ORDER BY halal_purchase_value DESC LIMIT 5;
Find the basketball player with the most three-pointers made in a season?
CREATE TABLE Players (player_id INTEGER,name TEXT,three_pointers INTEGER); INSERT INTO Players (player_id,name,three_pointers) VALUES (1,'Player 1',200),(2,'Player 2',250),(3,'Player 3',300);
SELECT name FROM Players WHERE three_pointers = (SELECT MAX(three_pointers) FROM Players);
Delete a product's material from the "inventory" table
CREATE TABLE inventory (product_id INT,material_id INT,quantity INT);
DELETE FROM inventory WHERE product_id = 1001 AND material_id = 3001;
What is the total billing amount for cases of each type?
CREATE TABLE CaseTypeBilling (CaseType VARCHAR(50),TotalAmount DECIMAL(10,2)); INSERT INTO CaseTypeBilling (CaseType,TotalAmount) VALUES ('Civil',0); INSERT INTO CaseTypeBilling (CaseType,TotalAmount) VALUES ('Criminal',0);
UPDATE CaseTypeBilling SET TotalAmount = (SELECT SUM(B.Amount) FROM Billing B JOIN CaseBilling CB ON B.BillingID = CB.BillingID JOIN Cases C ON CB.CaseID = C.CaseID WHERE C.CaseType = CaseTypeBilling.CaseType);
Insert new records into the 'agricultural_innovations' table for a new crop variety in India
CREATE TABLE agricultural_innovations (id INT,innovation_name VARCHAR(255),country VARCHAR(255),sector VARCHAR(255));
INSERT INTO agricultural_innovations (id, innovation_name, country, sector) VALUES (1, 'Drought-resistant Maize', 'India', 'Agriculture');
What are the names of the art movements that had the most significant cultural impact in the 19th century?
CREATE TABLE ArtMovements (MovementID int,MovementName varchar(100),YearStart int,YearEnd int,CulturalImpact int); INSERT INTO ArtMovements (MovementID,MovementName,YearStart,YearEnd,CulturalImpact) VALUES (1,'Romanticism',1800,1850,90),(2,'Realism',1848,1890,85),(3,'Impressionism',1860,1890,80);
SELECT MovementName FROM ArtMovements WHERE YearStart BETWEEN 1800 AND 1899 AND CulturalImpact = (SELECT MAX(CulturalImpact) FROM ArtMovements WHERE YearStart BETWEEN 1800 AND 1899);
Update the age of donor with id 1 to 30
CREATE TABLE donors (id INT PRIMARY KEY,name VARCHAR(100),age INT,state VARCHAR(2),income FLOAT);
UPDATE donors SET age = 30 WHERE id = 1;
How many marine species have been researched in the Atlantic Ocean that have a population greater than 10000?
CREATE TABLE marine_species_research (id INT,species TEXT,location TEXT,year INT,population INT); INSERT INTO marine_species_research (id,species,location,year,population) VALUES (1,'Whale Shark','Atlantic Ocean',2010,12000),(2,'Dolphin','Atlantic Ocean',2005,5000),(3,'Turtle','Atlantic Ocean',2018,20000);
SELECT COUNT(*) FROM marine_species_research WHERE location = 'Atlantic Ocean' AND population > 10000;
What is the average quantity of military vehicles per country in the North American region?
CREATE TABLE MilitaryVehicles (Id INT,Country VARCHAR(50),VehicleType VARCHAR(50),Quantity INT);INSERT INTO MilitaryVehicles (Id,Country,VehicleType,Quantity) VALUES (1,'USA','Tank',3000),(2,'Canada','Armored Personnel Carrier',1500),(3,'Mexico','Artillery',1000);
SELECT AVG(Quantity) AS AverageQuantity FROM (SELECT Country, SUM(Quantity) Quantity FROM MilitaryVehicles WHERE Country IN ('USA', 'Canada', 'Mexico') GROUP BY Country) AS Subquery;
What is the total number of farmers who have participated in community development initiatives in Kenya and Uganda?
CREATE TABLE farmers (id INT,name TEXT,country TEXT); INSERT INTO farmers (id,name,country) VALUES (1,'John','Kenya'),(2,'Jane','Uganda'); CREATE TABLE initiatives (id INT,name TEXT,location TEXT); INSERT INTO initiatives (id,name,location) VALUES (1,'Training','Kenya'),(2,'Workshop','Uganda'); CREATE TABLE participati...
SELECT COUNT(DISTINCT f.id) FROM farmers f INNER JOIN participation p ON f.id = p.farmer_id INNER JOIN initiatives i ON p.initiative_id = i.id WHERE f.country IN ('Kenya', 'Uganda');
What are the carbon emissions (in metric tons) for each country?
CREATE TABLE carbon_emissions (country VARCHAR(50),emissions INT); INSERT INTO carbon_emissions (country,emissions) VALUES ('CN',10000),('IN',7000),('US',5000);
SELECT country, emissions FROM carbon_emissions;
What is the total cost of astrophysics research conducted in the US in 2010?
CREATE TABLE Research (id INT,title VARCHAR(100),country VARCHAR(100),year INT,cost FLOAT); INSERT INTO Research (id,title,country,year,cost) VALUES (1,'Project A','US',2010,100000),(2,'Project B','US',2011,120000);
SELECT SUM(cost) FROM Research WHERE country = 'US' AND year = 2010;
What is the total quantity of vegetarian dishes sold per store, per day?
CREATE TABLE Stores (StoreID INT,StoreName VARCHAR(50));CREATE TABLE Menu (MenuID INT,MenuItem VARCHAR(50),IsVegetarian BIT);CREATE TABLE Sales (SaleID INT,StoreID INT,MenuID INT,QuantitySold INT,SaleDate DATE);
SELECT SaleDate, StoreName, SUM(QuantitySold) AS TotalQuantity FROM Sales JOIN Menu ON Sales.MenuID = Menu.MenuID JOIN Stores ON Sales.StoreID = Stores.StoreID WHERE IsVegetarian = 1 GROUP BY SaleDate, StoreName;
What is the total number of animals in the 'animal_population' table, grouped by species, that were part of community education programs?
CREATE TABLE animal_population (animal_id INT,species VARCHAR(50),num_animals INT,education_program BOOLEAN);
SELECT species, SUM(num_animals) FROM animal_population WHERE education_program = TRUE GROUP BY species;
What was the total quantity of refrigerated cargo unloaded at the port of Long Beach in August 2021, grouped by cargo type?
CREATE TABLE ports (id INT,name VARCHAR(50)); INSERT INTO ports (id,name) VALUES (1,'Oakland'),(2,'Long Beach'),(3,'Los Angeles'); CREATE TABLE cargo (id INT,port_id INT,cargo_type VARCHAR(50),temperature_type VARCHAR(50),quantity INT); INSERT INTO cargo (id,port_id,cargo_type,temperature_type,quantity) VALUES (1,1,'Fr...
SELECT cargo_type, SUM(quantity) as total_quantity FROM cargo WHERE port_id = 2 AND temperature_type = 'Refrigerated' AND MONTH(date) = 8 GROUP BY cargo_type;
What is the average rating for each product, and the number of ratings for each product, ordered by the average rating in descending order?
CREATE TABLE product (product_id INT,name VARCHAR(50),rating DECIMAL(3,2),num_ratings INT); INSERT INTO product VALUES (1,'Product A',4.5,100),(2,'Product B',3.5,200),(3,'Product C',5.0,50);
SELECT name, AVG(rating) as avg_rating, num_ratings FROM product GROUP BY name ORDER BY avg_rating DESC, num_ratings DESC;
What are the energy efficiency stats for companies in Texas?
CREATE TABLE Companies (id INT,name TEXT,industry TEXT,location TEXT); INSERT INTO Companies (id,name,industry,location) VALUES (1,'GreenTech Inc.','Renewable Energy','Texas'),(2,'EcoPower LLC.','Energy Efficiency','Texas'); CREATE TABLE EnergyEfficiency (company_id INT,year INT,efficiency_score INT); INSERT INTO Energ...
SELECT Companies.name, EnergyEfficiency.efficiency_score FROM Companies INNER JOIN EnergyEfficiency ON Companies.id = EnergyEfficiency.company_id WHERE Companies.location = 'Texas';
What is the total number of properties owned by each owner in co-ownership properties?
CREATE TABLE CoOwnershipProperties (PropertyID INT,OwnerID INT); CREATE TABLE Owners (OwnerID INT,OwnerName VARCHAR(255));
SELECT O.OwnerName, COUNT(COP.PropertyID) as TotalPropertiesOwned FROM Owners O JOIN CoOwnershipProperties COP ON O.OwnerID = COP.OwnerID GROUP BY O.OwnerName;
What is the minimum assets value for clients in the 'High-Risk' category who own investment product 'GOOG'?
CREATE TABLE clients (id INT,name TEXT,category TEXT,assets FLOAT); CREATE TABLE investments (id INT,client_id INT,product_code TEXT); INSERT INTO clients (id,name,category,assets) VALUES (1,'John Doe','Medium-Risk',50000.00),(2,'Jane Smith','Low-Risk',75000.00),(3,'Alice Johnson','High-Risk',100000.00),(4,'Bob Brown',...
SELECT MIN(assets) FROM clients c JOIN investments i ON c.id = i.client_id WHERE c.category = 'High-Risk' AND i.product_code = 'GOOG';
What is the number of peacekeeping operations conducted by the UN in the Middle East region?
CREATE TABLE PeacekeepingOperations (OperationID INT,OperationName VARCHAR(100),OperationType VARCHAR(50),StartDate DATE,EndDate DATE);
SELECT COUNT(OperationID) FROM PeacekeepingOperations WHERE OperationType = 'Peacekeeping' AND (StartDate BETWEEN '2000-01-01' AND '2022-12-31') AND (EndDate BETWEEN '2000-01-01' AND '2022-12-31') AND (OperationName LIKE '%Middle East%');
What is the average number of streams per day for pop songs in New York last month?
CREATE TABLE Streams (song_genre VARCHAR(255),city VARCHAR(255),stream_count INT,stream_date DATE); INSERT INTO Streams (song_genre,city,stream_count,stream_date) VALUES ('pop','New York',500,'2022-01-01'),('hip-hop','Los Angeles',600,'2022-01-02');
SELECT AVG(stream_count/1.0) FROM Streams WHERE song_genre = 'pop' AND city = 'New York' AND stream_date >= DATEADD(MONTH, -1, GETDATE());
How many garments were produced in 'France' for each month in the 'Autumn 2022' season?
CREATE TABLE ManufacturingDates (ManufacturingDate DATE,GarmentID INT); INSERT INTO ManufacturingDates (ManufacturingDate,GarmentID) VALUES ('2022-10-01',1),('2022-11-01',2),('2022-12-01',3); CREATE TABLE Garments (GarmentID INT,GarmentType VARCHAR(20),ManufacturerID INT,Country VARCHAR(50)); INSERT INTO Garments (Garm...
SELECT EXTRACT(MONTH FROM ManufacturingDate) as Month, COUNT(*) as TotalGarments FROM ManufacturingDates M JOIN Garments G ON M.GarmentID = G.GarmentID WHERE Country = 'France' AND ManufacturingDate BETWEEN '2022-10-01' AND '2022-12-31' GROUP BY Month;
Find the maximum and minimum R&D expenditure for the drugs approved in 2018 and 2019.
CREATE TABLE drugs_2(drug_name TEXT,approval_year INT,rd_expenditure FLOAT); INSERT INTO drugs_2(drug_name,approval_year,rd_expenditure) VALUES('DrugA',2017,5000000),('DrugB',2018,7000000),('DrugC',2019,8000000),('DrugD',2019,6000000),('DrugE',2018,4000000);
SELECT MAX(rd_expenditure), MIN(rd_expenditure) FROM drugs_2 WHERE approval_year IN (2018, 2019);
How many marine species are there in each ocean basin?
CREATE TABLE marine_species (species_id INT,species_name VARCHAR(255),ocean_basin VARCHAR(50)); INSERT INTO marine_species (species_id,species_name,ocean_basin) VALUES (1,'Green Sea Turtle','Pacific'),(2,'Humpback Whale','Atlantic');
SELECT ocean_basin, COUNT(*) FROM marine_species GROUP BY ocean_basin;
What is the count of transactions for clients living in Australia?
CREATE TABLE clients (client_id INT,name TEXT,country TEXT,transaction_amount DECIMAL); INSERT INTO clients (client_id,name,country,transaction_amount) VALUES (1,'John Doe','Australia',500.00); INSERT INTO clients (client_id,name,country,transaction_amount) VALUES (2,'Jane Smith','United States',350.00); INSERT INTO cl...
SELECT COUNT(*) FROM clients WHERE country = 'Australia';
What is the percentage of donations made by each donor compared to the total donations?
CREATE TABLE Donors (DonorID INT,DonorName TEXT); CREATE TABLE Donations (DonationID INT,DonorID INT,DonationAmount DECIMAL(10,2)); INSERT INTO Donors (DonorID,DonorName) VALUES (1,'John Doe'),(2,'Jane Smith'),(3,'Alice Johnson'); INSERT INTO Donations (DonationID,DonorID,DonationAmount) VALUES (1,1,500.00),(2,1,750.00...
SELECT DonorName, SUM(DonationAmount) AS TotalDonation, SUM(DonationAmount) OVER () AS TotalDonations, (SUM(DonationAmount) / SUM(DonationAmount) OVER ()) * 100.0 AS DonationPercentage FROM Donors dn JOIN Donations d ON dn.DonorID = d.DonorID GROUP BY DonorName;
Insert a new record for a research vessel 'RV Sea Surveyor' in the research_vessels table.
CREATE TABLE research_vessels (id INT,name VARCHAR(50),type VARCHAR(20),year INT);
INSERT INTO research_vessels (id, name, type, year) VALUES (4, 'RV Sea Surveyor', 'Hydrographic', 2022);
Determine the average amount donated per donor for each disaster response.
CREATE TABLE donors (id INT,disaster_id INT,amount FLOAT); CREATE TABLE disasters (id INT,name VARCHAR(255));
SELECT d.name, AVG(donors.amount) as avg_donation_per_donor FROM disasters d LEFT JOIN donors ON d.id = donors.disaster_id GROUP BY d.id;
What is the total quantity of gold and silver mined at each mine between 2021-01-01 and 2021-01-07?
CREATE TABLE MiningOperations (MineID INT,Material VARCHAR(20),Quantity INT,Date DATE); INSERT INTO MiningOperations (MineID,Material,Quantity,Date) VALUES (1,'Gold',500,'2021-01-01'); INSERT INTO MiningOperations (MineID,Material,Quantity,Date) VALUES (2,'Silver',300,'2021-01-02');
SELECT MineID, SUM(Quantity) as TotalQuantity FROM MiningOperations WHERE Date >= '2021-01-01' AND Date <= '2021-01-07' AND Material IN ('Gold', 'Silver') GROUP BY MineID;
What is the maximum and minimum water temperature in the farms located in the Caribbean region?
CREATE TABLE temp_data (farm_id INT,location VARCHAR(20),temp FLOAT); INSERT INTO temp_data (farm_id,location,temp) VALUES (1,'Caribbean region',25.5),(2,'Caribbean region',24.8),(3,'Caribbean region',26.1);
SELECT MAX(temp), MIN(temp) FROM temp_data WHERE location = 'Caribbean region';
Identify the years with the highest production of Erbium and Ytterbium
CREATE TABLE production_data (element VARCHAR(10),year INT,quantity INT); INSERT INTO production_data VALUES ('Erbium',2015,1200),('Erbium',2016,1500),('Erbium',2017,1800),('Ytterbium',2015,500),('Ytterbium',2016,600),('Ytterbium',2017,700);
SELECT element, MAX(year) AS max_year FROM production_data WHERE element IN ('Erbium', 'Ytterbium') GROUP BY element;
What is the minimum temperature recorded in the Atlantic Ocean?
CREATE TABLE ocean_temperatures (year INTEGER,ocean VARCHAR(255),temperature FLOAT);
SELECT MIN(temperature) FROM ocean_temperatures WHERE ocean = 'Atlantic Ocean';
What are the total sales (in USD) of VR headsets released before 2015?
CREATE TABLE VRSales (HeadsetID INT,Name VARCHAR(20),ReleaseDate DATE,Sales INT); INSERT INTO VRSales (HeadsetID,Name,ReleaseDate,Sales) VALUES (1,'Oculus Rift','2016-03-28',500000),(2,'HTC Vive','2016-04-05',700000),(3,'PlayStation VR','2016-10-13',1000000),(4,'Samsung Gear VR','2015-11-20',200000);
SELECT SUM(Sales) FROM VRSales WHERE ReleaseDate < '2015-01-01';
What is the total number of employees hired from Latinx and Indigenous communities, by year?
CREATE TABLE Employees (EmployeeID INT,HireDate DATE); CREATE TABLE UnderrepresentedCommunities (CommunityID INT,CommunityName VARCHAR(50)); CREATE TABLE EmployeeCommunities (EmployeeID INT,CommunityID INT);
SELECT YEAR(e.HireDate) AS Year, COUNT(DISTINCT e.EmployeeID) FROM Employees e INNER JOIN EmployeeCommunities ec ON e.EmployeeID = ec.EmployeeID INNER JOIN UnderrepresentedCommunities uc ON ec.CommunityID = uc.CommunityID WHERE uc.CommunityName IN ('Latinx', 'Indigenous') GROUP BY YEAR(e.HireDate);
What is the total number of wins of players who played Rocket League in Germany?
CREATE TABLE Players (PlayerID INT,PlayerCountry VARCHAR(20),Game VARCHAR(20),Wins INT); INSERT INTO Players (PlayerID,PlayerCountry,Game,Wins) VALUES (1,'Germany','Rocket League',50),(2,'Germany','Fortnite',60);
SELECT SUM(Wins) FROM Players WHERE Game = 'Rocket League' AND PlayerCountry = 'Germany';
Which biotech startups have received funding from at least 2 different sources and are based in Latin America or the Caribbean?
CREATE TABLE startup_funding (company_name VARCHAR(100),company_location VARCHAR(100),funding_source VARCHAR(50),funding_amount DECIMAL(10,2),funding_date DATE); INSERT INTO startup_funding VALUES ('GreenGeniusBio','Brazil','VC Funding',2000000.00,'2021-02-14'); INSERT INTO startup_funding VALUES ('BioTechMexico','Mexi...
SELECT company_name FROM startup_funding WHERE company_location IN ('Latin America', 'Caribbean') AND funding_source IN (SELECT funding_source FROM startup_funding GROUP BY funding_source HAVING COUNT(DISTINCT funding_source) > 1) GROUP BY company_name HAVING COUNT(DISTINCT funding_source) > 1;
Create a view to display animal species with their population counts
CREATE TABLE animal_population (id INT PRIMARY KEY,species VARCHAR(255),population INT);
CREATE VIEW animal_population_view AS SELECT species, population FROM animal_population;
What is the price difference between the most expensive and least expensive product from each supplier?
CREATE TABLE suppliers (id INT,name VARCHAR(255),location VARCHAR(255),product VARCHAR(255),price DECIMAL(5,2),delivery_date TIMESTAMP); INSERT INTO suppliers (id,name,location,product,price,delivery_date) VALUES (1,'Acme Farms','California','Tomatoes',2.50,'2022-01-05 09:00:00'),(2,'Green Earth','Mexico','Avocados',4....
SELECT name, product, MAX(price) - MIN(price) as price_difference FROM suppliers GROUP BY name;
Delete all records from the 'operators' table where the operator is based in Nigeria.
CREATE TABLE operators (operator_id INT,operator_name TEXT,country TEXT); INSERT INTO operators (operator_id,operator_name,country) VALUES (1,'Operator A','USA'),(2,'Operator B','Canada'),(3,'Operator C','Nigeria');
DELETE FROM operators WHERE country = 'Nigeria';
What is the number of workplaces in total in the state of Pennsylvania?
CREATE TABLE workplaces (id INT,name TEXT,state TEXT); INSERT INTO workplaces (id,name,state) VALUES (1,'DEF Company','Pennsylvania');
SELECT COUNT(*) FROM workplaces WHERE state = 'Pennsylvania';
Insert a new bus route from 'Tokyo' to 'Osaka' with a distance of 500 km and a fare of ¥5000.
CREATE TABLE routes (route_id INT,route_name TEXT); INSERT INTO routes (route_id,route_name) VALUES (101,'Bus Route 101'),(102,'Bus Route 102'),(105,'Bus Route 105'),(501,'Bus Route 501'),(502,'Bus Route 502'); CREATE TABLE bus_routes (route_id INT,start_station TEXT,end_station TEXT,distance INT,fare DECIMAL);
INSERT INTO bus_routes (route_id, start_station, end_station, distance, fare) VALUES (501, 'Tokyo', 'Osaka', 500, 5000);
What is the average temperature in the 'Amazon Rainforest' for the months of January, February, and March in the years 2017 and 2018?
CREATE TABLE Climate_Data (region VARCHAR(20),month INT,year INT,temperature FLOAT); INSERT INTO Climate_Data (region,month,year,temperature) VALUES ('Amazon Rainforest',1,2017,25.5),('Amazon Rainforest',2,2017,26.3);
SELECT AVG(cd.temperature) as avg_temperature FROM Climate_Data cd WHERE cd.region = 'Amazon Rainforest' AND cd.month IN (1, 2, 3) AND cd.year IN (2017, 2018) GROUP BY cd.region;
What is the maximum number of works sold by an artist in a single year?
CREATE TABLE Artists (id INT,name VARCHAR(255)); CREATE TABLE Sales (id INT,artist_id INT,sale_date DATE); CREATE TABLE Works (id INT,artist_id INT,sale_date DATE);
SELECT artist_id, MAX(sales_per_year) FROM (SELECT artist_id, YEAR(sale_date) AS sale_year, COUNT(*) AS sales_per_year FROM Sales JOIN Works ON Sales.id = Works.id GROUP BY artist_id, sale_year) subquery GROUP BY artist_id;
Which countries have launched the most satellites, and how many have they launched?
CREATE TABLE satellites_by_country (id INT,country VARCHAR(255),name VARCHAR(255)); INSERT INTO satellites_by_country (id,country,name) VALUES (1,'USA','Starlink 1'),(2,'New Zealand','Photon 1'),(3,'USA','GPS 3-01'),(4,'Russia','Glonass-M 58'),(5,'China','Beidou-3 M23');
SELECT country, COUNT(*) as num_satellites FROM satellites_by_country GROUP BY country ORDER BY num_satellites DESC;
What is the total installed capacity of hydroelectric power plants in the province of Quebec?
CREATE TABLE hydroelectric_power_plants (id INT,plant_name VARCHAR(50),province VARCHAR(50),installed_capacity FLOAT); INSERT INTO hydroelectric_power_plants (id,plant_name,province,installed_capacity) VALUES (1,'Quebec Hydroelectric Power Plant','Quebec',5000);
SELECT SUM(installed_capacity) FROM hydroelectric_power_plants WHERE province = 'Quebec';
Find the earliest date of articles in 'Technology'
CREATE TABLE articles (id INT,title VARCHAR(100),topic VARCHAR(50),date DATE); INSERT INTO articles (id,title,topic,date) VALUES (1,'Article 1','Politics','2021-01-01'); INSERT INTO articles (id,name,topic,date) VALUES (2,'Article 2','Sports','2021-01-02'); INSERT INTO articles (id,title,topic,date) VALUES (3,'Article ...
SELECT MIN(date) as earliest_date FROM articles WHERE topic = 'Technology';
Which cruelty-free certified cosmetic products have the lowest consumer preference scores in the United Kingdom?
CREATE TABLE uk_cosmetics_preferences (id INT,consumer_id INT,product_id INT,preference_score INT,is_cruelty_free BOOLEAN); INSERT INTO uk_cosmetics_preferences (id,consumer_id,product_id,preference_score,is_cruelty_free) VALUES (1,1,1,5,true);
SELECT p.name, cp.preference_score FROM uk_cosmetics_preferences cp INNER JOIN products p ON cp.product_id = p.id WHERE cp.is_cruelty_free = true ORDER BY cp.preference_score ASC;
List all campaigns that targeted mindfulness-based interventions in the last 3 months.
CREATE TABLE campaigns (campaign_id INT,start_date DATE,end_date DATE,focus VARCHAR(20)); INSERT INTO campaigns (campaign_id,start_date,end_date,focus) VALUES (1,'2022-04-01','2022-06-30','mindfulness-based interventions'),(2,'2022-07-01','2022-08-31','stress management'),(3,'2022-09-01','2022-10-31','self-care');
SELECT * FROM campaigns WHERE focus = 'mindfulness-based interventions' AND start_date <= '2022-04-01' AND end_date >= '2022-04-01';
What is the average age of attendees who visited the art exhibit last month?
CREATE TABLE ArtExhibitAttendees (attendeeID INT,visitDate DATE,age INT); INSERT INTO ArtExhibitAttendees (attendeeID,visitDate,age) VALUES (1,'2022-01-03',35),(2,'2022-01-17',42),(3,'2022-01-25',28);
SELECT AVG(age) FROM ArtExhibitAttendees WHERE visitDate >= '2022-01-01' AND visitDate <= '2022-01-31';
Determine the year-over-year change in water consumption for each city from 2018 to 2019.
CREATE TABLE city_yearly_consumption (id INT,city VARCHAR(50),year INT,yearly_consumption FLOAT); INSERT INTO city_yearly_consumption (id,city,year,yearly_consumption) VALUES (1,'New York',2018,1200000000),(2,'New York',2019,1260000000),(3,'Los Angeles',2018,600000000),(4,'Los Angeles',2019,630000000);
SELECT city, (t2.yearly_consumption - t1.yearly_consumption) * 100.0 / t1.yearly_consumption AS yoy_change FROM city_yearly_consumption t1, city_yearly_consumption t2 WHERE t1.city = t2.city AND t1.year = 2018 AND t2.year = 2019;
What is the average price of sustainably sourced cotton by country?
CREATE TABLE SustainableCotton (country VARCHAR(50),price DECIMAL(10,2));
SELECT country, AVG(price) FROM SustainableCotton GROUP BY country;
Insert a new record into the humanitarian_aid table.
CREATE TABLE humanitarian_aid (id INT PRIMARY KEY,aid_name VARCHAR(50),recipient_country VARCHAR(50),amount_donated DECIMAL(10,2));
INSERT INTO humanitarian_aid (id, aid_name, recipient_country, amount_donated) VALUES (1, 'Food Aid', 'Yemen', 500000.00);
What is the minimum environmental impact score in the last 5 years?
CREATE TABLE environment (id INT,date DATE,score INT); INSERT INTO environment (id,date,score) VALUES (1,'2017-01-01',70),(2,'2017-02-01',75),(3,'2019-01-01',80),(4,'2019-02-01',85),(5,'2021-01-01',90);
SELECT MIN(e.score) AS min_impact_score FROM environment e WHERE e.date >= DATE_SUB(CURDATE(), INTERVAL 5 YEAR);
What is the total population of animals in each habitat type?
CREATE TABLE animals (id INT,species TEXT,population INT,habitat_type TEXT); INSERT INTO animals (id,species,population,habitat_type) VALUES (1,'Tiger',1200,'Forest'),(2,'Elephant',1500,'Savannah'),(3,'Rhinoceros',800,'Wetlands');
SELECT habitat_type, SUM(population) as total_population FROM animals GROUP BY habitat_type;
Find the total installed capacity of wind and solar power plants in Germany and France.
CREATE TABLE wind_plants (country VARCHAR(20),capacity INT); INSERT INTO wind_plants (country,capacity) VALUES ('Germany',50000),('France',30000); CREATE TABLE solar_plants (country VARCHAR(20),capacity INT); INSERT INTO solar_plants (country,capacity) VALUES ('Germany',70000),('France',60000);
SELECT SUM(capacity) FROM wind_plants WHERE country IN ('Germany', 'France') UNION ALL SELECT SUM(capacity) FROM solar_plants WHERE country IN ('Germany', 'France');
What are the average safety inspection scores for each manufacturing site, grouped by month?
CREATE TABLE ManufacturingSite(Id INT,Name VARCHAR(50),Location VARCHAR(50)); CREATE TABLE SafetyInspectionScore(Id INT,Score INT,ManufacturingSiteId INT,InspectionDate DATE);
SELECT m.Name, DATE_FORMAT(s.InspectionDate, '%Y-%m') AS Month, AVG(s.Score) AS AverageScore FROM SafetyInspectionScore s JOIN ManufacturingSite m ON s.ManufacturingSiteId = m.Id GROUP BY m.Name, Month;
Who are the top 5 cities with the most police officers in Texas, and what is the number of officers in each city?
CREATE TABLE Cities (CityName TEXT,CityID INTEGER); CREATE TABLE PoliceStations (StationID INTEGER,StationCityID INTEGER); CREATE TABLE PoliceOfficers (OfficerID INTEGER,OfficerStationID INTEGER,OfficerSalary INTEGER);
SELECT C.CityName, COUNT(PO.OfficerID) FROM Cities C INNER JOIN PoliceStations PS ON C.CityID = PS.StationCityID INNER JOIN PoliceOfficers PO ON PS.StationID = PO.OfficerStationID WHERE C.State = 'Texas' GROUP BY C.CityName ORDER BY COUNT(PO.OfficerID) DESC LIMIT 5;
What is the total installed capacity of wind power projects in the 'renewables' schema, grouped by country?
CREATE SCHEMA if not exists renewables; Use renewables; CREATE TABLE if not exists wind_projects (project_id INT,country VARCHAR(50),installed_capacity INT); INSERT INTO wind_projects (project_id,country,installed_capacity) VALUES (1,'Germany',20000),(2,'Spain',15000),(3,'France',25000);
SELECT country, SUM(installed_capacity) FROM wind_projects GROUP BY country;
What is the average acquisition cost of artworks in the modern art category, grouped by museum?
CREATE TABLE artworks (id INT,museum_id INT,category VARCHAR(255),acquisition_cost INT); CREATE TABLE museums (id INT,name VARCHAR(255),city VARCHAR(255),state VARCHAR(255));
SELECT m.name, AVG(acquisition_cost) FROM artworks a JOIN museums m ON a.museum_id = m.id WHERE category = 'Modern Art' GROUP BY m.name;
What is the percentage of Yttrium exported from India to other countries annually?
CREATE TABLE YttriumExport(year INT,country VARCHAR(50),percentage DECIMAL(5,2)); INSERT INTO YttriumExport(year,country,percentage) VALUES (2018,'India',22.5),(2018,'USA',15.0),(2018,'China',40.0),(2019,'India',25.0),(2019,'USA',16.0),(2019,'China',39.0);
SELECT (SUM(percentage) FILTER (WHERE country = 'India'))/SUM(percentage) FROM YttriumExport;
Who are the top 5 content creators in terms of post engagement in the sports genre?
CREATE TABLE content_creators (creator_id INT,creator_name VARCHAR(50),genre VARCHAR(50),post_count INT,engagement DECIMAL(10,2)); INSERT INTO content_creators VALUES (109,'Creator 1','Sports',55,2500),(110,'Creator 2','Sports',40,2000),(111,'Creator 3','Music',60,800),(112,'Creator 4','Sports',50,3000),(113,'Creator 5...
SELECT creator_name, SUM(engagement) as total_engagement FROM content_creators WHERE genre = 'Sports' GROUP BY creator_name ORDER BY total_engagement DESC LIMIT 5;
What is the total number of tickets sold for football games in the Midwest region?
CREATE TABLE tickets (ticket_id INT,game_id INT,region VARCHAR(50),quantity INT); INSERT INTO tickets (ticket_id,game_id,region,quantity) VALUES (1,1,'Midwest',500); INSERT INTO tickets (ticket_id,game_id,region,quantity) VALUES (2,2,'Northeast',700); CREATE TABLE games (game_id INT,sport VARCHAR(50)); INSERT INTO game...
SELECT SUM(quantity) FROM tickets INNER JOIN games ON tickets.game_id = games.game_id WHERE region = 'Midwest' AND sport = 'Football';
How many volunteers signed up for each organization in Q3 of 2022?
CREATE TABLE volunteers (id INT,volunteer_name TEXT,organization TEXT,signup_date DATE); INSERT INTO volunteers (id,volunteer_name,organization,signup_date) VALUES (1,'Alice','Doctors Without Borders','2022-07-05'); INSERT INTO volunteers (id,volunteer_name,organization,signup_date) VALUES (2,'Bob','Greenpeace','2022-1...
SELECT organization, COUNT(volunteer_name) as num_volunteers FROM volunteers WHERE signup_date >= '2022-07-01' AND signup_date < '2022-10-01' GROUP BY organization;
Insert a new green building with ID 8 in Portland, OR with a size of 15000
CREATE TABLE green_buildings (building_id INT,city VARCHAR(50),size INT);
INSERT INTO green_buildings (building_id, city, size) VALUES (8, 'Portland', 15000);
What is the maximum investment in each sector?
CREATE TABLE strategies (id INT,sector VARCHAR(20),investment FLOAT); INSERT INTO strategies (id,sector,investment) VALUES (1,'Education',50000.0),(2,'Healthcare',75000.0),(3,'Education',100000.0);
SELECT sector, MAX(investment) FROM strategies GROUP BY sector;
What safety measures are required for 'Nitric Acid' in China?
CREATE TABLE Chemicals (Id INT,Name VARCHAR(255),Manufacturing_Country VARCHAR(255)); CREATE TABLE Safety_Protocols (Id INT,Chemical_Id INT,Safety_Measure VARCHAR(255)); INSERT INTO Chemicals (Id,Name,Manufacturing_Country) VALUES (1,'Nitric Acid','China'); INSERT INTO Safety_Protocols (Id,Chemical_Id,Safety_Measure) V...
SELECT Chemicals.Name, Safety_Protocols.Safety_Measure FROM Chemicals INNER JOIN Safety_Protocols ON Chemicals.Id = Safety_Protocols.Chemical_Id WHERE Chemicals.Name = 'Nitric Acid' AND Chemicals.Manufacturing_Country = 'China';