Questions tagged [grouping]

The process of grouping entities into collections of associated elements.

Grouping is a form of hierarchical knowledge representation, similar to mind mapping, concept mapping and argument mapping, all of which need to observe at least some of the principles of grouping.

SQL Server - Indicates whether a specified column expression in a GROUP BY list is aggregated or not. Read more about this

Wiki Links

7381 questions
55
votes
4 answers

How to group a list of tuples/objects by similar index/attribute in python?

Given a list old_list = [obj_1, obj_2, obj_3, ...] I want to create a list: new_list = [[obj_1, obj_2], [obj_3], ...] where obj_1.some_attr == obj_2.some_attr. I could throw some for loops and if checks together, but this is ugly. Is there a…
Aufwind
  • 25,310
  • 38
  • 109
  • 154
53
votes
8 answers

Which SQL statement is faster? (HAVING vs. WHERE...)

SELECT NR_DZIALU, COUNT (NR_DZIALU) AS LICZ_PRAC_DZIALU FROM PRACOWNICY GROUP BY NR_DZIALU HAVING NR_DZIALU = 30 or SELECT NR_DZIALU, COUNT (NR_DZIALU) AS LICZ_PRAC_DZIALU FROM PRACOWNICY WHERE NR_DZIALU = 30 GROUP BY…
M_1
  • 2,135
  • 4
  • 21
  • 24
52
votes
5 answers

How do I group items in an array by date?

Given the following array of objects: [ { "notes": "Game was played", "time": "2017-10-04T20:24:30+00:00", "sport": "hockey", "owner": "steve", "players": "10", "game_id": 1, }, { "notes": "Game was played", "time":…
Blake
  • 553
  • 1
  • 4
  • 7
52
votes
9 answers

Regex Group in Perl: how to capture elements into array from regex group that matches unknown number of/multiple/variable occurrences from a string?

In Perl, how can I use one regex grouping to capture more than one occurrence that matches it, into several array elements? For example, for a string: var1=100 var2=90 var5=hello var3="a, b, c" var7=test var3=hello to process this with…
therobyouknow
  • 6,604
  • 13
  • 56
  • 73
48
votes
1 answer

SQLite count, group and order by count

I have a table that looks like this: FOO BAR BAZ ----+----+---- foo1 bar1 baz1 foo2 bar3 baz2 foo3 bar1 baz3 foo4 bar1 baz4 foo5 bar3 baz5 foo6 bar1 baz6 foo7 bar2 baz7 And as a result I would like to get the count of how many times each bar…
tkit
  • 8,082
  • 6
  • 40
  • 71
48
votes
1 answer

Grouping Java8 stream without collecting it

Is there any way in Java 8 to group the elements in a java.util.stream.Stream without collecting them? I want the result to be a Stream again. Because I have to work with a lot of data or even infinite streams, I cannot collect the data first and…
Matthias Wimmer
  • 3,789
  • 2
  • 22
  • 41
46
votes
3 answers

jq: group and key by property

I have a list of objects that look like this: [ { "ip": "1.1.1.1", "component": "name1" }, { "ip": "1.1.1.2", "component": "name1" }, { "ip": "1.1.1.3", "component": "name2" }, { "ip": "1.1.1.4", …
replay
  • 3,569
  • 3
  • 21
  • 30
46
votes
1 answer

Concatenate and group multiple rows in Oracle

Possible Duplicate: how to retrieve two columns data in A,B format in Oracle Suppose I have a table like this: NAME GROUP_NAME name1 groupA name2 groupB name5 groupC name4 groupA name3 groupC I'd…
Yijia Zhan
  • 463
  • 1
  • 4
  • 6
45
votes
2 answers

How to group by and sum an array of objects?

I would like to group an array of objects by Id and sum the quantity in jQuery. How can I achieve this? For example: var array = [ { Id: "001", qty: 1 }, { Id: "002", qty: 2 }, { Id: "001", qty: 2 }, { Id: "003", qty: 4 } ] Should result…
Phirum
  • 655
  • 2
  • 6
  • 12
45
votes
3 answers

how to apply group by on xslt elements

I need to group the value based on some attribute and populate it. below mentioned is i/p xml and if you see there are 4 rows for Users and for id 2,4 Division is same i.e. HR while generating actual o/p I need to group by Division ... Any help…
Amit
  • 3,358
  • 9
  • 34
  • 48
44
votes
6 answers

Stream groupingBy: reducing to first element of list

I have a List which can be represented (simplified) JSON-style: [ { codice=EUR, description=Euro, ratio=1 }, { codice=USD, description=Dollars, ratio=1.1 } ] I want to transform that in a Map like this: {…
Fabio B.
  • 9,138
  • 25
  • 105
  • 177
43
votes
7 answers

Grouping by week/month/etc & ActiveRecord?

I'm doing some statics calculation in my product. A user has performed a number of operations, let's say posted comments. I want to be able to show them how many comments they've posted per week for the past month, or per month for the past year. …
teich
  • 1,692
  • 2
  • 16
  • 19
43
votes
2 answers

Java 8 is not maintaining the order while grouping

I m using Java 8 for grouping by data. But results obtained are not in order formed. Map> groupedResult = null; if (!CollectionUtils.isEmpty(groupByColumns)) { Map mapArr[] = new…
Shreya Shah
  • 582
  • 1
  • 4
  • 17
43
votes
2 answers

Using geom_line with multiple groupings

I have a table as follows: > testsizes size value replicate lane 361 16 6898 1 L1 362 17 10707 1 L1 363 18 1786 1 L1 364 19 1721 1 L1 365 20 2454 1 L1 421 16 8486 2 …
MattLBeck
  • 5,701
  • 7
  • 40
  • 56
41
votes
1 answer

cut function in R- labeling without scientific notations for use in ggplot2

I use cut and classIntervals to group data in R which I later plot with ggplot2. So a basic operation cutting by quantiles with n=3 would look like this: library(classInt) a<-c(1,10,100,1000,100000,1000000) b<-cut(a, breaks=data.frame( …
Joschi
  • 2,941
  • 9
  • 28
  • 36