DE SQL Hiring Questions | 106
DE SQL Hiring Questions | 106 Q: I have a table with customer ID, session ID, and session date. Another table has transaction date and customer ID. I want to know the days between the session date and the next transaction, previous transaction, and closest transaction. * A customer can have multiple transactions before and after session. This problem requires calculating time differences between session dates and transaction dates for each customer. Here's a SQL solution: SQL Solution: WITH NextTransactionDates AS ( SELECT customer_id, session_date, transaction_date AS next_transaction_date, ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY transaction_date) as rn_next, DATE_DIFF('day', session_date, transaction_date) AS days_to_next_transaction FROM sessions s JOIN transactions t ON s.customer_id = t.customer_id WHERE session_date <= transaction_date ...