context
stringlengths
11
9.12k
question
stringlengths
0
1.06k
SQL
stringlengths
2
4.44k
source
stringclasses
28 values
CREATE TABLE sales_representatives (id INT, name TEXT, region TEXT, sales FLOAT); INSERT INTO sales_representatives (id, name, region, sales) VALUES (1, 'Jose', 'South', 80000), (2, 'Anna', 'South', 70000), (3, 'Raul', 'North', 90000), (4, 'Tanya', 'South', 60000), (5, 'Mohammed', 'East', 100000), (6, 'Emily', 'West', 110000);
Who are the sales representatives with the lowest sales in the South region, and what are their sales amounts?
SELECT name, sales FROM sales_representatives WHERE region = 'South' ORDER BY sales ASC;
gretelai_synthetic_text_to_sql
CREATE TABLE users (user_id INT, user_category VARCHAR(20), user_followers INT); CREATE TABLE posts (post_id INT, user_id INT, post_category VARCHAR(20), post_date DATE, post_likes INT);
What is the sum of post_likes for posts in the 'travel' category from the 'posts' table, who have more than 10,000 followers from the 'users' table, in the past 60 days?
SELECT SUM(post_likes) FROM posts p1 WHERE post_category = 'travel' AND p1.user_id IN (SELECT user_id FROM users WHERE user_followers > 10000) AND p1.post_date >= CURDATE() - INTERVAL 60 DAY;
gretelai_synthetic_text_to_sql
CREATE TABLE nfl_games (game_id INT, season_year INT, home_team VARCHAR(50), away_team VARCHAR(50), home_score INT, away_score INT);
What is the highest scoring NFL game of the 2015 season?
SELECT home_team, away_team, GREATEST(home_score, away_score) AS total_score FROM nfl_games WHERE season_year = 2015 ORDER BY total_score DESC LIMIT 1;
gretelai_synthetic_text_to_sql
CREATE TABLE resources_depleted (id INT, date DATE, resource VARCHAR(50), quantity INT); CREATE VIEW total_resources AS SELECT SUM(quantity) AS total_quantity FROM resources_depleted; CREATE VIEW coal_resources AS SELECT SUM(quantity) AS coal_quantity FROM resources_depleted WHERE resource = 'coal';
Find the percentage of total resources depleted that is coal?
SELECT (coal_quantity / total_quantity) * 100 AS percentage FROM coal_resources, total_resources;
gretelai_synthetic_text_to_sql
CREATE TABLE safety_incidents (incident_id INT, country VARCHAR(50), incident_type VARCHAR(50)); INSERT INTO safety_incidents (incident_id, country, incident_type) VALUES (1, 'CountryA', 'Data Privacy'), (2, 'CountryB', 'Model Malfunction'), (3, 'CountryA', 'Data Privacy');
What is the percentage of AI safety incidents related to data privacy in each country?
SELECT country, COUNT(*) * 100.0 / (SELECT COUNT(*) FROM safety_incidents) as pct_data_privacy_incidents FROM safety_incidents WHERE incident_type = 'Data Privacy' GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE Attorneys (AttorneyID INT, Name VARCHAR(50), Title VARCHAR(20)); INSERT INTO Attorneys (AttorneyID, Name, Title) VALUES (1, 'John Doe', 'Partner'), (2, 'Jane Smith', 'Associate'); CREATE TABLE Cases (CaseID INT, AttorneyID INT, Won BOOLEAN); INSERT INTO Cases (CaseID, AttorneyID, Won) VALUES (1, 1, TRUE), (2, 1, FALSE), (3, 2, TRUE), (4, 2, TRUE);
What is the percentage of cases won by attorneys with 'Partner' title?
SELECT AVG(CASE WHEN Attorneys.Title = 'Partner' AND Cases.Won THEN 100.0 ELSE 0.0 END) AS PercentageWon FROM Attorneys JOIN Cases ON Attorneys.AttorneyID = Cases.AttorneyID WHERE Attorneys.Title = 'Partner';
gretelai_synthetic_text_to_sql
CREATE TABLE ThreatIntelligenceAlerts (AlertID INT, AlertDate DATE, Region TEXT); INSERT INTO ThreatIntelligenceAlerts (AlertID, AlertDate, Region) VALUES (1, '2022-01-10', 'Asia-Pacific'), (2, '2022-02-15', 'Europe'), (3, '2022-03-20', 'Asia-Pacific'), (4, '2022-04-25', 'North America'), (5, '2022-05-10', 'Asia-Pacific');
What is the number of threat intelligence alerts in the Asia-Pacific region in H1 2022?
SELECT COUNT(*) FROM ThreatIntelligenceAlerts WHERE Region = 'Asia-Pacific' AND AlertDate BETWEEN '2022-01-01' AND '2022-06-30';
gretelai_synthetic_text_to_sql
CREATE TABLE r_and_d (drug_name TEXT, expenditure FLOAT, quarter INT, year INT); INSERT INTO r_and_d (drug_name, expenditure, quarter, year) VALUES ('JKL-012', 120000.00, 1, 2022), ('MNO-345', 110000.00, 1, 2022), ('GHI-999', 130000.00, 1, 2022);
What was the R&D expenditure for drug 'GHI-999' in Q1 2022?
SELECT expenditure FROM r_and_d WHERE drug_name = 'GHI-999' AND quarter = 1 AND year = 2022;
gretelai_synthetic_text_to_sql
CREATE TABLE military_sales_4 (supplier VARCHAR(255), buyer VARCHAR(255), equipment VARCHAR(255), year INTEGER, quantity INTEGER); INSERT INTO military_sales_4 (supplier, buyer, equipment, year, quantity) VALUES ('Boeing', 'Australian Government', 'Super Hornet Fighter Jet', 2021, 5), ('Boeing', 'Australian Government', 'Chinook Helicopter', 2021, 2);
What is the total number of military equipment sold by Boeing to the Australian government in 2021?
SELECT SUM(quantity) FROM military_sales_4 WHERE supplier = 'Boeing' AND buyer = 'Australian Government' AND year = 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE climate_mitigation (id INT, country VARCHAR(50), year INT, efforts VARCHAR(50)); INSERT INTO climate_mitigation (id, country, year, efforts) VALUES (1, 'Germany', 2020, 'carbon capture');
Which countries in Europe have reported the most climate mitigation efforts in the last 2 years?
SELECT country, COUNT(*) as num_efforts FROM climate_mitigation WHERE year BETWEEN (YEAR(CURRENT_DATE) - 2) AND YEAR(CURRENT_DATE) GROUP BY country ORDER BY num_efforts DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE financial_aid (financial_aid_id INT, city_id INT, aid_amount DECIMAL(10,2)); CREATE TABLE cities (city_id INT, city_name VARCHAR(50)); INSERT INTO financial_aid (financial_aid_id, city_id, aid_amount) VALUES (1, 1, 25000), (2, 2, 32000), (3, 3, 18000), (4, 4, 40000), (5, 5, 22000), (6, 6, 15000); INSERT INTO cities (city_id, city_name) VALUES (1, 'Los Angeles'), (2, 'Houston'), (3, 'New York'), (4, 'Miami'), (5, 'Chicago'), (6, 'Atlanta');
What is the total amount of financial aid given to each city of 'cities' table and which cities received it?
SELECT city_name, SUM(aid_amount) as total_financial_aid FROM cities INNER JOIN financial_aid ON cities.city_id = financial_aid.city_id GROUP BY city_name;
gretelai_synthetic_text_to_sql
CREATE TABLE Language_Donors (Donor_Name VARCHAR(50), Country VARCHAR(50), Donation_Amount INT); INSERT INTO Language_Donors (Donor_Name, Country, Donation_Amount) VALUES ('Mary Lee', 'USA', 25000), ('David Kim', 'South Korea', 30000), ('Emma Johnson', 'Australia', 35000);
Who are the top 3 donors to language preservation efforts in the Pacific Islands, based on the amount donated?
SELECT Donor_Name, Country, Donation_Amount FROM Language_Donors WHERE Country IN ('USA', 'South Korea', 'Australia') ORDER BY Donation_Amount DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE restaurants (id INT, name VARCHAR(255), category VARCHAR(255));INSERT INTO restaurants (id, name, category) VALUES (1, 'Plant-Based Bistro', 'vegan'), (2, 'The Veggie Table', 'vegan'), (3, 'Farm Fresh Eats', 'vegan');CREATE TABLE sales (restaurant_id INT, revenue INT);INSERT INTO sales (restaurant_id, revenue) VALUES (1, 5000), (1, 7000), (2, 4000), (3, 8000);
Find the total revenue generated by restaurants in the "vegan" category.
SELECT SUM(sales.revenue) FROM sales JOIN restaurants ON sales.restaurant_id = restaurants.id WHERE restaurants.category = 'vegan';
gretelai_synthetic_text_to_sql
CREATE TABLE animal_population (id INT, type VARCHAR(50), species VARCHAR(50), animals INT); INSERT INTO animal_population (id, type, species, animals) VALUES (1, 'Wetlands', 'Alligator', 150), (2, 'Wetlands', 'Turtle', 100), (3, 'Wetlands', 'Crane', 120);
How many animals of each species are there in the 'Wetlands' habitat?
SELECT species, SUM(animals) FROM animal_population WHERE type = 'Wetlands' GROUP BY species;
gretelai_synthetic_text_to_sql
CREATE TABLE subscribers (service VARCHAR(50), subscriber_count INT, quarter VARCHAR(10), year INT); INSERT INTO subscribers (service, subscriber_count, quarter, year) VALUES ('Netflix', 200000000, 'Q1', 2020), ('Netflix', 208000000, 'Q2', 2020), ('Netflix', 215000000, 'Q3', 2020);
Find the percentage change in the number of subscribers for streaming services by quarter.
SELECT service, quarter, year, LAG(subscriber_count) OVER(PARTITION BY service ORDER BY year, quarter) as prev_subscriber_count, (subscriber_count - COALESCE(prev_subscriber_count, subscriber_count)) * 100.0 / subscriber_count as pct_change FROM subscribers;
gretelai_synthetic_text_to_sql
CREATE TABLE aid (id INT, region TEXT, year INT, amount_received DECIMAL(10,2)); INSERT INTO aid
Which regions received the most aid in 2016?
SELECT region, SUM(amount_received) FROM aid WHERE year = 2016 GROUP BY region ORDER BY SUM(amount_received) DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE virtual_tours(id INT, name TEXT, country TEXT, duration INT, price FLOAT); INSERT INTO virtual_tours (id, name, country, duration, price) VALUES (1, 'Tokyo Sky Tree Virtual Tour', 'Japan', 60, 15.99);
List all virtual tours in Japan with their duration and price.
SELECT name, duration, price FROM virtual_tours WHERE country = 'Japan';
gretelai_synthetic_text_to_sql
CREATE TABLE CyberThreats (Threat VARCHAR(50), Frequency INT); INSERT INTO CyberThreats (Threat, Frequency) VALUES ('Phishing', 1500), ('Malware', 1200), ('Ransomware', 1000), ('Denial of Service', 800), ('Data Breach', 600);
What are the top 3 cyber threats by frequency?
SELECT Threat, Frequency, RANK() OVER (ORDER BY Frequency DESC) as Rank FROM CyberThreats WHERE Rank <= 3;
gretelai_synthetic_text_to_sql
CREATE TABLE Warehouse (id INT, name VARCHAR(255)); INSERT INTO Warehouse (id, name) VALUES (1, 'New York'), (2, 'Texas'); CREATE TABLE Packages (id INT, weight FLOAT, warehouse_id INT, shipment_date DATE); INSERT INTO Packages (id, weight, warehouse_id, shipment_date) VALUES (1, 5.6, 1, '2021-01-01'), (2, 7.2, 1, '2021-01-02'), (3, 3.1, 2, '2021-01-03');
What is the average weight of packages shipped to Texas from the New York warehouse?
SELECT AVG(weight) FROM Packages WHERE warehouse_id = (SELECT id FROM Warehouse WHERE name = 'Texas') AND shipment_date BETWEEN '2021-01-01' AND '2021-12-31';
gretelai_synthetic_text_to_sql
CREATE TABLE donations (donor_id INT, donation_amount DECIMAL(10,2), cause TEXT, donation_date DATE); INSERT INTO donations (donor_id, donation_amount, cause, donation_date) VALUES (1, 8000, 'arts & culture', '2023-02-15'); CREATE TABLE donors (donor_id INT, donor_country TEXT); INSERT INTO donors (donor_id, donor_country) VALUES (1, 'Mexico');
What is the maximum donation amount to arts & culture causes by donors from Mexico in the last 2 years?
SELECT MAX(donation_amount) FROM donations JOIN donors ON donations.donor_id = donors.donor_id WHERE cause = 'arts & culture' AND donors.donor_country = 'Mexico' AND donation_date BETWEEN DATE_SUB(NOW(), INTERVAL 2 YEAR) AND NOW();
gretelai_synthetic_text_to_sql
CREATE TABLE cb_agreements (id INT, union TEXT, employer TEXT, start_date DATE, end_date DATE); INSERT INTO cb_agreements (id, union, employer, start_date, end_date) VALUES (1, 'UAW', 'GM', '2016-09-15', '2023-09-14'); INSERT INTO cb_agreements (id, union, employer, start_date, end_date) VALUES (2, 'Teamsters', 'UPS', '2017-07-01', '2024-06-30');
active_cb_agreements
SELECT *, CASE WHEN CURDATE() BETWEEN start_date AND end_date THEN 'Active' ELSE 'Inactive' END as agreement_status FROM cb_agreements;
gretelai_synthetic_text_to_sql
CREATE TABLE military_equipment_maintenance (request_id INT, cost FLOAT, request_date DATE); INSERT INTO military_equipment_maintenance (request_id, cost, request_date) VALUES (1, 20000, '2022-01-01'), (2, 30000, '2022-02-01');
List the top 5 most expensive military equipment maintenance requests in 2022
SELECT * FROM military_equipment_maintenance WHERE request_date >= '2022-01-01' AND request_date < '2023-01-01' ORDER BY cost DESC LIMIT 5;
gretelai_synthetic_text_to_sql
CREATE TABLE community_education (id INT, program VARCHAR(50), location VARCHAR(50), date DATE);
Find the number of unique educational programs in 'community_education' table
SELECT COUNT(DISTINCT program) FROM community_education;
gretelai_synthetic_text_to_sql
CREATE TABLE AutoShows (Show VARCHAR(50), Models INT); INSERT INTO AutoShows (Show, Models) VALUES ('LA Auto Show', 50), ('Detroit Auto Show', 40), ('Tokyo Auto Show', 60), ('Paris Auto Show', 45), ('Frankfurt Auto Show', 55);
What are the top 3 auto shows with the most electric vehicle models?
SELECT Show FROM AutoShows ORDER BY Models DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE organizations (id INT PRIMARY KEY, name VARCHAR(50), type VARCHAR(50), location VARCHAR(50)); INSERT INTO organizations (id, name, type, location) VALUES (1, 'Australian Renewable Energy Agency', 'Government', 'Australia'); INSERT INTO organizations (id, name, type, location) VALUES (2, 'Sustainable Energy Authority of Ireland', 'Government', 'Ireland');
Which organizations have a location in 'Australia' and are of type 'Government'?
SELECT organizations.name, organizations.type, organizations.location FROM organizations WHERE organizations.location = 'Australia' AND organizations.type = 'Government';
gretelai_synthetic_text_to_sql
CREATE TABLE lending_applications (id INT, application_date DATE, approved BOOLEAN); INSERT INTO lending_applications (id, application_date, approved) VALUES (1, '2021-01-02', TRUE), (2, '2021-03-15', FALSE), (3, '2021-04-01', TRUE);
How many socially responsible lending applications were approved in Q1 2021?
SELECT COUNT(*) as num_approved FROM lending_applications WHERE approved = TRUE AND application_date >= '2021-01-01' AND application_date < '2021-04-01';
gretelai_synthetic_text_to_sql
CREATE TABLE accessibility_initiatives (initiative_id INT, initiative_name VARCHAR(50), region VARCHAR(50), launch_year INT); INSERT INTO accessibility_initiatives (initiative_id, initiative_name, region, launch_year) VALUES (1, 'AccessInit1', 'APAC', 2017), (2, 'AccessInit2', 'EMEA', 2016), (3, 'AccessInit3', 'APAC', 2018), (4, 'AccessInit4', 'AMER', 2019);
How many accessible technology initiatives were launched in APAC and EMEA before 2018?
SELECT region, COUNT(*) as count FROM accessibility_initiatives WHERE launch_year < 2018 AND region IN ('APAC', 'EMEA') GROUP BY region;
gretelai_synthetic_text_to_sql
CREATE TABLE Clients (ClientID INT, Name TEXT, Region TEXT); INSERT INTO Clients VALUES (1, 'Jones', 'Northeast'), (2, 'Brown', 'Midwest'), (3, 'Davis', 'Northeast'), (4, 'Miller', 'South'); CREATE TABLE Cases (CaseID INT, ClientID INT, Hours DECIMAL, HourlyRate DECIMAL); INSERT INTO Cases VALUES (1, 1, 10, 200), (2, 2, 8, 180), (3, 3, 15, 220), (4, 1, 12, 250);
What are the names of clients who have had cases in the same regions as the client with the highest billing amount?
SELECT c2.Name FROM Clients c1 INNER JOIN Clients c2 ON c1.Region = c2.Region WHERE c1.ClientID = (SELECT ClientID FROM Clients c INNER JOIN Cases ca ON c.ClientID = ca.ClientID GROUP BY c.ClientID ORDER BY SUM(ca.Hours * ca.HourlyRate) DESC LIMIT 1);
gretelai_synthetic_text_to_sql
CREATE TABLE Artists (ArtistID INT, ArtistName VARCHAR(50), Gender VARCHAR(10), BirthYear INT);CREATE TABLE Paintings (PaintingID INT, PaintingName VARCHAR(50), ArtistID INT, CreationYear INT, Medium VARCHAR(50)); INSERT INTO Artists VALUES (1, 'Frida Kahlo', 'Female', 1907); INSERT INTO Paintings VALUES (1, 'The Two Fridas', 1, 1939, 'Oil on canvas');
What are the most common mediums used by female artists?
SELECT Medium, COUNT(*) as UsageCount FROM Artists a JOIN Paintings p ON a.ArtistID = p.ArtistID WHERE a.Gender = 'Female' GROUP BY Medium ORDER BY UsageCount DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE Artworks (ArtworkID INT, Name VARCHAR(100), Artist VARCHAR(100), Year INT);
What is the average age of artists when they created their masterpieces?
SELECT (AVG(YEAR(CURRENT_DATE) - Artworks.Year) / COUNT(DISTINCT Artworks.Artist)) AS AverageAge
gretelai_synthetic_text_to_sql
CREATE TABLE offenders (oid INT, name TEXT, PRIMARY KEY(oid)); CREATE TABLE crimes (cid INT, oid INT, year INT, PRIMARY KEY(cid), FOREIGN KEY(oid) REFERENCES offenders(oid));
How many crimes were committed by repeat offenders in 2020?
SELECT COUNT(DISTINCT c.oid) FROM crimes c JOIN offenders o ON c.oid = o.oid WHERE c.year = 2020 AND o.oid IN (SELECT oid FROM crimes GROUP BY oid HAVING COUNT(*) > 1);
gretelai_synthetic_text_to_sql
CREATE TABLE fish_harvest (id INT, species VARCHAR(50), region VARCHAR(50), qty INT, quarter INT); INSERT INTO fish_harvest (id, species, region, qty, quarter) VALUES (1, 'Salmon', 'Atlantic', 5000, 1), (2, 'Tuna', 'Pacific', 3000, 1), (3, 'Cod', 'Atlantic', 7000, 2);
How many fish were harvested in Q1 for each species in the Atlantic region?
SELECT species, SUM(qty) FROM fish_harvest WHERE quarter IN (1, 2, 3) AND region = 'Atlantic' GROUP BY species;
gretelai_synthetic_text_to_sql
CREATE TABLE ExcavationSites (site_id INT, site_name TEXT, period TEXT); INSERT INTO ExcavationSites (site_id, site_name, period) VALUES (1, 'SiteA', 'Iron Age'), (2, 'SiteB', 'Bronze Age'); CREATE TABLE Artifacts (artifact_id INT, site_id INT, artifact_name TEXT); INSERT INTO Artifacts (artifact_id, site_id, artifact_name) VALUES (1, 1, 'Artifact1'), (2, 1, 'Artifact2'), (3, 2, 'Artifact3');
Delete all excavation sites and related artifacts from the 'Bronze Age'.
DELETE FROM Artifacts WHERE site_id IN (SELECT site_id FROM ExcavationSites WHERE period = 'Bronze Age'); DELETE FROM ExcavationSites WHERE period = 'Bronze Age';
gretelai_synthetic_text_to_sql
CREATE TABLE DonorVolunteer (DonorID INT, ProgramID INT); INSERT INTO DonorVolunteer (DonorID, ProgramID) VALUES (1, 101), (2, 102), (3, 103), (4, 101);
Find the programs that have received donations from donors who have also volunteered their time?
SELECT ProgramID FROM DonorVolunteer GROUP BY ProgramID HAVING COUNT(DISTINCT DonorID) > 1;
gretelai_synthetic_text_to_sql
CREATE TABLE employment (employment_id INT, supplier_id INT, employee_name VARCHAR(255), employment_date DATE); INSERT INTO employment (employment_id, supplier_id, employee_name, employment_date) VALUES (1, 1, 'John Doe', '2021-01-01'), (2, 1, 'Jane Doe', '2022-02-01');
How many employees have been hired by each supplier, partitioned by year and ordered by the number of employees hired?
SELECT supplier_id, DATE_TRUNC('year', employment_date) AS year, COUNT(DISTINCT employee_name) AS number_of_employees, RANK() OVER (ORDER BY COUNT(DISTINCT employee_name) DESC) AS ranking FROM employment GROUP BY supplier_id, year ORDER BY number_of_employees DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE drugs (drug_name TEXT, rd_expenditures INTEGER); INSERT INTO drugs (drug_name, rd_expenditures) VALUES ('DrugE', 18000000); INSERT INTO drugs (drug_name, rd_expenditures) VALUES ('DrugF', 10000000);
What are the R&D expenditures for DrugE and DrugF?
SELECT drug_name, rd_expenditures FROM drugs WHERE drug_name IN ('DrugE', 'DrugF');
gretelai_synthetic_text_to_sql
CREATE TABLE nutrition (ingredient_id INT, calories INT, protein INT, carbohydrates INT, fat INT); INSERT INTO nutrition (ingredient_id, calories, protein, carbohydrates, fat) VALUES (1, 220, 8, 39, 3.5), (2, 596, 11, 52, 46), (3, 387, 10, 73, 3), (4, 137, 5, 12, 9), (5, 0, 0, 0, 0), (6, 899, 0, 0, 99); CREATE TABLE ingredients (id INT PRIMARY KEY, name VARCHAR(255), origin VARCHAR(255));
Show nutrition data for an ingredient
SELECT nutrition.calories, nutrition.protein, nutrition.carbohydrates, nutrition.fat FROM ingredients INNER JOIN nutrition ON ingredients.id = nutrition.ingredient_id WHERE ingredients.name = 'Quinoa';
gretelai_synthetic_text_to_sql
CREATE TABLE animals (id INT, name VARCHAR(50), status VARCHAR(20), age INT); INSERT INTO animals (id, name, status, age) VALUES (1, 'Tiger', 'Endangered', 10); INSERT INTO animals (id, name, status, age) VALUES (2, 'Elephant', 'Vulnerable', 30); INSERT INTO animals (id, name, status, age) VALUES (3, 'Rhino', 'Critically Endangered', 5); INSERT INTO animals (id, name, status, age) VALUES (4, 'Panda', 'Threatened', 15);
List the names of all animals in the 'threatened' status, ordered by their age
SELECT name FROM animals WHERE status = 'Threatened' ORDER BY age;
gretelai_synthetic_text_to_sql
CREATE TABLE songs (song_id INT, genre VARCHAR(20), album VARCHAR(30), artist VARCHAR(30), length FLOAT, release_year INT); INSERT INTO genres (genre) VALUES ('pop'), ('rock'), ('jazz'), ('hip-hop'); ALTER TABLE songs ADD CONSTRAINT fk_genre FOREIGN KEY (genre) REFERENCES genres(genre);
What is the total length of songs in the rock genre released in 2010?
SELECT SUM(length) as total_length FROM songs WHERE genre = (SELECT genre FROM genres WHERE genre = 'rock') AND release_year = 2010;
gretelai_synthetic_text_to_sql
CREATE TABLE concerts (concert_id INT, artist_name VARCHAR(100), concert_date DATE); INSERT INTO concerts (concert_id, artist_name, concert_date) VALUES (1, 'Taylor Swift', '2020-01-01'); INSERT INTO concerts (concert_id, artist_name, concert_date) VALUES (2, 'BTS', '2020-02-01'); INSERT INTO concerts (concert_id, artist_name, concert_date) VALUES (3, 'Taylor Swift', '2020-03-01');
How many concerts did each artist perform at in the year 2020?
SELECT artist_name, COUNT(*) as concerts_in_2020 FROM concerts WHERE YEAR(concert_date) = 2020 GROUP BY artist_name;
gretelai_synthetic_text_to_sql
CREATE TABLE events (event_id INT, event_name VARCHAR(50), location VARCHAR(50)); INSERT INTO events (event_id, event_name, location) VALUES (1, 'Jazz Night', 'New York'); CREATE TABLE visitors (visitor_id INT, event_id INT, age INT); INSERT INTO visitors (visitor_id, event_id, age) VALUES (1, 1, 35), (2, 1, 42), (3, 1, 28);
What is the average age of visitors who attended jazz events in New York?
SELECT AVG(age) FROM visitors INNER JOIN events ON visitors.event_id = events.event_id WHERE events.location = 'New York' AND events.event_name = 'Jazz Night';
gretelai_synthetic_text_to_sql
CREATE TABLE TemperatureData (country VARCHAR(50), year INT, continent VARCHAR(50), temperature FLOAT); INSERT INTO TemperatureData (country, year, continent, temperature) VALUES ('Canada', 1950, 'North America', 6.5), ('Mexico', 1950, 'North America', 22.0), ('Brazil', 1950, 'South America', 26.0);
What is the average annual temperature change for each continent since 1950?
SELECT continent, AVG(temperature - (SELECT temperature FROM TemperatureData WHERE country = 'Canada' AND year = 1950 AND continent = 'North America')) as 'Average Annual Temperature Change' FROM TemperatureData WHERE year > 1950 GROUP BY continent;
gretelai_synthetic_text_to_sql
CREATE TABLE marine_species (id INT, species_name VARCHAR(255), ocean VARCHAR(255), depth INT); INSERT INTO marine_species (id, species_name, ocean, depth) VALUES (1, 'Hadal Snailfish', 'Atlantic', 7500); INSERT INTO marine_species (id, species_name, ocean, depth) VALUES (2, 'Atlantic Blue Marlin', 'Atlantic', 2000);
How many marine species were observed in the Atlantic ocean with a depth greater than 5000 meters?
SELECT COUNT(*) FROM marine_species WHERE ocean = 'Atlantic' AND depth > 5000;
gretelai_synthetic_text_to_sql
CREATE TABLE customers (id INT, name VARCHAR(50), city VARCHAR(50), balance DECIMAL(10,2)); INSERT INTO customers (id, name, city, balance) VALUES (1, 'John Doe', 'New York', 15000.50); INSERT INTO customers (id, name, city, balance) VALUES (2, 'Jane Smith', 'Los Angeles', 12000.00); INSERT INTO customers (id, name, city, balance) VALUES (3, 'Jim Brown', 'London', 25000.00); INSERT INTO customers (id, name, city, balance) VALUES (4, 'Aya Tanaka', 'Tokyo', 30000.00);
What is the highest balance in 'Tokyo'?
SELECT MAX(balance) FROM customers WHERE city = 'Tokyo';
gretelai_synthetic_text_to_sql
CREATE TABLE astronauts(id INT, name VARCHAR(255), birth_date DATE, gender VARCHAR(10), missions VARCHAR(255)); INSERT INTO astronauts(id, name, birth_date, gender, missions) VALUES (1, 'Alan Shepard', '1923-11-18', 'Male', 'Apollo 14'), (2, 'Buzz Aldrin', '1930-01-20', 'Male', 'Apollo 11');
Who is the oldest astronaut to have walked on the Moon?
SELECT name FROM astronauts WHERE birth_date <= (SELECT MIN(birth_date) FROM astronauts WHERE missions LIKE '%Moon%') AND missions LIKE '%Moon%' ORDER BY birth_date DESC LIMIT 1;
gretelai_synthetic_text_to_sql
CREATE TABLE construction_workers (worker_id INT, name TEXT); CREATE TABLE project_types (project_id INT, project_type TEXT); CREATE TABLE worker_projects (worker_id INT, project_id INT, total_labor_hours INT); INSERT INTO construction_workers (worker_id, name) VALUES (1, 'John Doe'), (2, 'Jane Smith'), (3, 'Maria Garcia'), (4, 'Ahmed Patel'), (5, 'Fatima Khan'), (6, 'Raj Patel'), (7, 'Karen Jackson'); INSERT INTO project_types (project_id, project_type) VALUES (1, 'Residential'), (2, 'Commercial'), (3, 'Sustainable'), (4, 'Historical Restoration'), (5, 'Sustainable'), (6, 'Sustainable'), (7, 'Residential'), (8, 'Historical Restoration'); INSERT INTO worker_projects (worker_id, project_id, total_labor_hours) VALUES (1, 1, 500), (1, 2, 300), (2, 2, 600), (2, 3, 400), (3, 1, 700), (3, 3, 500), (4, 4, 800), (4, 5, 900), (5, 6, 1000), (6, 7, 1100), (7, 3, 1200), (7, 5, 1300), (1, 8, 600), (3, 8, 700);
List the names and total labor hours for workers who have worked on sustainable or historical projects, sorted by the total labor hours in descending order.
SELECT construction_workers.name, SUM(worker_projects.total_labor_hours) FROM construction_workers INNER JOIN worker_projects ON construction_workers.worker_id = worker_projects.worker_id INNER JOIN project_types ON worker_projects.project_id = project_types.project_id WHERE project_types.project_type = 'Sustainable' OR project_types.project_type = 'Historical Restoration' GROUP BY construction_workers.name ORDER BY SUM(worker_projects.total_labor_hours) DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE tracks (id INT, title VARCHAR(255), genre VARCHAR(255), platform VARCHAR(255), sales INT); INSERT INTO tracks (id, title, genre, platform, sales) VALUES (1, 'Track 1', 'Jazz', 'iTunes', 50);
What is the total number of jazz tracks sold on iTunes in Q3 2022?
SELECT SUM(sales) FROM tracks WHERE genre = 'Jazz' AND platform = 'iTunes' AND YEAR(id) = 2022 AND QUARTER(id) = 3;
gretelai_synthetic_text_to_sql
CREATE TABLE Artworks (artwork_id INT, artwork_name VARCHAR(255), artist_name VARCHAR(255), art_category VARCHAR(255)); INSERT INTO Artworks (artwork_id, artwork_name, artist_name, art_category) VALUES (1, 'Painting 1', 'Artist A', 'Painting'), (2, 'Sculpture 1', 'Artist B', 'Sculpture'), (3, 'Painting 2', 'Artist A', 'Painting'), (4, 'Drawing 1', 'Artist C', 'Drawing'), (5, 'Sculpture 2', 'Artist B', 'Sculpture'), (6, 'Painting 3', 'Artist A', 'Painting');
Identify artists who have created more than 3 artworks in each art category and display their names and the number of artworks they've created in each category.
SELECT artist_name, art_category, COUNT(artwork_id) AS num_artworks FROM Artworks GROUP BY artist_name, art_category HAVING COUNT(artwork_id) > 3 ORDER BY num_artworks DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE waste_generation(region VARCHAR(255), population INT, year INT, waste_kg FLOAT);
What is the total waste generation (kg) for rural areas with a population of over 100,000 in 2020?
SELECT SUM(waste_kg) FROM waste_generation WHERE region LIKE '%rural%' AND population > 100000 AND year = 2020;
gretelai_synthetic_text_to_sql
CREATE TABLE heritage_sites (site_id INT, site_name TEXT, country TEXT, year_listed INT); INSERT INTO heritage_sites (site_id, site_name, country, year_listed) VALUES (1, 'Machu Picchu', 'Peru', 1983), (2, 'Petra', 'Jordan', 1985);
What is the average year of listing for heritage sites in each country, ordered by the average year in ascending order?
SELECT country, AVG(year_listed) as avg_year FROM heritage_sites GROUP BY country ORDER BY avg_year;
gretelai_synthetic_text_to_sql
CREATE TABLE shipments (id INT, goods_id INT, quantity INT, source_continent VARCHAR(50), destination_country VARCHAR(50)); INSERT INTO shipments (id, goods_id, quantity, source_continent, destination_country) VALUES (1, 101, 50, 'Asia', 'Brazil'), (2, 102, 75, 'Africa', 'India'), (3, 103, 100, 'Europe', 'USA'), (4, 104, 20, 'Australia', 'Canada'), (5, 105, 30, 'Antarctica', 'Russia');
What are the top 3 countries with the highest total quantities of goods received from all continents?
SELECT destination_country, SUM(quantity) as total_quantity FROM shipments GROUP BY destination_country ORDER BY total_quantity DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE SpaceMissions (id INT, spacecraft_id INT, mission TEXT, duration INT, manufacturer TEXT);
What is the maximum duration of a space mission for each spacecraft manufacturer?
SELECT manufacturer, MAX(duration) FROM SpaceMissions GROUP BY manufacturer;
gretelai_synthetic_text_to_sql
CREATE TABLE buses (id INT, is_autonomous BOOLEAN, city VARCHAR(20), num_buses INT); INSERT INTO buses (id, is_autonomous, city, num_buses) VALUES (1, true, 'Singapore', 500), (2, false, 'Singapore', 1000);
What is the ratio of autonomous to non-autonomous buses in Singapore?
SELECT (SUM(CASE WHEN is_autonomous THEN num_buses ELSE 0 END)) / (SUM(CASE WHEN is_autonomous = false THEN num_buses ELSE 0 END)) FROM buses WHERE city = 'Singapore';
gretelai_synthetic_text_to_sql
CREATE TABLE Water_Infrastructure (id INT, project_name VARCHAR(50), location VARCHAR(50), cost INT);
Calculate the moving average of costs for 3 projects in 'Water_Infrastructure' table.
SELECT project_name, cost, AVG(cost) OVER (ORDER BY id ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS moving_average FROM Water_Infrastructure;
gretelai_synthetic_text_to_sql
CREATE TABLE memberships (id INT, member_state VARCHAR(50), membership_start_date DATE, membership_fee FLOAT); INSERT INTO memberships (id, member_state, membership_start_date, membership_fee) VALUES (1, 'New York', '2022-01-05', 50.0), (2, 'California', '2022-01-10', 75.0);
What is the total revenue generated from memberships in New York and California in Q1 2022?
SELECT SUM(membership_fee) FROM memberships WHERE member_state IN ('New York', 'California') AND membership_start_date BETWEEN '2022-01-01' AND '2022-03-31';
gretelai_synthetic_text_to_sql
CREATE TABLE Facilities (FacilityID INT, FacilityName VARCHAR(50), City VARCHAR(50), Sport VARCHAR(20), Capacity INT); INSERT INTO Facilities (FacilityID, FacilityName, City, Sport, Capacity) VALUES (1, 'Wembley Stadium', 'London', 'Soccer', 90000), (2, 'Madison Square Garden', 'New York', 'Basketball', 20000), (3, 'Staples Center', 'Los Angeles', 'Basketball', 21000);
What is the maximum capacity of basketball facilities?
SELECT MAX(Capacity) FROM Facilities WHERE Sport = 'Basketball';
gretelai_synthetic_text_to_sql
CREATE TABLE branches (branch_id INT, name VARCHAR(255), address VARCHAR(255)); CREATE TABLE loans (loan_id INT, branch_id INT, date DATE, amount DECIMAL(10,2), shariah_compliant BOOLEAN);
Show me the total amount of Shariah-compliant loans issued by each branch in the last quarter.
SELECT branches.name, SUM(loans.amount) FROM branches INNER JOIN loans ON branches.branch_id = loans.branch_id WHERE loans.date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH) AND CURRENT_DATE AND loans.shariah_compliant = TRUE GROUP BY branches.name;
gretelai_synthetic_text_to_sql
CREATE TABLE violations (id INT, workplace_id INT, violation_count INT); INSERT INTO violations (id, workplace_id, violation_count) VALUES (1, 1, 20), (2, 1, 30), (3, 2, 10), (4, 3, 50), (5, 4, 35);
Update the workplace violation count for Workplace D to 25.
UPDATE violations SET violation_count = 25 WHERE workplace_id = 4;
gretelai_synthetic_text_to_sql
CREATE TABLE ArtistExhibitions (id INT, artist_id INT, city VARCHAR(20), price DECIMAL(5,2)); INSERT INTO ArtistExhibitions (id, artist_id, city, price) VALUES (1, 1, 'Paris', 10.00), (2, 1, 'Rome', 12.00), (3, 2, 'Paris', 15.00), (4, 2, 'London', 20.00); CREATE TABLE Artists (id INT, name VARCHAR(30)); INSERT INTO Artists (id, name) VALUES (1, 'Claude Monet'), (2, 'Francisco Goya');
What is the name of the artist with the lowest average ticket price for their exhibitions?
SELECT Artists.name, AVG(ArtistExhibitions.price) AS avg_price FROM Artists JOIN ArtistExhibitions ON Artists.id = ArtistExhibitions.artist_id GROUP BY Artists.name ORDER BY avg_price ASC LIMIT 1;
gretelai_synthetic_text_to_sql
CREATE TABLE community_initiatives (country TEXT, year INT, budget_spent NUMERIC, initiative_type TEXT); INSERT INTO community_initiatives (country, year, budget_spent, initiative_type) VALUES ('Mexico', 2017, 0.8, 'Community Development'), ('Mexico', 2017, 0.9, 'Community Development'), ('Mexico', 2018, 0.75, 'Community Development'), ('Mexico', 2018, 0.92, 'Community Development'), ('Mexico', 2019, 0.85, 'Community Development'), ('Mexico', 2019, 0.95, 'Community Development'), ('Mexico', 2020, 0.87, 'Community Development'), ('Mexico', 2020, 0.96, 'Community Development'), ('Mexico', 2021, 0.88, 'Community Development'), ('Mexico', 2021, 0.93, 'Community Development');
How many community development initiatives were completed in Mexico each year, with at least 85% of the budget spent?
SELECT year, COUNT(*) FROM community_initiatives WHERE country = 'Mexico' AND budget_spent >= 0.85 GROUP BY year;
gretelai_synthetic_text_to_sql
CREATE TABLE exploration_projects (project_id INT, project_name VARCHAR(50), region VARCHAR(50)); CREATE TABLE wells (well_id INT, well_name VARCHAR(50), project_id INT, production FLOAT); INSERT INTO exploration_projects (project_id, project_name, region) VALUES (1, 'Project X', 'Asia-Pacific'), (2, 'Project Y', 'Asia-Pacific'); INSERT INTO wells (well_id, well_name, project_id, production) VALUES (1, 'Well A', 1, 10000), (2, 'Well B', 1, 15000), (3, 'Well C', 2, 20000);
What are the exploration projects in the 'Asia-Pacific' region, along with their total production?
SELECT exploration_projects.project_name, SUM(wells.production) FROM exploration_projects INNER JOIN wells ON exploration_projects.project_id = wells.project_id WHERE exploration_projects.region = 'Asia-Pacific' GROUP BY exploration_projects.project_name;
gretelai_synthetic_text_to_sql
CREATE TABLE vr_headsets (id INT PRIMARY KEY, name VARCHAR(50), manufacturer VARCHAR(50), release_date DATE);
Delete all virtual reality headsets that were released more than two years ago
DELETE FROM vr_headsets WHERE release_date < DATEADD(year, -2, GETDATE());
gretelai_synthetic_text_to_sql
CREATE TABLE programs (id INT, name VARCHAR(50), budget DECIMAL(10,2)); CREATE TABLE expenses (id INT, program_id INT, amount DECIMAL(10,2));
Calculate the percentage of total budget spent for each program
SELECT p.name, SUM(e.amount) / p.budget * 100 as pct_spent FROM programs p JOIN expenses e ON p.id = e.program_id GROUP BY p.name;
gretelai_synthetic_text_to_sql
CREATE TABLE green_buildings (id INT, name VARCHAR(50), location VARCHAR(50), carbon_offset_value FLOAT);
Find the green building with the highest carbon offset value
SELECT * FROM green_buildings WHERE carbon_offset_value = (SELECT MAX(carbon_offset_value) FROM green_buildings);
gretelai_synthetic_text_to_sql
CREATE TABLE Players (PlayerID INT PRIMARY KEY, Name VARCHAR(100), Age INT, Sport VARCHAR(50), Country VARCHAR(50)); INSERT INTO Players (PlayerID, Name, Age, Sport, Country) VALUES (1, 'Lionel Messi', 34, 'Football', 'Argentina'); INSERT INTO Players (PlayerID, Name, Age, Sport, Country) VALUES (2, 'Sergio Aguero', 33, 'Football', 'Argentina');
Who is the oldest football player from Argentina?
SELECT Name as OldestPlayer FROM Players WHERE Sport = 'Football' AND Country = 'Argentina' ORDER BY Age DESC LIMIT 1;
gretelai_synthetic_text_to_sql
CREATE SCHEMA if not exists biosensors;CREATE TABLE if not exists biosensors.patents (id INT PRIMARY KEY, name VARCHAR(100), country VARCHAR(50), patent_date DATE);
How many biosensor technology patents were granted in Germany between 2015 and 2018?
SELECT COUNT(*) FROM biosensors.patents WHERE country = 'Germany' AND patent_date BETWEEN '2015-01-01' AND '2018-12-31';
gretelai_synthetic_text_to_sql
CREATE TABLE city_electric_vehicles (city VARCHAR(50), electric_vehicle INT, date DATE);
What is the total number of electric vehicles in the city per month?
SELECT city, SUM(electric_vehicle) as total_evs FROM city_electric_vehicles GROUP BY city, DATE_TRUNC('month', date);
gretelai_synthetic_text_to_sql
CREATE TABLE strains (id INT, name TEXT, type TEXT); INSERT INTO strains (id, name, type) VALUES (3, 'Pineapple Express', 'Hybrid'); CREATE TABLE sales (id INT, strain_id INT, retail_price DECIMAL, sale_date DATE, state TEXT); INSERT INTO sales (id, strain_id, retail_price, sale_date, state) VALUES (20, 3, 22.00, '2022-04-01', 'Oregon'), (21, 3, 22.00, '2022-04-02', 'Oregon'), (22, 3, 22.00, '2022-04-03', 'Oregon');
Calculate the moving average of daily sales for the strain 'Pineapple Express' over the last 30 days in Oregon.
SELECT AVG(retail_price) OVER (ORDER BY sale_date ROWS BETWEEN 29 PRECEDING AND CURRENT ROW) FROM sales WHERE strain_id = 3 AND state = 'Oregon';
gretelai_synthetic_text_to_sql
CREATE TABLE copper_mine (site_id INT, country VARCHAR(50), production_date DATE, quantity INT); INSERT INTO copper_mine (site_id, country, production_date, quantity) VALUES (1, 'Peru', '2015-01-02', 1000), (2, 'Chile', '2014-12-31', 1500), (3, 'Peru', '2016-03-04', 2000), (4, 'Chile', '2015-06-10', 500);
What is the total number of mining sites and the total quantity of copper extracted for sites located in Peru, having a production date on or after 2015-01-01?
SELECT country, COUNT(DISTINCT site_id) as num_sites, SUM(quantity) as total_copper FROM copper_mine WHERE country = 'Peru' AND production_date >= '2015-01-01' GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE tv_shows (id INT, title VARCHAR(50), genre VARCHAR(20), budget DECIMAL(10,2)); INSERT INTO tv_shows (id, title, genre, budget) VALUES (1, 'ShowA', 'Drama', 8000000), (2, 'ShowB', 'Drama', 10000000);
What's the combined budget of all TV shows in a specific genre?
SELECT SUM(budget) FROM tv_shows WHERE genre = 'Drama';
gretelai_synthetic_text_to_sql
CREATE TABLE fan_attendance (fan_id INT, last_attendance DATE);
Delete records of fans who have not attended any games in the past 2 years from the "fan_attendance" table
DELETE FROM fan_attendance WHERE fan_id NOT IN (SELECT fan_id FROM ticket_sales GROUP BY fan_id HAVING MAX(ticket_sales.sale_date) >= DATE_SUB(CURDATE(), INTERVAL 2 YEAR));
gretelai_synthetic_text_to_sql
CREATE TABLE Donations (DonationID INT, DonorID INT, ProgramID INT, Amount DECIMAL(10,2), DonationDate DATE); CREATE TABLE Programs (ProgramID INT, ProgramName TEXT, FocusArea TEXT);
What is the total amount donated to education programs in the second half of 2021?
SELECT SUM(d.Amount) FROM Donations d INNER JOIN Programs p ON d.ProgramID = p.ProgramID WHERE p.FocusArea = 'Education' AND YEAR(d.DonationDate) = 2021 AND MONTH(d.DonationDate) BETWEEN 7 AND 12;
gretelai_synthetic_text_to_sql
CREATE TABLE virtual_sites(site_id INT, site_name TEXT, virtual_tour_count INT); INSERT INTO virtual_sites(site_id, site_name, virtual_tour_count) VALUES (1, 'Machu Picchu Virtual Tour', 400), (2, 'Eiffel Tower Virtual Tour', 500), (3, 'Great Wall of China Virtual Tour', 600), (4, 'Pyramids of Giza Virtual Tour', 300), (5, 'Taj Mahal Virtual Tour', 550);
Find the top 3 virtual cultural heritage sites globally, and display their site_id, site_name, and virtual_tour_count.
SELECT site_id, site_name, virtual_tour_count FROM (SELECT site_id, site_name, virtual_tour_count, ROW_NUMBER() OVER (ORDER BY virtual_tour_count DESC) rn FROM virtual_sites) subquery WHERE rn <= 3;
gretelai_synthetic_text_to_sql
CREATE TABLE Training (EmployeeID INT, TrainingName VARCHAR(30), CompletionDate DATE); INSERT INTO Training (EmployeeID, TrainingName, CompletionDate) VALUES (6, 'Accessible Technology', '2022-02-20');
How many employees have completed training on accessible technology?
SELECT COUNT(*) FROM Training WHERE TrainingName = 'Accessible Technology';
gretelai_synthetic_text_to_sql
CREATE TABLE protected_zone (tree_id INT, species VARCHAR(50), age INT, height INT, location VARCHAR(50));CREATE TABLE unprotected_zone (tree_id INT, species VARCHAR(50), age INT, height INT, location VARCHAR(50));
What is the number of tree species that are present in both the protected_zone and unprotected_zone tables, and what is the maximum height of trees in the protected_zone table for each of those species?
SELECT species, MAX(height) AS max_height FROM forestry_data.protected_zone WHERE species IN (SELECT species FROM forestry_data.unprotected_zone) GROUP BY species;
gretelai_synthetic_text_to_sql
CREATE TABLE pollution_control_initiatives (initiative_name VARCHAR(255), cost DECIMAL(10,2)); INSERT INTO pollution_control_initiatives (initiative_name, cost) VALUES ('Initiative A', 50000.0), ('Initiative B', 60000.0), ('Initiative C', 70000.0);
Find the total cost of all pollution control initiatives
SELECT SUM(cost) FROM pollution_control_initiatives;
gretelai_synthetic_text_to_sql
CREATE TABLE membership (id INT, union_id INT, members INT); INSERT INTO membership (id, union_id, members) VALUES (1, 1, 500), (2, 2, 300), (3, 3, 700), (4, 1, 600);
What are the membership statistics for unions advocating for underrepresented communities?
SELECT u.name, m.members FROM unions u INNER JOIN membership m ON u.id = m.union_id WHERE u.focus_area = 'underrepresented communities';
gretelai_synthetic_text_to_sql
CREATE TABLE climate_adaptation_projects (id INT, project_name VARCHAR(100), region VARCHAR(100), budget FLOAT); INSERT INTO climate_adaptation_projects (id, project_name, region, budget) VALUES (1, 'Water Management System', 'Latin America', 12000000), (2, 'Green Spaces Expansion', 'Europe', 8000000);
List all climate adaptation projects in Latin America and their respective budgets.
SELECT project_name, budget FROM climate_adaptation_projects WHERE region = 'Latin America';
gretelai_synthetic_text_to_sql
CREATE TABLE organizations (organization_id INT, organization_name VARCHAR(255));CREATE TABLE support_programs (program_id INT, program_name VARCHAR(255), organization_id INT);
What is the total number of disability support programs offered by each organization?
SELECT o.organization_name, COUNT(s.program_id) as total_programs FROM organizations o INNER JOIN support_programs s ON o.organization_id = s.organization_id GROUP BY o.organization_name;
gretelai_synthetic_text_to_sql
CREATE TABLE wells (well_id INT, company VARCHAR(50), region VARCHAR(50), active BOOLEAN); INSERT INTO wells VALUES (1, 'Company A', 'Alberta', TRUE); INSERT INTO wells VALUES (2, 'Company B', 'Alberta', FALSE); INSERT INTO wells VALUES (3, 'Company A', 'Gulf of Mexico', TRUE);
Which company has the most active wells in the 'Alberta' region?
SELECT company, COUNT(*) as num_wells FROM wells WHERE region = 'Alberta' AND active = TRUE GROUP BY company ORDER BY num_wells DESC LIMIT 1;
gretelai_synthetic_text_to_sql
CREATE TABLE carbon_offset_initiatives (initiative_id INT, initiative_name VARCHAR(100), location VARCHAR(100), carbon_offset_tonnes FLOAT); INSERT INTO carbon_offset_initiatives (initiative_id, initiative_name, location, carbon_offset_tonnes) VALUES (1, 'Initiative 1', 'India', 1000.5), (2, 'Initiative 2', 'China', 1500.2);
What is the average carbon offset of initiatives in the 'carbon_offset_initiatives' table, rounded to the nearest integer?
SELECT ROUND(AVG(carbon_offset_tonnes)) FROM carbon_offset_initiatives;
gretelai_synthetic_text_to_sql
CREATE TABLE Budget(Year INT, Region VARCHAR(20), Department VARCHAR(20), Amount INT); INSERT INTO Budget(Year, Region, Department, Amount) VALUES (2022, 'West', 'Infrastructure Development', 5000000), (2022, 'West', 'Infrastructure Development', 6000000), (2022, 'West', 'Infrastructure Development', 4000000);
What is the maximum budget allocated for infrastructure development in the 'West' region in 2022?
SELECT MAX(Amount) FROM Budget WHERE Region = 'West' AND Department = 'Infrastructure Development' AND Year = 2022;
gretelai_synthetic_text_to_sql
CREATE TABLE treatments (treatment_id INT, patient_id INT, healthcare_id INT, date DATE); CREATE TABLE patients (patient_id INT, disease TEXT, age INT, gender TEXT); CREATE TABLE healthcare_facilities (healthcare_id INT, name TEXT, type TEXT, rural BOOLEAN); INSERT INTO treatments (treatment_id, patient_id, healthcare_id, date) VALUES (1, 1, 1, '2021-01-01'), (2, 2, 2, '2021-01-02'); INSERT INTO patients (patient_id, disease, age, gender) VALUES (1, 'Diabetes', 50, 'Female'), (2, 'Diabetes', 60, 'Male'); INSERT INTO healthcare_facilities (healthcare_id, name, type, rural) VALUES (1, 'Rural General Hospital', 'Hospital', TRUE), (2, 'Rural Clinic', 'Clinic', TRUE), (3, 'Rural Pharmacy', 'Pharmacy', TRUE);
How many rural patients with diabetes were treated in hospitals, clinics, or pharmacies, broken down by year?
SELECT YEAR(treatments.date) as year, healthcare_facilities.type, COUNT(treatments.treatment_id) as count FROM treatments INNER JOIN patients ON treatments.patient_id = patients.patient_id INNER JOIN healthcare_facilities ON treatments.healthcare_id = healthcare_facilities.healthcare_id WHERE patients.disease = 'Diabetes' AND healthcare_facilities.rural = TRUE GROUP BY YEAR(treatments.date), healthcare_facilities.type;
gretelai_synthetic_text_to_sql
CREATE TABLE plants (plant_id INT, plant_name VARCHAR(50), city VARCHAR(50), production_output INT); INSERT INTO plants (plant_id, plant_name, city, production_output) VALUES (1, 'PlantA', 'CityX', 500), (2, 'PlantB', 'CityY', 700), (3, 'PlantC', 'CityX', 600), (4, 'PlantD', 'CityZ', 800), (5, 'PlantE', 'CityY', 900);
What is the total production output of plants located in 'CityX' or 'CityY'?
SELECT SUM(production_output) FROM plants WHERE city IN ('CityX', 'CityY');
gretelai_synthetic_text_to_sql
CREATE TABLE teams (team_name VARCHAR(255), season_start_year INT, season_end_year INT); INSERT INTO teams (team_name, season_start_year, season_end_year) VALUES ('Thunder', 2015, 2016); CREATE TABLE players (player_name VARCHAR(255), team_name VARCHAR(255), blocks INT);
What is the total number of blocks by the Thunder's Russell Westbrook in the 2015-2016 season?
SELECT SUM(blocks) FROM players WHERE player_name = 'Russell Westbrook' AND team_name = 'Thunder' AND season_start_year = 2015 AND season_end_year = 2016;
gretelai_synthetic_text_to_sql
CREATE TABLE Cities (CityID INT, CityName VARCHAR(255)); CREATE TABLE Properties (PropertyID INT, SquareFootage FLOAT, SustainabilityRating INT, CityID INT); INSERT INTO Cities VALUES (1, 'Seattle'); INSERT INTO Properties VALUES (1, 1200, 3, 1);
What is the average square footage of sustainable housing units in 'Seattle'?
SELECT AVG(SquareFootage) FROM Properties p JOIN Cities c ON p.CityID = c.CityID WHERE p.SustainabilityRating >= 2 AND c.CityName = 'Seattle';
gretelai_synthetic_text_to_sql
CREATE TABLE vessel_positions (id INT, vessel_name VARCHAR(50), position_lat DECIMAL(8,6), position_lon DECIMAL(8,6), position_timestamp TIMESTAMP); INSERT INTO vessel_positions (id, vessel_name, position_lat, position_lon, position_timestamp) VALUES (1, 'Vessel A', 71.2741, 15.0378, '2022-02-01 12:00:00'), (2, 'Vessel B', 64.1466, -21.9434, '2022-01-01 10:30:00'), (3, 'Vessel C', 69.6404, 14.5010, '2022-03-01 09:00:00');
What is the earliest recorded position of all vessels in the Arctic Ocean?
SELECT vessel_name, MIN(position_timestamp) FROM vessel_positions WHERE ocean = 'Arctic Ocean' GROUP BY vessel_name;
gretelai_synthetic_text_to_sql
CREATE TABLE european_countries (id INT, name VARCHAR(50)); CREATE TABLE mining_operations (id INT, country_id INT, region VARCHAR(20)); CREATE TABLE employees (id INT, operation_id INT, role VARCHAR(20)); INSERT INTO european_countries (id, name) VALUES (1, 'Germany'), (2, 'France'); INSERT INTO mining_operations (id, country_id, region) VALUES (1, 1, 'Europe'), (2, 2, 'Europe'); INSERT INTO employees (id, operation_id, role) VALUES (1, 1, 'Operator'), (2, 1, 'Engineer'), (3, 2, 'Operator'), (4, 2, 'Supervisor');
What's the number of unique roles and their count for mining operations in Europe?
SELECT e.role, COUNT(DISTINCT e.id) as role_count FROM employees e INNER JOIN mining_operations m ON e.operation_id = m.id INNER JOIN european_countries c ON m.country_id = c.id GROUP BY e.role;
gretelai_synthetic_text_to_sql
CREATE TABLE waste_generation (id INT, country VARCHAR(255), year INT, waste_quantity INT); INSERT INTO waste_generation (id, country, year, waste_quantity) VALUES (1, 'China', 2019, 5000), (2, 'India', 2019, 4500), (3, 'USA', 2019, 4000);
What is the total waste generation for the top 2 contributors in 2019?
SELECT country, SUM(waste_quantity) FROM waste_generation WHERE year = 2019 GROUP BY country ORDER BY SUM(waste_quantity) DESC LIMIT 2;
gretelai_synthetic_text_to_sql
CREATE TABLE articles (id INT, title TEXT, word_count INT, published DATE, category TEXT, author_gender TEXT); INSERT INTO articles (id, title, word_count, published, category, author_gender) VALUES (1, 'Article 1', 400, '2021-01-01', 'Opinion', 'Male');
What is the total word count of articles published in the 'Opinion' category in the year 2021, categorized by gender?
SELECT author_gender, SUM(word_count) FROM articles WHERE category = 'Opinion' AND YEAR(published) = 2021 GROUP BY author_gender;
gretelai_synthetic_text_to_sql
CREATE TABLE property (id INT, size_sqft INT, city VARCHAR(255), co_ownership BOOLEAN); INSERT INTO property (id, size_sqft, city, co_ownership) VALUES (1, 1200, 'Seattle', true), (2, 800, 'New York', false);
What is the average size in square feet of properties with co-ownership agreements in Seattle?
SELECT AVG(size_sqft) FROM property WHERE city = 'Seattle' AND co_ownership = true;
gretelai_synthetic_text_to_sql
CREATE TABLE Authors (id INT PRIMARY KEY, name VARCHAR(100), gender VARCHAR(10)); INSERT INTO Authors (id, name, gender) VALUES (1, 'John Doe', 'Male'), (2, 'Jane Smith', 'Female'); CREATE TABLE ArticleAuthors (article_id INT, author_id INT, FOREIGN KEY (article_id) REFERENCES Articles(id), FOREIGN KEY (author_id) REFERENCES Authors(id)); INSERT INTO ArticleAuthors (article_id, author_id) VALUES (1, 1), (2, 2), (3, 1);
How many female and male authors have contributed to the articles?
SELECT gender, COUNT(author_id) as num_authors FROM ArticleAuthors aa JOIN Authors a ON aa.author_id = a.id GROUP BY gender;
gretelai_synthetic_text_to_sql
CREATE TABLE vessels (id VARCHAR(20), name VARCHAR(20), type VARCHAR(20)); CREATE TABLE incidents (id INT, vessel_id VARCHAR(20), type VARCHAR(20)); INSERT INTO vessels (id, name, type) VALUES ('1', 'VesselA', 'Cargo'), ('2', 'VesselB', 'Tanker'), ('3', 'VesselC', 'Cargo'), ('4', 'VesselD', 'Passenger'); INSERT INTO incidents (id, vessel_id, type) VALUES (1, '1', 'Collision'), (2, '2', 'Grounding'), (3, '1', 'OilSpill'), (4, '3', 'Fire'), (5, '4', 'Safety');
How many safety incidents were reported for 'Passenger' type vessels?
SELECT COUNT(*) FROM incidents JOIN vessels ON incidents.vessel_id = vessels.id WHERE type = 'Passenger';
gretelai_synthetic_text_to_sql
CREATE TABLE iron_mines (id INT, name TEXT, location TEXT, production INT); INSERT INTO iron_mines (id, name, location, production) VALUES (1, 'Iron Mine A', 'Country F', 500); INSERT INTO iron_mines (id, name, location, production) VALUES (2, 'Iron Mine B', 'Country F', 700); INSERT INTO iron_mines (id, name, location, production) VALUES (3, 'Iron Mine C', 'Country F', 1000); INSERT INTO iron_mines (id, name, location, production) VALUES (4, 'Iron Mine D', 'Country G', 1200);
Determine the minimum and maximum production values for iron mines in 'Country F'.
SELECT MIN(production), MAX(production) FROM iron_mines WHERE location = 'Country F';
gretelai_synthetic_text_to_sql
CREATE TABLE Nigerian_TV (title TEXT, year INTEGER); INSERT INTO Nigerian_TV (title, year) VALUES ('TVShow1', 2019), ('TVShow2', 2020), ('TVShow3', 2021), ('TVShow4', 2022), ('TVShow5', 2023), ('TVShow6', 2024);
How many TV shows were produced in Nigeria in the last 3 years?
SELECT COUNT(*) FROM Nigerian_TV WHERE year BETWEEN 2020 AND 2023;
gretelai_synthetic_text_to_sql
CREATE TABLE licenses (id INT, type VARCHAR(15), issued_date DATE); INSERT INTO licenses (id, type, issued_date) VALUES (1, 'Cultivation', '2022-01-15'), (2, 'Processing', '2022-02-20'), (3, 'Dispensary', '2022-03-10');
Count the number of cultivation licenses issued per month in Washington in 2022.
SELECT MONTH(issued_date), COUNT(*) FROM licenses WHERE type = 'Cultivation' AND YEAR(issued_date) = 2022 GROUP BY MONTH(issued_date);
gretelai_synthetic_text_to_sql
CREATE TABLE VR_Games (GameID INT, GameName VARCHAR(50), Genre VARCHAR(20)); CREATE TABLE Designers (DesignerID INT, DesignerName VARCHAR(50), YearsOfExperience INT); CREATE TABLE VR_GameDesign (GameID INT, DesignerID INT);
Display the number of VR games in each genre and the total number of years of experience their designers have in VR game development.
SELECT VR_Games.Genre, SUM(Designers.YearsOfExperience) FROM VR_Games INNER JOIN VR_GameDesign ON VR_Games.GameID = VR_GameDesign.GameID INNER JOIN Designers ON VR_GameDesign.DesignerID = Designers.DesignerID GROUP BY VR_Games.Genre;
gretelai_synthetic_text_to_sql
CREATE TABLE carbon_sequestration_by_country (id INT, country VARCHAR(255), year INT, metric_tons FLOAT); INSERT INTO carbon_sequestration_by_country (id, country, year, metric_tons) VALUES (1, 'Brazil', 2019, 123456.12), (2, 'Indonesia', 2019, 234567.12), (3, 'Canada', 2019, 345678.12), (4, 'Russia', 2019, 456789.12), (5, 'China', 2019, 567890.12);
List the top 5 countries with the highest total carbon sequestration, in metric tons, for the year 2019.
SELECT country, SUM(metric_tons) as total_metric_tons FROM carbon_sequestration_by_country WHERE year = 2019 GROUP BY country ORDER BY total_metric_tons DESC LIMIT 5;
gretelai_synthetic_text_to_sql
CREATE TABLE patients (patient_id INT PRIMARY KEY, patient_name TEXT, date_of_birth DATE); CREATE TABLE therapy_sessions (session_id INT PRIMARY KEY, patient_id INT, therapist_id INT, session_date DATE, session_duration TIME);
Count the number of patients who have attended therapy sessions more than once in a month
SELECT COUNT(DISTINCT patients.patient_id) FROM patients INNER JOIN therapy_sessions ON patients.patient_id = therapy_sessions.patient_id GROUP BY patients.patient_id HAVING COUNT(patients.patient_id) > 1;
gretelai_synthetic_text_to_sql
CREATE TABLE district (did INT, name VARCHAR(255)); INSERT INTO district VALUES (1, 'Downtown'), (2, 'Uptown'); CREATE TABLE calls (call_id INT, district_id INT, response_time INT);
Identify the top 3 districts with the longest average response time.
SELECT d.name, AVG(c.response_time) as avg_response_time FROM district d JOIN calls c ON d.did = c.district_id GROUP BY d.did ORDER BY avg_response_time DESC LIMIT 3;
gretelai_synthetic_text_to_sql