Table: Person

+-------------+---------+
| Column Name | Type |
+-------------+---------+
| PersonId | int |
| FirstName | varchar |
| LastName | varchar |
+-------------+---------+
PersonId is the primary key column for this table.

Table: Address

+-------------+---------+
| Column Name | Type |
+-------------+---------+
| AddressId | int |
| PersonId | int |
| City | varchar |
| State | varchar |
+-------------+---------+
AddressId is the primary key column for this table.

Write a SQL query for a report that provides the following information for each person in the Person table, regardless if there is an address for each of those people:

FirstName, LastName, City, State

需求:简单的表连接

查询:sql

CREATE TABLE Person(
PersonId TINYINT UNSIGNED auto_increment PRIMARY KEY,
FirstName varchar(20),
LastName varchar(20)
)ENGINE=MyISAM CHARSET=utf8;
CREATE TABLE Address(
AddressId TINYINT UNSIGNED auto_increment PRIMARY KEY,
PersonId TINYINT UNSIGNED,
City VARCHAR(20),
State VARCHAR(20)
)ENGINE=MyISAM CHARSET=utf8;

SELECT t1.FirstName,t1.LastName,t2.City,t2.State
FROM Person t1
LEFT JOIN Address t2 ON t1.PersonId=t2.PersonId


[LeetCode]-DataBase-Combine Two Tables的更多相关文章

  1. LeetCode 175 Combine Two Tables mysql,left join 难度:0

    https://leetcode.com/problems/combine-two-tables/ Combine Two Tables Table: Person +-------------+-- ...

  2. LeetCode 175. Combine Two Tables 【MySQL中连接查询on和where的区别】

    一.题目 175. Combine Two Tables 二.分析 连接查询的时候要考虑where和on的区别 where : 查询时,连接的时候是必须严格满足条件的,满足了才会加入到临时表中. on ...

  3. [Leetcode|SQL] Combine Two Tables

    Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId ...

  4. leetcode 175 Combine Two Tables join用法

    https://leetcode.com/problemset/database/ ACM退役,刚好要学sql,一定要刷题才行,leetcode吧. 这一题,说了两个表,一个左一个右吧,左边的pers ...

  5. LeetCode 175. Combine Two Tables (组合两个表)

    题目标签: 题目给了我们两个table,让我们合并,根据Person为主. 因为题目说了 提供person 信息,不管这个人有没有地址.所以这里用Left Join. Java Solution: R ...

  6. LeeCode(Database)-Combine Two Tables

    Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId ...

  7. Leetcode 175. Combine Two Tables

    Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId ...

  8. sql 中多表查询-leetcode : Combine Two Tables

    因为对数据库的内容早都忘得差不多了,所以我的第一感觉是: select Person.FirstName, Person.LastName, Address.City from Person, Add ...

  9. leetcode database题目

    LeetCode有10道SQL的题目,最近学习SQL语言,顺便刷题强化一下, 说实话刷完SQL学习指南这本书,不是很难,上面的例子 跟语法规则我都能理解透, 实际中来做一些比较难的业务逻辑题,却一下子 ...

  10. LeetCode Database题解

    175. Combine Two Tables 使用外连接即可. # Write your MySQL query statement below select FirstName, LastName ...

随机推荐

  1. jQuery-点击按钮页面滚动到顶部,底部,指定位置

    $('.scroll_top').click(function(){$('html,body').animate({scrollTop: '0px'}, 800);}); //页面滚动至顶部 $('. ...

  2. Python 集合的各种操作 数学运算 关系操作 增删改查 生成式

    # 集合是无序的 是可变的 不能重复 允许数学运算 分散存储 # 创建# collegel = {'哲学','经济学','法学','教育学'}## # {'教育学', '经济学', '法学', '哲学 ...

  3. python爬虫常用第三方库

    这个列表包含与网页抓取和数据处理的Python库 网络 通用 urllib -网络库(stdlib). requests -网络库. grab – 网络库(基于pycurl). pycurl – 网络 ...

  4. PHP trait与单例模式 (一次编写,到处使用)

    一  trait php是单继承的语言,无法同时从两个基类中继承属性和方法,为了解决这个问题,php出了Trait这个特性. 个人理解的trait是: trait = abstract class - ...

  5. vue 简介 vue 项目 组件

    1. 概念 Vue (读音 /vjuː/,类似于 view) 是一套用于构建用户界面的渐进式框架.能够为复杂的单页应用提供驱动. 2. 用法 2.1 声明式渲染 2.1.1 改变文本     {{ m ...

  6. 位操作符:&位与、|位或、^异或、~求反、<<左移位、>>带符号右移位、>>>无符号右移位

    . 操作符 名称 实例(例中使用字节) 描述 & 位与 10101110 & 10010010 得到10000010 两个相应位上比特如果都为1,则执行 与 操作会得到1 | 位或 1 ...

  7. 将shell脚本的执行过程和执行结果导入到log文件中

    [root@localhost scripts]# vim ping.sh #!/bin/bash set -x ##分步执行 exec &> /tmp/log.txt ##脚本执行的过 ...

  8. centos7 部署zabbix服务器端

    zabbix服务器端搭建与部署: 1.部署LAMP环境由于zabbix提供集中的web监控管理界面,因此服务在web界面的呈现需要LAMP架构支持.php 连接mysql服务,因为7版本mysql要收 ...

  9. 6U VPX 高性能计算存储板卡

    基于6U VPX的 XC7VX690T+C6678的双FMC接口雷达通信处理板   一.板卡概述 高性能VPX信号处理板基于标准6U VPX架构,提供两个标准FMC插槽,适用于电子对抗或雷达信号等领域 ...

  10. 网络流 最大流 Drainage Ditches Dinic

    hdu 1532 题目大意: 就是由于下大雨的时候约翰的农场就会被雨水给淹没,无奈下约翰不得不修建水沟,而且是网络水沟,并且聪明的约翰还控制了水的流速,本题就是让你求出最大流速,无疑要运用到求最大流了 ...