2
大きなテーブルからグループごとに最大の価値を得るための効率的なクエリ
テーブルが与えられた場合: Column | Type id | integer latitude | numeric(9,6) longitude | numeric(9,6) speed | integer equipment_id | integer created_at | timestamp without time zone Indexes: "geoposition_records_pkey" PRIMARY KEY, btree (id) このテーブルには2000万件のレコードがありますが、比較的多くはありません。ただし、シーケンシャルスキャンが遅くなります。 max(created_at)それぞれの最後のレコード()を取得するにはどうすればよいequipment_idですか? 私はこのトピックの多くの回答を読んだいくつかのバリエーションを使用して、次の両方のクエリを試しました: select max(created_at),equipment_id from geoposition_records group by equipment_id; select distinct on (equipment_id) equipment_id,created_at from geoposition_records order by …