context
stringlengths
11
9.12k
question
stringlengths
0
1.06k
SQL
stringlengths
2
4.44k
source
stringclasses
28 values
CREATE TABLE Maintenance_Requests (request_id INT, equipment_type TEXT, city TEXT, request_date DATE); INSERT INTO Maintenance_Requests (request_id, equipment_type, city, request_date) VALUES (1, 'Helicopter', 'Tokyo', '2021-03-01'), (2, 'Tank', 'Tokyo', '2021-01-01');
How many military equipment maintenance requests were submitted in Tokyo in Q1 2021?
SELECT COUNT(*) FROM Maintenance_Requests WHERE city = 'Tokyo' AND QUARTER(request_date) = 1 AND year = 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE strain_sales (dispensary_id INT, sale_date DATE, strain_id INT, quantity INT); INSERT INTO strain_sales (dispensary_id, sale_date, strain_id, quantity) VALUES (1, '2022-01-01', 1, 50), (1, '2022-01-15', 2, 30), (1, '2022-02-05', 3, 25), (2, '2022-01-03', 1, 40), (2, '2022-01-31', 3, 50), (2, '2022-02-20', 1, 30);
How many times did each strain of cannabis sell at each dispensary in Q1 2022?
SELECT s.name, d.name, SUM(ss.quantity) as total_sales FROM strain_sales ss JOIN strains s ON ss.strain_id = s.id JOIN dispensaries d ON ss.dispensary_id = d.id WHERE ss.sale_date BETWEEN '2022-01-01' AND '2022-03-31' GROUP BY s.name, d.name;
gretelai_synthetic_text_to_sql
CREATE TABLE orders(order_id INT, dish VARCHAR(255), category VARCHAR(255), vegetarian BOOLEAN); INSERT INTO orders(order_id, dish, category, vegetarian) VALUES (1, 'Tofu Stir Fry', 'Starter', TRUE), (2, 'Lentil Soup', 'Starter', TRUE), (3, 'Chickpea Curry', 'Main', TRUE), (4, 'Tofu Curry', 'Main', TRUE), (5, 'Quinoa Salad', 'Side', TRUE);
Find the percentage of orders that include a vegetarian dish.
SELECT 100.0 * SUM(vegetarian) / COUNT(*) as vegetarian_percentage FROM orders;
gretelai_synthetic_text_to_sql
CREATE SCHEMA br_schema;CREATE TABLE br_schema.transportation_budget (year INT, service VARCHAR(20), amount INT);INSERT INTO br_schema.transportation_budget (year, service, amount) VALUES (2019, 'Transportation', 20000000);
What is the total budget allocated for transportation services in Brazil in 2019?
SELECT amount FROM br_schema.transportation_budget WHERE year = 2019 AND service = 'Transportation';
gretelai_synthetic_text_to_sql
CREATE TABLE customers (customer_id INT, name VARCHAR(255), state VARCHAR(255)); INSERT INTO customers (customer_id, name, state) VALUES (1, 'Customer A', 'WA'), (2, 'Customer B', 'WA'), (3, 'Customer C', 'OR'); CREATE TABLE purchases (purchase_id INT, customer_id INT, dispensary_id INT, purchase_date DATE); INSERT INTO purchases (purchase_id, customer_id, dispensary_id, purchase_date) VALUES (1, 1, 1, '2022-01-01'), (2, 1, 2, '2022-01-10'), (3, 2, 1, '2022-02-01'), (4, 3, 3, '2022-03-01');
How many unique customers made purchases at dispensaries in Washington state, along with their corresponding first purchase date?
SELECT c.name, MIN(p.purchase_date) as first_purchase_date FROM customers c INNER JOIN purchases p ON c.customer_id = p.customer_id WHERE c.state = 'WA' GROUP BY c.name;
gretelai_synthetic_text_to_sql
CREATE TABLE Manufacturers (name VARCHAR(50), satellites INT); INSERT INTO Manufacturers (name, satellites) VALUES ('SpaceX', 200), ('Boeing', 100), ('Lockheed Martin', 75);
Who are the top 2 manufacturers of satellites by number of satellites deployed?
SELECT name FROM Manufacturers WHERE satellites IN (SELECT MAX(satellites) FROM Manufacturers) LIMIT 2;
gretelai_synthetic_text_to_sql
CREATE TABLE cybersecurity_incidents (id INT, incident_name VARCHAR(50), country VARCHAR(50), year INT); INSERT INTO cybersecurity_incidents (id, incident_name, country, year) VALUES (1, 'SolarWinds hack', 'USA', 2020), (2, 'RansomEXX', 'Germany', 2021);
Identify the number of cybersecurity incidents reported per country in the 'cybersecurity_incidents' table.
SELECT country, COUNT(*) AS number_of_incidents FROM cybersecurity_incidents GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE Textiles (brand VARCHAR(20), fabric_type VARCHAR(20)); INSERT INTO Textiles (brand, fabric_type) VALUES ('Eco-conscious Living', 'Tencel'), ('Eco-conscious Living', 'Lyocell'), ('Green Garments', 'Organic Silk'), ('Green Garments', 'Ecovero');
Compare the number of sustainable fabric types in the 'Textiles' table between brands 'Eco-conscious Living' and 'Green Garments'.
SELECT COUNT(DISTINCT fabric_type) FROM Textiles WHERE brand = 'Eco-conscious Living' INTERSECT SELECT COUNT(DISTINCT fabric_type) FROM Textiles WHERE brand = 'Green Garments';
gretelai_synthetic_text_to_sql
CREATE TABLE marine_species (species_name TEXT, ocean TEXT, threatened BOOLEAN); INSERT INTO marine_species (species_name, ocean, threatened) VALUES ('Species A', 'Southern Ocean', TRUE); INSERT INTO marine_species (species_name, ocean, threatened) VALUES ('Species B', 'Southern Ocean', FALSE);
What is the total number of marine species observed in the Southern Ocean, and how many of these species are threatened?
SELECT COUNT(*) AS total_species, SUM(threatened) AS threatened_species FROM marine_species WHERE ocean = 'Southern Ocean';
gretelai_synthetic_text_to_sql
CREATE TABLE customer_complaints (complaint_id INT, carrier VARCHAR(50)); INSERT INTO customer_complaints (complaint_id, carrier) VALUES (1, 'Verizon'), (2, 'AT&T'), (3, 'Verizon'), (4, 'T-Mobile'); CREATE VIEW complaint_count_view AS SELECT carrier, COUNT(*) as complaint_count FROM customer_complaints GROUP BY carrier;
What is the distribution of customer complaints by mobile carrier?
SELECT carrier, complaint_count, complaint_count/SUM(complaint_count) OVER (PARTITION BY carrier) as complaint_percentage FROM complaint_count_view;
gretelai_synthetic_text_to_sql
CREATE TABLE FundingSources (FundingSourceID INT PRIMARY KEY, Name VARCHAR(100), Amount FLOAT, Date DATE);
Insert data for a recent grant from the National Endowment for the Arts
INSERT INTO FundingSources (FundingSourceID, Name, Amount, Date) VALUES (1, 'National Endowment for the Arts', 50000, '2021-12-15');
gretelai_synthetic_text_to_sql
CREATE TABLE clinical_trials (clinical_trial_id INT, drug_id INT, trial_phase INT, trial_outcome TEXT); INSERT INTO clinical_trials (clinical_trial_id, drug_id, trial_phase, trial_outcome) VALUES (1, 1002, 1, 'Completed'), (2, 1002, 2, 'Suspended'), (3, 1003, 1, 'Recruiting'), (4, 1001, 2, 'Completed'), (5, 1001, 3, 'Failed');
List clinical trials with their phases and outcomes for a different drug?
SELECT drug_id, trial_phase, trial_outcome FROM clinical_trials WHERE drug_id = 1002;
gretelai_synthetic_text_to_sql
CREATE TABLE org_info (org_id INT, org_name VARCHAR(50), location VARCHAR(50)); INSERT INTO org_info (org_id, org_name, location) VALUES (1, 'Genetech Labs', 'USA'), (2, 'BioCore', 'Canada'), (3, 'Synthesize Solutions', 'India'); CREATE TABLE bioreactor_data (org_id INT, volume FLOAT); INSERT INTO bioreactor_data (org_id, volume) VALUES (1, 15000), (1, 18000), (2, 20000), (2, 22000), (3, 12000), (3, 14000), (3, 16000);
What is the maximum bioreactor volume for each research organization?
SELECT org_name, MAX(volume) as max_volume FROM bioreactor_data JOIN org_info ON bioreactor_data.org_id = org_info.org_id GROUP BY org_id;
gretelai_synthetic_text_to_sql
CREATE TABLE marine_species (id INT, name VARCHAR(50), population INT);
Delete all records from the marine_species table where the species name contains 'Shark'
DELETE FROM marine_species WHERE name LIKE '%Shark%';
gretelai_synthetic_text_to_sql
CREATE TABLE programs (id INT, name TEXT, budget FLOAT); INSERT INTO programs (id, name, budget) VALUES (1, 'Education', 60000.00), (2, 'Health', 40000.00), (3, 'Arts', 30000.00);
List all programs and their corresponding budgets, sorted by budget in descending order.
SELECT * FROM programs ORDER BY budget DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE dysprosium_production (id INT, year INT, producer VARCHAR(255), dysprosium_prod FLOAT); INSERT INTO dysprosium_production (id, year, producer, dysprosium_prod) VALUES (1, 2020, 'China', 456.8), (2, 2020, 'USA', 345.6), (3, 2020, 'Australia', 678.9), (4, 2019, 'China', 567.8), (5, 2019, 'USA', 456.7);
Delete the row with the highest Dysprosium production in 2020.
DELETE FROM dysprosium_production WHERE (producer, dysprosium_prod) IN (SELECT producer, MAX(dysprosium_prod) FROM dysprosium_production WHERE year = 2020 GROUP BY producer);
gretelai_synthetic_text_to_sql
CREATE TABLE conservation_initiatives (id INT PRIMARY KEY AUTO_INCREMENT, country VARCHAR(255), cost FLOAT, initiative_type VARCHAR(255));
Show the average water conservation initiative cost for each country in the "conservation_initiatives" table
SELECT country, AVG(cost) FROM conservation_initiatives GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE warehouse (id INT, location VARCHAR(255)); INSERT INTO warehouse (id, location) VALUES (1, 'Chicago'), (2, 'Houston'); CREATE TABLE packages (id INT, warehouse_id INT, weight FLOAT); INSERT INTO packages (id, warehouse_id, weight) VALUES (1, 1, 50.3), (2, 1, 30.1), (3, 2, 70.0), (4, 2, 10.0);
How many packages were shipped from each warehouse, and what was the total weight shipped from each warehouse?
SELECT warehouse_id, COUNT(*) as num_packages, SUM(weight) as total_weight FROM packages GROUP BY warehouse_id;
gretelai_synthetic_text_to_sql
CREATE TABLE species (id INT, species_name VARCHAR, conservation_status VARCHAR); INSERT INTO species VALUES (1, 'Polar Bear', 'Vulnerable');
List the unique species and their conservation status in the Arctic region.
SELECT DISTINCT species_name, conservation_status FROM species;
gretelai_synthetic_text_to_sql
CREATE TABLE drugs (id INT, name VARCHAR(255), company VARCHAR(255), department VARCHAR(255), fda_approval_date DATE, sales FLOAT); INSERT INTO drugs (id, name, company, department, fda_approval_date, sales) VALUES (1, 'DrugA', 'Euro Biotech', 'Cardiology', '2017-01-01', 1000000), (2, 'DrugB', 'Asian BioTech', 'Cardiology', '2016-06-15', 2000000), (3, 'DrugC', 'North American Pharma', 'Cardiology', '2018-03-23', 3000000), (4, 'DrugD', 'Euro Biotech', 'Oncology', '2014-11-11', 4000000), (5, 'DrugE', 'Asian BioTech', 'Cardiology', '2015-09-10', 5000000);
List the top 5 drugs by sales in the cardiology department that were approved by the FDA after 2016, including the company name and the difference in sales between the top drug and each of the other top drugs.
SELECT a.name, a.company, a.sales, b.sales - a.sales AS sales_difference FROM drugs a INNER JOIN (SELECT * FROM drugs WHERE department = 'Cardiology' AND fda_approval_date > '2016-12-31' ORDER BY sales DESC LIMIT 5) b ON a.name = b.name ORDER BY sales DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE investments_3 (investment_id INT, strategy VARCHAR(20), return_rate DECIMAL(10,2), investment_date DATE); INSERT INTO investments_3 (investment_id, strategy, return_rate, investment_date) VALUES (1, 'Stock', 0.12, '2022-01-01'), (2, 'Bond', 0.05, '2022-02-01'), (3, 'Real Estate', 0.07, '2022-03-01');
What is the average investment return for each quarter?
SELECT DATE_FORMAT(investment_date, '%Y-%m') as month, AVG(return_rate) as avg_return FROM investments_3 GROUP BY YEAR(investment_date), QUARTER(investment_date);
gretelai_synthetic_text_to_sql
CREATE TABLE accounts (customer_id INT, account_type VARCHAR(20), balance DECIMAL(10, 2), transaction_date DATE);
Identify customers who have had an increasing balance for the past three consecutive transactions, partitioned by account type.
SELECT customer_id, account_type, balance FROM (SELECT customer_id, account_type, balance, transaction_date, LAG(balance, 2) OVER (PARTITION BY customer_id, account_type ORDER BY transaction_date) AS lag_balance_2 FROM accounts) AS lagged_accounts WHERE balance > lag_balance_2;
gretelai_synthetic_text_to_sql
CREATE TABLE crops (id INT, crop_type VARCHAR(255), avg_temperature DECIMAL(5,2)); INSERT INTO crops (id, crop_type, avg_temperature) VALUES (1, 'Corn', 20.5), (2, 'Soybean', 18.3), (3, 'Wheat', 15.6);
What is the average temperature in the 'crops' table for each crop type?
SELECT crop_type, AVG(avg_temperature) as AvgTemp FROM crops GROUP BY crop_type;
gretelai_synthetic_text_to_sql
CREATE TABLE legal_aid_orgs (org_id INT, name VARCHAR(50), city VARCHAR(50), state VARCHAR(20), languages VARCHAR(50)); INSERT INTO legal_aid_orgs (org_id, name, city, state, languages) VALUES (1, 'Legal Aid NYC', 'New York', 'New York', 'English, Spanish'), (2, 'Legal Services NYC', 'New York', 'New York', 'English');
What is the number of legal aid organizations in New York City that provide services in Spanish?
SELECT COUNT(*) FROM legal_aid_orgs WHERE city = 'New York' AND languages LIKE '%Spanish%';
gretelai_synthetic_text_to_sql
CREATE TABLE Dispensaries (id INT, name TEXT, state TEXT); INSERT INTO Dispensaries (id, name, state) VALUES (1, 'Dispensary A', 'Colorado'), (2, 'Dispensary B', 'Colorado'); CREATE TABLE Sales (dispensary_id INT, date DATE, price_per_gram INT); INSERT INTO Sales (dispensary_id, date, price_per_gram) VALUES (1, '2021-04-01', 10), (1, '2021-04-02', 12), (1, '2021-05-01', 11), (2, '2021-04-01', 9), (2, '2021-04-03', 8), (2, '2021-05-01', 9);
What was the average price per gram for each dispensary in Colorado in Q2 2021?
SELECT d.name, AVG(s.price_per_gram) as avg_price_per_gram FROM Dispensaries d INNER JOIN Sales s ON d.id = s.dispensary_id WHERE s.date BETWEEN '2021-04-01' AND '2021-06-30' GROUP BY d.name;
gretelai_synthetic_text_to_sql
CREATE TABLE exhibitions (exhibition_id INT PRIMARY KEY, exhibition_name VARCHAR(255), city VARCHAR(255), country VARCHAR(255));
Add a new exhibition and its details
INSERT INTO exhibitions (exhibition_id, exhibition_name, city, country) VALUES (123, 'Impressionist Masterpieces', 'Paris', 'France');
gretelai_synthetic_text_to_sql
CREATE TABLE Donors (donor_id INT, name VARCHAR(50), city VARCHAR(50)); INSERT INTO Donors (donor_id, name, city) VALUES (1, 'John Doe', 'New York'), (2, 'Jane Smith', 'Los Angeles');
What is the total number of donors by city?
SELECT city, COUNT(*) as total_donors FROM Donors GROUP BY city;
gretelai_synthetic_text_to_sql
CREATE TABLE Volunteers (id INT, user_id INT, program VARCHAR(50), hours DECIMAL(10, 2), volunteer_date DATE); INSERT INTO Volunteers (id, user_id, program, hours, volunteer_date) VALUES (1, 201, 'program A', 3.00, '2021-02-01'); INSERT INTO Volunteers (id, user_id, program, hours, volunteer_date) VALUES (9, 209, 'program E', 7.00, '2021-09-01');
Who volunteered the most hours in program E in 2021?
SELECT user_id, SUM(hours) FROM Volunteers WHERE program = 'program E' AND volunteer_date BETWEEN '2021-01-01' AND '2021-12-31' GROUP BY user_id ORDER BY SUM(hours) DESC LIMIT 1;
gretelai_synthetic_text_to_sql
CREATE TABLE products (id INT, name VARCHAR(255), category VARCHAR(255), price DECIMAL(5,2), vegan BOOLEAN); INSERT INTO products (id, name, category, price, vegan) VALUES (1, 'Shampoo', 'haircare', 12.99, true), (2, 'Conditioner', 'haircare', 14.99, true), (3, 'Hair Spray', 'haircare', 7.99, false);
Update the price of all vegan haircare products to increase by 5%.
UPDATE products SET price = price * 1.05 WHERE category = 'haircare' AND vegan = true;
gretelai_synthetic_text_to_sql
CREATE TABLE tb_cases (id INT, case_date DATE, location TEXT); INSERT INTO tb_cases (id, case_date, location) VALUES (1, '2021-12-31', 'India'); INSERT INTO tb_cases (id, case_date, location) VALUES (2, '2022-02-05', 'India');
How many tuberculosis cases were reported in India in the last year?
SELECT COUNT(*) FROM tb_cases WHERE location = 'India' AND case_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR);
gretelai_synthetic_text_to_sql
CREATE TABLE carbon_prices (id INT, country TEXT, price DECIMAL); INSERT INTO carbon_prices (id, country, price) VALUES (1, 'EU', 25.5), (2, 'EU', 26.3), (3, 'EU', 24.8);
What is the average carbon price in the EU?
SELECT AVG(price) FROM carbon_prices WHERE country = 'EU';
gretelai_synthetic_text_to_sql
CREATE TABLE workplaces (id INT, country VARCHAR(50), num_lrvs INT, num_employees INT); INSERT INTO workplaces (id, country, num_lrvs, num_employees) VALUES (1, 'Mexico', 2, 100), (2, 'Mexico', 5, 200), (3, 'Mexico', 3, 150);
What is the total number of labor rights violations in workplaces in Mexico?
SELECT SUM(num_lrvs) FROM workplaces WHERE country = 'Mexico';
gretelai_synthetic_text_to_sql
CREATE TABLE suppliers (id INT, name VARCHAR(255), country VARCHAR(255)); INSERT INTO suppliers (id, name, country) VALUES (1, 'Supplier A', 'United States'), (2, 'Supplier B', 'Canada'), (3, 'Supplier C', 'United States'), (4, 'Supplier D', 'Mexico');
How many suppliers are there in the database from the United States?
SELECT COUNT(*) FROM suppliers WHERE country = 'United States';
gretelai_synthetic_text_to_sql
CREATE TABLE EsportsEvents (EventID INT, Country VARCHAR(20), PlayerID INT); INSERT INTO EsportsEvents (EventID, Country, PlayerID) VALUES (1, 'USA', 1), (2, 'Canada', 2), (3, 'USA', 3);
How many players have participated in esports events from each country?
SELECT Country, COUNT(DISTINCT PlayerID) FROM EsportsEvents GROUP BY Country;
gretelai_synthetic_text_to_sql
CREATE TABLE tv_shows (id INT, title VARCHAR(255), rating FLOAT, release_year INT, producer VARCHAR(50)); INSERT INTO tv_shows (id, title, rating, release_year, producer) VALUES (1, 'Show1', 7.5, 2010, 'Producer1'), (2, 'Show2', 8.2, 2012, 'Producer1'), (3, 'Show3', 6.8, 2015, 'Producer1'), (4, 'Show4', 8.8, 2011, 'Producer2'), (5, 'Show5', 7.5, 2014, 'Producer2');
Who are the producers who have released more than 2 TV shows with an average rating of 7 or higher in the United States?
SELECT producer FROM tv_shows WHERE rating >= 7 GROUP BY producer HAVING COUNT(*) > 2;
gretelai_synthetic_text_to_sql
CREATE TABLE Volunteers (VolunteerID int, ProgramID int, VolunteerHours decimal(10, 2), VolunteerDate date); INSERT INTO Volunteers (VolunteerID, ProgramID, VolunteerHours, VolunteerDate) VALUES (1, 1, 5.0, '2021-10-01'), (2, 1, 8.0, '2021-11-01'), (3, 2, 3.0, '2021-12-01'), (4, 3, 7.0, '2022-01-01'); CREATE TABLE Programs (ProgramID int, ProgramName varchar(255)); INSERT INTO Programs (ProgramID, ProgramName) VALUES (1, 'Education'), (2, 'Health'), (3, 'Environment');
Calculate the number of unique volunteers and total volunteer hours per quarter for each program?
SELECT ProgramID, DATE_TRUNC('quarter', VolunteerDate) AS Quarter, COUNT(DISTINCT VolunteerID) AS UniqueVolunteers, SUM(VolunteerHours) AS TotalVolunteerHours FROM Volunteers GROUP BY ProgramID, Quarter;
gretelai_synthetic_text_to_sql
CREATE TABLE Policyholders (PolicyID INT, PolicyholderName VARCHAR(50), RiskScore INT, PolicyDuration INT, Region VARCHAR(20)); INSERT INTO Policyholders VALUES (1, 'John Smith', 500, 36, 'Caribbean'); INSERT INTO Policyholders VALUES (2, 'Jane Doe', 700, 24, 'Africa');
What is the maximum policy duration for policyholders in the Caribbean region with a risk score between 400 and 600?
SELECT MAX(p.PolicyDuration) as MaxPolicyDuration FROM Policyholders p WHERE p.Region = 'Caribbean' AND p.RiskScore BETWEEN 400 AND 600;
gretelai_synthetic_text_to_sql
CREATE TABLE visitors_info (visitor_id INT, visit_date DATE, city VARCHAR(255)); INSERT INTO visitors_info (visitor_id, visit_date, city) VALUES (1, '2022-01-01', 'Paris'), (2, '2022-01-03', 'London'), (3, '2022-01-05', 'Paris');
How many visitors attended the museum in the last week from the city of Paris?
SELECT COUNT(*) FROM visitors_info WHERE city = 'Paris' AND visit_date >= DATEADD(week, -1, GETDATE());
gretelai_synthetic_text_to_sql
CREATE TABLE Donations (DonationID int, Sector varchar(50), Amount int); INSERT INTO Donations (DonationID, Sector, Amount) VALUES (1, 'Health', 1000), (2, 'Education', 2000), (3, 'Health', 1500), (4, 'Infrastructure', 500);
What is the total amount of donations for each sector?
SELECT s.Sector, SUM(d.Amount) AS TotalDonations FROM Donations d RIGHT JOIN (SELECT DISTINCT Sector FROM Donations) s ON d.Sector = s.Sector GROUP BY s.Sector;
gretelai_synthetic_text_to_sql
CREATE TABLE astronauts (id INT, name VARCHAR(50), age INT, spacecraft_experience VARCHAR(50));CREATE TABLE missions (id INT, astronaut_id INT, spacecraft VARCHAR(50), mission_destination VARCHAR(50)); INSERT INTO astronauts VALUES (1, 'Mark Watney', 40, 'Dragon'); INSERT INTO missions VALUES (1, 1, 'Dragon', 'ISS');
What is the average age of astronauts who have piloted Dragon spacecraft on missions to ISS?
SELECT AVG(astronauts.age) FROM astronauts INNER JOIN missions ON astronauts.id = missions.astronaut_id WHERE astronauts.spacecraft_experience = 'Dragon' AND missions.mission_destination = 'ISS';
gretelai_synthetic_text_to_sql
CREATE TABLE Artworks (id INT, title VARCHAR(50)); CREATE TABLE Exhibitions (id INT, artwork_id INT, gallery_id INT); CREATE TABLE Galleries (id INT, name VARCHAR(30));
List all artworks that were exhibited in more than one gallery, along with the names of the galleries and the total number of exhibitions.
SELECT a.title, GROUP_CONCAT(g.name) as gallery_names, COUNT(DISTINCT e.gallery_id) as num_exhibitions FROM Artworks a JOIN Exhibitions e ON a.id = e.artwork_id JOIN Galleries g ON e.gallery_id = g.id GROUP BY a.title HAVING num_exhibitions > 1;
gretelai_synthetic_text_to_sql
CREATE TABLE City_Autonomous_Vehicle_Adoption (id INT, city VARCHAR(50), autonomous_adoption INT, vehicle_type VARCHAR(50));
What is the total number of autonomous buses and trains in each city?
SELECT city, SUM(autonomous_adoption) FROM City_Autonomous_Vehicle_Adoption WHERE vehicle_type IN ('bus', 'train') GROUP BY city;
gretelai_synthetic_text_to_sql
CREATE TABLE products (product_id INT, product_name VARCHAR(50), uses_recycled_materials BIT); INSERT INTO products (product_id, product_name, uses_recycled_materials) VALUES (1, 'Product A', 1), (2, 'Product B', 0), (3, 'Product C', 1); CREATE TABLE pricing (product_id INT, retail_price DECIMAL(5, 2)); INSERT INTO pricing (product_id, retail_price) VALUES (1, 25.99), (2, 34.99), (3, 19.99);
Insert new records for products made with recycled materials and their corresponding retail prices.
INSERT INTO pricing (product_id, retail_price) SELECT 4 as product_id, 29.99 as retail_price WHERE EXISTS (SELECT 1 FROM products WHERE product_id = 4 AND uses_recycled_materials = 1);
gretelai_synthetic_text_to_sql
CREATE TABLE green_buildings (id INT PRIMARY KEY, name VARCHAR(50), location VARCHAR(50), size INT, certification VARCHAR(50));
Insert records into 'green_buildings' for three buildings
INSERT INTO green_buildings (id, name, location, size, certification) VALUES (1, 'EcoTower', 'Singapore', 50000, 'LEED Platinum'); INSERT INTO green_buildings (id, name, location, size, certification) VALUES (2, 'GreenHaus', 'Berlin', 35000, 'DGNB Gold'); INSERT INTO green_buildings (id, name, location, size, certification) VALUES (3, 'SustainaCentre', 'Sydney', 40000, 'Green Star');
gretelai_synthetic_text_to_sql
CREATE TABLE membership_data (member_id INT, join_date DATE); CREATE TABLE workout_data (workout_id INT, member_id INT, workout_date DATE);
List members who did no workouts in the last quarter of 2021.
SELECT m.member_id, m.join_date FROM membership_data m LEFT JOIN workout_data w ON m.member_id = w.member_id WHERE QUARTER(w.workout_date) IS NULL AND YEAR(w.workout_date) = 2021 AND QUARTER(m.join_date) <> 4;
gretelai_synthetic_text_to_sql
CREATE TABLE FoodSafetyRecords(product_id INT, product_name VARCHAR(50), is_organic BOOLEAN, calorie_count INT);
What is the average calorie count for organic products in the FoodSafetyRecords table?
SELECT AVG(calorie_count) FROM FoodSafetyRecords WHERE is_organic = TRUE;
gretelai_synthetic_text_to_sql
CREATE TABLE southern_marine_life (species VARCHAR(255), count INT); INSERT INTO southern_marine_life (species, count) VALUES ('Seal', 300), ('Whale', 250), ('Turtle', 150), ('Dolphin', 200);
What is the total number of marine mammals and reptiles observed in the Southern Ocean?
SELECT SUM(count) FROM southern_marine_life WHERE species IN ('Seal', 'Whale', 'Turtle');
gretelai_synthetic_text_to_sql
CREATE TABLE farm_arctic (farm_id INT, temperature FLOAT); INSERT INTO farm_arctic (farm_id, temperature) VALUES (1, 10), (2, 12), (3, 8), (4, 15), (5, 11); CREATE VIEW farm_arctic_view AS SELECT farm_id, temperature FROM farm_arctic WHERE temperature BETWEEN 8 AND 15;
Determine the maximum and minimum water temperature in fish farms in the Arctic region.
SELECT MIN(temperature), MAX(temperature) FROM farm_arctic_view;
gretelai_synthetic_text_to_sql
INSERT INTO companies (id, name, country, sector, ESG_score) VALUES (6, 'HealthCo', 'Brazil', 'Healthcare', 88.0), (7, 'CareCo', 'Colombia', 'Healthcare', 82.0);
Show companies in the healthcare sector with ESG scores above 85 in Latin America.
SELECT * FROM companies WHERE sector = 'Healthcare' AND ESG_score > 85 AND companies.country LIKE 'Latin%';
gretelai_synthetic_text_to_sql
CREATE TABLE marine_trenches (id INT, name TEXT, depth FLOAT, location TEXT); INSERT INTO marine_trenches (id, name, depth, location) VALUES (1, 'Mariana Trench', 10994.0, 'Pacific Ocean'), (2, 'Tonga Trench', 10882.0, 'Pacific Ocean');
Find the average depth of the Mariana Trench.
SELECT AVG(depth) FROM marine_trenches WHERE name = 'Mariana Trench';
gretelai_synthetic_text_to_sql
CREATE TABLE martian_temperatures(id INT, date DATE, temperature FLOAT, lander VARCHAR(255)); INSERT INTO martian_temperatures VALUES (1, '1976-06-21', -20.7, 'Viking 1'); INSERT INTO martian_temperatures VALUES (2, '1976-07-01', -17.8, 'Viking 1'); INSERT INTO martian_temperatures VALUES (3, '1976-07-15', -12.3, 'Viking 1');
What is the maximum temperature recorded by the Viking 1 lander on Mars?
SELECT MAX(temperature) FROM martian_temperatures WHERE lander = 'Viking 1';
gretelai_synthetic_text_to_sql
CREATE TABLE companies (id INT, name TEXT, industry TEXT, founder_region TEXT, funding_received FLOAT); INSERT INTO companies (id, name, industry, founder_region, funding_received) VALUES (1, 'FintechSA', 'Fintech', 'SouthAmerica', 1000000); INSERT INTO companies (id, name, industry, founder_region, funding_received) VALUES (2, 'GreenTechMale', 'GreenTech', 'Europe', 750000);
What is the total funding received by startups in the fintech sector founded by a person from South America?
SELECT SUM(funding_received) FROM companies WHERE industry = 'Fintech' AND founder_region = 'SouthAmerica';
gretelai_synthetic_text_to_sql
CREATE TABLE wind_energy_infrastructure (project_id INT, state VARCHAR(50), project_type VARCHAR(50), investment_cost INT);
What is the total investment (in USD) in wind energy infrastructure projects, grouped by state and project type, where the total investment is greater than 5,000,000 USD?
SELECT state, project_type, SUM(investment_cost) FROM wind_energy_infrastructure GROUP BY state, project_type HAVING SUM(investment_cost) > 5000000;
gretelai_synthetic_text_to_sql
CREATE TABLE berlin_transport (route_id INT, vehicle_type VARCHAR(10), departure_time TIME); INSERT INTO berlin_transport (route_id, vehicle_type, departure_time) VALUES (1, 'Bus', '06:00:00'), (1, 'Train', '06:30:00'), (2, 'Bus', '07:00:00'), (2, 'Train', '07:30:00');
What is the earliest departure time for each vehicle type in the Berlin public transportation system?
SELECT vehicle_type, MIN(departure_time) FROM berlin_transport GROUP BY vehicle_type;
gretelai_synthetic_text_to_sql
CREATE TABLE social_enterprises_esg (id INT, name TEXT, sector TEXT, score FLOAT); INSERT INTO social_enterprises_esg (id, name, sector, score) VALUES (1, 'HealthTech Nonprofit', 'Health', 85.2), (2, 'Medical Innovations Co.', 'Health', 92.3);
What is the maximum ESG score for social enterprises in the Health sector?
SELECT MAX(score) FROM social_enterprises_esg WHERE sector = 'Health';
gretelai_synthetic_text_to_sql
CREATE TABLE EmployeeInfo (EmployeeID INT, Identity VARCHAR(20), Department VARCHAR(20)); INSERT INTO EmployeeInfo (EmployeeID, Identity, Department) VALUES (1, 'LGBTQ+', 'Finance'), (2, 'Straight', 'Marketing');
What is the percentage of employees who identify as LGBTQ+ in the finance department?
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM EmployeeInfo)) AS Percentage FROM EmployeeInfo WHERE Identity = 'LGBTQ+' AND Department = 'Finance';
gretelai_synthetic_text_to_sql
CREATE TABLE mobile_plans (plan_name TEXT, monthly_cost FLOAT, data_allowance INT, start_date DATE); INSERT INTO mobile_plans (plan_name, monthly_cost, data_allowance, start_date) VALUES ('PlanA', 40, 2, '2022-01-01'), ('PlanB', 50, 4, '2022-01-01');
What is the total revenue generated from data plans in Q1 2022?
SELECT SUM(monthly_cost) FROM mobile_plans WHERE start_date >= '2022-01-01' AND start_date < '2022-04-01';
gretelai_synthetic_text_to_sql
CREATE TABLE service_requests (id INT, priority TEXT, response_time INT, city TEXT);
What is the average response time for high-priority service requests in CityA?
SELECT AVG(response_time) FROM service_requests WHERE priority = 'high' AND city = 'CityA';
gretelai_synthetic_text_to_sql
CREATE TABLE EngineeringPrograms (ProgramID INT, ProgramName VARCHAR(50)); CREATE TABLE NursingPrograms (ProgramID INT, ProgramName VARCHAR(50)); INSERT INTO EngineeringPrograms VALUES (1, 'Engineering Scholars'), (2, 'Accessible Labs'), (3, 'Research Grants'), (4, 'Mentorship'); INSERT INTO NursingPrograms VALUES (2, 'Accessible Labs'), (3, 'Clinical Skills'), (4, 'Simulation Labs');
List the support programs offered in the Engineering faculty that are not offered in the Nursing faculty.
SELECT ProgramName FROM EngineeringPrograms WHERE ProgramName NOT IN (SELECT ProgramName FROM NursingPrograms);
gretelai_synthetic_text_to_sql
CREATE TABLE workplaces (id INT, name VARCHAR(255), union_status VARCHAR(255), num_employees INT); INSERT INTO workplaces (id, name, union_status, num_employees) VALUES (1, 'ABC Company', 'Union', 500), (2, 'XYZ Corporation', 'Union', 250), (3, 'DEF Industries', 'Non-Union', 300), (4, 'GHI Company', 'Non-Union', 1000);
What is the minimum and maximum number of employees in workplaces, categorized by union status?
SELECT MIN(num_employees) as 'Minimum', MAX(num_employees) as 'Maximum', union_status FROM workplaces GROUP BY union_status;
gretelai_synthetic_text_to_sql
CREATE TABLE Workshops (WorkshopID INT, TeacherID INT, WorkshopName VARCHAR(100), Attendance INT);
Insert data into 'Workshops' table with values (1, 2, 'Introduction to Physics', 15), (2, 1, 'Advanced Algebra', 20)
INSERT INTO Workshops (WorkshopID, TeacherID, WorkshopName, Attendance) VALUES (1, 2, 'Introduction to Physics', 15), (2, 1, 'Advanced Algebra', 20);
gretelai_synthetic_text_to_sql
CREATE TABLE companies (id INT, name TEXT, founding_date DATE, founder_gender TEXT); INSERT INTO companies (id, name, founding_date, founder_gender) VALUES (1, 'TechCo', '2012-01-01', 'Male'); INSERT INTO companies (id, name, founding_date, founder_gender) VALUES (2, 'GreenEnergy', '2015-01-01', 'Female'); CREATE TABLE funding_records (id INT, company_id INT, funding_amount INT, funding_date DATE); INSERT INTO funding_records (id, company_id, funding_amount, funding_date) VALUES (1, 1, 1000000, '2018-01-01');
List the names of companies that received funding after being founded for more than 5 years.
SELECT companies.name FROM companies JOIN funding_records ON companies.id = funding_records.company_id WHERE DATEDIFF(funding_records.funding_date, companies.founding_date) > (5 * 365)
gretelai_synthetic_text_to_sql
CREATE TABLE smart_cities (city VARCHAR(50), country VARCHAR(50), solar_capacity INT); INSERT INTO smart_cities (city, country, solar_capacity) VALUES ('City1', 'Japan', 10000), ('City2', 'Japan', 15000), ('City3', 'Japan', 8000);
List all smart city projects in Japan and their corresponding installed capacity of solar panels.
SELECT * FROM smart_cities WHERE country = 'Japan';
gretelai_synthetic_text_to_sql
CREATE TABLE regulatory_frameworks (rf_id INT, name VARCHAR(255)); CREATE TABLE smart_contracts (sc_id INT, name VARCHAR(255), rf_id INT);
What is the total number of smart contracts associated with each regulatory framework?
SELECT rf_id, name, COUNT(sc_id) OVER (PARTITION BY rf_id) as total_smart_contracts FROM smart_contracts sc JOIN regulatory_frameworks rf ON sc.rf_id = rf.rf_id;
gretelai_synthetic_text_to_sql
CREATE TABLE Equipment (id INT, type VARCHAR(255), quantity INT);
Show the total quantity of military equipment for each type in the 'Equipment' table
SELECT type, SUM(quantity) as total_quantity FROM Equipment GROUP BY type;
gretelai_synthetic_text_to_sql
CREATE TABLE countries (country_name TEXT, deep_sea_program TEXT, start_year INT); INSERT INTO countries (country_name, deep_sea_program, start_year) VALUES ('United States', 'Okeanos Explorer', 2008), ('Japan', 'JAMSTEC', 1997);
List all countries with deep-sea exploration programs and the year they started.
SELECT country_name, deep_sea_program, start_year FROM countries;
gretelai_synthetic_text_to_sql
CREATE TABLE contract_negotiations(id INT, country VARCHAR(50), contractor VARCHAR(50), negotiation_date DATE); INSERT INTO contract_negotiations(id, country, contractor, negotiation_date) VALUES (1, 'Canada', 'ABC Corp', '2021-01-01'); INSERT INTO contract_negotiations(id, country, contractor, negotiation_date) VALUES (2, 'US', 'ABC Corp', '2021-02-01');
List all contract negotiations involving country 'Canada' and defense contractor 'ABC Corp'.
SELECT * FROM contract_negotiations WHERE country = 'Canada' AND contractor = 'ABC Corp';
gretelai_synthetic_text_to_sql
CREATE TABLE grants (id INT, title VARCHAR(50), amount DECIMAL(10,2)); INSERT INTO grants (id, title, amount) VALUES (25, 'Sample Grant', 50000.00), (30, 'Another Grant', 150000.00);
Delete all grants with an amount greater than $100000
DELETE FROM grants WHERE amount > 100000;
gretelai_synthetic_text_to_sql
CREATE TABLE Vehicles (Id INT, Manufacturer VARCHAR(50), SafetyRating FLOAT); INSERT INTO Vehicles (Id, Manufacturer, SafetyRating) VALUES (1, 'Toyota', 4.2), (2, 'Honda', 4.4), (3, 'Nissan', 4.1), (4, 'Subaru', 4.6), (5, 'Mazda', 4.3);
What is the lowest safety rating for vehicles manufactured in Japan?
SELECT MIN(SafetyRating) FROM Vehicles WHERE Manufacturer = 'Japan';
gretelai_synthetic_text_to_sql
CREATE TABLE norway_energy (id INT PRIMARY KEY, year INT, source VARCHAR(30), capacity_mw FLOAT); INSERT INTO norway_energy (id, year, source, capacity_mw) VALUES (1, 2017, 'Wind', 5000), (2, 2017, 'Hydro', 15000), (3, 2018, 'Wind', 6000), (4, 2018, 'Hydro', 16000);
What is the combined capacity (in MW) of wind and hydro power in Norway for the years 2017 and 2018?
SELECT year, source, SUM(capacity_mw) as total_capacity_mw FROM norway_energy GROUP BY year, source HAVING source IN ('Wind', 'Hydro');
gretelai_synthetic_text_to_sql
CREATE TABLE circular_economy_initiatives (state VARCHAR(255), year INT, initiative TEXT); INSERT INTO circular_economy_initiatives (state, year, initiative) VALUES ('California', 2023, 'Compostable plastic bags program');
What are the circular economy initiatives in the state of California in 2023?
SELECT initiative FROM circular_economy_initiatives WHERE state = 'California' AND year = 2023;
gretelai_synthetic_text_to_sql
CREATE TABLE humanitarian_assistance (id INT PRIMARY KEY, disaster VARCHAR(50), year INT, country VARCHAR(50));
Insert a new record into the 'humanitarian_assistance' table with the following values: (5, 'Hurricane Katrina', 2005, 'United States')
INSERT INTO humanitarian_assistance (id, disaster, year, country) VALUES (5, 'Hurricane Katrina', 2005, 'United States');
gretelai_synthetic_text_to_sql
CREATE VIEW Education_Programs AS SELECT 'Wildlife_Ambassadors' AS program, 15000 AS budget UNION SELECT 'Conservation_Champions', 20000;
What is the total budget for all education programs?
SELECT SUM(budget) FROM Education_Programs;
gretelai_synthetic_text_to_sql
CREATE TABLE Donations (id INT, donor_name TEXT, donation_amount DECIMAL(10,2), state TEXT); INSERT INTO Donations (id, donor_name, donation_amount, state) VALUES (1, 'John Doe', 50.00, 'NY'), (2, 'Jane Smith', 100.00, 'CA'), (3, 'Mike Johnson', 25.00, 'NY');
What is the total number of donations per state?
SELECT state, COUNT(*) FROM Donations GROUP BY state;
gretelai_synthetic_text_to_sql
CREATE TABLE cases (case_id INT, case_type TEXT, billable_hours INT); INSERT INTO cases (case_id, case_type, billable_hours) VALUES (1, 'Civil', 10), (2, 'Criminal', 15), (3, 'Civil', 20), (4, 'Criminal', 25);
What is the total billable hours for each case type?
SELECT case_type, SUM(billable_hours) as total_billable_hours FROM cases GROUP BY case_type;
gretelai_synthetic_text_to_sql
CREATE TABLE tilapia_farms (id INT, name TEXT, country TEXT); CREATE TABLE water_flow_rates (id INT, farm_id INT, flow_rate FLOAT); INSERT INTO tilapia_farms (id, name, country) VALUES (1, 'Farm F', 'South America'), (2, 'Farm G', 'South America'), (3, 'Farm H', 'North America'); INSERT INTO water_flow_rates (id, farm_id, flow_rate) VALUES (1, 1, 0.45), (2, 1, 0.50), (3, 2, 0.48), (4, 2, 0.52), (5, 3, 0.55);
What is the maximum water flow rate for tilapia farms in South America?
SELECT MAX(flow_rate) FROM water_flow_rates WFR JOIN tilapia_farms TF ON WFR.farm_id = TF.id WHERE TF.country = 'South America';
gretelai_synthetic_text_to_sql
CREATE TABLE energy_efficiency_africa (country TEXT, score FLOAT); INSERT INTO energy_efficiency_africa (country, score) VALUES ('Egypt', 68.3), ('South Africa', 66.5), ('Morocco', 63.7), ('Tunisia', 60.2), ('Algeria', 58.8), ('Nigeria', 55.1), ('Mauritius', 53.6), ('Ghana', 52.3), ('Kenya', 51.8), ('Libya', 50.5);
What is the energy efficiency score for African countries?
SELECT score FROM energy_efficiency_africa;
gretelai_synthetic_text_to_sql
CREATE TABLE solar_projects (id INT, name VARCHAR(255), location VARCHAR(255), co2_emissions INT);
Find total CO2 emissions for solar projects in the European Union
SELECT SUM(co2_emissions) FROM solar_projects WHERE location LIKE '%European Union%';
gretelai_synthetic_text_to_sql
CREATE TABLE international_visitors_2021 (id INT, country VARCHAR(50), num_visitors INT); INSERT INTO international_visitors_2021 (id, country, num_visitors) VALUES (1, 'France', 3500000), (2, 'Spain', 2500000), (3, 'Germany', 3000000); CREATE TABLE international_visitors_2022 (id INT, country VARCHAR(50), num_visitors INT); INSERT INTO international_visitors_2022 (id, country, num_visitors) VALUES (1, 'France', 4000000), (2, 'Spain', 3500000), (3, 'Germany', 5000000);
Identify the top 3 destinations with the highest increase in international tourists between 2021 and 2022.
SELECT i2022.country, (i2022.num_visitors - i2021.num_visitors) AS increase FROM international_visitors_2022 i2022 JOIN international_visitors_2021 i2021 ON i2022.country = i2021.country ORDER BY increase DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE driver (driver_id INT, driver_name TEXT);CREATE TABLE fare (fare_id INT, driver_id INT, fare_amount DECIMAL, collection_date DATE); INSERT INTO driver (driver_id, driver_name) VALUES (1, 'Driver1'), (2, 'Driver2'), (3, 'Driver3'), (4, 'Driver4'), (5, 'Driver5'); INSERT INTO fare (fare_id, driver_id, fare_amount, collection_date) VALUES (1, 1, 5.00, '2023-01-01'), (2, 1, 5.00, '2023-01-02'), (3, 2, 3.00, '2023-01-01'), (4, 2, 3.00, '2023-01-03'), (5, 3, 2.00, '2023-01-01');
What is the total fare collected for each driver in the last month?
SELECT d.driver_name, SUM(f.fare_amount) as total_fare FROM driver d JOIN fare f ON d.driver_id = f.driver_id WHERE f.collection_date BETWEEN DATEADD(month, -1, GETDATE()) AND GETDATE() GROUP BY d.driver_id;
gretelai_synthetic_text_to_sql
CREATE TABLE music_track (track_id INT, title VARCHAR(100), genre VARCHAR(50)); INSERT INTO music_track (track_id, title, genre) VALUES (1, 'Moonlight Sonata', 'Instrumental');
Update the genre of the music track 'Moonlight Sonata' to 'Classical'.
UPDATE music_track SET genre = 'Classical' WHERE title = 'Moonlight Sonata';
gretelai_synthetic_text_to_sql
CREATE TABLE staff (id INT, name VARCHAR(50), position VARCHAR(50), salary INT); INSERT INTO staff (id, name, position, salary) VALUES (1, 'Jane Smith', 'Editor', 70000), (2, 'Mike Johnson', 'Reporter', 40000);
What is the minimum salary of reporters in the "staff" table?
SELECT MIN(salary) FROM staff WHERE position = 'Reporter';
gretelai_synthetic_text_to_sql
CREATE TABLE Port_Long_Beach_Crane_Stats (crane_name TEXT, handling_date DATE, containers_handled INTEGER); INSERT INTO Port_Long_Beach_Crane_Stats (crane_name, handling_date, containers_handled) VALUES ('CraneA', '2021-01-01', 50), ('CraneB', '2021-01-02', 75), ('CraneC', '2021-01-03', 85), ('CraneD', '2021-01-04', 60);
What is the maximum number of containers handled in a single day by cranes in the Port of Long Beach in January 2021?
SELECT MAX(containers_handled) FROM Port_Long_Beach_Crane_Stats WHERE handling_date >= '2021-01-01' AND handling_date <= '2021-01-31';
gretelai_synthetic_text_to_sql
CREATE TABLE communities (id INT, name VARCHAR(255)); INSERT INTO communities (id, name) VALUES (1, 'Indigenous Artists Network'), (2, 'Women in AI Arts'); CREATE TABLE applications (id INT, name VARCHAR(255), community_id INT, sector VARCHAR(255), published_date DATE); INSERT INTO applications (id, name, community_id, sector, published_date) VALUES (1, 'App1', 1, 'Arts', '2021-01-01'), (2, 'App2', 2, 'Cultural Heritage', '2020-01-01');
Which underrepresented communities have contributed to the development of creative AI applications for the arts sector in the past two years, in the Creative AI database?
SELECT communities.name FROM communities JOIN applications ON communities.id = applications.community_id WHERE sector IN ('Arts', 'Cultural Heritage') AND YEAR(published_date) >= YEAR(CURRENT_DATE()) - 2 AND communities.name IN ('Indigenous Artists Network', 'Women in AI Arts');
gretelai_synthetic_text_to_sql
CREATE TABLE agency (agency_id INT, agency_name VARCHAR(50)); INSERT INTO agency (agency_id, agency_name) VALUES (1, 'Police Department'), (2, 'Courts'), (3, 'Probation Department'); CREATE TABLE cases (case_id INT, agency_id INT, open_date DATE, close_date DATE); INSERT INTO cases (case_id, agency_id, open_date, close_date) VALUES (1, 1, '2020-01-01', '2020-03-15'), (2, 2, '2020-02-10', '2020-06-20'), (3, 3, '2020-04-01', '2020-08-30'), (4, 1, '2020-06-15', '2020-10-25');
What is the count of cases per agency for each month in 2020?
SELECT EXTRACT(MONTH FROM open_date) as month, agency_name, COUNT(*) as cases_count FROM cases JOIN agency ON cases.agency_id = agency.agency_id WHERE open_date BETWEEN '2020-01-01' AND '2020-12-31' GROUP BY month, agency_name;
gretelai_synthetic_text_to_sql
CREATE TABLE crop_area (crop_type VARCHAR(20), area_ha FLOAT); INSERT INTO crop_area (crop_type, area_ha) VALUES ('Corn', 500.00), ('Soybeans', 700.00), ('Wheat', 300.00);
Find the total area under cultivation for each crop type
SELECT crop_type, SUM(area_ha) FROM crop_area GROUP BY crop_type;
gretelai_synthetic_text_to_sql
CREATE TABLE sydney_bus (ride_id INT, fare DECIMAL(5,2), ride_date DATE); CREATE TABLE sydney_train (ride_id INT, fare DECIMAL(5,2), ride_date DATE); CREATE TABLE sydney_ferry (ride_id INT, fare DECIMAL(5,2), ride_date DATE);
What is the total revenue for public transportation in Sydney on weekends?
SELECT SUM(fare) FROM (SELECT fare FROM sydney_bus WHERE DAYOFWEEK(ride_date) IN (1,7) UNION ALL SELECT fare FROM sydney_train WHERE DAYOFWEEK(ride_date) IN (1,7) UNION ALL SELECT fare FROM sydney_ferry WHERE DAYOFWEEK(ride_date) IN (1,7)) AS weekend_fares;
gretelai_synthetic_text_to_sql
CREATE TABLE vessels (id INT, name TEXT, type TEXT);CREATE TABLE cargos (id INT, vessel_id INT, destination TEXT, date DATE, delayed BOOLEAN); INSERT INTO vessels (id, name, type) VALUES (1, 'VesselB', 'Container'); INSERT INTO cargos (id, vessel_id, destination, date, delayed) VALUES (1, 1, 'NewYork', '2020-01-01', true);
How many vessels arrived in the US ports with delayed cargo in 2020?
SELECT COUNT(DISTINCT v.id) FROM vessels v JOIN cargos c ON v.id = c.vessel_id WHERE c.destination LIKE 'US%' AND c.delayed = true AND c.date BETWEEN '2020-01-01' AND '2020-12-31';
gretelai_synthetic_text_to_sql
CREATE TABLE ResponseTimes (ID INT, City VARCHAR(50), Date TIMESTAMP, Time INT); INSERT INTO ResponseTimes (ID, City, Date, Time) VALUES (7, 'CityC', '2015-01-01 00:00:00', 6), (8, 'CityC', '2015-01-01 01:00:00', 7), (9, 'CityC', '2015-01-01 02:00:00', 8), (10, 'CityD', '2015-01-01 00:00:00', 5), (11, 'CityD', '2015-01-01 01:00:00', 4), (12, 'CityD', '2015-01-01 02:00:00', 3);
What is the average response time for each city, considering the previous two records in addition to the current one, ordered by date?
SELECT City, AVG(Time) OVER (PARTITION BY City ORDER BY Date ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS AvgResponseTime FROM ResponseTimes;
gretelai_synthetic_text_to_sql
CREATE TABLE Members (MemberID INT, MemberName VARCHAR(50), LastCheckIn DATETIME);
Delete records of members who have not checked in for the past 60 days from the 'Members' table
DELETE FROM Members WHERE MemberID NOT IN (SELECT MemberID FROM (SELECT MemberID, COUNT(*) as CheckInCount FROM Members WHERE LastCheckIn >= DATE_SUB(CURRENT_DATE(), INTERVAL 60 DAY) GROUP BY MemberID) t1 WHERE CheckInCount > 0);
gretelai_synthetic_text_to_sql
CREATE TABLE excavation_sites (id INT, site_name VARCHAR(255)); CREATE TABLE artifacts (id INT, excavation_site_id INT, artifact_type VARCHAR(255));
What is the distribution of artifact types by excavation site?
SELECT e.site_name, a.artifact_type, COUNT(a.id) AS artifact_count FROM excavation_sites e JOIN artifacts a ON e.id = a.excavation_site_id GROUP BY e.site_name, a.artifact_type;
gretelai_synthetic_text_to_sql
CREATE TABLE Accommodation_Requests (id INT, request_id INT, campus VARCHAR(50), accommodation_type VARCHAR(50), status VARCHAR(50), response_time INT); INSERT INTO Accommodation_Requests (id, request_id, campus, accommodation_type, status, response_time) VALUES (1, 5001, 'East Campus', 'Alternative Text', 'Pending', 2), (2, 5002, 'West Campus', 'Assistive Technology', 'Approved', 3), (3, 5003, 'East Campus', 'Sign Language Interpreter', 'Pending', 5), (4, 5004, 'West Campus', 'Note Taker', 'Pending', 4);
What is the number of pending disability accommodations requests by accommodation type and campus?
SELECT Accommodation_Requests.accommodation_type, Accommodation_Requests.campus, COUNT(*) as pending_requests FROM Accommodation_Requests WHERE Accommodation_Requests.status = 'Pending' GROUP BY Accommodation_Requests.accommodation_type, Accommodation_Requests.campus;
gretelai_synthetic_text_to_sql
CREATE TABLE customers (customer_id INT, customer_name TEXT, region TEXT); INSERT INTO customers (customer_id, customer_name, region) VALUES (1, 'NorthEast Organics', 'Northeast'); CREATE TABLE orders (order_id INT, order_date DATE, customer_id INT, product_id INT); INSERT INTO orders (order_id, order_date, customer_id, product_id) VALUES (1, '2022-01-01', 1, 1); CREATE TABLE products (product_id INT, product_name TEXT, is_ethically_sourced BOOLEAN, quantity INT); INSERT INTO products (product_id, product_name, is_ethically_sourced, quantity) VALUES (1, 'Eco-Friendly Tote Bag', true, 50);
Find the total quantity of ethically sourced products purchased by customers in the Northeast region.
SELECT SUM(quantity) FROM orders JOIN customers ON orders.customer_id = customers.customer_id JOIN products ON orders.product_id = products.product_id WHERE products.is_ethically_sourced = true AND customers.region = 'Northeast';
gretelai_synthetic_text_to_sql
CREATE TABLE producers (id INT PRIMARY KEY, name VARCHAR(255), country VARCHAR(255));CREATE TABLE production (year INT, producer_id INT, element VARCHAR(255), quantity INT, FOREIGN KEY (producer_id) REFERENCES producers(id));
What are the total annual productions for each producer of Dysprosium and Terbium?
SELECT p.name, SUM(CASE WHEN production.element = 'Dysprosium' THEN production.quantity ELSE 0 END) AS Dysprosium, SUM(CASE WHEN production.element = 'Terbium' THEN production.quantity ELSE 0 END) AS Terbium FROM production JOIN producers p ON production.producer_id = p.id GROUP BY p.name;
gretelai_synthetic_text_to_sql
CREATE TABLE wind_farms (id INT, farm VARCHAR(50), country VARCHAR(50), continent VARCHAR(50), capacity FLOAT); INSERT INTO wind_farms (id, farm, country, continent, capacity) VALUES (1, 'Gansu Wind Farm', 'China', 'Asia', 7965.0), (2, 'Muppandal Wind Farm', 'India', 'Asia', 1500.0);
What is the total installed capacity in MW, for wind farms, per country, in Asia?
SELECT country, SUM(capacity) FROM wind_farms WHERE farm LIKE '%Wind%' AND continent = 'Asia' GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE investor_activities (investor VARCHAR(20), sector VARCHAR(30)); INSERT INTO investor_activities (investor, sector) VALUES ('XYZ', 'climate change'), ('ABC', 'climate change'), ('DEF', 'poverty reduction');
List all the unique investors in the climate change sector?
SELECT DISTINCT investor FROM investor_activities WHERE sector = 'climate change';
gretelai_synthetic_text_to_sql
CREATE TABLE ScienceFunding (id INT, department VARCHAR(255), year INT, funding DECIMAL(10,2));
Determine the average annual research funding for each department in the College of Science, from 2015 to 2022, and order the results by the average annual funding in ascending order.
SELECT department, AVG(funding) as avg_annual_funding FROM ScienceFunding WHERE department LIKE 'Science%' AND year BETWEEN 2015 AND 2022 GROUP BY department ORDER BY avg_annual_funding ASC;
gretelai_synthetic_text_to_sql
CREATE VIEW HealthyDiner AS SELECT * FROM MenuItems WHERE is_vegan = TRUE;
Calculate the average calories of vegan menu items in 'HealthyDiner' view.
SELECT AVG(calories) FROM HealthyDiner WHERE item_type = 'Main Course';
gretelai_synthetic_text_to_sql
CREATE TABLE MedicalSupplies (supply_id INT, supply_name VARCHAR(255), quantity INT, delivery_date DATE, service_area VARCHAR(255), agency VARCHAR(255)); INSERT INTO MedicalSupplies (supply_id, supply_name, quantity, delivery_date, service_area, agency) VALUES (7, 'Bandages', 200, '2021-07-15', 'Refugee Support', 'WHO');
What is the total number of medical supplies delivered by 'WHO' to 'Refugee Support' projects in '2021'?
SELECT SUM(MedicalSupplies.quantity) FROM MedicalSupplies WHERE MedicalSupplies.service_area = 'Refugee Support' AND MedicalSupplies.agency = 'WHO' AND YEAR(MedicalSupplies.delivery_date) = 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE safety_records (vessel_id INT, safety_score REAL);
Update the safety record for vessel "Atlantic Queen" with id 106 to 3.8
UPDATE safety_records SET safety_score = 3.8 WHERE vessel_id = 106 AND name = 'Atlantic Queen';
gretelai_synthetic_text_to_sql