instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Which suppliers have sold timber in a specific forest plot?
CREATE TABLE Suppliers (SupplierID int,SupplierName varchar(50)); INSERT INTO Suppliers VALUES (1,'SupplierA'),(2,'SupplierB'); CREATE TABLE Sales (SaleID int,SupplierID int,PlotID int); INSERT INTO Sales VALUES (1,1,1),(2,1,2),(3,2,1); CREATE TABLE ForestPlots (PlotID int,PlotName varchar(50)); INSERT INTO ForestPlots...
SELECT Suppliers.SupplierName FROM Suppliers INNER JOIN Sales ON Suppliers.SupplierID = Sales.SupplierID INNER JOIN ForestPlots ON Sales.PlotID = ForestPlots.PlotID WHERE ForestPlots.PlotName = 'Plot1';
What are the names of all spacecraft that have been to the outer solar system?
CREATE TABLE Spacecraft (SpacecraftID INT,HasVisitedOuterSolarSystem BOOLEAN,Name VARCHAR);
SELECT Name FROM Spacecraft WHERE HasVisitedOuterSolarSystem = TRUE;
What are the maximum and minimum consumer preference scores for cruelty-free products?
CREATE TABLE Brands (BrandName VARCHAR(50),CrueltyFree BOOLEAN,ConsumerPreferenceScore INT); INSERT INTO Brands (BrandName,CrueltyFree,ConsumerPreferenceScore) VALUES ('The Body Shop',TRUE,92),('Lush',TRUE,95),('Urban Decay',TRUE,87);
SELECT MAX(ConsumerPreferenceScore), MIN(ConsumerPreferenceScore) FROM Brands WHERE CrueltyFree = TRUE;
What is the total budget for projects with a risk level of 'Medium'?
CREATE TABLE projects (id INT,name VARCHAR(50),budget DECIMAL(10,2),risk_level VARCHAR(10),PRIMARY KEY(id)); INSERT INTO projects (id,name,budget,risk_level) VALUES (1,'Army Tank Development',50000000,'Medium'); INSERT INTO projects (id,name,budget,risk_level) VALUES (2,'Missile System Upgrade',70000000,'Low');
SELECT SUM(budget) as total_budget FROM projects WHERE risk_level = 'Medium';
Get the top 5 most common topics among articles with a word count > 1000
CREATE TABLE topics (id INT PRIMARY KEY,name TEXT NOT NULL); CREATE TABLE articles_topics (article_id INT,topic_id INT); CREATE TABLE articles (id INT PRIMARY KEY,title TEXT NOT NULL,word_count INT);
SELECT topics.name, COUNT(articles_topics.article_id) as article_count FROM topics INNER JOIN articles_topics ON topics.id = articles_topics.topic_id INNER JOIN articles ON articles_topics.article_id = articles.id WHERE articles.word_count > 1000 GROUP BY topics.name ORDER BY article_count DESC LIMIT 5;
Which vendors have contracts that require military equipment maintenance in a specific region?
CREATE TABLE if not exists equipment_maintenance (contract_id INT,vendor VARCHAR(255),equipment VARCHAR(255),maintenance_region VARCHAR(255)); INSERT INTO equipment_maintenance (contract_id,vendor,equipment,maintenance_region) VALUES (3,'DEF Corp','F-35','Southwest');
SELECT defense_contracts.vendor, military_equipment.equipment, equipment_maintenance.maintenance_region FROM defense_contracts INNER JOIN military_equipment ON defense_contracts.contract_id = military_equipment.contract_id INNER JOIN equipment_maintenance ON military_equipment.equipment_id = equipment_maintenance.equip...
What is the average salary of male and female employees in each department?
CREATE TABLE Employee (id INT,Name VARCHAR(50),DepartmentID INT,Salary FLOAT,Gender VARCHAR(10)); INSERT INTO Employee (id,Name,DepartmentID,Salary,Gender) VALUES (101,'Employee1',1,50000,'Female'); INSERT INTO Employee (id,Name,DepartmentID,Salary,Gender) VALUES (102,'Employee2',1,55000,'Male'); INSERT INTO Employee (...
SELECT DepartmentID, AVG(CASE WHEN Gender = 'Male' THEN Salary ELSE NULL END) AS AvgMaleSalary, AVG(CASE WHEN Gender = 'Female' THEN Salary ELSE NULL END) AS AvgFemaleSalary FROM Employee GROUP BY DepartmentID;
Calculate the average temperature of the Atlantic Ocean in January.
CREATE TABLE temperature_data (month INTEGER,location TEXT,temperature FLOAT); INSERT INTO temperature_data (month,location,temperature) VALUES (1,'Atlantic Ocean',25.0); INSERT INTO temperature_data (month,location,temperature) VALUES (2,'Atlantic Ocean',26.0);
SELECT AVG(temperature) FROM temperature_data WHERE month = 1 AND location = 'Atlantic Ocean';
Delete all records from the 'animal_population' table where the population is less than 700.
CREATE TABLE animal_population (id INT,species VARCHAR(255),population INT); INSERT INTO animal_population (id,species,population) VALUES (1,'Tiger',500),(2,'Elephant',2000),(3,'Lion',800),(4,'Giraffe',1500);
DELETE FROM animal_population WHERE population < 700;
What is the average age of fans who have attended at least five NBA games in the last year?
CREATE TABLE nba_fans (fan_id INT,name VARCHAR(50),age INT,games_attended INT); INSERT INTO nba_fans (fan_id,name,age,games_attended) VALUES (1,'John Smith',35,6),(2,'Maria Garcia',28,4),(3,'James Kim',40,7),(4,'Sarah Lee',31,3);
SELECT AVG(age) FROM nba_fans WHERE games_attended >= 5;
What is the total revenue generated from sustainable material sales in the North region?
CREATE TABLE sales (id INT,material VARCHAR(50),region VARCHAR(50),revenue INT); INSERT INTO sales (id,material,region,revenue) VALUES (1,'organic cotton','North',1000),(2,'recycled polyester','North',1500),(3,'conventional cotton','South',2000),(4,'polyester','South',2500);
SELECT SUM(revenue) as total_sustainable_revenue FROM sales WHERE material LIKE '%sustainable%' AND region = 'North';
Identify the total number of satellites launched by China and India?
CREATE TABLE satellite_launches (id INT,country TEXT,launch_year INT,satellite_name TEXT); INSERT INTO satellite_launches (id,country,launch_year,satellite_name) VALUES (1,'China',2010,'Satellite1'),(2,'India',2015,'Satellite2');
SELECT SUM(satellite_launches.id) FROM satellite_launches WHERE country IN ('China', 'India');
What is the average number of autonomous vehicle tests for each city?
CREATE TABLE autonomous_vehicles (id INT,city_id INT,model VARCHAR(50),year INT,tests INT); INSERT INTO autonomous_vehicles (id,city_id,model,year,tests) VALUES (4,3,'Zoox',2022,60000); INSERT INTO autonomous_vehicles (id,city_id,model,year,tests) VALUES (5,3,'NVIDIA Drive',2021,50000);
SELECT city_id, AVG(tests) FROM autonomous_vehicles GROUP BY city_id;
What is the maximum age of members in unions with a 'manufacturing' industry classification?
CREATE TABLE unions (id INT,name VARCHAR(255),industry VARCHAR(255),member_age INT); INSERT INTO unions (id,name,industry,member_age) VALUES (1,'Union A','manufacturing',50),(2,'Union B','manufacturing',45),(3,'Union C','manufacturing',55);
SELECT MAX(member_age) FROM unions WHERE industry = 'manufacturing';
What is the total number of trips for each vehicle?
CREATE TABLE vehicle (vehicle_id INT,model VARCHAR(255)); CREATE TABLE trip (trip_id INT,vehicle_id INT,fare DECIMAL(10,2)); INSERT INTO vehicle (vehicle_id,model) VALUES (1,'Vehicle X'),(2,'Vehicle Y'),(3,'Vehicle Z'); INSERT INTO trip (trip_id,vehicle_id,fare) VALUES (1,1,2.00),(2,1,3.00),(3,2,4.00),(4,3,5.00);
SELECT v.vehicle_id, v.model, COUNT(t.trip_id) AS trip_count FROM vehicle v JOIN trip t ON v.vehicle_id = t.vehicle_id GROUP BY v.vehicle_id;
Who volunteered for the Arts program in Q1 2021 and how many hours did they contribute?
CREATE TABLE Arts_Volunteers (id INT,volunteer VARCHAR(50),program VARCHAR(50),hours FLOAT,volunteer_date DATE); INSERT INTO Arts_Volunteers (id,volunteer,program,hours,volunteer_date) VALUES (1,'Olivia Smith','Arts',5,'2021-01-01'); INSERT INTO Arts_Volunteers (id,volunteer,program,hours,volunteer_date) VALUES (2,'Kev...
SELECT volunteer, SUM(hours) as total_hours FROM Arts_Volunteers WHERE QUARTER(volunteer_date) = 1 AND program = 'Arts' GROUP BY volunteer;
Get the number of unique authors and their total word count.
CREATE TABLE news_articles (id INT,title VARCHAR(100),content TEXT,author_id INT); CREATE TABLE authors (id INT,name VARCHAR(50));
SELECT a.name, COUNT(DISTINCT na.id) AS articles_count, SUM(LENGTH(na.content) - LENGTH(REPLACE(na.content, ' ', '')) + 1) AS word_count FROM news_articles na JOIN authors a ON na.author_id = a.id GROUP BY a.name;
How many artifacts were found at each excavation site, broken down by the material of the artifact?
CREATE TABLE ExcavationSites (SiteID int,SiteName varchar(50),Location varchar(50)); CREATE TABLE Artifacts (ArtifactID int,SiteID int,Material varchar(20),Description varchar(100));
SELECT ExcavationSites.SiteName, Artifacts.Material, COUNT(Artifacts.ArtifactID) AS CountOfArtifacts FROM ExcavationSites INNER JOIN Artifacts ON ExcavationSites.SiteID = Artifacts.SiteID GROUP BY ExcavationSites.SiteName, Artifacts.Material;
Top 3 cities with highest hotel ratings in 'Europe'?
CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,hotel_rating FLOAT,hotel_location TEXT); INSERT INTO hotels (hotel_id,hotel_name,hotel_rating,hotel_location) VALUES (1,'Hotel Paris',4.6,'Europe'),(2,'Hotel London',4.5,'Europe'),(3,'Hotel Rome',4.4,'Europe');
SELECT hotel_location, AVG(hotel_rating) avg_rating FROM hotels WHERE hotel_location = 'Europe' GROUP BY hotel_location ORDER BY avg_rating DESC LIMIT 3;
Show the top 5 users with the most followers, along with the number of posts they've made.
CREATE TABLE if not exists user_info (user_id int,username varchar(50),followers int,following int);CREATE TABLE if not exists post (post_id int,user_id int,content_type varchar(10),post_date date);
SELECT u.username, u.followers, COUNT(p.post_id) as total_posts FROM user_info u INNER JOIN post p ON u.user_id = p.user_id GROUP BY u.username, u.followers ORDER BY followers DESC, total_posts DESC LIMIT 5;
What is the name and ID of the most recently added bridge?
CREATE TABLE Bridges (ID INT,Name VARCHAR(50),Location VARCHAR(50),DateAdded DATE); INSERT INTO Bridges (ID,Name,Location,DateAdded) VALUES (1,'Golden Gate Bridge','San Francisco,CA','1937-05-27'); INSERT INTO Bridges (ID,Name,Location,DateAdded) VALUES (2,'George Washington Bridge','New York,NY','1931-10-25');
SELECT Name, ID FROM Bridges ORDER BY DateAdded DESC LIMIT 1;
List the number of exploration wells drilled in each basin in the Caspian Sea
CREATE TABLE exploration_wells (basin VARCHAR(255),region VARCHAR(255),num_wells INT); INSERT INTO exploration_wells (basin,region,num_wells) VALUES ('Absheron','Caspian Sea',25),('Kashagan','Caspian Sea',30),('Gunashli','Caspian Sea',12);
SELECT basin, SUM(num_wells) FROM exploration_wells WHERE region = 'Caspian Sea' GROUP BY basin;
What is the average sustainability rating of properties in the city of Chicago?
CREATE TABLE properties (id INT,city VARCHAR(255),sustainability_rating INT); INSERT INTO properties (id,city,sustainability_rating) VALUES (1,'Chicago',3),(2,'Chicago',4),(3,'Chicago',5),(4,'Milwaukee',2);
SELECT AVG(sustainability_rating) FROM properties WHERE city = 'Chicago';
What is the total quantity of unsold garments, grouped by their material type, that are present in the 'inventory' table?
CREATE TABLE inventory (id INT,garment_name VARCHAR(50),material VARCHAR(50),quantity_manufactured INT,quantity_sold INT);
SELECT material, SUM(quantity_manufactured - quantity_sold) AS total_unsold_quantity FROM inventory GROUP BY material;
How many virtual tours are available for historical sites in Japan?
CREATE TABLE virtual_tours (tour_id INT,site_name VARCHAR(50),country VARCHAR(50)); INSERT INTO virtual_tours VALUES (1,'Himeji Castle','Japan'),(2,'Mount Fuji','Japan'),(3,'Tower of London','England');
SELECT COUNT(*) FROM virtual_tours WHERE country = 'Japan';
What is the total revenue generated from ethical product sales in the last 6 months?
CREATE TABLE products (product_id int,is_ethical boolean,revenue decimal); INSERT INTO products (product_id,is_ethical,revenue) VALUES (1,true,1000),(2,false,2000),(3,true,3000);
SELECT SUM(revenue) FROM products WHERE is_ethical = true AND purchase_date >= DATEADD(month, -6, GETDATE());
Which types of artifacts are most commonly found in 'African' excavations?
CREATE TABLE Artifact_Types (TypeID INT,Type VARCHAR(50)); INSERT INTO Artifact_Types (TypeID,Type) VALUES (1,'Pottery'); INSERT INTO Artifact_Types (TypeID,Type) VALUES (2,'Tools'); INSERT INTO Artifact_Types (TypeID,Type) VALUES (3,'Beads'); CREATE TABLE Artifacts (ArtifactID INT,Site VARCHAR(50),TypeID INT,Quantity ...
SELECT A.Type, SUM(A.Quantity) AS Total_Quantity FROM Artifacts A INNER JOIN (SELECT DISTINCT Site FROM Excavations WHERE Country = 'Africa') E ON A.Site = E.Site GROUP BY A.Type;
How many times has each artist performed, and who has performed the most?
CREATE TABLE performances (artist VARCHAR(50),performance_count INT); INSERT INTO performances (artist,performance_count) VALUES ('Artist A',3),('Artist B',2),('Artist C',4);
SELECT artist, performance_count, ROW_NUMBER() OVER (ORDER BY performance_count DESC) AS rank FROM performances;
List the names of psychiatrists who conducted therapy sessions in Texas.
CREATE TABLE therapists (therapist_id INT,name VARCHAR(50),state VARCHAR(2)); INSERT INTO therapists (therapist_id,name,state) VALUES (1,'Dr. Smith','TX'),(2,'Dr. Johnson','NY'),(3,'Dr. Brown','TX');
SELECT name FROM therapists WHERE state = 'TX';
What's the minimum budget for TV shows in the 'Action' genre?
CREATE TABLE TVShows (id INT,title VARCHAR(100),genre VARCHAR(20),budget FLOAT);
SELECT MIN(budget) FROM TVShows WHERE genre = 'Action';
Delete records of cyber attacks that happened before 2010 from the "cyber_attacks" table
CREATE TABLE cyber_attacks (id INT,year INT,type VARCHAR(255),country VARCHAR(255)); INSERT INTO cyber_attacks (id,year,type,country) VALUES (1,2010,'AE','Phishing'); INSERT INTO cyber_attacks (id,year,type,country) VALUES (2,2012,'BR','Malware'); INSERT INTO cyber_attacks (id,year,type,country) VALUES (3,2014,'CN','DD...
DELETE FROM cyber_attacks WHERE year < 2010;
What is the total number of electric buses in the German public transportation system?
CREATE TABLE public_transportation (id INT,country VARCHAR(255),type VARCHAR(255),quantity INT); INSERT INTO public_transportation (id,country,type,quantity) VALUES (1,'Germany','Electric Bus',250),(2,'Germany','Diesel Bus',500);
SELECT SUM(quantity) FROM public_transportation WHERE country = 'Germany' AND type = 'Electric Bus';
Find the total quantity of sustainable materials used by brands in the Asia-Pacific region.
CREATE TABLE brands (brand_id INT,name VARCHAR(255),region VARCHAR(255)); INSERT INTO brands (brand_id,name,region) VALUES (1,'GreenBrand','Asia-Pacific'),(2,'EcoFashion','Europe'); CREATE TABLE materials (material_id INT,name VARCHAR(255),is_sustainable BOOLEAN); INSERT INTO materials (material_id,name,is_sustainable)...
SELECT SUM(bm.quantity) FROM brand_materials bm JOIN brands b ON bm.brand_id = b.brand_id JOIN materials m ON bm.material_id = m.material_id WHERE b.region = 'Asia-Pacific' AND m.is_sustainable = TRUE;
How many artifacts of type 'Pottery' are there in total?
CREATE TABLE SiteE (artifact_id INT,artifact_type TEXT,quantity INT); INSERT INTO SiteE (artifact_id,artifact_type,quantity) VALUES (1,'Pottery',30),(2,'Tools',15),(3,'Jewelry',25); INSERT INTO SiteE (artifact_id,artifact_type,quantity) VALUES (4,'Pottery',20),(5,'Tools',10),(6,'Jewelry',25);
SELECT SUM(quantity) FROM SiteE WHERE artifact_type = 'Pottery';
What is the daily waste generation trend in kg for the past year?
CREATE TABLE daily_waste_generation(date DATE,waste_kg FLOAT);
SELECT date, waste_kg FROM daily_waste_generation WHERE date >= DATEADD(year, -1, GETDATE()) ORDER BY date;
Show the total carbon offsets achieved by each smart city technology.
CREATE TABLE SmartCityTechnologies (TechID INT,TechName VARCHAR(50));CREATE TABLE CarbonOffsets (OffsetID INT,TechID INT,Amount FLOAT);
SELECT SmartCityTechnologies.TechName, SUM(CarbonOffsets.Amount) FROM SmartCityTechnologies INNER JOIN CarbonOffsets ON SmartCityTechnologies.TechID = CarbonOffsets.TechID GROUP BY SmartCityTechnologies.TechName;
Number of Series A rounds for startups founded by Latinx?
CREATE TABLE rounds (id INT,startup_id INT,round_type TEXT,round_date DATE,amount FLOAT);
SELECT COUNT(*) FROM rounds WHERE round_type = 'Series A' AND startup_id IN (SELECT id FROM startups WHERE founder_gender = 'latinx');
Which construction companies have worked on the most sustainable building projects, and what are their names and the number of projects they have worked on?
CREATE TABLE Company_Sustainable_Projects (Company TEXT,Project_ID INT); INSERT INTO Company_Sustainable_Projects (Company,Project_ID) VALUES ('XYZ Construction',1),('XYZ Construction',2),('ABC Construction',3),('ABC Construction',4),('Smith & Sons',5),('Smith & Sons',6),('Green Builders',7),('Green Builders',8),('Gree...
SELECT csp.Company, COUNT(csp.Project_ID) AS Project_Count FROM Company_Sustainable_Projects csp GROUP BY csp.Company ORDER BY Project_Count DESC;
What is the average temperature in Indian tea plantations for the last week from Precision farming data?
CREATE TABLE if not exists precision_farming_data (id INT,location VARCHAR(255),temperature FLOAT,farming_date DATETIME); INSERT INTO precision_farming_data (id,location,temperature,farming_date) VALUES (1,'India',24.6,'2022-03-25 10:00:00'),(2,'Nepal',21.5,'2022-03-25 10:00:00');
SELECT AVG(temperature) FROM precision_farming_data WHERE location = 'India' AND farming_date BETWEEN DATE_SUB(NOW(), INTERVAL 1 WEEK) AND NOW();
Display the average policy duration, by policy type and marital status, for policyholders in California.
CREATE TABLE Policy (PolicyId INT,PolicyType VARCHAR(50),IssueDate DATE,ExpirationDate DATE,PolicyholderMaritalStatus VARCHAR(20),Region VARCHAR(50));
SELECT Policy.PolicyType, Policy.PolicyholderMaritalStatus, AVG(DATEDIFF(day, IssueDate, ExpirationDate)) as AveragePolicyDuration FROM Policy WHERE Policy.Region = 'California' GROUP BY Policy.PolicyType, Policy.PolicyholderMaritalStatus;
What is the average revenue of fairly traded products in the last quarter?
CREATE TABLE sales (sale_id int,product_id int,is_fair_trade boolean,revenue decimal,sale_date date);
SELECT AVG(revenue) FROM sales WHERE is_fair_trade = true AND sale_date >= DATEADD(quarter, -1, GETDATE());
What is the average rating of movies released in Spain?
CREATE TABLE movies (id INT,title VARCHAR(100),genre VARCHAR(50),release_year INT,rating DECIMAL(3,2),country VARCHAR(50)); INSERT INTO movies (id,title,genre,release_year,rating,country) VALUES (1,'Movie1','Comedy',2020,8.2,'Spain'); INSERT INTO movies (id,title,genre,release_year,rating,country) VALUES (2,'Movie2','D...
SELECT AVG(rating) FROM movies WHERE country = 'Spain';
Update the temperature sensor readings to 25 degrees Celsius for sensor_id 12
CREATE TABLE temperature_sensor_data (sensor_id INT,temperature FLOAT,timestamp TIMESTAMP); INSERT INTO temperature_sensor_data (sensor_id,temperature,timestamp) VALUES (12,23.6,'2022-05-21 10:00:00');
WITH updated_data AS (UPDATE temperature_sensor_data SET temperature = 25 WHERE sensor_id = 12 RETURNING *) SELECT * FROM updated_data;
List all decentralized applications created by developers from African countries?
CREATE TABLE decentralized_apps (id INT,name VARCHAR(255),developer_country VARCHAR(50)); INSERT INTO decentralized_apps (id,name,developer_country) VALUES (1,'App1','Nigeria'),(2,'App2','South Africa'),(3,'App3','USA'),(4,'App4','Egypt');
SELECT name FROM decentralized_apps WHERE developer_country IN ('Nigeria', 'South Africa', 'Egypt', 'Kenya', 'Tunisia');
Delete all records with donation amounts below 1000 in the 'donations' table.
CREATE TABLE donations (donation_id INT,donor_id INT,campaign_id INT,donation_amount DECIMAL(10,2));
DELETE FROM donations WHERE donation_amount < 1000;
What are the total assets of Shariah-compliant banks in the United States?
CREATE TABLE shariah_banks (bank_name TEXT,location TEXT,total_assets NUMERIC); INSERT INTO shariah_banks (bank_name,location,total_assets) VALUES ('ABC Bank','USA',5000000),('XYZ Finance','USA',7000000);
SELECT SUM(total_assets) FROM shariah_banks WHERE location = 'USA';
What was the total amount donated by all donors from 'United States' in the year 2020?
CREATE TABLE Donors (DonorID int,DonorName varchar(100),Country varchar(50),DonationAmount decimal(10,2)); INSERT INTO Donors (DonorID,DonorName,Country,DonationAmount) VALUES (1,'John Doe','United States',500.00);
SELECT SUM(DonationAmount) FROM Donors WHERE Country = 'United States' AND YEAR(DonationDate) = 2020;
What are the names and IDs of players who have played games from all unique genres in the 'Game Design' table?
CREATE TABLE Players (PlayerID INT,Name VARCHAR(100),GameID INT); INSERT INTO Players (PlayerID,Name,GameID) VALUES (1,'John Doe',1),(2,'Jane Smith',2),(3,'James Brown',3),(4,'Sophia Johnson',4),(5,'Emma White',1),(6,'Oliver Black',2),(7,'Lucas Green',3),(8,'Ava Blue',4); CREATE TABLE Game_Design (GameID INT,GameName V...
SELECT DISTINCT p.PlayerID, p.Name FROM Players p INNER JOIN Game_Design gd ON p.GameID = gd.GameID GROUP BY p.PlayerID, p.Name HAVING COUNT(DISTINCT gd.Genre) = (SELECT COUNT(DISTINCT Genre) FROM Game_Design);
Count the number of bike racks on Red Line trains
CREATE TABLE train_features (feature VARCHAR(50),fleet_name VARCHAR(50)); INSERT INTO train_features (feature,fleet_name) VALUES ('Bike Rack','Red Line'),('Wheelchair Space','Red Line'),('Luggage Rack','Blue Line');
SELECT COUNT(*) FROM train_features WHERE feature = 'Bike Rack' AND fleet_name = 'Red Line';
List all coordinators of community development initiatives in Nigeria and their initiatives.
CREATE TABLE CommunityDev (id INT,initiative VARCHAR(255),country VARCHAR(255),coordinator VARCHAR(255)); INSERT INTO CommunityDev (id,initiative,country,coordinator) VALUES (1,'Youth Empowerment','Nigeria','Adebayo Adeleke'),(2,'Elderly Care','Nigeria','Bolanle Adebisi');
SELECT coordinator, initiative FROM CommunityDev WHERE country = 'Nigeria';
Which cities have the most green buildings in the 'green_buildings' schema?
CREATE SCHEMA if not exists green_buildings; CREATE TABLE if not exists green_buildings.buildings (id INT,building_name VARCHAR,city VARCHAR,co2_emissions FLOAT); INSERT INTO green_buildings.buildings (id,building_name,city,co2_emissions) VALUES (1,'Green Building 1','New York',100),(2,'Green Building 2','Los Angeles',...
SELECT city, COUNT(*) FROM green_buildings.buildings WHERE co2_emissions IS NOT NULL GROUP BY city ORDER BY COUNT(*) DESC;
How many publications has each faculty member in the College of Science authored?
CREATE TABLE faculty (id INT,name VARCHAR(255),department_id INT); INSERT INTO faculty (id,name,department_id) VALUES (1,'Alice',1),(2,'Bob',1),(3,'Charlie',2),(4,'Diana',2); CREATE TABLE publication (id INT,faculty_id INT,title VARCHAR(255)); INSERT INTO publication (id,faculty_id,title) VALUES (1,1,'Paper 1'),(2,1,'P...
SELECT f.name, COUNT(p.id) as num_publications FROM faculty f JOIN publication p ON f.id = p.faculty_id WHERE f.department_id IN (SELECT id FROM department WHERE name = 'College of Science') GROUP BY f.name;
What is the total production of quinoa in 2020, grouped by country?
CREATE TABLE QuinoaProduction (Country VARCHAR(50),Year INT,Production INT);
SELECT Country, SUM(Production) FROM QuinoaProduction WHERE Year = 2020 GROUP BY Country;
Get the number of mobile subscribers in each country who used more than 3 GB of data in Q1 2021?
CREATE TABLE mobile_subscribers (subscriber_id INT,data_usage DECIMAL(5,2),country VARCHAR(50),registration_date DATE); INSERT INTO mobile_subscribers (subscriber_id,data_usage,country,registration_date) VALUES (1,4.5,'USA','2021-01-01'),(2,2.2,'Canada','2021-01-15'),(3,1.8,'Mexico','2021-01-05'),(4,3.2,'USA','2021-01-...
SELECT country, COUNT(*) AS num_subscribers FROM mobile_subscribers WHERE country IN ('USA', 'Canada', 'Mexico') AND YEAR(registration_date) = 2021 AND QUARTER(registration_date) = 1 AND data_usage > 3 GROUP BY country;
Identify the top 3 regions with the highest number of community health workers and mental health professionals combined.
CREATE TABLE HealthWorkers (Region VARCHAR(20),WorkerType VARCHAR(20),Count INT); INSERT INTO HealthWorkers (Region,WorkerType,Count) VALUES ('Northeast','MentalHealthProfessional',900),('Northeast','CommunityHealthWorker',500),('Southeast','MentalHealthProfessional',600),('Southeast','CommunityHealthWorker',400),('Mid...
SELECT Region, SUM(Count) AS TotalCount FROM HealthWorkers GROUP BY Region ORDER BY TotalCount DESC LIMIT 3;
Update the 'num_passengers' column in the 'public_transit' table for the 'route_id' 25 to 30
CREATE TABLE public_transit (route_id INT,num_passengers INT,route_type VARCHAR(255),route_length FLOAT);
UPDATE public_transit SET num_passengers = 30 WHERE route_id = 25;
How many articles were published by 'The Seattle Tribune' in each month of the last year, including months without any articles?
CREATE TABLE the_seattle_tribune (publication_date DATE);
SELECT to_char(publication_date, 'Month') as month, COUNT(*) as articles FROM the_seattle_tribune WHERE publication_date > DATE('now','-1 year') GROUP BY month ORDER BY MIN(publication_date);
What is the minimum wage in textile factories in India?
CREATE TABLE Wages (WageID INT,MinWage FLOAT,Country VARCHAR(20)); INSERT INTO Wages VALUES (1,150,'India'); INSERT INTO Wages VALUES (2,180,'India');
SELECT MinWage FROM Wages WHERE Country = 'India' ORDER BY MinWage ASC LIMIT 1;
How many airports were built in the Western region before 2010?
CREATE TABLE InfrastructureProjects (id INT,name VARCHAR(100),region VARCHAR(50),project_type VARCHAR(50),completion_date DATE); INSERT INTO InfrastructureProjects (id,name,region,project_type,completion_date) VALUES (1,'San Francisco Airport','Western','airport','2002-01-01');
SELECT COUNT(*) FROM InfrastructureProjects WHERE region = 'Western' AND project_type = 'airport' AND completion_date < '2010-01-01';
What is the average labor productivity in silver mining?
CREATE TABLE labor (employee_id INT,employee_name VARCHAR(50),department VARCHAR(20),hours_worked INT,productivity INT); INSERT INTO labor (employee_id,employee_name,department,hours_worked,productivity) VALUES (1,'Juan Garcia','silver',160,500),(2,'Maria Rodriguez','silver',180,600),(3,'Pedro Lopez','gold',165,700),(4...
SELECT AVG(l.productivity) AS avg_productivity FROM labor l WHERE l.department = 'silver';
Delete all records in the 'drilling_rigs' table where 'operating_company' is 'Transocean'
CREATE TABLE drilling_rigs (rig_id INT PRIMARY KEY,rig_name VARCHAR(50),operating_company VARCHAR(50));
DELETE FROM drilling_rigs WHERE operating_company = 'Transocean';
What is the success rate of economic diversification efforts in Zambia in the last 2 years?
CREATE TABLE efforts(id INT,name TEXT,country TEXT,start_date DATE,end_date DATE,success BOOLEAN); INSERT INTO efforts(id,name,country,start_date,end_date,success) VALUES (1,'Small Business Loans','Zambia','2020-01-01','2021-12-31',true),(2,'Vocational Training','Zambia','2019-01-01','2020-12-31',false);
SELECT COUNT(*)/COUNT(DISTINCT id) FROM efforts WHERE country = 'Zambia' AND start_date >= DATE('2020-01-01') AND end_date <= DATE('2021-12-31') AND success = true;
What is the number of climate change related disasters in Oceania from 2005 to 2015?
CREATE TABLE disasters (year INT,continent TEXT,disaster TEXT); INSERT INTO disasters (year,continent,disaster) VALUES (2005,'Oceania','Cyclone'),(2006,'Oceania','Flood'),(2007,'Oceania','Drought'),(2008,'Oceania','Heatwave'),(2009,'Oceania','Tornado'),(2010,'Oceania','Volcanic Eruption'),(2011,'Oceania','Landslide'),(...
SELECT continent, COUNT(DISTINCT year) FROM disasters WHERE continent = 'Oceania' AND year BETWEEN 2005 AND 2015 GROUP BY continent;
List all the programs that have been funded by at least one donation, along with their total funding amounts and the number of individual donors.
CREATE TABLE Programs (ProgramID INT,ProgramName VARCHAR(50)); INSERT INTO Programs (ProgramID,ProgramName) VALUES (1,'Education'),(2,'Healthcare'),(3,'Environment'); CREATE TABLE Donations (DonationID INT,DonorID INT,ProgramID INT,DonationAmount DECIMAL(10,2)); INSERT INTO Donations (DonationID,DonorID,ProgramID,Donat...
SELECT Programs.ProgramName, SUM(Donations.DonationAmount) AS TotalFunding, COUNT(DISTINCT Donors.DonorID) AS DonorCount FROM Programs INNER JOIN Donations ON Programs.ProgramID = Donations.ProgramID INNER JOIN Donors ON Donations.DonorID = Donors.DonorID GROUP BY Programs.ProgramName;
List all the unique vulnerabilities that have been exploited in the last 30 days, along with the number of times each vulnerability has been exploited.
CREATE TABLE exploited_vulnerabilities (vulnerability VARCHAR(50),exploit_count INT,exploit_date DATE); INSERT INTO exploited_vulnerabilities (vulnerability,exploit_count,exploit_date) VALUES ('Vulnerability A',20,'2023-01-01'),('Vulnerability B',15,'2023-01-02'),('Vulnerability C',12,'2023-01-03'),('Vulnerability A',1...
SELECT vulnerability, SUM(exploit_count) AS total_exploits FROM exploited_vulnerabilities WHERE exploit_date >= DATEADD(day, -30, GETDATE()) GROUP BY vulnerability;
What is the average number of endangered languages in Southeast Asian countries?
CREATE TABLE Countries (id INT,name VARCHAR(50),region VARCHAR(50)); INSERT INTO Countries (id,name,region) VALUES (1,'Indonesia','Southeast Asia'),(2,'Philippines','Southeast Asia'),(3,'Malaysia','Southeast Asia'),(4,'Myanmar','Southeast Asia'),(5,'Thailand','Southeast Asia'); CREATE TABLE EndangeredLanguages (id INT,...
SELECT AVG(e.count) as avg_endangered_languages FROM (SELECT COUNT(*) as count FROM EndangeredLanguages WHERE country_id = Countries.id GROUP BY country_id) e JOIN Countries ON e.country_id = Countries.id WHERE Countries.region = 'Southeast Asia';
What is the average cost of a 'beef burger' at all restaurants?
CREATE TABLE menus (restaurant VARCHAR(255),item VARCHAR(255),cost FLOAT); INSERT INTO menus (restaurant,item,cost) VALUES ('Burger Spot','beef burger',8.5),('Gourmet Delight','beef burger',12.0);
SELECT AVG(cost) FROM menus WHERE item = 'beef burger';
What is the total revenue for 'Tasty Bites' in 2021?
CREATE TABLE revenues (restaurant VARCHAR(255),year INT,revenue INT); INSERT INTO revenues (restaurant,year,revenue) VALUES ('Tasty Bites',2021,350000);
SELECT revenue FROM revenues WHERE restaurant = 'Tasty Bites' AND year = 2021;
Show the number of pallets and total weight of freight for each country.
CREATE TABLE countries (country_code CHAR(2),country_name VARCHAR(50)); INSERT INTO countries VALUES ('US','United States'),('CA','Canada'),('MX','Mexico'); CREATE TABLE freight (id INT,country_code CHAR(2),weight INT,pallets INT); INSERT INTO freight VALUES (1,'US',500,10),(2,'CA',400,8),(3,'MX',600,12);
SELECT c.country_name, SUM(f.weight) as total_weight, SUM(f.pallets) as total_pallets FROM freight f INNER JOIN countries c ON f.country_code = c.country_code GROUP BY c.country_name;
What is the total number of tickets sold for pop concerts in North America since 2021?
CREATE TABLE Concerts (ConcertID INT PRIMARY KEY,ConcertName VARCHAR(100),Location VARCHAR(100),Genre VARCHAR(50),TicketsSold INT,TicketPrice DECIMAL(5,2),SaleDate DATE); INSERT INTO Concerts (ConcertID,ConcertName,Location,Genre,TicketsSold,TicketPrice,SaleDate) VALUES (1,'Concert 1','USA','Pop',500,50.00,'2022-01-01'...
SELECT SUM(TicketsSold) FROM Concerts WHERE Genre = 'Pop' AND Location LIKE 'North%' AND YEAR(SaleDate) >= 2021;
What is the total number of employees from each country, and the percentage of the total workforce they represent?
CREATE TABLE Employees (EmployeeID INT,Country VARCHAR(255)); INSERT INTO Employees (EmployeeID,Country) VALUES (1,'USA'); INSERT INTO Employees (EmployeeID,Country) VALUES (2,'Canada'); INSERT INTO Employees (EmployeeID,Country) VALUES (3,'Mexico');
SELECT E.Country, COUNT(E.EmployeeID) AS Num_Employees, COUNT(E.EmployeeID) * 100.0 / (SELECT COUNT(*) FROM Employees) AS Pct_Total_Workforce FROM Employees E GROUP BY E.Country;
Insert data into the 'immunization_coverage' table
CREATE TABLE immunization_coverage (id INT PRIMARY KEY,country VARCHAR(50),coverage FLOAT);
INSERT INTO immunization_coverage (id, country, coverage) VALUES (1, 'Nepal', 85.0);
How many electric vehicles were sold per month in the 'sales' table?
CREATE TABLE sales (id INT,sale_date DATE,vehicle_type VARCHAR(20));
SELECT DATE_TRUNC('month', sale_date) AS month, COUNT(*) FILTER (WHERE vehicle_type = 'Electric') AS electric_sales FROM sales GROUP BY month;
What is the total donation amount for the 'effective_altruism' category in the year 2020?
CREATE TABLE donations (category TEXT,donation_date DATE,donation_amount FLOAT); INSERT INTO donations (category,donation_date,donation_amount) VALUES ('effective_altruism','2020-01-01',2000.00),('impact_investing','2019-12-31',3000.00);
SELECT SUM(donation_amount) FROM donations WHERE category = 'effective_altruism' AND YEAR(donation_date) = 2020;
What is the total number of user comments related to articles about immigration, having more than 10 words?
CREATE TABLE articles (article_id INT,title TEXT,topic TEXT); INSERT INTO articles (article_id,title,topic) VALUES (1,'Immigration Reform in the US','immigration'),(2,'European Immigration Trends','immigration'); CREATE TABLE user_comments (comment_id INT,article_id INT,user_id INT,comment TEXT,word_count INT); INSERT...
SELECT SUM(word_count) FROM user_comments JOIN articles ON user_comments.article_id = articles.article_id WHERE articles.topic = 'immigration' AND word_count > 10;
What is the total number of unique users who have streamed music in each country?
CREATE TABLE country_streams (stream_id INT,country VARCHAR(255),user_id INT); CREATE TABLE user (user_id INT,user_name VARCHAR(255));
SELECT country, COUNT(DISTINCT user_id) FROM country_streams GROUP BY country;
List countries with peacekeeping operations exceeding 500 soldiers in 2019
CREATE TABLE peacekeeping_operations (id INT,country VARCHAR(50),year INT,soldiers INT);
SELECT country FROM peacekeeping_operations WHERE year = 2019 AND soldiers > 500 GROUP BY country HAVING COUNT(*) > 1;
What is the total number of articles published by 'CNN' in the 'world' category?
CREATE TABLE cnn (article_id INT,title VARCHAR(255),publish_date DATE,author VARCHAR(255),category VARCHAR(255)); INSERT INTO cnn (article_id,title,publish_date,author,category) VALUES (1,'Article 13','2022-01-13','Author 13','world'); CREATE TABLE world (article_id INT,title VARCHAR(255),publish_date DATE,author VARCH...
SELECT COUNT(*) FROM cnn WHERE category = 'world';
Identify Algorithmic Fairness team members and their respective roles.
CREATE TABLE AlgorithmicFairnessTeam (TeamMemberID INT PRIMARY KEY,Name VARCHAR(30),Role VARCHAR(30)); INSERT INTO AlgorithmicFairnessTeam (TeamMemberID,Name,Role) VALUES (1,'Alice','Data Scientist'),(2,'Bob','Team Lead');
SELECT Name, Role FROM AlgorithmicFairnessTeam;
What is the average size of habitats (in square kilometers) for each continent?
CREATE TABLE habitat (id INT,location TEXT,size FLOAT);
SELECT h.location, AVG(size) FROM habitat h GROUP BY h.location;
How many customers have opened new accounts in the last month in the Asia-Pacific region?
CREATE TABLE branches (branch_id INT,branch_country VARCHAR(50)); INSERT INTO branches (branch_id,branch_country) VALUES (1,'USA'),(2,'Canada'),(3,'Australia'),(4,'Japan'); CREATE TABLE customers (customer_id INT,branch_id INT,account_opening_date DATE); INSERT INTO customers (customer_id,branch_id,account_opening_date...
SELECT COUNT(*) FROM customers WHERE account_opening_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 1 MONTH) AND CURDATE() AND branch_id IN (SELECT branch_id FROM branches WHERE branch_country LIKE 'Asia%');
What is the total number of military vehicles produced by domestic manufacturers in 2020?
CREATE TABLE manufacturers (id INT,name TEXT,location TEXT); INSERT INTO manufacturers (id,name,location) VALUES (1,'Manufacturer1','USA'),(2,'Manufacturer2','USA'); CREATE TABLE military_vehicles (id INT,model TEXT,manufacturer_id INT,year INT,quantity INT); INSERT INTO military_vehicles (id,model,manufacturer_id,year...
SELECT SUM(quantity) FROM military_vehicles JOIN manufacturers ON military_vehicles.manufacturer_id = manufacturers.id WHERE manufacturers.location = 'USA' AND military_vehicles.year = 2020;
What is the minimum duration of a single workout session for each member?
CREATE TABLE members (member_id INT,name VARCHAR(50),gender VARCHAR(10),dob DATE); INSERT INTO members (member_id,name,gender,dob) VALUES (1,'Carlos Gomez','Male','2002-01-18'); INSERT INTO members (member_id,name,gender,dob) VALUES (2,'Dana Peterson','Female','2001-09-09'); CREATE TABLE workout_sessions (session_id IN...
SELECT member_id, MIN(duration) AS min_duration FROM workout_sessions GROUP BY member_id;
Insert a new record in the 'design_standards' table with id 5, name 'Seismic Resistant Design', description 'New standards for seismic resistance', and standard_date '2022-03-15'
CREATE TABLE design_standards (id INT,name VARCHAR(50),description TEXT,standard_date DATE);
INSERT INTO design_standards (id, name, description, standard_date) VALUES (5, 'Seismic Resistant Design', 'New standards for seismic resistance', '2022-03-15');
What is the total revenue generated by games with a user rating of 4 or higher?
CREATE TABLE GameRatings (RatingID INT,GameID INT,UserRating INT); INSERT INTO GameRatings (RatingID,GameID,UserRating) VALUES (1,1,5); INSERT INTO GameRatings (RatingID,GameID,UserRating) VALUES (2,2,4);
SELECT SUM(gs.Revenue) FROM GameSales gs JOIN Games g ON gs.GameID = g.GameID JOIN GameRatings gr ON g.GameID = gr.GameID WHERE gr.UserRating >= 4;
What is the number of players who played a game in the last 30 days in the 'player_activity_data' schema?
CREATE TABLE player_activity_data (player_id INT,last_played_date DATE); INSERT INTO player_activity_data VALUES (1,'2023-03-01'),(2,'2023-02-25'),(3,'2023-03-15'),(4,'2023-01-28'),(5,'2023-02-03'),(6,'2023-03-08');
SELECT COUNT(*) AS num_players FROM player_activity_data WHERE last_played_date >= CURDATE() - INTERVAL 30 DAY;
What is the average sale price of military equipment by type for defense contractor XYZ?
CREATE TABLE EquipmentTypes (equipment_type VARCHAR(50),manufacturer VARCHAR(50),sale_price DECIMAL(10,2)); INSERT INTO EquipmentTypes (equipment_type,manufacturer,sale_price) VALUES ('Tank','XYZ',5000000.00); INSERT INTO EquipmentTypes (equipment_type,manufacturer,sale_price) VALUES ('Fighter Jet','XYZ',80000000.00);
SELECT equipment_type, AVG(sale_price) as avg_sale_price FROM EquipmentTypes WHERE manufacturer = 'XYZ' GROUP BY equipment_type;
What is the total value of military equipment sales to Oceania?
CREATE TABLE equipment_sales (id INT,equipment_name VARCHAR,quantity INT,country VARCHAR,sale_price DECIMAL(10,2));
SELECT SUM(quantity * sale_price) FROM equipment_sales WHERE country = 'Oceania';
How many cases were lost by attorneys who identify as female and are from the 'California' region?
CREATE TABLE Attorneys (attorney_id INT,name TEXT,gender TEXT,region TEXT); INSERT INTO Attorneys (attorney_id,name,gender,region) VALUES (1,'John Doe','Male','New York'),(2,'Jane Smith','Female','California'),(3,'Mike Johnson','Male','California'); CREATE TABLE Cases (case_id INT,attorney_id INT,won BOOLEAN); INSERT I...
SELECT COUNT(Cases.case_id) FROM Cases INNER JOIN Attorneys ON Cases.attorney_id = Attorneys.attorney_id WHERE Attorneys.gender = 'Female' AND Attorneys.region = 'California' AND Cases.won = FALSE;
How many cases were handled by attorneys in the 'Jones' firm?
CREATE TABLE attorneys (attorney_id INT,attorney_name VARCHAR(50),firm VARCHAR(50)); INSERT INTO attorneys (attorney_id,attorney_name,firm) VALUES (1,'Jane Jones','Jones'),(2,'Robert Smith','Smith'); CREATE TABLE cases (case_id INT,attorney_id INT); INSERT INTO cases (case_id,attorney_id) VALUES (1,1),(2,1),(3,2);
SELECT COUNT(*) FROM cases INNER JOIN attorneys ON cases.attorney_id = attorneys.attorney_id WHERE attorneys.firm = 'Jones';
What is the life expectancy in each country in Africa?
CREATE TABLE life_expectancy (id INT,country VARCHAR(20),year INT,life_expectancy FLOAT); INSERT INTO life_expectancy (id,country,year,life_expectancy) VALUES (1,'Kenya',2018,65.0),(2,'Kenya',2019,65.5),(3,'Nigeria',2019,59.0);
SELECT country, life_expectancy FROM life_expectancy WHERE year = (SELECT MAX(year) FROM life_expectancy) GROUP BY country;
Identify the earliest appointment date for each healthcare provider at each clinic location, in the "rural_clinics" table with appointment data.
CREATE TABLE rural_clinics (clinic_location VARCHAR(255),healthcare_provider_name VARCHAR(255),appointment_date DATE); INSERT INTO rural_clinics (clinic_location,healthcare_provider_name,appointment_date) VALUES ('Location1','Provider1','2022-01-01'),('Location1','Provider1','2022-01-05'),('Location2','Provider2','2022...
SELECT clinic_location, healthcare_provider_name, MIN(appointment_date) OVER (PARTITION BY clinic_location, healthcare_provider_name) AS earliest_appointment_date FROM rural_clinics;
What is the average risk assessment score for initiatives in the 'clean water' category?
CREATE TABLE initiatives (id INT,category VARCHAR(50),risk_assessment FLOAT); INSERT INTO initiatives (id,category,risk_assessment) VALUES (1,'clean water',65.0),(2,'gender equality',72.5),(3,'clean water',70.0),(4,'affordable housing',75.2);
SELECT AVG(risk_assessment) FROM initiatives WHERE category = 'clean water';
Calculate the percentage of each incident type out of the total incidents for the 'Healthcare' industry in the last quarter.
CREATE TABLE security_incidents (id INT,timestamp TIMESTAMP,industry VARCHAR(255),country VARCHAR(255),incident_type VARCHAR(255)); INSERT INTO security_incidents (id,timestamp,industry,country,incident_type) VALUES (1,'2022-04-01 10:00:00','Healthcare','USA','malware'),(2,'2022-04-02 15:00:00','Healthcare','Canada','p...
SELECT incident_type, ROUND(COUNT(*) * 100.0 / (SELECT COUNT(*) FROM security_incidents WHERE industry = 'Healthcare' AND timestamp >= DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 3 MONTH)) , 2) as percentage FROM security_incidents WHERE industry = 'Healthcare' AND timestamp >= DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL 3 MONTH...
What is the total data usage for subscribers in 'urban' areas, excluding those who have had a billing issue in the past year?
CREATE TABLE Subscribers (SubscriberID int,DataUsage int,Area varchar(10),BillingIssue bit); INSERT INTO Subscribers (SubscriberID,DataUsage,Area,BillingIssue) VALUES (1,20000,'rural',0),(2,30000,'urban',1),(3,15000,'rural',1),(4,25000,'urban',0),(5,35000,'urban',0);
SELECT DataUsage FROM Subscribers WHERE Area = 'urban' AND BillingIssue = 0
What is the production count for well 'I09' in 'Brazilian Atlantic'?
CREATE TABLE wells (well_id VARCHAR(10),well_location VARCHAR(20)); INSERT INTO wells (well_id,well_location) VALUES ('I09','Brazilian Atlantic'); CREATE TABLE production (well_id VARCHAR(10),production_count INT); INSERT INTO production (well_id,production_count) VALUES ('I09',13000);
SELECT production_count FROM production WHERE well_id = 'I09';
What is the average number of visitors to national parks in Australia per month?
CREATE TABLE national_parks (park_id INT,location TEXT,visitors INT,date DATE); INSERT INTO national_parks (park_id,location,visitors,date) VALUES (1,'Uluru-Kata Tjuta National Park',2000,'2021-10-01'),(2,'Great Barrier Reef Marine Park',3000,'2021-11-01');
SELECT AVG(visitors) FROM national_parks WHERE location = 'Australia' GROUP BY date_format(date, '%Y-%m');
Update the name of the founder of Startup X to 'Founder Y' in the diversity metrics table
CREATE TABLE diversity_metrics(id INT,company_name VARCHAR(50),founder_name VARCHAR(50),gender VARCHAR(10),age INT); INSERT INTO diversity_metrics VALUES (1,'Startup X','Founder A','Male',40); INSERT INTO diversity_metrics VALUES (2,'Startup Y','Founder B','Female',35); INSERT INTO diversity_metrics VALUES (3,'Startup ...
UPDATE diversity_metrics SET founder_name = 'Founder Y' WHERE company_name = 'Startup X';
What are the names of the rural health departments, ordered by the total patient count, and including the total salary expenditure for each department?
CREATE TABLE departments (name VARCHAR(255),patient_count INT,total_salary NUMERIC(10,2)); INSERT INTO departments (name,patient_count,total_salary) VALUES (1,100,300000),(2,150,400000);
SELECT name, patient_count, total_salary FROM departments ORDER BY patient_count DESC;
What is the average monthly data usage for each postpaid mobile subscriber by region, sorted by the highest average usage?
CREATE TABLE subscribers (subscriber_id INT,subscription_type VARCHAR(10),data_usage FLOAT,region VARCHAR(20)); INSERT INTO subscribers (subscriber_id,subscription_type,data_usage,region) VALUES (1,'postpaid',3.5,'North'),(2,'postpaid',4.2,'South'),(3,'postpaid',3.8,'North');
SELECT region, AVG(data_usage) as avg_data_usage FROM subscribers WHERE subscription_type = 'postpaid' GROUP BY region ORDER BY avg_data_usage DESC;