Use the lag function:
SELECT value - lag(value) OVER (ORDER BY Id) FROM table
Sequences used for Ids can skip values, so Id-1 does not always work.
More Related Contents:
- Is it possible to write single query on two table which are not connected to each other?
- sql server 2008 management studio not checking the syntax of my query
- Split function equivalent in T-SQL?
- Querying data by joining two tables in two database on different servers
- Is having an ‘OR’ in an INNER JOIN condition a bad idea?
- Where value in column containing comma delimited values
- How to find all connected subgraphs of an undirected graph
- How to use table variable in a dynamic sql statement?
- SQL query to split column data into rows
- Common Table Expression, why semicolon?
- T-SQL split string based on delimiter
- Bulk DELETE on SQL Server 2008 (Is there anything like Bulk Copy (bcp) for delete data?)
- Create Trigger to log SQL that affected table?
- How do I find duplicates across multiple columns?
- Transfer data from one database to another database
- How to find third or nᵗʰ maximum salary from salary table?
- SQL “between” not inclusive
- Can I set ignore_dup_key on for a primary key?
- Selecting first row per group
- Using PIVOT in SQL Server 2008
- sql varchar(max) vs varchar(fix)
- sql group by only rows which are in sequence
- Function in SQL Server 2008 similar to GREATEST in mysql?
- store arabic in SQL database
- Convert Date format into DD/MMM/YYYY format in SQL Server
- How to retrieve field names from temporary table (SQL Server 2008)
- How to combine results of two queries into a single dataset
- When using GETDATE() in many places, is it better to use a variable?
- Executing SQL Server Agent Job from a stored procedure and returning job result
- Cumulative Total in MS Sql server [duplicate]