instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Add a new decentralized application (dApp) to the database with the name 'Olympus' and the category 'DeFi'.
CREATE TABLE dapps (id INT,name TEXT,category TEXT);
INSERT INTO dapps (name, category) VALUES ('Olympus', 'DeFi');
What is the percentage of wastewater treated in the month of March across all treatment plants?
CREATE TABLE wastewater_treatment(plant_id INT,treated_volume FLOAT,month DATE); INSERT INTO wastewater_treatment(plant_id,treated_volume,month) VALUES (1,10000,'2022-03-01'),(2,15000,'2022-03-01'),(3,12000,'2022-03-01');
SELECT 100.0 * SUM(treated_volume) / (SELECT SUM(treated_volume) FROM wastewater_treatment WHERE month = '2022-03-01') AS percentage FROM wastewater_treatment WHERE month = '2022-03-01';
What is the maximum playtime in a single session for each player?
CREATE TABLE PlayerMaxSessions (PlayerID int,MaxPlaytime int); INSERT INTO PlayerMaxSessions (PlayerID,MaxPlaytime) VALUES (1,90),(2,75),(3,80);
SELECT P.PlayerName, MAX(PMS.MaxPlaytime) as MaxPlaytime FROM Players P JOIN PlayerMaxSessions PMS ON P.PlayerID = PMS.PlayerID;
What is the average temperature change in the Arctic per decade for each month?
CREATE TABLE weather (year INT,month INT,avg_temp FLOAT); INSERT INTO weather
SELECT (year - year % 10) / 10 AS decade, month, AVG(avg_temp) FROM weather GROUP BY decade, month HAVING COUNT(*) > 36;
What is the average data usage for postpaid mobile customers in the Midwest region?
CREATE TABLE customers(id INT,type VARCHAR(10),region VARCHAR(10)); INSERT INTO customers VALUES (1,'postpaid','Midwest'); CREATE TABLE usage(customer_id INT,data_usage INT);
SELECT AVG(usage.data_usage) FROM usage JOIN customers ON usage.customer_id = customers.id WHERE customers.type = 'postpaid' AND customers.region = 'Midwest';
What is the percentage of community health workers who are bilingual by state?
CREATE TABLE community_health_workers (id INT PRIMARY KEY,state VARCHAR(20),worker_count INT,bilingual_worker_count INT); INSERT INTO community_health_workers (id,state,worker_count,bilingual_worker_count) VALUES (1,'California',100,60),(2,'Texas',200,80);
SELECT state, AVG(bilingual_worker_count::float / worker_count * 100.0) AS percentage FROM community_health_workers GROUP BY state;
What is the highest property tax in San Francisco?
CREATE TABLE tax_rates (id INT,city TEXT,state TEXT,property_type TEXT,rate FLOAT);
SELECT MAX(rate) FROM tax_rates WHERE city = 'San Francisco' AND property_type = 'Residential';
What is the earliest and latest launch date for each country's space missions?
CREATE TABLE space_missions (id INT,country VARCHAR(255),launch_date DATE);
SELECT country, MIN(launch_date) as earliest_launch, MAX(launch_date) as latest_launch FROM space_missions GROUP BY country;
Find the average age of patients with influenza in Texas?
CREATE TABLE patients (id INT,name TEXT,age INT,disease TEXT,state TEXT); INSERT INTO patients (id,name,age,disease,state) VALUES (1,'John Doe',35,'influenza','Texas'),(2,'Jane Smith',42,'common cold','California');
SELECT AVG(age) FROM patients WHERE disease = 'influenza' AND state = 'Texas';
What is the average speed of electric vehicles by make?
CREATE TABLE ElectricVehicles (Make VARCHAR(50),Model VARCHAR(50),Year INT,AverageSpeed DECIMAL(5,2));
SELECT Make, AVG(AverageSpeed) AS AvgSpeed FROM ElectricVehicles GROUP BY Make;
List all trainings and the number of employees who attended each.
CREATE TABLE trainings (id INT,name VARCHAR(255));CREATE TABLE training_attendees (employee_id INT,training_id INT);
SELECT t.name, COUNT(a.employee_id) AS attendees FROM trainings t LEFT JOIN training_attendees a ON t.id = a.training_id GROUP BY t.name;
What is the maximum ticket price for Latin concerts in October?
CREATE TABLE Concerts (id INT,genre VARCHAR(20),price DECIMAL(5,2)); INSERT INTO Concerts (id,genre,price) VALUES (1,'Latin',180.00),(2,'Reggae',130.00),(3,'Latin',220.00);
SELECT MAX(price) FROM Concerts WHERE genre = 'Latin' AND date BETWEEN '2022-10-01' AND '2022-10-31';
How many movies were released per year in India?
CREATE TABLE movie (id INT PRIMARY KEY,title VARCHAR(255),year INT,country VARCHAR(255)); INSERT INTO movie (id,title,year,country) VALUES (1,'MovieA',2000,'India'),(2,'MovieB',2005,'India'),(3,'MovieC',2003,'India'),(4,'MovieD',2001,'India'),(5,'MovieE',2002,'India');
SELECT year, COUNT(id) AS movies_released FROM movie GROUP BY year;
What is the average CO2 emission of vehicles by manufacturer, for manufacturers with more than 50 vehicles sold?
CREATE TABLE Vehicles (Id INT,Manufacturer VARCHAR(255),CO2Emission INT,VehiclesSold INT); INSERT INTO Vehicles VALUES (1,'Toyota',120,75),(2,'Honda',110,60),(3,'Ford',150,85),(4,'Tesla',0,100);
SELECT Manufacturer, AVG(CO2Emission) as Avg_Emission FROM (SELECT Manufacturer, CO2Emission, ROW_NUMBER() OVER (PARTITION BY Manufacturer ORDER BY VehiclesSold DESC) as rn FROM Vehicles) t WHERE rn <= 1 GROUP BY Manufacturer;
What are the details of unsustainable suppliers from Africa?
CREATE TABLE suppliers (id INT,name VARCHAR(255),country VARCHAR(255),ethical_rating DECIMAL(3,1)); INSERT INTO suppliers (id,name,country,ethical_rating) VALUES (5,'African Cotton Inc','Nigeria',3.2); INSERT INTO suppliers (id,name,country,ethical_rating) VALUES (6,'Kente Weavers','Ghana',3.8);
SELECT name, country, ethical_rating FROM suppliers WHERE ethical_rating < 4.0 AND country LIKE 'Africa%';
What is the average streaming revenue per artist by genre in the United States?
CREATE TABLE artists (artist_id INT,artist_name VARCHAR(100),genre VARCHAR(50),country VARCHAR(50),revenue DECIMAL(10,2)); INSERT INTO artists (artist_id,artist_name,genre,country,revenue) VALUES (1,'Taylor Swift','Pop','USA',1500000); INSERT INTO artists (artist_id,artist_name,genre,country,revenue) VALUES (2,'BTS','K...
SELECT genre, AVG(revenue) as avg_revenue FROM artists WHERE country = 'USA' GROUP BY genre;
What is the average age of readers who prefer sports news from the "New York Times" database?
CREATE TABLE readers (id INT,name TEXT,age INT,preference TEXT); INSERT INTO readers (id,name,age,preference) VALUES (1,'Alice',35,'sports'); INSERT INTO readers (id,name,age,preference) VALUES (2,'Bob',42,'politics'); INSERT INTO readers (id,name,age,preference) VALUES (3,'Charlie',28,'sports');
SELECT AVG(age) FROM readers WHERE preference = 'sports';
What is the minimum energy efficiency rating for smart city initiatives in Italy?
CREATE TABLE SmartCities (city_id INT,city_name VARCHAR(255),country VARCHAR(255),energy_efficiency_rating FLOAT);
SELECT MIN(energy_efficiency_rating) FROM SmartCities WHERE country = 'Italy';
What is the percentage of fish biomass that is made up of each species in each farm, partitioned by month?
CREATE TABLE fish_farms (id INT,name VARCHAR(255)); INSERT INTO fish_farms (id,name) VALUES (1,'Farm A'),(2,'Farm B'),(3,'Farm C'); CREATE TABLE fish_inventory (id INT,farm_id INT,species_id INT,biomass FLOAT,date DATE); INSERT INTO fish_inventory (id,farm_id,species_id,biomass,date) VALUES (1,1,1,1000,'2021-01-01'),(2...
SELECT f.name, fi.species_id, DATE_TRUNC('month', fi.date) as month, 100.0 * SUM(fi.biomass) / (SELECT SUM(biomass) FROM fish_inventory WHERE farm_id = fi.farm_id AND DATE_TRUNC('month', date) = DATE_TRUNC('month', fi.date)) as pct_biomass FROM fish_inventory fi JOIN fish_farms f ON fi.farm_id = f.id GROUP BY f.name, f...
What is the failure rate of aircraft engines by manufacturer?
CREATE TABLE Aircraft_Engine_Failure (ID INT,Manufacturer VARCHAR(20),Failure_Rate DECIMAL(5,2)); INSERT INTO Aircraft_Engine_Failure (ID,Manufacturer,Failure_Rate) VALUES (1,'Pratt & Whitney',0.01),(2,'Rolls-Royce',0.02),(3,'General Electric',0.03);
SELECT Manufacturer, Failure_Rate FROM Aircraft_Engine_Failure;
Which network technologies were most frequently invested in for broadband infrastructure from 2018 to 2020?
CREATE TABLE broadband_infrastructure (investment_year INT,technology VARCHAR(50)); INSERT INTO broadband_infrastructure (investment_year,technology) VALUES (2018,'Fiber Optic'),(2019,'Cable'),(2020,'5G');
SELECT technology, COUNT(*) FROM broadband_infrastructure WHERE investment_year BETWEEN 2018 AND 2020 GROUP BY technology;
Who were the top 5 most active users (based on post count) in the 'Europe' region for the month of March 2021?
CREATE TABLE posts (post_id INT,user_id INT,post_date DATE); CREATE TABLE users (user_id INT,name VARCHAR(255),region VARCHAR(255)); INSERT INTO posts (post_id,user_id,post_date) VALUES (1,1,'2021-03-01'); INSERT INTO users (user_id,name,region) VALUES (1,'Maria','Europe');
SELECT users.name, COUNT(*) as post_count FROM posts JOIN users ON posts.user_id = users.user_id WHERE users.region = 'Europe' AND post_date >= '2021-03-01' AND post_date < '2021-04-01' GROUP BY users.name ORDER BY post_count DESC LIMIT 5;
What is the total number of policies by policyholder state?
CREATE TABLE policyholder_state (policyholder_id INT,policyholder_state VARCHAR(20)); CREATE TABLE policies (policy_id INT,policyholder_id INT); INSERT INTO policyholder_state VALUES (1,'California'); INSERT INTO policies VALUES (1,1);
SELECT policyholder_state, COUNT(*) as total_policies FROM policies JOIN policyholder_state ON policies.policyholder_id = policyholder_state.policyholder_id GROUP BY policyholder_state;
How many mental health conditions are recorded in the database?
CREATE TABLE Conditions (ConditionID int,Condition varchar(50)); INSERT INTO Conditions (ConditionID,Condition) VALUES (1,'Anxiety'),(2,'Depression');
SELECT COUNT(*) FROM Conditions;
What is the minimum timber volume in African forests?
CREATE TABLE forests (id INT,country VARCHAR(255),region VARCHAR(255),timber_volume FLOAT);
SELECT MIN(timber_volume) FROM forests WHERE region = 'Africa';
What is the total square footage of buildings in the city of Houston?
CREATE TABLE building_info (info_id INT,sq_footage INT,city TEXT,sustainable BOOLEAN); INSERT INTO building_info VALUES (1,50000,'Houston',FALSE),(2,60000,'Houston',FALSE),(3,70000,'Seattle',TRUE),(4,40000,'New York',FALSE);
SELECT SUM(sq_footage) FROM building_info WHERE city = 'Houston';
Who are the data scientists for projects in the 'ethical AI' sector?
CREATE TABLE employees (employee_id INT,name VARCHAR(50),position VARCHAR(50)); INSERT INTO employees (employee_id,name,position) VALUES (1,'Greg','Project Manager'); INSERT INTO employees (employee_id,name,position) VALUES (2,'Hannah','Data Scientist'); INSERT INTO employees (employee_id,name,position) VALUES (3,'Ivan...
SELECT name FROM employees INNER JOIN projects ON employees.employee_id = projects.data_scientist WHERE projects.sector = 'ethical AI';
Military tech budget changes in 2019
CREATE TABLE budget_changes (year INT,budget_change FLOAT);
SELECT year, budget_change FROM budget_changes WHERE year = 2019;
What is the average age of employees in the HR database who have completed diversity training?
CREATE TABLE hr_database (id INT,employee_id INT,age INT,training_completed TEXT); INSERT INTO hr_database (id,employee_id,age,training_completed) VALUES (1,101,35,'Diversity'),(2,102,40,'Inclusion'),(3,103,32,'None');
SELECT AVG(age) as avg_age FROM hr_database WHERE training_completed = 'Diversity';
What is the average depth of marine protected areas with a conservation status of 'Least Concern'?
CREATE TABLE marine_protected_areas (id INT,name VARCHAR(255),area_size FLOAT,avg_depth FLOAT,conservation_status VARCHAR(100)); INSERT INTO marine_protected_areas (id,name,area_size,avg_depth,conservation_status) VALUES (1,'Great Barrier Reef',344400,-200,'Least Concern'),(2,'Galapagos Marine Reserve',133000,-300,'End...
SELECT AVG(avg_depth) FROM marine_protected_areas WHERE conservation_status = 'Least Concern';
How many space missions have been successful or unsuccessful, with a percentage breakdown?
CREATE TABLE mission_outcomes (mission_name VARCHAR(50),mission_status VARCHAR(10)); INSERT INTO mission_outcomes (mission_name,mission_status) VALUES ('Voyager 1','Success'),('Voyager 2','Success'),('Cassini','Success'),('Galileo','Success'),('New Horizons','Success'),('Mars Climate Orbiter','Failure'),('Mars Polar La...
SELECT 'Success' AS mission_status, COUNT(*) AS num_missions, (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM mission_outcomes)) AS percentage FROM mission_outcomes WHERE mission_status = 'Success' UNION ALL SELECT 'Failure', COUNT(*), (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM mission_outcomes)) FROM mission_outcomes WHERE m...
What is the average number of community development initiatives in Rwanda and Uganda that received funding in 2021?
CREATE TABLE Community_Development (Project_ID INT,Project_Name TEXT,Location TEXT,Funding_Received DECIMAL,Year INT); INSERT INTO Community_Development (Project_ID,Project_Name,Location,Funding_Received,Year) VALUES (1,'Clean Water Initiative','Rwanda',25000,2021),(2,'Education Support','Uganda',30000,2021);
SELECT AVG(Funding_Received) FROM Community_Development WHERE Year = 2021 AND Location IN ('Rwanda', 'Uganda');
What is the total number of orders shipped to the United States that contain eco-friendly materials?
CREATE TABLE orders (id INT,order_value DECIMAL(10,2),eco_friendly BOOLEAN,country VARCHAR(50)); INSERT INTO orders (id,order_value,eco_friendly,country) VALUES (1,150.50,TRUE,'USA'),(2,75.20,FALSE,'Canada'),(3,225.00,TRUE,'USA');
SELECT COUNT(*) FROM orders WHERE eco_friendly = TRUE AND country = 'USA';
What is the average amount of grant money received per project by women-led organizations in the agricultural innovation sector in Kenya?
CREATE TABLE agricultural_innovations (id INT,organization_name TEXT,sector TEXT,country TEXT,grant_amount DECIMAL(10,2)); INSERT INTO agricultural_innovations (id,organization_name,sector,country,grant_amount) VALUES (1,'FarmHer Kenya','Agriculture','Kenya',5000.00),(2,'Green Innovations','Agriculture','Kenya',8000.00...
SELECT AVG(grant_amount) FROM agricultural_innovations WHERE country = 'Kenya' AND sector = 'Agriculture' AND organization_name IN (SELECT organization_name FROM agricultural_innovations WHERE organization_name LIKE '%women%');
What is the total quantity of each product sold by month?
CREATE TABLE sales_by_month (product_id INT,sale_month DATE,quantity INT); INSERT INTO sales_by_month (product_id,sale_month,quantity) VALUES (1,'2021-01-01',50),(1,'2021-02-01',75),(2,'2021-01-01',100),(3,'2021-03-01',25);
SELECT EXTRACT(MONTH FROM sale_month) AS month, product_id, SUM(quantity) AS total_quantity FROM sales_by_month GROUP BY month, product_id;
Find the number of wheelchair-accessible buses per depot.
CREATE TABLE depot (depot_id INT,depot_name TEXT);CREATE TABLE bus (bus_id INT,depot_id INT,is_wheelchair_accessible BOOLEAN); INSERT INTO depot (depot_id,depot_name) VALUES (1,'DepotA'),(2,'DepotB'),(3,'DepotC'); INSERT INTO bus (bus_id,depot_id,is_wheelchair_accessible) VALUES (1,1,true),(2,1,false),(3,2,true),(4,2,f...
SELECT d.depot_name, COUNT(b.bus_id) as wheelchair_accessible_buses FROM depot d JOIN bus b ON d.depot_id = b.depot_id WHERE b.is_wheelchair_accessible = true GROUP BY d.depot_name;
How many artists from underrepresented communities have had solo exhibitions in New York in the last 5 years?
CREATE TABLE exhibitions_artists (id INT,city VARCHAR(20),year INT,type VARCHAR(10),community VARCHAR(20)); INSERT INTO exhibitions_artists (id,city,year,type,community) VALUES (1,'Tokyo',2017,'modern art','Asian'),(2,'Tokyo',2018,'modern art','Asian'),(3,'Paris',2018,'modern art','European'),(4,'London',2018,'modern a...
SELECT COUNT(*) FROM exhibitions_artists WHERE city = 'New York' AND community IN ('African American', 'Latinx', 'Native American') AND year BETWEEN 2017 AND 2021 AND type = 'modern art';
How many projects are in the 'renewable_energy' table?
CREATE TABLE renewable_energy (id INT,project_name VARCHAR(50),location VARCHAR(50),cost FLOAT); INSERT INTO renewable_energy (id,project_name,location,cost) VALUES (1,'Solar Farm','Miami',10000000); INSERT INTO renewable_energy (id,project_name,location,cost) VALUES (2,'Wind Farm','Seattle',6000000);
SELECT COUNT(*) FROM renewable_energy;
What is the distribution of audience members by age group, for events held at the 'Art Gallery'?
CREATE TABLE ArtGallery (event_id INT,event_name VARCHAR(50),event_date DATE,age_group VARCHAR(20));
SELECT age_group, COUNT(*) FROM ArtGallery GROUP BY age_group;
What are the names and transaction dates of all transactions that occurred in the United States or Canada?
CREATE TABLE transactions (id INT,transaction_date DATE,country VARCHAR(255),amount DECIMAL(10,2)); INSERT INTO transactions (id,transaction_date,country,amount) VALUES (1,'2022-01-01','USA',100.00),(2,'2022-01-02','Canada',200.00),(3,'2022-01-03','USA',300.00);
SELECT country, transaction_date FROM transactions WHERE country IN ('USA', 'Canada');
Delete the record for the animal 'Duck' from the 'Wetlands' habitat.
CREATE TABLE animals (id INT,animal_name VARCHAR(255),habitat_type VARCHAR(255)); INSERT INTO animals (id,animal_name,habitat_type) VALUES (1,'Lion','Savannah'),(2,'Elephant','Forest'),(3,'Hippo','Wetlands'),(4,'Giraffe','Savannah'),(5,'Duck','Wetlands'),(6,'Bear','Mountains');
DELETE FROM animals WHERE animal_name = 'Duck' AND habitat_type = 'Wetlands';
Identify the total revenue generated from 'Halal' beauty products in the past year.
CREATE TABLE sales (sale_id INT,product_id INT,sale_amount DECIMAL,sale_date DATE); CREATE TABLE products (product_id INT,product_name TEXT,category TEXT,interested_in_halal BOOLEAN); INSERT INTO sales (sale_id,product_id,sale_amount,sale_date) VALUES (1,1,50.00,'2022-01-01'),(2,1,40.00,'2022-01-15'),(3,2,30.00,'2022-0...
SELECT SUM(sale_amount) FROM sales JOIN products ON sales.product_id = products.product_id WHERE products.interested_in_halal = true AND sales.sale_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) AND CURRENT_DATE;
How many skincare products were sold in the USA in Q2 of 2022?
CREATE TABLE sales (id INT,product_name VARCHAR(50),quantity INT,sale_date DATE); INSERT INTO sales (id,product_name,quantity,sale_date) VALUES (1,'Cleanser',450,'2022-04-05'),(2,'Toner',300,'2022-07-10'),(3,'Moisturizer',500,'2022-05-22');
SELECT COUNT(*) FROM sales WHERE product_name LIKE '%Skincare%' AND sale_date BETWEEN '2022-04-01' AND '2022-06-30';
Insert a new record for a program 'Youth Mentoring' with a start date of Jan 1, 2023 and an end date of Dec 31, 2023 into the 'Programs' table
CREATE TABLE Programs (ProgramID INT,ProgramName VARCHAR(50),StartDate DATE,EndDate DATE);
INSERT INTO Programs (ProgramID, ProgramName, StartDate, EndDate) VALUES (1, 'Youth Mentoring', '2023-01-01', '2023-12-31');
Which ocean has the lowest average sea surface temperature?'
CREATE TABLE ocean_temperatures (ocean TEXT,avg_temp FLOAT); INSERT INTO ocean_temperatures (ocean,avg_temp) VALUES ('Pacific',28.0); INSERT INTO ocean_temperatures (ocean,avg_temp) VALUES ('Atlantic',27.5); INSERT INTO ocean_temperatures (ocean,avg_temp) VALUES ('Arctic',0.0);
SELECT ocean, MIN(avg_temp) FROM ocean_temperatures;
What is the average travel distance to the nearest hospital in urban and rural areas?
CREATE TABLE hospitals (id INT,area VARCHAR(10),location POINT); INSERT INTO hospitals (id,area,location) VALUES (1,'urban',ST_Point(0,0)); INSERT INTO hospitals (id,area,location) VALUES (2,'rural',ST_Point(10,10)); INSERT INTO hospitals (id,area,location) VALUES (3,'urban',ST_Point(20,20)); INSERT INTO hospitals (id,...
SELECT AVG(ST_Distance(location, ST_MakePoint(0, 0))) FROM hospitals WHERE area = 'urban'; SELECT AVG(ST_Distance(location, ST_MakePoint(0, 0))) FROM hospitals WHERE area = 'rural';
Identify the top 3 agricultural innovations with the highest investment amounts.
CREATE TABLE agri_innovations (id INT,innovation_name VARCHAR(255),investment_amount FLOAT); INSERT INTO agri_innovations (id,innovation_name,investment_amount) VALUES (1,'Precision Agriculture',500000),(2,'Drip Irrigation',350000),(3,'Vertical Farming',700000);
SELECT innovation_name, investment_amount FROM agri_innovations ORDER BY investment_amount DESC LIMIT 3;
Which suppliers have manufactured equipment for projects in Africa?
CREATE TABLE Suppliers (id INT,supplier_name VARCHAR(255),location VARCHAR(255),supplier_type VARCHAR(255)); CREATE TABLE Equipment (id INT,equipment_type VARCHAR(255),manufacturer VARCHAR(255),production_year INT,supplier_id INT); CREATE TABLE Projects (id INT,project_name VARCHAR(255),start_date DATE,end_date DATE,re...
SELECT DISTINCT Suppliers.supplier_name FROM Suppliers INNER JOIN Equipment ON Suppliers.id = Equipment.supplier_id INNER JOIN Projects ON Equipment.id = Projects.id WHERE Projects.region = 'Africa';
What is the average salary of developers who have worked on accessible technology projects?
CREATE TABLE developers(id INT,name TEXT,salary FLOAT,project TEXT); INSERT INTO developers(id,name,salary,project) VALUES (1,'Alice',70000.0,'Accessible Tech'); INSERT INTO developers(id,name,salary,project) VALUES (2,'Bob',75000.0,'Accessible Tech'); INSERT INTO developers(id,name,salary,project) VALUES (3,'Charlie',...
SELECT AVG(salary) FROM developers WHERE project = 'Accessible Tech';
What is the average purchase amount for in-game items by players from the United States?
CREATE TABLE players (id INT,country VARCHAR(255)); INSERT INTO players (id,country) VALUES (1,'United States'),(2,'Canada'); CREATE TABLE in_game_purchases (id INT,player_id INT,amount DECIMAL(5,2)); INSERT INTO in_game_purchases (id,player_id,amount) VALUES (1,1,10.50),(2,1,12.25),(3,2,5.00);
SELECT AVG(amount) FROM in_game_purchases igp JOIN players p ON igp.player_id = p.id WHERE p.country = 'United States';
What is the minimum response time for emergency calls in each district?
CREATE TABLE emergency_calls (call_id INT,district TEXT,response_time FLOAT); INSERT INTO emergency_calls (call_id,district,response_time) VALUES (1,'Downtown',10.5),(2,'Uptown',12.0),(3,'Harbor',8.0);
SELECT district, MIN(response_time) FROM emergency_calls GROUP BY district;
Display the total population of sharks and dolphins from the 'MarineLife' table
CREATE TABLE MarineLife (id INT PRIMARY KEY,species VARCHAR(255),population INT);
SELECT SUM(population) FROM MarineLife WHERE species IN ('shark', 'dolphin');
Add a new record to the 'military_equipment' table for each of the following: equipment_id 789, equipment_type 'tanks', country 'Russia', in_service true
CREATE TABLE military_equipment (equipment_id INT PRIMARY KEY,equipment_type VARCHAR(20),country VARCHAR(20),in_service BOOLEAN);
INSERT INTO military_equipment (equipment_id, equipment_type, country, in_service) VALUES (789, 'tanks', 'Russia', true);
Find the number of virtual tours in Japan with a duration over 30 minutes.
CREATE TABLE tours (id INT,country VARCHAR(20),duration INT); INSERT INTO tours (id,country,duration) VALUES (1,'Japan',60),(2,'Japan',20),(3,'Italy',30);
SELECT COUNT(*) FROM tours WHERE country = 'Japan' AND duration > 30;
What are the names of playlists that have at least 3 songs?
CREATE VIEW playlist_songs_count AS SELECT playlist_id,COUNT(song_id) AS songs_count FROM playlist_songs GROUP BY playlist_id; CREATE VIEW playlists_3_songs AS SELECT * FROM playlist_songs_count WHERE songs_count >= 3; CREATE TABLE playlists_detailed (playlist_id INT,playlist_name VARCHAR(50)); INSERT INTO playlists_de...
SELECT playlist_name FROM playlists_detailed JOIN playlists_3_songs ON playlists_detailed.playlist_id = playlists_3_songs.playlist_id;
What is the total number of satellites launched by SpaceX?
CREATE TABLE satellites_launched (id INT,company VARCHAR(50),num_satellites INT);INSERT INTO satellites_launched (id,company,num_satellites) VALUES (1,'SpaceX',2500);
SELECT SUM(num_satellites) FROM satellites_launched WHERE company = 'SpaceX';
What is the number of companies founded by women, per city, in the last year?
CREATE TABLE companies (id INT,name TEXT,city TEXT,founder_gender TEXT,founding_date DATE); INSERT INTO companies (id,name,city,founder_gender,founding_date) VALUES (1,'Acme Inc','San Francisco','Female','2022-01-01'),(2,'Beta Corp','San Francisco','Male','2021-01-01'),(3,'Gamma Inc','New York','Female','2022-01-01'),(...
SELECT city, COUNT(*) FROM companies WHERE founder_gender = 'Female' AND founding_date >= (CURRENT_DATE - INTERVAL '1 year') GROUP BY city;
Which day of the week has the highest number of orders for vegan meals?
CREATE TABLE Dates (DateID int,OrderDate date); INSERT INTO Dates VALUES (1,'2022-01-01'),(2,'2022-01-02'),(3,'2022-01-03'),(4,'2022-01-04'),(5,'2022-01-05'); CREATE TABLE Orders (OrderID int,DateID int,IsVegan bit); INSERT INTO Orders VALUES (1,1,1),(2,2,0),(3,3,1),(4,4,1),(5,5,0);
SELECT DATENAME(dw, OrderDate) AS DayOfWeek, COUNT(*) AS NumberOfOrders FROM Orders JOIN Dates ON Orders.DateID = Dates.DateID WHERE IsVegan = 1 GROUP BY DATENAME(dw, OrderDate) ORDER BY NumberOfOrders DESC;
What is the average TV show viewership rating by network?
CREATE TABLE tv_ratings (id INT,show TEXT,network TEXT,rating FLOAT); INSERT INTO tv_ratings (id,show,network,rating) VALUES (1,'Show4','Network1',7.1); INSERT INTO tv_ratings (id,show,network,rating) VALUES (2,'Show5','Network2',8.5); INSERT INTO tv_ratings (id,show,network,rating) VALUES (3,'Show6','Network1',6.8);
SELECT network, AVG(rating) as avg_rating FROM tv_ratings GROUP BY network;
What is the minimum age of vessels for each vessel type?
CREATE TABLE vessel_details (id INT,vessel_id INT,age INT,type_id INT);
SELECT vt.name, MIN(vd.age) as min_age FROM vessel_details vd JOIN vessel_type vt ON vd.type_id = vt.id GROUP BY vt.name;
Show companies founded in 2018
CREATE TABLE startup (id INT,name TEXT,founding_year INT,founder_gender TEXT);
SELECT name FROM startup WHERE founding_year = 2018;
Insert a new record for a government employee in the state of California with the ID of 5 and the name of 'David Lee'.
CREATE TABLE employees (id INT,name VARCHAR(255),last_active DATE,state VARCHAR(255)); INSERT INTO employees (id,name,last_active,state) VALUES (1,'John Doe','2016-01-01','New York'),(2,'Jane Smith','2021-02-01','Florida'),(3,'Bob Johnson','2018-05-01','California');
INSERT INTO employees (id, name, last_active, state) VALUES (5, 'David Lee', NOW(), 'California');
Insert a new record into the "employees" table for a new employee named "Jamal Brown"
CREATE TABLE employees (id INT PRIMARY KEY,first_name VARCHAR(50),last_name VARCHAR(50),department VARCHAR(50),hire_date DATE);
INSERT INTO employees (id, first_name, last_name, department, hire_date) VALUES (1234, 'Jamal', 'Brown', 'Manufacturing', '2022-05-15');
What is the minimum and maximum calorie count for all dishes in the menu table?
CREATE TABLE menu (id INT,name TEXT,category TEXT,calories INT); INSERT INTO menu (id,name,category,calories) VALUES (1,'Chicken Alfredo','Entrée',1200); INSERT INTO menu (id,name,category,calories) VALUES (2,'Veggie Lasagna','Entrée',800); INSERT INTO menu (id,name,category,calories) VALUES (3,'Quinoa Salad','Side',40...
SELECT MIN(calories), MAX(calories) FROM menu;
List all vessels with more than 5 safety incidents since 2020-01-01
CREATE TABLE Inspections (id INT PRIMARY KEY,vessel_id INT,inspection_date DATE,result VARCHAR(255)); CREATE TABLE SafetyRecords (id INT PRIMARY KEY,vessel_id INT,incident_date DATE,description VARCHAR(255)); CREATE TABLE Vessels (id INT PRIMARY KEY,name VARCHAR(255));
SELECT Vessels.name FROM Vessels INNER JOIN SafetyRecords ON Vessels.id = SafetyRecords.vessel_id WHERE SafetyRecords.incident_date >= '2020-01-01' GROUP BY Vessels.name HAVING COUNT(SafetyRecords.id) > 5;
Count the number of threat intelligence alerts raised in the Asia-Pacific region in 2020
CREATE TABLE threat_intelligence (alert_id INT,region VARCHAR(50),date DATE,threat_level VARCHAR(50)); INSERT INTO threat_intelligence (alert_id,region,date,threat_level) VALUES (1,'Asia-Pacific','2020-03-12','High');
SELECT COUNT(*) FROM threat_intelligence WHERE region = 'Asia-Pacific' AND YEAR(date) = 2020;
Delete TV shows with release years before 2010.
CREATE TABLE tv_shows (show_id INT,title VARCHAR(100),release_year INT,rating FLOAT); INSERT INTO tv_shows (show_id,title,release_year,rating) VALUES (1,'Game of Thrones',2011,4.1),(2,'Friends',1994,4.6),(3,'Breaking Bad',2008,4.8);
DELETE FROM tv_shows WHERE release_year < 2010;
Find the total number of streams for songs released in 2010?
CREATE TABLE songs (song_id INT,song_name VARCHAR(50),release_year INT); INSERT INTO songs (song_id,song_name,release_year) VALUES (101,'Bad Romance',2010),(102,'Rolling in the Deep',2011),(103,'Empire State of Mind',2009); CREATE TABLE streams (stream_id INT,song_id INT,user_id INT); INSERT INTO streams (stream_id,son...
SELECT COUNT(*) as total_streams FROM streams JOIN songs ON streams.song_id = songs.song_id WHERE release_year = 2010;
Find the total length of underwater cables in the Mediterranean and Arctic Oceans.
CREATE TABLE underwater_cables (ocean_name TEXT,cable_length INT); INSERT INTO underwater_cables (ocean_name,cable_length) VALUES ('Mediterranean',3000),('Arctic',5000);
SELECT SUM(cable_length) FROM underwater_cables WHERE ocean_name IN ('Mediterranean', 'Arctic');
What is the total playtime for each player in January 2021?
CREATE TABLE player_daily_playtime (player_id INT,play_date DATE,playtime INT); INSERT INTO player_daily_playtime (player_id,play_date,playtime) VALUES (1,'2021-01-01',100),(1,'2021-01-02',200),(1,'2021-01-03',300),(2,'2021-01-01',400),(2,'2021-01-02',500),(2,'2021-01-03',600);
SELECT player_id, SUM(playtime) FROM player_daily_playtime WHERE play_date BETWEEN '2021-01-01' AND '2021-01-31' GROUP BY player_id;
What is the average salary for workers in unions that have collective bargaining agreements and are in the 'Construction' industry?
CREATE TABLE unions (id INT,industry VARCHAR(255),has_cba BOOLEAN); CREATE TABLE workers (id INT,union_id INT,salary DECIMAL(10,2));
SELECT AVG(workers.salary) FROM workers JOIN unions ON workers.union_id = unions.id WHERE unions.industry = 'Construction' AND unions.has_cba = TRUE;
What is the minimum order value for purchases made using a mobile device in the United Kingdom?
CREATE TABLE orders (id INT,order_value DECIMAL(10,2),device VARCHAR(20),country VARCHAR(50)); INSERT INTO orders (id,order_value,device,country) VALUES (1,150.50,'mobile','UK'),(2,75.20,'desktop','Canada'),(3,225.00,'mobile','UK');
SELECT MIN(order_value) FROM orders WHERE device = 'mobile' AND country = 'UK';
Identify restaurants that serve both sushi and pizza.
CREATE TABLE Restaurants (restaurant_id INT,name VARCHAR(255),cuisine VARCHAR(255)); INSERT INTO Restaurants (restaurant_id,name,cuisine) VALUES (1,'Pizzeria 123','Italian'),(2,'Sushi Bar','Japanese'),(3,'Mexican Grill','Mexican'),(4,'Sushi Pizza','Japanese,Italian');
SELECT name FROM Restaurants WHERE cuisine LIKE '%sushi%' INTERSECT SELECT name FROM Restaurants WHERE cuisine LIKE '%pizza%';
What was the revenue for 'DrugC' in each quarter of 2019?
CREATE TABLE revenue_by_quarter (drug_name TEXT,quarter INT,year INT,revenue FLOAT); INSERT INTO revenue_by_quarter (drug_name,quarter,year,revenue) VALUES ('DrugC',1,2019,1200000.0),('DrugC',2,2019,1400000.0);
SELECT drug_name, quarter, SUM(revenue) FROM revenue_by_quarter WHERE drug_name = 'DrugC' AND year = 2019 GROUP BY drug_name, quarter;
What is the most common therapy type?
CREATE TABLE therapy_sessions (id INT,patient_id INT,session_date DATE,therapy_type TEXT);
SELECT therapy_type, COUNT(*) AS session_count FROM therapy_sessions GROUP BY therapy_type ORDER BY session_count DESC LIMIT 1;
Which funding sources contributed to each program?
CREATE TABLE Funding (id INT,program VARCHAR(50),funding_source VARCHAR(50)); INSERT INTO Funding (id,program,funding_source) VALUES (1,'Youth Orchestra','City Grant'),(2,'Theater Production','Private Donation'),(3,'Workshop Series','Government Grant'),(4,'Youth Orchestra','Private Donation');
SELECT program, funding_source, COUNT(*) as contribution_count FROM Funding GROUP BY program, funding_source;
List all waste types
CREATE TABLE waste_types (id INT PRIMARY KEY,waste_type VARCHAR(255)); INSERT INTO waste_types (id,waste_type) VALUES (1,'Plastic'),(2,'Paper');
SELECT * FROM waste_types;
What is the average budget for language preservation programs in Southeast Asia?
CREATE TABLE language_preservation (id INT,region VARCHAR(20),budget DECIMAL(10,2)); INSERT INTO language_preservation (id,region,budget) VALUES (1,'Southeast Asia',50000.00),(2,'Africa',75000.00),(3,'South America',60000.00);
SELECT AVG(budget) FROM language_preservation WHERE region = 'Southeast Asia';
Delete satellites with missing International Designators from the satellites table
CREATE TABLE satellites (id INT,name VARCHAR(255),international_designator VARCHAR(20));
DELETE FROM satellites WHERE international_designator IS NULL;
Insert a new 'exploration' record for 'XYZ Oil' in the 'North Sea' dated '2022-01-01'
CREATE TABLE exploration (id INT PRIMARY KEY,operator TEXT,location TEXT,date DATE,result TEXT);
INSERT INTO exploration (operator, location, date, result) VALUES ('XYZ Oil', 'North Sea', '2022-01-01', 'Undetermined');
What is the total value of defense contracts for each quarter in the year 2022?
CREATE TABLE Contracts (ContractID INT,Contractor VARCHAR(50),Value DECIMAL(10,2),ContractDate DATE); INSERT INTO Contracts (ContractID,Contractor,Value,ContractDate) VALUES (1,'Boeing',50000000,'2022-01-15'),(2,'Lockheed Martin',70000000,'2022-04-02'),(3,'Northrop Grumman',90000000,'2022-07-10');
SELECT DATE_FORMAT(ContractDate, '%Y-%m') as Quarter, SUM(Value) as TotalValue FROM Contracts WHERE YEAR(ContractDate) = 2022 GROUP BY Quarter;
Which states have droughts in the last 6 months?
CREATE TABLE drought_info (state VARCHAR(2),drought_start_date DATE,drought_end_date DATE); INSERT INTO drought_info (state,drought_start_date,drought_end_date) VALUES ('CA','2022-01-01','2022-06-30'),('NV','2022-02-01','2022-06-30'),('AZ','2022-03-01','2022-06-30'),('NM','2022-04-01','2022-06-30');
SELECT d.state FROM drought_info d WHERE d.drought_start_date BETWEEN '2022-01-01' AND '2022-06-30' AND d.drought_end_date BETWEEN '2022-01-01' AND '2022-06-30';
What is the average price of silk garments sourced from India?
CREATE TABLE garments (id INT,price DECIMAL(5,2),material VARCHAR(20),country VARCHAR(20)); INSERT INTO garments (id,price,material,country) VALUES (1,50.00,'silk','India'); -- additional rows removed for brevity;
SELECT AVG(price) FROM garments WHERE material = 'silk' AND country = 'India';
What is the total revenue for restaurants serving Japanese cuisine?
CREATE TABLE Restaurants (RestaurantID int,CuisineType varchar(255),Revenue int); INSERT INTO Restaurants (RestaurantID,CuisineType,Revenue) VALUES (1,'Italian',5000),(2,'Mexican',6000),(3,'Indian',7000),(4,'Chinese',8000),(5,'French',9000),(6,'Thai',10000),(7,'Mediterranean',11000),(8,'Mediterranean',12000),(9,'Japane...
SELECT CuisineType, SUM(Revenue) FROM Restaurants WHERE CuisineType = 'Japanese' GROUP BY CuisineType;
What is the total number of public transportation stops in the city of New York, and what is the average distance between those stops?
CREATE TABLE stops (stop_name VARCHAR(255),stop_distance FLOAT,city VARCHAR(255));
SELECT AVG(stop_distance) FROM stops JOIN cities ON stops.city = cities.city_abbreviation WHERE cities.city_name = 'New York';
Create a table for health equity metrics by race
CREATE TABLE health_equity_race (id INT PRIMARY KEY,state VARCHAR(2),year INT,race VARCHAR(20),disparity_rate FLOAT);
CREATE TABLE if not exists health_equity_race_new AS SELECT * FROM health_equity_race WHERE FALSE;
List the names of the top 5 donors and their total contributions in the last 3 years.
CREATE TABLE Donors (donor_id INT,donor_name VARCHAR(50),donation_date DATE,amount INT); INSERT INTO Donors (donor_id,donor_name,donation_date,amount) VALUES (1,'John Doe','2021-01-01',100),(2,'Jane Smith','2020-01-01',50),(3,'Jim Brown','2019-01-01',200);
SELECT donor_name, SUM(amount) AS Total_Contributions FROM Donors D WHERE donation_date >= DATE(NOW()) - INTERVAL 3 YEAR GROUP BY donor_name ORDER BY Total_Contributions DESC LIMIT 5
Count the number of unique 'investors' in the 'ImpactInvestors' table.
CREATE TABLE ImpactInvestors (id INT,investor VARCHAR(255));
SELECT COUNT(DISTINCT investor) FROM ImpactInvestors;
What is the total amount of CO2 emissions in each Arctic country?
CREATE TABLE CO2Emissions (Country VARCHAR(50),Emissions INT); INSERT INTO CO2Emissions (Country,Emissions) VALUES ('Canada',550000),('United States',5000000),('Greenland',15000),('Finland',45000),('Norway',35000),('Sweden',55000),('Russia',1500000);
SELECT Country, SUM(Emissions) FROM CO2Emissions GROUP BY Country;
What is the percentage of users who are 30 years old or older?
CREATE TABLE users (id INT,age INT,gender TEXT); INSERT INTO users (id,age,gender) VALUES (1,25,'male'),(2,35,'non-binary'),(3,30,'female'),(4,45,'male'),(5,50,'non-binary'),(6,20,'male'),(7,40,'non-binary'),(8,33,'female'),(9,35,'male'),(10,60,'non-binary');
SELECT (COUNT(CASE WHEN age >= 30 THEN 1 END) * 100.0 / COUNT(*)) as percentage_over_30 FROM users;
What is the total revenue for the first quarter of 2022 by city?
CREATE TABLE gym_memberships (id INT,member_name VARCHAR(50),start_date DATE,end_date DATE,membership_type VARCHAR(50),price DECIMAL(5,2)); CREATE TABLE gym_locations (id INT,location_name VARCHAR(50),state VARCHAR(50),city VARCHAR(50),members INT);
SELECT city, SUM(price) AS total_revenue FROM gym_memberships JOIN gym_locations ON gym_memberships.location_name = gym_locations.location WHERE start_date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY city;
What is the total number of sustainable tourism certifications for each region?
CREATE TABLE if not exists sustainability (certification_id INT,region VARCHAR(50),certification_date DATE); INSERT INTO sustainability (certification_id,region,certification_date) VALUES (1,'Europe','2022-01-01'),(2,'Asia','2022-02-01'),(3,'Americas','2022-03-01'),(4,'Africa','2022-04-01'),(5,'Oceania','2022-05-01');
SELECT region, COUNT(*) as total_certifications FROM sustainability GROUP BY region;
What is the average price of non-vegetarian menu items?
CREATE TABLE menus (menu_id INT,menu_name VARCHAR(50),menu_type VARCHAR(20),price DECIMAL(5,2)); INSERT INTO menus (menu_id,menu_name,menu_type,price) VALUES (1,'Quinoa Salad','Vegetarian',9.99),(2,'Margherita Pizza','Non-vegetarian',12.99),(3,'Tofu Stir Fry','Vegetarian',10.99),(4,'Steak','Non-vegetarian',25.99),(5,'G...
SELECT AVG(price) FROM menus WHERE menu_type = 'Non-vegetarian';
What is the total budget allocation for each sector, with the largest allocation first?
CREATE TABLE Sector_Budget(Sector VARCHAR(255),Allocation INT); INSERT INTO Sector_Budget VALUES ('Education',25000000),('Healthcare',20000000),('Transportation',15000000),('Public_Safety',10000000);
SELECT Sector, SUM(Allocation) as Total_Allocation FROM Sector_Budget GROUP BY Sector ORDER BY Total_Allocation DESC;
What is the total revenue from Electronic dance music concerts in May?
CREATE TABLE Concerts (id INT,genre VARCHAR(20),price DECIMAL(5,2)); INSERT INTO Concerts (id,genre,price) VALUES (1,'Electronic dance music',100.00),(2,'Rock',75.00),(3,'Electronic dance music',120.00); CREATE TABLE Dates (id INT,concert_id INT,date DATE); INSERT INTO Dates (id,concert_id) VALUES (1,1),(2,2),(3,3);
SELECT SUM(price) FROM Concerts JOIN Dates ON Concerts.id = Dates.concert_id WHERE Concerts.genre = 'Electronic dance music' AND Dates.date BETWEEN '2022-05-01' AND '2022-05-31';
Find the total grant amount awarded to faculty members in the College of Fine Arts who are from outside the United States.
CREATE TABLE faculty (id INT,name VARCHAR(50),department VARCHAR(50),country VARCHAR(50)); CREATE TABLE grants (id INT,faculty_id INT,amount INT); INSERT INTO faculty VALUES (1,'Penelope','Fine Arts','Mexico'),(2,'Quinn','Fine Arts','Canada'),(3,'Riley','Fine Arts','USA'); INSERT INTO grants VALUES (1,1,5000),(2,1,7000...
SELECT SUM(amount) FROM grants INNER JOIN faculty ON grants.faculty_id = faculty.id WHERE country != 'USA';
How many animals were admitted to the rescue center in the last 6 months from the 'African Wildlife' region?
CREATE TABLE rescue_center (animal_id INT,animal_name VARCHAR(50),date_admitted DATE,region VARCHAR(50)); INSERT INTO rescue_center (animal_id,animal_name,date_admitted,region) VALUES (1,'Lion','2021-01-15','African Wildlife'); INSERT INTO rescue_center (animal_id,animal_name,date_admitted,region) VALUES (2,'Elephant',...
SELECT COUNT(animal_id) FROM rescue_center WHERE date_admitted >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH) AND region = 'African Wildlife';
What is the median account balance for customers who have either a socially responsible checking account or a socially responsible investment account?
CREATE TABLE socially_responsible_checking (checking_id INT,customer_id INT,account_balance DECIMAL); CREATE TABLE socially_responsible_investments (investment_id INT,customer_id INT,account_balance DECIMAL); CREATE TABLE socially_responsible_accounts (account_id INT,checking_id INT,investment_id INT);
SELECT AVG(CASE WHEN srch.customer_id IS NOT NULL THEN srch.account_balance ELSE sri.account_balance END) FROM socially_responsible_checking srch RIGHT JOIN socially_responsible_investments sri ON srch.customer_id = sri.customer_id JOIN socially_responsible_accounts sra ON srch.checking_id = sra.checking_id OR sri.inve...
What is the average project timeline for green building projects in Colorado?
CREATE TABLE project_timelines (id INT,project_id INT,start_date DATE,end_date DATE); CREATE TABLE building_projects (id INT,name TEXT,state TEXT,is_green BOOLEAN); INSERT INTO project_timelines (id,project_id,start_date,end_date) VALUES (1,1,'2020-01-01','2020-06-30'); INSERT INTO project_timelines (id,project_id,star...
SELECT AVG(DATEDIFF(end_date, start_date)) FROM project_timelines JOIN building_projects ON project_timelines.project_id = building_projects.id WHERE building_projects.state = 'Colorado' AND building_projects.is_green = true;
What is the total number of public participation events in the justice sector for the last 3 years?
CREATE TABLE public_participation_events (id INT,sector VARCHAR(20),year INT); INSERT INTO public_participation_events (id,sector,year) VALUES (1,'justice',2018),(2,'justice',2019),(3,'justice',2020),(4,'justice',2018),(5,'justice',2019),(6,'justice',2020);
SELECT COUNT(DISTINCT year) FROM public_participation_events WHERE sector = 'justice' AND year BETWEEN (SELECT MAX(year) - 2 FROM public_participation_events) AND MAX(year);