rails 与 sql goup_by

rails

Sku.joins(:site_skus).where("site_skus.site_id": [11,12,13]).group("skus.id")

sql

SELECT "skus".* FROM "skus" INNER JOIN "site_skus" ON "site_skus"."sku_id" = "skus"."id" WHERE "site_skus"."site_id" IN (11, 12, 13) GROUP BY skus.id

就结果

<Sku id: 9632, product_id: 11617, level: "D", created_at: "2017-06-20 07:27:55", updated_at: "2017-06-20 07:27:55">

你可能感兴趣的:(ralis,rails)