简体   繁体   中英

SQL difference between two rows with timestamp

Im working on with SQL on PostgreSQL I have this table that describes images of cars with columns camera , whn and reg

Camera is int,whn is timestamp string(eg 2007-02-25 07:51:10) and reg is string

I am doing this assignment and im stuck on:

"Print the register plate(reg) of cars which have been photographed twice by the same camera or different and the difference between the photos is a minute or less"

Does anybody know how i can express this difference between two different rows of the column whn that needs to be equal or less than 60 seconds?

  1. Sort your table by timestamp.
  2. Use lag() from windows function to get row below current row.
  3. Use extract() to see different between two timestamp.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM