context
stringlengths
11
9.12k
question
stringlengths
0
1.06k
SQL
stringlengths
2
4.44k
source
stringclasses
28 values
CREATE TABLE GreenFields (product_id INT, product_name VARCHAR(50), eco_label VARCHAR(50)); INSERT INTO GreenFields (product_id, product_name, eco_label) VALUES (1, 'Eggs', 'Free Range'), (2, 'Milk', 'Conventional'), (3, 'Chicken', 'Free Range'), (4, 'Beef', 'Grass Fed');
How many products in 'GreenFields' have a valid eco-label?
SELECT COUNT(*) FROM GreenFields WHERE eco_label <> '';
gretelai_synthetic_text_to_sql
CREATE TABLE PacificIslandsDestinations (destination_id INT, name VARCHAR(50), country VARCHAR(50), sustainability_rating INT, visitor_count INT); INSERT INTO PacificIslandsDestinations (destination_id, name, country, sustainability_rating, visitor_count) VALUES (1, 'Eco Retreat', 'Fiji', 4, 600); INSERT INTO PacificIslandsDestinations (destination_id, name, country, sustainability_rating, visitor_count) VALUES (2, 'Green Island', 'Tahiti', 5, 800);
What is the minimum sustainability rating for any destination in the Pacific Islands with at least 500 visitors?
SELECT MIN(sustainability_rating) FROM PacificIslandsDestinations WHERE country IN ('Pacific Islands') AND visitor_count >= 500;
gretelai_synthetic_text_to_sql
CREATE TABLE streams (id INT, user_id INT, song_id INT, platform VARCHAR(20), stream_date DATE); INSERT INTO streams (id, user_id, song_id, platform, stream_date) VALUES (1, 1, 1, 'Apple Music', '2021-01-01'), (2, 2, 2, 'Apple Music', '2021-01-02');
What is the total number of unique users who have streamed Jazz music on Apple Music from the USA in the last 30 days?
SELECT COUNT(DISTINCT user_id) FROM streams WHERE platform = 'Apple Music' AND genre = 'Jazz' AND stream_date >= NOW() - INTERVAL '30 days';
gretelai_synthetic_text_to_sql
CREATE TABLE rail_transportation (id INT, type VARCHAR(20), num_vehicles INT); INSERT INTO rail_transportation (id, type, num_vehicles) VALUES (1, 'Traditional Train', 600), (2, 'Hybrid Train', 350), (3, 'Electric Train', 400);
What is the total number of hybrid and electric trains in the rail_transportation table?
SELECT SUM(num_vehicles) FROM rail_transportation WHERE type IN ('Hybrid Train', 'Electric Train');
gretelai_synthetic_text_to_sql
CREATE TABLE customers (customer_id INT, customer_name VARCHAR(255)); INSERT INTO customers (customer_id, customer_name) VALUES (1, 'John Doe'), (2, 'Jane Smith'), (3, 'Bob Johnson'); CREATE TABLE sales (sale_id INT, customer_id INT, revenue INT); INSERT INTO sales (sale_id, customer_id, revenue) VALUES (1, 1, 100), (2, 2, 50), (3, 1, 200);
List the top 5 customers by total spending
SELECT customers.customer_name, SUM(sales.revenue) FROM sales INNER JOIN customers ON sales.customer_id = customers.customer_id GROUP BY customers.customer_name ORDER BY SUM(sales.revenue) DESC LIMIT 5;
gretelai_synthetic_text_to_sql
CREATE TABLE smart_cities (id INT, project_name VARCHAR(100), completion_year INT, country VARCHAR(50)); INSERT INTO smart_cities (id, project_name, completion_year, country) VALUES (1, 'Smart Grid Tokyo', 2019, 'Japan'), (2, 'Intelligent Lighting Osaka', 2020, 'Japan'), (3, 'Eco-City Kyoto', 2018, 'Japan');
Which smart city projects in Japan were completed in 2020?
SELECT project_name FROM smart_cities WHERE completion_year = 2020 AND country = 'Japan';
gretelai_synthetic_text_to_sql
CREATE TABLE inventory (ingredient_id INT, ingredient_name VARCHAR(255), quantity INT, reorder_threshold INT, last_updated TIMESTAMP);
What is the total quantity of ingredients that are below their reorder threshold?
SELECT ingredient_name, SUM(quantity) as total_quantity FROM inventory WHERE quantity < reorder_threshold GROUP BY ingredient_name;
gretelai_synthetic_text_to_sql
CREATE TABLE GameDesigners (DesignerID INT, Name VARCHAR(30), VRAdoption BOOLEAN);
Insert new records for a game designer who has adopted virtual reality technology.
INSERT INTO GameDesigners (DesignerID, Name, VRAdoption) VALUES (1, 'John Doe', TRUE);
gretelai_synthetic_text_to_sql
CREATE TABLE Publications (PublicationID INT PRIMARY KEY, Title VARCHAR(255), Author VARCHAR(255), Year INT, Type VARCHAR(255));
Create a table to store information about archaeological publications
CREATE TABLE Publications (PublicationID INT PRIMARY KEY, Title VARCHAR(255), Author VARCHAR(255), Year INT, Type VARCHAR(255));
gretelai_synthetic_text_to_sql
CREATE TABLE projects (id INT, name VARCHAR(50), researcher_id INT); INSERT INTO projects (id, name, researcher_id) VALUES (1, 'Genome Wide Association Study', 1); INSERT INTO projects (id, name, researcher_id) VALUES (2, 'Gene Expression Analysis', 2); CREATE TABLE techniques (id INT, name VARCHAR(50), description VARCHAR(50)); INSERT INTO techniques (id, name, description) VALUES (1, 'Genotyping', 'DNA analysis technique'); INSERT INTO techniques (id, name, description) VALUES (2, 'RNA Sequencing', 'Transcriptome analysis technique'); CREATE TABLE project_techniques (project_id INT, technique_id INT); INSERT INTO project_techniques (project_id, technique_id) VALUES (1, 1); INSERT INTO project_techniques (project_id, technique_id) VALUES (2, 2);
List genetic research projects and their techniques
SELECT p.name, t.name as technique_name FROM projects p JOIN project_techniques pt ON p.id = pt.project_id JOIN techniques t ON pt.technique_id = t.id;
gretelai_synthetic_text_to_sql
CREATE TABLE sales_3(drug_name TEXT, quarter INT, year INT, revenue FLOAT, drug_category TEXT); INSERT INTO sales_3(drug_name, quarter, year, revenue, drug_category) VALUES('DrugS', 3, 2020, 1000000, 'Analgesics'), ('DrugT', 3, 2020, 1200000, 'Antibiotics'), ('DrugU', 3, 2020, 1100000, 'Analgesics'), ('DrugV', 3, 2020, 900000, 'Cardiovascular');
What is the total sales revenue for each drug in Q3 2020, grouped by drug category?
SELECT drug_category, SUM(revenue) FROM sales_3 WHERE quarter = 3 AND year = 2020 GROUP BY drug_category;
gretelai_synthetic_text_to_sql
CREATE TABLE hotels (hotel_id INT, hotel_name TEXT, country TEXT, occupancy_rate FLOAT);
What is the average occupancy rate for hotels in the United States by month?
SELECT DATE_PART('month', timestamp) AS month, AVG(occupancy_rate) FROM hotels JOIN bookings ON hotels.hotel_id = bookings.hotel_id GROUP BY month;
gretelai_synthetic_text_to_sql
CREATE TABLE if not exists wells (well_id int, region varchar(50), production_year int, oil_production int);INSERT INTO wells (well_id, region, production_year, oil_production) VALUES (1, 'Permian Basin', 2019, 120000), (2, 'Permian Basin', 2018, 135000), (3, 'Eagle Ford', 2019, 110000);
List all the wells in the Permian Basin with their respective production figures for 2019
SELECT * FROM wells WHERE region = 'Permian Basin' AND production_year = 2019;
gretelai_synthetic_text_to_sql
CREATE TABLE InclusionInitiatives (InitiativeID INT, InitiativeName VARCHAR(50), InitiativeMonth DATE, InitiativeYear INT); INSERT INTO InclusionInitiatives (InitiativeID, InitiativeName, InitiativeMonth, InitiativeYear) VALUES (1, 'Disability Pride Month', '2021-07-01', 2021), (2, 'Global Accessibility Awareness Day', '2021-05-20', 2021), (3, 'International Day of Persons with Disabilities', '2021-12-03', 2021), (4, 'Sign Language Day', '2021-09-23', 2021), (5, 'Learning Disabilities Awareness Month', '2021-10-01', 2021);
How many inclusion initiatives were conducted per month in the year 2021?
SELECT EXTRACT(MONTH FROM InitiativeMonth) as Month, COUNT(*) as InitiativeCount FROM InclusionInitiatives WHERE InitiativeYear = 2021 GROUP BY Month;
gretelai_synthetic_text_to_sql
CREATE TABLE CargoWeight (Id INT, VesselName VARCHAR(50), Origin VARCHAR(50), Destination VARCHAR(50), CargoDate DATETIME, CargoWeight INT);
What is the minimum cargo weight carried by vessels from Japan to the US in the last 6 months?
SELECT MIN(CargoWeight) FROM CargoWeight WHERE Origin = 'Japan' AND Destination = 'US' AND CargoDate >= DATEADD(MONTH, -6, GETDATE());
gretelai_synthetic_text_to_sql
CREATE TABLE cybersecurity_budgets (id INT, country VARCHAR(50), year INT, budget INT);
What is the annual budget for cybersecurity in the top 3 spending countries?
SELECT country, SUM(budget) as annual_budget FROM cybersecurity_budgets WHERE (country, budget) IN (SELECT country, DENSE_RANK() OVER (ORDER BY budget DESC) as rank FROM cybersecurity_budgets GROUP BY country) AND rank <= 3 GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE users (id INT, country VARCHAR(50), stream_count INT); INSERT INTO users (id, country, stream_count) VALUES (1, 'USA', 100), (2, 'Canada', 120), (3, 'USA', 150);
What is the ratio of stream counts between users from the USA and Canada?
SELECT 100.0 * AVG(CASE WHEN country = 'USA' THEN stream_count END) / AVG(CASE WHEN country = 'Canada' THEN stream_count END) AS stream_count_ratio FROM users;
gretelai_synthetic_text_to_sql
CREATE TABLE infrastructure_projects (id INT, project_name VARCHAR(50), location VARCHAR(50), budget DECIMAL(10,2), year INT); INSERT INTO infrastructure_projects (id, project_name, location, budget, year) VALUES (1, 'Highway 101 Expansion', 'California', 5000000, 2022), (2, 'Bridge Replacement', 'New York', 3000000, 2022), (3, 'Transit System Upgrade', 'Texas', 8000000, 2023);
What is the average budget for infrastructure projects in 2022 and 2023?
SELECT AVG(budget) as avg_budget FROM infrastructure_projects WHERE year IN (2022, 2023);
gretelai_synthetic_text_to_sql
CREATE SCHEMA if not exists genetic_research;CREATE TABLE if not exists genetic_research.projects (id INT PRIMARY KEY, name VARCHAR(255), location VARCHAR(255), status VARCHAR(255)); INSERT INTO genetic_research.projects (id, name, location, status) VALUES (1, 'ProjectA', 'Germany', 'Active'), (2, 'ProjectB', 'France', 'Completed'), (3, 'ProjectC', 'Italy', 'Active'), (4, 'ProjectD', 'EU', 'Active');
How many genetic research projects are there in France?
SELECT COUNT(*) FROM genetic_research.projects WHERE location = 'France';
gretelai_synthetic_text_to_sql
CREATE TABLE universities (university_name VARCHAR(50), location VARCHAR(50), ethics_courses INTEGER, ai_courses INTEGER);
Find the total number of AI ethics courses offered in 'universities' table.
SELECT SUM(ai_courses) FROM universities WHERE ethics_courses > 0;
gretelai_synthetic_text_to_sql
CREATE TABLE players (id INT, name VARCHAR(50), age INT, gender VARCHAR(10), sport VARCHAR(20)); INSERT INTO players (id, name, age, gender, sport) VALUES (1, 'Alice', 25, 'Female', 'Basketball'); INSERT INTO players (id, name, age, gender, sport) VALUES (2, 'Bob', 30, 'Male', 'Basketball');
What is the average age of female basketball players?
SELECT AVG(age) FROM players WHERE gender = 'Female' AND sport = 'Basketball';
gretelai_synthetic_text_to_sql
CREATE TABLE Users (UserId INT, Age INT, Name VARCHAR(50)); INSERT INTO Users (UserId, Age, Name) VALUES (1, 35, 'Alice'); INSERT INTO Users (UserId, Age, Name) VALUES (2, 28, 'Bob'); CREATE TABLE DigitalAssets (AssetId INT, AssetName VARCHAR(50), UserId INT); INSERT INTO DigitalAssets (AssetId, AssetName, UserId) VALUES (1, 'ETH', 1); INSERT INTO DigitalAssets (AssetId, AssetName, UserId) VALUES (2, 'BTC', 2);
What are the names and types of digital assets owned by users with age greater than 30?
SELECT u.Name, da.AssetName FROM Users u INNER JOIN DigitalAssets da ON u.UserId = da.UserId WHERE u.Age > 30;
gretelai_synthetic_text_to_sql
CREATE TABLE languages (name VARCHAR(255), native_speakers INT, continent VARCHAR(255)); INSERT INTO languages (name, native_speakers, continent) VALUES ('Navajo', 170000, 'North America'); INSERT INTO languages (name, native_speakers, continent) VALUES ('Cree', 117000, 'North America');
Which indigenous language in North America has the highest number of speakers, and what is the second-highest number of speakers for any indigenous language in North America?
SELECT name, native_speakers FROM languages WHERE continent = 'North America' AND native_speakers = (SELECT MAX(native_speakers) FROM languages WHERE continent = 'North America' AND native_speakers < (SELECT MAX(native_speakers) FROM languages WHERE continent = 'North America'));
gretelai_synthetic_text_to_sql
CREATE TABLE transactions (id INT, category VARCHAR(50), amount DECIMAL(10, 2), transaction_date DATE); INSERT INTO transactions (id, category, amount, transaction_date) VALUES (1, 'fine_dining', 150.50, '2022-06-01'), (2, 'gift_shop', 25.95, '2022-07-02'), (3, 'coffee_shop', 8.95, '2022-06-02');
Determine the average spending in the 'gift_shop' category for the month of July 2022.
SELECT AVG(amount) as avg_spending FROM transactions WHERE category = 'gift_shop' AND transaction_date BETWEEN '2022-07-01' AND '2022-07-31';
gretelai_synthetic_text_to_sql
CREATE TABLE co2_emissions (country VARCHAR(50), year INT, co2_emission FLOAT);
What is the total CO2 emission from Arctic countries between 2015 and 2019?
SELECT SUM(co2_emission) FROM co2_emissions WHERE year BETWEEN 2015 AND 2019 AND country IN ('Norway', 'Russia', 'Canada', 'Greenland', 'Finland', 'Sweden', 'Iceland');
gretelai_synthetic_text_to_sql
CREATE TABLE autonomous_vehicles (region VARCHAR(255), num_vehicles INT, num_total_vehicles INT); INSERT INTO autonomous_vehicles (region, num_vehicles, num_total_vehicles) VALUES ('California', 5000, 20000), ('Texas', 4000, 15000), ('New York', 3000, 10000), ('Florida', 2000, 8000);
What is the percentage of autonomous vehicles out of total vehicles in each region in the 'autonomous_vehicles' schema?
SELECT region, (num_vehicles * 100.0 / num_total_vehicles) AS percentage FROM autonomous_vehicles;
gretelai_synthetic_text_to_sql
CREATE TABLE likes_posts(region VARCHAR(20), post_date DATE, likes INT, posts INT); INSERT INTO likes_posts(region, post_date, likes, posts) VALUES('Europe', '2021-05-01', 1000, 100), ('Europe', '2021-05-02', 1100, 110), ('Europe', '2021-05-03', 1200, 120), ('Europe', '2021-05-04', 1300, 130), ('Europe', '2021-05-05', 1400, 140), ('Europe', '2021-05-06', 1500, 150), ('Europe', '2021-05-07', 1600, 160);
What was the average number of likes per post in Europe in the last month?
SELECT AVG(likes/posts) FROM likes_posts WHERE region = 'Europe' AND post_date >= DATEADD(month, -1, CURRENT_DATE)
gretelai_synthetic_text_to_sql
CREATE TABLE AstronautMedical (id INT, astronaut_id INT, nationality VARCHAR(50), medical_condition VARCHAR(50)); INSERT INTO AstronautMedical (id, astronaut_id, nationality, medical_condition) VALUES (1, 121, 'Brazil', 'Hypercalcemia'); INSERT INTO AstronautMedical (id, astronaut_id, nationality, medical_condition) VALUES (2, 122, 'Brazil', 'Urinary Tract Infection'); INSERT INTO AstronautMedical (id, astronaut_id, nationality, medical_condition) VALUES (3, 123, 'Brazil', 'Nausea');
List all unique medical conditions of astronauts from Brazil.
SELECT DISTINCT medical_condition FROM AstronautMedical WHERE nationality = 'Brazil';
gretelai_synthetic_text_to_sql
CREATE TABLE company (id INT, name TEXT, founding_year INT); INSERT INTO company (id, name, founding_year) VALUES (1, 'AquaTech', 2008), (2, 'BioFuels', 2012), (3, 'ClimaCorp', 2002); CREATE TABLE diversity_metrics (id INT, company_id INT, diversity_score DECIMAL); INSERT INTO diversity_metrics (id, company_id, diversity_score) VALUES (1, 1, 0.7), (2, 2, 0.8), (3, 3, 0.6);
Delete records from the diversity_metrics table for companies founded before 2010
WITH cte_company AS (DELETE FROM company WHERE founding_year < 2010 RETURNING id) DELETE FROM diversity_metrics WHERE company_id IN (SELECT id FROM cte_company);
gretelai_synthetic_text_to_sql
CREATE TABLE policyholder (policyholder_id INT, name VARCHAR(50), age INT, gender VARCHAR(10), zip_code INT, policy_number INT, policy_type VARCHAR(20)); CREATE TABLE policy (policy_id INT, policy_number INT, issue_date DATE, risk_score INT); CREATE TABLE claim (claim_id INT, policy_id INT, claim_date DATE, claim_amount INT);
What is the name, age, and policy type of policyholders who have filed a claim in the last week and have a risk score over 600?
SELECT policyholder.name, policyholder.age, policyholder.policy_type FROM policyholder JOIN policy ON policyholder.policy_number = policy.policy_number JOIN claim ON policy.policy_id = claim.policy_id WHERE claim_date >= DATEADD(WEEK, -1, GETDATE()) AND policy.risk_score > 600;
gretelai_synthetic_text_to_sql
CREATE TABLE departments (department_name VARCHAR(50), employee_count INT); INSERT INTO departments (department_name, employee_count) VALUES ('Engineering', 300), ('Human Resources', 150), ('Operations', 250);
What is the total number of employees per department, ordered by the department name in ascending order and total employees in descending order?
SELECT department_name, employee_count, RANK() OVER (ORDER BY employee_count DESC) as employee_rank FROM departments ORDER BY department_name ASC, employee_rank DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE Players (PlayerID INT, PlayerName VARCHAR(50)); INSERT INTO Players (PlayerID, PlayerName) VALUES (1, 'John Doe'), (2, 'Jane Smith'), (3, 'Mike Johnson'); CREATE TABLE EsportsWinners (EventID INT, PlayerID INT); INSERT INTO EsportsWinners (EventID, PlayerID) VALUES (1, 1), (2, 2), (3, 1), (4, 3);
List the names of players who have played in esports events.
SELECT PlayerName FROM Players WHERE PlayerID IN (SELECT PlayerID FROM EsportsWinners);
gretelai_synthetic_text_to_sql
create table DeviceTemperature (Device varchar(255), Temperature int, Timestamp datetime); insert into DeviceTemperature values ('Device1', 20, '2022-01-01 00:00:00'), ('Device2', 22, '2022-01-01 00:00:00'), ('Device1', 25, '2022-01-02 00:00:00');
What is the average temperature per device per day?
select Device, DATE(Timestamp) as Date, AVG(Temperature) as AvgTemperature from DeviceTemperature group by Device, Date;
gretelai_synthetic_text_to_sql
CREATE TABLE restaurants (name TEXT, revenue FLOAT); INSERT INTO restaurants (name, revenue) VALUES ('Pizzeria Spumoni', 15000.0), ('Pizzeria Yum', 18000.0), ('Bakery Bon Appetit', 22000.0);
Delete all restaurants with revenue less than 17000.00
DELETE FROM restaurants WHERE revenue < 17000.0;
gretelai_synthetic_text_to_sql
CREATE TABLE games (id INT, title VARCHAR(50), release_date DATE, genre VARCHAR(20));
List the top 5 most popular game genres in the last month, along with the number of games released in each genre.
SELECT g.genre, COUNT(g.id) AS games_released, SUM(CASE WHEN g.release_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH) THEN 1 ELSE 0 END) AS popular_in_last_month FROM games g GROUP BY g.genre ORDER BY games_released DESC, popular_in_last_month DESC LIMIT 5;
gretelai_synthetic_text_to_sql
CREATE TABLE ArtWorks (ArtworkID INT, Title VARCHAR(100), YearCreated INT, Category VARCHAR(50), ArtistID INT); INSERT INTO ArtWorks (ArtworkID, Title, YearCreated, Category, ArtistID) VALUES (1, 'Guernica', 1937, 'Modern Art', 1); INSERT INTO ArtWorks (ArtworkID, Title, YearCreated, Category, ArtistID) VALUES (2, 'Starry Night', 1889, 'Post-Impressionism', 2);
How many impressionist artworks were created between 1880 and 1900?
SELECT COUNT(ArtworkID) FROM ArtWorks WHERE YearCreated BETWEEN 1880 AND 1900 AND Category = 'Impressionism';
gretelai_synthetic_text_to_sql
CREATE TABLE students (student_id INT PRIMARY KEY, name VARCHAR(50), department VARCHAR(50), grant_recipient BOOLEAN, publication_date DATE); INSERT INTO students (student_id, name, department, grant_recipient, publication_date) VALUES (1, 'David', 'Social Sciences', FALSE, '2022-01-01'), (2, 'Gina', 'Social Sciences', TRUE, '2021-01-01'); CREATE TABLE publications (publication_id INT PRIMARY KEY, student_id INT, publication_date DATE); INSERT INTO publications (publication_id, student_id, publication_date) VALUES (1, 1, '2022-01-01');
Show the number of graduate students in the Social Sciences department who have published research in the past year but have not received any research grants.
SELECT COUNT(*) FROM students s LEFT JOIN grants g ON s.student_id = g.student_id WHERE s.department = 'Social Sciences' AND s.publication_date >= DATEADD(year, -1, GETDATE()) AND g.student_id IS NULL;
gretelai_synthetic_text_to_sql
CREATE TABLE feedback (id INT, area TEXT, category TEXT, sentiment TEXT); INSERT INTO feedback (id, area, category, sentiment) VALUES (1, 'City A', 'waste management', 'negative'), (2, 'Town B', 'waste management', 'positive'), (3, 'City A', 'waste management', 'negative');
What is the percentage of negative citizen feedback on waste management?
SELECT (COUNT(*) FILTER (WHERE sentiment = 'negative')) * 100.0 / COUNT(*) AS percentage FROM feedback WHERE category = 'waste management';
gretelai_synthetic_text_to_sql
CREATE TABLE students(id INT, program VARCHAR(255)); INSERT INTO students VALUES (1, 'mental health'), (2, 'mental health'), (3, 'physical health'), (4, 'physical health'), (5, 'traditional learning');
What is the total number of students in the mental health and physical health programs?
SELECT COUNT(*) FROM students WHERE program IN ('mental health', 'physical health');
gretelai_synthetic_text_to_sql
CREATE TABLE wells (well_id INT, well_name VARCHAR(50), region VARCHAR(50), production FLOAT); INSERT INTO wells (well_id, well_name, region, production) VALUES (1, 'Well A', 'North Sea', 10000);
What are the production figures for wells in the 'North Sea' region?
SELECT region, SUM(production) FROM wells WHERE region = 'North Sea' GROUP BY region;
gretelai_synthetic_text_to_sql
CREATE TABLE public_health_policy_analysis (id INT, policy_name VARCHAR(30), impact_score INT);
Insert new public health policy analysis data
INSERT INTO public_health_policy_analysis (id, policy_name, impact_score) VALUES (3, 'Policy A', 95);
gretelai_synthetic_text_to_sql
CREATE TABLE Department (id INT, department_name VARCHAR(255)); INSERT INTO Department (id, department_name) VALUES (1, 'Research and Development'), (2, 'Production'), (3, 'Quality Control'), (4, 'Maintenance'); CREATE TABLE ChemicalWaste (id INT, department_id INT, waste_amount INT, waste_date DATE); INSERT INTO ChemicalWaste (id, department_id, waste_amount, waste_date) VALUES (1, 1, 50, '2022-01-01'), (2, 1, 75, '2022-01-05'), (3, 2, 100, '2022-01-03'), (4, 2, 120, '2022-01-07'), (5, 3, 80, '2022-01-02'), (6, 3, 90, '2022-01-04'), (7, 4, 60, '2022-01-01'), (8, 4, 70, '2022-01-03');
What is the total amount of chemical waste produced by each department in the last quarter?
SELECT d.department_name as department, SUM(cw.waste_amount) as total_waste FROM ChemicalWaste cw JOIN Department d ON cw.department_id = d.id WHERE cw.waste_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 3 MONTH) AND CURDATE() GROUP BY d.department_name;
gretelai_synthetic_text_to_sql
CREATE TABLE hospitals (id INT, name TEXT, location TEXT, num_beds INT, state TEXT); INSERT INTO hospitals (id, name, location, num_beds, state) VALUES (1, 'Hospital A', 'Rural Texas', 200, 'Texas'), (2, 'Hospital B', 'Rural California', 250, 'California'); CREATE TABLE clinics (id INT, name TEXT, location TEXT, num_beds INT, state TEXT); INSERT INTO clinics (id, name, location, num_beds, state) VALUES (1, 'Clinic A', 'Rural Texas', 50, 'Texas'), (2, 'Clinic B', 'Rural California', 75, 'California'); CREATE TABLE distance (hospital_id INT, clinic_id INT, distance FLOAT); INSERT INTO distance (hospital_id, clinic_id, distance) VALUES (1, 1, 15.0), (1, 2, 20.0), (2, 1, 25.0), (2, 2, 30.0);
What is the number of rural hospitals and clinics in each state, and the number of clinics within a 20-mile radius of each hospital?
SELECT h.state, COUNT(h.id) AS num_hospitals, COUNT(c.id) AS num_clinics_within_20_miles FROM hospitals h INNER JOIN distance d ON h.id = d.hospital_id INNER JOIN clinics c ON d.clinic_id = c.id WHERE d.distance <= 20 GROUP BY h.state;
gretelai_synthetic_text_to_sql
CREATE TABLE claims (policyholder_id INT, claim_amount DECIMAL(10,2), policyholder_state VARCHAR(20)); INSERT INTO claims (policyholder_id, claim_amount, policyholder_state) VALUES (1, 500.00, 'Florida'), (2, 900.00, 'Florida'), (3, 700.00, 'Florida');
What is the maximum claim amount paid to policyholders in 'Florida'?
SELECT MAX(claim_amount) FROM claims WHERE policyholder_state = 'Florida';
gretelai_synthetic_text_to_sql
CREATE TABLE AssistiveTechnology (studentID INT, accommodationType VARCHAR(50), cost DECIMAL(5,2));
What is the average cost of accommodations per student who received accommodations in the MobilityImpairment category in the AssistiveTechnology table?
SELECT AVG(cost) FROM AssistiveTechnology WHERE studentID IN (SELECT studentID FROM AssistiveTechnology WHERE accommodationType = 'MobilityImpairment');
gretelai_synthetic_text_to_sql
CREATE TABLE renewable_installs (country VARCHAR(50), installations INT); INSERT INTO renewable_installs (country, installations) VALUES ('Germany', 5000), ('France', 3000), ('Germany', 2000), ('Spain', 4000);
Get the number of renewable energy installations in each country
SELECT country, COUNT(installs) FROM renewable_installs GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE Thales_Projects (id INT, corporation VARCHAR(20), region VARCHAR(20), project_name VARCHAR(20), completion_date DATE); INSERT INTO Thales_Projects (id, corporation, region, project_name, completion_date) VALUES (1, 'Thales Group', 'Africa', 'Project X', '2022-06-30');
Which defense projects has Thales Group completed in Africa?
SELECT project_name, completion_date FROM Thales_Projects WHERE corporation = 'Thales Group' AND region = 'Africa';
gretelai_synthetic_text_to_sql
CREATE TABLE training_data2 (id INT, algorithm VARCHAR(20), bias INT, fairness INT); INSERT INTO training_data2 (id, algorithm, bias, fairness) VALUES (1, 'Neural Network', 3, 7), (2, 'Decision Trees', 5, 6), (3, 'Neural Network', 4, 8);
Delete records with 'algorithm' = 'Neural Network' in the 'training_data2' table
DELETE FROM training_data2 WHERE algorithm = 'Neural Network';
gretelai_synthetic_text_to_sql
CREATE TABLE support_programs_2 (id INT, name TEXT, region TEXT, budget FLOAT, start_year INT); INSERT INTO support_programs_2 (id, name, region, budget, start_year) VALUES (1, 'Accessible Tech', 'Africa', 50000.00, 2018), (2, 'Mobility Training', 'Africa', 75000.00, 2017);
What is the total budget for support programs in Africa that were implemented after 2018?
SELECT SUM(budget) FROM support_programs_2 WHERE region = 'Africa' AND start_year > 2018;
gretelai_synthetic_text_to_sql
CREATE TABLE Donors (DonorID INT, DonorName TEXT, Gender TEXT, DonationAmount DECIMAL(10,2)); INSERT INTO Donors (DonorID, DonorName, Gender, DonationAmount) VALUES (6, 'Sophia Garcia', 'Female', 500), (7, 'Liam Thompson', 'Male', 700), (8, 'Olivia Anderson', 'Female', 600), (9, 'Benjamin Johnson', 'Male', 800), (10, 'Ava Martinez', 'Non-binary', 300);
What is the total donation amount per gender?
SELECT Gender, SUM(DonationAmount) FROM Donors GROUP BY Gender;
gretelai_synthetic_text_to_sql
CREATE TABLE green_buildings_toronto (id INT, building_name VARCHAR(50), city VARCHAR(50), building_type VARCHAR(50), certification_level VARCHAR(50)); INSERT INTO green_buildings_toronto (id, building_name, city, building_type, certification_level) VALUES (1, 'Toronto Green Tower', 'Toronto', 'Residential', 'LEED Gold');
List all green buildings in the city of Toronto, along with their types and certification levels.
SELECT building_name, building_type, certification_level FROM green_buildings_toronto WHERE city = 'Toronto';
gretelai_synthetic_text_to_sql
CREATE TABLE projects (id INT, name VARCHAR(50), sector VARCHAR(50), location VARCHAR(50), start_date DATE, end_date DATE); INSERT INTO projects (id, name, sector, location, start_date, end_date) VALUES (1, 'Solar Farm', 'Renewable Energy', 'California', '2015-01-01', '2025-12-31'); INSERT INTO projects (id, name, sector, location, start_date, end_date) VALUES (2, 'Green Roofs', 'Urban Development', 'New York', '2018-07-01', '2028-06-30'); INSERT INTO projects (id, name, sector, location, start_date, end_date) VALUES (3, 'Wind Farm', 'Renewable Energy', 'Brazil', '2016-01-01', '2026-12-31'); INSERT INTO projects (id, name, sector, location, start_date, end_date) VALUES (4, 'Public Transportation', 'Urban Development', 'Brazil', '2019-01-01', '2029-12-31');
Which countries have projects in both renewable energy and urban development sectors?
SELECT location FROM projects WHERE sector IN ('Renewable Energy', 'Urban Development') GROUP BY location HAVING COUNT(DISTINCT sector) = 2;
gretelai_synthetic_text_to_sql
CREATE TABLE warehouse_stats (id INT, warehouse_state VARCHAR(20), pallets INT, handling_date DATE); INSERT INTO warehouse_stats (id, warehouse_state, pallets, handling_date) VALUES (1, 'California', 45, '2022-01-03'), (2, 'Texas', 52, '2022-01-07');
What is the maximum number of pallets handled by a single warehouse in a day?
SELECT MAX(pallets) FROM warehouse_stats;
gretelai_synthetic_text_to_sql
CREATE TABLE sales (id INT, state VARCHAR(20), weight DECIMAL(10,2), month INT, year INT);
What was the total weight of cannabis sold in Oregon in the first quarter of 2021?
SELECT SUM(weight) FROM sales WHERE state = 'Oregon' AND month BETWEEN 1 AND 3 AND year = 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE volunteers (volunteer_id INT, volunteer_name TEXT, volunteer_region TEXT, volunteer_join_date DATE); INSERT INTO volunteers (volunteer_id, volunteer_name, volunteer_region, volunteer_join_date) VALUES (1, 'Jane Doe', 'Asia', '2021-01-01');
Find the number of volunteers who joined in Q1 2021 from 'Asia'?
SELECT COUNT(*) FROM volunteers WHERE EXTRACT(QUARTER FROM volunteer_join_date) = 1 AND volunteer_region = 'Asia';
gretelai_synthetic_text_to_sql
CREATE TABLE emergencies (type VARCHAR(255), response_time INT); INSERT INTO emergencies (type, response_time) VALUES ('Fire', 5), ('Medical', 8);
What is the difference in response time between fire and medical emergencies?
SELECT type, LEAD(response_time) OVER (ORDER BY response_time) - response_time AS difference FROM emergencies;
gretelai_synthetic_text_to_sql
CREATE TABLE oil_reservoirs (reservoir_id INT PRIMARY KEY, reservoir_name VARCHAR(255), discovered_year INT, oil_volume_bbls BIGINT);
Delete all records from the 'oil_reservoirs' table where the 'discovered_year' is before 1990
DELETE FROM oil_reservoirs WHERE discovered_year < 1990;
gretelai_synthetic_text_to_sql
CREATE TABLE investments (id INT, investor VARCHAR(20), sector VARCHAR(20), amount FLOAT); INSERT INTO investments (id, investor, sector, amount) VALUES (1, 'Green Capital', 'renewable energy', 500000.0), (2, 'Blue Horizon', 'technology', 750000.0), (3, 'Green Capital', 'sustainable agriculture', 350000.0);
Find all investments made by the investor 'Green Capital' in the 'renewable energy' sector.
SELECT * FROM investments WHERE investor = 'Green Capital' AND sector = 'renewable energy';
gretelai_synthetic_text_to_sql
CREATE TABLE Products (ProductID INT, ProductName VARCHAR(50), Category VARCHAR(50), Price DECIMAL(5,2), Vegan BOOLEAN); INSERT INTO Products (ProductID, ProductName, Category, Price, Vegan) VALUES (1, 'Liquid Lipstick', 'Makeup', 15.99, TRUE), (2, 'Mascara', 'Makeup', 9.99, FALSE), (3, 'Eyeshadow Palette', 'Makeup', 32.99, TRUE);
What is the average price of vegan products in the Makeup category?
SELECT Category, AVG(Price) FROM Products WHERE Category = 'Makeup' AND Vegan = TRUE GROUP BY Category;
gretelai_synthetic_text_to_sql
CREATE TABLE shark_encounters (encounter_id INT, species VARCHAR(255), encounter_date DATE); INSERT INTO shark_encounters (encounter_id, species, encounter_date) VALUES (1, 'Oceanic Whitetip Shark', '2021-09-12'), (2, 'Great White Shark', '2022-02-05');
Update the 'encounter_date' column in the 'shark_encounters' table, changing '2021-09-12' to '2022-09-12'
UPDATE shark_encounters SET encounter_date = '2022-09-12' WHERE encounter_date = '2021-09-12';
gretelai_synthetic_text_to_sql
CREATE TABLE mitigation_projects (country VARCHAR(50), year INT, status VARCHAR(50)); INSERT INTO mitigation_projects (country, year, status) VALUES ('Brazil', 2005, 'Completed'), ('Argentina', 2008, 'Completed'), ('Colombia', 2002, 'Completed'), ('Peru', 1999, 'In-progress');
How many mitigation projects were completed in Latin America before 2010?
SELECT COUNT(*) FROM mitigation_projects WHERE country IN ('Brazil', 'Argentina', 'Colombia') AND year < 2010 AND status = 'Completed';
gretelai_synthetic_text_to_sql
CREATE TABLE case_billing (case_id INT, attorney_id INT, billing_amount DECIMAL, case_date DATE); CREATE TABLE attorneys (attorney_id INT, attorney_last_name VARCHAR(50));
Find the total billing amount for cases handled by attorney 'Lee' in 2017.
SELECT SUM(billing_amount) FROM case_billing JOIN attorneys ON case_billing.attorney_id = attorneys.attorney_id WHERE attorneys.attorney_last_name = 'Lee' AND case_date BETWEEN '2017-01-01' AND '2017-12-31';
gretelai_synthetic_text_to_sql
CREATE TABLE sustainable_urbanism (id INT, city VARCHAR(20), initiative VARCHAR(50), start_date DATE); INSERT INTO sustainable_urbanism (id, city, initiative, start_date) VALUES (1, 'NYC', 'Green Roofs Program', '2010-01-01'), (2, 'LA', 'Bike Lane Expansion', '2015-05-01'), (3, 'NYC', 'Solar Power Incentives', '2012-07-01');
Which sustainable urbanism initiatives were implemented in NYC and when?
SELECT city, initiative, start_date FROM sustainable_urbanism WHERE city = 'NYC';
gretelai_synthetic_text_to_sql
CREATE TABLE marine_conservation (project_name VARCHAR(255), location VARCHAR(255)); INSERT INTO marine_conservation (project_name, location) VALUES ('Coral Restoration Project', 'Madagascar'), ('Seagrass Protection Program', 'Tanzania'), ('Marine Debris Cleanup', 'South Africa');
How many marine conservation projects are there in Africa?
SELECT COUNT(project_name) FROM marine_conservation WHERE location LIKE 'Africa%';
gretelai_synthetic_text_to_sql
CREATE TABLE restaurant_menu (restaurant_id INT, cuisine VARCHAR(255)); INSERT INTO restaurant_menu (restaurant_id, cuisine) VALUES (1, 'Italian'), (1, 'Mexican'), (2, 'Chinese'), (3, 'Italian');
List the unique cuisine types served in the restaurant.
SELECT DISTINCT cuisine FROM restaurant_menu;
gretelai_synthetic_text_to_sql
CREATE TABLE Players (id INT, name VARCHAR(50), age INT, platform VARCHAR(50), country VARCHAR(50), total_hours_played INT); INSERT INTO Players (id, name, age, platform, country, total_hours_played) VALUES (1, 'Player1', 25, 'PC', 'USA', 200), (2, 'Player2', 30, 'Console', 'Canada', 150), (3, 'Player3', 35, 'Mobile', 'USA', 250);
What is the total number of hours played by players in each country, and what is the maximum number of hours played by players from a single country?
SELECT country, SUM(total_hours_played) AS total_hours, MAX(total_hours_played) AS max_hours_per_country FROM Players GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE menu_revenue (menu_item VARCHAR(255), revenue DECIMAL(10,2)); INSERT INTO menu_revenue (menu_item, revenue) VALUES ('Burger', 8000.00), ('Sandwich', 9000.00), ('Pizza', 11000.00), ('Pasta', 7000.00), ('Salad', 13000.00);
Which menu items had the lowest revenue in the first quarter of 2022?
SELECT menu_item, MIN(revenue) as lowest_revenue FROM menu_revenue WHERE menu_revenue.menu_item IN (SELECT menu_item FROM menu_revenue WHERE revenue BETWEEN '2022-01-01' AND '2022-03-31') GROUP BY menu_item;
gretelai_synthetic_text_to_sql
CREATE TABLE london_trains (id INT, departure_time TIME, is_accessible BOOLEAN); INSERT INTO london_trains (id, departure_time, is_accessible) VALUES (1, '07:30:00', TRUE), (2, '08:45:00', FALSE);
Identify the most common departure times for accessible train rides in London.
SELECT is_accessible, MODE(departure_time) AS common_departure_time FROM london_trains WHERE is_accessible = TRUE GROUP BY is_accessible;
gretelai_synthetic_text_to_sql
CREATE TABLE unions (id INT, name TEXT, domain TEXT, members INT); INSERT INTO unions (id, name, domain, members) VALUES (1, 'International Association of Sheet Metal, Air, Rail and Transportation Workers', 'Transportation, Metals', 200000); INSERT INTO unions (id, name, domain, members) VALUES (2, 'United Steelworkers', 'Metals, Mining, Energy, Construction', 850000);
Update the number of members for the 'International Association of Sheet Metal, Air, Rail and Transportation Workers' to 250,000.
UPDATE unions SET members = 250000 WHERE name = 'International Association of Sheet Metal, Air, Rail and Transportation Workers';
gretelai_synthetic_text_to_sql
CREATE TABLE AthleteWellbeing (id INT, name VARCHAR(255), region VARCHAR(255), access_count INT, last_access DATE); INSERT INTO AthleteWellbeing (id, name, region, access_count, last_access) VALUES (1, 'Yoga', 'Pacific', 40, '2021-06-01'), (2, 'Meditation', 'Pacific', 60, '2022-02-01'), (3, 'Nutrition', 'Atlantic', 30, '2021-09-20'), (4, 'Yoga', 'Atlantic', 50, '2022-01-05'), (5, 'Meditation', 'Atlantic', 80, '2021-12-10');
Remove any athlete wellbeing programs that have not been accessed in the last 6 months.
DELETE FROM AthleteWellbeing WHERE last_access < DATE_SUB(CURRENT_DATE, INTERVAL 6 MONTH);
gretelai_synthetic_text_to_sql
CREATE TABLE Artists (id INT, name VARCHAR(255), language_preservation_contributions INT, UNIQUE(id));
Who are the top 5 artists with the most contributions to language preservation, and their total contributions?
SELECT Artists.name, SUM(Artists.language_preservation_contributions) as total_contributions FROM Artists ORDER BY total_contributions DESC LIMIT 5;
gretelai_synthetic_text_to_sql
CREATE TABLE humanitarian_assistance (id INT, provider_country VARCHAR(255), recipient_country VARCHAR(255), amount FLOAT, year INT);
Get the total amount of humanitarian assistance provided by each country in the year 2018
SELECT provider_country, SUM(amount) FROM humanitarian_assistance WHERE year = 2018 GROUP BY provider_country;
gretelai_synthetic_text_to_sql
CREATE TABLE posts (id INT PRIMARY KEY, user_id INT, post_date DATETIME, content TEXT);
How many times was hashtag #vegan used in posts in 2022?
SELECT COUNT(*) FROM posts JOIN hashtags ON posts.id = hashtags.post_id WHERE hashtags.name = '#vegan' AND YEAR(posts.post_date) = 2022;
gretelai_synthetic_text_to_sql
CREATE TABLE Funding (program_id INT, region VARCHAR(50), funding_amount DECIMAL(10,2), funding_date DATE); INSERT INTO Funding (program_id, region, funding_amount, funding_date) VALUES (1, 'Africa', 5000.00, '2021-01-01'), (2, 'Asia', 7000.00, '2021-02-01'), (3, 'Europe', 3000.00, '2021-03-01');
What was the total funding received by programs in 'Africa'?
SELECT SUM(funding_amount) AS total_funding FROM Funding WHERE region = 'Africa';
gretelai_synthetic_text_to_sql
CREATE TABLE company_founding (id INT, company_name VARCHAR(50), year INT, diversity_score DECIMAL(3, 2));
Calculate the average diversity score for companies founded between 2016 and 2018
SELECT AVG(diversity_score) AS avg_diversity_score FROM company_founding WHERE year BETWEEN 2016 AND 2018;
gretelai_synthetic_text_to_sql
CREATE TABLE donors (id INT, name TEXT, total_donations DECIMAL);
Insert a new record into the 'donors' table for 'Sophia Lee' with a total donation amount of $350
INSERT INTO donors (id, name, total_donations) VALUES (1, 'Sophia Lee', 350.00);
gretelai_synthetic_text_to_sql
CREATE TABLE game_sessions (SessionID INT, PlayerID INT, SessionDate DATE); INSERT INTO game_sessions (SessionID, PlayerID, SessionDate) VALUES (1, 1, '2021-06-01'); INSERT INTO game_sessions (SessionID, PlayerID, SessionDate) VALUES (2, 2, '2021-06-10');
Delete players who haven't played in the last month from 'game_sessions' table.
DELETE FROM game_sessions WHERE SessionDate < DATEADD(month, -1, GETDATE());
gretelai_synthetic_text_to_sql
CREATE TABLE attractions (id INT, name VARCHAR(50), city VARCHAR(20), rating FLOAT); INSERT INTO attractions (id, name, city, rating) VALUES (1, 'Opera House', 'Sydney', 4.6), (2, 'Bridge', 'Sydney', 3.8), (3, 'Tower', 'New York', 4.8);
What is the average rating of all attractions?
SELECT AVG(rating) FROM attractions;
gretelai_synthetic_text_to_sql
CREATE TABLE aircrafts (id INT, manufacturer VARCHAR(255), speed FLOAT, issues BOOLEAN); INSERT INTO aircrafts (id, manufacturer, speed, issues) VALUES (1, 'Aerospace Corp', 600, true), (2, 'Aerospace Corp', 700, false), (3, 'SpaceTech', 800, false);
What is the average speed of aircrafts manufactured by 'Aerospace Corp' that had issues during manufacturing?
SELECT AVG(speed) FROM aircrafts WHERE manufacturer = 'Aerospace Corp' AND issues = true;
gretelai_synthetic_text_to_sql
CREATE TABLE hospitals (id INT, name VARCHAR(50), location VARCHAR(50), capacity INT); INSERT INTO hospitals (id, name, location, capacity) VALUES (1, 'Cape Town Hospital', 'Cape Town', 400); CREATE TABLE patients (id INT, name VARCHAR(50), age INT, gender VARCHAR(10), city VARCHAR(50)); INSERT INTO patients (id, name, age, gender, city) VALUES (3, 'John Doe', 45, 'Male', 'Cape Town'); INSERT INTO patients (id, name, age, gender, city) VALUES (4, 'Jane Smith', 50, 'Female', 'Johannesburg');
List the hospitals in Cape Town with their capacity and the number of male patients.
SELECT hospitals.name, hospitals.capacity, COUNT(patients.id) FROM hospitals LEFT JOIN patients ON hospitals.location = patients.city AND patients.gender = 'Male' WHERE hospitals.location = 'Cape Town' GROUP BY hospitals.name;
gretelai_synthetic_text_to_sql
CREATE TABLE violations (violation_id INT, violation_date DATE, violation_details VARCHAR(255), fine_amount INT, state_id INT);
What is the average mental health parity violation fine amount by state?
SELECT AVG(fine_amount) as avg_fine_amount, state_id FROM violations GROUP BY state_id;
gretelai_synthetic_text_to_sql
CREATE TABLE districts (district_id INT, district_name VARCHAR(255));CREATE TABLE incidents (incident_id INT, district_id INT, incident_type VARCHAR(255), incident_date DATE);
Which districts have experienced the most fires in the past year?
SELECT district_name, COUNT(*) AS count FROM districts d JOIN incidents i ON d.district_id = i.district_id WHERE i.incident_type = 'Fire' AND incident_date >= DATEADD(year, -1, GETDATE()) GROUP BY district_name ORDER BY count DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE green_buildings (property_id INT, building_type TEXT, construction_year INT); INSERT INTO green_buildings VALUES (1, 'Apartment', 2010), (2, 'House', 2005), (3, 'Townhouse', 2015)
Find the maximum 'construction_year' in green_buildings for each 'building_type'.
SELECT building_type, MAX(construction_year) AS max_construction_year FROM green_buildings GROUP BY building_type;
gretelai_synthetic_text_to_sql
CREATE TABLE food_safety(inspection_id INT, inspector VARCHAR(255), restaurant VARCHAR(255), inspection_date DATE, result ENUM('Pass', 'Fail'));
Insert new food safety records for the 'Health Inspector' with ID 678.
INSERT INTO food_safety (inspection_id, inspector, restaurant, inspection_date, result) VALUES (1234, '678', 'Mexican Grill', '2022-02-15', 'Pass'), (1235, '678', 'Vegan Cafe', '2022-02-16', 'Pass'), (1236, '678', 'Sushi Bar', '2022-02-17', 'Fail');
gretelai_synthetic_text_to_sql
CREATE TABLE yearly_copper (id INT, mine VARCHAR, country VARCHAR, year INT, quantity INT); INSERT INTO yearly_copper (id, mine, country, year, quantity) VALUES (1, 'MineA', 'Chile', 2020, 12000), (2, 'MineB', 'Chile', 2020, 15000), (3, 'MineA', 'Chile', 2021, 13000), (4, 'MineB', 'Chile', 2021, 16000), (5, 'MineC', 'Peru', 2020, 20000), (6, 'MineD', 'Peru', 2020, 22000), (7, 'MineC', 'Peru', 2021, 21000), (8, 'MineD', 'Peru', 2021, 24000);
What is the total quantity of copper mined in Chile and Peru in 2020 and 2021?
SELECT country, SUM(quantity) FROM yearly_copper WHERE (country IN ('Chile', 'Peru') AND year IN (2020, 2021)) GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE policyholders (policyholder_id INT, policyholder_name TEXT, policyholder_state TEXT, policyholder_dob DATE); INSERT INTO policyholders VALUES (1, 'John Doe', 'NY', '1980-01-01'); INSERT INTO policyholders VALUES (2, 'Jane Smith', 'CA', '1990-02-02'); CREATE TABLE claims_info (claim_id INT, policyholder_id INT, claim_amount FLOAT); INSERT INTO claims_info VALUES (1, 1, 500.0); INSERT INTO claims_info VALUES (2, 1, 700.0); INSERT INTO claims_info VALUES (3, 2, 300.0);
Select policyholder_state, AVG(claim_amount) from claims_info inner join policyholders using (policyholder_id) group by policyholder_state
SELECT policyholder_state, AVG(claim_amount) FROM claims_info INNER JOIN policyholders USING (policyholder_id) GROUP BY policyholder_state
gretelai_synthetic_text_to_sql
CREATE TABLE user_accounts (id INT, user_role VARCHAR(50));
What is the distribution of user roles in the system?
SELECT user_role, COUNT(*) as user_count FROM user_accounts GROUP BY user_role;
gretelai_synthetic_text_to_sql
CREATE TABLE MobilityTrips (trip_id INT, trip_date DATE, trip_type TEXT, city TEXT); CREATE TABLE SharedMobility (trip_id INT, trip_type TEXT);
What is the total number of shared mobility trips in the last quarter, broken down by city?
SELECT city, COUNT(*) AS total_trips FROM MobilityTrips mp INNER JOIN SharedMobility sm ON mp.trip_id = sm.trip_id WHERE trip_date >= DATE_SUB(CURDATE(), INTERVAL 3 MONTH) GROUP BY city;
gretelai_synthetic_text_to_sql
CREATE TABLE Claims (ClaimID INT, PolicyID INT, ClaimAmount DECIMAL(10,2)); INSERT INTO Claims (ClaimID, PolicyID, ClaimAmount) VALUES (1, 1, 5000.00), (2, 2, 120000.00), (3, 4, 7500.00); CREATE TABLE Policyholders (PolicyID INT, CoverageLimit DECIMAL(10,2)); INSERT INTO Policyholders (PolicyID, CoverageLimit) VALUES (1, 750000.00), (2, 400000.00), (4, 50000.00);
Delete any claim records for policyholders with a coverage limit under $100,000.
WITH LowLimitClaims AS (DELETE FROM Claims WHERE PolicyID IN (SELECT PolicyID FROM Policyholders WHERE CoverageLimit < 100000) RETURNING *) SELECT * FROM LowLimitClaims;
gretelai_synthetic_text_to_sql
CREATE TABLE deep_sea_expeditions (expedition_name TEXT, location TEXT, year INTEGER); INSERT INTO deep_sea_expeditions (expedition_name, location, year) VALUES ('Atlantic Deep', 'Atlantic Ocean', 2020), ('Mariana Trench Expedition', 'Pacific Ocean', 2019);
How many deep-sea expeditions have been conducted in the Atlantic Ocean?
SELECT COUNT(*) FROM deep_sea_expeditions WHERE location = 'Atlantic Ocean';
gretelai_synthetic_text_to_sql
CREATE TABLE appointment (id INT PRIMARY KEY, patient_id INT, doctor_id INT, appointment_date DATE);CREATE VIEW doctor_appointments AS SELECT doctor_id, COUNT(*) as num_appointments FROM appointment GROUP BY doctor_id;
Create a view that shows the number of appointments for each doctor
SELECT * FROM doctor_appointments;
gretelai_synthetic_text_to_sql
CREATE TABLE threat_actors (id INT, name VARCHAR, alias TEXT, country VARCHAR); INSERT INTO threat_actors (id, name, alias, country) VALUES (1, 'APT28', 'Sofacy Group', 'Russia');
Update the alias of the 'APT28' threat actor to 'Fancy Bear' in the 'threat_actors' table
UPDATE threat_actors SET alias='Fancy Bear' WHERE name='APT28';
gretelai_synthetic_text_to_sql
CREATE TABLE Restaurants (restaurant_id INT, name VARCHAR(255), state VARCHAR(255), cuisine VARCHAR(255), revenue DECIMAL(10,2)); INSERT INTO Restaurants (restaurant_id, name, state, cuisine, revenue) VALUES (1, 'Restaurant A', 'ON', 'Italian', 5000.00), (2, 'Restaurant B', 'TX', 'Mexican', 6000.00), (3, 'Restaurant C', 'NY', 'Italian', 4000.00);
What is the average revenue for restaurants in Ontario serving Italian cuisine?
SELECT state, AVG(revenue) FROM Restaurants WHERE cuisine = 'Italian' AND state = 'ON' GROUP BY state;
gretelai_synthetic_text_to_sql
CREATE TABLE fabric_sources (id INT, fabric_id INT, country VARCHAR(50), quantity INT); INSERT INTO fabric_sources (id, fabric_id, country, quantity) VALUES (1, 1, 'India', 500), (2, 1, 'Bangladesh', 300), (3, 2, 'China', 800), (4, 2, 'Taiwan', 200), (5, 3, 'Egypt', 750); CREATE TABLE fabrics (id INT, fabric_type VARCHAR(50), is_sustainable BOOLEAN); INSERT INTO fabrics (id, fabric_type, is_sustainable) VALUES (1, 'Organic Cotton', TRUE), (2, 'Recycled Polyester', TRUE), (3, 'Conventional Cotton', FALSE);
What is the total quantity of sustainable fabrics sourced from each country?
SELECT f.country, SUM(fs.quantity) AS total_quantity FROM fabric_sources fs INNER JOIN fabrics f ON fs.fabric_id = f.id WHERE f.is_sustainable = TRUE GROUP BY f.country;
gretelai_synthetic_text_to_sql
CREATE TABLE OilFields (FieldID INT, FieldName VARCHAR(50), Country VARCHAR(50), Production INT, Reserves INT); INSERT INTO OilFields (FieldID, FieldName, Country, Production, Reserves) VALUES (1, 'Galaxy', 'USA', 20000, 500000); INSERT INTO OilFields (FieldID, FieldName, Country, Production, Reserves) VALUES (2, 'Apollo', 'Canada', 15000, 400000);
Retrieve the total production and reserves for oil fields in the USA.
SELECT Country, SUM(Production) AS Total_Production, SUM(Reserves) AS Total_Reserves FROM OilFields WHERE Country = 'USA' GROUP BY Country;
gretelai_synthetic_text_to_sql
CREATE TABLE military_equipment (equipment_name VARCHAR(255), origin_country VARCHAR(255));
List all equipment names and their origins from the 'military_equipment' table
SELECT equipment_name, origin_country FROM military_equipment;
gretelai_synthetic_text_to_sql
CREATE TABLE donors (donor_id INT, donor_name TEXT, donor_country TEXT); INSERT INTO donors (donor_id, donor_name, donor_country) VALUES (1, 'John Doe', 'Nigeria'), (2, 'Jane Smith', 'USA'), (3, 'Alice Johnson', 'Canada'); CREATE TABLE donations (donation_id INT, donor_id INT, cause TEXT, amount DECIMAL(10,2)); INSERT INTO donations (donation_id, donor_id, cause, amount) VALUES (1, 1, 'Education', 500.00), (2, 1, 'Health', 300.00), (3, 2, 'Environment', 750.00), (4, 2, 'Education', 250.00), (5, 3, 'Health', 600.00); CREATE TABLE causes (cause_id INT, cause TEXT); INSERT INTO causes (cause_id, cause) VALUES (1, 'Education'), (2, 'Health'), (3, 'Environment');
What is the average donation amount for donors from Nigeria, grouped by cause?
SELECT d.donor_country, c.cause, AVG(donations.amount) as avg_donation FROM donors d JOIN donations ON d.donor_id = donations.donor_id JOIN causes c ON donations.cause = c.cause WHERE d.donor_country = 'Nigeria' GROUP BY d.donor_country, c.cause;
gretelai_synthetic_text_to_sql
CREATE TABLE Artifacts (ArtifactID INT, SiteID INT, ArtifactName TEXT, Archaeologist TEXT); INSERT INTO Artifacts (ArtifactID, SiteID, ArtifactName, Archaeologist) VALUES (1, 4, 'Death Mask of Tutankhamun', 'Howard Carter'), (2, 4, 'Rosetta Stone', 'Pierre-François Bouchard'), (3, 5, 'Giza Pyramids', 'Hassan Fathy');
List all artifacts from Egypt and their corresponding archaeologist's name.
SELECT ArtifactName, Archaeologist FROM Artifacts WHERE Country = 'Egypt';
gretelai_synthetic_text_to_sql
CREATE TABLE crop_yields (id INT, crop VARCHAR(50), year INT, yield FLOAT, state VARCHAR(50)); INSERT INTO crop_yields (id, crop, year, yield, state) VALUES (1, 'Corn', 2019, 115, 'IA'), (2, 'Corn', 2020, 120, 'IA'), (3, 'Corn', 2021, 125, 'IA'), (4, 'Soybeans', 2019, 45, 'IL'), (5, 'Soybeans', 2020, 50, 'IL'), (6, 'Soybeans', 2021, 55, 'IL');
Calculate the three-year moving average of 'yield' for the 'crop_yields' table, ordered by 'state'.
SELECT state, year, AVG(yield) OVER (PARTITION BY state ORDER BY year ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS moving_avg FROM crop_yields;
gretelai_synthetic_text_to_sql
CREATE TABLE time_tracking (attorney TEXT, cases TEXT, billable_hours DECIMAL(5,2)); INSERT INTO time_tracking (attorney, cases, billable_hours) VALUES ('Johnson', 'case1', 10.00), ('Johnson', 'case2', 12.00), ('Williams', 'case3', 15.00), ('Williams', 'case4', 18.00);
What is the average billable hours per case for attorneys in the 'nyc' region?
SELECT AVG(billable_hours) as avg_billable_hours FROM time_tracking JOIN attorneys ON time_tracking.attorney = attorneys.name WHERE attorneys.region = 'nyc';
gretelai_synthetic_text_to_sql