You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在PRESTO中使用WHERE条件检索JSON数据?

在Presto查询中添加JSON字段过滤条件

你需要使用json_extract_scalar函数提取JSON中的org字段值,再通过WHERE子句添加过滤条件,筛选出org等于'legal'的记录。

修改后的完整查询语句如下:

WITH dataset AS (SELECT * FROM (VALUES
    (JSON '{"name": "Bob Smith", "org": "legal"}'),
    (JSON '{"name": "Susan Smith", "org": "engineering"}'),
    (JSON '{"name": "Jane Smith", "org": "finance"}')
  ) AS t (users)
)
SELECT json_extract_scalar(users, '$.name') AS user
FROM dataset
WHERE json_extract_scalar(users, '$.org') = 'legal';

说明

  • json_extract_scalar(users, '$.org'):从JSON类型的users列中提取org字段的字符串值;
  • WHERE子句通过该提取值与'legal'匹配,仅保留符合条件的记录。

内容的提问来源于stack exchange,提问作者Seuzz sandy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 17:20:36