随笔 - 144  文章 - 0  评论 - 2  阅读 - 92190

oracel中将子表中一个字段多条数据合并到主表的sql

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
select f.* ,g.nsjgName, h.XCJZZZZ, h.XCJFZZZ
  from (select max(t.JGSY_NAMEs) JGSY_NAMEs,
               max(t.jgsy_gg) jgsy_gg,
               jgsy_code,
               sum(t.zcjzs) zcjzs,
               sum(t.fcjzs) fcjzs,
               listagg(t.pzwh, ',') within group(order by t.jgsy_code) pzwh,
               listagg(t.BEIZHU, ',') within group(order by t.jgsy_code) beizhu
          from s_zsys t
         where t.BLRESULT = '3'
           and substr(t.jgsy_code, 0, 6) = '320100'
         group by jgsy_code
         order by t.jgsy_code) f
  left join (select jgsy_parent_code,
                    listagg(jgsy_name, ',') within group(order by gen.jgsy_parent_code) nsjgName
               from jgsy_common gen
              where 1 = 1
                and gen.jgsy_type = '06'
              group by jgsy_parent_code) g
    on g.jgsy_parent_code = f.jgsy_code
  left join BMLDZS h
    on h.jgsy_code = f.jgsy_code;<br><br>
 
--select * from jgsy_common  f where f.jgsy_parent_code='320100-01-10012'  and f.jgsy_type='06'<br><br><br>注意用这个函数可以知道那个是统计列【grouping函数】<br>select max(code) code,case when grouping (code) = 1 then '0'  end  orders,max(name) name,

  

1
grouping
posted on   IT-QI  阅读(280)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 提示词工程——AI应用必不可少的技术
· 地球OL攻略 —— 某应届生求职总结
· 字符编码:从基础到乱码解决
· SpringCloud带你走进微服务的世界
< 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

点击右上角即可分享
微信分享提示