mysql 查询json类型数据

如果 t1表里有一个extra字段,字段是text类型,数据为json格式  {"value":"XMjgxIqqqqqqqqqq"}

如何获取json里面value对于的值呢?

JSON_EXTRACT(t1.extra,‘$.value‘)

得到 "XMjgxIqqqqqqqqqq"

原始sql和原始结果

select t1.id AS item_id, t1.title AS item_name,t6.id AS topic_id,
       t6.title AS topic_name, t1.extra AS media_id, t1.biz_type
        from tem t1
        join component_item t2 on t1.id = t2.item_id
        join component t3 on t2.component_id = t3.id
        join drawer t4 on t4.id = t3.drawer_id
        join channel_drawer t5 on t5.drawer_id = t4.id
        join channel t6 on t6.id = t5.channel_id
        where t1.biz_type in ("JUMP_TO_SHOW","JUMP_TO_VIDEO")
              and t1.extra IS NOT NULL
              and t6.topic_property IS NOT NULL 

优化后的sql

select t1.id AS item_id, t1.title AS item_name,t6.id AS topic_id,
       t6.title AS topic_name, JSON_EXTRACT(t1.extra,‘$.value‘) AS media_id,
       trim(LEADING ‘JUMP_TO_‘ from t1.biz_type) AS biz_type
        from item_pre t1
        join component_item_pre t2 on t1.id = t2.item_id
        join component_pre t3 on t2.component_id = t3.id
        join drawer_pre t4 on t4.id = t3.drawer_id
        join channel_drawer_pre t5 on t5.drawer_id = t4.id
        join channel_pre t6 on t6.id = t5.channel_id
        where t1.biz_type in ("JUMP_TO_SHOW","JUMP_TO_VIDEO")
              and t1.extra IS NOT NULL
              and t6.topic_property IS NOT NULL
              and JSON_EXTRACT(t6.topic_property,‘$.group‘)= "电影"

时间: 2024-08-30 02:17:29

mysql 查询json类型数据的相关文章

使用Python向MySQL数据库中存入json类型数据

0.说明 因为出于个人项目的需要,获取到的数据都是json类型的,并且都要存入MySQL数据库中,因为json类型数据不像一般的文本数据,所以在存入MySQL时需要注意的问题很多. 在网上找了很多方法,整理了一下比较实用可靠的,总结下来就是下面的过程: MySQL表中需要保证存储json数据的列类型为BLOB: 使用sql语句时,使用MySQLdb.excape_string函数来对json数据进行转义: 查询数据时,将结果使用json.loads就能够得到原来的Python数据类型: 下面就来

Struts2+Jquery实现ajax并返回json类型数据

主要实现步骤如下: 1.JSP页面使用脚本代码执行ajax请求 2.Action中查询出需要返回的数据,并转换为json类型模式数据 3.配置struts.xml文件 4.页面脚本接受并处理数据 网上看到很多关于Struts2+ajax+jquery+json的例子,但是很多都不完整,也看不明白,主要原因是返回jsno类型数据和原来的返回字符串类型数据不一样,并且网友们实现步骤没有说清楚,让初学的朋友捉摸不透到底该怎么做. 我做了个简单的demo,供网友们学习,最后我会附上链接,可以下载整个de

MySQL对JSON类型UTF-8编码导致中文乱码探讨

前言 继上文发表之后,结合评论意见并亲自验证最终发现是编码的问题,但是对于字符编码还是有点不解,于是乎,有了本文,我们来学习字符编码,在学习的过程中,我发现对于MySQL中JSON类型的编码导致数据中文出现乱码还有可深挖之处,接下来我们来分析一下,若有错误之处,还请批评指出. 字符编码 评论中指出任何不在基本多文本平面的Unicode字符,都无法使用MySQL的utf8字符集存储,包括Emoji 表情(Emoji 是一种特殊的Unicode 编码,常见于IOS和Android 手机上)和很多不常

MVC - 11(下).jquery.tmpl.js 接收JSON类型数据循环

继续 mvc-11(上).dto:http://www.cnblogs.com/tangge/p/3840060.html jquery.tmpl.js 下载:http://pan.baidu.com/s/1o68w7Ke   1.前台 Index.cshtml @{ ViewBag.Title = "学员列表"; } @section headSection{ <script type="text/x-jquery-tmpl" id="trtemp

C#操作json类型数据

将对象序列化为 JavaScript 对象表示法 (JSON),并将 JSON 数据反序列化为对象. 此类不能继承. // msdn 例子: [csharp] view plaincopy namespace SL_DataContractJsonSerializer { public partial class Page : UserControl { public Page() { InitializeComponent(); } //This uses an event handler, 

mysql查询各种类型的前N条记录

mysql查询各种类型的前N条记录,将3改为N(需查询条数)即可  (select * from event_info where event_type = 1  limit 3)union all(select * from event_info where event_type = 2  limit 3)union all(select * from event_info where event_type = 3  limit 3) 原文出处:http://my.oschina.net/u/

mysql存取blob类型数据

参考网址:http://www.cnblogs.com/jway1101/p/5815658.html 首先是建表语句,需要实现将表建立好. CREATE TABLE `blobtest` ( `primary_id` varchar(32) NOT NULL, `bank_id` varchar(32) NOT NULL, `bank_name` varchar(64) NOT NULL, `blob_data` blob NOT NULL, PRIMARY KEY (`primary_id`

mysql查询当天所有数据sql语句

mysql查询当天的所有信息: select * from test where year(regdate)=year(now()) and month(regdate)=month(now()) and day(regdate)=day(now())这个有一些繁琐,还有简单的写法: select * from table where date(regdate) = curdate();另一种写法没测试过查询当天的记录 select * from hb_article_view where TO

Mybatis和Mysql的Json类型

Mysql5.7新增加了Json类型字段,但是目前Mybatis中并不支持 1.新建MybatisJsonTypeHandler.java import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.