context
stringlengths
11
9.12k
question
stringlengths
0
1.06k
SQL
stringlengths
2
4.44k
source
stringclasses
28 values
CREATE TABLE wells (id INT, region VARCHAR(20), well_type VARCHAR(20)); INSERT INTO wells (id, region, well_type) VALUES (1, 'North Sea', 'Exploration'), (2, 'Gulf of Mexico', 'Production');
Determine the total number of wells drilled in the North Sea region
SELECT COUNT(*) FROM wells WHERE region = 'North Sea';
gretelai_synthetic_text_to_sql
CREATE TABLE electric_vehicles (id INT, make VARCHAR(50), range INT); INSERT INTO electric_vehicles (id, make, range) VALUES (1, 'Tesla', 350), (2, 'Tesla', 400), (3, 'Nissan', 250), (4, 'Nissan', 280), (5, 'Ford', 310), (6, 'Ford', NULL), (7, 'Chevy', 240);
Calculate the average range of electric vehicles for each make, excluding null values
SELECT make, AVG(range) as avg_range FROM electric_vehicles WHERE range IS NOT NULL GROUP BY make;
gretelai_synthetic_text_to_sql
CREATE TABLE auto_shows (show_name VARCHAR(255), year INT, location VARCHAR(255));
Delete all records in the 'auto_shows' table for the year 2023
DELETE FROM auto_shows WHERE year = 2023;
gretelai_synthetic_text_to_sql
CREATE TABLE Mines (MineID INT, MineType VARCHAR(20), ProductionCapacity INT); INSERT INTO Mines (MineID, MineType, ProductionCapacity) VALUES (1, 'Coal', 500000); INSERT INTO Mines (MineID, MineType, ProductionCapacity) VALUES (2, 'Gold', 200000);
What is the maximum production capacity of the African coal mines?
SELECT MAX(ProductionCapacity) FROM Mines WHERE MineType = 'Coal' AND Location LIKE 'Africa%';
gretelai_synthetic_text_to_sql
CREATE TABLE construction_workers (worker_id INT, name TEXT); CREATE TABLE project_types (project_id INT, project_type TEXT); CREATE TABLE worker_projects (worker_id INT, project_id INT, total_labor_hours INT); CREATE TABLE projects (project_id INT, city TEXT, state TEXT); INSERT INTO construction_workers (worker_id, n...
List the names and total labor hours of construction workers who have worked on sustainable building projects in New York City.
SELECT construction_workers.name, SUM(worker_projects.total_labor_hours) FROM construction_workers INNER JOIN worker_projects ON construction_workers.worker_id = worker_projects.worker_id INNER JOIN (SELECT DISTINCT project_id FROM projects INNER JOIN project_types ON projects.city = 'New York City' AND project_types.p...
gretelai_synthetic_text_to_sql
CREATE TABLE oil_prices (price_date DATE, oil_price NUMERIC(10,2)); INSERT INTO oil_prices (price_date, oil_price) VALUES ('2022-01-01', 70), ('2022-01-02', 72), ('2022-01-03', 75), ('2022-01-04', 78);
Find the daily change in oil price from the 'oil_prices' table.
SELECT price_date, oil_price, LAG(oil_price, 1) OVER (ORDER BY price_date) as prev_oil_price, oil_price - LAG(oil_price, 1) OVER (ORDER BY price_date) as daily_change FROM oil_prices;
gretelai_synthetic_text_to_sql
CREATE TABLE green_buildings (id INT, city VARCHAR(20), green_score INT); INSERT INTO green_buildings (id, city, green_score) VALUES (1, 'Boston', 85), (2, 'Philadelphia', 75), (3, 'Atlanta', 90);
What is the average 'green_score' in the 'green_buildings' table?
SELECT AVG(green_score) FROM green_buildings;
gretelai_synthetic_text_to_sql
CREATE TABLE transactions (transaction_id INT, transaction_type VARCHAR(20), transaction_amount DECIMAL(10,2), transaction_date DATE); INSERT INTO transactions (transaction_id, transaction_type, transaction_amount, transaction_date) VALUES (1, 'Withdrawal', 500.00, '2022-01-01');
What is the total transaction amount by transaction type for the first quarter of 2022?
SELECT SUM(transaction_amount), transaction_type FROM transactions WHERE transaction_date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY transaction_type;
gretelai_synthetic_text_to_sql
CREATE TABLE planting_records (record_id INT, user_id INT, crop_type VARCHAR(255), planting_date DATE);
Delete all planting records that are more than two years old.
DELETE pr FROM planting_records pr WHERE pr.planting_date < DATE_SUB(CURDATE(), INTERVAL 2 YEAR);
gretelai_synthetic_text_to_sql
CREATE TABLE vessel_inspections (id INT, vessel_id INT, region TEXT, inspection_date DATE); INSERT INTO vessel_inspections (id, vessel_id, region, inspection_date) VALUES (1, 1, 'Mediterranean', '2022-02-01'); INSERT INTO vessel_inspections (id, vessel_id, region, inspection_date) VALUES (2, 2, 'Mediterranean', '2022-0...
What is the latest safety inspection date for vessels in the 'Mediterranean'?
SELECT MAX(inspection_date) FROM vessel_inspections WHERE region = 'Mediterranean'
gretelai_synthetic_text_to_sql
CREATE TABLE community_development (country VARCHAR(50), quarter INT, score FLOAT); INSERT INTO community_development (country, quarter, score) VALUES ('Fiji', 3, 5.2), ('Samoa', 3, 7.5), ('Tonga', 3, 6.1), ('Vanuatu', 3, 4.9), ('Papua New Guinea', 3, 5.8), ('Solomon Islands', 3, 6.6);
What was the average community development initiative score for each country in the Pacific Islands in Q3 2017?
SELECT country, AVG(score) as avg_score FROM community_development WHERE quarter = 3 GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE Artists (id INT, name VARCHAR(100)); CREATE TABLE Users (id INT, name VARCHAR(100)); CREATE TABLE Streams (id INT, user_id INT, artist_id INT, minutes DECIMAL(10,2), year INT, city VARCHAR(50));
Find the number of unique users who streamed a given artist's music in a given year, grouped by city.
SELECT artist_id, city, COUNT(DISTINCT user_id) AS unique_users FROM Streams WHERE year = 2021 GROUP BY artist_id, city;
gretelai_synthetic_text_to_sql
CREATE TABLE Vessel (VesselID INT, Name VARCHAR(255), CarrierID INT, Type VARCHAR(255)); INSERT INTO Vessel (VesselID, Name, CarrierID, Type) VALUES (12, 'Independence', 10, 'Container Ship'); INSERT INTO Vessel (VesselID, Name, CarrierID, Type) VALUES (13, 'Liberty', 10, 'Container Ship'); INSERT INTO Vessel (VesselID...
Which vessels belonging to carriers from the United States have carried cargo weighing more than 15000 tons?
SELECT Vessel.Name FROM Vessel JOIN Cargo ON Vessel.VesselID = Cargo.VesselID JOIN Carrier ON Vessel.CarrierID = Carrier.CarrierID WHERE Cargo.Weight > 15000 AND Carrier.Country = 'United States';
gretelai_synthetic_text_to_sql
CREATE TABLE program (id INT, name VARCHAR(50), start_year INT, end_year INT); INSERT INTO program (id, name, start_year, end_year) VALUES (1, 'Green City Initiative', 2005, 2015), (2, 'Public Art Program', 2008, 2022), (3, 'Safe Streets', 2010, 2020), (4, 'Youth Mentorship', 2018, 2025);
What are the names and start years of the programs in the 'government_programs' database that started after 2015?
SELECT name, start_year FROM program WHERE start_year > 2015;
gretelai_synthetic_text_to_sql
CREATE TABLE DonorCategories (DonorID INT, Category TEXT); INSERT INTO DonorCategories (DonorID, Category) VALUES (1, 'Effective Altruism'), (2, 'Impact Investing'), (3, 'Effective Altruism'), (4, 'Impact Investing'), (5, 'Effective Altruism'), (6, 'Social Entrepreneurship');
Find the number of unique donors in each category?
SELECT Category, COUNT(DISTINCT DonorID) as UniqueDonors FROM DonorCategories GROUP BY Category;
gretelai_synthetic_text_to_sql
CREATE TABLE Family_Friendly_Exhibitions (id INT, city VARCHAR(255), year INT, visitor_age INT);
What is the minimum age of visitors who attended family-friendly exhibitions in London last year?
SELECT MIN(visitor_age) FROM Family_Friendly_Exhibitions WHERE city = 'London' AND year = 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE crimes (id INT, state VARCHAR(20), year INT, crime_type VARCHAR(20), num_crimes INT); INSERT INTO crimes (id, state, year, crime_type, num_crimes) VALUES (1, 'California', 2020, 'Theft', 2000), (2, 'California', 2020, 'Assault', 1500), (3, 'California', 2020, 'Vandalism', 1000);
Find the top 3 types of crimes with the most reports in the state of California in the year 2020.
SELECT crime_type, SUM(num_crimes) as total_crimes FROM crimes WHERE state = 'California' AND year = 2020 GROUP BY crime_type ORDER BY total_crimes DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE tourism (visitor_country VARCHAR(50), host_country VARCHAR(50), duration INT); INSERT INTO tourism (visitor_country, host_country, duration) VALUES ('United States', 'Egypt', 10), ('United States', 'Egypt', 14), ('Canada', 'Egypt', 12);
What is the average duration of stays in Egypt for tourists from the United States?
SELECT AVG(duration) FROM tourism WHERE visitor_country = 'United States' AND host_country = 'Egypt';
gretelai_synthetic_text_to_sql
CREATE TABLE game_genres (game_id INT, genre VARCHAR(20)); INSERT INTO game_genres (game_id, genre) VALUES (1, 'Action'), (2, 'Adventure'), (3, 'Strategy'), (4, 'Puzzle'); CREATE TABLE user_games (user_id INT, game_id INT, playtime INT); INSERT INTO user_games (user_id, game_id, playtime) VALUES (1, 1, 50), (1, 2, 20),...
How many players have played a game in each genre, and what is the average playtime per genre?
SELECT genre, COUNT(DISTINCT user_id) AS num_players, AVG(playtime) AS avg_playtime FROM user_games JOIN game_genres ON user_games.game_id = game_genres.game_id GROUP BY genre;
gretelai_synthetic_text_to_sql
CREATE TABLE tech_accessibility (id INT, name VARCHAR(50), accessibility_score DECIMAL(3,2)); INSERT INTO tech_accessibility (id, name, accessibility_score) VALUES (1, 'Tech1', 3.5); INSERT INTO tech_accessibility (id, name, accessibility_score) VALUES (2, 'Tech2', 2.8);
What is the name and accessibility score of the technology with the lowest accessibility score?
SELECT name, accessibility_score, RANK() OVER (ORDER BY accessibility_score) AS rank FROM tech_accessibility;
gretelai_synthetic_text_to_sql
CREATE TABLE movies(id INT PRIMARY KEY, name VARCHAR(255), budget INT);
get movies with budget greater than 150 million
SELECT name FROM movies WHERE budget > 150000000;
gretelai_synthetic_text_to_sql
CREATE TABLE mine (id INT, name TEXT, location TEXT); CREATE TABLE depletion (mine_id INT, date DATE, resource TEXT, quantity INT); INSERT INTO mine VALUES (1, 'Mine A', 'Country A'); INSERT INTO mine VALUES (2, 'Mine B', 'Country B'); INSERT INTO depletion VALUES (1, '2021-01-01', 'Gold', 100); INSERT INTO depletion V...
Determine the total amount of resources depleted by each mine, by resource type
SELECT mine.name, depletion.resource, SUM(depletion.quantity) AS total_depleted FROM mine INNER JOIN depletion ON mine.id = depletion.mine_id GROUP BY mine.name, depletion.resource;
gretelai_synthetic_text_to_sql
CREATE TABLE clinic_m (patient_id INT, cost INT, treatment VARCHAR(10)); INSERT INTO clinic_m (patient_id, cost, treatment) VALUES (25, 200, 'therapy'), (26, 100, 'medication');
What is the maximum cost of therapy for patients in 'clinic_m'?
SELECT MAX(cost) FROM clinic_m WHERE treatment = 'therapy';
gretelai_synthetic_text_to_sql
CREATE TABLE Hospitals (HospitalID INT, CulturalCompetencyScore DECIMAL(5,2), HospitalName VARCHAR(255), ReportDate DATE); INSERT INTO Hospitals (HospitalID, CulturalCompetencyScore, HospitalName, ReportDate) VALUES (1, 85.6, 'Johns Hopkins Hospital', '2022-06-01'); INSERT INTO Hospitals (HospitalID, CulturalCompetency...
What is the cultural competency score for each hospital in the last week?
SELECT ReportDate, CulturalCompetencyScore, HospitalName FROM Hospitals WHERE ReportDate >= DATEADD(week, -1, GETDATE());
gretelai_synthetic_text_to_sql
CREATE TABLE MilitaryOperations (ID INT, OperationYear INT, Country TEXT, Region TEXT); INSERT INTO MilitaryOperations (ID, OperationYear, Country, Region) VALUES (1, 2020, 'USA', 'Africa'), (2, 2021, 'France', 'Africa'), (3, 2019, 'UK', 'Europe');
Which countries have active military operations in Africa in 2021?
SELECT DISTINCT Country FROM MilitaryOperations WHERE OperationYear = 2021 AND Region = 'Africa';
gretelai_synthetic_text_to_sql
CREATE TABLE sustainable_sourcing (restaurant_id INT, rating INT); INSERT INTO sustainable_sourcing (restaurant_id, rating) VALUES (2, 95), (4, 90);
Add a new sustainable sourcing record for restaurant 4 with a rating of 90. Use the sustainable_sourcing table.
INSERT INTO sustainable_sourcing (restaurant_id, rating) VALUES (4, 90);
gretelai_synthetic_text_to_sql
CREATE TABLE building_efficiency (building_id INT, building_type VARCHAR(50), energy_efficiency_rating FLOAT); INSERT INTO building_efficiency (building_id, building_type, energy_efficiency_rating) VALUES (1, 'Residential', 70.0), (2, 'Industrial', 60.0), (3, 'Commercial', 65.0);
What is the minimum energy efficiency rating for industrial buildings in the 'building_efficiency' table?
SELECT MIN(energy_efficiency_rating) FROM building_efficiency WHERE building_type = 'Industrial';
gretelai_synthetic_text_to_sql
CREATE TABLE tourists (tourist_id INT, name TEXT, country TEXT, continent TEXT); INSERT INTO tourists (tourist_id, name, country, continent) VALUES (1, 'John Doe', 'USA', 'North America'), (2, 'Jane Smith', 'Brazil', 'South America'), (3, 'Minh Nguyen', 'Vietnam', 'Asia'), (4, 'Pierre Dupont', 'France', 'Europe'), (5, ...
What is the number of tourists visiting Japan from each continent?
SELECT continent, COUNT(DISTINCT country) FROM tourists WHERE country = 'Japan' GROUP BY continent;
gretelai_synthetic_text_to_sql
CREATE TABLE Satellites (satellite_id INT, deployment_year INT, cost FLOAT); INSERT INTO Satellites (satellite_id, deployment_year, cost) VALUES (1, 2022, 20000000.0), (2, 2021, 15000000.0);
What was the total cost of satellites deployed in 2022?
SELECT SUM(cost) FROM Satellites WHERE deployment_year = 2022;
gretelai_synthetic_text_to_sql
CREATE TABLE WorkplaceSafety (union_id INT, year INT, incidents INT); CREATE TABLE Unions (union_id INT, industry TEXT);
What is the total number of workplace incidents reported for each industry?
SELECT Unions.industry, SUM(WorkplaceSafety.incidents) FROM WorkplaceSafety INNER JOIN Unions ON WorkplaceSafety.union_id = Unions.union_id GROUP BY Unions.industry;
gretelai_synthetic_text_to_sql
CREATE TABLE startups (id INT, name VARCHAR(255), founding_year INT, industry VARCHAR(255), average_funding INT); INSERT INTO startups (id, name, founding_year, industry, average_funding) VALUES (1, 'Acme Inc', 2015, 'Tech', 500000), (2, 'Bravo Corp', 2017, 'Retail', 750000);
What is the average funding amount received by startups in the 'Tech' industry?
SELECT AVG(startups.average_funding) FROM startups WHERE startups.industry = 'Tech';
gretelai_synthetic_text_to_sql
CREATE TABLE weather_data (id INT, year INT, avg_temp FLOAT);
What is the average temperature recorded in the Arctic per year?
SELECT AVG(avg_temp) FROM weather_data GROUP BY year;
gretelai_synthetic_text_to_sql
CREATE TABLE manufacturers (id INT PRIMARY KEY, name TEXT, location TEXT, sustainability_score INT); CREATE TABLE products (id INT PRIMARY KEY, name TEXT, category TEXT, price DECIMAL, manufacturer_id INT, FOREIGN KEY (manufacturer_id) REFERENCES manufacturers(id));
What is the average price of products made by sustainable manufacturers?
SELECT AVG(p.price) FROM products p JOIN manufacturers m ON p.manufacturer_id = m.id WHERE m.sustainability_score >= 80;
gretelai_synthetic_text_to_sql
CREATE TABLE africa_attractions (id INT, name TEXT, country TEXT, sustainable BOOLEAN);
Display the names and types of all the attractions in Africa that are not yet sustainable.
SELECT name, type FROM africa_attractions WHERE sustainable = 'false';
gretelai_synthetic_text_to_sql
CREATE TABLE SupplierMaterials (SupplierName TEXT, Material TEXT); INSERT INTO SupplierMaterials (SupplierName, Material) VALUES ('FairTradeFashions', 'Silk'), ('FairTradeFashions', 'Wool'), ('EcoFriendlyFashions', 'Cotton'), ('EcoFriendlyFashions', 'Polyester');
Which materials are used by 'FairTradeFashions' but not by 'EcoFriendlyFashions'?
SELECT s1.SupplierName, s1.Material FROM SupplierMaterials s1 LEFT JOIN SupplierMaterials s2 ON s1.Material = s2.Material AND s2.SupplierName = 'EcoFriendlyFashions' WHERE s2.SupplierName IS NULL AND s1.SupplierName = 'FairTradeFashions';
gretelai_synthetic_text_to_sql
CREATE TABLE marine_protected_areas (id INT, name TEXT, location TEXT, size FLOAT); INSERT INTO marine_protected_areas (id, name, location, size) VALUES (1, 'Atlantic MPAs', 'Atlantic Ocean', 1500.0), (2, 'Pacific MPAs', 'Pacific Ocean', 1200.5), (3, 'Caribbean MPAs', 'Atlantic Ocean', 800.3);
How many marine protected areas (MPAs) are there in the Atlantic Ocean that are larger than 1000 square kilometers?
SELECT COUNT(*) FROM marine_protected_areas WHERE location = 'Atlantic Ocean' AND size > 1000;
gretelai_synthetic_text_to_sql
CREATE TABLE Donors (DonorID INT, DonorName TEXT, TotalDonation DECIMAL); INSERT INTO Donors (DonorID, DonorName, TotalDonation) VALUES (1, 'John Doe', 500.00), (2, 'Jane Smith', 350.00), (3, 'Bob Johnson', 700.00), (4, 'Alice Davis', 200.00), (5, 'Charlie Brown', 800.00), (6, 'David Williams', 100.00);
Who are the top 3 donors by total donation?
SELECT DonorName, TotalDonation FROM (SELECT DonorName, TotalDonation, ROW_NUMBER() OVER (ORDER BY TotalDonation DESC) AS Rank FROM Donors) AS SubQuery WHERE Rank <= 3;
gretelai_synthetic_text_to_sql
CREATE TABLE if not exists labor_violations (id INT PRIMARY KEY, industry VARCHAR(255), violation_date DATE); INSERT INTO labor_violations (id, industry, violation_date) VALUES (1, 'construction', '2022-01-05'), (2, 'construction', '2022-02-10'), (3, 'manufacturing', '2022-03-15');
How many labor rights violations occurred in the 'construction' industry in the last 6 months?
SELECT COUNT(*) FROM labor_violations WHERE industry = 'construction' AND violation_date >= DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH);
gretelai_synthetic_text_to_sql
CREATE TABLE SecurityIncidents (id INT, department VARCHAR(255), incident_start_date DATE, incident_end_date DATE, incident_type VARCHAR(255)); INSERT INTO SecurityIncidents (id, department, incident_start_date, incident_end_date, incident_type) VALUES (1, 'IT', '2022-01-01', '2022-01-05', 'Phishing');
What is the average duration of security incidents for each department, only showing departments with more than 15 incidents?
SELECT department, AVG(DATEDIFF(incident_end_date, incident_start_date)) as avg_duration FROM SecurityIncidents GROUP BY department HAVING COUNT(*) > 15;
gretelai_synthetic_text_to_sql
CREATE TABLE MetroLines (LineID int, Passengers int); INSERT INTO MetroLines (LineID, Passengers) VALUES (1, 1000), (2, 800), (3, 800);
Which metro lines in Barcelona have the least number of passengers?
SELECT LineID, MIN(Passengers) FROM MetroLines;
gretelai_synthetic_text_to_sql
CREATE TABLE WastewaterTreatmentFacilities (FacilityID INT, FacilityName VARCHAR(255), Address VARCHAR(255), City VARCHAR(255), State VARCHAR(255), ZipCode VARCHAR(10)); INSERT INTO WastewaterTreatmentFacilities (FacilityID, FacilityName, Address, City, State, ZipCode) VALUES (1, 'Blue Ridge Wastewater Treatment Plant'...
What is the cumulative water usage for the Blue Ridge Wastewater Treatment Plant up to a specific date?
SELECT UsageID, SUM(TotalGallons) OVER (ORDER BY UsageDate) FROM WaterUsage WHERE FacilityID = 1;
gretelai_synthetic_text_to_sql
CREATE TABLE security_incidents (id INT, incident_date DATE);
What is the maximum number of security incidents in a single day in the last month?
SELECT MAX(COUNT(*)) FROM security_incidents WHERE incident_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY DATE(incident_date);
gretelai_synthetic_text_to_sql
CREATE TABLE network_security_policies (policy_id INT, department VARCHAR(255), policy_name VARCHAR(255), policy_strength VARCHAR(255));
Insert a new network security policy for the IT department with a policy strength of high.
INSERT INTO network_security_policies (policy_id, department, policy_name, policy_strength) VALUES (1, 'IT', 'Example Network Security Policy', 'High');
gretelai_synthetic_text_to_sql
CREATE TABLE policies(id INT, date DATE, region VARCHAR(50), policy_type VARCHAR(50), policy_id VARCHAR(50)); INSERT INTO policies(id, date, region, policy_type, policy_id) VALUES (1, '2021-01-01', 'Europe', 'access_control', 'POL-2021-01'), (2, '2021-01-02', 'Europe', 'security_management', 'POL-2021-02');
What is the daily count and average number of access control policies in Europe?
SELECT date, COUNT(*) as total_policies, AVG(policy_type = 'access_control'::int) as avg_access_control FROM policies WHERE region = 'Europe' GROUP BY date ORDER BY date;
gretelai_synthetic_text_to_sql
CREATE TABLE Sales (sale_id INT, sale_date DATE, sale_amount FLOAT, product_material VARCHAR(50));
What is the total revenue generated from recycled material products for the current year?
SELECT SUM(Sales.sale_amount) as total_revenue FROM Sales WHERE EXTRACT(YEAR FROM Sales.sale_date) = EXTRACT(YEAR FROM CURRENT_DATE) AND Sales.product_material LIKE '%recycled%';
gretelai_synthetic_text_to_sql
CREATE TABLE programs (id INT, name VARCHAR(255));CREATE TABLE officers (id INT, program_id INT, assigned BOOLEAN);
How many police officers are assigned to each community policing program?
SELECT p.name, COUNT(o.id) FROM programs p INNER JOIN officers o ON p.id = o.program_id WHERE o.assigned = TRUE GROUP BY p.name;
gretelai_synthetic_text_to_sql
CREATE TABLE agri_investment (country TEXT, year INT, investment_amount NUMERIC); INSERT INTO agri_investment (country, year, investment_amount) VALUES ('Indonesia', 2017, 1000000), ('Indonesia', 2018, 1250000), ('Indonesia', 2019, 1500000), ('Indonesia', 2020, 1750000), ('Indonesia', 2021, 2000000);
What was the total agricultural innovation investment in Indonesia, in descending order of investment amount?
SELECT year, SUM(investment_amount) OVER (ORDER BY SUM(investment_amount) DESC) AS total_investment FROM agri_investment WHERE country = 'Indonesia' GROUP BY year ORDER BY total_investment DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE venture (id INT, name VARCHAR(255), sector VARCHAR(255), founding_date DATE, founder_lgbtq BOOLEAN); INSERT INTO venture (id, name, sector, founding_date, founder_lgbtq) VALUES (1, 'Echo Inc', 'Technology', '2010-01-01', FALSE); INSERT INTO venture (id, name, sector, founding_date, founder_lgbtq) VALUES (2...
How many startups were founded by individuals from the LGBTQ+ community in the retail sector before 2018?
SELECT COUNT(*) FROM venture WHERE sector = 'Retail' AND founding_date < '2018-01-01' AND founder_lgbtq = TRUE;
gretelai_synthetic_text_to_sql
CREATE TABLE policies (policy_number INT, policyholder_name TEXT, issue_date DATE, state TEXT, phone_number TEXT); INSERT INTO policies (policy_number, policyholder_name, issue_date, state, phone_number) VALUES (12345, 'John Doe', '2021-06-01', 'California', '555-555-5555'); INSERT INTO policies (policy_number, policyh...
What is the name and phone number of policyholders in New York?
SELECT policyholder_name, phone_number FROM policies WHERE state = 'New York';
gretelai_synthetic_text_to_sql
CREATE TABLE Astronauts (AstronautID INT, Name VARCHAR(50), Nationality VARCHAR(50), FirstFlightDate DATE); INSERT INTO Astronauts (AstronautID, Name, Nationality, FirstFlightDate) VALUES (1, 'Sergei Krikalev', 'Russia', '1988-05-30'); INSERT INTO Astronauts (AstronautID, Name, Nationality, FirstFlightDate) VALUES (2, ...
Display the average age of astronauts from each country at the time of their first spaceflight.
SELECT Nationality, AVG(DATEDIFF(day, BirthDate, FirstFlightDate)) / 365.25 AS AvgAgeAtFirstFlight FROM (SELECT AstronautID, Name, Nationality, BirthDate, MIN(FirstFlightDate) OVER (PARTITION BY AstronautID) FirstFlightDate FROM Astronauts) t GROUP BY Nationality;
gretelai_synthetic_text_to_sql
CREATE TABLE customers (customer_id INT, name VARCHAR(50), region VARCHAR(50)); INSERT INTO customers (customer_id, name, region) VALUES (1, 'James Johnson', 'North America'); INSERT INTO customers (customer_id, name, region) VALUES (2, 'Sophia Rodriguez', 'South America'); CREATE TABLE transactions (transaction_id INT...
Find the average transaction value for the 'North America' region.
SELECT AVG(transaction_value) FROM transactions JOIN customers ON transactions.customer_id = customers.customer_id WHERE customers.region = 'North America';
gretelai_synthetic_text_to_sql
CREATE TABLE DefenseDiplomacy (ID INT, EventName TEXT, EventDate DATE, ParticipatingCountries TEXT); INSERT INTO DefenseDiplomacy VALUES (1, 'Event 1', '2018-01-01', 'USA, Canada, UK'); CREATE VIEW NATO AS SELECT Country FROM DefenseDiplomacy WHERE Country IN ('USA', 'Canada', 'UK', 'France', 'Germany');
List all defense diplomacy events that have taken place in the North Atlantic Treaty Organization (NATO) countries in the last 5 years, along with the number of participating countries.
SELECT EventName, ParticipatingCountries, COUNT(DISTINCT SUBSTRING_INDEX(ParticipatingCountries, ',', n)) as NumberOfCountries FROM DefenseDiplomacy d CROSS JOIN (SELECT numbers.N FROM (SELECT 1 as N UNION ALL SELECT 2 UNION ALL SELECT 3) numbers) n JOIN NATO nato ON FIND_IN_SET(nato.Country, ParticipatingCountries) > ...
gretelai_synthetic_text_to_sql
CREATE TABLE Hospitals (name TEXT, location TEXT, type TEXT, num_beds INTEGER, state TEXT); INSERT INTO Hospitals (name, location, type, num_beds, state) VALUES ('Hospital A', 'City A, Rural West', 'General', 250, 'Rural West'), ('Hospital B', 'City B, Rural West', 'Specialty', 125, 'Rural West');
What is the minimum number of hospital beds per state in Rural West?
SELECT state, MIN(num_beds) as min_beds FROM Hospitals WHERE state IN ('Rural West', 'Rural West') GROUP BY state;
gretelai_synthetic_text_to_sql
CREATE TABLE basin_production (basin VARCHAR(50), year INT, oil_production FLOAT, gas_production FLOAT); INSERT INTO basin_production (basin, year, oil_production, gas_production) VALUES ('Permian', 2015, 1234.5, 678.9); INSERT INTO basin_production (basin, year, oil_production, gas_production) VALUES ('Permian', 2016,...
What was the total oil production in the Permian Basin in 2017?
SELECT SUM(oil_production) as total_oil_production FROM basin_production WHERE basin = 'Permian' AND year = 2017;
gretelai_synthetic_text_to_sql
CREATE TABLE production (country VARCHAR(255), element VARCHAR(255), amount INT, year INT); INSERT INTO production (country, element, amount, year) VALUES ('China', 'Dysprosium', 12000, 2019), ('Malaysia', 'Dysprosium', 2000, 2019), ('United States', 'Dysprosium', 3000, 2019); CREATE TABLE price (element VARCHAR(255), ...
List the top 3 producing countries of Dysprosium in 2019, ordered by production amount.
SELECT country, SUM(amount) as total_production FROM production WHERE element = 'Dysprosium' AND year = 2019 GROUP BY country ORDER BY total_production DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE Workouts (WorkoutID INT, MemberID INT, Duration INT, MembershipType VARCHAR(20));
Update the 'Workouts' table to increase the duration of workouts by 5% for members with a 'Basic' membership type
UPDATE Workouts w SET Duration = w.Duration * 1.05 WHERE w.MemberID IN (SELECT m.MemberID FROM Members m WHERE m.MembershipType = 'Basic');
gretelai_synthetic_text_to_sql
CREATE TABLE dispensaries (id INT, name TEXT, state TEXT, license_expiry DATE); INSERT INTO dispensaries (id, name, state, license_expiry) VALUES (1, 'Dispensary C', 'Colorado', '2023-05-01');
How many dispensaries exist in Colorado with a valid license in 2023?
SELECT COUNT(*) as num_dispensaries FROM dispensaries WHERE state = 'Colorado' AND license_expiry >= '2023-01-01';
gretelai_synthetic_text_to_sql
CREATE TABLE newspapers (id INT, name VARCHAR(255), country VARCHAR(255));CREATE TABLE readership (id INT, newspaper_id INT, age_group VARCHAR(255), year INT); INSERT INTO newspapers (id, name, country) VALUES (1, 'New York Times', 'USA'); INSERT INTO readership (id, newspaper_id, age_group, year) VALUES (1, 1, '25-34'...
Which newspapers were most popular among 25-34 year olds in the US in 2021?
SELECT newspapers.name FROM newspapers INNER JOIN readership ON newspapers.id = readership.newspaper_id WHERE readership.age_group = '25-34' AND readership.year = 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE workers (id INT, name TEXT, industry TEXT, union_member BOOLEAN, salary REAL); INSERT INTO workers (id, name, industry, union_member, salary) VALUES (1, 'John Doe', 'construction', true, 60000.00), (2, 'Jane Smith', 'retail', false, 35000.00);
Which industries have the lowest average salary for union members, compared to non-union members?
SELECT industry, AVG(salary) FROM workers WHERE union_member = true GROUP BY industry HAVING AVG(salary) < (SELECT AVG(salary) FROM workers WHERE union_member = false AND industry = workers.industry);
gretelai_synthetic_text_to_sql
CREATE TABLE artists (id INT, name TEXT, city TEXT, country TEXT);CREATE TABLE art_pieces (id INT, title TEXT, medium TEXT, artist_id INT);
What are the top 3 most popular art mediums in each city?
SELECT a.city, ap.medium, COUNT(ap.id) as num_pieces, RANK() OVER (PARTITION BY a.city ORDER BY COUNT(ap.id) DESC) as rank FROM artists a JOIN art_pieces ap ON a.id = ap.artist_id GROUP BY a.city, ap.medium HAVING rank <= 3;
gretelai_synthetic_text_to_sql
CREATE TABLE CustomerReturns2(id INT, customer_name VARCHAR(50), returned_items INT); INSERT INTO CustomerReturns2(id, customer_name, returned_items) VALUES (1, 'Greg Black', 1), (2, 'Heidi Green', 0);
Who are the customers with the lowest number of returned items?
SELECT customer_name, returned_items FROM CustomerReturns2 ORDER BY returned_items ASC;
gretelai_synthetic_text_to_sql
CREATE TABLE if not exists events (id INT, name VARCHAR(255), region VARCHAR(255), attendance INT); INSERT INTO events (id, name, region, attendance) VALUES (1, 'Ballet', 'Northeast', 200), (2, 'Tango', 'Southwest', 150), (3, 'Salsa', 'Southeast', 250), (4, 'Hip Hop', 'Northwest', 120);
Which region had the highest total attendance at dance events?
SELECT region, MAX(attendance) FROM events WHERE name LIKE '%dance%';
gretelai_synthetic_text_to_sql
CREATE TABLE Flights (Airline VARCHAR(255), ArrivalTime TIME);
What is the average arrival time of flights for each airline?
SELECT Airline, AVG(ArrivalTime) OVER (PARTITION BY Airline) AS AvgArrivalTime FROM Flights;
gretelai_synthetic_text_to_sql
CREATE TABLE Policy_Advocacy (Fiscal_Year INT, Region VARCHAR(10), Expenditure DECIMAL(7,2)); INSERT INTO Policy_Advocacy VALUES (2022, 'Northeast', 50000.00), (2022, 'Southeast', 40000.00), (2023, 'Northeast', 55000.00), (2023, 'Southeast', 45000.00);
What is the average policy advocacy expenditure per region, partitioned by fiscal year and ordered from highest to lowest?
SELECT Fiscal_Year, Region, AVG(Expenditure) as Avg_Expenditure, RANK() OVER (PARTITION BY Fiscal_Year ORDER BY AVG(Expenditure) DESC) as Rank FROM Policy_Advocacy GROUP BY Fiscal_Year, Region ORDER BY Fiscal_Year, Avg_Expenditure DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE circular_economy(country VARCHAR(20), year INT, population INT, initiatives INT); INSERT INTO circular_economy(country, year, population, initiatives) VALUES ('Nigeria', 2018, 196, 15), ('Ethiopia', 2018, 114, 12), ('Egypt', 2018, 102, 18), ('South Africa', 2018, 58, 23), ('Kenya', 2018, 53, 19), ('Tanzani...
What is the total circular economy initiatives count for the year 2018 for countries in Africa with a population between 5 and 15 million?
SELECT SUM(initiatives) FROM circular_economy WHERE year = 2018 AND population BETWEEN 5000000 AND 15000000 GROUP BY year;
gretelai_synthetic_text_to_sql
CREATE TABLE factories (id INT, name VARCHAR(255), recycling_rate DECIMAL(10, 2));CREATE TABLE recycling_reports (id INT, factory_id INT, report_date DATE);
Find the top 3 factories with the highest recycling rate in the past month.
SELECT factories.name, factories.recycling_rate FROM factories INNER JOIN recycling_reports ON factories.id = recycling_reports.factory_id WHERE recycling_reports.report_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) GROUP BY factories.id ORDER BY factories.recycling_rate DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE Maritime_Laws (id INT PRIMARY KEY, country VARCHAR(255), law_name VARCHAR(255), description TEXT); CREATE TABLE Vessel_Violations (id INT PRIMARY KEY, vessel_id INT, maritime_law_id INT, violation_date DATE, FOREIGN KEY (vessel_id) REFERENCES Vessels(id), FOREIGN KEY (maritime_law_id) REFERENCES Maritime_L...
Which countries have more than 75 violations of maritime laws related to plastic waste disposal?
SELECT Maritime_Laws.country, COUNT(Vessel_Violations.id) FROM Maritime_Laws JOIN Vessel_Violations ON Maritime_Laws.id = Vessel_Violations.maritime_law_id WHERE law_name LIKE '%plastic%' GROUP BY Maritime_Laws.country HAVING COUNT(Vessel_Violations.id) > 75;
gretelai_synthetic_text_to_sql
CREATE TABLE rural_infrastructure (country TEXT, year INT, investment NUMERIC); INSERT INTO rural_infrastructure (country, year, investment) VALUES ('Brazil', 2012, 1500000), ('Brazil', 2013, 1700000), ('Brazil', 2014, 1800000), ('Brazil', 2015, 2000000), ('Brazil', 2016, 2200000), ('Brazil', 2017, 2400000), ('Brazil',...
What is the total investment in rural infrastructure in Brazil for the past decade, grouped by year?
SELECT year, SUM(investment) OVER (PARTITION BY NULL ORDER BY year) AS total_investment FROM rural_infrastructure WHERE country = 'Brazil' AND year BETWEEN 2012 AND 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE rural_infrastructure (project_id INT, project_type VARCHAR(50), budget INT);
List the types of rural infrastructure projects and their respective budgets from the 'rural_infrastructure' table
SELECT project_type, budget FROM rural_infrastructure;
gretelai_synthetic_text_to_sql
CREATE TABLE Customers (CustomerID int, Name varchar(50), Age int); INSERT INTO Customers (CustomerID, Name, Age) VALUES (1, 'John Smith', 35), (2, 'Jane Doe', 42), (3, 'Michael Lee', 28); CREATE TABLE Transactions (TransactionID int, CustomerID int, Amount decimal(10,2)); INSERT INTO Transactions (TransactionID, Custo...
List all customers who have never made a transaction?
SELECT Contexts.CustomerID, Contexts.Name FROM Contexts WHERE Contexts.CustomerID NOT IN (SELECT Transactions.CustomerID FROM Transactions) ORDER BY Contexts.CustomerID;
gretelai_synthetic_text_to_sql
CREATE TABLE emergency_responses (id INT PRIMARY KEY, disaster_id INT, response_type VARCHAR(50), FOREIGN KEY (disaster_id) REFERENCES disasters(id));
What is the total number of emergency responses for each disaster type?
SELECT response_type, COUNT(*) as total_responses FROM emergency_responses er JOIN disasters d ON er.disaster_id = d.id GROUP BY response_type;
gretelai_synthetic_text_to_sql
CREATE TABLE Farmers (id INT PRIMARY KEY, name VARCHAR(255), age INT, gender VARCHAR(10), location VARCHAR(255), farmer_id INT); CREATE TABLE Equipment (id INT PRIMARY KEY, type VARCHAR(255), model VARCHAR(255), purchased_date DATE, last_service_date DATE, status VARCHAR(255), farmer_id INT, FOREIGN KEY (farmer_id) REF...
Delete a farmer and their related data in South Africa
DELETE f, e, fd FROM Farmers f INNER JOIN Equipment e ON f.farmer_id = e.farmer_id INNER JOIN Fields fd ON f.farmer_id = fd.farmer_id WHERE f.name = 'Sipho Ndlovu';
gretelai_synthetic_text_to_sql
CREATE TABLE production_forecasts (forecast_id INT, well_id INT, production_year INT, production_volume FLOAT, region VARCHAR(50)); INSERT INTO production_forecasts (forecast_id, well_id, production_year, production_volume, region) VALUES (5, 5, 2022, 250.6, 'North Sea'); INSERT INTO production_forecasts (forecast_id, ...
What are the production forecasts for the wells in the North Sea, ranked by production volume in descending order for each production year?
SELECT forecast_id, well_id, production_year, production_volume, region, ROW_NUMBER() OVER (PARTITION BY production_year ORDER BY production_volume DESC) as rank FROM production_forecasts WHERE region = 'North Sea';
gretelai_synthetic_text_to_sql
CREATE TABLE heritage_sites(site_id INT, name TEXT, country TEXT, protected BOOLEAN); INSERT INTO heritage_sites (site_id, name, country, protected) VALUES (1, 'Ancient Ruins', 'Mexico', TRUE), (2, 'Historic Monastery', 'Spain', TRUE);
How many cultural heritage sites are preserved in Mexico?
SELECT COUNT(*) FROM heritage_sites WHERE country = 'Mexico' AND protected = TRUE;
gretelai_synthetic_text_to_sql
CREATE TABLE fabric_sources (source_id INT, sustainable BOOLEAN);CREATE VIEW sustainable_fabric_sources AS SELECT * FROM fabric_sources WHERE sustainable = TRUE;
How many unique fabric sources are used in sustainable fashion production?
SELECT COUNT(DISTINCT source_id) FROM sustainable_fabric_sources;
gretelai_synthetic_text_to_sql
CREATE TABLE Suppliers (SupplierID INT, SupplierName VARCHAR(100)); INSERT INTO Suppliers (SupplierID, SupplierName) VALUES (1, 'Alpha Corp'), (2, 'Beta Inc'), (3, 'Charlie Ltd'); CREATE TABLE Contracts (ContractID INT, SupplierID INT); INSERT INTO Contracts (ContractID, SupplierID) VALUES (1, 1), (2, 2);
Which suppliers have no contracts?
SELECT Suppliers.SupplierName FROM Suppliers LEFT JOIN Contracts ON Suppliers.SupplierID = Contracts.SupplierID WHERE Contracts.ContractID IS NULL;
gretelai_synthetic_text_to_sql
CREATE TABLE chicago_crimes (id INT, crime_date DATE, crime_type VARCHAR(20)); INSERT INTO chicago_crimes (id, crime_date, crime_type) VALUES (1, '2022-02-01', 'Theft'), (2, '2022-02-15', 'Vandalism'), (3, '2022-02-15', 'Theft');
What is the most common crime in Chicago?
SELECT crime_type, COUNT(*) AS count FROM chicago_crimes GROUP BY crime_type ORDER BY count DESC LIMIT 1;
gretelai_synthetic_text_to_sql
CREATE TABLE patents (technology TEXT, year INTEGER, filed BOOLEAN); INSERT INTO patents (technology, year, filed) VALUES ('BioSensor1', 2019, true), ('BioSensor2', 2020, true), ('BioSensor3', 2018, false);
List the biosensor technology patents filed before 2020.
SELECT technology FROM patents WHERE year < 2020;
gretelai_synthetic_text_to_sql
CREATE TABLE wind_energy (month INT, year INT, production FLOAT);
What was the average monthly wind energy production (in MWh) in 2021?
SELECT AVG(production) FROM wind_energy WHERE year = 2021 GROUP BY month;
gretelai_synthetic_text_to_sql
CREATE TABLE Resources (ResourceID INT, Site VARCHAR(50), Quantity INT, DepletionDate DATE); INSERT INTO Resources (ResourceID, Site, Quantity, DepletionDate) VALUES (1, 'Site A', 500, '2019-04-15'); INSERT INTO Resources (ResourceID, Site, Quantity, DepletionDate) VALUES (2, 'Site A', 700, '2019-07-12'); INSERT INTO R...
What is the total amount of resources depleted for each mining site in Q2 of 2019?
SELECT Site, SUM(Quantity) FROM Resources WHERE MONTH(DepletionDate) BETWEEN 4 AND 6 GROUP BY Site;
gretelai_synthetic_text_to_sql
CREATE TABLE menu_engineering (menu_item VARCHAR(30), daily_revenue DECIMAL(10,2)); INSERT INTO menu_engineering (menu_item, daily_revenue) VALUES ('Cheese Burger', 250.00), ('Veggie Pizza', 300.00), ('Garden Salad', 150.00), ('BBQ Ribs', 400.00);
Find the top 2 menu items with highest daily revenue.
SELECT menu_item, daily_revenue FROM (SELECT menu_item, daily_revenue, ROW_NUMBER() OVER (ORDER BY daily_revenue DESC) as rn FROM menu_engineering) tmp WHERE rn <= 2;
gretelai_synthetic_text_to_sql
CREATE TABLE union_bargaining (id INT, union_name TEXT, state TEXT, involved_in_bargaining BOOLEAN); INSERT INTO union_bargaining (id, union_name, state, involved_in_bargaining) VALUES (1, 'Union D', 'Florida', true), (2, 'Union E', 'Florida', false), (3, 'Union F', 'Florida', true);
What is the total number of members in unions that are involved in collective bargaining in Florida?
SELECT SUM(involved_in_bargaining) FROM union_bargaining WHERE state = 'Florida';
gretelai_synthetic_text_to_sql
CREATE TABLE Volunteers (id INT, program VARCHAR(50), volunteer VARCHAR(50), engagement_date DATE); INSERT INTO Volunteers (id, program, volunteer, engagement_date) VALUES (1, 'Arts Education', 'John Smith', '2022-07-05'), (2, 'Environment', 'Jane Doe', '2022-07-07'), (3, 'Arts Education', 'Sara Connor', '2022-07-10'),...
How many unique volunteers were engaged in each program in Q3 2022?
SELECT program, DATE_FORMAT(engagement_date, '%Y-%m') as quarter, COUNT(DISTINCT volunteer) as unique_volunteers FROM Volunteers WHERE engagement_date BETWEEN '2022-07-01' AND '2022-09-30' GROUP BY program, quarter;
gretelai_synthetic_text_to_sql
CREATE TABLE workout_equipment (id INT, member_id INT, equipment_name VARCHAR(50));
Delete the workout_equipment table
DROP TABLE workout_equipment;
gretelai_synthetic_text_to_sql
CREATE TABLE drought_impact_south_africa(id INT, location VARCHAR(50), impact FLOAT, year INT); INSERT INTO drought_impact_south_africa(id, location, impact, year) VALUES (1, 'Cape Town', 28.1, 2018);
Which locations in South Africa had the highest drought impact in the last 10 years?
SELECT location, MAX(impact) as max_impact FROM drought_impact_south_africa WHERE year BETWEEN (SELECT MAX(year) - 10 FROM drought_impact_south_africa) AND MAX(year) GROUP BY location ORDER BY max_impact DESC;
gretelai_synthetic_text_to_sql
CREATE SCHEMA research;CREATE TABLE grants(faculty_name TEXT,department TEXT,amount INTEGER);INSERT INTO grants(faculty_name,department,amount)VALUES('Charlie','Mathematics',100000),('Dave','Physics',200000);
What are the total research grant funds awarded to faculty members in the Mathematics department?
SELECT SUM(amount) FROM research.grants WHERE department='Mathematics';
gretelai_synthetic_text_to_sql
CREATE TABLE patients (patient_id INT, age INT, gender TEXT, state TEXT, condition TEXT, medication TEXT); INSERT INTO patients (patient_id, age, gender, state, condition, medication) VALUES (1, 30, 'Female', 'Texas', 'Depression', 'Yes'); INSERT INTO patients (patient_id, age, gender, state, condition, medication) VAL...
How many patients in each state received medication for depression?
SELECT state, COUNT(*) FROM patients WHERE condition = 'Depression' AND medication = 'Yes' GROUP BY state;
gretelai_synthetic_text_to_sql
CREATE TABLE Infrastructure (id INT, name VARCHAR(100), type VARCHAR(50), location VARCHAR(100), state VARCHAR(50)); INSERT INTO Infrastructure (id, name, type, location, state) VALUES (9, 'Western Plains Wind Farm', 'Wind Farm', 'Woodward', 'Oklahoma');
Show the number of wind farms in Oklahoma
SELECT COUNT(*) FROM Infrastructure WHERE type = 'Wind Farm' AND state = 'Oklahoma';
gretelai_synthetic_text_to_sql
CREATE TABLE garments (id INT, garment_type VARCHAR(255), material VARCHAR(255), price DECIMAL(5,2), country VARCHAR(255));
Find the minimum retail price of hemp garments in the UK
SELECT MIN(price) FROM garments WHERE garment_type = 'Shirt' AND material = 'Hemp' AND country = 'United Kingdom';
gretelai_synthetic_text_to_sql
CREATE TABLE hospitals (id INT, name TEXT, city TEXT, state TEXT, beds INT); INSERT INTO hospitals (id, name, city, state, beds) VALUES (1, 'General Hospital', 'Miami', 'Florida', 500); INSERT INTO hospitals (id, name, city, state, beds) VALUES (2, 'Memorial Hospital', 'Boston', 'Massachusetts', 600);
How many hospitals are there in Florida and Massachusetts?
SELECT state, COUNT(*) as hospital_count FROM hospitals WHERE state IN ('Florida', 'Massachusetts') GROUP BY state;
gretelai_synthetic_text_to_sql
CREATE TABLE properties_for_sale (id INT, property_id INT, city TEXT, state TEXT, is_for_sale BOOLEAN);
How many properties are for sale in Oakland?
SELECT COUNT(*) FROM properties_for_sale WHERE city = 'Oakland' AND is_for_sale = TRUE;
gretelai_synthetic_text_to_sql
CREATE TABLE hotels_3 (hotel_id INT, hotel_name TEXT, region TEXT, has_mobile_checkin BOOLEAN); INSERT INTO hotels_3 (hotel_id, hotel_name, region, has_mobile_checkin) VALUES (1, 'Hotel C', 'MEA', true), (2, 'Hotel D', 'MEA', false);
What is the percentage of hotels in MEA region that have adopted mobile check-in?
SELECT (COUNT(*) FILTER (WHERE has_mobile_checkin = true) * 100.0 / COUNT(*))::decimal(5,2) as percentage FROM hotels_3 WHERE region = 'MEA';
gretelai_synthetic_text_to_sql
CREATE TABLE LanthanumProduction (Processor VARCHAR(50), Year INT, Production FLOAT); INSERT INTO LanthanumProduction(Processor, Year, Production) VALUES ('ProcessorA', 2017, 451.5), ('ProcessorA', 2018, 456.7), ('ProcessorA', 2019, 462.1), ('ProcessorB', 2017, 389.1), ('ProcessorB', 2018, 393.5), ('ProcessorB', 2019, ...
Find the lanthanum production difference between 2018 and 2017 for each processor.
SELECT Processor, Production - LAG(Production) OVER (PARTITION BY Processor ORDER BY Year) as Difference FROM LanthanumProduction WHERE Processor IN ('ProcessorA', 'ProcessorB');
gretelai_synthetic_text_to_sql
CREATE TABLE accounts (id INT, name VARCHAR(255), followers INT); CREATE TABLE posts (id INT, account_id INT, content TEXT, timestamp TIMESTAMP); INSERT INTO accounts (id, name, followers) VALUES (1, 'user1', 15000); INSERT INTO posts (id, account_id, content, timestamp) VALUES (1, 1, 'post1 with travel', '2022-05-01 1...
How many posts were made by users with more than 10,000 followers, in the past week, that contain the word "travel"?
SELECT COUNT(*) FROM posts JOIN accounts ON posts.account_id = accounts.id WHERE accounts.followers > 10000 AND posts.timestamp >= NOW() - INTERVAL '1 week' AND posts.content LIKE '%travel%';
gretelai_synthetic_text_to_sql
CREATE TABLE Resource_Depletion(Mine_Name TEXT, Reserves_Copper INT, Reserves_Gold INT); INSERT INTO Resource_Depletion(Mine_Name, Reserves_Copper, Reserves_Gold) VALUES('Tasiast', 2500000, 15000); INSERT INTO Resource_Depletion(Mine_Name, Reserves_Copper, Reserves_Gold) VALUES('Katanga', 3500000, 20000);
Which mine has the highest copper reserves?
SELECT Mine_Name, Reserves_Copper FROM Resource_Depletion ORDER BY Reserves_Copper DESC LIMIT 1;
gretelai_synthetic_text_to_sql
CREATE TABLE countries (id INT, name TEXT, region TEXT, obesity_rate INT); INSERT INTO countries (id, name, region, obesity_rate) VALUES (1, 'France', 'Europe', 25); INSERT INTO countries (id, name, region, obesity_rate) VALUES (2, 'Germany', 'Europe', 30);
What is the percentage of the population that is obese in each country in the European region?
SELECT name, region, obesity_rate FROM countries WHERE region = 'Europe';
gretelai_synthetic_text_to_sql
CREATE TABLE customers (customer_id INT, name VARCHAR(100), region VARCHAR(50)); INSERT INTO customers (customer_id, name, region) VALUES (1, 'John Doe', 'Asia-Pacific'), (2, 'Jane Smith', 'Europe'), (3, 'Alice Johnson', 'Asia-Pacific'); CREATE TABLE sales (sale_id INT, customer_id INT, revenue DECIMAL(10,2)); INSERT I...
What is the total revenue generated from customers in the Asia-Pacific region?
SELECT SUM(sales.revenue) FROM sales JOIN customers ON sales.customer_id = customers.customer_id WHERE customers.region = 'Asia-Pacific';
gretelai_synthetic_text_to_sql
CREATE TABLE Exhibitions (id INT, name TEXT, visitor_count INT); INSERT INTO Exhibitions (id, name, visitor_count) VALUES (1, 'Dinosaurs', 1000), (2, 'Egypt', 800);
What is the minimum number of visitors for an exhibition?
SELECT MIN(visitor_count) FROM Exhibitions;
gretelai_synthetic_text_to_sql
CREATE TABLE vehicle_sales (id INT, vehicle_model VARCHAR(50), vehicle_type VARCHAR(50), price FLOAT); INSERT INTO vehicle_sales (id, vehicle_model, vehicle_type, price) VALUES (1, 'Tesla Model 3', 'electric', 45000), (2, 'Nissan Leaf', 'electric', 30000), (3, 'Honda Civic', 'gasoline', 25000), (4, 'Toyota Prius', 'hyb...
List the number of unique electric vehicle models and their average price in the vehicle_sales and autonomous_vehicles tables.
SELECT COUNT(DISTINCT vehicle_model) AS unique_models, AVG(price) AS average_price FROM (SELECT vehicle_model, price FROM vehicle_sales WHERE vehicle_type = 'electric' UNION ALL SELECT vehicle_model, price FROM autonomous_vehicles WHERE vehicle_type = 'electric');
gretelai_synthetic_text_to_sql
CREATE TABLE temperature_data (id INT, date DATE, arctic_region VARCHAR(255), temperature FLOAT); INSERT INTO temperature_data (id, date, arctic_region, temperature) VALUES (1, '2000-01-01', 'North Pole', -25.0), (2, '2000-02-01', 'North Pole', -28.5);
What is the average temperature change in the Arctic region for each month since 2000?
SELECT EXTRACT(MONTH FROM date) AS month, AVG(temperature) FROM temperature_data WHERE date >= '2000-01-01' GROUP BY month;
gretelai_synthetic_text_to_sql