instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
What is the average depth of marine life research stations in the Pacific Ocean?
CREATE TABLE marine_life_research_stations (station_id INT,station_name TEXT,location TEXT,depth FLOAT); INSERT INTO marine_life_research_stations (station_id,station_name,location,depth) VALUES (1,'Station A','Pacific Ocean',3000.5),(2,'Station B','Atlantic Ocean',4000.2);
SELECT AVG(depth) FROM marine_life_research_stations WHERE location = 'Pacific Ocean';
What is the monthly trend of transactions for each customer in the past year?
CREATE TABLE customers (customer_id INT,name VARCHAR(50)); CREATE TABLE transactions (transaction_id INT,customer_id INT,trans_date DATE,amount DECIMAL(10,2)); INSERT INTO customers (customer_id,name) VALUES (1,'John Smith'),(2,'Sarah Lee'); INSERT INTO transactions (transaction_id,customer_id,trans_date,amount) VALUES (1,1,'2021-06-01',500.00),(2,1,'2021-06-15',200.00),(3,2,'2021-07-03',150.00);
SELECT customer_id, DATE_TRUNC('month', trans_date) AS month, AVG(amount) AS avg_monthly_trans FROM transactions GROUP BY customer_id, month ORDER BY customer_id, month;
Show recycling rates for Germany for the year 2021
CREATE TABLE recycling_rates (country VARCHAR(50),year INT,rate DECIMAL(5,2));
SELECT rate FROM recycling_rates WHERE country = 'Germany' AND year = 2021;
How many volunteers signed up in '2022' for the 'Food Support' program?
CREATE TABLE volunteers (id INT,volunteer_name TEXT,program TEXT,signup_date DATE); INSERT INTO volunteers (id,volunteer_name,program,signup_date) VALUES (1,'Alice','Food Support','2022-01-01'); INSERT INTO volunteers (id,volunteer_name,program,signup_date) VALUES (2,'Bob','Food Support','2022-03-10');
SELECT COUNT(*) FROM volunteers WHERE program = 'Food Support' AND YEAR(signup_date) = 2022;
Who is the leading goal scorer in the history of the UEFA Champions League?
CREATE TABLE ucl_goals (player_name VARCHAR(50),goals INT,assists INT); INSERT INTO ucl_goals (player_name,goals,assists) VALUES ('Cristiano Ronaldo',140,42),('Lionel Messi',125,35);
SELECT player_name, SUM(goals) as total_goals FROM ucl_goals GROUP BY player_name ORDER BY total_goals DESC LIMIT 1;
Which vessels have caused more than 15 pollution incidents in the Mediterranean sea?
CREATE TABLE Vessels (id INT PRIMARY KEY,name VARCHAR(255),type VARCHAR(255),length FLOAT,year_built INT); CREATE TABLE Pollution_Incidents (id INT PRIMARY KEY,incident_date DATE,latitude FLOAT,longitude FLOAT,vessel_id INT,country VARCHAR(255),FOREIGN KEY (vessel_id) REFERENCES Vessels(id));
SELECT Vessels.name, COUNT(Pollution_Incidents.id) FROM Vessels JOIN Pollution_Incidents ON Vessels.id = Pollution_Incidents.vessel_id WHERE country = 'Mediterranean sea' GROUP BY Vessels.name HAVING COUNT(Pollution_Incidents.id) > 15;
How many total supplies were delivered to Colombia in 2021?
CREATE TABLE supplies (id INT,country TEXT,year INT,quantity INT); INSERT INTO supplies (id,country,year,quantity) VALUES (1,'Colombia',2019,300); INSERT INTO supplies (id,country,year,quantity) VALUES (2,'Colombia',2021,500); INSERT INTO supplies (id,country,year,quantity) VALUES (3,'Mexico',2020,400);
SELECT SUM(quantity) FROM supplies WHERE country = 'Colombia' AND year = 2021;
Insert new customer records for 'John Smith', '123 Main St', 'Los Angeles', 'CA', '90001'
CREATE TABLE customers (customer_id INT PRIMARY KEY,first_name VARCHAR(255),last_name VARCHAR(255),address VARCHAR(255),city VARCHAR(255),state VARCHAR(255),zip_code VARCHAR(255));
INSERT INTO customers (customer_id, first_name, last_name, address, city, state, zip_code) VALUES (NULL, 'John', 'Smith', '123 Main St', 'Los Angeles', 'CA', '90001');
What percentage of cosmetic products sold in the EU has been involved in a product safety incident in the last 5 years?
CREATE TABLE Products (Product_ID INT,Product_Name TEXT,Is_EU_Based BOOLEAN); INSERT INTO Products (Product_ID,Product_Name,Is_EU_Based) VALUES (1,'Lush Dream Cream',true),(2,'Estée Lauder Double Wear Foundation',false),(3,'The Body Shop Vitamin E Moisture Cream',true); CREATE TABLE Safety_Incidents (Incident_ID INT,Product_ID INT,Incident_Date DATE); INSERT INTO Safety_Incidents (Incident_ID,Product_ID,Incident_Date) VALUES (1,2,'2020-03-15'),(2,1,'2019-08-04'),(3,3,'2021-02-20'),(4,1,'2020-12-09');
SELECT (COUNT(DISTINCT P.Product_ID) * 100.0 / (SELECT COUNT(DISTINCT Product_ID) FROM Products WHERE Is_EU_Based = true)) AS Percentage FROM Safety_Incidents SI INNER JOIN Products P ON SI.Product_ID = P.Product_ID WHERE SI.Incident_Date >= DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR);
Update the 'battery_range' column in the 'electric_vehicle_stats' table to 250 for the record with id 3
CREATE TABLE electric_vehicle_stats (id INT,make TEXT,model TEXT,battery_range INT); INSERT INTO electric_vehicle_stats (id,make,model,battery_range) VALUES (1,'Tesla','Model 3',263),(2,'Chevrolet','Bolt',259),(3,'Nissan','Leaf',226);
WITH cte AS (UPDATE electric_vehicle_stats SET battery_range = 250 WHERE id = 3) SELECT * FROM cte;
What are the names of all the movies that have a rating greater than or equal to 8?
CREATE TABLE movies (id INT,title VARCHAR(255),rating FLOAT); INSERT INTO movies (id,title,rating) VALUES (1,'MovieA',7.5),(2,'MovieB',8.2),(3,'MovieC',6.8),(4,'MovieD',9.0);
SELECT title FROM movies WHERE rating >= 8;
What is the average ticket price for dance performances in Europe in Q1 2022?
CREATE TABLE CulturalEvents (id INT,region VARCHAR(20),quarter INT,year INT,category VARCHAR(20),price FLOAT); INSERT INTO CulturalEvents (id,region,quarter,year,category,price) VALUES (3,'Europe',1,2022,'Dance',30); INSERT INTO CulturalEvents (id,region,quarter,year,category,price) VALUES (4,'Europe',1,2022,'Theater',40);
SELECT AVG(price) FROM CulturalEvents WHERE region = 'Europe' AND quarter = 1 AND year = 2022 AND category = 'Dance';
List all cargo types and their corresponding weights from the 'cargo_tracking' table.
CREATE TABLE cargo_tracking (cargo_id INT,cargo_type VARCHAR(50),weight FLOAT); INSERT INTO cargo_tracking (cargo_id,cargo_type,weight) VALUES (1,'CargoType1',5000),(2,'CargoType2',7000),(3,'CargoType3',6000);
SELECT cargo_type, weight FROM cargo_tracking;
What was the total budget spent on community outreach events in Q3 2021?
CREATE TABLE Budget (BudgetID INT,Category TEXT,Amount DECIMAL(10,2),SpendDate DATE); INSERT INTO Budget (BudgetID,Category,Amount,SpendDate) VALUES (1,'Supplies',1500,'2021-07-05'),(2,'Salaries',5000,'2021-08-28'),(3,'Rent',2000,'2021-09-30'),(4,'Community Outreach',8000,'2021-07-14'),(5,'Community Outreach',6000,'2021-09-20');
SELECT Category, SUM(Amount) as TotalBudget FROM Budget WHERE SpendDate BETWEEN '2021-07-01' AND '2021-09-30' AND Category = 'Community Outreach' GROUP BY Category;
How many concerts were held in Los Angeles in the last 3 years?
CREATE TABLE Concerts (location VARCHAR(50),year INT); INSERT INTO Concerts (location,year) VALUES ('Los Angeles',2019),('New York',2020),('Los Angeles',2020),('Los Angeles',2021),('Chicago',2019);
SELECT COUNT(*) FROM Concerts WHERE location = 'Los Angeles' AND year >= (SELECT MAX(year) - 3 FROM Concerts);
What is the total number of employees hired in 2021?
CREATE TABLE Employees (EmployeeID INT,Name VARCHAR(50),HireDate DATE); INSERT INTO Employees (EmployeeID,Name,HireDate) VALUES (1,'John Doe','2021-01-01'),(2,'Jane Smith','2021-02-14'),(3,'Mike Johnson','2020-12-01');
SELECT COUNT(*) FROM Employees WHERE YEAR(HireDate) = 2021;
How many users in each gender category have a membership that includes group classes?
CREATE TABLE membership_types (id INT,user_id INT,membership_type VARCHAR(20)); INSERT INTO membership_types (id,user_id,membership_type) VALUES (1,1,'Individual'),(2,2,'Family'),(3,3,'Group'); CREATE TABLE group_classes (id INT,user_id INT,class_name VARCHAR(50)); INSERT INTO group_classes (id,user_id,class_name) VALUES (1,1,'Yoga'),(2,3,'Spinning');
SELECT membership_type, COUNT(*) FROM membership_types m JOIN group_classes g ON m.user_id = g.user_id GROUP BY membership_type;
What is the total timber production in temperate forests in the United States?
CREATE TABLE TimberProduction (id INT,name VARCHAR(255),region VARCHAR(255),year INT,production FLOAT); INSERT INTO TimberProduction (id,name,region,year,production) VALUES (1,'Temperate Forest','United States',2015,30000);
SELECT SUM(production) FROM TimberProduction WHERE name = 'Temperate Forest' AND region = 'United States';
What are the top 3 music genres by total listening time in the United States?
CREATE TABLE music_streams (user_id INT,genre VARCHAR(255),listening_time FLOAT); CREATE TABLE countries (country_code CHAR(2),country_name VARCHAR(255)); CREATE VIEW stream_summary AS SELECT genre,SUM(listening_time) as total_time FROM music_streams GROUP BY genre; CREATE VIEW country_summary AS SELECT country_code,country_name FROM countries;
SELECT genre, total_time FROM ( SELECT genre, total_time, ROW_NUMBER() OVER (ORDER BY total_time DESC) as rank FROM stream_summary ) subquery WHERE rank <= 3;
What is the maximum flight safety incident rate in Russia?
CREATE TABLE FlightSafetyRecords (id INT,country VARCHAR(255),incidents INT,flights INT); INSERT INTO FlightSafetyRecords VALUES (1,'Russia',120,5000),(2,'USA',50,20000),(3,'Canada',30,10000),(4,'Mexico',80,6000);
SELECT MAX(incidents/flights) FROM FlightSafetyRecords WHERE country = 'Russia';
How many hectares of forest are managed by indigenous communities in the Amazon rainforest region?
CREATE TABLE forest_management (id INT,community_name VARCHAR(255),region VARCHAR(255),managed_hectares INT);
SELECT SUM(managed_hectares) FROM forest_management WHERE community_name LIKE '%indigenous%' AND region = 'Amazon rainforest';
Which spacecraft had the longest duration of a space mission?
CREATE TABLE Spacecraft (SpacecraftID INT,Name VARCHAR(50),Manufacturer VARCHAR(50),Duration INT); INSERT INTO Spacecraft (SpacecraftID,Name,Manufacturer,Duration) VALUES (1,'Voyager 1','NASA',43559),(2,'Voyager 2','NASA',42087),(3,'ISS','NASA',960839);
SELECT s.Name FROM Spacecraft s WHERE s.Duration = (SELECT MAX(Duration) FROM Spacecraft);
What is the average number of defense diplomacy events conducted by India from 2015 to 2020?
CREATE TABLE defense_diplomacy (country VARCHAR(50),year INT,event_count INT); INSERT INTO defense_diplomacy (country,year,event_count) VALUES ('India',2015,5),('India',2016,6),('India',2017,7),('India',2018,8),('India',2019,9),('India',2020,10);
SELECT AVG(event_count) FROM defense_diplomacy WHERE country = 'India' AND year BETWEEN 2015 AND 2020;
Update the vegan status for a specific certification
CREATE TABLE certifications (certification_id INT,certification_name TEXT,cruelty_free BOOLEAN,vegan BOOLEAN); INSERT INTO certifications (certification_id,certification_name,cruelty_free,vegan) VALUES (1,'Leaping Bunny',TRUE,FALSE),(2,'Choose Cruelty Free',TRUE,FALSE),(3,'PETA Cruelty-Free',TRUE,FALSE);
UPDATE certifications SET vegan = TRUE WHERE certification_name = 'Choose Cruelty Free';
Calculate the total budget allocated for each program.
CREATE TABLE programs (id INT,name VARCHAR(255)); CREATE TABLE budget (id INT,program_id INT,amount DECIMAL(10,2)); INSERT INTO programs (id,name) VALUES (1,'Disaster Relief'),(2,'Housing'),(3,'Economic Development'); INSERT INTO budget (id,program_id,amount) VALUES (1,1,50000),(2,2,75000),(3,3,100000);
SELECT program_id, SUM(amount) OVER (PARTITION BY program_id) AS total_budget FROM budget;
What is the total waste generation in the city of Seattle for the year 2020?
CREATE TABLE waste_generation (city VARCHAR(20),year INT,total_waste_gen FLOAT); INSERT INTO waste_generation (city,year,total_waste_gen) VALUES ('Seattle',2020,250000);
SELECT total_waste_gen FROM waste_generation WHERE city = 'Seattle' AND year = 2020;
What is the average length of highways in Japan?
CREATE TABLE Highway (id INT,name TEXT,location TEXT,length FLOAT); INSERT INTO Highway (id,name,location,length) VALUES (1,'Shuto Expressway','Tokyo,Japan',320);
SELECT AVG(length) FROM Highway WHERE location = 'Japan';
What is the earliest year of creation for art pieces in the 'Abstract Art' category?
CREATE TABLE Art_History (art_id INT,art_name VARCHAR(255),category VARCHAR(255),year INT); INSERT INTO Art_History (art_id,art_name,category,year) VALUES (1,'Composition VIII','Abstract Art',1916),(2,'The Scream','Expressionism',1893),(3,'Black Square','Suprematism',1915);
SELECT MIN(year) FROM Art_History WHERE category = 'Abstract Art';
What is the percentage of community health workers who have a cultural competency score greater than 80?
CREATE TABLE CommunityHealthWorkers (WorkerID INT,Score INT); INSERT INTO CommunityHealthWorkers (WorkerID,Score) VALUES (1,85),(2,85),(3,90),(4,75),(5,80);
SELECT 100.0 * COUNT(*) / (SELECT COUNT(*) FROM CommunityHealthWorkers) as Percentage FROM CommunityHealthWorkers WHERE Score > 80;
What is the average exit strategy valuation for startups founded by non-minority founders?
CREATE TABLE companies (id INT,name TEXT,founder_race TEXT,exit_strategy_valuation FLOAT); INSERT INTO companies (id,name,founder_race,exit_strategy_valuation) VALUES (1,'Eta Co','non-minority',15000000); INSERT INTO companies (id,name,founder_race,exit_strategy_valuation) VALUES (2,'Theta Inc','minority',8000000); INSERT INTO companies (id,name,founder_race,exit_strategy_valuation) VALUES (3,'Iota Pty','non-minority',20000000);
SELECT AVG(exit_strategy_valuation) FROM companies WHERE founder_race = 'non-minority';
What was the average revenue per attendee for events with a ticket price above $75?
CREATE TABLE Events (EventID int,EventName varchar(50),Attendance int,TicketPrice numeric); INSERT INTO Events VALUES (1,'Art Symposium',300,100),(2,'Music Festival',500,100),(3,'Theater Performance',150,100);
SELECT AVG(TicketPrice) FROM Events WHERE TicketPrice > 75;
What is the total budget for all community development initiatives in the United States, broken down by initiative type?
CREATE TABLE community_development (id INT,country VARCHAR(50),initiative VARCHAR(50),budget INT); INSERT INTO community_development (id,country,initiative,budget) VALUES (1,'USA','Community Center',3000000),(2,'USA','Park',4000000),(3,'Canada','Community Garden',2000000);
SELECT initiative, SUM(budget) as total_budget FROM community_development WHERE country = 'USA' GROUP BY initiative;
Which satellite has the least number of total launches in 2019?
CREATE TABLE satellite_launches (id INT,satellite VARCHAR(255),year INT,launches INT); INSERT INTO satellite_launches (id,satellite,year,launches) VALUES (1,'Starlink-1',2019,3),(2,'Galileo IOV-1',2019,2),(3,'Starlink-2',2019,4);
SELECT satellite, MIN(launches) AS least_launches FROM satellite_launches WHERE year = 2019 GROUP BY satellite HAVING least_launches = (SELECT MIN(launches) FROM satellite_launches WHERE year = 2019);
Find the total number of vehicles in each auto show category where the number of vehicles is greater than 50.
CREATE TABLE AutoShow (Vehicle VARCHAR(255),Category VARCHAR(255)); INSERT INTO AutoShow (Vehicle,Category) VALUES ('TeslaModel3','Electric'),('ToyotaCorolla','Compact'),('HondaCivic','Compact'),('VolvoXC90','SUV'),('TeslaModelS','Electric');
SELECT Category, COUNT(*) as TotalVehicles FROM AutoShow GROUP BY Category HAVING TotalVehicles > 50;
Add a new station to the stations table for the city of Accra, Ghana.
stations (id,name,city,country,latitude,longitude)
INSERT INTO stations (name, city, country) VALUES ('Accra Central', 'Accra', 'Ghana');
Find the names and extraction amounts of minerals that are extracted by companies operating in the European Union.
CREATE TABLE company (id INT,name VARCHAR(255),country VARCHAR(255));CREATE TABLE extraction (company_id INT,mineral VARCHAR(255),amount INT);
SELECT DISTINCT e.mineral, SUM(e.amount) as total_extraction FROM extraction e JOIN company c ON e.company_id = c.id WHERE c.country LIKE '%European Union%' GROUP BY e.mineral;
What is the maximum budget allocated to any digital divide initiative?
CREATE TABLE div_initiatives (name TEXT,budget INTEGER); INSERT INTO div_initiatives (name,budget) VALUES ('DivBridge',800000),('CloseGap',900000),('ConnectWorld',700000);
SELECT MAX(budget) FROM div_initiatives;
Which aircraft models have had more than 2000 flight hours?
CREATE TABLE FlightHours (FlightID int,AircraftModelID int,FlightHours int); CREATE TABLE AircraftModels (ModelID int,ModelName varchar(50)); INSERT INTO FlightHours VALUES (1,1,1500),(2,1,2000),(3,2,500),(4,2,1000),(5,3,2500),(6,3,3000); INSERT INTO AircraftModels VALUES (1,'Boeing 737'),(2,'Airbus A320'),(3,'SpaceX Starship');
SELECT am.ModelName FROM FlightHours fh INNER JOIN AircraftModels am ON fh.AircraftModelID = am.ModelID WHERE fh.FlightHours > 2000 GROUP BY am.ModelName;
What is the total number of concert tickets sold for each month in the Concerts table?
CREATE TABLE Concerts (id INT,artist_name VARCHAR(255),country VARCHAR(255),date DATE,tickets_sold INT); INSERT INTO Concerts (id,artist_name,country,date,tickets_sold) VALUES (1,'Taylor Swift','USA','2022-01-01',1000),(2,'BTS','South Korea','2022-02-01',1500),(3,'Ed Sheeran','UK','2022-03-01',1200),(4,'Rihanna','Barbados','2022-04-01',800),(5,'Shakira','Colombia','2022-05-01',900);
SELECT EXTRACT(MONTH FROM date) as month, SUM(tickets_sold) as total_tickets_sold FROM Concerts GROUP BY month;
What is the average construction labor cost for carpenters in Ohio?
CREATE TABLE construction_labor (state VARCHAR(20),job VARCHAR(50),cost FLOAT); INSERT INTO construction_labor VALUES ('Ohio','Carpenter',46.0),('Ohio','Carpenter',47.0),('Ohio','Electrician',50.0);
SELECT AVG(cost) FROM construction_labor WHERE state = 'Ohio' AND job = 'Carpenter';
Which mining sites have exceeded their annual CO2 emission limit?
CREATE TABLE MiningSites(id INT,name VARCHAR(30),location VARCHAR(30),annual_co2_limit INT); CREATE TABLE Emissions(site_id INT,date DATE,co2_emission INT);
SELECT m.name FROM MiningSites m JOIN Emissions e ON m.id = e.site_id GROUP BY m.id HAVING SUM(e.co2_emission) > m.annual_co2_limit;
What's the average rating for music albums released in 2021?
CREATE TABLE music_albums (id INT,title VARCHAR(100),release_year INT,rating FLOAT); INSERT INTO music_albums (id,title,release_year,rating) VALUES (1,'Album1',2021,4.5); INSERT INTO music_albums (id,title,release_year,rating) VALUES (2,'Album2',2021,4.3); INSERT INTO music_albums (id,title,release_year,rating) VALUES (3,'Album3',2020,4.8); INSERT INTO music_albums (id,title,release_year,rating) VALUES (4,'Album4',2020,4.7);
SELECT AVG(rating) FROM music_albums WHERE release_year = 2021;
Insert a new record into the 'vehicles' table for a bus with license plate 'ABC123' and a model year of 2020
CREATE TABLE vehicles (id INT,license_plate TEXT,model_year INT,type TEXT);
INSERT INTO vehicles (license_plate, model_year, type) VALUES ('ABC123', 2020, 'bus');
What is the name and location of the last community center in Lebanon, ordered by center ID?
CREATE TABLE Lebanon (id INT,name TEXT,type TEXT,location TEXT); INSERT INTO Lebanon (id,name,type,location) VALUES (1,'Center A','Community','Beirut'); INSERT INTO Lebanon (id,name,type,location) VALUES (2,'Center B','Health','Tripoli'); INSERT INTO Lebanon (id,name,type,location) VALUES (3,'Center C','Community','Sidon');
SELECT name, location FROM (SELECT name, location, ROW_NUMBER() OVER (ORDER BY id DESC) AS row_num FROM Lebanon WHERE type = 'Community') AS community_centers WHERE row_num = 1;
Who launched the most space missions?
CREATE TABLE missions(name TEXT,agency TEXT,launch_date TEXT); INSERT INTO missions(name,agency,launch_date) VALUES('Apollo 11','NASA','1969-07-16'),('Apollo 13','NASA','1970-04-11'),('Sputnik 1','Russia','1957-10-04');
SELECT agency, COUNT(*) FROM missions GROUP BY agency ORDER BY COUNT(*) DESC LIMIT 1;
What is the total budget for digital divide initiatives by companies in the public sector?
CREATE TABLE pub_sector (name TEXT,budget INTEGER,sector TEXT); INSERT INTO pub_sector (name,budget,sector) VALUES ('DivBridgePub',800000,'public'),('CloseGapPub',900000,'public'),('ConnectWorldPub',700000,'non-profit');
SELECT SUM(budget) FROM pub_sector WHERE sector = 'public';
Display the number of freedom of information requests and their status in the Australian Capital Territory for the year 2022
CREATE TABLE aus_freedom_of_info (request_id INT,region VARCHAR(20),year INT,requests_open INT,request_status VARCHAR(20)); INSERT INTO aus_freedom_of_info (request_id,region,year,requests_open,request_status) VALUES (1,'Australian Capital Territory',2022,300,'open');
SELECT requests_open, request_status FROM aus_freedom_of_info WHERE region = 'Australian Capital Territory' AND year = 2022;
delete all records from the wildlife table where the species is 'Wolf'
CREATE TABLE wildlife (id INT PRIMARY KEY,species VARCHAR(255),region VARCHAR(255),population INT);
DELETE FROM wildlife WHERE species = 'Wolf';
Update the 'average_spending' for 'Petite' size to '120' in the 'Size' table
CREATE TABLE Size (id INT PRIMARY KEY,name VARCHAR(50),average_spending DECIMAL(5,2));
UPDATE Size SET average_spending = 120 WHERE name = 'Petite';
How many students with physical disabilities are majoring in Computer Science?
CREATE TABLE Students (Id INT,Name VARCHAR(50),DisabilityType VARCHAR(30),Major VARCHAR(50)); INSERT INTO Students (Id,Name,DisabilityType,Major) VALUES (1,'John Doe','Physical','Computer Science'),(2,'Jane Smith','Learning','Psychology'),(3,'Alex Johnson','Physical','Computer Science');
SELECT COUNT(*) FROM Students WHERE DisabilityType = 'Physical' AND Major = 'Computer Science';
List the names of all unique research grant categories.
CREATE TABLE grant (id INT,category TEXT); INSERT INTO grant (id,category) VALUES (1,'research'),(2,'travel'),(3,'equipment'),(4,'research'),(5,'conference');
SELECT DISTINCT category FROM grant;
What is the average production cost of organic cotton t-shirts?
CREATE TABLE OrganicCottonTShirts (id INT,production_cost DECIMAL);
SELECT AVG(production_cost) FROM OrganicCottonTShirts;
Insert a new food product with the name 'Quinoa Puffs' and no safety recall
CREATE TABLE food_products (id INT PRIMARY KEY,name TEXT,safety_recall BOOLEAN);
INSERT INTO food_products (name, safety_recall) VALUES ('Quinoa Puffs', false);
List the number of wells in each city, grouped by country.
CREATE TABLE wells (well_id INT,well_name VARCHAR(255),location VARCHAR(255),city VARCHAR(255),country VARCHAR(255)); INSERT INTO wells (well_id,well_name,location,city,country) VALUES (1,'Well A','Aberdeen','UK'),(2,'Well B','Stavanger','Norway'),(3,'Well C','New Orleans','USA'),(4,'Well D','Ho Chi Minh City','Vietnam');
SELECT country, city, COUNT(*) AS num_wells FROM wells GROUP BY country, city;
Insert new employees into the Employees table
CREATE TABLE Employees (id INT,name VARCHAR(50),position VARCHAR(50),left_company BOOLEAN);
INSERT INTO Employees (id, name, position, left_company) VALUES (1, 'Juan Garcia', 'Software Engineer', FALSE), (2, 'Aisha Khan', 'Data Scientist', FALSE), (3, 'Carlos Mendoza', 'QA Engineer', FALSE);
Find the total budget for projects in the 'transportation' category that were constructed after 2000
CREATE TABLE projects (id INT,name VARCHAR(50),category VARCHAR(50),budget FLOAT,year_built INT); INSERT INTO projects (id,name,category,budget,year_built) VALUES (1,'Highway Expansion','transportation',10000000,2005); INSERT INTO projects (id,name,category,budget,year_built) VALUES (2,'Light Rail Construction','transportation',5000000,2002);
SELECT SUM(budget) FROM projects WHERE category = 'transportation' AND year_built > 2000;
Update the status of all space missions launched in 2012 to 'active'.
CREATE TABLE SpaceMissions (ID INT,Name VARCHAR(50),LaunchDate DATE,Status VARCHAR(20)); INSERT INTO SpaceMissions VALUES (1,'Mission A','2008-03-12',NULL),(2,'Mission B','2012-06-18',NULL),(3,'Mission C','2005-02-03',NULL),(4,'Mission D','2017-11-14',NULL);
UPDATE SpaceMissions SET Status = 'active' WHERE YEAR(LaunchDate) = 2012;
How many patients visited clinic A each month in 2021?
CREATE TABLE clinic_visits (clinic_name TEXT,visit_date DATE); INSERT INTO clinic_visits (clinic_name,visit_date) VALUES ('Clinic A','2021-01-05'),('Clinic A','2021-02-12'),('Clinic A','2021-03-20');
SELECT clinic_name, EXTRACT(MONTH FROM visit_date), COUNT(*) FROM clinic_visits WHERE clinic_name = 'Clinic A' AND visit_date >= '2021-01-01' AND visit_date < '2022-01-01' GROUP BY clinic_name, EXTRACT(MONTH FROM visit_date)
What's the maximum ESG rating for all companies in the 'healthcare' sector?
CREATE TABLE sectors (sector_id INT,sector_name VARCHAR(20)); CREATE TABLE companies (company_id INT,company_name VARCHAR(30),sector_id INT,esg_rating FLOAT);
SELECT MAX(c.esg_rating) FROM companies c INNER JOIN sectors s ON c.sector_id = s.sector_id WHERE s.sector_name = 'healthcare';
How many green energy projects were funded in Asia in the last 5 years?
CREATE TABLE green_energy_projects (id INT,funded DATE,region VARCHAR(50)); INSERT INTO green_energy_projects (id,funded,region) VALUES (1,'2018-01-01','Asia'),(2,'2019-05-15','Europe'),(3,'2020-09-20','Asia');
SELECT COUNT(*) FROM green_energy_projects WHERE region = 'Asia' AND funded >= DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR);
Which country had the highest number of tourists in 2020?
CREATE TABLE tourists (id INT,country VARCHAR(50),visitors INT,year INT); INSERT INTO tourists (id,country,visitors,year) VALUES (1,'Japan',1000,2020),(2,'Brazil',1500,2020),(3,'Argentina',2000,2020);
SELECT country, MAX(visitors) FROM tourists WHERE year = 2020 GROUP BY country;
Which renewable energy projects in the 'renewable_projects' table are located in Africa?
CREATE TABLE renewable_projects (project_name VARCHAR(255),location VARCHAR(255));
SELECT project_name FROM renewable_projects WHERE location LIKE '%Africa%';
What is the average transaction amount for each gender in the "online_customers" table?
CREATE TABLE online_customers (id INT,name VARCHAR(50),age INT,gender VARCHAR(10),city VARCHAR(50)); INSERT INTO online_customers (id,name,age,gender,city) VALUES (1,'Aisha Williams',32,'Female','Chicago'); INSERT INTO online_customers (id,name,age,gender,city) VALUES (2,'Hiroshi Tanaka',45,'Male','Tokyo'); INSERT INTO online_customers (id,name,age,gender,city) VALUES (3,'Clara Rodriguez',29,'Female','Madrid'); CREATE TABLE online_transactions (id INT,customer_id INT,type VARCHAR(50),amount DECIMAL(10,2),date DATE); INSERT INTO online_transactions (id,customer_id,type,amount,date) VALUES (1,1,'purchase',50.00,'2021-01-01'); INSERT INTO online_transactions (id,customer_id,type,amount,date) VALUES (2,1,'refund',10.00,'2021-01-05'); INSERT INTO online_transactions (id,customer_id,type,amount,date) VALUES (3,2,'purchase',100.00,'2021-01-02');
SELECT o.gender, AVG(ot.amount) as avg_amount FROM online_customers o JOIN online_transactions ot ON o.id = ot.customer_id GROUP BY o.gender;
What was the total number of volunteers registered in 'New York' and 'Florida'?
CREATE TABLE Volunteers (volunteer_id INT,registration_date DATE,state VARCHAR(20)); INSERT INTO Volunteers (volunteer_id,registration_date,state) VALUES (1,'2022-01-01','New York'),(2,'2022-01-02','Florida');
SELECT SUM(state = 'New York') + SUM(state = 'Florida') FROM Volunteers;
What is the average annual climate finance provided for climate adaptation in Latin America and the Caribbean?
CREATE TABLE climate_finance_la_caribbean (country VARCHAR(50),initiative VARCHAR(50),funding DECIMAL(10,2),year INT); INSERT INTO climate_finance_la_caribbean (country,initiative,funding,year) VALUES ('Mexico','Coastal Protection',1200000,2018),('Colombia','Water Management',1800000,2019),('Brazil','Disaster Risk Reduction',1500000,2020),('Cuba','Ecosystem Restoration',2000000,2021); CREATE TABLE regions (country VARCHAR(50),region VARCHAR(50)); INSERT INTO regions (country,region) VALUES ('Mexico','Latin America and the Caribbean'),('Colombia','Latin America and the Caribbean'),('Brazil','Latin America and the Caribbean'),('Cuba','Latin America and the Caribbean');
SELECT AVG(cf.funding / 1000) AS avg_annual_funding FROM climate_finance_la_caribbean cf INNER JOIN regions r ON cf.country = r.country WHERE r.region = 'Latin America and the Caribbean' AND cf.initiative = 'climate adaptation';
Which countries have participated in defense diplomacy events but not in peacekeeping operations?
CREATE TABLE peacekeeping_operations (id INT,country VARCHAR(255),operation VARCHAR(255)); CREATE TABLE defense_diplomacy (id INT,country VARCHAR(255),event VARCHAR(255));
SELECT ddip.country FROM defense_diplomacy ddip LEFT JOIN peacekeeping_operations pkops ON ddip.country = pkops.country WHERE pkops.country IS NULL;
How many sightings of each type of whale were there in the Arctic in 2019?
CREATE TABLE WhaleSightings (id INT,location VARCHAR(20),whale_type VARCHAR(20),sighted_date DATE); INSERT INTO WhaleSightings (id,location,whale_type,sighted_date) VALUES (1,'Arctic Ocean','Beluga','2019-07-01'); INSERT INTO WhaleSightings (id,location,whale_type,sighted_date) VALUES (2,'Beaufort Sea','Narwhal','2019-08-10');
SELECT whale_type, COUNT(*) FROM WhaleSightings WHERE location LIKE 'Arctic%' AND sighted_date BETWEEN '2019-01-01' AND '2019-12-31' GROUP BY whale_type;
Identify the unique recycling initiatives in each district.
CREATE TABLE RecyclingInitiatives (id INT,district VARCHAR(20),initiative VARCHAR(50)); INSERT INTO RecyclingInitiatives (id,district,initiative) VALUES (1,'DistrictA','Composting'),(2,'DistrictB','Plastic Recycling'),(3,'DistrictA','Metal Recycling');
SELECT DISTINCT district, initiative FROM RecyclingInitiatives;
What is the total number of shipments in the freight forwarding data for each month?
CREATE TABLE ShipmentDates (shipment_id INT,shipment_date DATE); INSERT INTO ShipmentDates (shipment_id,shipment_date) VALUES (1,'2022-01-01'),(2,'2022-02-01'),(3,'2022-03-01');
SELECT EXTRACT(MONTH FROM shipment_date) as month, COUNT(*) as total_shipments FROM ShipmentDates GROUP BY month;
Delete records of citizens who have not provided feedback in the last 2 years from the "citizen_feedback" table
CREATE TABLE citizen_feedback (citizen_id INT,feedback TEXT,feedback_date DATE);
DELETE FROM citizen_feedback WHERE feedback_date < (SELECT DATE(NOW()) - INTERVAL 2 YEAR);
Update the publication date of the article with id 12 to 2022-11-15 in the "articles" table
CREATE TABLE articles (article_id INT,title VARCHAR(255),publication_date DATE,author_id INT);
UPDATE articles SET publication_date = '2022-11-15' WHERE article_id = 12;
What is the total number of visitors to art exhibitions by state?
CREATE TABLE art_exhibitions (exhibition_id INT,exhibition_name VARCHAR(50),state VARCHAR(50)); INSERT INTO art_exhibitions (exhibition_id,exhibition_name,state) VALUES (1,'Modern Art Show','California'),(2,'Classic Art Exhibit','New York'); CREATE TABLE exhibition_visitors (exhibition_id INT,total_visitors INT); INSERT INTO exhibition_visitors (exhibition_id,total_visitors) VALUES (1,500),(2,700);
SELECT e.state, SUM(v.total_visitors) as total_visitors FROM art_exhibitions e INNER JOIN exhibition_visitors v ON e.exhibition_id = v.exhibition_id GROUP BY e.state;
Find artworks by artists who have curated exhibitions in New York or London, excluding those created before 1950.
CREATE TABLE Artists (ArtistID INT PRIMARY KEY,Name VARCHAR(100),CurationHistory TEXT); INSERT INTO Artists (ArtistID,Name,CurationHistory) VALUES (1,'Jasper Johns','Curated exhibitions in New York'); INSERT INTO Artists (ArtistID,Name,CurationHistory) VALUES (2,'Gustav Klimt','Never curated exhibitions'); CREATE TABLE ArtWorks (ArtWorkID INT PRIMARY KEY,Title VARCHAR(100),YearCreated INT,ArtistID INT,FOREIGN KEY (ArtistID) REFERENCES Artists(ArtistID)); INSERT INTO ArtWorks (ArtWorkID,Title,YearCreated,ArtistID) VALUES (1,'Flag',1954,1); INSERT INTO ArtWorks (ArtWorkID,Title,YearCreated,ArtistID) VALUES (2,'The Kiss',1907,2);
SELECT ArtWorks.Title FROM ArtWorks INNER JOIN Artists ON ArtWorks.ArtistID = Artists.ArtistID WHERE Artists.CurationHistory IS NOT NULL AND ArtWorks.YearCreated > 1950 AND Artists.Name IN (SELECT Artists.Name FROM Artists WHERE Artists.CurationHistory LIKE '%New York%' OR Artists.CurationHistory LIKE '%London%');
Update the 'start_date' of a restorative justice program in the 'programs' table
CREATE TABLE programs (id INT,name VARCHAR(50),location VARCHAR(50),type VARCHAR(50),start_date DATE,end_date DATE);
UPDATE programs SET start_date = '2023-02-01' WHERE id = 103;
How many rural infrastructure projects were completed in Asia in 2018 and 2019?
CREATE TABLE rural_infrastructure (country VARCHAR(50),project VARCHAR(50),completion_date DATE); INSERT INTO rural_infrastructure (country,project,completion_date) VALUES ('India','Road Construction','2018-04-01'),('China','Electrification','2018-12-25'),('Nepal','Bridge Building','2019-08-15'),('Bangladesh','Water Supply','2019-02-20'),('Pakistan','School Construction','2018-09-01');
SELECT YEAR(completion_date) as year, COUNT(project) as num_projects FROM rural_infrastructure WHERE country IN ('India', 'China', 'Nepal', 'Bangladesh', 'Pakistan') AND YEAR(completion_date) IN (2018, 2019) GROUP BY year;
Which cities have experienced both an increase in extreme weather events and a decrease in disaster preparedness budget since 2015?
CREATE TABLE weather_events (city VARCHAR(50),year INT,events INT); CREATE TABLE preparedness_budget (city VARCHAR(50),year INT,budget FLOAT); INSERT INTO weather_events VALUES ('CityX',2015,3); INSERT INTO preparedness_budget VALUES ('CityX',2015,1000000);
SELECT city FROM weather_events WHERE events > (SELECT events FROM weather_events WHERE city = weather_events.city AND year = 2015) AND city IN (SELECT city FROM preparedness_budget WHERE budget < (SELECT budget FROM preparedness_budget WHERE city = preparedness_budget.city AND year = 2015))
What is the maximum price of any vegetarian dish?
CREATE TABLE Menu (id INT,item_name VARCHAR(255),price DECIMAL(5,2),vegetarian BOOLEAN);
SELECT MAX(price) FROM Menu WHERE vegetarian = TRUE;
What is the average age of inmates in Illinois prisons who have not participated in restorative justice programs?
CREATE TABLE prisons (id INT,state VARCHAR(2)); INSERT INTO prisons (id,state) VALUES (1,'Illinois'); CREATE TABLE inmates (id INT,age INT,prison_id INT,restorative_justice BOOLEAN);
SELECT AVG(inmates.age) FROM inmates INNER JOIN prisons ON inmates.prison_id = prisons.id WHERE prisons.state = 'Illinois' AND inmates.restorative_justice = FALSE;
What is the minimum and maximum funding amount for startups founded by people from underrepresented racial or ethnic backgrounds in the sustainable energy sector?
CREATE TABLE startups(id INT,name TEXT,industry TEXT,foundation_date DATE,founder_race TEXT,funding FLOAT); INSERT INTO startups(id,name,industry,foundation_date,founder_race,funding) VALUES (1,'GreenPower','Sustainable Energy','2018-01-01','Hispanic',2000000);
SELECT MIN(funding), MAX(funding) FROM startups WHERE industry = 'Sustainable Energy' AND founder_race IN ('African American', 'Hispanic', 'Native American', 'Pacific Islander');
How many security incidents were mitigated in the EMEA region before Q2 of 2021?
CREATE TABLE incidents_by_region (id INT,region TEXT,date_mitigated DATE,incident_status TEXT); INSERT INTO incidents_by_region (id,region,date_mitigated,incident_status) VALUES (1,'EMEA','2021-01-02','mitigated'); INSERT INTO incidents_by_region (id,region,date_mitigated,incident_status) VALUES (2,'APAC','2021-02-03','unmitigated'); INSERT INTO incidents_by_region (id,region,date_mitigated,incident_status) VALUES (3,'EMEA','2021-03-04','mitigated'); INSERT INTO incidents_by_region (id,region,date_mitigated,incident_status) VALUES (4,'APAC','2021-04-05','mitigated'); INSERT INTO incidents_by_region (id,region,date_mitigated,incident_status) VALUES (5,'EMEA','2021-05-06','unmitigated');
SELECT COUNT(*) as count FROM incidents_by_region WHERE region = 'EMEA' AND date_mitigated < '2021-04-01' AND incident_status = 'mitigated';
What is the total cargo weight in metric tons for the vessel 'Seafarer' that arrived at the port of Dakar?
CREATE TABLE Cargo(Id INT,VesselId INT,ArrivalPort VARCHAR(255),Weight DECIMAL(10,2)); INSERT INTO Cargo VALUES (1,1,'Dakar',500.5),(2,1,'Dakar',700.3),(3,2,'Singapore',900),(4,2,'Tokyo',600);
SELECT SUM(c.Weight) FROM Cargo c WHERE c.ArrivalPort = 'Dakar' AND c.VesselId = (SELECT Id FROM Vessels WHERE Name = 'Seafarer');
What is the maximum budget allocated for military technology in the last 5 years?
CREATE TABLE military_budgets (id INT,year INT,budget INT); INSERT INTO military_budgets (id,year,budget) VALUES (1,2017,1000000),(2,2018,1200000),(3,2019,1500000);
SELECT MAX(budget) FROM military_budgets WHERE year >= YEAR(CURDATE()) - 5;
What is the average rating of products with "organic" ingredients?
CREATE TABLE products (id INT,name VARCHAR(100),rating FLOAT,organic BOOLEAN);
SELECT AVG(rating) FROM products WHERE organic = TRUE;
What is the maximum length of underwater caves in the Southern Hemisphere?
CREATE TABLE underwater_caves (cave_name TEXT,length REAL,hemisphere TEXT); INSERT INTO underwater_caves (cave_name,length,hemisphere) VALUES ('Cave_A',3500.0,'Southern'),('Cave_B',4000.0,'Southern'),('Cave_C',3000.0,'Northern');
SELECT MAX(length) FROM underwater_caves WHERE hemisphere = 'Southern';
What is the total climate finance for 'Africa'?
CREATE TABLE climate_finance (country VARCHAR(255),amount FLOAT); INSERT INTO climate_finance (country,amount) VALUES ('Canada',5000000),('Mexico',6000000),('Brazil',3000000),('Argentina',4000000),('Kenya',7000000),('Nigeria',8000000);
SELECT SUM(amount) FROM climate_finance WHERE country = 'Africa';
How many volunteers signed up for each country in 2022?
CREATE TABLE volunteer_signups (id INT,volunteer_name TEXT,country TEXT,signup_date DATE); INSERT INTO volunteer_signups (id,volunteer_name,country,signup_date) VALUES (1,'Fatima Al-Hassan','Iraq','2022-05-22'); INSERT INTO volunteer_signups (id,volunteer_name,country,signup_date) VALUES (2,'Ravi Patel','India','2022-09-03');
SELECT country, COUNT(volunteer_name) as num_volunteers FROM volunteer_signups WHERE signup_date >= '2022-01-01' AND signup_date < '2023-01-01' GROUP BY country;
What is the average monthly revenue of eco-friendly nail polish products in the North American market, for the past 6 months?
CREATE TABLE sales(product_id INT,sale_date DATE,revenue DECIMAL(10,2),country VARCHAR(50)); INSERT INTO sales VALUES (24,'2021-07-01',15.00,'CA'); INSERT INTO sales VALUES (25,'2021-08-01',20.00,'US'); CREATE TABLE products(product_id INT,product_name VARCHAR(50),is_eco_friendly BOOLEAN,product_category VARCHAR(50)); INSERT INTO products VALUES (24,'Nail Polish',TRUE,'Nail Care'); INSERT INTO products VALUES (25,'Base Coat',TRUE,'Nail Care');
SELECT AVG(sales.revenue) as avg_monthly_revenue FROM sales JOIN products ON sales.product_id = products.product_id WHERE products.is_eco_friendly = TRUE AND products.product_category = 'Nail Care' AND sales.sale_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 6 MONTH) AND CURDATE() GROUP BY sales.country;
What is the total maintenance cost and average time since last maintenance for each piece of equipment, partitioned by vendor and ordered by total maintenance cost in descending order?
CREATE TABLE equipment (id INT,vendor_id INT,model VARCHAR(255),last_maintenance_date DATE,maintenance_cost FLOAT); INSERT INTO equipment (id,vendor_id,model,last_maintenance_date,maintenance_cost) VALUES (1,1,'M1 Abrams','2021-03-25',10000); INSERT INTO equipment (id,vendor_id,model,last_maintenance_date,maintenance_cost) VALUES (2,2,'F-35','2022-01-10',20000); CREATE TABLE vendor (id INT,name VARCHAR(255)); INSERT INTO vendor (id,name) VALUES (1,'ABC Corp'); INSERT INTO vendor (id,name) VALUES (2,'DEF Inc');
SELECT v.name as vendor, e.model, SUM(e.maintenance_cost) as total_maintenance_cost, AVG(DATEDIFF(day, e.last_maintenance_date, GETDATE())) as avg_time_since_last_maintenance, ROW_NUMBER() OVER (PARTITION BY v.name ORDER BY SUM(e.maintenance_cost) DESC) as rank FROM equipment e JOIN vendor v ON e.vendor_id = v.id GROUP BY v.name, e.model ORDER BY total_maintenance_cost DESC;
What is the maximum diameter at breast height (DBH) for trees in the tropical rainforest biome?
CREATE TABLE biomes (biome_id INT PRIMARY KEY,name VARCHAR(50),area_km2 FLOAT); INSERT INTO biomes (biome_id,name,area_km2) VALUES (1,'Tropical Rainforest',15000000.0),(2,'Temperate Rainforest',250000.0),(3,'Boreal Forest',12000000.0); CREATE TABLE trees (tree_id INT PRIMARY KEY,species VARCHAR(50),biome_id INT,dbh FLOAT,FOREIGN KEY (biome_id) REFERENCES biomes(biome_id)); INSERT INTO trees (tree_id,species,biome_id,dbh) VALUES (1,'Rubber Tree',1,80.0),(2,'Mahogany',1,60.0),(3,'Cacao',1,30.0);
SELECT MAX(dbh) FROM trees WHERE biomes.name = 'Tropical Rainforest';
What is the total number of likes on posts by users in 'Canada'?
CREATE TABLE users (id INT,name VARCHAR(50),gender VARCHAR(10),age INT,location VARCHAR(50)); CREATE TABLE posts (id INT,user_id INT,content TEXT,timestamp TIMESTAMP,likes INT); CREATE TABLE likes (post_id INT,user_id INT);
SELECT SUM(posts.likes) AS total_likes FROM posts JOIN users ON posts.user_id = users.id WHERE users.location = 'Canada';
What is the total assets value for all clients in the Pacific region?
CREATE TABLE clients (client_id INT,region VARCHAR(20)); INSERT INTO clients (client_id,region) VALUES (1,'Pacific'),(2,'Atlantic'); CREATE TABLE assets (asset_id INT,client_id INT,value INT); INSERT INTO assets (asset_id,client_id,value) VALUES (1,1,5000),(2,1,7000),(3,2,3000);
SELECT SUM(value) FROM assets JOIN clients ON assets.client_id = clients.client_id WHERE clients.region = 'Pacific';
Calculate the percentage of cruelty-free cosmetic products by country.
CREATE TABLE ingredients (ingredient_id INT,ingredient_name TEXT,organic TEXT,product_id INT,country TEXT); INSERT INTO ingredients VALUES (1,'Jojoba Oil','Organic',1,'Mexico'),(2,'Shea Butter','Organic',2,'Ghana'),(3,'Aloe Vera','Organic',3,'Mexico'),(4,'Rosehip Oil','Organic',4,'Chile'),(5,'Cocoa Butter','Conventional',5,'Ghana'); CREATE TABLE cosmetics (product_id INT,product_name TEXT,cruelty_free BOOLEAN,price FLOAT); INSERT INTO cosmetics VALUES (1,'Lipstick A',true,12.99),(2,'Foundation B',false,18.50),(3,'Mascara C',true,9.99),(4,'Eyeshadow D',true,14.99),(5,'Blush E',false,11.99);
SELECT country, (COUNT(*) FILTER (WHERE cruelty_free = true)) * 100.0 / COUNT(*) as percentage FROM ingredients JOIN cosmetics ON ingredients.product_id = cosmetics.product_id GROUP BY country;
What is the total number of bike-sharing trips taken in the Madrid public transportation network during the evening peak hours?
CREATE TABLE bike_trips (entry_time TIME,num_trips INT); INSERT INTO bike_trips (entry_time,num_trips) VALUES ('17:00:00',200),('18:00:00',300),('19:00:00',400);
SELECT SUM(num_trips) FROM bike_trips WHERE entry_time BETWEEN '17:00:00' AND '19:00:00';
Who are the top contributors for the Louvre museum?
CREATE TABLE Donors (DonorID int,Name varchar(50),City varchar(50)); CREATE TABLE Donations (DonationID int,DonorID int,MuseumID int,Amount int);
SELECT Donors.Name, SUM(Donations.Amount) AS TotalDonatedAmount FROM Donors INNER JOIN Donations ON Donors.DonorID = Donations.DonorID WHERE Donations.MuseumID = (SELECT MuseumID FROM Museums WHERE Name = 'Louvre') GROUP BY Donors.Name ORDER BY TotalDonatedAmount DESC;
What is the minimum cultural competency training level for community health workers serving a rural area?
CREATE TABLE community_health_workers (worker_id INT,cultural_competency_level VARCHAR(20),service_area VARCHAR(10)); INSERT INTO community_health_workers (worker_id,cultural_competency_level,service_area) VALUES (1,'Intermediate','Rural'),(2,'Advanced','Urban'),(3,'Beginner','Rural');
SELECT cultural_competency_level, MIN(worker_id) as first_worker FROM community_health_workers WHERE service_area = 'Rural' GROUP BY cultural_competency_level;
What is the total revenue of tours that promote virtual tourism?
CREATE TABLE tours (id INT,name VARCHAR(255),description TEXT,revenue FLOAT); INSERT INTO tours (id,name,description,revenue) VALUES (1,'Virtual Landmarks Tour','Experience cultural heritage sites in Paris from the comfort of your home.',6000.00),(2,'Online Sustainable City Tour','Take a virtual tour of Tokyo''s eco-friendly initiatives.',5000.00);
SELECT SUM(revenue) FROM tours WHERE description LIKE '%virtual%tourism%';
Add new column to donors table
CREATE TABLE donors (id INT PRIMARY KEY,name VARCHAR(100),age INT,state VARCHAR(2),income FLOAT);
ALTER TABLE donors ADD COLUMN gender VARCHAR(1);
Delete all records from the Machinery table that have an Age greater than 15 years.
CREATE TABLE Machinery (MachineryID INT,Type VARCHAR(50),Age INT); INSERT INTO Machinery (MachineryID,Type,Age) VALUES (1,'Excavator',10); INSERT INTO Machinery (MachineryID,Type,Age) VALUES (2,'Dumper',12); INSERT INTO Machinery (MachineryID,Type,Age) VALUES (3,'Shovel',16);
DELETE FROM Machinery WHERE Age > 15;
List diversity metrics for companies in the 'finance' sector.
CREATE TABLE company_diversity (company_id INT,sector VARCHAR(20),female_percent FLOAT,minority_percent FLOAT); INSERT INTO company_diversity (company_id,sector,female_percent,minority_percent) VALUES (1,'technology',0.4,0.3),(2,'finance',0.6,0.1),(3,'technology',0.5,0.4),(4,'finance',0.7,0.2);
SELECT sector, female_percent, minority_percent FROM company_diversity WHERE sector = 'finance';
Insert a new organization into the nonprofits table
CREATE TABLE nonprofits (id INT,name VARCHAR(255),city VARCHAR(255),state VARCHAR(255),zip_code VARCHAR(10));
INSERT INTO nonprofits (id, name, city, state, zip_code) VALUES (5, 'Rainforest Foundation US', 'New York', 'NY', '10013');