Return each customer's name and the number of days between their signup date and 2026-07-01 (alias daysonbook). Table…
SQLLevel: IntermediateDates
Return each customer's name and the number of days between their signup date and 2026-07-01 (alias days_on_book).
Table definitions (from the source exercise):
CREATE TABLE customers(customer_id INTEGER PRIMARY KEY, name TEXT, city TEXT, signup_date TEXT, credit_score INTEGER);
Hints
- Define one output row and the source-table keys.
- Check duplicates, NULLs and the order of filtering and aggregation.
Answer
Approach: DATEDIFF('2026-07-01', signup_date).
SELECT name, DATEDIFF('2026-07-01', signup_date) AS days_on_book
FROM customers;
The source uses SQLite with a MySQL compatibility layer. Date and string functions are dialect dependent; the query is preserved as published.
Source and licence: SQL Practice Lab — Ebrahim Sharifi · MIT