Can you solve this simple SQL query?

后端 未结 3 834
伪装坚强ぢ
伪装坚强ぢ 2021-01-14 20:31

Suppose it\'s a website that sells photo cameras. Here are my entities (tables):

Camera: A simple camera
Feature: A feature like: 6mp, max resolution 1024x76         


        
3条回答
  •  遥遥无期
    2021-01-14 20:50

    SELECT camera.id
    FROM camera JOIN camera_features ON camera.id=camera_features.camera_id
    GROUP BY camera.id
    HAVING sum(camera_features.feature_id IN (1,2,3))=3
    

    3 is the number of features in (1,2,3). And assuming (camera_id,feature_id) is unique in camera_features.

提交回复
热议问题