context
stringlengths
11
9.12k
question
stringlengths
0
1.06k
SQL
stringlengths
2
4.44k
source
stringclasses
28 values
CREATE TABLE exhibitions (id INT, name TEXT, start_date DATE, end_date DATE);
Update the exhibitions table with end dates for all exhibitions that started before 2022
UPDATE exhibitions SET end_date = DATE_SUB(start_date, INTERVAL 1 DAY) WHERE start_date < '2022-01-01';
gretelai_synthetic_text_to_sql
CREATE TABLE species (species_name TEXT, population INTEGER, region TEXT); INSERT INTO species (species_name, population, region) VALUES ('Green Sea Turtle', 1500, 'Pacific Ocean');
Update the population of the 'Green Sea Turtle' to 2000 in the 'species' table.
UPDATE species SET population = 2000 WHERE species_name = 'Green Sea Turtle';
gretelai_synthetic_text_to_sql
CREATE TABLE community_health_center (name TEXT, patient_id INTEGER, vaccine TEXT, age INTEGER); INSERT INTO community_health_center (name, patient_id, vaccine, age) VALUES ('Community health center A', 1, 'Pfizer', 45), ('Community health center A', 2, 'Pfizer', 50);
What is the average age of patients who received the Pfizer vaccine in community health center A?
SELECT AVG(age) FROM (SELECT * FROM community_health_center WHERE vaccine = 'Pfizer' AND name = 'Community health center A')
gretelai_synthetic_text_to_sql
CREATE TABLE AutonomousVehicles (id INT, company VARCHAR(20), vehicle_type VARCHAR(20), num_vehicles INT); INSERT INTO AutonomousVehicles (id, company, vehicle_type, num_vehicles) VALUES (1, 'Waymo', 'Self-Driving Car', 500), (2, 'Tesla', 'Autopilot Car', 800), (3, 'Cruise', 'Self-Driving Car', 300); CREATE TABLE ElectricVehicles (id INT, company VARCHAR(20), vehicle_type VARCHAR(20), num_vehicles INT); INSERT INTO ElectricVehicles (id, company, vehicle_type, num_vehicles) VALUES (1, 'Tesla', 'EV', 1500000), (2, 'Nissan', 'Leaf', 500000), (3, 'Chevrolet', 'Bolt', 300000);
Get the number of electric and autonomous vehicles for each company.
SELECT company, num_vehicles FROM AutonomousVehicles WHERE vehicle_type = 'Self-Driving Car' INTERSECT SELECT company, num_vehicles FROM ElectricVehicles WHERE vehicle_type = 'EV';
gretelai_synthetic_text_to_sql
CREATE TABLE Household_Water_Conservation (ID INT, City VARCHAR(20), Conserves_Water BOOLEAN); INSERT INTO Household_Water_Conservation (ID, City, Conserves_Water) VALUES (1, 'Seattle', FALSE), (2, 'Los Angeles', TRUE), (3, 'New York', TRUE), (4, 'Seattle', FALSE);
What is the percentage of households in the city of New York that conserve water?
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Household_Water_Conservation WHERE City = 'New York')) FROM Household_Water_Conservation WHERE City = 'New York' AND Conserves_Water = TRUE;
gretelai_synthetic_text_to_sql
CREATE TABLE if not exists national_security_incidents (region VARCHAR(50), year INT, incident_count INT);
How many national security incidents were recorded in the 'Asia-Pacific' region each year?
SELECT region, year, COUNT(incident_count) as total_incidents FROM national_security_incidents WHERE region = 'Asia-Pacific' GROUP BY region, year;
gretelai_synthetic_text_to_sql
CREATE TABLE CityBuildings (City VARCHAR(50), BuildingID INT, BuildingType VARCHAR(50), EnergyConsumption FLOAT, SquareFootage FLOAT); INSERT INTO CityBuildings (City, BuildingID, BuildingType, EnergyConsumption, SquareFootage) VALUES ('CityA', 1, 'Residential', 12000, 2000), ('CityB', 2, 'Commercial', 25000, 5000);
What is the average energy consumption per square foot for each city?
SELECT City, AVG(EnergyConsumption / SquareFootage) AS AvgEnergyConsumptionPerSqft FROM CityBuildings GROUP BY City;
gretelai_synthetic_text_to_sql
CREATE TABLE Products (ProductID INT, ProductName VARCHAR(50), IsOrganic BOOLEAN, Price INT); INSERT INTO Products (ProductID, ProductName, IsOrganic, Price) VALUES (1, 'Apple', true, 100), (2, 'Carrot', false, 80), (3, 'Banana', true, 120), (4, 'Potato', false, 90);
Find the average price (in USD) of organic products?
SELECT AVG(Price) FROM Products WHERE IsOrganic = true;
gretelai_synthetic_text_to_sql
CREATE TABLE countries (id INT, name TEXT, region TEXT); INSERT INTO countries (id, name, region) VALUES (1, 'Country A', 'Africa'), (2, 'Country B', 'Asia'), (3, 'Country C', 'Europe'); CREATE TABLE aid (id INT, country INT, amount FLOAT); INSERT INTO aid (id, country, amount) VALUES (1, 1, 500), (2, 2, 750), (3, 1, 250);
Which countries have received the most humanitarian aid in each region of the world?
SELECT c.name, c.region, SUM(a.amount) as total_aid FROM countries c JOIN aid a ON c.id = a.country GROUP BY c.name, c.region ORDER BY total_aid DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE people (person_id INT, city VARCHAR(20), water_consumption FLOAT, consumption_date DATE); INSERT INTO people (person_id, city, water_consumption, consumption_date) VALUES (1, 'Los Angeles', 100.0, '2021-01-01'), (2, 'Los Angeles', 120.0, '2021-02-01'), (3, 'Los Angeles', 110.0, '2021-03-01');
What is the average water consumption per person in the city of Los Angeles, calculated monthly?
SELECT city, AVG(water_consumption) FROM (SELECT city, person_id, AVG(water_consumption) AS water_consumption FROM people GROUP BY city, PERIOD_DIFF(consumption_date, DATE_FORMAT(consumption_date, '%Y%m')) * 100) AS monthly_consumption GROUP BY city;
gretelai_synthetic_text_to_sql
CREATE TABLE co_ownership (property_id INT, city VARCHAR(20), size INT); INSERT INTO co_ownership (property_id, city, size) VALUES (1, 'Vancouver', 1200), (2, 'Vancouver', 1500), (3, 'Toronto', 1800);
What is the average property size for co-ownership properties in Vancouver?
SELECT AVG(size) FROM co_ownership WHERE city = 'Vancouver' AND property_id IN (SELECT DISTINCT property_id FROM co_ownership WHERE co_ownership.city = 'Vancouver' AND co_ownership.property_id IS NOT NULL);
gretelai_synthetic_text_to_sql
CREATE TABLE Artists (ArtistID INT, Name VARCHAR(50), Age INT, Genre VARCHAR(50)); INSERT INTO Artists VALUES (1, 'John Doe', 35, 'Country'); INSERT INTO Artists VALUES (2, 'Jane Smith', 28, 'Pop'); CREATE TABLE Festivals (FestivalID INT, Name VARCHAR(50)); CREATE TABLE Performances (PerformanceID INT, ArtistID INT, FestivalID INT); INSERT INTO Festivals VALUES (1, 'Coachella'); INSERT INTO Festivals VALUES (2, 'Lollapalooza'); INSERT INTO Performances VALUES (1, 1, 1); INSERT INTO Performances VALUES (2, 2, 2);
What is the average age of all country musicians who have performed at music festivals?
SELECT AVG(A.Age) FROM Artists A INNER JOIN Performances P ON A.ArtistID = P.ArtistID INNER JOIN Festivals F ON P.FestivalID = F.FestivalID WHERE A.Genre = 'Country';
gretelai_synthetic_text_to_sql
CREATE TABLE icebergs (id INT, name VARCHAR(255), size_km2 FLOAT);
Find the number of icebergs in the Arctic ocean larger than 10 km²
SELECT COUNT(*) FROM icebergs WHERE size_km2 > 10 AND region = 'Arctic Ocean'
gretelai_synthetic_text_to_sql
CREATE TABLE co_ownership (property_id INT, size FLOAT, city VARCHAR(20)); INSERT INTO co_ownership (property_id, size, city) VALUES (1, 1200.0, 'Seattle'), (2, 1500.0, 'NYC'), (3, 1300.0, 'Oakland');
What is the average size of co-owned properties in Oakland?
SELECT AVG(size) FROM co_ownership WHERE city = 'Oakland';
gretelai_synthetic_text_to_sql
CREATE TABLE climate_adaptation (project_name VARCHAR(255), region VARCHAR(255), co2_reduction_tonnes INT); INSERT INTO climate_adaptation (project_name, region, co2_reduction_tonnes) VALUES ('Flood Prevention', 'North America', 1200); INSERT INTO climate_adaptation (project_name, region, co2_reduction_tonnes) VALUES ('Drought Management', 'North America', 1800);
What is the average CO2 emissions reduction for each climate adaptation project in North America?
SELECT region, AVG(co2_reduction_tonnes) as avg_co2_reduction FROM climate_adaptation WHERE region = 'North America' GROUP BY region;
gretelai_synthetic_text_to_sql
CREATE TABLE PrecisionAgriculture.HarvestYield (FieldID INT, Yield FLOAT, HarvestDate DATE);
Select the average yield from the "HarvestYield" table
SELECT AVG(Yield) FROM PrecisionAgriculture.HarvestYield;
gretelai_synthetic_text_to_sql
CREATE TABLE traditional_arts (id INT, name VARCHAR(255), expert VARCHAR(255), community VARCHAR(255)); INSERT INTO traditional_arts (id, name, expert, community) VALUES (1, 'Plains Indian Sign Language', 'Thomas Wissler', 'Native American'), (2, 'Navajo Weaving', 'D.Y. Begay', 'Native American');
Who are the traditional art experts in the 'traditional_arts' schema from the Native American community?
SELECT expert, community FROM traditional_arts.traditional_arts WHERE community = 'Native American';
gretelai_synthetic_text_to_sql
CREATE SCHEMA indigenous_systems;CREATE TABLE farmers (id INT, name VARCHAR(50), region VARCHAR(50));INSERT INTO indigenous_systems.farmers (id, name, region) VALUES (1, 'Farmer 1', 'Region A'), (2, 'Farmer 2', 'Region B'), (3, 'Farmer 3', 'Region A'), (4, 'Farmer 4', 'Region C');
How many indigenous farmers, categorized by region, are present in the 'indigenous_systems' schema?
SELECT region, COUNT(*) FROM indigenous_systems.farmers GROUP BY region;
gretelai_synthetic_text_to_sql
CREATE TABLE exhibitions (id INT PRIMARY KEY, name VARCHAR(25), visitors INT); CREATE VIEW top_exhibitions AS SELECT name, visitors FROM exhibitions ORDER BY visitors DESC LIMIT 3;
Add a new view to display the top 3 most visited exhibitions
CREATE VIEW top_exhibitions AS SELECT name, visitors FROM exhibitions ORDER BY visitors DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE economic_diversification (id INT, country VARCHAR(20), project_name VARCHAR(50), project_budget FLOAT); INSERT INTO economic_diversification (id, country, project_name, project_budget) VALUES (1, 'Bolivia', 'Eco-tourism', 80000.00), (2, 'Bolivia', 'Handicraft Production', 60000.00);
Delete all economic diversification projects in Bolivia with a budget less than 75000.00.
DELETE FROM economic_diversification WHERE country = 'Bolivia' AND project_budget < 75000.00;
gretelai_synthetic_text_to_sql
CREATE TABLE crops (id INT, name VARCHAR(50), yield INT, acrate DECIMAL(5,2), region VARCHAR(50), year INT); INSERT INTO crops (id, name, yield, acrate, region, year) VALUES (1, 'Corn', 200, 2.3, 'Atlantic', 2022), (2, 'Soybeans', 120, 2.2, 'Atlantic', 2022), (3, 'Wheat', 180, 2.5, 'Atlantic', 2022);
Determine the difference in yield between the highest and lowest yield crops in the Atlantic region in 2022.
SELECT MAX(yield) - MIN(yield) FROM crops WHERE region = 'Atlantic' AND year = 2022;
gretelai_synthetic_text_to_sql
CREATE TABLE Vessels (ID INT, Name VARCHAR(50), Type VARCHAR(50), Safety_Inspected INT, Engine_Capacity INT); INSERT INTO Vessels (ID, Name, Type, Safety_Inspected, Engine_Capacity) VALUES (1, 'MV Endeavour', 'Cargo Ship', 1, 3000), (2, 'MV Nautilus', 'Cargo Ship', 0, 1500);
Show the total number of vessels that have passed safety inspections and the number of vessels with engine capacities less than 2000, in a single result set?
SELECT COUNT(*) FROM Vessels WHERE Safety_Inspected = 1 UNION ALL SELECT COUNT(*) FROM Vessels WHERE Engine_Capacity < 2000;
gretelai_synthetic_text_to_sql
CREATE TABLE singapore_transportation (id INT, trip_id INT, mode VARCHAR(255), start_time TIMESTAMP, end_time TIMESTAMP); INSERT INTO singapore_transportation (id, trip_id, mode, start_time, end_time) VALUES (1, 555, 'MRT', '2022-01-01 07:30:00', '2022-01-01 07:45:00'); INSERT INTO singapore_transportation (id, trip_id, mode, start_time, end_time) VALUES (2, 666, 'Bus', '2022-01-01 08:00:00', '2022-01-01 08:15:00');
What is the minimum travel time for public transportation in Singapore and how many such trips are there?
SELECT MIN(TIMESTAMPDIFF(MINUTE, start_time, end_time)) as min_travel_time, COUNT(*) as num_trips FROM singapore_transportation;
gretelai_synthetic_text_to_sql
CREATE TABLE students (student_id INT, district_id INT); CREATE TABLE professional_development_courses (course_id INT, course_name VARCHAR(50), course_date DATE, district_id INT);
How many students in each school district have completed a professional development course in the past year?
SELECT sd.district_name, COUNT(DISTINCT s.student_id) FROM students s INNER JOIN school_districts sd ON s.district_id = sd.district_id INNER JOIN professional_development_courses pdc ON s.district_id = pdc.district_id WHERE pdc.course_date > DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY sd.district_name;
gretelai_synthetic_text_to_sql
CREATE TABLE certifications (certification_id INT, certification_date DATE, cruelty_free BOOLEAN); INSERT INTO certifications (certification_id, certification_date, cruelty_free) VALUES (1, '2022-01-01', true), (2, '2022-02-15', false), (3, '2022-03-20', true);
Number of cruelty-free certifications by month?
SELECT DATEPART(month, certification_date) as month, SUM(cruelty_free) as cruelty_free_certifications FROM certifications GROUP BY DATEPART(month, certification_date);
gretelai_synthetic_text_to_sql
CREATE TABLE drought_impact (id INT PRIMARY KEY, location VARCHAR(20), impact_level VARCHAR(10));
Insert new data into the 'drought_impact' table reflecting the drought conditions in 'Africa'
INSERT INTO drought_impact (id, location, impact_level) VALUES (1, 'Sahel', 'severe'), (2, 'Eastern Africa', 'moderate'), (3, 'Southern Africa', 'mild');
gretelai_synthetic_text_to_sql
CREATE TABLE ConservationInitiatives (id INT, state VARCHAR(20), initiative VARCHAR(20)); INSERT INTO ConservationInitiatives (id, state, initiative) VALUES (1, 'Texas', 'Rainwater Harvesting'), (2, 'Texas', 'Greywater Recycling'), (3, 'California', 'Drip Irrigation');
What is the number of water conservation initiatives in Texas?
SELECT COUNT(*) FROM ConservationInitiatives WHERE state = 'Texas';
gretelai_synthetic_text_to_sql
CREATE TABLE food_safety_inspections (restaurant_name VARCHAR(255), inspection_date DATE, score INT); INSERT INTO food_safety_inspections (restaurant_name, inspection_date, score) VALUES ('Pizza Palace', '2022-01-01', 85); INSERT INTO food_safety_inspections (restaurant_name, inspection_date, score) VALUES ('Pizza Palace', '2022-02-01', 65);
Delete food safety inspection records with a score lower than 70 for 'Pizza Palace' restaurant.
DELETE FROM food_safety_inspections WHERE restaurant_name = 'Pizza Palace' AND score < 70;
gretelai_synthetic_text_to_sql
CREATE TABLE athletes (id INT, name VARCHAR(50), age INT, sport VARCHAR(50), event VARCHAR(50)); INSERT INTO athletes (id, name, age, sport, event) VALUES (1, 'John Doe', 25, 'Football', 'Super Bowl'), (2, 'Jane Smith', 30, 'Basketball', 'NBA Finals'), (3, 'Richard Roe', 28, 'Football', 'Super Bowl'), (4, 'Jessica Brown', 27, 'Football', 'Super Bowl'), (5, 'Michael Green', 31, 'Basketball', 'NBA Finals');
List the names of athletes who have participated in football games but not basketball games.
SELECT name FROM athletes WHERE sport = 'Football' AND id NOT IN (SELECT id FROM athletes WHERE sport = 'Basketball');
gretelai_synthetic_text_to_sql
CREATE TABLE food_aid (id INT, country VARCHAR(255), year INT, amount INT); INSERT INTO food_aid (id, country, year, amount) VALUES (1, 'Iraq', 2021, 1000), (2, 'Iraq', 2022, 1200), (3, 'Colombia', 2021, 1500), (4, 'Colombia', 2022, 1800);
What is the total amount of food aid distributed in Iraq and Colombia in 2021 and 2022?
SELECT country, SUM(amount) FROM food_aid WHERE year IN (2021, 2022) GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE menus (id INT, name VARCHAR(255), category VARCHAR(255), price DECIMAL(5,2)); CREATE TABLE orders (id INT, menu_id INT, order_date DATETIME, location VARCHAR(255));
What is the total revenue for the 'Sustainable Seafood' category in the 'Downtown' location?
SELECT SUM(menus.price) FROM menus INNER JOIN orders ON menus.id = orders.menu_id WHERE menus.category = 'Sustainable Seafood' AND orders.location = 'Downtown';
gretelai_synthetic_text_to_sql
CREATE TABLE oceanic_habitats (habitat_type VARCHAR(50), size INT); INSERT INTO oceanic_habitats (habitat_type, size) VALUES ('Coral Reefs', 2500), ('Oceanic Islands', 5000), ('Open Ocean', 7000);
What is the percentage of the total habitat size for each habitat type in the Oceanic conservation programs?
SELECT habitat_type, size/SUM(size) as percentage FROM oceanic_habitats;
gretelai_synthetic_text_to_sql
CREATE TABLE shuttle_trips (trip_id INT, trip_start_time TIMESTAMP, trip_end_time TIMESTAMP, vehicle_type VARCHAR(10), passengers INT);
How many autonomous shuttle trips started between 7-9 AM for each day of the week?
SELECT EXTRACT(DOW FROM trip_start_time) AS day_of_week, COUNT(*) AS trips_count FROM shuttle_trips WHERE vehicle_type = 'Autonomous Shuttle' AND EXTRACT(HOUR FROM trip_start_time) BETWEEN 7 AND 9 GROUP BY day_of_week;
gretelai_synthetic_text_to_sql
CREATE TABLE products (product_id INT, segment VARCHAR(20), price DECIMAL(5,2)); INSERT INTO products (product_id, segment, price) VALUES (1, 'Natural', 15.99), (2, 'Organic', 22.99), (3, 'Natural', 12.49), (4, 'Organic', 18.99);
Which organic products have a price above the average for organic products?
SELECT * FROM products WHERE segment = 'Organic' AND price > (SELECT AVG(price) FROM products WHERE segment = 'Organic');
gretelai_synthetic_text_to_sql
CREATE TABLE nba_games (game_id INT, date DATE, home_team VARCHAR(50), away_team VARCHAR(50), home_score INT, away_score INT); INSERT INTO nba_games (game_id, date, home_team, away_team, home_score, away_score) VALUES (1, '2022-01-01', 'Los Angeles Lakers', 'Chicago Bulls', 123, 105);
What is the highest score in a single NBA game?
SELECT home_score FROM nba_games WHERE home_score > (SELECT away_score FROM nba_games WHERE home_team = (SELECT away_team FROM nba_games WHERE home_score = (SELECT MAX(home_score) FROM nba_games)) AND away_team = (SELECT home_team FROM nba_games WHERE home_score = (SELECT MAX(home_score) FROM nba_games)));
gretelai_synthetic_text_to_sql
CREATE TABLE social_impact_investments (id INT, category VARCHAR(50), transaction_value FLOAT); INSERT INTO social_impact_investments (id, category, transaction_value) VALUES (1, 'ESG1', 5000.0), (2, 'ESG2', 7000.0), (3, 'ESG1', 10000.0), (4, 'ESG3', 3000.0), (5, 'ESG2', 1500.0); CREATE TABLE esg_categories (id INT, category VARCHAR(50)); INSERT INTO esg_categories (id, category) VALUES (1, 'ESG1'), (2, 'ESG2'), (3, 'ESG3');
What is the minimum transaction value for social impact investments in a specific ESG category?
SELECT MIN(transaction_value) FROM social_impact_investments JOIN esg_categories ON social_impact_investments.category = esg_categories.category WHERE esg_categories.category = 'ESG1';
gretelai_synthetic_text_to_sql
CREATE TABLE virtual_tourism (id INT, country VARCHAR(50), num_sessions INT, session_date DATE, region VARCHAR(50)); INSERT INTO virtual_tourism (id, country, num_sessions, session_date, region) VALUES (1, 'USA', 2500, '2023-01-01', 'North America'), (2, 'Canada', 1800, '2023-01-02', 'North America'), (3, 'Australia', 3000, '2023-10-01', 'Oceania');
Find the top 2 countries with the most virtual tourism sessions in Q4 2023, excluding the 'Asia' region.
SELECT country, SUM(num_sessions) as total_sessions FROM virtual_tourism WHERE session_date BETWEEN '2023-10-01' AND '2023-12-31' AND region != 'Asia' GROUP BY country ORDER BY total_sessions DESC LIMIT 2;
gretelai_synthetic_text_to_sql
CREATE TABLE donors (id INT, name TEXT);CREATE TABLE donations (id INT, donor_id INT, amount DECIMAL, donation_date DATE);
Who are the top 5 donors by total donations in 2021 and 2022, and what is the total amount donated by each of them?
SELECT d.name, YEAR(donation_date) as year, SUM(donations.amount) as total_donations FROM donors d JOIN donations ON d.id = donations.donor_id WHERE YEAR(donation_date) IN (2021, 2022) GROUP BY d.id, year ORDER BY total_donations DESC, year DESC LIMIT 5;
gretelai_synthetic_text_to_sql
CREATE TABLE food_assistance (id INT, agency VARCHAR(255), country VARCHAR(255), amount DECIMAL(10, 2)); INSERT INTO food_assistance (id, agency, country, amount) VALUES ('1', 'WFP', 'Uganda', '700000'), ('2', 'UNHCR', 'Uganda', '800000'), ('3', 'FAO', 'Uganda', '600000'), ('4', 'WFP', 'Kenya', '900000'), ('5', 'UNHCR', 'Kenya', '500000'), ('6', 'FAO', 'Kenya', '400000');
What is the total amount of food assistance provided by UN agencies to refugees in Uganda and Kenya, grouped by agency?
SELECT agency, SUM(amount) as total_assistance FROM food_assistance WHERE country IN ('Uganda', 'Kenya') GROUP BY agency;
gretelai_synthetic_text_to_sql
CREATE TABLE military_transactions (id INT, country VARCHAR(255), year INT, technology VARCHAR(255)); INSERT INTO military_transactions (id, country, year, technology) VALUES (1, 'China', 2020, 'Drones'), (2, 'India', 2020, 'Cyber Warfare Systems');
Which military technologies were acquired by the Asian countries in 2020?
SELECT DISTINCT technology FROM military_transactions WHERE country IN ('China', 'India') AND year = 2020 AND technology IS NOT NULL;
gretelai_synthetic_text_to_sql
CREATE TABLE eco_hotels (hotel_id INT, name TEXT, city TEXT); INSERT INTO eco_hotels (hotel_id, name, city) VALUES (1, 'Green Hotel', 'Paris'), (3, 'Eco Retreat', 'Rome');
Update the name of the hotel with ID 3 to 'Sustainable Stay' in the eco_hotels table.
UPDATE eco_hotels SET name = 'Sustainable Stay' WHERE hotel_id = 3;
gretelai_synthetic_text_to_sql
CREATE TABLE Projects (region VARCHAR(20), project_name VARCHAR(50), project_cost INT); INSERT INTO Projects (region, project_name, project_cost) VALUES ('Northeast', 'Bridge Reconstruction', 5000000), ('Southeast', 'Road Expansion', 3000000), ('Midwest', 'Water Treatment Plant Upgrade', 6500000), ('Southwest', 'Dams Safety Improvement', 7500000), ('West', 'Transit System Modernization', 9000000);
What are the top 3 expensive projects across all regions?
SELECT project_name, project_cost FROM (SELECT project_name, project_cost, ROW_NUMBER() OVER (ORDER BY project_cost DESC) as rank FROM Projects) as ranked_projects WHERE rank <= 3;
gretelai_synthetic_text_to_sql
CREATE TABLE lifelong_learning (student_id INT, student_name VARCHAR(50), region VARCHAR(30), dropped_out BOOLEAN); INSERT INTO lifelong_learning (student_id, student_name, region, dropped_out) VALUES (1, 'John Doe', 'Northeast', true), (2, 'Jane Smith', 'Southeast', false);
How many students dropped out of lifelong learning programs in each region?
SELECT region, SUM(dropped_out) FROM lifelong_learning GROUP BY region;
gretelai_synthetic_text_to_sql
CREATE TABLE student_enrollment (state VARCHAR(20), disability VARCHAR(30), count INT); INSERT INTO student_enrollment (state, disability, count) VALUES ('California', 'Visual Impairment', 350); INSERT INTO student_enrollment (state, disability, count) VALUES ('California', 'Visual Impairment', 200);
How many students with visual impairments are enrolled in California schools?
SELECT SUM(count) FROM student_enrollment WHERE state = 'California' AND disability = 'Visual Impairment';
gretelai_synthetic_text_to_sql
CREATE TABLE marine_life (id INT, species_name VARCHAR(255));
Update the species name for all records in the MarineLife table where the species name is 'Unknown' to 'Not Identified'.
UPDATE marine_life SET species_name = 'Not Identified' WHERE species_name = 'Unknown';
gretelai_synthetic_text_to_sql
athlete_demographics
Delete the athlete demographics table
DROP TABLE IF EXISTS athlete_demographics;
gretelai_synthetic_text_to_sql
CREATE TABLE member_demographics (member_id INT, age INT, gender VARCHAR(10), city VARCHAR(50), state VARCHAR(20));
Add a new column 'country' to the 'member_demographics' table
ALTER TABLE member_demographics ADD country VARCHAR(50);
gretelai_synthetic_text_to_sql
CREATE TABLE debris_types (id INT, debris_type VARCHAR(50), quantity INT);
Find the top 5 most common types of space debris?
SELECT debris_type, quantity FROM (SELECT debris_type, quantity, RANK() OVER (ORDER BY quantity DESC) AS debris_rank FROM debris_types) AS subquery WHERE debris_rank <= 5;
gretelai_synthetic_text_to_sql
CREATE TABLE sales(product_id INT, sale_date DATE, revenue DECIMAL(10,2), country VARCHAR(50)); INSERT INTO sales VALUES (9, '2021-04-01', 60.00, 'CA'); INSERT INTO sales VALUES (10, '2021-05-01', 70.00, 'US'); CREATE TABLE products(product_id INT, product_name VARCHAR(50), is_natural BOOLEAN); INSERT INTO products VALUES (9, 'Green Tea Moisturizer', TRUE); INSERT INTO products VALUES (10, 'Retinol Cream', FALSE);
What is the monthly average revenue of natural skincare products in the North American market, for the past 12 months?
SELECT AVG(sales.revenue) as monthly_average_revenue FROM sales JOIN products ON sales.product_id = products.product_id WHERE products.is_natural = TRUE AND sales.country = 'North America' AND DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= sales.sale_date GROUP BY EXTRACT(YEAR_MONTH FROM sales.sale_date);
gretelai_synthetic_text_to_sql
CREATE TABLE org_staff (role VARCHAR(10), count INT); INSERT INTO org_staff (role, count) VALUES ('Volunteer', 30), ('Staff', 40);
What is the total number of volunteers and staff in the organization?
SELECT SUM(count) FROM org_staff;
gretelai_synthetic_text_to_sql
CREATE SCHEMA innovation; CREATE TABLE metrics (metric_name VARCHAR(50), metric_type VARCHAR(50)); INSERT INTO metrics (metric_name, metric_type) VALUES ('Crop Yield', 'Quantitative'), ('Cultural Acceptance', 'Qualitative'), ('Sustainability', 'Qualitative');
List all agricultural innovation metrics in the 'innovation' schema, along with their respective types.
SELECT metric_name, metric_type FROM innovation.metrics;
gretelai_synthetic_text_to_sql
CREATE TABLE green_building (property_id INT, certification VARCHAR(20)); INSERT INTO green_building (property_id, certification) VALUES (1, 'LEED'), (2, 'BREEAM');
What is the total number of properties with green building certifications?
SELECT COUNT(*) FROM green_building;
gretelai_synthetic_text_to_sql
CREATE TABLE strains (id INT PRIMARY KEY, name VARCHAR(255), type VARCHAR(255), cultivation_date DATE); CREATE TABLE sales (id INT PRIMARY KEY, strain_id INT, quantity INT, sale_date DATE);
What are the total sales for each strain type, excluding those with no sales, for the last month?
SELECT strains.type, SUM(sales.quantity) as total_sales FROM strains INNER JOIN sales ON strains.id = sales.strain_id WHERE sales.sale_date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) AND CURRENT_DATE GROUP BY strains.type HAVING total_sales > 0;
gretelai_synthetic_text_to_sql
CREATE TABLE fares (ride_type TEXT, fare DECIMAL(5,2));
Update the fare for 'Subway' rides
UPDATE fares SET fare = 1.50 WHERE ride_type = 'Subway';
gretelai_synthetic_text_to_sql
CREATE TABLE Donors (DonorID int, Name varchar(50), TotalDonation decimal(10,2), Country varchar(50)); INSERT INTO Donors (DonorID, Name, TotalDonation, Country) VALUES (1, 'John Doe', 500.00, 'Canada'), (2, 'Jane Smith', 800.00, 'United States'), (3, 'Alice Johnson', 1500.00, 'United States'), (4, 'Bob Brown', 1000.00, 'Canada');
What is the percentage of total donations received from donors in Canada?
SELECT (SUM(CASE WHEN Country = 'Canada' THEN TotalDonation ELSE 0 END) / SUM(TotalDonation)) * 100 as Percentage FROM Donors;
gretelai_synthetic_text_to_sql
CREATE TABLE bus_speed (id INT, type VARCHAR(20), city VARCHAR(20), speed INT); INSERT INTO bus_speed (id, type, city, speed) VALUES (1, 'electric', 'Mumbai', 40), (2, 'diesel', 'Mumbai', 30), (3, 'electric', 'New Delhi', 50), (4, 'diesel', 'New Delhi', 40);
What is the average speed of electric buses in Mumbai and New Delhi?
SELECT AVG(speed) FROM bus_speed WHERE type = 'electric' AND city IN ('Mumbai', 'New Delhi');
gretelai_synthetic_text_to_sql
CREATE TABLE policies_2 (policy_id INT, last_reviewed DATE); INSERT INTO policies_2 (policy_id, last_reviewed) VALUES (1, '2021-01-01'), (2, '2020-02-15'), (3, '2021-03-05');
Which policies have not been reviewed in the last year?
SELECT policy_id FROM policies_2 WHERE last_reviewed < DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR);
gretelai_synthetic_text_to_sql
CREATE TABLE Navy (id INT, name VARCHAR(50), rank VARCHAR(50), department VARCHAR(50)); INSERT INTO Navy (id, name, rank, department) VALUES (1, 'Alice Davis', 'Admiral', 'Navy'); INSERT INTO Navy (id, name, rank, department) VALUES (2, 'Bob Johnson', 'Commander', 'Navy');
What are the names and ranks of officers in the 'Navy' department?
SELECT name, rank FROM Navy WHERE department = 'Navy';
gretelai_synthetic_text_to_sql
CREATE TABLE Conservation_Grants ( id INT PRIMARY KEY, grant_name VARCHAR(50), organization VARCHAR(50), region VARCHAR(50), amount FLOAT); INSERT INTO Conservation_Grants (id, grant_name, organization, region, amount) VALUES (1, 'Coral Reef Restoration', 'Coral Guardian', 'Indian Ocean', 50000), (2, 'Seagrass Protection', 'Project Seagrass', 'Caribbean', 35000), (3, 'Pacific Reef Revival', 'Ocean Quest', 'Pacific', 20000), (4, 'Mangrove Conservation', 'Coastal Watch', 'Pacific', 45000), (5, 'Turtle Habitat Preservation', 'Sea Turtle Inc.', 'Pacific', 60000);
Identify the tertiles for conservation grants based on the grant amounts in the Pacific region.
SELECT grant_name, organization, region, amount, NTILE(3) OVER(PARTITION BY region ORDER BY amount DESC) as tertile FROM Conservation_Grants WHERE region = 'Pacific';
gretelai_synthetic_text_to_sql
CREATE TABLE donations (donation_id INT, donation_date DATE, amount DECIMAL(10,2), region TEXT); INSERT INTO donations (donation_id, donation_date, amount, region) VALUES (1, '2019-01-01', 1000.00, 'North America'), (2, '2019-02-01', 1500.00, 'Europe'), (3, '2019-03-01', 2000.00, 'Asia');
Which regions had the highest total donations in 2019?
SELECT region, SUM(amount) as total_donations FROM donations WHERE YEAR(donation_date) = 2019 GROUP BY region ORDER BY total_donations DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE startups (id INT, name VARCHAR(100), location VARCHAR(100), funding FLOAT); INSERT INTO startups (id, name, location, funding) VALUES (1, 'StartupA', 'France', 10000000); INSERT INTO startups (id, name, location, funding) VALUES (2, 'StartupB', 'France', 12000000);
What is the total funding received by biotech startups in France?
SELECT SUM(funding) FROM startups WHERE location = 'France';
gretelai_synthetic_text_to_sql
CREATE TABLE national_security_budgets (id INT, agency_name VARCHAR(255), budget DECIMAL(10,2), year INT); INSERT INTO national_security_budgets (id, agency_name, budget, year) VALUES (1, 'CIA', 50000000, 2010); INSERT INTO national_security_budgets (id, agency_name, budget, year) VALUES (2, 'FSB', 40000000, 2015);
What is the average budget for national security agencies in the Middle East in the last decade?
SELECT AVG(budget) AS avg_budget FROM national_security_budgets WHERE year BETWEEN 2010 AND 2020 AND agency_name IN ('Mossad', 'CIA', 'FSB', 'MI6', 'MoI');
gretelai_synthetic_text_to_sql
CREATE TABLE products (product_id INT, cruelty_free BOOLEAN, vegan BOOLEAN); INSERT INTO products VALUES (1, true, true), (2, false, false), (3, false, true), (4, true, false), (5, true, true), (6, false, true), (7, true, false), (8, false, false), (9, true, true), (10, false, false);
What percentage of cruelty-free products are also vegan?
SELECT (COUNT(p.cruelty_free AND p.vegan) * 100.0 / (SELECT COUNT(*) FROM products)) AS vegan_cruelty_free_percentage FROM products p;
gretelai_synthetic_text_to_sql
CREATE TABLE renewable_projects (name TEXT, country TEXT, type TEXT, co2_reduction_tons INT); INSERT INTO renewable_projects (name, country, type, co2_reduction_tons) VALUES ('Solar Farm X', 'USA', 'Solar', 15000), ('Wind Farm Y', 'Canada', 'Wind', 20000);
What is the total CO2 emissions reduction (in metric tons) achieved by renewable energy projects in the US and Canada, grouped by type?
SELECT type, SUM(co2_reduction_tons) FROM renewable_projects WHERE country IN ('USA', 'Canada') GROUP BY type;
gretelai_synthetic_text_to_sql
CREATE TABLE Departments (DepartmentID INT, DepartmentName VARCHAR(50), ManagerID INT); INSERT INTO Departments (DepartmentID, DepartmentName, ManagerID) VALUES (1, 'Mining', 101), (2, 'Engineering', 102), (3, 'Management', 103); CREATE TABLE Employees (EmployeeID INT, FirstName VARCHAR(50), LastName VARCHAR(50), DepartmentID INT, ManagerID INT); INSERT INTO Employees (EmployeeID, FirstName, LastName, DepartmentID) VALUES (1, 'John', 'Doe', 1), (2, 'Jane', 'Smith', 2), (3, 'Mike', 'Johnson', 1), (4, 'Sara', 'Lee', 2), (5, 'Alex', 'Anderson', 3);
How many employees work in the Engineering department?
SELECT COUNT(*) FROM Employees WHERE DepartmentID = (SELECT DepartmentID FROM Departments WHERE DepartmentName = 'Engineering');
gretelai_synthetic_text_to_sql
CREATE TABLE ArtWorks (ArtWorkID INT, Title VARCHAR(100), YearCreated INT, ArtistID INT, Medium VARCHAR(50), MuseumID INT);
Insert a new artwork
INSERT INTO ArtWorks (ArtWorkID, Title, YearCreated, ArtistID, Medium, MuseumID) VALUES (2, 'The Two Fridas', 1939, 2, 'Oil on canvas', 1);
gretelai_synthetic_text_to_sql
CREATE TABLE sustainability_ratings (country VARCHAR(20), rating DECIMAL(3,2)); INSERT INTO sustainability_ratings (country, rating) VALUES ('Bhutan', 9.2), ('Sweden', 9.0), ('Finland', 8.9), ('Norway', 8.8);
List the top 3 countries with the highest sustainable tourism ratings.
SELECT country, rating FROM sustainability_ratings ORDER BY rating DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE Tech_Social_Good (sector VARCHAR(50), initiative VARCHAR(50)); INSERT INTO Tech_Social_Good (sector, initiative) VALUES ('Healthcare', 'AI for Disease Diagnosis'), ('Education', 'Accessible Technology for Persons with Disabilities'), ('Community Development', 'Community Technology Centers'), ('Environment', 'Online Education Platforms for Sustainable Agriculture'), ('Government', 'Cybersecurity for Public Services');
What is the distribution of technology for social good initiatives by sector?
SELECT sector, COUNT(initiative) as num_initiatives FROM Tech_Social_Good GROUP BY sector;
gretelai_synthetic_text_to_sql
CREATE TABLE publications (id INT, title VARCHAR(100), year INT, citations INT); INSERT INTO publications (id, title, year, citations) VALUES (1, 'Publication 1', 2018, 5), (2, 'Publication 2', 2020, 15), (3, 'Publication 3', 2019, 8);
Delete the publication with ID 2.
DELETE FROM publications WHERE id = 2;
gretelai_synthetic_text_to_sql
CREATE TABLE Stores (id INT, name VARCHAR(255), region VARCHAR(255)); INSERT INTO Stores (id, name, region) VALUES (1, 'Store A', 'North'), (2, 'Store B', 'North'), (3, 'Store C', 'South'), (4, 'Store D', 'South'); CREATE TABLE Sales_By_Store (id INT, store_id INT, quarter INT, year INT, amount INT); INSERT INTO Sales_By_Store (id, store_id, quarter, year, amount) VALUES (1, 1, 1, 2021, 1000), (2, 2, 1, 2021, 1500), (3, 3, 1, 2021, 2000), (4, 4, 1, 2021, 2500);
What is the total sales amount for each store in the 'North' region in Q1 of 2021?
SELECT s.name, SUM(sb.amount) FROM Sales_By_Store sb JOIN Stores s ON sb.store_id = s.id WHERE sb.quarter = 1 AND sb.year = 2021 AND s.region = 'North' GROUP BY s.name;
gretelai_synthetic_text_to_sql
CREATE TABLE policies (id INT, type VARCHAR(10)); INSERT INTO policies (id, type) VALUES (1, 'auto');CREATE TABLE claims (id INT, policy_id INT, amount DECIMAL(10,2)); INSERT INTO claims (id, policy_id, amount) VALUES (1, 1, 5000), (2, 1, 3000)
What is the average claim amount for policies in the 'auto' category?
SELECT AVG(claims.amount) FROM claims JOIN policies ON claims.policy_id = policies.id WHERE policies.type = 'auto';
gretelai_synthetic_text_to_sql
CREATE TABLE Service_Request (id INT, city_id INT, service VARCHAR(50), status VARCHAR(20), date_created DATETIME); INSERT INTO Service_Request (id, city_id, service, status, date_created) VALUES (13, 1, 'Transportation', 'Open', '2022-05-01 10:00:00'), (14, 1, 'Utilities', 'Closed', '2022-04-15 14:30:00'), (15, 2, 'Transportation', 'Open', '2022-06-10 09:00:00'), (16, 2, 'Utilities', 'Open', '2022-05-25 16:00:00'), (17, 3, 'Transportation', 'Closed', '2022-04-01 10:00:00'), (18, 3, 'Utilities', 'Open', '2022-06-01 14:30:00');
How many open service requests are there in each city in the 'Transportation' service category?
SELECT C.name as city_name, SR.service, COUNT(*) as num_open_requests FROM City C INNER JOIN Service_Request SR ON C.id = SR.city_id WHERE SR.status = 'Open' AND SR.service LIKE '%Transportation%' GROUP BY C.name;
gretelai_synthetic_text_to_sql
CREATE TABLE mlb (team VARCHAR(255), game_id INT, home_attendance INT); INSERT INTO mlb (team, game_id, home_attendance) VALUES ('Yankees', 1, 30000), ('Yankees', 2, 31000), ('Mets', 1, 25000), ('Mets', 2, 26000);
What is the number of fans attending each team's home games in the 2020 MLB season?
SELECT team, SUM(home_attendance) FROM mlb GROUP BY team;
gretelai_synthetic_text_to_sql
CREATE TABLE carbon_offsets (project_id INT, country_name VARCHAR(50), carbon_offset INT); INSERT INTO carbon_offsets (project_id, country_name, carbon_offset) VALUES (1, 'Germany', 5000), (2, 'France', 7000), (3, 'Spain', 6000); CREATE TABLE eu_projects (project_id INT, project_name VARCHAR(100)); INSERT INTO eu_projects (project_id, project_name) VALUES (1, 'EU Project A'), (2, 'EU Project B'), (3, 'EU Project C');
What is the average carbon offset per project for renewable energy projects in the European Union?
SELECT AVG(carbon_offset) FROM carbon_offsets JOIN eu_projects ON carbon_offsets.project_id = eu_projects.project_id WHERE country_name IN ('Germany', 'France', 'Spain');
gretelai_synthetic_text_to_sql
CREATE TABLE LanguagePreservation (country VARCHAR(50), budget INT); INSERT INTO LanguagePreservation (country, budget) VALUES ('Nigeria', 50000), ('Kenya', 75000), ('Egypt', 60000), ('SouthAfrica', 80000), ('Ethiopia', 45000);
What is the average budget allocated for language preservation programs in African countries?
SELECT AVG(budget) FROM LanguagePreservation WHERE country IN ('Nigeria', 'Kenya', 'Egypt', 'SouthAfrica', 'Ethiopia') AND region = 'Africa';
gretelai_synthetic_text_to_sql
CREATE TABLE community_health_workers (worker_id INT, age INT, cultural_competency_score INT); INSERT INTO community_health_workers (worker_id, age, cultural_competency_score) VALUES (1, 35, 80), (2, 40, 85), (3, 45, 90), (4, 30, 95);
What is the minimum cultural competency score for community health workers in each age group?
SELECT age_group, MIN(cultural_competency_score) FROM (SELECT CASE WHEN age < 40 THEN 'Under 40' ELSE '40 and over' END AS age_group, cultural_competency_score FROM community_health_workers) AS subquery GROUP BY age_group;
gretelai_synthetic_text_to_sql
CREATE TABLE programs (id INT, name TEXT, location TEXT, budget INT); CREATE TABLE volunteer_hours (id INT, volunteer_id INT, program_id INT, hours INT); CREATE TABLE volunteers (id INT, name TEXT, email TEXT);
List all programs, their details, and the number of volunteers and total hours contributed to each program.
SELECT programs.name as program_name, programs.location as program_location, SUM(volunteer_hours.hours) as total_hours, COUNT(DISTINCT volunteers.id) as num_volunteers FROM programs LEFT JOIN volunteer_hours ON programs.id = volunteer_hours.program_id LEFT JOIN volunteers ON volunteer_hours.volunteer_id = volunteers.id GROUP BY programs.id;
gretelai_synthetic_text_to_sql
CREATE TABLE sustainable_practices (id INT PRIMARY KEY, hotel_id INT, practice VARCHAR(255)); INSERT INTO sustainable_practices (id, hotel_id, practice) VALUES (1, 1, 'Recycling program'); INSERT INTO sustainable_practices (id, hotel_id, practice) VALUES (2, 2, 'Solar power');
Delete the sustainable practice with an id of 1 in the sustainable_practices table
DELETE FROM sustainable_practices WHERE id = 1;
gretelai_synthetic_text_to_sql
CREATE TABLE satellites (id INT, name VARCHAR(255), country_of_origin VARCHAR(255), avg_distance FLOAT);
Update the country of origin of the satellite with ID 789 to "China".
UPDATE satellites SET country_of_origin = 'China' WHERE id = 789;
gretelai_synthetic_text_to_sql
CREATE TABLE donors (id INT, name VARCHAR(255)); CREATE TABLE donations (id INT, donor_id INT, amount DECIMAL(10, 2)); INSERT INTO donors (id, name) VALUES (1, 'John Doe'), (2, 'Jane Smith'); INSERT INTO donations (id, donor_id, amount) VALUES (1, 1, 500.00), (2, 1, 300.00), (3, 2, 250.00), (4, 2, 400.00);
What is the total donation amount for each donor?
SELECT d.donor_id, SUM(d.amount) FROM donations d GROUP BY d.donor_id;
gretelai_synthetic_text_to_sql
CREATE TABLE suppliers (id INT, supplier_name TEXT, country TEXT, last_inspection_date DATE); INSERT INTO suppliers (id, supplier_name, country, last_inspection_date) VALUES (1, 'Supplier 1', 'Japan', '2022-02-15'), (2, 'Supplier 2', 'Japan', '2021-08-28'), (3, 'Supplier 3', 'India', '2022-03-15');
List the names of chemical suppliers and their respective last inspection dates from Japan.
SELECT supplier_name, last_inspection_date FROM suppliers WHERE country = 'Japan';
gretelai_synthetic_text_to_sql
CREATE TABLE Astronauts (astronaut_name VARCHAR(30), age INT, first_mission_date DATE); INSERT INTO Astronauts (astronaut_name, age, first_mission_date) VALUES ('Astronaut1', 40, '2000-01-01');
What is the average age of astronauts during their first space mission?
SELECT AVG(age) FROM Astronauts WHERE first_mission_date = (SELECT MIN(first_mission_date) FROM Astronauts);
gretelai_synthetic_text_to_sql
CREATE TABLE species (id INT PRIMARY KEY, common_name VARCHAR(255), scientific_name VARCHAR(255), habitat TEXT);
delete all records from the species table where the scientific_name is 'Quercus robur'
DELETE FROM species WHERE scientific_name = 'Quercus robur';
gretelai_synthetic_text_to_sql
CREATE TABLE articles (author VARCHAR(50), article_title VARCHAR(100), publication_date DATE); INSERT INTO articles (author, article_title, publication_date) VALUES ('John Doe', 'Article 1', '2021-01-01'); INSERT INTO articles (author, article_title, publication_date) VALUES ('Jane Smith', 'Article 2', '2021-01-02');
What is the total number of articles by each author in the 'articles' table?
SELECT author, COUNT(*) as total_articles FROM articles GROUP BY author;
gretelai_synthetic_text_to_sql
CREATE TABLE SilkProduction (country VARCHAR(50), co2_emission INT); INSERT INTO SilkProduction VALUES ('China', 1200), ('India', 800), ('China', 1500), ('Japan', 500);
What is the total CO2 emission of silk production in China?
SELECT SUM(co2_emission) FROM SilkProduction WHERE country = 'China';
gretelai_synthetic_text_to_sql
CREATE TABLE users (id INT, country VARCHAR(255)); CREATE TABLE posts (id INT, user_id INT, content TEXT); INSERT INTO users (id, country) VALUES (1, 'Brazil'), (2, 'Brazil'), (3, 'Brazil'), (4, 'France'), (5, 'Germany'); INSERT INTO posts (id, user_id, content) VALUES (1, 1, 'Hello'), (2, 1, 'World'), (3, 2, 'AI'), (4, 2, 'Data'), (5, 3, 'Science');
Who are the top 5 users in Brazil by number of posts?
SELECT users.id, users.country, COUNT(posts.id) AS post_count FROM users JOIN posts ON users.id = posts.user_id WHERE users.country = 'Brazil' GROUP BY users.id ORDER BY post_count DESC LIMIT 5;
gretelai_synthetic_text_to_sql
CREATE TABLE property (id INT PRIMARY KEY, affordability_score INT);
Delete properties with affordability scores below 60
DELETE FROM property WHERE affordability_score < 60;
gretelai_synthetic_text_to_sql
CREATE TABLE soil_moisture (id INT, farm_id INT, moisture_level FLOAT, measurement_date DATE);
Delete all soil moisture data for farm_id 123
DELETE FROM soil_moisture WHERE farm_id = 123;
gretelai_synthetic_text_to_sql
CREATE TABLE Exhibitions (id INT, name VARCHAR(50), year INT, visitor_age INT);
What is the minimum age of visitors who attended the 'Classic Art' exhibition last year?
SELECT MIN(visitor_age) FROM Exhibitions WHERE name = 'Classic Art' AND year = 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE Sustainable_Projects (project_id INT, project_name VARCHAR(50), location VARCHAR(50), cost FLOAT); INSERT INTO Sustainable_Projects VALUES (9876, 'Solar Farm', 'Oregon', 12000000);
List all sustainable building projects in Oregon with a cost greater than $10 million.
SELECT project_id, project_name, location, cost FROM Sustainable_Projects WHERE location = 'Oregon' AND cost > 10000000;
gretelai_synthetic_text_to_sql
CREATE TABLE route_segments (segment_id INT, route_id INT, start_station VARCHAR(255), end_station VARCHAR(255), length FLOAT);CREATE TABLE fares (fare_id INT, route_id INT, segment_id INT, fare FLOAT);
What is the total revenue for each route segment in the NYC subway system?
SELECT rs.route_id, rs.segment_id, SUM(f.fare) as total_revenue FROM route_segments rs JOIN fares f ON rs.segment_id = f.segment_id GROUP BY rs.route_id, rs.segment_id;
gretelai_synthetic_text_to_sql
CREATE TABLE emergency_incidents (id INT, district VARCHAR(20), type VARCHAR(20), date DATE); INSERT INTO emergency_incidents (id, district, type, date) VALUES (1, 'Downtown', 'Fire', '2022-01-01'); INSERT INTO emergency_incidents (id, district, type, date) VALUES (2, 'Uptown', 'Medical', '2022-01-02'); INSERT INTO emergency_incidents (id, district, type, date) VALUES (3, 'North', 'Fire', '2022-01-03'); INSERT INTO emergency_incidents (id, district, type, date) VALUES (4, 'North', 'Medical', '2022-01-04'); INSERT INTO emergency_incidents (id, district, type, date) VALUES (5, 'Downtown', 'Medical', '2022-01-05'); INSERT INTO emergency_incidents (id, district, type, date) VALUES (6, 'Downtown', 'Fire', '2022-01-06');
What is the most common type of emergency in the Downtown district?
SELECT type, COUNT(*) AS count FROM emergency_incidents WHERE district = 'Downtown' GROUP BY type ORDER BY count DESC LIMIT 1;
gretelai_synthetic_text_to_sql
CREATE TABLE geological_data (id VARCHAR(10), location VARCHAR(50), rock_type VARCHAR(50), age VARCHAR(50));
Insert a new record into the 'geological_data' table with ID '001', location 'Alberta', rock_type 'Shale', age 'Devonian'
INSERT INTO geological_data (id, location, rock_type, age) VALUES ('001', 'Alberta', 'Shale', 'Devonian');
gretelai_synthetic_text_to_sql
CREATE TABLE Astronauts (astronaut_name TEXT, continent TEXT); INSERT INTO Astronauts (astronaut_name, continent) VALUES ('Serena Auñón-Chancellor', 'North America'), ('Alexander Gerst', 'Europe'), ('Reid Wiseman', 'North America'), ('Max Surayev', 'Europe'), ('Jeff Williams', 'North America');
What is the total number of astronauts from each continent?
SELECT continent, COUNT(*) as total_astronauts FROM Astronauts GROUP BY continent;
gretelai_synthetic_text_to_sql
CREATE TABLE client (client_id INT, name TEXT, country TEXT, financial_wellbeing_score INT); INSERT INTO client (client_id, name, country, financial_wellbeing_score) VALUES (14, 'Fatima Khalid', 'Pakistan', 70); CREATE VIEW pakistan_clients AS SELECT * FROM client WHERE country = 'Pakistan';
Update the financial wellbeing score for client with ID 14 to 82.
UPDATE client SET financial_wellbeing_score = 82 WHERE client_id = 14;
gretelai_synthetic_text_to_sql
CREATE TABLE waste_treatment_methods (id INT, name VARCHAR(255)); INSERT INTO waste_treatment_methods (id, name) VALUES (1, 'Landfill'), (2, 'Incineration'), (3, 'Recycling'); CREATE TABLE co2_emissions (treatment_method_id INT, emissions INT); INSERT INTO co2_emissions (treatment_method_id, emissions) VALUES (1, 100), (1, 120), (2, 80), (2, 100), (3, 60), (3, 70);
What is the total CO2 emissions for each waste treatment method?
SELECT wtm.name as treatment_method, SUM(ce.emissions) as total_emissions FROM waste_treatment_methods wtm JOIN co2_emissions ce ON wtm.id = ce.treatment_method_id GROUP BY wtm.name;
gretelai_synthetic_text_to_sql
CREATE TABLE nba_3pt (team TEXT, three_point_fg INT); INSERT INTO nba_3pt (team, three_point_fg) VALUES ('76ers', 13.1), ('Bucks', 12.8), ('Suns', 14.0);
What is the average number of three-point field goals made per game by each NBA team in the 2021-2022 season?
SELECT team, AVG(three_point_fg) as avg_three_point_fg FROM nba_3pt GROUP BY team;
gretelai_synthetic_text_to_sql
CREATE TABLE criminal_cases (case_id INT, case_type VARCHAR(255), disposition VARCHAR(255), year INT, court_id INT); INSERT INTO criminal_cases (case_id, case_type, disposition, year, court_id) VALUES (1, 'Assault', 'Guilty', 2020, 1), (2, 'Theft', 'Not Guilty', 2019, 1);
What is the number of criminal cases by type, disposition, and year, for a specific court?
SELECT case_type, disposition, year, COUNT(*) as num_cases FROM criminal_cases WHERE court_id = 1 GROUP BY case_type, disposition, year;
gretelai_synthetic_text_to_sql
CREATE TABLE assets (asset_id INT, asset_name VARCHAR(255), total_transactions INT);
What is the total number of transactions for each digital asset in the 'assets' table, sorted by the total transaction count in descending order?
SELECT asset_name, SUM(total_transactions) as total_transactions FROM assets GROUP BY asset_name ORDER BY total_transactions DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE canada_waste_rates (province VARCHAR(50), generation_rate NUMERIC(10,2), measurement_date DATE); INSERT INTO canada_waste_rates (province, generation_rate, measurement_date) VALUES ('Alberta', 1.35, '2022-02-28'), ('British Columbia', 0.99, '2022-02-28'), ('Ontario', 1.21, '2022-02-28');
Calculate the total waste generation rate for each province in Canada in the last quarter.
SELECT province, SUM(generation_rate) total_rate FROM canada_waste_rates WHERE measurement_date >= DATEADD(quarter, -1, CURRENT_DATE) GROUP BY province, ROW_NUMBER() OVER (PARTITION BY province ORDER BY measurement_date DESC);
gretelai_synthetic_text_to_sql