【MySQL】ON WHERE 和 ON AND 的区别

1. 查询语句语法规则

image

  • “[ ]” 包含的内容可以省略;

  • “{ }” 包含的内容必须存在;

  • DISTINCT: 设定 **distinct** 可以去掉重复记录;

  • AS: 表明或字段名过长时,可以用 **AS** 关键字起别名,也可省略不写,但查询语句复杂时可读性会很差;

  • GROUP BY: 按组分类显示查询出的数据;

  • HAVING:**GROUP BY** 分组时依赖的分组条件;

  • ORDER BY: 将查询出来的结果集按照一定顺序排序完成;

  • LIMIT: 限制显示查询结果的条数;

2. WHERE 和 ON 的区别

WHEREON
用来过滤单个表或过滤连接后的结果集;用来执行 join 操作时指定连接条件;
可以在没有连接的情况下单独使用;只能在连接操作时使用,用于确定如何将两个或多个表中的行进行匹配;
子句的条件是在连接操作之后应用;子句的条件基于两个表之间的关联列;
可以引用任何列,不局限于连接条件的列;在连接操作过程中用于确定哪些列应该被连接;

3. 实验准备

SQL 脚本:

/*
 Navicat Premium Data Transfer

 Source Server         : mysql
 Source Server Type    : MySQL
 Source Server Version : 80016
 Source Host           : localhost:3306
 Source Schema         : git_db

 Target Server Type    : MySQL
 Target Server Version : 80016
 File Encoding         : 65001

 Date: 08/05/2024 23:31:48
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;


-- ----------------------------
-- Table structure for dish
-- ----------------------------
DROP TABLE IF EXISTS `dish`;
CREATE TABLE `dish`  (
  `id` bigint(20) NOT NULL COMMENT '主键',
  `name` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '菜品名称',
  `category_id` bigint(20) NOT NULL COMMENT '菜品分类id',
  `price` decimal(10, 2) NULL DEFAULT NULL COMMENT '菜品价格',
  `code` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '商品码',
  `image` varchar(200) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '图片',
  `description` varchar(400) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '描述信息',
  `status` int(11) NOT NULL DEFAULT 1 COMMENT '0 停售 1 起售',
  `sort` int(11) NOT NULL DEFAULT 0 COMMENT '顺序',
  `create_time` datetime(0) NOT NULL COMMENT '创建时间',
  `update_time` datetime(0) NOT NULL COMMENT '更新时间',
  `create_user` bigint(20) NOT NULL COMMENT '创建人',
  `update_user` bigint(20) NOT NULL COMMENT '修改人',
  `is_deleted` int(11) NOT NULL DEFAULT 0 COMMENT '是否删除',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `idx_dish_name`(`name`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '菜品管理' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of dish
-- ----------------------------
INSERT INTO `dish` VALUES (1397849739276890114, '辣子', 1397844263642378242, 7800.00, '222222222', 'FmftrRvdL8_XcB5k6hYOhLhGEooz', '来自鲜嫩美味的小鸡,值得一尝', 1, 0, '2021-05-27 09:38:43', '2024-01-05 17:25:18', 1, 1737037426064642049, 1);
INSERT INTO `dish` VALUES (1397850140982161409, '毛氏红烧肉', 1397844263642378242, 6800.00, '123412341234', 'FmJKaugRK038RldaGmXXdRIcgxHS', '毛氏红烧肉毛氏红烧肉,确定不来一份?', 1, 0, '2021-05-27 09:40:19', '2023-12-26 10:52:55', 1, 1722873762260840450, 0);
INSERT INTO `dish` VALUES (1397850392090947585, '组庵鱼翅', 1397844263642378242, 4800.00, '123412341234', 'FgOalYD18aSVNp3Jmd5hmpPpvwvz', '组庵鱼翅,看图足以表明好吃程度', 1, 0, '2021-05-27 09:41:19', '2024-01-05 17:25:18', 1, 1737037426064642049, 1);
INSERT INTO `dish` VALUES (1397850851245600769, '霸王别姬', 1397844263642378242, 12800.00, '123412341234', 'FliwXr-EIkopolHKj-Fw55vZKQPL', '还有什么比霸王别姬更美味的呢?', 0, 0, '2021-05-27 09:43:08', '2023-12-27 19:15:23', 1, 1722873762260840450, 1);
INSERT INTO `dish` VALUES (1397851099502260226, '全家福', 1397844263642378242, 11800.00, '23412341234', 'FtyT7Hfvwk2os6eLd2sbQfwJ7saW', '别光吃肉啦,来份全家福吧,让你长寿又美味', 0, 0, '2021-05-27 09:44:08', '2023-12-27 19:15:23', 1, 1722873762260840450, 1);
INSERT INTO `dish` VALUES (1397851370462687234, '邵阳猪血丸子', 1397844263642378242, 13800.00, '1246812345678', 'Fq3HHLNj5LUwdtbA2oYHFDbD8Zcc', '看,美味不?来嘛来嘛,这才是最爱吖', 1, 0, '2021-05-27 09:45:12', '2023-12-26 14:33:00', 1, 1722873762260840450, 0);
INSERT INTO `dish` VALUES (1397851668262465537, '口味蛇', 1397844263642378242, 16800.00, '1234567812345678', 'FnVsJK_n0qCgLqiCcmyXjtwig7sR', '爬行界的扛把子,东兴-口味蛇,让你欲罢不能', 0, 0, '2021-05-27 09:46:23', '2023-12-27 19:15:23', 1, 1722873762260840450, 1);
INSERT INTO `dish` VALUES (1397852391150759938, '辣子鸡丁', 1397844303408574465, 8800.00, '2346812468', 'FmftrRvdL8_XcB5k6hYOhLhGEooz', '辣子鸡丁,辣子鸡丁,永远的魂', 1, 0, '2021-05-27 09:49:16', '2023-12-27 11:05:20', 1, 1722873762260840450, 0);
INSERT INTO `dish` VALUES (1397853183287013378, '麻辣兔头', 1397844303408574465, 19800.00, '123456787654321', 'Fvp6Rux94uPXaq9qBBKRrB_XpNyR', '麻辣兔头的详细制作,麻辣鲜香,色泽红润,回味悠长', 1, 0, '2021-05-27 09:52:24', '2023-12-27 11:06:25', 1, 1722873762260840450, 0);
INSERT INTO `dish` VALUES (1397853709101740034, '蒜泥白肉', 1397844303408574465, 9800.00, '1234321234321', 'FraH3a_GWeUcDBPOlpzfETbmd0Uy', '多么的有食欲啊', 1, 0, '2021-05-27 09:54:30', '2023-12-27 11:07:14', 1, 1722873762260840450, 0);
INSERT INTO `dish` VALUES (1397862477831122945, '上汤焗龙虾', 1397844391040167938, 108800.00, '', 'Fm07DblGbESyZm7EwJiHXYjhxD5K', '上汤焗龙虾是一道色香味俱全的传统名菜,属于粤菜系。此菜以龙虾为主料,配以高汤制成的一道海鲜美食。本品肉质洁白细嫩,味道鲜美,蛋白质含量高,脂肪含量低,营养丰富。是色香味俱全的传统名菜。', 1, 0, '2021-05-27 10:29:20', '2023-12-27 11:04:23', 1, 1722873762260840450, 0);
INSERT INTO `dish` VALUES (1413342036832100354, '北冰洋', 1413341197421846529, 500.00, '', 'Fh3638DI4tN5vt89JaQsoRN3IP27', '', 1, 0, '2021-07-09 11:39:35', '2024-01-05 17:25:18', 1, 1737037426064642049, 1);
INSERT INTO `dish` VALUES (1413384757047271425, '王老吉', 1413341197421846529, 500.00, '', 'Fir_CMcjZOaho4R4ZhjZGOa349BV', '', 1, 0, '2021-07-09 14:29:20', '2023-12-27 11:07:45', 1, 1722873762260840450, 0);
INSERT INTO `dish` VALUES (1413385247889891330, '米饭', 1413384954989060097, 200.00, '', 'FpC_XrOuJ5WeKnIQTmUMQjbJW9X0', '', 1, 0, '2021-07-09 14:31:17', '2024-01-05 17:20:57', 1, 1737037426064642049, 0);
INSERT INTO `dish` VALUES (1537734154819469314, '剁椒鱼头', 1397844303408574465, 2000.00, '', 'FqCDofIDL-zsDIWcp-Cfb0Z8gP7L', '无', 0, 0, '2022-06-17 17:49:27', '2023-12-27 19:15:23', 1, 1722873762260840450, 1);
INSERT INTO `dish` VALUES (1539187286716006402, '宫保鸡丁', 1397844303408574465, 2000.00, '', 'Fp9olpQsWJKHUgVQzZgUPLtMiFWI', '很下饭', 0, 0, '2022-06-21 18:03:41', '2023-12-27 19:15:23', 1, 1722873762260840450, 1);
INSERT INTO `dish` VALUES (1739535644308574209, '红烧狮子头', 1397844263642378242, 4399.00, '1231231234567', 'FiKfhSo5St-xQAW57gtddZND-cuR', '', 1, 0, '2023-12-26 14:36:31', '2023-12-26 14:36:31', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish` VALUES (1739536700186857474, '饭小满', 1397844263642378242, 6899.00, '1231231234567', 'FibIOLVZNQ5lCiybqQeLsR1RY2Mf', '汤小鲜和饭小满,惠子专属', 0, 0, '2023-12-26 14:40:43', '2024-01-05 17:25:18', 1722873762260840450, 1737037426064642049, 1);
INSERT INTO `dish` VALUES (1743157716142280706, '蛋蛋', 1397844263642378242, 2334.00, '1231231234567', 'Fpt-V3t4igDXkgtkFiUdMiOEX83N', '', 1, 0, '2024-01-05 14:29:20', '2024-01-05 14:31:50', 1722873762260840450, 1722873762260840450, 1);
INSERT INTO `dish` VALUES (1743201852635525122, '东北菜', 1737398571216732161, 58.80, '1231231234567', 'FrU7WUw7HOQ4Mnv-GSQ7tma0zTNR', '', 1, 0, '2024-01-05 17:24:43', '2024-01-05 17:25:18', 1737037426064642049, 1737037426064642049, 1);

-- ----------------------------
-- Table structure for dish_flavor
-- ----------------------------
DROP TABLE IF EXISTS `dish_flavor`;
CREATE TABLE `dish_flavor`  (
  `id` bigint(20) NOT NULL COMMENT '主键',
  `dish_id` bigint(20) NOT NULL COMMENT '菜品',
  `name` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '口味名称',
  `value` varchar(500) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL COMMENT '口味数据list',
  `create_time` datetime(0) NOT NULL COMMENT '创建时间',
  `update_time` datetime(0) NOT NULL COMMENT '更新时间',
  `create_user` bigint(20) NOT NULL COMMENT '创建人',
  `update_user` bigint(20) NOT NULL COMMENT '修改人',
  `is_deleted` int(11) NOT NULL DEFAULT 0 COMMENT '是否删除',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_bin COMMENT = '菜品口味关系表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of dish_flavor
-- ----------------------------
INSERT INTO `dish_flavor` VALUES (1397849417888346113, 1397849417854791681, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-27 09:37:27', '2021-05-27 09:37:27', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397849936421761025, 1397849936404983809, '忌口', '[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]', '2021-05-27 09:39:30', '2021-05-27 09:39:30', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397849936438538241, 1397849936404983809, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-27 09:39:30', '2021-05-27 09:39:30', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397850630734262274, 1397850630700707841, '忌口', '[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]', '2021-05-27 09:42:16', '2021-05-27 09:42:16', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397850630755233794, 1397850630700707841, '辣度', '[\"微辣\",\"中辣\",\"重辣\"]', '2021-05-27 09:42:16', '2021-05-27 09:42:16', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397853423486414850, 1397853423461249026, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-27 09:53:22', '2021-05-27 09:53:22', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397853890283089922, 1397853890262118402, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-27 09:55:13', '2021-05-27 09:55:13', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397854133632413697, 1397854133603053569, '温度', '[\"热饮\",\"常温\",\"去冰\",\"少冰\",\"多冰\"]', '2021-05-27 09:56:11', '2021-05-27 09:56:11', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397854652623007745, 1397854652581064706, '忌口', '[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]', '2021-05-27 09:58:15', '2021-05-27 09:58:15', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397854652635590658, 1397854652581064706, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-27 09:58:15', '2021-05-27 09:58:15', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397854865735593986, 1397854865672679425, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-27 09:59:06', '2021-05-27 09:59:06', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397855742303186946, 1397855742273826817, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-27 10:02:35', '2021-05-27 10:02:35', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397855906497605633, 1397855906468245506, '忌口', '[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]', '2021-05-27 10:03:14', '2021-05-27 10:03:14', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397856190573621250, 1397856190540066818, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-27 10:04:21', '2021-05-27 10:04:21', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397859056709316609, 1397859056684150785, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-27 10:15:45', '2021-05-27 10:15:45', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397859277837217794, 1397859277812051969, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-27 10:16:37', '2021-05-27 10:16:37', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397859487502086146, 1397859487476920321, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-27 10:17:27', '2021-05-27 10:17:27', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397859757061615618, 1397859757036449794, '甜味', '[\"无糖\",\"少糖\",\"半躺\",\"多糖\",\"全糖\"]', '2021-05-27 10:18:32', '2021-05-27 10:18:32', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397860242086735874, 1397860242057375745, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-27 10:20:27', '2021-05-27 10:20:27', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397860963918065665, 1397860963880316929, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-27 10:23:19', '2021-05-27 10:23:19', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397861135754506242, 1397861135733534722, '甜味', '[\"无糖\",\"少糖\",\"半躺\",\"多糖\",\"全糖\"]', '2021-05-27 10:24:00', '2021-05-27 10:24:00', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397861370035744769, 1397861370010578945, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-27 10:24:56', '2021-05-27 10:24:56', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397861683459305474, 1397861683434139649, '忌口', '[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]', '2021-05-27 10:26:11', '2021-05-27 10:26:11', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397861898467717121, 1397861898438356993, '忌口', '[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]', '2021-05-27 10:27:02', '2021-05-27 10:27:02', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1397862198054268929, 1397862198033297410, '忌口', '[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]', '2021-05-27 10:28:14', '2021-05-27 10:28:14', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1398089545865015297, 1398089545676271617, '温度', '[\"热饮\",\"常温\",\"去冰\",\"少冰\",\"多冰\"]', '2021-05-28 01:31:38', '2021-05-28 01:31:38', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1398089782323097601, 1398089782285348866, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-28 01:32:34', '2021-05-28 01:32:34', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1398090003262255106, 1398090003228700673, '忌口', '[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]', '2021-05-28 01:33:27', '2021-05-28 01:33:27', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1398090264554811394, 1398090264517062657, '忌口', '[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]', '2021-05-28 01:34:29', '2021-05-28 01:34:29', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1398090455399837698, 1398090455324340225, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-28 01:35:14', '2021-05-28 01:35:14', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1398090685449023490, 1398090685419663362, '温度', '[\"热饮\",\"常温\",\"去冰\",\"少冰\",\"多冰\"]', '2021-05-28 01:36:09', '2021-05-28 01:36:09', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1398090825358422017, 1398090825329061889, '忌口', '[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]', '2021-05-28 01:36:43', '2021-05-28 01:36:43', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1398091007051476993, 1398091007017922561, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-28 01:37:26', '2021-05-28 01:37:26', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1398091296164851713, 1398091296131297281, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-28 01:38:35', '2021-05-28 01:38:35', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1398091546531246081, 1398091546480914433, '忌口', '[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]', '2021-05-28 01:39:35', '2021-05-28 01:39:35', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1398091729809747969, 1398091729788776450, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-28 01:40:18', '2021-05-28 01:40:18', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1398091889499484161, 1398091889449152513, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-28 01:40:56', '2021-05-28 01:40:56', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1398092095179763713, 1398092095142014978, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-28 01:41:45', '2021-05-28 01:41:45', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1398092283877306370, 1398092283847946241, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-28 01:42:30', '2021-05-28 01:42:30', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1398094018939236354, 1398094018893099009, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-28 01:49:24', '2021-05-28 01:49:24', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1398094391494094850, 1398094391456346113, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-05-28 01:50:53', '2021-05-28 01:50:53', 1, 1, 0);
INSERT INTO `dish_flavor` VALUES (1399574026165727233, 1399305325713600514, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2021-06-01 03:50:25', '2021-06-01 03:50:25', 1399309715396669441, 1399309715396669441, 0);
INSERT INTO `dish_flavor` VALUES (1739479372016144386, 1397850140982161409, '忌口', '[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]', '2023-12-26 10:52:55', '2023-12-26 10:52:55', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739479372066476033, 1397850140982161409, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2023-12-26 10:52:55', '2023-12-26 10:52:55', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739532310017249283, 1739532310017249282, '麻辣', '[\"香辣\"]', '2023-12-26 14:23:16', '2023-12-26 14:23:16', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739534757175529474, 1397851370462687234, '温度', '[\"热饮\",\"常温\",\"去冰\",\"少冰\",\"多冰\"]', '2023-12-26 14:33:00', '2023-12-26 14:33:00', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739534757175529475, 1397851370462687234, '忌口', '[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]', '2023-12-26 14:33:00', '2023-12-26 14:33:00', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739534757242638338, 1397851370462687234, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2023-12-26 14:33:00', '2023-12-26 14:33:00', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739535644308574210, 1739535644308574209, '辣味', '[\"麻辣\"]', '2023-12-26 14:36:31', '2023-12-26 14:36:31', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739844644069826562, 1397862477831122945, '辣度', '[\"不辣\",\"微辣\",\"中辣\"]', '2023-12-27 11:04:23', '2023-12-27 11:04:23', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739844884004986881, 1397852391150759938, '忌口', '[\"不要葱\",\"不要香菜\",\"不要辣\"]', '2023-12-27 11:05:20', '2023-12-27 11:05:20', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739844884004986882, 1397852391150759938, '辣度', '[\"不辣\",\"微辣\",\"重辣\"]', '2023-12-27 11:05:20', '2023-12-27 11:05:20', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739845155649085441, 1397853183287013378, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2023-12-27 11:06:25', '2023-12-27 11:06:25', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739845364533813249, 1397853709101740034, '忌口', '[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]', '2023-12-27 11:07:14', '2023-12-27 11:07:14', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739845491591864322, 1413384757047271425, '温度', '[\"常温\",\"冷藏\"]', '2023-12-27 11:07:45', '2023-12-27 11:07:45', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739845691626610689, 1413342036832100354, '温度', '[\"常温\",\"冷藏\"]', '2023-12-27 11:08:32', '2023-12-27 11:08:32', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739845919285043202, 1739536700186857474, '甜味', '[\"香甜\"]', '2023-12-27 11:09:27', '2023-12-27 11:09:27', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739846471691657218, 1397850392090947585, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2023-12-27 11:11:38', '2023-12-27 11:11:38', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739846471691657219, 1397850392090947585, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2023-12-27 11:11:38', '2023-12-27 11:11:38', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739846656018735105, 1539187286716006402, '甜味', '[\"少糖\"]', '2023-12-27 11:12:22', '2023-12-27 11:12:22', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739846656018735106, 1539187286716006402, '忌口', '[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]', '2023-12-27 11:12:22', '2023-12-27 11:12:22', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739846656018735107, 1539187286716006402, '辣度', '[\"中辣\",\"重辣\"]', '2023-12-27 11:12:22', '2023-12-27 11:12:22', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739846825481199617, 1537734154819469314, '甜味', '[\"全糖\"]', '2023-12-27 11:13:03', '2023-12-27 11:13:03', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739846825481199618, 1537734154819469314, '忌口', '[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]', '2023-12-27 11:13:03', '2023-12-27 11:13:03', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739846825481199619, 1537734154819469314, '温度', '[\"常温\"]', '2023-12-27 11:13:03', '2023-12-27 11:13:03', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739846825552502786, 1537734154819469314, '辣度', '[\"微辣\"]', '2023-12-27 11:13:03', '2023-12-27 11:13:03', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739847028082860033, 1397851668262465537, '温度', '[\"热饮\",\"常温\",\"去冰\",\"少冰\",\"多冰\"]', '2023-12-27 11:13:51', '2023-12-27 11:13:51', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739847213240410114, 1397851099502260226, '忌口', '[\"不要葱\",\"不要蒜\",\"不要香菜\",\"不要辣\"]', '2023-12-27 11:14:35', '2023-12-27 11:14:35', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739847213240410115, 1397851099502260226, '辣度', '[\"不辣\",\"微辣\",\"中辣\"]', '2023-12-27 11:14:35', '2023-12-27 11:14:35', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739847432023695361, 1397850851245600769, '忌口', '[\"不要蒜\",\"不要香菜\",\"不要辣\"]', '2023-12-27 11:15:27', '2023-12-27 11:15:27', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1739847432023695362, 1397850851245600769, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2023-12-27 11:15:27', '2023-12-27 11:15:27', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1743156290007687170, 1397849739276890114, '辣度', '[\"不辣\",\"微辣\",\"中辣\",\"重辣\"]', '2024-01-05 14:23:40', '2024-01-05 14:23:40', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1743157716142280707, 1743157716142280706, '1234', '[\"菜品\"]', '2024-01-05 14:29:20', '2024-01-05 14:29:20', 1722873762260840450, 1722873762260840450, 0);
INSERT INTO `dish_flavor` VALUES (1743201954439671809, 1743201852635525122, '甜味', '[\"7分甜\"]', '2024-01-05 17:25:08', '2024-01-05 17:25:08', 1737037426064642049, 1737037426064642049, 0);


SET FOREIGN_KEY_CHECKS = 1;

实验环境

操作系统:Windows 11 专业版

MySQL版本号:8.0.11

可视化工具:Navicat Premium 12

WHERE | AND | ON

where…and…

image

    select name,category_id,price,description from dish 
      where category_id='1397844303408574465' 
      and price=2000;

image

left join … on …

    select dish.name,category_id,price,description,dish_flavor.name,dish_flavor.`value` from dish 
      left join dish_flavor 
      on dish.id = dish_flavor.dish_id;

image

left join … on … where …

    select dish.name,category_id,price,description,dish_flavor.name,dish_flavor.`value` 
    from dish 
    left join dish_flavor 
    on dish.id = dish_flavor.dish_id
    where dish_flavor.name='辣度';

image

left join … on … and …

    select dish.name,category_id,price,description,dish_flavor.name,dish_flavor.`value` 
    from dish 
    left join dish_flavor 
    on dish.id = dish_flavor.dish_id
    and dish_flavor.name='辣度';

image

left join … on … where … and …

    select dish.name,category_id,price,description,dish_flavor.name,dish_flavor.`value` 
    from dish 
    left join dish_flavor 
    on dish.id = dish_flavor.dish_id
    where dish_flavor.name='辣度'
    and dish.name='组庵鱼翅';

image

left join … on … and … where …

    select dish.name,category_id,price,description,dish_flavor.name,dish_flavor.`value` 
    from dish 
    left join dish_flavor 
    on dish.id = dish_flavor.dish_id
    and dish_flavor.name='辣度'
    where dish.name='组庵鱼翅';

image

结论

  • **left join ... on ... where ...** <= **left join ... on ... and ...**
  1. where 会对含有 null 值的记录进行过滤,and 不会;
  • **left join ... on ... where ... and ....** = **left join ... on ... and ... where ...**
  1. 前者经过 where 对含有 null 值的记录进行了过滤,后者在 and 语句完成后对结果集进行了 null 值记录过滤,所以二者的效果几乎一样;
  • 由于数据库记录条数较少,在进行查询性能测试时误差在0.03秒左右,作不了考证,故没有对此作叙述,使用了 <= 和 = 来表述两条查询语句之间的关系qwq

总结

  1. where 用于对结果集的任何列进行过滤,包括没有参与连接的列

    a. 在连接之后应用,不会影响连接的执行计划,仅影响返回的行数

  2. on 用于指定连接两个或多个表中的连接条件,通常基于两个表之间的关联列;

    a. 影响连接的执行计划,减少参与连接的行数,从而提高查询性能。

  3. and 用于条件追加,不会对含有 null 值的记录进行过滤;


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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

06.配置邮件报警

配置邮件报警 我的授权码&#xff1a;HCHNVOAENURLOACG 1.定义发件人 密码是163邮箱的授权码 2.配置收件人 我就配置收件人是qq邮箱了 3.启动动作 验证邮件发送成功

Redis如何避免数据丢失?——AOF

目录 AOF日志 1. 持久化——命令写入到AOF文件 写到用户缓冲区 AOF的触发入口函数——propagate 具体的实现逻辑——feedAppendOnlyFile 从用户缓冲区写入到AOF文件(磁盘&#xff09; 函数write、fsync、fdatasync Redis的线程池 AOF文件的同步策略 触发的入口函数——…

特斯拉擎天柱机器人:工厂自动化的未来

随着技术的进步&#xff0c;工业自动化已经逐步进入了一个新的纪元。特斯拉最近公布的擎天柱机器人Optimus的演示&#xff0c;不仅仅展示了一个高科技机器人的能力&#xff0c;更是向我们揭示了未来工厂的可能性。 特斯拉擎天柱机器人的功能展示 马斯克在最新的演示中向我们展…

使用Nuxt.js实现服务端渲染(SSR)

Nuxt.js 是一个基于 Vue.js 的框架&#xff0c;它提供了服务器端渲染&#xff08;SSR&#xff09;和静态站点生成&#xff08;SSG&#xff09;的能力&#xff0c;使开发者能够轻松地构建高效、优雅的前端应用。Nuxt.js 集成了许多开箱即用的功能和工具&#xff0c;帮助开发者快…

C语言—深入理解指针(2)

1.数组名的理解 不难发现&#xff0c;数组名就是数组首元素的地址。 但是有两个例外&#xff1a; 1.sizeof&#xff08;数组名&#xff09; 这里的数组名表示整个数组&#xff0c;计算的是整个数组的大小&#xff0c;单位是字节。 2.&数组名 这里的数组名也表示整个数…

MacOS miniconda安装方法

打开macos “终端” 应用 执行命令 mkdir -p ~/miniconda3curl https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-MacOSX-arm64.sh -o ~/miniconda3/miniconda.shbash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3rm -rf ~/miniconda3/mini…

CPU基本知识点

目录 1.概念 2.分类 3.运作原理 4.指令系统 1.概念 CPU&#xff1a;英文Central Processing Unit&#xff0c;即中央处理器。 解释和执行指令的功能单元&#xff0c;它是计算机的中枢神经系统&#xff08;即核心&#xff09;。 是计算机最核心的部件&#xff0c;主要是运算…

嵌入式数据库SQLite 3配置使用详细笔记教程

0、惨痛教训 随着管理开发的项目体积越来越庞大&#xff0c;产品系统涉及的数据量也越来越多&#xff0c;并且伴随着项目不久就要交付给甲方了。如果项目的数据信息没有被妥善管理&#xff0c;后期设备的运行状态、操作状况等数据流信息不能被溯源&#xff0c;当出现了一些特殊…

【35分钟掌握金融风控策略16】贷前风控策略详解-1

目录 贷前风控策略详解 贷前风控目标 精准审核申请贷款客户资质 对申请贷款客户进行合理定额 对申请贷款客户进行合理定价 推动实现利润最大化 贷前风控数据源 客户贷款时提供的数据 贷前风控策略详解 俗话说&#xff0c;良好的开端是成功的一半&#xff0c;而贷前是风…

C++新手村指南:入门基础

目录 C概念 C发展史 C关键字&#xff08;C98&#xff09; 命名空间 命名空间的定义 命名空间的使用 C中的输入&&输出 缺省参数 缺省参数的概念 缺省参数的分类 函数重载 函数重载概念 函数重载实现 引用 引用的概念 引用的特性 常引用 引用的使用场景…

基于单片机的小型自动浇灌系统设计

摘 要:以单片机为主控芯片,结合传感器和计算机,搭建了一套智能化的浇灌系统;利用LabVIEW 设计并编写了基于状态机程序架构的上位机软件,实现了友好的用户交互界面,实时测量、显示与记录等功能,并由主控芯片进行浇灌。经测试,本系统具有结构简单,研制成本低,运…

详细介绍一下PointPillars算法的网络结构

PointPillars是一种用于3D目标检测的算法&#xff0c;它主要使用了点云数据和深度学习模型。 PointPillars算法的网络结构主要可以分为三个主要阶段&#xff1a; Pillar Feature Net&#xff08;点云特征处理网络&#xff09;&#xff1a;此阶段的主要任务是将输入的点云数据转…

回答篇:测试开发高频面试题目

引用之前文章&#xff1a;《测试开发高频面试题目》 https://blog.csdn.net/qq_41214208/article/details/138193469?spm1001.2014.3001.5502 本篇文章是回答篇&#xff08;持续更新中&#xff09; 1. 什么是测试开发以及其在软件开发流程中的作用。 a. 测试开发是指测试人员或…

Java:Servlet详解

目录 一、什么是Servlet 二、Servlet原理 Servlet的生命周期 三、 Servlet注释 WebServlet 一、什么是Servlet Servlet是JavaWeb开发的一种技术&#xff0c;Servlet程序需要部署在Servlet容器&#xff08;服务端&#xff09;中才能运行&#xff0c;常见的Servlet容器有Tom…

【C++】环境搭建CentOS Clion报错Unsupported git Version 1.8.3.1

【C】环境搭建Clion-Unsupported git Version 1.8.3.1 Git升级步骤1.卸载旧版本2.安装依赖3.下载git最新版本包4.解压git文件包5.编译文件5.将git加入环境变量6.验证git版本 如上图所示&#xff0c;报错Unsupported git Version 1.8.3.1 At least 2.17.0 is required 报错意思…

windows驱动开发-inf文件(一)

驱动总是和inf文件相关&#xff0c;在WinDDK的时候&#xff0c;许多inf文件都需要开发工程师手动编写&#xff0c;不过&#xff0c;现在已经可以使用inx文件来生成inf文件了&#xff0c;它经常用于驱动的安装和卸载&#xff1b;不过&#xff0c;并不是所有的驱动都需要使用inf文…

小白修复msvcp140.dll丢失的解决方法,一键修复丢失的dll文件

在我们使用电脑时&#xff0c;常常会碰到各种烦人的状况。比方说&#xff0c;当我们期待畅玩游戏时&#xff0c;可能会突然遭遇一则令人沮丧的提示&#xff1a;“打开游戏缺少msvcp140.dll文件”。这个问题会给我们带来困扰和不愉快&#xff0c;但庆幸的是&#xff0c;有多种解…

UE4_Water插件_Buoyancy组件使用

water插件提供了一个浮力Actor蓝图类。 需要注意的几个问题&#xff1a; 1、StaticMesh需要替换根组件。 2、需要模拟物理设置质量。 3、需要添加浮力组件&#xff0c;设置浮力点&#xff0c;应用水中牵引力。 4、最重要的是需要激活——自动启用。 5、调水波长的地方 双击图片…

【JavaScript】内置对象 - Date 日期对象 ④ ( 制作倒计时页面 )

文章目录 一、倒计时页面实现1、需求分析2、计算秒数3、计算倒计时时间的 天 / 时 / 分 / 秒4、页面中显示倒计时时间 二、完整代码示例1、完整代码2、执行结果 Date 日期对象参考文档 : https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Da…

北京大学肖臻老师《区块链技术与应用》P16(状态树)和P17(交易树和收据树)

1️⃣ 参考 北京大学肖臻老师《区块链技术与应用》 P16 - ETH状态树篇P17 - ETH交易树和收据树篇 部分文字和图片 北京大学肖臻老师《区块链技术与应用》公开课笔记18——ETH数据结构篇2(状态树2)北京大学肖臻老师《区块链技术与应用》公开课笔记19——ETH数据结构篇3(交易树和…