Skip to content

Instantly share code, notes, and snippets.

@Alxandr
Last active May 26, 2025 12:04
Show Gist options
  • Save Alxandr/2a8f28ddea01b7f1a8d44d79658bfc4e to your computer and use it in GitHub Desktop.
Save Alxandr/2a8f28ddea01b7f1a8d44d79658bfc4e to your computer and use it in GitHub Desktop.
-- for posterity
with worst as (
select era.to_party, count(*) as sub_unit_count
from register.external_role_assignment era
where era."source" = 'ccr'
and (era.identifier = 'ikke-naeringsdrivende-hovedenhet' OR era.identifier = 'hovedenhet')
group by era.to_party
)
select p.uuid, p."organization_identifier", p.id, w.sub_unit_count
from worst w
inner join register.party p on p."uuid" = w.to_party
order by w.sub_unit_count desc
limit 10
uuid organization_identifier id sub_unit_count
5e8b0bc9-b678-49cb-a3d9-7a805bbc6d5a 730109598 57883351 1376
dab34a7b-6aae-43c4-b1bf-0797eeda8fe6 725742134 59041525 976
6943199a-8fd9-4fd2-bd78-0fc8a7a2da7c 726373493 57907614 528
c2c0f633-4f22-4f8f-99e0-d38c66a91ce3 726426503 58060545 413
31674783-5ddf-4b32-9e08-d43eb921dd65 313382796 61843550 412
f2cd00ca-1bc9-489a-94e0-53cb5ef006e7 313776301 61830231 400
bf3b277a-19be-4ccf-bdd4-9041456785d0 726642656 57537034 349
e82850b5-f457-49fe-a72c-c9415c026b61 730095031 58607358 344
7d28fda4-dab4-4be6-ba6d-daa5aa7606bb 725870671 58587104 343
66fe4095-9c37-4314-ab56-066dfadf3a36 712450932 58656314 336
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment