select
    number_of_witnesses,
    count(*) as number_of_claims
from
    (
        select
            a.id          as claim_id,
            count(b.id)   as number_of_witnesses
        from
            claim a
            left outer join
            witness b
            on a.id = b.claim_id
        group by
            a.id
    ) x
group by
    number_of_witnesses
order by
    number_of_witnesses;
