· 6 years ago · Jan 17, 2020, 09:20 PM
1-- borrowed from https://stackoverflow.com/q/7745609/808921
2
3CREATE TABLE IF NOT EXISTS `customer` (
4 `name` varchar(90) NOT NULL,
5 `item` varchar(90) NOT NULL
6) DEFAULT CHARSET=utf8;
7INSERT INTO `customer` (`name`, `item`) VALUES
8 ('1', '1'),
9 ('1', '3'),
10 ('3', '1'),
11 ('3', '3'),
12 ('2', '1'),
13 ('2', '3'),
14 ('3' ,'2'),
15 ('3' ,'1'),
16 ('4', '1'),
17 ('4', '3'),
18 ('4', '7')
19
20
21
22
23
24select item , count(item) as pp from
25(select name,item ,count(item) from customer group by name,item) as p
26group by item
27having count(item) = (select count( distinct name) from customer)