欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

postgresql 日期查詢最全整理

 更新時間:2024年08月07日 10:45:24   作者:gis分享者  
這篇文章主要介紹了postgresql 日期查詢最全整理,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧

1、獲取當(dāng)前日期

select now();

在這里插入圖片描述

select current_timestamp;

在這里插入圖片描述

返回值均是當(dāng)前年月日、時分秒,且秒保留6位小數(shù),兩種方式等價

select current_time;

在這里插入圖片描述

返回值:時分秒,秒最高精確到6位

select current_date;

在這里插入圖片描述

返回值:年月日

2、查詢今天的數(shù)據(jù)

SELECT * FROM 表名 WHERE 時間字段 >= current_date AND 時間字段 < current_date + 1;

3、查詢昨天的數(shù)據(jù)

SELECT * FROM 表名 WHERE 時間字段 >= current_date - 1 AND 時間字段 < current_date;

4、查詢一個月內(nèi)的數(shù)據(jù)

SELECT * FROM 表名 WHERE 時間字段 >= current_date - interval '1 month' AND 時間字段 <= current_date;

5、按日, 周, 月, 季度, 年統(tǒng)計數(shù)據(jù)

select date_trunc('DAY', 時間字段) as statisticTime, 分組字段, count(0) from 表名 GROUP BY date_trunc('DAY', 時間字段), 分組字段

日: DAY; 周: WEEK; 月: MONTH; 季度: QUARTER; 年: YEAR

6、 查詢昨天、上周、上月、上年的日期

select to_char( now() - interval '1 day','yyyy-mm-dd');
select to_char( now() - interval '1 week','yyyy-mm-dd hh:mi:ss');
select to_char( now() - interval '1 month','yyyy-mm-dd');
select to_char( now() - interval '1 year','yyyy-mm-dd');

7、查詢今天、今月、今年的開始的日期時間

select date_trunc('year', now())
select date_trunc('month', now())
select date_trunc('day', now())
select date_trunc('hour', now())
select date_trunc('minute', now())
select date_trunc('second', now())

8、查詢最近1秒,1分,1小時,1天,1周(7天),1月,1年的記錄

select * from 表名 where timestamp_start >= current_timestamp - interval ' 1 seconds '
select * from 表名 where timestamp_start >= current_timestamp - interval ' 1 minutes'
select * from 表名 where timestamp_start >= current_timestamp - interval ' 1 hours'
select * from 表名 where timestamp_start >= current_timestamp - interval ' 1 day'
select * from 表名 where timestamp_start >= current_timestamp - interval ' 7 day'
select * from 表名 where timestamp_start >= current_timestamp - interval ' 1 month'
select * from 表名 where timestamp_start >= current_timestamp - interval ' 1 year'

9、從時間戳中提取 年月日時分秒、周

select date_part('year', timestamp '2024-02-16 12:38:40')
select date_part('month', timestamp '2024-02-16 12:38:40')
select date_part('day', timestamp '2024-02-16 12:38:40')
select date_part('hour', timestamp '2024-02-16 12:38:40')
select date_part('minute', timestamp '2024-02-16 12:38:40')
select date_part('second', timestamp '2024-02-16 12:38:40')
select date_part('week', timestamp '2024-02-16 12:38:40')

到此這篇關(guān)于postgresql 您要的日期查詢都在這的文章就介紹到這了,更多相關(guān)postgresql 日期查詢內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • PostgreSQL中數(shù)據(jù)批量導(dǎo)入導(dǎo)出的錯誤處理

    PostgreSQL中數(shù)據(jù)批量導(dǎo)入導(dǎo)出的錯誤處理

    在 PostgreSQL 中進(jìn)行數(shù)據(jù)的批量導(dǎo)入導(dǎo)出是常見的操作,但有時可能會遇到各種錯誤,下面將詳細(xì)探討可能出現(xiàn)的錯誤類型、原因及相應(yīng)的解決方案,并提供具體的示例來幫助您更好地理解和處理這些問題,需要的朋友可以參考下
    2024-07-07
  • postgres 使用存儲過程批量插入數(shù)據(jù)的操作

    postgres 使用存儲過程批量插入數(shù)據(jù)的操作

    這篇文章主要介紹了postgres 使用存儲過程批量插入數(shù)據(jù)的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-02-02
  • postgresql初始化之initdb的使用詳解

    postgresql初始化之initdb的使用詳解

    這篇文章主要介紹了postgresql初始化之initdb的使用詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • PostgreSQL 刪除check約束的實現(xiàn)

    PostgreSQL 刪除check約束的實現(xiàn)

    這篇文章主要介紹了PostgreSQL 刪除check約束的實現(xiàn),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-02-02
  • postgresql?json取值慢的原因分析

    postgresql?json取值慢的原因分析

    這篇文章主要介紹了postgresql json取值為何這么慢,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-06-06
  • postgresql 中的加密擴(kuò)展插件pgcrypto用法說明

    postgresql 中的加密擴(kuò)展插件pgcrypto用法說明

    這篇文章主要介紹了postgresql 中的加密擴(kuò)展插件pgcrypto用法說明,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • postgresql?IvorySQL新增命令及相關(guān)配置參數(shù)詳解

    postgresql?IvorySQL新增命令及相關(guān)配置參數(shù)詳解

    這篇文章主要為大家介紹了postgresql?IvorySQL新增命令及相關(guān)配置參數(shù)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-12-12
  • PostgreSQL15.x安裝的詳細(xì)教程

    PostgreSQL15.x安裝的詳細(xì)教程

    PostgreSQL 是一個功能強(qiáng)大的開源關(guān)系型數(shù)據(jù)庫系統(tǒng),基于 C 語言實現(xiàn),采用 PostgreSQL 許可證,這是一種自由軟件許可證,允許用戶自由使用、修改和分發(fā)源代碼,所以本文將給大家介紹PostgreSQL15.x安裝的詳細(xì)教程,需要的朋友可以參考下
    2024-09-09
  • Ruoyi從mysql切換到postgresql的幾個踩坑實戰(zhàn)

    Ruoyi從mysql切換到postgresql的幾個踩坑實戰(zhàn)

    最近由于工作的原因,需要將Ruoyi從mysql切換到postgresql,所以這篇文章主要給大家介紹了關(guān)于Ruoyi從mysql切換到postgresql的幾個踩坑實戰(zhàn),需要的朋友可以參考下
    2023-02-02
  • 本地計算機(jī)上的 postgresql 服務(wù)啟動后停止的問題解決

    本地計算機(jī)上的 postgresql 服務(wù)啟動后停止的問題解決

    這篇文章主要介紹了本地計算機(jī)上的 postgresql 服務(wù)啟動后停止的問題解決,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01

最新評論