|  | Posted by Erland Sommarskog on 06/12/34 11:45 
(sucaba.r@gmail.com) writes:> From looking at the table, the system ran for three days before it was
 > reset (rows 1-3).  It then ran for 4 days (rows 4-7) for a total of 7
 > (not 5 as I indicated above).  So I'd need to capture 7 as the total.
 
 To be perfectly honest, you will never get any help with your queries,
 if you don't have a grip of the business requirements.
 
 Here is a query based on Tom's table, but it returns 6 and not 7, because
 the first row is not counted:
 
 select count (*)
 from   @t a
 JOIN   @t b ON a.PK = b.PK + 1
 WHERE  a.Amount > b.Amount
 
 
 
 
 --
 Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
 
 Books Online for SQL Server 2005 at
 http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
 Books Online for SQL Server 2000 at
 http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
  Navigation: [Reply to this message] |