记录一次如何查询mysql分库分表数据

 一、前言

本次查询是在未知如何分库分表的情况下,对表数据进行查询,其中有的字段为JSON结构。需要提取JSON中某个字段的内容。

二、查询步骤

1、第一方式是将所有分表数据进行union  all

select  * from  apporder.ord_shopping_order
union all 
select  * from  apporder.ord_shopping_order_2
union all 
select  * from  apporder.ord_shopping_order_3
union all 
select  * from  apporder.ord_shopping_order_4
union all 
select  * from  apporder.ord_shopping_order_5
union all 
select  * from  apporder.ord_shopping_order_6
union all 
select  * from  apporder.ord_shopping_order_7
union all 
select  * from  apporder.ord_shopping_order_8
union all 
select  * from  apporder.ord_shopping_order_9
union all 
select  * from  apporder.ord_shopping_order_10
union all 
select  * from  apporder.ord_shopping_order_11
union all 
select  * from  apporder.ord_shopping_order_12
union all 
select  * from  apporder.ord_shopping_order_13
union all 
select  * from  apporder.ord_shopping_order_14
union all 
select  * from  apporder.ord_shopping_order_15
union all 
select  * from  apporder.ord_shopping_order_16
union all 
select  * from  apporder.ord_shopping_order_17
union all 
select  * from  apporder.ord_shopping_order_18
union all 
select  * from  apporder.ord_shopping_order_19
union all 
select  * from  apporder.ord_shopping_order_20
union all 
select  * from  apporder.ord_shopping_order_21
union all 
select  * from  apporder.ord_shopping_order_22
union all 
select  * from  apporder.ord_shopping_order_23
union all 
select  * from  apporder.ord_shopping_order_24
union all 
select  * from  apporder.ord_shopping_order_25
union all 
select  * from  apporder.ord_shopping_order_26
union all 
select  * from  apporder.ord_shopping_order_27
union all 
select  * from  apporder.ord_shopping_order_28
union all 
select  * from  apporder.ord_shopping_order_29
union all 
select  * from  apporder.ord_shopping_order_30
union all 
select  * from  apporder.ord_shopping_order_31
union all 
select  * from  apporder.ord_shopping_order_32
union all 
select  * from  apporder.ord_shopping_order_33
union all 
select  * from  apporder.ord_shopping_order_34
union all 
select  * from  apporder.ord_shopping_order_35
union all 
select  * from  apporder.ord_shopping_order_36
union all 
select  * from  apporder.ord_shopping_order_37
union all 
select  * from  apporder.ord_shopping_order_38
union all 
select  * from  apporder.ord_shopping_order_39
union all 
select  * from  apporder.ord_shopping_order_40
union all 
select  * from  apporder.ord_shopping_order_41
union all 
select  * from  apporder.ord_shopping_order_42
union all 
select  * from  apporder.ord_shopping_order_43
union all 
select  * from  apporder.ord_shopping_order_44
union all 
select  * from  apporder.ord_shopping_order_45
union all 
select  * from  apporder.ord_shopping_order_46
union all 
select  * from  apporder.ord_shopping_order_47
union all 
select  * from  apporder.ord_shopping_order_48
union all 
select  * from  apporder.ord_shopping_order_49
union all 
select  * from  apporder.ord_shopping_order_50
union all 
select  * from  apporder.ord_shopping_order_51
union all 
select  * from  apporder.ord_shopping_order_52
union all 
select  * from  apporder.ord_shopping_order_53
union all 
select  * from  apporder.ord_shopping_order_54
union all 
select  * from  apporder.ord_shopping_order_55
union all 
select  * from  apporder.ord_shopping_order_56
union all 
select  * from  apporder.ord_shopping_order_57
union all 
select  * from  apporder.ord_shopping_order_58
union all 
select  * from  apporder.ord_shopping_order_59
union all 
select  * from  apporder.ord_shopping_order_60
union all 
select  * from  apporder.ord_shopping_order_61
union all 
select  * from  apporder.ord_shopping_order_62
union all 
select  * from  apporder.ord_shopping_order_63;

