context
stringlengths
11
9.12k
question
stringlengths
0
1.06k
SQL
stringlengths
2
4.44k
source
stringclasses
28 values
CREATE TABLE athletes (athlete_id INT, athlete_name VARCHAR(50), team_id INT);CREATE TABLE performance (athlete_id INT, game_date DATE, score INT, season INT); INSERT INTO athletes (athlete_id, athlete_name, team_id) VALUES (1, 'Athlete1', 1), (2, 'Athlete2', 2); INSERT INTO performance (athlete_id, game_date, score, season) VALUES (1, '2022-01-01', 85, 2022), (1, '2022-01-02', 90, 2022), (2, '2022-01-03', 80, 2022);
Which athletes have the highest total performance score in the current season?
SELECT a.athlete_name, SUM(p.score) as total_score FROM athletes a JOIN performance p ON a.athlete_id = p.athlete_id WHERE p.season = YEAR(GETDATE()) GROUP BY a.athlete_name ORDER BY total_score DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE forestry_plots (id INT, tree_type VARCHAR(255), planted_date DATE, age INT); INSERT INTO forestry_plots (id, tree_type, planted_date, age) VALUES (1, 'Oak', '2000-01-01', 22), (2, 'Pine', '2010-05-05', 12);
What is the average age of trees in forestry_plots table?
SELECT AVG(age) FROM forestry_plots;
gretelai_synthetic_text_to_sql
CREATE TABLE equipment_incident_repair_times (incident_id INT, incident_date DATE, repair_time INT, region VARCHAR(255)); INSERT INTO equipment_incident_repair_times (incident_id, incident_date, repair_time, region) VALUES (1, '2021-01-01', 5, 'Atlantic'), (2, '2021-01-15', 10, 'Pacific'), (3, '2021-03-20', 7, 'Atlantic'), (4, '2021-07-01', 12, 'Pacific'), (5, '2021-12-15', 8, 'Pacific');
What is the maximum and minimum repair time for equipment incidents in the Pacific region in 2021?
SELECT MAX(repair_time), MIN(repair_time) FROM equipment_incident_repair_times WHERE region = 'Pacific' AND incident_date BETWEEN '2021-01-01' AND '2021-12-31';
gretelai_synthetic_text_to_sql
CREATE TABLE IntelligenceOperations (id INT, name VARCHAR(100), location VARCHAR(100)); INSERT INTO IntelligenceOperations (id, name, location) VALUES (1, 'Operation1', 'Europe'); INSERT INTO IntelligenceOperations (id, name, location) VALUES (2, 'Operation2', 'Asia');
How many intelligence operations have been conducted in 'Europe'?
SELECT COUNT(*) FROM IntelligenceOperations WHERE location = 'Europe';
gretelai_synthetic_text_to_sql
CREATE TABLE deep_sea_pressure (depth INT, region VARCHAR(20), pressure INT); INSERT INTO deep_sea_pressure (depth, region, pressure) VALUES (7000, 'Indian Ocean', 720); INSERT INTO deep_sea_pressure (depth, region, pressure) VALUES (7000, 'Indian Ocean', 710); INSERT INTO deep_sea_pressure (depth, region, pressure) VALUES (7000, 'Indian Ocean', 730);
What is the average deep-sea pressure at 7000 meters in the Indian Ocean?
SELECT AVG(pressure) FROM deep_sea_pressure WHERE depth = 7000 AND region = 'Indian Ocean';
gretelai_synthetic_text_to_sql
CREATE TABLE Members (MemberID INT, Age INT, MembershipType VARCHAR(20)); INSERT INTO Members (MemberID, Age, MembershipType) VALUES (1, 25, 'Gold'), (2, 30, 'Silver'), (3, 35, 'Gold'); CREATE TABLE Workout (MemberID INT, Equipment VARCHAR(20), Duration INT, Date DATE); INSERT INTO Workout (MemberID, Equipment, Duration, Date) VALUES (1, 'Treadmill', 60, '2022-01-01'), (2, 'Bike', 45, '2022-01-02'), (3, 'Treadmill', 30, '2022-01-03'), (1, 'Bike', 30, '2022-01-04'), (2, 'Treadmill', 45, '2022-01-05'), (3, 'Swimming Pool', 60, '2022-01-06');
What is the total number of workouts and the total duration of workouts for each member in the past month?
SELECT Members.MemberID, COUNT(Workout.MemberID) AS NumberOfWorkouts, SUM(Workout.Duration) AS TotalDuration FROM Members LEFT JOIN Workout ON Members.MemberID = Workout.MemberID WHERE Workout.Date >= DATEADD(day, -30, GETDATE()) GROUP BY Members.MemberID;
gretelai_synthetic_text_to_sql
CREATE TABLE public_schools (id INT, name TEXT, location TEXT, num_students INT, avg_teacher_age FLOAT); INSERT INTO public_schools (id, name, location, num_students, avg_teacher_age) VALUES (1, 'School 1', 'CA', 850, 45.3), (2, 'School 2', 'CA', 600, 43.2), (3, 'School 3', 'CA', 700, 47.1);
Delete all records of schools with more than 800 students in California.
DELETE FROM public_schools WHERE location = 'CA' AND num_students > 800;
gretelai_synthetic_text_to_sql
CREATE TABLE emergency_incidents (id INT, reported_date DATE); INSERT INTO emergency_incidents (id, reported_date) VALUES (1001, '2021-01-01');
Update the reported date of emergency incident with ID 1001 to '2021-01-03'
UPDATE emergency_incidents SET reported_date = '2021-01-03' WHERE id = 1001;
gretelai_synthetic_text_to_sql
CREATE TABLE explainable_ai (id INT, author VARCHAR(50), country VARCHAR(50), title VARCHAR(100), publication_date DATE); INSERT INTO explainable_ai (id, author, country, title, publication_date) VALUES (1, 'Sophie Martin', 'France', 'Explainable AI for Image Recognition', '2021-03-01'), (2, 'Hans Schmidt', 'Germany', 'Transparent AI Systems', '2020-07-15');
What's the number of explainable AI papers published by French and German authors since 2019?
SELECT COUNT(*) FROM explainable_ai WHERE country IN ('France', 'Germany') AND publication_date >= '2019-01-01' AND (title LIKE '%explainable%' OR title LIKE '%transparent%');
gretelai_synthetic_text_to_sql
CREATE TABLE policy_impact (city VARCHAR(255), policy_id INT, impact TEXT); INSERT INTO policy_impact
What is the total number of policy impact records for 'City G'?
SELECT COUNT(*) FROM policy_impact WHERE city = 'City G'
gretelai_synthetic_text_to_sql
CREATE TABLE restaurants (restaurant_id INT, name VARCHAR(50), location VARCHAR(50)); INSERT INTO restaurants (restaurant_id, name, location) VALUES (1, 'Green ABC Cafe', 'New York'), (2, 'XYZ Diner', 'Los Angeles'); CREATE TABLE sales (sale_id INT, restaurant_id INT, sale_date DATE, revenue DECIMAL(10,2)); INSERT INTO sales (sale_id, restaurant_id, sale_date, revenue) VALUES (5, 1, '2022-02-01', 1200), (6, 1, '2022-02-03', 1800), (7, 2, '2022-02-02', 1300), (8, 2, '2022-02-04', 2300);
What was the total revenue for each restaurant, including the name and location, for the month of February 2022?
SELECT r.name, r.location, SUM(s.revenue) as total_revenue FROM restaurants r INNER JOIN sales s ON r.restaurant_id = s.restaurant_id WHERE s.sale_date BETWEEN '2022-02-01' AND '2022-02-28' GROUP BY r.restaurant_id, r.name, r.location;
gretelai_synthetic_text_to_sql
CREATE TABLE HeritageSites (SiteID INT, SiteName VARCHAR(50)); CREATE TABLE CommunityEvents (EventID INT, EventName VARCHAR(50), SiteID INT); INSERT INTO HeritageSites VALUES (1, 'SiteA'), (2, 'SiteB'), (3, 'SiteC'), (4, 'SiteD'); INSERT INTO CommunityEvents VALUES (1, 'Workshop', 1), (2, 'Performance', 1), (3, 'Workshop', 2), (4, 'Lecture', 3), (5, 'Workshop', 3), (6, 'Performance', 4);
How many community events are organized per heritage site?
SELECT HS.SiteName, COUNT(CE.EventID) AS TotalEvents FROM HeritageSites HS JOIN CommunityEvents CE ON HS.SiteID = CE.SiteID GROUP BY HS.SiteName;
gretelai_synthetic_text_to_sql
CREATE TABLE Trench (trench_name VARCHAR(50), max_depth NUMERIC(8,2), min_depth NUMERIC(8,2)); INSERT INTO Trench (trench_name, max_depth, min_depth) VALUES ('Puerto Rico Trench', 8648, 8376);
What are the maximum and minimum depths of the Puerto Rico Trench?
SELECT trench_name, MAX(max_depth) AS max_depth, MIN(min_depth) AS min_depth FROM Trench WHERE trench_name = 'Puerto Rico Trench';
gretelai_synthetic_text_to_sql
CREATE TABLE regions (id INT, biome VARCHAR(50)); INSERT INTO regions (id, biome) VALUES (1, 'temperate'); CREATE TABLE timber_harvest (id INT, region_id INT, year INT, volume FLOAT); INSERT INTO timber_harvest (id, region_id, year, volume) VALUES (1, 1, 2023, 1200.5);
Calculate total timber volume in 'temperate' regions for 2023.
SELECT SUM(volume) FROM timber_harvest WHERE region_id IN (SELECT id FROM regions WHERE biome = 'temperate') AND year = 2023;
gretelai_synthetic_text_to_sql
CREATE TABLE fire_incidents (id INT, incident_type VARCHAR(50), incident_location VARCHAR(100), response_time INT, city VARCHAR(50), state VARCHAR(50)); INSERT INTO fire_incidents (id, incident_type, incident_location, response_time, city, state) VALUES (1, 'Fire', '456 Elm St', 8, 'New York', 'NY');
What is the total number of fire incidents in the state of New York?
SELECT COUNT(*) FROM fire_incidents WHERE state = 'NY';
gretelai_synthetic_text_to_sql
CREATE TABLE faculty (faculty_id INT, faculty_name VARCHAR(50), dept_name VARCHAR(50), salary INT); CREATE TABLE publications (publication_id INT, faculty_id INT, pub_date DATE);
What is the average salary of faculty members who have published in academic journals in the past year, and how does this compare to the average salary of all faculty members?
SELECT AVG(f.salary) as avg_salary_publishing, (SELECT AVG(f2.salary) FROM faculty f2) as avg_salary_all FROM faculty f INNER JOIN publications p ON f.faculty_id = p.faculty_id WHERE p.pub_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 1 YEAR);
gretelai_synthetic_text_to_sql
CREATE TABLE customer_meals (customer_id INTEGER, restaurant_name TEXT, calories INTEGER, meal_date DATE); INSERT INTO customer_meals (customer_id, restaurant_name, calories, meal_date) VALUES (1, 'New York Vegan', 400, '2022-08-01'); INSERT INTO customer_meals (customer_id, restaurant_name, calories, meal_date) VALUES (2, 'New York Vegan', 600, '2022-08-01');
What are the total calories consumed by each customer for the 'New York Vegan' restaurant in the month of August 2022, ranked by consumption?
SELECT customer_id, SUM(calories) as total_calories FROM customer_meals WHERE restaurant_name = 'New York Vegan' AND meal_date >= '2022-08-01' AND meal_date < '2022-09-01' GROUP BY customer_id ORDER BY total_calories DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE SoilMoisture (date DATE, soil_moisture INT, crop_type VARCHAR(20));
What is the trend in soil moisture for each crop type over the past 5 years?
SELECT crop_type, soil_moisture, ROW_NUMBER() OVER(PARTITION BY crop_type ORDER BY date DESC) as rank, AVG(soil_moisture) OVER(PARTITION BY crop_type ORDER BY date ROWS BETWEEN 3 PRECEDING AND CURRENT ROW) as avg_soil_moisture FROM SoilMoisture WHERE date >= DATEADD(year, -5, CURRENT_DATE);
gretelai_synthetic_text_to_sql
CREATE TABLE MilitarySpending (region VARCHAR(50), country VARCHAR(50), amount INT); INSERT INTO MilitarySpending (region, country, amount) VALUES ('Asia', 'India', 6500000000); INSERT INTO MilitarySpending (region, country, amount) VALUES ('Asia', 'China', 2610000000); INSERT INTO MilitarySpending (region, country, amount) VALUES ('Europe', 'Russia', 660000000);
What is the total military spending by 'Asia' countries in the 'MilitarySpending' table?
SELECT region, SUM(amount) FROM MilitarySpending WHERE region = 'Asia' GROUP BY region;
gretelai_synthetic_text_to_sql
CREATE TABLE Trains (id INT, name VARCHAR(50), speed FLOAT, country VARCHAR(50)); INSERT INTO Trains (id, name, speed, country) VALUES (1, 'TrainA', 120.5, 'Canada'), (2, 'TrainB', 150.7, 'Canada'), (3, 'TrainC', 180.9, 'USA'), (4, 'TrainD', 200.2, 'USA');
What is the average speed of electric trains in Canada and the US, grouped by country?
SELECT context.country, AVG(context.speed) FROM (SELECT * FROM Trains WHERE Trains.country IN ('Canada', 'USA')) AS context GROUP BY context.country;
gretelai_synthetic_text_to_sql
CREATE TABLE Plays (Platform VARCHAR(20), Genre VARCHAR(10), Plays INT, EventDate DATE); INSERT INTO Plays (Platform, Genre, Plays, EventDate) VALUES ('Spotify', 'Jazz', 20000, '2021-01-01'), ('Spotify', 'Pop', 30000, '2021-01-01'), ('Deezer', 'Jazz', 15000, '2021-01-01'), ('Deezer', 'Pop', 20000, '2021-01-01');
What is the total number of plays for the jazz genre on Spotify and Deezer?
SELECT Platform, SUM(Plays) as TotalPlays FROM Plays WHERE Genre = 'Jazz' AND (Platform = 'Spotify' OR Platform = 'Deezer') GROUP BY Platform;
gretelai_synthetic_text_to_sql
CREATE TABLE HealthEquityMetrics (MetricID INT, State VARCHAR(25)); INSERT INTO HealthEquityMetrics (MetricID, State) VALUES (1, 'NY'), (2, 'CA'), (3, 'TX'), (4, 'CA'), (5, 'NY');
Which health equity metrics are tracked in each state?
SELECT State, COUNT(DISTINCT MetricID) as NumMetrics FROM HealthEquityMetrics GROUP BY State;
gretelai_synthetic_text_to_sql
CREATE TABLE Restaurants (RestaurantID int, Name varchar(50), Location varchar(50)); CREATE TABLE Menu (MenuID int, ItemName varchar(50), Category varchar(50)); CREATE TABLE MenuSales (MenuID int, RestaurantID int, QuantitySold int, Revenue decimal(5,2), SaleDate date);
Insert new menu items that are locally sourced and update their revenue data for the month of July 2021 in restaurants located in New York.
INSERT INTO Menu (MenuID, ItemName, Category) VALUES (1001, 'New York Cheesecake', 'Dessert'), (1002, 'Brooklyn Pizza', 'Main Course'); UPDATE MenuSales SET Revenue = 50 WHERE MenuID = 1001 AND SaleDate >= '2021-07-01' AND SaleDate <= '2021-07-31'; UPDATE MenuSales SET Revenue = 12.99 WHERE MenuID = 1002 AND SaleDate >= '2021-07-01' AND SaleDate <= '2021-07-31';
gretelai_synthetic_text_to_sql
CREATE TABLE route_planning (route_id INT, trips_taken INT, fare_collected DECIMAL(5,2)); INSERT INTO route_planning (route_id, trips_taken, fare_collected) VALUES (1, 500, 1200.00), (2, 600, 1950.00), (3, 450, 1125.00);
Show the number of trips taken and fare collected per route
SELECT route_id, trips_taken, fare_collected, (fare_collected / trips_taken) as average_fare FROM route_planning;
gretelai_synthetic_text_to_sql
CREATE TABLE campaigns (campaign_id INT, campaign_title VARCHAR(255), revenue INT); INSERT INTO campaigns (campaign_id, campaign_title, revenue) VALUES (1, 'Campaign 1', 1000), (2, 'Campaign 2', 500), (3, 'Campaign 3', 1500);
What is the total revenue generated by each advertising campaign in the last quarter?
SELECT campaign_title, SUM(revenue) FROM campaigns WHERE campaign_date >= DATEADD(quarter, -1, GETDATE()) GROUP BY campaign_title;
gretelai_synthetic_text_to_sql
CREATE TABLE medical_personnel (id INT, name VARCHAR(255), skill_level VARCHAR(255), country VARCHAR(255)); INSERT INTO medical_personnel (id, name, skill_level, country) VALUES ('1', 'Ahmed', 'Expert', 'Syria'), ('2', 'Fatima', 'Intermediate', 'Syria'), ('3', 'Hassan', 'Beginner', 'Yemen'), ('4', 'Zainab', 'Expert', 'Yemen'), ('5', 'Ali', 'Intermediate', 'Syria'), ('6', 'Aisha', 'Beginner', 'Yemen');
List the names and skill levels of all medical personnel who have served in Syria and Yemen, sorted alphabetically by name.
SELECT name, skill_level FROM medical_personnel WHERE country IN ('Syria', 'Yemen') ORDER BY name ASC;
gretelai_synthetic_text_to_sql
CREATE TABLE financial_capability_programs (program_id INT, program_name VARCHAR(50), country VARCHAR(50), region VARCHAR(50));
Determine the number of financial capability programs in each country and region
SELECT country, region, COUNT(*) FROM financial_capability_programs GROUP BY country, region;
gretelai_synthetic_text_to_sql
CREATE TABLE clinics (name VARCHAR(255), establishment_date DATE); INSERT INTO clinics (name, establishment_date) VALUES ('Clinic C', '2011-01-01'), ('Clinic D', '2015-05-15');
Which rural health clinics were established after 2010, and what are their names?
SELECT name FROM clinics WHERE establishment_date > '2010-12-31';
gretelai_synthetic_text_to_sql
CREATE TABLE investments (id INT, region VARCHAR(20), year INT, amount FLOAT); INSERT INTO investments (id, region, year, amount) VALUES (1, 'Asia-Pacific', 2020, 1000000), (2, 'Asia-Pacific', 2019, 900000), (3, 'Asia-Pacific', 2018, 800000);
What is the total investment in network infrastructure for the Asia-Pacific region in the last 3 years?
SELECT SUM(amount) FROM investments WHERE region = 'Asia-Pacific' AND year BETWEEN 2018 AND 2020;
gretelai_synthetic_text_to_sql
CREATE TABLE containers (id INT, port VARCHAR(255), handled_date DATE, handling_time INT); INSERT INTO containers (id, port, handled_date, handling_time) VALUES (1, 'Sydney', '2022-03-02', 120), (2, 'Melbourne', '2022-03-03', 100), (3, 'Brisbane', '2022-03-04', 150), (4, 'Sydney', '2022-03-05', 130), (5, 'Melbourne', '2022-03-06', 110);
What is the average handling time of containers at the port 'Sydney'?
SELECT AVG(handling_time) FROM containers WHERE port = 'Sydney';
gretelai_synthetic_text_to_sql
CREATE TABLE waste_generation (city VARCHAR(255), year INT, amount INT); INSERT INTO waste_generation (city, year, amount) VALUES ('San Francisco', 2020, 500000);
What is the total waste generation in the city of San Francisco in 2020?
SELECT amount FROM waste_generation WHERE city = 'San Francisco' AND year = 2020;
gretelai_synthetic_text_to_sql
CREATE TABLE teacher_training (teacher_id INT, teacher_name TEXT, subject TEXT, completed_training BOOLEAN);
What is the percentage of teachers who have completed professional development in each subject area?
SELECT subject, AVG(CAST(completed_training AS FLOAT))*100 as percentage FROM teacher_training WHERE completed_training = TRUE GROUP BY subject;
gretelai_synthetic_text_to_sql
CREATE TABLE hr.employee_details (id INT, employee_id INT, first_name VARCHAR(50), last_name VARCHAR(50), department VARCHAR(50), birth_date DATE); CREATE TABLE hr.employee_hires (id INT, employee_id INT, hire_date DATE, job_id VARCHAR(20));
Show the names and salaries of employees who were hired in the same month as their birthday in the 'hr' schema's 'employee_details' and 'employee_hires' tables
SELECT e.first_name, e.last_name, e.salary FROM hr.employee_details e INNER JOIN hr.employee_hires h ON e.employee_id = h.employee_id WHERE MONTH(e.birth_date) = MONTH(h.hire_date);
gretelai_synthetic_text_to_sql
CREATE TABLE GH_Well (Well_ID VARCHAR(10), Production_Rate INT); INSERT INTO GH_Well (Well_ID, Production_Rate) VALUES ('W001', 200), ('W002', 300);CREATE TABLE Well_Status (Well_ID VARCHAR(10), Status VARCHAR(10)); INSERT INTO Well_Status (Well_ID, Status) VALUES ('W001', 'Active'), ('W002', 'Inactive');
What is the maximum production rate in the 'GH_Well' table for wells with a status of 'Active' in the 'Well_Status' table?
SELECT MAX(Production_Rate) FROM GH_Well WHERE Well_ID IN (SELECT Well_ID FROM Well_Status WHERE Status = 'Active');
gretelai_synthetic_text_to_sql
CREATE TABLE IoT_AI_Strategies (Country VARCHAR(255), Strategy VARCHAR(255)); INSERT INTO IoT_AI_Strategies (Country, Strategy) VALUES ('USA', 'IoT Security Improvement Act'), ('UK', 'National Cyber Security Strategy'), ('Germany', 'IT-Sicherheitsgesetz'), ('Japan', 'Cybersecurity Basic Act');
Which countries have implemented cybersecurity strategies related to IoT and AI?
SELECT Country FROM IoT_AI_Strategies WHERE Strategy LIKE '%IoT%' OR Strategy LIKE '%AI%';
gretelai_synthetic_text_to_sql
CREATE TABLE STORES (store_id INT, region VARCHAR(20), sales FLOAT); INSERT INTO STORES VALUES (1, 'North', 5000), (2, 'South', 7000), (3, 'East', 8000), (4, 'West', 6000); CREATE TABLE PRODUCTS (product_id INT, category VARCHAR(20), price FLOAT); INSERT INTO PRODUCTS VALUES (1, 'Tops', 25), (2, 'Pants', 35), (3, 'Dresses', 45);
Calculate the total sales for stores in the 'North' region where the sales are below the average product price.
SELECT SUM(sales) FROM STORES WHERE region = 'North' AND sales < (SELECT AVG(price) FROM PRODUCTS);
gretelai_synthetic_text_to_sql
CREATE TABLE students (student_id INT, student_name VARCHAR(50), country VARCHAR(50)); CREATE TABLE lifelong_learning (ll_id INT, student_id INT, program_name VARCHAR(50)); INSERT INTO students (student_id, student_name, country) VALUES (1, 'Alice', 'USA'), (2, 'Bob', 'Canada'), (3, 'Charlie', 'Mexico'), (4, 'David', 'USA'), (5, 'Eva', 'Canada'); INSERT INTO lifelong_learning (ll_id, student_id, program_name) VALUES (1, 1, 'Program A'), (2, 2, 'Program B'), (3, 3, 'Program C'), (4, 4, 'Program A'), (5, 5, 'Program B');
What is the number of students enrolled in lifelong learning programs by program name and country?
SELECT lifelong_learning.program_name, students.country, COUNT(DISTINCT lifelong_learning.student_id) as num_students FROM lifelong_learning INNER JOIN students ON lifelong_learning.student_id = students.student_id GROUP BY lifelong_learning.program_name, students.country;
gretelai_synthetic_text_to_sql
CREATE TABLE space_debris (debris_year INT, debris_type VARCHAR(30), mass FLOAT); INSERT INTO space_debris VALUES (2015, 'Fuel Tank', 1200.20), (2016, 'Upper Stage', 2500.50), (2017, 'Payload Adapter', 600.30), (2018, 'Instrument', 80.10);
What is the total mass of space debris generated each year in the space_debris table?
SELECT debris_year, SUM(mass) OVER (PARTITION BY debris_year) FROM space_debris;
gretelai_synthetic_text_to_sql
CREATE TABLE animal_habitat (habitat_id INT, animal_name VARCHAR(50), habitat_size INT); INSERT INTO animal_habitat (habitat_id, animal_name, habitat_size) VALUES (1, 'Tiger', 500), (2, 'Elephant', 1000), (3, 'Lion', 700);
What is the average habitat size for animals in the 'animal_habitat' table?
SELECT AVG(habitat_size) FROM animal_habitat;
gretelai_synthetic_text_to_sql
CREATE TABLE subscribers (subscriber_id INT, service_type VARCHAR(50), data_usage FLOAT); CREATE TABLE services (service_type VARCHAR(50), description VARCHAR(50));
For each 'service_type' in the 'services' table, return the number of rows in the 'subscribers' table with the corresponding 'service_type'.
SELECT s.service_type, COUNT(*) OVER (PARTITION BY s.service_type) AS count_of_subscribers_with_service_type FROM services s JOIN subscribers sub ON s.service_type = sub.service_type;
gretelai_synthetic_text_to_sql
CREATE TABLE policies (policy_name VARCHAR(255), region VARCHAR(255), start_year INT, end_year INT); INSERT INTO policies (policy_name, region, start_year, end_year) VALUES ('Renewable Portfolio Standard', 'Asia-Pacific', 2015, 2020), ('Feed-in Tariff Program', 'Asia-Pacific', 2016, 2020), ('Energy Storage Target', 'Asia-Pacific', 2017, 2020), ('Carbon Pricing', 'Asia-Pacific', 2018, 2020), ('Green Building Codes', 'Asia-Pacific', 2019, 2020);
List all the clean energy policy trends in the Asia-Pacific region from 2015 to 2020.
SELECT policy_name FROM policies WHERE region = 'Asia-Pacific' AND start_year BETWEEN 2015 AND 2020;
gretelai_synthetic_text_to_sql
CREATE TABLE student (id INT, name VARCHAR(50), program VARCHAR(50)); CREATE TABLE grant (id INT, title VARCHAR(100), student_id INT);
What are the names of graduate students who have not received any research grants?
SELECT s.name FROM student s LEFT JOIN grant g ON s.id = g.student_id WHERE g.id IS NULL;
gretelai_synthetic_text_to_sql
CREATE TABLE anime (id INT, title VARCHAR(255), release_year INT, views INT, country VARCHAR(50), runtime INT); INSERT INTO anime (id, title, release_year, views, country, runtime) VALUES (1, 'Anime1', 2010, 10000, 'Japan', 120), (2, 'Anime2', 2015, 15000, 'Japan', 150);
What is the total runtime for all anime produced in Japan?
SELECT SUM(runtime) FROM anime WHERE country = 'Japan';
gretelai_synthetic_text_to_sql
CREATE TABLE donations (id INT, volunteer TEXT, donation FLOAT, donation_date DATE); INSERT INTO donations (id, volunteer, donation, donation_date) VALUES (1, 'Jamal Williams', 50.00, '2022-01-01'), (2, 'Sophia Garcia', 100.00, '2022-02-01'), (3, 'Liam Brown', 25.00, '2022-01-15'), (4, 'Olivia Johnson', 75.00, '2022-03-05'), (5, 'William Davis', 125.00, '2022-03-20');
What is the total donation amount per volunteer for the year 2022?
SELECT volunteer, SUM(donation) FROM donations WHERE donation_date BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY volunteer;
gretelai_synthetic_text_to_sql
CREATE TABLE EsportsPlayers (PlayerID INT, Name VARCHAR(50), Country VARCHAR(20), Tournaments INT, Earnings DECIMAL(10,2)); INSERT INTO EsportsPlayers (PlayerID, Name, Country, Tournaments, Earnings) VALUES (1, 'John Doe', 'USA', 5, 500000), (2, 'Jane Smith', 'Canada', 3, 350000), (3, 'Mike Johnson', 'Mexico', 7, 600000);
List the names and total earnings of the top 5 players who have earned the most from esports tournaments?
SELECT Name, SUM(Earnings) AS TotalEarnings FROM EsportsPlayers GROUP BY Name ORDER BY TotalEarnings DESC LIMIT 5;
gretelai_synthetic_text_to_sql
CREATE TABLE employees (id INT, name VARCHAR(50), department VARCHAR(20), hire_date DATE); INSERT INTO employees (id, name, department, hire_date) VALUES (1, 'John Doe', 'quality control', '2016-01-01'), (2, 'Jane Smith', 'engineering', '2018-01-01'), (3, 'Bob Johnson', 'quality control', '2015-01-01');
What are the names of all employees in the 'quality control' department who have been with the company for more than 5 years?
SELECT name FROM employees WHERE department = 'quality control' AND hire_date <= DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR);
gretelai_synthetic_text_to_sql
CREATE TABLE investments (company_id INT, round_type TEXT, raised_amount INT); INSERT INTO investments (company_id, round_type, raised_amount) VALUES (1, 'Series A', 5000000); INSERT INTO investments (company_id, round_type, raised_amount) VALUES (2, 'Seed', 1000000); CREATE TABLE companies (id INT, name TEXT, founding_year INT, founder_gender TEXT); INSERT INTO companies (id, name, founding_year, founder_gender) VALUES (1, 'Acme Inc', 2018, 'Female'); INSERT INTO companies (id, name, founding_year, founder_gender) VALUES (2, 'Bravo Corp', 2020, 'Male');
What is the average investment per round for companies founded by women in the last 5 years?
SELECT AVG(raised_amount) as avg_investment FROM investments JOIN companies ON investments.company_id = companies.id WHERE companies.founding_year >= YEAR(CURRENT_DATE) - 5 AND companies.founder_gender = 'Female';
gretelai_synthetic_text_to_sql
CREATE TABLE CommunityHealthWorkers (Id INT, Age INT, CulturalCompetencyLevel VARCHAR(20)); INSERT INTO CommunityHealthWorkers (Id, Age, CulturalCompetencyLevel) VALUES (1, 45, 'High'), (2, 35, 'Medium'), (3, 50, 'Low');
What is the average age of community health workers by cultural competency level?
SELECT CulturalCompetencyLevel, AVG(Age) as AvgAge FROM CommunityHealthWorkers GROUP BY CulturalCompetencyLevel;
gretelai_synthetic_text_to_sql
CREATE TABLE news_reports (id INT, title VARCHAR(100), publication_date DATE, word_count INT); INSERT INTO news_reports (id, title, publication_date, word_count) VALUES (1, 'Climate Change Impact', '2022-03-01', 1500), (2, 'Political Turmoil in Europe', '2021-12-15', 2000), (3, 'Technology Advancements in Healthcare', '2022-06-20', 1200);
How many news reports in the "news_reports" table were published in 2022 and have more than 1000 words?
SELECT COUNT(*) FROM news_reports WHERE YEAR(publication_date) = 2022 AND word_count > 1000;
gretelai_synthetic_text_to_sql
CREATE TABLE GamingData (PlayerID INT, Date DATE, GamesPlayed INT); INSERT INTO GamingData (PlayerID, Date, GamesPlayed) VALUES (1, '2022-01-01', 5), (2, '2022-01-02', 10), (3, '2022-01-03', 15), (4, '2022-01-04', 20), (5, '2022-01-05', 25);
What is the maximum number of games played in a day by any player in the 'GamingData' table?
SELECT MAX(GamesPlayed) FROM GamingData;
gretelai_synthetic_text_to_sql
CREATE TABLE community_development (id INT, name VARCHAR(50), type VARCHAR(50), budget FLOAT); INSERT INTO community_development (id, name, type, budget) VALUES (1, 'Green Spaces', 'Community Development', 75000.00), (2, 'Smart Street Lighting', 'Agricultural Innovation', 120000.00), (3, 'Cultural Center', 'Community Development', 100000.00);
What are the unique types of community development projects in the 'community_development' table?
SELECT DISTINCT type FROM community_development WHERE type = 'Community Development';
gretelai_synthetic_text_to_sql
CREATE TABLE recycling_rates (id INT, material VARCHAR(20), year INT, recycling_rate DECIMAL(5,2)); INSERT INTO recycling_rates (id, material, year, recycling_rate) VALUES (1, 'glass', 2017, 0.35), (2, 'glass', 2018, 0.37), (3, 'glass', 2019, 0.39), (4, 'paper', 2017, 0.60), (5, 'paper', 2018, 0.63), (6, 'paper', 2019, 0.66);
What is the change in recycling rate for glass between 2018 and 2019?
SELECT (recycling_rate - (SELECT recycling_rate FROM recycling_rates r2 WHERE r2.material = 'glass' AND r2.year = 2018)) FROM recycling_rates WHERE material = 'glass' AND year = 2019;
gretelai_synthetic_text_to_sql
CREATE TABLE recycling_rates (id INT PRIMARY KEY, location VARCHAR(50), rate FLOAT);
Show the locations with a recycling rate above 50%
SELECT location FROM recycling_rates WHERE rate > 50;
gretelai_synthetic_text_to_sql
CREATE TABLE if not exists investments (id INT PRIMARY KEY, strategy_id INT, value REAL);
alter a table to add a new column
ALTER TABLE investments ADD COLUMN currency TEXT;
gretelai_synthetic_text_to_sql
CREATE TABLE clinic_p (patient_id INT, cost INT, treatment VARCHAR(10)); INSERT INTO clinic_p (patient_id, cost, treatment) VALUES (31, 100, 'therapy'), (32, 200, 'medication'); CREATE TABLE clinic_q (patient_id INT, cost INT, treatment VARCHAR(10)); INSERT INTO clinic_q (patient_id, cost, treatment) VALUES (33, 300, 'therapy'), (34, 400, 'medication');
How many patients received therapy in 'clinic_p' and 'clinic_q'?
SELECT COUNT(*) FROM (SELECT * FROM clinic_p WHERE treatment = 'therapy' UNION ALL SELECT * FROM clinic_q WHERE treatment = 'therapy') AS combined_therapy_clinics;
gretelai_synthetic_text_to_sql
CREATE TABLE policy_initiatives (initiative_name VARCHAR(255), city VARCHAR(50), init_year INT, evidence_based BOOLEAN); INSERT INTO policy_initiatives (initiative_name, city, init_year, evidence_based) VALUES ('Initiative A', 'LA', 2020, TRUE), ('Initiative B', 'LA', 2019, FALSE), ('Initiative C', 'LA', 2020, TRUE);
How many evidence-based policy making initiatives were implemented in the city of Los Angeles in the year 2020?
SELECT COUNT(*) FROM policy_initiatives WHERE city = 'LA' AND init_year = 2020 AND evidence_based = TRUE;
gretelai_synthetic_text_to_sql
CREATE TABLE GreenBuildings (id INT, name VARCHAR(50), location VARCHAR(50), energyConsumption DECIMAL(5,2)); CREATE TABLE Averages (location VARCHAR(50), avg_consumption DECIMAL(5,2), num_buildings INT); INSERT INTO Averages (location, avg_consumption, num_buildings) SELECT location, AVG(energyConsumption) as avg_consumption, COUNT(*) as num_buildings FROM GreenBuildings GROUP BY location;
Find the locations with the highest average energy consumption that have more than 5 buildings in the 'GreenBuildings' table.
SELECT location, avg_consumption FROM Averages WHERE avg_consumption = (SELECT MAX(avg_consumption) FROM Averages) AND num_buildings > 5;
gretelai_synthetic_text_to_sql
CREATE TABLE Employees (EmployeeID int, Department varchar(50)); INSERT INTO Employees (EmployeeID, Department) VALUES (1, 'Engineering'), (2, 'Marketing'), (3, 'Sales'); CREATE TABLE Departments (Department varchar(50), Manager varchar(50)); INSERT INTO Departments (Department, Manager) VALUES ('Engineering', 'John Doe'), ('Marketing', 'Jane Smith'), ('Sales', 'Bob Johnson');
What is the total number of employees in each department, and what is the percentage of the total employee count that each department represents?
SELECT e.Department, COUNT(e.EmployeeID) as EmployeeCount, COUNT(e.EmployeeID) * 100.0 / (SELECT COUNT(*) FROM Employees) as PercentageOfTotal FROM Employees e GROUP BY e.Department;
gretelai_synthetic_text_to_sql
CREATE TABLE Budget (BudgetID INT, Department VARCHAR(50), Amount DECIMAL(10,2), BudgetYear INT);
What is the total budget allocated for the "Education" department in the current year?
SELECT SUM(Amount) FROM Budget WHERE Department = 'Education' AND BudgetYear = YEAR(CURDATE());
gretelai_synthetic_text_to_sql
CREATE TABLE recycled_polyester_supply_chain (manufacturer_id INT, quantity FLOAT); INSERT INTO recycled_polyester_supply_chain (manufacturer_id, quantity) VALUES (1, 600.0), (2, 400.0), (3, 800.0);
What is the total quantity of recycled polyester used by manufacturers in the ethical fashion supply chain?
SELECT SUM(quantity) FROM recycled_polyester_supply_chain;
gretelai_synthetic_text_to_sql
CREATE TABLE spacecraft (id INT, name VARCHAR(255), launch_company VARCHAR(255), launch_date DATE, max_speed FLOAT);
What is the average speed of spacecraft launched by SpaceX and NASA?
SELECT launch_company, AVG(max_speed) as avg_speed FROM spacecraft WHERE launch_company IN ('SpaceX', 'NASA') GROUP BY launch_company;
gretelai_synthetic_text_to_sql
CREATE TABLE investments (id INT, company_id INT, investment_amount INT); CREATE TABLE companies (id INT, name TEXT, founding_year INT, founder_race TEXT); INSERT INTO investments (id, company_id, investment_amount) VALUES (1, 1, 5000000); INSERT INTO investments (id, company_id, investment_amount) VALUES (2, 2, 3000000); INSERT INTO companies (id, name, founding_year, founder_race) VALUES (1, 'Delta Startups', 2020, 'Black'); INSERT INTO companies (id, name, founding_year, founder_race) VALUES (2, 'Epsilon Enterprises', 2018, 'White');
What is the minimum investment amount for startups with a Black founder?
SELECT MIN(investment_amount) FROM investments JOIN companies ON investments.company_id = companies.id WHERE companies.founder_race = 'Black';
gretelai_synthetic_text_to_sql
CREATE TABLE threat_actors (name VARCHAR(50), sector VARCHAR(20), threat_level VARCHAR(10)); INSERT INTO threat_actors (name, sector, threat_level) VALUES ('Actor 1', 'Government', 'Medium'), ('Actor 2', 'Government', 'Low');
Show the names and threat levels of all threat actors operating in the government sector, excluding those with a 'Low' threat level.
SELECT name, threat_level FROM threat_actors WHERE sector = 'Government' AND threat_level != 'Low';
gretelai_synthetic_text_to_sql
CREATE TABLE Exhibition_Visits (visitor_id INT, visit_date DATE);
Find the number of days since the last exhibition visit for each visitor.
SELECT visitor_id, DATEDIFF(MAX(visit_date), visit_date) AS days_since_last_visit FROM Exhibition_Visits GROUP BY visitor_id;
gretelai_synthetic_text_to_sql
CREATE TABLE property (id INT, size_sqft INT, has_walkability BOOLEAN, has_inclusive_policy BOOLEAN); INSERT INTO property (id, size_sqft, has_walkability, has_inclusive_policy) VALUES (1, 1200, true, true), (2, 800, false, false), (3, 1500, true, true), (4, 900, true, false);
What is the total number of properties in walkable neighborhoods with inclusive housing policies, and their average size in square feet?
SELECT SUM(1), AVG(size_sqft) FROM property WHERE has_walkability = true AND has_inclusive_policy = true;
gretelai_synthetic_text_to_sql
CREATE TABLE Restaurants (RestaurantID int, RestaurantName varchar(255), Region varchar(255), VeganOptions varchar(10)); CREATE TABLE MenuItems (MenuID int, MenuName varchar(255), RestaurantID int, Sales int);
List all restaurants offering vegan options in 'Eastside' and their respective total revenue.
SELECT R.RestaurantName, SUM(M.Sales) as TotalRevenue FROM Restaurants R INNER JOIN MenuItems M ON R.RestaurantID = M.RestaurantID WHERE R.Region = 'Eastside' AND R.VeganOptions = 'Yes' GROUP BY R.RestaurantName;
gretelai_synthetic_text_to_sql
CREATE TABLE project (id INT PRIMARY KEY, name VARCHAR(255), location VARCHAR(255), start_date DATE, end_date DATE, sustainability_rating FLOAT); CREATE TABLE labor (id INT PRIMARY KEY, project_id INT, worker_name VARCHAR(255), hours_worked FLOAT, hourly_wage FLOAT); CREATE VIEW labor_summary AS SELECT project_id, SUM(hours_worked) as total_hours, AVG(hourly_wage) as avg_wage FROM labor GROUP BY project_id;
Find the average number of workers and their total wages for projects in New York with a sustainability rating greater than 0.8.
SELECT p.name, ls.total_hours, ls.avg_wage, ls.total_hours * ls.avg_wage as total_wages FROM project p INNER JOIN labor_summary ls ON p.id = ls.project_id WHERE p.location = 'New York' AND p.sustainability_rating > 0.8;
gretelai_synthetic_text_to_sql
CREATE TABLE financial_transactions (id INT, amount DECIMAL(10,2)); INSERT INTO financial_transactions (id, amount) VALUES (1, 500.00), (2, 250.00); CREATE TABLE volunteer_events (id INT, attendees INT); INSERT INTO volunteer_events (id, attendees) VALUES (1, 30), (2, 50);
What is the total number of financial transactions and volunteer management events in the database?
SELECT COUNT(*) FROM financial_transactions UNION ALL SELECT COUNT(*) FROM volunteer_events;
gretelai_synthetic_text_to_sql
CREATE TABLE SamariumProduction (country VARCHAR(20), year INT, quantity INT); INSERT INTO SamariumProduction (country, year, quantity) VALUES ('India', 2017, 80), ('India', 2018, 90);
What is the total production quantity of samarium in India for the year 2017?
SELECT SUM(quantity) FROM SamariumProduction WHERE country = 'India' AND year = 2017;
gretelai_synthetic_text_to_sql
CREATE TABLE DonorRank (DonorID int, DonationRank int, DonationAmount numeric); INSERT INTO DonorRank (DonorID, DonationRank, DonationAmount) VALUES (1, 1, 100), (2, 2, 200), (3, 3, 50), (4, 4, 75), (5, 5, 125), (6, 6, 150), (7, 7, 175), (8, 8, 200), (9, 9, 225), (10, 10, 250), (11, 11, 300);
What is the number of donations made by the top 10 donors?
SELECT DonorID, SUM(DonationAmount) FROM DonorRank WHERE DonationRank <= 10 GROUP BY DonorID;
gretelai_synthetic_text_to_sql
CREATE SCHEMA mental_health; USE mental_health; CREATE TABLE campaigns (campaign_id INT, country VARCHAR(50), launch_date DATE); INSERT INTO campaigns VALUES (1, 'US', '2008-01-01');
Which campaigns were launched in the US before 2010?
SELECT * FROM campaigns WHERE country = 'US' AND launch_date < '2010-01-01';
gretelai_synthetic_text_to_sql
CREATE TABLE donations(id INT, donor_name TEXT, donation_amount FLOAT, donation_date DATE); INSERT INTO donations(id, donor_name, donation_amount, donation_date) VALUES (1, 'James Lee', 50, '2022-11-29'), (2, 'Grace Kim', 100, '2022-12-01'), (3, 'Anthony Nguyen', 25, '2022-11-29');
What is the maximum donation amount given on Giving Tuesday?
SELECT MAX(donation_amount) FROM donations WHERE donation_date = '2022-11-29';
gretelai_synthetic_text_to_sql
CREATE TABLE facilities (facility_id INT, facility_type VARCHAR(20), state_abbr VARCHAR(2)); INSERT INTO facilities (facility_id, facility_type, state_abbr) VALUES (1, 'Public Health Clinic', 'CA'), (2, 'Hospital', 'CA'), (3, 'Public Health Clinic', 'NY');
What is the total number of public health facilities by state?
SELECT state_abbr, COUNT(*) as public_health_facilities FROM facilities WHERE facility_type = 'Public Health Clinic' GROUP BY state_abbr;
gretelai_synthetic_text_to_sql
CREATE TABLE Materials (material_id INT PRIMARY KEY, material VARCHAR(50), usage INT); INSERT INTO Materials (material_id, material, usage) VALUES (1, 'Organic Cotton', 500), (2, 'Recycled Polyester', 300), (3, 'Hemp', 100), (4, 'Tencel', 200);
What is the sustainable material with the least usage?
SELECT material FROM (SELECT material, MIN(usage) AS min_usage FROM Materials) AS least_used_materials;
gretelai_synthetic_text_to_sql
CREATE TABLE Performance (id INT PRIMARY KEY, name VARCHAR(50), artist VARCHAR(50), date DATE);
How many pieces in the 'Performance' table were created after '2020-01-01'?
SELECT COUNT(*) FROM Performance WHERE date > '2020-01-01';
gretelai_synthetic_text_to_sql
CREATE TABLE MakeupSales (sale_id INT, product_id INT, sale_price DECIMAL(5,2), sale_date DATE, is_cruelty_free BOOLEAN, is_vegan BOOLEAN); INSERT INTO MakeupSales (sale_id, product_id, sale_price, sale_date, is_cruelty_free, is_vegan) VALUES (1, 201, 24.99, '2022-01-10', true, true); CREATE TABLE ProductIngredients (ingredient_id INT, product_id INT, is_vegan BOOLEAN); INSERT INTO ProductIngredients (ingredient_id, product_id, is_vegan) VALUES (1, 201, true);
List all cruelty-free makeup products with vegan ingredients and their average sale price.
SELECT m.product_id, m.product_name, AVG(m.sale_price) FROM MakeupSales m JOIN ProductIngredients pi ON m.product_id = pi.product_id WHERE m.is_cruelty_free = true AND pi.is_vegan = true GROUP BY m.product_id;
gretelai_synthetic_text_to_sql
CREATE TABLE property (id INT, price FLOAT, type VARCHAR(20));
What is the maximum property price for each type of property?
SELECT type, MAX(price) FROM property GROUP BY type;
gretelai_synthetic_text_to_sql
CREATE TABLE Workouts (WorkoutID INT, MemberID INT, WorkoutType VARCHAR(20), Duration INT, Date DATE); INSERT INTO Workouts (WorkoutID, MemberID, WorkoutType, Duration, Date) VALUES (7, 1007, 'Zumba', 45, '2023-02-20'); INSERT INTO Workouts (WorkoutID, MemberID, WorkoutType, Duration, Date) VALUES (8, 1008, 'Boxing', 60, '2023-02-21');
SELECT MemberID, COUNT(*) as WorkoutCountThisWeek FROM Workouts WHERE Date >= DATE_TRUNC('week', CURRENT_DATE) GROUP BY MemberID ORDER BY WorkoutCountThisWeek DESC;
SELECT MemberID, WorkoutType, DATE_TRUNC('day', Date) as Day, AVG(Duration) as AverageDurationPerDay FROM Workouts GROUP BY MemberID, WorkoutType, Day ORDER BY Day DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE patients (id INT, name VARCHAR(50), treatment VARCHAR(50)); CREATE TABLE treatments (treatment VARCHAR(50), cost INT);
How many patients received each treatment type?
SELECT p.treatment, COUNT(p.treatment) AS num_patients FROM patients p GROUP BY p.treatment;
gretelai_synthetic_text_to_sql
CREATE TABLE mining_sites (id INT, name VARCHAR(50), location VARCHAR(50), extraction_rate DECIMAL(5,2)); INSERT INTO mining_sites (id, name, location, extraction_rate) VALUES (1, 'Gold Mine', 'California', 12.5), (2, 'Silver Mine', 'Nevada', 15.2), (3, 'Copper Mine', 'Arizona', 18.9), (4, 'Iron Mine', 'Minnesota', 21.1);
find the average extraction rate for mines in the mining_sites table, excluding the mines located in 'California'
SELECT AVG(extraction_rate) FROM mining_sites WHERE location != 'California';
gretelai_synthetic_text_to_sql
CREATE TABLE comedy_nights (id INT, visitor_id INT, visit_date DATE); CREATE TABLE poetry_slams (id INT, visitor_id INT, visit_date DATE);
Identify the number of unique visitors who attended both comedy nights and poetry slams in the same week.
SELECT COUNT(DISTINCT visitor_id) AS unique_visitors FROM comedy_nights INNER JOIN poetry_slams ON comedy_nights.visitor_id = poetry_slams.visitor_id AND WEEKOFYEAR(comedy_nights.visit_date) = WEEKOFYEAR(poetry_slams.visit_date);
gretelai_synthetic_text_to_sql
CREATE TABLE cosmetics_sales (product VARCHAR(255), country VARCHAR(255), sale_date DATE, revenue DECIMAL(10,2)); CREATE TABLE cosmetics (product VARCHAR(255), product_category VARCHAR(255), vegan BOOLEAN); CREATE TABLE countries (country VARCHAR(255), continent VARCHAR(255)); CREATE TABLE sale_records (product VARCHAR(255), country VARCHAR(255), sale_date DATE); INSERT INTO countries (country, continent) VALUES ('Brazil', 'South America'); CREATE VIEW q1_2023_sales AS SELECT * FROM sale_records WHERE sale_date BETWEEN '2023-01-01' AND '2023-03-31'; CREATE VIEW vegan_makeup AS SELECT * FROM cosmetics WHERE product_category = 'Makeup' AND vegan = true; CREATE VIEW vegan_brazil_sales AS SELECT * FROM q1_2023_sales JOIN vegan_makeup ON cosmetics.product = sale_records.product WHERE sale_records.country = 'Brazil';
Find the number of vegan makeup products sold in Brazil in Q1 2023.
SELECT COUNT(*) FROM vegan_brazil_sales;
gretelai_synthetic_text_to_sql
CREATE TABLE health_facilities (facility_id INT, name VARCHAR(50), type VARCHAR(50), population INT, city VARCHAR(50), state VARCHAR(50));
How many 'hospitals' are there in the 'health_facilities' table?
SELECT COUNT(*) FROM health_facilities WHERE type = 'hospital';
gretelai_synthetic_text_to_sql
CREATE TABLE Courses (CourseID INT, Name VARCHAR(50), OpenPedagogy BOOLEAN); INSERT INTO Courses (CourseID, Name, OpenPedagogy) VALUES (1, 'Introduction to Programming', true); INSERT INTO Courses (CourseID, Name, OpenPedagogy) VALUES (2, 'Calculus I', false); CREATE TABLE LifelongLearningEvents (EventID INT, CourseID INT, Name VARCHAR(50), Attendees INT); INSERT INTO LifelongLearningEvents (EventID, CourseID, Name, Attendees) VALUES (1, 1, 'Python for Data Science', 50); INSERT INTO LifelongLearningEvents (EventID, CourseID, Name, Attendees) VALUES (2, 2, 'Introduction to Open Pedagogy', 30);
List the names of courses that use open pedagogy and have more than 40 attendees in their lifelong learning events.
SELECT Courses.Name FROM Courses INNER JOIN LifelongLearningEvents ON Courses.CourseID = LifelongLearningEvents.CourseID WHERE Courses.OpenPedagogy = true AND LifelongLearningEvents.Attendees > 40;
gretelai_synthetic_text_to_sql
CREATE TABLE ice_thickness (id INT, year INT, thickness FLOAT); INSERT INTO ice_thickness (id, year, thickness) VALUES (1, 2005, 3.2), (2, 2015, 2.8);
List all ice thickness measurements in the 'ice_thickness' table older than 2010.
SELECT * FROM ice_thickness WHERE year < 2010;
gretelai_synthetic_text_to_sql
CREATE TABLE arctic_species (id INT, species_name TEXT, biomass INT); INSERT INTO arctic_species (id, species_name, biomass) VALUES (1, 'Beluga Whale', 1500), (2, 'Narwhal', 1200), (3, 'Greenland Shark', 800), (4, 'Bearded Seal', 500);
What is the total number of marine species with biomass data in the Arctic Ocean?
SELECT COUNT(*) FROM arctic_species WHERE biomass IS NOT NULL;
gretelai_synthetic_text_to_sql
CREATE TABLE renewable_energy_projects (project_id INT, project_name VARCHAR(255), location VARCHAR(255), total_investment INT, investment_type VARCHAR(255)); INSERT INTO renewable_energy_projects (project_id, project_name, location, total_investment, investment_type) VALUES (1, 'Renewable Energy Project A', 'California', 600000, 'Equity'); INSERT INTO renewable_energy_projects (project_id, project_name, location, total_investment, investment_type) VALUES (2, 'Renewable Energy Project B', 'Texas', 400000, 'Debt'); INSERT INTO renewable_energy_projects (project_id, project_name, location, total_investment, investment_type) VALUES (3, 'Renewable Energy Project C', 'Oklahoma', 700000, 'Equity'); INSERT INTO renewable_energy_projects (project_id, project_name, location, total_investment, investment_type) VALUES (4, 'Renewable Energy Project D', 'California', 800000, 'Equity');
List the renewable energy projects in California and their respective investment types, and the total number of renewable energy projects in California
SELECT * FROM renewable_energy_projects WHERE location = 'California'; SELECT COUNT(*) FROM renewable_energy_projects WHERE location = 'California';
gretelai_synthetic_text_to_sql
CREATE TABLE SpaceMissions (MissionID INT, Year INT, Country VARCHAR(50), SatelliteID INT); INSERT INTO SpaceMissions (MissionID, Year, Country, SatelliteID) VALUES (1, 2010, 'USA', 101), (2, 2012, 'Russia', 201), (3, 2015, 'China', 301), (4, 2018, 'India', 401), (5, 2020, 'Japan', 501);
Which countries have launched satellites in a specific year, based on the SpaceMissions table?
SELECT Country FROM SpaceMissions WHERE Year = 2015 GROUP BY Country HAVING COUNT(SatelliteID) > 0;
gretelai_synthetic_text_to_sql
CREATE TABLE products (id INT, name VARCHAR(255), price DECIMAL(10,2), supplier_id INT);
Find the total price of products supplied by each supplier, sorted by the total price in descending order.
SELECT supplier_id, SUM(price) AS total_price FROM products GROUP BY supplier_id ORDER BY total_price DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE events (id INT, title VARCHAR(50), event_type VARCHAR(50), city VARCHAR(50), tickets_sold INT); INSERT INTO events (id, title, event_type, city, tickets_sold) VALUES (1, 'Classical Music Concert', 'concert', 'New York', 1200); INSERT INTO events (id, title, event_type, city, tickets_sold) VALUES (2, 'Modern Art Exhibition', 'exhibition', 'New York', 1500); INSERT INTO events (id, title, event_type, city, tickets_sold) VALUES (3, 'Photography Workshop', 'workshop', 'New York', 800);
How many tickets were sold for each event type (concert, exhibition, workshop) at cultural centers in New York?
SELECT event_type, SUM(tickets_sold) FROM events WHERE city = 'New York' GROUP BY event_type;
gretelai_synthetic_text_to_sql
CREATE TABLE EndangeredLanguages (id INT, language VARCHAR(50), status VARCHAR(50)); INSERT INTO EndangeredLanguages (id, language, status) VALUES (1, 'Navajo', 'Vulnerable'); INSERT INTO EndangeredLanguages (id, language, status) VALUES (2, 'Cayuga', 'Critically Endangered');
What are the endangered languages in North America?
SELECT language FROM EndangeredLanguages WHERE EndangeredLanguages.status = 'Vulnerable' OR EndangeredLanguages.status = 'Endangered' OR EndangeredLanguages.status = 'Critically Endangered' AND EndangeredLanguages.country IN ('Canada', 'United States')
gretelai_synthetic_text_to_sql
CREATE TABLE countries (id INT, name TEXT); CREATE TABLE satellites (id INT, country_id INT, name TEXT, launch_date DATE, manufacturer TEXT); INSERT INTO countries (id, name) VALUES (1, 'USA'), (2, 'Russia'), (3, 'China'), (4, 'India'); INSERT INTO satellites (id, country_id, name, launch_date, manufacturer) VALUES (1, 1, 'Dragon', '2012-05-25', 'SpaceX'), (2, 1, 'Falcon', '2015-12-21', 'SpaceX'), (3, 2, 'Sputnik', '1957-10-04', 'Russia'), (4, 3, 'ChinaSat 1E', '2000-12-05', 'CAST'), (5, 4, 'EDUSAT', '2004-09-20', 'ISRO');
Which countries have launched satellites in the year 2000?
SELECT c.name FROM satellites s JOIN countries c ON s.country_id = c.id WHERE YEAR(s.launch_date) = 2000;
gretelai_synthetic_text_to_sql
CREATE TABLE Forests (id INT, name VARCHAR(255), hectares FLOAT, country VARCHAR(255)); INSERT INTO Forests (id, name, hectares, country) VALUES (1, 'Amazon Rainforest', 55000000.0, 'Brazil'); CREATE TABLE Wildlife (id INT, species VARCHAR(255), population INT, forest_id INT); INSERT INTO Wildlife (id, species, population, forest_id) VALUES (1, 'Jaguar', 15000, 1), (2, 'Toucan', 2500, 1);
What is the maximum and minimum population of a specific species in each forest?
SELECT Forests.name, Wildlife.species, MAX(Wildlife.population) as max_population, MIN(Wildlife.population) as min_population FROM Forests INNER JOIN Wildlife ON Forests.id = Wildlife.forest_id GROUP BY Forests.name, Wildlife.species;
gretelai_synthetic_text_to_sql
CREATE TABLE auto_shows_2023 (show_name VARCHAR(255), location VARCHAR(255), start_date DATE, end_date DATE);
Insert records for the 2023 Detroit and Tokyo Auto Shows
INSERT INTO auto_shows_2023 (show_name, location, start_date, end_date) VALUES ('Detroit Auto Show', 'Detroit', '2023-06-14', '2023-06-25'); INSERT INTO auto_shows_2023 (show_name, location, start_date, end_date) VALUES ('Tokyo Auto Show', 'Tokyo', '2023-11-01', '2023-11-12');
gretelai_synthetic_text_to_sql
CREATE TABLE Articles (id INT, publication DATE, newspaper VARCHAR(20)); INSERT INTO Articles (id, publication, newspaper) VALUES (1, '2022-01-01', 'NewYorkTimes'), (2, '2022-01-15', 'NewYorkTimes'), (3, '2022-02-01', 'NewYorkTimes');
How many news articles were published in the "NewYorkTimes" in January 2022?
SELECT COUNT(*) FROM Articles WHERE newspaper = 'NewYorkTimes' AND publication BETWEEN '2022-01-01' AND '2022-01-31';
gretelai_synthetic_text_to_sql
CREATE TABLE Donations (id INT, donor_id INT, country VARCHAR(20), artworks_donated INT); INSERT INTO Donations (id, donor_id, country, artworks_donated) VALUES (1, 1, 'India', 25), (2, 2, 'USA', 30), (3, 3, 'India', 45);
What is the total number of artworks donated by artists from India?
SELECT SUM(artworks_donated) FROM Donations WHERE country = 'India';
gretelai_synthetic_text_to_sql
CREATE TABLE building_permits (permit_id INT, building_type VARCHAR(20), state VARCHAR(20)); INSERT INTO building_permits (permit_id, building_type, state) VALUES (1, 'Residential', 'California'), (2, 'Commercial', 'California'), (3, 'Residential', 'Texas');
What is the total number of permits issued for residential buildings in the state of California?
SELECT COUNT(*) FROM building_permits WHERE building_type = 'Residential' AND state = 'California';
gretelai_synthetic_text_to_sql
CREATE TABLE patient_visits (country VARCHAR(20), clinic_name VARCHAR(50), patients_per_day INT); INSERT INTO patient_visits (country, clinic_name, patients_per_day) VALUES ('Russia', 'Clinic V', 50), ('Russia', 'Clinic W', 60), ('Ukraine', 'Clinic X', 70), ('Ukraine', 'Clinic Y', 80);
What is the average number of patients seen per day in rural health clinics in Russia and Ukraine?
SELECT country, AVG(patients_per_day) FROM patient_visits GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE marine_species (species_id INT, species_name VARCHAR(50), ocean_basin VARCHAR(50)); INSERT INTO marine_species (species_id, species_name, ocean_basin) VALUES (1, 'Blue Whale', 'Pacific'), (2, 'Green Sea Turtle', 'Atlantic'), (3, 'Giant Pacific Octopus', 'Pacific');
Identify the number of marine species in each ocean basin.
SELECT ocean_basin, COUNT(*) FROM marine_species GROUP BY ocean_basin;
gretelai_synthetic_text_to_sql
CREATE TABLE software (id INT, name VARCHAR(255)); INSERT INTO software (id, name) VALUES (1, 'Product A'), (2, 'Product B'); CREATE TABLE vulnerabilities (id INT, software_id INT, discovered_on DATE, severity VARCHAR(255)); INSERT INTO vulnerabilities (id, software_id, discovered_on, severity) VALUES (1, 1, '2022-01-01', 'High'), (2, 1, '2022-02-01', 'Medium'), (3, 2, '2022-03-01', 'Low');
Identify the most recent vulnerabilities for each software product.
SELECT software.name, vulnerabilities.id, vulnerabilities.severity, vulnerabilities.discovered_on FROM software LEFT JOIN (SELECT *, ROW_NUMBER() OVER (PARTITION BY software_id ORDER BY discovered_on DESC) rn FROM vulnerabilities) vulnerabilities ON software.id = vulnerabilities.software_id WHERE vulnerabilities.rn = 1;
gretelai_synthetic_text_to_sql