【问题标题】:how do we check if an element in the array exists and if it has a value of "true" in Presto我们如何检查数组中的元素是否存在以及它在 Presto 中的值是否为“true”
【发布时间】:2020-12-14 15:20:30
【问题描述】:

数组中的数据看起来像 XXXX:"False"。我用过

element_at(array_name,'Field') and contains(map_keys(array_name),'Field')。他们只检查元素是否存在于数组中。但是如果“字段”的值为“真”,我该如何检查该值?

【问题讨论】:

  • array_name 的确切类型是什么? (SELECT DISTINCT typeof(array_name) ... 返回什么?)
  • 我的解释可能有误,但不同的查询返回“map(varchar, varchar)”,我认为上面的 array_name 是地图,'Field 是元素。

标签: sql arrays where-clause presto


【解决方案1】:

假设你手头有一张地图,并且你想检查给定键的值,你可以使用element_at()

where element_at(array_name, 'Field') = 'True'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-27
    • 1970-01-01
    • 1970-01-01
    • 2021-09-20
    • 1970-01-01
    • 2010-12-30
    • 2015-07-31
    • 1970-01-01
    相关资源
    最近更新 更多