饿虎岗资源网 Design By www.oxmxm.com

PGSQL查询今天的数据

select *
 from 表名 as n
 where n.create_date>=current_date;

PG查询昨天的数据

方法1:

 select *
 from 表名 as n
 where
    age(
    current_date,to_timestamp(substring(to_char(n.create_date, 'yyyy-MM-dd hh24 : MI : ss' ) FROM 1 FOR 10),'yyyy-MM-dd')) ='1 days';

方法2:

select *
 from 表名 as n
 where n.create_date>=current_date-1 and n.create_date <current_date;

n.create_date 是一个timestamp的数据;

current_date是pgsql数据一个获取当前日期的字段;

to_char(timestamp,text)把timestamp数据转换成字符串;

substring(text from int for int) 截取想要的文本格式 ‘yyyy-MM-dd';

to_timestamp(text,'yyyy-MM-dd')转换成timestamp格式;

age(timestamp,timestamp)获取两个时间之差 返回 days

PG查询最近一个月内的数据

select *
 from 表名 as n
 and n.create_date>=to_timestamp(substring(to_char(now(),'yyyy-MM-dd hh24:MI:ss') FROM 1 FOR 10),'yyyy-MM-dd')- interval '30 day';

补充:postgresql 查询当前时间

需求:PostgreSQL中有四种获取当前时间的方式。

解决方案:

1.now()

PGSQL 实现查询今天,昨天的数据,一个月之内的数据

返回值:当前年月日、时分秒,且秒保留6位小数。

2.current_timestamp

PGSQL 实现查询今天,昨天的数据,一个月之内的数据

返回值:当前年月日、时分秒,且秒保留6位小数。(同上)

申明:now和current_timestamp几乎没区别,返回值相同,建议用now。

3.current_time

PGSQL 实现查询今天,昨天的数据,一个月之内的数据

返回值:时分秒,秒最高精确到6位

4.current_date

PGSQL 实现查询今天,昨天的数据,一个月之内的数据

返回值:年月日

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。如有错误或未考虑完全的地方,望不吝赐教。

饿虎岗资源网 Design By www.oxmxm.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
饿虎岗资源网 Design By www.oxmxm.com

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。

更新日志