orientdborientdb2.2orientdb-2.1

OrientDB perform a group by on embeddedlist column


I have the following query:

SELECT Sub_Type, count(Sub_Type)     
FROM SOME_TABLE  
GROUP BY Sub_Type

Sub_Type field type is an embedded list of string

The result I'm getting is:

Blotter_Sub_Type | count
["A"] | 2
["B"] | 3
["C"] | 3
["A","B"] | 1
["B","C"] | 1

But when I'm really after is to get how many occurrences of each value, my expected result is:

Blotter_Sub_Type | count
"A" | 3
"B" | 5
"C" | 4

Meaning that it will count the occurrences of each value individually


Solution

  • You have to use UNWIND and a subquery:

    SELECT Sub_Type, count(Sub_Type) FROM (
       SELECT Sub_Type FROM SOME_TABLE UNWIND Sub_Type
    ) GROUP BY Sub_Type