Home  >  Article  >  Database  >  What is the row to column function in Oracle?

What is the row to column function in Oracle?

WBOY
WBOYOriginal
2022-01-24 16:02:5831953browse

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

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!

Statement:
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