instruction
stringlengths 0
1.06k
| input
stringlengths 11
5.3k
| response
stringlengths 2
4.44k
|
---|---|---|
Find the number of artists from each country, who have been awarded the National Medal of Arts, and the name of the country's capital.
|
CREATE TABLE artists_nma (id INT,name VARCHAR(50),country VARCHAR(30)); INSERT INTO artists_nma (id,name,country) VALUES (1,'Artist1','USA'),(2,'Artist2','Canada'),(3,'Artist3','Mexico'); CREATE TABLE countries (id INT,country VARCHAR(30),capital VARCHAR(30)); INSERT INTO countries (id,country,capital) VALUES (1,'USA','Washington DC'),(2,'Canada','Ottawa'),(3,'Mexico','Mexico City');
|
SELECT c.capital, a.country, COUNT(a.id) as artist_count FROM artists_nma a JOIN countries c ON a.country = c.country GROUP BY a.country, c.capital;
|
What is the average donation amount for each cause in Sub-Saharan Africa?
|
CREATE TABLE cause_average (cause VARCHAR(50),country VARCHAR(50),donation DECIMAL(10,2)); INSERT INTO cause_average (cause,country,donation) VALUES ('Global Health','Nigeria',500.00),('Education','South Africa',600.00),('Environment','Kenya',700.00),('Animal Welfare','Tanzania',800.00);
|
SELECT cause, AVG(donation) FROM cause_average WHERE country IN ('Nigeria', 'South Africa', 'Kenya', 'Tanzania') GROUP BY cause;
|
What is the total number of news articles published in the "articles" table by year?
|
CREATE TABLE articles (id INT,title VARCHAR(100),publication_date DATE);
|
SELECT EXTRACT(YEAR FROM publication_date) AS year, COUNT(*) AS num_articles FROM articles GROUP BY year;
|
Which cybersecurity strategies were implemented in the last 3 years?
|
CREATE TABLE cyber_strategies (id INT,strategy VARCHAR(255),implementation_date DATE); INSERT INTO cyber_strategies (id,strategy,implementation_date) VALUES (1,'Next-gen firewalls','2020-01-01'),(2,'AI-driven threat hunting','2021-04-15'),(3,'Zero Trust framework','2019-07-22'),(4,'Encrypted communications','2020-12-03'),(5,'Multi-factor authentication','2021-06-08');
|
SELECT strategy, YEAR(implementation_date) as year FROM cyber_strategies WHERE implementation_date >= DATE(NOW()) - INTERVAL 3 YEAR;
|
What is the total number of medals won by athletes from Japan in the Olympics?
|
CREATE TABLE olympics (athlete TEXT,country TEXT,medal TEXT);
|
SELECT SUM(CASE WHEN medal = 'Gold' THEN 1 WHEN medal = 'Silver' THEN 0.5 WHEN medal = 'Bronze' THEN 0.25 ELSE 0 END) as total_medals FROM olympics WHERE country = 'Japan';
|
What is the total revenue for each region in the 'Region_Sales' table?
|
CREATE TABLE Region_Sales (region TEXT,revenue FLOAT); INSERT INTO Region_Sales (region,revenue) VALUES ('North',50000),('South',60000);
|
SELECT region, SUM(revenue) FROM Region_Sales GROUP BY region;
|
What is the average mass of space debris by country?
|
CREATE TABLE space_debris (country TEXT,category TEXT,mass FLOAT); INSERT INTO space_debris (country,category,mass) VALUES ('USA','Aluminum',120.5),('USA','Titanium',170.1),('Russia','Aluminum',150.2),('Russia','Titanium',180.1),('China','Copper',100.1),('China','Steel',250.7);
|
SELECT country, AVG(mass) AS avg_mass FROM space_debris GROUP BY country;
|
What is the total revenue for cases handled by Smith & Johnson in the last quarter?
|
CREATE TABLE cases (id INT,attorney_firm VARCHAR(255),date DATE,revenue FLOAT); INSERT INTO cases (id,attorney_firm,date,revenue) VALUES (1,'Smith & Johnson','2021-01-01',5000.00),(2,'Smith & Johnson','2021-02-01',7000.00),(3,'Smith & Johnson','2021-03-01',6000.00);
|
SELECT SUM(revenue) FROM cases WHERE attorney_firm = 'Smith & Johnson' AND date >= DATE_SUB('2021-04-01', INTERVAL 3 MONTH);
|
What is the total cultural competency score for health workers in California?
|
CREATE TABLE CulturalCompetency (WorkerID INT,WorkerName VARCHAR(100),State VARCHAR(2),Score INT); INSERT INTO CulturalCompetency (WorkerID,WorkerName,State,Score) VALUES (1,'Michael Johnson','California',85);
|
SELECT SUM(Score) FROM CulturalCompetency WHERE State = 'California';
|
What is the earliest publication date of articles about 'immigration' published by 'Al Jazeera' in 2022?
|
CREATE TABLE articles (title VARCHAR(255),publication_date DATE,topic VARCHAR(50),channel VARCHAR(50)); INSERT INTO articles (title,publication_date,topic,channel) VALUES ('Immigration policies in the EU','2022-01-05','immigration','Al Jazeera'),('Immigration trends in the US','2022-01-10','immigration','Al Jazeera'),('Immigration and human rights','2022-01-15','immigration','Al Jazeera'),('Immigration and economy','2022-01-20','immigration','Al Jazeera'),('Immigration and technology','2022-01-25','immigration','Al Jazeera');
|
SELECT MIN(publication_date) FROM articles WHERE channel = 'Al Jazeera' AND topic = 'immigration' AND publication_date BETWEEN '2022-01-01' AND '2022-12-31';
|
How many marine species are there in the Arctic Ocean?
|
CREATE TABLE arctic_ocean (id INT,marine_species_count INT); INSERT INTO arctic_ocean (id,marine_species_count) VALUES (1,2000);
|
SELECT marine_species_count FROM arctic_ocean WHERE id = 1;
|
List the top 5 most popular game genres based on the number of unique players who have played games in each genre, and the average age of these players.
|
CREATE TABLE Genres (GenreID INT,Genre VARCHAR(20)); CREATE TABLE Games (GameID INT,GameName VARCHAR(50),GenreID INT); CREATE TABLE GamePlayer (PlayerID INT,GameID INT); CREATE TABLE Players (PlayerID INT,Age INT,Gender VARCHAR(10));
|
SELECT Genres.Genre, COUNT(DISTINCT GamePlayer.PlayerID) AS NumPlayers, AVG(Players.Age) AS AvgAge FROM Genres INNER JOIN Games ON Genres.GenreID = Games.GenreID INNER JOIN GamePlayer ON Games.GameID = GamePlayer.GameID INNER JOIN Players ON GamePlayer.PlayerID = Players.PlayerID GROUP BY Genres.Genre ORDER BY NumPlayers DESC LIMIT 5;
|
List the top 2 oxygen monitoring stations with the lowest average dissolved oxygen levels in the last 6 months?
|
CREATE TABLE monitoring_stations (id INT,name TEXT,location TEXT); INSERT INTO monitoring_stations (id,name,location) VALUES (1,'Station A','Coast of California'),(2,'Station B','Seattle Coast'),(3,'Station C','Florida Keys'); CREATE TABLE oxygen_readings (id INT,station_id INT,reading DATE,level DECIMAL(5,2)); INSERT INTO oxygen_readings (id,station_id,reading,level) VALUES (1,1,'2022-06-01',7.5),(2,1,'2022-06-15',7.3),(3,2,'2022-06-05',7.8),(4,2,'2022-06-20',7.6),(5,3,'2022-06-02',8.2),(6,3,'2022-06-17',8.0);
|
SELECT station_id, AVG(level) avg_oxygen FROM oxygen_readings WHERE reading >= DATEADD(month, -6, CURRENT_DATE) GROUP BY station_id ORDER BY avg_oxygen ASC FETCH FIRST 2 ROWS ONLY;
|
Delete records of military equipment maintenance for 'Type E-7' helicopters
|
CREATE TABLE equipment_maintenance (equipment_type VARCHAR(50),maintenance_date DATE,maintenance_cost DECIMAL(10,2));
|
DELETE FROM equipment_maintenance WHERE equipment_type = 'Type E-7';
|
How many safety incidents were recorded for each chemical in the past 6 months?
|
CREATE TABLE chemicals (chemical_id INT,chemical_name VARCHAR(50)); CREATE TABLE safety_incidents (incident_id INT,chemical_id INT,incident_date DATE); INSERT INTO chemicals (chemical_id,chemical_name) VALUES (1,'Chemical A'),(2,'Chemical B'); INSERT INTO safety_incidents (incident_id,chemical_id,incident_date) VALUES (1,1,'2022-01-01'),(2,2,'2022-01-01');
|
SELECT chemicals.chemical_name, COUNT(safety_incidents.incident_id) FROM chemicals LEFT JOIN safety_incidents ON chemicals.chemical_id = safety_incidents.chemical_id WHERE safety_incidents.incident_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH) GROUP BY chemicals.chemical_name;
|
How many missions has the Russian Federal Space Agency launched to the Moon?
|
CREATE TABLE rfsa_missions (id INT,mission_name VARCHAR(255),launch_date DATE,destination VARCHAR(255)); INSERT INTO rfsa_missions (id,mission_name,launch_date,destination) VALUES (1,'Luna 2','1959-09-12','Moon');
|
SELECT COUNT(*) FROM rfsa_missions WHERE destination = 'Moon';
|
Determine the number of security incidents caused by insider threats in the past month
|
CREATE TABLE security_incidents (id INT,incident_type VARCHAR(50),incident_date DATE);
|
SELECT COUNT(*) as num_incidents FROM security_incidents WHERE incident_type = 'insider threat' AND incident_date >= DATEADD(month, -1, GETDATE());
|
What is the current status of defense diplomacy initiatives between the USA and Canada?
|
CREATE TABLE defense_diplomacy (initiative_id INT,initiative_name TEXT,initiative_description TEXT,country1 TEXT,country2 TEXT,status TEXT); INSERT INTO defense_diplomacy (initiative_id,initiative_name,initiative_description,country1,country2,status) VALUES (1,'Joint Military Exercise','Annual military exercise between the USA and Canada','USA','Canada','In Progress'),(2,'Defense Technology Exchange','Exchange of defense technology between the USA and Canada','USA','Canada','Completed');
|
SELECT defense_diplomacy.status FROM defense_diplomacy WHERE defense_diplomacy.country1 = 'USA' AND defense_diplomacy.country2 = 'Canada';
|
What is the average order size for each salesperson?
|
CREATE TABLE salesperson (id INT,name VARCHAR(50),region VARCHAR(50)); INSERT INTO salesperson (id,name,region) VALUES (1,'John Doe','North'),(2,'Jane Smith','South'); CREATE TABLE orders (id INT,salesperson_id INT,size INT); INSERT INTO orders (id,salesperson_id,size) VALUES (1,1,10),(2,1,15),(3,2,20),(4,2,25);
|
SELECT salesperson_id, AVG(size) as avg_order_size FROM orders GROUP BY salesperson_id;
|
What is the average popularity of songs released in the 80s and 90s for each artist?
|
CREATE TABLE songs (song_id INT,title TEXT,release_year INT,artist_id INT,popularity INT); CREATE TABLE artists (artist_id INT,name TEXT);
|
SELECT a.name, AVG(s.popularity) FROM songs s JOIN artists a ON s.artist_id = a.artist_id WHERE s.release_year BETWEEN 1980 AND 1999 GROUP BY a.name;
|
What is the minimum drug approval time for drugs in Asia?
|
CREATE TABLE drug_approvals (approval_id INT,drug_name TEXT,approval_time INT,region TEXT); INSERT INTO drug_approvals (approval_id,drug_name,approval_time,region) VALUES (1,'DrugG',180,'Asia'),(2,'DrugH',210,'Asia');
|
SELECT region, MIN(approval_time) as min_approval_time FROM drug_approvals WHERE region = 'Asia';
|
List the top 3 categories with the highest number of orders in the past month.
|
CREATE TABLE categories (id INT,name TEXT); CREATE TABLE orders (id INT,category_id INT,order_date DATE);
|
SELECT c.name, COUNT(*) as num_orders FROM categories c JOIN orders o ON c.id = o.category_id WHERE order_date BETWEEN DATE_SUB(NOW(), INTERVAL 1 MONTH) AND NOW() GROUP BY c.name ORDER BY num_orders DESC LIMIT 3;
|
What are the names of forests in India and their respective carbon sequestration amounts for each year?
|
CREATE TABLE Forests (Fid INT PRIMARY KEY,Name VARCHAR(50),Country VARCHAR(50),Area FLOAT); CREATE TABLE Carbon (Cid INT PRIMARY KEY,Fid INT,Year INT,Sequestration FLOAT,FOREIGN KEY (Fid) REFERENCES Forests(Fid));
|
SELECT Forests.Name, Carbon.Year, SUM(Carbon.Sequestration) FROM Forests FULL OUTER JOIN Carbon ON Forests.Fid = Carbon.Fid WHERE Forests.Country = 'India' GROUP BY Carbon.Year, Forests.Name;
|
What is the average monthly sales amount per sales representative for the first half of the year?
|
CREATE TABLE sales (rep_id INT,date DATE,sales FLOAT); INSERT INTO sales (rep_id,date,sales) VALUES (1,'2021-01-01',500),(1,'2021-02-01',600),(1,'2021-03-01',700),(1,'2021-04-01',800),(1,'2021-05-01',900),(1,'2021-06-01',1000),(2,'2021-01-01',400),(2,'2021-02-01',500),(2,'2021-03-01',600),(2,'2021-04-01',700),(2,'2021-05-01',800),(2,'2021-06-01',900);
|
SELECT rep_id, AVG(sales) as avg_monthly_sales FROM sales WHERE date BETWEEN '2021-01-01' AND '2021-06-30' GROUP BY rep_id;
|
How many AI-powered chatbot users are there in the customer_support table?
|
CREATE TABLE customer_support (customer_id INT,name VARCHAR(50),email VARCHAR(50),used_ai_chatbot BOOLEAN);
|
SELECT COUNT(*) FROM customer_support WHERE used_ai_chatbot = TRUE;
|
How many volunteers engaged in programs in Q1 of 2022?
|
CREATE TABLE volunteers (volunteer_id INT,volunteer_name VARCHAR(50),program_id INT,volunteer_date DATE); CREATE TABLE programs (program_id INT,program_name VARCHAR(50));
|
SELECT COUNT(DISTINCT volunteer_id) FROM volunteers WHERE QUARTER(volunteer_date) = 1 AND YEAR(volunteer_date) = 2022;
|
What was the total prize money awarded in the last three Men's Tennis Grand Slams?
|
CREATE TABLE tennis_gs (tournament VARCHAR(50),year INT,prize_money INT); INSERT INTO tennis_gs VALUES ('Australian Open',2021,62000000),('French Open',2021,44000000),('Wimbledon',2021,41900000),('US Open',2021,57700000);
|
SELECT SUM(prize_money) FROM tennis_gs WHERE tournament IN ('Australian Open', 'French Open', 'Wimbledon') AND year >= 2019;
|
What are the total sales of cosmetic products in the database?
|
CREATE TABLE products (product_id INT,product_name VARCHAR(100),sales INT); INSERT INTO products VALUES (1,'Mascara',5000),(2,'Lipstick',7000),(3,'Foundation',6000);
|
SELECT SUM(sales) FROM products;
|
What is the maximum budget for any public works project?
|
CREATE TABLE PublicWorksB(id INT,project VARCHAR(30),budget DECIMAL(10,2)); INSERT INTO PublicWorksB(id,project,budget) VALUES (1,'Highway Construction',800000.00),(2,'Airport Expansion',3000000.00);
|
SELECT MAX(budget) FROM PublicWorksB;
|
Find the total carbon offset by project in Florida
|
CREATE TABLE carbon_offset_programs (project_id INT,state VARCHAR(20),carbon_offsets FLOAT); INSERT INTO carbon_offset_programs (project_id,state,carbon_offsets) VALUES (1,'Florida',1200.5),(2,'California',1800.75),(3,'Florida',2500.33);
|
SELECT project_id, SUM(carbon_offsets) FROM carbon_offset_programs WHERE state = 'Florida' GROUP BY project_id;
|
What is the total number of crimes reported in the city of Houston in the year 2019 and 2020?
|
CREATE TABLE public.crime_statistics (id serial PRIMARY KEY,city varchar(255),year int,num_crimes int); INSERT INTO public.crime_statistics (city,year,num_crimes) VALUES ('Houston',2019,30000),('Houston',2020,35000);
|
SELECT SUM(num_crimes) FROM public.crime_statistics WHERE city = 'Houston' AND (year = 2019 OR year = 2020);
|
Add a new record for 'Assistive Listening Devices' program with a budget of $60,000 in the 'Disability Services' department.
|
CREATE TABLE budget (dept VARCHAR(50),program VARCHAR(50),amount INT);
|
INSERT INTO budget (dept, program, amount) VALUES ('Disability Services', 'Assistive Listening Devices', 60000);
|
What is the distribution of community health workers by their years of experience, partitioned by the languages they speak?
|
CREATE TABLE community_health_workers (worker_id INT,name VARCHAR(255),location VARCHAR(255),language VARCHAR(255),years_experience INT); INSERT INTO community_health_workers (worker_id,name,location,language,years_experience) VALUES (1,'Ana Flores','Los Angeles,CA','Spanish',10),(2,'Han Kim','Seattle,WA','Korean',7),(3,'Leila Nguyen','Houston,TX','Vietnamese',12);
|
SELECT worker_id, language, years_experience, COUNT(*) OVER(PARTITION BY language, years_experience) as count FROM community_health_workers;
|
How many garments are made of each material?
|
CREATE TABLE GarmentMaterials (id INT,garment_id INT,material VARCHAR(20));CREATE TABLE Garments (id INT,name VARCHAR(50)); INSERT INTO GarmentMaterials (id,garment_id,material) VALUES (1,1001,'organic_cotton'),(2,1002,'recycled_polyester'),(3,1003,'organic_cotton'),(4,1004,'hemp'),(5,1005,'organic_cotton'); INSERT INTO Garments (id,name) VALUES (1001,'Eco T-Shirt'),(1002,'Green Sweater'),(1003,'Circular Hoodie'),(1004,'Hemp Shirt'),(1005,'Ethical Jacket');
|
SELECT material, COUNT(DISTINCT garment_id) as garment_count FROM GarmentMaterials GROUP BY material;
|
What is the total billing amount for clients in the 'toronto' region?
|
CREATE TABLE clients (id INT,name TEXT,region TEXT,billing_amount DECIMAL(10,2)); INSERT INTO clients (id,name,region,billing_amount) VALUES (1,'David','toronto',500.00),(2,'Ella','toronto',600.00),(3,'Fiona','toronto',700.00);
|
SELECT SUM(billing_amount) FROM clients WHERE region = 'toronto';
|
Who are the Indigenous artisans from Africa specializing in pottery?
|
CREATE TABLE Artisans (ArtisanID INT PRIMARY KEY,Name VARCHAR(100),Specialty VARCHAR(50),Nation VARCHAR(50)); INSERT INTO Artisans (ArtisanID,Name,Specialty,Nation) VALUES (1,'Fatu Koroma','Pottery','Sierra Leone'),(2,'Ali Omar','Weaving','Somalia');
|
SELECT Name FROM Artisans WHERE Specialty = 'Pottery' AND Nation = 'Africa';
|
Find the total production quantity for well 'W2' in January 2021
|
CREATE TABLE production (well_id VARCHAR(2),date DATE,quantity FLOAT); INSERT INTO production (well_id,date,quantity) VALUES ('W1','2021-01-01',100.0),('W1','2021-01-02',120.0),('W2','2021-01-01',150.0);
|
SELECT SUM(quantity) FROM production WHERE well_id = 'W2' AND date >= '2021-01-01' AND date < '2021-02-01';
|
How many 'road_sections' are there in 'Rural' locations?
|
CREATE TABLE road_sections (id INT,section_name VARCHAR(50),location VARCHAR(50)); INSERT INTO road_sections (id,section_name,location) VALUES (1,'Section 1','Urban'),(2,'Section 2','Rural'),(3,'Section 3','Urban');
|
SELECT COUNT(*) FROM road_sections WHERE location = 'Rural';
|
Show the number of security incidents for each severity level in the last month.
|
CREATE TABLE incident_severity (id INT,incident_count INT,severity VARCHAR(50),incident_date DATE); INSERT INTO incident_severity (id,incident_count,severity,incident_date) VALUES (1,12,'Low','2022-03-01'),(2,20,'Medium','2022-03-02'),(3,30,'High','2022-03-03');
|
SELECT severity, SUM(incident_count) as total_incidents FROM incident_severity WHERE incident_date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH) GROUP BY severity;
|
What is the safety rating of the product named "Aloe Vera Lotion" from the brand "PureNature"?
|
CREATE TABLE product_safety_records (id INT PRIMARY KEY,product_id INT,safety_rating INT,last_inspection_date DATE); INSERT INTO product_safety_records (id,product_id,safety_rating,last_inspection_date) VALUES (1,1,5,'2021-06-15'); CREATE TABLE products (id INT PRIMARY KEY,name TEXT,brand TEXT); INSERT INTO products (id,name,brand) VALUES (1,'Aloe Vera Lotion','PureNature');
|
SELECT safety_rating FROM product_safety_records WHERE product_id = (SELECT id FROM products WHERE name = 'Aloe Vera Lotion' AND brand = 'PureNature')
|
What is the total humanitarian assistance budget for Oceania countries in 2021?
|
CREATE TABLE humanitarian_assistance_oceania (country VARCHAR(50),year INT,budget INT); INSERT INTO humanitarian_assistance_oceania (country,year,budget) VALUES ('Australia',2021,1200000),('New Zealand',2021,1100000),('Papua New Guinea',2021,900000);
|
SELECT SUM(budget) total_budget FROM humanitarian_assistance_oceania WHERE country IN ('Australia', 'New Zealand', 'Papua New Guinea') AND year = 2021;
|
What is the total budget allocated for healthcare and education services in 2020?
|
CREATE SCHEMA gov_schema;CREATE TABLE gov_schema.budget_allocation (year INT,service VARCHAR(20),amount INT);INSERT INTO gov_schema.budget_allocation (year,service,amount) VALUES (2020,'Healthcare',20000000),(2020,'Education',15000000);
|
SELECT SUM(amount) FROM gov_schema.budget_allocation WHERE year = 2020 AND (service = 'Healthcare' OR service = 'Education');
|
Who is the customer with the highest spending on vegan dishes?
|
CREATE TABLE customers (customer_id INT,customer_name VARCHAR(50)); INSERT INTO customers VALUES (1,'James Doe'),(2,'Jane Smith'),(3,'Alice Johnson'); CREATE TABLE orders (order_id INT,customer_id INT,menu_id INT,order_date DATE,total_cost DECIMAL(5,2)); INSERT INTO orders VALUES (1,1,1,'2022-01-01',25.00),(2,2,3,'2022-01-02',18.50),(3,3,2,'2022-01-03',12.50),(4,1,4,'2022-01-04',32.00); CREATE TABLE menu (menu_id INT,item_name VARCHAR(50),is_vegan BOOLEAN,price DECIMAL(5,2)); INSERT INTO menu VALUES (1,'Veggie Burger',true,8.99),(2,'Cheeseburger',false,7.99),(3,'Tofu Stir Fry',true,11.99),(4,'Quinoa Salad',true,9.01);
|
SELECT customers.customer_name, SUM(orders.total_cost) as total_spent FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id INNER JOIN menu ON orders.menu_id = menu.menu_id WHERE menu.is_vegan = true GROUP BY customers.customer_name ORDER BY total_spent DESC LIMIT 1;
|
What is the average sale value per equipment type?
|
CREATE TABLE Military_Equipment_Sales(id INT,sale_date DATE,country VARCHAR(50),equipment_type VARCHAR(50),sale_value FLOAT); INSERT INTO Military_Equipment_Sales(id,sale_date,country,equipment_type,sale_value) VALUES (1,'2020-01-01','USA','Naval',70000000);
|
SELECT equipment_type, AVG(sale_value) FROM Military_Equipment_Sales GROUP BY equipment_type;
|
What is the maximum budget for a bioprocess engineering project in each country?
|
CREATE TABLE bioprocess_engineering(id INT,project VARCHAR(50),country VARCHAR(50),budget DECIMAL(10,2)); INSERT INTO bioprocess_engineering VALUES (1,'ProjectA','USA',3000000.00),(2,'ProjectB','Canada',5000000.00),(3,'ProjectC','Mexico',4000000.00);
|
SELECT country, MAX(budget) FROM bioprocess_engineering GROUP BY country;
|
What is the minimum production rate for wells in the Marcellus Shale?
|
CREATE TABLE well_prod (well_name VARCHAR(50),location VARCHAR(50),rate FLOAT); INSERT INTO well_prod (well_name,location,rate) VALUES ('Well A','Marcellus Shale',1200),('Well B','Marcellus Shale',1800);
|
SELECT MIN(rate) FROM well_prod WHERE location = 'Marcellus Shale';
|
Calculate the average depth of all marine protected areas.
|
CREATE TABLE marine_protected_areas (name TEXT,location TEXT,avg_depth REAL); INSERT INTO marine_protected_areas (name,location,avg_depth) VALUES ('Galapagos Islands Marine Reserve','Ecuador','2500'),('Great Barrier Reef Marine Park','Australia','180');
|
SELECT AVG(avg_depth) FROM marine_protected_areas;
|
What is the average budget for accessible technology projects launched in 2022?
|
CREATE TABLE access_tech (name TEXT,budget INTEGER,launch_year INTEGER,accessible TEXT); INSERT INTO access_tech (name,budget,launch_year,accessible) VALUES ('AccTech1',500000,2022,'yes'),('AccTech2',600000,2022,'yes'),('AccTech3',400000,2021,'no');
|
SELECT AVG(budget) FROM access_tech WHERE launch_year = 2022 AND accessible = 'yes';
|
What is the energy efficiency of the top 3 countries in Asia?
|
CREATE TABLE energy_efficiency_asia (id INT,country VARCHAR(255),efficiency FLOAT); INSERT INTO energy_efficiency_asia (id,country,efficiency) VALUES (1,'Japan',0.35),(2,'China',0.32),(3,'South Korea',0.31),(4,'India',0.29);
|
SELECT country, efficiency FROM energy_efficiency_asia ORDER BY efficiency DESC LIMIT 3;
|
Show total hours billed and total billing amount for each attorney in 'billing' table
|
CREATE TABLE billing (attorney_id INT,client_id INT,hours_billed INT,billing_rate DECIMAL(5,2));
|
SELECT attorney_id, SUM(hours_billed), SUM(hours_billed * billing_rate) FROM billing GROUP BY attorney_id;
|
How many cases were opened by each attorney in 2020?
|
CREATE TABLE attorneys (attorney_id INT,name VARCHAR(50),start_date DATE); INSERT INTO attorneys (attorney_id,name,start_date) VALUES (1,'John Doe','2020-01-01'); INSERT INTO attorneys (attorney_id,name,start_date) VALUES (2,'Jane Smith','2019-06-15'); CREATE TABLE cases (case_id INT,attorney_id INT,open_date DATE); INSERT INTO cases (case_id,attorney_id,open_date) VALUES (1,1,'2020-01-01'); INSERT INTO cases (case_id,attorney_id,open_date) VALUES (2,2,'2020-02-15'); INSERT INTO cases (case_id,attorney_id,open_date) VALUES (3,1,'2019-12-31');
|
SELECT attorney_id, COUNT(case_id) as cases_opened FROM cases WHERE YEAR(open_date) = 2020 GROUP BY attorney_id;
|
What is the average age of farmers in the 'farmers' table?
|
CREATE TABLE farmers (id INT,name VARCHAR(50),age INT,location VARCHAR(50)); INSERT INTO farmers (id,name,age,location) VALUES (1,'John Doe',45,'Ruralville'); INSERT INTO farmers (id,name,age,location) VALUES (2,'Jane Smith',50,'Farmtown');
|
SELECT AVG(age) FROM farmers;
|
Find the total number of digital assets issued in the US and their respective names
|
CREATE TABLE DigitalAssets (name VARCHAR(255),country VARCHAR(255)); INSERT INTO DigitalAssets (name,country) VALUES ('Asset1','USA'),('Asset2','Canada');
|
SELECT SUM(CASE WHEN country = 'USA' THEN 1 ELSE 0 END) as total_assets, name FROM DigitalAssets WHERE country = 'USA';
|
Calculate the percentage change in production for each site, compared to the previous month.
|
CREATE TABLE production (site_id INT,production_date DATE,quantity INT);
|
SELECT site_id, production_date, (LAG(quantity) OVER (PARTITION BY site_id ORDER BY production_date) - quantity) * 100.0 / LAG(quantity) OVER (PARTITION BY site_id ORDER BY production_date) as pct_change FROM production;
|
What is the total fare revenue for the subway system in the last quarter?
|
CREATE TABLE SubwayFares (FareID INT,TripID INT,Fare FLOAT);
|
SELECT SUM(Fare) FROM SubwayFares JOIN TrainTrips ON SubwayFares.TripID = TrainTrips.TripID WHERE TrainTrips.TripDate >= DATEADD(QUARTER, -1, GETDATE());
|
What is the average age of soccer players in the English Premier League?
|
CREATE TABLE epl_players (player_id INT,player_name VARCHAR(50),team_id INT,team_name VARCHAR(50),age INT); INSERT INTO epl_players (player_id,player_name,team_id,team_name,age) VALUES (1,'Harry Kane',1,'Tottenham Hotspur',29),(2,'Mohamed Salah',2,'Liverpool',30),(3,'Virgil van Dijk',2,'Liverpool',31);
|
SELECT AVG(age) FROM epl_players;
|
What is the total donation amount for each donor type in the last quarter?
|
CREATE TABLE Donations (DonationID INT,DonorID INT,DonationDate DATE,DonationAmount DECIMAL(10,2),DonorType VARCHAR(50)); CREATE VIEW DonorTypes AS SELECT DISTINCT DonorType FROM Donations;
|
SELECT dt.DonorType, SUM(d.DonationAmount) FROM Donations d JOIN DonorTypes dt ON d.DonorType = dt.DonorType WHERE d.DonationDate >= DATEADD(quarter, -1, GETDATE()) GROUP BY dt.DonorType;
|
What is the total runtime of TV shows produced by 'Diverse Producers' in 2018 and 2019?
|
CREATE TABLE tv_shows (id INT,title VARCHAR(255),runtime_minutes INT,production_year INT,producer VARCHAR(255)); INSERT INTO tv_shows (id,title,runtime_minutes,production_year,producer) VALUES (1,'Show1',420,2018,'Diverse Producers'); INSERT INTO tv_shows (id,title,runtime_minutes,production_year,producer) VALUES (2,'Show2',300,2019,'Diverse Producers'); INSERT INTO tv_shows (id,title,runtime_minutes,production_year,producer) VALUES (3,'Show3',450,2018,'Other Producers');
|
SELECT SUM(runtime_minutes) FROM tv_shows WHERE production_year BETWEEN 2018 AND 2019 AND producer = 'Diverse Producers';
|
Determine the percentage of sales revenue for products that are labeled 'cruelty-free', considering only sales from the past month.
|
CREATE TABLE SalesDataCrueltyFree (sale_id INT,product_id INT,sale_date DATE,sale_revenue FLOAT,is_cruelty_free BOOLEAN); INSERT INTO SalesDataCrueltyFree (sale_id,product_id,sale_date,sale_revenue,is_cruelty_free) VALUES (1,1,'2022-01-02',75,true),(2,2,'2022-01-15',30,false),(3,3,'2022-01-28',60,false),(4,4,'2022-01-10',120,true),(5,5,'2022-01-22',45,false);
|
SELECT (SUM(sale_revenue) / (SELECT SUM(sale_revenue) FROM SalesDataCrueltyFree WHERE sale_date >= DATEADD(month, -1, GETDATE()))) * 100 as revenue_percentage FROM SalesDataCrueltyFree WHERE is_cruelty_free = true AND sale_date >= DATEADD(month, -1, GETDATE());
|
What is the distribution of audience members by age group, for events held in New York City, in the past year?
|
CREATE TABLE Events (id INT,city VARCHAR(50),date DATE); INSERT INTO Events (id,city,date) VALUES (1,'New York City','2021-05-01'),(2,'Los Angeles','2021-05-02'); CREATE TABLE Audience (id INT,event_id INT,age_group VARCHAR(20)); INSERT INTO Audience (id,event_id,age_group) VALUES (1,1,'18-24'),(2,1,'25-34'),(3,2,'35-44');
|
SELECT e.city, a.age_group, COUNT(a.id) AS count FROM Events e INNER JOIN Audience a ON e.id = a.event_id WHERE e.city = 'New York City' AND e.date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY e.city, a.age_group;
|
What is the total fare collected for each route in the 'routes' table?
|
CREATE TABLE routes (route_id INT,route_name VARCHAR(255),length FLOAT,fare FLOAT);
|
SELECT route_name, SUM(fare) as total_fare FROM routes GROUP BY route_name;
|
What is the total number of peacekeeping missions led by each country, and the average duration of these missions, for countries that have led more than 5 missions, ordered by the average mission duration in descending order?
|
CREATE TABLE Countries(CountryID INT,CountryName TEXT); CREATE TABLE PeacekeepingMissions(MissionID INT,MissionName TEXT,CountryID INT,StartDate DATE,EndDate DATE);
|
SELECT CountryName, COUNT(MissionID) as NumMissions, AVG(DATEDIFF(EndDate, StartDate)) as AvgMissionDuration FROM PeacekeepingMissions JOIN Countries ON PeacekeepingMissions.CountryID = Countries.CountryID GROUP BY CountryName HAVING NumMissions > 5 ORDER BY AvgMissionDuration DESC;
|
What are the unique severity levels in the 'incidents' table?
|
CREATE TABLE incidents (incident_id INT,region VARCHAR(50),severity VARCHAR(10)); INSERT INTO incidents (incident_id,region,severity) VALUES (1,'region_1','medium'),(2,'region_2','high'),(3,'region_3','high'),(4,'region_1','low'),(5,'region_3','medium');
|
SELECT DISTINCT severity FROM incidents;
|
What is the average attendance at workshops held in the last year?
|
CREATE TABLE attendance (id INT,workshop_date DATE,num_attendees INT); INSERT INTO attendance (id,workshop_date,num_attendees) VALUES (1,'2021-01-01',25),(2,'2021-02-15',30),(3,'2021-03-10',20),(4,'2022-04-01',35);
|
SELECT AVG(num_attendees) as avg_attendance FROM attendance WHERE workshop_date >= DATEADD(year, -1, GETDATE());
|
Update the open date of the 'Topaz Twilight' mine in Nunavut, Canada
|
CREATE TABLE mining_operations (id INT PRIMARY KEY,mine_name VARCHAR(255),location VARCHAR(255),resource VARCHAR(255),open_date DATE);
|
UPDATE mining_operations SET open_date = '2022-03-15' WHERE mine_name = 'Topaz Twilight';
|
List the names of ports where the Ever Ace has docked.
|
CREATE TABLE Ports (PortID INT,PortName VARCHAR(100),City VARCHAR(100),Country VARCHAR(100)); INSERT INTO Ports (PortID,PortName,City,Country) VALUES (1,'Port of Los Angeles','Los Angeles','USA'); INSERT INTO Ports (PortID,PortName,City,Country) VALUES (2,'Port of Rotterdam','Rotterdam','Netherlands'); CREATE TABLE Vessels (VesselID INT,VesselName VARCHAR(100),VesselType VARCHAR(100),PortID INT); INSERT INTO Vessels (VesselID,VesselName,VesselType,PortID) VALUES (1,'Ever Ace','Container Ship',1);
|
SELECT Ports.PortName FROM Ports INNER JOIN Vessels ON Ports.PortID = Vessels.PortID WHERE Vessels.VesselName = 'Ever Ace';
|
Update the monthly cost of the "Premium" mobile plan to 70.00
|
CREATE TABLE mobile_plans (plan_id INT,plan_name VARCHAR(255),monthly_cost DECIMAL(10,2)); INSERT INTO mobile_plans (plan_id,plan_name,monthly_cost) VALUES (1,'Basic',30.00),(2,'Premium',60.00);
|
UPDATE mobile_plans SET monthly_cost = 70.00 WHERE plan_name = 'Premium';
|
Show the number of food safety inspections and the percentage of inspections with violations for restaurants in Texas, for the last 6 months.
|
CREATE TABLE Inspections (InspectionID INT,RestaurantID INT,InspectionDate DATETIME,ViolationCount INT);
|
SELECT RestaurantID, COUNT(*) OVER (PARTITION BY RestaurantID) as TotalInspections, (COUNT(*) FILTER (WHERE ViolationCount > 0) OVER (PARTITION BY RestaurantID) * 100.0 / COUNT(*) OVER (PARTITION BY RestaurantID)) as ViolationPercentage FROM Inspections WHERE RestaurantID IN (SELECT RestaurantID FROM Restaurants WHERE State = 'Texas') AND InspectionDate > CURRENT_DATE - INTERVAL '6 months';
|
Which country has the lowest total zinc production, China or India?
|
CREATE TABLE zinc_production (country VARCHAR(20),quantity INT); INSERT INTO zinc_production (country,quantity) VALUES ('China',3000),('India',2500);
|
SELECT country, MIN(quantity) FROM zinc_production WHERE country IN ('China', 'India') GROUP BY country;
|
What is the total amount of research grants awarded to the Department of Physics in the last 5 years?
|
CREATE TABLE department (id INT,name VARCHAR(255),college VARCHAR(255));CREATE TABLE grant (id INT,department_id INT,title VARCHAR(255),amount DECIMAL(10,2),year INT);
|
SELECT SUM(amount) FROM grant g JOIN department d ON g.department_id = d.id WHERE d.name = 'Department of Physics' AND g.year >= YEAR(CURDATE()) - 5;
|
What is the average energy savings of smart city projects in Barcelona, Spain?
|
CREATE TABLE smart_city_projects (id INT,project_name VARCHAR(50),city VARCHAR(50),country VARCHAR(50),energy_savings FLOAT); INSERT INTO smart_city_projects (id,project_name,city,country,energy_savings) VALUES (1,'Barcelona Smart Grid','Barcelona','Spain',15.2);
|
SELECT AVG(energy_savings) FROM smart_city_projects WHERE city = 'Barcelona' AND country = 'Spain';
|
What is the minimum production cost for a garment made from hemp?
|
CREATE TABLE HempProduction (id INT,garment_type VARCHAR(255),cost DECIMAL(10,2)); INSERT INTO HempProduction (id,garment_type,cost) VALUES (1,'T-Shirt',15.50),(2,'Pants',25.00),(3,'Dress',55.99);
|
SELECT MIN(cost) FROM HempProduction WHERE garment_type IN ('T-Shirt', 'Pants', 'Dress');
|
What is the total number of smart city technology projects in the city of Vancouver, Canada, that have a status of 'Active' or 'In Progress'?
|
CREATE TABLE smart_city_projects (id INT PRIMARY KEY,project_name VARCHAR(255),city VARCHAR(255),country VARCHAR(255),status VARCHAR(255));
|
SELECT COUNT(*) FROM smart_city_projects WHERE city = 'Vancouver' AND country = 'Canada' AND (status = 'Active' OR status = 'In Progress');
|
Show the top 3 destinations with the highest increase in tourists from 2018 to 2019
|
CREATE TABLE tourism_stats (destination VARCHAR(255),year INT,visitors INT); INSERT INTO tourism_stats (destination,year,visitors) VALUES ('Japan',2018,13000000),('Japan',2019,15000000),('Canada',2018,21000000),('Canada',2019,23000000),('France',2018,22000000),('France',2019,24000000),('City A',2018,500000),('City A',2019,700000),('City B',2018,800000),('City B',2019,1000000);
|
SELECT destination, (visitors - (SELECT visitors FROM tourism_stats t2 WHERE t2.destination = t1.destination AND t2.year = 2018)) AS diff FROM tourism_stats t1 WHERE year = 2019 ORDER BY diff DESC LIMIT 3;
|
List all factories in countries with a high percentage of sustainable textile sourcing, ordered alphabetically by factory name.
|
CREATE TABLE Factories (FactoryID int,FactoryName varchar(50),Country varchar(50)); INSERT INTO Factories (FactoryID,FactoryName,Country) VALUES (1,'EcoFactory','Bangladesh'); INSERT INTO Factories (FactoryID,FactoryName,Country) VALUES (2,'GreenManufacturing','India'); CREATE TABLE Sourcing (FactoryID int,SustainableSourcePercentage decimal(5,2)); INSERT INTO Sourcing (FactoryID,SustainableSourcePercentage) VALUES (1,0.85); INSERT INTO Sourcing (FactoryID,SustainableSourcePercentage) VALUES (2,0.90);
|
SELECT f.FactoryName FROM Factories f INNER JOIN Sourcing s ON f.FactoryID = s.FactoryID WHERE s.SustainableSourcePercentage >= 0.80 GROUP BY f.FactoryName ORDER BY f.FactoryName ASC;
|
List all space exploration missions conducted by the European Space Agency since 2010.
|
CREATE TABLE SpaceMissions (mission_id INT,agency VARCHAR(255),year INT,mission_name VARCHAR(255));
|
SELECT mission_name FROM SpaceMissions WHERE agency = 'European Space Agency' AND year >= 2010;
|
What is the production rate trend for well 'Well Z' in the past 90 days?
|
CREATE TABLE wells (well_id INT,well_name VARCHAR(255),well_type VARCHAR(255),location VARCHAR(255)); INSERT INTO wells VALUES (1,'Well Z','Offshore','Gulf of Mexico');
|
SELECT production_rate, date FROM (SELECT production_rate, date, row_number() OVER (ORDER BY date DESC) as rn FROM well_production WHERE well_name = 'Well Z' AND date >= CURRENT_DATE - INTERVAL '90 days' ORDER BY date DESC) WHERE rn <= 90;
|
Find the number of unique cruelty-free beauty products and the number of unique organic beauty products, and then identify the products that are both cruelty-free and organic.
|
CREATE TABLE Products (product_id INT,product_name TEXT,is_cruelty_free BOOLEAN,is_organic BOOLEAN); INSERT INTO Products (product_id,product_name,is_cruelty_free,is_organic) VALUES (1,'Product A',true,false),(2,'Product B',true,true),(3,'Product C',false,true),(4,'Product D',false,false);
|
SELECT COUNT(DISTINCT product_id) as cruelty_free_count FROM Products WHERE is_cruelty_free = true; SELECT COUNT(DISTINCT product_id) as organic_count FROM Products WHERE is_organic = true; SELECT product_id FROM Products WHERE is_cruelty_free = true AND is_organic = true;
|
Find carriers sharing the same country with carriers having reverse logistics contracts?
|
CREATE TABLE Carrier (CarrierID INT,CarrierName TEXT,Country TEXT); INSERT INTO Carrier (CarrierID,CarrierName,Country) VALUES (1,'Global Logistics','USA'),(2,'Canada Shipping','Canada'),(3,'Oceanic Freight','Australia'); CREATE TABLE Contract (ContractID INT,CarrierID INT,ContractType TEXT); INSERT INTO Contract (ContractID,CarrierID,ContractType) VALUES (1,1,'Freight'),(2,2,'Freight'),(3,1,'ReverseLogistics');
|
SELECT DISTINCT c1.CarrierName, c1.Country FROM Carrier c1 JOIN Carrier c2 ON c1.Country = c2.Country WHERE c2.CarrierID IN (SELECT CarrierID FROM Contract WHERE ContractType = 'ReverseLogistics');
|
List the top 3 states with the highest water usage in wastewater treatment plants?
|
CREATE TABLE Wastewater_Plant (id INT,state VARCHAR(20),water_usage FLOAT); INSERT INTO Wastewater_Plant (id,state,water_usage) VALUES (1,'California',12000.0),(2,'Texas',9000.0),(3,'Florida',8000.0),(4,'California',15000.0),(5,'New_York',7000.0);
|
SELECT state, water_usage FROM Wastewater_Plant ORDER BY water_usage DESC LIMIT 3;
|
What is the average budget of biotech startups in Africa?
|
CREATE TABLE biotech_startups (id INT,name VARCHAR(50),budget DECIMAL(10,2),region VARCHAR(50)); INSERT INTO biotech_startups (id,name,budget,region) VALUES (1,'Genetix',5000000.00,'Africa'); INSERT INTO biotech_startups (id,name,budget,region) VALUES (2,'BioEngineerz',7000000.00,'USA'); INSERT INTO biotech_startups (id,name,budget,region) VALUES (3,'SensoraBio',6000000.00,'Germany');
|
SELECT AVG(budget) FROM biotech_startups WHERE region = 'Africa';
|
How many defense projects in the Middle East have exceeded their budget by more than 15%?
|
CREATE TABLE projects (id INT,name VARCHAR(255),region VARCHAR(255),budget DECIMAL(10,2),actual_cost DECIMAL(10,2)); INSERT INTO projects (id,name,region,budget,actual_cost) VALUES (1,'Project A','Middle East',10000000.00,11500000.00),(2,'Project B','Middle East',20000000.00,18000000.00),(3,'Project C','Middle East',15000000.00,16500000.00),(4,'Project D','Middle East',25000000.00,27500000.00);
|
SELECT COUNT(*) as num_exceeded_budget FROM projects WHERE region = 'Middle East' AND actual_cost > (budget * 1.15);
|
What is the maximum and minimum capacity of energy storage projects completed in California in 2021?
|
CREATE TABLE energy_storage (id INT,project TEXT,location TEXT,year INT,capacity FLOAT,status TEXT); INSERT INTO energy_storage (id,project,location,year,capacity,status) VALUES (1,'Los Angeles Energy Storage','California',2021,50.0,'completed'),(2,'San Diego Energy Storage','California',2021,75.0,'in progress');
|
SELECT MAX(capacity) as max_capacity, MIN(capacity) as min_capacity FROM energy_storage WHERE location = 'California' AND year = 2021 AND status = 'completed';
|
List all Mars rovers and their launch dates.
|
CREATE TABLE rovers (name VARCHAR(50),mission_name VARCHAR(50),launch_date DATE); INSERT INTO rovers (name,mission_name,launch_date) VALUES ('Sojourner','Mars Pathfinder','1996-12-04'),('Spirit','Mars Exploration Rover','2003-06-10'),('Opportunity','Mars Exploration Rover','2003-07-07'),('Curiosity','Mars Science Laboratory','2011-11-26'),('Perseverance','Mars 2020','2020-07-30');
|
SELECT name, launch_date FROM rovers;
|
What is the maximum revenue for restaurants with a seating capacity of 50 or less?
|
CREATE TABLE Restaurants (restaurant_id INT,name VARCHAR(255),seating_capacity INT,revenue DECIMAL(10,2)); INSERT INTO Restaurants (restaurant_id,name,seating_capacity,revenue) VALUES (1,'Restaurant A',75,5000.00),(2,'Restaurant B',50,6000.00),(3,'Restaurant C',25,4000.00);
|
SELECT MAX(revenue) FROM Restaurants WHERE seating_capacity <= 50;
|
What is the total number of hotels and the total number of virtual tours in the database?
|
CREATE TABLE hotels (hotel_id INT,name VARCHAR(50),category VARCHAR(20),rating DECIMAL(2,1)); INSERT INTO hotels (hotel_id,name,category,rating) VALUES (1,'The Urban Chic','boutique',4.5),(2,'The Artistic Boutique','boutique',4.7),(3,'The Cozy Inn','budget',4.2); CREATE TABLE virtual_tours (tour_id INT,hotel_id INT,title VARCHAR(50),duration INT); INSERT INTO virtual_tours (tour_id,hotel_id,title,duration) VALUES (1,1,'Virtual Tour: The Urban Chic Lobby',15),(2,1,'Virtual Tour: The Urban Chic Rooms',30),(3,2,'Virtual Tour: The Artistic Boutique Lobby',10),(4,3,'Virtual Tour: The Cozy Inn Rooms',20);
|
SELECT COUNT(*) FROM hotels; SELECT COUNT(*) FROM virtual_tours;
|
List all cultural heritage sites in Italy, France, and Greece.
|
CREATE TABLE sites (id INT,country VARCHAR(50),type VARCHAR(50)); INSERT INTO sites (id,country,type) VALUES (1,'Italy','Cultural'),(2,'Spain','Cultural'),(3,'France','Natural'),(4,'Greece','Cultural');
|
SELECT * FROM sites WHERE country IN ('Italy', 'France', 'Greece') AND type = 'Cultural';
|
How many physicians specialize in pediatrics in hospitals in rural areas of California?
|
CREATE TABLE hospitals (id INT,name VARCHAR(50),state VARCHAR(25),num_physicians INT,location VARCHAR(20),specialty VARCHAR(50)); INSERT INTO hospitals (id,name,state,num_physicians,location,specialty) VALUES (1,'Hospital A','California',50,'rural','pediatrics'),(2,'Hospital B','California',30,'urban','internal medicine'),(3,'Hospital C','California',75,'rural','general surgery');
|
SELECT COUNT(*) FROM hospitals WHERE location = 'rural' AND state = 'California' AND specialty = 'pediatrics';
|
What is the average number of publications per faculty member in the Humanities department?
|
CREATE TABLE faculty (id INT,name VARCHAR(50),department VARCHAR(50),position VARCHAR(50)); INSERT INTO faculty (id,name,department,position) VALUES (1,'Gina Wilson','Humanities','Professor'); INSERT INTO faculty (id,name,department,position) VALUES (2,'Harry Moore','Humanities','Assistant Professor'); CREATE TABLE publications (id INT,faculty_id INT,title VARCHAR(100)); INSERT INTO publications (id,faculty_id,title) VALUES (1,1,'Publication A'); INSERT INTO publications (id,faculty_id,title) VALUES (2,1,'Publication B'); INSERT INTO publications (id,faculty_id,title) VALUES (3,2,'Publication C');
|
SELECT AVG(num_publications) FROM (SELECT f.id, COUNT(p.id) as num_publications FROM faculty f LEFT JOIN publications p ON f.id = p.faculty_id WHERE f.department = 'Humanities' GROUP BY f.id) t;
|
What is the minimum temperature required for each chemical in storage?
|
CREATE TABLE chemicals (chemical_id INT,name VARCHAR(255)); CREATE TABLE storage_temperatures (temperature_id INT,chemical_id INT,min_temp DECIMAL(5,2)); INSERT INTO chemicals (chemical_id,name) VALUES (1,'Chemical A'),(2,'Chemical B'); INSERT INTO storage_temperatures (temperature_id,chemical_id,min_temp) VALUES (1,1,15.0),(2,1,14.5),(3,2,10.0),(4,2,9.5);
|
SELECT c.name, MIN(st.min_temp) as min_temp FROM storage_temperatures st JOIN chemicals c ON st.chemical_id = c.chemical_id GROUP BY c.name;
|
What is the average fuel consumption rate for vessels in the Caribbean Sea, grouped by vessel type and year?
|
CREATE TABLE vessels (id INT,name TEXT,type TEXT,fuel_capacity FLOAT,gps_position TEXT); CREATE TABLE gps_positions (id INT,latitude FLOAT,longitude FLOAT,country TEXT,year INT,distance_traveled FLOAT);
|
SELECT v.type, v.year, AVG(v.fuel_capacity / g.distance_traveled) FROM vessels v JOIN gps_positions g ON v.gps_position = g.id WHERE g.country = 'Caribbean Sea' GROUP BY v.type, v.year;
|
List all claims and their corresponding claim types, along with the policy type, for policyholder ID 4?
|
CREATE TABLE Claims (ClaimID INT,PolicyholderID INT,ClaimType VARCHAR(20),PolicyType VARCHAR(20)); INSERT INTO Claims (ClaimID,PolicyholderID,ClaimType,PolicyType) VALUES (1,4,'Theft','Auto'),(2,4,'Fire','Home'),(3,5,'Accident','Auto');
|
SELECT Claims.ClaimID, Claims.ClaimType, Policyholders.PolicyType FROM Claims INNER JOIN Policyholders ON Claims.PolicyholderID = Policyholders.PolicyholderID WHERE Policyholders.PolicyholderID = 4;
|
Insert new records of public schools and colleges in the state of California into the corresponding tables.
|
CREATE TABLE public_schools(id INT,name VARCHAR(100),school_type VARCHAR(50),address VARCHAR(200),state VARCHAR(50));CREATE TABLE colleges(id INT,name VARCHAR(100),school_type VARCHAR(50),address VARCHAR(200),state VARCHAR(50));
|
INSERT INTO public_schools (name, school_type, address, state) VALUES ('Oakland Elementary School', 'Elementary', '123 Main St, Oakland, CA', 'California'), ('San Francisco Community College', 'Community College', '456 Market St, San Francisco, CA', 'California');INSERT INTO colleges (name, school_type, address, state) VALUES ('Berkeley College of Arts', 'College of Arts', '789 University Ave, Berkeley, CA', 'California'), ('Stanford University', 'University', '100 Serra Mall, Stanford, CA', 'California');
|
What was the average gift size in Canada?
|
CREATE TABLE donations (id INT,country TEXT,amount DECIMAL(10,2)); INSERT INTO donations (id,country,amount) VALUES (1,'USA',100.00),(2,'Canada',50.50),(3,'USA',200.00),(4,'Canada',150.25);
|
SELECT AVG(amount) FROM donations WHERE country = 'Canada';
|
Get the 'algorithm' and 'recall' values for records with 'precision' < 0.85 in the 'evaluation_data2' table
|
CREATE TABLE evaluation_data2 (id INT,algorithm VARCHAR(20),precision DECIMAL(3,2),recall DECIMAL(3,2)); INSERT INTO evaluation_data2 (id,algorithm,precision,recall) VALUES (1,'Random Forest',0.92,0.85),(2,'XGBoost',0.75,0.87),(3,'Naive Bayes',0.88,0.83);
|
SELECT algorithm, recall FROM evaluation_data2 WHERE precision < 0.85;
|
Find the top 3 industries with the highest total funding for companies that have had at least 2 investment rounds, ordered by the total funding in descending order.
|
CREATE TABLE Companies (id INT,name TEXT,industry TEXT,total_funding FLOAT,num_investments INT); INSERT INTO Companies (id,name,industry,total_funding,num_investments) VALUES (1,'Acme Inc','Software',2500000,2),(2,'Beta Corp','Software',5000000,1),(3,'Gamma Startup','Hardware',1000000,1);
|
SELECT industry, SUM(total_funding) AS industry_funding FROM Companies WHERE num_investments >= 2 GROUP BY industry ORDER BY industry_funding DESC LIMIT 3;
|
What is the average maintenance cost for military aircraft?
|
CREATE TABLE aircraft (id INT,model VARCHAR(50),maintenance_cost FLOAT); INSERT INTO aircraft (id,model,maintenance_cost) VALUES (1,'F-16',35000),(2,'F-35',42000),(3,'A-10',28000);
|
SELECT AVG(maintenance_cost) FROM aircraft;
|
List all community health workers, their ages, and corresponding states.
|
CREATE TABLE CommunityHealthWorkers (ID INT,Name VARCHAR(50),Age INT,State VARCHAR(50)); INSERT INTO CommunityHealthWorkers (ID,Name,Age,State) VALUES (1,'John Doe',35,'California'); INSERT INTO CommunityHealthWorkers (ID,Name,Age,State) VALUES (2,'Jane Smith',40,'Florida');
|
SELECT Name, Age, State FROM CommunityHealthWorkers;
|
What is the percentage of mobile subscribers who are using 4G or higher networks in each state?
|
CREATE TABLE mobile_subscribers (subscriber_id int,network_type varchar(10),state varchar(20)); INSERT INTO mobile_subscribers (subscriber_id,network_type,state) VALUES (1,'4G','WA'),(2,'3G','NY'),(3,'5G','IL'); CREATE TABLE network_types (network_type varchar(10),description varchar(20)); INSERT INTO network_types (network_type,description) VALUES ('2G','2G Network'),('3G','3G Network'),('4G','4G Network'),('5G','5G Network');
|
SELECT state, 100.0 * SUM(CASE WHEN network_type IN ('4G', '5G') THEN 1 ELSE 0 END) / COUNT(*) as percentage FROM mobile_subscribers GROUP BY state;
|
Update the 'num_passengers' column in the 'public_transit' table for the 'route_id' 42 to 50
|
CREATE TABLE public_transit (route_id INT,num_passengers INT,route_type VARCHAR(255),route_length FLOAT);
|
UPDATE public_transit SET num_passengers = 50 WHERE route_id = 42;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.