答案 0 :(得分:0)
我建议使用聚合和having
子句来实现过滤logc:
select userid
from mytable
group by userid
having
(
max(case when formfieldid = 1 then 1 end) = 1
and max(case when formfieldid = 2 then 1 end) = 1
)
or max(case when formfieldid = 3 then 1 end) = 1
取决于您未告知的实际数据库,可能会有更整洁的选项来表达条件。例如,在MySQL中:
having
(max(formfieldid = 1) and max(formfieldid = 2))
or max(formfieldid = 3)