2、第二种方式是创建一个存储过程,方便以后更快速查询

先建一个表结构与  分表一样的表 ord_shopping_procedure

create table ord_shopping_procedure as  select  * from  ord_shopping_order_2;

create table ord_shopping_procedure as  select  * from  ord_shopping_order_2

然后创建存储过程

CREATE DEFINER=`root`@`%` PROCEDURE `apporder`.`ord_shopping`()
begin
truncate table ord_shopping_procedure;
insert into   ord_shopping_procedure
select  * from  apporder.ord_shopping_order
union all 
select  * from  apporder.ord_shopping_order_2
union all 
select  * from  apporder.ord_shopping_order_3
union all 
select  * from  apporder.ord_shopping_order_4
union all 
select  * from  apporder.ord_shopping_order_5
union all 
select  * from  apporder.ord_shopping_order_6
union all 
select  * from  apporder.ord_shopping_order_7
union all 
select  * from  apporder.ord_shopping_order_8
union all 
select  * from  apporder.ord_shopping_order_9
union all 
select  * from  apporder.ord_shopping_order_10
union all 
select  * from  apporder.ord_shopping_order_11
union all 
select  * from  apporder.ord_shopping_order_12
union all 
select  * from  apporder.ord_shopping_order_13
union all 
select  * from  apporder.ord_shopping_order_14
union all 
select  * from  apporder.ord_shopping_order_15
union all 
select  * from  apporder.ord_shopping_order_16
union all 
select  * from  apporder.ord_shopping_order_17
union all 
select  * from  apporder.ord_shopping_order_18
union all 
select  * from  apporder.ord_shopping_order_19
union all 
select  * from  apporder.ord_shopping_order_20
union all 
select  * from  apporder.ord_shopping_order_21
union all 
select  * from  apporder.ord_shopping_order_22
union all 
select  * from  apporder.ord_shopping_order_23
union all 
select  * from  apporder.ord_shopping_order_24
union all 
select  * from  apporder.ord_shopping_order_25
union all 
select  * from  apporder.ord_shopping_order_26
union all 
select  * from  apporder.ord_shopping_order_27
union all 
select  * from  apporder.ord_shopping_order_28
union all 
select  * from  apporder.ord_shopping_order_29
union all 
select  * from  apporder.ord_shopping_order_30
union all 
select  * from  apporder.ord_shopping_order_31
union all 
select  * from  apporder.ord_shopping_order_32
union all 
select  * from  apporder.ord_shopping_order_33
union all 
select  * from  apporder.ord_shopping_order_34
union all 
select  * from  apporder.ord_shopping_order_35
union all 
select  * from  apporder.ord_shopping_order_36
union all 
select  * from  apporder.ord_shopping_order_37
union all 
select  * from  apporder.ord_shopping_order_38
union all 
select  * from  apporder.ord_shopping_order_39
union all 
select  * from  apporder.ord_shopping_order_40
union all 
select  * from  apporder.ord_shopping_order_41
union all 
select  * from  apporder.ord_shopping_order_42
union all 
select  * from  apporder.ord_shopping_order_43
union all 
select  * from  apporder.ord_shopping_order_44
union all 
select  * from  apporder.ord_shopping_order_45
union all 
select  * from  apporder.ord_shopping_order_46
union all 
select  * from  apporder.ord_shopping_order_47
union all 
select  * from  apporder.ord_shopping_order_48
union all 
select  * from  apporder.ord_shopping_order_49
union all 
select  * from  apporder.ord_shopping_order_50
union all 
select  * from  apporder.ord_shopping_order_51
union all 
select  * from  apporder.ord_shopping_order_52
union all 
select  * from  apporder.ord_shopping_order_53
union all 
select  * from  apporder.ord_shopping_order_54
union all 
select  * from  apporder.ord_shopping_order_55
union all 
select  * from  apporder.ord_shopping_order_56
union all 
select  * from  apporder.ord_shopping_order_57
union all 
select  * from  apporder.ord_shopping_order_58
union all 
select  * from  apporder.ord_shopping_order_59
union all 
select  * from  apporder.ord_shopping_order_60
union all 
select  * from  apporder.ord_shopping_order_61
union all 
select  * from  apporder.ord_shopping_order_62
union all 
select  * from  apporder.ord_shopping_order_63;truncate table ord_shopping;
insert into   ord_shopping
select t.*, JSON_EXTRACT(t.json, '$.skuName') as sku_name from  (
select id,order_type,order_mode,user_id,user_name,trade_no,state,total_amount, pay_amount pay_time ,
ou_name ,mobile  ,create_time, sale_amount, JSON_EXTRACT(item_abstract_json, '$[0]') as json,store_ou_code,store_name
,mch_ou_code,mch_name
from  ord_shopping_procedure ) t;END;

