context
stringlengths
11
9.12k
question
stringlengths
0
1.06k
SQL
stringlengths
2
4.44k
source
stringclasses
28 values
CREATE TABLE AircraftSpecifications (Id INT, Manufacturer VARCHAR(50), Model VARCHAR(50), MaxPassengers INT); INSERT INTO AircraftSpecifications (Id, Manufacturer, Model, MaxPassengers) VALUES (1, 'Airbus', 'A380', 853);
What is the maximum number of passengers that can be carried by Airbus A380?
SELECT MaxPassengers FROM AircraftSpecifications WHERE Manufacturer = 'Airbus' AND Model = 'A380';
gretelai_synthetic_text_to_sql
CREATE TABLE menus (menu_id INT, name VARCHAR(100), category VARCHAR(50), price DECIMAL(5,2), quantity INT); INSERT INTO menus (menu_id, name, category, price, quantity) VALUES (1, 'Chicken Caesar Salad', 'Salad', 12.99, 300), (2, 'Margherita Pizza', 'Pizza', 9.99, 450);
What are the average sales for each category in the last quarter?
SELECT category, AVG(quantity * price) as avg_sales FROM menus WHERE MONTH(order_date) BETWEEN MONTH(CURRENT_DATE()) - 3 AND MONTH(CURRENT_DATE()) GROUP BY category;
gretelai_synthetic_text_to_sql
CREATE SCHEMA forestry; CREATE TABLE trees (id INT, species VARCHAR(50)); INSERT INTO trees (id, species) VALUES (1, 'oak'), (2, 'pine'), (3, 'eucalyptus'), (4, 'oak'), (5, 'maple');
count the number of tree species in the forestry schema
SELECT COUNT(DISTINCT species) FROM forestry.trees;
gretelai_synthetic_text_to_sql
CREATE TABLE teams (id INT, region VARCHAR(10)); INSERT INTO teams (id, region) VALUES (1, 'Europe'); INSERT INTO teams (id, region) VALUES (2, 'Asia');
List eSports teams that have players from both "Europe" and "Asia"
SELECT id FROM teams WHERE region = 'Europe' INTERSECT SELECT id FROM teams WHERE region = 'Asia';
gretelai_synthetic_text_to_sql
CREATE TABLE incident_device_resolution (id INT, incident_id INT, device_type VARCHAR(255), resolution_time INT, incident_date DATE); INSERT INTO incident_device_resolution (id, incident_id, device_type, resolution_time, incident_date) VALUES (1, 1, 'Laptop', 120, '2021-01-01'), (2, 1, 'Mobile', 150, '2021-01-01'), (3, 2, 'Desktop', 100, '2021-01-01'), (4, 3, 'Laptop', 180, '2021-01-01'), (5, 3, 'Server', 110, '2021-01-01'), (6, 4, 'Mobile', 140, '2021-01-01'), (7, 4, 'Tablet', 120, '2021-01-01'), (8, 5, 'Server', 150, '2021-01-01');
What is the average time to resolve security incidents for each device type in the last month?
SELECT device_type, AVG(resolution_time) as avg_resolution_time FROM incident_device_resolution WHERE incident_date >= DATEADD(day, -30, GETDATE()) GROUP BY device_type;
gretelai_synthetic_text_to_sql
CREATE TABLE agricultural_land (id INT, location VARCHAR(50), size FLOAT); INSERT INTO agricultural_land (id, location, size) VALUES (1, 'Springfield', 500.0); INSERT INTO agricultural_land (id, location, size) VALUES (2, 'Shelbyville', 350.0);
What is the total area of agricultural land in the 'agricultural_land' table?
SELECT SUM(size) FROM agricultural_land;
gretelai_synthetic_text_to_sql
CREATE TABLE geology (well_id INT, rock_type VARCHAR(50)); CREATE TABLE drilling (well_id INT, drill_depth INT);
List all unique fields from the 'geology' and 'drilling' tables.
SELECT field FROM (SELECT 'geology' as table_name, column_name as field FROM information_schema.columns WHERE table_name = 'geology' UNION ALL SELECT 'drilling' as table_name, column_name as field FROM information_schema.columns WHERE table_name = 'drilling') as subquery;
gretelai_synthetic_text_to_sql
CREATE TABLE Spending (ID INT, Country VARCHAR(100), Year INT, HealthcareSpending FLOAT); INSERT INTO Spending (ID, Country, Year, HealthcareSpending) VALUES (1, 'India', 2020, 200);
What is the average healthcare spending per capita in India?
SELECT AVG(HealthcareSpending) FROM Spending WHERE Country = 'India' AND Year = 2020;
gretelai_synthetic_text_to_sql
CREATE TABLE sub_saharan_africa_regions (id INT, name VARCHAR(255)); CREATE TABLE life_expectancy (id INT, region_id INT, expectancy DECIMAL(5,2)); INSERT INTO sub_saharan_africa_regions (id, name) VALUES (1, 'West Africa'), (2, 'Central Africa'), (3, 'Eastern Africa'), (4, 'Southern Africa');
What is the average life expectancy in each region of sub-Saharan Africa?
SELECT r.name, AVG(le.expectancy) FROM life_expectancy le JOIN sub_saharan_africa_regions r ON le.region_id = r.id GROUP BY r.name;
gretelai_synthetic_text_to_sql
CREATE TABLE disease_prevalence (county VARCHAR(50), diagnosis VARCHAR(50), prevalence DECIMAL(5,2)); INSERT INTO disease_prevalence (county, diagnosis, prevalence) VALUES ('Rural County A', 'Heart Disease', 10.00), ('Rural County B', 'Diabetes', 7.50), ('Rural County C', 'Diabetes', 9.00);
Update the 'Diabetes' prevalence rate for 'Rural County C' in the "disease_prevalence" table to 8%
UPDATE disease_prevalence SET prevalence = 0.08 WHERE county = 'Rural County C' AND diagnosis = 'Diabetes';
gretelai_synthetic_text_to_sql
CREATE TABLE Military_Equipment_Sales(equipment_id INT, manufacturer VARCHAR(255), purchaser VARCHAR(255), sale_date DATE, quantity INT);INSERT INTO Military_Equipment_Sales(equipment_id, manufacturer, purchaser, sale_date, quantity) VALUES (1, 'BAE Systems', 'Brazil', '2019-10-01', 15), (2, 'BAE Systems', 'Argentina', '2019-12-15', 20);
What is the total number of military equipment sold by BAE Systems to South American countries in Q4 2019?
SELECT SUM(quantity) FROM Military_Equipment_Sales WHERE manufacturer = 'BAE Systems' AND purchaser LIKE 'South America%' AND sale_date BETWEEN '2019-10-01' AND '2019-12-31';
gretelai_synthetic_text_to_sql
CREATE TABLE mining_sites(id INT, site VARCHAR(50), accidents INT); INSERT INTO mining_sites (id, site, accidents) VALUES (1, 'Surface', 5), (2, 'Underground', 3), (3, 'Gold Mine', 0);
Delete the mining site 'Gold Mine' if it exists in the mining_sites table.
DELETE FROM mining_sites WHERE site = 'Gold Mine';
gretelai_synthetic_text_to_sql
CREATE TABLE membership_data (member_id INT, join_date DATE); CREATE TABLE workout_data (workout_id INT, member_id INT, workout_date DATE);
List all members who joined in the first quarter of 2020 and their total workouts in that period.
SELECT m.member_id, m.join_date, COUNT(w.workout_id) as total_workouts FROM membership_data m JOIN workout_data w ON m.member_id = w.member_id WHERE QUARTER(m.join_date) = 1 AND YEAR(m.join_date) = 2020 GROUP BY m.member_id;
gretelai_synthetic_text_to_sql
CREATE TABLE oceans (id INT, name VARCHAR(50)); CREATE TABLE species (id INT, ocean_id INT, name VARCHAR(50), max_size FLOAT); INSERT INTO oceans VALUES (1, 'Atlantic Ocean'); INSERT INTO species VALUES (1, 1, 'Bluefin Tuna', 300), (2, 1, 'Sailfish', 360);
Identify the number of fish species and their maximum size in the Atlantic Ocean.
SELECT COUNT(DISTINCT s.name) as species_count, MAX(s.max_size) as max_size FROM species s INNER JOIN oceans o ON s.ocean_id = o.id WHERE o.name = 'Atlantic Ocean';
gretelai_synthetic_text_to_sql
CREATE TABLE company_founding(id INT PRIMARY KEY, company_name VARCHAR(100), founder_country VARCHAR(50)); INSERT INTO company_founding VALUES (1, 'Acme Inc', 'USA'); INSERT INTO company_founding VALUES (2, 'Beta Corp', 'USA'); INSERT INTO company_founding VALUES (3, 'Charlie LLC', 'Canada'); INSERT INTO company_founding VALUES (4, 'Delta Inc', 'USA');
Count the number of companies founded by individuals from each country
SELECT founder_country, COUNT(*) FROM company_founding GROUP BY founder_country;
gretelai_synthetic_text_to_sql
CREATE TABLE customers (id INT, name VARCHAR(50), data_usage FLOAT, city VARCHAR(50));
What is the total data usage for the top 10 customers in the city of Chicago?
SELECT SUM(data_usage) FROM customers WHERE city = 'Chicago' AND id IN (SELECT id FROM (SELECT id FROM customers WHERE city = 'Chicago' ORDER BY data_usage DESC LIMIT 10) subquery) ORDER BY data_usage DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE Military_Equipment_Sales(equipment_id INT, manufacturer VARCHAR(255), purchaser VARCHAR(255), sale_date DATE, quantity INT);INSERT INTO Military_Equipment_Sales(equipment_id, manufacturer, purchaser, sale_date, quantity) VALUES (1, 'Lockheed Martin', 'Egypt', '2019-01-10', 8), (2, 'Lockheed Martin', 'South Africa', '2019-03-01', 12);
What is the average quantity of military equipment sold by Lockheed Martin to African countries in Q1 2019?
SELECT AVG(quantity) FROM Military_Equipment_Sales WHERE manufacturer = 'Lockheed Martin' AND purchaser LIKE 'Africa%' AND sale_date BETWEEN '2019-01-01' AND '2019-03-31';
gretelai_synthetic_text_to_sql
CREATE TABLE labor_statistics (id INT, city VARCHAR(255), state VARCHAR(255), union_member BOOLEAN, hourly_wage FLOAT);
List all construction labor statistics for the state of New York, broken down by union membership status.
SELECT state, union_member, hourly_wage FROM labor_statistics WHERE state = 'New York' ORDER BY union_member;
gretelai_synthetic_text_to_sql
CREATE TABLE health_equity_metrics (metric_id INT, measurement_date DATE, value INT); INSERT INTO health_equity_metrics (metric_id, measurement_date, value) VALUES (1, '2021-01-01', 70), (2, '2021-02-01', 75), (3, '2021-03-01', 80), (4, '2021-04-01', 85), (5, '2021-05-01', 90), (6, '2022-01-01', 95), (7, '2022-02-01', 100), (8, '2022-03-01', 105), (9, '2022-04-01', 110), (10, '2022-05-01', 115);
What is the trend of health equity metrics over the past year?
SELECT EXTRACT(MONTH FROM measurement_date) as month, AVG(value) as avg_value FROM health_equity_metrics WHERE measurement_date >= '2021-01-01' AND measurement_date < '2022-06-01' GROUP BY month;
gretelai_synthetic_text_to_sql
CREATE TABLE loans (loan_number INT, customer_name VARCHAR(50), balance DECIMAL(10, 2), is_shariah_compliant BOOLEAN); INSERT INTO loans (loan_number, customer_name, balance, is_shariah_compliant) VALUES (1, 'Ahmed', 5000, true), (2, 'Sara', 7000, false), (3, 'Mohammed', 8000, true);
What is the total balance for all Shariah-compliant loans?
SELECT SUM(balance) FROM loans WHERE is_shariah_compliant = true;
gretelai_synthetic_text_to_sql
CREATE TABLE RegionsCleanWater (Region VARCHAR(50), Population INT, CleanWater INT); INSERT INTO RegionsCleanWater (Region, Population, CleanWater) VALUES ('North', 100000, 90000), ('South', 120000, 100000), ('East', 110000, 95000), ('West', 90000, 85000);
What is the percentage of the population with access to clean water in each region?
SELECT Region, (SUM(CleanWater) / SUM(Population)) * 100 AS CleanWaterPercentage FROM RegionsCleanWater GROUP BY Region;
gretelai_synthetic_text_to_sql
CREATE TABLE mines (id INT PRIMARY KEY, name VARCHAR(255), location VARCHAR(255), year_opened INT, total_employees INT); INSERT INTO mines (id, name, location, year_opened, total_employees) VALUES (1, 'Grasberg Mine', 'Indonesia', 1973, 19000); INSERT INTO mines (id, name, location, year_opened, total_employees) VALUES (2, 'Batu Hijau Mine', 'Indonesia', 2000, 7500); CREATE TABLE labor_productivity (id INT PRIMARY KEY, mine_id INT, productivity_score INT, year INT); INSERT INTO labor_productivity (id, mine_id, productivity_score, year) VALUES (1, 1, 8, 2010); INSERT INTO labor_productivity (id, mine_id, productivity_score, year) VALUES (2, 2, 9, 2015);
Which mines in Indonesia have a labor productivity score below 6?
SELECT mines.id, labor_productivity.productivity_score FROM labor_productivity JOIN mines ON labor_productivity.mine_id = mines.id WHERE mines.location = 'Indonesia' GROUP BY mines.id HAVING MIN(labor_productivity.productivity_score) < 6;
gretelai_synthetic_text_to_sql
CREATE TABLE teams (team_id INT, team_name VARCHAR(50), league VARCHAR(50)); CREATE TABLE games (game_id INT, team_id INT, attendance INT, sport VARCHAR(50));
What is the average attendance for baseball games in the National league?
SELECT AVG(games.attendance) FROM games JOIN teams ON games.team_id = teams.team_id WHERE teams.league = 'National' AND games.sport = 'Baseball';
gretelai_synthetic_text_to_sql
CREATE TABLE local_impact (id INT, city VARCHAR(50), value INT); INSERT INTO local_impact (id, city, value) VALUES (1, 'New York', 1000), (2, 'Los Angeles', 800), (3, 'Tokyo', 800);
Determine the percentage of local economic impact in New York and Los Angeles.
SELECT city, ROUND(100.0 * value / SUM(value) OVER (PARTITION BY NULL), 2) AS percentage FROM local_impact WHERE city IN ('New York', 'Los Angeles');
gretelai_synthetic_text_to_sql
CREATE TABLE FastChargers (Id INT, Type VARCHAR(255), Manufacturer VARCHAR(255), ChargingTime INT); INSERT INTO FastChargers (Id, Type, Manufacturer, ChargingTime) VALUES (1, 'DC Fast', 'Tesla', 30), (2, 'DC Fast', 'ChargePoint', 45), (3, 'DC Fast', 'EVgo', 35), (4, 'DC Fast', 'SemaConnect', 40);
What is the minimum charging time of DC Fast EV chargers?
SELECT MIN(ChargingTime) FROM FastChargers WHERE Type = 'DC Fast'
gretelai_synthetic_text_to_sql
CREATE TABLE CosmeticsPackaging (product_id INT, product_name VARCHAR(100), packaging_weight DECIMAL(5,2), packaging_material VARCHAR(50), country VARCHAR(50)); INSERT INTO CosmeticsPackaging VALUES (601, 'Lip Balm', 10, 'Plastic', 'Japan'), (602, 'Eyebrow Pencil', 8, 'Wood', 'Japan'), (603, 'Eyeshadow', 15, 'Plastic', 'Japan'), (604, 'Concealer', 12, 'Glass', 'Japan'), (605, 'Mascara', 7, 'Plastic', 'Japan');
Show the total weight of plastic packaging used for cosmetics sold in Japan.
SELECT SUM(packaging_weight) FROM CosmeticsPackaging WHERE country = 'Japan' AND packaging_material = 'Plastic';
gretelai_synthetic_text_to_sql
CREATE TABLE countries (id INT, name TEXT); CREATE TABLE articles (id INT, title TEXT, content TEXT, category_id INT, country_id INT); INSERT INTO countries (id, name) VALUES (1, 'USA'), (2, 'Canada'), (3, 'Mexico'); INSERT INTO articles (id, title, content, category_id, country_id) VALUES (1, 'Article 1', 'Content 1', NULL, 1), (2, 'Article 2', 'Content 2', 2, 2), (3, 'Article 3', 'Content 3', NULL, 3), (4, 'Article 4', 'Content 4', 1, 1), (5, 'Article 5', 'Content 5', 3, 2);
What is the total number of articles published in each country, and which articles were published without a category?
SELECT COALESCE(countries.name, 'Uncategorized') as country, COUNT(articles.id) FROM articles LEFT JOIN countries ON articles.country_id = countries.id GROUP BY country ORDER BY COUNT(articles.id) DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE users (id INT, name VARCHAR(20), country VARCHAR(20), last_login TIMESTAMP); INSERT INTO users (id, name, country, last_login) VALUES (4, 'Charlie', 'Canada', '2021-01-05 10:00:00');
What is the average number of logins for each user?
SELECT name AS user, AVG(DATEDIFF('second', MIN(last_login), MAX(last_login))) as avg_logins FROM users GROUP BY user;
gretelai_synthetic_text_to_sql
CREATE TABLE SatelliteLaunches (id INT, launch_country VARCHAR(50), launch_site VARCHAR(50)); CREATE TABLE Countries (id INT, name VARCHAR(50), code VARCHAR(3));
List all countries involved in satellite launches?
SELECT DISTINCT SatelliteLaunches.launch_country FROM SatelliteLaunches JOIN Countries ON SatelliteLaunches.launch_country = Countries.name;
gretelai_synthetic_text_to_sql
CREATE TABLE customer_accounts (customer_id INT, account_type VARCHAR(50), balance FLOAT); INSERT INTO customer_accounts (customer_id, account_type, balance) VALUES (1, 'Shariah Compliant Checking', 5000.00), (2, 'Shariah Compliant Savings', 8000.00), (3, 'Shariah Compliant Checking', 3000.00), (4, 'Shariah Compliant Savings', 12000.00);
What is the average account balance for customers in the Shariah Compliant Savings group?
SELECT AVG(balance) FROM customer_accounts WHERE account_type = 'Shariah Compliant Savings';
gretelai_synthetic_text_to_sql
CREATE TABLE traditional_arts (art_id INT, art_name TEXT, art_type TEXT, artist TEXT, years_practiced INT); INSERT INTO traditional_arts (art_id, art_name, art_type, artist, years_practiced) VALUES (1, 'Thangka Painting', 'Painting', 'Sonam', 55), (2, 'Talavera Pottery', 'Pottery', 'Rafael', 60);
Identify traditional arts that have been practiced for more than 50 years, and their respective artists.
SELECT art_name, artist FROM traditional_arts WHERE years_practiced > 50;
gretelai_synthetic_text_to_sql
CREATE TABLE ArtWorkSales (artworkID INT, saleDate DATE, artworkMedium VARCHAR(50), revenue DECIMAL(10,2));
What was the total revenue for each artwork medium in each year?
SELECT artworkMedium, YEAR(saleDate) as sale_year, SUM(revenue) as total_revenue FROM ArtWorkSales GROUP BY artworkMedium, sale_year;
gretelai_synthetic_text_to_sql
CREATE TABLE customer_transactions (id INT, customer_id INT, transaction_value DECIMAL(10, 2), transaction_date DATE); INSERT INTO customer_transactions (id, customer_id, transaction_value, transaction_date) VALUES (1, 1, 100, '2022-01-01'), (2, 1, 200, '2022-01-15'), (3, 2, 50, '2022-01-05'), (4, 2, 150, '2022-01-30'), (5, 3, 300, '2022-01-20');
What is the average transaction value and standard deviation for each customer in the last year?
SELECT c.customer_id, AVG(c.transaction_value) AS avg_transaction_value, STDDEV(c.transaction_value) AS stddev_transaction_value FROM customer_transactions c WHERE c.transaction_date >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR) GROUP BY c.customer_id;
gretelai_synthetic_text_to_sql
CREATE TABLE strategies (id INT, investment_id INT, strategy VARCHAR(30)); CREATE TABLE esg_scores (id INT, strategy_id INT, score INT); INSERT INTO strategies (id, investment_id, strategy) VALUES (1, 1, 'Microloans'), (2, 1, 'Scholarships'), (3, 2, 'Health Clinics'), (4, 3, 'Tutoring Programs'), (5, 4, 'Sustainable Agriculture'); INSERT INTO esg_scores (id, strategy_id, score) VALUES (1, 1, 75), (2, 1, 85), (3, 2, 60), (4, 3, 90), (5, 4, 95), (6, 4, 100);
What is the sum of ESG scores for each investment strategy?
SELECT s.strategy, SUM(es.score) as total_score FROM strategies s INNER JOIN esg_scores es ON s.id = es.strategy_id GROUP BY s.strategy;
gretelai_synthetic_text_to_sql
CREATE TABLE language_preservation_programs_region (id INT, program_name VARCHAR(100), language VARCHAR(50), region VARCHAR(50)); INSERT INTO language_preservation_programs_region (id, program_name, language, region) VALUES (1, 'Endangered Languages Program', 'Quechua', 'South America'), (2, 'Indigenous Languages Initiative', 'Navajo', 'North America'), (3, 'Minority Language Support', 'Gaelic', 'Europe');
How many languages are preserved in each language preservation program by region?
SELECT region, program_name, COUNT(DISTINCT language) as num_languages FROM language_preservation_programs_region GROUP BY region, program_name;
gretelai_synthetic_text_to_sql
CREATE TABLE Infrastructure (investment_id INT, investment_type VARCHAR(20), region VARCHAR(20), investment_amount FLOAT, investment_date DATE);
Insert new network infrastructure investments in the 'Metro' region for Q1 2024.
INSERT INTO Infrastructure (investment_id, investment_type, region, investment_amount, investment_date) VALUES (1, '5G Tower', 'Metro', 500000, '2024-01-01'), (2, 'Broadband Node', 'Metro', 350000, '2024-01-15'), (3, 'Fiber Optics', 'Metro', 200000, '2024-01-31');
gretelai_synthetic_text_to_sql
CREATE TABLE space_missions (id INT, mission_name VARCHAR(50), launch_date DATE, scheduled_date DATE); INSERT INTO space_missions VALUES (1, 'Artemis I', '2022-08-29', '2022-06-29'); INSERT INTO space_missions VALUES (2, 'Mars Science Laboratory', '2011-11-26', '2011-10-30');
Which space missions had a delay of more than 30 days in the space_missions table?
SELECT mission_name, launch_date, scheduled_date, DATEDIFF(day, scheduled_date, launch_date) as delay_days FROM space_missions WHERE DATEDIFF(day, scheduled_date, launch_date) > 30;
gretelai_synthetic_text_to_sql
CREATE TABLE veteran_employment (veteran_id INT, industry VARCHAR(50), state VARCHAR(50), year INT, employment_rate FLOAT); INSERT INTO veteran_employment (veteran_id, industry, state, year, employment_rate) VALUES (5001, 'IT', 'California', 2019, 0.85);
Retrieve veteran employment statistics for the IT sector in California in 2019
SELECT * FROM veteran_employment WHERE industry = 'IT' AND state = 'California' AND year = 2019;
gretelai_synthetic_text_to_sql
CREATE TABLE sales (sales_id INT, item_id INT, sales_amount DECIMAL(5,2)); CREATE TABLE menu (item_id INT, item_name VARCHAR(255)); INSERT INTO sales VALUES (1, 1, 20.00), (2, 1, 30.00), (3, 2, 40.00), (4, 3, 50.00), (5, 4, 60.00); INSERT INTO menu VALUES (1, 'Cheese Pizza'), (2, 'Margherita Pizza'), (3, 'Chicken Alfredo'), (4, 'Beef Lasagna');
What is the percentage of sales for the top 3 selling items?
SELECT item_id, sales_amount, (sales_amount / (SELECT SUM(sales_amount) FROM sales WHERE item_id IN (SELECT item_id FROM (SELECT item_id, RANK() OVER (ORDER BY sales_amount DESC) AS rank FROM sales) AS subquery WHERE rank <= 3)) * 100) AS sales_percentage FROM sales WHERE item_id IN (SELECT item_id FROM (SELECT item_id, RANK() OVER (ORDER BY sales_amount DESC) AS rank FROM sales) AS subquery WHERE rank <= 3);
gretelai_synthetic_text_to_sql
CREATE TABLE department (name VARCHAR(255), id INT);CREATE TABLE graduate_student (name VARCHAR(255), department_id INT, publication_year INT);
What is the maximum number of publications per year for graduate students in the Physics department?
SELECT MAX(publication_year) FROM graduate_student WHERE department_id IN (SELECT id FROM department WHERE name = 'Physics');
gretelai_synthetic_text_to_sql
CREATE TABLE charging_stations (id INT, station_name VARCHAR(255), region VARCHAR(255), num_stalls INT);
What is the total number of charging stations in the 'charging_stations' table, grouped by their 'region' and 'num_stalls'?
SELECT region, num_stalls, COUNT(*) FROM charging_stations GROUP BY region, num_stalls;
gretelai_synthetic_text_to_sql
CREATE TABLE plastic_waste (country VARCHAR(50), year INT, amount INT); INSERT INTO plastic_waste (country, year, amount) VALUES ('Nigeria', 2022, 60000), ('South Africa', 2022, 50000), ('Egypt', 2022, 40000);
What is the total waste generation in the plastic category for each country in 2022?'
SELECT country, SUM(amount) as total_plastic_waste FROM plastic_waste WHERE year = 2022 GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE Projects (id INT, name VARCHAR(100), PRIMARY KEY (id)); INSERT INTO Projects (id, name) VALUES (1, 'Project A'), (2, 'Project B'); CREATE TABLE EnergyStorage (id INT, project_id INT, storage_type VARCHAR(100), PRIMARY KEY (id), FOREIGN KEY (project_id) REFERENCES Projects(id)); INSERT INTO EnergyStorage (id, project_id, storage_type) VALUES (1, 1, 'Batteries'), (2, 2, 'Flywheels'); CREATE TABLE Funding (id INT, project_id INT, fund_name VARCHAR(100), amount FLOAT, PRIMARY KEY (id), FOREIGN KEY (project_id) REFERENCES Projects(id)); INSERT INTO Funding (id, project_id, fund_name, amount) VALUES (1, 1, 'Solar Fund A', 200.0), (2, 2, 'Wind Fund B', 300.0);
What is the average amount of funding received by projects that have implemented energy storage systems?
SELECT AVG(F.amount) FROM Funding F INNER JOIN EnergyStorage ES ON F.project_id = ES.project_id;
gretelai_synthetic_text_to_sql
CREATE TABLE cargo (id INT PRIMARY KEY, name VARCHAR(255), weight FLOAT, volume FLOAT, destination VARCHAR(255)); INSERT INTO cargo (id, name, weight, volume, destination) VALUES (1, 'Electronics', 12.5, 50.2, 'Tokyo');
Create a view for cargoes with a weight greater than 10 metric tons
CREATE VIEW cargo_heavy_new AS SELECT * FROM cargo WHERE weight > 10;
gretelai_synthetic_text_to_sql
CREATE TABLE Contract_Negotiations (contract_id INT, equipment_name VARCHAR(50), customer_country VARCHAR(50), negotiation_date DATE, negotiation_duration INT); INSERT INTO Contract_Negotiations (contract_id, equipment_name, customer_country, negotiation_date, negotiation_duration) VALUES (1, 'Tank A', 'Canada', '2020-01-01', 30); INSERT INTO Contract_Negotiations (contract_id, equipment_name, customer_country, negotiation_date, negotiation_duration) VALUES (2, 'Helicopter B', 'Canada', '2021-01-01', 50);
What is the maximum contract negotiation duration for military equipment sales to Canada?
SELECT equipment_name, customer_country, MAX(negotiation_duration) AS max_negotiation_duration FROM Contract_Negotiations WHERE customer_country = 'Canada' GROUP BY equipment_name, customer_country;
gretelai_synthetic_text_to_sql
CREATE TABLE habitat (id INT, name VARCHAR(255)); INSERT INTO habitat (id, name) VALUES (1, 'Habitat1'); INSERT INTO habitat (id, name) VALUES (2, 'Habitat2'); CREATE TABLE wildlife (id INT, habitat_id INT); INSERT INTO wildlife (id, habitat_id) VALUES (1, 1); CREATE TABLE region (id INT, name VARCHAR(255)); INSERT INTO region (id, name) VALUES (1, 'Region1'); INSERT INTO region (id, name) VALUES (2, 'Region2');
Which habitats have no wildlife present?
SELECT h.name FROM habitat h LEFT JOIN wildlife w ON h.id = w.habitat_id WHERE w.habitat_id IS NULL;
gretelai_synthetic_text_to_sql
CREATE TABLE Public_Works (project_id INT, project_name VARCHAR(50), location VARCHAR(50), construction_cost FLOAT); INSERT INTO Public_Works (project_id, project_name, location, construction_cost) VALUES (1, 'Highway Construction', 'Utah', 20000000); INSERT INTO Public_Works (project_id, project_name, location, construction_cost) VALUES (2, 'Bike Lane Implementation', 'Minnesota', 1000000);
What is the total construction cost for transportation projects in the 'Public_Works' table?
SELECT SUM(construction_cost) FROM Public_Works WHERE project_name LIKE '%Transportation%';
gretelai_synthetic_text_to_sql
CREATE TABLE safety_incidents (incident_id INT, aircraft_type VARCHAR(50), incident_description VARCHAR(500));
How many safety incidents have been reported for each aircraft type?
SELECT aircraft_type, COUNT(incident_id) as num_incidents FROM safety_incidents GROUP BY aircraft_type;
gretelai_synthetic_text_to_sql
CREATE TABLE art_forms (id INT, name TEXT, type TEXT, revenue INT); INSERT INTO art_forms (id, name, type, revenue) VALUES (1, 'Art Form A', 'Type1', 2000), (2, 'Art Form B', 'Type2', 3000), (3, 'Art Form C', 'Type1', 1000);
Which traditional art form has the highest average revenue?
SELECT type, AVG(revenue) FROM art_forms GROUP BY type ORDER BY AVG(revenue) DESC LIMIT 1
gretelai_synthetic_text_to_sql
CREATE TABLE entrees (id INT, name VARCHAR(255), type VARCHAR(255), serving_size INT); INSERT INTO entrees (id, name, type, serving_size) VALUES (1, 'Vegetable Lasagna', 'Vegetarian', 400), (2, 'Spaghetti Squash', 'Vegetarian', 300);
What is the maximum serving size of our vegetarian entrées?
SELECT MAX(serving_size) FROM entrees WHERE type = 'Vegetarian';
gretelai_synthetic_text_to_sql
CREATE TABLE Vendors (VendorID VARCHAR(20), VendorName VARCHAR(20)); INSERT INTO Vendors (VendorID, VendorName) VALUES ('X', 'VendorX'), ('Y', 'VendorY'); CREATE TABLE FreightForwardingTransactions (TransactionID INT, VendorID VARCHAR(20), TransactionStatus VARCHAR(20), TransactionDate DATE); INSERT INTO FreightForwardingTransactions (TransactionID, VendorID, TransactionStatus, TransactionDate) VALUES (1, 'Y', 'Created', '2022-01-03');
What is the earliest transaction date for 'VendorY' in the freight forwarding domain?
SELECT MIN(FreightForwardingTransactions.TransactionDate) AS EarliestTransactionDate FROM FreightForwardingTransactions JOIN Vendors ON FreightForwardingTransactions.VendorID = Vendors.VendorID WHERE Vendors.VendorName = 'VendorY';
gretelai_synthetic_text_to_sql
CREATE TABLE investments (id INT, sector VARCHAR(20), amount DECIMAL(10,2)); INSERT INTO investments (id, sector, amount) VALUES (1, 'Education', 5000.00), (2, 'Healthcare', 7000.00), (3, 'Education', 6000.00); CREATE TABLE strategies (id INT, investment_id INT, strategy VARCHAR(30)); INSERT INTO strategies (id, investment_id, strategy) VALUES (1, 1, 'Microloans'), (2, 1, 'Scholarships'), (3, 2, 'Health Clinics'), (4, 3, 'Tutoring Programs');
What is the average investment per strategy in the education sector?
SELECT AVG(i.amount) FROM investments i INNER JOIN strategies s ON i.id = s.investment_id WHERE i.sector = 'Education';
gretelai_synthetic_text_to_sql
CREATE SCHEMA PollutionControl; CREATE TABLE Initiatives (initiative_id INT, year INT); INSERT INTO Initiatives (initiative_id, year) VALUES (1, 2020), (2, 2021), (3, 2020), (4, 2021), (5, 2022);
What is the total number of pollution control initiatives in the 'PollutionControl' schema from 2020 and 2021?
SELECT COUNT(*) FROM PollutionControl.Initiatives WHERE year IN (2020, 2021);
gretelai_synthetic_text_to_sql
CREATE TABLE volunteers (volunteer_id INT, region_id INT, volunteer_age INT); CREATE TABLE regions (region_id INT, region_type VARCHAR(10)); INSERT INTO volunteers (volunteer_id, region_id, volunteer_age) VALUES (1, 1, 25), (2, 1, 35), (3, 2, 22), (4, 2, 30), (5, 3, 28); INSERT INTO regions (region_id, region_type) VALUES (1, 'rural'), (2, 'urban'), (3, 'semi-urban');
How many volunteers are there in the 'regions' table with 'region_type' as 'rural'?
SELECT COUNT(*) FROM volunteers v JOIN regions r ON v.region_id = r.region_id WHERE r.region_type = 'rural';
gretelai_synthetic_text_to_sql
CREATE TABLE transactions (id INT PRIMARY KEY, customer_id INT, amount DECIMAL(10,2), transaction_date DATE, customer_status VARCHAR(50)); INSERT INTO transactions (id, customer_id, amount, transaction_date, customer_status) VALUES (1, 1, 500.00, '2022-01-01', 'Gold'); INSERT INTO transactions (id, customer_id, amount, transaction_date, customer_status) VALUES (2, 2, 750.00, '2022-01-02', 'Silver');
Delete transactions over $1000 for customers with 'Gold' status
DELETE t FROM transactions t WHERE t.amount > 1000 AND t.customer_status = 'Gold';
gretelai_synthetic_text_to_sql
CREATE TABLE indigenous_food_systems (id INT, name TEXT, location TEXT, area_ha FLOAT); INSERT INTO indigenous_food_systems (id, name, location, area_ha) VALUES (1, 'System A', 'Mexico', 7), (2, 'System B', 'Mexico', 3), (3, 'System C', 'Brazil', 4.5); CREATE TABLE agroecological_projects (id INT, name TEXT, location TEXT, area_ha FLOAT); INSERT INTO agroecological_projects (id, name, location, area_ha) VALUES (1, 'Project A', 'Asia', 1.5), (2, 'Project B', 'Asia', 2.2), (3, 'Project C', 'Africa', 3);
Which indigenous food systems have an area greater than the average area of agroecological projects in 'Asia'?
SELECT name FROM indigenous_food_systems WHERE area_ha > (SELECT AVG(area_ha) FROM agroecological_projects WHERE location = 'Asia');
gretelai_synthetic_text_to_sql
CREATE TABLE Donations (DonationID int, DonorID int, OrganizationID int, AmountDonated decimal(10,2), DonationDate date); INSERT INTO Donations (DonationID, DonorID, OrganizationID, AmountDonated, DonationDate) VALUES (1, 1, 101, 2000.00, '2021-01-01'), (2, 2, 102, 2500.00, '2021-02-01'); CREATE TABLE Organizations (OrganizationID int, OrganizationName varchar(100)); INSERT INTO Organizations (OrganizationID, OrganizationName) VALUES (101, 'Effective Altruism Funds'), (102, 'Gates Philanthropy Partners');
What is the total amount donated by each organization in 2021?
SELECT OrganizationID, OrganizationName, SUM(AmountDonated) as TotalDonated FROM Donations JOIN Organizations ON Donations.OrganizationID = Organizations.OrganizationID WHERE YEAR(DonationDate) = 2021 GROUP BY OrganizationID, OrganizationName;
gretelai_synthetic_text_to_sql
CREATE TABLE PlayerGame (PlayerID INT, GameID INT, Playtime INT); INSERT INTO PlayerGame (PlayerID, GameID, Playtime) VALUES (1, 1, 100); INSERT INTO PlayerGame (PlayerID, GameID, Playtime) VALUES (2, 2, 150);
What is the total playtime of all players in a specific game?
SELECT GameID, SUM(Playtime) as TotalPlaytime FROM PlayerGame GROUP BY GameID
gretelai_synthetic_text_to_sql
CREATE TABLE Faculty (FacultyID INT, Name VARCHAR(50), Department VARCHAR(50), Gender VARCHAR(10), Salary INT); INSERT INTO Faculty (FacultyID, Name, Department, Gender, Salary) VALUES (1, 'Alice', 'Mathematics', 'Female', 80000); INSERT INTO Faculty (FacultyID, Name, Department, Gender, Salary) VALUES (2, 'Bob', 'Mathematics', 'Male', 85000); CREATE TABLE ResearchGrants (GrantID INT, FacultyID INT, Amount INT); INSERT INTO ResearchGrants (GrantID, FacultyID, Amount) VALUES (1, 1, 90000); INSERT INTO ResearchGrants (GrantID, FacultyID, Amount) VALUES (2, 2, 95000);
What is the maximum amount of research grant awarded to a faculty member in the Mathematics department?
SELECT MAX(rg.Amount) FROM ResearchGrants rg INNER JOIN Faculty f ON rg.FacultyID = f.FacultyID WHERE f.Department = 'Mathematics';
gretelai_synthetic_text_to_sql
CREATE TABLE SatelliteLaunches (id INT, name VARCHAR(255), type VARCHAR(255), launch_date DATE, country VARCHAR(255)); INSERT INTO SatelliteLaunches (id, name, type, launch_date, country) VALUES (1, 'Sputnik 1', 'Satellite', '1957-10-04', 'Russia'), (2, 'Explorer 1', 'Satellite', '1958-01-31', 'United States'), (3, 'KITSAT-1', 'Satellite', '1992-08-10', 'South Korea');
Which countries have launched the most satellites into orbit?
SELECT country, COUNT(*) as num_satellite_launches FROM SatelliteLaunches GROUP BY country ORDER BY num_satellite_launches DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE video_content (id INTEGER, title TEXT, type TEXT, genre TEXT, duration INTEGER, release_date DATE, views INTEGER); INSERT INTO video_content (id, title, type, genre, duration, release_date, views) VALUES (1, 'Media Literacy 101', 'Video', 'Media Literacy', 15, '2019-12-31', 2000), (2, 'Advanced Media Literacy', 'Video', 'Media Literacy', 25, '2021-01-01', 1500);
Get the average duration of videos in the video_content table related to media literacy and published since 2019.
SELECT AVG(duration) AS avg_duration FROM video_content WHERE genre = 'Media Literacy' AND release_date >= '2019-01-01';
gretelai_synthetic_text_to_sql
CREATE TABLE Grants (GrantID INT, Title VARCHAR(100), Amount DECIMAL(10,2), Organization VARCHAR(50), StartDate DATE, EndDate DATE, StudentID INT, Department VARCHAR(50)); CREATE TABLE Students (StudentID INT, FirstName VARCHAR(50), LastName VARCHAR(50), Department VARCHAR(50), Program VARCHAR(50), Gender VARCHAR(10));
What is the maximum grant amount awarded to a graduate student in the Engineering department in the past 3 years?
SELECT MAX(g.Amount) as 'Maximum Grant Amount' FROM Grants g JOIN Students s ON g.StudentID = s.StudentID WHERE s.Department = 'Engineering' AND g.StartDate >= DATEADD(year, -3, GETDATE());
gretelai_synthetic_text_to_sql
CREATE TABLE shared_bikes (bike_id INT, city VARCHAR(20), is_electric BOOLEAN); INSERT INTO shared_bikes (bike_id, city, is_electric) VALUES (1, 'New York', true), (2, 'Chicago', true), (3, 'New York', false);
What is the total number of traditional and electric shared bikes in the shared_bikes table?
SELECT SUM(1 - is_electric) FROM shared_bikes WHERE city IN ('New York', 'Chicago');
gretelai_synthetic_text_to_sql
CREATE TABLE Artists (ArtistID INT, ArtistName VARCHAR(100), Country VARCHAR(50)); INSERT INTO Artists (ArtistID, ArtistName, Country) VALUES (1, 'Enrique Iglesias', 'Spain'), (2, 'Green Day', 'USA'); CREATE TABLE Songs (SongID INT, SongName VARCHAR(100), ArtistID INT, Length FLOAT); INSERT INTO Songs (SongID, SongName, ArtistID, Length) VALUES (1, 'Hero', 1, 4.2), (2, 'Boulevard of Broken Dreams', 2, 4.2); CREATE TABLE Albums (AlbumID INT, AlbumName VARCHAR(100), ArtistID INT, LongestSongLength FLOAT); INSERT INTO Albums (AlbumID, AlbumName, ArtistID, LongestSongLength) VALUES (1, 'Euphoria', 1, 5.5), (2, 'American Idiot', 2, 4.7);
What are the names of all albums released by artists from Spain that contain at least one song longer than 5 minutes?
SELECT AlbumName FROM Albums a JOIN Artists ar ON a.ArtistID = ar.ArtistID JOIN Songs s ON ar.ArtistID = s.ArtistID WHERE Country = 'Spain' AND s.Length > 5 GROUP BY AlbumName;
gretelai_synthetic_text_to_sql
CREATE TABLE Workers (WorkerID INT, Salary FLOAT, Country VARCHAR(20)); INSERT INTO Workers VALUES (1, 500, 'India'); INSERT INTO Workers VALUES (2, 600, 'India');
What is the average salary of workers in textile factories in India?
SELECT AVG(Salary) FROM Workers WHERE Country = 'India';
gretelai_synthetic_text_to_sql
CREATE TABLE water_usage (id INT, usage FLOAT, purpose VARCHAR(20), date DATE); INSERT INTO water_usage (id, usage, purpose, date) VALUES (1, 0, 'industrial', '2021-12-01'); INSERT INTO water_usage (id, usage, purpose, date) VALUES (2, 150, 'residential', '2021-12-01');
Determine the percentage of days in 'December 2021' with zero water usage for 'industrial' purposes in the 'water_usage' table
SELECT ROUND(100.0 * AVG(CASE WHEN usage = 0 THEN 1 ELSE 0 END), 2) as percentage FROM water_usage WHERE purpose = 'industrial' AND date BETWEEN '2021-12-01' AND '2021-12-31' GROUP BY date HAVING COUNT(*) = 31;
gretelai_synthetic_text_to_sql
CREATE TABLE Sales_by_Size (id INT, size VARCHAR(20), season VARCHAR(20), sales INT); INSERT INTO Sales_by_Size (id, size, season, sales) VALUES (1, 'XS', 'Spring', 100), (2, 'S', 'Spring', 200), (3, 'M', 'Spring', 300), (4, 'L', 'Spring', 150), (5, 'XL', 'Spring', 50), (6, 'XS', 'Summer', 120), (7, 'S', 'Summer', 220), (8, 'M', 'Summer', 320), (9, 'L', 'Summer', 180), (10, 'XL', 'Summer', 80), (11, 'XS', 'Fall', 150), (12, 'S', 'Fall', 250), (13, 'M', 'Fall', 350), (14, 'L', 'Fall', 200), (15, 'XL', 'Fall', 100), (16, 'XS', 'Winter', 180), (17, 'S', 'Winter', 280), (18, 'M', 'Winter', 380), (19, 'L', 'Winter', 250), (20, 'XL', 'Winter', 150);
What is the total sales for each size, with a separate column for each season's sales?
SELECT size, SUM(CASE WHEN season = 'Spring' THEN sales ELSE 0 END) AS spring_sales, SUM(CASE WHEN season = 'Summer' THEN sales ELSE 0 END) AS summer_sales, SUM(CASE WHEN season = 'Fall' THEN sales ELSE 0 END) AS fall_sales, SUM(CASE WHEN season = 'Winter' THEN sales ELSE 0 END) AS winter_sales FROM Sales_by_Size GROUP BY size;
gretelai_synthetic_text_to_sql
CREATE TABLE mines (id INT, mine_name VARCHAR(50), production_year INT, neodymium_pr Float, praseodymium_pr FLOAT, dysprosium_pr FLOAT); INSERT INTO mines (id, mine_name, production_year, neodymium_pr, praseodymium_pr, dysprosium_pr) VALUES (1, 'Mount Weld', 2018, 3000, 2000, 1500), (2, 'Bayan Obo', 2018, 10000, 5000, 2000);
How many Rare Earth Elements are produced by each mine?
SELECT mine_name, production_year, neodymium_pr + praseodymium_pr + dysprosium_pr as total_production FROM mines;
gretelai_synthetic_text_to_sql
CREATE TABLE production (id INT, mine_id INT, year INT, element TEXT, production_quantity INT); INSERT INTO production (id, mine_id, year, element, production_quantity) VALUES (1, 1, 2019, 'Lanthanum', 250), (2, 2, 2019, 'Lanthanum', 400), (3, 3, 2019, 'Lanthanum', 550), (4, 1, 2019, 'Cerium', 300), (5, 2, 2019, 'Cerium', 450), (6, 3, 2019, 'Cerium', 600);
List the top 3 producers of Lanthanum by total production quantity for the year 2019.
SELECT mine_id, SUM(production_quantity) FROM production WHERE year = 2019 AND element = 'Lanthanum' GROUP BY mine_id ORDER BY SUM(production_quantity) DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE Volunteer_Hours (id INT, volunteer_id INT, hours DECIMAL(10, 2), hour_date DATE); INSERT INTO Volunteer_Hours (id, volunteer_id, hours, hour_date) VALUES (1, 1, 2.00, '2020-06-01'); INSERT INTO Volunteer_Hours (id, volunteer_id, hours, hour_date) VALUES (2, 2, 3.00, '2021-03-15');
Who are the top 5 volunteers who have donated the most time, in the last 12 months, and what is the total time donated by each?
SELECT volunteer_id, SUM(hours) as total_hours FROM Volunteer_Hours WHERE hour_date >= DATE_SUB(CURRENT_DATE, INTERVAL 12 MONTH) GROUP BY volunteer_id ORDER BY total_hours DESC LIMIT 5;
gretelai_synthetic_text_to_sql
CREATE TABLE regions (region_id INT, region VARCHAR(50)); INSERT INTO regions (region_id, region) VALUES (1, 'North'), (2, 'South'), (3, 'East'), (4, 'West'); CREATE TABLE cases (id INT, region_id INT, days_to_resolve INT); INSERT INTO cases (id, region_id, days_to_resolve) VALUES (1, 1, 60), (2, 1, 75), (3, 2, 45), (4, 3, 90), (5, 4, 55), (6, 4, 40);
What is the average time to resolve criminal justice cases per region?
SELECT r.region, AVG(c.days_to_resolve) AS avg_days_to_resolve FROM cases c JOIN regions r ON c.region_id = r.region_id GROUP BY r.region;
gretelai_synthetic_text_to_sql
CREATE TABLE user_info (id INT, user_name TEXT, diet TEXT); INSERT INTO user_info (id, user_name, diet) VALUES (1, 'Alice', 'Vegetarian'), (2, 'Bob', 'Vegan'); CREATE TABLE meals (id INT, user_id INT, calories INT, meal_date DATE); INSERT INTO meals (id, user_id, calories, meal_date) VALUES (1, 1, 1200, '2023-01-01'), (2, 2, 1500, '2023-01-02');
What is the average caloric intake for users in the "Vegetarian" diet group for the past week?
SELECT AVG(calories) FROM (SELECT calories FROM meals JOIN user_info ON user_info.id = meals.user_id WHERE diet = 'Vegetarian' AND meal_date BETWEEN DATE_SUB(CURRENT_DATE(), INTERVAL 1 WEEK) AND CURRENT_DATE()) AS subquery;
gretelai_synthetic_text_to_sql
CREATE TABLE players (id INT PRIMARY KEY, name TEXT, last_login DATETIME);
Delete player records who haven't played for 6 months from the players table
DELETE FROM players WHERE last_login < NOW() - INTERVAL 6 MONTH;
gretelai_synthetic_text_to_sql
CREATE TABLE MilitarySpending (Country VARCHAR(50), Year INT, Spending NUMERIC(18,2)); INSERT INTO MilitarySpending (Country, Year, Spending) VALUES ('United States', 2021, 770000), ('China', 2021, 250000), ('India', 2021, 66000), ('United States', 2020, 750000), ('China', 2020, 230000), ('India', 2020, 60000);
What is the percentage change in military spending for each country from the previous year?
SELECT A.Country, (B.Spending - A.Spending)*100.0/A.Spending AS PercentageChange FROM MilitarySpending A INNER JOIN MilitarySpending B ON A.Country = B.Country AND A.Year = B.Year - 1;
gretelai_synthetic_text_to_sql
CREATE TABLE DirectorMovies (MovieTitle VARCHAR(50), Director VARCHAR(50)); INSERT INTO DirectorMovies (MovieTitle, Director) VALUES ('The Godfather', 'Francis Ford Coppola'), ('The Shawshank Redemption', 'Frank Darabont'), ('The Godfather: Part II', 'Francis Ford Coppola'), ('The Dark Knight', 'Christopher Nolan'), ('Star Wars: Episode IV - A New Hope', 'George Lucas');
What is the number of movies by director in the Media database?
SELECT Director, COUNT(*) as NumMovies FROM DirectorMovies GROUP BY Director;
gretelai_synthetic_text_to_sql
CREATE TABLE ContractNegotiations (contract_id INT, contractor VARCHAR(50), start_date DATE, end_date DATE); INSERT INTO ContractNegotiations (contract_id, contractor, start_date, end_date) VALUES (1, 'Z', '2021-01-01', '2021-12-31'); INSERT INTO ContractNegotiations (contract_id, contractor, start_date, end_date) VALUES (2, 'Z', '2022-01-01', '2022-12-31');
What is the earliest and latest start and end dates for contracts negotiated by contractor Z?
SELECT contractor, MIN(start_date) as earliest_start_date, MAX(start_date) as latest_start_date, MIN(end_date) as earliest_end_date, MAX(end_date) as latest_end_date FROM ContractNegotiations WHERE contractor = 'Z' GROUP BY contractor;
gretelai_synthetic_text_to_sql
CREATE TABLE Funding (id INT, state VARCHAR(2), program VARCHAR(20), amount FLOAT); INSERT INTO Funding (id, state, program, amount) VALUES (1, 'WA', 'Art for All', 150000.00), (2, 'OR', 'Art Reach', 200000.00), (3, 'WA', 'Unseen Art', 120000.00); CREATE TABLE Communities (id INT, state VARCHAR(2), underrepresented VARCHAR(5)); INSERT INTO Communities (id, state, underrepresented) VALUES (1, 'WA', 'yes'), (2, 'OR', 'yes'), (3, 'WA', 'yes');
What is the total funding received by art programs for underrepresented communities in Washington and Oregon?
SELECT SUM(amount) FROM Funding INNER JOIN Communities ON Funding.state = Communities.state WHERE Communities.underrepresented = 'yes' AND Funding.state IN ('WA', 'OR');
gretelai_synthetic_text_to_sql
CREATE TABLE network_investment (investment_id INT, investment_amount FLOAT, investment_date DATE, state VARCHAR(50));
What is the total network investment for the state of New York in the last 6 months?
SELECT SUM(investment_amount) FROM network_investment WHERE investment_date >= CURDATE() - INTERVAL 6 MONTH AND state = 'New York';
gretelai_synthetic_text_to_sql
CREATE TABLE technology_accessibility (id INT, country VARCHAR, region VARCHAR, score DECIMAL);
What is the average technology accessibility score for countries in the Asia-Pacific region?
SELECT AVG(score) as avg_score FROM technology_accessibility WHERE region = 'Asia-Pacific';
gretelai_synthetic_text_to_sql
CREATE TABLE artists (id INT, name VARCHAR(100), age INT, gender VARCHAR(50)); CREATE TABLE songs (id INT, title VARCHAR(100), release_year INT, genre VARCHAR(50), streams INT, artist_id INT); INSERT INTO artists (id, name, age, gender) VALUES (1, 'Taylor Swift', 31, 'Female'); INSERT INTO artists (id, name, age, gender) VALUES (2, 'Kendrick Lamar', 34, 'Male'); INSERT INTO songs (id, title, release_year, genre, streams, artist_id) VALUES (1, 'Cardigan', 2020, 'Pop', 1000000, 1); INSERT INTO songs (id, title, release_year, genre, streams, artist_id) VALUES (2, 'Humble', 2017, 'Hip Hop', 800000, 2); CREATE TABLE albums (id INT, title VARCHAR(100), release_year INT, artist_id INT); CREATE TABLE album_tracks (id INT, song_id INT, album_id INT); INSERT INTO albums (id, title, release_year, artist_id) VALUES (1, 'Lover', 2019, 1); INSERT INTO album_tracks (id, song_id, album_id) VALUES (1, 1, 1);
What is the maximum number of streams for a song by a female artist?
SELECT MAX(streams) FROM songs INNER JOIN artists ON songs.artist_id = artists.id WHERE artists.gender = 'Female';
gretelai_synthetic_text_to_sql
CREATE TABLE ethical_ai_initiatives (id INT, initiative_name VARCHAR(255), funding_quarter VARCHAR(10), budget DECIMAL(10,2)); INSERT INTO ethical_ai_initiatives (id, initiative_name, funding_quarter, budget) VALUES (1, 'AI Ethics Research', 'Q1 2021', 30000), (2, 'AI Ethics Guidelines Development', 'Q2 2021', 25000);
What is the total budget allocated for ethical AI initiatives in Q1 2021?
SELECT SUM(budget) FROM ethical_ai_initiatives WHERE funding_quarter = 'Q1 2021';
gretelai_synthetic_text_to_sql
CREATE TABLE Branches (branch_id INT, branch_type VARCHAR(255));CREATE TABLE Menu (dish_name VARCHAR(255), branch_id INT, dish_category VARCHAR(255), price DECIMAL(5,2));CREATE TABLE Sales (sale_date DATE, dish_name VARCHAR(255), quantity INT);
What is the total quantity of dishes sold by category in rural branches last month?
SELECT dish_category, SUM(quantity) as total_sales FROM Sales JOIN Menu ON Sales.dish_name = Menu.dish_name JOIN Branches ON Menu.branch_id = Branches.branch_id WHERE branch_type = 'rural' AND sale_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) AND CURRENT_DATE GROUP BY dish_category;
gretelai_synthetic_text_to_sql
CREATE TABLE sales (sale_id INT, item_id INT, sale_quantity INT, sale_date DATE); INSERT INTO sales (sale_id, item_id, sale_quantity, sale_date) VALUES (1, 1, 20, '2022-06-01'), (2, 3, 50, '2022-06-05'), (3, 1, 30, '2022-06-10'), (4, 6, 40, '2022-06-12'), (5, 6, 20, '2022-06-15'), (6, 7, 60, '2022-06-18'); CREATE TABLE menu (item_id INT, name TEXT, category TEXT, is_vegetarian BOOLEAN, price FLOAT, is_vegan BOOLEAN); INSERT INTO menu (item_id, name, category, is_vegetarian, price, is_vegan) VALUES (1, 'Chickpea Curry', 'Lunch', true, 10.5, false), (2, 'Chicken Tikka Masala', 'Lunch', false, 13.0, false), (3, 'Quinoa Salad', 'Starters', true, 7.5, false), (4, 'Eggplant Parmigiana', 'Dinner', true, 12.0, false), (5, 'Bruschetta', 'Starters', true, 6.0, false), (6, 'Vegan Lasagna', 'Dinner', true, 14.0, true), (7, 'Tofu Stir Fry', 'Dinner', true, 11.0, true);
What is the total revenue generated from vegan dishes in a week?
SELECT SUM(s.sale_quantity * m.price) as total_revenue FROM sales s JOIN menu m ON s.item_id = m.item_id WHERE m.is_vegan = true AND s.sale_date BETWEEN '2022-06-01' AND '2022-06-07';
gretelai_synthetic_text_to_sql
CREATE TABLE crops (id INT, name VARCHAR(20), farming_system VARCHAR(20));
How many crops have been grown in the 'indigenous' farming systems in total?
SELECT COUNT(*) FROM crops WHERE farming_system = 'indigenous';
gretelai_synthetic_text_to_sql
CREATE TABLE vessels (id INT, name VARCHAR(255), year_built INT, num_incidents INT, region VARCHAR(255)); INSERT INTO vessels (id, name, year_built, num_incidents, region) VALUES (1, 'Ocean Titan', 1996, 48, 'Atlantic');
List all vessels with more than 50 reported incidents of oil spills in the Atlantic Ocean since 2010.
SELECT name FROM vessels WHERE region = 'Atlantic' AND num_incidents > 50 AND year_built >= 2010;
gretelai_synthetic_text_to_sql
CREATE TABLE customer_complaints (id INT PRIMARY KEY, complaint TEXT, date DATE, resolved BOOLEAN);
Create a table for storing customer complaints
CREATE TABLE customer_complaints AS SELECT * FROM (VALUES (1, 'Data billing issue', '2021-10-01', false), (2, 'Internet connectivity problem', '2021-10-02', true));
gretelai_synthetic_text_to_sql
CREATE TABLE categories (id INT, name TEXT); CREATE TABLE articles (id INT, title TEXT, content TEXT, category_id INT, region_id INT); INSERT INTO categories (id, name) VALUES (1, 'Politics'), (2, 'Technology'), (3, 'Sports'), (4, 'International'); INSERT INTO articles (id, title, content, category_id, region_id) VALUES (1, 'Article 1', 'Content 1', 1, 1), (2, 'Article 2', 'Content 2', 2, 2), (3, 'Article 3', 'Content 3', 1, 3), (4, 'Article 4', 'Content 4', 4, 1), (5, 'Article 5', 'Content 5', 4, 2);
What is the average word count of articles in the 'international' category, grouped by region?
SELECT regions.name, AVG(LENGTH(articles.content) - LENGTH(REPLACE(articles.content, ' ', '')) + 1) as average_word_count FROM categories INNER JOIN articles ON categories.id = articles.category_id INNER JOIN regions ON regions.id = articles.region_id WHERE categories.name = 'International' GROUP BY regions.name;
gretelai_synthetic_text_to_sql
CREATE TABLE judges (judge_id INT, cases_handled INT, year INT);
What is the maximum number of cases handled by a judge in a year?
SELECT MAX(cases_handled) FROM judges WHERE year = (SELECT MAX(year) FROM judges);
gretelai_synthetic_text_to_sql
CREATE TABLE mining_sites (site_id INT, site_name VARCHAR(255)); INSERT INTO mining_sites (site_id, site_name) VALUES (1, 'Site A'), (2, 'Site B'); CREATE TABLE employees (employee_id INT, site_id INT, name VARCHAR(255), position VARCHAR(255)); INSERT INTO employees (employee_id, site_id, name, position) VALUES (1, 1, 'John Doe', 'Engineer'), (2, 1, 'Jane Smith', 'Supervisor'), (3, 2, 'Mike Johnson', 'Engineer');
Calculate the total number of employees for each mining site
SELECT s.site_name, COUNT(e.employee_id) as total_employees FROM mining_sites s INNER JOIN employees e ON s.site_id = e.site_id GROUP BY s.site_name;
gretelai_synthetic_text_to_sql
CREATE TABLE Resource_Management ( id INT PRIMARY KEY, location VARCHAR(50), resource_type VARCHAR(50), quantity INT, year INT ); INSERT INTO Resource_Management (id, location, resource_type, quantity, year) VALUES (1, 'Svalbard', 'Fish', 10000, 2020); INSERT INTO Resource_Management (id, location, resource_type, quantity, year) VALUES (2, 'Greenland', 'Coal', 500000, 2020); INSERT INTO Resource_Management (id, location, resource_type, quantity, year) VALUES (3, 'Greenland', 'Iron Ore', 200000, 2020); INSERT INTO Resource_Management (id, location, resource_type, quantity, year) VALUES (4, 'Svalbard', 'Coal', 30000, 2021); INSERT INTO Resource_Management (id, location, resource_type, quantity, year) VALUES (5, 'Greenland', 'Zinc', 150000, 2021);
What is the total quantity of minerals managed by Greenland and Svalbard in 2020 and 2021?
SELECT location, SUM(quantity) FROM Resource_Management WHERE location IN ('Greenland', 'Svalbard') AND year IN (2020, 2021) AND resource_type = 'Minerals' GROUP BY location
gretelai_synthetic_text_to_sql
CREATE TABLE gadolinium_prices (continent VARCHAR(10), price DECIMAL(5,2), year INT); INSERT INTO gadolinium_prices (continent, price, year) VALUES ('Asia', 120.50, 2020), ('Asia', 125.30, 2019), ('Asia', 116.20, 2018);
Find the maximum price of gadolinium produced in Asia.
SELECT MAX(price) FROM gadolinium_prices WHERE continent = 'Asia';
gretelai_synthetic_text_to_sql
CREATE TABLE Provinces (ProvinceName VARCHAR(50), NumberOfClinics INT); INSERT INTO Provinces (ProvinceName, NumberOfClinics) VALUES ('Ontario', 1500), ('Quebec', 1200), ('British Columbia', 800), ('Alberta', 700), ('Manitoba', 500);
What is the average number of clinics per province, ranked from highest to lowest?
SELECT AVG(NumberOfClinics) AS AvgClinicsPerProvince FROM Provinces
gretelai_synthetic_text_to_sql
CREATE TABLE MarsRovers (Id INT, Name VARCHAR(50), Status VARCHAR(10), LandingYear INT); INSERT INTO MarsRovers (Id, Name, Status, LandingYear) VALUES (1, 'Sojourner', 'Success', 1997), (2, 'Spirit', 'Success', 2004), (3, 'Opportunity', 'Success', 2004), (4, 'Phoenix', 'Success', 2008), (5, 'Curiosity', 'Success', 2012), (6, 'Perseverance', 'Success', 2021), (7, 'Schiaparelli', 'Failure', 2016), (8, 'InSight', 'Success', 2018);
What is the success rate of Mars rovers that have landed on the planet?
SELECT 100.0 * COUNT(Status) FILTER (WHERE Status = 'Success') / COUNT(*) FROM MarsRovers;
gretelai_synthetic_text_to_sql
CREATE SCHEMA RuralHealth; USE RuralHealth; CREATE TABLE States (StateName VARCHAR(50), StateAbbreviation VARCHAR(10)); CREATE TABLE Hospitals (HospitalID INT, HospitalName VARCHAR(50), StateAbbreviation VARCHAR(10), NumberOfBeds INT); INSERT INTO States (StateName, StateAbbreviation) VALUES ('Alabama', 'AL'), ('Alaska', 'AK'); INSERT INTO Hospitals (HospitalID, HospitalName, StateAbbreviation, NumberOfBeds) VALUES (1, 'HospitalA', 'AL', 200), (2, 'HospitalB', 'AK', 300); INSERT INTO StatesPopulation (StateAbbreviation, StatePopulation) VALUES ('AL', 5000000), ('AK', 1000000);
What is the average number of hospital beds per capita for each state, ordered from highest to lowest?
SELECT States.StateAbbreviation, AVG(Hospitals.NumberOfBeds * 1.0 / StatesPopulation.StatePopulation) as AvgBedsPerCapita FROM Hospitals INNER JOIN States ON Hospitals.StateAbbreviation = States.StateAbbreviation INNER JOIN StatesPopulation ON Hospitals.StateAbbreviation = StatesPopulation.StateAbbreviation GROUP BY States.StateAbbreviation ORDER BY AvgBedsPerCapita DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE top_artists (artist_id INT); INSERT INTO top_artists (artist_id) VALUES (1), (2), (3);
What is the number of unique users who streamed each artist, for artists who have performed at music festivals in the last year and have more than 10 million streams?
SELECT a.artist_id, COUNT(DISTINCT u.user_id) as num_users FROM user_streams u JOIN festival_performances f ON u.artist_id = f.artist_id JOIN artist_genre g ON u.artist_id = g.artist_id JOIN top_artists t ON u.artist_id = t.artist_id WHERE f.performance_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY a.artist_id;
gretelai_synthetic_text_to_sql
CREATE TABLE industry (industry_id INT, industry_name VARCHAR(255)); INSERT INTO industry (industry_id, industry_name) VALUES (1, 'IndustryA'), (2, 'IndustryB'); CREATE TABLE co2_emission (year INT, industry_id INT, co2_emission INT); INSERT INTO co2_emission (year, industry_id, co2_emission) VALUES (2000, 1, 1500), (2000, 2, 2500), (2001, 1, 1800), (2001, 2, 2800), (2002, 1, 1200), (2002, 2, 2300);
What is the maximum CO2 emission for each industry?
SELECT industry_id, MAX(co2_emission) as max_emission FROM co2_emission GROUP BY industry_id
gretelai_synthetic_text_to_sql
CREATE TABLE companies (id INT, name TEXT, founder_gender TEXT, exit_strategy TEXT); CREATE TABLE funding_rounds (id INT, company_id INT, size INT);
What is the total funding raised by companies with female founders that have exited via IPO?
SELECT SUM(funding_rounds.size) FROM companies INNER JOIN funding_rounds ON companies.id = funding_rounds.company_id WHERE companies.founder_gender = 'female' AND companies.exit_strategy = 'IPO';
gretelai_synthetic_text_to_sql
CREATE TABLE policyholders (id INT, policyholder_name TEXT, state TEXT, policy_term INT); INSERT INTO policyholders (id, policyholder_name, state, policy_term) VALUES (1, 'Jim Brown', 'TX', 22); CREATE TABLE claims (id INT, policyholder_id INT, amount INT); INSERT INTO claims (id, policyholder_id, amount) VALUES (1, 1, 3000);
What is the maximum claim amount for policyholders living in 'TX' with a policy term less than 2 years?
SELECT MAX(claims.amount) FROM claims JOIN policyholders ON claims.policyholder_id = policyholders.id WHERE policyholders.state = 'TX' AND policyholders.policy_term < 24;
gretelai_synthetic_text_to_sql
CREATE SCHEMA if not exists biotech;USE biotech;CREATE TABLE if not exists startups (name VARCHAR(255), country VARCHAR(255), funding FLOAT);INSERT INTO startups (name, country, funding) VALUES ('Startup1', 'Australia', 6000000), ('Startup2', 'Brazil', 9000000), ('Startup3', 'USA', 3000000), ('Startup4', 'Australia', 7000000), ('Startup5', 'Brazil', 4000000);
What is the maximum and minimum funding received by biotech startups in Australia and Brazil?
SELECT country, MAX(funding) as max_funding, MIN(funding) as min_funding FROM startups GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE inventory (id INT PRIMARY KEY, item_name TEXT, item_type TEXT, quantity INT, date_added DATE); INSERT INTO inventory (id, item_name, item_type, quantity, date_added) VALUES (1, 'Bandages', 'Medical Supplies', 100, '2014-01-01');
Delete all records related to medical supplies from the inventory older than 2015?
DELETE FROM inventory WHERE item_type = 'Medical Supplies' AND date_added < '2016-01-01';
gretelai_synthetic_text_to_sql