您好,我在数据库中有大量数据,因此我需要一种方法来过滤sql数据以及其中的特定数据。
例如:我想从此代码中获取姓名和文字
INSERT INTO `Employers` VALUES
('rgthtr5','9123123','{"name":"Mohamed","text":"employer","bla":"
bla","bla":"bla"})
答案 0 :(得分:1)
您可以使用JSON_VALUE
从json获取值:
declare @tmp table ([code] varchar(10), [ncode] varchar(10), [json] varchar(max))
INSERT INTO @tmp VALUES
('rgthtr5', '9123123', '{"name":"Mohamed1","text":"employer1","bla":"bla","bla":"bla"})')
,('rgthtr6', '9123124', '{"name":"Mohamed2","text":"employer2","bla":"bla","bla":"bla"})')
,('rgthtr7', '9123125', '{"name":"Mohamed3","text":"employer3","bla":"bla","bla":"bla"})')
select
[code],
[ncode],
JSON_VALUE([json], '$.name') as [name],
JSON_VALUE([json], '$.text') as [text]
from @tmp
结果: