pgsql或取最新的一条数据
2022/7/22 2:22:50
本文主要是介绍pgsql或取最新的一条数据,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
SELECT company.id,company.zz,snap.xydm,snap."companyName", p.xm fr from (
SELECT a.id,string_agg(
case
when d.zzlx = 1 then '路基路面'
when d.zzlx = 2 then '桥梁'
when d.zzlx = 3 then '隧道'
when d.zzlx = 4 then '交通安全设施' end
||
case
when d.zzdj = 1 then '甲级'
when d.zzdj = 2 then '乙级'
else '' end , ',') as zz
from company_info a
left join company_info_snapshot b on a.id = b.company_id
left join company_aptitude_r c on c.snapshot_id = b.id
left join aptitude d on c.aptitude_id = d.id
where d.id is not null and a.del_flag = 2 and d.del_flag = 2 and b.del_flag = 2 and zt = 2
and concat(a.name,a.xydm) like concat('%','','%')
GROUP BY a.id
) company
left join (
SELECT company_id,(array_agg(id order by create_time desc ))[1] snapshot_id,
(array_agg(name order by create_time desc ))[1] as "companyName",
(array_agg(xydm order by create_time desc ))[1] xydm,
(array_agg(fddbr order by create_time desc ))[1] fddbr
from company_info_snapshot
GROUP BY company_id
) snap on snap.company_id = company.id
left join personnel p on p.id = snap.fddbr
搜索
复制
这篇关于pgsql或取最新的一条数据的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23Springboot应用的多环境打包入门
- 2024-11-23Springboot应用的生产发布入门教程
- 2024-11-23Python编程入门指南
- 2024-11-23Java创业入门:从零开始的编程之旅
- 2024-11-23Java创业入门:新手必读的Java编程与创业指南
- 2024-11-23Java对接阿里云智能语音服务入门详解
- 2024-11-23Java对接阿里云智能语音服务入门教程
- 2024-11-23JAVA对接阿里云智能语音服务入门教程
- 2024-11-23Java副业入门:初学者的简单教程
- 2024-11-23JAVA副业入门:初学者的实战指南