这个答案与我的评论一致 -
查找 1 条记录(简单)
SELECT tmp1.rid AS rid
FROM mybb_reputation AS tmp1
WHERE tmp1.reputation = 3;
查找任意 2 条记录(使用 < 因为关系的顺序与答案无关)
SELECT CONCAT_WS(',',tmp1.rid, tmp2.rid) AS rid
FROM mybb_reputation AS tmp1
JOIN mybb_reputation AS tmp2
ON tmp1.rid < tmp2.rid
WHERE tmp1.reputation + tmp2.reputation = 3
查找任意 3 条记录(与之前关于 < 的想法相同)
SELECT CONCAT_WS(',',tmp1.rid, tmp2.rid, tmp3.rid) AS rid
FROM mybb_reputation AS tmp1
JOIN mybb_reputation AS tmp2
ON tmp1.rid < tmp2.rid
JOIN mybb_reputation AS tmp3
ON tmp2.rid < tmp3.rid
WHERE tmp1.reputation + tmp2.reputation + tmp3.reputation = 3
查找 4(算法只是重复)
SELECT CONCAT_WS(',',tmp1.rid, tmp2.rid, tmp3.rid, tmp4.rid) AS rid
FROM mybb_reputation AS tmp1
JOIN mybb_reputation AS tmp2
ON tmp1.rid < tmp2.rid
JOIN mybb_reputation AS tmp3
ON tmp2.rid < tmp3.rid
JOIN mybb_reputation AS tmp4
ON tmp3.rid < tmp4.rid
WHERE tmp1.reputation + tmp2.reputation + tmp3.reputation + tmp4.reputation = 3
无论您想要多少组合,您都需要继续此操作。