context
stringlengths
11
9.12k
question
stringlengths
0
1.06k
SQL
stringlengths
2
4.44k
source
stringclasses
28 values
CREATE TABLE Visitor_Log (Visitor_ID INT, Visit_Date DATE); INSERT INTO Visitor_Log (Visitor_ID, Visit_Date) VALUES (1001, '2022-01-01'), (1002, '2022-01-02'), (1003, '2022-01-03'), (1001, '2022-01-04');
Find the number of visitors who have visited the museum more than once in the last month.
SELECT COUNT(DISTINCT Visitor_ID) FROM Visitor_Log WHERE Visitor_ID IN (SELECT Visitor_ID FROM Visitor_Log GROUP BY Visitor_ID HAVING COUNT(DISTINCT Visit_Date) > 1) AND Visit_Date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH);
gretelai_synthetic_text_to_sql
CREATE TABLE player_sessions (id INT, player_name TEXT, playtime INT); INSERT INTO player_sessions (id, player_name, playtime) VALUES (1, 'Olivia', 120); INSERT INTO player_sessions (id, player_name, playtime) VALUES (2, 'Olivia', 150); INSERT INTO player_sessions (id, player_name, playtime) VALUES (3, 'William', 200);
What is the average playtime for all players?
SELECT AVG(playtime) FROM player_sessions;
gretelai_synthetic_text_to_sql
CREATE TABLE Permits (PermitID int, Type varchar(20), Date date); INSERT INTO Permits (PermitID, Type, Date) VALUES (1, 'Residential', '2021-01-01'); INSERT INTO Permits (PermitID, Type, Date) VALUES (2, 'Commercial', '2021-01-10'); INSERT INTO Permits (PermitID, Type, Date) VALUES (3, 'Residential', '2021-02-15');
What is the maximum and minimum number of building permits issued per month in the last year?
SELECT MIN(Count) AS MinCount, MAX(Count) AS MaxCount FROM (SELECT COUNT(*) AS Count FROM Permits WHERE Date >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR) GROUP BY DATE_FORMAT(Date, '%Y-%m')) AS PermitCounts;
gretelai_synthetic_text_to_sql
CREATE TABLE drug_sales (sale_id INT, drug_name VARCHAR(255), year INT, sales INT); INSERT INTO drug_sales (sale_id, drug_name, year, sales) VALUES (1, 'DrugA', 2018, 5000000), (2, 'DrugB', 2019, 7000000), (3, 'DrugC', 2020, 8000000);
Delete the sales record for DrugA in 2019.
DELETE FROM drug_sales WHERE drug_name = 'DrugA' AND year = 2019;
gretelai_synthetic_text_to_sql
CREATE TABLE fans (fan_id INT, team_id INT, gender VARCHAR(50)); INSERT INTO fans VALUES (1, 1, 'Female'), (2, 1, 'Male'), (3, 2, 'Female'), (4, 2, 'Female'), (5, 3, 'Male');
Which team has the most fans?
SELECT te.team_name, COUNT(f.fan_id) as num_fans FROM fans f JOIN teams te ON f.team_id = te.team_id GROUP BY te.team_id ORDER BY num_fans DESC LIMIT 1;
gretelai_synthetic_text_to_sql
CREATE TABLE users (user_id INT, username VARCHAR(50)); CREATE TABLE posts (post_id INT, user_id INT, hashtags VARCHAR(50)); INSERT INTO users (user_id, username) VALUES (1, 'user1'), (2, 'user2'), (3, 'user3'); INSERT INTO posts (post_id, user_id, hashtags) VALUES (1, 1, '#Travel'), (2, 1, '#Food'), (3, 2, '#Travel'), (4, 3, '#Travel'), (5, 3, '#Music');
List the usernames and number of posts for users who have posted more than 50 times on a specific hashtag (#Travel)
SELECT users.username, COUNT(posts.post_id) AS post_count FROM users INNER JOIN posts ON users.user_id = posts.user_id WHERE FIND_IN_SET('#Travel', posts.hashtags) > 0 GROUP BY users.username HAVING post_count > 50;
gretelai_synthetic_text_to_sql
CREATE TABLE rd_expenditures (company TEXT, year INT, amount FLOAT); INSERT INTO rd_expenditures (company, year, amount) VALUES ('AstraZeneca', 2020, 22000000), ('Novartis', 2020, 16000000);
Find the ratio of R&D expenditures between 'AstraZeneca' and 'Novartis'.
SELECT (SELECT SUM(amount) FROM rd_expenditures WHERE company = 'AstraZeneca' AND year = 2020) / (SELECT SUM(amount) FROM rd_expenditures WHERE company = 'Novartis' AND year = 2020);
gretelai_synthetic_text_to_sql
CREATE TABLE HumanitarianAssistance (Organization VARCHAR(50), Year INT, Amount DECIMAL(10,2)); INSERT INTO HumanitarianAssistance (Organization, Year, Amount) VALUES ('UNHCR', 2020, 1500000), ('WFP', 2020, 2000000), ('RedCross', 2020, 1200000), ('CARE', 2020, 1800000);
What is the total amount of humanitarian assistance provided by each organization in 2020?
SELECT Organization, SUM(Amount) AS TotalAssistance FROM HumanitarianAssistance WHERE Year = 2020 GROUP BY Organization;
gretelai_synthetic_text_to_sql
CREATE TABLE properties (property_id INT, city VARCHAR(50), size INT); INSERT INTO properties (property_id, city, size) VALUES (1, 'Portland', 1500), (2, 'Seattle', 1200), (3, 'Portland', 1800), (4, 'Oakland', 1000);
What is the total property size for properties in each city?
SELECT city, SUM(size) FROM properties GROUP BY city;
gretelai_synthetic_text_to_sql
CREATE TABLE Property (id INT PRIMARY KEY, address VARCHAR(255), city VARCHAR(255), state VARCHAR(255), zip INT, co_owners INT, sustainable_features VARCHAR(255), price INT); CREATE TABLE AffordableHousing (id INT PRIMARY KEY, property_id INT, program_name VARCHAR(255), beds INT, square_feet INT); CREATE TABLE InclusiveHousing (id INT PRIMARY KEY, property_id INT, policy_type VARCHAR(255), start_date DATE, end_date DATE);
Which properties are part of both affordable housing and inclusive housing programs?
SELECT Property.address, Property.city, Property.state, Property.zip, Property.co_owners, Property.sustainable_features, Property.price FROM Property INNER JOIN AffordableHousing ON Property.id = AffordableHousing.property_id INNER JOIN InclusiveHousing ON Property.id = InclusiveHousing.property_id;
gretelai_synthetic_text_to_sql
CREATE TABLE grad_students (id INT, name VARCHAR(50), country VARCHAR(50));CREATE TABLE papers (id INT, paper_id INT, title VARCHAR(100), year INT, author_id INT);
What is the number of graduate students from African countries who have published 2 or more academic papers in the last 3 years?
SELECT COUNT(DISTINCT gs.id) FROM grad_students gs JOIN papers p ON gs.id = p.author_id WHERE gs.country IN (SELECT name FROM countries WHERE region = 'Africa') AND p.year BETWEEN YEAR(CURRENT_DATE) - 3 AND YEAR(CURRENT_DATE) GROUP BY gs.id HAVING COUNT(DISTINCT p.paper_id) >= 2;
gretelai_synthetic_text_to_sql
CREATE TABLE Spacecraft (id INT, name VARCHAR(50), country VARCHAR(50), launch_date DATE); INSERT INTO Spacecraft (id, name, country, launch_date) VALUES (1, 'Falcon 9', 'USA', '2010-06-04'); INSERT INTO Spacecraft (id, name, country, launch_date) VALUES (2, 'Soyuz-FG', 'Russia', '2001-11-02'); INSERT INTO Spacecraft (id, name, country, launch_date) VALUES (3, 'Long March 3B', 'China', '1996-02-19'); CREATE TABLE Satellites (id INT, name VARCHAR(50), type VARCHAR(50), spacecraft_id INT); INSERT INTO Satellites (id, name, type, spacecraft_id) VALUES (1, 'TESS', 'Observation', 1); INSERT INTO Satellites (id, name, type, spacecraft_id) VALUES (2, 'MetOp-C', 'Weather', 2); INSERT INTO Satellites (id, name, type, spacecraft_id) VALUES (3, 'Chinasat 18', 'Communication', 3);
What is the name and type of all satellites launched by spacecraft that were launched after the year 2010?
SELECT s.name, s.type FROM Satellites s JOIN Spacecraft sp ON s.spacecraft_id = sp.id WHERE sp.launch_date > '2010-01-01';
gretelai_synthetic_text_to_sql
CREATE TABLE Employees (EmployeeID INT, FirstName VARCHAR(50), LastName VARCHAR(50));CREATE TABLE Maintenance (MaintenanceID INT, EmployeeID INT, MaintenanceType VARCHAR(50), MaintenanceHours DECIMAL(10,2));CREATE VIEW EmployeeMaintenance AS SELECT EmployeeID, FirstName, LastName, ROW_NUMBER() OVER (PARTITION BY EmployeeID ORDER BY MaintenanceHours DESC) AS MaintenanceRank FROM Employees E JOIN Maintenance M ON E.EmployeeID = M.EmployeeID;
Which employee has been involved in the most maintenance activities, and what is their total involvement in terms of maintenance hours?
SELECT FirstName, LastName, MaintenanceRank, SUM(MaintenanceHours) AS TotalMaintenanceHours FROM EmployeeMaintenance GROUP BY FirstName, LastName, MaintenanceRank ORDER BY TotalMaintenanceHours DESC FETCH FIRST 1 ROW ONLY;
gretelai_synthetic_text_to_sql
CREATE TABLE buses (id INT, city VARCHAR(20)); INSERT INTO buses (id, city) VALUES (1, 'London'), (2, 'Manchester'); CREATE TABLE bus_fares (id INT, bus_id INT, fare DECIMAL(5,2), fare_date DATE); INSERT INTO bus_fares (id, bus_id, fare, fare_date) VALUES (1, 1, 3.50, '2022-01-01'), (2, 1, 3.75, '2022-01-03'), (3, 2, 2.00, '2022-01-05');
What is the total fare collected for buses in the city of London in the past week?
SELECT SUM(bf.fare) FROM bus_fares bf JOIN buses b ON bf.bus_id = b.id WHERE b.city = 'London' AND bf.fare_date >= DATEADD(week, -1, GETDATE());
gretelai_synthetic_text_to_sql
CREATE TABLE disaster_response (disaster_name VARCHAR(255), country VARCHAR(255), operation_start_date DATE, operation_end_date DATE); INSERT INTO disaster_response (disaster_name, country, operation_start_date, operation_end_date) VALUES ('Flood', 'Pakistan', '2018-01-01', '2018-04-30'), ('Earthquake', 'Pakistan', '2018-10-01', '2018-12-31');
What was the number of disaster response operations in Pakistan in 2018?
SELECT COUNT(*) FROM disaster_response WHERE country = 'Pakistan' AND YEAR(operation_start_date) = 2018 AND YEAR(operation_end_date) = 2018;
gretelai_synthetic_text_to_sql
CREATE TABLE rural_clinics (clinic_location VARCHAR(255), patient_wait_time INT); INSERT INTO rural_clinics (clinic_location, patient_wait_time) VALUES ('Location1', 15), ('Location1', 20), ('Location2', 10), ('Location2', 12), ('Location3', 25), ('Location3', 30);
Calculate the average patient wait time, partitioned by clinic location, in the "rural_clinics" table with patient wait time data.
SELECT clinic_location, AVG(patient_wait_time) OVER (PARTITION BY clinic_location) FROM rural_clinics;
gretelai_synthetic_text_to_sql
CREATE TABLE teams (team_id INT, team_name TEXT, league TEXT); INSERT INTO teams (team_id, team_name, league) VALUES (1, 'Golden State Warriors', 'NBA'), (2, 'Los Angeles Lakers', 'NBA'); CREATE TABLE games (game_id INT, team_id INT, points INT); INSERT INTO games (game_id, team_id, points) VALUES (1, 1, 110), (2, 1, 105), (3, 2, 120), (4, 2, 130);
What is the total number of points scored by the 'Golden State Warriors' and 'Los Angeles Lakers' in the 'NBA'?
SELECT SUM(points) FROM games WHERE team_id IN (SELECT team_id FROM teams WHERE team_name IN ('Golden State Warriors', 'Los Angeles Lakers')) AND league = 'NBA';
gretelai_synthetic_text_to_sql
CREATE TABLE green_buildings (property_id INT, address VARCHAR(255), city VARCHAR(255), state VARCHAR(255), certification_date DATE);
Update the city name to 'San Francisco' for records in the 'green_buildings' table with a 'certification_date' earlier than 2010
UPDATE green_buildings SET city = 'San Francisco' WHERE certification_date < '2010-01-01';
gretelai_synthetic_text_to_sql
CREATE TABLE transportation (id INT, mode VARCHAR(50), tourists INT); INSERT INTO transportation (id, mode, tourists) VALUES (1, 'Plane', 15000), (2, 'Train', 3000), (3, 'Car', 5000), (4, 'Bus', 2000), (5, 'Bike', 100);
What is the most common mode of transportation for international tourists?
SELECT mode, RANK() OVER (ORDER BY tourists DESC) as rank FROM transportation;
gretelai_synthetic_text_to_sql
CREATE TABLE military_bases (id INT PRIMARY KEY, base_name VARCHAR(100), status VARCHAR(20)); INSERT INTO military_bases (id, base_name, status) VALUES (1, 'Ramstein', 'inactive');
Update military_bases table, set status to 'active' where base_name is 'Ramstein'
UPDATE military_bases SET status = 'active' WHERE base_name = 'Ramstein';
gretelai_synthetic_text_to_sql
CREATE TABLE well_completion_costs (id INT, well_name VARCHAR(50), location VARCHAR(50), cost FLOAT); INSERT INTO well_completion_costs (id, well_name, location, cost) VALUES (1, 'Well A', 'Caspian Sea', 5000000), (2, 'Well B', 'Caspian Sea', 7000000);
Sum of well completion costs for wells in the Caspian Sea.
SELECT SUM(cost) FROM well_completion_costs WHERE location = 'Caspian Sea';
gretelai_synthetic_text_to_sql
CREATE TABLE Authors (AuthorID INT, Name VARCHAR(50), Age INT, Gender VARCHAR(10), LastBookPublished DATE);
What is the average age of all female authors who have published a book in the last 5 years?
SELECT AVG(Age) FROM Authors WHERE Gender = 'Female' AND LastBookPublished >= DATEADD(year, -5, GETDATE());
gretelai_synthetic_text_to_sql
CREATE TABLE Projects (id INT, name TEXT, country TEXT, cost FLOAT); INSERT INTO Projects (id, name, country, cost) VALUES (1, 'ProjectA', 'CountryX', 2000000.00), (2, 'ProjectB', 'CountryY', 2500500.75), (3, 'ProjectC', 'CountryZ', 1800000.50), (4, 'ProjectD', 'CountryA', 3000000.00); CREATE TABLE Countries (id INT, name TEXT, continent TEXT); INSERT INTO Countries (id, name, continent) VALUES (1, 'CountryX', 'Africa'), (2, 'CountryY', 'Africa'), (3, 'CountryZ', 'Europe'), (4, 'CountryA', 'Africa');
What is the maximum construction cost of public works projects in the 'Africa' continent?
SELECT MAX(cost) FROM Projects INNER JOIN Countries ON Projects.country = Countries.name WHERE Countries.continent = 'Africa';
gretelai_synthetic_text_to_sql
CREATE TABLE public_works (id INT, name VARCHAR(50), location VARCHAR(50), year INT, cost FLOAT);
Find the top 3 locations with the highest average project cost in the 'public_works' table, partitioned by year.
SELECT location, AVG(cost) as avg_cost, ROW_NUMBER() OVER (PARTITION BY year ORDER BY AVG(cost) DESC) as rn FROM public_works GROUP BY location, year ORDER BY year, avg_cost DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE Machines (MachineID INT, MachineType VARCHAR(50), Manufacturer VARCHAR(50), PurchaseDate DATE, PurchasePrice DECIMAL(10,2), Department VARCHAR(50)); INSERT INTO Machines (MachineID, MachineType, Manufacturer, PurchaseDate, PurchasePrice, Department) VALUES (1, 'CNC', 'ABC Machining', '2018-01-01', 150000.00, 'Manufacturing'); INSERT INTO Machines (MachineID, MachineType, Manufacturer, PurchaseDate, PurchasePrice, Department) VALUES (2, 'Robot', 'XYZ Automation', '2019-06-15', 200000.00, 'Manufacturing');
List the machines in the Manufacturing department that were purchased after January 1, 2019 and their purchase prices.
SELECT MachineType, PurchasePrice FROM Machines WHERE Department = 'Manufacturing' AND PurchaseDate > '2019-01-01';
gretelai_synthetic_text_to_sql
CREATE TABLE country_targets (country TEXT, year INT, emissions_target FLOAT); INSERT INTO country_targets (country, year, emissions_target) VALUES ('Canada', 2020, 500000);
Which countries have exceeded their historical emissions targets as of 2020? (alternative)
SELECT country FROM country_targets WHERE year = 2020 AND emissions_target < (SELECT emissions FROM country_emissions WHERE country = country_targets.country AND year = 2020);
gretelai_synthetic_text_to_sql
CREATE TABLE Artworks (artwork_id INT, name VARCHAR(255), artist_id INT, date_sold DATE, price DECIMAL(10,2)); CREATE TABLE Artists (artist_id INT, name VARCHAR(255), gender VARCHAR(255));
Who are the top 3 most prolific female artists in the 21st century?
SELECT Artists.name, COUNT(Artworks.artwork_id) as count FROM Artists INNER JOIN Artworks ON Artists.artist_id = Artworks.artist_id WHERE Artists.gender = 'Female' AND YEAR(Artworks.date_sold) >= 2000 GROUP BY Artists.name ORDER BY count DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE player_daily_playtime_v2 (player_id INT, play_date DATE, playtime INT); INSERT INTO player_daily_playtime_v2 (player_id, play_date, playtime) VALUES (4, '2021-02-01', 150), (4, '2021-02-02', 250), (4, '2021-02-03', 350), (5, '2021-02-01', 450), (5, '2021-02-02', 550), (5, '2021-02-03', 650);
What is the average playtime per day for each player in 'player_daily_playtime_v2'?
SELECT player_id, AVG(playtime) FROM player_daily_playtime_v2 GROUP BY player_id;
gretelai_synthetic_text_to_sql
CREATE TABLE unions (id INT, name VARCHAR(255), state VARCHAR(255)); CREATE TABLE union_industry (id INT, union_id INT, industry VARCHAR(255), workers INT); INSERT INTO unions (id, name, state) VALUES (1, 'LiUNA', 'California'); INSERT INTO union_industry (id, union_id, industry, workers) VALUES (1, 1, 'Construction', 300);
What is the maximum number of workers in each union by industry in California?
SELECT ui.industry, MAX(ui.workers) as max_workers FROM union_industry ui JOIN unions u ON ui.union_id = u.id WHERE u.state = 'California' GROUP BY ui.industry;
gretelai_synthetic_text_to_sql
CREATE TABLE elephants (elephant_id INT, elephant_name VARCHAR(50), age INT, weight FLOAT, sanctuary VARCHAR(50)); INSERT INTO elephants (elephant_id, elephant_name, age, weight, sanctuary) VALUES (1, 'Elephant_1', 12, 3000, 'African Savanna'); INSERT INTO elephants (elephant_id, elephant_name, age, weight, sanctuary) VALUES (2, 'Elephant_2', 8, 2500, 'African Savanna');
What is the minimum age of adult elephants in the 'African Savanna' sanctuary?
SELECT MIN(age) FROM elephants WHERE sanctuary = 'African Savanna' AND age >= 18;
gretelai_synthetic_text_to_sql
CREATE TABLE Employees (EmployeeID INT, Department VARCHAR(20), Age INT, TechnicalTraining BOOLEAN); INSERT INTO Employees (EmployeeID, Department, Age, TechnicalTraining) VALUES (1, 'IT', 30, 1), (2, 'HR', 35, 0), (3, 'IT', 28, 1);
What is the average age of employees in the IT department who have completed technical training?
SELECT Department, AVG(Age) FROM Employees WHERE Department = 'IT' AND TechnicalTraining = 1 GROUP BY Department;
gretelai_synthetic_text_to_sql
CREATE TABLE pacificsalmon (country VARCHAR(20), location VARCHAR(30), max_sustainable_yield FLOAT); INSERT INTO pacificsalmon (country, location, max_sustainable_yield) VALUES ('Canada', 'British Columbia', 50000), ('USA', 'Washington', 40000);
What is the maximum sustainable yield of salmon in the Pacific Ocean off the coast of British Columbia, Canada?
SELECT max_sustainable_yield FROM pacificsalmon WHERE country = 'Canada' AND location = 'British Columbia';
gretelai_synthetic_text_to_sql
CREATE TABLE housing_data (id INT, address VARCHAR(255), city VARCHAR(255), state VARCHAR(255), square_footage INT, sustainable_features VARCHAR(255)); INSERT INTO housing_data (id, address, city, state, square_footage, sustainable_features) VALUES (1, '123 Maple St', 'San Francisco', 'CA', 1200, 'solar panels'), (2, '456 Oak St', 'Austin', 'TX', 1500, 'none'), (3, '789 Pine St', 'Seattle', 'WA', 1800, 'green roof');
What is the total square footage of properties with sustainable features in the 'housing_data' table?
SELECT SUM(square_footage) FROM housing_data WHERE sustainable_features IS NOT NULL;
gretelai_synthetic_text_to_sql
CREATE TABLE stevedoring (stevedoring_id INT, company VARCHAR(255), quarter INT, container_type VARCHAR(255), containers_handled INT);INSERT INTO stevedoring (stevedoring_id, company, quarter, container_type, containers_handled) VALUES (1, 'ABC', 3, 'dry', 5000), (2, 'ABC', 3, 'refrigerated', 3000), (3, 'XYZ', 3, 'dry', 4000), (4, 'XYZ', 3, 'refrigerated', 6000);
How many containers were handled by each stevedoring company in the third quarter of 2019, grouped by company and container type?
SELECT company, container_type, SUM(containers_handled) FROM stevedoring WHERE quarter = 3 GROUP BY company, container_type;
gretelai_synthetic_text_to_sql
CREATE TABLE Farming(country VARCHAR(255), year INT, species VARCHAR(255), production FLOAT);
Delete all records of farmed salmon in Scotland in 2022.
DELETE FROM Farming WHERE country = 'Scotland' AND species = 'Salmon' AND year = 2022;
gretelai_synthetic_text_to_sql
CREATE TABLE PsychologyInclusion (EffortID INT, Effort VARCHAR(50)); CREATE TABLE EnglishInclusion (EffortID INT, Effort VARCHAR(50)); INSERT INTO PsychologyInclusion VALUES (1, 'Mental Health Resources'), (2, 'Accessible Counseling'), (3, 'Diverse Research Opportunities'); INSERT INTO EnglishInclusion VALUES (2, 'Accessible Counseling'), (4, 'Writing Workshops');
Present the inclusion efforts in the Psychology faculty that are not available in the English faculty.
SELECT Effort FROM PsychologyInclusion WHERE Effort NOT IN (SELECT Effort FROM EnglishInclusion);
gretelai_synthetic_text_to_sql
CREATE TABLE SpeciesBiomass (species_name VARCHAR(50), species_id INT, biomass_mt NUMERIC(12,2), region VARCHAR(50), PRIMARY KEY(species_name, species_id)); INSERT INTO SpeciesBiomass (species_name, species_id, biomass_mt, region) VALUES ('Dolphin', 1, 456.25, 'Southern Ocean'), ('Whale', 2, 897.56, 'Southern Ocean');
What is the average biomass of dolphins in the Southern Ocean?
SELECT AVG(SpeciesBiomass.biomass_mt) FROM SpeciesBiomass WHERE SpeciesBiomass.species_name = 'Dolphin' AND SpeciesBiomass.region = 'Southern Ocean';
gretelai_synthetic_text_to_sql
CREATE TABLE users (user_id INT, app VARCHAR(20)); INSERT INTO users (user_id, app) VALUES (1, 'creative_ai'), (2, 'algorithmic_fairness'), (3, 'explainable_ai'); CREATE TABLE transactions (transaction_id INT, user_id INT, amount DECIMAL(10, 2)); INSERT INTO transactions (transaction_id, user_id, amount) VALUES (1, 1, 50.00), (2, 1, 75.00), (3, 2, 30.00), (4, 3, 100.00), (5, 1, 60.00);
What is the average transaction amount per user in the 'creative_ai' application?
SELECT AVG(amount) as avg_amount FROM transactions INNER JOIN users ON transactions.user_id = users.user_id WHERE users.app = 'creative_ai';
gretelai_synthetic_text_to_sql
CREATE TABLE customer_segments (customer_id INT, segment VARCHAR(20)); INSERT INTO customer_segments VALUES (1, 'High Value'); INSERT INTO customer_segments VALUES (2, 'Low Value'); INSERT INTO customer_segments VALUES (3, 'High Value'); CREATE VIEW customer_accounts AS SELECT c.customer_id, a.balance FROM accounts a JOIN customers c ON a.customer_id = c.customer_id;
Show total balances for customers in the 'High Value' segment
SELECT SUM(ca.balance) as total_balance FROM customer_accounts ca JOIN customer_segments cs ON ca.customer_id = cs.customer_id WHERE cs.segment = 'High Value';
gretelai_synthetic_text_to_sql
CREATE TABLE production (site_id INT, production_date DATE, quantity INT);
Determine the three-month moving average of production at each manufacturing site.
SELECT site_id, AVG(quantity) OVER (PARTITION BY site_id ORDER BY production_date ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) as moving_avg FROM production;
gretelai_synthetic_text_to_sql
CREATE TABLE sanctuary_d (animal_id INT, animal_name VARCHAR(50), population INT); INSERT INTO sanctuary_d VALUES (1, 'tiger', 25); INSERT INTO sanctuary_d VALUES (2, 'elephant', 30); INSERT INTO sanctuary_d VALUES (3, 'monkey', 35); INSERT INTO sanctuary_d VALUES (4, 'lion', 40);
What is the total number of animals in all sanctuaries?
SELECT SUM(population) FROM sanctuary_d;
gretelai_synthetic_text_to_sql
CREATE TABLE electric_vehicles (vehicle_id INT, license_plate TEXT, registration_date DATE, last_maintenance_date DATE, vehicle_type TEXT, distance_traveled_km FLOAT);
What is the total distance traveled by electric vehicles in Los Angeles in the last month?
SELECT SUM(distance_traveled_km) FROM electric_vehicles WHERE vehicle_type = 'electric' AND registration_date < DATE_SUB(CURDATE(), INTERVAL 1 MONTH) AND license_plate LIKE 'CA-%';
gretelai_synthetic_text_to_sql
CREATE TABLE GallerySales (Gallery VARCHAR(255), ArtWork VARCHAR(255), Year INT, Revenue DECIMAL(10,2)); INSERT INTO GallerySales (Gallery, ArtWork, Year, Revenue) VALUES ('Gallery 1', 'Artwork 1', 2021, 500.00), ('Gallery 1', 'Artwork 2', 2021, 400.00), ('Gallery 2', 'Artwork 3', 2021, 750.00), ('Gallery 2', 'Artwork 4', 2021, 1000.00);
What was the total revenue for each gallery in 2021?
SELECT Gallery, SUM(Revenue) as TotalRevenue FROM GallerySales WHERE Year = 2021 GROUP BY Gallery;
gretelai_synthetic_text_to_sql
CREATE TABLE campaigns (campaign_id INT, launch_year INT, condition VARCHAR(50), country VARCHAR(50)); INSERT INTO campaigns (campaign_id, launch_year, condition, country) VALUES (1, 2015, 'Depression', 'USA'), (2, 2018, 'Anxiety', 'USA'), (3, 2020, 'Depression', 'USA');
How many depression awareness campaigns were launched in the United States between 2015 and 2020?
SELECT COUNT(*) FROM campaigns WHERE country = 'USA' AND condition = 'Depression' AND launch_year BETWEEN 2015 AND 2020;
gretelai_synthetic_text_to_sql
CREATE TABLE Audience (AudienceID INT, Age INT, Event TEXT); INSERT INTO Audience (AudienceID, Age, Event) VALUES (1, 30, 'Theater'), (2, 25, 'Theater'), (3, 40, 'Movie');
What is the average age of the audience members who attended the "Theater" event?
SELECT AVG(Age) FROM Audience WHERE Event = 'Theater';
gretelai_synthetic_text_to_sql
CREATE TABLE Games (GameID INT, GameType VARCHAR(255), ReleaseCountry VARCHAR(255), Playtime INT); INSERT INTO Games (GameID, GameType, ReleaseCountry, Playtime) VALUES (1, 'RPG', 'Egypt', 120); INSERT INTO Games (GameID, GameType, ReleaseCountry, Playtime) VALUES (2, 'Shooter', 'South Africa', 180); INSERT INTO Games (GameID, GameType, ReleaseCountry, Playtime) VALUES (3, 'Adventure', 'Morocco', 90);
What is the minimum playtime for any VR game in Africa?
SELECT MIN(Playtime) FROM Games WHERE ReleaseCountry LIKE '%Africa%';
gretelai_synthetic_text_to_sql
CREATE TABLE financial_capability (client_id INT, financial_literacy_score INT, country VARCHAR(50)); INSERT INTO financial_capability VALUES (4, 65, 'Indonesia');
Update the 'financial_capability' table to reflect an increase in the financial literacy score of a client in Indonesia.
UPDATE financial_capability SET financial_literacy_score = 70 WHERE client_id = 4 AND country = 'Indonesia';
gretelai_synthetic_text_to_sql
CREATE TABLE Vessels (VesselID INT, Name VARCHAR(255), Type VARCHAR(255), Flag VARCHAR(255)); CREATE TABLE PortVisits (VisitID INT, VesselID INT, Port VARCHAR(255), VisitDate DATE, Country VARCHAR(255)); INSERT INTO Vessels (VesselID, Name, Type, Flag) VALUES (1, 'European Trader', 'Cargo', 'EU'), (2, 'Atlantic Navigator', 'Cargo', 'EU'); INSERT INTO PortVisits (VisitID, VesselID, Port, VisitDate, Country) VALUES (1, 1, 'Amsterdam', '2022-01-02', 'Netherlands'), (2, 1, 'Paris', '2022-02-14', 'France'), (3, 2, 'Madrid', '2022-03-01', 'Spain'), (4, 2, 'Berlin', '2022-04-10', 'Germany');
Which vessels have visited ports in more than one country in Europe?
SELECT Vessels.Name FROM Vessels INNER JOIN PortVisits ON Vessels.VesselID = PortVisits.VesselID WHERE PortVisits.Country IN ('Netherlands', 'France', 'Spain', 'Germany') GROUP BY Vessels.Name HAVING COUNT(DISTINCT PortVisits.Country) > 1;
gretelai_synthetic_text_to_sql
CREATE TABLE Donors (DonorID INT, DonorName VARCHAR(50), DonationAmount DECIMAL(10,2)); INSERT INTO Donors (DonorID, DonorName, DonationAmount) VALUES (1, 'John Smith', 500), (2, 'Jane Doe', 750), (3, 'Bob Johnson', 1000), (4, 'Alice Williams', 1200), (5, 'Charlie Brown', 1500); CREATE TABLE DonationPrograms (DonationID INT, ProgramID INT); INSERT INTO DonationPrograms (DonationID, ProgramID) VALUES (1, 1), (2, 1), (1, 2), (3, 2), (4, 3), (5, 3), (5, 4);
Find the top 5 donors for the 'Arts' program?
SELECT D.DonorID, D.DonorName, SUM(D.DonationAmount) AS TotalDonated FROM Donors D JOIN DonationPrograms DP ON D.DonationID = DP.DonationID WHERE DP.ProgramID = (SELECT ProgramID FROM Programs WHERE ProgramName = 'Arts') GROUP BY D.DonorID, D.DonorName ORDER BY TotalDonated DESC LIMIT 5;
gretelai_synthetic_text_to_sql
CREATE TABLE tech_for_good (region TEXT, project TEXT, budget INTEGER); INSERT INTO tech_for_good (region, project, budget) VALUES ('East Africa', 'AI for Healthcare', 150000); INSERT INTO tech_for_good (region, project, budget) VALUES ('East Africa', 'AI for Education', 200000);
What is the total budget for AI projects in the 'east_africa' region in the 'tech_for_good' table?
SELECT SUM(budget) FROM tech_for_good WHERE region = 'East Africa';
gretelai_synthetic_text_to_sql
CREATE TABLE clients (client_id INT, client_name TEXT, region TEXT, financial_wellbeing_score DECIMAL);
What is the average financial wellbeing score for clients in the Middle East?
SELECT AVG(financial_wellbeing_score) FROM clients WHERE region = 'Middle East';
gretelai_synthetic_text_to_sql
CREATE TABLE CuisineTypes (CuisineTypeID INT, CuisineType VARCHAR(50));CREATE TABLE Dishes (DishID INT, DishName VARCHAR(50), CuisineTypeID INT, CaloricContent INT, HasCaloricInfo BOOLEAN); INSERT INTO CuisineTypes VALUES (1, 'Italian'), (2, 'Chinese'), (3, 'Indian'); INSERT INTO Dishes VALUES (1, 'Pizza Margherita', 1, 500, true), (2, 'Spaghetti Bolognese', 1, 700, true), (3, 'Kung Pao Chicken', 2, 600, true), (4, 'Spring Rolls', 2, NULL, false), (5, 'Butter Chicken', 3, 800, true), (6, 'Palak Paneer', 3, 600, true);
What is the average caloric content of dishes in each cuisine type, excluding dishes with no caloric information?
SELECT ct.CuisineType, AVG(d.CaloricContent) as AvgCaloricContent FROM CuisineTypes ct JOIN Dishes d ON ct.CuisineTypeID = d.CuisineTypeID WHERE d.HasCaloricInfo = true GROUP BY ct.CuisineType;
gretelai_synthetic_text_to_sql
CREATE TABLE agricultural_innovation (innovation_id INT, innovation_name TEXT, region TEXT, investment_amount INT, year INT); INSERT INTO agricultural_innovation (innovation_id, innovation_name, region, investment_amount, year) VALUES (1, 'Drought-Resistant Crops', 'Africa', 2000000, 2020); INSERT INTO agricultural_innovation (innovation_id, innovation_name, region, investment_amount, year) VALUES (2, 'Precision Farming', 'Asia', 3000000, 2021);
What is the total investment in agricultural innovation in 'Africa' up to 2021?
SELECT SUM(investment_amount) FROM agricultural_innovation WHERE year <= 2021 AND region = 'Africa';
gretelai_synthetic_text_to_sql
CREATE TABLE sales(sale_id INT, product_id INT, retailer_id INT, quantity INT, sale_date DATE); INSERT INTO sales(sale_id, product_id, retailer_id, quantity, sale_date) VALUES (1, 1, 101, 10, '2022-01-01'), (2, 2, 101, 15, '2022-01-02'), (3, 3, 102, 5, '2022-01-03');
Insert new records of products sold to a retailer
INSERT INTO sales(sale_id, product_id, retailer_id, quantity, sale_date) VALUES (4, 4, 101, 8, '2022-01-04'), (5, 5, 102, 12, '2022-01-05'), (6, 6, 103, 7, '2022-01-06');
gretelai_synthetic_text_to_sql
CREATE TABLE production_data (id INT, date DATE, coal_production INT, gold_production INT); INSERT INTO production_data (id, date, coal_production, gold_production) VALUES (1, '2022-01-01', 200, 10); INSERT INTO production_data (id, date, coal_production, gold_production) VALUES (2, '2022-01-02', 250, 15);
What is the maximum amount of coal extracted in a single day in the 'production_data' table?
SELECT MAX(coal_production) as max_coal_production FROM production_data;
gretelai_synthetic_text_to_sql
CREATE TABLE AircraftFlightHours (AircraftID INT, Model VARCHAR(50), Manufacturer VARCHAR(50), FlightHours INT); INSERT INTO AircraftFlightHours (AircraftID, Model, Manufacturer, FlightHours) VALUES (1, '747', 'Boeing', 55000); INSERT INTO AircraftFlightHours (AircraftID, Model, Manufacturer, FlightHours) VALUES (2, 'A320', 'Airbus', 35000); INSERT INTO AircraftFlightHours (AircraftID, Model, Manufacturer, FlightHours) VALUES (3, 'CRJ', 'Bombardier', 20000);
Calculate the average flight hours for each aircraft model, partitioned by manufacturer.
SELECT Model, Manufacturer, AVG(FlightHours) OVER (PARTITION BY Manufacturer) AS Avg_Flight_Hours_By_Manufacturer FROM AircraftFlightHours;
gretelai_synthetic_text_to_sql
CREATE TABLE Attorneys (AttorneyID INT, Name VARCHAR(50), Wins INT, Losses INT); INSERT INTO Attorneys (AttorneyID, Name, Wins, Losses) VALUES (1, 'John Doe', 10, 2), (2, 'Jane Smith', 15, 5); CREATE TABLE Cases (CaseID INT, AttorneyID INT, CaseType VARCHAR(50)); INSERT INTO Cases (CaseID, AttorneyID, CaseType) VALUES (1, 1, 'Criminal'), (2, 2, 'Criminal');
Who are the attorneys with a win rate greater than 70% in criminal cases?
SELECT Name FROM Attorneys WHERE (Wins / (Wins + Losses)) * 100 > 70 AND AttorneyID IN (SELECT AttorneyID FROM Cases WHERE CaseType = 'Criminal');
gretelai_synthetic_text_to_sql
CREATE TABLE games (id INT, team TEXT, season INT, home_or_away TEXT, wins INT, losses INT); INSERT INTO games (id, team, season, home_or_away, wins, losses) VALUES (1, 'Team A', 2020, 'Home', 35, 10); INSERT INTO games (id, team, season, home_or_away, wins, losses) VALUES (2, 'Team B', 2020, 'Away', 28, 17);
What is the maximum number of games won by any team in a single season?
SELECT team, MAX(wins) FROM games GROUP BY team;
gretelai_synthetic_text_to_sql
CREATE TABLE OrganizationDonations (OrgID INT, DonationAmount INT, DonationYear INT); CREATE TABLE Organizations (OrgID INT, OrgName TEXT);
What's the avg. donation amount for each org in '2019'?
SELECT o.OrgName, AVG(od.DonationAmount) FROM OrganizationDonations od INNER JOIN Organizations o ON od.OrgID = o.OrgID WHERE od.DonationYear = 2019 GROUP BY o.OrgName;
gretelai_synthetic_text_to_sql
CREATE TABLE menu_engineering(menu_item VARCHAR(255), category VARCHAR(255), revenue DECIMAL(10,2), sustainable_source BOOLEAN); INSERT INTO menu_engineering VALUES ('Vegan Pizza', 'Vegan', 1200, TRUE); INSERT INTO menu_engineering VALUES ('Tofu Stir Fry', 'Vegan', 800, TRUE);
Which menu items in the vegan category have a revenue greater than $1000 in 2022?
SELECT menu_item FROM menu_engineering WHERE category = 'Vegan' AND revenue > 1000 AND YEAR(date) = 2022;
gretelai_synthetic_text_to_sql
CREATE TABLE protected_areas (id INT, name VARCHAR(50), location VARCHAR(50)); INSERT INTO protected_areas (id, name, location) VALUES (1, 'Yosemite National Park', 'North America');
List all the 'protected areas' in 'North America'
SELECT name FROM protected_areas WHERE location = 'North America' AND status = 'protected';
gretelai_synthetic_text_to_sql
CREATE TABLE marine_protected_areas (name text, depth integer); INSERT INTO marine_protected_areas (name, depth) VALUES ('Galapagos Islands', 2000), ('Great Barrier Reef', 1000);
Which marine protected areas have a depth greater than 1000 meters?
SELECT name FROM marine_protected_areas WHERE depth > 1000;
gretelai_synthetic_text_to_sql
CREATE TABLE faculty (faculty_id INT, name TEXT, department TEXT);CREATE TABLE grants (grant_id INT, faculty_id INT, funding_source TEXT, grant_date DATE, grant_amount INT); INSERT INTO faculty (faculty_id, name, department) VALUES (1, 'Alice', 'Computer Science'), (2, 'Bob', 'Computer Science'); INSERT INTO grants (grant_id, faculty_id, funding_source, grant_date, grant_amount) VALUES (1, 1, 'Google', '2022-01-01', 50000), (2, 2, 'Microsoft', '2021-01-01', 75000);
What is the total amount of research grants received by each faculty member in the 'Computer Science' department?
SELECT faculty.name, SUM(grants.grant_amount) AS total_grant_amount FROM faculty INNER JOIN grants ON faculty.faculty_id = grants.faculty_id WHERE faculty.department = 'Computer Science' GROUP BY faculty.name;
gretelai_synthetic_text_to_sql
CREATE TABLE project (id INT, name VARCHAR(50), location VARCHAR(50), start_date DATE); INSERT INTO project (id, name, location, start_date) VALUES (1, 'Green Build', 'NYC', '2020-01-01'), (2, 'Solar Tower', 'LA', '2019-12-15'), (3, 'Eco House', 'Austin', '2020-03-01'); CREATE TABLE labor (id INT, project_id INT, worker VARCHAR(50), hours FLOAT); INSERT INTO labor (id, project_id, worker, hours) VALUES (1, 1, 'John', 40), (2, 1, 'Jane', 35), (3, 2, 'Bob', 45), (4, 2, 'Alice', 50), (5, 3, 'Alex', 48), (6, 3, 'Nia', 42), (7, 3, 'Jamal', 55); CREATE TABLE sustainable (project_id INT, solar_panels BOOLEAN, wind_turbines BOOLEAN, green_roof BOOLEAN); INSERT INTO sustainable (project_id, solar_panels, wind_turbines, green_roof) VALUES (1, TRUE, FALSE, TRUE), (2, TRUE, TRUE, FALSE), (3, FALSE, FALSE, TRUE);
How many workers were involved in projects that have solar panels?
SELECT COUNT(DISTINCT l.project_id) AS num_workers FROM labor l JOIN sustainable s ON l.project_id = s.project_id WHERE s.solar_panels = TRUE;
gretelai_synthetic_text_to_sql
CREATE TABLE victims (id INT PRIMARY KEY, name VARCHAR(50), age INT, ethnicity VARCHAR(20), incident_date DATE);
Create a table named 'victims'
CREATE TABLE victims (id INT PRIMARY KEY, name VARCHAR(50), age INT, ethnicity VARCHAR(20), incident_date DATE);
gretelai_synthetic_text_to_sql
CREATE TABLE stations (station_id INT, name VARCHAR(255), latitude FLOAT, longitude FLOAT, region VARCHAR(5)); CREATE TABLE routes (route_id INT, name VARCHAR(255), start_station_id INT, end_station_id INT); CREATE VIEW stations_view AS SELECT station_id, name, latitude, longitude, 'North' AS region FROM stations WHERE latitude > 40 AND longitude < -70; SELECT * FROM stations WHERE latitude < 40 OR longitude > -70; CREATE TABLE trips (trip_id INT, route_id INT, start_time TIMESTAMP, end_time TIMESTAMP, total_fare FLOAT); CREATE VIEW recent_trips AS SELECT trip_id, route_id, start_time, total_fare FROM trips WHERE start_time > NOW() - INTERVAL '24 hour';
Show average total fare from "recent_trips" view.
SELECT AVG(total_fare) FROM recent_trips;
gretelai_synthetic_text_to_sql
CREATE TABLE singapore_taxis (id INT, taxi_id VARCHAR(20), start_time TIMESTAMP, end_time TIMESTAMP, autonomous BOOLEAN);
Identify the number of autonomous taxis in Singapore by hour.
SELECT DATE_FORMAT(start_time, '%Y-%m-%d %H') AS hour, COUNT(*) FROM singapore_taxis WHERE autonomous = TRUE GROUP BY hour;
gretelai_synthetic_text_to_sql
CREATE TABLE Products(id INT, name TEXT, material TEXT, is_sustainable BOOLEAN, is_fair_trade_certified BOOLEAN); INSERT INTO Products(id, name, material, is_sustainable, is_fair_trade_certified) VALUES (1, 'Shirt', 'Hemp', true, false), (2, 'Pants', 'Tencel', true, true), (3, 'Jacket', 'Recycled Polyester', true, true); CREATE TABLE Materials(id INT, name TEXT, is_sustainable BOOLEAN); INSERT INTO Materials(id, name, is_sustainable) VALUES (1, 'Hemp', true), (2, 'Tencel', true), (3, 'Recycled Polyester', true);
Add a new fair trade certified product 'Socks' to 'Products' table
INSERT INTO Products(id, name, material, is_sustainable, is_fair_trade_certified) VALUES (4, 'Socks', 'Organic Cotton', true, true);
gretelai_synthetic_text_to_sql
CREATE TABLE Player (Player_ID INT, Name VARCHAR(50), Date_Joined DATE); INSERT INTO Player (Player_ID, Name, Date_Joined) VALUES (1, 'John Doe', '2019-06-15'), (2, 'Jane Smith', '2020-03-08'), (3, 'Alice Johnson', '2021-02-22'), (4, 'Bob Brown', '2020-08-10');
Update player records to set the name 'Siti Rosli' if the Player_ID is 2 in the 'Player' table
UPDATE Player SET Name = 'Siti Rosli' WHERE Player_ID = 2;
gretelai_synthetic_text_to_sql
CREATE TABLE pro_bono_work (id INT, lawyer_name TEXT, hours_worked INT, region TEXT, work_year INT); INSERT INTO pro_bono_work (id, lawyer_name, hours_worked, region, work_year) VALUES (1, 'Mohammed Ahmed', 30, 'Southern', 2022); INSERT INTO pro_bono_work (id, lawyer_name, hours_worked, region, work_year) VALUES (2, 'Karen Nguyen', 25, 'Southern', 2022);
What is the average number of hours of pro bono work performed by lawyers in the Southern region in the past year?
SELECT AVG(hours_worked) FROM pro_bono_work WHERE region = 'Southern' AND work_year = 2022;
gretelai_synthetic_text_to_sql
CREATE TABLE military_equipment (equipment_id INT, region VARCHAR(10), maintenance_cost DECIMAL(10,2), maintenance_date DATE); INSERT INTO military_equipment VALUES (1, 'Africa', 3000.00, '2021-07-01'), (2, 'Europe', 2500.00, '2021-08-01'), (3, 'Africa', 4500.00, '2021-10-01');
What is the total maintenance cost for military equipment in the African region in the second half of 2021?
SELECT SUM(maintenance_cost) FROM military_equipment WHERE region = 'Africa' AND maintenance_date >= DATE '2021-07-01' AND maintenance_date < DATE '2022-01-01';
gretelai_synthetic_text_to_sql
CREATE TABLE students (id INT, hearing_impairment BOOLEAN, department VARCHAR(255)); INSERT INTO students (id, hearing_impairment, department) VALUES (1, true, 'engineering'), (2, false, 'engineering'), (3, true, 'engineering'), (4, false, 'engineering'); CREATE TABLE accommodations (id INT, student_id INT, year INT, cost DECIMAL(10,2)); INSERT INTO accommodations (id, student_id, year, cost) VALUES (1, 1, 2018, 500.00), (2, 1, 2019, 200.00), (3, 3, 2018, 300.00), (4, 3, 2019, 100.00), (5, 3, 2021, 400.00), (6, 4, 2020, 700.00);
What is the total cost of accommodations for students with hearing impairments in the engineering department in 2021?
SELECT SUM(cost) as total_cost FROM accommodations a INNER JOIN students s ON a.student_id = s.id WHERE s.hearing_impairment = true AND s.department = 'engineering' AND a.year = 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE news (title VARCHAR(255), author VARCHAR(255), age INT, category VARCHAR(255)); INSERT INTO news (title, author, age, category) VALUES ('Sample News', 'Mary Johnson', 45, 'Opinion');
Who is the oldest author in the 'opinion' category?
SELECT author FROM news WHERE category = 'Opinion' ORDER BY age DESC LIMIT 1;
gretelai_synthetic_text_to_sql
CREATE TABLE company_drilling_figures (company_id INT, drilling_date DATE);
List the number of wells drilled per drilling company in 2021
SELECT company_id, COUNT(*) as num_wells_drilled FROM company_drilling_figures WHERE drilling_date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY company_id;
gretelai_synthetic_text_to_sql
CREATE TABLE virtual_tours (tour_id INT, city TEXT, region TEXT, engagement FLOAT); INSERT INTO virtual_tours (tour_id, city, region, engagement) VALUES (1, 'Tokyo', 'APAC', 250.5), (2, 'Seoul', 'APAC', 300.7), (3, 'Osaka', 'APAC', 220.1), (4, 'Paris', 'EMEA', 350.2);
What is the average number of virtual tour engagements per city in 'APAC' region?
SELECT city, AVG(engagement) FROM virtual_tours WHERE region = 'APAC' GROUP BY city;
gretelai_synthetic_text_to_sql
CREATE TABLE historical_cities (name VARCHAR(50), year INT, population INT); INSERT INTO historical_cities (name, year, population) VALUES ('CityA', 2018, 750000), ('CityA', 2019, 760000), ('CityA', 2020, 770000), ('CityB', 2018, 600000), ('CityB', 2019, 605000), ('CityB', 2020, 610000), ('CityC', 2018, 550000), ('CityC', 2019, 555000), ('CityC', 2020, 560000);
What is the name of the city with the highest population growth rate in the last 3 years?
SELECT name FROM (SELECT name, (population-LAG(population) OVER (PARTITION BY name ORDER BY year))/(year-LAG(year) OVER (PARTITION BY name ORDER BY year)) as growth_rate FROM historical_cities WHERE year BETWEEN 2018 AND 2020) WHERE growth_rate = (SELECT MAX(growth_rate) FROM (SELECT name, (population-LAG(population) OVER (PARTITION BY name ORDER BY year))/(year-LAG(year) OVER (PARTITION BY name ORDER BY year)) as growth_rate FROM historical_cities WHERE year BETWEEN 2018 AND 2020));
gretelai_synthetic_text_to_sql
CREATE TABLE Projects (id INT, region VARCHAR(255), completion_time INT); INSERT INTO Projects (id, region, completion_time) VALUES (1, 'Southwest', 120), (2, 'Northeast', 150), (3, 'Southwest', 100);
What is the minimum time to complete a project in the Southwest?
SELECT MIN(completion_time) FROM Projects WHERE region = 'Southwest';
gretelai_synthetic_text_to_sql
CREATE TABLE media_ethics (id INT, topic TEXT, description TEXT, created_at DATE);
Insert a new record into the "media_ethics" table with the following details: id 8, topic "Freedom of the press", description "Importance of a free press in a democracy", created_at "2022-03-20"
INSERT INTO media_ethics (id, topic, description, created_at) VALUES (8, 'Freedom of the press', 'Importance of a free press in a democracy', '2022-03-20');
gretelai_synthetic_text_to_sql
CREATE TABLE plots (id INT, size_ha FLOAT, location TEXT, type TEXT); INSERT INTO plots (id, size_ha, location, type) VALUES (1, 2.5, 'Africa', 'Urban'); INSERT INTO plots (id, size_ha, location, type) VALUES (2, 1.8, 'Africa', 'Indigenous');
What is the minimum size (in hectares) of a plot in the 'plots' table, where the plot is used for indigenous food systems and is located in the 'Africa' region?
SELECT MIN(size_ha) FROM plots WHERE type = 'Indigenous' AND location = 'Africa';
gretelai_synthetic_text_to_sql
CREATE TABLE Designs(id INT, design_name VARCHAR(100), release_date DATE); INSERT INTO Designs(id, design_name, release_date) VALUES (1, 'Spring Dress', '2022-03-01'); INSERT INTO Designs(id, design_name, release_date) VALUES (2, 'Summer Shirt', '2022-05-15');
Show the number of new garment designs released per month in 2022.
SELECT DATEPART(month, release_date) AS Month, COUNT(*) AS DesignsReleased FROM Designs WHERE YEAR(release_date) = 2022 GROUP BY DATEPART(month, release_date);
gretelai_synthetic_text_to_sql
create table MachineEnergy (Machine varchar(255), Energy int, Shift int, Timestamp datetime); insert into MachineEnergy values ('Machine1', 50, 1, '2022-01-01 00:00:00'), ('Machine2', 70, 1, '2022-01-01 00:00:00'), ('Machine1', 60, 2, '2022-01-02 00:00:00');
What is the average energy consumption per machine per shift?
select Machine, Shift, AVG(Energy) as AvgEnergy from MachineEnergy group by Machine, Shift;
gretelai_synthetic_text_to_sql
CREATE TABLE unions (id INT, name TEXT, domain TEXT, members INT); INSERT INTO unions (id, name, domain, members) VALUES (1, 'United Auto Workers', 'Automobiles, Aerospace', 350000); INSERT INTO unions (id, name, domain, members) VALUES (2, 'United Steelworkers', 'Metals, Mining, Energy, Construction', 850000);
Update the number of members for the 'United Auto Workers' to 400,000.
UPDATE unions SET members = 400000 WHERE name = 'United Auto Workers';
gretelai_synthetic_text_to_sql
CREATE TABLE factories (factory_id INT, country VARCHAR(20), has_fair_labor BOOLEAN); INSERT INTO factories (factory_id, country, has_fair_labor) VALUES (1, 'Bangladesh', TRUE), (2, 'Cambodia', FALSE), (3, 'India', TRUE), (4, 'Vietnam', FALSE);
Which countries have the most factories with fair labor practices?
SELECT country, SUM(has_fair_labor) AS total_fair_labor FROM factories GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE practice_by_offense (offense_id INT, practice_id INT); CREATE TABLE restorative_practices (practice_id INT, practice VARCHAR(255));
What are the restorative practices unique to a specific offense type in the 'practice_by_offense' table?
SELECT practice FROM restorative_practices WHERE practice_id IN (SELECT practice_id FROM practice_by_offense GROUP BY practice_id HAVING COUNT(DISTINCT offense_id) = 1);
gretelai_synthetic_text_to_sql
CREATE TABLE sales (sale_id INT, sale_date DATE, sale_price DECIMAL(5,2));
What is the total revenue generated from sales in the 'sales' table, partitioned by month?
SELECT EXTRACT(MONTH FROM sale_date) as month, SUM(sale_price) FROM sales GROUP BY month;
gretelai_synthetic_text_to_sql
CREATE TABLE deliveries (id INT, order_id INT, delivery_time INT, transportation_mode VARCHAR(50)); INSERT INTO deliveries (id, order_id, delivery_time, transportation_mode) VALUES (1, 1001, 3, 'Air'), (2, 1002, 7, 'Road'), (3, 1003, 5, 'Rail'), (4, 1004, 2, 'Sea');
What is the average delivery time for each transportation mode?
SELECT transportation_mode, AVG(delivery_time) as avg_delivery_time FROM deliveries GROUP BY transportation_mode;
gretelai_synthetic_text_to_sql
CREATE TABLE military_sales (id INT PRIMARY KEY, region VARCHAR(20), year INT, equipment_name VARCHAR(30), quantity INT, value FLOAT);
Insert new records for 'Artillery' sales to 'South America' in the year '2026' with the quantity of 20 and value of 18000000
INSERT INTO military_sales (id, region, year, equipment_name, quantity, value) VALUES (4, 'South America', 2026, 'Artillery', 20, 18000000);
gretelai_synthetic_text_to_sql
CREATE TABLE Exhibitions (exhibition_id INT, name VARCHAR(50), start_date DATE, end_date DATE, day VARCHAR(10)); CREATE TABLE Visitors (visitor_id INT, exhibition_id INT, age INT, gender VARCHAR(50));
What is the average age of visitors who attended exhibitions on 'Friday'?
SELECT AVG(age) FROM Visitors v JOIN Exhibitions e ON v.exhibition_id = e.exhibition_id WHERE e.day = 'Friday';
gretelai_synthetic_text_to_sql
CREATE TABLE energy_storage (id INT, location TEXT, country TEXT, capacity FLOAT); INSERT INTO energy_storage (id, location, country, capacity) VALUES (1, 'Hornsdale', 'Australia', 129.0), (2, 'Tesla Big Battery', 'Australia', 100.0), (3, 'Bald Hills', 'Australia', 105.0);
What is the minimum energy storage capacity (MWh) in the Australian energy market, and how many storage facilities have a capacity greater than 100 MWh?
SELECT MIN(capacity), COUNT(*) FROM energy_storage WHERE country = 'Australia' AND capacity > 100;
gretelai_synthetic_text_to_sql
CREATE TABLE climate_adaptation (country VARCHAR(255), population INT); INSERT INTO climate_adaptation VALUES ('Australia', 25000000); INSERT INTO climate_adaptation VALUES ('New Zealand', 4900000);
What is the total population of countries involved in climate adaptation projects in Oceania?
SELECT SUM(population) FROM climate_adaptation WHERE continent = 'Oceania';
gretelai_synthetic_text_to_sql
CREATE TABLE game_scores (id INT PRIMARY KEY, player_id INT, game_name VARCHAR(100), score INT); INSERT INTO game_scores VALUES (1, 1001, 'GameA', 5000), (2, 1002, 'GameB', 7000), (3, 1003, 'GameA', 3000), (4, 1004, 'GameB', 7500), (5, 1001, 'GameA', 5500), (6, 1005, 'GameC', 8000);
Calculate the average score for each game
SELECT game_name, AVG(score) AS avg_score FROM game_scores GROUP BY game_name;
gretelai_synthetic_text_to_sql
CREATE TABLE student_mental_health (id INT PRIMARY KEY, student_id INT, mental_health_score INT, assessment_date DATE);
Design a new table named 'student_mental_health'
CREATE TABLE student_mental_health (id INT PRIMARY KEY, student_id INT, mental_health_score INT, assessment_date DATE);
gretelai_synthetic_text_to_sql
CREATE TABLE shared_bicycles (bicycle_id INT, ride_start_time TIMESTAMP, ride_end_time TIMESTAMP, start_location TEXT, end_location TEXT, distance FLOAT);
What is the total distance traveled by shared electric bicycles in Paris in the past month?
SELECT SUM(distance) FROM shared_bicycles WHERE start_location LIKE 'Paris%' AND vehicle_type = 'Electric Bicycle' AND ride_start_time >= NOW() - INTERVAL '1 month';
gretelai_synthetic_text_to_sql
CREATE TABLE CommunityHealthWorkers (WorkerID INT, Name VARCHAR(50), Specialty VARCHAR(50));
Insert new records of community health workers who specialize in both mental health and physical health.
INSERT INTO CommunityHealthWorkers (WorkerID, Name, Specialty) VALUES (3, 'Jim Brown', 'Mental Health, Physical Health'); INSERT INTO CommunityHealthWorkers (WorkerID, Name, Specialty) VALUES (4, 'Sara Johnson', 'Mental Health, Physical Health');
gretelai_synthetic_text_to_sql
CREATE TABLE JobOffers (OfferID INT, JobCategory VARCHAR(20), Gender VARCHAR(10), OfferDate DATE); INSERT INTO JobOffers (OfferID, JobCategory, Gender, OfferDate) VALUES (1, 'Marketing', 'Female', '2022-01-10'), (2, 'IT', 'Male', '2022-03-15');
What is the number of job offers extended to female candidates in the last 6 months?
SELECT JobCategory, COUNT(*) FROM JobOffers WHERE Gender = 'Female' AND OfferDate BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH) AND CURRENT_DATE GROUP BY JobCategory;
gretelai_synthetic_text_to_sql
CREATE TABLE peacekeeping_training(id INT, personnel_id INT, trained_by VARCHAR(255), trained_in VARCHAR(255), training_year INT); INSERT INTO peacekeeping_training(id, personnel_id, trained_by, trained_in, training_year) VALUES (1, 111, 'EU', 'Cybersecurity', 2017), (2, 222, 'EU', 'Peacekeeping Tactics', 2018), (3, 333, 'EU', 'Cybersecurity', 2019), (4, 444, 'EU', 'Cybersecurity', 2020), (5, 555, 'EU', 'Cybersecurity', 2021), (6, 666, 'EU', 'Cybersecurity', 2022);
What is the maximum number of peacekeeping personnel trained by the European Union in cybersecurity between 2017 and 2022, inclusive?
SELECT MAX(personnel_id) FROM peacekeeping_training WHERE trained_by = 'EU' AND trained_in = 'Cybersecurity' AND training_year BETWEEN 2017 AND 2022;
gretelai_synthetic_text_to_sql
CREATE TABLE Shipments (country varchar(20), shipment_date date); INSERT INTO Shipments (country, shipment_date) VALUES ('Country X', '2022-01-05'), ('Country Y', '2022-02-10');
Which country had the highest total number of shipments in the month of 'February 2022'?
SELECT country, SUM(CASE WHEN EXTRACT(MONTH FROM shipment_date) = 2 AND EXTRACT(YEAR FROM shipment_date) = 2022 THEN 1 ELSE 0 END) AS total_shipments, SUM(total_shipments) OVER () AS total_shipments_all_countries FROM (SELECT country, COUNT(*) AS total_shipments FROM Shipments GROUP BY country, EXTRACT(MONTH FROM shipment_date), EXTRACT(YEAR FROM shipment_date)) subquery ORDER BY total_shipments DESC LIMIT 1;
gretelai_synthetic_text_to_sql
CREATE TABLE MentalHealthPolicies (PolicyID INT, State VARCHAR(20), Year INT, Policy VARCHAR(100)); INSERT INTO MentalHealthPolicies (PolicyID, State, Year, Policy) VALUES (1, 'California', 2021, 'Mental Health Teletherapy Expansion'); INSERT INTO MentalHealthPolicies (PolicyID, State, Year, Policy) VALUES (2, 'California', 2020, 'Suicide Prevention Program');
How many mental health policies were implemented in California in 2021?
SELECT COUNT(*) FROM MentalHealthPolicies WHERE State = 'California' AND Year = 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE JuvenileCases (Id INT, Race VARCHAR(50), Program VARCHAR(50), ResolutionDate DATE); INSERT INTO JuvenileCases (Id, Race, Program, ResolutionDate) VALUES (1, 'Hispanic', 'Community Supervision', '2021-03-21'), (2, 'Black', 'Probation', '2020-12-12'), (3, 'Asian', 'Community Supervision', '2021-06-15');
Find the number of juvenile cases that were resolved through community supervision, broken down by race/ethnicity, for the past year.
SELECT Race, COUNT(*) as NumCases FROM JuvenileCases WHERE Program = 'Community Supervision' AND YEAR(ResolutionDate) = 2021 GROUP BY Race;
gretelai_synthetic_text_to_sql
CREATE TABLE policies (policy_id INT, policyholder_id INT); CREATE TABLE claims (claim_id INT, policy_id INT, amount DECIMAL(10,2));
Determine the policy with the highest claim amount for each policyholder.
SELECT policies.policyholder_id, MAX(claims.amount) AS highest_claim_amount FROM policies INNER JOIN claims ON policies.policy_id = claims.policy_id GROUP BY policies.policyholder_id;
gretelai_synthetic_text_to_sql