当前位置:网站首页>175. Combine two tables (very simple)
175. Combine two tables (very simple)
2022-07-27 03:13:00 【only-qi】
Problem description :
surface : Person
+-------------+---------+
| Name | type |
+-------------+---------+
| PersonId | int |
| FirstName | varchar |
| LastName | varchar |
+-------------+---------+
personId Is the primary key column of the table .
This table contains some people's ID And their last and first names .
surface : Address
+-------------+---------+
| Name | type |
+-------------+---------+
| AddressId | int |
| PersonId | int |
| City | varchar |
| State | varchar |
+-------------+---------+
addressId Is the primary key column of the table .
Each row of the table contains a ID = PersonId Information about people's cities and states .
Write a SQL Query to report Person The last name of each person in the list 、 name 、 Cities and states . If personId Your address is not in Address In the table , The report is empty null .
With In any order Return result table .
The query result format is as follows .
Example :
Example 1:
Input :
Person surface :
+----------+----------+-----------+
| personId | lastName | firstName |
+----------+----------+-----------+
| 1 | Wang | Allen |
| 2 | Alice | Bob |
+----------+----------+-----------+
Address surface :
+-----------+----------+---------------+------------+
| addressId | personId | city | state |
+-----------+----------+---------------+------------+
| 1 | 2 | New York City | New York |
| 2 | 3 | Leetcode | California |
+-----------+----------+---------------+------------+
Output :
+-----------+----------+---------------+----------+
| firstName | lastName | city | state |
+-----------+----------+---------------+----------+
| Allen | Wang | Null | Null |
| Bob | Alice | New York City | New York |
+-----------+----------+---------------+----------+
explain :
There is no personId = 1 The address of , So their cities and States return null.
addressId = 1 Contains personId = 2 Address information for .
Pass times 403,646
Submit the number 547,216
On sql, Take it to run :
CREATE TABLE `address` (
`AddressId` int(10) NOT NULL AUTO_INCREMENT,
`PersonId` int(10) DEFAULT NULL,
`City` varchar(255) DEFAULT NULL,
`State` varchar(255) DEFAULT NULL,
PRIMARY KEY (`AddressId`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
CREATE TABLE `person` (
`PersonId` int(11) NOT NULL AUTO_INCREMENT,
`FirstName` varchar(255) DEFAULT NULL,
`LastName` varchar(255) DEFAULT NULL,
PRIMARY KEY (`PersonId`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;SELECT p.FirstName,p.LastName,a.City,a.State from person as p left join address as a on a.PersonId=p.PersonIdI want to brush it 300 Algorithm questions , The first 108 Avenue
边栏推荐
- 185. All employees with the top three highest wages in the Department (mandatory)
- 2649: segment calculation
- CAS deployment and successful login jump address
- Source code analysis of warning notification for skywalking series learning
- What did kubedmin do?
- CS224W fall 1.2 Applications of Graph ML
- 五、MFC视图窗口和文档
- 阿里云技术专家杨泽强:弹性计算云上可观测能力的构建
- 2649: 段位计算
- 对象创建的流程分析
猜你喜欢

基于GoLang实现API短信网关

window对象的常见事件

HCIP第十三天笔记

易灵思T35 FPGA驱动LVDS显示屏

Kubeadmin到底做了什么?

Inftnews | ggac and China Aerospace ases exclusively produce "China 2065 Collection Edition"
Common questions and answers of software testing interview (divergent thinking, interface, performance, concept,)

批量复制宝贝上传提示乱码,如何解决?

QT编译出来的exe以管理员权限启动

Inftnews | "traffic + experience" white lining e Digital Fashion Festival leads the new changes of digital fashion
随机推荐
[binary search simple question] leetcode 35. search insertion position, 69. Square root of X, 367. Effective complete square, 441. Arrange coins
My crawler notes (VII) blog traffic +1 through Crawlers
对象创建的流程分析
制作ppt时间轴
CS224W fall 1.2 Applications of Graph ML
2513: 小勇学分数(公约数问题)
177. The nth highest salary (simple)
AcWing 2074. 倒计数 模拟
[二分查找简单题] LeetCode 35. 搜索插入位置,69. x 的平方根,367. 有效的完全平方数,441. 排列硬币
Plato Farm全新玩法,套利ePLATO稳获超高收益
HCIP第十四天笔记
Integrated water conservancy video monitoring station telemetry terminal video image water level water quality water quantity flow velocity monitoring
基于.NetCore开发博客项目 StarBlog - (16) 一些新功能 (监控/统计/配置/初始化)
CAS部署使用以及登录成功跳转地址
【flask】服务端获取客户端请求的文件
Thread.Sleep(0)的作用
抖音服务器带宽有多大,才能供上亿人同时刷?
杀毒软件 clamav 的安装和使用
B-树的应用以及添加和删除操作
Baidu cloud face recognition