PostgreSQL 常用语句

## 更新JSON,JSONB字段
update 表名 set 列名 = (jsonb_set(列名::jsonb,'{key}','"value"'::jsonb)) where 条件 
## 旧表的数据插入到新表
INSERT INTO 表名 (字段名) SELECT 字段名 FROM 表名
## 执行计划
explain analyze [sql语句]
## sum求和后,添加默认值0
select coalesce(sum(field_name), 0) from table_name
## Case when用法
select case when 字段名= 1 then '1' when 字段名= 2 then '2' else '默认值' end as 别名 from 表名
## 日期分组
select (select enterprise_name from user_enterprise where enterprise_id = tag_bind_related.enterprise_id) as 企业 ,to_char(create_time , 'yyyyMMdd') as 日期, count(*) 数量 from tag_bind_related where create_time > '2021-03-17 00:00:00' and enterprise_id  != create_user_id 
group by enterprise_id , 日期 
## 格式转换
select cast(FIELD_NAME as text) from TABLE_NAME
## 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值