查询以水平显示输出 [英] Query to display output horizontally

查看:61
本文介绍了查询以水平显示输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以水平方式显示查询输出.我有一些示例数据

I need to display a query output in a horizontal manner. I have some example data

create table TestTable (id number, name varchar2(10))

insert into TestTable values (1, 'John')
insert into TestTable values (2, 'Mckensy')
insert into TestTable values (3, 'Valneech')
insert into TestTable values (4, 'Zeebra')

commit

select * from TestTable

这将获得垂直视图的输出.

This gets the output in a vertical view.

ID Name
==========
1  John
2  Mckensy
3  Valneech
4  Zeebra

但是,我需要水平显示它.

However, I need to display it horizontally.

ID   1    2       3        4
Name John Mckensy Valneech Zeebra

这怎么办?

推荐答案

要进行透视,应使用这在SQL中并不是很漂亮,因此您应该仔细考虑这是否是您想要的.我通常使用 Oracle Base 进行数据透视例子,但是有很多.

This is not particularly pretty to do in SQL, so you should consider carefully whether this is what you want to do. I normally use Oracle Base for pivoting examples but there are many out there.

这里有一些 SQL小提琴来演示.

这篇关于查询以水平显示输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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