context
stringlengths 11
9.12k
| question
stringlengths 0
1.06k
| SQL
stringlengths 2
4.44k
| source
stringclasses 28
values |
|---|---|---|---|
CREATE TABLE Projects (id INT, division VARCHAR(10)); INSERT INTO Projects (id, division) VALUES (1, 'water'), (2, 'transport'), (3, 'energy'); CREATE TABLE TransportProjects (id INT, project_id INT, length DECIMAL(10,2)); INSERT INTO TransportProjects (id, project_id, length) VALUES (1, 2, 500), (2, 2, 550), (3, 3, 600);
|
How many bridges are in the transport division?
|
SELECT COUNT(*) FROM TransportProjects tp JOIN Projects p ON tp.project_id = p.id WHERE p.division = 'transport';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE healthcare_facilities (id INT, name VARCHAR(100), location VARCHAR(50), has_pharmacy BOOLEAN); INSERT INTO healthcare_facilities (id, name, location, has_pharmacy) VALUES (1, 'Rural Clinic', 'Texas', TRUE);
|
What is the percentage of healthcare facilities in rural areas of Texas that have a pharmacy on-site?
|
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM healthcare_facilities WHERE healthcare_facilities.location LIKE '%rural%')) AS percentage FROM healthcare_facilities WHERE healthcare_facilities.location LIKE '%Texas' AND healthcare_facilities.has_pharmacy = TRUE;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Donors (DonorID INT, Name TEXT, TotalDonation DECIMAL(10,2), DonationDate DATE, Country TEXT); INSERT INTO Donors VALUES (1, 'Josephine Garcia', 2000.00, '2021-01-01', 'USA'), (2, 'Ahmed Khan', 1500.00, '2021-03-31', 'India'), (3, 'Maria Rodriguez', 1000.00, '2021-01-15', 'Mexico');
|
What is the total amount donated by each donor in the first quarter of 2021, and the number of donations made in that time period, broken down by the donor's country of residence?
|
SELECT Country, SUM(TotalDonation) as TotalDonated, COUNT(*) as NumDonations FROM Donors WHERE YEAR(DonationDate) = 2021 AND MONTH(DonationDate) BETWEEN 1 AND 3 GROUP BY Country;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE products (product_id INT, name VARCHAR(100), price DECIMAL(5,2), certification VARCHAR(50)); INSERT INTO products (product_id, name, price, certification) VALUES (1, 'Organic Cotton T-Shirt', 25.99, 'Fair Trade'); INSERT INTO products (product_id, name, price, certification) VALUES (2, 'Recycled Tote Bag', 12.99, 'Fair Trade'); CREATE TABLE store (store_id INT, location VARCHAR(50), continent VARCHAR(50)); INSERT INTO store (store_id, location, continent) VALUES (1, 'Berlin Store', 'Europe'); INSERT INTO store (store_id, location, continent) VALUES (2, 'Paris Store', 'Europe'); CREATE TABLE sales (sale_id INT, product_id INT, store_id INT, quantity INT);
|
What is the average price of Fair Trade certified products sold in Europe?
|
SELECT AVG(p.price) FROM products p JOIN sales s ON p.product_id = s.product_id JOIN store st ON s.store_id = st.store_id WHERE p.certification = 'Fair Trade' AND st.continent = 'Europe';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE law_violations (id INTEGER, vessel_size INTEGER, location TEXT, year INTEGER); INSERT INTO law_violations (id, vessel_size, location, year) VALUES (1, 250, 'Southeast Asia', 2020), (2, 150, 'Southeast Asia', 2020), (3, 300, 'Indian Ocean', 2020);
|
What is the average size of vessels that violated maritime law in Southeast Asia in 2020?
|
SELECT AVG(vessel_size) FROM law_violations WHERE location = 'Southeast Asia' AND year = 2020;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE sectors (sid INT, sector_name TEXT); CREATE TABLE employees (eid INT, sector_id INT, employee_type TEXT, salary INT); INSERT INTO sectors VALUES (1, 'Sector A'); INSERT INTO sectors VALUES (2, 'Sector B'); INSERT INTO employees VALUES (1, 1, 'Police Officer', 50000); INSERT INTO employees VALUES (2, 1, 'Firefighter', 60000); INSERT INTO employees VALUES (3, 2, 'Police Officer', 55000); INSERT INTO employees VALUES (4, 2, 'Firefighter', 65000);
|
What is the total number of police officers and firefighters in each community policing sector?
|
SELECT s.sector_name, SUM(CASE WHEN e.employee_type = 'Police Officer' THEN 1 ELSE 0 END) AS total_police_officers, SUM(CASE WHEN e.employee_type = 'Firefighter' THEN 1 ELSE 0 END) AS total_firefighters FROM sectors s JOIN employees e ON s.sid = e.sector_id GROUP BY s.sector_name;
|
gretelai_synthetic_text_to_sql
|
CREATE SCHEMA disease_data; CREATE TABLE zika_cases (id INT, clinic_id INT, date DATE, cases INT); INSERT INTO disease_data.zika_cases (id, clinic_id, date, cases) VALUES (1, 1001, '2020-01-01', 2), (2, 1001, '2020-02-01', 3), (3, 1002, '2020-03-01', 1), (4, 1002, '2020-04-01', 5), (5, 1003, '2020-05-01', 4);
|
How many confirmed Zika virus cases were reported in 'disease_data' for the year 2020?
|
SELECT SUM(cases) FROM disease_data.zika_cases WHERE date BETWEEN '2020-01-01' AND '2020-12-31';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE patients (id INT, country VARCHAR(255), improvement VARCHAR(255)); INSERT INTO patients (id, country, improvement) VALUES (1, 'Australia', 'Improved'), (2, 'Australia', 'Not Improved'), (3, 'USA', 'Improved'); CREATE TABLE therapy (patient_id INT, therapy_type VARCHAR(255)); INSERT INTO therapy (patient_id, therapy_type) VALUES (1, 'CBT'), (2, 'CBT'), (3, 'DBT');
|
Percentage of patients who improved after CBT in Australia?
|
SELECT 100.0 * COUNT(CASE WHEN improvement = 'Improved' AND country = 'Australia' AND therapy_type = 'CBT' THEN 1 END) / COUNT(*) as percentage FROM patients JOIN therapy ON patients.id = therapy.patient_id WHERE country = 'Australia';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE vessels (id INT, name VARCHAR(50), company VARCHAR(50)); INSERT INTO vessels (id, name, company) VALUES (1, 'MV Pegasus', 'Sea Dragons Shipping'), (2, 'MV Orion', 'Sea Dragons Shipping'), (3, 'MV Draco', 'Poseidon Shipping'), (4, 'MV Perseus', 'Poseidon Shipping'), (5, 'MV Andromeda', 'Triton Shipping');
|
List the vessels owned by the company 'Sea Dragons Shipping'
|
SELECT name FROM vessels WHERE company = 'Sea Dragons Shipping';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Players (PlayerID INT, GameType VARCHAR(10)); INSERT INTO Players (PlayerID, GameType) VALUES (1, 'Sports'), (2, 'Strategy'), (3, 'Action'), (4, 'Simulation');
|
What is the total number of players who play sports and action games?
|
SELECT COUNT(*) FROM Players WHERE GameType IN ('Sports', 'Action');
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE news_reporters (id INT, name VARCHAR(50), gender VARCHAR(10), age INT); INSERT INTO news_reporters (id, name, gender, age) VALUES (1, 'John Doe', 'Male', 35), (2, 'Jane Smith', 'Female', 32), (3, 'Alice Johnson', 'Female', 40);
|
What is the minimum age of male journalists in the 'news_reporters' table?
|
SELECT MIN(age) FROM news_reporters WHERE gender = 'Male';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE StateI_Enviro (ID INT, Year INT, Amount FLOAT); INSERT INTO StateI_Enviro (ID, Year, Amount) VALUES (1, 2022, 1000000), (2, 2022, 1500000), (3, 2022, 750000);
|
What is the minimum and maximum amount of funds spent on environmental initiatives in 'StateI' in 2022?
|
SELECT MIN(Amount), MAX(Amount) FROM StateI_Enviro WHERE Year = 2022;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE donation_dates (donation_id INT, donation_year INT, program_category VARCHAR(20)); INSERT INTO donation_dates VALUES (1, 2021, 'Arts'), (2, 2022, 'Education'), (3, 2022, 'Health'), (4, 2021, 'Science'), (5, 2022, 'Arts');
|
List the program categories that have received donations in the current year, excluding categories that received donations only in the previous year.
|
SELECT program_category FROM donation_dates WHERE donation_year = YEAR(CURRENT_DATE) AND program_category NOT IN (SELECT program_category FROM donation_dates WHERE donation_year = YEAR(CURRENT_DATE) - 1) GROUP BY program_category;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE climate_finance (project_id INT, project_location VARCHAR(50), project_type VARCHAR(50), amount FLOAT); INSERT INTO climate_finance (project_id, project_location, project_type, amount) VALUES (1, 'Africa', 'Renewable Energy', 5000000); INSERT INTO climate_finance (project_id, project_location, project_type, amount) VALUES (2, 'Asia', 'Energy Efficiency', 6000000); INSERT INTO climate_finance (project_id, project_location, project_type, amount) VALUES (3, 'South America', 'Carbon Capture', 7000000);
|
What is the total amount of climate finance provided to projects in Africa, Asia, and South America, categorized by project type?
|
SELECT project_type, SUM(amount) as total_amount FROM climate_finance WHERE project_location IN ('Africa', 'Asia', 'South America') GROUP BY project_type;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE mobile_plans (id INT, plan_name VARCHAR(50), num_subscribers INT, price FLOAT);
|
What is the total revenue generated by each mobile plan in the last quarter?
|
SELECT plan_name, SUM(price * num_subscribers) FROM mobile_plans JOIN mobile_subscribers ON mobile_plans.id = mobile_subscribers.plan_id WHERE mobile_subscribers.subscription_date >= DATE_SUB(CURDATE(), INTERVAL 3 MONTH) GROUP BY plan_name;
|
gretelai_synthetic_text_to_sql
|
CREATE SCHEMA CityData; CREATE TABLE CitySocialServices (Service varchar(255), Year int, Budget int, Contractor varchar(255)); INSERT INTO CitySocialServices (Service, Year, Budget, Contractor) VALUES ('Childcare', 2025, 200000, 'Public'), ('Childcare', 2025, 500000, 'Private'), ('Elderly Care', 2025, 700000, 'Public');
|
What is the total budget allocated for social services provided by private contractors in the 'CityData' schema's 'CitySocialServices' table, for the year 2025?
|
SELECT SUM(Budget) FROM CityData.CitySocialServices WHERE Year = 2025 AND Contractor = 'Private';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE smart_contracts (id INT, creator VARCHAR(50), region VARCHAR(10)); INSERT INTO smart_contracts (id, creator, region) VALUES ('Creator1', 'Africa'), ('Creator2', 'Africa'), ('Creator3', 'Africa'); INSERT INTO smart_contracts (id, creator, region) VALUES (4, 'Creator4', 'Asia'), (5, 'Creator5', 'Asia');
|
Who are the top 3 smart contract creators in Africa by number of contracts?
|
SELECT creator, COUNT(*) as contract_count, RANK() OVER (PARTITION BY region ORDER BY COUNT(*) DESC) as rank FROM smart_contracts GROUP BY creator;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Claim (ClaimID int, PolicyID int, ClaimDate date, ClaimAmount int, State varchar(50)); INSERT INTO Claim (ClaimID, PolicyID, ClaimDate, ClaimAmount, State) VALUES (1, 1, '2020-03-15', 2000, 'Texas'), (2, 2, '2019-12-27', 3000, 'California'), (3, 3, '2021-01-05', 1500, 'Texas');
|
How many claims were filed in Texas in 2020?
|
SELECT COUNT(*) FROM Claim WHERE ClaimDate BETWEEN '2020-01-01' AND '2020-12-31' AND State = 'Texas';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Neighborhoods (NeighborhoodID INT, NeighborhoodName VARCHAR(255)); CREATE TABLE PropertyTaxRates (PropertyTaxRateID INT, NeighborhoodID INT, Rate DECIMAL(5,2));
|
What is the standard deviation of property tax rates in each neighborhood?
|
SELECT N.NeighborhoodName, STDEV(PTR.Rate) as StdDevRate FROM Neighborhoods N JOIN PropertyTaxRates PTR ON N.NeighborhoodID = PTR.NeighborhoodID GROUP BY N.NeighborhoodName;
|
gretelai_synthetic_text_to_sql
|
CREATE SCHEMA labor_unions; CREATE TABLE unions (id INT PRIMARY KEY, name VARCHAR(255)); CREATE TABLE employees (id INT PRIMARY KEY, name VARCHAR(255), union_id INT, FOREIGN KEY (union_id) REFERENCES unions(id)); INSERT INTO unions (id, name) VALUES (1, 'Union A'), (2, 'Union B'); INSERT INTO employees (id, name, union_id) VALUES (1, 'John Doe', 1), (2, 'Jane Smith', NULL);
|
Find the number of employees and unions in the 'labor_unions' schema
|
SELECT COUNT(DISTINCT e.id) AS employee_count, COUNT(DISTINCT u.id) AS union_count FROM labor_unions.employees e LEFT JOIN labor_unions.unions u ON e.union_id = u.id;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE ports (id INT PRIMARY KEY, name VARCHAR(50), region_id INT); CREATE TABLE regions (id INT PRIMARY KEY, name VARCHAR(50));
|
List all ports with their corresponding regions from the 'ports' and 'regions' tables.
|
SELECT ports.name, regions.name AS region_name FROM ports INNER JOIN regions ON ports.region_id = regions.id;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE climate_finance (project VARCHAR(50), country VARCHAR(50), amount FLOAT, date DATE); CREATE TABLE inflation_rates (country VARCHAR(50), rate FLOAT, date DATE); INSERT INTO climate_finance (project, country, amount, date) VALUES ('Green City', 'USA', 5000000, '2020-01-01'); INSERT INTO inflation_rates (country, rate, date) VALUES ('USA', 1.02, '2020-01-01');
|
Update the climate finance data to reflect the current inflation rates, using the 'inflation_rates' table.
|
UPDATE climate_finance SET amount = amount * (SELECT rate FROM inflation_rates WHERE climate_finance.country = inflation_rates.country AND climate_finance.date = inflation_rates.date);
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE programs (program_id INT, program_name TEXT, budget DECIMAL(10, 2)); INSERT INTO programs VALUES (1, 'Education', 10000.00), (2, 'Health', 15000.00), (3, 'Environment', 8000.00);
|
List all programs in the 'programs' table that have a budget greater than the average program budget.
|
SELECT program_name FROM programs WHERE budget > (SELECT AVG(budget) FROM programs);
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE farmer (id INTEGER, name TEXT, area TEXT);CREATE TABLE farmland (id INTEGER, farmer_id INTEGER, type TEXT, start_date DATE, end_date DATE);CREATE TABLE crop (id INTEGER, farmland_id INTEGER, type TEXT, planted_date DATE);
|
How many farmers are growing each crop type in urban and rural areas in the past month?
|
SELECT fl.type as area_type, c.type as crop, COUNT(f.id) as num_farmers FROM farmer f INNER JOIN farmland fl ON f.id = fl.farmer_id INNER JOIN crop c ON fl.id = c.farmland_id WHERE c.planted_date >= DATEADD(month, -1, CURRENT_DATE) GROUP BY fl.type, c.type;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE ProductsParabenFree (product_id INT, product_name TEXT, is_paraben_free BOOLEAN); INSERT INTO ProductsParabenFree (product_id, product_name, is_paraben_free) VALUES (1, 'Product A', true), (2, 'Product B', false), (3, 'Product C', false), (4, 'Product D', true), (5, 'Product E', false);
|
List the top 5 most purchased beauty products that are not labeled 'paraben-free'.
|
SELECT product_id, product_name FROM ProductsParabenFree WHERE is_paraben_free = false GROUP BY product_id, product_name ORDER BY COUNT(*) DESC LIMIT 5;
|
gretelai_synthetic_text_to_sql
|
CREATE VIEW ongoing_peacekeeping_operations AS SELECT * FROM peacekeeping_operations WHERE end_date >= CURDATE();
|
Create a view named 'ongoing_peacekeeping_operations'
|
CREATE VIEW ongoing_peacekeeping_operations AS SELECT * FROM peacekeeping_operations WHERE end_date >= CURDATE();
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Sales (id INT, vehicle_id INT, quantity INT, date DATE, country VARCHAR(50)); CREATE TABLE Vehicles (id INT, make VARCHAR(50), model VARCHAR(50), type VARCHAR(50)); INSERT INTO Sales (id, vehicle_id, quantity, date, country) VALUES (1, 1, 100, '2021-01-01', 'USA'); INSERT INTO Vehicles (id, make, model, type) VALUES (1, 'Tesla', 'Model 3', 'Electric');
|
What is the market share of electric vehicles in each country?
|
SELECT country, (SUM(CASE WHEN type = 'Electric' THEN quantity ELSE 0 END) / SUM(quantity)) * 100 AS market_share FROM Sales INNER JOIN Vehicles ON Sales.vehicle_id = Vehicles.id GROUP BY country;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE oil_rig (id INT, company VARCHAR(255), location VARCHAR(255), status VARCHAR(255));
|
Delete all records in the 'oil_rig' table where the 'location' is 'North Sea'
|
DELETE FROM oil_rig WHERE location = 'North Sea';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE drugs (drug_name TEXT, sales INTEGER); INSERT INTO drugs (drug_name, sales) VALUES ('DrugA', 5000), ('DrugB', 7000);
|
What are the total sales figures for drug 'DrugA' and 'DrugB'?
|
SELECT SUM(sales) FROM drugs WHERE drug_name IN ('DrugA', 'DrugB');
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE community_development (id INT, year INT, initiative VARCHAR(50), status VARCHAR(20)); INSERT INTO community_development (id, year, initiative, status) VALUES (1, 2018, 'Cultural Festival', 'Planned'), (2, 2019, 'Youth Center', 'In Progress'), (3, 2019, 'Sports Club', 'Completed'), (4, 2018, 'Clean Water Access', 'Planned');
|
How many community development initiatives were planned in 2018?
|
SELECT COUNT(*) FROM community_development WHERE year = 2018 AND status = 'Planned';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE texas_population (id INT, city VARCHAR(50), population INT, year INT); INSERT INTO texas_population (id, city, population, year) VALUES (1, 'Houston', 2300000, 2020); INSERT INTO texas_population (id, city, population, year) VALUES (2, 'San Antonio', 1600000, 2020); INSERT INTO texas_population (id, city, population, year) VALUES (3, 'Dallas', 1300000, 2020); INSERT INTO texas_population (id, city, population, year) VALUES (4, 'Austin', 1000000, 2020); CREATE TABLE texas_water_consumption (id INT, city VARCHAR(50), water_consumption FLOAT, year INT); INSERT INTO texas_water_consumption (id, city, water_consumption, year) VALUES (1, 'Houston', 18000000, 2020); INSERT INTO texas_water_consumption (id, city, water_consumption, year) VALUES (2, 'San Antonio', 12000000, 2020); INSERT INTO texas_water_consumption (id, city, water_consumption, year) VALUES (3, 'Dallas', 9000000, 2020); INSERT INTO texas_water_consumption (id, city, water_consumption, year) VALUES (4, 'Austin', 7000000, 2020);
|
What is the average water consumption per capita in the state of Texas for the year 2020?
|
SELECT AVG(twc.water_consumption / tp.population) FROM texas_water_consumption twc INNER JOIN texas_population tp ON twc.city = tp.city WHERE twc.year = 2020;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Astronauts (id INT, name VARCHAR(255), country VARCHAR(255), age INT); INSERT INTO Astronauts (id, name, country, age) VALUES (1, 'Rakesh Sharma', 'India', 72); INSERT INTO Astronauts (id, name, country, age) VALUES (2, 'Kalpana Chawla', 'India', N/A); INSERT INTO Astronauts (id, name, country, age) VALUES (3, 'Sunita Williams', 'United States', 57);
|
How many astronauts are from India?
|
SELECT COUNT(*) FROM Astronauts WHERE country = 'India';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Venues (VenueID INT, Name VARCHAR(100), City VARCHAR(100), Capacity INT);
|
What is the most popular concert venue in New York City?
|
SELECT V.Name FROM Venues V INNER JOIN Concerts C ON V.VenueID = C.VenueID WHERE V.City = 'New York City' GROUP BY V.Name ORDER BY COUNT(*) DESC LIMIT 1;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE teams (team_id INT, team_name VARCHAR(100)); CREATE TABLE players (player_id INT, player_name VARCHAR(100), team_id INT); CREATE TABLE goals (goal_id INT, player_id INT, goal_count INT);
|
Who are the top 5 goal scorers in the English Premier League this season?
|
SELECT players.player_name, SUM(goals.goal_count) as total_goals FROM players INNER JOIN goals ON players.player_id = goals.player_id WHERE teams.team_id IN (SELECT team_id FROM teams WHERE team_name = 'English Premier League') GROUP BY players.player_name ORDER BY total_goals DESC LIMIT 5;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE posts (id INT, user_id INT, content TEXT, timestamp TIMESTAMP);
|
What is the average number of posts per day in the 'social_media' database?
|
SELECT AVG(COUNT(posts.id)/86400) AS avg_posts_per_day FROM posts;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE SpaceRadar (id INT, country VARCHAR(50), year INT, satellites INT); INSERT INTO SpaceRadar (id, country, year, satellites) VALUES (1, 'USA', 2000, 10), (2, 'China', 2005, 8), (3, 'Russia', 1995, 12);
|
What is the earliest year in which a country launched a satellite in the SpaceRadar table?
|
SELECT country, MIN(year) AS earliest_year FROM SpaceRadar GROUP BY country;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE id_mine_productivity (year INT, productivity FLOAT); INSERT INTO id_mine_productivity (year, productivity) VALUES (2018, 1.9), (2019, 2.1); CREATE TABLE id_mine_safety (year INT, accident_rate FLOAT); INSERT INTO id_mine_safety (year, accident_rate) VALUES (2018, 0.015), (2019, 0.017);
|
List labor productivity and accident rates for Indonesian mining operations in 2018 and 2019.
|
SELECT id_mine_productivity.productivity, id_mine_safety.accident_rate FROM id_mine_productivity INNER JOIN id_mine_safety ON id_mine_productivity.year = id_mine_safety.year WHERE id_mine_productivity.year IN (2018, 2019);
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE fleet (id INT, type TEXT, model TEXT, year INT, last_maintenance DATE); INSERT INTO fleet (id, type, model, year, last_maintenance) VALUES (1, 'bus', 'Artic', 2015, '2022-01-01'), (2, 'bus', 'Midi', 2018, '2022-02-01'), (3, 'tram', 'Cantrib', 2010, '2022-03-01'), (4, 'train', 'EMU', 2000, '2022-04-01');
|
What is the total number of 'bus' and 'tram' vehicles in the 'fleet' table that are in need of maintenance?
|
SELECT type, COUNT(*) as count FROM fleet WHERE type IN ('bus', 'tram') AND last_maintenance < DATEADD(year, -1, CURRENT_TIMESTAMP) GROUP BY type;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE cities (id INT, name VARCHAR(50)); INSERT INTO cities (id, name) VALUES (1, 'Dallas'), (2, 'Houston'); CREATE TABLE schools (id INT, name VARCHAR(50), city_id INT); INSERT INTO schools (id, name, city_id) VALUES (1, 'School A', 1), (2, 'School B', 1), (3, 'School C', 2);
|
How many public schools are in the city of Dallas?
|
SELECT COUNT(*) FROM schools WHERE city_id = (SELECT id FROM cities WHERE name = 'Dallas');
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE customer_complaints (id INT, state VARCHAR(50), complaint_date DATE, complaint_type VARCHAR(50));
|
What is the number of customer complaints received in each state in the last month?
|
SELECT state, COUNT(*) FROM customer_complaints WHERE complaint_date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH) GROUP BY state;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE community(id INT, name VARCHAR(255), population INT, language VARCHAR(255), representative BOOLEAN);
|
Add a new column representative to the community table and update values
|
ALTER TABLE community ADD COLUMN representative BOOLEAN;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE retailers (id INT, name VARCHAR(50), country VARCHAR(50)); INSERT INTO retailers (id, name, country) VALUES (1, 'Retailer A', 'Kenya'), (2, 'Retailer B', 'Kenya'), (3, 'Retailer C', 'USA'); CREATE TABLE circular_economy (id INT, retailer_id INT, recycled_materials BOOLEAN); INSERT INTO circular_economy (id, retailer_id, recycled_materials) VALUES (1, 1, true), (2, 2, false), (3, 3, false);
|
How many retailers in Kenya offer recycled materials?
|
SELECT r.name, COUNT(CE.recycled_materials) as num_retailers FROM circular_economy CE JOIN retailers r ON CE.retailer_id = r.id WHERE r.country = 'Kenya' AND CE.recycled_materials = true GROUP BY r.name;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Members (MemberID INT, Name VARCHAR(50), Age INT, Gender VARCHAR(50), Smartwatch BOOLEAN); INSERT INTO Members (MemberID, Name, Age, Gender, Smartwatch) VALUES (1, 'John Doe', 30, 'Male', TRUE); INSERT INTO Members (MemberID, Name, Age, Gender, Smartwatch) VALUES (2, 'Jane Smith', 35, 'Female', FALSE); CREATE TABLE Workouts (WorkoutID INT, WorkoutType VARCHAR(50), MemberID INT, Smartwatch BOOLEAN); INSERT INTO Workouts (WorkoutID, WorkoutType, MemberID, Smartwatch) VALUES (1, 'Strength Training', 1, TRUE); INSERT INTO Workouts (WorkoutID, WorkoutType, MemberID, Smartwatch) VALUES (2, 'Yoga', 2, FALSE);
|
What is the average age of male members who own a smartwatch and performed a strength training workout?
|
SELECT AVG(Members.Age) FROM Members INNER JOIN Workouts ON Members.MemberID = Workouts.MemberID WHERE Members.Gender = 'Male' AND Members.Smartwatch = TRUE AND Workouts.WorkoutType = 'Strength Training';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE broadband_plans (plan_id INT, speed FLOAT, state VARCHAR(20)); INSERT INTO broadband_plans (plan_id, speed, state) VALUES (1, 150, 'Texas'), (2, 120, 'California'), (3, 200, 'Texas'), (4, 100, 'Texas');
|
What is the minimum speed of the broadband plans for customers living in the state of Texas?
|
SELECT MIN(speed) FROM broadband_plans WHERE state = 'Texas';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE initiatives (launch_date DATE); INSERT INTO initiatives (launch_date) VALUES ('2021-10-01'), ('2021-11-15'), ('2021-01-05'), ('2021-12-20'), ('2021-04-22');
|
How many open data initiatives were launched in Q4 2021?
|
SELECT COUNT(*) FROM initiatives WHERE launch_date BETWEEN '2021-10-01' AND '2021-12-31' AND EXTRACT(QUARTER FROM launch_date) = 4;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE well_production (well_name VARCHAR(50), location VARCHAR(50), rate FLOAT); INSERT INTO well_production (well_name, location, rate) VALUES ('Well A', 'Barnett Shale', 1000), ('Well B', 'Barnett Shale', 1200);
|
What is the average production rate for wells in the Barnett Shale?
|
SELECT AVG(rate) FROM well_production WHERE location = 'Barnett Shale';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE defense_projects (id INT, project_name VARCHAR(50), start_date DATE, end_date DATE, revenue FLOAT); INSERT INTO defense_projects (id, project_name, start_date, end_date, revenue) VALUES (1, 'Project A', '2020-01-01', '2023-12-31', 10000000);
|
What was the total revenue for defense projects with a duration over 24 months as of Q4 2022?
|
SELECT SUM(revenue) FROM defense_projects WHERE DATEDIFF(end_date, start_date) > 24 AND quarter = 'Q4' AND year = 2022;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE startup (id INT, name TEXT, industry TEXT, exit_strategy TEXT);
|
How many startups have exited via an IPO in the Biotech sector?
|
SELECT COUNT(*) FROM startup WHERE industry = 'Biotech' AND exit_strategy = 'IPO';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE attorneys (attorney_id INT, years_of_experience INT); INSERT INTO attorneys (attorney_id, years_of_experience) VALUES (1, 12), (2, 8), (3, 15), (4, 20); CREATE TABLE cases (case_id INT, attorney_id INT); INSERT INTO cases (case_id, attorney_id) VALUES (1, 1), (2, 3), (3, 4), (4, 2);
|
How many cases were handled by attorneys with more than 10 years of experience?
|
SELECT COUNT(*) FROM cases INNER JOIN attorneys ON cases.attorney_id = attorneys.attorney_id WHERE attorneys.years_of_experience > 10;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE wildlife_habitat (id INT, continent VARCHAR(255), country VARCHAR(255), region VARCHAR(255), habitat_type VARCHAR(255), area FLOAT); INSERT INTO wildlife_habitat (id, continent, country, region, habitat_type, area) VALUES (1, 'Africa', 'Kenya', 'East Africa', 'Forest', 12345.12), (2, 'Africa', 'Tanzania', 'East Africa', 'Savannah', 23456.12);
|
What is the total wildlife habitat area, in square kilometers, for each type of habitat in Africa?
|
SELECT habitat_type, SUM(area) FROM wildlife_habitat WHERE continent = 'Africa' GROUP BY habitat_type;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Artworks (artwork_id INT, artwork_name VARCHAR(50), runtime INT, gallery_name VARCHAR(50)); INSERT INTO Artworks (artwork_id, artwork_name, runtime, gallery_name) VALUES (1, 'Un Chien Andalou', 16, 'Surrealism'), (2, 'The Seashell and the Clergyman', 67, 'Surrealism');
|
What is the total runtime of all movies in the 'Surrealism' gallery?
|
SELECT SUM(runtime) FROM Artworks WHERE gallery_name = 'Surrealism';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Astronauts (id INT, name VARCHAR(255), gender VARCHAR(10), agency VARCHAR(255), missions INT); INSERT INTO Astronauts (id, name, gender, agency, missions) VALUES (1, 'Eileen Collins', 'Female', 'NASA', 4), (2, 'Yi So-yeon', 'Female', 'Korea Aerospace Research Institute', 1);
|
Who are the female astronauts with the most missions for each agency?
|
SELECT name, agency, missions, RANK() OVER (PARTITION BY agency ORDER BY missions DESC) as mission_rank FROM Astronauts WHERE gender = 'Female';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE criminal_cases (case_id INT PRIMARY KEY, client_name VARCHAR(255), attorney_id INT, case_outcome VARCHAR(50));
|
Delete all cases from the 'criminal_cases' table where the case outcome is 'not guilty' and the attorney's ID is 458.
|
DELETE FROM criminal_cases WHERE case_outcome = 'not guilty' AND attorney_id = 458;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE warehouses (id INT, location VARCHAR(255), weight INT); INSERT INTO warehouses (id, location, weight) VALUES (1, 'Houston', 1000), (2, 'New York', 2000), (3, 'Tokyo', 3000);
|
What is the total weight of items in the warehouse located in Tokyo?
|
SELECT SUM(weight) FROM warehouses WHERE location = 'Tokyo';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE students (student_id INT, mental_health_score INT, participated_in_lifelong_learning BOOLEAN); INSERT INTO students (student_id, mental_health_score, participated_in_lifelong_learning) VALUES (1, 80, FALSE), (2, 70, FALSE), (3, 90, TRUE), (4, 60, FALSE);
|
What is the number of students who have a higher mental health score than the average mental health score of students who have not participated in lifelong learning activities?
|
SELECT COUNT(*) FROM students s1 WHERE s1.mental_health_score > (SELECT AVG(s2.mental_health_score) FROM students s2 WHERE s2.participated_in_lifelong_learning = FALSE);
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE garment_sales (sales_id INT PRIMARY KEY, garment_id INT, store_id INT, quantity INT, price DECIMAL(5,2), date DATE); CREATE TABLE garments (garment_id INT PRIMARY KEY, garment_name TEXT, garment_category TEXT, sustainability_score INT); INSERT INTO garments (garment_id, garment_name, garment_category, sustainability_score) VALUES (1, 'Cotton Shirt', 'Tops', 80), (2, 'Denim Jeans', 'Bottoms', 60), (3, 'Silk Scarf', 'Accessories', 90);
|
What is the total quantity of garments sold per garment category?
|
SELECT g.garment_category, SUM(gs.quantity) as total_quantity FROM garment_sales gs JOIN garments g ON gs.garment_id = g.garment_id GROUP BY g.garment_category;
|
gretelai_synthetic_text_to_sql
|
CREATE SCHEMA if not exists higher_ed;CREATE TABLE if not exists higher_ed.faculty(id INT, name VARCHAR(255), department VARCHAR(255), grant_amount DECIMAL(10,2));
|
What is the maximum research grant amount awarded in the Engineering department?
|
SELECT MAX(grant_amount) FROM higher_ed.faculty WHERE department = 'Engineering';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE sustainable_urbanism (property_id INT, size FLOAT, location VARCHAR(255)); INSERT INTO sustainable_urbanism (property_id, size, location) VALUES (1, 1200, 'Eco City'), (2, 1500, 'Green Valley');
|
What is the average property size in the sustainable_urbanism table?
|
SELECT AVG(size) FROM sustainable_urbanism;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Astronauts (Astronaut_ID INT, Name VARCHAR(255), Country VARCHAR(255));
|
Insert a new astronaut 'Hiroshi Tanaka' from Japan.
|
INSERT INTO Astronauts (Name, Country) VALUES ('Hiroshi Tanaka', 'Japan');
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE conservation_initiatives (country VARCHAR(20), start_year INT, end_year INT, num_initiatives INT); INSERT INTO conservation_initiatives (country, start_year, end_year, num_initiatives) VALUES ('Canada', 2015, 2018, 120);
|
How many water conservation initiatives were implemented in Canada between 2015 and 2018?
|
SELECT num_initiatives FROM conservation_initiatives WHERE country = 'Canada' AND start_year <= 2018 AND end_year >= 2015;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE IngredientSources (ProductID INT, Ingredient VARCHAR(50), SourceCountry VARCHAR(50), PRIMARY KEY (ProductID, Ingredient)); INSERT INTO IngredientSources (ProductID, Ingredient, SourceCountry) VALUES (1, 'Water', 'Canada'), (1, 'Glycerin', 'UK'), (2, 'Water', 'Mexico'), (2, 'Glycerin', 'France'); CREATE TABLE CrueltyFreeCertifications (ProductID INT, CertificationDate DATE, Certifier VARCHAR(50), PRIMARY KEY (ProductID, CertificationDate)); INSERT INTO CrueltyFreeCertifications (ProductID, CertificationDate, Certifier) VALUES (1, '2020-12-01', 'Leaping Bunny'), (2, '2021-03-01', 'PETA');
|
Which cruelty-free certified products use ingredients sourced from the UK and France?
|
SELECT ProductID FROM IngredientSources WHERE SourceCountry IN ('UK', 'France') GROUP BY ProductID HAVING COUNT(DISTINCT SourceCountry) = 2 INTERSECT SELECT ProductID FROM CrueltyFreeCertifications;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE investments (investment_id INT, company_id INT, sector VARCHAR(20), investment_amount FLOAT); INSERT INTO investments (investment_id, company_id, sector, investment_amount) VALUES (101, 1, 'renewable_energy', 50000), (102, 2, 'sustainable_agriculture', 75000), (103, 3, 'green_transportation', 60000);
|
Calculate the average investment amount for companies in the 'renewable_energy' sector.
|
SELECT AVG(investment_amount) FROM investments WHERE sector = 'renewable_energy';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE student_mental_health_scores (student_id INT, mental_health_score INT, date DATE); INSERT INTO student_mental_health_scores (student_id, mental_health_score, date) VALUES (1, 75, '2022-01-01'), (1, 85, '2022-02-01'), (2, 88, '2022-01-01'), (2, 90, '2022-02-01'), (3, 68, '2022-01-01'), (3, 73, '2022-02-01'), (4, 70, '2022-01-01'), (4, 75, '2022-02-01'), (5, 72, '2022-01-01'), (5, 82, '2022-02-01');
|
What is the number of students who have improved their mental health score by more than 10 points?
|
SELECT COUNT(DISTINCT student_id) as num_students_improved FROM (SELECT student_id, mental_health_score, LAG(mental_health_score) OVER (PARTITION BY student_id ORDER BY date) as previous_mental_health_score FROM student_mental_health_scores) subquery WHERE mental_health_score > previous_mental_health_score + 10;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE OrganicCottonSales (product_id INT, product_name VARCHAR(255), sale_date DATE, revenue DECIMAL(10,2)); INSERT INTO OrganicCottonSales (product_id, product_name, sale_date, revenue) VALUES (1, 'Organic Cotton T-Shirt', '2021-01-02', 25.99), (2, 'Organic Cotton Hoodie', '2021-01-03', 49.99);
|
What is the total revenue of organic cotton products in the USA?
|
SELECT SUM(revenue) FROM OrganicCottonSales WHERE sale_date BETWEEN '2021-01-01' AND '2021-12-31' AND product_name LIKE '%Organic Cotton%' AND country = 'USA';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE ticket_sales (sale_id INT, user_id INT, concert_name VARCHAR(255), quantity INT, total_price DECIMAL(5,2), date_purchased DATE);
|
Update the ticket price of concert 'Rock the Bay' in 'ticket_sales' table to $120.
|
UPDATE ticket_sales SET ticket_price = 120 WHERE concert_name = 'Rock the Bay';
|
gretelai_synthetic_text_to_sql
|
CREATE VIEW sales_data AS SELECT o.order_id, c.customer_gender, g.garment_size, g.garment_type, g.price, g.quantity, o.order_date FROM orders o JOIN customers c ON o.customer_id = c.customer_id JOIN order_items oi ON o.order_id = oi.order_id JOIN garments g ON oi.garment_id = g.garment_id;
|
List the total quantity of garments sold, by size and gender, from the 'sales_data' view, for the month of April 2022.
|
SELECT customer_gender, garment_size, SUM(quantity) FROM sales_data WHERE EXTRACT(MONTH FROM order_date) = 4 GROUP BY customer_gender, garment_size;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE funding (id INT, program VARCHAR(50), country VARCHAR(50), amount INT); INSERT INTO funding (id, program, country, amount) VALUES (1, 'Indigenous Arts Program', 'Canada', 50000);
|
What is the total amount of funding received by Indigenous art programs in Canada?
|
SELECT SUM(amount) FROM funding WHERE program = 'Indigenous Arts Program' AND country = 'Canada';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE ConcertGenre (ConcertID INT, GenreID INT); INSERT INTO ConcertGenre VALUES (7, 3), (8, 1), (9, 2), (13, 5);
|
What is the maximum ticket price for concerts in the 'Hip Hop' genre?
|
SELECT MAX(TicketPrice) FROM Concerts JOIN ConcertGenre ON Concerts.ConcertID = ConcertGenre.ConcertID JOIN Genre ON ConcertGenre.GenreID = Genre.GenreID WHERE Genre.Genre = 'Hip Hop';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Sales (id INT, product_id INT, size VARCHAR(10), quantity INT, sale_date DATE); INSERT INTO Sales (id, product_id, size, quantity, sale_date) VALUES (1, 1, '2XL', 5, '2022-05-01'), (2, 2, 'XS', 3, '2022-05-15');
|
What is the total quantity of size 2XL clothing sold in the last month?
|
SELECT SUM(quantity) FROM Sales WHERE size = '2XL' AND sale_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE marine_species (id INTEGER, scientific_name TEXT, common_name TEXT); INSERT INTO marine_species (id, scientific_name, common_name) VALUES (1, 'Loligo opalescens', 'California market squid'); INSERT INTO marine_species (id, scientific_name, common_name) VALUES (2, 'Lepidochelys kempii', 'Atlantic ridley sea turtle');
|
Delete the record for the species "Atlantic ridley sea turtle" from the marine_species table.
|
DELETE FROM marine_species WHERE common_name = 'Atlantic ridley sea turtle';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE makeup_sales (id INT, brand VARCHAR(50), category VARCHAR(50), sales INT, country VARCHAR(50)); INSERT INTO makeup_sales (id, brand, category, sales, country) VALUES (1, 'Elate Cosmetics', 'Eye Shadow', 200, 'UK');
|
Which cruelty-free makeup brands are most popular in the UK?
|
SELECT brand, SUM(sales) FROM makeup_sales WHERE category IN ('Lipstick', 'Mascara', 'Eye Shadow') AND country = 'UK' AND brand NOT IN ('Brand A', 'Brand B') GROUP BY brand ORDER BY SUM(sales) DESC;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE players (player_id INT, name VARCHAR(100), position VARCHAR(50), team_id INT); CREATE TABLE teams (team_id INT, name VARCHAR(100), city VARCHAR(100)); INSERT INTO teams (team_id, name, city) VALUES (1, 'Boston Bruins', 'Boston'), (2, 'New York Rangers', 'New York'), (3, 'Seattle Kraken', 'Seattle');
|
Insert records of 2 new players for team 'Seattle Kraken'
|
INSERT INTO players (player_id, name, position, team_id) VALUES (6, 'Sofia Garcia', 'Forward', 3), (7, 'Hiroshi Tanaka', 'Defense', 3);
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Customers (CustomerID int, IncomeLevel varchar(50), Location varchar(50)); INSERT INTO Customers (CustomerID, IncomeLevel, Location) VALUES (1, 'Low Income', 'Latin America'); CREATE TABLE Loans (LoanID int, CustomerID int, Type varchar(50), SociallyResponsible bit); INSERT INTO Loans (LoanID, CustomerID, Type, SociallyResponsible) VALUES (1, 1, 'Personal Loan', 1); CREATE TABLE Accounts (AccountID int, CustomerID int, Balance decimal(10,2)); INSERT INTO Accounts (AccountID, CustomerID, Balance) VALUES (1, 1, 500.00);
|
What is the average account balance of low-income borrowers in Latin America who have taken out socially responsible loans?
|
SELECT AVG(A.Balance) FROM Accounts A INNER JOIN Customers C ON A.CustomerID = C.CustomerID INNER JOIN Loans L ON C.CustomerID = L.CustomerID WHERE C.Location = 'Latin America' AND C.IncomeLevel = 'Low Income' AND L.SociallyResponsible = 1;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE mine (id INT, name TEXT, location TEXT, eia_date DATE); INSERT INTO mine (id, name, location, eia_date) VALUES (1, 'Emerald Edge', 'OR', '2021-04-01'), (2, 'Sapphire Slope', 'WA', '2021-06-15'), (3, 'Ruby Ridge', 'ID', '2020-12-31'), (4, 'Topaz Terrace', 'UT', '2021-08-30'), (5, 'Amethyst Acre', 'NV', '2022-02-14');
|
List mines with environmental impact assessments conducted in 2021
|
SELECT name FROM mine WHERE EXTRACT(YEAR FROM eia_date) = 2021;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE SpacecraftManufacturing (id INT, company VARCHAR(255), mass FLOAT); INSERT INTO SpacecraftManufacturing (id, company, mass) VALUES (1, 'Aerospace Inc.', 5000.0), (2, 'Galactic Corp.', 7000.0), (3, 'Space Tech', 6500.0);
|
Which spacecraft have a mass greater than 6000 tons?
|
SELECT * FROM SpacecraftManufacturing WHERE mass > 6000;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE artists (id INT, name VARCHAR(50), is_traditional_artist BOOLEAN);CREATE TABLE artist_event (id INT, artist_id INT, event_date DATE);
|
Find the percentage of traditional artists who have engaged in community events in the last 12 months?
|
SELECT 100.0 * COUNT(DISTINCT CASE WHEN artist_event.event_date >= DATEADD(year, -1, GETDATE()) THEN artists.id END) / COUNT(DISTINCT artists.id) as pct_last_12_months FROM artists LEFT JOIN artist_event ON artists.id = artist_event.artist_id;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE customer_preferences (customer_preference_id INT, customer_id INT, preference VARCHAR(20), created_at TIMESTAMP);
|
Insert a new record into the customer_preferences table for a customer who prefers vegan options
|
INSERT INTO customer_preferences (customer_id, preference, created_at) VALUES (1, 'Vegan', NOW());
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE investments (investment_id INT, sector VARCHAR(20), investment_amount DECIMAL(10,2)); INSERT INTO investments (investment_id, sector, investment_amount) VALUES (1, 'Real Estate', 250000.00), (2, 'Technology', 500000.00);
|
What is the total investment amount for the real estate sector?
|
SELECT SUM(investment_amount) FROM investments WHERE sector = 'Real Estate';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE shipping_routes (id INT, departure_country VARCHAR(50), arrival_country VARCHAR(50), departure_region VARCHAR(50), arrival_region VARCHAR(50), transportation_method VARCHAR(50), quantity FLOAT); INSERT INTO shipping_routes (id, departure_country, arrival_country, departure_region, arrival_region, transportation_method, quantity) VALUES (1, 'United States', 'Canada', 'Pacific', 'Pacific', 'Ship', 5000.3);
|
What is the average quantity of goods, in metric tons, shipped from the United States to Canada via the Pacific Ocean?
|
SELECT AVG(quantity) FROM shipping_routes WHERE departure_country = 'United States' AND arrival_country = 'Canada' AND departure_region = 'Pacific' AND arrival_region = 'Pacific' AND transportation_method = 'Ship';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE product (product_id INT, product_name TEXT); CREATE TABLE ingredient (ingredient_id INT, product_id INT, weight FLOAT, cruelty_free BOOLEAN); INSERT INTO product VALUES (1, 'Lipstick'), (2, 'Moisturizer'); INSERT INTO ingredient VALUES (1, 1, 50.0, true), (2, 1, 25.0, false), (3, 2, 30.0, true);
|
What is the total weight of cruelty-free ingredients for each product?
|
SELECT p.product_name, SUM(i.weight) FROM product p JOIN ingredient i ON p.product_id = i.product_id WHERE i.cruelty_free = true GROUP BY p.product_name;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE students (id INT, region TEXT, start_year INT); INSERT INTO students (id, region, start_year) VALUES (1, 'Nigeria', 2019), (2, 'Brazil', 2020);
|
Update the start year of the student with id 2 to 2022.
|
UPDATE students SET start_year = 2022 WHERE id = 2;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE bookings (booking_id INT, hotel_id INT, booking_date DATE, booking_channel TEXT); INSERT INTO bookings (booking_id, hotel_id, booking_date, booking_channel) VALUES (1, 1, '2022-04-01', 'OTA'), (2, 2, '2022-05-15', 'Direct'), (3, 1, '2022-06-30', 'OTA'); CREATE TABLE hotels (hotel_id INT, region TEXT); INSERT INTO hotels (hotel_id, region) VALUES (1, 'Northeast'), (2, 'West Coast');
|
How many bookings were made through OTA channels for each region in Q2 of 2022?
|
SELECT region, COUNT(*) FROM bookings b JOIN hotels h ON b.hotel_id = h.hotel_id WHERE EXTRACT(QUARTER FROM booking_date) = 2 AND booking_channel = 'OTA' GROUP BY region;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE AircraftManufacturing (id INT, company VARCHAR(50), manufacture_year INT, quantity INT); INSERT INTO AircraftManufacturing (id, company, manufacture_year, quantity) VALUES (1, 'Boeing', 2010, 200), (2, 'Boeing', 2015, 250), (3, 'Airbus', 2017, 300), (4, 'Airbus', 2018, 350), (5, 'Embraer', 2020, 200);
|
What is the distribution of aircraft manufacturing by company and year?
|
SELECT company, manufacture_year, SUM(quantity) as total_aircrafts FROM AircraftManufacturing GROUP BY company, manufacture_year;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE developers (developer_id INT, developer_name VARCHAR(100), developer_country VARCHAR(50), date_of_birth DATE, assets_value FLOAT); CREATE TABLE assets (asset_id INT, developer_id INT, asset_name VARCHAR(100), asset_value FLOAT); INSERT INTO developers VALUES (1, 'Han', 'China', '1988-07-08', 5000); INSERT INTO developers VALUES (2, 'Kim', 'South Korea', '1991-03-20', 3000); INSERT INTO assets VALUES (1, 1, 'Asset1', 1500); INSERT INTO assets VALUES (2, 1, 'Asset2', 2000); INSERT INTO assets VALUES (3, 2, 'Asset3', 2500);
|
Show the total value of digital assets owned by developers from Asia in June 2022.
|
SELECT d.developer_country, SUM(assets_value) as total_value FROM developers d JOIN assets a ON d.developer_id = a.developer_id WHERE d.date_of_birth BETWEEN '1980-01-01' AND '2000-12-31' AND d.developer_country IN ('China', 'South Korea', 'India', 'Japan', 'Singapore') AND a.assets_value IS NOT NULL GROUP BY d.developer_country;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE sales (sale_id INT, product_id INT, sale_amount DECIMAL(5,2)); INSERT INTO sales (sale_id, product_id, sale_amount) VALUES (1, 1, 25.99), (2, 2, 19.99), (3, 3, 39.99), (4, 1, 25.99); CREATE TABLE products (product_id INT, is_fair_trade BOOLEAN); INSERT INTO products (product_id, is_fair_trade) VALUES (1, TRUE), (2, FALSE), (3, FALSE), (4, TRUE);
|
What is the total revenue generated from fair trade products?
|
SELECT SUM(sale_amount) FROM sales JOIN products ON sales.product_id = products.product_id WHERE products.is_fair_trade = TRUE;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE flights(flight_id INT, origin TEXT, destination TEXT, year INT, distance INT, CO2_emissions INT);INSERT INTO flights (flight_id, origin, destination, year, distance, CO2_emissions) VALUES (1, 'Sydney', 'Auckland', 2019, 2166, 108300), (2, 'Melbourne', 'Wellington', 2019, 1972, 98600), (3, 'Brisbane', 'Christchurch', 2019, 2235, 111750), (4, 'Adelaide', 'Queenstown', 2019, 2446, 122300), (5, 'Perth', 'Dunedin', 2019, 3882, 194100);
|
What is the total CO2 emissions for flights between Australia and New Zealand in 2019?
|
SELECT SUM(CO2_emissions) FROM flights WHERE origin IN ('Sydney', 'Melbourne', 'Brisbane', 'Adelaide', 'Perth') AND destination IN ('Auckland', 'Wellington', 'Christchurch', 'Queenstown', 'Dunedin') AND year = 2019;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Claims (ClaimID INT, PolicyType VARCHAR(20), ProcessingDepartment VARCHAR(20), ProcessingDate DATE, ClaimAmount INT); INSERT INTO Claims (ClaimID, PolicyType, ProcessingDepartment, ProcessingDate, ClaimAmount) VALUES (1, 'Auto', 'Claims', '2023-01-10', 5000), (2, 'Home', 'Risk Assessment', '2023-02-15', 20000);
|
What is the total claim amount for policy type 'Auto' in the Claims department for all time?
|
SELECT PolicyType, SUM(ClaimAmount) as TotalClaimAmount FROM Claims WHERE ProcessingDepartment = 'Claims' AND PolicyType = 'Auto' GROUP BY PolicyType;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE us_battery_storage (storage_type VARCHAR(20), capacity INT); INSERT INTO us_battery_storage (storage_type, capacity) VALUES ('Utility-scale Batteries', 25000), ('Pumped Hydro Storage', 150000);
|
Compare the energy storage capacities of utility-scale batteries and pumped hydro storage systems in the United States.
|
SELECT capacity FROM us_battery_storage WHERE storage_type = 'Utility-scale Batteries' INTERSECT SELECT capacity FROM us_battery_storage WHERE storage_type = 'Pumped Hydro Storage';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE user_activity (id INT, user_id INT, activity_type VARCHAR(50), activity_date DATE, followers INT); INSERT INTO user_activity (id, user_id, activity_type, activity_date, followers) VALUES (1, 1, 'Followers Gained', '2022-03-01', 50), (2, 2, 'Followers Lost', '2022-03-02', -30), (3, 3, 'Followers Gained', '2022-03-03', 25), (4, 4, 'Followers Lost', '2022-03-04', -10), (5, 5, 'Followers Gained', '2022-03-05', 40); CREATE TABLE users (id INT, country VARCHAR(50)); INSERT INTO users (id, country) VALUES (1, 'India'), (2, 'India'), (3, 'India'), (4, 'India'), (5, 'India');
|
Show the total number of followers gained and lost by users from India, grouped by month.
|
SELECT DATE_FORMAT(activity_date, '%Y-%m') as month, SUM(CASE WHEN activity_type = 'Followers Gained' THEN followers ELSE -followers END) as net_followers FROM user_activity JOIN users ON user_activity.user_id = users.id WHERE users.country = 'India' GROUP BY month;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE tourism_stats (id INT PRIMARY KEY, year INT, country VARCHAR(255), destination VARCHAR(255), duration INT); INSERT INTO tourism_stats (id, year, country, destination, duration) VALUES (1, 2022, 'USA', 'France', 7), (2, 2022, 'USA', 'Italy', 10), (3, 2022, 'USA', 'Spain', 5);
|
What is the minimum trip duration for American tourists visiting Europe in 2022?
|
SELECT MIN(duration) FROM tourism_stats WHERE country = 'USA' AND destination LIKE 'Europe%' AND year = 2022;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Excavation_Sites (id INT PRIMARY KEY, name VARCHAR(255), location TEXT, country VARCHAR(255)); INSERT INTO Excavation_Sites (id, name, location, country) VALUES (1, 'Pompeii', 'Near Naples, Italy', 'Italy');
|
Insert data about an excavation site into the Excavation_Sites table
|
INSERT INTO Excavation_Sites (id, name, location, country) VALUES (2, 'Machu Picchu', 'Andes Mountains, Peru', 'Peru');
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Smoking (ID INT, Country VARCHAR(100), Year INT, SmokerPercentage FLOAT); INSERT INTO Smoking (ID, Country, Year, SmokerPercentage) VALUES (1, 'Japan', 2020, 17.8);
|
What is the percentage of smokers in Japan?
|
SELECT SmokerPercentage FROM Smoking WHERE Country = 'Japan' AND Year = 2020;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Diversification (id INT, project VARCHAR(255), country VARCHAR(255), year INT, cost FLOAT); INSERT INTO Diversification (id, project, country, year, cost) VALUES (1, 'Agro-Processing Plant', 'Morocco', 2015, 4000000), (2, 'Tourism Complex', 'Egypt', 2017, 8000000), (3, 'Textile Factory', 'Tunisia', 2016, 5000000), (4, 'IT Hub', 'Algeria', 2018, 9000000);
|
What was the total cost of economic diversification projects in the 'Diversification' table implemented in 2016 or earlier, for projects in 'Africa'?
|
SELECT SUM(cost) as total_cost FROM Diversification WHERE year <= 2016 AND country LIKE 'Africa%';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Missions (MissionID INT, Name VARCHAR(100), Destination VARCHAR(50), Duration FLOAT);
|
What is the average duration of all missions to Mars?
|
SELECT AVG(Duration) FROM Missions WHERE Destination = 'Mars';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Vessels (id INT, name TEXT, speed FLOAT, flag_country TEXT, arrive_port TEXT, arrive_date DATE); INSERT INTO Vessels (id, name, speed, flag_country, arrive_port, arrive_date) VALUES (1, 'Vessel1', 24.5, 'Nigeria', 'Port L', '2019-01-25'); INSERT INTO Vessels (id, name, speed, flag_country, arrive_port, arrive_date) VALUES (2, 'Vessel2', 26.0, 'Nigeria', 'Port L', '2019-02-22');
|
Find the average speed of Nigerian-flagged vessels traveling to Port L in the last 10 days of each month in 2019.
|
SELECT arrive_port, AVG(speed) FROM Vessels WHERE flag_country = 'Nigeria' AND arrive_port = 'Port L' AND DATE_TRUNC('month', arrive_date) = DATE_TRUNC('month', arrive_date - INTERVAL '10 days') AND EXTRACT(YEAR FROM arrive_date) = 2019 GROUP BY arrive_port;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE hospitals (id INT, name TEXT, location TEXT); INSERT INTO hospitals (id, name, location) VALUES (1, 'Hospital A', 'Rural Texas'); INSERT INTO hospitals (id, name, location) VALUES (2, 'Hospital B', 'Rural California'); INSERT INTO hospitals (id, name, location) VALUES (3, 'Hospital C', 'Rural New York');
|
What is the number of hospitals in rural areas of Texas, California, and New York?
|
SELECT COUNT(*) FROM hospitals WHERE location IN ('Rural Texas', 'Rural California', 'Rural New York');
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE southeast_offsets (id INT, program_name TEXT, region TEXT, offset_amount INT); INSERT INTO southeast_offsets (id, program_name, region, offset_amount) VALUES (1, 'GreenTrees', 'Southeast', 12000), (2, 'Carbonfund', 'Southeast', 18000), (3, 'TerraPass', 'Southeast', 24000);
|
Show carbon offset programs in the 'Southeast' region and their respective offset amounts
|
SELECT program_name, offset_amount FROM southeast_offsets WHERE region = 'Southeast';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE artists (artist_id INT, name VARCHAR(50), age INT, country VARCHAR(50)); INSERT INTO artists (artist_id, name, age, country) VALUES (1, 'Pablo Picasso', 91, 'Spain'); INSERT INTO artists (artist_id, name, age, country) VALUES (2, 'Francis Bacon', 82, 'Ireland'); INSERT INTO artists (artist_id, name, age, country) VALUES (3, 'Piet Mondrian', 71, 'Netherlands'); CREATE TABLE countries (country VARCHAR(50), continent VARCHAR(50)); INSERT INTO countries (country, continent) VALUES ('Spain', 'Europe'); INSERT INTO countries (country, continent) VALUES ('Ireland', 'Europe'); INSERT INTO countries (country, continent) VALUES ('Netherlands', 'Europe');
|
How many artists in the 'artists' table are from each continent?
|
SELECT c.continent, COUNT(a.artist_id) as num_artists FROM artists a JOIN countries c ON a.country = c.country GROUP BY c.continent;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE military_bases (id INT, name VARCHAR(50), country VARCHAR(50)); INSERT INTO military_bases (id, name, country) VALUES (1, 'Fort Bragg', 'USA'), (2, 'Camp Pendleton', 'USA'), (3, 'Canberra Deep Space Communication Complex', 'Australia');
|
What is the total number of military bases and their respective countries?
|
SELECT COUNT(*) as total_bases, country FROM military_bases GROUP BY country;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE arctic_animal_sightings (id INT, date DATE, animal VARCHAR(255)); INSERT INTO arctic_animal_sightings (id, date, animal) VALUES (1, '2021-01-01', 'Polar Bear'), (2, '2021-02-01', 'Walrus'), (3, '2021-03-01', 'Fox');
|
How many different animals were observed in the 'arctic_animal_sightings' table for each month?
|
SELECT MONTH(date) AS month, COUNT(DISTINCT animal) AS animal_count FROM arctic_animal_sightings GROUP BY month;
|
gretelai_synthetic_text_to_sql
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.