c/c++语言开发共享【Leetcode】CombineTwoTables

  题目: table: person +————-+———+ | column name | type

 

题目:
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

思路:
考察join语句
inner join是两表交集
outer join是两表除了交集之外的部分,left是不管左边表满不满足on的条件都在结果中,right同理,full是两表并集

算法:

  select firstname,lastname,city,state from person p  left outer join address a on p.personid=a.personid

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/c-cdevelopment/605686.html

(0)
上一篇 2021年5月13日
下一篇 2021年5月13日

精彩推荐