SQL 连接两个视图
需要一些帮助连接这两个表
我有两个看起来像这样的视图
view1 view2
+------+--------+ +------+--------+
| code | SUM(*) | | code | SUM(*) |
+------+--------+ +------+--------+
| AAA | 4 | | AAA | 4 |
| BBB | 3 | | CCC | 1 |
+------+--------+ +------+--------+
我想将它们连接到一个看起来像这样的表
+------+--------+
| code | SUM(*) |
+------+--------+
| AAA | 4 |
| BBB | 3 |
| CCC | 1 |
+------+--------+
我已经尝试过,但只是失败了。
Need some help joining these two tables
I have two views that looks like this
view1 view2
+------+--------+ +------+--------+
| code | SUM(*) | | code | SUM(*) |
+------+--------+ +------+--------+
| AAA | 4 | | AAA | 4 |
| BBB | 3 | | CCC | 1 |
+------+--------+ +------+--------+
I want to join them into a table that looks like this
+------+--------+
| code | SUM(*) |
+------+--------+
| AAA | 4 |
| BBB | 3 |
| CCC | 1 |
+------+--------+
I have tried, but only failed..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
UNION
不会返回重复的条目,这似乎正是您正在寻找的。Utilizing a
UNION
will not return duplicate entries, which is what it seems you are looking for.您可以使用
UNION
来实现:You can use a
UNION
for this:对于您的第一个结果,使用
union
发布的答案将起到作用:但是,鉴于您的其中一列是总和,这似乎不太可能是您真正想要的。
对于第二个结果(添加值的位置),您需要使用
union
和子查询:For your first result, the answers posted using
union
will do the trick:However, given the fact that one of your columns is a sum, this seems unlikely to be what you actually want.
For your second result (where the values are added), you'll need to use a
union
and a subquery: