instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the most common type of crime in each district?
CREATE TABLE Crimes (CrimeID INT,District VARCHAR(15),CrimeType VARCHAR(20)); INSERT INTO Crimes (CrimeID,District,CrimeType) VALUES (1,'District1','Theft'),(2,'District2','Assault'),(3,'District1','Vandalism');
SELECT District, CrimeType FROM Crimes GROUP BY District;
Insert new marine debris records into the marine_debris table.
CREATE TABLE marine_debris (id INT,debris_type VARCHAR(255),debris_date DATE); INSERT INTO marine_debris (id,debris_type,debris_date) VALUES (1,'Fishing Net','2022-01-01'),(2,'Plastic Bottle','2022-02-01');
INSERT INTO marine_debris (id, debris_type, debris_date) VALUES (3, 'Microplastic', '2022-03-01'), (4, 'Abandoned Net', '2022-04-01');
List all the unique locations where pollution monitoring has been conducted, along with the number of records for each location.
CREATE TABLE Pollution (id INT PRIMARY KEY,location VARCHAR(255),pollutant VARCHAR(255),level FLOAT);
SELECT location, COUNT(*) as record_count FROM Pollution GROUP BY location;
Retrieve the names of all marine species with a conservation status of 'Critically Endangered'
CREATE TABLE red_list_data (id INT,species TEXT,conservation_status TEXT);
SELECT species FROM red_list_data WHERE conservation_status = 'Critically Endangered';
How many times has each dish been ordered for takeout?
CREATE TABLE dishes (dish_id INT,dish_name VARCHAR(255)); CREATE TABLE orders (order_id INT,order_date DATE,dish_id INT,order_type VARCHAR(255)); INSERT INTO dishes (dish_id,dish_name) VALUES (1,'Cheese Burger'),(2,'French Fries'),(3,'Caesar Salad'),(4,'Coke'); INSERT INTO orders (order_id,order_date,dish_id,order_type) VALUES (1,'2022-03-01',1,'takeout'),(2,'2022-03-01',3,'dine in'),(3,'2022-03-02',2,'takeout'),(4,'2022-03-02',4,'takeout');
SELECT dish_name, COUNT(*) as total_takeout_orders FROM orders WHERE order_type = 'takeout' GROUP BY dish_name;
What is the total number of military equipment sold by Lockheed Martin to the Canadian government in 2020?
CREATE TABLE military_sales (supplier VARCHAR(255),buyer VARCHAR(255),equipment VARCHAR(255),year INTEGER,quantity INTEGER); INSERT INTO military_sales (supplier,buyer,equipment,year,quantity) VALUES ('Lockheed Martin','Canadian Government','F-35 Fighter Jet',2020,12),('Lockheed Martin','Canadian Government','C-130 Hercules',2020,3);
SELECT SUM(quantity) FROM military_sales WHERE supplier = 'Lockheed Martin' AND buyer = 'Canadian Government' AND year = 2020;
Which miner has the lowest CO2 emissions in Africa?
CREATE TABLE environmental_impact (miner_name VARCHAR(50),country VARCHAR(50),co2_emissions INT,year INT,PRIMARY KEY (miner_name,year));INSERT INTO environmental_impact (miner_name,country,co2_emissions,year) VALUES ('Anna Taylor','South Africa',120,2020),('Laura Johnson','Egypt',100,2020),('Brian Kim','Ghana',150,2020);CREATE VIEW miner_year_co2_emissions AS SELECT miner_name,country,co2_emissions,year,ROW_NUMBER() OVER(PARTITION BY miner_name ORDER BY co2_emissions ASC) as emission_rank FROM environmental_impact;
SELECT context.miner_name, context.country, sql.co2_emissions, sql.emission_rank FROM environmental_impact sql JOIN miner_year_co2_emissions context ON sql.miner_name = context.miner_name WHERE context.emission_rank = 1 AND sql.country = 'Africa'
How many employees work at each mine, categorized by their job types?
CREATE TABLE Mine (MineID int,MineName varchar(50),Location varchar(50)); CREATE TABLE Employee (EmployeeID int,EmployeeName varchar(50),JobType varchar(50),MineID int); INSERT INTO Mine VALUES (1,'ABC Mine','Colorado'),(2,'DEF Mine','Wyoming'),(3,'GHI Mine','West Virginia'); INSERT INTO Employee VALUES (1,'John Doe','Miner',1),(2,'Jane Smith','Engineer',1),(3,'Michael Lee','Miner',2),(4,'Emily Johnson','Admin',2),(5,'Robert Brown','Miner',3),(6,'Sophia Davis','Engineer',3);
SELECT MineName, JobType, COUNT(*) as EmployeeCount FROM Employee INNER JOIN Mine ON Employee.MineID = Mine.MineID GROUP BY MineName, JobType;
How many workforce diversity incidents were reported in the Southern region in 2020, excluding those reported in January?
CREATE TABLE diversity_incidents (incident_id INT,region_id INT,incident_date DATE); INSERT INTO diversity_incidents (incident_id,region_id,incident_date) VALUES (1,1,'2020-02-01'),(2,1,'2020-03-01'),(3,2,'2020-01-01'); CREATE TABLE region (region_id INT,region_name VARCHAR(20)); INSERT INTO region (region_id,region_name) VALUES (1,'Southern'),(2,'Northern');
SELECT region_id, COUNT(incident_id) FROM diversity_incidents WHERE region_id = 1 AND incident_date BETWEEN '2020-02-01' AND '2020-12-31' GROUP BY region_id;
Update the Machinery table to change the Type of MachineryID 2 to 'Bulldozer'.
CREATE TABLE Machinery (MachineryID INT,Type VARCHAR(50),Age INT); INSERT INTO Machinery (MachineryID,Type,Age) VALUES (1,'Excavator',10); INSERT INTO Machinery (MachineryID,Type,Age) VALUES (2,'Dumper',12); INSERT INTO Machinery (MachineryID,Type,Age) VALUES (3,'Shovel',16);
UPDATE Machinery SET Type = 'Bulldozer' WHERE MachineryID = 2;
Update a compliance record's regulation and description in the compliance table
CREATE TABLE compliance (compliance_id INT,regulation VARCHAR(100),description VARCHAR(255),compliance_date DATE);
UPDATE compliance SET regulation = 'Data Privacy', description = 'Complied with data privacy regulations' WHERE compliance_id = 4001;
Which artist has the highest total ticket sales?
CREATE TABLE tickets (artist_name TEXT,tickets_sold INT); INSERT INTO tickets (artist_name,tickets_sold) VALUES ('Taylor Swift',1250000),('BTS',1500000),('Adele',1000000);
SELECT artist_name, SUM(tickets_sold) as total_tickets_sold FROM tickets GROUP BY artist_name ORDER BY total_tickets_sold DESC LIMIT 1;
What is the average word count of news articles published in the "articles" table by month?
CREATE TABLE articles (id INT,title VARCHAR(100),publication_date DATE,word_count INT);
SELECT EXTRACT(MONTH FROM publication_date) AS month, AVG(word_count) AS avg_word_count FROM articles GROUP BY month;
What is the average word count of news articles written by investigative journalists?
CREATE TABLE reporters (id INT,name VARCHAR(50),gender VARCHAR(10),age INT,position VARCHAR(20),country VARCHAR(50)); INSERT INTO reporters (id,name,gender,age,position,country) VALUES (1,'Anna Smith','Female',35,'News Reporter','USA'); INSERT INTO reporters (id,name,gender,age,position,country) VALUES (2,'Mike Johnson','Male',40,'Investigative Journalist','Canada'); INSERT INTO reporters (id,name,gender,age,position,country) VALUES (3,'Sofia Rodriguez','Female',32,'Investigative Journalist','Mexico'); CREATE TABLE news_articles (id INT,title VARCHAR(100),content TEXT,publication_date DATE,reporter_id INT); INSERT INTO news_articles (id,title,content,publication_date,reporter_id) VALUES (1,'News Article 1','Content of News Article 1','2021-01-01',2); INSERT INTO news_articles (id,title,content,publication_date,reporter_id) VALUES (2,'News Article 2','Content of News Article 2','2021-02-01',3);
SELECT AVG(LENGTH(content) - LENGTH(REPLACE(content, ' ', '')) + 1) AS avg_word_count FROM news_articles WHERE reporter_id IN (SELECT id FROM reporters WHERE position = 'Investigative Journalist');
What is the total amount donated by donors in the 'Regular Donors' category?
CREATE TABLE Donors (DonorID INT,DonorName VARCHAR(50),Category VARCHAR(20)); INSERT INTO Donors (DonorID,DonorName,Category) VALUES (1,'John Doe','Young Donors'),(2,'Jane Smith','Regular Donors'),(3,'Alice Johnson','Young Donors'); CREATE TABLE Donations (DonationID INT,DonorID INT,DonationAmount DECIMAL(10,2));
SELECT SUM(DonationAmount) FROM Donations INNER JOIN Donors ON Donations.DonorID = Donors.DonorID WHERE Donors.Category = 'Regular Donors';
Delete records of players who joined after 2020-01-01 from the 'Player' table
CREATE TABLE Player (Player_ID INT,Name VARCHAR(50),Date_Joined DATE); INSERT INTO Player (Player_ID,Name,Date_Joined) VALUES (1,'John Doe','2019-06-15'),(2,'Jane Smith','2020-03-08'),(3,'Alice Johnson','2021-02-22');
DELETE FROM Player WHERE Date_Joined > '2020-01-01';
Find the number of IoT sensors installed in each farm that use Sprinkler irrigation.
CREATE TABLE IoT_Sensors (id INT,sensor_type VARCHAR(50),Farm_id INT); INSERT INTO IoT_Sensors (id,sensor_type,Farm_id) VALUES (1,'Soil Moisture',1),(2,'Temperature',1),(3,'Humidity',2); CREATE TABLE Irrigation (id INT,Farm_id INT,irrigation_type VARCHAR(50),duration INT); INSERT INTO Irrigation (id,Farm_id,irrigation_type,duration) VALUES (1,1,'Sprinkler',30),(2,2,'Drip',45);
SELECT f.id, COUNT(s.id) FROM Farmers f JOIN Irrigation i ON f.id = i.Farm_id JOIN IoT_Sensors s ON f.id = s.Farm_id WHERE i.irrigation_type = 'Sprinkler' GROUP BY f.id;
Identify the renewable energy project with the highest carbon offset (in tonnes) in 'projects' schema?
CREATE SCHEMA IF NOT EXISTS projects; CREATE TABLE IF NOT EXISTS projects.carbon_offset (offset_id INT,project_id INT,offset_tonnes INT); INSERT INTO projects.carbon_offset (offset_id,project_id,offset_tonnes) VALUES (1,1,5000),(2,2,7000),(3,3,6000);
SELECT project_id, MAX(offset_tonnes) as max_offset FROM projects.carbon_offset GROUP BY project_id;
Find the total revenue for each cuisine type
CREATE TABLE Restaurants (RestaurantID int,CuisineType varchar(255)); INSERT INTO Restaurants (RestaurantID,CuisineType) VALUES (1,'Italian'),(2,'Mexican'),(3,'Chinese'); CREATE TABLE Sales (SaleID int,RestaurantID int,Revenue decimal(10,2)); INSERT INTO Sales (SaleID,RestaurantID,Revenue) VALUES (1,1,500.00),(2,2,750.00),(3,3,300.00);
SELECT R.CuisineType, SUM(S.Revenue) as TotalRevenue FROM Restaurants R INNER JOIN Sales S ON R.RestaurantID = S.RestaurantID GROUP BY R.CuisineType;
How many restaurants are there in each country?
CREATE TABLE restaurant (restaurant_id INT,country VARCHAR(50)); INSERT INTO restaurant (restaurant_id,country) VALUES (1,'USA'),(2,'Canada'),(3,'USA'),(4,'Mexico');
SELECT country, COUNT(*) FROM restaurant GROUP BY country;
What is the minimum price of vegan dishes in San Francisco?
CREATE TABLE Restaurants (id INT,name VARCHAR(50),city VARCHAR(20)); CREATE TABLE Menu (id INT,restaurant_id INT,dish VARCHAR(50),category VARCHAR(20),price DECIMAL(5,2)); INSERT INTO Restaurants (id,name,city) VALUES (1,'VeganVibes','San Francisco'); INSERT INTO Menu (id,restaurant_id,dish,category,price) VALUES (1,1,'Tofu Stir Fry','Vegan',9.99);
SELECT MIN(price) FROM Menu JOIN Restaurants ON Menu.restaurant_id = Restaurants.id WHERE Restaurants.city = 'San Francisco' AND category = 'Vegan';
What is the total revenue for 'Italian' category in '2023'?
CREATE TABLE RestaurantRevenue (category VARCHAR(20),year INT,revenue FLOAT); INSERT INTO RestaurantRevenue (category,year,revenue) VALUES ('Italian',2023,25000.00),('Italian',2023,28000.00),('Italian',2023,30000.00);
SELECT SUM(revenue) FROM RestaurantRevenue WHERE category = 'Italian' AND year = 2023;
List the top 3 most expensive eco-friendly products in Europe and their suppliers.
CREATE TABLE Suppliers (supplierID INT,supplierName VARCHAR(50),country VARCHAR(50)); CREATE TABLE Products (productID INT,productName VARCHAR(50),price DECIMAL(10,2),ecoFriendly BOOLEAN,supplierID INT);
SELECT P.productName, P.price, S.supplierName FROM (SELECT * FROM Products WHERE ecoFriendly = TRUE ORDER BY price DESC LIMIT 3) P JOIN Suppliers S ON P.supplierID = S.supplierID;
What are the names and launch dates of satellites launched by SpaceX?
CREATE TABLE satellites (id INT,name VARCHAR(255),launch_date DATE); INSERT INTO satellites (id,name,launch_date) VALUES (1,'Dragon','2012-12-08'); INSERT INTO satellites (id,name,launch_date) VALUES (2,'Falcon','2013-09-29');
SELECT name, launch_date FROM satellites WHERE manufacturer = 'SpaceX';
Insert a new record for the spacecraft 'Artemis III' into the Spacecrafts table
CREATE TABLE Spacecrafts (SpacecraftID INT,Name VARCHAR(50),Manufacturer VARCHAR(50),YearManufactured INT);
INSERT INTO Spacecrafts (SpacecraftID, Name, Manufacturer, YearManufactured) VALUES (3, 'Artemis III', 'NASA', 2022);
What is the maximum number of spacewalks for each astronaut?
CREATE TABLE Spacewalks (id INT,astronaut_id INT,duration FLOAT,mission TEXT); CREATE TABLE Astronauts (id INT,name TEXT);
SELECT a.name, MAX(sw.id) FROM Astronauts a JOIN Spacewalks sw ON a.id = sw.astronaut_id GROUP BY a.name;
What is the distribution of fan demographics by age range for each team?
CREATE TABLE fan_demographics_team (id INT,team VARCHAR(50),age_range VARCHAR(20)); INSERT INTO fan_demographics_team (id,team,age_range) VALUES (1,'TeamA','18-24'),(2,'TeamA','25-34'),(3,'TeamB','18-24'),(4,'TeamB','35-44'),(5,'TeamB','45-54');
SELECT team, age_range, COUNT(*) as count FROM fan_demographics_team GROUP BY team, age_range;
What are the names of the policies related to the transportation sector?
CREATE TABLE policies (id INT,sector VARCHAR(20),name VARCHAR(50)); INSERT INTO policies (id,sector,name) VALUES (1,'Transportation','Safety Regulations'),(2,'Financial','Financial Regulation');
SELECT name FROM policies WHERE sector = 'Transportation';
Count the number of 'Train' records in the 'PublicTransit' table where 'state' is 'California'
CREATE TABLE PublicTransit (transit_id INT,transit_type VARCHAR(20),city VARCHAR(20),state VARCHAR(20)); INSERT INTO PublicTransit (transit_id,transit_type,city,state) VALUES (1,'Bus','New York','New York'),(2,'Subway','New York','New York'),(3,'Train','Los Angeles','California');
SELECT COUNT(*) FROM PublicTransit WHERE transit_type = 'Train' AND state = 'California';
How many autonomous taxis were in operation in San Francisco as of January 1, 2022?
CREATE TABLE autonomous_taxis(taxi_id INT,taxi_type VARCHAR(50),operation_start_date DATE,operation_end_date DATE,city VARCHAR(50));
SELECT COUNT(*) FROM autonomous_taxis WHERE taxi_type = 'autonomous' AND operation_end_date >= '2022-01-01' AND operation_start_date <= '2022-01-01' AND city = 'San Francisco';
List all garments in the "Spring 2023" collection that are made of silk or cotton.
CREATE TABLE Spring2023 (garment_id INT,garment_name VARCHAR(50),material VARCHAR(50)); INSERT INTO Spring2023 (garment_id,garment_name,material) VALUES (1,'Linen Blend Dress','Linen-Hemp Blend'),(2,'Silk Top','Silk'),(3,'Recycled Polyester Skirt','Recycled Polyester'),(4,'Cotton Shirt','Cotton');
SELECT garment_name FROM Spring2023 WHERE material IN ('Silk', 'Cotton');
What is the number of employees in the 'education' industry?
CREATE TABLE if not exists employment (id INT,industry VARCHAR,number_of_employees INT); INSERT INTO employment (id,industry,number_of_employees) VALUES (1,'manufacturing',5000),(2,'technology',8000),(3,'healthcare',7000),(4,'retail',6000),(5,'education',9000);
SELECT SUM(number_of_employees) FROM employment WHERE industry = 'education';
What is the total number of workers in unions involved in collective bargaining in each state?
CREATE TABLE unions (id INT,state VARCHAR(2),workers INT); CREATE VIEW collective_bargaining AS SELECT * FROM unions WHERE issue = 'collective_bargaining';
SELECT state, SUM(workers) FROM collective_bargaining GROUP BY state;
What is the total waste generated in South Asia in the year 2020?
CREATE TABLE WasteGeneration (country VARCHAR(50),year INT,waste_generated_kg FLOAT);
SELECT SUM(waste_generated_kg) FROM WasteGeneration WHERE country IN ('India', 'Pakistan', 'Bangladesh', 'Sri Lanka', 'Afghanistan', 'Nepal', 'Bhutan') AND year = 2020;
What was the minimum glass recycling rate in 2019 for South America and Africa?
CREATE TABLE RecyclingRates (year INT,region VARCHAR(50),material VARCHAR(50),recycling_rate FLOAT); INSERT INTO RecyclingRates (year,region,material,recycling_rate) VALUES (2019,'North America','Glass',0.3),(2019,'Europe','Glass',0.45),(2019,'Asia','Glass',0.4),(2019,'South America','Glass',0.2),(2019,'Africa','Glass',0.1);
SELECT MIN(recycling_rate) FROM RecyclingRates WHERE year = 2019 AND material = 'Glass' AND region IN ('South America', 'Africa');
How many members in the West region have a premium membership?
CREATE TABLE memberships (id INT,member_type VARCHAR(50),region VARCHAR(50));
SELECT COUNT(*) FROM memberships WHERE member_type = 'Premium' AND region = 'West';
SELECT MemberID, COUNT(*) as WorkoutCountToday FROM Workouts WHERE Date = CURRENT_DATE GROUP BY MemberID ORDER BY WorkoutCountToday DESC;
CREATE TABLE Workouts (WorkoutID INT,MemberID INT,WorkoutType VARCHAR(20),Duration INT,Date DATE); INSERT INTO Workouts (WorkoutID,MemberID,WorkoutType,Duration,Date) VALUES (11,1013,'Pilates',45,'2023-03-01'); INSERT INTO Workouts (WorkoutID,MemberID,WorkoutType,Duration,Date) VALUES (12,1014,'Cycling',60,'2023-03-01');
SELECT MemberID, WorkoutType, DATE_TRUNC('week', Date) as Week, AVG(Duration) as AverageWorkoutDurationPerWeek FROM Workouts GROUP BY MemberID, WorkoutType, Week ORDER BY Week DESC;
How many economic diversification projects were completed in '2019'?
CREATE TABLE economic_diversification (id INT,project_name VARCHAR(50),sector VARCHAR(50),start_date DATE,end_date DATE,budget FLOAT); INSERT INTO economic_diversification (id,project_name,sector,start_date,end_date,budget) VALUES (1,'Renewable Energy Investment','Economic Diversification','2018-01-01','2019-12-31',750000);
SELECT COUNT(*) FROM economic_diversification WHERE YEAR(end_date) = 2019;
What is the maximum and minimum population of animals for each species?
CREATE TABLE animal_population (species VARCHAR(50),population INT); INSERT INTO animal_population (species,population) VALUES ('Tiger',300),('Lion',250),('Elephant',500),('Giraffe',200);
SELECT species, MIN(population) OVER (PARTITION BY species) as min_population, MAX(population) OVER (PARTITION BY species) as max_population FROM animal_population ORDER BY species;
What is the total conservation funding per region for the last 5 years?
CREATE TABLE conservation_funding (id INT,region VARCHAR(255),funding FLOAT,year INT);
SELECT region, SUM(funding) as total_funding, EXTRACT(YEAR FROM date_trunc('year', current_date)) - sequence AS years_ago FROM conservation_funding, generate_series(1, 5) sequence GROUP BY region, sequence ORDER BY years_ago DESC;
What is the average dissolved oxygen level for each species in our fish farms?
CREATE TABLE fish_farms (id INT,name TEXT,location TEXT,water_type TEXT); INSERT INTO fish_farms (id,name,location,water_type) VALUES (1,'Farm A','Seattle','Saltwater'); INSERT INTO fish_farms (id,name,location,water_type) VALUES (2,'Farm B','Portland','Freshwater'); CREATE TABLE fish_species (id INT,name TEXT,average_dissolved_oxygen FLOAT); INSERT INTO fish_species (id,name,average_dissolved_oxygen) VALUES (1,'Salmon',6.5); INSERT INTO fish_species (id,name,average_dissolved_oxygen) VALUES (2,'Trout',7.0); CREATE TABLE fish_inventory (fish_farm_id INT,fish_species_id INT,quantity INT); INSERT INTO fish_inventory (fish_farm_id,fish_species_id,quantity) VALUES (1,1,500); INSERT INTO fish_inventory (fish_farm_id,fish_species_id,quantity) VALUES (1,2,300); INSERT INTO fish_inventory (fish_farm_id,fish_species_id,quantity) VALUES (2,1,400); INSERT INTO fish_inventory (fish_farm_id,fish_species_id,quantity) VALUES (2,2,600);
SELECT fs.name AS species_name, AVG(av.dissolved_oxygen) AS avg_dissolved_oxygen FROM fish_inventory fi JOIN fish_farms ff ON fi.fish_farm_id = ff.id JOIN fish_species fs ON fi.fish_species_id = fs.id JOIN (SELECT fish_species_id, AVG(dissolved_oxygen) AS dissolved_oxygen FROM water_quality GROUP BY fish_species_id) av ON fs.id = av.fish_species_id GROUP BY fs.name;
What is the average water temperature in the Pacific Ocean for the month of July?
CREATE TABLE pacific_ocean_temp (id INT,date DATE,temp FLOAT); INSERT INTO pacific_ocean_temp (id,date,temp) VALUES (1,'2021-07-01',20.5),(2,'2021-07-02',21.2),(3,'2021-07-03',22.0);
SELECT AVG(temp) FROM pacific_ocean_temp WHERE EXTRACT(MONTH FROM date) = 7 AND EXTRACT(YEAR FROM date) = 2021 AND ocean_name = 'Pacific Ocean';
List the building permits issued in New York City for the construction of multi-family buildings since 2015.
CREATE TABLE building_permits (permit_id INT,city VARCHAR(50),building_type VARCHAR(20),issue_date DATE); INSERT INTO building_permits (permit_id,city,building_type,issue_date) VALUES (1,'NYC','Multi-family','2015-04-01'),(2,'NYC','Single-family','2016-08-15'),(3,'LA','Multi-family','2017-12-25');
SELECT permit_id, city, building_type, issue_date FROM building_permits WHERE city = 'NYC' AND building_type = 'Multi-family' AND issue_date >= '2015-01-01';
What is the average project timeline for sustainable building projects in the city of Seattle?
CREATE TABLE project (id INT,name VARCHAR(255),city VARCHAR(255),timeline FLOAT);CREATE TABLE sustainable_building (id INT,project_id INT,sustainable_practice VARCHAR(255));
SELECT AVG(project.timeline) FROM project INNER JOIN sustainable_building ON project.id = sustainable_building.project_id WHERE project.city = 'Seattle';
How many climate mitigation projects were initiated in Latin America since 2015?
CREATE TABLE mitigation_projects (project_id INT,year INT,region VARCHAR(255));
SELECT COUNT(*) FROM mitigation_projects WHERE year >= 2015 AND region = 'Latin America';
What was the total investment in climate communication in Europe and Central Asia in 2019?
CREATE TABLE climate_investments (id INT,region VARCHAR(50),category VARCHAR(50),year INT,investment FLOAT); INSERT INTO climate_investments (id,region,category,year,investment) VALUES (1,'Western Europe','Climate Communication',2018,500000); INSERT INTO climate_investments (id,region,category,year,investment) VALUES (2,'Eastern Europe','Climate Adaptation',2019,700000); INSERT INTO climate_investments (id,region,category,year,investment) VALUES (3,'Central Asia','Climate Communication',2019,800000);
SELECT SUM(investment) FROM climate_investments WHERE category = 'Climate Communication' AND (region = 'Europe' OR region = 'Central Asia') AND year = 2019;
Find the number of clinical trials for 'DrugE' that ended in phase 3?
CREATE TABLE clinical_trials (drug_name TEXT,phase INT); INSERT INTO clinical_trials (drug_name,phase) VALUES ('DrugE',3),('DrugF',2);
SELECT COUNT(*) FROM clinical_trials WHERE drug_name = 'DrugE' AND phase = 3;
How many cases of Measles were reported in Brazil in 2014?
CREATE TABLE measles_reports (id INT,disease VARCHAR(50),location VARCHAR(50),year INT,reported INT); INSERT INTO measles_reports (id,disease,location,year,reported) VALUES (1,'Measles','Brazil',2014,1760),(2,'Measles','Brazil',2013,3254);
SELECT reported FROM measles_reports WHERE disease = 'Measles' AND location = 'Brazil' AND year = 2014;
Display the number of exits by year
CREATE TABLE exit (id INT,company_id INT,exit_year INT,exit_type TEXT);
SELECT exit_year, COUNT(*) FROM exit GROUP BY exit_year;
What is the average disability accommodation budget by state?
CREATE TABLE disability_accommodations_state (accom_id INT,accom_name TEXT,budget DECIMAL(10,2),state_id INT);CREATE TABLE states (state_id INT,state_name TEXT);
SELECT s.state_name, AVG(da.budget) AS avg_budget FROM disability_accommodations_state da INNER JOIN states s ON da.state_id = s.state_id GROUP BY s.state_name;
What is the maximum population size of all marine species in the North Atlantic, grouped by conservation status?"
CREATE TABLE marine_species_population (species_name VARCHAR(255),region VARCHAR(255),max_population_size FLOAT,conservation_status VARCHAR(255)); INSERT INTO marine_species_population (species_name,region,max_population_size,conservation_status) VALUES ('Basking Shark','North Atlantic',2000,'Fully Protected'),('Great White Shark','North Atlantic',3000,'Partially Protected'),('North Atlantic Right Whale','North Atlantic',400,'Fully Protected');
SELECT conservation_status, MAX(max_population_size) as max_population_size FROM marine_species_population WHERE region = 'North Atlantic' GROUP BY conservation_status;
List the dapps that have deployed the fewest smart contracts in the 'Polygon' network.
CREATE TABLE polygon_dapps (dapp_name VARCHAR(20),network VARCHAR(20),smart_contracts INT); INSERT INTO polygon_dapps (dapp_name,network,smart_contracts) VALUES ('QuickSwap','Polygon',20),('Dfyn','Polygon',30),('MaticNetwork','Polygon',40);
SELECT dapp_name, network, smart_contracts, DENSE_RANK() OVER (ORDER BY smart_contracts ASC) as rank FROM polygon_dapps WHERE network = 'Polygon';
What is the number of smart contracts developed by individuals from underrepresented communities in the Ethereum network?
CREATE TABLE if not exists smart_contracts (contract_id INT,contract_address VARCHAR(255),developer_community VARCHAR(255)); INSERT INTO smart_contracts (contract_id,contract_address,developer_community) VALUES (1,'0x123...','Women in Tech'),(2,'0x456...','Minority Ethnic Group'),(3,'0x789...','LGBTQ+'),(4,'0xabc...','People with Disabilities'),(5,'0xdef...','Indigenous People'),(6,'0xghi...','Young Developers');
SELECT COUNT(*) FROM smart_contracts WHERE developer_community IN ('Women in Tech', 'Minority Ethnic Group', 'LGBTQ+', 'People with Disabilities', 'Indigenous People', 'Young Developers');
What is the maximum safety rating for products in the skincare category that are not tested on animals?
CREATE TABLE Products (id INT,ProductName VARCHAR(50),Category VARCHAR(50),Price DECIMAL(5,2),IsCrueltyFree BOOLEAN); CREATE TABLE ProductSafety (id INT,ProductID INT,SafetyRating DECIMAL(3,2),TestDate DATE); CREATE TABLE CrueltyFreeCertification (id INT,ProductID INT,CertificationDate DATE);
SELECT MAX(PS.SafetyRating) as HighestSafetyRating FROM ProductSafety PS JOIN Products P ON PS.ProductID = P.id JOIN CrueltyFreeCertification CFC ON P.id = CFC.ProductID WHERE P.Category = 'skincare' AND P.IsCrueltyFree = TRUE AND CFC.CertificationDate IS NOT NULL;
Which ingredients used in cosmetics are sourced from countries with high biodiversity and have been certified as organic?
CREATE TABLE Ingredients (Ingredient_ID INT,Ingredient_Name TEXT,Is_Organic BOOLEAN); INSERT INTO Ingredients (Ingredient_ID,Ingredient_Name,Is_Organic) VALUES (1,'Aloe Vera',true),(2,'Shea Butter',true),(3,'Palm Oil',false); CREATE TABLE Ingredient_Sources (Ingredient_ID INT,Source_Country TEXT); INSERT INTO Ingredient_Sources (Ingredient_ID,Source_Country) VALUES (1,'Mexico'),(2,'Ghana'),(3,'Indonesia');
SELECT I.Ingredient_Name FROM Ingredients I INNER JOIN Ingredient_Sources ISrc ON I.Ingredient_ID = ISrc.Ingredient_ID WHERE I.Is_Organic = true AND ISrc.Source_Country IN ('Brazil', 'Indonesia', 'Colombia', 'Madagascar', 'Peru');
Show the number of threat occurrences per threat type and month in the 'threat_intelligence' table
CREATE TABLE threat_intelligence (threat_id INT,threat_type VARCHAR(50),threat_level VARCHAR(10),occurrence_date DATE);
SELECT EXTRACT(MONTH FROM occurrence_date) as month, threat_type, COUNT(*) as threat_count FROM threat_intelligence GROUP BY month, threat_type;
Show veteran employment statistics for the year 2020
CREATE TABLE veteran_employment (year INT,total_veterans INT,employed_veterans INT,unemployed_veterans INT);
SELECT * FROM veteran_employment WHERE year = 2020;
What is the total number of peacekeeping operations in the Middle East and their average duration?
CREATE TABLE PeacekeepingOperationsMiddleEast (id INT,operation VARCHAR(50),location VARCHAR(50),start_date DATE,end_date DATE); INSERT INTO PeacekeepingOperationsMiddleEast (id,operation,location,start_date,end_date) VALUES (1,'Operation Iraqi Freedom','Iraq','2003-03-20','2011-12-15'),(2,'Operation Enduring Freedom','Afghanistan','2001-10-07','2014-12-28');
SELECT COUNT(*) AS total_operations, AVG(end_date - start_date) AS avg_duration FROM PeacekeepingOperationsMiddleEast;
What is the average transaction amount for retail customers in New York?
CREATE TABLE retail_customers (customer_id INT,name VARCHAR(50),state VARCHAR(20),transaction_amount DECIMAL(10,2)); INSERT INTO retail_customers (customer_id,name,state,transaction_amount) VALUES (1,'John Doe','NY',120.50),(2,'Jane Smith','NY',75.30);
SELECT AVG(transaction_amount) FROM retail_customers WHERE state = 'NY';
What is the total assets of clients who have invested in both stocks and bonds?
CREATE TABLE clients (client_id INT,name TEXT,age INT,gender TEXT,total_assets DECIMAL(10,2)); INSERT INTO clients VALUES (1,'John Doe',35,'Male',250000.00),(2,'Jane Smith',45,'Female',500000.00); CREATE TABLE investments (client_id INT,investment_type TEXT); INSERT INTO investments VALUES (1,'Stocks'),(1,'Bonds'),(2,'Stocks');
SELECT c.total_assets FROM clients c INNER JOIN investments i ON c.client_id = i.client_id WHERE i.investment_type IN ('Stocks', 'Bonds') GROUP BY c.client_id HAVING COUNT(DISTINCT i.investment_type) = 2;
Show the total tonnage of cargo handled by each port in the South America region, ranked in descending order, including ports with no cargo.
CREATE TABLE ports(port_id INT,port_name TEXT,region TEXT);CREATE TABLE cargo(cargo_id INT,port_id INT,tonnage INT);INSERT INTO ports VALUES (1,'Port A','South America'),(2,'Port B','North America'),(3,'Port C','South America');INSERT INTO cargo VALUES (1,1,500),(2,1,800),(3,2,300),(4,3,500),(5,1,700);
SELECT p.port_name, COALESCE(SUM(c.tonnage),0) as total_tonnage FROM ports p LEFT JOIN cargo c ON p.port_id = c.port_id WHERE p.region = 'South America' GROUP BY p.port_name ORDER BY total_tonnage DESC;
Add a new record to the 'resources' table for a rural health center in India.
CREATE SCHEMA rural; CREATE TABLE rural.resources (id INT,resource_type TEXT,country TEXT);
INSERT INTO rural.resources (id, resource_type, country) VALUES (1, 'rural health center', 'India');
What is the average budget of military technology programs in the Asia-Pacific region, excluding programs with a budget over $500 million?
CREATE TABLE MilitaryBudget (region VARCHAR(255),program VARCHAR(255),budget DECIMAL(10,2)); INSERT INTO MilitaryBudget (region,program,budget) VALUES ('Asia-Pacific','ProgramA',400000000.00),('Asia-Pacific','ProgramB',600000000.00),('Europe','ProgramC',300000000.00);
SELECT AVG(budget) FROM MilitaryBudget WHERE region = 'Asia-Pacific' AND budget <= 500000000;
What is the total budget for program 'Sports' in 2021?
CREATE TABLE Budget (program_id INT,program_name VARCHAR(255),year INT,allocated_budget DECIMAL(10,2)); INSERT INTO Budget (program_id,program_name,year,allocated_budget) VALUES (4,'Sports',2021,5000.00),(1,'Arts',2020,2000.00),(2,'Education',2020,3000.00),(3,'Environment',2020,4000.00),(4,'Sports',2020,4500.00);
SELECT SUM(allocated_budget) FROM Budget WHERE program_name = 'Sports' AND year = 2021;
Who are the top 3 donors in terms of total donation amount?
CREATE TABLE Donors (DonorID int,Name varchar(100),TotalDonations decimal(10,2)); INSERT INTO Donors (DonorID,Name,TotalDonations) VALUES (1,'John Doe',150.00); INSERT INTO Donors (DonorID,Name,TotalDonations) VALUES (2,'Jane Smith',250.00);
SELECT Name, TotalDonations FROM Donors ORDER BY TotalDonations DESC LIMIT 3;
Alter 'Courses' table to add a column 'StudentsEnrolled'
CREATE TABLE Students (StudentId INT,Name VARCHAR(50),Age INT); INSERT INTO Students (StudentId,Name,Age) VALUES (1001,'John Doe',16); CREATE VIEW StudentNames AS SELECT * FROM Students; CREATE TABLE Courses (CourseId INT,CourseName VARCHAR(50),Instructor VARCHAR(50),StudentsEnrolled INT); INSERT INTO Courses (CourseId,CourseName,Instructor,StudentsEnrolled) VALUES (1001,'Introduction to Programming','Mr. Smith',0);
ALTER TABLE Courses ADD COLUMN StudentsEnrolled INT;
How many employees were hired in each month of 2022?
CREATE TABLE Employees (EmployeeID INT,HireDate DATE); INSERT INTO Employees (EmployeeID,HireDate) VALUES (1,'2022-01-15'); INSERT INTO Employees (EmployeeID,HireDate) VALUES (2,'2022-02-01');
SELECT EXTRACT(MONTH FROM HireDate) AS Month, COUNT(*) AS NumberOfHires FROM Employees WHERE HireDate BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY Month;
How many wells are there in total in the 'CaspianSea' schema?
CREATE TABLE CaspianSea.wells (well_id INT); INSERT INTO CaspianSea.wells (well_id) VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
SELECT COUNT(*) FROM CaspianSea.wells;
Update the 'oil_production' value for the record with 'well_id' = 2 in the 'production_figures' table to 2000
CREATE TABLE production_figures (well_id INT,year INT,oil_production INT,gas_production INT); INSERT INTO production_figures (well_id,year,oil_production,gas_production) VALUES (1,2019,1000,2000000); INSERT INTO production_figures (well_id,year,oil_production,gas_production) VALUES (2,2020,1500,2500000);
UPDATE production_figures SET oil_production = 2000 WHERE well_id = 2;
How many educational institutions in 'refugee_camps' have 'education_support' as one of their services?
CREATE TABLE refugee_camps (id INT,name VARCHAR(50),type VARCHAR(50),num_edu_institutions INT,services VARCHAR(50));
SELECT num_edu_institutions FROM refugee_camps WHERE services LIKE '%education_support%';
Which organizations have contributed more than $50,000 for 'Community Development' sector in 'South America'?
CREATE TABLE Contributions_South_America (id INT,organization VARCHAR(50),sector VARCHAR(50),amount DECIMAL(10,2));
SELECT organization FROM Contributions_South_America WHERE sector = 'Community Development' AND amount > 50000 AND location = 'South America';
What is the minimum budget for an AI project in Europe?
CREATE TABLE ai_projects (id INT,country VARCHAR(255),budget DECIMAL(10,2)); INSERT INTO ai_projects (id,country,budget) VALUES (1,'Germany',400000.00),(2,'France',350000.00),(3,'UK',300000.00),(4,'Spain',450000.00);
SELECT MIN(budget) FROM ai_projects WHERE country = 'UK';
What is the total number of employees working in companies that have implemented ethical AI?
CREATE TABLE Companies (id INT,name TEXT,has_ethical_ai BOOLEAN,num_employees INT); INSERT INTO Companies (id,name,has_ethical_ai,num_employees) VALUES (1,'TechCo',true,1000),(2,'GreenTech',true,1500),(3,'EthicalLabs',true,750),(4,'Tech4All',false,800),(5,'InclusiveTech',false,1200);
SELECT SUM(num_employees) FROM Companies WHERE has_ethical_ai = true;
What is the minimum number of bikes available at each station in Paris?
CREATE TABLE bike_stations (station_id INT,city VARCHAR(50),num_bikes INT); INSERT INTO bike_stations (station_id,city,num_bikes) VALUES (1,'Paris',15),(2,'Paris',20),(3,'Paris',10);
SELECT station_id, MIN(num_bikes) FROM bike_stations WHERE city = 'Paris' GROUP BY station_id;
What is the percentage of accessible buses and trams in the fleet?
CREATE TABLE fleet (vehicle_id INT,type VARCHAR(50),accessibility BOOLEAN); INSERT INTO fleet VALUES (1,'Bus',TRUE),(2,'Bus',FALSE),(3,'Tram',TRUE),(4,'Tram',TRUE);
SELECT type, (COUNT(*) FILTER (WHERE accessibility = TRUE) * 100.0 / COUNT(*)) AS percentage FROM fleet GROUP BY type;
Update the material_waste table to set recycling_rate to 35 for all materials with type as 'Plastic'
CREATE TABLE material_waste (id INT PRIMARY KEY,material_name VARCHAR(255),type VARCHAR(255),recycling_rate INT); INSERT INTO material_waste (id,material_name,type,recycling_rate) VALUES (1,'Bottle','Plastic',30),(2,'Bag','Plastic',25),(3,'Frame','Metal',40);
UPDATE material_waste SET recycling_rate = 35 WHERE type = 'Plastic';
What is the average carbon footprint of clothing items made with recycled materials?
CREATE TABLE RecycledClothing (id INT,carbon_footprint DECIMAL(5,2)); INSERT INTO RecycledClothing VALUES (1,10.50),(2,12.00),(3,11.25);
SELECT AVG(carbon_footprint) FROM RecycledClothing;
Which materials in the 'inventory' table have a quantity of at least 100 and are not used in the production of any product in the 'products' table?
CREATE TABLE inventory(id INT,material VARCHAR(255),quantity INT); CREATE TABLE products(id INT,material VARCHAR(255),quantity INT); INSERT INTO inventory(id,material,quantity) VALUES (1,'organic cotton',75),(2,'conventional cotton',100),(3,'organic cotton',30),(4,'hemp',60); INSERT INTO products(id,material,quantity) VALUES (1,'organic cotton',150),(2,'conventional cotton',200),(3,'hemp',100);
SELECT material FROM inventory i WHERE quantity >= 100 AND NOT EXISTS (SELECT * FROM products p WHERE i.material = p.material);
What is the average fabric waste (in kg) for each textile supplier in the NY region?
CREATE TABLE TextileSuppliers (SupplierID INT,SupplierName TEXT,Region TEXT,AvgFabricWaste FLOAT); INSERT INTO TextileSuppliers (SupplierID,SupplierName,Region,AvgFabricWaste) VALUES (1,'Supplier1','NY',15.5),(2,'Supplier2','NY',12.3),(3,'Supplier3','NJ',18.6);
SELECT Region, AVG(AvgFabricWaste) FROM TextileSuppliers WHERE Region = 'NY' GROUP BY Region;
What is the name and sensitivity of the biosensor technology with the lowest sensitivity?
CREATE SCHEMA if not exists biosensors;CREATE TABLE if not exists biosensors.technologies(id INT,name TEXT,sensitivity FLOAT);INSERT INTO biosensors.technologies(id,name,sensitivity) VALUES (1,'TechnologyA',95.2),(2,'TechnologyB',98.7),(3,'TechnologyC',99.4);
SELECT name, sensitivity FROM biosensors.technologies ORDER BY sensitivity ASC LIMIT 1;
Which graduate students have not received any research grants?
CREATE TABLE grad_students (id INT,name TEXT,department TEXT); INSERT INTO grad_students (id,name,department) VALUES (1,'John Doe','Computer Science'),(2,'Jane Smith','Mathematics'); CREATE TABLE research_grants (id INT,student_id INT,title TEXT); INSERT INTO research_grants (id,student_id,title) VALUES (1,3,'Machine Learning'),(2,4,'Graph Theory');
SELECT g.name FROM grad_students g LEFT JOIN research_grants r ON g.id = r.student_id WHERE r.id IS NULL;
Which smart city initiatives have been implemented in a given city?
CREATE TABLE City (city_id INT,city_name VARCHAR(50)); CREATE TABLE Initiative (initiative_id INT,initiative_name VARCHAR(50),city_id INT);
SELECT Initiative.initiative_name FROM City JOIN Initiative ON City.city_id = Initiative.city_id WHERE City.city_name = 'CityName';
Delete all records from the "virtual_tours" table where the "platform" is "WebXR"
CREATE TABLE virtual_tours (id INT,name VARCHAR(50),platform VARCHAR(50));
DELETE FROM virtual_tours WHERE platform = 'WebXR';
Delete the record for the 'Virtual Tour of the Great Wall' from the database.
CREATE TABLE tours (id INT,name TEXT,location TEXT); INSERT INTO tours (id,name,location) VALUES (1,'Virtual Tour of the Great Wall','China');
DELETE FROM tours WHERE name = 'Virtual Tour of the Great Wall' AND location = 'China';
What is the ranking of hotels in the 'asia_hotels' view by online travel agency bookings?
CREATE VIEW asia_hotels AS SELECT * FROM hotels WHERE continent = 'Asia'; CREATE VIEW online_travel_agency_bookings AS SELECT hotel_id,COUNT(*) as bookings FROM online_travel_agency GROUP BY hotel_id;
SELECT name, ROW_NUMBER() OVER (ORDER BY bookings DESC) as ranking FROM asia_hotels JOIN online_travel_agency_bookings ON asia_hotels.id = online_travel_agency_bookings.hotel_id;
What is the maximum and minimum temperature difference between any two Arctic research stations?
CREATE TABLE arctic_stations (id INT,name TEXT,location TEXT,temperature DECIMAL(5,2)); INSERT INTO arctic_stations (id,name,location,temperature) VALUES (1,'Station A','Greenland',2.3),(2,'Station B','Canada',-5.2);
SELECT a.name as station1, b.name as station2, MAX(ABS(a.temperature - b.temperature)) as temp_diff FROM arctic_stations a, arctic_stations b ORDER BY temp_diff DESC LIMIT 1
How many whale species are in the Southern Ocean?
CREATE TABLE SouthernOcean (whale_species TEXT,population INT); INSERT INTO SouthernOcean (whale_species,population) VALUES ('Blue Whale',2500),('Fin Whale',4000),('Humpback Whale',1500);
SELECT COUNT(whale_species) FROM SouthernOcean WHERE whale_species LIKE '%Whale%';
List all unique marine species observed in 'north_pole' and 'south_pole'.
CREATE TABLE polar_species_observations (id INTEGER,species_name VARCHAR(255),pole VARCHAR(255));
SELECT DISTINCT species_name FROM polar_species_observations WHERE pole IN ('North Pole', 'South Pole');
What is the minimum temperature (in degrees Celsius) recorded in the Indian Ocean in the last decade?
CREATE TABLE ocean_temperature (year INT,location TEXT,temperature FLOAT); INSERT INTO ocean_temperature (year,location,temperature) VALUES (2011,'Indian Ocean',26.0),(2012,'Indian Ocean',26.5),(2013,'Indian Ocean',27.0),(2014,'Indian Ocean',27.5),(2015,'Indian Ocean',28.0),(2016,'Indian Ocean',28.5),(2017,'Indian Ocean',29.0),(2018,'Indian Ocean',29.5),(2019,'Indian Ocean',30.0),(2020,'Indian Ocean',30.5);
SELECT MIN(temperature) FROM ocean_temperature WHERE year BETWEEN 2011 AND 2020 AND location = 'Indian Ocean';
What is the total population of all marine species in the Pacific ocean?
CREATE TABLE marine_species (id INT,name TEXT,population INT,location TEXT); INSERT INTO marine_species (id,name,population,location) VALUES (1,'Dolphin',50,'Atlantic'); INSERT INTO marine_species (id,name,population,location) VALUES (2,'Turtle',25,'Atlantic'); INSERT INTO marine_species (id,name,population,location) VALUES (3,'Shark',100,'Pacific');
SELECT SUM(population) FROM marine_species WHERE location = 'Pacific';
How many shows were released in each genre, and what is the total runtime for each genre?
CREATE TABLE shows (id INT,title VARCHAR(100),genre VARCHAR(50),country VARCHAR(50),release_year INT,runtime INT);
SELECT genre, COUNT(*), SUM(runtime) FROM shows GROUP BY genre;
What is the total runtime of TV shows with diverse casts?
CREATE TABLE tv_shows (show_id INT,runtime_minutes INT,cast_diverse BOOLEAN);
SELECT SUM(runtime_minutes) FROM tv_shows WHERE cast_diverse = TRUE;
What was the average military equipment sales price per quarter in 2019?
CREATE TABLE equipment_sales(id INT,quarter INT,year INT,equipment VARCHAR(255),price FLOAT);
SELECT quarter, AVG(price) FROM equipment_sales WHERE year = 2019 GROUP BY quarter;
What is the total CO2 emission for each equipment type, excluding equipment that is older than 8 years?
CREATE TABLE EmissionData (EquipmentID INT,EquipmentType VARCHAR(50),CO2Emission INT,Age INT); INSERT INTO EmissionData (EquipmentID,EquipmentType,CO2Emission,Age) VALUES (1,'Excavator',50,8); INSERT INTO EmissionData (EquipmentID,EquipmentType,CO2Emission,Age) VALUES (2,'Haul Truck',70,7); INSERT INTO EmissionData (EquipmentID,EquipmentType,CO2Emission,Age) VALUES (3,'Shovel',30,6); INSERT INTO EmissionData (EquipmentID,EquipmentType,CO2Emission,Age) VALUES (4,'Drilling Rig',40,3);
SELECT EquipmentType, SUM(CO2Emission) as TotalCO2Emission FROM EmissionData WHERE Age <= 8 GROUP BY EquipmentType;
What are the top 5 countries with the most broadband subscribers?
CREATE TABLE broadband_subscribers (subscriber_id INT,country VARCHAR(50)); INSERT INTO broadband_subscribers (subscriber_id,country) VALUES (1,'USA'),(2,'Canada'),(3,'Mexico'),(4,'Brazil'),(5,'USA'),(6,'Canada'),(7,'Germany'),(8,'France'); CREATE TABLE country_codes (country VARCHAR(50),code CHAR(2)); INSERT INTO country_codes (country,code) VALUES ('USA','US'),('Canada','CA'),('Mexico','MX'),('Brazil','BR'),('Germany','DE'),('France','FR');
SELECT bs.country, COUNT(bs.subscriber_id) AS num_subscribers FROM broadband_subscribers bs JOIN country_codes cc ON bs.country = cc.country GROUP BY bs.country ORDER BY num_subscribers DESC LIMIT 5;
What is the total number of postpaid and prepaid mobile subscribers in each region?
CREATE TABLE mobile_subscribers (subscriber_id INT,subscriber_type VARCHAR(10),region VARCHAR(20)); INSERT INTO mobile_subscribers (subscriber_id,subscriber_type,region) VALUES (1,'postpaid','West'),(2,'prepaid','East'),(3,'postpaid','North'),(4,'prepaid','South'),(5,'postpaid','East');
SELECT region, COUNT(*) as total_subscribers FROM mobile_subscribers GROUP BY region;
How many non-profit organizations are there in the 'social_services' sector with an annual revenue greater than $500,000?
CREATE TABLE organizations (org_id INT,org_name TEXT,sector TEXT,annual_revenue FLOAT); INSERT INTO organizations (org_id,org_name,sector,annual_revenue) VALUES (1,'Habitat for Humanity','social_services',600000.00),(2,'Red Cross','emergency_services',800000.00);
SELECT COUNT(*) FROM organizations WHERE sector = 'social_services' AND annual_revenue > 500000.00;
What is the mission statement for the nonprofit with the lowest average grant amount?
CREATE TABLE Nonprofits (NonprofitID INT,Name VARCHAR(50),City VARCHAR(50),State VARCHAR(2),Zip VARCHAR(10),MissionStatement TEXT); CREATE TABLE Grants (GrantID INT,DonorID INT,NonprofitID INT,GrantAmount DECIMAL(10,2),Date DATE);
SELECT MissionStatement FROM Nonprofits N WHERE N.NonprofitID = (SELECT G.NonprofitID FROM Grants G GROUP BY G.NonprofitID ORDER BY AVG(GrantAmount) ASC LIMIT 1);
Insert a new record into the "DeepSeaExploration" table with values (1, 'Atlantic Ocean', 'Successful')
CREATE TABLE DeepSeaExploration (Id INT,Location VARCHAR(20),Status VARCHAR(10));
INSERT INTO DeepSeaExploration (Id, Location, Status) VALUES (1, 'Atlantic Ocean', 'Successful');
What is the maximum score achieved in the 'scores' table?
CREATE TABLE scores (player_id INT,game_id INT,score FLOAT); INSERT INTO scores VALUES (1,1,95.6),(2,1,98.7),(3,2,85.2),(4,2,88.3),(5,3,120.5),(6,3,125.8);
SELECT MAX(score) FROM scores;