By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE mytable (
customer_nr int,
product varchar(10)
);
insert into mytable values
(11111, 'Table'),
(22222, 'Sofa'),
(333333, 'Table'),
(444444, 'Closet'),
(11111, 'Bed'),
(11211, 'Table'),
(22222, 'Sofa'),
(333333, 'Table'),
(444444, 'Closet'),
(11211, 'Bed');
Records: 10 Duplicates: 0 Warnings: 0
select customer_nr
from mytable
where product in ('Table', 'Bed')
group by customer_nr
having count(distinct product) = 2
customer_nr |
---|
11111 |
11211 |
select 'Table' as 'product A', 'Bed' as 'product B', count(distinct customer_nr)
from (
select customer_nr
from mytable
where product in ('Table', 'Bed')
group by customer_nr
having count(distinct product) = 2
) as s
product A | product B | count(distinct customer_nr) |
---|---|---|
Table | Bed | 2 |