Oracle 多行数据合并成一行_oracle多行数据合并成一行_少年民仔的博客-程序员资料

技术标签: 合并多行  Oracle 学习之路  oracle  listagg  数据库  

方案一:wm_concat函数

select username, id, wmsys.wm_concat(subject) as subject, wmsys.wm_concat(score) as score
from STUDENTSCORES
group by username, id

方案二:listagg函数

select username, id, LISTAGG(subject, '-') within group(order by subject) as subject, LISTAGG(score, ',') within group(order by score) as score
from STUDENTSCORES
group by username, id

方案三:常规sql

select username, id, translate(ltrim(subject, '/'), '*/', '*,') as subject,translate(ltrim (score, '/'), '*/', '*,') as score
from 
(select row_number() over (partition by username, id order by username, id, lvl desc) as rn, username, id, subject, score
from 
(select username, id, level lvl,                            sys_connect_by_path (subject, '/') as subject, sys_connect_by_path (score, '/') as score
from 
(select username, id, subject, score,                                       row_number() over (partition by username,id order by username, id) as num from STUDENTSCORES order by username, id)
connect by username = prior username and id = prior id and num - 1 = prior num))
where rn = 1;

注意:

  1. 方案一中默认分隔符为 ‘,’
  2. 方案二只适合11g之后的版本
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/u012414590/article/details/72550925

智能推荐

CCM ——极致发挥STM32F4性能的利器_花洛兮灬的博客-程序员资料

http://blog.sina.com.cn/s/blog_61332ec601016hj6.html**CCM(Core Coupled Memory)是给F4内核专用的全速64KB RAM, 它们没有经过总线矩阵, F4内核与之直接相连, 地址空间在0x1000_0000 ~ 0x1000_FFFF.由于其地址空间和常规的SRAM不连续, 加之DMA和外设也无法直接使用它们, 就使...

OCP-1Z0-051 第130题 LEFT OUTER JOIN的用法_hello_holly的博客-程序员资料

一、原题View the Exhibit and examine the data in the EMPLOYEES table:You want to display all the employee names and their corresponding manager names.Evaluate the following query:SQL> SELECT e.emp

Windows Server 2012 在桌面上显示”我的电脑_我是高手高手高高手的博客-程序员资料

如果是在Windows Server 2012本地控制台下,直接按Win(键盘上的微软徽标键)+R,输入:rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,0回车后,勾选所需要的桌面图标的名称,确定即可。

​程序员离职后收到原公司 2400 元,被告违反竞业协议赔 18 万_唐普开发者程序员:cxyITgc的博客-程序员资料

​程序员离职后收到原公司 2400 元,被告违反竞业协议赔 18 万!到底是怎么回事?

IOS开发之----异常处理_沸腾的泪水05314的博客-程序员资料

转载自:http://blog.sina.com.cn/s/blog_71715bf8010166qf.html开篇大话: Object-C语言的异常处理符号和C++、JAVA相似。再加上使用NSException,NSError或者自定义的类,你可以在你的应用程序里添加强大的错误处理机制。异常处理机制是由这个四个关键字支持的:@try,@catch,@thorw,@finally。当代码

node相关报错问题_gyp info using [email protected]_lily1346891的博客-程序员资料

问题一:node-sass npm ERR! command failed解决:1、删除 npm uninstall node-sass2、安装 npm install node-sass问题二:npm ERR! gyp info it worked if it ends with oknpm ERR! gyp info using [email protected] ERR! gyp info using [email protected] | win32 | x64npm ERR! gyp ERR!

随便推点

sublime text3自定义快捷键_miqi1227的博客-程序员资料

我的sublime text 3 快捷键配置。强烈推荐下面标红的快捷键,谁用谁知道,编码的时候再也不用依赖方向键和鼠标了。[//=======================我的快捷键=======================//// 删除当前行{ "keys": ["ctrl+d"], "command":"run_macro_file", "args":

shell脚本练习题_weixin_30421809的博客-程序员资料

下面列出了几个linux学习中的shell脚本题目1、九九乘法表#!/bin/bashecho "九九乘法表"#注意((之间不能有空格、加减乘除的格式、还有转义字符\*、-nefor (( i=1; i<=9; i=i+1 ))do for (( j=1; j<=i; j=j+1 )) do ((result=$i*$j)) ec...

matlab分段函数中大于、小于(“」”、“「”)的应用_matlab小于_viafcccy的博客-程序员资料

代码范例clc,clear;T=0.001;k1=-1:T:5;f1=2*((k1>0)-(k1>4)); %f1(t)的 MATLAB描述k2=-1:T:3;f2=(k2>0)-(k2>2); %f2(t)信号的描述%画图程序subplot(3,1,1)plot(k1,f1);axis([-1,5,0,2.2]) %f1的显示范围title('f1');

mysql安装图解 mysql图文安装教程(详细说明)_浮生(FS)的博客-程序员资料

很多朋友刚开始接触mysql数据库服务器,下面是网友整理的一篇mysql的安装教程,步骤明细也有详细的说明。MySQL5.0版本的安装图解教程是给新手学习的,当前mysql5.0.96是最新的稳定版本。mysql 下载地址 http://www.jb51.net/softs/2193.html下面的是MySQL安装的图解,用的可执行文件安装的

java面试(进阶四篇)解答_恐龙弟旺仔的博客-程序员资料

题目来自于网络,答案是笔者整理的。仅供参考,欢迎指正来源: https://mp.weixin.qq.com/s?__biz=MzI1NDQ3MjQxNA==&mid=2247485779&idx=1&sn=3b06b9923df7f40f887ead8b8a53e50e&chksm=e9c5f0e2deb279f47fbfc3a12a70896bf95fa8c...

推荐文章

热门文章

相关标签