Home > Database > Oracle > body text

What is the row to column function in Oracle?

WBOY
Release: 2022-01-24 16:02:58
Original
32024 people have browsed it

In Oracle, the function for converting rows to columns is the pivot() function. The function of this function is to convert rows into columns. The syntax is "pivot (aggregation function for column name in (type))"; where An alias can be specified in "in('')", and a subquery can also be specified in in.

What is the row to column function in Oracle?

The operating environment of this tutorial: Windows 10 system, Oracle 11g version, Dell G3 computer.

What is the row-to-column function in Oracle

oracle—pivot row-to-column

Group display processing of the result set.

What is the row to column function in Oracle?

--行转列
select *
  from SalesList pivot(
    max(salesNum) for shangPin in (    --shangPin 即要转成列的字段
        '上衣' as 上衣,                 --max(salesNum) 此处必须为聚合函数,
        '裤子' as 裤子,                 --in () 对要转成列的每一个值指定一个列名
        '袜子' as 袜子,
        '帽子' as 帽子
    )
  )
 where 1 = 1;                          --这里可以写查询条件,没有可以直接不要where
Copy after login

Note: pivot (aggregation function for column name in (type)), where in('') can specify an alias, and in in can also specify a subquery, such as select distinct code from customers

Add a column named in to the column, and the corresponding values ​​will be aggregated and displayed

Recommended tutorial: "Oracle Video Tutorial"

The above is the detailed content of What is the row to column function in Oracle?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template