Posts

Showing posts with the label pivot

PostgreSQL multiple row as columns

Image
Clash Royale CLAN TAG #URR8PPP PostgreSQL multiple row as columns I have a table like this: | id | name | segment | date_created | question | answer | |----|------|---------|--------------|----------|--------| | 1 | John | 1 | 2018-01-01 | 10 | 28 | | 1 | John | 1 | 2018-01-01 | 14 | 37 | | 1 | John | 1 | 2018-01-01 | 9 | 83 | | 2 | Jack | 3 | 2018-03-11 | 22 | 13 | | 2 | Jack | 3 | 2018-03-11 | 23 | 16 | And I want to show this information in a single row, transpose all the questions and answers as columns: | id | name | segment | date_created | question_01 | answer_01 | question_02 | answer_02 | question_03 | answer_03 | |----|------|---------|--------------|-------------|-----------|-------------|-----------|-------------|-----------| | 1 | John | 1 | 2018-01-01 | 10 | 28 | 14 | 37 | 9 | 83 | | 2 | Jack | 3 | 2018-03-11 | ...

SQL help pivoting a single table

Image
Clash Royale CLAN TAG #URR8PPP SQL help pivoting a single table I have a table containing several columns. There are multiple records that contain the same info except for the last column which is different. I need this last column to be combined into one row as additional columns. There will only be up to 3 additional columns (course, course2, course3). Below is my table layout. Thanks for any help. Columns EmployeeNumber Email LastName FirstName Address1 City State Zip Phone Certified School EmployeeType BirthDate Course StaffNumber The only column that will contain different data that I need to combine is Course. Otherwise, there will be several rows with identical data that I need to combine into one. Sorry, I said last column, but it's the next to last column containing different info. – Jeff Green 1 min ago ...