context
stringlengths
11
9.12k
question
stringlengths
0
1.06k
SQL
stringlengths
2
4.44k
source
stringclasses
28 values
CREATE TABLE FashionTrends (TrendID INT, TrendName TEXT, Popularity INT, Revenue INT, SizeDiversityScore INT); INSERT INTO FashionTrends (TrendID, TrendName, Popularity, Revenue, SizeDiversityScore) VALUES (1, 'Athleisure', 8000, 50000, 9), (2, 'Denim', 9000, 60000, 7), (3, 'Boho-Chic', 7000, 40000, 8), (4, 'Minimalism', 6000, 30000, 10); CREATE TABLE SizeDiversity (TrendID INT, SizeDiversityScore INT); INSERT INTO SizeDiversity (TrendID, SizeDiversityScore) VALUES (1, 9), (2, 7), (3, 8), (4, 10);
What is the total revenue for each fashion trend that is popular in the UK and has a size diversity score greater than 8?
SELECT FT.TrendName, SUM(FT.Revenue) FROM FashionTrends FT INNER JOIN SizeDiversity SD ON FT.TrendID = SD.TrendID WHERE FT.Popularity > 8000 AND SD.SizeDiversityScore > 8 GROUP BY FT.TrendName HAVING COUNT(DISTINCT FT.Country) > 1;
gretelai_synthetic_text_to_sql
CREATE TABLE wind_farms (id INT, name TEXT, location TEXT, capacity FLOAT); INSERT INTO wind_farms (id, name, location, capacity) VALUES (1, 'Farm A', 'Texas', 300.2), (2, 'Farm B', 'Texas', 200.1);
How many wind farms are there in 'Texas' that have a capacity of at least 250 MW?
SELECT COUNT(*) FROM wind_farms WHERE location = 'Texas' AND capacity >= 250;
gretelai_synthetic_text_to_sql
CREATE TABLE users (id INT, name VARCHAR(50), location VARCHAR(50), followers INT); INSERT INTO users (id, name, location, followers) VALUES (1, 'Alice', 'Canada', 100); INSERT INTO users (id, name, location, followers) VALUES (2, 'Bob', 'USA', 200); INSERT INTO users (id, name, location, followers) VALUES (3, 'Charlie', 'Mexico', 300);
What is the maximum number of followers for any user, and what is their location?
SELECT location, MAX(followers) as max_followers FROM users;
gretelai_synthetic_text_to_sql
CREATE TABLE forestry_survey (id INT, species VARCHAR(255), diameter FLOAT, height FLOAT, volume FLOAT); INSERT INTO forestry_survey (id, species, diameter, height, volume) VALUES (1, 'Redwood', 5.6, 120, 23.4); INSERT INTO forestry_survey (id, species, diameter, height, volume) VALUES (2, 'Oak', 2.4, 60, 4.2); INSERT INTO forestry_survey (id, species, diameter, height, volume) VALUES (3, 'Pine', 3.8, 80, 12.3);
What is the combined height of all Redwood trees?
SELECT SUM(height) FROM forestry_survey WHERE species = 'Redwood';
gretelai_synthetic_text_to_sql
CREATE TABLE DailySteps (user_id INT, steps INT, activity_date DATE); INSERT INTO DailySteps (user_id, steps, activity_date) VALUES (1, 12000, '2021-01-01'), (2, 8000, '2021-01-02'), (3, 15000, '2021-12-31');
Determine the number of users who achieved over 10,000 steps per day on average in 2021.
SELECT COUNT(*) FROM (SELECT user_id, AVG(steps) avg_steps FROM DailySteps GROUP BY user_id) subquery WHERE avg_steps > 10000;
gretelai_synthetic_text_to_sql
CREATE TABLE recycling_rates (sector VARCHAR(20), material VARCHAR(20), recycling_rate DECIMAL(5,2)); INSERT INTO recycling_rates (sector, material, recycling_rate) VALUES ('residential', 'plastic', 0.25), ('commercial', 'plastic', 0.30), ('residential', 'paper', 0.40), ('commercial', 'paper', 0.50);
What is the recycling rate of plastic in the commercial sector?
SELECT recycling_rate FROM recycling_rates WHERE sector = 'commercial' AND material = 'plastic';
gretelai_synthetic_text_to_sql
CREATE TABLE Companies (id INT, name TEXT, has_exit_strategy BOOLEAN); INSERT INTO Companies (id, name, has_exit_strategy) VALUES (1, 'Star Startup', TRUE); INSERT INTO Companies (id, name, has_exit_strategy) VALUES (2, 'Moonshot Inc', FALSE); CREATE TABLE Investors (id INT, name TEXT); INSERT INTO Investors (id, name) VALUES (1, 'Venture Capital 4'); INSERT INTO Investors (id, name) VALUES (2, 'Angel Investor 4');
Show the number of unique investors who have invested in companies that have an exit strategy.
SELECT COUNT(DISTINCT Investors.name) FROM Companies INNER JOIN Investors ON TRUE WHERE Companies.has_exit_strategy = TRUE;
gretelai_synthetic_text_to_sql
CREATE TABLE smart_transportation_projects (id INT, project_name VARCHAR(255), project_type VARCHAR(255), location VARCHAR(255), start_date DATE, end_date DATE, PRIMARY KEY(id)); INSERT INTO smart_transportation_projects (id, project_name, project_type, location, start_date, end_date) VALUES (1, 'Bike Sharing', 'Transportation', 'Barcelona', '2022-06-01', '2024-05-31'), (2, 'Autonomous Buses', 'Transportation', 'Singapore', '2023-01-15', '2025-01-14'), (3, 'Smart Traffic Lights', 'Transportation', 'Amsterdam', '2023-02-01', '2022-01-31');
Identify smart city projects with overlapping start and end dates.
SELECT project_name, project_type, location, start_date, end_date FROM smart_transportation_projects WHERE start_date <= end_date AND end_date >= start_date;
gretelai_synthetic_text_to_sql
CREATE TABLE union_members (member_id INT, name VARCHAR(50), age INT, union_id INT); CREATE TABLE unions (union_id INT, union_name VARCHAR(50), focus VARCHAR(50)); INSERT INTO union_members (member_id, name, age, union_id) VALUES (1, 'John Doe', 35, 1), (2, 'Jane Smith', 40, 1), (3, 'Mike Johnson', 30, 2); INSERT INTO unions (union_id, union_name, focus) VALUES (1, 'Healthcare Workers Union', 'healthcare'), (2, 'Teachers Union', 'education');
What is the average age of members in unions that have a focus on healthcare?
SELECT AVG(um.age) FROM union_members um INNER JOIN unions u ON um.union_id = u.union_id WHERE u.focus = 'healthcare';
gretelai_synthetic_text_to_sql
CREATE TABLE defense_diplomacy (activity_id INT, country1 TEXT, country2 TEXT); INSERT INTO defense_diplomacy (activity_id, country1, country2) VALUES (1, 'France', 'Germany'), (2, 'Germany', 'France');
What are the defense diplomacy activities between France and Germany?
SELECT * FROM defense_diplomacy WHERE (country1 = 'France' AND country2 = 'Germany') OR (country1 = 'Germany' AND country2 = 'France')
gretelai_synthetic_text_to_sql
CREATE TABLE player_inventory (player_id INT, item_name VARCHAR(50), quantity INT);
Insert new records into the "player_inventory" table with the following data: (1, 'Health Potion', 5), (2, 'Gold Coin', 100)
WITH cte AS (VALUES (1, 'Health Potion', 5), (2, 'Gold Coin', 100)) INSERT INTO player_inventory (player_id, item_name, quantity) SELECT * FROM cte;
gretelai_synthetic_text_to_sql
CREATE TABLE employees (id INT, name VARCHAR(50), gender VARCHAR(50), department VARCHAR(50), role VARCHAR(50)); INSERT INTO employees (id, name, gender, department, role) VALUES (1, 'John Doe', 'male', 'hr', 'employee'); INSERT INTO employees (id, name, gender, department, role) VALUES (2, 'Jane Smith', 'female', 'hr', 'manager'); INSERT INTO employees (id, name, gender, department, role) VALUES (3, 'Bob Johnson', 'male', 'operations', 'employee');
Find the total number of male and female employees in the 'hr' and 'operations' departments and exclude employees from the 'management' role.
SELECT COUNT(*) FILTER (WHERE gender = 'male') AS male_count, COUNT(*) FILTER (WHERE gender = 'female') AS female_count FROM employees WHERE department IN ('hr', 'operations') AND role != 'manager';
gretelai_synthetic_text_to_sql
CREATE TABLE Players (PlayerID INT, PlayerName VARCHAR(50), Game VARCHAR(50)); INSERT INTO Players (PlayerID, PlayerName, Game) VALUES (1, 'Sophia Garcia', 'Battle Royale Adventure'), (2, 'Daniel Kim', 'Rhythm Game 2023'), (3, 'Lila Hernandez', 'Virtual Reality Chess'), (4, 'Kenji Nguyen', 'Racing Simulator 2022');
What is the total number of players who play "Battle Royale Adventure" or "Rhythm Game 2023"?
SELECT COUNT(*) FROM Players WHERE Game IN ('Battle Royale Adventure', 'Rhythm Game 2023');
gretelai_synthetic_text_to_sql
CREATE TABLE Employees (EmployeeID INT, Department VARCHAR(50)); INSERT INTO Employees (EmployeeID, Department) VALUES (1, 'IT'); INSERT INTO Employees (EmployeeID, Department) VALUES (2, 'IT'); INSERT INTO Employees (EmployeeID, Department) VALUES (3, 'HR'); INSERT INTO Employees (EmployeeID, Department) VALUES (4, 'Finance'); CREATE TABLE Training (TrainingID INT, Course VARCHAR(50), EmployeeID INT); INSERT INTO Training (TrainingID, Course, EmployeeID) VALUES (1, 'Diversity and Inclusion', 1); INSERT INTO Training (TrainingID, Course, EmployeeID) VALUES (2, 'Diversity and Inclusion', 3);
Which departments have taken a diversity and inclusion training course?
SELECT Department FROM Employees INNER JOIN Training ON Employees.EmployeeID = Training.EmployeeID WHERE Course = 'Diversity and Inclusion'
gretelai_synthetic_text_to_sql
CREATE TABLE cybersecurity (strategy_id INT, strategy_name VARCHAR(50), description TEXT, last_updated TIMESTAMP);
What is the description of the latest cybersecurity strategy in the 'cybersecurity' table?
SELECT description FROM cybersecurity WHERE strategy_id = (SELECT strategy_id FROM cybersecurity WHERE last_updated = (SELECT MAX(last_updated) FROM cybersecurity));
gretelai_synthetic_text_to_sql
CREATE TABLE marine_species (id INT, species_name VARCHAR(50), ocean VARCHAR(50)); CREATE TABLE research_initiatives (id INT, species_name VARCHAR(50), initiative_id INT);
What are the names of all the marine species that are part of any research initiative in the 'marine_species' and 'research_initiatives' tables?
SELECT species_name FROM marine_species WHERE species_name IN (SELECT species_name FROM research_initiatives);
gretelai_synthetic_text_to_sql
CREATE TABLE sustainability (id INT, project_id INT, sustainable_material VARCHAR(255), amount_used INT); INSERT INTO sustainability (id, project_id, sustainable_material, amount_used) VALUES (1, 1, 'Recycled Steel', 1000), (2, 2, 'Reclaimed Wood', 500), (3, 2, 'Eco-Friendly Paint', 300);
How many sustainable materials were used in total for project with ID 2?
SELECT SUM(amount_used) FROM sustainability WHERE project_id = 2;
gretelai_synthetic_text_to_sql
CREATE TABLE waste_generation (id INT, location VARCHAR(50), generation_date DATE, waste_amount INT); INSERT INTO waste_generation (id, location, generation_date, waste_amount) VALUES (1, 'New York', '2018-01-01', 1000), (2, 'Los Angeles', '2019-01-01', 2000), (3, 'London', '2020-01-01', 1200), (4, 'Sydney', '2019-07-01', 1800), (5, 'Rio de Janeiro', '2018-05-01', 2500);
Delete records in waste_generation table where the generation_date is after 2020-01-01
DELETE FROM waste_generation WHERE generation_date > '2020-01-01';
gretelai_synthetic_text_to_sql
CREATE TABLE artists (id INT, name TEXT, country TEXT); INSERT INTO artists (id, name, country) VALUES (1, 'Taylor Swift', 'United States'), (2, 'Eminem', 'United States'); CREATE TABLE songs (id INT, title TEXT, artist_id INT); INSERT INTO songs (id, title, artist_id) VALUES (1, 'Shake it Off', 1), (2, 'Lose Yourself', 2);
What is the total number of songs produced by artists from the United States?
SELECT COUNT(*) FROM songs JOIN artists ON songs.artist_id = artists.id WHERE artists.country = 'United States';
gretelai_synthetic_text_to_sql
CREATE TABLE organization (org_id INT, org_name TEXT); INSERT INTO organization (org_id, org_name) VALUES (1, 'Volunteers Inc'); INSERT INTO organization (org_id, org_name) VALUES (2, 'Helping Hands');
Add a new organization to the database
INSERT INTO organization (org_id, org_name) VALUES (3, 'Caring Communities');
gretelai_synthetic_text_to_sql
CREATE TABLE maritime_law_violations (id INT PRIMARY KEY, vessel_name VARCHAR(255), violation_type VARCHAR(255), fine FLOAT, violation_date DATE);
List all maritime law violations in the 'maritime_law_violations' table
SELECT * FROM maritime_law_violations;
gretelai_synthetic_text_to_sql
CREATE TABLE marine_protected_areas (id INT, name TEXT, region TEXT, avg_depth FLOAT); INSERT INTO marine_protected_areas (id, name, region, avg_depth) VALUES (1, 'Galapagos Marine Reserve', 'Pacific', 200.5); INSERT INTO marine_protected_areas (id, name, region, avg_depth) VALUES (2, 'Great Barrier Reef', 'Pacific', 91.4);
What is the average depth of all marine protected areas in the Pacific region?'
SELECT AVG(avg_depth) FROM marine_protected_areas WHERE region = 'Pacific';
gretelai_synthetic_text_to_sql
CREATE TABLE operators (operator_id INT, operator_name TEXT); INSERT INTO operators (operator_id, operator_name) VALUES (1, 'Company A'), (2, 'Company B'); CREATE TABLE wells (well_id INT, operator_id INT, location TEXT); INSERT INTO wells (well_id, operator_id, location) VALUES (1, 1, 'Gulf of Mexico'), (2, 1, 'Atlantic'), (3, 2, 'Gulf of Mexico'), (4, 2, 'Caribbean');
Identify the number of wells drilled by each operator in the Gulf of Mexico
SELECT o.operator_name, COUNT(w.well_id) AS num_wells_drilled FROM wells w JOIN operators o ON w.operator_id = o.operator_id WHERE w.location = 'Gulf of Mexico' GROUP BY o.operator_id;
gretelai_synthetic_text_to_sql
CREATE TABLE intelligence_operations (operation_name VARCHAR(255), operation_year INT, country VARCHAR(255)); INSERT INTO intelligence_operations (operation_name, operation_year, country) VALUES ('Operation Red Sparrow', 2018, 'Russia'), ('Operation Black Swan', 2017, 'China');
Present the number of intelligence operations conducted per country in the last 5 years
SELECT country, operation_year FROM intelligence_operations WHERE operation_year BETWEEN (YEAR(CURRENT_DATE) - 5) AND YEAR(CURRENT_DATE) GROUP BY country, operation_year;
gretelai_synthetic_text_to_sql
CREATE TABLE warehouse (id INT, name VARCHAR(255), location VARCHAR(255)); INSERT INTO warehouse (id, name, location) VALUES (1, 'NY', 'New York'), (2, 'LA', 'Los Angeles'); CREATE TABLE inventory (item_code VARCHAR(255), quantity INT, warehouse_id INT); INSERT INTO inventory (item_code, quantity, warehouse_id) VALUES ('EGG-01', 300, 1), ('APP-01', 200, 1), ('ORG-01', 150, 2);
How many items are there in the 'NY' warehouse?
SELECT COUNT(DISTINCT item_code) FROM inventory WHERE warehouse_id = (SELECT id FROM warehouse WHERE location = 'New York');
gretelai_synthetic_text_to_sql
CREATE TABLE basketball_games(id INT, team VARCHAR(50), location VARCHAR(50), year INT, tickets_sold INT); INSERT INTO basketball_games(id, team, location, year, tickets_sold) VALUES (1, 'Portland Trail Blazers', 'Moda Center', 2020, 765000), (2, 'Seattle SuperSonics', 'KeyArena', 2020, 600000), (3, 'Oklahoma City Thunder', 'Chesapeake Energy Arena', 2020, 550000);
Find the total number of tickets sold for basketball games in the Pacific Northwest in 2020.
SELECT SUM(tickets_sold) FROM basketball_games WHERE location IN ('Moda Center', 'KeyArena') AND year = 2020;
gretelai_synthetic_text_to_sql
CREATE TABLE Patients (ID INT, Name TEXT); CREATE TABLE Providers (ID INT, Name TEXT, Type TEXT);
Show the number of patients and providers in the rural healthcare system.
SELECT (SELECT COUNT(*) FROM Patients) + (SELECT COUNT(*) FROM Providers) AS Total;
gretelai_synthetic_text_to_sql
CREATE TABLE initiatives (id INT, leader VARCHAR(255), initiative_type VARCHAR(255)); INSERT INTO initiatives (id, leader, initiative_type) VALUES (1, 'BIPOC Woman', 'digital_divide'), (2, 'White Man', 'digital_divide'), (3, 'BIPOC Man', 'accessibility');
What percentage of digital divide initiatives are led by BIPOC individuals?
SELECT (COUNT(*) FILTER (WHERE leader ILIKE '%BIPOC%')) * 100.0 / COUNT(*) FROM initiatives WHERE initiative_type = 'digital_divide';
gretelai_synthetic_text_to_sql
CREATE TABLE songs (id INT, title VARCHAR(255), duration INT, genre VARCHAR(255)); INSERT INTO songs (id, title, duration, genre) VALUES (1, 'Song 1', 180, 'Pop');
What is the total duration of all songs in the pop genre?
SELECT SUM(duration) FROM songs WHERE genre = 'Pop';
gretelai_synthetic_text_to_sql
CREATE TABLE Productivity_Silver (mineral TEXT, region TEXT, productivity REAL); INSERT INTO Productivity_Silver (mineral, region, productivity) VALUES ('Silver', 'Africa', 3.2); INSERT INTO Productivity_Silver (mineral, region, productivity) VALUES ('Silver', 'Asia', 3.6); INSERT INTO Productivity_Silver (mineral, region, productivity) VALUES ('Silver', 'Europe', 3.4);
Calculate the average productivity for 'Silver' mineral extractions in all regions.
SELECT AVG(productivity) FROM Productivity_Silver WHERE mineral = 'Silver';
gretelai_synthetic_text_to_sql
CREATE TABLE military_aircrafts(id INT, type VARCHAR(255), manufacturer VARCHAR(255), year INT, contractor VARCHAR(255));
What is the total number of military aircrafts by type, maintained by contractor X in the year 2020?
SELECT type, COUNT(*) as total FROM military_aircrafts WHERE contractor = 'X' AND year = 2020 GROUP BY type;
gretelai_synthetic_text_to_sql
CREATE TABLE manufacturers (id INT PRIMARY KEY, name TEXT, location TEXT, is_fair_trade BOOLEAN); CREATE TABLE products (id INT PRIMARY KEY, name TEXT, category TEXT, price DECIMAL, manufacturer_id INT, FOREIGN KEY (manufacturer_id) REFERENCES manufacturers(id));
What is the percentage of products made by fair trade manufacturers?
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM products)) FROM products p JOIN manufacturers m ON p.manufacturer_id = m.id WHERE m.is_fair_trade = TRUE;
gretelai_synthetic_text_to_sql
CREATE TABLE Region (RegionID INT, RegionName VARCHAR(255)); INSERT INTO Region (RegionID, RegionName) VALUES (1, 'RegionX'), (2, 'RegionY'), (3, 'RegionZ'); CREATE TABLE Fare (FareID INT, RegionID INT, FareAmount DECIMAL(5,2)); INSERT INTO Fare (FareID, RegionID, FareAmount) VALUES (1, 1, 3.50), (2, 1, 2.80), (3, 2, 4.20), (4, 2, 3.90), (5, 3, 1.50), (6, 3, 1.80);
What is the maximum fare for public transportation in each region?
SELECT Region.RegionName, MAX(FareAmount) FROM Region JOIN Fare ON Region.RegionID = Fare.RegionID GROUP BY Region.RegionName;
gretelai_synthetic_text_to_sql
CREATE TABLE CityBudget (BudgetID INT PRIMARY KEY, Department VARCHAR(50), BudgetAmount DECIMAL(10, 2)); INSERT INTO CityBudget (BudgetID, Department, BudgetAmount) VALUES (1, 'Public Works', 250000.00), (2, 'Education', 750000.00), (3, 'Parks and Recreation', 150000.00);
What is the budget for the Parks and Recreation department after a 10% increase?
UPDATE CityBudget SET BudgetAmount = BudgetAmount * 1.1 WHERE Department = 'Parks and Recreation';
gretelai_synthetic_text_to_sql
CREATE TABLE Accidents (ID INT PRIMARY KEY, VesselID INT, Region TEXT); INSERT INTO Accidents (ID, VesselID, Region) VALUES (1, 1, 'Atlantic'), (2, 2, 'Pacific'), (3, 3, 'Atlantic');
How many accidents were reported for vessels in the 'Pacific' region?
SELECT COUNT(*) FROM Accidents WHERE Region = 'Pacific';
gretelai_synthetic_text_to_sql
CREATE TABLE Accommodations (student_id INT, accommodation_type TEXT); CREATE VIEW Accommodation_Counts AS SELECT accommodation_type, COUNT(*) FROM Accommodations GROUP BY accommodation_type;
How many students have been served in each accommodation category?
SELECT * FROM Accommodation_Counts;
gretelai_synthetic_text_to_sql
CREATE TABLE sales (salesperson VARCHAR(20), revenue INT); INSERT INTO sales (salesperson, revenue) VALUES ('John', 5000), ('Jane', 7000), ('Doe', 6000);
What is the total revenue for each salesperson in the sales database?
SELECT salesperson, SUM(revenue) FROM sales GROUP BY salesperson;
gretelai_synthetic_text_to_sql
CREATE TABLE Runs (id INT, user_id INT, distance FLOAT, neighborhood TEXT); INSERT INTO Runs (id, user_id, distance, neighborhood) VALUES (1, 1, 5.6, 'West Village'), (2, 2, 7.2, 'Silver Lake');
What is the average distance run by users in a specific neighborhood?
SELECT AVG(distance) FROM Runs WHERE neighborhood = 'West Village';
gretelai_synthetic_text_to_sql
CREATE TABLE cargo (id INT, vessel_name VARCHAR(255), port_name VARCHAR(255), weight INT); INSERT INTO cargo (id, vessel_name, port_name, weight) VALUES (1, 'Seafarer', 'Port of Los Angeles', 5000), (2, 'Oceanus', 'Port of New York', 7000), (3, 'Neptune', 'Port of Singapore', 8000), (4, 'Seafarer', 'Port of Los Angeles', 6000);
What is the maximum cargo weight handled by the ACME Shipping Company in a single port call?
SELECT MAX(weight) FROM cargo WHERE vessel_name IN (SELECT name FROM vessels WHERE company = 'ACME Shipping');
gretelai_synthetic_text_to_sql
CREATE TABLE marine_protected_areas (name VARCHAR(255), location VARCHAR(255), depth FLOAT); INSERT INTO marine_protected_areas (name, location, depth) VALUES ('MPA 1', 'Indian', 150.7); INSERT INTO marine_protected_areas (name, location, depth) VALUES ('MPA 2', 'Atlantic', 200.3);
What is the average depth of all marine protected areas in the Indian and Atlantic regions?
SELECT AVG(depth) FROM marine_protected_areas WHERE location IN ('Indian', 'Atlantic');
gretelai_synthetic_text_to_sql
CREATE TABLE countries (country_code CHAR(2), country_name VARCHAR(50)); CREATE TABLE protected_areas (area_id INT, area_name VARCHAR(50), country_code CHAR(2)); INSERT INTO countries (country_code, country_name) VALUES ('CA', 'Canada'), ('US', 'United States'), ('DK', 'Denmark'); INSERT INTO protected_areas (area_id, area_name, country_code) VALUES (1, 'Waterton Lakes National Park', 'CA'), (2, 'Banff National Park', 'CA'), (3, 'Glacier National Park', 'US'), (4, 'Thy National Park', 'DK');
What is the total number of protected areas in each country?
SELECT country_code, COUNT(*) as total_protected_areas FROM protected_areas GROUP BY country_code;
gretelai_synthetic_text_to_sql
CREATE TABLE research_grants (id INT, pi_gender VARCHAR(10), year INT, amount INT); INSERT INTO research_grants (id, pi_gender, year, amount) VALUES (1, 'Female', 2020, 50000); INSERT INTO research_grants (id, pi_gender, year, amount) VALUES (2, 'Male', 2019, 75000);
What is the total amount of research grants awarded to women principal investigators in the last 3 years?
SELECT SUM(amount) FROM research_grants WHERE pi_gender = 'Female' AND year BETWEEN 2019 AND 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE ai_adoption (hotel_id INT, hotel_name VARCHAR(255), region VARCHAR(255), ai_adopted INT);
How many hotels adopted AI in the Americas and Europe?
SELECT SUM(ai_adopted) FROM ai_adoption WHERE region IN ('Americas', 'Europe');
gretelai_synthetic_text_to_sql
CREATE TABLE product_types (id INT, product_type VARCHAR(50)); INSERT INTO product_types (id, product_type) VALUES (1, 'Stocks'), (2, 'Bonds'); CREATE TABLE transactions (product_type_id INT, transaction_amount DECIMAL(10,2)); INSERT INTO transactions (product_type_id, transaction_amount) VALUES (1, 200.00), (1, 300.00), (2, 100.00), (2, 400.00);
What is the average transaction amount for each product type?
SELECT p.product_type, AVG(t.transaction_amount) as avg_transaction_amount FROM product_types p JOIN transactions t ON p.id = t.product_type_id GROUP BY p.product_type;
gretelai_synthetic_text_to_sql
CREATE TABLE workouts (id INT, user_id INT, workout_type VARCHAR(20), duration INT); INSERT INTO workouts (id, user_id, workout_type, duration) VALUES (1, 101, 'Strength Training', 60), (2, 102, 'Strength Training', 90), (3, 103, 'Strength Training', 45), (4, 104, 'Yoga', 30); CREATE TABLE users (id INT, birthdate DATE); INSERT INTO users (id, birthdate) VALUES (101, '1996-01-01'), (102, '1989-05-20'), (103, '1978-12-15'), (104, '2000-06-03');
What is the total duration of strength training workouts for users aged 25-35?
SELECT SUM(duration) as total_duration FROM workouts JOIN users ON workouts.user_id = users.id WHERE users.birthdate BETWEEN '1986-01-01' AND '1996-12-31' AND workout_type = 'Strength Training';
gretelai_synthetic_text_to_sql
CREATE TABLE menu_items (item_id INT, name VARCHAR(255), category VARCHAR(255)); INSERT INTO menu_items (item_id, name, category) VALUES (1, 'Burger', 'Main Course'), (2, 'Salad', 'Side Dish'); CREATE TABLE inspections (inspection_id INT, item_id INT, date DATE, result VARCHAR(255)); INSERT INTO inspections (inspection_id, item_id, date, result) VALUES (1, 1, '2022-02-01', 'Passed'), (2, 1, '2022-02-15', 'Passed'), (3, 2, '2022-02-10', 'Failed');
Which menu items were inspected by the Food Safety Agency in the last 30 days?
SELECT m.name, i.date FROM menu_items m JOIN inspections i ON m.item_id = i.item_id WHERE i.date >= DATE(NOW()) - INTERVAL 30 DAY;
gretelai_synthetic_text_to_sql
CREATE TABLE school_funding (state VARCHAR(255), year INT, school_name VARCHAR(255), funding_amount FLOAT); INSERT INTO school_funding (state, year, school_name, funding_amount) VALUES ('California', 2021, 'School A', 500000.00), ('California', 2021, 'School B', 600000.00), ('California', 2021, 'School C', 700000.00), ('California', 2022, 'School A', 550000.00), ('California', 2022, 'School B', 650000.00), ('California', 2022, 'School C', 750000.00); CREATE TABLE schools (school_name VARCHAR(255), school_type VARCHAR(255)); INSERT INTO schools (school_name, school_type) VALUES ('School A', 'Public'), ('School B', 'Public'), ('School C', 'Public');
What is the total amount of funding received by public schools in the state of California in 2021 and 2022, using a cross join?
SELECT s.school_name, SUM(sf.funding_amount) AS total_funding_amount FROM school_funding sf CROSS JOIN schools s WHERE sf.state = 'California' AND sf.year IN (2021, 2022) AND s.school_type = 'Public' GROUP BY s.school_name;
gretelai_synthetic_text_to_sql
CREATE TABLE mobile_subscribers_2 (id INT, country VARCHAR(20), technology VARCHAR(10)); INSERT INTO mobile_subscribers_2 (id, country, technology) VALUES (1, 'USA', '4G'); INSERT INTO mobile_subscribers_2 (id, country, technology) VALUES (2, 'Canada', '5G');
Calculate the percentage of mobile subscribers using 4G technology in each country.
SELECT country, technology, COUNT(*) as total, (COUNT(*) FILTER (WHERE technology = '4G')::FLOAT / COUNT(*)) * 100 as percentage FROM mobile_subscribers_2 GROUP BY country, technology HAVING technology = '4G';
gretelai_synthetic_text_to_sql
CREATE TABLE accessible_tech (region VARCHAR(20), initiatives INT); INSERT INTO accessible_tech (region, initiatives) VALUES ('Africa', 50), ('Asia', 75), ('South America', 100);
What is the number of accessible technology initiatives in Asia?
SELECT initiatives FROM accessible_tech WHERE region = 'Asia';
gretelai_synthetic_text_to_sql
CREATE TABLE carbon_pricing (country VARCHAR(20), carbon_price DECIMAL(5,2)); INSERT INTO carbon_pricing (country, carbon_price) VALUES ('Germany', 25.00), ('France', 32.00), ('USA', 12.00), ('UK', 28.00), ('Italy', 22.00), ('India', 8.00), ('Canada', 18.00);
What is the average carbon price in India and Canada?
SELECT AVG(carbon_price) FROM carbon_pricing WHERE country IN ('India', 'Canada');
gretelai_synthetic_text_to_sql
CREATE TABLE HealthPolicyTypes (PolicyTypeID int, PolicyType varchar(20)); CREATE TABLE HealthClaims (ClaimID int, PolicyTypeID int, ClaimAmount decimal); INSERT INTO HealthPolicyTypes (PolicyTypeID, PolicyType) VALUES (1, 'Health Maintenance Organization'); INSERT INTO HealthPolicyTypes (PolicyTypeID, PolicyType) VALUES (2, 'Preferred Provider Organization'); INSERT INTO HealthClaims (ClaimID, PolicyTypeID, ClaimAmount) VALUES (1, 1, 1200); INSERT INTO HealthClaims (ClaimID, PolicyTypeID, ClaimAmount) VALUES (2, 2, 1800);
List health insurance policy types and their respective average claim amounts.
SELECT HealthPolicyTypes.PolicyType, AVG(HealthClaims.ClaimAmount) FROM HealthPolicyTypes INNER JOIN HealthClaims ON HealthPolicyTypes.PolicyTypeID = HealthClaims.PolicyTypeID GROUP BY HealthPolicyTypes.PolicyType;
gretelai_synthetic_text_to_sql
CREATE TABLE investigative_projects (project_id INT, project_name VARCHAR(255), status VARCHAR(20), assigned_to INT);
Delete all records from the 'investigative_projects' table where the project is assigned to 'John Doe'
DELETE FROM investigative_projects WHERE assigned_to = (SELECT employee_id FROM employees WHERE name = 'John Doe');
gretelai_synthetic_text_to_sql
CREATE VIEW international_programs AS SELECT * FROM programs WHERE country = 'International';
What is the total budget for the 'international_programs' view?
SELECT SUM(budget) FROM international_programs;
gretelai_synthetic_text_to_sql
CREATE TABLE orders (order_id INT, order_time TIME, is_organic BOOLEAN); INSERT INTO orders (order_id, order_time, is_organic) VALUES (1, '09:00:00', true), (2, '10:30:00', false), (3, '08:45:00', true);
What is the total amount of organic food orders placed before 10 AM in the 'orders' table?
SELECT SUM(IIF(is_organic, 1, 0)) as total_organic_orders FROM orders WHERE order_time < '10:00:00';
gretelai_synthetic_text_to_sql
CREATE TABLE Buildings (building_id INT, name VARCHAR(50), building_type VARCHAR(50));CREATE TABLE Units (unit_id INT, building_id INT, year_built INT, rent INT);
What is the average change in rent from year to year for units in each building, ordered by building type and then by average change?
SELECT b.building_type, b.name, AVG(u.change_in_rent) as avg_change_in_rent FROM (SELECT building_id, YEAR(rent_date) as year, AVG(rent) - LAG(AVG(rent)) OVER (PARTITION BY building_id ORDER BY YEAR(rent_date)) as change_in_rent FROM Units JOIN Rent_Dates ON Units.unit_id = Rent_Dates.unit_id GROUP BY building_id, year) u JOIN Buildings b ON u.building_id = b.building_id GROUP BY b.building_type, b.name ORDER BY b.building_type, avg_change_in_rent;
gretelai_synthetic_text_to_sql
CREATE TABLE news (id INT, title TEXT, category TEXT); INSERT INTO news (id, title, category) VALUES (1, 'Global NewsA', 'National'); INSERT INTO news (id, title, category) VALUES (2, 'Local NewsB', 'Local'); INSERT INTO news (id, title, category) VALUES (3, 'World News ArticleC', 'World News');
Update the genre of a news article to 'World News' if its title contains 'Global'.
UPDATE news SET category = 'World News' WHERE title LIKE '%Global%';
gretelai_synthetic_text_to_sql
CREATE TABLE packages (package_id INT, delivery_date DATE, warehouse_location VARCHAR(20));
Insert a new record for a package with ID 4, delivered on 2021-08-01, located in 'Warehouse A'
INSERT INTO packages (package_id, delivery_date, warehouse_location) VALUES (4, '2021-08-01', 'Warehouse A');
gretelai_synthetic_text_to_sql
CREATE TABLE sales (id INT PRIMARY KEY, product_id INT, quantity INT, sale_price DECIMAL(5,2), order_date DATE, country VARCHAR(255), region VARCHAR(255)); INSERT INTO sales (id, product_id, quantity, sale_price, order_date, country, region) VALUES (1, 1, 2, 59.99, '2021-12-01', 'Germany', 'Europe'); INSERT INTO sales (id, product_id, quantity, sale_price, order_date, country, region) VALUES (2, 2, 1, 39.99, '2021-12-03', 'France', 'Europe');
What is the total revenue per country in the European region?
SELECT region, SUM(quantity * sale_price) as total_revenue FROM sales WHERE region = 'Europe' GROUP BY region;
gretelai_synthetic_text_to_sql
CREATE TABLE policy_violations (id INT, user_id INT, violation_date DATE); CREATE TABLE users (id INT, name VARCHAR(50)); INSERT INTO policy_violations (id, user_id, violation_date) VALUES (1, 1, '2021-12-01'), (2, 2, '2021-12-03'), (3, 3, '2021-12-04'), (4, 1, '2021-12-05'), (5, 4, '2021-12-06'), (6, 5, '2021-12-07'); INSERT INTO users (id, name) VALUES (1, 'Alice'), (2, 'Bob'), (3, 'Charlie'), (4, 'David'), (5, 'Eve');
Who are the top 5 users by number of policy violations?
SELECT users.name, COUNT(policy_violations.id) as violation_count FROM policy_violations INNER JOIN users ON policy_violations.user_id = users.id GROUP BY users.name ORDER BY violation_count DESC LIMIT 5;
gretelai_synthetic_text_to_sql
CREATE TABLE LandfillCapacity (region VARCHAR(255), year INT, capacity INT); INSERT INTO LandfillCapacity (region, year, capacity) VALUES ('North', 2020, 50000), ('South', 2020, 60000), ('East', 2020, 40000), ('West', 2020, 30000);
What is the landfill capacity for each region for the year 2020?
SELECT region, capacity FROM LandfillCapacity WHERE year = 2020;
gretelai_synthetic_text_to_sql
CREATE TABLE co_ownership (id INT, property_id INT, owner TEXT, city TEXT, size INT); INSERT INTO co_ownership (id, property_id, owner, city, size) VALUES (1, 101, 'Alice', 'Austin', 1200), (2, 101, 'Bob', 'Austin', 1200), (3, 102, 'Carol', 'Seattle', 900);
What is the average property size for co-owned properties in the city of Austin?
SELECT AVG(size) FROM co_ownership WHERE city = 'Austin';
gretelai_synthetic_text_to_sql
CREATE TABLE atlantic_ocean (name VARCHAR(255), depth FLOAT); INSERT INTO atlantic_ocean VALUES ('Puerto Rico', 8380);
What is the minimum depth of all trenches in the Atlantic Ocean?
SELECT MIN(depth) FROM atlantic_ocean WHERE name = 'Puerto Rico';
gretelai_synthetic_text_to_sql
CREATE TABLE ai_ethics (developer VARCHAR(255), principle VARCHAR(255)); INSERT INTO ai_ethics (developer, principle) VALUES ('IBM', 'Fairness'), ('Google', 'Accountability'), ('IBM', 'Transparency');
Delete all records in the 'ai_ethics' table where the 'developer' column is 'IBM'
DELETE FROM ai_ethics WHERE developer = 'IBM';
gretelai_synthetic_text_to_sql
CREATE TABLE customers (customer_number INT, status VARCHAR(10), country VARCHAR(50), created_at TIMESTAMP);
Update the status column to 'active' for all records in the customers table where country is 'Indonesia'
UPDATE customers SET status = 'active' WHERE country = 'Indonesia';
gretelai_synthetic_text_to_sql
CREATE TABLE memberships (id INT, member_id INT, start_date DATE, end_date DATE, price DECIMAL(5,2)); CREATE TABLE members (id INT, name VARCHAR(255), type VARCHAR(255)); INSERT INTO memberships (id, member_id, start_date, end_date, price) VALUES (1, 1, '2022-01-01', '2022-12-31', 100.00), (2, 2, '2022-07-01', '2023-06-30', 150.00), (3, 3, '2022-04-01', '2022-12-31', 75.00); INSERT INTO members (id, name, type) VALUES (1, 'Jane Doe', 'Individual'), (2, 'John Smith', 'Family'), (3, 'Alice Johnson', 'Senior');
What is the total revenue generated by museum memberships?
SELECT SUM(price) FROM memberships JOIN members ON memberships.member_id = members.id WHERE members.type = 'Individual' OR members.type = 'Family' OR members.type = 'Senior';
gretelai_synthetic_text_to_sql
CREATE TABLE Cases (CaseID VARCHAR(10), CaseStatus VARCHAR(10));
Insert a new case with CaseID '0002' and CaseStatus 'Open' into the Cases table
WITH cte AS (VALUES ('0002', 'Open')) INSERT INTO Cases SELECT * FROM cte;
gretelai_synthetic_text_to_sql
CREATE TABLE transactions (transaction_id INT, transaction_date DATE, amount DECIMAL(10,2));
What is the average transaction amount per day?
SELECT AVG(amount) FROM transactions GROUP BY transaction_date;
gretelai_synthetic_text_to_sql
CREATE TABLE author (author_id INT, author_name VARCHAR(50), is_minority BOOLEAN); INSERT INTO author (author_id, author_name, is_minority) VALUES (1, 'Alice Johnson', TRUE), (2, 'Bob Smith', FALSE), (3, 'Carla Garcia', TRUE); CREATE TABLE article (article_id INT, author_id INT, publication_date DATE); INSERT INTO article (article_id, author_id, publication_date) VALUES (1, 1, '2021-01-01'), (2, 2, '2021-02-01'), (3, 3, '2021-03-01');
How many articles were published by minority authors in 2021?
SELECT COUNT(*) as num_articles FROM article JOIN author ON article.author_id = author.author_id WHERE is_minority = TRUE AND EXTRACT(YEAR FROM publication_date) = 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE hotels (hotel_id INT, hotel_name VARCHAR(100), category VARCHAR(50), rating FLOAT, num_reviews INT); INSERT INTO hotels (hotel_id, hotel_name, category, rating, num_reviews) VALUES (1, 'Hotel A', 'Budget', 4.2, 120), (2, 'Hotel B', 'Luxury', 4.8, 250), (3, 'Hotel C', 'Budget', 3.9, 65), (4, 'Hotel D', 'Midrange', 4.5, 180);
What is the average rating of hotels in the 'Budget' category that have more than 100 reviews?
SELECT AVG(rating) FROM hotels WHERE category = 'Budget' AND num_reviews > 100;
gretelai_synthetic_text_to_sql
CREATE TABLE fires (id INT, date DATE, location VARCHAR(20)); INSERT INTO fires (id, date, location) VALUES (1, '2022-01-01', 'downtown'), (2, '2022-01-02', 'downtown'), (3, '2022-01-03', 'uptown');
What is the maximum number of fires in 'downtown' in a single day?
SELECT MAX(count) FROM (SELECT date, COUNT(*) AS count FROM fires WHERE location = 'downtown' GROUP BY date) AS subquery;
gretelai_synthetic_text_to_sql
CREATE TABLE mining_operation_data (mine_name VARCHAR(50), mined_material VARCHAR(20), production_capacity INT);
Insert a new record in the 'mining_operation_data' table for the 'Mirny' mine, 'Diamond' as the mined_material, and a production_capacity of 70000 tonnes
INSERT INTO mining_operation_data (mine_name, mined_material, production_capacity) VALUES ('Mirny', 'Diamond', 70000);
gretelai_synthetic_text_to_sql
CREATE TABLE articles (id INT, title VARCHAR(50), topic VARCHAR(50), word_count INT, publish_date DATE); INSERT INTO articles (id, title, topic, word_count, publish_date) VALUES (1, 'Article 1', 'topic1', 1500, '2022-01-01'), (2, 'Article 2', 'topic2', 1000, '2022-02-01');
What is the average word count of articles published in the last month?
SELECT AVG(word_count) FROM articles WHERE publish_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);
gretelai_synthetic_text_to_sql
CREATE TABLE reporters (id INT, name VARCHAR(50), gender VARCHAR(10), age INT, country VARCHAR(50)); CREATE TABLE published_stories (reporter_id INT, news_id INT); CREATE TABLE news (id INT, title VARCHAR(100), views INT, date DATE, country VARCHAR(50));
What is the total number of news stories published in the "news" table for each country in the "reporters" table?
SELECT r.country, COUNT(*) AS total_stories FROM reporters r INNER JOIN published_stories ps ON r.id = ps.reporter_id INNER JOIN news n ON ps.news_id = n.id GROUP BY r.country;
gretelai_synthetic_text_to_sql
CREATE TABLE TextileSourcing (FabricType VARCHAR(255), Quantity INT, IsSustainable BOOLEAN); INSERT INTO TextileSourcing (FabricType, Quantity, IsSustainable) VALUES ('Organic Cotton', 1200, TRUE), ('Recycled Polyester', 800, TRUE), ('Tencel', 1500, TRUE), ('Virgin Polyester', 1000, FALSE), ('Conventional Cotton', 2000, FALSE);
Show the total quantity of sustainable fabric types used in all clothing items.
SELECT SUM(Quantity) FROM TextileSourcing WHERE IsSustainable = TRUE;
gretelai_synthetic_text_to_sql
CREATE TABLE accounts (id INT, name VARCHAR(255), location VARCHAR(255)); CREATE TABLE posts (id INT, account_id INT, content TEXT, comments INT, timestamp TIMESTAMP); INSERT INTO accounts (id, name, location) VALUES (1, 'yoga_lover', 'Brazil'); INSERT INTO posts (id, account_id, content, comments, timestamp) VALUES (1, 1, 'post1 with yoga', 20, '2022-05-01 12:00:00');
What is the average number of comments on posts made in the past week, that contain the word "yoga", for accounts located in Brazil?
SELECT AVG(comments) FROM posts JOIN accounts ON posts.account_id = accounts.id WHERE posts.timestamp >= NOW() - INTERVAL '1 week' AND posts.content LIKE '%yoga%' AND accounts.location = 'Brazil';
gretelai_synthetic_text_to_sql
CREATE TABLE shariah_compliant_finance_history (client_id INT, balance DECIMAL(10, 2), month DATE); INSERT INTO shariah_compliant_finance_history (client_id, balance, month) VALUES (3, 25000.50, '2022-01-01'), (3, 28000.75, '2022-02-01'), (4, 30000.75, '2022-01-01'), (4, 32000.50, '2022-02-01');
Which client has the highest increase in balance in the Shariah-compliant finance database compared to the previous month?
SELECT h1.client_id, h1.balance - LAG(h1.balance) OVER (PARTITION BY h1.client_id ORDER BY h1.month) AS balance_change FROM shariah_compliant_finance_history h1 ORDER BY balance_change DESC LIMIT 1;
gretelai_synthetic_text_to_sql
CREATE TABLE chemical_manufacturers (manufacturer_id INT, name VARCHAR(255), country VARCHAR(255)); INSERT INTO chemical_manufacturers (manufacturer_id, name, country) VALUES (1, 'ManufacturerA', 'USA'), (2, 'ManufacturerB', 'Canada'), (3, 'ManufacturerC', 'USA'); CREATE TABLE emissions (emission_id INT, manufacturer_id INT, gas_type VARCHAR(255), amount INT); INSERT INTO emissions (emission_id, manufacturer_id, gas_type, amount) VALUES (1, 1, 'CO2', 1000), (2, 1, 'CH4', 200), (3, 2, 'CO2', 1500), (4, 3, 'CO2', 1200), (5, 3, 'CH4', 300);
List all chemical manufacturers in a given region, along with the total amount of CO2 emissions for each.
SELECT cm.name, SUM(e.amount) FROM chemical_manufacturers cm JOIN emissions e ON cm.manufacturer_id = e.manufacturer_id WHERE cm.country = 'USA' AND e.gas_type = 'CO2' GROUP BY cm.name;
gretelai_synthetic_text_to_sql
CREATE TABLE All_Cosmetics (product_id INT, product_name VARCHAR(255), rating DECIMAL(3,1), price DECIMAL(10,2)); INSERT INTO All_Cosmetics (product_id, product_name, rating, price) VALUES (1, 'Cosmetic 1', 4.6, 24.99), (2, 'Cosmetic 2', 4.8, 34.99), (3, 'Cosmetic 3', 4.2, 19.99);
List all cosmetics with a rating above 4.5 and less than 25 USD.
SELECT * FROM All_Cosmetics WHERE rating > 4.5 AND price < 25;
gretelai_synthetic_text_to_sql
CREATE TABLE teams (team_id INT, team_name VARCHAR(50)); INSERT INTO teams (team_id, team_name) VALUES (1, 'NY Knicks'), (2, 'LA Lakers'); CREATE TABLE ticket_sales (id INT, team_id INT, revenue INT);
What is the total revenue generated from ticket sales for the NY Knicks?
SELECT SUM(ticket_sales.revenue) FROM ticket_sales JOIN teams ON ticket_sales.team_id = teams.team_id WHERE teams.team_name = 'NY Knicks';
gretelai_synthetic_text_to_sql
CREATE TABLE drug_manufacturers (manufacturer_id INT, drug_name TEXT, manufacturer TEXT, sales FLOAT); INSERT INTO drug_manufacturers (manufacturer_id, drug_name, manufacturer, sales) VALUES (1, 'DrugE', 'Manufacturer1', 7000000), (2, 'DrugF', 'Manufacturer2', 8000000);
What is the total sales figure for each drug by manufacturer?
SELECT manufacturer, SUM(sales) as total_sales FROM drug_manufacturers GROUP BY manufacturer;
gretelai_synthetic_text_to_sql
CREATE TABLE IF NOT EXISTS players (id INT, name VARCHAR(50), position VARCHAR(50), team VARCHAR(50), league VARCHAR(50), salary INT);
List the names and salaries of baseball players who earned more than the average salary in their league in the 2022 season.
SELECT name, salary FROM players WHERE league = 'MLB' AND salary > (SELECT AVG(salary) FROM players WHERE league = 'MLB') UNION SELECT name, salary FROM players WHERE league = 'MiLB' AND salary > (SELECT AVG(salary) FROM players WHERE league = 'MiLB');
gretelai_synthetic_text_to_sql
CREATE TABLE polygon_nfts (nft_id INT, nft_name VARCHAR(255), nft_category VARCHAR(255), network VARCHAR(50));
What is the distribution of non-fungible tokens (NFTs) by category on the Polygon network?
SELECT nft_category, COUNT(*) as count FROM polygon_nfts WHERE network = 'Polygon' GROUP BY nft_category;
gretelai_synthetic_text_to_sql
CREATE TABLE heritage_sites (site_id INT, name VARCHAR(50), location VARCHAR(50), year INT, type VARCHAR(50));
Find the heritage sites that were established in the same year as the earliest heritage site in their country.
SELECT h1.* FROM heritage_sites h1 INNER JOIN (SELECT location, MIN(year) AS min_year FROM heritage_sites GROUP BY location) h2 ON h1.location = h2.location AND h1.year = h2.min_year;
gretelai_synthetic_text_to_sql
CREATE TABLE artifacts (id INT, name VARCHAR(50), description TEXT); INSERT INTO artifacts (id, name, description) VALUES (1, 'Pottery', 'Ancient pottery from the Mayan civilization'), (2, 'Totem pole', 'Wooden totem pole from the Haida nation'), (3, 'Woven rug', 'Hand-woven rug from the Navajo tribe'), (4, 'Beaded necklace', 'Beaded necklace from the Inuit people'), (5, 'Drum', 'Traditional drum from the Apache tribe');
Delete all records with an id greater than 5 from the artifacts table.
DELETE FROM artifacts WHERE id > 5;
gretelai_synthetic_text_to_sql
CREATE TABLE Astrophysics_Research(id INT, constellation VARCHAR(50), distance_to_nearest_star FLOAT);
Get the average distance to the nearest star for each constellation in the Astrophysics_Research table.
SELECT constellation, AVG(distance_to_nearest_star) as Average_Distance FROM Astrophysics_Research GROUP BY constellation;
gretelai_synthetic_text_to_sql
CREATE TABLE carbon_offset_initiatives (initiative_name TEXT, city TEXT, reduction_amount INTEGER); INSERT INTO carbon_offset_initiatives VALUES ('InitiativeA', 'City1', 500), ('InitiativeB', 'City1', 800), ('InitiativeC', 'City2', 300), ('InitiativeD', 'City2', 700);
List the bottom 3 carbon offset initiatives by reduction amount for each city?
SELECT initiative_name, city, reduction_amount, RANK() OVER (PARTITION BY city ORDER BY reduction_amount ASC) AS rank FROM carbon_offset_initiatives WHERE rank <= 3;
gretelai_synthetic_text_to_sql
CREATE TABLE rd_expenditure (drug_name TEXT, expenditure NUMERIC, region TEXT); INSERT INTO rd_expenditure (drug_name, expenditure, region) VALUES ('Vaxo', 5000000, 'United States'), ('MedX', 7000000, 'China');
What is the total R&D expenditure for the drug 'MedX' in Asia?
SELECT SUM(expenditure) FROM rd_expenditure WHERE drug_name = 'MedX' AND region = 'Asia';
gretelai_synthetic_text_to_sql
SELECT DISTINCT School FROM Teachers;
List all unique schools in the 'Teachers' table
SELECT DISTINCT School FROM Teachers;
gretelai_synthetic_text_to_sql
CREATE TABLE products (product_id INTEGER, name TEXT, category TEXT, sustainable BOOLEAN, price FLOAT); INSERT INTO products (product_id, name, category, sustainable, price) VALUES (1001, 'Organic Cotton Dress', 'dresses', TRUE, 80.0), (1002, 'Silk Blouse', 'tops', FALSE, 60.0), (1003, 'Recycled Polyester Jacket', 'jackets', TRUE, 120.0), (1004, 'Bamboo T-Shirt', 'tops', TRUE, 30.0);
What is the average price of sustainable fashion products in the tops category?
SELECT AVG(price) FROM products WHERE sustainable = TRUE AND category = 'tops';
gretelai_synthetic_text_to_sql
CREATE TABLE mine (id INT, name TEXT, location TEXT, mineral TEXT, productivity INT); INSERT INTO mine (id, name, location, mineral, productivity) VALUES (1, 'Olympic Dam', 'Australia', 'Uranium', 700), (2, 'Ranger', 'Australia', 'Uranium', 900);
Delete all uranium mines in Australia with productivity below 800?
DELETE FROM mine WHERE mineral = 'Uranium' AND location = 'Australia' AND productivity < 800;
gretelai_synthetic_text_to_sql
CREATE TABLE sustainable_practices (practice_id INT, description TEXT, category VARCHAR(20)); INSERT INTO sustainable_practices (practice_id, description, category) VALUES (2, 'Using water-efficient appliances', 'Water');
Update the record in the "sustainable_practices" table with an ID of 2 to have a description of 'Minimizing water usage in laundry'
UPDATE sustainable_practices SET description = 'Minimizing water usage in laundry' WHERE practice_id = 2;
gretelai_synthetic_text_to_sql
CREATE TABLE co2_emissions (id INT, region VARCHAR(50), co2_emission INT); INSERT INTO co2_emissions (id, region, co2_emission) VALUES (4, 'Andes', 16000); INSERT INTO co2_emissions (id, region, co2_emission) VALUES (5, 'Andes', 17000); INSERT INTO co2_emissions (id, region, co2_emission) VALUES (6, 'Andes', 18000);
What is the total CO2 emission from mining operations in the Andes region?
SELECT SUM(co2_emission) FROM co2_emissions WHERE region = 'Andes';
gretelai_synthetic_text_to_sql
CREATE TABLE genetic_data (id INT PRIMARY KEY, sample_id INT, gene_sequence TEXT, date DATE); INSERT INTO genetic_data (id, sample_id, gene_sequence, date) VALUES (1, 1001, 'ATGCGAT...', '2021-01-01'), (2, 1002, 'CGATCG...', '2021-01-02'), (3, 1003, 'ATCGATG...', '2021-01-16');
List all the genetic data samples with a gene sequence starting with 'AT' and created after January 15th, 2021.
SELECT sample_id, gene_sequence FROM genetic_data WHERE gene_sequence LIKE 'AT%' AND date > '2021-01-15';
gretelai_synthetic_text_to_sql
CREATE TABLE rural_hospitals (id INT, state VARCHAR(2), patient_satisfaction_score INT); INSERT INTO rural_hospitals (id, state, patient_satisfaction_score) VALUES (1, 'TX', 88), (2, 'TX', 75), (3, 'CA', 92), (4, 'CA', 82);
What is the total number of rural hospitals in Texas and California with a patient satisfaction score greater than 85?
SELECT SUM(CASE WHEN state IN ('TX', 'CA') AND patient_satisfaction_score > 85 THEN 1 ELSE 0 END) FROM rural_hospitals;
gretelai_synthetic_text_to_sql
CREATE TABLE suppliers (id INT PRIMARY KEY, name VARCHAR(255), country VARCHAR(255), industry VARCHAR(255)); INSERT INTO suppliers (id, name, country, industry) VALUES (1, 'Supplier A', 'Bangladesh', 'Textile'); CREATE TABLE garments (id INT PRIMARY KEY, supplier_id INT, name VARCHAR(255), category VARCHAR(255), price DECIMAL(10,2)); CREATE TABLE sales (id INT PRIMARY KEY, garment_id INT, date DATE, quantity INT); CREATE VIEW sales_by_month AS SELECT YEAR(date) as sales_year, MONTH(date) as sales_month, SUM(quantity) as total_sales FROM sales GROUP BY sales_year, sales_month;
What is the average sales per month for the 'Fast Fashion' category in the year 2023?
SELECT AVG(total_sales) FROM sales_by_month WHERE sales_year = 2023 AND category = 'Fast Fashion' GROUP BY sales_month;
gretelai_synthetic_text_to_sql
CREATE TABLE labor_costs (id INT, project_state TEXT, project_type TEXT, labor_cost DECIMAL(10,2)); INSERT INTO labor_costs (id, project_state, project_type, labor_cost) VALUES (1, 'California', 'Sustainable', 12000.00), (2, 'California', 'Conventional', 10000.00);
What is the average labor cost for sustainable building projects in California?
SELECT AVG(labor_cost) FROM labor_costs WHERE project_state = 'California' AND project_type = 'Sustainable';
gretelai_synthetic_text_to_sql
CREATE TABLE CustomerNavalSpending (customer_name TEXT, purchase_month DATE, amount INTEGER); INSERT INTO CustomerNavalSpending (customer_name, purchase_month, amount) VALUES ('ABC Corp', '2021-04-01', 5000000), ('DEF Inc', '2021-10-15', 7000000), ('GHI Enterprises', '2021-07-20', 6000000), ('JKL Ltd', '2021-12-03', 8000000);
What was the average monthly naval equipment spending for each customer in 2021?
SELECT customer_name, AVG(amount) FROM CustomerNavalSpending WHERE purchase_month BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY customer_name;
gretelai_synthetic_text_to_sql
CREATE TABLE ProductsParabenFreeSalesData (product_id INT, product_name TEXT, is_paraben_free BOOLEAN, sale_revenue FLOAT, is_organic BOOLEAN); INSERT INTO ProductsParabenFreeSalesData (product_id, product_name, is_paraben_free, sale_revenue, is_organic) VALUES (1, 'Product A', true, 75, true), (2, 'Product B', false, 30, false), (3, 'Product C', false, 60, false), (4, 'Product D', true, 120, true), (5, 'Product E', false, 45, false);
List the beauty products that are labeled 'paraben-free' and have a sale revenue above the average sale revenue for all products, excluding products labeled 'organic'.
SELECT product_id, product_name, sale_revenue FROM ProductsParabenFreeSalesData WHERE is_paraben_free = true AND is_organic = false AND sale_revenue > (SELECT AVG(sale_revenue) FROM ProductsParabenFreeSalesData WHERE is_organic = false);
gretelai_synthetic_text_to_sql
CREATE SCHEMA if not exists pharma; CREATE TABLE if not exists pharma.drug_approval (year INT, drug VARCHAR(255)); INSERT INTO pharma.drug_approval (year, drug) VALUES (2018, 'Drug A'), (2019, 'Drug B'), (2020, 'Drug C'), (2020, 'Drug D'), (2021, 'Drug E');
How many drugs were approved in each year?
SELECT year, COUNT(DISTINCT drug) AS drugs_approved FROM pharma.drug_approval GROUP BY year ORDER BY year;
gretelai_synthetic_text_to_sql
CREATE TABLE tourism_stats (id INT PRIMARY KEY, country VARCHAR(255), destination VARCHAR(255), duration INT); INSERT INTO tourism_stats (id, country, destination, duration) VALUES (1, 'China', 'Kenya', 12), (2, 'China', 'South Africa', 20), (3, 'China', 'Egypt', 14);
What is the average trip duration in days for Chinese tourists visiting Africa?
SELECT AVG(duration) FROM tourism_stats WHERE country = 'China' AND destination LIKE 'Africa%';
gretelai_synthetic_text_to_sql