How to split rows and columns by using ADF?

Zhu, Yueli YZ [NC] 235 Reputation points
2024-04-15T15:57:51.3866667+00:00

How can I retrieve data from the following table by using ADF lookup activity

User's image

and want to get the result as below?

User's image

Thanks

Azure SQL Database
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
9,599 questions
0 comments No comments
{count} votes

Accepted answer
  1. Amira Bedhiafi 15,676 Reputation points
    2024-04-15T16:09:10.8966667+00:00

    You can use the a conditional aggregation directly in your ADF Lookup activity :

    SELECT
    id,
    MAX(CASE WHEN address = '100 street' THEN occupied_time END) AS [100 street],
    MAX(CASE WHEN address = '200 road' THEN occupied_time END) AS [200 road]
    FROM YourTableName
    WHERE id = 3
    GROUP BY id;
    

    If you want to remove the filter for id = 3 so that the query produces results for all id values :

    SELECT
        id,
        MAX(CASE WHEN address = '100 street' THEN occupied_time END) AS [100 street],
        MAX(CASE WHEN address = '200 road' THEN occupied_time END) AS [200 road]
    FROM YourTableName
    GROUP BY id;
    
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful