Top "Greatest-n-per-group" questions

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

Pandas get topmost n records within each group

Suppose I have pandas DataFrame like this: >>> df = pd.DataFrame({'id':[1,1,1,2,2,2,2,3,4],'value':[1,2,3,1,2,3,4,1,1]}) >>> df id …

python pandas greatest-n-per-group window-functions top-n
GROUP BY having MAX date

I have problem when executing this code: SELECT * FROM tblpm n WHERE date_updated=(SELECT MAX(date_updated) FROM tblpm …

mysql sql optimization greatest-n-per-group
MAX function in where clause mysql

How can I use max() function in where clause of a mysql query, I am trying: select firstName,Lastname,MAX(…

mysql sql max greatest-n-per-group
SQL query to get most recent row for each instance of a given key

I'm trying to get the ip, user, and most recent timestamp from a table which may contain both the current …

sql postgresql greatest-n-per-group
Select a Column in SQL not in Group By

I have been trying to find some info on how to select a non-aggregate column that is not contained in …

sql sql-server-2008 tsql greatest-n-per-group
SQL Left Join first match only

I have a query against a large number of big tables (rows and columns) with a number of joins, however …

sql sql-server tsql join greatest-n-per-group
How to select the rows with maximum values in each group with dplyr?

I would like to select a row with maximum value in each group with dplyr. Firstly I generate some random …

r dplyr plyr greatest-n-per-group
How to select data where a field has a min value in MySQL?

I want to select data from a table in MySQL where a specific field has the minimum value, I've tried …

mysql sql aggregate-functions greatest-n-per-group
how to sort order of LEFT JOIN in SQL query?

OK I tried googling for an answer like crazy, but I couldn't resolve this, so I hope someone will be …

mysql sql greatest-n-per-group
Aggregate a dataframe on a given column and display another column

I have a dataframe in R of the following form: > head(data) Group Score Info 1 1 1 a 2 1 2 b 3 1 3 c 4 2 4 d 5 2 3 …

r aggregate plyr greatest-n-per-group