context
stringlengths
11
9.12k
question
stringlengths
0
1.06k
SQL
stringlengths
2
4.44k
source
stringclasses
28 values
CREATE TABLE protected_areas (id INT, forest_type VARCHAR(255), area FLOAT);
How many protected areas are in temperate forests with high carbon sequestration?
SELECT COUNT(*) FROM protected_areas WHERE forest_type = 'Temperate Forest' AND area > (SELECT AVG(area) FROM forests WHERE carbon_sequestration > 50);
gretelai_synthetic_text_to_sql
CREATE TABLE coal_mine (company_id INT, quantity_mined INT);CREATE TABLE iron_ore_mine (company_id INT, quantity_mined INT);
What is the total quantity of coal and iron ore mined by each company?
SELECT m.company_name, SUM(cm.quantity_mined) AS total_coal_mined, SUM(iom.quantity_mined) AS total_iron_ore_mined FROM mining_companies m JOIN coal_mine cm ON m.company_id = cm.company_id JOIN iron_ore_mine iom ON m.company_id = iom.company_id GROUP BY m.company_name;
gretelai_synthetic_text_to_sql
CREATE TABLE iot_sensor_data (id INT, farm_id INT, sensor_type VARCHAR(255), value FLOAT, measurement_date DATE);
Insert new IoT sensor data for farm_id 444
INSERT INTO iot_sensor_data (id, farm_id, sensor_type, value, measurement_date) VALUES (8, 444, 'humidity', 65.3, '2022-06-03');
gretelai_synthetic_text_to_sql
CREATE TABLE carbon_prices (id INT, continent VARCHAR(50), year INT, price FLOAT); INSERT INTO carbon_prices (id, continent, year, price) VALUES (1, 'Europe', 2020, 25.0), (2, 'North America', 2020, 10.0);
What is the average carbon price in USD per tonne, for each continent, in 2020?
SELECT continent, AVG(price) FROM carbon_prices WHERE year = 2020 GROUP BY continent;
gretelai_synthetic_text_to_sql
CREATE TABLE broadband_subscriptions (customer_id INT, subscription BOOLEAN, state VARCHAR(50)); INSERT INTO broadband_subscriptions (customer_id, subscription, state) VALUES (1, TRUE, 'California'), (2, FALSE, 'Texas'), (3, TRUE, 'New York'); CREATE TABLE state_populations (state VARCHAR(50), population INT); INSERT INTO state_populations (state, population) VALUES ('California', 39512223), ('Texas', 29528404), ('New York', 19453561);
What is the total number of broadband subscribers in each state with a population of over 5 million?
SELECT bs.state, COUNT(bs.customer_id) AS num_subscribers FROM broadband_subscriptions bs JOIN state_populations sp ON bs.state = sp.state WHERE sp.population > 5000000 GROUP BY bs.state;
gretelai_synthetic_text_to_sql
CREATE TABLE Streaming (song VARCHAR(50), streams INT); INSERT INTO Streaming (song, streams) VALUES ('Heat Waves', 500), ('Drivers License', 700), ('Good 4 U', 600), ('Heat Waves', 400);
What was the total number of streams for a specific song?
SELECT SUM(streams) FROM Streaming WHERE song = 'Heat Waves';
gretelai_synthetic_text_to_sql
CREATE TABLE Immunization (ID INT, Country VARCHAR(100), Year INT, ChildImmunizationRate FLOAT); INSERT INTO Immunization (ID, Country, Year, ChildImmunizationRate) VALUES (1, 'Australia', 2020, 95.1);
What is the immunization rate for children in Australia?
SELECT ChildImmunizationRate FROM Immunization WHERE Country = 'Australia' AND Year = 2020;
gretelai_synthetic_text_to_sql
CREATE TABLE shariah_compliant_finance_2 (id INT, country VARCHAR(20), institution VARCHAR(30)); INSERT INTO shariah_compliant_finance_2 (id, country, institution) VALUES (1, 'UK', 'LBS Bank'), (2, 'Germany', 'KT Bank'), (3, 'France', 'Shariah Compliant Bank'), (4, 'Spain', 'Al Baraka Bank');
Number of Shariah-compliant finance institutions in Europe, ordered by institution_count descending.
SELECT country, COUNT(institution) AS institution_count FROM shariah_compliant_finance_2 WHERE country IN ('UK', 'Germany', 'France', 'Spain') GROUP BY country ORDER BY institution_count DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE articles (title VARCHAR(255), publication_date DATE, author VARCHAR(255), community VARCHAR(255)); INSERT INTO articles (title, publication_date, author, community) VALUES ('Article1', '2023-02-01', 'Author1', 'Underrepresented Community1'), ('Article2', '2023-02-05', 'Author2', 'Underrepresented Community2'), ('Article3', '2023-03-10', 'Author3', 'Underrepresented Community1'), ('Article4', '2023-03-15', 'Author4', 'Underrepresented Community2'), ('Article5', '2023-03-20', 'Author5', 'Underrepresented Community3');
How many articles were published in the last month by authors from underrepresented communities?
SELECT COUNT(*) FROM articles WHERE publication_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) AND community IN ('Underrepresented Community1', 'Underrepresented Community2', 'Underrepresented Community3');
gretelai_synthetic_text_to_sql
CREATE TABLE WasteGeneration (BrandID INT, WasteQuantity INT, RecycledQuantity INT);
What is the total quantity of textile waste generated by each fashion brand, and how much of it is recycled?
SELECT FB.BrandName, SUM(WG.WasteQuantity) AS TotalWasteGenerated, SUM(WG.RecycledQuantity) AS TotalWasteRecycled FROM FashionBrands FB INNER JOIN WasteGeneration WG ON FB.BrandID = WG.BrandID GROUP BY FB.BrandName;
gretelai_synthetic_text_to_sql
CREATE TABLE manufacturing_process (process_id INT, process_type VARCHAR(255), hazardous_waste_quantity INT);
What is the total quantity of hazardous waste generated by each manufacturing process, partitioned by process type and ordered by the highest total quantity?
SELECT process_type, process_id, SUM(hazardous_waste_quantity) AS total_waste FROM manufacturing_process GROUP BY process_type, process_id ORDER BY total_waste DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE Rocket_Engines (ID INT, Manufacturer VARCHAR(20), Failure_Rate DECIMAL(5,2)); INSERT INTO Rocket_Engines (ID, Manufacturer, Failure_Rate) VALUES (1, 'SpaceX', 0.05), (2, 'Arianespace', 0.02), (3, 'ULA', 0.01);
What is the failure rate of rocket engines by manufacturer?
SELECT Manufacturer, Failure_Rate FROM Rocket_Engines;
gretelai_synthetic_text_to_sql
CREATE TABLE schools (id INT, name TEXT, budget INT, city TEXT); INSERT INTO schools (id, name, budget, city) VALUES (1, 'SchoolA', 500000, 'CityA'), (2, 'SchoolB', 600000, 'CityA');
Which schools in CityA have the lowest overall budget per student?
SELECT s.name, s.budget/COUNT(ds.student_id) as avg_budget_per_student FROM schools s JOIN district_schools ds ON s.id = ds.school_id WHERE s.city = 'CityA' GROUP BY s.name HAVING avg_budget_per_student = (SELECT MIN(s.budget/COUNT(ds.student_id)) FROM schools s JOIN district_schools ds ON s.id = ds.school_id WHERE s.city = 'CityA' GROUP BY s.name);
gretelai_synthetic_text_to_sql
CREATE TABLE CommunityMediationCenters (Name VARCHAR(255), CasesHandled INT); INSERT INTO CommunityMediationCenters (Name, CasesHandled) VALUES ('CM Center 1', 120), ('CM Center 2', 150), ('CM Center 3', 175);
What is the number of cases handled by each community mediation center in 2021?
SELECT Name, SUM(CasesHandled) as TotalCasesHandled FROM CommunityMediationCenters WHERE YEAR(EventDate) = 2021 GROUP BY Name;
gretelai_synthetic_text_to_sql
CREATE TABLE attorneys (attorney_id INT, title TEXT); CREATE TABLE cases (case_id INT, attorney_id INT, billing_amount INT);
What is the total billing amount for cases handled by attorneys who have the word 'Partner' in their title?
SELECT SUM(cases.billing_amount) FROM cases INNER JOIN attorneys ON cases.attorney_id = attorneys.attorney_id WHERE attorneys.title LIKE '%Partner%';
gretelai_synthetic_text_to_sql
CREATE TABLE grad_students (id INT, name VARCHAR(50), department VARCHAR(50)); INSERT INTO grad_students VALUES (1, 'John Doe', 'Physics'); INSERT INTO grad_students VALUES (2, 'Jane Smith', 'Mathematics'); CREATE TABLE research_grants (id INT, student_id INT, year INT, amount DECIMAL(10, 2)); INSERT INTO research_grants VALUES (1, 1, 2021, 10000); INSERT INTO research_grants VALUES (2, 2, 2020, 12000);
Which graduate students received research grants in 2021?
SELECT g.name FROM grad_students g JOIN research_grants r ON g.id = r.student_id WHERE r.year = 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE Volunteers (VolunteerID INT, Name TEXT, Hours FLOAT); INSERT INTO Volunteers (VolunteerID, Name, Hours) VALUES (1, 'Alice', 7.0), (2, 'Bob', 4.0), (3, 'Charlie', 6.0);
Delete all volunteer records with less than 5 hours of service.
DELETE FROM Volunteers WHERE Hours < 5;
gretelai_synthetic_text_to_sql
CREATE TABLE bridges (id INT, name VARCHAR(50), state VARCHAR(50), length FLOAT); INSERT INTO bridges (id, name, state, length) VALUES (1, 'Bridge A', 'Texas', 650.00), (2, 'Bridge B', 'Texas', 450.33), (3, 'Bridge C', 'Florida', 700.00);
How many bridges in Texas have a length greater than 500 meters?
SELECT COUNT(*) FROM bridges WHERE state = 'Texas' AND length > 500;
gretelai_synthetic_text_to_sql
CREATE TABLE Employees (EmployeeID INT, Department VARCHAR(20), Ethnicity VARCHAR(20)); INSERT INTO Employees (EmployeeID, Department, Ethnicity) VALUES (1, 'Mining', 'Caucasian'); INSERT INTO Employees (EmployeeID, Department, Ethnicity) VALUES (2, 'Mining', 'African-American'); INSERT INTO Employees (EmployeeID, Department, Ethnicity) VALUES (3, 'Mining', 'Indigenous');
What is the number of workers in the Mining department who identify as Indigenous?
SELECT COUNT(*) FROM Employees WHERE Department = 'Mining' AND Ethnicity = 'Indigenous';
gretelai_synthetic_text_to_sql
CREATE TABLE Defense_Spending (Country VARCHAR(255), Year INT, Spending DECIMAL(10,2));
What is the total amount of defense spending by European countries in the last 20 years, including inflation adjustment?
SELECT SUM(Spending) FROM (SELECT Spending FROM Defense_Spending WHERE Country IN (SELECT DISTINCT Country FROM European_Countries) AND Year BETWEEN (YEAR(CURRENT_DATE)-20) AND YEAR(CURRENT_DATE) GROUP BY Spending, Year) AS Total_Spending;
gretelai_synthetic_text_to_sql
CREATE TABLE country_yields (country VARCHAR(50), crop_yield INT); INSERT INTO country_yields (country, crop_yield) VALUES ('US', 5000), ('China', 8000), ('India', 7000), ('Brazil', 6000);
Calculate the percentage of total crop yield that each country contributes.
SELECT country, SUM(crop_yield) * 100.0 / NULLIF(SUM(SUM(crop_yield)) OVER (), 0) AS pct_yield FROM country_yields GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE sea_level_data (city VARCHAR(255), year INT, sea_level FLOAT); CREATE TABLE city_information (city VARCHAR(255), location VARCHAR(255));
What is the change in sea level for each coastal city in the last 5 years?
SELECT city, (sea_level - LAG(sea_level) OVER (PARTITION BY city ORDER BY year)) AS sea_level_change FROM sea_level_data WHERE year BETWEEN 2018 AND 2022;
gretelai_synthetic_text_to_sql
CREATE TABLE donors (id INT, name TEXT, state TEXT, total_donated DECIMAL(10,2)); INSERT INTO donors (id, name, state, total_donated) VALUES (1, 'Jane Smith', 'Texas', 500.00); CREATE TABLE donations (id INT, donor_id INT, org_id INT, donation_amount DECIMAL(10,2)); INSERT INTO donations (id, donor_id, org_id, donation_amount) VALUES (1, 1, 1, 100.00);
Show the total number of unique donors who have donated to organizations with the word 'Child' in their name, excluding donors who have donated less than $25 in their lifetime and are located in 'Texas'.
SELECT COUNT(DISTINCT donor_id) FROM donations JOIN organizations ON donations.org_id = organizations.id WHERE organizations.name LIKE '%Child%' AND donor_id IN (SELECT donor_id FROM donations JOIN donors ON donations.donor_id = donors.id GROUP BY donor_id HAVING SUM(donation_amount) >= 25.00 AND state != 'Texas');
gretelai_synthetic_text_to_sql
CREATE SCHEMA if not exists genetics;CREATE TABLE if not exists genetics.experiments (id INT PRIMARY KEY, name VARCHAR(100), location VARCHAR(100)); INSERT INTO genetics.experiments (id, name, location) VALUES (1, 'ExpA', 'Buenos Aires'), (2, 'ExpB', 'Santiago'), (3, 'ExpC', 'Rio de Janeiro'), (4, 'ExpD', 'Lima'), (5, 'ExpE', 'Bogotá');
Which genetic research experiments have been conducted in South America?
SELECT DISTINCT name FROM genetics.experiments WHERE location = 'South America';
gretelai_synthetic_text_to_sql
CREATE SCHEMA if not exists arts_culture;CREATE TABLE if not exists arts_culture.donors (donor_id INT PRIMARY KEY, name VARCHAR(255), type VARCHAR(255), donation DECIMAL(10,2));INSERT INTO arts_culture.donors (donor_id, name, type, donation) VALUES (1, 'John Doe', 'Individual', 50.00), (2, 'Jane Smith', 'Individual', 100.00), (3, 'Google Inc.', 'Corporation', 5000.00);
Delete all records from the 'donors' table where the donation amount is less than $25.
DELETE FROM arts_culture.donors WHERE donation < 25.00;
gretelai_synthetic_text_to_sql
CREATE TABLE CityBudgets (city_id INT, city_name VARCHAR(50), budget_year INT, budget_amount DECIMAL(10,2)); INSERT INTO CityBudgets (city_id, city_name, budget_year, budget_amount) VALUES (1, 'New York', 2019, 50000), (2, 'Los Angeles', 2020, 60000), (3, 'Chicago', 2019, 40000), (4, 'Houston', 2020, 70000), (5, 'Philadelphia', 2019, 30000), (6, 'Phoenix', 2020, 80000);
Which cities had the highest total budget for programs in 2019 and 2020?
SELECT city_name, SUM(budget_amount) FROM CityBudgets WHERE budget_year IN (2019, 2020) GROUP BY city_name ORDER BY SUM(budget_amount) DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE life_expectancy_rural_urban (area VARCHAR(10), years FLOAT); INSERT INTO life_expectancy_rural_urban (area, years) VALUES ('Rural', 78.5), ('Urban', 81.2);
What is the average life expectancy, by rural vs urban areas?
SELECT area, AVG(years) as avg_years FROM life_expectancy_rural_urban GROUP BY area;
gretelai_synthetic_text_to_sql
CREATE TABLE mobile_subscribers (subscriber_id INT, country VARCHAR(50)); INSERT INTO mobile_subscribers (subscriber_id, country) VALUES (1, 'USA'), (2, 'Canada'), (3, 'Mexico'), (4, 'USA'), (5, 'Canada');
Calculate the percentage of mobile subscribers in each country?
SELECT country, (COUNT(*) / (SELECT COUNT(*) FROM mobile_subscribers)) * 100 AS percentage FROM mobile_subscribers GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE PlayerGameplay (PlayerID INT, Age INT, Gender VARCHAR(10), Playtime INT, Game VARCHAR(20)); INSERT INTO PlayerGameplay (PlayerID, Age, Gender, Playtime, Game) VALUES (1, 25, 'Female', 10000, 'Need for Speed');
What is the average playtime of racing games played by female players?
SELECT AVG(Playtime) FROM PlayerGameplay WHERE Game LIKE '%racing%' AND Gender = 'Female';
gretelai_synthetic_text_to_sql
CREATE TABLE CircularEconomy (initiative VARCHAR(100), location VARCHAR(50)); INSERT INTO CircularEconomy (initiative, location) VALUES ('Waste-to-Energy', 'Germany'), ('Plastic Recycling', 'France'), ('Green Public Procurement', 'Spain');
Identify the circular economy initiatives in the European Union.
SELECT initiative FROM CircularEconomy WHERE location LIKE 'Europe%';
gretelai_synthetic_text_to_sql
CREATE TABLE eco_housing (property_id INT, has_solar_panels BOOLEAN); INSERT INTO eco_housing VALUES (1, true), (2, false), (3, true)
Find the number of property_id's in eco_housing that have a 'solar_panels' feature.
SELECT COUNT(*) FROM eco_housing WHERE has_solar_panels = true;
gretelai_synthetic_text_to_sql
CREATE TABLE marine_protected_areas (name VARCHAR(255), country VARCHAR(255), area_size FLOAT); INSERT INTO marine_protected_areas (name, country, area_size) VALUES ('Ross Sea', 'New Zealand', 800000);
Which country has the largest marine protected area?
SELECT country, MAX(area_size) as max_size FROM marine_protected_areas;
gretelai_synthetic_text_to_sql
CREATE TABLE employees (employee_id INT, department VARCHAR(20), salary DECIMAL(10, 2));
Find the third highest salary for employees in the HR department, using a window function.
SELECT employee_id, department, salary FROM (SELECT employee_id, department, salary, RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS salary_rank FROM employees) AS employee_salaries WHERE salary_rank = 3 AND department = 'HR';
gretelai_synthetic_text_to_sql
CREATE TABLE co2_emissions_germany (sector VARCHAR(255), year INT, co2_emissions INT); INSERT INTO co2_emissions_germany VALUES ('Transportation', 2018, 800), ('Transportation', 2018, 850), ('Transportation', 2019, 820), ('Transportation', 2019, 870), ('Transportation', 2020, 780), ('Transportation', 2020, 830);
What is the average CO2 emissions in the transportation sector in Germany from 2018 to 2020?
SELECT AVG(co2_emissions) FROM co2_emissions_germany WHERE sector = 'Transportation' AND year BETWEEN 2018 AND 2020;
gretelai_synthetic_text_to_sql
CREATE TABLE network_investments (country VARCHAR(255), investment_amount DECIMAL(10,2)); INSERT INTO network_investments (country, investment_amount) VALUES ('USA', 5000000.00), ('Canada', 3000000.00), ('Mexico', 2000000.00), ('Brazil', 4000000.00);
Which countries have the highest network infrastructure investments?
SELECT country, investment_amount FROM network_investments ORDER BY investment_amount DESC LIMIT 2;
gretelai_synthetic_text_to_sql
CREATE TABLE Donors (DonorID int, DonorName varchar(50), Country varchar(50), DonationAmount numeric(18,2)); INSERT INTO Donors (DonorID, DonorName, Country, DonationAmount) VALUES (1, 'Donor1', 'USA', 5000), (2, 'Donor2', 'Canada', 7000), (3, 'Donor3', 'India', 8000), (4, 'Donor4', 'China', 9000);
What is the total donation amount by donors from Asia in 2019?
SELECT SUM(DonationAmount) FROM Donors WHERE YEAR(DonationDate) = 2019 AND Country IN ('India', 'China');
gretelai_synthetic_text_to_sql
CREATE TABLE grants (id INT, department VARCHAR(10), amount INT, year INT); INSERT INTO grants (id, department, amount, year) VALUES (1, 'Physics', 50000, 2020), (2, 'Mathematics', 75000, 2021);
What is the total grant amount awarded to the Mathematics department in 2021?
SELECT SUM(amount) FROM grants WHERE department = 'Mathematics' AND year = 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE Medals (Country VARCHAR(100), Continent VARCHAR(100), MedalType VARCHAR(10), Quantity INT); INSERT INTO Medals (Country, Continent, MedalType, Quantity) VALUES ('USA', 'North America', 'Gold', 101), ('China', 'Asia', 'Silver', 70), ('Great Britain', 'Europe', 'Bronze', 65);
What is the total number of medals won by each continent in the Summer Olympics?
SELECT Continent, SUM(Quantity) as TotalMedals FROM Medals GROUP BY Continent;
gretelai_synthetic_text_to_sql
CREATE TABLE Players (PlayerID INT, Age INT, Gender VARCHAR(10), HasPlayedVR BOOLEAN); INSERT INTO Players (PlayerID, Age, Gender, HasPlayedVR) VALUES (1, 25, 'Male', true), (2, 30, 'Female', false), (3, 22, 'Male', true);
What is the minimum age of players who have played VR games?
SELECT MIN(Age) FROM Players WHERE HasPlayedVR = true;
gretelai_synthetic_text_to_sql
CREATE TABLE accounts (account_id INT, region VARCHAR(20), balance DECIMAL(10,2)); INSERT INTO accounts (account_id, region, balance) VALUES (1, 'Africa', 1000.00), (2, 'Europe', 500.00);
What is the minimum balance for customers in the Africa region?
SELECT MIN(balance) FROM accounts WHERE region = 'Africa';
gretelai_synthetic_text_to_sql
CREATE TABLE theater_events (id INT, event_id INT, participant_id INT, country VARCHAR(50));
Calculate the number of distinct countries that have participated in theater events in the past year
SELECT COUNT(DISTINCT country) FROM theater_events WHERE event_date >= '2021-01-01';
gretelai_synthetic_text_to_sql
CREATE TABLE threat_indicators (id INT, sector TEXT, country TEXT, confidence INT); INSERT INTO threat_indicators (id, sector, country, confidence) VALUES (1, 'Healthcare', 'USA', 85); INSERT INTO threat_indicators (id, sector, country, confidence) VALUES (2, 'Healthcare', 'USA', 70); INSERT INTO threat_indicators (id, sector, country, confidence) VALUES (3, 'Healthcare', 'Canada', 88);
What is the maximum number of threat indicators for the healthcare sector in the United States?
SELECT MAX(confidence) FROM threat_indicators WHERE sector = 'Healthcare' AND country = 'USA';
gretelai_synthetic_text_to_sql
CREATE TABLE consumers (id INT, location VARCHAR(255), aware_of_sustainable_materials BOOLEAN); INSERT INTO consumers (id, location, aware_of_sustainable_materials) VALUES (1, 'Nigeria', true), (2, 'Kenya', false), (3, 'Egypt', true), (4, 'South Africa', true);
How many consumers in Africa are aware of sustainable materials?
SELECT COUNT(*) FROM consumers WHERE location LIKE 'Africa%' AND aware_of_sustainable_materials = true;
gretelai_synthetic_text_to_sql
CREATE TABLE chemical (chemical_id INT, plant_location VARCHAR(50)); CREATE TABLE incident (incident_id INT, chemical_id INT, incident_rate DECIMAL(5,2)); INSERT INTO chemical (chemical_id, plant_location) VALUES (1, 'Plant A'), (2, 'Plant A'), (3, 'Plant B'), (4, 'Plant B'); INSERT INTO incident (incident_id, chemical_id, incident_rate) VALUES (1, 1, 0.05), (2, 1, 0.07), (3, 2, 0.10), (4, 3, 0.03), (5, 4, 0.08);
Identify the top 2 chemicals with the highest safety incident rate, partitioned by plant location.
SELECT chemical_id, plant_location, incident_rate, RANK() OVER (PARTITION BY plant_location ORDER BY incident_rate DESC) as safety_rank FROM incident JOIN chemical ON incident.chemical_id = chemical.chemical_id WHERE safety_rank <= 2;
gretelai_synthetic_text_to_sql
CREATE TABLE PlayerStats (PlayerID INT, Kills INT, Deaths INT, Assists INT);
List all players who have achieved a KDA ratio greater than 5 in 'PlayerStats' table
SELECT p.PlayerID FROM PlayerStats p WHERE (p.Kills/p.Deaths + p.Assists) > 5;
gretelai_synthetic_text_to_sql
CREATE TABLE athlete_stats (athlete_id INT PRIMARY KEY, name VARCHAR(100), sport VARCHAR(50), team VARCHAR(50), games_played INT, goals_scored INT, assists INT); INSERT INTO athlete_stats (athlete_id, name, sport, team, games_played, goals_scored, assists) VALUES (1, 'John Doe', 'Soccer', 'Blue Eagles', 10, 5, 3), (2, 'Jane Smith', 'Soccer', 'Blue Eagles', 12, 7, 2), (3, 'Raj Patel', 'Cricket', 'Indian Lions', 15, 30, 15), (4, 'Emma Johnson', 'Basketball', 'NY Knicks', 20, 15, 5);
Display athlete names and their total goals and assists
SELECT name, SUM(goals_scored) as total_goals, SUM(assists) as total_assists FROM athlete_stats GROUP BY name;
gretelai_synthetic_text_to_sql
CREATE TABLE Naval_Officers (id INT, name VARCHAR(50), rank VARCHAR(50), age INT, years_of_service INT); INSERT INTO Naval_Officers (id, name, rank, age, years_of_service) VALUES (1, 'Alice Johnson', 'Commander', 40, 15); INSERT INTO Naval_Officers (id, name, rank, age, years_of_service) VALUES (2, 'Brian Lee', 'Lieutenant', 32, 8);
What is the average age of naval officers in the 'Naval_Officers' table?
SELECT AVG(age) FROM Naval_Officers WHERE rank LIKE 'Commander';
gretelai_synthetic_text_to_sql
CREATE TABLE fl_events (id INT, num_attendees INT, avg_ticket_price FLOAT); INSERT INTO fl_events (id, num_attendees, avg_ticket_price) VALUES (1, 5000, 20.5), (2, 7000, 25.0);
What is the total number of attendees at arts events in Florida and their average ticket price?
SELECT SUM(fe.num_attendees), AVG(fe.avg_ticket_price) FROM fl_events fe WHERE fe.state = 'FL';
gretelai_synthetic_text_to_sql
CREATE TABLE inventory (item_id INT, item_name TEXT, category TEXT, quantity INT); INSERT INTO inventory (item_id, item_name, category, quantity) VALUES (1, 'Hamburger', 'Meat', 100), (2, 'Bun', 'Bread', 20), (3, 'Lettuce', 'Vegetables', 5);
How many items in each category have a quantity less than 10?
SELECT category, COUNT(*) as low_quantity_items FROM inventory WHERE quantity < 10 GROUP BY category;
gretelai_synthetic_text_to_sql
CREATE TABLE Categories (CategoryID INT, CategoryName VARCHAR(255));CREATE TABLE Garments (GarmentID INT, CategoryID INT, SalePrice DECIMAL(10,2));CREATE TABLE Sales (SaleID INT, GarmentID INT, SaleDate DATE, Quantity INT);
What is the total sales revenue for each category of garment, ordered by the total sales revenue in descending order?
SELECT c.CategoryName, SUM(g.SalePrice * s.Quantity) AS TotalRevenue FROM Categories c JOIN Garments g ON c.CategoryID = g.CategoryID JOIN Sales s ON g.GarmentID = s.GarmentID GROUP BY c.CategoryName ORDER BY TotalRevenue DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE hotels_geo (id INT PRIMARY KEY, hotel_id INT, country VARCHAR(255));
What is the total number of hotels in each country?
SELECT h.country, COUNT(DISTINCT hg.hotel_id) FROM hotels h JOIN hotels_geo hg ON h.id = hg.hotel_id GROUP BY h.country;
gretelai_synthetic_text_to_sql
CREATE TABLE TV_Production (id INT, title VARCHAR(100), release_year INT); INSERT INTO TV_Production (id, title, release_year) VALUES (1, 'The Mandalorian', 2019), (2, 'Breaking Bad', 2008), (3, 'Black Mirror', 2011);
How many TV shows were produced each year?
SELECT release_year, COUNT(*) FROM TV_Production GROUP BY release_year;
gretelai_synthetic_text_to_sql
CREATE TABLE athlete_wellbeing (program_id INT, program_name VARCHAR(255), description TEXT, cost DECIMAL(5,2), date_started DATE, date_ended DATE);
What is the total cost of all athlete wellbeing programs that started in '2022' from 'athlete_wellbeing' table?
SELECT SUM(cost) FROM athlete_wellbeing WHERE YEAR(date_started) = 2022;
gretelai_synthetic_text_to_sql
CREATE TABLE incidents (incident_id INT, incident_date DATE, incident_sector VARCHAR(255));
How many security incidents were reported in the education sector in the last month?
SELECT COUNT(*) FROM incidents WHERE incident_sector = 'Education' AND incident_date >= DATEADD(month, -1, GETDATE());
gretelai_synthetic_text_to_sql
CREATE TABLE users (id INT, age INT, gender VARCHAR(10)); INSERT INTO users (id, age, gender) VALUES (1, 25, 'Female'), (2, 30, 'Male'); CREATE TABLE workouts (id INT, user_id INT, heart_rate INT, workout_time TIME); INSERT INTO workouts (id, user_id, heart_rate, workout_time) VALUES (1, 1, 120, '07:00:00'), (2, 1, 110, '09:00:00'), (3, 2, 140, '08:00:00');
What is the average heart rate of users aged 25-30 during their morning workouts?
SELECT AVG(heart_rate) FROM workouts WHERE user_id IN (SELECT id FROM users WHERE age BETWEEN 25 AND 30) AND workout_time BETWEEN '06:00:00' AND '11:59:59';
gretelai_synthetic_text_to_sql
CREATE TABLE mental_health_parity (id INT, state VARCHAR(2), parity_law VARCHAR(255));
Delete all records from the 'mental_health_parity' table where 'state' is 'CA'
DELETE FROM mental_health_parity WHERE state = 'CA';
gretelai_synthetic_text_to_sql
CREATE TABLE waste_production(state VARCHAR(20), year INT, operation VARCHAR(20), waste_produced INT); INSERT INTO waste_production VALUES ('Colorado', 2018, 'mining', 50000), ('Colorado', 2019, 'mining', 55000), ('Colorado', 2020, 'mining', 60000), ('Wyoming', 2018, 'mining', 70000), ('Wyoming', 2019, 'mining', 75000), ('Wyoming', 2020, 'mining', 80000);
Determine the total amount of waste produced by mining operations in each state
SELECT state, SUM(waste_produced) FROM waste_production WHERE year BETWEEN 2018 AND 2020 AND operation = 'mining' GROUP BY state;
gretelai_synthetic_text_to_sql
CREATE TABLE Donors (DonorID INT, DonorName TEXT, DonationCount INT); INSERT INTO Donors (DonorID, DonorName, DonationCount) VALUES (1, 'John Doe', 3), (2, 'Jane Smith', 1);
What is the percentage of donors who made more than one donation in 2021?
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Donors)) as '% of Donors with Multiple Donations' FROM Donors WHERE DonationCount > 1;
gretelai_synthetic_text_to_sql
CREATE TABLE public_hearings (hearing_id INT, topic VARCHAR(255), district VARCHAR(255)); INSERT INTO public_hearings (hearing_id, topic, district) VALUES (1, 'Transportation', 'Downtown'); INSERT INTO public_hearings (hearing_id, topic, district) VALUES (2, 'Education', 'Uptown');
Get the number of public hearings held in each district of the city
SELECT district, COUNT(*) FROM public_hearings GROUP BY district;
gretelai_synthetic_text_to_sql
CREATE TABLE mental_health_parity_violations (id INT, region VARCHAR(50), violation_count INT); INSERT INTO mental_health_parity_violations (id, region, violation_count) VALUES (1, 'Northeast', 10), (2, 'Southeast', 5), (3, 'Midwest', 15);
Identify the number of mental health parity violations by region?
SELECT region, SUM(violation_count) as total_violations FROM mental_health_parity_violations GROUP BY region;
gretelai_synthetic_text_to_sql
CREATE TABLE SpaceMissions (id INT, name VARCHAR(50), manufacturer VARCHAR(50), cost FLOAT); INSERT INTO SpaceMissions (id, name, manufacturer, cost) VALUES (1, 'InSight', 'SpacePro', 825000000); INSERT INTO SpaceMissions (id, name, manufacturer, cost) VALUES (2, 'Perseverance', 'SpacePro', 2400000000);
What is the total cost of SpacePro's Mars missions?
SELECT SUM(cost) FROM SpaceMissions WHERE manufacturer = 'SpacePro' AND name IN ('InSight', 'Perseverance');
gretelai_synthetic_text_to_sql
CREATE TABLE smart_city_initiatives (initiative_id INT, initiative_name VARCHAR(100), annual_budget FLOAT); INSERT INTO smart_city_initiatives (initiative_id, initiative_name, annual_budget) VALUES (1, 'Smart Lighting', 5000000), (2, 'Smart Waste Management', 7000000), (3, 'Smart Traffic Management', 6000000);
List the top 3 smart city initiatives by annual budget in descending order.
SELECT initiative_name, annual_budget FROM (SELECT initiative_name, annual_budget, ROW_NUMBER() OVER (ORDER BY annual_budget DESC) rn FROM smart_city_initiatives) WHERE rn <= 3
gretelai_synthetic_text_to_sql
CREATE TABLE planting_data (planting_date DATE, crop_type VARCHAR(20)); INSERT INTO planting_data (planting_date, crop_type) VALUES ('2022-05-01', 'Corn'), ('2022-05-15', 'Soybeans'), ('2022-05-30', 'Wheat'), ('2022-06-01', 'Corn'), ('2022-06-15', 'Soybeans');
Find the number of times each crop type was planted in the last 30 days
SELECT crop_type, COUNT(*) FROM planting_data WHERE planting_date >= DATE_SUB(CURDATE(), INTERVAL 30 DAY) GROUP BY crop_type;
gretelai_synthetic_text_to_sql
CREATE TABLE students (student_id INT, teacher_id INT, mental_health_score INT); INSERT INTO students (student_id, teacher_id, mental_health_score) VALUES (1, 1, 75), (2, 1, 80), (3, 2, 70); CREATE TABLE teachers (teacher_id INT, name VARCHAR(20)); INSERT INTO teachers (teacher_id, name) VALUES (1, 'James'), (2, 'Emily');
What is the average mental health score of students for each teacher?
SELECT t.teacher_id, t.name, AVG(s.mental_health_score) as avg_mental_health_score FROM students s JOIN teachers t ON s.teacher_id = t.teacher_id GROUP BY t.teacher_id, t.name;
gretelai_synthetic_text_to_sql
CREATE TABLE Missions (id INT, destination VARCHAR(100), had_problems BOOLEAN); INSERT INTO Missions VALUES (1, 'Jupiter', TRUE); INSERT INTO Missions VALUES (2, 'Jupiter', FALSE);
What is the total number of missions to Jupiter and the number of those missions that encountered problems?
SELECT SUM(CASE WHEN Missions.destination = 'Jupiter' THEN 1 ELSE 0 END) AS total_missions, SUM(CASE WHEN Missions.destination = 'Jupiter' AND Missions.had_problems = TRUE THEN 1 ELSE 0 END) AS problematic_missions FROM Missions;
gretelai_synthetic_text_to_sql
CREATE TABLE defense_projects (project_name VARCHAR(255), start_date DATE, end_date DATE); INSERT INTO defense_projects (project_name, start_date, end_date) VALUES ('Project A', '2021-01-01', '2023-12-31'), ('Project B', '2019-01-01', '2022-12-31'), ('Project C', '2021-01-01', '2024-12-31');
List all the defense projects with timelines extending into 2023 or beyond.
SELECT project_name FROM defense_projects WHERE end_date >= '2023-01-01';
gretelai_synthetic_text_to_sql
CREATE TABLE manufacturers (manufacturer_id INT, manufacturer_name VARCHAR(255), industry VARCHAR(255), avg_waste_produced DECIMAL(5,2));
What is the average waste produced by manufacturers in the leather industry?
SELECT AVG(avg_waste_produced) FROM manufacturers WHERE industry = 'leather';
gretelai_synthetic_text_to_sql
CREATE TABLE patients (id INT, age INT, gender VARCHAR(10), region VARCHAR(50), therapy_date DATE); CREATE VIEW region_therapy_patients AS SELECT region, AVG(age) as avg_age FROM patients WHERE therapy_date IS NOT NULL GROUP BY region;
What is the average age of patients who received therapy in each region?
SELECT * FROM region_therapy_patients;
gretelai_synthetic_text_to_sql
CREATE TABLE regions (region_id INT, region_name VARCHAR(50)); INSERT INTO regions (region_id, region_name) VALUES (1, 'North America'), (2, 'South America'), (3, 'Europe'), (4, 'Africa'), (5, 'Asia'), (6, 'Australia'); CREATE TABLE news_articles (article_id INT, content_type VARCHAR(50), region_id INT, creation_date DATE);
What is the distribution of content types by region for news articles in the past year?
SELECT content_type, region_name, COUNT(*) FROM news_articles JOIN regions ON news_articles.region_id = regions.region_id WHERE creation_date >= DATEADD(year, -1, GETDATE()) GROUP BY content_type, region_name;
gretelai_synthetic_text_to_sql
CREATE TABLE Employees (EmployeeID INT, Gender VARCHAR(10), Salary DECIMAL(10,2), HireDate DATE, Department VARCHAR(50)); INSERT INTO Employees (EmployeeID, Gender, Salary, HireDate, Department) VALUES (1, 'Male', 50000, '2020-01-01', 'HR'); INSERT INTO Employees (EmployeeID, Gender, Salary, HireDate, Department) VALUES (2, 'Female', 55000, '2019-01-01', 'IT'); INSERT INTO Employees (EmployeeID, Gender, Salary, HireDate, Department) VALUES (3, 'Male', 60000, '2020-05-01', 'IT'); INSERT INTO Employees (EmployeeID, Gender, Salary, HireDate, Department) VALUES (4, 'Female', 70000, '2018-01-01', 'Sales'); INSERT INTO Employees (EmployeeID, Gender, Salary, HireDate, Department) VALUES (5, 'Male', 80000, '2019-06-01', 'Finance');
What is the total salary cost for each department for employees hired in 2019?
SELECT Department, SUM(Salary) as Total_Salary_Cost FROM Employees WHERE YEAR(HireDate) = 2019 GROUP BY Department;
gretelai_synthetic_text_to_sql
CREATE TABLE agencies (agency VARCHAR(255)); INSERT INTO agencies (agency) VALUES ('DHS'), ('DIA'), ('NRO'), ('NGA'); CREATE TABLE military_tech (tech VARCHAR(255)); INSERT INTO military_tech (tech) VALUES ('encryption'), ('stealth'), ('UAV'), ('AI'), ('radar'); CREATE VIEW agency_tech AS SELECT a.agency, mt.tech FROM agencies a CROSS JOIN military_tech mt;
Identify the number of military technologies for each national security agency in the 'agency_tech' view.
SELECT a.agency, COUNT(*) FROM agency_tech a GROUP BY a.agency;
gretelai_synthetic_text_to_sql
CREATE TABLE visitor_data (destination VARCHAR(50), year INT, visitors INT);
Which destinations had a YoY visitor growth rate above 50% in 2021 compared to 2020?
SELECT destination, ((visitors_2021 / NULLIF(visitors_2020, 0) - 1) * 100) as yoy_growth_rate FROM visitor_data WHERE year IN (2020, 2021) GROUP BY destination HAVING MAX(yoy_growth_rate) > 50;
gretelai_synthetic_text_to_sql
CREATE TABLE Volunteers (id INT, first_name VARCHAR, last_name VARCHAR, email VARCHAR, phone_number VARCHAR, date_joined DATE); INSERT INTO Volunteers (id, first_name, last_name, email, phone_number, date_joined) VALUES (1, 'John', 'Doe', 'john.doe@email.com', '555-123-4567', '2021-05-01'), (2, 'Jane', 'Doe', 'jane.doe@email.com', '555-987-6543', '2021-06-01');
Update the phone number for a volunteer
UPDATE Volunteers SET phone_number = '555-987-6544' WHERE id = 2;
gretelai_synthetic_text_to_sql
CREATE TABLE Permits (PermitID INT, ProjectID INT, PermitType CHAR(1), PermitDate DATE);
Delete all records in the Permits table with a permit date before 2022-01-01.
DELETE FROM Permits WHERE PermitDate<'2022-01-01';
gretelai_synthetic_text_to_sql
CREATE TABLE users (id INT, name VARCHAR(50), country VARCHAR(50)); INSERT INTO users (id, name, country) VALUES (1, 'Ravi Kumar', 'India'), (2, 'Priya Patel', 'Canada'); CREATE TABLE engagements (id INT, user_id INT, post_id INT, timestamp DATETIME, engagement_type VARCHAR(50)); INSERT INTO engagements (id, user_id, post_id, timestamp, engagement_type) VALUES (1, 1, 2, '2022-01-01 13:00:00', 'like'), (2, 2, 3, '2022-01-04 11:00:00', 'comment');
How many users from India have never engaged with posts from users in Canada?
SELECT COUNT(DISTINCT users.id) FROM users LEFT JOIN engagements ON users.id = engagements.user_id AND engagements.engagement_type = 'like' WHERE users.country = 'India' AND engagements.user_id IS NULL;
gretelai_synthetic_text_to_sql
CREATE TABLE players (player_id INT, name VARCHAR(50)); INSERT INTO players VALUES (1, 'John'); INSERT INTO players VALUES (2, 'Jane'); INSERT INTO players VALUES (3, 'Mark'); CREATE TABLE scores (score_id INT, player_id INT, score INT); INSERT INTO scores VALUES (1, 1, 90); INSERT INTO scores VALUES (2, 1, 95); INSERT INTO scores VALUES (3, 2, 85); INSERT INTO scores VALUES (4, 2, 88); INSERT INTO scores VALUES (5, 3, 92); INSERT INTO scores VALUES (6, 3, 97);
Delete all records for players with a player_id greater than 100 from the 'players' and 'scores' tables.
DELETE FROM scores WHERE player_id > 100; DELETE FROM players WHERE player_id > 100;
gretelai_synthetic_text_to_sql
CREATE TABLE Vessels (ID INT, Name TEXT, FuelConsumption FLOAT, DockedAt DATETIME); INSERT INTO Vessels (ID, Name, FuelConsumption, DockedAt) VALUES (1, 'Vessel1', 500, '2022-01-01 10:00:00'), (2, 'Vessel2', 600, '2022-01-05 14:30:00'), (3, 'Vessel3', 700, '2022-02-01 11:00:00'); CREATE TABLE Ports (ID INT, Name TEXT); INSERT INTO Ports (ID, Name) VALUES (1, 'Oakland'), (2, 'San_Francisco');
What is the total fuel consumption of vessels with the name starting with 'V' that docked in the port of Oakland in the last month?
SELECT SUM(FuelConsumption) FROM Vessels WHERE Name LIKE 'V%' AND DockedAt >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) AND Ports.Name = 'Oakland';
gretelai_synthetic_text_to_sql
CREATE TABLE Games(game_id INT, game_name VARCHAR(50), genre VARCHAR(20), release_date DATE); INSERT INTO Games(game_id, game_name, genre, release_date) VALUES (1, 'Game 1', 'FPS', '2020-01-01'); INSERT INTO Games(game_id, game_name, genre, release_date) VALUES (2, 'Game 2', 'RPG', '2019-01-01');
How many FPS games were released in 2020?
SELECT COUNT(*) FROM Games WHERE genre = 'FPS' AND YEAR(release_date) = 2020;
gretelai_synthetic_text_to_sql
CREATE TABLE SunRise (id INT, importer VARCHAR(20), country VARCHAR(20), product VARCHAR(20), weight FLOAT); INSERT INTO SunRise (id, importer, country, product, weight) VALUES (1, 'SunRise', 'Spain', 'Oranges', 250.5), (2, 'SunRise', 'Italy', 'Grapes', 300.2);
What is the total weight of fruits imported by 'SunRise' from Spain?
SELECT SUM(weight) FROM SunRise WHERE importer = 'SunRise' AND country = 'Spain' AND product LIKE '%fruit%';
gretelai_synthetic_text_to_sql
CREATE TABLE staff (id INT, name VARCHAR(50), position VARCHAR(20), age INT); INSERT INTO staff (id, name, position, age) VALUES (1, 'John Doe', 'Editor', 50); INSERT INTO staff (id, name, position, age) VALUES (2, 'Jim Brown', 'Editor', 45); INSERT INTO staff (id, name, position, age) VALUES (3, 'Samantha Johnson', 'News Reporter', 35);
What is the name and age of the oldest editor in the 'staff' table?
SELECT name, age FROM staff WHERE position = 'Editor' ORDER BY age DESC LIMIT 1;
gretelai_synthetic_text_to_sql
CREATE TABLE Policyholders (PolicyID INT, PolicyholderName TEXT); INSERT INTO Policyholders (PolicyID, PolicyholderName) VALUES (1, 'John Doe'), (2, 'Jane Smith'); CREATE TABLE Claims (ClaimID INT, PolicyID INT, ClaimAmount INT); INSERT INTO Claims (ClaimID, PolicyID, ClaimAmount) VALUES (1, 1, 500), (2, 1, 750), (3, 2, 1000);
Calculate the total claim amount for each policy, grouped by policy ID and ordered by the total claim amount in descending order.
SELECT PolicyID, SUM(ClaimAmount) AS TotalClaimAmount FROM Claims GROUP BY PolicyID ORDER BY TotalClaimAmount DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE Cases (CaseID INT, ClientFirstName VARCHAR(50), ClientLastName VARCHAR(50), State VARCHAR(2), CaseOutcome VARCHAR(20), OpenDate DATE, CloseDate DATE); INSERT INTO Cases (CaseID, ClientFirstName, ClientLastName, State, CaseOutcome, OpenDate, CloseDate) VALUES (1, 'John', 'Doe', 'NY', 'settled', '2020-01-01', '2020-06-01'), (2, 'Jane', 'Smith', 'CA', 'won', '2019-01-01', '2019-12-31');
For cases with an outcome of 'settled', find the client's first and last name, state, and the difference between the case closing date and the case opening date, in descending order by the difference.
SELECT ClientFirstName, ClientLastName, State, DATEDIFF(CloseDate, OpenDate) AS DaysOpen FROM Cases WHERE CaseOutcome = 'settled' ORDER BY DaysOpen DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE Exhibitions (id INT, city VARCHAR(20), visitors INT, exhibition_date DATE); INSERT INTO Exhibitions (id, city, visitors, exhibition_date) VALUES (1, 'Barcelona', 40, '2021-06-01'), (2, 'Barcelona', 50, '2021-06-05');
What is the average number of visitors for exhibitions held in Barcelona?
SELECT AVG(visitors) as avg_visitors FROM Exhibitions WHERE city = 'Barcelona'
gretelai_synthetic_text_to_sql
CREATE TABLE returns (return_id INT, customer_id INT, item_id INT, return_date DATE);
Identify the top 5 customers who returned the most items in reverse logistics in Q4 2020.
SELECT customer_id, COUNT(*) as num_returns FROM returns WHERE EXTRACT(MONTH FROM return_date) BETWEEN 10 AND 12 GROUP BY customer_id ORDER BY num_returns DESC LIMIT 5;
gretelai_synthetic_text_to_sql
CREATE TABLE investments (id INT, fund_name VARCHAR(255), sector VARCHAR(255), investment_amount FLOAT);
Which fund has invested the most in the education sector?
SELECT fund_name, SUM(investment_amount) as total_investment FROM investments WHERE sector = 'education' GROUP BY fund_name ORDER BY total_investment DESC LIMIT 1;
gretelai_synthetic_text_to_sql
CREATE TABLE Library (LibraryName VARCHAR(50), Country VARCHAR(50), IsPublic BOOLEAN); INSERT INTO Library (LibraryName, Country, IsPublic) VALUES ('New York Public Library', 'United States', TRUE), ('British Library', 'United Kingdom', FALSE), ('National Library of France', 'France', FALSE);
What is the total number of public libraries in the United States?
SELECT COUNT(*) FROM Library WHERE Country = 'United States' AND IsPublic = TRUE;
gretelai_synthetic_text_to_sql
CREATE TABLE supplier_ethics (supplier_id INT, country VARCHAR(50), labor_practices VARCHAR(50), sustainability_score INT); CREATE TABLE product_transparency (product_id INT, supplier_id INT, material VARCHAR(50), country_of_origin VARCHAR(50), production_process VARCHAR(50)); CREATE VIEW supplier_sustainability_scores AS SELECT country, AVG(sustainability_score) as avg_sustainability_score FROM supplier_ethics GROUP BY country;
Show the average sustainability score and number of products for each country
SELECT s.country, AVG(se.sustainability_score) as avg_sustainability_score, COUNT(pt.product_id) as product_count FROM supplier_sustainability_scores s LEFT JOIN supplier_ethics se ON s.country = se.country LEFT JOIN product_transparency pt ON se.supplier_id = pt.supplier_id GROUP BY s.country;
gretelai_synthetic_text_to_sql
CREATE TABLE SmartContracts (id INT, name VARCHAR(50), hash VARCHAR(66));
List the smart contract names and their corresponding hashes in the 'SmartContracts' table.
SELECT name, hash FROM SmartContracts;
gretelai_synthetic_text_to_sql
CREATE TABLE energy_storage (id INT, state TEXT, year INT, capacity_mwh FLOAT); INSERT INTO energy_storage (id, state, year, capacity_mwh) VALUES (1, 'California', 2019, 500.2), (2, 'California', 2020, 700.3), (3, 'New York', 2021, 800.4);
What was the total energy storage capacity (MWh) added in New York in 2021?
SELECT SUM(capacity_mwh) FROM energy_storage WHERE state = 'New York' AND year = 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE Volunteers (VolunteerID INT, VolunteerName TEXT, VolunteerDate DATE, Hours INT);
Find the number of volunteers who have volunteered in the past month, and the number of volunteer hours they have contributed.
SELECT COUNT(DISTINCT VolunteerID) AS NumVolunteers, SUM(Hours) AS TotalHours FROM Volunteers WHERE VolunteerDate >= DATEADD(month, -1, GETDATE());
gretelai_synthetic_text_to_sql
CREATE TABLE City (id INT, name VARCHAR(50)); INSERT INTO City (id, name) VALUES (1, 'New York'); INSERT INTO City (id, name) VALUES (2, 'Los Angeles'); INSERT INTO City (id, name) VALUES (3, 'Rio de Janeiro'); INSERT INTO City (id, name) VALUES (4, 'London'); INSERT INTO City (id, name) VALUES (5, 'Tokyo'); CREATE TABLE Policy (id INT, name VARCHAR(50), city_id INT, category VARCHAR(50), budget DECIMAL(10,2), start_date DATE, end_date DATE, responsible_party VARCHAR(50)); INSERT INTO Policy (id, name, city_id, category, budget, start_date, end_date, responsible_party) VALUES (1, 'Education', 3, 'Education', 1200000, '2021-01-01', '2023-12-31', 'EduDeptRio'); INSERT INTO Policy (id, name, city_id, category, budget, start_date, end_date, responsible_party) VALUES (2, 'Healthcare', 3, 'Healthcare', 1500000, '2020-01-01', '2022-12-31', 'HealthDeptRio'); INSERT INTO Policy (id, name, city_id, category, budget, start_date, end_date, responsible_party) VALUES (3, 'Transportation', 4, 'Transportation', 2000000, '2019-01-01', '2024-12-31', 'TranspDeptLondon'); INSERT INTO Policy (id, name, city_id, category, budget, start_date, end_date, responsible_party) VALUES (4, 'Education', 4, 'Education', 1800000, '2020-01-01', '2023-12-31', 'EduDeptLondon'); INSERT INTO Policy (id, name, city_id, category, budget, start_date, end_date, responsible_party) VALUES (5, 'Transportation', 5, 'Transportation', 1000000, '2021-01-01', '2024-12-31', 'TranspDeptTokyo'); INSERT INTO Policy (id, name, city_id, category, budget, start_date, end_date, responsible_party) VALUES (6, 'Education', 3, 'Education', 1700000, '2022-01-01', '2025-12-31', 'EduDeptRio');
Who is responsible for implementing education policies in 'Rio de Janeiro'?
SELECT responsible_party FROM Policy WHERE city_id = 3 AND category = 'Education';
gretelai_synthetic_text_to_sql
CREATE TABLE vulnerabilities (vulnerability_id INT, severity VARCHAR(255), last_updated TIMESTAMP, patch_time INT); INSERT INTO vulnerabilities (vulnerability_id, severity, last_updated, patch_time) VALUES (1, 'High', '2022-01-01 10:00:00', 3), (2, 'High', '2022-02-01 15:30:00', 5), (3, 'High', '2022-03-01 08:15:00', 7);
What is the maximum number of days taken to patch a high-severity vulnerability in the last quarter?
SELECT MAX(patch_time) as max_patch_time FROM vulnerabilities WHERE severity = 'High' AND last_updated >= DATEADD(quarter, -1, CURRENT_TIMESTAMP);
gretelai_synthetic_text_to_sql
CREATE TABLE MilitaryEquipment (id INT, country VARCHAR(50), cost FLOAT); INSERT INTO MilitaryEquipment (id, country, cost) VALUES (1, 'China', 1200000), (2, 'Japan', 800000), (3, 'India', 1500000);
What is the average cost of military equipment maintenance per country in the Asia-Pacific region?
SELECT AVG(cost) FROM MilitaryEquipment WHERE country IN ('China', 'Japan', 'India') AND country LIKE '%Asia%';
gretelai_synthetic_text_to_sql
CREATE TABLE mine_operators (id INT PRIMARY KEY, name VARCHAR(50), role VARCHAR(50), gender VARCHAR(10), years_of_experience INT, join_date DATE); INSERT INTO mine_operators (id, name, role, gender, years_of_experience, join_date) VALUES (1, 'John Doe', 'Mining Engineer', 'Male', 7, '2019-01-01'), (2, 'Aisha', 'Mining Engineer', 'Female', 3, '2021-04-01');
List the names, roles, and years of experience of mining engineers who joined the company in January or February.
SELECT name, role, years_of_experience FROM mine_operators WHERE MONTH(join_date) IN (1, 2);
gretelai_synthetic_text_to_sql
CREATE TABLE teacher_pd (teacher_id INT, department VARCHAR(20), course_name VARCHAR(50), completion_date DATE); INSERT INTO teacher_pd (teacher_id, department, course_name, completion_date) VALUES (1, 'Science', 'Python for Data Analysis', '2022-05-01'), (2, 'Science', 'Open Pedagogy in STEM', '2022-06-15'), (3, 'English', 'Teaching Writing Online', '2022-04-01');
List the professional development courses completed by teachers in the "Science" department.
SELECT course_name FROM teacher_pd WHERE department = 'Science';
gretelai_synthetic_text_to_sql
CREATE TABLE sustain_tour (initiative_id INT, initiative_name TEXT, country TEXT, revenue FLOAT, start_date DATE, end_date DATE); INSERT INTO sustain_tour (initiative_id, initiative_name, country, revenue, start_date, end_date) VALUES (1, 'Canada Eco-Lodge Program', 'Canada', 5000.00, '2022-04-01', '2022-06-30'); INSERT INTO sustain_tour (initiative_id, initiative_name, country, revenue, start_date, end_date) VALUES (2, 'Canada Wildlife Conservation Fund', 'Canada', 7000.00, '2022-04-01', '2022-06-30');
What is the average daily revenue for sustainable tourism initiatives in Canada in the second quarter of 2022?
SELECT AVG(revenue/100) FROM sustain_tour WHERE country = 'Canada' AND start_date >= '2022-04-01' AND end_date < '2022-07-01';
gretelai_synthetic_text_to_sql
CREATE TABLE Rainfall_K (field VARCHAR(50), date DATE, rainfall FLOAT); INSERT INTO Rainfall_K (field, date, rainfall) VALUES ('Field K', '2022-01-01', 150.6), ('Field K', '2022-02-01', 125.8), ('Field K', '2022-03-01', 178.9);
What is the total rainfall in field K this year?
SELECT SUM(rainfall) FROM Rainfall_K WHERE field = 'Field K' AND date BETWEEN '2022-01-01' AND CURRENT_DATE;
gretelai_synthetic_text_to_sql
CREATE TABLE local_impact (year INT, location TEXT, economic_impact INT); INSERT INTO local_impact (year, location, economic_impact) VALUES (2019, 'Barcelona', 10000), (2021, 'Barcelona', 8000);
Find the local economic impact of tourism in Barcelona, Spain in 2021.
SELECT economic_impact FROM local_impact WHERE location = 'Barcelona' AND year = 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE weather_data (measurement_date DATE, precipitation FLOAT); INSERT INTO weather_data (measurement_date, precipitation) VALUES ('2022-01-01', 0.2), ('2022-01-02', 0.4), ('2022-01-15', 0.6);
Get precipitation data for the last 30 days
SELECT precipitation FROM weather_data WHERE measurement_date >= DATE(NOW()) - INTERVAL 30 DAY;
gretelai_synthetic_text_to_sql
CREATE TABLE wells (well_id INT, field VARCHAR(50), region VARCHAR(50), production_oil FLOAT, production_gas FLOAT, production_date DATE); INSERT INTO wells (well_id, field, region, production_oil, production_gas, production_date) VALUES (1, 'Thunder Horse', 'Gulf of Mexico', 20000.0, 7000.0, '2019-01-01'), (2, 'Tahiti', 'Gulf of Mexico', 12000.0, 5000.0, '2019-03-01');
What was the total oil production in the 'Gulf of Mexico' in 2019?
SELECT SUM(production_oil) FROM wells WHERE region = 'Gulf of Mexico' AND YEAR(production_date) = 2019;
gretelai_synthetic_text_to_sql