我最近问过how to solve a simple SQL query。事实证明有many solutions。
经过一些基准测试后,我认为这是最好的一个:
SELECT DISTINCT Camera.*
FROM Camera c
INNER JOIN cameras_features fc1 ON c.id = fc1.camera_id AND fc1.feature_id = 1
INNER JOIN cameras_features fc2 ON c.id = fc2.camera_id AND fc2.feature_id = 2
现在,我不知道如何使用Django ORM执行此查询。