instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
What is the total number of players who play games in each genre?
|
CREATE TABLE Players (PlayerID INT,GamePreference VARCHAR(20)); INSERT INTO Players (PlayerID,GamePreference) VALUES (1,'Shooter'),(2,'RPG'),(3,'Strategy'),(4,'Shooter'),(5,'RPG'); CREATE TABLE GameDesign (GameID INT,GameName VARCHAR(20),Genre VARCHAR(20)); INSERT INTO GameDesign (GameID,GameName,Genre) VALUES (1,'GameA','Shooter'),(2,'GameB','RPG'),(3,'GameC','Strategy');
|
SELECT GameDesign.Genre, COUNT(Players.PlayerID) as Count FROM GameDesign INNER JOIN Players ON Players.GamePreference = GameDesign.Genre GROUP BY GameDesign.Genre;
|
Calculate the percentage of financially capable customers in each region.
|
CREATE TABLE customers (customer_id INT,region VARCHAR(50),financially_capable BOOLEAN);
|
SELECT region, AVG(CAST(financially_capable AS FLOAT)) * 100 AS pct_financially_capable FROM customers GROUP BY region;
|
What is the average quantity of each dish sold per day in all branches?
|
CREATE TABLE Branches (branch_id INT,branch_name VARCHAR(255));CREATE TABLE Menu (dish_name VARCHAR(255),branch_id INT);CREATE TABLE Sales (sale_date DATE,dish_name VARCHAR(255),quantity INT);
|
SELECT Menu.dish_name, AVG(quantity) as avg_quantity FROM Sales JOIN Menu ON Sales.dish_name = Menu.dish_name GROUP BY Menu.dish_name;
|
What is the total number of renewable energy projects in the state of Texas?
|
CREATE TABLE renewable_energy_projects (project_id INT,project_name VARCHAR(255),city VARCHAR(255),state VARCHAR(255),project_type VARCHAR(255)); INSERT INTO renewable_energy_projects (project_id,project_name,city,state,project_type) VALUES (1,'Texas Wind Farm','Austin','TX','Wind'); INSERT INTO renewable_energy_projects (project_id,project_name,city,state,project_type) VALUES (2,'Lone Star Solar','Houston','TX','Solar');
|
SELECT COUNT(*) FROM renewable_energy_projects WHERE state = 'TX';
|
What is the total waste quantity generated and the total number of circular economy initiatives, for each location and material, for the year 2023?
|
CREATE TABLE WasteGeneration (Date date,Location text,Material text,Quantity integer);CREATE TABLE CircularEconomyInitiatives (Location text,Initiative text,StartDate date);
|
SELECT wg.Location, wg.Material, SUM(wg.Quantity) as TotalWasteQuantity, COUNT(DISTINCT cei.Initiative) as NumberOfInitiatives FROM WasteGeneration wg LEFT JOIN CircularEconomyInitiatives cei ON wg.Location = cei.Location WHERE wg.Date >= '2023-01-01' AND wg.Date < '2024-01-01' GROUP BY wg.Location, wg.Material;
|
What is the regulatory status of XRP in the United States?
|
CREATE TABLE regulatory_frameworks (digital_asset VARCHAR(10),country VARCHAR(20),regulatory_status VARCHAR(30)); INSERT INTO regulatory_frameworks (digital_asset,country,regulatory_status) VALUES ('XRP','United States','Under Review');
|
SELECT regulatory_status FROM regulatory_frameworks WHERE digital_asset = 'XRP' AND country = 'United States';
|
Delete consumer awareness data for a specific region.
|
CREATE TABLE consumer_awareness (region_id INT PRIMARY KEY,awareness_score INT,year INT);
|
DELETE FROM consumer_awareness WHERE region_id = 456 AND year = 2021;
|
Identify the top 3 most visited exhibitions in the digital museum
|
CREATE TABLE DigitalExhibitions (exhibition_id INT,exhibition_name VARCHAR(50),visitors INT); INSERT INTO DigitalExhibitions (exhibition_id,exhibition_name,visitors) VALUES (1,'Nature',25000),(2,'Art',30000),(3,'History',20000),(4,'Science',35000);
|
SELECT exhibition_name, visitors FROM DigitalExhibitions ORDER BY visitors DESC LIMIT 3;
|
What is the average credit card limit for customers in the Mumbai branch?
|
CREATE TABLE accounts (customer_id INT,account_type VARCHAR(20),branch VARCHAR(20),balance DECIMAL(10,2),credit_limit DECIMAL(10,2)); INSERT INTO accounts (customer_id,account_type,branch,balance,credit_limit) VALUES (1,'Savings','New York',5000.00,1000.00),(2,'Checking','New York',7000.00,2000.00),(3,'Checking','Mumbai',8000.00,5000.00),(4,'Savings','Mumbai',4000.00,3000.00),(5,'Credit Card','Mumbai',0.00,10000.00);
|
SELECT AVG(credit_limit) FROM accounts WHERE account_type = 'Credit Card' AND branch = 'Mumbai';
|
List all marine mammals that are endangered and their IUCN status.
|
CREATE TABLE marine_mammals (id INT,name TEXT,iucn_status TEXT); INSERT INTO marine_mammals (id,name,iucn_status) VALUES (1,'Blue Whale','Endangered'),(2,'Dolphin','Least Concern'),(3,'Manatee','Vulnerable');
|
SELECT name, iucn_status FROM marine_mammals WHERE iucn_status = 'Endangered';
|
What is the military spending by country and year?
|
CREATE TABLE military_spending (id INT,country VARCHAR(255),amount FLOAT,year INT); INSERT INTO military_spending (id,country,amount,year) VALUES (1,'Brazil',25.6,2018); INSERT INTO military_spending (id,country,amount,year) VALUES (2,'South Africa',30.8,2019);
|
SELECT country, year, SUM(amount) as total_spending FROM military_spending GROUP BY country, year;
|
How many farmers in Kenya are certified as organic before 2018?
|
CREATE TABLE Farmers (id INT PRIMARY KEY,name VARCHAR(50),age INT,location VARCHAR(50),is_organic BOOLEAN); INSERT INTO Farmers (id,name,age,location,is_organic) VALUES (1,'James Mwangi',35,'Kenya',true); INSERT INTO Farmers (id,name,age,location,is_organic) VALUES (2,'Grace Wambui',40,'Tanzania',false); CREATE TABLE Organic_Certification (id INT PRIMARY KEY,farmer_id INT,certification_date DATE); INSERT INTO Organic_Certification (id,farmer_id,certification_date) VALUES (1,1,'2017-05-15'); INSERT INTO Organic_Certification (id,farmer_id,certification_date) VALUES (2,2,'2019-08-20');
|
SELECT COUNT(*) FROM Farmers JOIN Organic_Certification ON Farmers.id = Organic_Certification.farmer_id WHERE Farmers.location = 'Kenya' AND certification_date < '2018-01-01' AND is_organic = true;
|
How many vessels were there in each country in 2021?
|
CREATE TABLE vessels_2021 (id INT,vessel_id INT,name VARCHAR(50),country VARCHAR(50),registration_date DATE); INSERT INTO vessels_2021 VALUES (1,1,'Vessel1','Japan','2021-01-01'),(2,2,'Vessel2','Japan','2021-02-15'),(3,3,'Vessel3','China','2021-04-01');
|
SELECT country, COUNT(DISTINCT vessel_id) AS num_vessels FROM vessels_2021 WHERE YEAR(registration_date) = 2021 GROUP BY country;
|
What is the total duration of yoga sessions for users over 40?
|
CREATE TABLE workout_sessions (id INT,user_id INT,session_type VARCHAR(20),session_duration INT,session_date DATE); INSERT INTO workout_sessions (id,user_id,session_type,session_duration,session_date) VALUES (1,20,'Yoga',60,'2022-09-01'),(2,25,'Pilates',45,'2022-08-15'),(3,42,'Yoga',90,'2022-09-10');
|
SELECT SUM(session_duration) FROM workout_sessions WHERE session_type = 'Yoga' AND user_id >= 40;
|
What is the average sustainable score for products manufactured in 'Europe' in the month of 'January'?
|
CREATE TABLE SustainableFashion (ProductID INT,SustainableScore INT,ManufacturingDate DATE); INSERT INTO SustainableFashion (ProductID,SustainableScore,ManufacturingDate) VALUES (1,80,'2021-01-01'),(2,85,'2021-02-01'),(3,90,'2021-03-01'),(4,70,'2021-04-01'),(5,95,'2021-05-01'),(6,82,'2021-01-15'),(7,88,'2021-01-30');
|
SELECT AVG(SustainableScore) FROM SustainableFashion WHERE ManufacturingDate BETWEEN '2021-01-01' AND '2021-01-31';
|
Find the total number of news stories published per week in 2022
|
CREATE TABLE news_stories (id INT,published_date DATE); INSERT INTO news_stories (id,published_date) VALUES (1,'2022-01-01'),(2,'2022-01-02'),(3,'2022-01-09'),(4,'2022-01-16')
|
SELECT WEEKOFYEAR(published_date) AS week, COUNT(*) AS total FROM news_stories WHERE YEAR(published_date) = 2022 GROUP BY week;
|
What is the percentage of peacekeeping operation costs covered by each military branch in each year, ordered by year and branch?
|
CREATE TABLE peacekeeping_operation_costs (id INT,year INT,military_branch VARCHAR(255),cost DECIMAL(10,2)); INSERT INTO peacekeeping_operation_costs (id,year,military_branch,cost) VALUES (1,2015,'Army',50000),(2,2016,'Navy',60000),(3,2017,'Air Force',40000),(4,2018,'Marines',70000),(5,2019,'Coast Guard',55000),(6,2015,'National Guard',45000),(7,2016,'Army',30000),(8,2017,'Navy',25000),(9,2018,'Air Force',35000),(10,2019,'Marines',40000);
|
SELECT year, military_branch, ROUND(100.0 * cost / SUM(cost) OVER (PARTITION BY year), 2) AS percentage FROM peacekeeping_operation_costs ORDER BY year, military_branch;
|
Update the capacity of all 'Bulk Carrier' ships in the 'Indian' region to 150000.
|
CREATE TABLE new_ship_capacities (id INT PRIMARY KEY,ship_type_id INT,region_id INT,capacity INT,FOREIGN KEY (ship_type_id) REFERENCES ship_types(id),FOREIGN KEY (region_id) REFERENCES regions(id));
|
UPDATE ship_capacities sc JOIN new_ship_capacities nsc ON sc.ship_type_id = nsc.ship_type_id AND sc.region_id = nsc.region_id SET sc.capacity = 150000 WHERE nsc.ship_type_id = (SELECT id FROM ship_types WHERE name = 'Bulk Carrier') AND nsc.region_id = (SELECT id FROM regions WHERE name = 'Indian');
|
What is the total claim amount for each policyholder living in New York?
|
CREATE TABLE Policyholders (ID INT,ClaimAmount DECIMAL(10,2),State VARCHAR(50)); INSERT INTO Policyholders (ID,ClaimAmount,State) VALUES (1,1500.00,'New York'),(2,500.00,'Texas'),(3,1000.00,'California'),(4,2000.00,'New York');
|
SELECT State, SUM(ClaimAmount) FROM Policyholders WHERE State = 'New York' GROUP BY State;
|
What is the total revenue for each menu category in the African continent?
|
CREATE TABLE menus (menu_id INT,category VARCHAR(255)); INSERT INTO menus VALUES (1,'Appetizers'); INSERT INTO menus VALUES (2,'Entrees'); INSERT INTO menus VALUES (3,'Desserts'); CREATE TABLE sales (sale_id INT,menu_id INT,quantity INT,country VARCHAR(255),price DECIMAL(10,2),region VARCHAR(255));
|
SELECT m.category, SUM(s.price * s.quantity) as total_revenue FROM menus m INNER JOIN sales s ON m.menu_id = s.menu_id WHERE s.region = 'African continent' GROUP BY m.category;
|
Create a table named "sustainable_practices" with columns "practice_id", "practice_name", "description" of types integer, text, text respectively
|
CREATE TABLE sustainable_practices (practice_id integer,practice_name text,description text);
|
CREATE TABLE sustainable_practices (practice_id integer, practice_name text, description text);
|
What is the total size of co-owned properties in each city?
|
CREATE TABLE co_ownership (id INT,city VARCHAR(20),size FLOAT); INSERT INTO co_ownership (id,city,size) VALUES (1,'Seattle',1200.5),(2,'Portland',1100.75),(3,'Seattle',1300.25),(4,'NYC',800.5);
|
SELECT city, SUM(size) as total_size FROM co_ownership GROUP BY city;
|
What is the maximum number of home runs hit in a single game in the baseball_matches table?
|
CREATE TABLE baseball_matches (match_id INT,player_name VARCHAR(100),home_runs INT);
|
SELECT MAX(home_runs) FROM baseball_matches WHERE location = 'home';
|
Show the total number of security incidents for each department in the 'incidents' and 'departments' tables
|
CREATE TABLE incidents (incident_id INT PRIMARY KEY,incident_title VARCHAR(255),department_id INT); CREATE TABLE departments (department_id INT PRIMARY KEY,department_name VARCHAR(255)); INSERT INTO incidents (incident_id,incident_title,department_id) VALUES (1,'Phishing Attack',104),(2,'Malware Infection',105),(3,'Unauthorized Access',106); INSERT INTO departments (department_id,department_name) VALUES (104,'Sales'),(105,'Marketing'),(106,'Legal');
|
SELECT d.department_name, COUNT(i.incident_id) as total_incidents FROM incidents i INNER JOIN departments d ON i.department_id = d.department_id GROUP BY d.department_name;
|
Determine the average claim amount for policyholders in each underwriting group.
|
CREATE TABLE underwriting (id INT,group VARCHAR(10),name VARCHAR(20),claim_amount DECIMAL(10,2)); INSERT INTO underwriting (id,group,name,claim_amount) VALUES (1,'High Risk','John Doe',5000.00),(2,'Medium Risk','Sophia Gonzalez',6000.00),(3,'Medium Risk','Javier Rodriguez',7000.00),(4,'Low Risk','Emma White',3000.00);
|
SELECT group, AVG(claim_amount) FROM underwriting GROUP BY group;
|
Insert new faculty members into the faculty table.
|
CREATE TABLE faculty (id INT PRIMARY KEY,name VARCHAR(50),department VARCHAR(50),years_of_service INT);
|
INSERT INTO faculty (id, name, department, years_of_service) VALUES (6, 'Dr. Maria Rodriguez', 'Mathematics', 12), (7, 'Dr. Ali Al-Khateeb', 'Computer Science', 15), (8, 'Dr. Fatima Ahmed', 'Physics', 18);
|
Count the number of employees who identify as LGBTQ+ in the Marketing department.
|
CREATE TABLE Employees (EmployeeID INT,Gender VARCHAR(20),Department VARCHAR(20)); INSERT INTO Employees (EmployeeID,Gender,Department) VALUES (1,'Male','IT'),(2,'Female','IT'),(3,'Non-binary','HR'),(4,'Gay','Marketing'),(5,'Lesbian','Marketing');
|
SELECT COUNT(*) FROM Employees WHERE Department = 'Marketing' AND Gender IN ('Lesbian', 'Gay', ' Bisexual', 'Transgender', 'Queer', 'Questioning');
|
What is the total revenue generated from online sales in Q1 2022?
|
CREATE TABLE sales (sale_id INT,sale_date DATE,sale_channel VARCHAR(20),sale_revenue FLOAT); INSERT INTO sales (sale_id,sale_date,sale_channel,sale_revenue) VALUES (1,'2022-01-01','online',100.0),(2,'2022-01-02','retail',50.0),(3,'2022-01-03','online',120.0);
|
SELECT SUM(sale_revenue) FROM sales WHERE sale_channel = 'online' AND sale_date BETWEEN '2022-01-01' AND '2022-03-31';
|
What is the average age of athletes who have participated in the NBA finals?
|
CREATE TABLE athletes (id INT,name VARCHAR(50),age INT,sport VARCHAR(50)); INSERT INTO athletes (id,name,age,sport) VALUES (1,'John Doe',25,'Basketball'); INSERT INTO athletes (id,name,age,sport) VALUES (2,'Jane Smith',30,'Basketball');
|
SELECT AVG(age) FROM athletes WHERE sport = 'Basketball' AND id IN (SELECT athlete_id FROM nba_finals);
|
What is the average labor productivity (measured in metric tons of ore extracted per employee) in the mining sector, for each country, for the year 2020?
|
CREATE TABLE mining_sector (country VARCHAR(50),year INT,tons_extracted INT,employees INT); INSERT INTO mining_sector (country,year,tons_extracted,employees) VALUES ('Canada',2020,1200000,8000),('Australia',2020,1500000,10000),('Chile',2020,1000000,7000);
|
SELECT country, AVG(tons_extracted/employees) as avg_labor_productivity FROM mining_sector WHERE year = 2020 GROUP BY country;
|
What is the average price of luxury electric vehicles in the luxuryelectricvehicles schema?
|
CREATE TABLE LuxuryElectricVehicles (id INT,make VARCHAR(50),model VARCHAR(50),price DECIMAL(10,2));
|
SELECT AVG(price) FROM luxuryelectricvehicles.LuxuryElectricVehicles;
|
What is the average number of volunteer hours per volunteer for each organization?
|
CREATE TABLE Organizations (OrgID INT,OrgName TEXT); CREATE TABLE Volunteers (VolID INT,OrgID INT,VolunteerHours INT); INSERT INTO Organizations (OrgID,OrgName) VALUES (1,'Habitat for Humanity'),(2,'American Red Cross'); INSERT INTO Volunteers (VolID,OrgID,VolunteerHours) VALUES (1,1,100),(2,1,200),(3,2,300),(4,2,400),(5,1,150),(6,2,250);
|
SELECT OrgName, AVG(VolunteerHours) FROM Organizations JOIN Volunteers ON Organizations.OrgID = Volunteers.OrgID GROUP BY OrgName;
|
Which departments have received grants for 'Artificial Intelligence'?
|
CREATE TABLE departments (id INT,name TEXT,budget INT); INSERT INTO departments (id,name,budget) VALUES (1,'Computer Science',1000000),(2,'Mathematics',750000); CREATE TABLE research_grants (id INT,department_id INT,title TEXT,funding_amount INT); INSERT INTO research_grants (id,department_id,title,funding_amount) VALUES (1,1,'Artificial Intelligence',200000),(2,1,'Data Science',150000),(3,2,'Algebraic Geometry',125000);
|
SELECT d.name FROM departments d INNER JOIN research_grants rg ON d.id = rg.department_id WHERE rg.title LIKE '%Artificial Intelligence%';
|
What is the total number of legal technology patents per district?
|
CREATE TABLE District (id INT,name VARCHAR(255)); INSERT INTO District (id,name) VALUES (1,'North'),(2,'South'),(3,'East'),(4,'West'); CREATE TABLE LegalTechnologyPatents (id INT,district_id INT,patents INT); INSERT INTO LegalTechnologyPatents (id,district_id,patents) VALUES (1,1,150),(2,1,200),(3,2,100),(4,2,120),(5,3,300),(6,3,350),(7,4,400),(8,4,450);
|
SELECT d.name, SUM(ltp.patents) as total_patents FROM District d JOIN LegalTechnologyPatents ltp ON d.id = ltp.district_id GROUP BY d.id;
|
Insert records into 'fan_demographics' table for fans of 'Sports Team D'
|
CREATE TABLE fan_demographics (fan_id INT,age INT,gender VARCHAR(10),favorite_team VARCHAR(20));
|
INSERT INTO fan_demographics (fan_id, age, gender, favorite_team) VALUES (10, 25, 'Female', 'Sports Team D'), (11, 35, 'Male', 'Sports Team D'), (12, 42, 'Non-binary', 'Sports Team D');
|
Which devices were discovered on a specific date in the 'NetworkDevices' table?
|
CREATE TABLE NetworkDevices (id INT,device_name VARCHAR(50),severity VARCHAR(10),discovered_date DATE); INSERT INTO NetworkDevices (id,device_name,severity,discovered_date) VALUES (1,'Router1','High','2021-08-01'),(2,'Switch1','Medium','2021-07-15'),(3,'Firewall1','Low','2021-06-01'),(4,'Router2','High','2021-09-01'),(5,'Switch2','Low','2021-07-15');
|
SELECT device_name FROM NetworkDevices WHERE discovered_date = '2021-08-01';
|
What was the total budget for 'Healthcare' sector in the year 2020, excluding records with a budget less than $100,000?
|
CREATE TABLE Budget (Sector VARCHAR(50),BudgetAmount NUMERIC(15,2),BudgetYear INT); INSERT INTO Budget (Sector,BudgetAmount,BudgetYear) VALUES ('Healthcare',1500000,2020),('Healthcare',200000,2020),('Healthcare',750000,2020);
|
SELECT SUM(BudgetAmount) FROM Budget WHERE Sector = 'Healthcare' AND BudgetYear = 2020 AND BudgetAmount >= 100000;
|
Which cultivation facility has the highest total production cost?
|
CREATE TABLE CultivationFacility (FacilityID INT,FacilityName VARCHAR(255),TotalProductionCost DECIMAL(10,2)); INSERT INTO CultivationFacility (FacilityID,FacilityName,TotalProductionCost) VALUES (1,'Facility X',50000.00),(2,'Facility Y',55000.00),(3,'Facility Z',45000.00);
|
SELECT FacilityName, TotalProductionCost FROM CultivationFacility ORDER BY TotalProductionCost DESC LIMIT 1;
|
What is the total water consumption in the Water_Usage table for the year 2020?
|
CREATE TABLE Water_Usage (id INT,year INT,water_consumption FLOAT); INSERT INTO Water_Usage (id,year,water_consumption) VALUES (1,2018,12000.0),(2,2019,13000.0),(3,2020,14000.0),(4,2021,15000.0);
|
SELECT SUM(water_consumption) FROM Water_Usage WHERE year = 2020;
|
What was the average price of products sold in each month?
|
CREATE TABLE sales (sale_id int,product_id int,quantity int,date date); INSERT INTO sales (sale_id,product_id,quantity,date) VALUES (1,1,10,'2021-01-01'),(2,2,15,'2021-01-02'),(3,1,12,'2021-01-03'),(4,3,20,'2021-01-04'),(5,4,18,'2021-02-05'),(6,1,8,'2021-02-06'),(7,2,10,'2021-02-07'); CREATE TABLE products (product_id int,product_name varchar(255),category varchar(255),price decimal(10,2),quantity int); INSERT INTO products (product_id,product_name,category,price,quantity) VALUES (1,'Product A','Category X',150.00,200),(2,'Product B','Category Y',250.00,150),(3,'Product C','Category X',100.00,300),(4,'Product D','Category Y',200.00,250);
|
SELECT DATE_FORMAT(s.date, '%Y-%m') as month, AVG(p.price) as avg_price FROM sales s JOIN products p ON s.product_id = p.product_id GROUP BY month;
|
What is the average revenue per stream for the R&B genre in the United States over the past year?
|
CREATE TABLE streams (stream_id INT,track_id INT,genre VARCHAR(50),country VARCHAR(50),timestamp TIMESTAMP,revenue FLOAT); INSERT INTO streams (stream_id,track_id,genre,country,timestamp,revenue) VALUES (1,1001,'R&B','United States','2022-02-01 00:00:00',0.15),(2,1002,'R&B','United States','2022-02-02 12:30:00',0.2);
|
SELECT AVG(revenue) FROM streams WHERE genre = 'R&B' AND country = 'United States' AND timestamp >= '2021-01-01' AND timestamp < '2022-01-01';
|
Which platform had the highest oil production increase between Q3 and Q4 2021?
|
CREATE TABLE platform (platform_id INT,platform_name TEXT,oil_production_q3_2021 FLOAT,oil_production_q4_2021 FLOAT); INSERT INTO platform (platform_id,platform_name,oil_production_q3_2021,oil_production_q4_2021) VALUES (1,'A',1000,1200),(2,'B',1600,1800),(3,'C',2200,2500);
|
SELECT platform_name, (oil_production_q4_2021 - oil_production_q3_2021) as oil_production_increase FROM platform ORDER BY oil_production_increase DESC;
|
What is the total amount donated per month?
|
CREATE TABLE Donations (DonationID INT,DonorID INT,DonationAmount DECIMAL(10,2),DonationDate DATE);
|
SELECT EXTRACT(MONTH FROM D.DonationDate) AS Month, SUM(D.DonationAmount) FROM Donations D GROUP BY Month;
|
What is the total number of collective bargaining agreements signed by each union in a specific year?
|
CREATE TABLE Unions (UnionID INT,UnionName TEXT); CREATE TABLE Agreements (AgreementID INT,UnionID INT,AgreementDate DATE);
|
SELECT u.UnionName, YEAR(a.AgreementDate) AS AgreementYear, COUNT(a.AgreementID) AS TotalAgreementsPerYear FROM Unions u INNER JOIN Agreements a ON u.UnionID = a.UnionID GROUP BY u.UnionName, AgreementYear;
|
What is the trend of defense project timelines in the African continent over the last 3 years?
|
CREATE TABLE Project_Timelines (project_id INT,project_start_date DATE,project_end_date DATE,project_region VARCHAR(50));
|
SELECT project_region, DATEPART(year, project_start_date) as project_year, AVG(DATEDIFF(day, project_start_date, project_end_date)) as avg_project_duration FROM Project_Timelines WHERE project_region = 'African continent' AND project_start_date >= DATEADD(year, -3, GETDATE()) GROUP BY project_region, project_year;
|
Identify the top three most vulnerable systems based on the number of recorded vulnerabilities?
|
CREATE TABLE vulnerabilities (id INT,system VARCHAR(20),vulnerability_type VARCHAR(20),timestamp TIMESTAMP); INSERT INTO vulnerabilities (id,system,vulnerability_type,timestamp) VALUES (1,'Firewall','Configuration issue','2022-01-01 10:00:00'),(2,'Router','Unpatched software','2022-01-02 11:00:00');
|
SELECT system, COUNT(*) as num_vulnerabilities FROM vulnerabilities GROUP BY system ORDER BY num_vulnerabilities DESC LIMIT 3;
|
What is the distribution of mobile plans by customer location?
|
CREATE TABLE mobile_plans (plan_id INT,plan_type VARCHAR(50),location VARCHAR(50)); INSERT INTO mobile_plans (plan_id,plan_type,location) VALUES (1,'postpaid','Chicago'); INSERT INTO mobile_plans (plan_id,plan_type,location) VALUES (2,'prepaid','Chicago'); INSERT INTO mobile_plans (plan_id,plan_type,location) VALUES (3,'postpaid','New York');
|
SELECT plan_type, location, COUNT(*) FROM mobile_plans GROUP BY plan_type, location;
|
What is the total budget allocated to education and healthcare in 2022?
|
CREATE TABLE Budget (Year INT,Department VARCHAR(20),Amount INT); INSERT INTO Budget VALUES (2022,'Education',1500000),(2022,'Healthcare',1200000);
|
SELECT SUM(Amount) FROM Budget WHERE Year = 2022 AND Department IN ('Education', 'Healthcare');
|
What is the total number of unique vulnerabilities in the financial sector?
|
CREATE TABLE vulnerabilities (id INT,sector VARCHAR(20),vulnerability VARCHAR(50),frequency INT);
|
SELECT COUNT(DISTINCT vulnerability) FROM vulnerabilities WHERE sector = 'financial';
|
Show the top 3 regions with the highest mobile and broadband subscriber count for each technology.
|
CREATE TABLE subscriber_regions (subscriber_id INT,technology VARCHAR(20),region VARCHAR(20)); INSERT INTO subscriber_regions (subscriber_id,technology,region) VALUES (1,'4G','North'),(2,'5G','South'),(3,'3G','East'),(4,'Fiber','North'),(5,'Cable','South'),(6,'DSL','East');
|
SELECT technology, region, COUNT(*) as total FROM subscriber_regions GROUP BY technology, region ORDER BY technology, total DESC;
|
What is the total cargo handled by vessel 'Atlantic Crusader'?
|
CREATE TABLE cargo_details (id INT,vessel_name VARCHAR(50),cargo_type VARCHAR(50),quantity INT); INSERT INTO cargo_details (id,vessel_name,cargo_type,quantity) VALUES (1,'Atlantic Crusader','Container',7000),(2,'Atlantic Crusader','Bulk',8000);
|
SELECT SUM(quantity) FROM cargo_details WHERE vessel_name = 'Atlantic Crusader';
|
What is the number of students enrolled in open pedagogy courses per province in Canada?
|
CREATE TABLE courses (course_id INT,province VARCHAR(50),enrolled_students INT); INSERT INTO courses (course_id,province,enrolled_students) VALUES (1,'Ontario',50),(2,'Quebec',30),(3,'British Columbia',20);
|
SELECT c.province, COUNT(c.course_id) as num_courses FROM courses c GROUP BY c.province;
|
What is the water volume of the Indian Ocean compared to the Atlantic Ocean?
|
CREATE TABLE Ocean_Volumes (ocean TEXT,volume_cubic_km FLOAT); INSERT INTO Ocean_Volumes (ocean,volume_cubic_km) VALUES ('Indian Ocean',292140000),('Atlantic Ocean',329610000);
|
SELECT (SELECT volume_cubic_km FROM Ocean_Volumes WHERE ocean = 'Indian Ocean') / (SELECT volume_cubic_km FROM Ocean_Volumes WHERE ocean = 'Atlantic Ocean') AS ratio;
|
What is the number of work-related injuries reported per month by type?
|
CREATE TABLE work_injuries (injury_date DATE,mine_id INT,injury_type TEXT); INSERT INTO work_injuries (injury_date,mine_id,injury_type) VALUES ('2021-01-15',1,'Fracture'),('2021-02-03',1,'Burn'),('2021-03-12',2,'Electrocution'),('2021-04-20',3,'Fracture'),('2021-05-05',1,'Burn'),('2021-06-18',2,'Electrocution'),('2021-07-02',3,'Fracture'),('2021-08-16',1,'Burn'),('2021-09-01',2,'Electrocution'),('2021-10-14',3,'Fracture'),('2021-11-29',1,'Burn'),('2021-12-15',2,'Electrocution'),('2021-01-05',4,'Fracture');
|
SELECT EXTRACT(MONTH FROM injury_date) AS month, injury_type, COUNT(*) AS injuries_count FROM work_injuries GROUP BY month, injury_type ORDER BY month, injury_type;
|
Find the difference in total production of Europium between 2019 and 2020 for countries that produced more Europium in 2020 than in 2019.
|
CREATE TABLE Country (Code TEXT,Name TEXT,Continent TEXT); INSERT INTO Country (Code,Name,Continent) VALUES ('CN','China','Asia'),('AU','Australia','Australia'),('KR','South Korea','Asia'),('IN','India','Asia'); CREATE TABLE ProductionYearly (Year INT,Country TEXT,Element TEXT,Quantity INT); INSERT INTO ProductionYearly (Year,Country,Element,Quantity) VALUES (2019,'CN','Europium',1000),(2019,'AU','Europium',800),(2019,'KR','Europium',700),(2020,'CN','Europium',1100),(2020,'AU','Europium',850),(2020,'KR','Europium',750);
|
SELECT a.Country, b.Quantity - a.Quantity AS Difference FROM ProductionYearly a JOIN ProductionYearly b ON a.Country = b.Country WHERE a.Element = 'Europium' AND b.Element = 'Europium' AND a.Year = 2019 AND b.Year = 2020 AND b.Quantity > a.Quantity AND a.Country IN (SELECT Name FROM Country WHERE Continent = 'Asia');
|
What is the maximum number of views for a report on a site from Period5, and the type of report with that view count?
|
CREATE TABLE Sites (id INT,site_name VARCHAR(50),location VARCHAR(50),period VARCHAR(50),type VARCHAR(50)); INSERT INTO Sites (id,site_name,location,period,type) VALUES (1,'Site1','Location1','Period1','Settlement'),(2,'Site2','Location2','Period5','Village'); CREATE TABLE Reports (id INT,site_name VARCHAR(50),date DATE,type VARCHAR(50),views INT); INSERT INTO Reports (id,site_name,date,type,views) VALUES (1,'Site1','2021-01-01','Excavation',1000),(2,'Site2','2021-02-01','Survey',800);
|
SELECT r.type, r.views FROM Reports r JOIN Sites s ON r.site_name = s.site_name WHERE s.period = 'Period5' AND r.views = (SELECT MAX(views) FROM Reports WHERE site_name IN (SELECT site_name FROM Sites WHERE period = 'Period5'));
|
Insert new records into the 'industry_4_0' table with the following data: (1, 'Automated Production Line', '2022-05-01')
|
CREATE TABLE industry_4_0 (id INT PRIMARY KEY,initiative_name VARCHAR(100),implementation_date DATE);
|
INSERT INTO industry_4_0 (id, initiative_name, implementation_date) VALUES (1, 'Automated Production Line', '2022-05-01');
|
What is the total production quantity for wells in the 'gulf' region?
|
CREATE TABLE gulf_wells (well_name TEXT,region TEXT,production_quantity INT); INSERT INTO gulf_wells (well_name,region,production_quantity) VALUES ('Well A','gulf',4000),('Well B','gulf',5000),('Well C','gulf',6000);
|
SELECT SUM(production_quantity) FROM gulf_wells WHERE region = 'gulf';
|
Which organizations have received donations greater than $100?
|
CREATE TABLE Organization (OrgID INT,Name VARCHAR(255)); CREATE TABLE Donation (DonID INT,OrgID INT,Amount DECIMAL(10,2)); INSERT INTO Organization VALUES (1,'Greenpeace'),(2,'Red Cross'),(3,'Wildlife Fund'); INSERT INTO Donation VALUES (1,1,50.00),(2,1,150.00),(3,2,75.00),(4,3,120.00);
|
SELECT OrgID, Name FROM Organization o WHERE EXISTS (SELECT * FROM Donation d WHERE d.OrgID = o.OrgID AND d.Amount > 100);
|
Display the total number of subscribers in each country, excluding subscribers with a 'test' account type
|
CREATE TABLE subscriber_data (subscriber_id INT,subscriber_type VARCHAR(20),country VARCHAR(20)); INSERT INTO subscriber_data (subscriber_id,subscriber_type,country) VALUES (1,'Regular','USA'),(2,'Test','Canada'),(3,'Regular','Mexico');
|
SELECT country, COUNT(*) as total_subscribers FROM subscriber_data WHERE subscriber_type != 'Test' GROUP BY country;
|
Find artists who have performed in both New York and Los Angeles.
|
CREATE TABLE Artists (artist_id INT,artist_name VARCHAR(50),city VARCHAR(50)); INSERT INTO Artists (artist_id,artist_name,city) VALUES (1,'John Doe','New York'),(2,'Jane Smith','Los Angeles'),(3,'John Doe','Los Angeles');
|
SELECT artist_name FROM Artists WHERE city IN ('New York', 'Los Angeles') GROUP BY artist_name HAVING COUNT(DISTINCT city) = 2;
|
Delete the record for the veteran with the SSN 123-45-6789 from the employees table.
|
CREATE TABLE employees (ssn VARCHAR(11),first_name VARCHAR(20),last_name VARCHAR(20),job_title VARCHAR(30));
|
DELETE FROM employees WHERE ssn = '123-45-6789';
|
Which companies own the most number of drilling rigs located in the Gulf of Mexico region?
|
CREATE TABLE gulf_of_mexico_drilling_rigs (id INT,name VARCHAR(50),operator VARCHAR(50),location VARCHAR(50)); INSERT INTO gulf_of_mexico_drilling_rigs VALUES (1,'Rig A','Company X','Gulf of Mexico'); INSERT INTO gulf_of_mexico_drilling_rigs VALUES (2,'Rig B','Company Y','Gulf of Mexico'); INSERT INTO gulf_of_mexico_drilling_rigs VALUES (3,'Rig C','Company X','Gulf of Mexico'); INSERT INTO gulf_of_mexico_drilling_rigs VALUES (4,'Rig D','Company Z','Gulf of Mexico'); INSERT INTO gulf_of_mexico_drilling_rigs VALUES (5,'Rig E','Company Y','Gulf of Mexico');
|
SELECT operator, COUNT(*) AS num_of_rigs FROM gulf_of_mexico_drilling_rigs WHERE location = 'Gulf of Mexico' GROUP BY operator ORDER BY num_of_rigs DESC;
|
Create a view named "cargo_summary" that displays the average delivery time for cargo to each destination.
|
CREATE TABLE cargo (cargo_id INT,vessel_id INT,destination VARCHAR(50),delivery_date DATE);
|
CREATE VIEW cargo_summary AS SELECT destination, AVG(DATEDIFF(delivery_date, GETDATE())) AS avg_delivery_time FROM cargo GROUP BY destination;
|
How many trips have been made to the Port of Singapore by each captain?
|
CREATE SCHEMA if not exists ocean_shipping;CREATE TABLE if not exists ocean_shipping.captains (id INT PRIMARY KEY,name VARCHAR(100));CREATE TABLE if not exists ocean_shipping.trips (id INT PRIMARY KEY,captain_id INT,port VARCHAR(100));INSERT INTO ocean_shipping.captains (id,name) VALUES (1,'Captain A'),(2,'Captain B'),(3,'Captain C');INSERT INTO ocean_shipping.trips (id,captain_id,port) VALUES (1,1,'Port of Singapore'),(2,2,'Port of Singapore'),(3,1,'Port of Oakland'),(4,3,'Port of Oakland');
|
SELECT captains.name, COUNT(trips.id) FROM ocean_shipping.captains LEFT JOIN ocean_shipping.trips ON captains.id = trips.captain_id WHERE trips.port = 'Port of Singapore' GROUP BY captains.name;
|
What is the average safety rating for electric vehicles in the 'automotive' schema?
|
CREATE TABLE electric_vehicles (id INT,name VARCHAR(50),safety_rating FLOAT); CREATE TABLE vehicles (id INT,type VARCHAR(50)); INSERT INTO electric_vehicles VALUES (1,'Tesla Model 3',5.2); INSERT INTO vehicles VALUES (1,'electric');
|
SELECT AVG(safety_rating) FROM electric_vehicles INNER JOIN vehicles ON electric_vehicles.id = vehicles.id WHERE vehicles.type = 'electric';
|
What is the total amount of climate finance committed to renewable energy projects in Africa since 2010?
|
CREATE TABLE renewable_energy_projects (project_id INT,project_name TEXT,location TEXT,funded_year INT,funding_amount FLOAT); INSERT INTO renewable_energy_projects (project_id,project_name,location,funded_year,funding_amount) VALUES (1,'Solar Farm 1','Egypt',2015,5000000.0),(2,'Wind Farm 1','Morocco',2013,7000000.0),(3,'Hydro Plant 1','South Africa',2012,9000000.0);
|
SELECT SUM(funding_amount) FROM renewable_energy_projects WHERE funded_year >= 2010 AND location LIKE 'Africa%';
|
Find the policy number, policyholder name, and claim amount for the top 5 claims in descending order by claim amount.
|
CREATE TABLE Policy (PolicyNumber INT,PolicyholderName VARCHAR(50)); CREATE TABLE Claim (ClaimID INT,PolicyNumber INT,ClaimAmount DECIMAL(10,2)); INSERT INTO Policy VALUES (1,'John Doe'),(2,'Jane Smith'); INSERT INTO Claim VALUES (1,1,5000),(2,1,3000),(3,2,7000),(4,2,8000),(5,2,9000);
|
SELECT PolicyNumber, PolicyholderName, ClaimAmount FROM (SELECT PolicyNumber, PolicyholderName, ClaimAmount, ROW_NUMBER() OVER (ORDER BY ClaimAmount DESC) as rn FROM Policy JOIN Claim ON Policy.PolicyNumber = Claim.PolicyNumber) x WHERE rn <= 5;
|
Which professional development courses did teacher Jane Smith attend in 2021?
|
CREATE TABLE teachers (teacher_id INT,teacher_name TEXT); CREATE TABLE professional_development_courses (course_id INT,course_name TEXT,year INT,teacher_id INT); INSERT INTO teachers (teacher_id,teacher_name) VALUES (1,'Jane Smith'); INSERT INTO professional_development_courses (course_id,course_name,year,teacher_id) VALUES (101,'Python for Educators',2021,1),(102,'Data Visualization',2020,1);
|
SELECT pdc.course_name FROM professional_development_courses pdc INNER JOIN teachers t ON pdc.teacher_id = t.teacher_id WHERE t.teacher_name = 'Jane Smith' AND pdc.year = 2021;
|
Delete the existing high-speed train route from Rome to Milan
|
CREATE TABLE high_speed_rail_routes (id INT PRIMARY KEY,route_name VARCHAR(255),departure_city VARCHAR(255),destination_city VARCHAR(255),distance INT,avg_speed INT);
|
DELETE FROM high_speed_rail_routes WHERE route_name = 'Rome-Milan Express';
|
What is the name of the shelter with ID '1'?
|
CREATE TABLE shelters (shelter_id INT,shelter_name VARCHAR(30),region_id INT); INSERT INTO shelters (shelter_id,shelter_name,region_id) VALUES (1,'Emergency Shelter 1',3),(2,'Temporary Home',3),(3,'Relief House',1),(4,'New Shelter Name',4),(5,'Casa de Ayuda',4);
|
SELECT shelter_name FROM shelters WHERE shelter_id = 1;
|
List all customers with a credit score above 700 who have made a purchase in the last month.
|
CREATE TABLE customers (id INT,name VARCHAR(255),credit_score INT,last_purchase_date DATE); INSERT INTO customers (id,name,credit_score,last_purchase_date) VALUES (1,'Jane Smith',750,'2022-04-15'),(2,'Bob Johnson',680,'2022-03-20');
|
SELECT * FROM customers WHERE credit_score > 700 AND last_purchase_date BETWEEN DATEADD(month, -1, GETDATE()) AND GETDATE();
|
Which climate monitoring stations are located in the same country as 'Station A'?
|
CREATE TABLE climate_monitoring_stations (id INT,station_name VARCHAR(255),country VARCHAR(255)); INSERT INTO climate_monitoring_stations (id,station_name,country) VALUES (1,'Station A','canada'),(2,'Station B','greenland'),(3,'Station C','canada'),(4,'Station D','norway');
|
SELECT station_name FROM climate_monitoring_stations WHERE country = (SELECT country FROM climate_monitoring_stations WHERE station_name = 'Station A');
|
What is the percentage of female and non-binary faculty in each department?
|
CREATE TABLE departments (id INT,name VARCHAR(255)); INSERT INTO departments (id,name) VALUES (1,'Biology'),(2,'Mathematics'),(3,'Sociology'); CREATE TABLE faculty (id INT,name VARCHAR(255),department_id INT,gender VARCHAR(10)); INSERT INTO faculty (id,name,department_id,gender) VALUES (1,'Alice',1,'Female'),(2,'Bob',2,'Male'),(3,'Charlie',3,'Non-binary'),(4,'Dave',1,'Male'),(5,'Eve',3,'Female');
|
SELECT d.name, g.gender, COUNT(f.id) * 100.0 / SUM(COUNT(f.id)) OVER (PARTITION BY d.name) FROM faculty f JOIN departments d ON f.department_id = d.id JOIN (VALUES ('Female'), ('Non-binary')) AS g(gender) ON f.gender = g.gender GROUP BY d.name, g.gender;
|
What is the total number of employees hired from South America in the year 2020, sorted by their hire date?
|
CREATE TABLE Employees (EmployeeID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Country VARCHAR(50),HireDate DATE);
|
SELECT COUNT(*) FROM Employees WHERE Country IN ('South America') AND YEAR(HireDate) = 2020 ORDER BY HireDate;
|
What is the highest-scoring NBA game in history and which teams were involved?
|
CREATE TABLE nba_scores (game_id INT,home_team VARCHAR(50),away_team VARCHAR(50),home_score INT,away_score INT); INSERT INTO nba_scores (game_id,home_team,away_team,home_score,away_score) VALUES (1,'Detroit Pistons','Denver Nuggets',186,184);
|
SELECT home_team, away_team, home_score, away_score FROM nba_scores WHERE home_score + away_score = (SELECT MAX(home_score + away_score) FROM nba_scores);
|
What is the number of vegetarian and non-vegetarian menu items in each menu category?
|
CREATE TABLE menu_categories (menu_category VARCHAR(255),vegetarian BOOLEAN); INSERT INTO menu_categories (menu_category,vegetarian) VALUES ('Appetizers',FALSE),('Entrees',FALSE),('Desserts',TRUE); CREATE TABLE menu_items_ext (item_name VARCHAR(255),menu_category VARCHAR(255),vegetarian BOOLEAN); INSERT INTO menu_items_ext (item_name,menu_category,vegetarian) VALUES ('Chicken Strips','Appetizers',FALSE),('Garden Salad','Appetizers',TRUE),('Veggie Burger','Entrees',TRUE),('Steak','Entrees',FALSE),('Ice Cream','Desserts',TRUE),('Chocolate Mousse','Desserts',FALSE);
|
SELECT menu_category, SUM(CASE WHEN vegetarian THEN 1 ELSE 0 END) AS vegetarian_items, SUM(CASE WHEN NOT vegetarian THEN 1 ELSE 0 END) AS non_vegetarian_items FROM menu_items_ext GROUP BY menu_category;
|
What is the total number of hospitals and clinics in the San Francisco Bay Area?
|
CREATE TABLE public.hospitals (id SERIAL PRIMARY KEY,name TEXT,location TEXT,num_beds INTEGER); INSERT INTO public.hospitals (name,location,num_beds) VALUES ('General Hospital','San Francisco',500),('Children''s Hospital','Oakland',300); CREATE TABLE public.clinics (id SERIAL PRIMARY KEY,name TEXT,location TEXT); INSERT INTO public.clinics (name,location) VALUES ('Community Clinic','San Francisco'),('Wellness Clinic','Berkeley');
|
SELECT COUNT(*) FROM public.hospitals UNION ALL SELECT COUNT(*) FROM public.clinics;
|
Identify the top 5 cities globally with the highest number of renewable energy projects in the past year.
|
CREATE TABLE renewable_projects (id INT,project_name VARCHAR(255),city VARCHAR(255),start_date DATE);
|
SELECT city, COUNT(*) AS project_count FROM renewable_projects WHERE start_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY city ORDER BY project_count DESC LIMIT 5;
|
How many biosensor technologies are there in the UK?
|
CREATE SCHEMA if not exists biosensors;CREATE TABLE if not exists biosensors.technologies(id INT,name TEXT,location TEXT,funding DECIMAL(10,2),type TEXT);INSERT INTO biosensors.technologies (id,name,location,funding,type) VALUES (1,'BioSensorA','Germany',1200000.00,'Optical'),(2,'BioSensorB','UK',1500000.00,'Electrochemical'),(3,'BioSensorC','USA',900000.00,'Optical');
|
SELECT COUNT(*) FROM biosensors.technologies WHERE location = 'UK';
|
What is the average number of intelligence operations conducted by the Russian government per year?
|
CREATE TABLE intel_operations (id INT,country VARCHAR(255),year INT,operations_count INT); INSERT INTO intel_operations (id,country,year,operations_count) VALUES (1,'Russia',2017,500),(2,'Russia',2018,600),(3,'Russia',2019,700),(4,'Russia',2020,800);
|
SELECT AVG(operations_count) FROM intel_operations WHERE country = 'Russia';
|
What was the average community development score for Middle Eastern countries in Q4 2021?
|
CREATE TABLE CommunityDevelopment (id INT,country VARCHAR(20),quarter INT,score FLOAT); INSERT INTO CommunityDevelopment (id,country,quarter,score) VALUES (1,'Iran',4,85.5),(2,'Saudi Arabia',3,82.3),(3,'Turkey',2,78.7),(4,'United Arab Emirates',1,88.2),(5,'Israel',4,90.1);
|
SELECT AVG(score) FROM CommunityDevelopment WHERE country IN ('Iran', 'Saudi Arabia', 'Turkey', 'United Arab Emirates', 'Israel') AND quarter = 4;
|
Which artifacts were found at 'Gournay-sur-Aronde'? Provide their IDs, types, and dates.
|
CREATE TABLE Artifacts (ArtifactID INT,SiteID INT,ArtifactType TEXT,Date DATE); INSERT INTO Artifacts (ArtifactID,SiteID,ArtifactType,Date) VALUES (1,3,'Pottery','1950-01-01'),(2,3,'Bronze Sword','1950-01-02'),(3,1,'Glassware','1900-01-01');
|
SELECT ArtifactID, ArtifactType, Date FROM Artifacts WHERE SiteID = (SELECT SiteID FROM ExcavationSites WHERE SiteName = 'Gournay-sur-Aronde');
|
Determine the average carbon offsetting (in metric tons) of green building projects in the 'Greater Toronto Area'
|
CREATE TABLE green_buildings (id INT,name VARCHAR(100),location VARCHAR(50),carbon_offset FLOAT); INSERT INTO green_buildings (id,name,location,carbon_offset) VALUES (1,'Green Building A','Greater Toronto Area',500.3); INSERT INTO green_buildings (id,name,location,carbon_offset) VALUES (2,'Green Building B','New York',400.2);
|
SELECT AVG(carbon_offset) FROM green_buildings WHERE location = 'Greater Toronto Area';
|
What is the maximum landfill capacity in tons for landfills in Mexico City?
|
CREATE TABLE landfills_mexico(location VARCHAR(50),capacity INT); INSERT INTO landfills_mexico(location,capacity) VALUES ('Mexico City',120000),('Mexico City',150000),('Mexico City',100000),('Guadalajara',130000),('Guadalajara',140000),('Guadalajara',110000);
|
SELECT MAX(capacity) FROM landfills_mexico WHERE location = 'Mexico City';
|
Update the sustainability_rating of hotel with hotel_id 1 to 5.
|
CREATE TABLE hotels (hotel_id INT,name VARCHAR(50),location VARCHAR(50),stars INT,sustainability_rating INT);
|
UPDATE hotels SET sustainability_rating = 5 WHERE hotel_id = 1;
|
Insert a record of a new Reggae music stream in Jamaica on April 10, 2021 with revenue of 1.50.
|
CREATE TABLE streams (song_id INT,stream_date DATE,genre VARCHAR(20),country VARCHAR(20),revenue DECIMAL(10,2));
|
INSERT INTO streams (song_id, stream_date, genre, country, revenue) VALUES (15, '2021-04-10', 'Reggae', 'Jamaica', 1.50);
|
What is the total funding for biotech startups in the 'east_coast' region?
|
CREATE TABLE biotech_startups (id INT,name TEXT,region TEXT,budget FLOAT); INSERT INTO biotech_startups (id,name,region,budget) VALUES (1,'StartupA','East Coast',5000000),(2,'StartupB','West Coast',7000000),(3,'StartupC','East Coast',3000000);
|
SELECT SUM(budget) FROM biotech_startups WHERE region = 'East Coast';
|
What are the top 3 countries with the most pollution incidents in the 'PollutionIncidents' table?
|
CREATE TABLE PollutionIncidents (IncidentID INT,Country VARCHAR(50),PollutionLevel INT); INSERT INTO PollutionIncidents (IncidentID,Country,PollutionLevel) VALUES (1,'US',5),(2,'Canada',7),(3,'Mexico',6),(4,'Brazil',8),(5,'Argentina',4);
|
SELECT Country, PollutionLevel FROM PollutionIncidents ORDER BY PollutionLevel DESC LIMIT 3;
|
List all countries and the number of AI safety conferences held there.
|
CREATE TABLE countries (id INT,name TEXT); INSERT INTO countries (id,name) VALUES (1,'USA'),(2,'Canada'),(3,'UK'),(4,'Australia'); CREATE TABLE conferences (id INT,country_id INT,name TEXT,topic TEXT); INSERT INTO conferences (id,country_id,name,topic) VALUES (1,1,'Conf1','AI Safety'),(2,1,'Conf2','AI Safety'),(3,3,'Conf3','AI Safety'),(4,4,'Conf4','AI Safety');
|
SELECT countries.name, COUNT(conferences.id) as conferences_count FROM countries LEFT JOIN conferences ON countries.id = conferences.country_id AND conferences.topic = 'AI Safety' GROUP BY countries.name;
|
What is the total playtime for each player?
|
CREATE TABLE PlayerSessions (SessionID int,PlayerID int,GameID int,Playtime int); INSERT INTO PlayerSessions (SessionID,PlayerID,GameID,Playtime) VALUES (1,1,1,60),(2,1,1,90),(3,2,1,75),(4,2,2,120),(5,3,2,100),(6,3,3,80);
|
SELECT P.PlayerName, SUM(PS.Playtime) as TotalPlaytime FROM Players P JOIN PlayerSessions PS ON P.PlayerID = PS.PlayerID GROUP BY P.PlayerName;
|
What is the number of unique materials used in the production of products in each country?
|
CREATE TABLE products (product_id INT,country VARCHAR(50),raw_material VARCHAR(50)); CREATE VIEW country_products AS SELECT country,raw_material FROM products GROUP BY country;
|
SELECT country, COUNT(DISTINCT raw_material) FROM country_products GROUP BY country;
|
What is the average funding per language preservation program by region?
|
CREATE TABLE LanguagePreservation (id INT,program VARCHAR(255),region VARCHAR(255),funding FLOAT); INSERT INTO LanguagePreservation (id,program,region,funding) VALUES (1,'Language Immersion','North America',30000),(2,'Bilingual Education','Europe',25000),(3,'Community Workshops','Asia',22000);
|
SELECT region, AVG(funding) FROM LanguagePreservation GROUP BY region;
|
What is the distribution of AI creativity research topics by continent?
|
CREATE TABLE topics (id INT,title TEXT,continent TEXT);
|
SELECT continent, COUNT(*) as num_topics, ROUND(100.0 * COUNT(*) / (SELECT COUNT(*) FROM topics) , 1) as percentage FROM topics GROUP BY continent ORDER BY percentage DESC;
|
Delete expeditions led by the 'Marine Discovery Institute' with a depth greater than 4500 meters.
|
CREATE TABLE Expeditions (ExpeditionID INT,Society VARCHAR(25),Depth INT); INSERT INTO Expeditions (ExpeditionID,Society,Depth) VALUES (1,'Undersea Exploration Society',3000),(2,'Oceanic Research Foundation',4000),(3,'Marine Discovery Institute',5000);
|
DELETE FROM Expeditions WHERE Society = 'Marine Discovery Institute' AND Depth > 4500;
|
What is the total revenue for each product category in the past week, sorted by revenue in descending order?
|
CREATE TABLE sales (id INT PRIMARY KEY,product_id INT,date DATE,revenue FLOAT,FOREIGN KEY (product_id) REFERENCES products(id)); INSERT INTO sales (id,product_id,date,revenue) VALUES (3,3,'2022-05-05',500.00); CREATE TABLE products (id INT PRIMARY KEY,name VARCHAR(255),category VARCHAR(255)); INSERT INTO products (id,name,category) VALUES (4,'Eco Denim Jacket','Clothing');
|
SELECT p.category, SUM(s.revenue) AS total_revenue FROM sales s JOIN products p ON s.product_id = p.id WHERE s.date BETWEEN DATE_SUB(CURDATE(), INTERVAL 1 WEEK) AND CURDATE() GROUP BY p.category ORDER BY total_revenue DESC;
|
Count the number of defense contracts awarded in the last 6 months.
|
CREATE TABLE Contracts (id INT,contract_number VARCHAR(50),contract_date DATE,contract_value FLOAT,contract_type VARCHAR(50));
|
SELECT COUNT(*) FROM Contracts WHERE contract_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH) AND contract_type = 'Defense';
|
Find the annual growth rate in box office collections for Bollywood movies since 2010.
|
CREATE TABLE box_office (movie_id INT,title VARCHAR(100),release_year INT,collection INT,production_company VARCHAR(50)); INSERT INTO box_office (movie_id,title,release_year,collection,production_company) VALUES (1,'PK',2014,800000000,'UTV Motion Pictures'),(2,'Dangal',2016,1000000000,'Walt Disney Pictures');
|
SELECT production_company, AVG(collection) as avg_annual_collection, (EXP(AVG(LOG(collection + 1))) - 1) * 100.0 AS annual_growth_rate FROM box_office WHERE production_company LIKE '%Bollywood%' GROUP BY production_company;
|
Which companies have received funding since 2020 and their respective industry?
|
CREATE TABLE Company (id INT,name TEXT,industry TEXT,founding_date DATE); INSERT INTO Company (id,name,industry,founding_date) VALUES (1,'Acme Inc','Tech','2016-01-02'); INSERT INTO Company (id,name,industry,founding_date) VALUES (2,'Wright Startups','Transport','2015-05-15'); INSERT INTO Company (id,name,industry,founding_date) VALUES (3,'Bella Innovations','FashionTech','2018-09-09'); CREATE TABLE Funding (id INT,company_id INT,amount INT,funding_date DATE); INSERT INTO Funding (id,company_id,amount,funding_date) VALUES (1,1,5000000,'2021-03-20'); INSERT INTO Funding (id,company_id,amount,funding_date) VALUES (2,2,7000000,'2020-08-05'); INSERT INTO Funding (id,company_id,amount,funding_date) VALUES (3,3,9000000,'2019-01-10');
|
SELECT Company.name, Company.industry, Funding.funding_date FROM Company INNER JOIN Funding ON Company.id = Funding.company_id WHERE Funding.funding_date > '2019-01-01';
|
List all public transportation routes in the city of Philadelphia and their respective budgets for 2024, ordered by budget amount in descending order.
|
CREATE TABLE routes (city varchar(50),year int,route varchar(50),budget int); INSERT INTO routes (city,year,route,budget) VALUES ('Philadelphia',2024,'Route 1',5000000),('Philadelphia',2024,'Route 2',4000000),('Philadelphia',2024,'Route 3',3000000),('Philadelphia',2024,'Route 4',2000000);
|
SELECT route, budget FROM routes WHERE city = 'Philadelphia' AND year = 2024 ORDER BY budget DESC;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.