Questions tagged [unpivot]

UNPIVOT describes a Query Language feature of some Relational Databases. The UNPIVOT feature converts columnar data into row data, and vice versa for the PIVOT feature.

Overview

UNPIVOT describes a Query Language feature of some Relational Databases. The UNPIVOT feature converts columnar data into row data, and vice versa for the PIVOT feature.

Databases that support PIVOT/UNPIVOT syntax:

  • Oracle 11g+
  • SQL Server 2005+

Alternative approaches

While MySQL does not have a UNPIVOT function, this can be replicated using a SELECT statement with UNION ALL for each column.

Alternative meanings

UNPIVOT is also a feature of other applications such as Business Intelligence Query tools and some spreadsheets.

1361 questions
-3
votes
1 answer

mysql moving 2 columns to one reordening the data where not 0

Could this table be re-arranged into one table (using a view ) +----+------+--------+ | id | item1| item2 | +----+------+--------+ | 1 | A | B | | 2 | 0 | B | | 3 | A | 0 | | 4 | 0 | 0 …
user3845661
-3
votes
2 answers

Display the Alternative columns from table row

enter image description here Display the Alternative columns from table row
-3
votes
3 answers

Select a value of a view with view name and column name

What I have: VIEW A uid name 10 test1 20 test2 30 test3 40 test4 What I want: ViewName ColName Row Value View A uid 1 10 View A name 1 test1 View A uid 2 20 View A name 2 test2
PassionateDeveloper
  • 14,558
  • 34
  • 107
  • 176
-3
votes
3 answers

Is there a way to transpose groups of columns to rows in excel?

My source table in excel looks like this: code name1 perc1 name2 perc2 name3 perc3 11 x 10 x2 20 x3 70 12 y 20 y2 80 13 z 100 45 q 15 q2…
HamiEbra
  • 310
  • 2
  • 7
-3
votes
1 answer

Oracle 11g unpivot very slow - low performance

My query's unpivot query performance is very low, it runs very slowly and takes around 11s to execute, while the base query that it's based on takes around 60ms to execute. The base query is complex, with several joins, but it returns only a few…
Dariusz
  • 21,561
  • 9
  • 74
  • 114
-3
votes
2 answers

Oracle SQL - Combine two columns into one

I have a table Column 1 Column 2 A B B C C D C E Now I want the output like below (All possible routes from A to end point like A-B-C-D, A-B-C-E) Column 1 A B C D …
badkarma
  • 31
  • 1
  • 7
-3
votes
1 answer

T-SQL (Un)Pivot Table

I have a view as follows (did a view as I thought it would be easier that accessing the more complicated table) ID | aText1 | aText2 | aInt1 | aInt2 ------------------------------------- 1 | ABC1 | XYZ1 | 2 | 20 2 | ABC1 | XYZ2 | 3 …
pee2pee
  • 3,619
  • 7
  • 52
  • 133
-3
votes
2 answers

Variation of pivot in SQL

I have a table similar to: +------+----------+----------+----------+----------+ | Name | Subject1 | Subject2 | Subject3 | Subject4 | +------+----------+----------+----------+----------+ | x | 10 | 11 | 12 | 13 | | y | …
-3
votes
1 answer

SQL Pivot based on multiple columns

Hi I am New to SQL Pivoting I have different requirement where i need to Pivot data based on multiple columns(Q1,Q2,Q3,Q4) based on Categories for Programs. Please advice how can I achieve this? All examples are based on a single column( eg. SUM(Q1)…
Biju Thomas
  • 1,079
  • 3
  • 14
  • 27
-5
votes
1 answer

Pivoting rows to columns for each id

I want to pivot rows into columns in Postgres 10. Here is the example data on db-fiddle: I want to achieve the following output:
kimi
  • 525
  • 5
  • 17
1 2 3
90
91