context
stringlengths
11
9.12k
question
stringlengths
0
1.06k
SQL
stringlengths
2
4.44k
source
stringclasses
28 values
CREATE TABLE ship_speeds (id INT, vessel_name VARCHAR(50), type VARCHAR(50), region VARCHAR(50), length DECIMAL(5,2), speed DECIMAL(5,2));
What is the maximum and minimum speed of cargo ships in the Indian Ocean, grouped by their length?
SELECT type, MIN(speed) AS min_speed, MAX(speed) AS max_speed FROM ship_speeds WHERE region = 'Indian Ocean' AND type = 'Cargo Ship' GROUP BY type, FLOOR(length);
gretelai_synthetic_text_to_sql
CREATE TABLE Astronauts (ID INT, Astronaut_Name VARCHAR(255), Missions INT); INSERT INTO Astronauts (ID, Astronaut_Name, Missions) VALUES (1, 'Jane Smith', 3), (2, 'Bob Johnson', 1);
List all astronauts who have participated in space missions, along with the number of missions they've been on, ordered by the number of missions in descending order.
SELECT Astronaut_Name, Missions FROM Astronauts ORDER BY Missions DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE subscribers (subscriber_id INT, subscriber_name VARCHAR(50), plan_id INT, country VARCHAR(50)); INSERT INTO subscribers (subscriber_id, subscriber_name, plan_id, country) VALUES (1, 'Alice', 1, 'USA'), (2, 'Bob', 2, 'Canada'), (3, 'Charlie', 2, 'Mexico'), (4, 'Diana', 3, 'USA'), (5, 'Eve', 1, 'Canada'), (6, 'Frank', 3, 'Mexico'); CREATE TABLE plans (plan_id INT, plan_name VARCHAR(50), plan_type VARCHAR(50)); INSERT INTO plans (plan_id, plan_name, plan_type) VALUES (1, 'Mobile', 'Postpaid'), (2, 'Broadband', 'Fiber'), (3, 'Broadband', 'Cable');
What are the top 3 countries with the highest number of broadband subscribers?
SELECT country, COUNT(*) as num_subscribers FROM subscribers s INNER JOIN plans p ON s.plan_id = p.plan_id WHERE p.plan_type = 'Broadband' GROUP BY country ORDER BY num_subscribers DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE ConsumerPurchases (id INT, consumer_id INT, purchase_date DATE, item_type VARCHAR(20)); INSERT INTO ConsumerPurchases (id, consumer_id, purchase_date, item_type) VALUES (1, 1, '2021-06-15', 'Shirt'), (2, 1, '2021-07-22', 'Shoes'), (3, 2, '2021-05-09', 'Dress'), (4, 3, '2020-12-31', 'Jeans'), (5, 3, '2021-08-18', 'Shirt');
How many consumers in the United States have purchased second-hand clothing in the past year?
SELECT COUNT(*) FROM ConsumerPurchases WHERE item_type = 'Shirt' OR item_type = 'Shoes' AND YEAR(purchase_date) = YEAR(CURRENT_DATE) - 1 AND consumer_id IN (SELECT DISTINCT consumer_id FROM ConsumerPurchases WHERE location = 'USA');
gretelai_synthetic_text_to_sql
CREATE TABLE artists_events (id INT, artist_id INT, event_id INT); INSERT INTO artists_events (id, artist_id, event_id) VALUES (1, 1, 'Art of the Americas'), (2, 2, 'Art of the Americas'), (3, 3, 'Women in Art'); CREATE TABLE events (id INT, name VARCHAR(50), date DATE); INSERT INTO events (id, name, date) VALUES (1, 'Art of the Americas', '2022-06-01'), (2, 'Women in Art', '2022-07-01'), (3, 'Ancient Art', '2022-08-01');
Delete all artists from the 'Ancient Art' event.
DELETE FROM artists_events WHERE event_id = (SELECT id FROM events WHERE name = 'Ancient Art');
gretelai_synthetic_text_to_sql
CREATE SCHEMA if not exists arts_culture;CREATE TABLE if not exists arts_culture.donors (donor_id INT PRIMARY KEY, name VARCHAR(255), type VARCHAR(255), donation DECIMAL(10,2));INSERT INTO arts_culture.donors (donor_id, name, type, donation) VALUES (1, 'John Doe', 'Individual', 50.00), (2, 'Jane Smith', 'Individual', 100.00), (3, 'Google Inc.', 'Corporation', 5000.00);
What is the average donation amount by donor type, excluding the top and bottom 5%?
SELECT type, AVG(donation) as avg_donation FROM (SELECT donation, type, NTILE(100) OVER (ORDER BY donation) as percentile FROM arts_culture.donors) d WHERE percentile NOT IN (1, 2, 99, 100) GROUP BY type;
gretelai_synthetic_text_to_sql
CREATE TABLE mines (id INT, name TEXT, location TEXT, production_quantity FLOAT); INSERT INTO mines (id, name, location, production_quantity) VALUES (1, 'Mina Gerais', 'Brazil', 120); INSERT INTO mines (id, name, location, production_quantity) VALUES (2, 'Cerro Matoso', 'Colombia', 240); INSERT INTO mines (id, name, location, production_quantity) VALUES (3, 'Pitinga Mine', 'Brazil', 360);
Find the average production quantity (in metric tons) of Samarium from South American mines.
SELECT AVG(production_quantity) FROM mines WHERE location LIKE 'South%' AND element = 'Samarium';
gretelai_synthetic_text_to_sql
CREATE TABLE Policy (PolicyID INT, PolicyType VARCHAR(50)); INSERT INTO Policy VALUES (1, 'Auto'), (2, 'Home'), (3, 'Life'); CREATE TABLE Claims (ClaimID INT, PolicyID INT, ClaimDate DATE); INSERT INTO Claims VALUES (1, 1, '2021-01-01'), (2, 1, '2021-02-01'), (3, 2, '2021-03-01'), (4, 3, '2020-01-01'), (5, 1, '2021-04-01'), (6, 2, '2020-01-01');
Delete records of policies without a claim in the last 12 months for policy type 'Home'.
DELETE p FROM Policy p INNER JOIN Claims c ON p.PolicyID = c.PolicyID WHERE p.PolicyType = 'Home' AND c.ClaimDate < DATE_SUB(CURDATE(), INTERVAL 12 MONTH);
gretelai_synthetic_text_to_sql
CREATE TABLE investments (investment_id INT, investor_id INT, sector VARCHAR(20), investment_value DECIMAL(10,2)); INSERT INTO investments (investment_id, investor_id, sector, investment_value) VALUES (1, 1, 'technology', 5000.00), (2, 2, 'finance', 3000.00);
What is the maximum investment value in the finance sector?
SELECT MAX(investment_value) FROM investments WHERE sector = 'finance';
gretelai_synthetic_text_to_sql
CREATE TABLE Sales (SaleID INT, VendorID INT, Revenue INT, SaleDate DATE); INSERT INTO Sales VALUES (1, 1, 1000, '2020-01-01'), (2, 1, 1200, '2020-01-02'), (3, 2, 800, '2020-01-01');
What is the difference in revenue between consecutive sales for each vendor, partitioned by vendor location, ordered by sale date?
SELECT SaleID, VendorID, LAG(Revenue) OVER (PARTITION BY VendorID, Location ORDER BY SaleDate) AS PreviousRevenue, Revenue, Revenue - LAG(Revenue) OVER (PARTITION BY VendorID, Location ORDER BY SaleDate) AS RevenueDifference FROM Sales;
gretelai_synthetic_text_to_sql
CREATE TABLE salaries (id INT, employee_name VARCHAR(50), job_role VARCHAR(50), salary DECIMAL(5,2));INSERT INTO salaries (id, employee_name, job_role, salary) VALUES (1, 'John Doe', 'Data Scientist', 80000.00), (2, 'Jane Smith', 'Software Engineer', 90000.00), (3, 'Alice Johnson', 'Data Analyst', 70000.00);
What is the minimum and maximum salary for each job role in the company?
SELECT job_role, MIN(salary) as min_salary, MAX(salary) as max_salary FROM salaries GROUP BY job_role;
gretelai_synthetic_text_to_sql
CREATE TABLE Products (ProductID int, ProductName varchar(50), Category varchar(50), Rating float); INSERT INTO Products (ProductID, ProductName, Category, Rating) VALUES (1, 'Foundation A', 'Foundation', 3.5), (2, 'Foundation B', 'Foundation', 4.2), (3, 'Lipstick C', 'Lipstick', 4.7);
Update the rating of the 'Lipstick' product with ProductID 3 to 4.8.
UPDATE Products SET Rating = 4.8 WHERE ProductID = 3 AND Category = 'Lipstick';
gretelai_synthetic_text_to_sql
CREATE TABLE DiverseEmployees (id INT, name VARCHAR(100), department VARCHAR(50), country VARCHAR(50));
Insert new employees into the DiverseEmployees table.
INSERT INTO DiverseEmployees (id, name, department, country) VALUES (7, 'Hamza Ahmed', 'Finance', 'Pakistan'), (8, 'Xiuying Zhang', 'IT', 'China'), (9, 'Amina Diop', 'Marketing', 'Senegal'), (10, 'Santiago Rodriguez', 'HR', 'Brazil');
gretelai_synthetic_text_to_sql
CREATE TABLE marine_species (name TEXT, affected_by TEXT); INSERT INTO marine_species (name, affected_by) VALUES ('Coral', 'ocean_acidification'), ('Pacific Oyster', 'ocean_acidification'), ('Pteropods', 'ocean_acidification'), ('Coccolithophores', 'ocean_acidification'), ('Seagrasses', 'ocean_acidification');
List all marine species affected by ocean acidification in descending order by number of occurrences.
SELECT affected_by, name AS marine_species, COUNT(*) AS occurrences FROM marine_species GROUP BY affected_by ORDER BY occurrences DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE users (id INT, name VARCHAR(50), join_date DATE, total_likes INT, allow_notifications BOOLEAN); INSERT INTO users (id, name, join_date, total_likes, allow_notifications) VALUES (1, 'Alice', '2020-01-01', 100, true), (2, 'Bob', '2019-05-15', 150, false);
Update user notification settings
UPDATE users SET allow_notifications = CASE WHEN id = 1 THEN false ELSE true END WHERE id IN (1, 2);
gretelai_synthetic_text_to_sql
CREATE TABLE student_exams (id INT, student_name VARCHAR(50), ethnicity VARCHAR(50), passed_exam BOOLEAN); INSERT INTO student_exams (id, student_name, ethnicity, passed_exam) VALUES (1, 'John Doe', 'Asian', true), (2, 'Jane Doe', 'Hispanic', false);
What is the percentage of students passing exams by ethnicity?
SELECT ethnicity, AVG(CAST(passed_exam AS INT)) * 100 AS percentage FROM student_exams GROUP BY ethnicity;
gretelai_synthetic_text_to_sql
CREATE TABLE timber_production (id INT, volume REAL, year INT, country TEXT);
What is the total volume of timber produced in the last 10 years in Brazil?
SELECT SUM(volume) FROM timber_production WHERE country = 'Brazil' AND year BETWEEN 2012 AND 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE Product (product_id INT PRIMARY KEY, product_name VARCHAR(50), is_circular_supply_chain BOOLEAN);
Find the number of products that are part of a circular supply chain in the 'Product' table
SELECT COUNT(*) FROM Product WHERE is_circular_supply_chain = TRUE;
gretelai_synthetic_text_to_sql
CREATE TABLE water_usage (id INT, crop VARCHAR(255), year INT, water_usage DECIMAL(5,2)); INSERT INTO water_usage (id, crop, year, water_usage) VALUES (1, 'Corn', 2020, 10.5), (2, 'Soybean', 2020, 8.3), (3, 'Rice', 2020, 12.0);
What is the average water usage of rice in the 'water_usage' table?
SELECT crop, AVG(water_usage) as AvgWaterUsage FROM water_usage WHERE crop = 'Rice' GROUP BY crop;
gretelai_synthetic_text_to_sql
CREATE TABLE CommunityHealthWorker (WorkerID INT, Age INT, City VARCHAR(50)); INSERT INTO CommunityHealthWorker (WorkerID, Age, City) VALUES (1, 45, 'New York'), (2, 35, 'Los Angeles'), (3, 50, 'Chicago'), (4, 40, 'Houston'), (5, 55, 'Philadelphia');
What is the average age of community health workers by city?
SELECT City, AVG(Age) as AvgAge FROM CommunityHealthWorker GROUP BY City;
gretelai_synthetic_text_to_sql
CREATE TABLE exploration (exp_id INT, exp_country TEXT, cost INT); INSERT INTO exploration (exp_id, exp_country, cost) VALUES (1, 'Country A', 10000), (2, 'Country B', 15000), (3, 'Country C', 12000);
What are the maximum and minimum exploration costs for each country in South America?
SELECT exp_country, MAX(cost) AS max_cost, MIN(cost) AS min_cost FROM exploration GROUP BY exp_country;
gretelai_synthetic_text_to_sql
CREATE TABLE Farmers (id INT, name VARCHAR, location VARCHAR, years_of_experience INT); INSERT INTO Farmers (id, name, location, years_of_experience) VALUES (1, 'Grace Kim', 'Seoul', 12), (2, 'Benjamin Smith', 'New York', 9), (3, 'Fatima Ahmed', 'Dubai', 18); CREATE TABLE Animals (id INT, farmer_id INT, animal_name VARCHAR, weight INT); INSERT INTO Animals (id, farmer_id, animal_name, weight) VALUES (1, 1, 'Cattle', 700), (2, 1, 'Goat', 30), (3, 2, 'Horse', 500), (4, 3, 'Camel', 800), (5, 3, 'Sheep', 40);
What is the average animal weight for each farmer in the agriculture database?
SELECT f.name, AVG(a.weight) as average_animal_weight FROM Farmers f JOIN Animals a ON f.id = a.farmer_id GROUP BY f.name;
gretelai_synthetic_text_to_sql
CREATE TABLE authors (id INT, name VARCHAR(100), gender VARCHAR(10)); INSERT INTO authors (id, name, gender) VALUES (1, 'Author Name', 'Female'); CREATE TABLE publications (id INT, title VARCHAR(100), author VARCHAR(100), journal VARCHAR(100), year INT); INSERT INTO publications (id, title, author, journal, year) VALUES (1, 'Publication Title', 'Author Name', 'Journal Name', 2021);
Identify the journal that has published the most articles by female authors in the past 5 years.
SELECT journal, COUNT(*) as num_publications FROM publications p JOIN authors a ON p.author = a.name WHERE a.gender = 'Female' AND year BETWEEN YEAR(CURRENT_DATE) - 5 AND YEAR(CURRENT_DATE) GROUP BY journal ORDER BY num_publications DESC LIMIT 1;
gretelai_synthetic_text_to_sql
CREATE TABLE Artworks (id INT, art_category VARCHAR(255), artist_name VARCHAR(255), year INT, art_medium VARCHAR(255), price DECIMAL(10,2));
What is the total number of artworks in each art category and year combination in the 'Artworks' table?
SELECT art_category, year, COUNT(*) as total FROM Artworks GROUP BY art_category, year;
gretelai_synthetic_text_to_sql
CREATE TABLE football_games(id INT, team VARCHAR(50), location VARCHAR(50), price DECIMAL(5,2)); INSERT INTO football_games(id, team, location, price) VALUES (1, 'Atlanta Falcons', 'Georgia Dome', 95.00), (2, 'Carolina Panthers', 'Bank of America Stadium', 80.50), (3, 'New Orleans Saints', 'Mercedes-Benz Superdome', 110.00);
What is the average ticket price for football games in the Southeast region?
SELECT AVG(price) FROM football_games WHERE location IN ('Georgia Dome', 'Bank of America Stadium', 'Mercedes-Benz Superdome');
gretelai_synthetic_text_to_sql
CREATE TABLE Events (id INT, event_name VARCHAR(100), event_type VARCHAR(50), location VARCHAR(100), start_time TIMESTAMP, end_time TIMESTAMP); CREATE TABLE Attendees (id INT, attendee_age INT, event_id INT);
What is the total attendance by age group, for dance events in New York, in 2022?
SELECT attendee_age_group, SUM(attendance) as total_attendance FROM (SELECT attendee_age AS attendee_age_group, COUNT(*) AS attendance FROM Attendees JOIN Events ON Attendees.event_id = Events.id WHERE Events.event_type = 'dance' AND Events.location LIKE '%New York%' AND DATE_TRUNC('year', Events.start_time) = DATE_TRUNC('year', '2022-01-01') GROUP BY attendee_age) AS subquery GROUP BY attendee_age_group;
gretelai_synthetic_text_to_sql
CREATE TABLE manufacturers (id INT PRIMARY KEY, name VARCHAR(255), location VARCHAR(255), ethical_rating FLOAT); INSERT INTO manufacturers (id, name, location, ethical_rating) VALUES (1, 'Ethical Co.', 'France', 4.6), (2, 'Green Producers', 'France', 4.4); CREATE TABLE materials (id INT PRIMARY KEY, name VARCHAR(255), origin VARCHAR(255), sustainability_rating FLOAT); INSERT INTO materials (id, name, origin, sustainability_rating) VALUES (1, 'Sustainable Wood', 'France', 4.8), (2, 'Recycled Metal', 'France', 4.7);
What is the average ethical rating of manufacturers in France that use sustainable materials?
SELECT AVG(m.ethical_rating) FROM manufacturers m INNER JOIN materials s ON m.location = s.origin WHERE s.sustainability_rating > 4.6;
gretelai_synthetic_text_to_sql
CREATE TABLE Pinterest(id INT, user_id INT, post_time TIMESTAMP, content TEXT, repost BOOLEAN, bot BOOLEAN); CREATE TABLE Tumblr(id INT, user_id INT, post_time TIMESTAMP, content TEXT, repost BOOLEAN, bot BOOLEAN);
Find the total number of posts and users from 'Pinterest' and 'Tumblr' platforms, excluding reposts and bots.
SELECT COUNT(DISTINCT user_id) AS total_users, COUNT(*) AS total_posts FROM Pinterest WHERE repost = FALSE AND bot = FALSE UNION ALL SELECT COUNT(DISTINCT user_id) AS total_users, COUNT(*) AS total_posts FROM Tumblr WHERE repost = FALSE AND bot = FALSE;
gretelai_synthetic_text_to_sql
CREATE TABLE indigenous_farms (id INT, region VARCHAR(10), crop VARCHAR(20));
How many crops are grown in 'indigenous_farms' table for region '05'?
SELECT COUNT(DISTINCT crop) FROM indigenous_farms WHERE region = '05';
gretelai_synthetic_text_to_sql
CREATE TABLE Sales (SalesID INT, SalesRep VARCHAR(50), SaleDate DATE, Revenue DECIMAL(10,2)); INSERT INTO Sales VALUES (1, 'Salesperson A', '2022-01-01', 1000.00), (2, 'Salesperson B', '2022-01-05', 1500.00), (3, 'Salesperson A', '2022-02-03', 2000.00);
What is the monthly sales revenue for each sales representative?
SELECT SalesRep, DATE_TRUNC('month', SaleDate) as Month, SUM(Revenue) as MonthlyRevenue FROM Sales GROUP BY SalesRep, Month ORDER BY SalesRep, Month;
gretelai_synthetic_text_to_sql
CREATE TABLE Volunteers (id INT, name TEXT, country TEXT); INSERT INTO Volunteers (id, name, country) VALUES (1, 'John Doe', 'USA'), (2, 'Jane Smith', 'Canada'); CREATE TABLE Donors (id INT, name TEXT, country TEXT); INSERT INTO Donors (id, name, country) VALUES (3, 'Mike Johnson', 'USA'), (4, 'Sara Williams', 'Mexico');
Identify the top 3 countries with the most volunteers and donors.
(SELECT country, COUNT(*) as total FROM Volunteers GROUP BY country ORDER BY total DESC LIMIT 3) UNION ALL (SELECT country, COUNT(*) as total FROM Donors GROUP BY country ORDER BY total DESC LIMIT 3);
gretelai_synthetic_text_to_sql
CREATE TABLE customers (customer_id INT, name VARCHAR(50)); CREATE TABLE transactions (transaction_id INT, customer_id INT, transaction_amount DECIMAL(10,2)); INSERT INTO customers (customer_id, name) VALUES (1, 'Alice Davis'); INSERT INTO customers (customer_id, name) VALUES (2, 'Bob Thompson'); INSERT INTO transactions (transaction_id, customer_id, transaction_amount) VALUES (1, 1, 150.00); INSERT INTO transactions (transaction_id, customer_id, transaction_amount) VALUES (2, 2, 250.00);
List the top 5 customers with the highest total transaction amount in the past month.
SELECT customer_id, name, SUM(transaction_amount) as total_transaction_amount FROM transactions t INNER JOIN customers c ON t.customer_id = c.customer_id WHERE transaction_date BETWEEN DATEADD(month, -1, GETDATE()) AND GETDATE() GROUP BY customer_id, name ORDER BY total_transaction_amount DESC LIMIT 5;
gretelai_synthetic_text_to_sql
CREATE TABLE causes (cause_id INT, name TEXT, description TEXT);CREATE TABLE volunteers (volunteer_id INT, cause_id INT, total_hours DECIMAL);
List the top 3 most common causes for volunteering?
SELECT causes.name, COUNT(volunteers.cause_id) as total_volunteers FROM causes JOIN volunteers ON causes.cause_id = volunteers.cause_id GROUP BY causes.name ORDER BY total_volunteers DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE startups (id INT, name TEXT, industry TEXT, founding_date DATE, founders TEXT, funding FLOAT); INSERT INTO startups (id, name, industry, founding_date, founders, funding) VALUES (1, 'FintechForAll', 'Fintech', '2020-01-01', 'Individuals with disabilities', 3000000.0);
What is the total funding received by startups founded by individuals with disabilities in the fintech sector?
SELECT SUM(funding) FROM startups WHERE founders = 'Individuals with disabilities' AND industry = 'Fintech';
gretelai_synthetic_text_to_sql
CREATE TABLE menus (menu_id INT, menu_name VARCHAR(50), category VARCHAR(50), price DECIMAL(5,2)); INSERT INTO menus (menu_id, menu_name, category, price) VALUES (1, 'Quinoa Salad', 'Vegetarian', 9.99), (2, 'Margherita Pizza', 'Non-Vegetarian', 12.99), (3, 'Chickpea Curry', 'Vegetarian', 10.99), (4, 'Tofu Stir Fry', 'Vegan', 11.99), (5, 'Steak', 'Non-Vegetarian', 25.99);
How many non-vegetarian items are there on the menu?
SELECT COUNT(*) FROM menus WHERE category = 'Non-Vegetarian';
gretelai_synthetic_text_to_sql
CREATE TABLE Peacekeeping_Operations (Operation_ID INT, Country_Name VARCHAR(50), Start_Date DATE, End_Date DATE); INSERT INTO Peacekeeping_Operations (Operation_ID, Country_Name, Start_Date, End_Date) VALUES (1, 'Bangladesh', '2005-01-01', '2007-12-31');
What is the average duration of peacekeeping operations for each country?
SELECT Country_Name, AVG(DATEDIFF(End_Date, Start_Date)) as Average_Duration FROM Peacekeeping_Operations GROUP BY Country_Name;
gretelai_synthetic_text_to_sql
CREATE TABLE ClimateDisastersData (country VARCHAR(50), year INT, disaster_type VARCHAR(50), people_affected INT);
What is the number of climate-related disasters in Southeast Asia between 2000 and 2010, and the total number of people affected by them?
SELECT COUNT(*), SUM(people_affected) FROM ClimateDisastersData WHERE country LIKE 'Southeast Asia%' AND year BETWEEN 2000 AND 2010 AND disaster_type LIKE 'climate%';
gretelai_synthetic_text_to_sql
CREATE TABLE events (id INT, name VARCHAR(255), date DATE, attendees INT); INSERT INTO events (id, name, date, attendees) VALUES (1, 'Festival', '2022-06-01', 5000), (2, 'Conference', '2022-07-01', 2000), (3, 'Exhibition', '2022-08-01', 3000);
What is the maximum number of attendees for any cultural event?
SELECT MAX(attendees) FROM events;
gretelai_synthetic_text_to_sql
CREATE TABLE electric_buses (bus_id INT, city VARCHAR(20)); INSERT INTO electric_buses (bus_id, city) VALUES (1, 'Tokyo'), (2, 'Tokyo'), (3, 'Seoul'), (4, 'Seoul');
How many electric buses are there in Tokyo and Seoul combined?
SELECT COUNT(*) FROM electric_buses WHERE city IN ('Tokyo', 'Seoul');
gretelai_synthetic_text_to_sql
CREATE TABLE CaseBilling (CaseID INT, AttorneyID INT, Billing FLOAT); INSERT INTO CaseBilling (CaseID, AttorneyID, Billing) VALUES (1, 1, 1500.00), (2, 2, 3000.00), (3, 3, 5000.00), (4, 1, 2000.00), (5, 2, 1000.00), (6, 3, 4000.00);
Show the average billing amount for each attorney's cases, ordered alphabetically by attorney name.
SELECT a.Name AS AttorneyName, AVG(cb.Billing) AS AvgBilling FROM Attorneys a JOIN CaseBilling cb ON a.AttorneyID = cb.AttorneyID GROUP BY a.Name ORDER BY a.Name;
gretelai_synthetic_text_to_sql
CREATE TABLE quarterly_visitors (id INT, country TEXT, quarter INT, year INT, num_visitors INT); INSERT INTO quarterly_visitors (id, country, quarter, year, num_visitors) VALUES (1, 'India', 1, 2023, 1000000), (2, 'India', 2, 2023, 1100000), (3, 'China', 1, 2023, 1200000);
What is the change in the number of tourists visiting India between Q1 and Q2 in 2023?
SELECT country, (SUM(CASE WHEN quarter = 2 THEN num_visitors ELSE 0 END) - SUM(CASE WHEN quarter = 1 THEN num_visitors ELSE 0 END)) AS change_in_visitors FROM quarterly_visitors WHERE country = 'India' AND year = 2023 GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE Policy_Budget (Policy_ID INT PRIMARY KEY, Policy_Area VARCHAR(30), Budget INT); INSERT INTO Policy_Budget (Policy_ID, Policy_Area, Budget) VALUES (1, 'Transportation', 8000000), (2, 'Education', 7000000), (3, 'Environment', 5000000), (4, 'Housing', 9000000);
What is the total budget allocated for policies related to the environment?
SELECT SUM(Budget) FROM Policy_Budget WHERE Policy_Area = 'Environment';
gretelai_synthetic_text_to_sql
CREATE TABLE employee_ethnicity (id INT, employee_id INT, ethnicity VARCHAR(50)); INSERT INTO employee_ethnicity (id, employee_id, ethnicity) VALUES (1, 1, 'Hispanic'), (2, 2, 'Asian'), (3, 3, 'African American');
Display the number of employees, by ethnicity, in the 'employee_ethnicity' table.
SELECT ethnicity, COUNT(*) as num_employees FROM employee_ethnicity GROUP BY ethnicity;
gretelai_synthetic_text_to_sql
CREATE TABLE fabric_sustainability (id INT PRIMARY KEY, fabric_type VARCHAR(255), country_origin VARCHAR(255), water_usage FLOAT, co2_emissions FLOAT); INSERT INTO fabric_sustainability (id, fabric_type, country_origin, water_usage, co2_emissions) VALUES (1, 'Cotton', 'Egypt', 1500, 4.5);
What is the total water usage for each fabric type produced in Egypt?
SELECT fabric_sustainability.fabric_type, SUM(fabric_sustainability.water_usage) as total_water_usage FROM fabric_sustainability WHERE fabric_sustainability.country_origin = 'Egypt' GROUP BY fabric_sustainability.fabric_type;
gretelai_synthetic_text_to_sql
CREATE TABLE Catfish_Farms (Farm_ID INT, Farm_Name TEXT, Region TEXT, Water_Temperature FLOAT); INSERT INTO Catfish_Farms (Farm_ID, Farm_Name, Region, Water_Temperature) VALUES (1, 'Farm M', 'African', 30.0); INSERT INTO Catfish_Farms (Farm_ID, Farm_Name, Region, Water_Temperature) VALUES (2, 'Farm N', 'African', 31.0); INSERT INTO Catfish_Farms (Farm_ID, Farm_Name, Region, Water_Temperature) VALUES (3, 'Farm O', 'European', 29.0);
What is the maximum water temperature in Catfish Farms in the African region?
SELECT MAX(Water_Temperature) FROM Catfish_Farms WHERE Region = 'African';
gretelai_synthetic_text_to_sql
CREATE TABLE Suppliers (id INT, supplier_name VARCHAR(255), country VARCHAR(255)); INSERT INTO Suppliers (id, supplier_name, country) VALUES (1, 'Supplier A', 'USA'), (2, 'Supplier B', 'South Africa'), (3, 'Supplier C', 'China'); CREATE TABLE Purchase_Orders (id INT, supplier_id INT, purchase_value DECIMAL(5,2)); INSERT INTO Purchase_Orders (id, supplier_id, purchase_value) VALUES (1, 1, 1000.00), (2, 2, 1500.00), (3, 3, 1200.00);
What is the total revenue generated from textile sourcing in Africa?
SELECT SUM(Purchase_Orders.purchase_value) FROM Purchase_Orders INNER JOIN Suppliers ON Purchase_Orders.supplier_id = Suppliers.id WHERE Suppliers.country = 'South Africa';
gretelai_synthetic_text_to_sql
CREATE TABLE country (id INT PRIMARY KEY, name VARCHAR(50));CREATE TABLE carbon_price (id INT PRIMARY KEY, name VARCHAR(50), country_id INT, FOREIGN KEY (country_id) REFERENCES country(id), price DECIMAL(10,2));CREATE TABLE carbon_emission (id INT PRIMARY KEY, date DATE, source_id INT, FOREIGN KEY (source_id) REFERENCES renewable_source(id), carbon_emitted DECIMAL(10,2));CREATE TABLE power_usage (id INT PRIMARY KEY, date DATE, usage_amount INT, country_id INT, FOREIGN KEY (country_id) REFERENCES country(id));
What is the average carbon price and total carbon emitted in Spain for 2020?
SELECT c.name AS country_name, cp.name AS carbon_price_name, AVG(cp.price) AS average_carbon_price, SUM(ce.carbon_emitted) AS total_carbon_emitted FROM carbon_emission ce JOIN carbon_price cp ON ce.country_id = cp.country_id JOIN power_usage pu ON ce.date = pu.date AND ce.country_id = pu.country_id JOIN country c ON pu.country_id = c.id WHERE c.name = 'Spain' AND pu.date BETWEEN '2020-01-01' AND '2020-12-31' GROUP BY c.name, cp.name;
gretelai_synthetic_text_to_sql
CREATE TABLE TherapyApproaches (TherapyID INT, TherapyName VARCHAR(50)); CREATE TABLE Patients (PatientID INT, Age INT, Gender VARCHAR(10), TherapyStartYear INT); CREATE TABLE TherapySessions (SessionID INT, PatientID INT, TherapyID INT);
How many patients were treated with a specific therapy approach in a specific year?
SELECT TherapyApproaches.TherapyName, Patients.TherapyStartYear, COUNT(TherapySessions.SessionID) FROM TherapyApproaches INNER JOIN TherapySessions ON TherapyApproaches.TherapyID = TherapySessions.TherapyID INNER JOIN Patients ON TherapySessions.PatientID = Patients.PatientID GROUP BY TherapyApproaches.TherapyName, Patients.TherapyStartYear;
gretelai_synthetic_text_to_sql
CREATE TABLE farms (id INT, name VARCHAR(50), country VARCHAR(50), certification VARCHAR(50)); INSERT INTO farms
Remove fish farms with poor health scores
DELETE FROM farms WHERE certification NOT IN ('ASC', 'BAP', 'MSC');
gretelai_synthetic_text_to_sql
CREATE TABLE Property (id INT PRIMARY KEY, address VARCHAR(255), city VARCHAR(255), state VARCHAR(255), zip INT, co_owners INT, sustainable_features VARCHAR(255), price INT);
What is the price of properties without sustainable features?
SELECT Property.price FROM Property WHERE sustainable_features = '';
gretelai_synthetic_text_to_sql
CREATE TABLE veteran_employment (state TEXT, num_veterans INT, total_employees INT); INSERT INTO veteran_employment VALUES ('California', 10000, 50000), ('Texas', 12000, 60000);
What is the percentage of veterans employed in each state?
SELECT state, (num_veterans::DECIMAL(10,2) / total_employees::DECIMAL(10,2)) * 100 AS veteran_percentage FROM veteran_employment;
gretelai_synthetic_text_to_sql
CREATE TABLE Players (PlayerID INT, Name VARCHAR(100), Age INT, Country VARCHAR(50)); INSERT INTO Players VALUES (1, 'Jessica Brown', 27, 'Australia'); INSERT INTO Players VALUES (2, 'Daniel Kim', 31, 'Japan'); CREATE TABLE Countries (Country VARCHAR(50), Continent VARCHAR(50)); INSERT INTO Countries VALUES ('Australia', 'Oceania'); INSERT INTO Countries VALUES ('Japan', 'Asia'); CREATE TABLE GameDesign (GameID INT, GameName VARCHAR(100), Genre VARCHAR(50)); INSERT INTO GameDesign VALUES (1, 'GameX', 'RPG'); INSERT INTO GameDesign VALUES (2, 'GameY', 'Strategy');
Calculate the average age of players who have played RPG games with more than 50 hours of playtime, grouped by continent.
SELECT C.Continent, AVG(P.Age) as AvgAge FROM Players P JOIN Countries C ON P.Country = C.Country JOIN (SELECT PlayerID, Genre FROM Players P JOIN GameDesign GD ON P.PlayerID = GD.GameID WHERE GD.Genre = 'RPG' AND P.TotalHoursPlayed > 50) AS GameRPG ON P.PlayerID = GameRPG.PlayerID GROUP BY C.Continent;
gretelai_synthetic_text_to_sql
CREATE TABLE CustomersRegion (CustomerID INT, CustomerName VARCHAR(255), Region VARCHAR(50), TotalFreightCharges DECIMAL(10, 2)); INSERT INTO CustomersRegion (CustomerID, CustomerName, Region, TotalFreightCharges) VALUES (1, 'ABC Corp', 'East', 5000.00), (2, 'XYZ Inc', 'West', 7000.00), (3, 'LMN Ltd', 'East', 6000.00), (4, 'DEF Co', 'West', 8000.00), (5, 'GHI Pvt', 'East', 9000.00);
What is the total freight charge for each customer in the 'East' region?
SELECT CustomerName, TotalFreightCharges FROM CustomersRegion WHERE Region = 'East';
gretelai_synthetic_text_to_sql
CREATE TABLE Art (ArtID INT, Type VARCHAR(255), Region VARCHAR(255), Continent VARCHAR(255), Quantity INT); INSERT INTO Art (ArtID, Type, Region, Continent, Quantity) VALUES (1, 'Painting', 'Asia', 'Asia', 25), (2, 'Sculpture', 'Africa', 'Africa', 18), (3, 'Textile', 'South America', 'South America', 30), (4, 'Pottery', 'Europe', 'Europe', 20), (5, 'Jewelry', 'North America', 'North America', 12);
What is the total number of traditional art pieces by type and continent?
SELECT Type, Continent, SUM(Quantity) as Total_Quantity FROM Art GROUP BY Type, Continent;
gretelai_synthetic_text_to_sql
CREATE TABLE cleaners (id INT, name VARCHAR(50), salary DECIMAL(10, 2), is_union_member BOOLEAN, department VARCHAR(50)); INSERT INTO cleaners (id, name, salary, is_union_member, department) VALUES (1, 'Olivia', 90000.00, true, 'cleaning'), (2, 'Owen', 95000.00, true, 'cleaning'), (3, 'Olga', 80000.00, true, 'management');
What is the average salary for workers in the 'service_database' database who are members of a union and work in the 'cleaning' department?
SELECT AVG(salary) FROM cleaners WHERE is_union_member = true AND department = 'cleaning';
gretelai_synthetic_text_to_sql
CREATE TABLE students (student_id INT, school_id INT, mental_health_score INT); CREATE TABLE enrollments (student_id INT, course_type VARCHAR, enrollment_date DATE);
What is the minimum mental health score per school for students who have enrolled in lifelong learning courses?
SELECT s.school_id, MIN(s.mental_health_score) as min_score FROM students s INNER JOIN enrollments e ON s.student_id = e.student_id WHERE e.course_type = 'lifelong learning' GROUP BY s.school_id;
gretelai_synthetic_text_to_sql
CREATE TABLE MentalHealthParity (ID INT PRIMARY KEY, State VARCHAR(2), ParityStatus VARCHAR(10));
Insert records for all states into MentalHealthParity
INSERT INTO MentalHealthParity (ID, State, ParityStatus) VALUES (1, 'AK', 'Yes'), (2, 'AL', 'No'), (3, 'AR', 'No'), (4, 'AZ', 'Yes'), (5, 'CA', 'Yes'), (6, 'CO', 'Yes'), (7, 'CT', 'Yes'), (8, 'DC', 'Yes'), (9, 'DE', 'Yes'), (10, 'FL', 'No'), (11, 'GA', 'No'), (12, 'HI', 'Yes');
gretelai_synthetic_text_to_sql
CREATE TABLE salmon_farms (id INT, name TEXT, country TEXT); CREATE TABLE temperature_readings (id INT, farm_id INT, temperature FLOAT); INSERT INTO salmon_farms (id, name, country) VALUES (1, 'Farm X', 'Norway'), (2, 'Farm Y', 'Norway'), (3, 'Farm Z', 'Canada'); INSERT INTO temperature_readings (id, farm_id, temperature) VALUES (1, 1, 12.5), (2, 1, 13.0), (3, 2, 11.0), (4, 2, 11.5), (5, 3, 7.0);
What is the average water temperature in salmon farms in Norway?
SELECT AVG(temperature) FROM temperature_readings TR JOIN salmon_farms SF ON TR.farm_id = SF.id WHERE SF.country = 'Norway';
gretelai_synthetic_text_to_sql
CREATE TABLE products (product_id INT, product VARCHAR(255), brand_id INT, price DECIMAL(5,2), organic BOOLEAN, rating INT); CREATE TABLE brands (brand_id INT, brand VARCHAR(255)); INSERT INTO products (product_id, product, brand_id, price, organic, rating) VALUES (1, 'Organic Shampoo', 1, 12.99, TRUE, 4), (2, 'Non-organic Shampoo', 1, 9.99, FALSE, 3), (3, 'Organic Conditioner', 1, 14.99, TRUE, 5), (4, 'Non-organic Conditioner', 1, 10.99, FALSE, 4), (5, 'Organic Face Cream', 2, 15.99, TRUE, 5), (6, 'Non-organic Face Cream', 2, 13.99, FALSE, 4); INSERT INTO brands (brand_id, brand) VALUES (1, 'Brand A'), (2, 'Brand B');
What is the average rating of organic products, categorized by brand?
SELECT b.brand, AVG(p.rating) as avg_organic_rating FROM products p JOIN brands b ON p.brand_id = b.brand_id WHERE p.organic = TRUE GROUP BY b.brand;
gretelai_synthetic_text_to_sql
CREATE TABLE graduate_students (id INT, name VARCHAR(50), community VARCHAR(50), grant_amount DECIMAL(10,2)); INSERT INTO graduate_students (id, name, community, grant_amount) VALUES (1, 'John Doe', 'Underrepresented', 25000.00), (2, 'Jane Smith', 'Not Underrepresented', 30000.00);
What is the average grant amount awarded to graduate students from underrepresented communities?
SELECT AVG(grant_amount) FROM graduate_students WHERE community = 'Underrepresented';
gretelai_synthetic_text_to_sql
CREATE TABLE Spacecraft (Id INT, Model VARCHAR(255), ManufacturingCost DECIMAL(10,2)); INSERT INTO Spacecraft (Id, Model, ManufacturingCost) VALUES (1, 'Voyager', 100000.00), (2, 'Cassini', 300000.00), (3, 'Galileo', 250000.00);
What is the total manufacturing cost for each spacecraft model?
SELECT Model, SUM(ManufacturingCost) as TotalManufacturingCost FROM Spacecraft GROUP BY Model;
gretelai_synthetic_text_to_sql
CREATE TABLE properties (id INT, size FLOAT, PRIMARY KEY (id)); INSERT INTO properties (id, size) VALUES (1, 1200.0), (2, 800.0), (3, 1500.0), (4, 1000.0);
What is the total size of properties in the 'properties' table?
SELECT SUM(size) FROM properties;
gretelai_synthetic_text_to_sql
CREATE TABLE exhibitions (exhibition_id INT, name VARCHAR(255)); INSERT INTO exhibitions (exhibition_id, name) VALUES (1, 'Art of the Renaissance'), (2, 'Modern Art'), (3, 'Impressionist Art'); CREATE TABLE visitors (visitor_id INT, exhibition_id INT, age INT); INSERT INTO visitors (visitor_id, exhibition_id, age) VALUES (1, 1, 25), (2, 1, 42), (3, 2, 28), (4, 3, 29), (5, 3, 22), (6, 3, 35);
What was the average age of visitors who attended the Impressionist Art exhibition?
SELECT AVG(age) as avg_age FROM visitors WHERE exhibition_id = 3;
gretelai_synthetic_text_to_sql
CREATE TABLE company (id INT, name VARCHAR(50), industry VARCHAR(50), founder_gender VARCHAR(10)); INSERT INTO company (id, name, industry, founder_gender) VALUES (1, 'Acme Inc', 'Tech', 'Female'), (2, 'Beta Corp', 'Finance', 'Male'), (3, 'Gamma Startup', 'Tech', 'Female'), (4, 'Delta Company', 'Finance', 'Non-binary');
Which industries have the most diverse founding teams in terms of gender?
SELECT industry, COUNT(DISTINCT founder_gender) AS diversity_score FROM company GROUP BY industry ORDER BY diversity_score DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE phytoplankton_depth (id INT, location VARCHAR(50), depth FLOAT, phytoplankton_present BOOLEAN); INSERT INTO phytoplankton_depth (id, location, depth, phytoplankton_present) VALUES (1, 'Southern Ocean', 50.0, TRUE); INSERT INTO phytoplankton_depth (id, location, depth, phytoplankton_present) VALUES (2, 'Southern Ocean', 75.0, TRUE);
What is the minimum depth in the Southern Ocean where phytoplankton are present?
SELECT MIN(depth) FROM phytoplankton_depth WHERE location = 'Southern Ocean' AND phytoplankton_present = TRUE;
gretelai_synthetic_text_to_sql
CREATE TABLE disinformation_language (id INT, detected_at TIMESTAMP, language VARCHAR, confirmed BOOLEAN); INSERT INTO disinformation_language (id, detected_at, language, confirmed) VALUES (1, '2021-01-01 12:00:00', 'English', true); INSERT INTO disinformation_language (id, detected_at, language, confirmed) VALUES (2, '2021-01-02 13:00:00', 'Spanish', false);
How many instances of disinformation were detected in a specific language during a specific time period?
SELECT COUNT(*) FROM disinformation_language WHERE detected_at BETWEEN '2021-01-01' AND '2021-01-07' AND language = 'Spanish' AND confirmed = true;
gretelai_synthetic_text_to_sql
CREATE TABLE online_travel_agencies(id INT, name TEXT, country TEXT, bookings INT);
Which OTA has the lowest number of bookings in 'Asia'?
SELECT name, MIN(bookings) FROM online_travel_agencies WHERE country = 'Asia' GROUP BY name;
gretelai_synthetic_text_to_sql
CREATE TABLE Budget (BudgetID int, BudgetYear int, BudgetAmount decimal(10,2)); INSERT INTO Budget (BudgetID, BudgetYear, BudgetAmount) VALUES (1, 2022, 50000), (2, 2023, 60000);
What was the total budget for 2022?
SELECT SUM(BudgetAmount) FROM Budget WHERE BudgetYear = 2022;
gretelai_synthetic_text_to_sql
CREATE TABLE community_education (education_id INT, education_name VARCHAR(50), start_date DATE, end_date DATE); INSERT INTO community_education (education_id, education_name, start_date, end_date) VALUES (1, 'Animal Tracking', '2021-01-01', '2021-12-31'), (2, 'Habitat Conservation', '2021-04-01', '2021-12-31'), (3, 'Wildlife Photography', '2021-07-01', '2021-10-31');
how many education programs are there in total in the 'community_education' table?
SELECT COUNT(*) FROM community_education;
gretelai_synthetic_text_to_sql
CREATE TABLE EsportsEvents (EventID INT PRIMARY KEY, EventName VARCHAR(50), GameID INT, PrizePool DECIMAL(10,2), GameGenre VARCHAR(20)); INSERT INTO EsportsEvents (EventID, EventName, GameID, PrizePool, GameGenre) VALUES (6, 'Fortnite World Cup', 5, 30000000.00, 'Battle Royale'); INSERT INTO EsportsEvents (EventID, EventName, GameID, PrizePool, GameGenre) VALUES (7, 'PUBG Global Championship', 6, 2000000.00, 'Battle Royale');
What is the average prize pool for esports events related to the 'Battle Royale' genre?
SELECT AVG(PrizePool) FROM EsportsEvents WHERE GameGenre = 'Battle Royale';
gretelai_synthetic_text_to_sql
CREATE TABLE security_policies (id INT, name VARCHAR(255), description TEXT, last_updated TIMESTAMP);
What are the names and descriptions of all the security policies that have been updated in the last month?
SELECT name, description FROM security_policies WHERE last_updated >= NOW() - INTERVAL 1 MONTH;
gretelai_synthetic_text_to_sql
CREATE TABLE oil_reservoirs (reservoir_id INT, reservoir_name VARCHAR(100), location VARCHAR(100), oil_capacity FLOAT); INSERT INTO oil_reservoirs (reservoir_id, reservoir_name, location, oil_capacity) VALUES (1, 'Girassol', 'Angola', 800), (2, 'Jazireh-e-Jafar', 'Iran', 1500), (3, 'Thunder Horse', 'Gulf of Mexico', 1200), (4, 'Kashagan', 'Caspian Sea', 1100);
Show all reservoirs with capacity > 1000
SELECT * FROM oil_reservoirs WHERE oil_capacity > 1000;
gretelai_synthetic_text_to_sql
CREATE TABLE volunteers (id INT, name TEXT, organization TEXT, join_date DATE); INSERT INTO volunteers (id, name, organization, join_date) VALUES (1, 'Volunteer 1', 'Organization A', '2021-01-01'), (2, 'Volunteer 2', 'Organization B', '2021-03-15');
List the number of volunteers who have joined each organization in the last 6 months.
SELECT organization, COUNT(*) AS num_volunteers FROM volunteers WHERE join_date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH) GROUP BY organization;
gretelai_synthetic_text_to_sql
CREATE TABLE SniperElite (PlayerID INT, Headshots INT, ShotsFired INT); INSERT INTO SniperElite (PlayerID, Headshots, ShotsFired) VALUES (1, 60, 200), (2, 55, 180), (3, 65, 220), (4, 62, 210), (5, 58, 190);
What is the maximum number of headshots achieved by players who have more than 50 headshots in the "SniperElite" table?
SELECT MAX(Headshots) FROM SniperElite WHERE Headshots > 50;
gretelai_synthetic_text_to_sql
CREATE TABLE companies (id INT, name TEXT, industry TEXT, circular_economy TEXT, waste_production_tonnes FLOAT, year INT); INSERT INTO companies (id, name, industry, circular_economy, waste_production_tonnes, year) VALUES (1, 'Circular Solutions', 'Manufacturing', 'Circular Economy', 500, 2021); INSERT INTO companies (id, name, industry, circular_economy, waste_production_tonnes, year) VALUES (2, 'Eco Manufacturing', 'Manufacturing', 'Circular Economy', 600, 2021); INSERT INTO companies (id, name, industry, circular_economy, waste_production_tonnes, year) VALUES (3, 'Green Tech', 'Technology', 'Circular Economy', 400, 2021);
What is the total amount of waste produced by companies in the circular economy in the past year?
SELECT SUM(waste_production_tonnes) as total_waste FROM companies WHERE circular_economy = 'Circular Economy' AND year = 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE users_extended (id INT, country VARCHAR(255)); CREATE TABLE posts_extended (id INT, user_id INT, content TEXT, country VARCHAR(255)); INSERT INTO users_extended (id, country) VALUES (1, 'USA'), (2, 'Canada'), (3, 'Mexico'); INSERT INTO posts_extended (id, user_id, content, country) VALUES (1, 1, 'Hello', 'USA'), (2, 1, 'World', 'USA'), (3, 2, 'AI', 'Canada');
How many users have posted content in each country?
SELECT users_extended.country, COUNT(DISTINCT posts_extended.user_id) FROM users_extended JOIN posts_extended ON users_extended.id = posts_extended.user_id GROUP BY users_extended.country;
gretelai_synthetic_text_to_sql
CREATE TABLE articles (id INT, title TEXT, content TEXT); CREATE TABLE videos (id INT, title TEXT, url TEXT); INSERT INTO articles (id, title, content) VALUES (1, 'Article 1', 'Content 1'); INSERT INTO articles (id, title, content) VALUES (2, 'Article 2', 'Content 2'); INSERT INTO videos (id, title, url) VALUES (1, 'Video 1', 'URL 1'); INSERT INTO videos (id, title, url) VALUES (2, 'Video 2', 'URL 2'); INSERT INTO articles (id, title, content) VALUES (1, 'Article 1', 'Content 1');
What is the total number of articles and videos in the media database, excluding any duplicate entries?
SELECT COUNT(DISTINCT a.id) + COUNT(DISTINCT v.id) FROM articles a JOIN videos v ON TRUE;
gretelai_synthetic_text_to_sql
CREATE TABLE investments (id INT, amount DECIMAL(10, 2), sector VARCHAR(255)); INSERT INTO investments (id, amount, sector) VALUES (1, 50000, 'Education'); CREATE TABLE esg_factors (id INT, investment_id INT, environmental_score DECIMAL(10, 2), social_score DECIMAL(10, 2), governance_score DECIMAL(10, 2)); INSERT INTO esg_factors (id, investment_id, environmental_score, social_score, governance_score) VALUES (1, 1, 80, 85, 90);
What's the average environmental score for investments in the education sector?
SELECT AVG(esg_factors.environmental_score) FROM esg_factors INNER JOIN investments ON esg_factors.investment_id = investments.id WHERE investments.sector = 'Education';
gretelai_synthetic_text_to_sql
DROP TABLE ocean_species;
Delete the 'ocean_species' table
DROP TABLE ocean_species;
gretelai_synthetic_text_to_sql
CREATE TABLE member_demographics (member_id INT, age INT, gender VARCHAR(10)); INSERT INTO member_demographics (member_id, age, gender) VALUES (1, 27, 'Female'), (2, 32, 'Trans Male'), (3, 46, 'Non-binary'); CREATE TABLE wearable_data (member_id INT, heart_rate INT, timestamp TIMESTAMP, membership_type VARCHAR(20)); INSERT INTO wearable_data (member_id, heart_rate, timestamp, membership_type) VALUES (1, 120, '2022-01-01 10:00:00', 'Platinum'), (1, 115, '2022-01-01 11:00:00', 'Platinum'), (2, 130, '2022-01-01 10:00:00', 'Platinum'), (2, 135, '2022-01-01 11:00:00', 'Platinum'), (3, 105, '2022-01-01 10:00:00', 'Platinum'), (3, 100, '2022-01-01 11:00:00', 'Platinum');
What is the average heart rate for members with a platinum membership, categorized by gender?
SELECT gender, AVG(heart_rate) as avg_heart_rate FROM wearable_data w JOIN member_demographics m ON w.member_id = m.member_id WHERE membership_type = 'Platinum' GROUP BY gender;
gretelai_synthetic_text_to_sql
CREATE TABLE marine_species (id INT PRIMARY KEY, species_name VARCHAR(255), conservation_status VARCHAR(255)); CREATE TABLE conservation_efforts (id INT PRIMARY KEY, species_id INT, location VARCHAR(255), FOREIGN KEY (species_id) REFERENCES marine_species(id)); CREATE TABLE organizations (id INT PRIMARY KEY, effort_id INT, organization_name VARCHAR(255), organization_website VARCHAR(255), FOREIGN KEY (effort_id) REFERENCES conservation_efforts(id)); INSERT INTO marine_species (id, species_name, conservation_status) VALUES (1, 'Marine Turtle', 'vulnerable');
What are the names and websites of organizations contributing to the conservation of marine turtles?
SELECT marine_species.species_name, organizations.organization_name, organizations.organization_website FROM marine_species INNER JOIN conservation_efforts ON marine_species.id = conservation_efforts.species_id INNER JOIN organizations ON conservation_efforts.id = organizations.effort_id WHERE marine_species.species_name = 'Marine Turtle';
gretelai_synthetic_text_to_sql
CREATE TABLE exhibition_data (id INT, exhibition_name VARCHAR(50), art_movement VARCHAR(50));
Count the number of exhibitions for the Cubism art movement.
SELECT COUNT(*) as num_exhibitions FROM exhibition_data WHERE art_movement = 'Cubism';
gretelai_synthetic_text_to_sql
CREATE TABLE restorative_justice_programs (id INT, name VARCHAR(50), location VARCHAR(50), start_date DATE); CREATE TABLE participants (id INT, program_id INT, participant_name VARCHAR(50), participation_date DATE);
Which restorative justice programs in California have more than 50 participants?
SELECT restorative_justice_programs.name, COUNT(participants.id) as num_participants FROM restorative_justice_programs JOIN participants ON restorative_justice_programs.id = participants.program_id WHERE restorative_justice_programs.location = 'CA' GROUP BY restorative_justice_programs.name HAVING num_participants > 50;
gretelai_synthetic_text_to_sql
CREATE TABLE student_mental_health (student_id INT, school_id INT, score INT); INSERT INTO student_mental_health (student_id, school_id, score) VALUES (1, 100, 80), (2, 100, 75), (3, 200, 90), (4, 200, 85), (5, 300, 70);
What is the minimum mental health score for students in each school that has more than one student?
SELECT school_id, MIN(score) as min_score FROM student_mental_health GROUP BY school_id HAVING COUNT(student_id) > 1;
gretelai_synthetic_text_to_sql
CREATE TABLE Communities (CommunityID INT, Name TEXT); CREATE TABLE Programs (ProgramID INT, Name TEXT, CommunityID INT);
How many times has the Food Security Program been held in each community?
SELECT C.Name as CommunityName, COUNT(P.ProgramID) as ProgramCount FROM Communities C INNER JOIN Programs P ON C.CommunityID = P.CommunityID WHERE P.Name = 'Food Security Program' GROUP BY C.CommunityID, C.Name;
gretelai_synthetic_text_to_sql
CREATE TABLE Product(Id INT, Category VARCHAR(50), ManufacturerId INT); CREATE TABLE InnovationScore(Id INT, Score INT, ProductId INT, ScoreDate DATE);
What are the average innovation scores for each product category, grouped by month?
SELECT p.Category, DATE_FORMAT(i.ScoreDate, '%Y-%m') AS Month, AVG(i.Score) AS AverageScore FROM InnovationScore i JOIN Product p ON i.ProductId = p.Id GROUP BY p.Category, Month;
gretelai_synthetic_text_to_sql
CREATE TABLE Teams (TeamID INT PRIMARY KEY, TeamName VARCHAR(100), Sport VARCHAR(50), Country VARCHAR(50)); INSERT INTO Teams (TeamID, TeamName, Sport, Country) VALUES (1, 'Boston Celtics', 'Basketball', 'USA'); CREATE TABLE Matches (MatchID INT PRIMARY KEY, HomeTeamID INT, AwayTeamID INT, MatchDate DATETIME); INSERT INTO Matches (MatchID, HomeTeamID, AwayTeamID, MatchDate) VALUES (1, 1, 2, '2022-01-01 15:00:00');
What is the total number of basketball matches played by teams from the USA after 2021-12-31?
SELECT COUNT(*) as TotalMatches FROM Matches JOIN Teams ON Matches.HomeTeamID = Teams.TeamID WHERE Teams.Country = 'USA' AND MatchDate > '2021-12-31';
gretelai_synthetic_text_to_sql
CREATE TABLE grants_awarded (id INT, recipient_name VARCHAR(50), recipient_type VARCHAR(50), region VARCHAR(50), year INT, grant_amount DECIMAL(10, 2));
Calculate the total amount of grants awarded to SMEs in the 'grants_awarded' table, grouped by region and year, with amounts greater than $10,000?
SELECT region, year, SUM(grant_amount) FROM grants_awarded WHERE recipient_type = 'SME' AND grant_amount > 10000 GROUP BY region, year;
gretelai_synthetic_text_to_sql
CREATE TABLE faculty (id INT, name VARCHAR(100), department VARCHAR(50), tenure VARCHAR(10));
Calculate the percentage of tenured faculty members in the English department.
SELECT (COUNT(*) FILTER (WHERE tenure = 'Yes')) * 100.0 / COUNT(*) AS tenure_percentage FROM faculty WHERE department = 'English';
gretelai_synthetic_text_to_sql
CREATE TABLE Farmers (id INT, name VARCHAR(50), age INT, gender VARCHAR(10), location VARCHAR(50)); INSERT INTO Farmers (id, name, age, gender, location) VALUES (1, 'John Doe', 35, 'Male', 'USA'); INSERT INTO Farmers (id, name, age, gender, location) VALUES (2, 'Jane Smith', 40, 'Female', 'Canada'); CREATE TABLE Crops (id INT, farmer_id INT, crop_name VARCHAR(50), yield INT, price FLOAT); INSERT INTO Crops (id, farmer_id, crop_name, yield, price) VALUES (1, 1, 'Corn', 120, 2.5); INSERT INTO Crops (id, farmer_id, crop_name, yield, price) VALUES (2, 2, 'Wheat', 150, 3.2);
What is the average yield of crops grown by female farmers?
SELECT AVG(c.yield) AS average_yield FROM Crops c JOIN Farmers f ON c.farmer_id = f.id WHERE f.gender = 'Female';
gretelai_synthetic_text_to_sql
CREATE TABLE genetic_research (id INT, name TEXT, description TEXT); INSERT INTO genetic_research (id, name, description) VALUES (1, 'ProjectX', 'Genome sequencing'), (2, 'ProjectY', 'CRISPR study'), (3, 'ProjectZ', 'Gene therapy');
List all genetic research projects in the 'genetic_research' table.
SELECT * FROM genetic_research;
gretelai_synthetic_text_to_sql
CREATE TABLE YttriumShipments (id INT PRIMARY KEY, mine_id INT, import_year INT, quantity INT, FOREIGN KEY (mine_id) REFERENCES YttriumMines(id)); CREATE TABLE YttriumMines (id INT PRIMARY KEY, name VARCHAR(100), production_capacity INT);
What is the total quantity of Yttrium imported by China from mines with a production capacity over 1500 tons?
SELECT SUM(quantity) FROM YttriumShipments INNER JOIN YttriumMines ON YttriumShipments.mine_id = YttriumMines.id WHERE YttriumShipments.country = 'China' AND YttriumMines.production_capacity > 1500;
gretelai_synthetic_text_to_sql
CREATE TABLE patient (id INT, name TEXT, mental_health_score INT, community TEXT); INSERT INTO patient (id, name, mental_health_score, community) VALUES (1, 'John Doe', 60, 'Straight'), (2, 'Jane Smith', 70, 'LGBTQ+'), (3, 'Ana Garcia', 50, 'Latino'), (4, 'Sara Johnson', 85, 'African American'), (5, 'Hiroshi Tanaka', 90, 'Asian'), (6, 'Peter Brown', 80, 'Caucasian');
What is the highest mental health score for patients who identify as Caucasian or Asian?
SELECT MAX(mental_health_score) FROM patient WHERE community IN ('Caucasian', 'Asian');
gretelai_synthetic_text_to_sql
CREATE TABLE Military_Equipment_Sales(sale_id INT, sale_date DATE, equipment_type VARCHAR(50), country VARCHAR(50), sale_value DECIMAL(10,2));
What is the total value of military equipment sales to the United States from January 2020 to the present?
SELECT SUM(sale_value) FROM Military_Equipment_Sales WHERE country = 'United States' AND sale_date >= '2020-01-01';
gretelai_synthetic_text_to_sql
CREATE TABLE arts_orgs (id INT, state VARCHAR(2), org_name VARCHAR(20)); CREATE TABLE org_events (id INT, org_name VARCHAR(20), num_events INT); CREATE TABLE funding_info (id INT, org_name VARCHAR(20), amount INT); INSERT INTO arts_orgs (id, state, org_name) VALUES (1, 'CO', 'OrgA'), (2, 'GA', 'OrgB'); INSERT INTO org_events (id, org_name, num_events) VALUES (1, 'OrgA', 3), (2, 'OrgB', 4); INSERT INTO funding_info (id, org_name, amount) VALUES (1, 'OrgA', 10000), (2, 'OrgB', 15000);
How many arts organizations in Colorado and Georgia have received funding and their total number of events?
SELECT COUNT(DISTINCT ao.org_name), SUM(oe.num_events) FROM arts_orgs ao INNER JOIN org_events oe ON ao.org_name = oe.org_name INNER JOIN funding_info fi ON ao.org_name = fi.org_name WHERE ao.state IN ('CO', 'GA');
gretelai_synthetic_text_to_sql
CREATE TABLE restorative_justice_programs (program_id INT, state VARCHAR(2), duration INT); INSERT INTO restorative_justice_programs (program_id, state, duration) VALUES (1, 'WA', 30), (2, 'WA', 45);
What is the average time taken to resolve restorative justice programs in Washington?
SELECT AVG(duration) FROM restorative_justice_programs WHERE state = 'WA';
gretelai_synthetic_text_to_sql
CREATE TABLE Vessels (ID INT, Name VARCHAR(50), Type VARCHAR(50)); CREATE TABLE SafetyIncidents (ID INT, VesselID INT, Location VARCHAR(50), IncidentType VARCHAR(50)); INSERT INTO Vessels (ID, Name, Type) VALUES (1, 'Ocean Titan', 'Cargo'); INSERT INTO SafetyIncidents (ID, VesselID, Location, IncidentType) VALUES (1, 1, 'North Sea', 'Collision'); INSERT INTO SafetyIncidents (ID, VesselID, Location, IncidentType) VALUES (2, 2, 'North Sea', 'Grounding');
List all unique vessel types for vessels with safety incidents in the North Sea.
SELECT DISTINCT v.Type FROM Vessels v INNER JOIN SafetyIncidents si ON v.ID = si.VesselID WHERE si.Location = 'North Sea';
gretelai_synthetic_text_to_sql
CREATE TABLE makeup_sales (product_cruelty_free BOOLEAN, sale_country VARCHAR(20), sales_quantity INT); INSERT INTO makeup_sales (product_cruelty_free, sale_country, sales_quantity) VALUES (TRUE, 'USA', 250), (FALSE, 'USA', 180), (TRUE, 'Canada', 120), (FALSE, 'Canada', 90), (TRUE, 'Mexico', 80), (FALSE, 'Mexico', 110);
What are the top 3 countries with the highest sales of cruelty-free makeup products?
SELECT sale_country, SUM(sales_quantity) AS total_sales FROM makeup_sales WHERE product_cruelty_free = TRUE GROUP BY sale_country ORDER BY total_sales DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE PolicyBroker (PolicyID INT, PolicyType VARCHAR(20), Broker VARCHAR(20)); INSERT INTO PolicyBroker (PolicyID, PolicyType, Broker) VALUES (1, 'Auto', 'BrokerSmith'), (2, 'Home', 'BrokerJones'), (3, 'Auto', 'BrokerSmith');
Show the number of policy types for each broker.
SELECT Broker, COUNT(DISTINCT PolicyType) FROM PolicyBroker GROUP BY Broker;
gretelai_synthetic_text_to_sql
CREATE TABLE drugs (id INT, name VARCHAR(255), company VARCHAR(255), department VARCHAR(255), fda_approval_date DATE, sales FLOAT); INSERT INTO drugs (id, name, company, department, fda_approval_date, sales) VALUES (1, 'DrugA', 'African Pharma', 'Neurology', '2016-01-01', 10000000), (2, 'DrugB', 'European BioTech', 'Neurology', '2017-06-15', 12000000), (3, 'DrugC', 'Asian Pharma', 'Neurology', '2018-03-23', 8000000), (4, 'DrugD', 'Oceanic Pharma', 'Cardiology', '2014-11-11', 14000000), (5, 'DrugE', 'South American Pharma', 'Neurology', '2015-09-10', 9000000);
Calculate the market share of the top 2 drugs by sales in the neurology department that were approved by the FDA before 2018, excluding companies from North America.
SELECT (a.sales / (SELECT SUM(sales) FROM drugs WHERE department = 'Neurology' AND fda_approval_date < '2018-01-01' AND company NOT IN ('North America')) * 100) AS market_share FROM drugs a WHERE a.name IN (SELECT name FROM (SELECT name FROM drugs WHERE department = 'Neurology' AND fda_approval_date < '2018-01-01' AND company NOT IN ('North America') GROUP BY name ORDER BY SUM(sales) DESC LIMIT 2) b);
gretelai_synthetic_text_to_sql