SQL group by values stored in arrays -


i use orientdb. have table this:

 name | categories -------------------   n1  |   [a,b]   n2  |   [c]   n3  |   [c,a]   n4  |   [a,b] 

and build query returns list of categories, , each category list of related names, this:

 category |   names -----------------------         | [n1,n3,n4]     b     | [n1,n4]     c     | [n2,n3] 

if "categories" wasn't array, achieve with:

select   categories category,   set(name) names table group categories 

but, being categories arrays, get:

 category |  names --------------------    [a,b]  | [n1,n4]     [c]   | [n2]    [c,a]  | [n3] 

what query should rather write?

i reproduced structure command

create class test extends v create property test.name string create property test.categories embeddelist string  insert test(name,categories) values ("n1",["a","b"]),("n2",["c"]),("n3",["c","a"]),("n4",["a","b"]) 

enter image description here

and used query

select categories,$a.name name (select distinct(categories) categories (select categories  test order categories unwind categories)) let $a = (select name test categories contains $parent.$current.categories) 

enter image description here

hope helps.


Comments

Popular posts from this blog

php - isset function not working properly -

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -