在mysql查询中构造json对象时取消引用一个值

nzkunb0c  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(292)

mysql版本5.7.12
查询

SELECT JSON_OBJECT(unix_timestamp(created_time),JSON_OBJECT(status,cast(concat(count(status))as char))) FROM table_name where  status='NEW'  and unix_timestamp(created_time) between 1512543400 and 1532716199 GROUP BY unix_timestamp(created_time);

结果

+--------------------------------------------------------------------------------------------------+
| JSON_OBJECT(unix_timestamp(created_time),JSON_OBJECT(status,cast(concat(count(status))as char))) |
+--------------------------------------------------------------------------------------------------+
| {"1526447587": {"NEW": "1"}}                                                                     |
| {"1530170666": {"NEW": "1"}}                                                                     |
+--------------------------------------------------------------------------------------------------+

我想像下面这样取消引用值“1”,怎么做??

{"1526447587": {"NEW": 1}}
oxiaedzo

oxiaedzo1#

把石膏取下来 char :

SELECT JSON_OBJECT(UNIX_TIMESTAMP(NOW()), JSON_OBJECT('hello', 312)) AS output
FROM dual

这将输出:

{"1532691464": {"hello": 312}}

演示

相关问题