在oracle中将行拆分为列 [英] Splitting rows to columns in oracle

查看:142
本文介绍了在oracle中将行拆分为列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表格中的数据如下:

I have data in a table which looks like:

我想通过Oracle中的sql查询(不使用数据透视)拆分其数据,并使数据如下所示:

I want to split its data and make it look like the following through a sql query in Oracle (without using pivot):

该怎么办?不用枢轴还有其他方法吗?

How can it be done?? is there any other way of doing so without using pivot?

推荐答案

您需要在此处使用数据透视查询来获取所需的输出:

You need to use a pivot query here to get the output you want:

SELECT Name,
       MIN(CASE WHEN ID_Type = 'PAN'      THEN ID_No ELSE NULL END) AS PAN,
       MIN(CASE WHEN ID_Type = 'DL'       THEN ID_No ELSE NULL END) AS DL,
       MIN(CASE WHEN ID_Type = 'Passport' THEN ID_No ELSE NULL END) AS Passport
FROM yourTable
GROUP BY Name

如果您正在运行11g或更高版本,也可以尝试使用Oracle内置的PIVOT()函数.

You could also try using Oracle's built in PIVOT() function if you are running version 11g or later.

这篇关于在oracle中将行拆分为列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