context
stringlengths 11
9.12k
| question
stringlengths 0
1.06k
| SQL
stringlengths 2
4.44k
| source
stringclasses 28
values |
|---|---|---|---|
CREATE TABLE autonomous_trains (train_id INT, trip_duration INT, start_speed INT, end_speed INT, trip_date DATE); INSERT INTO autonomous_trains (train_id, trip_duration, start_speed, end_speed, trip_date) VALUES (1, 1200, 5, 15, '2022-01-01'), (2, 900, 10, 20, '2022-01-02'); CREATE TABLE city_coordinates (city VARCHAR(50), latitude DECIMAL(9,6), longitude DECIMAL(9,6)); INSERT INTO city_coordinates (city, latitude, longitude) VALUES ('Sydney', -33.8679, 151.2071);
|
What is the average speed of autonomous trains in Sydney?
|
SELECT AVG(end_speed - start_speed) as avg_speed FROM autonomous_trains, city_coordinates WHERE city_coordinates.city = 'Sydney';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE incidents (id INT, incident_date DATE, location TEXT, offender_id INT, victim_id INT); INSERT INTO incidents (id, incident_date, location, offender_id, victim_id) VALUES (1, '2021-01-01', 'New York', 1, 1), (2, '2021-02-01', 'California', 2, 2);
|
What is the number of unique victims and offenders for each incident date, for incidents that occurred in 'California'?
|
SELECT incident_date, COUNT(DISTINCT offender_id) AS unique_offenders, COUNT(DISTINCT victim_id) AS unique_victims FROM incidents WHERE location = 'California' GROUP BY incident_date;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE games (id INT, team_id INT, day VARCHAR(50)); CREATE TABLE ticket_sales (id INT, game_id INT, num_tickets INT);
|
What are the total ticket sales for all teams playing on a Friday?
|
SELECT SUM(ticket_sales.num_tickets) FROM ticket_sales JOIN games ON ticket_sales.game_id = games.id WHERE games.day = 'Friday';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE agency_cybersecurity_incidents (incident_id INT, agency VARCHAR(50), incident_type VARCHAR(50), incident_date DATE); INSERT INTO agency_cybersecurity_incidents VALUES (1, 'CIA', 'Malware Attack', '2022-02-10');
|
List the defense agencies that have not had any cybersecurity incidents in the last 6 months.
|
SELECT DISTINCT agency FROM agency_cybersecurity_incidents WHERE agency NOT IN (SELECT agency FROM agency_cybersecurity_incidents WHERE incident_date >= (CURRENT_DATE - INTERVAL '6 months')) ORDER BY agency;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE customers (customer_id INT, name VARCHAR(255)); CREATE TABLE retail_bank_transactions (transaction_id INT, customer_id INT, amount DECIMAL(10,2), trans_date DATE);
|
What is the total value of transactions for each customer for the last 30 days for a retail bank?
|
SELECT customers.name, SUM(retail_bank_transactions.amount) FROM customers INNER JOIN retail_bank_transactions ON customers.customer_id = retail_bank_transactions.customer_id WHERE retail_bank_transactions.trans_date >= NOW() - INTERVAL '30 days' GROUP BY customers.name;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE healthcare_expenditure (id INT, location VARCHAR(50), disease_category VARCHAR(50), expenditure INT); INSERT INTO healthcare_expenditure (id, location, disease_category, expenditure) VALUES (1, 'California', 'Cancer', 100000);
|
What is the total healthcare expenditure in rural areas of California, broken down by disease category?
|
SELECT healthcare_expenditure.disease_category, SUM(healthcare_expenditure.expenditure) FROM healthcare_expenditure WHERE healthcare_expenditure.location = 'California' AND healthcare_expenditure.location LIKE '%rural%' GROUP BY healthcare_expenditure.disease_category;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE file_access_logs (id INT, file_path VARCHAR(255), access_time TIMESTAMP, is_sensitive BOOLEAN);
|
What are the top 10 most frequently accessed sensitive files in the past week?
|
SELECT file_path, COUNT(*) as access_count FROM file_access_logs WHERE is_sensitive = TRUE AND access_time >= NOW() - INTERVAL '1 week' GROUP BY file_path ORDER BY access_count DESC LIMIT 10;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE europium_production (id INT, country TEXT, year INT, europium_prod FLOAT); INSERT INTO europium_production (id, country, year, europium_prod) VALUES (1, 'China', 2018, 5000.0), (2, 'Russia', 2018, 3000.0), (3, 'Australia', 2018, 2000.0), (4, 'Brazil', 2018, 1000.0);
|
What is the percentage of Europium production in the world by country for the year 2018?
|
SELECT country, (europium_prod / SUM(europium_prod) OVER ()) * 100 as europium_percentage FROM europium_production WHERE year = 2018;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE fish_species (id INT, name VARCHAR(255)); INSERT INTO fish_species (id, name) VALUES (1, 'Salmon'), (2, 'Tilapia'), (3, 'Cod'); CREATE TABLE oxygen_readings (id INT, fish_id INT, date DATE, level FLOAT); INSERT INTO oxygen_readings (id, fish_id, date, level) VALUES (1, 1, '2021-01-01', 6.5), (2, 1, '2021-01-02', 6.8), (3, 2, '2021-01-01', 7.2), (4, 3, '2021-02-02', 6.9);
|
What is the change in dissolved oxygen levels for each fish species over time, partitioned by month?
|
SELECT f.name, DATE_TRUNC('month', o.date) as month, o.level - LAG(o.level) OVER (PARTITION BY f.id, DATE_TRUNC('month', o.date) ORDER BY o.date) as change FROM oxygen_readings o JOIN fish_species f ON o.fish_id = f.id ORDER BY o.date;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Textiles (id INT, country VARCHAR(20), price DECIMAL(5,2)); CREATE VIEW TextilesByCountry AS SELECT country, AVG(price) as avg_price FROM Textiles GROUP BY country;
|
What is the average price of textiles sourced from each country?
|
SELECT country, avg_price FROM TextilesByCountry;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE wind_turbines (id INT, country VARCHAR(255), energy_production FLOAT); INSERT INTO wind_turbines (id, country, energy_production) VALUES (1, 'Germany', 2500.5), (2, 'France', 2300.7), (3, 'Germany', 2450.3), (4, 'France', 2700.9);
|
What is the average energy production per wind turbine in Germany and France?
|
SELECT AVG(energy_production) as avg_energy_production, country FROM wind_turbines GROUP BY country;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE rugby (id INT, player VARCHAR(50), team VARCHAR(50), league VARCHAR(50), tries INT); INSERT INTO rugby (id, player, team, league, tries) VALUES (1, 'Jonny May', 'England', 'Six Nations Championship', 5); INSERT INTO rugby (id, player, team, league, tries) VALUES (2, 'Jacob Stockdale', 'Ireland', 'Six Nations Championship', 4);
|
What is the total number of tries scored by rugby players in the Six Nations Championship?
|
SELECT SUM(tries) FROM rugby WHERE league = 'Six Nations Championship';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Buildings (id INT, country VARCHAR(50), energy_efficiency FLOAT); INSERT INTO Buildings (id, country, energy_efficiency) VALUES (1, 'UK', 0.28), (2, 'UK', 0.32), (3, 'France', 0.24);
|
What is the average energy efficiency (in kWh/m2) of buildings in the UK?
|
SELECT AVG(energy_efficiency) FROM Buildings WHERE country = 'UK';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE arctic_biodiversity (id INTEGER, species VARCHAR(255), population INTEGER);
|
What is the total population of each species in the 'arctic_biodiversity' table?
|
SELECT species, SUM(population) AS total_population FROM arctic_biodiversity GROUP BY species;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE properties (id INT, size FLOAT, sustainable BOOLEAN, city VARCHAR(20)); INSERT INTO properties (id, size, sustainable, city) VALUES (1, 1500, TRUE, 'New York'), (2, 2000, TRUE, 'New York'), (3, 1000, FALSE, 'New York');
|
What is the average property size for sustainable urbanism initiatives in New York?
|
SELECT AVG(size) FROM properties WHERE city = 'New York' AND sustainable = TRUE;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Jobs (JobID INT, Department VARCHAR(50), OpenDate DATE, CloseDate DATE); INSERT INTO Jobs (JobID, Department, OpenDate, CloseDate) VALUES (1, 'IT', '2021-01-01', '2021-01-15'), (2, 'HR', '2021-06-01', '2021-06-30'), (3, 'IT', '2021-03-01', '2021-03-15'), (4, 'Finance', '2022-01-01', '2022-01-15');
|
What is the average time to fill job openings for each department in the company?
|
SELECT Department, AVG(DATEDIFF(day, OpenDate, CloseDate)) AS AvgTimeToFill FROM Jobs GROUP BY Department;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE TemperatureData (region VARCHAR(255), date DATE, temperature FLOAT); INSERT INTO TemperatureData (region, date, temperature) VALUES ('Arctic Ocean', '2019-01-01', -20.5), ('Arctic Ocean', '2019-01-02', -21.3), ('Arctic Ocean', '2020-01-01', -15.6), ('Arctic Ocean', '2020-01-02', -16.2);
|
What is the maximum temperature recorded in the Arctic regions for each year?
|
SELECT region, year, MAX(temperature) as max_temperature FROM (SELECT region, date, temperature, EXTRACT(YEAR FROM date) as year FROM TemperatureData) subquery GROUP BY year, region;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE products (product_id INT, name VARCHAR(50)); INSERT INTO products (product_id, name) VALUES (1, 'Lipstick A'), (2, 'Lipstick B'), (3, 'Eyeshadow C'); CREATE TABLE ingredient_suppliers (ingredient_id INT, supplier_country VARCHAR(50), product_id INT); INSERT INTO ingredient_suppliers (ingredient_id, supplier_country, product_id) VALUES (1, 'US', 1), (2, 'CA', 1), (3, 'US', 2), (4, 'MX', 3), (5, 'US', 3);
|
List all products that have ingredients sourced from multiple countries.
|
SELECT products.name FROM products INNER JOIN (SELECT product_id, COUNT(DISTINCT supplier_country) as country_count FROM ingredient_suppliers GROUP BY product_id HAVING country_count > 1) as country_data ON products.product_id = country_data.product_id;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE teacher_pd (teacher_id INT, course_id INT, course_type VARCHAR(255));
|
Delete all professional development courses of type 'Workshop' for teacher with ID 345.
|
DELETE FROM teacher_pd WHERE teacher_id = 345 AND course_type = 'Workshop';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE ConcertTickets (ticket_id INT, genre VARCHAR(20), price DECIMAL(5,2));
|
What is the average ticket price for electronic music concerts?
|
SELECT AVG(price) FROM ConcertTickets WHERE genre = 'electronic';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE DefenseProjects (id INT, project_name VARCHAR(255), region VARCHAR(255), start_date DATE, end_date DATE, budget INT, actual_cost INT, status VARCHAR(255)); INSERT INTO DefenseProjects (id, project_name, region, start_date, end_date, budget, actual_cost, status) VALUES (1, 'Project X', 'Middle East', '2018-01-01', '2020-12-31', 15000000, 16000000, 'Completed'), (2, 'Project Y', 'Middle East', '2019-01-01', '2021-12-31', 20000000, 21000000, 'On Time'), (3, 'Project Z', 'Middle East', '2020-01-01', '2023-12-31', 25000000, 26000000, 'In Progress');
|
What is the total cost of all defense projects in the Middle East that were completed before their scheduled end date?
|
SELECT SUM(budget) FROM DefenseProjects WHERE region = 'Middle East' AND (status = 'Completed' OR end_date <= CURDATE()) AND budget IS NOT NULL;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE programs(id INT, name TEXT, budget FLOAT);CREATE TABLE donations(id INT, program_id INT, amount FLOAT, donation_date DATE);
|
List the programs that have a higher average donation amount compared to the average donation amount for all programs combined.
|
SELECT programs.name FROM programs JOIN (SELECT program_id, AVG(amount) as avg_donation FROM donations GROUP BY program_id) as donations_avg ON programs.id = donations_avg.program_id WHERE donations_avg.avg_donation > (SELECT AVG(amount) FROM donations);
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Exhibitions (ExhibitionID INT PRIMARY KEY, Title VARCHAR(100), City VARCHAR(100), StartDate DATE, EndDate DATE, ArtWorkID INT, FOREIGN KEY (ArtWorkID) REFERENCES ArtWorks(ArtWorkID)); INSERT INTO Exhibitions (ExhibitionID, Title, City, StartDate, EndDate, ArtWorkID) VALUES (1, 'Artistic Revolutions', 'London', '2020-01-01', '2020-03-31', 1); INSERT INTO Exhibitions (ExhibitionID, Title, City, StartDate, EndDate, ArtWorkID) VALUES (2, 'Artistic Revolutions', 'Tokyo', '2020-04-01', '2020-06-30', 1); CREATE TABLE ArtWorks (ArtWorkID INT PRIMARY KEY, Title VARCHAR(100)); INSERT INTO ArtWorks (ArtWorkID, Title) VALUES (1, 'The Persistence of Memory');
|
Identify artworks that have been exhibited in both London and Tokyo.
|
SELECT ArtWorks.Title FROM ArtWorks INNER JOIN Exhibitions ON ArtWorks.ArtWorkID = Exhibitions.ArtWorkID WHERE Exhibitions.City IN ('London', 'Tokyo') GROUP BY ArtWorks.Title HAVING COUNT(DISTINCT Exhibitions.City) = 2;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE PRODUCT ( id INT PRIMARY KEY, name TEXT, material TEXT, quantity INT, country TEXT, certifications TEXT, is_recycled BOOLEAN ); INSERT INTO PRODUCT (id, name, material, quantity, country, certifications, is_recycled) VALUES (1, 'Organic Cotton Shirt', 'Organic Cotton', 30, 'USA', 'GOTS, Fair Trade', FALSE); INSERT INTO PRODUCT (id, name, material, quantity, country, certifications) VALUES (2, 'Recycled Poly Shoes', 'Recycled Polyester', 25, 'Germany', 'BlueSign'); INSERT INTO PRODUCT (id, name, material, quantity, country, certifications) VALUES (3, 'Bamboo T-Shirt', 'Bamboo', 15, 'China', 'OEKO-TEX'); INSERT INTO PRODUCT (id, name, material, quantity, country, certifications, is_recycled) VALUES (4, 'Recycled Denim Jeans', 'Recycled Cotton', 40, 'USA', 'GOTS', TRUE);
|
What is the total quantity of all products that are made from recycled materials?
|
SELECT SUM(quantity) FROM PRODUCT WHERE is_recycled = TRUE;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE teams (id INT, name TEXT, fans INT, location TEXT); CREATE TABLE matches (id INT, home_team INT, visiting_team INT);
|
Find all the matches where the home team has a higher number of fans than the visiting team.
|
SELECT m.id, t1.name, t2.name FROM matches m INNER JOIN teams t1 ON m.home_team = t1.id INNER JOIN teams t2 ON m.visiting_team = t2.id WHERE t1.fans > t2.fans;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Underwriters (UnderwriterID int, UnderwriterName varchar(50), TotalPolicies int, RenewedPolicies int); INSERT INTO Underwriters (UnderwriterID, UnderwriterName, TotalPolicies, RenewedPolicies) VALUES (1, 'John Smith', 250, 180), (2, 'Emily Johnson', 220, 165), (3, 'Michael Davis', 275, 210);
|
What is the policy retention rate for each underwriter?
|
SELECT UnderwriterName, RenewedPolicies * 100.0 / TotalPolicies AS PolicyRetentionRate FROM Underwriters
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE ProductionCosts (id INT, chemical VARCHAR(255), region VARCHAR(255), year INT, cost FLOAT); INSERT INTO ProductionCosts (id, chemical, region, year, cost) VALUES (1, 'chemical Y', 'midwest', 2023, 15000), (2, 'chemical Z', 'southeast', 2023, 12000);
|
What is the total production cost for chemical Y in the midwest in 2023?
|
SELECT SUM(cost) FROM ProductionCosts WHERE chemical = 'chemical Y' AND region = 'midwest' AND year = 2023;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE mining_sites (site_id INT, site_name VARCHAR(50), location VARCHAR(50), number_of_employees INT); INSERT INTO mining_sites (site_id, site_name, location, number_of_employees) VALUES (1, 'Site One', 'USA', 200), (2, 'Site Two', 'Canada', 300);
|
How many mining sites are there in the "mining_sites" table?
|
SELECT COUNT(*) FROM mining_sites;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE trainings (id INT, employee_id INT, training_name VARCHAR(50), cost FLOAT, training_year INT); INSERT INTO trainings (id, employee_id, training_name, cost, training_year) VALUES (1, 1, 'Data Science', 2000.00, 2021), (2, 1, 'Cybersecurity', 3000.00, 2021), (3, 6, 'IT Fundamentals', 1500.00, 2021);
|
What is the total training cost for IT employees in 2021?
|
SELECT SUM(cost) FROM trainings WHERE employee_id IN (SELECT id FROM employees WHERE department = 'IT') AND training_year = 2021;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE employees (id INT, name VARCHAR(50), department VARCHAR(50), age INT); INSERT INTO employees (id, name, department, age) VALUES (1, 'John Doe', 'Marketing', 35), (2, 'Jane Smith', 'Marketing', 32), (3, 'Richard Roe', 'Finance', 45), (4, 'Judy Johnson', 'Finance', 42), (5, 'Alexander Brown', 'Sales', 38), (6, 'Olivia Wilson', 'Sales', 31);
|
What is the average age of employees in the sales department?
|
SELECT AVG(age) FROM employees WHERE department = 'Sales';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE ocean_acidification (id INT, avg_level FLOAT); INSERT INTO ocean_acidification (id, avg_level) VALUES (1, 7.5); INSERT INTO ocean_acidification (id, avg_level) VALUES (2, 8.0);
|
What is the minimum ocean acidification level ever recorded?
|
SELECT MIN(avg_level) FROM ocean_acidification;
|
gretelai_synthetic_text_to_sql
|
game_stats(player_id, game_id, score, date_played)
|
Show the total score of each player in the last month
|
SELECT player_id, SUM(score) as total_score FROM game_stats WHERE date_played >= CURDATE() - INTERVAL 1 MONTH GROUP BY player_id;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE maintenance_requests (request_id INT, service_branch VARCHAR(255), request_date DATE); INSERT INTO maintenance_requests (request_id, service_branch, request_date) VALUES (1, 'Air Force', '2022-01-01'), (2, 'Navy', '2022-02-02'), (3, 'Air Force', '2022-03-03');
|
What is the minimum number of military aircraft maintenance requests recorded for the Navy in the year 2022?
|
SELECT MIN(COUNT(*)) FROM maintenance_requests WHERE service_branch = 'Navy' AND EXTRACT(YEAR FROM request_date) = 2022 GROUP BY service_branch;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE ca_projects (project_id INT, project_name VARCHAR(100), state VARCHAR(50), project_type VARCHAR(50), carbon_offset INT); INSERT INTO ca_projects (project_id, project_name, state, project_type, carbon_offset) VALUES (1, 'CA Project A', 'California', 'Wind', 5000), (2, 'CA Project B', 'California', 'Solar', 7000), (3, 'CA Project C', 'California', 'Wind', 6000);
|
What is the average carbon offset per renewable energy project in the state of California, grouped by project type?
|
SELECT project_type, AVG(carbon_offset) FROM ca_projects WHERE state = 'California' GROUP BY project_type;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Concerts (ConcertID INT, Artist VARCHAR(50), City VARCHAR(50)); INSERT INTO Concerts (ConcertID, Artist, City) VALUES (1, 'Taylor Swift', 'Los Angeles'), (2, 'BTS', 'New York'), (3, 'Adele', 'London'), (4, 'Taylor Swift', 'Paris'), (5, 'BTS', 'New York'), (6, 'Rihanna', 'New York');
|
List all cities where at least two different artists have performed.
|
SELECT City FROM (SELECT City, Artist, ROW_NUMBER() OVER (PARTITION BY City ORDER BY City) as Rank FROM Concerts) WHERE Rank = 2 GROUP BY City;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE clinicians (id INT PRIMARY KEY, first_name VARCHAR(50), last_name VARCHAR(50)); INSERT INTO clinicians (id, first_name, last_name) VALUES ('1', 'John', 'Doe'), ('2', 'Jane', 'Smith');
|
Delete records from the "clinicians" table where the clinician's last name is 'Doe'
|
DELETE FROM clinicians WHERE last_name = 'Doe';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Stadiums (stadium_name TEXT, capacity INTEGER); INSERT INTO Stadiums (stadium_name, capacity) VALUES ('Stadium X', 50000); CREATE TABLE FootballMatches (match_id INTEGER, home_team TEXT, away_team TEXT, stadium_name TEXT, home_score INTEGER, away_score INTEGER); INSERT INTO FootballMatches (match_id, home_team, away_team, stadium_name, home_score, away_score) VALUES (1, 'Team A', 'Team B', 'Stadium X', 3, 1);
|
What is the average score of all football matches played in the 'Stadium X'?
|
SELECT AVG(home_score + away_score) FROM FootballMatches WHERE stadium_name = 'Stadium X';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE hospital_admissions (id INT, patient_id INT, admission_date DATE, discharge_date DATE, diagnosis VARCHAR(50)); INSERT INTO hospital_admissions (id, patient_id, admission_date, discharge_date, diagnosis) VALUES (1, 4, '2022-04-01', '2022-04-05', 'Diabetes'), (2, 5, '2022-06-10', '2022-06-13', 'Hypertension');
|
Compute the average length of hospital stays for patients admitted in 2022 with a diagnosis of diabetes.
|
SELECT patient_id, AVG(DATEDIFF(discharge_date, admission_date)) FROM hospital_admissions WHERE diagnosis = 'Diabetes' AND admission_date BETWEEN '2022-01-01' AND '2022-12-31' GROUP BY patient_id;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Sustainable_Materials (Type VARCHAR(255), Price FLOAT); INSERT INTO Sustainable_Materials (Type, Price) VALUES ('Organic Cotton', 3.5), ('Recycled Polyester', 4.2), ('Hemp', 2.8);
|
Insert a new sustainable material, 'Bamboo', with a price of 3.0.
|
INSERT INTO Sustainable_Materials (Type, Price) VALUES ('Bamboo', 3.0);
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Exhibitions (exhibition_id INT, date DATE, location VARCHAR(255));CREATE TABLE Visitors (visitor_id INT, exhibition_id INT); INSERT INTO Exhibitions (exhibition_id, date, location) VALUES (1, '2022-02-10', 'Paris'), (2, '2022-02-11', 'Paris'), (3, '2022-02-12', 'London'); INSERT INTO Visitors (visitor_id, exhibition_id) VALUES (1, 1), (2, 1), (3, 1), (4, 2), (5, 2), (6, 3);
|
What is the maximum number of visitors in a day for exhibitions in Paris?
|
SELECT MAX(visitor_count) FROM (SELECT COUNT(Visitors.visitor_id) AS visitor_count FROM Visitors JOIN Exhibitions ON Visitors.exhibition_id = Exhibitions.exhibition_id WHERE Exhibitions.location = 'Paris' GROUP BY Exhibitions.date) AS subquery;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE vehicle_types (city VARCHAR(20), vehicle_type VARCHAR(20)); INSERT INTO vehicle_types (city, vehicle_type) VALUES ('Los Angeles', 'Car'), ('Los Angeles', 'Bus'), ('Los Angeles', 'Bike'), ('Paris', 'Car'), ('Paris', 'Bus'), ('Paris', 'Scooter'), ('Sydney', 'Train'), ('Sydney', 'Ferry'), ('Sydney', 'Bike');
|
Show the distinct vehicle types in each city from the following table.
|
SELECT DISTINCT city, vehicle_type FROM vehicle_types;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE publications (title VARCHAR(50), journal VARCHAR(50), year INT, student_id INT, department VARCHAR(50), country VARCHAR(50)); INSERT INTO publications VALUES ('Paper1', 'Journal of Computer Science', 2020, 123, 'Computer Science', 'USA'); CREATE TABLE students (student_id INT, name VARCHAR(50), program VARCHAR(50), country VARCHAR(50)); INSERT INTO students VALUES (123, 'Jane Smith', 'Graduate', 'Canada');
|
List all unique journals where international graduate students have published in the last 2 years.
|
SELECT DISTINCT journal FROM publications p JOIN students s ON p.student_id = s.student_id WHERE program = 'Graduate' AND country != 'USA' AND year BETWEEN YEAR(CURRENT_DATE) - 2 AND YEAR(CURRENT_DATE);
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Volunteers( id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255), email VARCHAR(255), age INT, city VARCHAR(255)) INSERT INTO Volunteers (name, email, age, city) VALUES ('John Doe', 'john.doe@example.com', 30, 'New York') INSERT INTO Volunteers (name, email, age, city) VALUES ('Jane Smith', 'jane.smith@example.com', 25, 'Los Angeles') INSERT INTO Volunteers (name, email, age, city) VALUES ('Alice Johnson', 'alice.johnson@example.com', 28, 'Miami') INSERT INTO Volunteers (name, email, age, city) VALUES ('Bob Brown', 'bob.brown@example.com', 35, 'Chicago')
|
Get the total number of volunteers
|
SELECT COUNT(*) FROM Volunteers
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE industrial_sectors (id INT, sector VARCHAR(50), water_consumption FLOAT); INSERT INTO industrial_sectors (id, sector, water_consumption) VALUES (1, 'SectorA', 1200), (2, 'SectorB', 1500), (3, 'SectorC', 1800);
|
What was the average water consumption by industrial sector in the first half of 2021?
|
SELECT sector, AVG(water_consumption) as avg_water_consumption FROM industrial_sectors WHERE YEAR(event_date) = 2021 AND MONTH(event_date) <= 6 GROUP BY sector;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE teacher_training (id INT, name VARCHAR(50), age INT, subject VARCHAR(50));
|
Who are the teachers in the teacher_training table who teach Mathematics and have more than 10 years of experience?
|
SELECT name FROM teacher_training WHERE subject = 'Mathematics' AND age > 10 * 12;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Members (MemberID INT, Age INT, MembershipType VARCHAR(10)); INSERT INTO Members (MemberID, Age, MembershipType) VALUES (1, 35, 'Premium'), (2, 28, 'Basic'), (3, 42, 'Premium'); CREATE TABLE SmartwatchOwners (MemberID INT); INSERT INTO SmartwatchOwners (MemberID) VALUES (1), (3);
|
What is the average age of members who have a 'Premium' membership and do not own a smartwatch?
|
SELECT AVG(Members.Age) FROM Members LEFT JOIN SmartwatchOwners ON Members.MemberID = SmartwatchOwners.MemberID WHERE Members.MembershipType = 'Premium' AND SmartwatchOwners.MemberID IS NULL;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE project (id INT, name TEXT, country TEXT, type TEXT, capacity INT); INSERT INTO project (id, name, country, type, capacity) VALUES (9, 'Niagara Falls', 'Canada', 'Hydro', 2400), (10, 'Alberta Wind', 'Canada', 'Wind', 450);
|
Show the combined capacity (in MW) of hydro and wind projects in Canada
|
SELECT SUM(capacity) FROM project WHERE country = 'Canada' AND (type = 'Hydro' OR type = 'Wind');
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE species (species_id INT, name TEXT, location TEXT); INSERT INTO species (species_id, name, location) VALUES (1, 'Clownfish', 'Indian'), (2, 'Blue Whale', 'Indian');
|
What is the total number of species in the Indian ocean?
|
SELECT COUNT(*) FROM species WHERE location = 'Indian'
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE designer (id INT PRIMARY KEY, name VARCHAR(255), country_origin VARCHAR(255)); CREATE TABLE garment (id INT PRIMARY KEY, garment_name VARCHAR(255), quantity INT, price DECIMAL(5,2)); CREATE TABLE designer_garments (id INT PRIMARY KEY, designer_id INT, garment_id INT, FOREIGN KEY (designer_id) REFERENCES designer(id), FOREIGN KEY (garment_id) REFERENCES garment(id)); INSERT INTO designer (id, name, country_origin) VALUES (1, 'Neha', 'India'), (2, 'Alex', 'USA'); INSERT INTO garment (id, garment_name, quantity, price) VALUES (1, 'Rayon', 100, 15.00), (2, 'Silk', 0, 0), (3, 'Cotton', 200, 20.00); INSERT INTO designer_garments (id, designer_id, garment_id) VALUES (1, 1, 1), (2, 1, 3), (3, 2, 1), (4, 2, 3);
|
Calculate the total quantity of garments produced by each designer.
|
SELECT designer.name, SUM(garment.quantity) as total_quantity FROM designer INNER JOIN designer_garments ON designer.id = designer_garments.designer_id INNER JOIN garment ON designer_garments.garment_id = garment.id GROUP BY designer.name;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE readers (id INT, age INT, gender VARCHAR(10), country VARCHAR(50), news_preference VARCHAR(50)); INSERT INTO readers (id, age, gender, country, news_preference) VALUES (1, 35, 'Male', 'Nigeria', 'Sports'), (2, 45, 'Female', 'Nigeria', 'Sports');
|
Get the percentage of male and female readers who prefer sports news in Nigeria.
|
SELECT gender, PERCENTAGE := (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM readers WHERE country = 'Nigeria' AND news_preference = 'Sports')) percentage FROM readers WHERE country = 'Nigeria' AND news_preference = 'Sports' GROUP BY gender;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE songs (id INT, title VARCHAR(255), release_year INT); INSERT INTO songs (id, title, release_year) VALUES (1, 'Song 1', 2000), (2, 'Song 2', 2010);
|
What is the earliest release year in the songs table?
|
SELECT MIN(release_year) FROM songs;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE landfill_capacity(country VARCHAR(255), year INT, capacity_m3 FLOAT);
|
What is the maximum landfill capacity (m3) for each country in 2018?
|
SELECT country, MAX(capacity_m3) FROM landfill_capacity WHERE year = 2018 GROUP BY country;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE penguins (id INT, name VARCHAR(20), species VARCHAR(20), age INT, gender VARCHAR(10)); INSERT INTO penguins (id, name, species, age, gender) VALUES (1, 'Pip', 'Penguin', 3, 'Male'); INSERT INTO penguins (id, name, species, age, gender) VALUES (2, 'Penny', 'Penguin', 5, 'Female');
|
What is the minimum age of male penguins in the "penguins" table?
|
SELECT MIN(age) FROM penguins WHERE gender = 'Male' AND species = 'Penguin';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE hospitals (id INT, name TEXT, state TEXT, covid_cases INT); INSERT INTO hospitals (id, name, state, covid_cases) VALUES (1, 'Rural General Hospital', 'State A', 5), (2, 'Rural District Hospital', 'State B', 10), (3, 'Rural Specialty Hospital', 'State A', 0);
|
Determine the number of rural hospitals in each state with at least one COVID-19 case.
|
SELECT state, COUNT(*) as hospital_count FROM hospitals WHERE covid_cases > 0 GROUP BY state;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE CropData (id INT, Crop VARCHAR(255), NitrogenLevel INT, Timestamp DATETIME); INSERT INTO CropData (id, Crop, NitrogenLevel, Timestamp) VALUES (1, 'Cotton', 250, '2022-06-01 12:00:00'), (2, 'Rice', 200, '2022-06-01 12:00:00');
|
What is the average nitrogen level for each crop type in the past week, ranked by the highest average?
|
SELECT Crop, AVG(NitrogenLevel) as AvgNitrogen FROM CropData WHERE Timestamp BETWEEN DATEADD(day, -7, GETDATE()) AND GETDATE() GROUP BY Crop ORDER BY AvgNitrogen DESC;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE EV_Market_Share (province VARCHAR(50), market_share FLOAT); INSERT INTO EV_Market_Share (province, market_share) VALUES ('Ontario', 0.25); INSERT INTO EV_Market_Share (province, market_share) VALUES ('Quebec', 0.40);
|
What is the market share of electric vehicles in Canada by province?
|
SELECT province, market_share FROM EV_Market_Share ORDER BY market_share DESC;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Candidates (CandidateID INT, MilitarySpouse VARCHAR(10), HireDate DATE); INSERT INTO Candidates (CandidateID, MilitarySpouse, HireDate) VALUES (11, 'Yes', '2022-04-10');
|
What is the percentage of candidates who are military spouses that were hired in the last quarter?
|
SELECT (COUNT(*) / (SELECT COUNT(*) FROM Candidates WHERE HireDate BETWEEN DATE_SUB(CURDATE(), INTERVAL 3 MONTH) AND CURDATE())) * 100 AS Percentage FROM Candidates WHERE MilitarySpouse = 'Yes' AND HireDate BETWEEN DATE_SUB(CURDATE(), INTERVAL 3 MONTH) AND CURDATE();
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Missions (MissionID INT, Name VARCHAR(50), Agency VARCHAR(50), Cost INT); INSERT INTO Missions (MissionID, Name, Agency, Cost) VALUES (1, 'Falcon 9', 'SpaceX', 60000000), (2, 'Falcon Heavy', 'SpaceX', 90000000);
|
What is the total cost of all space missions launched by SpaceX?
|
SELECT SUM(Cost) FROM Missions WHERE Agency = 'SpaceX';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE hydroelectric_plants (id INT, name TEXT, country TEXT, capacity FLOAT); INSERT INTO hydroelectric_plants (id, name, country, capacity) VALUES (1, 'Robert-Bourassa Generating Station', 'Canada', 5616), (2, 'Churchill Falls', 'Canada', 5428), (3, 'La Grande-1', 'Canada', 2779), (4, 'La Grande-2', 'Canada', 5225), (5, 'La Grande-3', 'Canada', 2660);
|
What is the total energy storage capacity of hydroelectric plants in Canada?
|
SELECT SUM(capacity) FROM hydroelectric_plants WHERE country = 'Canada';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE volunteers (id INT PRIMARY KEY, name VARCHAR(255), email VARCHAR(255), hours_per_week FLOAT);
|
Update the email of Jane Smith in the 'volunteers' table
|
UPDATE volunteers SET email = '[jane.smith.new@gmail.com](mailto:jane.smith.new@gmail.com)' WHERE name = 'Jane Smith';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE mining_workforce (id INT, state VARCHAR(50), years_of_experience INT, position VARCHAR(50)); INSERT INTO mining_workforce (id, state, years_of_experience, position) VALUES (1, 'Utah', 6, 'Miner'); INSERT INTO mining_workforce (id, state, years_of_experience, position) VALUES (2, 'Utah', 7, 'Miner'); INSERT INTO mining_workforce (id, state, years_of_experience, position) VALUES (3, 'Utah', 5, 'Miner');
|
What is the total number of workers in mining operations in the state of Utah that have more than 5 years of experience?
|
SELECT COUNT(*) FROM mining_workforce WHERE state = 'Utah' AND years_of_experience > 5;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE rugby_matches (match_id INT, season INT, tickets_sold INT); INSERT INTO rugby_matches (match_id, season, tickets_sold) VALUES (1, 2018, 30000), (2, 2018, 35000), (3, 2019, 40000);
|
What is the total number of tickets sold for rugby matches in '2018' and '2019'?
|
SELECT SUM(tickets_sold) FROM rugby_matches WHERE season IN (2018, 2019);
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE users (user_id INT, posts_count INT, followers_count INT, join_date DATE); CREATE TABLE posts (post_id INT, user_id INT, post_date DATE);
|
List the top 3 most active users in terms of content creation, in the past month, who have created at least 5 posts and have a follower count greater than 1000.
|
SELECT u.user_id, u.posts_count, u.followers_count FROM users u JOIN posts p ON u.user_id = p.user_id WHERE u.followers_count > 1000 AND u.posts_count >= 5 AND p.post_date >= NOW() - INTERVAL '1 month' GROUP BY u.user_id, u.posts_count, u.followers_count ORDER BY u.posts_count DESC LIMIT 3;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE organizations (id INT, sector VARCHAR(20), ESG_rating FLOAT); INSERT INTO organizations (id, sector, ESG_rating) VALUES (1, 'Healthcare', 7.5), (2, 'Technology', 8.2), (3, 'Healthcare', 8.0), (4, 'Renewable Energy', 9.0); CREATE TABLE investments (id INT, organization_id INT); INSERT INTO investments (id, organization_id) VALUES (1, 1), (2, 2), (3, 3), (4, 4);
|
How many organizations are in each sector?
|
SELECT organizations.sector, COUNT(DISTINCT organizations.id) FROM organizations JOIN investments ON organizations.id = investments.organization_id GROUP BY organizations.sector;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE if not exists scooter_share (id INT, city VARCHAR(20), company VARCHAR(20), quantity INT);INSERT INTO scooter_share (id, city, company, quantity) VALUES (1, 'San Francisco', 'Lime', 200), (2, 'San Francisco', 'Bird', 150), (3, 'New York', 'Lime', 100), (4, 'New York', 'Bird', 120);
|
What is the minimum number of shared scooters in San Francisco?
|
SELECT MIN(quantity) FROM scooter_share WHERE city = 'San Francisco';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE borough (id INT, name TEXT); CREATE TABLE community_policing (id INT, borough_id INT, program TEXT);
|
Which community policing programs are available in each borough?
|
SELECT b.name, c.program FROM borough b JOIN community_policing c ON b.id = c.borough_id;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE chemical_safety (chemical VARCHAR(30), safety_rating INT); INSERT INTO chemical_safety (chemical, safety_rating) VALUES ('Ethanol', 8), ('Propanol', 6), ('Butanol', 5); CREATE TABLE environmental_impact (chemical VARCHAR(30), impact_score INT); INSERT INTO environmental_impact (chemical, impact_score) VALUES ('Ethanol', 40), ('Propanol', 50), ('Butanol', 60);
|
What are the names of all chemicals with an impact score greater than 50 and their corresponding safety ratings?
|
SELECT chemical, safety_rating FROM chemical_safety WHERE chemical IN (SELECT chemical FROM environmental_impact WHERE impact_score > 50);
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Donations (DonationID INT, DonationAmount DECIMAL(10,2), DonationDate DATE);
|
What is the maximum donation amount received in the month of June?
|
SELECT MAX(DonationAmount) FROM Donations WHERE MONTH(DonationDate) = 6;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE delays_berlin (id INT, city VARCHAR(50), delay TIME); INSERT INTO delays_berlin (id, city, delay) VALUES (1, 'Berlin', '00:20'), (2, 'Berlin', '00:18'), (3, 'Berlin', '00:15');
|
What is the maximum delay for public transportation in Berlin?
|
SELECT MAX(delay) FROM delays_berlin WHERE city = 'Berlin';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE FarmRegion (FarmID INT, Region VARCHAR(50), RegionID INT); INSERT INTO FarmRegion (FarmID, Region, RegionID) VALUES (1, 'North', 1), (2, 'South', 2), (3, 'North', 1);
|
Number of organic farms in each region
|
SELECT f.Region, COUNT(f.FarmID) FROM OrganicFarm f INNER JOIN FarmRegion r ON f.FarmID = r.FarmID GROUP BY f.Region;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE districts (id INT, name VARCHAR(20), type VARCHAR(10)); INSERT INTO districts (id, name, type) VALUES (1, 'City A', 'urban'), (2, 'Town B', 'urban'), (3, 'Village C', 'rural'), (4, 'Hamlet D', 'rural'); CREATE TABLE budget_allocations (id INT, district_id INT, category VARCHAR(20), amount INT); INSERT INTO budget_allocations (id, district_id, category, amount) VALUES (1, 1, 'education', 50000), (2, 1, 'healthcare', 30000), (3, 2, 'education', 40000), (4, 2, 'healthcare', 45000), (5, 3, 'education', 20000), (6, 3, 'healthcare', 35000), (7, 4, 'education', 15000), (8, 4, 'healthcare', 60000);
|
Which rural areas received more than $30,000 in healthcare funding?
|
SELECT d.name FROM districts d JOIN budget_allocations ba ON d.id = ba.district_id WHERE d.type = 'rural' AND ba.category = 'healthcare' AND ba.amount > 30000;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE ticket_sales (state VARCHAR(255), sport VARCHAR(255), quantity INT, price DECIMAL(5,2)); INSERT INTO ticket_sales (state, sport, quantity, price) VALUES ('NY', 'Basketball', 1500, 75.50), ('CA', 'Basketball', 1800, 75.50), ('TX', 'Basketball', 1200, 75.50);
|
Which state has the highest total ticket sales for basketball?
|
SELECT state, SUM(quantity * price) total_sales FROM ticket_sales WHERE sport = 'Basketball' GROUP BY state ORDER BY total_sales DESC LIMIT 1;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE marine_research_projects (id INT, country VARCHAR(50), funder VARCHAR(50), project_name VARCHAR(50), date DATE); INSERT INTO marine_research_projects (id, country, funder, project_name, date) VALUES (1, 'Canada', 'WWF', 'Ocean Pollution Study', '2022-03-05'); INSERT INTO marine_research_projects (id, country, funder, project_name, date) VALUES (2, 'Mexico', 'WWF', 'Coral Reef Conservation', '2022-02-22');
|
Identify the top 3 countries with the most marine research projects funded by the World Wildlife Fund (WWF) in the last 5 years.
|
SELECT country, COUNT(*) AS total_projects FROM marine_research_projects WHERE funder = 'WWF' AND date >= DATE_SUB(CURRENT_DATE, INTERVAL 5 YEAR) GROUP BY country ORDER BY total_projects DESC LIMIT 3;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE quarterly_extractions (id INT, year INT, quarter INT, extraction_amount INT); INSERT INTO quarterly_extractions (id, year, quarter, extraction_amount) VALUES (1, 2019, 1, 800), (2, 2019, 2, 850), (3, 2019, 3, 900), (4, 2019, 4, 950), (5, 2020, 1, 1000), (6, 2020, 2, 1050), (7, 2020, 3, 1100), (8, 2020, 4, 1150), (9, 2021, 1, 1200), (10, 2021, 2, 1250), (11, 2021, 3, 1300), (12, 2021, 4, 1350);
|
What is the percentage change in mineral extractions per quarter, for the last 3 years?
|
SELECT year, quarter, (extraction_amount - LAG(extraction_amount) OVER (PARTITION BY year ORDER BY quarter)) * 100.0 / LAG(extraction_amount) OVER (PARTITION BY year ORDER BY quarter) AS percentage_change FROM quarterly_extractions WHERE year BETWEEN 2019 AND 2021 ORDER BY year, quarter;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE WasteGeneration (waste_id INT, region VARCHAR(255), waste_amount DECIMAL(10,2), generation_date DATE); INSERT INTO WasteGeneration (waste_id, region, waste_amount, generation_date) VALUES (1, 'North', 1200, '2021-01-01'), (2, 'South', 1500, '2021-01-01'), (3, 'East', 800, '2021-01-01'), (4, 'West', 1700, '2021-01-01');
|
What is the total waste generation for the bottom 2 regions with the lowest waste generation?
|
SELECT SUM(waste_amount) FROM WasteGeneration GROUP BY region ORDER BY SUM(waste_amount) LIMIT 2;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE initiative (initiative_id INT, initiative_name VARCHAR(255), launch_date DATE, region VARCHAR(50)); INSERT INTO initiative (initiative_id, initiative_name, launch_date, region) VALUES (1, 'Accessible Software Development', '2018-04-01', 'North America'), (2, 'Adaptive Hardware Prototyping', '2019-12-15', 'Europe'), (3, 'Digital Inclusion Program', '2020-08-03', 'Asia'), (4, 'Diverse Tech Talent Network', '2021-02-22', 'Africa');
|
What is the percentage of accessible technology initiatives launched in each region?
|
SELECT region, COUNT(*) * 100.0 / (SELECT COUNT(*) FROM initiative) as percentage FROM initiative GROUP BY region;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Mines (MineID INT, MineName TEXT, Location TEXT, Employees INT, Contractors INT);
|
What is the total number of employees and contractors in each mine?
|
SELECT MineName, Employees + Contractors AS TotalWorkforce FROM Mines;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE energy_usage (country TEXT, renewable_energy TEXT); INSERT INTO energy_usage (country, renewable_energy) VALUES ('country_A', 'solar'), ('country_A', 'wind'), ('country_B', 'solar'), ('country_C', 'hydro');
|
Which 'renewable_energy' sources were used in 'country_B'?
|
SELECT renewable_energy FROM energy_usage WHERE country = 'country_B';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE network_devices (id INT, name VARCHAR(255), region VARCHAR(255), installed_at TIMESTAMP);
|
List the top 5 regions with the highest number of network devices?
|
SELECT region, COUNT(*) as total_devices FROM network_devices GROUP BY region ORDER BY total_devices DESC LIMIT 5;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE us_temperature (year INT, avg_temp FLOAT); INSERT INTO us_temperature (year, avg_temp) VALUES (2015, 10.1), (2016, 10.5), (2017, 11.2), (2018, 10.8), (2019, 11.0), (2020, 11.5); CREATE TABLE canada_temperature (year INT, avg_temp FLOAT); INSERT INTO canada_temperature (year, avg_temp) VALUES (2015, 3.1), (2016, 3.5), (2017, 4.2), (2018, 3.8), (2019, 4.0), (2020, 4.5);
|
What is the average temperature change in the United States and Canada from 2015 to 2020?
|
SELECT AVG(us_temperature.avg_temp) AS us_avg_temp, AVG(canada_temperature.avg_temp) AS canada_avg_temp FROM us_temperature, canada_temperature WHERE us_temperature.year = canada_temperature.year AND us_temperature.year BETWEEN 2015 AND 2020;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE textile_emissions (id INT, country VARCHAR(50), co2_emissions INT); INSERT INTO textile_emissions (id, country, co2_emissions) VALUES (1, 'Bangladesh', 5000), (2, 'China', 15000), (3, 'India', 10000), (4, 'USA', 8000);
|
What is the difference in CO2 emissions between the highest and lowest emitting countries?
|
SELECT MAX(co2_emissions) - MIN(co2_emissions) as co2_emissions_difference FROM textile_emissions;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE warehouse (id INT, location VARCHAR(255), capacity INT); INSERT INTO warehouse (id, location, capacity) VALUES (1, 'warehouse1', 5000), (2, 'warehouse2', 7000); CREATE TABLE packages (id INT, warehouse_id INT, weight INT, destination VARCHAR(255)); INSERT INTO packages (id, warehouse_id, weight, destination) VALUES (1, 1, 15, 'USA'), (2, 2, 20, 'Canada'), (3, 1, 12, 'Mexico'), (4, 2, 22, 'Canada'), (5, 1, 18, 'USA');
|
What is the average weight of packages shipped to Canada from the 'warehouse2'?
|
SELECT AVG(weight) FROM packages WHERE warehouse_id = 2 AND destination = 'Canada';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE mental_health_providers (id INT, state VARCHAR(50), cultural_competency_score DECIMAL(3,2)); INSERT INTO mental_health_providers (id, state, cultural_competency_score) VALUES (1, 'California', 4.75), (2, 'Texas', 4.50), (3, 'Florida', 4.25), (4, 'California', 5.00), (5, 'Texas', 4.80);
|
What is the maximum cultural competency score achieved by mental health providers in each state?
|
SELECT state, MAX(cultural_competency_score) FROM mental_health_providers GROUP BY state;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE public.emergency_responses (id serial PRIMARY KEY, city varchar(255), response_time int); INSERT INTO public.emergency_responses (city, response_time) VALUES ('Los Angeles', 120);
|
What is the average emergency response time in the city of Los Angeles?
|
SELECT AVG(response_time) FROM public.emergency_responses WHERE city = 'Los Angeles';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE SpaceExploration (mission_id INT, spacecraft VARCHAR(50), flight_duration INT);
|
What is the minimum flight duration for Blue Origin missions?
|
SELECT MIN(flight_duration) FROM SpaceExploration WHERE spacecraft = 'Blue Origin';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE suppliers (supplier_id INT, organic BOOLEAN); CREATE TABLE ingredients (ingredient_id INT, supplier_id INT, restaurant_id INT, is_organic BOOLEAN); CREATE TABLE restaurants (restaurant_id INT, city VARCHAR(255)); INSERT INTO suppliers VALUES (1, true); INSERT INTO suppliers VALUES (2, false); INSERT INTO ingredients VALUES (1, 1, 1, true); INSERT INTO ingredients VALUES (2, 1, 2, false); INSERT INTO ingredients VALUES (3, 2, 3, false); INSERT INTO restaurants VALUES (1, 'Miami'); INSERT INTO restaurants VALUES (2, 'Atlanta'); INSERT INTO restaurants VALUES (3, 'Phoenix');
|
Which organic suppliers have never provided ingredients to restaurants located in a coastal city?
|
SELECT s.supplier_id FROM suppliers s LEFT JOIN ingredients i ON s.supplier_id = i.supplier_id RIGHT JOIN restaurants r ON i.restaurant_id = r.restaurant_id WHERE s.organic = true AND r.city NOT LIKE '%coast%' GROUP BY s.supplier_id HAVING COUNT(i.ingredient_id) = 0;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE RnDExpenditures (drug_name VARCHAR(255), rnd_expenditure DECIMAL(10,2)); INSERT INTO RnDExpenditures (drug_name, rnd_expenditure) VALUES ('DrugA', 50000.00), ('DrugB', 70000.00), ('DrugC', 30000.00);
|
What is the total R&D expenditure for each drug in the 'RnDExpenditures' table, unpivoted and with a total row?
|
SELECT drug_name, 'rnd_expenditure' as metric, SUM(rnd_expenditure) as value FROM RnDExpenditures GROUP BY drug_name UNION ALL SELECT 'Total', SUM(rnd_expenditure) as value FROM RnDExpenditures;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE company_impact (id INT, name VARCHAR(50), sector VARCHAR(20), impact_score FLOAT); INSERT INTO company_impact (id, name, sector, impact_score) VALUES (1, 'Company X', 'Technology', 85.0), (2, 'Company Y', 'Finance', 80.0), (3, 'Company Z', 'Technology', 87.5);
|
What is the minimum impact score achieved by a company in the technology sector?
|
SELECT MIN(impact_score) FROM company_impact WHERE sector = 'Technology';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE startup (id INT, name TEXT, founder_veteran_status TEXT, num_employees INT); INSERT INTO startup (id, name, founder_veteran_status, num_employees) VALUES (1, 'VetStart', 'Veteran', 100); INSERT INTO startup (id, name, founder_veteran_status, num_employees) VALUES (2, 'TechStart', 'Non-Veteran', 1000);
|
What is the minimum number of employees for startups founded by veterans?
|
SELECT MIN(num_employees) FROM startup WHERE founder_veteran_status = 'Veteran';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE VineyardSoilMoisture (country VARCHAR(20), region VARCHAR(30), moisture FLOAT); INSERT INTO VineyardSoilMoisture (country, region, moisture) VALUES ('France', 'Bordeaux', 42.3), ('France', 'Burgundy', 48.1), ('Spain', 'Rioja', 39.5), ('Spain', 'Ribera del Duero', 45.6);
|
What are the average soil moisture levels for vineyards in France and Spain?
|
SELECT AVG(moisture) FROM VineyardSoilMoisture WHERE country IN ('France', 'Spain') AND region IN ('Bordeaux', 'Burgundy', 'Rioja', 'Ribera del Duero');
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Donors (DonorID INT, DonationDate DATE, Amount DECIMAL(10,2)); INSERT INTO Donors (DonorID, DonationDate, Amount) VALUES (1, '2022-07-01', 50.00), (2, '2022-10-14', 100.00), (3, '2022-09-03', 25.00);
|
How many new donors made donations in Q3 2022?
|
SELECT COUNT(DonorID) FROM Donors WHERE YEAR(DonationDate) = 2022 AND DonorID NOT IN (SELECT DonorID FROM Donors GROUP BY DonorID HAVING COUNT(DonorID) < 2) AND QUARTER(DonationDate) = 3;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE creative_ai_applications (app_id INT, app_name TEXT, safety_score FLOAT, region TEXT); INSERT INTO creative_ai_applications (app_id, app_name, safety_score, region) VALUES (1, 'Dalle', 0.85, 'Africa'), (2, 'Midjourney', 0.90, 'Europe'), (3, 'Jukebox', 0.80, 'Africa');
|
What is the maximum safety score for each creative AI application in Africa?
|
SELECT app_name, MAX(safety_score) OVER (PARTITION BY region) as max_safety_score FROM creative_ai_applications WHERE region = 'Africa';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE nba_stadiums (stadium_id INT, stadium_name VARCHAR(255), city VARCHAR(255)); CREATE TABLE nba_games (game_id INT, home_stadium_id INT, away_stadium_id INT);
|
Show the number of games played in each stadium in the 'nba_stadiums' table.
|
SELECT home_stadium_id AS stadium_id, COUNT(*) AS total_games FROM nba_games GROUP BY home_stadium_id UNION ALL SELECT away_stadium_id, COUNT(*) FROM nba_games GROUP BY away_stadium_id;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE subscriber_data (subscriber_id INT, data_usage FLOAT, month DATE); INSERT INTO subscriber_data (subscriber_id, data_usage, month) VALUES (42, 25, '2021-01-01'), (42, 30, '2021-02-01');
|
Find the difference in data usage between consecutive months for subscriber_id 42 in the 'west' region.
|
SELECT subscriber_id, LAG(data_usage) OVER (PARTITION BY subscriber_id ORDER BY month) as prev_data_usage, data_usage, month FROM subscriber_data WHERE subscriber_id = 42 AND region = 'west' ORDER BY month;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE patients (id INT, country VARCHAR(255));CREATE TABLE treatments (id INT, patient_id INT, treatment VARCHAR(255)); INSERT INTO patients (id, country) VALUES (1, 'Mexico'), (2, 'USA'), (3, 'Canada'); INSERT INTO treatments (id, patient_id, treatment) VALUES (1, 1, 'Psychotherapy'), (2, 2, 'CBT'), (3, 3, 'DBT');
|
How many patients have been treated with psychotherapy in Mexico?
|
SELECT COUNT(DISTINCT patients.id) FROM patients INNER JOIN treatments ON patients.id = treatments.patient_id WHERE treatments.treatment = 'Psychotherapy' AND patients.country = 'Mexico';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE military_equipment (id INT PRIMARY KEY, manufacturer VARCHAR(50), equipment_type VARCHAR(50), year INT);
|
Delete all records from the 'military_equipment' table where the 'equipment_type' is 'Naval'
|
WITH cte AS (DELETE FROM military_equipment WHERE equipment_type = 'Naval' RETURNING *) INSERT INTO military_equipment SELECT * FROM cte;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE VenueW (event_id INT, attendee_id INT, age_group VARCHAR(20), amount INT); CREATE TABLE AgeGroups (age_group VARCHAR(20), lower_age INT, upper_age INT);
|
How many unique audience members have attended events at 'VenueW' in each age group, and what is the average amount spent per age group?
|
SELECT v.age_group, COUNT(DISTINCT v.attendee_id) AS unique_attendees, AVG(v.amount) AS avg_spent FROM VenueW v JOIN AgeGroups a ON v.age_group = a.age_group GROUP BY v.age_group;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE mines (id VARCHAR(10), name VARCHAR(50), location VARCHAR(50), production_rate INT); INSERT INTO mines (id, name, location, production_rate) VALUES ('Mine_001', 'Gold Mine', 'Alberta', 450); INSERT INTO mines (id, name, location, production_rate) VALUES ('Mine_002', 'Coal Mine', 'Wyoming', 750);
|
Update the 'production_rate' of the 'Mine_001' record in the 'mines' table to 500
|
UPDATE mines SET production_rate = 500 WHERE id = 'Mine_001';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Trainings (training_id INT, training_type VARCHAR(50), year INT, region_id INT); INSERT INTO Trainings (training_id, training_type, year, region_id) VALUES (1, 'Cybersecurity training', 2020, 9), (2, 'Leadership training', 2019, 9);
|
Find the total number of cybersecurity trainings conducted in the Caribbean region in 2020.
|
SELECT COUNT(*) FROM Trainings WHERE training_type = 'Cybersecurity training' AND year = 2020 AND region_id = (SELECT region_id FROM Regions WHERE region_name = 'Caribbean');
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE crimes (id INT, report_date DATE, type TEXT, city TEXT); INSERT INTO crimes (id, report_date, type, city) VALUES (1, '2022-01-01', 'theft', 'London');
|
What is the most common type of crime reported in London?
|
SELECT crimes.type, COUNT(*) FROM crimes WHERE crimes.city = 'London' GROUP BY crimes.type ORDER BY COUNT(*) DESC LIMIT 1;
|
gretelai_synthetic_text_to_sql
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.