r
rushi chowdary

Posted on 27th April 2024|1803 views

0
votes

Postgresql Pivot Without Crosstab

How to create pivot without crosstab in PostgreSQL?

Answers
P
Harish Harsh

Posted on 27th April 2024

No, you cannot create a Pivot table in PostgreSQL without using crosstab function as you have to use a tablefunc module for a required database.

  • Pivot is the modified, detailed and straightforward data table of crosstab table.
  • By taking random data or raw data, you can modify it to the crosstab table directly by using the crosstab function afterwards. You can convert it to Pivot table using Pivot function.  
  • Pivot and crosstab are similar to each other, but Pivot generated without writing a function.
  • As Pivot is used to organise, sort, group, sum or average data stored and this da give data relations except that it is similar to crosstab table.

Raw data using crosstab() function before Pivoting:

Student

Subject

Evaluation_result

Smith, John

Music

7.0

Smith, John

Maths

4.0

Smith, John

History

9.0

Smith, John

Language

7.0

Smith, John

Geography

9.0

Gabriel, Peter

Music

2.0

Gabriel, Peter

Maths

10.0

Gabriel, Peter

History

7.0

Gabriel, Peter

Language

4.0

Gabriel, Peter

Geography

10.0

After Pivoting table:

Student

Geography 

History

Language

Maths

Music

Gabriel, Peter

10.0

7.0

4.0

10.0

2.0

Smith, John

9.0

9.0

7.0

4.0

7.0

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos