instruction
stringlengths
0
1.06k
input
stringlengths
11
5.3k
response
stringlengths
2
4.44k
How many organic food suppliers are there in the EU?
CREATE TABLE suppliers (id INT,country VARCHAR(20),organic BOOLEAN); INSERT INTO suppliers (id,country,organic) VALUES (1,'Germany',true),(2,'France',false);
SELECT COUNT(*) FROM suppliers WHERE country IN ('EU countries') AND organic = true;
How many pallets were handled by each warehouse in 'Paris'?
CREATE TABLE Warehouse (id INT,name VARCHAR(20),city VARCHAR(20)); INSERT INTO Warehouse (id,name,city) VALUES (1,'Paris Warehouse 1','Paris'),(2,'Paris Warehouse 2','Paris'); CREATE TABLE Handling (id INT,shipment_id INT,warehouse_id INT,pallets INT); INSERT INTO Handling (id,shipment_id,warehouse_id,pallets) VALUES (1,101,1,500),(2,102,1,750),(3,103,2,300);
SELECT w.name, SUM(h.pallets) FROM Handling h JOIN Warehouse w ON h.warehouse_id = w.id WHERE w.city = 'Paris' GROUP BY h.warehouse_id;
What is the total volume of freight forwarded from Mexico to Canada?
CREATE TABLE Canada_Freight (id INT,origin_country VARCHAR(50),destination_country VARCHAR(50),volume FLOAT); INSERT INTO Canada_Freight (id,origin_country,destination_country,volume) VALUES (1,'Mexico','Canada',120.5),(2,'Mexico','Canada',240.6),(3,'USA','Canada',360.7);
SELECT SUM(volume) FROM Canada_Freight WHERE origin_country = 'Mexico' AND destination_country = 'Canada';
What is the total weight of shipments to country USA?
CREATE TABLE shipments (shipment_id INT,country VARCHAR(255),weight INT); INSERT INTO shipments (shipment_id,country,weight) VALUES (1,'USA',50),(2,'USA',70),(3,'USA',60);
SELECT SUM(weight) FROM shipments WHERE country = 'USA';
What is the percentage of the population in Illinois that has a college degree?
CREATE TABLE states (id INT,name VARCHAR(255)); INSERT INTO states (id,name) VALUES (1,'Illinois'); CREATE TABLE residents (id INT,state_id INT,degree BOOLEAN,population INT); INSERT INTO residents (id,state_id,degree,population) VALUES (1,1,true,500000),(2,1,false,400000),(3,1,true,600000),(4,1,false,300000);
SELECT AVG(residents.degree) * 100 AS pct_college_degree FROM residents INNER JOIN states ON residents.state_id = states.id WHERE states.name = 'Illinois';
What is the number of female and non-binary faculty members in each college?
CREATE TABLE college (college_name TEXT); INSERT INTO college (college_name) VALUES ('College of Science'),('College of Arts'),('College of Business'); CREATE TABLE faculty (faculty_id INTEGER,college_name TEXT,gender TEXT); INSERT INTO faculty (faculty_id,college_name,gender) VALUES (1,'College of Science','Male'),(2,'College of Science','Female'),(3,'College of Arts','Non-binary'),(4,'College of Business','Male'),(5,'College of Science','Non-binary');
SELECT college_name, gender, COUNT(*) FROM faculty WHERE gender IN ('Female', 'Non-binary') GROUP BY college_name, gender;
Display the number of buildings with each certification level for a given city in the 'green_buildings' table
CREATE TABLE green_buildings (id INT,building_name VARCHAR(50),city VARCHAR(50),certification_level VARCHAR(50));
SELECT city, certification_level, COUNT(*) as building_count FROM green_buildings GROUP BY city, certification_level;
What is the total installed capacity of solar energy projects in the 'renewable_energy' table?
CREATE TABLE renewable_energy (project_id INT,project_name VARCHAR(100),location VARCHAR(100),energy_type VARCHAR(50),installed_capacity FLOAT); INSERT INTO renewable_energy (project_id,project_name,location,energy_type,installed_capacity) VALUES (1,'Solar Farm 1','Australia','Solar',30.0),(2,'Wind Farm 1','Sweden','Wind',65.3);
SELECT SUM(installed_capacity) FROM renewable_energy WHERE energy_type = 'Solar';
List the hotels in the hotels table that offer a wellness facility but do not offer a spa facility.
CREATE TABLE hotels (hotel_id INT,name VARCHAR(50),facility VARCHAR(50)); INSERT INTO hotels (hotel_id,name,facility) VALUES (1,'Hotel X','spa,gym,wellness'),(2,'Hotel Y','wellness'),(3,'Hotel Z','spa,wellness'),(4,'Hotel W','gym,wellness'),(5,'Hotel V','spa,gym'),(6,'Hotel U','wellness,pool');
SELECT * FROM hotels WHERE facility LIKE '%wellness%' AND facility NOT LIKE '%spa%';
How many paintings were on display at the 'Artistic Wonders' gallery in each month of 2021, excluding paintings on display for less than a week?
CREATE TABLE Artists (ArtistID INT,ArtistName VARCHAR(50),Nationality VARCHAR(50),ActiveYears INT);CREATE TABLE Paintings (PaintingID INT,PaintingName VARCHAR(50),ArtistID INT,DisplayStart DATE,DisplayEnd DATE);CREATE TABLE Gallery (GalleryID INT,GalleryName VARCHAR(50),City VARCHAR(50));INSERT INTO Artists VALUES (1,'Claude Monet','French',67); INSERT INTO Paintings VALUES (1,'Water Lilies',1,'2020-01-01','2021-12-31'); INSERT INTO Gallery VALUES (1,'Artistic Wonders','Paris');
SELECT DATEPART(YEAR, DisplayStart) AS Year, DATEPART(MONTH, DisplayStart) AS Month, COUNT(*) AS PaintingsOnDisplay FROM Paintings JOIN Gallery ON Paintings.GalleryID = Gallery.GalleryID WHERE GalleryName = 'Artistic Wonders' AND DisplayEnd >= DATEADD(DAY, 7, DisplayStart) AND DisplayStart <= '2021-12-31' GROUP BY DATEPART(YEAR, DisplayStart), DATEPART(MONTH, DisplayStart);
What is the total number of species recorded in the Arctic Research Station 16 and 17?
CREATE TABLE Arctic_Research_Station_16 (id INT,species TEXT); CREATE TABLE Arctic_Research_Station_17 (id INT,species TEXT);
SELECT COUNT(DISTINCT species) FROM Arctic_Research_Station_16; SELECT COUNT(DISTINCT species) FROM Arctic_Research_Station_17; SELECT COUNT(DISTINCT species) FROM (SELECT * FROM Arctic_Research_Station_16 UNION ALL SELECT * FROM Arctic_Research_Station_17) AS Arctic_Species;
Add a new treatment type 'art therapy' for patient 5 in Canada
CREATE SCHEMA mental_health; USE mental_health; CREATE TABLE patients (patient_id INT,diagnosis VARCHAR(50),age INT,country VARCHAR(50)); CREATE TABLE treatments (treatment_id INT,patient_id INT,treatment_type VARCHAR(50),treatment_date DATE,country VARCHAR(50)); INSERT INTO patients VALUES (5,'depression',45,'Canada');
INSERT INTO treatments VALUES (9, 5, 'art therapy', '2022-03-20', 'Canada');
Delete the record of a patient in Argentina who received art therapy
CREATE TABLE mental_health.patients (patient_id INT,first_name VARCHAR(50),last_name VARCHAR(50),age INT,gender VARCHAR(50),country VARCHAR(50)); INSERT INTO mental_health.patients (patient_id,first_name,last_name,age,gender,country) VALUES (12,'Ana','Gomez',30,'Female','Argentina'); CREATE TABLE mental_health.treatments (treatment_id INT,patient_id INT,therapist_id INT,treatment_type VARCHAR(50),country VARCHAR(50)); INSERT INTO mental_health.treatments (treatment_id,patient_id,therapist_id,treatment_type,country) VALUES (13,12,102,'Art Therapy','Argentina');
DELETE FROM mental_health.treatments WHERE patient_id = (SELECT patient_id FROM mental_health.patients WHERE first_name = 'Ana' AND last_name = 'Gomez' AND country = 'Argentina'); DELETE FROM mental_health.patients WHERE first_name = 'Ana' AND last_name = 'Gomez' AND country = 'Argentina';
What is the total number of visitors to Asian destinations who participated in voluntourism in the last 3 years?
CREATE TABLE visitors (visitor_id INT,destination TEXT,visit_date DATE,voluntourism BOOLEAN); INSERT INTO visitors (visitor_id,destination,visit_date,voluntourism) VALUES (1,'Bali','2019-05-15',TRUE),(2,'Phuket','2020-12-28',FALSE),(3,'Kyoto','2018-07-22',TRUE);
SELECT COUNT(*) FROM visitors WHERE destination LIKE 'Asia%' AND voluntourism = TRUE AND visit_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 YEAR);
How many articles have been published in each country, and what is the percentage of articles in the 'politics' category in each country?
CREATE TABLE articles (article_id INT,title VARCHAR(50),category VARCHAR(20),country VARCHAR(20)); INSERT INTO articles (article_id,title,category,country) VALUES (1,'Politics in 2022','politics','USA'),(2,'British Politics','politics','UK'),(3,'Indian Economy','economy','India');
SELECT country, COUNT(*) as article_count, 100.0 * COUNT(CASE WHEN category = 'politics' THEN 1 END) / COUNT(*) as politics_percentage FROM articles GROUP BY country;
Update the category of articles with the word 'sports' in the title to 'sport'.
CREATE TABLE articles (id INT,title TEXT,category TEXT,likes INT,created_at DATETIME); INSERT INTO articles (id,title,category,likes,created_at) VALUES (1,'Climate crisis: 12 years to save the planet','climate change',100,'2022-01-01 10:30:00');
UPDATE articles SET category = 'sport' WHERE title LIKE '%sports%';
What is the proportion of articles about the environment in the "NYTimes" and "WashingtonPost"?
CREATE TABLE EnvironmentArticles (id INT,publication DATE,newspaper VARCHAR(20)); INSERT INTO EnvironmentArticles (id,publication,newspaper) VALUES (1,'2022-01-01','NYTimes'),(2,'2022-01-15','WashingtonPost'),(3,'2022-02-01','NYTimes');
SELECT (COUNT(*) FILTER (WHERE newspaper = 'NYTimes') + COUNT(*) FILTER (WHERE newspaper = 'WashingtonPost')) * 100.0 / (SELECT COUNT(*) FROM EnvironmentArticles) AS proportion FROM EnvironmentArticles WHERE newspaper IN ('NYTimes', 'WashingtonPost') AND category = 'environment';
Which news articles have been published in both the 'media' and 'news' schemas?
CREATE TABLE media.articles (article_id INT,title VARCHAR(100),publish_date DATE); CREATE TABLE news.articles (article_id INT,title VARCHAR(100),publish_date DATE); INSERT INTO media.articles (article_id,title,publish_date) VALUES (1,'Article 1','2021-01-01'),(2,'Article 2','2021-02-01'); INSERT INTO news.articles (article_id,title,publish_date) VALUES (1,'Article 1','2021-01-01'),(3,'Article 3','2021-03-01');
SELECT media.articles.title FROM media.articles INNER JOIN news.articles ON media.articles.title = news.articles.title;
Delete all records from the 'programs' table where the 'program_name' is 'Literacy Program'
CREATE TABLE programs (id INT,program_name TEXT,region TEXT); INSERT INTO programs (id,program_name,region) VALUES (1,'Arts Education','Northwest'),(2,'Science Education','Southeast'),(3,'Literacy Program','Northeast');
DELETE FROM programs WHERE program_name = 'Literacy Program';
What is the total number of volunteers and total volunteer hours for each region, excluding the top 3 regions with the highest total volunteer hours?
CREATE TABLE Volunteers (VolunteerID INT,VolunteerName TEXT,Region TEXT,VolunteerHours INT,EventDate DATE); INSERT INTO Volunteers VALUES (1,'Ahmed Al-Hassan','Middle East and North Africa',20,'2022-01-01'),(2,'Fatima Al-Farsi','Europe',15,'2022-02-01');
SELECT Region, COUNT(VolunteerID) as TotalVolunteers, SUM(VolunteerHours) as TotalHours FROM Volunteers v JOIN (SELECT Region, ROW_NUMBER() OVER (ORDER BY SUM(VolunteerHours) DESC) as rn FROM Volunteers GROUP BY Region) tmp ON v.Region = tmp.Region WHERE rn > 3 GROUP BY Region;
Who is the oldest donor from each city?
CREATE TABLE donors_2 (id INT PRIMARY KEY,name VARCHAR(50),age INT,city VARCHAR(50),state VARCHAR(50)); INSERT INTO donors_2 (id,name,age,city,state) VALUES (1,'John Doe',35,'New York','NY'),(2,'Jane Smith',40,'Buffalo','NY'),(3,'Mike Johnson',50,'Boston','MA');
SELECT city, MAX(age) as oldest_donor_age FROM donors_2 GROUP BY city;
Display the average depth of each ocean with a depth greater than 3000 meters.
CREATE TABLE OCEAN_DEPTHS (OCEAN VARCHAR(20),AVERAGE_DEPTH FLOAT); INSERT INTO OCEAN_DEPTHS (OCEAN,AVERAGE_DEPTH) VALUES ('Pacific Ocean',4000),('Atlantic Ocean',3500),('Indian Ocean',3800),('Southern Ocean',4500),('Arctic Ocean',1500);
SELECT OCEAN, AVERAGE_DEPTH FROM OCEAN_DEPTHS WHERE AVERAGE_DEPTH > 3000;
What is the average donation amount in 'Asia' region?
CREATE TABLE donations (id INT,donor_id INT,donation_amount DECIMAL(10,2),region VARCHAR(50)); INSERT INTO donations (id,donor_id,donation_amount,region) VALUES (1,1,100.00,'Asia'); INSERT INTO donations (id,donor_id,donation_amount,region) VALUES (2,2,200.00,'Africa'); INSERT INTO donations (id,donor_id,donation_amount,region) VALUES (3,3,300.00,'Europe');
SELECT AVG(donation_amount) FROM donations WHERE region = 'Asia';
What is the total number of donations and total amount donated for each region in the 'Regions' table?
CREATE TABLE Regions (RegionID int,RegionName varchar(50),DonationCount int,TotalDonations numeric(18,2));
SELECT RegionName, SUM(DonationCount) as TotalDonationsCount, SUM(TotalDonations) as TotalDonationsAmount FROM Regions GROUP BY RegionName;
What is the total duration played for each player?
CREATE TABLE PlayerGame (PlayerID INT,GameID INT,Played DATE,StartTime TIMESTAMP,EndTime TIMESTAMP); INSERT INTO PlayerGame (PlayerID,GameID,Played,StartTime,EndTime) VALUES (1,1,'2022-01-01','2022-01-01 10:00:00','2022-01-01 12:00:00'),(2,2,'2022-01-02','2022-01-02 14:00:00','2022-01-02 16:00:00'),(3,1,'2022-01-03','2022-01-03 10:00:00','2022-01-03 11:00:00'),(4,3,'2022-01-04','2022-01-04 18:00:00','2022-01-04 19:00:00');
SELECT PlayerID, SUM(TIMESTAMPDIFF(MINUTE, StartTime, EndTime)) FROM PlayerGame GROUP BY PlayerID;
How many players from each country are in the 'Players' table?
CREATE TABLE Players (PlayerID INT,Name VARCHAR(100),Country VARCHAR(50)); INSERT INTO Players (PlayerID,Name,Country) VALUES (1,'John Doe','USA'),(2,'Jane Smith','Canada'),(3,'James Brown','England'),(4,'Sophia Johnson','Germany'),(5,'Emma White','USA'),(6,'Oliver Black','Canada');
SELECT Country, COUNT(*) AS PlayerCount FROM Players GROUP BY Country;
What is the minimum temperature reading for sensor with ID 102 in the 'sensors' table?
CREATE TABLE sensors (id INT,sensor_id INT,temperature DECIMAL(5,2)); INSERT INTO sensors (id,sensor_id,temperature) VALUES (1,101,23.5),(2,102,25.7),(3,103,21.8),(4,104,27.3);
SELECT MIN(temperature) FROM sensors WHERE sensor_id = 102;
Insert a new record of budget allocation for the 'Emergency Services' department for the year 2025
CREATE TABLE budget_allocation (department TEXT,year INT,allocation DECIMAL(10,2));
INSERT INTO budget_allocation (department, year, allocation) VALUES ('Emergency Services', 2025, 800000.00);
What is the average production quantity of neodymium in 2020 for mines located in Canada?
CREATE TABLE mines (id INT,name TEXT,location TEXT,production_quantity INT,year INT); INSERT INTO mines (id,name,location,production_quantity,year) VALUES (1,'Great Western Minerals Group','Canada',350,2020),(2,'Neo Material Technologies','Canada',420,2020);
SELECT AVG(production_quantity) FROM mines WHERE location = 'Canada' AND year = 2020 AND element = 'neodymium';
Find the total square footage of wheelchair-accessible properties in Boston.
CREATE TABLE properties (id INT,city VARCHAR(20),square_footage INT,wheelchair_accessible BOOLEAN); INSERT INTO properties (id,city,square_footage,wheelchair_accessible) VALUES (1,'Boston',1000,true); INSERT INTO properties (id,city,square_footage,wheelchair_accessible) VALUES (2,'Boston',1200,false);
SELECT SUM(square_footage) FROM properties WHERE city = 'Boston' AND wheelchair_accessible = true;
How many hydroelectric power plants were constructed in Malaysia, Philippines, and Singapore between 2015 and 2020?
CREATE TABLE hydro_plants (plant_id INT,country VARCHAR(50),construction_year INT); INSERT INTO hydro_plants (plant_id,country,construction_year) VALUES (1,'Malaysia',2016),(2,'Philippines',2018),(3,'Singapore',2017),(4,'Malaysia',2019),(5,'Philippines',2020),(6,'Singapore',2015),(7,'Malaysia',2018);
SELECT COUNT(*) FROM hydro_plants WHERE country IN ('Malaysia', 'Philippines', 'Singapore') AND construction_year BETWEEN 2015 AND 2020;
Update the name of the Wind Farm in Germany with the highest capacity
CREATE TABLE wind_farms (id INT,name VARCHAR(100),country VARCHAR(50),capacity_mw FLOAT); INSERT INTO wind_farms (id,name,country,capacity_mw) VALUES (1,'Windfarm 1','Germany',120.5),(2,'Windfarm 2','Germany',250.3);
UPDATE wind_farms SET name = 'Super Windfarm' WHERE country = 'Germany' ORDER BY capacity_mw DESC LIMIT 1;
Show the total cost of all astrophysics research projects led by researchers from the Canadian Space Agency, grouped by research publication year.
CREATE TABLE AstrophysicsResearch (id INT,title VARCHAR(500),abstract TEXT,publication_date DATE,lead_researcher INT,institution VARCHAR(500)); CREATE TABLE Researchers (id INT,name VARCHAR(50),age INT,gender VARCHAR(10),nationality VARCHAR(50),affiliation VARCHAR(500)); INSERT INTO Researchers (id,name,nationality) VALUES (1,'Sarah Lee','Canadian'); INSERT INTO AstrophysicsResearch (id,title,publication_date,lead_researcher) VALUES (1,'Project A','2020-01-01',1);
SELECT YEAR(publication_date) AS publication_year, SUM(r.total_cost) AS total_cost FROM AstrophysicsResearch r JOIN Researchers re ON r.lead_researcher = re.id WHERE re.nationality = 'Canadian' GROUP BY YEAR(publication_date);
Identify fans who have attended both basketball and soccer games in the last 9 months.
CREATE TABLE fan_attendance(fan_id INT,game_type VARCHAR(10),attendance_date DATE); INSERT INTO fan_attendance(fan_id,game_type,attendance_date) VALUES (1,'basketball','2022-04-05'),(2,'soccer','2022-05-07'),(3,'basketball','2022-06-10'),(1,'soccer','2022-06-12'),(4,'basketball','2022-07-15'),(3,'soccer','2022-07-17');
SELECT fan_id FROM fan_attendance WHERE game_type = 'basketball' AND attendance_date >= DATEADD(month, -9, GETDATE()) INTERSECT SELECT fan_id FROM fan_attendance WHERE game_type = 'soccer' AND attendance_date >= DATEADD(month, -9, GETDATE());
What are the total ticket sales for basketball and soccer games?
CREATE TABLE games (game_id INT,game_type VARCHAR(10)); INSERT INTO games (game_id,game_type) VALUES (1,'Basketball'),(2,'Soccer'); CREATE TABLE sales (sale_id INT,game_id INT,revenue DECIMAL(5,2)); INSERT INTO sales (sale_id,game_id,revenue) VALUES (1,1,500.00),(2,1,750.00),(3,2,800.00),(4,2,1000.00);
SELECT SUM(sales.revenue) FROM sales JOIN games ON sales.game_id = games.game_id WHERE games.game_type IN ('Basketball', 'Soccer');
What are the details of phishing threats and their associated malicious IPs?
CREATE TABLE threat_intelligence(id INT,threat_name VARCHAR(255),category VARCHAR(255),origin VARCHAR(255)); INSERT INTO threat_intelligence(id,threat_name,category,origin) VALUES (1,'Phishing Attack','Phishing','Russia'); CREATE TABLE suspicious_ips(id INT,ip_address VARCHAR(255),location VARCHAR(255),last_seen DATETIME); INSERT INTO suspicious_ips(id,ip_address,location,last_seen) VALUES (1,'192.168.1.2','Russia','2021-03-02 11:00:00');
SELECT ti.threat_name, si.ip_address, si.location, si.last_seen FROM threat_intelligence ti INNER JOIN suspicious_ips si ON ti.origin = si.location WHERE ti.category = 'Phishing';
What is the total number of threat intelligence entries for the last 3 months?
CREATE TABLE ThreatIntelligence (EntryID INT,EntryDate DATE); INSERT INTO ThreatIntelligence (EntryID,EntryDate) VALUES (1,'2022-05-15'); INSERT INTO ThreatIntelligence (EntryID,EntryDate) VALUES (2,'2022-04-17');
SELECT COUNT(*) FROM ThreatIntelligence WHERE EntryDate >= DATE_SUB(CURDATE(), INTERVAL 3 MONTH);
What is the total number of electric and hybrid vehicles in 'vehicle_data' table?
CREATE TABLE vehicle_data (id INT,vehicle_type VARCHAR(20),is_electric BOOLEAN,is_hybrid BOOLEAN);
SELECT COUNT(*) FROM vehicle_data WHERE is_electric = true OR is_hybrid = true;
Calculate the total revenue generated from the US market.
CREATE TABLE Sales (id INT PRIMARY KEY,market VARCHAR(20),revenue DECIMAL(10,2)); INSERT INTO Sales (id,market,revenue) VALUES (1,'US',20000.00),(2,'Canada',15000.00);
SELECT SUM(revenue) FROM Sales WHERE market = 'US';
How many units of each product were sold in Canada in Q2 and Q3 of 2021?
CREATE TABLE product_sales (product_name VARCHAR(30),country VARCHAR(20),quarter INT,year INT,units_sold INT); INSERT INTO product_sales (product_name,country,quarter,year,units_sold) VALUES ('t-shirt','Canada',2,2021,800),('t-shirt','Canada',3,2021,900),('jeans','Canada',2,2021,1200),('jeans','Canada',3,2021,1300);
SELECT product_name, SUM(units_sold) FROM product_sales WHERE country = 'Canada' AND (quarter = 2 OR quarter = 3) AND year = 2021 GROUP BY product_name;
Update the names of members in the 'transportation' union to 'crew'.
CREATE TABLE unions (id INT,name TEXT,member_name TEXT); CREATE TABLE members (id INT,union_id INT,name TEXT);
UPDATE members SET name = 'crew' WHERE union_id IN (SELECT id FROM unions WHERE name = 'transportation');
What is the total number of workers in unions that have a collective bargaining agreement in the technology sector?
CREATE TABLE union_tech (union_id INT,union_name TEXT,members INT,cb_agreement BOOLEAN); INSERT INTO union_tech (union_id,union_name,members,cb_agreement) VALUES (1,'Union A',5000,true),(2,'Union B',3000,false),(3,'Union C',7000,true);
SELECT SUM(members) FROM union_tech WHERE cb_agreement = true;
Delete all records from the patents table with a filing date older than 5 years.
CREATE TABLE patents (patent_id INT,patent_number INT,filing_date DATE,vehicle_id INT);
DELETE FROM patents WHERE filing_date < DATEADD(year, -5, GETDATE());
What is the average horsepower of luxury vehicles in the 'GreenCar' database produced after 2017?
CREATE TABLE LuxuryVehicles (Id INT,Make VARCHAR(50),Model VARCHAR(50),Year INT,Horsepower INT);
SELECT AVG(Horsepower) FROM LuxuryVehicles WHERE Year > 2017;
What is the average safety rating of vehicles manufactured in each country?
CREATE TABLE Vehicles (id INT,make VARCHAR(50),model VARCHAR(50),safety_rating FLOAT,country VARCHAR(50));
SELECT country, AVG(safety_rating) FROM Vehicles GROUP BY country;
What is the minimum safety rating of electric vehicles in the 'green_cars' table?
CREATE TABLE green_cars (id INT,make VARCHAR(50),model VARCHAR(50),type VARCHAR(50),safety_rating INT);
SELECT MIN(safety_rating) FROM green_cars WHERE type = 'Electric';
Get the number of visitors and exhibitions for each art category.
CREATE TABLE art_categories (id INT,category VARCHAR(50),num_visitors INT,num_exhibitions INT); INSERT INTO art_categories (id,category,num_visitors,num_exhibitions) VALUES (1,'Painting',1200,500),(2,'Sculpture',800,300);
SELECT category, SUM(num_visitors) as total_visitors, SUM(num_exhibitions) as total_exhibitions FROM art_categories GROUP BY category;
Which exhibition had the highest number of visitors in Los Angeles in the first half of 2019?
CREATE TABLE Exhibition_Visitor_Count (exhibition_id INT,city VARCHAR(50),half INT,year INT,visitor_count INT);
SELECT exhibition_id, MAX(visitor_count) FROM Exhibition_Visitor_Count WHERE city = 'Los Angeles' AND half IN (1, 2) AND year = 2019 GROUP BY exhibition_id;
What is the total water consumption in liters for users in 'Asia' in March 2022?
CREATE TABLE water_consumption_by_region (user_location VARCHAR(20),consumption FLOAT,consumption_date DATE); INSERT INTO water_consumption_by_region (user_location,consumption,consumption_date) VALUES ('Africa',150,'2022-03-01'),('Asia',250,'2022-03-01'),('Africa',160,'2022-03-02'),('Asia',240,'2022-03-02');
SELECT SUM(consumption) FROM water_consumption_by_region WHERE user_location = 'Asia' AND consumption_date >= '2022-03-01' AND consumption_date < '2022-04-01';
What is the average safety score for each creative AI algorithm, grouped by their application domains?
CREATE TABLE creative_ai_algorithms (algorithm_id INT,algorithm_name VARCHAR(255),domain VARCHAR(255),safety_score FLOAT);CREATE TABLE ai_application_domains (domain_id INT,domain VARCHAR(255));
SELECT caa.domain, AVG(caa.safety_score) FROM creative_ai_algorithms caa INNER JOIN ai_application_domains aad ON caa.domain = aad.domain GROUP BY caa.domain;
How many rural infrastructure projects have been implemented in Mexico since 2010 that targeted economic diversification?
CREATE TABLE infrastructure_projects (id INT,project_name VARCHAR(100),location VARCHAR(50),start_date DATE,end_date DATE,sector VARCHAR(50)); INSERT INTO infrastructure_projects (id,project_name,location,start_date,end_date,sector) VALUES (1,'Rural Road Improvement','Puebla','2012-01-01','2013-12-31','Transportation'); INSERT INTO infrastructure_projects (id,project_name,location,start_date,end_date,sector) VALUES (2,'Solar Powered Water Pumping System','Oaxaca','2011-04-15','2012-03-31','Energy');
SELECT COUNT(*) FROM infrastructure_projects WHERE location = 'Mexico' AND sector = 'Economic Diversification' AND start_date <= '2010-12-31' AND (end_date >= '2010-12-31' OR end_date IS NULL);
List all the accidents involving Russian airlines since 2000, along with the aircraft type and the number of fatalities.
CREATE TABLE AirlineAccidents (AccidentID INT,Airline VARCHAR(50),AircraftType VARCHAR(50),Date DATE,Fatalities INT);
SELECT AirlineAccidents.Airline, AirlineAccidents.AircraftType, AirlineAccidents.Date, AirlineAccidents.Fatalities FROM AirlineAccidents WHERE AirlineAccidents.Airline LIKE '%Russian%' AND AirlineAccidents.Date >= '2000-01-01' ORDER BY AirlineAccidents.Date;
Display the name and family of all fish species in the "fish_species" table that have a region of "South America"
create table fish_species (id integer,name text,family text,region text); insert into fish_species (id,name,family,region) values (1,'Pacu','Serrasalmidae','South America'); insert into fish_species (id,name,family,region) values (2,'Piranha','Serrasalmidae','South America'); insert into fish_species (id,name,family,region) values (3,'Dorado','Salmoniformes','South America');
select name, family from fish_species where region = 'South America';
What is the average stock level and biomass for each species in the 'fish_stock' table?
CREATE TABLE fish_stock (id INT,species VARCHAR(255),stock_level INT,biomass DECIMAL(6,2)); INSERT INTO fish_stock (id,species,stock_level,biomass) VALUES (1,'Tilapia',250,325.45),(2,'Salmon',180,2134.67),(3,'Tilapia',300,412.34),(4,'Catfish',150,654.32),(5,'Salmon',200,2500.00);
SELECT species, AVG(stock_level) as avg_stock_level, AVG(biomass) as avg_biomass FROM fish_stock GROUP BY species;
What is the maximum and minimum dissolved oxygen level for each species of fish in the aquaculture facility?
CREATE TABLE fish_species (id INT,species TEXT,dissolved_oxygen_tolerance FLOAT);CREATE TABLE fish_population (id INT,species TEXT,population INT,dissolved_oxygen FLOAT,date DATE);
SELECT species, MAX(dissolved_oxygen) AS max_dissolved_oxygen, MIN(dissolved_oxygen) AS min_dissolved_oxygen FROM fish_population fp JOIN fish_species fs ON fp.species = fs.species GROUP BY species;
What is the maximum biomass of fish for each species in Africa?
CREATE TABLE fish_stock (id INT,species VARCHAR,biomass FLOAT,country VARCHAR); INSERT INTO fish_stock (id,species,biomass,country) VALUES (1,'Tilapia',500.0,'Egypt'),(2,'Salmon',800.0,'Norway'),(3,'Trout',300.0,'New Zealand'),(4,'Bass',700.0,'South Africa'),(5,'Tilapia',600.0,'Tanzania');
SELECT species, MAX(biomass) FROM fish_stock WHERE country IN ('Egypt', 'South Africa', 'Tanzania') GROUP BY species;
What are the average labor costs for green building projects in California?
CREATE TABLE Green_Buildings (Project_ID INT,Project_Name VARCHAR(255),State VARCHAR(255),Labor_Cost DECIMAL(10,2)); INSERT INTO Green_Buildings (Project_ID,Project_Name,State,Labor_Cost) VALUES (1,'Solar Farm','California',150000.00),(2,'Wind Turbine Park','California',200000.00);
SELECT AVG(Labor_Cost) FROM Green_Buildings WHERE State = 'California';
Find all cases and their associated attorneys that have an expense greater than $500
CREATE TABLE cases (case_id INT,attorney_id INT); CREATE TABLE attorneys_expenses (attorney_expense_id INT,attorney_id INT,amount DECIMAL(10,2));
SELECT cases.case_id, attorneys_expenses.attorney_id, attorneys_expenses.amount FROM cases INNER JOIN attorneys_expenses ON cases.attorney_id = attorneys_expenses.attorney_id WHERE attorneys_expenses.amount > 500;
How many cases were handled by attorneys who joined the firm in 2015 or later?
CREATE TABLE attorneys (attorney_id INT,join_year INT); CREATE TABLE cases (case_id INT,attorney_id INT,billing_amount INT);
SELECT COUNT(DISTINCT cases.case_id) FROM cases INNER JOIN attorneys ON cases.attorney_id = attorneys.attorney_id WHERE attorneys.join_year >= 2015;
What is the maximum number of cases handled by attorneys who identify as male?
CREATE TABLE attorneys (attorney_id INT,gender VARCHAR(10),total_cases INT); INSERT INTO attorneys (attorney_id,gender,total_cases) VALUES (1,'Female',15),(2,'Male',20),(3,'Male',10);
SELECT MAX(total_cases) FROM attorneys WHERE gender = 'Male';
What is the average annual climate finance investment in the Middle East?
CREATE TABLE climate_finance_investments (id INT,country VARCHAR(50),investment FLOAT,year INT); INSERT INTO climate_finance_investments (id,country,investment,year) VALUES (1,'Iran',2000000,2018),(2,'Iraq',1500000,2018),(3,'Israel',3000000,2019);
SELECT AVG(investment) FROM climate_finance_investments WHERE country = 'Iran' OR country = 'Iraq' OR country = 'Israel' GROUP BY year;
How many primary care physicians are there in each county of Los Angeles in 2022?
CREATE TABLE Physicians (ID INT,Specialty VARCHAR(20),County VARCHAR(20),State VARCHAR(20),Date DATE); INSERT INTO Physicians (ID,Specialty,County,State,Date) VALUES (1,'Primary Care','Los Angeles','California','2022-01-01');
SELECT County, COUNT(*) FROM Physicians WHERE Specialty = 'Primary Care' AND State = 'California' AND YEAR(Date) = 2022 GROUP BY County;
What is the infant mortality rate in Latin America by country?
CREATE TABLE latin_america (country VARCHAR(50),infant_mortality_rate DECIMAL(3,1)); INSERT INTO latin_america (country,infant_mortality_rate) VALUES ('Argentina',8.2),('Brazil',13.0),('Chile',6.4);
SELECT country, AVG(infant_mortality_rate) as avg_infant_mortality_rate FROM latin_america GROUP BY country;
What is the current circulating supply of digital asset 'Polkadot'?
CREATE TABLE digital_assets_supply (asset_name TEXT,circulating_supply INT,total_supply INT); INSERT INTO digital_assets_supply (asset_name,circulating_supply,total_supply) VALUES ('Polkadot',1000000000,1000000000);
SELECT circulating_supply FROM digital_assets_supply WHERE asset_name = 'Polkadot';
List all timber production records for the year 2000, including the species and volume, in descending order by volume.
CREATE TABLE timber_production (id INT,year INT,species VARCHAR(255),volume FLOAT); INSERT INTO timber_production (id,year,species,volume) VALUES (1,2000,'Pine',1200),(2,2000,'Oak',1500),(3,2001,'Spruce',1800);
SELECT species, volume FROM timber_production WHERE year = 2000 ORDER BY volume DESC;
How many 'Foundation' products have a rating of at least 4.0?
CREATE TABLE Products (ProductID int,ProductName varchar(50),Category varchar(50),Rating float); INSERT INTO Products (ProductID,ProductName,Category,Rating) VALUES (1,'Foundation A','Foundation',3.5),(2,'Foundation B','Foundation',4.2),(3,'Lipstick C','Lipstick',4.7);
SELECT COUNT(*) as NumRated4 FROM Products WHERE Category = 'Foundation' AND Rating >= 4.0;
What is the total revenue for cosmetic products in the United Kingdom that are certified as vegan and cruelty-free?
CREATE TABLE cosmetics_sales (product_id INT,product_name TEXT,is_vegan BOOLEAN,is_cruelty_free BOOLEAN,country TEXT,revenue INT);
SELECT SUM(revenue) FROM cosmetics_sales WHERE is_vegan = TRUE AND is_cruelty_free = TRUE AND country = 'United Kingdom';
What is the maximum response time for each community?
CREATE TABLE communities (community_id INT,community_name VARCHAR(50)); CREATE TABLE emergencies (emergency_id INT,community_id INT,responded_date DATE,response_time INT); INSERT INTO communities (community_id,community_name) VALUES (1,'Community A'),(2,'Community B'),(3,'Community C'); INSERT INTO emergencies (emergency_id,community_id,responded_date,response_time) VALUES (1,1,'2021-01-01',15),(2,2,'2021-02-01',20),(3,3,'2021-03-01',25),(4,1,'2021-04-01',18);
SELECT community_name, MAX(response_time) max_response_time FROM emergencies JOIN communities ON emergencies.community_id = communities.community_id GROUP BY community_name;
Show all military innovation records that are not related to 'Country W'
CREATE TABLE military_innovation (id INT,country VARCHAR(255),innovation VARCHAR(255));
SELECT * FROM military_innovation WHERE country != 'Country W';
What is the minimum and maximum transaction amount for customers in the West region?
CREATE TABLE transactions (transaction_id INT,customer_id INT,transaction_date DATE,transaction_amount DECIMAL(10,2)); INSERT INTO transactions (transaction_id,customer_id,transaction_date,transaction_amount) VALUES (1,2,'2022-01-05',350.00),(2,1,'2022-01-10',500.00),(3,4,'2022-01-15',600.00),(4,4,'2022-01-30',800.00);
SELECT MIN(transaction_amount), MAX(transaction_amount) FROM transactions WHERE customer_id IN (SELECT customer_id FROM customers WHERE region = 'West');
What is the average salary of workers in the manufacturing industry, grouped by their job role and location, for the year 2021?
CREATE TABLE Workers (worker_id INT,job_role VARCHAR(255),location VARCHAR(255),salary DECIMAL(10,2),join_date DATE); INSERT INTO Workers (worker_id,job_role,location,salary,join_date) VALUES (1,'Engineer','New York',75000.00,'2021-01-01'); INSERT INTO Workers (worker_id,job_role,location,salary,join_date) VALUES (2,'Technician','California',50000.00,'2021-01-01');
SELECT w.job_role, w.location, AVG(w.salary) as avg_salary FROM Workers w WHERE YEAR(w.join_date) = 2021 GROUP BY w.job_role, w.location;
Find excavation sites with more than 50 artifacts.
CREATE TABLE excavation_sites (id INT,name VARCHAR(255)); CREATE TABLE artifacts (id INT,excavation_site_id INT,year INT,type VARCHAR(255));
SELECT es.name FROM excavation_sites es JOIN artifacts a ON es.id = a.excavation_site_id GROUP BY es.name HAVING COUNT(a.id) > 50;
Delete records of hospitals in Alabama.
CREATE TABLE hospitals (id INT,name TEXT,location TEXT); INSERT INTO hospitals (id,name,location) VALUES (1,'Hospital A','Rural Texas'); INSERT INTO hospitals (id,name,location) VALUES (5,'Hospital E','Rural Alabama');
DELETE FROM hospitals WHERE location = 'Rural Alabama';
What is the number of hospitals in 'rural_healthcare' table?
CREATE TABLE rural_healthcare (name VARCHAR(255),type VARCHAR(255),location VARCHAR(255)); INSERT INTO rural_healthcare (name,type,location) VALUES ('Rural General Hospital','Hospital','Bushland'),('Rural Community Hospital','Hospital','Forest Region');
SELECT COUNT(*) FROM rural_healthcare WHERE type = 'Hospital';
Update the name of the artist with id 1 to 'Adele'.
CREATE TABLE artists (id INT,name TEXT); INSERT INTO artists (id,name) VALUES (1,'Taylor Swift'),(2,'Eminem');
UPDATE artists SET name = 'Adele' WHERE id = 1;
What are the names of the top 5 artists with the highest number of streams on the "platformP" platform, considering only the "country" genre?
CREATE TABLE platformP (artist_name TEXT,genre TEXT,streams BIGINT);
SELECT artist_name FROM platformP WHERE genre = 'country' GROUP BY artist_name ORDER BY SUM(streams) DESC LIMIT 5;
Who are the top 2 artists with the most R&B songs?
CREATE TABLE songs (song_id INT,song_title TEXT,artist_name TEXT,genre TEXT); INSERT INTO songs VALUES (1,'Love Song','Alicia Keys','R&B'),(2,'Rolling in the Deep','Adele','R&B'),(3,'Empire State of Mind','Jay-Z','R&B'),(4,'Crazy','Gnarls Barkley','Soul'),(5,'Tears Always Win','Alicia Keys','R&B'); CREATE TABLE artists (artist_id INT,artist_name TEXT); INSERT INTO artists VALUES (1,'Alicia Keys'),(2,'Adele'),(3,'Jay-Z'),(4,'Gnarls Barkley');
SELECT artists.artist_name, COUNT(songs.song_id) as song_count FROM songs INNER JOIN artists ON songs.artist_name = artists.artist_name WHERE songs.genre = 'R&B' GROUP BY artists.artist_name ORDER BY song_count DESC LIMIT 2;
How many professional development courses did teachers complete in each department?
CREATE TABLE teacher_professional_development (teacher_id INT,department_id INT,course_count INT);
SELECT department_id, SUM(course_count) as total_courses FROM teacher_professional_development GROUP BY department_id;
What is the percentage of students who participated in lifelong learning programs in each school?
CREATE TABLE school_lifelong_learning_participation (school_id INT,student_id INT,participated_in_program BOOLEAN); INSERT INTO school_lifelong_learning_participation (school_id,student_id,participated_in_program) VALUES (1,1,true),(1,2,false),(1,3,true),(2,4,true),(2,5,true),(3,6,false),(3,7,false),(3,8,true); CREATE TABLE schools (school_id INT,school_name TEXT); INSERT INTO schools (school_id,school_name) VALUES (1,'Green Valley High'),(2,'Oak Park Middle'),(3,'Sunshine Elementary');
SELECT s.school_name, 100.0 * AVG(CASE WHEN sllp.participated_in_program THEN 1.0 ELSE 0.0 END) as percentage_participated FROM school_lifelong_learning_participation sllp JOIN schools s ON sllp.school_id = s.school_id GROUP BY sllp.school_id;
What is the average capacity of geothermal plants?
CREATE TABLE geothermal_plants (name TEXT,location TEXT,capacity_MW INTEGER); INSERT INTO geothermal_plants (name,location,capacity_MW) VALUES ('Plant D','Country A',60),('Plant E','Country B',80),('Plant F','Country C',70);
SELECT AVG(capacity_MW) FROM geothermal_plants;
List the number of unique volunteers and total volunteer hours for each community.
CREATE TABLE volunteers (id INT,community_id INT,hours FLOAT); CREATE TABLE communities (id INT,name VARCHAR(255));
SELECT c.name, COUNT(DISTINCT volunteers.id) as volunteer_count, SUM(volunteers.hours) as total_volunteer_hours FROM communities c LEFT JOIN volunteers ON c.id = volunteers.community_id GROUP BY c.id;
What is the total number of disaster response projects in Asia?
CREATE TABLE disaster_response_projects (id INT,name VARCHAR(100),region VARCHAR(50),status VARCHAR(20)); INSERT INTO disaster_response_projects (id,name,region,status) VALUES (1,'Project A','Asia','Completed'),(2,'Project B','Africa','In Progress'),(3,'Project C','Asia','Completed');
SELECT COUNT(*) FROM disaster_response_projects WHERE region = 'Asia';
What is the total number of ethical AI patents filed in Mexico, Argentina, and Colombia?
CREATE TABLE patents (patent_id INT,title VARCHAR(50),filed_country VARCHAR(50),ethical BOOLEAN); INSERT INTO patents (patent_id,title,filed_country,ethical) VALUES (1,'PatentA','Mexico',true),(2,'PatentB','Argentina',false),(3,'PatentC','Colombia',true),(4,'PatentD','Mexico',true),(5,'PatentE','Argentina',true);
SELECT COUNT(*) FROM patents WHERE ethical = true AND filed_country IN ('Mexico', 'Argentina', 'Colombia');
Update the financial wellbeing score of clients in Indonesia to 1 point higher than their current score.
CREATE TABLE financial_wellbeing_id (client_id INT,financial_wellbeing_score INT,country VARCHAR(50)); INSERT INTO financial_wellbeing_id (client_id,financial_wellbeing_score,country) VALUES (1,7,'Indonesia'),(2,3,'Indonesia'),(3,6,'Indonesia');
WITH updated_scores AS (UPDATE financial_wellbeing_id SET financial_wellbeing_score = financial_wellbeing_score + 1 WHERE country = 'Indonesia') SELECT * FROM updated_scores;
Identify all ingredients that appear in more than one cuisine type.
CREATE TABLE cuisines (id INT,name TEXT,ingredient TEXT);
SELECT ingredient FROM cuisines GROUP BY ingredient HAVING COUNT(DISTINCT name) > 1;
Show the total number of records in the "Sustainability" table
CREATE TABLE Sustainability (id INT,company VARCHAR(50),rating DECIMAL(2,1),year INT); INSERT INTO Sustainability (id,company,rating,year) VALUES (1,'Company1',3.5,2019),(2,'Company2',4.2,2020);
SELECT COUNT(*) FROM Sustainability;
Update the FoodSafetyRecords.OrganicFarms table to include a new record for a certified organic farm in Kenya.
CREATE TABLE FoodSafetyRecords.OrganicFarms (farmName TEXT,country TEXT,certified BOOLEAN);
INSERT INTO FoodSafetyRecords.OrganicFarms (farmName, country, certified) VALUES ('Ngong Organic Farm', 'Kenya', TRUE);
Find the average warehouse management costs for the Sydney and Melbourne warehouses in Q2 2023?
CREATE TABLE warehouse_costs_apac (warehouse_id INT,warehouse_location VARCHAR(255),cost DECIMAL(10,2),quarter INT,year INT); INSERT INTO warehouse_costs_apac (warehouse_id,warehouse_location,cost,quarter,year) VALUES (1,'Sydney Warehouse',3800.00,2,2023),(2,'Melbourne Warehouse',3200.00,2,2023),(3,'Brisbane Warehouse',2800.00,2,2023);
SELECT warehouse_location, AVG(cost) as avg_cost FROM warehouse_costs_apac WHERE warehouse_location IN ('Sydney Warehouse', 'Melbourne Warehouse') AND quarter = 2 AND year = 2023 GROUP BY warehouse_location;
What is the average number of public consultations attended by residents in urban areas?
CREATE TABLE residents (id INT,age INT,city VARCHAR(50),state VARCHAR(50),rural BOOLEAN,consultations INT); INSERT INTO residents (id,age,city,state,rural,consultations) VALUES (1,34,'New York','NY',false,2),(2,55,'Los Angeles','CA',false,1); CREATE TABLE cities (id INT,name VARCHAR(50),state VARCHAR(50),rural BOOLEAN); INSERT INTO cities (id,name,state,rural) VALUES (1,'New York','NY',false),(2,'Los Angeles','CA',false),(3,'Smallville','NY',true);
SELECT AVG(consultations) as avg_consultations FROM residents r JOIN cities c ON r.city = c.name WHERE r.rural = false;
Add a new carbon offset initiative to the "carbon_offsets" table
CREATE TABLE carbon_offsets (id INT PRIMARY KEY,name VARCHAR(255),location VARCHAR(255),type VARCHAR(255),amount FLOAT);
INSERT INTO carbon_offsets (id, name, location, type, amount) VALUES (1, 'TreePlanting', 'Paris', 'Trees', 1000.0);
What is the percentage of mental health parity violations in each state?
CREATE TABLE parity_violations (state VARCHAR(25),violation_count INT); INSERT INTO parity_violations (state,violation_count) VALUES ('California',20),('New York',15),('Texas',10),('Florida',25),('Illinois',30),('Pennsylvania',22),('Ohio',18),('Georgia',27);
SELECT state, ROUND(100.0*SUM(violation_count) / (SELECT SUM(violation_count) FROM parity_violations), 2) as violation_percentage FROM parity_violations GROUP BY state;
List the local economic impact of tourism in New York and Los Angeles.
CREATE TABLE local_economy (city TEXT,impact FLOAT); INSERT INTO local_economy (city,impact) VALUES ('New York',12000),('Los Angeles',9000);
SELECT city, impact FROM local_economy WHERE city IN ('New York', 'Los Angeles');
What is the average revenue generated by sustainable tourism initiatives in North America per month?
CREATE TABLE sustainable_tourism_revenue (revenue_id INT,initiative_id INT,country TEXT,revenue DECIMAL(10,2),timestamp TIMESTAMP); INSERT INTO sustainable_tourism_revenue (revenue_id,initiative_id,country,revenue,timestamp) VALUES (1,1,'USA',2500.00,'2022-01-01 12:00:00'),(2,2,'Canada',3000.00,'2022-01-05 15:30:00');
SELECT AVG(revenue) FROM sustainable_tourism_revenue WHERE country IN ('USA', 'Canada') AND DATE_TRUNC('month', timestamp) = DATE_TRUNC('month', NOW());
What is the average number of voice commands successfully executed per day for luxury hotels?
CREATE TABLE voice_commands (id INT PRIMARY KEY,hotel_category VARCHAR(50),voice_command VARCHAR(50),success_count INT,command_date DATE); INSERT INTO voice_commands (id,hotel_category,voice_command,success_count,command_date) VALUES (1,'Luxury','Adjust lighting',35,'2022-03-01'),(2,'Luxury','Play music',28,'2022-03-02');
SELECT hotel_category, AVG(success_count) FROM voice_commands WHERE hotel_category = 'Luxury' GROUP BY hotel_category, DATE_TRUNC('day', command_date) HAVING COUNT(*) > 1;
What is the total revenue per hotel for the first two days of June, 2021, considering AI-powered hotel operations?
CREATE TABLE ota_bookings (ota_id INT,booking_date DATE,revenue FLOAT); INSERT INTO ota_bookings (ota_id,booking_date,revenue) VALUES (1,'2021-06-01',500.0),(3,'2021-06-01',400.0),(2,'2021-06-02',600.0); CREATE TABLE hotels (hotel_id INT,ota_id INT,hotel_name VARCHAR(50),ai_operations INT); INSERT INTO hotels (hotel_id,ota_id,hotel_name,ai_operations) VALUES (1,1,'Hotel A',1),(2,2,'Hotel B',1),(3,3,'Hotel C',0);
SELECT h.hotel_name, SUM(ob.revenue) as total_revenue FROM ota_bookings ob JOIN hotels h ON ob.ota_id = h.ota_id WHERE booking_date BETWEEN '2021-06-01' AND '2021-06-02' AND h.ai_operations = 1 GROUP BY h.hotel_name;
Which OTA (Online Travel Agency) has the highest virtual tour engagement in the 'ota_stats' table?
CREATE TABLE ota_stats (ota_name TEXT,virtual_tour_views INT); INSERT INTO ota_stats (ota_name,virtual_tour_views) VALUES ('Expedia',15000),('Booking.com',18000),('Agoda',12000);
SELECT ota_name, MAX(virtual_tour_views) FROM ota_stats;
Update the temperature of the record from 2011 to -18.5
CREATE TABLE climate (id INT PRIMARY KEY,year INT,temperature FLOAT,precipitation FLOAT,location VARCHAR(100));
WITH upd AS (UPDATE climate SET temperature = -18.5 WHERE year = 2011) SELECT id, year, temperature, precipitation, location FROM climate;
What is the average budget allocated for community engagement programs in North America?
CREATE TABLE CommunityEngagement (Location VARCHAR(50),Budget DECIMAL(10,2)); INSERT INTO CommunityEngagement (Location,Budget) VALUES ('North America',600000);
SELECT AVG(Budget) FROM CommunityEngagement WHERE Location = 'North America';
Display total cost of all road projects in New York
CREATE TABLE road_projects (id INT,name TEXT,cost FLOAT,location TEXT); INSERT INTO road_projects (id,name,cost,location) VALUES (1,'Road Project A',500000.00,'New York'),(2,'Road Project B',750000.00,'California');
SELECT SUM(cost) FROM road_projects WHERE location = 'New York';
Find the number of tourists who visited Australia in 2018
CREATE TABLE tourism_stats (destination VARCHAR(255),year INT,visitors INT); INSERT INTO tourism_stats (destination,year,visitors) VALUES ('Australia',2018,17000000);
SELECT visitors FROM tourism_stats WHERE destination = 'Australia' AND year = 2018;