Home Database Mysql Tutorial 分组合并多列

分组合并多列

Jun 07, 2016 pm 02:56 PM
Group merge multiple columns Version

Oracle9i及以前的版本中,没有可直接支持的分组后,用某个特殊字符进行分隔列 像10g有wm_concat,11g可以用listagg(字段,分隔字符) within group(order by 字段) Oracle SELECT 分组列,ltrim(MAX(sys_connect_by_path(字符串列,',')),',')FROM (SELECT 分组列

Oracle9i及以前的版本中,没有可直接支持的分组后,用某个特殊字符进行分隔列
像10g有wm_concat,11g可以用listagg(字段,分隔字符) within group(order by 字段)
Oracle
SELECT 分组列,ltrim(MAX(sys_connect_by_path(字符串列,',')),',')
FROM (
SELECT 分组列,字符串列,rank()over(ORDER BY 分组列) + row_number()over(order by 分组列) RN,row_number()over(partition by 分组列 order by 分组列) RM
FROM 表)
start with RM=1
connect by prior RN=RN-1
group by
分组列
;

--在FROM 表这个地方你可以过滤掉这些空值
--或在ltrim(MAX(sys_connect_by_path(字符串列,',')),',')这个地方

--再加个这个就可以rtrim(ltrim(MAX(sys_connect_by_path(字符串列,',')),','),',')
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to quickly check numpy version How to quickly check numpy version Jan 19, 2024 am 08:23 AM

How to quickly check numpy version

How to check maven version How to check maven version Jan 17, 2024 pm 05:06 PM

How to check maven version

Tutorial on updating curl version under Linux! Tutorial on updating curl version under Linux! Mar 07, 2024 am 08:30 AM

Tutorial on updating curl version under Linux!

Simple steps to update pip version: done in 1 minute Simple steps to update pip version: done in 1 minute Jan 27, 2024 am 09:45 AM

Simple steps to update pip version: done in 1 minute

Check the Kirin operating system version and kernel version Check the Kirin operating system version and kernel version Feb 21, 2024 pm 07:04 PM

Check the Kirin operating system version and kernel version

Interpret the meaning and difference of PHP version NTS Interpret the meaning and difference of PHP version NTS Mar 27, 2024 am 11:48 AM

Interpret the meaning and difference of PHP version NTS

How to easily install Python on Windows, you can choose from two methods How to easily install Python on Windows, you can choose from two methods Feb 18, 2024 pm 04:57 PM

How to easily install Python on Windows, you can choose from two methods

How to easily check the installed version of Oracle How to easily check the installed version of Oracle Mar 07, 2024 am 11:27 AM

How to easily check the installed version of Oracle

See all articles