Pgsql 根據當前時間查詢前三天的資料
阿新 • • 發佈:2021-01-30
技術標籤:資料庫postgresql
pgsql像mysql一樣支援一些時間函式;
current_timestamp時間函式的作用和now相同;
1. select current_timestamp; 當前時間+精度+時區
2. 輸出為 : 2021-01-29 14:24:49.895409+08
1. select current_timestamp(0)::TIMESTAMP(0); 去掉了精度+時區
2. 輸出為 :2021-01-29 14:28:20
通過區間查詢欄位來實現查詢從當前時間前三天的資料(今天+昨天+前天),可以修改’3 day’的值來查詢所需時間值;
from 表名 o where billing_date between ( SELECT current_timestamp - interval '3 day') and current_timestamp