context
stringlengths
11
9.12k
question
stringlengths
0
1.06k
SQL
stringlengths
2
4.44k
source
stringclasses
28 values
CREATE TABLE CityYearPopulation (CityId INT, Year INT, Population INT, PRIMARY KEY (CityId, Year)); INSERT INTO CityYearPopulation (CityId, Year, Population) VALUES (1, 2019, 8400000); INSERT INTO CityYearPopulation (CityId, Year, Population) VALUES (1, 2020, 8600000); INSERT INTO CityYearPopulation (CityId, Year, Population) VALUES (2, 2019, 3900000); INSERT INTO CityYearPopulation (CityId, Year, Population) VALUES (2, 2020, 3800000);
What is the percentage change in population for each city between 2019 and 2020?
SELECT CityId, Year, Population, (Population - LAG(Population, 1) OVER (PARTITION BY CityId ORDER BY Year))*100.0 / LAG(Population, 1) OVER (PARTITION BY CityId ORDER BY Year) as PopulationPercentageChange FROM CityYearPopulation;
gretelai_synthetic_text_to_sql
CREATE TABLE Libraries (Location TEXT, Count INT); INSERT INTO Libraries (Location, Count) VALUES ('Urban', 150), ('Rural', 50);
How many public libraries exist in urban and rural areas, respectively?
SELECT Location, Count FROM Libraries;
gretelai_synthetic_text_to_sql
CREATE TABLE policy_holder (policy_holder_id INT, first_name VARCHAR(20), last_name VARCHAR(20), address VARCHAR(50));
Update the address of policyholder with policy_holder_id 123 in the 'policy_holder' table to '123 Main St, New York, NY 10001'.
UPDATE policy_holder SET address = '123 Main St, New York, NY 10001' WHERE policy_holder_id = 123;
gretelai_synthetic_text_to_sql
CREATE TABLE legal_aid_attorneys (attorney_id INT, name VARCHAR(50), cases_handled INT); INSERT INTO legal_aid_attorneys (attorney_id, name, cases_handled) VALUES (1, 'John Doe', 200), (2, 'Jane Smith', 300), (3, 'Mike Johnson', 150);
Identify the legal aid attorney with the most cases
SELECT name, MAX(cases_handled) FROM legal_aid_attorneys;
gretelai_synthetic_text_to_sql
CREATE TABLE Feedback (Date DATE, Region VARCHAR(50), Service VARCHAR(50), Comment TEXT); INSERT INTO Feedback (Date, Region, Service, Comment) VALUES ('2021-01-01', 'Central', 'Healthcare', 'Great service'), ('2021-01-02', 'Central', 'Healthcare', 'Poor service');
How many citizen feedback records were received for healthcare services in the Central region?
SELECT COUNT(*) FROM Feedback WHERE Region = 'Central' AND Service = 'Healthcare';
gretelai_synthetic_text_to_sql
CREATE TABLE wind_farms (id INT, country VARCHAR(255), name VARCHAR(255), capacity FLOAT); INSERT INTO wind_farms (id, country, name, capacity) VALUES (1, 'Germany', 'Windfarm A', 100.5), (2, 'Germany', 'Windfarm B', 110.2), (3, 'Germany', 'Windfarm C', 130.0);
What is the minimum installed capacity of a wind farm in Germany?
SELECT MIN(capacity) FROM wind_farms WHERE country = 'Germany';
gretelai_synthetic_text_to_sql
CREATE TABLE defense_projects (id INT, project_name VARCHAR(255), continent VARCHAR(255), start_date DATE, end_date DATE, contractor VARCHAR(255)); INSERT INTO defense_projects (id, project_name, continent, start_date, end_date, contractor) VALUES (1, 'Project E', 'Africa', '2016-01-01', '2022-12-31', 'Thales'); INSERT INTO defense_projects (id, project_name, continent, start_date, end_date, contractor) VALUES (2, 'Project F', 'Africa', '2017-01-01', NULL, 'BAE Systems');
List all defense projects in the African continent that started after 2015 and their associated contractors, ordered by the start date.
SELECT project_name, contractor FROM defense_projects WHERE continent = 'Africa' AND start_date > '2015-12-31' ORDER BY start_date;
gretelai_synthetic_text_to_sql
CREATE TABLE art_periods (id INT, art_period VARCHAR(50)); CREATE TABLE artworks (id INT, art_name VARCHAR(50), art_period_id INT); CREATE TABLE sales (id INT, artwork_id INT, sale_price DECIMAL(10, 2));
What is the highest sale price for a Pop Art sculpture?
SELECT MAX(s.sale_price) as max_price FROM sales s JOIN artworks a ON s.artwork_id = a.id JOIN art_periods p ON a.art_period_id = p.id WHERE p.art_period = 'Pop Art' AND a.art_type = 'sculpture';
gretelai_synthetic_text_to_sql
CREATE TABLE astronaut_medical(id INT, name VARCHAR(20), region VARCHAR(10), checkup_duration INT); INSERT INTO astronaut_medical(id, name, region, checkup_duration) VALUES (1, 'John Doe', 'America', 30); INSERT INTO astronaut_medical(id, name, region, checkup_duration) VALUES (2, 'Jane Smith', 'Asia', 45);
Find the average medical checkup duration (in minutes) for astronauts from Asia.
SELECT AVG(checkup_duration) FROM astronaut_medical WHERE region = 'Asia';
gretelai_synthetic_text_to_sql
CREATE TABLE AutoShows (Id INT, Location VARCHAR(50), Year INT, TotalAttendees INT); INSERT INTO AutoShows (Id, Location, Year, TotalAttendees) VALUES (1, 'Paris', 2018, 150000), (2, 'Lyon', 2020, 80000);
What is the total number of auto shows held in France over the last 5 years?
SELECT SUM(TotalAttendees) FROM AutoShows WHERE Location = 'France' AND Year >= (SELECT MAX(Year) - 5 FROM AutoShows);
gretelai_synthetic_text_to_sql
CREATE TABLE Brands (Brand_ID INT PRIMARY KEY, Brand_Name TEXT, Cruelty_Free BOOLEAN, Consumer_Preference FLOAT); INSERT INTO Brands (Brand_ID, Brand_Name, Cruelty_Free, Consumer_Preference) VALUES (1, 'Aromatica', TRUE, 4.6), (2, 'Herbivore', TRUE, 4.5), (3, 'Kora', FALSE, 4.2), (4, 'Lush', TRUE, 4.7);
Which cruelty-free brands have the highest consumer preference ratings?
SELECT Brand_Name, Consumer_Preference FROM Brands WHERE Cruelty_Free = TRUE ORDER BY Consumer_Preference DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE ArtPieces (id INT, title VARCHAR(255), type VARCHAR(255), price DECIMAL(10,2), sale_year INT, artist_country VARCHAR(255)); INSERT INTO ArtPieces (id, title, type, price, sale_year, artist_country) VALUES (1, 'Watercolor1', 'Watercolor', 800, 2020, 'USA');
What is the average price of watercolor paintings sold in the US?
SELECT AVG(price) FROM ArtPieces WHERE type = 'Watercolor' AND artist_country = 'USA';
gretelai_synthetic_text_to_sql
CREATE TABLE Vehicles (VehicleID INT, VehicleType VARCHAR(50), Service VARCHAR(50)); INSERT INTO Vehicles (VehicleID, VehicleType, Service) VALUES (1, 'MiniBus', 'Bus'), (2, 'StandardBus', 'Bus'), (3, 'ArticulatedBus', 'Bus'), (4, 'Tram', 'Tram'), (5, 'LightRail', 'Tram');
How many vehicles of each type are there in the 'Bus' and 'Tram' services?
SELECT VehicleType, Service, COUNT(*) as VehicleCount FROM Vehicles GROUP BY VehicleType, Service HAVING Service IN ('Bus', 'Tram') ORDER BY Service, VehicleCount DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE military_bases (base_id INT, base_name VARCHAR(50)); CREATE TABLE base_personnel (base_id INT, base_name VARCHAR(50), personnel_count INT); INSERT INTO military_bases VALUES (1, 'Fort Rucker'), (2, 'Fort Wainwright'), (3, 'Fort Huachuca'); INSERT INTO base_personnel VALUES (1, 'Fort Rucker', 5000), (2, 'Fort Wainwright', 3000), (3, 'Fort Huachuca', 7000);
Which military bases have the most number of military personnel in the 'military_bases' and 'base_personnel' tables?
SELECT m.base_name, SUM(bp.personnel_count) as total_personnel FROM military_bases m JOIN base_personnel bp ON m.base_id = bp.base_id GROUP BY m.base_name ORDER BY total_personnel DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE green_buildings (building_id INT, location TEXT, certification_level TEXT); INSERT INTO green_buildings (building_id, location, certification_level) VALUES (1, 'Los Angeles', 'Gold'), (2, 'Chicago', 'Platinum'), (3, 'Houston', 'Silver');
How many green buildings are there in the 'green_buildings' table?
SELECT COUNT(*) FROM green_buildings;
gretelai_synthetic_text_to_sql
CREATE TABLE restaurant_menu (restaurant_id INT, ingredient_id INT, sustainable BOOLEAN); INSERT INTO restaurant_menu (restaurant_id, ingredient_id, sustainable) VALUES (1, 1, true), (2, 2, false), (3, 1, true); CREATE TABLE ingredient (ingredient_id INT, ingredient_name VARCHAR(255)); INSERT INTO ingredient (ingredient_id, ingredient_name) VALUES (1, 'Organic Chicken'), (2, 'Farm Fresh Vegetables');
Which sustainable ingredients are most commonly used by restaurants in the top quartile of revenue?
SELECT ingredient_name, COUNT(*) as usage_count FROM ingredient i JOIN (SELECT DISTINCT ON (restaurant_id) restaurant_id, ingredient_id FROM restaurant_menu WHERE sustainable = true ORDER BY restaurant_id, revenue DESC) rm ON i.ingredient_id = rm.ingredient_id GROUP BY ingredient_name ORDER BY usage_count DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE transactions (transaction_id INT, customer_id INT, transaction_amount DECIMAL(10,2), transaction_date DATE, payment_method VARCHAR(50));
What is the total transaction value for each payment method in Q1 2022?
SELECT SUM(transaction_amount), payment_method FROM transactions WHERE transactions.transaction_date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY payment_method;
gretelai_synthetic_text_to_sql
CREATE TABLE restaurants (restaurant_id INT, name TEXT, city TEXT); INSERT INTO restaurants (restaurant_id, name, city) VALUES (1, 'Vancouver Pizza', 'Vancouver'), (2, 'Canada Delights', 'Vancouver'); CREATE TABLE inspections (inspection_id INT, restaurant_id INT, inspection_date DATE, grade TEXT); INSERT INTO inspections (inspection_id, restaurant_id, inspection_date, grade) VALUES (1, 1, '2021-05-01', 'A'), (2, 1, '2021-10-15', 'A'), (3, 2, '2021-01-20', 'B');
Display all food safety inspection records for restaurants located in the city of Vancouver, Canada.
SELECT * FROM inspections JOIN restaurants ON inspections.restaurant_id = restaurants.restaurant_id WHERE city = 'Vancouver';
gretelai_synthetic_text_to_sql
CREATE TABLE waste_generation (country VARCHAR(255), generation_rate FLOAT); INSERT INTO waste_generation (country, generation_rate) VALUES ('India', 0.62), ('China', 2.60);
What is the waste generation rate for India and China?
SELECT country, generation_rate FROM waste_generation WHERE country IN ('India', 'China');
gretelai_synthetic_text_to_sql
CREATE TABLE community_health_workers (id INT, name VARCHAR, age INT, ethnicity VARCHAR, lgbtq_identification BOOLEAN, language VARCHAR, mental_health_first_aid_training BOOLEAN); INSERT INTO community_health_workers (id, name, age, ethnicity, lgbtq_identification, language, mental_health_first_aid_training) VALUES (1, 'Jamie Wong', 35, 'Asian', FALSE, 'English', FALSE), (2, 'Maria Rodriguez', 40, 'Hispanic', FALSE, 'Spanish', TRUE);
Update the records of community health workers who identify as African American to reflect that they have received mental health first aid training.
UPDATE community_health_workers SET mental_health_first_aid_training = TRUE WHERE ethnicity = 'African American';
gretelai_synthetic_text_to_sql
CREATE TABLE mental_health_facilities (name VARCHAR(255), state VARCHAR(255), num_beds INT); INSERT INTO mental_health_facilities (name, state, num_beds) VALUES ('Facility A', 'NY', 100), ('Facility B', 'CA', 150), ('Facility C', 'TX', 200);
What is the total number of mental health facilities in each state?
SELECT state, COUNT(*) FROM mental_health_facilities GROUP BY state;
gretelai_synthetic_text_to_sql
CREATE TABLE waste_recycled (recycled_id INT, supplier_id INT, waste_recycled INT, recycling_date DATE); INSERT INTO waste_recycled (recycled_id, supplier_id, waste_recycled, recycling_date) VALUES (1, 1, 1000, '2022-01-01'), (2, 1, 2000, '2022-02-01');
What is the total waste recycled by each supplier, partitioned by year and ordered by total waste recycled?
SELECT supplier_id, DATE_TRUNC('year', recycling_date) AS year, SUM(waste_recycled) AS total_waste_recycled, RANK() OVER (PARTITION BY supplier_id ORDER BY SUM(waste_recycled) DESC) AS ranking FROM waste_recycled GROUP BY supplier_id, year ORDER BY total_waste_recycled DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE IngredientSource (id INT, product_id INT, ingredient_id INT, country VARCHAR(255), safety_rating INT); INSERT INTO IngredientSource (id, product_id, ingredient_id, country, safety_rating) VALUES (1, 1, 1, 'US', 90), (2, 1, 2, 'CA', 95), (3, 2, 3, 'MX', 85), (4, 2, 4, 'US', 92), (5, 1, 5, 'IN', 88), (6, 1, 6, 'IN', 91), (7, 3, 1, 'MX', 95), (8, 3, 2, 'MX', 92), (9, 3, 3, 'MX', 88), (10, 4, 1, 'CA', 90);
List the top 3 countries where most ingredients are sourced.
SELECT country, COUNT(*) as ingredient_count FROM IngredientSource GROUP BY country ORDER BY ingredient_count DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE EmployeeHistory (EmployeeID INT, ChangeDate DATE, ChangeType VARCHAR(255), Gender VARCHAR(255)); INSERT INTO EmployeeHistory (EmployeeID, ChangeDate, ChangeType, Gender) VALUES (1, '2022-01-01', 'Promotion', 'Female'), (2, '2022-04-01', 'Promotion', 'Male'), (3, '2022-02-15', 'Promotion', 'Non-binary');
How many promotions were made in the last 6 months, broken down by gender?
SELECT DATEPART(MONTH, ChangeDate) AS Month, Gender, COUNT(*) FROM EmployeeHistory WHERE ChangeType = 'Promotion' AND ChangeDate >= DATEADD(MONTH, -6, GETDATE()) GROUP BY Gender, DATEPART(MONTH, ChangeDate);
gretelai_synthetic_text_to_sql
CREATE TABLE south_china_sea_wells (well_id INT, well_name VARCHAR(50), drill_date DATE); INSERT INTO south_china_sea_wells (well_id, well_name, drill_date) VALUES (1, 'South China Sea Well A', '2017-01-01'), (2, 'South China Sea Well B', '2018-01-01'), (3, 'South China Sea Well C', '2019-01-01'), (4, 'South China Sea Well D', '2020-01-01');
Show the number of wells drilled in the South China Sea each year from 2017 to 2020.
SELECT YEAR(drill_date) AS Year, COUNT(*) AS Number_of_wells FROM south_china_sea_wells GROUP BY YEAR(drill_date);
gretelai_synthetic_text_to_sql
CREATE TABLE smart_contracts (id INT, name TEXT, developer TEXT); INSERT INTO smart_contracts (id, name, developer) VALUES (1, 'Contract1', 'John Doe'), (2, 'Contract2', 'Jane Smith');
Which smart contracts were created by developer 'John Doe'?
SELECT name FROM smart_contracts WHERE developer = 'John Doe';
gretelai_synthetic_text_to_sql
CREATE TABLE Lipsticks (product_id INT, product_name TEXT, price DECIMAL(5,2), quantity_sold INT, country TEXT); INSERT INTO Lipsticks (product_id, product_name, price, quantity_sold, country) VALUES (1, 'Ruby Woo', 18.00, 1500, 'USA'), (2, 'Russian Red', 19.50, 1200, 'USA'), (3, 'Lady Danger', 17.50, 1800, 'USA'), (4, 'Mick Jaggar', 16.00, 900, 'USA'), (5, 'Carmine', 15.00, 1300, 'USA');
What are the top 5 lipsticks sold in the USA in terms of revenue?
SELECT product_name, SUM(price * quantity_sold) AS revenue FROM Lipsticks WHERE country = 'USA' GROUP BY product_name ORDER BY revenue DESC LIMIT 5;
gretelai_synthetic_text_to_sql
CREATE TABLE patients (patient_id INT, age INT, condition VARCHAR(255)); INSERT INTO patients (patient_id, age, condition) VALUES (1, 35, 'Anxiety'); INSERT INTO patients (patient_id, age, condition) VALUES (2, 40, 'Depression'); CREATE TABLE workshops (workshop_id INT, name VARCHAR(255), completed BOOLEAN); INSERT INTO workshops (workshop_id, name, completed) VALUES (1, 'Coping Skills', true); INSERT INTO workshops (workshop_id, name, completed) VALUES (2, 'Mindfulness', false);
What is the average age of patients who have completed the 'Coping Skills' workshop?
SELECT AVG(patients.age) FROM patients INNER JOIN workshops ON patients.patient_id = workshops.workshop_id WHERE workshops.name = 'Coping Skills' AND workshops.completed = true;
gretelai_synthetic_text_to_sql
CREATE TABLE community_gardens (id INT, city VARCHAR(20), acreage DECIMAL(5,2)); INSERT INTO community_gardens (id, city, acreage) VALUES (1, 'TOR', 0.75), (2, 'VAN', 1.00), (3, 'TOR', 0.85), (4, 'VAN', 1.25);
What is the average acreage of community gardens in Toronto and Vancouver?
SELECT AVG(acreage) FROM community_gardens WHERE city IN ('TOR', 'VAN');
gretelai_synthetic_text_to_sql
CREATE TABLE berthing (id INT, vessel_type VARCHAR(255), berthing_time INT); INSERT INTO berthing VALUES (1, 'container', 120), (2, 'bulk', 150), (3, 'tanker', 200);
What is the average berthing time for each vessel type?
SELECT vessel_type, AVG(berthing_time) as avg_berthing_time FROM berthing GROUP BY vessel_type;
gretelai_synthetic_text_to_sql
CREATE TABLE socially_responsible_loans (id INT, value DECIMAL(10, 2), client_type VARCHAR(20), date DATE);
What is the total value of socially responsible loans issued to microfinance clients in H1 2022?
SELECT SUM(value) FROM socially_responsible_loans WHERE client_type = 'microfinance' AND date BETWEEN '2022-01-01' AND '2022-06-30';
gretelai_synthetic_text_to_sql
CREATE TABLE funding_rounds (company_id INT, round_number INT, funding_amount INT); INSERT INTO funding_rounds (company_id, round_number, funding_amount) VALUES (1, 1, 5000000), (1, 2, 7000000), (2, 1, 3000000), (2, 2, 4000000);
List all companies that had a higher funding round than their previous round, in descending order of difference.
SELECT a.company_id, (a.funding_amount - b.funding_amount) AS difference FROM funding_rounds a INNER JOIN funding_rounds b ON a.company_id = b.company_id AND a.round_number = b.round_number + 1 ORDER BY difference DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE virtual_tours (id INT PRIMARY KEY, hotel_name VARCHAR(255), num_views INT, view_date DATE);
Calculate the total number of virtual tours for each hotel since 2021-01-01
SELECT hotel_name, SUM(num_views) as total_views FROM virtual_tours WHERE view_date >= '2021-01-01' GROUP BY hotel_name;
gretelai_synthetic_text_to_sql
CREATE TABLE campaigns (campaign_name VARCHAR(30), reach INT, conversions INT); INSERT INTO campaigns (campaign_name, reach, conversions) VALUES ('Mental Health Awareness Campaign', 10000, 1500); INSERT INTO campaigns (campaign_name, reach, conversions) VALUES ('Suicide Prevention Campaign', 8000, 1200); INSERT INTO campaigns (campaign_name, reach, conversions) VALUES ('Depression Screening Campaign', 6000, 800);
What is the success rate of the 'Mental Health Awareness Campaign'?
SELECT (CONVERT(FLOAT, conversions) / reach) * 100.0 FROM campaigns WHERE campaign_name = 'Mental Health Awareness Campaign';
gretelai_synthetic_text_to_sql
CREATE TABLE cases (case_id INT, case_category VARCHAR(255), resolution_date DATE);
What is the average time to resolution for cases in each category?
SELECT case_category, AVG(DATEDIFF(resolution_date, case_date)) as avg_time_to_resolution FROM cases GROUP BY case_category;
gretelai_synthetic_text_to_sql
CREATE TABLE farmer_innovation (farmer_id INT PRIMARY KEY, farmer_name VARCHAR(50), innovation_id INT);
Delete all farmers who have not adopted any innovation from the 'farmer_innovation' table
DELETE FROM farmer_innovation WHERE farmer_id NOT IN (SELECT farmer_id FROM farmer_innovation GROUP BY farmer_id HAVING COUNT(DISTINCT innovation_id) > 0);
gretelai_synthetic_text_to_sql
See context
How many policyholders are in each age group?
SELECT * FROM num_policyholders_by_age;
gretelai_synthetic_text_to_sql
CREATE TABLE safety_test_results (id INT, vehicle_make VARCHAR, vehicle_model VARCHAR, safety_rating DECIMAL(3,2));
Identify the vehicle models with the lowest safety ratings, grouped by 'vehicle_make', in the 'safety_test_results' table.
SELECT vehicle_make, vehicle_model, MIN(safety_rating) OVER (PARTITION BY vehicle_make) AS min_safety_rating FROM safety_test_results WHERE safety_rating = min_safety_rating;
gretelai_synthetic_text_to_sql
CREATE TABLE coffee (id INT, country TEXT, farm_name TEXT, pesticide_kg FLOAT); INSERT INTO coffee (id, country, farm_name, pesticide_kg) VALUES (1, 'Brazil', 'Fazenda XYZ', 50.0), (2, 'Colombia', 'Hacienda ABC', 40.0), (3, 'Ethiopia', 'Plantation DEF', 30.0), (4, 'Guatemala', 'Finca GHI', 60.0);
Which countries have the highest pesticide usage in coffee production?
SELECT country, AVG(pesticide_kg) FROM coffee GROUP BY country ORDER BY AVG(pesticide_kg) DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE FASHION_TRENDS (trend_id INT PRIMARY KEY, trend_name VARCHAR(50), popularity INT); INSERT INTO FASHION_TRENDS (trend_id, trend_name, popularity) VALUES (1, 'TrendA', 1000), (2, 'TrendB', 800), (3, 'TrendC', 1200), (4, 'TrendD', 500);
Delete the fashion trend with the lowest popularity.
DELETE FROM FASHION_TRENDS WHERE trend_name = 'TrendD';
gretelai_synthetic_text_to_sql
CREATE TABLE cargo_ships (id INT PRIMARY KEY, name VARCHAR(50), year_built INT, type VARCHAR(50), capacity INT);
What are the names and types of all cargo ships in the 'cargo_ships' table that have a capacity greater than 50000 tons?
SELECT name, type FROM cargo_ships WHERE capacity > 50000;
gretelai_synthetic_text_to_sql
CREATE TABLE astronauts (astronaut_id INT, name VARCHAR(50), nationality VARCHAR(50), spacewalks INT, lifespan INT);
What is the average lifespan of astronauts who have been on spacewalks, grouped by their nationality?
SELECT a.nationality, AVG(a.lifespan) FROM astronauts a INNER JOIN (SELECT astronaut_id, COUNT(*) as spacewalks FROM spacewalks GROUP BY astronaut_id) sw ON a.astronaut_id = sw.astronaut_id WHERE a.spacewalks > 0 GROUP BY a.nationality;
gretelai_synthetic_text_to_sql
CREATE TABLE restaurants (id INT, name TEXT, city TEXT, state TEXT); INSERT INTO restaurants (id, name, city, state) VALUES (1, 'Restaurant A', 'New York', 'NY'), (2, 'Restaurant B', 'New York', 'NY'); CREATE TABLE dishes (id INT, name TEXT, price DECIMAL, restaurant_id INT, dietary_restrictions TEXT); INSERT INTO dishes (id, name, price, restaurant_id, dietary_restrictions) VALUES (1, 'Vegan Pizza', 15.00, 1, 'vegan'), (2, 'Pasta with Tomato Sauce', 12.00, 1, 'vegan'), (3, 'Cheeseburger', 10.50, 1, 'none'), (4, 'Fish and Chips', 15.00, 2, 'none');
What is the maximum price of vegan dishes offered by restaurants in New York?
SELECT MAX(price) FROM dishes WHERE dietary_restrictions = 'vegan' AND restaurant_id IN (SELECT id FROM restaurants WHERE city = 'New York');
gretelai_synthetic_text_to_sql
CREATE TABLE Employees (EmployeeID INT, FirstName VARCHAR(50), LastName VARCHAR(50), Department VARCHAR(50), Location VARCHAR(50), Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID, FirstName, LastName, Department, Location, Salary) VALUES (1, 'John', 'Doe', 'IT', 'New York', 80000.00), (2, 'Jane', 'Doe', 'HR', 'Los Angeles', 65000.00);
Update the salary of all employees in the 'HR' department to $70,000
UPDATE Employees SET Salary = 70000.00 WHERE Department = 'HR';
gretelai_synthetic_text_to_sql
CREATE TABLE maintenance (workshop VARCHAR(20), service_date DATE); INSERT INTO maintenance (workshop, service_date) VALUES ('Maintenance', '2021-03-15'), ('Body Shop', '2021-03-17'), ('Maintenance', '2021-03-20'), ('Tires', '2021-03-22'), ('Maintenance', '2021-03-30'), ('Body Shop', '2021-03-31');
What is the latest service date for the 'Body Shop'?
SELECT MAX(service_date) FROM maintenance WHERE workshop = 'Body Shop';
gretelai_synthetic_text_to_sql
CREATE TABLE continent_data (paper_id INT, continent VARCHAR(50)); INSERT INTO continent_data (paper_id, continent) VALUES (1, 'Africa'), (2, 'Asia'), (3, 'Africa');
What is the distribution of explainable AI papers by authors from different continents?
SELECT continent, COUNT(*) as num_papers FROM continent_data GROUP BY continent ORDER BY num_papers DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE cosmetics (product_name TEXT, consumer_preference_score INTEGER, cruelty_free BOOLEAN); INSERT INTO cosmetics (product_name, consumer_preference_score, cruelty_free) VALUES ('ProductA', 85, true), ('ProductB', 90, false), ('ProductC', 70, true), ('ProductD', 95, true), ('ProductE', 80, false), ('ProductF', 75, true);
What is the maximum consumer preference score for cosmetic products that are not certified cruelty-free?
SELECT MAX(consumer_preference_score) FROM cosmetics WHERE cruelty_free = false;
gretelai_synthetic_text_to_sql
CREATE TABLE Artists (id INT, artist_name VARCHAR(255), gender VARCHAR(255)); INSERT INTO Artists (id, artist_name, gender) VALUES (1, 'Artist 1', 'Female'), (2, 'Artist 2', 'Male'), (3, 'Artist 3', 'Female'); CREATE TABLE ArtPieces (id INT, artist_id INT, art_piece VARCHAR(255)); INSERT INTO ArtPieces (id, artist_id, art_piece) VALUES (1, 1, 'Painting 1'), (2, 1, 'Sculpture 1'), (3, 2, 'Painting 2'), (4, 3, 'Photography 1');
What is the total number of art pieces created by female artists?
SELECT COUNT(*) FROM ArtPieces JOIN Artists ON ArtPieces.artist_id = Artists.id WHERE Artists.gender = 'Female';
gretelai_synthetic_text_to_sql
CREATE TABLE coal_mines (id INT, name TEXT, location TEXT, production_rate FLOAT); INSERT INTO coal_mines (id, name, location, production_rate) VALUES (1, 'Shenhua', 'Inner Mongolia, China', 8.9), (2, 'Huangling', 'Shanxi, China', 7.1), (3, 'Datong', 'Shanxi, China', 5.3);
List coal mines in China with production rates above 5.5.
SELECT name, production_rate FROM coal_mines WHERE location LIKE '%China%' AND production_rate > 5.5;
gretelai_synthetic_text_to_sql
CREATE TABLE Sustainable_Materials(Sustainable_Material_ID INT, Sustainable_Material_Name TEXT, Manufacturing_Country TEXT); INSERT INTO Sustainable_Materials(Sustainable_Material_ID, Sustainable_Material_Name, Manufacturing_Country) VALUES (1, 'Organic Cotton', 'India'), (2, 'Recycled Polyester', 'China');
Find the top 2 brands with the highest quantity of sustainable material used, for each sustainable material type, and show the quantity used.
SELECT Brand_Name, Sustainable_Material_Name, SUM(Quantity) as Quantity FROM Brands JOIN Sustainable_Materials ON Brands.Sustainable_Material_ID = Sustainable_Materials.Sustainable_Material_ID GROUP BY Brand_Name, Sustainable_Material_Name ORDER BY Quantity DESC FETCH FIRST 2 ROWS WITH TIES;
gretelai_synthetic_text_to_sql
CREATE TABLE research_projects (id INT, title VARCHAR(255), department VARCHAR(100), funding DECIMAL(10,2), start_date DATE); INSERT INTO research_projects (id, title, department, funding, start_date) VALUES (1, 'AI Project', 'Computer Science', 80000.00, '2020-01-01'), (2, 'ML Project', 'Computer Science', 60000.00, '2021-01-01');
What is the total funding received by research projects in the Computer Science department, broken down by year?
SELECT YEAR(start_date) as year, SUM(funding) as total_funding FROM research_projects WHERE department = 'Computer Science' GROUP BY year;
gretelai_synthetic_text_to_sql
CREATE TABLE cultural_sites (site_id INT, site_name VARCHAR(50), country VARCHAR(50)); INSERT INTO cultural_sites VALUES (1, 'Acropolis', 'Greece'), (2, 'Colosseum', 'Italy'), (3, 'Machu Picchu', 'Peru'), (4, 'Taj Mahal', 'India'), (5, 'Petra', 'Jordan');
List the top 3 countries with the highest number of cultural heritage sites.
SELECT country, COUNT(*) as site_count FROM cultural_sites GROUP BY country ORDER BY site_count DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE Policyholders (ID INT, Age INT, State VARCHAR(50)); INSERT INTO Policyholders (ID, Age, State) VALUES (1, 35, 'California'), (2, 45, 'Texas'), (3, 30, 'California'), (4, 50, 'New York');
What is the average age of policyholders living in California?
SELECT AVG(Age) FROM Policyholders WHERE State = 'California';
gretelai_synthetic_text_to_sql
CREATE TABLE Students (StudentID INT PRIMARY KEY, SpecialEducation BOOLEAN, Anxiety DATE); INSERT INTO Students (StudentID, SpecialEducation, Anxiety) VALUES (1, 1, '2022-02-05');
How many students in the "Special Education" program have reported feelings of anxiety in the past week?
SELECT COUNT(*) FROM Students WHERE SpecialEducation = 1 AND Anxiety >= DATEADD(week, -1, GETDATE());
gretelai_synthetic_text_to_sql
CREATE TABLE sales (id INT, product_id INT, material VARCHAR(50), sale_date DATE, quantity INT);
What are the top 3 sustainable materials with the highest sales this month?
SELECT material, SUM(quantity) AS total_sales FROM sales WHERE material IN ('organic_cotton', 'recycled_polyester', 'tencel', 'hemp', 'modal') AND sale_date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH) GROUP BY material ORDER BY total_sales DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE autonomous_buses (bus_id INT, trip_start_time TIMESTAMP, trip_end_time TIMESTAMP, trip_distance FLOAT, city VARCHAR(50));
What is the maximum trip duration for autonomous buses in Seoul?
SELECT MAX(TIMESTAMP_DIFF(trip_end_time, trip_start_time, MINUTE)) as max_duration FROM autonomous_buses WHERE city = 'Seoul';
gretelai_synthetic_text_to_sql
CREATE TABLE broadband_subscribers (subscriber_id INT, plan_start_date DATE, plan_end_date DATE); INSERT INTO broadband_subscribers (subscriber_id, plan_start_date, plan_end_date) VALUES (1, '2021-01-01', '2021-01-31'), (2, '2021-02-01', '2021-02-28'), (3, '2020-12-15', '2021-01-14');
Find the total number of broadband subscribers who have not upgraded their plans in the last month.
SELECT COUNT(*) FROM broadband_subscribers WHERE plan_end_date < DATE_SUB(CURDATE(), INTERVAL 1 MONTH) AND plan_start_date < plan_end_date;
gretelai_synthetic_text_to_sql
CREATE TABLE waste_generation (area_type VARCHAR(50), waste_type VARCHAR(50), amount INT); INSERT INTO waste_generation (area_type, waste_type, amount) VALUES ('Urban', 'Organic', 1500), ('Rural', 'Organic', 1000);
What is the total amount of organic waste generated in urban areas compared to rural areas?
SELECT SUM(CASE WHEN area_type = 'Urban' THEN amount ELSE 0 END) AS urban_total, SUM(CASE WHEN area_type = 'Rural' THEN amount ELSE 0 END) AS rural_total FROM waste_generation WHERE waste_type = 'Organic';
gretelai_synthetic_text_to_sql
CREATE TABLE tours (id INT, name TEXT, city TEXT, rating FLOAT); INSERT INTO tours (id, name, city, rating) VALUES (1, 'Statue of Liberty Tour', 'New York City', 4.6), (2, 'Empire State Building Tour', 'New York City', 4.7), (3, 'Central Park Tour', 'New York City', 4.5);
What is the average rating of virtual tours in New York City?
SELECT AVG(rating) FROM tours WHERE city = 'New York City';
gretelai_synthetic_text_to_sql
CREATE TABLE startup_funding (id INT, name VARCHAR(50), location VARCHAR(50), industry VARCHAR(50)); INSERT INTO startup_funding (id, name, location, industry) VALUES (1, 'Startup C', 'Germany', 'Biotech'); INSERT INTO startup_funding (id, name, location, industry) VALUES (2, 'Startup D', 'USA', 'Biotech');
List all biotech startups that have received funding in Germany.
SELECT name FROM startup_funding WHERE industry = 'Biotech' AND location = 'Germany';
gretelai_synthetic_text_to_sql
CREATE TABLE cybersecurity_strategies (id INT, strategy VARCHAR(100), budget INT, year_developed INT);
What is the total budget for cybersecurity strategies that were developed before 2015, listed in the cybersecurity_strategies table?
SELECT SUM(budget) FROM cybersecurity_strategies WHERE year_developed < 2015;
gretelai_synthetic_text_to_sql
CREATE TABLE mine (id INT, name TEXT, location TEXT, mineral TEXT, productivity INT); INSERT INTO mine (id, name, location, mineral, productivity) VALUES (1, 'Bingham Canyon', 'USA', 'Lead', 1000), (2, 'Morenci', 'USA', 'Lead', 1100);
Delete all lead mines in the USA with productivity below 900?
DELETE FROM mine WHERE mineral = 'Lead' AND location = 'USA' AND productivity < 900;
gretelai_synthetic_text_to_sql
CREATE TABLE deliveries (id INT, delivery_date DATE, route_id VARCHAR(5), delivery_time INT); INSERT INTO deliveries (id, delivery_date, route_id, delivery_time) VALUES (1, '2022-01-02', 'R01', 300), (2, '2022-01-10', 'R02', 450), (3, '2022-01-15', 'R03', 250), (4, '2022-01-20', 'R02', 400), (5, '2022-01-25', 'R03', 275);
What is the average delivery time for route 'R03'?
SELECT AVG(delivery_time) FROM deliveries WHERE route_id = 'R03';
gretelai_synthetic_text_to_sql
CREATE TABLE MusicArtists (id INT, name VARCHAR(100), country VARCHAR(50), viewers INT);
What's the total number of viewers for music artists from Africa?
SELECT SUM(viewers) FROM MusicArtists WHERE country = 'Africa';
gretelai_synthetic_text_to_sql
CREATE TABLE Shipments (shipment_id INT, origin VARCHAR(50), destination VARCHAR(50), weight FLOAT, shipment_date DATE); INSERT INTO Shipments (shipment_id, origin, destination, weight, shipment_date) VALUES (1, 'California', 'Texas', 500.5, '2021-04-20'); INSERT INTO Shipments (shipment_id, origin, destination, weight, shipment_date) VALUES (2, 'California', 'Texas', 700.3, '2021-06-15');
What was the total weight of shipments from California to Texas in Q2 2021?
SELECT SUM(weight) FROM Shipments WHERE origin = 'California' AND destination = 'Texas' AND shipment_date BETWEEN '2021-04-01' AND '2021-06-30';
gretelai_synthetic_text_to_sql
CREATE TABLE CommunityHealthWorkers (Id INT, Age INT, Gender VARCHAR(10), Ethnicity VARCHAR(20)); INSERT INTO CommunityHealthWorkers (Id, Age, Gender, Ethnicity) VALUES (1, 45, 'Female', 'Hispanic'), (2, 35, 'Male', 'LGBTQ+'), (3, 50, 'Non-binary', 'African American'), (4, 40, 'Transgender', 'LGBTQ+'), (5, 30, 'Male', 'African American');
What is the minimum age of community health workers who identify as African American?
SELECT MIN(Age) as MinAge FROM CommunityHealthWorkers WHERE Ethnicity = 'African American';
gretelai_synthetic_text_to_sql
electric_vehicles
List all electric vehicles with a battery range greater than 350 miles
SELECT * FROM electric_vehicles WHERE battery_range > 350;
gretelai_synthetic_text_to_sql
CREATE TABLE renewable_projects (project_id INT, name VARCHAR(50), type VARCHAR(50), location VARCHAR(50)); INSERT INTO renewable_projects (project_id, name, type, location) VALUES (1, 'Wind Farm 1', 'Wind', 'Texas');
Find the number of Renewable Energy projects in each state in the USA
SELECT location, COUNT(*) FROM renewable_projects WHERE location LIKE 'USA%' GROUP BY location;
gretelai_synthetic_text_to_sql
CREATE TABLE plants (id INT, plant_name VARCHAR(50), state VARCHAR(50), capacity INT); INSERT INTO plants VALUES (1, 'LA Plant 1', 'California', 50000), (2, 'LA Plant 2', 'California', 60000), (3, 'SD Plant 1', 'California', 40000), (4, 'SF Plant 1', 'California', 70000);
How many water treatment plants are there in California and their capacities?
SELECT plant_name, capacity FROM plants WHERE state = 'California';
gretelai_synthetic_text_to_sql
CREATE TABLE cases (id INT, date DATE, legal_aid_org_id INT);CREATE VIEW latest_year AS SELECT EXTRACT(YEAR FROM date) as year, EXTRACT(MONTH FROM date) as month FROM cases;
How many cases were handled by each legal aid organization, in the last year?
SELECT legal_aid_org_id, COUNT(*) as cases_handled FROM cases INNER JOIN latest_year ON EXTRACT(YEAR FROM cases.date) = latest_year.year GROUP BY legal_aid_org_id;
gretelai_synthetic_text_to_sql
CREATE TABLE Brands (id INT, brand VARCHAR(255), country VARCHAR(255)); INSERT INTO Brands (id, brand, country) VALUES (1, 'BrandA', 'USA'), (2, 'BrandB', 'Canada'), (3, 'BrandC', 'Mexico'); CREATE TABLE Sales (id INT, brand_id INT, product VARCHAR(255), quantity INT, country VARCHAR(255)); INSERT INTO Sales (id, brand_id, product, quantity, country) VALUES (1, 1, 'Product1', 50, 'USA'), (2, 1, 'Product2', 75, 'USA'), (3, 2, 'Product3', 30, 'Canada'), (4, 2, 'Product4', 40, 'Canada'), (5, 3, 'Product5', 60, 'Mexico'), (6, 3, 'Product6', 80, 'Mexico');
What is the total quantity of products sold by each brand, grouped by country?
SELECT s.country, b.brand, SUM(s.quantity) AS total_quantity FROM Sales s JOIN Brands b ON s.brand_id = b.id GROUP BY s.country, b.brand;
gretelai_synthetic_text_to_sql
CREATE TABLE TransitUsers (id INT, city VARCHAR(50), usage INT); INSERT INTO TransitUsers (id, city, usage) VALUES (1, 'Los Angeles', 2500); INSERT INTO TransitUsers (id, city, usage) VALUES (2, 'San Francisco', 3000);
What is the total number of public transportation users in the cities of Los Angeles and San Francisco?
SELECT SUM(usage) FROM TransitUsers WHERE city IN ('Los Angeles', 'San Francisco');
gretelai_synthetic_text_to_sql
CREATE TABLE TraditionalArts (ArtForm varchar(50), ArtistCount int); INSERT INTO TraditionalArts (ArtForm, ArtistCount) VALUES ('Batik', 50), ('Ukara Stitching', 30), ('Tingatinga Painting', 40);
Which traditional art form has the most artists?
SELECT ArtForm FROM TraditionalArts WHERE ArtistCount = (SELECT MAX(ArtistCount) FROM TraditionalArts);
gretelai_synthetic_text_to_sql
CREATE TABLE subscriptions (id INT, user_id INT, start_date DATETIME, end_date DATETIME, price INT); CREATE TABLE users (id INT, name TEXT, is_subscriber BOOLEAN); CREATE TABLE user_activity (user_id INT, article_id INT, start_time DATETIME, end_time DATETIME); CREATE TABLE articles (id INT, title TEXT, category TEXT);
What is the total revenue generated from subscribers in the last quarter who read articles about 'technology'?
SELECT SUM(price) FROM subscriptions JOIN users ON subscriptions.user_id = users.id JOIN user_activity ON users.id = user_activity.user_id JOIN articles ON user_activity.article_id = articles.id WHERE articles.category = 'technology' AND subscriptions.start_date <= DATE_SUB(NOW(), INTERVAL 3 MONTH) AND subscriptions.end_date >= DATE_SUB(NOW(), INTERVAL 3 MONTH);
gretelai_synthetic_text_to_sql
CREATE TABLE network_investments (investment_id INT, region VARCHAR(50), investment_amount DECIMAL(10, 2)); INSERT INTO network_investments (investment_id, region, investment_amount) VALUES (1, 'Asia-Pacific', 500000.00), (2, 'Europe', 350000.00);
What is the total investment in network infrastructure for the Asia-Pacific region?
SELECT SUM(investment_amount) FROM network_investments WHERE region = 'Asia-Pacific';
gretelai_synthetic_text_to_sql
CREATE TABLE construction_employers (employer VARCHAR(50), state VARCHAR(20), num_employees INT); INSERT INTO construction_employers VALUES ('ABC Construction', 'Florida', 500), ('XYZ Construction', 'Florida', 600), ('DEF Construction', 'Florida', 450), ('GHI Construction', 'Georgia', 700);
Who are the top 2 employers of construction labor in Florida?
SELECT employer FROM construction_employers WHERE state = 'Florida' ORDER BY num_employees DESC LIMIT 2;
gretelai_synthetic_text_to_sql
CREATE TABLE region (id INT, name VARCHAR(255)); INSERT INTO region (id, name) VALUES (1, 'North America'), (2, 'Europe'), (3, 'Asia'); CREATE TABLE incident (id INT, region_id INT, timestamp TIMESTAMP); INSERT INTO incident (id, region_id) VALUES (1, 1), (2, 1), (3, 2), (4, 3), (5, 1);
How many cybersecurity incidents occurred in each region for the past year, grouped by region?
SELECT r.name, COUNT(i.id) as num_incidents FROM incident i JOIN region r ON i.region_id = r.id WHERE i.timestamp >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 YEAR) GROUP BY r.name;
gretelai_synthetic_text_to_sql
CREATE TABLE facilities (facility_id INT, condition VARCHAR(50)); INSERT INTO facilities VALUES (1, 'Depression'), (1, 'Anxiety'), (2, 'ADHD'), (3, 'Depression');
Identify facilities with the lowest number of mental health conditions treated.
SELECT facility_id FROM facilities GROUP BY facility_id HAVING COUNT(DISTINCT condition) = (SELECT MIN(cnt) FROM (SELECT COUNT(DISTINCT condition) as cnt FROM facilities GROUP BY facility_id) t);
gretelai_synthetic_text_to_sql
CREATE TABLE games (id INT, team_id INT, player_id INT, goals INT, sport VARCHAR(50)); INSERT INTO games (id, team_id, player_id, goals, sport) VALUES (1, 101, 1, 1, 'Soccer'); INSERT INTO games (id, team_id, player_id, goals, sport) VALUES (2, 102, 2, 2, 'Soccer');
What is the average number of goals scored by soccer players in the last 10 games they have played?
SELECT AVG(goals) FROM games WHERE sport = 'Soccer' AND id IN (SELECT game_id FROM last_10_games);
gretelai_synthetic_text_to_sql
CREATE TABLE biotech_startups (id INT, name VARCHAR(50), location VARCHAR(50), funding FLOAT); INSERT INTO biotech_startups (id, name, location, funding) VALUES (1, 'Genomic Inc', 'California', 1500000); INSERT INTO biotech_startups (id, name, location, funding) VALUES (2, 'BioSense', 'Texas', 1200000);
What is the maximum funding received by a biotech startup in Texas?
SELECT MAX(funding) FROM biotech_startups WHERE location = 'Texas';
gretelai_synthetic_text_to_sql
CREATE TABLE DrillingPlatforms (PlatformID int, PlatformName varchar(50), Location varchar(50), PlatformType varchar(50), NumberOfWells int); INSERT INTO DrillingPlatforms (PlatformID, PlatformName, Location, PlatformType, NumberOfWells) VALUES (1, 'A01', 'North Sea', 'Offshore', 10), (2, 'B02', 'Gulf of Mexico', 'Offshore', 15);
Add a new drilling platform named 'E05' in the North Sea for 'Offshore' operations to the DrillingPlatforms table.
INSERT INTO DrillingPlatforms (PlatformID, PlatformName, Location, PlatformType, NumberOfWells) VALUES (5, 'E05', 'North Sea', 'Offshore', 0);
gretelai_synthetic_text_to_sql
CREATE TABLE players (player_id INT, player_name TEXT, country TEXT); INSERT INTO players VALUES (1, 'John Doe', 'Egypt'), (2, 'Jane Smith', 'South Africa'), (3, 'Bob Johnson', 'Canada'); CREATE TABLE tournaments (tournament_id INT, tournament_name TEXT, country TEXT); INSERT INTO tournaments VALUES (1, 'ESL One', 'USA'), (2, 'DreamHack', 'Sweden'); CREATE TABLE wins (player_id INT, tournament_id INT, wins INT); INSERT INTO wins VALUES (1, 1, 3), (1, 2, 2), (2, 1, 1), (3, 1, 0);
What is the maximum number of wins in a tournament for a player from Africa?
SELECT MAX(wins.wins) FROM wins JOIN players ON wins.player_id = players.player_id WHERE players.country = 'Egypt' OR players.country = 'South Africa';
gretelai_synthetic_text_to_sql
CREATE TABLE SustainableMaterials (material_id INT, garment_id INT, quantity_used INT); INSERT INTO SustainableMaterials (material_id, garment_id, quantity_used) VALUES (1, 1, 500), (2, 1, 750), (3, 2, 800), (4, 3, 1000); CREATE TABLE ProductionDates (production_id INT, garment_id INT, production_date DATE); INSERT INTO ProductionDates (production_id, garment_id, production_date) VALUES (1, 1, '2021-01-01'), (2, 1, '2021-02-01'), (3, 2, '2021-03-01'), (4, 3, '2021-04-01');
What is the total quantity of sustainable materials used in the production of garments in the last 6 months?
SELECT SUM(SustainableMaterials.quantity_used) FROM SustainableMaterials INNER JOIN ProductionDates ON SustainableMaterials.garment_id = ProductionDates.garment_id WHERE ProductionDates.production_date BETWEEN DATEADD(month, -6, GETDATE()) AND GETDATE();
gretelai_synthetic_text_to_sql
CREATE TABLE Private_Banking (customer_id INT, name VARCHAR(50), division VARCHAR(20), account_balance DECIMAL(10,2)); INSERT INTO Private_Banking (customer_id, name, division, account_balance) VALUES (1, 'John Doe', 'Private Banking', 5000.00), (2, 'Jane Smith', 'Private Banking', 7000.00), (3, 'Karen Green', 'Compliance', 9000.00); CREATE TABLE Compliance (customer_id INT, name VARCHAR(50), division VARCHAR(20)); INSERT INTO Compliance (customer_id, name, division) VALUES (2, 'Jane Smith', 'Compliance');
What are the names and account balances of customers who have accounts in the Private Banking and Compliance divisions?
SELECT p.name, p.account_balance FROM Private_Banking p INNER JOIN Compliance c ON p.customer_id = c.customer_id WHERE p.division = 'Private Banking' AND c.division = 'Compliance';
gretelai_synthetic_text_to_sql
CREATE TABLE developers (id INT, name VARCHAR(50), salary FLOAT, project VARCHAR(50)); INSERT INTO developers (id, name, salary, project) VALUES (1, 'Alice', 80000.0, 'Machine Learning'); INSERT INTO developers (id, name, salary, project) VALUES (2, 'Bob', 85000.0, 'Machine Learning');
What is the maximum salary of developers who work on machine learning projects?
SELECT MAX(salary) FROM developers WHERE project = 'Machine Learning';
gretelai_synthetic_text_to_sql
CREATE TABLE sales_by_day (id INT, date DATE, quantity INT); INSERT INTO sales_by_day (id, date, quantity) VALUES (1, '2022-01-01', 25), (2, '2022-01-02', 30), (3, '2022-01-03', 20), (4, '2022-01-04', 35);
How many sales were made on '2022-01-02'?
SELECT SUM(quantity) FROM sales_by_day WHERE date = '2022-01-02';
gretelai_synthetic_text_to_sql
CREATE TABLE forests (id INT, name VARCHAR(255), location VARCHAR(255), biome VARCHAR(255), area FLOAT, elevation_range VARCHAR(255)); INSERT INTO forests (id, name, location, biome, area, elevation_range) VALUES (1, 'Amazon Rainforest', 'South America', 'Tropical Rainforest', 6700000, '0 - 300 m'); INSERT INTO forests (id, name, location, biome, area, elevation_range) VALUES (2, 'Congo Rainforest', 'Central Africa', 'Tropical Rainforest', 340000, '0 - 500 m');
List all the forests with an area greater than 500000 square kilometers, ranked by their area in descending order.
SELECT name, area FROM forests WHERE area > 500000 ORDER BY area DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE funding (funding_id INT, contributor VARCHAR(50), amount INT, region VARCHAR(20)); INSERT INTO funding (funding_id, contributor, amount, region) VALUES (1, 'Contributor A', 150000, 'Canada'), (2, 'Contributor B', 250000, 'Canada');
Who are the top 3 contributors to criminal justice reform in Canada by funding amount?
SELECT contributor FROM funding WHERE region = 'Canada' GROUP BY contributor ORDER BY SUM(amount) DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE african_countries (id INT, name VARCHAR(50)); CREATE TABLE mining_operations (id INT, country_id INT, region VARCHAR(20)); CREATE TABLE employees (id INT, operation_id INT, role VARCHAR(20)); INSERT INTO african_countries (id, name) VALUES (1, 'Egypt'), (2, 'South Africa'); INSERT INTO mining_operations (id, country_id, region) VALUES (1, 1, 'Africa'), (2, 2, 'Africa'); INSERT INTO employees (id, operation_id, role) VALUES (1, 1, 'Operator'), (2, 1, 'Engineer'), (3, 2, 'Operator');
What's the total number of employees and their roles in mining operations located in Africa?
SELECT e.role, COUNT(DISTINCT e.id) as total_employees FROM employees e INNER JOIN mining_operations m ON e.operation_id = m.id INNER JOIN african_countries c ON m.country_id = c.id GROUP BY e.role;
gretelai_synthetic_text_to_sql
CREATE SCHEMA carbon_offset; CREATE TABLE carbon_offset_programs (id INT, name VARCHAR(100), carbon_offset FLOAT); INSERT INTO carbon_offset_programs (id, name, carbon_offset) VALUES (1, 'Program G', 10.5), (2, 'Program H', 12.7);
Show the average carbon offset of programs in the 'carbon_offset' schema.
SELECT AVG(carbon_offset) FROM carbon_offset.carbon_offset_programs;
gretelai_synthetic_text_to_sql
CREATE TABLE NavalVessels (ID INT, Country VARCHAR(20), Type VARCHAR(20)); INSERT INTO NavalVessels (ID, Country, Type) VALUES (1, 'Russia', 'Submarine');
What are the types of naval vessels owned by the Russian government?
SELECT Type FROM NavalVessels WHERE Country = 'Russia';
gretelai_synthetic_text_to_sql
CREATE TABLE OrganicFruits (id INT, fruit VARCHAR(20), quantity INT, sale_date DATE); INSERT INTO OrganicFruits (id, fruit, quantity, sale_date) VALUES (1, 'Apples', 30, '2022-01-01'), (2, 'Bananas', 40, '2022-01-02');
What is the total quantity of organic fruits sold in the last month?
SELECT SUM(quantity) FROM OrganicFruits WHERE sale_date >= DATEADD(month, -1, GETDATE());
gretelai_synthetic_text_to_sql
CREATE TABLE mobile_subscribers (id INT, region VARCHAR(20), data_usage INT, usage_date DATE, broadband BOOLEAN);
List all mobile subscribers in South America who have used more than 10 GB of data in the last week and have an active broadband subscription?
SELECT m.id, m.region, m.data_usage, m.usage_date FROM mobile_subscribers m INNER JOIN (SELECT subscriber_id FROM mobile_subscribers WHERE data_usage > 10000 AND usage_date > DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK)) d ON m.id = d.subscriber_id WHERE m.region = 'South America' AND m.broadband = TRUE;
gretelai_synthetic_text_to_sql
CREATE TABLE Farm (region VARCHAR(255), stock_count INT); INSERT INTO Farm (region, stock_count) VALUES ('South Atlantic', 600), ('South Atlantic', 1100), ('South Pacific', 1300);
List the farms in the South Atlantic region with a stock count between 500 and 1500?
SELECT * FROM Farm WHERE region = 'South Atlantic' AND stock_count BETWEEN 500 AND 1500;
gretelai_synthetic_text_to_sql
CREATE TABLE fish_stock (fish_id INT PRIMARY KEY, species VARCHAR(50), location VARCHAR(50), biomass FLOAT); CREATE TABLE feeding (feed_id INT PRIMARY KEY, feed_type VARCHAR(50), nutrients FLOAT);
Insert data into the 'feeding' table with feed types 'pellets', 'flakes', and 'mash' and corresponding nutrient values 350, 280, and 420
INSERT INTO feeding (feed_id, feed_type, nutrients) VALUES (1, 'pellets', 350), (2, 'flakes', 280), (3, 'mash', 420);
gretelai_synthetic_text_to_sql
CREATE TABLE coastlines (country VARCHAR(50), length FLOAT); INSERT INTO coastlines (country, length) VALUES ('Canada', 202080), ('China', 14500), ('Indonesia', 54716), ('Russia', 37653), ('Philippines', 36289);
Which countries have the longest coastlines?
SELECT country, length FROM coastlines ORDER BY length DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE attorneys (id INT, first_name VARCHAR(20), last_name VARCHAR(20)); INSERT INTO attorneys (id, first_name, last_name) VALUES (1, 'Jane', 'Doe'), (2, 'John', 'Smith'), (3, 'Bob', 'Kim'); CREATE TABLE cases (id INT, attorney_id INT, case_type VARCHAR(10));
List all cases with a 'divorce' case_type, along with the attorney who handled the case, ordered by the attorney's last name in ascending order.
SELECT cases.id, attorney_id, case_type, attorneys.last_name FROM cases INNER JOIN attorneys ON cases.attorney_id = attorneys.id WHERE case_type = 'divorce' ORDER BY attorneys.last_name ASC;
gretelai_synthetic_text_to_sql
CREATE TABLE investments(id INT, investment VARCHAR(25), date DATE); INSERT INTO investments(id, investment, date) VALUES (1, 'FTTH deployment', '2020-01-01'), (2, '5G upgrade', '2019-12-15'), (3, 'Data center expansion', '2020-06-30');
List all network infrastructure investments made in the year 2020.
SELECT * FROM investments WHERE YEAR(date) = 2020;
gretelai_synthetic_text_to_sql
CREATE TABLE resource_depletion (id INT, location VARCHAR(50), operation_type VARCHAR(50), monthly_resource_depletion INT); INSERT INTO resource_depletion (id, location, operation_type, monthly_resource_depletion) VALUES (1, 'Australia', 'Gold', 500), (2, 'South Africa', 'Gold', 700), (3, 'Canada', 'Diamond', 600);
What is the average monthly resource depletion from gold mining operations in Australia and South Africa?
SELECT AVG(monthly_resource_depletion) as avg_depletion FROM resource_depletion WHERE operation_type = 'Gold' AND location IN ('Australia', 'South Africa');
gretelai_synthetic_text_to_sql
CREATE TABLE conservation_initiatives (initiative_id INT, initiative_name VARCHAR(100), budget FLOAT);
Identify the number of water conservation initiatives in the 'conservation_initiatives' table
SELECT COUNT(*) as num_conservation_initiatives FROM conservation_initiatives;
gretelai_synthetic_text_to_sql