匹配 MySQL 中的每个值至少一个
我有 2 个表,我想从一个表中选择条目,其中第二个表中有用于项目列表的条目。
例如:
条目
id=1 requirements=(1,2,3)
id=2 requirements=(1,3,5)
提交
id=1 entry=1 requirement=1
id=2 entry=2 requirement=2
id=3 entry=3 requirement=3
会选择条目 id=1
,但不会条目 id=2
(因此 WHERE IN
不做这项工作)
*编辑实际数据集:
INSERT INTO submission
(entry_id
, requirement_id
, submission_id
)价值观 (17,1,1), (43,1,2), (57,0,3), (57,0,4), (1,1,5), (26,1,6), (40,1,7), (40,1,8), (40,1,9), (40,1,10), (85,1,11), (94,1,12), (114, 0, 13), (32,1,14), (34, 0, 15);
INSERT INTO entry
(entry_id
, category_id
) 值 (1, 2), (2, 1), (3, 1), (4, 1), (5, 2), (6, 1), (7, 1), (8, 1), (9, 1), (10, 1), (11, 1), (12, 1), (13, 1), (14, 1), (15, 1);
插入类别
(category_id
,要求
)值 (1, '1,2,3'), (2, '1,2,4,5,6'), (3, '1,2,4,5,6');
I've got 2 tables, I want to select entries from one table, where there are entries in the second table for a list of items.
for example:
entry
id=1 requirements=(1,2,3)
id=2 requirements=(1,3,5)
submission
id=1 entry=1 requirement=1
id=2 entry=2 requirement=2
id=3 entry=3 requirement=3
Would select entry id=1
, but not entry id=2
(so WHERE IN
doesn't do the job)
*edit actual datasets:
INSERT INTO submission
(entry_id
, requirement_id
, submission_id
) VALUES
(17, 1, 1),
(43, 1, 2),
(57, 0, 3),
(57, 0, 4),
(1, 1, 5),
(26, 1, 6),
(40, 1, 7),
(40, 1, 8),
(40, 1, 9),
(40, 1, 10),
(85, 1, 11),
(94, 1, 12),
(114, 0, 13),
(32, 1, 14),
(34, 0, 15);
INSERT INTO entry
(entry_id
, category_id
) VALUES
(1, 2),
(2, 1),
(3, 1),
(4, 1),
(5, 2),
(6, 1),
(7, 1),
(8, 1),
(9, 1),
(10, 1),
(11, 1),
(12, 1),
(13, 1),
(14, 1),
(15, 1);
INSERT INTO category
(category_id
, requirement
) VALUES
(1, '1,2,3'),
(2, '1,2,4,5,6'),
(3, '1,2,4,5,6');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查找表 1 中的所有行,其中表 2 中有 3 个匹配行:
我会为您的数据编写实际的查询,但我无法解读您的问题。
Find all rows in table 1 where there are 3 matching rows in table 2:
I'd write the actual query for your data but I can't decipher your question.