instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the total area of all wildlife habitats in hectares?
CREATE TABLE habitat (id INT,name VARCHAR(255),area_ha INT); INSERT INTO habitat (id,name,area_ha) VALUES (1,'Habitat1',5000),(2,'Habitat2',7000),(3,'Habitat3',6000);
SELECT SUM(area_ha) FROM habitat;
What is the total number of military personnel in the 'Army' table?
CREATE TABLE Army (id INT,name VARCHAR(50),rank VARCHAR(20),region VARCHAR(20),num_personnel INT); INSERT INTO Army (id,name,rank,region,num_personnel) VALUES (1,'John Doe','Colonel','Europe',500);
SELECT SUM(num_personnel) FROM Army;
How many cultural heritage sites in Italy have more than 5,000 annual visitors?
CREATE TABLE cultural_heritage (id INT,site VARCHAR(50),country VARCHAR(20),annual_visitors INT); INSERT INTO cultural_heritage (id,site,country,annual_visitors) VALUES (1,'Colosseum','Italy',6000),(2,'Leaning Tower of Pisa','Italy',4000),(3,'Roman Forum','Italy',5500);
SELECT COUNT(*) FROM cultural_heritage WHERE country = 'Italy' GROUP BY country HAVING SUM(annual_visitors) > 5000;
What is the total number of shared bikes and e-scooters in San Francisco?
CREATE TABLE ride_sharing (id INT,vehicle VARCHAR(20),city VARCHAR(20)); INSERT INTO ride_sharing (id,vehicle,city) VALUES (1,'bike','San Francisco'),(2,'e-scooter','San Francisco');
SELECT SUM(CASE WHEN vehicle IN ('bike', 'e-scooter') THEN 1 ELSE 0 END) FROM ride_sharing WHERE city = 'San Francisco';
List all companies that have a 'recycling' program and their corresponding program start dates.
CREATE TABLE companies (company_id INT,name VARCHAR(30),recycling_program BOOLEAN,recycling_program_start_date DATE);
SELECT companies.name, companies.recycling_program_start_date FROM companies WHERE companies.recycling_program = TRUE;
Calculate the total sustainable sourcing cost per location.
CREATE TABLE Locations (Location_ID INT,Location_Name TEXT); INSERT INTO Locations (Location_ID,Location_Name) VALUES (1,'Location1'),(2,'Location2'); CREATE TABLE Sustainable_Sourcing (Source_ID INT,Location_ID INT,Cost DECIMAL); INSERT INTO Sustainable_Sourcing (Source_ID,Location_ID,Cost) VALUES (1,1,100.00),(2,1,200.00),(3,2,300.00),(4,2,400.00);
SELECT L.Location_Name, SUM(SS.Cost) as Total_Sustainable_Cost FROM Sustainable_Sourcing SS JOIN Locations L ON SS.Location_ID = L.Location_ID GROUP BY L.Location_Name;
What is the number of policies and total claim amount for policyholders in 'CO'?
CREATE TABLE Policyholders (PolicyID INT,PolicyholderName TEXT,State TEXT); INSERT INTO Policyholders (PolicyID,PolicyholderName,State) VALUES (1,'John Smith','CO'),(2,'Jane Doe','NY'); CREATE TABLE Claims (ClaimID INT,PolicyID INT,ClaimAmount INT); INSERT INTO Claims (ClaimID,PolicyID,ClaimAmount) VALUES (1,1,5000),(2,1,3000),(3,2,7000);
SELECT COUNT(Policyholders.PolicyID) AS NumPolicies, SUM(Claims.ClaimAmount) AS TotalClaimAmount FROM Policyholders INNER JOIN Claims ON Policyholders.PolicyID = Claims.PolicyID WHERE Policyholders.State = 'CO';
List all artworks in the 'Surrealism' genre, along with the name of the artist who created each artwork.
CREATE TABLE Artwork (artwork_id INT,artwork_name VARCHAR(30),genre VARCHAR(20),artist_id INT); CREATE TABLE Artist (artist_id INT,artist_name VARCHAR(30));
SELECT Artwork.artwork_name, Artist.artist_name FROM Artwork INNER JOIN Artist ON Artwork.artist_id = Artist.artist_id WHERE Artwork.genre = 'Surrealism';
Insert new records into the Policyholders, LifeInsurance, and HealthInsurance tables for a new policyholder who lives in California.
CREATE TABLE Policyholders (PolicyholderID INT,Name VARCHAR(50),Address VARCHAR(100),State VARCHAR(2)); CREATE TABLE LifeInsurance (PolicyholderID INT,PolicyType VARCHAR(50)); CREATE TABLE HealthInsurance (PolicyholderID INT,PolicyType VARCHAR(50));
INSERT INTO Policyholders (PolicyholderID, Name, Address, State) VALUES (5, 'Maria Garcia', '910 Olive Ave', 'CA'); INSERT INTO LifeInsurance (PolicyholderID, PolicyType) VALUES (5, 'Whole Life'); INSERT INTO HealthInsurance (PolicyholderID, PolicyType) VALUES (5, 'PPO');
Number of renewable energy projects in Latin America
CREATE TABLE renewable_energy_projects (id INT,project_name VARCHAR(255),country VARCHAR(255),technology VARCHAR(255),start_date DATE,end_date DATE);
SELECT COUNT(*) FROM renewable_energy_projects WHERE country IN ('Brazil', 'Colombia', 'Argentina', 'Chile', 'Peru') AND technology != 'Fossil';
How many garments are made of hemp in India?
CREATE TABLE production (id INT,garment_id INT,country VARCHAR(255),material VARCHAR(255)); INSERT INTO production (id,garment_id,country,material) VALUES
SELECT COUNT(*) FROM production WHERE material = 'Hemp' AND country = 'India';
Calculate the average number of cases per court in the justice system
CREATE TABLE courts (court_id INT,court_name VARCHAR(255),PRIMARY KEY (court_id)); CREATE TABLE court_cases (court_id INT,case_id INT,PRIMARY KEY (court_id,case_id),FOREIGN KEY (court_id) REFERENCES courts(court_id),FOREIGN KEY (case_id) REFERENCES cases(case_id)); INSERT INTO courts (court_id,court_name) VALUES (1,'Court 1'),(2,'Court 2'),(3,'Court 3'); INSERT INTO court_cases (court_id,case_id) VALUES (1,1),(1,2),(2,3),(3,4);
SELECT AVG(cc.court_id) FROM courts c INNER JOIN court_cases cc ON c.court_id = cc.court_id;
Vendors with the highest quantity of organic food sold
CREATE TABLE Vendor (VendorID INT,VendorName VARCHAR(50),FarmID INT); INSERT INTO Vendor (VendorID,VendorName,FarmID) VALUES (1,'EcoMarket',1),(2,'NaturalHarvest',2),(3,'GreenBasket',1); CREATE TABLE Sales (VendorID INT,ItemID INT,Quantity INT); INSERT INTO Sales (VendorID,ItemID,Quantity) VALUES (1,1,500),(2,2,700),(3,1,600);
SELECT v.VendorName, SUM(s.Quantity) FROM Vendor v INNER JOIN Sales s ON v.VendorID = s.VendorID INNER JOIN OrganicFarm f ON v.FarmID = f.FarmID GROUP BY v.VendorName ORDER BY SUM(s.Quantity) DESC;
Update the name of the record with id 7 in the table "marine_protected_areas" to 'Coral Reefs'
CREATE TABLE marine_protected_areas (id INT,name VARCHAR(50),size FLOAT,country VARCHAR(50));
UPDATE marine_protected_areas SET name = 'Coral Reefs' WHERE id = 7;
Which biosensors were developed in '2021'?
CREATE TABLE Biosensor (biosensor_id INT,name TEXT,year INT); INSERT INTO Biosensor (biosensor_id,name,year) VALUES (1,'BS1',2019),(2,'BS2',2021),(3,'BS3',2018);
SELECT name FROM Biosensor WHERE year = 2021;
What is the total donation amount for each organization in the 'Donations' and 'Organizations' tables?
CREATE TABLE Donations (donation_id INT,org_id INT,donation_amount DECIMAL(10,2));
SELECT O.name, SUM(D.donation_amount) FROM Donations D INNER JOIN Organizations O ON D.org_id = O.org_id GROUP BY O.name;
What is the maximum number of goals scored by a single player in a game in each of the last five seasons in the Premier League?
CREATE TABLE premier_league_seasons (season_id INT,season_start_date DATE,season_end_date DATE); CREATE TABLE premier_league_games (game_id INT,season_id INT,home_team VARCHAR(100),away_team VARCHAR(100),home_team_goals INT,away_team_goals INT);
SELECT s.season_start_date, MAX(g.home_team_goals) as max_goals FROM premier_league_seasons s JOIN premier_league_games g ON s.season_id = g.season_id WHERE s.season_id >= (SELECT MAX(season_id) - 5) GROUP BY s.season_start_date;
What are the names and locations of all whale sanctuaries?
CREATE TABLE whale_sanctuaries (name VARCHAR(255),location VARCHAR(255)); INSERT INTO whale_sanctuaries (name,location) VALUES ('SSS','North Atlantic');
SELECT name, location FROM whale_sanctuaries
How many patients participated in clinical trial 'Trial-A' for drug 'ABC-456'?
CREATE TABLE clinical_trials (trial_name TEXT,drug_name TEXT,patient_count INT); INSERT INTO clinical_trials (trial_name,drug_name,patient_count) VALUES ('Trial-A','ABC-456',200),('Trial-B','DEF-789',300);
SELECT patient_count FROM clinical_trials WHERE trial_name = 'Trial-A' AND drug_name = 'ABC-456';
What is the total number of unions in the 'Africa' region with 'Craft' as their union type?
CREATE TABLE Labor_Unions (id INT,union_type VARCHAR(20),region VARCHAR(20)); INSERT INTO Labor_Unions (id,union_type,region) VALUES (1,'Craft','Africa'),(2,'Professional','Americas'),(3,'Craft','Europe'),(4,'Industrial','Asia');
SELECT COUNT(*) FROM Labor_Unions WHERE union_type = 'Craft' AND region = 'Africa';
What is the maximum number of military satellites owned by each country?
CREATE TABLE countries (id INT,name VARCHAR(255)); CREATE TABLE military_satellites (id INT,country_id INT,number INT);
SELECT c.name, MAX(ms.number) as max_satellites FROM countries c JOIN military_satellites ms ON c.id = ms.country_id GROUP BY c.id;
Delete all records from the 'stations' table where the 'station_type' is 'Underground'
CREATE TABLE stations (station_id INT,station_name VARCHAR(50),station_type VARCHAR(20)); INSERT INTO stations (station_id,station_name,station_type) VALUES (1,'StationA','Underground'),(2,'StationB','Overground'),(3,'StationC','Underground');
DELETE FROM stations WHERE station_type = 'Underground';
What is the total revenue for the 'Vegan Dishes' category?
CREATE TABLE menus (id INT,name VARCHAR(255),category VARCHAR(255),price DECIMAL(5,2)); INSERT INTO menus (id,name,category,price) VALUES (1,'Veggie Burger','Vegan Dishes',8.99),(2,'Chickpea Curry','Vegan Dishes',10.99),(3,'Tofu Stir Fry','Vegan Dishes',12.49);
SELECT SUM(price) FROM menus WHERE category = 'Vegan Dishes';
What is the total revenue for each game in the 'action' genre?
CREATE TABLE games (id INT,name VARCHAR(100),genre VARCHAR(50),revenue FLOAT); INSERT INTO games (id,name,genre,revenue) VALUES (1,'GameA','action',5000000),(2,'GameB','rpg',7000000),(3,'GameC','action',8000000);
SELECT genre, SUM(revenue) FROM games WHERE genre = 'action' GROUP BY genre;
How many volunteers engaged in each program in Q1 2021?
CREATE TABLE Volunteers (id INT,volunteer VARCHAR(50),program VARCHAR(50),hours FLOAT,volunteer_date DATE); INSERT INTO Volunteers (id,volunteer,program,hours,volunteer_date) VALUES (1,'Alice','Education',10,'2021-01-01'); INSERT INTO Volunteers (id,volunteer,program,hours,volunteer_date) VALUES (2,'Bob','Environment',15,'2021-02-01');
SELECT program, COUNT(DISTINCT volunteer) as num_volunteers FROM Volunteers WHERE QUARTER(volunteer_date) = 1 AND YEAR(volunteer_date) = 2021 GROUP BY program;
What is the average productivity of workers per mineral?
CREATE TABLE worker_productivity (worker_id INT,worker_name TEXT,mineral TEXT,productivity DECIMAL); INSERT INTO worker_productivity (worker_id,worker_name,mineral,productivity) VALUES (1,'John','Gold',5.0),(2,'Jane','Gold',5.5),(3,'Bob','Silver',4.8),(4,'Alice','Silver',5.2),(5,'Charlie','Copper',4.5),(6,'David','Copper',4.7);
SELECT mineral, AVG(productivity) FROM worker_productivity GROUP BY mineral;
What are the labor productivity metrics for mining in India and Russia in 2020?
CREATE TABLE LaborProductivity (Country VARCHAR(255),Year INT,Sector VARCHAR(255),Productivity DECIMAL(5,2)); INSERT INTO LaborProductivity (Country,Year,Sector,Productivity) VALUES ('India',2020,'Mining',40.00),('India',2020,'Mining',45.00),('Russia',2020,'Mining',55.00),('Russia',2020,'Mining',60.00);
SELECT Context.Country, Context.Productivity FROM LaborProductivity as Context WHERE Context.Year = 2020 AND Context.Sector = 'Mining' AND Context.Country IN ('India', 'Russia');
What are the names and locations of all dams in Washington state, along with their respective construction companies and the year they were constructed?
CREATE TABLE Dams (DamID INT,Name VARCHAR(255),State VARCHAR(255),Company VARCHAR(255),ConstructionYear INT); INSERT INTO Dams VALUES (1,'Dam A','Washington','DAMCON',1985); INSERT INTO Dams VALUES (2,'Dam B','Oregon','DAMCO',1990); INSERT INTO Dams VALUES (3,'Dam C','Washington','DAMS Inc.',1995);
SELECT Name, State, Company, ConstructionYear FROM Dams WHERE State = 'Washington';
Which performing arts event has the highest average attendance?
CREATE TABLE if not exists performing_arts_attendance (id INT,name VARCHAR(255),type VARCHAR(255),attendees INT); INSERT INTO performing_arts_attendance (id,name,type,attendees) VALUES (1,'Symphony','Performing Arts',250),(2,'Opera','Performing Arts',180),(3,'Ballet','Performing Arts',320),(4,'Theater','Performing Arts',150);
SELECT type, AVG(attendees) FROM performing_arts_attendance WHERE type = 'Performing Arts' GROUP BY type ORDER BY AVG(attendees) DESC LIMIT 1;
What is the average conservation priority of marine species in the Southern Ocean?
CREATE TABLE species (name VARCHAR(255),conservation_priority FLOAT,region VARCHAR(255)); INSERT INTO species (name,conservation_priority,region) VALUES ('Krill',0.6,'Southern Ocean'),('Blue Whale',0.55,'Southern Ocean'),('Orca',0.5,'Southern Ocean'),('Seal',0.45,'Southern Ocean'),('Penguin',0.4,'Southern Ocean');
SELECT AVG(conservation_priority) FROM species WHERE region = 'Southern Ocean';
What was the maximum donation amount from corporate donors in the Central region in 2022?
CREATE TABLE DonorContributions (donor_id INT,donation_amount DECIMAL(10,2),donation_date DATE,region VARCHAR(50),donor_type VARCHAR(50)); INSERT INTO DonorContributions (donor_id,donation_amount,donation_date,region,donor_type) VALUES (25,10000,'2022-01-01','Central','Corporate'),(26,12000,'2022-02-01','Central','Corporate'),(27,8000,'2022-03-01','Central','Individual');
SELECT MAX(donation_amount) FROM DonorContributions WHERE region = 'Central' AND donation_date BETWEEN '2022-01-01' AND '2022-12-31' AND donor_type = 'Corporate';
What was the total budget allocated for environmental services in 2020, 2021, and 2022?
CREATE TABLE EnvBudget (Year INT,Amount INT); INSERT INTO EnvBudget (Year,Amount) VALUES (2020,1200000),(2021,1300000),(2022,1400000);
SELECT Year, SUM(Amount) FROM EnvBudget GROUP BY Year;
What is the distribution of ESG ratings for companies in the technology sector?
CREATE TABLE companies (id INT,name TEXT,sector TEXT,ESG_rating FLOAT); INSERT INTO companies (id,name,sector,ESG_rating) VALUES (1,'Apple','Technology',8.2),(2,'Microsoft','Technology',8.5),(3,'Google','Technology',8.3),(4,'Amazon','Technology',7.9),(5,'Facebook','Technology',7.7);
SELECT sector, ESG_rating, COUNT(*) AS rating_count FROM companies GROUP BY sector, ESG_rating ORDER BY sector, ESG_rating;
Locations with more than 1 renewable energy project
CREATE TABLE renewable_energy_projects (id INT,name VARCHAR(255),location VARCHAR(255),capacity FLOAT); INSERT INTO renewable_energy_projects (id,name,location,capacity) VALUES (1,'SolarFarm1','CityA',1000),(2,'WindFarm1','CityB',2000),(3,'SolarFarm2','CityA',1500),(4,'WindFarm2','CityB',2500),(5,'HydroPower1','CityC',3000);
SELECT location, COUNT(*) as num_projects FROM renewable_energy_projects GROUP BY location HAVING COUNT(*) > 1;
What is the total landfill capacity in the province of Ontario in 2022?
CREATE TABLE landfill_capacity (province VARCHAR(255),year INT,capacity INT); INSERT INTO landfill_capacity (province,year,capacity) VALUES ('Ontario',2022,5000000);
SELECT SUM(capacity) FROM landfill_capacity WHERE province = 'Ontario' AND year = 2022;
Identify the number of electric vehicles in Los Angeles per day.
CREATE TABLE la_evs (id INT,vehicle_type VARCHAR(20),registration_date DATE);
SELECT DATE(registration_date) AS registration_day, COUNT(*) FROM la_evs WHERE vehicle_type = 'electric' GROUP BY registration_day;
Show the number of donors, total donation amount, and the average number of hours contributed by volunteers for each organization in the 'organizations' table.
CREATE TABLE donors (donor_id INT,donor_name TEXT,donation_amount DECIMAL,org_id INT); CREATE TABLE volunteers (volunteer_id INT,hours_contributed INT,org_id INT); CREATE TABLE organizations (org_id INT,org_name TEXT);
SELECT organizations.org_name, COUNT(donors.donor_id) as num_donors, SUM(donors.donation_amount) as total_donations, AVG(volunteers.hours_contributed) as avg_hours_contributed FROM donors INNER JOIN organizations ON donors.org_id = organizations.org_id INNER JOIN volunteers ON organizations.org_id = volunteers.org_id GROUP BY organizations.org_name;
Find the total installed capacity (in MW) of Wind Farms in the region 'West'
CREATE TABLE wind_farms (id INT,name VARCHAR(100),region VARCHAR(10),capacity FLOAT); INSERT INTO wind_farms (id,name,region,capacity) VALUES (1,'Wind Farm A','West',150.5); INSERT INTO wind_farms (id,name,region,capacity) VALUES (2,'Wind Farm B','East',120.3);
SELECT SUM(capacity) FROM wind_farms WHERE region = 'West';
How many destinations are marketed by each destination marketing organization?
CREATE TABLE dmo (id INT,name TEXT,region TEXT); CREATE TABLE dmo_markets (id INT,dmo_id INT,destination TEXT); INSERT INTO dmo (id,name,region) VALUES (1,'Tourism Australia','Australia'),(2,'Japan National Tourism Organization','Japan'); INSERT INTO dmo_markets (id,dmo_id,destination) VALUES (1,1,'Sydney'),(2,1,'Melbourne'),(3,2,'Tokyo'),(4,2,'Osaka');
SELECT dmo.name, COUNT(dmo_markets.destination) FROM dmo INNER JOIN dmo_markets ON dmo.id = dmo_markets.dmo_id GROUP BY dmo.name;
What is the total biomass of marine life in the Indian Ocean?
CREATE TABLE marine_life (life_id INT,life_name VARCHAR(50),region VARCHAR(50),biomass INT); INSERT INTO marine_life (life_id,life_name,region) VALUES (1,'Shark','Indian Ocean'),(2,'Tuna','Indian Ocean');
SELECT SUM(biomass) FROM marine_life WHERE region = 'Indian Ocean';
Update the viewership count for TV Show 'The Crown' to 12 million
CREATE TABLE tv_shows (id INT,title VARCHAR(100),viewership_count INT); INSERT INTO tv_shows (id,title,viewership_count) VALUES (1,'The Mandalorian',8000000); INSERT INTO tv_shows (id,title,viewership_count) VALUES (2,'The Crown',10000000);
UPDATE tv_shows SET viewership_count = 12000000 WHERE title = 'The Crown';
What is the total number of volunteers from underrepresented communities who engaged in 2022?
CREATE TABLE volunteers (volunteer_id INT,volunteer_name VARCHAR(50),volunteer_region VARCHAR(50),volunteer_hours DECIMAL(10,2),volunteer_date DATE);
SELECT COUNT(*) FROM volunteers WHERE YEAR(volunteer_date) = 2022 AND volunteer_region IN ('Indigenous', 'Latinx', 'Black', 'Asian Pacific Islander', 'LGBTQ+');
What is the minimum and maximum funding amount for startups founded by women in the AI sector?
CREATE TABLE startups(id INT,name TEXT,industry TEXT,founder_gender TEXT,funding FLOAT); INSERT INTO startups(id,name,industry,founder_gender,funding) VALUES (1,'WomenInAI','AI','Female',1000000);
SELECT MIN(funding), MAX(funding) FROM startups WHERE industry = 'AI' AND founder_gender = 'Female';
List all the cybersecurity strategies related to 'Risk Management' in the 'Cybersecurity' schema.
CREATE SCHEMA IF NOT EXISTS Cybersecurity; CREATE TABLE IF NOT EXISTS Cybersecurity.Cyber_Strategies (strategy_id INT,strategy_name VARCHAR(255),description TEXT); INSERT INTO Cybersecurity.Cyber_Strategies (strategy_id,strategy_name,description) VALUES (1,'NIST Cybersecurity Framework','Provides guidelines for managing cybersecurity risks'),(2,'CIS Critical Security Controls','Set of 20 actions to stop the most common cyber attacks'),(3,'ISO 27001/27002','Information security management system standard');
SELECT * FROM Cybersecurity.Cyber_Strategies WHERE description LIKE '%Risk Management%';
How many new garment types have been introduced in the African market in the last 6 months?
CREATE TABLE garment_releases (id INT,garment_type VARCHAR(255),region VARCHAR(255),release_date DATE); INSERT INTO garment_releases (id,garment_type,region,release_date) VALUES (1,'Ankara Dress','Africa','2022-01-01'),(2,'Kente Cloth Pants','Africa','2022-02-01'),(3,'Dashiki Shirt','Africa','2022-03-01');
SELECT COUNT(*) as num_new_garment_types FROM garment_releases WHERE region = 'Africa' AND release_date >= DATEADD(month, -6, CURRENT_TIMESTAMP);
Show the number of unique vehicle types in the vehicles table, ordered from highest to lowest
CREATE TABLE vehicles (vehicle_id INT,vehicle_type VARCHAR(50)); INSERT INTO vehicles (vehicle_id,vehicle_type) VALUES (1000,'Bus'),(1001,'Tram'),(1002,'Bus'),(1003,'Tram'),(1004,'Trolleybus');
SELECT COUNT(DISTINCT vehicle_type) FROM vehicles GROUP BY vehicle_type ORDER BY COUNT(DISTINCT vehicle_type) DESC;
Count the number of vessels for each fuel type in the fleet
CREATE TABLE Vessels (Id INT,Name VARCHAR(50),FuelType VARCHAR(20)); INSERT INTO Vessels (Id,Name,FuelType) VALUES (1,'Vessel1','Diesel'),(2,'Vessel2','LNG'),(3,'Vessel3','Diesel'),(4,'Vessel4','Hydrogen');
SELECT FuelType, COUNT(*) FROM Vessels GROUP BY FuelType;
Delete all records from the 'oil_platforms' table where the water_depth_ft is greater than 4000
CREATE TABLE oil_platforms (platform_id INT PRIMARY KEY,platform_name VARCHAR(255),water_depth_ft INT,operational_status VARCHAR(50));
DELETE FROM oil_platforms WHERE water_depth_ft > 4000;
Calculate the average claim amount for policyholders from Quebec who have a home or life insurance policy, and order the results by the average claim amount in ascending order.
CREATE TABLE Policyholder (PolicyholderID INT,State VARCHAR(255),PolicyType VARCHAR(255),ClaimAmount DECIMAL(10,2)); INSERT INTO Policyholder VALUES (1,'QC','Home',5000),(2,'NY','Home',7000),(3,'NJ','Auto',8000),(4,'CA','Life',6000),(5,'QC','Life',9000);
SELECT PolicyType, AVG(ClaimAmount) as AvgClaimAmount FROM Policyholder WHERE State = 'QC' AND PolicyType IN ('Home', 'Life') GROUP BY PolicyType ORDER BY AvgClaimAmount ASC;
Number of mental health providers per 100,000 people in rural California?
CREATE TABLE mental_health_providers (id INT,state VARCHAR(20),rural BOOLEAN,population INT,providers INT); INSERT INTO mental_health_providers (id,state,rural,population,providers) VALUES (1,'California',true,1000000,800),(2,'California',false,2000000,1500),(3,'Oregon',true,500000,400);
SELECT (providers * 100000.0 / population) FROM mental_health_providers WHERE state = 'California' AND rural = true;
How many pallets were shipped from each warehouse in the first quarter of 2022?
CREATE TABLE Warehouses (id INT,name VARCHAR(50)); INSERT INTO Warehouses (id,name) VALUES (1,'Seattle'),(2,'Toronto'),(3,'Mexico City'); CREATE TABLE Shipments (id INT,warehouse_id INT,pallets INT,shipment_date DATE); INSERT INTO Shipments (id,warehouse_id,pallets,shipment_date) VALUES (1,1,50,'2022-01-01'),(2,1,75,'2022-01-15'),(3,2,100,'2022-02-01');
SELECT Warehouses.name, SUM(Shipments.pallets) AS total_pallets FROM Warehouses INNER JOIN Shipments ON Warehouses.id = Shipments.warehouse_id WHERE Shipments.shipment_date >= '2022-01-01' AND Shipments.shipment_date < '2022-04-01' GROUP BY Warehouses.name;
What is the total number of animals rescued by each organization in the last 3 years?
CREATE TABLE animal_rescue_data (organization VARCHAR(255),year INT,animals_rescued INT);
SELECT organization, SUM(animals_rescued) FROM animal_rescue_data WHERE year BETWEEN 2020 AND 2022 GROUP BY organization;
Identify top 2 most expensive gene sequencing costs in Germany.
CREATE TABLE gene_sequencing_costs (id INT,lab_name TEXT,country TEXT,cost FLOAT); INSERT INTO gene_sequencing_costs (id,lab_name,country,cost) VALUES (1,'Lab1','Germany',55000.0),(2,'Lab2','Germany',60000.0),(3,'Lab3','France',45000.0);
SELECT lab_name, cost FROM (SELECT lab_name, cost, RANK() OVER (ORDER BY cost DESC) as rank FROM gene_sequencing_costs WHERE country = 'Germany') sub WHERE rank <= 2;
What is the median time to resolve cases using restorative justice methods?
CREATE TABLE Cases (ID INT,CaseNumber INT,DateOpened DATE,DateClosed DATE,Resolution VARCHAR(255)); INSERT INTO Cases (ID,CaseNumber,DateOpened,DateClosed,Resolution) VALUES (1,12345,'2022-01-01','2022-03-15','Restorative Justice'),(2,67890,'2022-02-15','2022-04-30','Trial'),(3,111213,'2022-03-28',NULL,'Mediation');
SELECT AVG(DATEDIFF(DateClosed, DateOpened)) as MedianTimeToResolve FROM Cases WHERE Resolution = 'Restorative Justice' AND DateClosed IS NOT NULL;
Show the number of records in the Inventory table where the warehouse_id is 101
CREATE TABLE Inventory (item_id INT,item_name VARCHAR(50),quantity INT,warehouse_id INT);
SELECT COUNT(*) FROM Inventory WHERE warehouse_id = 101;
What is the average temperature change in the Arctic Circle for each year, including the total number of measurements taken?
CREATE TABLE weather_data (measurement_id INT,measurement_date DATE,temperature FLOAT,location VARCHAR(50));
SELECT AVG(temperature) AS avg_temperature_change, YEAR(measurement_date) AS year, COUNT(*) AS total_measurements FROM weather_data WHERE location LIKE '%Arctic Circle%' GROUP BY year;
Delete defense contracts for 'Brazil' with status 'Expired'
CREATE TABLE defense_contracts (cont_id INT,cont_name VARCHAR(50),proj_id INT,cont_status VARCHAR(50),cont_end_date DATE); INSERT INTO defense_contracts (cont_id,cont_name,proj_id,cont_status,cont_end_date) VALUES (1,'Army Modernization',1,'Expired','2022-01-01');
DELETE FROM defense_contracts WHERE cont_status = 'Expired' AND region = 'Brazil';
Insert a new record into the Turtles table for the Leatherback Turtle, with the ocean being the Atlantic Ocean and a population of 45000.
CREATE TABLE Turtles (Species VARCHAR(255),Ocean VARCHAR(255),Population INT);
INSERT INTO Turtles (Species, Ocean, Population) VALUES ('Leatherback Turtle', 'Atlantic Ocean', 45000);
What is the total number of visitors who attended the 'Digital Art' exhibition and are from the USA?
CREATE TABLE Visitors (id INT,country VARCHAR(50),exhibition_id INT); CREATE TABLE Exhibitions (id INT,name VARCHAR(50)); INSERT INTO Exhibitions (id,name) VALUES (1,'Digital Art'); ALTER TABLE Visitors ADD FOREIGN KEY (exhibition_id) REFERENCES Exhibitions(id);
SELECT COUNT(*) FROM Visitors WHERE exhibition_id = 1 AND country = 'USA';
What is the average digital divide index for rural and urban areas?
CREATE TABLE Digital_Divide (area VARCHAR(50),region VARCHAR(50),index INT); INSERT INTO Digital_Divide (area,region,index) VALUES ('Rural','Africa',70),('Urban','Africa',50),('Rural','Asia',60),('Urban','Asia',40),('Rural','South America',50),('Urban','South America',30),('Rural','Europe',40),('Urban','Europe',20),('Rural','North America',30),('Urban','North America',10);
SELECT area, AVG(index) as avg_index FROM Digital_Divide GROUP BY area;
What is the maximum popularity score for each category in the food trends table?
CREATE TABLE FoodTrends (product_id INT,product_name VARCHAR(255),category VARCHAR(100),popularity_score INT); INSERT INTO FoodTrends (product_id,product_name,category,popularity_score) VALUES (1,'Quinoa Salad','Organic',85),(2,'Chia Seeds','Vegan',90),(3,'Grass-Fed Beef','Sustainable',75);
SELECT category, MAX(popularity_score) FROM FoodTrends GROUP BY category;
What is the maximum number of guests that can be accommodated in eco-friendly hotels in India?
CREATE TABLE Hotels (hotel_id INT,hotel_name TEXT,country TEXT,eco_friendly BOOLEAN,max_guests INT); INSERT INTO Hotels (hotel_id,hotel_name,country,eco_friendly,max_guests) VALUES (1,'Eco-Friendly Hotel Delhi','India',true,150); INSERT INTO Hotels (hotel_id,hotel_name,country,eco_friendly,max_guests) VALUES (2,'Green Hotel Mumbai','India',true,120); INSERT INTO Hotels (hotel_id,hotel_name,country,eco_friendly,max_guests) VALUES (3,'Regular Hotel Bangalore','India',false,200);
SELECT MAX(max_guests) FROM Hotels WHERE country = 'India' AND eco_friendly = true;
What is the total quantity of fruits sold in the Midwest region?
CREATE TABLE Suppliers (SupplierID INT,SupplierName VARCHAR(50),Location VARCHAR(50)); INSERT INTO Suppliers (SupplierID,SupplierName,Location) VALUES (1,'Supplier A','Northeast'),(2,'Supplier B','Midwest'),(3,'Supplier C','Southwest'); CREATE TABLE Products (ProductID INT,ProductName VARCHAR(50),SupplierID INT,Category VARCHAR(50)); INSERT INTO Products (ProductID,ProductName,SupplierID,Category) VALUES (1,'Beef',1,'Meat'),(2,'Chicken',1,'Meat'),(3,'Apples',2,'Fruits'),(4,'Oranges',2,'Fruits'),(5,'Tofu',3,'Vegetables'),(6,'Carrots',3,'Vegetables'); CREATE TABLE Sales (SaleID INT,ProductID INT,Quantity INT); INSERT INTO Sales (SaleID,ProductID,Quantity) VALUES (1,1,10),(2,2,15),(3,3,20),(4,4,25),(5,5,30),(6,6,35);
SELECT SUM(Quantity) FROM Sales JOIN Products ON Sales.ProductID = Products.ProductID JOIN Suppliers ON Products.SupplierID = Suppliers.SupplierID WHERE Category = 'Fruits' AND Suppliers.Location = 'Midwest';
What's the average donation amount per donor in H1 2021?
CREATE TABLE donations (id INT,donor_id INT,donation_amount DECIMAL,donation_date DATE);
SELECT AVG(donation_amount) FROM (SELECT donation_amount, donor_id FROM donations WHERE donation_date >= '2021-01-01' AND donation_date < '2021-07-01' GROUP BY donor_id) AS donations_per_donor;
What is the average financial wellbeing score for low-income households in Southeast Asia?
CREATE TABLE financial_wellbeing (id INT,household_id INT,region VARCHAR(255),score FLOAT);
SELECT AVG(score) FROM financial_wellbeing WHERE household_id <= 30000 AND region = 'Southeast Asia';
What is the average number of accommodations provided to students with learning disabilities per month in the past year?
CREATE TABLE accommodations (id INT,student_id INT,type TEXT,cost INT,date DATE); INSERT INTO accommodations (id,student_id,type,cost,date) VALUES (1,1,'extended time',200,'2022-01-01'); INSERT INTO accommodations (id,student_id,type,cost,date) VALUES (2,2,'note taker',500,'2022-02-01');
SELECT AVG(COUNT(*)) FROM accommodations WHERE student_id IN (SELECT id FROM students WHERE disability = 'learning disability') AND date >= DATE_SUB(NOW(), INTERVAL 1 YEAR) GROUP BY MONTH(date);
What is the average number of support programs provided to students with hearing impairments per provider?
CREATE TABLE SupportProgramsForHearingImpaired (ProgramID INT,ProviderName VARCHAR(50),DisabilityType VARCHAR(50));
SELECT ProviderName, AVG(ProgramCount) FROM (SELECT ProviderName, COUNT(ProgramID) as ProgramCount FROM SupportProgramsForHearingImpaired WHERE DisabilityType = 'hearing impairment' GROUP BY ProviderName) as subquery GROUP BY ProviderName;
What is the total number of workers represented by each union, including workers who are not union members?
CREATE TABLE workers (id INT,name TEXT,union_id INT,union_member BOOLEAN); INSERT INTO workers (id,name,union_id,union_member) VALUES (1,'John Doe',1,true),(2,'Jane Smith',1,false); CREATE TABLE unions (id INT,name TEXT,member_count INT); INSERT INTO unions (id,name,member_count) VALUES (1,'Union A',50);
SELECT u.name, COALESCE(SUM(w.union_member), 0) FROM unions u LEFT JOIN workers w ON u.id = w.union_id GROUP BY u.name;
Show the top 3 cities with the most green building certifications.
CREATE TABLE city_certifications (city VARCHAR(20),certifications INT); INSERT INTO city_certifications (city,certifications) VALUES ('New York',500),('Los Angeles',300),('Chicago',400);
SELECT city, certifications FROM (SELECT city, certifications, RANK() OVER (ORDER BY certifications DESC) as rank FROM city_certifications) AS subquery WHERE rank <= 3;
Find the average number of weeks patients with depression are hospitalized in France.
CREATE TABLE patients (patient_id INT,patient_name VARCHAR(50),condition VARCHAR(50),country VARCHAR(50),hospitalization_date DATE,discharge_date DATE); INSERT INTO patients (patient_id,patient_name,condition,country,hospitalization_date,discharge_date) VALUES (1,'Jean Dupont','Depression','France','2021-02-01','2021-02-14');
SELECT AVG(DATEDIFF(day, patients.hospitalization_date, patients.discharge_date)/7.0) FROM patients WHERE patients.condition = 'Depression' AND patients.country = 'France';
Find the number of trees in each forest that are older than 50 years.
CREATE TABLE forests (id INT,name VARCHAR(255)); INSERT INTO forests (id,name) VALUES (1,'Forest A'),(2,'Forest B'); CREATE TABLE trees (id INT,forest_id INT,age INT); INSERT INTO trees (id,forest_id,age) VALUES (1,1,60),(2,1,45),(3,2,55),(4,2,30);
SELECT f.name, COUNT(t.id) FROM forests f JOIN trees t ON f.id = t.forest_id WHERE t.age > 50 GROUP BY f.name;
Insert records into the table 'community_health_workers'
CREATE TABLE community_health_workers (id INT PRIMARY KEY,name VARCHAR(255),region VARCHAR(255),years_experience INT,cultural_competency_score INT); INSERT INTO community_health_workers (id,name,region,years_experience,cultural_competency_score) VALUES (1,'Ada Williams','Southeast',8,95),(2,'Brian Johnson','Midwest',5,80),(3,'Carla Garcia','West',12,90); INSERT INTO community_health_workers (id,name,region,years_experience,cultural_competency_score) VALUES (4,'Ella Jones','Northeast',6,85),(5,'Farhad Ahmed','South',10,93),(6,'Graciela Gutierrez','Central',11,94);
INSERT INTO community_health_workers (id, name, region, years_experience, cultural_competency_score) VALUES (7, 'Hee Jeong Lee', 'Northwest', 7, 87), (8, 'Ibrahim Hussein', 'East', 9, 96), (9, 'Jasmine Patel', 'Southwest', 8, 91);
What is the minimum and maximum depth of all marine protected areas in the Atlantic Ocean?
CREATE TABLE marine_protected_areas_atlantic_ocean (area_name VARCHAR(255),min_depth DECIMAL(10,2),max_depth DECIMAL(10,2)); INSERT INTO marine_protected_areas_atlantic_ocean (area_name,min_depth,max_depth) VALUES ('Azores Nature Park',10.25,50.65),('Bermuda Park',50.65,100.20),('Galapagos Marine Reserve',15.00,300.00);
SELECT MIN(min_depth) AS min_depth, MAX(max_depth) AS max_depth FROM marine_protected_areas_atlantic_ocean;
What is the renewable energy capacity for each city, ordered from the highest to the lowest?
CREATE TABLE CityEnergy (City VARCHAR(50),EnergyCapacity FLOAT,Renewable BOOLEAN); INSERT INTO CityEnergy (City,EnergyCapacity,Renewable) VALUES ('CityA',5000,TRUE),('CityB',3000,FALSE),('CityC',7000,TRUE);
SELECT City, EnergyCapacity FROM CityEnergy WHERE Renewable = TRUE ORDER BY EnergyCapacity DESC;
How many users have engaged with posts from users in India in the last week?
CREATE TABLE users (id INT,name VARCHAR(50),country VARCHAR(50)); INSERT INTO users (id,name,country) VALUES (1,'John Doe','USA'),(2,'Jane Smith','India'); CREATE TABLE posts (id INT,user_id INT,timestamp DATETIME); INSERT INTO posts (id,user_id,timestamp) VALUES (1,1,'2022-01-01 12:00:00'),(2,1,'2022-01-02 14:00:00'),(3,2,'2022-01-03 10:00:00'),(4,2,'2022-01-04 16:00:00'),(5,2,'2022-01-05 18:00:00'); CREATE TABLE engagements (id INT,post_id INT,user_id INT,timestamp DATETIME); INSERT INTO engagements (id,post_id,user_id,timestamp) VALUES (1,1,2,'2022-01-01 13:00:00'),(2,2,1,'2022-01-02 15:00:00'),(3,3,2,'2022-01-04 11:00:00'),(4,4,1,'2022-01-05 19:00:00'),(5,5,2,'2022-01-06 13:00:00');
SELECT COUNT(DISTINCT engagements.user_id) FROM engagements INNER JOIN posts ON engagements.post_id = posts.id INNER JOIN users AS post_users ON posts.user_id = post_users.id INNER JOIN users AS engagement_users ON engagements.user_id = engagement_users.id WHERE post_users.country = 'India' AND engagements.timestamp >= DATE_SUB(NOW(), INTERVAL 1 WEEK);
Identify the regions with highest carbon sequestration in 2020.
CREATE TABLE carbon_sequestration (year INT,region VARCHAR(255),sequestration FLOAT); INSERT INTO carbon_sequestration (year,region,sequestration) VALUES (2020,'Region A',1300.0),(2020,'Region B',1400.0),(2020,'Region C',1200.0);
SELECT region FROM carbon_sequestration WHERE sequestration = (SELECT MAX(sequestration) FROM carbon_sequestration WHERE year = 2020);
What is the maximum altitude of Chinese satellites?
CREATE TABLE Satellites (satellite_id INT,name VARCHAR(255),country VARCHAR(255),altitude FLOAT,constellation VARCHAR(255)); INSERT INTO Satellites (satellite_id,name,country,altitude,constellation) VALUES (1,'Tianwen-1','China',377.5,'Mars Exploration'),(2,'Beidou-3','China',35786,'Navigation'),(3,'Fengyun-3','China',836,'Weather');
SELECT MAX(altitude) FROM Satellites WHERE country = 'China';
What is the total quantity of unsold size 2XL clothing in the warehouse?
CREATE TABLE Inventory (id INT,product_id INT,size VARCHAR(10),quantity INT); INSERT INTO Inventory (id,product_id,size,quantity) VALUES (1,1,'2XL',25),(2,2,'XS',50);
SELECT SUM(quantity) FROM Inventory WHERE size = '2XL' AND quantity > 0;
What is the distribution of art collections by period in Amsterdam?
CREATE TABLE Collections_Period (city VARCHAR(20),period VARCHAR(20),pieces INT); INSERT INTO Collections_Period (city,period,pieces) VALUES ('Amsterdam','Renaissance',500),('Amsterdam','Baroque',300),('Amsterdam','Modern',200),('Paris','Renaissance',700);
SELECT period, COUNT(*) FROM Collections_Period WHERE city = 'Amsterdam' GROUP BY period;
What are the total construction costs and average project timelines for companies that have worked on both government-funded and privately-funded projects in the state of Washington, grouped by sustainability status?
CREATE TABLE Company_Projects_WA (Company TEXT,Project_ID INT,Funding TEXT,Sustainable BOOLEAN,Cost FLOAT,Timeline INT); INSERT INTO Company_Projects_WA (Company,Project_ID,Funding,Sustainable,Cost,Timeline) VALUES ('Miller & Sons',1,'Government',true,1500000,365),('Miller & Sons',2,'Private',true,2000000,420),('Smith Constructors',3,'Government',true,1200000,450),('Smith Constructors',4,'Private',false,1800000,500),('Eco Builders',5,'Government',true,900000,400),('Eco Builders',6,'Private',true,1300000,440),('Green & Co.',7,'Government',true,1000000,380),('Green & Co.',8,'Government',true,1400000,425),('Green & Co.',9,'Private',false,1100000,475);
SELECT cp.Sustainable, cp.Company, AVG(cp.Cost), AVG(cp.Timeline) FROM Company_Projects_WA cp WHERE cp.Funding = 'Government' OR cp.Funding = 'Private' GROUP BY cp.Sustainable, cp.Company;
Insert new community policing metric for 'Boston' in '2022-01-01'.
CREATE TABLE community_policing_metrics (id INT,city TEXT,metric_date DATE,metric_value INT); INSERT INTO community_policing_metrics (id,city,metric_date,metric_value) VALUES (1,'New York','2021-12-01',20),(2,'Los Angeles','2021-12-02',15),(3,'Chicago','2021-12-03',18);
INSERT INTO community_policing_metrics (city, metric_date, metric_value) VALUES ('Boston', '2022-01-01', 17);
How many mobile customers are there in Florida, and how many have devices compatible with both 4G and 5G networks?
CREATE TABLE mobile_customers (customer_id INT,name VARCHAR(50),device_4g BOOLEAN,device_5g BOOLEAN,state VARCHAR(20)); INSERT INTO mobile_customers (customer_id,name,device_4g,device_5g,state) VALUES (1,'Juan Garcia',true,true,'Florida');
SELECT COUNT(*), SUM(device_4g AND device_5g) FROM mobile_customers WHERE state = 'Florida';
What is the total waste generation in the residential sector for the year 2020?
CREATE TABLE waste_generation (id INT,sector VARCHAR(20),year INT,amount INT); INSERT INTO waste_generation (id,sector,year,amount) VALUES (1,'residential',2020,15000);
SELECT SUM(amount) FROM waste_generation WHERE sector = 'residential' AND year = 2020;
What is the average speed of electric vehicles in 'vehicle_data' table?
CREATE TABLE vehicle_data (id INT,vehicle_type VARCHAR(20),avg_speed FLOAT);
SELECT AVG(avg_speed) FROM vehicle_data WHERE vehicle_type = 'Electric Vehicle';
Update the salaries of employees in the IT department with a 3% increase.
CREATE TABLE EmployeeData (EmployeeID INT,Department VARCHAR(50),Salary DECIMAL(10,2)); INSERT INTO EmployeeData VALUES (1,'IT',50000); INSERT INTO EmployeeData VALUES (2,'HR',55000); INSERT INTO EmployeeData VALUES (3,'Finance',60000);
UPDATE EmployeeData SET Salary = Salary * 1.03 WHERE Department = 'IT';
What is the maximum donation amount given to a single organization in the healthcare sector?
CREATE TABLE donations (id INT,donor_id INT,organization_id INT,donation_amount DECIMAL(10,2),sector VARCHAR(255)); INSERT INTO donations (id,donor_id,organization_id,donation_amount,sector) VALUES (1,1,1,1000.00,'healthcare'),(2,2,2,500.00,'education'),(3,1,1,2000.00,'healthcare');
SELECT MAX(donation_amount) FROM donations WHERE sector = 'healthcare' GROUP BY organization_id;
What is the average publication rate of graduate students in the Music department who identify as disabled?
CREATE TABLE students (id INT,name VARCHAR(100),department VARCHAR(50),publication_count INT,disability VARCHAR(50)); INSERT INTO students VALUES (1,'Harper Brown','Music',2,'Yes');
SELECT department, AVG(publication_rate) FROM (SELECT department, disability, AVG(publication_count) AS publication_rate FROM students WHERE department = 'Music' GROUP BY department, disability) AS subquery WHERE disability = 'Yes' GROUP BY department;
Update the funding amount for the latest investment round of a company in the AI sector.
CREATE TABLE latest_investments (id INT,company_id INT,round_number INT,investment_amount INT); CREATE TABLE companies_funding (id INT,company_id INT,funding_amount INT); CREATE TABLE companies (id INT,name TEXT,industry TEXT);
UPDATE companies_funding JOIN latest_investments ON companies_funding.company_id = latest_investments.company_id SET companies_funding.funding_amount = latest_investments.investment_amount WHERE companies_funding.company_id = latest_investments.company_id AND latest_investments.round_number = (SELECT MAX(round_number) FROM latest_investments JOIN companies ON latest_investments.company_id = companies.id WHERE companies.industry = 'AI');
Delete a department from the "departments" table
CREATE TABLE departments (id INT,department VARCHAR(50),manager VARCHAR(50));
DELETE FROM departments WHERE department = 'Marketing';
Identify the heritage site in 'Asia' with the highest visitor count.
CREATE TABLE HeritageSites (SiteID INT PRIMARY KEY,SiteName VARCHAR(50),Location VARCHAR(50),VisitorCount INT); INSERT INTO HeritageSites (SiteID,SiteName,Location,VisitorCount) VALUES (1,'Angkor Wat','Cambodia',2500000),(2,'Taj Mahal','India',3000000);
SELECT SiteName, MAX(VisitorCount) FROM HeritageSites WHERE Location LIKE '%Asia%' GROUP BY SiteName;
How many military equipment maintenance requests were there in Q2 2020?
CREATE TABLE maintenance_requests (request_id INT,date DATE,type VARCHAR(255)); INSERT INTO maintenance_requests (request_id,date,type) VALUES (1,'2020-01-01','equipment'); INSERT INTO maintenance_requests (request_id,date,type) VALUES (2,'2020-01-15','facility');
SELECT COUNT(*) FROM maintenance_requests WHERE date BETWEEN '2020-04-01' AND '2020-06-30' AND type = 'equipment';
What is the maximum pollution level recorded in the Indian Ocean?
CREATE TABLE pollution_data (location VARCHAR(255),pollution_level FLOAT); INSERT INTO pollution_data (location,pollution_level) VALUES ('Indian Ocean',12.5),('Atlantic Ocean',15.6);
SELECT MAX(pollution_level) FROM pollution_data WHERE location = 'Indian Ocean';
Insert a new electric vehicle model "Tesla X" into the "vehicles" table with an id of 2.
CREATE TABLE vehicles (id INT,type VARCHAR(50)); INSERT INTO vehicles VALUES (1,'sedan');
INSERT INTO vehicles (id, type) VALUES (2, 'electric vehicle');
What is the number of marine species, grouped by conservation status and region?
CREATE TABLE marine_species_2 (id INT,species VARCHAR(255),conservation_status VARCHAR(255),region VARCHAR(255)); INSERT INTO marine_species_2 (id,species,conservation_status,region) VALUES (1,'Blue Whale','Endangered','Arctic'); INSERT INTO marine_species_2 (id,species,conservation_status,region) VALUES (2,'Green Sea Turtle','Vulnerable','Atlantic'); INSERT INTO marine_species_2 (id,species,conservation_status,region) VALUES (3,'Clownfish','Least Concern','Indian');
SELECT conservation_status, region, COUNT(*) FROM marine_species_2 GROUP BY conservation_status, region;
What is the total number of vehicles tested in 'Vehicle Safety Testing' table by manufacturer?
CREATE TABLE Vehicle_Safety_Testing (vehicle_id INT,manufacturer VARCHAR(50),safety_rating VARCHAR(20));
SELECT manufacturer, COUNT(*) FROM Vehicle_Safety_Testing GROUP BY manufacturer;
What is the total number of volunteer hours for a specific volunteer?
CREATE TABLE VolunteerHours (VolunteerHourID INT,VolunteerName TEXT,Hours DECIMAL,Program TEXT); INSERT INTO VolunteerHours (VolunteerHourID,VolunteerName,Hours,Program) VALUES (1,'Juan',5.00,'Feeding Program'),(2,'Juan',3.00,'Education Program'),(3,'Maria',4.00,'Feeding Program'),(4,'Pedro',6.00,'Education Program'),(5,'Jose',7.00,'Feeding Program'),(6,'Carlos',2.00,'Education Program');
SELECT VolunteerName, SUM(Hours) AS TotalVolunteerHours FROM VolunteerHours GROUP BY VolunteerName;
What is the total number of tickets sold for cultural events in 'New York' and 'London'?
CREATE TABLE events (id INT,name TEXT,location TEXT,tickets_sold INT); INSERT INTO events (id,name,location,tickets_sold) VALUES (1,'Broadway Show','New York',200),(2,'Museum Exhibit','London',150),(3,'Concert','Paris',300);
SELECT SUM(tickets_sold) FROM events WHERE location IN ('New York', 'London');
Find the number of unique non-profit organizations that received donations in the impact investing category from donors in the United Kingdom.
CREATE TABLE donations (donation_id INT,donor_id INT,donation_amount FLOAT,donation_category TEXT); INSERT INTO donations (donation_id,donor_id,donation_amount,donation_category) VALUES (1,1,1000.00,'Impact Investing'),(2,2,500.00,'Education');
SELECT COUNT(DISTINCT donation_recipient_id) FROM (SELECT donation_recipient_id FROM donations WHERE donation_category = 'Impact Investing' AND EXISTS (SELECT 1 FROM donors WHERE donors.donor_id = donations.donor_id AND donors.donor_country = 'United Kingdom')) AS donation_subset;
What is the total number of fish in each region?
CREATE TABLE Fish_Farms (Farm_ID INT,Farm_Name TEXT,Region TEXT,Number_of_Fish INT); INSERT INTO Fish_Farms (Farm_ID,Farm_Name,Region,Number_of_Fish) VALUES (1,'Farm S','Northern',5000); INSERT INTO Fish_Farms (Farm_ID,Farm_Name,Region,Number_of_Fish) VALUES (2,'Farm T','Southern',6000); INSERT INTO Fish_Farms (Farm_ID,Farm_Name,Region,Number_of_Fish) VALUES (3,'Farm U','Eastern',7000); INSERT INTO Fish_Farms (Farm_ID,Farm_Name,Region,Number_of_Fish) VALUES (4,'Farm V','Western',8000);
SELECT Region, SUM(Number_of_Fish) FROM Fish_Farms GROUP BY Region;
Identify the number of unique countries represented by the founders of companies in the tech industry.
CREATE TABLE companies (id INT,name TEXT,industry TEXT,founding_date DATE,founder_country TEXT);CREATE TABLE founders (id INT,company_id INT);
SELECT COUNT(DISTINCT founder_country) FROM companies INNER JOIN founders ON companies.id = founders.company_id WHERE companies.industry = 'tech';