简体   繁体   English

过滤一列是 json 的 SQL 查询

[英]Filter SQL query where one column is a json

I have a column in SQL that has a JSON formatted data inside of it.我在 SQL 中有一个列,其中包含 JSON 格式的数据。 For example, lets call this column JSON and the first input would be例如,让我们将此列称为 JSON,第一个输入将是

{
  "ID" :123, 
  "NAME": NULL, 
  "FINISH": "MATTE"
}

How can I filter this column and only display values that don't have a NULL input in a variable such as "NAME"?如何过滤此列并仅显示在“NAME”等变量中没有 NULL 输入的值?

I'd go with the following approach:我会采用以下方法:

select *
from <your_table>
where json_value(<your_json_column>, '$.name') is not null;

In the query above, you'd only need to change <your_table> for the actual name of the table, and <your_json_column> for the actual name of the JSON column.在上面的查询中,您只需将<your_table>更改为表的实际名称,将<your_json_column> your_json_column> 更改为 JSON 列的实际名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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