instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
Delete wellness trends with a popularity score below 7.0
CREATE TABLE wellness_trends (name VARCHAR(50),description TEXT,popularity_score DECIMAL(3,2));
DELETE FROM wellness_trends WHERE popularity_score < 7.0;
Delete all food safety inspection records for 'Healthy Bites' in 2020.
CREATE TABLE food_safety_inspections (restaurant_id INT,inspection_date DATE,result VARCHAR(10));
DELETE FROM food_safety_inspections WHERE restaurant_id = 4 AND inspection_date BETWEEN '2020-01-01' AND '2020-12-31';
What is the total revenue generated by eco-friendly hotels in Spain?
CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,country TEXT); INSERT INTO hotels (hotel_id,hotel_name,country) VALUES (1,'EcoHotel Madrid','Spain'),(2,'GreenRetreat Barcelona','Spain'); CREATE TABLE bookings (booking_id INT,hotel_id INT,revenue FLOAT); INSERT INTO bookings (booking_id,hotel_id,revenue) VALUES (1,1,200.0),(2,1,300.0),(3,2,400.0);
SELECT SUM(revenue) FROM bookings INNER JOIN hotels ON bookings.hotel_id = hotels.hotel_id WHERE hotels.country = 'Spain' AND hotels.hotel_name LIKE '%eco%';
How many traffic violations were reported in the 'Downtown' area in July 2021?
CREATE TABLE Violations(Date DATE,Location VARCHAR(20),Type VARCHAR(20),Quantity INT); INSERT INTO Violations(Date,Location,Type,Quantity) VALUES ('2021-07-01','Downtown','Speeding',50),('2021-07-01','Downtown','Running Red Light',30),('2021-07-02','Downtown','Speeding',40),('2021-07-02','Downtown','Running Red Light',25);
SELECT SUM(Quantity) FROM Violations WHERE Location = 'Downtown' AND Date BETWEEN '2021-07-01' AND '2021-07-31';
List all defense diplomacy events with the United States and at least one other country in 2019
CREATE TABLE event (event_id INT,country_code_1 VARCHAR(3),country_code_2 VARCHAR(3),event_type VARCHAR(50),event_year INT); INSERT INTO event (event_id,country_code_1,country_code_2,event_type,event_year) VALUES (1,'USA','DEU','defense_diplomacy',2019),(2,'USA','FRA','peacekeeping',2018),(3,'CAN','GBR','defense_diplomacy',2019),(4,'AUS','NZL','military_exercise',2018);
SELECT * FROM event WHERE (country_code_1 = 'USA' AND country_code_2 IS NOT NULL) OR (country_code_2 = 'USA' AND country_code_1 IS NOT NULL) AND event_year = 2019 AND event_type = 'defense_diplomacy';
What is the maximum humidity recorded in Field17 and Field18 in the year 2022?
CREATE TABLE Field17 (date DATE,humidity FLOAT); INSERT INTO Field17 VALUES ('2022-01-01',60),('2022-01-02',65); CREATE TABLE Field18 (date DATE,humidity FLOAT); INSERT INTO Field18 VALUES ('2022-01-01',55),('2022-01-02',60);
SELECT GREATEST(f17.humidity, f18.humidity) as max_humidity FROM Field17 f17 INNER JOIN Field18 f18 ON f17.date = f18.date WHERE EXTRACT(YEAR FROM f17.date) = 2022;
What is the maximum number of emergency calls received in a single day?
CREATE TABLE days (did INT,name TEXT,date TEXT);CREATE TABLE emergencies (eid INT,did INT,date TEXT);
SELECT MAX(emergencies.date) FROM emergencies INNER JOIN days ON emergencies.date = days.date GROUP BY emergencies.date HAVING COUNT(emergencies.eid) = (SELECT MAX(count) FROM (SELECT emergencies.date, COUNT(emergencies.eid) FROM emergencies INNER JOIN days ON emergencies.date = days.date GROUP BY emergencies.date) subquery);
Update the year of 'LA Auto Show' to 2024 in the 'auto_show_information' table
CREATE TABLE auto_show_information (id INT,show_name VARCHAR(50),year INT);
UPDATE auto_show_information SET year = 2024 WHERE show_name = 'LA Auto Show';
Which cybersecurity strategies were implemented in 'Year' 2020?
CREATE TABLE Cybersecurity (id INT,strategy VARCHAR(50),year INT,description VARCHAR(255)); INSERT INTO Cybersecurity (id,strategy,year,description) VALUES (1,'Next-Gen Firewall',2020,'Deployed next-generation firewall for network security. '); INSERT INTO Cybersecurity (id,strategy,year,description) VALUES (2,'Intrusion Detection System',2019,'Implemented Intrusion Detection System in the network. ');
SELECT strategy FROM Cybersecurity WHERE year = 2020;
What is the minimum connection speed for broadband customers in the 'rural' region?
CREATE TABLE subscribers (id INT,connection_type VARCHAR(10),region VARCHAR(10)); INSERT INTO subscribers (id,connection_type,region) VALUES (1,'broadband','rural'),(2,'broadband','rural'),(3,'dialup','rural'); CREATE TABLE connection_speeds (subscriber_id INT,speed INT); INSERT INTO connection_speeds (subscriber_id,speed) VALUES (1,600),(2,550),(3,100);
SELECT MIN(speed) FROM connection_speeds JOIN subscribers ON connection_speeds.subscriber_id = subscribers.id WHERE subscribers.connection_type = 'broadband' AND subscribers.region = 'rural';
What is the total number of police stations in the city of Miami?
CREATE TABLE public.police_stations (id SERIAL PRIMARY KEY,city VARCHAR(255),num_stations INTEGER); INSERT INTO public.police_stations (city,num_stations) VALUES ('Miami',120),('Los Angeles',200),('New York',150);
SELECT num_stations FROM public.police_stations WHERE city = 'Miami';
How many patients diagnosed with Measles in New York are younger than 10?
CREATE TABLE Patients (ID INT,Age INT,Disease VARCHAR(20),State VARCHAR(20)); INSERT INTO Patients (ID,Age,Disease,State) VALUES (1,34,'Tuberculosis','California'); INSERT INTO Patients (ID,Age,Disease,State) VALUES (2,5,'Measles','New York');
SELECT COUNT(*) FROM Patients WHERE Disease = 'Measles' AND State = 'New York' AND Age < 10;
Delete all records from the temperature table for the past month.
CREATE TABLE temperature (id INT,field_id INT,value INT,timestamp TIMESTAMP);
DELETE FROM temperature WHERE timestamp >= NOW() - INTERVAL '1 month';
List all job titles with their average salary and the number of employees in that role.
CREATE TABLE roles (role_id INT,role_title VARCHAR(255),salary INT); INSERT INTO roles (role_id,role_title,salary) VALUES (1,'Manager',70000),(2,'Developer',60000),(3,'Tester',50000); CREATE TABLE employees_roles (emp_id INT,role_id INT); INSERT INTO employees_roles (emp_id,role_id) VALUES (1,1),(2,2),(3,2),(4,3);
SELECT r.role_title, AVG(r.salary) as avg_salary, COUNT(e.emp_id) as num_employees FROM roles r RIGHT JOIN employees_roles er ON r.role_id = er.role_id JOIN employees e ON er.emp_id = e.emp_id GROUP BY r.role_title;
What is the total amount donated by each donor in descending order, along with their respective rank?
CREATE TABLE donors (donor_id INT,donor_name TEXT,amount_donated DECIMAL(10,2)); INSERT INTO donors VALUES (1,'John Doe',500.00),(2,'Jane Smith',300.00),(3,'Alice Johnson',800.00);
SELECT donor_id, donor_name, amount_donated, RANK() OVER (ORDER BY amount_donated DESC) as donor_rank FROM donors;
How many tourists visited Europe from North America in the past year?
CREATE TABLE if NOT EXISTS tourists (id INT,name TEXT,home_region TEXT,visited_region TEXT,visit_date DATE); INSERT INTO tourists (id,name,home_region,visited_region,visit_date) VALUES (1,'John Doe','North America','Europe','2022-01-05'),(2,'Jane Smith','South America','Europe','2021-12-10');
SELECT COUNT(*) FROM tourists WHERE home_region = 'North America' AND visited_region = 'Europe' AND visit_date >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR);
What was the maximum response time for emergency medical services in the first quarter of 2022?
CREATE TABLE ems_incidents (id INT,incident_date DATE,response_time INT); INSERT INTO ems_incidents (id,incident_date,response_time) VALUES (1,'2022-01-01',50),(2,'2022-01-02',60),(3,'2022-01-03',40);
SELECT MAX(response_time) FROM ems_incidents WHERE incident_date BETWEEN '2022-01-01' AND '2022-03-31';
What is the average mission duration for SpaceX's Falcon Heavy?
CREATE TABLE Space_Missions (id INT PRIMARY KEY,name VARCHAR(100),spacecraft VARCHAR(100),launch_date DATE,mission_duration INT); INSERT INTO Space_Missions (id,name,spacecraft,launch_date,mission_duration) VALUES (1,'Mission1','Falcon Heavy','2020-01-01',120),(2,'Mission2','Falcon Heavy','2021-02-02',150);
SELECT AVG(mission_duration) FROM Space_Missions WHERE spacecraft = 'Falcon Heavy';
What is the average program impact score for programs focused on education?
CREATE TABLE programs (program_id INT,program_focus VARCHAR(20),impact_score DECIMAL(3,2)); INSERT INTO programs (program_id,program_focus,impact_score) VALUES (1,'education',78.50),(2,'healthcare',82.30);
SELECT AVG(impact_score) FROM programs WHERE program_focus = 'education';
What is the minimum founding year for companies in the 'E-commerce' sector?
CREATE TABLE companies (id INT,name TEXT,industry TEXT,founding_year INT,funding FLOAT); INSERT INTO companies (id,name,industry,founding_year,funding) VALUES (1,'Acme Inc','E-commerce',2010,1000000.0); INSERT INTO companies (id,name,industry,founding_year,funding) VALUES (2,'Beta Corp','E-commerce',2015,2000000.0);
SELECT MIN(founding_year) FROM companies WHERE industry = 'E-commerce';
What is the maximum claim amount paid to policyholders in 'Alabama' and 'Alaska'?
CREATE TABLE claims (policyholder_id INT,claim_amount DECIMAL(10,2),policyholder_state VARCHAR(20)); INSERT INTO claims (policyholder_id,claim_amount,policyholder_state) VALUES (1,500.00,'Alabama'),(2,900.00,'Alaska'),(3,700.00,'Alabama');
SELECT MAX(claim_amount) FROM claims WHERE policyholder_state IN ('Alabama', 'Alaska');
How many players from Asia have a score greater than 75 in 'Shooter Games'?
CREATE TABLE Players (PlayerID INT,PlayerName VARCHAR(100),Country VARCHAR(50),Game VARCHAR(50),Score INT); INSERT INTO Players (PlayerID,PlayerName,Country,Game,Score) VALUES (1,'John Doe','United States','Racing Games',90); INSERT INTO Players (PlayerID,PlayerName,Country,Game,Score) VALUES (2,'Jane Smith','Canada','Racing Games',80); INSERT INTO Players (PlayerID,PlayerName,Country,Game,Score) VALUES (3,'Leung Chan','China','Shooter Games',85); INSERT INTO Players (PlayerID,PlayerName,Country,Game,Score) VALUES (4,'Park Ji-sung','South Korea','Shooter Games',95);
SELECT COUNT(*) FROM Players WHERE Country LIKE 'Asia%' AND Game = 'Shooter Games' AND Score > 75;
How many recycling centers are in the region 'West'?
CREATE TABLE recycling_centers (region VARCHAR(10),count INT); INSERT INTO recycling_centers (region,count) VALUES ('North',12),('South',15),('East',18),('West',20);
SELECT SUM(count) FROM recycling_centers WHERE region = 'West';
Display the latest soil temperature (in Celsius) for each field
CREATE TABLE soil_temperature (id INT,field VARCHAR(50),temperature FLOAT,timestamp DATETIME); INSERT INTO soil_temperature (id,field,temperature,timestamp) VALUES (1,'Field1',20.0,'2022-01-01 10:00:00'),(2,'Field2',22.0,'2022-01-02 10:00:00');
SELECT field, temperature as latest_soil_temperature FROM soil_temperature WHERE timestamp IN (SELECT MAX(timestamp) FROM soil_temperature GROUP BY field);
What is the total number of properties and the average property price for properties with a housing affordability score greater than 80 in the "GreenCity" schema?
CREATE TABLE Property (id INT,affordability_score INT,price FLOAT,city VARCHAR(20)); INSERT INTO Property (id,affordability_score,price,city) VALUES (1,85,500000,'GreenCity'),(2,70,700000,'GreenCity'),(3,90,300000,'GreenCity');
SELECT COUNT(Property.id) AS total_properties, AVG(Property.price) AS avg_property_price FROM Property WHERE Property.city = 'GreenCity' AND Property.affordability_score > 80;
Identify space missions launched in 2025 with the shortest duration.
CREATE TABLE space_missions(id INT,launch_year INT,duration INT,mission_name VARCHAR(50)); INSERT INTO space_missions(id,launch_year,duration,mission_name) VALUES (1,2005,120,'Mars Explorer 1'); INSERT INTO space_missions(id,launch_year,duration,mission_name) VALUES (2,2025,150,'Astro-Travel 1');
SELECT mission_name FROM space_missions WHERE duration = (SELECT MIN(duration) FROM space_missions WHERE launch_year = 2025);
List the number of lanes and the length of all highways in the road network that have more than 4 lanes.
CREATE TABLE Roads (id INT,name TEXT,num_lanes INT,length REAL); INSERT INTO Roads (id,name,num_lanes,length) VALUES (1,'I-5',6,1381.5),(2,'I-80',4,2899.8),(3,'I-90',4,3020.5);
SELECT num_lanes, length FROM Roads WHERE num_lanes > 4
What is the maximum safe maritime traffic speed for each shipping lane?'
CREATE TABLE shipping_lanes (lane_id INT,name VARCHAR(50),max_safe_speed INT);
SELECT name, max_safe_speed FROM shipping_lanes;
Show menu items with lower prices than the most expensive vegetarian dish.
CREATE TABLE vegetarian_menus (menu_id INT,menu_name VARCHAR(50),menu_type VARCHAR(50),price DECIMAL(5,2)); INSERT INTO vegetarian_menus (menu_id,menu_name,menu_type,price) VALUES (5,'Falafel Salad','Entree',11.99),(6,'Cheese Pizza','Entree',9.99),(7,'Fruit Salad','Entree',8.99);
SELECT menu_name, price FROM menus WHERE menu_type = 'Entree' AND price < (SELECT MAX(price) FROM vegetarian_menus) AND menu_type = 'Entree';
Insert new records into the stops table for a new stop with the following details: stop_id of 116, stop_name of 'Union St', stop_lat of 40.7334, and stop_lon of -73.9921
CREATE TABLE stops (stop_id INT,stop_name VARCHAR(255),stop_lat DECIMAL(9,6),stop_lon DECIMAL(9,6));
INSERT INTO stops (stop_id, stop_name, stop_lat, stop_lon) VALUES (116, 'Union St', 40.7334, -73.9921);
What is the percentage of individuals with visual impairments out of all individuals with disabilities in each location?
CREATE TABLE Individuals (id INT,impairment TEXT,location TEXT); INSERT INTO Individuals (id,impairment,location) VALUES (1,'Visual','Texas'),(2,'Hearing','Texas'),(3,'Visual','California'),(4,'Mobility','California');
SELECT location, COUNT(CASE WHEN impairment = 'Visual' THEN 1 END) * 100.0 / COUNT(*) as percentage FROM Individuals GROUP BY location;
What is the percentage of global Terbium production by Canada?
CREATE TABLE global_production (country VARCHAR(255),element VARCHAR(255),production INT); INSERT INTO global_production (country,element,production) VALUES ('Canada','Terbium',250),('China','Terbium',1500),('Australia','Terbium',750);
SELECT country, (production * 100.0 / (SELECT SUM(production) FROM global_production WHERE element = 'Terbium') ) as percentage FROM global_production WHERE element = 'Terbium' AND country = 'Canada';
What are the research grant titles that have been published in more than one journal?
CREATE TABLE grant (id INT,title VARCHAR(100)); CREATE TABLE publication (id INT,title VARCHAR(100),grant_id INT,journal_name VARCHAR(50));
SELECT g.title FROM grant g JOIN (SELECT grant_id FROM publication GROUP BY grant_id HAVING COUNT(*) > 1) p ON g.id = p.grant_id;
What is the number of circular supply chain products per country?
CREATE TABLE products (product_id INT,product_name VARCHAR(50),country VARCHAR(50),is_circular_supply_chain BOOLEAN); INSERT INTO products (product_id,product_name,country,is_circular_supply_chain) VALUES (1,'T-Shirt','USA',true),(2,'Jeans','Canada',false),(3,'Shoes','Mexico',true),(4,'Dress','Brazil',true),(5,'Bag','Argentina',false);
SELECT country, COUNT(product_id) FROM products WHERE is_circular_supply_chain = true GROUP BY country;
Calculate the percentage of underrepresented minority faculty members in the 'Sciences' department.
CREATE TABLE faculty (faculty_id INT,dept_name VARCHAR(255),is_underrepresented_minority BOOLEAN); INSERT INTO faculty (faculty_id,dept_name,is_underrepresented_minority) VALUES (1,'Humanities',FALSE),(2,'Social Sciences',TRUE),(3,'Sciences',TRUE),(4,'Arts',FALSE);
SELECT dept_name, AVG(is_underrepresented_minority) * 100.0 AS pct_underrepresented FROM faculty WHERE dept_name = 'Sciences' GROUP BY dept_name;
What is the average price of artworks created in the '1930s'?
CREATE TABLE Artworks (id INT,artwork_name VARCHAR(255),year_created INT,price FLOAT); INSERT INTO Artworks (id,artwork_name,year_created,price) VALUES (1,'Composition with Red Blue and Yellow',1930,800000); INSERT INTO Artworks (id,artwork_name,year_created,price) VALUES (2,'The Persistence of Memory',1931,900000); INSERT INTO Artworks (id,artwork_name,year_created,price) VALUES (3,'Girl before a Mirror',1932,700000); INSERT INTO Artworks (id,artwork_name,year_created,price) VALUES (4,'Swing Time',1933,600000); INSERT INTO Artworks (id,artwork_name,year_created,price) VALUES (5,'Guernica',1937,1000000);
SELECT AVG(price) FROM Artworks WHERE year_created BETWEEN 1930 AND 1939;
What is the total revenue for each mobile plan, including taxes, for the year 2021?'
CREATE TABLE mobile_plans (plan_id INT,plan_name VARCHAR(50),monthly_cost DECIMAL(5,2),tax_rate DECIMAL(3,2)); INSERT INTO mobile_plans (plan_id,plan_name,monthly_cost,tax_rate) VALUES (1,'Plan A',30.00,0.07),(2,'Plan B',40.00,0.09); CREATE TABLE sales (sale_id INT,plan_id INT,sale_date DATE,quantity INT);
SELECT m.plan_name, SUM(m.monthly_cost * (1 + m.tax_rate) * s.quantity) AS total_revenue FROM mobile_plans m JOIN sales s ON m.plan_id = s.plan_id WHERE YEAR(sale_date) = 2021 GROUP BY m.plan_name;
What is the total training cost for the IT department in the year 2021?
CREATE TABLE Employees (Employee_ID INT PRIMARY KEY,First_Name VARCHAR(30),Last_Name VARCHAR(30),Department VARCHAR(30)); CREATE TABLE Trainings (Training_ID INT PRIMARY KEY,Training_Name VARCHAR(30),Trainer_Name VARCHAR(30),Department VARCHAR(30),Cost DECIMAL(10,2),Training_Date DATE); INSERT INTO Employees (Employee_ID,First_Name,Last_Name,Department) VALUES (1,'Eli','Williams','IT'); INSERT INTO Trainings (Training_ID,Training_Name,Trainer_Name,Department,Cost,Training_Date) VALUES (1,'Database Management','Frank','IT',1000.00,'2021-02-01');
SELECT SUM(Cost) FROM Trainings WHERE Department = 'IT' AND YEAR(Training_Date) = 2021;
What is the policy type and corresponding weight for each policy, ordered by weight in descending order, for policies issued in 'New York'?
CREATE TABLE Policies (PolicyID INT,PolicyType VARCHAR(20),IssueState VARCHAR(20),Weight DECIMAL(5,2)); INSERT INTO Policies (PolicyID,PolicyType,IssueState,Weight) VALUES (1,'Auto','New York',1800.00),(2,'Home','New York',1300.00),(3,'Life','New York',2200.00);
SELECT PolicyType, Weight FROM Policies WHERE IssueState = 'New York' ORDER BY Weight DESC;
List all mining operations with their environmental impact scores in the Western US.
CREATE TABLE mining_operations(id INT,name VARCHAR,location VARCHAR); CREATE TABLE environmental_impact(operation_id INT,score FLOAT); INSERT INTO mining_operations(id,name,location) VALUES (1,'Golden Mining Co.','Western US'),(2,'Silver Peak Mining','Eastern US'); INSERT INTO environmental_impact(operation_id,score) VALUES (1,78.2),(2,54.1);
SELECT mining_operations.name, environmental_impact.score FROM mining_operations INNER JOIN environmental_impact ON mining_operations.id = environmental_impact.operation_id WHERE mining_operations.location = 'Western US';
Insert a new record for a donor from India with a donation of 3000 USD.
CREATE TABLE donors (id INT,name TEXT,country TEXT,amount_donated DECIMAL(10,2)); INSERT INTO donors (id,name,country,amount_donated) VALUES (1,'Alice','United States',5000.00),(2,'Bob','Canada',6000.00);
INSERT INTO donors (name, country, amount_donated) VALUES ('Charlie', 'India', 3000.00);
Update employee salaries in the Employees table by 5% for the 'Construction' department.
CREATE TABLE Employees (EmployeeID INT,FirstName VARCHAR(50),LastName VARCHAR(50),Position VARCHAR(50),Department VARCHAR(50),Salary DECIMAL(10,2),FOREIGN KEY (EmployeeID) REFERENCES Projects(EmployeeID));
UPDATE Employees SET Salary = Salary * 1.05 WHERE Department = 'Construction';
Insert new records into the 'swimming_events' table for the 50m freestyle, 100m backstroke, and 200m butterfly
CREATE TABLE swimming_events (event_id INT,event_name VARCHAR(50),distance INT,stroke VARCHAR(50));
INSERT INTO swimming_events (event_id, event_name, distance, stroke) VALUES (1, '50m freestyle', 50, 'freestyle'), (2, '100m backstroke', 100, 'backstroke'), (3, '200m butterfly', 200, 'butterfly');
Which department has the highest average salary?
CREATE TABLE Employees (EmployeeID INT,Name VARCHAR(50),Department VARCHAR(50),Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID,Name,Department,Salary) VALUES (1,'John Doe','HR',50000.00),(2,'Jane Smith','IT',60000.00),(3,'Mike Johnson','HR',55000.00); CREATE TABLE Departments (Department VARCHAR(50),Manager VARCHAR(50)); INSERT INTO Departments (Department,Manager) VALUES ('HR','Peter'),('IT','Sarah');
SELECT d.Department, AVG(e.Salary) as AvgSalary FROM Employees e JOIN Departments d ON e.Department = d.Department GROUP BY d.Department ORDER BY AvgSalary DESC LIMIT 1;
What is the maximum financial wellbeing score for women in North America?
CREATE TABLE wellbeing (id INT,region VARCHAR(20),gender VARCHAR(10),score DECIMAL(3,1)); INSERT INTO wellbeing (id,region,gender,score) VALUES (1,'North America','Female',75.5),(2,'Europe','Male',80.0),(3,'Asia-Pacific','Female',72.0);
SELECT MAX(score) FROM wellbeing WHERE region = 'North America' AND gender = 'Female';
What is the average age of volunteers in the volunteers table who have completed exactly 3 training sessions?
CREATE TABLE volunteers (id INT,name VARCHAR(50),age INT,sessions_completed INT);
SELECT AVG(age) FROM volunteers WHERE sessions_completed = 3;
How many solar panels were installed in California between 2015 and 2018?
CREATE TABLE solar_panels (id INT,name TEXT,state TEXT,installation_year INT);
SELECT COUNT(*) FROM solar_panels WHERE state = 'California' AND installation_year BETWEEN 2015 AND 2018;
List the names and salaries of baseball players earning more than $100,000 in the 'baseball_players' table.
CREATE TABLE baseball_players (player_id INT,name VARCHAR(50),salary DECIMAL(10,2)); INSERT INTO baseball_players (player_id,name,salary) VALUES (1,'Jim Brown',120000.00); INSERT INTO baseball_players (player_id,name,salary) VALUES (2,'Mike Johnson',90000.00);
SELECT name, salary FROM baseball_players WHERE salary > 100000.00;
What is the total defense spending for each country in Europe?
CREATE TABLE defense_spending_2 (country VARCHAR(50),continent VARCHAR(50),amount DECIMAL(10,2)); INSERT INTO defense_spending_2 (country,continent,amount) VALUES ('Russia','Europe',61000000000),('France','Europe',57000000000),('Germany','Europe',49000000000),('UK','Europe',48000000000),('Italy','Europe',28000000000);
SELECT country, SUM(amount) as total_defense_spending FROM defense_spending_2 WHERE continent = 'Europe' GROUP BY country;
Which country has the most active players in 'GameF'?
CREATE TABLE player_profiles (player_id INT,player_country VARCHAR(50)); INSERT INTO player_profiles (player_id,player_country) VALUES (1,'USA'),(2,'Canada'),(3,'Mexico'),(4,'Brazil'),(5,'USA'); CREATE TABLE player_games (player_id INT,game_name VARCHAR(100)); INSERT INTO player_games (player_id,game_name) VALUES (1,'GameF'),(2,'GameG'),(3,'GameF'),(4,'GameH'),(5,'GameF');
SELECT player_country, COUNT(player_id) AS active_players FROM player_profiles JOIN player_games ON player_profiles.player_id = player_games.player_id WHERE game_name = 'GameF' GROUP BY player_country ORDER BY active_players DESC LIMIT 1;
Identify the top 3 countries with the largest area of indigenous food systems.
CREATE TABLE indigenous_food_systems (id INT,country TEXT,area FLOAT); INSERT INTO indigenous_food_systems (id,country,area) VALUES (1,'Country 1',500.0),(2,'Country 2',700.0),(3,'Country 3',1000.0);
SELECT country, area FROM indigenous_food_systems ORDER BY area DESC LIMIT 3;
What is the total quantity of 'Fair Trade Coffee' sold last month?
CREATE TABLE beverages (id INT,name VARCHAR(255),qty_sold INT); INSERT INTO beverages (id,name,qty_sold) VALUES (1,'Fair Trade Coffee',400),(2,'Chamomile Tea',300),(3,'Lemonade',200); CREATE TABLE date (id INT,date DATE); INSERT INTO date (id,date) VALUES (1,'2022-02-01'),(2,'2022-02-08'),(3,'2022-02-15'),(4,'2022-02-22');
SELECT SUM(qty_sold) AS total_qty_sold FROM beverages WHERE name = 'Fair Trade Coffee' AND date IN (SELECT date FROM date WHERE date BETWEEN DATE_SUB(NOW(), INTERVAL 2 MONTH) AND DATE_SUB(NOW(), INTERVAL 1 MONTH));
What is the most common treatment approach for patients with depression in Texas in 2020?
CREATE TABLE treatments_tx (patient_id INT,condition VARCHAR(20),treatment VARCHAR(10),state VARCHAR(20),year INT); INSERT INTO treatments_tx VALUES (1,'Depression','CBT','Texas',2020),(2,'Depression','DBT','Texas',2020),(3,'Anxiety','CBT','Texas',2020);
SELECT treatment, COUNT(*) AS count FROM treatments_tx WHERE condition = 'Depression' AND state = 'Texas' AND year = 2020 GROUP BY treatment ORDER BY count DESC LIMIT 1;
What is the average age of athletes in the basketball_players table?
CREATE TABLE basketball_players (player_id INT,name VARCHAR(50),age INT,position VARCHAR(20)); INSERT INTO basketball_players (player_id,name,age,position) VALUES (1,'John Doe',25,'Guard'); INSERT INTO basketball_players (player_id,name,age,position) VALUES (2,'Jane Smith',30,'Forward');
SELECT AVG(age) FROM basketball_players;
Count the number of visitors who visited multiple museums
CREATE TABLE MuseumVisitors (visitor_id INT,museum_id INT); INSERT INTO MuseumVisitors (visitor_id,museum_id) VALUES (1,100),(2,101),(3,100),(4,102),(5,101),(6,100),(7,102);
SELECT COUNT(*) FROM (SELECT visitor_id FROM MuseumVisitors GROUP BY visitor_id HAVING COUNT(DISTINCT museum_id) > 1) subquery;
What is the total number of hotels using AI chatbots in 'Tokyo' as of 2022?
CREATE TABLE ai_adoption (hotel_id INT,city TEXT,ai_chatbot BOOLEAN,year INT); INSERT INTO ai_adoption (hotel_id,city,ai_chatbot,year) VALUES (1,'Tokyo',true,2022),(2,'Tokyo',false,2022),(3,'Osaka',true,2022);
SELECT COUNT(*) FROM ai_adoption WHERE city = 'Tokyo' AND ai_chatbot = true AND year = 2022;
What is the average price of vegan menu items sold in the Pacific Northwest region?
CREATE TABLE menu (menu_id INT,menu_name TEXT,menu_type TEXT,price DECIMAL,daily_sales INT,region TEXT); CREATE VIEW vegan_menu AS SELECT * FROM menu WHERE menu_type = 'vegan';
SELECT AVG(price) FROM vegan_menu WHERE region = 'Pacific Northwest';
Calculate the average age of athletes from India who participated in the Olympics in the 'olympics_athletes' table?
CREATE TABLE olympics_athletes (athlete_id INT,name VARCHAR(50),age INT,country VARCHAR(50),participated_in_olympics INT);
SELECT AVG(age) FROM olympics_athletes WHERE country = 'India' AND participated_in_olympics = 1;
How many news articles were published about climate change in the last year, for publications 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'),(2,'Political Turmoil in Europe','2022-02-13','Politics','United Kingdom');
SELECT COUNT(*) FROM news_articles WHERE topic = 'Climate Change' AND publication_country = 'United States' AND publication_date >= DATEADD(year, -1, GETDATE());
How many volunteers engaged in arts and culture programs in H1 2022?
CREATE TABLE Volunteers (id INT,user_id INT,program_id INT,volunteer_date DATE); INSERT INTO Volunteers (id,user_id,program_id,volunteer_date) VALUES (1,1001,401,'2022-02-10'); INSERT INTO Volunteers (id,user_id,program_id,volunteer_date) VALUES (2,1002,402,'2022-06-15'); INSERT INTO Volunteers (id,user_id,program_id,volunteer_date) VALUES (3,1003,401,'2022-04-15');
SELECT COUNT(*) FROM Volunteers WHERE program_id BETWEEN 401 AND 410 AND volunteer_date >= '2022-01-01' AND volunteer_date < '2022-07-01';
What is the total number of satellites launched by the US and Russia?
CREATE TABLE Satellite_Table (id INT,satellite_name VARCHAR(100),country_launched VARCHAR(50));
SELECT COUNT(*) FROM Satellite_Table WHERE COUNTRY_LAUNCHED IN ('United States', 'Russia');
Which athletes participated in the athlete_wellbeing program and their corresponding team?
CREATE TABLE athlete_wellbeing (id INT,athlete VARCHAR(50),team VARCHAR(50),program VARCHAR(50),date DATE);
SELECT athlete, team FROM athlete_wellbeing;
What is the maximum age of employees in the HR department?
CREATE TABLE Employees (id INT,name VARCHAR(50),age INT,department VARCHAR(50)); INSERT INTO Employees (id,name,age,department) VALUES (1,'John Doe',35,'HR'),(2,'Jane Smith',30,'HR');
SELECT MAX(age) FROM Employees WHERE department = 'HR';
List the names of all the farmers who have sold crops worth more than $5000 in the 'organic' market.
CREATE TABLE farmers (id INT,name VARCHAR(30),crop_sold VARCHAR(20),sold_amount DECIMAL(6,2)); CREATE TABLE market (id INT,name VARCHAR(10),type VARCHAR(10));
SELECT farmers.name FROM farmers, market WHERE farmers.crop_sold = market.name AND market.type = 'organic' GROUP BY farmers.name HAVING SUM(sold_amount) > 5000;
What is the percentage of hotels that have adopted AI chatbots in each city?
CREATE TABLE hotels (hotel_id INT,hotel_name TEXT,city TEXT); INSERT INTO hotels (hotel_id,hotel_name,city) VALUES (1,'Hotel X','New York City'),(2,'Hotel Y','Chicago'),(3,'Hotel Z','Los Angeles'); CREATE TABLE ai_chatbots (hotel_id INT,chatbot_name TEXT); INSERT INTO ai_chatbots (hotel_id,chatbot_name) VALUES (1,'Chatbot A'),(3,'Chatbot B'),(4,'Chatbot C');
SELECT city, (COUNT(DISTINCT hotels.hotel_id) / (SELECT COUNT(DISTINCT hotel_id) FROM hotels WHERE city = hotels.city) * 100) as pct_hotels_with_chatbots FROM hotels INNER JOIN ai_chatbots ON hotels.hotel_id = ai_chatbots.hotel_id GROUP BY city;
What is the percentage of products in each category that are organic, ranked in ascending order of percentage?
CREATE TABLE products (product_id INT,category VARCHAR(20),is_organic BOOLEAN); INSERT INTO products (product_id,category,is_organic) VALUES (1,'Natural',false),(2,'Organic',true),(3,'Natural',true),(4,'Conventional',false);
SELECT category, 100.0 * COUNT(*) FILTER (WHERE is_organic) / COUNT(*) as percentage FROM products GROUP BY category ORDER BY percentage ASC;
What is the highest temperature recorded per city in the 'crop_weather' table?
CREATE TABLE crop_weather (city VARCHAR(50),temperature INT,month INT); INSERT INTO crop_weather (city,temperature,month) VALUES ('CityA',15,4),('CityA',18,4),('CityB',20,4),('CityB',22,4),('CityA',25,5),('CityA',28,5),('CityB',26,5),('CityB',30,5);
SELECT city, MAX(temperature) as max_temp FROM crop_weather GROUP BY city;
How many vessels were inspected in the last year for maritime law compliance?
CREATE TABLE vessel_inspections (id INT,inspection_date DATE,vessel_name TEXT); INSERT INTO vessel_inspections (id,inspection_date,vessel_name) VALUES (1,'2021-05-12','Vessel X'),(2,'2021-07-15','Vessel Y'),(3,'2020-11-28','Vessel Z');
SELECT COUNT(*) FROM vessel_inspections WHERE inspection_date >= DATEADD(year, -1, CURRENT_DATE);
What is the maximum financial wellbeing score for individuals in Nigeria?
CREATE TABLE financial_wellbeing (person_id INT,country VARCHAR,score FLOAT); INSERT INTO financial_wellbeing (person_id,country,score) VALUES (1,'Nigeria',70); INSERT INTO financial_wellbeing (person_id,country,score) VALUES (2,'Nigeria',85);
SELECT MAX(score) FROM financial_wellbeing WHERE country = 'Nigeria';
How many members joined in Q1 and Q3 of 2021, by region?
CREATE TABLE memberships (membership_id INT,join_date DATE,region VARCHAR(20)); INSERT INTO memberships (membership_id,join_date,region) VALUES (1,'2021-01-05','North'),(2,'2021-04-10','South'),(3,'2021-07-22','East');
SELECT COUNT(*) as q1_q3_count, region FROM memberships WHERE (EXTRACT(QUARTER FROM join_date) = 1) OR (EXTRACT(QUARTER FROM join_date) = 3) GROUP BY region;
Which country had the highest calorie intake per person in 2021?
CREATE TABLE CountryFoodIntake (CountryName VARCHAR(50),Year INT,CaloriesPerPerson INT); INSERT INTO CountryFoodIntake (CountryName,Year,CaloriesPerPerson) VALUES ('United States',2021,3800),('Mexico',2021,3400),('Italy',2021,3200),('Japan',2021,2800),('India',2021,2500);
SELECT CountryName, MAX(CaloriesPerPerson) FROM CountryFoodIntake WHERE Year = 2021 GROUP BY CountryName;
What is the sum of renewable energy capacity (wind and solar) for each country, ranked by the total capacity?
CREATE TABLE renewable_energy_capacity (country VARCHAR(50),wind_capacity NUMERIC(5,2),solar_capacity NUMERIC(5,2)); INSERT INTO renewable_energy_capacity (country,wind_capacity,solar_capacity) VALUES ('Germany',30.0,20.0),('France',40.0,30.0),('Canada',50.0,40.0),('Brazil',NULL,45.0),('India',10.0,NULL);
SELECT country, SUM(wind_capacity + solar_capacity) OVER (PARTITION BY country) AS total_capacity, RANK() OVER (ORDER BY SUM(wind_capacity + solar_capacity) DESC) AS rank FROM renewable_energy_capacity WHERE wind_capacity IS NOT NULL AND solar_capacity IS NOT NULL GROUP BY country;
What is the average age of employees in each department?
CREATE TABLE Employees (EmployeeID int,Department varchar(20),Age int); INSERT INTO Employees (EmployeeID,Department,Age) VALUES (1,'HR',30),(2,'IT',35),(3,'Sales',28);
SELECT Department, AVG(Age) FROM Employees GROUP BY Department;
How many wind farms are there in the 'renewable_energy' schema?
CREATE SCHEMA renewable_energy; CREATE TABLE wind_farms (id INT,name VARCHAR(100),capacity FLOAT); INSERT INTO wind_farms (id,name,capacity) VALUES (1,'Wind Farm I',60.0),(2,'Wind Farm J',80.0);
SELECT COUNT(*) FROM renewable_energy.wind_farms;
What is the maximum sale price for each medium?
CREATE TABLE Artwork (ArtworkID INT,Title VARCHAR(100),Type VARCHAR(50),Price FLOAT); INSERT INTO Artwork VALUES (1,'The Persistence of Memory','Painting',15000000); INSERT INTO Artwork VALUES (2,'The Starry Night','Painting',2000000); INSERT INTO Artwork VALUES (3,'The Scream','Print',10000000); INSERT INTO Artwork VALUES (4,'The Last Supper','Mural',100000000);
SELECT A.Type, MAX(A.Price) FROM Artwork A GROUP BY A.Type;
What is the average size of fishing vessels in the Southern Hemisphere?
CREATE TABLE fishing_vessels (id INT,name VARCHAR(255),region VARCHAR(255),length FLOAT); INSERT INTO fishing_vessels (id,name,region,length) VALUES (1,'Vessel A','Northern Hemisphere',50.5); INSERT INTO fishing_vessels (id,name,region,length) VALUES (2,'Vessel B','Southern Hemisphere',60.3); INSERT INTO fishing_vessels (id,name,region,length) VALUES (3,'Vessel C','Northern Hemisphere',70.2);
SELECT AVG(length) FROM fishing_vessels WHERE region = 'Southern Hemisphere';
How many eco-friendly hotels are there in 'Canada'?
CREATE TABLE hotels (id INT,name TEXT,country TEXT,is_eco BOOLEAN); INSERT INTO hotels (id,name,country,is_eco) VALUES (1,'Eco Hotel Toronto','Canada',TRUE);
SELECT COUNT(*) FROM hotels WHERE country = 'Canada' AND is_eco = TRUE;
What is the name and launch date of the space technology launched in the last quarter of 2021?
CREATE TABLE space_tech (id INT,name VARCHAR(50),launch_date DATE); INSERT INTO space_tech (id,name,launch_date) VALUES (1,'SpaceTech1','2021-10-01'); INSERT INTO space_tech (id,name,launch_date) VALUES (2,'SpaceTech2','2021-12-15');
SELECT name, launch_date, ROW_NUMBER() OVER (ORDER BY launch_date DESC) AS rank FROM space_tech WHERE launch_date >= '2021-10-01' AND launch_date < '2022-01-01';
What is the total number of police stations in New York City?
CREATE TABLE nyc_police_stations (id INT,station_name VARCHAR(20),location VARCHAR(20)); INSERT INTO nyc_police_stations (id,station_name,location) VALUES (1,'1st Precinct','Manhattan'),(2,'2nd Precinct','Manhattan');
SELECT COUNT(*) FROM nyc_police_stations;
What is the total budget spent on ethical AI initiatives by organizations in the top 3 regions with the highest budget?
CREATE TABLE organization (org_id INT,org_name TEXT,region TEXT,budget FLOAT); INSERT INTO organization (org_id,org_name,region,budget) VALUES (1,'ABC Tech','Asia-Pacific',500000.00),(2,'XYZ Research','North America',800000.00),(3,'Global Innovations','Europe',600000.00),(4,'Tech for Good','South America',300000.00),(5,'Accessible AI','Asia-Pacific',700000.00);
SELECT SUM(budget) FROM (SELECT region, budget FROM organization ORDER BY budget DESC LIMIT 3) AS top_regions;
What is the average number of traditional art pieces per artist?
CREATE TABLE traditional_art (id INT,artist VARCHAR(50),title VARCHAR(100)); INSERT INTO traditional_art (id,artist,title) VALUES (1,'Picasso','Guernica'),(2,'Dali','Persistence of Memory'),(3,'Picasso','Three Musicians');
SELECT AVG(art_count) FROM (SELECT artist, COUNT(*) AS art_count FROM traditional_art GROUP BY artist) AS art_counts;
How many marine mammal species are in the Indian Ocean?
CREATE TABLE IndianOcean (mammal_species TEXT,population INT); INSERT INTO IndianOcean (mammal_species,population) VALUES ('Blue Whale',2000),('Dugong',1000),('Sperm Whale',1500);
SELECT COUNT(mammal_species) FROM IndianOcean WHERE mammal_species LIKE '%mammal%';
List the unique Green Building certification names and their corresponding year of establishment in descending order.
CREATE SCHEMA green_buildings; CREATE TABLE certifications (certification_name VARCHAR(255),year_established INT); INSERT INTO certifications (certification_name,year_established) VALUES ('LEED',1998),('BREEAM',1990),('Green Star',2002),('WELL',2014);
SELECT DISTINCT certification_name, year_established FROM green_buildings.certifications ORDER BY year_established DESC;
Identify the top three countries with the highest average bridge construction cost.
CREATE TABLE Bridge (Country VARCHAR(50),Cost FLOAT); INSERT INTO Bridge (Country,Cost) VALUES ('Canada',10000000),('USA',12000000),('Mexico',8000000),('Brazil',9000000);
SELECT Country, AVG(Cost) as Avg_Cost, ROW_NUMBER() OVER (ORDER BY Avg_Cost DESC) as Rank FROM Bridge GROUP BY Country HAVING Rank <= 3;
How many customers are there in 'London' with a balance greater than 20000?
CREATE TABLE customers (id INT,name VARCHAR(50),city VARCHAR(50),balance DECIMAL(10,2)); INSERT INTO customers (id,name,city,balance) VALUES (1,'John Doe','New York',15000.50); INSERT INTO customers (id,name,city,balance) VALUES (2,'Jane Smith','Los Angeles',12000.00); INSERT INTO customers (id,name,city,balance) VALUES (3,'Jim Brown','London',25000.00);
SELECT COUNT(*) FROM customers WHERE city = 'London' AND balance > 20000;
Find the number of building permits issued in each state, sorted by the number of permits in descending order
CREATE TABLE building_permits_2 (permit_id INT,state VARCHAR(20),issue_date DATE); INSERT INTO building_permits_2 (permit_id,state,issue_date) VALUES (1,'WA','2021-01-01'),(2,'OR','2021-01-02'),(3,'CA','2021-01-03');
SELECT state, COUNT(*) as permit_count FROM building_permits_2 GROUP BY state ORDER BY permit_count DESC;
What is the average number of employees in factories located in Africa in the textile industry?
CREATE TABLE factories_2 (id INT,industry VARCHAR(50),region VARCHAR(50),number_of_employees INT); INSERT INTO factories_2 (id,industry,region,number_of_employees) VALUES (1,'Textile','Africa',300),(2,'Automotive','Europe',500),(3,'Textile','Africa',400),(4,'Aerospace','North America',1500),(5,'Textile','Asia',600);
SELECT AVG(number_of_employees) FROM factories_2 WHERE industry = 'Textile' AND region = 'Africa';
Create a table for storing autonomous vehicle testing data
CREATE TABLE autonomous_testing (id INT PRIMARY KEY,location VARCHAR(100),company VARCHAR(100),date DATE,miles_driven INT);
CREATE TABLE autonomous_testing (id INT PRIMARY KEY, location VARCHAR(100), company VARCHAR(100), date DATE, miles_driven INT);
Find the top 5 cities with the most emergency calls in the state of Texas in the year 2021.
CREATE TABLE emergency_calls (id INT,city VARCHAR(20),state VARCHAR(20),year INT); INSERT INTO emergency_calls (id,city,state,year) VALUES (1,'Houston','Texas',2021),(2,'Dallas','Texas',2021),(3,'Austin','Texas',2021); CREATE TABLE calls_by_city (num_calls INT,city VARCHAR(20)); INSERT INTO calls_by_city (num_calls,city) SELECT COUNT(*),city FROM emergency_calls GROUP BY city;
SELECT city, num_calls FROM calls_by_city WHERE state = 'Texas' AND year = 2021 ORDER BY num_calls DESC LIMIT 5;
What is the total number of students who received accommodations in the "West Coast" region in 2020?
CREATE TABLE Accommodations (student_id INT,region VARCHAR(20),accommodation_date DATE); INSERT INTO Accommodations (student_id,region,accommodation_date) VALUES (1,'West Coast','2020-01-01'),(2,'East Coast','2019-12-31'),(3,'West Coast','2020-02-01');
SELECT COUNT(*) FROM Accommodations WHERE region = 'West Coast' AND EXTRACT(YEAR FROM accommodation_date) = 2020;
Who are the top 5 cities with the most public libraries in California?
CREATE TABLE public_libraries (id INT,name VARCHAR(255),city VARCHAR(255),state VARCHAR(255)); INSERT INTO public_libraries (id,name,city,state) VALUES (1,'Library 1','City A','CA'); INSERT INTO public_libraries (id,name,city,state) VALUES (2,'Library 2','City B','CA');
SELECT city, COUNT(*) AS library_count FROM public_libraries WHERE state = 'CA' GROUP BY city ORDER BY library_count DESC LIMIT 5;
Find the total number of species of marine life in each ocean basin.
CREATE TABLE marine_life_species (species_name TEXT,ocean_basin TEXT,threat_status TEXT);
SELECT ocean_basin, COUNT(*) FROM marine_life_species GROUP BY ocean_basin;
Find the number of research grants awarded per year, in descending order of grant year.
CREATE TABLE grants (grant_id INT,grant_year INT,grant_amount INT);
SELECT grant_year, COUNT(*) FROM grants GROUP BY grant_year ORDER BY grant_year DESC;
What is the average citizen satisfaction score for waste management services in the city of Los Angeles?
CREATE SCHEMA gov_data;CREATE TABLE gov_data.citizen_satisfaction_scores (city VARCHAR(20),service VARCHAR(20),score INT); INSERT INTO gov_data.citizen_satisfaction_scores (city,service,score) VALUES ('Los Angeles','Waste Management',70),('Los Angeles','Public Libraries',85),('Los Angeles','Parks',90);
SELECT AVG(score) FROM gov_data.citizen_satisfaction_scores WHERE city = 'Los Angeles' AND service = 'Waste Management';
What is the average number of posts per day for users in the music industry?
CREATE TABLE user_stats (user_id INT,stat_type VARCHAR(50),stat_date DATE,value INT); INSERT INTO user_stats (user_id,stat_type,stat_date,value) VALUES (1,'posts','2022-01-01',1),(2,'posts','2022-01-01',2),(1,'posts','2022-01-02',2);
SELECT AVG(value) FROM user_stats WHERE stat_type = 'posts' AND stat_date >= DATEADD(day, -30, GETDATE()) AND stat_date < DATEADD(day, -29, GETDATE()) AND user_id IN (SELECT id FROM users WHERE industry = 'music');
What is the average ticket price for concerts with attendance over 10000 for artists who identify as male and are from Oceania in 2024?
CREATE TABLE concert_events (event_id INT,artist_id INT,event_date DATE,event_location VARCHAR(255),attendance INT,ticket_price DECIMAL(10,2),country VARCHAR(50)); INSERT INTO concert_events (event_id,artist_id,event_date,event_location,attendance,ticket_price,country) VALUES (1,1,'2024-01-01','NYC',15000,50.00,'Australia'); CREATE TABLE artist_demographics (artist_id INT,artist_name VARCHAR(255),gender VARCHAR(50),ethnicity VARCHAR(50),country VARCHAR(50)); INSERT INTO artist_demographics (artist_id,artist_name,gender,ethnicity,country) VALUES (1,'John Doe','male','Oceanian','Australia');
SELECT AVG(ticket_price) FROM concert_events ce JOIN artist_demographics ad ON ce.artist_id = ad.artist_id WHERE ce.attendance > 10000 AND ad.gender = 'male' AND ad.ethnicity = 'Oceanian' AND ce.event_date BETWEEN '2024-01-01' AND '2024-12-31';
Add new records of users who have registered for a course in the last month to the users table
CREATE TABLE users (id INT,name VARCHAR(50),email VARCHAR(50),registered_for_course BOOLEAN);
INSERT INTO users (name, email, registered_for_course) SELECT name, email, true FROM course_registrations WHERE registration_date > DATE_SUB(CURDATE(), INTERVAL 1 MONTH);
Update the 'employee_details' table and set the 'safety_training_status' to 'completed' for all employees in the 'mining' department
CREATE TABLE employee_details (id INT,name VARCHAR(50),department VARCHAR(20),safety_training_status VARCHAR(20));
UPDATE employee_details SET safety_training_status = 'completed' WHERE department = 'mining';
What is the total sales of gastroenterology drugs in Brazil?
CREATE TABLE sales_data (drug_name VARCHAR(50),country VARCHAR(50),sales_amount NUMERIC(10,2)); INSERT INTO sales_data (drug_name,country,sales_amount) VALUES ('DrugL','Brazil',8500000),('DrugM','Brazil',9500000),('DrugN','Brazil',7500000);
SELECT SUM(sales_amount) FROM sales_data WHERE drug_category = 'Gastroenterology' AND country = 'Brazil';
How many professional development courses were completed by teachers in the "West" region in 2021?
CREATE TABLE regions (region VARCHAR(20)); INSERT INTO regions (region) VALUES ('North'),('South'),('East'),('West'); CREATE TABLE courses (course_id INT,teacher_id INT,course_name VARCHAR(50),completion_date DATE); INSERT INTO courses (course_id,teacher_id,course_name,completion_date) VALUES (1,1,'PD1','2021-01-01'),(2,2,'PD2','2021-03-15'),(3,3,'PD3','2020-12-31'),(4,4,'PD4','2021-06-05'),(5,5,'PD5','2021-11-30');
SELECT COUNT(*) FROM courses JOIN regions ON courses.teacher_id = (SELECT teacher_id FROM teachers WHERE teachers.region = 'West') WHERE YEAR(completion_date) = 2021 AND course_name LIKE 'PD%';