Let's say I have a 1D-like table like this:
TBL_1
[ Task ][ Entity ][ Timespan ]
[ TASK1 ][ ID1 ][ 3 ]
[ TASK2 ][ ID2 ][ 4 ]
[ TASK2 ][ ID1 ][ 5 ]
[ TASK1 ][ ID2 ][ 6 ]
How would I turn it into a 2D-like view like this:
[ Entity ][ TASK1 ][ TASK2 ]
[ ID1 ][ 3 ][ 5 ]
[ ID2 ][ 6 ][ 4 ]
Given that the number of tasks should be dynamic?
My current solution looks like that:
SELECT A.Entity, B.Task TASK1, C.Task TASK2
FROM (SELECT DISTINCT ENTITY FROM TBL_1) A
LEFT JOIN TBL_1 B
ON A.Entity = B.Entity AND B.Task = 'TASK1'
LEFT JOIN TBL_1 C
ON A.Entity = C.Entity AND C.Task = 'TASK2'
But this requires me to "Hardcode" the tasks. How can-I make this dynamic?
Thank you very much!