[英]SQL selecting distinct Ids with specific values
I would recommend aggregation and having
clause to implement the filtering logc:我会建议聚合和
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
Depending on your actual database, which you did not tell, there may be neater options to express the conditions.根据您没有告诉的实际数据库,可能有更简洁的选项来表达条件。 For example, in MySQL:
例如,在 MySQL 中:
having
(max(formfieldid = 1) and max(formfieldid = 2))
or max(formfieldid = 3)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.