Code: Select all
Select S."Source" "Källa", Owner_1 "Ägare 1", Owner_2 "Ägare 2", Owner_3 "Ägare 3", S."Period", S."Comment" "Kommentar",
[i]S.(Case When "Mixed_Cams" = 1 Then 'Yes') as "MIX"[/i]
From
(
Select A."ID_Source",
Max(case when SLOT = 0 then PE."Name" end) as Owner_1,
Max(case when SLOT = 1 then PE."Name" end) as Owner_2,
Max(case when SLOT = 2 then PE."Name" end) as Owner_3
From
(
Select
SP."ID_Source", SP."ID_Person",
mod(Count(SP1."ID_Person"), 3) SLOT
From "SourcePerson" SP
Left Join "SourcePerson" SP1
On SP1."ID_Source" = SP."ID_Source" and SP1."SourcePerson" < SP."SourcePerson"
Group By SP."ID_Source", SP."ID_Person"
) A
Join "Person" PE
On PE."ID_Person" = A."ID_Person"
Group By A."ID_Source"
) B
Join "Source" S
On S."ID_Source" = B."ID_Source"
Where S."Source" = 'RESS 2007' --Ange Källa eller kommentera bort (--...) raden för att visa alla album
Order By S."Source"