柠檬工会_工会经营者

柠檬工会

Hey guys! This week we’ll be going over some ways to work with result sets in MySQL. These result sets are the outputs of your everyday queries, such as:

大家好! 本周,我们将介绍一些在MySQL中处理结果集的方法。 这些结果集是您日常查询的输出,例如:

Image for post

联盟 (UNION)

One way to combine two result sets is by using the UNION operator. By default, this combines two result sets without duplicating any rows. This works as you would believe it would in set theory. The syntax for this would be:

合并两个结果集的一种方法是使用UNION运算符。 默认情况下,这将合并两个结果集,而不会重复任何行。 正如您所相信的那样,这会起作用。 语法如下:

Image for post

Where you have your regular SELECT statements, but use UNION to combine each result set. Each UNION can be followed by either DISTINCT or ALL. DISTINCT will combine the sets but keep each unique value only once, while ALL will combine the sets while keeping duplicates. If you don’t specify either, DISTINCT is used, which is pretty intuitive.

在具有常规SELECT语句的位置,但使用UNION合并每个结果集。 每个UNION后面都可以加上DISTINCTALLDISTINCT将合并集合,但每个唯一值仅保留一次,而ALL将合并集合,同时保留重复项。 如果您未指定任何一个,则使用DISTINCT ,这非常直观。

Do note that each SELECT statement should have the same number of columns selected and the data types of the columns should be compatible.

请注意,每个SELECT语句应选择相同数量的列,并且列的数据类型应兼容。

Now let’s look at an example using this. Let’s say we have two tables, table1 and table2, as shown below:

现在让我们来看一个使用此示例。 假设我们有两个表,table1和table2,如下所示:

Image for post

If we were to combine both columns, col1 and col2, from each table, by following the syntax:

如果我们要通过遵循以下语法将每个表中的列col1和col2组合在一起:

Image for post

Will produce the following:

将产生以下内容:

Image for post

Also note that the result’s column names will match those of the first SELECT statement. We can also use aliasing to change this by aliasing the column names of the first SELECT statement.

还要注意,结果的列名将与第一个SELECT语句的列名匹配。 我们还可以使用别名来更改别名,方法是对第一个SELECT语句的列名进行别名处理。

You may have noticed that UNION is similar to JOIN. They both merge your data. However, UNION combines sets vertically, while JOIN combines sets horizontally, as illustrated below:

您可能已经注意到UNION与JOIN类似。 他们都合并您的数据。 但是,UNION垂直组合集合,而JOIN水平组合集合,如下所示:

Image for post
Union vs. (Inner) Join联合与(内部)合并

Now we know how to combine different result sets into a single one!

现在我们知道如何将不同的结果集组合为一个!

The following resource is a huge help for anything SQL related!

以下资源对于任何与SQL相关的问题都是巨大的帮助!

翻译自: https://medium.com/@gl7526/the-union-operator-4721f2ca3482

柠檬工会

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

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

相关文章

229. 求众数 II

229. 求众数 II 给定一个大小为 n 的整数数组,找出其中所有出现超过 ⌊ n/3 ⌋ 次的元素。 示例 1:输入:[3,2,3] 输出:[3]示例 2:输入:nums [1] 输出:[1]示例 3:输入:…

写给Java开发者看的JavaScript对象机制

帮助面向对象开发者理解关于JavaScript对象机制 本文是以一个熟悉OO语言的开发者视角,来解释JavaScript中的对象。 对于不了解JavaScript 语言,尤其是习惯了OO语言的开发者来说,由于语法上些许的相似会让人产生心理预期,JavaScrip…

Pythonic---------详细讲解

作者:半载流殇 链接:https://zhuanlan.zhihu.com/p/35219750 来源:知乎 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。Pythonic,简言之就是以Python这门语言独特的方式写出既简洁又优美的代码…

大数据ab 测试_在真实数据上进行AB测试应用程序

大数据ab 测试Hello Everyone!大家好! I am back with another article about Data Science. In this article, I will write about what is A-B testing and how to use it on real life data-set to compare two advertisement methods.我回来了另一篇有关数据科…

492. 构造矩形

492. 构造矩形 作为一位web开发者, 懂得怎样去规划一个页面的尺寸是很重要的。 现给定一个具体的矩形页面面积,你的任务是设计一个长度为 L 和宽度为 W 且满足以下要求的矩形的页面。要求: 你设计的矩形页面必须等于给定的目标面积。 宽度 …

node:爬虫爬取网页图片

前言 周末自己在家闲着没事,刷着微信,玩着手机,发现自己的微信头像该换了,就去网上找了一下头像,看着图片,自己就想着作为一个码农,可以把这些图片都爬取下来做成一个微信小程序,说干…

