context
stringlengths
11
9.12k
question
stringlengths
0
1.06k
SQL
stringlengths
2
4.44k
source
stringclasses
28 values
CREATE TABLE RainfallData (ID INT, FieldID INT, Timestamp DATETIME, Rainfall FLOAT); CREATE VIEW LastYearRainfallData AS SELECT * FROM RainfallData WHERE Timestamp BETWEEN DATEADD(year, -1, GETDATE()) AND GETDATE(); CREATE VIEW Field3RainfallData AS SELECT * FROM RainfallData WHERE FieldID = 3; CREATE VIEW Field4RainfallData AS SELECT * FROM RainfallData WHERE FieldID = 4; CREATE VIEW Field3And4RainfallData AS SELECT * FROM LastYearRainfallData WHERE Field3RainfallData.FieldID = Field4RainfallData.FieldID;
What is the total rainfall for the past year in 'Field3' and 'Field4' combined?
SELECT SUM(Rainfall) OVER (PARTITION BY FieldID) AS TotalRainfall FROM Field3And4RainfallData;
gretelai_synthetic_text_to_sql
CREATE TABLE military_equipment (equipment_id INT, name VARCHAR(255), type VARCHAR(255), maintenance_cost DECIMAL(10,2), state VARCHAR(2));
Find the average maintenance cost for military equipment in the state of California
SELECT AVG(maintenance_cost) FROM military_equipment WHERE state = 'California';
gretelai_synthetic_text_to_sql
CREATE TABLE ArtDonations (artist_name VARCHAR(50), piece_count INT, donation_value DECIMAL(5,2), donation_date DATE); INSERT INTO ArtDonations (artist_name, piece_count, donation_value, donation_date) VALUES ('Monet', 3, 500.00, '2017-03-12'), ('Renoir', 2, 800.00, '2019-05-28'), ('Cezanne', 1, 1000.00, '2020-11-05');
Find the number of art pieces donated by each artist and the average donation value.
SELECT artist_name, AVG(donation_value), SUM(piece_count) FROM ArtDonations GROUP BY artist_name;
gretelai_synthetic_text_to_sql
CREATE TABLE theater_events (id INT, event_id INT, participant_id INT, country VARCHAR(50));
Insert a new record for a theater event in Mexico with 200 participants
INSERT INTO theater_events (id, event_id, participant_id, country) VALUES (7, 107, 204, 'Mexico');
gretelai_synthetic_text_to_sql
CREATE TABLE Accommodations (student_id INT, state VARCHAR(255), visual_impairment BOOLEAN);
How many students require accommodations for visual impairments in each state?
SELECT state, COUNT(*) FROM Accommodations WHERE visual_impairment = TRUE GROUP BY state;
gretelai_synthetic_text_to_sql
CREATE TABLE sectors (id INT, sector_name VARCHAR(255)); INSERT INTO sectors (id, sector_name) VALUES (1, 'Retail'), (2, 'Manufacturing'); CREATE TABLE violations (id INT, sector_id INT, violation_date DATE); INSERT INTO violations (id, sector_id, violation_date) VALUES (1, 1, '2022-02-12'), (2, 1, '2022-01-08');
How many workplace safety violations have been recorded in the retail sector in the last 6 months?
SELECT COUNT(*) as total_violations FROM violations v JOIN sectors s ON v.sector_id = s.id WHERE s.sector_name = 'Retail' AND v.violation_date >= DATE(NOW()) - INTERVAL 6 MONTH;
gretelai_synthetic_text_to_sql
CREATE TABLE rural_infrastructure (id INT, project_name VARCHAR(50), initiation_year INT); INSERT INTO rural_infrastructure (id, project_name, initiation_year) VALUES (1, 'Irrigation System Upgrade', 2008), (2, 'Rural Road Expansion', 2022); CREATE TABLE community_development (id INT, initiative_name VARCHAR(50), initiation_year INT); INSERT INTO community_development (id, initiative_name, initiation_year) VALUES (1, 'Youth Empowerment Program', 2008), (2, 'Renewable Energy Workshops', 2022);
Which rural infrastructure projects in the 'rural_infrastructure' table have the same initiation year as any community development initiatives in the 'community_development' table but different project names?
SELECT project_name FROM rural_infrastructure WHERE initiation_year IN (SELECT initiation_year FROM community_development) AND project_name NOT IN (SELECT initiative_name FROM community_development);
gretelai_synthetic_text_to_sql
CREATE TABLE Donors (DonorID int, DonorName varchar(50), DonationDate date, DonationAmount decimal(10,2), Program varchar(50)); INSERT INTO Donors (DonorID, DonorName, DonationDate, DonationAmount, Program) VALUES (1, 'Olga Gonzalez', '2019-10-02', 50.00, 'ProgramE'), (2, 'Mohammed Al-Saadi', '2019-11-15', 100.00, 'ProgramF'), (3, 'Svetlana Petrova', '2019-12-01', 75.00, 'ProgramE');
What was the total donation amount and average donation amount per donor for each program in Q4 2019, excluding donations below $10?
SELECT Program, SUM(DonationAmount) as TotalDonationAmount, AVG(DonationAmount) as AverageDonationAmountPerDonor FROM Donors WHERE DonationDate BETWEEN '2019-10-01' AND '2019-12-31' AND DonationAmount >= 10 GROUP BY Program;
gretelai_synthetic_text_to_sql
CREATE TABLE state (name VARCHAR(255), budget INT); CREATE TABLE department (name VARCHAR(255), state VARCHAR(255), budget INT); INSERT INTO state (name, budget) VALUES ('California', 200000000), ('Texas', 150000000), ('New York', 180000000), ('Florida', 160000000), ('Illinois', 140000000); INSERT INTO department (name, state, budget) VALUES ('Education', 'California', 30000000), ('Healthcare', 'California', 50000000), ('Transportation', 'California', 25000000), ('Education', 'Texas', 25000000), ('Healthcare', 'Texas', 40000000);
What is the total budget allocated to each department in the state government?
SELECT state, SUM(budget) FROM department GROUP BY state;
gretelai_synthetic_text_to_sql
CREATE TABLE users (id INT, name VARCHAR(50), age INT, city VARCHAR(50)); INSERT INTO users (id, name, age, city) VALUES (1, 'David', 20, 'New York'); INSERT INTO users (id, name, age, city) VALUES (2, 'Eva', 25, 'Los Angeles'); INSERT INTO users (id, name, age, city) VALUES (3, 'Fiona', 30, 'Chicago'); INSERT INTO users (id, name, age, city) VALUES (4, 'George', 35, 'New York');
What is the total number of users by age range?
SELECT CASE WHEN age < 30 THEN 'Under 30' ELSE '30 and over' END as age_range, COUNT(*) as total_users FROM users GROUP BY age_range;
gretelai_synthetic_text_to_sql
CREATE TABLE vessels (id INT, name VARCHAR(50), company VARCHAR(50), capacity INT); INSERT INTO vessels (id, name, company, capacity) VALUES (1, 'MV Horizon', 'Blue Whale Shipping', 12000), (2, 'MV Oceanus', 'Blue Whale Shipping', 15000), (3, 'MV Andromeda', 'Starship Shipping', 10000), (4, 'MV Antares', 'Starship Shipping', 9000);
Show the names and capacities of all vessels that have a capacity greater than the average capacity of vessels in the database.
SELECT name, capacity FROM vessels WHERE capacity > (SELECT AVG(capacity) FROM vessels);
gretelai_synthetic_text_to_sql
CREATE TABLE user (id INT, name VARCHAR(50), age INT, gender VARCHAR(10), region VARCHAR(20), created_at TIMESTAMP); INSERT INTO user (id, name, age, gender, region, created_at) VALUES (1, 'Anika Chakrabarti', 30, 'Female', 'asia', '2021-01-01 10:00:00'), (2, 'Hiroshi Sato', 35, 'Male', 'asia', '2021-01-02 11:00:00');
How many users are there in total from 'asia' region?
SELECT COUNT(*) FROM user WHERE region = 'asia';
gretelai_synthetic_text_to_sql
CREATE TABLE SatelliteDeployments (id INT, country VARCHAR(50), year INT, number_of_satellites INT);
List the top 3 countries with the highest number of satellite deployments?
SELECT country, SUM(number_of_satellites) FROM SatelliteDeployments GROUP BY country ORDER BY SUM(number_of_satellites) DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE Diversity (Company VARCHAR(50), Year INT, DiverseEmployees INT); INSERT INTO Diversity (Company, Year, DiverseEmployees) VALUES ('Acme Inc.', 2018, 50), ('Acme Inc.', 2019, 75), ('Acme Inc.', 2020, 85), ('Beta Corp.', 2018, 30), ('Beta Corp.', 2019, 35), ('Beta Corp.', 2020, 40);
Update diversity metrics for 2019 in the database to reflect the new values.
UPDATE Diversity SET DiverseEmployees = 80 WHERE Company = 'Acme Inc.' AND Year = 2019;
gretelai_synthetic_text_to_sql
CREATE TABLE solar_plants (id INT, state VARCHAR(255), name VARCHAR(255)); INSERT INTO solar_plants (id, state, name) VALUES (1, 'California', 'Solar Plant A'), (2, 'California', 'Solar Plant B'), (3, 'Nevada', 'Solar Plant C');
How many solar power plants are in California?
SELECT COUNT(*) FROM solar_plants WHERE state = 'California';
gretelai_synthetic_text_to_sql
CREATE TABLE Clothing (id INT, recycled BOOLEAN, price DECIMAL(5,2)); INSERT INTO Clothing VALUES (1, true, 125.00), (2, false, 75.00), (3, false, 150.00), (4, true, 85.00), (5, false, 95.00);
List all clothing items made from recycled materials that are priced over $100.
SELECT id, price FROM Clothing WHERE recycled = true AND price > 100;
gretelai_synthetic_text_to_sql
CREATE TABLE rd_expenditure (expenditure_id INT, organization_id INT, quarter INT, year INT, amount DECIMAL(10, 2));
What was the R&D expenditure for each organization in 2022?
SELECT organization_id, SUM(amount) as total_expenditure FROM rd_expenditure WHERE year = 2022 GROUP BY organization_id;
gretelai_synthetic_text_to_sql
CREATE TABLE donations (id INT, initiative VARCHAR(255), donor_gender VARCHAR(255), donation_amount DECIMAL(10, 2), donation_date DATE); INSERT INTO donations (id, initiative, donor_gender, donation_amount, donation_date) VALUES (1, 'Women Empowerment', 'Female', 500, '2022-01-01'), (2, 'Healthcare Access', 'Male', 700, '2022-02-01'), (3, 'Environmental Conservation', 'Female', 600, '2022-03-01'), (4, 'Education Equality', 'Non-binary', 800, '2022-03-01'), (5, 'Food Security', 'Male', 700, '2022-04-01'), (6, 'Women Empowerment', 'Female', 600, '2022-04-01');
What is the percentage of donors by gender for each initiative this year?
SELECT initiative, donor_gender, COUNT(*) * 100.0 / (SELECT COUNT(*) FROM donations WHERE donation_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR)) AS percentage FROM donations WHERE donation_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY initiative, donor_gender;
gretelai_synthetic_text_to_sql
CREATE TABLE regulatory_frameworks (id INT, name VARCHAR, implementation_date DATE); INSERT INTO regulatory_frameworks (id, name, implementation_date) VALUES (1, 'RF1', '2021-01-01'), (2, 'RF2', '2020-02-02'), (3, 'RF3', '2019-03-03'), (4, 'RF4', '2018-04-04'), (5, 'RF5', '2017-05-05'), (6, 'RF6', '2016-06-06'), (7, 'RF7', '2015-07-07');
Delete all regulatory frameworks that were implemented before 2021.
DELETE FROM regulatory_frameworks WHERE implementation_date < '2021-01-01';
gretelai_synthetic_text_to_sql
CREATE TABLE ocean_temperature (id INT PRIMARY KEY, location VARCHAR(255), temperature FLOAT, month DATE); INSERT INTO ocean_temperature (id, location, temperature, month) VALUES (1, 'Atlantic_Ocean', 22.5, '2017-01-01'), (2, 'Atlantic_Ocean', 23.0, '2018-01-01'), (3, 'Atlantic_Ocean', 22.0, '2019-01-01'), (4, 'Atlantic_Ocean', 21.5, '2020-01-01'), (5, 'Atlantic_Ocean', 23.5, '2021-01-01');
Calculate average ocean temperatures for the last 5 years in the Atlantic.
SELECT AVG(temperature) FROM ocean_temperature WHERE location = 'Atlantic_Ocean' AND month BETWEEN '2017-01-01' AND '2021-12-31';
gretelai_synthetic_text_to_sql
CREATE TABLE products (product_id INT, product_name VARCHAR(255), is_vegan BOOLEAN);
How many vegan products does the company offer?
SELECT COUNT(*) FROM products WHERE is_vegan = TRUE;
gretelai_synthetic_text_to_sql
CREATE TABLE Artists (ArtistID INT, ArtistName VARCHAR(50), BirthYear INT);CREATE TABLE Paintings (PaintingID INT, PaintingName VARCHAR(50), ArtistID INT, CreationYear INT, InsuredValue INT); INSERT INTO Artists VALUES (1, 'Vincent van Gogh', 1853); INSERT INTO Paintings VALUES (1, 'Starry Night', 1, 1889, 100000000);
What is the average insured value of paintings produced by artists born before 1950?
SELECT AVG(InsuredValue) FROM Artists a JOIN Paintings p ON a.ArtistID = p.ArtistID WHERE a.BirthYear < 1950;
gretelai_synthetic_text_to_sql
CREATE TABLE Dams (id INT, name TEXT, location TEXT, state TEXT, built DATE); INSERT INTO Dams (id, name, location, state, built) VALUES (1, 'Dam A', 'Location A', 'California', '1970-01-01'), (2, 'Dam B', 'Location B', 'Oregon', '2000-01-01');
Delete all dams in California that were built before 1980.
DELETE FROM Dams WHERE state = 'California' AND built < '1980-01-01';
gretelai_synthetic_text_to_sql
CREATE TABLE schools (school_id INT, school_name VARCHAR(255), location VARCHAR(255)); INSERT INTO schools (school_id, school_name, location) VALUES (1, 'School A', 'urban'), (2, 'School B', 'rural'), (3, 'School C', 'urban'); CREATE TABLE students (student_id INT, school_id INT, mental_health_score INT); INSERT INTO students (student_id, school_id, mental_health_score) VALUES (1, 1, 80), (2, 1, 85), (3, 2, 70), (4, 2, 75), (5, 3, 90), (6, 3, 95);
What is the average mental health score of students in urban schools?
SELECT AVG(st.mental_health_score) as avg_mental_health_score FROM students st JOIN schools s ON st.school_id = s.school_id WHERE s.location = 'urban';
gretelai_synthetic_text_to_sql
CREATE TABLE veteran_employment (veteran_id INT, veteran_state VARCHAR(2), employment_status VARCHAR(255), employment_date DATE);
Calculate veteran employment rates by state, for the past 6 months
SELECT veteran_state, AVG(CASE WHEN employment_status = 'Employed' THEN 100 ELSE 0 END) as employment_rate FROM veteran_employment WHERE employment_date >= DATEADD(month, -6, CURRENT_DATE) GROUP BY veteran_state;
gretelai_synthetic_text_to_sql
CREATE TABLE clinics (id INT, name VARCHAR(255)); CREATE TABLE clinic_treatments (clinic_id INT, condition VARCHAR(255)); INSERT INTO clinics (id, name) VALUES (1, 'New Hope Clinic'); INSERT INTO clinic_treatments (clinic_id, condition) VALUES (1, 'Anxiety Disorder'); INSERT INTO clinic_treatments (clinic_id, condition) VALUES (1, 'Depression');
What are the mental health conditions treated at 'New Hope Clinic'?
SELECT condition FROM clinic_treatments WHERE clinic_id = (SELECT id FROM clinics WHERE name = 'New Hope Clinic');
gretelai_synthetic_text_to_sql
CREATE TABLE organization (org_id INT, org_name VARCHAR(255)); CREATE TABLE volunteer (vol_id INT, org_id INT, vol_join_date DATE); CREATE TABLE donation (don_id INT, donor_id INT, org_id INT, donation_date DATE);
Determine the number of volunteers who have joined each organization in the current year, for organizations that have received at least one donation in the current year.
SELECT org_id, COUNT(*) AS num_new_volunteers FROM volunteer WHERE EXTRACT(YEAR FROM vol_join_date) = EXTRACT(YEAR FROM CURRENT_DATE) AND org_id IN (SELECT DISTINCT org_id FROM donation WHERE EXTRACT(YEAR FROM donation_date) = EXTRACT(YEAR FROM CURRENT_DATE)) GROUP BY org_id;
gretelai_synthetic_text_to_sql
CREATE TABLE teachers (teacher_id INT, professional_development_programs INT, last_update DATE); INSERT INTO teachers (teacher_id, professional_development_programs, last_update) VALUES (1, 3, '2022-01-01'), (2, 2, '2022-02-01');
How many professional development programs were offered per teacher last year?
SELECT t.teacher_id, AVG(t.professional_development_programs) as avg_programs_per_teacher FROM teachers t WHERE t.last_update >= '2021-01-01' AND t.last_update < '2022-01-01' GROUP BY t.teacher_id;
gretelai_synthetic_text_to_sql
CREATE TABLE indian_ocean_marine_life (species VARCHAR(255), count INT); INSERT INTO indian_ocean_marine_life (species, count) VALUES ('Turtle', 150), ('Shark', 200), ('Whale', 100);
List all the distinct marine species and their observation counts in the Indian Ocean, excluding sharks.
SELECT species, count FROM indian_ocean_marine_life WHERE species != 'Shark';
gretelai_synthetic_text_to_sql
CREATE TABLE Articles (id INT, title VARCHAR(255), word_count INT, publish_date DATE); INSERT INTO Articles (id, title, word_count, publish_date) VALUES (1, 'Article 1', 500, '2023-01-01'), (2, 'Article 2', 600, '2023-02-01'), (3, 'Article 3', 700, '2023-03-01'), (4, 'Article 4', 800, '2023-01-05'), (5, 'Article 5', 900, '2023-01-10'), (6, 'Article 6', 1000, '2023-02-15'), (7, 'Article 7', 1100, '2023-03-20'), (8, 'Article 8', 1200, '2023-01-25'), (9, 'Article 9', 1300, '2023-02-30'), (10, 'Article 10', 1400, '2023-01-01');
What is the average word count of articles published in January?
SELECT AVG(word_count) FROM Articles WHERE MONTH(publish_date) = 1;
gretelai_synthetic_text_to_sql
CREATE TABLE crop_area (id INT, crop_type VARCHAR(20), area FLOAT); INSERT INTO crop_area (id, crop_type, area) VALUES (1, 'Cotton', 345.67), (2, 'Rice', 456.78), (3, 'Cotton', 567.89), (4, 'Sorghum', 678.90);
What is the total area under cultivation for each crop type?
SELECT crop_type, SUM(area) AS total_area FROM crop_area GROUP BY crop_type;
gretelai_synthetic_text_to_sql
CREATE TABLE security_incidents (id INT, severity VARCHAR(255), incident_date DATE, incident_count INT);
What is the total number of security incidents recorded for each month in the 'security_incidents' table for the past year?
SELECT EXTRACT(YEAR_MONTH FROM incident_date) as year_month, SUM(incident_count) as total_incidents FROM security_incidents WHERE incident_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) GROUP BY EXTRACT(YEAR_MONTH FROM incident_date);
gretelai_synthetic_text_to_sql
CREATE TABLE FinancialWellbeingPrograms (id INT, program_name VARCHAR(50), country VARCHAR(50), income FLOAT, expenses FLOAT); INSERT INTO FinancialWellbeingPrograms (id, program_name, country, income, expenses) VALUES (1, 'Financial Capability Program', 'South Africa', 55000, 32000), (2, 'Debt Management Program', 'South Africa', 60000, 36000), (3, 'Retirement Planning Program', 'South Africa', 70000, 42000), (4, 'Budgeting Program', 'South Africa', 45000, 27000);
What is the average income and expenses for financial wellbeing programs in South Africa?
SELECT country, AVG(income) as avg_income, AVG(expenses) as avg_expenses FROM FinancialWellbeingPrograms WHERE country = 'South Africa';
gretelai_synthetic_text_to_sql
CREATE SCHEMA if not exists bioprocess;CREATE TABLE if not exists bioprocess.engineering (id INT PRIMARY KEY, name VARCHAR(100), location VARCHAR(50), funding FLOAT);INSERT INTO bioprocess.engineering (id, name, location, funding) VALUES (1, 'CompanyA', 'China', 8000000.0), (2, 'CompanyB', 'Canada', 4000000.0), (3, 'CompanyC', 'Germany', 5000000.0), (4, 'CompanyD', 'USA', 3000000.0), (5, 'CompanyE', 'China', 2000000.0), (6, 'CompanyF', 'Canada', 1000000.0);
How many bioprocess engineering companies in China have received funding?
SELECT COUNT(*) FROM bioprocess.engineering WHERE location = 'China' AND funding IS NOT NULL;
gretelai_synthetic_text_to_sql
CREATE TABLE Households (id INT, city VARCHAR(20), daily_consumption FLOAT); INSERT INTO Households (id, city, daily_consumption) VALUES (1, 'San Francisco', 340.5), (2, 'San Francisco', 367.8), (3, 'Los Angeles', 425.6);
What is the average daily water consumption per household in the city of San Francisco?
SELECT AVG(daily_consumption) FROM Households WHERE city = 'San Francisco';
gretelai_synthetic_text_to_sql
CREATE TABLE social_media(user_id INT, user_name VARCHAR(50), region VARCHAR(50), post_date DATE, hashtags BOOLEAN, likes INT);
Show the number of posts with and without hashtags in the 'social_media' table, for users in 'South America'.
SELECT SUM(hashtags) as posts_with_hashtags, SUM(NOT hashtags) as posts_without_hashtags FROM social_media WHERE region = 'South America';
gretelai_synthetic_text_to_sql
CREATE TABLE contractor_sales (contractor VARCHAR(20), equipment_type VARCHAR(20), sale_year INT, quantity INT); INSERT INTO contractor_sales (contractor, equipment_type, sale_year, quantity) VALUES ('Boeing', 'Aircraft', 2021, 1500), ('BAE Systems', 'Missiles', 2021, 1000);
What are the names of the defense contractors and their associated military equipment sales in descending order, for sales made in 2021?
SELECT contractor, SUM(quantity) as total_sales FROM contractor_sales WHERE sale_year = 2021 GROUP BY contractor ORDER BY total_sales DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE marine_species_observations (species_name VARCHAR(255), location VARCHAR(255), num_observations INT); INSERT INTO marine_species_observations (species_name, location, num_observations) VALUES ('Whale Shark', 'Indian Ocean', 100), ('Manta Ray', 'Indian Ocean', 200), ('Dolphins', 'Indian Ocean', 500);
How many species of marine life have been observed in the Indian Ocean?
SELECT COUNT(DISTINCT species_name) FROM marine_species_observations WHERE location = 'Indian Ocean';
gretelai_synthetic_text_to_sql
CREATE TABLE CarbonPrice (year INT, price FLOAT, market VARCHAR(50));
What is the maximum carbon price in the 'RGGI' market in USD/tonne, for the years 2017 to 2021?
SELECT MAX(price) FROM CarbonPrice WHERE market = 'RGGI' AND year BETWEEN 2017 AND 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE games (team TEXT, played BOOLEAN); INSERT INTO games (team, played) VALUES ('Team A', TRUE), ('Team A', TRUE), ('Team A', TRUE), ('Team B', TRUE), ('Team B', TRUE), ('Team C', TRUE), ('Team C', TRUE), ('Team C', TRUE), ('Team C', TRUE), ('Team C', TRUE), ('Team D', TRUE), ('Team D', TRUE), ('Team D', TRUE);
Find the maximum number of games played by a team in the 'games' table.
SELECT team, COUNT(*) as games_played FROM games WHERE played = TRUE GROUP BY team ORDER BY games_played DESC LIMIT 1;
gretelai_synthetic_text_to_sql
CREATE TABLE eu_countries (id INT PRIMARY KEY, country VARCHAR(20), num_initiatives INT); INSERT INTO eu_countries (id, country, num_initiatives) VALUES (1, 'France', 35); INSERT INTO eu_countries (id, country, num_initiatives) VALUES (2, 'Germany', 45);
Which country in the European Union had the most open data initiatives in 2019?
SELECT country, MAX(num_initiatives) FROM eu_countries WHERE country IN ('France', 'Germany', 'Italy', 'Spain', 'Poland') GROUP BY country;
gretelai_synthetic_text_to_sql
CREATE TABLE mining_sites(id INT, name VARCHAR, location VARCHAR); CREATE TABLE employees(id INT, site_id INT, gender VARCHAR, role VARCHAR); INSERT INTO mining_sites(id, name, location) VALUES (1, 'Delta Mining', 'Northern MN'), (2, 'Echo Mining', 'Southern MN'); INSERT INTO employees(id, site_id, gender, role) VALUES (1, 1, 'Male', 'Engineer'), (2, 1, 'Female', 'Operator'), (3, 2, 'Male', 'Manager'), (4, 2, 'Female', 'Engineer'), (5, 3, 'Male', 'Operator'), (6, 3, 'Female', 'Engineer');
What is the percentage of female engineers at each mining site in Northern MN?
SELECT mining_sites.name, (COUNT(*) FILTER (WHERE gender = 'Female' AND role = 'Engineer')) * 100.0 / COUNT(*) FROM mining_sites INNER JOIN employees ON mining_sites.id = employees.site_id WHERE location = 'Northern MN' GROUP BY mining_sites.name;
gretelai_synthetic_text_to_sql
CREATE TABLE ProductionMaterials (production_id INT, material_type VARCHAR(255), weight INT); INSERT INTO ProductionMaterials (production_id, material_type, weight) VALUES (1, 'Organic Cotton', 1000), (2, 'Recycled Polyester', 2000), (3, 'Reclaimed Wood', 3000), (4, 'Conflict-Free Minerals', 4000), (5, 'Fair Trade Textiles', 5000), (6, 'Natural Dyes', 6000);
What is the total weight of each sustainable material used in production?
SELECT material_type, SUM(weight) as total_weight FROM ProductionMaterials GROUP BY material_type;
gretelai_synthetic_text_to_sql
CREATE TABLE Arrivals (ArrivalID INT, VisitorID INT, ArrivalDate DATE); INSERT INTO Arrivals (ArrivalID, VisitorID, ArrivalDate) VALUES (1, 1, '2022-10-01'), (2, 2, '2022-11-01'), (3, 3, '2022-12-01');
Which countries had the highest international visitor count in the last quarter of 2022?
SELECT EXTRACT(YEAR FROM ArrivalDate) AS Year, EXTRACT(MONTH FROM ArrivalDate) AS Month, COUNT(VisitorID) AS VisitorCount, Country FROM Arrivals JOIN Visitors ON Arrivals.VisitorID = Visitors.VisitorID WHERE ArrivalDate BETWEEN '2022-10-01' AND '2022-12-31' GROUP BY Year, Month, Country ORDER BY VisitorCount DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE vessels (id INT, name VARCHAR(20)); INSERT INTO vessels (id, name) VALUES (1, 'Aurelia'), (2, 'Belfast'), (3, 'Caledonia'); CREATE TABLE cargos (vessel_id INT, weight INT); INSERT INTO cargos (vessel_id, weight) VALUES (1, 5000), (1, 7000), (2, 6000), (3, 8000), (3, 9000);
What was the total cargo weight for vessel 'Aurelia'?
SELECT SUM(weight) FROM cargos WHERE vessel_id = (SELECT id FROM vessels WHERE name = 'Aurelia');
gretelai_synthetic_text_to_sql
CREATE TABLE policy_holder (policy_holder_id INT, first_name VARCHAR(50), last_name VARCHAR(50), email VARCHAR(50), phone VARCHAR(15), address VARCHAR(100), city VARCHAR(50), state VARCHAR(2), zip VARCHAR(10));
Insert a new record in the policy_holder table with policy_holder_id 3, first_name 'Clara', last_name 'Martinez', email 'clara.martinez@example.com', phone '555-123-4567', address '123 Main St', city 'San Juan', state 'PR', zip '00926'
INSERT INTO policy_holder (policy_holder_id, first_name, last_name, email, phone, address, city, state, zip) VALUES (3, 'Clara', 'Martinez', 'clara.martinez@example.com', '555-123-4567', '123 Main St', 'San Juan', 'PR', '00926');
gretelai_synthetic_text_to_sql
CREATE TABLE ArtWork (id INT, title VARCHAR(255), type VARCHAR(255), price DECIMAL(10,2), sale_year INT, location VARCHAR(255)); INSERT INTO ArtWork (id, title, type, price, sale_year, location) VALUES (1, 'Sculpture1', 'Sculpture', 10000, 1989, 'UK');
What is the total value of sculptures sold in the UK before 1990?
SELECT SUM(price) FROM ArtWork WHERE type = 'Sculpture' AND location LIKE '%UK%' AND sale_year < 1990;
gretelai_synthetic_text_to_sql
CREATE TABLE satellites (satellite_id INT, launch_date DATE, launch_status VARCHAR(10));
What is the earliest launch date for a successful satellite launch?
SELECT MIN(launch_date) FROM satellites WHERE launch_status = 'successful';
gretelai_synthetic_text_to_sql
CREATE TABLE CustomerSizes (CustomerID INT, TopSize VARCHAR(10), BottomSize VARCHAR(10)); INSERT INTO CustomerSizes (CustomerID, TopSize, BottomSize) VALUES (1, 'M', 'L'), (2, 'S', 'M'), (3, 'L', 'XL'), (4, 'XL', 'L');
What is the average top size for customers who have a specific bottom size?
SELECT CS.BottomSize, AVG(CS.TopSize) AS AvgTopSize FROM CustomerSizes CS WHERE CS.BottomSize = 'L' GROUP BY CS.BottomSize;
gretelai_synthetic_text_to_sql
CREATE TABLE children_movies (title VARCHAR(255), release_year INT, rating DECIMAL(3,2)); INSERT INTO children_movies (title, release_year, rating) VALUES ('Movie4', 2019, 4.5), ('Movie5', 2019, 4.8), ('Movie6', 2019, 5.0);
What is the average content rating for children's movies released in 2019?
SELECT AVG(rating) avg_rating FROM children_movies WHERE release_year = 2019;
gretelai_synthetic_text_to_sql
CREATE TABLE concentrate_sales (dispensary_id INT, sale_date DATE, weight DECIMAL(10, 2), price DECIMAL(10, 2)); INSERT INTO concentrate_sales (dispensary_id, sale_date, weight, price) VALUES (1, '2022-07-01', 100, 20), (1, '2022-07-15', 150, 22), (1, '2022-08-05', 200, 18), (2, '2022-07-03', 75, 25), (2, '2022-07-30', 225, 28), (2, '2022-08-20', 175, 24);
What was the total revenue from cannabis concentrate sales at each dispensary in Q3 2022?
SELECT d.name, SUM(cs.price * cs.weight) as total_revenue FROM concentrate_sales cs JOIN dispensaries d ON cs.dispensary_id = d.id WHERE cs.sale_date BETWEEN '2022-07-01' AND '2022-09-30' GROUP BY d.name;
gretelai_synthetic_text_to_sql
CREATE TABLE volunteers( id INT PRIMARY KEY NOT NULL, name VARCHAR(50), age INT, city VARCHAR(30), country VARCHAR(30) ); INSERT INTO volunteers (id, name, age, city, country) VALUES (1, 'John Doe', 25, 'New York', 'USA'); INSERT INTO volunteers (id, name, age, city, country) VALUES (2, 'Jane Doe', 30, 'Los Angeles', 'USA');
How many volunteers are there in total?
SELECT COUNT(*) FROM volunteers;
gretelai_synthetic_text_to_sql
CREATE TABLE Shipment (id INT PRIMARY KEY, warehouse_id INT, customer_id INT, shipped_date DATE); INSERT INTO Shipment (id, warehouse_id, customer_id, shipped_date) VALUES (1, 1, 1, '2022-01-01'), (2, 2, 2, '2022-01-05'), (3, 3, 3, '2022-01-07'), (4, 1, 2, '2022-02-10'), (5, 2, 1, '2022-03-14'); CREATE TABLE Customer (id INT PRIMARY KEY, name VARCHAR(100), address VARCHAR(200), phone VARCHAR(15)); INSERT INTO Customer (id, name, address, phone) VALUES (1, 'John Doe', '123 Main St, Miami, FL', '305-555-1212'), (2, 'Jane Smith', '456 Oak St, San Francisco, CA', '415-555-3434'), (3, 'Mike Johnson', '789 Elm St, Dallas, TX', '214-555-5656');
Retrieve the names of customers who have had shipments from both 'New York' and 'Los Angeles'.
SELECT c.name FROM Customer c JOIN Shipment s1 ON c.id = s1.customer_id JOIN Shipment s2 ON c.id = s2.customer_id WHERE s1.warehouse_id = (SELECT id FROM Warehouse WHERE city = 'New York') AND s2.warehouse_id = (SELECT id FROM Warehouse WHERE city = 'Los Angeles') GROUP BY c.id HAVING COUNT(DISTINCT s1.warehouse_id) = 2;
gretelai_synthetic_text_to_sql
CREATE TABLE news_articles (id INT, title VARCHAR(255), author_id INT, publication_date DATE); INSERT INTO news_articles (id, title, author_id, publication_date) VALUES (1, 'The Big Story', 1, '2021-10-01'); INSERT INTO news_articles (id, title, author_id, publication_date) VALUES (3, 'Breaking News', 4, '2022-01-10');
List all news articles published between January 1st and 15th, 2022.
SELECT * FROM news_articles WHERE publication_date BETWEEN '2022-01-01' AND '2022-01-15';
gretelai_synthetic_text_to_sql
CREATE TABLE carbon_pricing (country VARCHAR(50), scheme VARCHAR(50), price FLOAT); INSERT INTO carbon_pricing (country, scheme, price) VALUES ('Germany', 'Carbon Tax', 25.0), ('France', 'Cap-and-Trade', 18.5), ('Spain', 'Carbon Tax', 22.0), ('Italy', 'Carbon Tax', 28.0), ('Poland', 'Cap-and-Trade', 15.5);
List all the carbon pricing schemes in the European Union
SELECT country, scheme FROM carbon_pricing WHERE country = 'European Union';
gretelai_synthetic_text_to_sql
CREATE TABLE AircraftManufacturing (id INT, manufacturer VARCHAR(255), country VARCHAR(255), cost FLOAT); INSERT INTO AircraftManufacturing VALUES (1, 'Boeing', 'USA', 120000000), (2, 'Lockheed Martin', 'USA', 200000000), (3, 'Northrop Grumman', 'USA', 150000000);
What is the total manufacturing cost of aircrafts produced in the USA?
SELECT SUM(cost) FROM AircraftManufacturing WHERE country = 'USA';
gretelai_synthetic_text_to_sql
CREATE TABLE talent_acquisition (id INT PRIMARY KEY, job_title VARCHAR(50), source VARCHAR(50), applicants INT, hires INT, cost DECIMAL(5,2));
Insert a new record into the "talent_acquisition" table
INSERT INTO talent_acquisition (id, job_title, source, applicants, hires, cost) VALUES (4001, 'Software Engineer', 'LinkedIn', 250, 50, 15000.00);
gretelai_synthetic_text_to_sql
CREATE TABLE PassengerVessels (VesselID INT, VesselName VARCHAR(100), SafetyInspections INT, LastInspection DATE, Region VARCHAR(50)); INSERT INTO PassengerVessels (VesselID, VesselName, SafetyInspections, LastInspection, Region) VALUES (1, 'Passenger Vessel 1', 2, '2022-03-12', 'Caribbean'), (2, 'Passenger Vessel 2', 1, '2022-02-25', 'Caribbean'), (3, 'Passenger Vessel 3', 0, '2022-01-10', 'Caribbean');
Find the number of passenger vessels that have had safety inspections in the Caribbean in the last 6 months
SELECT COUNT(*) FROM PassengerVessels WHERE SafetyInspections > 0 AND Region = 'Caribbean' AND LastInspection >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH);
gretelai_synthetic_text_to_sql
CREATE TABLE menus (id INT, name VARCHAR(255), category VARCHAR(255), price DECIMAL(10,2), PRIMARY KEY(id)); INSERT INTO menus VALUES (1, 'Pizza Margherita', 'Pizza', 9.99), (2, 'Chicken Alfredo', 'Pasta', 12.49), (3, 'California Roll', 'Sushi', 8.99), (4, 'Seasonal Fruit Bowl', 'Starters', 7.99), (5, 'Lobster Risotto', 'Pasta', 24.99); CREATE TABLE categories (id INT, category VARCHAR(255), PRIMARY KEY(id)); INSERT INTO categories VALUES (1, 'Pizza'), (2, 'Pasta'), (3, 'Sushi'), (4, 'Starters');
Which menu items have a higher price than their average category price?
SELECT menus.name FROM menus JOIN categories ON menus.category = categories.category GROUP BY menus.category HAVING price > AVG(menus.price) WHERE menus.category = categories.category;
gretelai_synthetic_text_to_sql
CREATE TABLE employees (id INT, name VARCHAR(50), department VARCHAR(50), salary DECIMAL(10, 2)); INSERT INTO employees (id, name, department, salary) VALUES (1, 'John Doe', 'IT', 80000.00), (2, 'Jane Smith', 'Marketing', 70000.00), (3, 'Mike Johnson', 'IT', 85000.00), (4, 'Sara Connor', 'Sales', 90000.00);
What is the average salary for employees in each department, excluding the Sales department?
SELECT department, AVG(salary) AS avg_salary FROM employees WHERE department <> 'Sales' GROUP BY department;
gretelai_synthetic_text_to_sql
CREATE TABLE Carriers (CarrierID int, CarrierName varchar(255));CREATE TABLE Shipments (ShipmentID int, CarrierID int, OnTime bit, ShippedDate datetime); INSERT INTO Carriers (CarrierID, CarrierName) VALUES (1, 'Carrier A'); INSERT INTO Shipments (ShipmentID, CarrierID, OnTime, ShippedDate) VALUES (1, 1, 1, '2022-01-01');
Which carriers have the highest and lowest on-time delivery percentages for the past quarter?
SELECT CarrierName, (SUM(CASE WHEN OnTime = 1 THEN 1 ELSE 0 END) / COUNT(*)) * 100.0 as OnTimePercentage FROM Carriers c INNER JOIN Shipments s ON c.CarrierID = s.CarrierID WHERE s.ShippedDate >= DATEADD(quarter, -1, GETDATE()) GROUP BY CarrierName ORDER BY OnTimePercentage DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE EducationPrograms(ProgramDate DATE, Region VARCHAR(20), ProgramType VARCHAR(20), Number INT);INSERT INTO EducationPrograms(ProgramDate, Region, ProgramType, Number) VALUES ('2021-07-01', 'Africa', 'Workshop', 15), ('2021-07-01', 'Asia', 'Seminar', 20), ('2021-07-02', 'Africa', 'Workshop', 12), ('2021-07-02', 'Asia', 'Seminar', 18), ('2021-08-01', 'Africa', 'Workshop', 18), ('2021-08-01', 'Asia', 'Seminar', 25), ('2021-09-01', 'Africa', 'Workshop', 22), ('2021-09-01', 'Asia', 'Seminar', 30), ('2021-09-02', 'Africa', 'Workshop', 20), ('2021-09-02', 'Asia', 'Seminar', 33);
How many community education programs were held in each region in Q3 2021?
SELECT DATEPART(qq, ProgramDate) AS Quarter, Region, SUM(Number) AS TotalPrograms FROM EducationPrograms WHERE ProgramDate BETWEEN '2021-07-01' AND '2021-09-30' GROUP BY DATEPART(qq, ProgramDate), Region;
gretelai_synthetic_text_to_sql
CREATE TABLE aircraft (aircraft_id INT, model VARCHAR(100), manufacturer VARCHAR(100)); CREATE TABLE safety_records (record_id INT, aircraft_id INT, incident_count INT); INSERT INTO aircraft (aircraft_id, model, manufacturer) VALUES (1, 'Aircraft Model 1', 'Aviation Inc.'); INSERT INTO aircraft (aircraft_id, model, manufacturer) VALUES (2, 'Aircraft Model 2', 'Flight Corp.'); INSERT INTO safety_records (record_id, aircraft_id, incident_count) VALUES (1, 1, 3); INSERT INTO safety_records (record_id, aircraft_id, incident_count) VALUES (2, 2, 1);
What is the average incident count per aircraft model?
SELECT model, AVG(incident_count) FROM aircraft INNER JOIN safety_records ON aircraft.aircraft_id = safety_records.aircraft_id GROUP BY model;
gretelai_synthetic_text_to_sql
CREATE TABLE Infrastructure (id INT, project VARCHAR(255), location VARCHAR(255), year INT, cost FLOAT); INSERT INTO Infrastructure (id, project, location, year, cost) VALUES (1, 'Bridge', 'Rural East', 2015, 1500000), (2, 'Road', 'Urban North', 2017, 5000000), (3, 'Water Supply', 'Rural South', 2016, 3000000), (4, 'Electricity', 'Urban West', 2018, 7000000);
How many rural infrastructure projects in the 'Infrastructure' table were completed in 2015 or earlier?
SELECT COUNT(*) as num_projects FROM Infrastructure WHERE year <= 2015;
gretelai_synthetic_text_to_sql
CREATE TABLE cyber_attacks (id INT, region VARCHAR(20), attack_type VARCHAR(30), date DATE); INSERT INTO cyber_attacks (id, region, attack_type, date) VALUES (1, 'East Coast', 'Phishing', '2021-01-01'); INSERT INTO cyber_attacks (id, region, attack_type, date) VALUES (2, 'West Coast', 'Malware', '2021-01-02');
What is the total number of cyber attacks in the East Coast region?
SELECT COUNT(*) FROM cyber_attacks WHERE region = 'East Coast';
gretelai_synthetic_text_to_sql
CREATE TABLE shariah_mortgages (mortgage_id INT, customer_id INT, account_balance DECIMAL); CREATE TABLE socially_responsible_loans (loan_id INT, customer_id INT, account_balance DECIMAL); CREATE TABLE shariah_loans (loan_id INT, mortgage_id INT);
What is the average account balance for customers who have a Shariah-compliant mortgage or a socially responsible loan?
SELECT AVG(CASE WHEN sm.customer_id IS NOT NULL THEN sm.account_balance ELSE srl.account_balance END) FROM shariah_mortgages sm RIGHT JOIN socially_responsible_loans srl ON sm.customer_id = srl.customer_id JOIN shariah_loans sl ON sm.mortgage_id = sl.mortgage_id OR srl.loan_id = sl.loan_id;
gretelai_synthetic_text_to_sql
CREATE TABLE community_policing (id INT, county VARCHAR(20), year INT, events INT);
How many community policing events were held in the Los Angeles County in the year 2020?
SELECT COUNT(*) FROM community_policing WHERE county = 'Los Angeles' AND year = 2020;
gretelai_synthetic_text_to_sql
CREATE TABLE games (game_id INT, team1 VARCHAR(50), team2 VARCHAR(50), league VARCHAR(50), season INT, year INT, points1 INT, points2 INT); INSERT INTO games (game_id, team1, team2, league, season, year, points1, points2) VALUES (1, 'Warriors', 'Cavaliers', 'NBA', 2015, 2015, 104, 91);
What is the total number of points scored by the 'Warriors' in the NBA since the year 2015?
SELECT SUM(points1) FROM games WHERE team1 = 'Warriors' AND year >= 2015;
gretelai_synthetic_text_to_sql
CREATE TABLE automation_trends (date DATETIME, trend_data VARCHAR(500));
Delete the automation trend for May 6, 2022
DELETE FROM automation_trends WHERE date = '2022-05-06';
gretelai_synthetic_text_to_sql
CREATE TABLE clients (client_id INT, client_name TEXT, total_billing FLOAT); INSERT INTO clients (client_id, client_name, total_billing) VALUES (1, 'Jane Doe', 2000.00), (2, 'John Doe', 3000.00);
What is the total billing amount for client 'John Doe'?
SELECT total_billing FROM clients WHERE client_name = 'John Doe';
gretelai_synthetic_text_to_sql
CREATE TABLE AgriculturalInnovation (ProjectID INT, ProjectName VARCHAR(50), Location VARCHAR(50), Investment FLOAT); INSERT INTO AgriculturalInnovation (ProjectID, ProjectName, Location, Investment) VALUES (1, 'Precision Farming Project', 'China', 150000.00), (2, 'Vertical Farming Project', 'India', 200000.00);
Find the top 3 agricultural innovation projects with the highest investment in Asia?
SELECT ProjectName, Investment FROM (SELECT ProjectName, Investment, RANK() OVER (ORDER BY Investment DESC) as ProjectRank FROM AgriculturalInnovation WHERE Location = 'Asia') WHERE ProjectRank <= 3;
gretelai_synthetic_text_to_sql
CREATE TABLE ethereum_transactions (transaction_id INT, gas_fee DECIMAL, timestamp TIMESTAMP);
What is the average gas fee for Ethereum transactions in the past month?
SELECT AVG(gas_fee) FROM ethereum_transactions WHERE timestamp >= NOW() - INTERVAL '1 month';
gretelai_synthetic_text_to_sql
CREATE TABLE product_ingredients (product_id INT, ingredient VARCHAR(255), percentage FLOAT, is_organic BOOLEAN, PRIMARY KEY (product_id, ingredient));
Create a view that shows the top 5 products with the most organic ingredients
CREATE VIEW top_5_organic_products AS SELECT product_id, SUM(percentage) as total_organic_ingredients FROM product_ingredients WHERE is_organic = true GROUP BY product_id ORDER BY total_organic_ingredients DESC LIMIT 5;
gretelai_synthetic_text_to_sql
CREATE TABLE exploration_projects (id INT, location VARCHAR(20), start_date DATE);
List the number of exploration projects in Africa that started in the last 3 years.
SELECT COUNT(*) FROM exploration_projects WHERE location LIKE 'Africa%' AND start_date > DATE_SUB(CURDATE(), INTERVAL 3 YEAR);
gretelai_synthetic_text_to_sql
CREATE TABLE environmental_impact (id INT, year INT, co2_emission FLOAT); INSERT INTO environmental_impact (id, year, co2_emission) VALUES (1, 2018, 12000.00); INSERT INTO environmental_impact (id, year, co2_emission) VALUES (2, 2019, 15000.00); INSERT INTO environmental_impact (id, year, co2_emission) VALUES (3, 2020, 18000.00);
What is the total CO2 emission in the 'environmental_impact' table for the year 2020?
SELECT SUM(co2_emission) FROM environmental_impact WHERE year = 2020;
gretelai_synthetic_text_to_sql
CREATE TABLE Factories (factory_id INT, name VARCHAR(100), location VARCHAR(100), num_workers INT, wage DECIMAL(5,2), uses_organic BOOLEAN); CREATE TABLE Materials (material_id INT, name VARCHAR(100), type VARCHAR(50), is_organic BOOLEAN); INSERT INTO Factories VALUES (1,'Factory A','New York',200,15.00,TRUE),(2,'Factory B','Mumbai',350,5.00,FALSE),(3,'Factory C','Dhaka',500,8.00,TRUE),(4,'Factory D','São Paulo',400,10.00,FALSE); INSERT INTO Materials VALUES (1,'Organic Cotton', 'Sustainable', TRUE),(2,'Recycled Rubber', 'Recycled', FALSE),(3,'Hemp', 'Sustainable', TRUE),(4,'Synthetic Fiber', 'Synthetic', FALSE);
What is the average wage of workers in factories that use organic materials?
SELECT AVG(Factories.wage) FROM Factories JOIN Materials ON Factories.uses_organic = Materials.is_organic WHERE Materials.name = 'Organic Cotton';
gretelai_synthetic_text_to_sql
CREATE TABLE SmartCities (CityID int, CityName varchar(50), RenewableEnergyConsumption int);
What is the maximum, minimum, and average renewable energy consumption per smart city?
SELECT CityName, MAX(RenewableEnergyConsumption) as MaxREConsumption, MIN(RenewableEnergyConsumption) as MinREConsumption, AVG(RenewableEnergyConsumption) as AvgREConsumption FROM SmartCities GROUP BY CityName;
gretelai_synthetic_text_to_sql
CREATE TABLE waste_generation (id INT, state VARCHAR(50), waste_amount FLOAT, waste_type VARCHAR(50), year INT); INSERT INTO waste_generation (id, state, waste_amount, waste_type, year) VALUES (1, 'New South Wales', 12000, 'aluminum', 2020), (2, 'Victoria', 10000, 'aluminum', 2020), (3, 'Queensland', 9000, 'aluminum', 2020);
What is the aluminum waste generation per capita by state in Australia in 2020?
SELECT state, SUM(waste_amount) / (SELECT SUM(population) FROM populations WHERE populations.state = state AND populations.year = 2020) as per_capita FROM waste_generation WHERE waste_type = 'aluminum' AND year = 2020 GROUP BY state ORDER BY per_capita DESC;
gretelai_synthetic_text_to_sql
CREATE TABLE product_safety (product_id INT, region VARCHAR(255), cruelty_free BOOLEAN); CREATE VIEW product_safety_summary AS SELECT region, SUM(cruelty_free) AS cruelty_free_products FROM product_safety GROUP BY region;
Which regions have the highest percentage of cruelty-free certified products?
SELECT region, (cruelty_free_products * 100.0 / total_products) AS percentage_cruelty_free FROM product_safety_summary WHERE total_products > 0;
gretelai_synthetic_text_to_sql
CREATE TABLE defense_projects (id INT, country VARCHAR(50), start_year INT, end_year INT); INSERT INTO defense_projects (id, country, start_year, end_year) VALUES (1, 'India', 2019, 2022); INSERT INTO defense_projects (id, country, start_year, end_year) VALUES (2, 'India', 2017, 2020);
How many defense projects were ongoing in India as of 2019?
SELECT COUNT(*) FROM defense_projects WHERE country = 'India' AND end_year >= 2019;
gretelai_synthetic_text_to_sql
CREATE TABLE crop_temperature (crop_id INT, crop_type VARCHAR(50), timestamp TIMESTAMP, temperature INT);
Identify the top three crops with the highest average temperature for the past year.
SELECT crop_type, AVG(temperature) AS avg_temperature FROM crop_temperature WHERE timestamp >= NOW() - INTERVAL '1 year' GROUP BY crop_type ORDER BY avg_temperature DESC LIMIT 3;
gretelai_synthetic_text_to_sql
CREATE TABLE Volunteers (VolunteerID INT, VolunteerName TEXT, VolunteerDate DATE);
Find the total number of volunteers who joined in Q1 and Q3 of 2021.
SELECT SUM(CASE WHEN EXTRACT(QUARTER FROM V.VolunteerDate) IN (1,3) THEN 1 ELSE 0 END) as Volunteers FROM Volunteers V WHERE YEAR(V.VolunteerDate) = 2021;
gretelai_synthetic_text_to_sql
CREATE TABLE supplier_info (supplier_name VARCHAR(50), supplier_country VARCHAR(50));
Insert new record into 'supplier_info' table for 'Supplier B' and 'Brazil'
INSERT INTO supplier_info (supplier_name, supplier_country) VALUES ('Supplier B', 'Brazil');
gretelai_synthetic_text_to_sql
CREATE TABLE RetailerA (item VARCHAR(20), quantity INT); INSERT INTO RetailerA VALUES ('Dress', 250);
What is the total quantity of 'Dress' items sold by 'Retailer A'?
SELECT SUM(quantity) FROM RetailerA WHERE item = 'Dress' AND retailer = 'Retailer A';
gretelai_synthetic_text_to_sql
CREATE TABLE sales_data (sale_id INT, product VARCHAR(255), country VARCHAR(255), sales FLOAT); INSERT INTO sales_data (sale_id, product, country, sales) VALUES (1, 'ProductA', 'USA', 4000), (2, 'ProductB', 'Brazil', 5000), (3, 'ProductC', 'India', 6000), (4, 'ProductD', 'China', 7000);
Which products were sold in a specific country?
SELECT product FROM sales_data WHERE country = 'India';
gretelai_synthetic_text_to_sql
CREATE TABLE freight_forwarders (id INT, name VARCHAR(255));CREATE TABLE shipments (id INT, forwarder_id INT, weight FLOAT);INSERT INTO freight_forwarders (id, name) VALUES (1, 'ABC Freight'), (2, 'XYZ Logistics');INSERT INTO shipments (id, forwarder_id, weight) VALUES (1, 1, 120.5), (2, 1, 75.2), (3, 2, 50.0);
Which freight forwarders have handled shipments that weigh more than 100 kg?
SELECT f.name FROM freight_forwarders f INNER JOIN shipments s ON f.id = s.forwarder_id WHERE s.weight > 100;
gretelai_synthetic_text_to_sql
CREATE TABLE space_missions (id INT, mission_name VARCHAR(50), launch_date DATE, scheduled_date DATE); INSERT INTO space_missions VALUES (1, 'Artemis I', '2022-08-29', '2022-06-29'); INSERT INTO space_missions VALUES (2, 'Mars Science Laboratory', '2011-11-26', '2011-08-05');
Delete space missions with a launch delay of more than 90 days in the space_missions table?
DELETE FROM space_missions WHERE DATEDIFF(day, scheduled_date, launch_date) > 90;
gretelai_synthetic_text_to_sql
CREATE TABLE subscriber_activity (subscriber_id INT, last_data_usage_date DATE); INSERT INTO subscriber_activity (subscriber_id, last_data_usage_date) VALUES (1, '2021-01-01'), (2, '2022-03-15'), (3, NULL), (6, NULL);
Delete subscribers who have not used any data in the last year.
DELETE FROM subscribers WHERE subscriber_id NOT IN (SELECT subscriber_id FROM subscriber_activity WHERE last_data_usage_date IS NOT NULL);
gretelai_synthetic_text_to_sql
CREATE TABLE union_members (member_id INT, member_name VARCHAR(255), union_id INT, monthly_salary DECIMAL(10,2)); CREATE TABLE unions (union_id INT, union_name VARCHAR(255)); INSERT INTO unions (union_id, union_name) VALUES (123, 'United Workers Union'); INSERT INTO unions (union_id, union_name) VALUES (456, 'Labor Rights Union'); INSERT INTO union_members (member_id, member_name, union_id, monthly_salary) VALUES (1, 'John Doe', 456, 3500.50); INSERT INTO union_members (member_id, member_name, union_id, monthly_salary) VALUES (2, 'Jane Doe', 123, 3200.25);
What is the average monthly salary of workers in the 'Labor Rights Union'?
SELECT AVG(monthly_salary) FROM union_members WHERE union_id = (SELECT union_id FROM unions WHERE union_name = 'Labor Rights Union');
gretelai_synthetic_text_to_sql
CREATE TABLE bus_fares (ride_id INT, fare FLOAT, region VARCHAR(20)); INSERT INTO bus_fares (ride_id, fare, region) VALUES (1, 2.50, 'NY'), (2, 3.00, 'NJ'), (3, 2.75, 'NY'); CREATE TABLE train_fares (ride_id INT, fare FLOAT, region VARCHAR(20)); INSERT INTO train_fares (ride_id, fare, region) VALUES (4, 5.00, 'NY'), (5, 6.00, 'NY'), (6, 4.50, 'NY');
What is the total revenue generated from bus and train rides in the NY region?
SELECT SUM(fare) FROM (SELECT fare FROM bus_fares WHERE region = 'NY' UNION ALL SELECT fare FROM train_fares WHERE region = 'NY') AS total_fares;
gretelai_synthetic_text_to_sql
CREATE TABLE students (student_id INT, student_name TEXT, program TEXT, total_open_pedagogy_hours INT); INSERT INTO students (student_id, student_name, program, total_open_pedagogy_hours) VALUES (1, 'Alice', 'Technology and Design', 45), (2, 'Bob', 'History', 30), (3, 'Charlie', 'Technology and Design', 60);
What is the total number of hours spent on open pedagogy projects by students in the 'Technology and Design' program?
SELECT SUM(total_open_pedagogy_hours) FROM students WHERE program = 'Technology and Design';
gretelai_synthetic_text_to_sql
CREATE SCHEMA if not exists asia_schema_2;CREATE TABLE asia_schema_2.asia_mines (id INT, name VARCHAR, production_value DECIMAL);INSERT INTO asia_schema_2.asia_mines (id, name, production_value) VALUES (1, 'A mining', 850000.00), (2, 'B mining', 600000.00);
List all mining operations in 'asia_mines' with production values higher than $800000.
SELECT name FROM asia_schema_2.asia_mines WHERE production_value > 800000;
gretelai_synthetic_text_to_sql
CREATE TABLE cases (case_id INT, attorney_name VARCHAR(50), case_outcome VARCHAR(10), case_state VARCHAR(10)); INSERT INTO cases (case_id, attorney_name, case_outcome, case_state) VALUES (1, 'Michael Lee', 'Won', 'California'), (2, 'Grace Kim', 'Lost', 'California'), (3, 'Michael Lee', 'Won', 'California');
What are the names of attorneys who have a 100% success rate in California?
SELECT attorney_name FROM cases WHERE case_outcome = 'Won' AND case_state = 'California' GROUP BY attorney_name HAVING COUNT(*) = (SELECT COUNT(*) FROM cases WHERE attorney_name = cases.attorney_name AND case_outcome = 'Won' AND case_state = 'California');
gretelai_synthetic_text_to_sql
CREATE TABLE schema1.vulnerabilities (id INT, name VARCHAR(255), severity VARCHAR(50), description TEXT, date_discovered DATE, last_observed DATE); INSERT INTO schema1.vulnerabilities (id, name, severity, description, date_discovered, last_observed) VALUES (1, 'SQL Injection', 'Critical', 'Allows unauthorized access', '2021-01-01', '2021-02-01');
What is the maximum severity of vulnerabilities in the 'vulnerabilities' table?
SELECT MAX(severity) FROM schema1.vulnerabilities;
gretelai_synthetic_text_to_sql
CREATE TABLE organizations (id INT, name VARCHAR(50), type VARCHAR(50), country VARCHAR(50)); INSERT INTO organizations (id, name, type, country) VALUES (1, 'Greenpeace', 'NGO', 'Global'); INSERT INTO organizations (id, name, type, country) VALUES (2, 'SolarAid', 'NGO', 'India'); INSERT INTO organizations (id, name, type, country) VALUES (3, 'Climate Action Network', 'NGO', 'Global'); INSERT INTO organizations (id, name, type, country) VALUES (4, 'Centre for Science and Environment', 'Research Institute', 'India'); CREATE TABLE communications (id INT, title VARCHAR(50), description TEXT, type VARCHAR(50), target_audience VARCHAR(50), organization_id INT); INSERT INTO communications (id, title, description, type, target_audience, organization_id) VALUES (1, 'Renewable Energy Report', 'Climate change mitigation strategies.', 'Report', 'General Public', 1); INSERT INTO communications (id, title, description, type, target_audience, organization_id) VALUES (2, 'Solar Power Webinar', 'Introduction to solar power.', 'Webinar', 'Students', 2); INSERT INTO communications (id, title, description, type, target_audience, organization_id) VALUES (3, 'Climate Change Impact Study', 'Analysis of climate change impacts.', 'Study', 'General Public', 3); INSERT INTO communications (id, title, description, type, target_audience, organization_id) VALUES (4, 'Climate Policy Brief', 'Policy recommendations on climate change.', 'Brief', 'Policy Makers', 3);
List the unique types of communications for NGOs based in India.
SELECT DISTINCT type FROM communications c JOIN organizations o ON c.organization_id = o.id WHERE o.type = 'NGO' AND o.country = 'India';
gretelai_synthetic_text_to_sql
CREATE TABLE research_spending (id INT PRIMARY KEY, chemical_name VARCHAR(255), production_plant VARCHAR(255), research_spending_per_product DECIMAL(5,2)); INSERT INTO research_spending (id, chemical_name, production_plant, research_spending_per_product) VALUES (1, 'Hydrochloric Acid', 'Plant C', 5000); INSERT INTO research_spending (id, chemical_name, production_plant, research_spending_per_product) VALUES (2, 'Acetic Acid', 'Plant D', 6000);
Find the average research spending per product for chemicals produced in Asian plants.
SELECT AVG(research_spending_per_product) FROM research_spending WHERE production_plant LIKE '%Asia%';
gretelai_synthetic_text_to_sql
CREATE TABLE temperature_monitor (station VARCHAR(50), depth FLOAT, temperature FLOAT); INSERT INTO temperature_monitor VALUES ('Station 1', 0, 20.5), ('Station 1', 100, 21.5), ('Station 2', 0, 21.3), ('Station 2', 100, 22.3);
What is the difference in temperature between consecutive monitoring stations for each depth?
SELECT station, depth, temperature - LAG(temperature) OVER (PARTITION BY depth ORDER BY station) as temperature_difference FROM temperature_monitor;
gretelai_synthetic_text_to_sql
CREATE TABLE states (id INT, name VARCHAR(255)); INSERT INTO states (id, name) VALUES (1, 'Alabama'), (2, 'Alaska'); CREATE TABLE populations (id INT, state_id INT, smoker BOOLEAN); INSERT INTO populations (id, state_id, smoker) VALUES (1, 1, true);
What percentage of the population in each state has a smoking habit?
SELECT s.name, (COUNT(p.id) * 100.0 / (SELECT COUNT(*) FROM populations WHERE state_id = s.id)) AS smoker_percentage FROM states s JOIN populations p ON s.id = p.state_id GROUP BY s.name;
gretelai_synthetic_text_to_sql
CREATE SCHEMA carbon_offsets; CREATE TABLE projects (project_name VARCHAR(255), region VARCHAR(255), investment_amount INT); INSERT INTO projects (project_name, region, investment_amount) VALUES ('Tropical Forest Conservation', 'Asia', 5000000), ('Wind Power Generation', 'Europe', 8000000), ('Soil Carbon Sequestration', 'Africa', 3000000), ('Oceanic Algae Farming', 'Oceania', 7000000);
Find the number of carbon offset projects by region and their corresponding total investment amounts, grouped by region.
SELECT region, COUNT(*), SUM(investment_amount) FROM carbon_offsets.projects GROUP BY region;
gretelai_synthetic_text_to_sql
CREATE TABLE underground_mines (mine_site VARCHAR(50), annual_inspections INT); INSERT INTO underground_mines (mine_site, annual_inspections) VALUES ('Site A', 3), ('Site B', 1), ('Site C', 2), ('Site D', 4);
List all unique 'mine_sites' from the 'underground_mines' table with 'annual_inspections' greater than 2?
SELECT mine_site FROM underground_mines WHERE annual_inspections > 2;
gretelai_synthetic_text_to_sql