56,687
社区成员
发帖
与我相关
我的任务
分享
CREATE TABLE `product_config` (
`product_id` bigint(20) NOT NULL COMMENT '产品ID',
`config_id` bigint(20) NOT NULL COMMENT '产品配置属性ID'
)
INSERT INTO `product_config`(`product_id`, `config_id`) VALUES (4, 7);
INSERT INTO `product_config`(`product_id`, `config_id`) VALUES (6, 2);
INSERT INTO `product_config`(`product_id`, `config_id`) VALUES (6, 7);
INSERT INTO `product_config`(`product_id`, `config_id`) VALUES (6, 14);
想查询出config_id等于2,7,14的product_id
SELECT
distinct product_id
from product_config as a
where config_id in (2,7,14)
and exists(
select 1 from product_config as b where a.product_id=b.product_id and b.config_id=7
)
and exists(
select 1 from product_config as c where a.product_id=c.product_id and c.config_id=14
);