pgsql 记录

查询 pgsql可使用的内存

SHOW work_mem;

ALTER SYSTEM SET work_mem= 2097151; 

pgsql查询两张表的百分比

SELECT
CAST (
(
COUNT (DISTINCT s.userid) / CAST (
COUNT (DISTINCT u.userid) AS DECIMAL
)
) * 100 AS INT
)
FROM
portal.system_record s,
portal.sys_user 

 pgsql查询时间  

当前时间向前推一天\

SELECT current_timestamp - interval '1 day'

求出最近7天的数据
select * from 表名 where date between (SELECT current_timestamp - interval '7 day') and current_timestamp

当前时间向前推进一个月
SELECT current_timestamp - interval '1 month'

当前时间向前推进一年

SELECT current_timestamp - interval '1 year'
当前时间向前推一小时:
SELECT current_timestamp - interval '1 hour'
当前时间向前推一分钟:
SELECT current_timestamp - interval '1 min'
当前时间向前推60秒:
SELECT current_timestamp - interval '60 second'





select * from task where to_date(deadline, 'yyyymm')<to_date('201909', 'yyyymmdd')//查询指定月份之前

 select * from task where to_date(deadline, 'yyyymmdd')<now()   //查询当前日期之前   

 

 

id自增

创建一个序列
CREATE SEQUENCE upms_log_id_seq START 10;

然后 

nextval(' upms_log_id_seq')

从一张表插入到另一张表

INSERT INTO "portal"."system_log_analysis" ("userid", "anchor_point_1", "anchor_point_2","action", "time")
select s.userid,s.moudle,s.sub_module,s."action",s."time" from system_record s

 

 




 
posted @ 2020-04-21 16:04  一杯清茶一本书  阅读(328)  评论(0编辑  收藏  举报