当前位置: 首页 > news >正文

网站建设 小程序制作免费卖货平台

网站建设 小程序制作,免费卖货平台,广告设计公司合同,输入姓名查询个人征信目录 一、说明二、示例2.1 simple:简单表,不使用union或者子查询2.2 primary:主查询,外层的查询2.3 subquery:select、where之后包含了子查询,在select语句中出现的子查询语句,结果不依赖于外部…

目录

        • 一、说明
        • 二、示例
            • 2.1 simple:简单表,不使用union或者子查询
            • 2.2 primary:主查询,外层的查询
            • 2.3 subquery:select、where之后包含了子查询,在select语句中出现的子查询语句,结果不依赖于外部查询(不在from语句中)
            • 2.4 dependent subquery:指在select语句中出现的查询语句,结果依赖于外部查询
            • 2.5 derived:派生表
            • 2.6 union
            • 2.7 union all
            • 2.8 dependent union
        • 三、sql脚本

一、说明

  • 1.表示select的类型,查询语句执行的查询操作的类型
  • 2.常见的取值有:simple、primary、union、subquery、dependent subquery
  • 3.simple:简单表,不使用union或者子查询
  • 4.primary:主查询,外层的查询
  • 5.union:union中的第二个或者后面的查询语句
  • 6.subquery:select、where之后包含了子查询,在select语句中出现的子查询语句,结果不依赖于外部查询(不在from语句中)
  • 7.dependent subquery:指在select语句中出现的查询语句,结果依赖于外部查询
  • 8.derived:派生表,在from子句的查询语句,表示从外部数据源中推导出来,不是从select语句中的其他列中选择出来的
  • 9.union:分union与union all两种,若第二个select出现在union之后,则被标记为union;如果union被from子句的子查询包含,则第一个select会被标记为derived;union会针对相同的结果集进行去重,union all不会进行去重处理
  • 10.dependent union:当union作为子查询时,第一个union为dependent subquery,第二个union为dependent union

二、示例

2.1 simple:简单表,不使用union或者子查询
1.单表的select_type,不使用union和子查询
explain select * from users;

在这里插入图片描述

2.表连接查询的select_type,不使用union和子查询
explain select * from users inner join orders where users.id = orders.user_id;

在这里插入图片描述

2.2 primary:主查询,外层的查询
explain select id from users union select id from orders;

在这里插入图片描述

2.3 subquery:select、where之后包含了子查询,在select语句中出现的子查询语句,结果不依赖于外部查询(不在from语句中)
explain select orders.*,(select product_name from products where id = 10001) from orders;

在这里插入图片描述

2.4 dependent subquery:指在select语句中出现的查询语句,结果依赖于外部查询
explain select orders.*,(select product_name from products where id = orders.product_id) from orders;

在这里插入图片描述

2.5 derived:派生表
-- 关闭对衍生表合并优化
set session optimizer_switch='derived_merge=off';
-- 查看optimizer_switch参数
show variables like '%optimizer_switch%';
-- 
explain select * from (select user_id from orders where id = 10001) as temp;
-- 还原表合并优化
set session optimizer_switch='derived_merge=on';

在这里插入图片描述

2.6 union

1.union result:union关键字会将数据结果进行去重,会使用一个临时表,临时表的记录会被标记为union result

explain select * from (select id from products where product_price = 8000 union select id from orders where user_id = 20001 union select id from users where user_name = '张三' ) as temp;

在这里插入图片描述

2.7 union all
explain select * from (select id from products where product_price = 8000 union all select id from orders where user_id = 20001 union all select id from users where user_name = '张三' ) as temp;

在这里插入图片描述

2.8 dependent union
explain select * from orders where id in (select id from products where product_price = 8000 union all select id from orders where user_id = 20001
union all select id from users where user_name = '张三');

在这里插入图片描述

三、sql脚本

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;-- ----------------------------
-- Table structure for orders
-- ----------------------------
DROP TABLE IF EXISTS `orders`;
CREATE TABLE `orders`  (`id` int(0) NOT NULL COMMENT '主键id',`price` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '订单总额',`user_id` int(0) DEFAULT NULL COMMENT '用户id',`product_id` int(0) DEFAULT NULL COMMENT '产品id',`number` int(0) DEFAULT NULL COMMENT '产品数量',PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;-- ----------------------------
-- Records of orders
-- ----------------------------
INSERT INTO `orders` VALUES (10001, '80000', 20001, 10001, 10);-- ----------------------------
-- Table structure for products
-- ----------------------------
DROP TABLE IF EXISTS `products`;
CREATE TABLE `products`  (`id` int(0) NOT NULL COMMENT '主键id',`product_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '商品名称',`product_price` decimal(10, 2) DEFAULT NULL COMMENT '商品价格',PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;-- ----------------------------
-- Records of products
-- ----------------------------
INSERT INTO `products` VALUES (10001, '苹果手机', 8000.00);-- ----------------------------
-- Table structure for users
-- ----------------------------
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users`  (`id` int(0) NOT NULL COMMENT '主键id',`user_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '用户名称',PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;-- ----------------------------
-- Records of users
-- ----------------------------
INSERT INTO `users` VALUES (20001, '张三');SET FOREIGN_KEY_CHECKS = 1;
http://www.tj-hxxt.cn/news/46536.html

相关文章:

  • 电商网站开发目的深圳互联网推广公司
  • 做网站怎么样才能赚到钱机构类网站有哪些
  • wordpress用户组 隐藏seo
  • 做网站是什么课合肥网站优化排名推广
  • 个人做门户网站如何编写一个网站
  • 企业网站源码自适应seosem顾问
  • 日照网站建设doingseo大型网站seo课程
  • 药膳网站建设的目的湖南发展最新消息公告
  • 网站刷单账务处理怎么做百度seo技术优化
  • 网络推广软件费用情况aso具体优化
  • 自己做网站 套模板yoast seo教程
  • 短视频代运营公司靠谱吗许昌网站seo
  • github做网站空间关键词搜索点击软件
  • 怎么用阿里云建网站软文网站推荐
  • dedecms做论坛网站全球疫情最新数据统计
  • 宁波附近的seo推广广东百度seo
  • 渠道网站怎么做蛋糕
  • 做下载类网站赚钱吗成品短视频网站源码搭建
  • 海淀石家庄网站建设百度快照入口官网
  • 苏州网站建设熊掌分析网站推广和优化的原因
  • 企业宣传网站设计论文百度软件
  • 新余商城网站建设哪里有做网络推广的
  • 美间在线设计平台安卓手机优化
  • 怎么做网站安全运维电子商务网站建设与管理
  • 长春市长春网站建设网seo外链发布工具
  • 怪兽网站模板泰安seo
  • wordpress 用户 搜索绍兴seo推广公司
  • 做电影网站用什么虚拟主机网址搜索ip地址
  • 石青网站推广软件2023年8月疫情严重吗
  • 深圳全网建站公司推荐java培训机构十强