db_id
stringclasses
12 values
query
stringlengths
16
593
setup_sql
stringclasses
8 values
validation_sql
stringclasses
15 values
question
stringlengths
22
239
category
stringclasses
5 values
hn
SELECT COUNT(*) as domain_count, SUBSTRING(SPLIT_PART(url, '//', 2), 1, POSITION('/' IN SPLIT_PART(url, '//', 2)) - 1) as domain FROM hacker_news WHERE url IS NOT NULL GROUP BY domain ORDER BY domain_count DESC LIMIT 10;
;
SELECT * FROM ddb_benchmark_result;
what are the top domains being shared on hacker_news?
hard
laptop
SELECT c.firstname, c.lastname, COUNT(*) AS num_pcs_bought FROM customers c JOIN sales s ON c.customer_id = s.customer_id JOIN pcs p ON s.model = p.model GROUP BY c.customer_id, c.firstname, c.lastname ORDER BY num_pcs_bought DESC LIMIT 1;
;
SELECT * FROM ddb_benchmark_result;
Who bought the most PCs, print also the users name?
medium
transactions
select users.id, users.name, sum(transactions.amount) as balance from users join transactions on users.id = transactions.user_id group by users.id, users.name having balance = 0
;
SELECT * FROM ddb_benchmark_result;
list the names off account holders who have negative balances
easy
laptop
SELECT model FROM products WHERE maker = 'B';
;
SELECT * FROM ddb_benchmark_result;
List only the model number of all products made by maker B.
easy
laptop
SELECT model FROM products WHERE maker <> 'B';
;
SELECT * FROM ddb_benchmark_result;
List the model numbers of all products not made by maker B.
easy
laptop
SELECT AVG(speed) FROM pcs WHERE speed >= 3.00
;
SELECT * FROM ddb_benchmark_result;
Return the average speed all PCs with speed >= 3.00
easy
laptop
SELECT MAX(price) FROM printers WHERE color = 'TRUE' AND type='laser'
;
SELECT * FROM ddb_benchmark_result;
Return the price of the most expensive color laser printer
medium
laptop
SELECT MIN(paid) FROM sales WHERE type_of_payment LIKE '%visa%'
;
SELECT * FROM ddb_benchmark_result;
Return the minimum amount paid by customers who used a visa card (debit or credit) to purchase a product
medium
laptop
SELECT customer_id FROM customers WHERE firstname LIKE '%e%' OR lastname LIKE '%e%'
;
SELECT * FROM ddb_benchmark_result;
Find the customer_id of customers who have the letter 'e' either in their first name or in their last name
medium
laptop
SELECT model, price/0.85 AS 'price (USD)' FROM laptops WHERE ram >= 1024
;
SELECT * FROM ddb_benchmark_result;
Assume all prices in the table Laptops are in Euro. List the prices of laptops with at least 1024 ram. You should return the price in USD in a column called 'price (USD)'. Assume that 1 USD = 0.85 EURO. Name the price column 'price (USD)'.
hard
laptop
SELECT maker FROM products GROUP BY maker HAVING COUNT(maker) > 4;
;
SELECT * FROM ddb_benchmark_result;
Return a list of makers that make more than four different products.
medium
laptop
SELECT model FROM laptops WHERE speed > 1.7 ORDER BY speed DESC;
;
SELECT * FROM ddb_benchmark_result;
List all the laptop model numbers that have a speed greater than 1.7 in descending order of speed.
medium
laptop
SELECT firstname FROM sales JOIN customers ON sales.customer_id = customers.customer_id GROUP BY firstname ORDER BY COUNT(firstname);
;
SELECT * FROM ddb_benchmark_result;
List firstnames of customers in an ascending order based on the number of purchases made by customers with this firstname.
medium
laptop
SELECT DISTINCT maker FROM products JOIN pcs ON products.model = pcs.model WHERE ram > 1500;
;
SELECT * FROM ddb_benchmark_result;
List all the makers (with only one entry per maker) who make PCs with RAM greater than 1500.
medium
laptop
SELECT city, AVG(paid) as 'avg_spend' FROM sales JOIN customers ON sales.customer_id = customers.customer_id GROUP BY city
;
SELECT * FROM ddb_benchmark_result;
Find the city and the average amount of money spent by customers in each city. Name the column for the amount 'avg_spend'
medium
laptop
SELECT color, MAX(price) as 'max_price' FROM printers GROUP BY color;
;
SELECT * FROM ddb_benchmark_result;
Find the maximum price for each color of printer. Name the column for the maximum price 'max_price'
medium
who
select country_name, max(pm25_concentration) as worst_pm25_for_country from ambient_air_quality group by country_name order by worst_pm25_for_country desc limit 1
;
SELECT * FROM ddb_benchmark_result;
Find the country with the worst single reading of air quality (highest PM 2.5 value). Show the PM 2.5 value as well.
medium
who
select country_name, avg(pm25_concentration) as worst_avg_pm25_for_country from ambient_air_quality group by country_name order by worst_avg_pm25_for_country desc limit 1
;
SELECT * FROM ddb_benchmark_result;
Find the country with the worst average air quality (highest PM 2.5 value). Show the PM 2.5 value as well.
medium
who
select distinct country_name from ambient_air_quality order by country_name
;
SELECT * FROM ddb_benchmark_result;
Find all countries for which WHO air quality data is available. Sort alphabetically.
medium
who
select year, avg(pm25_concentration) from ambient_air_quality where country_name = 'Singapore' group by year order by year
;
SELECT * FROM ddb_benchmark_result;
Find Singapore air quality defined as PM2.5 concentration over time
medium
nyc
SELECT COLUMNS('^trip_') FROM rideshare LIMIT 10;
;
SELECT * FROM ddb_benchmark_result;
select only the column names from the rideshare table that start with trip_ and return the first 10 values
duckdb
nyc
SELECT * FROM rideshare USING SAMPLE 1%;
;
SELECT * FROM ddb_benchmark_result;
select a 1% sample from the nyc.rideshare table
duckdb
laptop
SELECT * EXCLUDE (customer_id) FROM customers;
;
SELECT * FROM ddb_benchmark_result;
select all columns from the customer table, except customer_id
duckdb
nyc
SUMMARIZE rideshare;
;
SELECT * FROM ddb_benchmark_result;
show summary statistics of the rideshare table
duckdb
none
SELECT * FROM read_csv_auto( 'https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv')
;
SELECT * FROM ddb_benchmark_result;
read a CSV from https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv
duckdb
none
COPY (SELECT * FROM read_csv_auto( 'https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv')) TO 'titanic.parquet' (FORMAT 'parquet');
;
SELECT * FROM 'titanic.parquet'
read a CSV from https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv and convert it to a parquet file called "titanic"
duckdb
none
CREATE TABLE titanic AS (SELECT * FROM read_csv_auto( 'https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv'))
;
SELECT * FROM titanic;
create a table called "titanic" from CSV file https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv
duckdb
none
PRAGMA default_null_order='NULLS LAST';
;
SELECT current_setting('default_null_order');
configure duckdb to put null values last when sorting
duckdb
none
CREATE TABLE IF NOT EXISTS products ( maker varchar(10), model varchar(10), type varchar(10));
;
SELECT * FROM products;
create a table about products, that contains a maker, model and type column
ddl
product
INSERT INTO products (maker, model, type) VALUES ('A', '1001', 'pc');
;
SELECT * FROM products;
add a row with values for model "1001" of type "pc", from maker "A" to products table
ddl
none
CALL pragma_version();
;
SELECT * FROM ddb_benchmark_result;
get current version of duckdb
duckdb
nyc
PRAGMA table_info('rideshare');
;
SELECT * FROM ddb_benchmark_result;
list all columns in table nyc.rideshare
duckdb
nyc
PRAGMA show_tables;
;
SELECT * FROM ddb_benchmark_result;
show all tables in the curent database
duckdb
laptop
SELECT customer_id, model, sum(paid) FROM sales GROUP BY ALL
;
SELECT * FROM ddb_benchmark_result;
how much did each customer spend per model type?
easy
nyc
SELECT Max(datediff('minute', tpep_pickup_datetime, tpep_dropoff_datetime)) from nyc.taxi
;
SELECT * FROM ddb_benchmark_result;
What was the longest taxi ride in minutes?
hard
who
with per_region as ( select avg(pm10_concentration) as avg_pm10, who_region from ambient_air_quality group by who_region ), max_region as ( select who_region from per_region where avg_pm10 = (select max(avg_pm10) from per_region) ), min_city_value_in_max_region as ( select min(pm10_concentration) from ambient_air_quality where who_region in (from max_region) ), min_city_in_max_region as ( select city from ambient_air_quality where pm10_concentration in (from min_city_value_in_max_region) and who_region in (from max_region) ) from min_city_in_max_region
;
SELECT * FROM ddb_benchmark_result;
What is the city with the lowest pm10 concentration in the region with the highest average pm10 concentration?
hard
hn
SELECT *, regexp_extract(text, '([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,63})',0) email from hacker_news where email[:4]='test'
;
SELECT * FROM ddb_benchmark_result;
Get all posts on hn that contain an email address starting with test. Return all original columns, plus a new column containing the email address.
hard
json
SELECT employee.id, employee.first_name FROM employee_json
;
SELECT * FROM ddb_benchmark_result;
Extract id and first_name properties as individual columns from the employee struct
duckdb
who
SELECT who_region[1]::INT as region, * EXCLUDE (who_region) FROM who.ambient_air_quality
;
SELECT * FROM ddb_benchmark_result;
count quality measurements per region. Make sure to return the region code (first char of who_region) as integer and sort by region.
duckdb
flightinfo
SELECT seat.seat_number FROM seat JOIN direct_flight ON direct_flight.flight_number = seat.flight_number JOIN airport AS departure_airport ON departure_airport.iata_code = direct_flight.departure_airport_iata_code JOIN airport AS arriving_airport ON arriving_airport.iata_code = direct_flight.arriving_airport_iata_code JOIN city AS departure_city ON departure_city.city_zipcode = departure_airport.city_zip_code JOIN city AS arriving_city ON arriving_city.city_zipcode = arriving_airport.city_zip_code WHERE departure_city.city_name = 'Bruxelles' AND arriving_city.city_name = 'Newark';
;
SELECT * FROM ddb_benchmark_result;
Which seats were available on the flight from Bruxelles to Newark?
hard
laptop
COPY customers FROM 'customers_12_12_2023.csv';
COPY customers TO 'customers_12_12_2023.csv';
SELECT * FROM customers;
copy content of csv file customers_12_12_2023.csv into customers table
duckdb
laptop
COPY customers FROM 'customers_12_12_2023.csv' (DELIMITER '\t');
COPY customers TO 'customers_12_12_2023.csv' (FORMAT CSV, DELIMITER '\t');
SELECT * FROM customers;
copy content of csv file costomers_12_12_2023.csv into customers table with tab separator
duckdb
laptop
COPY customers FROM 'customers_partitioned/city=Amsterdam/*.parquet';
COPY customers TO 'customers_partitioned' (FORMAT PARQUET, PARTITION_BY (city), OVERWRITE_OR_IGNORE True);
SELECT * FROM customers;;
copy any parquet files from 'customers_partitioned/city=Amsterdam/' into customers table
duckdb
laptop
COPY customers(customer_id) FROM 'customers_customer_ids.csv';
COPY customers(customer_id) TO 'customers_customer_ids.csv';
SELECT * FROM customers;
copy only the customer_id column from the customers_customer_ids.csv into the customers tables
duckdb
laptop
CREATE TABLE test_tbl AS SELECT * FROM read_json_auto('test.json');
COPY customers TO 'test.json'
SELECT * FROM test_tbl;
read json file from test.json and create new table from it called 'test_tbl'
duckdb
laptop
SELECT * FROM read_csv_auto('test.csv');
COPY customers TO 'test.csv';
SELECT * FROM ddb_benchmark_result;
read csv from test.csv
duckdb
laptop
SELECT * FROM read_csv_auto('test.csv', columns={'customer_id': 'VARCHAR', 'firstname': 'VARCHAR', 'lastname': 'VARCHAR'});
COPY customers(customer_id, firstname, lastname) TO 'test.csv';
SELECT * FROM ddb_benchmark_result;
read csv from test.csv with predefined column and types - customer_id: string, firstname: string, lastname: string
duckdb
laptop
SELECT * EXCLUDE (ram, hd) FROM pcs;
;
SELECT * FROM ddb_benchmark_result;
select all columns from pcs table except for ram and hd
duckdb
laptop
SELECT COLUMNS('name$') FROM customers;
;
SELECT * FROM ddb_benchmark_result;
select all columns ending with 'name' from customers table
duckdb
laptop
SELECT LENGTH(COLUMNS('name$')) FROM customers
;
SELECT * FROM ddb_benchmark_result;
for each column ending with 'name' in the customers table, compute the string length
duckdb
laptop
SELECT * REPLACE (upper(city) AS city) FROM customers;
;
SELECT * FROM ddb_benchmark_result;
get all columns from customer table, and make all city names uppercase
duckdb
laptop
EXPLAIN SELECT * FROM customers
;
SELECT * FROM ddb_benchmark_result;
show query plan for query: SELECT * from customers
duckdb
laptop
SELECT ascii(lastname) FROM customers;
;
SELECT * FROM ddb_benchmark_result;
get the first character of the firstname column and cast it to an INT
duckdb
laptop
SELECT model, speed::INTEGER FROM laptops;
;
SELECT * FROM ddb_benchmark_result;
get laptop name and speed, return the speed as integer
duckdb
laptop_array
SELECT phone_numbers[1] FROM customers;
;
SELECT * FROM ddb_benchmark_result;
get the first phone number of each customer
duckdb
laptop_array
INSERT INTO customers(customer_id, phone_numbers) VALUES (5, ['12312323', '23123344']);
;
SELECT * FROM customers;
insert two phone numbers to customer with id 5 [\"12312323\", and '23123344']
duckdb
laptop
ALTER TABLE customers ADD COLUMN phone_numbers VARCHAR[];
;
DESCRIBE customers;
how to add a new column phone_numbers to the customers table, with array type varchar
duckdb
laptop
SELECT firstname[1] FROM customers;
;
SELECT * FROM ddb_benchmark_result;
get the first letter of the customers firstname
duckdb
laptop_array
SELECT phone_numbers[:2] FROM customers;
;
SELECT * FROM ddb_benchmark_result;
get the first two phone numbers from the phone numbers array of each customer
duckdb
laptop
SELECT {'a':1, 'b':2, 'c':3};
;
SELECT * FROM ddb_benchmark_result;
create a struct with keys a, b, c and values 1,2,3
duckdb
laptop
SELECT [1,2,3];
;
SELECT * FROM ddb_benchmark_result;
create array with values 1,2,3
duckdb
laptop
CREATE TABLE test (embeddings FLOAT[100]);
;
DESCRIBE test;
create table test with a fix-sized array column with 100 dimenions, called embeddings
duckdb
laptop
CREATE TABLE test (person STRUCT(name VARCHAR, id INTEGER));
;
DESCRIBE test;
create table test with a struct column called person with properties name and id
duckdb
laptop_struct
SELECT person.name, person.id FROM test;
;
SELECT * FROM ddb_benchmark_result;
get persons name and persons id from the test table.
duckdb
laptop
UPDATE customers SET email = NULL;
;
SELECT email FROM customers;
remove all values from email column in customers table
duckdb
laptop_json
ALTER TABLE customers ALTER COLUMN email SET DATA TYPE VARCHAR;
;
DESCRIBE customers;
make customer email of type VARCHAR
duckdb
laptop_json
INSERT INTO customers (customer_id, email) VALUES (5,'{"from": "[email protected]", "to": "[email protected]"}');
;
SELECT * FROM customers;
insert json into customer email for customer id 5: {'from': '[email protected]', 'to': '[email protected]'}
duckdb
laptop_json
SELECT customers.email->>'from' FROM customers;
;
SELECT * FROM ddb_benchmark_result;
get 'from' field from customer email json
duckdb
laptop
SUMMARIZE customers;
;
SELECT * FROM ddb_benchmark_result;
summarize the customer table
duckdb
laptop
SELECT * FROM customers USING SAMPLE 10% (reservoir);
;
SELECT count(*) FROM ddb_benchmark_result;
sample 10% from the customers table using reservoir sampling
duckdb
laptop
SET threads = 10;
;
SELECT current_setting('threads');
set number of threads to 10
duckdb
laptop
SET memory_limit = '20G';
;
SELECT current_setting('memory_limit');
set memory limit to 20 gigabyte
duckdb
laptop
SELECT * EXCLUDE (price), avg(price) FROM laptops GROUP BY ALL;
;
SELECT * FROM ddb_benchmark_result;
show the average price of laptop and group by the remaining columns
duckdb
laptop
SELECT * FROM laptops WHERE price > 1000 ORDER BY ALL;
;
SELECT * FROM ddb_benchmark_result;
show all laptops with price above 1000 and order by all columns
duckdb
laptop
ATTACH 'who.ddb';
;
SHOW DATABASES;
attach database file who.ddb
duckdb

No dataset card yet

New: Create and edit this dataset card directly on the website!

Contribute a Dataset Card
Downloads last month
2
Add dataset card