【问题标题】:Find users having all skills in passed array在传递的数组中查找具有所有技能的用户
【发布时间】:2021-06-18 04:57:05
【问题描述】:

我有一个skillSets 表,其中包含以下字段。

skillSets
-------------------------
userId -> multiple rows for same users

data: JSON {
skillId
}

type

clientId

我想要传递数组中所有技能的所有用户。

所以如果一个用户有skills a, b and not c it should be ignored for skills in (a, b, c)

但它应该选择用户which have skills a, b, c for skills in (a b, c)

还应该选择用户which have skills a, b, c, d for skills in (a, b, c)

Select userid, data, type
from g.skillSets where
clientid='cce2032a-fd3d-48a1-8e4c-417eb77776c3'
and type = 'Skill Item'
AND JSONB_EXTRACT_PATH_TEXT(g.skillSets.data,'skillId') in ('72c28245-968f-11eb-b30a-87bc1ba467bd','84737607-968f-11eb-b30a-87bc1ba467bd','cca8631f-968f-11eb-b30a-87bc1ba467bd');

【问题讨论】:

    标签: sql postgresql relational-division


    【解决方案1】:

    使用jsonb 遏制运算符@>

    ... WHERE data @> '{ "skillId": [ "a", "b", "c" ] }'
    

    data 上的 GIN 索引可以支持此条件。

    【讨论】:

      猜你喜欢
      • 2021-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-08
      • 2016-09-15
      相关资源
      最近更新 更多