oracle – LISTAGG功能与两列
发布时间:2020-12-12 15:12:59 所属栏目:百科 来源:网络整理
导读:我有这样一张桌子(报告) --------------------------------------------------| user_id | Department | Position | Record_id |--------------------------------------------------| 1 | Science | Professor | 1001 || 1 | Maths | | 1002 || 1 | History
我有这样一张桌子(报告)
-------------------------------------------------- | user_id | Department | Position | Record_id | -------------------------------------------------- | 1 | Science | Professor | 1001 | | 1 | Maths | | 1002 | | 1 | History | Teacher | 1003 | | 2 | Science | Professor | 1004 | | 2 | Chemistry | Assistant | 1005 | -------------------------------------------------- 我想要得到以下结果 --------------------------------------------------------- | user_id | Department+Position | --------------------------------------------------------- | 1 | Science,Professor;Maths,; History,Teacher | | 2 | Science,Professor; Chemistry,Assistant | --------------------------------------------------------- 这意味着我需要保留空格,就像在结果表中看到的那样. SELECT user_id,LISTAGG(department,';') WITHIN GROUP (ORDER BY record_id) FROM report 提前致谢 :-) 在集合中只需要明智地使用连接:select user_id,listagg(department || ',' || nvl(position,' '),'; ') within group ( order by record_id ) from report 即通过逗号和位置聚合部门的连接,如果为空,则将其替换为空格. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Swift之小项目实战
- React实践 - Component Generator
- objective-c – (Cocoa)在单个窗口可可应用程序中,UIViewCo
- reactos操作系统实现(47)
- 【Bug记录】Anroid解析xml 出现unexpected token错误
- ruby-on-rails – 未定义的方法`symbolize_keys!’ 2:Fix
- actionscript-3 – 在蒙皮时访问hostComponent的自定义属性
- Oracle:序列MySequence.currval在此会话中尚未定义
- 如何在页面标签(textaera)禁止修改状态下可以修改.
- 如何将Swift中的String转换为字节?
推荐文章
站长推荐
热点阅读