在日常开发中 或许会碰到这种情景 就是对于数据库中存储的json格式的数据 想要转换、处理、清洗、进行数据分析
这里推荐SQL处理,因为我还是比较钟爱与SQL处理、一来可以提高SQL的动手操作能力、而来工具处理有一定的限制性 比如同样的问题 SQL可以立于不败之地,如果只会工具处理的话 A工具我会了B工具呢 无形之中增加的学习成本 综上所述 SQL处理的重要性不言而喻 那么小手动起来吧!
先解决问题 在深入学习
> [42000] [Microsoft][SQL Server Native Client 11.0][SQL Server]参数数据类型 ntext 对于 json_value 函数的参数 1 无效。 (8116)
SELECT name AS column_name , TYPE_NAME(system_type_id) AS column_type FROM sys.columns WHERE object_id = OBJECT_ID(N'MES_SeedPot') and name = 'PotEnvironment '
SELECT
CONVERT(varchar(max),PotEnvironment)
FROM
MES_SeedPot
- with t as (
- select
- CONVERT(varchar(max),PotEnvironment) PotEnvironment
- FROM
- MES_SeedPot
- )
- -- select isjson(PotEnvironment) from t
-
- SELECT
- 'id' id,
- json_Query ( PotEnvironment, '$.id' ) v_id,
- 'potEnvDays' potEnvDays,
- json_value ( PotEnvironment, '$.potEnvDays' ) v_potEnvDays,
- 'potCO2ppm' potCO2ppm,
- Json_Value ( PotEnvironment, '$.potCO2ppm' ) v_potCO2ppm,
- 'potSmell' potSmell,
- Json_Value ( PotEnvironment, '$.potSmell' ) v_potSmell,
- 'potHypha' potHypha,
- Json_Value ( PotEnvironment, '$.potHypha' ) v_potHypha,
- 'potPressure' potPressure,
- Json_Value ( PotEnvironment, '$.potPressure' ) v_potPressure,
- 'potTemperature' potTemperature,
- Json_Value ( PotEnvironment, '$.potTemperature' ) v_potTemperature,
- 'potFlowrate' potFlowrate,
- Json_Value ( PotEnvironment, '$.potFlowrate' ) v_potFlowrate,
- 'potOperators1' potOperators1,
- Json_Value ( PotEnvironment, '$.potOperators1' ) v_potOperators1,
- 'potOperators2' potOperators2,
- Json_Value ( PotEnvironment, '$.potOperators2' ) v_potOperators2
- FROM
- t