如何更好的掌握一个知识点_如何成为一个更好的讲故事的人3个关键点

如何更好的掌握一个知识点You’re launching a digital transformation initiative in the middle of the ongoing pandemic. You are pretty excited about this big-ticket investment, which has the potential to solve remote-work challenges that your organization fac…

centos 搭建jenkins+git+maven

gitmavenjenkins持续集成搭建发布人:[李源] 2017-12-08 04:33:37 一、搭建说明 系统:centos 6.5 jdk:1.8.0_144 jenkins:jenkins-2.93-1.1 git:git-2.9.0 maven:Maven 3.3.9 二、部署 2.1、jdk安装 1)下…

638. 大礼包

638. 大礼包 在 LeetCode 商店中, 有 n 件在售的物品。每件物品都有对应的价格。然而,也有一些大礼包,每个大礼包以优惠的价格捆绑销售一组物品。 给你一个整数数组 price 表示物品价格,其中 price[i] 是第 i 件物品的价格。另有…

记录一次spark连接mysql遇到的问题

在使用spark连接mysql的过程中报错了,错误如下 08:51:32.495 [main] ERROR - Error loading factory org.apache.calcite.jdbc.CalciteJdbc41Factory java.lang.NoClassDefFoundError: org/apache/calcite/linq4j/QueryProviderat java.lang.ClassLoader.defineCla…

什么事数据科学_如果您想进入数据科学,则必须知道的7件事

什么事数据科学No way. No freaking way to enter data science any time soon…That is exactly what I thought a year back.没门。 很快就不会出现进入数据科学的怪异方式 ……这正是我一年前的想法。 A little bit about my data science story: I am a complete beginner…

python基础03——数据类型string

1. 字符串介绍 在python中,引号中加了引号的字符都被认为是字符串。 1 namejim 2 address"beijing" 3 msg My name is Jim, I am 22 years old! 那单引号、双引号、多引号有什么区别呢? 1) 单双引号木有任何区别,部分情况 需要考虑…

Java基础-基本数据类型

Java中常见的转义字符: 某些字符前面加上\代表了一些特殊含义: \r :return 表示把光标定位到本行行首. \n :next 表示把光标定位到下一行同样的位置. 单独使用在某些平台上会产生不同的效果.通常这两个一起使用,即:\r\n. 表示换行. \t :tab键,长度上相当于四个或者是八个空格 …

季节性时间序列数据分析_如何指导时间序列数据的探索性数据分析

季节性时间序列数据分析为什么要进行探索性数据分析? (Why Exploratory Data Analysis?) You might have heard that before proceeding with a machine learning problem it is good to do en end-to-end analysis of the data by carrying a proper exploratory …

TortoiseGit上传项目到GitHub

1. 简介 gitHub是一个面向开源及私有软件项目的托管平台,因为只支持git 作为唯一的版本库格式进行托管,故名gitHub。 2. 准备 2.1 安装git:https://git-scm.com/downloads。无脑安装 2.2 安装TortoiseGit(小乌龟):https://torto…

496. 下一个更大元素 I

496. 下一个更大元素 I 给你两个 没有重复元素 的数组 nums1 和 nums2 ,其中nums1 是 nums2 的子集。 请你找出 nums1 中每个元素在 nums2 中的下一个比其大的值。 nums1 中数字 x 的下一个更大元素是指 x 在 nums2 中对应位置的右边的第一个比 x 大的元素。如果…

利用PHP扩展Taint找出网站的潜在安全漏洞实践

一、背景 笔者从接触计算机后就对网络安全一直比较感兴趣,在做PHP开发后对WEB安全一直比较关注,2016时无意中发现Taint这个扩展,体验之后发现确实好用;不过当时在查询相关资料时候发现关注此扩展的人数并不多;最近因为…

美团骑手检测出虚假定位_在虚假信息活动中检测协调

美团骑手检测出虚假定位Coordination is one of the central features of information operations and disinformation campaigns, which can be defined as concerted efforts to target people with false or misleading information, often with some strategic objective (…

869. 重新排序得到 2 的幂

869. 重新排序得到 2 的幂 给定正整数 N ,我们按任何顺序(包括原始顺序)将数字重新排序,注意其前导数字不能为零。 如果我们可以通过上述方式得到 2 的幂,返回 true;否则,返回 false。 示例 …

org.apache.maven.archiver.MavenArchiver.getManifest

eclipse导入新的maven项目时,pom.xml第一行报错: org.apache.maven.archiver.MavenArchiver.getManifest(org.apache.maven.project.MavenProject, org.apache.maven.archiver.MavenArchiveConfiguration) 解决办法: help -> Install New…