instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Delete all records of crop type 'Sorghum' with temperature readings below 20.
CREATE TABLE sensor_data (id INT,crop_type VARCHAR(255),temperature INT,humidity INT,measurement_date DATE); INSERT INTO sensor_data (id,crop_type,temperature,humidity,measurement_date) VALUES (1,'Corn',22,55,'2021-07-01'); INSERT INTO sensor_data (id,crop_type,temperature,humidity,measurement_date) VALUES (2,'Cotton',...
DELETE FROM sensor_data WHERE crop_type = 'Sorghum' AND temperature < 20;
List all artists who have exhibited at the MoMA and the year(s) of their exhibition(s).
CREATE TABLE moma_exhibitions (artist_name TEXT,exhibition_year INTEGER); INSERT INTO moma_exhibitions (artist_name,exhibition_year) VALUES ('Pablo Picasso',1939),('Vincent Van Gogh',1935),('Francis Bacon',1975);
SELECT artist_name, exhibition_year FROM moma_exhibitions;
What is the total budget allocated for healthcare services in the year 2020?
CREATE TABLE HealthBudget (Year INT,Service VARCHAR(255),Budget FLOAT); INSERT INTO HealthBudget (Year,Service,Budget) VALUES (2018,'Healthcare',120000),(2019,'Healthcare',150000),(2020,'Healthcare',NULL),(2021,'Healthcare',180000);
SELECT SUM(Budget) FROM HealthBudget WHERE Year = 2020 AND Service = 'Healthcare';
List all historical sites with their preservation status and number of annual visitors from Italy.
CREATE TABLE HistoricalSites (SiteID INT,SiteName VARCHAR(255),Country VARCHAR(255),PreservationStatus VARCHAR(255)); INSERT INTO HistoricalSites (SiteID,SiteName,Country,PreservationStatus) VALUES (1,'Colosseum','Italy','Good'),(2,'Leaning Tower','Italy','Fair'); CREATE TABLE VisitorCounts (SiteID INT,Year INT,Visitor...
SELECT HistoricalSites.SiteName, HistoricalSites.PreservationStatus, SUM(VisitorCounts.VisitorCount) FROM HistoricalSites INNER JOIN VisitorCounts ON HistoricalSites.SiteID = VisitorCounts.SiteID WHERE HistoricalSites.Country = 'Italy' GROUP BY HistoricalSites.SiteName, HistoricalSites.PreservationStatus;
Update the population of the Arctic Fox by 150.
CREATE TABLE species (id INT PRIMARY KEY,name VARCHAR(50),population INT);
WITH updated_population AS (UPDATE species SET population = population + 150 WHERE name = 'Arctic Fox') SELECT * FROM species WHERE name = 'Arctic Fox';
What is the total waste generation in grams for each North American country in 2019?
CREATE TABLE waste_generation (country VARCHAR(50),year INT,continent VARCHAR(50),waste_generation FLOAT); INSERT INTO waste_generation (country,year,continent,waste_generation) VALUES ('USA',2019,'North America',7000),('Canada',2019,'North America',6000),('Mexico',2019,'North America',5000);
SELECT country, SUM(waste_generation) FROM waste_generation WHERE year = 2019 AND continent = 'North America' GROUP BY country;
List property_ids, co-owners' names, and their shares in the co_ownership table.
CREATE TABLE co_ownership (property_id INT,co_owner_name TEXT,share FLOAT); INSERT INTO co_ownership VALUES (1,'Alice',0.5),(1,'Bob',0.5),(2,'Carol',1.0)
SELECT property_id, co_owner_name, share FROM co_ownership;
Add new community health worker record for Hawaii
CREATE TABLE community_health_workers (chw_id INT,state VARCHAR(2),name VARCHAR(50),certification_date DATE);
INSERT INTO community_health_workers (chw_id, state, name, certification_date) VALUES (321, 'HI', 'Keoni Kanahele', '2023-02-15');
What is the total revenue for 'Pasta' and 'Salad' items?
CREATE TABLE revenue (item_name TEXT,revenue INTEGER); INSERT INTO revenue (item_name,revenue) VALUES ('Burger',500),('Pizza',700),('Pasta',600),('Salad',400);
SELECT SUM(revenue) FROM revenue WHERE item_name IN ('Pasta', 'Salad');
What is the average funding received by companies founded by women in the agriculture sector?
CREATE TABLE companies (id INT,name TEXT,industry TEXT,founders_gender TEXT,funding FLOAT);
SELECT AVG(funding) FROM companies WHERE founders_gender = 'female' AND industry = 'agriculture';
What is the distribution of open pedagogy initiatives by country?
CREATE TABLE initiatives (initiative_id INT,initiative_name VARCHAR(50),country VARCHAR(20),open_pedagogy BOOLEAN); INSERT INTO initiatives (initiative_id,initiative_name,country,open_pedagogy) VALUES (1,'Open Education Resources','USA',TRUE),(2,'Massive Open Online Courses','Canada',TRUE),(3,'Flipped Classroom','Mexic...
SELECT country, COUNT(*) as num_initiatives FROM initiatives WHERE open_pedagogy = TRUE GROUP BY country;
What is the sum of ticket prices for all exhibitions in the "Ancient Civilizations" category?
CREATE TABLE Exhibitions (ExhibitionID INT,ExhibitionName VARCHAR(255),Category VARCHAR(255),TicketPrice DECIMAL(5,2)); INSERT INTO Exhibitions (ExhibitionID,ExhibitionName,Category,TicketPrice) VALUES (1,'Egyptian Treasures','Ancient Civilizations',25.99),(2,'Roman Antiquities','Ancient Civilizations',29.99);
SELECT SUM(TicketPrice) FROM Exhibitions WHERE Category = 'Ancient Civilizations';
Who are the top 5 actors by the number of movies they have acted in?
CREATE TABLE actors (id INT,name VARCHAR(255),movies INT); INSERT INTO actors (id,name,movies) VALUES (1,'ActorA',10),(2,'ActorB',5),(3,'ActorC',15),(4,'ActorD',3),(5,'ActorE',20);
SELECT name, movies FROM actors ORDER BY movies DESC LIMIT 5;
Which countries received the most climate finance in the form of international aid in 2022?
CREATE TABLE climate_finance (id INT,country VARCHAR(20),finance_type VARCHAR(20),amount INT,finance_year INT); INSERT INTO climate_finance (id,country,finance_type,amount,finance_year) VALUES (1,'Brazil','International Aid',1000000,2022),(2,'India','International Aid',1200000,2022),(3,'Indonesia','International Aid',8...
SELECT country, SUM(amount) FROM climate_finance WHERE finance_type = 'International Aid' AND finance_year = 2022 GROUP BY country ORDER BY SUM(amount) DESC;
What was the maximum speed recorded for a vessel in the Mediterranean Sea?
CREATE TABLE regions (id INT,name VARCHAR(255)); INSERT INTO regions (id,name) VALUES (1,'Mediterranean Sea'); CREATE TABLE vessel_movements (id INT,vessel_id INT,departure_port_id INT,arrival_port_id INT,speed DECIMAL(5,2),date DATE,region_id INT); INSERT INTO vessel_movements (id,vessel_id,departure_port_id,arrival_p...
SELECT MAX(speed) FROM vessel_movements WHERE region_id = (SELECT id FROM regions WHERE name = 'Mediterranean Sea');
What is the total revenue for the 'Pop' genre in the first half of 2020?
CREATE TABLE genres (id INT,genre VARCHAR(255)); INSERT INTO genres (id,genre) VALUES (1,'Pop'); CREATE TABLE sales (id INT,genre_id INT,revenue DECIMAL(10,2),sale_date DATE);
SELECT SUM(sales.revenue) FROM sales JOIN genres ON sales.genre_id = genres.id WHERE genres.genre = 'Pop' AND sale_date BETWEEN '2020-01-01' AND '2020-06-30';
What is the number of carbon offset programs implemented in 'South America'?
CREATE TABLE carbon_offset_programs (program_id INT,program_name VARCHAR(255),location VARCHAR(255)); INSERT INTO carbon_offset_programs (program_id,program_name,location) VALUES (1,'Tree Planting Program 1','Asia'),(2,'Energy Efficiency Program 1','North America'),(3,'Tree Planting Program 2','Europe'),(4,'Carbon Capt...
SELECT COUNT(*) FROM carbon_offset_programs WHERE location = 'South America';
What are the top 3 drugs by sales revenue in the EU region for 2020?
CREATE TABLE drugs (drug_id INT,drug_name TEXT,sales_region TEXT,revenue FLOAT); INSERT INTO drugs (drug_id,drug_name,sales_region,revenue) VALUES (1001,'DrugA','EU',5000000),(1002,'DrugB','EU',6000000),(1003,'DrugC','US',7000000),(1004,'DrugD','EU',4000000);
SELECT drug_name, MAX(revenue) AS max_revenue FROM drugs WHERE sales_region = 'EU' GROUP BY drug_name LIMIT 3;
What is the total revenue generated from selling Lanthanum in Japan from 2017 to 2019?
CREATE TABLE Lanthanum_Sales (id INT PRIMARY KEY,year INT,country VARCHAR(20),quantity INT,price PER_KG); INSERT INTO Lanthanum_Sales (id,year,country,quantity,price) VALUES (1,2017,'Japan',1200,10),(2,2018,'Japan',1300,11),(3,2019,'Japan',1400,12),(4,2017,'China',1600,9),(5,2018,'China',1700,10),(6,2019,'China',1800,1...
SELECT SUM(quantity * price) FROM Lanthanum_Sales WHERE country = 'Japan' AND year BETWEEN 2017 AND 2019;
Calculate the percentage of citizens who rated service 123 a 5
CREATE TABLE feedback (citizen_id INT,service_id INT,rating INT); INSERT INTO feedback (citizen_id,service_id,rating) VALUES (1,123,5),(2,123,4),(3,123,5),(4,123,3),(5,123,5),(6,123,1);
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM feedback WHERE service_id = 123)) as percentage FROM feedback WHERE service_id = 123 AND rating = 5;
Who are the top 5 most read news topics in India?
CREATE TABLE news_readership (id INT,topic VARCHAR(50),country VARCHAR(50),readership INT); INSERT INTO news_readership (id,topic,country,readership) VALUES (1,'Politics','India',5000); INSERT INTO news_readership (id,topic,country,readership) VALUES (2,'Sports','India',3000);
SELECT topic, SUM(readership) FROM news_readership WHERE country = 'India' GROUP BY topic ORDER BY SUM(readership) DESC LIMIT 5;
What is the average donation amount per country?
CREATE TABLE donations (id INT,donor_name VARCHAR(50),donation_amount DECIMAL(10,2),donation_date DATE,country VARCHAR(50)); INSERT INTO donations (id,donor_name,donation_amount,donation_date,country) VALUES (1,'John Doe',50.00,'2021-01-01','USA'); INSERT INTO donations (id,donor_name,donation_amount,donation_date,coun...
SELECT country, AVG(donation_amount) as avg_donation FROM donations GROUP BY country;
What is the minimum price of non-vegetarian menu items?
CREATE TABLE menus (menu_id INT,menu_name VARCHAR(255),type VARCHAR(255),price DECIMAL(5,2)); INSERT INTO menus (menu_id,menu_name,type,price) VALUES (1,'Quinoa Salad','Vegetarian',12.99),(2,'Margherita Pizza','Non-Vegetarian',9.99),(3,'Falafel Wrap','Vegetarian',8.99),(4,'Steak Sandwich','Non-Vegetarian',11.99),(7,'Ch...
SELECT MIN(price) FROM menus WHERE type = 'Non-Vegetarian';
What percentage of patients with PTSD have had a positive outcome after CBT therapy?
CREATE TABLE PatientOutcomes (PatientID INT,Condition VARCHAR(50),Therapy VARCHAR(50),Outcome VARCHAR(10));
SELECT 100.0 * SUM(CASE WHEN Outcome = 'positive' THEN 1 ELSE 0 END) / COUNT(*) FROM PatientOutcomes WHERE Condition = 'PTSD' AND Therapy = 'CBT';
How many members have a gym membership starting in January?
CREATE TABLE gym_memberships(member_id INT,start_date DATE); INSERT INTO gym_memberships(member_id,start_date) VALUES (1,'2022-01-01'); INSERT INTO gym_memberships(member_id,start_date) VALUES (2,'2022-02-01'); INSERT INTO gym_memberships(member_id,start_date) VALUES (3,'2021-12-15'); INSERT INTO gym_memberships(member...
SELECT COUNT(member_id) FROM gym_memberships WHERE MONTH(start_date) = 1;
List the biosensors developed for infectious diseases.
CREATE SCHEMA if not exists biosensor;CREATE TABLE if not exists biosensor.sensors(id INT,name TEXT,disease_category TEXT);INSERT INTO biosensor.sensors (id,name,disease_category) VALUES (1,'BiosensorA','Infectious Diseases'),(2,'BiosensorB','Cancer'),(3,'BiosensorC','Neurological Disorders'),(4,'BiosensorD','Infectiou...
SELECT * FROM biosensor.sensors WHERE disease_category = 'Infectious Diseases';
Determine the number of threat intelligence metrics reported by each organization in the past year
CREATE TABLE threat_intelligence (metric_id INT,organization VARCHAR(100),metric_value FLOAT,report_date DATE);
SELECT organization, COUNT(*) AS num_metrics FROM threat_intelligence WHERE report_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY organization;
What is the total budget allocated for public participation programs in the state of New York for the year 2020?
CREATE TABLE public_participation_programs (program_id INT,budget INT,state VARCHAR(20),year INT); INSERT INTO public_participation_programs (program_id,budget,state,year) VALUES (1,100000,'New York',2020),(2,200000,'California',2019),(3,150000,'New York',2020),(4,50000,'California',2020),(5,250000,'New York',2019);
SELECT SUM(budget) FROM public_participation_programs WHERE state = 'New York' AND year = 2020;
List all marine species and their average conservation status score, if available.
CREATE TABLE species (id INT,name VARCHAR(50),habitat_type VARCHAR(50)); CREATE TABLE conservation_status (id INT,species_id INT,status VARCHAR(50),score FLOAT);
SELECT species.name, AVG(score) AS avg_score FROM species LEFT JOIN conservation_status ON species.id = conservation_status.species_id GROUP BY species.name;
Add a new author, 'Ali Al-Ahmad', to the 'authors' table
CREATE TABLE authors (author_id INT PRIMARY KEY,first_name VARCHAR(50),last_name VARCHAR(50));
INSERT INTO authors (first_name, last_name) VALUES ('Ali', 'Al-Ahmad');
What is the total number of articles published about climate change and the minimum age of readers who prefer political news in the United States?
CREATE TABLE news_articles (id INT,title VARCHAR(100),publication_date DATE,topic VARCHAR(50),publication_country VARCHAR(50)); INSERT INTO news_articles (id,title,publication_date,topic,publication_country) VALUES (1,'Climate Change: A Growing Crisis','2022-02-12','Climate Change','United States'); CREATE TABLE reader...
SELECT COUNT(*) FROM news_articles WHERE topic = 'Climate Change' AND publication_country = 'United States' UNION SELECT MIN(age) FROM readers WHERE country = 'United States' AND news_preference = 'Politics';
Who is the partner country of the most recent defense agreement of Japan?
CREATE TABLE if not exists diplomacy (id INT,event_name VARCHAR(100),country VARCHAR(50),partner_country VARCHAR(50),date DATE); INSERT INTO diplomacy (id,event_name,country,partner_country,date) VALUES (1,'Military Aid','USA','Afghanistan','2001-09-11'); INSERT INTO diplomacy (id,event_name,country,partner_country,dat...
SELECT event_name, country, partner_country, date, RANK() OVER(PARTITION BY country ORDER BY date DESC) as recent_rank FROM diplomacy WHERE event_name = 'Defense Agreement' AND country = 'Japan' ORDER BY date DESC FETCH FIRST 1 ROW ONLY;
Which athlete has won the most medals in swimming events in France?
CREATE TABLE if not exists countries (country_id INT,country VARCHAR(255)); INSERT INTO countries (country_id,country) VALUES (1,'France'),(2,'Germany'),(3,'Italy'); CREATE TABLE if not exists athletes (athlete_id INT,country_id INT,medals INT,sport VARCHAR(255)); INSERT INTO athletes (athlete_id,country_id,medals,spor...
SELECT athlete_id, SUM(medals) FROM athletes WHERE country_id = 1 AND sport = 'Swimming' GROUP BY athlete_id ORDER BY SUM(medals) DESC LIMIT 1;
Delete the record for the donor with ID 4
CREATE TABLE Donors (ID INT PRIMARY KEY,Name TEXT,Email TEXT);
DELETE FROM Donors WHERE ID = 4;
Delete records in the 'unfair_outcomes' table where the 'outcome' is 'unfavorable' and the 'bias_type' is 'gender'
CREATE TABLE unfair_outcomes (id INT PRIMARY KEY,algorithm_name VARCHAR(50),outcome VARCHAR(20),bias_type VARCHAR(20),description TEXT);
DELETE FROM unfair_outcomes WHERE outcome = 'unfavorable' AND bias_type = 'gender';
Show the total budget for each program, the number of donors who have contributed to the program, and the total amount donated, along with program details.
CREATE TABLE programs (id INT,name TEXT,location TEXT,budget INT); CREATE TABLE donations (id INT,donor_id INT,program_id INT,amount DECIMAL); CREATE TABLE donors (id INT,name TEXT,email TEXT);
SELECT programs.name as program_name, COUNT(DISTINCT donors.id) as num_donors, SUM(donations.amount) as total_donation, programs.budget as budget FROM programs INNER JOIN donations ON programs.id = donations.program_id INNER JOIN donors ON donations.donor_id = donors.id GROUP BY programs.id;
What is the total cost of ingredients for each menu item?
CREATE TABLE menu_items (id INT,name VARCHAR(50),category VARCHAR(50),cost DECIMAL(10,2));
SELECT name, SUM(cost) as total_cost FROM menu_items GROUP BY name;
What is the average horsepower of electric vehicles in the 2022 Detroit Auto Show?
CREATE TABLE AutoShow (Id INT,VehicleType VARCHAR(50),Event VARCHAR(100),Horsepower FLOAT); INSERT INTO AutoShow (Id,VehicleType,Event,Horsepower) VALUES (1,'Electric','2022 Detroit Auto Show',350),(2,'Hybrid','2022 Detroit Auto Show',250),(3,'Gasoline','2022 Detroit Auto Show',200),(4,'Electric','2022 Shanghai Auto Sh...
SELECT AVG(Horsepower) FROM AutoShow WHERE VehicleType = 'Electric' AND Event LIKE '%2022 Detroit Auto Show%'
What is the total number of healthcare facilities in each state?
use rural_health; CREATE TABLE facilities (id int,name text,type text,state text); INSERT INTO facilities (id,name,type,state) VALUES (1,'Rural Hospital A','Hospital','Alabama'); INSERT INTO facilities (id,name,type,state) VALUES (2,'Urgent Care B','Urgent Care','Alabama'); INSERT INTO facilities (id,name,type,state) V...
SELECT state, COUNT(*) as total FROM rural_health.facilities GROUP BY state;
What is the total number of public transportation trips taken in Tokyo?
CREATE TABLE bus_routes (route_id INT,city VARCHAR(50),num_trips INT); INSERT INTO bus_routes (route_id,city,num_trips) VALUES (1,'Tokyo',1000),(2,'Tokyo',1500),(3,'Tokyo',2000); CREATE TABLE train_lines (line_id INT,city VARCHAR(50),num_trips INT); INSERT INTO train_lines (line_id,city,num_trips) VALUES (1,'Tokyo',250...
SELECT (SELECT SUM(num_trips) FROM bus_routes WHERE city = 'Tokyo') + (SELECT SUM(num_trips) FROM train_lines WHERE city = 'Tokyo');
What is the average organic waste generation per capita in Japan?
CREATE TABLE OrganicWasteData (country VARCHAR(50),population INT,organic_waste_kg FLOAT); INSERT INTO OrganicWasteData (country,population,organic_waste_kg) VALUES ('Japan',126317000,13.4);
SELECT AVG(organic_waste_kg/population) FROM OrganicWasteData WHERE country = 'Japan';
List all the unique mental health programs offered by schools in the 'programs' table, sorted alphabetically.
CREATE TABLE programs (school_id INT,program_name VARCHAR(50),program_type VARCHAR(20));
SELECT DISTINCT program_name FROM programs WHERE program_type = 'mental_health' ORDER BY program_name ASC;
How many professional development courses have been completed by each teacher?
CREATE TABLE teacher (id INT,name TEXT); INSERT INTO teacher (id,name) VALUES (1,'John Doe'),(2,'Jane Smith'); CREATE TABLE course (id INT,name TEXT,teacher_id INT); INSERT INTO course (id,name,teacher_id) VALUES (1,'Python for Teachers',1),(2,'Data Science for Teachers',1),(3,'Math for Teachers',2),(4,'Science for Tea...
SELECT c.teacher_id, COUNT(DISTINCT c.id) AS courses_completed FROM course c GROUP BY c.teacher_id;
Find the maximum quantity of products in the 'furniture' category
CREATE TABLE products (product_id INT,category VARCHAR(20),quantity INT); INSERT INTO products (product_id,category,quantity) VALUES (1,'furniture',25),(2,'furniture',50),(3,'furniture',75);
SELECT MAX(quantity) FROM products WHERE category = 'furniture';
What is the total quantity of 'organic cotton' products in the inventory?
CREATE TABLE product (product_id INT,name VARCHAR(255),quantity INT,material VARCHAR(255)); INSERT INTO product (product_id,name,quantity,material) VALUES (1,'Organic Cotton T-Shirt',30,'organic cotton');
SELECT SUM(quantity) FROM product WHERE material = 'organic cotton';
Create a view to show the average recycling rate by country
CREATE TABLE circular_supply_chain (product_id INT,supplier_id INT,recycling_program BOOLEAN); CREATE VIEW recycling_rates_by_country AS SELECT country,AVG(recycling_program) as avg_recycling_rate FROM circular_supply_chain cs JOIN product_transparency pt ON cs.product_id = pt.product_id JOIN supplier_ethics se ON cs.s...
CREATE VIEW recycling_rates_by_country AS SELECT country, AVG(recycling_program) as avg_recycling_rate FROM circular_supply_chain cs JOIN product_transparency pt ON cs.product_id = pt.product_id JOIN supplier_ethics se ON cs.supplier_id = se.supplier_id GROUP BY country;
Add a new explainable AI dataset 'German Credit'
CREATE TABLE xai_datasets (id INT,name VARCHAR(255),description VARCHAR(255)); INSERT INTO xai_datasets (id,name,description) VALUES (1,'Credit Approval','Credit approval dataset for customers with sensitive features');
INSERT INTO xai_datasets (id, name, description) VALUES (2, 'German Credit', 'Credit dataset for individuals with sensitive features');
What is the average movie rating by users from the United States?
CREATE TABLE Movies (movie_id INT,title VARCHAR(255),release_date DATE,genre VARCHAR(255),rating DECIMAL(3,2),user_country VARCHAR(50)); INSERT INTO Movies (movie_id,title,release_date,genre,rating,user_country) VALUES (1,'Movie1','2020-01-01','Action',8.5,'USA'),(2,'Movie2','2019-05-15','Drama',7.2,'Canada'),(3,'Movie...
SELECT AVG(rating) FROM Movies WHERE user_country = 'USA';
What is the sum of investments made in the healthcare sector?
CREATE TABLE investments (id INT,sector VARCHAR(20),amount DECIMAL(10,2)); INSERT INTO investments (id,sector,amount) VALUES (1,'education',15000.00),(2,'healthcare',20000.00),(3,'education',22000.00);
SELECT SUM(amount) FROM investments WHERE sector = 'healthcare';
Show the building permit data for the last 6 months, for the Western region, and rank the permits by their permit numbers in descending order.
CREATE TABLE Permits (PermitID int,Region varchar(20),Date date); INSERT INTO Permits (PermitID,Region,Date) VALUES (1,'Western','2022-01-01'),(2,'Central','2022-02-01'),(3,'Western','2022-03-01');
SELECT PermitID, Region, Date, ROW_NUMBER() OVER (PARTITION BY Region ORDER BY Date DESC) as rn FROM Permits WHERE Region = 'Western' AND Date >= DATEADD(month, -6, GETDATE());
Calculate the total number of scientific observations conducted by spacecraft on Jupiter.
CREATE TABLE spacecrafts (spacecraft_id INT,name TEXT,observations_jupiter INT); INSERT INTO spacecrafts (spacecraft_id,name,observations_jupiter) VALUES (1,'Galileo',1546),(2,'Juno',2000),(3,'Pioneer 10',20),(4,'Cassini',100); CREATE TABLE spacecraft_missions (spacecraft_id INT,mission_id INT); INSERT INTO spacecraft_...
SELECT SUM(observations_jupiter) FROM spacecrafts sc JOIN spacecraft_missions sm ON sc.spacecraft_id = sm.spacecraft_id JOIN space_missions s ON sm.mission_id = s.mission_id WHERE s.destination = 'Jupiter';
Which soccer players have scored the most goals in the 2022 FIFA World Cup, sorted by team?
CREATE TABLE soccer_players (player_id INT,name VARCHAR(50),team VARCHAR(50),goals INT,tournament VARCHAR(50)); INSERT INTO soccer_players (player_id,name,team,goals,tournament) VALUES (1,'Lionel Messi','Argentina',5,'FIFA World Cup');
SELECT team, name, SUM(goals) as total_goals FROM soccer_players WHERE tournament = 'FIFA World Cup' AND YEAR(start_date) = 2022 GROUP BY team, name ORDER BY total_goals DESC;
List the names and species of all animals in the Canadian Wildlife Reserve.
CREATE TABLE Animals (name VARCHAR(50),species VARCHAR(50),location VARCHAR(50)); INSERT INTO Animals (name,species,location) VALUES ('Moose 1','Moose','Canadian Wildlife Reserve'),('Moose 2','Moose','Canadian Wildlife Reserve'),('Grizzly Bear 1','Grizzly Bear','Canadian Wildlife Reserve'); CREATE TABLE Reserves (name ...
SELECT name, species FROM Animals INNER JOIN Reserves ON TRUE WHERE Animals.location = Reserves.location AND Reserves.name = 'Canadian Wildlife Reserve';
What are the total sales and average potency for each strain produced by cultivators in Oregon in 2019?
CREATE TABLE cultivators (id INT,name TEXT,state TEXT); INSERT INTO cultivators (id,name,state) VALUES (1,'Cultivator C','Oregon'); INSERT INTO cultivators (id,name,state) VALUES (2,'Cultivator D','Oregon'); CREATE TABLE strains (cultivator_id INT,name TEXT,year INT,potency INT,sales INT); INSERT INTO strains (cultivat...
SELECT s.name as strain_name, c.state as cultivator_state, SUM(s.sales) as total_sales, AVG(s.potency) as average_potency FROM strains s INNER JOIN cultivators c ON s.cultivator_id = c.id WHERE c.state = 'Oregon' AND s.year = 2019 GROUP BY s.name, c.state;
Delete the record with id 1 from the 'farmers' table
CREATE TABLE farmers (id INT PRIMARY KEY,name VARCHAR(50),age INT,gender VARCHAR(10),location VARCHAR(50),profession VARCHAR(50)); INSERT INTO farmers (id,name,age,gender,location,profession) VALUES (1,'John Doe',35,'Male','USA','Farmer'),(2,'Jane Smith',40,'Female','Canada','Farmer');
DELETE FROM farmers WHERE id = 1;
What is the average funding amount per round for female founders?
CREATE TABLE companies (id INT,name TEXT,founder_gender TEXT,funding_amount INT); INSERT INTO companies (id,name,founder_gender,funding_amount) VALUES (1,'Acme Inc','Female',5000000);
SELECT AVG(funding_amount) FROM companies WHERE founder_gender = 'Female';
What is the total mass of spacecraft that were manufactured by SpaceCorp?
CREATE TABLE Spacecraft (id INT,name VARCHAR(50),manufacturer VARCHAR(50),mass FLOAT); INSERT INTO Spacecraft (id,name,manufacturer,mass) VALUES (1,'Voyager 1','SpaceCorp',770.0),(2,'Voyager 2','SpaceCorp',770.0),(3,'Galileo','NASA',2223.0),(4,'Cassini','NASA',5650.0),(5,'InSight','JPL',358.0),(6,'Perseverance','NASA',...
SELECT SUM(Spacecraft.mass) FROM Spacecraft WHERE Spacecraft.manufacturer = 'SpaceCorp';
How many marine mammals are found in the Arctic Ocean?
CREATE TABLE marine_mammals (name TEXT,ocean TEXT);
SELECT COUNT(*) FROM marine_mammals WHERE ocean = 'Arctic Ocean';
What is the average occupancy rate of hotels in the city of 'Rome' with more than 100 reviews?
CREATE TABLE hotel_reviews (hotel_id INT,hotel_name TEXT,city TEXT,occupancy_rate DECIMAL,review_count INT); INSERT INTO hotel_reviews (hotel_id,hotel_name,city,occupancy_rate,review_count) VALUES (101,'Hotel Roma','Rome',0.75,120),(102,'Eternal City Inn','Rome',0.85,200),(103,'Villa Bella','Paris',0.90,150);
SELECT AVG(occupancy_rate) as avg_occupancy_rate FROM hotel_reviews WHERE city = 'Rome' AND review_count > 100;
What is the average speed of shared e-scooters in New York?
CREATE TABLE shared_escooters (scooter_id INT,trip_duration INT,start_speed INT,end_speed INT,trip_date DATE); INSERT INTO shared_escooters (scooter_id,trip_duration,start_speed,end_speed,trip_date) VALUES (1,1200,5,15,'2022-01-01'),(2,900,10,20,'2022-01-02'); CREATE TABLE city_coordinates (city VARCHAR(50),latitude DE...
SELECT AVG(end_speed - start_speed) as avg_speed FROM shared_escooters, city_coordinates WHERE city_coordinates.city = 'New York';
What is the total revenue from mobile and broadband services for the month of July 2021?
CREATE TABLE mobile_revenue (revenue_id INT,revenue_date DATE,revenue_amount FLOAT,revenue_type VARCHAR(20)); INSERT INTO mobile_revenue (revenue_id,revenue_date,revenue_amount,revenue_type) VALUES (1,'2021-07-12',50000,'Mobile'),(2,'2021-07-28',75000,'Broadband'); CREATE TABLE broadband_revenue (revenue_id INT,revenue...
SELECT SUM(revenue_amount) FROM mobile_revenue WHERE revenue_date BETWEEN '2021-07-01' AND '2021-07-31' UNION ALL SELECT SUM(revenue_amount) FROM broadband_revenue WHERE revenue_date BETWEEN '2021-07-01' AND '2021-07-31';
What is the average age of patients who experienced improvement after therapy?
CREATE TABLE patients (id INT,age INT,gender VARCHAR(10),condition VARCHAR(50),therapy_date DATE,improvement BOOLEAN);
SELECT AVG(age) FROM patients WHERE improvement = TRUE;
What is the maximum quantity of clothes sold in a single day?
CREATE TABLE sales (id INT,product_id INT,size TEXT,quantity INT,sale_date DATE); INSERT INTO sales (id,product_id,size,quantity,sale_date) VALUES (1,1001,'XS',25,'2021-09-01'),(2,1002,'XXL',30,'2021-09-15'),(3,1003,'M',40,'2021-09-20'),(4,1004,'L',50,'2021-09-25');
SELECT MAX(quantity) FROM sales;
What is the median donation amount for donors from Africa?
CREATE TABLE Countries (CountryID INT PRIMARY KEY,CountryName TEXT,Continent TEXT); INSERT INTO Countries (CountryID,CountryName,Continent) VALUES (1,'United States','North America'); INSERT INTO Countries (CountryID,CountryName,Continent) VALUES (2,'United Kingdom','Europe'); INSERT INTO Countries (CountryID,CountryNa...
SELECT AVG(AmountDonated) FROM (SELECT AmountDonated FROM Donors INNER JOIN Donors_Countries ON Donors.DonorID = Donors_Countries.DonorID WHERE Donors_Countries.CountryName = 'Nigeria' ORDER BY AmountDonated) AS DonorAmounts WHERE (ROW_NUMBER() OVER (ORDER BY AmountDonated) IN ((COUNT(*) + 1) / 2, (COUNT(*) + 2) / 2));
What is the total number of fair trade certified clothing items?
CREATE TABLE ClothingItems (id INT,fair_trade_certified BOOLEAN); INSERT INTO ClothingItems VALUES (1,true),(2,false),(3,true),(4,true),(5,false);
SELECT COUNT(*) FROM ClothingItems WHERE fair_trade_certified = true;
What is the total playtime of player 'Kevin' in the VR game 'Superhot'?
CREATE TABLE vr_games_4 (id INT,player TEXT,game TEXT,playtime INT); INSERT INTO vr_games_4 (id,player,game,playtime) VALUES (1,'Kevin','Superhot',70),(2,'Lara','Beat Saber',110),(3,'Kevin','Arizona Sunshine',90);
SELECT SUM(playtime) FROM vr_games_4 WHERE player = 'Kevin' AND game = 'Superhot';
What is the average depth of all marine reserves in the Indian Ocean?
CREATE TABLE indian_ocean_reserves (reserve_name VARCHAR(255),avg_depth FLOAT); INSERT INTO indian_ocean_reserves (reserve_name,avg_depth) VALUES ('Maldives',100.0),('Andaman Islands',200.0);
SELECT AVG(avg_depth) FROM indian_ocean_reserves;
Show all whale sightings in the Arctic Ocean in the last 5 years.
CREATE TABLE whale_sightings (species TEXT,location TEXT,date DATE); INSERT INTO whale_sightings (species,location,date) VALUES ('Beluga Whale','Arctic Ocean','2018-01-01'),('Narwhal','Arctic Ocean','2020-05-15');
SELECT * FROM whale_sightings WHERE location = 'Arctic Ocean' AND date >= (SELECT CURRENT_DATE - INTERVAL '5 years');
Display data from the view
CREATE VIEW AverageMentalHealthByMonth AS SELECT DATE_TRUNC('month',AssessmentDate) AS Month,AVG(MentalHealthScore) AS AverageScore FROM StudentsMentalHealth GROUP BY Month; SELECT * FROM AverageMentalHealthByMonth;
SELECT * FROM AverageMentalHealthByMonth;
What's the name and status of the projects with a budget over 400000?
CREATE TABLE Projects (id INT,name TEXT,organization_id INT,budget FLOAT,status TEXT); INSERT INTO Projects (id,name,organization_id,budget,status) VALUES (1,'Disaster Response',1,250000,'Completed'),(2,'Rebuilding Infrastructure',2,450000,'In Progress');
SELECT Projects.name, Projects.status FROM Projects WHERE Projects.budget > 400000;
Insert a new record into the EmployeeData table for an employee named 'Ali' Ahmed, working in the 'Admin' department with a salary of 50000.
CREATE TABLE EmployeeData (EmployeeID INT PRIMARY KEY,FirstName VARCHAR(50),LastName VARCHAR(50),Department VARCHAR(50),Salary DECIMAL(10,2));
INSERT INTO EmployeeData (EmployeeID, FirstName, LastName, Department, Salary) VALUES (5, 'Ali', 'Ahmed', 'Admin', 50000);
How many rural infrastructure projects are there in total for each country, including those with a budget of 0?
CREATE TABLE rural_projects (id INT,name TEXT,location TEXT,budget FLOAT); INSERT INTO rural_projects (id,name,location,budget) VALUES (1,'Water Supply','Kenya',500000.00),(2,'Electricity Grid','Tanzania',200000.00),(3,'Road Construction','Uganda',NULL);
SELECT location, COUNT(*) FROM rural_projects GROUP BY location;
What was the total value of construction projects in Maryland in Q2 2022?
CREATE TABLE md_projects (quarter VARCHAR(5),state VARCHAR(10),project_value FLOAT); INSERT INTO md_projects (quarter,state,project_value) VALUES ('Q1 2022','Maryland',12000000),('Q2 2022','Maryland',15000000),('Q3 2022','Maryland',16000000),('Q4 2022','Maryland',18000000);
SELECT project_value FROM md_projects WHERE quarter = 'Q2 2022' AND state = 'Maryland';
Who are the curators of digital exhibits in Asia?
CREATE TABLE DigitalExhibits (ExhibitID INT,Title VARCHAR(50),Curator VARCHAR(50),City VARCHAR(50)); INSERT INTO DigitalExhibits (ExhibitID,Title,Curator,City) VALUES (1,'Digital Art Museum','Alice Johnson','Tokyo'); INSERT INTO DigitalExhibits (ExhibitID,Title,Curator,City) VALUES (2,'Virtual Reality Experience','Bob ...
SELECT DigitalExhibits.Curator FROM DigitalExhibits WHERE DigitalExhibits.City = 'Asia';
Identify fans who have never purchased tickets for basketball games.
CREATE TABLE Fans (fan_id INT,fan_name VARCHAR(50),favorite_sport_id INT); CREATE TABLE Sports (sport_id INT,sport_name VARCHAR(50)); CREATE TABLE Tickets (ticket_id INT,fan_id INT,sport_id INT,quantity INT,purchase_date DATE);
SELECT fan_name FROM Fans LEFT JOIN Tickets ON Fans.fan_id = Tickets.fan_id AND Sports.sport_id = 1 WHERE Tickets.ticket_id IS NULL;
Which programs did volunteer 'Zoe' engage with in 2022?
CREATE TABLE Programs (ProgramID int,ProgramName varchar(255)); INSERT INTO Programs (ProgramID,ProgramName) VALUES (1,'Education'),(2,'Health'),(3,'Environment'); CREATE TABLE Volunteers (VolunteerID int,VolunteerName varchar(255),ProgramID int,VolunteerDate date); INSERT INTO Volunteers (VolunteerID,VolunteerName,Pro...
SELECT DISTINCT ProgramName FROM Volunteers V JOIN Programs P ON V.ProgramID = P.ProgramID WHERE VolunteerName = 'Zoe';
Determine the total revenue generated by each supplier for organic products in the UK.
CREATE TABLE organic_prods (product_id INT,name VARCHAR(50),price DECIMAL(5,2),supplier VARCHAR(50)); INSERT INTO organic_prods VALUES (1,'Organic Tofu',5.99,'EcoFarm'); INSERT INTO organic_prods VALUES (2,'Organic Almond Butter',8.99,'EcoFarm'); CREATE TABLE uk_suppliers (product_id INT,supplier VARCHAR(50),uk_locatio...
SELECT s.supplier, SUM(op.price) FROM organic_prods op JOIN uk_suppliers us ON op.product_id = us.product_id JOIN (SELECT supplier FROM uk_suppliers GROUP BY supplier) s ON op.supplier = s.supplier WHERE us.uk_location = 1 AND op.name LIKE '%organic%' GROUP BY s.supplier;
What is the maximum number of emergency calls made in the "east" district, for the month of January?
CREATE TABLE emergency_calls (id INT,call_time TIMESTAMP,location VARCHAR(20));
SELECT MAX(COUNT(*)) FROM emergency_calls WHERE location = 'east' AND EXTRACT(MONTH FROM call_time) = 1;
What is the maximum salary of workers in the 'retail' industry in the 'North' region?
CREATE TABLE regions (region_id INT,region_name TEXT); CREATE TABLE workers (worker_id INT,worker_name TEXT,salary INT,region_id INT,industry_id INT); CREATE TABLE industries (industry_id INT,industry_name TEXT); INSERT INTO regions VALUES (1,'North'),(2,'South'),(3,'East'),(4,'West'); INSERT INTO workers VALUE...
SELECT MAX(salary) FROM workers INNER JOIN regions ON workers.region_id = regions.region_id INNER JOIN industries ON workers.industry_id = industries.industry_id WHERE regions.region_name = 'North' AND industries.industry_name = 'retail';
What is the daily production quantity of the 'MOUNTAIN_OIL' well in the 'OIL_PRODUCTION' table?
CREATE TABLE OIL_PRODUCTION (WELL_NAME VARCHAR(255),PRODUCTION_DATE DATE,QUANTITY INT);
SELECT QUANTITY FROM OIL_PRODUCTION WHERE WELL_NAME = 'MOUNTAIN_OIL' AND PRODUCTION_DATE = CURDATE();
Find the top 5 donors by total donations, considering only donors who have donated more than $1000 in total?
CREATE TABLE Donors (DonorID int,FirstName varchar(50),LastName varchar(50)); INSERT INTO Donors (DonorID,FirstName,LastName) VALUES (1,'John','Doe'),(2,'Jane','Smith'),(3,'Alice','Johnson'),(4,'Bob','Brown'),(5,'Charlie','Williams'); CREATE TABLE Donations (DonationID int,DonorID int,Amount decimal(10,2)); INSERT INTO...
SELECT D.FirstName, D.LastName, SUM(D.Amount) as TotalDonated FROM Donors D INNER JOIN Donations ON D.DonorID = Donations.DonorID GROUP BY D.DonorID HAVING TotalDonated > 1000 ORDER BY TotalDonated DESC LIMIT 5;
Who are the community health workers serving the Non-Hispanic population?
CREATE TABLE community_health_workers (worker_id INT,name VARCHAR(50),ethnicity VARCHAR(20)); INSERT INTO community_health_workers (worker_id,name,ethnicity) VALUES (1,'Ana Garcia','Hispanic'),(2,'Juan Hernandez','Hispanic'),(3,'Mark Johnson','Non-Hispanic');
SELECT * FROM community_health_workers WHERE ethnicity = 'Non-Hispanic';
List the number of pallets shipped to each warehouse in the Asia-Pacific region in the past month, excluding warehouses with fewer than 50 shipments.
CREATE TABLE Warehouses (WarehouseID int,WarehouseName varchar(255),Region varchar(255));CREATE TABLE Shipments (ShipmentID int,WarehouseID int,Pallets int,ShippedDate datetime); INSERT INTO Warehouses (WarehouseID,WarehouseName,Region) VALUES (1,'W1','Asia-Pacific'); INSERT INTO Shipments (ShipmentID,WarehouseID,Palle...
SELECT w.WarehouseName, SUM(s.Pallets) as TotalPallets FROM Warehouses w INNER JOIN Shipments s ON w.WarehouseID = s.WarehouseID WHERE w.Region = 'Asia-Pacific' AND s.ShippedDate >= DATEADD(month, -1, GETDATE()) GROUP BY w.WarehouseName HAVING COUNT(*) >= 50;
How many biosensor technology patents have been filed in the last 5 years by company?
CREATE SCHEMA if not exists biosensors;CREATE TABLE if not exists biosensors.patents (id INT,company VARCHAR(100),filing_date DATE);INSERT INTO biosensors.patents (id,company,filing_date) VALUES (1,'CompanyA','2018-03-15'),(2,'CompanyB','2019-08-01'),(3,'CompanyC','2020-02-20');
SELECT company, COUNT(*) as patents_filed FROM biosensors.patents WHERE filing_date >= DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR) GROUP BY company;
What is the total amount spent on each project in 'Projects' table for the year 2022?
CREATE TABLE Projects (ProjectID INT,ProjectName VARCHAR(50),Spending INT,SpendingDate DATE); INSERT INTO Projects (ProjectID,ProjectName,Spending,SpendingDate) VALUES (1,'ProjectA',15000,'2022-01-01'),(2,'ProjectB',20000,'2022-02-15'),(3,'ProjectA',12000,'2022-03-03');
SELECT ProjectName, EXTRACT(YEAR FROM SpendingDate) AS Year, SUM(Spending) AS TotalSpending FROM Projects WHERE EXTRACT(YEAR FROM SpendingDate) = 2022 GROUP BY ProjectName, Year
What is the average budget for accessible technology projects in Africa?
CREATE TABLE AccessibleTech (location VARCHAR(20),budget DECIMAL(10,2)); INSERT INTO AccessibleTech (location,budget) VALUES ('Africa',50000.00),('Asia',75000.00),('Europe',120000.00),('SouthAmerica',60000.00),('NorthAmerica',150000.00);
SELECT AVG(budget) FROM AccessibleTech WHERE location = 'Africa';
What is the total funding received by biotech startups in India, grouped by year?
CREATE TABLE startups (id INT,name VARCHAR(255),country VARCHAR(255),funding FLOAT,date DATE); INSERT INTO startups (id,name,country,funding,date) VALUES (1,'StartupA','India',5000000,'2020-01-01'); INSERT INTO startups (id,name,country,funding,date) VALUES (2,'StartupB','India',7000000,'2019-01-01');
SELECT country, YEAR(date) AS year, SUM(funding) FROM startups WHERE country = 'India' GROUP BY year, country;
What is the average number of military personnel per peacekeeping mission for each country?
CREATE TABLE peacekeeping_missions (country VARCHAR(255),mission VARCHAR(255),personnel INT); INSERT INTO peacekeeping_missions (country,mission,personnel) VALUES ('USA','Mission1',100),('USA','Mission2',150),('China','Mission1',200),('China','Mission3',250),('France','Mission2',120),('France','Mission3',180),('UK','Mi...
SELECT country, AVG(personnel) as avg_personnel_per_mission FROM peacekeeping_missions GROUP BY country;
What is the average billing amount for cases handled by attorneys with 'Senior Partner' title?
CREATE TABLE Attorneys (AttorneyID int,Name varchar(50),Title varchar(50),YearsOfExperience int); INSERT INTO Attorneys (AttorneyID,Name,Title,YearsOfExperience) VALUES (1,'John Doe','Senior Partner',20); INSERT INTO Attorneys (AttorneyID,Name,Title,YearsOfExperience) VALUES (2,'Jane Smith','Associate',5);
SELECT AVG(BillingAmount) FROM Cases INNER JOIN Attorneys ON Cases.AttorneyID = Attorneys.AttorneyID WHERE Attorneys.Title = 'Senior Partner';
What is the total number of electric vehicles sold in each city, broken down by make and model?
CREATE TABLE electric_vehicles (city_name VARCHAR(255),make VARCHAR(255),model VARCHAR(255),sales INT); INSERT INTO electric_vehicles (city_name,make,model,sales) VALUES ('Los Angeles','Tesla','Model S',1500),('New York','Chevrolet','Bolt',1000);
SELECT city_name, make, model, SUM(sales) as total_sales FROM electric_vehicles GROUP BY city_name, make, model;
What is the name of the research station with the lowest capacity in a country with an indigenous community population greater than 200?
CREATE TABLE ResearchStations (id INT,name VARCHAR(50),capacity INT,country VARCHAR(50)); INSERT INTO ResearchStations (id,name,capacity,country) VALUES (1,'Station A',50,'Norway');CREATE TABLE IndigenousCommunities (id INT,name VARCHAR(50),population INT,region VARCHAR(50)); INSERT INTO IndigenousCommunities (id,name,...
SELECT name FROM ResearchStations r WHERE r.capacity = (SELECT MIN(capacity) FROM ResearchStations) AND r.country = ANY(SELECT ic.region FROM IndigenousCommunities ic WHERE ic.population > 200);
What is the average annual rainfall and temperature for each urban farm in the "urban_farms", "urban_regions", and "weather" tables?
CREATE TABLE urban_farms (id INT,urban_region_id INT); CREATE TABLE urban_regions (id INT,name VARCHAR(50)); CREATE TABLE weather (id INT,region_id INT,year INT,rainfall FLOAT,temperature FLOAT);
SELECT urban_farms.id AS farm_id, urban_regions.name AS region, AVG(weather.rainfall) AS avg_rainfall, AVG(weather.temperature) AS avg_temperature FROM urban_farms INNER JOIN urban_regions ON urban_farms.urban_region_id = urban_regions.id INNER JOIN weather ON urban_regions.id = weather.region_id GROUP BY urban_farms.i...
What is the total number of digital assets in circulation in India as of 2022-02-01?
CREATE TABLE digital_assets (asset_name TEXT,in_circulation INTEGER,circulation_date DATE); INSERT INTO digital_assets (asset_name,in_circulation,circulation_date) VALUES ('Bitcoin',18750000,'2022-02-01'),('Ethereum',115500000,'2022-02-01');
SELECT SUM(in_circulation) FROM digital_assets WHERE circulation_date = '2022-02-01' AND asset_name IN ('Bitcoin', 'Ethereum');
Which farmers grow fruits or nuts in the agriculture database?
CREATE TABLE Farmers (id INT,name VARCHAR,location VARCHAR,years_of_experience INT); INSERT INTO Farmers (id,name,location,years_of_experience) VALUES (1,'Sophia Garcia','Madrid',10),(2,'Mohammad Al-Said','Cairo',12),(3,'Park Soo-jin','Seoul',8); CREATE TABLE Crops (id INT,farmer_id INT,crop_name VARCHAR,yield INT,crop...
SELECT f.name, COUNT(DISTINCT c.crop_name) as unique_fruits_or_nuts_count FROM Farmers f JOIN Crops c ON f.id = c.farmer_id WHERE c.crop_type IN ('fruit', 'nut') GROUP BY f.name;
What is the average salary of male and female employees in the mining department?
CREATE TABLE Employees (employee_id INT,name VARCHAR(50),gender VARCHAR(10),department VARCHAR(20),salary DECIMAL(10,2)); INSERT INTO Employees (employee_id,name,gender,department,salary) VALUES (1,'John Doe','Male','Mining',50000),(2,'Jane Smith','Female','Mining',55000),(3,'Alice Johnson','Female','HR',60000);
SELECT gender, AVG(salary) as avg_salary FROM Employees WHERE department = 'Mining' GROUP BY gender;
Delete all articles about politics written by men in the '70s.
CREATE TABLE articles (id INT PRIMARY KEY,title TEXT,year INT,topic TEXT,author TEXT); INSERT INTO articles (id,title,year,topic,author) VALUES (1,'Article1',1970,'Politics','James Johnson'),(2,'Article2',1980,'Sports','Mary Davis'),(3,'Article3',1975,'Politics','Michael Brown');
DELETE FROM articles WHERE author IN ('James Johnson', 'Michael Brown') AND topic = 'Politics' AND year = 1970;
What is the total number of cruelty-free products with natural ingredients?
CREATE TABLE Products (product_id INT,is_cruelty_free BOOLEAN,has_natural_ingredients BOOLEAN);
SELECT COUNT(*) FROM Products WHERE is_cruelty_free = TRUE AND has_natural_ingredients = TRUE;
Find the menu items that had sales every day in the last week?
CREATE TABLE daily_sales (sale_date DATE,item VARCHAR(50),sales INT); INSERT INTO daily_sales (sale_date,item,sales) VALUES ('2022-01-01','Pizza Margherita',15),('2022-01-01','Spaghetti Bolognese',10); CREATE VIEW item_sales AS SELECT item,sale_date FROM daily_sales GROUP BY item,sale_date;
SELECT item FROM item_sales WHERE sale_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND CURDATE() GROUP BY item HAVING COUNT(DISTINCT sale_date) = 7;
What was the total revenue generated by each exhibition?
CREATE TABLE tickets (ticket_id INT,ticket_price DECIMAL(5,2),exhibition_id INT); INSERT INTO tickets (ticket_id,ticket_price,exhibition_id) VALUES (1,20.00,1),(2,25.00,2),(3,15.00,1);
SELECT e.exhibition_name, SUM(t.ticket_price) FROM exhibitions e JOIN tickets t ON e.exhibition_id = t.exhibition_id GROUP BY e.exhibition_name;
How many ethical AI courses were offered in Asia in 2020?
CREATE TABLE ethical_ai (country VARCHAR(20),year INT,courses INT); INSERT INTO ethical_ai (country,year,courses) VALUES ('China',2020,15),('India',2020,12),('Japan',2020,18);
SELECT SUM(courses) FROM ethical_ai WHERE country = 'Asia' AND year = 2020;