0
one to many
관계가있는 테이블 1. Artist
과 2. Photo
이 있습니다.사진이없는 레코드를 찾는 방법
및 less then 5 photos
을 가지고있는 all artists
을 찾고 싶습니다.
어떻게 쿼리를 작성할 수 있습니까?
one to many
관계가있는 테이블 1. Artist
과 2. Photo
이 있습니다.사진이없는 레코드를 찾는 방법
및 less then 5 photos
을 가지고있는 all artists
을 찾고 싶습니다.
어떻게 쿼리를 작성할 수 있습니까?
시도해보십시오.
Artist.join(:photos).having("count(photos.*)<5")
당신이
Artist.join(:photos).group("photos.artist_id").select("sum(photos.artist_id) as total_photos").having("total_photos<5")
를 사용하는을 찾을 수 있습니다