您可以在一系列 case ... then 1 else 0 end 语句中添加匹配项,并将最终结果与所需匹配项的数量进行比较:
SELECT *
FROM Personal
WHERE
case when [State] = 'Tx' then 1 else 0 end
+ case when [City] = 'Austin' then 1 else 0 end
+ case when [Gender] = 'Male' then 1 else 0 end
>= 2
或者,您可以将其分解为 union all 列表:
SELECT *
FROM personal
INNER JOIN (SELECT id
FROM (SELECT id
FROM personal
WHERE state = 'Tx'
UNION ALL
SELECT id
FROM personal
WHERE city = 'Austin'
UNION ALL
SELECT id
FROM personal
WHERE gender = 'Male') a
GROUP BY id
HAVING COUNT (*) >= 2) a
ON personal.id = a.id