由于表中存在JSON字段,同时我们再查询表是应查询需要的字段即可

所以这一段是重点

truncate table ord_shopping;
insert into   ord_shopping
select t.*, JSON_EXTRACT(t.json, '$.skuName') as sku_name from  (
select id,order_type,order_mode,user_id,user_name,trade_no,state,total_amount, pay_amount pay_time ,
ou_name ,mobile  ,create_time, sale_amount, JSON_EXTRACT(item_abstract_json, '$[0]') as json,store_ou_code,store_name
,mch_ou_code,mch_name
from  ord_shopping_procedure ) t;

truncate table ord_shopping;
insert into   ord_shopping
select t.*, JSON_EXTRACT(t.json, '$.skuName') as sku_name from  (
select id,order_type,order_mode,user_id,user_name,trade_no,state,total_amount, pay_amount pay_time ,
ou_name ,mobile  ,create_time, sale_amount, JSON_EXTRACT(item_abstract_json, '$[0]') as json,store_ou_code,store_name
,mch_ou_code,mch_name
from  ord_shopping_procedure ) t;

JSON_EXTRACT(item_abstract_json, '$[0]') as json

表示item_abstract_json这字段存储的JSON字符串数组,我们把下标为0的取出来,

样例数据是这样的

[{"id": 1059,"productType": 1,"productTypeSub": null,"skuName": "L’Oréal 欧莱雅男士锐能抗皱紧致洁面膏","skuId": 194538,"skuCode": "200015112056194538","thirdCode": "C023338","isGift": 0,"scale": null,"unit": null,"brandId": 1707,"storeOuCode": "1043002001","number": 1,"specs": "规格:100ML  ","cls1StaId": 1316,"cls2StaId": 16831,"cls3StaId": 16840,"cls1StaName": "美妆护肤","cls2StaName": "男士护肤","cls3StaName": "男士洁面","phPictureUrl": "https:///default_file/00/01/52/02.jpg","activityId": null,"activityTitle": null,"selfActivityId": null,"selfActivityTitle": null,"selfActivityType": null,"randomDeductionActivityId": null,"randomDeductionActivityTitle": null,"salePrice": 28.0,"realPrice": 28,"pointsPrice": 0,"rewardsPrice": 0,"empRewardsPrice": 0,"enterprisePrice": 0,"eleType": null,"eleDetailJson": null,"thirdServeId": null,"lineNo": "1","packageItem": [],"barcode": null,"exchangeJumpAddress": null,"skuSaleScale": null,"perWeight": null,"externalNumber": null,"externalPrice": null,"deliverType": 2,"serveHour": null,"serveFlag": 0,"qyMerchant": null,"qyAlias": null,"distributionHigherReferrerId": null,"thirdpartyDeliveryTime": null,"thirdpartyCompleteTime": null
}]

然后我们只需要取JSON的 skuName的内容就要用到这个函数

JSON_EXTRACT(t.json, '$.skuName') as sku_name

