context
stringlengths
11
9.12k
question
stringlengths
0
1.06k
SQL
stringlengths
2
4.44k
source
stringclasses
28 values
CREATE TABLE album (id INT PRIMARY KEY, title VARCHAR(255), year INT, revenue INT); INSERT INTO album (id, title, year, revenue) VALUES (1, 'AlbumA', 2000, 5000000), (2, 'AlbumB', 2000, 7000000), (3, 'AlbumC', 2001, 6000000);
What's the total revenue of music albums released in 2000?
SELECT SUM(revenue) FROM album WHERE year = 2000;
gretelai_synthetic_text_to_sql
CREATE TABLE containers (id INT, name TEXT, width INT, height INT, length INT); INSERT INTO containers (id, name, width, height, length) VALUES (1, 'Container 1', 10, 20, 30); INSERT INTO containers (id, name, width, height, length) VALUES (2, 'Container 2', 8, 15, 25); INSERT INTO containers (id, name, width, height, length) VALUES (3, 'Container 3', 12, 18, 22);
Delete all records of containers with invalid measurements.
DELETE FROM containers WHERE width < 8 OR height < 8 OR length < 8;
gretelai_synthetic_text_to_sql
CREATE TABLE articles (id INT, title VARCHAR(100), word_count INT, publication_date DATE, category VARCHAR(50));
What is the average word count of articles published in the "articles" table in 2021?
SELECT AVG(word_count) FROM articles WHERE YEAR(publication_date) = 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE wells (well_id INT, field VARCHAR(50), region VARCHAR(50), drill_year INT, production_oil FLOAT, production_gas FLOAT); INSERT INTO wells (well_id, field, region, drill_year, production_oil, production_gas) VALUES (1, 'Vankor', 'Siberia', 2018, 18000.0, 6000.0), (2, 'Severo-Kurilsk', 'Siberia', 2019, 12000.0, 4000.0);
How many wells were drilled in 'Siberia' between 2017 and 2020?
SELECT COUNT(*) FROM wells WHERE region = 'Siberia' AND drill_year BETWEEN 2017 AND 2020;
gretelai_synthetic_text_to_sql
CREATE TABLE italy_heritage_sites (site_id INT, name TEXT, location TEXT, country TEXT, annual_revenue INT); INSERT INTO italy_heritage_sites (site_id, name, location, country, annual_revenue) VALUES (1, 'Colosseum', 'Rome', 'Italy', 4000000);
Which cultural heritage sites in Rome have annual revenues over 3 million?
SELECT name, annual_revenue FROM italy_heritage_sites WHERE location = 'Rome' AND annual_revenue > 3000000;
gretelai_synthetic_text_to_sql
CREATE TABLE donors (id INT, name TEXT, country TEXT); INSERT INTO donors (id, name, country) VALUES (1, 'John Doe', 'USA'), (2, 'Jane Smith', 'Canada'); CREATE TABLE donations (id INT, donor_id INT, amount DECIMAL(10,2)); INSERT INTO donations (id, donor_id, amount) VALUES (1, 1, 500.00), (2, 1, 250.00), (3, 2, 100.00);
What is the total donation amount by each donor in the US?
SELECT d.name, SUM(donations.amount) as total_donation FROM donors d INNER JOIN donations ON d.id = donations.donor_id WHERE d.country = 'USA' GROUP BY d.name;
gretelai_synthetic_text_to_sql
CREATE TABLE users (id INT, country VARCHAR(255)); INSERT INTO users (id, country) VALUES (1, 'India'), (2, 'Pakistan'); CREATE TABLE posts (id INT, user_id INT, post_date DATE); INSERT INTO posts (id, user_id, post_date) VALUES (1, 1, '2022-01-01'), (2, 1, '2022-01-02'), (3, 2, '2022-01-01');
What is the average number of posts per day for users from India?
SELECT AVG(posts_per_day) FROM (SELECT user_id, COUNT(*) AS posts_per_day FROM posts WHERE post_date BETWEEN '2022-01-01' AND LAST_DAY('2022-01-01') GROUP BY user_id) AS user_posts JOIN users ON users.id = user_posts.user_id WHERE users.country = 'India';
gretelai_synthetic_text_to_sql
CREATE TABLE geopolitical_risk_assessments (id INT, region VARCHAR(255), assessment VARCHAR(255)); INSERT INTO geopolitical_risk_assessments (id, region, assessment) VALUES (1, 'Africa', 'High'), (2, 'Europe', 'Medium'), (3, 'Americas', 'Low'), (4, 'Middle East', 'High');
What is the geopolitical risk assessment for the Middle East?
SELECT assessment FROM geopolitical_risk_assessments WHERE region = 'Middle East';
gretelai_synthetic_text_to_sql
CREATE TABLE wind_farms (country VARCHAR(50), operational BOOLEAN, year INT); INSERT INTO wind_farms (country, operational, year) VALUES ('Canada', true, 2020), ('Brazil', true, 2020), ('Argentina', true, 2020), ('Mexico', false, 2020);
List the number of wind farms in Canada, Brazil, and Argentina, as of 2020.
SELECT country, COUNT(*) FROM wind_farms WHERE country IN ('Canada', 'Brazil', 'Argentina') AND operational = true GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE MammalSightings (ID INT, SightingDate DATE, Species VARCHAR(100), Reserve VARCHAR(100), Observations INT); INSERT INTO MammalSightings (ID, SightingDate, Species, Reserve, Observations) VALUES (1, '2022-05-01', 'Polar Bear', 'Nunavut Wildlife Reserve', 10); INSERT INTO MammalSightings (ID, SightingDate, Species, Reserve, Observations) VALUES (2, '2022-05-05', 'Caribou', 'Yukon Wildlife Reserve', 5);
How many sightings of each mammal species were recorded in the last month across all Arctic reserves?
SELECT Species, Reserve, COUNT(Observations) OVER (PARTITION BY Species, Reserve ORDER BY Species, Reserve ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS SightingsCount FROM MammalSightings WHERE SightingDate >= DATEADD(month, -1, GETDATE());
gretelai_synthetic_text_to_sql
CREATE TABLE if not exists employment (id INT, industry VARCHAR, number_of_employees INT); INSERT INTO employment (id, industry, number_of_employees) VALUES (1, 'manufacturing', 5000), (2, 'technology', 8000), (3, 'healthcare', 7000);
What is the total number of employees in all industries?
SELECT SUM(number_of_employees) FROM employment;
gretelai_synthetic_text_to_sql
CREATE TABLE Water_Usage (id INT, year INT, water_consumption FLOAT); INSERT INTO Water_Usage (id, year, water_consumption) VALUES (1, 2018, 12000.0), (2, 2019, 13000.0), (3, 2020, 14000.0), (4, 2021, 15000.0);
Update the water consumption value in the Water_Usage table for the year 2019 to 12800, if the consumption for that year is higher than the average consumption for the years 2018-2020.
UPDATE Water_Usage SET water_consumption = 12800 WHERE year = 2019 AND water_consumption = (SELECT AVG(water_consumption) FROM Water_Usage WHERE year BETWEEN 2018 AND 2020);
gretelai_synthetic_text_to_sql
CREATE TABLE donations (id INT, donor_id INT, amount DECIMAL(10,2), donation_date DATE); INSERT INTO donations (id, donor_id, amount, donation_date) VALUES (1, 101, 500.00, '2021-01-01'), (2, 102, 300.00, '2021-02-15'), (3, 101, 600.00, '2022-04-01');
What is the total amount donated by each donor who has made a donation in both the last and current quarters?
SELECT donor_id, SUM(amount) FROM donations WHERE donation_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 6 MONTH) AND DATE_SUB(CURDATE(), INTERVAL 3 MONTH) GROUP BY donor_id;
gretelai_synthetic_text_to_sql
CREATE TABLE teams (team_id INT, team_name VARCHAR(50), conference VARCHAR(50)); INSERT INTO teams (team_id, team_name, conference) VALUES (1, 'Atlanta Hawks', 'Eastern'), (2, 'Boston Celtics', 'Eastern'); CREATE TABLE players (player_id INT, player_name VARCHAR(50), team_id INT, age INT);
What is the average age of basketball players in the Eastern Conference by team?
SELECT t.conference, t.team_name, AVG(p.age) as avg_age FROM players p JOIN teams t ON p.team_id = t.team_id WHERE t.conference = 'Eastern' GROUP BY t.conference, t.team_name;
gretelai_synthetic_text_to_sql
CREATE SCHEMA publications;CREATE TABLE student_publications(student_name TEXT,department TEXT,num_publications INTEGER);INSERT INTO student_publications(student_name,department,num_publications)VALUES('Rajesh','Chemistry',4),('Sarah','Chemistry',3),('Tariq','Physics',0);
What is the average number of publications for graduate students in the Chemistry department?
SELECT department,AVG(num_publications) FROM publications.student_publications WHERE department='Chemistry' GROUP BY department;
gretelai_synthetic_text_to_sql
CREATE SCHEMA oceans;CREATE TABLE oceans.marine_life_data (id INT PRIMARY KEY, species VARCHAR(50)); INSERT INTO oceans.marine_life_data (id, species) VALUES (1, 'Tuna'), (2, 'Salmon');
Provide the total number of marine life research data records by species.
SELECT context.species, COUNT(context.species) FROM oceans.marine_life_data AS context GROUP BY context.species;
gretelai_synthetic_text_to_sql
CREATE TABLE Departments (DepartmentID int, DepartmentName varchar(255)); CREATE TABLE Faculty (FacultyID int, FacultyName varchar(255), DepartmentID int, Gender varchar(10));
What is the number of female and male faculty members in each department, ordered by the department name?
SELECT DepartmentName, Gender, COUNT(*) as NumFaculty FROM Faculty f JOIN Departments d ON f.DepartmentID = d.DepartmentID GROUP BY DepartmentName, Gender ORDER BY DepartmentName;
gretelai_synthetic_text_to_sql
CREATE TABLE account (account_id INT, client_id INT, region VARCHAR(50), account_type VARCHAR(50), open_date DATE); INSERT INTO account (account_id, client_id, region, account_type, open_date) VALUES (1, 1, 'Middle East', 'Shariah-compliant', '2022-01-01'), (2, 2, 'Asia', 'Shariah-compliant', '2022-02-01');
What is the number of Shariah-compliant accounts opened by clients in the last month, partitioned by region?
SELECT region, COUNT(*) FROM account WHERE account_type = 'Shariah-compliant' AND open_date >= DATEADD(month, -1, GETDATE()) GROUP BY region;
gretelai_synthetic_text_to_sql
CREATE TABLE Museums (id INT PRIMARY KEY, name VARCHAR(100), location VARCHAR(100), country VARCHAR(50)); INSERT INTO Museums (id, name, location, country) VALUES (1, 'Metropolitan Museum of Art', 'New York', 'USA'); CREATE TABLE Artworks (id INT PRIMARY KEY, title VARCHAR(100), year INT, museum_id INT, FOREIGN KEY (museum_id) REFERENCES Museums(id)); INSERT INTO Artworks (id, title, year, museum_id) VALUES (1, 'Washington Crossing the Delaware', 1851, 1);
What is the oldest artwork in each museum's collection?
SELECT m.name, MIN(a.year) FROM Artworks a JOIN Museums m ON a.museum_id = m.id GROUP BY m.id;
gretelai_synthetic_text_to_sql
CREATE TABLE SeaIceExtent (sea VARCHAR(255), date DATE, extent FLOAT); INSERT INTO SeaIceExtent (sea, date, extent) VALUES ('Barents Sea', '2022-01-01', 1.2); INSERT INTO SeaIceExtent (sea, date, extent) VALUES ('Barents Sea', '2022-02-01', 1.5);
What is the maximum sea ice extent in the Barents Sea during the winter months of 2022?
SELECT MAX(extent) FROM SeaIceExtent WHERE sea = 'Barents Sea' AND date BETWEEN '2022-01-01' AND '2022-12-31' AND MONTH(date) BETWEEN 12 AND 2;
gretelai_synthetic_text_to_sql
CREATE TABLE attorneys (id INT, name TEXT, gender TEXT, city TEXT); INSERT INTO attorneys (id, name, gender, city) VALUES (1, 'Alicia Florrick', 'Female', 'Chicago'); CREATE TABLE cases (id INT, attorney_id INT, result TEXT); INSERT INTO cases (id, attorney_id, result) VALUES (1, 1, 'dropped');
Find the number of cases handled by female attorneys in Chicago.
SELECT COUNT(*) FROM cases INNER JOIN attorneys ON cases.attorney_id = attorneys.id WHERE attorneys.city = 'Chicago' AND attorneys.gender = 'Female';
gretelai_synthetic_text_to_sql
CREATE TABLE nonprofits (id INT, name VARCHAR(255), focus VARCHAR(255), state VARCHAR(2)); INSERT INTO nonprofits (id, name, focus, state) VALUES (1, 'ACLU', 'Social Justice', 'NY'), (2, 'Planned Parenthood', 'Healthcare', 'CA'), (3, 'Greenpeace', 'Environment', 'CA');
List all nonprofits with a focus on social justice in New York.
SELECT name FROM nonprofits WHERE focus = 'Social Justice' AND state = 'NY';
gretelai_synthetic_text_to_sql
CREATE TABLE recycling (factory_id INT, water_recycling BOOLEAN); INSERT INTO recycling (factory_id, water_recycling) VALUES (1, TRUE), (2, FALSE), (3, TRUE), (4, TRUE), (5, FALSE);
What percentage of factories have a water recycling system?
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM recycling)) as percentage FROM recycling WHERE water_recycling = TRUE;
gretelai_synthetic_text_to_sql
CREATE TABLE MobileSubscribers (SubscriberID int, Country varchar(10)); CREATE TABLE BroadbandSubscribers (SubscriberID int, Country varchar(10)); INSERT INTO MobileSubscribers (SubscriberID, Country) VALUES (1, 'USA'), (2, 'Canada'), (3, 'Mexico'), (4, 'Brazil'); INSERT INTO BroadbandSubscribers (SubscriberID, Country) VALUES (1, 'USA'), (2, 'Canada'), (3, 'Mexico'), (4, 'Colombia');
Identify the number of mobile and broadband subscribers per country, and their respective percentage contributions to total subscribers.
SELECT C.Country, COUNT(M.SubscriberID) AS MobileCount, COUNT(B.SubscriberID) AS BroadbandCount, (COUNT(M.SubscriberID)::float / (COUNT(M.SubscriberID) + COUNT(B.SubscriberID))) * 100 AS MobilePercent, (COUNT(B.SubscriberID)::float / (COUNT(M.SubscriberID) + COUNT(B.SubscriberID))) * 100 AS BroadbandPercent FROM MobileSubscribers M FULL OUTER JOIN BroadbandSubscribers B ON M.Country = B.Country GROUP BY C.Country;
gretelai_synthetic_text_to_sql
CREATE TABLE programs (id INT, name TEXT); INSERT INTO programs (id, name) VALUES (1, 'Feeding the Hungry'), (2, 'Tutoring Kids'), (3, 'Cleaning the Environment'), (4, 'Medical Aid'); CREATE TABLE donations (id INT, program_id INT, amount DECIMAL(10, 2));
Insert a new program 'Elderly Care' with ID 5 and add corresponding donation records.
INSERT INTO programs (id, name) VALUES (5, 'Elderly Care'); INSERT INTO donations (id, program_id, amount) VALUES (1, 5, 250.00), (2, 5, 500.00);
gretelai_synthetic_text_to_sql
CREATE TABLE job_applications (id INT, applicant_name VARCHAR(255), application_date DATE, job_title VARCHAR(255), status VARCHAR(255)); INSERT INTO job_applications (id, applicant_name, application_date, job_title, status) VALUES (1, 'John Doe', '2021-01-15', 'Software Engineer', 'Hired'), (2, 'Jane Smith', '2021-02-20', 'Data Analyst', 'Rejected'), (3, 'Alice Johnson', '2021-03-10', 'Project Manager', 'Hired'), (4, 'Bob Brown', '2021-04-01', 'HR Specialist', 'Hired'), (5, 'Charlie Davis', '2021-05-03', 'Finance Manager', 'Interview');
How many employees were hired each month in 2021?
SELECT DATE_FORMAT(application_date, '%Y-%m') as month, COUNT(*) as num_hired FROM job_applications WHERE YEAR(application_date) = 2021 AND status = 'Hired' GROUP BY month;
gretelai_synthetic_text_to_sql
CREATE TABLE customers (customer_id INT, name VARCHAR(50)); INSERT INTO customers VALUES (1, 'John Doe'), (2, 'Jane Smith'); CREATE TABLE transactions (transaction_id INT, customer_id INT, amount DECIMAL(10,2), transaction_date DATE); INSERT INTO transactions VALUES (1, 1, 150.50, '2020-01-01'), (2, 1, 200.00, '2020-02-15'), (3, 2, 75.30, '2020-03-03');
What is the total amount of transactions for each customer in the year 2020?
SELECT c.customer_id, c.name, SUM(t.amount) FROM customers c JOIN transactions t ON c.customer_id = t.customer_id WHERE YEAR(t.transaction_date) = 2020 GROUP BY c.customer_id, c.name;
gretelai_synthetic_text_to_sql
CREATE TABLE artist_demographics (id INT, name VARCHAR(50), country VARCHAR(50), age INT); INSERT INTO artist_demographics (id, name, country, age) VALUES (1, 'John Doe', 'Cuba', 45), (2, 'Jane Smith', 'Bahamas', 35), (3, 'Mike Johnson', 'Jamaica', 55);
What is the minimum age of artists in the Caribbean?
SELECT MIN(age) FROM artist_demographics WHERE country IN ('Cuba', 'Bahamas', 'Jamaica');
gretelai_synthetic_text_to_sql
CREATE TABLE artist_listeners (listener_id INT, artist_id INT, platform VARCHAR(255), listener_month DATE, listeners INT); CREATE VIEW monthly_listeners AS SELECT artist_id, platform, listener_month, SUM(listeners) as total_listeners FROM artist_listeners GROUP BY artist_id, platform, listener_month;
Which artists have the highest number of monthly listeners in the last 12 months, for each platform?
SELECT artist_id, platform, listener_month, total_listeners, ROW_NUMBER() OVER (PARTITION BY platform ORDER BY total_listeners DESC) as rank FROM monthly_listeners WHERE listener_month >= DATEADD(month, -12, CURRENT_DATE) ORDER BY platform, rank;
gretelai_synthetic_text_to_sql
CREATE TABLE forests (id INT, forest VARCHAR(50), year INT, carbon_sequestration FLOAT); INSERT INTO forests (id, forest, year, carbon_sequestration) VALUES (1, 'Forest A', 2019, 12.5), (2, 'Forest A', 2020, 15.2), (3, 'Forest B', 2019, 10.0), (4, 'Forest B', 2020, 11.8), (5, 'Forest C', 2019, 15.0), (6, 'Forest C', 2020, 18.2), (7, 'Forest D', 2019, 14.0), (8, 'Forest D', 2020, 16.0);
Identify the top three forests with the highest average carbon sequestration per year.
SELECT forest, AVG(carbon_sequestration) AS avg_carbon_sequestration FROM forests GROUP BY forest ORDER BY avg_carbon_sequestration DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE sensor_data (sensor_id INT, system VARCHAR(20), status VARCHAR(10), report_date DATE); INSERT INTO sensor_data (sensor_id, system, status, report_date) VALUES (1, 'Precision Irrigation System', 'malfunction', '2021-08-01'), (2, 'Precision Irrigation System', 'working', '2021-08-02'), (3, 'Precision Irrigation System', 'malfunction', '2021-08-03');
Identify the number of IoT sensors that reported malfunctions in 'Precision Irrigation System' during the first week of August, 2021.
SELECT COUNT(*) FROM sensor_data WHERE system = 'Precision Irrigation System' AND status = 'malfunction' AND report_date BETWEEN '2021-08-01' AND '2021-08-07';
gretelai_synthetic_text_to_sql
CREATE TABLE Auto_Shows (Show_Name VARCHAR(30), Year INT, Attendance INT); INSERT INTO Auto_Shows (Show_Name, Year, Attendance) VALUES ('Detroit Auto Show', 2021, 750000), ('Frankfurt Auto Show', 2021, 850000), ('Tokyo Auto Show', 2021, 900000), ('Paris Auto Show', 2021, 1000000), ('Los Angeles Auto Show', 2021, 600000);
Which auto show had the highest attendance in 2021?
SELECT Show_Name, Attendance FROM Auto_Shows WHERE Year = 2021 ORDER BY Attendance DESC LIMIT 1;
gretelai_synthetic_text_to_sql
CREATE TABLE water_usage(industry_id INT, industry VARCHAR(50), state VARCHAR(50), usage FLOAT, year INT); INSERT INTO water_usage(industry_id, industry, state, usage, year) VALUES (1, 'Agriculture', 'California', 12345.6, 2019), (2, 'Manufacturing', 'California', 4567.8, 2019);
List the top 5 water consuming industries and their total water usage in the state of California for 2019.
SELECT industry, SUM(usage) FROM water_usage WHERE state = 'California' AND year = 2019 GROUP BY industry ORDER BY SUM(usage) DESC LIMIT 5;
gretelai_synthetic_text_to_sql
CREATE TABLE municipalities (id INT PRIMARY KEY, name VARCHAR(255));CREATE TABLE complaints (id INT PRIMARY KEY, municipality_id INT, title VARCHAR(255));
Identify the top 5 municipalities with the highest number of citizen complaints, including the number of complaints for each.
SELECT m.name, COUNT(c.id) AS num_complaints FROM municipalities m JOIN complaints c ON m.id = c.municipality_id GROUP BY m.name ORDER BY num_complaints DESC LIMIT 5;
gretelai_synthetic_text_to_sql
CREATE SCHEMA if not exists africa_schema_3;CREATE TABLE africa_schema_3.african_mines (id INT, name VARCHAR, location VARCHAR);INSERT INTO africa_schema_3.african_mines (id, name, location) VALUES (1, 'Ghana mining', 'Ghana'), (2, 'South Africa mining', 'South Africa');
List all mining operations in 'african_mines' located in Ghana.
SELECT name FROM africa_schema_3.african_mines WHERE location = 'Ghana';
gretelai_synthetic_text_to_sql
CREATE SCHEMA Government;CREATE TABLE Government.State (name VARCHAR(255), budget INT);CREATE TABLE Government.Park (name VARCHAR(255), state VARCHAR(255), area INT, budget INT);
What is the total budget allocated to public parks in each state with a park area greater than 500 acres?
SELECT state, SUM(budget) FROM Government.Park WHERE state IN (SELECT name FROM Government.State WHERE area > 500) GROUP BY state;
gretelai_synthetic_text_to_sql
CREATE TABLE Sales (SaleID INT, ProductID INT, QuantitySold INT, SaleDate DATE, DispensaryID INT);
Insert new records of edibles sold in Oregon in June 2021
INSERT INTO Sales (SaleID, ProductID, QuantitySold, SaleDate, DispensaryID) VALUES (1, 101, 15, '2021-06-01', 1001), (2, 102, 20, '2021-06-02', 1001), (3, 103, 10, '2021-06-03', 1001);
gretelai_synthetic_text_to_sql
CREATE TABLE daily_visitors (date DATE, exhibition_id INT, visitors INT); INSERT INTO daily_visitors (date, exhibition_id, visitors) VALUES ('2022-01-01', 5, 200), ('2022-01-02', 5, 250), ('2022-01-03', 6, 300);
What is the average number of visitors per day for the "Ancient Civilizations" exhibition?
SELECT AVG(visitors) FROM daily_visitors WHERE exhibition_id = 5;
gretelai_synthetic_text_to_sql
CREATE TABLE ClothingManufacturers (manufacturer TEXT, sustainable BOOLEAN, last_sustainable_update DATE); INSERT INTO ClothingManufacturers (manufacturer, sustainable, last_sustainable_update) VALUES ('Manufacturer1', true, '2019-01-01'), ('Manufacturer2', false, '2016-01-01'), ('Manufacturer3', true, '2021-01-01'), ('Manufacturer4', true, '2018-01-01');
Count the number of sustainable clothing manufacturers, and show only those manufacturers that have adopted sustainable practices in the last 3 years.
SELECT manufacturer, COUNT(*) as sustainable_manufacturers FROM ClothingManufacturers WHERE sustainable = true AND last_sustainable_update >= DATE_SUB(CURRENT_DATE, INTERVAL 3 YEAR) GROUP BY manufacturer HAVING COUNT(*) > 500;
gretelai_synthetic_text_to_sql
CREATE TABLE WasteGeneration (country VARCHAR(255), waste_generation_kg_per_capita DECIMAL(5,2), region VARCHAR(255)); INSERT INTO WasteGeneration (country, waste_generation_kg_per_capita, region) VALUES ('Israel', 3.4, 'Middle East'), ('Saudi Arabia', 3.1, 'Middle East'), ('Turkey', 2.5, 'Middle East');
What is the average waste generation per capita in the Middle East?
SELECT AVG(waste_generation_kg_per_capita) FROM WasteGeneration WHERE region = 'Middle East';
gretelai_synthetic_text_to_sql
CREATE TABLE infrastructure_investments (investment_id INT, investment_type VARCHAR(20), investment_date DATE, state VARCHAR(50)); INSERT INTO infrastructure_investments (investment_id, investment_type, investment_date, state) VALUES (1, '5G tower', '2023-01-15', 'Ontario');
Which network infrastructure investments were made in the last 3 months in Ontario, Canada?
SELECT * FROM infrastructure_investments WHERE state = 'Ontario' AND investment_date > DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH);
gretelai_synthetic_text_to_sql
CREATE TABLE organizations (id INT, name TEXT);CREATE TABLE funding (id INT, organization_id INT, amount DECIMAL, initiative_year INT, initiative_category TEXT);
Which organizations received the most funding for climate change initiatives in 2020?
SELECT o.name, SUM(funding.amount) as total_funding FROM organizations o JOIN funding ON o.id = funding.organization_id WHERE funding.initiative_year = 2020 AND funding.initiative_category = 'climate change' GROUP BY o.id ORDER BY total_funding DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE DeepestTrenches (id INT, name VARCHAR(255), depth FLOAT); INSERT INTO DeepestTrenches (id, name, depth) VALUES (1, 'Marianas Trench', 10994); INSERT INTO DeepestTrenches (id, name, depth) VALUES (2, 'Tonga Trench', 10882);
What are the names and depths of the deepest ocean trenches in the Pacific Ocean?
SELECT name, depth FROM DeepestTrenches WHERE depth = (SELECT MAX(depth) FROM DeepestTrenches);
gretelai_synthetic_text_to_sql
CREATE TABLE cause_donations (cause VARCHAR(50), country VARCHAR(50), donation DECIMAL(10,2)); INSERT INTO cause_donations (cause, country, donation) VALUES ('Global Health', 'Australia', 5000.00), ('Education', 'Japan', 7000.00), ('Environment', 'India', 8000.00), ('Animal Welfare', 'China', 9000.00);
What is the total donation amount for each cause in the Asia-Pacific region?
SELECT country, SUM(donation) FROM cause_donations WHERE country IN ('Australia', 'Japan', 'India', 'China') GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE Workers (WorkerID int, Name varchar(50), State varchar(25), Earnings decimal(10,2)); INSERT INTO Workers (WorkerID, Name, State, Earnings) VALUES (1, 'John Doe', 'WA', 50000.00), (2, 'Jane Smith', 'WA', 60000.00), (3, 'Mike Johnson', 'WA', 55000.00);
Who are the top 3 construction workers by total earnings in WA?
SELECT Name, ROW_NUMBER() OVER (ORDER BY Earnings DESC) AS Rank FROM Workers WHERE State = 'WA' GROUP BY Name HAVING Rank <= 3;
gretelai_synthetic_text_to_sql
CREATE TABLE Events (event_id INT, venue_name VARCHAR(255), attendance INT); INSERT INTO Events (event_id, venue_name, attendance) VALUES (1, 'Artistic Hub', 300), (2, 'Artistic Hub', 400), (3, 'Creative Space', 250);
What is the average attendance for events at the 'Artistic Hub' venue?
SELECT AVG(attendance) FROM Events WHERE venue_name = 'Artistic Hub';
gretelai_synthetic_text_to_sql
CREATE TABLE grad_enrollment (id INT, student_id INT, student_major VARCHAR(50)); INSERT INTO grad_enrollment (id, student_id, student_major) VALUES (1, 2001, 'Environmental Science'), (2, 2002, 'Marine Biology'), (3, 2003, 'Wildlife Conservation'), (4, 2004, 'Botany'), (5, 2005, 'Ecology'), (6, 2006, 'Zoology');
How many graduate students are enrolled in each department in the College of Environmental and Life Sciences?
SELECT student_major, COUNT(*) FROM grad_enrollment WHERE student_major LIKE '%Environmental and Life Sciences%' GROUP BY student_major;
gretelai_synthetic_text_to_sql
CREATE TABLE employees (id INT, salary FLOAT, organization_type VARCHAR(255)); INSERT INTO employees (id, salary, organization_type) VALUES (1, 70000.00, 'social good'), (2, 80000.00, 'tech company'), (3, 60000.00, 'social good'), (4, 90000.00, 'tech company');
What is the maximum salary of employees working in social good organizations?
SELECT MAX(salary) FROM employees WHERE organization_type = 'social good';
gretelai_synthetic_text_to_sql
CREATE TABLE users (id INT, username VARCHAR(50)); CREATE TABLE status_updates (user_id INT, update_time TIMESTAMP); CREATE TABLE photos (user_id INT, photo_time TIMESTAMP);
Which users have posted a status update or a photo in the last 30 days, and what are their usernames?
SELECT users.username FROM users JOIN status_updates ON users.id = status_updates.user_id WHERE status_updates.update_time > NOW() - INTERVAL '30 days' UNION SELECT users.username FROM users JOIN photos ON users.id = photos.user_id WHERE photos.photo_time > NOW() - INTERVAL '30 days';
gretelai_synthetic_text_to_sql
CREATE TABLE facilities (city TEXT, facility_type TEXT); INSERT INTO facilities (city, facility_type) VALUES ('CityA', 'hospital'), ('CityB', 'hospital'), ('CityC', 'hospital'), ('CityA', 'school'), ('CityB', 'school'), ('CityC', 'school'), ('CityA', 'library'), ('CityB', 'library'), ('CityC', 'library');
List all unique facility types across all cities, excluding libraries.
SELECT DISTINCT facility_type FROM facilities WHERE facility_type != 'library';
gretelai_synthetic_text_to_sql
CREATE TABLE europe (country VARCHAR(50), doctors_per_1000 DECIMAL(3,1)); INSERT INTO europe (country, doctors_per_1000) VALUES ('France', 3.2), ('Germany', 4.3), ('Italy', 4.0);
How many doctors are there per 1000 people in Europe by country?
SELECT country, AVG(doctors_per_1000 * 1000) as doctors_per_1000_people FROM europe GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE deepest_points(ocean VARCHAR(255), depth INT);INSERT INTO deepest_points(ocean, depth) VALUES ('Pacific Ocean', 36070), ('Atlantic Ocean', 8648), ('Indian Ocean', 7258), ('Southern Ocean', 7290), ('Arctic Ocean', 4261);
What is the minimum depth of the deepest point in each ocean?
SELECT MIN(depth) FROM deepest_points;
gretelai_synthetic_text_to_sql
CREATE TABLE user (user_id INT, username VARCHAR(20), posts INT, created_at DATE); INSERT INTO user (user_id, username, posts, created_at) VALUES (1, 'user1', 10, '2022-01-01'), (2, 'user2', 20, '2022-01-02'), (3, 'user3', 30, '2022-01-03'), (4, 'user4', 40, '2022-01-04'), (5, 'user5', 50, '2022-01-05');
What is the average number of posts per day for users in the social_media database?
SELECT AVG(posts / (DATEDIFF('2022-01-05', created_at))) FROM user;
gretelai_synthetic_text_to_sql
CREATE TABLE social_enterprises (id INT, region VARCHAR(20), registration_date DATE); INSERT INTO social_enterprises (id, region, registration_date) VALUES (1, 'Asia-Pacific', '2021-01-01'), (2, 'Europe', '2022-03-15'), (3, 'Americas', '2020-05-03'), (4, 'Americas', '2019-09-20');
List all social enterprises in the 'Americas' region, ordered by their registration date.
SELECT * FROM social_enterprises WHERE region = 'Americas' ORDER BY registration_date;
gretelai_synthetic_text_to_sql
CREATE TABLE Accommodations(id INT, name TEXT, country TEXT, eco_friendly BOOLEAN); INSERT INTO Accommodations(id, name, country, eco_friendly) VALUES (1, 'Eco Lodge', 'Brazil', true), (2, 'Green Apartment', 'Germany', true), (3, 'Regular Hotel', 'Australia', false), (4, 'Sustainable Villa', 'France', true);
How many eco-friendly accommodations are available in Australia and France?
SELECT country, COUNT(*) FROM Accommodations WHERE eco_friendly = true AND country IN ('Australia', 'France') GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE mexico_autonomous_vehicles (vehicle_id INT, type VARCHAR(20), trips INT); CREATE TABLE sao_paulo_autonomous_vehicles (vehicle_id INT, type VARCHAR(20), trips INT); INSERT INTO mexico_autonomous_vehicles (vehicle_id, type, trips) VALUES (1, 'Car', 30), (2, 'Bus', 25), (3, 'Truck', 15); INSERT INTO sao_paulo_autonomous_vehicles (vehicle_id, type, trips) VALUES (4, 'Car', 22), (5, 'Bus', 18), (6, 'Van', 28);
Get the types of autonomous vehicles in Mexico City and Sao Paulo with more than 20 trips.
SELECT DISTINCT type FROM mexico_autonomous_vehicles WHERE trips > 20 UNION SELECT DISTINCT type FROM sao_paulo_autonomous_vehicles WHERE trips > 20;
gretelai_synthetic_text_to_sql
CREATE TABLE CommunityPolicing (id INT, state VARCHAR(20), program_type VARCHAR(20), quantity INT);
What is the maximum number of community policing programs in the state of California?
SELECT MAX(quantity) FROM CommunityPolicing WHERE state = 'California';
gretelai_synthetic_text_to_sql
CREATE TABLE climate_mitigation (id INT, project VARCHAR(255), location VARCHAR(255), budget FLOAT);
Insert a new record into the climate_mitigation table for a project in South America with a budget of 4,500,000.
INSERT INTO climate_mitigation (id, project, location, budget) VALUES (1, 'Reforestation Program', 'South America', 4500000);
gretelai_synthetic_text_to_sql
CREATE TABLE wells (well_id INT, company VARCHAR(255), region VARCHAR(255)); INSERT INTO wells (well_id, company, region) VALUES (1, 'ExxonMobil', 'North Sea'); INSERT INTO wells (well_id, company, region) VALUES (2, 'ExxonMobil', 'Gulf of Mexico');
What is the total number of wells drilled by ExxonMobil in the North Sea?
SELECT COUNT(*) FROM wells WHERE company = 'ExxonMobil' AND region = 'North Sea';
gretelai_synthetic_text_to_sql
CREATE TABLE manufacturers (manufacturer_id INT, manufacturer_name VARCHAR(255));CREATE TABLE garments (garment_id INT, garment_name VARCHAR(255), manufacturer_id INT, price DECIMAL(10,2), is_eco_friendly BOOLEAN);
Which manufacturers have the highest and lowest average prices for eco-friendly garments?
SELECT m.manufacturer_name, AVG(g.price) AS avg_price FROM garments g JOIN manufacturers m ON g.manufacturer_id = m.manufacturer_id WHERE g.is_eco_friendly = TRUE GROUP BY m.manufacturer_name ORDER BY avg_price DESC, m.manufacturer_name ASC LIMIT 1; SELECT m.manufacturer_name, AVG(g.price) AS avg_price FROM garments g JOIN manufacturers m ON g.manufacturer_id = m.manufacturer_id WHERE g.is_eco_friendly = TRUE GROUP BY m.manufacturer_name ORDER BY avg_price ASC, m.manufacturer_name ASC LIMIT 1;
gretelai_synthetic_text_to_sql
CREATE TABLE artists_countries (artist_id INT, country VARCHAR(50)); INSERT INTO artists_countries (artist_id, country) VALUES (1, 'USA'), (2, 'Canada'), (3, 'Mexico'), (4, 'USA'), (5, 'Brazil'), (6, 'USA'), (7, 'Australia'), (8, 'Canada'), (9, 'USA'), (10, 'Germany'); CREATE TABLE artists_sales (artist_id INT, revenue FLOAT); INSERT INTO artists_sales (artist_id, revenue) VALUES (1, 500000.0), (2, 450000.0), (3, 400000.0), (4, 350000.0), (5, 300000.0), (6, 250000.0), (7, 200000.0), (8, 150000.0), (9, 100000.0), (10, 50000.0);
What is the number of unique countries represented by the top 5 best-selling artists?
SELECT COUNT(DISTINCT country) FROM artists_countries ac JOIN (SELECT artist_id FROM artists_sales ORDER BY revenue DESC LIMIT 5) as t ON ac.artist_id = t.artist_id;
gretelai_synthetic_text_to_sql
CREATE TABLE habitats (id INT, habitat_type VARCHAR(255)); INSERT INTO habitats (id, habitat_type) VALUES (1, 'Forest'), (2, 'Grassland'), (3, 'Wetlands'); CREATE TABLE animals (id INT, animal_name VARCHAR(255), habitat_id INT); INSERT INTO animals (id, animal_name, habitat_id) VALUES (1, 'Tiger', 1), (2, 'Elephant', 2), (3, 'Crane', 3);
Find the number of animals in each habitat type
SELECT h.habitat_type, COUNT(a.id) as animal_count FROM habitats h INNER JOIN animals a ON h.id = a.habitat_id GROUP BY h.habitat_type;
gretelai_synthetic_text_to_sql
CREATE TABLE PeacekeepingOperations (id INT, country VARCHAR(50), operation_count INT, year INT); INSERT INTO PeacekeepingOperations (id, country, operation_count, year) VALUES (1, 'China', 5, 2016), (2, 'India', 3, 2016), (3, 'Japan', 4, 2016), (4, 'China', 6, 2017), (5, 'India', 4, 2017), (6, 'Japan', 5, 2017);
What is the total number of peacekeeping operations led by countries in Asia since 2015?
SELECT SUM(operation_count) FROM PeacekeepingOperations WHERE country IN ('China', 'India', 'Japan') AND year >= 2015;
gretelai_synthetic_text_to_sql
CREATE TABLE landfills(region VARCHAR(255), capacity FLOAT); INSERT INTO landfills(region, capacity) VALUES('Region1', 12345.67), ('Region2', 23456.78), ('Region3', 34567.89), ('Region4', 45678.90);
What is the current landfill capacity in cubic meters for the top 3 regions with the highest capacity?
SELECT region, capacity FROM (SELECT region, capacity, ROW_NUMBER() OVER (ORDER BY capacity DESC) as rn FROM landfills) tmp WHERE rn <= 3;
gretelai_synthetic_text_to_sql
CREATE TABLE companies (id INT PRIMARY KEY, name VARCHAR(255)); CREATE TABLE diversity_metrics (id INT PRIMARY KEY, company_id INT, gender VARCHAR(50), diversity_score DECIMAL(3,2));
Insert diversity metrics for 'SmartHome'
INSERT INTO diversity_metrics (id, company_id, gender, diversity_score) VALUES (6, 105, 'Female', 0.55), (7, 105, 'Male', 0.45);
gretelai_synthetic_text_to_sql
CREATE TABLE vehicle_specs (vehicle_name VARCHAR(50), vehicle_type VARCHAR(20), max_speed INT);
What is the maximum speed of sports cars compared to electric vehicles in the 'vehicle_specs' table?
SELECT vehicle_type, MAX(max_speed) FROM vehicle_specs GROUP BY vehicle_type ORDER BY max_speed DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE ArcticOcean (volcano_name TEXT, location TEXT); INSERT INTO ArcticOcean (volcano_name, location) VALUES ('Ormen Lange', 'Norwegian Sea'), ('Kolbeinsey Ridge', 'Greenland Sea'), ('Gakkel Ridge', 'Eurasian Basin');
List all underwater volcanoes in the Arctic Ocean.
SELECT volcano_name FROM ArcticOcean;
gretelai_synthetic_text_to_sql
CREATE TABLE users (id INT, name TEXT); CREATE TABLE user_actions (id INT, user_id INT, action TEXT, album_id INT, platform TEXT); CREATE VIEW unique_platform_users AS SELECT platform, COUNT(DISTINCT user_id) as user_count FROM user_actions GROUP BY platform;
Display the number of unique users who have streamed or downloaded music on each platform.
SELECT platform, user_count FROM unique_platform_users;
gretelai_synthetic_text_to_sql
CREATE TABLE fish_farms (id INT, name TEXT, location TEXT, water_type TEXT); INSERT INTO fish_farms (id, name, location, water_type) VALUES (1, 'Farm C', 'Tokyo', 'Saltwater'); INSERT INTO fish_farms (id, name, location, water_type) VALUES (2, 'Farm D', 'Beijing', 'Freshwater');
What is the average dissolved oxygen level for fish farms in Asia?
SELECT AVG(wq.dissolved_oxygen) FROM fish_farms ff JOIN water_quality wq ON ff.id = wq.fish_farm_id WHERE ff.location LIKE 'Asia%';
gretelai_synthetic_text_to_sql
CREATE TABLE marine_species_population (species_name VARCHAR(255), region VARCHAR(255), avg_population_size FLOAT, conservation_status VARCHAR(255)); INSERT INTO marine_species_population (species_name, region, avg_population_size, conservation_status) VALUES ('Ross Seal', 'Southern Ocean', 1000, 'Fully Protected'), ('Antarctic Krill', 'Southern Ocean', 100000, 'Partially Protected'), ('Crabeater Seal', 'Southern Ocean', 700, 'Fully Protected');
What is the average population size of all marine species in the Southern Ocean, grouped by conservation status?"
SELECT conservation_status, AVG(avg_population_size) as avg_population_size FROM marine_species_population WHERE region = 'Southern Ocean' GROUP BY conservation_status;
gretelai_synthetic_text_to_sql
CREATE TABLE Festivals (FestivalID INT, FestivalName VARCHAR(255)); INSERT INTO Festivals (FestivalID, FestivalName) VALUES (1, 'Festival1'), (2, 'Festival2'), (3, 'Festival3'), (4, 'Festival4'), (5, 'Festival5'); CREATE TABLE Concerts (ConcertID INT, FestivalID INT, GenreID INT); INSERT INTO Concerts (ConcertID, FestivalID, GenreID) VALUES (1, 1, 2), (2, 2, 4), (3, 3, 1), (4, 4, 5), (5, 5, 2), (6, 1, 4), (7, 2, 1), (8, 3, 2);
List all festivals that have had hip hop or rock concerts.
SELECT DISTINCT FestivalName FROM Festivals F JOIN Concerts C ON F.FestivalID = C.FestivalID WHERE C.GenreID IN (2, 4);
gretelai_synthetic_text_to_sql
CREATE TABLE agency (agency_id INT, agency_name VARCHAR(50)); INSERT INTO agency (agency_id, agency_name) VALUES (1, 'Police Department'), (2, 'Courts'), (3, 'Probation Department');
What is the total number of cases handled by each agency?
SELECT agency_name, COUNT(*) as total_cases FROM agency JOIN cases ON agency.agency_id = cases.agency_id GROUP BY agency_name;
gretelai_synthetic_text_to_sql
CREATE TABLE Clients (ClientID INT, ClientName VARCHAR(100), Region VARCHAR(50), FinanciallyCapable BOOLEAN, LastLoanDate DATE, LastDepositDate DATE); INSERT INTO Clients (ClientID, ClientName, Region, FinanciallyCapable, LastLoanDate, LastDepositDate) VALUES (1, 'AB Johnson', 'Africa', FALSE, '2020-02-01', '2021-03-01'), (2, 'CD Smith', 'Africa', TRUE, '2021-05-15', '2021-07-10'), (3, 'EF Liu', 'Africa', FALSE, NULL, '2021-08-01');
Delete records of financially incapable clients from the African region who have not taken any loans or made any deposits in the past 6 months.
DELETE FROM Clients WHERE FinanciallyCapable = FALSE AND Region = 'Africa' AND (LastLoanDate < DATE_SUB(CURDATE(), INTERVAL 6 MONTH) OR LastDepositDate < DATE_SUB(CURDATE(), INTERVAL 6 MONTH));
gretelai_synthetic_text_to_sql
CREATE TABLE ships (id INT, name VARCHAR(50), type VARCHAR(50), year_built INT, max_capacity INT, port_id INT); CREATE TABLE cargos (id INT, description VARCHAR(50), weight FLOAT, port_id INT, ship_id INT); CREATE VIEW ship_cargo AS SELECT s.name AS ship_name, c.description AS cargo_description, c.weight FROM ships s JOIN cargos c ON s.id = c.ship_id;
What is the maximum weight of cargo handled by vessels in the 'Container' type that were built before 2010?
SELECT MAX(c.weight) AS max_weight FROM ships s JOIN ship_cargo sc ON s.name = sc.ship_name JOIN cargos c ON sc.cargo_description = c.description WHERE s.type = 'Container' AND s.year_built < 2010;
gretelai_synthetic_text_to_sql
CREATE TABLE space_debris (id INT, name VARCHAR(50), type VARCHAR(50), launch_date DATE, orbit VARCHAR(50), mass FLOAT);
What is the total mass (in kg) of space debris in Low Earth Orbit?
SELECT SUM(mass) FROM space_debris WHERE orbit = 'Low Earth Orbit';
gretelai_synthetic_text_to_sql
CREATE TABLE districts (district_id INT, num_students INT, num_teachers INT); INSERT INTO districts (district_id, num_students, num_teachers) VALUES (101, 500, 100), (102, 700, 150), (103, 600, 120), (104, 650, 130), (105, 450, 90);
What is the number of districts with more than 600 students?
SELECT COUNT(*) FROM (SELECT district_id FROM districts WHERE num_students > 600 GROUP BY district_id HAVING COUNT(*) > 1);
gretelai_synthetic_text_to_sql
CREATE TABLE ai_algorithms (algorithm_id INT, algorithm_name VARCHAR(50), algorithm_subtype VARCHAR(50), region VARCHAR(50), safety_score FLOAT); INSERT INTO ai_algorithms (algorithm_id, algorithm_name, algorithm_subtype, region, safety_score) VALUES (1, 'AlgoA', 'Deep RL', 'Asia-Pacific', 0.85), (2, 'AlgoB', 'Computer Vision', 'Asia-Pacific', 0.92), (3, 'AlgoC', 'Deep RL', 'Asia-Pacific', 0.88);
What is the average safety score for AI algorithms, grouped by algorithm subtype in the Asia-Pacific region?
SELECT algorithm_subtype, region, AVG(safety_score) AS avg_safety_score FROM ai_algorithms WHERE region = 'Asia-Pacific' GROUP BY algorithm_subtype, region;
gretelai_synthetic_text_to_sql
CREATE TABLE renewable_energy (project_name VARCHAR(50), country VARCHAR(50), year INT, investment INT, renewable_source VARCHAR(50)); INSERT INTO renewable_energy (project_name, country, year, investment, renewable_source) VALUES ('Kenya Wind', 'Kenya', 2018, 300000, 'Wind'); INSERT INTO renewable_energy (project_name, country, year, investment, renewable_source) VALUES ('Nigerian Solar', 'Nigeria', 2018, 500000, 'Solar'); INSERT INTO renewable_energy (project_name, country, year, investment, renewable_source) VALUES ('Moroccan Solar', 'Morocco', 2018, 800000, 'Solar');
What is the number of renewable energy projects and their total investment in Africa in the year 2018?
SELECT COUNT(*) as num_projects, SUM(investment) as total_investment FROM renewable_energy WHERE year = 2018 AND country = 'Africa';
gretelai_synthetic_text_to_sql
CREATE TABLE companies (id INT, name TEXT, industry TEXT, founder_underrepresented BOOLEAN); INSERT INTO companies (id, name, industry, founder_underrepresented) VALUES (1, 'Xi Inc', 'tech', true); INSERT INTO companies (id, name, industry, founder_underrepresented) VALUES (2, 'Omicron Corp', 'finance', false); INSERT INTO companies (id, name, industry, founder_underrepresented) VALUES (3, 'Pi Pty', 'retail', true);
What is the count of startups by industry with at least one underrepresented founder?
SELECT industry, COUNT(*) FROM companies WHERE founder_underrepresented = true GROUP BY industry;
gretelai_synthetic_text_to_sql
nato_equipment
List all military equipment from NATO countries
SELECT * FROM nato_equipment;
gretelai_synthetic_text_to_sql
CREATE TABLE Donations (id INT, donor_id INT, cause VARCHAR(255), amount DECIMAL(10, 2), donation_date DATE); INSERT INTO Donations (id, donor_id, cause, amount, donation_date) VALUES (1, 1001, 'Education', 5000, '2022-01-05'), (2, 1002, 'Health', 3000, '2022-03-15'), (3, 1003, 'Environment', 7000, '2022-01-30');
What is the average donation amount per donor in 2022?
SELECT donor_id, AVG(amount) as avg_donation FROM Donations WHERE donation_date BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY donor_id;
gretelai_synthetic_text_to_sql
CREATE TABLE workers (id INT, name VARCHAR(50), sector VARCHAR(50), salary DECIMAL(10,2)); INSERT INTO workers (id, name, sector, salary) VALUES (1, 'John Doe', 'Ethical Manufacturing', 50000.00), (2, 'Jane Smith', 'Ethical Manufacturing', 55000.00), (3, 'Mike Johnson', 'Ethical Manufacturing', 45000.00);
Update the salary of a worker in the ethical manufacturing sector.
UPDATE workers SET salary = 57000 WHERE name = 'John Doe' AND sector = 'Ethical Manufacturing';
gretelai_synthetic_text_to_sql
CREATE TABLE Properties(id INT, size FLOAT, price INT, city VARCHAR(20));INSERT INTO Properties(id, size, price, city) VALUES (1, 1200, 500000, 'Seattle'), (2, 1500, 650000, 'Seattle'), (3, 1000, 400000, 'Portland'), (4, 2000, 800000, 'SanFrancisco');
What is the average size and price of properties, excluding the most expensive city?
SELECT AVG(size), AVG(price) FROM Properties WHERE city != (SELECT city FROM Properties ORDER BY price DESC LIMIT 1);
gretelai_synthetic_text_to_sql
CREATE TABLE customers (id INT, segment VARCHAR(20)); CREATE TABLE transactions (id INT, customer_id INT, amount DECIMAL(10,2), transaction_date DATE); INSERT INTO customers (id, segment) VALUES (1, 'Online'); INSERT INTO transactions (id, customer_id, amount, transaction_date) VALUES (1, 1, 500, '2022-04-01');
What is the total transaction amount for the 'Online' customer segment in the last quarter?
SELECT SUM(amount) FROM transactions JOIN customers ON transactions.customer_id = customers.id WHERE customers.segment = 'Online' AND transaction_date >= DATE_SUB(CURDATE(), INTERVAL 3 MONTH);
gretelai_synthetic_text_to_sql
CREATE TABLE GameScore (GameID int, GameName varchar(50), Genre varchar(50), Score int); INSERT INTO GameScore (GameID, GameName, Genre, Score) VALUES (1, 'GameA', 'Shooter', 80), (2, 'GameB', 'RPG', 90), (3, 'GameC', 'Shooter', 70), (4, 'GameD', 'RPG', 85);
What is the average score for each game genre?
SELECT Genre, AVG(Score) as AvgScore FROM GameScore GROUP BY Genre;
gretelai_synthetic_text_to_sql
CREATE TABLE tv_shows (id INT, title VARCHAR(255), duration INT, country VARCHAR(50)); INSERT INTO tv_shows (id, title, duration, country) VALUES (1, 'Show1', 30, 'South Korea'), (2, 'Show2', 60, 'South Korea'), (3, 'Show3', 45, 'USA');
What is the average duration of TV shows in South Korea?
SELECT AVG(duration) FROM tv_shows WHERE country = 'South Korea';
gretelai_synthetic_text_to_sql
CREATE TABLE MuseumVisits (ID INT, VisitDate DATE, VisitorID INT, Museum VARCHAR(255), State VARCHAR(50)); CREATE TABLE RepeatVisitors (ID INT, VisitorID INT, FirstVisit DATE, SecondVisit DATE);
What is the percentage of repeat visitors from different states for historical sites?
SELECT m.State, COUNT(DISTINCT m.VisitorID) as TotalVisitors, COUNT(DISTINCT r.VisitorID) as RepeatVisitors, (COUNT(DISTINCT r.VisitorID) * 100.0 / COUNT(DISTINCT m.VisitorID)) as RepeatVisitorPercentage FROM MuseumVisits m JOIN RepeatVisitors r ON m.VisitorID = r.VisitorID WHERE m.Museum = 'Historical Site' GROUP BY m.State;
gretelai_synthetic_text_to_sql
CREATE TABLE habitats (habitat_type VARCHAR(255), area_size FLOAT); CREATE TABLE endangered_species (species VARCHAR(255), habitat_type VARCHAR(255), endangered BOOLEAN);
Show the average area size and total number of endangered species for each habitat type in the "habitats" and "endangered_species" tables
SELECT h1.habitat_type, AVG(h1.area_size) as avg_area_size, SUM(CASE WHEN e1.endangered THEN 1 ELSE 0 END) as total_endangered FROM habitats h1 LEFT JOIN endangered_species e1 ON h1.habitat_type = e1.habitat_type GROUP BY h1.habitat_type;
gretelai_synthetic_text_to_sql
CREATE TABLE marine_species_biomass (species_name VARCHAR(255), region VARCHAR(255), max_biomass FLOAT, conservation_status VARCHAR(255)); INSERT INTO marine_species_biomass (species_name, region, max_biomass, conservation_status) VALUES ('Ross Seal', 'Southern Ocean', 1500, 'Fully Protected'), ('Antarctic Krill', 'Southern Ocean', 100000, 'Partially Protected'), ('Crabeater Seal', 'Southern Ocean', 800, 'Fully Protected');
What is the maximum biomass of all marine species in the Southern Ocean, grouped by conservation status?"
SELECT conservation_status, MAX(max_biomass) as max_biomass FROM marine_species_biomass WHERE region = 'Southern Ocean' GROUP BY conservation_status;
gretelai_synthetic_text_to_sql
CREATE TABLE grants (grant_id INT, faculty_id INT, amount FLOAT, grant_date DATE);
How many research grants have been awarded to each department in the past year?
SELECT department, COUNT(grant_id) FROM grants JOIN faculty ON grants.faculty_id = faculty.faculty_id WHERE grant_date >= DATEADD(year, -1, GETDATE()) GROUP BY department;
gretelai_synthetic_text_to_sql
CREATE TABLE ExoplanetMissions (Mission VARCHAR(50), Spacecraft VARCHAR(50), Discoveries INT, StartYear INT, EndYear INT); INSERT INTO ExoplanetMissions (Mission, Spacecraft, Discoveries, StartYear, EndYear) VALUES ('Kepler', 'Kepler', 2680, 2009, 2018), ('K2', 'K2', 415, 2013, 2021), ('TESS', 'TESS', 25, 2018, NULL), ('CoRoT', 'CoRoT', 33, 2006, 2014), ('Hipparcos', 'Hipparcos', 14, 1989, 1993);
List the space missions that have discovered exoplanets.
SELECT DISTINCT Mission, Spacecraft FROM ExoplanetMissions WHERE Discoveries > 0;
gretelai_synthetic_text_to_sql
CREATE TABLE creative_ai (id INT, tool VARCHAR(20), application VARCHAR(50), country VARCHAR(20)); INSERT INTO creative_ai (id, tool, application, country) VALUES (1, 'GAN', 'Art Generation', 'Canada'); INSERT INTO creative_ai (id, tool, application, country) VALUES (2, 'DALL-E', 'Text-to-Image', 'USA');
Delete records in the 'creative_ai' table where 'tool' is 'GAN' and 'country' is 'Canada'
DELETE FROM creative_ai WHERE tool = 'GAN' AND country = 'Canada';
gretelai_synthetic_text_to_sql
CREATE TABLE fabrics_sourced (id INT PRIMARY KEY, fabric_type VARCHAR(255), country VARCHAR(255), sustainability_rating INT);
Insert records for cotton, hemp, and silk into 'fabrics_sourced' table
INSERT INTO fabrics_sourced (id, fabric_type, country, sustainability_rating) VALUES (1, 'cotton', 'India', 7), (2, 'hemp', 'China', 9), (3, 'silk', 'China', 6);
gretelai_synthetic_text_to_sql
CREATE TABLE prices (id INT, element TEXT, date DATE, price INT); INSERT INTO prices (id, element, date, price) VALUES (1, 'europium', '2020-01-01', 1000), (2, 'europium', '2021-01-01', 1200);
What is the average price of europium per kilogram in the last 2 years?
SELECT AVG(price) FROM prices WHERE element = 'europium' AND extract(year from date) >= 2020;
gretelai_synthetic_text_to_sql
CREATE TABLE posts (id INT, country VARCHAR(255), likes INT, created_at TIMESTAMP);
What was the average number of likes on posts containing the hashtag "#sustainability" in the United States, in the past week?
SELECT AVG(likes) FROM posts WHERE country = 'United States' AND hashtags LIKE '%#sustainability%' AND created_at > NOW() - INTERVAL '1 week';
gretelai_synthetic_text_to_sql
CREATE TABLE oceanography (id INT PRIMARY KEY, ocean_name VARCHAR(255), depth FLOAT); INSERT INTO oceanography (id, ocean_name, depth) VALUES (1, 'Pacific Ocean', 3970); INSERT INTO oceanography (id, ocean_name, depth) VALUES (2, 'Atlantic Ocean', 3000);
Update the 'depth' column to '3980' for all records in the 'oceanography' table where the 'ocean_name' is 'Atlantic Ocean'
UPDATE oceanography SET depth = 3980 WHERE ocean_name = 'Atlantic Ocean';
gretelai_synthetic_text_to_sql
CREATE TABLE CommunityImpacts (community TEXT, year INT, impact_level TEXT); INSERT INTO CommunityImpacts (community, year, impact_level) VALUES ('Inuit', 2010, 'High'), ('Inuit', 2015, 'Very High'), ('Inuit', 2020, 'Severe'), ('Sami', 2015, 'High'), ('Sami', 2020, 'Very High'), ('Gwich’in', 2015, 'High'), ('Gwich’in', 2020, 'Very High'), ('Yupik', 2015, 'High'), ('Yupik', 2020, 'Severe');
Identify indigenous communities facing severe impacts from climate change
SELECT community, STRING_AGG(DISTINCT impact_level, ', ') AS impact_levels FROM CommunityImpacts WHERE year >= 2015 GROUP BY community HAVING COUNT(DISTINCT impact_level) > 2;
gretelai_synthetic_text_to_sql
CREATE TABLE marine_species (id INT, name VARCHAR(255), habitat_type VARCHAR(255), average_depth FLOAT); INSERT INTO marine_species (id, name, habitat_type, average_depth) VALUES (1, 'Clownfish', 'Coral Reef', 20.0); INSERT INTO marine_species (id, name, habitat_type, average_depth) VALUES (2, 'Blue Whale', 'Open Ocean', 200.0); INSERT INTO marine_species (id, name, habitat_type, average_depth) VALUES (3, 'Sea Turtle', 'Coral Reef', 10.0);
What is the total number of marine species in the 'Coral Reef' and 'Open Ocean' habitats?
SELECT SUM(CASE WHEN ms.habitat_type IN ('Coral Reef', 'Open Ocean') THEN 1 ELSE 0 END) as total_species FROM marine_species ms;
gretelai_synthetic_text_to_sql
CREATE TABLE Weather (date DATE, temperature INT, crop_type VARCHAR(20));
What is the average temperature for each crop type in the past 3 years?
SELECT crop_type, AVG(temperature) OVER(PARTITION BY crop_type ORDER BY crop_type ROWS BETWEEN 3 PRECEDING AND CURRENT ROW) as avg_temp FROM Weather;
gretelai_synthetic_text_to_sql
CREATE TABLE education_programs (program_id INT, program_name VARCHAR(50), program_year INT); INSERT INTO education_programs (program_id, program_name, program_year) VALUES (1, 'Program A', 2021), (2, 'Program B', 2022);
How many community education programs were held in '2021'?
SELECT COUNT(*) FROM education_programs WHERE program_year = 2021;
gretelai_synthetic_text_to_sql