with x as (
select '20190101' as order1,'A' as goods from dual
union all
select '20190101' as order1,'B' as goods from dual
union all
select '20190101' as order1,'C' as goods from dual
union all
select '20190102' as order1,'A' as goods from dual
union all
select '20190102' as order1,'C' as goods from dual
union all
select '20190103' as order1,'C' as goods from dual
union all
select '20190103' as order1,'D' as goods from dual
)
SELECT y.goods1, y.goods2, COUNT(DISTINCT y1.order1) as js
FROM(
SELECT A.goods as goods1, B.goods as goods2
FROM (SELECT DISTINCT goods FROM x) A,
(SELECT DISTINCT goods FROM x) B
WHERE A.goods < B.goods
) y INNER JOIN x y1 ON y1.goods = y.goods1
WHERE EXISTS(SELECT * FROM x y2 WHERE y2.order1 = y1.order1 AND y2.goods = y.goods2)
GROUP BY y.goods1, y.goods2;