[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 ...
随机推荐
- PostgreSQL-临时表空间与配置表
虽然我给数据库创建了表空间,但是操作中仍遇到了些问题,需要创建临时表空间. 配置表 首先了解下 postgres 的配置表,手动修改各种配置. 打开即可看到各种配置,包括临时表空间. 临时表空间 1. ...
- ELK的搭建以及使用
一.架构如图: 二.工作机制: 在需要收集日志的应用上安装filebeat(需要修改配置文件,配置文件稍后介绍),启动filebeat后,会收集该应用的日志推送给redis,然后logstash从re ...
- MySQL表存在外键关系无法清空数据的解决方案
先 SET FOREIGN_KEY_CHECKS=0; 然后delete删除,再 SET FOREIGN_KEY_CHECKS=1;
- vs2012编译CZMQ-2.2.0
1.下载源代码包 到地址http://download.zeromq.org/czmq-2.2.0.zip下载源代码,解压缩到czmq-2.2.0文件夹下如图所看到的 watermark/2/text ...
- 08、beta-actin和GAPDH的3'/5'比值
一.大部分的基因都有beta-action基因和GAPDH基因,很多Affymetrix芯片都将它们设为一组观察RNA降解程度的内参基因.mRNA是按照5’至3’的顺序来降解的,通过比较它们3’相对于 ...
- CentOS 设置 yum源
什么是 yum Yum(全称 Yellow Dog Updater)是一个在 Fedora 和 RedHat 以及 CentOS 中的 Shell 前端软件包管理器.基于 RPM 包管理,能够从指定的 ...
- Json解析报错: Error is : Unescaped control character...的解决方法
在利用json-framework来实现json解析的过程时,会出现"-JSONValue Failed. Error is : Unescaped control character&qu ...
- fork树
i son/pa ppid pid fpid parent parent parent child child parent child parent parent child child child ...
- 五、WebSocket 链接
一.前端代码: <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml& ...
- mysql5.7.26做主从复制配置
一.首先两台服务器安装好mysql数据库环境 参照linux rpm方式安装mysql5.1 https://www.cnblogs.com/sky-cheng/p/10564604.html 二.主 ...