Returns the greatest of all elements of the sequence, compared by using Operators.max on the function result.
Questions tagged [maxby]
25 questions
6
votes
1 answer
How can I get the corresponding value of a column based on an aggregate of another column?
I am migrating some PostgreSQL queries to Snowflake and I am struggling to replicate the following query:
WITH test_table(col1, col2, col3, col4) AS (
VALUES
(1, 1, 7, 5),
(1, 1, 6, 4),
(1, 2, 1, 4),
(1, 2, 2,…

Thomas Mannschott
- 75
- 6
5
votes
2 answers
jq find the max in quoted values
Here is my JSON test.jsonfile :
[
{
"name": "nodejs",
"version": "0.1.21",
"apiVersion": "v1"
},
{
"name": "nodejs",
"version": "0.1.20",
"apiVersion": "v1"
},
{
"name": "nodejs",
"version": "0.1.11",
…

Nicolas Pepinster
- 5,413
- 2
- 30
- 48
5
votes
3 answers
Returning all maximum or minimum values that can be multiple
Enumerable#max_by and Enumerable#min_by return one of the relevant elements (presumably the first one) when there are multiple max/min elements in the receiver. For example, the following:
[1, 2, 3, 5].max_by{|e| e % 3}
returns only 2 (or only…

sawa
- 165,429
- 45
- 277
- 381
3
votes
2 answers
Bigquery Standard SQL "max_by" and "regr_slope" functions
Is there any equivalent function in Bigquery using Standard SQL for max_by and regr_slope functions. If not how to achieve this.
Thanks,
Maniyar

Maniyar
- 39
- 1
- 2
3
votes
2 answers
Getting the MoreLinq MaxBy function to return more than one element
I have a situation in which I have a list of objects with an int property and I need to retrieve the 3 objects with the highest value for that property. The MoreLinq MaxBy function is very convenient to find the single highest, but is there a way I…

Fenoec
- 179
- 2
- 8
2
votes
3 answers
GroupBy and Stream Filter based on max field for particular record on each date java list
I am having a list that looks like below
[
{
"busId": "4-3323309834",
"dataDateTime": "2022-08-27 05:22:46",
"busName": "27Tr Solaris Single Deck",
"speedLimit": 80,
"id": 1,
"currentSpeed": 67,
"passengersNo": 80
},
…

Emmanuel Njorodongo
- 1,004
- 17
- 35
2
votes
1 answer
I am trying to find the Salary of the Newest Employee for every Department. Using java 8 in a single step
Aim is to find the Salary of the newest Employee in the Department considering employee ID will increase.
I have written a 2 step code and I am trying to find a solution that can do this in a single step using java8.
My Process is:
get a Map of…

ISHAN KUMAR GHOSH
- 226
- 1
- 7
2
votes
1 answer
Cannot access Map returned by maxBy
I have a Map[String, Any] of donuts
val donuts: Seq[Map[String, Any]] = Seq(Map("type" -> "plain", "price" -> 1.5), Map("type" -> "jelly", "price" -> 2.5))
I want to find the highest priced donut using maxBy.
val d = donuts.maxBy(donut =>…

cph2117
- 2,651
- 1
- 28
- 41
2
votes
3 answers
Pushing max hash key-values into an array in Ruby?
I have a hash called count, defined as count = {4=>2, 5=>3, 6=>3, 7=>1}.
I want to take the max value, and then push the key that corresponds to that value into an array, so I do this:
array = []
array.push(count.max_by{|k,v| v}[0])
=>>…

darrendahl
- 23
- 3
1
vote
2 answers
MaxBy() is there a way to get multiple max values?
I am trying to get the maximum values out of a list but if there are multiple max values then I want to get all the max values.
For instance I have:
Name1, 31
Name2, 35
Name3, 33
Name4, 35
And I want to get:
{Name2, 35} AND {Name4, 35}
I tried using…

ToastedProphet
- 13
- 2
1
vote
1 answer
maxBy() multiple attributes of objects in List()
Say I have a list of books
val books = List(Book)
where Book(bookID: String, bookName: String) and a map
val scores = Map(bookID -> score:float)
I would like to get the book with the highest score first, then alphabetically by bookName
Getting the…

jeb2
- 179
- 1
- 6
1
vote
2 answers
Presto: is MAX_BY() deterministic
Is the function MAX_BY() deterministic.
If I use MAX_() for two different columns both depending on a third one, will I get the same row result?
The presto documentation doesn't mention this.
This documentation about mysql mention that it is not, so…

user1527152
- 946
- 1
- 13
- 37
1
vote
2 answers
Select top n items from each array order by desc
Consider a collection with the following documents:
{
"_id" : 1,
"name" : "Class 1",
"students" : [
{ "rollNo" : 10001, "name" : "Ram", "score" : 65 },
{ "rollNo" : 10002, "name" : "Shyam", "score" : 90 }, <=
{…

saif
- 487
- 1
- 7
- 19
1
vote
1 answer
None if no clear winner in Scala Map maxBy
val valueCountsMap: mutable.Map[String, Int] = mutable.Map[String, Int]()
valueCountsMap("a") = 1
valueCountsMap("b") = 1
valueCountsMap("c") = 1
val maxOccurredValueNCount: (String, Int) = valueCountsMap.maxBy(_._2)
// maxOccurredValueNCount:…

yalkris
- 2,596
- 5
- 31
- 51
1
vote
2 answers
F# int list of two maximums
Previous question: F# Filtering multiple years
I need to return an int list of two years where the given years are the greatest amount of rainfall for any February within the data set.
So far, I have found the first year using List.maxBy but I…

lewishh
- 53
- 6