Questions tagged [greatest-n-per-group]

Use this for problems that involve returning one or more rows from each group in a data set. Despite the name, this tag is suitable for minimum- and maximum- per group queries.

361 questions
1
vote
2 answers

sql query using analytic functions

The table is laid out like name, id, attr1, attr2, data_date a, 1, sals, ksdjf, 05-25-2018 b, 1, laskd, lskd, 05-20-2017 c, 2, klss, kjfe, 03-20-2018 d, 2, aow , lww , 02-10-2018 ..... select name, id,…
1
vote
1 answer

Select to get a value from a id combined with a max value

I have a table like this: idAction | numberLine | action 1 | 1 | 1 1 | 2 | 2 1 | 3 | 7 1 | 4 | 6 2 | 1 | 2 1 | 2 | 5 1 | 3 | …
Narf92
  • 13
  • 2
0
votes
1 answer

Query the last records by date, where condition is true

A made this query, which is works perfectly now: SELECT t.DocID, t.RevID, t.EffDate FROM tblRev AS t INNER JOIN ( SELECT DocID, max(EffDate) AS MAXEffDate FROM tblRev GROUP BY DocID ) AS tm ON (t.EffDate = tm.MAxEffDate) AND (t.DocID =…