执行完存储过程,最后我们查询一下这个表ord_shopping

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/177672.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

vue跨域请求

vue.config.js devServer:{proxy:"http://localhost:8081"}main.js中定义 import axios from "axios"; axios&#xff0c; App.vue中引用 <template><Article/> </template><script> import Article from "/components/Ar…

才聚免费为你招聘,用人单位看过来!

才聚团队从1998年开始从事项目管理的推广工作&#xff0c;20多年来培训学员超30万人次&#xff0c;分布全国各地、服务企业超过5000家。拥有大批 PMP &#xff08;项目管理专业人员资格&#xff09; NPDP&#xff08;产品经理国际资格&#xff09; 软考 &#xff08;信息系统…

五丶openlayer之LOD和分辨率

LOD是Levels of Detail的简写&#xff0c;用于根据当前的环境&#xff0c;渲染不同的图像&#xff0c;用于降低非重要的细节度&#xff0c;从而提高渲染效率&#xff0c;在电子游戏中经常运用&#xff0c;对于需要显示全球地图的GIS系统而言&#xff0c;更需要应用这项技术。 …

UE5学习(游戏存档,两种适应性的射线检测,时间膨胀)

游戏存档 0.建立游戏存档类 1.建立存档 命名要用规律&#xff0c;读档时根据命名调用 2.读取存档 这里是用存档时间&#xff08;秒&#xff09;验证是否有存档成功。 两种鼠标位置射线检测方法 两种适用性未使用大量项目验证&#xff0c;为个人观点 1.适用于游戏中 2.适用于…

Ubuntu20.04部署TVM流程及编译优化模型示例

前言&#xff1a;记录自己安装TVM的流程&#xff0c;以及一个简单的利用TVM编译模型并执行的示例。 1&#xff0c;官网下载TVM源码 git clone --recursive https://github.com/apache/tvmgit submodule init git submodule update顺便完成准备工作&#xff0c;比如升级cmake版本…

YOLOv8 onnx 文件推理多线程加速视频流

运行环境&#xff1a; MacOS&#xff1a;14.0Python 3.9Pytorch2.1onnx 运行时 模型文件&#xff1a; https://wwxd.lanzouu.com/iBqiA1g49pbc 密码:f40v 下载 best.apk后将后缀名修改为 onnx 即可模型在英伟达 T4GPU 使用 coco128 训练了 200 轮如遇下载不了可私信获取 代码…

个人投资白银收益怎么样?

个人投资白银是可以带来丰厚的收益&#xff0c;但收益的具体情况取决于多种因素。以下是一些明确的答案和举例&#xff0c;帮助投资者更好地理解个人投资白银的收益情况。 白银市场的价格波动是决定投资收益的主要因素之一&#xff0c;白银价格受全球经济形势、地缘局势风险、…

Cesium 可视化深度纹理

Cesium 可视化深度纹理 // 创建纹理辅助器图元const textureHelper new TextureHelperPrimitive(viewer.scene)viewer.scene.primitives.add(textureHelper)viewer.scene.postRender.addEventListener(function () {const framebuffer viewer.scene.view.pickDepths[0]?.fra…

设计前中后队列 : 图解极简队列解法 [Deque + 纯数组](含进阶链表)

题目描述 这是 LeetCode 上的 「1670. 设计前中后队列」 &#xff0c;难度为 「中等」。 Tag : 「数据结构」、「双端队列」、「队列」、「链表」 请你设计一个队列&#xff0c;支持在前&#xff0c;中&#xff0c;后三个位置的 push 和 pop 操作。 请你完成 FrontMiddleBack 类…

easyexcel指定sheet页动态给行列加背景色

easyexcel&#xff0c;有多个sheet页&#xff0c;某些sheet页的行、列动态需要加背景色 import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.Head; import com.alibaba.excel.write.handler.CellWriteHandler; import com.alibaba.excel.write.m…

了解FastSam:一个通用分割模型(草记)

