Oracle很好的自动拼接某个字段的函数listagg使用实例

with mes1 as

(

select c.cugrnname,cdd.cuassociatepackingname,c.cuReceiveTime,c.cuReceivePerson,

CASE WHEN c.custatus = 1 THEN N'已发送'

ELSE N'已接收' END custatus

,c.cuSendTime, c.cuSendPerson,cdd.cupackingworkcenter,cdd.cuqty,pb.PRODUCTNAME,p.description,cdd.description as Reworks ,c.cuconfirmperson as CONFIRM

from cugrn c

inner join cuDetails cd on cd.cugrnid = c.cugrnid

inner join cuassociatepacking cdd on cdd.cuassociatepackingid = cd.cuassociatepackingid

inner join product p on p.productid = cdd.cuproductid

inner join productbase pb on pb.productbaseid = p.productbaseid

where c.cugrnname = N'M221124014' or cdd.cuassociatepackingname = N'1'

),

mes2 as

(

select th,max(gd) as gd

from

(

select 托号 as th, listagg(工单,',') within group ( order by 托号) over (partition by 托号) gd

-----很好的自动拼接某个字段的函数

from

( SELECT C1.CUASSOCIATEPACKINGNAME as 托号,

MO.MFGORDERNAME as 工单

FROM cuAssociatePacking c1

inner join cuAssociateDetails c2 on c1.cuassociatepackingid = c2.cuassociatepackingid

left join cuAssociatePacking C5 on c5.cuassociatepackingname = C2.CUSONLOT

left join cuAssociateDetails c6 on c6.cuassociatepackingid = c5.cuassociatepackingid

left join container C7 on c7.containerid = c6.cufromlotid

LEFT join cucontainergraderrecord ccd on ccd.containername=C7.containername

inner join mfgorder mo on ccd.cuworkorder = mo.mfgordername

inner join mes1 m1 on m1.cuassociatepackingname=c1.CUASSOCIATEPACKINGNAME

where c1.cupackingtype='Pallet' ---and c1.cupackingtime>sysdate-1

group by c1.CUASSOCIATEPACKINGNAME,mo.mfgordername

)t

)t1

group by t1.th ----确保一条记录

)

select m1.*,m2.gd

from mes1 m1

left join mes2 m2 on m1.CUASSOCIATEPACKINGNAME=m2.th

相关推荐
零炻大礼包38 分钟前
【SQL server】数据库远程连接配置
数据库
zmgst1 小时前
canal1.1.7使用canal-adapter进行mysql同步数据
java·数据库·mysql
随心............1 小时前
python操作MySQL以及SQL综合案例
数据库·mysql
€☞扫地僧☜€1 小时前
docker 拉取MySQL8.0镜像以及安装
运维·数据库·docker·容器
CopyDragon1 小时前
设置域名跨越访问
数据库·sqlite
xjjeffery1 小时前
MySQL 基础
数据库·mysql
写bug的小屁孩1 小时前
前后端交互接口(三)
运维·服务器·数据库·windows·用户界面·qt6.3
恒辉信达1 小时前
hhdb数据库介绍(8-4)
服务器·数据库·mysql
齐 飞2 小时前
MongoDB笔记01-概念与安装
前端·数据库·笔记·后端·mongodb
云空2 小时前
《Python 与 SQLite:强大的数据库组合》
数据库·python·sqlite