Group by date and calculate

Viewed 69

For each account I need to subtract the earliest amount from the most recent amount.

Input

 - ACCOUNT      DATE      AMOUNT
 - 123        7/18/2017      500
 - 456        7/18/2017      450
 - 123        7/17/2017      300
 - 456        7/17/2017      200

Desired output:

 - 123  7/17/2017  7/18/2017 200
 - 456  7/17/2017  7/18/2017 250

I've tried grouping by max and min dates, but it wasn't helpful. And I don't have much flexibility in regards to the sort of the input. How can I arrange the data properly?

1 Answers
Related