SSIS - pivoting duplicate values in multiple records

AndreA

I have a situation like this:

ID  TYPE    TIMESTAMP
1   A       22/06/2015 03:55:02
1   A       22/06/2015 03:55:05
1   B       22/06/2015 03:55:10

Of course if i try to pivot SISS gives an error telling that there is a duplicate value in the TYPE for that ID; so I thought it would be nice to have a result like this:

ID  occurrence  A                       B
1   1           22/06/2015 03:55:02     22/06/2015 03:55:10
1   2           22/06/2015 03:55:05

It would be also nice if the fist occurrence would be filled with the earlier timestamps of the events (A and B), but I think this will be done just by ordering correctly.

Can this be done?

JamieD77

You should be able to use ROW_NUMBER to create the "Occurrence" column and pivot the data based on Type

SELECT  * 
FROM (  
        SELECT  *,
                ROW_NUMBER() OVER(PARTITION BY [ID], [Type] ORDER BY [TimeStamp]) Occurrence  
        FROM    Test
) t
PIVOT
(       MAX([TimeStamp])
        FOR [Type] IN ([A],[B])
) p

DEMO

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Pivoting a pandas dataframe with duplicate index values

From Dev

SQL : Flag multiple records with duplicate values but in alternate columns

From Dev

List records with duplicate values

From Dev

Ignore duplicate records in SSIS' OLE DB destination

From Dev

Pivoting a table with duplicate index

From Dev

Treating Null values and duplicate records in SQL Server

From Dev

Need help updating records with duplicate values in MySQL

From Dev

Replace duplicate values only in consecutive records with NULL

From Dev

SQL Query to select records without duplicate values

From Dev

Pivoting based on unique values

From Dev

Delete duplicate records based on multiple columns

From Dev

Check multiple columns for duplicate and list all records

From Dev

Multiple sets of duplicate records from a pandas dataframe

From Dev

SQL - Pivoting on Column and Row Values

From Dev

dataframe slicing and pivoting then into multiple dataframes

From Dev

Pivoting multiple columns in C#

From Dev

Show First instance of records with duplicate values in tow colums

From Dev

Obtain records with multiple instances of field values

From Dev

Find group of records that match multiple values

From Dev

Find records with multiple foreign key values in Rails

From Dev

Update multiple records with different incremental values

From Dev

MySQL: Select multiple records with comma separated values

From Dev

Update multiple records with different incremental values

From Dev

SQL return records based on multiple columns values

From Dev

How to append name and values of each set of records into multiple records

From Dev

Run a rake db:seed multiple times without creating duplicate records?

From Dev

Use" INSERT ... ON DUPLICATE KEY UPDATE" to insert multiple records

From Dev

Displaying multiple records in one row with duplicate user id

From Dev

Find duplicate records in large table on multiple columns the right way

Related Related

  1. 1

    Pivoting a pandas dataframe with duplicate index values

  2. 2

    SQL : Flag multiple records with duplicate values but in alternate columns

  3. 3

    List records with duplicate values

  4. 4

    Ignore duplicate records in SSIS' OLE DB destination

  5. 5

    Pivoting a table with duplicate index

  6. 6

    Treating Null values and duplicate records in SQL Server

  7. 7

    Need help updating records with duplicate values in MySQL

  8. 8

    Replace duplicate values only in consecutive records with NULL

  9. 9

    SQL Query to select records without duplicate values

  10. 10

    Pivoting based on unique values

  11. 11

    Delete duplicate records based on multiple columns

  12. 12

    Check multiple columns for duplicate and list all records

  13. 13

    Multiple sets of duplicate records from a pandas dataframe

  14. 14

    SQL - Pivoting on Column and Row Values

  15. 15

    dataframe slicing and pivoting then into multiple dataframes

  16. 16

    Pivoting multiple columns in C#

  17. 17

    Show First instance of records with duplicate values in tow colums

  18. 18

    Obtain records with multiple instances of field values

  19. 19

    Find group of records that match multiple values

  20. 20

    Find records with multiple foreign key values in Rails

  21. 21

    Update multiple records with different incremental values

  22. 22

    MySQL: Select multiple records with comma separated values

  23. 23

    Update multiple records with different incremental values

  24. 24

    SQL return records based on multiple columns values

  25. 25

    How to append name and values of each set of records into multiple records

  26. 26

    Run a rake db:seed multiple times without creating duplicate records?

  27. 27

    Use" INSERT ... ON DUPLICATE KEY UPDATE" to insert multiple records

  28. 28

    Displaying multiple records in one row with duplicate user id

  29. 29

    Find duplicate records in large table on multiple columns the right way

HotTag

Archive