[英]Select Difference Between Rows (Postgres)
隨着時間的推移,我正在聚集Facebook“喜歡”的網址計數。 每小時,我檢查“喜歡”計數並將其插入帶時間戳的行。 如何獲得新行和前一小時行之間的總差異?
例如,
謝謝!
這應該做到這一點。
SELECT id, total, total - lag(total) over (partition by id order by timestamp_column) as diff_since_last FROM the_table_with_no_name
當我嘗試a_horse_with_no_name的解決方案時,我不得不刪除'id by id'部分以獲得結果(我正在使用PG 9.2)
SELECT id,total,total - lag(total)over(order by timestamp_column)as diff_since_last FROM the_table_with_no_name
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.