Aparanjit
Aparanjit

Reputation: 41

Need to get the First ordered date and last ordered date for all customers from order table

I have order table which has information about all the customers orders. Now, I want to pull the first orderdate and last orderdate of the each and every customer.

Can someone help me in this?

Thanks in Advance..

Upvotes: 0

Views: 46

Answers (1)

Lamak
Lamak

Reputation: 70638

This is a simple MIN and MAX:

SELECT CustomerId, 
       MIN(OrderDate) Min_Order_Date
       MAX(OrderDate) Last_Order_Date
FROM dbo.Orders
GROUP BY CustomerId;

Upvotes: 3

Related Questions