将多行转换为多列 [英] Convert multiple rows into one row with multiple columns
本文介绍了将多行转换为多列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含以下信息的表:
I've a table containing information as follows:
idnumber applic_id cctype ccnumber
--------- ------------ -------- ----------
1 23 1 223445
2 23 2 345567
我需要查询以下内容:
idnumber applic_id cctype ccnumber idnumber applic_id cctype ccnumber
--------- ------------ -------- ---------- --------- ------------ -------- ----------
1 23 1 223445 2 23 2 345567
有人知道吗?我正在使用PostgreSQL 8.3。
Is anyone have a clue? I'm using PostgreSQL 8.3.
推荐答案
您可以使用 CASE
语句
或使用
You can use CASE
statements for simple queries.
Or use the crosstab()
function of the tablefunc module for more complex cases and better performance.
此相关问题下的案例:
PostgreSQL交叉表查询
You can find examples for both cases under this related question:
PostgreSQL Crosstab Query
这篇关于将多行转换为多列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文