[LeetCode]-DataBase-Combine Two Tables
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的更多相关文章
- LeetCode 175 Combine Two Tables mysql,left join 难度:0
https://leetcode.com/problems/combine-two-tables/ Combine Two Tables Table: Person +-------------+-- ...
- LeetCode 175. Combine Two Tables 【MySQL中连接查询on和where的区别】
一.题目 175. Combine Two Tables 二.分析 连接查询的时候要考虑where和on的区别 where : 查询时,连接的时候是必须严格满足条件的,满足了才会加入到临时表中. on ...
- [Leetcode|SQL] Combine Two Tables
Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId ...
- leetcode 175 Combine Two Tables join用法
https://leetcode.com/problemset/database/ ACM退役,刚好要学sql,一定要刷题才行,leetcode吧. 这一题,说了两个表,一个左一个右吧,左边的pers ...
- LeetCode 175. Combine Two Tables (组合两个表)
题目标签: 题目给了我们两个table,让我们合并,根据Person为主. 因为题目说了 提供person 信息,不管这个人有没有地址.所以这里用Left Join. Java Solution: R ...
- LeeCode(Database)-Combine Two Tables
Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId ...
- Leetcode 175. Combine Two Tables
Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId ...
- sql 中多表查询-leetcode : Combine Two Tables
因为对数据库的内容早都忘得差不多了,所以我的第一感觉是: select Person.FirstName, Person.LastName, Address.City from Person, Add ...
- leetcode database题目
LeetCode有10道SQL的题目,最近学习SQL语言,顺便刷题强化一下, 说实话刷完SQL学习指南这本书,不是很难,上面的例子 跟语法规则我都能理解透, 实际中来做一些比较难的业务逻辑题,却一下子 ...
- LeetCode Database题解
175. Combine Two Tables 使用外连接即可. # Write your MySQL query statement below select FirstName, LastName ...
随机推荐
- Maven出错的问题处理
1:使用Maven部署dubbox.jar包到maven本地仓库 由于Dubbox的jar包并没有部署到Maven的中央仓库中,大家在Maven的中央仓库中可以查找到Dubbo的最终版本是2.5.3 ...
- 邀请好友注册页面光标点到输入框后,输入框会先灰一下。只有ios存在
输入框会先灰一下.只有ios存在 用这一行代码可以解决问题: -webkit-tap-highlight-color:transparent;
- git使用以及对应sourceTree
git上面的几条指令 (1)要想把A合并到B分支上,就需要先切换到B分支上,然后在合并A分支,执行指令: git checkout B // 这是切换到B分支上 git merge A // 这是将A ...
- SQL 基础语句整理
SQL教程 SELECT 语句 SELECT * FROM 表名称 DISTINCT 语句 SELECT DISTINCT 列名称 FROM 表名称 SELECT LastName,FirstName ...
- ES各种操作的过程
参考:https://blog.csdn.net/better_xf/article/details/81188050 一.es写入数据的过程 客户端选择一个node发送请求过去,这个node就是co ...
- 配置ShiroFilter需要注意的问题(Shiro_DelegatingFilterProxy)
ShiroFilter的工作原理 ShiroFilter:DelegatingFilterProxy作用是自动到Spring 容器查找名字为shiroFilter(filter-name)的bean并 ...
- Malloc与Free不调用构造函数与析构函数
例子: #include "stdafx.h" #include <new> #include <iostream> using namespace std ...
- centos7 mysql 各种报错
1.重置root密码 vi /etc/my.cnf 添加skip-grant-tables service mysqld restart 2.mysql 登录 报错1 Unknown system v ...
- IDeajCommunity 配置smart tomcat插件
ntelliJ IDEA社区版没有自带tomcat. 装插件--smart tomcat. IntelliJ IDEA>>Preferences>>Plugins>> ...
- 连接gitlab
https://www.cnblogs.com/mengyu/p/7761340.html 一.PyCharm配置Git的环境 1.PyCharm 连接Git首先需要本机安装Git软件; 2.PyCh ...