Я думаю, что вы ищете декартово объединение между магазинами, а затем проверяете, чтобы увидеть количество совпадений sku.
Вот мой запрос
--This gets the total count of sku by store
with data
as (select store_id,count(sku) as tot_sku
from products
group by store_id
)
select a.store_id as store_id
,b.store_id as other_store_id
--when the skus in one store match with another then count those
,count(case when a.sku=b.sku then 1 end) as cnt_overlap
,max(c.tot_sku) as tot_sku
,count(case when a.sku=b.sku then 1 end)*100.00/max(c.tot_sku) as pct_overlap
from products a
join products b
on a.store_id <> b.store_id
join data c
on a.store_id=c.store_id
group by a.store_id,b.store_id
order by 1
+----------+----------------+-------------+---------+----------------------+
| store_id | other_store_id | cnt_overlap | tot_sku | pct_overlap |
+----------+----------------+-------------+---------+----------------------+
| 1 | 2 | 1 | 1 | 100.0000000000000000 |
| 1 | 3 | 1 | 1 | 100.0000000000000000 |
| 1 | 4 | 1 | 1 | 100.0000000000000000 |
| 1 | 5 | 1 | 1 | 100.0000000000000000 |
| 2 | 1 | 1 | 2 | 50.0000000000000000 |
| 2 | 3 | 2 | 2 | 100.0000000000000000 |
| 2 | 4 | 1 | 2 | 50.0000000000000000 |
| 2 | 5 | 1 | 2 | 50.0000000000000000 |
| 3 | 1 | 1 | 5 | 20.0000000000000000 |
| 3 | 2 | 2 | 5 | 40.0000000000000000 |
| 3 | 4 | 1 | 5 | 20.0000000000000000 |
| 3 | 5 | 1 | 5 | 20.0000000000000000 |
| 4 | 1 | 1 | 1 | 100.0000000000000000 |
| 4 | 2 | 1 | 1 | 100.0000000000000000 |
| 4 | 3 | 1 | 1 | 100.0000000000000000 |
| 4 | 5 | 1 | 1 | 100.0000000000000000 |
| 5 | 1 | 1 | 1 | 100.0000000000000000 |
| 5 | 2 | 1 | 1 | 100.0000000000000000 |
| 5 | 3 | 1 | 1 | 100.0000000000000000 |
| 5 | 4 | 1 | 1 | 100.0000000000000000 |
+----------+----------------+-------------+---------+----------------------+
вот моя ссылка на БД скрипта
https://dbfiddle.uk/?rdbms=postgres_12&fiddle=151fa1f18ac25bb0362ebc47de02dd09