Leetcode 175. Combine Two Tables

原创 2016年08月30日 01:53:46

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;


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

LeetCode : 175. Combine Two Tables

175. Combine Two TablesTable: Person+-------------+---------+ | Column Name | Type | +-----------...

175. Combine Two Tables

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

Two Sum leetcode c++

  • 2015年10月01日 10:47
  • 763B
  • 下载

Codeforces Round #141 (Div. 2) B. Two Tables 枚举

You've got two rectangular tables with sizes na × ma and nb × mb cells. The tables consist of zero...

(转)A SQL query walks into a bar and sees two tables. He walks up to them and says 'Can I join you?'

A SQL query walks into a bar and sees two tables. He walks up to them and says 'Can I join you?' (s...
  • nettcp
  • nettcp
  • 2011年08月04日 22:17
  • 250

169.You have two tables with referential integrity enforced between them. You need to insert data to

169.You have two tables with referential integrity enforced between them. You need to insert data to...

【CodeForce】Codeforces Round #141 (Div. 2) B. Two Tables

第二次熬夜做题,发现这一次的阅读量好大,英语差的连题目都看不懂。。。好不容易看懂了一个,代码写了我两个小时,哎.....不解释了。 CF比赛连接 Codeforces Round #141 (Div...

MySQL:Compare two tables

Sometimes you have two tables with similar structures and want to compare them. One could be the tab...
  • cubesky
  • cubesky
  • 2014年08月22日 11:51
  • 512

[Leetcode]Add Two Numbers 链表实现大数字相加

机智代码来源:http://www.2cto.com/kf/201401/275891.html C语言实现:/** * Definition for singly-linked list. *...

【LeetCode-面试算法经典-Java实现】【001-Two Sum(求两个数的和)】

给定一个整数数组,找出其中两个数满足相加等于你指定的目标数字。要求:这个函数twoSum必须要返回能够相加等于目标数字的两个数的索引,且index1必须要小于index2。请注意一点,你返回的结果(包...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Leetcode 175. Combine Two Tables
举报原因:
原因补充:

(最多只允许输入30个字)