想尝试这个FastSam的部署&#xff0c;但至今还没跑通&#xff0c;一个问题能带出一片问题&#xff0c;感觉挺心情挺郁闷的。后来和学长交流的时候&#xff0c;说那就是学少了&#xff0c;没必要急着将跑通它作为目的。也很有道理&#xff0c;这个任务还不太适合我当前的水平&am…

「Verilog学习笔记」信号发生器

专栏前言 本专栏的内容主要是记录本人学习Verilog过程中的一些知识点&#xff0c;刷题网站用的是牛客网 方波的实现&#xff0c;较为简单&#xff0c;只需要设置一个计数器&#xff0c;使输出保持10个时钟为0&#xff0c;跳变为20&#xff0c;再保持10个时钟。依次循环。可以按…

基于Webserver的工业数据采集控制

http协议 http简介 HTTP协议是Hyper Text Transfer Protocol&#xff08;超文本传输协议&#xff09;的缩写&#xff0c;是用于Web Browser&#xff08;浏览器&#xff09;到Web Server&#xff08;服务器&#xff09;进行数据交互的传输协议。 HTTP是应用层协议 HTTP是一个基于…

蓝桥杯每日一题2023.11.28

题目描述 三羊献瑞 - 蓝桥云课 (lanqiao.cn) 题目分析 本题首先进行观察可以确定 1.“三”为 1 &#xff08;十进制数字要进位进一位&#xff09; 2.“祥”一定不为 0 &#xff08;有前导0就不能算为 4 位数&#xff09; 使用搜索时将其特判 #include<bits/stdc.h> …

【RLChina2023】CCF 苏州 记录

目录 RLChina介绍主旨报告专题报告智能体学习理论(专题一)智能体决策与规划(专题二)智能体框架、体系结构与训练系统(专题六)基于大语言模型的具身智能体与机器人研究 (专题八)教学报告——强化学习入门特别论坛——智能体和多智能体艺术的探索会议照片RLChina介绍 RLC…

【华为OD题库-040】计算最接近的数-java

题目 给定一个数组X和正整数K&#xff0c;请找出使表达式X[i]-x[i1]…-X[ik-1]&#xff0c;结果最接近于数组中位数的下标i&#xff0c;如果有多个满足条件&#xff0c;请返回最大的i。 其中&#xff0c;数组中位数:长度为N的数组&#xff0c;按照元素的值大小升序排列后&#…

「阿里巴巴」裁撤量子实验室!

据内部消息&#xff0c;阿里巴巴达摩院由于预算及盈利等原因&#xff0c;已经撤裁旗下量子实验室。此次&#xff0c;共计裁减30余人。 达摩院官网已撤下量子实验室的相关介绍页面。上图&#xff1a;早先关于量子实验室的相关介绍&#xff1b;下图&#xff1a;现在达摩院官网“实…

Linux 局域网传输工具LANDrop安装

Linux 局域网传输工具LANDrop安装 &#x1f959;下载&#x1f32d;解压&#x1f96a;运行 &#x1f959;下载 官网下载 或网盘 &#x1f32d;解压 使用以下命令解压获得squashfs-root文件夹 ./LANDrop-latest-linux.AppImage --appimage-extract&#x1f96a;运行 进入squ…

flutter 文本不随系统设置而改变大小[最全的整理]

文本不随系统设置而改变大小[三] 前言方案十三&#xff1a;使用Flexible方案十四&#xff1a;使用MediaQueryData的textScaleFactor属性方案十五&#xff1a;使用FractionallySizedBox方案十六&#xff1a;使用自定义文本样式方案十七&#xff1a;使用自定义绘制&#xff08;Cu…

Doris_Doris导入常见问题

Doris数据导入错误 &#xff1a;the length of input is too larger than schema 可能原因&#xff1a;varchar长度设置过短 Doris表字段乱序 导入palo表中的csv本身无schema信息&#xff0c;csv与palo表字段顺序必须一致&#xff0c;否则会错乱 Doris数据文件中字段比表字段…