When there is a table like the following,
To extract the difference from the previous day (get the previous record, not the actual date)
What should I do?
* Table definition *
create table uriage
(date DATE NOT NULL,
price double precision);
Postgresql 11 is assumed.
Answer # 1
lag is for the purpose.
select price-lag (price) over (order by date) as difference from table
In practice, you will also usepartition by.
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- python - you may need to restart the kernel to use updated packages error
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- python 3x - typeerror: 'method' object is not subscriptable
- xcode - pod install [!] no `podfile 'found in the project directory
- vuejs - [vuetify] unable to locate target [data-app] i want to unit test to avoid warning
- i want to call a child component method from a parent in vuejs