context
stringlengths 11
9.12k
| question
stringlengths 0
1.06k
| SQL
stringlengths 2
4.44k
| source
stringclasses 28
values |
|---|---|---|---|
CREATE TABLE sids_projects (project_id INT, project_name TEXT, location TEXT, funding_amount DECIMAL(10,2), funder TEXT, commitment_date DATE);
|
What is the total amount of climate finance committed to projects in Small Island Developing States (SIDS) in the Pacific region?
|
SELECT SUM(funding_amount) FROM sids_projects WHERE location LIKE '%Pacific%' AND funder LIKE '%Climate Finance%' AND location IN (SELECT location FROM sids WHERE sids.region = 'Small Island Developing States');
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Household (ID INT, City VARCHAR(20), Consumption FLOAT); INSERT INTO Household (ID, City, Consumption) VALUES (1, 'NYC', 12.3), (2, 'NYC', 13.8), (3, 'NYC', 11.5), (4, 'Seattle', 10.5);
|
What is the percentage of households in the city of NYC that consume more than 12 gallons of water per day?
|
SELECT (COUNT(*) * 100.0 / (SELECT COUNT(*) FROM Household WHERE City = 'NYC')) FROM Household WHERE City = 'NYC' AND Consumption > 12;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE user_workouts_feb (id INT, user_id INT, activity VARCHAR(50), duration INT, timestamp TIMESTAMP); INSERT INTO user_workouts_feb (id, user_id, activity, duration, timestamp) VALUES (1, 1001, 'running', 30, '2022-02-01 10:00:00'); INSERT INTO user_workouts_feb (id, user_id, activity, duration, timestamp) VALUES (2, 1002, 'swimming', 45, '2022-02-01 11:30:00'); INSERT INTO user_workouts_feb (id, user_id, activity, duration, timestamp) VALUES (3, 1003, 'yoga', 60, '2022-02-02 09:00:00');
|
Find the top 3 most popular workout activities in the month of February 2022.
|
SELECT activity, COUNT(*) as count FROM user_workouts_feb WHERE EXTRACT(MONTH FROM timestamp) = 2 GROUP BY activity ORDER BY count DESC LIMIT 3;
|
gretelai_synthetic_text_to_sql
|
CREATE SCHEMA Aerospace;CREATE TABLE Aerospace.AircraftManufacturing (manufacturer VARCHAR(50), country VARCHAR(50), delivery_time INT, mission_result VARCHAR(10));INSERT INTO Aerospace.AircraftManufacturing (manufacturer, country, delivery_time, mission_result) VALUES ('Boeing', 'USA', 20, 'Success'), ('Airbus', 'Europe', 25, 'Failure'), ('Comac', 'China', 35, 'Success'), ('Mitsubishi', 'Japan', 15, 'Success');
|
What is the average delivery time for aircraft by manufacturer, considering only successful missions?
|
SELECT manufacturer, AVG(delivery_time) AS avg_delivery_time FROM Aerospace.AircraftManufacturing WHERE mission_result = 'Success' GROUP BY manufacturer;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE crimes (id INT, date DATE, division VARCHAR(10)); INSERT INTO crimes (id, date, division) VALUES (1, '2022-01-01', 'south'), (2, '2022-01-02', 'south'), (3, '2022-01-03', 'north'); INSERT INTO crimes (id, date, division) VALUES (4, '2022-01-04', 'south'), (5, '2022-01-05', 'south'), (6, '2022-01-06', 'north');
|
What is the maximum number of crimes committed in a single day in the 'south' division?
|
SELECT MAX(count) FROM (SELECT date, COUNT(*) AS count FROM crimes WHERE division = 'south' GROUP BY date) AS subquery;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE academic_publications (id INT, author_name TEXT, author_gender TEXT, department TEXT, publication_date DATE); INSERT INTO academic_publications (id, author_name, author_gender, department, publication_date) VALUES (1, 'Grace', 'F', 'Humanities', '2021-05-01'); INSERT INTO academic_publications (id, author_name, author_gender, department, publication_date) VALUES (2, 'Hugo', 'M', 'Engineering', '2022-09-15');
|
What is the total number of academic publications by female authors in the humanities department?
|
SELECT COUNT(*) FROM academic_publications WHERE author_gender = 'F' AND department = 'Humanities'
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE BoeingSales (equipment_type TEXT, quantity INT, year INT); INSERT INTO BoeingSales VALUES ('F-15', 20, 2020); INSERT INTO BoeingSales VALUES ('Chinook', 5, 2020); CREATE TABLE GeneralAtomicsSales (country TEXT, quantity INT, year INT); INSERT INTO GeneralAtomicsSales VALUES ('United States', 40, 2020); INSERT INTO GeneralAtomicsSales VALUES ('Italy', 5, 2020);
|
Determine the difference in the number of military equipment sold by Boeing and General Atomics in 2020.
|
SELECT BoeingSales.quantity - GeneralAtomicsSales.quantity AS Difference
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE wells (id INT, name VARCHAR(255), location VARCHAR(255), owner VARCHAR(255), production_quantity INT); INSERT INTO wells (id, name, location, owner, production_quantity) VALUES (1, 'Well A', 'North Sea', 'Acme Oil', 1000), (2, 'Well B', 'Gulf of Mexico', 'Big Oil', 2000), (3, 'Well C', 'North Sea', 'Acme Oil', 1500), (4, 'Well D', 'North Sea', 'Big Oil', 2500), (5, 'Well E', 'North Sea', 'Big Oil', 3000);
|
What is the maximum production quantity for wells owned by 'Big Oil' and located in the 'North Sea'?
|
SELECT MAX(production_quantity) FROM wells WHERE location = 'North Sea' AND owner = 'Big Oil';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE climate_finance (year INT, region VARCHAR(50), initiative VARCHAR(50), amount FLOAT); INSERT INTO climate_finance (year, region, initiative, amount) VALUES (2020, 'Asia Pacific', 'climate mitigation', 12000000);
|
What is the total amount of climate finance provided to countries in the Asia Pacific region for climate mitigation initiatives in the year 2020?
|
SELECT SUM(amount) FROM climate_finance WHERE year = 2020 AND region = 'Asia Pacific' AND initiative = 'climate mitigation';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE workforce_development_programs (id INT, name VARCHAR(255), manufacturer_id INT, program_type VARCHAR(255)); INSERT INTO workforce_development_programs (id, name, manufacturer_id, program_type) VALUES (1, 'Apprenticeship Program', 1, 'Skills Training'); CREATE TABLE manufacturers (id INT, name VARCHAR(255), location VARCHAR(255), employee_count INT); INSERT INTO manufacturers (id, name, location, employee_count) VALUES (1, 'Manufacturer X', 'Sydney', 500);
|
What are the skills training programs and their corresponding manufacturer names?
|
SELECT wdp.name, m.name AS manufacturer_name FROM workforce_development_programs wdp INNER JOIN manufacturers m ON wdp.manufacturer_id = m.id WHERE wdp.program_type = 'Skills Training';
|
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 average CO2 emission in the 'environmental_impact' table for the years 2018 and 2019?
|
SELECT AVG(co2_emission) FROM environmental_impact WHERE year IN (2018, 2019);
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE DisasterEvents (event_id INT, event_year INT, event_location VARCHAR(50), event_organizer VARCHAR(50)); INSERT INTO DisasterEvents (event_id, event_year, event_location, event_organizer) VALUES (1, 2021, 'India', 'Non-Profit A'), (2, 2020, 'Indonesia', 'Non-Profit B'), (3, 2021, 'Philippines', 'Government Agency C');
|
How many disaster response events were organized by non-profit organizations in Asia in 2021?
|
SELECT COUNT(*) FROM DisasterEvents WHERE event_year = 2021 AND event_location LIKE 'Asia%' AND event_organizer LIKE 'Non-Profit%';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE IF NOT EXISTS decentralized_applications (dapp_id INT PRIMARY KEY, name VARCHAR(100), tx_id INT, category VARCHAR(50), blockchain VARCHAR(50), FOREIGN KEY (tx_id) REFERENCES blockchain_transactions(tx_id)); CREATE TABLE IF NOT EXISTS blockchain_transactions (tx_id INT PRIMARY KEY, blockchain VARCHAR(50)); INSERT INTO blockchain_transactions (tx_id, blockchain) VALUES (1, 'Binance Smart Chain');
|
What are the names and categories of the decentralized applications that have been deployed on the Binance Smart Chain and have had the most number of transactions?
|
SELECT dapp_name, category, COUNT(dapp_id) FROM decentralized_applications da JOIN blockchain_transactions bt ON da.tx_id = bt.tx_id WHERE bt.blockchain = 'Binance Smart Chain' GROUP BY dapp_name, category ORDER BY COUNT(dapp_id) DESC LIMIT 10;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE production_data (id INT PRIMARY KEY, mine_id INT, year INT, monthly_production INT);
|
What is the annual production volume trend for the mine with the ID 'mine001'?
|
SELECT year, AVG(monthly_production) as annual_production FROM production_data WHERE mine_id = 'mine001' GROUP BY year;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE workers (id INT, name VARCHAR(50), industry VARCHAR(50), salary FLOAT, state VARCHAR(50)); INSERT INTO workers (id, name, industry, salary, state) VALUES (1, 'John Doe', 'oil', 45000, 'Texas'); INSERT INTO workers (id, name, industry, salary, state) VALUES (2, 'Jane Smith', 'oil', 60000, 'Texas'); INSERT INTO workers (id, name, industry, salary, state) VALUES (3, 'Mike Johnson', 'coal', 70000, 'Texas');
|
Delete records of workers who earn less than $50,000 in the 'oil' industry in Texas, USA.
|
DELETE FROM workers WHERE industry = 'oil' AND salary < 50000 AND state = 'Texas';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE hotel_carbon_footprint(hotel_id INT, hotel_name TEXT, country TEXT, is_sustainable BOOLEAN, carbon_footprint INT); INSERT INTO hotel_carbon_footprint (hotel_id, hotel_name, country, is_sustainable, carbon_footprint) VALUES (1, 'Eco Hotel', 'South Africa', true, 40), (2, 'Luxury Resort', 'South Africa', false, 100), (3, 'Green Hotel', 'South Africa', true, 50);
|
Which sustainable hotels in South Africa have the lowest carbon footprint?
|
SELECT hotel_name, carbon_footprint FROM hotel_carbon_footprint WHERE country = 'South Africa' AND is_sustainable = true ORDER BY carbon_footprint ASC;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE energy_storage_facilities (id INT, name VARCHAR(255), state VARCHAR(50)); INSERT INTO energy_storage_facilities (id, name, state) VALUES (1, 'Facility A', 'California'), (2, 'Facility B', 'Texas'), (3, 'Facility C', 'California'), (4, 'Facility D', 'New York');
|
How many energy storage facilities are there in California, Texas, and New York, and what are their names?
|
SELECT e.state, COUNT(*), e.name FROM energy_storage_facilities e WHERE e.state IN ('California', 'Texas', 'New York') GROUP BY e.state, e.name;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE CARGO (ID INT, VESSEL_ID INT, CARGO_NAME VARCHAR(50), WEIGHT INT);
|
Delete records of cargo with a weight over 10000 tons from the CARGO table
|
DELETE FROM CARGO WHERE WEIGHT > 10000;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE FarmF (country VARCHAR(20), species VARCHAR(20), biomass FLOAT); INSERT INTO FarmF (country, species, biomass) VALUES ('Norway', 'Salmon', 5000); INSERT INTO FarmF (country, species, biomass) VALUES ('Norway', 'Cod', 3000); INSERT INTO FarmF (country, species, biomass) VALUES ('Scotland', 'Herring', 2000); INSERT INTO FarmF (country, species, biomass) VALUES ('Scotland', 'Mackerel', 1000); INSERT INTO FarmF (country, species, biomass) VALUES ('Canada', 'Halibut', 4000);
|
What is the average biomass of fish farmed in each country, excluding fish from Norway?
|
SELECT country, AVG(biomass) FROM FarmF WHERE country != 'Norway' GROUP BY country;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Production_Processes (id INT, process VARCHAR(255)); INSERT INTO Production_Processes (id, process) VALUES (1, 'Dyeing'), (2, 'Cutting'), (3, 'Sewing'), (4, 'Finishing'); CREATE TABLE Water_Consumption (id INT, process_id INT, year INT, consumption INT); INSERT INTO Water_Consumption (id, process_id, year, consumption) VALUES (1, 1, 2022, 5000), (2, 2, 2022, 4000), (3, 3, 2022, 3000), (4, 4, 2022, 2000);
|
What is the total water consumption for each production process in 2022?
|
SELECT p.process, SUM(w.consumption) FROM Water_Consumption w JOIN Production_Processes p ON w.process_id = p.id WHERE w.year = 2022 GROUP BY p.process;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Donations (DonationID int, DonorID int, Cause text, DonationAmount numeric); INSERT INTO Donations VALUES (1, 1, 'Education', 500); INSERT INTO Donations VALUES (2, 2, 'Health', 1000);
|
What's the sum of donations for education causes?
|
SELECT SUM(DonationAmount) FROM Donations WHERE Cause = 'Education';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE ocean_depths (ocean VARCHAR(50), depth FLOAT); INSERT INTO ocean_depths (ocean, depth) VALUES ('Mariana Trench', 10994), ('Tonga Trench', 10882), ('Kermadec Trench', 10047), ('Java Trench', 8047), ('Samoa Trench', 7999);
|
What is the maximum ocean depth recorded?
|
SELECT MAX(depth) FROM ocean_depths;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE graduate_students (student_id INT, dept_name VARCHAR(50)); CREATE TABLE publications (publication_id INT, student_id INT, pub_date DATE);
|
How many graduate students have published in academic journals in the past year, and what is the distribution of publications by department?
|
SELECT g.dept_name, COUNT(p.publication_id) as num_publications FROM graduate_students g INNER JOIN publications p ON g.student_id = p.student_id WHERE p.pub_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 1 YEAR) GROUP BY g.dept_name;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE media_content (id INT, country VARCHAR(50), genre VARCHAR(50), frequency INT); INSERT INTO media_content (id, country, genre, frequency) VALUES (1, 'USA', 'Movie', 100), (2, 'Canada', 'Movie', 20), (3, 'Mexico', 'TV Show', 30);
|
Which countries have the least media representation in the media_content table?
|
SELECT country, frequency FROM media_content ORDER BY frequency LIMIT 1;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE australian_hospitals (id INT, hospital_name VARCHAR(50), hospital_type VARCHAR(50), num_beds INT, ownership VARCHAR(50)); INSERT INTO australian_hospitals (id, hospital_name, hospital_type, num_beds, ownership) VALUES (1, 'Hospital A', 'Public', 500, 'Public');
|
What is the total number of hospital beds by ownership in Australia?
|
SELECT ownership, SUM(num_beds) as total_beds FROM australian_hospitals GROUP BY ownership;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE City (CityName VARCHAR(50), Country VARCHAR(50), Population INT); INSERT INTO City (CityName, Country, Population) VALUES ('New York', 'USA', 8500000), ('Los Angeles', 'USA', 4000000), ('Tokyo', 'Japan', 9000000), ('Delhi', 'India', 19000000);
|
What is the total population of cities with a population over 1 million?
|
SELECT SUM(Population) FROM City WHERE Population > 1000000;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE stores (id INT, name TEXT, location TEXT, certified_organic BOOLEAN); INSERT INTO stores (id, name, location, certified_organic) VALUES (1, 'Eco-Market', 'San Francisco', true); INSERT INTO stores (id, name, location, certified_organic) VALUES (2, 'Farm Fresh', 'Los Angeles', false);
|
Which stores in the stores table have an 'organic' certification?
|
SELECT name FROM stores WHERE certified_organic = true;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE ca_workplaces (id INT, name TEXT, country TEXT, workplace_safety BOOLEAN); INSERT INTO ca_workplaces (id, name, country, workplace_safety) VALUES (1, 'Workplace D', 'Canada', true), (2, 'Workplace E', 'Canada', true), (3, 'Workplace F', 'Canada', false);
|
List all the workplaces in Canada that have implemented workplace safety measures.
|
SELECT name FROM ca_workplaces WHERE workplace_safety = true;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE WeatherData (location VARCHAR(50), year INT, avg_temp FLOAT);
|
What's the average temperature change in South America between 1950 and 2000, and how does it compare to the global average temperature change during the same period?
|
SELECT w1.avg_temp - w2.avg_temp AS temp_diff FROM (SELECT AVG(avg_temp) FROM WeatherData WHERE location LIKE 'South America%' AND year BETWEEN 1950 AND 2000) w1, (SELECT AVG(avg_temp) FROM WeatherData WHERE year BETWEEN 1950 AND 2000) w2;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE recycling_rates (country VARCHAR(255), recycling_rate FLOAT); INSERT INTO recycling_rates (country, recycling_rate) VALUES ('South Africa', 0.36), ('Egypt', 0.22), ('Nigeria', 0.15);
|
What is the average recycling rate for Africa?
|
SELECT AVG(recycling_rate) FROM recycling_rates WHERE country IN ('South Africa', 'Egypt', 'Nigeria');
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE defense_diplomacy (country VARCHAR(50), year INT, event VARCHAR(50)); INSERT INTO defense_diplomacy (country, year, event) VALUES ('Japan', 2015, 'G7 Defense Ministerial'); INSERT INTO defense_diplomacy (country, year, event) VALUES ('Japan', 2016, 'Japan-US Defense Ministerial'); INSERT INTO defense_diplomacy (country, year, event) VALUES ('Japan', 2017, 'Japan-India Defense Ministerial'); INSERT INTO defense_diplomacy (country, year, event) VALUES ('Canada', 2015, 'NATO Defense Ministerial'); INSERT INTO defense_diplomacy (country, year, event) VALUES ('Canada', 2016, 'Canada-UK Defense Ministerial'); INSERT INTO defense_diplomacy (country, year, event) VALUES ('Canada', 2017, 'Canada-France Defense Ministerial');
|
Which defense diplomacy events involved Japan and Canada from 2015 to 2017?
|
SELECT country, GROUP_CONCAT(event) as events FROM defense_diplomacy WHERE (country = 'Japan' OR country = 'Canada') AND (year BETWEEN 2015 AND 2017) GROUP BY country;
|
gretelai_synthetic_text_to_sql
|
CREATE VIEW contract_summary AS SELECT company_name, COUNT(*) AS total_contracts, SUM(contract_value) AS total_value FROM contract_negotiations JOIN contract ON contract_negotiations.contract_id = contract.id GROUP BY company_name;
|
Create a view named 'contract_summary' with columns 'company_name', 'total_contracts', 'total_value
|
CREATE VIEW contract_summary AS SELECT company_name, COUNT(*) AS total_contracts, SUM(contract_value) AS total_value FROM contract_negotiations JOIN contract ON contract_negotiations.contract_id = contract.id GROUP BY company_name;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE users (user_id INT, user_location VARCHAR(30)); CREATE TABLE transactions (transaction_id INT, user_id INT, transaction_value FLOAT, transaction_date DATE); INSERT INTO users (user_id, user_location) VALUES (1, 'Rural'); INSERT INTO transactions (transaction_id, user_id, transaction_value, transaction_date) VALUES (1, 1, 100.00, '2021-06-01');
|
Identify users from rural areas with more than 3 transactions in the month of June 2021, and rank them by transaction value.
|
SELECT user_id, RANK() OVER (ORDER BY SUM(transaction_value) DESC) as rank FROM transactions INNER JOIN users ON transactions.user_id = users.user_id WHERE EXTRACT(MONTH FROM transaction_date) = 6 AND user_location = 'Rural' GROUP BY user_id HAVING COUNT(*) > 3;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE organizations_fairness (org_id INT, fairness_score FLOAT); INSERT INTO organizations_fairness (org_id, fairness_score) VALUES (1, 0.85), (2, 0.92), (3, 0.88), (4, 0.7), (5, 0.95);
|
Which organizations have developed models with a fairness score greater than 0.9?
|
SELECT org_id FROM organizations_fairness WHERE fairness_score > 0.9;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Fleets (id INT, name VARCHAR(255)); INSERT INTO Fleets (id, name) VALUES (1, 'Eco-friendly'); CREATE TABLE Vessels (id INT, name VARCHAR(255), fleet_id INT); INSERT INTO Vessels (id, name, fleet_id) VALUES (1, 'Eco Warrior', 1);
|
Add a new vessel 'Sea Turtle' to the 'Eco-friendly' fleet.
|
INSERT INTO Vessels (id, name, fleet_id) SELECT 2, 'Sea Turtle', id FROM Fleets WHERE name = 'Eco-friendly';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE service_requests (id INT, request_type VARCHAR(255), request_date DATE); INSERT INTO service_requests (id, request_type, request_date) VALUES (1, 'Road Repair', '2022-01-01'), (2, 'Waste Collection', '2022-02-01'), (3, 'Street Lighting', '2022-01-15');
|
What is the number of public service requests received in 2022, grouped by request type, in the 'service_requests' table?
|
SELECT request_type, COUNT(*) FROM service_requests WHERE YEAR(request_date) = 2022 GROUP BY request_type;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE if not exists vehicle_types (vehicle_type varchar(20)); INSERT INTO vehicle_types (vehicle_type) VALUES ('autonomous'), ('manual'); CREATE TABLE if not exists adoption_rates (vehicle_type varchar(20), city varchar(20), adoption_rate float); INSERT INTO adoption_rates (vehicle_type, city, adoption_rate) VALUES ('autonomous', 'mumbai', 25.6), ('manual', 'mumbai', 74.1);
|
Update all autonomous vehicle records in 'mumbai' with a new adoption rate of 28.5
|
UPDATE adoption_rates SET adoption_rate = 28.5 WHERE vehicle_type = 'autonomous' AND city = 'mumbai';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE polygon_defi (protocol_name VARCHAR(50), tvl DECIMAL(18,2));
|
What is the current total value locked in DeFi protocols on the Polygon network?
|
SELECT SUM(tvl) FROM polygon_defi WHERE protocol_name = 'Aave';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE taxis (id INT, city TEXT, vehicle_type TEXT, fuel_type TEXT, total_taxis INT); INSERT INTO taxis (id, city, vehicle_type, fuel_type, total_taxis) VALUES (1, 'San Francisco', 'Taxi', 'Autonomous', 100), (2, 'New York', 'Taxi', 'Gasoline', 800), (3, 'Los Angeles', 'Taxi', 'Autonomous', 150);
|
What is the average number of autonomous taxis in the taxis table for each city?
|
SELECT city, AVG(total_taxis) as avg_autonomous_taxis FROM taxis WHERE vehicle_type = 'Taxi' AND fuel_type = 'Autonomous' GROUP BY city;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE users (id INT, user_id INT); INSERT INTO users (id, user_id) VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5); CREATE TABLE posts (id INT, user_id INT, post_date DATE); INSERT INTO posts (id, user_id, post_date) VALUES (1, 1, '2022-01-01'), (2, 2, '2022-01-02'), (3, 1, '2022-01-03'), (4, 2, '2022-01-04'), (5, 3, '2022-01-05'), (6, 3, '2022-01-05'), (7, 1, '2022-01-06'), (8, 2, '2022-01-07'), (9, 4, '2022-01-08'), (10, 5, '2022-01-09'), (11, 1, '2022-01-10'), (12, 2, '2022-01-11');
|
Which users have posted the most in the last 3 days?
|
SELECT user_id, COUNT(*) AS num_posts FROM posts WHERE post_date >= DATEADD(day, -3, GETDATE()) GROUP BY user_id ORDER BY num_posts DESC;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Donations (id INT, department VARCHAR(20), amount FLOAT); INSERT INTO Donations (id, department, amount) VALUES (1, 'Animals', 500.00), (2, 'Education', 300.00);
|
What is the average donation amount in the 'Donations' table?
|
SELECT AVG(amount) FROM Donations
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE waste_generation(region VARCHAR(50), waste FLOAT); INSERT INTO waste_generation(region, waste) VALUES('RegionA', 12.5), ('RegionB', 15.8), ('RegionC', 18.3);
|
What is the total quantity (in metric tons) of textile waste generated in each region?
|
SELECT region, SUM(waste) FROM waste_generation GROUP BY region;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE clients (client_id INT, name VARCHAR(50), investment FLOAT); CREATE TABLE fund_investments (client_id INT, fund_name VARCHAR(50), investment FLOAT);
|
What is the total investment of all clients in the "US Equity" fund?
|
SELECT SUM(investment) FROM clients INNER JOIN fund_investments ON clients.client_id = fund_investments.client_id WHERE fund_investments.fund_name = 'US Equity';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE cruelty_free_certification (certification_id INT PRIMARY KEY, product_id INT, certification_date DATE, certification_authority TEXT);
|
Create a table to store cruelty-free certification information
|
CREATE TABLE cruelty_free_certification (certification_id INT PRIMARY KEY, product_id INT, certification_date DATE, certification_authority TEXT);
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE healthcare_facilities (id INT, name TEXT, location TEXT, type TEXT); INSERT INTO healthcare_facilities (id, name, location, type) VALUES (1, 'Hospital A', 'rural', 'hospital'); INSERT INTO healthcare_facilities (id, name, location, type) VALUES (2, 'Clinic A', 'rural', 'clinic'); INSERT INTO healthcare_facilities (id, name, location, type) VALUES (3, 'Pharmacy A', 'rural', 'pharmacy');
|
List the unique types of healthcare facilities in 'rural' areas, excluding pharmacies.
|
SELECT DISTINCT type FROM healthcare_facilities WHERE location = 'rural' AND type != 'pharmacy';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE renewable_energy (country VARCHAR(255), year INT, energy_produced FLOAT); INSERT INTO renewable_energy (country, year, energy_produced) VALUES ('United States', 2020, 456.78);
|
What is the total energy produced by wind power in the United States for the year 2020?
|
SELECT SUM(energy_produced) FROM renewable_energy WHERE country = 'United States' AND energy_type = 'Wind' AND year = 2020;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Astronauts (AstronautID INT, Age INT, HasSpacewalked BOOLEAN);
|
What is the average age of all astronauts who have been on a spacewalk?
|
SELECT AVG(Age) FROM Astronauts WHERE HasSpacewalked = TRUE;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE spanish_movies (id INT PRIMARY KEY, name VARCHAR(255), release_year INT, revenue INT); INSERT INTO spanish_movies (id, name, release_year, revenue) VALUES (1, 'Dolor y Gloria', 2022, 12000000), (2, 'Mientras Dure la Guerra', 2022, 9000000), (3, 'La Trinchera Infinita', 2022, 10000000);
|
What is the total revenue generated by Spanish movies released in 2022?
|
SELECT SUM(revenue) FROM spanish_movies WHERE release_year = 2022;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE indigenous_composition (id INT, country VARCHAR(50), population INT, indigenous INT); INSERT INTO indigenous_composition (id, country, population, indigenous) VALUES (1, 'Australia', 25368000, 798200);
|
What is the percentage of the population that is Indigenous in Australia?
|
SELECT (indigenous * 100.0 / population) FROM indigenous_composition WHERE country = 'Australia';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Jobs (Quarter INT, Sector VARCHAR(255), Openings INT); INSERT INTO Jobs (Quarter, Sector, Openings) VALUES (1, 'IT', 1000), (1, 'Finance', 800), (2, 'IT', 1200), (2, 'Finance', 900);
|
What is the total number of job openings in the IT sector in the last quarter?
|
SELECT SUM(Openings) FROM Jobs WHERE Quarter IN (3, 4) AND Sector = 'IT';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE products (product_id INT, product_name VARCHAR(255), brand VARCHAR(255), price DECIMAL(10, 2)); INSERT INTO products VALUES (1, 'ProductA', 'BrandX', 50), (2, 'ProductB', 'BrandX', 75), (3, 'ProductC', 'BrandY', 60);
|
List all brands that have products with a price higher than the average product price.
|
SELECT brand FROM products WHERE price > (SELECT AVG(price) FROM products);
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE forests (id INT, country VARCHAR(50), volume FLOAT); INSERT INTO forests (id, country, volume) VALUES (1, 'Indonesia', 1200.5), (2, 'Brazil', 1500.3), (3, 'Canada', 800.2), (4, 'Russia', 900.1), (5, 'United States', 1000.0);
|
What is the total volume of timber harvested in forests in each country?
|
SELECT country, SUM(volume) FROM forests GROUP BY country;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE permits (company VARCHAR(255), region VARCHAR(255), permit_number INT);
|
Show unique drilling permits issued to DEF Oil & Gas in the Gulf of Mexico.
|
SELECT DISTINCT permit_number FROM permits WHERE company = 'DEF Oil & Gas' AND region = 'Gulf of Mexico';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Donations (DonationID INT, DonorID INT, DonationDate DATE, DonationAmount DECIMAL(10,2), DonationCategory VARCHAR(50)); CREATE TABLE Donors (DonorID INT, DonorName VARCHAR(50), DonorType VARCHAR(50));
|
Who are the top 3 donors by average donation amount in the Education category?
|
SELECT DonorName, AVG(DonationAmount) FROM Donations d JOIN Donors don ON d.DonorID = don.DonorID WHERE DonationCategory = 'Education' GROUP BY DonorID, DonorName ORDER BY AVG(DonationAmount) DESC FETCH NEXT 3 ROWS ONLY;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Ingredients (product_id INT, ingredient TEXT); INSERT INTO Ingredients (product_id, ingredient) VALUES (1, 'aloe vera'), (2, 'almond oil'), (3, 'coconut oil'), (4, 'aloe vera'), (5, 'lavender');
|
List the top 3 most purchased beauty products that contain 'aloe vera' as an ingredient and are vegan-friendly.
|
SELECT product_id, ingredient FROM Ingredients WHERE ingredient = 'aloe vera' INTERSECT SELECT product_id FROM Products WHERE is_vegan = true LIMIT 3;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE electric_vehicles (vehicle_id INT, vehicle_model VARCHAR(50), total_sold INT, city VARCHAR(50)); INSERT INTO electric_vehicles (vehicle_id, vehicle_model, total_sold, city) VALUES (1, 'Zonda Electric', 1500, 'Cape Town'), (2, 'Rimac Nevera', 1000, 'Cape Town');
|
Which electric vehicle models have the highest sales in Cape Town?
|
SELECT vehicle_model, SUM(total_sold) FROM electric_vehicles WHERE city = 'Cape Town' GROUP BY vehicle_model ORDER BY SUM(total_sold) DESC;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE denver_prop(id INT, owner1 VARCHAR(20), owner2 VARCHAR(20), market_value INT); INSERT INTO denver_prop VALUES (1, 'Eve', 'Frank', 550000), (2, 'Grace', 'Hal', 450000);
|
Identify the co-owners of properties in Denver with a market value above $500,000.
|
SELECT owner1, owner2 FROM denver_prop WHERE market_value > 500000 AND (owner1 <> owner2);
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE military_equipment (equipment_id INT PRIMARY KEY, equipment_type VARCHAR(50), manufactured_year INT, quantity INT, country VARCHAR(50));
|
Delete records in the 'military_equipment' table where the 'equipment_type' is 'Artillery' and 'manufactured_year' is before 2000
|
DELETE FROM military_equipment WHERE equipment_type = 'Artillery' AND manufactured_year < 2000;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE bookings (booking_id INT, booking_date DATE, revenue DECIMAL(10,2)); INSERT INTO bookings (booking_id, booking_date, revenue) VALUES (1, '2022-08-01', 100), (2, '2022-08-02', 200), (3, '2022-08-03', 300);
|
What is the total revenue per day for the 'bookings' table in the month of August 2022?
|
SELECT DATE(booking_date) AS booking_day, SUM(revenue) AS total_revenue FROM bookings WHERE EXTRACT(MONTH FROM booking_date) = 8 GROUP BY booking_day;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE claims (claim_id INT, policy_id INT, claim_amount DECIMAL); INSERT INTO claims (claim_id, policy_id, claim_amount) VALUES (1, 1001, 2500.00), (2, 1002, 3000.00), (3, 1003, 1500.00), (4, 1002, 3500.00);
|
What is the maximum claim amount for policy number 1002?
|
SELECT MAX(claim_amount) FROM claims WHERE policy_id = 1002;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Volunteers (VolunteerID int, ProgramName varchar(50), VolunteerDate date); INSERT INTO Volunteers (VolunteerID, ProgramName, VolunteerDate) VALUES (1, 'Education', '2021-01-01'), (2, 'Healthcare', '2021-02-01'), (3, 'Education', '2021-12-25');
|
How many volunteers engaged in each program in 2021, grouped by program name?
|
SELECT ProgramName, COUNT(*) as NumberOfVolunteers FROM Volunteers WHERE YEAR(VolunteerDate) = 2021 GROUP BY ProgramName;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE regions (id INT, name VARCHAR(50), budget INT, country VARCHAR(50)); INSERT INTO regions (id, name, budget, country) VALUES (1, 'Northeast', 50000, 'USA'), (2, 'Southeast', 60000, 'USA'), (3, 'East Asia', 70000, 'China'), (4, 'South Asia', 40000, 'India'); CREATE TABLE pd_budgets (id INT, region_id INT, amount INT, students INT); INSERT INTO pd_budgets (id, region_id, amount, students) VALUES (1, 1, 40000, 2000), (2, 2, 50000, 2500), (3, 3, 60000, 3000), (4, 4, 30000, 1500);
|
Which countries have the lowest teacher professional development budgets per student?
|
SELECT r.country, MIN(pd_budgets.amount/pd_budgets.students) as lowest_budget_per_student FROM regions r JOIN pd_budgets ON r.id = pd_budgets.region_id GROUP BY r.country;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Companies (CompanyID INT, CompanyName VARCHAR(50)); INSERT INTO Companies (CompanyID, CompanyName) VALUES (1, 'ABC Mining'), (2, 'XYZ Excavations'); CREATE TABLE Minerals (MineralID INT, MineralName VARCHAR(50), CompanyID INT); INSERT INTO Minerals (MineralID, MineralName, CompanyID) VALUES (1, 'Gold', 1), (2, 'Silver', 1), (3, 'Copper', 2), (4, 'Iron', 2);
|
What are the names and types of minerals extracted by each company?
|
SELECT CompanyName, MineralName FROM Companies JOIN Minerals ON Companies.CompanyID = Minerals.CompanyID;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE cases (id INT, practice_area VARCHAR(255), billing_amount DECIMAL(10,2), case_outcome VARCHAR(255), attorney_id INT); INSERT INTO cases (id, practice_area, billing_amount, case_outcome, attorney_id) VALUES (1, 'Civil', 5000.00, 'Won', 1), (2, 'Criminal', 3000.00, 'Won', 2), (3, 'Civil', 7000.00, 'Lost', 1), (4, 'Civil', 6000.00, 'Won', 3), (5, 'Criminal', 4000.00, 'Lost', 2); CREATE TABLE attorneys (id INT, degree VARCHAR(255)); INSERT INTO attorneys (id, degree) VALUES (1, 'JD'), (2, 'LLM'), (3, 'JD'), (4, 'BA');
|
What is the total billing amount for cases in the 'Criminal' practice area that were won by attorneys with a 'LLM' degree?
|
SELECT SUM(billing_amount) FROM cases INNER JOIN attorneys ON cases.attorney_id = attorneys.id WHERE cases.practice_area = 'Criminal' AND cases.case_outcome = 'Won' AND attorneys.degree = 'LLM';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Players (PlayerID INT PRIMARY KEY, Name VARCHAR(50), Age INT, Gender VARCHAR(10), Country VARCHAR(50)); INSERT INTO Players (PlayerID, Name, Age, Gender, Country) VALUES (1, 'Jamal Jackson', 25, 'Male', 'United States'); INSERT INTO Players (PlayerID, Name, Age, Gender, Country) VALUES (2, 'Sofia Rodriguez', 22, 'Female', 'Spain');
|
Update player demographics information
|
UPDATE Players SET Age = 23, Gender = 'Non-binary', Country = 'Mexico' WHERE PlayerID = 1;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE RuralInfrastructure (id INT, country VARCHAR(50), project VARCHAR(50), budget FLOAT, year INT); INSERT INTO RuralInfrastructure (id, country, project, budget, year) VALUES (1, 'Rural Kenya', 'Irrigation System Improvement', 250000, 2021);
|
Update the budget for the 'Irrigation System Improvement' project in Rural Kenya to 300000 in 2021.
|
WITH cte AS (UPDATE RuralInfrastructure SET budget = 300000 WHERE country = 'Rural Kenya' AND project = 'Irrigation System Improvement' AND year = 2021) SELECT * FROM RuralInfrastructure WHERE country = 'Rural Kenya' AND project = 'Irrigation System Improvement' AND year = 2021;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE vessels (id INT, name TEXT, port_id INT, speed FLOAT); INSERT INTO vessels (id, name, port_id, speed) VALUES (1, 'VesselA', 1, 20.5), (2, 'VesselB', 1, 21.3), (3, 'VesselC', 2, 25.0);
|
Insert a new record into the table 'vessels' with the name 'VesselD', port_id 1, and speed 23.5.
|
INSERT INTO vessels (name, port_id, speed) VALUES ('VesselD', 1, 23.5);
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE environmental_impact (chemical_id INT, environmental_impact_score INT, production_country VARCHAR(255)); INSERT INTO environmental_impact (chemical_id, environmental_impact_score, production_country) VALUES (101, 78, 'Brazil'), (102, 82, 'USA'), (103, 85, 'Mexico'), (104, 60, 'Brazil'), (105, 90, 'Canada');
|
What is the average environmental impact score for chemicals produced in Brazil?
|
SELECT AVG(environmental_impact_score) FROM environmental_impact WHERE production_country = 'Brazil'
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Infrastructure_Projects (id INT, country VARCHAR(50), year INT, cost FLOAT); INSERT INTO Infrastructure_Projects (id, country, year, cost) VALUES (1, 'Kenya', 2020, 150000.0), (2, 'Tanzania', 2019, 120000.0), (3, 'Kenya', 2018, 175000.0);
|
What was the total cost of all infrastructure projects in Kenya in 2020?
|
SELECT SUM(cost) FROM Infrastructure_Projects WHERE country = 'Kenya' AND year = 2020;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE teachers (teacher_id INT, years_of_experience INT, mental_health_resource_access DATE); INSERT INTO teachers VALUES (1, 5, NULL), (2, 3, NULL), (3, 8, NULL);
|
What is the average years of experience for teachers who have not accessed mental health resources?
|
SELECT AVG(years_of_experience) AS avg_experience FROM teachers WHERE mental_health_resource_access IS NULL;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE suppliers (id INT, name VARCHAR(255), country VARCHAR(255)); CREATE TABLE products (id INT, name VARCHAR(255), organic BOOLEAN, weight FLOAT, supplier_id INT);
|
Identify the top 3 heaviest non-organic products and their suppliers.
|
SELECT p.name, s.name as supplier, p.weight FROM suppliers s INNER JOIN products p ON s.id = p.supplier_id WHERE p.organic = 'f' ORDER BY p.weight DESC LIMIT 3;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE labor_productivity_q4 (site_id INT, productivity FLOAT, productivity_date DATE); INSERT INTO labor_productivity_q4 (site_id, productivity, productivity_date) VALUES (1, 12.0, '2022-10-01'), (1, 13.0, '2022-10-02'), (1, 14.0, '2022-10-03'); INSERT INTO labor_productivity_q4 (site_id, productivity, productivity_date) VALUES (2, 15.0, '2022-10-01'), (2, 16.0, '2022-10-02'), (2, 17.0, '2022-10-03');
|
What is the minimum labor productivity for a mine site in Q4 2022?
|
SELECT site_id, MIN(productivity) FROM labor_productivity_q4 WHERE productivity_date BETWEEN '2022-10-01' AND '2022-12-31' GROUP BY site_id;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE equipment_inventory (id INT, equipment_type VARCHAR(50), quantity INT); INSERT INTO equipment_inventory (id, equipment_type, quantity) VALUES (1, 'Excavator', 10), (2, 'Drill', 15), (3, 'Haul Truck', 20);
|
How many mining equipment units are there in the 'equipment_inventory' table, broken down by type?
|
SELECT equipment_type, quantity FROM equipment_inventory;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE events (id INT, name VARCHAR(255), date DATE, category VARCHAR(255)); INSERT INTO events (id, name, date, category) VALUES (1, 'Concert', '2022-06-01', 'music'), (2, 'Play', '2022-06-02', 'theater');
|
What is the average attendance for events in the 'music' category?
|
SELECT AVG(attendance) FROM events WHERE category = 'music';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE ad_revenue (country VARCHAR(2), date DATE, revenue DECIMAL(10,2)); INSERT INTO ad_revenue (country, date, revenue) VALUES ('US', '2022-01-01', 100), ('JP', '2022-04-01', 200), ('JP', '2022-04-15', 250);
|
What is the average advertising revenue in Japan for Q2 2022?
|
SELECT AVG(revenue) FROM ad_revenue WHERE country = 'JP' AND date BETWEEN '2022-04-01' AND '2022-06-30';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE streams (song_id INT, stream_date DATE, genre VARCHAR(20), country VARCHAR(20), revenue DECIMAL(10,2)); INSERT INTO streams (song_id, stream_date, genre, country, revenue) VALUES (10, '2021-03-01', 'Classical', 'UK', 1.50);
|
Update the revenue of all Classical music streams in the United Kingdom on March 1, 2021 to 2.50.
|
UPDATE streams SET revenue = 2.50 WHERE genre = 'Classical' AND country = 'UK' AND stream_date = '2021-03-01';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE museums (name VARCHAR(255), location VARCHAR(255), year_established INT, type VARCHAR(255)); INSERT INTO museums (name, location, year_established, type) VALUES ('British Museum', 'London', 1753, 'History'), ('Louvre Museum', 'Paris', 1793, 'Art'), ('Metropolitan Museum of Art', 'New York', 1870, 'Art'); CREATE TABLE attendance (museum_name VARCHAR(255), year INT, total_visitors INT); INSERT INTO attendance (museum_name, year, total_visitors) VALUES ('British Museum', 2019, 6267367), ('Louvre Museum', 2019, 10028000), ('Metropolitan Museum of Art', 2019, 6911941);
|
What is the total number of visitors to historical museums in the year 2019?
|
SELECT SUM(total_visitors) FROM attendance WHERE year = 2019 AND type = 'History';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE textile_sources (source_id INT, material VARCHAR(50), country VARCHAR(50)); INSERT INTO textile_sources (source_id, material, country) VALUES (1, 'Recycled Polyester', 'China'), (2, 'Recycled Polyester', 'India'); CREATE TABLE quantities (quantity_id INT, source_id INT, quantity INT); INSERT INTO quantities (quantity_id, source_id, quantity) VALUES (1, 1, 5000), (2, 2, 7000);
|
What is the total quantity of recycled polyester sourced from Asian countries?
|
SELECT SUM(q.quantity) FROM quantities q INNER JOIN textile_sources ts ON q.source_id = ts.source_id WHERE ts.material = 'Recycled Polyester' AND ts.country IN ('China', 'India');
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE posts (id INT, user_id INT, content TEXT, comments INT, hashtags TEXT);
|
Find the average number of comments for posts with the hashtag #nature in the "wildlife_appreciation" schema.
|
SELECT AVG(comments) FROM posts WHERE hashtags LIKE '%#nature%';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Hiring (HireID INT, HireDate DATE); INSERT INTO Hiring (HireID, HireDate) VALUES (1, '2022-10-01'), (2, '2022-11-15'), (3, '2022-12-20'), (4, '2023-01-05'), (5, '2023-02-12');
|
How many employees were hired in the last quarter of 2022?
|
SELECT COUNT(*) FROM Hiring WHERE HireDate >= '2022-10-01' AND HireDate < '2023-01-01';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE posts (id INT, user_id INT, created_at TIMESTAMP); CREATE TABLE users (id INT, username VARCHAR(255));
|
Identify users who have posted more than 5 times per day on average in the last 30 days.
|
SELECT users.username FROM users JOIN (SELECT user_id, COUNT(*) / 30 AS avg_posts_per_day FROM posts WHERE created_at >= NOW() - INTERVAL 30 DAY GROUP BY user_id HAVING avg_posts_per_day > 5) AS subquery ON users.id = subquery.user_id;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE program_hours (id INT, program TEXT, hours DECIMAL, hours_date DATE);
|
Which programs had the least volunteer hours in Q4 2021?
|
SELECT program, SUM(hours) as total_hours FROM program_hours WHERE hours_date >= '2021-10-01' AND hours_date < '2022-01-01' GROUP BY program ORDER BY total_hours ASC;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE games (game_id INT, team VARCHAR(50), position VARCHAR(50), wins INT);
|
List the teams that have a win rate greater than 60%.
|
SELECT team FROM (SELECT team, SUM(wins) AS wins, COUNT(*) AS total_games FROM games GROUP BY team) AS subquery WHERE wins / total_games > 0.6;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE if not exists cities (city_id INT, city VARCHAR(255)); INSERT INTO cities (city_id, city) VALUES (1, 'London'), (2, 'Paris'), (3, 'Berlin'); CREATE TABLE if not exists matches (match_id INT, city_id INT, match_date DATE); INSERT INTO matches (match_id, city_id, match_date) VALUES (1, 1, '2022-01-01'), (2, 2, '2022-01-02'), (3, 3, '2022-01-03'), (4, 1, '2021-06-01'), (5, 1, '2021-12-25');
|
How many soccer games took place in London since 2020?
|
SELECT COUNT(*) FROM matches WHERE city_id = 1 AND match_date >= '2020-01-01';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE crops_2 (id INT, farmer_id INT, name TEXT, yield INT, year INT); INSERT INTO crops_2 (id, farmer_id, name, yield, year) VALUES (1, 1, 'cassava', 400, 2010), (2, 1, 'cassava', 500, 2011), (3, 2, 'cassava', 600, 2010), (4, 2, 'cassava', 700, 2011), (5, 3, 'cassava', 800, 2010), (6, 3, 'cassava', 900, 2011);
|
Identify the total production of 'cassava' by small farmers in 'Africa' for the last 3 years.
|
SELECT SUM(yield) FROM crops_2 WHERE name = 'cassava' AND country = 'Africa' AND year BETWEEN 2010 AND 2012;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Vessels (ID INT, Name VARCHAR(255), Speed FLOAT, Arrival DATETIME); INSERT INTO Vessels (ID, Name, Speed, Arrival) VALUES (1, 'Vessel1', 20.5, '2022-01-01 10:00:00'), (2, 'Vessel2', 25.3, '2022-01-15 14:30:00');
|
What is the average speed of vessels that arrived in the US in the last month?
|
SELECT AVG(Speed) FROM (SELECT Speed, ROW_NUMBER() OVER (ORDER BY Arrival DESC) as RowNum FROM Vessels WHERE Arrival >= DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH)) AS Sub WHERE RowNum <= 10;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE properties (id INT, city VARCHAR(50), square_footage FLOAT); INSERT INTO properties (id, city, square_footage) VALUES (1, 'Austin', 1200.0), (2, 'Austin', 1500.0), (3, 'Seattle', 1800.0);
|
What is the average square footage of co-living units in the city of Austin?
|
SELECT AVG(square_footage) FROM properties WHERE city = 'Austin' AND square_footage IS NOT NULL AND city IS NOT NULL;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Ethical_AI (country VARCHAR(255), budget INT); INSERT INTO Ethical_AI (country, budget) VALUES ('USA', 5000000), ('Canada', 3000000), ('Mexico', 2000000);
|
What is the average budget allocated for ethical AI initiatives by country?
|
SELECT AVG(budget) as avg_budget, country FROM Ethical_AI GROUP BY country;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE WaterConsumption (ID INT, City VARCHAR(20), State VARCHAR(20), Consumption FLOAT, Date DATE); INSERT INTO WaterConsumption (ID, City, State, Consumption, Date) VALUES (13, 'Los Angeles', 'California', 200, '2020-08-01'), (14, 'San Francisco', 'California', 180, '2020-08-02'), (15, 'San Diego', 'California', 190, '2020-08-03'), (16, 'Los Angeles', 'California', 210, '2020-08-04');
|
Find the top 3 water-consuming cities in the state of California for August 2020.
|
SELECT City, SUM(Consumption) FROM WaterConsumption WHERE State = 'California' AND Date >= '2020-08-01' AND Date <= '2020-08-31' GROUP BY City ORDER BY SUM(Consumption) DESC LIMIT 3
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Policy (PolicyID int, PolicyType varchar(50), EffectiveDate date, RiskScore int); CREATE TABLE Claim (ClaimID int, PolicyID int, ClaimDate date, ClaimAmount int, State varchar(50)); INSERT INTO Policy (PolicyID, PolicyType, EffectiveDate, RiskScore) VALUES (1, 'Auto', '2020-01-01', 700), (2, 'Home', '2019-05-05', 900), (3, 'Life', '2021-08-01', 850); INSERT INTO Claim (ClaimID, PolicyID, ClaimDate, ClaimAmount, State) VALUES (1, 1, '2020-03-15', 2000, 'Texas'), (2, 2, '2019-12-27', 3000, 'California'), (3, 3, '2021-01-05', 1500, 'Texas');
|
Which policy types have no claims in 2020?
|
SELECT Policy.PolicyType FROM Policy LEFT JOIN Claim ON Policy.PolicyID = Claim.PolicyID WHERE Claim.ClaimDate IS NULL AND Claim.ClaimDate BETWEEN '2020-01-01' AND '2020-12-31';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE waste_generation (waste_type VARCHAR(255), region VARCHAR(255), generation_rate INT, date DATE); INSERT INTO waste_generation (waste_type, region, generation_rate, date) VALUES ('Plastic', 'Northwest', 120, '2021-01-01'), ('Plastic', 'Northwest', 150, '2021-01-02'), ('Paper', 'Northwest', 210, '2021-01-01'), ('Paper', 'Northwest', 240, '2021-01-02');
|
What is the daily waste generation rate for each waste type, ranked by the highest generation rate, for the Northwest region?
|
SELECT waste_type, region, generation_rate, date, RANK() OVER (PARTITION BY waste_type ORDER BY generation_rate DESC) as daily_generation_rank FROM waste_generation WHERE region = 'Northwest';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE network_investments (investment_id INT, investment_date DATE, investment_amount DECIMAL(10,2)); INSERT INTO network_investments (investment_id, investment_date, investment_amount) VALUES (1, '2022-01-01', 50000), (2, '2022-03-15', 75000), (3, '2022-06-30', 60000), (4, '2022-09-15', 85000), (5, '2022-12-31', 90000);
|
Which network infrastructure investments were made in the last 6 months?
|
SELECT * FROM network_investments WHERE network_investments.investment_date >= DATE_SUB(CURDATE(), INTERVAL 6 MONTH);
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE tourism_stats (country VARCHAR(255), year INT, visitors INT, continent VARCHAR(255));
|
Insert records of tourists who visited Canada in 2022.
|
INSERT INTO tourism_stats (country, year, visitors, continent) VALUES ('Canada', 2022, 3500000, 'North America');
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE usage (id INT, subscriber_id INT, data_usage DECIMAL(10,2)); INSERT INTO usage (id, subscriber_id, data_usage) VALUES (1, 1, 2.5), (2, 2, 3.0), (3, 3, 1.5); CREATE TABLE subscribers (id INT, type VARCHAR(10), region VARCHAR(10)); INSERT INTO subscribers (id, type, region) VALUES (1, 'postpaid', 'North'), (2, 'prepaid', 'South'), (3, 'postpaid', 'East');
|
What is the average data usage (in GB) for prepaid mobile customers in the 'South' region?
|
SELECT AVG(usage.data_usage) AS avg_data_usage FROM usage INNER JOIN subscribers ON usage.subscriber_id = subscribers.id WHERE subscribers.type = 'prepaid' AND subscribers.region = 'South';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE donations (id INT PRIMARY KEY, donor_id INT, donation_amount DECIMAL(10,2), donation_date DATE, nonprofit_id INT); CREATE TABLE nonprofits (id INT PRIMARY KEY, name VARCHAR(100), city VARCHAR(50), mission VARCHAR(200)); INSERT INTO donations (id, donor_id, donation_amount, donation_date, nonprofit_id) VALUES (1, 1, 500, '2022-01-01', 1); INSERT INTO donations (id, donor_id, donation_amount, donation_date, nonprofit_id) VALUES (2, 2, 750, '2022-02-15', 2); INSERT INTO nonprofits (id, name, city, mission) VALUES (1, 'Save the Children', 'Washington', 'Improving the lives of children through better education, health care, and economic opportunities.'); INSERT INTO nonprofits (id, name, city, mission) VALUES (2, 'Greenpeace', 'San Francisco', 'Dedicated to preserving the environment and promoting peace.');
|
Rank nonprofits based in Washington by the number of donations received
|
SELECT nonprofits.name, ROW_NUMBER() OVER (PARTITION BY nonprofits.city ORDER BY COUNT(donations.id) DESC) as ranking FROM nonprofits INNER JOIN donations ON nonprofits.id = donations.nonprofit_id WHERE nonprofits.city = 'Washington' GROUP BY nonprofits.name;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE Spacecraft (SpacecraftID INT, Name VARCHAR(50), Manufacturer VARCHAR(50), LaunchDate DATE, Mass FLOAT); INSERT INTO Spacecraft VALUES (1, 'Mariner 4', 'NASA', '1964-11-28', 260), (2, 'Mariner 6', 'NASA', '1969-02-25', 419), (3, 'Mariner 7', 'NASA', '1969-03-27', 419), (4, 'Viking 1', 'NASA', '1975-08-20', 1200), (5, 'Viking 2', 'NASA', '1975-09-09', 1200), (6, 'Mars Pathfinder', 'NASA', '1996-12-04', 1400), (7, 'Mars Global Surveyor', 'NASA', '1996-11-07', 1060), (8, 'Nozomi', 'ISAS', '1998-07-03', 540), (9, 'Mars Climate Orbiter', 'NASA', 1998-12-11, 628), (10, 'Mars Polar Lander', 'NASA', 1999-01-03, 370);
|
What is the combined mass of all spacecraft that have been to Mars?
|
SELECT SUM(Mass) FROM Spacecraft WHERE Destination = 'Mars';
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE ports (port_id INT, port_name VARCHAR(255), country VARCHAR(255)); INSERT INTO ports VALUES (1, 'Port of Shanghai', 'China'); CREATE TABLE cargo (cargo_id INT, port_id INT, weight FLOAT, handling_date DATE);
|
Insert new cargo records for a shipment from the Port of Oakland to Japan in 2023
|
INSERT INTO cargo (cargo_id, port_id, weight, handling_date) VALUES (1001, (SELECT port_id FROM ports WHERE port_name = 'Port of Oakland'), 6000, '2023-02-14'), (1002, (SELECT port_id FROM ports WHERE country = 'Japan'), 5500, '2023-02-16');
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE peacekeeping_operations (id INT, country VARCHAR(255), year INT);
|
Delete records of peacekeeping operations older than a certain year.
|
DELETE FROM peacekeeping_operations WHERE year < (SELECT EXTRACT(YEAR FROM NOW()) - 10);
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE games (team TEXT, result TEXT); INSERT INTO games (team, result) VALUES ('Team A', 'win'), ('Team A', 'loss'), ('Team B', 'win');
|
Which team has the highest number of home wins in the last 10 games?
|
SELECT team, COUNT(*) FILTER (WHERE result = 'win') OVER (PARTITION BY team ORDER BY team ROWS BETWEEN UNBOUNDED PRECEDING AND 9 PRECEDING) as home_wins FROM games WHERE result = 'win' ORDER BY home_wins DESC LIMIT 1;
|
gretelai_synthetic_text_to_sql
|
CREATE TABLE sources (id INT, name TEXT, organic BOOLEAN); CREATE TABLE products_sources (product_id INT, source_id INT); INSERT INTO sources VALUES (1, 'Source A', TRUE), (2, 'Source B', FALSE), (3, 'Source C', TRUE); INSERT INTO products_sources VALUES (1, 1), (2, 1), (3, 2), (4, 3);
|
Find the number of unique products from organic sources.
|
SELECT COUNT(DISTINCT products_sources.product_id) FROM products_sources INNER JOIN sources ON products_sources.source_id = sources.id WHERE sources.organic = TRUE;
|
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.