Top "Greatest-n-per-group" questions

Query the row with the greatest/least value per group.

Django Query That Get Most Recent Objects From Different Categories

I have two models A and B. All B objects have a foreign key to an A object. Given a …

python django django-queryset greatest-n-per-group
one-to-many query selecting all parents and single top child for each parent

There are two SQL tables: Parents: +--+---------+ |id| text | +--+---------+ | 1| Blah | | 2| Blah2 | | 3| Blah3 | +--+---------+ Childs +--+------+…

sql sql-server tsql greatest-n-per-group
Select latest row for each group from oracle

I have a table with user comments in a guestbook. Columns are: id, user_id, title, comment, timestamp. I need …

sql oracle greatest-n-per-group
MySQL - Join tables, retrieve only Max ID

I've seen solutions for something similar on other posts, but I've been having an issue applying it to my specific …

sql max greatest-n-per-group
Subset rows corresponding to max value by group using data.table

Assume I have a data.table containing some baseball players: library(plyr) library(data.table) bdt <- as.data.…

r data.table greatest-n-per-group
Get values from first and last row per group

I'm new to Postgres, coming from MySQL and hoping that one of y'all would be able to help me out. …

sql postgresql group-by aggregate greatest-n-per-group
PostgreSQL: Select only the first record per id based on sort order

For the following query I need to select only the first record with the lowest shape_type value (ranges from 1 …

sql postgresql distinct greatest-n-per-group distinct-on
GROUP BY in Postgres - no equality for JSON data type?

I have the following data in a matches table: 5;{"Id":1,"Teams":[{"Name":"TeamA","Players":[{"Name":"AAA"},{"Name":"BBB"}]},{"Name":"TeamB","…

sql json postgresql greatest-n-per-group lateral
How to SELECT the newest four items per category?

I have a database of items. Each item is categorized with a category ID from a category table. I am …

sql mysql greatest-n-per-group
Trying to find the second largest value in a column (postgres sql)

I am trying to find the second largest value in a column and only the second largest value. select a.…

sql postgresql greatest-n-per-group