SQL 服务器 where JSON 字段上的子句
SQL Server where Clause on JSON Field
我有一个table
ID | Start Date | End Date | Summary
---+-------------------+-------------------+----------------------------
1 | 2020-01-01T09:20 | 2020-01-01T09:30 | {"total":20,"totalError":10}
1 | 2020-01-02T09:20 | 2020-01-02T10:55 | {"total":10,"totalError":5}
我要查询where totalError > 0
Select *
from runLog
where Summary.totalError > 0
这可能吗?
使用JSON_VALUE()
:
select * from runLog where json_value(summary, '$.totalError') > 0
我有一个table
ID | Start Date | End Date | Summary
---+-------------------+-------------------+----------------------------
1 | 2020-01-01T09:20 | 2020-01-01T09:30 | {"total":20,"totalError":10}
1 | 2020-01-02T09:20 | 2020-01-02T10:55 | {"total":10,"totalError":5}
我要查询where totalError > 0
Select *
from runLog
where Summary.totalError > 0
这可能吗?
使用JSON_VALUE()
:
select * from runLog where json_value(summary, '$.totalError') > 0