nidus-sync/db/sql/trapdata_by_location_id_recent.sql
Eli Ribble 41587c3694
Move database logic into separate subdirectory
I'm trying to see if this speeds up builds a bit. May not without a
module boundary, but for now it's nice organization to have as the
program grows.
2025-11-24 18:08:31 +00:00

12 lines
322 B
SQL

-- TrapDataByLocationIDRecent
SELECT enddatetime, globalid, loc_id
FROM (
SELECT enddatetime, globalid, loc_id, ROW_NUMBER()
OVER (PARTITION BY loc_id ORDER BY enddatetime DESC) as row_num
FROM fs_trapdata
WHERE
organization_id = $1 AND
loc_id IN ($2)
) ranked_data
WHERE row_num <= 10
ORDER BY enddatetime DESC;