关闭

Leetcode 175. Combine Two Tables

标签: MySQL
294人阅读 评论(0) 收藏 举报
分类:

175. Combine Two Tables

Total Accepted: 25227 Total Submissions: 73988 Difficulty: Easy

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

本弱渣博主准备开始进军leetcode的数据库内容,主要是题目做的太无聊了,并且没有面试光刷题并没有什么卵用。大牛从名校出来,高GPA,项目牛逼就拿面试了,然后随便刷个题就拿offer了,弱渣项目没有简历关都过不了,刷300题也觉得性价比不高啊


思路:

有俩表,需要把俩表的信息整合,用join。因为是regardless of address所以是left join。也就是左表每一行的信息加右边对应同personId的行信息。


# Write your MySQL query statement below
select a.FirstName, a.LastName, b.City, b.State from Person a left join Address b
on a.personid = b.personid;


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:36351次
    • 积分:1653
    • 等级:
    • 排名:千里之外
    • 原创:133篇
    • 转载:3篇
    • 译文:0篇
    • 评论:24条
    文章分类
    最新评论