How to pivot all rows value using sql

Ravi
ID      grp  find
534-1   A    OK
534-1   A    Good
534-1   B    Good
534-1   C    OK
534-2   A    AVERAGE

I wanted to display above table using pivot, It should display all value from above table like this

ID       A          B         C    
534-1    OK        Good       OK    
534-1    Good      NULL       NULL 
534-2    Average   NULL       NULL

I'm using following query

select * 
     from
     #temp1
     pivot(MAX(find)
      for grp in ([A]
     ,[B]
     ,[C])) pvt

But, I'm getting following output, which is missing another value for 534-1.

ID       A         B         C
534-1    OK        Good      OK
534-2    Average   NULL      NULL

Anyone have any idea what am I missing here ?

TechDo

Please try:

select ID,[A],[B],[C] 
from(
    select *,row_number() over (partition by grp order by grp) Col from #temp1
)x pivot
     (MAX(find)
      for grp in ([A]
      ,[B]
      ,[C])) as y

Example at SQL Fiddle.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SQL: how to pivot rows based on its value

From Dev

How to select all rows that share a maximum value in a column using SQL

From Dev

SQL Pivot - How To Show all rows with null values?

From Dev

SQL Pivot - How To Show all rows with null values?

From Dev

Oracle SQL Developer: How to transpose rows to columns using PIVOT function

From Dev

SQL separate columns by rows value (pivot)

From Java

Convert Rows to columns using 'Pivot' in SQL Server

From Dev

How to update column value in all rows that match with employee id in sql

From Dev

SQL: How to get a column's values of all rows as a single value?

From Dev

how to return all rows even when they have no value in Oracle SQL

From Dev

How to find all rows with a NULL value in any column using PostgreSQL

From Dev

SQL PIVOT query is repeating the same values for all pivoted rows

From Dev

Set Value With NULL When Pivot SQL Selection Return 0 Rows

From Dev

Sql Server pivot columns into rows fill NULL with zero or existing value

From Dev

SQL: SELECT value for all rows based on a value in one of the rows and a condition

From Dev

I need to flatten out SQL Server rows into columns using pivot

From Dev

Convert two tables rows to columns in SQL Server using Pivot

From Dev

Increment FK column value of all rows SQL

From Dev

SQL query that removes all rows with certain value?

From Dev

how to get sql select query result as column vs value wise instead of row wise without using PIVOT

From Dev

How to count rows of pivot table where value is greater than 0

From Dev

Excel Pivot Table - How to retrieve value of cell in Rows section

From Dev

how to pivot on number of rows in SQL Server 2008+

From Dev

How to convert multiple rows into one row with multiple columns using Pivot in SQL Server when data having NULL values

From Dev

SQL function on all rows using row parameter

From Dev

SQL PIVOT on a variable amount of rows

From Dev

SQL Query to pivot and combine rows

From Dev

SQL Pivot function to group rows

From Dev

Pivot Rows to Columns Dynamically - SQL

Related Related

  1. 1

    SQL: how to pivot rows based on its value

  2. 2

    How to select all rows that share a maximum value in a column using SQL

  3. 3

    SQL Pivot - How To Show all rows with null values?

  4. 4

    SQL Pivot - How To Show all rows with null values?

  5. 5

    Oracle SQL Developer: How to transpose rows to columns using PIVOT function

  6. 6

    SQL separate columns by rows value (pivot)

  7. 7

    Convert Rows to columns using 'Pivot' in SQL Server

  8. 8

    How to update column value in all rows that match with employee id in sql

  9. 9

    SQL: How to get a column's values of all rows as a single value?

  10. 10

    how to return all rows even when they have no value in Oracle SQL

  11. 11

    How to find all rows with a NULL value in any column using PostgreSQL

  12. 12

    SQL PIVOT query is repeating the same values for all pivoted rows

  13. 13

    Set Value With NULL When Pivot SQL Selection Return 0 Rows

  14. 14

    Sql Server pivot columns into rows fill NULL with zero or existing value

  15. 15

    SQL: SELECT value for all rows based on a value in one of the rows and a condition

  16. 16

    I need to flatten out SQL Server rows into columns using pivot

  17. 17

    Convert two tables rows to columns in SQL Server using Pivot

  18. 18

    Increment FK column value of all rows SQL

  19. 19

    SQL query that removes all rows with certain value?

  20. 20

    how to get sql select query result as column vs value wise instead of row wise without using PIVOT

  21. 21

    How to count rows of pivot table where value is greater than 0

  22. 22

    Excel Pivot Table - How to retrieve value of cell in Rows section

  23. 23

    how to pivot on number of rows in SQL Server 2008+

  24. 24

    How to convert multiple rows into one row with multiple columns using Pivot in SQL Server when data having NULL values

  25. 25

    SQL function on all rows using row parameter

  26. 26

    SQL PIVOT on a variable amount of rows

  27. 27

    SQL Query to pivot and combine rows

  28. 28

    SQL Pivot function to group rows

  29. 29

    Pivot Rows to Columns Dynamically - SQL

HotTag

Archive