instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
Find the names of geothermal_plants with capacity greater than 50 MW.
|
CREATE TABLE geothermal_plants (id INT,name VARCHAR(255),capacity INT); INSERT INTO geothermal_plants (id,name,capacity) VALUES (1,'Sample Geothermal Plant',60);
|
SELECT name FROM geothermal_plants WHERE capacity > 50;
|
Which brands offer the most vegan-friendly products?
|
CREATE TABLE brands (brand_id INT PRIMARY KEY,brand_name VARCHAR(50)); CREATE TABLE products (product_id INT,brand_id INT,PRIMARY KEY (product_id,brand_id),FOREIGN KEY (brand_id) REFERENCES brands(brand_id)); CREATE TABLE vegan_products (product_id INT,brand_id INT,PRIMARY KEY (product_id,brand_id),FOREIGN KEY (product_id) REFERENCES products(product_id),FOREIGN KEY (brand_id) REFERENCES brands(brand_id)); INSERT INTO brands (brand_id,brand_name) VALUES (1,'Kat Von D'),(2,'LUSH'),(3,'The Body Shop'); INSERT INTO products (product_id,brand_id) VALUES (1,1),(2,1),(3,2),(4,2),(5,3),(6,3); INSERT INTO vegan_products (product_id,brand_id) VALUES (1,1),(2,1),(3,2),(5,3);
|
SELECT brand_name, COUNT(*) as product_count FROM vegan_products JOIN brands ON vegan_products.brand_id = brands.brand_id GROUP BY brand_id ORDER BY product_count DESC;
|
What is the total number of posts in a given language for a given time period?
|
CREATE TABLE posts (id INT,language VARCHAR(255),timestamp TIMESTAMP); INSERT INTO posts (id,language,timestamp) VALUES (1,'English','2022-01-01 10:00:00'),(2,'Spanish','2022-01-02 12:00:00'),(3,'French','2022-01-03 14:00:00'),(4,'English','2022-01-01 10:00:00'),(5,'Spanish','2022-01-02 12:00:00');
|
SELECT language, COUNT(*) FROM posts WHERE language IN ('English', 'Spanish') AND timestamp BETWEEN '2022-01-01' AND '2022-01-05' GROUP BY language;
|
What are the production figures for wells in the North Sea?
|
CREATE TABLE wells (well_id INT,name VARCHAR(50),location VARCHAR(50),production FLOAT); INSERT INTO wells (well_id,name,location,production) VALUES (1,'A1','North Sea',10000);
|
SELECT production FROM wells WHERE location = 'North Sea';
|
Which ingredients are used in both lipstick and foundation products?
|
CREATE TABLE ingredients (ingredient_id INT PRIMARY KEY,ingredient_name VARCHAR(50)); CREATE TABLE lipsticks (product_id INT,ingredient_id INT,FOREIGN KEY (ingredient_id) REFERENCES ingredients(ingredient_id)); INSERT INTO lipsticks (product_id,ingredient_id) VALUES (1,1),(1,2),(2,2),(2,3); CREATE TABLE foundation (product_id INT,ingredient_id INT,FOREIGN KEY (ingredient_id) REFERENCES ingredients(ingredient_id)); INSERT INTO foundation (product_id,ingredient_id) VALUES (1,2),(1,3),(2,3),(2,4);
|
SELECT ingredient_name FROM ingredients WHERE ingredient_id IN (SELECT ingredient_id FROM lipsticks INTERSECT SELECT ingredient_id FROM foundation);
|
What is the percentage of tourists who visited Africa in 2021 and took a guided safari tour?
|
CREATE TABLE africa_tourists (visited_africa BOOLEAN,took_safari BOOLEAN); INSERT INTO africa_tourists (visited_africa,took_safari) VALUES (TRUE,TRUE),(TRUE,FALSE),(FALSE,FALSE),(TRUE,TRUE),(FALSE,TRUE),(TRUE,FALSE);
|
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM africa_tourists WHERE visited_africa = TRUE)) AS percentage FROM africa_tourists WHERE visited_africa = TRUE AND took_safari = TRUE;
|
What is the minimum number of streams for Folk music in July?
|
CREATE TABLE Streams (id INT,genre VARCHAR(20),date DATE,streams INT); INSERT INTO Streams (id,genre,date,streams) VALUES (1,'Folk','2022-07-01',100),(2,'Pop','2022-06-15',150),(3,'Folk','2022-07-10',200);
|
SELECT MIN(streams) FROM Streams WHERE genre = 'Folk' AND date BETWEEN '2022-07-01' AND '2022-07-31';
|
Identify the top 3 countries with the highest carbon sequestration values in temperate forests for the last 5 years.
|
CREATE TABLE forest_carbon (id INT,country VARCHAR(30),region VARCHAR(20),year INT,carbon_value FLOAT);
|
SELECT country, SUM(carbon_value) as total_carbon_value FROM forest_carbon WHERE region = 'Temperate' GROUP BY country ORDER BY total_carbon_value DESC LIMIT 3;
|
What is the total number of climate finance investments in Oceania for climate adaptation projects between 2015 and 2017?
|
CREATE TABLE climate_finance_adaptation (country VARCHAR(50),year INT,project_type VARCHAR(50),amount FLOAT); INSERT INTO climate_finance_adaptation (country,year,project_type,amount) VALUES ('Australia',2015,'Climate Adaptation',5000000),('New Zealand',2016,'Climate Adaptation',6000000),('Papua New Guinea',2017,'Climate Adaptation',7000000);
|
SELECT SUM(amount) FROM climate_finance_adaptation WHERE country IN ('Australia', 'New Zealand', 'Papua New Guinea') AND project_type = 'Climate Adaptation' AND year BETWEEN 2015 AND 2017;
|
Find the average depth of the ocean floor in the 'atlantic_ocean'.
|
CREATE TABLE ocean_floor_depth (location VARCHAR(255),depth INTEGER);
|
SELECT AVG(depth) FROM ocean_floor_depth WHERE location = 'Atlantic Ocean';
|
What is the average age of employees in the company?
|
CREATE TABLE Employees (id INT,name VARCHAR(50),age INT); INSERT INTO Employees (id,name,age) VALUES (1,'John Doe',35),(2,'Jane Smith',30);
|
SELECT AVG(age) FROM Employees;
|
Delete all climate communication projects with a negative ROI.
|
CREATE TABLE climate_communication (project VARCHAR(50),country VARCHAR(50),roi FLOAT,date DATE); INSERT INTO climate_communication (project,country,roi,date) VALUES ('Climate News','UK',1.2,'2020-01-01'); INSERT INTO climate_communication (project,country,roi,date) VALUES ('Climate Talks','Germany',-0.5,'2020-01-01');
|
DELETE FROM climate_communication WHERE roi < 0;
|
What is the total capacity of renewable energy projects in each country, in MW?
|
CREATE TABLE renewable_projects (id INT,project_name VARCHAR(100),capacity FLOAT,country VARCHAR(50)); INSERT INTO renewable_projects (id,project_name,capacity,country) VALUES (1,'Renewable Project 1',100.2,'Germany'),(2,'Renewable Project 2',150.3,'Sweden');
|
SELECT country, SUM(capacity) FROM renewable_projects GROUP BY country;
|
Update population of 'Polar Bear' in animals table by 20%
|
CREATE TABLE animals (id INT PRIMARY KEY,species VARCHAR(50),population INT,region VARCHAR(50)); INSERT INTO animals (id,species,population,region) VALUES (1,'Polar Bear',3000,'Arctic');
|
WITH cte AS (UPDATE animals SET population = population * 1.2 WHERE species = 'Polar Bear') SELECT * FROM animals;
|
What is the earliest and latest production date for each product category?
|
CREATE TABLE production (product_id INT,category VARCHAR(255),production_date DATE); INSERT INTO production (product_id,category,production_date) VALUES (1,'CategoryA','2021-01-01'),(2,'CategoryB','2021-03-15'),(3,'CategoryA','2021-07-01');
|
SELECT category, MIN(production_date) AS earliest_production_date, MAX(production_date) AS latest_production_date FROM production GROUP BY category;
|
List all unique mining locations and their environmental impact scores.
|
CREATE TABLE MiningLocation (id INT,name VARCHAR(255)); INSERT INTO MiningLocation (id,name) VALUES (1,'Mountain X'),(2,'Hill Y'); CREATE TABLE EnvironmentalImpact (location_id INT,score INT); INSERT INTO EnvironmentalImpact (location_id,score) VALUES (1,70),(2,80);
|
SELECT DISTINCT l.name, e.score FROM MiningLocation l, EnvironmentalImpact e WHERE l.id = e.location_id;
|
Update the budget for 'Education Equality' program to 30000
|
CREATE TABLE Programs (ProgramID INT,Program TEXT,Budget DECIMAL); INSERT INTO Programs (ProgramID,Program,Budget) VALUES (1,'Education Equality',25000);
|
UPDATE Programs SET Budget = 30000 WHERE Program = 'Education Equality';
|
Create a table named 'suppliers' with columns for company name, location, ethical_certification, and last_audit_date
|
CREATE TABLE suppliers (id INT PRIMARY KEY,company_name VARCHAR(255),location VARCHAR(255),ethical_certification VARCHAR(255),last_audit_date DATE);
|
CREATE TABLE suppliers (id INT PRIMARY KEY, company_name VARCHAR(255), location VARCHAR(255), ethical_certification VARCHAR(255), last_audit_date DATE);
|
Calculate the difference in safety ratings between hybrid and electric vehicles in the 'safety_test' table, for each region.
|
CREATE TABLE safety_test (vehicle_type VARCHAR(10),safety_rating INT,sale_region VARCHAR(10));
|
SELECT sale_region, AVG(safety_rating) FILTER (WHERE vehicle_type = 'Electric') - AVG(safety_rating) FILTER (WHERE vehicle_type = 'Hybrid') AS safety_diff FROM safety_test GROUP BY sale_region;
|
What is the maximum installed capacity of hydroelectric power plants in each of the top 3 countries with the most hydroelectric power plants?
|
CREATE TABLE hydroelectric_power_plants (id INT,name VARCHAR(100),country VARCHAR(50),capacity FLOAT,completion_date DATE); INSERT INTO hydroelectric_power_plants (id,name,country,capacity,completion_date) VALUES (1,'Hydroelectric Power Plant A','China',2000,'2010-01-01'); INSERT INTO hydroelectric_power_plants (id,name,country,capacity,completion_date) VALUES (2,'Hydroelectric Power Plant B','Brazil',2500,'2011-01-01');
|
SELECT country, MAX(capacity) AS max_capacity FROM hydroelectric_power_plants GROUP BY country ORDER BY max_capacity DESC LIMIT 3;
|
What is the average fare of public trams in Melbourne?
|
CREATE TABLE public_trams(id INT,tram_number INT,city VARCHAR(20),fare FLOAT);
|
SELECT AVG(fare) FROM public_trams WHERE city = 'Melbourne';
|
How many products in each category are made from recycled materials?
|
CREATE TABLE products (product_id INT,category VARCHAR(50),recycled BOOLEAN); INSERT INTO products (product_id,category,recycled) VALUES (101,'Electronics',TRUE),(102,'Clothing',FALSE),(103,'Furniture',TRUE),(104,'Clothing',TRUE),(105,'Electronics',FALSE);
|
SELECT category, COUNT(*) AS product_count FROM products WHERE recycled = TRUE GROUP BY category;
|
What are the names and descriptions of all vulnerabilities found in the financial sector?
|
CREATE TABLE vulnerabilities (sector VARCHAR(20),name VARCHAR(50),description TEXT); INSERT INTO vulnerabilities (sector,name,description) VALUES ('Financial','Heartbleed','...');
|
SELECT name, description FROM vulnerabilities WHERE sector = 'Financial';
|
What is the number of employees in the 'textile_recycling' sector in 'India'?
|
CREATE TABLE manufacturing_countries (country VARCHAR(50),manufacturing_sector VARCHAR(50),total_emissions INT); INSERT INTO manufacturing_countries (country,manufacturing_sector,total_emissions) VALUES ('India','textile_recycling',35000);
|
SELECT total_employees FROM manufacturing_countries WHERE country = 'India' AND manufacturing_sector = 'textile_recycling';
|
Calculate the number of traditional arts events in each state of the USA, ordered by the number of events in descending order.
|
CREATE TABLE Events (EventID INT,EventName TEXT,State TEXT); INSERT INTO Events (EventID,EventName,State) VALUES (1001,'Community Pottery Workshop','NY'),(1002,'Weaving Techniques Demonstration','CA'),(1003,'Traditional Dance Festival','TX');
|
SELECT State, COUNT(EventID) AS Number_Of_Events FROM Events WHERE State IN ('NY', 'CA', 'TX', 'FL', 'IL') GROUP BY State ORDER BY Number_Of_Events DESC;
|
How many algorithmic fairness projects are completed?
|
CREATE TABLE fairness_projects (id INT PRIMARY KEY,project_name VARCHAR(50),status VARCHAR(50)); INSERT INTO fairness_projects (id,project_name,status) VALUES (1,'Bias Mitigation','Completed'),(2,'Disparate Impact','In Progress'),(3,'Explainability','Completed'),(4,'Fairness Metrics','Completed'),(5,'Transparency','Completed');
|
SELECT COUNT(*) FROM fairness_projects WHERE status = 'Completed';
|
How many labor rights violations were recorded for each industry in the Southern region in 2021?
|
CREATE TABLE industries (id INT,industry VARCHAR(255),region VARCHAR(255)); INSERT INTO industries (id,industry,region) VALUES (1,'Industry A','Southern'),(2,'Industry B','Southern'),(3,'Industry C','Northern'); CREATE TABLE violations (id INT,industry_id INT,violation_count INT,violation_date DATE); INSERT INTO violations (id,industry_id,violation_count,violation_date) VALUES (1,1,20,'2021-01-01'),(2,1,30,'2021-02-01'),(3,2,10,'2021-03-01'),(4,3,50,'2020-01-01');
|
SELECT i.industry, SUM(v.violation_count) as total_violations FROM industries i JOIN violations v ON i.id = v.industry_id WHERE i.region = 'Southern' AND YEAR(v.violation_date) = 2021 GROUP BY i.industry;
|
How many times has the organic certification been revoked for suppliers in the European Union?
|
CREATE TABLE suppliers (id INT,name VARCHAR(255),country VARCHAR(255),organic_certified INT); INSERT INTO suppliers (id,name,country,organic_certified) VALUES (1,'Supplier 1','Germany',1),(2,'Supplier 2','France',0),(3,'Supplier 3','Italy',1);
|
SELECT COUNT(*) FROM suppliers WHERE organic_certified = 0 AND country LIKE 'Europe%';
|
What is the average permit duration in California for projects beginning in 2021?
|
CREATE TABLE Building_Permits (permit_id INT,permit_date DATE,permit_expiration DATE,state VARCHAR(20)); INSERT INTO Building_Permits (permit_id,permit_date,permit_expiration,state) VALUES (1,'2021-01-01','2021-04-15','California'),(2,'2021-02-01','2021-05-31','California'),(3,'2022-03-01','2022-06-15','California');
|
SELECT AVG(DATEDIFF(permit_expiration, permit_date)) FROM Building_Permits WHERE state = 'California' AND permit_date >= '2021-01-01';
|
Update the climate_finance table to reflect a new climate finance commitment of $10 million for a project in Fiji.
|
CREATE TABLE climate_finance (id INT,country VARCHAR(50),amount FLOAT);
|
UPDATE climate_finance SET amount = amount + 10000000.00 WHERE country = 'Fiji';
|
What is the percentage of transactions that were made by customers from the United States in Q1 2022?
|
CREATE TABLE customers (customer_id INT,country_code CHAR(2)); CREATE TABLE transactions (transaction_id INT,customer_id INT,transaction_amount DECIMAL(10,2),transaction_date DATE);
|
SELECT 100.0 * SUM(CASE WHEN country_code = 'US' THEN 1 ELSE 0 END) / COUNT(*) FROM transactions INNER JOIN customers ON transactions.customer_id = customers.customer_id WHERE transactions.transaction_date BETWEEN '2022-01-01' AND '2022-03-31';
|
What is the maximum distance traveled by electric vehicles in China, grouped by manufacturer?
|
CREATE TABLE ElectricVehicles (id INT,manufacturer VARCHAR(50),distance FLOAT,country VARCHAR(50)); INSERT INTO ElectricVehicles (id,manufacturer,distance,country) VALUES (1,'ManufacturerA',250.3,'China'),(2,'ManufacturerB',300.5,'China'),(3,'ManufacturerC',350.7,'China'),(4,'ManufacturerD',400.8,'China');
|
SELECT context.manufacturer, MAX(context.distance) FROM (SELECT * FROM ElectricVehicles WHERE ElectricVehicles.country = 'China') AS context GROUP BY context.manufacturer;
|
What is the average energy efficiency score for buildings in 'UrbanEfficiency' table, by city?
|
CREATE TABLE UrbanEfficiency (id INT,building_name TEXT,city TEXT,state TEXT,energy_efficiency_score INT);
|
SELECT city, AVG(energy_efficiency_score) FROM UrbanEfficiency GROUP BY city;
|
Find the average age of members who have done 'Cycling'?
|
CREATE TABLE Members (Id INT,Name VARCHAR(50),Age INT,Nationality VARCHAR(50)); INSERT INTO Members (Id,Name,Age,Nationality) VALUES (1,'John Doe',30,'UK'),(2,'Jane Smith',25,'Canada'); CREATE TABLE Workouts (Id INT,MemberId INT,WorkoutType VARCHAR(50),Duration INT,Date DATE); INSERT INTO Workouts (Id,MemberId,WorkoutType,Duration,Date) VALUES (1,1,'Cycling',30,'2022-01-01'),(2,2,'Swimming',60,'2022-01-02');
|
SELECT AVG(m.Age) as AverageAge FROM Members m JOIN Workouts w ON m.Id = w.MemberId WHERE w.WorkoutType = 'Cycling';
|
What is the maximum safety rating in the 'vessels' table?
|
CREATE TABLE vessels (id INT,name TEXT,type TEXT,safety_rating REAL); INSERT INTO vessels (id,name,type,safety_rating) VALUES (1,'Fishing Vessel 1','Fishing',8.8),(2,'Cargo Ship 1','Cargo',9.2);
|
SELECT MAX(safety_rating) FROM vessels;
|
What is the total assets value for each client as of 2022-01-01?
|
CREATE TABLE clients (client_id INT,name TEXT,assets_value FLOAT); INSERT INTO clients (client_id,name,assets_value) VALUES (1,'John Doe',150000.00),(2,'Jane Smith',220000.00);
|
SELECT name, SUM(assets_value) as total_assets_value FROM clients WHERE DATE(assets_value_date) = '2022-01-01' GROUP BY name;
|
What is the average budget of all transportation projects in the year 2020?
|
CREATE TABLE TransportationProjects (ProjectID INT,Name VARCHAR(100),Budget DECIMAL(10,2),Year INT); INSERT INTO TransportationProjects (ProjectID,Name,Budget,Year) VALUES (1,'Road Expansion',5000000,2020),(2,'Bridge Construction',8000000,2019),(3,'Traffic Light Installation',200000,2020);
|
SELECT AVG(Budget) FROM TransportationProjects WHERE Year = 2020;
|
What is the average length of songs per genre, ranked by popularity?
|
CREATE TABLE genres (genre_id INT,genre VARCHAR(255)); CREATE TABLE songs (song_id INT,song_name VARCHAR(255),genre_id INT,length FLOAT); CREATE VIEW song_length_per_genre AS SELECT genre_id,AVG(length) as avg_length FROM songs GROUP BY genre_id; CREATE VIEW genre_popularity AS SELECT genre_id,COUNT(song_id) as num_songs FROM songs GROUP BY genre_id ORDER BY num_songs DESC; CREATE VIEW final_result AS SELECT g.genre,sl.avg_length,g.num_songs,g.num_songs/SUM(g.num_songs) OVER () as popularity_ratio FROM song_length_per_genre sl JOIN genre_popularity g ON sl.genre_id = g.genre_id;
|
SELECT genre, avg_length, popularity_ratio FROM final_result;
|
Calculate the total number of policies for each insurance type where the policy limit is less than the average claim amount.
|
CREATE TABLE Policy_Limits (Policy_Type VARCHAR(20),Policy_Limit INT); INSERT INTO Policy_Limits (Policy_Type,Policy_Limit) VALUES ('Life',25000),('Health',5000),('Auto',7500),('Life',30000),('Health',6000); CREATE TABLE Claim_Amounts (Policy_Type VARCHAR(20),Claim_Amount INT); INSERT INTO Claim_Amounts (Policy_Type,Claim_Amount) VALUES ('Life',35000),('Health',7000),('Auto',10000),('Life',22000),('Health',5500);
|
SELECT Policy_Type, COUNT(*) FROM Policy_Limits INNER JOIN Claim_Amounts ON Policy_Limits.Policy_Type = Claim_Amounts.Policy_Type WHERE Policy_Limits.Policy_Limit < AVG(Claim_Amounts.Claim_Amount) GROUP BY Policy_Type;
|
What is the percentage of residents in rural areas of Florida who have visited a doctor in the past year?
|
CREATE TABLE florida_rural_residents (resident_id INT,rural_area VARCHAR(255),visited_doctor BOOLEAN); INSERT INTO florida_rural_residents VALUES (1,'Rural Area 1',true),(2,'Rural Area 2',false);
|
SELECT (COUNT(*) FILTER (WHERE visited_doctor = true)) * 100.0 / COUNT(*) FROM florida_rural_residents WHERE rural_area IS NOT NULL;
|
Delete records of vessels with missing engine status information.
|
CREATE TABLE Vessels (VesselID INT,VesselName TEXT,FuelType TEXT,EngineStatus TEXT); INSERT INTO Vessels (VesselID,VesselName,FuelType,EngineStatus) VALUES (1,'Sea Tiger','LNG','Operational'),(2,'Ocean Wave','Diesel',NULL),(3,'River Queen','LNG','Operational'),(4,'Harbor Breeze','Diesel','Operational');
|
DELETE FROM Vessels WHERE EngineStatus IS NULL;
|
Which manufacturer has built the most unique types of submarines?
|
CREATE TABLE Submarines (id INT PRIMARY KEY,name VARCHAR(50),type VARCHAR(50),manufacturer VARCHAR(50),year INT); INSERT INTO Submarines (id,name,type,manufacturer,year) VALUES (1,'Dory','Mini','Acme Inc.',2015),(2,'Nemo','Midget','SeaWorks',2017),(3,'Oceanic','Spy','OceanTech',2018),(4,'SeaStar','Mini','Acme Inc.',2019);
|
SELECT manufacturer, COUNT(DISTINCT type) AS unique_types FROM Submarines GROUP BY manufacturer ORDER BY unique_types DESC LIMIT 1;
|
What was the minimum price per gram for Sativa strains in Washington in 2020?
|
CREATE TABLE prices (id INT,state VARCHAR(50),year INT,strain_type VARCHAR(50),price FLOAT); INSERT INTO prices (id,state,year,strain_type,price) VALUES (1,'Washington',2020,'Sativa',10.0),(2,'Washington',2020,'Indica',12.0),(3,'Oregon',2021,'Hybrid',11.5);
|
SELECT MIN(price) FROM prices WHERE state = 'Washington' AND year = 2020 AND strain_type = 'Sativa';
|
What is the total number of work hours lost due to equipment failures at the mining sites in 2020?
|
CREATE TABLE WorkHours (WorkHourID INT,SiteID INT,Year INT,Cause VARCHAR(255),Hours INT); INSERT INTO WorkHours (WorkHourID,SiteID,Year,Cause,Hours) VALUES (1,1,2020,'Equipment Failure',10),(2,2,2019,'Human Error',15),(3,3,2020,'Equipment Failure',20),(4,1,2020,'Equipment Failure',25);
|
SELECT SUM(Hours) FROM WorkHours WHERE Year = 2020 AND Cause = 'Equipment Failure';
|
How many articles were published in the articles table before and after the year 2010?
|
CREATE TABLE articles (id INT,title TEXT,publication_date DATE);
|
SELECT COUNT(*) FROM articles WHERE publication_date < '2010-01-01' UNION SELECT COUNT(*) FROM articles WHERE publication_date >= '2010-01-01';
|
What is the total number of aircraft manufactured by each company in 2020?
|
CREATE TABLE Manufacturers (Id INT,Name VARCHAR(50),Country VARCHAR(50)); INSERT INTO Manufacturers (Id,Name,Country) VALUES (1,'Boeing','USA'),(2,'Airbus','Europe'); CREATE TABLE Aircraft (Id INT,ManufacturerId INT,Model VARCHAR(50),ProductionYear INT); INSERT INTO Aircraft (Id,ManufacturerId,Model,ProductionYear) VALUES (1,1,'737',2020),(2,1,'787',2020),(3,2,'A320',2020),(4,2,'A350',2020);
|
SELECT m.Name, COUNT(a.Id) as Total FROM Manufacturers m JOIN Aircraft a ON m.Id = a.ManufacturerId WHERE a.ProductionYear = 2020 GROUP BY m.Name;
|
What is the total number of mobile subscribers who have made international calls in the Eastern region?
|
CREATE TABLE mobile_subscribers (subscriber_id INT,international_calls BOOLEAN,region VARCHAR(20)); INSERT INTO mobile_subscribers (subscriber_id,international_calls,region) VALUES (1,TRUE,'Southeast'),(2,FALSE,'Northeast'),(3,FALSE,'Southeast'),(4,TRUE,'Northern'),(5,TRUE,'Eastern'),(6,TRUE,'Eastern');
|
SELECT COUNT(*) FROM mobile_subscribers WHERE international_calls = TRUE AND region = 'Eastern';
|
Determine the highest sustainability rating for each restaurant category.
|
CREATE TABLE restaurants (id INT,name VARCHAR(255),category VARCHAR(255),sustainability_rating INT,monthly_revenue DECIMAL(10,2)); INSERT INTO restaurants (id,name,category,sustainability_rating,monthly_revenue) VALUES (1,'Green Garden','Organic',5,25000),(2,'Quick Bites','Fast Food',2,18000),(3,'Healthy Bites','Organic',4,22000),(4,'Farm Fresh','Farm to Table',3,19000),(5,'Local Harvest','Organic',5,26000);
|
SELECT category, MAX(sustainability_rating) FROM restaurants GROUP BY category;
|
What is the total revenue for each genre, for genres that have more than 5 concerts, in descending order?
|
CREATE SCHEMA if not exists music_schema;CREATE TABLE if not exists concerts (id INT,name VARCHAR,city VARCHAR,genre VARCHAR,revenue FLOAT);INSERT INTO concerts (id,name,city,genre,revenue) VALUES (1,'Music Festival','New York','Pop',50000.00),(2,'Rock Concert','Chicago','Rock',75000.00),(3,'Jazz Festival','Los Angeles','Jazz',125000.00),(4,'Hip Hop Concert','Miami','Hip Hop',60000.00),(5,'Country Music Festival','Nashville','Country',40000.00),(6,'EDM Festival','Las Vegas','EDM',80000.00),(7,'Pop Concert','Los Angeles','Pop',70000.00),(8,'Rock Festival','Chicago','Rock',65000.00),(9,'Jazz Concert','Los Angeles','Jazz',110000.00),(10,'Hip Hop Festival','Miami','Hip Hop',75000.00);
|
SELECT genre, SUM(revenue) as total_revenue FROM music_schema.concerts GROUP BY genre HAVING COUNT(*) > 5 ORDER BY total_revenue DESC;
|
What is the total number of customers who have made at least one transaction in the last month?
|
CREATE TABLE customers (customer_id INT,name VARCHAR(50),last_transaction_date DATE); INSERT INTO customers (customer_id,name,last_transaction_date) VALUES (1,'John Doe','2022-01-15'),(2,'Jane Smith',NULL),(3,'Bob Johnson','2022-01-03');
|
SELECT COUNT(DISTINCT customer_id) FROM customers WHERE last_transaction_date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH);
|
What are the total production figures for oil and gas in the North Sea, broken down by country?
|
CREATE TABLE north_sea_oil_production (country VARCHAR(50),year INT,oil_production FLOAT,gas_production FLOAT); INSERT INTO north_sea_oil_production (country,year,oil_production,gas_production) VALUES ('UK',2019,70.5,34.6),('Norway',2019,124.6,91.2),('Denmark',2019,12.3,4.8);
|
SELECT country, SUM(oil_production) as total_oil_production, SUM(gas_production) as total_gas_production FROM north_sea_oil_production GROUP BY country;
|
What is the average lead time for each product, for the past 6 months, by each supplier?
|
CREATE TABLE LeadTimes (lead_time INT,supplier_id INT,product VARCHAR(255),lead_time_date DATE); INSERT INTO LeadTimes (lead_time,supplier_id,product,lead_time_date) VALUES (10,1,'Product A','2021-01-01'); INSERT INTO LeadTimes (lead_time,supplier_id,product,lead_time_date) VALUES (15,2,'Product B','2021-01-01'); INSERT INTO LeadTimes (lead_time,supplier_id,product,lead_time_date) VALUES (12,1,'Product A','2021-02-01');
|
SELECT s.supplier_id, s.product, AVG(s.lead_time) as avg_lead_time FROM LeadTimes s WHERE s.lead_time_date BETWEEN DATE_SUB(NOW(), INTERVAL 6 MONTH) AND NOW() GROUP BY s.supplier_id, s.product;
|
What is the total CO2 emission of each manufacturing process?
|
CREATE TABLE ManufacturingProcesses (ProcessID INT,ProcessName VARCHAR(50)); INSERT INTO ManufacturingProcesses (ProcessID,ProcessName) VALUES (1,'ProcessA'),(2,'ProcessB'),(3,'ProcessC'); CREATE TABLE CO2Emissions (EmissionID INT,CO2Emission DECIMAL(5,2),ProcessID INT); INSERT INTO CO2Emissions (EmissionID,CO2Emission,ProcessID) VALUES (1,50.50,1),(2,60.60,1),(3,70.70,2),(4,80.80,2),(5,90.90,3),(6,100.00,3);
|
SELECT ProcessName, SUM(CO2Emission) as TotalCO2Emission FROM ManufacturingProcesses mp JOIN CO2Emissions ce ON mp.ProcessID = ce.ProcessID GROUP BY ProcessName;
|
How many unique organizations provided support in Kenya?
|
CREATE TABLE organizations (id INT,name TEXT,location TEXT); INSERT INTO organizations (id,name,location) VALUES (1,'WFP','Kenya'),(2,'UNHCR','Tanzania'),(3,'Save the Children','Kenya');
|
SELECT COUNT(DISTINCT name) FROM organizations WHERE location = 'Kenya';
|
List all factories that produce products that are ethically sourced in the 'Factory' table
|
CREATE TABLE Factory (factory_id INT PRIMARY KEY,factory_country VARCHAR(50),product_id INT,FOREIGN KEY (product_id) REFERENCES Product(product_id)); CREATE TABLE Product (product_id INT PRIMARY KEY,product_name VARCHAR(50),is_ethically_sourced BOOLEAN);
|
SELECT DISTINCT Factory.factory_country FROM Factory INNER JOIN Product ON Factory.product_id = Product.product_id WHERE Product.is_ethically_sourced = TRUE;
|
What is the average health equity metric score for mental health facilities in suburban areas?
|
CREATE TABLE mental_health_facilities (facility_id INT,location TEXT,score INT); INSERT INTO mental_health_facilities (facility_id,location,score) VALUES (1,'Urban',80),(2,'Rural',75),(3,'Suburban',85);
|
SELECT AVG(score) FROM mental_health_facilities WHERE location = 'Suburban';
|
Show the number of AI safety incidents that occurred before and after a specific date, partitioned by region.
|
CREATE TABLE SafetyIncidents (incident_id INT,incident_date DATE,region VARCHAR(255),incident_type VARCHAR(255)); INSERT INTO SafetyIncidents (incident_id,incident_date,region,incident_type) VALUES (1,'2022-01-01','US','Algorithm Malfunction'),(2,'2022-01-10','Canada','Data Breach'),(3,'2022-01-15','US','System Failure'),(4,'2022-02-01','Canada','Algorithm Malfunction'),(5,'2022-02-15','US','Data Breach'),(6,'2022-03-01','Canada','System Failure');
|
SELECT region, COUNT(CASE WHEN incident_date < '2022-02-01' THEN 1 END) as incidents_before, COUNT(CASE WHEN incident_date >= '2022-02-01' THEN 1 END) as incidents_after FROM SafetyIncidents GROUP BY region;
|
Delete the record with id 3 from the 'animals' table
|
CREATE TABLE animals (id INT PRIMARY KEY,name VARCHAR(50),species VARCHAR(50),population INT);
|
DELETE FROM animals WHERE id = 3;
|
Which strains are not compliant with regulatory limits for THC content?
|
CREATE TABLE StrainRegulations (StrainName TEXT,MaximumTHCContent FLOAT); INSERT INTO StrainRegulations (StrainName,MaximumTHCContent) VALUES ('Purple Haze',20.0),('Blue Dream',18.0),('Sour Diesel',19.0); CREATE TABLE StrainTesting (StrainName TEXT,THCContent FLOAT); INSERT INTO StrainTesting (StrainName,THCContent) VALUES ('Purple Haze',22.0),('Blue Dream',17.5),('Sour Diesel',21.0);
|
SELECT StrainName FROM StrainTesting WHERE THCContent > (SELECT MaximumTHCContent FROM StrainRegulations WHERE StrainName = StrainTesting.StrainName);
|
What's the total amount donated by each donor, ordered by the most donated?
|
CREATE TABLE Donors (Id INT,Name TEXT,Amount DECIMAL(10,2)); INSERT INTO Donors VALUES (1,'Alice',250.00),(2,'Bob',175.00);
|
SELECT Name, SUM(Amount) as TotalDonated FROM Donors GROUP BY Name ORDER BY TotalDonated DESC;
|
What is the maximum capacity of renewable energy sources in city 3?
|
CREATE TABLE city (id INT,name VARCHAR(255),population INT,sustainable_projects INT); INSERT INTO city (id,name,population,sustainable_projects) VALUES (1,'San Francisco',884363,450); INSERT INTO city (id,name,population,sustainable_projects) VALUES (2,'Los Angeles',4000000,650); INSERT INTO city (id,name,population,sustainable_projects) VALUES (3,'New York',8500000,1500); CREATE TABLE building (id INT,name VARCHAR(255),city_id INT,size FLOAT,is_green BOOLEAN); INSERT INTO building (id,name,city_id,size,is_green) VALUES (1,'City Hall',1,12000.0,true); INSERT INTO building (id,name,city_id,size,is_green) VALUES (2,'Library',1,8000.0,false); CREATE TABLE renewable_energy (id INT,building_id INT,type VARCHAR(255),capacity INT); INSERT INTO renewable_energy (id,building_id,type,capacity) VALUES (1,1,'Solar',100); INSERT INTO renewable_energy (id,building_id,type,capacity) VALUES (2,1,'Wind',50);
|
SELECT MAX(capacity) as max_capacity FROM renewable_energy WHERE building_id IN (SELECT id FROM building WHERE city_id = 3);
|
Which program has the most volunteers?
|
CREATE TABLE Volunteers (VolunteerID INT,Name TEXT,Program TEXT);
|
SELECT Program, COUNT(*) AS Count FROM Volunteers GROUP BY Program ORDER BY Count DESC LIMIT 1;
|
Show the total number of restorative justice programs by city
|
CREATE TABLE restorative_justice_programs (program_id INT,city VARCHAR(50),victims_served INT); INSERT INTO restorative_justice_programs (program_id,city,victims_served) VALUES (1,'Los Angeles',300),(2,'New York',400),(3,'Houston',550),(4,'Miami',600),(5,'San Francisco',700),(6,'Chicago',800);
|
SELECT city, COUNT(*) FROM restorative_justice_programs GROUP BY city;
|
What are the green-certified properties in cities with populations over 1,000,000 and their certification years?
|
CREATE TABLE Property (id INT PRIMARY KEY,city_id INT,type VARCHAR(50),price INT); CREATE TABLE Sustainable_Building (id INT PRIMARY KEY,property_id INT,certification VARCHAR(50),year INT); CREATE VIEW Green_Certified_Properties AS SELECT * FROM Sustainable_Building WHERE certification IN ('LEED','BREEAM');
|
SELECT Property.city_id, Green_Certified_Properties.certification, Green_Certified_Properties.year FROM Property INNER JOIN Green_Certified_Properties ON Property.id = Green_Certified_Properties.property_id WHERE Property.type = 'Green Apartments' AND Property.city_id IN (SELECT id FROM City WHERE population > 1000000);
|
How many building permits were issued per region?
|
CREATE TABLE Building_Permits (id INT,region VARCHAR(20),permit_number VARCHAR(20),project VARCHAR(30),quantity INT); INSERT INTO Building_Permits (id,region,permit_number,project,quantity) VALUES (1,'North','GP001','Green Tower',500),(2,'West','GP002','Solar Park',200),(3,'East','GP003','Wind Farm',800);
|
SELECT region, COUNT(permit_number) FROM Building_Permits GROUP BY region;
|
Show the top 3 countries with the highest number of reported vulnerabilities in the last month, excluding any vulnerabilities related to software version 1.0.0.
|
CREATE TABLE vulnerabilities (id INT,country VARCHAR(255),software_version VARCHAR(255),report_date DATE); INSERT INTO vulnerabilities (id,country,software_version,report_date) VALUES (1,'USA','1.0.0','2022-01-01'); INSERT INTO vulnerabilities (id,country,software_version,report_date) VALUES (2,'Canada','2.0.0','2022-01-05'); INSERT INTO vulnerabilities (id,country,software_version,report_date) VALUES (3,'Mexico','1.0.0','2022-01-09');
|
SELECT country, COUNT(*) as total_vulnerabilities FROM vulnerabilities WHERE report_date >= DATEADD(month, -1, GETDATE()) AND software_version != '1.0.0' GROUP BY country ORDER BY total_vulnerabilities DESC LIMIT 3;
|
How many electric taxis are currently in operation in Berlin, Germany?
|
CREATE TABLE electric_taxis (taxi_id INT,in_operation BOOLEAN,city VARCHAR(50));
|
SELECT COUNT(*) FROM electric_taxis WHERE in_operation = TRUE AND city = 'Berlin';
|
Find the dispensary with the highest total sales revenue in the third quarter of 2021.
|
CREATE TABLE DispensarySales (dispensary_id INT,sale_revenue DECIMAL(10,2),sale_date DATE);
|
SELECT dispensary_id, SUM(sale_revenue) as total_revenue FROM DispensarySales WHERE sale_date >= '2021-07-01' AND sale_date <= '2021-09-30' GROUP BY dispensary_id ORDER BY total_revenue DESC LIMIT 1;
|
What is the average waste generation per capita in kg for the region 'Jakarta' in 2021?
|
CREATE TABLE waste_per_capita (region VARCHAR(50),year INT,per_capita_kg FLOAT); INSERT INTO waste_per_capita (region,year,per_capita_kg) VALUES ('Jakarta',2021,567.89);
|
SELECT AVG(per_capita_kg) FROM waste_per_capita WHERE region = 'Jakarta' AND year = 2021;
|
What is the maximum ESG score for the Agriculture sector?
|
CREATE TABLE investments(id INT,sector VARCHAR(20),esg_score INT); INSERT INTO investments VALUES(1,'Agriculture',90),(2,'Healthcare',75),(3,'Agriculture',87);
|
SELECT MAX(esg_score) as max_esg_score FROM investments WHERE sector = 'Agriculture';
|
Delete all records from the "cases" table where the case type is 'civil'
|
CREATE TABLE cases (case_id INT,case_type VARCHAR(10)); INSERT INTO cases (case_id,case_type) VALUES (1,'civil'),(2,'criminal');
|
DELETE FROM cases WHERE case_type = 'civil';
|
Show revenue for restaurants located in 'California' and 'Texas' from the 'Revenue' table, excluding records with a revenue greater than 40000.
|
CREATE TABLE Revenue (restaurant VARCHAR(255),state VARCHAR(255),revenue DECIMAL(10,2)); INSERT INTO Revenue (restaurant,state,revenue) VALUES ('Bistro Veggie','California',35000),('Pizza House','New York',50000),('Vegan Delight','California',40000);
|
SELECT revenue FROM Revenue WHERE state IN ('California', 'Texas') AND revenue <= 40000;
|
How many marine species are there in each ocean basin, in descending order?
|
CREATE TABLE marine_species_by_basin (id INT,species VARCHAR(255),basin VARCHAR(255)); INSERT INTO marine_species_by_basin (id,species,basin) VALUES (1,'Species1','Atlantic'),(2,'Species2','Pacific');
|
SELECT basin, COUNT(*) as species_count FROM marine_species_by_basin GROUP BY basin ORDER BY species_count DESC;
|
Who is the leading goal scorer in the history of the English Premier League?
|
CREATE TABLE epl_goals (player_name VARCHAR(50),goals INT,assists INT); INSERT INTO epl_goals (player_name,goals,assists) VALUES ('Alan Shearer',260,64),('Wayne Rooney',208,103);
|
SELECT player_name, SUM(goals) as total_goals FROM epl_goals GROUP BY player_name ORDER BY total_goals DESC LIMIT 1;
|
What is the name and position of the top 2 military personnel with the highest salaries?
|
CREATE TABLE MilitaryPersonnel (PersonnelID INT,PersonnelName TEXT,Position TEXT,Salary INT); INSERT INTO MilitaryPersonnel (PersonnelID,PersonnelName,Position,Salary) VALUES (1,'John Smith','General',200000); INSERT INTO MilitaryPersonnel (PersonnelID,PersonnelName,Position,Salary) VALUES (2,'Jane Doe','Colonel',150000); INSERT INTO MilitaryPersonnel (PersonnelID,PersonnelName,Position,Salary) VALUES (3,'Mike Johnson','Sergeant',80000);
|
SELECT PersonnelName, Position FROM MilitaryPersonnel ORDER BY Salary DESC LIMIT 2;
|
How many movies were released per year in the USA?
|
CREATE TABLE movie_info (title VARCHAR(255),release_year INT,country VARCHAR(255)); INSERT INTO movie_info (title,release_year,country) VALUES ('The Matrix',1999,'USA'),('Pulp Fiction',1994,'USA');
|
SELECT release_year, COUNT(*) FROM movie_info WHERE country = 'USA' GROUP BY release_year;
|
What is the average lifelong learning score of students in 'Summer 2022'?
|
CREATE TABLE lifelong_learning (student_id INT,learning_score INT,date DATE); INSERT INTO lifelong_learning (student_id,learning_score,date) VALUES (1,90,'2022-06-01'),(2,95,'2022-06-02'),(3,80,'2022-06-03');
|
SELECT AVG(learning_score) FROM lifelong_learning WHERE date = '2022-06-01';
|
Yearly change in carbon price from 2015 to 2025?
|
CREATE TABLE carbon_price (year INT,price FLOAT); INSERT INTO carbon_price (year,price) VALUES (2015,10.0),(2016,12.5),(2017,15.0),(2018,17.5),(2019,20.0),(2020,22.5),(2021,25.0),(2022,27.5),(2023,30.0),(2024,32.5),(2025,35.0);
|
SELECT cp1.year + INTERVAL '1 year' AS year, (cp2.price - cp1.price) / cp1.price * 100.0 AS percentage_change FROM carbon_price cp1 JOIN carbon_price cp2 ON cp1.year + 1 = cp2.year;
|
What is the maximum number of safety issues in a workplace for each state?
|
CREATE TABLE workplaces (id INT,state VARCHAR(2),safety_issues INT); INSERT INTO workplaces (id,state,safety_issues) VALUES (1,'NY',10),(2,'CA',5),(3,'TX',15),(4,'FL',8);
|
SELECT state, MAX(safety_issues) OVER (PARTITION BY state) AS max_safety_issues FROM workplaces;
|
What is the total amount of copper mined in the last quarter from the mines in the Andes?
|
CREATE TABLE CopperMined (MineID INT,MineType VARCHAR(15),MinedDate DATE,CopperAmount INT);
|
SELECT SUM(CopperAmount) FROM CopperMined WHERE MineType = 'Copper' AND MinedDate >= DATEADD(quarter, DATEDIFF(quarter, 0, GETDATE()), 0);
|
What is the total volume of trees in the 'TropicalRainforest' table?
|
CREATE TABLE TropicalRainforest (id INT,species VARCHAR(255),diameter FLOAT,height FLOAT,volume FLOAT); INSERT INTO TropicalRainforest (id,species,diameter,height,volume) VALUES (1,'RubberTree',3.2,45,15.6); INSERT INTO TropicalRainforest (id,species,diameter,height,volume) VALUES (2,'Mahogany',4.5,60,30.8);
|
SELECT SUM(volume) FROM TropicalRainforest;
|
What is the average depth for marine species in the Actinopterygii order, grouped by their family?
|
CREATE TABLE marine_species (species_id INT,species_name VARCHAR(100),max_depth FLOAT,order_name VARCHAR(50),family VARCHAR(50));
|
SELECT family, AVG(max_depth) FROM marine_species WHERE order_name = 'Actinopterygii' GROUP BY family;
|
What is the tier of each supply based on quantity, with 5 tiers?
|
CREATE TABLE supplies (id INT,name TEXT,quantity INT,category TEXT,expiration_date DATE); INSERT INTO supplies (id,name,quantity,category,expiration_date) VALUES (1,'Water',500,'Essential','2023-05-01'); INSERT INTO supplies (id,name,quantity,category,expiration_date) VALUES (2,'Tents',100,'Shelter','2022-12-31');
|
SELECT *, NTILE(5) OVER (ORDER BY quantity DESC) as tier FROM supplies;
|
What is the circular economy rating of the 'Innovative Technologies' plant?
|
CREATE TABLE Plants (id INT,name VARCHAR(255),circular_economy_rating DECIMAL(3,2)); INSERT INTO Plants (id,name,circular_economy_rating) VALUES (4,'Innovative Technologies',4.2);
|
SELECT circular_economy_rating FROM Plants WHERE name = 'Innovative Technologies';
|
Identify the Green building certification with the lowest certification authority count, along with the certification authority
|
CREATE TABLE green_buildings (id INT PRIMARY KEY,building_name VARCHAR(255),certification VARCHAR(255),certification_authority VARCHAR(255)); INSERT INTO green_buildings (id,building_name,certification,certification_authority) VALUES (1,'EcoCampus','LEED','USGBC'); INSERT INTO green_buildings (id,building_name,certification,certification_authority) VALUES (2,'GreenApartments','BREEAM','BRE'); INSERT INTO green_buildings (id,building_name,certification,certification_authority) VALUES (3,'EcoOffice','Green Star','GBCA');
|
SELECT certification, certification_authority FROM green_buildings GROUP BY certification, certification_authority HAVING COUNT(*) = (SELECT MIN(cert_count) FROM (SELECT certification_authority, COUNT(*) as cert_count FROM green_buildings GROUP BY certification_authority) t);
|
What is the maximum swimming speed achieved in a race by athletes in Rio de Janeiro?
|
CREATE TABLE if not exists cities (city_id INT,city VARCHAR(255)); INSERT INTO cities (city_id,city) VALUES (1,'Rio de Janeiro'),(2,'Sydney'),(3,'Tokyo'); CREATE TABLE if not exists athletes (athlete_id INT,city_id INT,speed FLOAT); INSERT INTO athletes (athlete_id,city_id,speed) VALUES (1,1,1.2),(2,2,1.5),(3,3,1.3),(4,1,1.8),(5,1,2.0);
|
SELECT MAX(speed) FROM athletes WHERE city_id = 1;
|
Show the number of maintenance requests for each public transportation vehicle type
|
CREATE TABLE vehicle (vehicle_id INT,vehicle_type VARCHAR(20),last_maintenance_date DATE);
|
SELECT vehicle_type, COUNT(*) AS maintenance_requests FROM vehicle WHERE last_maintenance_date < DATE(NOW()) - INTERVAL 30 DAY GROUP BY vehicle_type;
|
How many hours did each volunteer contribute in the first quarter of 2024, including any partial hours?
|
CREATE TABLE VolunteerHours (HourID INT,VolunteerID INT,Hours DECIMAL(10,2),HourDate DATE);
|
SELECT V.Name, SUM(VH.Hours) as TotalHours FROM VolunteerHours VH JOIN Volunteers V ON VH.VolunteerID = Volunteers.VolunteerID WHERE VH.HourDate BETWEEN '2024-01-01' AND '2024-03-31' GROUP BY V.VolunteerID, V.Name;
|
What is the average amount spent by players who have made a purchase in the game "Galactic Guardians" and are from Africa?
|
CREATE TABLE Purchases (PlayerID INT,PlayerName VARCHAR(50),Game VARCHAR(50),Purchase_amount DECIMAL(10,2)); CREATE TABLE Players (PlayerID INT,PlayerName VARCHAR(50),Game VARCHAR(50),Country VARCHAR(50)); INSERT INTO Players (PlayerID,PlayerName,Game,Country) VALUES (1,'John Doe','Galactic Guardians','Egypt'); INSERT INTO Players (PlayerID,PlayerName,Game,Country) VALUES (2,'Jane Smith','Galactic Guardians','South Africa'); INSERT INTO Purchases (PlayerID,PlayerName,Game,Purchase_amount) VALUES (1,'John Doe','Galactic Guardians',50.00); INSERT INTO Purchases (PlayerID,PlayerName,Game,Purchase_amount) VALUES (2,'Jane Smith','Galactic Guardians',75.00);
|
SELECT AVG(Purchase_amount) FROM Players INNER JOIN Purchases ON Players.PlayerID = Purchases.PlayerID WHERE Players.Game = 'Galactic Guardians' AND Players.Country LIKE 'Africa%';
|
What is the percentage change in international arrivals to each continent compared to the same quarter last year?
|
CREATE TABLE quarterly_arrivals (continent VARCHAR(255),year INT,quarter INT,arrivals INT); INSERT INTO quarterly_arrivals (continent,year,quarter,arrivals) VALUES ('Asia',2021,1,4000000); INSERT INTO quarterly_arrivals (continent,year,quarter,arrivals) VALUES ('Asia',2021,2,4500000); INSERT INTO quarterly_arrivals (continent,year,quarter,arrivals) VALUES ('Asia',2020,1,3500000); INSERT INTO quarterly_arrivals (continent,year,quarter,arrivals) VALUES ('Asia',2020,2,4000000);
|
SELECT continent, year, quarter, arrivals, NTILE(4) OVER (ORDER BY arrivals) as quartile, (arrivals - LAG(arrivals) OVER (PARTITION BY continent ORDER BY year, quarter))*100.0 / LAG(arrivals) OVER (PARTITION BY continent ORDER BY year, quarter) as pct_change FROM quarterly_arrivals;
|
Calculate the average food safety score for restaurants located in NY.
|
CREATE TABLE restaurant_inspections (id INT,restaurant_id INT,inspection_date DATE,score INT); INSERT INTO restaurant_inspections (id,restaurant_id,inspection_date,score) VALUES (1,1,'2022-01-01',95),(2,1,'2022-03-15',92),(3,2,'2022-01-10',88),(4,2,'2022-02-20',90),(5,3,'2022-01-05',98),(6,3,'2022-03-22',97); CREATE TABLE restaurants (id INT,name VARCHAR(255),location VARCHAR(255)); INSERT INTO restaurants (id,name,location) VALUES (1,'Green Garden','NY'),(2,'Quick Bites','CA'),(3,'Healthy Bites','NY');
|
SELECT AVG(score) FROM restaurant_inspections JOIN restaurants ON restaurant_inspections.restaurant_id = restaurants.id WHERE restaurants.location = 'NY';
|
What is the number of water conservation initiatives implemented in the state of New York for each year since 2015?
|
CREATE TABLE conservation_initiatives (initiative_id INT,state VARCHAR(20),initiative_year INT); INSERT INTO conservation_initiatives (initiative_id,state,initiative_year) VALUES (1,'New York',2015); INSERT INTO conservation_initiatives (initiative_id,state,initiative_year) VALUES (2,'New York',2016);
|
SELECT initiative_year, COUNT(*) FROM conservation_initiatives WHERE state = 'New York' GROUP BY initiative_year;
|
What is the most common age group for tuberculosis cases in South Africa?
|
CREATE TABLE SouthAfrica (Age VARCHAR(50),TuberculosisCases INT); INSERT INTO SouthAfrica (Age,TuberculosisCases) VALUES ('0-4',123),('5-9',234),('10-14',345),('15-19',456),('20-24',567),('25-29',678),('30-34',789),('35-39',890),('40-44',901),('45-49',1012),('50-54',1123),('55-59',1234),('60-64',1345),('65-69',1456),('70-74',1567),('75-79',1678),('80-84',1789),('85-89',1890),('90-94',1901),('95-99',2012),('100-104',2123);
|
SELECT Age, TuberculosisCases FROM SouthAfrica ORDER BY TuberculosisCases DESC LIMIT 1;
|
Find the number of building permits issued in Los Angeles County for 2020
|
CREATE TABLE building_permits (county VARCHAR(255),year INTEGER,num_permits INTEGER); INSERT INTO building_permits (county,year,num_permits) VALUES ('Los Angeles County',2020,12000),('Los Angeles County',2019,11000),('Orange County',2020,9000);
|
SELECT SUM(num_permits) FROM building_permits WHERE county = 'Los Angeles County' AND year = 2020;
|
List all the co-owned properties in Vancouver, BC and their owners.
|
CREATE TABLE properties (id INT,city VARCHAR(50),price INT); CREATE TABLE co_owners (property_id INT,owner_name VARCHAR(50)); INSERT INTO properties (id,city,price) VALUES (1,'Vancouver',800000),(2,'Seattle',400000); INSERT INTO co_owners (property_id,owner_name) VALUES (1,'Greg'),(1,'Harmony'),(2,'Ivy');
|
SELECT properties.city, co_owners.owner_name FROM properties INNER JOIN co_owners ON properties.id = co_owners.property_id WHERE properties.city = 'Vancouver';
|
What's the total revenue generated per visitor who attended the 'Ancient Civilization' exhibition?
|
CREATE TABLE Transactions (TransactionID INT,VisitorID INT,Amount DECIMAL(10,2));
|
SELECT AVG(t.Amount) FROM Transactions t JOIN Visitors v ON t.VisitorID = v.VisitorID JOIN Artworks a ON v.VisitorID = a.VisitorID JOIN Exhibitions e ON a.ExhibitionID = e.ExhibitionID WHERE e.ExhibitionName = 'Ancient Civilization';
|
What is the number of students who received each type of disability support service?
|
CREATE TABLE Support_Services (Student_ID INT,Student_Name TEXT,Service_Type TEXT); INSERT INTO Support_Services (Student_ID,Student_Name,Service_Type) VALUES (1,'John Doe','Tutoring'),(2,'Jane Smith','Sign Language Interpreting'),(3,'Michael Brown','Tutoring');
|
SELECT Service_Type, COUNT(*) FROM Support_Services GROUP BY Service_Type;
|
How many students are enrolled in each school type (public, private, or charter) in the 'school_enrollment' table?
|
CREATE TABLE school_enrollment (school_id INT,student_count INT,school_type VARCHAR(10));
|
SELECT school_type, SUM(student_count) FROM school_enrollment GROUP BY school_type;
|
What is the maximum water consumption recorded for any household in the city of Los Angeles?
|
CREATE TABLE Household_Water_Usage (ID INT,City VARCHAR(20),Consumption FLOAT); INSERT INTO Household_Water_Usage (ID,City,Consumption) VALUES (1,'Seattle',12.3),(2,'Los Angeles',15.6),(3,'Seattle',13.4);
|
SELECT MAX(Consumption) FROM Household_Water_Usage WHERE City = 'Los Angeles';
|
What are the top 5 most expensive products?
|
CREATE TABLE if not exists product (id INT PRIMARY KEY,name TEXT,brand_id INT,price DECIMAL(5,2)); INSERT INTO product (id,name,brand_id,price) VALUES (3,'Luxury Moisturizing Cream',1,250.00);
|
SELECT name, price FROM product ORDER BY price DESC LIMIT 5;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.