汽车:
id name
1 Mercedes
2 AudiCarAttributes:
id car_id attribute
1 1 fast
2 1 modern
3 1 fancy
4 1 green
5 2 fast
6 2 quiet
7 2 blue
8 2 old如果返回结果依赖于汽车的属性,sql查询会是什么样子,如下所示:
[fast OR modern] AND [fancy OR old] = would return both cars
[fast OR modern] AND [old OR blue] = would only return the audi car发布于 2020-11-27 22:22:37
您可以将聚合与having子句一起使用:
select car_id
from carattributes
group by car_id
having sum( attribute in ('fast', 'modern')) > 0 and
sum( attribute in ('fancy', old')) > 0https://stackoverflow.com/questions/65038797
复制相似问题