I want to get the first value and last value of a selected measure between a specified date range.
Example:
If I have a query that returns values between 10 Nov and 17 Nov, I want to subtract the value at 17 Nov from the value at 10 Nov.
I tried using tail()
and head()
functions but it still not working.
Asked
Active
Viewed 293 times
0

Mo T
- 440
- 2
- 9
- 30
-
so in other words you need only rows containing first and last values on a particular column? – Eduard Uta Nov 17 '14 at 14:36
-
@EduardUta No, The difference between them, and then I will get top count of 10 values based on the difference. – Mo T Nov 17 '14 at 14:40
-
You need to provide us some additional info concerning the schema of your table. Give us some sample data as well. – Giorgos Betsos Nov 17 '14 at 14:59
1 Answers
0
SELECT MAX(t.Col) - MIN(t.Col)
FROM yourTable t
The statement returns the difference between max and min values on column Col. The statement can be further used as a subquery in various clauses such as where or select. If the column Col is a date-related one then the difference computed will reflect the number of days between min an max.

Eduard Uta
- 2,477
- 5
- 26
- 36
-
Please include an explanation of your code. It's unlikely to be helpful to the asker without an explanation. – Josh Burgess Nov 17 '14 at 15:06