懵懂的菜鸟

Stay hungry,Stay foolish.

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

pg_sql常用查询语句整理

复制代码
#pg_sql之增删改查

#修改:
inset into table_name
(id,
name,
age,
address
)
select
replace(old_id,old_id,new_id),#old_id字段的old_id数据,替换为new_id
replace(name,name,substring(concat('【新名字】'),name),1,20)),#name字段替换为【新名字】+name
20,
address
from
    table_name
where
    id ='201901'

#增加
inset into table_name
(id,
name,
age,
address,
date
)
values(
'201901',
'xiaoming',
'23',
'上海',
TO_DATE('2006-03-01','YYYY-MM-DD'))

#更新
update table_name
    set id =3
    where id = 2 and name ='xiaoming'

#联表搜索 join on
mybatis注解多条件查询
@Selct({"<script>"+"查询语句"+"</script>"})
List<DemoBo> getListByForm(Page<DemoBo> page,DemoForm demoForm)
查询语句如下:

select
    A.id,
    B.name,
    A.address,
    A.age
from table_nameA as A
    left join table_nameB as B on A.id = B.id
where A.id = 0
    <if test 'id != null'> and A.id <![CDATA[=]]> #{id}</if>
    <if test 'name != null'> and A.name <![CDATA[=]]> #{name}</if>
order by A.age desc,A.id desc

#条件判断 case when
selct a.id ,a.name,a.age
    case when
        b.begindate = b.enddate
        then 1
        else 0
    end as f_date
from table_nameA as a
    inner join(
            selct id,
            count(*) as count,
            sum(case when age =2 then 1 else 0 end) as age
            from table_nameB
            group by id
        ) as b on a.id = b.id
where a.id =1232
复制代码

 

posted on   懵懂的菜鸟  阅读(1788)  评论(0编辑  收藏  举报

编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
历史上的今天:
2018-05-11 spass按位置编码,进行排序题处理与分析
点击右上角即可分享
微信分享提示