Question

Locked

SQL previous record

By phamyh ·
I would like to find the previous Speed to all cars in a database and compare it to the last speed it was changed by date. Then do a count of how many times it was changed. Can someone help? Thanks.

Example:

CarNum DorDate SpeedoEnd PrevEnd
16 5/1/2008 337374
16 5/2/2008 337538 337374
16 5/3/2008 337898 337538
16 5/4/2008 338212 337898
17 5/1/2008 201371
17 5/2/2008 201519 201371
17 5/3/2008 201784 201519
18 5/1/2008 196520
18 5/2/2008 196719 196520
18 5/3/2008 196774 196719

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Well if I get you, you could

by Tony Hopkinson In reply to SQL previous record

do
select Distinct CarNum,DORDate,SpeedoEnd
to get all the changes, Distinct would cut out any records where SpeedoEnd didn't change

and then count from that so

Select CarNum,Count(DORDate) From
(select Distinct CarNum,DORDate,SpeedoEnd) changes

changes is just a dummy name to fool sql into taking the query in brackets as a table

PrevEnd isn't helping you at all by the way, I'd try and get rid of it, it's a carry over from a non-db system

Back to Web Development Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums