【LeetCode】175.组合两个表
程序员文章站
2022-04-15 14:44:39
...
175.组合两个表
用到的表和数据SQL:
Create table Person (PersonId int,FirstName varchar(255), LastName varchar(255));
Create table Address (AddressId int,PersonId int, City varchar(255), State varchar(255));
Truncate table Person;
insert into Person (PersonId, LastName,FirstName) values ('1', 'Wang', 'Allen');
Truncate table Address;
insert into Address (AddressId, PersonId,City, State) values ('1', '2', 'New York City', 'New York');
答案:
此题相当于是把两个表的数据通过PersonId连接在一起,组合成一张新表
select p.FirstName,p.LastName,a.City,a.State from Person p
left join Address a on a.PersonId =p.PersonId
写的比较粗糙,有不理解的可以扫描二维码加QQ群找我解答。