简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM