context
stringlengths 11
9.12k
| question
stringlengths 0
1.06k
| SQL
stringlengths 2
4.44k
| source
stringclasses 28
values |
|---|---|---|---|
CREATE TABLE departments (department VARCHAR(50), total_grant_amount FLOAT); INSERT INTO departments VALUES ('Computer Science', 500000), ('Mathematics', 400000), ('Physics', 600000); CREATE TABLE grants (grant_id INT, department VARCHAR(50), year INT, amount FLOAT, faculty_published BOOLEAN); INSERT INTO grants VALUES (1, 'Computer Science', 2018, 100000, true), (2, 'Physics', 2017, 150000, false), (3, 'Mathematics', 2019, 120000, true), (4, 'Computer Science', 2020, 125000, true), (5, 'Physics', 2016, 130000, false), (6, 'Mathematics', 2021, 110000, true);
|
Determine the total amount of research grants awarded to each department in the last five years, excluding grants awarded to faculty members who have not published in the last three years.
|
SELECT d.department, SUM(g.amount) FROM departments d JOIN grants g ON d.department = g.department WHERE g.faculty_published = true AND g.year BETWEEN YEAR(CURRENT_DATE) - 5 AND YEAR(CURRENT_DATE) GROUP BY d.department;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE climate_adaptation (project_name VARCHAR(255), region VARCHAR(255), co2_reduction_tonnes INT, start_date DATE); INSERT INTO climate_adaptation (project_name, region, co2_reduction_tonnes, start_date) VALUES ('Flood Prevention', 'Asia', 1000, '2018-01-01'); INSERT INTO climate_adaptation (project_name, region, co2_reduction_tonnes, start_date) VALUES ('Drought Resistance', 'Asia', 1500, '2019-05-15');
|
What is the average annual CO2 emissions reduction for each climate adaptation project in Asia?
|
SELECT region, AVG(co2_reduction_tonnes / DATEDIFF(year, start_date, CURDATE())) as avg_annual_reduction FROM climate_adaptation WHERE region = 'Asia' GROUP BY region;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE donations (id INT, donor_id INT, project_id INT, amount INT); CREATE TABLE donors (id INT, name TEXT, age INT); CREATE TABLE projects (id INT, name TEXT, location TEXT); INSERT INTO donations VALUES (1, 1, 1, 500), (2, 2, 2, 300), (3, 3, 1, 700); INSERT INTO donors VALUES (1, 'Adebola Johnson', 35), (2, 'Abdirahman Osman', 40), (3, 'Chiamaka Nwankwo', 45); INSERT INTO projects VALUES (1, 'Education', 'Nigeria'), (2, 'Clean Water', 'Somalia');
|
What's the total donation amount given to the Education program in Nigeria and the Clean Water project in Somalia?
|
SELECT SUM(d.amount) FROM donations d INNER JOIN projects p ON d.project_id = p.id WHERE p.name IN ('Education', 'Clean Water') AND p.location IN ('Nigeria', 'Somalia');
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE artists (id INT, name TEXT); INSERT INTO artists (id, name) VALUES (1, 'Artist 1'), (2, 'Artist 2'), (3, 'Artist 3'); CREATE TABLE artworks (id INT, title TEXT, year_created INT, artist_id INT); INSERT INTO artworks (id, title, year_created, artist_id) VALUES (1, 'Artwork 1', 2000, 1), (2, 'Artwork 2', 1990, 1), (3, 'Artwork 3', 2010, 2), (4, 'Artwork 4', 2022, 3), (5, 'Artwork 5', 2015, 1);
|
Delete all artworks by artist 'Artist 1'.
|
DELETE FROM artworks WHERE artist_id = 1;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE food_safety_inspections(restaurant_id INT, restaurant_name VARCHAR(255), category VARCHAR(255), state VARCHAR(255), score INT, date DATE); INSERT INTO food_safety_inspections(restaurant_id, restaurant_name, category, state, score, date) VALUES (1, 'Burger Joint', 'Fast Food', 'California', 85, '2021-01-01'); INSERT INTO food_safety_inspections(restaurant_id, restaurant_name, category, state, score, date) VALUES (2, 'Pizza Place', 'Fast Food', 'California', 90, '2021-01-02');
|
What was the average food safety inspection score for 'Fast Food' restaurants in 'California' in 2021?
|
SELECT AVG(score) FROM food_safety_inspections WHERE category = 'Fast Food' AND state = 'California' AND date BETWEEN '2021-01-01' AND '2021-12-31';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE infectious_disease (region VARCHAR(10), cases INT); INSERT INTO infectious_disease (region, cases) VALUES ('North', 100), ('South', 150), ('East', 200), ('West', 50);
|
Number of infectious disease cases in each region, ordered by the highest number of cases.
|
SELECT region, cases, RANK() OVER (ORDER BY cases DESC) AS rank FROM infectious_disease;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Customers (customer_id INT, country VARCHAR(255), size VARCHAR(50), preferred_trend_id INT);CREATE TABLE Sales (sale_id INT, garment_id INT, location_id INT, sale_date DATE);CREATE TABLE Garments (garment_id INT, trend_id INT, fabric_source_id INT, size VARCHAR(50), style VARCHAR(255));CREATE TABLE FabricSources (source_id INT, fabric_type VARCHAR(255), country_of_origin VARCHAR(255), ethical_rating DECIMAL(3,2));CREATE TABLE StoreLocations (location_id INT, city VARCHAR(255), country VARCHAR(255), sales_volume INT);CREATE VIEW PetiteCustomers AS SELECT * FROM Customers WHERE size = 'Petite';CREATE VIEW EcoFriendlyDenim AS SELECT * FROM Garments WHERE fabric_source_id IN (SELECT source_id FROM FabricSources WHERE fabric_type = 'Denim' AND ethical_rating >= 7.0) AND style = 'Eco-friendly';CREATE VIEW ParisSales AS SELECT * FROM Sales WHERE location_id IN (SELECT location_id FROM StoreLocations WHERE city = 'Paris');CREATE VIEW ParisPetiteEcoDenim AS SELECT * FROM ParisSales WHERE garment_id IN (SELECT garment_id FROM EcoFriendlyDenim WHERE size = 'Petite');
|
How many Petite customers have purchased Eco-friendly Denim items in Paris during 2021?
|
SELECT COUNT(DISTINCT customer_id) FROM ParisPetiteEcoDenim WHERE sale_date BETWEEN '2021-01-01' AND '2021-12-31';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE ethical_ai_projects (id INT, project_name VARCHAR(50), completion_date DATE, schema VARCHAR(50)); INSERT INTO ethical_ai_projects (id, project_name, completion_date, schema) VALUES (1, 'Project A', '2021-01-01', 'responsible_ai'), (2, 'Project B', '2022-01-01', 'responsible_ai'), (3, 'Project C', '2023-02-01', 'responsible_ai'), (4, 'Project D', '2023-03-15', 'responsible_ai');
|
How many ethical AI projects were completed in the "responsible_ai" schema in 2021, 2022, and Q1 2023?
|
SELECT COUNT(*) FROM ethical_ai_projects WHERE schema = 'responsible_ai' AND (YEAR(completion_date) BETWEEN 2021 AND 2023 OR QUARTER(completion_date) = 1 AND YEAR(completion_date) = 2023);
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE train_schedules (id INT, station_id INT, route_id INT, timestamp TIMESTAMP); CREATE VIEW trains_between_7_9 AS SELECT station_id FROM train_schedules WHERE TIME(timestamp) BETWEEN '07:00:00' AND '09:00:00';
|
How many trains in Berlin pass through a station between 7 AM and 9 AM?
|
SELECT COUNT(*) FROM trains_between_7_9;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE museums (name VARCHAR(255), location VARCHAR(255), website VARCHAR(255));
|
Find the names and locations of all the museums that have a website.
|
SELECT name, location FROM museums WHERE website IS NOT NULL;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE forests (id INT, name VARCHAR(50), hectares DECIMAL(5,2), year_planted INT, country VARCHAR(50), PRIMARY KEY (id)); INSERT INTO forests (id, name, hectares, year_planted, country) VALUES (1, 'Forest A', 123.45, 1990, 'USA'), (2, 'Forest B', 654.32, 1985, 'Canada'), (3, 'Forest C', 456.78, 2010, 'USA'), (4, 'Forest D', 903.45, 1980, 'Mexico');
|
Determine the total hectares of forest land for each country
|
SELECT f.country, SUM(f.hectares) FROM forests f GROUP BY f.country;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE portfolio_managers (manager_id INT, portfolio_id INT, manager_name VARCHAR(30), portfolio_value DECIMAL(12,2)); INSERT INTO portfolio_managers (manager_id, portfolio_id, manager_name, portfolio_value) VALUES (1, 1001, 'Manager A', 12000000.00), (2, 1002, 'Manager B', 8000000.00), (3, 1003, 'Manager C', 5000000.00), (1, 1004, 'Manager A', 15000000.00);
|
Display the total value of assets for each portfolio manager who manages at least one portfolio with a value greater than $10 million.
|
SELECT manager_name, SUM(portfolio_value) FROM portfolio_managers WHERE portfolio_value > 10000000 GROUP BY manager_name;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE people (id INT, name TEXT); CREATE TABLE expenses (id INT, person_id INT, category TEXT, year INT, amount FLOAT); INSERT INTO people (id, name) VALUES (1, 'John Doe'); INSERT INTO people (id, name) VALUES (2, 'Jane Doe'); INSERT INTO expenses (id, person_id, category, year, amount) VALUES (1, 1, 'Shelter', 2019, 1000.00); INSERT INTO expenses (id, person_id, category, year, amount) VALUES (2, 1, 'Shelter', 2018, 1500.00); INSERT INTO expenses (id, person_id, category, year, amount) VALUES (3, 2, 'Shelter', 2019, 2000.00);
|
What was the average amount spent per person on shelter in 2019?
|
SELECT AVG(amount) FROM expenses e JOIN people p ON e.person_id = p.id WHERE e.category = 'Shelter' AND e.year = 2019;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE RevenueData (StreamingPlatform TEXT, Genre TEXT, Quarter TEXT(2), Year INTEGER, ARPU FLOAT); INSERT INTO RevenueData (StreamingPlatform, Genre, Quarter, Year, ARPU) VALUES ('Spotify', 'Rock', 'Q3', 2021, 4.5), ('AppleMusic', 'Rock', 'Q3', 2021, 5.3), ('YoutubeMusic', 'Rock', 'Q3', 2021, 3.9), ('Pandora', 'Rock', 'Q3', 2021, 4.1), ('Tidal', 'Rock', 'Q3', 2021, 5.7);
|
What is the average revenue per user (ARPU) for the rock genre across all streaming platforms in Q3 2021?
|
SELECT AVG(ARPU) as AvgARPU FROM RevenueData WHERE Genre = 'Rock' AND Quarter = 'Q3' AND Year = 2021;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE water_usage (id INT PRIMARY KEY, mine_id INT, water_type VARCHAR(255), usage_quantity FLOAT, FOREIGN KEY (mine_id) REFERENCES mines(id));
|
What is the average water usage quantity for mines that use recycled water, updated to reflect a 10% decrease?
|
SELECT AVG(usage_quantity) FROM water_usage WHERE water_type = 'recycled';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE production_sites(id INT, site_name TEXT, safety_score INT, last_inspection_date DATE);
|
Insert a new record for a production site located in India with a safety score of 88 and a last inspection date of 2022-01-10.
|
INSERT INTO production_sites (site_name, safety_score, last_inspection_date) VALUES ('Site C', 88, '2022-01-10');
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Donors (DonorID int, DonorName varchar(50), Country varchar(50)); INSERT INTO Donors (DonorID, DonorName, Country) VALUES (1, 'John Doe', 'USA'), (2, 'Jane Smith', 'Canada'); CREATE TABLE Donations (DonationID int, DonorID int, DonationAmount decimal(10,2)); INSERT INTO Donations (DonationID, DonorID, DonationAmount) VALUES (1, 2, 100), (2, 2, 200), (3, 1, 50);
|
What is the maximum donation amount received from a donor in each country?
|
SELECT Country, MAX(DonationAmount) FROM Donations JOIN Donors ON Donations.DonorID = Donors.DonorID GROUP BY Country;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Songs (SongName TEXT, Genre TEXT, LengthMinutes INTEGER, Year INTEGER); INSERT INTO Songs (SongName, Genre, LengthMinutes, Year) VALUES ('Song1', 'Jazz', 4, 2020), ('Song2', 'Jazz', 5, 2020), ('Song3', 'Jazz', 3, 2020);
|
What are the total number of songs and the average length in minutes for the jazz genre in 2020?
|
SELECT Genre, COUNT(*) as NumOfSongs, AVG(LengthMinutes) as AvgLength FROM Songs WHERE Genre = 'Jazz' AND Year = 2020;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE climate_finance (country VARCHAR(50), year INT, amount INT); INSERT INTO climate_finance (country, year, amount) VALUES ('Nigeria', 2020, 5000000), ('Kenya', 2020, 6000000), ('Egypt', 2020, 7000000);
|
How many climate finance records are there for each country in Africa?
|
SELECT country, COUNT(*) FROM climate_finance WHERE country IN ('Nigeria', 'Kenya', 'Egypt') GROUP BY country;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE inventory(item VARCHAR(255), warehouse VARCHAR(255)); INSERT INTO inventory VALUES('XYZ', 'A01');
|
Update the warehouse location for item XYZ
|
UPDATE inventory SET warehouse = 'B02' WHERE item = 'XYZ';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE organic_sales (id INT PRIMARY KEY, retailer_id INT, product_id INT, quantity INT, date DATE, organic BOOLEAN); INSERT INTO organic_sales (id, retailer_id, product_id, quantity, date, organic) VALUES (1, 1, 1, 50, '2022-01-01', true), (2, 2, 2, 75, '2022-01-02', true);
|
What is the total quantity of organic cotton garments sold by retailers located in Los Angeles, grouped by product category and date?
|
SELECT o.category, o.date, SUM(o.quantity) FROM organic_sales o JOIN products p ON o.product_id = p.id JOIN retailers r ON o.retailer_id = r.id WHERE o.organic = true AND r.location = 'Los Angeles' GROUP BY o.category, o.date;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Programs (ProgramID INT, ProgramName TEXT, Donations DECIMAL(10,2)); INSERT INTO Programs (ProgramID, ProgramName, Donations) VALUES (1, 'Education', 5000.00), (2, 'Healthcare', 7000.00);
|
Which programs received the most donations?
|
SELECT ProgramName, SUM(Donations) AS TotalDonations FROM Programs GROUP BY ProgramName ORDER BY TotalDonations DESC;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE donors (id INT, name VARCHAR(255), country VARCHAR(255));CREATE TABLE donations (id INT, donor_id INT, cause_id INT, amount DECIMAL(10, 2), donation_date DATE);CREATE TABLE causes (id INT, name VARCHAR(255));
|
What's the total amount of donations made for each cause in the last 3 years?
|
SELECT c.name, YEAR(d.donation_date), SUM(d.amount) FROM donations d INNER JOIN causes c ON d.cause_id = c.id WHERE d.donation_date >= DATE_SUB(NOW(), INTERVAL 3 YEAR) GROUP BY YEAR(d.donation_date), c.name;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE case_outcomes (case_id INT PRIMARY KEY, attorney_id INT, outcome VARCHAR(20));
|
Show the number of cases and their respective outcomes for a given attorney
|
SELECT attorney_id, COUNT(*) FROM case_outcomes GROUP BY attorney_id;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE CybersecurityVulnerabilities (Vulnerability VARCHAR(50), Severity DECIMAL(3,2)); INSERT INTO CybersecurityVulnerabilities (Vulnerability, Severity) VALUES ('SQL Injection', 9.0), ('Cross-Site Scripting', 8.5), ('Remote Code Execution', 8.0), ('Buffer Overflow', 7.5), ('Path Traversal', 7.0);
|
What are the top cybersecurity vulnerabilities?
|
SELECT Vulnerability, Severity, RANK() OVER (ORDER BY Severity DESC) as Rank FROM CybersecurityVulnerabilities WHERE Rank <= 3;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE subscribers (id INT, subscriber_type VARCHAR(20), location VARCHAR(20)); INSERT INTO subscribers (id, subscriber_type, location) VALUES (1, 'Broadband', 'Suburban');
|
How many broadband subscribers does the company have in 'Suburban' areas?
|
SELECT COUNT(*) FROM subscribers WHERE subscriber_type = 'Broadband' AND location = 'Suburban';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE employees (id INT, first_name VARCHAR(50), last_name VARCHAR(50), hire_date DATE, salary INT); CREATE TABLE diversity_training (id INT, employee_id INT, training_name VARCHAR(50), completed_date DATE);
|
Delete all diversity and inclusion training records for employees who were hired before 2020 or have a salary less than 50000.
|
DELETE dt FROM diversity_training dt WHERE dt.employee_id IN (SELECT e.id FROM employees e WHERE e.hire_date < '2020-01-01' OR e.salary < 50000);
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Donations (donation_id INT, amount DECIMAL(10,2), program VARCHAR(255));
|
What is the minimum donation amount for the 'Arts' program?
|
SELECT MIN(amount) FROM Donations WHERE program = 'Arts';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE basketball_scores (player VARCHAR(50), team VARCHAR(50), date DATE, points INT); INSERT INTO basketball_scores (player, team, date, points) VALUES ('LeBron James', 'Los Angeles Lakers', '2022-01-01', 50), ('Kevin Durant', 'Brooklyn Nets', '2022-01-02', 45), ('Giannis Antetokounmpo', 'Milwaukee Bucks', '2022-01-03', 55);
|
What is the maximum number of points scored by a player in a single game in the 'basketball_scores' table?
|
SELECT MAX(points) FROM basketball_scores;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Exhibits (exhibit_id INT, city VARCHAR(50)); INSERT INTO Exhibits (exhibit_id, city) VALUES (1, 'New York'), (2, 'Los Angeles'), (3, 'Chicago'), (4, 'New York'), (5, 'Los Angeles');
|
Find the number of art exhibits in each city, ordered by the number of exhibits in descending order.
|
SELECT city, COUNT(*) as num_exhibits FROM Exhibits GROUP BY city ORDER BY num_exhibits DESC;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE accounts (account_id INT, client_id INT, account_type VARCHAR(50)); INSERT INTO accounts VALUES (1, 1, 'Checking'), (2, 2, 'Savings'), (3, 3, 'Checking'), (4, 1, 'Credit Card'), (5, 4, 'Savings');
|
Which clients have more than one account?
|
SELECT client_id, COUNT(*) as account_count FROM accounts GROUP BY client_id HAVING account_count > 1;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE seals (id INT, species TEXT, location TEXT, population INT); INSERT INTO seals (id, species, location, population) VALUES (1, 'Crabeater Seal', 'Antarctic', 7500);
|
How many species of seals are there in the Antarctic Ocean?"
|
SELECT COUNT(species) FROM seals WHERE location = 'Antarctic Ocean';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE teams (team_id INT, name VARCHAR(50), city VARCHAR(50)); CREATE TABLE games (game_id INT, team_id INT, home_team BOOLEAN, points INT);
|
Find the total points scored at home by the Lakers in the games table
|
SELECT SUM(games.points) AS total_points FROM teams INNER JOIN games ON teams.team_id = games.team_id WHERE teams.name = 'Lakers' AND games.home_team = TRUE;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE investments (investment_id INT, sector TEXT, value DECIMAL(10, 2)); INSERT INTO investments (investment_id, sector, value) VALUES (1, 'Technology', 100000.00), (2, 'Finance', 200000.00), (3, 'Technology', 150000.00);
|
What is the total value of investments in the 'Technology' sector?
|
SELECT SUM(value) FROM investments WHERE sector = 'Technology';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE rural_economy (id INT, project_name VARCHAR(50), budget DECIMAL(10, 2)); INSERT INTO rural_economy (id, project_name, budget) VALUES (1, 'Eco-Tourism', 85000.00), (2, 'Handicraft Production', 65000.00);
|
List all economic diversification projects in the 'rural_economy' table, excluding those with a budget over 100000.
|
SELECT project_name FROM rural_economy WHERE budget <= 100000;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Fleet (VehicleID INT, VehicleType VARCHAR(50), Autonomous BOOLEAN); INSERT INTO Fleet (VehicleID, VehicleType, Autonomous) VALUES (1, 'Taxi', true), (2, 'Taxi', false), (3, 'Shuttle', false), (4, 'Autonomous Taxi', true), (5, 'Sedan', false), (6, 'Autonomous Shuttle', true);
|
Calculate the percentage of autonomous taxis in the fleet
|
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Fleet)) as Percentage FROM Fleet WHERE Autonomous = true;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE mines (id INT, name VARCHAR(255), water_consumption INT, number_of_employees INT); INSERT INTO mines (id, name, water_consumption, number_of_employees) VALUES (1, 'Mine A', 50000, 200), (2, 'Mine B', 60000, 250), (3, 'Mine C', 40000, 180), (4, 'Mine D', 55000, 220);
|
What is the average water consumption per employee across all mines?
|
SELECT AVG(m.water_consumption/m.number_of_employees) as avg_water_consumption_per_employee FROM mines m;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE suppliers (id INT, name VARCHAR(255), country VARCHAR(255), sustainability_score INT);
|
Update the sustainability_score for all suppliers from 'Country A' in the suppliers table to 85.
|
UPDATE suppliers SET sustainability_score = 85 WHERE country = 'Country A';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE event_attendance (attendee_id INT, event_id INT, age_group VARCHAR(20)); INSERT INTO event_attendance (attendee_id, event_id, age_group) VALUES (1, 1, '5-17'), (2, 1, '18-34'), (3, 1, '35-54'), (4, 1, '55+');
|
What is the distribution of attendees by age group for the "Art in the Park" event?
|
SELECT age_group, COUNT(*) AS attendee_count FROM event_attendance WHERE event_id = 1 GROUP BY age_group;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE smart_cities.buildings (id INT, city VARCHAR(255), co2_emissions INT); CREATE VIEW smart_cities.buildings_view AS SELECT id, city, co2_emissions FROM smart_cities.buildings;
|
What is the average CO2 emission for buildings in the 'smart_cities' schema, excluding the top 10% highest emitters?
|
SELECT AVG(co2_emissions) FROM smart_cities.buildings_view WHERE co2_emissions NOT IN ( SELECT DISTINCT co2_emissions FROM ( SELECT co2_emissions, NTILE(10) OVER (ORDER BY co2_emissions DESC) as tile FROM smart_cities.buildings_view ) as subquery WHERE tile = 1 );
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE EmployeeSalary (EmployeeID INT, JobTitleID INT, Salary INT, FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID), FOREIGN KEY (JobTitleID) REFERENCES JobTitle(JobTitleID));
|
Update the 'Head of People Ops' salary to $150,000 in the EmployeeSalary table
|
UPDATE EmployeeSalary SET Salary = 150000 WHERE JobTitleID = (SELECT JobTitleID FROM JobTitle WHERE JobTitleName = 'Head of People Ops');
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE shipments (id INT, supplier_id INT, country VARCHAR(255), weight DECIMAL(5,2)); INSERT INTO shipments (id, supplier_id, country, weight) VALUES (1, 1, 'Spain', 25), (2, 1, 'Spain', 30), (3, 2, 'France', 20);
|
What is the total weight in kg of all shipments from Spain?
|
SELECT SUM(weight) FROM shipments WHERE country = 'Spain';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE sources (id INT PRIMARY KEY, source_name VARCHAR(50));
|
Add a new textile source 'Organic Silk' to the 'sources' table
|
INSERT INTO sources (id, source_name) VALUES (2, 'Organic Silk');
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE WasteGenerationByCountry (country VARCHAR(50), year INT, amount INT); INSERT INTO WasteGenerationByCountry (country, year, amount) VALUES ('India', 2017, 300000), ('India', 2018, 320000), ('India', 2019, 350000), ('India', 2020, 370000), ('India', 2021, 400000);
|
What is the total waste generation in India over the past 5 years?
|
SELECT SUM(amount) FROM WasteGenerationByCountry WHERE country = 'India';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE companies (id INT, name TEXT, industry TEXT, founding_date DATE, founder_gender TEXT); INSERT INTO companies (id, name, industry, founding_date, founder_gender) VALUES (1, 'GreenTech', 'Renewable Energy', '2016-01-01', 'Female'); INSERT INTO companies (id, name, industry, founding_date, founder_gender) VALUES (2, 'EcoFirm', 'Renewable Energy', '2017-01-01', 'Male'); 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, 500000, '2018-01-01'); INSERT INTO funding_records (id, company_id, funding_amount, funding_date) VALUES (2, 2, 750000, '2019-01-01');
|
What is the total funding amount for companies in the renewable energy sector that have a female founder?
|
SELECT SUM(funding_amount) FROM funding_records JOIN companies ON funding_records.company_id = companies.id WHERE companies.industry = 'Renewable Energy' AND companies.founder_gender = 'Female'
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE customers (customer_id INT, name VARCHAR(50), country VARCHAR(50), credit_score INT); INSERT INTO customers (customer_id, name, country, credit_score) VALUES (1, 'John Doe', 'USA', 750); INSERT INTO customers (customer_id, name, country, credit_score) VALUES (2, 'Jane Smith', 'Canada', 800); INSERT INTO customers (customer_id, name, country, credit_score) VALUES (3, 'Alice Johnson', 'USA', 600);
|
What is the maximum and minimum credit score for customers in each country?
|
SELECT country, MIN(credit_score) as min_credit_score, MAX(credit_score) as max_credit_score FROM customers GROUP BY country;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE fish_inventory (id INT PRIMARY KEY, species VARCHAR(50), quantity INT, location VARCHAR(50)); INSERT INTO fish_inventory (id, species, quantity, location) VALUES (1, 'Salmon', 50, 'Tank A'), (2, 'Tilapia', 75, 'Tank B'), (3, 'Cod', 100, 'Tank C');
|
Determine the number of different fish species available in the 'fish_inventory' table.
|
SELECT COUNT(DISTINCT species) FROM fish_inventory;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE shared_electric_cars (car_id INT, trip_start_time TIMESTAMP, trip_end_time TIMESTAMP, trip_distance FLOAT, city VARCHAR(50));
|
What is the average trip duration for shared electric cars in London?
|
SELECT AVG(TIMESTAMP_DIFF(trip_end_time, trip_start_time, MINUTE)) as avg_duration FROM shared_electric_cars WHERE city = 'London';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE innovation_projects (id INT, project_name VARCHAR(100), location VARCHAR(50), budget DECIMAL(10,2), completion_date DATE); INSERT INTO innovation_projects (id, project_name, location, budget, completion_date) VALUES (1, 'Precision Farming', 'Nepal', 65000.00, '2020-01-01'); INSERT INTO innovation_projects (id, project_name, location, budget, completion_date) VALUES (2, 'Agroforestry Expansion', 'Nepal', 80000.00, '2019-06-15');
|
What is the total budget for agricultural innovation projects in Nepal that were completed after 2018?
|
SELECT SUM(budget) FROM innovation_projects WHERE location = 'Nepal' AND completion_date > '2018-12-31';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE post_likes (like_id INT, post_id INT, user_id INT, like_date DATE); INSERT INTO post_likes (like_id, post_id, user_id, like_date) VALUES (1, 1, 1, '2021-01-01'), (2, 1, 2, '2021-01-02'), (3, 2, 3, '2021-01-03'), (4, 2, 4, '2021-01-04'), (5, 3, 5, '2021-01-05'), (6, 1, 6, '2021-01-06'), (7, 3, 7, '2021-01-07'), (8, 3, 8, '2021-01-08'), (9, 2, 9, '2021-01-09'), (10, 3, 10, '2021-01-10');
|
Get the top 5 most liked posts in the social_media schema's posts table, ordered by the number of likes.
|
SELECT posts.post_id, COUNT(post_likes.like_id) as num_likes FROM posts INNER JOIN post_likes ON posts.post_id = post_likes.post_id GROUP BY posts.post_id ORDER BY num_likes DESC LIMIT 5;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Volunteers (id INT, name TEXT, country TEXT); INSERT INTO Volunteers (id, name, country) VALUES (1, 'Ahmed Al-Saadi', 'Iraq'), (2, 'Minh Nguyen', 'Vietnam'), (3, 'Clara Gomez', 'Colombia'), (4, 'Sofia Ahmed', 'Pakistan'); CREATE TABLE Donors (id INT, name TEXT, country TEXT); INSERT INTO Donors (id, name, country) VALUES (1, 'Jose Garcia', 'Spain'), (2, 'Anna Kuznetsova', 'Russia'), (3, 'Jean-Pierre Dupont', 'France'), (5, 'Lee Seung-Hun', 'South Korea'); CREATE TABLE Programs (id INT, name TEXT, country TEXT); INSERT INTO Programs (id, name, country) VALUES (1, 'Global Literacy', 'USA'), (2, 'Clean Water', 'Mexico'), (3, 'Refugee Support', 'Syria');
|
Find the number of unique volunteers and donors who are from a country not represented in the Programs table.
|
SELECT COUNT(DISTINCT Volunteers.country) + COUNT(DISTINCT Donors.country) - COUNT(DISTINCT Programs.country) as total_unique_countries FROM Volunteers FULL OUTER JOIN Donors ON Volunteers.country = Donors.country FULL OUTER JOIN Programs ON Volunteers.country = Programs.country WHERE Programs.country IS NULL;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE military_sales (id INT, region VARCHAR(20), quarter VARCHAR(10), year INT, cost FLOAT); INSERT INTO military_sales (id, region, quarter, year, cost) VALUES (1, 'Middle East', 'Q2', 2022, 2500000);
|
What is the average cost of military equipment sold in the Middle East in Q2 2022?
|
SELECT AVG(cost) FROM military_sales WHERE region = 'Middle East' AND quarter = 'Q2' AND year = 2022;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Memberships (id INT, member_name TEXT, region TEXT, price DECIMAL(5,2)); INSERT INTO Memberships (id, member_name, region, price) VALUES (1, 'John Doe', 'San Francisco', 50.00); INSERT INTO Memberships (id, member_name, region, price) VALUES (2, 'Jane Smith', 'New York', 75.00);
|
Update the price of the membership for Jane Smith to 80.00.
|
UPDATE Memberships SET price = 80.00 WHERE member_name = 'Jane Smith';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE community_development.schools (id INT, name VARCHAR(50), capacity INT, location VARCHAR(50));
|
What is the average capacity of schools in the 'community_development' schema?
|
SELECT AVG(capacity) FROM community_development.schools;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE sustainable_sourcing (supplier_id INT, supplier_name VARCHAR(255), is_approved BOOLEAN); INSERT INTO sustainable_sourcing (supplier_id, supplier_name, is_approved) VALUES (4, 'Green Vendor', false);
|
Update the is_approved status of 'Green Vendor' in the sustainable_sourcing table.
|
UPDATE sustainable_sourcing SET is_approved = true WHERE supplier_name = 'Green Vendor';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE donors (id INT, name TEXT, region TEXT, donation_amount FLOAT); INSERT INTO donors (id, name, region, donation_amount) VALUES (1, 'John Doe', 'Emerging_Market', 5000.00), (2, 'Jane Smith', 'Emerging_Market', 6000.00);
|
List all records of donors who have donated more than $5000 in the 'emerging_market' region.
|
SELECT * FROM donors WHERE region = 'Emerging_Market' AND donation_amount > 5000;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE tweets (tweet_id INT, user_id INT, tweet_date DATE);CREATE TABLE users (user_id INT, country VARCHAR(50), registration_date DATE);CREATE TABLE country_populations (country VARCHAR(50), population INT);
|
What is the total number of users who have posted a tweet in the past month and who are located in a country with a population of over 100 million?
|
SELECT COUNT(DISTINCT t.user_id) as num_users FROM tweets t JOIN users u ON t.user_id = u.user_id JOIN country_populations cp ON u.country = cp.country WHERE t.tweet_date >= DATE(NOW()) - INTERVAL 1 MONTH AND cp.population > 100000000;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE menu_items (restaurant_id INT, is_sustainable BOOLEAN); INSERT INTO menu_items (restaurant_id, is_sustainable) VALUES (1, TRUE), (1, FALSE), (2, TRUE), (2, TRUE), (3, FALSE), (3, TRUE);
|
What is the percentage of sustainable menu items for each restaurant?
|
SELECT restaurant_id, (COUNT(*) FILTER (WHERE is_sustainable = TRUE) * 100.0 / COUNT(*)) AS percentage FROM menu_items GROUP BY restaurant_id;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE food_safety (id INT PRIMARY KEY, restaurant_id INT, inspection_date DATE, score INT);
|
Delete records in the food_safety table that have an inspection score below 70
|
DELETE FROM food_safety WHERE score < 70;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE sales_data (drug VARCHAR(50), region VARCHAR(50), quarter INT, year INT, revenue FLOAT); INSERT INTO sales_data (drug, region, quarter, year, revenue) VALUES ('DrugC', 'USA', 2, 2020, 6000000);
|
What was the total sales revenue for 'DrugC' in the 'USA' region in Q2 2020?
|
SELECT SUM(revenue) FROM sales_data WHERE drug = 'DrugC' AND region = 'USA' AND quarter = 2 AND year = 2020;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE satellite_image (id INT, field_id INT, image_url TEXT, anomaly BOOLEAN, timestamp TIMESTAMP); CREATE TABLE field (id INT, type VARCHAR(20));
|
Which satellite images have anomalies in the past month for soybean fields?
|
SELECT s.image_url FROM satellite_image s INNER JOIN field f ON s.field_id = f.id WHERE f.type = 'soybean' AND s.anomaly = true AND s.timestamp >= NOW() - INTERVAL '1 month';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE artifacts (id INT, artifact_type VARCHAR(255), material VARCHAR(255), analysis_date DATE);
|
Add records to the 'artifacts' table.
|
INSERT INTO artifacts (id, artifact_type, material, analysis_date) VALUES (1, 'Pottery Shard', 'Clay', '2005-06-01'), (2, 'Bronze Sword', 'Bronze', '1500-01-01');
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Manufacturers (ManufacturerID INT, ManufacturerName TEXT, Region TEXT); INSERT INTO Manufacturers (ManufacturerID, ManufacturerName, Region) VALUES (1, 'ABC Chemicals', 'Asia'), (2, 'XYZ Chemicals', 'North America'), (3, ' DEF Chemicals', 'Asia'); CREATE TABLE ChemicalProducts (ProductID INT, Chemical TEXT, ManufacturerID INT, SafetyScore DECIMAL(3,2)); INSERT INTO ChemicalProducts (ProductID, Chemical, ManufacturerID, SafetyScore) VALUES (1, 'Acetone', 1, 4.2), (2, 'Ethanol', 1, 4.8), (3, 'Methanol', 2, 5.0), (4, 'Propanol', 3, 4.7), (5, 'Butanol', 3, 4.9);
|
Which manufacturers in the Asian region have a safety score above 4.5 for their chemical products?
|
SELECT M.ManufacturerName FROM ChemicalProducts CP INNER JOIN Manufacturers M ON CP.ManufacturerID = M.ManufacturerID WHERE M.Region = 'Asia' AND CP.SafetyScore > 4.5;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE genre_streams (stream_id INT, genre VARCHAR(255), streams INT, stream_date DATE); CREATE VIEW daily_genre_streams AS SELECT genre, DATE_TRUNC('day', stream_date) as date, AVG(streams) as avg_streams FROM genre_streams WHERE stream_date >= DATEADD(day, -30, CURRENT_DATE) GROUP BY genre, date;
|
What is the average number of streams per day, by genre, for the last 30 days?
|
SELECT * FROM daily_genre_streams;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Employees (EmployeeID INT, Gender VARCHAR(10), Department VARCHAR(20), Salary FLOAT, YearsWithCompany INT); INSERT INTO Employees (EmployeeID, Gender, Department, Salary, YearsWithCompany) VALUES (1, 'Male', 'IT', 75000, 6), (2, 'Female', 'IT', 70000, 3), (3, 'Male', 'HR', 60000, 8), (4, 'Female', 'HR', 65000, 2), (5, 'Male', 'IT', 80000, 1);
|
What is the average salary of employees who have been with the company for more than 5 years?
|
SELECT AVG(Salary) FROM Employees WHERE YearsWithCompany > 5;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE harvest_permits (id INT, issue_quarter INT, issued_date DATE);
|
How many timber harvest permits were issued in each quarter of 2019?
|
SELECT EXTRACT(QUARTER FROM issued_date) as quarter, COUNT(*) as num_permits FROM harvest_permits WHERE EXTRACT(YEAR FROM issued_date) = 2019 GROUP BY quarter;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE electric_vehicle_adoption (id INT PRIMARY KEY, country VARCHAR(255), adoption_percentage DECIMAL(5,2));
|
Create a view named 'ev_adoption_stats' based on 'electric_vehicle_adoption' table
|
CREATE VIEW ev_adoption_stats AS SELECT * FROM electric_vehicle_adoption;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE cargo_handling (id INT PRIMARY KEY, cargo_id INT, port VARCHAR(20)); INSERT INTO cargo_handling (id, cargo_id, port) VALUES (1, 101, 'New York'), (2, 102, 'Seattle'), (3, 103, 'Buenos Aires');
|
Delete all records from table cargo_handling with port as 'Seattle'
|
DELETE FROM cargo_handling WHERE port = 'Seattle';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE defendants (defendant_id INT PRIMARY KEY, name VARCHAR(255), age INT, gender VARCHAR(50), race VARCHAR(50), ethnicity VARCHAR(50), date_of_birth DATE, charges VARCHAR(255), case_number INT, case_status VARCHAR(50));
|
Update a defendant record in the 'defendants' table
|
UPDATE defendants SET charges = 'Assault', case_status = 'In Progress' WHERE defendant_id = 2003 AND case_number = 2022001;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE SpyAgencies (id INT PRIMARY KEY, name VARCHAR(50), country VARCHAR(50), year_found INT); INSERT INTO SpyAgencies (id, name, country, year_found) VALUES (1, 'CIA', 'USA', 1947); INSERT INTO SpyAgencies (id, name, country, year_found) VALUES (2, 'MI6', 'UK', 1909);
|
What is the age of each spy agency in each country?
|
SELECT country, MAX(year_found) - MIN(year_found) AS age FROM SpyAgencies GROUP BY country;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE sales (sale_id INT, menu_item_id INT, sale_amount DECIMAL(10, 2), sale_date DATE); INSERT INTO sales VALUES (1, 1, 50.00, '2022-02-01'), (2, 2, 75.00, '2022-03-01'), (3, 3, 60.00, '2022-02-02'), (4, 1, 100.00, '2022-03-02'); CREATE TABLE menu_items (menu_item_id INT, category VARCHAR(255)); INSERT INTO menu_items VALUES (1, 'Entrees'), (2, 'Soups'), (3, 'Salads');
|
Calculate the revenue generated by each category of menu item in the last 30 days.
|
SELECT c1.category, SUM(s1.sale_amount) AS total_revenue FROM sales s1 INNER JOIN menu_items m1 ON s1.menu_item_id = m1.menu_item_id INNER JOIN (SELECT menu_item_id, category FROM menu_items EXCEPT SELECT menu_item_id, category FROM menu_items WHERE menu_item_id NOT IN (SELECT menu_item_id FROM sales)) c1 ON m1.menu_item_id = c1.menu_item_id WHERE s1.sale_date > DATEADD(day, -30, GETDATE()) GROUP BY c1.category;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE product_hazard (product_name VARCHAR(255), hazard_category VARCHAR(255)); INSERT INTO product_hazard (product_name, hazard_category) VALUES ('ProductA', 'Flammable'), ('ProductB', 'Corrosive'), ('ProductC', 'Toxic');
|
What are the product names and their respective hazard categories from the product_hazard table?
|
SELECT product_name, hazard_category FROM product_hazard;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE EconomicImpact (id INT, name TEXT, country TEXT, initiative TEXT); INSERT INTO EconomicImpact (id, name, country, initiative) VALUES (1, 'Barcelona Sustainable Business Program', 'Spain', 'Local Sourcing'), (2, 'Madrid Green Spaces Expansion', 'Spain', 'Community Engagement');
|
Which local economic impact initiatives were implemented in Spain?
|
SELECT DISTINCT initiative FROM EconomicImpact WHERE country = 'Spain';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE cities (city_name VARCHAR(255), population INT, state_abbreviation VARCHAR(255)); INSERT INTO cities (city_name, population, state_abbreviation) VALUES ('CityG', 1800000, 'NY'), ('CityH', 1200000, 'NY'), ('CityI', 2000000, 'NY'); CREATE TABLE schools (school_name VARCHAR(255), city_name VARCHAR(255), annual_budget INT); INSERT INTO schools (school_name, city_name, annual_budget) VALUES ('School6', 'CityG', 900000), ('School7', 'CityG', 1000000), ('School8', 'CityH', 700000), ('School9', 'CityI', 1200000);
|
What is the average annual budget for schools located in cities with a population over 1,500,000 in the state of New York?
|
SELECT AVG(annual_budget) FROM schools INNER JOIN cities ON schools.city_name = cities.city_name WHERE cities.population > 1500000 AND cities.state_abbreviation = 'NY';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE aircraft_manufacturing (id INT PRIMARY KEY, model VARCHAR(100), manufacturing_year INT);
|
Delete all records from the aircraft_manufacturing table where the manufacturing_year is greater than 2020
|
DELETE FROM aircraft_manufacturing WHERE manufacturing_year > 2020;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE GeneticResearch (project_id INT, completion_date DATE, region VARCHAR(10)); INSERT INTO GeneticResearch (project_id, completion_date, region) VALUES (1, '2020-01-01', 'Asia'), (2, '2019-12-31', 'Africa'), (3, '2021-03-15', 'Europe'), (4, '2018-06-20', 'Americas'), (5, '2020-12-27', 'Asia');
|
How many genetic research projects have been completed in Asian countries?
|
SELECT COUNT(project_id) FROM GeneticResearch WHERE region = 'Asia';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE security_incidents (region VARCHAR(255), incident_date DATE); INSERT INTO security_incidents (region, incident_date) VALUES ('North America', '2022-01-01'), ('Europe', '2022-02-01'), ('Asia', '2022-03-01'), ('Asia', '2022-04-01'), ('Africa', '2022-05-01');
|
How many security incidents occurred in each region over the last year?
|
SELECT region, COUNT(*) as incident_count FROM security_incidents WHERE incident_date >= DATEADD(year, -1, CURRENT_DATE) GROUP BY region;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE VolunteerHours (VolunteerID INT, ProgramID INT, Hours DECIMAL(5,2), HourDate DATE); INSERT INTO VolunteerHours (VolunteerID, ProgramID, Hours, HourDate) VALUES (1, 1, 5, '2020-07-15'), (2, 2, 3, '2020-11-02'), (1, 1, 4, '2020-12-31');
|
How many volunteer hours were recorded for each program in H2 2020?
|
SELECT ProgramID, SUM(Hours) as TotalHours FROM VolunteerHours WHERE HourDate BETWEEN '2020-07-01' AND '2020-12-31' GROUP BY ProgramID;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE crew_members (id INT, name VARCHAR(50), nationality VARCHAR(20), position VARCHAR(20), hire_date DATE); INSERT INTO crew_members (id, name, nationality, position, hire_date) VALUES (1, 'John Doe', 'Canadian', 'Captain', '2000-01-01'); INSERT INTO crew_members (id, name, nationality, position, hire_date) VALUES (2, 'Jane Smith', 'Russian', 'Captain', '2005-01-01');
|
Delete records in the 'crew_members' table where the nationality is 'Russian' and the position is 'Captain'
|
DELETE FROM crew_members WHERE nationality = 'Russian' AND position = 'Captain';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE project (id INT PRIMARY KEY, name TEXT, budget INT, status TEXT, city_id INT, FOREIGN KEY (city_id) REFERENCES city(id));
|
What is the minimum budget for a single public works project in the state of California?
|
SELECT MIN(budget) FROM project WHERE city_id IN (SELECT id FROM city WHERE state = 'CA') AND status = 'Open';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE mobile_subscribers (subscriber_id INT, name VARCHAR(50), data_usage FLOAT, call_usage FLOAT, region VARCHAR(50)); INSERT INTO mobile_subscribers (subscriber_id, name, data_usage, call_usage, region) VALUES (1, 'Jane Smith', 500.0, 120.0, 'New York');
|
What is the combined monthly usage of mobile data and calls for subscribers in the New York region, in descending order?
|
SELECT subscriber_id, name, data_usage + call_usage AS total_usage FROM mobile_subscribers WHERE region = 'New York' ORDER BY total_usage DESC;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE autonomous_taxis (taxi_id INT, registration_date TIMESTAMP, taxi_type VARCHAR(50), city VARCHAR(50));
|
What is the percentage of autonomous taxis in Singapore?
|
SELECT COUNT(*) * 100.0 / (SELECT COUNT(*) FROM autonomous_taxis) as pct_autonomous_taxis FROM autonomous_taxis WHERE taxi_type = 'autonomous' AND city = 'Singapore';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE animal_population (id INT PRIMARY KEY, species VARCHAR(255), population INT, year INT);
|
Calculate the average population of each animal species across all years
|
SELECT species, AVG(population) FROM animal_population GROUP BY species;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE social_enterprises (id INT, region VARCHAR(20)); INSERT INTO social_enterprises (id, region) VALUES (1, 'Asia-Pacific'), (2, 'Europe'), (3, 'Asia-Pacific'), (4, 'Americas');
|
How many social enterprises are in the 'Asia-Pacific' region?
|
SELECT COUNT(*) FROM social_enterprises WHERE region = 'Asia-Pacific';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Workouts (WorkoutID INT, WorkoutName VARCHAR(20), Category VARCHAR(10)); INSERT INTO Workouts (WorkoutID, WorkoutName, Category) VALUES (1, 'Treadmill', 'Cardio'), (2, 'Yoga', 'Strength'), (3, 'Cycling', 'Cardio'); CREATE TABLE CaloriesBurned (WorkoutID INT, CaloriesBurned INT); INSERT INTO CaloriesBurned (WorkoutID, CaloriesBurned) VALUES (1, 300), (2, 150), (3, 400);
|
List the names and total calories burned for all workouts in the 'Cardio' category.
|
SELECT Workouts.WorkoutName, SUM(CaloriesBurned) FROM Workouts INNER JOIN CaloriesBurned ON Workouts.WorkoutID = CaloriesBurned.WorkoutID WHERE Workouts.Category = 'Cardio' GROUP BY Workouts.WorkoutName;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE LegalAid (ApplicationID INT, Applicant VARCHAR(20), Community VARCHAR(20), Approval BOOLEAN, SubmissionDate DATE); INSERT INTO LegalAid (ApplicationID, Applicant, Community, Approval, SubmissionDate) VALUES (1, 'John Doe', 'Indigenous', TRUE, '2022-01-10'), (2, 'Jane Smith', 'African American', FALSE, '2022-02-15'), (3, 'Jim Brown', 'Asian', TRUE, '2022-03-05');
|
What is the average number of legal aid applications approved per month for Indigenous communities?
|
SELECT AVG(COUNT(CASE WHEN Approval THEN 1 END)) FROM LegalAid WHERE Community = 'Indigenous' GROUP BY EXTRACT(MONTH FROM SubmissionDate);
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE ngo_projects (id INT PRIMARY KEY, ngo_name TEXT, country TEXT); INSERT INTO ngo_projects (id, ngo_name, country) VALUES (1, 'Medicins Sans Frontieres', 'Syria'); CREATE TABLE ngo_contacts (id INT PRIMARY KEY, ngo_name TEXT, contact_name TEXT); INSERT INTO ngo_contacts (id, ngo_name, contact_name) VALUES (1, 'Medicins Sans Frontieres', 'John Doe');
|
Which NGOs have worked in at least 3 different countries?
|
SELECT ngo_name FROM ngo_projects GROUP BY ngo_name HAVING COUNT(DISTINCT country) >= 3;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE vessel_performance (id INT, vessel_name TEXT, region TEXT, speed DECIMAL(5,2));
|
What is the maximum speed of a vessel in the Pacific region?
|
SELECT MAX(speed) FROM vessel_performance WHERE region = 'Pacific';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE consumer_data (id INT, consumer VARCHAR(20), total_spent DECIMAL(6,2)); INSERT INTO consumer_data (id, consumer, total_spent) VALUES (1, 'Anna', 450.75), (2, 'Bella', 321.65), (3, 'Charlie', 578.30), (4, 'David', 102.50);
|
Show the top 3 consumers and their total spending on ethical_fashion.com.
|
SELECT consumer, SUM(total_spent) as total_spending FROM consumer_data GROUP BY consumer ORDER BY total_spending DESC LIMIT 3;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE explainable_ai_algorithms_scores (algorithm_id INTEGER, complexity_score FLOAT);
|
What is the average explainable_ai_algorithms complexity score?
|
SELECT AVG(complexity_score) FROM explainable_ai_algorithms_scores;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE EquipmentSales (SaleID INT, Contractor VARCHAR(255), EquipmentType VARCHAR(255), Quantity INT, SalePrice DECIMAL(5, 2)); INSERT INTO EquipmentSales (SaleID, Contractor, EquipmentType, Quantity, SalePrice) VALUES (1, 'Contractor Y', 'Helicopter', 5, 5000000);
|
What was the total value of military equipment sales by Contractor Y in Q2 of 2020?
|
SELECT Contractor, SUM(Quantity * SalePrice) FROM EquipmentSales WHERE Contractor = 'Contractor Y' AND Quarter = 'Q2' AND Year = 2020 GROUP BY Contractor;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE veteran_unemployment (unemployment_rate FLOAT, report_date DATE); INSERT INTO veteran_unemployment (unemployment_rate, report_date) VALUES (4.1, '2021-12-01'), (4.3, '2021-11-01'), (4.5, '2021-10-01');
|
What is the average veteran unemployment rate for the last 12 months, rounded to the nearest integer?
|
SELECT ROUND(AVG(unemployment_rate)) FROM veteran_unemployment WHERE report_date >= DATE_SUB(CURRENT_DATE, INTERVAL 12 MONTH);
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE SpaceExploration (mission_id INT, launch_cost INT, spacecraft VARCHAR(50));
|
What is the average launch cost for SpaceX missions?
|
SELECT AVG(launch_cost) FROM SpaceExploration WHERE spacecraft = 'SpaceX';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Transactions (TransactionID INT, TransactionDate DATE, Amount DECIMAL(10,2)); INSERT INTO Transactions (TransactionID, TransactionDate, Amount) VALUES (1, '2022-01-01', 500.00), (2, '2022-01-02', 250.00), (3, '2022-01-03', 750.00), (4, '2022-01-04', 1500.00), (5, '2022-01-05', 200.00), (6, '2022-01-06', 300.00);
|
Calculate the moving average of transaction amounts for the last 3 days.
|
SELECT TransactionDate, AVG(Amount) OVER (ORDER BY TransactionDate ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) as MovingAverage FROM Transactions;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE attorneys (id INT, name VARCHAR(50), cases_handled INT, region VARCHAR(50), billable_rate DECIMAL(10,2)); INSERT INTO attorneys (id, name, cases_handled, region, billable_rate) VALUES (1, 'John Lee', 40, 'Northeast', 200.00); INSERT INTO attorneys (id, name, cases_handled, region, billable_rate) VALUES (2, 'Jane Doe', 50, 'Southwest', 250.00);
|
Determine the average billing rate per region
|
SELECT region, AVG(billable_rate) as avg_billing_rate FROM attorneys GROUP BY region;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE users (id INT, smartwatch BOOLEAN, fitness_goal VARCHAR(50)); INSERT INTO users (id, smartwatch, fitness_goal) VALUES (1, TRUE, 'weight loss'), (2, FALSE, 'muscle gain'), (3, TRUE, 'weight loss'), (4, FALSE, 'flexibility'), (5, TRUE, 'muscle gain');
|
What is the number of users who own a smartwatch, grouped by their fitness goal?
|
SELECT fitness_goal, COUNT(*) as num_users FROM users WHERE smartwatch = TRUE GROUP BY fitness_goal;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE hockey_teams (team_id INT, team_name VARCHAR(30), goals INT);
|
Show the total number of goals scored by the 'hockey_teams' table in descending order.
|
SELECT team_name, SUM(goals) as total_goals FROM hockey_teams GROUP BY team_name ORDER BY total_goals DESC;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE songs (id INT, title TEXT, length FLOAT, genre TEXT, release_year INT); INSERT INTO songs (id, title, length, genre, release_year) VALUES (1, 'Song1', 245.6, 'Pop', 2019), (2, 'Song2', 189.3, 'Rock', 2020), (3, 'Song3', 215.9, 'Pop', 2018), (4, 'Song4', 150.2, 'Hip Hop', 2020), (5, 'Song5', 120.0, 'Hip Hop', 2019), (6, 'Song6', 360.0, 'Jazz', 2018), (7, 'Song7', 200.0, 'Country', 2020), (8, 'Song8', 220.0, 'Country', 2021), (9, 'Song9', 400.0, 'Classical', 2020), (10, 'Song10', 300.0, 'Classical', 2020);
|
What is the average length (in seconds) of all classical songs released in 2020?
|
SELECT AVG(length) FROM songs WHERE genre = 'Classical' AND release_year = 2020;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE art_classes (id INT, attendee_id INT, class_month DATE);INSERT INTO art_classes (id, attendee_id, class_month) VALUES (1, 101, '2021-01-01'), (2, 102, '2021-02-01'), (3, 103, '2021-01-01');
|
Find the number of new attendees by month for art classes in 2021
|
SELECT EXTRACT(MONTH FROM class_month) AS month, COUNT(DISTINCT attendee_id) AS new_attendees FROM art_classes WHERE EXTRACT(YEAR FROM class_month) = 2021 GROUP BY month ORDER BY month;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Students (StudentID INT, FirstName VARCHAR(20), LastName VARCHAR(20), NumberOfPublications INT);
|
Find the number of students who have not published any papers.
|
SELECT COUNT(*) FROM Students WHERE NumberOfPublications = 0;
|
gretelai_synthetic_text_to_sql
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.