博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
sql横着连接起来sql_SQL联接
阅读量:2505 次
发布时间:2019-05-11

本文共 1600 字,大约阅读时间需要 5 分钟。

sql横着连接起来sql

Joins are a very powerful tool. Remember relational algebra from the database intro module?

联接是一个非常强大的工具。 还记得数据库介绍模块中的关系代数吗?

Joins are applied relational algebra.

连接是应用关系代数

Suppose you have 2 tables, people and cars:

假设您有2张桌子, people cars

CREATE TABLE people (  age INT NOT NULL,  name CHAR(20) NOT NULL PRIMARY KEY);CREATE TABLE cars (  brand CHAR(20) NOT NULL,  model CHAR(20) NOT NULL,  owner CHAR(20) NOT NULL PRIMARY KEY);

We add some data:

我们添加一些数据:

INSERT INTO people VALUES (37, 'Flavio');INSERT INTO people VALUES (8, 'Roger');INSERT INTO cars VALUES ('Ford', 'Fiesta', 'Flavio');INSERT INTO cars VALUES ('Ford', 'Mustang', 'Roger');

Now say that we want to correlate the two tables, because the police stopped Roger driving, looks young, and want to know his age from their database.

现在,我们要关联这两个表,因为警察阻止了Roger的驾驶,看起来很年轻,并且想从他们的数据库中知道他的年龄。

Roger is my dog, but let’s suppose dogs can drive cars.

罗杰是我的狗,但让我们假设狗可以开车。

We can create a join with this syntax:

我们可以使用此语法创建一个连接

SELECT age FROM people JOIN cars ON people.name = cars.owner WHERE cars.model='Mustang';

We’ll get this result back:

我们将获得以下结果:

age -----   8

What is happening? We are joining the two tables cars on two specific columns: name from the people table, and owner from the cars table.

怎么了? 我们将两个表格中的cars加入到两个特定的列中: people表中的namecars表中的owner

Joins are a topic that can grow in complexity because there are many different kind of joins that you can use to do fancier things with multiple tables, but here is the most basic example.

联接是一个可能会变得越来越复杂的主题,因为可以使用多种不同的联接对多个表进行更复杂的操作,但这是最基本的示例。

翻译自:

sql横着连接起来sql

转载地址:http://chmgb.baihongyu.com/

你可能感兴趣的文章
Overlay之VXLAN架构
查看>>
Eclipse : An error occurred while filtering resources(Maven错误提示)
查看>>
在eclipse上用tomcat部署项目404解决方案
查看>>
web.xml 配置中classpath: 与classpath*:的区别
查看>>
suse如何修改ssh端口为2222?
查看>>
详细理解“>/dev/null 2>&1”
查看>>
suse如何创建定时任务?
查看>>
suse搭建ftp服务器方法
查看>>
centos虚拟机设置共享文件夹并通过我的电脑访问[增加smbd端口修改]
查看>>
文件拷贝(IFileOperation::CopyItem)
查看>>
MapReduce的 Speculative Execution机制
查看>>
大数据学习之路------借助HDP SANDBOX开始学习
查看>>
Hadoop基础学习:基于Hortonworks HDP
查看>>
为什么linux安装程序 都要放到/usr/local目录下
查看>>
Hive安装前扫盲之Derby和Metastore
查看>>
永久修改PATH环境变量的几种办法
查看>>
大数据学习之HDP SANDBOX开始学习
查看>>
Hive Beeline使用
查看>>
Centos6安装图形界面(hdp不需要,hdp直接从github上下载数据即可)
查看>>
CentOS7 中把yum源更换成163源
查看>>