Questions tagged [pivot]

The PIVOT syntax converts row data into columnar data, and vice versa for the UNPIVOT syntax. The syntax is non-standard, and not all databases support the PIVOT syntax, but the functionality can be implemented, often using decision logic (CASE expressions, etc) and aggregate functions.

The PIVOT syntax converts row data into columnar data, and vice versa for the UNPIVOT syntax. The syntax is non-standard, and not all databases support the PIVOT syntax, but the functionality can be implemented, often using decision logic (CASE expressions, etc) and aggregate functions.

The PIVOT operation may also be referred to as cross-tabulation or .

Similar functionality also exists in data processing tools/packages such as (via pivot method), (via pivot_wider function), and (via unstack function).

Databases that support PIVOT/UNPIVOT syntax:

  • Oracle 11g+
  • SQL Server 2005+

While MySQL does not have a PIVOT function, this can be replicated using an aggregate function and either a CASE statement or IF()

PostgreSQL (true in 9.3 and below, at least) do not offer PIVOT, but do supply the crosstab function from the bundled tablefunc extension. This function may be used, albeit awkwardly, to achieve the same effect.

Reference:

11340 questions
2
votes
0 answers

pivot table with duplicate entries without aggregating/grouping using scala and spark-sql

I have a situation similar to that mentioned in this question. But my complete project is in Scala and I'd prefer to exploit scala / spark-sql APIs for time and package-building-and-deployment constraints. Do we have a method similar to…
shripal mehta
  • 401
  • 4
  • 21
2
votes
1 answer

SQL Server 2008 Pivot without knowing for values

In SQL server 2008, I have below table. I do not how to use Pivot without giving for value in ([val1],[val2],[val2],..) Any hep in this regard will be greatly appreciated. Thanks. create table [VJ1].[dbo].[pivot] (class varchar(25) null, name…
user219628
  • 3,755
  • 8
  • 35
  • 37
2
votes
2 answers

Implementing pivot table in Java

I need to implement a pivot table in Java and I know how to do with Java 8 Streams features. There are a lot of good solution over the web but I need something more and I don't understand how to do that: I need to create a more dynamic table where…
marks
  • 31
  • 9
2
votes
2 answers

Reordering pandas dataframe data for a multiindex after pivot

I'm building an analysis tool for public transportation data and want to reorder data in a pandas dataframe that can be best explained using the following example: My initial shape of data is: Population …
paweloque
  • 18,466
  • 26
  • 80
  • 136
2
votes
2 answers

Convert the Pivot table in MS Access to Pivot table in SQL Server

I need to convert some SQL statement from MS Access to SQL Server using a pivot table. I have a view [UETTDRSB39A Criteria] and a table [RPLEvidence options]. I have never tried using pivot tables in SQL Server. The MS Access code is: TRANSFORM…
Twini
  • 195
  • 16
2
votes
1 answer

Pandas pivot with duplicates

The sample data looks like this: d = pd.DataFrame({'name': ['Adam', 'Adam', 'Bob', 'Bob', 'Craig'], 'number': [111, 222, 333, 444, 555], 'type': ['phone', 'fax', 'phone', 'phone', 'fax']}) name number type ------ …
Xiaoyu Lu
  • 3,280
  • 1
  • 22
  • 34
2
votes
2 answers

Reshape long format to wide format with two columns for each observation in long format

I am trying to reshape a pandas dataframe with the following long format: ISO3 Indicator Year Value FRA Pop. density 2003 113,6 FRA Pop. density 2004 114,5 FRA Pop. density 2005 115,4 USA Pop. density …
Laurens
  • 85
  • 7
2
votes
0 answers

How to SetSourceData on a Chart. Getting error: "HRESULT E_FAIL has been returned from a call to a COM component"

I'm trying to create two charts on a pivot table. When I create the first one it's ok, but when I try to create the second one I'm getting this following error: "HRESULT E_FAIL has been returned from a call to a COM…
ygorrios
  • 21
  • 2
2
votes
0 answers

How to include ' partition by ' in TD15 Pivot function?

Right now I'm having query like this - SELECT a, b, SUM (CASE WHEN measure_name = 'ABC' THEN measure_qty END) OVER (PARTITION BY a, b ) AS ABCPIVOT FROM data_app.work_test Now as TD15 is supporting direct PIVOTING. How do I…
XYZ123
  • 21
  • 3
2
votes
1 answer

Pandas pivoting more than one column in index

I have a dataframe: In [1]: import pandas as pd ...: ...: df = pd.DataFrame([['dicts', 'oui_lookup', 'MergeTree', 'ipdr1']], colum ...: ns=['database', 'table', 'engine', 'server']) ...: df …
user3225309
  • 1,183
  • 3
  • 15
  • 31
2
votes
1 answer

Laravel pivot relationship on relationship (Eloquent)

In Laravel, is it possible to put a relationship within a relationship? Basically, I already have a relationship set up, but I then need another relationship for that relationship (if that makes sense). My two models: Store Supplier My…
Mr Digital
  • 29
  • 3
2
votes
2 answers

sql server pivot table query

we are trying to convert an attendance log data into a pivot table . for the sake of simplicity, the actual data is in the form : EmployeeId, InOrOut, DateTime 1 0 2019-01-01 08:00:00 1 1 2019-01-01 17:00:00 1 …
Abdul Ali
  • 1,905
  • 8
  • 28
  • 50
2
votes
1 answer

Popups in Pivot

I have a Pivot layout with three items. One holds news for today, the second shows news for the week and in the third one you can search by date. If there aren't news for today yet, I show a message through a popup. I use a popup because I can put…
enkara
  • 6,189
  • 6
  • 34
  • 52
2
votes
1 answer

ReOrder Column in Pivot table

I am looking for a way to reorder column in my Pivot Table Here rare my columns : pivot.columns pivot = dfpivot.pivot_table(index=['DEPARTMENT_NAME','LEVEL_NAME','NAME','CLTNAME'],columns=['StaffitWeek'], values=['ASSIGN_TIME'], margins=False,…
atomi kise
  • 93
  • 10
2
votes
2 answers

Dynamically generated Excel Xml (thru OpenXml) has a x: in all of its tags

So, I dynamically created a PivotTable on an empty workbook (with data connections built already), and saved successfully: the document is even opened successfully why Excel GUI: everything seems right and working properly. When I looked inside the…
Frank
  • 23
  • 2