简体   繁体   English

SQL 带时间戳的两行之间的差异

[英]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我正在使用 PostgreSQL 上的 SQL 我有这张表,它描述了带有列摄像头whnreg的汽车图像

Camera is int,whn is timestamp string(eg 2007-02-25 07:51:10) and reg is string Camera 是 int,whn 是时间戳字符串(例如 2007-02-25 07:51:10),reg 是字符串

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" “打印同一台相机或不同相机两次拍摄的汽车的登记牌(reg),照片之间的差异是一分钟或更短”

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?有谁知道我如何表达需要等于或小于 60 秒的列的两个不同行之间的这种差异?

  1. Sort your table by timestamp.按时间戳对表格进行排序。
  2. Use lag() from windows function to get row below current row.使用windows function中的 lag() 获取当前行下方的行。
  3. Use extract() to see different between two timestamp.使用extract()查看两个时间戳之间的差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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