首页 > 数据库 >sqlserver、mysql、sqlite json类型数据查询及索引优化

sqlserver、mysql、sqlite json类型数据查询及索引优化

时间:2023-02-22 15:25:53浏览次数:60  
标签:Customer sqlite name val sqlserver json tab child

 

sqlserver:

#query
SELECT SalesOrderNumber,
    OrderDate,
    JSON_VALUE(Info, '$.Customer.Name') AS CustomerName
FROM Sales.SalesOrderHeader
WHERE JSON_VALUE(Info, '$.Customer.Name') = N'Aaron Campbell' 

#index
ALTER TABLE Sales.SalesOrderHeader
ADD vCustomerName AS JSON_VALUE(Info,'$.Customer.Name')

CREATE INDEX idx_soh_json_CustomerName
ON Sales.SalesOrderHeader(vCustomerName)  

 

mysql:

#query
SELECT val->>'$.child.id' AS id,val->>'$.child.name' AS name FROM tab_name WHERE ID > 0 and val->>'$.child.id'>=2

#index
alter table tab_name add column vname varchar(40) generated always  as (val->"$.child.name") virtual;

CREATE INDEX `name_idx` ON `tab_name`(`vname`);  

 

sqlite:

#query
SELECT ifnull(json_extract(dec,"$.ID"),0) as ID,val FROM tab_name;

 

标签:Customer,sqlite,name,val,sqlserver,json,tab,child
From: https://www.cnblogs.com/dreamman/p/17144498.html

相关文章