context
stringlengths
11
9.12k
question
stringlengths
0
1.06k
SQL
stringlengths
2
4.44k
source
stringclasses
28 values
CREATE TABLE donors (id INT, last_donation DATE); INSERT INTO donors VALUES (1, '2021-06-01')
List donors who have not donated in the last 6 months
SELECT d.id, d.last_donation FROM donors d WHERE d.last_donation < DATE_SUB(CURDATE(), INTERVAL 6 MONTH);
gretelai_synthetic_text_to_sql
CREATE TABLE ProjectData (ProjectID INT, InstallationDate DATE, InspectionDate DATE);
Determine the number of days between the "InstallationDate" and "InspectionDate" for each renewable energy project in the "ProjectData" table.
SELECT ProjectID, InspectionDate - InstallationDate AS DaysBetweenDates FROM ProjectData;
gretelai_synthetic_text_to_sql
CREATE TABLE Projects (Year INT, Region VARCHAR(20), Status VARCHAR(20), Type VARCHAR(20)); INSERT INTO Projects (Year, Region, Status, Type) VALUES (2018, 'Africa', 'Completed', 'Climate Adaptation');
Which climate adaptation projects were completed in Africa in 2018?
SELECT * FROM Projects WHERE Year = 2018 AND Region = 'Africa' AND Type = 'Climate Adaptation' AND Status = 'Completed';
gretelai_synthetic_text_to_sql
CREATE TABLE RenewableEnergyProjects (id INT, region VARCHAR(20), project_type VARCHAR(20), project_start_date DATE); INSERT INTO RenewableEnergyProjects (id, region, project_type, project_start_date) VALUES (1, 'Africa', 'Wind', '2019-01-01'), (2, 'Africa', 'Hydroelectric', '2020-06-17'), (3, 'Europe', 'Solar', '2021-03-25');
How many renewable energy projects have been implemented in the Africa region, excluding solar power plants, in the last 3 years?
SELECT COUNT(*) FROM RenewableEnergyProjects WHERE region = 'Africa' AND project_type != 'Solar' AND project_start_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 YEAR);
gretelai_synthetic_text_to_sql
CREATE TABLE QuarterlyPolicy (Quarter TEXT, Year INTEGER, Change INTEGER); INSERT INTO QuarterlyPolicy (Quarter, Year, Change) VALUES ('Q1 2021', 2021, 12), ('Q2 2021', 2021, 15), ('Q3 2021', 2021, 10), ('Q4 2021', 2021, 18);
How many policy changes were made per quarter in 2021?
SELECT Quarter, SUM(Change) FROM QuarterlyPolicy WHERE Year = 2021 GROUP BY Quarter;
gretelai_synthetic_text_to_sql
CREATE TABLE Concerts (id INT, city VARCHAR(20), price FLOAT, tickets_sold INT); INSERT INTO Concerts (id, city, price, tickets_sold) VALUES (1, 'Chicago', 100.0, 200), (2, 'Chicago', 120.0, 150), (3, 'New York', 150.0, 250);
What was the average ticket price for concerts in a specific city?
SELECT AVG(price) FROM Concerts WHERE city = 'Chicago';
gretelai_synthetic_text_to_sql
CREATE TABLE Suppliers (id INT, name TEXT, location TEXT);CREATE TABLE Materials (id INT, supplier_id INT, factory_id INT, material TEXT, quantity INT, date DATE);INSERT INTO Suppliers VALUES (1, 'SupplierA', 'CityA'), (2, 'SupplierB', 'CityB'), (3, 'SupplierC', 'CityC');INSERT INTO Materials VALUES (1, 1, 5, 'MaterialX', 100, '2021-06-01'), (2, 1, 5, 'MaterialY', 200, '2021-07-15'), (3, 2, 5, 'MaterialX', 150, '2021-08-01'), (4, 3, 6, 'MaterialZ', 50, '2021-09-10');
Which suppliers have not provided any materials to factory5 in the past year?
SELECT DISTINCT s.name FROM Suppliers s WHERE s.id NOT IN (SELECT m.supplier_id FROM Materials m WHERE m.factory_id = 5 AND m.date BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) AND CURRENT_DATE);
gretelai_synthetic_text_to_sql
CREATE TABLE volunteers (id INT, name TEXT, organization_id INT); INSERT INTO volunteers (id, name, organization_id) VALUES (1, 'John Doe', 1), (2, 'Jane Smith', 1), (3, 'Mike Johnson', 2);
List the names of volunteers who have participated in both education and health programs in the same organization.
SELECT volunteers.name FROM volunteers JOIN (SELECT organization_id FROM grants WHERE initiative_type IN ('Education', 'Health') GROUP BY organization_id HAVING COUNT(DISTINCT initiative_type) = 2) AS grp_org ON volunteers.organization_id = grp_org.organization_id;
gretelai_synthetic_text_to_sql
CREATE TABLE ocean_depth (location TEXT, depth INTEGER);
What is the maximum depth of the ocean?
SELECT MAX(depth) FROM ocean_depth;
gretelai_synthetic_text_to_sql
CREATE TABLE company (id INT, name TEXT, country TEXT, founding_date DATE, founder_refugee BOOLEAN); INSERT INTO company (id, name, country, founding_date, founder_refugee) VALUES (1, 'Chi Corp', 'Sweden', '2019-01-01', TRUE); INSERT INTO company (id, name, country, founding_date, founder_refugee) VALUES (2, 'Psi Enterprises', 'Sweden', '2018-01-01', FALSE);
What percentage of companies were founded by refugees in Sweden in 2019?
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM company WHERE founding_date >= '2019-01-01' AND country = 'Sweden')) FROM company WHERE founder_refugee = TRUE AND founding_date >= '2019-01-01' AND country = 'Sweden';
gretelai_synthetic_text_to_sql
CREATE TABLE defense_projects_2 (project_name varchar(255), year int, budget int); INSERT INTO defense_projects_2 (project_name, year, budget) VALUES ('Project A', 2021, 5500000), ('Project A', 2022, 5000000), ('Project B', 2021, 7500000), ('Project B', 2022, 7000000);
Which defense projects had a budget decrease in 2022 compared to 2021?
SELECT project_name FROM defense_projects_2 WHERE budget[(SELECT budget FROM defense_projects_2 WHERE project_name = defense_projects_2.project_name AND year = 2021)] > budget WHERE year = 2022;
gretelai_synthetic_text_to_sql
CREATE TABLE community_health_center (name TEXT, patient_id INTEGER, age INTEGER); INSERT INTO community_health_center (name, patient_id, age) VALUES ('Community health center A', 1, 45), ('Community health center A', 2, 50), ('Community health center A', 3, 30), ('Community health center A', 4, 60), ('Community health center B', 5, 25), ('Community health center B', 6, 45);
What is the average age of patients in community health center B?
SELECT AVG(age) FROM community_health_center WHERE name = 'Community health center B'
gretelai_synthetic_text_to_sql
CREATE TABLE revenue (region VARCHAR(10), product VARCHAR(20), revenue INT); INSERT INTO revenue (region, product, revenue) VALUES ('Oceania', 'shirt', 10000), ('Oceania', 'pants', 12000);
What is the total revenue generated from the sale of clothing products in Oceania?
SELECT SUM(revenue) FROM revenue WHERE region = 'Oceania';
gretelai_synthetic_text_to_sql
CREATE TABLE Ingredients (IngredientID INT, Name TEXT, IsVegan BOOLEAN, SupplierID INT); CREATE TABLE Suppliers (SupplierID INT, Name TEXT);
List all suppliers providing ingredients for a vegan-only menu.
SELECT DISTINCT Suppliers.Name FROM Suppliers INNER JOIN Ingredients ON Suppliers.SupplierID = Ingredients.SupplierID WHERE IsVegan = TRUE;
gretelai_synthetic_text_to_sql
CREATE TABLE public_buses (bus_id INT, trip_id INT, trip_start_time TIMESTAMP, trip_end_time TIMESTAMP, start_location TEXT, end_location TEXT, city TEXT, avg_waiting_time DECIMAL, peak_hours TEXT);
What is the average waiting time for public buses in Sydney, Australia during peak hours?
SELECT AVG(avg_waiting_time) FROM public_buses WHERE city = 'Sydney' AND peak_hours = 'yes';
gretelai_synthetic_text_to_sql
CREATE TABLE Claims (ClaimID INT, PolicyID INT, ClaimAmount DECIMAL(5,2), ClaimDate DATE); INSERT INTO Claims (ClaimID, PolicyID, ClaimAmount, ClaimDate) VALUES (1, 1, 500, '2020-01-01'); INSERT INTO Claims (ClaimID, PolicyID, ClaimAmount, ClaimDate) VALUES (2, 1, 750, '2020-02-01'); INSERT INTO Claims (ClaimID, PolicyID, ClaimAmount, ClaimDate) VALUES (3, 2, 400, '2020-03-01'); CREATE TABLE Policyholders (PolicyID INT, PolicyholderName VARCHAR(50), State VARCHAR(2)); INSERT INTO Policyholders (PolicyID, PolicyholderName, State) VALUES (1, 'Juan Garcia', 'Texas'); INSERT INTO Policyholders (PolicyID, PolicyholderName, State) VALUES (2, 'Thanh Nguyen', 'Texas');
What are the policy numbers and claim dates for policyholders in Texas with claims exceeding $1000?
SELECT PolicyID, ClaimDate FROM Claims JOIN Policyholders ON Claims.PolicyID = Policyholders.PolicyID WHERE Policyholders.State = 'Texas' AND ClaimAmount > 1000;
gretelai_synthetic_text_to_sql
CREATE TABLE mental_health_parity (state VARCHAR(255), violations INT); CREATE TABLE community_health_workers (state VARCHAR(255), training_level VARCHAR(255), workers INT); INSERT INTO mental_health_parity (state, violations) VALUES ('California', 150), ('New York', 120), ('Texas', 180), ('Florida', 100); INSERT INTO community_health_workers (state, training_level, workers) VALUES ('California', 'Beginner', 100), ('California', 'Intermediate', 200), ('California', 'Advanced', 300), ('New York', 'Beginner', 150), ('New York', 'Intermediate', 150), ('New York', 'Advanced', 200), ('Texas', 'Beginner', 200), ('Texas', 'Intermediate', 300), ('Texas', 'Advanced', 400), ('Florida', 'Beginner', 100), ('Florida', 'Intermediate', 200), ('Florida', 'Advanced', 300);
What is the total number of mental health parity violations by state and training level of community health workers?
SELECT m.state, t.training_level, SUM(m.violations) FROM mental_health_parity m INNER JOIN community_health_workers t ON m.state = t.state GROUP BY m.state, t.training_level;
gretelai_synthetic_text_to_sql
CREATE TABLE articles (id INT, title TEXT, category TEXT, likes INT, created_at DATETIME); INSERT INTO articles (id, title, category, likes, created_at) VALUES (1, 'Climate crisis: 12 years to save the planet', 'climate change', 100, '2022-01-01 10:30:00');
Delete articles with less than 20 likes and published before 2022.
DELETE FROM articles WHERE likes < 20 AND created_at < '2022-01-01 00:00:00';
gretelai_synthetic_text_to_sql
CREATE TABLE Donations (DonationID int, DonationDate date, DonationAmount int, Program varchar(50)); INSERT INTO Donations (DonationID, DonationDate, DonationAmount, Program) VALUES (1, '2021-01-01', 100, 'Food Support'), (2, '2021-01-10', 200, 'Food Support');
Calculate the total donation amount and average donation per volunteer for the 'Food Support' program in 2021.
SELECT AVG(DonationAmount) as AverageDonationPerVolunteer, SUM(DonationAmount) as TotalDonationAmount FROM Donations WHERE Program = 'Food Support' AND YEAR(DonationDate) = 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE rd_expenditure (company TEXT, region TEXT, expenditure_year INT, expenditure_amount INT); INSERT INTO rd_expenditure (company, region, expenditure_year, expenditure_amount) VALUES ('BioCure', 'Asia', 2021, 20000);
What was the total R&D expenditure for 'BioCure' in 'Asia' for 2021?
SELECT SUM(expenditure_amount) FROM rd_expenditure WHERE company = 'BioCure' AND region = 'Asia' AND expenditure_year = 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE athlete_participation (id INT, athlete VARCHAR(255), program VARCHAR(255), participation DECIMAL(5,2)); INSERT INTO athlete_participation (id, athlete, program, participation) VALUES (1, 'John Doe', 'Yoga', 0.75), (2, 'Jane Doe', 'Meditation', 0.85), (3, 'John Doe', 'Pilates', 0.65), (4, 'Jane Doe', 'Yoga', 0.95);
What is the average wellbeing program participation rate by athlete?
SELECT athlete, AVG(participation) as avg_participation FROM athlete_participation GROUP BY athlete;
gretelai_synthetic_text_to_sql
CREATE TABLE clients (client_id INT, client_name VARCHAR(255)); INSERT INTO clients (client_id, client_name) VALUES (1, 'Acme Inc'), (2, 'Beta Corp'); CREATE TABLE billing (bill_id INT, client_id INT, amount DECIMAL(10, 2)); INSERT INTO billing (bill_id, client_id, amount) VALUES (1, 1, 500.00), (2, 1, 250.00), (3, 2, 750.00);
What is the total billing amount for each client?
SELECT c.client_name, SUM(b.amount) as total_billing FROM clients c INNER JOIN billing b ON c.client_id = b.client_id GROUP BY c.client_id, c.client_name;
gretelai_synthetic_text_to_sql
CREATE TABLE satellite_images (id INT, image_name VARCHAR(50), capture_date DATE); INSERT INTO satellite_images (id, image_name, capture_date) VALUES (1, 'image1', '2021-07-01'), (2, 'image2', '2021-08-01');
List the satellite images in the 'satellite_images' table that were taken in July 2021.
SELECT * FROM satellite_images WHERE MONTH(capture_date) = 7 AND YEAR(capture_date) = 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE explainable_ai (transaction_id INT, algorithm_name VARCHAR(255), transaction_date DATE); INSERT INTO explainable_ai (transaction_id, algorithm_name, transaction_date) VALUES (1, 'SHAP', '2022-01-01'), (2, 'LIME', '2022-01-05'), (3, 'SHAP', '2022-01-10');
List explainable AI algorithms that have been used in the last month.
SELECT algorithm_name FROM explainable_ai WHERE transaction_date >= DATEADD(month, -1, GETDATE());
gretelai_synthetic_text_to_sql
CREATE TABLE Volunteers (VolunteerID INT, SignUpDate DATE, IsActive BOOLEAN); INSERT INTO Volunteers (VolunteerID, SignUpDate, IsActive) VALUES (1, '2022-01-15', true), (2, '2022-02-20', false), (3, '2022-03-05', true);
What is the retention rate of volunteers who signed up in the last 6 months?
SELECT COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Volunteers WHERE SignUpDate >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '6 months') AND IsActive) as RetentionRate FROM Volunteers WHERE SignUpDate < DATE_TRUNC('month', CURRENT_DATE - INTERVAL '6 months') AND IsActive;
gretelai_synthetic_text_to_sql
CREATE TABLE park_data (park VARCHAR(255), year INT, polar_bear_sightings INT); CREATE TABLE park_information (park VARCHAR(255), size FLOAT, location VARCHAR(255));
How many polar bear sightings have been recorded in each park in the last 5 years?
SELECT park, COUNT(polar_bear_sightings) OVER (PARTITION BY park) FROM park_data WHERE year BETWEEN 2018 AND 2022;
gretelai_synthetic_text_to_sql
CREATE TABLE lunar_landings(id INT, agency VARCHAR(255), mission_name VARCHAR(255), launch_date DATE, landing_date DATE, mission_status VARCHAR(255));
What is the minimum number of successful lunar landings by any space agency, and which agency achieved this milestone first?
SELECT agency, MIN(mission_status = 'successful') as first_successful_mission FROM lunar_landings GROUP BY agency;
gretelai_synthetic_text_to_sql
CREATE TABLE marine_species (id INT, name VARCHAR(255)); CREATE TABLE oceanography_stations (id INT, station_name VARCHAR(255), species_id INT); INSERT INTO marine_species (id, name) VALUES (1, 'Clownfish'), (2, 'Blue Whale'); INSERT INTO oceanography_stations (id, station_name, species_id) VALUES (1, 'Station A', 1), (2, 'Station B', 1), (3, 'Station A', 2);
List all marine species that inhabit more than one oceanographic station.
SELECT marine_species.name FROM marine_species INNER JOIN oceanography_stations ON marine_species.id = oceanography_stations.species_id GROUP BY marine_species.name HAVING COUNT(DISTINCT oceanography_stations.station_name) > 1;
gretelai_synthetic_text_to_sql
CREATE TABLE ProductionWaste (ID INT, LineID INT, WasteDate DATE, WasteQuantity INT); INSERT INTO ProductionWaste (ID, LineID, WasteDate, WasteQuantity) VALUES (1, 100, '2021-04-03', 25), (2, 101, '2021-04-15', 35), (3, 102, '2021-04-28', 45);
What is the total waste produced by each production line in April 2021?
SELECT LineID, SUM(WasteQuantity) as TotalWaste FROM ProductionWaste WHERE WasteDate >= '2021-04-01' AND WasteDate < '2021-05-01' GROUP BY LineID;
gretelai_synthetic_text_to_sql
CREATE TABLE public_libraries (library_id INT, name VARCHAR(255), location VARCHAR(255), city VARCHAR(255), state VARCHAR(255), zip INT); INSERT INTO public_libraries (library_id, name, location, city, state, zip) VALUES (1, 'Houston Public Library', '500 McKinney', 'Houston', 'Texas', 77002); INSERT INTO public_libraries (library_id, name, location, city, state, zip) VALUES (2, 'Austin Public Library', '710 W Cesar Chavez St', 'Austin', 'Texas', 78701);
Get the number of public libraries in each city in Texas
SELECT city, COUNT(*) FROM public_libraries WHERE state = 'Texas' GROUP BY city;
gretelai_synthetic_text_to_sql
CREATE TABLE sales_representatives (rep_id INT, rep_name TEXT, territory TEXT); INSERT INTO sales_representatives (rep_id, rep_name, territory) VALUES (1, 'John Smith', 'Northeast'), (2, 'Jane Doe', 'Southeast'); CREATE TABLE sales_data (rep_id INT, sale_date DATE, revenue INT); INSERT INTO sales_data (rep_id, sale_date, revenue) VALUES (1, '2020-01-01', 5000), (1, '2020-01-15', 7000), (2, '2020-02-01', 6000), (2, '2020-03-15', 8000);
What is the total sales revenue for each sales representative's territory, ordered by highest revenue first, for the year 2020?'
SELECT rep_name, SUM(revenue) AS total_sales FROM sales_data JOIN sales_representatives ON sales_data.rep_id = sales_representatives.rep_id WHERE sale_date BETWEEN '2020-01-01' AND '2020-12-31' GROUP BY rep_name ORDER BY total_sales DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE patients (id INT, age INT, has_hypertension BOOLEAN); INSERT INTO patients (id, age, has_hypertension) VALUES (1, 60, true), (2, 45, false); CREATE TABLE locations (id INT, region VARCHAR, is_rural BOOLEAN); INSERT INTO locations (id, region, is_rural) VALUES (1, 'Appalachia', true), (2, 'California', false);
What is the average age of patients with hypertension in Appalachian rural areas?
SELECT AVG(patients.age) FROM patients INNER JOIN locations ON patients.id = locations.id WHERE patients.has_hypertension = true AND locations.is_rural = true;
gretelai_synthetic_text_to_sql
CREATE SCHEMA if not exists finance;CREATE TABLE if not exists loans (id INT PRIMARY KEY, institution_name TEXT, region TEXT, amount DECIMAL(10,2)); INSERT INTO loans (id, institution_name, region, amount) VALUES (1, 'ABC Microfinance', 'Latin America', 5000.00);
Update the loan amount for ABC Microfinance in Latin America to $6500.00
UPDATE finance.loans SET amount = 6500.00 WHERE institution_name = 'ABC Microfinance' AND region = 'Latin America';
gretelai_synthetic_text_to_sql
CREATE TABLE network_investments (investment FLOAT, region VARCHAR(20)); INSERT INTO network_investments (investment, region) VALUES (120000, 'Western'), (150000, 'Northern'), (180000, 'Western'), (200000, 'Northern'), (250000, 'Eastern');
What is the average network investment for the telecom provider in all regions?
SELECT AVG(investment) FROM network_investments;
gretelai_synthetic_text_to_sql
CREATE TABLE waste_management (country VARCHAR(50), textile_waste_percentage FLOAT, waste_management_strategy VARCHAR(50)); INSERT INTO waste_management (country, textile_waste_percentage, waste_management_strategy) VALUES ('Germany', 0.15, 'Extensive Recycling Programs'), ('France', 0.18, 'Ban on Textile Waste Incineration'), ('Austria', 0.20, 'Waste Reduction Campaigns'), ('Belgium', 0.22, 'Waste Sorting and Recycling'), ('Netherlands', 0.25, 'Textile Waste Composting');
Which countries have the lowest percentage of textile waste sent to landfills and their corresponding waste management strategies?
SELECT country, waste_management_strategy FROM waste_management WHERE textile_waste_percentage <= 0.22 ORDER BY textile_waste_percentage ASC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE teacher_pd (teacher_id INT, course_id INT, completion_date DATE); INSERT INTO teacher_pd (teacher_id, course_id, completion_date) VALUES (1, 1001, '2020-01-01'), (1, 1002, '2020-06-01'), (2, 1001, '2019-12-31'), (3, 1003, '2021-03-15');
How many professional development courses did each teacher complete in the last 3 years?
SELECT teacher_id, COUNT(*) FROM teacher_pd WHERE completion_date >= DATE_SUB(CURDATE(), INTERVAL 3 YEAR) GROUP BY teacher_id;
gretelai_synthetic_text_to_sql
CREATE TABLE transactions (id INT, digital_asset VARCHAR(10), transaction_date DATE, amount DECIMAL(10,2)); INSERT INTO transactions (id, digital_asset, transaction_date, amount) VALUES (1, 'ABC', '2022-01-01', 100.00), (2, 'DEF', '2022-02-01', 200.00);
Delete all transactions related to digital asset 'ABC' in the year 2022
DELETE FROM transactions WHERE digital_asset = 'ABC' AND YEAR(transaction_date) = 2022;
gretelai_synthetic_text_to_sql
CREATE TABLE great_wall_visitors (id INT, name VARCHAR(50), nationality VARCHAR(50)); INSERT INTO great_wall_visitors (id, name, nationality) VALUES (1, 'John Smith', 'British'), (2, 'Li Xiang', 'Chinese'), (3, 'Sophia Lee', 'British');
What is the most common nationality of tourists visiting the Great Wall of China?
SELECT nationality, COUNT(*) AS count FROM great_wall_visitors GROUP BY nationality ORDER BY count DESC LIMIT 1;
gretelai_synthetic_text_to_sql
CREATE TABLE games (game_id INT, name VARCHAR(255)); CREATE TABLE players (player_id INT, name VARCHAR(255)); CREATE TABLE player_games (player_id INT, game_id INT, hours_played INT);
Display the total number of hours played by all players, separated by game
SELECT games.name, SUM(player_games.hours_played) as total_hours_played FROM games JOIN player_games ON games.game_id = player_games.game_id GROUP BY games.name;
gretelai_synthetic_text_to_sql
CREATE TABLE if NOT EXISTS countries (country_code VARCHAR(3), country_name VARCHAR(50), avg_grant_amount DECIMAL(10, 2)); INSERT INTO countries (country_code, country_name, avg_grant_amount) VALUES ('USA', 'United States', 150000.00), ('CAN', 'Canada', 120000.00);
Which countries have the highest average grant amount?
SELECT country_name, AVG(grant_amount) as avg_grant_amount FROM grants INNER JOIN countries ON grants.country_code = countries.country_code GROUP BY country_name ORDER BY avg_grant_amount DESC LIMIT 1;
gretelai_synthetic_text_to_sql
CREATE TABLE mining_sites (id INT, name VARCHAR(50), location VARCHAR(50), added_date DATE, PRIMARY KEY (id)); INSERT INTO mining_sites (id, name, location, added_date) VALUES (1, 'Diamond Mine', 'South Africa', '2020-01-15'); INSERT INTO mining_sites (id, name, location, added_date) VALUES (2, 'Gold Mine', 'Ghana', '2021-02-20'); INSERT INTO mining_sites (id, name, location, added_date) VALUES (3, 'Coal Mine', 'Mozambique', '2022-03-05');
How many new mining sites were added in Africa in the past year?
SELECT COUNT(*) FROM mining_sites WHERE added_date >= DATEADD(year, -1, GETDATE()) AND location LIKE 'Africa%';
gretelai_synthetic_text_to_sql
CREATE TABLE donations (donor_id INT, donation_date DATE, donation_amount DECIMAL(10, 2)); INSERT INTO donations (donor_id, donation_date, donation_amount) VALUES (1, '2022-01-01', 500.00), (1, '2022-02-01', 300.00), (2, '2022-03-01', 700.00), (3, '2022-04-01', 200.00);
What is the average monthly donation amount per donor, for the last year, excluding donors with only one donation?
SELECT AVG(donation_amount) as avg_monthly_donation_amount FROM (SELECT donor_id, YEAR(donation_date) as donation_year, MONTH(donation_date) as donation_month, AVG(donation_amount) as donation_amount FROM donations WHERE donation_date >= DATEADD(year, -1, GETDATE()) GROUP BY donor_id, YEAR(donation_date), MONTH(donation_date) HAVING COUNT(*) > 1) t GROUP BY donation_year, donation_month;
gretelai_synthetic_text_to_sql
CREATE TABLE ports (id INT, name VARCHAR(50), country VARCHAR(50)); CREATE TABLE visits (ship_id INT, port_id INT, visit_date DATE); INSERT INTO ports (id, name, country) VALUES (1, 'Los Angeles', 'USA'), (2, 'Singapore', 'Singapore'), (3, 'Rotterdam', 'Netherlands'); INSERT INTO visits (ship_id, port_id, visit_date) VALUES (1, 1, '2020-01-01'), (1, 2, '2020-02-01'), (2, 3, '2019-01-15'), (3, 1, '2020-03-01');
List all ports where the company has operated and their first visit date.
SELECT ports.name, MIN(visits.visit_date) FROM ports INNER JOIN visits ON ports.id = visits.port_id GROUP BY ports.name;
gretelai_synthetic_text_to_sql
CREATE TABLE teacher_workshops (id INT PRIMARY KEY, workshop_name TEXT, workshop_date DATE, location TEXT, max_attendees INT);
Create a view to show the number of teachers attending each workshop
CREATE VIEW workshop_attendance AS SELECT workshop_name, COUNT(attendee_id) as num_attendees FROM teacher_workshops JOIN teacher_attendance ON teacher_workshops.id = teacher_attendance.workshop_id GROUP BY workshop_name;
gretelai_synthetic_text_to_sql
CREATE TABLE Dispensaries (id INT, name TEXT, state TEXT, social_equity_program TEXT); INSERT INTO Dispensaries (id, name, state, social_equity_program) VALUES (1, 'Green Leaf', 'California', 'SEP1'), (2, 'Buds R Us', 'California', 'SEP2'), (3, 'Happy High', 'Colorado', 'SEP3'), (4, 'Cannabis Corner', 'Colorado', 'SEP4'), (5, 'Elevated Elements', 'New York', 'SEP5');
List all social equity programs and their respective dispensary counts across the US.
SELECT social_equity_program, COUNT(DISTINCT state) as dispensary_count FROM Dispensaries GROUP BY social_equity_program;
gretelai_synthetic_text_to_sql
CREATE TABLE Employees (EmployeeID INT, LGBTQ VARCHAR(10), Salary DECIMAL(10,2)); INSERT INTO Employees (EmployeeID, LGBTQ, Salary) VALUES (7, 'Yes', 90000.00);
What is the maximum salary of employees who identify as LGBTQ+?
SELECT MAX(Salary) FROM Employees WHERE LGBTQ = 'Yes';
gretelai_synthetic_text_to_sql
CREATE TABLE cities (city_name VARCHAR(255), population INT, state_abbreviation VARCHAR(255)); INSERT INTO cities (city_name, population, state_abbreviation) VALUES ('CityA', 1500000, 'NY'), ('CityB', 800000, 'NY'), ('CityC', 2500000, 'NY'); CREATE TABLE hospitals (hospital_name VARCHAR(255), city_name VARCHAR(255)); INSERT INTO hospitals (hospital_name, city_name) VALUES ('HospitalX', 'CityA'), ('HospitalY', 'CityA'), ('HospitalZ', 'CityB');
What is the number of hospitals and the population in each city in the state of New York?
SELECT c.city_name, COUNT(h.hospital_name) AS num_hospitals, c.population FROM cities c LEFT JOIN hospitals h ON c.city_name = h.city_name GROUP BY c.city_name;
gretelai_synthetic_text_to_sql
CREATE TABLE Departments (department_id INT, department_name VARCHAR(50), manufacturer_id INT); INSERT INTO Departments (department_id, department_name, manufacturer_id) VALUES (1, 'Ethical Manufacturing', 1), (2, 'Circular Economy', 2), (3, 'Workforce Development', 3); CREATE TABLE Employees (employee_id INT, employee_name VARCHAR(50), department_id INT, gender VARCHAR(10)); INSERT INTO Employees (employee_id, employee_name, department_id, gender) VALUES (1, 'Employee1', 1, 'Female'), (2, 'Employee2', 1, 'Male'), (3, 'Employee3', 2, 'Female'), (4, 'Employee4', 3, 'Non-binary');
Count the number of female and male employees in each department
SELECT d.department_name, e.gender, COUNT(e.employee_id) AS num_employees FROM Departments d INNER JOIN Employees e ON d.department_id = e.department_id GROUP BY d.department_name, e.gender;
gretelai_synthetic_text_to_sql
CREATE TABLE Manufacturers (ManufacturerID INT, ManufacturerName VARCHAR(50)); INSERT INTO Manufacturers (ManufacturerID, ManufacturerName) VALUES (1, 'Tesla'), (2, 'Nissan'), (3, 'BMW'); CREATE TABLE Vehicles (VehicleID INT, ManufacturerID INT, VehicleType VARCHAR(50), Electric BOOLEAN); INSERT INTO Vehicles (VehicleID, ManufacturerID, VehicleType, Electric) VALUES (1, 1, 'Model S', true), (2, 1, 'Model 3', true), (3, 2, 'Leaf', true), (4, 2, 'Versa', false), (5, 3, 'i3', true), (6, 3, 'X5', false);
Find the number of electric vehicles by manufacturer
SELECT ManufacturerName, COUNT(*) as Total FROM Manufacturers m JOIN Vehicles v ON m.ManufacturerID = v.ManufacturerID WHERE Electric = true GROUP BY ManufacturerName;
gretelai_synthetic_text_to_sql
CREATE TABLE nba_games (id INT, season INT, category VARCHAR(50), home_team VARCHAR(50), away_team VARCHAR(50), points_home INT, points_away INT);
Find the average number of points scored by each team in the NBA during the 2021-2022 regular season.
SELECT home_team, AVG(points_home) as avg_points FROM nba_games WHERE season = 2021 AND category = 'regular' GROUP BY home_team; SELECT away_team, AVG(points_away) as avg_points FROM nba_games WHERE season = 2021 AND category = 'regular' GROUP BY away_team;
gretelai_synthetic_text_to_sql
CREATE TABLE Properties (id INT, price INT, sustainable BOOLEAN); INSERT INTO Properties (id, price, sustainable) VALUES (1, 600000, TRUE), (2, 500000, FALSE), (3, 800000, TRUE), (4, 700000, FALSE);
What is the average property price in sustainable communities?
SELECT AVG(price) AS avg_price_sustainable FROM Properties WHERE sustainable = TRUE;
gretelai_synthetic_text_to_sql
CREATE TABLE Artists (artist_id INT, artist_name VARCHAR(255)); INSERT INTO Artists (artist_id, artist_name) VALUES (1, 'Artist1'), (2, 'Artist2'), (3, 'Artist3'); CREATE TABLE Genres (genre_id INT, genre_name VARCHAR(255)); INSERT INTO Genres (genre_id, genre_name) VALUES (1, 'Pop'), (2, 'Rock'); CREATE TABLE Plays (play_id INT, song_id INT, artist_id INT, genre_id INT); INSERT INTO Plays (play_id, song_id, artist_id, genre_id) VALUES (1, 1, 1, 1), (2, 2, 1, 1), (3, 3, 2, 2);
Who are the top 3 artists by total plays in a genre?
SELECT a.artist_name, g.genre_name, SUM(p.plays) AS total_plays FROM Artists a JOIN Plays p ON a.artist_id = p.artist_id JOIN Songs s ON p.song_id = s.song_id JOIN Albums al ON s.album_id = al.album_id JOIN Genres g ON al.genre_id = g.genre_id GROUP BY a.artist_name, g.genre_name ORDER BY total_plays DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE sales (product_id VARCHAR(255), sale_date DATE, quantity INT); INSERT INTO sales (product_id, sale_date, quantity) VALUES ('A', '2021-05-01', 5), ('A', '2021-05-02', 3), ('B', '2021-05-01', 7), ('C', '2022-05-01', 10);
What is the total quantity of products sold in the month of May in 2021 and 2022?
SELECT SUM(quantity) FROM sales WHERE MONTH(sale_date) = 5 AND (YEAR(sale_date) = 2021 OR YEAR(sale_date) = 2022);
gretelai_synthetic_text_to_sql
CREATE TABLE water_conservation (id INT PRIMARY KEY, location VARCHAR(50), water_savings FLOAT);
Create a table named 'water_conservation'
CREATE TABLE water_conservation (id INT PRIMARY KEY, location VARCHAR(50), water_savings FLOAT);
gretelai_synthetic_text_to_sql
CREATE TABLE PublicWorks(project_id INT, budget INT, location VARCHAR(255)); INSERT INTO PublicWorks VALUES(1,600000,'CityA'),(2,400000,'CityB'),(3,700000,'CityC'),(4,300000,'CityD'),(5,800000,'CityE'),(6,250000,'CityF');
What is the total number of public works projects in 'PublicWorks' table with a budget over 500000?
SELECT COUNT(*) FROM PublicWorks WHERE budget > 500000;
gretelai_synthetic_text_to_sql
CREATE TABLE military_bases(base_id INT, country VARCHAR(255), region VARCHAR(255)); INSERT INTO military_bases(base_id, country, region) VALUES (1, 'Australia', 'Oceania'), (2, 'New Zealand', 'Oceania'), (3, 'Papua New Guinea', 'Oceania'), (4, 'Fiji', 'Oceania'), (5, 'United States', 'Oceania'), (6, 'France', 'Oceania'), (7, 'United Kingdom', 'Oceania');
What is the total number of military bases in Oceania?
SELECT COUNT(*) FROM military_bases WHERE region = 'Oceania';
gretelai_synthetic_text_to_sql
CREATE TABLE polar_bear_sightings (sighting_date DATE, region VARCHAR(50)); INSERT INTO polar_bear_sightings (sighting_date, region) VALUES ('2010-01-01', 'Arctic North America'), ('2010-01-05', 'Arctic Europe');
How many polar bear sightings are in each Arctic region per year?
SELECT e.region, EXTRACT(YEAR FROM e.sighting_date) as year, COUNT(e.sighting_date) as sighting_count FROM polar_bear_sightings e GROUP BY e.region, e.sighting_date;
gretelai_synthetic_text_to_sql
CREATE TABLE social_media_users (id INT, country VARCHAR(2)); INSERT INTO social_media_users (id, country) VALUES (1, 'USA'), (2, 'Canada'); CREATE TABLE user_activity (user_id INT, post_id INT, likes INT, hashtags VARCHAR(255)); INSERT INTO user_activity (user_id, post_id, likes, hashtags) VALUES (1, 1, 10, '#nature'), (1, 2, 5, '#nature'), (1, 3, 8, '#travel'), (2, 4, 3, '#nature');
How many users from the USA in the "social_media_users" table liked at least 5 posts with the hashtag "#nature" in the "user_activity" table?
SELECT COUNT(DISTINCT su.id) FROM social_media_users su JOIN user_activity ua ON su.id = ua.user_id WHERE su.country = 'USA' AND ua.hashtags LIKE '%#nature%' GROUP BY su.id HAVING COUNT(ua.likes) >= 5;
gretelai_synthetic_text_to_sql
CREATE TABLE student_mental_health (student_id INT, mental_health_score INT, subject VARCHAR(255)); INSERT INTO student_mental_health (student_id, mental_health_score, subject) VALUES (1, 80, 'Mathematics'), (2, 90, 'Computer Science'), (3, 70, 'Computer Science'), (4, 85, 'English');
What is the average mental health score for students in each subject, ranked by score?
SELECT subject, AVG(mental_health_score) as avg_score, RANK() OVER (ORDER BY AVG(mental_health_score) DESC) as rank FROM student_mental_health GROUP BY subject ORDER BY rank;
gretelai_synthetic_text_to_sql
CREATE TABLE crime_statistics (crime_type VARCHAR(255), count INT, location VARCHAR(255));
Create a view to display top 3 crime types by count
CREATE VIEW top_3_crime_types AS SELECT crime_type, count FROM crime_statistics GROUP BY crime_type ORDER BY count DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE safety_tests (id INT PRIMARY KEY, company VARCHAR(255), brand VARCHAR(255), test_location VARCHAR(255), test_date DATE, safety_rating INT);
Show the total number of safety tests performed for each brand
SELECT brand, COUNT(*) as total_tests FROM safety_tests GROUP BY brand;
gretelai_synthetic_text_to_sql
CREATE TABLE users (user_id INT, first_name VARCHAR(50), last_name VARCHAR(50), age INT, gender VARCHAR(10), country VARCHAR(50));CREATE TABLE ad_activity (activity_id INT, user_id INT, ad_id INT, activity_type VARCHAR(50), activity_date DATE);CREATE TABLE ads (ad_id INT, ad_name VARCHAR(255), ad_category VARCHAR(255));
List all the users who have clicked on ads related to "vegan diet" in the past 3 months, along with their demographic info and the number of times they clicked on the ad.
SELECT u.first_name, u.last_name, u.age, u.gender, u.country, COUNT(a.activity_id) as clicks FROM users u JOIN ad_activity a ON u.user_id = a.user_id JOIN ads ad ON a.ad_id = ad.ad_id WHERE ad.ad_name LIKE '%vegan diet%' AND a.activity_date >= (CURRENT_DATE - INTERVAL 3 MONTH) AND a.activity_type = 'click' GROUP BY u.user_id;
gretelai_synthetic_text_to_sql
CREATE TABLE virtual_tours (tour_id INT, hotel_id INT, country TEXT, date DATE); INSERT INTO virtual_tours (tour_id, hotel_id, country, date) VALUES (1, 1, 'India', '2022-03-05'), (2, 2, 'Japan', '2022-03-10'), (3, 3, 'China', '2022-03-15');
How many virtual tours were conducted in Asia in the last month?
SELECT COUNT(*) FROM virtual_tours WHERE country IN ('India', 'Japan', 'China') AND date >= DATEADD(day, -30, GETDATE());
gretelai_synthetic_text_to_sql
CREATE TABLE renewable_energy (country VARCHAR(50), source VARCHAR(50), amount NUMERIC(12,2)); INSERT INTO renewable_energy (country, source, amount) VALUES ('Argentina', 'Wind', 500.50), ('Argentina', 'Solar', 700.20), ('Brazil', 'Wind', 800.00), ('Brazil', 'Solar', 1000.00), ('Canada', 'Wind', 1200.00), ('Canada', 'Solar', 1500.00), ('USA', 'Wind', 1800.00), ('USA', 'Solar', 2000.00);
What is the total amount of climate finance spent on renewable energy sources in South America and North America?
SELECT SUM(amount) FROM renewable_energy WHERE country IN ('South America', 'North America') AND source IN ('Wind', 'Solar');
gretelai_synthetic_text_to_sql
CREATE TABLE fish_stock (species VARCHAR(255), dissolved_oxygen FLOAT); CREATE TABLE ocean_health (species VARCHAR(255), dissolved_oxygen FLOAT); INSERT INTO fish_stock (species, dissolved_oxygen) VALUES ('Tilapia', 6.5), ('Salmon', 7.1); INSERT INTO ocean_health (species, dissolved_oxygen) VALUES ('Tilapia', 6.8), ('Salmon', 7.4);
What is the maximum dissolved oxygen level for each species, grouped by species, from the 'fish_stock' and 'ocean_health' tables?
SELECT f.species, MAX(f.dissolved_oxygen) FROM fish_stock f INNER JOIN ocean_health o ON f.species = o.species GROUP BY f.species;
gretelai_synthetic_text_to_sql
CREATE TABLE FOOD_ITEMS (id INT, name VARCHAR(50), category VARCHAR(50), is_organic BOOLEAN, avg_calories FLOAT); INSERT INTO FOOD_ITEMS (id, name, category, is_organic, avg_calories) VALUES (1, 'Apple', 'Fruit', true, 95), (2, 'Broccoli', 'Vegetable', true, 55);
What is the average calorie count for organic items in the FOOD_ITEMS table?
SELECT AVG(avg_calories) FROM FOOD_ITEMS WHERE is_organic = true AND category = 'Fruit';
gretelai_synthetic_text_to_sql
CREATE TABLE animals (id INT, name VARCHAR(50), species VARCHAR(50), population INT, habitat VARCHAR(50)); INSERT INTO animals (id, name, species, population, habitat) VALUES (5, 'Frog', 'Amphibian', 150, 'Wetlands'); INSERT INTO animals (id, name, species, population, habitat) VALUES (6, 'Duck', 'Bird', 75, 'Wetlands');
What is the total population of all animals in the wetlands habitat?
SELECT SUM(population) FROM animals WHERE habitat = 'Wetlands';
gretelai_synthetic_text_to_sql
CREATE TABLE power_plants (id INT, state VARCHAR(50), type VARCHAR(50), capacity FLOAT); INSERT INTO power_plants (id, state, type, capacity) VALUES (1, 'New York', 'Solar', 500), (2, 'New York', 'Wind', 700), (3, 'California', 'Solar', 800);
List the renewable energy power plants and their capacities (MW) in New York
SELECT type, capacity FROM power_plants WHERE state = 'New York';
gretelai_synthetic_text_to_sql
CREATE TABLE donors (id INT, donor_name TEXT, country TEXT); CREATE TABLE donations (id INT, donor_id INT, donation_amount DECIMAL(10,2)); INSERT INTO donors (id, donor_name, country) VALUES (1, 'John Doe', 'CA'), (2, 'Jane Smith', 'CA'), (3, 'Mary Johnson', 'US'); INSERT INTO donations (id, donor_id, donation_amount) VALUES (1, 1, 50.00), (2, 2, 100.00), (3, 1, 150.00);
Who are the top 5 donors in Canada?
SELECT donor_name, SUM(donation_amount) as total_donation FROM donations JOIN donors ON donations.donor_id = donors.id WHERE country = 'CA' GROUP BY donor_name ORDER BY total_donation DESC LIMIT 5;
gretelai_synthetic_text_to_sql
CREATE TABLE mining_operations (employee_id INT, first_name VARCHAR(50), last_name VARCHAR(50), position VARCHAR(50), age INT, country VARCHAR(50)); INSERT INTO mining_operations (employee_id, first_name, last_name, position, age, country) VALUES (1, 'John', 'Doe', 'Engineer', 35, 'USA'); INSERT INTO mining_operations (employee_id, first_name, last_name, position, age, country) VALUES (2, 'Jane', 'Smith', 'Supervisor', 42, 'Canada'); INSERT INTO mining_operations (employee_id, first_name, last_name, position, age, country) VALUES (7, 'Eva', 'Green', 'Engineer', 32, 'France');
What is the average age of employees in each position in the 'mining_operations' table?
SELECT position, AVG(age) FROM mining_operations GROUP BY position;
gretelai_synthetic_text_to_sql
CREATE TABLE SalesByDate (product VARCHAR(255), country VARCHAR(255), date DATE, quantity INT);
How many eyeshadows have been sold in Canada in the past year?
SELECT COUNT(*) FROM SalesByDate WHERE product = 'Eyeshadow' AND country = 'Canada' AND date >= DATEADD(year, -1, GETDATE());
gretelai_synthetic_text_to_sql
CREATE TABLE community_development (id INT, initiative_name VARCHAR(50), number_of_participants INT); INSERT INTO community_development VALUES (1, 'Youth Skills Training', 100), (2, 'Women Empowerment', 120), (3, 'Elderly Care', 80), (4, 'Environmental Conservation', 150), (5, 'Cultural Preservation', 110);
What is the name of the community development initiative with the least number of participants in the 'community_development' table?;
SELECT initiative_name FROM community_development WHERE number_of_participants = (SELECT MIN(number_of_participants) FROM community_development);
gretelai_synthetic_text_to_sql
CREATE TABLE reverse_logistics (return_id INT, return_reason VARCHAR(50), return_quantity INT); INSERT INTO reverse_logistics (return_id, return_reason, return_quantity) VALUES (1, 'Damaged', 50), (2, 'Wrong Item', 75), (3, 'Return to Stock', 100);
What is the total number of 'returns' in the 'reverse_logistics' table?
SELECT SUM(return_quantity) FROM reverse_logistics WHERE return_reason = 'Return to Stock';
gretelai_synthetic_text_to_sql
CREATE TABLE community_initiative (initiative_id INT, initiative_name VARCHAR(50), year INT, completed BOOLEAN); INSERT INTO community_initiative (initiative_id, initiative_name, year, completed) VALUES (1, 'Community Health Center', 2020, true);
How many community development initiatives were completed in 2020 and 2021 in the 'rural_development' database?
SELECT COUNT(*) FROM community_initiative WHERE year IN (2020, 2021) AND completed = true;
gretelai_synthetic_text_to_sql
CREATE TABLE recycling_rates(year INT, material VARCHAR(255), recycling_rate DECIMAL(5,2)); INSERT INTO recycling_rates VALUES (2018, 'Paper', 0.45), (2018, 'Plastic', 0.20), (2018, 'Glass', 0.35), (2019, 'Paper', 0.47), (2019, 'Plastic', 0.21), (2019, 'Glass', 0.36), (2020, 'Paper', 0.50), (2020, 'Plastic', 0.23), (2020, 'Glass', 0.38);
Which materials had a lower recycling rate in 2020 compared to 2018?
SELECT material, (r20.recycling_rate - r18.recycling_rate) AS difference FROM recycling_rates r20 JOIN recycling_rates r18 ON r20.material = r18.material WHERE r20.year = 2020 AND r18.year = 2018 AND r20.recycling_rate < r18.recycling_rate;
gretelai_synthetic_text_to_sql
CREATE TABLE FabricSources (source_id INT, fabric_type VARCHAR(255), country_of_origin VARCHAR(255), ethical_rating DECIMAL(3,2));CREATE TABLE Garments (garment_id INT, trend_id INT, fabric_source_id INT, size VARCHAR(50), style VARCHAR(255));CREATE VIEW HandwovenFabric AS SELECT * FROM FabricSources WHERE fabric_type = 'Handwoven';CREATE VIEW PlusSizeGarments AS SELECT * FROM Garments WHERE size LIKE '%Plus%';
What is the average ethical rating of Handwoven fabric sources for Plus Size garments?
SELECT AVG(ethical_rating) FROM HandwovenFabric HF JOIN PlusSizeGarments PSG ON HF.source_id = PSG.fabric_source_id;
gretelai_synthetic_text_to_sql
CREATE TABLE Customers (customer_id INT, customer_name TEXT); CREATE TABLE Brands (brand_id INT, brand_name TEXT, is_sustainable_sourcing BOOLEAN); CREATE TABLE Brand_Customers (brand_id INT, customer_id INT);
Find the number of unique customers who purchased items from brands with sustainable textile sourcing.
SELECT COUNT(DISTINCT c.customer_id) FROM Customers c JOIN Brand_Customers bc ON c.customer_id = bc.customer_id JOIN Brands b ON bc.brand_id = b.brand_id WHERE b.is_sustainable_sourcing = TRUE;
gretelai_synthetic_text_to_sql
CREATE TABLE france_energy_efficiency (id INT PRIMARY KEY, year INT, sector VARCHAR(30), improvement_percent FLOAT); INSERT INTO france_energy_efficiency (id, year, sector, improvement_percent) VALUES (1, 2019, 'Industry', 2.0), (2, 2019, 'Residential', 2.5), (3, 2019, 'Commercial', 2.2), (4, 2019, 'Transportation', 1.8);
What is the total energy efficiency improvement (in percentage) in France for 2019, grouped by sector?
SELECT year, sector, SUM(improvement_percent) as total_improvement_percent FROM france_energy_efficiency WHERE year = 2019 GROUP BY year, sector;
gretelai_synthetic_text_to_sql
CREATE TABLE volunteer_signups (id INT, state VARCHAR(50), signup_date DATE); INSERT INTO volunteer_signups (id, state, signup_date) VALUES (1, 'NY', '2021-03-01'); INSERT INTO volunteer_signups (id, state, signup_date) VALUES (2, 'CA', '2021-02-15');
Which states had the most volunteer signups in 2021?
SELECT state, COUNT(*) as num_signups FROM volunteer_signups WHERE signup_date >= '2021-01-01' AND signup_date < '2022-01-01' GROUP BY state ORDER BY num_signups DESC LIMIT 5;
gretelai_synthetic_text_to_sql
CREATE TABLE Galleries (gallery_id INT, gallery_name VARCHAR(255)); INSERT INTO Galleries (gallery_id, gallery_name) VALUES (1, 'Guggenheim Museum'), (2, 'Louvre Museum');
Add records of new galleries into the 'Galleries' table.
INSERT INTO Galleries (gallery_id, gallery_name) VALUES (3, 'Museum of Modern Art, Paris'), (4, 'Museum of Contemporary Art, Tokyo');
gretelai_synthetic_text_to_sql
CREATE TABLE food_trucks.restaurants (restaurant_id INT, name TEXT, sustainable_certification BOOLEAN); INSERT INTO food_trucks.restaurants (restaurant_id, name, sustainable_certification) VALUES (1, 'Tasty Bites', false), (2, 'Lunch Rush', true);
List the names of restaurants in the 'food_trucks' schema that do not have a sustainable sourcing certification.
SELECT name FROM food_trucks.restaurants WHERE sustainable_certification = false;
gretelai_synthetic_text_to_sql
CREATE TABLE explainable_ai (id INT, paper_name VARCHAR(50), publication_year INT, region VARCHAR(50)); INSERT INTO explainable_ai (id, paper_name, publication_year, region) VALUES (1, 'Interpretable Machine Learning Methods', 2020, 'North America'), (2, 'Visualizing Decision Trees for Explainability', 2019, 'Europe'), (3, 'Explainable AI for Healthcare Applications', 2021, 'Asia');
What is the number of explainable AI research papers published per year, segmented by region?
SELECT publication_year, region, COUNT(*) FROM explainable_ai GROUP BY publication_year, region;
gretelai_synthetic_text_to_sql
CREATE TABLE attorneys (id INT, name TEXT, region TEXT, specialty TEXT); INSERT INTO attorneys (id, name, region, specialty) VALUES (1, 'Jane Smith', 'New York', 'Personal Injury'), (2, 'John Doe', 'Boston', 'Criminal Law'), (3, 'Sarah Lee', 'New York', 'Bankruptcy'); CREATE TABLE cases (id INT, attorney_id INT, billing_amount INT); INSERT INTO cases (id, attorney_id, billing_amount) VALUES (1, 1, 1000), (2, 1, 2000), (3, 2, 3000), (4, 3, 4000), (5, 3, 5000);
What is the total billing amount for cases handled by attorneys in the 'New York' region who specialize in 'Personal Injury'?
SELECT SUM(billing_amount) FROM cases INNER JOIN attorneys ON cases.attorney_id = attorneys.id WHERE attorneys.region = 'New York' AND attorneys.specialty = 'Personal Injury';
gretelai_synthetic_text_to_sql
CREATE TABLE startups(id INT, name TEXT, founder TEXT, total_funding FLOAT, country TEXT); INSERT INTO startups(id, name, founder, total_funding, country) VALUES (1, 'Acme Inc', 'John Doe', 20000000.00, 'US'), (2, 'Beta Corp', 'Jane Smith', 30000000.00, 'UK');
What is the total funding received by startups founded by women in the US?
SELECT SUM(total_funding) FROM startups WHERE founder = 'Jane Smith' AND country = 'US';
gretelai_synthetic_text_to_sql
CREATE TABLE Oceans (id INT, name VARCHAR(20)); INSERT INTO Oceans (id, name) VALUES (1, 'Pacific'), (2, 'Atlantic'); CREATE TABLE SpeciesObservations (id INT, ocean_id INT, species VARCHAR(50), count INT); INSERT INTO SpeciesObservations (id, ocean_id, species, count) VALUES (1, 1, 'Shark', 500), (2, 1, 'Whale', 300), (3, 2, 'Shark', 700), (4, 2, 'Dolphin', 600);
What is the total number of marine life species observed in the Atlantic Ocean that are not sharks?
SELECT SUM(SpeciesObservations.count) FROM SpeciesObservations JOIN Oceans ON SpeciesObservations.ocean_id = Oceans.id WHERE Oceans.name = 'Atlantic' AND SpeciesObservations.species != 'Shark';
gretelai_synthetic_text_to_sql
CREATE TABLE weather (location VARCHAR(255), temperature INT, date DATE);
What is the average temperature in 'Tokyo' for the month of 'August' in the 'weather' table?
SELECT AVG(temperature) FROM weather WHERE location = 'Tokyo' AND EXTRACT(MONTH FROM date) = 8;
gretelai_synthetic_text_to_sql
CREATE TABLE Donations (DonationID INT, DonorID INT, Amount FLOAT, DonationDate DATE); INSERT INTO Donations (DonationID, DonorID, Amount, DonationDate) VALUES (1, 1, 500.00, '2021-01-01'), (2, 1, 250.00, '2021-02-14'), (3, 2, 750.00, '2022-01-05'), (4, 3, 1000.00, '2022-02-20');
What was the total amount donated by new donors in Q1 2022, compared to Q1 2021?
SELECT YEAR(DonationDate) as Year, SUM(Amount) as TotalDonated FROM Donations WHERE DonationDate BETWEEN '2021-01-01' AND '2021-03-31' AND DonorID NOT IN (SELECT DonorID FROM Donations WHERE DonationDate BETWEEN '2020-01-01' AND '2020-03-31') GROUP BY Year;
gretelai_synthetic_text_to_sql
CREATE TABLE BrandRevenue (brand VARCHAR(255), revenue DECIMAL(10,2), year INT, sustainable_supply_chain BOOLEAN);
What is the total revenue generated by brands that have a sustainable supply chain, in the year 2020?
SELECT SUM(revenue) FROM BrandRevenue WHERE sustainable_supply_chain = TRUE AND year = 2020;
gretelai_synthetic_text_to_sql
CREATE TABLE extraction (id INT PRIMARY KEY, site_id INT, mineral VARCHAR(50), quantity INT, year INT);
Insert new mineral extraction data
INSERT INTO extraction (site_id, mineral, quantity, year) VALUES (1, 'Iron', 500, 2021);
gretelai_synthetic_text_to_sql
CREATE TABLE media_library (id INT, type VARCHAR(10), title VARCHAR(50), length FLOAT, source VARCHAR(50)); INSERT INTO media_library (id, type, title, length, source) VALUES (1, 'article', 'Sample Article on Climate Change', 5.5, 'BBC'); INSERT INTO media_library (id, type, title, length, source) VALUES (2, 'video', 'Sample Video on Climate', 12.3, 'CNN');
What are the articles and videos with the word 'climate' in the title in the 'media_library'?
SELECT * FROM media_library WHERE (type = 'article' OR type = 'video') AND title LIKE '%climate%';
gretelai_synthetic_text_to_sql
CREATE TABLE cultural_sites (site_id INT, name TEXT, country TEXT, num_virtual_tours INT); INSERT INTO cultural_sites (site_id, name, country, num_virtual_tours) VALUES (1, 'Colosseum', 'Italy', 3), (2, 'Canal Grande', 'Italy', 2), (3, 'Leaning Tower', 'Italy', 4);
How many virtual tours are available for each cultural heritage site in Italy?
SELECT name, num_virtual_tours FROM cultural_sites WHERE country = 'Italy';
gretelai_synthetic_text_to_sql
CREATE TABLE daily_sales (sale_date DATE, menu_category VARCHAR(255), revenue INT);
What is the daily revenue for each menu category?
SELECT sale_date, menu_category, SUM(revenue) as daily_revenue FROM daily_sales GROUP BY sale_date, menu_category;
gretelai_synthetic_text_to_sql
CREATE TABLE drug_sales (drug_name VARCHAR(255), sales INT); INSERT INTO drug_sales (drug_name, sales) VALUES ('DrugA', 5000000), ('DrugB', 7000000), ('DrugC', 8000000); CREATE TABLE drug_approval (drug_name VARCHAR(255), approval_year INT); INSERT INTO drug_approval (drug_name, approval_year) VALUES ('DrugA', 2019), ('DrugB', 2020), ('DrugC', 2018);
What is the total sales of the drugs that were approved in 2020?
SELECT ds.sales FROM drug_sales ds JOIN drug_approval da ON ds.drug_name = da.drug_name WHERE da.approval_year = 2020;
gretelai_synthetic_text_to_sql
CREATE TABLE playlist_users (playlist_id INT, user_id INT); INSERT INTO playlist_users (playlist_id, user_id) VALUES (1, 1), (2, 2), (3, 1), (4, 3), (5, 4);
Display the number of unique users who have created playlists.
SELECT COUNT(DISTINCT user_id) AS num_users FROM playlist_users;
gretelai_synthetic_text_to_sql
CREATE TABLE attendance (id INT, age INT, event VARCHAR(50), visitors INT); INSERT INTO attendance (id, age, event, visitors) VALUES (1, 18, 'Art of the Americas', 500), (2, 25, 'Art of the Americas', 700), (3, 35, 'Art of the Americas', 800), (4, 19, 'Women in Art', 400), (5, 27, 'Women in Art', 600);
Calculate attendance by age group for the 'Women in Art' event.
SELECT event, AVG(age) as avg_age, COUNT(*) as total FROM attendance WHERE event = 'Women in Art' GROUP BY event;
gretelai_synthetic_text_to_sql
CREATE TABLE FemaleStartups(id INT, name TEXT, continent TEXT, founding_year INT, funding_amount INT); INSERT INTO FemaleStartups VALUES (1, 'FemTech', 'North America', 2018, 8000000), (2, 'GreenCity', 'North America', 2019, 9000000), (3, 'AI-Health', 'Europe', 2020, 7000000), (4, 'SolarEnergy', 'Australia', 2017, 6000000), (5, 'DataAnalytics', 'Europe', 2016, 5000000), (6, 'SmartGrid', 'North America', 2021, 10000000), (7, 'CloudServices', 'Asia', 2018, 4000000), (8, 'RenewableEnergy', 'South America', 2019, 11000000), (9, 'WasteManagement', 'Africa', 2020, 3000000);
List the top 3 continents with the highest average funding amount for female-led startups in the past 3 years.
SELECT continent, AVG(funding_amount) AS avg_funding FROM FemaleStartups WHERE founding_year >= YEAR(CURRENT_DATE) - 3 GROUP BY continent ORDER BY avg_funding DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE spacecraft_temperatures (spacecraft_name TEXT, temperature FLOAT, mission_date DATE);
What is the average temperature (in Kelvin) per spacecraft, ranked in descending order?
SELECT spacecraft_name, AVG(temperature) as avg_temperature, RANK() OVER (ORDER BY AVG(temperature) DESC) as temp_rank FROM spacecraft_temperatures GROUP BY spacecraft_name ORDER BY temp_rank;
gretelai_synthetic_text_to_sql
CREATE TABLE funding_records (funding_id INT, company_id INT, funding_amount DECIMAL(10, 2)); INSERT INTO funding_records (funding_id, company_id, funding_amount) VALUES (1, 1, 5000000.00), (2, 2, 7000000.00), (3, 3, 1000000.00);
Show startups with no funding records.
SELECT company_id FROM company_founding WHERE company_id NOT IN (SELECT company_id FROM funding_records);
gretelai_synthetic_text_to_sql
CREATE TABLE menu_categories (menu_category VARCHAR(50), num_gluten_free INT); INSERT INTO menu_categories (menu_category, num_gluten_free) VALUES ('Appetizers', 1), ('Entrees', 2), ('Desserts', 1);
What is the percentage of gluten-free items in each menu category?
SELECT menu_category, (num_gluten_free::DECIMAL / (SELECT SUM(num_gluten_free) FROM menu_categories)) * 100 FROM menu_categories;
gretelai_synthetic_text_to_sql
CREATE TABLE department (id INT, name TEXT);CREATE TABLE faculty (id INT, department_id INT);CREATE TABLE research_grant (id INT, faculty_id INT, amount INT);
What is the total amount of research grants awarded to faculty members in the Computer Science department?
SELECT SUM(rg.amount) FROM research_grant rg JOIN faculty f ON rg.faculty_id = f.id JOIN department d ON f.department_id = d.id WHERE d.name = 'Computer Science';
gretelai_synthetic_text_to_sql