context
stringlengths
11
9.12k
question
stringlengths
0
1.06k
SQL
stringlengths
2
4.44k
source
stringclasses
28 values
CREATE TABLE Programs (id INT, name VARCHAR(50), sector VARCHAR(10));CREATE TABLE Households (id INT, program_id INT, energy_savings FLOAT, household_size INT);
List energy efficiency programs and their corresponding energy savings per household from the Programs and Households tables
SELECT p.name, AVG(h.energy_savings / h.household_size) as savings_per_household FROM Programs p INNER JOIN Households h ON p.id = h.program_id WHERE p.sector = 'efficiency' GROUP BY p.id;
gretelai_synthetic_text_to_sql
CREATE TABLE climate_finance (finance_id INT, finance_amount DECIMAL(10,2), finance_type TEXT, project_id INT, commitment_date DATE);
What is the average climate finance commitment per climate adaptation project in Europe?
SELECT AVG(cf.finance_amount) FROM climate_finance cf JOIN climate_adaptation_projects cap ON cf.project_id = cap.project_id WHERE cap.location LIKE '%Europe%' AND cf.finance_type = 'climate_adaptation';
gretelai_synthetic_text_to_sql
CREATE TABLE community_initiatives (id INT, name VARCHAR(50), completion_date DATE); INSERT INTO community_initiatives (id, name, completion_date) VALUES (1, 'Clean Energy Project', '2018-12-31');
Which community development initiatives in the 'rural_infrastructure' schema were completed in 2018?
SELECT name FROM rural_infrastructure.community_initiatives WHERE completion_date = '2018-01-01' OR completion_date = '2018-02-01' OR completion_date = '2018-03-01' OR completion_date = '2018-04-01' OR completion_date = '2018-05-01' OR completion_date = '2018-06-01' OR completion_date = '2018-07-01' OR completion_date = '2018-08-01' OR completion_date = '2018-09-01' OR completion_date = '2018-10-01' OR completion_date = '2018-11-01' OR completion_date = '2018-12-01';
gretelai_synthetic_text_to_sql
CREATE TABLE ArtWorks (ID INT PRIMARY KEY, Title TEXT, Artist TEXT, Year INT);
Add a record to the ArtWorks table for an artwork titled 'Sunset', by 'Van Gogh', from year 1888
INSERT INTO ArtWorks (Title, Artist, Year) VALUES ('Sunset', 'Van Gogh', 1888);
gretelai_synthetic_text_to_sql
CREATE TABLE mines (id INT, location VARCHAR(50), neodymium_production FLOAT); INSERT INTO mines (id, location, neodymium_production) VALUES (1, 'Bayan Obo', 12000), (2, 'Mount Weld', 3500);
What is the average production of Neodymium by mine location?
SELECT location, AVG(neodymium_production) as avg_production FROM mines GROUP BY location;
gretelai_synthetic_text_to_sql
CREATE TABLE nutrition (id INT, dish TEXT, vegan BOOLEAN, calories INT); INSERT INTO nutrition (id, dish, vegan, calories) VALUES (1, 'Tofu Stir Fry', true, 600), (2, 'Chicken Shawarma', false, 900), (3, 'Vegan Nachos', true, 700), (4, 'Beef Burrito', false, 1200);
Which dish has the highest calorie count in the vegan category?
SELECT dish, calories FROM nutrition WHERE vegan = true ORDER BY calories DESC LIMIT 1;
gretelai_synthetic_text_to_sql
CREATE TABLE mental_health_parity (violation_id INT, provider_id INT, violation_count INT); INSERT INTO mental_health_parity (violation_id, provider_id, violation_count) VALUES (1, 1, 5), (2, 1, 3), (3, 2, 2), (4, 3, 1); CREATE TABLE healthcare_providers (provider_id INT, name VARCHAR(50)); INSERT INTO healthcare_providers (provider_id, name) VALUES (1, 'John Doe'), (2, 'Jane Smith'), (3, 'Maria Garcia');
What is the total number of mental health parity violations for each healthcare provider?
SELECT hp.name, SUM(mhp.violation_count) FROM healthcare_providers hp INNER JOIN mental_health_parity mhp ON hp.provider_id = mhp.provider_id GROUP BY hp.name;
gretelai_synthetic_text_to_sql
CREATE TABLE Budget_Allocation( allocation_id INT PRIMARY KEY, category VARCHAR(255), amount FLOAT, fiscal_year INT, FOREIGN KEY (category) REFERENCES Parks(name)); INSERT INTO Budget_Allocation (allocation_id, category, amount, fiscal_year) VALUES (1, 'Central Park', 15000000.00, 2021), (2, 'Prospect Park', 12000000.00, 2021), (3, 'Golden Gate Park', 18000000.00, 2021); CREATE TABLE Parks( park_id INT PRIMARY KEY, name VARCHAR(255), location VARCHAR(255), area FLOAT, created_date DATE);
Display the total budget allocated for public parks in 2021
SELECT SUM(amount) FROM Budget_Allocation WHERE fiscal_year = 2021 AND category IN (SELECT name FROM Parks);
gretelai_synthetic_text_to_sql
CREATE TABLE orders (order_id INT, customer_id INT, order_date DATE, total DECIMAL(5,2));
Update the total of the order with order_id 1 to $60.00
UPDATE orders SET total = 60.00 WHERE order_id = 1;
gretelai_synthetic_text_to_sql
CREATE TABLE OrganicCottonGarments (garment_id INT, production_cost DECIMAL(5,2), production_date DATE); INSERT INTO OrganicCottonGarments (garment_id, production_cost, production_date) VALUES (1, 25.00, '2022-01-01'), (2, 28.00, '2022-02-01'), (3, 26.50, '2022-03-01'), (4, 23.50, '2022-04-01'), (5, 29.00, '2022-05-01'), (6, 27.00, '2022-06-01'), (7, 21.00, '2022-07-01'), (8, 30.00, '2022-08-01'), (9, 24.00, '2022-09-01'), (10, 22.00, '2022-10-01');
What is the minimum production cost for garments made from organic cotton in the last 6 months?
SELECT MIN(production_cost) FROM OrganicCottonGarments WHERE production_date BETWEEN DATEADD(month, -6, GETDATE()) AND GETDATE();
gretelai_synthetic_text_to_sql
CREATE TABLE WeatherData (id INT, Temperature INT, Timestamp DATETIME); INSERT INTO WeatherData (id, Temperature, Timestamp) VALUES (1, 12, '2022-04-15 12:00:00'), (2, 18, '2022-04-16 12:00:00');
What is the daily minimum temperature for the last 60 days, with a running total of the number of days below 15 degrees Celsius?
SELECT Temperature, Timestamp, SUM(CASE WHEN Temperature < 15 THEN 1 ELSE 0 END) OVER (ORDER BY Timestamp) as RunningTotal FROM WeatherData WHERE Timestamp BETWEEN DATEADD(day, -60, GETDATE()) AND GETDATE();
gretelai_synthetic_text_to_sql
CREATE TABLE TransitProjects (project VARCHAR(50), city VARCHAR(20), start_date DATE, end_date DATE, budget INT); INSERT INTO TransitProjects (project, city, start_date, end_date, budget) VALUES ('ProjectA', 'New York', '2020-01-01', '2022-12-31', 60000000), ('ProjectB', 'Chicago', '2019-01-01', '2021-12-31', 55000000);
List all the public transportation projects in the city of New York and Chicago, including their start and end dates, that have an estimated budget over 50 million.
SELECT project, city, start_date, end_date FROM TransitProjects WHERE city IN ('New York', 'Chicago') AND budget > 50000000;
gretelai_synthetic_text_to_sql
CREATE TABLE industry_water_usage (industry_sector VARCHAR(50), city VARCHAR(50), year INT, water_consumption FLOAT); INSERT INTO industry_water_usage (industry_sector, city, year, water_consumption) VALUES ('Agriculture', 'Sacramento', 2020, 12345.6), ('Manufacturing', 'Sacramento', 2020, 23456.7), ('Residential', 'Sacramento', 2020, 34567.8);
What is the total water consumption by each industry sector in the city of Sacramento in 2020?
SELECT industry_sector, SUM(water_consumption) as total_water_consumption FROM industry_water_usage WHERE city = 'Sacramento' AND year = 2020 GROUP BY industry_sector;
gretelai_synthetic_text_to_sql
CREATE TABLE Cases (CaseID INT, AttorneyID INT, CaseOutcome VARCHAR(50)); INSERT INTO Cases (CaseID, AttorneyID, CaseOutcome) VALUES (1, 1, 'Won'), (2, 1, 'Lost'), (3, 2, 'Won'), (4, 2, 'Won'), (5, 3, 'Lost'), (6, 3, 'Lost'), (7, 4, 'Won'), (8, 4, 'Lost'), (9, 5, 'Lost'), (10, 5, 'Won'); CREATE TABLE Attorneys (AttorneyID INT, AttorneyName VARCHAR(50), Gender VARCHAR(50)); INSERT INTO Attorneys (AttorneyID, AttorneyName, Gender) VALUES (1, 'Jane Doe', 'Female'), (2, 'John Smith', 'Male'), (3, 'Sara Connor', 'Female'), (4, 'David Kim', 'Male'), (5, 'Emily Johnson', 'Female');
What is the number of cases and win rate for female attorneys in the West region?
SELECT a.AttorneyName, a.Gender, COUNT(c.CaseID) AS TotalCases, COUNT(c.CaseID) * 100.0 / SUM(COUNT(c.CaseID)) OVER (PARTITION BY a.Gender) AS WinRate FROM Attorneys a JOIN Cases c ON a.AttorneyID = c.AttorneyID WHERE a.Gender = 'Female' AND a.Region = 'West' GROUP BY a.AttorneyName, a.Gender;
gretelai_synthetic_text_to_sql
CREATE TABLE menu_categories (category_id INT, category_name TEXT);
Add new category 'Vegan' in the menu_categories table
INSERT INTO menu_categories (category_name) VALUES ('Vegan');
gretelai_synthetic_text_to_sql
CREATE TABLE socially_responsible_loans (id INT PRIMARY KEY, customer_id INT, amount DECIMAL(10,2), date DATE); CREATE VIEW last_month_loans AS SELECT * FROM socially_responsible_loans WHERE date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);
How many socially responsible loans were granted to customers in the last month?
SELECT COUNT(*) FROM last_month_loans;
gretelai_synthetic_text_to_sql
CREATE TABLE Roads (RoadID INT, Name TEXT, Length INT, State TEXT); INSERT INTO Roads (RoadID, Name, Length, State) VALUES (1, 'Road1', 50, 'New York'); INSERT INTO Roads (RoadID, Name, Length, State) VALUES (2, 'Road2', 75, 'New York'); INSERT INTO Roads (RoadID, Name, Length, State) VALUES (3, 'Road3', 100, 'New Jersey');
What is the total length of all roads in the state of New York?
SELECT SUM(Length) FROM Roads WHERE State = 'New York';
gretelai_synthetic_text_to_sql
CREATE TABLE road_projects (id INT, name TEXT, state TEXT, budget FLOAT); INSERT INTO road_projects (id, name, state, budget) VALUES (1, 'NY-1 Expressway Reconstruction', 'NY', 20000000);
What is the maximum budget for road projects in New York?
SELECT MAX(budget) FROM road_projects WHERE state = 'NY';
gretelai_synthetic_text_to_sql
CREATE TABLE agriculture_innovation_2 (id INT, project_name VARCHAR(50), budget DECIMAL(10, 2)); INSERT INTO agriculture_innovation_2 (id, project_name, budget) VALUES (1, 'Precision Agriculture', 75000.00), (2, 'Vertical Farming', 125000.00), (3, 'Biological Pest Control', 95000.00);
What are the names and budget allocations for all agricultural innovation projects in the 'agriculture_innovation_2' table?
SELECT project_name, budget FROM agriculture_innovation_2;
gretelai_synthetic_text_to_sql
CREATE TABLE social_media (user_id INT, posts_count INT);
What is the total number of posts in the 'social_media' table?
SELECT SUM(posts_count) FROM social_media;
gretelai_synthetic_text_to_sql
CREATE TABLE carbon_sequestration (id INT, country VARCHAR(255), region VARCHAR(255), year INT, metric_tons FLOAT); INSERT INTO carbon_sequestration (id, country, region, year, metric_tons) VALUES (1, 'Germany', 'Europe', 2020, 123456.12), (2, 'France', 'Europe', 2020, 234567.12), (3, 'Spain', 'Europe', 2020, 345678.12);
What is the average carbon sequestration, in metric tons, for each country in the Europe region for the year 2020?
SELECT country, AVG(metric_tons) FROM carbon_sequestration WHERE region = 'Europe' AND year = 2020 GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE dishes (id INT, name VARCHAR(255), is_organic BOOLEAN, serving_size INT, calories INT); INSERT INTO dishes (id, name, is_organic, serving_size, calories) VALUES (1, 'Quinoa Salad', true, 1, 400), (2, 'Spaghetti Bolognese', false, 2, 600), (3, 'Veggie Tacos', true, 1, 350);
What is the average caloric intake per serving for organic dishes?
SELECT AVG(calories / serving_size) as avg_caloric_intake FROM dishes WHERE is_organic = true;
gretelai_synthetic_text_to_sql
CREATE TABLE AttorneyStartYear (AttorneyID INT, StartYear INT); INSERT INTO AttorneyStartYear (AttorneyID, StartYear) VALUES (1, 2018), (2, 2019), (3, 2015);
What is the average number of cases handled by attorneys per year?
SELECT AVG(DATEDIFF(YEAR, StartYear, GETDATE())) FROM AttorneyStartYear;
gretelai_synthetic_text_to_sql
CREATE TABLE sales (product_id INT, product_category TEXT, sale_date DATE, revenue FLOAT);
What is the total revenue for each product category in Q2 2022?
SELECT product_category, SUM(revenue) FROM sales WHERE sale_date BETWEEN '2022-04-01' AND '2022-06-30' GROUP BY product_category;
gretelai_synthetic_text_to_sql
CREATE TABLE city (id INT, name VARCHAR(255)); INSERT INTO city (id, name) VALUES (1, 'CityA'), (2, 'CityB'); CREATE TABLE property (id INT, co_ownership_price DECIMAL(10,2), city_id INT, category VARCHAR(255)); INSERT INTO property (id, co_ownership_price, city_id, category) VALUES (1, 500000, 1, 'sustainable urbanism'), (2, 600000, 1, 'sustainable urbanism'), (3, 450000, 2, 'inclusive housing');
What is the minimum co-ownership price for properties in each city, grouped by category?
SELECT c.name AS city, p.category AS category, MIN(p.co_ownership_price) AS min_price FROM property p JOIN city c ON p.city_id = c.id GROUP BY c.name, p.category;
gretelai_synthetic_text_to_sql
CREATE TABLE Manufacturer (MID INT PRIMARY KEY, Name VARCHAR(50)); INSERT INTO Manufacturer (MID, Name) VALUES (1, 'Boeing'), (2, 'Lockheed Martin'), (3, 'Northrop Grumman'); CREATE TABLE Aircraft (AID INT PRIMARY KEY, Model VARCHAR(50), ManufacturerID INT, FOREIGN KEY (ManufacturerID) REFERENCES Manufacturer(MID)); INSERT INTO Aircraft (AID, Model, ManufacturerID) VALUES (1, 'F-15 Eagle', 2), (2, 'F-16 Fighting Falcon', 2), (3, 'F/A-18E/F Super Hornet', 1), (4, 'B-2 Spirit', 3);
What is the total number of military aircraft by manufacturer, sorted by the count in descending order?
SELECT m.Name, COUNT(a.AID) AS Total FROM Manufacturer m JOIN Aircraft a ON m.MID = a.ManufacturerID GROUP BY m.Name ORDER BY Total DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE safety_incidents (incident_id INT, location TEXT, incident_date DATE); INSERT INTO safety_incidents (incident_id, location, incident_date) VALUES (1, 'Nigeria', '2022-02-12'), (2, 'South Africa', '2021-10-18'), (3, 'Egypt', '2022-04-05'), (4, 'Kenya', '2021-08-07');
How many AI safety incidents were reported in Africa in the last 6 months?
SELECT COUNT(*) FROM safety_incidents WHERE location LIKE 'Africa%' AND incident_date >= DATEADD(month, -6, GETDATE());
gretelai_synthetic_text_to_sql
CREATE TABLE articles (title VARCHAR(255), media_literacy_score INT);
What is the minimum media literacy score for articles published in the 'articles' table?
SELECT MIN(media_literacy_score) AS min_score FROM articles;
gretelai_synthetic_text_to_sql
CREATE TABLE ResidentialEfficiency (city VARCHAR(20), building_type VARCHAR(20), energy_efficiency FLOAT); INSERT INTO ResidentialEfficiency (city, building_type, energy_efficiency) VALUES ('Seattle', 'Residential', 85.0);
What are the energy efficiency stats for residential buildings in the city of Seattle?
SELECT energy_efficiency FROM ResidentialEfficiency WHERE city = 'Seattle' AND building_type = 'Residential';
gretelai_synthetic_text_to_sql
CREATE TABLE BuildingPermits (id INT, permitNumber TEXT, state TEXT, quarter INT, year INT);
How many building permits were issued in Texas in Q1 of 2021?
SELECT COUNT(*) FROM BuildingPermits WHERE state = 'Texas' AND quarter = 1 AND year = 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE PolicyDocuments (Country VARCHAR(50), Year INT, Documents INT); INSERT INTO PolicyDocuments (Country, Year, Documents) VALUES ('Australia', 2010, 20), ('Australia', 2015, 25), ('Australia', 2020, 30), ('New Zealand', 2010, 15), ('New Zealand', 2015, 20), ('New Zealand', 2020, 25);
What is the number of climate-related policy documents published by each government in Oceania, ranked by the most recent year?
SELECT Country, MAX(Year) AS RecentYear, SUM(Documents) AS TotalDocuments FROM PolicyDocuments GROUP BY Country ORDER BY RecentYear DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE Players (PlayerID INT, PlayerName TEXT, Country TEXT); INSERT INTO Players (PlayerID, PlayerName, Country) VALUES (1, 'John Doe', 'France'), (2, 'Jane Smith', 'Germany'); CREATE TABLE GameSessions (SessionID INT, PlayerID INT, GameID INT, StartTime TIMESTAMP, EndTime TIMESTAMP); INSERT INTO GameSessions (SessionID, PlayerID, GameID, StartTime, EndTime) VALUES (1, 1, 1, '2021-01-01 10:00:00', '2021-01-01 12:00:00'), (2, 1, 2, '2021-01-01 14:00:00', '2021-01-01 16:00:00'), (3, 2, 1, '2021-01-01 09:00:00', '2021-01-01 11:00:00');
What is the total playtime for each game by players in Europe?
SELECT Players.Country, SUM(TIMESTAMPDIFF(MINUTE, GameSessions.StartTime, GameSessions.EndTime)) as TotalPlaytime FROM Players JOIN GameSessions ON Players.PlayerID = GameSessions.PlayerID WHERE Players.Country IN ('France', 'Germany') GROUP BY Players.Country;
gretelai_synthetic_text_to_sql
CREATE TABLE posts (id INT, hashtags TEXT, engagement_rate DECIMAL(5, 2), timestamp TIMESTAMP); INSERT INTO posts (id, hashtags, engagement_rate, timestamp) VALUES (1, '#music, #song', 6.15, '2022-07-17 10:00:00');
What is the average engagement rate for posts containing hashtags related to 'music' in the past day?
SELECT AVG(engagement_rate) FROM posts WHERE hashtags LIKE '%#music%' AND timestamp >= DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 DAY);
gretelai_synthetic_text_to_sql
CREATE TABLE HospitalBeds (HospitalID int, Beds int, Rural bool); INSERT INTO HospitalBeds (HospitalID, Beds, Rural) VALUES (1, 50, true);
What is the minimum number of hospital beds in rural areas of India?
SELECT MIN(Beds) FROM HospitalBeds WHERE Rural = true;
gretelai_synthetic_text_to_sql
CREATE TABLE RuralHealthFacilities (FacilityID INT, Name VARCHAR(50), Address VARCHAR(100), TotalBeds INT); INSERT INTO RuralHealthFacilities (FacilityID, Name, Address, TotalBeds) VALUES (1, 'Rural Community Hospital', '1234 Rural Rd', 50);
Update the address of the 'Rural Community Hospital' in 'RuralHealthFacilities' table.
UPDATE RuralHealthFacilities SET Address = '5678 Rural Ave' WHERE Name = 'Rural Community Hospital';
gretelai_synthetic_text_to_sql
CREATE TABLE volunteers (id INT, name VARCHAR(50), hours_served FLOAT);
Insert a new record into the volunteers table with the following information: id = 4, name = 'Olivia Thompson', hours_served = 25.00.
INSERT INTO volunteers (id, name, hours_served) VALUES (4, 'Olivia Thompson', 25.00);
gretelai_synthetic_text_to_sql
CREATE TABLE editors (id INT, name VARCHAR(50), gender VARCHAR(10), age INT, experience INT); INSERT INTO editors (id, name, gender, age, experience) VALUES (1, 'John Doe', 'Male', 55, 15); INSERT INTO editors (id, name, gender, age, experience) VALUES (2, 'Jim Brown', 'Male', 50, 12); INSERT INTO editors (id, name, gender, age, experience) VALUES (3, 'Samantha Johnson', 'Female', 45, 10); INSERT INTO editors (id, name, gender, age, experience) VALUES (4, 'Alicia Keys', 'Female', 40, 8); INSERT INTO editors (id, name, gender, age, experience) VALUES (5, 'Robert Smith', 'Male', 35, 6);
What is the total number of female and male editors in the 'editors' table?
SELECT SUM(CASE WHEN gender = 'Female' THEN 1 ELSE 0 END) AS female_editors, SUM(CASE WHEN gender = 'Male' THEN 1 ELSE 0 END) AS male_editors FROM editors;
gretelai_synthetic_text_to_sql
CREATE TABLE cosmetic_sales (product_id INT, sale_volume INT, market VARCHAR(10)); INSERT INTO cosmetic_sales (product_id, sale_volume, market) VALUES (1, 200, 'US'), (2, 300, 'CA'), (3, 400, 'US'); CREATE TABLE product_info (product_id INT, is_organic BOOLEAN); INSERT INTO product_info (product_id, is_organic) VALUES (1, true), (2, false), (3, false);
What is the total sales volume for organic cosmetic products in the US market?
SELECT SUM(cs.sale_volume) FROM cosmetic_sales cs JOIN product_info pi ON cs.product_id = pi.product_id WHERE pi.is_organic = true AND cs.market = 'US';
gretelai_synthetic_text_to_sql
CREATE TABLE clients (client_id INT, name TEXT, age INT, gender TEXT); INSERT INTO clients VALUES (1, 'John Doe', 35, 'Male'), (2, 'Jane Smith', 45, 'Female'), (3, 'Bob Johnson', 50, 'Male'), (4, 'Alice Lee', 40, 'Female'); CREATE TABLE investments (client_id INT, investment_type TEXT); INSERT INTO investments VALUES (1, 'Stocks'), (1, 'Bonds'), (2, 'Stocks'), (2, 'Mutual Funds'), (3, 'Mutual Funds'), (3, 'Real Estate'), (4, 'Real Estate');
Show the names and ages of clients who invested in mutual funds but not in stocks and bonds?
SELECT c.name, c.age FROM clients c INNER JOIN investments i ON c.client_id = i.client_id WHERE i.investment_type = 'Mutual Funds' AND c.client_id NOT IN (SELECT client_id FROM investments WHERE investment_type IN ('Stocks', 'Bonds'));
gretelai_synthetic_text_to_sql
CREATE TABLE ai_researchers (id INT, name VARCHAR(50), salary FLOAT, department VARCHAR(50), year INT); INSERT INTO ai_researchers (id, name, salary, department, year) VALUES (1, 'Jack', 100000, 'ai_ethics', 2022), (2, 'Jill', 105000, 'ai_ethics', 2022), (3, 'John', 95000, 'ai_ethics', 2022), (4, 'Jane', 90000, 'ai_ethics', 2022);
What is the minimum salary of AI researchers in the "ai_ethics" department of the "research_lab" company in 2022?
SELECT MIN(salary) FROM ai_researchers WHERE department = 'ai_ethics' AND year = 2022;
gretelai_synthetic_text_to_sql
CREATE TABLE players (id INT PRIMARY KEY, name VARCHAR(50), age INT, country VARCHAR(50));
Insert a new player from Brazil with the name 'Marcos Oliveira', age 35
INSERT INTO players (name, age, country) VALUES ('Marcos Oliveira', 35, 'Brazil');
gretelai_synthetic_text_to_sql
CREATE TABLE Hospitals (Country VARCHAR(50), Continent VARCHAR(50), HospitalsPer1000 FLOAT, Year INT); INSERT INTO Hospitals (Country, Continent, HospitalsPer1000, Year) VALUES ('France', 'Europe', 3.5, 2020), ('Germany', 'Europe', 4.0, 2020), ('Italy', 'Europe', 3.7, 2020);
What is the number of hospitals per 1000 people in European countries in 2020?
SELECT Country, Continent, HospitalsPer1000 FROM Hospitals WHERE Continent = 'Europe' AND Year = 2020;
gretelai_synthetic_text_to_sql
CREATE TABLE authors (id INT, name VARCHAR(50), gender VARCHAR(10), age INT, total_articles INT); INSERT INTO authors (id, name, gender, age, total_articles) VALUES (1, 'Jane Smith', 'Female', 35, 5); INSERT INTO authors (id, name, gender, age, total_articles) VALUES (2, 'Alice Johnson', 'Female', 40, 10); INSERT INTO authors (id, name, gender, age, total_articles) VALUES (3, 'John Doe', 'Male', 50, 15);
What is the total number of articles published by each author in the 'authors' table?
SELECT name, SUM(total_articles) FROM authors GROUP BY name;
gretelai_synthetic_text_to_sql
CREATE TABLE shared_vehicles (id INT, vehicle_type VARCHAR(20), trip_count INT); INSERT INTO shared_vehicles (id, vehicle_type, trip_count) VALUES (1, 'ebike', 1200), (2, 'escooter', 800), (3, 'car', 1500); CREATE TABLE city_data (city VARCHAR(20), shared_ebikes BOOLEAN, shared_escooters BOOLEAN, shared_cars BOOLEAN); INSERT INTO city_data (city, shared_ebikes, shared_escooters, shared_cars) VALUES ('San Francisco', true, true, true), ('Houston', false, false, true), ('Boston', true, true, true);
List cities with more than 2000 trips on shared electric vehicles
SELECT city FROM city_data WHERE (shared_ebikes = true OR shared_escooters = true OR shared_cars = true) AND city IN (SELECT city FROM (SELECT city, SUM(trip_count) AS total_trips FROM shared_vehicles WHERE (vehicle_type = 'ebike' OR vehicle_type = 'escooter' OR vehicle_type = 'car') GROUP BY city) AS shared_vehicles WHERE total_trips > 2000);
gretelai_synthetic_text_to_sql
CREATE TABLE Stores (store_id INT, store_name VARCHAR(255)); CREATE TABLE Products (product_id INT, product_name VARCHAR(255), is_sustainable BOOLEAN, cost INT); CREATE TABLE Inventory (store_id INT, product_id INT, quantity INT);
What is the total cost of sustainable seafood products in each store?
SELECT s.store_name, p.product_name, SUM(i.quantity * p.cost) as total_cost FROM Inventory i JOIN Stores s ON i.store_id = s.store_id JOIN Products p ON i.product_id = p.product_id WHERE p.is_sustainable = TRUE GROUP BY s.store_name, p.product_name;
gretelai_synthetic_text_to_sql
CREATE TABLE projects (id INT, name TEXT, state TEXT); CREATE TABLE project_materials (id INT, project_id INT, material TEXT); INSERT INTO projects (id, name, state) VALUES (1, 'Green Project 1', 'Utah'); INSERT INTO projects (id, name, state) VALUES (2, 'Eco Project 2', 'Utah'); INSERT INTO project_materials (id, project_id, material) VALUES (1, 1, 'Wood'); INSERT INTO project_materials (id, project_id, material) VALUES (2, 1, 'Glass'); INSERT INTO project_materials (id, project_id, material) VALUES (3, 2, 'Steel'); INSERT INTO project_materials (id, project_id, material) VALUES (4, 2, 'Concrete');
What are the top 3 construction materials used by project in Utah?
SELECT projects.name, project_materials.material, COUNT(project_materials.id) as material_count FROM projects JOIN project_materials ON projects.id = project_materials.project_id WHERE projects.state = 'Utah' GROUP BY projects.name, project_materials.material ORDER BY material_count DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE cases (id INT, judge_name VARCHAR(20), verdict VARCHAR(20), billing_amount DECIMAL(10,2)); INSERT INTO cases (id, judge_name, verdict, billing_amount) VALUES (1, 'Anderson', 'Not Guilty', 5000.00), (2, 'Brown', 'Guilty', 4000.00), (3, 'Anderson', 'Mistrial', 6000.00), (4, 'Green', 'Not Guilty', 7000.00);
List all case IDs and billing amounts for cases with a precedent set by Judge 'Anderson' that had a verdict of 'Not Guilty' or 'Mistrial'.
SELECT id, billing_amount FROM cases WHERE judge_name = 'Anderson' AND (verdict = 'Not Guilty' OR verdict = 'Mistrial');
gretelai_synthetic_text_to_sql
CREATE TABLE articles (id INT, title VARCHAR(255), section VARCHAR(64), word_count INT); INSERT INTO articles (id, title, section, word_count) VALUES (1, 'ArticleA', 'culture', 1200), (2, 'ArticleB', 'politics', 800), (3, 'ArticleC', 'culture', 1500);
Count the number of articles published in the 'culture' section with a word count greater than 1000.
SELECT COUNT(*) FROM articles WHERE section = 'culture' AND word_count > 1000;
gretelai_synthetic_text_to_sql
CREATE TABLE ClinicCapacity (ProvinceName VARCHAR(50), ClinicName VARCHAR(50), Capacity INT); INSERT INTO ClinicCapacity (ProvinceName, ClinicName, Capacity) VALUES ('Ontario', 'ClinicA', 200), ('Ontario', 'ClinicB', 250), ('Quebec', 'ClinicX', 150), ('British Columbia', 'ClinicY', 200), ('British Columbia', 'ClinicZ', 175);
What is the average clinic capacity per province, excluding the top 25% of clinics?
SELECT ProvinceName, AVG(Capacity) AS AvgCapacity FROM (SELECT ProvinceName, Capacity, NTILE(4) OVER (ORDER BY Capacity DESC) AS Quartile FROM ClinicCapacity) AS Subquery WHERE Quartile < 4 GROUP BY ProvinceName
gretelai_synthetic_text_to_sql
CREATE TABLE ResearchStations (id INT PRIMARY KEY, name VARCHAR(100), location VARCHAR(100), region VARCHAR(50)); INSERT INTO ResearchStations (id, name, location, region) VALUES (2, 'Station B', 'Greenland', 'Arctic'), (3, 'Station C', 'Svalbard', 'Arctic');
How many research stations are in each region without any species?
SELECT ResearchStations.region, COUNT(DISTINCT ResearchStations.name) FROM ResearchStations LEFT JOIN Species ON ResearchStations.region = Species.region WHERE Species.id IS NULL GROUP BY ResearchStations.region;
gretelai_synthetic_text_to_sql
CREATE VIEW visit_age_group AS SELECT age, COUNT(*) AS count FROM visitor_demographics GROUP BY age;
Create a view for the number of visits by age group
SELECT * FROM visit_age_group;
gretelai_synthetic_text_to_sql
CREATE TABLE customers (id INT, birth_date DATE); INSERT INTO customers (id, birth_date) VALUES (1, '1985-01-01'), (2, '1990-01-01'), (3, '1975-01-01'), (4, '2000-01-01'); CREATE TABLE transactions (id INT, customer_id INT, amount DECIMAL(10,2)); INSERT INTO transactions (id, customer_id, amount) VALUES (1, 1, 500.00), (2, 2, 350.00), (3, 3, 700.00), (4, 4, 600.00);
Find transactions conducted by customers with ages greater than 30, assuming we have a 'customers' table with 'birth_date'.
SELECT t.id, t.customer_id, t.amount FROM transactions t INNER JOIN customers c ON t.customer_id = c.id WHERE DATEDIFF(YEAR, c.birth_date, GETDATE()) > 30;
gretelai_synthetic_text_to_sql
CREATE TABLE language_preservation (id INT, language VARCHAR(255), initiative VARCHAR(255), country VARCHAR(255)); INSERT INTO language_preservation (id, language, initiative, country) VALUES (1, 'Quechua', 'Quechua Education', 'Peru'), (2, 'Gaelic', 'Gaelic Language Revitalization', 'Scotland');
Which languages have the most preservation initiatives?
SELECT language, COUNT(*) as initiatives_count FROM language_preservation GROUP BY language;
gretelai_synthetic_text_to_sql
CREATE TABLE Cases (CaseID INT PRIMARY KEY, CaseName VARCHAR(50), CaseType VARCHAR(50), LawyerID INT, ClientID INT); INSERT INTO Cases (CaseID, CaseName, CaseType, LawyerID, ClientID) VALUES (1, 'Sample Case', 'Immigration', 1, 1); CREATE TABLE Lawyers (LawyerID INT PRIMARY KEY, Name VARCHAR(50), SpecializedIn VARCHAR(50)); INSERT INTO Lawyers (LawyerID, Name, SpecializedIn) VALUES (1, 'Alex Garcia', 'Immigration'); CREATE TABLE Billing (BillingID INT PRIMARY KEY, CaseID INT, Hours INT, BillAmount FLOAT); INSERT INTO Billing (BillingID, CaseID, Hours, BillAmount) VALUES (1, 1, 20, 3000.0);
What is the total billing amount for cases handled by lawyers specialized in Immigration Law?
SELECT SUM(Billing.BillAmount) FROM Cases INNER JOIN Lawyers ON Cases.LawyerID = Lawyers.LawyerID INNER JOIN Billing ON Cases.CaseID = Billing.CaseID WHERE Lawyers.SpecializedIn = 'Immigration';
gretelai_synthetic_text_to_sql
CREATE TABLE outcomes (id INT, patient_id INT, improvement VARCHAR(10), therapy_type VARCHAR(10)); INSERT INTO outcomes (id, patient_id, improvement, therapy_type) VALUES (1, 1, 'improved', 'teletherapy'), (2, 2, 'did not improve', 'in-person'), (3, 3, 'improved', 'teletherapy'), (4, 4, 'did not improve', 'in-person'), (5, 5, 'improved', 'teletherapy'), (6, 6, 'did not improve', 'in-person');
What is the percentage of patients who improved after teletherapy?
SELECT (COUNT(*) FILTER (WHERE improvement = 'improved' AND therapy_type = 'teletherapy')) * 100.0 / COUNT(*) AS percentage FROM outcomes;
gretelai_synthetic_text_to_sql
CREATE TABLE cause (id INT PRIMARY KEY, name VARCHAR(255));CREATE TABLE volunteer (id INT PRIMARY KEY, cause_id INT, organization_id INT);
What is the average number of volunteers per cause?
SELECT c.name, AVG(COUNT(v.id)) AS avg_volunteers FROM cause c JOIN volunteer v ON c.id = v.cause_id GROUP BY c.id;
gretelai_synthetic_text_to_sql
CREATE TABLE LifeExpectancyData (Country VARCHAR(50), Gender VARCHAR(6), LifeExpectancy DECIMAL(3,1)); INSERT INTO LifeExpectancyData (Country, Gender, LifeExpectancy) VALUES ('Canada', 'Men', 80.1), ('Canada', 'Women', 84.3), ('USA', 'Men', 76.2), ('USA', 'Women', 81.6);
What is the average life expectancy for men and women in each country?
SELECT Country, Gender, AVG(LifeExpectancy) AS AvgLifeExp FROM LifeExpectancyData GROUP BY Country, Gender;
gretelai_synthetic_text_to_sql
CREATE TABLE climate_finance (id INT, project_name TEXT, budget INT, location TEXT); INSERT INTO climate_finance (id, project_name, budget, location) VALUES (1, 'Coral Reef Restoration', 25000, 'South America'); INSERT INTO climate_finance (id, project_name, budget, location) VALUES (2, 'Mangrove Planting', 30000, 'Asia');
What is the minimum budget of climate finance projects in South America?
SELECT MIN(budget) FROM climate_finance WHERE location = 'South America';
gretelai_synthetic_text_to_sql
CREATE TABLE vendors (vendor_id INT, ethical_score INT); INSERT INTO vendors (vendor_id, ethical_score) VALUES (1, 90), (2, 75), (3, 85); CREATE TABLE products (product_id INT, organic BOOLEAN); INSERT INTO products (product_id, organic) VALUES (101, TRUE), (102, FALSE), (103, TRUE); CREATE TABLE sales (sale_id INT, vendor_id INT, product_id INT, revenue INT); INSERT INTO sales (sale_id, vendor_id, product_id, revenue) VALUES (1, 1, 101, 500), (2, 1, 102, 300), (3, 2, 101, 400), (4, 3, 103, 600);
What is the total revenue of organic products sold by vendors with a high ethical labor score?
SELECT SUM(sales.revenue) FROM sales JOIN vendors ON sales.vendor_id = vendors.vendor_id JOIN products ON sales.product_id = products.product_id WHERE products.organic = TRUE AND vendors.ethical_score >= 80;
gretelai_synthetic_text_to_sql
CREATE TABLE IncidentTimes (id INT, incident_id INT, incident_time TIME); CREATE TABLE EmergencyIncidents (id INT, district_id INT, incident_date DATE); INSERT INTO IncidentTimes (id, incident_id, incident_time) VALUES (1, 1, '12:00:00'), (2, 2, '21:00:00'), (3, 3, '06:00:00'), (4, 4, '18:00:00'); INSERT INTO EmergencyIncidents (id, district_id, incident_date) VALUES (1, 1, '2021-12-01'), (2, 2, '2021-12-02'), (3, 3, '2021-12-03'), (4, 4, '2021-12-04');
Calculate the percentage of emergency incidents in each district that occurred at night (between 8 PM and 6 AM) during the last month.
SELECT district_id, COUNT(*) * 100.0 / SUM(COUNT(*)) OVER (PARTITION BY district_id) as pct_night_incidents FROM EmergencyIncidents e JOIN IncidentTimes i ON e.id = i.incident_id WHERE incident_time BETWEEN '20:00:00' AND '06:00:00' AND incident_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) AND CURRENT_DATE GROUP BY district_id;
gretelai_synthetic_text_to_sql
CREATE TABLE security_incidents (id INT, department VARCHAR(255), resolution_time INT, timestamp DATETIME, SLA_time INT);
What is the percentage of security incidents resolved within the SLA for each department in the last month?
SELECT department, 100.0 * COUNT(*) / (SELECT COUNT(*) FROM security_incidents WHERE department = security_incidents.department AND timestamp >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH)) as percentage_SLA FROM security_incidents WHERE resolution_time <= SLA_time AND timestamp >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY department;
gretelai_synthetic_text_to_sql
CREATE TABLE ingredients (ingredient_id INT, ingredient_name VARCHAR(50), is_gluten_free BOOLEAN, quantity INT); INSERT INTO ingredients (ingredient_id, ingredient_name, is_gluten_free, quantity) VALUES (1, 'Quinoa', TRUE, 50), (2, 'Tomatoes', TRUE, 200), (3, 'Chickpeas', FALSE, 100), (4, 'Beef', FALSE, 30), (5, 'Vegan Cheese', TRUE, 80), (6, 'Wheat Flour', FALSE, 70), (7, 'Gluten-Free Flour', TRUE, 60);
What is the total quantity of gluten-free ingredients?
SELECT SUM(quantity) FROM ingredients WHERE is_gluten_free = TRUE;
gretelai_synthetic_text_to_sql
CREATE TABLE Social_Impact_Scores (id INT, organization_name TEXT, social_impact_score INT); INSERT INTO Social_Impact_Scores (id, organization_name, social_impact_score) VALUES (1, 'Save the Children', 65), (2, 'World Wildlife Fund', 80), (3, 'Oxfam', 68);
List the organizations with a social impact score below 70, along with their respective scores.
SELECT organization_name, social_impact_score FROM Social_Impact_Scores WHERE social_impact_score < 70;
gretelai_synthetic_text_to_sql
CREATE TABLE space_projects (project_name VARCHAR(255), start_year INT, end_year INT, total_cost FLOAT); INSERT INTO space_projects (project_name, start_year, end_year, total_cost) VALUES ('Mars Exploration Program', 2020, 2030, 2500000000.00);
What was the total cost of the Mars Exploration Program in 2025?
SELECT total_cost FROM space_projects WHERE project_name = 'Mars Exploration Program' AND YEAR(2025 BETWEEN start_year AND end_year);
gretelai_synthetic_text_to_sql
CREATE TABLE Manufacturer(Id INT, Name VARCHAR(50), Location VARCHAR(50)); CREATE TABLE Chemical(Id INT, Name VARCHAR(50), ManufacturerId INT, QuantityProduced INT, ProductionDate DATE);
What are the total quantities of chemicals produced by each manufacturer, grouped by month?
SELECT m.Name, DATE_FORMAT(c.ProductionDate, '%Y-%m') AS Month, SUM(c.QuantityProduced) AS TotalQuantity FROM Chemical c JOIN Manufacturer m ON c.ManufacturerId = m.Id GROUP BY m.Name, Month;
gretelai_synthetic_text_to_sql
CREATE TABLE authors (id INT PRIMARY KEY, name VARCHAR(255)); INSERT INTO authors (id, name) VALUES (1, 'Stephen King'); INSERT INTO authors (id, name) VALUES (2, 'J.R.R. Tolkien'); CREATE TABLE books (id INT PRIMARY KEY, title VARCHAR(255), author_id INT, publication_year INT, category VARCHAR(255)); INSERT INTO books (id, title, author_id, publication_year, category) VALUES (1, 'The Shining', 1, 1977, 'Fiction'); INSERT INTO books (id, title, author_id, publication_year, category) VALUES (2, 'The Hobbit', 2, 1937, 'Fiction'); INSERT INTO books (id, title, author_id, publication_year, category) VALUES (3, 'The Lord of the Rings', 2, 1954, 'Fiction'); CREATE TABLE categories (id INT PRIMARY KEY, category VARCHAR(255)); INSERT INTO categories (id, category) VALUES (1, 'Fiction'); INSERT INTO categories (id, category) VALUES (2, 'Children');
Which authors have published more than one book in the 'Fiction' category?
SELECT a.name FROM authors a INNER JOIN books b ON a.id = b.author_id INNER JOIN categories c ON b.category = c.category WHERE a.id = b.author_id AND c.category = 'Fiction' GROUP BY a.name HAVING COUNT(b.id) > 1;
gretelai_synthetic_text_to_sql
CREATE TABLE ports (id INT, name VARCHAR(50)); CREATE TABLE import_activities (port_id INT, port_name VARCHAR(50), cargo_type VARCHAR(50)); CREATE TABLE export_activities (port_id INT, port_name VARCHAR(50), cargo_type VARCHAR(50));
List the ports where both import and export activities are present.
SELECT DISTINCT p.name FROM ports p INNER JOIN import_activities ia ON p.name = ia.port_name INNER JOIN export_activities ea ON p.name = ea.port_name;
gretelai_synthetic_text_to_sql
CREATE TABLE Shipments (id INT, destination VARCHAR(50), packages INT, timestamp DATE); INSERT INTO Shipments (id, destination, packages, timestamp) VALUES (1, 'Jakarta', 50, '2021-09-26'), (2, 'Bandung', 30, '2021-09-27'), (3, 'Surabaya', 40, '2021-09-28'), (4, 'Bali', 55, '2021-09-29'), (5, 'Yogyakarta', 60, '2021-09-30');
Find the total number of packages shipped to each destination in the last 5 days of September 2021
SELECT destination, SUM(packages) FROM Shipments WHERE timestamp BETWEEN '2021-09-26' AND '2021-09-30' GROUP BY destination;
gretelai_synthetic_text_to_sql
CREATE TABLE food_distributions (id INT, country VARCHAR(20), person_id INT, distribution_date DATE, quantity INT);
What is the average monthly food distribution per person in Kenya and Tanzania?
SELECT country, AVG(quantity) as avg_monthly_distribution FROM (SELECT country, person_id, DATE_TRUNC('month', distribution_date) as distribution_month, SUM(quantity) as quantity FROM food_distributions GROUP BY country, person_id, distribution_month) as subquery GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE Sales (id INT, product_id INT, size VARCHAR(10), price DECIMAL(5,2), sale_date DATE); INSERT INTO Sales (id, product_id, size, price, sale_date) VALUES (1, 1, '2XL', 50.00, '2022-04-01'), (2, 2, 'XS', 30.00, '2022-05-15');
How can I update the price of all size 2XL clothing items in the 'Sales' table to $60, for sales made in the last month?
UPDATE Sales SET price = 60.00 WHERE size = '2XL' AND sale_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);
gretelai_synthetic_text_to_sql
CREATE TABLE ProtectedHabitats (id INT, animal_id INT, species VARCHAR(255), size FLOAT, region VARCHAR(255)); INSERT INTO ProtectedHabitats (id, animal_id, species, size, region) VALUES (1, 1, 'Lion', 5.6, 'Africa'), (2, 2, 'Elephant', 3.2, 'Asia'), (3, 3, 'Tiger', 7.8, 'Africa');
What is the number of animals in protected habitats for each species and region?
SELECT species, region, COUNT(animal_id) FROM ProtectedHabitats GROUP BY species, region;
gretelai_synthetic_text_to_sql
CREATE TABLE space_debris (id INTEGER, country TEXT, debris_count INTEGER); INSERT INTO space_debris (id, country, debris_count) VALUES (1, 'USA', 3000), (2, 'Russia', 2500), (3, 'China', 2000), (4, 'India', 1000), (5, 'Japan', 800);
Which countries are responsible for the most space debris?
SELECT country, debris_count FROM space_debris ORDER BY debris_count DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE economic_diversification_efforts (id INT, country VARCHAR(50), effort_name VARCHAR(100), start_date DATE, end_date DATE, budget DECIMAL(10,2), success_status VARCHAR(50));
What is the total budget for all economic diversification efforts in Indonesia that were not successfully implemented?
SELECT SUM(budget) FROM economic_diversification_efforts WHERE country = 'Indonesia' AND success_status != 'Successfully Implemented';
gretelai_synthetic_text_to_sql
CREATE TABLE mining_sites (site_id INT, site_ownership VARCHAR(50), year INT, water_consumption INT); INSERT INTO mining_sites (site_id, site_ownership, year, water_consumption) VALUES (1, 'Company C', 2020, 12000); INSERT INTO mining_sites (site_id, site_ownership, year, water_consumption) VALUES (2, 'Company D', 2020, 15000); INSERT INTO mining_sites (site_id, site_ownership, year, water_consumption) VALUES (3, 'Company C', 2020, 18000);
What is the total water consumption per mining site, grouped by mine ownership in the 'mining_sites' table?
SELECT site_ownership, SUM(water_consumption) FROM mining_sites GROUP BY site_ownership;
gretelai_synthetic_text_to_sql
CREATE TABLE Artifacts (Artifact_ID INT, Name TEXT, Era TEXT); INSERT INTO Artifacts (Artifact_ID, Name, Era) VALUES (1, 'Jade Figurine', 'Preclassic'), (2, 'Ceramic Pot', 'Classic');
Which artifacts were found in the 'Classic' era?
SELECT Name FROM Artifacts WHERE Era='Classic';
gretelai_synthetic_text_to_sql
CREATE TABLE tunnel (id INT, name TEXT, city TEXT, construction_date DATE, construction_company TEXT); INSERT INTO tunnel (id, name, city, construction_date, construction_company) VALUES (1, 'Tunnel A', 'London', '2020-01-01', 'Company A'); INSERT INTO tunnel (id, name, city, construction_date, construction_company) VALUES (2, 'Tunnel B', 'London', '2018-01-01', 'Company B');
Identify the number of tunnels in the city of London that have been built in the last 5 years and their respective construction companies.
SELECT COUNT(*), construction_company FROM tunnel WHERE city = 'London' AND construction_date >= '2016-01-01' GROUP BY construction_company;
gretelai_synthetic_text_to_sql
CREATE TABLE defendant_events (id INT, defendant_id INT, event_type VARCHAR(255), timestamp TIMESTAMP); INSERT INTO defendant_events (id, defendant_id, event_type, timestamp) VALUES (1, 1, 'Arrest', '2022-01-01 10:00:00'); INSERT INTO defendant_events (id, defendant_id, event_type, timestamp) VALUES (2, 1, 'Arraignment', '2022-01-02 14:00:00');
What is the sequence of case events for each defendant, ordered by their timestamp?
SELECT defendant_id, event_type, timestamp, ROW_NUMBER() OVER(PARTITION BY defendant_id ORDER BY timestamp) as sequence FROM defendant_events;
gretelai_synthetic_text_to_sql
CREATE TABLE mine (id INT, name TEXT, location TEXT); INSERT INTO mine (id, name, location) VALUES (1, 'Mine I', 'Country R'), (2, 'Mine J', 'Country Q'); CREATE TABLE accident_report (mine_id INT, timestamp TIMESTAMP); INSERT INTO accident_report (mine_id, timestamp) VALUES (1, '2022-01-01 00:00:00'), (2, '2022-02-01 00:00:00');
What is the total number of accidents for each mine in the last year?
SELECT mine_id, COUNT(*) as num_accidents FROM accident_report WHERE timestamp >= DATEADD(year, -1, CURRENT_TIMESTAMP) GROUP BY mine_id;
gretelai_synthetic_text_to_sql
CREATE TABLE application (name VARCHAR(255), country VARCHAR(255), publications INTEGER); INSERT INTO application (name, country, publications) VALUES ('Japan', 'Japan', 300), ('Germany', 'Germany', 250), ('Canada', 'Canada', 200), ('Australia', 'Australia', 180), ('Brazil', 'Brazil', 150);
Which countries have published the most creative AI applications?
SELECT country, SUM(publications) as total_publications FROM application GROUP BY country ORDER BY total_publications DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE hotels (id INT, name TEXT, region TEXT, rating FLOAT, reviews INT); INSERT INTO hotels (id, name, region, rating, reviews) VALUES (1, 'Hotel Asia', 'APAC', 4.2, 180), (2, 'Hotel Europe', 'EMEA', 4.5, 220), (3, 'Hotel Americas', 'Americas', 4.7, 250), (4, 'Hotel APAC', 'APAC', 4.1, 120);
What is the average rating of hotels in the APAC region that have more than 150 reviews?
SELECT AVG(rating) FROM hotels WHERE region = 'APAC' AND reviews > 150;
gretelai_synthetic_text_to_sql
CREATE TABLE rural_hospitals (hospital_id INT, hospital_name VARCHAR(100), province VARCHAR(50), num_staff INT); INSERT INTO rural_hospitals (hospital_id, hospital_name, province, num_staff) VALUES (1, 'Hospital A', 'Jiangsu', 55), (2, 'Hospital B', 'Jiangsu', 65), (3, 'Hospital C', 'Shandong', 45), (4, 'Hospital D', 'Shandong', 75);
What is the minimum and maximum number of rural hospitals per province in Asia and how many of these hospitals are located in provinces with more than 50 rural hospitals?
SELECT MIN(num_staff) AS min_staff, MAX(num_staff) AS max_staff, COUNT(*) FILTER (WHERE num_staff > 50) AS hospitals_in_provinces_with_more_than_50_hospitals FROM ( SELECT province, COUNT(*) AS num_staff FROM rural_hospitals GROUP BY province ) subquery;
gretelai_synthetic_text_to_sql
CREATE TABLE sales (id INT, strain VARCHAR(50), state VARCHAR(50), month INT, year INT, revenue INT); INSERT INTO sales (id, strain, state, month, year, revenue) VALUES (1, 'Blue Dream', 'Colorado', 7, 2021, 150000);
Which strain had the highest sales in the month of July 2021 in the state of Colorado?
SELECT strain, MAX(revenue) FROM sales WHERE state = 'Colorado' AND month = 7 GROUP BY strain;
gretelai_synthetic_text_to_sql
CREATE TABLE riders (rider_id INT, name VARCHAR(255), address VARCHAR(255)); INSERT INTO riders (rider_id, name, address) VALUES (1, 'John Smith', '456 Elm St'), (2, 'Jane Doe', '742 Pine St'), (3, 'Liam Johnson', '321 Maple St');
Update rider 'Liam Johnson's' address to '789 Oak St'
UPDATE riders SET address = '789 Oak St' WHERE name = 'Liam Johnson';
gretelai_synthetic_text_to_sql
CREATE TABLE renewable_capacity (id INT, country VARCHAR(255), technology VARCHAR(255), capacity FLOAT);
What is the total installed renewable energy capacity in India, and how does it break down by technology?
SELECT technology, SUM(capacity) FROM renewable_capacity WHERE country = 'India' GROUP BY technology;
gretelai_synthetic_text_to_sql
CREATE TABLE companies (id INT, name TEXT, industry TEXT, founding_year INT, founder_gender TEXT, underrepresented_minority BOOLEAN); INSERT INTO companies (id, name, industry, founding_year, founder_gender, underrepresented_minority) VALUES (1, 'GreenTech', 'Energy', 2017, 'Male', TRUE); INSERT INTO companies (id, name, industry, founding_year, founder_gender, underrepresented_minority) VALUES (2, 'PowerGen', 'Energy', 2019, 'Female', FALSE); CREATE TABLE funding_records (company_id INT, funding_amount INT); INSERT INTO funding_records (company_id, funding_amount) VALUES (1, 12000000); INSERT INTO funding_records (company_id, funding_amount) VALUES (2, 8000000);
Find the number of companies founded by underrepresented minorities in the energy sector with funding records higher than $10 million.
SELECT COUNT(*) FROM companies JOIN funding_records ON companies.id = funding_records.company_id WHERE companies.industry = 'Energy' AND companies.underrepresented_minority = TRUE AND funding_records.funding_amount > 10000000;
gretelai_synthetic_text_to_sql
CREATE TABLE clients (client_id INT, name VARCHAR(100), age INT, country VARCHAR(50), financial_wellbeing_score INT); INSERT INTO clients (client_id, name, age, country, financial_wellbeing_score) VALUES (13, 'Ravi Patel', 32, 'India', 80);
What is the average age of clients in India with a financial wellbeing score greater than 70?
SELECT AVG(age) FROM clients c WHERE country = 'India' AND (SELECT COUNT(*) FROM financial_assessments fa WHERE fa.client_id = c.client_id AND fa.score > 70) > 0;
gretelai_synthetic_text_to_sql
CREATE TABLE events (id INT, name VARCHAR(255), category VARCHAR(255), date DATE, revenue DECIMAL(10, 2));
What is the total revenue by event category for events before 2022?
SELECT category, SUM(revenue) FROM events WHERE date < '2022-01-01' GROUP BY category;
gretelai_synthetic_text_to_sql
CREATE TABLE peruvian_departments (id INT, name VARCHAR(50)); CREATE TABLE chilean_regions (id INT, name VARCHAR(50)); CREATE TABLE mining_operations (id INT, country_id INT, region VARCHAR(20), annual_co2_emissions INT); INSERT INTO peruvian_departments (id, name) VALUES (1, 'Piura'), (2, 'Arequipa'); INSERT INTO chilean_regions (id, name) VALUES (1, 'Antofagasta'), (2, 'Atacama'); INSERT INTO mining_operations (id, country_id, region, annual_co2_emissions) VALUES (1, 1, 'Peru', 5000), (2, 1, 'Peru', 6000), (3, 2, 'Chile', 7000), (4, 2, 'Chile', 8000);
List all mining operations in Peru and Chile with their environmental impact stats?
SELECT m.id, m.region, m.annual_co2_emissions FROM mining_operations m INNER JOIN (SELECT * FROM peruvian_departments WHERE name IN ('Piura', 'Arequipa') UNION ALL SELECT * FROM chilean_regions WHERE name IN ('Antofagasta', 'Atacama')) c ON m.country_id = c.id;
gretelai_synthetic_text_to_sql
CREATE TABLE lending_initiatives (initiative_id INT, initiative_name VARCHAR(50), budget DECIMAL(18,2));
List all socially responsible lending initiatives with a budget greater than $10 million
SELECT initiative_name FROM lending_initiatives WHERE budget > 10000000;
gretelai_synthetic_text_to_sql
CREATE TABLE SupportPrograms (Id INT, Program VARCHAR(50), Region VARCHAR(30), Budget DECIMAL(10, 2)); INSERT INTO SupportPrograms (Id, Program, Region, Budget) VALUES (1, 'Sign Language Interpreters', 'APAC', 50000), (2, 'Assistive Technology', 'APAC', 80000), (3, 'Adaptive Furniture', 'APAC', 30000), (4, 'Mobility Equipment', 'APAC', 70000);
What is the average budget allocated for disability support programs in the APAC region?
SELECT AVG(Budget) FROM SupportPrograms WHERE Region = 'APAC';
gretelai_synthetic_text_to_sql
CREATE TABLE EnergyProduction (City VARCHAR(50), EnergyType VARCHAR(50), Production FLOAT); INSERT INTO EnergyProduction (City, EnergyType, Production) VALUES ('New York', 'Solar', 50.0), ('New York', 'Wind', 75.0), ('London', 'Solar', 80.0), ('London', 'Wind', 100.0);
What is the total energy production by energy type and city?
SELECT City, EnergyType, SUM(Production) AS TotalProduction FROM EnergyProduction GROUP BY City, EnergyType;
gretelai_synthetic_text_to_sql
CREATE TABLE production_data (year INT, element VARCHAR(10), quantity INT); INSERT INTO production_data (year, element, quantity) VALUES (2018, 'Terbium', 100), (2019, 'Terbium', 120), (2020, 'Terbium', 150), (2021, 'Terbium', 180);
What is the maximum production of Terbium in a single year?
SELECT MAX(quantity) FROM production_data WHERE element = 'Terbium';
gretelai_synthetic_text_to_sql
stations (id, name, city, country, latitude, longitude)
Update the latitude and longitude for stations in the city of Tokyo, Japan in the stations table.
UPDATE stations SET latitude = 35.6895, longitude = 139.6917 WHERE stations.city = 'Tokyo';
gretelai_synthetic_text_to_sql
CREATE TABLE electric_vehicles (vehicle_id INT, type VARCHAR(20), city VARCHAR(20)); INSERT INTO electric_vehicles (vehicle_id, type, city) VALUES (1, 'Car', 'Tokyo'), (2, 'Car', 'Tokyo'), (3, 'Bike', 'Tokyo'), (4, 'Car', 'Osaka'), (5, 'Bike', 'Osaka');
How many electric vehicles are there in Tokyo compared to Osaka?
SELECT city, COUNT(*) AS total_evs FROM electric_vehicles WHERE type IN ('Car', 'Bike') GROUP BY city;
gretelai_synthetic_text_to_sql
CREATE TABLE hospitals (id INT, name TEXT, city TEXT, state TEXT, beds INT); INSERT INTO hospitals (id, name, city, state, beds) VALUES (1, 'General Hospital', 'Miami', 'Florida', 500); INSERT INTO hospitals (id, name, city, state, beds) VALUES (2, 'Memorial Hospital', 'Boston', 'Massachusetts', 600);
What is the average number of beds in hospitals by state?
SELECT state, AVG(beds) as avg_beds FROM hospitals GROUP BY state;
gretelai_synthetic_text_to_sql
CREATE TABLE Artworks (ArtworkID INT, Type TEXT, SalePrice INT, CreationYear INT); INSERT INTO Artworks (ArtworkID, Type, SalePrice, CreationYear) VALUES (1, 'Sculpture', 100000, 1901);
What is the average sale price for sculptures from the 20th century?
SELECT AVG(SalePrice) FROM Artworks WHERE Type = 'Sculpture' AND CreationYear BETWEEN 1901 AND 2000;
gretelai_synthetic_text_to_sql
CREATE TABLE cultural_sites (site_id INT, name TEXT, country TEXT); INSERT INTO cultural_sites (site_id, name, country) VALUES (1, 'Taj Mahal', 'India'), (2, 'Hawa Mahal', 'India'), (3, 'Qutub Minar', 'India');
What is the total number of cultural heritage sites in India?
SELECT COUNT(*) FROM cultural_sites WHERE country = 'India';
gretelai_synthetic_text_to_sql
CREATE TABLE states (state_id INT, state_name TEXT, population INT, budget FLOAT);
Find the average budget for education services in each state, excluding states with a population under 500,000
SELECT state_name, AVG(budget) FROM states WHERE population > 500000 GROUP BY state_name;
gretelai_synthetic_text_to_sql
CREATE TABLE Neighborhood (id INT, name VARCHAR(255), city VARCHAR(255), country VARCHAR(255), co_ownership_density FLOAT); CREATE TABLE Property (id INT, neighborhood VARCHAR(255), price FLOAT, co_ownership BOOLEAN);
What is the average price of properties in neighborhoods with a co-ownership density above 0.5, that are higher than the overall average price for co-owned properties?
SELECT Neighborhood.name, AVG(Property.price) as avg_price FROM Neighborhood INNER JOIN Property ON Neighborhood.name = Property.neighborhood WHERE Neighborhood.co_ownership_density > 0.5 GROUP BY Neighborhood.name HAVING AVG(Property.price) > (SELECT AVG(Property.price) FROM Property WHERE Property.co_ownership = TRUE)
gretelai_synthetic_text_to_sql
CREATE TABLE inclusive_housing (id INT, property_id INT, number_of_units INT); INSERT INTO inclusive_housing (id, property_id, number_of_units) VALUES (1, 101, 12), (2, 102, 8), (3, 103, 15);
What is the maximum number of units in a single property in the 'inclusive_housing' table?
SELECT MAX(number_of_units) FROM inclusive_housing;
gretelai_synthetic_text_to_sql