我有四個資料表,它們具有重復的狀態但具有不同的 created_at (假設它位于名為“test”的關聯模型上)
樣本:
column 1: status_type : "test", created_at: "2019-08-14"
column 2: status_type : "test", created_at: "2020-20-14"
column 3: status_type : "integer", created_at: "2021-20-15"
column 4: status_type : "integer", created_at: "2022-22"15"
我想獲得兩個資料,分別是測驗和整數,但我需要根據他們的 created_at 更新或更新的資料。這個怎么查詢?謝謝
uj5u.com熱心網友回復:
您可以執行以下操作
Class.where(status_type: ['test', 'integer']).order('created_at').select('DISTINCT ON (status_type) *')
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/486275.html
