Reputation: 1392
I have a transaction table with 3 columns: transaction_id, user_id, time_created. I would like to output a table showing:
UserID FirstTransactionTime LastTransactionTime
for each user. What is the best way to construct this query?
Upvotes: 1
Views: 3136
Reputation: 15297
Assuming you mean the earliest and latest transaction start time, per user:
SELECT user_id, MIN(time_created), MAX(time_created)
FROM Transactions
GROUP BY user_id
Upvotes: 1