context
stringlengths
11
9.12k
question
stringlengths
0
1.06k
SQL
stringlengths
2
4.44k
source
stringclasses
28 values
CREATE TABLE baseball_games (game_id INT, season_year INT, home_team VARCHAR(50), away_team VARCHAR(50), home_attendance INT, away_attendance INT);
What is the average attendance for home games of the New York Yankees?
SELECT AVG(home_attendance) FROM baseball_games WHERE home_team = 'New York Yankees';
gretelai_synthetic_text_to_sql
CREATE TABLE Garments (garment_id INT, garment_name VARCHAR(50), retail_price DECIMAL(5,2)); INSERT INTO Garments (garment_id, garment_name, retail_price) VALUES (1, 'Sequin Evening Gown', 850.99), (2, 'Cashmere Sweater', 250.00), (3, 'Silk Blouse', 150.00);
Find the top 3 most expensive garments by their retail price.
SELECT garment_name, retail_price FROM (SELECT garment_name, retail_price, ROW_NUMBER() OVER (ORDER BY retail_price DESC) as rn FROM Garments) sub WHERE rn <= 3;
gretelai_synthetic_text_to_sql
CREATE TABLE r_and_d_expenditures (id INT, drug_name VARCHAR(255), r_and_d_cost DECIMAL(10, 2), expenditure_date DATE);
List the top 5 drugs by R&D expenditure in 2021, with a running total of their R&D costs.
SELECT drug_name, r_and_d_cost, SUM(r_and_d_cost) OVER (ORDER BY r_and_d_cost DESC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as running_total FROM r_and_d_expenditures WHERE expenditure_date BETWEEN '2021-01-01' AND '2021-12-31' ORDER BY running_total DESC, drug_name LIMIT 5;
gretelai_synthetic_text_to_sql
CREATE TABLE VulnAssess (systemName VARCHAR(50), severityScore INT); INSERT INTO VulnAssess (systemName, severityScore) VALUES ('SystemA', 7), ('SystemB', 5), ('SystemC', 3), ('SystemD', 6), ('SystemE', 8);
What is the distribution of severity scores for vulnerabilities in the VulnAssess table?
SELECT severityScore, COUNT(*) FROM VulnAssess GROUP BY severityScore;
gretelai_synthetic_text_to_sql
CREATE TABLE customers (customer_id INT, customer_name TEXT, country TEXT); INSERT INTO customers (customer_id, customer_name, country) VALUES (1, 'John Doe', 'USA'), (2, 'Jane Smith', 'Canada'); CREATE TABLE orders (order_id INT, customer_id INT, order_value DECIMAL); INSERT INTO orders (order_id, customer_id, order_value) VALUES (1, 1, 100), (2, 1, 200), (3, 2, 50);
What is the average order value per customer from the United States?
SELECT AVG(order_value) FROM orders JOIN customers ON orders.customer_id = customers.customer_id WHERE customers.country = 'USA';
gretelai_synthetic_text_to_sql
CREATE TABLE WeatherData (location VARCHAR(50), date DATE, temperature DECIMAL(5,2)); INSERT INTO WeatherData (location, date, temperature) VALUES ('Greenland', '2019-07-01', 12.3), ('Greenland', '2019-07-02', 15.1);
What is the maximum temperature recorded in Greenland in July 2019?
SELECT MAX(temperature) FROM WeatherData WHERE location = 'Greenland' AND date BETWEEN '2019-07-01' AND '2019-07-31';
gretelai_synthetic_text_to_sql
CREATE TABLE restorative_justice (case_id INT, quarter INT, year INT, time_taken INT); INSERT INTO restorative_justice (case_id, quarter, year, time_taken) VALUES (1, 1, 2021, 30), (2, 1, 2021, 45), (3, 1, 2021, 60);
What was the average time taken for restorative justice cases in the first quarter of 2021?
SELECT AVG(time_taken) as avg_time FROM restorative_justice WHERE quarter = 1 AND year = 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE fans (fan_id INT, team_id INT, age INT, gender VARCHAR(10)); INSERT INTO fans (fan_id, team_id, age, gender) VALUES (1, 1, 35, 'Male'); INSERT INTO fans (fan_id, team_id, age, gender) VALUES (2, 2, 45, 'Female');
What are the average fan demographics (age and gender) for each team?
SELECT teams.team_name, AVG(fans.age) as avg_age, COUNT(CASE WHEN fans.gender = 'Male' THEN 1 ELSE NULL END) as male_count, COUNT(CASE WHEN fans.gender = 'Female' THEN 1 ELSE NULL END) as female_count FROM fans JOIN teams ON fans.team_id = teams.team_id GROUP BY teams.team_name;
gretelai_synthetic_text_to_sql
CREATE TABLE fares (id INT, route_id INT, vehicle_type VARCHAR(255), fare DECIMAL); INSERT INTO fares (id, route_id, vehicle_type, fare) VALUES (1, 1, 'Train', 5.00);
What is the average fare of trains per route in the "fares" table?
SELECT route_id, AVG(fare) FROM fares WHERE vehicle_type = 'Train' GROUP BY route_id;
gretelai_synthetic_text_to_sql
CREATE TABLE infrastructure_projects (id INT, project_name TEXT, budget INT);INSERT INTO infrastructure_projects (id, project_name, budget) VALUES (1, 'ProjectA', 5000000), (2, 'ProjectB', 3000000), (3, 'ProjectC', 7000000);
What is the maximum budget allocated for any project in the infrastructure projects table?
SELECT MAX(budget) FROM infrastructure_projects;
gretelai_synthetic_text_to_sql
CREATE TABLE energy_storage (id INT, year INT, country VARCHAR(255), capacity FLOAT); INSERT INTO energy_storage (id, year, country, capacity) VALUES (1, 2015, 'Japan', 120.5), (2, 2016, 'Japan', 135.2), (3, 2017, 'Japan', 142.1), (4, 2018, 'Japan', 150.9);
What is the change in energy storage capacity in Japan between 2015 and 2018?
SELECT (capacity - LAG(capacity) OVER (PARTITION BY country ORDER BY year)) FROM energy_storage WHERE country = 'Japan' AND year IN (2016, 2017, 2018);
gretelai_synthetic_text_to_sql
CREATE TABLE health_equity_metrics (id INT, worker_id INT, region VARCHAR(50), metric1 BOOLEAN, metric2 BOOLEAN, metric3 BOOLEAN); INSERT INTO health_equity_metrics (id, worker_id, region, metric1, metric2, metric3) VALUES (1, 1, 'Southeast', true, true, false), (2, 2, 'Southeast', true, false, true), (3, 3, 'Southeast', false, true, true);
What is the percentage of health equity metrics met by each community health worker in the Southeast region?
SELECT worker_id, (SUM(CASE WHEN metric1 THEN 1 ELSE 0 END) + SUM(CASE WHEN metric2 THEN 1 ELSE 0 END) + SUM(CASE WHEN metric3 THEN 1 ELSE 0 END)) * 100.0 / 3 as percentage_met FROM health_equity_metrics WHERE region = 'Southeast' GROUP BY worker_id;
gretelai_synthetic_text_to_sql
CREATE TABLE WorkplaceSafety (id INT, quarter VARCHAR(10), incidents INT); INSERT INTO WorkplaceSafety (id, quarter, incidents) VALUES (1, 'Q1', 12), (2, 'Q2', 15), (3, 'Q3', 18);
List the number of workplace safety incidents for each quarter in the 'WorkplaceSafety' table
SELECT quarter, SUM(incidents) as total_incidents FROM WorkplaceSafety GROUP BY quarter;
gretelai_synthetic_text_to_sql
CREATE TABLE renewable_energy_japan (id INT, city VARCHAR(255), production FLOAT); INSERT INTO renewable_energy_japan (id, city, production) VALUES (1, 'Tokyo', 2000), (2, 'Osaka', 1500), (3, 'Nagoya', 1200);
List the renewable energy production of each city in Japan, sorted in descending order.
SELECT city, production FROM renewable_energy_japan ORDER BY production DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE sustainable_tourism (id INT, initiative VARCHAR(20), country VARCHAR(20), revenue DECIMAL(10, 2)); INSERT INTO sustainable_tourism (id, initiative, country, revenue) VALUES (1, 'Eco-Lodge', 'Costa Rica', 5000.00), (2, 'Birdwatching Tours', 'Costa Rica', 3000.00);
What is the total revenue generated from sustainable tourism initiatives in Costa Rica?
SELECT SUM(revenue) FROM sustainable_tourism WHERE country = 'Costa Rica';
gretelai_synthetic_text_to_sql
CREATE TABLE HighSchoolX (studentID INT, mentalHealthScore INT); INSERT INTO HighSchoolX (studentID, mentalHealthScore) VALUES (1, 80), (2, 85), (3, 70);
What is the average mental health score of students in 'High School X'?
SELECT AVG(mentalHealthScore) FROM HighSchoolX WHERE schoolName = 'High School X';
gretelai_synthetic_text_to_sql
game_stats(player_id, game_id, score, date_played)
Show all the players who have played more than 50 games
SELECT g.player_id, p.name FROM game_stats g JOIN players p ON g.player_id = p.player_id GROUP BY g.player_id HAVING COUNT(DISTINCT g.game_id) > 50;
gretelai_synthetic_text_to_sql
CREATE TABLE companies (id INT, name TEXT, founding_year INT, founder_count INT); INSERT INTO companies (id, name, founding_year, founder_count) VALUES (1, 'InnoVentures', 2018, 3); INSERT INTO companies (id, name, founding_year, founder_count) VALUES (2, 'TechBoost', 2018, 1); INSERT INTO companies (id, name, founding_year, founder_count) VALUES (3, 'GreenCoder', 2016, 2);
What is the average number of founders in companies founded in 2018?
SELECT AVG(founder_count) FROM companies WHERE founding_year = 2018;
gretelai_synthetic_text_to_sql
CREATE TABLE products (product_id INT, category TEXT, rating FLOAT); INSERT INTO products (product_id, category, rating) VALUES (1, 'Lips', 4.5), (2, 'Face', 3.2), (3, 'Lips', 4.8);
What is the average rating of products in the 'Face' category?
SELECT AVG(rating) FROM products WHERE category = 'Face';
gretelai_synthetic_text_to_sql
CREATE TABLE PlayerGameScores (GameID int, PlayerID int, PlayerName varchar(50), GameType varchar(50), Wins int); INSERT INTO PlayerGameScores (GameID, PlayerID, PlayerName, GameType, Wins) VALUES (1, 1, 'Leung Chan', 'Racing', 12), (2, 1, 'Leung Chan', 'Shooter', 8), (3, 2, 'Akane Tanaka', 'Racing', 15), (4, 2, 'Akane Tanaka', 'Shooter', 10), (5, 3, 'Park Min-ho', 'Racing', 8);
What is the highest number of wins in a single game for each player?
SELECT PlayerID, MAX(Wins) FROM PlayerGameScores GROUP BY PlayerID;
gretelai_synthetic_text_to_sql
CREATE TABLE if not exists Buses (id INT, type VARCHAR(20), city VARCHAR(20), operating INT, date DATE); INSERT INTO Buses (id, type, city, operating, date) VALUES (1, 'Electric', 'Cairo', 100, '2022-03-22'), (2, 'Diesel', 'Cairo', 200, '2022-03-22'), (3, 'Electric', 'Cairo', 95, '2022-03-23');
What is the minimum number of electric buses operating in Cairo on a daily basis?
SELECT MIN(operating) FROM Buses WHERE type = 'Electric' AND city = 'Cairo';
gretelai_synthetic_text_to_sql
CREATE TABLE agroecology_projects (id INT, name TEXT, country TEXT, avg_rainfall FLOAT); INSERT INTO agroecology_projects (id, name, country, avg_rainfall) VALUES (1, 'Project 1', 'Brazil', 100.5), (2, 'Project 2', 'Colombia', 120.0);
What is the average rainfall in June for agroecology projects in Brazil and Colombia?
SELECT AVG(avg_rainfall) as avg_rainfall FROM agroecology_projects WHERE country IN ('Brazil', 'Colombia') AND MONTH(datetime) = 6;
gretelai_synthetic_text_to_sql
CREATE TABLE energy_consumption(year INT, operation VARCHAR(20), daily_energy_consumption FLOAT); INSERT INTO energy_consumption VALUES (2018, 'mining', 25000.5), (2019, 'mining', 26000.3), (2020, 'mining', 27000.2);
Calculate the average amount of energy consumed by mining operations per day
SELECT AVG(daily_energy_consumption) FROM energy_consumption WHERE year BETWEEN 2018 AND 2020 AND operation = 'mining';
gretelai_synthetic_text_to_sql
CREATE TABLE mobile_usage (subscriber_id INT, month INT, usage FLOAT); INSERT INTO mobile_usage (subscriber_id, month, usage) VALUES (1, 1, 100), (1, 2, 110), (2, 1, 200), (2, 2, 220), (3, 1, 150), (3, 2, 180);
Detect mobile subscribers with a sudden increase in data usage, showing the top 3 largest increase percentages.
SELECT subscriber_id, 100.0 * (LAG(usage, 1) OVER (PARTITION BY subscriber_id ORDER BY month) - usage) / LAG(usage, 1) OVER (PARTITION BY subscriber_id ORDER BY month) as pct_increase, ROW_NUMBER() OVER (ORDER BY pct_increase DESC) as rank FROM mobile_usage GROUP BY subscriber_id HAVING rank <= 3;
gretelai_synthetic_text_to_sql
CREATE TABLE FoodSystems (id INT, name VARCHAR(50), location VARCHAR(50), type VARCHAR(50)); INSERT INTO FoodSystems (id, name, location, type) VALUES (1, 'Andean Root Crops', 'South America', 'Indigenous Food System');
Which indigenous food systems are present in South America?
SELECT * FROM FoodSystems WHERE location = 'South America' AND type = 'Indigenous Food System';
gretelai_synthetic_text_to_sql
CREATE TABLE carbon_prices (date DATE, price FLOAT); INSERT INTO carbon_prices (date, price) VALUES ('2021-01-01', 25), ('2021-01-02', 26), ('2021-01-03', 27), ('2021-02-01', 28), ('2021-02-02', 29), ('2021-02-03', 30), ('2021-03-01', 31), ('2021-03-02', 32), ('2021-03-03', 33);
Find the carbon prices and their moving average for the last 2 months.
SELECT date, price, AVG(price) OVER (ORDER BY date ROWS BETWEEN 27 PRECEDING AND 1 PRECEDING) as moving_avg FROM carbon_prices WHERE date >= '2021-02-01';
gretelai_synthetic_text_to_sql
CREATE TABLE Ship_Incidents (id INT, ship_name VARCHAR(50), incident_type VARCHAR(50), incident_date DATE, location VARCHAR(50)); INSERT INTO Ship_Incidents (id, ship_name, incident_type, incident_date, location) VALUES (1, 'MS Zenith', 'grounding', '2019-03-12', 'Baltic Sea');
Identify ship incidents in the Baltic Sea
SELECT ship_name, incident_type FROM Ship_Incidents WHERE location = 'Baltic Sea';
gretelai_synthetic_text_to_sql
CREATE TABLE if not exists berlin_train_trips (id INT, trip_id INT, fare DECIMAL(5,2), route_id INT, vehicle_id INT, timestamp TIMESTAMP);
What is the average fare for train trips in Berlin?
SELECT AVG(fare) FROM berlin_train_trips WHERE fare IS NOT NULL;
gretelai_synthetic_text_to_sql
CREATE TABLE SafetyRecords (RecordID int, VesselID int, IncidentType varchar(50), IncidentDate datetime); INSERT INTO SafetyRecords (RecordID, VesselID, IncidentType, IncidentDate) VALUES (1000, 3, 'Collision', '2019-12-15'); INSERT INTO SafetyRecords (RecordID, VesselID, IncidentType, IncidentDate) VALUES (1001, 1, 'Oil Spill', '2020-02-01'); INSERT INTO SafetyRecords (RecordID, VesselID, IncidentType, IncidentDate) VALUES (1002, 4, 'Fire', '2020-03-05');
How many incidents has each vessel had, and when was the earliest incident date for each vessel?
SELECT VesselID, VesselName, COUNT(*) as IncidentCount, MIN(IncidentDate) as FirstIncidentDate FROM SafetyRecords sr JOIN Vessels v ON sr.VesselID = v.VesselID GROUP BY VesselID, VesselName;
gretelai_synthetic_text_to_sql
CREATE TABLE fiscal_year (id INT, year INT); INSERT INTO fiscal_year (id, year) VALUES (1, 2017), (2, 2018), (3, 2019), (4, 2020), (5, 2021); CREATE TABLE national_security_operations (id INT, fiscal_year_id INT, budget DECIMAL(10,2)); INSERT INTO national_security_operations (id, fiscal_year_id, budget) VALUES (1, 1, 5000000.00), (2, 2, 5500000.00), (3, 3, 6000000.00), (4, 4, 6500000.00), (5, 5, 7000000.00);
What is the average budget for national security operations in the last 5 years?
SELECT AVG(n.budget) as avg_budget FROM national_security_operations n INNER JOIN fiscal_year f ON n.fiscal_year_id = f.id WHERE f.year BETWEEN 2017 AND 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE exhibition_visits (id INT, visitor_id INT, exhibition_id INT, state TEXT); INSERT INTO exhibition_visits (id, visitor_id, exhibition_id, state) VALUES (1, 1, 1, 'CA'), (2, 2, 1, 'NY');
Calculate the average number of exhibitions visited by visitors from each US state.
SELECT state, AVG(COUNT(DISTINCT exhibition_id)) as avg_exhibitions_visited FROM exhibition_visits WHERE state IS NOT NULL GROUP BY state;
gretelai_synthetic_text_to_sql
CREATE TABLE PlayerSessions (SessionID int, PlayerID int, GameID int, PlatformID int, Playtime int); INSERT INTO PlayerSessions (SessionID, PlayerID, GameID, PlatformID, Playtime) VALUES (1, 1, 1, 1, 60), (2, 1, 1, 1, 90), (3, 2, 1, 2, 75), (4, 2, 2, 2, 120), (5, 3, 2, 3, 100), (6, 3, 3, 1, 80); CREATE TABLE Platforms (PlatformID int, PlatformName varchar(50)); INSERT INTO Platforms (PlatformID, PlatformName) VALUES (1, 'PC'), (2, 'Console'), (3, 'Mobile');
What is the total playtime for each platform?
SELECT P.PlatformName, SUM(PS.Playtime) as TotalPlaytime FROM PlayerSessions PS JOIN Platforms P ON PS.PlatformID = P.PlatformID GROUP BY P.PlatformName;
gretelai_synthetic_text_to_sql
CREATE TABLE Donors (DonorID INT, DonorName TEXT, DonationDate DATE, DonationAmount INT);
What's the total amount donated by each donor in '2022'?
SELECT DonorName, SUM(DonationAmount) FROM Donors WHERE YEAR(DonationDate) = 2022 GROUP BY DonorName;
gretelai_synthetic_text_to_sql
CREATE TABLE customers (id INT, name VARCHAR(255), country VARCHAR(255)); INSERT INTO customers (id, name, country) VALUES (1, 'John Doe', 'USA'), (2, 'Jane Smith', 'Canada'), (3, 'Jim Brown', 'UK'), (4, 'Heidi Klum', 'Germany'); CREATE TABLE accounts (id INT, customer_id INT, balance DECIMAL(10, 2)); INSERT INTO accounts (id, customer_id, balance) VALUES (1, 1, 12000.00), (2, 1, 8000.00), (3, 2, 5000.00), (4, 4, 20000.00);
What is the maximum balance for customers from Germany?
SELECT MAX(a.balance) FROM accounts a JOIN customers c ON a.customer_id = c.id WHERE c.country = 'Germany';
gretelai_synthetic_text_to_sql
CREATE TABLE posts (id INT, user_id INT, content TEXT, created_at TIMESTAMP, language VARCHAR(10)); CREATE TABLE likes (id INT, post_id INT, user_id INT, created_at TIMESTAMP);
Show all posts related to data privacy in Spanish and the number of likes for each.
SELECT posts.content, COUNT(likes.id) AS likes_count FROM posts JOIN likes ON posts.id = likes.post_id WHERE posts.content LIKE '%data privacy%' AND posts.language = 'es' GROUP BY posts.id;
gretelai_synthetic_text_to_sql
CREATE TABLE UnionInfo (UnionID INT, UnionName VARCHAR(50)); INSERT INTO UnionInfo (UnionID, UnionName) VALUES (1001, 'National Labor Union'); INSERT INTO UnionInfo (UnionID, UnionName) VALUES (1002, 'United Steelworkers'); CREATE TABLE CollectiveBargaining (CBAID INT, UnionID INT, AgreementDate DATE); INSERT INTO CollectiveBargaining (CBAID, UnionID, AgreementDate) VALUES (1, 1001, '2020-01-01'); INSERT INTO CollectiveBargaining (CBAID, UnionID, AgreementDate) VALUES (2, 1002, '2019-06-15');
Show all unions and their collective bargaining agreements, if any, along with the date of the latest agreement
SELECT u.UnionID, u.UnionName, ISNULL(MAX(c.AgreementDate), 'No Agreements') as LatestAgreement FROM UnionInfo u LEFT JOIN CollectiveBargaining c ON u.UnionID = c.UnionID GROUP BY u.UnionID, u.UnionName;
gretelai_synthetic_text_to_sql
CREATE TABLE CommunityDevelopment (province VARCHAR(50), year INT, initiative VARCHAR(50), status VARCHAR(50));
How many community development initiatives were completed in each province in 2020?
SELECT province, COUNT(*) FROM CommunityDevelopment WHERE year = 2020 AND status = 'completed' GROUP BY province;
gretelai_synthetic_text_to_sql
CREATE TABLE conservation_initiatives ( id INT PRIMARY KEY, region VARCHAR(255), initiative_name VARCHAR(255), start_date DATE, end_date DATE);
Insert new water conservation initiatives in the 'Mississippi River Basin'
INSERT INTO conservation_initiatives (id, region, initiative_name, start_date, end_date) VALUES (1, 'Mississippi River Basin', 'Smart irrigation systems', DATE_SUB(CURDATE(), INTERVAL 1 MONTH), DATE_ADD(CURDATE(), INTERVAL 2 YEAR));
gretelai_synthetic_text_to_sql
crew_by_vessel
List all crew members for vessel with id 1, ordered by join_date
SELECT * FROM crew_by_vessel WHERE vessel_id = 1 ORDER BY join_date;
gretelai_synthetic_text_to_sql
CREATE TABLE profiles (id INT, user_id INT, country VARCHAR(50));
How many users are from each country in the profiles table?
SELECT country, COUNT(DISTINCT user_id) FROM profiles GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE global_energy (year INT, renewable_energy_consumption FLOAT, total_energy_consumption FLOAT);
What is the percentage of renewable energy consumption for the year 2020 in the world?
SELECT renewable_energy_consumption/total_energy_consumption * 100 AS pct FROM global_energy WHERE year = 2020;
gretelai_synthetic_text_to_sql
CREATE TABLE production (element VARCHAR(10), year INT, quantity FLOAT); INSERT INTO production (element, year, quantity) VALUES ('Erbium', 2015, 550), ('Erbium', 2016, 650), ('Erbium', 2017, 750), ('Erbium', 2018, 850), ('Erbium', 2019, 950), ('Gadolinium', 2015, 250), ('Gadolinium', 2016, 300), ('Gadolinium', 2017, 350), ('Gadolinium', 2018, 400), ('Gadolinium', 2019, 450), ('Holmium', 2015, 100), ('Holmium', 2016, 150), ('Holmium', 2017, 200), ('Holmium', 2018, 250), ('Holmium', 2019, 300);
Which rare earth element had the highest production increase between 2015 and 2018?
SELECT element, MAX(diff) FROM (SELECT element, (quantity - LAG(quantity) OVER (PARTITION BY element ORDER BY year)) AS diff FROM production) AS subquery;
gretelai_synthetic_text_to_sql
CREATE TABLE cargo_tracking (vessel_id VARCHAR(20), departure_port VARCHAR(255), destination_port VARCHAR(255), cargo_weight INT, departure_time TIMESTAMP);
Insert a new record into the "cargo_tracking" table with values "VT-123", "Mumbai", "Delhi", 5000, and "2022-03-22 10:30:00".
INSERT INTO cargo_tracking (vessel_id, departure_port, destination_port, cargo_weight, departure_time) VALUES ('VT-123', 'Mumbai', 'Delhi', 5000, '2022-03-22 10:30:00');
gretelai_synthetic_text_to_sql
CREATE TABLE green_buildings (id INT, building_name VARCHAR(255), city VARCHAR(255), country VARCHAR(255), certification_date DATE);
List the top 5 cities with the most green buildings
SELECT city, COUNT(*) AS num_green_buildings FROM green_buildings GROUP BY city ORDER BY num_green_buildings DESC LIMIT 5;
gretelai_synthetic_text_to_sql
CREATE TABLE legal_aid_providers (id INT, name VARCHAR(50), state VARCHAR(2)); INSERT INTO legal_aid_providers (id, name, state) VALUES (1, 'California Legal Aid', 'CA'), (2, 'Los Angeles Legal Aid', 'CA'), (3, 'San Francisco Legal Aid', 'CA'), (4, 'San Diego Legal Aid', 'CA'), (5, 'Silicon Valley Legal Aid', 'CA'); CREATE TABLE clients (id INT, provider_id INT, year INT);
Who are the top 5 legal aid providers in California by the number of clients served in the last 2 years?
SELECT legal_aid_providers.name, COUNT(clients.id) AS client_count FROM legal_aid_providers INNER JOIN clients ON legal_aid_providers.id = clients.provider_id WHERE clients.year BETWEEN YEAR(CURRENT_DATE()) - 2 AND YEAR(CURRENT_DATE()) GROUP BY legal_aid_providers.name ORDER BY client_count DESC LIMIT 5;
gretelai_synthetic_text_to_sql
CREATE TABLE MonthlySEAVisitors (visitor_id INT, destination VARCHAR(50), country VARCHAR(50), visit_month DATE); INSERT INTO MonthlySEAVisitors (visitor_id, destination, country, visit_month) VALUES (1, 'Eco Park', 'Thailand', '2022-02-01'); INSERT INTO MonthlySEAVisitors (visitor_id, destination, country, visit_month) VALUES (2, 'Green Beach', 'Vietnam', '2022-03-01');
What is the maximum number of visitors to a sustainable destination in a single month in South East Asia?
SELECT MAX(visitor_id) FROM MonthlySEAVisitors WHERE country IN ('South East Asia') GROUP BY visit_month;
gretelai_synthetic_text_to_sql
CREATE TABLE sales_vintage (id INT, garment VARCHAR(255), retail_store VARCHAR(255), sale_date DATE, quantity INT, sales_price DECIMAL(5,2)); INSERT INTO sales_vintage (id, garment, retail_store, sale_date, quantity, sales_price) VALUES (1, 'vintage_t-shirt', 'London Fashion', '2021-03-01', 20, 25.99); INSERT INTO sales_vintage (id, garment, retail_store, sale_date, quantity, sales_price) VALUES (2, 'vintage_jeans', 'Los Angeles Boutique', '2021-04-01', 12, 49.99);
What are the total sales for vintage garments at each retail store?
SELECT retail_store, SUM(quantity * sales_price) as total_sales FROM sales_vintage WHERE garment LIKE '%vintage%' GROUP BY retail_store;
gretelai_synthetic_text_to_sql
CREATE TABLE Inspections (Restaurant VARCHAR(255), Date DATE, Violation INT); INSERT INTO Inspections (Restaurant, Date, Violation) VALUES ('Cafe R', '2022-01-01', 0), ('Cafe R', '2022-02-01', 0), ('Cafe R', '2022-03-01', 0), ('Bistro A', '2022-01-01', 1), ('Bistro A', '2022-02-01', 0), ('Bistro A', '2022-03-01', 1);
List all restaurants that had zero food safety violations in 2022.
SELECT DISTINCT Restaurant FROM Inspections WHERE YEAR(Date) = 2022 AND Violation = 0;
gretelai_synthetic_text_to_sql
CREATE TABLE Crops (id INT PRIMARY KEY, name VARCHAR(50), planting_date DATE, harvest_date DATE, yield INT, farmer_id INT, FOREIGN KEY (farmer_id) REFERENCES Farmers(id)); INSERT INTO Crops (id, name, planting_date, harvest_date, yield, farmer_id) VALUES (1, 'Corn', '2022-05-01', '2022-08-01', 100, 1), (2, 'Soybeans', '2022-06-15', '2022-09-15', 50, 2), (3, 'Rice', '2021-03-01', '2021-06-01', 80, 3), (4, 'Wheat', '2022-04-01', '2022-07-01', 70, 4), (5, 'Oats', '2022-09-15', '2022-11-30', 60, 5);
What is the average yield of crops planted in the Midwest?
SELECT AVG(yield) FROM Crops WHERE region = 'Midwest';
gretelai_synthetic_text_to_sql
CREATE TABLE RenewableResidentialData (City VARCHAR(50), HouseholdID INT, EnergyConsumption FLOAT);
What is the average energy consumption per household in the "RenewableResidentialData" table, partitioned by city?
SELECT City, AVG(EnergyConsumption) OVER (PARTITION BY City) FROM RenewableResidentialData;
gretelai_synthetic_text_to_sql
CREATE TABLE sensors (id INT, city VARCHAR(255), type VARCHAR(255), value FLOAT, timestamp TIMESTAMP); INSERT INTO sensors (id, city, type, value, timestamp) VALUES (1, 'EcoCity', 'Wind Speed', 7.2, '2022-04-01 10:00:00'), (2, 'EcoCity', 'Solar Radiation', 500, '2022-04-01 10:00:00');
What is the average wind speed and solar radiation for each city by month?
SELECT city, type, AVG(value) as avg_value, DATE_FORMAT(timestamp, '%%Y-%%m') as month FROM sensors GROUP BY city, type, month;
gretelai_synthetic_text_to_sql
CREATE TABLE AutonomousTests (Id INT, Manufacturer VARCHAR(100), TestDate DATE, Distance FLOAT); INSERT INTO AutonomousTests (Id, Manufacturer, TestDate, Distance) VALUES (1, 'Tesla', '2021-01-01', 150.0); INSERT INTO AutonomousTests (Id, Manufacturer, TestDate, Distance) VALUES (2, 'Waymo', '2021-02-01', 170.0); INSERT INTO AutonomousTests (Id, Manufacturer, TestDate, Distance) VALUES (3, 'NVIDIA', '2021-03-01', 120.0); INSERT INTO AutonomousTests (Id, Manufacturer, TestDate, Distance) VALUES (4, 'Cruise', '2021-04-01', 180.0);
What is the percentage of autonomous driving test distance driven by each manufacturer in the USA in 2021?
SELECT Manufacturer, (SUM(Distance) * 100.0 / (SELECT SUM(Distance) FROM AutonomousTests WHERE Country = 'USA' AND EXTRACT(YEAR FROM TestDate) = 2021)) AS Percentage FROM AutonomousTests WHERE Country = 'USA' AND EXTRACT(YEAR FROM TestDate) = 2021 GROUP BY Manufacturer;
gretelai_synthetic_text_to_sql
CREATE TABLE marine_protected_areas (name TEXT, location TEXT, depth FLOAT); INSERT INTO marine_protected_areas (name, location, depth) VALUES ('Galapagos Marine Reserve', 'Pacific', 2400.0), ('Monterey Bay National Marine Sanctuary', 'Pacific', 30.0), ('Great Barrier Reef', 'Pacific', 344.0);
What is the maximum and minimum depth of marine protected areas in the Pacific Ocean?
SELECT MAX(depth) AS max_depth, MIN(depth) AS min_depth FROM marine_protected_areas WHERE location = 'Pacific';
gretelai_synthetic_text_to_sql
CREATE TABLE museums (id INT, city VARCHAR(20), art_pieces INT); INSERT INTO museums (id, city, art_pieces) VALUES (1, 'Paris', 5000), (2, 'Madrid', 7000), (3, 'Barcelona', 8000), (4, 'Paris', 6000), (5, 'Madrid', 8000), (6, 'Barcelona', 9000);
What is the total number of art pieces in 'Paris', 'Madrid', and 'Barcelona'?
SELECT city, SUM(art_pieces) FROM museums GROUP BY city HAVING city IN ('Paris', 'Madrid', 'Barcelona');
gretelai_synthetic_text_to_sql
CREATE TABLE menus (menu_id INT, menu_name VARCHAR(255), price DECIMAL(5,2), city VARCHAR(255)); INSERT INTO menus (menu_id, menu_name, price, city) VALUES (1, 'Veggie Burger', 8.99, 'New York'); INSERT INTO menus (menu_id, menu_name, price, city) VALUES (2, 'Veggie Wrap', 7.49, 'New York');
What is the average price of vegetarian menu items sold in New York?
SELECT AVG(price) FROM menus WHERE menu_name LIKE '%vegetarian%' AND city = 'New York';
gretelai_synthetic_text_to_sql
CREATE TABLE movies (title VARCHAR(255), rating INT, genre VARCHAR(50)); INSERT INTO movies (title, rating, genre) VALUES ('Movie1', 8, 'Action'), ('Movie2', 7, 'Drama'), ('Movie3', 9, 'Comedy'), ('Movie4', 6, 'Action'), ('Movie5', 8, 'Drama'), ('Movie6', 7, 'Comedy');
Which genre has the highest average movie rating?
SELECT genre, AVG(rating) as avg_rating FROM movies GROUP BY genre ORDER BY avg_rating DESC LIMIT 1;
gretelai_synthetic_text_to_sql
CREATE TABLE vulnerabilities (id INT, severity INT, country VARCHAR(255), vulnerability_date DATE); INSERT INTO vulnerabilities (id, severity, country, vulnerability_date) VALUES (1, 9, 'EU', '2022-02-01'), (2, 7, 'EU', '2022-02-02'), (3, 8, 'EU', '2022-02-03');
Which vulnerabilities had the highest severity in the European Union in the past week?
SELECT severity, COUNT(*) AS high_severity_count FROM vulnerabilities WHERE country = 'EU' AND vulnerability_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 WEEK) AND severity >= 7 GROUP BY severity ORDER BY high_severity_count DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE MentalHealth (StudentID int, Date date, MentalHealthScore int);
Update the 'MentalHealthScore' field for a mental health record in the 'MentalHealth' table
UPDATE MentalHealth SET MentalHealthScore = 80 WHERE StudentID = 1234 AND Date = '2022-09-01';
gretelai_synthetic_text_to_sql
CREATE TABLE global_tourism (destination VARCHAR(255), continent VARCHAR(255), visitors INT); INSERT INTO global_tourism (destination, continent, visitors) VALUES ('Rio de Janeiro', 'South America', 1000000); INSERT INTO global_tourism (destination, continent, visitors) VALUES ('Sydney', 'Australia', 2000000);
What is the average number of international visitors for each continent, and the total number of visitors worldwide?
SELECT continent, AVG(visitors) as avg_visitors_per_continent, SUM(visitors) as total_visitors_worldwide FROM global_tourism GROUP BY continent;
gretelai_synthetic_text_to_sql
CREATE TABLE vn_fr_parcels (id INT, shipped_date DATE); INSERT INTO vn_fr_parcels (id, shipped_date) VALUES (1, '2022-01-10'), (2, '2022-06-01');
How many parcels were shipped from Vietnam to France in the first half of the year?
SELECT COUNT(*) FROM vn_fr_parcels WHERE MONTH(shipped_date) <= 6 AND MONTH(shipped_date) > 0;
gretelai_synthetic_text_to_sql
CREATE TABLE recycling_rates (region VARCHAR(50), year INT, recycling_rate FLOAT); INSERT INTO recycling_rates (region, year, recycling_rate) VALUES ('Sydney', 2020, 67.89);
What was the recycling rate in percentage for the region 'Sydney' in 2020?
SELECT recycling_rate FROM recycling_rates WHERE region = 'Sydney' AND year = 2020;
gretelai_synthetic_text_to_sql
CREATE TABLE Shipment (id INT, weight INT); INSERT INTO Shipment (id, weight) VALUES (101, 10000), (102, 15000), (103, 8000);
What is the total weight of all shipments?
SELECT SUM(weight) FROM Shipment;
gretelai_synthetic_text_to_sql
CREATE TABLE impact_assessment (id INT PRIMARY KEY, company_id INT, assessment_date DATE, social_impact_score INT, environmental_impact_score INT); INSERT INTO impact_assessment (id, company_id, assessment_date, social_impact_score, environmental_impact_score) VALUES (1, 1, '2019-12-31', 85, 90); INSERT INTO impact_assessment (id, company_id, assessment_date, social_impact_score, environmental_impact_score) VALUES (2, 2, '2020-01-05', 75, 80); INSERT INTO impact_assessment (id, company_id, assessment_date, social_impact_score, environmental_impact_score) VALUES (3, 3, '2021-03-01', 90, 88); INSERT INTO company (id, name, industry, location, esg_score) VALUES (1, 'EcoPower', 'Renewable Energy', 'Brazil', 82); INSERT INTO company (id, name, industry, location, esg_score) VALUES (2, 'GreenTech', 'Renewable Energy', 'Argentina', 87); INSERT INTO company (id, name, industry, location, esg_score) VALUES (3, 'SolarCo', 'Renewable Energy', 'Chile', 90);
What is the average environmental impact score for companies in the 'Latin America' region?
SELECT AVG(ia.environmental_impact_score) AS avg_env_score FROM impact_assessment AS ia JOIN company AS c ON ia.company_id = c.id WHERE c.location LIKE 'Lat%';
gretelai_synthetic_text_to_sql
CREATE TABLE city_infrastructure (project_id INT, project_name VARCHAR(50), project_status VARCHAR(20));
Update the 'city_infrastructure' table to change the status of the project with ID 15 to 'Completed'
UPDATE city_infrastructure SET project_status = 'Completed' WHERE project_id = 15;
gretelai_synthetic_text_to_sql
CREATE TABLE humanitarian_assistance (donor VARCHAR(255), recipient VARCHAR(255), amount DECIMAL(10, 2)); INSERT INTO humanitarian_assistance (donor, recipient, amount) VALUES ('USA', 'Syria', 1000000), ('China', 'Pakistan', 500000), ('USA', 'Iraq', 800000), ('China', 'Afghanistan', 700000);
Identify the humanitarian assistance provided by the US and China
SELECT donor, recipient, amount FROM humanitarian_assistance WHERE donor IN ('USA', 'China');
gretelai_synthetic_text_to_sql
CREATE TABLE smart_contracts (contract_id INT, contract_address VARCHAR(50), network VARCHAR(20)); INSERT INTO smart_contracts (contract_id, contract_address, network) VALUES (1, '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D', 'Binance Smart Chain'); CREATE TABLE contract_transactions (transaction_id INT, contract_id INT, block_number INT);
List the top 3 smart contracts with the most transactions on the 'Binance Smart Chain'?
SELECT s.contract_address, COUNT(c.transaction_id) as transaction_count FROM smart_contracts s JOIN contract_transactions c ON s.contract_id = c.contract_id WHERE s.network = 'Binance Smart Chain' GROUP BY s.contract_address ORDER BY transaction_count DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE CommunityHealthWorkers (ID INT, State VARCHAR(20), Gender VARCHAR(10)); CREATE TABLE MentalHealthParity (ID INT, State VARCHAR(20), Complaint INT); INSERT INTO CommunityHealthWorkers (ID, State, Gender) VALUES (1, 'California', 'Male'), (2, 'California', 'Female'), (3, 'Texas', 'Male'); INSERT INTO MentalHealthParity (ID, State, Complaint) VALUES (1, 'California', 120), (2, 'Texas', 150);
What was the total number of community health workers and mental health parity complaints for each state?
SELECT State, COUNT(DISTINCT CommunityHealthWorker) as HealthWorkers, SUM(Complaint) as TotalComplaints FROM CommunityHealthWorkers JOIN MentalHealthParity ON CommunityHealthWorkers.State = MentalHealthParity.State GROUP BY State;
gretelai_synthetic_text_to_sql
CREATE TABLE programs (id INT, name TEXT, start_date DATE, end_date DATE); CREATE TABLE expenses (id INT, program_id INT, amount DECIMAL(10,2), expense_date DATE); INSERT INTO programs (id, name, start_date, end_date) VALUES (1, 'Education Program', '2021-07-01', '2021-12-31'), (2, 'Medical Outreach Program', '2021-04-15', '2021-11-30'), (3, 'Food Security Program', '2021-07-01', '2021-12-31'); INSERT INTO expenses (id, program_id, amount, expense_date) VALUES (1, 1, 1500.00, '2021-07-15'), (2, 1, 800.00, '2021-10-20'), (3, 2, 3000.00, '2021-07-01'), (4, 2, 1500.00, '2021-10-15'), (5, 3, 5000.00, '2021-08-01');
List all programs and their respective total expenses for Q3 2021, sorted by total expenses in descending order.
SELECT programs.name, SUM(expenses.amount) as total_expenses FROM programs INNER JOIN expenses ON programs.id = expenses.program_id WHERE expenses.expense_date BETWEEN '2021-07-01' AND '2021-09-30' GROUP BY programs.id ORDER BY total_expenses DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE DonorCountry (DonorID int, Country varchar(255)); INSERT INTO DonorCountry VALUES (1,'USA'); INSERT INTO DonorCountry VALUES (2,'Canada'); CREATE TABLE Donations (DonationID int, DonorID int, Amount float, DonationDate date); INSERT INTO Donations VALUES (1,1,5000000,'2022-01-01'); INSERT INTO Donations VALUES (2,2,7000000,'2021-12-31');
Identify the number of unique donors and total donation amount per country in the past year.
SELECT d.Country, COUNT(DISTINCT d.DonorID) as UniqueDonors, SUM(d.Amount) as TotalDonations FROM Donations d INNER JOIN DonorCountry dc ON d.DonorID = dc.DonorID WHERE d.DonationDate >= DATEADD(year, -1, GETDATE()) GROUP BY d.Country;
gretelai_synthetic_text_to_sql
CREATE TABLE Cities (City varchar(20), Inclusive varchar(5)); CREATE TABLE Properties (PropertyID int, City varchar(20)); INSERT INTO Cities (City, Inclusive) VALUES ('Seattle', 'Yes'); INSERT INTO Properties (PropertyID, City) VALUES (1, 'Seattle'); INSERT INTO Properties (PropertyID, City) VALUES (2, 'Portland');
What is the total number of properties in each city with inclusive housing policies?
SELECT Properties.City, COUNT(Properties.PropertyID) FROM Properties INNER JOIN Cities ON Properties.City = Cities.City WHERE Cities.Inclusive = 'Yes' GROUP BY Properties.City;
gretelai_synthetic_text_to_sql
CREATE TABLE subscribers (subscriber_id INT, service_type VARCHAR(50), data_usage FLOAT); CREATE TABLE services (service_type VARCHAR(50), description VARCHAR(50));
What is the average 'data_usage' in GB for each 'service_type' in the 'services' table, ordered by average 'data_usage' in descending order?
SELECT s.service_type, AVG(sub.data_usage) OVER (PARTITION BY s.service_type) AS avg_data_usage_gb FROM services s JOIN subscribers sub ON s.service_type = sub.service_type ORDER BY avg_data_usage_gb DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE media_literacy (id INT, user_id INT, ethnicity VARCHAR, score INT); INSERT INTO media_literacy (id, user_id, ethnicity, score) VALUES (1, 1, 'Latinx', 80); INSERT INTO media_literacy (id, user_id, ethnicity, score) VALUES (2, 2, 'Arab', 70);
What is the distribution of media literacy scores for Latinx users compared to Arab users?
SELECT ethnicity, AVG(score) as avg_score FROM media_literacy WHERE ethnicity IN ('Latinx', 'Arab') GROUP BY ethnicity;
gretelai_synthetic_text_to_sql
CREATE TABLE visitor_workshops (visitor_id INT, country VARCHAR(50), workshop_name VARCHAR(50)); INSERT INTO visitor_workshops (visitor_id, country, workshop_name) VALUES (1, 'United States', 'Painting'), (2, 'Canada', 'Sculpture'), (3, 'Mexico', 'Digital Art');
How many visitors from each country engaged with the digital museum's online workshops?
SELECT country, COUNT(*) as num_visitors FROM visitor_workshops GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE clothing (id INT, category VARCHAR(50), subcategory VARCHAR(50), price DECIMAL(5,2)); INSERT INTO clothing (id, category, subcategory, price) VALUES (1, 'Clothing', 'Tops', 25.99), (2, 'Clothing', 'Tops', 35.99), (3, 'Clothing', 'Tops', 15.99), (4, 'Clothing', 'Bottoms', 49.99), (5, 'Clothing', 'Bottoms', 39.99), (6, 'Clothing', 'Bottoms', 59.99);
Find the maximum price for tops
SELECT MAX(price) FROM clothing WHERE subcategory = 'Tops';
gretelai_synthetic_text_to_sql
CREATE TABLE humanitarian_assistance (donor VARCHAR(255), recipient VARCHAR(255), amount DECIMAL(10, 2), year INT); INSERT INTO humanitarian_assistance (donor, recipient, amount, year) VALUES ('USA', 'Syria', 1000000, 2020), ('China', 'Pakistan', 500000, 2020), ('USA', 'Iraq', 800000, 2020), ('China', 'Afghanistan', 700000, 2020);
Calculate the total humanitarian assistance provided by the US and China in 2020
SELECT donor, SUM(amount) as total_assistance FROM humanitarian_assistance WHERE donor IN ('USA', 'China') AND year = 2020 GROUP BY donor;
gretelai_synthetic_text_to_sql
CREATE TABLE states (state_name VARCHAR(255), budget INT); INSERT INTO states (state_name, budget) VALUES ('California', 3000000), ('Texas', 2500000), ('New York', 2000000); CREATE TABLE services (service_name VARCHAR(255), state_name VARCHAR(255), budget INT); INSERT INTO services (service_name, state_name, budget) VALUES ('education', 'California', 1500000), ('education', 'Texas', 1000000), ('education', 'New York', 500000), ('public transportation', 'California', 750000), ('public transportation', 'Texas', 600000), ('public transportation', 'New York', 400000);
Identify the top 2 states with the highest budget allocation for education and public transportation?
SELECT state_name, budget FROM (SELECT state_name, SUM(budget) AS budget FROM services WHERE service_name IN ('education', 'public transportation') GROUP BY state_name ORDER BY budget DESC) AS subquery LIMIT 2;
gretelai_synthetic_text_to_sql
CREATE TABLE co2_emissions (country VARCHAR(50), year INT, co2_emissions_mt INT, renewable_energy_production_twh FLOAT); INSERT INTO co2_emissions (country, year, co2_emissions_mt, renewable_energy_production_twh) VALUES ('Germany', 2019, 750, 230), ('Germany', 2020, 700, 245), ('Germany', 2021, 650, 260);
What is the CO2 emissions reduction in percentage achieved by renewable energy sources in Germany in 2020?
SELECT ((co2_emissions_mt * 100 / 750) - 100) FROM co2_emissions WHERE country = 'Germany' AND year = 2020;
gretelai_synthetic_text_to_sql
CREATE TABLE museum_donations (donation_id INT, donation_amount FLOAT, donation_date DATE); INSERT INTO museum_donations (donation_id, donation_amount, donation_date) VALUES (1, 250.00, '2021-06-01'), (2, 300.00, '2021-06-15'), (3, 150.00, '2021-07-01');
How many total donations were made in the month of June in the "museum_donations" table?
SELECT SUM(donation_amount) FROM museum_donations WHERE EXTRACT(MONTH FROM donation_date) = 6;
gretelai_synthetic_text_to_sql
CREATE TABLE Farm ( FarmID INT, FarmName VARCHAR(255) ); CREATE TABLE FishSpecies ( SpeciesID INT, SpeciesName VARCHAR(255), MaxDensity DECIMAL(10,2) ); CREATE TABLE Stock ( StockID INT, FarmID INT, SpeciesID INT, StockDensity DECIMAL(10,2), StockDate DATE ); INSERT INTO Farm (FarmID, FarmName) VALUES (1, 'Farm A'), (2, 'Farm B'), (3, 'Farm C'); INSERT INTO FishSpecies (SpeciesID, SpeciesName, MaxDensity) VALUES (1, 'Tilapia', 3.5), (2, 'Salmon', 2.7), (3, 'Catfish', 4.2); INSERT INTO Stock (StockID, FarmID, SpeciesID, StockDensity, StockDate) VALUES (1, 1, 1, 1.5, '2022-01-01'), (2, 1, 2, 2.3, '2022-01-02'), (3, 2, 1, 3.0, '2022-01-03'), (4, 2, 3, 4.0, '2022-01-04'), (5, 3, 1, 3.3, '2022-01-05');
What is the maximum sustainable stocking density for each fish species in the different farms?
SELECT f.FarmName, fs.SpeciesName, MAX(StockDensity) OVER (PARTITION BY f.FarmName, fs.SpeciesID) as MaxSustainableDensity FROM Stock JOIN Farm f ON Stock.FarmID = f.FarmID JOIN FishSpecies fs ON Stock.SpeciesID = fs.SpeciesID WHERE StockDensity <= MaxDensity;
gretelai_synthetic_text_to_sql
CREATE TABLE biotech_startups(id INT, name TEXT, location TEXT, industry TEXT, funding FLOAT, research TEXT); INSERT INTO biotech_startups VALUES(1, 'Caligenix', 'California', 'Biotechnology', 8000000, 'Genetic Research'); INSERT INTO biotech_startups VALUES(2, 'BioCal', 'California', 'Biotechnology', 10000000, 'Protein Synthesis');
What is the total funding received by biotech startups in California that have conducted genetic research in the last 2 years?
SELECT SUM(funding) FROM biotech_startups WHERE industry = 'Biotechnology' AND location = 'California' AND research IS NOT NULL AND research <> '' AND research LIKE '%Genetic%' AND research LIKE '%Last 2 Years%';
gretelai_synthetic_text_to_sql
CREATE TABLE students (student_id INT, dept_id INT, graduated BOOLEAN, num_publications INT);CREATE TABLE departments (dept_id INT, dept_name VARCHAR(255));
Calculate the percentage of graduate students per department who have published at least one paper, in descending order of percentage.
SELECT dept_name, COUNT(*) * 100.0 / (SELECT COUNT(*) FROM students s WHERE s.dept_id = f.dept_id) AS percentage FROM students f WHERE num_publications > 0 GROUP BY dept_name ORDER BY percentage DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE mobile_subscribers (subscriber_id INT, home_location VARCHAR(50), monthly_data_usage DECIMAL(10,2)); INSERT INTO mobile_subscribers (subscriber_id, home_location, monthly_data_usage) VALUES (1, 'USA', 3.5), (2, 'Mexico', 4.2), (3, 'Canada', 2.8), (4, 'USA', 4.5), (5, 'Canada', 3.2); CREATE TABLE country_averages (home_location VARCHAR(50), average_data_usage DECIMAL(10,2)); INSERT INTO country_averages (home_location, average_data_usage) SELECT home_location, AVG(monthly_data_usage) FROM mobile_subscribers GROUP BY home_location;
Which mobile subscribers have a higher data usage than the average in their country?
SELECT ms.subscriber_id, ms.home_location, ms.monthly_data_usage FROM mobile_subscribers ms INNER JOIN country_averages ca ON ms.home_location = ca.home_location WHERE ms.monthly_data_usage > ca.average_data_usage;
gretelai_synthetic_text_to_sql
CREATE TABLE military_equipment (id INT, country TEXT, equipment_type TEXT, quantity INT); INSERT INTO military_equipment (id, country, equipment_type, quantity) VALUES (1, 'USA', 'Tanks', 3000), (2, 'China', 'Tanks', 4000), (3, 'USA', 'Aircraft', 5000), (4, 'China', 'Aircraft', 6000);
List the types of military equipment used by the US and China, and the quantity of each type.
SELECT m.country, m.equipment_type, m.quantity FROM military_equipment m WHERE m.country IN ('USA', 'China') GROUP BY m.equipment_type;
gretelai_synthetic_text_to_sql
CREATE TABLE threat_intelligence (id INT, source TEXT, severity TEXT, reported_date DATE); INSERT INTO threat_intelligence (id, source, severity, reported_date) VALUES (1, 'FSB', 'low', '2021-02-01'); INSERT INTO threat_intelligence (id, source, severity, reported_date) VALUES (2, 'MI5', 'medium', '2021-03-10'); INSERT INTO threat_intelligence (id, source, severity, reported_date) VALUES (3, 'AIS', 'high', '2021-04-15');
Which threat intelligence sources reported the lowest severity threats in the last month?
SELECT source, severity FROM threat_intelligence WHERE reported_date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH) AND severity = (SELECT MIN(severity) FROM threat_intelligence WHERE reported_date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH));
gretelai_synthetic_text_to_sql
CREATE TABLE accounts (customer_id INT, account_type VARCHAR(20), transaction_date DATE);
Determine the number of days between each customer's first and last transaction, partitioned by account type.
SELECT customer_id, account_type, DATEDIFF(MAX(transaction_date), MIN(transaction_date)) OVER (PARTITION BY customer_id, account_type) AS days_between_first_last FROM accounts;
gretelai_synthetic_text_to_sql
CREATE TABLE RuralHealthFacility7 (id INT, name TEXT, treatment_time INT); INSERT INTO RuralHealthFacility7 (id, name, treatment_time) VALUES (1, 'Grace Yellow', 60), (2, 'Harry Blue', 75);
What is the maximum treatment time for patients in 'RuralHealthFacility7'?
SELECT MAX(treatment_time) FROM RuralHealthFacility7;
gretelai_synthetic_text_to_sql
CREATE TABLE climate_finance (country VARCHAR(50), year INT, investment FLOAT); INSERT INTO climate_finance (country, year, investment) VALUES ('Kenya', 2016, 1000000), ('Nigeria', 2017, 1500000);
What is the maximum investment in climate finance for each country in Africa, and which year did it occur?
SELECT country, MAX(investment) as max_investment, year FROM climate_finance WHERE country IN ('Kenya', 'Nigeria') GROUP BY country, year ORDER BY max_investment DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE policies(id INT, policy_name VARCHAR(50), policy_type VARCHAR(50), policy_date DATE);CREATE TABLE policy_dates(policy_id INT, start_date DATE, end_date DATE);
How many clean energy policies were implemented in each year in the policies and policy_dates tables?
SELECT YEAR(p.policy_date) AS policy_year, COUNT(*) AS num_policies FROM policies p INNER JOIN policy_dates pd ON p.id = pd.policy_id GROUP BY policy_year;
gretelai_synthetic_text_to_sql
CREATE TABLE sales_2022 AS SELECT * FROM sales WHERE sale_date BETWEEN '2022-01-01' AND '2022-12-31'; ALTER TABLE sales_2022 ADD COLUMN sale_country VARCHAR(50); UPDATE sales_2022 SET sale_country = CASE WHEN sale_channel = 'Online' THEN 'Online' ELSE sale_city END; ALTER TABLE sales_2022 ADD COLUMN product_category VARCHAR(50); UPDATE sales_2022 SET product_category = CASE WHEN product_id = 1 THEN 'Tops' WHEN product_id = 2 THEN 'Bottoms' WHEN product_id = 3 THEN 'Outerwear' WHEN product_id = 4 THEN 'Accessories' END;
What was the total sales amount for each product category by country in 2022, excluding online sales?
SELECT sale_country, product_category, SUM(sale_amount) FROM sales_2022 WHERE sale_country != 'Online' GROUP BY sale_country, product_category;
gretelai_synthetic_text_to_sql
CREATE TABLE artists (id INT PRIMARY KEY, name TEXT); CREATE TABLE songs (id INT PRIMARY KEY, title TEXT, year INT, artist_id INT, genre TEXT, streams INT); INSERT INTO artists (id, name) VALUES (1, 'BTS'), (2, 'Blackpink'), (3, 'TWICE'), (4, 'Taylor Swift'), (5, 'Ariana Grande'); INSERT INTO songs (id, title, year, artist_id, genre, streams) VALUES (1, 'Dynamite', 2020, 1, 'Pop', 800000000), (2, 'How You Like That', 2020, 2, 'Hip-Hop', 500000000), (3, 'Love Shot', 2018, 3, 'Pop', 400000000), (4, 'Tum Hi Ho', 2013, 4, 'Bollywood', 200000000), (5, 'Dil Se Re', 1998, 5, 'Bollywood', 100000000), (6, 'ME!', 2019, 4, 'Pop', 700000000), (7, '7 Rings', 2019, 5, 'Pop', 600000000);
Display the names of all artists who had a higher number of streams than their average in 2019.
SELECT a.name FROM artists a JOIN (SELECT artist_id, AVG(streams) as avg_streams FROM songs WHERE year = 2019 GROUP BY artist_id) b ON a.id = b.artist_id WHERE b.avg_streams < (SELECT streams FROM songs s WHERE s.artist_id = b.artist_id AND s.year = 2019 ORDER BY streams DESC LIMIT 1);
gretelai_synthetic_text_to_sql
CREATE TABLE companies_esg_3 (id INT, sector VARCHAR(20), ESG_score FLOAT); INSERT INTO companies_esg_3 (id, sector, ESG_score) VALUES (1, 'healthcare', 72.5), (2, 'pharmaceutical', 80.2), (3, 'healthcare', 76.1);
What's the minimum ESG score for companies in the 'healthcare' or 'pharmaceutical' sectors?
SELECT MIN(ESG_score) FROM companies_esg_3 WHERE sector IN ('healthcare', 'pharmaceutical');
gretelai_synthetic_text_to_sql
CREATE TABLE animal_populations (id INT, species VARCHAR(50), population INT); INSERT INTO animal_populations (id, species, population) VALUES (1, 'Giraffe', 1500), (2, 'Elephant', 2000), (3, 'Lion', 300), (4, 'Rhinoceros', 800), (5, 'Hippopotamus', 1200);
Show animal species and their population sizes
SELECT species, population FROM animal_populations;
gretelai_synthetic_text_to_sql
CREATE TABLE ethical_ai_research (id INT, publication_year INT, is_ethical BOOLEAN);
What is the distribution of ethical AI research papers by publication year?
SELECT publication_year, COUNT(*) as num_publications FROM ethical_ai_research WHERE is_ethical = TRUE GROUP BY publication_year;
gretelai_synthetic_text_to_sql
CREATE TABLE region_water_consumption (region VARCHAR(50), date DATE, consumption FLOAT); INSERT INTO region_water_consumption (region, date, consumption) VALUES ('Mumbai', '2020-07-01', 1500), ('Mumbai', '2020-07-02', 1600), ('Mumbai', '2020-07-03', 1400), ('Delhi', '2020-07-01', 1800), ('Delhi', '2020-07-02', 1900), ('Delhi', '2020-07-03', 2000);
Identify the top 2 regions with the highest average water consumption for the month of July 2020
SELECT region, AVG(consumption) AS avg_consumption FROM region_water_consumption WHERE date BETWEEN '2020-07-01' AND '2020-07-31' GROUP BY region ORDER BY avg_consumption DESC LIMIT 2;
gretelai_synthetic_text_to_sql
CREATE TABLE rural_projects (country TEXT, year INT, completion_rate NUMERIC); INSERT INTO rural_projects (country, year, completion_rate) VALUES ('Colombia', 2017, 0.85), ('Colombia', 2017, 0.95), ('Colombia', 2018, 0.88), ('Colombia', 2018, 0.92), ('Colombia', 2019, 0.9), ('Colombia', 2019, 0.97), ('Colombia', 2020, 0.85), ('Colombia', 2020, 0.96), ('Colombia', 2021, 0.93), ('Colombia', 2021, 0.98);
How many rural infrastructure projects were completed in Colombia each year, with at least 90% on-time completion rate?
SELECT year, COUNT(*) FROM rural_projects WHERE country = 'Colombia' AND completion_rate >= 0.9 GROUP BY year;
gretelai_synthetic_text_to_sql
CREATE TABLE food_safety_inspections(restaurant_name VARCHAR(255), violation_count INT, restaurant_segment VARCHAR(255)); INSERT INTO food_safety_inspections(restaurant_name, violation_count, restaurant_segment) VALUES('Casual Diner 1', 2, 'Casual Dining'), ('Casual Diner 2', 0, 'Casual Dining'), ('Casual Diner 3', 1, 'Casual Dining');
How many food safety violations occurred in each restaurant in the Casual Dining segment?
SELECT restaurant_segment, restaurant_name, SUM(violation_count) FROM food_safety_inspections GROUP BY restaurant_segment, restaurant_name;
gretelai_synthetic_text_to_sql
CREATE TABLE autonomous_vehicles_by_type (id INT PRIMARY KEY, city VARCHAR(255), type VARCHAR(255), num_vehicles INT);
Find the number of autonomous vehicles in each city, for taxis and shuttles
CREATE VIEW autonomous_vehicles_by_type_city AS SELECT city, type, COUNT(*) as num_vehicles FROM autonomous_vehicles WHERE make = 'Wayve' GROUP BY city, type; SELECT * FROM autonomous_vehicles_by_type_city WHERE type IN ('Taxi', 'Shuttle');
gretelai_synthetic_text_to_sql
CREATE TABLE carbon_sequestration (id INT, forest_name VARCHAR(255), biome VARCHAR(255), rate_tons_per_hectare_per_year FLOAT);
What is the average carbon sequestration rate, in metric tons per hectare per year, for all forests in the temperate biome?
SELECT AVG(rate_tons_per_hectare_per_year) FROM carbon_sequestration WHERE biome = 'temperate';
gretelai_synthetic_text_to_sql
CREATE TABLE ParityViolations (ViolationID int, RegionID int, ViolationCount int);CREATE TABLE RegionMentalHealth (RegionID int, PatientID int);
What is the total number of mental health parity violations and the number of patients treated for mental health issues in each region?
SELECT RegionID, SUM(ViolationCount) as TotalViolations, COUNT(PatientID) as PatientCount FROM ParityViolations JOIN RegionMentalHealth ON ParityViolations.RegionID = RegionMentalHealth.RegionID GROUP BY RegionID;
gretelai_synthetic_text_to_sql
CREATE TABLE medical_professionals (id INT, name VARCHAR(50), specialty VARCHAR(50), location VARCHAR(20)); INSERT INTO medical_professionals (id, name, specialty, location) VALUES (1, 'Dr. Smith', 'mental health', 'rural'), (2, 'Dr. Johnson', 'cardiology', 'urban'), (3, 'Dr. Brown', 'mental health', 'rural');
What is the total number of medical professionals in rural areas who specialize in mental health?
SELECT COUNT(*) FROM medical_professionals WHERE specialty = 'mental health' AND location = 'rural';
gretelai_synthetic_text_to_sql